@enfuce/nextgen-sdk 0.0.7 → 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.
Files changed (54) hide show
  1. package/README.md +19 -6
  2. package/dist/authorisation-control/client.d.ts +2 -2
  3. package/dist/card/client.d.ts +2 -2
  4. package/dist/cardholder/client.d.ts +2 -2
  5. package/dist/cards/client.d.ts +2 -2
  6. package/dist/esm/authorisation-control/client.d.ts +2 -2
  7. package/dist/esm/card/client.d.ts +2 -2
  8. package/dist/esm/cardholder/client.d.ts +2 -2
  9. package/dist/esm/cards/client.d.ts +2 -2
  10. package/dist/esm/exchange-rate/client.d.ts +2 -2
  11. package/dist/esm/issuer-events/client.d.ts +2 -2
  12. package/dist/esm/oauth/axios.d.ts +3 -3
  13. package/dist/esm/oauth/axios.js +1 -1
  14. package/dist/esm/oauth/clientCredentials.d.ts +17 -3
  15. package/dist/esm/oauth/clientCredentials.js +20 -4
  16. package/dist/esm/oauth/index.d.ts +2 -2
  17. package/dist/esm/oauth/index.js +1 -1
  18. package/dist/esm/oauth/tokenManager.d.ts +2 -2
  19. package/dist/esm/oauth/tokenManager.js +2 -2
  20. package/dist/esm/pin/client.d.ts +2 -2
  21. package/dist/esm/threeds/client.d.ts +2 -2
  22. package/dist/esm/threeds-oob/client.d.ts +2 -2
  23. package/dist/esm/wallet/client.d.ts +2 -2
  24. package/dist/exchange-rate/client.d.ts +2 -2
  25. package/dist/issuer-events/client.d.ts +2 -2
  26. package/dist/oauth/axios.d.ts +3 -3
  27. package/dist/oauth/axios.js +1 -1
  28. package/dist/oauth/clientCredentials.d.ts +17 -3
  29. package/dist/oauth/clientCredentials.js +19 -3
  30. package/dist/oauth/index.d.ts +2 -2
  31. package/dist/oauth/index.js +2 -2
  32. package/dist/oauth/tokenManager.d.ts +2 -2
  33. package/dist/oauth/tokenManager.js +4 -4
  34. package/dist/pin/client.d.ts +2 -2
  35. package/dist/threeds/client.d.ts +2 -2
  36. package/dist/threeds-oob/client.d.ts +2 -2
  37. package/dist/wallet/client.d.ts +2 -2
  38. package/package.json +1 -1
  39. package/src/authorisation-control/client.ts +3 -3
  40. package/src/card/client.ts +3 -3
  41. package/src/cardholder/client.ts +3 -3
  42. package/src/cards/client.ts +3 -3
  43. package/src/exchange-rate/client.ts +3 -3
  44. package/src/issuer-events/client.ts +3 -3
  45. package/src/oauth/axios.ts +3 -3
  46. package/src/oauth/clientCredentials.ts +43 -4
  47. package/src/oauth/index.ts +2 -2
  48. package/src/oauth/tokenManager.ts +2 -2
  49. package/src/pin/client.ts +3 -3
  50. package/src/threeds/client.ts +3 -3
  51. package/src/threeds-oob/client.ts +3 -3
  52. package/src/wallet/client.ts +3 -3
  53. package/test/clientCredentials.test.ts +20 -0
  54. package/test/oauth.test.ts +12 -12
package/README.md CHANGED
@@ -16,19 +16,22 @@ Each API is exposed under its own namespace, and every module ships a fluent `<M
16
16
  instance to the module's configuration and exposes each API:
17
17
 
18
18
  ```typescript
19
- import { oauth, card } from '@enfuce/nextgen-sdk';
19
+ import { oauth, card, config } from '@enfuce/nextgen-sdk';
20
+
21
+ // Identify the host by tenant + environment; the config helper derives every URL from it.
22
+ const te = { tenant: '<tenant>', environment: 'eu.live.prod' };
20
23
 
