@enfuce/nextgen-sdk 0.0.3 → 0.0.5

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 (40) hide show
  1. package/dist/esm/exchange-rate/api.d.ts +409 -0
  2. package/dist/esm/exchange-rate/api.js +403 -0
  3. package/dist/esm/exchange-rate/base.d.ts +42 -0
  4. package/dist/esm/exchange-rate/base.js +41 -0
  5. package/dist/esm/exchange-rate/common.d.ts +34 -0
  6. package/dist/esm/exchange-rate/common.js +126 -0
  7. package/dist/esm/exchange-rate/configuration.d.ts +98 -0
  8. package/dist/esm/exchange-rate/configuration.js +40 -0
  9. package/dist/esm/exchange-rate/index.d.ts +13 -0
  10. package/dist/esm/exchange-rate/index.js +15 -0
  11. package/dist/esm/index.d.ts +1 -0
  12. package/dist/esm/index.js +1 -0
  13. package/dist/esm/oauth/axios.d.ts +10 -4
  14. package/dist/esm/oauth/axios.js +15 -4
  15. package/dist/esm/oauth/index.js +5 -2
  16. package/dist/exchange-rate/api.d.ts +409 -0
  17. package/dist/exchange-rate/api.js +418 -0
  18. package/dist/exchange-rate/base.d.ts +42 -0
  19. package/dist/exchange-rate/base.js +46 -0
  20. package/dist/exchange-rate/common.d.ts +34 -0
  21. package/dist/exchange-rate/common.js +139 -0
  22. package/dist/exchange-rate/configuration.d.ts +98 -0
  23. package/dist/exchange-rate/configuration.js +44 -0
  24. package/dist/exchange-rate/index.d.ts +13 -0
  25. package/dist/exchange-rate/index.js +31 -0
  26. package/dist/index.d.ts +1 -0
  27. package/dist/index.js +2 -1
  28. package/dist/oauth/axios.d.ts +10 -4
  29. package/dist/oauth/axios.js +15 -4
  30. package/dist/oauth/index.js +5 -2
  31. package/package.json +1 -1
  32. package/src/exchange-rate/api.ts +615 -0
  33. package/src/exchange-rate/base.ts +62 -0
  34. package/src/exchange-rate/common.ts +127 -0
  35. package/src/exchange-rate/configuration.ts +121 -0
  36. package/src/exchange-rate/index.ts +18 -0
  37. package/src/index.ts +1 -0
  38. package/src/oauth/axios.ts +16 -4
  39. package/src/oauth/index.ts +5 -2
  40. package/test/oauth.test.ts +19 -0
