@fiatconnect/fiatconnect-sdk
Advanced tools
Comparing version 0.3.2 to 0.3.3
@@ -5,2 +5,9 @@ # Changelog | ||
### [0.3.3](https://github.com/fiatconnect/fiatconnect-sdk/compare/v0.3.2...v0.3.3) (2022-07-15) | ||
### Features | ||
* **client:** handle cookies based on platform ([#36](https://github.com/fiatconnect/fiatconnect-sdk/issues/36)) ([fd0b277](https://github.com/fiatconnect/fiatconnect-sdk/commit/fd0b2774e1a655b5c23441b46ff25843cf4ad240)) | ||
### [0.3.2](https://github.com/fiatconnect/fiatconnect-sdk/compare/v0.3.1...v0.3.2) (2022-06-27) | ||
@@ -7,0 +14,0 @@ |
import { DeleteFiatAccountRequestParams, GetFiatAccountsResponse, KycRequestParams, KycStatusResponse, PostFiatAccountRequestBody, PostFiatAccountResponse, QuoteRequestBody, QuoteResponse, TransferResponse, TransferStatusRequestParams, TransferStatusResponse, ClockResponse, FiatAccountSchema, KycSchema } from '@fiatconnect/fiatconnect-types'; | ||
import fetch from 'cross-fetch'; | ||
import { Result } from '@badrap/result'; | ||
import { AddKycParams, ResponseError, FiatConnectApiClient, FiatConnectClientConfig, TransferRequestParams, ClockDiffParams, ClockDiffResult, LoginParams } from './types'; | ||
export declare class FiatConnectClient implements FiatConnectApiClient { | ||
export declare class FiatConnectClientImpl implements FiatConnectApiClient { | ||
config: FiatConnectClientConfig; | ||
signingFunction: (message: string) => Promise<string>; | ||
_sessionExpiry?: Date; | ||
constructor(config: FiatConnectClientConfig, signingFunction: (message: string) => Promise<string>); | ||
fetchImpl: typeof fetch; | ||
constructor(config: FiatConnectClientConfig, signingFunction: (message: string) => Promise<string>, fetchImpl: typeof fetch); | ||
_getAuthHeader(): { | ||
@@ -96,1 +98,4 @@ Authorization: string; | ||
} | ||
export declare class FiatConnectClientWithCookie extends FiatConnectClientImpl { | ||
constructor(config: FiatConnectClientConfig, signingFunction: (message: string) => Promise<string>); | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.FiatConnectClient = void 0; | ||
exports.FiatConnectClientWithCookie = exports.FiatConnectClientImpl = void 0; | ||
const tslib_1 = require("tslib"); | ||
const fiatconnect_types_1 = require("@fiatconnect/fiatconnect-types"); | ||
const fetch_cookie_1 = tslib_1.__importDefault(require("fetch-cookie")); | ||
const node_fetch_1 = tslib_1.__importDefault(require("node-fetch")); | ||
const cross_fetch_1 = tslib_1.__importDefault(require("cross-fetch")); | ||
const siwe_1 = require("siwe"); | ||
@@ -17,7 +16,7 @@ const result_1 = require("@badrap/result"); | ||
const SESSION_DURATION_MS = 14400000; // 4 hours | ||
const fetch = (0, fetch_cookie_1.default)(node_fetch_1.default); | ||
class FiatConnectClient { | ||
constructor(config, signingFunction) { | ||
class FiatConnectClientImpl { | ||
constructor(config, signingFunction, fetchImpl) { | ||
this.config = config; | ||
this.signingFunction = signingFunction; | ||
this.fetchImpl = fetchImpl; | ||
} | ||
@@ -87,3 +86,3 @@ _getAuthHeader() { | ||
}; | ||
const response = await fetch(`${this.config.baseUrl}/auth/login`, { | ||
const response = await this.fetchImpl(`${this.config.baseUrl}/auth/login`, { | ||
method: 'POST', | ||
@@ -107,3 +106,3 @@ headers: Object.assign({ 'Content-Type': 'application/json' }, this._getAuthHeader()), | ||
try { | ||
const response = await fetch(`${this.config.baseUrl}/quote/${inOrOut}`, { | ||
const response = await this.fetchImpl(`${this.config.baseUrl}/quote/${inOrOut}`, { | ||
method: 'POST', | ||
@@ -171,3 +170,3 @@ headers: this._getAuthHeader(), | ||
try { | ||
const response = await fetch(`${this.config.baseUrl}/clock`, { | ||
const response = await this.fetchImpl(`${this.config.baseUrl}/clock`, { | ||
method: 'GET', | ||
@@ -204,3 +203,3 @@ headers: this._getAuthHeader(), | ||
await this._ensureLogin(); | ||
const response = await fetch(`${this.config.baseUrl}/kyc/${params.kycSchemaName}`, { | ||
const response = await this.fetchImpl(`${this.config.baseUrl}/kyc/${params.kycSchemaName}`, { | ||
method: 'POST', | ||
@@ -226,3 +225,3 @@ headers: Object.assign({ 'Content-Type': 'application/json' }, this._getAuthHeader()), | ||
await this._ensureLogin(); | ||
const response = await fetch(`${this.config.baseUrl}/kyc/${params.kycSchema}`, { | ||
const response = await this.fetchImpl(`${this.config.baseUrl}/kyc/${params.kycSchema}`, { | ||
method: 'DELETE', | ||
@@ -247,3 +246,3 @@ headers: this._getAuthHeader(), | ||
await this._ensureLogin(); | ||
const response = await fetch(`${this.config.baseUrl}/kyc/${params.kycSchema}/status`, { | ||
const response = await this.fetchImpl(`${this.config.baseUrl}/kyc/${params.kycSchema}/status`, { | ||
method: 'GET', | ||
@@ -268,3 +267,3 @@ headers: this._getAuthHeader(), | ||
await this._ensureLogin(); | ||
const response = await fetch(`${this.config.baseUrl}/accounts`, { | ||
const response = await this.fetchImpl(`${this.config.baseUrl}/accounts`, { | ||
method: 'POST', | ||
@@ -290,3 +289,3 @@ headers: Object.assign({ 'Content-Type': 'application/json' }, this._getAuthHeader()), | ||
await this._ensureLogin(); | ||
const response = await fetch(`${this.config.baseUrl}/accounts`, { | ||
const response = await this.fetchImpl(`${this.config.baseUrl}/accounts`, { | ||
method: 'GET', | ||
@@ -311,3 +310,3 @@ headers: this._getAuthHeader(), | ||
await this._ensureLogin(); | ||
const response = await fetch(`${this.config.baseUrl}/accounts/${params.fiatAccountId}`, { | ||
const response = await this.fetchImpl(`${this.config.baseUrl}/accounts/${params.fiatAccountId}`, { | ||
method: 'DELETE', | ||
@@ -332,3 +331,3 @@ headers: this._getAuthHeader(), | ||
await this._ensureLogin(); | ||
const response = await fetch(`${this.config.baseUrl}/transfer/in`, { | ||
const response = await this.fetchImpl(`${this.config.baseUrl}/transfer/in`, { | ||
method: 'POST', | ||
@@ -354,3 +353,3 @@ headers: Object.assign({ 'Content-Type': 'application/json', 'Idempotency-Key': params.idempotencyKey }, this._getAuthHeader()), | ||
await this._ensureLogin(); | ||
const response = await fetch(`${this.config.baseUrl}/transfer/out`, { | ||
const response = await this.fetchImpl(`${this.config.baseUrl}/transfer/out`, { | ||
method: 'POST', | ||
@@ -376,3 +375,3 @@ headers: Object.assign({ 'Content-Type': 'application/json', 'Idempotency-Key': params.idempotencyKey }, this._getAuthHeader()), | ||
await this._ensureLogin(); | ||
const response = await fetch(`${this.config.baseUrl}/transfer/${params.transferId}/status`, { | ||
const response = await this.fetchImpl(`${this.config.baseUrl}/transfer/${params.transferId}/status`, { | ||
method: 'GET', | ||
@@ -392,3 +391,3 @@ headers: this._getAuthHeader(), | ||
} | ||
exports.FiatConnectClient = FiatConnectClient; | ||
exports.FiatConnectClientImpl = FiatConnectClientImpl; | ||
/** | ||
@@ -420,2 +419,8 @@ * handleError accepts three types of inputs: | ||
} | ||
class FiatConnectClientWithCookie extends FiatConnectClientImpl { | ||
constructor(config, signingFunction) { | ||
super(config, signingFunction, cross_fetch_1.default); | ||
} | ||
} | ||
exports.FiatConnectClientWithCookie = FiatConnectClientWithCookie; | ||
//# sourceMappingURL=fiat-connect-client.js.map |
@@ -1,2 +0,7 @@ | ||
export { FiatConnectClient } from './fiat-connect-client'; | ||
import 'cross-fetch/polyfill'; | ||
import { FiatConnectClientImpl } from './fiat-connect-client'; | ||
import { FiatConnectClientConfig } from './types'; | ||
export * from './types'; | ||
export declare class FiatConnectClient extends FiatConnectClientImpl { | ||
constructor(config: FiatConnectClientConfig, signingFunction: (message: string) => Promise<string>); | ||
} |
@@ -5,5 +5,11 @@ "use strict"; | ||
const tslib_1 = require("tslib"); | ||
var fiat_connect_client_1 = require("./fiat-connect-client"); | ||
Object.defineProperty(exports, "FiatConnectClient", { enumerable: true, get: function () { return fiat_connect_client_1.FiatConnectClient; } }); | ||
require("cross-fetch/polyfill"); | ||
const fiat_connect_client_1 = require("./fiat-connect-client"); | ||
tslib_1.__exportStar(require("./types"), exports); | ||
class FiatConnectClient extends fiat_connect_client_1.FiatConnectClientImpl { | ||
constructor(config, signingFunction) { | ||
super(config, signingFunction, fetch); | ||
} | ||
} | ||
exports.FiatConnectClient = FiatConnectClient; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@fiatconnect/fiatconnect-sdk", | ||
"version": "0.3.2", | ||
"version": "0.3.3", | ||
"description": "A helper libary for wallets to integrate with FiatConnect APIs", | ||
@@ -20,3 +20,5 @@ "scripts": { | ||
], | ||
"main": "dist/index.js", | ||
"main": "dist/index-node.js", | ||
"browser": "dist/index.js", | ||
"react-native": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
@@ -54,5 +56,5 @@ "repository": "git@github.com:fiatconnect/fiatconnect-sdk.git", | ||
"@fiatconnect/fiatconnect-types": "^6.0.0", | ||
"cross-fetch": "^3.1.5", | ||
"ethers": "^5.6.4", | ||
"fetch-cookie": "^2.0.3", | ||
"node-fetch": "^2.6.6", | ||
"siwe": "^1.1.6", | ||
@@ -59,0 +61,0 @@ "tslib": "^2.4.0" |
@@ -20,4 +20,3 @@ import { | ||
} from '@fiatconnect/fiatconnect-types' | ||
import fetchCookie from 'fetch-cookie' | ||
import nodeFetch from 'node-fetch' | ||
import fetch from 'cross-fetch' | ||
import { generateNonce, SiweMessage } from 'siwe' | ||
@@ -43,8 +42,7 @@ import { Result } from '@badrap/result' | ||
const fetch = fetchCookie(nodeFetch) | ||
export class FiatConnectClient implements FiatConnectApiClient { | ||
export class FiatConnectClientImpl implements FiatConnectApiClient { | ||
config: FiatConnectClientConfig | ||
signingFunction: (message: string) => Promise<string> | ||
_sessionExpiry?: Date | ||
fetchImpl: typeof fetch | ||
@@ -54,5 +52,7 @@ constructor( | ||
signingFunction: (message: string) => Promise<string>, | ||
fetchImpl: typeof fetch, | ||
) { | ||
this.config = config | ||
this.signingFunction = signingFunction | ||
this.fetchImpl = fetchImpl | ||
} | ||
@@ -128,10 +128,13 @@ | ||
const response = await fetch(`${this.config.baseUrl}/auth/login`, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
...this._getAuthHeader(), | ||
const response = await this.fetchImpl( | ||
`${this.config.baseUrl}/auth/login`, | ||
{ | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
...this._getAuthHeader(), | ||
}, | ||
body: JSON.stringify(body), | ||
}, | ||
body: JSON.stringify(body), | ||
}) | ||
) | ||
@@ -156,7 +159,10 @@ if (!response.ok) { | ||
try { | ||
const response = await fetch(`${this.config.baseUrl}/quote/${inOrOut}`, { | ||
method: 'POST', | ||
headers: this._getAuthHeader(), | ||
body: JSON.stringify(body), | ||
}) | ||
const response = await this.fetchImpl( | ||
`${this.config.baseUrl}/quote/${inOrOut}`, | ||
{ | ||
method: 'POST', | ||
headers: this._getAuthHeader(), | ||
body: JSON.stringify(body), | ||
}, | ||
) | ||
const data = await response.json() | ||
@@ -229,3 +235,3 @@ if (!response.ok) { | ||
try { | ||
const response = await fetch(`${this.config.baseUrl}/clock`, { | ||
const response = await this.fetchImpl(`${this.config.baseUrl}/clock`, { | ||
method: 'GET', | ||
@@ -270,3 +276,3 @@ headers: this._getAuthHeader(), | ||
await this._ensureLogin() | ||
const response = await fetch( | ||
const response = await this.fetchImpl( | ||
`${this.config.baseUrl}/kyc/${params.kycSchemaName}`, | ||
@@ -300,3 +306,3 @@ { | ||
await this._ensureLogin() | ||
const response = await fetch( | ||
const response = await this.fetchImpl( | ||
`${this.config.baseUrl}/kyc/${params.kycSchema}`, | ||
@@ -326,3 +332,3 @@ { | ||
await this._ensureLogin() | ||
const response = await fetch( | ||
const response = await this.fetchImpl( | ||
`${this.config.baseUrl}/kyc/${params.kycSchema}/status`, | ||
@@ -352,3 +358,3 @@ { | ||
await this._ensureLogin() | ||
const response = await fetch(`${this.config.baseUrl}/accounts`, { | ||
const response = await this.fetchImpl(`${this.config.baseUrl}/accounts`, { | ||
method: 'POST', | ||
@@ -379,3 +385,3 @@ headers: { | ||
await this._ensureLogin() | ||
const response = await fetch(`${this.config.baseUrl}/accounts`, { | ||
const response = await this.fetchImpl(`${this.config.baseUrl}/accounts`, { | ||
method: 'GET', | ||
@@ -402,3 +408,3 @@ headers: this._getAuthHeader(), | ||
await this._ensureLogin() | ||
const response = await fetch( | ||
const response = await this.fetchImpl( | ||
`${this.config.baseUrl}/accounts/${params.fiatAccountId}`, | ||
@@ -428,11 +434,14 @@ { | ||
await this._ensureLogin() | ||
const response = await fetch(`${this.config.baseUrl}/transfer/in`, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'Idempotency-Key': params.idempotencyKey, | ||
...this._getAuthHeader(), | ||
const response = await this.fetchImpl( | ||
`${this.config.baseUrl}/transfer/in`, | ||
{ | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'Idempotency-Key': params.idempotencyKey, | ||
...this._getAuthHeader(), | ||
}, | ||
body: JSON.stringify(params.data), | ||
}, | ||
body: JSON.stringify(params.data), | ||
}) | ||
) | ||
const data = await response.json() | ||
@@ -456,11 +465,14 @@ if (!response.ok) { | ||
await this._ensureLogin() | ||
const response = await fetch(`${this.config.baseUrl}/transfer/out`, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'Idempotency-Key': params.idempotencyKey, | ||
...this._getAuthHeader(), | ||
const response = await this.fetchImpl( | ||
`${this.config.baseUrl}/transfer/out`, | ||
{ | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'Idempotency-Key': params.idempotencyKey, | ||
...this._getAuthHeader(), | ||
}, | ||
body: JSON.stringify(params.data), | ||
}, | ||
body: JSON.stringify(params.data), | ||
}) | ||
) | ||
const data = await response.json() | ||
@@ -484,3 +496,3 @@ if (!response.ok) { | ||
await this._ensureLogin() | ||
const response = await fetch( | ||
const response = await this.fetchImpl( | ||
`${this.config.baseUrl}/transfer/${params.transferId}/status`, | ||
@@ -529,1 +541,10 @@ { | ||
} | ||
export class FiatConnectClientWithCookie extends FiatConnectClientImpl { | ||
constructor( | ||
config: FiatConnectClientConfig, | ||
signingFunction: (message: string) => Promise<string>, | ||
) { | ||
super(config, signingFunction, fetch) | ||
} | ||
} |
@@ -1,2 +0,13 @@ | ||
export { FiatConnectClient } from './fiat-connect-client' | ||
import 'cross-fetch/polyfill' | ||
import { FiatConnectClientImpl } from './fiat-connect-client' | ||
import { FiatConnectClientConfig } from './types' | ||
export * from './types' | ||
export class FiatConnectClient extends FiatConnectClientImpl { | ||
constructor( | ||
config: FiatConnectClientConfig, | ||
signingFunction: (message: string) => Promise<string>, | ||
) { | ||
super(config, signingFunction, fetch) | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
109994
30
2367
3
+ Addedcross-fetch@^3.1.5
+ Addedcross-fetch@3.1.8(transitive)
- Removednode-fetch@^2.6.6