21
24
  // One token manager (cached client-credentials grant) — reuse it across every module.
22
- const tokens = oauth.clientCredentials({
23
- tokenUrl: 'https://auth.<tenant>.enfuce.com/oauth2/token',
25
+ const clientCredentialsManager = oauth.clientCredentials({
26
+ tokenUrl: config.tokenUrl(te),
24
27
  clientId: '<client-id>',
25
28
  clientSecret: '<client-secret>',
26
29
  scopes: ['issuer/admin.read'],
27
30
  });
28
31
 
29
32
  const client = card.CardClient.builder()
30
- .baseUrl('https://api.<tenant>.eu.live.prod.mycore.enfuce.com/issuer')
31
- .oauth(tokens) // token on every request + reactive 401 retry
33
+ .baseUrl(config.issuerBaseUrl(te))
34
+ .oauth(clientCredentialsManager) // token on every request + reactive 401 retry
32
35
  .configure((http) => { http.defaults.timeout = 10_000; }) // optional: timeout, proxy, headers …
33
36
  .build();
34
37
 
@@ -41,9 +44,19 @@ is available for every module, including ones whose spec declares no security sc
41
44
  (e.g. `exchangeRate.ExchangeRateClient`).
42
45
 
43
46
  Prefer the lower level? Build your own axios and pass it through:
44
- `oauth.createOAuthAxios(tokens, axios.create({ timeout: 10_000 }))`, then
47
+ `oauth.createOAuthAxios(clientCredentialsManager, axios.create({ timeout: 10_000 }))`, then
45
48
  `new card.GetCardApi(new card.Configuration({ basePath }), undefined, http)`.
46
49
 
50
+ Keeping the token URL separate from the client identity? Pass a `ClientCredentials` — e.g. with the
51
+ `config` helper deriving the URL:
52
+ ```typescript
53
+ const clientCredentialsManager = oauth.clientCredentials(config.tokenUrl(te), {
54
+ clientId: '<client-id>',
55
+ clientSecret: '<client-secret>',
56
+ scopes: ['issuer/admin.read'],
57
+ });
58
+ ```
59
+
47
60
  ## Available APIs
48
61
 
49
62
  - `oauth` — OAuth2 `client_credentials` token-management helper
@@ -1,5 +1,5 @@
1
1
  import { type AxiosInstance } from 'axios';
2
- import { type TokenManager } from '../oauth';
2
+ import { type OAuthClientCredentialsManager } from '../oauth';
3
3
  import { Configuration } from './configuration';
4
4
  import { AuthorisationRequestAPIApi } from './api';
5
5
  /**
@@ -36,7 +36,7 @@ export declare class AuthorisationControlClientBuilder {
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: TokenManager): this;
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 TokenManager } from '../oauth';
2
+ import { type OAuthClientCredentialsManager } from '../oauth';
3
3
  import { Configuration } from './configuration';
4
4
  import { CreateCardApi, CreatePINControlAccessTokenApi, GetCardApi, GetCardPaymentInfoApi, GetPlasticManufacturingHistoryApi, UpdateCardApi } from './api';
5
5
  /**
@@ -46,7 +46,7 @@ export declare class CardClientBuilder {
46
46
  /** The module's host, e.g. `https://api.<tenant>.../issuer`. */
47
47
  baseUrl(baseUrl: string): this;
48
48
  /** Install OAuth: a fresh bearer token on every request + reactive 401 retry. */
49
- oauth(tokens: TokenManager): this;
49
+ oauth(tokens: OAuthClientCredentialsManager): this;
50
50
  /**
51
51
  * Customize the underlying axios instance — set a timeout (`http.defaults.timeout = ...`), a proxy,
52
52
  * 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 TokenManager } from '../oauth';
2
+ import { type OAuthClientCredentialsManager } from '../oauth';
3
3
  import { Configuration } from './configuration';
4
4
  import { CreateCardholderApi, GetCardholderApi, GetCardsByCardholderIdApi, UpdateCardholderApi } from './api';
5
5
  /**
@@ -42,7 +42,7 @@ export declare class CardholderClientBuilder {
42
42
  /** The module's host, e.g. `https://api.<tenant>.../issuer`. */
43
43
  baseUrl(baseUrl: string): this;
44
44
  /** Install OAuth: a fresh bearer token on every request + reactive 401 retry. */
45
- oauth(tokens: TokenManager): this;
45
+ oauth(tokens: OAuthClientCredentialsManager): this;
46
46
  /**
47
47
  * Customize the underlying axios instance — set a timeout (`http.defaults.timeout = ...`), a proxy,
48
48
  * 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 TokenManager } from '../oauth';
2
+ import { type OAuthClientCredentialsManager } from '../oauth';
3
3
  import { Configuration } from './configuration';
4
4
  import { CardsApi } from './api';
5
5
  /**
@@ -36,7 +36,7 @@ export declare class CardsClientBuilder {
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: TokenManager): this;
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 TokenManager } from '../oauth';
2
+ import { type OAuthClientCredentialsManager } from '../oauth';
3
3
  import { Configuration } from './configuration';
4
4
  import { AuthorisationRequestAPIApi } from './api';
5
5
  /**
@@ -36,7 +36,7 @@ export declare class AuthorisationControlClientBuilder {
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: TokenManager): this;
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 TokenManager } from '../oauth';
2
+ import { type OAuthClientCredentialsManager } from '../oauth';
3
3
  import { Configuration } from './configuration';
4
4
  import { CreateCardApi, CreatePINControlAccessTokenApi, GetCardApi, GetCardPaymentInfoApi, GetPlasticManufacturingHistoryApi, UpdateCardApi } from './api';
5
5
  /**
@@ -46,7 +46,7 @@ export declare class CardClientBuilder {
46
46
  /** The module's host, e.g. `https://api.<tenant>.../issuer`. */
47
47
  baseUrl(baseUrl: string): this;
48
48
  /** Install OAuth: a fresh bearer token on every request + reactive 401 retry. */
49
- oauth(tokens: TokenManager): this;
49
+ oauth(tokens: OAuthClientCredentialsManager): this;
50
50
  /**
51
51
  * Customize the underlying axios instance — set a timeout (`http.defaults.timeout = ...`), a proxy,
52
52
  * 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 TokenManager } from '../oauth';
2
+ import { type OAuthClientCredentialsManager } from '../oauth';
3
3
  import { Configuration } from './configuration';
4
4
  import { CreateCardholderApi, GetCardholderApi, GetCardsByCardholderIdApi, UpdateCardholderApi } from './api';
5
5
  /**
@@ -42,7 +42,7 @@ export declare class CardholderClientBuilder {
42
42
  /** The module's host, e.g. `https://api.<tenant>.../issuer`. */
43
43
  baseUrl(baseUrl: string): this;
44
44
  /** Install OAuth: a fresh bearer token on every request + reactive 401 retry. */
45
- oauth(tokens: TokenManager): this;
45
+ oauth(tokens: OAuthClientCredentialsManager): this;
46
46
  /**
47
47
  * Customize the underlying axios instance — set a timeout (`http.defaults.timeout = ...`), a proxy,
48
48
  * 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 TokenManager } from '../oauth';
2
+ import { type OAuthClientCredentialsManager } from '../oauth';
3
3
  import { Configuration } from './configuration';
4
4
  import { CardsApi } from './api';
5
5
  /**
@@ -36,7 +36,7 @@ export declare class CardsClientBuilder {
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: TokenManager): this;
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 TokenManager } from '../oauth';
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: TokenManager): this;
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
@@ -1,5 +1,5 @@
1
1
  import { type AxiosInstance } from 'axios';
2
- import { type TokenManager } from '../oauth';
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: TokenManager): this;
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,10 +1,10 @@
1
1
  import { AxiosInstance } from 'axios';
2
- import { TokenManager } from './tokenManager';
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 TokenManager}) to *every* request. This authenticates API modules whose spec declares no
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: TokenManager, instance?: AxiosInstance): AxiosInstance;
20
+ export declare function createOAuthAxios(manager: OAuthClientCredentialsManager, instance?: AxiosInstance): AxiosInstance;
@@ -25,7 +25,7 @@ function stripBearer(header) {
25
25
  * Returns an {@link AxiosInstance} with OAuth bearer-token handling built in:
26
26
  *
27
27
  * - **Proactive:** a request interceptor attaches a fresh bearer token (from the
28
- * {@link TokenManager}) to *every* request. This authenticates API modules whose spec declares no
28
+ * {@link OAuthClientCredentialsManager}) to *every* request. This authenticates API modules whose spec declares no
29
29
  * security scheme (e.g. exchange-rate), so no `accessToken` on the `Configuration` is required.
30
30
  * - **Reactive:** a response interceptor, on a `401`, forces a token refresh and retries the request
31
31
  * exactly once with the new bearer token.
@@ -1,5 +1,5 @@
1
1
  import { AxiosInstance } from 'axios';
2
- import { TokenFetcher, TokenManager } from './tokenManager';
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 TokenManager} backed by the client-credentials grant. */
24
- export declare function clientCredentials(config: OAuthConfig, skewSeconds?: number): TokenManager;
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;
@@ -15,7 +15,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
15
15
  * OpenAPI Generator to (re)produce it.
16
16
  */
17
17
  import axios from 'axios';
18
- import { TokenManager } from './tokenManager';
18
+ import { OAuthClientCredentialsManager } from './tokenManager';
19
19
  /**
20
20
  * Builds a {@link TokenFetcher} that performs the OAuth2 `client_credentials`
21
21
  * grant: a form-encoded POST to `config.tokenUrl`, parsing `access_token` and
@@ -53,7 +53,23 @@ export function clientCredentialsFetcher(config) {
53
53
  return { accessToken: data.access_token, expiresInSeconds: (_b = data.expires_in) !== null && _b !== void 0 ? _b : 0 };
54
54
  });
55
55
  }
56
- /** Convenience: a caching {@link TokenManager} backed by the client-credentials grant. */
57
- export function clientCredentials(config, skewSeconds = 60) {
58
- return new TokenManager(clientCredentialsFetcher(config), skewSeconds);
56
+ export function clientCredentials(configOrUrl, credsOrSkew, skewSeconds = 60) {
57
+ var _a;
58
+ let config;
59
+ let skew;
60
+ if (typeof configOrUrl === 'string') {
61
+ const creds = credsOrSkew;
62
+ config = {
63
+ tokenUrl: configOrUrl,
64
+ clientId: creds.clientId,
65
+ clientSecret: (_a = creds.clientSecret) !== null && _a !== void 0 ? _a : '',
66
+ scopes: creds.scopes,
67
+ };
68
+ skew = skewSeconds;
69
+ }
70
+ else {
71
+ config = configOrUrl;
72
+ skew = typeof credsOrSkew === 'number' ? credsOrSkew : 60;
73
+ }
74
+ return new OAuthClientCredentialsManager(clientCredentialsFetcher(config), skew);
59
75
  }
@@ -1,3 +1,3 @@
1
- export { AccessToken, TokenFetcher, TokenManager } from './tokenManager';
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';
@@ -22,6 +22,6 @@
22
22
  *
23
23
  * Server-side only — a client secret must never ship to a browser.
24
24
  */
25
- export { TokenManager } from './tokenManager';
25
+ export { OAuthClientCredentialsManager } from './tokenManager';
26
26
  export { clientCredentials, clientCredentialsFetcher } from './clientCredentials';
27
27
  export { createOAuthAxios } from './axios';
@@ -11,14 +11,14 @@ export type TokenFetcher = () => Promise<AccessToken>;
11
11
  * client's `Configuration`:
12
12
  *
13
13
  * ```ts
14
- * const tokens = new TokenManager(fetcher);
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 TokenManager {
21
+ export declare class OAuthClientCredentialsManager {
22
22
  private readonly fetcher;
23
23
  private readonly skewSeconds;
24
24
  private readonly now;
@@ -19,14 +19,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
19
19
  * client's `Configuration`:
20
20
  *
21
21
  * ```ts
22
- * const tokens = new TokenManager(fetcher);
22
+ * const tokens = new OAuthClientCredentialsManager(fetcher);
23
23
  * const config = new card.Configuration({ accessToken: () => tokens.getToken() });
24
24
  * ```
25
25
  *
26
26
  * A token is considered expired once the clock passes `expiry - skew`. Concurrent
27
27
  * refreshes share a single in-flight promise, so the token endpoint is hit once.
28
28
  */
29
- export class TokenManager {
29
+ export class OAuthClientCredentialsManager {
30
30
  constructor(fetcher, skewSeconds = 60, now = Date.now) {
31
31
  this.fetcher = fetcher;
32
32
  this.skewSeconds = skewSeconds;
@@ -1,5 +1,5 @@
1
1
  import { type AxiosInstance } from 'axios';
2
- import { type TokenManager } from '../oauth';
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: TokenManager): this;
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
@@ -1,5 +1,5 @@
1
1
  import { type AxiosInstance } from 'axios';
2
- import { type TokenManager } from '../oauth';
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: TokenManager): this;
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 TokenManager } from '../oauth';
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: TokenManager): this;
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 TokenManager } from '../oauth';
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: TokenManager): this;
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
@@ -1,5 +1,5 @@
1
1
  import { type AxiosInstance } from 'axios';
2
- import { type TokenManager } from '../oauth';
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: TokenManager): this;
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
@@ -1,5 +1,5 @@
1
1
  import { type AxiosInstance } from 'axios';
2
- import { type TokenManager } from '../oauth';
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: TokenManager): this;
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,10 +1,10 @@
1
1
  import { AxiosInstance } from 'axios';
2
- import { TokenManager } from './tokenManager';
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 TokenManager}) to *every* request. This authenticates API modules whose spec declares no
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: TokenManager, instance?: AxiosInstance): AxiosInstance;
20
+ export declare function createOAuthAxios(manager: OAuthClientCredentialsManager, instance?: AxiosInstance): AxiosInstance;
@@ -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 TokenManager}) to *every* request. This authenticates API modules whose spec declares no
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, TokenManager } from './tokenManager';
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 TokenManager} backed by the client-credentials grant. */
24
- export declare function clientCredentials(config: OAuthConfig, skewSeconds?: number): TokenManager;
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
- /** Convenience: a caching {@link TokenManager} backed by the client-credentials grant. */
61
- function clientCredentials(config, skewSeconds = 60) {
62
- return new tokenManager_1.TokenManager(clientCredentialsFetcher(config), skewSeconds);
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
  }
@@ -1,3 +1,3 @@
1
- export { AccessToken, TokenFetcher, TokenManager } from './tokenManager';
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';
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createOAuthAxios = exports.clientCredentialsFetcher = exports.clientCredentials = exports.TokenManager = void 0;
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, "TokenManager", { enumerable: true, get: function () { return tokenManager_1.TokenManager; } });
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 TokenManager(fetcher);
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 TokenManager {
21
+ export declare class OAuthClientCredentialsManager {
22
22
  private readonly fetcher;
23
23
  private readonly skewSeconds;
24
24
  private readonly now;