@wix/sdk 1.8.1 → 1.9.1

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.
@@ -1,11 +1,11 @@
1
1
  import { AuthenticationStrategy } from '@wix/sdk-types';
2
- export type WixAppOAuthStrategy = AuthenticationStrategy<undefined, (opts: {
2
+ export type AppOAuthStrategy = AuthenticationStrategy<undefined, (opts: {
3
3
  instanceId: string;
4
4
  } | {
5
5
  refreshToken: string;
6
6
  } | {
7
7
  fromRequest: Request;
8
- }) => WixAppOAuthStrategy> & {
8
+ }) => AppOAuthStrategy> & {
9
9
  getInstallUrl(opts: {
10
10
  redirectUrl: string;
11
11
  state?: string;
@@ -31,11 +31,11 @@ export type WixAppOAuthStrategy = AuthenticationStrategy<undefined, (opts: {
31
31
  * @returns An authentication strategy that can be used with WixClient
32
32
  * @example
33
33
  * ```ts
34
- * import { WixAppOAuthStrategy, createClient } from '@wix/sdk';
34
+ * import { AppOAuthStrategy, createClient } from '@wix/sdk';
35
35
  * import { products } from '@wix/stores';
36
36
  *
37
37
  * const client = createClient({
38
- * auth: WixAppOAuthStrategy({
38
+ * auth: AppOAuthStrategy({
39
39
  * appId: 'appId',
40
40
  * appSecret: 'appSecret',
41
41
  * }),
@@ -57,7 +57,7 @@ export type WixAppOAuthStrategy = AuthenticationStrategy<undefined, (opts: {
57
57
  *
58
58
  * ```
59
59
  */
60
- export declare function WixAppOAuthStrategy(opts: {
60
+ export declare function AppOAuthStrategy(opts: {
61
61
  appId: string;
62
62
  appSecret?: string;
63
63
  publicKey?: string;
@@ -67,4 +67,4 @@ export declare function WixAppOAuthStrategy(opts: {
67
67
  instanceId?: string;
68
68
  } | {
69
69
  accessToken?: string;
70
- })): WixAppOAuthStrategy;
70
+ })): AppOAuthStrategy;
@@ -11,11 +11,11 @@ import { parsePublicKeyIfEncoded } from '../helpers.js';
11
11
  * @returns An authentication strategy that can be used with WixClient
12
12
  * @example
13
13
  * ```ts
14
- * import { WixAppOAuthStrategy, createClient } from '@wix/sdk';
14
+ * import { AppOAuthStrategy, createClient } from '@wix/sdk';
15
15
  * import { products } from '@wix/stores';
16
16
  *
17
17
  * const client = createClient({
18
- * auth: WixAppOAuthStrategy({
18
+ * auth: AppOAuthStrategy({
19
19
  * appId: 'appId',
20
20
  * appSecret: 'appSecret',
21
21
  * }),
@@ -38,7 +38,7 @@ import { parsePublicKeyIfEncoded } from '../helpers.js';
38
38
  * ```
39
39
  */
40
40
  // eslint-disable-next-line @typescript-eslint/no-redeclare
41
- export function WixAppOAuthStrategy(opts) {
41
+ export function AppOAuthStrategy(opts) {
42
42
  let refreshToken = 'refreshToken' in opts ? opts.refreshToken : undefined;
43
43
  return {
44
44
  getInstallUrl({ redirectUrl, token, state }) {
@@ -55,7 +55,7 @@ export function WixAppOAuthStrategy(opts) {
55
55
  },
56
56
  withAuth(params) {
57
57
  if ('instanceId' in params) {
58
- return WixAppOAuthStrategy({
58
+ return AppOAuthStrategy({
59
59
  appId: opts.appId,
60
60
  appSecret: opts.appSecret,
61
61
  publicKey: opts.publicKey,
@@ -63,7 +63,7 @@ export function WixAppOAuthStrategy(opts) {
63
63
  });
64
64
  }
65
65
  else if ('refreshToken' in params) {
66
- return WixAppOAuthStrategy({
66
+ return AppOAuthStrategy({
67
67
  appId: opts.appId,
68
68
  appSecret: opts.appSecret,
69
69
  publicKey: opts.publicKey,
@@ -75,7 +75,7 @@ export function WixAppOAuthStrategy(opts) {
75
75
  if (!authFromRequest) {
76
76
  throw new Error('Missing Authorization header in the request');
77
77
  }
78
- return WixAppOAuthStrategy({
78
+ return AppOAuthStrategy({
79
79
  appId: opts.appId,
80
80
  appSecret: opts.appSecret,
81
81
  publicKey: opts.publicKey,
@@ -88,7 +88,7 @@ export function WixAppOAuthStrategy(opts) {
88
88
  },
89
89
  async handleOAuthCallback(url, oauthOpts) {
90
90
  if (!opts.appSecret) {
91
- throw new Error('App secret is required for handling OAuth callback. Make sure to pass it to the WixAppOAuthStrategy');
91
+ throw new Error('App secret is required for handling OAuth callback. Make sure to pass it to the AppOAuthStrategy');
92
92
  }
93
93
  const params = new URLSearchParams(new URL(url).search);
94
94
  const state = params.get('state');
@@ -125,7 +125,7 @@ export function WixAppOAuthStrategy(opts) {
125
125
  },
126
126
  async getAuthHeaders() {
127
127
  if (!opts.appSecret) {
128
- throw new Error('App secret is required for retrieveing app-level access tokens. Make sure to pass it to the WixAppOAuthStrategy');
128
+ throw new Error('App secret is required for retrieveing app-level access tokens. Make sure to pass it to the AppOAuthStrategy');
129
129
  }
130
130
  if ('refreshToken' in opts || refreshToken) {
131
131
  const tokensRes = await fetch('https://www.wixapis.com/oauth/access', {
@@ -182,12 +182,12 @@ export function WixAppOAuthStrategy(opts) {
182
182
  };
183
183
  }
184
184
  else {
185
- throw new Error('Missing refresh token or instance ID. Either one is needed to get app level access tokens. Make sure to pass one of them to the WixAppOAuthStrategy');
185
+ throw new Error('Missing refresh token or instance ID. Either one is needed to get app level access tokens. Make sure to pass one of them to the AppOAuthStrategy');
186
186
  }
187
187
  },
188
188
  async decodeJWT(token, verifyCallerClaims = false) {
189
189
  if (!opts.publicKey) {
190
- throw new Error('Missing public key. Make sure to pass it to the WixAppOAuthStrategy');
190
+ throw new Error('Missing public key. Make sure to pass it to the AppOAuthStrategy');
191
191
  }
192
192
  const { jwtVerify, importSPKI } = await import('jose');
193
193
  const publicKey = await importSPKI(parsePublicKeyIfEncoded(opts.publicKey), 'RS256');
@@ -1,3 +1,4 @@
1
- import { EventDefinition, EventHandler } from '@wix/sdk-types';
1
+ import { BaseEventMetadata, EventDefinition, EventHandler } from '@wix/sdk-types';
2
2
  export declare const isEventHandlerModule: (val: any) => val is EventDefinition<unknown, string>;
3
- export declare function buildEventDefinition<T extends EventDefinition<any, string>>(eventDefinition: T, registerHandler: (eventType: string, handler: EventHandler<T>) => void): (handler: EventHandler<T>) => void;
3
+ export declare function buildEventDefinition<T extends EventDefinition<any, string>>(eventDefinition: T, registerHandler: (eventDefinition: T, handler: EventHandler<T>) => void): (handler: EventHandler<T>) => void;
4
+ export declare function runHandler<T extends EventDefinition>(eventDefinition: T, handler: EventHandler<T>, payload: unknown, baseEventMetadata: BaseEventMetadata): void | Promise<void>;
@@ -2,6 +2,38 @@ import { isObject } from './helpers.js';
2
2
  export const isEventHandlerModule = (val) => isObject(val) && val.__type === 'event-definition';
3
3
  export function buildEventDefinition(eventDefinition, registerHandler) {
4
4
  return (handler) => {
5
- registerHandler(eventDefinition.type, handler);
5
+ registerHandler(eventDefinition, handler);
6
6
  };
7
7
  }
8
+ export function runHandler(eventDefinition, handler, payload, baseEventMetadata) {
9
+ if (eventDefinition.isDomainEvent) {
10
+ const domainEventPayload = payload;
11
+ const { deletedEvent, actionEvent, createdEvent, updatedEvent, ...domainEventMetadata } = domainEventPayload;
12
+ const metadata = {
13
+ ...baseEventMetadata,
14
+ ...domainEventMetadata,
15
+ };
16
+ if (deletedEvent) {
17
+ return handler({ metadata });
18
+ }
19
+ else if (actionEvent) {
20
+ return handler({
21
+ data: domainEventPayload.actionEvent?.body,
22
+ metadata,
23
+ });
24
+ }
25
+ else {
26
+ return handler({
27
+ entity: domainEventPayload.createdEvent?.entity ??
28
+ domainEventPayload.updatedEvent?.currentEntity,
29
+ metadata,
30
+ });
31
+ }
32
+ }
33
+ else {
34
+ return handler({
35
+ data: payload,
36
+ metadata: baseEventMetadata,
37
+ });
38
+ }
39
+ }
package/build/index.d.ts CHANGED
@@ -3,7 +3,7 @@ export * from './wixMedia.js';
3
3
  export * from './auth/oauth2/OAuthStrategy.js';
4
4
  export * from './auth/oauth2/types.js';
5
5
  export * from './auth/ApiKeyAuthStrategy.js';
6
- export * from './auth/WixAppOAuthStrategy.js';
6
+ export * from './auth/AppOAuthStrategy.js';
7
7
  export * from '@wix/sdk-types';
8
8
  export { getDefaultDomain } from './rest-modules.js';
9
9
  export { API_URL } from './common.js';
package/build/index.js CHANGED
@@ -3,7 +3,7 @@ export * from './wixMedia.js';
3
3
  export * from './auth/oauth2/OAuthStrategy.js';
4
4
  export * from './auth/oauth2/types.js';
5
5
  export * from './auth/ApiKeyAuthStrategy.js';
6
- export * from './auth/WixAppOAuthStrategy.js';
6
+ export * from './auth/AppOAuthStrategy.js';
7
7
  export * from '@wix/sdk-types';
8
8
  export { getDefaultDomain } from './rest-modules.js';
9
9
  export { API_URL } from './common.js';
@@ -1,4 +1,4 @@
1
- import { AuthenticationStrategy, BoundAuthenticationStrategy, BuildEventDefinition, BuildRESTFunction, EventDefinition, Host, HostModule, HostModuleAPI, RESTFunctionDescriptor, SPIDefinition } from '@wix/sdk-types';
1
+ import { AuthenticationStrategy, BoundAuthenticationStrategy, BuildEventDefinition, BuildRESTFunction, EventDefinition, EventIdentity, Host, HostModule, HostModuleAPI, RESTFunctionDescriptor, SPIDefinition } 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';
@@ -97,6 +97,7 @@ type ResolvePossibleEvents<T extends EventDefinition<any>[]> = {
97
97
  } extends (infer U)[] ? U : never;
98
98
  export type ProcessedEvent<T extends EventDefinition<any>[] = []> = {
99
99
  instanceId: string;
100
+ identity?: EventIdentity;
100
101
  } & (T['length'] extends 0 ? {
101
102
  eventType: string;
102
103
  payload: unknown;
@@ -5,7 +5,7 @@ import { FetchErrorResponse } from './fetch-error.js';
5
5
  import { getDefaultContentHeader, isObject } from './helpers.js';
6
6
  import { buildHostModule, isHostModule } from './host-modules.js';
7
7
  import { buildRESTDescriptor } from './rest-modules.js';
8
- import { buildEventDefinition, isEventHandlerModule, } from './event-handlers-modules.js';
8
+ import { buildEventDefinition, isEventHandlerModule, runHandler, } from './event-handlers-modules.js';
9
9
  export function createClient(config) {
10
10
  const _headers = config.headers || { Authorization: '' };
11
11
  const eventHandlers = new Map();
@@ -33,10 +33,10 @@ export function createClient(config) {
33
33
  // excessively deep and possibly infinite.`
34
34
  const use = (modules, metadata) => {
35
35
  if (isEventHandlerModule(modules)) {
36
- return buildEventDefinition(modules, (eventType, handler) => {
37
- const handlers = eventHandlers.get(eventType) ?? [];
38
- handlers.push(handler);
39
- eventHandlers.set(eventType, handlers);
36
+ return buildEventDefinition(modules, (eventDefinition, handler) => {
37
+ const handlers = eventHandlers.get(eventDefinition.type) ?? [];
38
+ handlers.push({ eventDefinition, handler });
39
+ eventHandlers.set(eventDefinition.type, handlers);
40
40
  });
41
41
  }
42
42
  else if (isHostModule(modules) && config.host) {
@@ -132,6 +132,9 @@ export function createClient(config) {
132
132
  const parsedDecoded = JSON.parse(decoded.data);
133
133
  const eventType = parsedDecoded.eventType;
134
134
  const instanceId = parsedDecoded.instanceId;
135
+ const identity = parsedDecoded.identity
136
+ ? JSON.parse(parsedDecoded.identity)
137
+ : undefined;
135
138
  const payload = JSON.parse(parsedDecoded.data);
136
139
  const allExpectedEvents = [
137
140
  ...opts.expectedEvents,
@@ -144,13 +147,15 @@ export function createClient(config) {
144
147
  .join(', ')}`);
145
148
  }
146
149
  const handlers = eventHandlers.get(eventType) ?? [];
147
- await Promise.all(handlers.map((handler) => handler(payload, {
150
+ await Promise.all(handlers.map(({ eventDefinition, handler }) => runHandler(eventDefinition, handler, payload, {
148
151
  instanceId,
152
+ identity,
149
153
  })));
150
154
  return {
151
155
  instanceId,
152
156
  eventType,
153
157
  payload,
158
+ identity,
154
159
  };
155
160
  },
156
161
  async processRequest(request, opts) {
@@ -1,11 +1,11 @@
1
1
  import { AuthenticationStrategy } from '@wix/sdk-types';
2
- export type WixAppOAuthStrategy = AuthenticationStrategy<undefined, (opts: {
2
+ export type AppOAuthStrategy = AuthenticationStrategy<undefined, (opts: {
3
3
  instanceId: string;
4
4
  } | {
5
5
  refreshToken: string;
6
6
  } | {
7
7
  fromRequest: Request;
8
- }) => WixAppOAuthStrategy> & {
8
+ }) => AppOAuthStrategy> & {
9
9
  getInstallUrl(opts: {
10
10
  redirectUrl: string;
11
11
  state?: string;
@@ -31,11 +31,11 @@ export type WixAppOAuthStrategy = AuthenticationStrategy<undefined, (opts: {
31
31
  * @returns An authentication strategy that can be used with WixClient
32
32
  * @example
33
33
  * ```ts
34
- * import { WixAppOAuthStrategy, createClient } from '@wix/sdk';
34
+ * import { AppOAuthStrategy, createClient } from '@wix/sdk';
35
35
  * import { products } from '@wix/stores';
36
36
  *
37
37
  * const client = createClient({
38
- * auth: WixAppOAuthStrategy({
38
+ * auth: AppOAuthStrategy({
39
39
  * appId: 'appId',
40
40
  * appSecret: 'appSecret',
41
41
  * }),
@@ -57,7 +57,7 @@ export type WixAppOAuthStrategy = AuthenticationStrategy<undefined, (opts: {
57
57
  *
58
58
  * ```
59
59
  */
60
- export declare function WixAppOAuthStrategy(opts: {
60
+ export declare function AppOAuthStrategy(opts: {
61
61
  appId: string;
62
62
  appSecret?: string;
63
63
  publicKey?: string;
@@ -67,4 +67,4 @@ export declare function WixAppOAuthStrategy(opts: {
67
67
  instanceId?: string;
68
68
  } | {
69
69
  accessToken?: string;
70
- })): WixAppOAuthStrategy;
70
+ })): AppOAuthStrategy;
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.WixAppOAuthStrategy = void 0;
26
+ exports.AppOAuthStrategy = void 0;
27
27
  const helpers_js_1 = require("../helpers.js");
28
28
  /**
29
29
  * Creates an authentication strategy for Wix Apps OAuth installation process.
@@ -37,11 +37,11 @@ const helpers_js_1 = require("../helpers.js");
37
37
  * @returns An authentication strategy that can be used with WixClient
38
38
  * @example
39
39
  * ```ts
40
- * import { WixAppOAuthStrategy, createClient } from '@wix/sdk';
40
+ * import { AppOAuthStrategy, createClient } from '@wix/sdk';
41
41
  * import { products } from '@wix/stores';
42
42
  *
43
43
  * const client = createClient({
44
- * auth: WixAppOAuthStrategy({
44
+ * auth: AppOAuthStrategy({
45
45
  * appId: 'appId',
46
46
  * appSecret: 'appSecret',
47
47
  * }),
@@ -64,7 +64,7 @@ const helpers_js_1 = require("../helpers.js");
64
64
  * ```
65
65
  */
66
66
  // eslint-disable-next-line @typescript-eslint/no-redeclare
67
- function WixAppOAuthStrategy(opts) {
67
+ function AppOAuthStrategy(opts) {
68
68
  let refreshToken = 'refreshToken' in opts ? opts.refreshToken : undefined;
69
69
  return {
70
70
  getInstallUrl({ redirectUrl, token, state }) {
@@ -81,7 +81,7 @@ function WixAppOAuthStrategy(opts) {
81
81
  },
82
82
  withAuth(params) {
83
83
  if ('instanceId' in params) {
84
- return WixAppOAuthStrategy({
84
+ return AppOAuthStrategy({
85
85
  appId: opts.appId,
86
86
  appSecret: opts.appSecret,
87
87
  publicKey: opts.publicKey,
@@ -89,7 +89,7 @@ function WixAppOAuthStrategy(opts) {
89
89
  });
90
90
  }
91
91
  else if ('refreshToken' in params) {
92
- return WixAppOAuthStrategy({
92
+ return AppOAuthStrategy({
93
93
  appId: opts.appId,
94
94
  appSecret: opts.appSecret,
95
95
  publicKey: opts.publicKey,
@@ -101,7 +101,7 @@ function WixAppOAuthStrategy(opts) {
101
101
  if (!authFromRequest) {
102
102
  throw new Error('Missing Authorization header in the request');
103
103
  }
104
- return WixAppOAuthStrategy({
104
+ return AppOAuthStrategy({
105
105
  appId: opts.appId,
106
106
  appSecret: opts.appSecret,
107
107
  publicKey: opts.publicKey,
@@ -114,7 +114,7 @@ function WixAppOAuthStrategy(opts) {
114
114
  },
115
115
  async handleOAuthCallback(url, oauthOpts) {
116
116
  if (!opts.appSecret) {
117
- throw new Error('App secret is required for handling OAuth callback. Make sure to pass it to the WixAppOAuthStrategy');
117
+ throw new Error('App secret is required for handling OAuth callback. Make sure to pass it to the AppOAuthStrategy');
118
118
  }
119
119
  const params = new URLSearchParams(new URL(url).search);
120
120
  const state = params.get('state');
@@ -151,7 +151,7 @@ function WixAppOAuthStrategy(opts) {
151
151
  },
152
152
  async getAuthHeaders() {
153
153
  if (!opts.appSecret) {
154
- throw new Error('App secret is required for retrieveing app-level access tokens. Make sure to pass it to the WixAppOAuthStrategy');
154
+ throw new Error('App secret is required for retrieveing app-level access tokens. Make sure to pass it to the AppOAuthStrategy');
155
155
  }
156
156
  if ('refreshToken' in opts || refreshToken) {
157
157
  const tokensRes = await fetch('https://www.wixapis.com/oauth/access', {
@@ -208,12 +208,12 @@ function WixAppOAuthStrategy(opts) {
208
208
  };
209
209
  }
210
210
  else {
211
- throw new Error('Missing refresh token or instance ID. Either one is needed to get app level access tokens. Make sure to pass one of them to the WixAppOAuthStrategy');
211
+ throw new Error('Missing refresh token or instance ID. Either one is needed to get app level access tokens. Make sure to pass one of them to the AppOAuthStrategy');
212
212
  }
213
213
  },
214
214
  async decodeJWT(token, verifyCallerClaims = false) {
215
215
  if (!opts.publicKey) {
216
- throw new Error('Missing public key. Make sure to pass it to the WixAppOAuthStrategy');
216
+ throw new Error('Missing public key. Make sure to pass it to the AppOAuthStrategy');
217
217
  }
218
218
  const { jwtVerify, importSPKI } = await Promise.resolve().then(() => __importStar(require('jose')));
219
219
  const publicKey = await importSPKI((0, helpers_js_1.parsePublicKeyIfEncoded)(opts.publicKey), 'RS256');
@@ -232,4 +232,4 @@ function WixAppOAuthStrategy(opts) {
232
232
  },
233
233
  };
234
234
  }
235
- exports.WixAppOAuthStrategy = WixAppOAuthStrategy;
235
+ exports.AppOAuthStrategy = AppOAuthStrategy;
@@ -1,3 +1,4 @@
1
- import { EventDefinition, EventHandler } from '@wix/sdk-types';
1
+ import { BaseEventMetadata, EventDefinition, EventHandler } from '@wix/sdk-types';
2
2
  export declare const isEventHandlerModule: (val: any) => val is EventDefinition<unknown, string>;
3
- export declare function buildEventDefinition<T extends EventDefinition<any, string>>(eventDefinition: T, registerHandler: (eventType: string, handler: EventHandler<T>) => void): (handler: EventHandler<T>) => void;
3
+ export declare function buildEventDefinition<T extends EventDefinition<any, string>>(eventDefinition: T, registerHandler: (eventDefinition: T, handler: EventHandler<T>) => void): (handler: EventHandler<T>) => void;
4
+ export declare function runHandler<T extends EventDefinition>(eventDefinition: T, handler: EventHandler<T>, payload: unknown, baseEventMetadata: BaseEventMetadata): void | Promise<void>;
@@ -1,12 +1,45 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildEventDefinition = exports.isEventHandlerModule = void 0;
3
+ exports.runHandler = exports.buildEventDefinition = exports.isEventHandlerModule = void 0;
4
4
  const helpers_js_1 = require("./helpers.js");
5
5
  const isEventHandlerModule = (val) => (0, helpers_js_1.isObject)(val) && val.__type === 'event-definition';
6
6
  exports.isEventHandlerModule = isEventHandlerModule;
7
7
  function buildEventDefinition(eventDefinition, registerHandler) {
8
8
  return (handler) => {
9
- registerHandler(eventDefinition.type, handler);
9
+ registerHandler(eventDefinition, handler);
10
10
  };
11
11
  }
12
12
  exports.buildEventDefinition = buildEventDefinition;
13
+ function runHandler(eventDefinition, handler, payload, baseEventMetadata) {
14
+ if (eventDefinition.isDomainEvent) {
15
+ const domainEventPayload = payload;
16
+ const { deletedEvent, actionEvent, createdEvent, updatedEvent, ...domainEventMetadata } = domainEventPayload;
17
+ const metadata = {
18
+ ...baseEventMetadata,
19
+ ...domainEventMetadata,
20
+ };
21
+ if (deletedEvent) {
22
+ return handler({ metadata });
23
+ }
24
+ else if (actionEvent) {
25
+ return handler({
26
+ data: domainEventPayload.actionEvent?.body,
27
+ metadata,
28
+ });
29
+ }
30
+ else {
31
+ return handler({
32
+ entity: domainEventPayload.createdEvent?.entity ??
33
+ domainEventPayload.updatedEvent?.currentEntity,
34
+ metadata,
35
+ });
36
+ }
37
+ }
38
+ else {
39
+ return handler({
40
+ data: payload,
41
+ metadata: baseEventMetadata,
42
+ });
43
+ }
44
+ }
45
+ exports.runHandler = runHandler;
@@ -3,7 +3,7 @@ export * from './wixMedia.js';
3
3
  export * from './auth/oauth2/OAuthStrategy.js';
4
4
  export * from './auth/oauth2/types.js';
5
5
  export * from './auth/ApiKeyAuthStrategy.js';
6
- export * from './auth/WixAppOAuthStrategy.js';
6
+ export * from './auth/AppOAuthStrategy.js';
7
7
  export * from '@wix/sdk-types';
8
8
  export { getDefaultDomain } from './rest-modules.js';
9
9
  export { API_URL } from './common.js';
@@ -20,7 +20,7 @@ __exportStar(require("./wixMedia.js"), exports);
20
20
  __exportStar(require("./auth/oauth2/OAuthStrategy.js"), exports);
21
21
  __exportStar(require("./auth/oauth2/types.js"), exports);
22
22
  __exportStar(require("./auth/ApiKeyAuthStrategy.js"), exports);
23
- __exportStar(require("./auth/WixAppOAuthStrategy.js"), exports);
23
+ __exportStar(require("./auth/AppOAuthStrategy.js"), exports);
24
24
  __exportStar(require("@wix/sdk-types"), exports);
25
25
  var rest_modules_js_1 = require("./rest-modules.js");
26
26
  Object.defineProperty(exports, "getDefaultDomain", { enumerable: true, get: function () { return rest_modules_js_1.getDefaultDomain; } });
@@ -1,4 +1,4 @@
1
- import { AuthenticationStrategy, BoundAuthenticationStrategy, BuildEventDefinition, BuildRESTFunction, EventDefinition, Host, HostModule, HostModuleAPI, RESTFunctionDescriptor, SPIDefinition } from '@wix/sdk-types';
1
+ import { AuthenticationStrategy, BoundAuthenticationStrategy, BuildEventDefinition, BuildRESTFunction, EventDefinition, EventIdentity, Host, HostModule, HostModuleAPI, RESTFunctionDescriptor, SPIDefinition } 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';
@@ -97,6 +97,7 @@ type ResolvePossibleEvents<T extends EventDefinition<any>[]> = {
97
97
  } extends (infer U)[] ? U : never;
98
98
  export type ProcessedEvent<T extends EventDefinition<any>[] = []> = {
99
99
  instanceId: string;
100
+ identity?: EventIdentity;
100
101
  } & (T['length'] extends 0 ? {
101
102
  eventType: string;
102
103
  payload: unknown;
@@ -36,10 +36,10 @@ function createClient(config) {
36
36
  // excessively deep and possibly infinite.`
37
37
  const use = (modules, metadata) => {
38
38
  if ((0, event_handlers_modules_js_1.isEventHandlerModule)(modules)) {
39
- return (0, event_handlers_modules_js_1.buildEventDefinition)(modules, (eventType, handler) => {
40
- const handlers = eventHandlers.get(eventType) ?? [];
41
- handlers.push(handler);
42
- eventHandlers.set(eventType, handlers);
39
+ return (0, event_handlers_modules_js_1.buildEventDefinition)(modules, (eventDefinition, handler) => {
40
+ const handlers = eventHandlers.get(eventDefinition.type) ?? [];
41
+ handlers.push({ eventDefinition, handler });
42
+ eventHandlers.set(eventDefinition.type, handlers);
43
43
  });
44
44
  }
45
45
  else if ((0, host_modules_js_1.isHostModule)(modules) && config.host) {
@@ -135,6 +135,9 @@ function createClient(config) {
135
135
  const parsedDecoded = JSON.parse(decoded.data);
136
136
  const eventType = parsedDecoded.eventType;
137
137
  const instanceId = parsedDecoded.instanceId;
138
+ const identity = parsedDecoded.identity
139
+ ? JSON.parse(parsedDecoded.identity)
140
+ : undefined;
138
141
  const payload = JSON.parse(parsedDecoded.data);
139
142
  const allExpectedEvents = [
140
143
  ...opts.expectedEvents,
@@ -147,13 +150,15 @@ function createClient(config) {
147
150
  .join(', ')}`);
148
151
  }
149
152
  const handlers = eventHandlers.get(eventType) ?? [];
150
- await Promise.all(handlers.map((handler) => handler(payload, {
153
+ await Promise.all(handlers.map(({ eventDefinition, handler }) => (0, event_handlers_modules_js_1.runHandler)(eventDefinition, handler, payload, {
151
154
  instanceId,
155
+ identity,
152
156
  })));
153
157
  return {
154
158
  instanceId,
155
159
  eventType,
156
160
  payload,
161
+ identity,
157
162
  };
158
163
  },
159
164
  async processRequest(request, opts) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/sdk",
3
- "version": "1.8.1",
3
+ "version": "1.9.1",
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.64.0",
69
69
  "@wix/redirects": "^1.0.41",
70
- "@wix/sdk-types": "^1.6.0",
70
+ "@wix/sdk-types": "^1.6.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": "04edfaa4fa2a2ad6bdacb87fadaae88194bc9c204ed4e7ea1cf9296e"
123
+ "falconPackageHash": "219609c03177070f1295b18ec0ca671a82f02205060dbcd7b9f45e2a"
124
124
  }