UNPKG

twilio

Version:
370 lines (369 loc) 14.6 kB
"use strict"; /* * This code was generated by * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ * * Twilio Memory API * APIs for managing memory stores, profiles, events, and conversational intelligence capabilities. * * NOTE: This class is auto generated by OpenAPI Generator. * https://openapi-generator.tech * Do not edit the class manually. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.IdentifierInstance = exports.IdentifierContextImpl = exports.IdentifierUpdate = exports.Identifier = void 0; exports.IdentifierListInstance = IdentifierListInstance; const util_1 = require("util"); const deserialize = require("../../../base/deserialize"); const serialize = require("../../../base/serialize"); const utility_1 = require("../../../base/utility"); /** * Represents a single identifier value paired with its `idType`. Write operations obey limits, uniqueness, and normalization rules configured via identifier settings. */ class Identifier { constructor(payload) { this.idType = payload["idType"]; this.value = payload["value"]; } } exports.Identifier = Identifier; class IdentifierUpdate { constructor(payload) { this.idType = payload["idType"]; this.oldValue = payload["oldValue"]; this.newValue = payload["newValue"]; } } exports.IdentifierUpdate = IdentifierUpdate; class IdentifierContextImpl { constructor(_version, storeId, profileId, idType) { this._version = _version; if (!(0, utility_1.isValidPathParam)(storeId)) { throw new Error("Parameter 'storeId' is not valid."); } if (!(0, utility_1.isValidPathParam)(profileId)) { throw new Error("Parameter 'profileId' is not valid."); } if (!(0, utility_1.isValidPathParam)(idType)) { throw new Error("Parameter 'idType' is not valid."); } this._solution = { storeId, profileId, idType }; this._uri = `/Stores/${storeId}/Profiles/${profileId}/Identifiers/${idType}`; } remove(params, callback) { if (params instanceof Function) { callback = params; params = {}; } else { params = params || {}; } let data = {}; if (params["removeAll"] !== undefined) data["removeAll"] = serialize.bool(params["removeAll"]); const headers = {}; headers["Accept"] = "application/json"; const instance = this; let operationVersion = instance._version, operationPromise = operationVersion.fetch({ uri: instance._uri, method: "delete", params: data, headers, }); operationPromise = operationPromise.then((payload) => new IdentifierInstance(operationVersion, payload, instance._solution.storeId, instance._solution.profileId, instance._solution.idType)); operationPromise = instance._version.setPromiseCallback(operationPromise, callback); return operationPromise; } removeWithHttpInfo(params, callback) { if (params instanceof Function) { callback = params; params = {}; } else { params = params || {}; } let data = {}; if (params["removeAll"] !== undefined) data["removeAll"] = serialize.bool(params["removeAll"]); const headers = {}; headers["Accept"] = "application/json"; const instance = this; let operationVersion = instance._version; // DELETE operation that returns a response model let operationPromise = operationVersion .fetchWithResponseInfo({ uri: instance._uri, method: "delete", params: data, headers, }) .then((response) => ({ ...response, body: new IdentifierInstance(operationVersion, response.body, instance._solution.storeId, instance._solution.profileId, instance._solution.idType), })); operationPromise = instance._version.setPromiseCallback(operationPromise, callback); return operationPromise; } fetch(callback) { const headers = {}; headers["Accept"] = "application/json"; const instance = this; let operationVersion = instance._version, operationPromise = operationVersion.fetch({ uri: instance._uri, method: "get", headers, }); operationPromise = operationPromise.then((payload) => new IdentifierInstance(operationVersion, payload, instance._solution.storeId, instance._solution.profileId, instance._solution.idType)); operationPromise = instance._version.setPromiseCallback(operationPromise, callback); return operationPromise; } fetchWithHttpInfo(callback) { const headers = {}; headers["Accept"] = "application/json"; const instance = this; let operationVersion = instance._version; // CREATE, FETCH, UPDATE operations let operationPromise = operationVersion .fetchWithResponseInfo({ uri: instance._uri, method: "get", headers, }) .then((response) => ({ ...response, body: new IdentifierInstance(operationVersion, response.body, instance._solution.storeId, instance._solution.profileId, instance._solution.idType), })); operationPromise = instance._version.setPromiseCallback(operationPromise, callback); return operationPromise; } patch(params, headers, callback) { if (params === null || params === undefined) { throw new Error('Required parameter "params" missing.'); } let data = {}; data = params; if (headers === null || headers === undefined) { headers = {}; } headers["Content-Type"] = "application/json"; headers["Accept"] = "application/json"; const instance = this; let operationVersion = instance._version, operationPromise = operationVersion.patch({ uri: instance._uri, method: "patch", data, headers, }); operationPromise = operationPromise.then((payload) => new IdentifierInstance(operationVersion, payload, instance._solution.storeId, instance._solution.profileId, instance._solution.idType)); operationPromise = instance._version.setPromiseCallback(operationPromise, callback); return operationPromise; } patchWithHttpInfo(params, headers, callback) { if (params === null || params === undefined) { throw new Error('Required parameter "params" missing.'); } let data = {}; data = params; if (headers === null || headers === undefined) { headers = {}; } headers["Content-Type"] = "application/json"; headers["Accept"] = "application/json"; const instance = this; let operationVersion = instance._version; // CREATE, FETCH, UPDATE operations let operationPromise = operationVersion .patchWithResponseInfo({ uri: instance._uri, method: "patch", data, headers, }) .then((response) => ({ ...response, body: new IdentifierInstance(operationVersion, response.body, instance._solution.storeId, instance._solution.profileId, instance._solution.idType), })); operationPromise = instance._version.setPromiseCallback(operationPromise, callback); return operationPromise; } /** * Provide a user-friendly representation * * @returns Object */ toJSON() { return this._solution; } [util_1.inspect.custom](_depth, options) { return (0, util_1.inspect)(this.toJSON(), options); } } exports.IdentifierContextImpl = IdentifierContextImpl; class IdentifierInstance { constructor(_version, _payload, storeId, profileId, idType) { this._version = _version; const payload = _payload; this.message = payload.message; this.idType = payload.idType; this.values = payload.values; this._solution = { storeId, profileId, idType: idType }; } get _proxy() { this._context = this._context || new IdentifierContextImpl(this._version, this._solution.storeId, this._solution.profileId, this._solution.idType); return this._context; } remove(params, callback) { return this._proxy.remove(params, callback); } removeWithHttpInfo(params, callback) { return this._proxy.removeWithHttpInfo(params, callback); } /** * Fetch a IdentifierInstance * * @param callback - Callback to handle processed record * * @returns Resolves to processed IdentifierInstance */ fetch(callback) { return this._proxy.fetch(callback); } /** * Fetch a IdentifierInstance and return HTTP info * * @param callback - Callback to handle processed record * * @returns Resolves to processed IdentifierInstance with HTTP metadata */ fetchWithHttpInfo(callback) { return this._proxy.fetchWithHttpInfo(callback); } patch(params, callback) { return this._proxy.patch(params, callback); } patchWithHttpInfo(params, callback) { return this._proxy.patchWithHttpInfo(params, callback); } /** * Provide a user-friendly representation * * @returns Object */ toJSON() { return { message: this.message, idType: this.idType, values: this.values, }; } [util_1.inspect.custom](_depth, options) { return (0, util_1.inspect)(this.toJSON(), options); } } exports.IdentifierInstance = IdentifierInstance; function IdentifierListInstance(version, storeId, profileId) { if (!(0, utility_1.isValidPathParam)(storeId)) { throw new Error("Parameter 'storeId' is not valid."); } if (!(0, utility_1.isValidPathParam)(profileId)) { throw new Error("Parameter 'profileId' is not valid."); } const instance = ((idType) => instance.get(idType)); instance.get = function get(idType) { return new IdentifierContextImpl(version, storeId, profileId, idType); }; instance._version = version; instance._solution = { storeId, profileId }; instance._uri = `/Stores/${storeId}/Profiles/${profileId}/Identifiers`; instance.create = function create(params, headers, callback) { if (params === null || params === undefined) { throw new Error('Required parameter "params" missing.'); } let data = {}; data = params; if (headers === null || headers === undefined) { headers = {}; } headers["Content-Type"] = "application/json"; headers["Accept"] = "application/json"; let operationVersion = version, operationPromise = operationVersion.create({ uri: instance._uri, method: "post", data, headers, }); operationPromise = operationPromise.then((payload) => new IdentifierInstance(operationVersion, payload, instance._solution.storeId, instance._solution.profileId)); operationPromise = instance._version.setPromiseCallback(operationPromise, callback); return operationPromise; }; instance.createWithHttpInfo = function createWithHttpInfo(params, headers, callback) { if (params === null || params === undefined) { throw new Error('Required parameter "params" missing.'); } let data = {}; data = params; if (headers === null || headers === undefined) { headers = {}; } headers["Content-Type"] = "application/json"; headers["Accept"] = "application/json"; let operationVersion = version; // CREATE, FETCH, UPDATE operations let operationPromise = operationVersion .createWithResponseInfo({ uri: instance._uri, method: "post", data, headers, }) .then((response) => ({ ...response, body: new IdentifierInstance(operationVersion, response.body, instance._solution.storeId, instance._solution.profileId), })); operationPromise = instance._version.setPromiseCallback(operationPromise, callback); return operationPromise; }; instance.list = function list(callback) { const headers = {}; const data = {}; headers["Accept"] = "application/json"; let operationVersion = version, operationPromise = operationVersion.fetch({ uri: instance._uri, method: "get", headers, }); operationPromise = operationPromise.then((payload) => (payload["identifiers"] || []).map((item) => new IdentifierInstance(operationVersion, item, instance._solution.storeId, instance._solution.profileId))); operationPromise = instance._version.setPromiseCallback(operationPromise, callback); return operationPromise; }; instance.listWithHttpInfo = function listWithHttpInfo(callback) { const headers = {}; const data = {}; headers["Accept"] = "application/json"; let operationVersion = version; let operationPromise = operationVersion .fetchWithResponseInfo({ uri: instance._uri, method: "get", headers, }) .then((response) => ({ statusCode: response.statusCode, headers: response.headers, body: (response.body["identifiers"] || []).map((item) => new IdentifierInstance(operationVersion, item, instance._solution.storeId, instance._solution.profileId)), })); operationPromise = instance._version.setPromiseCallback(operationPromise, callback); return operationPromise; }; instance.toJSON = function toJSON() { return instance._solution; }; instance[util_1.inspect.custom] = function inspectImpl(_depth, options) { return (0, util_1.inspect)(instance.toJSON(), options); }; return instance; }