{"version":3,"sources":["../../../src/devcenter-scripts-v1-script-properties-embedded-scripts.universal.ts","../../../src/devcenter-scripts-v1-script-properties-embedded-scripts.http.ts"],"sourcesContent":["import { transformError as sdkTransformError } from '@wix/sdk-runtime/transform-error';\nimport {\n  renameKeysFromSDKRequestToRESTRequest,\n  renameKeysFromRESTResponseToSDKResponse,\n} from '@wix/sdk-runtime/rename-all-nested-keys';\nimport { HttpClient, NonNullablePaths } from '@wix/sdk-types';\nimport * as ambassadorWixDevcenterScriptsV1ScriptProperties from './devcenter-scripts-v1-script-properties-embedded-scripts.http.js';\n\nexport interface ScriptProperties {\n  /**\n   * Dynamic parameters available to the script when it runs on the site.\n   *\n   * Learn more about [using dynamic parameters](https://dev.wix.com/docs/wix-cli/guides/extensions/site-extensions/embedded-scripts/embedded-script-extension-files-and-code#using-dynamic-parameters-in-your-html-code).\n   */\n  parameters?: Record<string, string>;\n  /** Whether to disable the script. Default: `false`. */\n  disabled?: boolean;\n}\n\nexport interface EmbedScriptRequest {\n  /** Details of the script to embed. */\n  properties: ScriptProperties;\n  /**\n   * Extension ID of the embedded script.\n   *\n   * You can find the extension ID in the **Extensions** page in the [app dashboard](https://manage.wix.com/account/custom-apps). If you added the embedded script extension [using the Wix CLI](https://dev.wix.com/docs/wix-cli/guides/extensions/site-extensions/embedded-scripts/add-an-embedded-script-extension), you can also find it in the extension's [`embedded.extension.ts` file](https://dev.wix.com/docs/wix-cli/guides/extensions/site-extensions/embedded-scripts/embedded-script-extension-files-and-code#embeddedextensionts).\n   * @format GUID\n   */\n  componentId?: string | null;\n}\n\nexport interface EmbedScriptResponse {\n  /** Details of the embedded script. */\n  properties?: ScriptProperties;\n}\n\nexport interface GetEmbeddedScriptRequest {\n  /**\n   * Extension ID of the embedded script to retrieve.\n   *\n   * You can find the extension ID in the **Extensions** page in the [app dashboard](https://manage.wix.com/account/custom-apps). If you added the embedded script extension [using the Wix CLI](https://dev.wix.com/docs/wix-cli/guides/extensions/site-extensions/embedded-scripts/add-an-embedded-script-extension), you can also find it in the extension's [`embedded.extension.ts` file](https://dev.wix.com/docs/wix-cli/guides/extensions/site-extensions/embedded-scripts/embedded-script-extension-files-and-code#embeddedextensionts).\n   * @format GUID\n   */\n  componentId?: string | null;\n}\n\nexport interface GetEmbeddedScriptResponse {\n  /** Details of the retrieved embedded script. */\n  properties?: ScriptProperties;\n}\n\nexport interface EmbedScriptByInstanceIdRequest {\n  /** @format GUID */\n  instanceId?: string;\n  /** Parameters to embed */\n  properties?: ScriptProperties;\n  /** @format GUID */\n  componentId?: string | null;\n}\n\nexport interface GetEmbeddedScriptByInstanceIdRequest {\n  /** @format GUID */\n  instanceId?: string;\n  /** @format GUID */\n  componentId?: string | null;\n}\n\n/**\n * Inserts custom script tags into a site, with the specified values for any dynamic parameters. Call this method when your app is installed on a site.\n *\n * Your app must have an existing\n * [embedded script component](https://dev.wix.com/docs/build-apps/develop-your-app/extensions/site-extensions/embedded-scripts/about-embedded-scripts),\n * with exactly matching parameter names.\n * @param properties - Details of the script to embed.\n * @public\n * @requiredField properties\n * @permissionId APPS.MANAGE_EMBEDDED_SCRIPT\n * @applicableIdentity APP\n * @fqn com.wixpress.market.aim.api.EmbeddedScriptsService.EmbedScript\n */\nexport async function embedScript(\n  properties: ScriptProperties,\n  options?: EmbedScriptOptions\n): Promise<NonNullablePaths<EmbedScriptResponse, `properties.disabled`, 3>> {\n  // @ts-ignore\n  const { httpClient, sideEffects } = arguments[2] as {\n    httpClient: HttpClient;\n    sideEffects?: any;\n  };\n\n  const payload = renameKeysFromSDKRequestToRESTRequest({\n    properties: properties,\n    componentId: options?.componentId,\n  });\n\n  const reqOpts =\n    ambassadorWixDevcenterScriptsV1ScriptProperties.embedScript(payload);\n\n  sideEffects?.onSiteCall?.();\n  try {\n    const result = await httpClient.request(reqOpts);\n    sideEffects?.onSuccess?.(result);\n\n    return renameKeysFromRESTResponseToSDKResponse(result.data)!;\n  } catch (err: any) {\n    const transformedError = sdkTransformError(\n      err,\n      {\n        spreadPathsToArguments: {},\n        explicitPathsToArguments: {\n          properties: '$[0]',\n          componentId: '$[1].componentId',\n        },\n        singleArgumentUnchanged: false,\n      },\n      ['properties', 'options']\n    );\n    sideEffects?.onError?.(err);\n\n    throw transformedError;\n  }\n}\n\nexport interface EmbedScriptOptions {\n  /**\n   * Extension ID of the embedded script.\n   *\n   * You can find the extension ID in the **Extensions** page in the [app dashboard](https://manage.wix.com/account/custom-apps). If you added the embedded script extension [using the Wix CLI](https://dev.wix.com/docs/wix-cli/guides/extensions/site-extensions/embedded-scripts/add-an-embedded-script-extension), you can also find it in the extension's [`embedded.extension.ts` file](https://dev.wix.com/docs/wix-cli/guides/extensions/site-extensions/embedded-scripts/embedded-script-extension-files-and-code#embeddedextensionts).\n   * @format GUID\n   */\n  componentId?: string | null;\n}\n\n/**\n * Retrieves information about your app's existing embedded script.\n *\n * If your app doesn't have an embedded script on the relevant site, a `404` error is returned.\n * @public\n * @permissionId APPS.MANAGE_EMBEDDED_SCRIPT\n * @applicableIdentity APP\n * @returns Details of the retrieved embedded script.\n * @fqn com.wixpress.market.aim.api.EmbeddedScriptsService.GetEmbeddedScript\n */\nexport async function getEmbeddedScript(\n  options?: GetEmbeddedScriptOptions\n): Promise<NonNullablePaths<ScriptProperties, `disabled`, 2>> {\n  // @ts-ignore\n  const { httpClient, sideEffects } = arguments[1] as {\n    httpClient: HttpClient;\n    sideEffects?: any;\n  };\n\n  const payload = renameKeysFromSDKRequestToRESTRequest({\n    componentId: options?.componentId,\n  });\n\n  const reqOpts =\n    ambassadorWixDevcenterScriptsV1ScriptProperties.getEmbeddedScript(payload);\n\n  sideEffects?.onSiteCall?.();\n  try {\n    const result = await httpClient.request(reqOpts);\n    sideEffects?.onSuccess?.(result);\n\n    return renameKeysFromRESTResponseToSDKResponse(result.data)?.properties!;\n  } catch (err: any) {\n    const transformedError = sdkTransformError(\n      err,\n      {\n        spreadPathsToArguments: {},\n        explicitPathsToArguments: { componentId: '$[0].componentId' },\n        singleArgumentUnchanged: false,\n      },\n      ['options']\n    );\n    sideEffects?.onError?.(err);\n\n    throw transformedError;\n  }\n}\n\nexport interface GetEmbeddedScriptOptions {\n  /**\n   * Extension ID of the embedded script to retrieve.\n   *\n   * You can find the extension ID in the **Extensions** page in the [app dashboard](https://manage.wix.com/account/custom-apps). If you added the embedded script extension [using the Wix CLI](https://dev.wix.com/docs/wix-cli/guides/extensions/site-extensions/embedded-scripts/add-an-embedded-script-extension), you can also find it in the extension's [`embedded.extension.ts` file](https://dev.wix.com/docs/wix-cli/guides/extensions/site-extensions/embedded-scripts/embedded-script-extension-files-and-code#embeddedextensionts).\n   * @format GUID\n   */\n  componentId?: string | null;\n}\n","import { toURLSearchParams } from '@wix/sdk-runtime/rest-modules';\nimport { resolveUrl } from '@wix/sdk-runtime/rest-modules';\nimport { ResolveUrlOpts } from '@wix/sdk-runtime/rest-modules';\nimport { RequestOptionsFactory } from '@wix/sdk-types';\n\nfunction resolveComWixpressMarketAimApiEmbeddedScriptsServiceUrl(\n  opts: Omit<ResolveUrlOpts, 'domainToMappings'>\n) {\n  const domainToMappings = {\n    'api._api_base_domain_': [\n      {\n        srcPath: '/app-instance-manager-webapp',\n        destPath: '',\n      },\n    ],\n    'www.wixapis.com': [\n      {\n        srcPath: '/apps',\n        destPath: '',\n      },\n    ],\n    'wixapis.com': [\n      {\n        srcPath: '/apps',\n        destPath: '',\n      },\n    ],\n    'dev._base_domain_': [\n      {\n        srcPath: '/_api/app-instance-manager',\n        destPath: '',\n      },\n      {\n        srcPath: '/api/v1/instance',\n        destPath: '/v1/instance',\n      },\n      {\n        srcPath: '/api/v1/scripts',\n        destPath: '/v1/scripts',\n      },\n    ],\n    'manage._base_domain_': [\n      {\n        srcPath: '/_api/app-instance-manager',\n        destPath: '',\n      },\n    ],\n    'www._base_domain_': [\n      {\n        srcPath: '/_api/app-instance-manager',\n        destPath: '',\n      },\n    ],\n    'editor._base_domain_': [\n      {\n        srcPath: '/_api/app-instance-manager',\n        destPath: '',\n      },\n    ],\n    'blocks._base_domain_': [\n      {\n        srcPath: '/_api/app-instance-manager',\n        destPath: '',\n      },\n    ],\n    'create.editorx': [\n      {\n        srcPath: '/_api/app-instance-manager',\n        destPath: '',\n      },\n    ],\n    '*.dev.wix-code.com': [\n      {\n        srcPath: '/devcenter/app-instance/v1/instance',\n        destPath: '/v1/instance',\n      },\n      {\n        srcPath: '/devcenter/checkout/v1/checkout',\n        destPath: '/v1/checkout',\n      },\n      {\n        srcPath: '/devcenter/checkout/v1/metered-billing-charges',\n        destPath: '/v1/metered-billing-charges',\n      },\n      {\n        srcPath: '/devcenter/scripts/v1/scripts',\n        destPath: '/v1/scripts',\n      },\n      {\n        srcPath: '/market/aim/v1/billing-event',\n        destPath: '/v1/billing-event',\n      },\n      {\n        srcPath: '/devcenter/bi-events/v1/bi-event',\n        destPath: '/v1/bi-event',\n      },\n    ],\n    _: [\n      {\n        srcPath: '/devcenter/app-instance/v1/instance',\n        destPath: '/v1/instance',\n      },\n      {\n        srcPath: '/devcenter/checkout/v1/checkout',\n        destPath: '/v1/checkout',\n      },\n      {\n        srcPath: '/devcenter/checkout/v1/metered-billing-charges',\n        destPath: '/v1/metered-billing-charges',\n      },\n      {\n        srcPath: '/devcenter/scripts/v1/scripts',\n        destPath: '/v1/scripts',\n      },\n      {\n        srcPath: '/market/aim/v1/billing-event',\n        destPath: '/v1/billing-event',\n      },\n      {\n        srcPath: '/devcenter/bi-events/v1/bi-event',\n        destPath: '/v1/bi-event',\n      },\n    ],\n  };\n\n  return resolveUrl(Object.assign(opts, { domainToMappings }));\n}\n\nconst PACKAGE_NAME = '@wix/auto_sdk_app-management_embedded-scripts';\n\n/**\n * Inserts custom script tags into a site, with the specified values for any dynamic parameters. Call this method when your app is installed on a site.\n *\n * Your app must have an existing\n * [embedded script component](https://dev.wix.com/docs/build-apps/develop-your-app/extensions/site-extensions/embedded-scripts/about-embedded-scripts),\n * with exactly matching parameter names.\n */\nexport function embedScript(payload: object): RequestOptionsFactory<any> {\n  function __embedScript({ host }: any) {\n    const metadata = {\n      entityFqdn: 'wix.devcenter.scripts.v1.script_properties',\n      method: 'POST' as any,\n      methodFqn:\n        'com.wixpress.market.aim.api.EmbeddedScriptsService.EmbedScript',\n      packageName: PACKAGE_NAME,\n      migrationOptions: {\n        optInTransformResponse: true,\n      },\n      url: resolveComWixpressMarketAimApiEmbeddedScriptsServiceUrl({\n        protoPath: '/v1/scripts',\n        data: payload,\n        host,\n      }),\n      data: payload,\n    };\n\n    return metadata;\n  }\n\n  return __embedScript;\n}\n\n/**\n * Retrieves information about your app's existing embedded script.\n *\n * If your app doesn't have an embedded script on the relevant site, a `404` error is returned.\n */\nexport function getEmbeddedScript(payload: object): RequestOptionsFactory<any> {\n  function __getEmbeddedScript({ host }: any) {\n    const metadata = {\n      entityFqdn: 'wix.devcenter.scripts.v1.script_properties',\n      method: 'GET' as any,\n      methodFqn:\n        'com.wixpress.market.aim.api.EmbeddedScriptsService.GetEmbeddedScript',\n      packageName: PACKAGE_NAME,\n      migrationOptions: {\n        optInTransformResponse: true,\n      },\n      url: resolveComWixpressMarketAimApiEmbeddedScriptsServiceUrl({\n        protoPath: '/v1/scripts',\n        data: payload,\n        host,\n      }),\n      params: toURLSearchParams(payload),\n    };\n\n    return metadata;\n  }\n\n  return __getEmbeddedScript;\n}\n"],"mappings":";AAAA,SAAS,kBAAkB,yBAAyB;AACpD;AAAA,EACE;AAAA,EACA;AAAA,OACK;;;ACJP,SAAS,yBAAyB;AAClC,SAAS,kBAAkB;AAI3B,SAAS,wDACP,MACA;AACA,QAAM,mBAAmB;AAAA,IACvB,yBAAyB;AAAA,MACvB;AAAA,QACE,SAAS;AAAA,QACT,UAAU;AAAA,MACZ;AAAA,IACF;AAAA,IACA,mBAAmB;AAAA,MACjB;AAAA,QACE,SAAS;AAAA,QACT,UAAU;AAAA,MACZ;AAAA,IACF;AAAA,IACA,eAAe;AAAA,MACb;AAAA,QACE,SAAS;AAAA,QACT,UAAU;AAAA,MACZ;AAAA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