@wix/sdk 1.9.3 → 1.9.5
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/auth/wix-app-oauth/package.json +1 -1
- package/build/service-plugin-modules.d.ts +15 -0
- package/build/service-plugin-modules.js +36 -0
- package/build/wixClient.d.ts +4 -8
- package/build/wixClient.js +5 -21
- package/cjs/build/service-plugin-modules.d.ts +15 -0
- package/cjs/build/service-plugin-modules.js +41 -0
- package/cjs/build/wixClient.d.ts +4 -8
- package/cjs/build/wixClient.js +5 -21
- package/package.json +4 -4
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ServicePluginContract, ServicePluginDefinition } from '@wix/sdk-types';
|
|
2
|
+
export declare const isServicePluginModule: (val: any) => val is ServicePluginDefinition<ServicePluginContract>;
|
|
3
|
+
export declare function buildServicePluginDefinition<T extends ServicePluginDefinition<any>>(servicePluginDefinition: T, decodeJWT?: (token: string, verifyCallerClaims?: boolean) => Promise<{
|
|
4
|
+
decoded: {
|
|
5
|
+
data: string;
|
|
6
|
+
};
|
|
7
|
+
valid: boolean;
|
|
8
|
+
}>): {
|
|
9
|
+
provide(implementation: T['__contract']): void;
|
|
10
|
+
processRequest(request: Request): Promise<Response>;
|
|
11
|
+
process: (request: {
|
|
12
|
+
url: string;
|
|
13
|
+
body: string;
|
|
14
|
+
}) => Promise<any>;
|
|
15
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { isObject } from './helpers.js';
|
|
2
|
+
export const isServicePluginModule = (val) => isObject(val) && val.__type === 'service-plugin-definition';
|
|
3
|
+
export function buildServicePluginDefinition(servicePluginDefinition, decodeJWT) {
|
|
4
|
+
let impl;
|
|
5
|
+
async function process(request) {
|
|
6
|
+
if (!decodeJWT) {
|
|
7
|
+
throw new Error('decodeJWT is not supported by the authentication strategy');
|
|
8
|
+
}
|
|
9
|
+
const { decoded, valid } = await decodeJWT(request.body, true);
|
|
10
|
+
if (!valid) {
|
|
11
|
+
throw new Error('JWT is not valid');
|
|
12
|
+
}
|
|
13
|
+
const method = servicePluginDefinition.methods.find((m) => request.url.endsWith(m.primaryHttpMappingPath));
|
|
14
|
+
if (!method) {
|
|
15
|
+
throw new Error('Unexpect request: request url did not match any method: ' +
|
|
16
|
+
request.url);
|
|
17
|
+
}
|
|
18
|
+
const implMethod = impl[method.name];
|
|
19
|
+
if (!implMethod) {
|
|
20
|
+
throw new Error(`Got request for service plugin method ${method.name} but no implementation was provided. Available methods: ${Object.keys(impl).join(', ')}`);
|
|
21
|
+
}
|
|
22
|
+
return implMethod(method.transformations.fromREST(decoded.data));
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
provide(implementation) {
|
|
26
|
+
impl = implementation;
|
|
27
|
+
},
|
|
28
|
+
async processRequest(request) {
|
|
29
|
+
const url = request.url;
|
|
30
|
+
const body = await request.text();
|
|
31
|
+
const implMethodResult = await process({ url, body });
|
|
32
|
+
return Response.json(implMethodResult);
|
|
33
|
+
},
|
|
34
|
+
process,
|
|
35
|
+
};
|
|
36
|
+
}
|
package/build/wixClient.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AuthenticationStrategy, BoundAuthenticationStrategy, BuildEventDefinition, BuildRESTFunction, EventDefinition, EventIdentity, Host, HostModule, HostModuleAPI, RESTFunctionDescriptor,
|
|
1
|
+
import { AuthenticationStrategy, BoundAuthenticationStrategy, BuildEventDefinition, BuildRESTFunction, EventDefinition, EventIdentity, Host, HostModule, HostModuleAPI, RESTFunctionDescriptor, ServicePluginDefinition, BuildServicePluginDefinition } from '@wix/sdk-types';
|
|
2
2
|
import { ConditionalExcept } from 'type-fest/source/conditional-except.js';
|
|
3
3
|
import { EmptyObject } from 'type-fest/source/empty-object.js';
|
|
4
4
|
import { AmbassadorFunctionDescriptor, BuildAmbassadorFunction } from './ambassador-modules.js';
|
|
@@ -13,7 +13,7 @@ type Headers = Record<string, string>;
|
|
|
13
13
|
*/
|
|
14
14
|
export type BuildDescriptors<T extends Descriptors, H extends Host<any> | undefined, Depth extends number = 5> = {
|
|
15
15
|
done: T;
|
|
16
|
-
recurse: T extends AmbassadorFunctionDescriptor ? BuildAmbassadorFunction<T> : T extends RESTFunctionDescriptor ? BuildRESTFunction<T> : T extends EventDefinition ? BuildEventDefinition<T> : T extends HostModule<any, any> ? HostModuleAPI<T> : ConditionalExcept<{
|
|
16
|
+
recurse: T extends AmbassadorFunctionDescriptor ? BuildAmbassadorFunction<T> : T extends RESTFunctionDescriptor ? BuildRESTFunction<T> : T extends EventDefinition ? BuildEventDefinition<T> : T extends ServicePluginDefinition<any> ? BuildServicePluginDefinition<T> : T extends HostModule<any, any> ? HostModuleAPI<T> : ConditionalExcept<{
|
|
17
17
|
[Key in keyof T]: T[Key] extends Descriptors ? BuildDescriptors<T[Key], H, [-1, 0, 1, 2, 3, 4, 5][Depth]> : never;
|
|
18
18
|
}, EmptyObject>;
|
|
19
19
|
}[Depth extends -1 ? 'done' : 'recurse'];
|
|
@@ -48,7 +48,7 @@ type TypedQueryInput<Result = {
|
|
|
48
48
|
*/
|
|
49
49
|
__ensureTypesOfVariablesAndResultMatching?: (variables: Variables) => Result;
|
|
50
50
|
};
|
|
51
|
-
export type WixClient<H extends Host<any> | undefined = undefined, Z extends AuthenticationStrategy<H> = AuthenticationStrategy<H>, T extends Descriptors =
|
|
51
|
+
export type WixClient<H extends Host<any> | undefined = undefined, Z extends AuthenticationStrategy<H> = AuthenticationStrategy<H>, T extends Descriptors = {}> = {
|
|
52
52
|
setHeaders(headers: Headers): void;
|
|
53
53
|
auth: Omit<Z, 'getAuthHeaders'> & BoundAuthenticationStrategy;
|
|
54
54
|
withAuth: Z['withAuth'] extends undefined ? never : (...args: Parameters<NonNullable<Z['withAuth']>>) => WixClient<H, Z, T>;
|
|
@@ -60,6 +60,7 @@ export type WixClient<H extends Host<any> | undefined = undefined, Z extends Aut
|
|
|
60
60
|
errors?: GraphQLFormattedError[];
|
|
61
61
|
}>;
|
|
62
62
|
webhooks: {
|
|
63
|
+
getRegisteredEvents(): string[];
|
|
63
64
|
process<ExpectedEvents extends EventDefinition<any>[] = []>(jwt: string, opts?: {
|
|
64
65
|
expectedEvents: ExpectedEvents;
|
|
65
66
|
}): Promise<ProcessedEvent<ExpectedEvents>>;
|
|
@@ -76,11 +77,6 @@ export type WixClient<H extends Host<any> | undefined = undefined, Z extends Aut
|
|
|
76
77
|
}, 'AppRemoved'>;
|
|
77
78
|
};
|
|
78
79
|
};
|
|
79
|
-
spi: <S extends SPIDefinition<any, any>>() => {
|
|
80
|
-
process(jwt: string): Promise<S['__input']>;
|
|
81
|
-
processRequest(request: Request): Promise<S['__input']>;
|
|
82
|
-
result(result: S['__result']): S['__result'];
|
|
83
|
-
};
|
|
84
80
|
} & BuildDescriptors<T, H>;
|
|
85
81
|
type ResolvePossibleEvents<T extends EventDefinition<any>[]> = {
|
|
86
82
|
[K in keyof T]: T[K] extends EventDefinition<any> ? {
|
package/build/wixClient.js
CHANGED
|
@@ -6,6 +6,7 @@ import { getDefaultContentHeader, isObject } from './helpers.js';
|
|
|
6
6
|
import { buildHostModule, isHostModule } from './host-modules.js';
|
|
7
7
|
import { buildRESTDescriptor } from './rest-modules.js';
|
|
8
8
|
import { buildEventDefinition, isEventHandlerModule, runHandler, } from './event-handlers-modules.js';
|
|
9
|
+
import { buildServicePluginDefinition, isServicePluginModule, } from './service-plugin-modules.js';
|
|
9
10
|
export function createClient(config) {
|
|
10
11
|
const _headers = config.headers || { Authorization: '' };
|
|
11
12
|
const eventHandlers = new Map();
|
|
@@ -39,6 +40,9 @@ export function createClient(config) {
|
|
|
39
40
|
eventHandlers.set(eventDefinition.type, handlers);
|
|
40
41
|
});
|
|
41
42
|
}
|
|
43
|
+
else if (isServicePluginModule(modules)) {
|
|
44
|
+
return buildServicePluginDefinition(modules, authStrategy.decodeJWT);
|
|
45
|
+
}
|
|
42
46
|
else if (isHostModule(modules) && config.host) {
|
|
43
47
|
return buildHostModule(modules, config.host);
|
|
44
48
|
}
|
|
@@ -119,6 +123,7 @@ export function createClient(config) {
|
|
|
119
123
|
return { data: data ?? {}, errors };
|
|
120
124
|
},
|
|
121
125
|
webhooks: {
|
|
126
|
+
getRegisteredEvents: () => Array.from(eventHandlers.keys()),
|
|
122
127
|
process: async (jwt, opts = {
|
|
123
128
|
expectedEvents: [],
|
|
124
129
|
}) => {
|
|
@@ -167,26 +172,5 @@ export function createClient(config) {
|
|
|
167
172
|
AppRemoved: EventDefinition('AppRemoved')(),
|
|
168
173
|
},
|
|
169
174
|
},
|
|
170
|
-
spi() {
|
|
171
|
-
return {
|
|
172
|
-
async process(jwt) {
|
|
173
|
-
if (!authStrategy.decodeJWT) {
|
|
174
|
-
throw new Error('decodeJWT is not supported by the authentication strategy');
|
|
175
|
-
}
|
|
176
|
-
const { decoded, valid } = await authStrategy.decodeJWT(jwt, true);
|
|
177
|
-
if (!valid) {
|
|
178
|
-
throw new Error('JWT is not valid');
|
|
179
|
-
}
|
|
180
|
-
return decoded.data;
|
|
181
|
-
},
|
|
182
|
-
async processRequest(request) {
|
|
183
|
-
const body = await request.text();
|
|
184
|
-
return this.process(body);
|
|
185
|
-
},
|
|
186
|
-
result(result) {
|
|
187
|
-
return result;
|
|
188
|
-
},
|
|
189
|
-
};
|
|
190
|
-
},
|
|
191
175
|
};
|
|
192
176
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ServicePluginContract, ServicePluginDefinition } from '@wix/sdk-types';
|
|
2
|
+
export declare const isServicePluginModule: (val: any) => val is ServicePluginDefinition<ServicePluginContract>;
|
|
3
|
+
export declare function buildServicePluginDefinition<T extends ServicePluginDefinition<any>>(servicePluginDefinition: T, decodeJWT?: (token: string, verifyCallerClaims?: boolean) => Promise<{
|
|
4
|
+
decoded: {
|
|
5
|
+
data: string;
|
|
6
|
+
};
|
|
7
|
+
valid: boolean;
|
|
8
|
+
}>): {
|
|
9
|
+
provide(implementation: T['__contract']): void;
|
|
10
|
+
processRequest(request: Request): Promise<Response>;
|
|
11
|
+
process: (request: {
|
|
12
|
+
url: string;
|
|
13
|
+
body: string;
|
|
14
|
+
}) => Promise<any>;
|
|
15
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildServicePluginDefinition = exports.isServicePluginModule = void 0;
|
|
4
|
+
const helpers_js_1 = require("./helpers.js");
|
|
5
|
+
const isServicePluginModule = (val) => (0, helpers_js_1.isObject)(val) && val.__type === 'service-plugin-definition';
|
|
6
|
+
exports.isServicePluginModule = isServicePluginModule;
|
|
7
|
+
function buildServicePluginDefinition(servicePluginDefinition, decodeJWT) {
|
|
8
|
+
let impl;
|
|
9
|
+
async function process(request) {
|
|
10
|
+
if (!decodeJWT) {
|
|
11
|
+
throw new Error('decodeJWT is not supported by the authentication strategy');
|
|
12
|
+
}
|
|
13
|
+
const { decoded, valid } = await decodeJWT(request.body, true);
|
|
14
|
+
if (!valid) {
|
|
15
|
+
throw new Error('JWT is not valid');
|
|
16
|
+
}
|
|
17
|
+
const method = servicePluginDefinition.methods.find((m) => request.url.endsWith(m.primaryHttpMappingPath));
|
|
18
|
+
if (!method) {
|
|
19
|
+
throw new Error('Unexpect request: request url did not match any method: ' +
|
|
20
|
+
request.url);
|
|
21
|
+
}
|
|
22
|
+
const implMethod = impl[method.name];
|
|
23
|
+
if (!implMethod) {
|
|
24
|
+
throw new Error(`Got request for service plugin method ${method.name} but no implementation was provided. Available methods: ${Object.keys(impl).join(', ')}`);
|
|
25
|
+
}
|
|
26
|
+
return implMethod(method.transformations.fromREST(decoded.data));
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
provide(implementation) {
|
|
30
|
+
impl = implementation;
|
|
31
|
+
},
|
|
32
|
+
async processRequest(request) {
|
|
33
|
+
const url = request.url;
|
|
34
|
+
const body = await request.text();
|
|
35
|
+
const implMethodResult = await process({ url, body });
|
|
36
|
+
return Response.json(implMethodResult);
|
|
37
|
+
},
|
|
38
|
+
process,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
exports.buildServicePluginDefinition = buildServicePluginDefinition;
|
package/cjs/build/wixClient.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AuthenticationStrategy, BoundAuthenticationStrategy, BuildEventDefinition, BuildRESTFunction, EventDefinition, EventIdentity, Host, HostModule, HostModuleAPI, RESTFunctionDescriptor,
|
|
1
|
+
import { AuthenticationStrategy, BoundAuthenticationStrategy, BuildEventDefinition, BuildRESTFunction, EventDefinition, EventIdentity, Host, HostModule, HostModuleAPI, RESTFunctionDescriptor, ServicePluginDefinition, BuildServicePluginDefinition } from '@wix/sdk-types';
|
|
2
2
|
import { ConditionalExcept } from 'type-fest/source/conditional-except.js';
|
|
3
3
|
import { EmptyObject } from 'type-fest/source/empty-object.js';
|
|
4
4
|
import { AmbassadorFunctionDescriptor, BuildAmbassadorFunction } from './ambassador-modules.js';
|
|
@@ -13,7 +13,7 @@ type Headers = Record<string, string>;
|
|
|
13
13
|
*/
|
|
14
14
|
export type BuildDescriptors<T extends Descriptors, H extends Host<any> | undefined, Depth extends number = 5> = {
|
|
15
15
|
done: T;
|
|
16
|
-
recurse: T extends AmbassadorFunctionDescriptor ? BuildAmbassadorFunction<T> : T extends RESTFunctionDescriptor ? BuildRESTFunction<T> : T extends EventDefinition ? BuildEventDefinition<T> : T extends HostModule<any, any> ? HostModuleAPI<T> : ConditionalExcept<{
|
|
16
|
+
recurse: T extends AmbassadorFunctionDescriptor ? BuildAmbassadorFunction<T> : T extends RESTFunctionDescriptor ? BuildRESTFunction<T> : T extends EventDefinition ? BuildEventDefinition<T> : T extends ServicePluginDefinition<any> ? BuildServicePluginDefinition<T> : T extends HostModule<any, any> ? HostModuleAPI<T> : ConditionalExcept<{
|
|
17
17
|
[Key in keyof T]: T[Key] extends Descriptors ? BuildDescriptors<T[Key], H, [-1, 0, 1, 2, 3, 4, 5][Depth]> : never;
|
|
18
18
|
}, EmptyObject>;
|
|
19
19
|
}[Depth extends -1 ? 'done' : 'recurse'];
|
|
@@ -48,7 +48,7 @@ type TypedQueryInput<Result = {
|
|
|
48
48
|
*/
|
|
49
49
|
__ensureTypesOfVariablesAndResultMatching?: (variables: Variables) => Result;
|
|
50
50
|
};
|
|
51
|
-
export type WixClient<H extends Host<any> | undefined = undefined, Z extends AuthenticationStrategy<H> = AuthenticationStrategy<H>, T extends Descriptors =
|
|
51
|
+
export type WixClient<H extends Host<any> | undefined = undefined, Z extends AuthenticationStrategy<H> = AuthenticationStrategy<H>, T extends Descriptors = {}> = {
|
|
52
52
|
setHeaders(headers: Headers): void;
|
|
53
53
|
auth: Omit<Z, 'getAuthHeaders'> & BoundAuthenticationStrategy;
|
|
54
54
|
withAuth: Z['withAuth'] extends undefined ? never : (...args: Parameters<NonNullable<Z['withAuth']>>) => WixClient<H, Z, T>;
|
|
@@ -60,6 +60,7 @@ export type WixClient<H extends Host<any> | undefined = undefined, Z extends Aut
|
|
|
60
60
|
errors?: GraphQLFormattedError[];
|
|
61
61
|
}>;
|
|
62
62
|
webhooks: {
|
|
63
|
+
getRegisteredEvents(): string[];
|
|
63
64
|
process<ExpectedEvents extends EventDefinition<any>[] = []>(jwt: string, opts?: {
|
|
64
65
|
expectedEvents: ExpectedEvents;
|
|
65
66
|
}): Promise<ProcessedEvent<ExpectedEvents>>;
|
|
@@ -76,11 +77,6 @@ export type WixClient<H extends Host<any> | undefined = undefined, Z extends Aut
|
|
|
76
77
|
}, 'AppRemoved'>;
|
|
77
78
|
};
|
|
78
79
|
};
|
|
79
|
-
spi: <S extends SPIDefinition<any, any>>() => {
|
|
80
|
-
process(jwt: string): Promise<S['__input']>;
|
|
81
|
-
processRequest(request: Request): Promise<S['__input']>;
|
|
82
|
-
result(result: S['__result']): S['__result'];
|
|
83
|
-
};
|
|
84
80
|
} & BuildDescriptors<T, H>;
|
|
85
81
|
type ResolvePossibleEvents<T extends EventDefinition<any>[]> = {
|
|
86
82
|
[K in keyof T]: T[K] extends EventDefinition<any> ? {
|
package/cjs/build/wixClient.js
CHANGED
|
@@ -9,6 +9,7 @@ const helpers_js_1 = require("./helpers.js");
|
|
|
9
9
|
const host_modules_js_1 = require("./host-modules.js");
|
|
10
10
|
const rest_modules_js_1 = require("./rest-modules.js");
|
|
11
11
|
const event_handlers_modules_js_1 = require("./event-handlers-modules.js");
|
|
12
|
+
const service_plugin_modules_js_1 = require("./service-plugin-modules.js");
|
|
12
13
|
function createClient(config) {
|
|
13
14
|
const _headers = config.headers || { Authorization: '' };
|
|
14
15
|
const eventHandlers = new Map();
|
|
@@ -42,6 +43,9 @@ function createClient(config) {
|
|
|
42
43
|
eventHandlers.set(eventDefinition.type, handlers);
|
|
43
44
|
});
|
|
44
45
|
}
|
|
46
|
+
else if ((0, service_plugin_modules_js_1.isServicePluginModule)(modules)) {
|
|
47
|
+
return (0, service_plugin_modules_js_1.buildServicePluginDefinition)(modules, authStrategy.decodeJWT);
|
|
48
|
+
}
|
|
45
49
|
else if ((0, host_modules_js_1.isHostModule)(modules) && config.host) {
|
|
46
50
|
return (0, host_modules_js_1.buildHostModule)(modules, config.host);
|
|
47
51
|
}
|
|
@@ -122,6 +126,7 @@ function createClient(config) {
|
|
|
122
126
|
return { data: data ?? {}, errors };
|
|
123
127
|
},
|
|
124
128
|
webhooks: {
|
|
129
|
+
getRegisteredEvents: () => Array.from(eventHandlers.keys()),
|
|
125
130
|
process: async (jwt, opts = {
|
|
126
131
|
expectedEvents: [],
|
|
127
132
|
}) => {
|
|
@@ -170,27 +175,6 @@ function createClient(config) {
|
|
|
170
175
|
AppRemoved: (0, sdk_types_1.EventDefinition)('AppRemoved')(),
|
|
171
176
|
},
|
|
172
177
|
},
|
|
173
|
-
spi() {
|
|
174
|
-
return {
|
|
175
|
-
async process(jwt) {
|
|
176
|
-
if (!authStrategy.decodeJWT) {
|
|
177
|
-
throw new Error('decodeJWT is not supported by the authentication strategy');
|
|
178
|
-
}
|
|
179
|
-
const { decoded, valid } = await authStrategy.decodeJWT(jwt, true);
|
|
180
|
-
if (!valid) {
|
|
181
|
-
throw new Error('JWT is not valid');
|
|
182
|
-
}
|
|
183
|
-
return decoded.data;
|
|
184
|
-
},
|
|
185
|
-
async processRequest(request) {
|
|
186
|
-
const body = await request.text();
|
|
187
|
-
return this.process(body);
|
|
188
|
-
},
|
|
189
|
-
result(result) {
|
|
190
|
-
return result;
|
|
191
|
-
},
|
|
192
|
-
};
|
|
193
|
-
},
|
|
194
178
|
};
|
|
195
179
|
}
|
|
196
180
|
exports.createClient = createClient;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/sdk",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.5",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Ronny Ringel",
|
|
@@ -65,9 +65,9 @@
|
|
|
65
65
|
"dependencies": {
|
|
66
66
|
"@babel/runtime": "^7.23.2",
|
|
67
67
|
"@wix/identity": "^1.0.78",
|
|
68
|
-
"@wix/image-kit": "^1.
|
|
68
|
+
"@wix/image-kit": "^1.68.0",
|
|
69
69
|
"@wix/redirects": "^1.0.41",
|
|
70
|
-
"@wix/sdk-types": "^1.
|
|
70
|
+
"@wix/sdk-types": "^1.7.0",
|
|
71
71
|
"crypto-js": "^4.2.0",
|
|
72
72
|
"jose": "^5.2.1",
|
|
73
73
|
"pkce-challenge": "^3.1.0",
|
|
@@ -120,5 +120,5 @@
|
|
|
120
120
|
"wallaby": {
|
|
121
121
|
"autoDetect": true
|
|
122
122
|
},
|
|
123
|
-
"falconPackageHash": "
|
|
123
|
+
"falconPackageHash": "4847889c9a664c68045c56437187e8d89efdb0f75d76f39ec415d644"
|
|
124
124
|
}
|