@commercetools/connect-payments-sdk 0.0.1 → 0.0.4
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/api/context/types/request-context.type.d.ts +2 -2
- package/dist/api/handlers/config.handler.d.ts +1 -1
- package/dist/api/handlers/status.handler.d.ts +12 -6
- package/dist/api/handlers/status.handler.js +4 -7
- package/dist/api/handlers/types/handler.type.d.ts +2 -2
- package/dist/api/hooks/jwt-auth.hook.d.ts +16 -0
- package/dist/api/hooks/jwt-auth.hook.js +22 -0
- package/dist/api/hooks/oauth2-auth.hook.d.ts +16 -0
- package/dist/api/hooks/oauth2-auth.hook.js +22 -0
- package/dist/api/hooks/session-auth.hook.d.ts +14 -13
- package/dist/api/hooks/session-auth.hook.js +18 -27
- package/dist/api/hooks/types/hook.type.d.ts +10 -0
- package/dist/api/index.d.ts +3 -0
- package/dist/api/index.js +3 -0
- package/dist/commercetools/index.d.ts +2 -0
- package/dist/commercetools/services/ct-authorization.service.d.ts +18 -0
- package/dist/commercetools/services/ct-authorization.service.js +42 -0
- package/dist/commercetools/services/ct-payment.service.d.ts +6 -1
- package/dist/commercetools/services/ct-payment.service.js +72 -0
- package/dist/commercetools/services/ct-session.service.d.ts +16 -0
- package/dist/commercetools/services/ct-session.service.js +45 -0
- package/dist/commercetools/types/api.type.d.ts +11 -0
- package/dist/commercetools/types/authorization.type.d.ts +9 -0
- package/dist/commercetools/types/payment.type.d.ts +10 -0
- package/dist/commercetools/types/session.type.d.ts +28 -0
- package/dist/commercetools/types/session.type.js +2 -0
- package/dist/errorx/errorx.d.ts +4 -1
- package/dist/errorx/errorx.js +15 -4
- package/dist/index.d.ts +8 -8
- package/dist/index.js +38 -12
- package/dist/security/authn/authns.d.ts +49 -0
- package/dist/security/authn/authns.js +123 -0
- package/dist/security/authn/bearer-utils.d.ts +1 -0
- package/dist/security/authn/bearer-utils.js +19 -0
- package/dist/security/authn/jwt-authn-manager.d.ts +12 -0
- package/dist/security/authn/jwt-authn-manager.js +33 -0
- package/dist/security/authn/oauth2-authn-manager.d.ts +17 -0
- package/dist/security/authn/oauth2-authn-manager.js +65 -0
- package/dist/security/authn/session-authn-manager.d.ts +10 -0
- package/dist/security/authn/session-authn-manager.js +25 -0
- package/dist/security/authn/types/authn.type.d.ts +27 -0
- package/dist/security/authn/types/authn.type.js +2 -0
- package/dist/security/index.d.ts +6 -2
- package/dist/security/index.js +6 -2
- package/dist/security/services/jwt.service.d.ts +10 -0
- package/dist/security/services/jwt.service.js +40 -0
- package/dist/security/services/oauth2.service.d.ts +7 -14
- package/dist/security/services/oauth2.service.js +22 -35
- package/dist/security/services/types/jwt.type.d.ts +5 -0
- package/dist/security/services/types/jwt.type.js +2 -0
- package/dist/security/services/types/oauth2.type.d.ts +14 -0
- package/dist/security/services/types/oauth2.type.js +2 -0
- package/package.json +5 -3
- package/.github/workflows/ci.yml +0 -34
- package/.github/workflows/release.yml +0 -46
- package/.husky/pre-commit +0 -4
- package/dist/security/auth/session.auth.d.ts +0 -20
- package/dist/security/auth/session.auth.js +0 -54
- package/dist/security/types/oauth2.type.d.ts +0 -13
- package/dist/security/types/session.type.d.ts +0 -10
- /package/dist/{security/types/oauth2.type.js → api/hooks/types/hook.type.js} +0 -0
- /package/dist/{security/types/session.type.js → commercetools/types/authorization.type.js} +0 -0
|
@@ -1,53 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DefaultOauth2Service = void 0;
|
|
4
|
-
const errorx_1 = require("../../errorx
|
|
4
|
+
const errorx_1 = require("../../errorx");
|
|
5
5
|
class DefaultOauth2Service {
|
|
6
|
-
|
|
7
|
-
fetch;
|
|
8
|
-
logger;
|
|
9
|
-
constructor(opts) {
|
|
10
|
-
this.authUrl = opts.authUrl;
|
|
11
|
-
this.fetch = opts.fetch;
|
|
12
|
-
this.logger = opts.logger;
|
|
13
|
-
}
|
|
14
|
-
oauth2tokenCache = new Map();
|
|
15
|
-
oauth2tokenKey(clientId, clientSecret) {
|
|
16
|
-
return `${clientId}:${clientSecret}`;
|
|
17
|
-
}
|
|
18
|
-
async getAccessToken(opts) {
|
|
19
|
-
const token = this.oauth2tokenCache.get(this.oauth2tokenKey(opts.clientId, opts.clientSecret));
|
|
20
|
-
// Check if token is valid for at least 1 hour
|
|
21
|
-
if (token && token.expiresAt + 3600 * 1000 > Date.now()) {
|
|
22
|
-
if (this.logger) {
|
|
23
|
-
this.logger.debug({
|
|
24
|
-
isRenewal: token ? true : false,
|
|
25
|
-
}, 'Renewing token access token');
|
|
26
|
-
}
|
|
27
|
-
return token.token;
|
|
28
|
-
}
|
|
29
|
-
const encodedCredentials = btoa(`${opts.clientId}:${opts.clientSecret}`);
|
|
6
|
+
async introspectToken(opts) {
|
|
30
7
|
const urlencoded = new URLSearchParams();
|
|
31
|
-
urlencoded.append('
|
|
32
|
-
const
|
|
8
|
+
urlencoded.append('token', opts.token);
|
|
9
|
+
const tokenResponse = await fetch(opts.url, {
|
|
33
10
|
method: 'POST',
|
|
34
11
|
headers: {
|
|
35
12
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
36
|
-
Authorization: `Basic ${
|
|
13
|
+
Authorization: `Basic ${btoa(opts.clientId + ':' + opts.clientSecret)}`,
|
|
37
14
|
},
|
|
38
15
|
body: urlencoded,
|
|
39
16
|
});
|
|
40
|
-
if (
|
|
41
|
-
|
|
42
|
-
|
|
17
|
+
if (tokenResponse.status > 299) {
|
|
18
|
+
if (tokenResponse.status === 401) {
|
|
19
|
+
const tokenResponseJson = (await tokenResponse.json());
|
|
20
|
+
throw new errorx_1.ErrorAuthErrorResponse(tokenResponseJson.message, {
|
|
21
|
+
privateFields: {
|
|
22
|
+
clientId: opts.clientId,
|
|
23
|
+
status: tokenResponse.status,
|
|
24
|
+
},
|
|
25
|
+
skipLog: true,
|
|
26
|
+
}, tokenResponseJson.error);
|
|
27
|
+
}
|
|
28
|
+
throw new errorx_1.ErrorGeneral('Failed to authorize request.', {
|
|
29
|
+
privateMessage: 'some error happened while requesting token from coco',
|
|
43
30
|
privateFields: {
|
|
44
|
-
|
|
45
|
-
|
|
31
|
+
clientId: opts.clientId,
|
|
32
|
+
status: tokenResponse.status,
|
|
46
33
|
},
|
|
34
|
+
skipLog: true,
|
|
47
35
|
});
|
|
48
36
|
}
|
|
49
|
-
|
|
50
|
-
return tokenRes;
|
|
37
|
+
return (await tokenResponse.json());
|
|
51
38
|
}
|
|
52
39
|
}
|
|
53
40
|
exports.DefaultOauth2Service = DefaultOauth2Service;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type TokenInfo = {
|
|
2
|
+
active: boolean;
|
|
3
|
+
scope: string;
|
|
4
|
+
exp: number;
|
|
5
|
+
client_id: string;
|
|
6
|
+
};
|
|
7
|
+
export interface Oauth2Service {
|
|
8
|
+
introspectToken(opts: {
|
|
9
|
+
url: string;
|
|
10
|
+
clientId: string;
|
|
11
|
+
clientSecret: string;
|
|
12
|
+
token: string;
|
|
13
|
+
}): Promise<TokenInfo>;
|
|
14
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercetools/connect-payments-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
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,9 @@
|
|
|
15
15
|
],
|
|
16
16
|
"license": "ISC",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@commercetools/platform-sdk": "
|
|
19
|
-
"@commercetools/sdk-client-v2": "2.3.0"
|
|
18
|
+
"@commercetools/platform-sdk": "7.2.0-alpha.4",
|
|
19
|
+
"@commercetools/sdk-client-v2": "2.3.0",
|
|
20
|
+
"jsonwebtoken": "9.0.2",
|
|
21
|
+
"jwks-rsa": "3.1.0"
|
|
20
22
|
}
|
|
21
23
|
}
|
package/.github/workflows/ci.yml
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
name: CI
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
pull_request:
|
|
5
|
-
branches: [ main ]
|
|
6
|
-
|
|
7
|
-
jobs:
|
|
8
|
-
ci:
|
|
9
|
-
runs-on: ubuntu-latest
|
|
10
|
-
steps:
|
|
11
|
-
- name: Checkout Repo
|
|
12
|
-
uses: actions/checkout@v4
|
|
13
|
-
|
|
14
|
-
- name: Install Node.js
|
|
15
|
-
uses: actions/setup-node@v3
|
|
16
|
-
with:
|
|
17
|
-
node-version: 20
|
|
18
|
-
|
|
19
|
-
- name: Install dependencies
|
|
20
|
-
uses: pnpm/action-setup@v2
|
|
21
|
-
with:
|
|
22
|
-
version: 8
|
|
23
|
-
run_install: |
|
|
24
|
-
- recursive: true
|
|
25
|
-
args: [--frozen-lockfile, --strict-peer-dependencies]
|
|
26
|
-
|
|
27
|
-
- name: Build
|
|
28
|
-
run: pnpm run build
|
|
29
|
-
|
|
30
|
-
- name: Static code analysis
|
|
31
|
-
run: pnpm run lint
|
|
32
|
-
|
|
33
|
-
- name: Tests
|
|
34
|
-
run: pnpm run test
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
name: Release
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
branches: [ main ]
|
|
6
|
-
|
|
7
|
-
jobs:
|
|
8
|
-
publish-gpr:
|
|
9
|
-
runs-on: ubuntu-latest
|
|
10
|
-
steps:
|
|
11
|
-
- name: Checkout Repo
|
|
12
|
-
uses: actions/checkout@v4
|
|
13
|
-
|
|
14
|
-
- name: Install Node.js
|
|
15
|
-
uses: actions/setup-node@v3
|
|
16
|
-
with:
|
|
17
|
-
node-version: 20
|
|
18
|
-
|
|
19
|
-
- name: Install dependencies
|
|
20
|
-
uses: pnpm/action-setup@v2
|
|
21
|
-
with:
|
|
22
|
-
version: 8
|
|
23
|
-
run_install: |
|
|
24
|
-
- recursive: true
|
|
25
|
-
args: [--frozen-lockfile, --strict-peer-dependencies]
|
|
26
|
-
|
|
27
|
-
- name: Static code analysis
|
|
28
|
-
run: pnpm run lint
|
|
29
|
-
|
|
30
|
-
- name: Tests
|
|
31
|
-
run: pnpm run test
|
|
32
|
-
|
|
33
|
-
- name: Create Release Pull Request or Publish to npm
|
|
34
|
-
id: changesets
|
|
35
|
-
uses: changesets/action@v1
|
|
36
|
-
with:
|
|
37
|
-
# This expects you to have a script called release which does a build for your packages and calls changeset publish
|
|
38
|
-
publish: pnpm run release
|
|
39
|
-
env:
|
|
40
|
-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
41
|
-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
42
|
-
|
|
43
|
-
- name: Create release
|
|
44
|
-
if: steps.changesets.outputs.published == 'true'
|
|
45
|
-
# You can do something when a publish happens.
|
|
46
|
-
run: VERSION=$(jq '.version' package.json -r);gh release create "$VERSION" --title "$VERSION [@commercetools/connect-payments-sdk]" --notes 'Check CHANGELOG.md file.'
|
package/.husky/pre-commit
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Fetch } from '../../fetch/types/fetch.type';
|
|
2
|
-
import { Oauth2Service } from '../types/oauth2.type';
|
|
3
|
-
import { IntrospectSessionParams, PaymentSessionData, SessionAuthenticator } from '../types/session.type';
|
|
4
|
-
export declare class DefaultSessionAuthenticator implements SessionAuthenticator {
|
|
5
|
-
private oauth2Service;
|
|
6
|
-
private sessionUrl;
|
|
7
|
-
private clientId;
|
|
8
|
-
private clientSecret;
|
|
9
|
-
private projectKey;
|
|
10
|
-
private fetch;
|
|
11
|
-
constructor(opts: {
|
|
12
|
-
oauth2Service: Oauth2Service;
|
|
13
|
-
sessionUrl: string;
|
|
14
|
-
clientId: string;
|
|
15
|
-
clientSecret: string;
|
|
16
|
-
projectKey: string;
|
|
17
|
-
fetch: Fetch;
|
|
18
|
-
});
|
|
19
|
-
introspectSession(opts: IntrospectSessionParams): Promise<PaymentSessionData>;
|
|
20
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DefaultSessionAuthenticator = void 0;
|
|
4
|
-
const errorx_1 = require("../../errorx/errorx");
|
|
5
|
-
class DefaultSessionAuthenticator {
|
|
6
|
-
oauth2Service;
|
|
7
|
-
sessionUrl;
|
|
8
|
-
clientId;
|
|
9
|
-
clientSecret;
|
|
10
|
-
projectKey;
|
|
11
|
-
fetch;
|
|
12
|
-
constructor(opts) {
|
|
13
|
-
this.oauth2Service = opts.oauth2Service;
|
|
14
|
-
this.sessionUrl = opts.sessionUrl;
|
|
15
|
-
this.clientId = opts.clientId;
|
|
16
|
-
this.clientSecret = opts.clientSecret;
|
|
17
|
-
this.projectKey = opts.projectKey;
|
|
18
|
-
this.fetch = opts.fetch;
|
|
19
|
-
}
|
|
20
|
-
async introspectSession(opts) {
|
|
21
|
-
const accessToken = await this.oauth2Service.getAccessToken({
|
|
22
|
-
clientId: this.clientId,
|
|
23
|
-
clientSecret: this.clientSecret,
|
|
24
|
-
});
|
|
25
|
-
const response = await this.fetch(`${this.sessionUrl}/${this.projectKey}/sessions/${opts.sessionId}`, {
|
|
26
|
-
method: 'GET',
|
|
27
|
-
headers: {
|
|
28
|
-
'Content-Type': 'application/json',
|
|
29
|
-
Authorization: `Bearer ${accessToken.access_token}`,
|
|
30
|
-
},
|
|
31
|
-
});
|
|
32
|
-
if (!response.ok) {
|
|
33
|
-
if (response.status === 401) {
|
|
34
|
-
throw new errorx_1.ErrorAuthErrorResponse({
|
|
35
|
-
privateMessage: 'Failed to get session data',
|
|
36
|
-
privateFields: {
|
|
37
|
-
responseStatus: response.status,
|
|
38
|
-
responseText: await response.text(),
|
|
39
|
-
},
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
throw new errorx_1.ErrorGeneral(undefined, {
|
|
43
|
-
privateMessage: 'Failed to get session data',
|
|
44
|
-
privateFields: {
|
|
45
|
-
responseStatus: response.status,
|
|
46
|
-
responseText: await response.text(),
|
|
47
|
-
},
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
const sessionRes = (await response.json());
|
|
51
|
-
return sessionRes.metadata;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
exports.DefaultSessionAuthenticator = DefaultSessionAuthenticator;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export type TokenResponse = {
|
|
2
|
-
access_token: string;
|
|
3
|
-
token_type: string;
|
|
4
|
-
scope: string;
|
|
5
|
-
expires_in: number;
|
|
6
|
-
};
|
|
7
|
-
export interface Oauth2Service {
|
|
8
|
-
getAccessToken(opts: GetAccessTokenParams): Promise<TokenResponse>;
|
|
9
|
-
}
|
|
10
|
-
export type GetAccessTokenParams = {
|
|
11
|
-
clientId: string;
|
|
12
|
-
clientSecret: string;
|
|
13
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export type PaymentSessionData = {
|
|
2
|
-
cartId: string;
|
|
3
|
-
allowedPaymentMethods?: string[];
|
|
4
|
-
};
|
|
5
|
-
export interface SessionAuthenticator {
|
|
6
|
-
introspectSession(opts: IntrospectSessionParams): Promise<PaymentSessionData>;
|
|
7
|
-
}
|
|
8
|
-
export type IntrospectSessionParams = {
|
|
9
|
-
sessionId: string;
|
|
10
|
-
};
|
|
File without changes
|
|
File without changes
|