From 10850929c43a1f2a1ee07d95c9c2d7c51c138c60 Mon Sep 17 00:00:00 2001 From: Noah Passalacqua Date: Tue, 31 Mar 2020 12:41:31 -0500 Subject: [PATCH 01/20] Create Account and Transfer classes. aoeu --- .gitignore | 2 + README.md | 6 +- dist/Account.d.ts | 29 ++++ dist/Account.d.ts.map | 1 + dist/Account.js | 107 +++++++++++++ dist/Account/IAccountData.d.ts | 28 ++++ dist/Account/IAccountData.d.ts.map | 1 + dist/Account/IAccountData.js | 2 + dist/Authed.d.ts | 24 +++ dist/Authed.d.ts.map | 1 + dist/Authed.js | 22 +++ dist/Model.d.ts | 8 + dist/Model.d.ts.map | 1 + dist/Model.js | 30 ++++ dist/Transfer.d.ts | 34 ++++ dist/Transfer.d.ts.map | 1 + dist/Transfer.js | 95 +++++++++++ dist/Transfer/ICreateTransferParams.d.ts | 16 ++ dist/Transfer/ICreateTransferParams.d.ts.map | 1 + dist/Transfer/ICreateTransferParams.js | 2 + dist/Transfer/ITransferData.d.ts | 46 ++++++ dist/Transfer/ITransferData.d.ts.map | 1 + dist/Transfer/ITransferData.js | 2 + dist/utils/API.d.ts | 12 ++ dist/utils/API.d.ts.map | 1 + dist/utils/API.js | 108 +++++++++++++ dist/utils/Request.d.ts | 13 ++ dist/utils/Request.js | 98 ++++++++++++ dist/wyre.d.ts | 21 +-- dist/wyre.d.ts.map | 1 + dist/wyre.js | 159 +++++++++---------- package-lock.json | 73 ++++++++- package.json | 4 +- src/Account.ts | 39 +++++ src/Account/IAccountData.ts | 28 ++++ src/Authed.ts | 34 ++++ src/Model.ts | 32 ++++ src/Transfer.ts | 49 ++++++ src/Transfer/ICreateTransferParams.ts | 15 ++ src/Transfer/ITransferData.ts | 48 ++++++ src/utils/API.ts | 110 +++++++++++++ src/wyre.ts | 135 +++------------- tsconfig.json | 33 ++-- 43 files changed, 1231 insertions(+), 242 deletions(-) create mode 100644 dist/Account.d.ts create mode 100644 dist/Account.d.ts.map create mode 100644 dist/Account.js create mode 100644 dist/Account/IAccountData.d.ts create mode 100644 dist/Account/IAccountData.d.ts.map create mode 100644 dist/Account/IAccountData.js create mode 100644 dist/Authed.d.ts create mode 100644 dist/Authed.d.ts.map create mode 100644 dist/Authed.js create mode 100644 dist/Model.d.ts create mode 100644 dist/Model.d.ts.map create mode 100644 dist/Model.js create mode 100644 dist/Transfer.d.ts create mode 100644 dist/Transfer.d.ts.map create mode 100644 dist/Transfer.js create mode 100644 dist/Transfer/ICreateTransferParams.d.ts create mode 100644 dist/Transfer/ICreateTransferParams.d.ts.map create mode 100644 dist/Transfer/ICreateTransferParams.js create mode 100644 dist/Transfer/ITransferData.d.ts create mode 100644 dist/Transfer/ITransferData.d.ts.map create mode 100644 dist/Transfer/ITransferData.js create mode 100644 dist/utils/API.d.ts create mode 100644 dist/utils/API.d.ts.map create mode 100644 dist/utils/API.js create mode 100644 dist/utils/Request.d.ts create mode 100644 dist/utils/Request.js create mode 100644 dist/wyre.d.ts.map create mode 100644 src/Account.ts create mode 100644 src/Account/IAccountData.ts create mode 100644 src/Authed.ts create mode 100644 src/Model.ts create mode 100644 src/Transfer.ts create mode 100644 src/Transfer/ICreateTransferParams.ts create mode 100644 src/Transfer/ITransferData.ts create mode 100644 src/utils/API.ts diff --git a/.gitignore b/.gitignore index 93f1361..060587b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ node_modules npm-debug.log + +.idea diff --git a/README.md b/README.md index 909b2af..28f6e17 100644 --- a/README.md +++ b/README.md @@ -93,15 +93,15 @@ Constructor parameters: | secretKey | your environment-specific Wyre API secret | baseUrl | specifies the Wyre environment you'd like to use. please use either:
`https://api.sendwyre.com` for production
`https://api.testwyre.com` for testwyre | format | the data format you're requesting.
`json` for straight JSON
`json_numberstring` for JSON with all decimals as strings (see [above](#regarding-decimal-numbers)] -| options | options that are passed to the underlying [Request](https://github.com/request/request) for _every_ request +| options | options that are passed to the underlying [API](https://github.com/request/request) for _every_ request -Note that the ability to override options used by the [Request](https://github.com/request/request) client is +Note that the ability to override options used by the [API](https://github.com/request/request) client is available both generally as well as per-request. Timeouts may be adjusted via the `options.timeout` (expressed in milliseconds). This may be controlled via the constructor, or per-request (as with all options). -### Request API +### API API Each of these methods performs a single Wyre API request and returns a promise for the resulting API response. diff --git a/dist/Account.d.ts b/dist/Account.d.ts new file mode 100644 index 0000000..296854b --- /dev/null +++ b/dist/Account.d.ts @@ -0,0 +1,29 @@ +import Model from './Model'; +import Transfer from './Transfer'; +import type { CreateTransferParams } from './Transfer/ICreateTransferParams'; +import type { IAccountData, IProfileField } from './Account/IAccountData'; +import API from './utils/API'; +export default class Account extends Model implements IAccountData { + id: string; + status: string; + type: string; + country: string; + createdAt: number; + depositAddresses: { + ETH: string; + BTC: string; + }; + totalBalances: { + BTC: number; + ETH: number; + }; + availableBalances: { + BTC: number; + ETH: number; + }; + profileFields: Array; + static fetch(id?: string, api?: API): Promise; + createTransfer(params: CreateTransferParams): Promise; + getTransfers(): Promise>; +} +//# sourceMappingURL=Account.d.ts.map \ No newline at end of file diff --git a/dist/Account.d.ts.map b/dist/Account.d.ts.map new file mode 100644 index 0000000..54987bb --- /dev/null +++ b/dist/Account.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"Account.d.ts","sourceRoot":"","sources":["../src/Account.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,SAAS,CAAA;AAC3B,OAAO,QAAQ,MAAM,YAAY,CAAA;AACjC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAA;AAE5E,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AACzE,OAAO,GAAG,MAAM,aAAa,CAAA;AAE7B,MAAM,CAAC,OAAO,OAAO,OAAQ,SAAQ,KAAK,CAAC,OAAO,CAAE,YAAW,YAAY;IAClE,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;IACjB,gBAAgB,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAA;IAC9C,aAAa,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAA;IAC3C,iBAAiB,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAA;IAC/C,aAAa,EAAE,KAAK,CAAC,aAAa,CAAC,CAAA;WAEtB,KAAK,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,MAAY,GAAG,OAAO,CAAC,OAAO,CAAC;IAU5D,cAAc,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,QAAQ,CAAC;IAM/D,YAAY,IAAI,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;CAItD"} \ No newline at end of file diff --git a/dist/Account.js b/dist/Account.js new file mode 100644 index 0000000..c4b43ae --- /dev/null +++ b/dist/Account.js @@ -0,0 +1,107 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var Model_1 = require("./Model"); +var Transfer_1 = require("./Transfer"); +var API_1 = require("./utils/API"); +var Account = (function (_super) { + __extends(Account, _super); + function Account() { + return _super !== null && _super.apply(this, arguments) || this; + } + Account.fetch = function (id, api) { + if (api === void 0) { api = new API_1.default(); } + return __awaiter(this, void 0, void 0, function () { + var accountUrl, data; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + accountUrl = 'accounts'; + if (!!id) + accountUrl += "/" + id; + return [4, api.get(accountUrl)]; + case 1: + data = _a.sent(); + return [2, new Account(data, api)]; + } + }); + }); + }; + Account.prototype.createTransfer = function (params) { + return __awaiter(this, void 0, void 0, function () { + var transfer; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4, Transfer_1.default.create(params, this.api)]; + case 1: + transfer = _a.sent(); + return [2, transfer]; + } + }); + }); + }; + Account.prototype.getTransfers = function () { + return __awaiter(this, void 0, void 0, function () { + var data; + var _this = this; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4, this.api.get('transfers')]; + case 1: + data = (_a.sent()).data; + return [2, data.map(function (transferData) { return new Transfer_1.default(transferData, _this.api); })]; + } + }); + }); + }; + return Account; +}(Model_1.default)); +exports.default = Account; diff --git a/dist/Account/IAccountData.d.ts b/dist/Account/IAccountData.d.ts new file mode 100644 index 0000000..a177257 --- /dev/null +++ b/dist/Account/IAccountData.d.ts @@ -0,0 +1,28 @@ +export interface IAccountData { + id: string; + status: string; + type: string; + country: string; + createdAt: number; + depositAddresses: { + ETH: string; + BTC: string; + }; + totalBalances: { + BTC: number; + ETH: number; + }; + availableBalances: { + BTC: number; + ETH: number; + }; + profileFields: Array; +} +export interface IProfileField { + fieldId: string; + fieldType: string; + value: string | object | null; + note: string | null; + status: string; +} +//# sourceMappingURL=IAccountData.d.ts.map \ No newline at end of file diff --git a/dist/Account/IAccountData.d.ts.map b/dist/Account/IAccountData.d.ts.map new file mode 100644 index 0000000..80ffa23 --- /dev/null +++ b/dist/Account/IAccountData.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"IAccountData.d.ts","sourceRoot":"","sources":["../../src/Account/IAccountData.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;IACjB,gBAAgB,EAAE;QAChB,GAAG,EAAE,MAAM,CAAA;QACX,GAAG,EAAE,MAAM,CAAA;KACZ,CAAA;IACD,aAAa,EAAE;QACb,GAAG,EAAE,MAAM,CAAA;QACX,GAAG,EAAE,MAAM,CAAA;KACZ,CAAA;IACD,iBAAiB,EAAE;QACjB,GAAG,EAAE,MAAM,CAAA;QACX,GAAG,EAAE,MAAM,CAAA;KACZ,CAAA;IACD,aAAa,EAAE,KAAK,CAAC,aAAa,CAAC,CAAA;CACpC;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;IAC7B,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;IACnB,MAAM,EAAE,MAAM,CAAA;CACf"} \ No newline at end of file diff --git a/dist/Account/IAccountData.js b/dist/Account/IAccountData.js new file mode 100644 index 0000000..c8ad2e5 --- /dev/null +++ b/dist/Account/IAccountData.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/dist/Authed.d.ts b/dist/Authed.d.ts new file mode 100644 index 0000000..8a8c8ea --- /dev/null +++ b/dist/Authed.d.ts @@ -0,0 +1,24 @@ +export interface Auth { + secretKey: string; + apiKey: string; + masqueradeTarget?: string; +} +export interface Config { + auth?: Auth; + apiVersion?: string; + format?: string; + qs?: { + [key: string]: string; + }; + options?: { + headers?: { + [key: string]: string; + }; + }; +} +export default class Authed { + protected readonly config: Config; + constructor(config?: Config); + get isAuthed(): boolean; +} +//# sourceMappingURL=Authed.d.ts.map \ No newline at end of file diff --git a/dist/Authed.d.ts.map b/dist/Authed.d.ts.map new file mode 100644 index 0000000..463167b --- /dev/null +++ b/dist/Authed.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"Authed.d.ts","sourceRoot":"","sources":["../src/Authed.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,IAAI;IACnB,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,MAAM,CAAA;IACd,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAC1B;AAED,MAAM,WAAW,MAAM;IACrB,IAAI,CAAC,EAAE,IAAI,CAAA;IACX,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,EAAE,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IAC/B,OAAO,CAAC,EAAE;QACR,OAAO,CAAC,EAAE;YAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;SAAE,CAAA;KACpC,CAAA;CACF;AAED,MAAM,CAAC,OAAO,OAAO,MAAM;IACzB,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;gBAErB,MAAM,CAAC,EAAE,MAAM;IAW3B,IAAW,QAAQ,IAAI,OAAO,CAE7B;CACF"} \ No newline at end of file diff --git a/dist/Authed.js b/dist/Authed.js new file mode 100644 index 0000000..42d75a4 --- /dev/null +++ b/dist/Authed.js @@ -0,0 +1,22 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var Authed = (function () { + function Authed(config) { + var defaultConfig = { + qs: {}, + options: { + headers: {} + } + }; + this.config = Object.assign({}, defaultConfig, config); + } + Object.defineProperty(Authed.prototype, "isAuthed", { + get: function () { + return !!this.config.auth && !!this.config.auth.secretKey && !!this.config.auth.apiKey; + }, + enumerable: true, + configurable: true + }); + return Authed; +}()); +exports.default = Authed; diff --git a/dist/Model.d.ts b/dist/Model.d.ts new file mode 100644 index 0000000..b638f2e --- /dev/null +++ b/dist/Model.d.ts @@ -0,0 +1,8 @@ +import API from './utils/API'; +export default class Model { + protected readonly api: API; + private data; + constructor(data: object, api: API); + protected set(data: object): void; +} +//# sourceMappingURL=Model.d.ts.map \ No newline at end of file diff --git a/dist/Model.d.ts.map b/dist/Model.d.ts.map new file mode 100644 index 0000000..e36e3fd --- /dev/null +++ b/dist/Model.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"Model.d.ts","sourceRoot":"","sources":["../src/Model.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,aAAa,CAAA;AAE7B,MAAM,CAAC,OAAO,OAAO,KAAK,CAAC,CAAC;IAC1B,SAAS,CAAC,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAA;IAC3B,OAAO,CAAC,IAAI,CAAa;gBAEb,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG;IAoBlC,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM;CAK3B"} \ No newline at end of file diff --git a/dist/Model.js b/dist/Model.js new file mode 100644 index 0000000..a04d222 --- /dev/null +++ b/dist/Model.js @@ -0,0 +1,30 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var Model = (function () { + function Model(data, api) { + this.data = {}; + this.set(data); + this.api = api; + var proxy = new Proxy(this, { + set: function (target, key, value) { + key in target.data + ? target.data[key] = value + : target[key] = value; + }, + get: function (target, key) { + return key in target.data + ? target.data[key] + : target[key]; + } + }); + return proxy; + } + Model.prototype.set = function (data) { + for (var _i = 0, _a = Object.entries(data); _i < _a.length; _i++) { + var _b = _a[_i], key = _b[0], value = _b[1]; + this.data[key] = value; + } + }; + return Model; +}()); +exports.default = Model; diff --git a/dist/Transfer.d.ts b/dist/Transfer.d.ts new file mode 100644 index 0000000..2cc2b0d --- /dev/null +++ b/dist/Transfer.d.ts @@ -0,0 +1,34 @@ +import Model from './Model'; +import API from './utils/API'; +import type { IStatusHistory, ITransferData, ITransferFees } from './Transfer/ITransferData'; +import type { CreateTransferParams } from './Transfer/ICreateTransferParams'; +export default class Transfer extends Model implements ITransferData { + blockchainTx: string; + cancelledAt: number; + completedAt: number; + createdAt: number; + customId: string; + dest: string; + destAmount: number; + destCurrency: string; + exchangeRate: number; + expiresAt: number; + failureReason: string; + fees: ITransferFees; + id: string; + message: string; + owner: string; + pendingSubStatus: string; + reversalReason: string; + reversingSubStatus: string; + source: string; + sourceAmount: number; + sourceCurrency: string; + status: string; + statusHistories: Array; + totalFees: number; + static verifyCreateParams(params: CreateTransferParams): void; + static create(params: CreateTransferParams, api?: API): Promise; + confirm(): Promise; +} +//# sourceMappingURL=Transfer.d.ts.map \ No newline at end of file diff --git a/dist/Transfer.d.ts.map b/dist/Transfer.d.ts.map new file mode 100644 index 0000000..a92b156 --- /dev/null +++ b/dist/Transfer.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"Transfer.d.ts","sourceRoot":"","sources":["../src/Transfer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,SAAS,CAAA;AAC3B,OAAO,GAAG,MAAM,aAAa,CAAA;AAC7B,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AAC5F,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAA;AAE5E,MAAM,CAAC,OAAO,OAAO,QAAS,SAAQ,KAAK,CAAC,QAAQ,CAAE,YAAW,aAAa;IACrE,YAAY,EAAE,MAAM,CAAA;IACpB,WAAW,EAAE,MAAM,CAAA;IACnB,WAAW,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,EAAE,MAAM,CAAA;IAClB,YAAY,EAAE,MAAM,CAAA;IACpB,YAAY,EAAE,MAAM,CAAA;IACpB,SAAS,EAAE,MAAM,CAAA;IACjB,aAAa,EAAE,MAAM,CAAA;IACrB,IAAI,EAAE,aAAa,CAAA;IACnB,EAAE,EAAE,MAAM,CAAA;IACV,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;IACb,gBAAgB,EAAE,MAAM,CAAA;IACxB,cAAc,EAAE,MAAM,CAAA;IACtB,kBAAkB,EAAE,MAAM,CAAA;IAC1B,MAAM,EAAE,MAAM,CAAA;IACd,YAAY,EAAE,MAAM,CAAA;IACpB,cAAc,EAAE,MAAM,CAAA;IACtB,MAAM,EAAE,MAAM,CAAA;IACd,eAAe,EAAE,KAAK,CAAC,cAAc,CAAC,CAAA;IACtC,SAAS,EAAE,MAAM,CAAA;WAEV,kBAAkB,CAAC,MAAM,EAAE,oBAAoB;WAKzC,MAAM,CAAC,MAAM,EAAE,oBAAoB,EAAE,GAAG,MAAY,GAAG,OAAO,CAAC,QAAQ,CAAC;IAQ/E,OAAO;CAIrB"} \ No newline at end of file diff --git a/dist/Transfer.js b/dist/Transfer.js new file mode 100644 index 0000000..9b0babb --- /dev/null +++ b/dist/Transfer.js @@ -0,0 +1,95 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var Model_1 = require("./Model"); +var API_1 = require("./utils/API"); +var Transfer = (function (_super) { + __extends(Transfer, _super); + function Transfer() { + return _super !== null && _super.apply(this, arguments) || this; + } + Transfer.verifyCreateParams = function (params) { + if (params.sourceAmount && params.destinationAmount) + throw new Error('Cannot have both source and destination amounts defined.'); + }; + Transfer.create = function (params, api) { + if (api === void 0) { api = new API_1.default(); } + return __awaiter(this, void 0, void 0, function () { + var data; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + this.verifyCreateParams(params); + return [4, api.post('transfers', params)]; + case 1: + data = _a.sent(); + return [2, new Transfer(data, api)]; + } + }); + }); + }; + Transfer.prototype.confirm = function () { + return __awaiter(this, void 0, void 0, function () { + var data; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4, this.api.post("transfers/" + this.id + "/confirm")]; + case 1: + data = _a.sent(); + this.set(data); + return [2]; + } + }); + }); + }; + return Transfer; +}(Model_1.default)); +exports.default = Transfer; diff --git a/dist/Transfer/ICreateTransferParams.d.ts b/dist/Transfer/ICreateTransferParams.d.ts new file mode 100644 index 0000000..dc2350f --- /dev/null +++ b/dist/Transfer/ICreateTransferParams.d.ts @@ -0,0 +1,16 @@ +export interface CreateTransferParams { + source: string; + sourceCurrency: string; + sourceAmount?: string; + destination: string; + destinationCurrency: string; + destinationAmount?: string; + message?: string; + notifyUrl?: string; + autoConfirm?: boolean; + customId?: string; + amountIncludesFees?: boolean; + preview?: boolean; + muteMessages?: boolean; +} +//# sourceMappingURL=ICreateTransferParams.d.ts.map \ No newline at end of file diff --git a/dist/Transfer/ICreateTransferParams.d.ts.map b/dist/Transfer/ICreateTransferParams.d.ts.map new file mode 100644 index 0000000..51b2aa8 --- /dev/null +++ b/dist/Transfer/ICreateTransferParams.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"ICreateTransferParams.d.ts","sourceRoot":"","sources":["../../src/Transfer/ICreateTransferParams.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAA;IACd,cAAc,EAAE,MAAM,CAAA;IACtB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,WAAW,EAAE,MAAM,CAAA;IACnB,mBAAmB,EAAE,MAAM,CAAA;IAC3B,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB"} \ No newline at end of file diff --git a/dist/Transfer/ICreateTransferParams.js b/dist/Transfer/ICreateTransferParams.js new file mode 100644 index 0000000..c8ad2e5 --- /dev/null +++ b/dist/Transfer/ICreateTransferParams.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/dist/Transfer/ITransferData.d.ts b/dist/Transfer/ITransferData.d.ts new file mode 100644 index 0000000..076b67e --- /dev/null +++ b/dist/Transfer/ITransferData.d.ts @@ -0,0 +1,46 @@ +export interface ITransferHistory { + data: Array; + position: number; + recordsTotal: number; + recordsFiltered: number; +} +export interface ITransferData { + id: string; + sourceAmount: number; + sourceCurrency: string; + destAmount: number; + destCurrency: string; + status: string; + message: string; + customId: string; + exchangeRate: number; + createdAt: number; + fees: ITransferFees; + totalFees: number; + completedAt: number; + cancelledAt: number; + failureReason: string; + expiresAt: number; + reversingSubStatus: string; + reversalReason: string; + pendingSubStatus: string; + dest: string; + blockchainTx: string; + statusHistories: Array; + owner: string; + source: string; +} +export interface ITransferFees { + [assetTicker: string]: number; +} +export interface IStatusHistory { + id: string; + transferId: string; + createdAt: number; + type: string; + statusOrder: number; + statusDetail: string; + state: string; + failedState: boolean; +} +//# sourceMappingURL=ITransferData.d.ts.map \ No newline at end of file diff --git a/dist/Transfer/ITransferData.d.ts.map b/dist/Transfer/ITransferData.d.ts.map new file mode 100644 index 0000000..74f3b2d --- /dev/null +++ b/dist/Transfer/ITransferData.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"ITransferData.d.ts","sourceRoot":"","sources":["../../src/Transfer/ITransferData.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,KAAK,CAAC,aAAa,CAAC,CAAA;IAC1B,QAAQ,EAAE,MAAM,CAAA;IAChB,YAAY,EAAE,MAAM,CAAA;IACpB,eAAe,EAAE,MAAM,CAAA;CACxB;AAED,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAA;IACV,YAAY,EAAE,MAAM,CAAA;IACpB,cAAc,EAAE,MAAM,CAAA;IACtB,UAAU,EAAE,MAAM,CAAA;IAClB,YAAY,EAAE,MAAM,CAAA;IACpB,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;IAChB,YAAY,EAAE,MAAM,CAAA;IACpB,SAAS,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,aAAa,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;IACjB,WAAW,EAAE,MAAM,CAAA;IACnB,WAAW,EAAE,MAAM,CAAA;IACnB,aAAa,EAAE,MAAM,CAAA;IACrB,SAAS,EAAE,MAAM,CAAA;IACjB,kBAAkB,EAAE,MAAM,CAAA;IAC1B,cAAc,EAAE,MAAM,CAAA;IACtB,gBAAgB,EAAE,MAAM,CAAA;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,YAAY,EAAE,MAAM,CAAA;IACpB,eAAe,EAAE,KAAK,CAAC,cAAc,CAAC,CAAA;IACtC,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,aAAa;IAC5B,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAAA;CAC9B;AAED,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAA;IACV,UAAU,EAAE,MAAM,CAAA;IAClB,SAAS,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,YAAY,EAAE,MAAM,CAAA;IACpB,KAAK,EAAE,MAAM,CAAA;IACb,WAAW,EAAE,OAAO,CAAA;CACrB"} \ No newline at end of file diff --git a/dist/Transfer/ITransferData.js b/dist/Transfer/ITransferData.js new file mode 100644 index 0000000..c8ad2e5 --- /dev/null +++ b/dist/Transfer/ITransferData.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/dist/utils/API.d.ts b/dist/utils/API.d.ts new file mode 100644 index 0000000..82a984f --- /dev/null +++ b/dist/utils/API.d.ts @@ -0,0 +1,12 @@ +import 'es6-shim'; +import Authed from '../Authed'; +export default class API extends Authed { + get(path: string, params?: any, options?: any): Promise; + post(path: string, body?: any, options?: any): Promise; + put(path: string, body?: any, options?: any): Promise; + delete(path: string, body?: any, options?: any): Promise; + private request; + private buildRequestOptions; + private buildSignature; +} +//# sourceMappingURL=API.d.ts.map \ No newline at end of file diff --git a/dist/utils/API.d.ts.map b/dist/utils/API.d.ts.map new file mode 100644 index 0000000..1de3e5d --- /dev/null +++ b/dist/utils/API.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"API.d.ts","sourceRoot":"","sources":["../../src/utils/API.ts"],"names":[],"mappings":"AAIA,OAAO,UAAU,CAAA;AAEjB,OAAO,MAAM,MAAM,WAAW,CAAA;AAM9B,MAAM,CAAC,OAAO,OAAO,GAAI,SAAQ,MAAM;IAC9B,GAAG,CAAC,CAAC,SAAS,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,CAAC,CAAC;IAIzE,IAAI,CAAC,CAAC,SAAS,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,CAAC,CAAC;IAIxE,GAAG,CAAC,CAAC,SAAS,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,CAAC,CAAC;IAIvE,MAAM,CAAC,CAAC,SAAS,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,CAAC,CAAC;IAIjF,OAAO,CAAC,OAAO;IAkBf,OAAO,CAAC,mBAAmB;IAyC3B,OAAO,CAAC,cAAc;CAqBvB"} \ No newline at end of file diff --git a/dist/utils/API.js b/dist/utils/API.js new file mode 100644 index 0000000..aa6ba89 --- /dev/null +++ b/dist/utils/API.js @@ -0,0 +1,108 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var request = require("request"); +var crypto = require("crypto"); +var querystring = require("querystring"); +var url = require("url"); +require("es6-shim"); +var Authed_1 = require("../Authed"); +var WYRE_BASEURL = 'https://api.testwyre.com'; +var WYRE_API_VERSION = '3'; +var WYRE_DEFAULT_API_FORMAT = 'json'; +var API = (function (_super) { + __extends(API, _super); + function API() { + return _super !== null && _super.apply(this, arguments) || this; + } + API.prototype.get = function (path, params, options) { + return this.request('GET', path, params, options); + }; + API.prototype.post = function (path, body, options) { + return this.request('POST', path, body, options); + }; + API.prototype.put = function (path, body, options) { + return this.request('PUT', path, body, options); + }; + API.prototype.delete = function (path, body, options) { + return this.request('DELETE', path, body, options); + }; + API.prototype.request = function (method, path, params, options) { + if (params === void 0) { params = {}; } + if (options === void 0) { options = {}; } + if (!path) + throw 'path required'; + var requestOptions = this.buildRequestOptions(method, path, params, options); + return new Promise(function (resolve, reject) { + request(requestOptions, function (err, res) { + if (err) + throw err; + else if (res.statusCode >= 200 && res.statusCode < 300) + resolve(res.body || {}); + else + reject(res.body || { statusCode: res.statusCode }); + }); + }); + }; + API.prototype.buildRequestOptions = function (method, path, params, options) { + options = options || {}; + var parsedUrl = url.parse(url.resolve(WYRE_BASEURL, "v" + WYRE_API_VERSION + "/" + path), true); + var json = !(options.headers || {}).hasOwnProperty('Content-Type') || options.headers['Content-Type'] == 'application/json'; + var requestOptions = __assign(__assign(__assign({}, this.config.options), options), { url: parsedUrl.protocol + '//' + parsedUrl.host + parsedUrl.pathname, method: method, headers: __assign(__assign({}, this.config.options.headers), options.headers), qs: __assign(__assign(__assign({}, this.config.qs), options.qs), { timestamp: new Date().getTime(), format: this.config.format || WYRE_DEFAULT_API_FORMAT }), json: json }); + if (requestOptions.method == 'GET') + requestOptions.qs = Object.assign(requestOptions.qs, params); + else + requestOptions.body = params; + Object.assign(requestOptions.qs, parsedUrl.query); + if (this.isAuthed && this.config.auth.masqueradeTarget && !('masqueradeAs' in requestOptions)) + requestOptions.qs.masqueradeAs = this.config.auth.masqueradeTarget; + if (this.isAuthed) { + requestOptions.headers['X-Api-Key'] = this.config.auth.apiKey; + requestOptions.headers['X-Api-Signature'] = this.buildSignature(requestOptions); + } + return requestOptions; + }; + API.prototype.buildSignature = function (requestOptions) { + var buffers = []; + var encoding = 'utf8'; + buffers.push(Buffer.from(requestOptions.url.toString(), encoding)); + buffers.push(Buffer.from(requestOptions.url.toString().indexOf('?') < 0 ? '?' : '&', encoding)); + buffers.push(Buffer.from(querystring.stringify(requestOptions.qs), encoding)); + if (requestOptions.body) { + if (typeof requestOptions.body == 'string') + buffers.push(Buffer.from(requestOptions.body, encoding)); + else if (requestOptions.body instanceof Buffer) + buffers.push(requestOptions.body); + else + buffers.push(Buffer.from(JSON.stringify(requestOptions.body), encoding)); + } + return crypto.createHmac('sha256', this.config.auth.secretKey) + .update(Buffer.concat(buffers)) + .digest('hex'); + }; + return API; +}(Authed_1.default)); +exports.default = API; diff --git a/dist/utils/Request.d.ts b/dist/utils/Request.d.ts new file mode 100644 index 0000000..c7ecd9e --- /dev/null +++ b/dist/utils/Request.d.ts @@ -0,0 +1,13 @@ +import 'es6-shim'; +import Authed from '../Authed'; +export default class Request extends Authed { + private static _instance; + static get instance(): Request; + get(path: string, params?: any, options?: any): Promise; + post(path: string, body?: any, options?: any): Promise; + put(path: string, body?: any, options?: any): Promise; + delete(path: string, body?: any, options?: any): Promise; + private request; + private buildRequestOptions; + private buildSignature; +} diff --git a/dist/utils/Request.js b/dist/utils/Request.js new file mode 100644 index 0000000..5bfe474 --- /dev/null +++ b/dist/utils/Request.js @@ -0,0 +1,98 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const request = require("request"); +const crypto = require("crypto"); +const querystring = require("querystring"); +const url = require("url"); +require("es6-shim"); +const Authed_1 = require("../Authed"); +const WYRE_BASEURL = 'https://api.testwyre.com/v3'; +const WYRE_DEFAULT_API_FORMAT = 'json'; +class Request extends Authed_1.default { + static get instance() { + if (this._instance) + return this._instance; + this._instance = + ; + } + get(path, params, options) { + return this.request('GET', path, params, options); + } + post(path, body, options) { + return this.request('POST', path, body, options); + } + put(path, body, options) { + return this.request('PUT', path, body, options); + } + delete(path, body, options) { + return this.request('DELETE', path, body, options); + } + request(method, path, params = {}, options = {}) { + if (!path) + throw 'path required'; + let requestOptions = this.buildRequestOptions(method, path, params, options); + return new Promise((resolve, reject) => { + request(requestOptions, (err, res) => { + if (err) + throw err; + else if (res.statusCode >= 200 && res.statusCode < 300) + resolve(res.body || {}); + else + reject(res.body || { statusCode: res.statusCode }); + }); + }); + } + buildRequestOptions(method, path, params, options) { + options = options || {}; + let parsedUrl = url.parse(url.resolve(WYRE_BASEURL, path), true); + let json = !(options.headers || {}).hasOwnProperty('Content-Type') || options.headers['Content-Type'] == 'application/json'; + let requestOptions = { + ...this.config.options, + ...options, + url: parsedUrl.protocol + '//' + parsedUrl.host + parsedUrl.pathname, + method: method, + headers: { + ...this.config.options.headers, + ...options.headers + }, + qs: { + ...this.config.qs, + ...options.qs, + timestamp: new Date().getTime(), + format: this.config.format || WYRE_DEFAULT_API_FORMAT + }, + json: json + }; + if (requestOptions.method == 'GET') + requestOptions.qs = Object.assign(requestOptions.qs, params); + else + requestOptions.body = params; + Object.assign(requestOptions.qs, parsedUrl.query); + if (this.isAuthed && this.config.auth.masqueradeTarget && !('masqueradeAs' in requestOptions)) + requestOptions.qs.masqueradeAs = this.config.auth.masqueradeTarget; + if (this.isAuthed) { + requestOptions.headers['X-Api-Key'] = this.config.auth.apiKey; + requestOptions.headers['X-Api-Signature'] = this.buildSignature(requestOptions); + } + return requestOptions; + } + buildSignature(requestOptions) { + let buffers = []; + const encoding = 'utf8'; + buffers.push(Buffer.from(requestOptions.url.toString(), encoding)); + buffers.push(Buffer.from(requestOptions.url.toString().indexOf('?') < 0 ? '?' : '&', encoding)); + buffers.push(Buffer.from(querystring.stringify(requestOptions.qs), encoding)); + if (requestOptions.body) { + if (typeof requestOptions.body == 'string') + buffers.push(Buffer.from(requestOptions.body, encoding)); + else if (requestOptions.body instanceof Buffer) + buffers.push(requestOptions.body); + else + buffers.push(Buffer.from(JSON.stringify(requestOptions.body), encoding)); + } + return crypto.createHmac('sha256', this.config.auth.secretKey) + .update(Buffer.concat(buffers)) + .digest('hex'); + } +} +exports.default = Request; diff --git a/dist/wyre.d.ts b/dist/wyre.d.ts index bffd362..d95dcbb 100644 --- a/dist/wyre.d.ts +++ b/dist/wyre.d.ts @@ -1,14 +1,9 @@ -import 'es6-shim'; -export declare class WyreClient { - private config; - private masqueradeTarget?; - constructor(config: any, masqueradeTarget?: string); - get(path: string, params?: any, options?: any): Promise; - post(path: string, body?: any, options?: any): Promise; - put(path: string, body?: any, options?: any): Promise; - delete(path: string, body?: any, options?: any): Promise; - masqueraded(target: string): WyreClient; - private request; - private buildRequestOptions; - private buildSignature; +import Authed from './Authed'; +import Account from './Account'; +import type { Config } from './Authed'; +export default class WyreClient extends Authed { + private readonly api; + constructor(config: Config); + fetchAccount(id?: string, masquerade?: boolean): Promise; } +//# sourceMappingURL=wyre.d.ts.map \ No newline at end of file diff --git a/dist/wyre.d.ts.map b/dist/wyre.d.ts.map new file mode 100644 index 0000000..ee6b092 --- /dev/null +++ b/dist/wyre.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"wyre.d.ts","sourceRoot":"","sources":["../src/wyre.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,UAAU,CAAA;AAC7B,OAAO,OAAO,MAAM,WAAW,CAAA;AAE/B,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAEtC,MAAM,CAAC,OAAO,OAAO,UAAW,SAAQ,MAAM;IAC5C,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAK;gBAEb,MAAM,EAAE,MAAM;IAMb,YAAY,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,UAAU,UAAQ,GAAG,OAAO,CAAC,OAAO,CAAC;CAc7E"} \ No newline at end of file diff --git a/dist/wyre.js b/dist/wyre.js index 5e71a92..f2ec7fe 100644 --- a/dist/wyre.js +++ b/dist/wyre.js @@ -1,96 +1,81 @@ "use strict"; -var __assign = (this && this.__assign) || Object.assign || function(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) - t[p] = s[p]; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } - return t; }; Object.defineProperty(exports, "__esModule", { value: true }); -var request = require("request"); -var crypto = require("crypto"); -var querystring = require("querystring"); -var url = require("url"); -require("es6-shim"); -var WYRE_BASEURL = "https://api.sendwyre.com"; -var WYRE_DEFAULT_API_VERSION = "2"; -var WYRE_DEFAULT_API_FORMAT = "json"; -var WyreClient = (function () { - function WyreClient(config, masqueradeTarget) { - this.config = config; - this.masqueradeTarget = masqueradeTarget; - if (!config.secretKey) - throw new Error('config.secretKey is missing'); - if (!config.apiKey) - throw new Error('config.apiKey is missing'); - this.config.options = this.config.options || {}; +var Authed_1 = require("./Authed"); +var Account_1 = require("./Account"); +var API_1 = require("./utils/API"); +var WyreClient = (function (_super) { + __extends(WyreClient, _super); + function WyreClient(config) { + var _this = _super.call(this, config) || this; + _this.api = new API_1.default(config); + return _this; } - WyreClient.prototype.get = function (path, params, options) { - return this.request("GET", path, params, options); - }; - WyreClient.prototype.post = function (path, body, options) { - return this.request("POST", path, body, options); - }; - WyreClient.prototype.put = function (path, body, options) { - return this.request("PUT", path, body, options); - }; - WyreClient.prototype.delete = function (path, body, options) { - return this.request("DELETE", path, body, options); - }; - WyreClient.prototype.masqueraded = function (target) { - return new WyreClient(this.config, target); - }; - WyreClient.prototype.request = function (method, path, params, options) { - if (params === void 0) { params = {}; } - if (options === void 0) { options = {}; } - if (!path) - throw "path required"; - var requestOptions = this.buildRequestOptions(method, path, params, options); - return new Promise(function (resolve, reject) { - request(requestOptions, function (err, res) { - if (err) - throw err; - else if (res.statusCode >= 200 && res.statusCode < 300) - resolve(res.body || {}); - else - reject(res.body || { statusCode: res.statusCode }); + WyreClient.prototype.fetchAccount = function (id, masquerade) { + if (masquerade === void 0) { masquerade = false; } + return __awaiter(this, void 0, void 0, function () { + var api, newConfig; + return __generator(this, function (_a) { + api = this.api; + if (!!id && masquerade) { + if (!this.isAuthed) + throw new Error('Cannot masquerade with no authorization.'); + newConfig = Object.assign({}, this.config); + newConfig.auth.masqueradeTarget = id; + api = new API_1.default(newConfig); + } + return [2, Account_1.default.fetch(id, api)]; }); }); }; - WyreClient.prototype.buildRequestOptions = function (method, path, params, options) { - options = options || {}; - var parsedUrl = url.parse(url.resolve(this.config.baseUrl || WYRE_BASEURL, path), true); - var json = !(options.headers || {}).hasOwnProperty('Content-Type') || options.headers['Content-Type'] == 'application/json'; - var requestOptions = __assign({}, this.config.options, options, { url: parsedUrl.protocol + "//" + parsedUrl.host + parsedUrl.pathname, method: method, headers: __assign({}, this.config.options.headers, options.headers, { "X-Api-Version": this.config.apiVersion || WYRE_DEFAULT_API_VERSION, "X-Api-Key": this.config.apiKey }), qs: __assign({}, this.config.qs, options.qs, { timestamp: new Date().getTime(), format: this.config.format || WYRE_DEFAULT_API_FORMAT }), json: json }); - if (requestOptions.method == "GET") - requestOptions.qs = Object.assign(requestOptions.qs, params); - else - requestOptions.body = params; - Object.assign(requestOptions.qs, parsedUrl.query); - if (this.masqueradeTarget && !('masqueradeAs' in requestOptions)) - requestOptions.qs.masqueradeAs = this.masqueradeTarget; - requestOptions.headers["X-Api-Signature"] = this.buildSignature(requestOptions); - return requestOptions; - }; - WyreClient.prototype.buildSignature = function (requestOptions) { - var buffers = []; - var encoding = 'utf8'; - buffers.push(Buffer.from(requestOptions.url.toString(), encoding)); - buffers.push(Buffer.from(requestOptions.url.toString().indexOf('?') < 0 ? "?" : "&", encoding)); - buffers.push(Buffer.from(querystring.stringify(requestOptions.qs), encoding)); - if (requestOptions.body) { - if (typeof requestOptions.body == 'string') - buffers.push(Buffer.from(requestOptions.body, encoding)); - else if (requestOptions.body instanceof Buffer) - buffers.push(requestOptions.body); - else - buffers.push(Buffer.from(JSON.stringify(requestOptions.body), encoding)); - } - return crypto.createHmac("sha256", this.config.secretKey) - .update(Buffer.concat(buffers)) - .digest("hex"); - }; return WyreClient; -}()); -exports.WyreClient = WyreClient; +}(Authed_1.default)); +exports.default = WyreClient; diff --git a/package-lock.json b/package-lock.json index 0737729..0f6124e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@wyre/api", - "version": "1.0.3", + "version": "1.0.4", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -20,9 +20,9 @@ } }, "@types/node": { - "version": "10.10.1", - "resolved": "https://registry.npmjs.org/@types/node/-/node-10.10.1.tgz", - "integrity": "sha512-nzsx28VwfaIykfzMAG9TB3jxF5Nn+1/WMKnmVZc8TsB+LMIVvwUscVn7PAq+LFaY5ng5u4jp5mRROSswo76PPA==", + "version": "13.9.1", + "resolved": "https://registry.npmjs.org/@types/node/-/node-13.9.1.tgz", + "integrity": "sha512-E6M6N0blf/jiZx8Q3nb0vNaswQeEyn0XlupO+xN6DtJ6r6IT4nXrTry7zhIfYvFCl3/8Cu6WIysmUBKiqV0bqQ==", "dev": true }, "@types/request": { @@ -54,6 +54,12 @@ "json-schema-traverse": "^0.3.0" } }, + "arg": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", + "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==", + "dev": true + }, "asn1": { "version": "0.2.4", "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.4.tgz", @@ -91,6 +97,12 @@ "tweetnacl": "^0.14.3" } }, + "buffer-from": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz", + "integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==", + "dev": true + }, "caseless": { "version": "0.12.0", "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", @@ -127,6 +139,12 @@ "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=" }, + "diff": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", + "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", + "dev": true + }, "ecc-jsbn": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz", @@ -261,6 +279,12 @@ "verror": "1.10.0" } }, + "make-error": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", + "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==", + "dev": true + }, "mime-db": { "version": "1.36.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.36.0.tgz", @@ -336,6 +360,22 @@ "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" }, + "source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "dev": true + }, + "source-map-support": { + "version": "0.5.16", + "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.16.tgz", + "integrity": "sha512-efyLRJDr68D9hBBNIPWFjhpFzURh+KJykQwvMyW5UiZzYwoF6l4YMMDIJJEyFWxWCqfyxLzz6tSfUFR+kXXsVQ==", + "dev": true, + "requires": { + "buffer-from": "^1.0.0", + "source-map": "^0.6.0" + } + }, "sshpk": { "version": "1.14.2", "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.14.2.tgz", @@ -361,6 +401,19 @@ "punycode": "^1.4.1" } }, + "ts-node": { + "version": "8.6.2", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-8.6.2.tgz", + "integrity": "sha512-4mZEbofxGqLL2RImpe3zMJukvEvcO1XP8bj8ozBPySdCUXEcU5cIRwR0aM3R+VoZq7iXc8N86NC0FspGRqP4gg==", + "dev": true, + "requires": { + "arg": "^4.1.0", + "diff": "^4.0.1", + "make-error": "^1.1.1", + "source-map-support": "^0.5.6", + "yn": "3.1.1" + } + }, "tunnel-agent": { "version": "0.6.0", "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", @@ -376,9 +429,9 @@ "optional": true }, "typescript": { - "version": "2.9.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-2.9.2.tgz", - "integrity": "sha512-Gr4p6nFNaoufRIY4NMdpQRNmgxVIGMs4Fcu/ujdYk3nAZqk7supzBE9idmvfZIlH/Cuj//dvi+019qEue9lV0w==", + "version": "3.8.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.8.3.tgz", + "integrity": "sha512-MYlEfn5VrLNsgudQTVJeNaQFUAI7DkhnOjdpAp4T+ku1TfQClewlbSuTVHiA+8skNBgaf02TL/kLOvig4y3G8w==", "dev": true }, "uuid": { @@ -395,6 +448,12 @@ "core-util-is": "1.0.2", "extsprintf": "^1.2.0" } + }, + "yn": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", + "integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==", + "dev": true } } } diff --git a/package.json b/package.json index c81e0ba..9ab3547 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,9 @@ "request": "2.88.0" }, "devDependencies": { + "@types/node": "^13.9.1", "@types/request": "2.47.1", - "typescript": "2.9.2" + "ts-node": "^8.6.2", + "typescript": "^3.8.3" } } diff --git a/src/Account.ts b/src/Account.ts new file mode 100644 index 0000000..60fb516 --- /dev/null +++ b/src/Account.ts @@ -0,0 +1,39 @@ +import Model from './Model' +import Transfer from './Transfer' +import type { CreateTransferParams } from './Transfer/ICreateTransferParams' +import type { ITransferHistory } from './Transfer/ITransferData' +import type { IAccountData, IProfileField } from './Account/IAccountData' +import API from './utils/API' + +export default class Account extends Model implements IAccountData { + public id: string + public status: string + public type: string + public country: string + public createdAt: number + public depositAddresses: { ETH: string; BTC: string } + public totalBalances: { BTC: number; ETH: number } + public availableBalances: { BTC: number; ETH: number } + public profileFields: Array + + public static async fetch(id?: string, api = new API()): Promise { + let accountUrl = 'accounts' + if (!!id) + accountUrl += `/${id}` + + const data = await api.get(accountUrl) + + return new Account(data, api) + } + + public async createTransfer(params: CreateTransferParams): Promise { + const transfer = await Transfer.create(params, this.api) + + return transfer + } + + public async getTransfers(): Promise> { + const { data } = await this.api.get('transfers') + return data.map((transferData) => new Transfer(transferData, this.api)) + } +} \ No newline at end of file diff --git a/src/Account/IAccountData.ts b/src/Account/IAccountData.ts new file mode 100644 index 0000000..26f8762 --- /dev/null +++ b/src/Account/IAccountData.ts @@ -0,0 +1,28 @@ +export interface IAccountData { + id: string + status: string + type: string + country: string + createdAt: number + depositAddresses: { + ETH: string + BTC: string + } + totalBalances: { + BTC: number + ETH: number + } + availableBalances: { + BTC: number + ETH: number + } + profileFields: Array +} + +export interface IProfileField { + fieldId: string + fieldType: string + value: string | object | null + note: string | null + status: string +} diff --git a/src/Authed.ts b/src/Authed.ts new file mode 100644 index 0000000..f2e1844 --- /dev/null +++ b/src/Authed.ts @@ -0,0 +1,34 @@ +export interface Auth { + secretKey: string + apiKey: string + masqueradeTarget?: string +} + +export interface Config { + auth?: Auth + apiVersion?: string + format?: string + qs?: { [key: string]: string }, + options?: { + headers?: { [key: string]: string } + } +} + +export default class Authed { + protected readonly config: Config + + constructor(config?: Config) { + const defaultConfig: Config = { + qs: {}, + options: { + headers: {} + } + } + + this.config = Object.assign({}, defaultConfig, config) + } + + public get isAuthed(): boolean { + return !!this.config.auth && !!this.config.auth.secretKey && !!this.config.auth.apiKey + } +} \ No newline at end of file diff --git a/src/Model.ts b/src/Model.ts new file mode 100644 index 0000000..62a71e7 --- /dev/null +++ b/src/Model.ts @@ -0,0 +1,32 @@ +import API from './utils/API' + +export default class Model { + protected readonly api: API + private data: object = {} + + constructor(data: object, api: API) { + this.set(data) + this.api = api + + const proxy = new Proxy>(this, { + set(target: Model, key: string | number | symbol, value: any): any { + key in target.data + ? target.data[key] = value + : target[key] = value + }, + get(target: Model, key: string | number | symbol): any { + return key in target.data + ? target.data[key] + : target[key] + } + }) + + return proxy + } + + protected set(data: object) { + for (const [ key, value ] of Object.entries(data)) { + this.data[key] = value + } + } +} \ No newline at end of file diff --git a/src/Transfer.ts b/src/Transfer.ts new file mode 100644 index 0000000..852663f --- /dev/null +++ b/src/Transfer.ts @@ -0,0 +1,49 @@ +import Model from './Model' +import API from './utils/API' +import type { IStatusHistory, ITransferData, ITransferFees } from './Transfer/ITransferData' +import type { CreateTransferParams } from './Transfer/ICreateTransferParams' + +export default class Transfer extends Model implements ITransferData { + public blockchainTx: string + public cancelledAt: number + public completedAt: number + public createdAt: number + public customId: string + public dest: string + public destAmount: number + public destCurrency: string + public exchangeRate: number + public expiresAt: number + public failureReason: string + public fees: ITransferFees + public id: string + public message: string + public owner: string + public pendingSubStatus: string + public reversalReason: string + public reversingSubStatus: string + public source: string + public sourceAmount: number + public sourceCurrency: string + public status: string + public statusHistories: Array + public totalFees: number + + public static verifyCreateParams(params: CreateTransferParams) { + if (params.sourceAmount && params.destinationAmount) + throw new Error('Cannot have both source and destination amounts defined.') + } + + public static async create(params: CreateTransferParams, api = new API()): Promise { + this.verifyCreateParams(params) + + const data = await api.post('transfers', params) + + return new Transfer(data, api) + } + + public async confirm() { + const data = await this.api.post(`transfers/${this.id}/confirm`) + this.set(data) + } +} diff --git a/src/Transfer/ICreateTransferParams.ts b/src/Transfer/ICreateTransferParams.ts new file mode 100644 index 0000000..fdfedfd --- /dev/null +++ b/src/Transfer/ICreateTransferParams.ts @@ -0,0 +1,15 @@ +export interface CreateTransferParams { + source: string + sourceCurrency: string + sourceAmount?: string + destination: string + destinationCurrency: string + destinationAmount?: string + message?: string + notifyUrl?: string + autoConfirm?: boolean + customId?: string + amountIncludesFees?: boolean + preview?: boolean + muteMessages?: boolean +} diff --git a/src/Transfer/ITransferData.ts b/src/Transfer/ITransferData.ts new file mode 100644 index 0000000..c688bf5 --- /dev/null +++ b/src/Transfer/ITransferData.ts @@ -0,0 +1,48 @@ +export interface ITransferHistory { + data: Array + position: number + recordsTotal: number + recordsFiltered: number +} + +export interface ITransferData { + id: string + sourceAmount: number + sourceCurrency: string + destAmount: number + destCurrency: string + status: string + message: string + customId: string + exchangeRate: number + createdAt: number + fees: ITransferFees + totalFees: number + completedAt: number + cancelledAt: number + failureReason: string + expiresAt: number + reversingSubStatus: string + reversalReason: string + pendingSubStatus: string + dest: string + blockchainTx: string + statusHistories: Array + owner: string + source: string +} + +export interface ITransferFees { + [assetTicker: string]: number +} + +export interface IStatusHistory { + id: string + transferId: string + createdAt: number + type: string + statusOrder: number + statusDetail: string + state: string + failedState: boolean +} diff --git a/src/utils/API.ts b/src/utils/API.ts new file mode 100644 index 0000000..aa24e07 --- /dev/null +++ b/src/utils/API.ts @@ -0,0 +1,110 @@ +import * as request from 'request' +import * as crypto from 'crypto' +import * as querystring from 'querystring' +import * as url from 'url' +import 'es6-shim' + +import Authed from '../Authed' + +const WYRE_BASEURL = 'https://api.testwyre.com' +const WYRE_API_VERSION = '3' +const WYRE_DEFAULT_API_FORMAT = 'json' + +export default class API extends Authed { + public get(path: string, params?: any, options?: any): Promise { + return this.request('GET', path, params, options) + } + + public post(path: string, body?: any, options?: any): Promise { + return this.request('POST', path, body, options) + } + + public put(path: string, body?: any, options?: any): Promise { + return this.request('PUT', path, body, options) + } + + public delete(path: string, body?: any, options?: any): Promise { + return this.request('DELETE', path, body, options) + } + + private request(method: string, path: string, params: any = {}, options: any = {}): Promise { + if (!path) + throw 'path required' + + let requestOptions = this.buildRequestOptions(method, path, params, options) + + return new Promise((resolve, reject) => { + request(requestOptions, (err, res) => { + if (err) + throw err + else if (res.statusCode >= 200 && res.statusCode < 300) + resolve(res.body || {}) + else + reject(res.body || { statusCode: res.statusCode }) + }) + }) + } + + private buildRequestOptions(method: string, path: string, params: any, options: any): request.UrlOptions & request.CoreOptions { + options = options || {} + + let parsedUrl = url.parse(url.resolve(WYRE_BASEURL, `v${WYRE_API_VERSION}/${path}`), true) + let json = !(options.headers || {}).hasOwnProperty('Content-Type') || options.headers['Content-Type'] == 'application/json' + + let requestOptions: request.UrlOptions & request.CoreOptions = { + ...this.config.options, + ...options, + url: parsedUrl.protocol + '//' + parsedUrl.host + parsedUrl.pathname, // no querystring here! + method: method, + headers: { + ...this.config.options.headers, + ...options.headers + }, + qs: { + ...this.config.qs, + ...options.qs, + timestamp: new Date().getTime(), + format: this.config.format || WYRE_DEFAULT_API_FORMAT + }, + json: json + } + + if (requestOptions.method == 'GET') + requestOptions.qs = Object.assign(requestOptions.qs, params) + else + requestOptions.body = params + + Object.assign(requestOptions.qs, parsedUrl.query) + if (this.isAuthed && this.config.auth.masqueradeTarget && !('masqueradeAs' in requestOptions)) + requestOptions.qs.masqueradeAs = this.config.auth.masqueradeTarget + + if (this.isAuthed) { + requestOptions.headers['X-Api-Key'] = this.config.auth.apiKey + requestOptions.headers['X-Api-Signature'] = this.buildSignature(requestOptions) + } + + return requestOptions + } + + private buildSignature(requestOptions: request.UrlOptions & request.CoreOptions): string { + let buffers: Buffer[] = [] + const encoding = 'utf8' + + buffers.push(Buffer.from(requestOptions.url.toString(), encoding)) + buffers.push(Buffer.from(requestOptions.url.toString().indexOf('?') < 0 ? '?' : '&', encoding)) + buffers.push(Buffer.from(querystring.stringify(requestOptions.qs), encoding)) + + if (requestOptions.body) { + if (typeof requestOptions.body == 'string') + buffers.push(Buffer.from(requestOptions.body, encoding)) + else if (requestOptions.body instanceof Buffer) + buffers.push(requestOptions.body) + else + buffers.push(Buffer.from(JSON.stringify(requestOptions.body), encoding)) + } + + return crypto.createHmac('sha256', this.config.auth.secretKey) + .update(Buffer.concat(buffers)) + .digest('hex') + } +} \ No newline at end of file diff --git a/src/wyre.ts b/src/wyre.ts index 9062f17..532c7dd 100644 --- a/src/wyre.ts +++ b/src/wyre.ts @@ -1,124 +1,29 @@ -import * as request from 'request' -import * as crypto from 'crypto' -import * as querystring from 'querystring' -import * as url from 'url' -import 'es6-shim' +import Authed from './Authed' +import Account from './Account' +import API from './utils/API' +import type { Config } from './Authed' -const WYRE_BASEURL = "https://api.sendwyre.com" -const WYRE_DEFAULT_API_VERSION = "2" -const WYRE_DEFAULT_API_FORMAT = "json" +export default class WyreClient extends Authed { + private readonly api: API -export class WyreClient { + constructor(config: Config) { + super(config) - constructor(private config: any, private masqueradeTarget?: string) { - if(!config.secretKey) throw new Error('config.secretKey is missing'); - if(!config.apiKey) throw new Error('config.apiKey is missing'); - this.config.options = this.config.options || {}; - } - - public get(path: string, params?: any, options?: any): Promise { - return this.request("GET", path, params, options) - } - - public post(path: string, body?: any, options?: any): Promise { - return this.request("POST", path, body, options) - } - - public put(path: string, body?: any, options?: any): Promise { - return this.request("PUT", path, body, options) - } - - public delete(path: string, body?: any, options?: any): Promise { - return this.request("DELETE", path, body, options) - } + this.api = new API(config) + } - /** - * returns a new wyre client which is ostensibly authenticated as the supplied - * target - * - * @param target an account ID or an SRN - */ - public masqueraded(target: string): WyreClient { - return new WyreClient(this.config, target); - } - - private request(method: string, path: string, params: any = {}, options: any = {}): Promise { - if(!path) - throw "path required" + public async fetchAccount(id?: string, masquerade = false): Promise { + let api = this.api + if (!!id && masquerade) { + if (!this.isAuthed) + throw new Error('Cannot masquerade with no authorization.') - let requestOptions = this.buildRequestOptions(method, path, params, options) + const newConfig = Object.assign({}, this.config) + newConfig.auth.masqueradeTarget = id - return new Promise((resolve, reject) => { - request(requestOptions, (err, res) => { - if(err) - throw err; - else if(res.statusCode >= 200 && res.statusCode < 300) - resolve(res.body || {}) - else - reject(res.body || { statusCode: res.statusCode }) - }) - }) + api = new API(newConfig) } - private buildRequestOptions(method: string, path: string, params: any, options: any): request.UrlOptions & request.CoreOptions { - options = options || {}; - - let parsedUrl = url.parse(url.resolve(this.config.baseUrl || WYRE_BASEURL, path), true) - let json = !(options.headers || {}).hasOwnProperty('Content-Type') || options.headers['Content-Type'] == 'application/json'; - - let requestOptions: request.UrlOptions & request.CoreOptions = { - ...this.config.options, - ...options, - url: parsedUrl.protocol + "//" + parsedUrl.host + parsedUrl.pathname, // no querystring here! - method: method, - headers: { - ...this.config.options.headers, - ...options.headers, - "X-Api-Version": this.config.apiVersion || WYRE_DEFAULT_API_VERSION, - "X-Api-Key": this.config.apiKey - }, - qs: { - ...this.config.qs, - ...options.qs, - timestamp: new Date().getTime(), - format: this.config.format || WYRE_DEFAULT_API_FORMAT - }, - json: json - }; - - if(requestOptions.method == "GET") - requestOptions.qs = Object.assign(requestOptions.qs, params) - else - requestOptions.body = params - - Object.assign(requestOptions.qs, parsedUrl.query); - if(this.masqueradeTarget && !('masqueradeAs' in requestOptions)) - requestOptions.qs.masqueradeAs = this.masqueradeTarget; - - requestOptions.headers["X-Api-Signature"] = this.buildSignature(requestOptions); - - return requestOptions - } - - private buildSignature(requestOptions: request.UrlOptions & request.CoreOptions): string { - let buffers: Buffer[] = []; - const encoding = 'utf8'; - - buffers.push(Buffer.from(requestOptions.url.toString(), encoding)); - buffers.push(Buffer.from(requestOptions.url.toString().indexOf('?') < 0 ? "?" : "&", encoding)); - buffers.push(Buffer.from(querystring.stringify(requestOptions.qs), encoding)); - - if(requestOptions.body) { - if(typeof requestOptions.body == 'string') - buffers.push(Buffer.from(requestOptions.body, encoding)); - else if(requestOptions.body instanceof Buffer) - buffers.push(requestOptions.body); - else - buffers.push(Buffer.from(JSON.stringify(requestOptions.body), encoding)); - } - - return crypto.createHmac("sha256", this.config.secretKey) - .update(Buffer.concat(buffers)) - .digest("hex") - } + return Account.fetch(id, api) + } } diff --git a/tsconfig.json b/tsconfig.json index 2b27242..50aae22 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,18 +1,19 @@ { - "compilerOptions": { - "declaration": true, - "emitDecoratorMetadata": true, - "experimentalDecorators": true, - "lib": ["es2015"], - "module": "commonjs", - "moduleResolution": "node", - "noImplicitAny": true, - "noImplicitUseStrict": false, - "noLib": false, - "outDir" : "dist", - "removeComments": true, - "rootDir": "src", - "suppressImplicitAnyIndexErrors": true, - "target": "es5" - } + "compilerOptions": { + "declaration": true, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "lib": ["es2015"], + "module": "commonjs", + "moduleResolution": "node", + "noImplicitAny": true, + "noImplicitUseStrict": false, + "noLib": false, + "outDir" : "dist", + "removeComments": true, + "rootDir": "src", + "suppressImplicitAnyIndexErrors": true, + "target": "es5", + "declarationMap": true + } } \ No newline at end of file From e766128d0c2a26fa264da36efa6d51a3015e76c0 Mon Sep 17 00:00:00 2001 From: Noah Passalacqua Date: Tue, 31 Mar 2020 15:16:32 -0500 Subject: [PATCH 02/20] Refactor Api class. --- dist/Account.d.ts | 12 +- dist/Account.d.ts.map | 2 +- dist/Account.js | 13 +- dist/Account/IAccount.d.ts | 28 +++++ dist/Account/IAccount.d.ts.map | 1 + dist/Account/IAccount.js | 2 + dist/Account/IAccountData.d.ts | 2 + dist/Account/IAccountData.d.ts.map | 2 +- dist/Model.d.ts | 13 +- dist/Model.d.ts.map | 2 +- dist/Model.js | 43 ++++--- dist/Transfer.d.ts | 13 +- dist/Transfer.d.ts.map | 2 +- dist/Transfer.js | 3 +- dist/Transfer/ITransfer.d.ts | 61 ++++++++++ dist/Transfer/ITransfer.d.ts.map | 1 + dist/Transfer/ITransfer.js | 2 + dist/utils/API.d.ts | 10 +- dist/utils/API.d.ts.map | 2 +- dist/utils/API.js | 7 +- dist/utils/API/IApiConfig.d.ts | 21 ++++ dist/utils/API/IApiConfig.d.ts.map | 1 + dist/utils/API/IApiConfig.js | 2 + dist/utils/API/IApiOptions.d.ts | 6 + dist/utils/API/IApiOptions.d.ts.map | 1 + dist/utils/API/IApiOptions.js | 2 + dist/utils/API/IOptions.d.ts | 6 + dist/utils/API/IOptions.d.ts.map | 1 + dist/utils/API/IOptions.js | 2 + dist/utils/Api.d.ts | 16 +++ dist/utils/Api.d.ts.map | 1 + dist/utils/Api.js | 111 ++++++++++++++++++ dist/utils/Auth/IAuthed.d.ts | 1 + dist/utils/Auth/IAuthed.d.ts.map | 1 + dist/utils/Auth/IAuthed.js | 0 dist/utils/Authed.d.ts | 6 + dist/utils/Authed.d.ts.map | 1 + dist/utils/Authed.js | 9 ++ dist/wyre.d.ts | 9 +- dist/wyre.d.ts.map | 2 +- dist/wyre.js | 33 ++---- src/Account.ts | 24 ++-- src/Account/{IAccountData.ts => IAccount.ts} | 2 +- src/Authed.ts | 34 ------ src/Model.ts | 53 ++++++--- src/Transfer.ts | 19 +-- src/Transfer/ICreateTransferParams.ts | 15 --- .../{ITransferData.ts => ITransfer.ts} | 36 ++++-- src/utils/API/IApiConfig.ts | 18 +++ src/utils/{API.ts => Api.ts} | 77 ++++++++---- src/wyre.ts | 25 ++-- 51 files changed, 532 insertions(+), 224 deletions(-) create mode 100644 dist/Account/IAccount.d.ts create mode 100644 dist/Account/IAccount.d.ts.map create mode 100644 dist/Account/IAccount.js create mode 100644 dist/Transfer/ITransfer.d.ts create mode 100644 dist/Transfer/ITransfer.d.ts.map create mode 100644 dist/Transfer/ITransfer.js create mode 100644 dist/utils/API/IApiConfig.d.ts create mode 100644 dist/utils/API/IApiConfig.d.ts.map create mode 100644 dist/utils/API/IApiConfig.js create mode 100644 dist/utils/API/IApiOptions.d.ts create mode 100644 dist/utils/API/IApiOptions.d.ts.map create mode 100644 dist/utils/API/IApiOptions.js create mode 100644 dist/utils/API/IOptions.d.ts create mode 100644 dist/utils/API/IOptions.d.ts.map create mode 100644 dist/utils/API/IOptions.js create mode 100644 dist/utils/Api.d.ts create mode 100644 dist/utils/Api.d.ts.map create mode 100644 dist/utils/Api.js create mode 100644 dist/utils/Auth/IAuthed.d.ts create mode 100644 dist/utils/Auth/IAuthed.d.ts.map create mode 100644 dist/utils/Auth/IAuthed.js create mode 100644 dist/utils/Authed.d.ts create mode 100644 dist/utils/Authed.d.ts.map create mode 100644 dist/utils/Authed.js rename src/Account/{IAccountData.ts => IAccount.ts} (93%) delete mode 100644 src/Authed.ts delete mode 100644 src/Transfer/ICreateTransferParams.ts rename src/Transfer/{ITransferData.ts => ITransfer.ts} (59%) create mode 100644 src/utils/API/IApiConfig.ts rename src/utils/{API.ts => Api.ts} (57%) diff --git a/dist/Account.d.ts b/dist/Account.d.ts index 296854b..9a8d3dc 100644 --- a/dist/Account.d.ts +++ b/dist/Account.d.ts @@ -1,9 +1,9 @@ import Model from './Model'; import Transfer from './Transfer'; -import type { CreateTransferParams } from './Transfer/ICreateTransferParams'; -import type { IAccountData, IProfileField } from './Account/IAccountData'; -import API from './utils/API'; -export default class Account extends Model implements IAccountData { +import Api from './utils/Api'; +import type { IAccount, IProfileField } from './Account/IAccount'; +import type { ICreateTransferParams } from './Transfer/ITransfer'; +export default class Account extends Model implements IAccount { id: string; status: string; type: string; @@ -22,8 +22,8 @@ export default class Account extends Model implements IAccountData { ETH: number; }; profileFields: Array; - static fetch(id?: string, api?: API): Promise; - createTransfer(params: CreateTransferParams): Promise; + static fetch(id: string, api: Api): Promise; + createTransfer(params: ICreateTransferParams): Promise; getTransfers(): Promise>; } //# sourceMappingURL=Account.d.ts.map \ No newline at end of file diff --git a/dist/Account.d.ts.map b/dist/Account.d.ts.map index 54987bb..d3bc85e 100644 --- a/dist/Account.d.ts.map +++ b/dist/Account.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"Account.d.ts","sourceRoot":"","sources":["../src/Account.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,SAAS,CAAA;AAC3B,OAAO,QAAQ,MAAM,YAAY,CAAA;AACjC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAA;AAE5E,OAAO,KAAK,EAAE,YAAY,EAA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,OAAO,CAAE,YAAW,QAAQ;IAC9D,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;IACjB,gBAAgB,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAA;IAC9C,aAAa,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAA;IAC3C,iBAAiB,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAA;IAC/C,aAAa,EAAE,KAAK,CAAC,aAAa,CAAC,CAAA;WAEtB,KAAK,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC;IASpD,cAAc,CAAC,MAAM,EAAE,qBAAqB,GAAG,OAAO,CAAC,QAAQ,CAAC;IAMhE,YAAY,IAAI,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;CAItD"} \ No newline at end of file diff --git a/dist/Account.js b/dist/Account.js index c4b43ae..dcb2035 100644 --- a/dist/Account.js +++ b/dist/Account.js @@ -51,26 +51,23 @@ var __generator = (this && this.__generator) || function (thisArg, body) { Object.defineProperty(exports, "__esModule", { value: true }); var Model_1 = require("./Model"); var Transfer_1 = require("./Transfer"); -var API_1 = require("./utils/API"); var Account = (function (_super) { __extends(Account, _super); function Account() { return _super !== null && _super.apply(this, arguments) || this; } Account.fetch = function (id, api) { - if (api === void 0) { api = new API_1.default(); } return __awaiter(this, void 0, void 0, function () { - var accountUrl, data; + var data, account; return __generator(this, function (_a) { switch (_a.label) { case 0: - accountUrl = 'accounts'; - if (!!id) - accountUrl += "/" + id; - return [4, api.get(accountUrl)]; + api.requireAuthed(); + return [4, api.get("accounts/" + id)]; case 1: data = _a.sent(); - return [2, new Account(data, api)]; + account = new Account(data, api); + return [2, account]; } }); }); diff --git a/dist/Account/IAccount.d.ts b/dist/Account/IAccount.d.ts new file mode 100644 index 0000000..7889b79 --- /dev/null +++ b/dist/Account/IAccount.d.ts @@ -0,0 +1,28 @@ +export interface IAccount { + id: string; + status: string; + type: string; + country: string; + createdAt: number; + depositAddresses: { + ETH: string; + BTC: string; + }; + totalBalances: { + BTC: number; + ETH: number; + }; + availableBalances: { + BTC: number; + ETH: number; + }; + profileFields: Array; +} +export interface IProfileField { + fieldId: string; + fieldType: string; + value: string | object | null; + note: string | null; + status: string; +} +//# sourceMappingURL=IAccount.d.ts.map \ No newline at end of file diff --git a/dist/Account/IAccount.d.ts.map b/dist/Account/IAccount.d.ts.map new file mode 100644 index 0000000..165449b --- /dev/null +++ b/dist/Account/IAccount.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"IAccount.d.ts","sourceRoot":"","sources":["../../src/Account/IAccount.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;IACjB,gBAAgB,EAAE;QAChB,GAAG,EAAE,MAAM,CAAA;QACX,GAAG,EAAE,MAAM,CAAA;KACZ,CAAA;IACD,aAAa,EAAE;QACb,GAAG,EAAE,MAAM,CAAA;QACX,GAAG,EAAE,MAAM,CAAA;KACZ,CAAA;IACD,iBAAiB,EAAE;QACjB,GAAG,EAAE,MAAM,CAAA;QACX,GAAG,EAAE,MAAM,CAAA;KACZ,CAAA;IACD,aAAa,EAAE,KAAK,CAAC,aAAa,CAAC,CAAA;CACpC;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;IAC7B,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;IACnB,MAAM,EAAE,MAAM,CAAA;CACf"} \ No newline at end of file diff --git a/dist/Account/IAccount.js b/dist/Account/IAccount.js new file mode 100644 index 0000000..c8ad2e5 --- /dev/null +++ b/dist/Account/IAccount.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/dist/Account/IAccountData.d.ts b/dist/Account/IAccountData.d.ts index a177257..f56303e 100644 --- a/dist/Account/IAccountData.d.ts +++ b/dist/Account/IAccountData.d.ts @@ -1,3 +1,4 @@ +import type { IPaymentMethod } from '../PaymentMethod/IPaymentMethod'; export interface IAccountData { id: string; status: string; @@ -16,6 +17,7 @@ export interface IAccountData { BTC: number; ETH: number; }; + paymentMethods: Array; profileFields: Array; } export interface IProfileField { diff --git a/dist/Account/IAccountData.d.ts.map b/dist/Account/IAccountData.d.ts.map index 80ffa23..b3b96aa 100644 --- a/dist/Account/IAccountData.d.ts.map +++ b/dist/Account/IAccountData.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"IAccountData.d.ts","sourceRoot":"","sources":["../../src/Account/IAccountData.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;IACjB,gBAAgB,EAAE;QAChB,GAAG,EAAE,MAAM,CAAA;QACX,GAAG,EAAE,MAAM,CAAA;KACZ,CAAA;IACD,aAAa,EAAE;QACb,GAAG,EAAE,MAAM,CAAA;QACX,GAAG,EAAE,MAAM,CAAA;KACZ,CAAA;IACD,iBAAiB,EAAE;QACjB,GAAG,EAAE,MAAM,CAAA;QACX,GAAG,EAAE,MAAM,CAAA;KACZ,CAAA;IACD,aAAa,EAAE,KAAK,CAAC,aAAa,CAAC,CAAA;CACpC;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;IAC7B,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;IACnB,MAAM,EAAE,MAAM,CAAA;CACf"} \ No newline at end of file +{"version":3,"file":"IAccountData.d.ts","sourceRoot":"","sources":["../../src/Account/IAccountData.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAA;AAErE,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;IACjB,gBAAgB,EAAE;QAChB,GAAG,EAAE,MAAM,CAAA;QACX,GAAG,EAAE,MAAM,CAAA;KACZ,CAAA;IACD,aAAa,EAAE;QACb,GAAG,EAAE,MAAM,CAAA;QACX,GAAG,EAAE,MAAM,CAAA;KACZ,CAAA;IACD,iBAAiB,EAAE;QACjB,GAAG,EAAE,MAAM,CAAA;QACX,GAAG,EAAE,MAAM,CAAA;KACZ,CAAA;IACD,cAAc,EAAE,KAAK,CAAC,cAAc,CAAC,CAAA;IACrC,aAAa,EAAE,KAAK,CAAC,aAAa,CAAC,CAAA;CACpC;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;IAC7B,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;IACnB,MAAM,EAAE,MAAM,CAAA;CACf"} \ No newline at end of file diff --git a/dist/Model.d.ts b/dist/Model.d.ts index b638f2e..6793d93 100644 --- a/dist/Model.d.ts +++ b/dist/Model.d.ts @@ -1,8 +1,9 @@ -import API from './utils/API'; -export default class Model { - protected readonly api: API; - private data; - constructor(data: object, api: API); - protected set(data: object): void; +import Api from './utils/Api'; +export default abstract class Model { + readonly api: Api; + data: object; + constructor(data: object, api: Api); + set(data: object): void; + set(key: PropertyKey, value: any): void; } //# sourceMappingURL=Model.d.ts.map \ No newline at end of file diff --git a/dist/Model.d.ts.map b/dist/Model.d.ts.map index e36e3fd..ca7cfa6 100644 --- a/dist/Model.d.ts.map +++ b/dist/Model.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"Model.d.ts","sourceRoot":"","sources":["../src/Model.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,aAAa,CAAA;AAE7B,MAAM,CAAC,OAAO,OAAO,KAAK,CAAC,CAAC;IAC1B,SAAS,CAAC,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAA;IAC3B,OAAO,CAAC,IAAI,CAAa;gBAEb,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG;IAoBlC,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM;CAK3B"} \ No newline at end of file +{"version":3,"file":"Model.d.ts","sourceRoot":"","sources":["../src/Model.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,aAAa,CAAA;AAE7B,MAAM,CAAC,OAAO,CAAC,QAAQ,OAAO,KAAK,CAAC,CAAC;IACnC,SAAgB,GAAG,EAAE,GAAG,CAAA;IACjB,IAAI,EAAE,MAAM,CAAK;gBAEZ,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG;IAS3B,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IACvB,GAAG,CAAC,GAAG,EAAE,WAAW,EAAE,KAAK,EAAE,GAAG,GAAG,IAAI;CAU/C"} \ No newline at end of file diff --git a/dist/Model.js b/dist/Model.js index a04d222..09af104 100644 --- a/dist/Model.js +++ b/dist/Model.js @@ -5,26 +5,39 @@ var Model = (function () { this.data = {}; this.set(data); this.api = api; - var proxy = new Proxy(this, { - set: function (target, key, value) { - key in target.data - ? target.data[key] = value - : target[key] = value; - }, - get: function (target, key) { - return key in target.data - ? target.data[key] - : target[key]; - } - }); + var proxy = new Proxy(this, new ModelProxyHandler()); return proxy; } - Model.prototype.set = function (data) { - for (var _i = 0, _a = Object.entries(data); _i < _a.length; _i++) { - var _b = _a[_i], key = _b[0], value = _b[1]; + Model.prototype.set = function (key, value) { + if (typeof key === 'object') { + for (var _i = 0, _a = Object.entries(key); _i < _a.length; _i++) { + var _b = _a[_i], k = _b[0], v = _b[1]; + this.data[k] = v; + } + } + else { this.data[key] = value; } }; return Model; }()); exports.default = Model; +var ModelProxyHandler = (function () { + function ModelProxyHandler() { + } + ModelProxyHandler.prototype.getOwnPropertyDescriptor = function (target, p) { + return { enumerable: true, configurable: true }; + }; + ModelProxyHandler.prototype.set = function (target, key, value) { + key in target.data + ? target.set(key, value) + : target[key] = value; + return true; + }; + ModelProxyHandler.prototype.get = function (target, key) { + return key in target.data + ? target.data[key] + : target[key]; + }; + return ModelProxyHandler; +}()); diff --git a/dist/Transfer.d.ts b/dist/Transfer.d.ts index 2cc2b0d..69266fa 100644 --- a/dist/Transfer.d.ts +++ b/dist/Transfer.d.ts @@ -1,8 +1,7 @@ import Model from './Model'; -import API from './utils/API'; -import type { IStatusHistory, ITransferData, ITransferFees } from './Transfer/ITransferData'; -import type { CreateTransferParams } from './Transfer/ICreateTransferParams'; -export default class Transfer extends Model implements ITransferData { +import Api from './utils/Api'; +import type { ITransferStatusHistory, ITransfer, ITransferFees, ICreateTransferParams } from './Transfer/ITransfer'; +export default class Transfer extends Model implements ITransfer { blockchainTx: string; cancelledAt: number; completedAt: number; @@ -25,10 +24,10 @@ export default class Transfer extends Model implements ITransferData { sourceAmount: number; sourceCurrency: string; status: string; - statusHistories: Array; + statusHistories: Array; totalFees: number; - static verifyCreateParams(params: CreateTransferParams): void; - static create(params: CreateTransferParams, api?: API): Promise; + static verifyCreateParams(params: ICreateTransferParams): void; + static create(params: ICreateTransferParams, api: Api): Promise; confirm(): Promise; } //# sourceMappingURL=Transfer.d.ts.map \ No newline at end of file diff --git a/dist/Transfer.d.ts.map b/dist/Transfer.d.ts.map index a92b156..14c310e 100644 --- a/dist/Transfer.d.ts.map +++ b/dist/Transfer.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"Transfer.d.ts","sourceRoot":"","sources":["../src/Transfer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,SAAS,CAAA;AAC3B,OAAO,GAAG,MAAM,aAAa,CAAA;AAC7B,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AAC5F,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAA;AAE5E,MAAM,CAAC,OAAO,OAAO,QAAS,SAAQ,KAAK,CAAC,QAAQ,CAAE,YAAW,aAAa;IACrE,YAAY,EAAE,MAAM,CAAA;IACpB,WAAW,EAAE,MAAM,CAAA;IACnB,WAAW,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,EAAE,MAAM,CAAA;IAClB,YAAY,EAAE,MAAM,CAAA;IACpB,YAAY,EAAE,MAAM,CAAA;IACpB,SAAS,EAAE,MAAM,CAAA;IACjB,aAAa,EAAE,MAAM,CAAA;IACrB,IAAI,EAAE,aAAa,CAAA;IACnB,EAAE,EAAE,MAAM,CAAA;IACV,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;IACb,gBAAgB,EAAE,MAAM,CAAA;IACxB,cAAc,EAAE,MAAM,CAAA;IACtB,kBAAkB,EAAE,MAAM,CAAA;IAC1B,MAAM,EAAE,MAAM,CAAA;IACd,YAAY,EAAE,MAAM,CAAA;IACpB,cAAc,EAAE,MAAM,CAAA;IACtB,MAAM,EAAE,MAAM,CAAA;IACd,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,EAAE,KAAK,CAAC,sBAAsB,CAAC,CAAA;IAC9C,SAAS,EAAE,MAAM,CAAA;WAEV,kBAAkB,CAAC,MAAM,EAAE,qBAAqB;WAK1C,MAAM,CAAC,MAAM,EAAE,qBAAqB,EAAE,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,QAAQ,CAAC;IAUzE,OAAO;CAIrB"} \ No newline at end of file diff --git a/dist/Transfer.js b/dist/Transfer.js index 9b0babb..6820e61 100644 --- a/dist/Transfer.js +++ b/dist/Transfer.js @@ -50,7 +50,6 @@ var __generator = (this && this.__generator) || function (thisArg, body) { }; Object.defineProperty(exports, "__esModule", { value: true }); var Model_1 = require("./Model"); -var API_1 = require("./utils/API"); var Transfer = (function (_super) { __extends(Transfer, _super); function Transfer() { @@ -61,12 +60,12 @@ var Transfer = (function (_super) { throw new Error('Cannot have both source and destination amounts defined.'); }; Transfer.create = function (params, api) { - if (api === void 0) { api = new API_1.default(); } return __awaiter(this, void 0, void 0, function () { var data; return __generator(this, function (_a) { switch (_a.label) { case 0: + api.requireAuthed(); this.verifyCreateParams(params); return [4, api.post('transfers', params)]; case 1: diff --git a/dist/Transfer/ITransfer.d.ts b/dist/Transfer/ITransfer.d.ts new file mode 100644 index 0000000..da35857 --- /dev/null +++ b/dist/Transfer/ITransfer.d.ts @@ -0,0 +1,61 @@ +export interface ITransfer { + id: string; + sourceAmount: number; + sourceCurrency: string; + destAmount: number; + destCurrency: string; + status: string; + message: string; + customId: string; + exchangeRate: number; + createdAt: number; + fees: ITransferFees; + totalFees: number; + completedAt: number; + cancelledAt: number; + failureReason: string; + expiresAt: number; + reversingSubStatus: string; + reversalReason: string; + pendingSubStatus: string; + dest: string; + blockchainTx: string; + statusHistories: Array; + owner: string; + source: string; +} +export interface ITransferFees { + [assetTicker: string]: number; +} +export interface ITransferStatusHistory { + id: string; + transferId: string; + createdAt: number; + type: string; + statusOrder: number; + statusDetail: string; + state: string; + failedState: boolean; +} +export interface ICreateTransferParams { + source: string; + sourceCurrency: string; + sourceAmount?: string; + destination: string; + destinationCurrency: string; + destinationAmount?: string; + message?: string; + notifyUrl?: string; + autoConfirm?: boolean; + customId?: string; + amountIncludesFees?: boolean; + preview?: boolean; + muteMessages?: boolean; +} +export interface ITransferHistoryResponse { + data: Array; + position: number; + recordsTotal: number; + recordsFiltered: number; +} +//# sourceMappingURL=ITransfer.d.ts.map \ No newline at end of file diff --git a/dist/Transfer/ITransfer.d.ts.map b/dist/Transfer/ITransfer.d.ts.map new file mode 100644 index 0000000..ffeaa1b --- /dev/null +++ b/dist/Transfer/ITransfer.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"ITransfer.d.ts","sourceRoot":"","sources":["../../src/Transfer/ITransfer.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,CAAA;IACV,YAAY,EAAE,MAAM,CAAA;IACpB,cAAc,EAAE,MAAM,CAAA;IACtB,UAAU,EAAE,MAAM,CAAA;IAClB,YAAY,EAAE,MAAM,CAAA;IACpB,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;IAChB,YAAY,EAAE,MAAM,CAAA;IACpB,SAAS,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,aAAa,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;IACjB,WAAW,EAAE,MAAM,CAAA;IACnB,WAAW,EAAE,MAAM,CAAA;IACnB,aAAa,EAAE,MAAM,CAAA;IACrB,SAAS,EAAE,MAAM,CAAA;IACjB,kBAAkB,EAAE,MAAM,CAAA;IAC1B,cAAc,EAAE,MAAM,CAAA;IACtB,gBAAgB,EAAE,MAAM,CAAA;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,YAAY,EAAE,MAAM,CAAA;IACpB,eAAe,EAAE,KAAK,CAAC,sBAAsB,CAAC,CAAA;IAC9C,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,aAAa;IAC5B,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAAA;CAC9B;AAED,MAAM,WAAW,sBAAsB;IACrC,EAAE,EAAE,MAAM,CAAA;IACV,UAAU,EAAE,MAAM,CAAA;IAClB,SAAS,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,YAAY,EAAE,MAAM,CAAA;IACpB,KAAK,EAAE,MAAM,CAAA;IACb,WAAW,EAAE,OAAO,CAAA;CACrB;AAED,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,MAAM,CAAA;IACd,cAAc,EAAE,MAAM,CAAA;IACtB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,WAAW,EAAE,MAAM,CAAA;IACnB,mBAAmB,EAAE,MAAM,CAAA;IAC3B,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB;AAED,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,KAAK,CAAC,SAAS,CAAC,CAAA;IACtB,QAAQ,EAAE,MAAM,CAAA;IAChB,YAAY,EAAE,MAAM,CAAA;IACpB,eAAe,EAAE,MAAM,CAAA;CACxB"} \ No newline at end of file diff --git a/dist/Transfer/ITransfer.js b/dist/Transfer/ITransfer.js new file mode 100644 index 0000000..c8ad2e5 --- /dev/null +++ b/dist/Transfer/ITransfer.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/dist/utils/API.d.ts b/dist/utils/API.d.ts index 82a984f..16b42f2 100644 --- a/dist/utils/API.d.ts +++ b/dist/utils/API.d.ts @@ -1,10 +1,12 @@ import 'es6-shim'; import Authed from '../Authed'; +import { IApiOptions } from './API/IApiOptions'; export default class API extends Authed { - get(path: string, params?: any, options?: any): Promise; - post(path: string, body?: any, options?: any): Promise; - put(path: string, body?: any, options?: any): Promise; - delete(path: string, body?: any, options?: any): Promise; + requireAuthed(): void; + get(path: string, params?: any, options?: IApiOptions): Promise; + post(path: string, body?: any, options?: IApiOptions): Promise; + put(path: string, body?: any, options?: IApiOptions): Promise; + delete(path: string, body?: any, options?: IApiOptions): Promise; private request; private buildRequestOptions; private buildSignature; diff --git a/dist/utils/API.d.ts.map b/dist/utils/API.d.ts.map index 1de3e5d..e4c8812 100644 --- a/dist/utils/API.d.ts.map +++ b/dist/utils/API.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"API.d.ts","sourceRoot":"","sources":["../../src/utils/API.ts"],"names":[],"mappings":"AAIA,OAAO,UAAU,CAAA;AAEjB,OAAO,MAAM,MAAM,WAAW,CAAA;AAM9B,MAAM,CAAC,OAAO,OAAO,GAAI,SAAQ,MAAM;IAC9B,GAAG,CAAC,CAAC,SAAS,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,CAAC,CAAC;IAIzE,IAAI,CAAC,CAAC,SAAS,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,CAAC,CAAC;IAIxE,GAAG,CAAC,CAAC,SAAS,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,CAAC,CAAC;IAIvE,MAAM,CAAC,CAAC,SAAS,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,CAAC,CAAC;IAIjF,OAAO,CAAC,OAAO;IAkBf,OAAO,CAAC,mBAAmB;IAyC3B,OAAO,CAAC,cAAc;CAqBvB"} \ No newline at end of file +{"version":3,"file":"API.d.ts","sourceRoot":"","sources":["../../src/utils/API.ts"],"names":[],"mappings":"AAIA,OAAO,UAAU,CAAA;AAEjB,OAAO,MAAM,MAAM,WAAW,CAAA;AAC9B,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAM/C,MAAM,CAAC,OAAO,OAAO,GAAI,SAAQ,MAAM;IAC9B,aAAa;IAKb,GAAG,CAAC,CAAC,SAAS,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC;IAIjF,IAAI,CAAC,CAAC,SAAS,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC;IAIhF,GAAG,CAAC,CAAC,SAAS,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC;IAI/E,MAAM,CAAC,CAAC,SAAS,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC;IAIzF,OAAO,CAAC,OAAO;IAkBf,OAAO,CAAC,mBAAmB;IAuC3B,OAAO,CAAC,cAAc;CAqBvB"} \ No newline at end of file diff --git a/dist/utils/API.js b/dist/utils/API.js index aa6ba89..aaa0f89 100644 --- a/dist/utils/API.js +++ b/dist/utils/API.js @@ -38,6 +38,10 @@ var API = (function (_super) { function API() { return _super !== null && _super.apply(this, arguments) || this; } + API.prototype.requireAuthed = function () { + if (!this.isAuthed) + throw new Error('Must be authenticated for this endpoint.'); + }; API.prototype.get = function (path, params, options) { return this.request('GET', path, params, options); }; @@ -68,8 +72,7 @@ var API = (function (_super) { }); }; API.prototype.buildRequestOptions = function (method, path, params, options) { - options = options || {}; - var parsedUrl = url.parse(url.resolve(WYRE_BASEURL, "v" + WYRE_API_VERSION + "/" + path), true); + var parsedUrl = url.parse(url.resolve(WYRE_BASEURL, "v" + (path === 'paymentMethods' ? '2' : WYRE_API_VERSION) + "/" + path), true); var json = !(options.headers || {}).hasOwnProperty('Content-Type') || options.headers['Content-Type'] == 'application/json'; var requestOptions = __assign(__assign(__assign({}, this.config.options), options), { url: parsedUrl.protocol + '//' + parsedUrl.host + parsedUrl.pathname, method: method, headers: __assign(__assign({}, this.config.options.headers), options.headers), qs: __assign(__assign(__assign({}, this.config.qs), options.qs), { timestamp: new Date().getTime(), format: this.config.format || WYRE_DEFAULT_API_FORMAT }), json: json }); if (requestOptions.method == 'GET') diff --git a/dist/utils/API/IApiConfig.d.ts b/dist/utils/API/IApiConfig.d.ts new file mode 100644 index 0000000..b365b73 --- /dev/null +++ b/dist/utils/API/IApiConfig.d.ts @@ -0,0 +1,21 @@ +export interface IApiConfig extends IApiOptions { + version: string; + uri?: string; + auth?: IAuth; +} +export interface IApiOptions { + version?: string; + format?: string; + headers?: { + [key: string]: string; + }; + qs?: { + [key: string]: string; + }; +} +export interface IAuth { + secretKey: string; + apiKey: string; + masqueradeTarget?: string; +} +//# sourceMappingURL=IApiConfig.d.ts.map \ No newline at end of file diff --git a/dist/utils/API/IApiConfig.d.ts.map b/dist/utils/API/IApiConfig.d.ts.map new file mode 100644 index 0000000..392a73b --- /dev/null +++ b/dist/utils/API/IApiConfig.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"IApiConfig.d.ts","sourceRoot":"","sources":["../../../src/utils/API/IApiConfig.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAW,SAAQ,WAAW;IAC7C,OAAO,EAAE,MAAM,CAAA;IACf,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,KAAK,CAAA;CACb;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAA;IACnC,EAAE,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAA;CAC/B;AAED,MAAM,WAAW,KAAK;IACpB,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,MAAM,CAAA;IACd,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAC1B"} \ No newline at end of file diff --git a/dist/utils/API/IApiConfig.js b/dist/utils/API/IApiConfig.js new file mode 100644 index 0000000..c8ad2e5 --- /dev/null +++ b/dist/utils/API/IApiConfig.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/dist/utils/API/IApiOptions.d.ts b/dist/utils/API/IApiOptions.d.ts new file mode 100644 index 0000000..4b7bba8 --- /dev/null +++ b/dist/utils/API/IApiOptions.d.ts @@ -0,0 +1,6 @@ +export interface IApiOptions { + headers?: object; + qs?: object; + version?: string; +} +//# sourceMappingURL=IApiOptions.d.ts.map \ No newline at end of file diff --git a/dist/utils/API/IApiOptions.d.ts.map b/dist/utils/API/IApiOptions.d.ts.map new file mode 100644 index 0000000..87fa81a --- /dev/null +++ b/dist/utils/API/IApiOptions.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"IApiOptions.d.ts","sourceRoot":"","sources":["../../../src/utils/API/IApiOptions.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB"} \ No newline at end of file diff --git a/dist/utils/API/IApiOptions.js b/dist/utils/API/IApiOptions.js new file mode 100644 index 0000000..c8ad2e5 --- /dev/null +++ b/dist/utils/API/IApiOptions.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/dist/utils/API/IOptions.d.ts b/dist/utils/API/IOptions.d.ts new file mode 100644 index 0000000..c3462fd --- /dev/null +++ b/dist/utils/API/IOptions.d.ts @@ -0,0 +1,6 @@ +export interface IOptions { + headers?: object; + qs?: object; + version: string; +} +//# sourceMappingURL=IOptions.d.ts.map \ No newline at end of file diff --git a/dist/utils/API/IOptions.d.ts.map b/dist/utils/API/IOptions.d.ts.map new file mode 100644 index 0000000..b8cff5a --- /dev/null +++ b/dist/utils/API/IOptions.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"IOptions.d.ts","sourceRoot":"","sources":["../../../src/utils/API/IOptions.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,QAAQ;IACvB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,OAAO,EAAE,MAAM,CAAA;CAChB"} \ No newline at end of file diff --git a/dist/utils/API/IOptions.js b/dist/utils/API/IOptions.js new file mode 100644 index 0000000..c8ad2e5 --- /dev/null +++ b/dist/utils/API/IOptions.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/dist/utils/Api.d.ts b/dist/utils/Api.d.ts new file mode 100644 index 0000000..e8e3392 --- /dev/null +++ b/dist/utils/Api.d.ts @@ -0,0 +1,16 @@ +import 'es6-shim'; +import { IApiConfig, IApiOptions } from './API/IApiConfig'; +export default class Api { + readonly config: IApiConfig; + constructor(config?: IApiConfig); + get isAuthed(): boolean; + requireAuthed(): void; + get(path: string, params?: object, options?: IApiOptions): Promise; + post(path: string, body?: object, options?: IApiOptions): Promise; + put(path: string, body?: object, options?: IApiOptions): Promise; + delete(path: string, body?: object, options?: IApiOptions): Promise; + private request; + private buildRequestOptions; + private buildSignature; +} +//# sourceMappingURL=Api.d.ts.map \ No newline at end of file diff --git a/dist/utils/Api.d.ts.map b/dist/utils/Api.d.ts.map new file mode 100644 index 0000000..a2a2252 --- /dev/null +++ b/dist/utils/Api.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"Api.d.ts","sourceRoot":"","sources":["../../src/utils/Api.ts"],"names":[],"mappings":"AAIA,OAAO,UAAU,CAAA;AAEjB,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAE1D,MAAM,CAAC,OAAO,OAAO,GAAG;IACtB,SAAgB,MAAM,EAAE,UAAU,CAAA;gBAEtB,MAAM,CAAC,EAAE,UAAU;IAc/B,IAAW,QAAQ,IAAI,OAAO,CAE7B;IAEM,aAAa;IAKb,GAAG,CAAC,CAAC,SAAS,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC;IAIpF,IAAI,CAAC,CAAC,SAAS,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC;IAInF,GAAG,CAAC,CAAC,SAAS,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC;IAIlF,MAAM,CAAC,CAAC,SAAS,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC;IAI5F,OAAO,CAAC,OAAO;IAkBf,OAAO,CAAC,mBAAmB;IAiD3B,OAAO,CAAC,cAAc;CAuBvB"} \ No newline at end of file diff --git a/dist/utils/Api.js b/dist/utils/Api.js new file mode 100644 index 0000000..6cad3d0 --- /dev/null +++ b/dist/utils/Api.js @@ -0,0 +1,111 @@ +"use strict"; +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var request = require("request"); +var crypto = require("crypto"); +var querystring = require("querystring"); +var url = require("url"); +require("es6-shim"); +var Api = (function () { + function Api(config) { + var defaultConfig = { + uri: 'https://api.testwyre.com', + version: '3', + format: 'json', + qs: {}, + headers: { + 'Content-Type': 'application/json' + } + }; + this.config = Object.assign({}, defaultConfig, config); + } + Object.defineProperty(Api.prototype, "isAuthed", { + get: function () { + return !!this.config.auth && !!this.config.auth.secretKey && !!this.config.auth.apiKey; + }, + enumerable: true, + configurable: true + }); + Api.prototype.requireAuthed = function () { + if (!this.isAuthed) + throw new Error('Must be authenticated for this endpoint.'); + }; + Api.prototype.get = function (path, params, options) { + return this.request('GET', path, params, options); + }; + Api.prototype.post = function (path, body, options) { + return this.request('POST', path, body, options); + }; + Api.prototype.put = function (path, body, options) { + return this.request('PUT', path, body, options); + }; + Api.prototype.delete = function (path, body, options) { + return this.request('DELETE', path, body, options); + }; + Api.prototype.request = function (method, path, params, options) { + if (params === void 0) { params = {}; } + if (options === void 0) { options = {}; } + if (!path) + throw 'path required'; + var requestOptions = this.buildRequestOptions(method, path, params, options); + return new Promise(function (resolve, reject) { + request(requestOptions, function (err, res) { + if (err) + throw err; + else if (res.statusCode >= 200 && res.statusCode < 300) + resolve(res.body || {}); + else + reject(res.body || { statusCode: res.statusCode }); + }); + }); + }; + Api.prototype.buildRequestOptions = function (method, path, params, options) { + var config = __assign(__assign(__assign({}, this.config), options), { headers: __assign(__assign({}, this.config.headers), options.headers), qs: __assign(__assign({}, this.config.qs), options.qs) }); + var parsedUrl = url.parse(url.resolve(config.uri, "v" + config.version + "/" + path), true); + var json = config.headers['Content-Type'] === 'application/json'; + var requestOptions = __assign(__assign({}, options), { url: parsedUrl.protocol + '//' + parsedUrl.host + parsedUrl.pathname, method: method, headers: __assign({}, config.headers), qs: __assign(__assign({}, config.qs), { timestamp: new Date().getTime(), format: this.config.format }), json: json }); + if (requestOptions.method == 'GET') + requestOptions.qs = Object.assign(requestOptions.qs, params); + else + requestOptions.body = params; + Object.assign(requestOptions.qs, parsedUrl.query); + if (this.isAuthed && config.auth.masqueradeTarget && !('masqueradeAs' in requestOptions)) + requestOptions.qs.masqueradeAs = config.auth.masqueradeTarget; + if (this.isAuthed) { + requestOptions.headers['X-Api-Key'] = config.auth.apiKey; + requestOptions.headers['X-Api-Signature'] = this.buildSignature(requestOptions); + } + return requestOptions; + }; + Api.prototype.buildSignature = function (requestOptions) { + this.requireAuthed(); + var buffers = []; + var encoding = 'utf8'; + buffers.push(Buffer.from(requestOptions.url.toString(), encoding)); + buffers.push(Buffer.from(requestOptions.url.toString().indexOf('?') < 0 ? '?' : '&', encoding)); + buffers.push(Buffer.from(querystring.stringify(requestOptions.qs), encoding)); + if (requestOptions.body) { + if (typeof requestOptions.body == 'string') + buffers.push(Buffer.from(requestOptions.body, encoding)); + else if (requestOptions.body instanceof Buffer) + buffers.push(requestOptions.body); + else + buffers.push(Buffer.from(JSON.stringify(requestOptions.body), encoding)); + } + return crypto.createHmac('sha256', this.config.auth.secretKey) + .update(Buffer.concat(buffers)) + .digest('hex'); + }; + return Api; +}()); +exports.default = Api; diff --git a/dist/utils/Auth/IAuthed.d.ts b/dist/utils/Auth/IAuthed.d.ts new file mode 100644 index 0000000..f13884f --- /dev/null +++ b/dist/utils/Auth/IAuthed.d.ts @@ -0,0 +1 @@ +//# sourceMappingURL=IAuthed.d.ts.map \ No newline at end of file diff --git a/dist/utils/Auth/IAuthed.d.ts.map b/dist/utils/Auth/IAuthed.d.ts.map new file mode 100644 index 0000000..19d1bd9 --- /dev/null +++ b/dist/utils/Auth/IAuthed.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"IAuthed.d.ts","sourceRoot":"","sources":["../../../src/utils/Auth/IAuthed.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/utils/Auth/IAuthed.js b/dist/utils/Auth/IAuthed.js new file mode 100644 index 0000000..e69de29 diff --git a/dist/utils/Authed.d.ts b/dist/utils/Authed.d.ts new file mode 100644 index 0000000..c4db48e --- /dev/null +++ b/dist/utils/Authed.d.ts @@ -0,0 +1,6 @@ +import Api from './Api'; +export default class Authed { + private readonly api; + constructor(api: Api); +} +//# sourceMappingURL=Authed.d.ts.map \ No newline at end of file diff --git a/dist/utils/Authed.d.ts.map b/dist/utils/Authed.d.ts.map new file mode 100644 index 0000000..f760fe6 --- /dev/null +++ b/dist/utils/Authed.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"Authed.d.ts","sourceRoot":"","sources":["../../src/utils/Authed.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,OAAO,CAAA;AAEvB,MAAM,CAAC,OAAO,OAAO,MAAM;IACzB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAK;gBAEb,GAAG,EAAE,GAAG;CAGrB"} \ No newline at end of file diff --git a/dist/utils/Authed.js b/dist/utils/Authed.js new file mode 100644 index 0000000..c552fa5 --- /dev/null +++ b/dist/utils/Authed.js @@ -0,0 +1,9 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var Authed = (function () { + function Authed(api) { + this.api = api; + } + return Authed; +}()); +exports.default = Authed; diff --git a/dist/wyre.d.ts b/dist/wyre.d.ts index d95dcbb..d7669f4 100644 --- a/dist/wyre.d.ts +++ b/dist/wyre.d.ts @@ -1,9 +1,8 @@ -import Authed from './Authed'; import Account from './Account'; -import type { Config } from './Authed'; -export default class WyreClient extends Authed { +import type { IApiConfig } from './utils/API/IApiConfig'; +export default class WyreClient { private readonly api; - constructor(config: Config); - fetchAccount(id?: string, masquerade?: boolean): Promise; + constructor(config: IApiConfig); + fetchAccount(id: string, masquerade?: boolean): Promise; } //# sourceMappingURL=wyre.d.ts.map \ No newline at end of file diff --git a/dist/wyre.d.ts.map b/dist/wyre.d.ts.map index ee6b092..1f53b14 100644 --- a/dist/wyre.d.ts.map +++ b/dist/wyre.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"wyre.d.ts","sourceRoot":"","sources":["../src/wyre.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,UAAU,CAAA;AAC7B,OAAO,OAAO,MAAM,WAAW,CAAA;AAE/B,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAEtC,MAAM,CAAC,OAAO,OAAO,UAAW,SAAQ,MAAM;IAC5C,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAK;gBAEb,MAAM,EAAE,MAAM;IAMb,YAAY,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,UAAU,UAAQ,GAAG,OAAO,CAAC,OAAO,CAAC;CAc7E"} \ No newline at end of file +{"version":3,"file":"wyre.d.ts","sourceRoot":"","sources":["../src/wyre.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,WAAW,CAAA;AAE/B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAExD,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAK;gBAEb,MAAM,EAAE,UAAU;IAIjB,YAAY,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,UAAQ,GAAG,OAAO,CAAC,OAAO,CAAC;CAc5E"} \ No newline at end of file diff --git a/dist/wyre.js b/dist/wyre.js index f2ec7fe..b314a81 100644 --- a/dist/wyre.js +++ b/dist/wyre.js @@ -1,17 +1,4 @@ "use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { @@ -49,15 +36,11 @@ var __generator = (this && this.__generator) || function (thisArg, body) { } }; Object.defineProperty(exports, "__esModule", { value: true }); -var Authed_1 = require("./Authed"); var Account_1 = require("./Account"); -var API_1 = require("./utils/API"); -var WyreClient = (function (_super) { - __extends(WyreClient, _super); +var Api_1 = require("./utils/Api"); +var WyreClient = (function () { function WyreClient(config) { - var _this = _super.call(this, config) || this; - _this.api = new API_1.default(config); - return _this; + this.api = new Api_1.default(config); } WyreClient.prototype.fetchAccount = function (id, masquerade) { if (masquerade === void 0) { masquerade = false; } @@ -65,17 +48,17 @@ var WyreClient = (function (_super) { var api, newConfig; return __generator(this, function (_a) { api = this.api; - if (!!id && masquerade) { - if (!this.isAuthed) + if (masquerade) { + if (!this.api.isAuthed) throw new Error('Cannot masquerade with no authorization.'); - newConfig = Object.assign({}, this.config); + newConfig = Object.assign({}, this.api.config); newConfig.auth.masqueradeTarget = id; - api = new API_1.default(newConfig); + api = new Api_1.default(newConfig); } return [2, Account_1.default.fetch(id, api)]; }); }); }; return WyreClient; -}(Authed_1.default)); +}()); exports.default = WyreClient; diff --git a/src/Account.ts b/src/Account.ts index 60fb516..3f2824a 100644 --- a/src/Account.ts +++ b/src/Account.ts @@ -1,11 +1,10 @@ import Model from './Model' import Transfer from './Transfer' -import type { CreateTransferParams } from './Transfer/ICreateTransferParams' -import type { ITransferHistory } from './Transfer/ITransferData' -import type { IAccountData, IProfileField } from './Account/IAccountData' -import API from './utils/API' +import Api from './utils/Api' +import type { IAccount, IProfileField } from './Account/IAccount' +import type { ICreateTransferParams, ITransferHistoryResponse } from './Transfer/ITransfer' -export default class Account extends Model implements IAccountData { +export default class Account extends Model implements IAccount { public id: string public status: string public type: string @@ -16,24 +15,23 @@ export default class Account extends Model implements IAccountData { public availableBalances: { BTC: number; ETH: number } public profileFields: Array - public static async fetch(id?: string, api = new API()): Promise { - let accountUrl = 'accounts' - if (!!id) - accountUrl += `/${id}` + public static async fetch(id: string, api: Api): Promise { + api.requireAuthed() - const data = await api.get(accountUrl) + const data = await api.get(`accounts/${id}`) + const account = new Account(data, api) - return new Account(data, api) + return account } - public async createTransfer(params: CreateTransferParams): Promise { + public async createTransfer(params: ICreateTransferParams): Promise { const transfer = await Transfer.create(params, this.api) return transfer } public async getTransfers(): Promise> { - const { data } = await this.api.get('transfers') + const { data } = await this.api.get('transfers') return data.map((transferData) => new Transfer(transferData, this.api)) } } \ No newline at end of file diff --git a/src/Account/IAccountData.ts b/src/Account/IAccount.ts similarity index 93% rename from src/Account/IAccountData.ts rename to src/Account/IAccount.ts index 26f8762..8457cfb 100644 --- a/src/Account/IAccountData.ts +++ b/src/Account/IAccount.ts @@ -1,4 +1,4 @@ -export interface IAccountData { +export interface IAccount { id: string status: string type: string diff --git a/src/Authed.ts b/src/Authed.ts deleted file mode 100644 index f2e1844..0000000 --- a/src/Authed.ts +++ /dev/null @@ -1,34 +0,0 @@ -export interface Auth { - secretKey: string - apiKey: string - masqueradeTarget?: string -} - -export interface Config { - auth?: Auth - apiVersion?: string - format?: string - qs?: { [key: string]: string }, - options?: { - headers?: { [key: string]: string } - } -} - -export default class Authed { - protected readonly config: Config - - constructor(config?: Config) { - const defaultConfig: Config = { - qs: {}, - options: { - headers: {} - } - } - - this.config = Object.assign({}, defaultConfig, config) - } - - public get isAuthed(): boolean { - return !!this.config.auth && !!this.config.auth.secretKey && !!this.config.auth.apiKey - } -} \ No newline at end of file diff --git a/src/Model.ts b/src/Model.ts index 62a71e7..33e2eeb 100644 --- a/src/Model.ts +++ b/src/Model.ts @@ -1,32 +1,47 @@ -import API from './utils/API' +import Api from './utils/Api' -export default class Model { - protected readonly api: API - private data: object = {} +export default abstract class Model { + public readonly api: Api + public data: object = {} - constructor(data: object, api: API) { + constructor(data: object, api: Api) { this.set(data) this.api = api - const proxy = new Proxy>(this, { - set(target: Model, key: string | number | symbol, value: any): any { - key in target.data - ? target.data[key] = value - : target[key] = value - }, - get(target: Model, key: string | number | symbol): any { - return key in target.data - ? target.data[key] - : target[key] - } - }) + const proxy = new Proxy(this, new ModelProxyHandler()) return proxy } - protected set(data: object) { - for (const [ key, value ] of Object.entries(data)) { + public set(data: object): void + public set(key: PropertyKey, value: any): void + public set(key: PropertyKey | object, value?: any): void { + if (typeof key === 'object') { + for (const [ k, v ] of Object.entries(key)) { + this.data[k] = v + } + } else { this.data[key] = value } } +} + +class ModelProxyHandler> implements ProxyHandler { + public getOwnPropertyDescriptor(target: T, p: PropertyKey): PropertyDescriptor | undefined { + return { enumerable: true, configurable: true } + } + + public set(target: T, key: PropertyKey, value: any): boolean { + key in target.data + ? target.set(key, value) + : target[key] = value + + return true + } + + public get(target: T, key: PropertyKey): any { + return key in target.data + ? target.data[key] + : target[key] + } } \ No newline at end of file diff --git a/src/Transfer.ts b/src/Transfer.ts index 852663f..a50ff0e 100644 --- a/src/Transfer.ts +++ b/src/Transfer.ts @@ -1,9 +1,8 @@ import Model from './Model' -import API from './utils/API' -import type { IStatusHistory, ITransferData, ITransferFees } from './Transfer/ITransferData' -import type { CreateTransferParams } from './Transfer/ICreateTransferParams' +import Api from './utils/Api' +import type { ITransferStatusHistory, ITransfer, ITransferFees, ICreateTransferParams } from './Transfer/ITransfer' -export default class Transfer extends Model implements ITransferData { +export default class Transfer extends Model implements ITransfer { public blockchainTx: string public cancelledAt: number public completedAt: number @@ -26,24 +25,26 @@ export default class Transfer extends Model implements ITransferData { public sourceAmount: number public sourceCurrency: string public status: string - public statusHistories: Array + public statusHistories: Array public totalFees: number - public static verifyCreateParams(params: CreateTransferParams) { + public static verifyCreateParams(params: ICreateTransferParams) { if (params.sourceAmount && params.destinationAmount) throw new Error('Cannot have both source and destination amounts defined.') } - public static async create(params: CreateTransferParams, api = new API()): Promise { + public static async create(params: ICreateTransferParams, api: Api): Promise { + api.requireAuthed() + this.verifyCreateParams(params) - const data = await api.post('transfers', params) + const data = await api.post('transfers', params) return new Transfer(data, api) } public async confirm() { - const data = await this.api.post(`transfers/${this.id}/confirm`) + const data = await this.api.post(`transfers/${this.id}/confirm`) this.set(data) } } diff --git a/src/Transfer/ICreateTransferParams.ts b/src/Transfer/ICreateTransferParams.ts deleted file mode 100644 index fdfedfd..0000000 --- a/src/Transfer/ICreateTransferParams.ts +++ /dev/null @@ -1,15 +0,0 @@ -export interface CreateTransferParams { - source: string - sourceCurrency: string - sourceAmount?: string - destination: string - destinationCurrency: string - destinationAmount?: string - message?: string - notifyUrl?: string - autoConfirm?: boolean - customId?: string - amountIncludesFees?: boolean - preview?: boolean - muteMessages?: boolean -} diff --git a/src/Transfer/ITransferData.ts b/src/Transfer/ITransfer.ts similarity index 59% rename from src/Transfer/ITransferData.ts rename to src/Transfer/ITransfer.ts index c688bf5..bab715a 100644 --- a/src/Transfer/ITransferData.ts +++ b/src/Transfer/ITransfer.ts @@ -1,11 +1,4 @@ -export interface ITransferHistory { - data: Array - position: number - recordsTotal: number - recordsFiltered: number -} - -export interface ITransferData { +export interface ITransfer { id: string sourceAmount: number sourceCurrency: string @@ -27,7 +20,7 @@ export interface ITransferData { pendingSubStatus: string dest: string blockchainTx: string - statusHistories: Array + statusHistories: Array owner: string source: string } @@ -36,7 +29,7 @@ export interface ITransferFees { [assetTicker: string]: number } -export interface IStatusHistory { +export interface ITransferStatusHistory { id: string transferId: string createdAt: number @@ -46,3 +39,26 @@ export interface IStatusHistory { state: string failedState: boolean } + +export interface ICreateTransferParams { + source: string + sourceCurrency: string + sourceAmount?: string + destination: string + destinationCurrency: string + destinationAmount?: string + message?: string + notifyUrl?: string + autoConfirm?: boolean + customId?: string + amountIncludesFees?: boolean + preview?: boolean + muteMessages?: boolean +} + +export interface ITransferHistoryResponse { + data: Array + position: number + recordsTotal: number + recordsFiltered: number +} diff --git a/src/utils/API/IApiConfig.ts b/src/utils/API/IApiConfig.ts new file mode 100644 index 0000000..8702c47 --- /dev/null +++ b/src/utils/API/IApiConfig.ts @@ -0,0 +1,18 @@ +export interface IApiConfig extends IApiOptions { + version: string + uri?: string + auth?: IAuth +} + +export interface IApiOptions { + version?: string + format?: string + headers?: { [key: string]: string } + qs?: { [key: string]: string } +} + +export interface IAuth { + secretKey: string + apiKey: string + masqueradeTarget?: string +} diff --git a/src/utils/API.ts b/src/utils/Api.ts similarity index 57% rename from src/utils/API.ts rename to src/utils/Api.ts index aa24e07..1877b6c 100644 --- a/src/utils/API.ts +++ b/src/utils/Api.ts @@ -4,30 +4,51 @@ import * as querystring from 'querystring' import * as url from 'url' import 'es6-shim' -import Authed from '../Authed' +import { IApiConfig, IApiOptions } from './API/IApiConfig' -const WYRE_BASEURL = 'https://api.testwyre.com' -const WYRE_API_VERSION = '3' -const WYRE_DEFAULT_API_FORMAT = 'json' +export default class Api { + public readonly config: IApiConfig -export default class API extends Authed { - public get(path: string, params?: any, options?: any): Promise { + constructor(config?: IApiConfig) { + const defaultConfig: IApiConfig = { + uri: 'https://api.testwyre.com', + version: '3', + format: 'json', + qs: {}, + headers: { + 'Content-Type': 'application/json' + } + } + + this.config = Object.assign({}, defaultConfig, config) + } + + public get isAuthed(): boolean { + return !!this.config.auth && !!this.config.auth.secretKey && !!this.config.auth.apiKey + } + + public requireAuthed() { + if (!this.isAuthed) + throw new Error('Must be authenticated for this endpoint.') + } + + public get(path: string, params?: object, options?: IApiOptions): Promise { return this.request('GET', path, params, options) } - public post(path: string, body?: any, options?: any): Promise { + public post(path: string, body?: object, options?: IApiOptions): Promise { return this.request('POST', path, body, options) } - public put(path: string, body?: any, options?: any): Promise { + public put(path: string, body?: object, options?: IApiOptions): Promise { return this.request('PUT', path, body, options) } - public delete(path: string, body?: any, options?: any): Promise { + public delete(path: string, body?: object, options?: IApiOptions): Promise { return this.request('DELETE', path, body, options) } - private request(method: string, path: string, params: any = {}, options: any = {}): Promise { + private request(method: string, path: string, params: object = {}, options: IApiOptions = {}): Promise { if (!path) throw 'path required' @@ -45,26 +66,34 @@ export default class API extends Authed { }) } - private buildRequestOptions(method: string, path: string, params: any, options: any): request.UrlOptions & request.CoreOptions { - options = options || {} + private buildRequestOptions(method: string, path: string, params: any, options: IApiOptions): request.UrlOptions & request.CoreOptions { + const config: IApiConfig = { + ...this.config, + ...options, + headers: { + ...this.config.headers, + ...options.headers + }, + qs: { + ...this.config.qs, + ...options.qs + } + } - let parsedUrl = url.parse(url.resolve(WYRE_BASEURL, `v${WYRE_API_VERSION}/${path}`), true) - let json = !(options.headers || {}).hasOwnProperty('Content-Type') || options.headers['Content-Type'] == 'application/json' + const parsedUrl = url.parse(url.resolve(config.uri, `v${config.version}/${path}`), true) + const json = config.headers['Content-Type'] === 'application/json' let requestOptions: request.UrlOptions & request.CoreOptions = { - ...this.config.options, ...options, url: parsedUrl.protocol + '//' + parsedUrl.host + parsedUrl.pathname, // no querystring here! method: method, headers: { - ...this.config.options.headers, - ...options.headers + ...config.headers }, qs: { - ...this.config.qs, - ...options.qs, + ...config.qs, timestamp: new Date().getTime(), - format: this.config.format || WYRE_DEFAULT_API_FORMAT + format: this.config.format }, json: json } @@ -75,11 +104,11 @@ export default class API extends Authed { requestOptions.body = params Object.assign(requestOptions.qs, parsedUrl.query) - if (this.isAuthed && this.config.auth.masqueradeTarget && !('masqueradeAs' in requestOptions)) - requestOptions.qs.masqueradeAs = this.config.auth.masqueradeTarget + if (this.isAuthed && config.auth.masqueradeTarget && !('masqueradeAs' in requestOptions)) + requestOptions.qs.masqueradeAs = config.auth.masqueradeTarget if (this.isAuthed) { - requestOptions.headers['X-Api-Key'] = this.config.auth.apiKey + requestOptions.headers['X-Api-Key'] = config.auth.apiKey requestOptions.headers['X-Api-Signature'] = this.buildSignature(requestOptions) } @@ -87,6 +116,8 @@ export default class API extends Authed { } private buildSignature(requestOptions: request.UrlOptions & request.CoreOptions): string { + this.requireAuthed() + let buffers: Buffer[] = [] const encoding = 'utf8' diff --git a/src/wyre.ts b/src/wyre.ts index 532c7dd..4538df0 100644 --- a/src/wyre.ts +++ b/src/wyre.ts @@ -1,27 +1,24 @@ -import Authed from './Authed' import Account from './Account' -import API from './utils/API' -import type { Config } from './Authed' +import Api from './utils/Api' +import type { IApiConfig } from './utils/API/IApiConfig' -export default class WyreClient extends Authed { - private readonly api: API +export default class WyreClient { + private readonly api: Api - constructor(config: Config) { - super(config) - - this.api = new API(config) + constructor(config: IApiConfig) { + this.api = new Api(config) } - public async fetchAccount(id?: string, masquerade = false): Promise { + public async fetchAccount(id: string, masquerade = false): Promise { let api = this.api - if (!!id && masquerade) { - if (!this.isAuthed) + if (masquerade) { + if (!this.api.isAuthed) throw new Error('Cannot masquerade with no authorization.') - const newConfig = Object.assign({}, this.config) + const newConfig = Object.assign({}, this.api.config) newConfig.auth.masqueradeTarget = id - api = new API(newConfig) + api = new Api(newConfig) } return Account.fetch(id, api) From 5e5ba5b7bbcae5693341d716b412a62d454eb9f4 Mon Sep 17 00:00:00 2001 From: Noah Passalacqua Date: Tue, 31 Mar 2020 15:18:03 -0500 Subject: [PATCH 03/20] Fetch payment methods for account. --- dist/Account.d.ts | 2 + dist/Account.d.ts.map | 2 +- dist/Account.js | 13 ++-- dist/Account/IAccount.d.ts | 2 + dist/Account/IAccount.d.ts.map | 2 +- dist/PaymentMethod.d.ts | 39 +++++++++++ dist/PaymentMethod.d.ts.map | 1 + dist/PaymentMethod.js | 77 ++++++++++++++++++++++ dist/PaymentMethod/IPaymentMethod.d.ts | 40 +++++++++++ dist/PaymentMethod/IPaymentMethod.d.ts.map | 1 + dist/PaymentMethod/IPaymentMethod.js | 2 + src/Account.ts | 3 + src/Account/IAccount.ts | 3 + src/PaymentMethod.ts | 47 +++++++++++++ src/PaymentMethod/IPaymentMethod.ts | 44 +++++++++++++ 15 files changed, 272 insertions(+), 6 deletions(-) create mode 100644 dist/PaymentMethod.d.ts create mode 100644 dist/PaymentMethod.d.ts.map create mode 100644 dist/PaymentMethod.js create mode 100644 dist/PaymentMethod/IPaymentMethod.d.ts create mode 100644 dist/PaymentMethod/IPaymentMethod.d.ts.map create mode 100644 dist/PaymentMethod/IPaymentMethod.js create mode 100644 src/PaymentMethod.ts create mode 100644 src/PaymentMethod/IPaymentMethod.ts diff --git a/dist/Account.d.ts b/dist/Account.d.ts index 9a8d3dc..1871329 100644 --- a/dist/Account.d.ts +++ b/dist/Account.d.ts @@ -1,5 +1,6 @@ import Model from './Model'; import Transfer from './Transfer'; +import PaymentMethod from './PaymentMethod'; import Api from './utils/Api'; import type { IAccount, IProfileField } from './Account/IAccount'; import type { ICreateTransferParams } from './Transfer/ITransfer'; @@ -22,6 +23,7 @@ export default class Account extends Model implements IAccount { ETH: number; }; profileFields: Array; + paymentMethods: Array; static fetch(id: string, api: Api): Promise; createTransfer(params: ICreateTransferParams): Promise; getTransfers(): Promise>; diff --git a/dist/Account.d.ts.map b/dist/Account.d.ts.map index d3bc85e..48204a8 100644 --- a/dist/Account.d.ts.map +++ b/dist/Account.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"Account.d.ts","sourceRoot":"","sources":["../src/Account.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,SAAS,CAAA;AAC3B,OAAO,QAAQ,MAAM,YAAY,CAAA;AACjC,OAAO,GAAG,MAAM,aAAa,CAAA;AAC7B,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AACjE,OAAO,KAAK,EAAE,qBAAqB,EAA4B,MAAM,sBAAsB,CAAA;AAE3F,MAAM,CAAC,OAAO,OAAO,OAAQ,SAAQ,KAAK,CAAC,O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d,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;IACjB,gBAAgB,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAA;IAC9C,aAAa,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAA;IAC3C,iBAAiB,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAA;IAC/C,aAAa,EAAE,KAAK,CAAC,aAAa,CAAC,CAAA;IACnC,cAAc,EAAE,KAAK,CAAC,aAAa,CAAC,CAAA;WAEvB,KAAK,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC;IAUpD,cAAc,CAAC,MAAM,EAAE,qBAAqB,GAAG,OAAO,CAAC,QAAQ,CAAC;IAMhE,YAAY,IAAI,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;CAItD"} \ No newline at end of file diff --git a/dist/Account.js b/dist/Account.js index dcb2035..12cdc21 100644 --- a/dist/Account.js +++ b/dist/Account.js @@ -51,6 +51,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) { Object.defineProperty(exports, "__esModule", { value: true }); var Model_1 = require("./Model"); var Transfer_1 = require("./Transfer"); +var PaymentMethod_1 = require("./PaymentMethod"); var Account = (function (_super) { __extends(Account, _super); function Account() { @@ -58,15 +59,19 @@ var Account = (function (_super) { } Account.fetch = function (id, api) { return __awaiter(this, void 0, void 0, function () { - var data, account; - return __generator(this, function (_a) { - switch (_a.label) { + var data, account, _a; + return __generator(this, function (_b) { + switch (_b.label) { case 0: api.requireAuthed(); return [4, api.get("accounts/" + id)]; case 1: - data = _a.sent(); + data = _b.sent(); account = new Account(data, api); + _a = account; + return [4, PaymentMethod_1.default.fetchAll(api)]; + case 2: + _a.paymentMethods = _b.sent(); return [2, account]; } }); diff --git a/dist/Account/IAccount.d.ts b/dist/Account/IAccount.d.ts index 7889b79..b448069 100644 --- a/dist/Account/IAccount.d.ts +++ b/dist/Account/IAccount.d.ts @@ -1,3 +1,4 @@ +import type { IPaymentMethod } from '../PaymentMethod/IPaymentMethod'; export interface IAccount { id: string; status: string; @@ -17,6 +18,7 @@ export interface IAccount { ETH: number; }; profileFields: Array; + paymentMethods: Array; } export interface IProfileField { fieldId: string; diff --git a/dist/Account/IAccount.d.ts.map b/dist/Account/IAccount.d.ts.map index 165449b..8c77240 100644 --- a/dist/Account/IAccount.d.ts.map +++ b/dist/Account/IAccount.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"IAccount.d.ts","sourceRoot":"","sources":["../../src/Account/IAccount.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;IACjB,gBAAgB,EAAE;QAChB,GAAG,EAAE,MAAM,CAAA;QACX,GAAG,EAAE,MAAM,CAAA;KACZ,CAAA;IACD,aAAa,EAAE;QACb,GAAG,EAAE,MAAM,CAAA;QACX,GAAG,EAAE,MAAM,CAAA;KACZ,CAAA;IACD,iBAAiB,EAAE;QACjB,GAAG,EAAE,MAAM,CAAA;QACX,GAAG,EAAE,MAAM,CAAA;KACZ,CAAA;IACD,aAAa,EAAE,KAAK,CAAC,aAAa,CAAC,CAAA;CACpC;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;IAC7B,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;IACnB,MAAM,EAAE,MAAM,CAAA;CACf"} \ No newline at end of file +{"version":3,"file":"IAccount.d.ts","sourceRoot":"","sources":["../../src/Account/IAccount.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAA;AAErE,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;IACjB,gBAAgB,EAAE;QAChB,GAAG,EAAE,MAAM,CAAA;QACX,GAAG,EAAE,MAAM,CAAA;KACZ,CAAA;IACD,aAAa,EAAE;QACb,GAAG,EAAE,MAAM,CAAA;QACX,GAAG,EAAE,MAAM,CAAA;KACZ,CAAA;IACD,iBAAiB,EAAE;QACjB,GAAG,EAAE,MAAM,CAAA;QACX,GAAG,EAAE,MAAM,CAAA;KACZ,CAAA;IACD,aAAa,EAAE,KAAK,CAAC,aAAa,CAAC,CAAA;IACnC,cAAc,EAAE,KAAK,CAAC,cAAc,CAAC,CAAA;CACtC;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;IAC7B,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;IACnB,MAAM,EAAE,MAAM,CAAA;CACf"} \ No newline at end of file diff --git a/dist/PaymentMethod.d.ts b/dist/PaymentMethod.d.ts new file mode 100644 index 0000000..bb7c0af --- /dev/null +++ b/dist/PaymentMethod.d.ts @@ -0,0 +1,39 @@ +import Model from './Model'; +import type { IPaymentMethod } from './PaymentMethod/IPaymentMethod'; +import Api from './utils/Api'; +export default class PaymentMethod extends Model implements IPaymentMethod { + beneficiaryType: string; + blockchains: object; + brand: null; + chargeFeeSchedule: null; + chargeableCurrencies: Array; + countryCode: string; + createdAt: number; + defaultCurrency: string; + depositFeeSchedule: null; + depositableCurrencies: Array; + disabled: boolean; + documents: Array; + expirationDisplay: string; + id: string; + last4Digits: string; + linkType: string; + liquidationBalances: object; + maxCharge: null; + maxDeposit: null; + minCharge: null; + minDeposit: null; + name: string; + nameOnMethod: string | null; + nickname: string | null; + owner: string; + rejectionMessage: string | null; + srn: string; + status: string | null; + statusMessage: string; + supportsDeposit: boolean; + supportsPayment: boolean; + waitingPrompts: Array; + static fetchAll(api: Api): Promise>; +} +//# sourceMappingURL=PaymentMethod.d.ts.map \ No newline at end of file diff --git a/dist/PaymentMethod.d.ts.map b/dist/PaymentMethod.d.ts.map new file mode 100644 index 0000000..403dede --- /dev/null +++ b/dist/PaymentMethod.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"PaymentMethod.d.ts","sourceRoot":"","sources":["../src/PaymentMethod.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,SAAS,CAAA;AAC3B,OAAO,KAAK,EAAE,cAAc,EAA2B,MAAM,gCAAgC,CAAA;AAC7F,OAAO,GAAG,MAAM,aAAa,CAAA;AAE7B,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,KAAK,CAAC,aAAa,CAAE,YAAW,cAAc;IAChF,eAAe,EAAE,MAAM,CAAA;IACvB,WAAW,EAAE,MAAM,CAAA;IACnB,KAAK,EAAE,IAAI,CAAA;IACX,iBAAiB,EAAE,IAAI,CAAA;IACvB,oBAAoB,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;IACnC,WAAW,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;IACjB,eAAe,EAAE,MAAM,CAAA;IACvB,kBAAkB,EAAE,IAAI,CAAA;IACxB,qBAAqB,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;IACpC,QAAQ,EAAE,OAAO,CAAA;IACjB,SAAS,EAAE,KAAK,CAAC,GAAG,CAAC,CAAA;IACrB,iBAAiB,EAAE,MAAM,CAAA;IACzB,EAAE,EAAE,MAAM,CAAA;IACV,WAAW,EAAE,MAAM,CAAA;IACnB,QAAQ,EAAE,MAAM,CAAA;IAChB,mBAAmB,EAAE,MAAM,CAAA;IAC3B,SAAS,EAAE,IAAI,CAAA;IACf,UAAU,EAAE,IAAI,CAAA;IAChB,SAAS,EAAE,IAAI,CAAA;IACf,UAAU,EAAE,IAAI,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,YAAY,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,KAAK,EAAE,MAAM,CAAA;IACb,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAA;IAC/B,GAAG,EAAE,MAAM,CAAA;IACX,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;IACrB,aAAa,EAAE,MAAM,CAAA;IACrB,eAAe,EAAE,OAAO,CAAA;IACxB,eAAe,EAAE,OAAO,CAAA;IACxB,cAAc,EAAE,KAAK,CAAC,GAAG,CAAC,CAAA;WAEb,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;CAQtE"} \ No newline at end of file diff --git a/dist/PaymentMethod.js b/dist/PaymentMethod.js new file mode 100644 index 0000000..d791649 --- /dev/null +++ b/dist/PaymentMethod.js @@ -0,0 +1,77 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var Model_1 = require("./Model"); +var PaymentMethod = (function (_super) { + __extends(PaymentMethod, _super); + function PaymentMethod() { + return _super !== null && _super.apply(this, arguments) || this; + } + PaymentMethod.fetchAll = function (api) { + return __awaiter(this, void 0, void 0, function () { + var paymentMethods; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + api.requireAuthed(); + return [4, api.get('paymentMethods', null, { + version: '2' + })]; + case 1: + paymentMethods = (_a.sent()).data; + return [2, paymentMethods.map(function (paymentData) { return new PaymentMethod(paymentData, api); })]; + } + }); + }); + }; + return PaymentMethod; +}(Model_1.default)); +exports.default = PaymentMethod; diff --git a/dist/PaymentMethod/IPaymentMethod.d.ts b/dist/PaymentMethod/IPaymentMethod.d.ts new file mode 100644 index 0000000..b768974 --- /dev/null +++ b/dist/PaymentMethod/IPaymentMethod.d.ts @@ -0,0 +1,40 @@ +export interface IPaymentMethod { + id: string; + owner: string; + createdAt: number; + name: string; + defaultCurrency: string; + status: string | null; + statusMessage: string; + waitingPrompts: Array; + linkType: string; + beneficiaryType: string; + supportsDeposit: boolean; + nameOnMethod: string | null; + last4Digits: string; + brand: null; + expirationDisplay: string; + countryCode: string; + nickname: string | null; + rejectionMessage: string | null; + disabled: boolean; + supportsPayment: boolean; + chargeableCurrencies: Array; + depositableCurrencies: Array; + srn: string; + chargeFeeSchedule: null; + depositFeeSchedule: null; + minCharge: null; + maxCharge: null; + minDeposit: null; + maxDeposit: null; + documents: Array; + blockchains: object; + liquidationBalances: object; +} +export interface IPaymentMethodsResponse { + data: Array; + recordsTotal: number; + position: number; +} +//# sourceMappingURL=IPaymentMethod.d.ts.map \ No newline at end of file diff --git a/dist/PaymentMethod/IPaymentMethod.d.ts.map b/dist/PaymentMethod/IPaymentMethod.d.ts.map new file mode 100644 index 0000000..f004b09 --- /dev/null +++ b/dist/PaymentMethod/IPaymentMethod.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"IPaymentMethod.d.ts","sourceRoot":"","sources":["../../src/PaymentMethod/IPaymentMethod.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,MAAM,CAAA;IACb,SAAS,EAAE,MAAM,CAAA;I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.js new file mode 100644 index 0000000..c8ad2e5 --- /dev/null +++ b/dist/PaymentMethod/IPaymentMethod.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/src/Account.ts b/src/Account.ts index 3f2824a..6f504d5 100644 --- a/src/Account.ts +++ b/src/Account.ts @@ -1,5 +1,6 @@ import Model from './Model' import Transfer from './Transfer' +import PaymentMethod from './PaymentMethod' import Api from './utils/Api' import type { IAccount, IProfileField } from './Account/IAccount' import type { ICreateTransferParams, ITransferHistoryResponse } from './Transfer/ITransfer' @@ -14,12 +15,14 @@ export default class Account extends Model implements IAccount { public totalBalances: { BTC: number; ETH: number } public availableBalances: { BTC: number; ETH: number } public profileFields: Array + public paymentMethods: Array public static async fetch(id: string, api: Api): Promise { api.requireAuthed() const data = await api.get(`accounts/${id}`) const account = new Account(data, api) + account.paymentMethods = await PaymentMethod.fetchAll(api) return account } diff --git a/src/Account/IAccount.ts b/src/Account/IAccount.ts index 8457cfb..5bdfd26 100644 --- a/src/Account/IAccount.ts +++ b/src/Account/IAccount.ts @@ -1,3 +1,5 @@ +import type { IPaymentMethod } from '../PaymentMethod/IPaymentMethod' + export interface IAccount { id: string status: string @@ -17,6 +19,7 @@ export interface IAccount { ETH: number } profileFields: Array + paymentMethods: Array } export interface IProfileField { diff --git a/src/PaymentMethod.ts b/src/PaymentMethod.ts new file mode 100644 index 0000000..9ddaace --- /dev/null +++ b/src/PaymentMethod.ts @@ -0,0 +1,47 @@ +import Model from './Model' +import type { IPaymentMethod, IPaymentMethodsResponse } from './PaymentMethod/IPaymentMethod' +import Api from './utils/Api' + +export default class PaymentMethod extends Model implements IPaymentMethod { + public beneficiaryType: string + public blockchains: object + public brand: null + public chargeFeeSchedule: null + public chargeableCurrencies: Array + public countryCode: string + public createdAt: number + public defaultCurrency: string + public depositFeeSchedule: null + public depositableCurrencies: Array + public disabled: boolean + public documents: Array + public expirationDisplay: string + public id: string + public last4Digits: string + public linkType: string + public liquidationBalances: object + public maxCharge: null + public maxDeposit: null + public minCharge: null + public minDeposit: null + public name: string + public nameOnMethod: string | null + public nickname: string | null + public owner: string + public rejectionMessage: string | null + public srn: string + public status: string | null + public statusMessage: string + public supportsDeposit: boolean + public supportsPayment: boolean + public waitingPrompts: Array + + public static async fetchAll(api: Api): Promise> { + api.requireAuthed() + + const { data: paymentMethods } = await api.get('paymentMethods', null, { + version: '2' + }) + return paymentMethods.map((paymentData) => new PaymentMethod(paymentData, api)) + } +} \ No newline at end of file diff --git a/src/PaymentMethod/IPaymentMethod.ts b/src/PaymentMethod/IPaymentMethod.ts new file mode 100644 index 0000000..fdf30b4 --- /dev/null +++ b/src/PaymentMethod/IPaymentMethod.ts @@ -0,0 +1,44 @@ +export interface IPaymentMethod { + id: string + owner: string + createdAt: number + name: string + defaultCurrency: string + status: string | null + statusMessage: string + // TODO: unknown type + waitingPrompts: Array + linkType: string + beneficiaryType: string + supportsDeposit: boolean + nameOnMethod: string | null + last4Digits: string + // TODO: unknown type + brand: null + expirationDisplay: string + countryCode: string + nickname: string | null + rejectionMessage: string | null + disabled: boolean + supportsPayment: boolean + chargeableCurrencies: Array, + depositableCurrencies: Array, + srn: string + + // TODO: unknown types + chargeFeeSchedule: null + depositFeeSchedule: null + minCharge: null + maxCharge: null + minDeposit: null + maxDeposit: null + documents: Array + blockchains: object + liquidationBalances: object +} + +export interface IPaymentMethodsResponse { + data: Array + recordsTotal: number + position: number +} From 8d5da12f92f768e754435bbe9cf55a5769579203 Mon Sep 17 00:00:00 2001 From: Noah Passalacqua Date: Wed, 1 Apr 2020 09:54:09 -0500 Subject: [PATCH 04/20] Create Account. --- dist/Account.d.ts | 9 +++-- dist/Account.d.ts.map | 2 +- dist/Account.js | 61 ++++++++++++++++++++++++++++------ dist/Account/IAccount.d.ts | 35 +++++++++++++++---- dist/Account/IAccount.d.ts.map | 2 +- dist/utils/Api.d.ts | 1 + dist/utils/Api.d.ts.map | 2 +- dist/utils/Api.js | 7 ++++ dist/wyre.d.ts | 2 ++ dist/wyre.d.ts.map | 2 +- dist/wyre.js | 20 +++++------ src/Account.ts | 29 ++++++++++++---- src/Account/IAccount.ts | 38 +++++++++++++++++---- src/utils/Api.ts | 10 ++++++ src/wyre.ts | 19 ++++------- 15 files changed, 182 insertions(+), 57 deletions(-) diff --git a/dist/Account.d.ts b/dist/Account.d.ts index 1871329..ec85691 100644 --- a/dist/Account.d.ts +++ b/dist/Account.d.ts @@ -2,7 +2,7 @@ import Model from './Model'; import Transfer from './Transfer'; import PaymentMethod from './PaymentMethod'; import Api from './utils/Api'; -import type { IAccount, IProfileField } from './Account/IAccount'; +import type { IAccount, IAccountResponse, ICreateAccountParams, IProfileField } from './Account/IAccount'; import type { ICreateTransferParams } from './Transfer/ITransfer'; export default class Account extends Model implements IAccount { id: string; @@ -24,8 +24,11 @@ export default class Account extends Model implements IAccount { }; profileFields: Array; paymentMethods: Array; - static fetch(id: string, api: Api): Promise; + static create(api: Api, params: ICreateAccountParams): Promise; + static fetch(api: Api, id: string): Promise; + protected static postFetch(data: IAccountResponse, api: Api): Promise; + fetchPaymentMethods(): Promise>; createTransfer(params: ICreateTransferParams): Promise; - getTransfers(): Promise>; + fetchTransfers(): Promise>; } //# sourceMappingURL=Account.d.ts.map \ No newline at end of file diff --git a/dist/Account.d.ts.map b/dist/Account.d.ts.map index 48204a8..601eabe 100644 --- a/dist/Account.d.ts.map +++ b/dist/Account.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"Account.d.ts","sourceRoot":"","sources":["../src/Account.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,SAAS,CAAA;AAC3B,OAAO,QAAQ,MAAM,YAAY,CAAA;AACjC,OAAO,aAAa,MAAM,iBAAiB,CAAA;AAC3C,OAAO,GAAG,MAAM,aAAa,CAAA;AAC7B,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AACjE,OAAO,KAAK,EAAE,qBAAqB,EAA4B,MAAM,sBAA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;AAE3F,MAAM,CAAC,OAAO,OAAO,OAAQ,SAAQ,KAAK,CAAC,OAAO,CAAE,YAAW,QAAQ;IAC9D,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;IACjB,gBAAgB,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAA;IAC9C,aAAa,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAA;IAC3C,iBAAiB,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAA;IAC/C,aAAa,EAAE,KAAK,CAAC,aAAa,CAAC,CAAA;IACnC,cAAc,EAAE,KAAK,CAAC,aAAa,CAAC,CAAA;WAEvB,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,OAAO,CAAC;WAShE,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;qBAM1C,SAAS,CAAC,IAAI,EAAE,gBAAgB,EAAE,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC;IAMvE,mBAAmB,IAAI,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;IAMpD,cAAc,CAAC,MAAM,EAAE,qBAAqB,GAAG,OAAO,CAAC,QAAQ,CAAC;IAMhE,cAAc,IAAI,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;CAIxD"} \ No newline at end of file diff --git a/dist/Account.js b/dist/Account.js index 12cdc21..66ab52a 100644 --- a/dist/Account.js +++ b/dist/Account.js @@ -57,26 +57,67 @@ var Account = (function (_super) { function Account() { return _super !== null && _super.apply(this, arguments) || this; } - Account.fetch = function (id, api) { + Account.create = function (api, params) { return __awaiter(this, void 0, void 0, function () { - var data, account, _a; - return __generator(this, function (_b) { - switch (_b.label) { + var data; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + api.requireAuthed(); + return [4, api.post('accounts', params)]; + case 1: + data = _a.sent(); + if (params.subaccount) + api = api.masqueradeAs(data.id); + return [2, this.postFetch(data, api)]; + } + }); + }); + }; + Account.fetch = function (api, id) { + return __awaiter(this, void 0, void 0, function () { + var data; + return __generator(this, function (_a) { + switch (_a.label) { case 0: api.requireAuthed(); return [4, api.get("accounts/" + id)]; case 1: - data = _b.sent(); + data = _a.sent(); + return [2, this.postFetch(data, api)]; + } + }); + }); + }; + Account.postFetch = function (data, api) { + return __awaiter(this, void 0, void 0, function () { + var account; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: account = new Account(data, api); - _a = account; - return [4, PaymentMethod_1.default.fetchAll(api)]; - case 2: - _a.paymentMethods = _b.sent(); + return [4, account.fetchPaymentMethods()]; + case 1: + _a.sent(); return [2, account]; } }); }); }; + Account.prototype.fetchPaymentMethods = function () { + return __awaiter(this, void 0, void 0, function () { + var paymentMethods; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4, PaymentMethod_1.default.fetchAll(this.api)]; + case 1: + paymentMethods = _a.sent(); + this.paymentMethods = paymentMethods; + return [2, paymentMethods]; + } + }); + }); + }; Account.prototype.createTransfer = function (params) { return __awaiter(this, void 0, void 0, function () { var transfer; @@ -90,7 +131,7 @@ var Account = (function (_super) { }); }); }; - Account.prototype.getTransfers = function () { + Account.prototype.fetchTransfers = function () { return __awaiter(this, void 0, void 0, function () { var data; var _this = this; diff --git a/dist/Account/IAccount.d.ts b/dist/Account/IAccount.d.ts index b448069..2ff7887 100644 --- a/dist/Account/IAccount.d.ts +++ b/dist/Account/IAccount.d.ts @@ -1,5 +1,8 @@ import type { IPaymentMethod } from '../PaymentMethod/IPaymentMethod'; -export interface IAccount { +export interface IAccount extends IAccountResponse { + paymentMethods: Array; +} +export interface IAccountResponse { id: string; status: string; type: string; @@ -18,13 +21,33 @@ export interface IAccount { ETH: number; }; profileFields: Array; - paymentMethods: Array; } export interface IProfileField { - fieldId: string; - fieldType: string; - value: string | object | null; + fieldId: IProfileFieldId; + fieldType: IProfileFieldType; + value: string | object | IProfileFieldValueAddress | Array | null; note: string | null; - status: string; + status: IProfileFieldStatus; +} +declare type IProfileFieldId = 'individualCellphoneNumber' | 'individualEmail' | 'individualLegalName' | 'individualDateOfBirth' | 'individualSsn' | 'individualResidenceAddress' | 'individualGovernmentId' | 'individualSourceOfFunds'; +declare type IProfileFieldType = 'CELLPHONE' | 'EMAIL' | 'STRING' | 'DATE' | 'ADDRESS' | 'DOCUMENT' | 'PAYMENT_METHOD'; +declare type IProfileFieldValueAddress = { + street1: string; + street2?: string; + city: string; + state: string; + postalCode: string; + country: string | 'US'; +}; +declare type IProfileFieldValueDocument = {}; +declare type IProfileFieldStatus = 'OPEN' | 'PENDING' | 'NULL'; +export interface ICreateAccountParams { + type: string; + country: string; + profileFields: Array; + referrerAccountId?: string; + subaccount?: boolean; + disableEmail?: boolean; } +export {}; //# sourceMappingURL=IAccount.d.ts.map \ No newline at end of file diff --git a/dist/Account/IAccount.d.ts.map b/dist/Account/IAccount.d.ts.map index 8c77240..fb0c67e 100644 --- a/dist/Account/IAccount.d.ts.map +++ b/dist/Account/IAccount.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"IAccount.d.ts","sourceRoot":"","sources":["../../src/Account/IAccount.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAA;AAErE,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;IACjB,gBAAgB,EAAE;QAChB,GAAG,EAAE,MAAM,CAAA;QACX,GAAG,EAAE,MAAM,CAAA;KACZ,CAAA;IACD,aAAa,EAAE;QACb,GAAG,EAAE,MAAM,CAAA;QACX,GAAG,EAAE,MAAM,CAAA;KACZ,CAAA;IACD,iBAAiB,EAAE;QACjB,GAAG,EAAE,MAAM,CAAA;QACX,GAAG,EAAE,MAAM,CAAA;KACZ,CAAA;IACD,aAAa,EAAE,KAAK,CAAC,aAAa,CAAC,CAAA;IACnC,cAAc,EAAE,KAAK,CAAC,cAAc,CAAC,CAAA;CACtC;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;IAC7B,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;IACnB,MAAM,EAAE,MAAM,CAAA;CACf"} \ No newline at end of file +{"version":3,"file":"IAccount.d.ts","sourceRoot":"","sources":["../../src/Account/IAccount.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAA;AAErE,MAAM,WAAW,QAAS,SAAQ,gBAAgB;IAChD,cAAc,EAAE,KAAK,CAAC,cAAc,CAAC,CAAA;CACtC;AACD,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;IACjB,gBAAgB,EAAE;QAChB,GAAG,EAAE,MAAM,CAAA;QACX,GAAG,EAAE,MAAM,CAAA;KACZ,CAAA;IACD,aAAa,EAAE;QACb,GAAG,EAAE,MAAM,CAAA;QACX,GAAG,EAAE,MAAM,CAAA;KACZ,CAAA;IACD,iBAAiB,EAAE;QACjB,GAAG,EAAE,MAAM,CAAA;QACX,GAAG,EAAE,MAAM,CAAA;KACZ,CAAA;IACD,a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/dist/utils/Api.d.ts +++ b/dist/utils/Api.d.ts @@ -5,6 +5,7 @@ export default class Api { constructor(config?: IApiConfig); get isAuthed(): boolean; requireAuthed(): void; + masqueradeAs(id: string): Api; get(path: string, params?: object, options?: IApiOptions): Promise; post(path: string, body?: object, options?: IApiOptions): Promise; put(path: string, body?: object, options?: IApiOptions): Promise; diff --git a/dist/utils/Api.d.ts.map b/dist/utils/Api.d.ts.map index a2a2252..d74cc8e 100644 --- a/dist/utils/Api.d.ts.map +++ b/dist/utils/Api.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"Api.d.ts","sourceRoot":"","sources":["../../src/utils/Api.ts"],"names":[],"mappings":"AAIA,OAAO,UAAU,CAAA;AAEjB,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAE1D,MAAM,CAAC,OAAO,OAAO,GAAG;IACtB,SAAgB,MAAM,EAAE,UAAU,CAAA;gBAEtB,MAAM,CAAC,EAAE,UAAU;IAc/B,IAAW,QAAQ,IAAI,OAAO,CAE7B;IAEM,aAAa;IAKb,GAAG,CAAC,CAAC,SAAS,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC;IAIpF,IAAI,CAAC,CAAC,SAAS,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC;IAInF,GAAG,CAAC,CAAC,SAAS,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC;IAIlF,MAAM,CAAC,CAAC,SAAS,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC;IAI5F,OAAO,CAAC,OAAO;IAkBf,OAAO,CAAC,mBAAmB;IAiD3B,OAAO,CAAC,cAAc;CAuBvB"} \ No newline at end of file +{"version":3,"file":"Api.d.ts","sourceRoot":"","sources":["../../src/utils/Api.ts"],"names":[],"mappings":"AAIA,OAAO,UAAU,CAAA;AAEjB,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAE1D,MAAM,CAAC,OAAO,OAAO,GAAG;IACtB,SAAgB,MAAM,EAAE,UAAU,CAAA;gBAEtB,MAAM,CAAC,EAAE,UAAU;IAc/B,IAAW,QAAQ,IAAI,OAAO,CAE7B;IAEM,aAAa;IAKb,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,GAAG;IAU7B,GAAG,CAAC,CAAC,SAAS,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC;IAIpF,IAAI,CAAC,CAAC,SAAS,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC;IAInF,GAAG,CAAC,CAAC,SAAS,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC;IAIlF,MAAM,CAAC,CAAC,SAAS,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC;IAI5F,OAAO,CAAC,OAAO;IAkBf,OAAO,CAAC,mBAAmB;IAiD3B,OAAO,CAAC,cAAc;CAuBvB"} \ No newline at end of file diff --git a/dist/utils/Api.js b/dist/utils/Api.js index 6cad3d0..ed74af3 100644 --- a/dist/utils/Api.js +++ b/dist/utils/Api.js @@ -40,6 +40,13 @@ var Api = (function () { if (!this.isAuthed) throw new Error('Must be authenticated for this endpoint.'); }; + Api.prototype.masqueradeAs = function (id) { + if (!this.isAuthed) + throw new Error('Cannot masquerade with no authorization.'); + var newConfig = Object.assign({}, this.config); + newConfig.auth.masqueradeTarget = id; + return new Api(newConfig); + }; Api.prototype.get = function (path, params, options) { return this.request('GET', path, params, options); }; diff --git a/dist/wyre.d.ts b/dist/wyre.d.ts index d7669f4..3d0decc 100644 --- a/dist/wyre.d.ts +++ b/dist/wyre.d.ts @@ -1,8 +1,10 @@ import Account from './Account'; import type { IApiConfig } from './utils/API/IApiConfig'; +import type { ICreateAccountParams } from './Account/IAccount'; export default class WyreClient { private readonly api; constructor(config: IApiConfig); + createAccount(params: ICreateAccountParams): Promise; fetchAccount(id: string, masquerade?: boolean): Promise; } //# sourceMappingURL=wyre.d.ts.map \ No newline at end of file diff --git a/dist/wyre.d.ts.map b/dist/wyre.d.ts.map index 1f53b14..d458290 100644 --- a/dist/wyre.d.ts.map +++ b/dist/wyre.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"wyre.d.ts","sourceRoot":"","sources":["../src/wyre.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,WAAW,CAAA;AAE/B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAExD,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAK;gBAEb,MAAM,EAAE,UAAU;IAIjB,YAAY,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,UAAQ,GAAG,OAAO,CAAC,OAAO,CAAC;CAc5E"} \ No newline at end of file +{"version":3,"file":"wyre.d.ts","sourceRoot":"","sources":["../src/wyre.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,WAAW,CAAA;AAE/B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAA;AAE9D,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAK;gBAEb,MAAM,EAAE,UAAU;IAIjB,aAAa,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,OAAO,CAAC;IAI7D,YAAY,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,UAAQ,GAAG,OAAO,CAAC,OAAO,CAAC;CAI5E"} \ No newline at end of file diff --git a/dist/wyre.js b/dist/wyre.js index b314a81..cf4a697 100644 --- a/dist/wyre.js +++ b/dist/wyre.js @@ -42,20 +42,20 @@ var WyreClient = (function () { function WyreClient(config) { this.api = new Api_1.default(config); } + WyreClient.prototype.createAccount = function (params) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + return [2, Account_1.default.create(this.api, params)]; + }); + }); + }; WyreClient.prototype.fetchAccount = function (id, masquerade) { if (masquerade === void 0) { masquerade = false; } return __awaiter(this, void 0, void 0, function () { - var api, newConfig; + var api; return __generator(this, function (_a) { - api = this.api; - if (masquerade) { - if (!this.api.isAuthed) - throw new Error('Cannot masquerade with no authorization.'); - newConfig = Object.assign({}, this.api.config); - newConfig.auth.masqueradeTarget = id; - api = new Api_1.default(newConfig); - } - return [2, Account_1.default.fetch(id, api)]; + api = masquerade ? this.api.masqueradeAs(id) : this.api; + return [2, Account_1.default.fetch(api, id)]; }); }); }; diff --git a/src/Account.ts b/src/Account.ts index 6f504d5..1308bba 100644 --- a/src/Account.ts +++ b/src/Account.ts @@ -2,7 +2,7 @@ import Model from './Model' import Transfer from './Transfer' import PaymentMethod from './PaymentMethod' import Api from './utils/Api' -import type { IAccount, IProfileField } from './Account/IAccount' +import type { IAccount, IAccountResponse, ICreateAccountParams, IProfileField } from './Account/IAccount' import type { ICreateTransferParams, ITransferHistoryResponse } from './Transfer/ITransfer' export default class Account extends Model implements IAccount { @@ -17,23 +17,40 @@ export default class Account extends Model implements IAccount { public profileFields: Array public paymentMethods: Array - public static async fetch(id: string, api: Api): Promise { + public static async create(api: Api, params: ICreateAccountParams): Promise { api.requireAuthed() - const data = await api.get(`accounts/${id}`) - const account = new Account(data, api) - account.paymentMethods = await PaymentMethod.fetchAll(api) + const data = await api.post('accounts', params) + if (params.subaccount) + api = api.masqueradeAs(data.id) + return this.postFetch(data, api) + } + + public static async fetch(api: Api, id: string): Promise { + api.requireAuthed() + const data = await api.get(`accounts/${id}`) + return this.postFetch(data, api) + } + protected static async postFetch(data: IAccountResponse, api: Api): Promise { + const account = new Account(data, api) + await account.fetchPaymentMethods() return account } + public async fetchPaymentMethods(): Promise> { + const paymentMethods = await PaymentMethod.fetchAll(this.api) + this.paymentMethods = paymentMethods + return paymentMethods + } + public async createTransfer(params: ICreateTransferParams): Promise { const transfer = await Transfer.create(params, this.api) return transfer } - public async getTransfers(): Promise> { + public async fetchTransfers(): Promise> { const { data } = await this.api.get('transfers') return data.map((transferData) => new Transfer(transferData, this.api)) } diff --git a/src/Account/IAccount.ts b/src/Account/IAccount.ts index 5bdfd26..8c7dfbe 100644 --- a/src/Account/IAccount.ts +++ b/src/Account/IAccount.ts @@ -1,6 +1,9 @@ import type { IPaymentMethod } from '../PaymentMethod/IPaymentMethod' -export interface IAccount { +export interface IAccount extends IAccountResponse { + paymentMethods: Array +} +export interface IAccountResponse { id: string status: string type: string @@ -19,13 +22,36 @@ export interface IAccount { ETH: number } profileFields: Array - paymentMethods: Array } export interface IProfileField { - fieldId: string - fieldType: string - value: string | object | null + fieldId: IProfileFieldId + fieldType: IProfileFieldType + value: string | object | IProfileFieldValueAddress | Array | null note: string | null - status: string + status: IProfileFieldStatus +} +type IProfileFieldId = 'individualCellphoneNumber' | 'individualEmail' | 'individualLegalName' | 'individualDateOfBirth' | 'individualSsn' | 'individualResidenceAddress' | 'individualGovernmentId' | 'individualSourceOfFunds' +type IProfileFieldType = 'CELLPHONE' | 'EMAIL' | 'STRING' | 'DATE' | 'ADDRESS' | 'DOCUMENT' | 'PAYMENT_METHOD' +type IProfileFieldValueAddress = { + street1: string + street2?: string + city: string + state: string + postalCode: string + country: string | 'US' +} +// TODO: unknown values +type IProfileFieldValueDocument = { + +} +type IProfileFieldStatus = 'OPEN' | 'PENDING' | 'NULL' + +export interface ICreateAccountParams { + type: string + country: string + profileFields: Array + referrerAccountId?: string + subaccount?: boolean + disableEmail?: boolean } diff --git a/src/utils/Api.ts b/src/utils/Api.ts index 1877b6c..0960309 100644 --- a/src/utils/Api.ts +++ b/src/utils/Api.ts @@ -32,6 +32,16 @@ export default class Api { throw new Error('Must be authenticated for this endpoint.') } + public masqueradeAs(id: string): Api { + if (!this.isAuthed) + throw new Error('Cannot masquerade with no authorization.') + + const newConfig = Object.assign({}, this.config) + newConfig.auth.masqueradeTarget = id + + return new Api(newConfig) + } + public get(path: string, params?: object, options?: IApiOptions): Promise { return this.request('GET', path, params, options) } diff --git a/src/wyre.ts b/src/wyre.ts index 4538df0..1142a9d 100644 --- a/src/wyre.ts +++ b/src/wyre.ts @@ -1,6 +1,7 @@ import Account from './Account' import Api from './utils/Api' import type { IApiConfig } from './utils/API/IApiConfig' +import type { ICreateAccountParams } from './Account/IAccount' export default class WyreClient { private readonly api: Api @@ -9,18 +10,12 @@ export default class WyreClient { this.api = new Api(config) } - public async fetchAccount(id: string, masquerade = false): Promise { - let api = this.api - if (masquerade) { - if (!this.api.isAuthed) - throw new Error('Cannot masquerade with no authorization.') - - const newConfig = Object.assign({}, this.api.config) - newConfig.auth.masqueradeTarget = id - - api = new Api(newConfig) - } + public async createAccount(params: ICreateAccountParams): Promise { + return Account.create(this.api, params) + } - return Account.fetch(id, api) + public async fetchAccount(id: string, masquerade = false): Promise { + const api = masquerade ? this.api.masqueradeAs(id) : this.api + return Account.fetch(api, id) } } From bf27d05c9c7fa715bf4310bc8f4ea771ab1868c7 Mon Sep 17 00:00:00 2001 From: Noah Passalacqua Date: Wed, 1 Apr 2020 10:27:05 -0500 Subject: [PATCH 05/20] Update Account. --- dist/Account.d.ts | 3 ++- dist/Account.d.ts.map | 2 +- dist/Account.js | 15 +++++++++++++++ dist/Account/IAccount.d.ts | 4 ++-- dist/Account/IAccount.d.ts.map | 2 +- dist/Model.d.ts | 3 ++- dist/Model.d.ts.map | 2 +- dist/Model.js | 14 +++----------- dist/Model/Data.d.ts | 9 +++++++++ dist/Model/Data.d.ts.map | 1 + dist/Model/Data.js | 33 +++++++++++++++++++++++++++++++++ src/Account.ts | 8 +++++++- src/Account/IAccount.ts | 4 ++-- src/Model.ts | 13 ++++--------- src/Model/Data.ts | 29 +++++++++++++++++++++++++++++ 15 files changed, 112 insertions(+), 30 deletions(-) create mode 100644 dist/Model/Data.d.ts create mode 100644 dist/Model/Data.d.ts.map create mode 100644 dist/Model/Data.js create mode 100644 src/Model/Data.ts diff --git a/dist/Account.d.ts b/dist/Account.d.ts index ec85691..0aeb215 100644 --- a/dist/Account.d.ts +++ b/dist/Account.d.ts @@ -6,7 +6,7 @@ import type { IAccount, IAccountResponse, ICreateAccountParams, IProfileField } import type { ICreateTransferParams } from './Transfer/ITransfer'; export default class Account extends Model implements IAccount { id: string; - status: string; + status: 'OPEN' | 'PENDING' | 'APPROVED'; type: string; country: string; createdAt: number; @@ -27,6 +27,7 @@ export default class Account extends Model implements IAccount { static create(api: Api, params: ICreateAccountParams): Promise; static fetch(api: Api, id: string): Promise; protected static postFetch(data: IAccountResponse, api: Api): Promise; + save(): Promise; fetchPaymentMethods(): Promise>; createTransfer(params: ICreateTransferParams): Promise; fetchTransfers(): Promise>; diff --git a/dist/Account.d.ts.map b/dist/Account.d.ts.map index 601eabe..758c0de 100644 --- a/dist/Account.d.ts.map +++ b/dist/Account.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"Account.d.ts","sourceRoot":"","sources":["../src/Account.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,SAAS,CAAA;AAC3B,OAAO,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AShE,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;qBAM1C,SAAS,CAAC,IAAI,EAAE,gBAAgB,EAAE,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC;IAMvE,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAMrB,mBAAmB,IAAI,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;IAMpD,cAAc,CAAC,MAAM,EAAE,qBAAqB,GAAG,OAAO,CAAC,QAAQ,CAAC;IAMhE,cAAc,IAAI,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;CAIxD"} \ No newline at end of file diff --git a/dist/Account.js b/dist/Account.js index 66ab52a..e67ea96 100644 --- a/dist/Account.js +++ b/dist/Account.js @@ -104,6 +104,21 @@ var Account = (function (_super) { }); }); }; + Account.prototype.save = function () { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!this.data.isChanged) + return [2]; + return [4, this.api.post("accounts/" + this.id, this.data.updatedValues)]; + case 1: + _a.sent(); + return [2]; + } + }); + }); + }; Account.prototype.fetchPaymentMethods = function () { return __awaiter(this, void 0, void 0, function () { var paymentMethods; diff --git a/dist/Account/IAccount.d.ts b/dist/Account/IAccount.d.ts index 2ff7887..f217f58 100644 --- a/dist/Account/IAccount.d.ts +++ b/dist/Account/IAccount.d.ts @@ -4,7 +4,7 @@ export interface IAccount extends IAccountResponse { } export interface IAccountResponse { id: string; - status: string; + status: 'OPEN' | 'PENDING' | 'APPROVED'; type: string; country: string; createdAt: number; @@ -40,7 +40,7 @@ declare type IProfileFieldValueAddress = { country: string | 'US'; }; declare type IProfileFieldValueDocument = {}; -declare type IProfileFieldStatus = 'OPEN' | 'PENDING' | 'NULL'; +declare type IProfileFieldStatus = 'OPEN' | 'PENDING' | 'APPROVED' | 'NULL'; export interface ICreateAccountParams { type: string; country: string; diff --git a/dist/Account/IAccount.d.ts.map b/dist/Account/IAccount.d.ts.map index fb0c67e..b59d8ec 100644 --- a/dist/Account/IAccount.d.ts.map +++ b/dist/Account/IAccount.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"IAccount.d.ts","sourceRoot":"","sources":["../../src/Account/IAccount.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAA;AAErE,MAAM,WAAW,QAAS,SAAQ,gBAAgB;IAChD,cAAc,EAAE,KAAK,CAAC,cAAc,CAAC,CAAA;CACtC;AACD,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;IACjB,gBAAgB,EAAE;QAChB,GAAG,EAAE,MAAM,CAAA;QACX,GAAG,EAAE,MAAM,CAAA;KACZ,CAAA;IACD,aAAa,EAAE;QACb,GAAG,EAAE,MAAM,CAAA;QACX,GAAG,EAAE,MAAM,CAAA;KACZ,CAAA;IACD,iBAAiB,EAAE;QACjB,GAAG,EAAE,MAAM,CAAA;QACX,GAAG,EAAE,MAAM,CAAA;KACZ,CAAA;IACD,aAAa,EAAE,KAAK,CAAC,aAAa,CAAC,CAAA;CACpC;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,eAAe,CAAA;IACxB,SAAS,EAAE,iBAAiB,CAAA;IAC5B,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,yBAAyB,GAAG,KAAK,CAAC,0BAA0B,CAAC,GAAG,IAAI,CAAA;IAC7F,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;IACnB,MAAM,EAAE,mBAAmB,CAAA;CAC5B;AACD,aAAK,eAAe,GAAG,2BAA2B,GAAG,iBAAiB,GAAG,qBAAqB,GAAG,uBAAuB,GAAG,eAAe,GAAG,4BAA4B,GAAG,wBAA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,CAAC,aAAa,CAAC,CAAA;IACnC,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB"} \ No newline at end of file diff --git a/dist/Model.d.ts b/dist/Model.d.ts index 6793d93..9ff7dda 100644 --- a/dist/Model.d.ts +++ b/dist/Model.d.ts @@ -1,7 +1,8 @@ import Api from './utils/Api'; +import Data from './Model/Data'; export default abstract class Model { readonly api: Api; - data: object; + readonly data: Data; constructor(data: object, api: Api); set(data: object): void; set(key: PropertyKey, value: any): void; diff --git a/dist/Model.d.ts.map b/dist/Model.d.ts.map index ca7cfa6..824c7f1 100644 --- a/dist/Model.d.ts.map +++ b/dist/Model.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"Model.d.ts","sourceRoot":"","sources":["../src/Model.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,aAAa,CAAA;AAE7B,MAAM,CAAC,OAAO,CAAC,QAAQ,OAAO,KAAK,CAAC,CAAC;IACnC,SAAgB,GAAG,EAAE,GAAG,CAAA;IACjB,IAAI,EAAE,MAAM,CAAK;gBAEZ,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG;IAS3B,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IACvB,GAAG,CAAC,GAAG,EAAE,WAAW,EAAE,KAAK,EAAE,GAAG,GAAG,IAAI;CAU/C"} \ No newline at end of file +{"version":3,"file":"Model.d.ts","sourceRoot":"","sources":["../src/Model.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,aAAa,CAAA;AAC7B,OAAO,IAAI,MAAM,cAAc,CAAA;AAE/B,MAAM,CAAC,OAAO,CAAC,QAAQ,OAAO,KAAK,CAAC,CAAC;IACnC,SAAgB,GAAG,EAAE,GAAG,CAAA;IACxB,SAAgB,IAAI,EAAE,IAAI,CAAA;gBAEd,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG;IAS3B,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IACvB,GAAG,CAAC,GAAG,EAAE,WAAW,EAAE,KAAK,EAAE,GAAG,GAAG,IAAI;CAI/C"} \ No newline at end of file diff --git a/dist/Model.js b/dist/Model.js index 09af104..3dc8f5e 100644 --- a/dist/Model.js +++ b/dist/Model.js @@ -1,23 +1,15 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); +var Data_1 = require("./Model/Data"); var Model = (function () { function Model(data, api) { - this.data = {}; - this.set(data); this.api = api; + this.data = new Data_1.default(data); var proxy = new Proxy(this, new ModelProxyHandler()); return proxy; } Model.prototype.set = function (key, value) { - if (typeof key === 'object') { - for (var _i = 0, _a = Object.entries(key); _i < _a.length; _i++) { - var _b = _a[_i], k = _b[0], v = _b[1]; - this.data[k] = v; - } - } - else { - this.data[key] = value; - } + this.data.set(key, value); }; return Model; }()); diff --git a/dist/Model/Data.d.ts b/dist/Model/Data.d.ts new file mode 100644 index 0000000..f17e8fc --- /dev/null +++ b/dist/Model/Data.d.ts @@ -0,0 +1,9 @@ +export default class Data { + readonly initValues: object; + readonly updatedValues: object; + constructor(data: object); + get isChanged(): boolean; + set(key: PropertyKey | object, value?: any): void; + get(key: string): T; +} +//# sourceMappingURL=Data.d.ts.map \ No newline at end of file diff --git a/dist/Model/Data.d.ts.map b/dist/Model/Data.d.ts.map new file mode 100644 index 0000000..f6af390 --- /dev/null +++ b/dist/Model/Data.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"Data.d.ts","sourceRoot":"","sources":["../../src/Model/Data.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,OAAO,IAAI;IACvB,SAAgB,UAAU,EAAE,MAAM,CAAA;IAClC,SAAgB,aAAa,EAAE,MAAM,CAAA;gBAEzB,IAAI,EAAE,MAAM;IAKxB,IAAW,SAAS,IAAI,OAAO,CAI9B;IAEM,GAAG,CAAC,GAAG,EAAE,WAAW,GAAG,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG,GAAG,IAAI;IAUjD,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC;CAG9B"} \ No newline at end of file diff --git a/dist/Model/Data.js b/dist/Model/Data.js new file mode 100644 index 0000000..b07a26c --- /dev/null +++ b/dist/Model/Data.js @@ -0,0 +1,33 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var Data = (function () { + function Data(data) { + this.initValues = data; + this.updatedValues = data; + } + Object.defineProperty(Data.prototype, "isChanged", { + get: function () { + var initValues = JSON.stringify(this.initValues); + var updatedValues = JSON.stringify(this.updatedValues); + return initValues !== updatedValues; + }, + enumerable: true, + configurable: true + }); + Data.prototype.set = function (key, value) { + if (typeof key === 'object') { + for (var _i = 0, _a = Object.entries(key); _i < _a.length; _i++) { + var _b = _a[_i], k = _b[0], v = _b[1]; + this.updatedValues[k] = v; + } + } + else { + this.updatedValues[key] = value; + } + }; + Data.prototype.get = function (key) { + return this.updatedValues[key]; + }; + return Data; +}()); +exports.default = Data; diff --git a/src/Account.ts b/src/Account.ts index 1308bba..ca50cba 100644 --- a/src/Account.ts +++ b/src/Account.ts @@ -7,7 +7,7 @@ import type { ICreateTransferParams, ITransferHistoryResponse } from './Transfer export default class Account extends Model implements IAccount { public id: string - public status: string + public status: 'OPEN' | 'PENDING' | 'APPROVED' public type: string public country: string public createdAt: number @@ -38,6 +38,12 @@ export default class Account extends Model implements IAccount { return account } + public async save(): Promise { + if (!this.data.isChanged) return + + await this.api.post(`accounts/${this.id}`, this.data.updatedValues) + } + public async fetchPaymentMethods(): Promise> { const paymentMethods = await PaymentMethod.fetchAll(this.api) this.paymentMethods = paymentMethods diff --git a/src/Account/IAccount.ts b/src/Account/IAccount.ts index 8c7dfbe..6a5b436 100644 --- a/src/Account/IAccount.ts +++ b/src/Account/IAccount.ts @@ -5,7 +5,7 @@ export interface IAccount extends IAccountResponse { } export interface IAccountResponse { id: string - status: string + status: 'OPEN' | 'PENDING' | 'APPROVED' type: string country: string createdAt: number @@ -45,7 +45,7 @@ type IProfileFieldValueAddress = { type IProfileFieldValueDocument = { } -type IProfileFieldStatus = 'OPEN' | 'PENDING' | 'NULL' +type IProfileFieldStatus = 'OPEN' | 'PENDING' | 'APPROVED' | 'NULL' export interface ICreateAccountParams { type: string diff --git a/src/Model.ts b/src/Model.ts index 33e2eeb..4c81abb 100644 --- a/src/Model.ts +++ b/src/Model.ts @@ -1,12 +1,13 @@ import Api from './utils/Api' +import Data from './Model/Data' export default abstract class Model { public readonly api: Api - public data: object = {} + public readonly data: Data constructor(data: object, api: Api) { - this.set(data) this.api = api + this.data = new Data(data) const proxy = new Proxy(this, new ModelProxyHandler()) @@ -16,13 +17,7 @@ export default abstract class Model { public set(data: object): void public set(key: PropertyKey, value: any): void public set(key: PropertyKey | object, value?: any): void { - if (typeof key === 'object') { - for (const [ k, v ] of Object.entries(key)) { - this.data[k] = v - } - } else { - this.data[key] = value - } + this.data.set(key, value) } } diff --git a/src/Model/Data.ts b/src/Model/Data.ts new file mode 100644 index 0000000..474f486 --- /dev/null +++ b/src/Model/Data.ts @@ -0,0 +1,29 @@ +export default class Data { + public readonly initValues: object + public readonly updatedValues: object + + constructor(data: object) { + this.initValues = data + this.updatedValues = data + } + + public get isChanged(): boolean { + const initValues = JSON.stringify(this.initValues) + const updatedValues = JSON.stringify(this.updatedValues) + return initValues !== updatedValues + } + + public set(key: PropertyKey | object, value?: any): void { + if (typeof key === 'object') { + for (const [ k, v ] of Object.entries(key)) { + this.updatedValues[k] = v + } + } else { + this.updatedValues[key] = value + } + } + + public get(key: string): T { + return this.updatedValues[key] + } +} \ No newline at end of file From 6bab4014f7f6206b4ef8f1b6cdd050c48ef3c5ab Mon Sep 17 00:00:00 2001 From: Noah Passalacqua Date: Wed, 8 Apr 2020 11:46:00 -0500 Subject: [PATCH 06/20] Update Models. --- dist/Account.d.ts | 7 +- dist/Account.d.ts.map | 2 +- dist/Account.js | 35 +++--- dist/Account/IAccountData.d.ts | 30 ----- dist/Account/IAccountData.d.ts.map | 1 - dist/Account/IAccountData.js | 2 - dist/Authed.d.ts | 24 ---- dist/Authed.d.ts.map | 1 - dist/Authed.js | 22 ---- dist/Model.d.ts | 5 +- dist/Model.d.ts.map | 2 +- dist/Model.js | 9 +- dist/Model/Data.d.ts | 2 +- dist/Model/Data.d.ts.map | 2 +- dist/PaymentMethod.d.ts | 6 +- dist/PaymentMethod.d.ts.map | 2 +- dist/PaymentMethod/IPaymentMethod.d.ts | 4 +- dist/Transfer.d.ts | 2 +- dist/Transfer.d.ts.map | 2 +- dist/Transfer/ICreateTransferParams.d.ts | 16 --- dist/Transfer/ICreateTransferParams.d.ts.map | 1 - dist/Transfer/ICreateTransferParams.js | 2 - dist/Transfer/ITransferData.d.ts | 46 -------- dist/Transfer/ITransferData.d.ts.map | 1 - dist/Transfer/ITransferData.js | 2 - dist/utils/API.d.ts | 14 --- dist/utils/API.d.ts.map | 1 - dist/utils/API.js | 111 ------------------- dist/utils/API/IApiConfig.d.ts | 2 +- dist/utils/API/IApiConfig.d.ts.map | 2 +- dist/utils/API/IApiOptions.d.ts | 6 - dist/utils/API/IApiOptions.d.ts.map | 1 - dist/utils/API/IApiOptions.js | 2 - dist/utils/API/IOptions.d.ts | 6 - dist/utils/API/IOptions.d.ts.map | 1 - dist/utils/API/IOptions.js | 2 - dist/utils/Auth/IAuthed.d.ts | 1 - dist/utils/Auth/IAuthed.d.ts.map | 1 - dist/utils/Auth/IAuthed.js | 0 dist/utils/Authed.d.ts | 6 - dist/utils/Authed.d.ts.map | 1 - dist/utils/Authed.js | 9 -- dist/utils/Request.d.ts | 13 --- dist/utils/Request.js | 98 ---------------- src/Account.ts | 17 +-- src/Model.ts | 16 ++- src/Model/Data.ts | 2 +- src/PaymentMethod.ts | 6 +- src/PaymentMethod/IPaymentMethod.ts | 4 +- src/Transfer.ts | 2 +- src/utils/API/IApiConfig.ts | 2 +- 51 files changed, 64 insertions(+), 490 deletions(-) delete mode 100644 dist/Account/IAccountData.d.ts delete mode 100644 dist/Account/IAccountData.d.ts.map delete mode 100644 dist/Account/IAccountData.js delete mode 100644 dist/Authed.d.ts delete mode 100644 dist/Authed.d.ts.map delete mode 100644 dist/Authed.js delete mode 100644 dist/Transfer/ICreateTransferParams.d.ts delete mode 100644 dist/Transfer/ICreateTransferParams.d.ts.map delete mode 100644 dist/Transfer/ICreateTransferParams.js delete mode 100644 dist/Transfer/ITransferData.d.ts delete mode 100644 dist/Transfer/ITransferData.d.ts.map delete mode 100644 dist/Transfer/ITransferData.js delete mode 100644 dist/utils/API.d.ts delete mode 100644 dist/utils/API.d.ts.map delete mode 100644 dist/utils/API.js delete mode 100644 dist/utils/API/IApiOptions.d.ts delete mode 100644 dist/utils/API/IApiOptions.d.ts.map delete mode 100644 dist/utils/API/IApiOptions.js delete mode 100644 dist/utils/API/IOptions.d.ts delete mode 100644 dist/utils/API/IOptions.d.ts.map delete mode 100644 dist/utils/API/IOptions.js delete mode 100644 dist/utils/Auth/IAuthed.d.ts delete mode 100644 dist/utils/Auth/IAuthed.d.ts.map delete mode 100644 dist/utils/Auth/IAuthed.js delete mode 100644 dist/utils/Authed.d.ts delete mode 100644 dist/utils/Authed.d.ts.map delete mode 100644 dist/utils/Authed.js delete mode 100644 dist/utils/Request.d.ts delete mode 100644 dist/utils/Request.js diff --git a/dist/Account.d.ts b/dist/Account.d.ts index 0aeb215..bccab07 100644 --- a/dist/Account.d.ts +++ b/dist/Account.d.ts @@ -2,9 +2,9 @@ import Model from './Model'; import Transfer from './Transfer'; import PaymentMethod from './PaymentMethod'; import Api from './utils/Api'; -import type { IAccount, IAccountResponse, ICreateAccountParams, IProfileField } from './Account/IAccount'; -import type { ICreateTransferParams } from './Transfer/ITransfer'; -export default class Account extends Model implements IAccount { +import { IAccount, IAccountResponse, ICreateAccountParams, IProfileField } from './Account/IAccount'; +import { ICreateTransferParams } from './Transfer/ITransfer'; +export default class Account extends Model implements IAccount { id: string; status: 'OPEN' | 'PENDING' | 'APPROVED'; type: string; @@ -28,7 +28,6 @@ export default class Account extends Model implements IAccount { static fetch(api: Api, id: string): Promise; protected static postFetch(data: IAccountResponse, api: Api): Promise; save(): Promise; - fetchPaymentMethods(): Promise>; createTransfer(params: ICreateTransferParams): Promise; fetchTransfers(): Promise>; } diff --git a/dist/Account.d.ts.map b/dist/Account.d.ts.map index 758c0de..16a2b10 100644 --- a/dist/Account.d.ts.map +++ b/dist/Account.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"Account.d.ts","sourceRoot":"","sources":["../src/Account.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,SAAS,CAAA;AAC3B,OAAO,QAAQ,MAAM,YAAY,CAAA;AACjC,OAAO,aAAa,MAAM,iBAAiB,CAAA;AAC3C,OAAO,GAAG,MAAM,aAAa,CAAA;AAC7B,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AACzG,OAAO,KAAK,EAAE,qBAAqB,EAA4B,MAAM,sBAAsB,CAAA;AAE3F,MAAM,CAAC,OAAO,OAAO,OAAQ,SAAQ,KAAK,CAAC,OAAO,CAAE,YAAW,QAAQ;IAC9D,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,UAAU,CAAA;IACvC,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;IACjB,gBAAgB,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAA;IAC9C,aAAa,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAA;IAC3C,iBAAiB,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAA;IAC/C,aAAa,EAAE,KAAK,CAAC,aA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;IACjB,gBAAgB,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAA;IAC9C,aAAa,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAA;IAC3C,iBAAiB,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAA;IAC/C,aAAa,EAAE,KAAK,CAAC,aAAa,CAAC,CAAA;IACnC,cAAc,EAAE,KAAK,CAAC,aAAa,CAAC,CAAA;WAEvB,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,OAAO,CAAC;WAShE,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;qBAM1C,SAAS,CAAC,IAAI,EAAE,gBAAgB,EAAE,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC;IAKvE,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAMrB,cAAc,CAAC,MAAM,EAAE,qBAAqB,GAAG,OAAO,CAAC,QAAQ,CAAC;IAMhE,cAAc,IAAI,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;CAIxD"} \ No newline at end of file diff --git a/dist/Account.js b/dist/Account.js index e67ea96..3b0bbb7 100644 --- a/dist/Account.js +++ b/dist/Account.js @@ -12,6 +12,17 @@ var __extends = (this && this.__extends) || (function () { d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { @@ -91,15 +102,13 @@ var Account = (function (_super) { }; Account.postFetch = function (data, api) { return __awaiter(this, void 0, void 0, function () { - var account; + var paymentMethods; return __generator(this, function (_a) { switch (_a.label) { - case 0: - account = new Account(data, api); - return [4, account.fetchPaymentMethods()]; + case 0: return [4, PaymentMethod_1.default.fetchAll(api)]; case 1: - _a.sent(); - return [2, account]; + paymentMethods = _a.sent(); + return [2, new Account(__assign(__assign({}, data), { paymentMethods: paymentMethods }), api)]; } }); }); @@ -119,20 +128,6 @@ var Account = (function (_super) { }); }); }; - Account.prototype.fetchPaymentMethods = function () { - return __awaiter(this, void 0, void 0, function () { - var paymentMethods; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4, PaymentMethod_1.default.fetchAll(this.api)]; - case 1: - paymentMethods = _a.sent(); - this.paymentMethods = paymentMethods; - return [2, paymentMethods]; - } - }); - }); - }; Account.prototype.createTransfer = function (params) { return __awaiter(this, void 0, void 0, function () { var transfer; diff --git a/dist/Account/IAccountData.d.ts b/dist/Account/IAccountData.d.ts deleted file mode 100644 index f56303e..0000000 --- a/dist/Account/IAccountData.d.ts +++ /dev/null @@ -1,30 +0,0 @@ -import type { IPaymentMethod } from '../PaymentMethod/IPaymentMethod'; -export interface IAccountData { - id: string; - status: string; - type: string; - country: string; - createdAt: number; - depositAddresses: { - ETH: string; - BTC: string; - }; - totalBalances: { - BTC: number; - ETH: number; - }; - availableBalances: { - BTC: number; - ETH: number; - }; - paymentMethods: Array; - profileFields: Array; -} -export interface IProfileField { - fieldId: string; - fieldType: string; - value: string | object | null; - note: string | null; - status: string; -} -//# sourceMappingURL=IAccountData.d.ts.map \ No newline at end of file diff --git a/dist/Account/IAccountData.d.ts.map b/dist/Account/IAccountData.d.ts.map deleted file mode 100644 index b3b96aa..0000000 --- a/dist/Account/IAccountData.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"IAccountData.d.ts","sourceRoot":"","sources":["../../src/Account/IAccountData.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAA;AAErE,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;IACjB,gBAAgB,EAAE;QAChB,GAAG,EAAE,MAAM,CAAA;QACX,GAAG,EAAE,MAAM,CAAA;KACZ,CAAA;IACD,aAAa,EAAE;QACb,GAAG,EAAE,MAAM,CAAA;QACX,GAAG,EAAE,MAAM,CAAA;KACZ,CAAA;IACD,iBAAiB,EAAE;QACjB,GAAG,EAAE,MAAM,CAAA;QACX,GAAG,EAAE,MAAM,CAAA;KACZ,CAAA;IACD,cAAc,EAAE,KAAK,CAAC,cAAc,CAAC,CAAA;IACrC,aAAa,EAAE,KAAK,CAAC,aAAa,CAAC,CAAA;CACpC;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;IAC7B,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;IACnB,MAAM,EAAE,MAAM,CAAA;CACf"} \ No newline at end of file diff --git a/dist/Account/IAccountData.js b/dist/Account/IAccountData.js deleted file mode 100644 index c8ad2e5..0000000 --- a/dist/Account/IAccountData.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/dist/Authed.d.ts b/dist/Authed.d.ts deleted file mode 100644 index 8a8c8ea..0000000 --- a/dist/Authed.d.ts +++ /dev/null @@ -1,24 +0,0 @@ -export interface Auth { - secretKey: string; - apiKey: string; - masqueradeTarget?: string; -} -export interface Config { - auth?: Auth; - apiVersion?: string; - format?: string; - qs?: { - [key: string]: string; - }; - options?: { - headers?: { - [key: string]: string; - }; - }; -} -export default class Authed { - protected readonly config: Config; - constructor(config?: Config); - get isAuthed(): boolean; -} -//# sourceMappingURL=Authed.d.ts.map \ No newline at end of file diff --git a/dist/Authed.d.ts.map b/dist/Authed.d.ts.map deleted file mode 100644 index 463167b..0000000 --- a/dist/Authed.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"Authed.d.ts","sourceRoot":"","sources":["../src/Authed.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,IAAI;IACnB,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,MAAM,CAAA;IACd,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAC1B;AAED,MAAM,WAAW,MAAM;IACrB,IAAI,CAAC,EAAE,IAAI,CAAA;IACX,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,EAAE,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IAC/B,OAAO,CAAC,EAAE;QACR,OAAO,CAAC,EAAE;YAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;SAAE,CAAA;KACpC,CAAA;CACF;AAED,MAAM,CAAC,OAAO,OAAO,MAAM;IACzB,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;gBAErB,MAAM,CAAC,EAAE,MAAM;IAW3B,IAAW,QAAQ,IAAI,OAAO,CAE7B;CACF"} \ No newline at end of file diff --git a/dist/Authed.js b/dist/Authed.js deleted file mode 100644 index 42d75a4..0000000 --- a/dist/Authed.js +++ /dev/null @@ -1,22 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var Authed = (function () { - function Authed(config) { - var defaultConfig = { - qs: {}, - options: { - headers: {} - } - }; - this.config = Object.assign({}, defaultConfig, config); - } - Object.defineProperty(Authed.prototype, "isAuthed", { - get: function () { - return !!this.config.auth && !!this.config.auth.secretKey && !!this.config.auth.apiKey; - }, - enumerable: true, - configurable: true - }); - return Authed; -}()); -exports.default = Authed; diff --git a/dist/Model.d.ts b/dist/Model.d.ts index 9ff7dda..7bdf0f6 100644 --- a/dist/Model.d.ts +++ b/dist/Model.d.ts @@ -1,10 +1,11 @@ import Api from './utils/Api'; import Data from './Model/Data'; -export default abstract class Model { +export default abstract class Model { readonly api: Api; readonly data: Data; - constructor(data: object, api: Api); + constructor(data: TData, api: Api); set(data: object): void; set(key: PropertyKey, value: any): void; + get(key: PropertyKey): T; } //# sourceMappingURL=Model.d.ts.map \ No newline at end of file diff --git a/dist/Model.d.ts.map b/dist/Model.d.ts.map index 824c7f1..e571ad1 100644 --- a/dist/Model.d.ts.map +++ b/dist/Model.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"Model.d.ts","sourceRoot":"","sources":["../src/Model.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,aAAa,CAAA;AAC7B,OAAO,IAAI,MAAM,cAAc,CAAA;AAE/B,MAAM,CAAC,OAAO,CAAC,QAAQ,OAAO,KAAK,CAAC,CAAC;IACnC,SAAgB,GAAG,EAAE,GAAG,CAAA;IACxB,SAAgB,IAAI,EAAE,IAAI,CAAA;gBAEd,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG;IAS3B,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IACvB,GAAG,CAAC,GAAG,EAAE,WAAW,EAAE,KAAK,EAAE,GAAG,GAAG,IAAI;CAI/C"} \ No newline at end of file +{"version":3,"file":"Model.d.ts","sourceRoot":"","sources":["../src/Model.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,aAAa,CAAA;AAC7B,OAAO,IAAI,MAAM,cAAc,CAAA;AAE/B,MAAM,CAAC,OAAO,CAAC,QAAQ,OAAO,KAAK,CAAC,CAAC,EAAE,KAAK,SAAS,MAAM;IACzD,SAAgB,GAAG,EAAE,GAAG,CAAA;IACxB,SAAgB,IAAI,EAAE,IAAI,CAAA;gBAEd,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG;IAS1B,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IACvB,GAAG,CAAC,GAAG,EAAE,WAAW,EAAE,KAAK,EAAE,GAAG,GAAG,IAAI;IAKvC,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,WAAW,GAAG,CAAC;CAGnC"} \ No newline at end of file diff --git a/dist/Model.js b/dist/Model.js index 3dc8f5e..30e5856 100644 --- a/dist/Model.js +++ b/dist/Model.js @@ -11,6 +11,9 @@ var Model = (function () { Model.prototype.set = function (key, value) { this.data.set(key, value); }; + Model.prototype.get = function (key) { + return this.data.get(key); + }; return Model; }()); exports.default = Model; @@ -21,14 +24,14 @@ var ModelProxyHandler = (function () { return { enumerable: true, configurable: true }; }; ModelProxyHandler.prototype.set = function (target, key, value) { - key in target.data + key in target.data.updatedValues ? target.set(key, value) : target[key] = value; return true; }; ModelProxyHandler.prototype.get = function (target, key) { - return key in target.data - ? target.data[key] + return key in target.data.updatedValues + ? target.get(key) : target[key]; }; return ModelProxyHandler; diff --git a/dist/Model/Data.d.ts b/dist/Model/Data.d.ts index f17e8fc..ccbc913 100644 --- a/dist/Model/Data.d.ts +++ b/dist/Model/Data.d.ts @@ -4,6 +4,6 @@ export default class Data { constructor(data: object); get isChanged(): boolean; set(key: PropertyKey | object, value?: any): void; - get(key: string): T; + get(key: PropertyKey): T; } //# sourceMappingURL=Data.d.ts.map \ No newline at end of file diff --git a/dist/Model/Data.d.ts.map b/dist/Model/Data.d.ts.map index f6af390..47db31a 100644 --- a/dist/Model/Data.d.ts.map +++ b/dist/Model/Data.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"Data.d.ts","sourceRoot":"","sources":["../../src/Model/Data.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,OAAO,IAAI;IACvB,SAAgB,UAAU,EAAE,MAAM,CAAA;IAClC,SAAgB,aAAa,EAAE,MAAM,CAAA;gBAEzB,IAAI,EAAE,MAAM;IAKxB,IAAW,SAAS,IAAI,OAAO,CAI9B;IAEM,GAAG,CAAC,GAAG,EAAE,WAAW,GAAG,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG,GAAG,IAAI;IAUjD,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC;CAG9B"} \ No newline at end of file +{"version":3,"file":"Data.d.ts","sourceRoot":"","sources":["../../src/Model/Data.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,OAAO,IAAI;IACvB,SAAgB,UAAU,EAAE,MAAM,CAAA;IAClC,SAAgB,aAAa,EAAE,MAAM,CAAA;gBAEzB,IAAI,EAAE,MAAM;IAKxB,IAAW,SAAS,IAAI,OAAO,CAI9B;IAEM,GAAG,CAAC,GAAG,EAAE,WAAW,GAAG,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG,GAAG,IAAI;IAUjD,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,WAAW,GAAG,CAAC;CAGnC"} \ No newline at end of file diff --git a/dist/PaymentMethod.d.ts b/dist/PaymentMethod.d.ts index bb7c0af..bf0126d 100644 --- a/dist/PaymentMethod.d.ts +++ b/dist/PaymentMethod.d.ts @@ -1,7 +1,7 @@ import Model from './Model'; import type { IPaymentMethod } from './PaymentMethod/IPaymentMethod'; import Api from './utils/Api'; -export default class PaymentMethod extends Model implements IPaymentMethod { +export default class PaymentMethod extends Model implements IPaymentMethod { beneficiaryType: string; blockchains: object; brand: null; @@ -17,7 +17,7 @@ export default class PaymentMethod extends Model implements IPaym expirationDisplay: string; id: string; last4Digits: string; - linkType: string; + linkType: 'INTERNATIONAL_TRANSFER' | 'LOCAL_TRANSFER'; liquidationBalances: object; maxCharge: null; maxDeposit: null; @@ -29,7 +29,7 @@ export default class PaymentMethod extends Model implements IPaym owner: string; rejectionMessage: string | null; srn: string; - status: string | null; + status: 'PENDING' | 'AWAITING_FOLLOWUP' | 'ACTIVE' | 'REJECTED'; statusMessage: string; supportsDeposit: boolean; supportsPayment: boolean; diff --git a/dist/PaymentMethod.d.ts.map b/dist/PaymentMethod.d.ts.map index 403dede..6832a6d 100644 --- a/dist/PaymentMethod.d.ts.map +++ b/dist/PaymentMethod.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"PaymentMethod.d.ts","sourceRoot":"","sources":["../src/PaymentMethod.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,SAAS,CAAA;AAC3B,OAAO,KAAK,EAAE,cAAc,EAA2B,MAAM,gCAAgC,CAAA;AAC7F,OAAO,GAAG,MAAM,aAAa,CAAA;AAE7B,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,KAAK,CAAC,aAAa,CAAE,YAAW,cAAc;IAChF,eAAe,EAAE,MAAM,CAAA;IACvB,WAAW,EAAE,MAAM,CAAA;IACnB,KAAK,EAAE,IAAI,CAAA;IACX,iBAAiB,EAAE,IAAI,CAAA;IACvB,oBAAoB,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;IACnC,WAAW,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;IACjB,eAAe,EAAE,MAAM,CAAA;IACvB,kBAAkB,EAAE,IAAI,CAAA;IACxB,qBAAqB,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;IACpC,QAAQ,EAAE,OAAO,CAAA;IACjB,SAAS,EAAE,KAAK,CAAC,GAAG,CAAC,CAAA;IACrB,iBAAiB,EAAE,MAAM,CAAA;IACzB,EAAE,EAAE,MAAM,CAAA;IACV,WAAW,EAAE,MAAM,CAAA;IACnB,QAAQ,EAAE,MAAM,CAAA;IAChB,mBAAmB,EAAE,MAAM,CAAA;IAC3B,SAAS,EAAE,IAAI,CAAA;IACf,UAAU,EAAE,IAAI,CAAA;IAChB,SAAS,EAAE,IAAI,CAAA;IACf,UAAU,EAAE,IAAI,CAAA;IAChB,IAAI,EAAE,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,MAAM,CAAA;IACzB,EAAE,EAAE,MAAM,CAAA;IACV,WAAW,EAAE,MAAM,CAAA;IACnB,QAAQ,EAAE,wBAAwB,GAAG,gBAAgB,CAAA;IACrD,mBAAmB,EAAE,MAAM,CAAA;IAC3B,SAAS,EAAE,IAAI,CAAA;IACf,UAAU,EAAE,IAAI,CAAA;IAChB,SAAS,EAAE,IAAI,CAAA;IACf,UAAU,EAAE,IAAI,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,YAAY,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,KAAK,EAAE,MAAM,CAAA;IACb,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAA;IAC/B,GAAG,EAAE,MAAM,CAAA;IACX,MAAM,EAAE,SAAS,GAAG,mBAAmB,GAAG,QAAQ,GAAG,UAAU,CAAA;IAC/D,aAAa,EAAE,MAAM,CAAA;IACrB,eAAe,EAAE,OAAO,CAAA;IACxB,eAAe,EAAE,OAAO,CAAA;IACxB,cAAc,EAAE,KAAK,CAAC,GAAG,CAAC,CAAA;WAEb,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;CAQtE"} \ No newline at end of file diff --git a/dist/PaymentMethod/IPaymentMethod.d.ts b/dist/PaymentMethod/IPaymentMethod.d.ts index b768974..b26483a 100644 --- a/dist/PaymentMethod/IPaymentMethod.d.ts +++ b/dist/PaymentMethod/IPaymentMethod.d.ts @@ -4,10 +4,10 @@ export interface IPaymentMethod { createdAt: number; name: string; defaultCurrency: string; - status: string | null; + status: 'PENDING' | 'AWAITING_FOLLOWUP' | 'ACTIVE' | 'REJECTED'; statusMessage: string; waitingPrompts: Array; - linkType: string; + linkType: 'INTERNATIONAL_TRANSFER' | 'LOCAL_TRANSFER'; beneficiaryType: string; supportsDeposit: boolean; nameOnMethod: string | null; diff --git a/dist/Transfer.d.ts b/dist/Transfer.d.ts index 69266fa..0649554 100644 --- a/dist/Transfer.d.ts +++ b/dist/Transfer.d.ts @@ -1,7 +1,7 @@ import Model from './Model'; import Api from './utils/Api'; import type { ITransferStatusHistory, ITransfer, ITransferFees, ICreateTransferParams } from './Transfer/ITransfer'; -export default class Transfer extends Model implements ITransfer { +export default class Transfer extends Model implements ITransfer { blockchainTx: string; cancelledAt: number; completedAt: number; diff --git a/dist/Transfer.d.ts.map b/dist/Transfer.d.ts.map index 14c310e..50d9af3 100644 --- a/dist/Transfer.d.ts.map +++ b/dist/Transfer.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"Transfer.d.ts","sourceRoot":"","sources":["../src/Transfer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,SAAS,CAAA;AAC3B,OAAO,GAAG,MAAM,aAAa,CAAA;AAC7B,OAAO,KAAK,EAAE,sBAAsB,EAAE,SAAS,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAA;AAEnH,MAAM,CAAC,OAAO,OAAO,QAAS,SAAQ,KAAK,CAAC,QAAQ,CAAE,YAAW,SAAS;IACjE,YAAY,EAAE,MAAM,CAAA;IACpB,WAAW,EAAE,MAAM,CAAA;IACnB,WAAW,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,EAAE,MAAM,CAAA;IAClB,YAAY,EAAE,MAAM,CAAA;IACpB,YAAY,EAAE,MAAM,CAAA;IACpB,SAAS,EAAE,MAAM,CAAA;IACjB,aAAa,EAAE,MAAM,CAAA;IACrB,IAAI,EAAE,aAAa,CAAA;IACnB,EAAE,EAAE,MAAM,CAAA;IACV,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;IACb,gBAAgB,EAAE,MAAM,CAAA;IACxB,cAAc,EAAE,MAAM,CAAA;IACtB,kBAAkB,EAAE,MAAM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AAkB,EAAE,MAAM,CAAA;IAC1B,MAAM,EAAE,MAAM,CAAA;IACd,YAAY,EAAE,MAAM,CAAA;IACpB,cAAc,EAAE,MAAM,CAAA;IACtB,MAAM,EAAE,MAAM,CAAA;IACd,eAAe,EAAE,KAAK,CAAC,sBAAsB,CAAC,CAAA;IAC9C,SAAS,EAAE,MAAM,CAAA;WAEV,kBAAkB,CAAC,MAAM,EAAE,qBAAqB;WAK1C,MAAM,CAAC,MAAM,EAAE,qBAAqB,EAAE,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,QAAQ,CAAC;IAUzE,OAAO;CAIrB"} \ No newline at end of file diff --git a/dist/Transfer/ICreateTransferParams.d.ts b/dist/Transfer/ICreateTransferParams.d.ts deleted file mode 100644 index dc2350f..0000000 --- a/dist/Transfer/ICreateTransferParams.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -export interface CreateTransferParams { - source: string; - sourceCurrency: string; - sourceAmount?: string; - destination: string; - destinationCurrency: string; - destinationAmount?: string; - message?: string; - notifyUrl?: string; - autoConfirm?: boolean; - customId?: string; - amountIncludesFees?: boolean; - preview?: boolean; - muteMessages?: boolean; -} -//# sourceMappingURL=ICreateTransferParams.d.ts.map \ No newline at end of file diff --git a/dist/Transfer/ICreateTransferParams.d.ts.map b/dist/Transfer/ICreateTransferParams.d.ts.map deleted file mode 100644 index 51b2aa8..0000000 --- a/dist/Transfer/ICreateTransferParams.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"ICreateTransferParams.d.ts","sourceRoot":"","sources":["../../src/Transfer/ICreateTransferParams.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAA;IACd,cAAc,EAAE,MAAM,CAAA;IACtB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,WAAW,EAAE,MAAM,CAAA;IACnB,mBAAmB,EAAE,MAAM,CAAA;IAC3B,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB"} \ No newline at end of file diff --git a/dist/Transfer/ICreateTransferParams.js b/dist/Transfer/ICreateTransferParams.js deleted file mode 100644 index c8ad2e5..0000000 --- a/dist/Transfer/ICreateTransferParams.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/dist/Transfer/ITransferData.d.ts b/dist/Transfer/ITransferData.d.ts deleted file mode 100644 index 076b67e..0000000 --- a/dist/Transfer/ITransferData.d.ts +++ /dev/null @@ -1,46 +0,0 @@ -export interface ITransferHistory { - data: Array; - position: number; - recordsTotal: number; - recordsFiltered: number; -} -export interface ITransferData { - id: string; - sourceAmount: number; - sourceCurrency: string; - destAmount: number; - destCurrency: string; - status: string; - message: string; - customId: string; - exchangeRate: number; - createdAt: number; - fees: ITransferFees; - totalFees: number; - completedAt: number; - cancelledAt: number; - failureReason: string; - expiresAt: number; - reversingSubStatus: string; - reversalReason: string; - pendingSubStatus: string; - dest: string; - blockchainTx: string; - statusHistories: Array; - owner: string; - source: string; -} -export interface ITransferFees { - [assetTicker: string]: number; -} -export interface IStatusHistory { - id: string; - transferId: string; - createdAt: number; - type: string; - statusOrder: number; - statusDetail: string; - state: string; - failedState: boolean; -} -//# sourceMappingURL=ITransferData.d.ts.map \ No newline at end of file diff --git a/dist/Transfer/ITransferData.d.ts.map b/dist/Transfer/ITransferData.d.ts.map deleted file mode 100644 index 74f3b2d..0000000 --- a/dist/Transfer/ITransferData.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"ITransferData.d.ts","sourceRoot":"","sources":["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A;IACnB,YAAY,EAAE,MAAM,CAAA;IACpB,KAAK,EAAE,MAAM,CAAA;IACb,WAAW,EAAE,OAAO,CAAA;CACrB"} \ No newline at end of file diff --git a/dist/Transfer/ITransferData.js b/dist/Transfer/ITransferData.js deleted file mode 100644 index c8ad2e5..0000000 --- a/dist/Transfer/ITransferData.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/dist/utils/API.d.ts b/dist/utils/API.d.ts deleted file mode 100644 index 16b42f2..0000000 --- a/dist/utils/API.d.ts +++ /dev/null @@ -1,14 +0,0 @@ -import 'es6-shim'; -import Authed from '../Authed'; -import { IApiOptions } from './API/IApiOptions'; -export default class API extends Authed { - requireAuthed(): void; - get(path: string, params?: any, options?: IApiOptions): Promise; - post(path: string, body?: any, options?: IApiOptions): Promise; - put(path: string, body?: any, options?: IApiOptions): Promise; - delete(path: string, body?: any, options?: IApiOptions): Promise; - private request; - private buildRequestOptions; - private buildSignature; -} -//# sourceMappingURL=API.d.ts.map \ No newline at end of file diff --git a/dist/utils/API.d.ts.map b/dist/utils/API.d.ts.map deleted file mode 100644 index e4c8812..0000000 --- a/dist/utils/API.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"API.d.ts","sourceRoot":"","sources":["../../src/utils/API.ts"],"names":[],"mappings":"AAIA,OAAO,UAAU,CAAA;AAEjB,OAAO,MAAM,MAAM,WAAW,CAAA;AAC9B,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAM/C,MAAM,CAAC,OAAO,OAAO,GAAI,SAAQ,MAAM;IAC9B,aAAa;IAKb,GAAG,CAAC,CAAC,SAAS,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC;IAIjF,IAAI,CAAC,CAAC,SAAS,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC;IAIhF,GAAG,CAAC,CAAC,SAAS,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC;IAI/E,MAAM,CAAC,CAAC,SAAS,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC;IAIzF,OAAO,CAAC,OAAO;IAkBf,OAAO,CAAC,mBAAmB;IAuC3B,OAAO,CAAC,cAAc;CAqBvB"} \ No newline at end of file diff --git a/dist/utils/API.js b/dist/utils/API.js deleted file mode 100644 index aaa0f89..0000000 --- a/dist/utils/API.js +++ /dev/null @@ -1,111 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) - t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var request = require("request"); -var crypto = require("crypto"); -var querystring = require("querystring"); -var url = require("url"); -require("es6-shim"); -var Authed_1 = require("../Authed"); -var WYRE_BASEURL = 'https://api.testwyre.com'; -var WYRE_API_VERSION = '3'; -var WYRE_DEFAULT_API_FORMAT = 'json'; -var API = (function (_super) { - __extends(API, _super); - function API() { - return _super !== null && _super.apply(this, arguments) || this; - } - API.prototype.requireAuthed = function () { - if (!this.isAuthed) - throw new Error('Must be authenticated for this endpoint.'); - }; - API.prototype.get = function (path, params, options) { - return this.request('GET', path, params, options); - }; - API.prototype.post = function (path, body, options) { - return this.request('POST', path, body, options); - }; - API.prototype.put = function (path, body, options) { - return this.request('PUT', path, body, options); - }; - API.prototype.delete = function (path, body, options) { - return this.request('DELETE', path, body, options); - }; - API.prototype.request = function (method, path, params, options) { - if (params === void 0) { params = {}; } - if (options === void 0) { options = {}; } - if (!path) - throw 'path required'; - var requestOptions = this.buildRequestOptions(method, path, params, options); - return new Promise(function (resolve, reject) { - request(requestOptions, function (err, res) { - if (err) - throw err; - else if (res.statusCode >= 200 && res.statusCode < 300) - resolve(res.body || {}); - else - reject(res.body || { statusCode: res.statusCode }); - }); - }); - }; - API.prototype.buildRequestOptions = function (method, path, params, options) { - var parsedUrl = url.parse(url.resolve(WYRE_BASEURL, "v" + (path === 'paymentMethods' ? '2' : WYRE_API_VERSION) + "/" + path), true); - var json = !(options.headers || {}).hasOwnProperty('Content-Type') || options.headers['Content-Type'] == 'application/json'; - var requestOptions = __assign(__assign(__assign({}, this.config.options), options), { url: parsedUrl.protocol + '//' + parsedUrl.host + parsedUrl.pathname, method: method, headers: __assign(__assign({}, this.config.options.headers), options.headers), qs: __assign(__assign(__assign({}, this.config.qs), options.qs), { timestamp: new Date().getTime(), format: this.config.format || WYRE_DEFAULT_API_FORMAT }), json: json }); - if (requestOptions.method == 'GET') - requestOptions.qs = Object.assign(requestOptions.qs, params); - else - requestOptions.body = params; - Object.assign(requestOptions.qs, parsedUrl.query); - if (this.isAuthed && this.config.auth.masqueradeTarget && !('masqueradeAs' in requestOptions)) - requestOptions.qs.masqueradeAs = this.config.auth.masqueradeTarget; - if (this.isAuthed) { - requestOptions.headers['X-Api-Key'] = this.config.auth.apiKey; - requestOptions.headers['X-Api-Signature'] = this.buildSignature(requestOptions); - } - return requestOptions; - }; - API.prototype.buildSignature = function (requestOptions) { - var buffers = []; - var encoding = 'utf8'; - buffers.push(Buffer.from(requestOptions.url.toString(), encoding)); - buffers.push(Buffer.from(requestOptions.url.toString().indexOf('?') < 0 ? '?' : '&', encoding)); - buffers.push(Buffer.from(querystring.stringify(requestOptions.qs), encoding)); - if (requestOptions.body) { - if (typeof requestOptions.body == 'string') - buffers.push(Buffer.from(requestOptions.body, encoding)); - else if (requestOptions.body instanceof Buffer) - buffers.push(requestOptions.body); - else - buffers.push(Buffer.from(JSON.stringify(requestOptions.body), encoding)); - } - return crypto.createHmac('sha256', this.config.auth.secretKey) - .update(Buffer.concat(buffers)) - .digest('hex'); - }; - return API; -}(Authed_1.default)); -exports.default = API; diff --git a/dist/utils/API/IApiConfig.d.ts b/dist/utils/API/IApiConfig.d.ts index b365b73..69c8d6d 100644 --- a/dist/utils/API/IApiConfig.d.ts +++ b/dist/utils/API/IApiConfig.d.ts @@ -1,5 +1,5 @@ export interface IApiConfig extends IApiOptions { - version: string; + version?: string; uri?: string; auth?: IAuth; } diff --git a/dist/utils/API/IApiConfig.d.ts.map b/dist/utils/API/IApiConfig.d.ts.map index 392a73b..396cf9d 100644 --- a/dist/utils/API/IApiConfig.d.ts.map +++ b/dist/utils/API/IApiConfig.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"IApiConfig.d.ts","sourceRoot":"","sources":["../../../src/utils/API/IApiConfig.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAW,SAAQ,WAAW;IAC7C,OAAO,EAAE,MAAM,CAAA;IACf,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,KAAK,CAAA;CACb;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAA;IACnC,EAAE,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAA;CAC/B;AAED,MAAM,WAAW,KAAK;IACpB,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,MAAM,CAAA;IACd,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAC1B"} \ No newline at end of file +{"version":3,"file":"IApiConfig.d.ts","sourceRoot":"","sources":["../../../src/utils/API/IApiConfig.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAW,SAAQ,WAAW;IAC7C,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,KAAK,CAAA;CACb;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAA;IACnC,EAAE,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAA;CAC/B;AAED,MAAM,WAAW,KAAK;IACpB,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,MAAM,CAAA;IACd,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAC1B"} \ No newline at end of file diff --git a/dist/utils/API/IApiOptions.d.ts b/dist/utils/API/IApiOptions.d.ts deleted file mode 100644 index 4b7bba8..0000000 --- a/dist/utils/API/IApiOptions.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -export interface IApiOptions { - headers?: object; - qs?: object; - version?: string; -} -//# sourceMappingURL=IApiOptions.d.ts.map \ No newline at end of file diff --git a/dist/utils/API/IApiOptions.d.ts.map b/dist/utils/API/IApiOptions.d.ts.map deleted file mode 100644 index 87fa81a..0000000 --- a/dist/utils/API/IApiOptions.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"IApiOptions.d.ts","sourceRoot":"","sources":["../../../src/utils/API/IApiOptions.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB"} \ No newline at end of file diff --git a/dist/utils/API/IApiOptions.js b/dist/utils/API/IApiOptions.js deleted file mode 100644 index c8ad2e5..0000000 --- a/dist/utils/API/IApiOptions.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/dist/utils/API/IOptions.d.ts b/dist/utils/API/IOptions.d.ts deleted file mode 100644 index c3462fd..0000000 --- a/dist/utils/API/IOptions.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -export interface IOptions { - headers?: object; - qs?: object; - version: string; -} -//# sourceMappingURL=IOptions.d.ts.map \ No newline at end of file diff --git a/dist/utils/API/IOptions.d.ts.map b/dist/utils/API/IOptions.d.ts.map deleted file mode 100644 index b8cff5a..0000000 --- a/dist/utils/API/IOptions.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"IOptions.d.ts","sourceRoot":"","sources":["../../../src/utils/API/IOptions.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,QAAQ;IACvB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,OAAO,EAAE,MAAM,CAAA;CAChB"} \ No newline at end of file diff --git a/dist/utils/API/IOptions.js b/dist/utils/API/IOptions.js deleted file mode 100644 index c8ad2e5..0000000 --- a/dist/utils/API/IOptions.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/dist/utils/Auth/IAuthed.d.ts b/dist/utils/Auth/IAuthed.d.ts deleted file mode 100644 index f13884f..0000000 --- a/dist/utils/Auth/IAuthed.d.ts +++ /dev/null @@ -1 +0,0 @@ -//# sourceMappingURL=IAuthed.d.ts.map \ No newline at end of file diff --git a/dist/utils/Auth/IAuthed.d.ts.map b/dist/utils/Auth/IAuthed.d.ts.map deleted file mode 100644 index 19d1bd9..0000000 --- a/dist/utils/Auth/IAuthed.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"IAuthed.d.ts","sourceRoot":"","sources":["../../../src/utils/Auth/IAuthed.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/utils/Auth/IAuthed.js b/dist/utils/Auth/IAuthed.js deleted file mode 100644 index e69de29..0000000 diff --git a/dist/utils/Authed.d.ts b/dist/utils/Authed.d.ts deleted file mode 100644 index c4db48e..0000000 --- a/dist/utils/Authed.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import Api from './Api'; -export default class Authed { - private readonly api; - constructor(api: Api); -} -//# sourceMappingURL=Authed.d.ts.map \ No newline at end of file diff --git a/dist/utils/Authed.d.ts.map b/dist/utils/Authed.d.ts.map deleted file mode 100644 index f760fe6..0000000 --- a/dist/utils/Authed.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"Authed.d.ts","sourceRoot":"","sources":["../../src/utils/Authed.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,OAAO,CAAA;AAEvB,MAAM,CAAC,OAAO,OAAO,MAAM;IACzB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAK;gBAEb,GAAG,EAAE,GAAG;CAGrB"} \ No newline at end of file diff --git a/dist/utils/Authed.js b/dist/utils/Authed.js deleted file mode 100644 index c552fa5..0000000 --- a/dist/utils/Authed.js +++ /dev/null @@ -1,9 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var Authed = (function () { - function Authed(api) { - this.api = api; - } - return Authed; -}()); -exports.default = Authed; diff --git a/dist/utils/Request.d.ts b/dist/utils/Request.d.ts deleted file mode 100644 index c7ecd9e..0000000 --- a/dist/utils/Request.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -import 'es6-shim'; -import Authed from '../Authed'; -export default class Request extends Authed { - private static _instance; - static get instance(): Request; - get(path: string, params?: any, options?: any): Promise; - post(path: string, body?: any, options?: any): Promise; - put(path: string, body?: any, options?: any): Promise; - delete(path: string, body?: any, options?: any): Promise; - private request; - private buildRequestOptions; - private buildSignature; -} diff --git a/dist/utils/Request.js b/dist/utils/Request.js deleted file mode 100644 index 5bfe474..0000000 --- a/dist/utils/Request.js +++ /dev/null @@ -1,98 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -const request = require("request"); -const crypto = require("crypto"); -const querystring = require("querystring"); -const url = require("url"); -require("es6-shim"); -const Authed_1 = require("../Authed"); -const WYRE_BASEURL = 'https://api.testwyre.com/v3'; -const WYRE_DEFAULT_API_FORMAT = 'json'; -class Request extends Authed_1.default { - static get instance() { - if (this._instance) - return this._instance; - this._instance = - ; - } - get(path, params, options) { - return this.request('GET', path, params, options); - } - post(path, body, options) { - return this.request('POST', path, body, options); - } - put(path, body, options) { - return this.request('PUT', path, body, options); - } - delete(path, body, options) { - return this.request('DELETE', path, body, options); - } - request(method, path, params = {}, options = {}) { - if (!path) - throw 'path required'; - let requestOptions = this.buildRequestOptions(method, path, params, options); - return new Promise((resolve, reject) => { - request(requestOptions, (err, res) => { - if (err) - throw err; - else if (res.statusCode >= 200 && res.statusCode < 300) - resolve(res.body || {}); - else - reject(res.body || { statusCode: res.statusCode }); - }); - }); - } - buildRequestOptions(method, path, params, options) { - options = options || {}; - let parsedUrl = url.parse(url.resolve(WYRE_BASEURL, path), true); - let json = !(options.headers || {}).hasOwnProperty('Content-Type') || options.headers['Content-Type'] == 'application/json'; - let requestOptions = { - ...this.config.options, - ...options, - url: parsedUrl.protocol + '//' + parsedUrl.host + parsedUrl.pathname, - method: method, - headers: { - ...this.config.options.headers, - ...options.headers - }, - qs: { - ...this.config.qs, - ...options.qs, - timestamp: new Date().getTime(), - format: this.config.format || WYRE_DEFAULT_API_FORMAT - }, - json: json - }; - if (requestOptions.method == 'GET') - requestOptions.qs = Object.assign(requestOptions.qs, params); - else - requestOptions.body = params; - Object.assign(requestOptions.qs, parsedUrl.query); - if (this.isAuthed && this.config.auth.masqueradeTarget && !('masqueradeAs' in requestOptions)) - requestOptions.qs.masqueradeAs = this.config.auth.masqueradeTarget; - if (this.isAuthed) { - requestOptions.headers['X-Api-Key'] = this.config.auth.apiKey; - requestOptions.headers['X-Api-Signature'] = this.buildSignature(requestOptions); - } - return requestOptions; - } - buildSignature(requestOptions) { - let buffers = []; - const encoding = 'utf8'; - buffers.push(Buffer.from(requestOptions.url.toString(), encoding)); - buffers.push(Buffer.from(requestOptions.url.toString().indexOf('?') < 0 ? '?' : '&', encoding)); - buffers.push(Buffer.from(querystring.stringify(requestOptions.qs), encoding)); - if (requestOptions.body) { - if (typeof requestOptions.body == 'string') - buffers.push(Buffer.from(requestOptions.body, encoding)); - else if (requestOptions.body instanceof Buffer) - buffers.push(requestOptions.body); - else - buffers.push(Buffer.from(JSON.stringify(requestOptions.body), encoding)); - } - return crypto.createHmac('sha256', this.config.auth.secretKey) - .update(Buffer.concat(buffers)) - .digest('hex'); - } -} -exports.default = Request; diff --git a/src/Account.ts b/src/Account.ts index ca50cba..b2a56c8 100644 --- a/src/Account.ts +++ b/src/Account.ts @@ -2,10 +2,10 @@ import Model from './Model' import Transfer from './Transfer' import PaymentMethod from './PaymentMethod' import Api from './utils/Api' -import type { IAccount, IAccountResponse, ICreateAccountParams, IProfileField } from './Account/IAccount' -import type { ICreateTransferParams, ITransferHistoryResponse } from './Transfer/ITransfer' +import { IAccount, IAccountResponse, ICreateAccountParams, IProfileField } from './Account/IAccount' +import { ICreateTransferParams, ITransferHistoryResponse } from './Transfer/ITransfer' -export default class Account extends Model implements IAccount { +export default class Account extends Model implements IAccount { public id: string public status: 'OPEN' | 'PENDING' | 'APPROVED' public type: string @@ -33,9 +33,8 @@ export default class Account extends Model implements IAccount { return this.postFetch(data, api) } protected static async postFetch(data: IAccountResponse, api: Api): Promise { - const account = new Account(data, api) - await account.fetchPaymentMethods() - return account + const paymentMethods = await PaymentMethod.fetchAll(api) + return new Account({ ...data, paymentMethods }, api) } public async save(): Promise { @@ -44,12 +43,6 @@ export default class Account extends Model implements IAccount { await this.api.post(`accounts/${this.id}`, this.data.updatedValues) } - public async fetchPaymentMethods(): Promise> { - const paymentMethods = await PaymentMethod.fetchAll(this.api) - this.paymentMethods = paymentMethods - return paymentMethods - } - public async createTransfer(params: ICreateTransferParams): Promise { const transfer = await Transfer.create(params, this.api) diff --git a/src/Model.ts b/src/Model.ts index 4c81abb..1f7efb0 100644 --- a/src/Model.ts +++ b/src/Model.ts @@ -1,11 +1,11 @@ import Api from './utils/Api' import Data from './Model/Data' -export default abstract class Model { +export default abstract class Model { public readonly api: Api public readonly data: Data - constructor(data: object, api: Api) { + constructor(data: TData, api: Api) { this.api = api this.data = new Data(data) @@ -19,15 +19,19 @@ export default abstract class Model { public set(key: PropertyKey | object, value?: any): void { this.data.set(key, value) } + + public get(key: PropertyKey): T { + return this.data.get(key) + } } -class ModelProxyHandler> implements ProxyHandler { +class ModelProxyHandler, TData extends object> implements ProxyHandler { public getOwnPropertyDescriptor(target: T, p: PropertyKey): PropertyDescriptor | undefined { return { enumerable: true, configurable: true } } public set(target: T, key: PropertyKey, value: any): boolean { - key in target.data + key in target.data.updatedValues ? target.set(key, value) : target[key] = value @@ -35,8 +39,8 @@ class ModelProxyHandler> implements ProxyHandler { } public get(target: T, key: PropertyKey): any { - return key in target.data - ? target.data[key] + return key in target.data.updatedValues + ? target.get(key) : target[key] } } \ No newline at end of file diff --git a/src/Model/Data.ts b/src/Model/Data.ts index 474f486..d64af7a 100644 --- a/src/Model/Data.ts +++ b/src/Model/Data.ts @@ -23,7 +23,7 @@ export default class Data { } } - public get(key: string): T { + public get(key: PropertyKey): T { return this.updatedValues[key] } } \ No newline at end of file diff --git a/src/PaymentMethod.ts b/src/PaymentMethod.ts index 9ddaace..b72bb00 100644 --- a/src/PaymentMethod.ts +++ b/src/PaymentMethod.ts @@ -2,7 +2,7 @@ import Model from './Model' import type { IPaymentMethod, IPaymentMethodsResponse } from './PaymentMethod/IPaymentMethod' import Api from './utils/Api' -export default class PaymentMethod extends Model implements IPaymentMethod { +export default class PaymentMethod extends Model implements IPaymentMethod { public beneficiaryType: string public blockchains: object public brand: null @@ -18,7 +18,7 @@ export default class PaymentMethod extends Model implements IPaym public expirationDisplay: string public id: string public last4Digits: string - public linkType: string + public linkType: 'INTERNATIONAL_TRANSFER' | 'LOCAL_TRANSFER' public liquidationBalances: object public maxCharge: null public maxDeposit: null @@ -30,7 +30,7 @@ export default class PaymentMethod extends Model implements IPaym public owner: string public rejectionMessage: string | null public srn: string - public status: string | null + public status: 'PENDING' | 'AWAITING_FOLLOWUP' | 'ACTIVE' | 'REJECTED' public statusMessage: string public supportsDeposit: boolean public supportsPayment: boolean diff --git a/src/PaymentMethod/IPaymentMethod.ts b/src/PaymentMethod/IPaymentMethod.ts index fdf30b4..b30fa73 100644 --- a/src/PaymentMethod/IPaymentMethod.ts +++ b/src/PaymentMethod/IPaymentMethod.ts @@ -4,11 +4,11 @@ export interface IPaymentMethod { createdAt: number name: string defaultCurrency: string - status: string | null + status: 'PENDING' | 'AWAITING_FOLLOWUP' | 'ACTIVE' | 'REJECTED' statusMessage: string // TODO: unknown type waitingPrompts: Array - linkType: string + linkType: 'INTERNATIONAL_TRANSFER' | 'LOCAL_TRANSFER' beneficiaryType: string supportsDeposit: boolean nameOnMethod: string | null diff --git a/src/Transfer.ts b/src/Transfer.ts index a50ff0e..78b58b5 100644 --- a/src/Transfer.ts +++ b/src/Transfer.ts @@ -2,7 +2,7 @@ import Model from './Model' import Api from './utils/Api' import type { ITransferStatusHistory, ITransfer, ITransferFees, ICreateTransferParams } from './Transfer/ITransfer' -export default class Transfer extends Model implements ITransfer { +export default class Transfer extends Model implements ITransfer { public blockchainTx: string public cancelledAt: number public completedAt: number diff --git a/src/utils/API/IApiConfig.ts b/src/utils/API/IApiConfig.ts index 8702c47..6a6b646 100644 --- a/src/utils/API/IApiConfig.ts +++ b/src/utils/API/IApiConfig.ts @@ -1,5 +1,5 @@ export interface IApiConfig extends IApiOptions { - version: string + version?: string uri?: string auth?: IAuth } From 3477a5f999b4dc2a981c75e4f0f52139f7c6621d Mon Sep 17 00:00:00 2001 From: Noah Passalacqua Date: Wed, 8 Apr 2020 11:47:57 -0500 Subject: [PATCH 07/20] Add ACH payment method support. --- dist/PaymentMethod.d.ts | 1 + dist/PaymentMethod.d.ts.map | 2 +- dist/PaymentMethod.js | 20 ++++++++++++++++++++ dist/PaymentMethod/IPaymentMethod.d.ts | 5 +++++ dist/PaymentMethod/IPaymentMethod.d.ts.map | 2 +- dist/Transfer.d.ts.map | 2 +- dist/Transfer.js | 16 ++++++++++++++-- dist/Transfer/ITransfer.d.ts | 5 +++-- dist/Transfer/ITransfer.d.ts.map | 2 +- src/PaymentMethod.ts | 12 ++++++++++++ src/PaymentMethod/IPaymentMethod.ts | 6 ++++++ src/Transfer.ts | 10 ++++++++++ src/Transfer/ITransfer.ts | 6 ++++-- 13 files changed, 79 insertions(+), 10 deletions(-) diff --git a/dist/PaymentMethod.d.ts b/dist/PaymentMethod.d.ts index bf0126d..110f367 100644 --- a/dist/PaymentMethod.d.ts +++ b/dist/PaymentMethod.d.ts @@ -34,6 +34,7 @@ export default class PaymentMethod extends Model supportsDeposit: boolean; supportsPayment: boolean; waitingPrompts: Array; + static createACH(api: Api, publicToken: string): Promise; static fetchAll(api: Api): Promise>; } //# sourceMappingURL=PaymentMethod.d.ts.map \ No newline at end of file diff --git a/dist/PaymentMethod.d.ts.map b/dist/PaymentMethod.d.ts.map index 6832a6d..c332d8d 100644 --- a/dist/PaymentMethod.d.ts.map +++ b/dist/PaymentMethod.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"PaymentMethod.d.ts","sourceRoot":"","sources":["../src/PaymentMethod.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AAE,IAAI,CAAA;IACf,UAAU,EAAE,IAAI,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,YAAY,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,KAAK,EAAE,MAAM,CAAA;IACb,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAA;IAC/B,GAAG,EAAE,MAAM,CAAA;IACX,MAAM,EAAE,SAAS,GAAG,mBAAmB,GAAG,QAAQ,GAAG,UAAU,CAAA;IAC/D,aAAa,EAAE,MAAM,CAAA;IACrB,eAAe,EAAE,OAAO,CAAA;IACxB,eAAe,EAAE,OAAO,CAAA;IACxB,cAAc,EAAE,KAAK,CAAC,GAAG,CAAC,CAAA;WAEb,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;WAYhE,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;CAQtE"} \ No newline at end of file diff --git a/dist/PaymentMethod.js b/dist/PaymentMethod.js index d791649..85d303f 100644 --- a/dist/PaymentMethod.js +++ b/dist/PaymentMethod.js @@ -55,6 +55,26 @@ var PaymentMethod = (function (_super) { function PaymentMethod() { return _super !== null && _super.apply(this, arguments) || this; } + PaymentMethod.createACH = function (api, publicToken) { + return __awaiter(this, void 0, void 0, function () { + var body, data; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + api.requireAuthed(); + body = { + publicToken: publicToken, + paymentMethodType: 'LOCAL_TRANSFER', + country: 'US' + }; + return [4, api.post('paymentMethods', body, { version: '2' })]; + case 1: + data = _a.sent(); + return [2, new PaymentMethod(data, api)]; + } + }); + }); + }; PaymentMethod.fetchAll = function (api) { return __awaiter(this, void 0, void 0, function () { var paymentMethods; diff --git a/dist/PaymentMethod/IPaymentMethod.d.ts b/dist/PaymentMethod/IPaymentMethod.d.ts index b26483a..641f531 100644 --- a/dist/PaymentMethod/IPaymentMethod.d.ts +++ b/dist/PaymentMethod/IPaymentMethod.d.ts @@ -37,4 +37,9 @@ export interface IPaymentMethodsResponse { recordsTotal: number; position: number; } +export interface IPaymentMethodACHCreateParams { + publicToken: string; + paymentMethodType: string; + country: string; +} //# sourceMappingURL=IPaymentMethod.d.ts.map \ No newline at end of file diff --git a/dist/PaymentMethod/IPaymentMethod.d.ts.map b/dist/PaymentMethod/IPaymentMethod.d.ts.map index f004b09..0d17e5f 100644 --- a/dist/PaymentMethod/IPaymentMethod.d.ts.map +++ b/dist/PaymentMethod/IPaymentMethod.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"IPaymentMethod.d.ts","sourceRoot":"","sources":["../../src/PaymentMethod/IPaymentMethod.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,MAAM,CAAA;IACb,SAAS,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,MAAM,CAAA;IACZ,eAAe,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;IACrB,aAAa,EAAE,MAAM,CAAA;IAErB,cAAc,EAAE,KAAK,CAAC,GAAG,CAAC,CAAA;IAC1B,QAAQ,EAAE,MAAM,CAAA;IAChB,eAAe,EAAE,MAAM,CAAA;IACvB,eAAe,EAAE,OAAO,CAAA;IACxB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,WAAW,EAAE,MAAM,CAAA;IAEnB,KAAK,EAAE,IAAI,CAAA;IACX,iBAAiB,EAAE,MAAM,CAAA;IACzB,WAAW,EAAE,MAAM,CAAA;IACnB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAA;IAC/B,QAAQ,EAAE,OAAO,CAAA;IACjB,eAAe,EAAE,OAAO,CAAA;IACxB,oBAAoB,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACpC,qBAAqB,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACrC,GAAG,EAAE,MAAM,CAAA;IAGX,iBAAiB,EAAE,IAAI,CAAA;IACvB,kBAAkB,EAAE,IAAI,CAAA;IACxB,SAAS,EAAE,IAAI,CAAA;IACf,SAAS,EAAE,IAAI,CAAA;IACf,UAAU,EAAE,IAAI,CAAA;IAChB,UAAU,EAAE,IAAI,CAAA;IAChB,SAAS,EAAE,KAAK,CAAC,GAAG,CAAC,CAAA;IACrB,WAAW,EAAE,MAAM,CAAA;IACnB,mBAAmB,EAAE,MAAM,CAAA;CAC5B;AAED,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,KAAK,CAAC,cAAc,CAAC,CAAA;IAC3B,YAAY,EAAE,MAAM,CAAA;IACpB,QAAQ,EAAE,MAAM,CAAA;CACjB"} \ No newline at end of file +{"version":3,"file":"IPaymentMethod.d.ts","sourceRoot":"","sources":["../../src/PaymentMethod/IPaymentMethod.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,MAAM,CAAA;IACb,SAAS,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,MAAM,CAAA;IACZ,eAAe,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,SAAS,GAAG,mBAAmB,GAAG,QAAQ,GAAG,UAAU,CAAA;IAC/D,aAAa,EAAE,MAAM,CAAA;IAErB,cAAc,EAAE,KAAK,CAAC,GAAG,CAAC,CAAA;IAC1B,QAAQ,EAAE,wBAAwB,GAAG,gBAAgB,CAAA;IACrD,eAAe,EAAE,MAAM,CAAA;IACvB,eAAe,EAAE,OAAO,CAAA;IACxB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,WAAW,EAAE,MAAM,CAAA;IAEnB,KAAK,EAAE,IAAI,CAAA;IACX,iBAAiB,EAAE,MAAM,CAAA;IACzB,WAAW,EAAE,MAAM,CAAA;IACnB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAA;IAC/B,QAAQ,EAAE,OAAO,CAAA;IACjB,eAAe,EAAE,OAAO,CAAA;IACxB,oBAAoB,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACpC,qBAAqB,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACrC,GAAG,EAAE,MAAM,CAAA;IAGX,iBAAiB,EAAE,IAAI,CAAA;IACvB,kBAAkB,EAAE,IAAI,CAAA;IACxB,SAAS,EAAE,IAAI,CAAA;IACf,SAAS,EAAE,IAAI,CAAA;IACf,UAAU,EAAE,IAAI,CAAA;IAChB,UAAU,EAAE,IAAI,CAAA;IAChB,SAAS,EAAE,KAAK,CAAC,GAAG,CAAC,CAAA;IACrB,WAAW,EAAE,MAAM,CAAA;IACnB,mBAAmB,EAAE,MAAM,CAAA;CAC5B;AAED,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,KAAK,CAAC,cAAc,CAAC,CAAA;IAC3B,YAAY,EAAE,MAAM,CAAA;IACpB,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,6BAA6B;IAC5C,WAAW,EAAE,MAAM,CAAA;IACnB,iBAAiB,EAAE,MAAM,CAAA;IACzB,OAAO,EAAE,MAAM,CAAA;CAChB"} \ No newline at end of file diff --git a/dist/Transfer.d.ts.map b/dist/Transfer.d.ts.map index 50d9af3..d92768c 100644 --- a/dist/Transfer.d.ts.map +++ b/dist/Transfer.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"Transfer.d.ts","sourceRoot":"","sources":["../src/Transfer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,SAAS,CAAA;AAC3B,OAAO,GAAG,MAAM,aAAa,CAAA;AAC7B,OAAO,KAAK,EAAE,sBAAsB,EAAE,SAAS,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAA;A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,sBAAsB,CAAA;AAGnH,MAAM,CAAC,OAAO,OAAO,QAAS,SAAQ,KAAK,CAAC,QAAQ,EAAE,SAAS,CAAE,YAAW,SAAS;IAC5E,YAAY,EAAE,MAAM,CAAA;IACpB,WAAW,EAAE,MAAM,CAAA;IACnB,WAAW,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,EAAE,MAAM,CAAA;IAClB,YAAY,EAAE,MAAM,CAAA;IACpB,YAAY,EAAE,MAAM,CAAA;IACpB,SAAS,EAAE,MAAM,CAAA;IACjB,aAAa,EAAE,MAAM,CAAA;IACrB,IAAI,EAAE,aAAa,CAAA;IACnB,EAAE,EAAE,MAAM,CAAA;IACV,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;IACb,gBAAgB,EAAE,MAAM,CAAA;IACxB,cAAc,EAAE,MAAM,CAAA;IACtB,kBAAkB,EAAE,MAAM,CAAA;IAC1B,MAAM,EAAE,MAAM,CAAA;IACd,YAAY,EAAE,MAAM,CAAA;IACpB,cAAc,EAAE,MAAM,CAAA;IACtB,MAAM,EAAE,MAAM,CAAA;IACd,eAAe,EAAE,KAAK,CAAC,sBAAsB,CAAC,CAAA;IAC9C,SAAS,EAAE,MAAM,CAAA;WAEV,kBAAkB,CAAC,MAAM,EAAE,qBAAqB;WAK1C,MAAM,CAAC,MAAM,EAAE,qBAAqB,EAAE,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,QAAQ,CAAC;IAmBzE,OAAO;CAIrB"} \ No newline at end of file diff --git a/dist/Transfer.js b/dist/Transfer.js index 6820e61..86030df 100644 --- a/dist/Transfer.js +++ b/dist/Transfer.js @@ -50,6 +50,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) { }; Object.defineProperty(exports, "__esModule", { value: true }); var Model_1 = require("./Model"); +var PaymentMethod_1 = require("./PaymentMethod"); var Transfer = (function (_super) { __extends(Transfer, _super); function Transfer() { @@ -61,14 +62,25 @@ var Transfer = (function (_super) { }; Transfer.create = function (params, api) { return __awaiter(this, void 0, void 0, function () { - var data; + var paymentMethods, isACH, data; return __generator(this, function (_a) { switch (_a.label) { case 0: api.requireAuthed(); this.verifyCreateParams(params); - return [4, api.post('transfers', params)]; + if (!(params.source instanceof PaymentMethod_1.default && params.source.linkType === 'LOCAL_TRANSFER')) return [3, 1]; + params.source = params.source.srn + ":ach"; + return [3, 3]; case 1: + if (!(typeof params.source === 'string' && /paymentmethod:/.test(params.source))) return [3, 3]; + return [4, PaymentMethod_1.default.fetchAll(api)]; + case 2: + paymentMethods = _a.sent(); + isACH = paymentMethods.some(function (method) { return method.srn === params.source && method.linkType === 'LOCAL_TRANSFER'; }); + params.source += ':ach'; + _a.label = 3; + case 3: return [4, api.post('transfers', params)]; + case 4: data = _a.sent(); return [2, new Transfer(data, api)]; } diff --git a/dist/Transfer/ITransfer.d.ts b/dist/Transfer/ITransfer.d.ts index da35857..9c243d4 100644 --- a/dist/Transfer/ITransfer.d.ts +++ b/dist/Transfer/ITransfer.d.ts @@ -1,3 +1,4 @@ +import PaymentMethod from '../PaymentMethod'; export interface ITransfer { id: string; sourceAmount: number; @@ -38,10 +39,10 @@ export interface ITransferStatusHistory { failedState: boolean; } export interface ICreateTransferParams { - source: string; + source: string | PaymentMethod; sourceCurrency: string; sourceAmount?: string; - destination: string; + destination: string | PaymentMethod; destinationCurrency: string; destinationAmount?: string; message?: string; diff --git a/dist/Transfer/ITransfer.d.ts.map b/dist/Transfer/ITransfer.d.ts.map index ffeaa1b..51adda5 100644 --- a/dist/Transfer/ITransfer.d.ts.map +++ b/dist/Transfer/ITransfer.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"ITransfer.d.ts","sourceRoot":"","sources":["../../src/Transfer/ITransfer.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,CAAA;IACV,YAA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MAAM,CAAA;IAC3B,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB;AAED,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,KAAK,CAAC,SAAS,CAAC,CAAA;IACtB,QAAQ,EAAE,MAAM,CAAA;IAChB,YAAY,EAAE,MAAM,CAAA;IACpB,eAAe,EAAE,MAAM,CAAA;CACxB"} \ No newline at end of file +{"version":3,"file":"ITransfer.d.ts","sourceRoot":"","sources":["../../src/Transfer/ITransfer.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,kBAAkB,CAAA;AAE5C,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,CAAA;IACV,YAAY,EAAE,MAAM,CAAA;IACpB,cAAc,EAAE,MAAM,CAAA;IACtB,UAAU,EAAE,MAAM,CAAA;IAClB,YAAY,EAAE,MAAM,CAAA;IACpB,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;IAChB,YAAY,EAAE,MAAM,CAAA;IACpB,SAAS,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,aAAa,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;IACjB,WAAW,EAAE,MAAM,CAAA;IACnB,WAAW,EAAE,MAAM,CAAA;IACnB,aAAa,EAAE,MAAM,CAAA;IACrB,SAAS,EAAE,MAAM,CAAA;IACjB,kBAAkB,EAAE,MAAM,CAAA;IAC1B,cAAc,EAAE,MAAM,CAAA;IACtB,gBAAgB,EAAE,MAAM,CAAA;IACxB,IAAI,EAA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PaymentMethod.ts index b72bb00..65d78ac 100644 --- a/src/PaymentMethod.ts +++ b/src/PaymentMethod.ts @@ -36,6 +36,18 @@ export default class PaymentMethod extends Model public supportsPayment: boolean public waitingPrompts: Array + public static async createACH(api: Api, publicToken: string): Promise { + api.requireAuthed() + + const body = { + publicToken, + paymentMethodType: 'LOCAL_TRANSFER', + country: 'US' + } + const data = await api.post('paymentMethods', body, { version: '2' }) + return new PaymentMethod(data, api) + } + public static async fetchAll(api: Api): Promise> { api.requireAuthed() diff --git a/src/PaymentMethod/IPaymentMethod.ts b/src/PaymentMethod/IPaymentMethod.ts index b30fa73..39dcaba 100644 --- a/src/PaymentMethod/IPaymentMethod.ts +++ b/src/PaymentMethod/IPaymentMethod.ts @@ -42,3 +42,9 @@ export interface IPaymentMethodsResponse { recordsTotal: number position: number } + +export interface IPaymentMethodACHCreateParams { + publicToken: string + paymentMethodType: string + country: string +} \ No newline at end of file diff --git a/src/Transfer.ts b/src/Transfer.ts index 78b58b5..276fd3b 100644 --- a/src/Transfer.ts +++ b/src/Transfer.ts @@ -1,6 +1,7 @@ import Model from './Model' import Api from './utils/Api' import type { ITransferStatusHistory, ITransfer, ITransferFees, ICreateTransferParams } from './Transfer/ITransfer' +import PaymentMethod from './PaymentMethod' export default class Transfer extends Model implements ITransfer { public blockchainTx: string @@ -38,6 +39,15 @@ export default class Transfer extends Model implements ITra this.verifyCreateParams(params) + // NOTE: Need to attach the suffix `:ach` if source is a LOCAL_TRANSFER + if (params.source instanceof PaymentMethod && params.source.linkType === 'LOCAL_TRANSFER') { + params.source = `${params.source.srn}:ach` + } else if (typeof params.source === 'string' && /paymentmethod:/.test(params.source)) { + const paymentMethods = await PaymentMethod.fetchAll(api) + const isACH = paymentMethods.some((method) => method.srn === params.source && method.linkType === 'LOCAL_TRANSFER') + params.source += ':ach' + } + const data = await api.post('transfers', params) return new Transfer(data, api) diff --git a/src/Transfer/ITransfer.ts b/src/Transfer/ITransfer.ts index bab715a..f9c76c5 100644 --- a/src/Transfer/ITransfer.ts +++ b/src/Transfer/ITransfer.ts @@ -1,3 +1,5 @@ +import PaymentMethod from '../PaymentMethod' + export interface ITransfer { id: string sourceAmount: number @@ -41,10 +43,10 @@ export interface ITransferStatusHistory { } export interface ICreateTransferParams { - source: string + source: string | PaymentMethod sourceCurrency: string sourceAmount?: string - destination: string + destination: string | PaymentMethod destinationCurrency: string destinationAmount?: string message?: string From 990802a0aa0ffb2ab356493557082b3f28fed541 Mon Sep 17 00:00:00 2001 From: Noah Passalacqua Date: Wed, 8 Apr 2020 12:22:58 -0500 Subject: [PATCH 08/20] Create wire transfer payment. --- dist/Account.d.ts | 2 +- dist/Account.d.ts.map | 2 +- dist/Account/IAccount.d.ts | 2 +- dist/Account/IAccount.d.ts.map | 2 +- dist/PaymentMethod.d.ts | 3 ++- dist/PaymentMethod.d.ts.map | 2 +- dist/PaymentMethod.js | 23 +++++++++++++++--- dist/PaymentMethod/IPaymentMethod.d.ts | 26 ++++++++++++++++++++- dist/PaymentMethod/IPaymentMethod.d.ts.map | 2 +- src/Account.ts | 4 ++-- src/Account/IAccount.ts | 2 +- src/PaymentMethod.ts | 20 +++++++++++++--- src/PaymentMethod/IPaymentMethod.ts | 27 +++++++++++++++++++++- 13 files changed, 99 insertions(+), 18 deletions(-) diff --git a/dist/Account.d.ts b/dist/Account.d.ts index bccab07..a66a4c0 100644 --- a/dist/Account.d.ts +++ b/dist/Account.d.ts @@ -7,7 +7,7 @@ import { ICreateTransferParams } from './Transfer/ITransfer'; export default class Account extends Model implements IAccount { id: string; status: 'OPEN' | 'PENDING' | 'APPROVED'; - type: string; + type: 'INDIVIDUAL' | 'BUSINESS'; country: string; createdAt: number; depositAddresses: { diff --git a/dist/Account.d.ts.map b/dist/Account.d.ts.map index 16a2b10..a252e1a 100644 --- a/dist/Account.d.ts.map +++ b/dist/Account.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"Account.d.ts","sourceRoot":"","sources":["../src/Account.ts"],"names":[],"mappings":"AAAA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GAAG,EAAE,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,OAAO,CAAC;WAShE,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;qBAM1C,SAAS,CAAC,IAAI,EAAE,gBAAgB,EAAE,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC;IAKvE,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAMrB,cAAc,CAAC,MAAM,EAAE,qBAAqB,GAAG,OAAO,CAAC,QAAQ,CAAC;IAMhE,cAAc,IAAI,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;CAIxD"} \ No newline at end of file diff --git a/dist/Account/IAccount.d.ts b/dist/Account/IAccount.d.ts index f217f58..20885e9 100644 --- a/dist/Account/IAccount.d.ts +++ b/dist/Account/IAccount.d.ts @@ -5,7 +5,7 @@ export interface IAccount extends IAccountResponse { export interface IAccountResponse { id: string; status: 'OPEN' | 'PENDING' | 'APPROVED'; - type: string; + type: 'INDIVIDUAL' | 'BUSINESS'; country: string; createdAt: number; depositAddresses: { diff --git a/dist/Account/IAccount.d.ts.map b/dist/Account/IAccount.d.ts.map index b59d8ec..bccd5e8 100644 --- a/dist/Account/IAccount.d.ts.map +++ b/dist/Account/IAccount.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"IAccount.d.ts","sourceRoot":"","sources":["../../src/Account/IAccount.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAA;AAErE,MAAM,WAAW,QAAS,SAAQ,gBAAgB;IAChD,cAAc,EAAE,KAAK,CAAC,cAAc,CAAC,CAAA;CACtC;AACD,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,UAAU,CAAA;IACvC,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CA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MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,aAAa,EAAE,KAAK,CAAC,aAAa,CAAC,CAAA;IACnC,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB"} \ No newline at end of file +{"version":3,"file":"IAccount.d.ts","sourceRoot":"","sources":["../../src/Account/IAccount.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAA;AAErE,MAAM,WAAW,QAAS,SAAQ,gBAAgB;IAChD,cAAc,EAAE,KAAK,CAAC,cAAc,CAAC,CAAA;CACtC;AACD,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,UAAU,CAAA;IACvC,IAAI,EAAE,YAAY,GAAG,UAAU,CAAA;IAC/B,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;IACjB,gBAAgB,EAAE;QAChB,GAAG,EAAE,MAAM,CAAA;QACX,GAAG,EAAE,MAAM,CAAA;KACZ,CAAA;IACD,aAAa,EAAE;QACb,GAAG,EAAE,MAAM,CAAA;QACX,GAAG,EAAE,MAAM,CAAA;KACZ,CAAA;IACD,iBAAiB,EAAE;QACjB,GAAG,EAAE,MAAM,CAAA;QACX,GAAG,EAAE,MAAM,CAAA;KACZ,CAAA;IACD,aAAa,EAAE,KAAK,CAAC,aAAa,CAAC,CAAA;CACpC;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,eAAe,CAAA;IACxB,SAAS,EAAE,iBAAiB,CAAA;IAC5B,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,yBAAyB,GAAG,KAAK,CAAC,0BAA0B,CAAC,GAAG,IAAI,CAAA;IAC7F,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;IACnB,MAAM,EAAE,mBAAmB,CAAA;CAC5B;AACD,aAAK,eAAe,GAAG,2BAA2B,GAAG,iBAAiB,GAAG,qBAAqB,GAAG,uBAAuB,GAAG,eAAe,GAAG,4BAA4B,GAAG,wBAAwB,GAAG,yBAAyB,CAAA;AAChO,aAAK,iBAAiB,GAAG,WAAW,GAAG,OAAO,GAAG,QAAQ,GAAG,MAAM,GAAG,SAAS,GAAG,UAAU,GAAG,gBAAgB,CAAA;AAC9G,aAAK,yBAAyB,GAAG;IAC/B,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;IACb,UAAU,EAAE,MAAM,CAAA;IAClB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;CACvB,CAAA;AAED,aAAK,0BAA0B,GAAG,EAEjC,CAAA;AACD,aAAK,mBAAmB,GAAG,MAAM,GAAG,SAAS,GAAG,UAAU,GAAG,MAAM,CAAA;AAEnE,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,aAAa,EAAE,KAAK,CAAC,aAAa,CAAC,CAAA;IACnC,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB"} \ No newline at end of file diff --git a/dist/PaymentMethod.d.ts b/dist/PaymentMethod.d.ts index 110f367..3313573 100644 --- a/dist/PaymentMethod.d.ts +++ b/dist/PaymentMethod.d.ts @@ -1,5 +1,5 @@ import Model from './Model'; -import type { IPaymentMethod } from './PaymentMethod/IPaymentMethod'; +import type { IPaymentMethod, IPaymentMethodWireCreateParams } from './PaymentMethod/IPaymentMethod'; import Api from './utils/Api'; export default class PaymentMethod extends Model implements IPaymentMethod { beneficiaryType: string; @@ -35,6 +35,7 @@ export default class PaymentMethod extends Model supportsPayment: boolean; waitingPrompts: Array; static createACH(api: Api, publicToken: string): Promise; + static createWire(api: Api, params: IPaymentMethodWireCreateParams): Promise; static fetchAll(api: Api): Promise>; } //# sourceMappingURL=PaymentMethod.d.ts.map \ No newline at end of file diff --git a/dist/PaymentMethod.d.ts.map b/dist/PaymentMethod.d.ts.map index c332d8d..77a0c61 100644 --- a/dist/PaymentMethod.d.ts.map +++ b/dist/PaymentMethod.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"PaymentMethod.d.ts","sourceRoot":"","sources":["../src/PaymentMethod.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,SAAS,CAAA;AAC3B,OAAO,KAAK,EAAE,cAAc,EAA2B,MAAM,gCAAgC,CAAA;AAC7F,OAAO,GAAG,MAAM,aAAa,CAAA;AAE7B,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,KAAK,CAAC,aAAa,EAAE,cAAc,CAAE,YAAW,cAAc;IAChG,eAAe,EAAE,MAAM,CAAA;IACvB,WAAW,EAAE,MAAM,CAAA;IACnB,KAAK,EAAE,IAAI,CAAA;IACX,iBAAiB,EAAE,IAAI,CAAA;IACvB,oBAAoB,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;IACnC,WAAW,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;IACjB,eAAe,EAAE,MAAM,CAAA;IACvB,kBAAkB,EAAE,IAAI,CAAA;IACxB,qBAAqB,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;IACpC,QAAQ,EAAE,OAAO,CAAA;IACjB,SAAS,EAAE,KAAK,CAAC,GAAG,CAAC,CAAA;IACrB,iBAAiB,EAAE,MAAM,CAAA;IACzB,EAAE,EAAE,MAAM,CAAA;IACV,WAAW,EAAE,MAAM,CAAA;IACnB,QAAQ,EAAE,wBAAwB,GAAG,gBAAgB,CAAA;IACrD,mBAAmB,EAAE,MAAM,CAAA;IAC3B,SAAS,EAAE,IAAI,CAA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ff --git a/dist/PaymentMethod.js b/dist/PaymentMethod.js index 85d303f..2046e15 100644 --- a/dist/PaymentMethod.js +++ b/dist/PaymentMethod.js @@ -57,17 +57,34 @@ var PaymentMethod = (function (_super) { } PaymentMethod.createACH = function (api, publicToken) { return __awaiter(this, void 0, void 0, function () { - var body, data; + var params, data; return __generator(this, function (_a) { switch (_a.label) { case 0: api.requireAuthed(); - body = { + params = { publicToken: publicToken, paymentMethodType: 'LOCAL_TRANSFER', country: 'US' }; - return [4, api.post('paymentMethods', body, { version: '2' })]; + return [4, api.post('paymentMethods', params, { version: '2' })]; + case 1: + data = _a.sent(); + return [2, new PaymentMethod(data, api)]; + } + }); + }); + }; + PaymentMethod.createWire = function (api, params) { + return __awaiter(this, void 0, void 0, function () { + var data; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + api.requireAuthed(); + params.paymentMethodType = 'INTERNATIONAL_TRANSFER'; + params.paymentType = 'LOCAL_BANK_WIRE'; + return [4, api.post('paymentMethods', params, { version: '2' })]; case 1: data = _a.sent(); return [2, new PaymentMethod(data, api)]; diff --git a/dist/PaymentMethod/IPaymentMethod.d.ts b/dist/PaymentMethod/IPaymentMethod.d.ts index 641f531..5d6251a 100644 --- a/dist/PaymentMethod/IPaymentMethod.d.ts +++ b/dist/PaymentMethod/IPaymentMethod.d.ts @@ -39,7 +39,31 @@ export interface IPaymentMethodsResponse { } export interface IPaymentMethodACHCreateParams { publicToken: string; - paymentMethodType: string; + paymentMethodType: 'LOCAL_TRANSFER'; + country: 'US'; +} +export interface IPaymentMethodWireCreateParams extends IPaymentMethodWireCreateParamsInternal { country: string; + currency: string; + beneficiaryType: 'INDIVIDUAL' | 'BUSINESS'; + beneficiaryAddress: string; + beneficiaryAddress2?: string; + beneficiaryCity: string; + beneficiaryState: string; + beneficiaryPostal: string; + beneficiaryPhoneNumber: string; + beneficiaryDobDay: string; + beneficiaryDobMonth: string; + beneficiaryDobYear: string; + firstNameOnAccount: string; + lastNameOnAccount: string; + accountNumber: string; + routingNumber: string; + accountType: 'CHECKING' | 'SAVINGS'; + chargeablePM: boolean; +} +export interface IPaymentMethodWireCreateParamsInternal { + paymentMethodType: 'INTERNATIONAL_TRANSFER'; + paymentType: 'LOCAL_BANK_WIRE'; } //# sourceMappingURL=IPaymentMethod.d.ts.map \ No newline at end of file diff --git a/dist/PaymentMethod/IPaymentMethod.d.ts.map b/dist/PaymentMethod/IPaymentMethod.d.ts.map index 0d17e5f..683e3d5 100644 --- a/dist/PaymentMethod/IPaymentMethod.d.ts.map +++ b/dist/PaymentMethod/IPaymentMethod.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"IPaymentMethod.d.ts","sourceRoot":"","sources":["../../src/PaymentMethod/IPaymentMethod.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,MAAM,CAAA;IACb,SAAS,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,MAAM,CAAA;IACZ,eAAe,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,SAAS,GAAG,mBAAmB,GAAG,QAAQ,GAAG,UAAU,CAAA;IAC/D,aAAa,EAAE,MAAM,CAAA;IAErB,cAAc,EAAE,KAAK,CAAC,GAAG,CAAC,CAAA;IAC1B,QAAQ,EAAE,wBAAwB,GAAG,gBAAgB,CAAA;IACrD,eAAe,EAAE,MAAM,CAAA;IACvB,eAAe,EAAE,OAAO,CAAA;IACxB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,WAAW,EAAE,MAAM,CAAA;IAEnB,KAAK,EAAE,IAAI,CAAA;IACX,iBAAiB,EAAE,MAAM,CAAA;IACzB,WAAW,EAAE,MAAM,CAAA;IACnB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAA;IAC/B,QAAQ,EAAE,OAAO,CAAA;IACjB,eAAe,EAAE,OAAO,CAAA;IACxB,oBAAoB,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACpC,qBAAqB,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACrC,GAAG,EAAE,MAAM,CAAA;IAGX,iBAAiB,EAAE,IAAI,CAAA;IACvB,kBAAkB,EAAE,IAAI,CAAA;IACxB,SAAS,EAAE,IAAI,CAAA;IACf,SAAS,EAAE,IAAI,CAAA;IACf,UAAU,EAAE,IAAI,CAAA;IAChB,UAAU,EAAE,IAAI,CAAA;IAChB,SAAS,EAAE,KAAK,CAAC,GAAG,CAAC,CAAA;IACrB,WAAW,EAAE,MAAM,CAAA;IACnB,mBAAmB,EAAE,MAAM,CAAA;CAC5B;AAED,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,KAAK,CAAC,cAAc,CAAC,CAAA;IAC3B,YAAY,EAAE,MAAM,CAAA;IACpB,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,6BAA6B;IAC5C,WAAW,EAAE,MAAM,CAAA;IACnB,iBAAiB,EAAE,MAAM,CAAA;IACzB,OAAO,EAAE,MAAM,CAAA;CAChB"} \ No newline at end of file +{"version":3,"file":"IPaymentMethod.d.ts","sourceRoot":"","sources":["../../src/PaymentMethod/IPaymentMethod.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,MAAM,CAAA;IACb,SAAS,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,MAAM,CAAA;IACZ,eAAe,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,SAAS,GAAG,mBAAmB,GAAG,QAAQ,GAAG,UAAU,CAAA;IAC/D,aAAa,EAAE,MAAM,CAAA;IAErB,cAAc,EAAE,KAAK,CAAC,GAAG,CAAC,CAAA;IAC1B,QAAQ,EAAE,wBAAwB,GAAG,gBAAgB,CAAA;IACrD,eAAe,EAAE,MAAM,CAAA;IACvB,eAAe,EAAE,OAAO,CAAA;IACxB,YAAY,EAAE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AAG,MAAM,CAAA;IACxB,gBAAgB,EAAG,MAAM,CAAA;IACzB,iBAAiB,EAAG,MAAM,CAAA;IAC1B,sBAAsB,EAAG,MAAM,CAAA;IAC/B,iBAAiB,EAAG,MAAM,CAAA;IAC1B,mBAAmB,EAAE,MAAM,CAAA;IAC3B,kBAAkB,EAAE,MAAM,CAAA;IAC1B,kBAAkB,EAAG,MAAM,CAAA;IAC3B,iBAAiB,EAAE,MAAM,CAAA;IACzB,aAAa,EAAE,MAAM,CAAA;IACrB,aAAa,EAAE,MAAM,CAAA;IACrB,WAAW,EAAE,UAAU,GAAG,SAAS,CAAA;IACnC,YAAY,EAAE,OAAO,CAAA;CACtB;AACD,MAAM,WAAW,sCAAsC;IACrD,iBAAiB,EAAE,wBAAwB,CAAA;IAC3C,WAAW,EAAE,iBAAiB,CAAA;CAC/B"} \ No newline at end of file diff --git a/src/Account.ts b/src/Account.ts index b2a56c8..4863593 100644 --- a/src/Account.ts +++ b/src/Account.ts @@ -1,6 +1,6 @@ import Model from './Model' import Transfer from './Transfer' -import PaymentMethod from './PaymentMethod' +import PaymentMethod, { PAYMENT_TYPE } from './PaymentMethod' import Api from './utils/Api' import { IAccount, IAccountResponse, ICreateAccountParams, IProfileField } from './Account/IAccount' import { ICreateTransferParams, ITransferHistoryResponse } from './Transfer/ITransfer' @@ -8,7 +8,7 @@ import { ICreateTransferParams, ITransferHistoryResponse } from './Transfer/ITra export default class Account extends Model implements IAccount { public id: string public status: 'OPEN' | 'PENDING' | 'APPROVED' - public type: string + public type: 'INDIVIDUAL' | 'BUSINESS' public country: string public createdAt: number public depositAddresses: { ETH: string; BTC: string } diff --git a/src/Account/IAccount.ts b/src/Account/IAccount.ts index 6a5b436..4545c98 100644 --- a/src/Account/IAccount.ts +++ b/src/Account/IAccount.ts @@ -6,7 +6,7 @@ export interface IAccount extends IAccountResponse { export interface IAccountResponse { id: string status: 'OPEN' | 'PENDING' | 'APPROVED' - type: string + type: 'INDIVIDUAL' | 'BUSINESS' country: string createdAt: number depositAddresses: { diff --git a/src/PaymentMethod.ts b/src/PaymentMethod.ts index 65d78ac..28eb2df 100644 --- a/src/PaymentMethod.ts +++ b/src/PaymentMethod.ts @@ -1,5 +1,9 @@ import Model from './Model' -import type { IPaymentMethod, IPaymentMethodsResponse } from './PaymentMethod/IPaymentMethod' +import type { + IPaymentMethod, + IPaymentMethodACHCreateParams, + IPaymentMethodsResponse, IPaymentMethodWireCreateParams +} from './PaymentMethod/IPaymentMethod' import Api from './utils/Api' export default class PaymentMethod extends Model implements IPaymentMethod { @@ -39,12 +43,22 @@ export default class PaymentMethod extends Model public static async createACH(api: Api, publicToken: string): Promise { api.requireAuthed() - const body = { + const params: IPaymentMethodACHCreateParams = { publicToken, paymentMethodType: 'LOCAL_TRANSFER', country: 'US' } - const data = await api.post('paymentMethods', body, { version: '2' }) + const data = await api.post('paymentMethods', params, { version: '2' }) + return new PaymentMethod(data, api) + } + + public static async createWire(api: Api, params: IPaymentMethodWireCreateParams): Promise { + api.requireAuthed() + + params.paymentMethodType = 'INTERNATIONAL_TRANSFER' + params.paymentType = 'LOCAL_BANK_WIRE' + + const data = await api.post('paymentMethods', params, { version: '2' }) return new PaymentMethod(data, api) } diff --git a/src/PaymentMethod/IPaymentMethod.ts b/src/PaymentMethod/IPaymentMethod.ts index 39dcaba..944a67f 100644 --- a/src/PaymentMethod/IPaymentMethod.ts +++ b/src/PaymentMethod/IPaymentMethod.ts @@ -45,6 +45,31 @@ export interface IPaymentMethodsResponse { export interface IPaymentMethodACHCreateParams { publicToken: string - paymentMethodType: string + paymentMethodType: 'LOCAL_TRANSFER' + country: 'US' +} + +export interface IPaymentMethodWireCreateParams extends IPaymentMethodWireCreateParamsInternal { country: string + currency: string + beneficiaryType: 'INDIVIDUAL' | 'BUSINESS' + beneficiaryAddress: string + beneficiaryAddress2?: string + beneficiaryCity: string + beneficiaryState: string + beneficiaryPostal: string + beneficiaryPhoneNumber: string + beneficiaryDobDay: string + beneficiaryDobMonth: string + beneficiaryDobYear: string + firstNameOnAccount: string + lastNameOnAccount: string + accountNumber: string + routingNumber: string + accountType: 'CHECKING' | 'SAVINGS' + chargeablePM: boolean +} +export interface IPaymentMethodWireCreateParamsInternal { + paymentMethodType: 'INTERNATIONAL_TRANSFER' + paymentType: 'LOCAL_BANK_WIRE' } \ No newline at end of file From 2fd584e2408bd338b1c44f9b8653116fbb221fd2 Mon Sep 17 00:00:00 2001 From: Noah Passalacqua Date: Wed, 8 Apr 2020 12:30:27 -0500 Subject: [PATCH 09/20] Fetch and delete payment method. --- dist/PaymentMethod.d.ts | 2 ++ dist/PaymentMethod.d.ts.map | 2 +- dist/PaymentMethod.js | 27 +++++++++++++++++++++++++++ src/PaymentMethod.ts | 11 +++++++++++ 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/dist/PaymentMethod.d.ts b/dist/PaymentMethod.d.ts index 3313573..c618518 100644 --- a/dist/PaymentMethod.d.ts +++ b/dist/PaymentMethod.d.ts @@ -37,5 +37,7 @@ export default class PaymentMethod extends Model static createACH(api: Api, publicToken: string): Promise; static createWire(api: Api, params: IPaymentMethodWireCreateParams): Promise; static fetchAll(api: Api): Promise>; + static fetch(api: Api, id: string): Promise; + delete(): Promise; } //# sourceMappingURL=PaymentMethod.d.ts.map \ No newline at end of file diff --git a/dist/PaymentMethod.d.ts.map b/dist/PaymentMethod.d.ts.map index 77a0c61..b0fedbb 100644 --- a/dist/PaymentMethod.d.ts.map +++ b/dist/PaymentMethod.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"PaymentMethod.d.ts","sourceRoot":"","sources":["../src/PaymentMethod.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,SAAS,CAAA;AAC3B,OAAO,KAAK,EACV,cAAc,EAEW,8BAA8B,EACxD,MAAM,gCAAgC,CAAA;AACvC,OAAO,GAAG,MAAM,aAAa,CAAA;AAE7B,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,KAAK,CAAC,aAAa,EAAE,cAAc,CAA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,IAAI,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,YAAY,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,KAAK,EAAE,MAAM,CAAA;IACb,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAA;IAC/B,GAAG,EAAE,MAAM,CAAA;IACX,MAAM,EAAE,SAAS,GAAG,mBAAmB,GAAG,QAAQ,GAAG,UAAU,CAAA;IAC/D,aAAa,EAAE,MAAM,CAAA;IACrB,eAAe,EAAE,OAAO,CAAA;IACxB,eAAe,EAAE,OAAO,CAAA;IACxB,cAAc,EAAE,KAAK,CAAC,GAAG,CAAC,CAAA;WAEb,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;WAYhE,UAAU,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,8BAA8B,GAAG,OAAO,CAAC,aAAa,CAAC;WAUpF,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;WASjD,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAO1D,MAAM;CAGpB"} \ No newline at end of file diff --git a/dist/PaymentMethod.js b/dist/PaymentMethod.js index 2046e15..a73f8a2 100644 --- a/dist/PaymentMethod.js +++ b/dist/PaymentMethod.js @@ -109,6 +109,33 @@ var PaymentMethod = (function (_super) { }); }); }; + PaymentMethod.fetch = function (api, id) { + return __awaiter(this, void 0, void 0, function () { + var data; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + api.requireAuthed(); + return [4, api.get("paymentMethod/" + id, null, { version: '2' })]; + case 1: + data = _a.sent(); + return [2, new PaymentMethod(data, api)]; + } + }); + }); + }; + PaymentMethod.prototype.delete = function () { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4, this.api.delete("paymentMethod/" + this.id, null, { version: '2' })]; + case 1: + _a.sent(); + return [2]; + } + }); + }); + }; return PaymentMethod; }(Model_1.default)); exports.default = PaymentMethod; diff --git a/src/PaymentMethod.ts b/src/PaymentMethod.ts index 28eb2df..791783f 100644 --- a/src/PaymentMethod.ts +++ b/src/PaymentMethod.ts @@ -70,4 +70,15 @@ export default class PaymentMethod extends Model }) return paymentMethods.map((paymentData) => new PaymentMethod(paymentData, api)) } + + public static async fetch(api: Api, id: string): Promise { + api.requireAuthed() + + const data = await api.get(`paymentMethod/${id}`, null, { version: '2' }) + return new PaymentMethod(data, api) + } + + public async delete() { + await this.api.delete(`paymentMethod/${this.id}`, null, { version: '2' }) + } } \ No newline at end of file From 7704ef3cf90b5b8e060558d15848c6bbaab94989 Mon Sep 17 00:00:00 2001 From: Noah Passalacqua Date: Wed, 8 Apr 2020 12:41:06 -0500 Subject: [PATCH 10/20] Attach blockchain to payment method. --- dist/PaymentMethod.d.ts | 3 ++- dist/PaymentMethod.d.ts.map | 2 +- dist/PaymentMethod.js | 28 ++++++++++++++++++++++ dist/PaymentMethod/IPaymentMethod.d.ts | 5 ++++ dist/PaymentMethod/IPaymentMethod.d.ts.map | 2 +- src/PaymentMethod.ts | 11 ++++++++- src/PaymentMethod/IPaymentMethod.ts | 6 +++++ 7 files changed, 53 insertions(+), 4 deletions(-) diff --git a/dist/PaymentMethod.d.ts b/dist/PaymentMethod.d.ts index c618518..cb58701 100644 --- a/dist/PaymentMethod.d.ts +++ b/dist/PaymentMethod.d.ts @@ -1,5 +1,5 @@ import Model from './Model'; -import type { IPaymentMethod, IPaymentMethodWireCreateParams } from './PaymentMethod/IPaymentMethod'; +import type { IPaymentMethod, IPaymentMethodAttachBlockchainOptions, IPaymentMethodBlockchain, IPaymentMethodWireCreateParams } from './PaymentMethod/IPaymentMethod'; import Api from './utils/Api'; export default class PaymentMethod extends Model implements IPaymentMethod { beneficiaryType: string; @@ -38,6 +38,7 @@ export default class PaymentMethod extends Model static createWire(api: Api, params: IPaymentMethodWireCreateParams): Promise; static fetchAll(api: Api): Promise>; static fetch(api: Api, id: string): Promise; + attachBlockchain(blockchain: IPaymentMethodBlockchain | Array, opts?: IPaymentMethodAttachBlockchainOptions): Promise; delete(): Promise; } //# sourceMappingURL=PaymentMethod.d.ts.map \ No newline at end of file diff --git a/dist/PaymentMethod.d.ts.map b/dist/PaymentMethod.d.ts.map index b0fedbb..e9b5ba8 100644 --- a/dist/PaymentMethod.d.ts.map +++ b/dist/PaymentMethod.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"PaymentMethod.d.ts","sourceRoot":"","sources":["../src/PaymentMethod.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,SAAS,CAAA;AAC3B,OAAO,KAAK,EACV,cAAc,EAEW,8BAA8B,EACxD,MAAM,gCAAgC,CAAA;AACvC,OAAO,GAAG,MAAM,aAAa,CAAA;AAE7B,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,KAAK,CAAC,aAAa,EAAE,cAAc,CAAE,YAAW,cAAc;IAChG,eAAe,EAAE,MAAM,CAAA;IACvB,WAAW,EAAE,MAAM,CAAA;IACnB,KAAK,EAAE,IAAI,CAAA;IACX,iBAAiB,EAAE,IAAI,CAAA;IACvB,oBAAoB,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;IACnC,WAAW,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;IACjB,eAAe,EAAE,MAAM,CAAA;IACvB,kBAAkB,EAAE,IAAI,CAAA;IACxB,qBAAqB,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;IACpC,QAAQ,EAAE,OAAO,CAAA;IACjB,SAAS,EAAE,KAAK,CAAC,GAAG,CAAC,CAAA;IACrB,iBAAiB,EAAE,MAAM,CAAA;IACzB,EAAE,EAAE,MAAM,CAAA;IACV,WAAW,EAAE,MAAM,CAAA;IACnB,QAAQ,EAAE,wBAAwB,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AAG,CAAC,CAAA;WAEb,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;WAYhE,UAAU,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,8BAA8B,GAAG,OAAO,CAAC,aAAa,CAAC;WAUpF,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;WASjD,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAO1D,gBAAgB,CAAC,UAAU,EAAE,wBAAwB,GAAG,KAAK,CAAC,wBAAwB,CAAC,EAAE,IAAI,GAAE,qCAA0C;IASzI,MAAM;CAGpB"} \ No newline at end of file diff --git a/dist/PaymentMethod.js b/dist/PaymentMethod.js index a73f8a2..77f1ddb 100644 --- a/dist/PaymentMethod.js +++ b/dist/PaymentMethod.js @@ -12,6 +12,17 @@ var __extends = (this && this.__extends) || (function () { d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { @@ -124,6 +135,23 @@ var PaymentMethod = (function (_super) { }); }); }; + PaymentMethod.prototype.attachBlockchain = function (blockchain, opts) { + if (opts === void 0) { opts = {}; } + return __awaiter(this, void 0, void 0, function () { + var params, data; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + params = __assign(__assign({}, opts), { blockchain: Array.isArray(blockchain) ? blockchain.join(',') : blockchain }); + return [4, this.api.get("paymentMethod/" + this.id + "/attach", params, { version: '2' })]; + case 1: + data = _a.sent(); + this.set(data); + return [2]; + } + }); + }); + }; PaymentMethod.prototype.delete = function () { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { diff --git a/dist/PaymentMethod/IPaymentMethod.d.ts b/dist/PaymentMethod/IPaymentMethod.d.ts index 5d6251a..93769d1 100644 --- a/dist/PaymentMethod/IPaymentMethod.d.ts +++ b/dist/PaymentMethod/IPaymentMethod.d.ts @@ -66,4 +66,9 @@ export interface IPaymentMethodWireCreateParamsInternal { paymentMethodType: 'INTERNATIONAL_TRANSFER'; paymentType: 'LOCAL_BANK_WIRE'; } +export declare type IPaymentMethodBlockchain = 'BTC' | 'ETH' | 'ALL'; +export interface IPaymentMethodAttachBlockchainOptions { + notifyUrl?: string; + muteMessages?: boolean; +} //# sourceMappingURL=IPaymentMethod.d.ts.map \ No newline at end of file diff --git a/dist/PaymentMethod/IPaymentMethod.d.ts.map b/dist/PaymentMethod/IPaymentMethod.d.ts.map index 683e3d5..930f597 100644 --- a/dist/PaymentMethod/IPaymentMethod.d.ts.map +++ b/dist/PaymentMethod/IPaymentMethod.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"IPaymentMethod.d.ts","sourceRoot":"","sources":["../../src/PaymentMethod/IPaymentMethod.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,MAAM,CAAA;IACb,SAAS,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,MAAM,CAAA;IACZ,eAAe,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,SAAS,GAAG,mBAAmB,GAAG,QAAQ,GAAG,UAAU,CAAA;IAC/D,aAAa,EAAE,MAAM,CAAA;IAErB,cAAc,EAAE,KAAK,CAAC,GAAG,CAAC,CAAA;IAC1B,QAAQ,EAAE,wBAAwB,GAAG,gBAAgB,CAAA;IACrD,eAAe,EAAE,MAAM,CAA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CAAA;IAC/B,iBAAiB,EAAG,MAAM,CAAA;IAC1B,mBAAmB,EAAE,MAAM,CAAA;IAC3B,kBAAkB,EAAE,MAAM,CAAA;IAC1B,kBAAkB,EAAG,MAAM,CAAA;IAC3B,iBAAiB,EAAE,MAAM,CAAA;IACzB,aAAa,EAAE,MAAM,CAAA;IACrB,aAAa,EAAE,MAAM,CAAA;IACrB,WAAW,EAAE,UAAU,GAAG,SAAS,CAAA;IACnC,YAAY,EAAE,OAAO,CAAA;CACtB;AACD,MAAM,WAAW,sCAAsC;IACrD,iBAAiB,EAAE,wBAAwB,CAAA;IAC3C,WAAW,EAAE,iBAAiB,CAAA;CAC/B;AAED,oBAAY,wBAAwB,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,CAAA;AAC5D,MAAM,WAAW,qCAAqC;IACpD,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB"} \ No newline at end of file diff --git a/src/PaymentMethod.ts b/src/PaymentMethod.ts index 791783f..17f8bd0 100644 --- a/src/PaymentMethod.ts +++ b/src/PaymentMethod.ts @@ -1,7 +1,7 @@ import Model from './Model' import type { IPaymentMethod, - IPaymentMethodACHCreateParams, + IPaymentMethodACHCreateParams, IPaymentMethodAttachBlockchainOptions, IPaymentMethodBlockchain, IPaymentMethodsResponse, IPaymentMethodWireCreateParams } from './PaymentMethod/IPaymentMethod' import Api from './utils/Api' @@ -78,6 +78,15 @@ export default class PaymentMethod extends Model return new PaymentMethod(data, api) } + public async attachBlockchain(blockchain: IPaymentMethodBlockchain | Array, opts: IPaymentMethodAttachBlockchainOptions = {}) { + const params = { + ...opts, + blockchain: Array.isArray(blockchain) ? blockchain.join(',') : blockchain + } + const data = await this.api.get(`paymentMethod/${this.id}/attach`, params, { version: '2' }) + this.set(data) + } + public async delete() { await this.api.delete(`paymentMethod/${this.id}`, null, { version: '2' }) } diff --git a/src/PaymentMethod/IPaymentMethod.ts b/src/PaymentMethod/IPaymentMethod.ts index 944a67f..39457ad 100644 --- a/src/PaymentMethod/IPaymentMethod.ts +++ b/src/PaymentMethod/IPaymentMethod.ts @@ -72,4 +72,10 @@ export interface IPaymentMethodWireCreateParams extends IPaymentMethodWireCreate export interface IPaymentMethodWireCreateParamsInternal { paymentMethodType: 'INTERNATIONAL_TRANSFER' paymentType: 'LOCAL_BANK_WIRE' +} + +export type IPaymentMethodBlockchain = 'BTC' | 'ETH' | 'ALL' +export interface IPaymentMethodAttachBlockchainOptions { + notifyUrl?: string + muteMessages?: boolean } \ No newline at end of file From 44b7b90bbb17d670042d1044d7ab4831ddad625e Mon Sep 17 00:00:00 2001 From: Noah Passalacqua Date: Wed, 8 Apr 2020 12:52:18 -0500 Subject: [PATCH 11/20] Fetch transfers. --- dist/Account.d.ts.map | 2 +- dist/Account.js | 11 ++--------- dist/Transfer.d.ts | 4 +++- dist/Transfer.d.ts.map | 2 +- dist/Transfer.js | 32 +++++++++++++++++++++++++++++++- src/Account.ts | 9 ++++----- src/Transfer.ts | 24 ++++++++++++++++++++++-- 7 files changed, 64 insertions(+), 20 deletions(-) diff --git a/dist/Account.d.ts.map b/dist/Account.d.ts.map index a252e1a..3bc0f70 100644 --- a/dist/Account.d.ts.map +++ b/dist/Account.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"Account.d.ts","sourceRoot":"","sources":["../src/Account.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,SAAS,CAAA;AAC3B,OAAO,QAAQ,MAAM,YAAY,CAAA;AACjC,OAAO,aAA+B,MAAM,iBAAiB,CAAA;AAC7D,OAAO,GAAG,MAAM,aAAa,CAAA;AAC7B,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AACpG,OAAO,EAAE,qBAAqB,EAA4B,MAAM,sBAAsB,CAAA;AAEtF,MAAM,CAAC,OAAO,OAAO,OAAQ,SAAQ,KAAK,CAAC,OAAO,EAAE,QAAQ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AAC;IAMhE,cAAc,IAAI,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;CAGxD"} \ No newline at end of file diff --git a/dist/Account.js b/dist/Account.js index 3b0bbb7..e9f7fb9 100644 --- a/dist/Account.js +++ b/dist/Account.js @@ -133,7 +133,7 @@ var Account = (function (_super) { var transfer; return __generator(this, function (_a) { switch (_a.label) { - case 0: return [4, Transfer_1.default.create(params, this.api)]; + case 0: return [4, Transfer_1.default.create(this.api, params)]; case 1: transfer = _a.sent(); return [2, transfer]; @@ -143,15 +143,8 @@ var Account = (function (_super) { }; Account.prototype.fetchTransfers = function () { return __awaiter(this, void 0, void 0, function () { - var data; - var _this = this; return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4, this.api.get('transfers')]; - case 1: - data = (_a.sent()).data; - return [2, data.map(function (transferData) { return new Transfer_1.default(transferData, _this.api); })]; - } + return [2, Transfer_1.default.fetchAll(this.api)]; }); }); }; diff --git a/dist/Transfer.d.ts b/dist/Transfer.d.ts index 0649554..e1dfb47 100644 --- a/dist/Transfer.d.ts +++ b/dist/Transfer.d.ts @@ -27,7 +27,9 @@ export default class Transfer extends Model implements ITra statusHistories: Array; totalFees: number; static verifyCreateParams(params: ICreateTransferParams): void; - static create(params: ICreateTransferParams, api: Api): Promise; + static create(api: Api, params: ICreateTransferParams): Promise; + static fetchAll(api: Api): Promise>; + static fetch(api: Api, id: string): Promise; confirm(): Promise; } //# sourceMappingURL=Transfer.d.ts.map \ No newline at end of file diff --git a/dist/Transfer.d.ts.map b/dist/Transfer.d.ts.map index d92768c..ca668b1 100644 --- a/dist/Transfer.d.ts.map +++ b/dist/Transfer.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"Transfer.d.ts","sourceRoot":"","sources":["../src/Transfer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,SAAS,CAAA;AAC3B,OAAO,GAAG,MAAM,aAAa,CAAA;AAC7B,OAAO,KAAK,EAAE,sBAAsB,EAAE,SAAS,EA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AAO;CAIrB"} \ No newline at end of file diff --git a/dist/Transfer.js b/dist/Transfer.js index 86030df..7f4159f 100644 --- a/dist/Transfer.js +++ b/dist/Transfer.js @@ -60,7 +60,7 @@ var Transfer = (function (_super) { if (params.sourceAmount && params.destinationAmount) throw new Error('Cannot have both source and destination amounts defined.'); }; - Transfer.create = function (params, api) { + Transfer.create = function (api, params) { return __awaiter(this, void 0, void 0, function () { var paymentMethods, isACH, data; return __generator(this, function (_a) { @@ -87,6 +87,36 @@ var Transfer = (function (_super) { }); }); }; + Transfer.fetchAll = function (api) { + return __awaiter(this, void 0, void 0, function () { + var data; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + api.requireAuthed(); + return [4, api.get('transfers')]; + case 1: + data = (_a.sent()).data; + return [2, data.map(function (transferData) { return new Transfer(transferData, api); })]; + } + }); + }); + }; + Transfer.fetch = function (api, id) { + return __awaiter(this, void 0, void 0, function () { + var data; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + api.requireAuthed(); + return [4, api.get("transfers/" + id)]; + case 1: + data = _a.sent(); + return [2, new Transfer(data, api)]; + } + }); + }); + }; Transfer.prototype.confirm = function () { return __awaiter(this, void 0, void 0, function () { var data; diff --git a/src/Account.ts b/src/Account.ts index 4863593..35a9b2e 100644 --- a/src/Account.ts +++ b/src/Account.ts @@ -1,9 +1,9 @@ import Model from './Model' import Transfer from './Transfer' -import PaymentMethod, { PAYMENT_TYPE } from './PaymentMethod' +import PaymentMethod from './PaymentMethod' import Api from './utils/Api' import { IAccount, IAccountResponse, ICreateAccountParams, IProfileField } from './Account/IAccount' -import { ICreateTransferParams, ITransferHistoryResponse } from './Transfer/ITransfer' +import { ICreateTransferParams } from './Transfer/ITransfer' export default class Account extends Model implements IAccount { public id: string @@ -44,13 +44,12 @@ export default class Account extends Model implements IAccoun } public async createTransfer(params: ICreateTransferParams): Promise { - const transfer = await Transfer.create(params, this.api) + const transfer = await Transfer.create(this.api, params) return transfer } public async fetchTransfers(): Promise> { - const { data } = await this.api.get('transfers') - return data.map((transferData) => new Transfer(transferData, this.api)) + return Transfer.fetchAll(this.api) } } \ No newline at end of file diff --git a/src/Transfer.ts b/src/Transfer.ts index 276fd3b..b28b928 100644 --- a/src/Transfer.ts +++ b/src/Transfer.ts @@ -1,6 +1,12 @@ import Model from './Model' import Api from './utils/Api' -import type { ITransferStatusHistory, ITransfer, ITransferFees, ICreateTransferParams } from './Transfer/ITransfer' +import type { + ITransferStatusHistory, + ITransfer, + ITransferFees, + ICreateTransferParams, + ITransferHistoryResponse +} from './Transfer/ITransfer' import PaymentMethod from './PaymentMethod' export default class Transfer extends Model implements ITransfer { @@ -34,7 +40,7 @@ export default class Transfer extends Model implements ITra throw new Error('Cannot have both source and destination amounts defined.') } - public static async create(params: ICreateTransferParams, api: Api): Promise { + public static async create(api: Api, params: ICreateTransferParams): Promise { api.requireAuthed() this.verifyCreateParams(params) @@ -53,6 +59,20 @@ export default class Transfer extends Model implements ITra return new Transfer(data, api) } + public static async fetchAll(api: Api): Promise> { + api.requireAuthed() + + const { data } = await api.get('transfers') + return data.map((transferData) => new Transfer(transferData, api)) + } + + public static async fetch(api: Api, id: string): Promise { + api.requireAuthed() + + const data = await api.get(`transfers/${id}`) + return new Transfer(data, api) + } + public async confirm() { const data = await this.api.post(`transfers/${this.id}/confirm`) this.set(data) From 2540b75c236bf50f142d3276669f5971c4fc2396 Mon Sep 17 00:00:00 2001 From: Noah Passalacqua Date: Wed, 8 Apr 2020 13:09:51 -0500 Subject: [PATCH 12/20] Fetch rates. --- dist/utils/Api.js | 2 +- dist/wyre.d.ts | 14 ++++++++++++++ dist/wyre.d.ts.map | 2 +- dist/wyre.js | 7 +++++++ src/utils/Api.ts | 2 +- src/wyre.ts | 8 ++++++++ 6 files changed, 32 insertions(+), 3 deletions(-) diff --git a/dist/utils/Api.js b/dist/utils/Api.js index ed74af3..4180605 100644 --- a/dist/utils/Api.js +++ b/dist/utils/Api.js @@ -19,7 +19,7 @@ require("es6-shim"); var Api = (function () { function Api(config) { var defaultConfig = { - uri: 'https://api.testwyre.com', + uri: 'https://api.sendwyre.com', version: '3', format: 'json', qs: {}, diff --git a/dist/wyre.d.ts b/dist/wyre.d.ts index 3d0decc..688cf0f 100644 --- a/dist/wyre.d.ts +++ b/dist/wyre.d.ts @@ -6,5 +6,19 @@ export default class WyreClient { constructor(config: IApiConfig); createAccount(params: ICreateAccountParams): Promise; fetchAccount(id: string, masquerade?: boolean): Promise; + fetchRates(): Promise<{ + [symbolPair: string]: number; + }>; + fetchRates(as: 'DIVISOR'): Promise<{ + [symbolPair: string]: number; + }>; + fetchRates(as: 'MULTIPLIER'): Promise<{ + [symbolPair: string]: number; + }>; + fetchRates(as: 'PRICED'): Promise<{ + [symbolPair: string]: { + [symbol: string]: number; + }; + }>; } //# sourceMappingURL=wyre.d.ts.map \ No newline at end of file diff --git a/dist/wyre.d.ts.map b/dist/wyre.d.ts.map index d458290..9cf9146 100644 --- a/dist/wyre.d.ts.map +++ b/dist/wyre.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"wyre.d.ts","sourceRoot":"","sources":["../src/wyre.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,WAAW,CAAA;AAE/B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAA;AAE9D,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAK;gBAEb,MAAM,EAAE,UAAU;IAIjB,aAAa,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,OAAO,CAAC;IAI7D,YAAY,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,UAAQ,GAAG,OAAO,CAAC,OAAO,CAAC;CAI5E"} \ No newline at end of file +{"version":3,"file":"wyre.d.ts","sourceRoot":"","sources":["../src/wyre.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,WAAW,CAAA;AAE/B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAA;AAE9D,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAK;gBAEb,MAAM,EAAE,UAAU;IAIjB,aAAa,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,OAAO,CAAC;IAI7D,YAAY,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,UAAQ,GAAG,OAAO,CAAC,OAAO,CAAC;IAK9D,UAAU,IAAI,OAAO,CAAC;QAAE,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IACvD,UAAU,CAAC,EAAE,EAAE,SAAS,GAAG,OAAO,CAAC;QAAE,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IACpE,UAAU,CAAC,EAAE,EAAE,YAAY,GAAG,OAAO,CAAC;QAAE,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IACvE,UAAU,CAAC,EAAE,EAAE,QAAQ,GAAG,OAAO,CAAC;QAAE,CAAC,UAAU,EAAE,MAAM,GAAG;YAAE,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAA;SAAE,CAAA;KAAE,CAAC;CAIvG"} \ No newline at end of file diff --git a/dist/wyre.js b/dist/wyre.js index cf4a697..d3693c4 100644 --- a/dist/wyre.js +++ b/dist/wyre.js @@ -59,6 +59,13 @@ var WyreClient = (function () { }); }); }; + WyreClient.prototype.fetchRates = function (as) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + return [2, this.api.get('rates', null, { qs: { as: as } })]; + }); + }); + }; return WyreClient; }()); exports.default = WyreClient; diff --git a/src/utils/Api.ts b/src/utils/Api.ts index 0960309..03c0bd9 100644 --- a/src/utils/Api.ts +++ b/src/utils/Api.ts @@ -11,7 +11,7 @@ export default class Api { constructor(config?: IApiConfig) { const defaultConfig: IApiConfig = { - uri: 'https://api.testwyre.com', + uri: 'https://api.sendwyre.com', version: '3', format: 'json', qs: {}, diff --git a/src/wyre.ts b/src/wyre.ts index 1142a9d..e4344e9 100644 --- a/src/wyre.ts +++ b/src/wyre.ts @@ -18,4 +18,12 @@ export default class WyreClient { const api = masquerade ? this.api.masqueradeAs(id) : this.api return Account.fetch(api, id) } + + public async fetchRates(): Promise<{ [symbolPair: string]: number }> + public async fetchRates(as: 'DIVISOR'): Promise<{ [symbolPair: string]: number }> + public async fetchRates(as: 'MULTIPLIER'): Promise<{ [symbolPair: string]: number }> + public async fetchRates(as: 'PRICED'): Promise<{ [symbolPair: string]: { [symbol: string]: number } }> + public async fetchRates(as?: string): Promise { + return this.api.get('rates', null, { qs: { as } }) + } } From 5904a07b2932f25cb2830ec334714f087adb7a98 Mon Sep 17 00:00:00 2001 From: Noah Passalacqua Date: Wed, 8 Apr 2020 13:46:24 -0500 Subject: [PATCH 13/20] Add subscriptions model. fix --- dist/Subscription.d.ts | 15 +++ dist/Subscription.d.ts.map | 1 + dist/Subscription.js | 120 +++++++++++++++++++++++ dist/Subscription/ISubscription.d.ts | 14 +++ dist/Subscription/ISubscription.d.ts.map | 1 + dist/Subscription/ISubscription.js | 2 + dist/wyre.d.ts | 3 +- dist/wyre.d.ts.map | 2 +- dist/wyre.js | 2 +- src/Subscription.ts | 46 +++++++++ src/Subscription/ISubscription.ts | 15 +++ src/wyre.ts | 4 +- 12 files changed, 220 insertions(+), 5 deletions(-) create mode 100644 dist/Subscription.d.ts create mode 100644 dist/Subscription.d.ts.map create mode 100644 dist/Subscription.js create mode 100644 dist/Subscription/ISubscription.d.ts create mode 100644 dist/Subscription/ISubscription.d.ts.map create mode 100644 dist/Subscription/ISubscription.js create mode 100644 src/Subscription.ts create mode 100644 src/Subscription/ISubscription.ts diff --git a/dist/Subscription.d.ts b/dist/Subscription.d.ts new file mode 100644 index 0000000..72508a3 --- /dev/null +++ b/dist/Subscription.d.ts @@ -0,0 +1,15 @@ +import Api from './utils/Api'; +import Model from './Model'; +import type { ISubscription } from './Subscription/ISubscription'; +export default class Subscription extends Model implements ISubscription { + id: string; + subscribed: string; + notifyTarget: string; + createdAt: number; + failure: any; + failCount: number; + static create(api: Api, srn: string, target: string): Promise; + static fetchAll(api: Api): Promise>; + delete(): Promise; +} +//# sourceMappingURL=Subscription.d.ts.map \ No newline at end of file diff --git a/dist/Subscription.d.ts.map b/dist/Subscription.d.ts.map new file mode 100644 index 0000000..7211ebd --- /dev/null +++ b/dist/Subscription.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"Subscription.d.ts","sourceRoot":"","sources":["../src/Subscription.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,aAAa,CAAA;AAC7B,OAAO,KAAK,MAAM,SAAS,CAAA;AAC3B,OAAO,KAAK,EAAE,aAAa,EAA0B,MAAM,8BAA8B,CAAA;AAEzF,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,KAAK,CAAC,YAAY,EAAE,aAAa,CAAE,YAAW,aAAa;IAC5F,EAAE,EAAE,MAAM,CAAA;IACV,UAAU,EAAE,MAAM,CAAA;IAClB,YAAY,EAAE,MAAM,CAAA;IACpB,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,GAAG,CAAA;IACZ,SAAS,EAAE,MAAM,CAAA;WAEJ,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;WAWpE,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IAmBvD,MAAM;CAGpB"} \ No newline at end of file diff --git a/dist/Subscription.js b/dist/Subscription.js new file mode 100644 index 0000000..63067f7 --- /dev/null +++ b/dist/Subscription.js @@ -0,0 +1,120 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var Model_1 = require("./Model"); +var Subscription = (function (_super) { + __extends(Subscription, _super); + function Subscription() { + return _super !== null && _super.apply(this, arguments) || this; + } + Subscription.create = function (api, srn, target) { + return __awaiter(this, void 0, void 0, function () { + var params, data; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + api.requireAuthed(); + params = { + subscribeTo: srn, + notifyTarget: target + }; + return [4, api.post('subscriptions', params)]; + case 1: + data = _a.sent(); + return [2, new Subscription(data, api)]; + } + }); + }); + }; + Subscription.fetchAll = function (api) { + return __awaiter(this, void 0, void 0, function () { + var subscriptions, offset, length, hasMore, _a, data, recordsTotal, position, subs; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + api.requireAuthed(); + subscriptions = []; + offset = 0; + length = 20; + hasMore = true; + _b.label = 1; + case 1: return [4, api.get('subscriptions', { offset: offset, length: length })]; + case 2: + _a = _b.sent(), data = _a.data, recordsTotal = _a.recordsTotal, position = _a.position; + subs = data.map(function (subData) { return new Subscription(subData, api); }); + subscriptions.push.apply(subscriptions, subs); + hasMore = Math.ceil(recordsTotal / length) - 1 !== position; + if (hasMore) + offset += length; + _b.label = 3; + case 3: + if (hasMore) return [3, 1]; + _b.label = 4; + case 4: return [2, subscriptions]; + } + }); + }); + }; + Subscription.prototype.delete = function () { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4, this.api.delete("subscriptions/" + this.id)]; + case 1: + _a.sent(); + return [2]; + } + }); + }); + }; + return Subscription; +}(Model_1.default)); +exports.default = Subscription; diff --git a/dist/Subscription/ISubscription.d.ts b/dist/Subscription/ISubscription.d.ts new file mode 100644 index 0000000..e6afe50 --- /dev/null +++ b/dist/Subscription/ISubscription.d.ts @@ -0,0 +1,14 @@ +export interface ISubscription { + id: string; + subscribed: string; + notifyTarget: string; + createdAt: number; + failure: any; + failCount: number; +} +export interface ISubscriptionsResponse { + data: Array; + recordsTotal: number; + position: number; +} +//# sourceMappingURL=ISubscription.d.ts.map \ No newline at end of file diff --git a/dist/Subscription/ISubscription.d.ts.map b/dist/Subscription/ISubscription.d.ts.map new file mode 100644 index 0000000..da0890e --- /dev/null +++ b/dist/Subscription/ISubscription.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"ISubscription.d.ts","sourceRoot":"","sources":["../../src/Subscription/ISubscription.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAA;IACV,UAAU,EAAE,MAAM,CAAA;IAClB,YAAY,EAAE,MAAM,CAAA;IACpB,SAAS,EAAE,MAAM,CAAA;IAEjB,OAAO,EAAE,GAAG,CAAA;IACZ,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,KAAK,CAAC,aAAa,CAAC,CAAA;IAC1B,YAAY,EAAE,MAAM,CAAA;IACpB,QAAQ,EAAE,MAAM,CAAA;CACjB"} \ No newline at end of file diff --git a/dist/Subscription/ISubscription.js b/dist/Subscription/ISubscription.js new file mode 100644 index 0000000..c8ad2e5 --- /dev/null +++ b/dist/Subscription/ISubscription.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/dist/wyre.d.ts b/dist/wyre.d.ts index 688cf0f..188d9d5 100644 --- a/dist/wyre.d.ts +++ b/dist/wyre.d.ts @@ -1,8 +1,9 @@ import Account from './Account'; +import Api from './utils/Api'; import type { IApiConfig } from './utils/API/IApiConfig'; import type { ICreateAccountParams } from './Account/IAccount'; export default class WyreClient { - private readonly api; + readonly api: Api; constructor(config: IApiConfig); createAccount(params: ICreateAccountParams): Promise; fetchAccount(id: string, masquerade?: boolean): Promise; diff --git a/dist/wyre.d.ts.map b/dist/wyre.d.ts.map index 9cf9146..5cf1234 100644 --- a/dist/wyre.d.ts.map +++ b/dist/wyre.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"wyre.d.ts","sourceRoot":"","sources":["../src/wyre.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,WAAW,CAAA;AAE/B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAA;AAE9D,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAK;gBAEb,MAAM,EAAE,UAAU;IAIjB,aAAa,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,OAAO,CAAC;IAI7D,YAAY,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,UAAQ,GAAG,OAAO,CAAC,OAAO,CAAC;IAK9D,UAAU,IAAI,OAAO,CAAC;QAAE,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IACvD,UAAU,CAAC,EAAE,EAAE,SAAS,GAAG,OAAO,CAAC;QAAE,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IACpE,UAAU,CAAC,EAAE,EAAE,YAAY,GAAG,OAAO,CAAC;QAAE,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IACvE,UAAU,CAAC,EAAE,EAAE,QAAQ,GAAG,OAAO,CAAC;QAAE,CAAC,UAAU,EAAE,MAAM,GAAG;YAAE,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAA;SAAE,CAAA;KAAE,CAAC;CAIvG"} \ No newline at end of file +{"version":3,"file":"wyre.d.ts","sourceRoot":"","sources":["../src/wyre.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,WAAW,CAAA;AAC/B,OAAO,GAAG,MAAM,aAAa,CAAA;AAC7B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAA;AAE9D,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B,SAAgB,GAAG,EAAE,GAAG,CAAA;gBAEZ,MAAM,EAAE,UAAU;IAIjB,aAAa,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,OAAO,CAAC;IAI7D,YAAY,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,UAAQ,GAAG,OAAO,CAAC,OAAO,CAAC;IAK9D,UAAU,IAAI,OAAO,CAAC;QAAE,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IACvD,UAAU,CAAC,EAAE,EAAE,SAAS,GAAG,OAAO,CAAC;QAAE,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IACpE,UAAU,CAAC,EAAE,EAAE,YAAY,GAAG,OAAO,CAAC;QAAE,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IACvE,UAAU,CAAC,EAAE,EAAE,QAAQ,GAAG,OAAO,CAAC;QAAE,CAAC,UAAU,EAAE,MAAM,GAAG;YAAE,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAA;SAAE,CAAA;KAAE,CAAC;CAIvG"} \ No newline at end of file diff --git a/dist/wyre.js b/dist/wyre.js index d3693c4..8372a4d 100644 --- a/dist/wyre.js +++ b/dist/wyre.js @@ -62,7 +62,7 @@ var WyreClient = (function () { WyreClient.prototype.fetchRates = function (as) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { - return [2, this.api.get('rates', null, { qs: { as: as } })]; + return [2, this.api.get('rates', { as: as })]; }); }); }; diff --git a/src/Subscription.ts b/src/Subscription.ts new file mode 100644 index 0000000..aa931d6 --- /dev/null +++ b/src/Subscription.ts @@ -0,0 +1,46 @@ +import Api from './utils/Api' +import Model from './Model' +import type { ISubscription, ISubscriptionsResponse } from './Subscription/ISubscription' + +export default class Subscription extends Model implements ISubscription { + public id: string + public subscribed: string + public notifyTarget: string + public createdAt: number + public failure: any + public failCount: number + + public static async create(api: Api, srn: string, target: string): Promise { + api.requireAuthed() + + const params = { + subscribeTo: srn, + notifyTarget: target + } + const data = await api.post('subscriptions', params) + return new Subscription(data, api) + } + + public static async fetchAll(api: Api): Promise> { + api.requireAuthed() + + const subscriptions: Array = [] + let offset = 0 + let length = 20 + let hasMore = true + do { + const { data, recordsTotal, position} = await api.get('subscriptions', { offset, length }) + const subs = data.map((subData) => new Subscription(subData, api)) + subscriptions.push(...subs) + + hasMore = Math.ceil(recordsTotal / length) - 1 !== position + if (hasMore) offset += length + } while (hasMore) + + return subscriptions + } + + public async delete() { + await this.api.delete(`subscriptions/${this.id}`) + } +} \ No newline at end of file diff --git a/src/Subscription/ISubscription.ts b/src/Subscription/ISubscription.ts new file mode 100644 index 0000000..93922e7 --- /dev/null +++ b/src/Subscription/ISubscription.ts @@ -0,0 +1,15 @@ +export interface ISubscription { + id: string + subscribed: string + notifyTarget: string + createdAt: number + // TODO: unknown type + failure: any + failCount: number +} + +export interface ISubscriptionsResponse { + data: Array + recordsTotal: number + position: number +} \ No newline at end of file diff --git a/src/wyre.ts b/src/wyre.ts index e4344e9..2edcced 100644 --- a/src/wyre.ts +++ b/src/wyre.ts @@ -4,7 +4,7 @@ import type { IApiConfig } from './utils/API/IApiConfig' import type { ICreateAccountParams } from './Account/IAccount' export default class WyreClient { - private readonly api: Api + public readonly api: Api constructor(config: IApiConfig) { this.api = new Api(config) @@ -24,6 +24,6 @@ export default class WyreClient { public async fetchRates(as: 'MULTIPLIER'): Promise<{ [symbolPair: string]: number }> public async fetchRates(as: 'PRICED'): Promise<{ [symbolPair: string]: { [symbol: string]: number } }> public async fetchRates(as?: string): Promise { - return this.api.get('rates', null, { qs: { as } }) + return this.api.get('rates', { as }) } } From d2bc70342247a07063aa7be66ed112a50c08c65a Mon Sep 17 00:00:00 2001 From: Noah Passalacqua Date: Wed, 8 Apr 2020 13:50:26 -0500 Subject: [PATCH 14/20] Paginate fetching payment methods. fix --- dist/PaymentMethod.d.ts.map | 2 +- dist/PaymentMethod.js | 30 +++++++++++++++++++++--------- src/PaymentMethod.ts | 18 ++++++++++++++---- 3 files changed, 36 insertions(+), 14 deletions(-) diff --git a/dist/PaymentMethod.d.ts.map b/dist/PaymentMethod.d.ts.map index e9b5ba8..8df1794 100644 --- a/dist/PaymentMethod.d.ts.map +++ b/dist/PaymentMethod.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"PaymentMethod.d.ts","sourceRoot":"","sources":["../src/PaymentMethod.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,SAAS,CAAA;AAC3B,OAAO,KAAK,EACV,cAAc,EACiB,qCAAqC,EAAE,wBAAwB,EACrE,8BAA8B,EACxD,MAAM,gCAAgC,CAAA;AACvC,OAAO,GAAG,MAAM,aAAa,CAAA;AAE7B,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,KAAK,CAAC,aAAa,EAAE,cAAc,CAAE,YAAW,cAAc;IAChG,eAAe,EAAE,MAAM,CAAA;IACvB,WAAW,EAAE,MAAM,CAAA;IACnB,KAAK,EAAE,IAAI,CAAA;IACX,iBAAiB,EAAE,IAAI,CAAA;IACvB,oBAAoB,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;IACnC,WAAW,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;IACjB,eAAe,EAAE,MAAM,CAAA;IACvB,kBAAkB,EAAE,IAAI,CAAA;IACxB,qBAAqB,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;IACpC,QAAQ,EAAE,OAAO,CAAA;IACjB,SAAS,EAAE,KAAK,CAAC,GAAG,CAAC,CAAA;I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B,GAAG,EAAE,MAAM,CAAA;IACX,MAAM,EAAE,SAAS,GAAG,mBAAmB,GAAG,QAAQ,GAAG,UAAU,CAAA;IAC/D,aAAa,EAAE,MAAM,CAAA;IACrB,eAAe,EAAE,OAAO,CAAA;IACxB,eAAe,EAAE,OAAO,CAAA;IACxB,cAAc,EAAE,KAAK,CAAC,GAAG,CAAC,CAAA;WAEb,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;WAYhE,UAAU,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,8BAA8B,GAAG,OAAO,CAAC,aAAa,CAAC;WAUpF,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;WAmBjD,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAO1D,gBAAgB,CAAC,UAAU,EAAE,wBAAwB,GAAG,KAAK,CAAC,wBAAwB,CAAC,EAAE,IAAI,GAAE,qCAA0C;IASzI,MAAM;CAGpB"} \ No newline at end of file diff --git a/dist/PaymentMethod.js b/dist/PaymentMethod.js index 77f1ddb..51d57b4 100644 --- a/dist/PaymentMethod.js +++ b/dist/PaymentMethod.js @@ -105,17 +105,29 @@ var PaymentMethod = (function (_super) { }; PaymentMethod.fetchAll = function (api) { return __awaiter(this, void 0, void 0, function () { - var paymentMethods; - return __generator(this, function (_a) { - switch (_a.label) { + var paymentMethods, offset, length, hasMore, _a, data, recordsTotal, position, methods; + return __generator(this, function (_b) { + switch (_b.label) { case 0: api.requireAuthed(); - return [4, api.get('paymentMethods', null, { - version: '2' - })]; - case 1: - paymentMethods = (_a.sent()).data; - return [2, paymentMethods.map(function (paymentData) { return new PaymentMethod(paymentData, api); })]; + paymentMethods = []; + offset = 0; + length = 20; + hasMore = true; + _b.label = 1; + case 1: return [4, api.get('paymentMethods', { offset: offset, length: length }, { version: '2' })]; + case 2: + _a = _b.sent(), data = _a.data, recordsTotal = _a.recordsTotal, position = _a.position; + methods = data.map(function (paymentData) { return new PaymentMethod(paymentData, api); }); + paymentMethods.push.apply(paymentMethods, methods); + hasMore = Math.ceil(recordsTotal / length) - 1 !== position; + if (hasMore) + offset += length; + _b.label = 3; + case 3: + if (hasMore) return [3, 1]; + _b.label = 4; + case 4: return [2, paymentMethods]; } }); }); diff --git a/src/PaymentMethod.ts b/src/PaymentMethod.ts index 17f8bd0..a0d1cf8 100644 --- a/src/PaymentMethod.ts +++ b/src/PaymentMethod.ts @@ -65,10 +65,20 @@ export default class PaymentMethod extends Model public static async fetchAll(api: Api): Promise> { api.requireAuthed() - const { data: paymentMethods } = await api.get('paymentMethods', null, { - version: '2' - }) - return paymentMethods.map((paymentData) => new PaymentMethod(paymentData, api)) + const paymentMethods: Array = [] + let offset = 0 + let length = 20 + let hasMore = true + do { + const { data, recordsTotal, position} = await api.get('paymentMethods', { offset, length }, { version: '2' }) + const methods = data.map((paymentData) => new PaymentMethod(paymentData, api)) + paymentMethods.push(...methods) + + hasMore = Math.ceil(recordsTotal / length) - 1 !== position + if (hasMore) offset += length + } while (hasMore) + + return paymentMethods } public static async fetch(api: Api, id: string): Promise { From 9ea3925eb504b0c9cb7038c6c0ecbd89a3599478 Mon Sep 17 00:00:00 2001 From: Noah Passalacqua Date: Wed, 8 Apr 2020 13:51:10 -0500 Subject: [PATCH 15/20] Paginate fetching Transfers. --- dist/Transfer.d.ts.map | 2 +- dist/Transfer.js | 28 +++++++++++++++++++++------- src/Transfer.ts | 16 ++++++++++++++-- 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/dist/Transfer.d.ts.map b/dist/Transfer.d.ts.map index ca668b1..05305b0 100644 --- a/dist/Transfer.d.ts.map +++ b/dist/Transfer.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"Transfer.d.ts","sourceRoot":"","sources":["../src/Transfer.ts"],"names":[],"mappings":"AAA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E,qBAAqB;WAK1C,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,qBAAqB,GAAG,OAAO,CAAC,QAAQ,CAAC;WAmBlE,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;WAmB5C,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;IAOrD,OAAO;CAIrB"} \ No newline at end of file diff --git a/dist/Transfer.js b/dist/Transfer.js index 7f4159f..8d8b2a3 100644 --- a/dist/Transfer.js +++ b/dist/Transfer.js @@ -89,15 +89,29 @@ var Transfer = (function (_super) { }; Transfer.fetchAll = function (api) { return __awaiter(this, void 0, void 0, function () { - var data; - return __generator(this, function (_a) { - switch (_a.label) { + var transfers, offset, length, hasMore, _a, data, recordsTotal, position, mappedTransfers; + return __generator(this, function (_b) { + switch (_b.label) { case 0: api.requireAuthed(); - return [4, api.get('transfers')]; - case 1: - data = (_a.sent()).data; - return [2, data.map(function (transferData) { return new Transfer(transferData, api); })]; + transfers = []; + offset = 0; + length = 20; + hasMore = true; + _b.label = 1; + case 1: return [4, api.get('transfers', { offset: offset, length: length })]; + case 2: + _a = _b.sent(), data = _a.data, recordsTotal = _a.recordsTotal, position = _a.position; + mappedTransfers = data.map(function (transferData) { return new Transfer(transferData, api); }); + transfers.push.apply(transfers, mappedTransfers); + hasMore = Math.ceil(recordsTotal / length) - 1 !== position; + if (hasMore) + offset += length; + _b.label = 3; + case 3: + if (hasMore) return [3, 1]; + _b.label = 4; + case 4: return [2, transfers]; } }); }); diff --git a/src/Transfer.ts b/src/Transfer.ts index b28b928..40f03c2 100644 --- a/src/Transfer.ts +++ b/src/Transfer.ts @@ -62,8 +62,20 @@ export default class Transfer extends Model implements ITra public static async fetchAll(api: Api): Promise> { api.requireAuthed() - const { data } = await api.get('transfers') - return data.map((transferData) => new Transfer(transferData, api)) + const transfers: Array = [] + let offset = 0 + let length = 20 + let hasMore = true + do { + const { data, recordsTotal, position} = await api.get('transfers', { offset, length }) + const mappedTransfers = data.map((transferData) => new Transfer(transferData, api)) + transfers.push(...mappedTransfers) + + hasMore = Math.ceil(recordsTotal / length) - 1 !== position + if (hasMore) offset += length + } while (hasMore) + + return transfers } public static async fetch(api: Api, id: string): Promise { From 8a5798e24a155d46057593e2a9b2a5f16d9dd903 Mon Sep 17 00:00:00 2001 From: Noah Passalacqua Date: Wed, 8 Apr 2020 14:08:14 -0500 Subject: [PATCH 16/20] Fetch account limits. fix --- dist/Account.d.ts | 6 ++++-- dist/Account.d.ts.map | 2 +- dist/Account.js | 8 ++++++++ dist/PaymentMethod.d.ts | 2 +- dist/PaymentMethod.d.ts.map | 2 +- dist/Transfer.d.ts.map | 2 +- dist/wyre.d.ts | 19 +++++-------------- dist/wyre.d.ts.map | 2 +- dist/wyre/ILimits.d.ts | 19 +++++++++++++++++++ dist/wyre/ILimits.d.ts.map | 1 + dist/wyre/ILimits.js | 2 ++ dist/wyre/IRates.d.ts | 9 +++++++++ dist/wyre/IRates.d.ts.map | 1 + dist/wyre/IRates.js | 2 ++ src/Account.ts | 11 +++++++++-- src/PaymentMethod.ts | 2 +- src/Transfer.ts | 2 +- src/wyre.ts | 9 +++++---- src/wyre/ILimits.ts | 19 +++++++++++++++++++ src/wyre/IRates.ts | 9 +++++++++ 20 files changed, 100 insertions(+), 29 deletions(-) create mode 100644 dist/wyre/ILimits.d.ts create mode 100644 dist/wyre/ILimits.d.ts.map create mode 100644 dist/wyre/ILimits.js create mode 100644 dist/wyre/IRates.d.ts create mode 100644 dist/wyre/IRates.d.ts.map create mode 100644 dist/wyre/IRates.js create mode 100644 src/wyre/ILimits.ts create mode 100644 src/wyre/IRates.ts diff --git a/dist/Account.d.ts b/dist/Account.d.ts index a66a4c0..3206b4a 100644 --- a/dist/Account.d.ts +++ b/dist/Account.d.ts @@ -2,8 +2,9 @@ import Model from './Model'; import Transfer from './Transfer'; import PaymentMethod from './PaymentMethod'; import Api from './utils/Api'; -import { IAccount, IAccountResponse, ICreateAccountParams, IProfileField } from './Account/IAccount'; -import { ICreateTransferParams } from './Transfer/ITransfer'; +import type { IAccount, IAccountResponse, ICreateAccountParams, IProfileField } from './Account/IAccount'; +import type { ICreateTransferParams } from './Transfer/ITransfer'; +import type { ILimits } from './wyre/ILimits'; export default class Account extends Model implements IAccount { id: string; status: 'OPEN' | 'PENDING' | 'APPROVED'; @@ -30,5 +31,6 @@ export default class Account extends Model implements IAccoun save(): Promise; createTransfer(params: ICreateTransferParams): Promise; fetchTransfers(): Promise>; + fetchLimits(): Promise; } //# sourceMappingURL=Account.d.ts.map \ No newline at end of file diff --git a/dist/Account.d.ts.map b/dist/Account.d.ts.map index 3bc0f70..9702544 100644 --- a/dist/Account.d.ts.map +++ b/dist/Account.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"Account.d.ts","sourceRoot":"","sources":["../src/Account.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,SAAS,CAAA;AAC3B,OAAO,QAAQ,MAAM,YAAY,CAAA;AACjC,OAAO,aAAa,MAAM,iBAAiB,CAAA;AAC3C,OAAO,GAAG,MAAM,aAAa,CAAA;AAC7B,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AACpG,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAA;AAE5D,MAAM,CAAC,OAAO,OAAO,OAAQ,SAAQ,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAE,YAAW,QAAQ;IACxE,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,UAAU,CAAA;IACvC,IAAI,EAAE,YAAY,GAAG,UAAU,CAAA;IAC/B,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;IACjB,gBAAgB,EAAE;QAAE,GAAG,EAAE,MAAM,CA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ist/Account.js +++ b/dist/Account.js @@ -148,6 +148,14 @@ var Account = (function (_super) { }); }); }; + Account.prototype.fetchLimits = function () { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + this.api.requireAuthed(); + return [2, this.api.get('limits')]; + }); + }); + }; return Account; }(Model_1.default)); exports.default = Account; diff --git a/dist/PaymentMethod.d.ts b/dist/PaymentMethod.d.ts index cb58701..b590abe 100644 --- a/dist/PaymentMethod.d.ts +++ b/dist/PaymentMethod.d.ts @@ -1,6 +1,6 @@ import Model from './Model'; -import type { IPaymentMethod, IPaymentMethodAttachBlockchainOptions, IPaymentMethodBlockchain, IPaymentMethodWireCreateParams } from './PaymentMethod/IPaymentMethod'; import Api from './utils/Api'; +import type { IPaymentMethod, IPaymentMethodAttachBlockchainOptions, IPaymentMethodBlockchain, IPaymentMethodWireCreateParams } from './PaymentMethod/IPaymentMethod'; export default class PaymentMethod extends Model implements IPaymentMethod { beneficiaryType: string; blockchains: object; diff --git a/dist/PaymentMethod.d.ts.map b/dist/PaymentMethod.d.ts.map index 8df1794..f3957f2 100644 --- a/dist/PaymentMethod.d.ts.map +++ b/dist/PaymentMethod.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"PaymentMethod.d.ts","sourceRoot":"","sources":["../src/PaymentMethod.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,SAAS,CAAA;AAC3B,OAAO,KAAK,EACV,cAAc,EACiB,qCAAqC,EAAE,wBAAwB,EACrE,8BAA8B,EACxD,MAAM,gCAAgC,CAAA;AACvC,OAAO,GAAG,MAAM,aAAa,CAAA;AAE7B,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,KAAK,CAAC,aAAa,EAAE,cAAc,CAAE,YAAW,cAAc;IAChG,eAAe,EAAE,MAAM,CAAA;IACvB,WAAW,EAAE,MAAM,CAAA;IACnB,KAAK,EAAE,IAAI,CAAA;IACX,iBAAiB,EAAE,IAAI,CAAA;IACvB,oBAAoB,EAAE,KAAK,CAAC,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AU,EAAE,IAAI,CAAA;IAChB,SAAS,EAAE,IAAI,CAAA;IACf,UAAU,EAAE,IAAI,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,YAAY,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,KAAK,EAAE,MAAM,CAAA;IACb,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAA;IAC/B,GAAG,EAAE,MAAM,CAAA;IACX,MAAM,EAAE,SAAS,GAAG,mBAAmB,GAAG,QAAQ,GAAG,UAAU,CAAA;IAC/D,aAAa,EAAE,MAAM,CAAA;IACrB,eAAe,EAAE,OAAO,CAAA;IACxB,eAAe,EAAE,OAAO,CAAA;IACxB,cAAc,EAAE,KAAK,CAAC,GAAG,CAAC,CAAA;WAEb,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;WAYhE,UAAU,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,8BAA8B,GAAG,OAAO,CAAC,aAAa,CAAC;WAUpF,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;WAmBjD,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAO1D,gBAAgB,CAAC,UAAU,EAAE,wBAAwB,GAAG,KAAK,CAAC,wBAAwB,CAAC,EAAE,IAAI,GAAE,qCAA0C;IASzI,MAAM;CAGpB"} \ No newline at end of file diff --git a/dist/Transfer.d.ts.map b/dist/Transfer.d.ts.map index 05305b0..dd43b07 100644 --- a/dist/Transfer.d.ts.map +++ b/dist/Transfer.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"Transfer.d.ts","sourceRoot":"","sources":["../src/Transfer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,SAAS,CAAA;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AAG,EAAE,GAAG,EAAE,MAAM,EAAE,qBAAqB,GAAG,OAAO,CAAC,QAAQ,CAAC;WAmBlE,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;WAmB5C,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;IAOrD,OAAO;CAIrB"} \ No newline at end of file diff --git a/dist/wyre.d.ts b/dist/wyre.d.ts index 188d9d5..e3da82c 100644 --- a/dist/wyre.d.ts +++ b/dist/wyre.d.ts @@ -2,24 +2,15 @@ import Account from './Account'; import Api from './utils/Api'; import type { IApiConfig } from './utils/API/IApiConfig'; import type { ICreateAccountParams } from './Account/IAccount'; +import type { IRates, IRatesPriced } from './wyre/IRates'; export default class WyreClient { readonly api: Api; constructor(config: IApiConfig); createAccount(params: ICreateAccountParams): Promise; fetchAccount(id: string, masquerade?: boolean): Promise; - fetchRates(): Promise<{ - [symbolPair: string]: number; - }>; - fetchRates(as: 'DIVISOR'): Promise<{ - [symbolPair: string]: number; - }>; - fetchRates(as: 'MULTIPLIER'): Promise<{ - [symbolPair: string]: number; - }>; - fetchRates(as: 'PRICED'): Promise<{ - [symbolPair: string]: { - [symbol: string]: number; - }; - }>; + fetchRates(): Promise; + fetchRates(as: 'DIVISOR'): Promise; + fetchRates(as: 'MULTIPLIER'): Promise; + fetchRates(as: 'PRICED'): Promise; } //# sourceMappingURL=wyre.d.ts.map \ No newline at end of file diff --git a/dist/wyre.d.ts.map b/dist/wyre.d.ts.map index 5cf1234..6fcca56 100644 --- a/dist/wyre.d.ts.map +++ b/dist/wyre.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"wyre.d.ts","sourceRoot":"","sources":["../src/wyre.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,WAAW,CAAA;AAC/B,OAAO,GAAG,MAAM,aAAa,CAAA;AAC7B,OAAO,KAAK,EAAE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AG,EAAE,GAAG,CAAA;gBAEZ,MAAM,EAAE,UAAU;IAIjB,aAAa,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,OAAO,CAAC;IAI7D,YAAY,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,UAAQ,GAAG,OAAO,CAAC,OAAO,CAAC;IAK9D,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;IAC7B,UAAU,CAAC,EAAE,EAAE,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC;IAC1C,UAAU,CAAC,EAAE,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC;IAC7C,UAAU,CAAC,EAAE,EAAE,QAAQ,GAAG,OAAO,CAAC,YAAY,CAAC;CAI7D"} \ No newline at end of file diff --git a/dist/wyre/ILimits.d.ts b/dist/wyre/ILimits.d.ts new file mode 100644 index 0000000..0ec9607 --- /dev/null +++ b/dist/wyre/ILimits.d.ts @@ -0,0 +1,19 @@ +export interface ILimits { + ACCOUNT?: ILimitsTime; + ACH?: ILimitsTime; + DEBIT_CARD?: ILimitsTime; +} +interface ILimitsTime { + 24?: ILimitValues; + 168?: ILimitValues; + 720?: ILimitValues; + 1440?: ILimitValues; +} +interface ILimitValues { + in: number; + out: number; + availIn: number; + availOut: number; +} +export {}; +//# sourceMappingURL=ILimits.d.ts.map \ No newline at end of file diff --git a/dist/wyre/ILimits.d.ts.map b/dist/wyre/ILimits.d.ts.map new file mode 100644 index 0000000..5ee9b5e --- /dev/null +++ b/dist/wyre/ILimits.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"ILimits.d.ts","sourceRoot":"","sources":["../../src/wyre/ILimits.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,OAAO;IACtB,OAAO,CAAC,EAAE,WAAW,CAAA;IACrB,GAAG,CAAC,EAAE,WAAW,CAAA;IACjB,UAAU,CAAC,EAAE,WAAW,CAAA;CACzB;AAED,UAAU,WAAW;IACnB,EAAE,CAAC,EAAE,YAAY,CAAA;IACjB,GAAG,CAAC,EAAE,YAAY,CAAA;IAClB,GAAG,CAAC,EAAE,YAAY,CAAA;IAClB,IAAI,CAAC,EAAE,YAAY,CAAA;CACpB;AAED,UAAU,YAAY;IACpB,EAAE,EAAE,MAAM,CAAA;IACV,GAAG,EAAE,MAAM,CAAA;IACX,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;CACjB"} \ No newline at end of file diff --git a/dist/wyre/ILimits.js b/dist/wyre/ILimits.js new file mode 100644 index 0000000..c8ad2e5 --- /dev/null +++ b/dist/wyre/ILimits.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/dist/wyre/IRates.d.ts b/dist/wyre/IRates.d.ts new file mode 100644 index 0000000..321face --- /dev/null +++ b/dist/wyre/IRates.d.ts @@ -0,0 +1,9 @@ +export interface IRates { + [symbolPair: string]: number; +} +export interface IRatesPriced { + [symbolPair: string]: { + [symbol: string]: number; + }; +} +//# sourceMappingURL=IRates.d.ts.map \ No newline at end of file diff --git a/dist/wyre/IRates.d.ts.map b/dist/wyre/IRates.d.ts.map new file mode 100644 index 0000000..81d6abe --- /dev/null +++ b/dist/wyre/IRates.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"IRates.d.ts","sourceRoot":"","sources":["../../src/wyre/IRates.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,MAAM;IACrB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAAA;CAC7B;AAED,MAAM,WAAW,YAAY;IAC3B,CAAC,UAAU,EAAE,MAAM,GAAG;QACpB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAA;KACzB,CAAA;CACF"} \ No newline at end of file diff --git a/dist/wyre/IRates.js b/dist/wyre/IRates.js new file mode 100644 index 0000000..c8ad2e5 --- /dev/null +++ b/dist/wyre/IRates.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/src/Account.ts b/src/Account.ts index 35a9b2e..888fe7c 100644 --- a/src/Account.ts +++ b/src/Account.ts @@ -2,8 +2,9 @@ import Model from './Model' import Transfer from './Transfer' import PaymentMethod from './PaymentMethod' import Api from './utils/Api' -import { IAccount, IAccountResponse, ICreateAccountParams, IProfileField } from './Account/IAccount' -import { ICreateTransferParams } from './Transfer/ITransfer' +import type { IAccount, IAccountResponse, ICreateAccountParams, IProfileField } from './Account/IAccount' +import type { ICreateTransferParams } from './Transfer/ITransfer' +import type { ILimits } from './wyre/ILimits' export default class Account extends Model implements IAccount { public id: string @@ -52,4 +53,10 @@ export default class Account extends Model implements IAccoun public async fetchTransfers(): Promise> { return Transfer.fetchAll(this.api) } + + public async fetchLimits(): Promise { + this.api.requireAuthed() + + return this.api.get('limits') + } } \ No newline at end of file diff --git a/src/PaymentMethod.ts b/src/PaymentMethod.ts index a0d1cf8..195c148 100644 --- a/src/PaymentMethod.ts +++ b/src/PaymentMethod.ts @@ -1,10 +1,10 @@ import Model from './Model' +import Api from './utils/Api' import type { IPaymentMethod, IPaymentMethodACHCreateParams, IPaymentMethodAttachBlockchainOptions, IPaymentMethodBlockchain, IPaymentMethodsResponse, IPaymentMethodWireCreateParams } from './PaymentMethod/IPaymentMethod' -import Api from './utils/Api' export default class PaymentMethod extends Model implements IPaymentMethod { public beneficiaryType: string diff --git a/src/Transfer.ts b/src/Transfer.ts index 40f03c2..8ecaae6 100644 --- a/src/Transfer.ts +++ b/src/Transfer.ts @@ -1,5 +1,6 @@ import Model from './Model' import Api from './utils/Api' +import PaymentMethod from './PaymentMethod' import type { ITransferStatusHistory, ITransfer, @@ -7,7 +8,6 @@ import type { ICreateTransferParams, ITransferHistoryResponse } from './Transfer/ITransfer' -import PaymentMethod from './PaymentMethod' export default class Transfer extends Model implements ITransfer { public blockchainTx: string diff --git a/src/wyre.ts b/src/wyre.ts index 2edcced..cf1a5a5 100644 --- a/src/wyre.ts +++ b/src/wyre.ts @@ -2,6 +2,7 @@ import Account from './Account' import Api from './utils/Api' import type { IApiConfig } from './utils/API/IApiConfig' import type { ICreateAccountParams } from './Account/IAccount' +import type { IRates, IRatesPriced } from './wyre/IRates' export default class WyreClient { public readonly api: Api @@ -19,10 +20,10 @@ export default class WyreClient { return Account.fetch(api, id) } - public async fetchRates(): Promise<{ [symbolPair: string]: number }> - public async fetchRates(as: 'DIVISOR'): Promise<{ [symbolPair: string]: number }> - public async fetchRates(as: 'MULTIPLIER'): Promise<{ [symbolPair: string]: number }> - public async fetchRates(as: 'PRICED'): Promise<{ [symbolPair: string]: { [symbol: string]: number } }> + public async fetchRates(): Promise + public async fetchRates(as: 'DIVISOR'): Promise + public async fetchRates(as: 'MULTIPLIER'): Promise + public async fetchRates(as: 'PRICED'): Promise public async fetchRates(as?: string): Promise { return this.api.get('rates', { as }) } diff --git a/src/wyre/ILimits.ts b/src/wyre/ILimits.ts new file mode 100644 index 0000000..492f483 --- /dev/null +++ b/src/wyre/ILimits.ts @@ -0,0 +1,19 @@ +export interface ILimits { + ACCOUNT?: ILimitsTime + ACH?: ILimitsTime + DEBIT_CARD?: ILimitsTime +} + +interface ILimitsTime { + 24?: ILimitValues + 168?: ILimitValues + 720?: ILimitValues + 1440?: ILimitValues +} + +interface ILimitValues { + in: number + out: number + availIn: number + availOut: number +} \ No newline at end of file diff --git a/src/wyre/IRates.ts b/src/wyre/IRates.ts new file mode 100644 index 0000000..a644368 --- /dev/null +++ b/src/wyre/IRates.ts @@ -0,0 +1,9 @@ +export interface IRates { + [symbolPair: string]: number +} + +export interface IRatesPriced { + [symbolPair: string]: { + [symbol: string]: number + } +} \ No newline at end of file From 1409e40ed78424792e274f2a1a214b4089510629 Mon Sep 17 00:00:00 2001 From: Noah Passalacqua Date: Wed, 8 Apr 2020 14:25:38 -0500 Subject: [PATCH 17/20] Fetch account from auth params. --- dist/wyre.d.ts | 1 + dist/wyre.d.ts.map | 2 +- dist/wyre.js | 15 ++++++++++++--- src/wyre.ts | 11 ++++++++++- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/dist/wyre.d.ts b/dist/wyre.d.ts index e3da82c..de7162e 100644 --- a/dist/wyre.d.ts +++ b/dist/wyre.d.ts @@ -7,6 +7,7 @@ export default class WyreClient { readonly api: Api; constructor(config: IApiConfig); createAccount(params: ICreateAccountParams): Promise; + fetchAccount(): Promise; fetchAccount(id: string, masquerade?: boolean): Promise; fetchRates(): Promise; fetchRates(as: 'DIVISOR'): Promise; diff --git a/dist/wyre.d.ts.map b/dist/wyre.d.ts.map index 6fcca56..2ace124 100644 --- a/dist/wyre.d.ts.map +++ b/dist/wyre.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"wyre.d.ts","sourceRoot":"","sources":["../src/wyre.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,WAAW,CAAA;AAC/B,OAAO,GAAG,MAAM,aAAa,CAAA;AAC7B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAA;AAC9D,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAEzD,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B,SAAgB,GAAG,EAAE,GAAG,CAAA;gBAEZ,MAAM,EAAE,UAAU;IAIjB,aAAa,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,OAAO,CAAC;IAI7D,YAAY,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,UAAQ,GAAG,OAAO,CAAC,OAAO,CAAC;IAK9D,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;IAC7B,UAAU,CAAC,EAAE,EAAE,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC;IAC1C,UAAU,CAAC,EAAE,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC;IAC7C,UAAU,CAAC,EAAE,EAAE,QAAQ,GAAG,OAAO,CAAC,YAAY,CAAC;CAI7D"} \ No newline at end of file +{"version":3,"file":"wyre.d.ts","sourceRoot":"","sources":["../src/wyre.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,WAAW,CAAA;AAC/B,OAAO,GAAG,MAAM,aAAa,CAAA;AAC7B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAA;AAC9D,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAEzD,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B,SAAgB,GAAG,EAAE,GAAG,CAAA;gBAEZ,MAAM,EAAE,UAAU;IAIjB,aAAa,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,OAAO,CAAC;IAI7D,YAAY,IAAI,OAAO,CAAC,OAAO,CAAC;IAChC,YAAY,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAahE,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;IAC7B,UAAU,CAAC,EAAE,EAAE,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC;IAC1C,UAAU,CAAC,EAAE,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC;IAC7C,UAAU,CAAC,EAAE,EAAE,QAAQ,GAAG,OAAO,CAAC,YAAY,CAAC;CAI7D"} \ No newline at end of file diff --git a/dist/wyre.js b/dist/wyre.js index 8372a4d..ae35884 100644 --- a/dist/wyre.js +++ b/dist/wyre.js @@ -52,10 +52,19 @@ var WyreClient = (function () { WyreClient.prototype.fetchAccount = function (id, masquerade) { if (masquerade === void 0) { masquerade = false; } return __awaiter(this, void 0, void 0, function () { - var api; + var api, data; return __generator(this, function (_a) { - api = masquerade ? this.api.masqueradeAs(id) : this.api; - return [2, Account_1.default.fetch(api, id)]; + switch (_a.label) { + case 0: + api = masquerade ? this.api.masqueradeAs(id) : this.api; + if (!!id) return [3, 2]; + return [4, api.get("account", null, { version: '2' })]; + case 1: + data = _a.sent(); + id = data.id; + _a.label = 2; + case 2: return [2, Account_1.default.fetch(api, id)]; + } }); }); }; diff --git a/src/wyre.ts b/src/wyre.ts index cf1a5a5..d2b3ee9 100644 --- a/src/wyre.ts +++ b/src/wyre.ts @@ -15,8 +15,17 @@ export default class WyreClient { return Account.create(this.api, params) } - public async fetchAccount(id: string, masquerade = false): Promise { + public async fetchAccount(): Promise + public async fetchAccount(id: string, masquerade?: boolean): Promise + public async fetchAccount(id?: string, masquerade = false): Promise { const api = masquerade ? this.api.masqueradeAs(id) : this.api + + // TODO: Update V3 of API to return account from auth params + if (!id) { + const data = await api.get(`account`, null, { version: '2' }) + id = data.id + } + return Account.fetch(api, id) } From 18f4138ca495b8e9e90dca0236c7a3202f992f29 Mon Sep 17 00:00:00 2001 From: Noah Passalacqua Date: Wed, 8 Apr 2020 14:30:03 -0500 Subject: [PATCH 18/20] Undo update to README. --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 28f6e17..909b2af 100644 --- a/README.md +++ b/README.md @@ -93,15 +93,15 @@ Constructor parameters: | secretKey | your environment-specific Wyre API secret | baseUrl | specifies the Wyre environment you'd like to use. please use either:
`https://api.sendwyre.com` for production
`https://api.testwyre.com` for testwyre | format | the data format you're requesting.
`json` for straight JSON
`json_numberstring` for JSON with all decimals as strings (see [above](#regarding-decimal-numbers)] -| options | options that are passed to the underlying [API](https://github.com/request/request) for _every_ request +| options | options that are passed to the underlying [Request](https://github.com/request/request) for _every_ request -Note that the ability to override options used by the [API](https://github.com/request/request) client is +Note that the ability to override options used by the [Request](https://github.com/request/request) client is available both generally as well as per-request. Timeouts may be adjusted via the `options.timeout` (expressed in milliseconds). This may be controlled via the constructor, or per-request (as with all options). -### API API +### Request API Each of these methods performs a single Wyre API request and returns a promise for the resulting API response. From 76ba1a275d692149120d46aee85415c83cc626e6 Mon Sep 17 00:00:00 2001 From: Noah Passalacqua Date: Wed, 8 Apr 2020 14:53:59 -0500 Subject: [PATCH 19/20] Add timeout option for API config. --- dist/utils/API/IApiConfig.d.ts | 1 + dist/utils/API/IApiConfig.d.ts.map | 2 +- src/utils/API/IApiConfig.ts | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/dist/utils/API/IApiConfig.d.ts b/dist/utils/API/IApiConfig.d.ts index 69c8d6d..9fb4d4f 100644 --- a/dist/utils/API/IApiConfig.d.ts +++ b/dist/utils/API/IApiConfig.d.ts @@ -12,6 +12,7 @@ export interface IApiOptions { qs?: { [key: string]: string; }; + timeout?: number; } export interface IAuth { secretKey: string; diff --git a/dist/utils/API/IApiConfig.d.ts.map b/dist/utils/API/IApiConfig.d.ts.map index 396cf9d..f146536 100644 --- a/dist/utils/API/IApiConfig.d.ts.map +++ b/dist/utils/API/IApiConfig.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"IApiConfig.d.ts","sourceRoot":"","sources":["../../../src/utils/API/IApiConfig.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAW,SAAQ,WAAW;IAC7C,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,KAAK,CAAA;CACb;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAA;IACnC,EAAE,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAA;CAC/B;AAED,MAAM,WAAW,KAAK;IACpB,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,MAAM,CAAA;IACd,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAC1B"} \ No newline at end of file +{"version":3,"file":"IApiConfig.d.ts","sourceRoot":"","sources":["../../../src/utils/API/IApiConfig.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAW,SAAQ,WAAW;IAC7C,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,KAAK,CAAA;CACb;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAA;IACnC,EAAE,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAA;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,KAAK;IACpB,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,MAAM,CAAA;IACd,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAC1B"} \ No newline at end of file diff --git a/src/utils/API/IApiConfig.ts b/src/utils/API/IApiConfig.ts index 6a6b646..5b3d03f 100644 --- a/src/utils/API/IApiConfig.ts +++ b/src/utils/API/IApiConfig.ts @@ -9,6 +9,7 @@ export interface IApiOptions { format?: string headers?: { [key: string]: string } qs?: { [key: string]: string } + timeout?: number } export interface IAuth { From 0df5dba657fe8c064664095c6ff333f84d433ca3 Mon Sep 17 00:00:00 2001 From: Noah Passalacqua Date: Wed, 8 Apr 2020 14:54:36 -0500 Subject: [PATCH 20/20] Update README. --- README.md | 74 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 909b2af..9b7105d 100644 --- a/README.md +++ b/README.md @@ -35,22 +35,28 @@ for a more natural declaration. ## Quickstart ```js -const WyreClient = require('@wyre/api').WyreClient +const WyreClient = require('@wyre/api') -let wyre = new WyreClient({ - format: "json_numberstring", - apiKey: "AK-AAAAAAA-AAAAAAA-AAAAAAA-AAAAAAA", - secretKey: "SK-AAAAAAA-AAAAAAA-AAAAAAA-AAAAAAA" - // baseUrl: "https://api.testwyre.com" // todo uncomment this line to use the testwyre environment -}); - -wyre.get("/v2/account") - .then(account => { - console.log("I am Wyre account ", account.id); +const client = new WyreClient({ + auth: { + apiKey: 'AK-api-key', + secretKey: 'SK-secret-key' }, - err => { + version: '3', // Keep this unless doing manual api calls + // uri: 'https://api.testwyre.com', // Uncomment this line to use the testwyre environment + format: 'json_numberstring', + headers: {}, + qs: {} +}) + +// Get account from auth credentials +client.fetchAccount() + .then((account) => { + console.log("I am Wyre account ", account.id); + }) + .catch((err) => { console.log("Problems, cap'n: ", err); - }); + }) ``` You're all set to begin coding! @@ -59,7 +65,7 @@ You're all set to begin coding! Attempt a $10 USD->BTC conversion: ```js -wyre.post("/transfers", { +account.createTransfer({ sourceAmount: "10", sourceCurrency: "USD", destCurrency: "BTC", @@ -71,7 +77,7 @@ Upload a document: ```js var fs = require('fs'); let my_id = fs.readFileSync('./my_id.jpg'); -wyre.post('/v3/accounts/' + account.id + '/individualGovernmentId', +client.api.post('accounts/' + account.id + '/individualGovernmentId', my_id, { headers: { 'Content-Type': 'image/jpeg' }}) .then(successCallback, errorCallback); @@ -89,11 +95,15 @@ Constructor parameters: | parameter | description | ----------|-------------- -| apiKey | your environment-specific Wyre API key -| secretKey | your environment-specific Wyre API secret -| baseUrl | specifies the Wyre environment you'd like to use. please use either:
`https://api.sendwyre.com` for production
`https://api.testwyre.com` for testwyre +| auth.apiKey | your environment-specific Wyre API key +| auth.secretKey | your environment-specific Wyre API secret +| auth.masqueradeTarget | sub-account id to masquerade as +| uri | specifies the Wyre environment you'd like to use. please use either:
`https://api.sendwyre.com` for production
`https://api.testwyre.com` for testwyre +| version | specifies the Wyre API version to use. Defaults to 3. | format | the data format you're requesting.
`json` for straight JSON
`json_numberstring` for JSON with all decimals as strings (see [above](#regarding-decimal-numbers)] -| options | options that are passed to the underlying [Request](https://github.com/request/request) for _every_ request +| headers | headers that are passed to the underlying [Request](https://github.com/request/request) for _every_ request +| qs | query string parameters that are passed to the underlying [Request](https://github.com/request/request) for _every_ request +| timeout | timeout limit for API request in milliseconds Note that the ability to override options used by the [Request](https://github.com/request/request) client is available both generally as well as per-request. @@ -106,10 +116,10 @@ or per-request (as with all options). Each of these methods performs a single Wyre API request and returns a promise for the resulting API response. ```js -wyre.get(path, parameters, options) -wyre.post(path, body, options) -wyre.put(path, body, options) -wyre.delete(path, body, options) +client.api.get(path, parameters, options) +client.api.post(path, body, options) +client.api.put(path, body, options) +client.api.delete(path, body, options) ``` ### Masquerading API @@ -118,14 +128,16 @@ This is an alternative to supplying the `masqueradeAs` parameter as a query para ```js // init the wyre client as usual -let wyre = new WyreClient({ /* your master api access setup here */ }); - -// create another sub-client authenticated as a particular user -let user1_wyre = wyre.masqueraded('AC-ABCDE12345'); - -// now use that client as normal! -user1_wyre.get('/v3/accounts/AC-ABCDE12345').then(successCallback, failureCallback); - +const client = new WyreClient({ /* your master api access setup here */ }); + +// Get sub-account with masquerade = true +client.fetchAccount('AC-sub-account-id', true) + .then((account) => { + console.log("I am Wyre sub-account ", account.id); + }) + .catch((err) => { + console.log("Problems, cap'n: ", err); + }) ``` ### Errors