@wix/sdk 1.17.6 → 1.17.7
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/event-handlers-modules.d.ts +1 -1
- package/build/event-handlers-modules.js +2 -1
- package/build/service-plugin-modules.d.ts +1 -1
- package/build/service-plugin-modules.js +2 -1
- package/build/wixClient.d.ts +1 -1
- package/build/wixClient.js +16 -10
- package/cjs/build/event-handlers-modules.d.ts +1 -1
- package/cjs/build/event-handlers-modules.js +2 -1
- package/cjs/build/service-plugin-modules.d.ts +1 -1
- package/cjs/build/service-plugin-modules.js +2 -1
- package/cjs/build/wixClient.d.ts +1 -1
- package/cjs/build/wixClient.js +16 -10
- package/package.json +2 -2
|
@@ -47,7 +47,7 @@ export type EventHandlersClient = Emitter<{
|
|
|
47
47
|
}, 'AppRemoved'>;
|
|
48
48
|
};
|
|
49
49
|
};
|
|
50
|
-
export declare function eventHandlersModules(
|
|
50
|
+
export declare function eventHandlersModules(getAuthStrategy: () => AuthenticationStrategy<any>): {
|
|
51
51
|
initModule(eventDefinition: EventDefinition<any, string>): (handler: EventHandler<EventDefinition<any, string>>) => void;
|
|
52
52
|
client: EventHandlersClient;
|
|
53
53
|
};
|
|
@@ -73,7 +73,7 @@ function runHandler(eventDefinition, handler, payload, baseEventMetadata) {
|
|
|
73
73
|
}
|
|
74
74
|
return handler(transformFromRESTFn(originalEnvelope));
|
|
75
75
|
}
|
|
76
|
-
export function eventHandlersModules(
|
|
76
|
+
export function eventHandlersModules(getAuthStrategy) {
|
|
77
77
|
const eventHandlers = new Map();
|
|
78
78
|
const webhooksEmitter = createNanoEvents();
|
|
79
79
|
const client = {
|
|
@@ -110,6 +110,7 @@ export function eventHandlersModules(authStrategy) {
|
|
|
110
110
|
return this.process(body, opts);
|
|
111
111
|
},
|
|
112
112
|
async parseJWT(jwt) {
|
|
113
|
+
const authStrategy = getAuthStrategy();
|
|
113
114
|
if (!authStrategy.decodeJWT) {
|
|
114
115
|
throw new Error('decodeJWT is not supported by the authentication strategy');
|
|
115
116
|
}
|
|
@@ -26,7 +26,7 @@ export type ServicePluginsClient = Emitter<{
|
|
|
26
26
|
parseRequest(request: Request): Promise<ServicePluginRequest>;
|
|
27
27
|
executeHandler(servicePluginRequest: ServicePluginRequest, url: string): Promise<UnknownServicePluginResponse>;
|
|
28
28
|
};
|
|
29
|
-
export declare function servicePluginsModules(
|
|
29
|
+
export declare function servicePluginsModules(getAuthStrategy: () => AuthenticationStrategy<any>): {
|
|
30
30
|
initModule<T extends ServicePluginDefinition<any>>(servicePluginDefinition: T): (implementation: T["__contract"]) => void;
|
|
31
31
|
client: ServicePluginsClient;
|
|
32
32
|
};
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { createNanoEvents } from './nanoevents.js';
|
|
2
2
|
export const isServicePluginModule = (val) => val.__type === 'service-plugin-definition';
|
|
3
|
-
export function servicePluginsModules(
|
|
3
|
+
export function servicePluginsModules(getAuthStrategy) {
|
|
4
4
|
const servicePluginsImplementations = new Map();
|
|
5
5
|
const servicePluginsEmitter = createNanoEvents();
|
|
6
6
|
const client = {
|
|
7
7
|
...servicePluginsEmitter,
|
|
8
8
|
getRegisteredServicePlugins: () => servicePluginsImplementations,
|
|
9
9
|
async parseJWT(jwt) {
|
|
10
|
+
const authStrategy = getAuthStrategy();
|
|
10
11
|
if (!authStrategy.decodeJWT) {
|
|
11
12
|
throw new Error('decodeJWT is not supported by the authentication strategy');
|
|
12
13
|
}
|
package/build/wixClient.d.ts
CHANGED
|
@@ -50,7 +50,7 @@ export type WixClient<H extends Host<any> | undefined = undefined, Z extends Aut
|
|
|
50
50
|
} & BuildDescriptors<T, H>;
|
|
51
51
|
export declare function createClient<H extends Host<any> | undefined = undefined, Z extends AuthenticationStrategy<H> = AuthenticationStrategy<H>, T extends Descriptors = EmptyObject>(config: {
|
|
52
52
|
modules?: H extends Host<any> ? AssertHostMatches<T, H> : T;
|
|
53
|
-
auth?: Z;
|
|
53
|
+
auth?: Z | (() => Z);
|
|
54
54
|
headers?: Headers;
|
|
55
55
|
host?: H;
|
|
56
56
|
useCDN?: boolean;
|
package/build/wixClient.js
CHANGED
|
@@ -12,12 +12,14 @@ import { runWithoutContext } from '@wix/sdk-runtime/context';
|
|
|
12
12
|
export const X_WIX_CONSISTENT_HEADER = 'X-Wix-Consistent';
|
|
13
13
|
export function createClient(config) {
|
|
14
14
|
const _headers = config.headers || { Authorization: '' };
|
|
15
|
-
const
|
|
16
|
-
{
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
15
|
+
const defaultStrategy = {
|
|
16
|
+
getAuthHeaders: (_) => Promise.resolve({ headers: {} }),
|
|
17
|
+
};
|
|
18
|
+
const auth = config.auth;
|
|
19
|
+
const getAuthStrategy = typeof auth === 'function' ? auth : () => auth ?? defaultStrategy;
|
|
20
|
+
const boundGetAuthHeaders = () => {
|
|
21
|
+
return getAuthStrategy().getAuthHeaders(config.host);
|
|
22
|
+
};
|
|
21
23
|
const fetchWithAuth = async (urlOrRequest, requestInit) => {
|
|
22
24
|
const authHeaders = await boundGetAuthHeaders();
|
|
23
25
|
const headers = {
|
|
@@ -79,8 +81,8 @@ export function createClient(config) {
|
|
|
79
81
|
throw e;
|
|
80
82
|
}
|
|
81
83
|
};
|
|
82
|
-
const { client: servicePluginsClient, initModule: initServicePluginModule } = servicePluginsModules(
|
|
83
|
-
const { client: eventHandlersClient, initModule: initEventHandlerModule } = eventHandlersModules(
|
|
84
|
+
const { client: servicePluginsClient, initModule: initServicePluginModule } = servicePluginsModules(getAuthStrategy);
|
|
85
|
+
const { client: eventHandlersClient, initModule: initEventHandlerModule } = eventHandlersModules(getAuthStrategy);
|
|
84
86
|
const boundFetch = async (url, options) => {
|
|
85
87
|
const authHeaders = await boundGetAuthHeaders();
|
|
86
88
|
const defaultContentTypeHeader = getDefaultContentHeader(options);
|
|
@@ -125,7 +127,9 @@ export function createClient(config) {
|
|
|
125
127
|
return modules;
|
|
126
128
|
}
|
|
127
129
|
const apiBaseUrl = config.host?.apiBaseUrl ?? DEFAULT_API_URL;
|
|
128
|
-
const shouldUseCDN = config.useCDN === undefined
|
|
130
|
+
const shouldUseCDN = config.useCDN === undefined
|
|
131
|
+
? getAuthStrategy().shouldUseCDN
|
|
132
|
+
: config.useCDN;
|
|
129
133
|
return buildRESTDescriptor(runWithoutContext(() => isAmbassadorModule(modules))
|
|
130
134
|
? toHTTPModule(modules)
|
|
131
135
|
: modules, metadata ?? {}, boundFetch, config.host?.getErrorHandler?.(), (relativeUrl, fetchOptions) => {
|
|
@@ -133,7 +137,7 @@ export function createClient(config) {
|
|
|
133
137
|
finalUrl.host = apiBaseUrl;
|
|
134
138
|
finalUrl.protocol = 'https';
|
|
135
139
|
return boundFetch(finalUrl.toString(), fetchOptions);
|
|
136
|
-
},
|
|
140
|
+
}, getAuthStrategy().getActiveToken, { HTTPHost: apiBaseUrl }, config.host?.name, shouldUseCDN);
|
|
137
141
|
}
|
|
138
142
|
else if (isObject(modules)) {
|
|
139
143
|
return Object.fromEntries(Object.entries(modules).map(([key, value]) => {
|
|
@@ -152,6 +156,8 @@ export function createClient(config) {
|
|
|
152
156
|
const wrappedModules = config.modules
|
|
153
157
|
? use(config.modules)
|
|
154
158
|
: {};
|
|
159
|
+
const authStrategy = { ...getAuthStrategy() };
|
|
160
|
+
authStrategy.getAuthHeaders = boundGetAuthHeaders;
|
|
155
161
|
return {
|
|
156
162
|
...wrappedModules,
|
|
157
163
|
auth: authStrategy,
|
|
@@ -47,7 +47,7 @@ export type EventHandlersClient = Emitter<{
|
|
|
47
47
|
}, 'AppRemoved'>;
|
|
48
48
|
};
|
|
49
49
|
};
|
|
50
|
-
export declare function eventHandlersModules(
|
|
50
|
+
export declare function eventHandlersModules(getAuthStrategy: () => AuthenticationStrategy<any>): {
|
|
51
51
|
initModule(eventDefinition: EventDefinition<any, string>): (handler: EventHandler<EventDefinition<any, string>>) => void;
|
|
52
52
|
client: EventHandlersClient;
|
|
53
53
|
};
|
|
@@ -79,7 +79,7 @@ function runHandler(eventDefinition, handler, payload, baseEventMetadata) {
|
|
|
79
79
|
}
|
|
80
80
|
return handler(transformFromRESTFn(originalEnvelope));
|
|
81
81
|
}
|
|
82
|
-
function eventHandlersModules(
|
|
82
|
+
function eventHandlersModules(getAuthStrategy) {
|
|
83
83
|
const eventHandlers = new Map();
|
|
84
84
|
const webhooksEmitter = (0, nanoevents_js_1.createNanoEvents)();
|
|
85
85
|
const client = {
|
|
@@ -116,6 +116,7 @@ function eventHandlersModules(authStrategy) {
|
|
|
116
116
|
return this.process(body, opts);
|
|
117
117
|
},
|
|
118
118
|
async parseJWT(jwt) {
|
|
119
|
+
const authStrategy = getAuthStrategy();
|
|
119
120
|
if (!authStrategy.decodeJWT) {
|
|
120
121
|
throw new Error('decodeJWT is not supported by the authentication strategy');
|
|
121
122
|
}
|
|
@@ -26,7 +26,7 @@ export type ServicePluginsClient = Emitter<{
|
|
|
26
26
|
parseRequest(request: Request): Promise<ServicePluginRequest>;
|
|
27
27
|
executeHandler(servicePluginRequest: ServicePluginRequest, url: string): Promise<UnknownServicePluginResponse>;
|
|
28
28
|
};
|
|
29
|
-
export declare function servicePluginsModules(
|
|
29
|
+
export declare function servicePluginsModules(getAuthStrategy: () => AuthenticationStrategy<any>): {
|
|
30
30
|
initModule<T extends ServicePluginDefinition<any>>(servicePluginDefinition: T): (implementation: T["__contract"]) => void;
|
|
31
31
|
client: ServicePluginsClient;
|
|
32
32
|
};
|
|
@@ -5,13 +5,14 @@ exports.servicePluginsModules = servicePluginsModules;
|
|
|
5
5
|
const nanoevents_js_1 = require("./nanoevents.js");
|
|
6
6
|
const isServicePluginModule = (val) => val.__type === 'service-plugin-definition';
|
|
7
7
|
exports.isServicePluginModule = isServicePluginModule;
|
|
8
|
-
function servicePluginsModules(
|
|
8
|
+
function servicePluginsModules(getAuthStrategy) {
|
|
9
9
|
const servicePluginsImplementations = new Map();
|
|
10
10
|
const servicePluginsEmitter = (0, nanoevents_js_1.createNanoEvents)();
|
|
11
11
|
const client = {
|
|
12
12
|
...servicePluginsEmitter,
|
|
13
13
|
getRegisteredServicePlugins: () => servicePluginsImplementations,
|
|
14
14
|
async parseJWT(jwt) {
|
|
15
|
+
const authStrategy = getAuthStrategy();
|
|
15
16
|
if (!authStrategy.decodeJWT) {
|
|
16
17
|
throw new Error('decodeJWT is not supported by the authentication strategy');
|
|
17
18
|
}
|
package/cjs/build/wixClient.d.ts
CHANGED
|
@@ -50,7 +50,7 @@ export type WixClient<H extends Host<any> | undefined = undefined, Z extends Aut
|
|
|
50
50
|
} & BuildDescriptors<T, H>;
|
|
51
51
|
export declare function createClient<H extends Host<any> | undefined = undefined, Z extends AuthenticationStrategy<H> = AuthenticationStrategy<H>, T extends Descriptors = EmptyObject>(config: {
|
|
52
52
|
modules?: H extends Host<any> ? AssertHostMatches<T, H> : T;
|
|
53
|
-
auth?: Z;
|
|
53
|
+
auth?: Z | (() => Z);
|
|
54
54
|
headers?: Headers;
|
|
55
55
|
host?: H;
|
|
56
56
|
useCDN?: boolean;
|
package/cjs/build/wixClient.js
CHANGED
|
@@ -16,12 +16,14 @@ const context_1 = require("@wix/sdk-runtime/context");
|
|
|
16
16
|
exports.X_WIX_CONSISTENT_HEADER = 'X-Wix-Consistent';
|
|
17
17
|
function createClient(config) {
|
|
18
18
|
const _headers = config.headers || { Authorization: '' };
|
|
19
|
-
const
|
|
20
|
-
{
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
19
|
+
const defaultStrategy = {
|
|
20
|
+
getAuthHeaders: (_) => Promise.resolve({ headers: {} }),
|
|
21
|
+
};
|
|
22
|
+
const auth = config.auth;
|
|
23
|
+
const getAuthStrategy = typeof auth === 'function' ? auth : () => auth ?? defaultStrategy;
|
|
24
|
+
const boundGetAuthHeaders = () => {
|
|
25
|
+
return getAuthStrategy().getAuthHeaders(config.host);
|
|
26
|
+
};
|
|
25
27
|
const fetchWithAuth = async (urlOrRequest, requestInit) => {
|
|
26
28
|
const authHeaders = await boundGetAuthHeaders();
|
|
27
29
|
const headers = {
|
|
@@ -83,8 +85,8 @@ function createClient(config) {
|
|
|
83
85
|
throw e;
|
|
84
86
|
}
|
|
85
87
|
};
|
|
86
|
-
const { client: servicePluginsClient, initModule: initServicePluginModule } = (0, service_plugin_modules_js_1.servicePluginsModules)(
|
|
87
|
-
const { client: eventHandlersClient, initModule: initEventHandlerModule } = (0, event_handlers_modules_js_1.eventHandlersModules)(
|
|
88
|
+
const { client: servicePluginsClient, initModule: initServicePluginModule } = (0, service_plugin_modules_js_1.servicePluginsModules)(getAuthStrategy);
|
|
89
|
+
const { client: eventHandlersClient, initModule: initEventHandlerModule } = (0, event_handlers_modules_js_1.eventHandlersModules)(getAuthStrategy);
|
|
88
90
|
const boundFetch = async (url, options) => {
|
|
89
91
|
const authHeaders = await boundGetAuthHeaders();
|
|
90
92
|
const defaultContentTypeHeader = (0, helpers_js_1.getDefaultContentHeader)(options);
|
|
@@ -129,7 +131,9 @@ function createClient(config) {
|
|
|
129
131
|
return modules;
|
|
130
132
|
}
|
|
131
133
|
const apiBaseUrl = config.host?.apiBaseUrl ?? common_js_1.DEFAULT_API_URL;
|
|
132
|
-
const shouldUseCDN = config.useCDN === undefined
|
|
134
|
+
const shouldUseCDN = config.useCDN === undefined
|
|
135
|
+
? getAuthStrategy().shouldUseCDN
|
|
136
|
+
: config.useCDN;
|
|
133
137
|
return (0, rest_modules_js_1.buildRESTDescriptor)((0, context_1.runWithoutContext)(() => (0, ambassador_modules_js_1.isAmbassadorModule)(modules))
|
|
134
138
|
? (0, ambassador_modules_js_1.toHTTPModule)(modules)
|
|
135
139
|
: modules, metadata ?? {}, boundFetch, config.host?.getErrorHandler?.(), (relativeUrl, fetchOptions) => {
|
|
@@ -137,7 +141,7 @@ function createClient(config) {
|
|
|
137
141
|
finalUrl.host = apiBaseUrl;
|
|
138
142
|
finalUrl.protocol = 'https';
|
|
139
143
|
return boundFetch(finalUrl.toString(), fetchOptions);
|
|
140
|
-
},
|
|
144
|
+
}, getAuthStrategy().getActiveToken, { HTTPHost: apiBaseUrl }, config.host?.name, shouldUseCDN);
|
|
141
145
|
}
|
|
142
146
|
else if ((0, helpers_js_1.isObject)(modules)) {
|
|
143
147
|
return Object.fromEntries(Object.entries(modules).map(([key, value]) => {
|
|
@@ -156,6 +160,8 @@ function createClient(config) {
|
|
|
156
160
|
const wrappedModules = config.modules
|
|
157
161
|
? use(config.modules)
|
|
158
162
|
: {};
|
|
163
|
+
const authStrategy = { ...getAuthStrategy() };
|
|
164
|
+
authStrategy.getAuthHeaders = boundGetAuthHeaders;
|
|
159
165
|
return {
|
|
160
166
|
...wrappedModules,
|
|
161
167
|
auth: authStrategy,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/sdk",
|
|
3
|
-
"version": "1.17.
|
|
3
|
+
"version": "1.17.7",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Ronny Ringel",
|
|
@@ -127,5 +127,5 @@
|
|
|
127
127
|
"wallaby": {
|
|
128
128
|
"autoDetect": true
|
|
129
129
|
},
|
|
130
|
-
"falconPackageHash": "
|
|
130
|
+
"falconPackageHash": "56ca4bfad88fe040bd3a7acf7270870a21caf1eac8736de6ef704215"
|
|
131
131
|
}
|