@wix/sdk 1.7.9 → 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.
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" resolution-mode="require"/>
2
- import type { AsyncLocalStorage } from 'node:async_hooks';
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 initWixContext(AsyncLocalStorageConstructor?: typeof AsyncLocalStorage): Promise<void>;
24
- export declare function runWithWixContext(authStrategy: {
25
- getAuthHeaders: () => Promise<{
26
- headers: {
27
- Authorization: string;
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
- }, fn: () => void): void;
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 {};
@@ -1,58 +1,52 @@
1
1
  import { createClient, } from './index.js';
2
- export async function initWixContext(AsyncLocalStorageConstructor) {
3
- if (globalThis.__wix_context__) {
4
- return;
5
- }
6
- if (AsyncLocalStorageConstructor) {
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
- globalThis.__wix_context__ = {
9
- asyncLocalStorage,
10
- initWixModules: (wixModules) => {
11
- const client = createClient({
12
- auth: {
13
- async getAuthHeaders() {
14
- const store = asyncLocalStorage.getStore();
15
- if (!store) {
16
- throw new Error('No wix context found, make sure to init and use wix context');
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
- return client.use(wixModules);
23
- },
24
- };
25
- }
26
- else {
27
- globalThis.__wix_context__ = {
28
- initWixModules: (wixModules) => {
29
- const client = createClient({
30
- auth: {
31
- async getAuthHeaders() {
32
- return {
33
- headers: {
34
- Authorization:
35
- // @ts-expect-error $ns is only available in the closure created by Velo
36
- $ns['wix-elementorySupport'].getRequestOptions().headers
37
- .Authorization,
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
- return client.use(wixModules);
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 type { AsyncLocalStorage } from 'node:async_hooks';
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 initWixContext(AsyncLocalStorageConstructor?: typeof AsyncLocalStorage): Promise<void>;
24
- export declare function runWithWixContext(authStrategy: {
25
- getAuthHeaders: () => Promise<{
26
- headers: {
27
- Authorization: string;
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
- }, fn: () => void): void;
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 {};
@@ -1,63 +1,56 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.runWithWixContext = exports.initWixContext = void 0;
3
+ exports.GlobalSingletonContext = exports.AsyncLocalStorageContext = exports.setGlobalWixModulesInit = void 0;
4
4
  const index_js_1 = require("./index.js");
5
- async function initWixContext(AsyncLocalStorageConstructor) {
6
- if (globalThis.__wix_context__) {
7
- return;
8
- }
9
- if (AsyncLocalStorageConstructor) {
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
- globalThis.__wix_context__ = {
12
- asyncLocalStorage,
13
- initWixModules: (wixModules) => {
14
- const client = (0, index_js_1.createClient)({
15
- auth: {
16
- async getAuthHeaders() {
17
- const store = asyncLocalStorage.getStore();
18
- if (!store) {
19
- throw new Error('No wix context found, make sure to init and use wix context');
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
- return client.use(wixModules);
26
- },
27
- };
28
- }
29
- else {
30
- globalThis.__wix_context__ = {
31
- initWixModules: (wixModules) => {
32
- const client = (0, index_js_1.createClient)({
33
- auth: {
34
- async getAuthHeaders() {
35
- return {
36
- headers: {
37
- Authorization:
38
- // @ts-expect-error $ns is only available in the closure created by Velo
39
- $ns['wix-elementorySupport'].getRequestOptions().headers
40
- .Authorization,
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
- return client.use(wixModules);
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.9",
3
+ "version": "1.7.10",
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.501",
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.1649.0",
88
+ "@wix/metro-runtime": "^1.1650.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": "50244a30d1030cfe838429c80f51e8d707ebd968412178a10ec3d4c2"
123
+ "falconPackageHash": "a647b56bc41785f6b222e47243bb5ff69161a35bac1334d88ced9da6"
124
124
  }