@wix/sdk 1.9.5 → 1.9.6
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/service-plugin-modules.d.ts +2 -9
- package/build/service-plugin-modules.js +3 -32
- package/build/wixClient.d.ts +12 -1
- package/build/wixClient.js +42 -1
- package/cjs/build/service-plugin-modules.d.ts +2 -9
- package/cjs/build/service-plugin-modules.js +3 -32
- package/cjs/build/wixClient.d.ts +12 -1
- package/cjs/build/wixClient.js +42 -1
- package/package.json +4 -4
|
@@ -1,15 +1,8 @@
|
|
|
1
1
|
import { ServicePluginContract, ServicePluginDefinition } from '@wix/sdk-types';
|
|
2
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<{
|
|
3
|
+
export declare function buildServicePluginDefinition<T extends ServicePluginDefinition<any>>(servicePluginDefinition: T, registrServicePluginImplementation: (servicePluginDefinition: T, implementation: T['__contract']) => void, decodeJWT?: (token: string, verifyCallerClaims?: boolean) => Promise<{
|
|
4
4
|
decoded: {
|
|
5
5
|
data: string;
|
|
6
6
|
};
|
|
7
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
|
-
};
|
|
8
|
+
}>): (implementation: T['__contract']) => void;
|
|
@@ -1,36 +1,7 @@
|
|
|
1
1
|
import { isObject } from './helpers.js';
|
|
2
2
|
export const isServicePluginModule = (val) => isObject(val) && val.__type === 'service-plugin-definition';
|
|
3
|
-
export function buildServicePluginDefinition(servicePluginDefinition, decodeJWT) {
|
|
4
|
-
|
|
5
|
-
|
|
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,
|
|
3
|
+
export function buildServicePluginDefinition(servicePluginDefinition, registrServicePluginImplementation, decodeJWT) {
|
|
4
|
+
return (implementation) => {
|
|
5
|
+
registrServicePluginImplementation(servicePluginDefinition, implementation);
|
|
35
6
|
};
|
|
36
7
|
}
|
package/build/wixClient.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AuthenticationStrategy, BoundAuthenticationStrategy, BuildEventDefinition, BuildRESTFunction, EventDefinition, EventIdentity, Host, HostModule, HostModuleAPI, RESTFunctionDescriptor, ServicePluginDefinition, BuildServicePluginDefinition } from '@wix/sdk-types';
|
|
1
|
+
import { AuthenticationStrategy, BoundAuthenticationStrategy, BuildEventDefinition, BuildRESTFunction, EventDefinition, EventIdentity, Host, HostModule, HostModuleAPI, RESTFunctionDescriptor, ServicePluginDefinition, BuildServicePluginDefinition, ServicePluginContract } 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';
|
|
@@ -77,6 +77,17 @@ export type WixClient<H extends Host<any> | undefined = undefined, Z extends Aut
|
|
|
77
77
|
}, 'AppRemoved'>;
|
|
78
78
|
};
|
|
79
79
|
};
|
|
80
|
+
servicePlugins: {
|
|
81
|
+
getRegisteredServicePlugins(): Map<string, {
|
|
82
|
+
servicePluginDefinition: ServicePluginDefinition<any>;
|
|
83
|
+
implementation: ServicePluginContract;
|
|
84
|
+
}[]>;
|
|
85
|
+
process(request: {
|
|
86
|
+
url: string;
|
|
87
|
+
body: string;
|
|
88
|
+
}, componentType: string): Promise<unknown>;
|
|
89
|
+
processRequest(request: Request, componentType: string): Promise<Response>;
|
|
90
|
+
};
|
|
80
91
|
} & BuildDescriptors<T, H>;
|
|
81
92
|
type ResolvePossibleEvents<T extends EventDefinition<any>[]> = {
|
|
82
93
|
[K in keyof T]: T[K] extends EventDefinition<any> ? {
|
package/build/wixClient.js
CHANGED
|
@@ -10,6 +10,7 @@ import { buildServicePluginDefinition, isServicePluginModule, } from './service-
|
|
|
10
10
|
export function createClient(config) {
|
|
11
11
|
const _headers = config.headers || { Authorization: '' };
|
|
12
12
|
const eventHandlers = new Map();
|
|
13
|
+
const servicePluginsImplementations = new Map();
|
|
13
14
|
const authStrategy = config.auth ||
|
|
14
15
|
{
|
|
15
16
|
getAuthHeaders: (_) => Promise.resolve({ headers: {} }),
|
|
@@ -41,7 +42,11 @@ export function createClient(config) {
|
|
|
41
42
|
});
|
|
42
43
|
}
|
|
43
44
|
else if (isServicePluginModule(modules)) {
|
|
44
|
-
return buildServicePluginDefinition(modules,
|
|
45
|
+
return buildServicePluginDefinition(modules, (servicePluginDefinition, implementation) => {
|
|
46
|
+
const implementations = servicePluginsImplementations.get(servicePluginDefinition.componentType) ?? [];
|
|
47
|
+
implementations.push({ servicePluginDefinition, implementation });
|
|
48
|
+
servicePluginsImplementations.set(servicePluginDefinition.componentType, implementations);
|
|
49
|
+
});
|
|
45
50
|
}
|
|
46
51
|
else if (isHostModule(modules) && config.host) {
|
|
47
52
|
return buildHostModule(modules, config.host);
|
|
@@ -172,5 +177,41 @@ export function createClient(config) {
|
|
|
172
177
|
AppRemoved: EventDefinition('AppRemoved')(),
|
|
173
178
|
},
|
|
174
179
|
},
|
|
180
|
+
servicePlugins: {
|
|
181
|
+
getRegisteredServicePlugins: () => servicePluginsImplementations,
|
|
182
|
+
async process(request, componentType) {
|
|
183
|
+
if (!authStrategy.decodeJWT) {
|
|
184
|
+
throw new Error('decodeJWT is not supported by the authentication strategy');
|
|
185
|
+
}
|
|
186
|
+
const { decoded, valid } = await authStrategy.decodeJWT(request.body, true);
|
|
187
|
+
if (!valid) {
|
|
188
|
+
throw new Error('JWT is not valid');
|
|
189
|
+
}
|
|
190
|
+
const implementations = servicePluginsImplementations.get(componentType) ?? [];
|
|
191
|
+
if (implementations.length === 0) {
|
|
192
|
+
throw new Error(`No service plugin implementations found for component type ${componentType}`);
|
|
193
|
+
}
|
|
194
|
+
else if (implementations.length > 1) {
|
|
195
|
+
throw new Error(`Multiple service plugin implementations found for component type ${componentType}. This is currently not supported`);
|
|
196
|
+
}
|
|
197
|
+
const { implementation: impl, servicePluginDefinition } = implementations[0];
|
|
198
|
+
const method = servicePluginDefinition.methods.find((m) => request.url.endsWith(m.primaryHttpMappingPath));
|
|
199
|
+
if (!method) {
|
|
200
|
+
throw new Error('Unexpect request: request url did not match any method: ' +
|
|
201
|
+
request.url);
|
|
202
|
+
}
|
|
203
|
+
const implMethod = impl[method.name];
|
|
204
|
+
if (!implMethod) {
|
|
205
|
+
throw new Error(`Got request for service plugin method ${method.name} but no implementation was provided. Available methods: ${Object.keys(impl).join(', ')}`);
|
|
206
|
+
}
|
|
207
|
+
return implMethod(method.transformations.fromREST(decoded.data));
|
|
208
|
+
},
|
|
209
|
+
async processRequest(request, componentType) {
|
|
210
|
+
const url = request.url;
|
|
211
|
+
const body = await request.text();
|
|
212
|
+
const implMethodResult = await this.process({ url, body }, componentType);
|
|
213
|
+
return Response.json(implMethodResult);
|
|
214
|
+
},
|
|
215
|
+
},
|
|
175
216
|
};
|
|
176
217
|
}
|
|
@@ -1,15 +1,8 @@
|
|
|
1
1
|
import { ServicePluginContract, ServicePluginDefinition } from '@wix/sdk-types';
|
|
2
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<{
|
|
3
|
+
export declare function buildServicePluginDefinition<T extends ServicePluginDefinition<any>>(servicePluginDefinition: T, registrServicePluginImplementation: (servicePluginDefinition: T, implementation: T['__contract']) => void, decodeJWT?: (token: string, verifyCallerClaims?: boolean) => Promise<{
|
|
4
4
|
decoded: {
|
|
5
5
|
data: string;
|
|
6
6
|
};
|
|
7
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
|
-
};
|
|
8
|
+
}>): (implementation: T['__contract']) => void;
|
|
@@ -4,38 +4,9 @@ exports.buildServicePluginDefinition = exports.isServicePluginModule = void 0;
|
|
|
4
4
|
const helpers_js_1 = require("./helpers.js");
|
|
5
5
|
const isServicePluginModule = (val) => (0, helpers_js_1.isObject)(val) && val.__type === 'service-plugin-definition';
|
|
6
6
|
exports.isServicePluginModule = isServicePluginModule;
|
|
7
|
-
function buildServicePluginDefinition(servicePluginDefinition, decodeJWT) {
|
|
8
|
-
|
|
9
|
-
|
|
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,
|
|
7
|
+
function buildServicePluginDefinition(servicePluginDefinition, registrServicePluginImplementation, decodeJWT) {
|
|
8
|
+
return (implementation) => {
|
|
9
|
+
registrServicePluginImplementation(servicePluginDefinition, implementation);
|
|
39
10
|
};
|
|
40
11
|
}
|
|
41
12
|
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, ServicePluginDefinition, BuildServicePluginDefinition } from '@wix/sdk-types';
|
|
1
|
+
import { AuthenticationStrategy, BoundAuthenticationStrategy, BuildEventDefinition, BuildRESTFunction, EventDefinition, EventIdentity, Host, HostModule, HostModuleAPI, RESTFunctionDescriptor, ServicePluginDefinition, BuildServicePluginDefinition, ServicePluginContract } 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';
|
|
@@ -77,6 +77,17 @@ export type WixClient<H extends Host<any> | undefined = undefined, Z extends Aut
|
|
|
77
77
|
}, 'AppRemoved'>;
|
|
78
78
|
};
|
|
79
79
|
};
|
|
80
|
+
servicePlugins: {
|
|
81
|
+
getRegisteredServicePlugins(): Map<string, {
|
|
82
|
+
servicePluginDefinition: ServicePluginDefinition<any>;
|
|
83
|
+
implementation: ServicePluginContract;
|
|
84
|
+
}[]>;
|
|
85
|
+
process(request: {
|
|
86
|
+
url: string;
|
|
87
|
+
body: string;
|
|
88
|
+
}, componentType: string): Promise<unknown>;
|
|
89
|
+
processRequest(request: Request, componentType: string): Promise<Response>;
|
|
90
|
+
};
|
|
80
91
|
} & BuildDescriptors<T, H>;
|
|
81
92
|
type ResolvePossibleEvents<T extends EventDefinition<any>[]> = {
|
|
82
93
|
[K in keyof T]: T[K] extends EventDefinition<any> ? {
|
package/cjs/build/wixClient.js
CHANGED
|
@@ -13,6 +13,7 @@ const service_plugin_modules_js_1 = require("./service-plugin-modules.js");
|
|
|
13
13
|
function createClient(config) {
|
|
14
14
|
const _headers = config.headers || { Authorization: '' };
|
|
15
15
|
const eventHandlers = new Map();
|
|
16
|
+
const servicePluginsImplementations = new Map();
|
|
16
17
|
const authStrategy = config.auth ||
|
|
17
18
|
{
|
|
18
19
|
getAuthHeaders: (_) => Promise.resolve({ headers: {} }),
|
|
@@ -44,7 +45,11 @@ function createClient(config) {
|
|
|
44
45
|
});
|
|
45
46
|
}
|
|
46
47
|
else if ((0, service_plugin_modules_js_1.isServicePluginModule)(modules)) {
|
|
47
|
-
return (0, service_plugin_modules_js_1.buildServicePluginDefinition)(modules,
|
|
48
|
+
return (0, service_plugin_modules_js_1.buildServicePluginDefinition)(modules, (servicePluginDefinition, implementation) => {
|
|
49
|
+
const implementations = servicePluginsImplementations.get(servicePluginDefinition.componentType) ?? [];
|
|
50
|
+
implementations.push({ servicePluginDefinition, implementation });
|
|
51
|
+
servicePluginsImplementations.set(servicePluginDefinition.componentType, implementations);
|
|
52
|
+
});
|
|
48
53
|
}
|
|
49
54
|
else if ((0, host_modules_js_1.isHostModule)(modules) && config.host) {
|
|
50
55
|
return (0, host_modules_js_1.buildHostModule)(modules, config.host);
|
|
@@ -175,6 +180,42 @@ function createClient(config) {
|
|
|
175
180
|
AppRemoved: (0, sdk_types_1.EventDefinition)('AppRemoved')(),
|
|
176
181
|
},
|
|
177
182
|
},
|
|
183
|
+
servicePlugins: {
|
|
184
|
+
getRegisteredServicePlugins: () => servicePluginsImplementations,
|
|
185
|
+
async process(request, componentType) {
|
|
186
|
+
if (!authStrategy.decodeJWT) {
|
|
187
|
+
throw new Error('decodeJWT is not supported by the authentication strategy');
|
|
188
|
+
}
|
|
189
|
+
const { decoded, valid } = await authStrategy.decodeJWT(request.body, true);
|
|
190
|
+
if (!valid) {
|
|
191
|
+
throw new Error('JWT is not valid');
|
|
192
|
+
}
|
|
193
|
+
const implementations = servicePluginsImplementations.get(componentType) ?? [];
|
|
194
|
+
if (implementations.length === 0) {
|
|
195
|
+
throw new Error(`No service plugin implementations found for component type ${componentType}`);
|
|
196
|
+
}
|
|
197
|
+
else if (implementations.length > 1) {
|
|
198
|
+
throw new Error(`Multiple service plugin implementations found for component type ${componentType}. This is currently not supported`);
|
|
199
|
+
}
|
|
200
|
+
const { implementation: impl, servicePluginDefinition } = implementations[0];
|
|
201
|
+
const method = servicePluginDefinition.methods.find((m) => request.url.endsWith(m.primaryHttpMappingPath));
|
|
202
|
+
if (!method) {
|
|
203
|
+
throw new Error('Unexpect request: request url did not match any method: ' +
|
|
204
|
+
request.url);
|
|
205
|
+
}
|
|
206
|
+
const implMethod = impl[method.name];
|
|
207
|
+
if (!implMethod) {
|
|
208
|
+
throw new Error(`Got request for service plugin method ${method.name} but no implementation was provided. Available methods: ${Object.keys(impl).join(', ')}`);
|
|
209
|
+
}
|
|
210
|
+
return implMethod(method.transformations.fromREST(decoded.data));
|
|
211
|
+
},
|
|
212
|
+
async processRequest(request, componentType) {
|
|
213
|
+
const url = request.url;
|
|
214
|
+
const body = await request.text();
|
|
215
|
+
const implMethodResult = await this.process({ url, body }, componentType);
|
|
216
|
+
return Response.json(implMethodResult);
|
|
217
|
+
},
|
|
218
|
+
},
|
|
178
219
|
};
|
|
179
220
|
}
|
|
180
221
|
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.6",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Ronny Ringel",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"@wix/identity": "^1.0.78",
|
|
68
68
|
"@wix/image-kit": "^1.68.0",
|
|
69
69
|
"@wix/redirects": "^1.0.41",
|
|
70
|
-
"@wix/sdk-types": "^1.7.
|
|
70
|
+
"@wix/sdk-types": "^1.7.1",
|
|
71
71
|
"crypto-js": "^4.2.0",
|
|
72
72
|
"jose": "^5.2.1",
|
|
73
73
|
"pkce-challenge": "^3.1.0",
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
"@wix/events": "^1.0.179",
|
|
87
87
|
"@wix/metro": "^1.0.73",
|
|
88
88
|
"@wix/metro-runtime": "^1.1677.0",
|
|
89
|
-
"@wix/sdk-runtime": "0.2.
|
|
89
|
+
"@wix/sdk-runtime": "0.2.12",
|
|
90
90
|
"eslint": "^8.56.0",
|
|
91
91
|
"eslint-config-sdk": "0.0.0",
|
|
92
92
|
"graphql": "^16.8.0",
|
|
@@ -120,5 +120,5 @@
|
|
|
120
120
|
"wallaby": {
|
|
121
121
|
"autoDetect": true
|
|
122
122
|
},
|
|
123
|
-
"falconPackageHash": "
|
|
123
|
+
"falconPackageHash": "8ccf00160ad425f42b9bf45df6e3b9284edad603a3cd345c450871f1"
|
|
124
124
|
}
|