diff --git a/src/lib/core.ts b/src/lib/core.ts index 641322b..1c38482 100644 --- a/src/lib/core.ts +++ b/src/lib/core.ts @@ -87,10 +87,10 @@ export class Fintoc { whoami: WhoamiManager; v2: FintocV2; - constructor(apiKey: string, jwsPrivateKey?: string) { + constructor(apiKey: string, jwsPrivateKey?: string, options?: { userAgent?: string }) { this.#client = new Client({ baseUrl: `${API_BASE_URL}`, - userAgent: `fintoc-node/${version}`, + userAgent: options?.userAgent || `fintoc-node/${version}`, apiKey, jwsPrivateKey, }); diff --git a/src/spec/core.spec.ts b/src/spec/core.spec.ts index 71a8fb8..9624b20 100644 --- a/src/spec/core.spec.ts +++ b/src/spec/core.spec.ts @@ -9,3 +9,17 @@ test('"Fintoc" object creation', (t) => { t.assert(fintoc.links instanceof LinksManager); t.assert(fintoc.webhookEndpoints instanceof WebhookEndpointsManager); }); + +test('"Fintoc" object creation with custom userAgent', (t) => { + const apiKey = 'super_secret_api_key'; + const fintoc = new Fintoc(apiKey, undefined, { userAgent: 'fintoc-cli/0.1.0' }); + t.assert(fintoc.links instanceof LinksManager); + t.assert(fintoc.webhookEndpoints instanceof WebhookEndpointsManager); + t.is((fintoc.links as any)._client.userAgent, 'fintoc-cli/0.1.0'); +}); + +test('"Fintoc" object creation uses default userAgent when not provided', (t) => { + const apiKey = 'super_secret_api_key'; + const fintoc = new Fintoc(apiKey); + t.true((fintoc.links as any)._client.userAgent.startsWith('fintoc-node/')); +});