-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
538 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { BasisTheoryProxy } from '@/proxy'; | ||
import type { | ||
Proxy as ElementsProxy, | ||
BasisTheoryElementsInternal, | ||
} from '@/types/elements'; | ||
import type { Proxy, ProxyRequestOptions } from '@/types/sdk'; | ||
|
||
const delegateProxy = ( | ||
elements?: BasisTheoryElementsInternal | ||
): new ( | ||
...args: ConstructorParameters<typeof BasisTheoryProxy> | ||
) => ElementsProxy & Proxy => | ||
class BasisTheoryProxyElementsDelegate | ||
extends BasisTheoryProxy | ||
implements ElementsProxy { | ||
public get(options?: ProxyRequestOptions): Promise<any> { | ||
if (elements !== undefined) { | ||
return elements.proxy.get(options); | ||
} | ||
|
||
return super.get(options); | ||
} | ||
|
||
public post(options?: ProxyRequestOptions): Promise<any> { | ||
if (elements !== undefined) { | ||
return elements.proxy.post(options); | ||
} | ||
|
||
return super.post(options); | ||
} | ||
|
||
public put(options?: ProxyRequestOptions): Promise<any> { | ||
if (elements !== undefined) { | ||
return elements.proxy.put(options); | ||
} | ||
|
||
return super.put(options); | ||
} | ||
|
||
public patch(options?: ProxyRequestOptions): Promise<any> { | ||
if (elements !== undefined) { | ||
return elements.proxy.patch(options); | ||
} | ||
|
||
return super.patch(options); | ||
} | ||
|
||
public delete(options?: ProxyRequestOptions): Promise<any> { | ||
if (elements !== undefined) { | ||
return elements.proxy.delete(options); | ||
} | ||
|
||
return super.delete(options); | ||
} | ||
}; | ||
|
||
export { delegateProxy }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { createRequestConfig, dataExtractor, proxyRaw } from '@/common'; | ||
import { BasisTheoryService } from '@/service'; | ||
import type { Proxy, ProxyRequestOptions } from '@/types/sdk'; | ||
|
||
type PROXY_METHODS = 'get' | 'post' | 'put' | 'patch' | 'delete'; | ||
|
||
export class BasisTheoryProxy extends BasisTheoryService implements Proxy { | ||
public get(options?: ProxyRequestOptions): Promise<any> { | ||
return this.proxyRequest('get', options); | ||
} | ||
|
||
public post(options?: ProxyRequestOptions): Promise<any> { | ||
return this.proxyRequest('post', options); | ||
} | ||
|
||
public put(options?: ProxyRequestOptions): Promise<any> { | ||
return this.proxyRequest('put', options); | ||
} | ||
|
||
public patch(options?: ProxyRequestOptions): Promise<any> { | ||
return this.proxyRequest('patch', options); | ||
} | ||
|
||
public delete(options?: ProxyRequestOptions): Promise<any> { | ||
return this.proxyRequest('delete', options); | ||
} | ||
|
||
private proxyRequest( | ||
method: PROXY_METHODS, | ||
options?: ProxyRequestOptions | ||
): Promise<any> { | ||
if (method === 'post' || method === 'put' || method === 'patch') { | ||
return this.client[method]( | ||
options?.path ?? '/', | ||
options?.body ?? undefined, | ||
createRequestConfig(options, { | ||
transformRequest: proxyRaw, | ||
transformResponse: proxyRaw, | ||
}) | ||
).then(dataExtractor); | ||
} | ||
|
||
return this.client[method]( | ||
options?.path ?? '/', | ||
createRequestConfig(options, { | ||
transformRequest: proxyRaw, | ||
transformResponse: proxyRaw, | ||
}) | ||
).then(dataExtractor); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './BasisTheoryProxy'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './tokenize'; | ||
export * from './tokens'; | ||
export * from './proxy'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import type { ProxyRequestOptions } from '@/types/sdk'; | ||
|
||
interface Proxy { | ||
get(options?: ProxyRequestOptions): Promise<any>; | ||
post(options?: ProxyRequestOptions): Promise<any>; | ||
patch(options?: ProxyRequestOptions): Promise<any>; | ||
put(options?: ProxyRequestOptions): Promise<any>; | ||
delete(options?: ProxyRequestOptions): Promise<any>; | ||
} | ||
|
||
export type { Proxy }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import type { RequestOptions } from './shared'; | ||
|
||
interface Proxy { | ||
get(options?: ProxyRequestOptions): Promise<any>; | ||
post(options?: ProxyRequestOptions): Promise<any>; | ||
patch(options?: ProxyRequestOptions): Promise<any>; | ||
put(options?: ProxyRequestOptions): Promise<any>; | ||
delete(options?: ProxyRequestOptions): Promise<any>; | ||
} | ||
|
||
type BasisTheoryProxyHeaders = { | ||
[key: string]: string; | ||
'BT-PROXY-URL': string; | ||
'BT-PROXY-KEY': string; | ||
}; | ||
|
||
type ProxyHeaders = Partial<BasisTheoryProxyHeaders>; | ||
|
||
type BasisTheoryQueryParams = { | ||
[key: string]: string; | ||
'bt-proxy-key': string; | ||
}; | ||
|
||
type ProxyQuery = Partial<BasisTheoryQueryParams>; | ||
|
||
interface ProxyRequestOptions extends RequestOptions { | ||
path?: string; | ||
query?: ProxyQuery; | ||
headers?: ProxyHeaders; | ||
body?: unknown; | ||
} | ||
|
||
export type { Proxy, ProxyRequestOptions, ProxyHeaders, ProxyQuery }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.