@wix/essentials 0.1.4 → 0.1.6
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/auth.d.ts +19 -0
- package/build/auth.js +18 -0
- package/build/http-client.d.ts +0 -9
- package/build/http-client.js +9 -42
- package/cjs/build/auth.d.ts +19 -0
- package/cjs/build/auth.js +19 -1
- package/cjs/build/http-client.d.ts +0 -9
- package/cjs/build/http-client.js +10 -44
- package/package.json +7 -7
package/build/auth.d.ts
CHANGED
|
@@ -1,2 +1,21 @@
|
|
|
1
1
|
import { RESTFunctionDescriptor } from '@wix/sdk-types';
|
|
2
2
|
export declare function elevate<T extends RESTFunctionDescriptor>(restModule: T): T;
|
|
3
|
+
export declare const getTokenInfo: (() => Promise<{
|
|
4
|
+
active: boolean;
|
|
5
|
+
subjectType: 'APP' | 'USER' | 'MEMBER' | 'VISITOR' | 'UNKNOWN';
|
|
6
|
+
subjectId: string;
|
|
7
|
+
exp: number;
|
|
8
|
+
iat: number;
|
|
9
|
+
clientId?: string | undefined;
|
|
10
|
+
siteId: string;
|
|
11
|
+
instanceId?: string | undefined;
|
|
12
|
+
}>) & ((restModuleOpts: import("@wix/sdk-types").HttpClient) => () => Promise<{
|
|
13
|
+
active: boolean;
|
|
14
|
+
subjectType: 'APP' | 'USER' | 'MEMBER' | 'VISITOR' | 'UNKNOWN';
|
|
15
|
+
subjectId: string;
|
|
16
|
+
exp: number;
|
|
17
|
+
iat: number;
|
|
18
|
+
clientId?: string | undefined;
|
|
19
|
+
siteId: string;
|
|
20
|
+
instanceId?: string | undefined;
|
|
21
|
+
}>);
|
package/build/auth.js
CHANGED
|
@@ -2,3 +2,21 @@ import { createRESTModule } from '@wix/sdk-runtime/rest-modules';
|
|
|
2
2
|
export function elevate(restModule) {
|
|
3
3
|
return createRESTModule(restModule, true);
|
|
4
4
|
}
|
|
5
|
+
export const getTokenInfo = createRESTModule((restModuleOpts) => {
|
|
6
|
+
return async () => {
|
|
7
|
+
if (!restModuleOpts.getActiveToken) {
|
|
8
|
+
throw new Error('Unable to get the currently active token. Please make sure you are using an authentication strategy that supports this operation.');
|
|
9
|
+
}
|
|
10
|
+
const res = await restModuleOpts.fetchWithAuth('https://www.wixapis.com/oauth2/token-info', {
|
|
11
|
+
method: 'POST',
|
|
12
|
+
body: JSON.stringify({ token: restModuleOpts.getActiveToken() }),
|
|
13
|
+
headers: {
|
|
14
|
+
'Content-Type': 'application/json',
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
if (!res.ok) {
|
|
18
|
+
throw new Error(`Failed to fetch token info: ${res.status} - ${res.statusText}. ${await res.text()}`);
|
|
19
|
+
}
|
|
20
|
+
return res.json();
|
|
21
|
+
};
|
|
22
|
+
});
|
package/build/http-client.d.ts
CHANGED
|
@@ -28,12 +28,3 @@ export type TypedQueryInput<Result = {
|
|
|
28
28
|
*/
|
|
29
29
|
__ensureTypesOfVariablesAndResultMatching?: (variables: Variables) => Result;
|
|
30
30
|
};
|
|
31
|
-
export declare class FetchErrorResponse extends Error {
|
|
32
|
-
readonly message: string;
|
|
33
|
-
readonly response: Response;
|
|
34
|
-
constructor(message: string, response: Response);
|
|
35
|
-
details(): Promise<{
|
|
36
|
-
details: any;
|
|
37
|
-
message: string;
|
|
38
|
-
}>;
|
|
39
|
-
}
|
package/build/http-client.js
CHANGED
|
@@ -7,48 +7,15 @@ export const graphql = createRESTModule(((restModuleOpts) => {
|
|
|
7
7
|
return async function graphql(query, variables, opts = {
|
|
8
8
|
apiVersion: 'alpha',
|
|
9
9
|
}) {
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
const result = await restModuleOpts.request(({ host }) => {
|
|
11
|
+
const basePath = host === 'www.wixapis.com' ? '/graphql' : '/_api/graphql';
|
|
12
|
+
return {
|
|
13
|
+
method: 'POST',
|
|
14
|
+
url: `${basePath}/${opts.apiVersion}`,
|
|
15
|
+
data: { query, variables },
|
|
16
|
+
packageName: '@wix/essentials',
|
|
17
|
+
};
|
|
16
18
|
});
|
|
17
|
-
|
|
18
|
-
throw new FetchErrorResponse(`GraphQL request failed with status ${res.status}`, res);
|
|
19
|
-
}
|
|
20
|
-
const { data, errors } = await res.json();
|
|
21
|
-
return { data: data ?? {}, errors };
|
|
19
|
+
return result.data;
|
|
22
20
|
};
|
|
23
21
|
}));
|
|
24
|
-
export class FetchErrorResponse extends Error {
|
|
25
|
-
message;
|
|
26
|
-
response;
|
|
27
|
-
constructor(message, response) {
|
|
28
|
-
super(message);
|
|
29
|
-
this.message = message;
|
|
30
|
-
this.response = response;
|
|
31
|
-
}
|
|
32
|
-
async details() {
|
|
33
|
-
const dataError = await this.response.json();
|
|
34
|
-
return errorBuilder(this.response.status, dataError?.message, dataError?.details, {
|
|
35
|
-
requestId: this.response.headers.get('X-Wix-Request-Id'),
|
|
36
|
-
details: dataError,
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
const errorBuilder = (code, description, details, data) => {
|
|
41
|
-
return {
|
|
42
|
-
details: {
|
|
43
|
-
...(!details?.validationError && {
|
|
44
|
-
applicationError: {
|
|
45
|
-
description,
|
|
46
|
-
code,
|
|
47
|
-
data,
|
|
48
|
-
},
|
|
49
|
-
}),
|
|
50
|
-
...details,
|
|
51
|
-
},
|
|
52
|
-
message: description,
|
|
53
|
-
};
|
|
54
|
-
};
|
package/cjs/build/auth.d.ts
CHANGED
|
@@ -1,2 +1,21 @@
|
|
|
1
1
|
import { RESTFunctionDescriptor } from '@wix/sdk-types';
|
|
2
2
|
export declare function elevate<T extends RESTFunctionDescriptor>(restModule: T): T;
|
|
3
|
+
export declare const getTokenInfo: (() => Promise<{
|
|
4
|
+
active: boolean;
|
|
5
|
+
subjectType: 'APP' | 'USER' | 'MEMBER' | 'VISITOR' | 'UNKNOWN';
|
|
6
|
+
subjectId: string;
|
|
7
|
+
exp: number;
|
|
8
|
+
iat: number;
|
|
9
|
+
clientId?: string | undefined;
|
|
10
|
+
siteId: string;
|
|
11
|
+
instanceId?: string | undefined;
|
|
12
|
+
}>) & ((restModuleOpts: import("@wix/sdk-types").HttpClient) => () => Promise<{
|
|
13
|
+
active: boolean;
|
|
14
|
+
subjectType: 'APP' | 'USER' | 'MEMBER' | 'VISITOR' | 'UNKNOWN';
|
|
15
|
+
subjectId: string;
|
|
16
|
+
exp: number;
|
|
17
|
+
iat: number;
|
|
18
|
+
clientId?: string | undefined;
|
|
19
|
+
siteId: string;
|
|
20
|
+
instanceId?: string | undefined;
|
|
21
|
+
}>);
|
package/cjs/build/auth.js
CHANGED
|
@@ -1,8 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.elevate = void 0;
|
|
3
|
+
exports.getTokenInfo = exports.elevate = void 0;
|
|
4
4
|
const rest_modules_1 = require("@wix/sdk-runtime/rest-modules");
|
|
5
5
|
function elevate(restModule) {
|
|
6
6
|
return (0, rest_modules_1.createRESTModule)(restModule, true);
|
|
7
7
|
}
|
|
8
8
|
exports.elevate = elevate;
|
|
9
|
+
exports.getTokenInfo = (0, rest_modules_1.createRESTModule)((restModuleOpts) => {
|
|
10
|
+
return async () => {
|
|
11
|
+
if (!restModuleOpts.getActiveToken) {
|
|
12
|
+
throw new Error('Unable to get the currently active token. Please make sure you are using an authentication strategy that supports this operation.');
|
|
13
|
+
}
|
|
14
|
+
const res = await restModuleOpts.fetchWithAuth('https://www.wixapis.com/oauth2/token-info', {
|
|
15
|
+
method: 'POST',
|
|
16
|
+
body: JSON.stringify({ token: restModuleOpts.getActiveToken() }),
|
|
17
|
+
headers: {
|
|
18
|
+
'Content-Type': 'application/json',
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
if (!res.ok) {
|
|
22
|
+
throw new Error(`Failed to fetch token info: ${res.status} - ${res.statusText}. ${await res.text()}`);
|
|
23
|
+
}
|
|
24
|
+
return res.json();
|
|
25
|
+
};
|
|
26
|
+
});
|
|
@@ -28,12 +28,3 @@ export type TypedQueryInput<Result = {
|
|
|
28
28
|
*/
|
|
29
29
|
__ensureTypesOfVariablesAndResultMatching?: (variables: Variables) => Result;
|
|
30
30
|
};
|
|
31
|
-
export declare class FetchErrorResponse extends Error {
|
|
32
|
-
readonly message: string;
|
|
33
|
-
readonly response: Response;
|
|
34
|
-
constructor(message: string, response: Response);
|
|
35
|
-
details(): Promise<{
|
|
36
|
-
details: any;
|
|
37
|
-
message: string;
|
|
38
|
-
}>;
|
|
39
|
-
}
|
package/cjs/build/http-client.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.graphql = exports.fetchWithAuth = void 0;
|
|
4
4
|
const rest_modules_1 = require("@wix/sdk-runtime/rest-modules");
|
|
5
5
|
exports.fetchWithAuth = (0, rest_modules_1.createRESTModule)((restModuleOpts) => {
|
|
6
6
|
return ((url, options) => restModuleOpts.fetchWithAuth(url, options));
|
|
@@ -10,49 +10,15 @@ exports.graphql = (0, rest_modules_1.createRESTModule)(((restModuleOpts) => {
|
|
|
10
10
|
return async function graphql(query, variables, opts = {
|
|
11
11
|
apiVersion: 'alpha',
|
|
12
12
|
}) {
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
const result = await restModuleOpts.request(({ host }) => {
|
|
14
|
+
const basePath = host === 'www.wixapis.com' ? '/graphql' : '/_api/graphql';
|
|
15
|
+
return {
|
|
16
|
+
method: 'POST',
|
|
17
|
+
url: `${basePath}/${opts.apiVersion}`,
|
|
18
|
+
data: { query, variables },
|
|
19
|
+
packageName: '@wix/essentials',
|
|
20
|
+
};
|
|
19
21
|
});
|
|
20
|
-
|
|
21
|
-
throw new FetchErrorResponse(`GraphQL request failed with status ${res.status}`, res);
|
|
22
|
-
}
|
|
23
|
-
const { data, errors } = await res.json();
|
|
24
|
-
return { data: data ?? {}, errors };
|
|
22
|
+
return result.data;
|
|
25
23
|
};
|
|
26
24
|
}));
|
|
27
|
-
class FetchErrorResponse extends Error {
|
|
28
|
-
message;
|
|
29
|
-
response;
|
|
30
|
-
constructor(message, response) {
|
|
31
|
-
super(message);
|
|
32
|
-
this.message = message;
|
|
33
|
-
this.response = response;
|
|
34
|
-
}
|
|
35
|
-
async details() {
|
|
36
|
-
const dataError = await this.response.json();
|
|
37
|
-
return errorBuilder(this.response.status, dataError?.message, dataError?.details, {
|
|
38
|
-
requestId: this.response.headers.get('X-Wix-Request-Id'),
|
|
39
|
-
details: dataError,
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
exports.FetchErrorResponse = FetchErrorResponse;
|
|
44
|
-
const errorBuilder = (code, description, details, data) => {
|
|
45
|
-
return {
|
|
46
|
-
details: {
|
|
47
|
-
...(!details?.validationError && {
|
|
48
|
-
applicationError: {
|
|
49
|
-
description,
|
|
50
|
-
code,
|
|
51
|
-
data,
|
|
52
|
-
},
|
|
53
|
-
}),
|
|
54
|
-
...details,
|
|
55
|
-
},
|
|
56
|
-
message: description,
|
|
57
|
-
};
|
|
58
|
-
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/essentials",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"main": "cjs/build/index.js",
|
|
6
6
|
"module": "build/index.mjs",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
},
|
|
23
23
|
"scripts": {
|
|
24
24
|
"build": "tsc && tsc --project tsconfig.cjs.json",
|
|
25
|
-
"test": "
|
|
25
|
+
"test": "vitest",
|
|
26
26
|
"lint": "eslint --max-warnings=0 .",
|
|
27
27
|
"lint:fix": "eslint --max-warnings=0 . --fix",
|
|
28
28
|
"typecheck": "tsc --noEmit"
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"*.{js,ts}": "yarn lint"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@wix/sdk-runtime": "^0.3.
|
|
35
|
-
"@wix/sdk-types": "^1.
|
|
34
|
+
"@wix/sdk-runtime": "^0.3.19",
|
|
35
|
+
"@wix/sdk-types": "^1.12.0"
|
|
36
36
|
},
|
|
37
37
|
"optionalDependencies": {
|
|
38
38
|
"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"
|
|
@@ -41,13 +41,13 @@
|
|
|
41
41
|
"@types/is-ci": "^3.0.4",
|
|
42
42
|
"@types/node": "^20.10.6",
|
|
43
43
|
"@vitest/ui": "^1.5.0",
|
|
44
|
-
"@wix/sdk
|
|
44
|
+
"@wix/sdk": "1.12.14",
|
|
45
45
|
"eslint": "^8.56.0",
|
|
46
46
|
"eslint-config-sdk": "0.0.0",
|
|
47
47
|
"graphql": "^16.8.0",
|
|
48
48
|
"is-ci": "^3.0.1",
|
|
49
49
|
"jsdom": "^22.1.0",
|
|
50
|
-
"msw": "^2.
|
|
50
|
+
"msw": "^2.4.5",
|
|
51
51
|
"typescript": "^5.3.3",
|
|
52
52
|
"vitest": "^1.5.0",
|
|
53
53
|
"vitest-teamcity-reporter": "^0.3.0"
|
|
@@ -69,5 +69,5 @@
|
|
|
69
69
|
]
|
|
70
70
|
}
|
|
71
71
|
},
|
|
72
|
-
"falconPackageHash": "
|
|
72
|
+
"falconPackageHash": "31bf6b618b6d87c3608612f6081ce2043607fa9e92701cc38acb0f51"
|
|
73
73
|
}
|