@wix/sdk 1.9.1 → 1.9.3

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';
@@ -11,19 +11,12 @@ type Headers = Record<string, string>;
11
11
  * Any non-descriptor properties are removed from the returned object, including descriptors that
12
12
  * do not match the given host (as they will not work with the given host).
13
13
  */
14
- export type BuildDescriptors<T extends Descriptors, H extends Host<any> | undefined> = BuildRESTDescriptors<T> & BuildAmbassadorDescriptors<T> & BuildEventDefinitions<T> & (H extends Host<any> ? BuildHostDescriptors<T> : {});
15
- type BuildRESTDescriptors<T extends Descriptors> = T extends RESTFunctionDescriptor ? BuildRESTFunction<T> : ConditionalExcept<{
16
- [Key in keyof T]: T[Key] extends Descriptors ? BuildRESTDescriptors<T[Key]> : never;
17
- }, EmptyObject>;
18
- type BuildAmbassadorDescriptors<T extends Descriptors> = T extends AmbassadorFunctionDescriptor ? BuildAmbassadorFunction<T> : ConditionalExcept<{
19
- [Key in keyof T]: T[Key] extends Descriptors ? BuildAmbassadorDescriptors<T[Key]> : never;
20
- }, EmptyObject>;
21
- type BuildHostDescriptors<T extends Descriptors> = T extends HostModule<any, any> ? HostModuleAPI<T> : ConditionalExcept<{
22
- [Key in keyof T]: T[Key] extends Descriptors ? BuildHostDescriptors<T[Key]> : never;
23
- }, EmptyObject>;
24
- type BuildEventDefinitions<T extends Descriptors> = T extends EventDefinition ? BuildEventDefinition<T> : ConditionalExcept<{
25
- [Key in keyof T]: T[Key] extends Descriptors ? BuildEventDefinitions<T[Key]> : never;
26
- }, EmptyObject>;
14
+ export type BuildDescriptors<T extends Descriptors, H extends Host<any> | undefined, Depth extends number = 5> = {
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<{
17
+ [Key in keyof T]: T[Key] extends Descriptors ? BuildDescriptors<T[Key], H, [-1, 0, 1, 2, 3, 4, 5][Depth]> : never;
18
+ }, EmptyObject>;
19
+ }[Depth extends -1 ? 'done' : 'recurse'];
27
20
  /**
28
21
  * Descriptors are objects that describe the API of a module, and the module
29
22
  * can either be a REST module or a host module.
@@ -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; } });
@@ -11,19 +11,12 @@ type Headers = Record<string, string>;
11
11
  * Any non-descriptor properties are removed from the returned object, including descriptors that
12
12
  * do not match the given host (as they will not work with the given host).
13
13
  */
14
- export type BuildDescriptors<T extends Descriptors, H extends Host<any> | undefined> = BuildRESTDescriptors<T> & BuildAmbassadorDescriptors<T> & BuildEventDefinitions<T> & (H extends Host<any> ? BuildHostDescriptors<T> : {});
15
- type BuildRESTDescriptors<T extends Descriptors> = T extends RESTFunctionDescriptor ? BuildRESTFunction<T> : ConditionalExcept<{
16
- [Key in keyof T]: T[Key] extends Descriptors ? BuildRESTDescriptors<T[Key]> : never;
17
- }, EmptyObject>;
18
- type BuildAmbassadorDescriptors<T extends Descriptors> = T extends AmbassadorFunctionDescriptor ? BuildAmbassadorFunction<T> : ConditionalExcept<{
19
- [Key in keyof T]: T[Key] extends Descriptors ? BuildAmbassadorDescriptors<T[Key]> : never;
20
- }, EmptyObject>;
21
- type BuildHostDescriptors<T extends Descriptors> = T extends HostModule<any, any> ? HostModuleAPI<T> : ConditionalExcept<{
22
- [Key in keyof T]: T[Key] extends Descriptors ? BuildHostDescriptors<T[Key]> : never;
23
- }, EmptyObject>;
24
- type BuildEventDefinitions<T extends Descriptors> = T extends EventDefinition ? BuildEventDefinition<T> : ConditionalExcept<{
25
- [Key in keyof T]: T[Key] extends Descriptors ? BuildEventDefinitions<T[Key]> : never;
26
- }, EmptyObject>;
14
+ export type BuildDescriptors<T extends Descriptors, H extends Host<any> | undefined, Depth extends number = 5> = {
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<{
17
+ [Key in keyof T]: T[Key] extends Descriptors ? BuildDescriptors<T[Key], H, [-1, 0, 1, 2, 3, 4, 5][Depth]> : never;
18
+ }, EmptyObject>;
19
+ }[Depth extends -1 ? 'done' : 'recurse'];
27
20
  /**
28
21
  * Descriptors are objects that describe the API of a module, and the module
29
22
  * can either be a REST module or a host module.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/sdk",
3
- "version": "1.9.1",
3
+ "version": "1.9.3",
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,7 +65,7 @@
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
70
  "@wix/sdk-types": "^1.6.3",
71
71
  "crypto-js": "^4.2.0",
@@ -120,5 +120,5 @@
120
120
  "wallaby": {
121
121
  "autoDetect": true
122
122
  },
123
- "falconPackageHash": "219609c03177070f1295b18ec0ca671a82f02205060dbcd7b9f45e2a"
123
+ "falconPackageHash": "b793f7d8e56d121118c1a7a6f27eb8df6d14f23cdc6399d6352dd96f"
124
124
  }