@wix/sdk 1.7.3 → 1.7.5

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,4 +1,4 @@
1
- import { verify } from 'jsonwebtoken';
1
+ import { jwtVerify, importSPKI } from 'jose';
2
2
  import { parsePublicKeyIfEncoded } from '../helpers.js';
3
3
  /**
4
4
  * Creates an authentication strategy for Wix Apps OAuth installation process.
@@ -120,19 +120,21 @@ export function WixAppOAuthStrategy(opts) {
120
120
  },
121
121
  };
122
122
  },
123
- decodeJWT(token, verifyCallerClaims = false) {
123
+ async decodeJWT(token, verifyCallerClaims = false) {
124
124
  if (!opts.publicKey) {
125
125
  throw new Error('Missing public key. Make sure to pass it to the WixAppOAuthStrategy');
126
126
  }
127
- const publicKey = parsePublicKeyIfEncoded(opts.publicKey);
128
- const decoded = verify(token, publicKey, verifyCallerClaims
127
+ const publicKey = await importSPKI(parsePublicKeyIfEncoded(opts.publicKey), 'RS256');
128
+ const decoded = await jwtVerify(token, publicKey, verifyCallerClaims
129
129
  ? {
130
130
  issuer: 'wix.com',
131
131
  audience: opts.appId,
132
132
  }
133
133
  : undefined);
134
134
  return {
135
- decoded,
135
+ decoded: {
136
+ data: decoded.payload.data,
137
+ },
136
138
  valid: true,
137
139
  };
138
140
  },
@@ -118,7 +118,7 @@ export function OAuthStrategy(config) {
118
118
  const getAuthUrl = async (oauthData, opts = {
119
119
  prompt: 'login',
120
120
  }) => {
121
- return getAuthorizationUrlWithOptions(oauthData, opts.responseMode ?? 'fragment', opts.prompt ?? 'login');
121
+ return getAuthorizationUrlWithOptions(oauthData, opts.responseMode ?? 'fragment', opts.prompt ?? 'login', opts.sessionToken);
122
122
  };
123
123
  const parseFromUrl = (url, responseMode = 'fragment') => {
124
124
  const parsedUrl = new URL(url ?? window.location.href);
@@ -1,4 +1,4 @@
1
- import { AuthenticationStrategy, BoundAuthenticationStrategy, BuildRESTFunction, Host, HostModule, HostModuleAPI, RESTFunctionDescriptor, EventDefinition, SPIDefinition } from '@wix/sdk-types';
1
+ import { AuthenticationStrategy, BoundAuthenticationStrategy, BuildRESTFunction, Host, HostModule, HostModuleAPI, RESTFunctionDescriptor, SPIDefinition, EventDefinition } from '@wix/sdk-types';
2
2
  import { ConditionalExcept, EmptyObject } from 'type-fest';
3
3
  import { AmbassadorFunctionDescriptor, BuildAmbassadorFunction } from './ambassador-modules.js';
4
4
  import { PublicMetadata } from './common.js';
@@ -63,7 +63,7 @@ export type WixClient<H extends Host<any> | undefined = undefined, Z extends Aut
63
63
  webhooks: {
64
64
  process<ExpectedEvents extends EventDefinition<any>[] = []>(jwt: string, opts?: {
65
65
  expectedEvents: ExpectedEvents;
66
- }): ProcessedEvent<ExpectedEvents>;
66
+ }): Promise<ProcessedEvent<ExpectedEvents>>;
67
67
  processRequest<ExpectedEvents extends EventDefinition<any>[] = []>(request: Request, opts?: {
68
68
  expectedEvents: ExpectedEvents;
69
69
  }): Promise<ProcessedEvent<ExpectedEvents>>;
@@ -71,14 +71,14 @@ export type WixClient<H extends Host<any> | undefined = undefined, Z extends Aut
71
71
  AppInstalled: EventDefinition<{
72
72
  appId: string;
73
73
  originInstanceId: string;
74
- }>;
74
+ }, 'AppInstalled'>;
75
75
  AppRemoved: EventDefinition<{
76
76
  appId: string;
77
- }>;
77
+ }, 'AppRemoved'>;
78
78
  };
79
79
  };
80
80
  spi: <S extends SPIDefinition<any, any>>() => {
81
- process(jwt: string): S['__input'];
81
+ process(jwt: string): Promise<S['__input']>;
82
82
  processRequest(request: Request): Promise<S['__input']>;
83
83
  result(result: S['__result']): S['__result'];
84
84
  };
@@ -1,3 +1,4 @@
1
+ import { EventDefinition, } from '@wix/sdk-types';
1
2
  import { toHTTPModule, isAmbassadorModule, ambassadorModuleOptions, } from './ambassador-modules.js';
2
3
  import { API_URL, PUBLIC_METADATA_KEY } from './common.js';
3
4
  import { getDefaultContentHeader, isObject } from './helpers.js';
@@ -86,13 +87,13 @@ export function createClient(config) {
86
87
  return { data: data ?? {}, errors };
87
88
  },
88
89
  webhooks: {
89
- process: (jwt, opts = {
90
+ process: async (jwt, opts = {
90
91
  expectedEvents: [],
91
92
  }) => {
92
93
  if (!authStrategy.decodeJWT) {
93
94
  throw new Error('decodeJWT is not supported by the authentication strategy');
94
95
  }
95
- const { decoded, valid } = authStrategy.decodeJWT(jwt);
96
+ const { decoded, valid } = await authStrategy.decodeJWT(jwt);
96
97
  if (!valid) {
97
98
  throw new Error('JWT is not valid');
98
99
  }
@@ -117,27 +118,21 @@ export function createClient(config) {
117
118
  return this.process(body, opts);
118
119
  },
119
120
  apps: {
120
- AppInstalled: {
121
- type: 'AppInstalled',
122
- __payload: void 0,
123
- },
124
- AppRemoved: {
125
- type: 'AppRemoved',
126
- __payload: void 0,
127
- },
121
+ AppInstalled: EventDefinition('AppInstalled')(),
122
+ AppRemoved: EventDefinition('AppRemoved')(),
128
123
  },
129
124
  },
130
125
  spi() {
131
126
  return {
132
- process(jwt) {
127
+ async process(jwt) {
133
128
  if (!authStrategy.decodeJWT) {
134
129
  throw new Error('decodeJWT is not supported by the authentication strategy');
135
130
  }
136
- const { decoded, valid } = authStrategy.decodeJWT(jwt, true);
131
+ const { decoded, valid } = await authStrategy.decodeJWT(jwt, true);
137
132
  if (!valid) {
138
133
  throw new Error('JWT is not valid');
139
134
  }
140
- return JSON.parse(decoded.data);
135
+ return decoded.data;
141
136
  },
142
137
  async processRequest(request) {
143
138
  const body = await request.text();
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.WixAppOAuthStrategy = void 0;
4
- const jsonwebtoken_1 = require("jsonwebtoken");
4
+ const jose_1 = require("jose");
5
5
  const helpers_js_1 = require("../helpers.js");
6
6
  /**
7
7
  * Creates an authentication strategy for Wix Apps OAuth installation process.
@@ -123,19 +123,21 @@ function WixAppOAuthStrategy(opts) {
123
123
  },
124
124
  };
125
125
  },
126
- decodeJWT(token, verifyCallerClaims = false) {
126
+ async decodeJWT(token, verifyCallerClaims = false) {
127
127
  if (!opts.publicKey) {
128
128
  throw new Error('Missing public key. Make sure to pass it to the WixAppOAuthStrategy');
129
129
  }
130
- const publicKey = (0, helpers_js_1.parsePublicKeyIfEncoded)(opts.publicKey);
131
- const decoded = (0, jsonwebtoken_1.verify)(token, publicKey, verifyCallerClaims
130
+ const publicKey = await (0, jose_1.importSPKI)((0, helpers_js_1.parsePublicKeyIfEncoded)(opts.publicKey), 'RS256');
131
+ const decoded = await (0, jose_1.jwtVerify)(token, publicKey, verifyCallerClaims
132
132
  ? {
133
133
  issuer: 'wix.com',
134
134
  audience: opts.appId,
135
135
  }
136
136
  : undefined);
137
137
  return {
138
- decoded,
138
+ decoded: {
139
+ data: decoded.payload.data,
140
+ },
139
141
  valid: true,
140
142
  };
141
143
  },
@@ -121,7 +121,7 @@ function OAuthStrategy(config) {
121
121
  const getAuthUrl = async (oauthData, opts = {
122
122
  prompt: 'login',
123
123
  }) => {
124
- return getAuthorizationUrlWithOptions(oauthData, opts.responseMode ?? 'fragment', opts.prompt ?? 'login');
124
+ return getAuthorizationUrlWithOptions(oauthData, opts.responseMode ?? 'fragment', opts.prompt ?? 'login', opts.sessionToken);
125
125
  };
126
126
  const parseFromUrl = (url, responseMode = 'fragment') => {
127
127
  const parsedUrl = new URL(url ?? window.location.href);
@@ -1,4 +1,4 @@
1
- import { AuthenticationStrategy, BoundAuthenticationStrategy, BuildRESTFunction, Host, HostModule, HostModuleAPI, RESTFunctionDescriptor, EventDefinition, SPIDefinition } from '@wix/sdk-types';
1
+ import { AuthenticationStrategy, BoundAuthenticationStrategy, BuildRESTFunction, Host, HostModule, HostModuleAPI, RESTFunctionDescriptor, SPIDefinition, EventDefinition } from '@wix/sdk-types';
2
2
  import { ConditionalExcept, EmptyObject } from 'type-fest';
3
3
  import { AmbassadorFunctionDescriptor, BuildAmbassadorFunction } from './ambassador-modules.js';
4
4
  import { PublicMetadata } from './common.js';
@@ -63,7 +63,7 @@ export type WixClient<H extends Host<any> | undefined = undefined, Z extends Aut
63
63
  webhooks: {
64
64
  process<ExpectedEvents extends EventDefinition<any>[] = []>(jwt: string, opts?: {
65
65
  expectedEvents: ExpectedEvents;
66
- }): ProcessedEvent<ExpectedEvents>;
66
+ }): Promise<ProcessedEvent<ExpectedEvents>>;
67
67
  processRequest<ExpectedEvents extends EventDefinition<any>[] = []>(request: Request, opts?: {
68
68
  expectedEvents: ExpectedEvents;
69
69
  }): Promise<ProcessedEvent<ExpectedEvents>>;
@@ -71,14 +71,14 @@ export type WixClient<H extends Host<any> | undefined = undefined, Z extends Aut
71
71
  AppInstalled: EventDefinition<{
72
72
  appId: string;
73
73
  originInstanceId: string;
74
- }>;
74
+ }, 'AppInstalled'>;
75
75
  AppRemoved: EventDefinition<{
76
76
  appId: string;
77
- }>;
77
+ }, 'AppRemoved'>;
78
78
  };
79
79
  };
80
80
  spi: <S extends SPIDefinition<any, any>>() => {
81
- process(jwt: string): S['__input'];
81
+ process(jwt: string): Promise<S['__input']>;
82
82
  processRequest(request: Request): Promise<S['__input']>;
83
83
  result(result: S['__result']): S['__result'];
84
84
  };
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createClient = void 0;
4
+ const sdk_types_1 = require("@wix/sdk-types");
4
5
  const ambassador_modules_js_1 = require("./ambassador-modules.js");
5
6
  const common_js_1 = require("./common.js");
6
7
  const helpers_js_1 = require("./helpers.js");
@@ -89,13 +90,13 @@ function createClient(config) {
89
90
  return { data: data ?? {}, errors };
90
91
  },
91
92
  webhooks: {
92
- process: (jwt, opts = {
93
+ process: async (jwt, opts = {
93
94
  expectedEvents: [],
94
95
  }) => {
95
96
  if (!authStrategy.decodeJWT) {
96
97
  throw new Error('decodeJWT is not supported by the authentication strategy');
97
98
  }
98
- const { decoded, valid } = authStrategy.decodeJWT(jwt);
99
+ const { decoded, valid } = await authStrategy.decodeJWT(jwt);
99
100
  if (!valid) {
100
101
  throw new Error('JWT is not valid');
101
102
  }
@@ -120,27 +121,21 @@ function createClient(config) {
120
121
  return this.process(body, opts);
121
122
  },
122
123
  apps: {
123
- AppInstalled: {
124
- type: 'AppInstalled',
125
- __payload: void 0,
126
- },
127
- AppRemoved: {
128
- type: 'AppRemoved',
129
- __payload: void 0,
130
- },
124
+ AppInstalled: (0, sdk_types_1.EventDefinition)('AppInstalled')(),
125
+ AppRemoved: (0, sdk_types_1.EventDefinition)('AppRemoved')(),
131
126
  },
132
127
  },
133
128
  spi() {
134
129
  return {
135
- process(jwt) {
130
+ async process(jwt) {
136
131
  if (!authStrategy.decodeJWT) {
137
132
  throw new Error('decodeJWT is not supported by the authentication strategy');
138
133
  }
139
- const { decoded, valid } = authStrategy.decodeJWT(jwt, true);
134
+ const { decoded, valid } = await authStrategy.decodeJWT(jwt, true);
140
135
  if (!valid) {
141
136
  throw new Error('JWT is not valid');
142
137
  }
143
- return JSON.parse(decoded.data);
138
+ return decoded.data;
144
139
  },
145
140
  async processRequest(request) {
146
141
  const body = await request.text();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/sdk",
3
- "version": "1.7.3",
3
+ "version": "1.7.5",
4
4
  "license": "UNLICENSED",
5
5
  "author": {
6
6
  "name": "Ronny Ringel",
@@ -59,12 +59,12 @@
59
59
  },
60
60
  "dependencies": {
61
61
  "@babel/runtime": "^7.23.2",
62
- "@wix/identity": "^1.0.72",
63
- "@wix/image-kit": "^1.50.0",
62
+ "@wix/identity": "^1.0.73",
63
+ "@wix/image-kit": "^1.53.0",
64
64
  "@wix/redirects": "^1.0.32",
65
- "@wix/sdk-types": "^1.5.6",
65
+ "@wix/sdk-types": "^1.5.8",
66
66
  "crypto-js": "^4.2.0",
67
- "jsonwebtoken": "^9.0.2",
67
+ "jose": "^5.2.1",
68
68
  "pkce-challenge": "^3.1.0",
69
69
  "querystring": "^0.2.1",
70
70
  "type-fest": "^4.9.0"
@@ -75,13 +75,12 @@
75
75
  "devDependencies": {
76
76
  "@types/crypto-js": "^4.2.1",
77
77
  "@types/is-ci": "^3.0.4",
78
- "@types/jsonwebtoken": "^9.0.5",
79
78
  "@types/node": "^20.10.6",
80
79
  "@vitest/ui": "^1.1.3",
81
- "@wix/ecom": "^1.0.474",
80
+ "@wix/ecom": "^1.0.477",
82
81
  "@wix/events": "^1.0.145",
83
82
  "@wix/metro": "^1.0.73",
84
- "@wix/metro-runtime": "^1.1618.0",
83
+ "@wix/metro-runtime": "^1.1626.0",
85
84
  "@wix/sdk-runtime": "0.2.7",
86
85
  "eslint": "^8.56.0",
87
86
  "eslint-config-sdk": "0.0.0",
@@ -116,5 +115,5 @@
116
115
  "wallaby": {
117
116
  "autoDetect": true
118
117
  },
119
- "falconPackageHash": "1ab723e4b75dc05738d9710385e9cfbe6d32deae3902e5809011288c"
118
+ "falconPackageHash": "f4e811e8bf2062b6ed3e27ff0f6c8f3e16dad175c63a2b0a37dccf38"
120
119
  }