@wix/sdk 1.12.4 → 1.12.5

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,6 +1,5 @@
1
- import { WixClient } from './wixClient.js';
2
1
  import { RESTFunctionDescriptor } from '@wix/sdk-types';
3
2
  export declare function elevate<T extends RESTFunctionDescriptor>(restModule: T): T;
4
- export declare const fetchWithAuth: WixClient['fetchWithAuth'];
5
- export declare const graphql: WixClient['graphql'];
3
+ export declare const fetchWithAuth: typeof fetch & ((restModuleOpts: import("@wix/sdk-types").HttpClient) => typeof fetch);
4
+ export { graphql } from './graphql.js';
6
5
  export { setGlobalWixContext } from './wix-context.js';
package/build/context.js CHANGED
@@ -1,20 +1,9 @@
1
- import { resolveContext } from '@wix/sdk-runtime/context';
2
1
  import { createRESTModule } from '@wix/sdk-runtime/rest-modules';
3
2
  export function elevate(restModule) {
4
3
  return createRESTModule(restModule, true);
5
4
  }
6
- export const fetchWithAuth = async (...args) => {
7
- const context = resolveContext();
8
- if (!context) {
9
- throw new Error('Wix context is not available. Make sure to initialize the Wix context before using SDK modules');
10
- }
11
- return context.fetchWithAuth(...args);
12
- };
13
- export const graphql = async (...args) => {
14
- const context = resolveContext();
15
- if (!context) {
16
- throw new Error('Wix context is not available. Make sure to initialize the Wix context before using SDK modules');
17
- }
18
- return context.graphql(...args);
19
- };
5
+ export const fetchWithAuth = createRESTModule((restModuleOpts) => {
6
+ return ((url, options) => restModuleOpts.fetchWithAuth(url, options));
7
+ });
8
+ export { graphql } from './graphql.js';
20
9
  export { setGlobalWixContext } from './wix-context.js';
@@ -0,0 +1,28 @@
1
+ import { DocumentNode, GraphQLFormattedError } from 'graphql';
2
+ export type TypedQueryInput<Result = {
3
+ [key: string]: any;
4
+ }, Variables = {
5
+ [key: string]: any;
6
+ }> = {
7
+ /**
8
+ * Type to support `@graphql-typed-document-node/core`
9
+ * @internal
10
+ */
11
+ __apiType?: (variables: Variables) => Result;
12
+ /**
13
+ * Type to support `TypedQueryDocumentNode` from `graphql`
14
+ * @internal
15
+ */
16
+ __ensureTypesOfVariablesAndResultMatching?: (variables: Variables) => Result;
17
+ };
18
+ export declare const graphql: ((query: string | String | DocumentNode | TypedQueryInput<unknown, any>, variables?: any, opts?: {
19
+ apiVersion: string;
20
+ }) => Promise<{
21
+ data: unknown;
22
+ errors?: GraphQLFormattedError[] | undefined;
23
+ }>) & ((restModuleOpts: import("@wix/sdk-types").HttpClient) => (query: string | String | DocumentNode | TypedQueryInput<unknown, any>, variables?: any, opts?: {
24
+ apiVersion: string;
25
+ }) => Promise<{
26
+ data: unknown;
27
+ errors?: GraphQLFormattedError[] | undefined;
28
+ }>);
@@ -0,0 +1,21 @@
1
+ import { createRESTModule } from '@wix/sdk-runtime/rest-modules';
2
+ import { FetchErrorResponse } from './fetch-error.js';
3
+ export const graphql = createRESTModule((restModuleOpts) => {
4
+ // eslint-disable-next-line @typescript-eslint/no-shadow
5
+ return async function graphql(query, variables, opts = {
6
+ apiVersion: 'alpha',
7
+ }) {
8
+ const res = await restModuleOpts.wixAPIFetch(`/graphql/${opts.apiVersion}`, {
9
+ method: 'POST',
10
+ headers: {
11
+ 'Content-Type': 'application/json',
12
+ },
13
+ body: JSON.stringify({ query, variables }),
14
+ });
15
+ if (res.status !== 200) {
16
+ throw new FetchErrorResponse(`GraphQL request failed with status ${res.status}`, res);
17
+ }
18
+ const { data, errors } = await res.json();
19
+ return { data: data ?? {}, errors };
20
+ };
21
+ });
@@ -3,4 +3,4 @@ export type RESTModuleOptions = {
3
3
  HTTPHost?: string;
4
4
  };
