@wix/sdk 1.7.9 → 1.7.11
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,4 +1,3 @@
|
|
|
1
|
-
import { jwtVerify, importSPKI } from 'jose';
|
|
2
1
|
import { parsePublicKeyIfEncoded } from '../helpers.js';
|
|
3
2
|
/**
|
|
4
3
|
* Creates an authentication strategy for Wix Apps OAuth installation process.
|
|
@@ -190,6 +189,7 @@ export function WixAppOAuthStrategy(opts) {
|
|
|
190
189
|
if (!opts.publicKey) {
|
|
191
190
|
throw new Error('Missing public key. Make sure to pass it to the WixAppOAuthStrategy');
|
|
192
191
|
}
|
|
192
|
+
const { jwtVerify, importSPKI } = await import('jose');
|
|
193
193
|
const publicKey = await importSPKI(parsePublicKeyIfEncoded(opts.publicKey), 'RS256');
|
|
194
194
|
const decoded = await jwtVerify(token, publicKey, verifyCallerClaims
|
|
195
195
|
? {
|
package/build/wix-context.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
import
|
|
3
|
-
import { BuildRESTFunction, RESTFunctionDescriptor } from './index.js';
|
|
2
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
3
|
+
import { BuildDescriptors, BuildRESTFunction, Descriptors, Host, RESTFunctionDescriptor } from './index.js';
|
|
4
4
|
export type MaybeWithWixContext<T extends RESTFunctionDescriptor> = typeof globalThis extends {
|
|
5
5
|
__wix_context__: {
|
|
6
6
|
initWixModules: unknown;
|
|
@@ -20,12 +20,33 @@ declare namespace globalThis {
|
|
|
20
20
|
initWixModules: unknown;
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
|
-
export declare function
|
|
24
|
-
export declare
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
export declare function setGlobalWixModulesInit(initWixModules: <T extends Descriptors, H extends Host>(wixModules: T) => BuildDescriptors<T, H>): void;
|
|
24
|
+
export declare const AsyncLocalStorageContext: {
|
|
25
|
+
asyncLocalStorage: AsyncLocalStorage<{
|
|
26
|
+
authStrategy: {
|
|
27
|
+
getAuthHeaders: () => Promise<{
|
|
28
|
+
headers: {
|
|
29
|
+
Authorization: string;
|
|
30
|
+
};
|
|
31
|
+
}>;
|
|
28
32
|
};
|
|
29
|
-
}
|
|
30
|
-
|
|
33
|
+
}> | undefined;
|
|
34
|
+
init(AsyncLocalStorageConstructor: typeof AsyncLocalStorage): void;
|
|
35
|
+
run(authStrategy: {
|
|
36
|
+
getAuthHeaders: () => Promise<{
|
|
37
|
+
headers: {
|
|
38
|
+
Authorization: string;
|
|
39
|
+
};
|
|
40
|
+
}>;
|
|
41
|
+
}, fn: () => unknown): unknown;
|
|
42
|
+
};
|
|
43
|
+
export declare const GlobalSingletonContext: {
|
|
44
|
+
init(authStrategy: {
|
|
45
|
+
getAuthHeaders: () => Promise<{
|
|
46
|
+
headers: {
|
|
47
|
+
Authorization: string;
|
|
48
|
+
};
|
|
49
|
+
}>;
|
|
50
|
+
}): void;
|
|
51
|
+
};
|
|
31
52
|
export {};
|
package/build/wix-context.js
CHANGED
|
@@ -1,58 +1,52 @@
|
|
|
1
1
|
import { createClient, } from './index.js';
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
2
|
+
export function setGlobalWixModulesInit(initWixModules) {
|
|
3
|
+
globalThis.__wix_context__ = {
|
|
4
|
+
initWixModules,
|
|
5
|
+
};
|
|
6
|
+
}
|
|
7
|
+
export const AsyncLocalStorageContext = {
|
|
8
|
+
asyncLocalStorage: undefined,
|
|
9
|
+
init(AsyncLocalStorageConstructor) {
|
|
7
10
|
const asyncLocalStorage = new AsyncLocalStorageConstructor();
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return store.authStrategy.getAuthHeaders();
|
|
19
|
-
},
|
|
11
|
+
this.asyncLocalStorage = asyncLocalStorage;
|
|
12
|
+
setGlobalWixModulesInit((wixModules) => {
|
|
13
|
+
const client = createClient({
|
|
14
|
+
auth: {
|
|
15
|
+
async getAuthHeaders() {
|
|
16
|
+
const store = asyncLocalStorage.getStore();
|
|
17
|
+
if (!store) {
|
|
18
|
+
throw new Error('No wix context found, make sure to init and use wix context');
|
|
19
|
+
}
|
|
20
|
+
return store.authStrategy.getAuthHeaders();
|
|
20
21
|
},
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
globalThis.__wix_context__
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
return client.use(wixModules);
|
|
25
|
+
});
|
|
26
|
+
},
|
|
27
|
+
run(authStrategy, fn) {
|
|
28
|
+
if (!globalThis.__wix_context__) {
|
|
29
|
+
throw new Error('Wix context not initialized');
|
|
30
|
+
}
|
|
31
|
+
if (this.asyncLocalStorage) {
|
|
32
|
+
return this.asyncLocalStorage.run({ authStrategy }, fn);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
throw new Error('AsyncLocalStorageContext: `run` has been called before `init` method. Make sure to call `init` method before using `run` method.');
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
export const GlobalSingletonContext = {
|
|
40
|
+
init(authStrategy) {
|
|
41
|
+
setGlobalWixModulesInit((wixModules) => {
|
|
42
|
+
const client = createClient({
|
|
43
|
+
auth: {
|
|
44
|
+
async getAuthHeaders() {
|
|
45
|
+
return authStrategy.getAuthHeaders();
|
|
41
46
|
},
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
export function runWithWixContext(authStrategy, fn) {
|
|
49
|
-
if (!globalThis.__wix_context__) {
|
|
50
|
-
throw new Error('Wix context not initialized');
|
|
51
|
-
}
|
|
52
|
-
if (globalThis.__wix_context__.asyncLocalStorage) {
|
|
53
|
-
return globalThis.__wix_context__.asyncLocalStorage.run({ authStrategy }, fn);
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
throw new Error('runWithWixContext is not supported in this environment');
|
|
57
|
-
}
|
|
58
|
-
}
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
return client.use(wixModules);
|
|
50
|
+
});
|
|
51
|
+
},
|
|
52
|
+
};
|
|
@@ -1,7 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
exports.WixAppOAuthStrategy = void 0;
|
|
4
|
-
const jose_1 = require("jose");
|
|
5
27
|
const helpers_js_1 = require("../helpers.js");
|
|
6
28
|
/**
|
|
7
29
|
* Creates an authentication strategy for Wix Apps OAuth installation process.
|
|
@@ -193,8 +215,9 @@ function WixAppOAuthStrategy(opts) {
|
|
|
193
215
|
if (!opts.publicKey) {
|
|
194
216
|
throw new Error('Missing public key. Make sure to pass it to the WixAppOAuthStrategy');
|
|
195
217
|
}
|
|
196
|
-
const
|
|
197
|
-
const
|
|
218
|
+
const { jwtVerify, importSPKI } = await Promise.resolve().then(() => __importStar(require('jose')));
|
|
219
|
+
const publicKey = await importSPKI((0, helpers_js_1.parsePublicKeyIfEncoded)(opts.publicKey), 'RS256');
|
|
220
|
+
const decoded = await jwtVerify(token, publicKey, verifyCallerClaims
|
|
198
221
|
? {
|
|
199
222
|
issuer: 'wix.com',
|
|
200
223
|
audience: opts.appId,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import
|
|
3
|
-
import { BuildRESTFunction, RESTFunctionDescriptor } from './index.js';
|
|
2
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
3
|
+
import { BuildDescriptors, BuildRESTFunction, Descriptors, Host, RESTFunctionDescriptor } from './index.js';
|
|
4
4
|
export type MaybeWithWixContext<T extends RESTFunctionDescriptor> = typeof globalThis extends {
|
|
5
5
|
__wix_context__: {
|
|
6
6
|
initWixModules: unknown;
|
|
@@ -20,12 +20,33 @@ declare namespace globalThis {
|
|
|
20
20
|
initWixModules: unknown;
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
|
-
export declare function
|
|
24
|
-
export declare
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
export declare function setGlobalWixModulesInit(initWixModules: <T extends Descriptors, H extends Host>(wixModules: T) => BuildDescriptors<T, H>): void;
|
|
24
|
+
export declare const AsyncLocalStorageContext: {
|
|
25
|
+
asyncLocalStorage: AsyncLocalStorage<{
|
|
26
|
+
authStrategy: {
|
|
27
|
+
getAuthHeaders: () => Promise<{
|
|
28
|
+
headers: {
|
|
29
|
+
Authorization: string;
|
|
30
|
+
};
|
|
31
|
+
}>;
|
|
28
32
|
};
|
|
29
|
-
}
|
|
30
|
-
|
|
33
|
+
}> | undefined;
|
|
34
|
+
init(AsyncLocalStorageConstructor: typeof AsyncLocalStorage): void;
|
|
35
|
+
run(authStrategy: {
|
|
36
|
+
getAuthHeaders: () => Promise<{
|
|
37
|
+
headers: {
|
|
38
|
+
Authorization: string;
|
|
39
|
+
};
|
|
40
|
+
}>;
|
|
41
|
+
}, fn: () => unknown): unknown;
|
|
42
|
+
};
|
|
43
|
+
export declare const GlobalSingletonContext: {
|
|
44
|
+
init(authStrategy: {
|
|
45
|
+
getAuthHeaders: () => Promise<{
|
|
46
|
+
headers: {
|
|
47
|
+
Authorization: string;
|
|
48
|
+
};
|
|
49
|
+
}>;
|
|
50
|
+
}): void;
|
|
51
|
+
};
|
|
31
52
|
export {};
|
package/cjs/build/wix-context.js
CHANGED
|
@@ -1,63 +1,56 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.GlobalSingletonContext = exports.AsyncLocalStorageContext = exports.setGlobalWixModulesInit = void 0;
|
|
4
4
|
const index_js_1 = require("./index.js");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
|
|
5
|
+
function setGlobalWixModulesInit(initWixModules) {
|
|
6
|
+
globalThis.__wix_context__ = {
|
|
7
|
+
initWixModules,
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
exports.setGlobalWixModulesInit = setGlobalWixModulesInit;
|
|
11
|
+
exports.AsyncLocalStorageContext = {
|
|
12
|
+
asyncLocalStorage: undefined,
|
|
13
|
+
init(AsyncLocalStorageConstructor) {
|
|
10
14
|
const asyncLocalStorage = new AsyncLocalStorageConstructor();
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return store.authStrategy.getAuthHeaders();
|
|
22
|
-
},
|
|
15
|
+
this.asyncLocalStorage = asyncLocalStorage;
|
|
16
|
+
setGlobalWixModulesInit((wixModules) => {
|
|
17
|
+
const client = (0, index_js_1.createClient)({
|
|
18
|
+
auth: {
|
|
19
|
+
async getAuthHeaders() {
|
|
20
|
+
const store = asyncLocalStorage.getStore();
|
|
21
|
+
if (!store) {
|
|
22
|
+
throw new Error('No wix context found, make sure to init and use wix context');
|
|
23
|
+
}
|
|
24
|
+
return store.authStrategy.getAuthHeaders();
|
|
23
25
|
},
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
globalThis.__wix_context__
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
return client.use(wixModules);
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
run(authStrategy, fn) {
|
|
32
|
+
if (!globalThis.__wix_context__) {
|
|
33
|
+
throw new Error('Wix context not initialized');
|
|
34
|
+
}
|
|
35
|
+
if (this.asyncLocalStorage) {
|
|
36
|
+
return this.asyncLocalStorage.run({ authStrategy }, fn);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
throw new Error('AsyncLocalStorageContext: `run` has been called before `init` method. Make sure to call `init` method before using `run` method.');
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
exports.GlobalSingletonContext = {
|
|
44
|
+
init(authStrategy) {
|
|
45
|
+
setGlobalWixModulesInit((wixModules) => {
|
|
46
|
+
const client = (0, index_js_1.createClient)({
|
|
47
|
+
auth: {
|
|
48
|
+
async getAuthHeaders() {
|
|
49
|
+
return authStrategy.getAuthHeaders();
|
|
44
50
|
},
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
exports.initWixContext = initWixContext;
|
|
52
|
-
function runWithWixContext(authStrategy, fn) {
|
|
53
|
-
if (!globalThis.__wix_context__) {
|
|
54
|
-
throw new Error('Wix context not initialized');
|
|
55
|
-
}
|
|
56
|
-
if (globalThis.__wix_context__.asyncLocalStorage) {
|
|
57
|
-
return globalThis.__wix_context__.asyncLocalStorage.run({ authStrategy }, fn);
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
throw new Error('runWithWixContext is not supported in this environment');
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
exports.runWithWixContext = runWithWixContext;
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
return client.use(wixModules);
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/sdk",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.11",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Ronny Ringel",
|
|
@@ -82,10 +82,10 @@
|
|
|
82
82
|
"@types/is-ci": "^3.0.4",
|
|
83
83
|
"@types/node": "^20.10.6",
|
|
84
84
|
"@vitest/ui": "^1.1.3",
|
|
85
|
-
"@wix/ecom": "^1.0.
|
|
85
|
+
"@wix/ecom": "^1.0.503",
|
|
86
86
|
"@wix/events": "^1.0.155",
|
|
87
87
|
"@wix/metro": "^1.0.73",
|
|
88
|
-
"@wix/metro-runtime": "^1.
|
|
88
|
+
"@wix/metro-runtime": "^1.1653.0",
|
|
89
89
|
"@wix/sdk-runtime": "0.2.8",
|
|
90
90
|
"eslint": "^8.56.0",
|
|
91
91
|
"eslint-config-sdk": "0.0.0",
|
|
@@ -120,5 +120,5 @@
|
|
|
120
120
|
"wallaby": {
|
|
121
121
|
"autoDetect": true
|
|
122
122
|
},
|
|
123
|
-
"falconPackageHash": "
|
|
123
|
+
"falconPackageHash": "71fd96705487f56ef457e93ee780103c29750bdf928b39234632f113"
|
|
124
124
|
}
|