@wix/sdk 1.7.8 → 1.7.10
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/wix-context.d.ts +30 -9
- package/build/wix-context.js +48 -54
- package/cjs/build/wix-context.d.ts +30 -9
- package/cjs/build/wix-context.js +50 -57
- package/context/package.json +3 -0
- package/package.json +6 -5
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,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.10",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Ronny Ringel",
|
|
@@ -45,7 +45,8 @@
|
|
|
45
45
|
"build",
|
|
46
46
|
"auth",
|
|
47
47
|
"client",
|
|
48
|
-
"cjs"
|
|
48
|
+
"cjs",
|
|
49
|
+
"context"
|
|
49
50
|
],
|
|
50
51
|
"publishConfig": {
|
|
51
52
|
"registry": "https://registry.npmjs.org/",
|
|
@@ -81,10 +82,10 @@
|
|
|
81
82
|
"@types/is-ci": "^3.0.4",
|
|
82
83
|
"@types/node": "^20.10.6",
|
|
83
84
|
"@vitest/ui": "^1.1.3",
|
|
84
|
-
"@wix/ecom": "^1.0.
|
|
85
|
+
"@wix/ecom": "^1.0.503",
|
|
85
86
|
"@wix/events": "^1.0.155",
|
|
86
87
|
"@wix/metro": "^1.0.73",
|
|
87
|
-
"@wix/metro-runtime": "^1.
|
|
88
|
+
"@wix/metro-runtime": "^1.1650.0",
|
|
88
89
|
"@wix/sdk-runtime": "0.2.8",
|
|
89
90
|
"eslint": "^8.56.0",
|
|
90
91
|
"eslint-config-sdk": "0.0.0",
|
|
@@ -119,5 +120,5 @@
|
|
|
119
120
|
"wallaby": {
|
|
120
121
|
"autoDetect": true
|
|
121
122
|
},
|
|
122
|
-
"falconPackageHash": "
|
|
123
|
+
"falconPackageHash": "a647b56bc41785f6b222e47243bb5ff69161a35bac1334d88ced9da6"
|
|
123
124
|
}
|