@wix/sdk 1.9.8 → 1.9.9

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.
@@ -2,4 +2,6 @@ import { BuildDescriptors, Descriptors, Host } from './index.js';
2
2
  export type WixContext = {
3
3
  initWixModules: <T extends Descriptors, H extends Host>(wixModules: T, elevated?: boolean) => BuildDescriptors<T, H>;
4
4
  };
5
- export declare function setGlobalWixContext(wixContext: WixContext): void;
5
+ export declare function setGlobalWixContext(wixContext: WixContext, options?: {
6
+ dangerouslyOverride?: boolean;
7
+ }): void;
@@ -1,5 +1,5 @@
1
- export function setGlobalWixContext(wixContext) {
2
- if (!globalThis.__wix_context__) {
1
+ export function setGlobalWixContext(wixContext, options = {}) {
2
+ if (!globalThis.__wix_context__ && options.dangerouslyOverride) {
3
3
  globalThis.__wix_context__ = wixContext;
4
4
  }
5
5
  }
@@ -85,8 +85,8 @@ export type WixClient<H extends Host<any> | undefined = undefined, Z extends Aut
85
85
  process(request: {
86
86
  url: string;
87
87
  body: string;
88
- }, componentType: string): Promise<unknown>;
89
- processRequest(request: Request, componentType: string): Promise<Response>;
88
+ }): Promise<unknown>;
89
+ processRequest(request: Request): Promise<Response>;
90
90
  };
91
91
  } & BuildDescriptors<T, H>;