@@ -0,0 +1,127 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * Exchange Rates API
5
+ * Endpoint for querying FX rates of payment scheme (including benchmark to ECB FX rates). API enables the issuer to comply with regulation (EU) 2019/518) and provide the cardholder with a better user experience by providing real-time visibility to scheme FX rates that are used for card transactions.
6
+ *
7
+ * The version of the OpenAPI document: 1
8
+ * Contact: info@enfuce.com
9
+ *
10
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
11
+ * https://openapi-generator.tech
12
+ * Do not edit the class manually.
13
+ */
14
+
15
+ import type { Configuration } from "./configuration";
16
+ import type { RequestArgs } from "./base";
17
+ import type { AxiosInstance, AxiosResponse } from 'axios';
18
+ import { RequiredError } from "./base";
19
+
20
+ export const DUMMY_BASE_URL = 'https://example.com'
21
+
22
+ /**
23
+ *
24
+ * @throws {RequiredError}
25
+ */
26
+ export const assertParamExists = function (functionName: string, paramName: string, paramValue: unknown) {
27
+ if (paramValue === null || paramValue === undefined) {
28
+ throw new RequiredError(paramName, `Required parameter ${paramName} was null or undefined when calling ${functionName}.`);
29
+ }
30
+ }
31
+
32
+ export const setApiKeyToObject = async function (object: any, keyParamName: string, configuration?: Configuration) {
33
+ if (configuration && configuration.apiKey) {
34
+ const localVarApiKeyValue = typeof configuration.apiKey === 'function'
35
+ ? await configuration.apiKey(keyParamName)
36
+ : await configuration.apiKey;
37
+ object[keyParamName] = localVarApiKeyValue;
38
+ }
39
+ }
40
+
41
+ export const setBasicAuthToObject = function (object: any, configuration?: Configuration) {
42
+ if (configuration && (configuration.username || configuration.password)) {
43
+ object["auth"] = { username: configuration.username, password: configuration.password };
44
+ }
45
+ }
46
+
47
+ export const setBearerAuthToObject = async function (object: any, configuration?: Configuration) {
48
+ if (configuration && configuration.accessToken) {
49
+ const accessToken = typeof configuration.accessToken === 'function'
50
+ ? await configuration.accessToken()
51
+ : await configuration.accessToken;
52
+ object["Authorization"] = "Bearer " + accessToken;
53
+ }
54
+ }
55
+
56
+ export const setOAuthToObject = async function (object: any, name: string, scopes: string[], configuration?: Configuration) {
57
+ if (configuration && configuration.accessToken) {
58
+ const localVarAccessTokenValue = typeof configuration.accessToken === 'function'
59
+ ? await configuration.accessToken(name, scopes)
60
+ : await configuration.accessToken;
61
+ object["Authorization"] = "Bearer " + localVarAccessTokenValue;
62
+ }
63
+ }
64
+
65
+
66
+ function setFlattenedQueryParams(urlSearchParams: URLSearchParams, parameter: any, key: string = ""): void {
67
+ if (parameter == null) return;
68
+ if (typeof parameter === "object") {
69
+ if (Array.isArray(parameter) || parameter instanceof Set) {
70
+ (parameter as any[]).forEach(item => setFlattenedQueryParams(urlSearchParams, item, key));
71
+ }
72
+ else {
73
+ Object.keys(parameter).forEach(currentKey =>
74
+ setFlattenedQueryParams(urlSearchParams, parameter[currentKey], `${key}${key !== '' ? '.' : ''}${currentKey}`)
75
+ );
76
+ }
77
+ }
78
+ else {
79
+ if (urlSearchParams.has(key)) {
80
+ urlSearchParams.append(key, parameter);
81
+ }
82
+ else {
83
+ urlSearchParams.set(key, parameter);
84
+ }
85
+ }
86
+ }
87
+
88
+ export const setSearchParams = function (url: URL, ...objects: any[]) {
89
+ const searchParams = new URLSearchParams(url.search);
90
+ setFlattenedQueryParams(searchParams, objects);
91
+ url.search = searchParams.toString();
92
+ }
93
+
94
+ /**
95
+ * JSON serialization helper function which replaces instances of unserializable types with serializable ones.
96
+ * This function will run for every key-value pair encountered by JSON.stringify while traversing an object.
97
+ * Converting a set to a string will return an empty object, so an intermediate conversion to an array is required.
98
+ */
99
+ // @ts-ignore
100
+ export const replaceWithSerializableTypeIfNeeded = function(key: string, value: any) {
101
+ if (value instanceof Set) {
102
+ return Array.from(value);
103
+ } else {
104
+ return value;
105
+ }
106
+ }
107
+
108
+ export const serializeDataIfNeeded = function (value: any, requestOptions: any, configuration?: Configuration) {
109
+ const nonString = typeof value !== 'string';
110
+ const needsSerialization = nonString && configuration && configuration.isJsonMime
111
+ ? configuration.isJsonMime(requestOptions.headers['Content-Type'])
112
+ : nonString;
113
+ return needsSerialization
114
+ ? JSON.stringify(value !== undefined ? value : {}, replaceWithSerializableTypeIfNeeded)
115
+ : (value || "");
116
+ }
117
+
118
+ export const toPathString = function (url: URL) {
119
+ return url.pathname + url.search + url.hash
120
+ }
121
+
122
+ export const createRequestFunction = function (axiosArgs: RequestArgs, globalAxios: AxiosInstance, BASE_PATH: string, configuration?: Configuration) {
123
+ return <T = unknown, R = AxiosResponse<T>>(axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => {
124
+ const axiosRequestArgs = {...axiosArgs.options, url: (axios.defaults.baseURL ? '' : configuration?.basePath ?? basePath) + axiosArgs.url};
125
+ return axios.request<T, R>(axiosRequestArgs);
126
+ };
127
+ }
@@ -0,0 +1,121 @@
1
+ /* tslint:disable */
2
+ /**
3
+ * Exchange Rates API
4
+ * Endpoint for querying FX rates of payment scheme (including benchmark to ECB FX rates). API enables the issuer to comply with regulation (EU) 2019/518) and provide the cardholder with a better user experience by providing real-time visibility to scheme FX rates that are used for card transactions.
5
+ *
6
+ * The version of the OpenAPI document: 1
7
+ * Contact: info@enfuce.com
8
+ *
9
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
10
+ * https://openapi-generator.tech
11
+ * Do not edit the class manually.
12
+ */
13
+
14
+ interface AWSv4Configuration {
15
+ options?: {
16
+ region?: string
17
+ service?: string
18
+ }
19
+ credentials?: {
20
+ accessKeyId?: string
21
+ secretAccessKey?: string,
22
+ sessionToken?: string
23
+ }
24
+ }
25
+
26
+ export interface ConfigurationParameters {
27
+ apiKey?: string | Promise<string> | ((name: string) => string) | ((name: string) => Promise<string>);
28
+ username?: string;
29
+ password?: string;
30
+ accessToken?: string | Promise<string> | ((name?: string, scopes?: string[]) => string) | ((name?: string, scopes?: string[]) => Promise<string>);
31
+ awsv4?: AWSv4Configuration;
32
+ basePath?: string;
33
+ serverIndex?: number;
34
+ baseOptions?: any;
35
+ formDataCtor?: new () => any;
36
+ }
37
+
38
+ export class Configuration {
39
+ /**
40
+ * parameter for apiKey security
41
+ * @param name security name
42
+ */
43
+ apiKey?: string | Promise<string> | ((name: string) => string) | ((name: string) => Promise<string>);
44
+ /**
45
+ * parameter for basic security
46
+ */
47
+ username?: string;
48
+ /**
49
+ * parameter for basic security
50
+ */
51
+ password?: string;
52
+ /**
53
+ * parameter for oauth2 security
54
+ * @param name security name
55
+ * @param scopes oauth2 scope
56
+ */
57
+ accessToken?: string | Promise<string> | ((name?: string, scopes?: string[]) => string) | ((name?: string, scopes?: string[]) => Promise<string>);
58
+ /**
59
+ * parameter for aws4 signature security
60
+ * @param {Object} AWS4Signature - AWS4 Signature security
61
+ * @param {string} options.region - aws region
62
+ * @param {string} options.service - name of the service.
63
+ * @param {string} credentials.accessKeyId - aws access key id
64
+ * @param {string} credentials.secretAccessKey - aws access key
65
+ * @param {string} credentials.sessionToken - aws session token
66
+ * @memberof Configuration
67
+ */
68
+ awsv4?: AWSv4Configuration;
69
+ /**
70
+ * override base path
71
+ */
72
+ basePath?: string;
73
+ /**
74
+ * override server index
75
+ */
76
+ serverIndex?: number;
77
+ /**
78
+ * base options for axios calls
79
+ */
80
+ baseOptions?: any;
81
+ /**
82
+ * The FormData constructor that will be used to create multipart form data
83
+ * requests. You can inject this here so that execution environments that
84
+ * do not support the FormData class can still run the generated client.
85
+ *
86
+ * @type {new () => FormData}
87
+ */
88
+ formDataCtor?: new () => any;
89
+
90
+ constructor(param: ConfigurationParameters = {}) {
91
+ this.apiKey = param.apiKey;
92
+ this.username = param.username;
93
+ this.password = param.password;
94
+ this.accessToken = param.accessToken;
95
+ this.awsv4 = param.awsv4;
96
+ this.basePath = param.basePath;
97
+ this.serverIndex = param.serverIndex;
98
+ this.baseOptions = {
99
+ ...param.baseOptions,
100
+ headers: {
101
+ ...param.baseOptions?.headers,
102
+ },
103
+ };
104
+ this.formDataCtor = param.formDataCtor;
105
+ }
106
+
107
+ /**
108
+ * Check if the given MIME is a JSON MIME.
109
+ * JSON MIME examples:
110
+ * application/json
111
+ * application/json; charset=UTF8
112
+ * APPLICATION/JSON
113
+ * application/vnd.company+json
114
+ * @param mime - MIME (Multipurpose Internet Mail Extensions)
115
+ * @return True if the given MIME is JSON, false otherwise.
116
+ */
117
+ public isJsonMime(mime: string): boolean {
118
+ const jsonMime: RegExp = /^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$/i;
119
+ return mime !== null && jsonMime.test(mime);
120
+ }
121
+ }
@@ -0,0 +1,18 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * Exchange Rates API
5
+ * Endpoint for querying FX rates of payment scheme (including benchmark to ECB FX rates). API enables the issuer to comply with regulation (EU) 2019/518) and provide the cardholder with a better user experience by providing real-time visibility to scheme FX rates that are used for card transactions.
6
+ *
7
+ * The version of the OpenAPI document: 1
8
+ * Contact: info@enfuce.com
9
+ *
10
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
11
+ * https://openapi-generator.tech
12
+ * Do not edit the class manually.
13
+ */
14
+
15
+
16
+ export * from "./api";
17
+ export * from "./configuration";
18
+
package/src/index.ts CHANGED
@@ -14,3 +14,4 @@ export * as threeds from './threeds';
14
14
  export * as threedsOob from './threeds-oob';
