"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.editSyntheticsParamsRoute = void 0; var _configSchema = require("@kbn/config-schema"); var _common = require("@kbn/spaces-plugin/common"); var _saved_objects = require("../../../common/types/saved_objects"); var _constants = require("../../../common/constants"); /* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one * or more contributor license agreements. Licensed under the Elastic License * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ const editSyntheticsParamsRoute = () => ({ method: 'PUT', path: _constants.SYNTHETICS_API_URLS.PARAMS, validate: { body: _configSchema.schema.object({ id: _configSchema.schema.string(), key: _configSchema.schema.string(), value: _configSchema.schema.string(), description: _configSchema.schema.maybe(_configSchema.schema.string()), tags: _configSchema.schema.maybe(_configSchema.schema.arrayOf(_configSchema.schema.string())), share_across_spaces: _configSchema.schema.maybe(_configSchema.schema.boolean()) }) }, writeAccess: true, handler: async ({ savedObjectsClient, request, response, server }) => { try { var _await$server$spaces$, _server$spaces; const { id: _spaceId } = (_await$server$spaces$ = await ((_server$spaces = server.spaces) === null || _server$spaces === void 0 ? void 0 : _server$spaces.spacesService.getActiveSpace(request))) !== null && _await$server$spaces$ !== void 0 ? _await$server$spaces$ : { id: _common.DEFAULT_SPACE_ID }; const { share_across_spaces: shareAcrossSpaces, id, ...data } = request.body; const { value } = data; const { id: responseId, attributes: { key, tags, description }, namespaces } = await savedObjectsClient.update(_saved_objects.syntheticsParamType, id, data); return response.ok({ body: { id: responseId, key, tags, description, namespaces, value } }); } catch (error) { var _error$output; if (((_error$output = error.output) === null || _error$output === void 0 ? void 0 : _error$output.statusCode) === 404) { var _server$spaces$spaces, _server$spaces2; const spaceId = (_server$spaces$spaces = (_server$spaces2 = server.spaces) === null || _server$spaces2 === void 0 ? void 0 : _server$spaces2.spacesService.getSpaceId(request)) !== null && _server$spaces$spaces !== void 0 ? _server$spaces$spaces : _common.DEFAULT_SPACE_ID; return response.notFound({ body: { message: `Kibana space '${spaceId}' does not exist` } }); } throw error; } } }); exports.editSyntheticsParamsRoute = editSyntheticsParamsRoute;