@commercetools/connect-payments-sdk 0.0.1
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/.github/workflows/ci.yml +34 -0
- package/.github/workflows/release.yml +46 -0
- package/.husky/pre-commit +4 -0
- package/CHANGELOG.md +7 -0
- package/README.md +19 -0
- package/dist/api/context/request-context.provider.d.ts +14 -0
- package/dist/api/context/request-context.provider.js +21 -0
- package/dist/api/context/types/request-context.type.d.ts +16 -0
- package/dist/api/context/types/request-context.type.js +2 -0
- package/dist/api/handlers/config.handler.d.ts +4 -0
- package/dist/api/handlers/config.handler.js +10 -0
- package/dist/api/handlers/status.handler.d.ts +25 -0
- package/dist/api/handlers/status.handler.js +73 -0
- package/dist/api/handlers/types/handler.type.d.ts +5 -0
- package/dist/api/handlers/types/handler.type.js +2 -0
- package/dist/api/hooks/session-auth.hook.d.ts +15 -0
- package/dist/api/hooks/session-auth.hook.js +31 -0
- package/dist/api/index.d.ts +5 -0
- package/dist/api/index.js +21 -0
- package/dist/commercetools/api/base-api.d.ts +7 -0
- package/dist/commercetools/api/base-api.js +22 -0
- package/dist/commercetools/api/cart-api.d.ts +8 -0
- package/dist/commercetools/api/cart-api.js +34 -0
- package/dist/commercetools/api/payment-api.d.ts +10 -0
- package/dist/commercetools/api/payment-api.js +40 -0
- package/dist/commercetools/api/root-api.d.ts +15 -0
- package/dist/commercetools/api/root-api.js +45 -0
- package/dist/commercetools/errors/ct-api.error.d.ts +13 -0
- package/dist/commercetools/errors/ct-api.error.js +17 -0
- package/dist/commercetools/index.d.ts +2 -0
- package/dist/commercetools/index.js +2 -0
- package/dist/commercetools/services/ct-cart.service.d.ts +14 -0
- package/dist/commercetools/services/ct-cart.service.js +54 -0
- package/dist/commercetools/services/ct-payment.service.d.ts +20 -0
- package/dist/commercetools/services/ct-payment.service.js +129 -0
- package/dist/commercetools/types/api.type.d.ts +32 -0
- package/dist/commercetools/types/api.type.js +2 -0
- package/dist/commercetools/types/cart.type.d.ts +21 -0
- package/dist/commercetools/types/cart.type.js +2 -0
- package/dist/commercetools/types/payment.type.d.ts +38 -0
- package/dist/commercetools/types/payment.type.js +2 -0
- package/dist/errorx/errorx.d.ts +150 -0
- package/dist/errorx/errorx.js +326 -0
- package/dist/errorx/index.d.ts +1 -0
- package/dist/errorx/index.js +17 -0
- package/dist/fetch/decorators/base.decorator.d.ts +9 -0
- package/dist/fetch/decorators/base.decorator.js +12 -0
- package/dist/fetch/decorators/monitoring.decorator.d.ts +13 -0
- package/dist/fetch/decorators/monitoring.decorator.js +32 -0
- package/dist/fetch/types/fetch.type.d.ts +6 -0
- package/dist/fetch/types/fetch.type.js +2 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +74 -0
- package/dist/logger/index.d.ts +1 -0
- package/dist/logger/index.js +17 -0
- package/dist/logger/logger.d.ts +6 -0
- package/dist/logger/logger.js +2 -0
- package/dist/security/auth/session.auth.d.ts +20 -0
- package/dist/security/auth/session.auth.js +54 -0
- package/dist/security/index.d.ts +3 -0
- package/dist/security/index.js +19 -0
- package/dist/security/services/oauth2.service.d.ts +16 -0
- package/dist/security/services/oauth2.service.js +53 -0
- package/dist/security/types/oauth2.type.d.ts +13 -0
- package/dist/security/types/oauth2.type.js +2 -0
- package/dist/security/types/session.type.d.ts +10 -0
- package/dist/security/types/session.type.js +2 -0
- package/package.json +21 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Fetch } from '../../fetch/types/fetch.type';
|
|
2
|
+
import { Logger } from '../../logger';
|
|
3
|
+
import { GetAccessTokenParams, Oauth2Service, TokenResponse } from '../types/oauth2.type';
|
|
4
|
+
export declare class DefaultOauth2Service implements Oauth2Service {
|
|
5
|
+
private authUrl;
|
|
6
|
+
private fetch;
|
|
7
|
+
private logger?;
|
|
8
|
+
constructor(opts: {
|
|
9
|
+
authUrl: string;
|
|
10
|
+
fetch: Fetch;
|
|
11
|
+
logger?: Logger;
|
|
12
|
+
});
|
|
13
|
+
private oauth2tokenCache;
|
|
14
|
+
private oauth2tokenKey;
|
|
15
|
+
getAccessToken(opts: GetAccessTokenParams): Promise<TokenResponse>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DefaultOauth2Service = void 0;
|
|
4
|
+
const errorx_1 = require("../../errorx/errorx");
|
|
5
|
+
class DefaultOauth2Service {
|
|
6
|
+
authUrl;
|
|
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}`);
|
|
30
|
+
const urlencoded = new URLSearchParams();
|
|
31
|
+
urlencoded.append('grant_type', 'client_credentials');
|
|
32
|
+
const response = await this.fetch(`${this.authUrl}/oauth/token`, {
|
|
33
|
+
method: 'POST',
|
|
34
|
+
headers: {
|
|
35
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
36
|
+
Authorization: `Basic ${encodedCredentials}`,
|
|
37
|
+
},
|
|
38
|
+
body: urlencoded,
|
|
39
|
+
});
|
|
40
|
+
if (!response.ok) {
|
|
41
|
+
throw new errorx_1.ErrorGeneral(undefined, {
|
|
42
|
+
privateMessage: 'Failed to get auth token',
|
|
43
|
+
privateFields: {
|
|
44
|
+
responseStatus: response.status,
|
|
45
|
+
responseText: await response.text(),
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
const tokenRes = (await response.json());
|
|
50
|
+
return tokenRes;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.DefaultOauth2Service = DefaultOauth2Service;
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@commercetools/connect-payments-sdk",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Payment SDK for commercetools payment connectors",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [
|
|
11
|
+
"commercetools",
|
|
12
|
+
"commercetools-connect",
|
|
13
|
+
"payments",
|
|
14
|
+
"sdk"
|
|
15
|
+
],
|
|
16
|
+
"license": "ISC",
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@commercetools/platform-sdk": "6.0.0",
|
|
19
|
+
"@commercetools/sdk-client-v2": "2.3.0"
|
|
20
|
+
}
|
|
21
|
+
}
|