@eximchain/dappbot-api-client
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -11,23 +11,11 @@ "use strict"; | ||
var builder = _a.builder; | ||
/** | ||
* ReqFactory: Log into DappBot. | ||
*/ | ||
this.builder = builder; | ||
// These functions are assigned in the constructor because | ||
// the builder requires arguments which are provided when | ||
// the overall class is instantiated. | ||
this.login = this.builder.reqFactoryWithArgs(auth_1.Login.Path, auth_1.Login.HTTP); | ||
/** | ||
* ReqFactory: Set a new password after account creation. | ||
*/ | ||
this.newPassword = this.builder.reqFactoryWithArgs(auth_1.NewPassChallenge.Path, auth_1.NewPassChallenge.HTTP); | ||
/** | ||
* ReqFactory: Refresh a user's authentication with DappBot. | ||
*/ | ||
this.refresh = this.builder.reqFactoryWithArgs(auth_1.Refresh.Path, auth_1.Refresh.HTTP); | ||
/** | ||
* ReqFactory: Begin a password reset. | ||
*/ | ||
this.beginPasswordReset = this.builder.reqFactoryWithArgs(auth_1.BeginPassReset.Path, auth_1.BeginPassReset.HTTP); | ||
/** | ||
* ReqFactory: Confirm a password reset. | ||
*/ | ||
this.confirmPasswordReset = this.builder.reqFactoryWithArgs(auth_1.ConfirmPassReset.Path, auth_1.ConfirmPassReset.HTTP); | ||
this.builder = builder; | ||
} | ||
@@ -34,0 +22,0 @@ return AuthAPI; |
@@ -10,28 +10,11 @@ "use strict"; | ||
var builder = _a.builder; | ||
/** | ||
* ReqFactory: Create a new account with DappBot. | ||
*/ | ||
this.builder = builder; | ||
// These functions are assigned in the constructor because | ||
// the builder requires arguments which are provided when | ||
// the overall class is instantiated. | ||
this.signUp = this.builder.reqFactoryWithArgs(payment_1.SignUp.Path, payment_1.SignUp.HTTP); | ||
/** | ||
* ReqFactory: Check your Stripe payment data, including | ||
* the customer, subscription, and their upcoming invoice. | ||
* Returns the most recent failed invoice if it exists. | ||
*/ | ||
this.readStripe = this.builder.reqFactoryWithArgs(payment_1.Read.Path, payment_1.Read.HTTP); | ||
/** | ||
* ReqFactory: Cancel your subscription to DappBot, deleting | ||
* all of your Dapps and stopping all future charges to your | ||
* card. | ||
*/ | ||
this.cancelSubscription = this.builder.reqFactoryWithArgs(payment_1.Cancel.Path, payment_1.Cancel.HTTP); | ||
/** | ||
* ReqFactory: Update the number of dapp slots you are | ||
* subscribed for. | ||
*/ | ||
this.updatePlanCounts = this.builder.reqFactoryWithArgs(payment_1.UpdatePlanCount.Path, payment_1.UpdatePlanCount.HTTP); | ||
/** | ||
* ReqFactory: Update the card associated with your Stripe account. | ||
*/ | ||
this.updateCard = this.builder.reqFactoryWithArgs(payment_1.UpdateCard.Path, payment_1.UpdateCard.HTTP); | ||
this.builder = builder; | ||
} | ||
@@ -38,0 +21,0 @@ return PaymentAPI; |
@@ -10,24 +10,11 @@ "use strict"; | ||
var builder = _a.builder; | ||
/** | ||
* ReqFactory: Create a new Dapp. | ||
*/ | ||
this.create = this.builder.reqFactoryWithArgsAndPath(private_1.CreateDapp.Path, private_1.CreateDapp.HTTP); | ||
/** | ||
* ReqFactory: Read one of your dapps' in the `Item.Api` format. | ||
*/ | ||
this.read = this.builder.reqFactoryWithArgsAndPath(private_1.ReadDapp.Path, private_1.ReadDapp.HTTP); | ||
/** | ||
* ReqFactory: Delete one of your dapps. | ||
*/ | ||
this.delete = this.builder.reqFactoryWithArgsAndPath(private_1.DeleteDapp.Path, private_1.DeleteDapp.HTTP); | ||
/** | ||
* ReqFactory: Update one of your dapps; only the `Item.Core` | ||
* attributes other than `DappName` are allowed to be updated. | ||
*/ | ||
this.update = this.builder.reqFactoryWithArgsAndPath(private_1.UpdateDapp.Path, private_1.UpdateDapp.HTTP); | ||
/** | ||
* ReqFactory: List all of your dapps. | ||
*/ | ||
this.list = this.builder.reqFactoryWithArgs(private_1.ListDapps.Path, private_1.ListDapps.HTTP); | ||
this.builder = builder; | ||
// These functions are assigned in the constructor because | ||
// the builder requires arguments which are provided when | ||
// the overall class is instantiated. | ||
this.createDapp = this.builder.reqFactoryWithArgsAndPath(private_1.CreateDapp.Path, private_1.CreateDapp.HTTP); | ||
this.readDapp = this.builder.reqFactoryWithArgsAndPath(private_1.ReadDapp.Path, private_1.ReadDapp.HTTP); | ||
this.updateDapp = this.builder.reqFactoryWithArgsAndPath(private_1.UpdateDapp.Path, private_1.UpdateDapp.HTTP); | ||
this.deleteDapp = this.builder.reqFactoryWithArgsAndPath(private_1.DeleteDapp.Path, private_1.DeleteDapp.HTTP); | ||
this.listDapps = this.builder.reqFactoryWithArgs(private_1.ListDapps.Path, private_1.ListDapps.HTTP); | ||
} | ||
@@ -34,0 +21,0 @@ return PrivateAPI; |
@@ -10,8 +10,7 @@ "use strict"; | ||
var builder = _a.builder; | ||
/** | ||
* ReqFactory: Get the `Item.Core` repesentation of any Dapp, | ||
* sufficient information required to render within `DappHub`. | ||
*/ | ||
this.view = this.builder.reqFactoryWithArgsAndPath(public_1.ViewDapp.Path, public_1.ViewDapp.HTTP); | ||
this.builder = builder; | ||
// These functions are assigned in the constructor because | ||
// the builder requires arguments which are provided when | ||
// the overall class is instantiated. | ||
this.viewDapp = this.builder.reqFactoryWithArgsAndPath(public_1.ViewDapp.Path, public_1.ViewDapp.HTTP); | ||
} | ||
@@ -18,0 +17,0 @@ return PublicAPI; |
"use strict"; | ||
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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
@@ -83,3 +84,3 @@ }); | ||
if (this.hasNoAuth()) { | ||
throw new Error("Please log in."); | ||
console.error("Please log in."); | ||
} | ||
@@ -106,4 +107,6 @@ if (!this.hasStaleAuth()) return [3 /*break*/, 2]; | ||
_a = this, authData = _a.authData, setAuthData = _a.setAuthData, dappbotUrl = _a.dappbotUrl; | ||
if (this.hasNoAuth()) | ||
throw new Error("Please log in."); | ||
if (this.hasNoAuth()) { | ||
console.error("Please log in."); | ||
return [2 /*return*/, this]; | ||
} | ||
refreshRequest = this.auth.refresh.request({ | ||
@@ -128,3 +131,4 @@ refreshToken: authData.RefreshToken | ||
setAuthData(user_1.default.newAuthData()); | ||
throw new Error("Unable to refresh your session, please log in again."); | ||
console.error("Unable to refresh your session, please log in again."); | ||
return [3 /*break*/, 4]; | ||
case 4: return [2 /*return*/]; | ||
@@ -151,3 +155,4 @@ } | ||
return false; | ||
return Date.now() > Date.parse(this.authData.ExpiresAt); | ||
var expiryDate = Date.parse(this.authData.ExpiresAt); | ||
return expiryDate !== NaN && Date.now() > expiryDate; | ||
}; | ||
@@ -160,4 +165,3 @@ /** | ||
API.prototype.hasNoAuth = function () { | ||
return (Date.parse(this.authData.ExpiresAt) === NaN || | ||
this.authData.RefreshToken === '' || | ||
return (this.authData.RefreshToken === '' || | ||
this.authData.Authorization === ''); | ||
@@ -164,0 +168,0 @@ }; |
@@ -5,3 +5,3 @@ "use strict"; | ||
var react_request_hook_1 = require("react-request-hook"); | ||
var methods_1 = require("@eximchain/dappbot-types/spec/methods"); | ||
var url = require('url'); | ||
var RequestBuilder = /** @class */ (function () { | ||
@@ -65,6 +65,6 @@ function RequestBuilder(_a) { | ||
*/ | ||
RequestBuilder.prototype.baseConf = function (path, method) { | ||
RequestBuilder.prototype.baseConf = function (method) { | ||
return { | ||
method: method, | ||
headers: this.buildHeaders(path) | ||
headers: this.buildHeaders() | ||
}; | ||
@@ -78,3 +78,3 @@ }; | ||
*/ | ||
RequestBuilder.prototype.buildFullPath = function (path) { return this.dappbotUrl + "/" + path; }; | ||
RequestBuilder.prototype.buildFullPath = function (path) { return url.format(url.resolve(this.dappbotUrl, path)); }; | ||
/** | ||
@@ -87,9 +87,7 @@ * Given a path string, returns an object with required headers to call | ||
*/ | ||
RequestBuilder.prototype.buildHeaders = function (path) { | ||
var privateResources = [methods_1.RootResources.private, methods_1.RootResources.payment]; | ||
function pathIncludes(name) { return path.indexOf(name) >= 0; } | ||
RequestBuilder.prototype.buildHeaders = function () { | ||
var headers = { | ||
'Content-Type': 'application/json' | ||
}; | ||
if (privateResources.some(pathIncludes) && this.authData) { | ||
if (this.authData.Authorization !== '') { | ||
headers.Authorization = this.authData.Authorization; | ||
@@ -107,3 +105,3 @@ } | ||
RequestBuilder.prototype.axiosConf = function (path, method, args) { | ||
return Object.assign(this.baseConf(path, method), { | ||
return Object.assign(this.baseConf(method), { | ||
data: args, | ||
@@ -134,5 +132,5 @@ url: this.buildFullPath(path) | ||
RequestBuilder.prototype.requestConf = function (path, method, args) { | ||
return Object.assign(this.baseConf(path, method), { | ||
return Object.assign(this.baseConf(method), { | ||
json: args, | ||
url: path | ||
url: this.buildFullPath(path) | ||
}); | ||
@@ -148,3 +146,3 @@ }; | ||
RequestBuilder.prototype.fetchConf = function (path, method, args) { | ||
return new node_fetch_1.Request(this.buildFullPath(path), Object.assign(this.baseConf(path, method), { body: JSON.stringify(args) })); | ||
return new node_fetch_1.Request(this.buildFullPath(path), Object.assign(this.baseConf(method), { body: JSON.stringify(args) })); | ||
}; | ||
@@ -151,0 +149,0 @@ return RequestBuilder; |
{ | ||
"name": "@eximchain/dappbot-api-client", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Typescript client for the DappBot API", | ||
@@ -20,3 +20,3 @@ "main": "dist/index.js", | ||
"author": "John O'Sullivan <john@eximchain.com>", | ||
"license": "UNLICENSED", | ||
"license": "MIT", | ||
"bugs": { | ||
@@ -27,3 +27,3 @@ "url": "https://github.com/Eximchain/dappbot-api-client/issues" | ||
"dependencies": { | ||
"@eximchain/dappbot-types": "^1.1.7", | ||
"@eximchain/dappbot-types": "^1.2.4", | ||
"@types/axios": "^0.14.0", | ||
@@ -47,2 +47,2 @@ "@types/lodash.omit": "^4.5.6", | ||
} | ||
} | ||
} |
import Auth, { | ||
Login, NewPassChallenge, Refresh, BeginPassReset, ConfirmPassReset | ||
} from '@eximchain/dappbot-types/spec/methods/auth'; | ||
import { APIModuleArgs } from '../types' | ||
import { APIModuleArgs, ReqFactoryWithArgs } from '../types' | ||
import RequestBuilder from '../requestBuilder'; | ||
@@ -14,4 +14,14 @@ | ||
constructor({ builder }: APIModuleArgs) { | ||
this.builder = builder; | ||
this.builder = builder; | ||
// These functions are assigned in the constructor because | ||
// the builder requires arguments which are provided when | ||
// the overall class is instantiated. | ||
this.login = this.builder.reqFactoryWithArgs<Login.Args, Login.Response>(Login.Path, Login.HTTP) | ||
this.newPassword = this.builder.reqFactoryWithArgs<NewPassChallenge.Args, NewPassChallenge.Response>(NewPassChallenge.Path, NewPassChallenge.HTTP); | ||
this.refresh = this.builder.reqFactoryWithArgs<Refresh.Args, Refresh.Response>(Refresh.Path, Refresh.HTTP); | ||
this.beginPasswordReset = this.builder.reqFactoryWithArgs<BeginPassReset.Args, BeginPassReset.Response>(BeginPassReset.Path, BeginPassReset.HTTP); | ||
this.confirmPasswordReset = this.builder.reqFactoryWithArgs<ConfirmPassReset.Args, ConfirmPassReset.Response>(ConfirmPassReset.Path, ConfirmPassReset.HTTP); | ||
} | ||
private builder: RequestBuilder | ||
@@ -22,27 +32,23 @@ | ||
*/ | ||
login = this.builder.reqFactoryWithArgs<Login.Args, Login.Response>(Login.Path, Login.HTTP) | ||
public login: ReqFactoryWithArgs<Login.Args, Login.Response> | ||
/** | ||
* ReqFactory: Set a new password after account creation. | ||
*/ | ||
newPassword = this.builder.reqFactoryWithArgs<NewPassChallenge.Args, NewPassChallenge.Response>(NewPassChallenge.Path, NewPassChallenge.HTTP); | ||
public newPassword: ReqFactoryWithArgs<NewPassChallenge.Args, NewPassChallenge.Response> | ||
/** | ||
* ReqFactory: Refresh a user's authentication with DappBot. | ||
*/ | ||
refresh = this.builder.reqFactoryWithArgs<Refresh.Args, Refresh.Response>(Refresh.Path, Refresh.HTTP); | ||
public refresh: ReqFactoryWithArgs<Refresh.Args, Refresh.Response> | ||
/** | ||
* ReqFactory: Begin a password reset. | ||
*/ | ||
beginPasswordReset = this.builder.reqFactoryWithArgs<BeginPassReset.Args, BeginPassReset.Response>(BeginPassReset.Path, BeginPassReset.HTTP); | ||
public beginPasswordReset: ReqFactoryWithArgs<BeginPassReset.Args, BeginPassReset.Response>; | ||
/** | ||
* ReqFactory: Confirm a password reset. | ||
*/ | ||
confirmPasswordReset = this.builder.reqFactoryWithArgs<ConfirmPassReset.Args, ConfirmPassReset.Response>(ConfirmPassReset.Path, ConfirmPassReset.HTTP); | ||
public confirmPasswordReset: ReqFactoryWithArgs<ConfirmPassReset.Args, ConfirmPassReset.Response>; | ||
} | ||
@@ -49,0 +55,0 @@ |
import { | ||
SignUp, Read, Cancel, UpdateCard, UpdatePlanCount | ||
} from '@eximchain/dappbot-types/spec/methods/payment'; | ||
import { APIModuleArgs } from '../types'; | ||
import { APIModuleArgs, ReqFactoryWithArgs } from '../types'; | ||
import RequestBuilder from '../requestBuilder'; | ||
@@ -13,3 +13,13 @@ | ||
this.builder = builder; | ||
// These functions are assigned in the constructor because | ||
// the builder requires arguments which are provided when | ||
// the overall class is instantiated. | ||
this.signUp = this.builder.reqFactoryWithArgs<SignUp.Args, SignUp.Response>(SignUp.Path, SignUp.HTTP); | ||
this.readStripe = this.builder.reqFactoryWithArgs<Read.Args, Read.Response>(Read.Path, Read.HTTP); | ||
this.cancelSubscription = this.builder.reqFactoryWithArgs<Cancel.Args, Cancel.Response>(Cancel.Path, Cancel.HTTP); | ||
this.updatePlanCounts = this.builder.reqFactoryWithArgs<UpdatePlanCount.Args, UpdatePlanCount.Response>(UpdatePlanCount.Path, UpdatePlanCount.HTTP); | ||
this.updateCard = this.builder.reqFactoryWithArgs<UpdateCard.Args, UpdateCard.Response>(UpdateCard.Path, UpdateCard.HTTP); | ||
} | ||
private builder:RequestBuilder | ||
@@ -20,5 +30,4 @@ | ||
*/ | ||
signUp = this.builder.reqFactoryWithArgs<SignUp.Args, SignUp.Response>(SignUp.Path, SignUp.HTTP); | ||
public signUp: ReqFactoryWithArgs<SignUp.Args, SignUp.Response> | ||
/** | ||
@@ -29,5 +38,4 @@ * ReqFactory: Check your Stripe payment data, including | ||
*/ | ||
readStripe = this.builder.reqFactoryWithArgs<Read.Args, Read.Response>(Read.Path, Read.HTTP); | ||
public readStripe: ReqFactoryWithArgs<Read.Args, Read.Response> | ||
/** | ||
@@ -38,5 +46,4 @@ * ReqFactory: Cancel your subscription to DappBot, deleting | ||
*/ | ||
cancelSubscription = this.builder.reqFactoryWithArgs<Cancel.Args, Cancel.Response>(Cancel.Path, Cancel.HTTP); | ||
public cancelSubscription: ReqFactoryWithArgs<Cancel.Args, Cancel.Response> | ||
/** | ||
@@ -46,3 +53,3 @@ * ReqFactory: Update the number of dapp slots you are | ||
*/ | ||
updatePlanCounts = this.builder.reqFactoryWithArgs<UpdatePlanCount.Args, UpdatePlanCount.Response>(UpdatePlanCount.Path, UpdatePlanCount.HTTP); | ||
public updatePlanCounts: ReqFactoryWithArgs<UpdatePlanCount.Args, UpdatePlanCount.Response>; | ||
@@ -52,5 +59,5 @@ /** | ||
*/ | ||
updateCard = this.builder.reqFactoryWithArgs<UpdateCard.Args, UpdateCard.Response>(UpdateCard.Path, UpdateCard.HTTP); | ||
public updateCard: ReqFactoryWithArgs<UpdateCard.Args, UpdateCard.Response> | ||
} | ||
export default PaymentAPI; |
import { | ||
CreateDapp, DeleteDapp, UpdateDapp, ReadDapp, ListDapps | ||
} from '@eximchain/dappbot-types/spec/methods/private'; | ||
import { APIModuleArgs } from '../types'; | ||
import { APIModuleArgs, ReqFactoryWithArgs, ReqFactoryWithArgsAndPath } from '../types'; | ||
import RequestBuilder from '../requestBuilder'; | ||
@@ -13,2 +13,11 @@ | ||
this.builder = builder; | ||
// These functions are assigned in the constructor because | ||
// the builder requires arguments which are provided when | ||
// the overall class is instantiated. | ||
this.createDapp = this.builder.reqFactoryWithArgsAndPath<CreateDapp.Args, CreateDapp.Response>(CreateDapp.Path, CreateDapp.HTTP); | ||
this.readDapp = this.builder.reqFactoryWithArgsAndPath<ReadDapp.Args, ReadDapp.Response>(ReadDapp.Path, ReadDapp.HTTP) | ||
this.updateDapp = this.builder.reqFactoryWithArgsAndPath<UpdateDapp.Args, UpdateDapp.Response>(UpdateDapp.Path, UpdateDapp.HTTP); | ||
this.deleteDapp = this.builder.reqFactoryWithArgsAndPath<DeleteDapp.Args, DeleteDapp.Response>(DeleteDapp.Path, DeleteDapp.HTTP); | ||
this.listDapps = this.builder.reqFactoryWithArgs<ListDapps.Args, ListDapps.Response>(ListDapps.Path, ListDapps.HTTP); | ||
} | ||
@@ -20,23 +29,20 @@ private builder:RequestBuilder | ||
*/ | ||
create = this.builder.reqFactoryWithArgsAndPath<CreateDapp.Args, CreateDapp.Response>(CreateDapp.Path, CreateDapp.HTTP); | ||
public createDapp: ReqFactoryWithArgsAndPath<CreateDapp.Args, CreateDapp.Response> | ||
/** | ||
* ReqFactory: Read one of your dapps' in the `Item.Api` format. | ||
*/ | ||
read = this.builder.reqFactoryWithArgsAndPath<ReadDapp.Args, ReadDapp.Response>(ReadDapp.Path, ReadDapp.HTTP) | ||
public readDapp: ReqFactoryWithArgsAndPath<ReadDapp.Args, ReadDapp.Response> | ||
/** | ||
* ReqFactory: Delete one of your dapps. | ||
*/ | ||
delete = this.builder.reqFactoryWithArgsAndPath<DeleteDapp.Args, DeleteDapp.Response>(DeleteDapp.Path, DeleteDapp.HTTP) | ||
public deleteDapp: ReqFactoryWithArgsAndPath<DeleteDapp.Args, DeleteDapp.Response> | ||
/** | ||
* ReqFactory: Update one of your dapps; only the `Item.Core` | ||
* attributes other than `DappName` are allowed to be updated. | ||
* attributes other than `DappName` are allowed to be updated, | ||
* and at least one must be set. | ||
*/ | ||
update = this.builder.reqFactoryWithArgsAndPath<UpdateDapp.Args, UpdateDapp.Response>(UpdateDapp.Path, UpdateDapp.HTTP) | ||
public updateDapp: ReqFactoryWithArgsAndPath<UpdateDapp.Args, UpdateDapp.Response> | ||
@@ -46,5 +52,6 @@ /** | ||
*/ | ||
list = this.builder.reqFactoryWithArgs<ListDapps.Args, ListDapps.Response>(ListDapps.Path, ListDapps.HTTP); | ||
public listDapps: ReqFactoryWithArgs<ListDapps.Args, ListDapps.Response> | ||
} | ||
export default PrivateAPI; |
import { ViewDapp } from '@eximchain/dappbot-types/spec/methods/public'; | ||
import { APIModuleArgs } from '../types'; | ||
import { APIModuleArgs, ReqFactoryWithArgsAndPath } from '../types'; | ||
import RequestBuilder from '../requestBuilder'; | ||
@@ -11,2 +11,7 @@ | ||
this.builder = builder; | ||
// These functions are assigned in the constructor because | ||
// the builder requires arguments which are provided when | ||
// the overall class is instantiated. | ||
this.viewDapp = this.builder.reqFactoryWithArgsAndPath<ViewDapp.Args, ViewDapp.Response>(ViewDapp.Path, ViewDapp.HTTP); | ||
} | ||
@@ -20,5 +25,5 @@ private builder:RequestBuilder | ||
*/ | ||
view = this.builder.reqFactoryWithArgsAndPath<ViewDapp.Args, ViewDapp.Response>(ViewDapp.Path, ViewDapp.HTTP); | ||
public viewDapp: ReqFactoryWithArgsAndPath<ViewDapp.Args, ViewDapp.Response> | ||
} | ||
export default PublicAPI; |
@@ -74,3 +74,3 @@ import User from '@eximchain/dappbot-types/spec/user'; | ||
if (this.hasNoAuth()){ | ||
throw new Error("Please log in.") | ||
console.error("Please log in."); | ||
} | ||
@@ -92,3 +92,6 @@ | ||
const { authData, setAuthData, dappbotUrl } = this; | ||
if (this.hasNoAuth()) throw new Error("Please log in."); | ||
if (this.hasNoAuth()) { | ||
console.error("Please log in."); | ||
return this; | ||
} | ||
const refreshRequest = this.auth.refresh.request({ | ||
@@ -110,3 +113,3 @@ refreshToken : authData.RefreshToken | ||
setAuthData(User.newAuthData()); | ||
throw new Error("Unable to refresh your session, please log in again."); | ||
console.error("Unable to refresh your session, please log in again."); | ||
} | ||
@@ -131,3 +134,4 @@ } | ||
if (this.hasNoAuth()) return false; | ||
return Date.now() > Date.parse(this.authData.ExpiresAt) | ||
let expiryDate = Date.parse(this.authData.ExpiresAt); | ||
return expiryDate !== NaN && Date.now() > expiryDate; | ||
} | ||
@@ -142,3 +146,2 @@ | ||
return ( | ||
Date.parse(this.authData.ExpiresAt) === NaN || | ||
this.authData.RefreshToken === '' || | ||
@@ -145,0 +148,0 @@ this.authData.Authorization === '' |
@@ -7,2 +7,3 @@ import { Request as FetchRequest, RequestInfo } from 'node-fetch'; | ||
import { Headers, ReqTypes, ReqFactoryWithArgs, ReqFactoryWithArgsAndPath } from './types'; | ||
const url = require('url') | ||
@@ -13,2 +14,3 @@ export interface RequestBuilderConfig { | ||
} | ||
export class RequestBuilder { | ||
@@ -37,3 +39,3 @@ constructor({ dappbotUrl, authData }: RequestBuilderConfig) { | ||
*/ | ||
reqFactoryWithArgs<Args, Returns>( | ||
public reqFactoryWithArgs<Args, Returns>( | ||
path:string, method:HttpMethods.ANY | ||
@@ -62,3 +64,3 @@ ):ReqFactoryWithArgs<Args, Returns> { | ||
*/ | ||
reqFactoryWithArgsAndPath<Args, Returns>( | ||
public reqFactoryWithArgsAndPath<Args, Returns>( | ||
path:(suffix:string)=>string, method:HttpMethods.ANY | ||
@@ -81,6 +83,6 @@ ):ReqFactoryWithArgsAndPath<Args, Returns> { | ||
*/ | ||
private baseConf(path: string, method: HttpMethods.ANY): ReqTypes.base { | ||
private baseConf(method: HttpMethods.ANY): ReqTypes.base { | ||
return { | ||
method: method, | ||
headers: this.buildHeaders(path) | ||
headers: this.buildHeaders() | ||
} | ||
@@ -95,3 +97,3 @@ } | ||
*/ | ||
buildFullPath(path: string) { return `${this.dappbotUrl}/${path}` } | ||
buildFullPath(path: string) { return url.format(url.resolve(this.dappbotUrl, path)) } | ||
@@ -105,9 +107,7 @@ /** | ||
*/ | ||
buildHeaders(path: string) { | ||
let privateResources = [RootResources.private, RootResources.payment]; | ||
function pathIncludes(name: string) { return path.indexOf(name) >= 0 } | ||
buildHeaders() { | ||
const headers: Headers = { | ||
'Content-Type': 'application/json' | ||
} | ||
if (privateResources.some(pathIncludes) && this.authData) { | ||
if (this.authData.Authorization !== '') { | ||
headers.Authorization = this.authData.Authorization; | ||
@@ -127,3 +127,3 @@ } | ||
return Object.assign( | ||
this.baseConf(path, method), | ||
this.baseConf(method), | ||
{ | ||
@@ -159,6 +159,6 @@ data: args, | ||
return Object.assign( | ||
this.baseConf(path, method), | ||
this.baseConf(method), | ||
{ | ||
json: args, | ||
url: path | ||
url: this.buildFullPath(path) | ||
} | ||
@@ -177,3 +177,3 @@ ); | ||
return new FetchRequest(this.buildFullPath(path), Object.assign( | ||
this.baseConf(path, method), | ||
this.baseConf(method), | ||
{ body: JSON.stringify(args) } | ||
@@ -180,0 +180,0 @@ )); |
Misc. License Issues
License(Experimental) A package's licensing information has fine-grained problems.
Found 1 instance in 1 package
309707
23
0
931