@mft/moneyhub-api-client 6.93.1 → 6.95.0
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/.vscode/settings.json +3 -0
- package/CHANGELOG.md +11 -1
- package/README.md +42 -0
- package/dist/discovery.d.ts +75 -0
- package/dist/discovery.d.ts.map +1 -0
- package/dist/discovery.js +169 -0
- package/dist/discovery.js.map +1 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +61 -24
- package/dist/index.js.map +1 -1
- package/dist/oidc-config.d.ts +17 -0
- package/dist/oidc-config.d.ts.map +1 -0
- package/dist/oidc-config.js +44 -0
- package/dist/oidc-config.js.map +1 -0
- package/dist/request.d.ts +11 -3
- package/dist/request.d.ts.map +1 -1
- package/dist/request.js +38 -7
- package/dist/request.js.map +1 -1
- package/dist/requests/caas/accounts.d.ts +5 -0
- package/dist/requests/caas/accounts.d.ts.map +1 -0
- package/dist/requests/caas/accounts.js +17 -0
- package/dist/requests/caas/accounts.js.map +1 -0
- package/dist/requests/caas/categories.d.ts +5 -0
- package/dist/requests/caas/categories.d.ts.map +1 -0
- package/dist/requests/caas/categories.js +26 -0
- package/dist/requests/caas/categories.js.map +1 -0
- package/dist/requests/caas/counterparties.d.ts +5 -0
- package/dist/requests/caas/counterparties.d.ts.map +1 -0
- package/dist/requests/caas/counterparties.js +18 -0
- package/dist/requests/caas/counterparties.js.map +1 -0
- package/dist/requests/caas/geotags.d.ts +5 -0
- package/dist/requests/caas/geotags.d.ts.map +1 -0
- package/dist/requests/caas/geotags.js +18 -0
- package/dist/requests/caas/geotags.js.map +1 -0
- package/dist/requests/caas/transactions.d.ts +5 -0
- package/dist/requests/caas/transactions.d.ts.map +1 -0
- package/dist/requests/caas/transactions.js +46 -0
- package/dist/requests/caas/transactions.js.map +1 -0
- package/dist/requests/caas/types/accounts.d.ts +7 -0
- package/dist/requests/caas/types/accounts.d.ts.map +1 -0
- package/dist/requests/{types/pay-file.js → caas/types/accounts.js} +1 -1
- package/dist/requests/caas/types/accounts.js.map +1 -0
- package/dist/requests/caas/types/categories.d.ts +17 -0
- package/dist/requests/caas/types/categories.d.ts.map +1 -0
- package/dist/requests/caas/types/categories.js +3 -0
- package/dist/requests/caas/types/categories.js.map +1 -0
- package/dist/requests/caas/types/counterparties.d.ts +9 -0
- package/dist/requests/caas/types/counterparties.d.ts.map +1 -0
- package/dist/requests/caas/types/counterparties.js +3 -0
- package/dist/requests/caas/types/counterparties.js.map +1 -0
- package/dist/requests/caas/types/geotags.d.ts +8 -0
- package/dist/requests/caas/types/geotags.d.ts.map +1 -0
- package/dist/{schema/pay-file.js → requests/caas/types/geotags.js} +1 -1
- package/dist/requests/caas/types/geotags.js.map +1 -0
- package/dist/requests/caas/types/transactions.d.ts +97 -0
- package/dist/requests/caas/types/transactions.d.ts.map +1 -0
- package/dist/requests/caas/types/transactions.js +3 -0
- package/dist/requests/caas/types/transactions.js.map +1 -0
- package/dist/requests/caas/types/users.d.ts +7 -0
- package/dist/requests/caas/types/users.d.ts.map +1 -0
- package/dist/requests/caas/types/users.js +3 -0
- package/dist/requests/caas/types/users.js.map +1 -0
- package/dist/requests/caas/users.d.ts +5 -0
- package/dist/requests/caas/users.d.ts.map +1 -0
- package/dist/requests/caas/users.js +17 -0
- package/dist/requests/caas/users.js.map +1 -0
- package/dist/requests/consent-history.d.ts +5 -0
- package/dist/requests/consent-history.d.ts.map +1 -0
- package/dist/requests/consent-history.js +17 -0
- package/dist/requests/consent-history.js.map +1 -0
- package/dist/requests/index.d.ts +45 -0
- package/dist/requests/index.d.ts.map +1 -1
- package/dist/requests/index.js +14 -0
- package/dist/requests/index.js.map +1 -1
- package/dist/requests/recurring-payments.d.ts.map +1 -1
- package/dist/requests/recurring-payments.js +8 -0
- package/dist/requests/recurring-payments.js.map +1 -1
- package/dist/requests/standard-financial-statements.d.ts +5 -0
- package/dist/requests/standard-financial-statements.d.ts.map +1 -0
- package/dist/requests/standard-financial-statements.js +23 -0
- package/dist/requests/standard-financial-statements.js.map +1 -0
- package/dist/requests/transactions.d.ts.map +1 -1
- package/dist/requests/transactions.js +15 -0
- package/dist/requests/transactions.js.map +1 -1
- package/dist/requests/types/consent-history.d.ts +6 -0
- package/dist/requests/types/consent-history.d.ts.map +1 -0
- package/dist/requests/types/consent-history.js +3 -0
- package/dist/requests/types/consent-history.js.map +1 -0
- package/dist/requests/types/recurring-payments.d.ts +5 -1
- package/dist/requests/types/recurring-payments.d.ts.map +1 -1
- package/dist/requests/types/standard-financial-statements.d.ts +17 -0
- package/dist/requests/types/standard-financial-statements.d.ts.map +1 -0
- package/dist/requests/types/standard-financial-statements.js +3 -0
- package/dist/requests/types/standard-financial-statements.js.map +1 -0
- package/dist/requests/types/transactions.d.ts +9 -1
- package/dist/requests/types/transactions.d.ts.map +1 -1
- package/dist/requests/unauthenticated.d.ts.map +1 -1
- package/dist/requests/unauthenticated.js +2 -2
- package/dist/requests/unauthenticated.js.map +1 -1
- package/dist/requests/users-and-connections.d.ts.map +1 -1
- package/dist/requests/users-and-connections.js +2 -1
- package/dist/requests/users-and-connections.js.map +1 -1
- package/dist/schema/config.d.ts +13 -0
- package/dist/schema/config.d.ts.map +1 -1
- package/dist/schema/consent-history.d.ts +31 -0
- package/dist/schema/consent-history.d.ts.map +1 -0
- package/dist/schema/consent-history.js +3 -0
- package/dist/schema/consent-history.js.map +1 -0
- package/dist/schema/payment.d.ts +11 -0
- package/dist/schema/payment.d.ts.map +1 -1
- package/dist/schema/scim-user.d.ts +4 -0
- package/dist/schema/scim-user.d.ts.map +1 -1
- package/dist/schema/standard-financial-statement.d.ts +21 -0
- package/dist/schema/standard-financial-statement.d.ts.map +1 -0
- package/dist/schema/standard-financial-statement.js +3 -0
- package/dist/schema/standard-financial-statement.js.map +1 -0
- package/dist/schema/statement.d.ts.map +1 -1
- package/dist/schema/statement.js +1 -0
- package/dist/schema/statement.js.map +1 -1
- package/dist/schema/transaction.d.ts +10 -2
- package/dist/schema/transaction.d.ts.map +1 -1
- package/dist/tokens.js +1 -1
- package/dist/tokens.js.map +1 -1
- package/docs/readme.md +2430 -0
- package/package.json +6 -3
- package/readme.md +235 -11
- package/dist/requests/pay-file.d.ts +0 -5
- package/dist/requests/pay-file.d.ts.map +0 -1
- package/dist/requests/pay-file.js +0 -23
- package/dist/requests/pay-file.js.map +0 -1
- package/dist/requests/types/pay-file.d.ts +0 -11
- package/dist/requests/types/pay-file.d.ts.map +0 -1
- package/dist/requests/types/pay-file.js.map +0 -1
- package/dist/schema/pay-file.d.ts +0 -16
- package/dist/schema/pay-file.d.ts.map +0 -1
- package/dist/schema/pay-file.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
6.95.0 / 2026-02-23
|
|
2
|
+
==========
|
|
3
|
+
|
|
4
|
+
**Features**
|
|
5
|
+
|
|
6
|
+
* **Gateway behaviour**: When `gatewayIdentityServiceUrl` is set, discovery is fetched from it and endpoint URLs in the document are rewritten to that base (discovery `issuer` is left unchanged for JWT validation). When `gatewayResourceServerUrl`, `gatewayCaasResourceServerUrl`, or `gatewayOsipResourceServerUrl` is set, the client uses that URL for that API and rewrites response link URLs in the response body to it. When `gatewayAccountConnectUrl` is set, the client uses that URL for the account-connect API (request routing only; link rewriting applies to resource server, CaaS, and OSIP only). When a gateway URL is not set for a resource, no rewriting occurs for that resource.
|
|
7
|
+
* `getOpenIdConfig()` uses a TTL cache backed by `@isaacs/ttlcache` (configurable via `options.openIdConfigCacheTtlMs`) and returns discovery with endpoint URLs rewritten to `gatewayIdentityServiceUrl` only when that option is set.
|
|
8
|
+
* Identity URLs are detected for versioning via the effective identity base (no hardcoded path prefix list); when provided, any request URL under that base does not have an API version segment added.
|
|
9
|
+
* See the readme section **Using the client behind a gateway** for configuration, verification, and security notes.
|
|
10
|
+
|
|
1
11
|
6.91.0 / 2025-05-01
|
|
2
12
|
==================
|
|
3
13
|
|
|
@@ -172,7 +182,7 @@
|
|
|
172
182
|
**Breaking Changes**
|
|
173
183
|
|
|
174
184
|
* Normalisation of all methods to use object destructuring to pass parameters. Please refer to the docs of each method when migrating to this version
|
|
175
|
-
* Delete methods only return the status code when
|
|
185
|
+
* Delete methods only return the status code when successful
|
|
176
186
|
* All methods to retrieve data return the body response as json, on previous versions some methods were returning the full response from the got library.
|
|
177
187
|
* When our API response code is not 2xx an HTTP error is thrown. Includes a response property with more information.
|
|
178
188
|
* Removal of all the methods with the suffix `WithToken`. To migrate to this version you can use the method with the same name but without the suffix. e.g `getUserConnectionsWithToken()` => `getUserConnections()`
|
package/README.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Moneyhub API Client
|
|
2
|
+
|
|
3
|
+
Node.js client for the [Moneyhub API](https://docs.moneyhubenterprise.com/docs).
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @mft/moneyhub-api-client
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick start
|
|
12
|
+
|
|
13
|
+
```javascript
|
|
14
|
+
const { Moneyhub } = require("@mft/moneyhub-api-client");
|
|
15
|
+
|
|
16
|
+
const moneyhub = await Moneyhub({
|
|
17
|
+
resourceServerUrl: "https://api.moneyhub.co.uk/v3",
|
|
18
|
+
identityServiceUrl: "https://identity.moneyhub.co.uk",
|
|
19
|
+
client: {
|
|
20
|
+
client_id: "your client id",
|
|
21
|
+
client_secret: "your client secret",
|
|
22
|
+
token_endpoint_auth_method: "client_secret_basic",
|
|
23
|
+
id_token_signed_response_alg: "RS256",
|
|
24
|
+
request_object_signing_alg: "none",
|
|
25
|
+
redirect_uri: "https://your-redirect-uri",
|
|
26
|
+
response_type: "code",
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const accounts = await moneyhub.getAccounts({
|
|
31
|
+
userId: "user-id",
|
|
32
|
+
params: {},
|
|
33
|
+
}, {});
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Documentation
|
|
37
|
+
|
|
38
|
+
Full API documentation, upgrade guides, configuration options, and examples are in **[docs/readme.md](docs/readme.md)**.
|
|
39
|
+
|
|
40
|
+
## Changelog
|
|
41
|
+
|
|
42
|
+
[CHANGELOG.md](CHANGELOG.md)
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { Agents } from "got";
|
|
2
|
+
import type { MutualTLSOptions } from "./schema/config";
|
|
3
|
+
export interface DiscoveryOptions {
|
|
4
|
+
timeout?: number;
|
|
5
|
+
agent?: Agents;
|
|
6
|
+
mTLS?: MutualTLSOptions;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Rewrites any string value in a value (object, array, or primitive) that starts with
|
|
10
|
+
* canonicalBase to use targetBase instead. Does not mutate the original.
|
|
11
|
+
* Used for both OIDC discovery documents and resource server response bodies (e.g. links).
|
|
12
|
+
* @param {*} value - Object, array or primitive to rewrite
|
|
13
|
+
* @param {string} canonicalBase - Base URL to replace
|
|
14
|
+
* @param {string} targetBase - Base URL to use instead
|
|
15
|
+
* @returns {*} A copy of value with matching URLs rewritten
|
|
16
|
+
*/
|
|
17
|
+
export declare function rewriteUrlsInObject<T>(value: T, canonicalBase: string, targetBase: string): T;
|
|
18
|
+
/**
|
|
19
|
+
* Rewrites URL fields in an OIDC discovery document so that endpoint URLs use the
|
|
20
|
+
* target base. Leaves the discovery "issuer" field unchanged so that JWT iss claim
|
|
21
|
+
* validation continues to work when the IdP still issues tokens with the canonical issuer.
|
|
22
|
+
* @param {Object} doc - OIDC discovery document
|
|
23
|
+
* @param {string} canonicalBase - Base URL to replace
|
|
24
|
+
* @param {string} targetBase - Base URL to use instead
|
|
25
|
+
* @returns {Object} Discovery document with endpoint URLs rewritten
|
|
26
|
+
*/
|
|
27
|
+
export declare function rewriteDiscoveryUrls(doc: Record<string, unknown>, canonicalBase: string, targetBase: string): Record<string, unknown>;
|
|
28
|
+
export interface OpenIDDiscoveryMetadata {
|
|
29
|
+
issuer: string;
|
|
30
|
+
authorization_endpoint?: string;
|
|
31
|
+
token_endpoint?: string;
|
|
32
|
+
jwks_uri?: string;
|
|
33
|
+
[key: string]: unknown;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Rewrites a discovery document so endpoint URLs use the identity service base (e.g. gateway).
|
|
37
|
+
* Single source of truth for canonical/target computation; used by both initial fetch and cache refresh.
|
|
38
|
+
* @param {string} identityServiceUrl - Identity service base URL (e.g. gateway or https://identity.moneyhub.co.uk)
|
|
39
|
+
* @param {Record<string, unknown>} doc - Raw OIDC discovery document
|
|
40
|
+
* @returns {Record<string, unknown>} Discovery document with endpoint URLs rewritten (issuer unchanged)
|
|
41
|
+
*/
|
|
42
|
+
export declare function rewriteDiscoveryDocForIdentityUrl(identityServiceUrl: string, doc: Record<string, unknown>): Record<string, unknown>;
|
|
43
|
+
/**
|
|
44
|
+
* Fetches the raw OpenID discovery document from identityServiceUrl/oidc (no URL rewriting).
|
|
45
|
+
* @param {string} identityServiceUrl - Identity service base URL
|
|
46
|
+
* @param {DiscoveryOptions} options - Optional timeout, agent or mTLS settings
|
|
47
|
+
* @returns {Promise<OpenIDDiscoveryMetadata>} Raw OpenID discovery metadata
|
|
48
|
+
*/
|
|
49
|
+
export declare function getDiscovery(identityServiceUrl: string, options?: DiscoveryOptions): Promise<OpenIDDiscoveryMetadata>;
|
|
50
|
+
/**
|
|
51
|
+
* Fetches the OpenID discovery document from identityServiceUrl/oidc and rewrites
|
|
52
|
+
* all endpoint URLs (but not the issuer field) to use the configured identity service url, so that
|
|
53
|
+
* when used behind a gateway all OIDC traffic goes through the gateway.
|
|
54
|
+
* @param {string} identityServiceUrl - Identity service URL (e.g. https://identity.moneyhub.co.uk)
|
|
55
|
+
* @param {DiscoveryOptions} options - Optional timeout, agent or mTLS settings
|
|
56
|
+
* @returns {Promise<OpenIDDiscoveryMetadata>} OpenID discovery metadata with URLs rewritten for the gateway
|
|
57
|
+
*/
|
|
58
|
+
export declare function getDiscoveryWithGatewayUrl(identityServiceUrl: string, options?: DiscoveryOptions): Promise<OpenIDDiscoveryMetadata>;
|
|
59
|
+
/**
|
|
60
|
+
* Infers the canonical API base from a response link URL (e.g. links.self) by taking
|
|
61
|
+
* origin and path up to and including the version segment (e.g. /v3).
|
|
62
|
+
* @param {string} linkUrl - Full link URL from a resource response
|
|
63
|
+
* @returns {string|null} Canonical base URL or null if it cannot be inferred
|
|
64
|
+
*/
|
|
65
|
+
export declare function inferCanonicalBaseFromLinkUrl(linkUrl: string): string | null;
|
|
66
|
+
/**
|
|
67
|
+
* Rewrites URL strings in a resource server response body (e.g. links.self, links.next,
|
|
68
|
+
* links.prev) so that any canonical API base is replaced with resourceServerUrl.
|
|
69
|
+
* Returns the body unchanged if no links or no canonical base can be inferred.
|
|
70
|
+
* @param {*} body - Resource server response body (typically with a links property)
|
|
71
|
+
* @param {string} resourceServerUrl - Base URL for the resource server (e.g. gateway URL)
|
|
72
|
+
* @returns {*} Body with link URLs rewritten to use resourceServerUrl
|
|
73
|
+
*/
|
|
74
|
+
export declare function rewriteResourceServerResponseUrls<T>(body: T, resourceServerUrl: string): T;
|
|
75
|
+
//# sourceMappingURL=discovery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../src/discovery.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,KAAK,CAAA;AAC/B,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,iBAAiB,CAAA;AAErD,MAAM,WAAW,gBAAgB;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,gBAAgB,CAAA;CACxB;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EACnC,KAAK,EAAE,CAAC,EACR,aAAa,EAAE,MAAM,EACrB,UAAU,EAAE,MAAM,GACjB,CAAC,CAuBH;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,aAAa,EAAE,MAAM,EACrB,UAAU,EAAE,MAAM,GACjB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAYzB;AAED,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,MAAM,CAAA;IACd,sBAAsB,CAAC,EAAE,MAAM,CAAA;IAC/B,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB;AAUD;;;;;;GAMG;AACH,wBAAgB,iCAAiC,CAC/C,kBAAkB,EAAE,MAAM,EAC1B,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC3B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAMzB;AAED;;;;;GAKG;AACH,wBAAsB,YAAY,CAChC,kBAAkB,EAAE,MAAM,EAC1B,OAAO,GAAE,gBAAqB,GAC7B,OAAO,CAAC,uBAAuB,CAAC,CAkBlC;AAED;;;;;;;GAOG;AACH,wBAAsB,0BAA0B,CAC9C,kBAAkB,EAAE,MAAM,EAC1B,OAAO,GAAE,gBAAqB,GAC7B,OAAO,CAAC,uBAAuB,CAAC,CAIlC;AAED;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAa5E;AAED;;;;;;;GAOG;AACH,wBAAgB,iCAAiC,CAAC,CAAC,EACjD,IAAI,EAAE,CAAC,EACP,iBAAiB,EAAE,MAAM,GACxB,CAAC,CAaH"}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.rewriteResourceServerResponseUrls = exports.inferCanonicalBaseFromLinkUrl = exports.getDiscoveryWithGatewayUrl = exports.getDiscovery = exports.rewriteDiscoveryDocForIdentityUrl = exports.rewriteDiscoveryUrls = exports.rewriteUrlsInObject = void 0;
|
|
7
|
+
const got_1 = __importDefault(require("got"));
|
|
8
|
+
/**
|
|
9
|
+
* Rewrites any string value in a value (object, array, or primitive) that starts with
|
|
10
|
+
* canonicalBase to use targetBase instead. Does not mutate the original.
|
|
11
|
+
* Used for both OIDC discovery documents and resource server response bodies (e.g. links).
|
|
12
|
+
* @param {*} value - Object, array or primitive to rewrite
|
|
13
|
+
* @param {string} canonicalBase - Base URL to replace
|
|
14
|
+
* @param {string} targetBase - Base URL to use instead
|
|
15
|
+
* @returns {*} A copy of value with matching URLs rewritten
|
|
16
|
+
*/
|
|
17
|
+
function rewriteUrlsInObject(value, canonicalBase, targetBase) {
|
|
18
|
+
if (canonicalBase === targetBase)
|
|
19
|
+
return value;
|
|
20
|
+
if (typeof value === "string") {
|
|
21
|
+
if (value.startsWith(canonicalBase)) {
|
|
22
|
+
return (targetBase + value.slice(canonicalBase.length));
|
|
23
|
+
}
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
if (Array.isArray(value)) {
|
|
27
|
+
return value.map((item) => rewriteUrlsInObject(item, canonicalBase, targetBase));
|
|
28
|
+
}
|
|
29
|
+
if (value !== null && typeof value === "object") {
|
|
30
|
+
const out = {};
|
|
31
|
+
for (const [k, v] of Object.entries(value)) {
|
|
32
|
+
out[k] = rewriteUrlsInObject(v, canonicalBase, targetBase);
|
|
33
|
+
}
|
|
34
|
+
return out;
|
|
35
|
+
}
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
exports.rewriteUrlsInObject = rewriteUrlsInObject;
|
|
39
|
+
/**
|
|
40
|
+
* Rewrites URL fields in an OIDC discovery document so that endpoint URLs use the
|
|
41
|
+
* target base. Leaves the discovery "issuer" field unchanged so that JWT iss claim
|
|
42
|
+
* validation continues to work when the IdP still issues tokens with the canonical issuer.
|
|
43
|
+
* @param {Object} doc - OIDC discovery document
|
|
44
|
+
* @param {string} canonicalBase - Base URL to replace
|
|
45
|
+
* @param {string} targetBase - Base URL to use instead
|
|
46
|
+
* @returns {Object} Discovery document with endpoint URLs rewritten
|
|
47
|
+
*/
|
|
48
|
+
function rewriteDiscoveryUrls(doc, canonicalBase, targetBase) {
|
|
49
|
+
if (canonicalBase === targetBase)
|
|
50
|
+
return doc;
|
|
51
|
+
const result = {};
|
|
52
|
+
for (const [key, val] of Object.entries(doc)) {
|
|
53
|
+
if (key === "issuer" && typeof val === "string") {
|
|
54
|
+
result[key] = val;
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
result[key] = rewriteUrlsInObject(val, canonicalBase, targetBase);
|
|
58
|
+
}
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
61
|
+
exports.rewriteDiscoveryUrls = rewriteDiscoveryUrls;
|
|
62
|
+
/**
|
|
63
|
+
* Normalised OIDC base for the given identity service URL (no trailing slash).
|
|
64
|
+
* @param {string} identityServiceUrl - Identity service base URL
|
|
65
|
+
* @returns {string} OIDC base URL with no trailing slash
|
|
66
|
+
*/
|
|
67
|
+
const oidcBaseFromIdentityUrl = (identityServiceUrl) => (identityServiceUrl.replace(/\/oidc\/?$/, "") + "/oidc").replace(/\/$/, "");
|
|
68
|
+
/**
|
|
69
|
+
* Rewrites a discovery document so endpoint URLs use the identity service base (e.g. gateway).
|
|
70
|
+
* Single source of truth for canonical/target computation; used by both initial fetch and cache refresh.
|
|
71
|
+
* @param {string} identityServiceUrl - Identity service base URL (e.g. gateway or https://identity.moneyhub.co.uk)
|
|
72
|
+
* @param {Record<string, unknown>} doc - Raw OIDC discovery document
|
|
73
|
+
* @returns {Record<string, unknown>} Discovery document with endpoint URLs rewritten (issuer unchanged)
|
|
74
|
+
*/
|
|
75
|
+
function rewriteDiscoveryDocForIdentityUrl(identityServiceUrl, doc) {
|
|
76
|
+
const issuer = doc === null || doc === void 0 ? void 0 : doc.issuer;
|
|
77
|
+
if (!issuer || typeof issuer !== "string")
|
|
78
|
+
return doc;
|
|
79
|
+
const canonicalBase = issuer.replace(/\/$/, "");
|
|
80
|
+
const targetBase = oidcBaseFromIdentityUrl(identityServiceUrl);
|
|
81
|
+
return rewriteDiscoveryUrls(doc, canonicalBase, targetBase);
|
|
82
|
+
}
|
|
83
|
+
exports.rewriteDiscoveryDocForIdentityUrl = rewriteDiscoveryDocForIdentityUrl;
|
|
84
|
+
/**
|
|
85
|
+
* Fetches the raw OpenID discovery document from identityServiceUrl/oidc (no URL rewriting).
|
|
86
|
+
* @param {string} identityServiceUrl - Identity service base URL
|
|
87
|
+
* @param {DiscoveryOptions} options - Optional timeout, agent or mTLS settings
|
|
88
|
+
* @returns {Promise<OpenIDDiscoveryMetadata>} Raw OpenID discovery metadata
|
|
89
|
+
*/
|
|
90
|
+
async function getDiscovery(identityServiceUrl, options = {}) {
|
|
91
|
+
const base = oidcBaseFromIdentityUrl(identityServiceUrl);
|
|
92
|
+
const url = `${base}/.well-known/openid-configuration`;
|
|
93
|
+
const gotOpts = {
|
|
94
|
+
timeout: options.timeout,
|
|
95
|
+
responseType: "json",
|
|
96
|
+
};
|
|
97
|
+
if (options.agent) {
|
|
98
|
+
gotOpts.agent = options.agent;
|
|
99
|
+
}
|
|
100
|
+
if (options.mTLS) {
|
|
101
|
+
gotOpts.https = {
|
|
102
|
+
certificate: options.mTLS.cert,
|
|
103
|
+
key: options.mTLS.key,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
const doc = (await (0, got_1.default)(url, gotOpts).json());
|
|
107
|
+
return doc;
|
|
108
|
+
}
|
|
109
|
+
exports.getDiscovery = getDiscovery;
|
|
110
|
+
/**
|
|
111
|
+
* Fetches the OpenID discovery document from identityServiceUrl/oidc and rewrites
|
|
112
|
+
* all endpoint URLs (but not the issuer field) to use the configured identity service url, so that
|
|
113
|
+
* when used behind a gateway all OIDC traffic goes through the gateway.
|
|
114
|
+
* @param {string} identityServiceUrl - Identity service URL (e.g. https://identity.moneyhub.co.uk)
|
|
115
|
+
* @param {DiscoveryOptions} options - Optional timeout, agent or mTLS settings
|
|
116
|
+
* @returns {Promise<OpenIDDiscoveryMetadata>} OpenID discovery metadata with URLs rewritten for the gateway
|
|
117
|
+
*/
|
|
118
|
+
async function getDiscoveryWithGatewayUrl(identityServiceUrl, options = {}) {
|
|
119
|
+
const doc = (await getDiscovery(identityServiceUrl, options));
|
|
120
|
+
const rewritten = rewriteDiscoveryDocForIdentityUrl(identityServiceUrl, doc);
|
|
121
|
+
return rewritten;
|
|
122
|
+
}
|
|
123
|
+
exports.getDiscoveryWithGatewayUrl = getDiscoveryWithGatewayUrl;
|
|
124
|
+
/**
|
|
125
|
+
* Infers the canonical API base from a response link URL (e.g. links.self) by taking
|
|
126
|
+
* origin and path up to and including the version segment (e.g. /v3).
|
|
127
|
+
* @param {string} linkUrl - Full link URL from a resource response
|
|
128
|
+
* @returns {string|null} Canonical base URL or null if it cannot be inferred
|
|
129
|
+
*/
|
|
130
|
+
function inferCanonicalBaseFromLinkUrl(linkUrl) {
|
|
131
|
+
try {
|
|
132
|
+
const u = new URL(linkUrl);
|
|
133
|
+
const pathParts = u.pathname.split("/").filter(Boolean);
|
|
134
|
+
const versionIndex = pathParts.findIndex((p) => /^v\d+(\.\d+)?$/i.test(p));
|
|
135
|
+
if (versionIndex >= 0) {
|
|
136
|
+
const versionPath = "/" + pathParts.slice(0, versionIndex + 1).join("/");
|
|
137
|
+
return `${u.origin}${versionPath}`;
|
|
138
|
+
}
|
|
139
|
+
return u.origin;
|
|
140
|
+
}
|
|
141
|
+
catch {
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
exports.inferCanonicalBaseFromLinkUrl = inferCanonicalBaseFromLinkUrl;
|
|
146
|
+
/**
|
|
147
|
+
* Rewrites URL strings in a resource server response body (e.g. links.self, links.next,
|
|
148
|
+
* links.prev) so that any canonical API base is replaced with resourceServerUrl.
|
|
149
|
+
* Returns the body unchanged if no links or no canonical base can be inferred.
|
|
150
|
+
* @param {*} body - Resource server response body (typically with a links property)
|
|
151
|
+
* @param {string} resourceServerUrl - Base URL for the resource server (e.g. gateway URL)
|
|
152
|
+
* @returns {*} Body with link URLs rewritten to use resourceServerUrl
|
|
153
|
+
*/
|
|
154
|
+
function rewriteResourceServerResponseUrls(body, resourceServerUrl) {
|
|
155
|
+
if (body === null || typeof body !== "object")
|
|
156
|
+
return body;
|
|
157
|
+
const targetBase = resourceServerUrl.replace(/\/$/, "");
|
|
158
|
+
const links = body.links;
|
|
159
|
+
if (!links || typeof links.self !== "string")
|
|
160
|
+
return body;
|
|
161
|
+
const canonicalBase = inferCanonicalBaseFromLinkUrl(links.self);
|
|
162
|
+
if (!canonicalBase || canonicalBase === targetBase)
|
|
163
|
+
return body;
|
|
164
|
+
const result = { ...body };
|
|
165
|
+
result.links = rewriteUrlsInObject(links, canonicalBase, targetBase);
|
|
166
|
+
return result;
|
|
167
|
+
}
|
|
168
|
+
exports.rewriteResourceServerResponseUrls = rewriteResourceServerResponseUrls;
|
|
169
|
+
//# sourceMappingURL=discovery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discovery.js","sourceRoot":"","sources":["../src/discovery.ts"],"names":[],"mappings":";;;;;;AAAA,8CAA2D;AAU3D;;;;;;;;GAQG;AACH,SAAgB,mBAAmB,CACjC,KAAQ,EACR,aAAqB,EACrB,UAAkB;IAElB,IAAI,aAAa,KAAK,UAAU;QAAE,OAAO,KAAK,CAAA;IAE9C,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QAC7B,IAAI,KAAK,CAAC,UAAU,CAAC,aAAa,CAAC,EAAE;YACnC,OAAO,CAAC,UAAU,GAAG,KAAK,CAAC,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,CA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M,UAAU,GAAG,iBAAiB,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;IACvD,MAAM,KAAK,GAAI,IAAgC,CAAC,KAAoE,CAAA;IACpH,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAA;IAEzD,MAAM,aAAa,GAAG,6BAA6B,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAC/D,IAAI,CAAC,aAAa,IAAI,aAAa,KAAK,UAAU;QAAE,OAAO,IAAI,CAAA;IAE/D,MAAM,MAAM,GAAG,EAAC,GAAI,IAAgC,EAAC,CAAA;IACrD,MAAM,CAAC,KAAK,GAAG,mBAAmB,CAAC,KAAK,EAAE,aAAa,EAAE,UAAU,CAAC,CAAA;IACpE,OAAO,MAAsB,CAAA;AAC/B,CAAC;AAhBD,8EAgBC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ declare const _Moneyhub: (apiClientConfig: ApiClientConfig) => Promise<{
|
|
|
5
5
|
keys: import("jose").JWK[];
|
|
6
6
|
} | null;
|
|
7
7
|
generators: typeof generators;
|
|
8
|
+
getConsentHistory: (params?: import("./schema/consent-history").ConsentHistorySearchParams | undefined, options?: import("./request").ExtraOptions | undefined) => Promise<import("./request").ApiResponse<import("./schema/consent-history").ConsentHistory[]>>;
|
|
8
9
|
categoriseTransactions: import("./requests/types/categorise-transactions").CategoriseTransactionsRequest;
|
|
9
10
|
createResellerCheckRequest: import("./requests/types/reseller-check").CreateResellerCheckRequest;
|
|
10
11
|
registerUser: ({ clientUserId, }: {
|
|
@@ -63,14 +64,54 @@ declare const _Moneyhub: (apiClientConfig: ApiClientConfig) => Promise<{
|
|
|
63
64
|
clientId?: string | undefined;
|
|
64
65
|
} | undefined) => Promise<Connections.WellKnownConnection[]>;
|
|
65
66
|
getOpenIdConfig: () => Promise<unknown>;
|
|
67
|
+
caasDeleteUser: ({ userId, }: {
|
|
68
|
+
userId: string;
|
|
69
|
+
}, options?: import("./request").ExtraOptions | undefined) => Promise<void>;
|
|
70
|
+
caasPatchTransaction: ({ accountId, transactionId, l2CategoryId, }: {
|
|
71
|
+
accountId: string;
|
|
72
|
+
transactionId: string;
|
|
73
|
+
l2CategoryId: string;
|
|
74
|
+
}, options?: import("./request").ExtraOptions | undefined) => Promise<import("./request").ApiResponse<import("./requests/caas/types/transactions").CaasTransaction[]>>;
|
|
75
|
+
caasEnrichTransactions: ({ transactions, }: {
|
|
76
|
+
transactions: import("./requests/caas/types/transactions").CaasTransactionInput[];
|
|
77
|
+
}, options?: import("./request").ExtraOptions | undefined) => Promise<import("./request").ApiResponse<import("./requests/caas/types/transactions").CaasTransaction[]>>;
|
|
78
|
+
caasGetTransactions: ({ userId, accountId, limit, }: {
|
|
79
|
+
userId?: string | undefined;
|
|
80
|
+
accountId: string;
|
|
81
|
+
limit?: number | undefined;
|
|
82
|
+
}, options?: import("./request").ExtraOptions | undefined) => Promise<import("./request").ApiResponse<import("./requests/caas/types/transactions").CaasTransaction[]>>;
|
|
83
|
+
caasDeleteTransaction: ({ accountId, transactionId, }: {
|
|
84
|
+
accountId: string;
|
|
85
|
+
transactionId: string;
|
|
86
|
+
}, options?: import("./request").ExtraOptions | undefined) => Promise<void>;
|
|
87
|
+
caasGetGeotags: ({ geotagIds, }: {
|
|
88
|
+
geotagIds: string[];
|
|
89
|
+
}, options?: import("./request").ExtraOptions | undefined) => Promise<import("./request").ApiResponse<import("./requests/caas/types/transactions").CaasGeotag[]>>;
|
|
90
|
+
caasGetCounterparties: ({ limit, offset, }: {
|
|
91
|
+
limit?: number | undefined;
|
|
92
|
+
offset?: number | undefined;
|
|
93
|
+
}, options?: import("./request").ExtraOptions | undefined) => Promise<import("./request").ApiResponse<import("./requests/caas/types/transactions").CaasCounterparty[]>>;
|
|
94
|
+
caasGetCategories: (options?: import("./request").ExtraOptions | undefined) => Promise<import("./request").ApiResponse<import("./requests/caas/types/categories").CaasCategory[]>>;
|
|
95
|
+
caasGetCategoryGroups: (options?: import("./request").ExtraOptions | undefined) => Promise<import("./request").ApiResponse<import("./requests/caas/types/categories").CaasCategoryGroup[]>>;
|
|
96
|
+
caasDeleteAccount: ({ accountId, }: {
|
|
97
|
+
accountId: string;
|
|
98
|
+
}, options?: import("./request").ExtraOptions | undefined) => Promise<void>;
|
|
66
99
|
getTransactions: ({ userId, params, }: {
|
|
67
100
|
userId?: string | undefined;
|
|
68
101
|
params?: Transactions.TransactionSearchParams | undefined;
|
|
69
102
|
}, options?: import("./request").ExtraOptions | undefined) => Promise<import("./request").ApiResponse<Transactions.Transaction[]>>;
|
|
103
|
+
getUnenrichedTransactions: ({ userId, params, }: {
|
|
104
|
+
userId?: string | undefined;
|
|
105
|
+
params?: Transactions.TransactionUnenrichedSearchParams | undefined;
|
|
106
|
+
}, options?: import("./request").ExtraOptions | undefined) => Promise<import("./request").ApiResponse<Transactions.TransactionUnenriched[]>>;
|
|
70
107
|
getTransaction: ({ userId, transactionId, }: {
|
|
71
108
|
userId?: string | undefined;
|
|
72
109
|
transactionId: string;
|
|
73
110
|
}, options?: import("./request").ExtraOptions | undefined) => Promise<import("./request").ApiResponse<Transactions.Transaction>>;
|
|
111
|
+
getUnenrichedTransaction: ({ userId, transactionId, }: {
|
|
112
|
+
userId?: string | undefined;
|
|
113
|
+
transactionId: string;
|
|
114
|
+
}, options?: import("./request").ExtraOptions | undefined) => Promise<import("./request").ApiResponse<Transactions.TransactionUnenriched>>;
|
|
74
115
|
addTransaction: ({ userId, transaction, }: {
|
|
75
116
|
userId: string;
|
|
76
117
|
transaction: Transactions.TransactionPost;
|
|
@@ -251,6 +292,10 @@ declare const _Moneyhub: (apiClientConfig: ApiClientConfig) => Promise<{
|
|
|
251
292
|
revokeRecurringPayment: ({ recurringPaymentId, }: {
|
|
252
293
|
recurringPaymentId: string;
|
|
253
294
|
}, options?: import("./request").ExtraOptions | undefined) => Promise<number>;
|
|
295
|
+
confirmFundsForRecurringPayment: ({ recurringPaymentId, fundsConfirmation, }: {
|
|
296
|
+
recurringPaymentId: string;
|
|
297
|
+
fundsConfirmation: Payments.FundsConfirmationRequest;
|
|
298
|
+
}, options?: import("./request").ExtraOptions | undefined) => Promise<import("./request").ApiResponse<Payments.FundsConfirmationResponse>>;
|
|
254
299
|
getProjects: ({ userId, params, }: {
|
|
255
300
|
userId: string;
|
|
256
301
|
params?: import("./request").SearchParams | undefined;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,UAAU,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,UAAU,EAAsB,MAAM,eAAe,CAAA;AAQ7E,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,iBAAiB,CAAA;AA8BpD,QAAA,MAAM,SAAS,oBAA2B,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AAQ,MAAM,kBAAkB,CAAA;AACjD,OAAO,KAAK,KAAK,mBAAmB,MAAM,8BAA8B,CAAA;AACxE,OAAO,KAAK,KAAK,aAAa,MAAM,wBAAwB,CAAA;AAC5D,OAAO,KAAK,KAAK,YAAY,MAAM,uBAAuB,CAAA;AAC1D,OAAO,KAAK,KAAK,gBAAgB,MAAM,4BAA4B,CAAA;AACnE,OAAO,KAAK,KAAK,aAAa,MAAM,wBAAwB,CAAA;AAC5D,OAAO,KAAK,KAAK,cAAc,MAAM,yBAAyB,CAAA;AAC9D,OAAO,KAAK,KAAK,UAAU,MAAM,oBAAoB,CAAA;AACrD,OAAO,KAAK,KAAK,KAAK,MAAM,eAAe,CAAA;AAC3C,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAA;AAC1C,OAAO,KAAK,KAAK,YAAY,MAAM,sBAAsB,CAAA;AACzD,OAAO,KAAK,KAAK,KAAK,MAAM,eAAe,CAAA;AAE3C,OAAO,EACL,QAAQ,EACR,aAAa,EACb,YAAY,EACZ,QAAQ,EACR,aAAa,EACb,UAAU,EACV,uBAAuB,EACvB,cAAc,EACd,WAAW,EACX,QAAQ,EACR,sBAAsB,EACtB,IAAI,EACJ,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,mBAAmB,EACnB,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,aAAa,EACb,cAAc,EACd,UAAU,EACV,KAAK,EACL,KAAK,EACL,YAAY,EACZ,KAAK,EACL,eAAe,EACf,QAAQ,GACT,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -33,43 +33,80 @@ const tokens_1 = __importDefault(require("./tokens"));
|
|
|
33
33
|
const requests_1 = __importDefault(require("./requests"));
|
|
34
34
|
const R = __importStar(require("ramda"));
|
|
35
35
|
const request_1 = __importDefault(require("./request"));
|
|
36
|
+
const discovery_1 = require("./discovery");
|
|
37
|
+
const oidc_config_1 = require("./oidc-config");
|
|
36
38
|
const DEFAULT_TIMEOUT = 60000;
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
+
const DEFAULT_OIDC_CACHE_TTL_MS = 3600000; // 1 hour
|
|
40
|
+
function buildConfig(apiClientConfig) {
|
|
41
|
+
return R.evolve({
|
|
39
42
|
identityServiceUrl: (val) => val.replace("/oidc", ""),
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
gatewayIdentityServiceUrl: (val) => val == null ? val : val.replace(/\/oidc\/?$/, ""),
|
|
44
|
+
caasResourceServerUrl: (val) => `${val.replace(/\/v\d+(\.\d+)?\b/, "")}/caas/v1`,
|
|
45
|
+
}, {
|
|
46
|
+
...apiClientConfig,
|
|
47
|
+
caasResourceServerUrl: apiClientConfig.resourceServerUrl,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
function effectiveUrls(config) {
|
|
51
|
+
var _a, _b, _c, _d, _e;
|
|
52
|
+
return {
|
|
53
|
+
identity: (_a = config.gatewayIdentityServiceUrl) !== null && _a !== void 0 ? _a : config.identityServiceUrl,
|
|
54
|
+
resource: (_b = config.gatewayResourceServerUrl) !== null && _b !== void 0 ? _b : config.resourceServerUrl,
|
|
55
|
+
caas: (_c = config.gatewayCaasResourceServerUrl) !== null && _c !== void 0 ? _c : config.caasResourceServerUrl,
|
|
56
|
+
osip: (_d = config.gatewayOsipResourceServerUrl) !== null && _d !== void 0 ? _d : config.osipResourceServerUrl,
|
|
57
|
+
accountConnect: (_e = config.gatewayAccountConnectUrl) !== null && _e !== void 0 ? _e : config.accountConnectUrl,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
const _Moneyhub = async (apiClientConfig) => {
|
|
61
|
+
const config = buildConfig(apiClientConfig);
|
|
62
|
+
const urls = effectiveUrls(config);
|
|
63
|
+
const { options = {}, client: clientCreds } = config;
|
|
64
|
+
const { timeout = DEFAULT_TIMEOUT, apiVersioning = true, agent, openIdConfigCacheTtlMs = DEFAULT_OIDC_CACHE_TTL_MS, retry = {} } = options;
|
|
65
|
+
const { mTLS } = clientCreds;
|
|
43
66
|
openid_client_1.custom.setHttpOptionsDefaults({
|
|
44
67
|
timeout,
|
|
45
|
-
...mTLS ? {
|
|
46
|
-
cert: mTLS.cert,
|
|
47
|
-
key: mTLS.key,
|
|
48
|
-
} : {},
|
|
68
|
+
...mTLS ? { cert: mTLS.cert, key: mTLS.key } : {},
|
|
49
69
|
});
|
|
50
|
-
const
|
|
70
|
+
const discoveryOpts = { timeout, agent: options.agent, mTLS: mTLS !== null && mTLS !== void 0 ? mTLS : undefined };
|
|
71
|
+
const discoveryMetadata = config.gatewayIdentityServiceUrl
|
|
72
|
+
? await (0, discovery_1.getDiscoveryWithGatewayUrl)(urls.identity, discoveryOpts)
|
|
73
|
+
: await (0, discovery_1.getDiscovery)(urls.identity, discoveryOpts);
|
|
74
|
+
const moneyhubIssuer = new openid_client_1.Issuer(discoveryMetadata);
|
|
51
75
|
const client = new moneyhubIssuer.Client({
|
|
52
|
-
client_id,
|
|
53
|
-
client_secret,
|
|
54
|
-
id_token_signed_response_alg,
|
|
55
|
-
redirect_uri,
|
|
56
|
-
token_endpoint_auth_method,
|
|
57
|
-
request_object_signing_alg,
|
|
76
|
+
...R.pick(["client_id", "client_secret", "id_token_signed_response_alg", "redirect_uri", "token_endpoint_auth_method", "request_object_signing_alg"], clientCreds),
|
|
58
77
|
tls_client_certificate_bound_access_tokens: (mTLS === null || mTLS === void 0 ? void 0 : mTLS.tls_client_certificate_bound_access_tokens) || false,
|
|
59
|
-
}, { keys });
|
|
78
|
+
}, { keys: clientCreds.keys });
|
|
60
79
|
client[openid_client_1.custom.clock_tolerance] = 10;
|
|
61
|
-
const
|
|
80
|
+
const requestFn = (0, request_1.default)({
|
|
62
81
|
client,
|
|
63
82
|
options: { timeout, apiVersioning, agent, mTLS, retry },
|
|
83
|
+
identityServiceUrl: urls.identity,
|
|
84
|
+
gatewayResourceServerUrl: config.gatewayResourceServerUrl,
|
|
85
|
+
gatewayCaasResourceServerUrl: config.gatewayCaasResourceServerUrl,
|
|
86
|
+
gatewayOsipResourceServerUrl: config.gatewayOsipResourceServerUrl,
|
|
87
|
+
});
|
|
88
|
+
const getOpenIdConfig = (0, oidc_config_1.createGetOpenIdConfig)({
|
|
89
|
+
identityServiceUrl: urls.identity,
|
|
90
|
+
gatewayIdentityServiceUrl: config.gatewayIdentityServiceUrl,
|
|
91
|
+
openIdConfigCacheTtlMs,
|
|
92
|
+
request: requestFn,
|
|
64
93
|
});
|
|
65
|
-
const
|
|
66
|
-
...
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
94
|
+
const configWithGetOpenIdConfig = {
|
|
95
|
+
...config,
|
|
96
|
+
resourceServerUrl: urls.resource,
|
|
97
|
+
identityServiceUrl: urls.identity,
|
|
98
|
+
caasResourceServerUrl: urls.caas,
|
|
99
|
+
osipResourceServerUrl: urls.osip,
|
|
100
|
+
accountConnectUrl: urls.accountConnect,
|
|
101
|
+
getOpenIdConfig,
|
|
102
|
+
};
|
|
103
|
+
return {
|
|
104
|
+
...(0, get_auth_urls_1.default)({ client, config: configWithGetOpenIdConfig }),
|
|
105
|
+
...(0, tokens_1.default)({ client, config: configWithGetOpenIdConfig }),
|
|
106
|
+
...(0, requests_1.default)({ config: configWithGetOpenIdConfig, request: requestFn }),
|
|
107
|
+
keys: () => { var _a; return (((_a = clientCreds.keys) === null || _a === void 0 ? void 0 : _a.length) ? { keys: clientCreds.keys } : null); },
|
|
70
108
|
generators: openid_client_1.generators,
|
|
71
109
|
};
|
|
72
|
-
return moneyhub;
|
|
73
110
|
};
|
|
74
111
|
const Moneyhub = _Moneyhub;
|
|
75
112
|
exports.Moneyhub = Moneyhub;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":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AAE,OAAO,EAAE,SAAS,EAAC,CAAC;QAC3E,IAAI,EAAE,GAAG,EAAE,WAAC,OAAA,CAAC,CAAA,MAAA,WAAW,CAAC,IAAI,0CAAE,MAAM,EAAC,CAAC,CAAC,EAAC,IAAI,EAAE,WAAW,CAAC,IAAI,EAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA,EAAA;QACxE,UAAU,EAAV,0BAAU;KACX,CAAA;AACH,CAAC,CAAA;AAGD,MAAM,QAAQ,GAAoE,SAAS,CAAA;AAyDzF,4BAAQ"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Request } from "./request";
|
|
2
|
+
export interface GetOpenIdConfigParams {
|
|
3
|
+
identityServiceUrl: string;
|
|
4
|
+
/** When set, discovery endpoint URLs are rewritten to this base. */
|
|
5
|
+
gatewayIdentityServiceUrl?: string;
|
|
6
|
+
openIdConfigCacheTtlMs: number;
|
|
7
|
+
request: Request;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Creates a getOpenIdConfig function that fetches the OIDC discovery document with optional
|
|
11
|
+
* URL rewriting for gateway use. Uses @isaacs/ttlcache for TTL-based caching when openIdConfigCacheTtlMs > 0.
|
|
12
|
+
*
|
|
13
|
+
* @param {GetOpenIdConfigParams} params - Configuration: identityServiceUrl, optional gatewayIdentityServiceUrl, openIdConfigCacheTtlMs, and the request function used to fetch the discovery document
|
|
14
|
+
* @returns {function(): Promise<Record<string, unknown>>} A function that returns a promise of the discovery document (with endpoint URLs rewritten to gatewayIdentityServiceUrl only when that option is set)
|
|
15
|
+
*/
|
|
16
|
+
export declare function createGetOpenIdConfig(params: GetOpenIdConfigParams): () => Promise<Record<string, unknown>>;
|
|
17
|
+
//# sourceMappingURL=oidc-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oidc-config.d.ts","sourceRoot":"","sources":["../src/oidc-config.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,WAAW,CAAA;AAYtC,MAAM,WAAW,qBAAqB;IACpC,kBAAkB,EAAE,MAAM,CAAA;IAE1B,oEAAoE;IACpE,yBAAyB,CAAC,EAAE,MAAM,CAAA;IAClC,sBAAsB,EAAE,MAAM,CAAA;IAC9B,OAAO,EAAE,OAAO,CAAA;CACjB;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,qBAAqB,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAyB3G"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createGetOpenIdConfig = void 0;
|
|
4
|
+
const ttlcache_1 = require("@isaacs/ttlcache");
|
|
5
|
+
const discovery_1 = require("./discovery");
|
|
6
|
+
const OIDC_CACHE_KEY = "oidc";
|
|
7
|
+
/**
|
|
8
|
+
* Builds the discovery document URL for the given identity service URL.
|
|
9
|
+
* @param {string} identityServiceUrl - Identity service URL
|
|
10
|
+
* @returns {string} Full URL to the OIDC discovery document
|
|
11
|
+
*/
|
|
12
|
+
const discoveryUrl = (identityServiceUrl) => identityServiceUrl.replace(/\/oidc\/?$/, "") + "/oidc/.well-known/openid-configuration";
|
|
13
|
+
/**
|
|
14
|
+
* Creates a getOpenIdConfig function that fetches the OIDC discovery document with optional
|
|
15
|
+
* URL rewriting for gateway use. Uses @isaacs/ttlcache for TTL-based caching when openIdConfigCacheTtlMs > 0.
|
|
16
|
+
*
|
|
17
|
+
* @param {GetOpenIdConfigParams} params - Configuration: identityServiceUrl, optional gatewayIdentityServiceUrl, openIdConfigCacheTtlMs, and the request function used to fetch the discovery document
|
|
18
|
+
* @returns {function(): Promise<Record<string, unknown>>} A function that returns a promise of the discovery document (with endpoint URLs rewritten to gatewayIdentityServiceUrl only when that option is set)
|
|
19
|
+
*/
|
|
20
|
+
function createGetOpenIdConfig(params) {
|
|
21
|
+
const { identityServiceUrl, gatewayIdentityServiceUrl, openIdConfigCacheTtlMs, request } = params;
|
|
22
|
+
const useCache = openIdConfigCacheTtlMs > 0;
|
|
23
|
+
const cache = useCache
|
|
24
|
+
? new ttlcache_1.TTLCache({ max: 1, ttl: openIdConfigCacheTtlMs })
|
|
25
|
+
: undefined;
|
|
26
|
+
return async function getOpenIdConfig() {
|
|
27
|
+
if (useCache && cache) {
|
|
28
|
+
const cached = cache.get(OIDC_CACHE_KEY);
|
|
29
|
+
if (cached)
|
|
30
|
+
return cached;
|
|
31
|
+
}
|
|
32
|
+
const raw = (await request(discoveryUrl(identityServiceUrl)));
|
|
33
|
+
const rewriteTarget = gatewayIdentityServiceUrl !== null && gatewayIdentityServiceUrl !== void 0 ? gatewayIdentityServiceUrl : identityServiceUrl;
|
|
34
|
+
const value = gatewayIdentityServiceUrl && (raw === null || raw === void 0 ? void 0 : raw.issuer) && typeof raw.issuer === "string"
|
|
35
|
+
? (0, discovery_1.rewriteDiscoveryDocForIdentityUrl)(rewriteTarget, raw)
|
|
36
|
+
: raw;
|
|
37
|
+
if (useCache && cache) {
|
|
38
|
+
cache.set(OIDC_CACHE_KEY, value);
|
|
39
|
+
}
|
|
40
|
+
return value;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
exports.createGetOpenIdConfig = createGetOpenIdConfig;
|
|
44
|
+
//# sourceMappingURL=oidc-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oidc-config.js","sourceRoot":"","sources":["../src/oidc-config.ts"],"names":[],"mappings":";;;AAAA,+CAAyC;AACzC,2CAA6D;AAG7D,MAAM,cAAc,GAAG,MAAM,CAAA;AAE7B;;;;GAIG;AACH,MAAM,YAAY,GAAG,CAAC,kBAA0B,EAAU,EAAE,CAC1D,kBAAkB,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,GAAG,wCAAwC,CAAA;AAWzF;;;;;;GAMG;AACH,SAAgB,qBAA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