@wix/sdk 1.10.2 → 1.11.1

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,31 +1,5 @@
1
- import type { HttpClient as SDKHttpClient } from '@wix/sdk-types';
1
+ import type { HttpClient as SDKHttpClient, AmbassadorFactory } from '@wix/sdk-types';
2
2
  import { RESTModuleOptions } from './rest-modules.js';
3
- export type RequestContext = {
4
- isSSR: boolean;
5
- host: string;
6
- protocol?: string;
7
- };
8
- /**
9
- * Ambassador request options types are copied mostly from AxiosRequestConfig.
10
- * They are copied and not imported to reduce the amount of dependencies (to reduce install time).
11
- * https://github.com/axios/axios/blob/3f53eb6960f05a1f88409c4b731a40de595cb825/index.d.ts#L307-L315
12
- */
13
- export type Method = 'get' | 'GET' | 'delete' | 'DELETE' | 'head' | 'HEAD' | 'options' | 'OPTIONS' | 'post' | 'POST' | 'put' | 'PUT' | 'patch' | 'PATCH' | 'purge' | 'PURGE' | 'link' | 'LINK' | 'unlink' | 'UNLINK';
14
- type ResponseTransformer = (data: any, headers?: any) => any;
15
- export type AmbassadorRequestOptions<T = any> = {
16
- _?: T;
17
- url?: string;
18
- method?: Method;
19
- params?: any;
20
- data?: any;
21
- transformResponse?: ResponseTransformer | ResponseTransformer[];
22
- };
23
- export type AmbassadorFactory<Request, Response> = (payload: Request) => ((context: RequestContext) => AmbassadorRequestOptions<Response>) & {
24
- __isAmbassador: boolean;
25
- };
26
- export type AmbassadorFunctionDescriptor<Request = any, Response = any> = AmbassadorFactory<Request, Response>;
27
- export type BuildAmbassadorFunction<T extends AmbassadorFunctionDescriptor> = T extends AmbassadorFunctionDescriptor<infer Request, infer Response> ? (req: Request) => Promise<Response> : never;
28
3
  export declare const toHTTPModule: <Request_1, Response_1>(factory: AmbassadorFactory<Request_1, Response_1>) => (httpClient: SDKHttpClient) => (payload: Request_1) => Promise<Response_1>;
29
4
  export declare const ambassadorModuleOptions: () => RESTModuleOptions;
30
5
  export declare const isAmbassadorModule: (module: any) => boolean;
31
- export {};
@@ -1,5 +1,4 @@
1
- import { APIMetadata } from '@wix/sdk-types';
2
- import { PublicMetadata } from '../common.js';
1
+ import { APIMetadata, PublicMetadata } from '@wix/sdk-types';
3
2
  export declare const WixBIHeaderName = "x-wix-bi-gateway";
