@wix/sdk 1.4.0 → 1.5.0
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.
- package/build/browser/index.mjs +56 -2
- package/build/index.d.mts +62 -1
- package/build/index.d.ts +62 -1
- package/build/index.js +57 -2
- package/build/index.mjs +56 -2
- package/package.json +10 -6
package/build/browser/index.mjs
CHANGED
|
@@ -107,6 +107,7 @@ function objectToKeyValue(input) {
|
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
// src/rest-modules.ts
|
|
110
|
+
var getDefaultDomain = (method, url) => method === "GET" && !FORCE_WRITE_API_URLS.some((write_url) => url === write_url) ? READ_ONLY_API_URL : API_URL;
|
|
110
111
|
function buildRESTDescriptor(origFunc, publicMetadata, boundFetch, options) {
|
|
111
112
|
return origFunc({
|
|
112
113
|
request: async (factory) => {
|
|
@@ -116,8 +117,7 @@ function buildRESTDescriptor(origFunc, publicMetadata, boundFetch, options) {
|
|
|
116
117
|
if (request.method === "GET" && ((_a = request.fallback) == null ? void 0 : _a.length) && request.params.toString().length > 4e3) {
|
|
117
118
|
request = requestOptions.fallback[0];
|
|
118
119
|
}
|
|
119
|
-
const
|
|
120
|
-
const domain = (_b = options == null ? void 0 : options.HTTPHost) != null ? _b : getDefaultDomain();
|
|
120
|
+
const domain = (_b = options == null ? void 0 : options.HTTPHost) != null ? _b : getDefaultDomain(request.method, request.url);
|
|
121
121
|
let url = `https://${domain}${request.url}`;
|
|
122
122
|
if (request.params && request.params.toString()) {
|
|
123
123
|
url += `?${request.params.toString()}`;
|
|
@@ -186,6 +186,42 @@ var errorBuilder = (code, description, details, data) => {
|
|
|
186
186
|
};
|
|
187
187
|
};
|
|
188
188
|
|
|
189
|
+
// src/fetch-error.ts
|
|
190
|
+
var FetchErrorResponse = class extends Error {
|
|
191
|
+
constructor(message, response) {
|
|
192
|
+
super(message);
|
|
193
|
+
this.message = message;
|
|
194
|
+
this.response = response;
|
|
195
|
+
}
|
|
196
|
+
async details() {
|
|
197
|
+
const dataError = await this.response.json();
|
|
198
|
+
return errorBuilder2(
|
|
199
|
+
this.response.status,
|
|
200
|
+
dataError == null ? void 0 : dataError.message,
|
|
201
|
+
dataError == null ? void 0 : dataError.details,
|
|
202
|
+
{
|
|
203
|
+
requestId: this.response.headers.get("X-Wix-Request-Id"),
|
|
204
|
+
details: dataError
|
|
205
|
+
}
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
var errorBuilder2 = (code, description, details, data) => {
|
|
210
|
+
return {
|
|
211
|
+
details: {
|
|
212
|
+
...!(details == null ? void 0 : details.validationError) && {
|
|
213
|
+
applicationError: {
|
|
214
|
+
description,
|
|
215
|
+
code,
|
|
216
|
+
data
|
|
217
|
+
}
|
|
218
|
+
},
|
|
219
|
+
...details
|
|
220
|
+
},
|
|
221
|
+
message: description
|
|
222
|
+
};
|
|
223
|
+
};
|
|
224
|
+
|
|
189
225
|
// src/wixClient.ts
|
|
190
226
|
function createClient(config) {
|
|
191
227
|
const _headers = config.headers || { Authorization: "" };
|
|
@@ -247,6 +283,23 @@ function createClient(config) {
|
|
|
247
283
|
finalUrl.host = API_URL;
|
|
248
284
|
finalUrl.protocol = "https";
|
|
249
285
|
return boundFetch(finalUrl, options);
|
|
286
|
+
},
|
|
287
|
+
async graphql(query, variables) {
|
|
288
|
+
const res = await boundFetch(`https://${API_URL}/graphql`, {
|
|
289
|
+
method: "POST",
|
|
290
|
+
headers: {
|
|
291
|
+
"Content-Type": "application/json"
|
|
292
|
+
},
|
|
293
|
+
body: JSON.stringify({ query, variables })
|
|
294
|
+
});
|
|
295
|
+
if (res.status !== 200) {
|
|
296
|
+
throw new FetchErrorResponse(
|
|
297
|
+
`GraphQL request failed with status ${res.status}`,
|
|
298
|
+
res
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
const { data, errors } = await res.json();
|
|
302
|
+
return { data: data != null ? data : {}, errors };
|
|
250
303
|
}
|
|
251
304
|
};
|
|
252
305
|
}
|
|
@@ -913,5 +966,6 @@ export {
|
|
|
913
966
|
WixAppOAuthStrategy,
|
|
914
967
|
createClient,
|
|
915
968
|
decodeText,
|
|
969
|
+
getDefaultDomain,
|
|
916
970
|
media
|
|
917
971
|
};
|
package/build/index.d.mts
CHANGED
|
@@ -9,6 +9,8 @@ type PublicMetadata = {
|
|
|
9
9
|
};
|
|
10
10
|
declare const API_URL = "www.wixapis.com";
|
|
11
11
|
|
|
12
|
+
declare const getDefaultDomain: (method: string, url: string) => "www.wixapis.com" | "readonly.wixapis.com";
|
|
13
|
+
|
|
12
14
|
type RequestContext = {
|
|
13
15
|
isSSR: boolean;
|
|
14
16
|
host: string;
|
|
@@ -36,6 +38,45 @@ type AmbassadorFactory<Request, Response> = {
|
|
|
36
38
|
type AmbassadorFunctionDescriptor<Request = any, Response = any> = AmbassadorFactory<Request, Response>;
|
|
37
39
|
type BuildAmbassadorFunction<T extends AmbassadorFunctionDescriptor> = T extends AmbassadorFunctionDescriptor<infer Request, infer Response> ? (req: Request) => Promise<Response> : never;
|
|
38
40
|
|
|
41
|
+
/**
|
|
42
|
+
* Represents a location in a Source.
|
|
43
|
+
*/
|
|
44
|
+
interface SourceLocation {
|
|
45
|
+
readonly line: number;
|
|
46
|
+
readonly column: number;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* See: https://spec.graphql.org/draft/#sec-Errors
|
|
51
|
+
*/
|
|
52
|
+
interface GraphQLFormattedError {
|
|
53
|
+
/**
|
|
54
|
+
* A short, human-readable summary of the problem that **SHOULD NOT** change
|
|
55
|
+
* from occurrence to occurrence of the problem, except for purposes of
|
|
56
|
+
* localization.
|
|
57
|
+
*/
|
|
58
|
+
readonly message: string;
|
|
59
|
+
/**
|
|
60
|
+
* If an error can be associated to a particular point in the requested
|
|
61
|
+
* GraphQL document, it should contain a list of locations.
|
|
62
|
+
*/
|
|
63
|
+
readonly locations?: ReadonlyArray<SourceLocation>;
|
|
64
|
+
/**
|
|
65
|
+
* If an error can be associated to a particular field in the GraphQL result,
|
|
66
|
+
* it _must_ contain an entry with the key `path` that details the path of
|
|
67
|
+
* the response field which experienced the error. This allows clients to
|
|
68
|
+
* identify whether a null result is intentional or caused by a runtime error.
|
|
69
|
+
*/
|
|
70
|
+
readonly path?: ReadonlyArray<string | number>;
|
|
71
|
+
/**
|
|
72
|
+
* Reserved for implementors to extend the protocol however they see fit,
|
|
73
|
+
* and hence there are no additional restrictions on its contents.
|
|
74
|
+
*/
|
|
75
|
+
readonly extensions?: {
|
|
76
|
+
[key: string]: unknown;
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
39
80
|
type Headers = {
|
|
40
81
|
Authorization: string;
|
|
41
82
|
} & Record<string, string>;
|
|
@@ -70,11 +111,31 @@ type Descriptors = RESTFunctionDescriptor | AmbassadorFunctionDescriptor | HostM
|
|
|
70
111
|
type AssertHostMatches<T extends Descriptors, H extends Host<any>> = T extends HostModule<any, infer U> ? H extends undefined ? never : H extends U ? T : HostModule<any, H> : T extends RESTFunctionDescriptor<any> ? T : {
|
|
71
112
|
[Key in keyof T]: T[Key] extends Descriptors ? AssertHostMatches<T[Key], H> : T[Key];
|
|
72
113
|
};
|
|
114
|
+
type TypedQueryInput<Result = {
|
|
115
|
+
[key: string]: any;
|
|
116
|
+
}, Variables = {
|
|
117
|
+
[key: string]: any;
|
|
118
|
+
}> = {
|
|
119
|
+
/**
|
|
120
|
+
* Type to support `@graphql-typed-document-node/core`
|
|
121
|
+
* @internal
|
|
122
|
+
*/
|
|
123
|
+
__apiType?: (variables: Variables) => Result;
|
|
124
|
+
/**
|
|
125
|
+
* Type to support `TypedQueryDocumentNode` from `graphql`
|
|
126
|
+
* @internal
|
|
127
|
+
*/
|
|
128
|
+
__ensureTypesOfVariablesAndResultMatching?: (variables: Variables) => Result;
|
|
129
|
+
};
|
|
73
130
|
type WixClient<H extends Host<any> | undefined = undefined, Z extends AuthenticationStrategy<H> = AuthenticationStrategy<H>, T extends Descriptors = Descriptors> = {
|
|
74
131
|
setHeaders(headers: Headers): void;
|
|
75
132
|
auth: Z;
|
|
76
133
|
fetch(relativeUrl: string, options: RequestInit): Promise<Response>;
|
|
77
134
|
use<R extends Descriptors = EmptyObject>(modules: H extends Host<any> ? AssertHostMatches<R, H> : R): BuildDescriptors<R, H>;
|
|
135
|
+
graphql<Result, Variables>(query: string | (string & TypedQueryInput<Result, Variables>), variables?: Variables): Promise<{
|
|
136
|
+
data: Result;
|
|
137
|
+
errors?: GraphQLFormattedError[];
|
|
138
|
+
}>;
|
|
78
139
|
} & BuildDescriptors<T, H>;
|
|
79
140
|
declare function createClient<H extends Host<any> | undefined = undefined, Z extends AuthenticationStrategy<H> = AuthenticationStrategy<H>, T extends Descriptors = EmptyObject>(config: {
|
|
80
141
|
modules?: H extends Host<any> ? AssertHostMatches<T, H> : T;
|
|
@@ -307,4 +368,4 @@ declare function WixAppOAuthStrategy(opts: {
|
|
|
307
368
|
refreshToken?: string;
|
|
308
369
|
}): WixAppOAuthStrategy;
|
|
309
370
|
|
|
310
|
-
export { API_URL, AccessToken, ApiKeyStrategy, AssertHostMatches, BuildDescriptors, CalculateNextState, Descriptors, IApiKeyStrategy, IOAuthStrategy, LoginParams, LoginState, OAuthStrategy, OauthData, OauthPKCE, ProcessableState, RefreshToken, RegisterParams, StateMachine, Token, TokenResponse, TokenRole, Tokens, WixAppOAuthStrategy, WixClient, createClient, decodeText, media };
|
|
371
|
+
export { API_URL, AccessToken, ApiKeyStrategy, AssertHostMatches, BuildDescriptors, CalculateNextState, Descriptors, IApiKeyStrategy, IOAuthStrategy, LoginParams, LoginState, OAuthStrategy, OauthData, OauthPKCE, ProcessableState, RefreshToken, RegisterParams, StateMachine, Token, TokenResponse, TokenRole, Tokens, WixAppOAuthStrategy, WixClient, createClient, decodeText, getDefaultDomain, media };
|
package/build/index.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ type PublicMetadata = {
|
|
|
9
9
|
};
|
|
10
10
|
declare const API_URL = "www.wixapis.com";
|
|
11
11
|
|
|
12
|
+
declare const getDefaultDomain: (method: string, url: string) => "www.wixapis.com" | "readonly.wixapis.com";
|
|
13
|
+
|
|
12
14
|
type RequestContext = {
|
|
13
15
|
isSSR: boolean;
|
|
14
16
|
host: string;
|
|
@@ -36,6 +38,45 @@ type AmbassadorFactory<Request, Response> = {
|
|
|
36
38
|
type AmbassadorFunctionDescriptor<Request = any, Response = any> = AmbassadorFactory<Request, Response>;
|
|
37
39
|
type BuildAmbassadorFunction<T extends AmbassadorFunctionDescriptor> = T extends AmbassadorFunctionDescriptor<infer Request, infer Response> ? (req: Request) => Promise<Response> : never;
|
|
38
40
|
|
|
41
|
+
/**
|
|
42
|
+
* Represents a location in a Source.
|
|
43
|
+
*/
|
|
44
|
+
interface SourceLocation {
|
|
45
|
+
readonly line: number;
|
|
46
|
+
readonly column: number;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* See: https://spec.graphql.org/draft/#sec-Errors
|
|
51
|
+
*/
|
|
52
|
+
interface GraphQLFormattedError {
|
|
53
|
+
/**
|
|
54
|
+
* A short, human-readable summary of the problem that **SHOULD NOT** change
|
|
55
|
+
* from occurrence to occurrence of the problem, except for purposes of
|
|
56
|
+
* localization.
|
|
57
|
+
*/
|
|
58
|
+
readonly message: string;
|
|
59
|
+
/**
|
|
60
|
+
* If an error can be associated to a particular point in the requested
|
|
61
|
+
* GraphQL document, it should contain a list of locations.
|
|
62
|
+
*/
|
|
63
|
+
readonly locations?: ReadonlyArray<SourceLocation>;
|
|
64
|
+
/**
|
|
65
|
+
* If an error can be associated to a particular field in the GraphQL result,
|
|
66
|
+
* it _must_ contain an entry with the key `path` that details the path of
|
|
67
|
+
* the response field which experienced the error. This allows clients to
|
|
68
|
+
* identify whether a null result is intentional or caused by a runtime error.
|
|
69
|
+
*/
|
|
70
|
+
readonly path?: ReadonlyArray<string | number>;
|
|
71
|
+
/**
|
|
72
|
+
* Reserved for implementors to extend the protocol however they see fit,
|
|
73
|
+
* and hence there are no additional restrictions on its contents.
|
|
74
|
+
*/
|
|
75
|
+
readonly extensions?: {
|
|
76
|
+
[key: string]: unknown;
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
39
80
|
type Headers = {
|
|
40
81
|
Authorization: string;
|
|
41
82
|
} & Record<string, string>;
|
|
@@ -70,11 +111,31 @@ type Descriptors = RESTFunctionDescriptor | AmbassadorFunctionDescriptor | HostM
|
|
|
70
111
|
type AssertHostMatches<T extends Descriptors, H extends Host<any>> = T extends HostModule<any, infer U> ? H extends undefined ? never : H extends U ? T : HostModule<any, H> : T extends RESTFunctionDescriptor<any> ? T : {
|
|
71
112
|
[Key in keyof T]: T[Key] extends Descriptors ? AssertHostMatches<T[Key], H> : T[Key];
|
|
72
113
|
};
|
|
114
|
+
type TypedQueryInput<Result = {
|
|
115
|
+
[key: string]: any;
|
|
116
|
+
}, Variables = {
|
|
117
|
+
[key: string]: any;
|
|
118
|
+
}> = {
|
|
119
|
+
/**
|
|
120
|
+
* Type to support `@graphql-typed-document-node/core`
|
|
121
|
+
* @internal
|
|
122
|
+
*/
|
|
123
|
+
__apiType?: (variables: Variables) => Result;
|
|
124
|
+
/**
|
|
125
|
+
* Type to support `TypedQueryDocumentNode` from `graphql`
|
|
126
|
+
* @internal
|
|
127
|
+
*/
|
|
128
|
+
__ensureTypesOfVariablesAndResultMatching?: (variables: Variables) => Result;
|
|
129
|
+
};
|
|
73
130
|
type WixClient<H extends Host<any> | undefined = undefined, Z extends AuthenticationStrategy<H> = AuthenticationStrategy<H>, T extends Descriptors = Descriptors> = {
|
|
74
131
|
setHeaders(headers: Headers): void;
|
|
75
132
|
auth: Z;
|
|
76
133
|
fetch(relativeUrl: string, options: RequestInit): Promise<Response>;
|
|
77
134
|
use<R extends Descriptors = EmptyObject>(modules: H extends Host<any> ? AssertHostMatches<R, H> : R): BuildDescriptors<R, H>;
|
|
135
|
+
graphql<Result, Variables>(query: string | (string & TypedQueryInput<Result, Variables>), variables?: Variables): Promise<{
|
|
136
|
+
data: Result;
|
|
137
|
+
errors?: GraphQLFormattedError[];
|
|
138
|
+
}>;
|
|
78
139
|
} & BuildDescriptors<T, H>;
|
|
79
140
|
declare function createClient<H extends Host<any> | undefined = undefined, Z extends AuthenticationStrategy<H> = AuthenticationStrategy<H>, T extends Descriptors = EmptyObject>(config: {
|
|
80
141
|
modules?: H extends Host<any> ? AssertHostMatches<T, H> : T;
|
|
@@ -307,4 +368,4 @@ declare function WixAppOAuthStrategy(opts: {
|
|
|
307
368
|
refreshToken?: string;
|
|
308
369
|
}): WixAppOAuthStrategy;
|
|
309
370
|
|
|
310
|
-
export { API_URL, AccessToken, ApiKeyStrategy, AssertHostMatches, BuildDescriptors, CalculateNextState, Descriptors, IApiKeyStrategy, IOAuthStrategy, LoginParams, LoginState, OAuthStrategy, OauthData, OauthPKCE, ProcessableState, RefreshToken, RegisterParams, StateMachine, Token, TokenResponse, TokenRole, Tokens, WixAppOAuthStrategy, WixClient, createClient, decodeText, media };
|
|
371
|
+
export { API_URL, AccessToken, ApiKeyStrategy, AssertHostMatches, BuildDescriptors, CalculateNextState, Descriptors, IApiKeyStrategy, IOAuthStrategy, LoginParams, LoginState, OAuthStrategy, OauthData, OauthPKCE, ProcessableState, RefreshToken, RegisterParams, StateMachine, Token, TokenResponse, TokenRole, Tokens, WixAppOAuthStrategy, WixClient, createClient, decodeText, getDefaultDomain, media };
|
package/build/index.js
CHANGED
|
@@ -39,6 +39,7 @@ __export(src_exports, {
|
|
|
39
39
|
WixAppOAuthStrategy: () => WixAppOAuthStrategy,
|
|
40
40
|
createClient: () => createClient,
|
|
41
41
|
decodeText: () => decodeText,
|
|
42
|
+
getDefaultDomain: () => getDefaultDomain,
|
|
42
43
|
media: () => media
|
|
43
44
|
});
|
|
44
45
|
module.exports = __toCommonJS(src_exports);
|
|
@@ -151,6 +152,7 @@ function objectToKeyValue(input) {
|
|
|
151
152
|
}
|
|
152
153
|
|
|
153
154
|
// src/rest-modules.ts
|
|
155
|
+
var getDefaultDomain = (method, url) => method === "GET" && !FORCE_WRITE_API_URLS.some((write_url) => url === write_url) ? READ_ONLY_API_URL : API_URL;
|
|
154
156
|
function buildRESTDescriptor(origFunc, publicMetadata, boundFetch, options) {
|
|
155
157
|
return origFunc({
|
|
156
158
|
request: async (factory) => {
|
|
@@ -159,8 +161,7 @@ function buildRESTDescriptor(origFunc, publicMetadata, boundFetch, options) {
|
|
|
159
161
|
if (request.method === "GET" && request.fallback?.length && request.params.toString().length > 4e3) {
|
|
160
162
|
request = requestOptions.fallback[0];
|
|
161
163
|
}
|
|
162
|
-
const
|
|
163
|
-
const domain = options?.HTTPHost ?? getDefaultDomain();
|
|
164
|
+
const domain = options?.HTTPHost ?? getDefaultDomain(request.method, request.url);
|
|
164
165
|
let url = `https://${domain}${request.url}`;
|
|
165
166
|
if (request.params && request.params.toString()) {
|
|
166
167
|
url += `?${request.params.toString()}`;
|
|
@@ -229,6 +230,42 @@ var errorBuilder = (code, description, details, data) => {
|
|
|
229
230
|
};
|
|
230
231
|
};
|
|
231
232
|
|
|
233
|
+
// src/fetch-error.ts
|
|
234
|
+
var FetchErrorResponse = class extends Error {
|
|
235
|
+
constructor(message, response) {
|
|
236
|
+
super(message);
|
|
237
|
+
this.message = message;
|
|
238
|
+
this.response = response;
|
|
239
|
+
}
|
|
240
|
+
async details() {
|
|
241
|
+
const dataError = await this.response.json();
|
|
242
|
+
return errorBuilder2(
|
|
243
|
+
this.response.status,
|
|
244
|
+
dataError?.message,
|
|
245
|
+
dataError?.details,
|
|
246
|
+
{
|
|
247
|
+
requestId: this.response.headers.get("X-Wix-Request-Id"),
|
|
248
|
+
details: dataError
|
|
249
|
+
}
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
var errorBuilder2 = (code, description, details, data) => {
|
|
254
|
+
return {
|
|
255
|
+
details: {
|
|
256
|
+
...!details?.validationError && {
|
|
257
|
+
applicationError: {
|
|
258
|
+
description,
|
|
259
|
+
code,
|
|
260
|
+
data
|
|
261
|
+
}
|
|
262
|
+
},
|
|
263
|
+
...details
|
|
264
|
+
},
|
|
265
|
+
message: description
|
|
266
|
+
};
|
|
267
|
+
};
|
|
268
|
+
|
|
232
269
|
// src/wixClient.ts
|
|
233
270
|
function createClient(config) {
|
|
234
271
|
const _headers = config.headers || { Authorization: "" };
|
|
@@ -290,6 +327,23 @@ function createClient(config) {
|
|
|
290
327
|
finalUrl.host = API_URL;
|
|
291
328
|
finalUrl.protocol = "https";
|
|
292
329
|
return boundFetch(finalUrl, options);
|
|
330
|
+
},
|
|
331
|
+
async graphql(query, variables) {
|
|
332
|
+
const res = await boundFetch(`https://${API_URL}/graphql`, {
|
|
333
|
+
method: "POST",
|
|
334
|
+
headers: {
|
|
335
|
+
"Content-Type": "application/json"
|
|
336
|
+
},
|
|
337
|
+
body: JSON.stringify({ query, variables })
|
|
338
|
+
});
|
|
339
|
+
if (res.status !== 200) {
|
|
340
|
+
throw new FetchErrorResponse(
|
|
341
|
+
`GraphQL request failed with status ${res.status}`,
|
|
342
|
+
res
|
|
343
|
+
);
|
|
344
|
+
}
|
|
345
|
+
const { data, errors } = await res.json();
|
|
346
|
+
return { data: data ?? {}, errors };
|
|
293
347
|
}
|
|
294
348
|
};
|
|
295
349
|
}
|
|
@@ -950,6 +1004,7 @@ __reExport(src_exports, require("@wix/sdk-types"), module.exports);
|
|
|
950
1004
|
WixAppOAuthStrategy,
|
|
951
1005
|
createClient,
|
|
952
1006
|
decodeText,
|
|
1007
|
+
getDefaultDomain,
|
|
953
1008
|
media,
|
|
954
1009
|
...require("@wix/sdk-types")
|
|
955
1010
|
});
|
package/build/index.mjs
CHANGED
|
@@ -106,6 +106,7 @@ function objectToKeyValue(input) {
|
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
// src/rest-modules.ts
|
|
109
|
+
var getDefaultDomain = (method, url) => method === "GET" && !FORCE_WRITE_API_URLS.some((write_url) => url === write_url) ? READ_ONLY_API_URL : API_URL;
|
|
109
110
|
function buildRESTDescriptor(origFunc, publicMetadata, boundFetch, options) {
|
|
110
111
|
return origFunc({
|
|
111
112
|
request: async (factory) => {
|
|
@@ -114,8 +115,7 @@ function buildRESTDescriptor(origFunc, publicMetadata, boundFetch, options) {
|
|
|
114
115
|
if (request.method === "GET" && request.fallback?.length && request.params.toString().length > 4e3) {
|
|
115
116
|
request = requestOptions.fallback[0];
|
|
116
117
|
}
|
|
117
|
-
const
|
|
118
|
-
const domain = options?.HTTPHost ?? getDefaultDomain();
|
|
118
|
+
const domain = options?.HTTPHost ?? getDefaultDomain(request.method, request.url);
|
|
119
119
|
let url = `https://${domain}${request.url}`;
|
|
120
120
|
if (request.params && request.params.toString()) {
|
|
121
121
|
url += `?${request.params.toString()}`;
|
|
@@ -184,6 +184,42 @@ var errorBuilder = (code, description, details, data) => {
|
|
|
184
184
|
};
|
|
185
185
|
};
|
|
186
186
|
|
|
187
|
+
// src/fetch-error.ts
|
|
188
|
+
var FetchErrorResponse = class extends Error {
|
|
189
|
+
constructor(message, response) {
|
|
190
|
+
super(message);
|
|
191
|
+
this.message = message;
|
|
192
|
+
this.response = response;
|
|
193
|
+
}
|
|
194
|
+
async details() {
|
|
195
|
+
const dataError = await this.response.json();
|
|
196
|
+
return errorBuilder2(
|
|
197
|
+
this.response.status,
|
|
198
|
+
dataError?.message,
|
|
199
|
+
dataError?.details,
|
|
200
|
+
{
|
|
201
|
+
requestId: this.response.headers.get("X-Wix-Request-Id"),
|
|
202
|
+
details: dataError
|
|
203
|
+
}
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
var errorBuilder2 = (code, description, details, data) => {
|
|
208
|
+
return {
|
|
209
|
+
details: {
|
|
210
|
+
...!details?.validationError && {
|
|
211
|
+
applicationError: {
|
|
212
|
+
description,
|
|
213
|
+
code,
|
|
214
|
+
data
|
|
215
|
+
}
|
|
216
|
+
},
|
|
217
|
+
...details
|
|
218
|
+
},
|
|
219
|
+
message: description
|
|
220
|
+
};
|
|
221
|
+
};
|
|
222
|
+
|
|
187
223
|
// src/wixClient.ts
|
|
188
224
|
function createClient(config) {
|
|
189
225
|
const _headers = config.headers || { Authorization: "" };
|
|
@@ -245,6 +281,23 @@ function createClient(config) {
|
|
|
245
281
|
finalUrl.host = API_URL;
|
|
246
282
|
finalUrl.protocol = "https";
|
|
247
283
|
return boundFetch(finalUrl, options);
|
|
284
|
+
},
|
|
285
|
+
async graphql(query, variables) {
|
|
286
|
+
const res = await boundFetch(`https://${API_URL}/graphql`, {
|
|
287
|
+
method: "POST",
|
|
288
|
+
headers: {
|
|
289
|
+
"Content-Type": "application/json"
|
|
290
|
+
},
|
|
291
|
+
body: JSON.stringify({ query, variables })
|
|
292
|
+
});
|
|
293
|
+
if (res.status !== 200) {
|
|
294
|
+
throw new FetchErrorResponse(
|
|
295
|
+
`GraphQL request failed with status ${res.status}`,
|
|
296
|
+
res
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
const { data, errors } = await res.json();
|
|
300
|
+
return { data: data ?? {}, errors };
|
|
248
301
|
}
|
|
249
302
|
};
|
|
250
303
|
}
|
|
@@ -904,5 +957,6 @@ export {
|
|
|
904
957
|
WixAppOAuthStrategy,
|
|
905
958
|
createClient,
|
|
906
959
|
decodeText,
|
|
960
|
+
getDefaultDomain,
|
|
907
961
|
media
|
|
908
962
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Ronny Ringel",
|
|
@@ -31,26 +31,30 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@babel/runtime": "^7.22.15",
|
|
34
|
-
"@wix/identity": "^1.0.
|
|
34
|
+
"@wix/identity": "^1.0.57",
|
|
35
35
|
"@wix/image-kit": "^1.37.0",
|
|
36
|
-
"@wix/metro-runtime": "^1.
|
|
36
|
+
"@wix/metro-runtime": "^1.1529.0",
|
|
37
37
|
"@wix/redirects": "^1.0.24",
|
|
38
|
-
"@wix/sdk-types": "1.
|
|
38
|
+
"@wix/sdk-types": "1.5.0",
|
|
39
39
|
"pkce-challenge": "^3.1.0",
|
|
40
40
|
"querystring": "^0.2.1",
|
|
41
41
|
"type-fest": "^3.13.1"
|
|
42
42
|
},
|
|
43
|
+
"optionalDependencies": {
|
|
44
|
+
"graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0"
|
|
45
|
+
},
|
|
43
46
|
"devDependencies": {
|
|
44
47
|
"@swc/core": "^1.3.83",
|
|
45
48
|
"@swc/jest": "^0.2.29",
|
|
46
49
|
"@types/jest": "^27.5.2",
|
|
47
50
|
"@types/node": "^16.18.50",
|
|
48
51
|
"@types/node-fetch": "^2.6.4",
|
|
49
|
-
"@wix/ecom": "^1.0.
|
|
52
|
+
"@wix/ecom": "^1.0.353",
|
|
50
53
|
"@wix/events": "^1.0.117",
|
|
51
54
|
"@wix/metro": "^1.0.67",
|
|
52
55
|
"eslint": "^7.32.0",
|
|
53
56
|
"eslint-config-sdk": "0.0.0",
|
|
57
|
+
"graphql": "16.8.0",
|
|
54
58
|
"is-ci": "^3.0.1",
|
|
55
59
|
"jest": "^27.5.1",
|
|
56
60
|
"jest-teamcity": "^1.11.0",
|
|
@@ -83,5 +87,5 @@
|
|
|
83
87
|
"wallaby": {
|
|
84
88
|
"autoDetect": true
|
|
85
89
|
},
|
|
86
|
-
"falconPackageHash": "
|
|
90
|
+
"falconPackageHash": "979b294b107b16bf496a7f4a836bf08aae79eb2ceba6528b9424a8a6"
|
|
87
91
|
}
|