Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fintoc",
"version": "1.18.0",
"version": "1.19.0",
"description": "The official Node client for the Fintoc API.",
"main": "build/main/index.js",
"typings": "build/main/index.d.ts",
Expand Down
4 changes: 2 additions & 2 deletions src/lib/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down
3 changes: 2 additions & 1 deletion src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import axios, { AxiosError } from 'axios';

Check warning on line 1 in src/lib/utils.ts

View workflow job for this annotation

GitHub Actions / eslint

'AxiosError' is defined but never used

import { IModule } from '../interfaces/module';
import { GenericFunction } from '../types';
Expand Down Expand Up @@ -44,7 +44,8 @@
* @returns A boolean that represents if `rawDate` is parseable as a Date object
*/
export function isISODate(rawDate: string) {
return !Number.isNaN(Date.parse(rawDate));
const isoDateRegex = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:?\d{2})?)?$/;
return isoDateRegex.test(rawDate);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/lib/version.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const versionInfo = [1, 18, 0];
export const versionInfo = [1, 19, 0];

export const version = versionInfo.join('.');
14 changes: 14 additions & 0 deletions src/spec/core.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/'));
});
6 changes: 6 additions & 0 deletions src/spec/utils/getResourceClass.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ test('"getResourceClass" string resource', async (t) => {
t.is(klass, String);
});

test('"getResourceClass" ambiguous string that Date.parse accepts should remain String', async (t) => {
const resource = 'any_resource';
t.is(await getResourceClass(resource, 'PS 2'), String);
t.is(await getResourceClass(resource, 'test 1'), String);
});

test('"getResourceClass" number resource', async (t) => {
const resource = 'any_resource';
const klass = await getResourceClass(resource, 15);
Expand Down
15 changes: 15 additions & 0 deletions src/spec/utils/isISODate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,22 @@ test('"isISODate" valid ISO format', (t) => {
t.assert(isISODate(validISODaTetimeString));
});

test('"isISODate" valid ISO date without time', (t) => {
t.assert(isISODate('2021-08-13'));
});

test('"isISODate" valid ISO date with timezone offset', (t) => {
t.assert(isISODate('2021-08-13T13:40:40.811+05:00'));
});

test('"isISODate" invalid ISO format', (t) => {
const invalidISODaTetimeString = 'This is not a date';
t.assert(!isISODate(invalidISODaTetimeString));
});

test('"isISODate" should not parse ambiguous strings as dates', (t) => {
t.assert(!isISODate('PS 2'));
t.assert(!isISODate('test 1'));
t.assert(!isISODate('Mar 5'));
t.assert(!isISODate('Jan 2024'));
});
Loading