Skip to content

Commit

Permalink
feat: add application keys endpoints (#412)
Browse files Browse the repository at this point in the history
* feat: adds application keys endpoints

* test: add `createKey` to application create

* fix: typo
  • Loading branch information
kevinperaza committed May 2, 2024
1 parent bf0ada4 commit 2b2be74
Show file tree
Hide file tree
Showing 12 changed files with 318 additions and 16 deletions.
39 changes: 26 additions & 13 deletions src/BasisTheory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import type {
} from '@/types/elements';
import type { TokenizeData } from '@/types/models';
import type {
ApplicationKeys,
Applications,
ApplicationTemplates,
BasisTheory as IBasisTheory,
Expand All @@ -38,11 +39,12 @@ import type {
RequestOptions,
Sessions,
Tenants,
ThreeDS,
Tokenize,
Tokens,
ThreeDS,
} from '@/types/sdk';
import { BasisTheoryApplicationTemplates } from './application-templates';
import { BasisTheoryApplicationKeys } from './applicationKeys';
import { BasisTheoryApplications } from './applications';
import {
assertInit,
Expand Down Expand Up @@ -76,36 +78,38 @@ export class BasisTheory
implements BasisTheoryInit, IBasisTheory, BasisTheoryElements {
private _initStatus: BasisTheoryInitStatus = 'not-started';

private _initOptions?: Required<BasisTheoryInitOptions>;

private _tokens?: Tokens & ElementsTokens;

private _tokenize?: Tokenize & ElementsTokenize;

private _elements?: BasisTheoryElementsInternal;
private _applicationKeys?: BasisTheoryApplicationKeys;

private _applications?: BasisTheoryApplications;

private _applicationTemplates?: BasisTheoryApplicationTemplates;

private _tenants?: BasisTheoryTenants;

private _logs?: BasisTheoryLogs;
private _elements?: BasisTheoryElementsInternal;

private _reactorFormulas?: BasisTheoryReactorFormulas;
private _initOptions?: Required<BasisTheoryInitOptions>;

private _reactors?: BasisTheoryReactors;
private _logs?: BasisTheoryLogs;

private _permissions?: BasisTheoryPermissions;

private _proxies?: Proxies;

private _proxy?: Proxy & ElementsProxy;

private _reactorFormulas?: BasisTheoryReactorFormulas;

private _reactors?: BasisTheoryReactors;

private _sessions?: Sessions;

private _tenants?: BasisTheoryTenants;

private _threeds?: ThreeDS;

private _tokenize?: Tokenize & ElementsTokenize;

private _tokens?: Tokens & ElementsTokens;

public init(
apiKey: string | undefined,
options?: BasisTheoryInitOptionsWithoutElements
Expand Down Expand Up @@ -171,6 +175,11 @@ export class BasisTheory
baseURL: new URL(CLIENT_BASE_PATHS.applications, baseUrl).toString(),
appInfo,
});
this._applicationKeys = new BasisTheoryApplicationKeys({
apiKey,
baseURL: new URL(CLIENT_BASE_PATHS.applicationKeys, baseUrl).toString(),
appInfo,
});
this._applicationTemplates = new BasisTheoryApplicationTemplates({
apiKey,
baseURL: new URL(
Expand Down Expand Up @@ -324,6 +333,10 @@ export class BasisTheory
return assertInit(this._applications);
}

public get applicationKeys(): ApplicationKeys {
return assertInit(this._applicationKeys);
}

public get applicationTemplates(): ApplicationTemplates {
return assertInit(this._applicationTemplates);
}
Expand Down
35 changes: 35 additions & 0 deletions src/applicationKeys/BasisTheoryApplicationKeys.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { dataExtractor } from '@/common';
import { BasisTheoryService } from '@/service';
import { CrudBuilder } from '@/service/CrudBuilder';
import type { ApplicationKey } from '@/types/models';

export const BasisTheoryApplicationKeys = new CrudBuilder(
class BasisTheoryApplicationKeys extends BasisTheoryService {
public create(applicationId: string): Promise<ApplicationKey> {
return this.client.post(`${applicationId}/keys`).then(dataExtractor);
}

public get(applicationId: string): Promise<ApplicationKey[]> {
return this.client.get(`${applicationId}/keys`).then(dataExtractor);
}

public getById(
applicationId: string,
keyId: string
): Promise<ApplicationKey> {
return this.client
.get(`${applicationId}/keys/${keyId}`)
.then(dataExtractor);
}

public delete(applicationId: string, keyId: string): Promise<void> {
return this.client
.delete(`${applicationId}/keys/${keyId}`)
.then(dataExtractor);
}
}
).build();

export type BasisTheoryApplicationKeys = InstanceType<
typeof BasisTheoryApplicationKeys
>;
1 change: 1 addition & 0 deletions src/applicationKeys/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { BasisTheoryApplicationKeys } from './BasisTheoryApplicationKeys';
3 changes: 3 additions & 0 deletions src/applications/BasisTheoryApplications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ export const BasisTheoryApplications = new CrudBuilder(
.then(dataExtractor);
}

/**
* @deprecated This method is deprecated. Use Terraform or https://portal.basistheory.com to manage keys instead.
*/
public regenerateKey(
id: string,
options?: RequestOptions
Expand Down
1 change: 1 addition & 0 deletions src/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const CLIENT_BASE_PATHS: BasisTheoryServicesBasePathMap = {
tokens: 'tokens',
tokenize: 'tokenize',
applications: 'applications',
applicationKeys: 'applications',
applicationTemplates: 'application-templates',
tenants: 'tenants/self',
logs: 'logs',
Expand Down
16 changes: 14 additions & 2 deletions src/types/models/applications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ interface Application extends Auditable {
id: string;
tenantId: string;
name?: string;
/**
* @deprecated use `keys` instead.
*/
key?: string;
keys?: ApplicationKey[];
type: ApplicationType;
permissions?: string[];
rules?: AccessRule[];
Expand All @@ -32,16 +36,24 @@ type Condition = {
value: string;
};

type ApplicationKey = {
id?: string;
key?: string;
createdAt?: string;
createdBy?: string;
};

type CreateApplication = Pick<
Application,
'name' | 'type' | 'permissions' | 'rules' | 'expiresAt'
>;
> & { createKey?: boolean };

type UpdateApplication = Pick<Application, 'name' | 'permissions' | 'rules'>;

export type {
ApplicationType,
Application,
ApplicationKey,
ApplicationType,
CreateApplication,
TransformType,
UpdateApplication,
Expand Down
2 changes: 2 additions & 0 deletions src/types/sdk/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type {
Tokens,
ThreeDS,
} from './services';
import { ApplicationKeys } from './services/applicationKeys';

interface ApplicationInfo {
name?: string;
Expand Down Expand Up @@ -51,6 +52,7 @@ interface BasisTheoryInit {
}
interface BasisTheory extends Tokenize {
applications: Applications;
applicationKeys: ApplicationKeys;
applicationTemplates: ApplicationTemplates;
/**
* @description Allows you to utilize element values in requests to a third-party API using our HTTP client service.
Expand Down
10 changes: 10 additions & 0 deletions src/types/sdk/services/applicationKeys.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { ApplicationKey } from '@/types/models';

interface ApplicationKeys {
create(id: string): Promise<ApplicationKey>;
delete(applicationId: string, keyId: string): Promise<void>;
get(applicationId: string): Promise<ApplicationKey[]>;
getById(applicationId: string, keyId: string): Promise<ApplicationKey>;
}

export type { ApplicationKeys };
1 change: 1 addition & 0 deletions src/types/sdk/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export * from './shared';
export * from './tokens';
export * from './tokenize';
export * from './applications';
export * from './applicationKeys';
export * from './tenants';
export * from './logs';
export * from './reactor-formulas';
Expand Down

0 comments on commit 2b2be74

Please sign in to comment.