UNPKG

@fusionauth/typescript-client

Version:
1,016 lines (1,004 loc) 901 kB
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.FusionAuth = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){ "use strict"; /* * Copyright (c) 2019, FusionAuth, All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific * language governing permissions and limitations under the License. */ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); }; Object.defineProperty(exports, "__esModule", { value: true }); var FusionAuthClient_1 = require("./src/FusionAuthClient"); exports.default = FusionAuthClient_1.default; __exportStar(require("./src/FusionAuthClient"), exports); __exportStar(require("./src/IRESTClient"), exports); __exportStar(require("./src/DefaultRESTClientBuilder"), exports); __exportStar(require("./src/ClientResponse"), exports); __exportStar(require("./src/IRESTClient"), exports); __exportStar(require("./src/IRESTClientBuilder"), exports); },{"./src/ClientResponse":3,"./src/DefaultRESTClientBuilder":5,"./src/FusionAuthClient":6,"./src/IRESTClient":7,"./src/IRESTClientBuilder":8}],2:[function(require,module,exports){ (function (global){(function (){ "use strict"; // ref: https://github.com/tc39/proposal-global var getGlobal = function () { // the only reliable means to get the global object is // `Function('return this')()` // However, this causes CSP violations in Chrome apps. if (typeof self !== 'undefined') { return self; } if (typeof window !== 'undefined') { return window; } if (typeof global !== 'undefined') { return global; } throw new Error('unable to locate global object'); } var globalObject = getGlobal(); module.exports = exports = globalObject.fetch; // Needed for TypeScript and Webpack. if (globalObject.fetch) { exports.default = globalObject.fetch.bind(globalObject); } exports.Headers = globalObject.Headers; exports.Request = globalObject.Request; exports.Response = globalObject.Response; }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) },{}],3:[function(require,module,exports){ "use strict"; /* * Copyright (c) 2019, FusionAuth, All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific * language governing permissions and limitations under the License. */ Object.defineProperty(exports, "__esModule", { value: true }); var ClientResponse = /** @class */ (function () { function ClientResponse() { } ClientResponse.prototype.wasSuccessful = function () { return this.statusCode >= 200 && this.statusCode < 300; }; return ClientResponse; }()); exports.default = ClientResponse; },{}],4:[function(require,module,exports){ (function (global){(function (){ "use strict"; /* * Copyright (c) 2019-2020, FusionAuth, All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific * language governing permissions and limitations under the License. */ 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 ClientResponse_1 = require("./ClientResponse"); var node_fetch_1 = require("node-fetch"); var url_1 = (typeof window !== "undefined" ? window['window'] : typeof global !== "undefined" ? global['window'] : null); /** * @author Brett P * @author Tyler Scott * @author TJ Peden */ var DefaultRESTClient = /** @class */ (function () { function DefaultRESTClient(host) { this.host = host; this.headers = {}; this.parameters = {}; this.responseHandler = DefaultRESTClient.JSONResponseHandler; this.errorResponseHandler = DefaultRESTClient.ErrorJSONResponseHandler; } /** * Sets the authorization header using a key * * @param {string} key The value of the authorization header. * @returns {DefaultRESTClient} */ DefaultRESTClient.prototype.withAuthorization = function (key) { if (key === null || typeof key === 'undefined') { return this; } this.withHeader('Authorization', key); return this; }; /** * Adds a segment to the request uri */ DefaultRESTClient.prototype.withUriSegment = function (segment) { if (segment === null || segment === undefined) { return this; } if (this.uri === null) { this.uri = ''; } if (this.uri.charAt(this.uri.length - 1) !== '/') { this.uri += '/'; } this.uri = this.uri + segment; return this; }; /** * Get the full url + parameter list */ DefaultRESTClient.prototype.getFullUrl = function () { return this.host + this.uri + this.getQueryString(); }; /** * Sets the body of the client request. * * @param body The object to be written to the request body as form data. */ DefaultRESTClient.prototype.withFormData = function (body) { var body2 = new url_1.URLSearchParams(); if (body) { body.forEach(function (value, name, searchParams) { if (value && value.length > 0 && value != "null" && value != "undefined") { body2.set(name, value); } }); body = body2; } this.body = body; this.withHeader('Content-Type', 'application/x-www-form-urlencoded'); return this; }; /** * Adds a header to the request. * * @param key The name of the header. * @param value The value of the header. */ DefaultRESTClient.prototype.withHeader = function (key, value) { this.headers[key] = value; return this; }; /** * Sets the body of the client request. * * @param body The object to be written to the request body as JSON. */ DefaultRESTClient.prototype.withJSONBody = function (body) { this.body = JSON.stringify(body); this.withHeader('Content-Type', 'application/json'); // Omit the Content-Length, this is set auto-magically by the request library return this; }; /** * Sets the http method for the request */ DefaultRESTClient.prototype.withMethod = function (method) { this.method = method; return this; }; /** * Sets the uri of the request */ DefaultRESTClient.prototype.withUri = function (uri) { this.uri = uri; return this; }; /** * Adds parameters to the request. * * @param name The name of the parameter. * @param value The value of the parameter, may be a string, object or number. */ DefaultRESTClient.prototype.withParameter = function (name, value) { this.parameters[name] = value; return this; }; /** * 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. */ DefaultRESTClient.prototype.withCredentials = function (value) { this.credentials = value; return this; }; DefaultRESTClient.prototype.withResponseHandler = function (handler) { this.responseHandler = handler; return this; }; DefaultRESTClient.prototype.withErrorResponseHandler = function (handler) { this.errorResponseHandler = handler; return this; }; /** * Run the request and return a promise. This promise will resolve if the request is successful * and reject otherwise. */ DefaultRESTClient.prototype.go = function () { return __awaiter(this, void 0, void 0, function () { var clientResponse, response, error_1; return __generator(this, function (_a) { switch (_a.label) { case 0: clientResponse = new ClientResponse_1.default(); _a.label = 1; case 1: _a.trys.push([1, 7, , 8]); return [4 /*yield*/, node_fetch_1.default(this.getFullUrl(), { method: this.method, headers: this.headers, body: this.body, // @ts-ignore (Credentials are not supported on NodeJS) credentials: this.credentials, })]; case 2: response = _a.sent(); if (!response.ok) return [3 /*break*/, 4]; return [4 /*yield*/, this.responseHandler(response)]; case 3: return [2 /*return*/, _a.sent()]; case 4: return [4 /*yield*/, this.errorResponseHandler(response)]; case 5: throw _a.sent(); case 6: return [3 /*break*/, 8]; case 7: error_1 = _a.sent(); if (error_1 instanceof ClientResponse_1.default) { throw error_1; // Don't catch a ClientResponse (we want this to trigger the catch of the promise } if (response) { // Try to recover the response status clientResponse.statusCode = response.status; } clientResponse.exception = error_1; throw clientResponse; case 8: return [2 /*return*/]; } }); }); }; DefaultRESTClient.prototype.getQueryString = function () { var queryString = ''; for (var key in this.parameters) { queryString += (queryString.length === 0) ? '?' : '&'; queryString += key + '=' + encodeURIComponent(this.parameters[key]); } return queryString; }; /** * A function that returns the JSON form of the response text. * * @param response * @constructor */ DefaultRESTClient.JSONResponseHandler = function (response) { return __awaiter(this, void 0, void 0, function () { var clientResponse, type, _a; return __generator(this, function (_b) { switch (_b.label) { case 0: clientResponse = new ClientResponse_1.default(); clientResponse.statusCode = response.status; type = response.headers.get("content-type"); if (!(type && type.startsWith("application/json"))) return [3 /*break*/, 2]; _a = clientResponse; return [4 /*yield*/, response.json()]; case 1: _a.response = _b.sent(); _b.label = 2; case 2: return [2 /*return*/, clientResponse]; } }); }); }; /** * A function that returns the JSON form of the response text. * * @param response * @constructor */ DefaultRESTClient.ErrorJSONResponseHandler = function (response) { return __awaiter(this, void 0, void 0, function () { var clientResponse, type, _a; return __generator(this, function (_b) { switch (_b.label) { case 0: clientResponse = new ClientResponse_1.default(); clientResponse.statusCode = response.status; type = response.headers.get("content-type"); if (!(type && type.startsWith("application/json"))) return [3 /*break*/, 2]; _a = clientResponse; return [4 /*yield*/, response.json()]; case 1: _a.exception = _b.sent(); _b.label = 2; case 2: return [2 /*return*/, clientResponse]; } }); }); }; return DefaultRESTClient; }()); exports.default = DefaultRESTClient; }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) },{"./ClientResponse":3,"node-fetch":2}],5:[function(require,module,exports){ "use strict"; /* * Copyright (c) 2019, FusionAuth, All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific * language governing permissions and limitations under the License. */ Object.defineProperty(exports, "__esModule", { value: true }); var DefaultRESTClient_1 = require("./DefaultRESTClient"); var DefaultRESTClientBuilder = /** @class */ (function () { function DefaultRESTClientBuilder() { } DefaultRESTClientBuilder.prototype.build = function (host) { return new DefaultRESTClient_1.default(host); }; return DefaultRESTClientBuilder; }()); exports.default = DefaultRESTClientBuilder; },{"./DefaultRESTClient":4}],6:[function(require,module,exports){ (function (global){(function (){ "use strict"; /* * Copyright (c) 2019-2023, FusionAuth, All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific * language governing permissions and limitations under the License. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.IdentityProviderLoginMethod = exports.ClientAuthenticationMethod = exports.OAuthErrorReason = exports.WebAuthnWorkflow = exports.Oauth2AuthorizedURLValidationPolicy = exports.LogoutBehavior = exports.RateLimitedRequestType = exports.CanonicalizationMethod = exports.SecureGeneratorType = exports.VerificationStrategy = exports.UniqueUsernameStrategy = exports.LDAPSecurityMethod = exports.TOTPAlgorithm = exports.EventType = exports.IdentityProviderType = exports.MessengerType = exports.ExpiryUnit = exports.EmailSecurityType = exports.ChangePasswordReason = exports.SteamAPIMode = exports.UserVerificationRequirement = exports.TransactionType = exports.FamilyRole = exports.KeyUse = exports.Algorithm = exports.EventLogType = exports.BreachAction = exports.IdentityProviderLinkingStrategy = exports.SAMLLogoutBehavior = exports.Sort = exports.OAuthErrorType = exports.LambdaEngineType = exports.UserActionPhase = exports.UnverifiedBehavior = exports.RefreshTokenExpirationPolicy = exports.RegistrationType = exports.LoginIdType = exports.CoseEllipticCurve = exports.AuthenticatorAttachment = exports.MultiFactorLoginPolicy = exports.ConnectorType = exports.KeyType = exports.AttestationType = exports.FormType = exports.KeyAlgorithm = exports.CaptchaMethod = exports.DeviceType = exports.RefreshTokenUsagePolicy = exports.ClientAuthenticationPolicy = exports.ResidentKeyRequirement = exports.AuthenticationThreats = exports.ObjectState = exports.AttestationConveyancePreference = exports.LambdaType = exports.CoseAlgorithmIdentifier = exports.HTTPMethod = exports.FormFieldAdminPolicy = exports.PublicKeyCredentialType = exports.SAMLv2DestinationAssertionPolicy = exports.CoseKeyType = exports.BreachMatchMode = exports.FormControl = exports.ContentStatus = exports.MessageType = exports.IPAccessControlEntryAction = exports.AuthenticatorAttachmentPreference = exports.XMLSignatureLocation = exports.TokenType = exports.ProofKeyForCodeExchangePolicy = exports.ReactorFeatureStatus = exports.GrantType = exports.UserState = exports.ApplicationMultiFactorTrustPolicy = exports.ConsentStatus = exports.BreachedPasswordStatus = exports.FormDataType = exports.FusionAuthClient = void 0; var DefaultRESTClientBuilder_1 = require("./DefaultRESTClientBuilder"); var url_1 = (typeof window !== "undefined" ? window['window'] : typeof global !== "undefined" ? global['window'] : null); var FusionAuthClient = /** @class */ (function () { function FusionAuthClient(apiKey, host, tenantId) { this.apiKey = apiKey; this.host = host; this.tenantId = tenantId; this.clientBuilder = new DefaultRESTClientBuilder_1.default(); } /** * Sets the tenant id, that will be included in the X-FusionAuth-TenantId header. * * @param {string | null} tenantId The value of the X-FusionAuth-TenantId header. * @returns {FusionAuthClient} */ FusionAuthClient.prototype.setTenantId = function (tenantId) { this.tenantId = tenantId; return this; }; /** * Sets whether and how cookies will be sent with each request. * * @param value The value that indicates whether and how cookies will be sent. * @returns {FusionAuthClient} */ FusionAuthClient.prototype.setRequestCredentials = function (value) { this.credentials = value; return this; }; /** * Takes an action on a user. The user being actioned is called the "actionee" and the user taking the action is called the * "actioner". Both user ids are required in the request object. * * @param {ActionRequest} request The action request that includes all the information about the action being taken including * the id of the action, any options and the duration (if applicable). * @returns {Promise<ClientResponse<ActionResponse>>} */ FusionAuthClient.prototype.actionUser = function (request) { return this.start() .withUri('/api/user/action') .withJSONBody(request) .withMethod("POST") .go(); }; /** * Activates the FusionAuth Reactor using a license id and optionally a license text (for air-gapped deployments) * * @param {ReactorRequest} request An optional request that contains the license text to activate Reactor (useful for air-gap deployments of FusionAuth). * @returns {Promise<ClientResponse<void>>} */ FusionAuthClient.prototype.activateReactor = function (request) { return this.start() .withUri('/api/reactor') .withJSONBody(request) .withMethod("POST") .go(); }; /** * Adds a user to an existing family. The family id must be specified. * * @param {UUID} familyId The id of the family. * @param {FamilyRequest} request The request object that contains all the information used to determine which user to add to the family. * @returns {Promise<ClientResponse<FamilyResponse>>} */ FusionAuthClient.prototype.addUserToFamily = function (familyId, request) { return this.start() .withUri('/api/user/family') .withUriSegment(familyId) .withJSONBody(request) .withMethod("PUT") .go(); }; /** * Approve a device grant. * * @param {string} client_id (Optional) The unique client identifier. The client Id is the Id of the FusionAuth Application in which you are attempting to authenticate. * @param {string} client_secret (Optional) The client secret. This value will be required if client authentication is enabled. * @param {string} token The access token used to identify the user. * @param {string} user_code The end-user verification code. * @returns {Promise<ClientResponse<DeviceApprovalResponse>>} */ FusionAuthClient.prototype.approveDevice = function (client_id, client_secret, token, user_code) { var body = new url_1.URLSearchParams(); body.append('client_id', client_id); body.append('client_secret', client_secret); body.append('token', token); body.append('user_code', user_code); return this.start() .withUri('/oauth2/device/approve') .withFormData(body) .withMethod("POST") .go(); }; /** * Cancels the user action. * * @param {UUID} actionId The action id of the action to cancel. * @param {ActionRequest} request The action request that contains the information about the cancellation. * @returns {Promise<ClientResponse<ActionResponse>>} */ FusionAuthClient.prototype.cancelAction = function (actionId, request) { return this.start() .withUri('/api/user/action') .withUriSegment(actionId) .withJSONBody(request) .withMethod("DELETE") .go(); }; /** * Changes a user's password using the change password Id. This usually occurs after an email has been sent to the user * and they clicked on a link to reset their password. * * As of version 1.32.2, prefer sending the changePasswordId in the request body. To do this, omit the first parameter, and set * the value in the request body. * * @param {string} changePasswordId The change password Id used to find the user. This value is generated by FusionAuth once the change password workflow has been initiated. * @param {ChangePasswordRequest} request The change password request that contains all the information used to change the password. * @returns {Promise<ClientResponse<ChangePasswordResponse>>} */ FusionAuthClient.prototype.changePassword = function (changePasswordId, request) { return this.startAnonymous() .withUri('/api/user/change-password') .withUriSegment(changePasswordId) .withJSONBody(request) .withMethod("POST") .go(); }; /** * Changes a user's password using their identity (login id and password). Using a loginId instead of the changePasswordId * bypasses the email verification and allows a password to be changed directly without first calling the #forgotPassword * method. * * @param {ChangePasswordRequest} request The change password request that contains all the information used to change the password. * @returns {Promise<ClientResponse<void>>} */ FusionAuthClient.prototype.changePasswordByIdentity = function (request) { return this.start() .withUri('/api/user/change-password') .withJSONBody(request) .withMethod("POST") .go(); }; /** * Check to see if the user must obtain a Trust Token Id in order to complete a change password request. * When a user has enabled Two-Factor authentication, before you are allowed to use the Change Password API to change * your password, you must obtain a Trust Token by completing a Two-Factor Step-Up authentication. * * An HTTP status code of 400 with a general error code of [TrustTokenRequired] indicates that a Trust Token is required to make a POST request to this API. * * @param {string} changePasswordId The change password Id used to find the user. This value is generated by FusionAuth once the change password workflow has been initiated. * @returns {Promise<ClientResponse<void>>} */ FusionAuthClient.prototype.checkChangePasswordUsingId = function (changePasswordId) { return this.startAnonymous() .withUri('/api/user/change-password') .withUriSegment(changePasswordId) .withMethod("GET") .go(); }; /** * Check to see if the user must obtain a Trust Token Id in order to complete a change password request. * When a user has enabled Two-Factor authentication, before you are allowed to use the Change Password API to change * your password, you must obtain a Trust Token by completing a Two-Factor Step-Up authentication. * * An HTTP status code of 400 with a general error code of [TrustTokenRequired] indicates that a Trust Token is required to make a POST request to this API. * * @param {string} encodedJWT The encoded JWT (access token). * @returns {Promise<ClientResponse<void>>} */ FusionAuthClient.prototype.checkChangePasswordUsingJWT = function (encodedJWT) { return this.startAnonymous() .withUri('/api/user/change-password') .withAuthorization('Bearer ' + encodedJWT) .withMethod("GET") .go(); }; /** * Check to see if the user must obtain a Trust Request Id in order to complete a change password request. * When a user has enabled Two-Factor authentication, before you are allowed to use the Change Password API to change * your password, you must obtain a Trust Request Id by completing a Two-Factor Step-Up authentication. * * An HTTP status code of 400 with a general error code of [TrustTokenRequired] indicates that a Trust Token is required to make a POST request to this API. * * @param {string} loginId The loginId of the User that you intend to change the password for. * @returns {Promise<ClientResponse<void>>} */ FusionAuthClient.prototype.checkChangePasswordUsingLoginId = function (loginId) { return this.start() .withUri('/api/user/change-password') .withParameter('username', loginId) .withMethod("GET") .go(); }; /** * Make a Client Credentials grant request to obtain an access token. * * @param {string} client_id (Optional) The client identifier. The client Id is the Id of the FusionAuth Entity in which you are attempting to authenticate. * This parameter is optional when Basic Authorization is used to authenticate this request. * @param {string} client_secret (Optional) The client secret used to authenticate this request. * This parameter is optional when Basic Authorization is used to authenticate this request. * @param {string} scope (Optional) This parameter is used to indicate which target entity you are requesting access. To request access to an entity, use the format target-entity:&lt;target-entity-id&gt;:&lt;roles&gt;. Roles are an optional comma separated list. * @returns {Promise<ClientResponse<AccessToken>>} */ FusionAuthClient.prototype.clientCredentialsGrant = function (client_id, client_secret, scope) { var body = new url_1.URLSearchParams(); body.append('client_id', client_id); body.append('client_secret', client_secret); body.append('grant_type', 'client_credentials'); body.append('scope', scope); return this.startAnonymous() .withUri('/oauth2/token') .withFormData(body) .withMethod("POST") .go(); }; /** * Adds a comment to the user's account. * * @param {UserCommentRequest} request The request object that contains all the information used to create the user comment. * @returns {Promise<ClientResponse<void>>} */ FusionAuthClient.prototype.commentOnUser = function (request) { return this.start() .withUri('/api/user/comment') .withJSONBody(request) .withMethod("POST") .go(); }; /** * Complete a WebAuthn authentication ceremony by validating the signature against the previously generated challenge without logging the user in * * @param {WebAuthnLoginRequest} request An object containing data necessary for completing the authentication ceremony * @returns {Promise<ClientResponse<WebAuthnAssertResponse>>} */ FusionAuthClient.prototype.completeWebAuthnAssertion = function (request) { return this.startAnonymous() .withUri('/api/webauthn/assert') .withJSONBody(request) .withMethod("POST") .go(); }; /** * Complete a WebAuthn authentication ceremony by validating the signature against the previously generated challenge and then login the user in * * @param {WebAuthnLoginRequest} request An object containing data necessary for completing the authentication ceremony * @returns {Promise<ClientResponse<LoginResponse>>} */ FusionAuthClient.prototype.completeWebAuthnLogin = function (request) { return this.startAnonymous() .withUri('/api/webauthn/login') .withJSONBody(request) .withMethod("POST") .go(); }; /** * Complete a WebAuthn registration ceremony by validating the client request and saving the new credential * * @param {WebAuthnRegisterCompleteRequest} request An object containing data necessary for completing the registration ceremony * @returns {Promise<ClientResponse<WebAuthnRegisterCompleteResponse>>} */ FusionAuthClient.prototype.completeWebAuthnRegistration = function (request) { return this.start() .withUri('/api/webauthn/register/complete') .withJSONBody(request) .withMethod("POST") .go(); }; /** * Creates an API key. You can optionally specify a unique Id for the key, if not provided one will be generated. * an API key can only be created with equal or lesser authority. An API key cannot create another API key unless it is granted * to that API key. * * If an API key is locked to a tenant, it can only create API Keys for that same tenant. * * @param {UUID} keyId (Optional) The unique Id of the API key. If not provided a secure random Id will be generated. * @param {APIKeyRequest} request The request object that contains all the information needed to create the APIKey. * @returns {Promise<ClientResponse<APIKeyResponse>>} */ FusionAuthClient.prototype.createAPIKey = function (keyId, request) { return this.start() .withUri('/api/api-key') .withUriSegment(keyId) .withJSONBody(request) .withMethod("POST") .go(); }; /** * Creates an application. You can optionally specify an Id for the application, if not provided one will be generated. * * @param {UUID} applicationId (Optional) The Id to use for the application. If not provided a secure random UUID will be generated. * @param {ApplicationRequest} request The request object that contains all the information used to create the application. * @returns {Promise<ClientResponse<ApplicationResponse>>} */ FusionAuthClient.prototype.createApplication = function (applicationId, request) { return this.start() .withUri('/api/application') .withUriSegment(applicationId) .withJSONBody(request) .withMethod("POST") .go(); }; /** * Creates a new role for an application. You must specify the id of the application you are creating the role for. * You can optionally specify an Id for the role inside the ApplicationRole object itself, if not provided one will be generated. * * @param {UUID} applicationId The Id of the application to create the role on. * @param {UUID} roleId (Optional) The Id of the role. If not provided a secure random UUID will be generated. * @param {ApplicationRequest} request The request object that contains all the information used to create the application role. * @returns {Promise<ClientResponse<ApplicationResponse>>} */ FusionAuthClient.prototype.createApplicationRole = function (applicationId, roleId, request) { return this.start() .withUri('/api/application') .withUriSegment(applicationId) .withUriSegment("role") .withUriSegment(roleId) .withJSONBody(request) .withMethod("POST") .go(); }; /** * Creates an audit log with the message and user name (usually an email). Audit logs should be written anytime you * make changes to the FusionAuth database. When using the FusionAuth App web interface, any changes are automatically * written to the audit log. However, if you are accessing the API, you must write the audit logs yourself. * * @param {AuditLogRequest} request The request object that contains all the information used to create the audit log entry. * @returns {Promise<ClientResponse<AuditLogResponse>>} */ FusionAuthClient.prototype.createAuditLog = function (request) { return this.start() .withUri('/api/system/audit-log') .withJSONBody(request) .withMethod("POST") .go(); }; /** * Creates a connector. You can optionally specify an Id for the connector, if not provided one will be generated. * * @param {UUID} connectorId (Optional) The Id for the connector. If not provided a secure random UUID will be generated. * @param {ConnectorRequest} request The request object that contains all the information used to create the connector. * @returns {Promise<ClientResponse<ConnectorResponse>>} */ FusionAuthClient.prototype.createConnector = function (connectorId, request) { return this.start() .withUri('/api/connector') .withUriSegment(connectorId) .withJSONBody(request) .withMethod("POST") .go(); }; /** * Creates a user consent type. You can optionally specify an Id for the consent type, if not provided one will be generated. * * @param {UUID} consentId (Optional) The Id for the consent. If not provided a secure random UUID will be generated. * @param {ConsentRequest} request The request object that contains all the information used to create the consent. * @returns {Promise<ClientResponse<ConsentResponse>>} */ FusionAuthClient.prototype.createConsent = function (consentId, request) { return this.start() .withUri('/api/consent') .withUriSegment(consentId) .withJSONBody(request) .withMethod("POST") .go(); }; /** * Creates an email template. You can optionally specify an Id for the template, if not provided one will be generated. * * @param {UUID} emailTemplateId (Optional) The Id for the template. If not provided a secure random UUID will be generated. * @param {EmailTemplateRequest} request The request object that contains all the information used to create the email template. * @returns {Promise<ClientResponse<EmailTemplateResponse>>} */ FusionAuthClient.prototype.createEmailTemplate = function (emailTemplateId, request) { return this.start() .withUri('/api/email/template') .withUriSegment(emailTemplateId) .withJSONBody(request) .withMethod("POST") .go(); }; /** * Creates an Entity. You can optionally specify an Id for the Entity. If not provided one will be generated. * * @param {UUID} entityId (Optional) The Id for the Entity. If not provided a secure random UUID will be generated. * @param {EntityRequest} request The request object that contains all the information used to create the Entity. * @returns {Promise<ClientResponse<EntityResponse>>} */ FusionAuthClient.prototype.createEntity = function (entityId, request) { return this.start() .withUri('/api/entity') .withUriSegment(entityId) .withJSONBody(request) .withMethod("POST") .go(); }; /** * Creates a Entity Type. You can optionally specify an Id for the Entity Type, if not provided one will be generated. * * @param {UUID} entityTypeId (Optional) The Id for the Entity Type. If not provided a secure random UUID will be generated. * @param {EntityTypeRequest} request The request object that contains all the information used to create the Entity Type. * @returns {Promise<ClientResponse<EntityTypeResponse>>} */ FusionAuthClient.prototype.createEntityType = function (entityTypeId, request) { return this.start() .withUri('/api/entity/type') .withUriSegment(entityTypeId) .withJSONBody(request) .withMethod("POST") .go(); }; /** * Creates a new permission for an entity type. You must specify the id of the entity type you are creating the permission for. * You can optionally specify an Id for the permission inside the EntityTypePermission object itself, if not provided one will be generated. * * @param {UUID} entityTypeId The Id of the entity type to create the permission on. * @param {UUID} permissionId (Optional) The Id of the permission. If not provided a secure random UUID will be generated. * @param {EntityTypeRequest} request The request object that contains all the information used to create the permission. * @returns {Promise<ClientResponse<EntityTypeResponse>>} */ FusionAuthClient.prototype.createEntityTypePermission = function (entityTypeId, permissionId, request) { return this.start() .withUri('/api/entity/type') .withUriSegment(entityTypeId) .withUriSegment("permission") .withUriSegment(permissionId) .withJSONBody(request) .withMethod("POST") .go(); }; /** * Creates a family with the user id in the request as the owner and sole member of the family. You can optionally specify an id for the * family, if not provided one will be generated. * * @param {UUID} familyId (Optional) The id for the family. If not provided a secure random UUID will be generated. * @param {FamilyRequest} request The request object that contains all the information used to create the family. * @returns {Promise<ClientResponse<FamilyResponse>>} */ FusionAuthClient.prototype.createFamily = function (familyId, request) { return this.start() .withUri('/api/user/family') .withUriSegment(familyId) .withJSONBody(request) .withMethod("POST") .go(); }; /** * Creates a form. You can optionally specify an Id for the form, if not provided one will be generated. * * @param {UUID} formId (Optional) The Id for the form. If not provided a secure random UUID will be generated. * @param {FormRequest} request The request object that contains all the information used to create the form. * @returns {Promise<ClientResponse<FormResponse>>} */ FusionAuthClient.prototype.createForm = function (formId, request) { return this.start() .withUri('/api/form') .withUriSegment(formId) .withJSONBody(request) .withMethod("POST") .go(); }; /** * Creates a form field. You can optionally specify an Id for the form, if not provided one will be generated. * * @param {UUID} fieldId (Optional) The Id for the form field. If not provided a secure random UUID will be generated. * @param {FormFieldRequest} request The request object that contains all the information used to create the form field. * @returns {Promise<ClientResponse<FormFieldResponse>>} */ FusionAuthClient.prototype.createFormField = function (fieldId, request) { return this.start() .withUri('/api/form/field') .withUriSegment(fieldId) .withJSONBody(request) .withMethod("POST") .go(); }; /** * Creates a group. You can optionally specify an Id for the group, if not provided one will be generated. * * @param {UUID} groupId (Optional) The Id for the group. If not provided a secure random UUID will be generated. * @param {GroupRequest} request The request object that contains all the information used to create the group. * @returns {Promise<ClientResponse<GroupResponse>>} */ FusionAuthClient.prototype.createGroup = function (groupId, request) { return this.start() .withUri('/api/group') .withUriSegment(groupId) .withJSONBody(request) .withMethod("POST") .go(); }; /** * Creates a member in a group. * * @param {MemberRequest} request The request object that contains all the information used to create the group member(s). * @returns {Promise<ClientResponse<MemberResponse>>} */ FusionAuthClient.prototype.createGroupMembers = function (request) { return this.start() .withUri('/api/group/member') .withJSONBody(request) .withMethod("POST") .go(); }; /** * Creates an IP Access Control List. You can optionally specify an Id on this create request, if one is not provided one will be generated. * * @param {UUID} accessControlListId (Optional) The Id for the IP Access Control List. If not provided a secure random UUID will be generated. * @param {IPAccessControlListRequest} request The request object that contains all the information used to create the IP Access Control List. * @returns {Promise<ClientResponse<IPAccessControlListResponse>>} */ FusionAuthClient.prototype.createIPAccessControlList = function (accessControlListId, request) { return this.start() .withUri('/api/ip-acl') .withUriSegment(accessControlListId) .withJSONBody(request) .withMethod("POST") .go(); }; /** * Creates an identity provider. You can optionally specify an Id for the identity provider, if not provided one will be generated. * * @param {UUID} identityProviderId (Optional) The Id of the identity provider. If not provided a secure random UUID will be generated. * @param {IdentityProviderRequest} request The request object that contains all the information used to create the identity provider. * @returns {Promise<ClientResponse<IdentityProviderResponse>>} */ FusionAuthClient.prototype.createIdentityProvider = function (identityProviderId, request) { return this.start() .withUri('/api/identity-provider') .withUriSegment(identityProviderId) .withJSONBody(request) .withMethod("POST") .go(); }; /** * Creates a Lambda. You can optionally specify an Id for the lambda, if not provided one will be generated. * * @param {UUID} lambdaId (Optional) The Id for the lambda. If not provided a secure random UUID will be generated. * @param {LambdaRequest} request The request object that contains all the information used to create the lambda. * @returns {Promise<ClientResponse<LambdaResponse>>} */ FusionAuthClient.prototype.createLambda = function (lambdaId, request) { return this.start() .withUri('/api/lambda') .withUriSegment(lambdaId) .withJSONBody(request) .withMethod("POST") .go(); }; /** * Creates an message template. You can optionally specify an Id for the template, if not provided one will be generated. * * @param {UUID} messageTemplateId (Optional) The Id for the template. If not provided a secure random UUID will be generated. * @param {MessageTemplateRequest} request The request object that contains all the information used to create the message template. * @returns {Promise<ClientResponse<MessageTemplateResponse>>} */ FusionAuthClient.prototype.createMessageTemplate = function (messageTemplateId, request) { return this.start() .withUri('/api/message/template') .withUriSegment(messageTemplateId) .withJSONBody(request) .withMethod("POST") .go(); }; /** * Creates a messenger. You can optionally specify an Id for the messenger, if not provided one will be generated. * * @param {UUID} messengerId (Optional) The Id for the messenger. If not provided a secure random UUID will be generated. * @param {MessengerRequest} request The request object that contains all the information used to create the messenger. * @returns {Promise<ClientResponse<MessengerResponse>>} */ FusionAuthClient.prototype.createMessenger = function (messengerId, request) { return this.start() .withUri('/api/messenger') .withUriSegment(messengerId) .withJS