5
5
  export declare const getDefaultDomain: (_method: string, _url: string) => string;
6
- export declare function buildRESTDescriptor<T extends RESTFunctionDescriptor>(origFunc: T, publicMetadata: PublicMetadata, boundFetch: (url: string | URL, init?: RequestInit) => Promise<Response>, options?: RESTModuleOptions): BuildRESTFunction<T>;
6
+ 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,7 +1,7 @@
1
1
  import { biHeaderGenerator } from './bi/biHeaderGenerator.js';
2
2
  import { API_URL } from './common.js';
3
3
  export const getDefaultDomain = (_method, _url) => API_URL;
4
- export function buildRESTDescriptor(origFunc, publicMetadata, boundFetch, options) {
4
+ export function buildRESTDescriptor(origFunc, publicMetadata, boundFetch, wixAPIFetch, options) {
5
5
  return origFunc({
6
6
  request: async (factory) => {
7
7
  const requestOptions = factory({ host: options?.HTTPHost || API_URL });
@@ -56,6 +56,7 @@ export function buildRESTDescriptor(origFunc, publicMetadata, boundFetch, option
56
56
  }
57
57
  },
58
58
  fetchWithAuth: boundFetch,
59
+ wixAPIFetch,
59
60
  });
60
61
  }
61
62
  const errorBuilder = (code, description, details, data) => {
@@ -29,6 +29,9 @@ type TypedQueryInput<Result = {
29
29
  export type WixClient<H extends Host<any> | undefined = undefined, Z extends AuthenticationStrategy<H> = AuthenticationStrategy<H>, T extends Descriptors = {}> = {
30
30
  setHeaders(headers: Headers): void;
31
31
  auth: Omit<Z, 'getAuthHeaders'> & BoundAuthenticationStrategy;
32
+ /**
33
+ * @deprecated Use `fetchWithAuth` instead
34
+ */
32
35
  fetch(relativeUrl: string, options: RequestInit): Promise<Response>;
33
36
  fetchWithAuth: typeof fetch;
34
37
  use<R extends Descriptors = EmptyObject>(modules: H extends Host<any> ? AssertHostMatches<R, H> : R): BuildDescriptors<R, H>;
@@ -65,7 +65,12 @@ export function createClient(config) {
65
65
  options: ambassadorModuleOptions(),
66
66
  }
67
67
  : { module: modules, options: undefined };
68
- return buildRESTDescriptor(module, metadata ?? {}, boundFetch, options);
68
+ return buildRESTDescriptor(module, metadata ?? {}, boundFetch, (relativeUrl, fetchOptions) => {
69
+ const finalUrl = new URL(relativeUrl, `https://${API_URL}`);
70
+ finalUrl.host = API_URL;
71
+ finalUrl.protocol = 'https';
72
+ return boundFetch(finalUrl.toString(), fetchOptions);
73
+ }, options);
69
74
  }
70
75
  else if (isObject(modules)) {
71
76
  return Object.fromEntries(Object.entries(modules).map(([key, value]) => {
@@ -1,6 +1,5 @@
1
- import { WixClient } from './wixClient.js';
2
1
  import { RESTFunctionDescriptor } from '@wix/sdk-types';
3
2
  export declare function elevate<T extends RESTFunctionDescriptor>(restModule: T): T;
4
- export declare const fetchWithAuth: WixClient['fetchWithAuth'];
5
- export declare const graphql: WixClient['graphql'];
3
+ export declare const fetchWithAuth: typeof fetch & ((restModuleOpts: import("@wix/sdk-types").HttpClient) => typeof fetch);
4
+ export { graphql } from './graphql.js';
6
5
  export { setGlobalWixContext } from './wix-context.js';
@@ -1,27 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.setGlobalWixContext = exports.graphql = exports.fetchWithAuth = exports.elevate = void 0;
4
- const context_1 = require("@wix/sdk-runtime/context");
5
4
  const rest_modules_1 = require("@wix/sdk-runtime/rest-modules");
6
5
  function elevate(restModule) {
7
6
  return (0, rest_modules_1.createRESTModule)(restModule, true);
8
7
  }
9
8
  exports.elevate = elevate;
10
- const fetchWithAuth = async (...args) => {
11
- const context = (0, context_1.resolveContext)();
12
- if (!context) {
13
- throw new Error('Wix context is not available. Make sure to initialize the Wix context before using SDK modules');
14
- }
15
- return context.fetchWithAuth(...args);
16
- };
17
- exports.fetchWithAuth = fetchWithAuth;
18
- const graphql = async (...args) => {
19
- const context = (0, context_1.resolveContext)();
20
- if (!context) {
21
- throw new Error('Wix context is not available. Make sure to initialize the Wix context before using SDK modules');
22
- }
23
- return context.graphql(...args);
24
- };
25
- exports.graphql = graphql;
9
+ exports.fetchWithAuth = (0, rest_modules_1.createRESTModule)((restModuleOpts) => {
10
+ return ((url, options) => restModuleOpts.fetchWithAuth(url, options));
11
+ });
12
+ var graphql_js_1 = require("./graphql.js");
13
+ Object.defineProperty(exports, "graphql", { enumerable: true, get: function () { return graphql_js_1.graphql; } });
26
14
  var wix_context_js_1 = require("./wix-context.js");
27
15
  Object.defineProperty(exports, "setGlobalWixContext", { enumerable: true, get: function () { return wix_context_js_1.setGlobalWixContext; } });
@@ -0,0 +1,28 @@
1
+ import { DocumentNode, GraphQLFormattedError } from 'graphql';
2
+ export type TypedQueryInput<Result = {
3
+ [key: string]: any;
4
+ }, Variables = {
5
+ [key: string]: any;
6
+ }> = {
7
+ /**
8
+ * Type to support `@graphql-typed-document-node/core`
9
+ * @internal
10
+ */
11
+ __apiType?: (variables: Variables) => Result;
12
+ /**
13
+ * Type to support `TypedQueryDocumentNode` from `graphql`
14
+ * @internal
15
+ */
16
+ __ensureTypesOfVariablesAndResultMatching?: (variables: Variables) => Result;
17
+ };
18
+ export declare const graphql: ((query: string | String | DocumentNode | TypedQueryInput<unknown, any>, variables?: any, opts?: {
19
+ apiVersion: string;
20
+ }) => Promise<{
21
+ data: unknown;
22
+ errors?: GraphQLFormattedError[] | undefined;
23
+ }>) & ((restModuleOpts: import("@wix/sdk-types").HttpClient) => (query: string | String | DocumentNode | TypedQueryInput<unknown, any>, variables?: any, opts?: {
24
+ apiVersion: string;
25
+ }) => Promise<{
26
+ data: unknown;
27
+ errors?: GraphQLFormattedError[] | undefined;
28
+ }>);
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.graphql = void 0;
4
+ const rest_modules_1 = require("@wix/sdk-runtime/rest-modules");
5
+ const fetch_error_js_1 = require("./fetch-error.js");
6
+ exports.graphql = (0, rest_modules_1.createRESTModule)((restModuleOpts) => {
7
+ // eslint-disable-next-line @typescript-eslint/no-shadow
8
+ return async function graphql(query, variables, opts = {
9
+ apiVersion: 'alpha',
10
+ }) {
11
+ const res = await restModuleOpts.wixAPIFetch(`/graphql/${opts.apiVersion}`, {
12
+ method: 'POST',
13
+ headers: {
14
+ 'Content-Type': 'application/json',
15
+ },
16
+ body: JSON.stringify({ query, variables }),
17
+ });
18
+ if (res.status !== 200) {
19
+ throw new fetch_error_js_1.FetchErrorResponse(`GraphQL request failed with status ${res.status}`, res);
20
+ }
21
+ const { data, errors } = await res.json();
22
+ return { data: data ?? {}, errors };
23
+ };
24
+ });
@@ -3,4 +3,4 @@ export type RESTModuleOptions = {
3
3
  HTTPHost?: string;
4
4
  };
5
5
  export declare const getDefaultDomain: (_method: string, _url: string) => string;
6
- export declare function buildRESTDescriptor<T extends RESTFunctionDescriptor>(origFunc: T, publicMetadata: PublicMetadata, boundFetch: (url: string | URL, init?: RequestInit) => Promise<Response>, options?: RESTModuleOptions): BuildRESTFunction<T>;
6
+ 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>;
@@ -5,7 +5,7 @@ const biHeaderGenerator_js_1 = require("./bi/biHeaderGenerator.js");
5
5
  const common_js_1 = require("./common.js");
6
6
  const getDefaultDomain = (_method, _url) => common_js_1.API_URL;
7
7
  exports.getDefaultDomain = getDefaultDomain;
8
- function buildRESTDescriptor(origFunc, publicMetadata, boundFetch, options) {
8
+ function buildRESTDescriptor(origFunc, publicMetadata, boundFetch, wixAPIFetch, options) {
9
9
  return origFunc({
10
10
  request: async (factory) => {
11
11
  const requestOptions = factory({ host: options?.HTTPHost || common_js_1.API_URL });
@@ -60,6 +60,7 @@ function buildRESTDescriptor(origFunc, publicMetadata, boundFetch, options) {
60
60
  }
61
61
  },
62
62
  fetchWithAuth: boundFetch,
63
+ wixAPIFetch,
63
64
  });
64
65
  }
65
66
  exports.buildRESTDescriptor = buildRESTDescriptor;
@@ -29,6 +29,9 @@ type TypedQueryInput<Result = {
29
29
  export type WixClient<H extends Host<any> | undefined = undefined, Z extends AuthenticationStrategy<H> = AuthenticationStrategy<H>, T extends Descriptors = {}> = {
30
30
  setHeaders(headers: Headers): void;
31
31
  auth: Omit<Z, 'getAuthHeaders'> & BoundAuthenticationStrategy;
32
+ /**
33
+ * @deprecated Use `fetchWithAuth` instead
34
+ */
32
35
  fetch(relativeUrl: string, options: RequestInit): Promise<Response>;
33
36
  fetchWithAuth: typeof fetch;
34
37
  use<R extends Descriptors = EmptyObject>(modules: H extends Host<any> ? AssertHostMatches<R, H> : R): BuildDescriptors<R, H>;
@@ -68,7 +68,12 @@ function createClient(config) {
68
68
  options: (0, ambassador_modules_js_1.ambassadorModuleOptions)(),
69
69
  }
70
70
  : { module: modules, options: undefined };
71
- return (0, rest_modules_js_1.buildRESTDescriptor)(module, metadata ?? {}, boundFetch, options);
71
+ return (0, rest_modules_js_1.buildRESTDescriptor)(module, metadata ?? {}, boundFetch, (relativeUrl, fetchOptions) => {
72
+ const finalUrl = new URL(relativeUrl, `https://${common_js_1.API_URL}`);
73
+ finalUrl.host = common_js_1.API_URL;
74
+ finalUrl.protocol = 'https';
75
+ return boundFetch(finalUrl.toString(), fetchOptions);
76
+ }, options);
72
77
  }
73
78
  else if ((0, helpers_js_1.isObject)(modules)) {
74
79
  return Object.fromEntries(Object.entries(modules).map(([key, value]) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/sdk",
3
- "version": "1.12.4",
3
+ "version": "1.12.5",
4
4
  "license": "UNLICENSED",
5
5
  "author": {
6
6
  "name": "Ronny Ringel",
@@ -68,8 +68,8 @@
68
68
  "@wix/image-kit": "^1.73.0",
69
69
  "@wix/redirects": "^1.0.41",
70
70
  "@wix/sdk-context": "^0.0.1",
71
- "@wix/sdk-runtime": "0.3.9",
72
- "@wix/sdk-types": "^1.9.1",
71
+ "@wix/sdk-runtime": "0.3.10",
72
+ "@wix/sdk-types": "^1.9.2",
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.9",
91
+ "@wix/sdk-runtime": "0.3.10",
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": "426069986cecb4df61b6a603251e92b202e9969f72e82615ba31ee78"
125
+ "falconPackageHash": "9b0f25d6117aad528752157be42ad190b1e1bac5458a8dac29e8e34b"
126
126
  }