@wix/sdk 1.7.7 → 1.7.8

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.
@@ -113,9 +113,13 @@ export function OAuthStrategy(config) {
113
113
  prompt: redirects.Prompt[prompt],
114
114
  },
115
115
  });
116
- return { authUrl: redirectSession.fullUrl };
116
+ return {
117
+ authUrl: redirectSession.fullUrl,
118
+ authorizationEndpoint: redirectSession.urlDetails.endpoint,
119
+ sessionToken: redirectSession.sessionToken,
120
+ };
117
121
  };
118
- const getAuthUrl = async (oauthData, opts = {
122
+ const getAuthUrl = async (oauthData = generateOAuthData('unused://'), opts = {
119
123
  prompt: 'login',
120
124
  }) => {
121
125
  return getAuthorizationUrlWithOptions(oauthData, opts.responseMode ?? 'fragment', opts.prompt ?? 'login', opts.sessionToken);
@@ -0,0 +1,31 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ import type { AsyncLocalStorage } from 'node:async_hooks';
3
+ import { BuildRESTFunction, RESTFunctionDescriptor } from './index.js';
4
+ export type MaybeWithWixContext<T extends RESTFunctionDescriptor> = typeof globalThis extends {
5
+ __wix_context__: {
6
+ initWixModules: unknown;
7
+ };
8
+ } ? BuildRESTFunction<T> : T;
9
+ declare namespace globalThis {
10
+ let __wix_context__: {
11
+ asyncLocalStorage?: import('node:async_hooks').AsyncLocalStorage<{
12
+ authStrategy: {
13
+ getAuthHeaders: () => Promise<{
14
+ headers: {
15
+ Authorization: string;
16
+ };
17
+ }>;
18
+ };
19
+ }>;
20
+ initWixModules: unknown;
21
+ };
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;
28
+ };
29
+ }>;
30
+ }, fn: () => void): void;
31
+ export {};
@@ -0,0 +1,58 @@
1
+ import { createClient, } from './index.js';
2
+ export async function initWixContext(AsyncLocalStorageConstructor) {
3
+ if (globalThis.__wix_context__) {
4
+ return;
5
+ }
6
+ if (AsyncLocalStorageConstructor) {
7
+ 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
+ },
20
+ },
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
+ },
41
+ },
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
+ }
@@ -116,9 +116,13 @@ function OAuthStrategy(config) {
116
116
  prompt: redirects_1.redirects.Prompt[prompt],
117
117
  },
118
118
  });
119
- return { authUrl: redirectSession.fullUrl };
119
+ return {
120
+ authUrl: redirectSession.fullUrl,
121
+ authorizationEndpoint: redirectSession.urlDetails.endpoint,
122
+ sessionToken: redirectSession.sessionToken,
123
+ };
120
124
  };
121
- const getAuthUrl = async (oauthData, opts = {
125
+ const getAuthUrl = async (oauthData = generateOAuthData('unused://'), opts = {
122
126
  prompt: 'login',
123
127
  }) => {
124
128
  return getAuthorizationUrlWithOptions(oauthData, opts.responseMode ?? 'fragment', opts.prompt ?? 'login', opts.sessionToken);
@@ -0,0 +1,31 @@
1
+ /// <reference types="node" />
2
+ import type { AsyncLocalStorage } from 'node:async_hooks';
3
+ import { BuildRESTFunction, RESTFunctionDescriptor } from './index.js';
4
+ export type MaybeWithWixContext<T extends RESTFunctionDescriptor> = typeof globalThis extends {
5
+ __wix_context__: {
6
+ initWixModules: unknown;
7
+ };
8
+ } ? BuildRESTFunction<T> : T;
9
+ declare namespace globalThis {
10
+ let __wix_context__: {
11
+ asyncLocalStorage?: import('node:async_hooks').AsyncLocalStorage<{
12
+ authStrategy: {
13
+ getAuthHeaders: () => Promise<{
14
+ headers: {
15
+ Authorization: string;
16
+ };
17
+ }>;
18
+ };
19
+ }>;
20
+ initWixModules: unknown;
21
+ };
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;
28
+ };
29
+ }>;
30
+ }, fn: () => void): void;
31
+ export {};
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runWithWixContext = exports.initWixContext = void 0;
4
+ const index_js_1 = require("./index.js");
5
+ async function initWixContext(AsyncLocalStorageConstructor) {
6
+ if (globalThis.__wix_context__) {
7
+ return;
8
+ }
9
+ if (AsyncLocalStorageConstructor) {
10
+ 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
+ },
23
+ },
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
+ },
44
+ },
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/sdk",
3
- "version": "1.7.7",
3
+ "version": "1.7.8",
4
4
  "license": "UNLICENSED",
5
5
  "author": {
6
6
  "name": "Ronny Ringel",
@@ -19,6 +19,10 @@
19
19
  "import": "./build/wixClient.js",
20
20
  "require": "./cjs/build/wixClient.js"
21
21
  },
22
+ "./context": {
23
+ "import": "./build/wix-context.js",
24
+ "require": "./cjs/build/wix-context.js"
25
+ },
22
26
  "./auth/oauth2": {
23
27
  "import": "./build/auth/oauth2/OAuthStrategy.js",
24
28
  "require": "./cjs/build/auth/oauth2/OAuthStrategy.js"
@@ -60,8 +64,8 @@
60
64
  "dependencies": {
61
65
  "@babel/runtime": "^7.23.2",
62
66
  "@wix/identity": "^1.0.74",
63
- "@wix/image-kit": "^1.58.0",
64
- "@wix/redirects": "^1.0.32",
67
+ "@wix/image-kit": "^1.59.0",
68
+ "@wix/redirects": "^1.0.34",
65
69
  "@wix/sdk-types": "^1.5.9",
66
70
  "crypto-js": "^4.2.0",
67
71
  "jose": "^5.2.1",
@@ -77,10 +81,10 @@
77
81
  "@types/is-ci": "^3.0.4",
78
82
  "@types/node": "^20.10.6",
79
83
  "@vitest/ui": "^1.1.3",
80
- "@wix/ecom": "^1.0.495",
81
- "@wix/events": "^1.0.153",
84
+ "@wix/ecom": "^1.0.501",
85
+ "@wix/events": "^1.0.155",
82
86
  "@wix/metro": "^1.0.73",
83
- "@wix/metro-runtime": "^1.1638.0",
87
+ "@wix/metro-runtime": "^1.1649.0",
84
88
  "@wix/sdk-runtime": "0.2.8",
85
89
  "eslint": "^8.56.0",
86
90
  "eslint-config-sdk": "0.0.0",
@@ -115,5 +119,5 @@
115
119
  "wallaby": {
116
120
  "autoDetect": true
117
121
  },
118
- "falconPackageHash": "14cbbfe86433a368e361f62c89354e3a6667cc7a256553b4c12a8f7f"
122
+ "falconPackageHash": "0756c223ee9c70c4a047a6778abdda76e491b31f86b351aeac4e8025"
119
123
  }