@wix/sdk 1.12.11 → 1.12.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,3 @@
1
1
  import type { HttpClient as SDKHttpClient, AmbassadorFactory } from '@wix/sdk-types';
2
- import { RESTModuleOptions } from './rest-modules.js';
3
2
  export declare const toHTTPModule: <Request_1, Response_1>(factory: AmbassadorFactory<Request_1, Response_1>) => (httpClient: SDKHttpClient) => (payload: Request_1) => Promise<Response_1>;
4
- export declare const ambassadorModuleOptions: () => RESTModuleOptions;
5
3
  export declare const isAmbassadorModule: (module: any) => boolean;
@@ -73,9 +73,6 @@ export const toHTTPModule = (factory) => (httpClient) => async (payload) => {
73
73
  throw e;
74
74
  }
75
75
  };
76
- export const ambassadorModuleOptions = () => ({
77
- HTTPHost: self.location.host,
78
- });
79
76
  /*
80
77
  * Because of issues with tree-shaking, we cant really put static parameter on module.
81
78
  * We still have check for __isAmbassador for backward compatibility
@@ -2,7 +2,7 @@ import { createClient } from '../../wixClient.js';
2
2
  import { redirects } from '@wix/redirects';
3
3
  import { createAccessToken, isTokenExpired } from '../../tokenHelpers.js';
4
4
  import { authentication, recovery, verification } from '@wix/identity';
5
- import { API_URL } from '../../common.js';
5
+ import { DEFAULT_API_URL } from '../../common.js';
6
6
  import { LoginState, TokenRole, } from './types.js';
7
7
  import { addPostMessageListener, loadFrame } from '../../iframeUtils.js';
8
8
  import { EMAIL_EXISTS, INVALID_CAPTCHA, INVALID_PASSWORD, MISSING_CAPTCHA, RESET_PASSWORD, } from './constants.js';
@@ -358,7 +358,7 @@ export function OAuthStrategy(config) {
358
358
  };
359
359
  }
360
360
  const fetchTokens = async (payload, headers = {}) => {
361
- const res = await fetch(`https://${API_URL}/oauth2/token`, {
361
+ const res = await fetch(`https://${DEFAULT_API_URL}/oauth2/token`, {
362
362
  method: 'POST',
363
363
  body: JSON.stringify(payload),
364
364
  headers: {
package/build/common.d.ts CHANGED
@@ -1,4 +1,3 @@
1
1
  export declare const PUBLIC_METADATA_KEY = "__metadata";
2
- export declare const API_URL = "www.wixapis.com";
3
- export declare const READ_ONLY_API_URL = "readonly.wixapis.com";
2
+ export declare const DEFAULT_API_URL = "www.wixapis.com";
4
3
  export declare const FORCE_WRITE_API_URLS: string[];
package/build/common.js CHANGED
@@ -1,4 +1,3 @@
1
1
  export const PUBLIC_METADATA_KEY = '__metadata';
2
- export const API_URL = 'www.wixapis.com';
3
- export const READ_ONLY_API_URL = 'readonly.wixapis.com';
2
+ export const DEFAULT_API_URL = 'www.wixapis.com';
4
3
  export const FORCE_WRITE_API_URLS = ['/ecom/v1/carts/current'];
package/build/index.d.ts CHANGED
@@ -5,5 +5,4 @@ export * from './auth/oauth2/types.js';
5
5
  export * from './auth/ApiKeyAuthStrategy.js';
6
6
  export * from './auth/AppStrategy.js';
7
7
  export * from '@wix/sdk-types';
8
- export { getDefaultDomain } from './rest-modules.js';
9
- export { API_URL } from './common.js';
8
+ export { DEFAULT_API_URL } from './common.js';
package/build/index.js CHANGED
@@ -5,5 +5,4 @@ export * from './auth/oauth2/types.js';
5
5
  export * from './auth/ApiKeyAuthStrategy.js';
6
6
  export * from './auth/AppStrategy.js';
7
7
  export * from '@wix/sdk-types';
8
- export { getDefaultDomain } from './rest-modules.js';
9
- export { API_URL } from './common.js';
8
+ export { DEFAULT_API_URL } from './common.js';
@@ -2,5 +2,4 @@ import { BuildRESTFunction, PublicMetadata, RESTFunctionDescriptor } from '@wix/
2
2
  export type RESTModuleOptions = {
3
3
  HTTPHost?: string;
4
4
  };
5
- export declare const getDefaultDomain: (_method: string, _url: string) => string;
6
5
  export declare function buildRESTDescriptor<T extends RESTFunctionDescriptor>(origFunc: T, publicMetadata: PublicMetadata, boundFetch: typeof fetch, wixAPIFetch: (relativeUrl: string, options: RequestInit) => Promise<Response>, options?: RESTModuleOptions): BuildRESTFunction<T>;
@@ -1,18 +1,19 @@
1
1
  import { biHeaderGenerator } from './bi/biHeaderGenerator.js';
2
- import { API_URL } from './common.js';
2
+ import { DEFAULT_API_URL } from './common.js';
3
3
  import { runWithoutContext } from '@wix/sdk-runtime/context';
4
- export const getDefaultDomain = (_method, _url) => API_URL;
5
4
  export function buildRESTDescriptor(origFunc, publicMetadata, boundFetch, wixAPIFetch, options) {
6
5
  return runWithoutContext(() => origFunc({
7
6
  request: async (factory) => {
8
- const requestOptions = factory({ host: options?.HTTPHost || API_URL });
7
+ const requestOptions = factory({
8
+ host: options?.HTTPHost || DEFAULT_API_URL,
9
+ });
9
10
  let request = requestOptions;
10
11
  if (request.method === 'GET' &&
11
12
  request.fallback?.length &&
12
13
  request.params.toString().length > 4000) {
13
14
  request = requestOptions.fallback[0];
14
15
  }
15
- const domain = options?.HTTPHost ?? getDefaultDomain(request.method, request.url);
16
+ const domain = options?.HTTPHost ?? DEFAULT_API_URL;
16
17
  let url = `https://${domain}${request.url}`;
17
18
  if (request.params && request.params.toString()) {
18
19
  url += `?${request.params.toString()}`;
@@ -1,7 +1,7 @@
1
1
  import { wixContext } from '@wix/sdk-context';
2
2
  import { SERVICE_PLUGIN_ERROR_TYPE, } from '@wix/sdk-types';
3
- import { ambassadorModuleOptions, isAmbassadorModule, toHTTPModule, } from './ambassador-modules.js';
4
- import { API_URL, PUBLIC_METADATA_KEY } from './common.js';
3
+ import { isAmbassadorModule, toHTTPModule } from './ambassador-modules.js';
4
+ import { DEFAULT_API_URL, PUBLIC_METADATA_KEY } from './common.js';
5
5
  import { FetchErrorResponse } from './fetch-error.js';
6
6
  import { getDefaultContentHeader, isObject } from './helpers.js';
7
7
  import { buildHostModule, isHostModule } from './host-modules.js';
@@ -52,18 +52,15 @@ export function createClient(config) {
52
52
  if ('__type' in modules && modules.__type === SERVICE_PLUGIN_ERROR_TYPE) {
53
53
  return modules;
54
54
  }
55
- const { module, options } = runWithoutContext(() => isAmbassadorModule(modules))
56
- ? {
57
- module: toHTTPModule(modules),
58
- options: ambassadorModuleOptions(),
59
- }
60
- : { module: modules, options: undefined };
61
- return buildRESTDescriptor(module, metadata ?? {}, boundFetch, (relativeUrl, fetchOptions) => {
62
- const finalUrl = new URL(relativeUrl, `https://${API_URL}`);
63
- finalUrl.host = API_URL;
55
+ const apiBaseUrl = config.host?.apiBaseUrl ?? DEFAULT_API_URL;
56
+ return buildRESTDescriptor(runWithoutContext(() => isAmbassadorModule(modules))
57
+ ? toHTTPModule(modules)
58
+ : modules, metadata ?? {}, boundFetch, (relativeUrl, fetchOptions) => {
59
+ const finalUrl = new URL(relativeUrl, `https://${apiBaseUrl}`);
60
+ finalUrl.host = apiBaseUrl;
64
61
  finalUrl.protocol = 'https';
65
62
  return boundFetch(finalUrl.toString(), fetchOptions);
66
- }, options);
63
+ }, { HTTPHost: apiBaseUrl });
67
64
  }
68
65
  else if (isObject(modules)) {
69
66
  return Object.fromEntries(Object.entries(modules).map(([key, value]) => {
@@ -116,8 +113,9 @@ export function createClient(config) {
116
113
  }
117
114
  },
118
115
  fetch: (relativeUrl, options) => {
119
- const finalUrl = new URL(relativeUrl, `https://${API_URL}`);
120
- finalUrl.host = API_URL;
116
+ const apiBaseUrl = config.host?.apiBaseUrl ?? DEFAULT_API_URL;
117
+ const finalUrl = new URL(relativeUrl, `https://${apiBaseUrl}`);
118
+ finalUrl.host = apiBaseUrl;
121
119
  finalUrl.protocol = 'https';
122
120
  return boundFetch(finalUrl.toString(), options);
123
121
  },
@@ -141,7 +139,8 @@ export function createClient(config) {
141
139
  async graphql(query, variables, opts = {
142
140
  apiVersion: 'alpha',
143
141
  }) {
144
- const res = await boundFetch(`https://${API_URL}/graphql/${opts.apiVersion}`, {
142
+ const apiBaseUrl = config?.host?.apiBaseUrl ?? DEFAULT_API_URL;
143
+ const res = await boundFetch(`https://${apiBaseUrl}/graphql/${opts.apiVersion}`, {
145
144
  method: 'POST',
146
145
  headers: {
147
146
  'Content-Type': 'application/json',
@@ -1,5 +1,3 @@
1
1
  import type { HttpClient as SDKHttpClient, AmbassadorFactory } from '@wix/sdk-types';
2
- import { RESTModuleOptions } from './rest-modules.js';
3
2
  export declare const toHTTPModule: <Request_1, Response_1>(factory: AmbassadorFactory<Request_1, Response_1>) => (httpClient: SDKHttpClient) => (payload: Request_1) => Promise<Response_1>;
4
- export declare const ambassadorModuleOptions: () => RESTModuleOptions;
5
3
  export declare const isAmbassadorModule: (module: any) => boolean;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isAmbassadorModule = exports.ambassadorModuleOptions = exports.toHTTPModule = void 0;
3
+ exports.isAmbassadorModule = exports.toHTTPModule = void 0;
4
4
  const parseMethod = (method) => {
5
5
  switch (method) {
6
6
  case 'get':
@@ -77,10 +77,6 @@ const toHTTPModule = (factory) => (httpClient) => async (payload) => {
77
77
  }
78
78
  };
79
79
  exports.toHTTPModule = toHTTPModule;
80
- const ambassadorModuleOptions = () => ({
81
- HTTPHost: self.location.host,
82
- });
83
- exports.ambassadorModuleOptions = ambassadorModuleOptions;
84
80
  /*
85
81
  * Because of issues with tree-shaking, we cant really put static parameter on module.
86
82
  * We still have check for __isAmbassador for backward compatibility
@@ -362,7 +362,7 @@ function OAuthStrategy(config) {
362
362
  }
363
363
  exports.OAuthStrategy = OAuthStrategy;
364
364
  const fetchTokens = async (payload, headers = {}) => {
365
- const res = await fetch(`https://${common_js_1.API_URL}/oauth2/token`, {
365
+ const res = await fetch(`https://${common_js_1.DEFAULT_API_URL}/oauth2/token`, {
366
366
  method: 'POST',
367
367
  body: JSON.stringify(payload),
368
368
  headers: {
@@ -1,4 +1,3 @@
1
1
  export declare const PUBLIC_METADATA_KEY = "__metadata";
2
- export declare const API_URL = "www.wixapis.com";
3
- export declare const READ_ONLY_API_URL = "readonly.wixapis.com";
2
+ export declare const DEFAULT_API_URL = "www.wixapis.com";
4
3
  export declare const FORCE_WRITE_API_URLS: string[];
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FORCE_WRITE_API_URLS = exports.READ_ONLY_API_URL = exports.API_URL = exports.PUBLIC_METADATA_KEY = void 0;
3
+ exports.FORCE_WRITE_API_URLS = exports.DEFAULT_API_URL = exports.PUBLIC_METADATA_KEY = void 0;
4
4
  exports.PUBLIC_METADATA_KEY = '__metadata';
5
- exports.API_URL = 'www.wixapis.com';
6
- exports.READ_ONLY_API_URL = 'readonly.wixapis.com';
5
+ exports.DEFAULT_API_URL = 'www.wixapis.com';
7
6
  exports.FORCE_WRITE_API_URLS = ['/ecom/v1/carts/current'];
@@ -5,5 +5,4 @@ export * from './auth/oauth2/types.js';
5
5
  export * from './auth/ApiKeyAuthStrategy.js';
6
6
  export * from './auth/AppStrategy.js';
7
7
  export * from '@wix/sdk-types';
8
- export { getDefaultDomain } from './rest-modules.js';
9
- export { API_URL } from './common.js';
8
+ export { DEFAULT_API_URL } from './common.js';
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.API_URL = exports.getDefaultDomain = void 0;
17
+ exports.DEFAULT_API_URL = void 0;
18
18
  __exportStar(require("./wixClient.js"), exports);
19
19
  __exportStar(require("./wixMedia.js"), exports);
20
20
  __exportStar(require("./auth/oauth2/OAuthStrategy.js"), exports);
@@ -22,7 +22,5 @@ __exportStar(require("./auth/oauth2/types.js"), exports);
22
22
  __exportStar(require("./auth/ApiKeyAuthStrategy.js"), exports);
23
23
  __exportStar(require("./auth/AppStrategy.js"), exports);
24
24
  __exportStar(require("@wix/sdk-types"), exports);
25
- var rest_modules_js_1 = require("./rest-modules.js");
26
- Object.defineProperty(exports, "getDefaultDomain", { enumerable: true, get: function () { return rest_modules_js_1.getDefaultDomain; } });
27
25
  var common_js_1 = require("./common.js");
28
- Object.defineProperty(exports, "API_URL", { enumerable: true, get: function () { return common_js_1.API_URL; } });
26
+ Object.defineProperty(exports, "DEFAULT_API_URL", { enumerable: true, get: function () { return common_js_1.DEFAULT_API_URL; } });
@@ -2,5 +2,4 @@ import { BuildRESTFunction, PublicMetadata, RESTFunctionDescriptor } from '@wix/
2
2
  export type RESTModuleOptions = {
3
3
  HTTPHost?: string;
4
4
  };
5
- export declare const getDefaultDomain: (_method: string, _url: string) => string;
6
5
  export declare function buildRESTDescriptor<T extends RESTFunctionDescriptor>(origFunc: T, publicMetadata: PublicMetadata, boundFetch: typeof fetch, wixAPIFetch: (relativeUrl: string, options: RequestInit) => Promise<Response>, options?: RESTModuleOptions): BuildRESTFunction<T>;
@@ -1,22 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildRESTDescriptor = exports.getDefaultDomain = void 0;
3
+ exports.buildRESTDescriptor = void 0;
4
4
  const biHeaderGenerator_js_1 = require("./bi/biHeaderGenerator.js");
5
5
  const common_js_1 = require("./common.js");
6
6
  const context_1 = require("@wix/sdk-runtime/context");
7
- const getDefaultDomain = (_method, _url) => common_js_1.API_URL;
8
- exports.getDefaultDomain = getDefaultDomain;
9
7
  function buildRESTDescriptor(origFunc, publicMetadata, boundFetch, wixAPIFetch, options) {
10
8
  return (0, context_1.runWithoutContext)(() => origFunc({
11
9
  request: async (factory) => {
12
- const requestOptions = factory({ host: options?.HTTPHost || common_js_1.API_URL });
10
+ const requestOptions = factory({
11
+ host: options?.HTTPHost || common_js_1.DEFAULT_API_URL,
12
+ });
13
13
  let request = requestOptions;
14
14
  if (request.method === 'GET' &&
15
15
  request.fallback?.length &&
16
16
  request.params.toString().length > 4000) {
17
17
  request = requestOptions.fallback[0];
18
18
  }
19
- const domain = options?.HTTPHost ?? (0, exports.getDefaultDomain)(request.method, request.url);
19
+ const domain = options?.HTTPHost ?? common_js_1.DEFAULT_API_URL;
20
20
  let url = `https://${domain}${request.url}`;
21
21
  if (request.params && request.params.toString()) {
22
22
  url += `?${request.params.toString()}`;
@@ -55,18 +55,15 @@ function createClient(config) {
55
55
  if ('__type' in modules && modules.__type === sdk_types_1.SERVICE_PLUGIN_ERROR_TYPE) {
56
56
  return modules;
57
57
  }
58
- const { module, options } = (0, context_1.runWithoutContext)(() => (0, ambassador_modules_js_1.isAmbassadorModule)(modules))
59
- ? {
60
- module: (0, ambassador_modules_js_1.toHTTPModule)(modules),
61
- options: (0, ambassador_modules_js_1.ambassadorModuleOptions)(),
62
- }
63
- : { module: modules, options: undefined };
64
- return (0, rest_modules_js_1.buildRESTDescriptor)(module, metadata ?? {}, boundFetch, (relativeUrl, fetchOptions) => {
65
- const finalUrl = new URL(relativeUrl, `https://${common_js_1.API_URL}`);
66
- finalUrl.host = common_js_1.API_URL;
58
+ const apiBaseUrl = config.host?.apiBaseUrl ?? common_js_1.DEFAULT_API_URL;
59
+ return (0, rest_modules_js_1.buildRESTDescriptor)((0, context_1.runWithoutContext)(() => (0, ambassador_modules_js_1.isAmbassadorModule)(modules))
60
+ ? (0, ambassador_modules_js_1.toHTTPModule)(modules)
61
+ : modules, metadata ?? {}, boundFetch, (relativeUrl, fetchOptions) => {
62
+ const finalUrl = new URL(relativeUrl, `https://${apiBaseUrl}`);
63
+ finalUrl.host = apiBaseUrl;
67
64
  finalUrl.protocol = 'https';
68
65
  return boundFetch(finalUrl.toString(), fetchOptions);
69
- }, options);
66
+ }, { HTTPHost: apiBaseUrl });
70
67
  }
71
68
  else if ((0, helpers_js_1.isObject)(modules)) {
72
69
  return Object.fromEntries(Object.entries(modules).map(([key, value]) => {
@@ -119,8 +116,9 @@ function createClient(config) {
119
116
  }
120
117
  },
121
118
  fetch: (relativeUrl, options) => {
122
- const finalUrl = new URL(relativeUrl, `https://${common_js_1.API_URL}`);
123
- finalUrl.host = common_js_1.API_URL;
119
+ const apiBaseUrl = config.host?.apiBaseUrl ?? common_js_1.DEFAULT_API_URL;
120
+ const finalUrl = new URL(relativeUrl, `https://${apiBaseUrl}`);
121
+ finalUrl.host = apiBaseUrl;
124
122
  finalUrl.protocol = 'https';
125
123
  return boundFetch(finalUrl.toString(), options);
126
124
  },
@@ -144,7 +142,8 @@ function createClient(config) {
144
142
  async graphql(query, variables, opts = {
145
143
  apiVersion: 'alpha',
146
144
  }) {
147
- const res = await boundFetch(`https://${common_js_1.API_URL}/graphql/${opts.apiVersion}`, {
145
+ const apiBaseUrl = config?.host?.apiBaseUrl ?? common_js_1.DEFAULT_API_URL;
146
+ const res = await boundFetch(`https://${apiBaseUrl}/graphql/${opts.apiVersion}`, {
148
147
  method: 'POST',
149
148
  headers: {
150
149
  'Content-Type': 'application/json',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/sdk",
3
- "version": "1.12.11",
3
+ "version": "1.12.12",
4
4
  "license": "UNLICENSED",
5
5
  "author": {
6
6
  "name": "Ronny Ringel",
@@ -68,8 +68,8 @@
68
68
  "@wix/image-kit": "^1.78.0",
69
69
  "@wix/redirects": "^1.0.41",
70
70
  "@wix/sdk-context": "^0.0.1",
71
- "@wix/sdk-runtime": "0.3.15",
72
- "@wix/sdk-types": "^1.9.2",
71
+ "@wix/sdk-runtime": "0.3.16",
72
+ "@wix/sdk-types": "^1.9.3",
73
73
  "crypto-js": "^4.2.0",
74
74
  "jose": "^5.2.1",
75
75
  "pkce-challenge": "^3.1.0",
@@ -88,7 +88,7 @@
88
88
  "@wix/events": "^1.0.179",
89
89
  "@wix/metro": "^1.0.73",
90
90
  "@wix/metro-runtime": "^1.1677.0",
91
- "@wix/sdk-runtime": "0.3.15",
91
+ "@wix/sdk-runtime": "0.3.16",
92
92
  "eslint": "^8.56.0",
93
93
  "eslint-config-sdk": "0.0.0",
94
94
  "graphql": "^16.8.0",
@@ -122,5 +122,5 @@
122
122
  "wallaby": {
123
123
  "autoDetect": true
124
124
  },
125
- "falconPackageHash": "50581ffffc42c024dba24d7ca3d381813b0485255f42bcc8eecbd2a1"
125
+ "falconPackageHash": "f3b508939b9d735e1177597d5a97d63c38940489f5e1b11c4f54c93b"
126
126
  }