15
15
  export * as clearingFileCopy from './clearing-file-copy';
16
16
  export * as transactionEvent from './transaction-event';
17
+ export * as exchangeRate from './exchange-rate';
@@ -19,19 +19,31 @@ function stripBearer(header: string): string {
19
19
  }
20
20
 
21
21
  /**
22
- * Returns an {@link AxiosInstance} with a response interceptor that, on a `401`,
23
- * forces a token refresh and retries the request exactly once with the new bearer
24
- * token. Pass it as the third argument of a generated API class:
22
+ * Returns an {@link AxiosInstance} with OAuth bearer-token handling built in:
23
+ *
24
+ * - **Proactive:** a request interceptor attaches a fresh bearer token (from the
25
+ * {@link TokenManager}) to *every* request. This authenticates API modules whose spec declares no
26
+ * security scheme (e.g. exchange-rate), so no `accessToken` on the `Configuration` is required.
27
+ * - **Reactive:** a response interceptor, on a `401`, forces a token refresh and retries the request
28
+ * exactly once with the new bearer token.
29
+ *
30
+ * Pass it as the third argument of a generated API class:
25
31
  *
26
32
  * ```ts
27
33
  * const http = createOAuthAxios(tokens);
28
- * const config = new card.Configuration({ accessToken: () => tokens.getToken() });
34
+ * const config = new card.Configuration({ basePath });
29
35
  * const api = new card.CardApi(config, undefined, http);
30
36
  * ```
31
37
  */
