@basis-theory/basis-theory-js
Advanced tools
Comparing version
@@ -10,2 +10,4 @@ "use strict"; | ||
var _constants = require("./common/constants"); | ||
var _atomic = require("./atomic"); | ||
@@ -36,4 +38,5 @@ | ||
const defaultInitOptions = { | ||
environment: 'production', | ||
elements: false | ||
apiBaseUrl: _constants.DEFAULT_BASE_URL, | ||
elements: false, | ||
elementsBaseUrl: _constants.DEFAULT_ELEMENTS_BASE_URL | ||
}; | ||
@@ -84,41 +87,57 @@ exports.defaultInitOptions = defaultInitOptions; | ||
}); | ||
let baseUrl = this._initOptions.apiBaseUrl; | ||
try { | ||
const baseUrlObject = new URL(this.initOptions.apiBaseUrl); | ||
if (baseUrlObject.hostname === 'localhost') { | ||
baseUrlObject.protocol = 'http'; | ||
} else { | ||
baseUrlObject.protocol = 'https'; | ||
} | ||
baseUrl = baseUrlObject.toString().replace(/\/$/, ''); | ||
} catch (e) { | ||
throw new Error('Invalid format for the given API base url.'); | ||
} | ||
this._tokens = new _tokens.BasisTheoryTokens({ | ||
apiKey, | ||
baseURL: _common.SERVICES.tokens[this._initOptions.environment] | ||
baseURL: new URL(_constants.CLIENT_BASE_PATHS.tokens, baseUrl).toString() | ||
}); | ||
this._atomic = new _atomic.BasisTheoryAtomic({ | ||
apiKey, | ||
baseURL: _common.SERVICES.atomic[this._initOptions.environment] | ||
baseURL: new URL(_constants.CLIENT_BASE_PATHS.atomic, baseUrl).toString() | ||
}); | ||
this._applications = new _applications.BasisTheoryApplications({ | ||
apiKey, | ||
baseURL: _common.SERVICES.applications[this._initOptions.environment] | ||
baseURL: new URL(_constants.CLIENT_BASE_PATHS.applications, baseUrl).toString() | ||
}); | ||
this._tenants = new _tenants.BasisTheoryTenants({ | ||
apiKey, | ||
baseURL: _common.SERVICES.tenants[this._initOptions.environment] | ||
baseURL: new URL(_constants.CLIENT_BASE_PATHS.tenants, baseUrl).toString() | ||
}); | ||
this._logs = new _logs.BasisTheoryLogs({ | ||
apiKey, | ||
baseURL: _common.SERVICES.logs[this._initOptions.environment] | ||
baseURL: new URL(_constants.CLIENT_BASE_PATHS.logs, baseUrl).toString() | ||
}); | ||
this._reactorFormulas = new _reactorFormulas.BasisTheoryReactorFormulas({ | ||
apiKey, | ||
baseURL: _common.SERVICES.reactorFormulas[this._initOptions.environment] | ||
baseURL: new URL(_constants.CLIENT_BASE_PATHS.reactorFormulas, baseUrl).toString() | ||
}); | ||
this._reactors = new _reactors.BasisTheoryReactors({ | ||
apiKey, | ||
baseURL: _common.SERVICES.reactors[this._initOptions.environment] | ||
baseURL: new URL(_constants.CLIENT_BASE_PATHS.reactors, baseUrl).toString() | ||
}); | ||
this._atomicBanks = new _banks.BasisTheoryAtomicBanks({ | ||
apiKey, | ||
baseURL: _common.SERVICES.atomicBanks[this._initOptions.environment] | ||
baseURL: new URL(_constants.CLIENT_BASE_PATHS.atomicBanks, baseUrl).toString() | ||
}); | ||
this._atomicCards = new _cards.BasisTheoryAtomicCards({ | ||
apiKey, | ||
baseURL: _common.SERVICES.atomicCards[this._initOptions.environment] | ||
baseURL: new URL(_constants.CLIENT_BASE_PATHS.atomicCards, baseUrl).toString() | ||
}); | ||
this._permissions = new _permissions.BasisTheoryPermissions({ | ||
apiKey, | ||
baseURL: _common.SERVICES.permissions[this._initOptions.environment] | ||
baseURL: new URL(_constants.CLIENT_BASE_PATHS.permissions, baseUrl).toString() | ||
}); | ||
@@ -141,4 +160,12 @@ this._encryption = new _BasisTheoryEncryptionAdapters.BasisTheoryEncryptionAdapters(); | ||
async loadElements(apiKey) { | ||
let elementsBaseUrl; | ||
try { | ||
elementsBaseUrl = new URL(this.initOptions.elementsBaseUrl); | ||
} catch (e) { | ||
throw new Error('Invalid format for the given Elements base url.'); | ||
} | ||
const elements = await (0, _common.loadElements)(); | ||
await elements.init(apiKey, this.initOptions.environment); | ||
await elements.init(apiKey, elementsBaseUrl.toString().replace(/\/$/, '')); | ||
this.elements = elements; | ||
@@ -145,0 +172,0 @@ } |
@@ -1,4 +0,6 @@ | ||
import { ServicesMap } from '../types'; | ||
export declare const SERVICES: ServicesMap; | ||
import type { ClientsBasePathMap } from '../types'; | ||
export declare const API_KEY_HEADER = "X-API-KEY"; | ||
export declare const BT_TRACE_ID_HEADER = "bt-trace-id"; | ||
export declare const DEFAULT_BASE_URL: string; | ||
export declare const DEFAULT_ELEMENTS_BASE_URL: string; | ||
export declare const CLIENT_BASE_PATHS: ClientsBasePathMap; |
@@ -6,59 +6,23 @@ "use strict"; | ||
}); | ||
exports.BT_TRACE_ID_HEADER = exports.API_KEY_HEADER = exports.SERVICES = void 0; | ||
const SERVICES = { | ||
tokens: { | ||
production: `https://${"api.basistheory.com"}/tokens`, | ||
sandbox: `https://${"api-dev.basistheory.com"}/tokens`, | ||
local: `http://${"localhost:3333"}/tokens` | ||
}, | ||
atomic: { | ||
production: `https://${"api.basistheory.com"}/atomic`, | ||
sandbox: `https://${"api-dev.basistheory.com"}/atomic`, | ||
local: `http://${"localhost:3333"}/atomic` | ||
}, | ||
applications: { | ||
production: `https://${"api.basistheory.com"}/applications`, | ||
sandbox: `https://${"api-dev.basistheory.com"}/applications`, | ||
local: `http://${"localhost:3333"}/applications` | ||
}, | ||
tenants: { | ||
production: `https://${"api.basistheory.com"}/tenants/self`, | ||
sandbox: `https://${"api-dev.basistheory.com"}/tenants/self`, | ||
local: `http://${"localhost:3333"}/tenants/self` | ||
}, | ||
logs: { | ||
production: `https://${"api.basistheory.com"}/logs`, | ||
sandbox: `https://${"api-dev.basistheory.com"}/logs`, | ||
local: `http://${"localhost:3333"}/logs` | ||
}, | ||
reactorFormulas: { | ||
production: `https://${"api.basistheory.com"}/reactor-formulas`, | ||
sandbox: `https://${"api-dev.basistheory.com"}/reactor-formulas`, | ||
local: `http://${"localhost:3333"}/reactor-formulas` | ||
}, | ||
reactors: { | ||
production: `https://${"api.basistheory.com"}/reactors`, | ||
sandbox: `https://${"api-dev.basistheory.com"}/reactors`, | ||
local: `http://${"localhost:3333"}/reactors` | ||
}, | ||
atomicBanks: { | ||
production: `https://${"api.basistheory.com"}/atomic/banks`, | ||
sandbox: `https://${"api-dev.basistheory.com"}/atomic/banks`, | ||
local: `http://${"localhost:3333"}/atomic/banks` | ||
}, | ||
atomicCards: { | ||
production: `https://${"api.basistheory.com"}/atomic/cards`, | ||
sandbox: `https://${"api-dev.basistheory.com"}/atomic/cards`, | ||
local: `http://${"localhost:3333"}/atomic/cards` | ||
}, | ||
permissions: { | ||
production: `https://${"api.basistheory.com"}/permissions`, | ||
sandbox: `https://${"api-dev.basistheory.com"}/permissions`, | ||
local: `http://${"localhost:3333"}/permissions` | ||
} | ||
}; | ||
exports.SERVICES = SERVICES; | ||
exports.CLIENT_BASE_PATHS = exports.DEFAULT_ELEMENTS_BASE_URL = exports.DEFAULT_BASE_URL = exports.BT_TRACE_ID_HEADER = exports.API_KEY_HEADER = void 0; | ||
const API_KEY_HEADER = 'X-API-KEY'; | ||
exports.API_KEY_HEADER = API_KEY_HEADER; | ||
const BT_TRACE_ID_HEADER = 'bt-trace-id'; | ||
exports.BT_TRACE_ID_HEADER = BT_TRACE_ID_HEADER; | ||
exports.BT_TRACE_ID_HEADER = BT_TRACE_ID_HEADER; | ||
const DEFAULT_BASE_URL = `https://${"api.basistheory.com"}`; | ||
exports.DEFAULT_BASE_URL = DEFAULT_BASE_URL; | ||
const DEFAULT_ELEMENTS_BASE_URL = `https://${"elements.basistheory.com"}`; | ||
exports.DEFAULT_ELEMENTS_BASE_URL = DEFAULT_ELEMENTS_BASE_URL; | ||
const CLIENT_BASE_PATHS = { | ||
tokens: 'tokens', | ||
atomic: 'atomic', | ||
applications: 'applications', | ||
tenants: 'tenants/self', | ||
logs: 'logs', | ||
reactorFormulas: 'reactor-formulas', | ||
reactors: 'reactors', | ||
atomicBanks: 'atomic/banks', | ||
atomicCards: 'atomic/cards', | ||
permissions: 'permissions' | ||
}; | ||
exports.CLIENT_BASE_PATHS = CLIENT_BASE_PATHS; |
@@ -1,6 +0,5 @@ | ||
import { ServiceEnvironment } from '../types'; | ||
export interface BasisTheoryElements { | ||
} | ||
export interface BasisTheoryElementsInit extends BasisTheoryElements { | ||
init: (apiKey: string, environment: ServiceEnvironment) => Promise<BasisTheoryElements>; | ||
init: (apiKey: string, elementsBaseUrl: string) => Promise<BasisTheoryElements>; | ||
} |
{ | ||
"name": "@basis-theory/basis-theory-js", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"repository": "https://github.com/Basis-Theory/basis-theory-js", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0", |
@@ -52,2 +52,14 @@ # Basis Theory JS SDK (aka BasisTheory.js) | ||
### Setting a custom API Url | ||
You can set a custom API Url to be used across all clients when creating a new SDK instance. | ||
```javascript | ||
import { BasisTheory } from '@basis-theory/basis-theory-js'; | ||
const bt = await new BasisTheory().init('key_N88mVGsp3sCXkykyN2EFED', { | ||
apiBaseUrl: 'https://api.somedomain.com', | ||
}); // replace with your application key and api base URL. | ||
``` | ||
## Development | ||
@@ -54,0 +66,0 @@ |
import type { BasisTheoryElements } from './elements'; | ||
export declare type InitStatus = 'not-started' | 'in-progress' | 'done' | 'error'; | ||
export declare type ServiceEnvironment = 'production' | 'sandbox' | 'local'; | ||
export declare type ServiceUrlMap = { | ||
[key in ServiceEnvironment]: string; | ||
export declare type Clients = 'tokens' | 'atomic' | 'applications' | 'reactorFormulas' | 'reactors' | 'atomicBanks' | 'atomicCards' | 'permissions' | 'logs' | 'tenants'; | ||
export declare type ClientsBasePathMap = { | ||
[key in Clients]: string; | ||
}; | ||
export declare type Services = 'tokens' | 'atomic' | 'applications' | 'reactorFormulas' | 'reactors' | 'atomicBanks' | 'atomicCards' | 'permissions' | 'logs' | 'tenants'; | ||
export declare type ServicesMap = { | ||
[key in Services]: ServiceUrlMap; | ||
}; | ||
export declare type Providers = 'BROWSER' | 'NODE'; | ||
@@ -23,4 +19,5 @@ export declare const algorithm: readonly ["RSA", "AES"]; | ||
export interface BasisTheoryInitOptions { | ||
environment?: ServiceEnvironment; | ||
apiBaseUrl?: string; | ||
elements?: boolean; | ||
elementsBaseUrl?: string; | ||
} | ||
@@ -27,0 +24,0 @@ declare global { |
82
17.14%95013
-0.16%2043
-0.87%