@wix/sdk 1.9.0 → 1.9.2

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 AppOAuthStrategy = AuthenticationStrategy<undefined, (opts: {
2
+ export type AppStrategy = AuthenticationStrategy<undefined, (opts: {
3
3
  instanceId: string;
4
4
  } | {
5
5
  refreshToken: string;
6
6
  } | {
7
7
  fromRequest: Request;
8
- }) => AppOAuthStrategy> & {
8
+ }) => AppStrategy> & {
9
9
  getInstallUrl(opts: {
10
10
  redirectUrl: string;
11
11
  state?: string;
@@ -31,11 +31,11 @@ export type AppOAuthStrategy = AuthenticationStrategy<undefined, (opts: {
31
31
  * @returns An authentication strategy that can be used with WixClient
32
32
  * @example
33
33
  * ```ts
34
- * import { AppOAuthStrategy, createClient } from '@wix/sdk';
34
+ * import { AppStrategy, createClient } from '@wix/sdk';
35
35
  * import { products } from '@wix/stores';
36
36
  *
37
37
  * const client = createClient({
38
- * auth: AppOAuthStrategy({
38
+ * auth: AppStrategy({
39
39
  * appId: 'appId',
40
40
  * appSecret: 'appSecret',
41
41
  * }),
@@ -57,7 +57,7 @@ export type AppOAuthStrategy = AuthenticationStrategy<undefined, (opts: {
57
57
  *
58
58
  * ```
59
59
  */
60
- export declare function AppOAuthStrategy(opts: {
60
+ export declare function AppStrategy(opts: {
61
61
  appId: string;
62
62
  appSecret?: string;
63
63
  publicKey?: string;
@@ -67,4 +67,4 @@ export declare function AppOAuthStrategy(opts: {
67
67
  instanceId?: string;
68
68
  } | {
69
69
  accessToken?: string;
70
- })): AppOAuthStrategy;
70
+ })): AppStrategy;
@@ -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 { AppOAuthStrategy, createClient } from '@wix/sdk';
14
+ * import { AppStrategy, createClient } from '@wix/sdk';
15
15
  * import { products } from '@wix/stores';
16
16
  *
17
17
  * const client = createClient({
18
- * auth: AppOAuthStrategy({
18
+ * auth: AppStrategy({
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 AppOAuthStrategy(opts) {
41
+ export function AppStrategy(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 AppOAuthStrategy(opts) {
55
55
  },
56
56
  withAuth(params) {
57
57
  if ('instanceId' in params) {
58
- return AppOAuthStrategy({
58
+ return AppStrategy({
59
59
  appId: opts.appId,
60
60
  appSecret: opts.appSecret,
61
61
  publicKey: opts.publicKey,
@@ -63,7 +63,7 @@ export function AppOAuthStrategy(opts) {
63
63
  });
64
64
  }
65
65
  else if ('refreshToken' in params) {
66
- return AppOAuthStrategy({
66
+ return AppStrategy({
67
67
  appId: opts.appId,
68
68
  appSecret: opts.appSecret,
69
69
  publicKey: opts.publicKey,
@@ -75,7 +75,7 @@ export function AppOAuthStrategy(opts) {
75
75
  if (!authFromRequest) {
76
76
  throw new Error('Missing Authorization header in the request');
77
77
  }
78
- return AppOAuthStrategy({
78
+ return AppStrategy({
79
79
  appId: opts.appId,
80
80
  appSecret: opts.appSecret,
81
81
  publicKey: opts.publicKey,
@@ -88,7 +88,7 @@ export function AppOAuthStrategy(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 AppOAuthStrategy');
91
+ throw new Error('App secret is required for handling OAuth callback. Make sure to pass it to the AppStrategy');
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 AppOAuthStrategy(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 AppOAuthStrategy');
128
+ throw new Error('App secret is required for retrieveing app-level access tokens. Make sure to pass it to the AppStrategy');
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 AppOAuthStrategy(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 AppOAuthStrategy');
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 AppStrategy');
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 AppOAuthStrategy');
190
+ throw new Error('Missing public key. Make sure to pass it to the AppStrategy');
191
191
  }
192
192
  const { jwtVerify, importSPKI } = await import('jose');
193
193
  const publicKey = await importSPKI(parsePublicKeyIfEncoded(opts.publicKey), 'RS256');
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/AppOAuthStrategy.js';
6
+ export * from './auth/AppStrategy.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/AppOAuthStrategy.js';
6
+ export * from './auth/AppStrategy.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,7 +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: unknown;
100
+ identity?: EventIdentity;
101
101
  } & (T['length'] extends 0 ? {
102
102
  eventType: string;
103
103
  payload: unknown;
@@ -132,7 +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 = JSON.parse(parsedDecoded.identity);
135
+ const identity = parsedDecoded.identity
136
+ ? JSON.parse(parsedDecoded.identity)
137
+ : undefined;
136
138
  const payload = JSON.parse(parsedDecoded.data);
137
139
  const allExpectedEvents = [
138
140
  ...opts.expectedEvents,
@@ -1,11 +1,11 @@
1
1
  import { AuthenticationStrategy } from '@wix/sdk-types';
2
- export type AppOAuthStrategy = AuthenticationStrategy<undefined, (opts: {
2
+ export type AppStrategy = AuthenticationStrategy<undefined, (opts: {
3
3
  instanceId: string;
4
4
  } | {
5
5
  refreshToken: string;
6
6
  } | {
7
7
  fromRequest: Request;
8
- }) => AppOAuthStrategy> & {
8
+ }) => AppStrategy> & {
9
9
  getInstallUrl(opts: {
10
10
  redirectUrl: string;
11
11
  state?: string;
@@ -31,11 +31,11 @@ export type AppOAuthStrategy = AuthenticationStrategy<undefined, (opts: {
31
31
  * @returns An authentication strategy that can be used with WixClient
32
32
  * @example
33
33
  * ```ts
34
- * import { AppOAuthStrategy, createClient } from '@wix/sdk';
34
+ * import { AppStrategy, createClient } from '@wix/sdk';
35
35
  * import { products } from '@wix/stores';
36
36
  *
37
37
  * const client = createClient({
38
- * auth: AppOAuthStrategy({
38
+ * auth: AppStrategy({
39
39
  * appId: 'appId',
40
40
  * appSecret: 'appSecret',
41
41
  * }),
@@ -57,7 +57,7 @@ export type AppOAuthStrategy = AuthenticationStrategy<undefined, (opts: {
57
57
  *
58
58
  * ```
59
59
  */
60
- export declare function AppOAuthStrategy(opts: {
60
+ export declare function AppStrategy(opts: {
61
61
  appId: string;
62
62
  appSecret?: string;
63
63
  publicKey?: string;
@@ -67,4 +67,4 @@ export declare function AppOAuthStrategy(opts: {
67
67
  instanceId?: string;
68
68
  } | {
69
69
  accessToken?: string;
70
- })): AppOAuthStrategy;
70
+ })): AppStrategy;
@@ -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.AppOAuthStrategy = void 0;
26
+ exports.AppStrategy = 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 { AppOAuthStrategy, createClient } from '@wix/sdk';
40
+ * import { AppStrategy, createClient } from '@wix/sdk';
41
41
  * import { products } from '@wix/stores';
42
42
  *
43
43
  * const client = createClient({
44
- * auth: AppOAuthStrategy({
44
+ * auth: AppStrategy({
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 AppOAuthStrategy(opts) {
67
+ function AppStrategy(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 AppOAuthStrategy(opts) {
81
81
  },
82
82
  withAuth(params) {
83
83
  if ('instanceId' in params) {
84
- return AppOAuthStrategy({
84
+ return AppStrategy({
85
85
  appId: opts.appId,
86
86
  appSecret: opts.appSecret,
87
87
  publicKey: opts.publicKey,
@@ -89,7 +89,7 @@ function AppOAuthStrategy(opts) {
89
89
  });
90
90
  }
91
91
  else if ('refreshToken' in params) {
92
- return AppOAuthStrategy({
92
+ return AppStrategy({
93
93
  appId: opts.appId,
94
94
  appSecret: opts.appSecret,
95
95
  publicKey: opts.publicKey,
@@ -101,7 +101,7 @@ function AppOAuthStrategy(opts) {
101
101
  if (!authFromRequest) {
102
102
  throw new Error('Missing Authorization header in the request');
103
103
  }
104
- return AppOAuthStrategy({
104
+ return AppStrategy({
105
105
  appId: opts.appId,
106
106
  appSecret: opts.appSecret,
107
107
  publicKey: opts.publicKey,
@@ -114,7 +114,7 @@ function AppOAuthStrategy(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 AppOAuthStrategy');
117
+ throw new Error('App secret is required for handling OAuth callback. Make sure to pass it to the AppStrategy');
118
118
  }
119
119
  const params = new URLSearchParams(new URL(url).search);
120
120
  const state = params.get('state');
@@ -151,7 +151,7 @@ function AppOAuthStrategy(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 AppOAuthStrategy');
154
+ throw new Error('App secret is required for retrieveing app-level access tokens. Make sure to pass it to the AppStrategy');
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 AppOAuthStrategy(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 AppOAuthStrategy');
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 AppStrategy');
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 AppOAuthStrategy');
216
+ throw new Error('Missing public key. Make sure to pass it to the AppStrategy');
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 AppOAuthStrategy(opts) {
232
232
  },
233
233
  };
234
234
  }
235
- exports.AppOAuthStrategy = AppOAuthStrategy;
235
+ exports.AppStrategy = AppStrategy;
@@ -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/AppOAuthStrategy.js';
6
+ export * from './auth/AppStrategy.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/AppOAuthStrategy.js"), exports);
23
+ __exportStar(require("./auth/AppStrategy.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,7 +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: unknown;
100
+ identity?: EventIdentity;
101
101
  } & (T['length'] extends 0 ? {
102
102
  eventType: string;
103
103
  payload: unknown;
@@ -135,7 +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 = JSON.parse(parsedDecoded.identity);
138
+ const identity = parsedDecoded.identity
139
+ ? JSON.parse(parsedDecoded.identity)
140
+ : undefined;
139
141
  const payload = JSON.parse(parsedDecoded.data);
140
142
  const allExpectedEvents = [
141
143
  ...opts.expectedEvents,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/sdk",
3
- "version": "1.9.0",
3
+ "version": "1.9.2",
4
4
  "license": "UNLICENSED",
5
5
  "author": {
6
6
  "name": "Ronny Ringel",
@@ -32,8 +32,8 @@
32
32
  "require": "./cjs/build/auth/ApiKeyAuthStrategy.js"
33
33
  },
34
34
  "./auth/wix-app-oauth": {
35
- "import": "./build/auth/WixAppOAuthStrategy.js",
36
- "require": "./cjs/build/auth/WixAppOAuthStrategy.js"
35
+ "import": "./build/auth/AppStrategy.js",
36
+ "require": "./cjs/build/auth/AppStrategy.js"
37
37
  },
38
38
  "./auth/velo": {
39
39
  "import": "./build/auth/VeloAuthStrategy.js",
@@ -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.64.0",
68
+ "@wix/image-kit": "^1.67.0",
69
69
  "@wix/redirects": "^1.0.41",
70
- "@wix/sdk-types": "^1.6.2",
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": "2a4c4555b4f48dd32d60e61c677f384a5ffe2bd3389542b08ab26273"
123
+ "falconPackageHash": "71774a6a839caae0eb644c899a798b3b14296d9c6321d8fae8dfeca5"
124
124
  }