32
38
  export function createOAuthAxios(manager: TokenManager, instance?: AxiosInstance): AxiosInstance {
33
39
  const http = instance ?? axios.create();
34
40
 
41
+ // Proactive: attach a fresh bearer token to every outgoing request.
42
+ http.interceptors.request.use(async (config) => {
43
+ config.headers.set('Authorization', BEARER_PREFIX + (await manager.getToken()));
44
+ return config;
45
+ });
46
+
35
47
  http.interceptors.response.use(undefined, async (error: AxiosError) => {
36
48
  const response = error.response;
37
49
  const original = error.config as RetriableConfig | undefined;
@@ -13,10 +13,13 @@
13
13
  * clientSecret: 'my-secret',
14
14
  * scopes: ['cards:read'],
15
15
  * });
16
- * const http = oauth.createOAuthAxios(tokens);
17
- * const config = new card.Configuration({ accessToken: () => tokens.getToken() });
16
+ * const http = oauth.createOAuthAxios(tokens); // attaches the token + retries on 401
17
+ * const config = new card.Configuration({ basePath: 'https://api.example.com' });
18
18
  * const api = new card.CardApi(config, undefined, http);
19
19
  *
20
+ * The same `http` instance authenticates every API module, including ones whose spec declares no
21
+ * security scheme (e.g. exchange-rate) — no `accessToken` on the `Configuration` is required.
22
+ *
20
23
  * Server-side only — a client secret must never ship to a browser.
21
24
  */
22
25
  export { AccessToken, TokenFetcher, TokenManager } from './tokenManager';
@@ -139,6 +139,25 @@ describe('clientCredentialsFetcher', () => {
139
139
  });
140
140
 
141
141
  describe('createOAuthAxios', () => {
142
+ it('proactively attaches a bearer token to a request that has no Authorization header', async () => {
143
+ const { fetch, calls } = countingFetcher();
144
+ const mgr = new TokenManager(fetch, 60, makeClock().now);
145
+
146
+ const seenAuth: (string | undefined)[] = [];
147
+ const adapter: AxiosAdapter = async (config) => {
148
+ seenAuth.push(config.headers?.Authorization as string | undefined);
149
+ return { data: { ok: true }, status: 200, statusText: 'OK', headers: {}, config };
150
+ };
151
+ const http = createOAuthAxios(mgr, axios.create({ adapter }));
152
+
153
+ // No Authorization header supplied — the SDK must attach one (as for a no-security-scheme spec).
154
+ const response = await http.request({ url: 'http://localhost/v1/ecb/currencies', method: 'get' });
155
+
156
+ expect(response.status).toBe(200);
157
+ expect(seenAuth).toEqual(['Bearer token-1']);
158
+ expect(calls.n).toBe(1);
159
+ });
160
+
142
161
  it('retries the request with a refreshed token when the first call rejects with 401', async () => {
143
162
  const { fetch } = countingFetcher();
144
163
  const mgr = new TokenManager(fetch, 60, makeClock().now);