@enfuce/nextgen-sdk 0.0.6 → 0.0.8
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/README.md +19 -6
- package/dist/authorisation-control/client.d.ts +2 -2
- package/dist/card/client.d.ts +2 -2
- package/dist/cardholder/client.d.ts +2 -2
- package/dist/cards/client.d.ts +2 -2
- package/dist/config/enfuceUrls.d.ts +20 -0
- package/dist/config/enfuceUrls.js +47 -0
- package/dist/config/index.d.ts +1 -0
- package/dist/config/index.js +22 -0
- package/dist/esm/authorisation-control/client.d.ts +2 -2
- package/dist/esm/card/client.d.ts +2 -2
- package/dist/esm/cardholder/client.d.ts +2 -2
- package/dist/esm/cards/client.d.ts +2 -2
- package/dist/esm/config/enfuceUrls.d.ts +20 -0
- package/dist/esm/config/enfuceUrls.js +40 -0
- package/dist/esm/config/index.d.ts +1 -0
- package/dist/esm/config/index.js +14 -0
- package/dist/esm/exchange-rate/client.d.ts +2 -2
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/issuer-events/client.d.ts +2 -2
- package/dist/esm/oauth/axios.d.ts +3 -3
- package/dist/esm/oauth/axios.js +1 -1
- package/dist/esm/oauth/clientCredentials.d.ts +17 -3
- package/dist/esm/oauth/clientCredentials.js +20 -4
- package/dist/esm/oauth/index.d.ts +2 -2
- package/dist/esm/oauth/index.js +1 -1
- package/dist/esm/oauth/tokenManager.d.ts +2 -2
- package/dist/esm/oauth/tokenManager.js +2 -2
- package/dist/esm/pin/client.d.ts +2 -2
- package/dist/esm/threeds/client.d.ts +2 -2
- package/dist/esm/threeds-oob/client.d.ts +2 -2
- package/dist/esm/wallet/client.d.ts +2 -2
- package/dist/exchange-rate/client.d.ts +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -1
- package/dist/issuer-events/client.d.ts +2 -2
- package/dist/oauth/axios.d.ts +3 -3
- package/dist/oauth/axios.js +1 -1
- package/dist/oauth/clientCredentials.d.ts +17 -3
- package/dist/oauth/clientCredentials.js +19 -3
- package/dist/oauth/index.d.ts +2 -2
- package/dist/oauth/index.js +2 -2
- package/dist/oauth/tokenManager.d.ts +2 -2
- package/dist/oauth/tokenManager.js +4 -4
- package/dist/pin/client.d.ts +2 -2
- package/dist/threeds/client.d.ts +2 -2
- package/dist/threeds-oob/client.d.ts +2 -2
- package/dist/wallet/client.d.ts +2 -2
- package/package.json +1 -1
- package/src/authorisation-control/client.ts +3 -3
- package/src/card/client.ts +3 -3
- package/src/cardholder/client.ts +3 -3
- package/src/cards/client.ts +3 -3
- package/src/config/enfuceUrls.ts +57 -0
- package/src/config/index.ts +21 -0
- package/src/exchange-rate/client.ts +3 -3
- package/src/index.ts +1 -0
- package/src/issuer-events/client.ts +3 -3
- package/src/oauth/axios.ts +3 -3
- package/src/oauth/clientCredentials.ts +43 -4
- package/src/oauth/index.ts +2 -2
- package/src/oauth/tokenManager.ts +2 -2
- package/src/pin/client.ts +3 -3
- package/src/threeds/client.ts +3 -3
- package/src/threeds-oob/client.ts +3 -3
- package/src/wallet/client.ts +3 -3
- package/test/clientCredentials.test.ts +20 -0
- package/test/config.test.ts +33 -0
- package/test/oauth.test.ts +12 -12
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type AxiosInstance } from 'axios';
|
|
2
|
-
import { type
|
|
2
|
+
import { type OAuthClientCredentialsManager } from '../oauth';
|
|
3
3
|
import { Configuration } from './configuration';
|
|
4
4
|
import { GetECBExchangeRateApi, GetECBSupportedCurrenciesApi, GetFXExchangeRatesApi } from './api';
|
|
5
5
|
/**
|
|
@@ -40,7 +40,7 @@ export declare class ExchangeRateClientBuilder {
|
|
|
40
40
|
/** The module's host, e.g. `https://api.<tenant>.../issuer`. */
|
|
41
41
|
baseUrl(baseUrl: string): this;
|
|
42
42
|
/** Install OAuth: a fresh bearer token on every request + reactive 401 retry. */
|
|
43
|
-
oauth(tokens:
|
|
43
|
+
oauth(tokens: OAuthClientCredentialsManager): this;
|
|
44
44
|
/**
|
|
45
45
|
* Customize the underlying axios instance — set a timeout (`http.defaults.timeout = ...`), a proxy,
|
|
46
46
|
* default headers, extra interceptors, etc. Runs after OAuth is installed. Composable: multiple
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
/* AUTO-GENERATED by scripts/generate.sh - do not edit. */
|
|
3
3
|
/* One namespaced export per API. Usage: import { card } from '@enfuce/nextgen-sdk'; */
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.exchangeRate = exports.transactionEvent = exports.clearingFileCopy = exports.threedsOob = exports.threeds = exports.cards = exports.authorisationControl = exports.issuerEvents = exports.pin = exports.cardholder = exports.wallet = exports.card = exports.oauth = void 0;
|
|
5
|
+
exports.exchangeRate = exports.transactionEvent = exports.clearingFileCopy = exports.threedsOob = exports.threeds = exports.cards = exports.authorisationControl = exports.issuerEvents = exports.pin = exports.cardholder = exports.wallet = exports.card = exports.config = exports.oauth = void 0;
|
|
6
6
|
exports.oauth = require("./oauth");
|
|
7
|
+
exports.config = require("./config");
|
|
7
8
|
exports.card = require("./card");
|
|
8
9
|
exports.wallet = require("./wallet");
|
|
9
10
|
exports.cardholder = require("./cardholder");
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type AxiosInstance } from 'axios';
|
|
2
|
-
import { type
|
|
2
|
+
import { type OAuthClientCredentialsManager } from '../oauth';
|
|
3
3
|
import { Configuration } from './configuration';
|
|
4
4
|
import { IssuerEventWebhooksApi } from './api';
|
|
5
5
|
/**
|
|
@@ -36,7 +36,7 @@ export declare class IssuerEventsClientBuilder {
|
|
|
36
36
|
/** The module's host, e.g. `https://api.<tenant>.../issuer`. */
|
|
37
37
|
baseUrl(baseUrl: string): this;
|
|
38
38
|
/** Install OAuth: a fresh bearer token on every request + reactive 401 retry. */
|
|
39
|
-
oauth(tokens:
|
|
39
|
+
oauth(tokens: OAuthClientCredentialsManager): this;
|
|
40
40
|
/**
|
|
41
41
|
* Customize the underlying axios instance — set a timeout (`http.defaults.timeout = ...`), a proxy,
|
|
42
42
|
* default headers, extra interceptors, etc. Runs after OAuth is installed. Composable: multiple
|
package/dist/oauth/axios.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { AxiosInstance } from 'axios';
|
|
2
|
-
import {
|
|
2
|
+
import { OAuthClientCredentialsManager } from './tokenManager';
|
|
3
3
|
/**
|
|
4
4
|
* Returns an {@link AxiosInstance} with OAuth bearer-token handling built in:
|
|
5
5
|
*
|
|
6
6
|
* - **Proactive:** a request interceptor attaches a fresh bearer token (from the
|
|
7
|
-
* {@link
|
|
7
|
+
* {@link OAuthClientCredentialsManager}) to *every* request. This authenticates API modules whose spec declares no
|
|
8
8
|
* security scheme (e.g. exchange-rate), so no `accessToken` on the `Configuration` is required.
|
|
9
9
|
* - **Reactive:** a response interceptor, on a `401`, forces a token refresh and retries the request
|
|
10
10
|
* exactly once with the new bearer token.
|
|
@@ -17,4 +17,4 @@ import { TokenManager } from './tokenManager';
|
|
|
17
17
|
* const api = new card.CardApi(config, undefined, http);
|
|
18
18
|
* ```
|
|
19
19
|
*/
|
|
20
|
-
export declare function createOAuthAxios(manager:
|
|
20
|
+
export declare function createOAuthAxios(manager: OAuthClientCredentialsManager, instance?: AxiosInstance): AxiosInstance;
|
package/dist/oauth/axios.js
CHANGED
|
@@ -28,7 +28,7 @@ function stripBearer(header) {
|
|
|
28
28
|
* Returns an {@link AxiosInstance} with OAuth bearer-token handling built in:
|
|
29
29
|
*
|
|
30
30
|
* - **Proactive:** a request interceptor attaches a fresh bearer token (from the
|
|
31
|
-
* {@link
|
|
31
|
+
* {@link OAuthClientCredentialsManager}) to *every* request. This authenticates API modules whose spec declares no
|
|
32
32
|
* security scheme (e.g. exchange-rate), so no `accessToken` on the `Configuration` is required.
|
|
33
33
|
* - **Reactive:** a response interceptor, on a `401`, forces a token refresh and retries the request
|
|
34
34
|
* exactly once with the new bearer token.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AxiosInstance } from 'axios';
|
|
2
|
-
import { TokenFetcher,
|
|
2
|
+
import { TokenFetcher, OAuthClientCredentialsManager } from './tokenManager';
|
|
3
3
|
/** Configuration for the OAuth2 `client_credentials` grant. */
|
|
4
4
|
export interface OAuthConfig {
|
|
5
5
|
tokenUrl: string;
|
|
@@ -14,11 +14,25 @@ export interface OAuthConfig {
|
|
|
14
14
|
/** Axios instance used for the token request. Defaults to a fresh instance. */
|
|
15
15
|
axiosInstance?: AxiosInstance;
|
|
16
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* The OAuth2 client-credentials identity — the client id/secret and requested scopes. It carries
|
|
19
|
+
* no URL: pair it with a token URL (e.g. derived from a `TenantEnvironment`) via the
|
|
20
|
+
* `clientCredentials(tokenUrl, credentials)` overload below.
|
|
21
|
+
*/
|
|
22
|
+
export interface ClientCredentials {
|
|
23
|
+
clientId: string;
|
|
24
|
+
/** May be omitted for a public client. */
|
|
25
|
+
clientSecret?: string;
|
|
26
|
+
/** Requested scopes; space-joined into a `scope` parameter. */
|
|
27
|
+
scopes?: string[];
|
|
28
|
+
}
|
|
17
29
|
/**
|
|
18
30
|
* Builds a {@link TokenFetcher} that performs the OAuth2 `client_credentials`
|
|
19
31
|
* grant: a form-encoded POST to `config.tokenUrl`, parsing `access_token` and
|
|
20
32
|
* `expires_in`. Server-side only — never ship a client secret to a browser.
|
|
21
33
|
*/
|
|
22
34
|
export declare function clientCredentialsFetcher(config: OAuthConfig): TokenFetcher;
|
|
23
|
-
/** Convenience: a caching {@link
|
|
24
|
-
export declare function clientCredentials(config: OAuthConfig, skewSeconds?: number):
|
|
35
|
+
/** Convenience: a caching {@link OAuthClientCredentialsManager} backed by the client-credentials grant. */
|
|
36
|
+
export declare function clientCredentials(config: OAuthConfig, skewSeconds?: number): OAuthClientCredentialsManager;
|
|
37
|
+
/** Convenience overload pairing a token URL with a {@link ClientCredentials} identity. */
|
|
38
|
+
export declare function clientCredentials(tokenUrl: string, credentials: ClientCredentials, skewSeconds?: number): OAuthClientCredentialsManager;
|
|
@@ -57,7 +57,23 @@ function clientCredentialsFetcher(config) {
|
|
|
57
57
|
return { accessToken: data.access_token, expiresInSeconds: (_b = data.expires_in) !== null && _b !== void 0 ? _b : 0 };
|
|
58
58
|
});
|
|
59
59
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
function clientCredentials(configOrUrl, credsOrSkew, skewSeconds = 60) {
|
|
61
|
+
var _a;
|
|
62
|
+
let config;
|
|
63
|
+
let skew;
|
|
64
|
+
if (typeof configOrUrl === 'string') {
|
|
65
|
+
const creds = credsOrSkew;
|
|
66
|
+
config = {
|
|
67
|
+
tokenUrl: configOrUrl,
|
|
68
|
+
clientId: creds.clientId,
|
|
69
|
+
clientSecret: (_a = creds.clientSecret) !== null && _a !== void 0 ? _a : '',
|
|
70
|
+
scopes: creds.scopes,
|
|
71
|
+
};
|
|
72
|
+
skew = skewSeconds;
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
config = configOrUrl;
|
|
76
|
+
skew = typeof credsOrSkew === 'number' ? credsOrSkew : 60;
|
|
77
|
+
}
|
|
78
|
+
return new tokenManager_1.OAuthClientCredentialsManager(clientCredentialsFetcher(config), skew);
|
|
63
79
|
}
|
package/dist/oauth/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { AccessToken, TokenFetcher,
|
|
2
|
-
export { OAuthConfig, clientCredentials, clientCredentialsFetcher } from './clientCredentials';
|
|
1
|
+
export { AccessToken, TokenFetcher, OAuthClientCredentialsManager } from './tokenManager';
|
|
2
|
+
export { ClientCredentials, OAuthConfig, clientCredentials, clientCredentialsFetcher } from './clientCredentials';
|
|
3
3
|
export { createOAuthAxios } from './axios';
|
package/dist/oauth/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createOAuthAxios = exports.clientCredentialsFetcher = exports.clientCredentials = exports.
|
|
3
|
+
exports.createOAuthAxios = exports.clientCredentialsFetcher = exports.clientCredentials = exports.OAuthClientCredentialsManager = void 0;
|
|
4
4
|
/*
|
|
5
5
|
* Enfuce nextgen SDK — OAuth token-management helper.
|
|
6
6
|
*
|
|
@@ -26,7 +26,7 @@ exports.createOAuthAxios = exports.clientCredentialsFetcher = exports.clientCred
|
|
|
26
26
|
* Server-side only — a client secret must never ship to a browser.
|
|
27
27
|
*/
|
|
28
28
|
var tokenManager_1 = require("./tokenManager");
|
|
29
|
-
Object.defineProperty(exports, "
|
|
29
|
+
Object.defineProperty(exports, "OAuthClientCredentialsManager", { enumerable: true, get: function () { return tokenManager_1.OAuthClientCredentialsManager; } });
|
|
30
30
|
var clientCredentials_1 = require("./clientCredentials");
|
|
31
31
|
Object.defineProperty(exports, "clientCredentials", { enumerable: true, get: function () { return clientCredentials_1.clientCredentials; } });
|
|
32
32
|
Object.defineProperty(exports, "clientCredentialsFetcher", { enumerable: true, get: function () { return clientCredentials_1.clientCredentialsFetcher; } });
|
|
@@ -11,14 +11,14 @@ export type TokenFetcher = () => Promise<AccessToken>;
|
|
|
11
11
|
* client's `Configuration`:
|
|
12
12
|
*
|
|
13
13
|
* ```ts
|
|
14
|
-
* const tokens = new
|
|
14
|
+
* const tokens = new OAuthClientCredentialsManager(fetcher);
|
|
15
15
|
* const config = new card.Configuration({ accessToken: () => tokens.getToken() });
|
|
16
16
|
* ```
|
|
17
17
|
*
|
|
18
18
|
* A token is considered expired once the clock passes `expiry - skew`. Concurrent
|
|
19
19
|
* refreshes share a single in-flight promise, so the token endpoint is hit once.
|
|
20
20
|
*/
|
|
21
|
-
export declare class
|
|
21
|
+
export declare class OAuthClientCredentialsManager {
|
|
22
22
|
private readonly fetcher;
|
|
23
23
|
private readonly skewSeconds;
|
|
24
24
|
private readonly now;
|
|
@@ -16,20 +16,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
16
16
|
});
|
|
17
17
|
};
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.
|
|
19
|
+
exports.OAuthClientCredentialsManager = void 0;
|
|
20
20
|
/**
|
|
21
21
|
* Caches an access token and refreshes it before expiry. Plug it into a generated
|
|
22
22
|
* client's `Configuration`:
|
|
23
23
|
*
|
|
24
24
|
* ```ts
|
|
25
|
-
* const tokens = new
|
|
25
|
+
* const tokens = new OAuthClientCredentialsManager(fetcher);
|
|
26
26
|
* const config = new card.Configuration({ accessToken: () => tokens.getToken() });
|
|
27
27
|
* ```
|
|
28
28
|
*
|
|
29
29
|
* A token is considered expired once the clock passes `expiry - skew`. Concurrent
|
|
30
30
|
* refreshes share a single in-flight promise, so the token endpoint is hit once.
|
|
31
31
|
*/
|
|
32
|
-
class
|
|
32
|
+
class OAuthClientCredentialsManager {
|
|
33
33
|
constructor(fetcher, skewSeconds = 60, now = Date.now) {
|
|
34
34
|
this.fetcher = fetcher;
|
|
35
35
|
this.skewSeconds = skewSeconds;
|
|
@@ -78,4 +78,4 @@ class TokenManager {
|
|
|
78
78
|
return this.inflight;
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
|
-
exports.
|
|
81
|
+
exports.OAuthClientCredentialsManager = OAuthClientCredentialsManager;
|
package/dist/pin/client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type AxiosInstance } from 'axios';
|
|
2
|
-
import { type
|
|
2
|
+
import { type OAuthClientCredentialsManager } from '../oauth';
|
|
3
3
|
import { Configuration } from './configuration';
|
|
4
4
|
import { PINOperationsUsingPKIApi, PINOperationsWithPreSharedKeyApi } from './api';
|
|
5
5
|
/**
|
|
@@ -38,7 +38,7 @@ export declare class PinClientBuilder {
|
|
|
38
38
|
/** The module's host, e.g. `https://api.<tenant>.../issuer`. */
|
|
39
39
|
baseUrl(baseUrl: string): this;
|
|
40
40
|
/** Install OAuth: a fresh bearer token on every request + reactive 401 retry. */
|
|
41
|
-
oauth(tokens:
|
|
41
|
+
oauth(tokens: OAuthClientCredentialsManager): this;
|
|
42
42
|
/**
|
|
43
43
|
* Customize the underlying axios instance — set a timeout (`http.defaults.timeout = ...`), a proxy,
|
|
44
44
|
* default headers, extra interceptors, etc. Runs after OAuth is installed. Composable: multiple
|
package/dist/threeds/client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type AxiosInstance } from 'axios';
|
|
2
|
-
import { type
|
|
2
|
+
import { type OAuthClientCredentialsManager } from '../oauth';
|
|
3
3
|
import { Configuration } from './configuration';
|
|
4
4
|
import { ThreeDSApi } from './api';
|
|
5
5
|
/**
|
|
@@ -36,7 +36,7 @@ export declare class ThreedsClientBuilder {
|
|
|
36
36
|
/** The module's host, e.g. `https://api.<tenant>.../issuer`. */
|
|
37
37
|
baseUrl(baseUrl: string): this;
|
|
38
38
|
/** Install OAuth: a fresh bearer token on every request + reactive 401 retry. */
|
|
39
|
-
oauth(tokens:
|
|
39
|
+
oauth(tokens: OAuthClientCredentialsManager): this;
|
|
40
40
|
/**
|
|
41
41
|
* Customize the underlying axios instance — set a timeout (`http.defaults.timeout = ...`), a proxy,
|
|
42
42
|
* default headers, extra interceptors, etc. Runs after OAuth is installed. Composable: multiple
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type AxiosInstance } from 'axios';
|
|
2
|
-
import { type
|
|
2
|
+
import { type OAuthClientCredentialsManager } from '../oauth';
|
|
3
3
|
import { Configuration } from './configuration';
|
|
4
4
|
import { OOBAuthenticationChallengeWebhookNotificationApi } from './api';
|
|
5
5
|
/**
|
|
@@ -36,7 +36,7 @@ export declare class ThreedsOobClientBuilder {
|
|
|
36
36
|
/** The module's host, e.g. `https://api.<tenant>.../issuer`. */
|
|
37
37
|
baseUrl(baseUrl: string): this;
|
|
38
38
|
/** Install OAuth: a fresh bearer token on every request + reactive 401 retry. */
|
|
39
|
-
oauth(tokens:
|
|
39
|
+
oauth(tokens: OAuthClientCredentialsManager): this;
|
|
40
40
|
/**
|
|
41
41
|
* Customize the underlying axios instance — set a timeout (`http.defaults.timeout = ...`), a proxy,
|
|
42
42
|
* default headers, extra interceptors, etc. Runs after OAuth is installed. Composable: multiple
|
package/dist/wallet/client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type AxiosInstance } from 'axios';
|
|
2
|
-
import { type
|
|
2
|
+
import { type OAuthClientCredentialsManager } from '../oauth';
|
|
3
3
|
import { Configuration } from './configuration';
|
|
4
4
|
import { ActivateTokenApi, DeactivateTokenApi, EligibleTokenRequestorsApi, GetTokensApi, PushCardsApi, PushProvisionApi, SuspendTokenApi, UnsuspendTokenApi } from './api';
|
|
5
5
|
/**
|
|
@@ -50,7 +50,7 @@ export declare class WalletClientBuilder {
|
|
|
50
50
|
/** The module's host, e.g. `https://api.<tenant>.../issuer`. */
|
|
51
51
|
baseUrl(baseUrl: string): this;
|
|
52
52
|
/** Install OAuth: a fresh bearer token on every request + reactive 401 retry. */
|
|
53
|
-
oauth(tokens:
|
|
53
|
+
oauth(tokens: OAuthClientCredentialsManager): this;
|
|
54
54
|
/**
|
|
55
55
|
* Customize the underlying axios instance — set a timeout (`http.defaults.timeout = ...`), a proxy,
|
|
56
56
|
* default headers, extra interceptors, etc. Runs after OAuth is installed. Composable: multiple
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* retry) to the module's Configuration and exposes each API. Nothing is shared across modules.
|
|
7
7
|
*/
|
|
8
8
|
import globalAxios, { type AxiosInstance } from 'axios';
|
|
9
|
-
import { createOAuthAxios, type
|
|
9
|
+
import { createOAuthAxios, type OAuthClientCredentialsManager } from '../oauth';
|
|
10
10
|
import { Configuration } from './configuration';
|
|
11
11
|
import {
|
|
12
12
|
AuthorisationRequestAPIApi,
|
|
@@ -50,7 +50,7 @@ export class AuthorisationControlClient {
|
|
|
50
50
|
export class AuthorisationControlClientBuilder {
|
|
51
51
|
|
|
52
52
|
private _baseUrl?: string;
|
|
53
|
-
private _tokens?:
|
|
53
|
+
private _tokens?: OAuthClientCredentialsManager;
|
|
54
54
|
private _customizers: Array<(http: AxiosInstance) => void> = [];
|
|
55
55
|
|
|
56
56
|
/** The module's host, e.g. `https://api.<tenant>.../issuer`. */
|
|
@@ -60,7 +60,7 @@ export class AuthorisationControlClientBuilder {
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
/** Install OAuth: a fresh bearer token on every request + reactive 401 retry. */
|
|
63
|
-
oauth(tokens:
|
|
63
|
+
oauth(tokens: OAuthClientCredentialsManager): this {
|
|
64
64
|
this._tokens = tokens;
|
|
65
65
|
return this;
|
|
66
66
|
}
|
package/src/card/client.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* retry) to the module's Configuration and exposes each API. Nothing is shared across modules.
|
|
7
7
|
*/
|
|
8
8
|
import globalAxios, { type AxiosInstance } from 'axios';
|
|
9
|
-
import { createOAuthAxios, type
|
|
9
|
+
import { createOAuthAxios, type OAuthClientCredentialsManager } from '../oauth';
|
|
10
10
|
import { Configuration } from './configuration';
|
|
11
11
|
import {
|
|
12
12
|
CreateCardApi,
|
|
@@ -80,7 +80,7 @@ export class CardClient {
|
|
|
80
80
|
export class CardClientBuilder {
|
|
81
81
|
|
|
82
82
|
private _baseUrl?: string;
|
|
83
|
-
private _tokens?:
|
|
83
|
+
private _tokens?: OAuthClientCredentialsManager;
|
|
84
84
|
private _customizers: Array<(http: AxiosInstance) => void> = [];
|
|
85
85
|
|
|
86
86
|
/** The module's host, e.g. `https://api.<tenant>.../issuer`. */
|
|
@@ -90,7 +90,7 @@ export class CardClientBuilder {
|
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
/** Install OAuth: a fresh bearer token on every request + reactive 401 retry. */
|
|
93
|
-
oauth(tokens:
|
|
93
|
+
oauth(tokens: OAuthClientCredentialsManager): this {
|
|
94
94
|
this._tokens = tokens;
|
|
95
95
|
return this;
|
|
96
96
|
}
|
package/src/cardholder/client.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* retry) to the module's Configuration and exposes each API. Nothing is shared across modules.
|
|
7
7
|
*/
|
|
8
8
|
import globalAxios, { type AxiosInstance } from 'axios';
|
|
9
|
-
import { createOAuthAxios, type
|
|
9
|
+
import { createOAuthAxios, type OAuthClientCredentialsManager } from '../oauth';
|
|
10
10
|
import { Configuration } from './configuration';
|
|
11
11
|
import {
|
|
12
12
|
CreateCardholderApi,
|
|
@@ -68,7 +68,7 @@ export class CardholderClient {
|
|
|
68
68
|
export class CardholderClientBuilder {
|
|
69
69
|
|
|
70
70
|
private _baseUrl?: string;
|
|
71
|
-
private _tokens?:
|
|
71
|
+
private _tokens?: OAuthClientCredentialsManager;
|
|
72
72
|
private _customizers: Array<(http: AxiosInstance) => void> = [];
|
|
73
73
|
|
|
74
74
|
/** The module's host, e.g. `https://api.<tenant>.../issuer`. */
|
|
@@ -78,7 +78,7 @@ export class CardholderClientBuilder {
|
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
/** Install OAuth: a fresh bearer token on every request + reactive 401 retry. */
|
|
81
|
-
oauth(tokens:
|
|
81
|
+
oauth(tokens: OAuthClientCredentialsManager): this {
|
|
82
82
|
this._tokens = tokens;
|
|
83
83
|
return this;
|
|
84
84
|
}
|
package/src/cards/client.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* retry) to the module's Configuration and exposes each API. Nothing is shared across modules.
|
|
7
7
|
*/
|
|
8
8
|
import globalAxios, { type AxiosInstance } from 'axios';
|
|
9
|
-
import { createOAuthAxios, type
|
|
9
|
+
import { createOAuthAxios, type OAuthClientCredentialsManager } from '../oauth';
|
|
10
10
|
import { Configuration } from './configuration';
|
|
11
11
|
import {
|
|
12
12
|
CardsApi,
|
|
@@ -50,7 +50,7 @@ export class CardsClient {
|
|
|
50
50
|
export class CardsClientBuilder {
|
|
51
51
|
|
|
52
52
|
private _baseUrl?: string;
|
|
53
|
-
private _tokens?:
|
|
53
|
+
private _tokens?: OAuthClientCredentialsManager;
|
|
54
54
|
private _customizers: Array<(http: AxiosInstance) => void> = [];
|
|
55
55
|
|
|
56
56
|
/** The module's host, e.g. `https://api.<tenant>.../issuer`. */
|
|
@@ -60,7 +60,7 @@ export class CardsClientBuilder {
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
/** Install OAuth: a fresh bearer token on every request + reactive 401 retry. */
|
|
63
|
-
oauth(tokens:
|
|
63
|
+
oauth(tokens: OAuthClientCredentialsManager): this {
|
|
64
64
|
this._tokens = tokens;
|
|
65
65
|
return this;
|
|
66
66
|
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Enfuce nextgen SDK — tenant/environment addressing helper.
|
|
3
|
+
*
|
|
4
|
+
* HAND-WRITTEN, NOT GENERATED. This module (src/config) is authored by hand and
|
|
5
|
+
* preserved across SDK regeneration (see scripts/generate.sh). Do not expect
|
|
6
|
+
* OpenAPI Generator to (re)produce it.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Identifies a single Enfuce deployment by its `tenant` and `environment` — the two variable
|
|
11
|
+
* segments of every Enfuce host, e.g. `api.<tenant>.<environment>.mycore.enfuce.com`.
|
|
12
|
+
*/
|
|
13
|
+
export interface TenantEnvironment {
|
|
14
|
+
/** Tenant segment, e.g. `swile`, `shine`, `cad`. */
|
|
15
|
+
tenant: string;
|
|
16
|
+
/** Environment segment, e.g. `ext-uat1-sandbox`, `eu.live.prod`. */
|
|
17
|
+
environment: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const DOMAIN_SUFFIX = 'mycore.enfuce.com';
|
|
21
|
+
|
|
22
|
+
function hostSuffix(te: TenantEnvironment): string {
|
|
23
|
+
const tenant = te?.tenant?.trim();
|
|
24
|
+
const environment = te?.environment?.trim();
|
|
25
|
+
if (!tenant) {
|
|
26
|
+
throw new Error('tenant must not be empty');
|
|
27
|
+
}
|
|
28
|
+
if (!environment) {
|
|
29
|
+
throw new Error('environment must not be empty');
|
|
30
|
+
}
|
|
31
|
+
return `${tenant}.${environment}.${DOMAIN_SUFFIX}`;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** `https://api.<tenant>.<environment>.mycore.enfuce.com` — the API root, no path. */
|
|
35
|
+
export function apiBaseUrl(te: TenantEnvironment): string {
|
|
36
|
+
return `https://api.${hostSuffix(te)}`;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** `.../issuer` — issuer domain (cardholder, card, wallet, pin). */
|
|
40
|
+
export function issuerBaseUrl(te: TenantEnvironment): string {
|
|
41
|
+
return `${apiBaseUrl(te)}/issuer`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** `.../processor` — processor domain (transactions, 3DS). */
|
|
45
|
+
export function processorBaseUrl(te: TenantEnvironment): string {
|
|
46
|
+
return `${apiBaseUrl(te)}/processor`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** `.../exchange-rates-api` — exchange-rate domain. */
|
|
50
|
+
export function exchangeRateBaseUrl(te: TenantEnvironment): string {
|
|
51
|
+
return `${apiBaseUrl(te)}/exchange-rates-api`;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** `https://auth.<tenant>.<environment>.mycore.enfuce.com/oauth2/token` — OAuth2 token endpoint. */
|
|
55
|
+
export function tokenUrl(te: TenantEnvironment): string {
|
|
56
|
+
return `https://auth.${hostSuffix(te)}/oauth2/token`;
|
|
57
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Enfuce nextgen SDK — tenant/environment addressing helper.
|
|
3
|
+
*
|
|
4
|
+
* HAND-WRITTEN, NOT GENERATED. This module (src/config) is authored by hand and
|
|
5
|
+
* preserved across SDK regeneration (see scripts/generate.sh). It is re-exported
|
|
6
|
+
* from the package barrel as `config`:
|
|
7
|
+
*
|
|
8
|
+
* import { config, cardholder, oauth } from '@enfuce/nextgen-sdk';
|
|
9
|
+
*
|
|
10
|
+
* const te = { tenant: 'swile', environment: 'ext-uat1-sandbox' };
|
|
11
|
+
* const conf = new cardholder.Configuration({ basePath: config.issuerBaseUrl(te) });
|
|
12
|
+
* const tokens = oauth.clientCredentials({ tokenUrl: config.tokenUrl(te), clientId, clientSecret });
|
|
13
|
+
*/
|
|
14
|
+
export {
|
|
15
|
+
TenantEnvironment,
|
|
16
|
+
apiBaseUrl,
|
|
17
|
+
issuerBaseUrl,
|
|
18
|
+
processorBaseUrl,
|
|
19
|
+
exchangeRateBaseUrl,
|
|
20
|
+
tokenUrl,
|
|
21
|
+
} from './enfuceUrls';
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* retry) to the module's Configuration and exposes each API. Nothing is shared across modules.
|
|
7
7
|
*/
|
|
8
8
|
import globalAxios, { type AxiosInstance } from 'axios';
|
|
9
|
-
import { createOAuthAxios, type
|
|
9
|
+
import { createOAuthAxios, type OAuthClientCredentialsManager } from '../oauth';
|
|
10
10
|
import { Configuration } from './configuration';
|
|
11
11
|
import {
|
|
12
12
|
GetECBExchangeRateApi,
|
|
@@ -62,7 +62,7 @@ export class ExchangeRateClient {
|
|
|
62
62
|
export class ExchangeRateClientBuilder {
|
|
63
63
|
|
|
64
64
|
private _baseUrl?: string;
|
|
65
|
-
private _tokens?:
|
|
65
|
+
private _tokens?: OAuthClientCredentialsManager;
|
|
66
66
|
private _customizers: Array<(http: AxiosInstance) => void> = [];
|
|
67
67
|
|
|
68
68
|
/** The module's host, e.g. `https://api.<tenant>.../issuer`. */
|
|
@@ -72,7 +72,7 @@ export class ExchangeRateClientBuilder {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
/** Install OAuth: a fresh bearer token on every request + reactive 401 retry. */
|
|
75
|
-
oauth(tokens:
|
|
75
|
+
oauth(tokens: OAuthClientCredentialsManager): this {
|
|
76
76
|
this._tokens = tokens;
|
|
77
77
|
return this;
|
|
78
78
|
}
|
package/src/index.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* retry) to the module's Configuration and exposes each API. Nothing is shared across modules.
|
|
7
7
|
*/
|
|
8
8
|
import globalAxios, { type AxiosInstance } from 'axios';
|
|
9
|
-
import { createOAuthAxios, type
|
|
9
|
+
import { createOAuthAxios, type OAuthClientCredentialsManager } from '../oauth';
|
|
10
10
|
import { Configuration } from './configuration';
|
|
11
11
|
import {
|
|
12
12
|
IssuerEventWebhooksApi,
|
|
@@ -50,7 +50,7 @@ export class IssuerEventsClient {
|
|
|
50
50
|
export class IssuerEventsClientBuilder {
|
|
51
51
|
|
|
52
52
|
private _baseUrl?: string;
|
|
53
|
-
private _tokens?:
|
|
53
|
+
private _tokens?: OAuthClientCredentialsManager;
|
|
54
54
|
private _customizers: Array<(http: AxiosInstance) => void> = [];
|
|
55
55
|
|
|
56
56
|
/** The module's host, e.g. `https://api.<tenant>.../issuer`. */
|
|
@@ -60,7 +60,7 @@ export class IssuerEventsClientBuilder {
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
/** Install OAuth: a fresh bearer token on every request + reactive 401 retry. */
|
|
63
|
-
oauth(tokens:
|
|
63
|
+
oauth(tokens: OAuthClientCredentialsManager): this {
|
|
64
64
|
this._tokens = tokens;
|
|
65
65
|
return this;
|
|
66
66
|
}
|
package/src/oauth/axios.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* OpenAPI Generator to (re)produce it.
|
|
7
7
|
*/
|
|
8
8
|
import axios, { AxiosError, AxiosInstance, InternalAxiosRequestConfig } from 'axios';
|
|
9
|
-
import {
|
|
9
|
+
import { OAuthClientCredentialsManager } from './tokenManager';
|
|
10
10
|
|
|
11
11
|
const BEARER_PREFIX = 'Bearer ';
|
|
12
12
|
|
|
@@ -22,7 +22,7 @@ function stripBearer(header: string): string {
|
|
|
22
22
|
* Returns an {@link AxiosInstance} with OAuth bearer-token handling built in:
|
|
23
23
|
*
|
|
24
24
|
* - **Proactive:** a request interceptor attaches a fresh bearer token (from the
|
|
25
|
-
* {@link
|
|
25
|
+
* {@link OAuthClientCredentialsManager}) to *every* request. This authenticates API modules whose spec declares no
|
|
26
26
|
* security scheme (e.g. exchange-rate), so no `accessToken` on the `Configuration` is required.
|
|
27
27
|
* - **Reactive:** a response interceptor, on a `401`, forces a token refresh and retries the request
|
|
28
28
|
* exactly once with the new bearer token.
|
|
@@ -35,7 +35,7 @@ function stripBearer(header: string): string {
|
|
|
35
35
|
* const api = new card.CardApi(config, undefined, http);
|
|
36
36
|
* ```
|
|
37
37
|
*/
|
|
38
|
-
export function createOAuthAxios(manager:
|
|
38
|
+
export function createOAuthAxios(manager: OAuthClientCredentialsManager, instance?: AxiosInstance): AxiosInstance {
|
|
39
39
|
const http = instance ?? axios.create();
|
|
40
40
|
|
|
41
41
|
// Proactive: attach a fresh bearer token to every outgoing request.
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* OpenAPI Generator to (re)produce it.
|
|
7
7
|
*/
|
|
8
8
|
import axios, { AxiosInstance, AxiosRequestConfig } from 'axios';
|
|
9
|
-
import { AccessToken, TokenFetcher,
|
|
9
|
+
import { AccessToken, TokenFetcher, OAuthClientCredentialsManager } from './tokenManager';
|
|
10
10
|
|
|
11
11
|
/** Configuration for the OAuth2 `client_credentials` grant. */
|
|
12
12
|
export interface OAuthConfig {
|
|
@@ -23,6 +23,19 @@ export interface OAuthConfig {
|
|
|
23
23
|
axiosInstance?: AxiosInstance;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
/**
|
|
27
|
+
* The OAuth2 client-credentials identity — the client id/secret and requested scopes. It carries
|
|
28
|
+
* no URL: pair it with a token URL (e.g. derived from a `TenantEnvironment`) via the
|
|
29
|
+
* `clientCredentials(tokenUrl, credentials)` overload below.
|
|
30
|
+
*/
|
|
31
|
+
export interface ClientCredentials {
|
|
32
|
+
clientId: string;
|
|
33
|
+
/** May be omitted for a public client. */
|
|
34
|
+
clientSecret?: string;
|
|
35
|
+
/** Requested scopes; space-joined into a `scope` parameter. */
|
|
36
|
+
scopes?: string[];
|
|
37
|
+
}
|
|
38
|
+
|
|
26
39
|
interface TokenResponse {
|
|
27
40
|
access_token?: string;
|
|
28
41
|
expires_in?: number;
|
|
@@ -66,7 +79,33 @@ export function clientCredentialsFetcher(config: OAuthConfig): TokenFetcher {
|
|
|
66
79
|
};
|
|
67
80
|
}
|
|
68
81
|
|
|
69
|
-
/** Convenience: a caching {@link
|
|
70
|
-
export function clientCredentials(config: OAuthConfig, skewSeconds
|
|
71
|
-
|
|
82
|
+
/** Convenience: a caching {@link OAuthClientCredentialsManager} backed by the client-credentials grant. */
|
|
83
|
+
export function clientCredentials(config: OAuthConfig, skewSeconds?: number): OAuthClientCredentialsManager;
|
|
84
|
+
/** Convenience overload pairing a token URL with a {@link ClientCredentials} identity. */
|
|
85
|
+
export function clientCredentials(
|
|
86
|
+
tokenUrl: string,
|
|
87
|
+
credentials: ClientCredentials,
|
|
88
|
+
skewSeconds?: number,
|
|
89
|
+
): OAuthClientCredentialsManager;
|
|
90
|
+
export function clientCredentials(
|
|
91
|
+
configOrUrl: OAuthConfig | string,
|
|
92
|
+
credsOrSkew?: ClientCredentials | number,
|
|
93
|
+
skewSeconds = 60,
|
|
94
|
+
): OAuthClientCredentialsManager {
|
|
95
|
+
let config: OAuthConfig;
|
|
96
|
+
let skew: number;
|
|
97
|
+
if (typeof configOrUrl === 'string') {
|
|
98
|
+
const creds = credsOrSkew as ClientCredentials;
|
|
99
|
+
config = {
|
|
100
|
+
tokenUrl: configOrUrl,
|
|
101
|
+
clientId: creds.clientId,
|
|
102
|
+
clientSecret: creds.clientSecret ?? '',
|
|
103
|
+
scopes: creds.scopes,
|
|
104
|
+
};
|
|
105
|
+
skew = skewSeconds;
|
|
106
|
+
} else {
|
|
107
|
+
config = configOrUrl;
|
|
108
|
+
skew = typeof credsOrSkew === 'number' ? credsOrSkew : 60;
|
|
109
|
+
}
|
|
110
|
+
return new OAuthClientCredentialsManager(clientCredentialsFetcher(config), skew);
|
|
72
111
|
}
|