4
3
  export type WixBIHeaderValues = {
5
4
  ['environment']: 'js-sdk';
package/build/common.d.ts CHANGED
@@ -1,7 +1,4 @@
1
1
  export declare const PUBLIC_METADATA_KEY = "__metadata";
2
- export type PublicMetadata = {
3
- PACKAGE_NAME?: string;
4
- };
5
2
  export declare const API_URL = "www.wixapis.com";
6
3
  export declare const READ_ONLY_API_URL = "readonly.wixapis.com";
7
4
  export declare const FORCE_WRITE_API_URLS: string[];
@@ -0,0 +1,5 @@
1
+ import { WixClient } from './wixClient.js';
2
+ export declare function elevate<T extends (...arg: any) => any>(func: T): (...param: Parameters<T>) => ReturnType<T>;
3
+ export declare const fetchWithAuth: WixClient['fetchWithAuth'];
4
+ export declare const graphql: WixClient['graphql'];
5
+ export { setGlobalWixContext } from './wix-context.js';
@@ -0,0 +1,22 @@
1
+ import { resolveContext } from '@wix/sdk-runtime/context';
2
+ export function elevate(func) {
3
+ return (...args) => {
4
+ let fullArgs = Array(func.length)
5
+ .fill(undefined)
6
+ .map((_, index) => args[index]);
7
+ // support old EDMs
8
+ if (fullArgs.length === 0) {
9
+ fullArgs = args;
10
+ }
11
+ return func(...fullArgs, { suppressAuth: true });
12
+ };
13
+ }
14
+ export const fetchWithAuth = async (...args) => {
15
+ const context = resolveContext();
16
+ return context.fetchWithAuth(...args);
17
+ };
18
+ export const graphql = async (...args) => {
19
+ const context = resolveContext();
20
+ return context.graphql(...args);
21
+ };
22
+ export { setGlobalWixContext } from './wix-context.js';
@@ -1,7 +1,6 @@
1
- import { PublicMetadata } from './common.js';
2
- import { BuildRESTFunction, RESTFunctionDescriptor } from '@wix/sdk-types';
1
+ import { BuildRESTFunction, PublicMetadata, RESTFunctionDescriptor } from '@wix/sdk-types';
3
2
  export type RESTModuleOptions = {
4
3
  HTTPHost?: string;
5
4
  };
6
- export declare const getDefaultDomain: (method: string, url: string) => "www.wixapis.com" | "readonly.wixapis.com";
5
+ export declare const getDefaultDomain: (_method: string, _url: string) => string;
7
6
  export declare function buildRESTDescriptor<T extends RESTFunctionDescriptor>(origFunc: T, publicMetadata: PublicMetadata, boundFetch: (url: string | URL, init?: RequestInit) => Promise<Response>, options?: RESTModuleOptions): BuildRESTFunction<T>;
@@ -1,9 +1,6 @@
1
1
  import { biHeaderGenerator } from './bi/biHeaderGenerator.js';
2
- import { API_URL, FORCE_WRITE_API_URLS, READ_ONLY_API_URL, } from './common.js';
3
- export const getDefaultDomain = (method, url) => method === 'GET' &&
4
- !FORCE_WRITE_API_URLS.some((write_url) => url === write_url)
5
- ? READ_ONLY_API_URL
6
- : API_URL;
2
+ import { API_URL } from './common.js';
3
+ export const getDefaultDomain = (_method, _url) => API_URL;
7
4
  export function buildRESTDescriptor(origFunc, publicMetadata, boundFetch, options) {
8
5
  return origFunc({
9
6
  request: async (factory) => {
@@ -2,6 +2,13 @@ import { BuildDescriptors, Descriptors, Host } from './index.js';
2
2
  export type WixContext = {
3
3
  initWixModules: <T extends Descriptors, H extends Host>(wixModules: T, elevated?: boolean) => BuildDescriptors<T, H>;
4
4
  };
5
+ /**
6
+ * Sets the Wix context globally.
7
+ * @param wixContext The Wix context to set globally.
8
+ * @param options Options for setting the context.
9
+ * @param options.dangerouslyOverride If true, the context will be set even if it already exists.
10
+ * @deprecated Use `WixClient.enableContext` instead.
11
+ */
5
12
  export declare function setGlobalWixContext(wixContext: WixContext, options?: {
6
13
  dangerouslyOverride?: boolean;
7
14
  }): void;
@@ -1,3 +1,10 @@
1
+ /**
2
+ * Sets the Wix context globally.
3
+ * @param wixContext The Wix context to set globally.
4
+ * @param options Options for setting the context.
5
+ * @param options.dangerouslyOverride If true, the context will be set even if it already exists.
6
+ * @deprecated Use `WixClient.enableContext` instead.
7
+ */
1
8
  export function setGlobalWixContext(wixContext, options = {}) {
2
9
  if (!globalThis.__wix_context__ || options.dangerouslyOverride) {
3
10
  globalThis.__wix_context__ = wixContext;
@@ -1,41 +1,8 @@
1
- import { AuthenticationStrategy, BoundAuthenticationStrategy, BuildEventDefinition, BuildRESTFunction, EventDefinition, EventIdentity, Host, HostModule, HostModuleAPI, RESTFunctionDescriptor, ServicePluginDefinition, BuildServicePluginDefinition, ServicePluginContract } from '@wix/sdk-types';
2
- import { ConditionalExcept } from 'type-fest/source/conditional-except.js';
1
+ import { AuthenticationStrategy, BoundAuthenticationStrategy, BuildDescriptors, Descriptors, EventDefinition, EventIdentity, Host, HostModule, RESTFunctionDescriptor, ServicePluginContract, ServicePluginDefinition } from '@wix/sdk-types';
3
2
  import { EmptyObject } from 'type-fest/source/empty-object.js';
4
- import { AmbassadorFunctionDescriptor, BuildAmbassadorFunction } from './ambassador-modules.js';
5
- import { PublicMetadata } from './common.js';
6
3
  import type { GraphQLFormattedError } from 'graphql';
4
+ export type ContextType = 'global' | 'module';
7
5
  type Headers = Record<string, string>;
8
- declare const SPI_ERROR_TYPE = "wix_spi_error";
9
- /**
10
- * This type takes in a descriptors object of a certain Host (including an `unknown` host)
11
- * and returns an object with the same structure, but with all descriptors replaced with their API.
12
- * Any non-descriptor properties are removed from the returned object, including descriptors that
13
- * do not match the given host (as they will not work with the given host).
14
- */
15
- export type BuildDescriptors<T extends Descriptors, H extends Host<any> | undefined, Depth extends number = 5> = {
16
- done: T;
17
- recurse: T extends {
18
- __type: typeof SPI_ERROR_TYPE;
19
- } ? never : T extends AmbassadorFunctionDescriptor ? BuildAmbassadorFunction<T> : T extends RESTFunctionDescriptor ? BuildRESTFunction<T> : T extends EventDefinition ? BuildEventDefinition<T> : T extends ServicePluginDefinition<any> ? BuildServicePluginDefinition<T> : T extends HostModule<any, any> ? HostModuleAPI<T> : ConditionalExcept<{
20
- [Key in keyof T]: T[Key] extends Descriptors ? BuildDescriptors<T[Key], H, [
21
- -1,
22
- 0,
23
- 1,
24
- 2,
25
- 3,
26
- 4,
27
- 5
28
- ][Depth]> : never;
29
- }, EmptyObject>;
30
- }[Depth extends -1 ? 'done' : 'recurse'];
31
- /**
32
- * Descriptors are objects that describe the API of a module, and the module
33
- * can either be a REST module or a host module.
34
- * This type is recursive, so it can describe nested modules.
35
- */
36
- export type Descriptors = RESTFunctionDescriptor | AmbassadorFunctionDescriptor | HostModule<any, any> | {
37
- [key: string]: Descriptors | PublicMetadata | any;
38
- };
39
6
  /**
40
7
  * This type is used in `createClient` to ensure that the given host matches the host of the given descriptors.
41
8
  * If the host does not match, the descriptor is replaced with a host module that will throw an error when used.
@@ -66,6 +33,7 @@ export type WixClient<H extends Host<any> | undefined = undefined, Z extends Aut
66
33
  fetch(relativeUrl: string, options: RequestInit): Promise<Response>;
67
34
  fetchWithAuth: typeof fetch;
68
35
  use<R extends Descriptors = EmptyObject>(modules: H extends Host<any> ? AssertHostMatches<R, H> : R): BuildDescriptors<R, H>;
36
+ enableContext(contextType: ContextType): void;
69
37
  graphql<Result, Variables>(query: string | ((string | String) & TypedQueryInput<Result, Variables>), variables?: Variables): Promise<{
70
38
  data: Result;
71
39
  errors?: GraphQLFormattedError[];
@@ -1,4 +1,5 @@
1
- import { EventDefinition, } from '@wix/sdk-types';
1
+ import { wixContext } from '@wix/sdk-context';
2
+ import { EventDefinition, SERVICE_PLUGIN_ERROR_TYPE, } from '@wix/sdk-types';
2
3
  import { ambassadorModuleOptions, isAmbassadorModule, toHTTPModule, } from './ambassador-modules.js';
3
4
  import { API_URL, PUBLIC_METADATA_KEY } from './common.js';
4
5
  import { FetchErrorResponse } from './fetch-error.js';
@@ -7,7 +8,6 @@ import { buildHostModule, isHostModule } from './host-modules.js';
7
8
  import { buildRESTDescriptor } from './rest-modules.js';
8
9
  import { buildEventDefinition, isEventHandlerModule, runHandler, } from './event-handlers-modules.js';
9
10
  import { buildServicePluginDefinition, isServicePluginModule, } from './service-plugin-modules.js';
10
- const SPI_ERROR_TYPE = 'wix_spi_error';
11
11
  export function createClient(config) {
12
12
  const _headers = config.headers || { Authorization: '' };
13
13
  const eventHandlers = new Map();
@@ -56,7 +56,7 @@ export function createClient(config) {
56
56
  // The generated namespaces all have the error classes on them and
57
57
  // a class is also a function, so we need to explicitly ignore these
58
58
  // error classes using a static field that exists on them.
59
- if ('__type' in modules && modules.__type === SPI_ERROR_TYPE) {
59
+ if ('__type' in modules && modules.__type === SERVICE_PLUGIN_ERROR_TYPE) {
60
60
  return modules;
61
61
  }
62
62
  const { module, options } = isAmbassadorModule(modules)
@@ -95,6 +95,19 @@ export function createClient(config) {
95
95
  : undefined),
96
96
  setHeaders,
97
97
  use,
98
+ enableContext(contextType) {
99
+ if (contextType === 'global') {
100
+ if (globalThis.__wix_context__ != null) {
101
+ globalThis.__wix_context__.client = this;
102
+ }
103
+ else {
104
+ globalThis.__wix_context__ = { client: this };
105
+ }
106
+ }
107
+ else {
108
+ wixContext.client = this;
109
+ }
110
+ },
98
111
  fetch: (relativeUrl, options) => {
99
112
  const finalUrl = new URL(relativeUrl, `https://${API_URL}`);
100
113
  finalUrl.host = API_URL;
@@ -1,31 +1,5 @@
1
- import type { HttpClient as SDKHttpClient } from '@wix/sdk-types';
1
+ import type { HttpClient as SDKHttpClient, AmbassadorFactory } from '@wix/sdk-types';
2
2
  import { RESTModuleOptions } from './rest-modules.js';
3
- export type RequestContext = {
4
- isSSR: boolean;
5
- host: string;
6
- protocol?: string;
7
- };
8
- /**
9
- * Ambassador request options types are copied mostly from AxiosRequestConfig.
10
- * They are copied and not imported to reduce the amount of dependencies (to reduce install time).
11
- * https://github.com/axios/axios/blob/3f53eb6960f05a1f88409c4b731a40de595cb825/index.d.ts#L307-L315
12
- */
13
- export type Method = 'get' | 'GET' | 'delete' | 'DELETE' | 'head' | 'HEAD' | 'options' | 'OPTIONS' | 'post' | 'POST' | 'put' | 'PUT' | 'patch' | 'PATCH' | 'purge' | 'PURGE' | 'link' | 'LINK' | 'unlink' | 'UNLINK';
14
- type ResponseTransformer = (data: any, headers?: any) => any;
15
- export type AmbassadorRequestOptions<T = any> = {
16
- _?: T;
17
- url?: string;
18
- method?: Method;
19
- params?: any;
20
- data?: any;
21
- transformResponse?: ResponseTransformer | ResponseTransformer[];
22
- };
23
- export type AmbassadorFactory<Request, Response> = (payload: Request) => ((context: RequestContext) => AmbassadorRequestOptions<Response>) & {
24
- __isAmbassador: boolean;
25
- };
26
- export type AmbassadorFunctionDescriptor<Request = any, Response = any> = AmbassadorFactory<Request, Response>;
27
- export type BuildAmbassadorFunction<T extends AmbassadorFunctionDescriptor> = T extends AmbassadorFunctionDescriptor<infer Request, infer Response> ? (req: Request) => Promise<Response> : never;
28
3
  export declare const toHTTPModule: <Request_1, Response_1>(factory: AmbassadorFactory<Request_1, Response_1>) => (httpClient: SDKHttpClient) => (payload: Request_1) => Promise<Response_1>;
29
4
  export declare const ambassadorModuleOptions: () => RESTModuleOptions;
30
5
  export declare const isAmbassadorModule: (module: any) => boolean;
31
- export {};
@@ -1,5 +1,4 @@
1
- import { APIMetadata } from '@wix/sdk-types';
2
- import { PublicMetadata } from '../common.js';
1
+ import { APIMetadata, PublicMetadata } from '@wix/sdk-types';
3
2
  export declare const WixBIHeaderName = "x-wix-bi-gateway";
4
3
  export type WixBIHeaderValues = {
5
4
  ['environment']: 'js-sdk';
@@ -1,7 +1,4 @@
1
1
  export declare const PUBLIC_METADATA_KEY = "__metadata";
2
- export type PublicMetadata = {
3
- PACKAGE_NAME?: string;
4
- };
5
2
  export declare const API_URL = "www.wixapis.com";
6
3
  export declare const READ_ONLY_API_URL = "readonly.wixapis.com";
7
4
  export declare const FORCE_WRITE_API_URLS: string[];
@@ -0,0 +1,5 @@
1
+ import { WixClient } from './wixClient.js';
2
+ export declare function elevate<T extends (...arg: any) => any>(func: T): (...param: Parameters<T>) => ReturnType<T>;
3
+ export declare const fetchWithAuth: WixClient['fetchWithAuth'];
4
+ export declare const graphql: WixClient['graphql'];
5
+ export { setGlobalWixContext } from './wix-context.js';
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setGlobalWixContext = exports.graphql = exports.fetchWithAuth = exports.elevate = void 0;
4
+ const context_1 = require("@wix/sdk-runtime/context");
5
+ function elevate(func) {
6
+ return (...args) => {
7
+ let fullArgs = Array(func.length)
8
+ .fill(undefined)
9
+ .map((_, index) => args[index]);
10
+ // support old EDMs
11
+ if (fullArgs.length === 0) {
12
+ fullArgs = args;
13
+ }
14
+ return func(...fullArgs, { suppressAuth: true });
15
+ };
16
+ }
17
+ exports.elevate = elevate;
18
+ const fetchWithAuth = async (...args) => {
19
+ const context = (0, context_1.resolveContext)();
20
+ return context.fetchWithAuth(...args);
21
+ };
22
+ exports.fetchWithAuth = fetchWithAuth;
23
+ const graphql = async (...args) => {
24
+ const context = (0, context_1.resolveContext)();
25
+ return context.graphql(...args);
26
+ };
27
+ exports.graphql = graphql;
28
+ var wix_context_js_1 = require("./wix-context.js");
29
+ Object.defineProperty(exports, "setGlobalWixContext", { enumerable: true, get: function () { return wix_context_js_1.setGlobalWixContext; } });
@@ -1,7 +1,6 @@
1
- import { PublicMetadata } from './common.js';
2
- import { BuildRESTFunction, RESTFunctionDescriptor } from '@wix/sdk-types';
1
+ import { BuildRESTFunction, PublicMetadata, RESTFunctionDescriptor } from '@wix/sdk-types';
3
2
  export type RESTModuleOptions = {
4
3
  HTTPHost?: string;
5
4
  };
6
- export declare const getDefaultDomain: (method: string, url: string) => "www.wixapis.com" | "readonly.wixapis.com";
5
+ export declare const getDefaultDomain: (_method: string, _url: string) => string;
7
6
  export declare function buildRESTDescriptor<T extends RESTFunctionDescriptor>(origFunc: T, publicMetadata: PublicMetadata, boundFetch: (url: string | URL, init?: RequestInit) => Promise<Response>, options?: RESTModuleOptions): BuildRESTFunction<T>;
@@ -3,10 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.buildRESTDescriptor = exports.getDefaultDomain = void 0;
4
4
  const biHeaderGenerator_js_1 = require("./bi/biHeaderGenerator.js");
5
5
  const common_js_1 = require("./common.js");
6
- const getDefaultDomain = (method, url) => method === 'GET' &&
7
- !common_js_1.FORCE_WRITE_API_URLS.some((write_url) => url === write_url)
8
- ? common_js_1.READ_ONLY_API_URL
9
- : common_js_1.API_URL;
6
+ const getDefaultDomain = (_method, _url) => common_js_1.API_URL;
10
7
  exports.getDefaultDomain = getDefaultDomain;
11
8
  function buildRESTDescriptor(origFunc, publicMetadata, boundFetch, options) {
12
9
  return origFunc({
@@ -2,6 +2,13 @@ import { BuildDescriptors, Descriptors, Host } from './index.js';
2
2
  export type WixContext = {
3
3
  initWixModules: <T extends Descriptors, H extends Host>(wixModules: T, elevated?: boolean) => BuildDescriptors<T, H>;
4
4
  };
5
+ /**
6
+ * Sets the Wix context globally.
7
+ * @param wixContext The Wix context to set globally.
8
+ * @param options Options for setting the context.
9
+ * @param options.dangerouslyOverride If true, the context will be set even if it already exists.
10
+ * @deprecated Use `WixClient.enableContext` instead.
11
+ */
5
12
  export declare function setGlobalWixContext(wixContext: WixContext, options?: {
6
13
  dangerouslyOverride?: boolean;
7
14
  }): void;
@@ -1,6 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.setGlobalWixContext = void 0;
4
+ /**
5
+ * Sets the Wix context globally.
6
+ * @param wixContext The Wix context to set globally.
7
+ * @param options Options for setting the context.
8
+ * @param options.dangerouslyOverride If true, the context will be set even if it already exists.
9
+ * @deprecated Use `WixClient.enableContext` instead.
10
+ */
4
11
  function setGlobalWixContext(wixContext, options = {}) {
5
12
  if (!globalThis.__wix_context__ || options.dangerouslyOverride) {
6
13
  globalThis.__wix_context__ = wixContext;
@@ -1,41 +1,8 @@
1
- import { AuthenticationStrategy, BoundAuthenticationStrategy, BuildEventDefinition, BuildRESTFunction, EventDefinition, EventIdentity, Host, HostModule, HostModuleAPI, RESTFunctionDescriptor, ServicePluginDefinition, BuildServicePluginDefinition, ServicePluginContract } from '@wix/sdk-types';
2
- import { ConditionalExcept } from 'type-fest/source/conditional-except.js';
1
+ import { AuthenticationStrategy, BoundAuthenticationStrategy, BuildDescriptors, Descriptors, EventDefinition, EventIdentity, Host, HostModule, RESTFunctionDescriptor, ServicePluginContract, ServicePluginDefinition } from '@wix/sdk-types';
3
2
  import { EmptyObject } from 'type-fest/source/empty-object.js';
4
- import { AmbassadorFunctionDescriptor, BuildAmbassadorFunction } from './ambassador-modules.js';
5
- import { PublicMetadata } from './common.js';
6
3
  import type { GraphQLFormattedError } from 'graphql';
4
+ export type ContextType = 'global' | 'module';
7
5
  type Headers = Record<string, string>;
8
- declare const SPI_ERROR_TYPE = "wix_spi_error";
9
- /**
10
- * This type takes in a descriptors object of a certain Host (including an `unknown` host)
11
- * and returns an object with the same structure, but with all descriptors replaced with their API.
12
- * Any non-descriptor properties are removed from the returned object, including descriptors that
13
- * do not match the given host (as they will not work with the given host).
14
- */
15
- export type BuildDescriptors<T extends Descriptors, H extends Host<any> | undefined, Depth extends number = 5> = {
16
- done: T;
17
- recurse: T extends {
18
- __type: typeof SPI_ERROR_TYPE;
19
- } ? never : T extends AmbassadorFunctionDescriptor ? BuildAmbassadorFunction<T> : T extends RESTFunctionDescriptor ? BuildRESTFunction<T> : T extends EventDefinition ? BuildEventDefinition<T> : T extends ServicePluginDefinition<any> ? BuildServicePluginDefinition<T> : T extends HostModule<any, any> ? HostModuleAPI<T> : ConditionalExcept<{
20
- [Key in keyof T]: T[Key] extends Descriptors ? BuildDescriptors<T[Key], H, [
21
- -1,
22
- 0,
23
- 1,
24
- 2,
25
- 3,
26
- 4,
27
- 5
28
- ][Depth]> : never;
29
- }, EmptyObject>;
30
- }[Depth extends -1 ? 'done' : 'recurse'];
31
- /**
32
- * Descriptors are objects that describe the API of a module, and the module
33
- * can either be a REST module or a host module.
34
- * This type is recursive, so it can describe nested modules.
35
- */
36
- export type Descriptors = RESTFunctionDescriptor | AmbassadorFunctionDescriptor | HostModule<any, any> | {
37
- [key: string]: Descriptors | PublicMetadata | any;
38
- };
39
6
  /**
40
7
  * This type is used in `createClient` to ensure that the given host matches the host of the given descriptors.
41
8
  * If the host does not match, the descriptor is replaced with a host module that will throw an error when used.
@@ -66,6 +33,7 @@ export type WixClient<H extends Host<any> | undefined = undefined, Z extends Aut
66
33
  fetch(relativeUrl: string, options: RequestInit): Promise<Response>;
67
34
  fetchWithAuth: typeof fetch;
68
35
  use<R extends Descriptors = EmptyObject>(modules: H extends Host<any> ? AssertHostMatches<R, H> : R): BuildDescriptors<R, H>;
36
+ enableContext(contextType: ContextType): void;
69
37
  graphql<Result, Variables>(query: string | ((string | String) & TypedQueryInput<Result, Variables>), variables?: Variables): Promise<{
70
38
  data: Result;
71
39
  errors?: GraphQLFormattedError[];
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createClient = void 0;
4
+ const sdk_context_1 = require("@wix/sdk-context");
4
5
  const sdk_types_1 = require("@wix/sdk-types");
5
6
  const ambassador_modules_js_1 = require("./ambassador-modules.js");
6
7
  const common_js_1 = require("./common.js");
@@ -10,7 +11,6 @@ const host_modules_js_1 = require("./host-modules.js");
10
11
  const rest_modules_js_1 = require("./rest-modules.js");
11
12
  const event_handlers_modules_js_1 = require("./event-handlers-modules.js");
12
13
  const service_plugin_modules_js_1 = require("./service-plugin-modules.js");
13
- const SPI_ERROR_TYPE = 'wix_spi_error';
14
14
  function createClient(config) {
15
15
  const _headers = config.headers || { Authorization: '' };
16
16
  const eventHandlers = new Map();
@@ -59,7 +59,7 @@ function createClient(config) {
59
59
  // The generated namespaces all have the error classes on them and
60
60
  // a class is also a function, so we need to explicitly ignore these
61
61
  // error classes using a static field that exists on them.
62
- if ('__type' in modules && modules.__type === SPI_ERROR_TYPE) {
62
+ if ('__type' in modules && modules.__type === sdk_types_1.SERVICE_PLUGIN_ERROR_TYPE) {
63
63
  return modules;
64
64
  }
65
65
  const { module, options } = (0, ambassador_modules_js_1.isAmbassadorModule)(modules)
@@ -98,6 +98,19 @@ function createClient(config) {
98
98
  : undefined),
99
99
  setHeaders,
100
100
  use,
101
+ enableContext(contextType) {
102
+ if (contextType === 'global') {
103
+ if (globalThis.__wix_context__ != null) {
104
+ globalThis.__wix_context__.client = this;
105
+ }
106
+ else {
107
+ globalThis.__wix_context__ = { client: this };
108
+ }
109
+ }
110
+ else {
111
+ sdk_context_1.wixContext.client = this;
112
+ }
113
+ },
101
114
  fetch: (relativeUrl, options) => {
102
115
  const finalUrl = new URL(relativeUrl, `https://${common_js_1.API_URL}`);
103
116
  finalUrl.host = common_js_1.API_URL;
@@ -1,3 +1,3 @@
1
1
  {
2
- "main": "../cjs/build/wix-context.js"
2
+ "main": "../cjs/build/context.js"
3
3
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/sdk",
3
- "version": "1.10.2",
3
+ "version": "1.11.1",
4
4
  "license": "UNLICENSED",
5
5
  "author": {
6
6
  "name": "Ronny Ringel",
@@ -20,8 +20,8 @@
20
20
  "require": "./cjs/build/wixClient.js"
21
21
  },
22
22
  "./context": {
23
- "import": "./build/wix-context.js",
24
- "require": "./cjs/build/wix-context.js"
23
+ "import": "./build/context.js",
24
+ "require": "./cjs/build/context.js"
25
25
  },
26
26
  "./auth/oauth2": {
27
27
  "import": "./build/auth/oauth2/OAuthStrategy.js",
@@ -65,9 +65,11 @@
65
65
  "dependencies": {
66
66
  "@babel/runtime": "^7.23.2",
67
67
  "@wix/identity": "^1.0.78",
68
- "@wix/image-kit": "^1.69.0",
68
+ "@wix/image-kit": "^1.70.0",
69
69
  "@wix/redirects": "^1.0.41",
70
- "@wix/sdk-types": "^1.8.0",
70
+ "@wix/sdk-context": "^0.0.1",
71
+ "@wix/sdk-runtime": "0.3.0",
72
+ "@wix/sdk-types": "^1.9.0",
71
73
  "crypto-js": "^4.2.0",
72
74
  "jose": "^5.2.1",
73
75
  "pkce-challenge": "^3.1.0",
@@ -86,7 +88,7 @@
86
88
  "@wix/events": "^1.0.179",
87
89
  "@wix/metro": "^1.0.73",
88
90
  "@wix/metro-runtime": "^1.1677.0",
89
- "@wix/sdk-runtime": "0.2.12",
91
+ "@wix/sdk-runtime": "0.3.0",
90
92
  "eslint": "^8.56.0",
91
93
  "eslint-config-sdk": "0.0.0",
92
94
  "graphql": "^16.8.0",
@@ -120,5 +122,5 @@
120
122
  "wallaby": {
121
123
  "autoDetect": true
122
124
  },
123
- "falconPackageHash": "445126e56e9a0b8384a7ceb1768d9aa017a75cdd8ce0004a4bdbc6f9"
125
+ "falconPackageHash": "463d0e16e85562d2b889feb9295a186f2437388d43ef754d18ab5ad7"
124
126
  }