@commercetools/connect-payments-sdk 0.4.0 → 0.4.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.
- package/CHANGELOG.md +12 -0
- package/dist/commercetools/services/ct-session.service.d.ts +1 -0
- package/dist/commercetools/services/ct-session.service.js +39 -10
- package/dist/index.d.ts +1 -1
- package/dist/security/authn/authns.js +1 -1
- package/dist/security/authn/session-header-authn-manager.js +3 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @commercetools/connect-payments-sdk
|
|
2
2
|
|
|
3
|
+
## 0.4.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 17b3982: export platform-sdk types
|
|
8
|
+
|
|
9
|
+
## 0.4.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 9991f6f: fix authentication error when the commercetools token had expired but the session Id provided was correct
|
|
14
|
+
|
|
3
15
|
## 0.4.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
|
@@ -16,4 +16,5 @@ export declare class DefaultSessionService implements SessionService {
|
|
|
16
16
|
getProcessorUrlFromSession(session: Session): string;
|
|
17
17
|
getPaymentInterfaceFromSession(session: Session): string | undefined;
|
|
18
18
|
getMerchantReturnUrlFromSession(session: Session): string | undefined;
|
|
19
|
+
private getSession;
|
|
19
20
|
}
|
|
@@ -16,25 +16,45 @@ class DefaultSessionService {
|
|
|
16
16
|
if (!this.token) {
|
|
17
17
|
this.token = await this.authorizationService.getAccessToken();
|
|
18
18
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
let res = await this.getSession(sessionId);
|
|
20
|
+
// If commercetools oauth token is expired, get a new one and retry
|
|
21
|
+
if (res.status === 401 || res.status === 403) {
|
|
22
|
+
this.token = await this.authorizationService.getAccessToken();
|
|
23
|
+
res = await this.getSession(sessionId);
|
|
24
|
+
}
|
|
25
|
+
if (res.status === 404) {
|
|
26
|
+
throw new errorx_1.ErrorAuthErrorResponse('commercetools session not found', {
|
|
27
|
+
privateFields: {
|
|
28
|
+
status: res.status,
|
|
29
|
+
statusText: res.statusText,
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
}
|
|
26
33
|
if (!res.ok) {
|
|
27
|
-
throw new errorx_1.ErrorGeneral('Could not get session'
|
|
34
|
+
throw new errorx_1.ErrorGeneral('Could not get commercetools session', {
|
|
35
|
+
privateFields: {
|
|
36
|
+
status: res.status,
|
|
37
|
+
statusText: res.statusText,
|
|
38
|
+
},
|
|
39
|
+
});
|
|
28
40
|
}
|
|
29
41
|
const session = (await res.json());
|
|
30
42
|
if (session.state !== 'ACTIVE') {
|
|
31
|
-
throw new errorx_1.ErrorAuthErrorResponse(
|
|
43
|
+
throw new errorx_1.ErrorAuthErrorResponse(`commercetools session is not ACTIVE, current status: ${session.state}`, {
|
|
44
|
+
privateFields: {
|
|
45
|
+
session: JSON.stringify(session),
|
|
46
|
+
},
|
|
47
|
+
});
|
|
32
48
|
}
|
|
33
49
|
return session;
|
|
34
50
|
}
|
|
35
51
|
getCartFromSession(session) {
|
|
36
52
|
if (!session.activeCart?.cartRef?.id) {
|
|
37
|
-
throw new errorx_1.ErrorAuthErrorResponse(
|
|
53
|
+
throw new errorx_1.ErrorAuthErrorResponse('Cart not found in commercetools session', {
|
|
54
|
+
privateFields: {
|
|
55
|
+
session: JSON.stringify(session),
|
|
56
|
+
},
|
|
57
|
+
});
|
|
38
58
|
}
|
|
39
59
|
return session.activeCart.cartRef.id;
|
|
40
60
|
}
|
|
@@ -50,5 +70,14 @@ class DefaultSessionService {
|
|
|
50
70
|
getMerchantReturnUrlFromSession(session) {
|
|
51
71
|
return session.metadata?.merchantReturnUrl;
|
|
52
72
|
}
|
|
73
|
+
async getSession(sessionId) {
|
|
74
|
+
return await fetch(`${this.sessionUrl}/${this.projectKey}/sessions/${sessionId}`, {
|
|
75
|
+
method: 'GET',
|
|
76
|
+
headers: {
|
|
77
|
+
'Content-Type': 'application/json',
|
|
78
|
+
Authorization: `Bearer ${this.token.access_token}`,
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
}
|
|
53
82
|
}
|
|
54
83
|
exports.DefaultSessionService = DefaultSessionService;
|
package/dist/index.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export declare const setupPaymentSDK: (opts: {
|
|
|
20
20
|
jwtIssuer: string;
|
|
21
21
|
getContextFn: () => RequestContextData;
|
|
22
22
|
updateContextFn: (ctx: Partial<RequestContextData>) => void;
|
|
23
|
-
logger?: Logger
|
|
23
|
+
logger?: Logger;
|
|
24
24
|
}) => {
|
|
25
25
|
ctAPI: DefaultCommercetoolsAPI;
|
|
26
26
|
ctCartService: DefaultCartService;
|
|
@@ -132,7 +132,7 @@ class JWTAuthentication {
|
|
|
132
132
|
return this.getPrincipal() !== undefined;
|
|
133
133
|
}
|
|
134
134
|
getAuthorities() {
|
|
135
|
-
return [];
|
|
135
|
+
return ['manage_project', 'manage_checkout_application'];
|
|
136
136
|
}
|
|
137
137
|
hasCredentials() {
|
|
138
138
|
return this.getCredentials() !== undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercetools/connect-payments-sdk",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "Payment SDK for commercetools payment connectors",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
],
|
|
16
16
|
"license": "ISC",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@commercetools/platform-sdk": "7.
|
|
18
|
+
"@commercetools/platform-sdk": "7.6.0",
|
|
19
19
|
"@commercetools/sdk-client-v2": "2.4.0",
|
|
20
20
|
"jsonwebtoken": "9.0.2",
|
|
21
21
|
"jwks-rsa": "3.1.0"
|