@fusionauth/typescript-client
Advanced tools
Comparing version 1.10.0 to 1.10.1
@@ -6,2 +6,3 @@ import IRESTClient from "./IRESTClient"; | ||
* @author Tyler Scott | ||
* @author TJ Peden | ||
*/ | ||
@@ -11,10 +12,7 @@ export default class DefaultRESTClient implements IRESTClient { | ||
body: string; | ||
headers: { | ||
[key: string]: string; | ||
}; | ||
headers: Record<string, string>; | ||
method: string; | ||
parameters: { | ||
[key: string]: string; | ||
}; | ||
parameters: Record<string, string>; | ||
uri: string; | ||
credentials: RequestCredentials; | ||
constructor(host: string); | ||
@@ -27,7 +25,7 @@ /** | ||
*/ | ||
withAuthorization(key: any): DefaultRESTClient; | ||
withAuthorization(key: string): DefaultRESTClient; | ||
/** | ||
* Adds a segment to the request uri | ||
*/ | ||
withUriSegment(segment: any): DefaultRESTClient; | ||
withUriSegment(segment: string | number): DefaultRESTClient; | ||
/** | ||
@@ -53,7 +51,7 @@ * Get the full url + parameter list | ||
*/ | ||
withMethod(method: any): DefaultRESTClient; | ||
withMethod(method: string): DefaultRESTClient; | ||
/** | ||
* Sets the uri of the request | ||
*/ | ||
withUri(uri: any): DefaultRESTClient; | ||
withUri(uri: string): DefaultRESTClient; | ||
/** | ||
@@ -65,4 +63,10 @@ * Adds parameters to the request. | ||
*/ | ||
withParameter(name: any, value: any): DefaultRESTClient; | ||
withParameter(name: string, value: any): DefaultRESTClient; | ||
/** | ||
* Sets request's credentials. | ||
* | ||
* @param value A string indicating whether credentials will be sent with the request always, never, or only when sent to a same-origin URL. | ||
*/ | ||
withCredentials(value: RequestCredentials): DefaultRESTClient; | ||
/** | ||
* Run the request and return a promise. This promise will resolve if the request is successful | ||
@@ -69,0 +73,0 @@ * and reject otherwise. |
@@ -17,8 +17,17 @@ "use strict"; | ||
*/ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
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); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const ClientResponse_1 = require("./ClientResponse"); | ||
let request = require("request"); | ||
const cross_fetch_1 = require("cross-fetch"); | ||
/** | ||
* @author Brett P | ||
* @author Tyler Scott | ||
* @author TJ Peden | ||
*/ | ||
@@ -112,2 +121,11 @@ class DefaultRESTClient { | ||
/** | ||
* Sets request's credentials. | ||
* | ||
* @param value A string indicating whether credentials will be sent with the request always, never, or only when sent to a same-origin URL. | ||
*/ | ||
withCredentials(value) { | ||
this.credentials = value; | ||
return this; | ||
} | ||
/** | ||
* Run the request and return a promise. This promise will resolve if the request is successful | ||
@@ -117,30 +135,21 @@ * and reject otherwise. | ||
go() { | ||
return new Promise((resolve, reject) => { | ||
request({ | ||
uri: this.getFullUrl(), | ||
method: this.method, | ||
headers: this.headers, | ||
body: this.body | ||
}, (error, response, body) => { | ||
let clientResponse = new ClientResponse_1.default(); | ||
if (error) { | ||
clientResponse.exception = error; | ||
reject(clientResponse); | ||
} | ||
else { | ||
clientResponse.statusCode = response.statusCode; | ||
clientResponse.response = body; | ||
try { // Try parsing as json | ||
clientResponse.response = JSON.parse(body); | ||
} | ||
catch (e) { | ||
} | ||
if (clientResponse.wasSuccessful()) { | ||
resolve(clientResponse); | ||
} | ||
else { | ||
reject(clientResponse); | ||
} | ||
} | ||
}); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const clientResponse = new ClientResponse_1.default(); | ||
try { | ||
const response = yield cross_fetch_1.default(this.getFullUrl(), { | ||
method: this.method, | ||
headers: this.headers, | ||
body: this.body, | ||
credentials: this.credentials, | ||
}); | ||
clientResponse.statusCode = response.status; | ||
clientResponse.response = yield response.json(); | ||
} | ||
catch (error) { | ||
clientResponse.exception = error; | ||
} | ||
if (!clientResponse.wasSuccessful()) { | ||
throw clientResponse; | ||
} | ||
return clientResponse; | ||
}); | ||
@@ -147,0 +156,0 @@ } |
@@ -9,7 +9,7 @@ import ClientResponse from "./ClientResponse"; | ||
*/ | ||
withAuthorization(key: any): IRESTClient; | ||
withAuthorization(key: string): IRESTClient; | ||
/** | ||
* Adds a segment to the request uri | ||
*/ | ||
withUriSegment(segment: any): IRESTClient; | ||
withUriSegment(segment: string | number): IRESTClient; | ||
/** | ||
@@ -31,7 +31,7 @@ * Adds a header to the request. | ||
*/ | ||
withMethod(method: any): IRESTClient; | ||
withMethod(method: string): IRESTClient; | ||
/** | ||
* Sets the uri of the request | ||
*/ | ||
withUri(uri: any): IRESTClient; | ||
withUri(uri: string): IRESTClient; | ||
/** | ||
@@ -43,4 +43,10 @@ * Adds parameters to the request. | ||
*/ | ||
withParameter(name: any, value: any): IRESTClient; | ||
withParameter(name: string, value: any): IRESTClient; | ||
/** | ||
* Sets request's credentials. | ||
* | ||
* @param value A string indicating whether credentials will be sent with the request always, never, or only when sent to a same-origin URL. | ||
*/ | ||
withCredentials(value: RequestCredentials): IRESTClient; | ||
/** | ||
* Run the request and return a promise. This promise will resolve if the request is successful | ||
@@ -47,0 +53,0 @@ * and reject otherwise. |
{ | ||
"name": "@fusionauth/typescript-client", | ||
"version": "1.10.0", | ||
"version": "1.10.1", | ||
"description": "A typescript implementation of the FusionAuth client.", | ||
@@ -54,4 +54,3 @@ "main": "build/index.js", | ||
"dependencies": { | ||
"request": "^2.88.0", | ||
"xhr": "^2.5.0" | ||
"cross-fetch": "^3.0.4" | ||
}, | ||
@@ -58,0 +57,0 @@ "browser": { |
@@ -8,3 +8,6 @@ ## FusionAuth TypeScript Client | ||
Installation | ||
## Credits | ||
* Thanks to [@tjpeden](https://github.com/tjpeden) for your excellent contributions! | ||
## Installation | ||
To install fusionauth-typescript-client, use npm | ||
@@ -11,0 +14,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
311713
1
21
7108
+ Addedcross-fetch@^3.0.4
+ Addedcross-fetch@3.1.8(transitive)
+ Addednode-fetch@2.7.0(transitive)
+ Addedtr46@0.0.3(transitive)
+ Addedwebidl-conversions@3.0.1(transitive)
+ Addedwhatwg-url@5.0.0(transitive)
- Removedrequest@^2.88.0
- Removedxhr@^2.5.0
- Removedajv@6.12.6(transitive)
- Removedasn1@0.2.6(transitive)
- Removedassert-plus@1.0.0(transitive)
- Removedasynckit@0.4.0(transitive)
- Removedaws-sign2@0.7.0(transitive)
- Removedaws4@1.13.2(transitive)
- Removedbcrypt-pbkdf@1.0.2(transitive)
- Removedcaseless@0.12.0(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removedcore-util-is@1.0.2(transitive)
- Removeddashdash@1.14.1(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removeddom-walk@0.1.2(transitive)
- Removedecc-jsbn@0.1.2(transitive)
- Removedextend@3.0.2(transitive)
- Removedextsprintf@1.3.0(transitive)
- Removedfast-deep-equal@3.1.3(transitive)
- Removedfast-json-stable-stringify@2.1.0(transitive)
- Removedforever-agent@0.6.1(transitive)
- Removedform-data@2.3.3(transitive)
- Removedgetpass@0.1.7(transitive)
- Removedglobal@4.4.0(transitive)
- Removedhar-schema@2.0.0(transitive)
- Removedhar-validator@5.1.5(transitive)
- Removedhttp-signature@1.2.0(transitive)
- Removedis-function@1.0.2(transitive)
- Removedis-typedarray@1.0.0(transitive)
- Removedisstream@0.1.2(transitive)
- Removedjsbn@0.1.1(transitive)
- Removedjson-schema@0.4.0(transitive)
- Removedjson-schema-traverse@0.4.1(transitive)
- Removedjson-stringify-safe@5.0.1(transitive)
- Removedjsprim@1.4.2(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removedmin-document@2.19.0(transitive)
- Removedoauth-sign@0.9.0(transitive)
- Removedparse-headers@2.0.5(transitive)
- Removedperformance-now@2.1.0(transitive)
- Removedprocess@0.11.10(transitive)
- Removedpsl@1.15.0(transitive)
- Removedpunycode@2.3.1(transitive)
- Removedqs@6.5.3(transitive)
- Removedrequest@2.88.2(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsshpk@1.18.0(transitive)
- Removedtough-cookie@2.5.0(transitive)
- Removedtunnel-agent@0.6.0(transitive)
- Removedtweetnacl@0.14.5(transitive)
- Removeduri-js@4.4.1(transitive)
- Removeduuid@3.4.0(transitive)
- Removedverror@1.10.0(transitive)
- Removedxhr@2.6.0(transitive)
- Removedxtend@4.0.2(transitive)