92
92
  type ResolvePossibleEvents<T extends EventDefinition<any>[]> = {
@@ -43,9 +43,9 @@ export function createClient(config) {
43
43
  }
44
44
  else if (isServicePluginModule(modules)) {
45
45
  return buildServicePluginDefinition(modules, (servicePluginDefinition, implementation) => {
46
- const implementations = servicePluginsImplementations.get(servicePluginDefinition.componentType) ?? [];
46
+ const implementations = servicePluginsImplementations.get(servicePluginDefinition.componentType.toLowerCase()) ?? [];
47
47
  implementations.push({ servicePluginDefinition, implementation });
48
- servicePluginsImplementations.set(servicePluginDefinition.componentType, implementations);
48
+ servicePluginsImplementations.set(servicePluginDefinition.componentType.toLowerCase(), implementations);
49
49
  });
50
50
  }
51
51
  else if (isHostModule(modules) && config.host) {
@@ -139,6 +139,9 @@ export function createClient(config) {
139
139
  if (!valid) {
140
140
  throw new Error('JWT is not valid');
141
141
  }
142
+ if (typeof decoded.data !== 'string') {
143
+ throw new Error(`Unexpected type of JWT data: expected string, got ${typeof decoded.data}`);
144
+ }
142
145
  const parsedDecoded = JSON.parse(decoded.data);
143
146
  const eventType = parsedDecoded.eventType;
144
147
  const instanceId = parsedDecoded.instanceId;
@@ -179,7 +182,7 @@ export function createClient(config) {
179
182
  },
180
183
  servicePlugins: {
181
184
  getRegisteredServicePlugins: () => servicePluginsImplementations,
182
- async process(request, componentType) {
185
+ async process(request) {
183
186
  if (!authStrategy.decodeJWT) {
184
187
  throw new Error('decodeJWT is not supported by the authentication strategy');
185
188
  }
@@ -187,6 +190,16 @@ export function createClient(config) {
187
190
  if (!valid) {
188
191
  throw new Error('JWT is not valid');
189
192
  }
193
+ if (typeof decoded.data !== 'object' ||
194
+ decoded.data === null ||
195
+ !('metadata' in decoded.data) ||
196
+ typeof decoded.data.metadata !== 'object' ||
197
+ decoded.data.metadata === null ||
198
+ !('appExtensionType' in decoded.data.metadata) ||
199
+ typeof decoded.data.metadata.appExtensionType !== 'string') {
200
+ throw new Error('Unexpected JWT data: expected object with metadata.appExtensionType string');
201
+ }
202
+ const componentType = decoded.data?.metadata.appExtensionType.toLowerCase();
190
203
  const implementations = servicePluginsImplementations.get(componentType) ?? [];
191
204
  if (implementations.length === 0) {
192
205
  throw new Error(`No service plugin implementations found for component type ${componentType}`);
@@ -206,10 +219,10 @@ export function createClient(config) {
206
219
  }
207
220
  return method.transformations.toREST(await implMethod(method.transformations.fromREST(decoded.data)));
208
221
  },
209
- async processRequest(request, componentType) {
222
+ async processRequest(request) {
210
223
  const url = request.url;
211
224
  const body = await request.text();
212
- const implMethodResult = await this.process({ url, body }, componentType);
225
+ const implMethodResult = await this.process({ url, body });
213
226
  return Response.json(implMethodResult);
214
227
  },
215
228
  },
@@ -2,4 +2,6 @@ import { BuildDescriptors, Descriptors, Host } from './index.js';
2
2
  export type WixContext = {
3
3
  initWixModules: <T extends Descriptors, H extends Host>(wixModules: T, elevated?: boolean) => BuildDescriptors<T, H>;
4
4
  };
5
- export declare function setGlobalWixContext(wixContext: WixContext): void;
5
+ export declare function setGlobalWixContext(wixContext: WixContext, options?: {
6
+ dangerouslyOverride?: boolean;
7
+ }): void;
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.setGlobalWixContext = void 0;
4
- function setGlobalWixContext(wixContext) {
5
- if (!globalThis.__wix_context__) {
4
+ function setGlobalWixContext(wixContext, options = {}) {
5
+ if (!globalThis.__wix_context__ && options.dangerouslyOverride) {
6
6
  globalThis.__wix_context__ = wixContext;
7
7
  }
8
8
  }
@@ -85,8 +85,8 @@ export type WixClient<H extends Host<any> | undefined = undefined, Z extends Aut
85
85
  process(request: {
86
86
  url: string;
87
87
  body: string;
88
- }, componentType: string): Promise<unknown>;
89
- processRequest(request: Request, componentType: string): Promise<Response>;
88
+ }): Promise<unknown>;
89
+ processRequest(request: Request): Promise<Response>;
90
90
  };
91
91
  } & BuildDescriptors<T, H>;
92
92
  type ResolvePossibleEvents<T extends EventDefinition<any>[]> = {
@@ -46,9 +46,9 @@ function createClient(config) {
46
46
  }
47
47
  else if ((0, service_plugin_modules_js_1.isServicePluginModule)(modules)) {
48
48
  return (0, service_plugin_modules_js_1.buildServicePluginDefinition)(modules, (servicePluginDefinition, implementation) => {
49
- const implementations = servicePluginsImplementations.get(servicePluginDefinition.componentType) ?? [];
49
+ const implementations = servicePluginsImplementations.get(servicePluginDefinition.componentType.toLowerCase()) ?? [];
50
50
  implementations.push({ servicePluginDefinition, implementation });
51
- servicePluginsImplementations.set(servicePluginDefinition.componentType, implementations);
51
+ servicePluginsImplementations.set(servicePluginDefinition.componentType.toLowerCase(), implementations);
52
52
  });
53
53
  }
54
54
  else if ((0, host_modules_js_1.isHostModule)(modules) && config.host) {
@@ -142,6 +142,9 @@ function createClient(config) {
142
142
  if (!valid) {
143
143
  throw new Error('JWT is not valid');
144
144
  }
145
+ if (typeof decoded.data !== 'string') {
146
+ throw new Error(`Unexpected type of JWT data: expected string, got ${typeof decoded.data}`);
147
+ }
145
148
  const parsedDecoded = JSON.parse(decoded.data);
146
149
  const eventType = parsedDecoded.eventType;
147
150
  const instanceId = parsedDecoded.instanceId;
@@ -182,7 +185,7 @@ function createClient(config) {
182
185
  },
183
186
  servicePlugins: {
184
187
  getRegisteredServicePlugins: () => servicePluginsImplementations,
185
- async process(request, componentType) {
188
+ async process(request) {
186
189
  if (!authStrategy.decodeJWT) {
187
190
  throw new Error('decodeJWT is not supported by the authentication strategy');
188
191
  }
@@ -190,6 +193,16 @@ function createClient(config) {
190
193
  if (!valid) {
191
194
  throw new Error('JWT is not valid');
192
195
  }
196
+ if (typeof decoded.data !== 'object' ||
197
+ decoded.data === null ||
198
+ !('metadata' in decoded.data) ||
199
+ typeof decoded.data.metadata !== 'object' ||
200
+ decoded.data.metadata === null ||
201
+ !('appExtensionType' in decoded.data.metadata) ||
202
+ typeof decoded.data.metadata.appExtensionType !== 'string') {
203
+ throw new Error('Unexpected JWT data: expected object with metadata.appExtensionType string');
204
+ }
205
+ const componentType = decoded.data?.metadata.appExtensionType.toLowerCase();
193
206
  const implementations = servicePluginsImplementations.get(componentType) ?? [];
194
207
  if (implementations.length === 0) {
195
208
  throw new Error(`No service plugin implementations found for component type ${componentType}`);
@@ -209,10 +222,10 @@ function createClient(config) {
209
222
  }
210
223
  return method.transformations.toREST(await implMethod(method.transformations.fromREST(decoded.data)));
211
224
  },
212
- async processRequest(request, componentType) {
225
+ async processRequest(request) {
213
226
  const url = request.url;
214
227
  const body = await request.text();
215
- const implMethodResult = await this.process({ url, body }, componentType);
228
+ const implMethodResult = await this.process({ url, body });
216
229
  return Response.json(implMethodResult);
217
230
  },
218
231
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/sdk",
3
- "version": "1.9.8",
3
+ "version": "1.9.9",
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.0",
68
+ "@wix/image-kit": "^1.69.0",
69
69
  "@wix/redirects": "^1.0.41",
70
- "@wix/sdk-types": "^1.7.2",
70
+ "@wix/sdk-types": "^1.7.3",
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": "e54c791dea32ccc3284789ca35f54c8187eda8e78badbe988df64cc3"
123
+ "falconPackageHash": "278ec14f84542dbb817d907aef5519c1b8b884f18af98b44141eac77"
124
124
  }