diff --git a/.releaserc.json b/.releaserc.json index ca22d93f..6882760e 100644 --- a/.releaserc.json +++ b/.releaserc.json @@ -1,7 +1,12 @@ { "branches": ["master"], "plugins": [ - "@semantic-release/commit-analyzer", + [ + "@semantic-release/commit-analyzer", + { + "releaseRules": [{ "type": "refactor", "release": "patch" }] + } + ], "@semantic-release/release-notes-generator", "@semantic-release/changelog", [ diff --git a/src/atomic/banks/BasisTheoryAtomicBanks.ts b/src/atomic/banks/BasisTheoryAtomicBanks.ts index 5c475953..ae240ea1 100644 --- a/src/atomic/banks/BasisTheoryAtomicBanks.ts +++ b/src/atomic/banks/BasisTheoryAtomicBanks.ts @@ -2,8 +2,6 @@ import type { AxiosTransformer } from 'axios'; import { createRequestConfig, dataExtractor, - proxyRaw, - transformAtomicReactionRequestSnakeCase, transformAtomicRequestSnakeCase, transformAtomicResponseCamelCase, } from '@/common'; @@ -13,8 +11,6 @@ import { CrudBuilder } from '@/service/CrudBuilder'; import type { AtomicBank, CreateAtomicBank, - AtomicReactRequest, - ReactResponse, UpdateAtomicBank, } from '@/types/models'; import type { PaginatedQuery, RequestOptions } from '@/types/sdk'; @@ -50,23 +46,6 @@ export const BasisTheoryAtomicBanks = new CrudBuilder( .patch(`/${id}`, request, createRequestConfig(options)) .then(dataExtractor); } - - public react( - tokenId: string, - request: AtomicReactRequest, - options?: RequestOptions - ): Promise { - return this.client - .post( - `/${tokenId}/react`, - request, - createRequestConfig(options, { - transformRequest: transformAtomicReactionRequestSnakeCase, - transformResponse: proxyRaw, - }) - ) - .then(dataExtractor); - } } ) .create() diff --git a/src/atomic/cards/BasisTheoryAtomicCards.ts b/src/atomic/cards/BasisTheoryAtomicCards.ts index 5fb9fc78..f6c0b9f2 100644 --- a/src/atomic/cards/BasisTheoryAtomicCards.ts +++ b/src/atomic/cards/BasisTheoryAtomicCards.ts @@ -1,10 +1,5 @@ import type { AxiosTransformer } from 'axios'; -import { - createRequestConfig, - dataExtractor, - transformAtomicReactionRequestSnakeCase, - proxyRaw, -} from '@/common'; +import { createRequestConfig, dataExtractor } from '@/common'; import { transformAtomicRequestSnakeCase, transformAtomicResponseCamelCase, @@ -15,8 +10,6 @@ import { CrudBuilder } from '@/service/CrudBuilder'; import type { AtomicCard, CreateAtomicCard, - AtomicReactRequest, - ReactResponse, UpdateAtomicCard, } from '@/types/models'; import type { PaginatedQuery, RequestOptions } from '@/types/sdk'; @@ -52,23 +45,6 @@ export const BasisTheoryAtomicCards = new CrudBuilder( .patch(`/${id}`, request, createRequestConfig(options)) .then(dataExtractor); } - - public react( - tokenId: string, - request: AtomicReactRequest, - options?: RequestOptions - ): Promise { - return this.client - .post( - `/${tokenId}/react`, - request, - createRequestConfig(options, { - transformRequest: transformAtomicReactionRequestSnakeCase, - transformResponse: proxyRaw, - }) - ) - .then(dataExtractor); - } } ) .create() diff --git a/src/common/utils.ts b/src/common/utils.ts index 858e4ac2..39afdf8a 100644 --- a/src/common/utils.ts +++ b/src/common/utils.ts @@ -9,12 +9,7 @@ import os from 'os'; import { snakeCase } from 'snake-case'; import snakecaseKeys from 'snakecase-keys'; import type { RequestTransformers } from '@/service'; -import type { - AtomicReactRequest, - Reactor, - Token, - TokenBase, -} from '@/types/models'; +import type { Reactor, Token, TokenBase } from '@/types/models'; import type { ApplicationInfo, ClientUserAgent, @@ -96,22 +91,6 @@ const transformTokenRequestSnakeCase: AxiosTransformer = ( } as Token; }; -const transformAtomicReactionRequestSnakeCase: AxiosTransformer = ( - request: AtomicReactRequest -): Token | undefined => { - if (typeof request === 'undefined') { - return undefined; - } - - return { - ...snakecaseKeys(request, { deep: true }), - ...(request.requestParameters !== undefined - ? // eslint-disable-next-line camelcase - { request_parameters: request.requestParameters } - : {}), - } as Token; -}; - const transformTokenResponseCamelCase: AxiosTransformer = ( token: Token ): Token | undefined => { @@ -288,7 +267,7 @@ const getQueryParams = (query: Q = {} as Q): string => { objectKeys.forEach((objectKey) => { appendSafe( - `${key}.${objectKey}`, + `${String(key)}.${objectKey}`, ((value as unknown) as Record)[objectKey], true ); @@ -393,7 +372,6 @@ export { transformReactorRequestSnakeCase, transformAtomicRequestSnakeCase, transformTokenRequestSnakeCase, - transformAtomicReactionRequestSnakeCase, transformTokenResponseCamelCase, transformReactorResponseCamelCase, transformResponseCamelCase, diff --git a/src/types/models/shared.ts b/src/types/models/shared.ts index d213e30a..956884c5 100644 --- a/src/types/models/shared.ts +++ b/src/types/models/shared.ts @@ -24,22 +24,9 @@ interface TokenBase extends Auditable { fingerprint?: string; metadata?: Record; } - -interface AtomicReactRequest { - reactorId: string; - requestParameters?: Record; -} - interface ReactResponse { tokens: DataObject; raw: DataObject; } -export type { - Primitive, - Auditable, - TokenType, - TokenBase, - AtomicReactRequest, - ReactResponse, -}; +export type { Primitive, Auditable, TokenType, TokenBase, ReactResponse }; diff --git a/src/types/sdk/services/banks.ts b/src/types/sdk/services/banks.ts index 167d3a86..95ef9659 100644 --- a/src/types/sdk/services/banks.ts +++ b/src/types/sdk/services/banks.ts @@ -3,21 +3,13 @@ import type { CreateAtomicBank, UpdateAtomicBank, } from '@/types/models'; -import type { - Create, - Retrieve, - Update, - Delete, - List, - AtomicReact, -} from './shared'; +import type { Create, Retrieve, Update, Delete, List } from './shared'; interface AtomicBanks extends Create, Retrieve, Update, Delete, - List, - AtomicReact {} + List {} export type { AtomicBanks }; diff --git a/src/types/sdk/services/cards.ts b/src/types/sdk/services/cards.ts index 340acc4b..c8a458d3 100644 --- a/src/types/sdk/services/cards.ts +++ b/src/types/sdk/services/cards.ts @@ -3,21 +3,13 @@ import type { CreateAtomicCard, UpdateAtomicCard, } from '@/types/models'; -import type { - Create, - Retrieve, - Update, - Delete, - List, - AtomicReact, -} from './shared'; +import type { Create, Retrieve, Update, Delete, List } from './shared'; interface AtomicCards extends Create, Retrieve, Update, Delete, - List, - AtomicReact {} + List {} export type { AtomicCards }; diff --git a/src/types/sdk/services/shared.ts b/src/types/sdk/services/shared.ts index f98d648b..8d625233 100644 --- a/src/types/sdk/services/shared.ts +++ b/src/types/sdk/services/shared.ts @@ -1,5 +1,3 @@ -import type { AtomicReactRequest, ReactResponse } from '@/types/models'; - interface RequestOptions { apiKey?: string; correlationId?: string; @@ -50,14 +48,6 @@ type List = { list(query?: Q, options?: RequestOptions): Promise>; }; -type AtomicReact = { - react( - tokenId: string, - request: AtomicReactRequest, - options?: RequestOptions - ): Promise; -}; - export type { RequestOptions, PaginatedQuery, @@ -67,5 +57,4 @@ export type { Update, Delete, List, - AtomicReact, }; diff --git a/test/atomic-banks.test.ts b/test/atomic-banks.test.ts index 40afb73c..35724ba1 100644 --- a/test/atomic-banks.test.ts +++ b/test/atomic-banks.test.ts @@ -6,7 +6,7 @@ import { BT_TRACE_ID_HEADER, transformAtomicRequestSnakeCase, } from '@/common'; -import type { AtomicBank, UpdateAtomicBank, TokenType } from '@/types/models'; +import type { AtomicBank, UpdateAtomicBank } from '@/types/models'; import type { BasisTheory as IBasisTheory } from '@/types/sdk'; import { testCreate, @@ -172,193 +172,4 @@ describe('Atomic Banks', () => { await expectBasisTheoryApiError(promise, status); }); }); - - describe('react', () => { - test('should react', async () => { - const id = chance.string(); - const reactorId = chance.string(); - const tenantId = chance.string(); - const fingerprint = chance.string(); - const type = chance.string() as TokenType; - - /* eslint-disable camelcase */ - const requestParameters = { - snake_case: chance.string(), - camelCase: chance.string(), - object: { - snake_case: chance.string(), - camelCase: chance.string(), - }, - }; - const data = { - snake_case: chance.string(), - camelCase: chance.string(), - }; - /* eslint-enable camelcase */ - - const createdBy = chance.string(); - const createdAt = chance.string(); - const modifiedBy = chance.string(); - const modifiedAt = chance.string(); - - client.onPost(`/${id}/react`).reply( - 200, - /* eslint-disable camelcase */ - JSON.stringify({ - tokens: { - id, - tenant_id: tenantId, - fingerprint, - type, - data, - created_at: createdAt, - created_by: createdBy, - modified_at: modifiedAt, - modified_by: modifiedBy, - }, - raw: data, - }) - /* eslint-enable camelcase */ - ); - - expect( - await bt.atomicBanks.react(id, { - reactorId, - requestParameters, - }) - ).toStrictEqual({ - /* eslint-disable camelcase */ - tokens: { - id, - tenant_id: tenantId, - fingerprint, - type, - data, - created_at: createdAt, - created_by: createdBy, - modified_at: modifiedAt, - modified_by: modifiedBy, - }, - raw: data, - /* eslint-enable camelcase */ - }); - expect(client.history.post).toHaveLength(1); - expect(client.history.post[0].url).toStrictEqual(`/${id}/react`); - expect(client.history.post[0].data).toStrictEqual( - /* eslint-disable camelcase */ - JSON.stringify({ - reactor_id: reactorId, - request_parameters: requestParameters, - }) - /* eslint-enable camelcase */ - ); - expect(client.history.post[0].headers).toMatchObject({ - [API_KEY_HEADER]: expect.any(String), - }); - }); - - test('should react with options', async () => { - const id = chance.string(); - const reactorId = chance.string(); - const tenantId = chance.string(); - const fingerprint = chance.string(); - const type = chance.string() as TokenType; - - /* eslint-disable camelcase */ - const requestParameters = { - snake_case: chance.string(), - camelCase: chance.string(), - object: { - snake_case: chance.string(), - camelCase: chance.string(), - }, - }; - const data = { - snake_case: chance.string(), - camelCase: chance.string(), - }; - /* eslint-enable camelcase */ - - const createdBy = chance.string(); - const createdAt = chance.string(); - const modifiedBy = chance.string(); - const modifiedAt = chance.string(); - const _apiKey = chance.string(); - const correlationId = chance.string(); - - client.onPost(`/${id}/react`).reply( - 200, - /* eslint-disable camelcase */ - JSON.stringify({ - tokens: { - id, - tenant_id: tenantId, - fingerprint, - type, - data, - created_at: createdAt, - created_by: createdBy, - modified_at: modifiedAt, - modified_by: modifiedBy, - }, - raw: data, - }) - /* eslint-enable camelcase */ - ); - - expect( - await bt.atomicBanks.react( - id, - { - reactorId, - requestParameters, - }, - { - apiKey: _apiKey, - correlationId, - } - ) - ).toStrictEqual({ - /* eslint-disable camelcase */ - tokens: { - id, - tenant_id: tenantId, - fingerprint, - type, - data, - created_at: createdAt, - created_by: createdBy, - modified_at: modifiedAt, - modified_by: modifiedBy, - }, - raw: data, - /* eslint-enable camelcase */ - }); - expect(client.history.post).toHaveLength(1); - expect(client.history.post[0].url).toStrictEqual(`/${id}/react`); - expect(client.history.post[0].data).toStrictEqual( - /* eslint-disable camelcase */ - JSON.stringify({ - reactor_id: reactorId, - request_parameters: requestParameters, - }) - /* eslint-enable camelcase */ - ); - expect(client.history.post[0].headers).toMatchObject({ - [API_KEY_HEADER]: _apiKey, - [BT_TRACE_ID_HEADER]: correlationId, - }); - }); - - test('should reject with status >= 400 <= 599', async () => { - const id = chance.string(); - const status = errorStatus(); - - client.onPost(`/${id}/react`).reply(status); - - const promise = bt.atomicBanks.react(id, { reactorId: chance.string() }); - - await expectBasisTheoryApiError(promise, status); - }); - }); }); diff --git a/test/atomic-cards.test.ts b/test/atomic-cards.test.ts index 719c1c0e..de5fe4ab 100644 --- a/test/atomic-cards.test.ts +++ b/test/atomic-cards.test.ts @@ -3,7 +3,7 @@ import { Chance } from 'chance'; import { BasisTheory } from '@/BasisTheory'; import { API_KEY_HEADER, BT_TRACE_ID_HEADER } from '@/common'; import { transformAtomicRequestSnakeCase } from '@/common/utils'; -import type { AtomicCard, UpdateAtomicCard, TokenType } from '@/types/models'; +import type { AtomicCard, UpdateAtomicCard } from '@/types/models'; import type { BasisTheory as IBasisTheory } from '@/types/sdk'; import { testCreate, @@ -175,193 +175,4 @@ describe('Atomic Cards', () => { await expectBasisTheoryApiError(promise, status); }); }); - - describe('react', () => { - test('should react', async () => { - const id = chance.string(); - const reactorId = chance.string(); - const tenantId = chance.string(); - const fingerprint = chance.string(); - const type = chance.string() as TokenType; - - /* eslint-disable camelcase */ - const requestParameters = { - snake_case: chance.string(), - camelCase: chance.string(), - object: { - snake_case: chance.string(), - camelCase: chance.string(), - }, - }; - const data = { - snake_case: chance.string(), - camelCase: chance.string(), - }; - /* eslint-enable camelcase */ - - const createdBy = chance.string(); - const createdAt = chance.string(); - const modifiedBy = chance.string(); - const modifiedAt = chance.string(); - - client.onPost(`/${id}/react`).reply( - 200, - /* eslint-disable camelcase */ - JSON.stringify({ - tokens: { - id, - tenant_id: tenantId, - fingerprint, - type, - data, - created_at: createdAt, - created_by: createdBy, - modified_at: modifiedAt, - modified_by: modifiedBy, - }, - raw: data, - }) - /* eslint-enable camelcase */ - ); - - expect( - await bt.atomicCards.react(id, { - reactorId, - requestParameters, - }) - ).toStrictEqual({ - /* eslint-disable camelcase */ - tokens: { - id, - tenant_id: tenantId, - fingerprint, - type, - data, - created_at: createdAt, - created_by: createdBy, - modified_at: modifiedAt, - modified_by: modifiedBy, - }, - raw: data, - /* eslint-enable camelcase */ - }); - expect(client.history.post).toHaveLength(1); - expect(client.history.post[0].url).toStrictEqual(`/${id}/react`); - expect(client.history.post[0].data).toStrictEqual( - /* eslint-disable camelcase */ - JSON.stringify({ - reactor_id: reactorId, - request_parameters: requestParameters, - }) - /* eslint-enable camelcase */ - ); - expect(client.history.post[0].headers).toMatchObject({ - [API_KEY_HEADER]: expect.any(String), - }); - }); - - test('should react with options', async () => { - const id = chance.string(); - const reactorId = chance.string(); - const tenantId = chance.string(); - const fingerprint = chance.string(); - const type = chance.string() as TokenType; - - /* eslint-disable camelcase */ - const requestParameters = { - snake_case: chance.string(), - camelCase: chance.string(), - object: { - snake_case: chance.string(), - camelCase: chance.string(), - }, - }; - const data = { - snake_case: chance.string(), - camelCase: chance.string(), - }; - /* eslint-enable camelcase */ - - const createdBy = chance.string(); - const createdAt = chance.string(); - const modifiedBy = chance.string(); - const modifiedAt = chance.string(); - const _apiKey = chance.string(); - const correlationId = chance.string(); - - client.onPost(`/${id}/react`).reply( - 200, - /* eslint-disable camelcase */ - JSON.stringify({ - tokens: { - id, - tenant_id: tenantId, - fingerprint, - type, - data, - created_at: createdAt, - created_by: createdBy, - modified_at: modifiedAt, - modified_by: modifiedBy, - }, - raw: data, - }) - /* eslint-enable camelcase */ - ); - - expect( - await bt.atomicCards.react( - id, - { - reactorId, - requestParameters, - }, - { - apiKey: _apiKey, - correlationId, - } - ) - ).toStrictEqual({ - /* eslint-disable camelcase */ - tokens: { - id, - tenant_id: tenantId, - fingerprint, - type, - data, - created_at: createdAt, - created_by: createdBy, - modified_at: modifiedAt, - modified_by: modifiedBy, - }, - raw: data, - /* eslint-enable camelcase */ - }); - expect(client.history.post).toHaveLength(1); - expect(client.history.post[0].url).toStrictEqual(`/${id}/react`); - expect(client.history.post[0].data).toStrictEqual( - /* eslint-disable camelcase */ - JSON.stringify({ - reactor_id: reactorId, - request_parameters: requestParameters, - }) - /* eslint-enable camelcase */ - ); - expect(client.history.post[0].headers).toMatchObject({ - [API_KEY_HEADER]: _apiKey, - [BT_TRACE_ID_HEADER]: correlationId, - }); - }); - - test('should reject with status >= 400 <= 599', async () => { - const id = chance.string(); - const status = errorStatus(); - - client.onPost(`/${id}/react`).reply(status); - - const promise = bt.atomicCards.react(id, { reactorId: chance.string() }); - - await expectBasisTheoryApiError(promise, status); - }); - }); });