@wix/essentials 0.1.7 → 0.1.9
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 +52 -6
- package/build/auth.js +47 -1
- package/build/http-client.d.ts +4 -4
- package/cjs/build/auth.d.ts +52 -6
- package/cjs/build/auth.js +49 -3
- package/cjs/build/http-client.d.ts +4 -4
- package/package.json +15 -12
package/build/auth.d.ts
CHANGED
|
@@ -1,21 +1,67 @@
|
|
|
1
1
|
import { RESTFunctionDescriptor } from '@wix/sdk-types';
|
|
2
2
|
export declare function elevate<T extends RESTFunctionDescriptor>(restModule: T): T;
|
|
3
|
+
/**
|
|
4
|
+
* Returns the information encoded in the currently active token in API backend extensions.
|
|
5
|
+
*
|
|
6
|
+
* When developing API backend extensions you might need to access information about the session that is making the request.
|
|
7
|
+
*
|
|
8
|
+
* This can include the user ID, the site ID, the instance ID, and more. This information is encoded in the token that is sent with the request
|
|
9
|
+
* and can be accessed using this function.
|
|
10
|
+
* @returns A promise that resolves to the token info.
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* // In an API backend extension in a Wix CLI project
|
|
14
|
+
* import { auth } from '@wix/essentials';
|
|
15
|
+
*
|
|
16
|
+
* export async function GET(req: Request) {
|
|
17
|
+
* const tokenInfo = await auth.getTokenInfo();
|
|
18
|
+
*
|
|
19
|
+
* if (tokenInfo.subjectType === 'USER') {
|
|
20
|
+
* return new Response(`Hello user ${tokenInfo.subjectId}`);
|
|
21
|
+
* } else if (tokenInfo.subjectType === 'APP') {
|
|
22
|
+
* return new Response('Hello app');
|
|
23
|
+
* } else if (tokenInfo.subjectType === 'MEMBER') {
|
|
24
|
+
* return new Response(`Hello member ${tokenInfo.subjectId}`);
|
|
25
|
+
* } else {
|
|
26
|
+
* return new Response(`Hello visitor ${tokenInfo.subjectId}`);
|
|
27
|
+
* }
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* // In a Velo web method
|
|
33
|
+
* import { auth } from '@wix/essentials';
|
|
34
|
+
* import { Permissions, webMethod } from 'wix-web-module';
|
|
35
|
+
*
|
|
36
|
+
* export const sayHello = webMethod(Permimissions.Anyone, async () => {
|
|
37
|
+
* const tokenInfo = await auth.getTokenInfo();
|
|
38
|
+
*
|
|
39
|
+
* if (tokenInfo.subjectType === 'USER') {
|
|
40
|
+
* return `Hello user ${tokenInfo.subjectId}`;
|
|
41
|
+
* } else if (tokenInfo.subjectType === 'APP') {
|
|
42
|
+
* return 'Hello app';
|
|
43
|
+
* } else if (tokenInfo.subjectType === 'MEMBER') {
|
|
44
|
+
* return `Hello member ${tokenInfo.subjectId}`;
|
|
45
|
+
* } else {
|
|
46
|
+
* return `Hello visitor ${tokenInfo.subjectId}`;
|
|
47
|
+
* }
|
|
48
|
+
*/
|
|
3
49
|
export declare const getTokenInfo: (() => Promise<{
|
|
4
50
|
active: boolean;
|
|
5
|
-
subjectType:
|
|
51
|
+
subjectType: "APP" | "USER" | "MEMBER" | "VISITOR" | "UNKNOWN";
|
|
6
52
|
subjectId: string;
|
|
7
53
|
exp: number;
|
|
8
54
|
iat: number;
|
|
9
|
-
clientId?: string
|
|
55
|
+
clientId?: string;
|
|
10
56
|
siteId: string;
|
|
11
|
-
instanceId?: string
|
|
57
|
+
instanceId?: string;
|
|
12
58
|
}>) & ((restModuleOpts: import("@wix/sdk-types").HttpClient) => () => Promise<{
|
|
13
59
|
active: boolean;
|
|
14
|
-
subjectType:
|
|
60
|
+
subjectType: "APP" | "USER" | "MEMBER" | "VISITOR" | "UNKNOWN";
|
|
15
61
|
subjectId: string;
|
|
16
62
|
exp: number;
|
|
17
63
|
iat: number;
|
|
18
|
-
clientId?: string
|
|
64
|
+
clientId?: string;
|
|
19
65
|
siteId: string;
|
|
20
|
-
instanceId?: string
|
|
66
|
+
instanceId?: string;
|
|
21
67
|
}>);
|
package/build/auth.js
CHANGED
|
@@ -2,12 +2,58 @@ import { createRESTModule } from '@wix/sdk-runtime/rest-modules';
|
|
|
2
2
|
export function elevate(restModule) {
|
|
3
3
|
return createRESTModule(restModule, true);
|
|
4
4
|
}
|
|
5
|
+
/**
|
|
6
|
+
* Returns the information encoded in the currently active token in API backend extensions.
|
|
7
|
+
*
|
|
8
|
+
* When developing API backend extensions you might need to access information about the session that is making the request.
|
|
9
|
+
*
|
|
10
|
+
* This can include the user ID, the site ID, the instance ID, and more. This information is encoded in the token that is sent with the request
|
|
11
|
+
* and can be accessed using this function.
|
|
12
|
+
* @returns A promise that resolves to the token info.
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* // In an API backend extension in a Wix CLI project
|
|
16
|
+
* import { auth } from '@wix/essentials';
|
|
17
|
+
*
|
|
18
|
+
* export async function GET(req: Request) {
|
|
19
|
+
* const tokenInfo = await auth.getTokenInfo();
|
|
20
|
+
*
|
|
21
|
+
* if (tokenInfo.subjectType === 'USER') {
|
|
22
|
+
* return new Response(`Hello user ${tokenInfo.subjectId}`);
|
|
23
|
+
* } else if (tokenInfo.subjectType === 'APP') {
|
|
24
|
+
* return new Response('Hello app');
|
|
25
|
+
* } else if (tokenInfo.subjectType === 'MEMBER') {
|
|
26
|
+
* return new Response(`Hello member ${tokenInfo.subjectId}`);
|
|
27
|
+
* } else {
|
|
28
|
+
* return new Response(`Hello visitor ${tokenInfo.subjectId}`);
|
|
29
|
+
* }
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* // In a Velo web method
|
|
35
|
+
* import { auth } from '@wix/essentials';
|
|
36
|
+
* import { Permissions, webMethod } from 'wix-web-module';
|
|
37
|
+
*
|
|
38
|
+
* export const sayHello = webMethod(Permimissions.Anyone, async () => {
|
|
39
|
+
* const tokenInfo = await auth.getTokenInfo();
|
|
40
|
+
*
|
|
41
|
+
* if (tokenInfo.subjectType === 'USER') {
|
|
42
|
+
* return `Hello user ${tokenInfo.subjectId}`;
|
|
43
|
+
* } else if (tokenInfo.subjectType === 'APP') {
|
|
44
|
+
* return 'Hello app';
|
|
45
|
+
* } else if (tokenInfo.subjectType === 'MEMBER') {
|
|
46
|
+
* return `Hello member ${tokenInfo.subjectId}`;
|
|
47
|
+
* } else {
|
|
48
|
+
* return `Hello visitor ${tokenInfo.subjectId}`;
|
|
49
|
+
* }
|
|
50
|
+
*/
|
|
5
51
|
export const getTokenInfo = createRESTModule((restModuleOpts) => {
|
|
6
52
|
return async () => {
|
|
7
53
|
if (!restModuleOpts.getActiveToken) {
|
|
8
54
|
throw new Error('Unable to get the currently active token. Please make sure you are using an authentication strategy that supports this operation.');
|
|
9
55
|
}
|
|
10
|
-
const res = await
|
|
56
|
+
const res = await fetch('https://www.wixapis.com/oauth2/token-info', {
|
|
11
57
|
method: 'POST',
|
|
12
58
|
body: JSON.stringify({ token: restModuleOpts.getActiveToken() }),
|
|
13
59
|
headers: {
|
package/build/http-client.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { DocumentNode, GraphQLFormattedError } from 'graphql';
|
|
2
2
|
import { RESTFunctionDescriptor } from '@wix/sdk-types';
|
|
3
3
|
export declare const fetchWithAuth: typeof fetch & ((restModuleOpts: import("@wix/sdk-types").HttpClient) => typeof fetch);
|
|
4
|
-
export declare const graphql: (<Result, Variables>(query: string | String | DocumentNode | TypedQueryInput<Result, Variables>, variables?: Variables
|
|
4
|
+
export declare const graphql: (<Result, Variables>(query: string | String | DocumentNode | TypedQueryInput<Result, Variables>, variables?: Variables, opts?: {
|
|
5
5
|
apiVersion: string;
|
|
6
6
|
}) => Promise<{
|
|
7
7
|
data: Result;
|
|
8
|
-
errors?: GraphQLFormattedError[]
|
|
9
|
-
}>) & RESTFunctionDescriptor<(<Result, Variables>(query: string | String | DocumentNode | TypedQueryInput<Result, Variables>, variables?: Variables
|
|
8
|
+
errors?: GraphQLFormattedError[];
|
|
9
|
+
}>) & RESTFunctionDescriptor<(<Result, Variables>(query: string | String | DocumentNode | TypedQueryInput<Result, Variables>, variables?: Variables, opts?: {
|
|
10
10
|
apiVersion: string;
|
|
11
11
|
}) => Promise<{
|
|
12
12
|
data: Result;
|
|
13
|
-
errors?: GraphQLFormattedError[]
|
|
13
|
+
errors?: GraphQLFormattedError[];
|
|
14
14
|
}>)>;
|
|
15
15
|
export type TypedQueryInput<Result = {
|
|
16
16
|
[key: string]: any;
|
package/cjs/build/auth.d.ts
CHANGED
|
@@ -1,21 +1,67 @@
|
|
|
1
1
|
import { RESTFunctionDescriptor } from '@wix/sdk-types';
|
|
2
2
|
export declare function elevate<T extends RESTFunctionDescriptor>(restModule: T): T;
|
|
3
|
+
/**
|
|
4
|
+
* Returns the information encoded in the currently active token in API backend extensions.
|
|
5
|
+
*
|
|
6
|
+
* When developing API backend extensions you might need to access information about the session that is making the request.
|
|
7
|
+
*
|
|
8
|
+
* This can include the user ID, the site ID, the instance ID, and more. This information is encoded in the token that is sent with the request
|
|
9
|
+
* and can be accessed using this function.
|
|
10
|
+
* @returns A promise that resolves to the token info.
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* // In an API backend extension in a Wix CLI project
|
|
14
|
+
* import { auth } from '@wix/essentials';
|
|
15
|
+
*
|
|
16
|
+
* export async function GET(req: Request) {
|
|
17
|
+
* const tokenInfo = await auth.getTokenInfo();
|
|
18
|
+
*
|
|
19
|
+
* if (tokenInfo.subjectType === 'USER') {
|
|
20
|
+
* return new Response(`Hello user ${tokenInfo.subjectId}`);
|
|
21
|
+
* } else if (tokenInfo.subjectType === 'APP') {
|
|
22
|
+
* return new Response('Hello app');
|
|
23
|
+
* } else if (tokenInfo.subjectType === 'MEMBER') {
|
|
24
|
+
* return new Response(`Hello member ${tokenInfo.subjectId}`);
|
|
25
|
+
* } else {
|
|
26
|
+
* return new Response(`Hello visitor ${tokenInfo.subjectId}`);
|
|
27
|
+
* }
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* // In a Velo web method
|
|
33
|
+
* import { auth } from '@wix/essentials';
|
|
34
|
+
* import { Permissions, webMethod } from 'wix-web-module';
|
|
35
|
+
*
|
|
36
|
+
* export const sayHello = webMethod(Permimissions.Anyone, async () => {
|
|
37
|
+
* const tokenInfo = await auth.getTokenInfo();
|
|
38
|
+
*
|
|
39
|
+
* if (tokenInfo.subjectType === 'USER') {
|
|
40
|
+
* return `Hello user ${tokenInfo.subjectId}`;
|
|
41
|
+
* } else if (tokenInfo.subjectType === 'APP') {
|
|
42
|
+
* return 'Hello app';
|
|
43
|
+
* } else if (tokenInfo.subjectType === 'MEMBER') {
|
|
44
|
+
* return `Hello member ${tokenInfo.subjectId}`;
|
|
45
|
+
* } else {
|
|
46
|
+
* return `Hello visitor ${tokenInfo.subjectId}`;
|
|
47
|
+
* }
|
|
48
|
+
*/
|
|
3
49
|
export declare const getTokenInfo: (() => Promise<{
|
|
4
50
|
active: boolean;
|
|
5
|
-
subjectType:
|
|
51
|
+
subjectType: "APP" | "USER" | "MEMBER" | "VISITOR" | "UNKNOWN";
|
|
6
52
|
subjectId: string;
|
|
7
53
|
exp: number;
|
|
8
54
|
iat: number;
|
|
9
|
-
clientId?: string
|
|
55
|
+
clientId?: string;
|
|
10
56
|
siteId: string;
|
|
11
|
-
instanceId?: string
|
|
57
|
+
instanceId?: string;
|
|
12
58
|
}>) & ((restModuleOpts: import("@wix/sdk-types").HttpClient) => () => Promise<{
|
|
13
59
|
active: boolean;
|
|
14
|
-
subjectType:
|
|
60
|
+
subjectType: "APP" | "USER" | "MEMBER" | "VISITOR" | "UNKNOWN";
|
|
15
61
|
subjectId: string;
|
|
16
62
|
exp: number;
|
|
17
63
|
iat: number;
|
|
18
|
-
clientId?: string
|
|
64
|
+
clientId?: string;
|
|
19
65
|
siteId: string;
|
|
20
|
-
instanceId?: string
|
|
66
|
+
instanceId?: string;
|
|
21
67
|
}>);
|
package/cjs/build/auth.js
CHANGED
|
@@ -1,17 +1,63 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getTokenInfo =
|
|
3
|
+
exports.getTokenInfo = void 0;
|
|
4
|
+
exports.elevate = elevate;
|
|
4
5
|
const rest_modules_1 = require("@wix/sdk-runtime/rest-modules");
|
|
5
6
|
function elevate(restModule) {
|
|
6
7
|
return (0, rest_modules_1.createRESTModule)(restModule, true);
|
|
7
8
|
}
|
|
8
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Returns the information encoded in the currently active token in API backend extensions.
|
|
11
|
+
*
|
|
12
|
+
* When developing API backend extensions you might need to access information about the session that is making the request.
|
|
13
|
+
*
|
|
14
|
+
* This can include the user ID, the site ID, the instance ID, and more. This information is encoded in the token that is sent with the request
|
|
15
|
+
* and can be accessed using this function.
|
|
16
|
+
* @returns A promise that resolves to the token info.
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* // In an API backend extension in a Wix CLI project
|
|
20
|
+
* import { auth } from '@wix/essentials';
|
|
21
|
+
*
|
|
22
|
+
* export async function GET(req: Request) {
|
|
23
|
+
* const tokenInfo = await auth.getTokenInfo();
|
|
24
|
+
*
|
|
25
|
+
* if (tokenInfo.subjectType === 'USER') {
|
|
26
|
+
* return new Response(`Hello user ${tokenInfo.subjectId}`);
|
|
27
|
+
* } else if (tokenInfo.subjectType === 'APP') {
|
|
28
|
+
* return new Response('Hello app');
|
|
29
|
+
* } else if (tokenInfo.subjectType === 'MEMBER') {
|
|
30
|
+
* return new Response(`Hello member ${tokenInfo.subjectId}`);
|
|
31
|
+
* } else {
|
|
32
|
+
* return new Response(`Hello visitor ${tokenInfo.subjectId}`);
|
|
33
|
+
* }
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* // In a Velo web method
|
|
39
|
+
* import { auth } from '@wix/essentials';
|
|
40
|
+
* import { Permissions, webMethod } from 'wix-web-module';
|
|
41
|
+
*
|
|
42
|
+
* export const sayHello = webMethod(Permimissions.Anyone, async () => {
|
|
43
|
+
* const tokenInfo = await auth.getTokenInfo();
|
|
44
|
+
*
|
|
45
|
+
* if (tokenInfo.subjectType === 'USER') {
|
|
46
|
+
* return `Hello user ${tokenInfo.subjectId}`;
|
|
47
|
+
* } else if (tokenInfo.subjectType === 'APP') {
|
|
48
|
+
* return 'Hello app';
|
|
49
|
+
* } else if (tokenInfo.subjectType === 'MEMBER') {
|
|
50
|
+
* return `Hello member ${tokenInfo.subjectId}`;
|
|
51
|
+
* } else {
|
|
52
|
+
* return `Hello visitor ${tokenInfo.subjectId}`;
|
|
53
|
+
* }
|
|
54
|
+
*/
|
|
9
55
|
exports.getTokenInfo = (0, rest_modules_1.createRESTModule)((restModuleOpts) => {
|
|
10
56
|
return async () => {
|
|
11
57
|
if (!restModuleOpts.getActiveToken) {
|
|
12
58
|
throw new Error('Unable to get the currently active token. Please make sure you are using an authentication strategy that supports this operation.');
|
|
13
59
|
}
|
|
14
|
-
const res = await
|
|
60
|
+
const res = await fetch('https://www.wixapis.com/oauth2/token-info', {
|
|
15
61
|
method: 'POST',
|
|
16
62
|
body: JSON.stringify({ token: restModuleOpts.getActiveToken() }),
|
|
17
63
|
headers: {
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { DocumentNode, GraphQLFormattedError } from 'graphql';
|
|
2
2
|
import { RESTFunctionDescriptor } from '@wix/sdk-types';
|
|
3
3
|
export declare const fetchWithAuth: typeof fetch & ((restModuleOpts: import("@wix/sdk-types").HttpClient) => typeof fetch);
|
|
4
|
-
export declare const graphql: (<Result, Variables>(query: string | String | DocumentNode | TypedQueryInput<Result, Variables>, variables?: Variables
|
|
4
|
+
export declare const graphql: (<Result, Variables>(query: string | String | DocumentNode | TypedQueryInput<Result, Variables>, variables?: Variables, opts?: {
|
|
5
5
|
apiVersion: string;
|
|
6
6
|
}) => Promise<{
|
|
7
7
|
data: Result;
|
|
8
|
-
errors?: GraphQLFormattedError[]
|
|
9
|
-
}>) & RESTFunctionDescriptor<(<Result, Variables>(query: string | String | DocumentNode | TypedQueryInput<Result, Variables>, variables?: Variables
|
|
8
|
+
errors?: GraphQLFormattedError[];
|
|
9
|
+
}>) & RESTFunctionDescriptor<(<Result, Variables>(query: string | String | DocumentNode | TypedQueryInput<Result, Variables>, variables?: Variables, opts?: {
|
|
10
10
|
apiVersion: string;
|
|
11
11
|
}) => Promise<{
|
|
12
12
|
data: Result;
|
|
13
|
-
errors?: GraphQLFormattedError[]
|
|
13
|
+
errors?: GraphQLFormattedError[];
|
|
14
14
|
}>)>;
|
|
15
15
|
export type TypedQueryInput<Result = {
|
|
16
16
|
[key: string]: any;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/essentials",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"main": "cjs/build/index.js",
|
|
6
6
|
"module": "build/index.mjs",
|
|
@@ -13,6 +13,9 @@
|
|
|
13
13
|
"./package.json": "./package.json"
|
|
14
14
|
},
|
|
15
15
|
"sideEffects": false,
|
|
16
|
+
"keywords": [
|
|
17
|
+
"wix-sdk-module=backend,page,public"
|
|
18
|
+
],
|
|
16
19
|
"files": [
|
|
17
20
|
"build",
|
|
18
21
|
"cjs"
|
|
@@ -32,26 +35,26 @@
|
|
|
32
35
|
"*.{js,ts}": "yarn lint"
|
|
33
36
|
},
|
|
34
37
|
"dependencies": {
|
|
35
|
-
"@wix/sdk-runtime": "^0.3.
|
|
36
|
-
"@wix/sdk-types": "^1.12.
|
|
38
|
+
"@wix/sdk-runtime": "^0.3.23",
|
|
39
|
+
"@wix/sdk-types": "^1.12.4"
|
|
37
40
|
},
|
|
38
41
|
"optionalDependencies": {
|
|
39
42
|
"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"
|
|
40
43
|
},
|
|
41
44
|
"devDependencies": {
|
|
42
45
|
"@types/is-ci": "^3.0.4",
|
|
43
|
-
"@types/node": "^20.
|
|
44
|
-
"@vitest/ui": "^1.
|
|
45
|
-
"@wix/sdk": "1.
|
|
46
|
-
"eslint": "^8.
|
|
46
|
+
"@types/node": "^20.17.5",
|
|
47
|
+
"@vitest/ui": "^1.6.0",
|
|
48
|
+
"@wix/sdk": "1.14.2",
|
|
49
|
+
"eslint": "^8.57.1",
|
|
47
50
|
"eslint-config-sdk": "0.0.0",
|
|
48
51
|
"graphql": "^16.8.0",
|
|
49
52
|
"is-ci": "^3.0.1",
|
|
50
53
|
"jsdom": "^22.1.0",
|
|
51
|
-
"msw": "^2.
|
|
52
|
-
"typescript": "^5.
|
|
53
|
-
"vitest": "^1.
|
|
54
|
-
"vitest-teamcity-reporter": "^0.3.
|
|
54
|
+
"msw": "^2.6.0",
|
|
55
|
+
"typescript": "^5.6.3",
|
|
56
|
+
"vitest": "^1.6.0",
|
|
57
|
+
"vitest-teamcity-reporter": "^0.3.1"
|
|
55
58
|
},
|
|
56
59
|
"eslintConfig": {
|
|
57
60
|
"extends": "sdk"
|
|
@@ -70,5 +73,5 @@
|
|
|
70
73
|
]
|
|
71
74
|
}
|
|
72
75
|
},
|
|
73
|
-
"falconPackageHash": "
|
|
76
|
+
"falconPackageHash": "548bb4c73eaa8f466416942621fe28493745e7ef88c7f4af7ad4f84a"
|
|
74
77
|
}
|