@wix/sdk 1.9.6 → 1.9.7
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.
- package/build/auth/oauth2/OAuthStrategy.js +19 -1
- package/build/auth/oauth2/types.d.ts +1 -0
- package/build/event-handlers-modules.js +12 -10
- package/cjs/build/auth/oauth2/OAuthStrategy.js +19 -1
- package/cjs/build/auth/oauth2/types.d.ts +1 -0
- package/cjs/build/event-handlers-modules.js +12 -10
- package/package.json +3 -3
|
@@ -319,6 +319,22 @@ export function OAuthStrategy(config) {
|
|
|
319
319
|
const loggedIn = () => {
|
|
320
320
|
return _tokens.refreshToken.role === TokenRole.MEMBER;
|
|
321
321
|
};
|
|
322
|
+
const getMemberTokensForExternalLogin = async (memberId, apiKey) => {
|
|
323
|
+
const tokensResponse = await fetchTokens({
|
|
324
|
+
grant_type: 'authorized_client',
|
|
325
|
+
scope: 'offline_access',
|
|
326
|
+
member_id: memberId,
|
|
327
|
+
}, {
|
|
328
|
+
Authorization: _tokens.accessToken.value + ',' + apiKey,
|
|
329
|
+
});
|
|
330
|
+
return {
|
|
331
|
+
accessToken: createAccessToken(tokensResponse.access_token, tokensResponse.expires_in),
|
|
332
|
+
refreshToken: {
|
|
333
|
+
value: tokensResponse.refresh_token,
|
|
334
|
+
role: TokenRole.MEMBER,
|
|
335
|
+
},
|
|
336
|
+
};
|
|
337
|
+
};
|
|
322
338
|
return {
|
|
323
339
|
generateVisitorTokens,
|
|
324
340
|
renewToken,
|
|
@@ -335,12 +351,13 @@ export function OAuthStrategy(config) {
|
|
|
335
351
|
processVerification,
|
|
336
352
|
login,
|
|
337
353
|
getMemberTokensForDirectLogin,
|
|
354
|
+
getMemberTokensForExternalLogin,
|
|
338
355
|
sendPasswordResetEmail,
|
|
339
356
|
captchaInvisibleSiteKey: '6LdoPaUfAAAAAJphvHoUoOob7mx0KDlXyXlgrx5v',
|
|
340
357
|
captchaVisibleSiteKey: '6Ld0J8IcAAAAANyrnxzrRlX1xrrdXsOmsepUYosy',
|
|
341
358
|
};
|
|
342
359
|
}
|
|
343
|
-
const fetchTokens = async (payload) => {
|
|
360
|
+
const fetchTokens = async (payload, headers = {}) => {
|
|
344
361
|
const res = await fetch(`https://${API_URL}/oauth2/token`, {
|
|
345
362
|
method: 'POST',
|
|
346
363
|
body: JSON.stringify(payload),
|
|
@@ -351,6 +368,7 @@ const fetchTokens = async (payload) => {
|
|
|
351
368
|
packageName: '@wix/sdk',
|
|
352
369
|
}),
|
|
353
370
|
'Content-Type': 'application/json',
|
|
371
|
+
...headers,
|
|
354
372
|
},
|
|
355
373
|
});
|
|
356
374
|
if (res.status !== 200) {
|
|
@@ -66,6 +66,7 @@ export interface IOAuthStrategy extends AuthenticationStrategy {
|
|
|
66
66
|
captchaInvisibleSiteKey: string;
|
|
67
67
|
captchaVisibleSiteKey: string;
|
|
68
68
|
loggedIn: () => boolean;
|
|
69
|
+
getMemberTokensForExternalLogin: (memberId: string, apiKey: string) => Promise<Tokens>;
|
|
69
70
|
}
|
|
70
71
|
export declare enum LoginState {
|
|
71
72
|
SUCCESS = "SUCCESS",
|
|
@@ -6,6 +6,7 @@ export function buildEventDefinition(eventDefinition, registerHandler) {
|
|
|
6
6
|
};
|
|
7
7
|
}
|
|
8
8
|
export function runHandler(eventDefinition, handler, payload, baseEventMetadata) {
|
|
9
|
+
let envelope;
|
|
9
10
|
if (eventDefinition.isDomainEvent) {
|
|
10
11
|
const domainEventPayload = payload;
|
|
11
12
|
const { deletedEvent, actionEvent, createdEvent, updatedEvent, ...domainEventMetadata } = domainEventPayload;
|
|
@@ -14,26 +15,27 @@ export function runHandler(eventDefinition, handler, payload, baseEventMetadata)
|
|
|
14
15
|
...domainEventMetadata,
|
|
15
16
|
};
|
|
16
17
|
if (deletedEvent) {
|
|
17
|
-
|
|
18
|
+
envelope = { metadata };
|
|
18
19
|
}
|
|
19
20
|
else if (actionEvent) {
|
|
20
|
-
|
|
21
|
-
data:
|
|
21
|
+
envelope = {
|
|
22
|
+
data: actionEvent.body,
|
|
22
23
|
metadata,
|
|
23
|
-
}
|
|
24
|
+
};
|
|
24
25
|
}
|
|
25
26
|
else {
|
|
26
|
-
|
|
27
|
-
entity:
|
|
28
|
-
domainEventPayload.updatedEvent?.currentEntity,
|
|
27
|
+
envelope = {
|
|
28
|
+
entity: createdEvent?.entity ?? updatedEvent?.currentEntity,
|
|
29
29
|
metadata,
|
|
30
|
-
}
|
|
30
|
+
};
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
else {
|
|
34
|
-
|
|
34
|
+
envelope = {
|
|
35
35
|
data: payload,
|
|
36
36
|
metadata: baseEventMetadata,
|
|
37
|
-
}
|
|
37
|
+
};
|
|
38
38
|
}
|
|
39
|
+
const transformFromRESTFn = eventDefinition.transformations ?? ((x) => x);
|
|
40
|
+
return handler(transformFromRESTFn(envelope));
|
|
39
41
|
}
|
|
@@ -322,6 +322,22 @@ function OAuthStrategy(config) {
|
|
|
322
322
|
const loggedIn = () => {
|
|
323
323
|
return _tokens.refreshToken.role === types_js_1.TokenRole.MEMBER;
|
|
324
324
|
};
|
|
325
|
+
const getMemberTokensForExternalLogin = async (memberId, apiKey) => {
|
|
326
|
+
const tokensResponse = await fetchTokens({
|
|
327
|
+
grant_type: 'authorized_client',
|
|
328
|
+
scope: 'offline_access',
|
|
329
|
+
member_id: memberId,
|
|
330
|
+
}, {
|
|
331
|
+
Authorization: _tokens.accessToken.value + ',' + apiKey,
|
|
332
|
+
});
|
|
333
|
+
return {
|
|
334
|
+
accessToken: (0, tokenHelpers_js_1.createAccessToken)(tokensResponse.access_token, tokensResponse.expires_in),
|
|
335
|
+
refreshToken: {
|
|
336
|
+
value: tokensResponse.refresh_token,
|
|
337
|
+
role: types_js_1.TokenRole.MEMBER,
|
|
338
|
+
},
|
|
339
|
+
};
|
|
340
|
+
};
|
|
325
341
|
return {
|
|
326
342
|
generateVisitorTokens,
|
|
327
343
|
renewToken,
|
|
@@ -338,13 +354,14 @@ function OAuthStrategy(config) {
|
|
|
338
354
|
processVerification,
|
|
339
355
|
login,
|
|
340
356
|
getMemberTokensForDirectLogin,
|
|
357
|
+
getMemberTokensForExternalLogin,
|
|
341
358
|
sendPasswordResetEmail,
|
|
342
359
|
captchaInvisibleSiteKey: '6LdoPaUfAAAAAJphvHoUoOob7mx0KDlXyXlgrx5v',
|
|
343
360
|
captchaVisibleSiteKey: '6Ld0J8IcAAAAANyrnxzrRlX1xrrdXsOmsepUYosy',
|
|
344
361
|
};
|
|
345
362
|
}
|
|
346
363
|
exports.OAuthStrategy = OAuthStrategy;
|
|
347
|
-
const fetchTokens = async (payload) => {
|
|
364
|
+
const fetchTokens = async (payload, headers = {}) => {
|
|
348
365
|
const res = await fetch(`https://${common_js_1.API_URL}/oauth2/token`, {
|
|
349
366
|
method: 'POST',
|
|
350
367
|
body: JSON.stringify(payload),
|
|
@@ -355,6 +372,7 @@ const fetchTokens = async (payload) => {
|
|
|
355
372
|
packageName: '@wix/sdk',
|
|
356
373
|
}),
|
|
357
374
|
'Content-Type': 'application/json',
|
|
375
|
+
...headers,
|
|
358
376
|
},
|
|
359
377
|
});
|
|
360
378
|
if (res.status !== 200) {
|
|
@@ -66,6 +66,7 @@ export interface IOAuthStrategy extends AuthenticationStrategy {
|
|
|
66
66
|
captchaInvisibleSiteKey: string;
|
|
67
67
|
captchaVisibleSiteKey: string;
|
|
68
68
|
loggedIn: () => boolean;
|
|
69
|
+
getMemberTokensForExternalLogin: (memberId: string, apiKey: string) => Promise<Tokens>;
|
|
69
70
|
}
|
|
70
71
|
export declare enum LoginState {
|
|
71
72
|
SUCCESS = "SUCCESS",
|
|
@@ -11,6 +11,7 @@ function buildEventDefinition(eventDefinition, registerHandler) {
|
|
|
11
11
|
}
|
|
12
12
|
exports.buildEventDefinition = buildEventDefinition;
|
|
13
13
|
function runHandler(eventDefinition, handler, payload, baseEventMetadata) {
|
|
14
|
+
let envelope;
|
|
14
15
|
if (eventDefinition.isDomainEvent) {
|
|
15
16
|
const domainEventPayload = payload;
|
|
16
17
|
const { deletedEvent, actionEvent, createdEvent, updatedEvent, ...domainEventMetadata } = domainEventPayload;
|
|
@@ -19,27 +20,28 @@ function runHandler(eventDefinition, handler, payload, baseEventMetadata) {
|
|
|
19
20
|
...domainEventMetadata,
|
|
20
21
|
};
|
|
21
22
|
if (deletedEvent) {
|
|
22
|
-
|
|
23
|
+
envelope = { metadata };
|
|
23
24
|
}
|
|
24
25
|
else if (actionEvent) {
|
|
25
|
-
|
|
26
|
-
data:
|
|
26
|
+
envelope = {
|
|
27
|
+
data: actionEvent.body,
|
|
27
28
|
metadata,
|
|
28
|
-
}
|
|
29
|
+
};
|
|
29
30
|
}
|
|
30
31
|
else {
|
|
31
|
-
|
|
32
|
-
entity:
|
|
33
|
-
domainEventPayload.updatedEvent?.currentEntity,
|
|
32
|
+
envelope = {
|
|
33
|
+
entity: createdEvent?.entity ?? updatedEvent?.currentEntity,
|
|
34
34
|
metadata,
|
|
35
|
-
}
|
|
35
|
+
};
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
else {
|
|
39
|
-
|
|
39
|
+
envelope = {
|
|
40
40
|
data: payload,
|
|
41
41
|
metadata: baseEventMetadata,
|
|
42
|
-
}
|
|
42
|
+
};
|
|
43
43
|
}
|
|
44
|
+
const transformFromRESTFn = eventDefinition.transformations ?? ((x) => x);
|
|
45
|
+
return handler(transformFromRESTFn(envelope));
|
|
44
46
|
}
|
|
45
47
|
exports.runHandler = runHandler;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/sdk",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.7",
|
|
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.68.0",
|
|
69
69
|
"@wix/redirects": "^1.0.41",
|
|
70
|
-
"@wix/sdk-types": "^1.7.
|
|
70
|
+
"@wix/sdk-types": "^1.7.2",
|
|
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": "
|
|
123
|
+
"falconPackageHash": "d4dbbb6460aeb154746786c06a55f71816e5fd35e26dbe365fbe69aa"
|
|
124
124
|
}
|