{"version":3,"sources":["jsdelivr-header.js","/npm/twilio-notifications@1.0.1/node_modules/tslib/tslib.es6.js","/npm/twilio-notifications@1.0.1/src/logger.ts","/npm/twilio-notifications@1.0.1/src/connector.ts","/npm/twilio-notifications@1.0.1/src/registrar.connector.ts","/npm/twilio-notifications@1.0.1/src/client.ts"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACgDO,SAAS,WAAW,EAAY,EAAQ,EAAK,GAChD,IAA2H,EAAvH,EAAI,UAAU,OAAQ,EAAI,EAAI,EAAI,EAAkB,OAAT,EAAgB,EAAO,OAAO,yBAAyB,EAAQ,GAAO,EACrH,GAAuB,iBAAZ,SAAoD,mBAArB,QAAQ,SAAyB,EAAI,QAAQ,SAAS,EAAY,EAAQ,EAAK,QACpH,IAAK,IAAI,EAAI,EAAW,OAAS,EAAG,GAAK,EAAG,KAAS,EAAI,EAAW,MAAI,GAAK,EAAI,EAAI,EAAE,GAAK,EAAI,EAAI,EAAE,EAAQ,EAAK,GAAK,EAAE,EAAQ,KAAS,GAChJ,OAAO,EAAI,GAAK,GAAK,OAAO,eAAe,EAAQ,EAAK,GAAI,CAC/D,CAMM,SAAS,WAAW,EAAa,GACpC,GAAuB,iBAAZ,SAAoD,mBAArB,QAAQ,SAAyB,OAAO,QAAQ,SAAS,EAAa,EACnH,C,49LCjED,IAAM,IAAM,kBAAO,UAAU,yBAE7B,SAAS,YAAY,EAAQ,GAC3B,MAAO,IAAA,QAAI,IAAI,MAAO,cAAf,0BAAA,OAAqD,EAArD,MAAgE,OACrE,MAAM,KAAK,GAEd,CAED,MAAM,OACJ,QAAA,CAAS,GACP,IAAI,SAAS,EACd,CAED,KAAA,GAAa,QAAA,EAAA,UAAA,OAAJ,EAAI,IAAA,MAAA,GAAA,EAAA,EAAA,EAAA,EAAA,IAAJ,EAAI,GAAA,UAAA,GACX,IAAI,MAAM,MAAM,KAAM,YAAY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AAgB,CACxC,kCACA,YACA,+BAAQ,QAEE,WAAA,qBAAA,OAAA,UAAN","file":"/npm/twilio-notifications@1.0.1/dist/browser.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/twilio-notifications@1.0.1/dist/browser.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","/*! *****************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = function(d, b) {\r\n    extendStatics = Object.setPrototypeOf ||\r\n        ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n        function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\r\n    return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n    if (typeof b !== \"function\" && b !== null)\r\n        throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\r\n    extendStatics(d, b);\r\n    function __() { this.constructor = d; }\r\n    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n    __assign = Object.assign || function __assign(t) {\r\n        for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n            s = arguments[i];\r\n            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n        }\r\n        return t;\r\n    }\r\n    return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n    var t = {};\r\n    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n        t[p] = s[p];\r\n    if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n                t[p[i]] = s[p[i]];\r\n        }\r\n    return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n    if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n    return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n    return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n    if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n    return new (P || (P = Promise))(function (resolve, reject) {\r\n        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n        function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n        step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n    });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n    return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n    function verb(n) { return function (v) { return step([n, v]); }; }\r\n    function step(op) {\r\n        if (f) throw new TypeError(\"Generator is already executing.\");\r\n        while (_) try {\r\n            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;\r\n            if (y = 0, t) op = [op[0] & 2, t.value];\r\n            switch (op[0]) {\r\n                case 0: case 1: t = op; break;\r\n                case 4: _.label++; return { value: op[1], done: false };\r\n                case 5: _.label++; y = op[1]; op = [0]; continue;\r\n                case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n                default:\r\n                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n                    if (t[2]) _.ops.pop();\r\n                    _.trys.pop(); continue;\r\n            }\r\n            op = body.call(thisArg, _);\r\n        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n    }\r\n}\r\n\r\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\r\n    if (k2 === undefined) k2 = k;\r\n    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });\r\n}) : (function(o, m, k, k2) {\r\n    if (k2 === undefined) k2 = k;\r\n    o[k2] = m[k];\r\n});\r\n\r\nexport function __exportStar(m, o) {\r\n    for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\r\n}\r\n\r\nexport function __values(o) {\r\n    var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n    if (m) return m.call(o);\r\n    if (o && typeof o.length === \"number\") return {\r\n        next: function () {\r\n            if (o && i >= o.length) o = void 0;\r\n            return { value: o && o[i++], done: !o };\r\n        }\r\n    };\r\n    throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n    var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n    if (!m) return o;\r\n    var i = m.call(o), r, ar = [], e;\r\n    try {\r\n        while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n    }\r\n    catch (error) { e = { error: error }; }\r\n    finally {\r\n        try {\r\n            if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n        }\r\n        finally { if (e) throw e.error; }\r\n    }\r\n    return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spread() {\r\n    for (var ar = [], i = 0; i < arguments.length; i++)\r\n        ar = ar.concat(__read(arguments[i]));\r\n    return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spreadArrays() {\r\n    for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n    for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n        for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n            r[k] = a[j];\r\n    return r;\r\n}\r\n\r\nexport function __spreadArray(to, from, pack) {\r\n    if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\r\n        if (ar || !(i in from)) {\r\n            if (!ar) ar = Array.prototype.slice.call(from, 0, i);\r\n            ar[i] = from[i];\r\n        }\r\n    }\r\n    return to.concat(ar || from);\r\n}\r\n\r\nexport function __await(v) {\r\n    return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n    if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n    var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n    return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n    function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n    function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n    function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n    function fulfill(value) { resume(\"next\", value); }\r\n    function reject(value) { resume(\"throw\", value); }\r\n    function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n    var i, p;\r\n    return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n    function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === \"return\" } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n    if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n    var m = o[Symbol.asyncIterator], i;\r\n    return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n    function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n    function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n    if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n    return cooked;\r\n};\r\n\r\nvar __setModuleDefault = Object.create ? (function(o, v) {\r\n    Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n    o[\"default\"] = v;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n    if (mod && mod.__esModule) return mod;\r\n    var result = {};\r\n    if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n    __setModuleDefault(result, mod);\r\n    return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n    return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, state, kind, f) {\r\n    if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a getter\");\r\n    if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\r\n    return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, state, value, kind, f) {\r\n    if (kind === \"m\") throw new TypeError(\"Private method is not writable\");\r\n    if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a setter\");\r\n    if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\r\n    return (kind === \"a\" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;\r\n}\r\n","import * as logger from \"loglevel\";\n\nconst log = logger.getLogger(\"twilio-notificatiions\");\n\nfunction prepareLine(prefix, args) {\n  return [`${new Date().toISOString()} Twilio.Notifications ${prefix}:`].concat(\n    Array.from(args)\n  );\n}\n\nclass Logger {\n  setLevel(level: any): void {\n    log.setLevel(level as any);\n  }\n\n  trace(...args): void {\n    log.trace.apply(null, prepareLine(\"T\", args));\n  }\n  debug(...args): void {\n    log.debug.apply(null, prepareLine(\"D\", args));\n  }\n  info(...args): void {\n    log.info.apply(null, prepareLine(\"I\", args));\n  }\n  warn(...args): void {\n    log.warn.apply(null, prepareLine(\"W\", args));\n  }\n  error(...args): void {\n    log.error.apply(null, prepareLine(\"E\", args));\n  }\n}\n\nconst logInstance = new Logger();\n\nexport { Logger, logInstance as log };\n","import { EventEmitter } from \"events\";\nimport { log } from \"./logger\";\n\ntype ChannelType = \"twilsock\" | \"apn\" | \"fcm\";\n\ntype UpdateReason = \"token\" | \"notificationId\" | \"messageType\";\n\nclass RegistrationState {\n  constructor(\n    public token: string = \"\",\n    public notificationId: string = \"\",\n    public messageTypes: Set<string> = new Set<string>()\n  ) {}\n}\n\nfunction setDifference<T>(a: Set<T>, b: Set<T>): Array<T> {\n  return [\n    ...[...a].filter((x) => !b.has(x)),\n    ...[...b].filter((x) => !a.has(x)),\n  ];\n}\n\nfunction hasDifference(\n  a: RegistrationState,\n  b: RegistrationState\n): [boolean, Set<UpdateReason>] {\n  const reasons = new Set<UpdateReason>();\n  if (a.notificationId !== b.notificationId) {\n    reasons.add(\"notificationId\");\n  }\n\n  if (a.token !== b.token) {\n    reasons.add(\"token\");\n  }\n\n  if (setDifference(a.messageTypes, b.messageTypes).length > 0) {\n    reasons.add(\"messageType\");\n  }\n\n  return [reasons.size > 0, reasons];\n}\n\nabstract class Connector extends EventEmitter {\n  protected readonly desiredState: RegistrationState = new RegistrationState();\n  protected readonly currentState: RegistrationState = new RegistrationState();\n  private _hasActiveAttempt = false; // @todo replace with FSM\n\n  protected constructor(protected readonly channelType: ChannelType) {\n    super();\n  }\n\n  /**\n   * Set desired notification ID for the registration.\n   * Call commitChanges() afterwards to commit this change.\n   * @param notificationId Notification context ID to register.\n   */\n  public setNotificationId(notificationId: string): void {\n    this.desiredState.notificationId = notificationId;\n  }\n\n  public subscribe(messageType: string): void {\n    if (this.desiredState.messageTypes.has(messageType)) {\n      log.debug(\n        `message type '${messageType}' for channel ${this.channelType} is already registered`\n      );\n      return;\n    }\n\n    this.desiredState.messageTypes.add(messageType);\n  }\n\n  public unsubscribe(messageType: string): void {\n    if (!this.desiredState.messageTypes.has(messageType)) {\n      return;\n    }\n\n    this.desiredState.messageTypes.delete(messageType);\n  }\n\n  public updateToken(token: string): void {\n    // @todo not entirely correct?\n    this.desiredState.token = token;\n  }\n\n  /**\n   * Perform actual registration after all required changes are settled.\n   */\n  public async commitChanges(): Promise<void> {\n    // if (!this.config.token || this.config.token.length === 0) { // @todo factor desiredState.token here?\n    //   log.trace(\"Can't persist registration: token is not set\");\n    //   return;\n    // }\n\n    if (this._hasActiveAttempt) {\n      // Concurrent access violation\n      log.error(\"One registration attempt is already in progress\");\n      throw new Error(\"One registration attempt is already in progress\");\n    }\n\n    const [needToUpdate, reasons] = hasDifference(\n      this.desiredState,\n      this.currentState\n    );\n    if (!needToUpdate) {\n      // The state did not change - complete successfully!\n      return;\n    }\n\n    if (!this.currentState.notificationId) {\n      reasons.delete(\"notificationId\");\n    }\n\n    log.trace(\n      `Persisting ${this.channelType} registration`,\n      reasons,\n      this.desiredState\n    );\n    try {\n      this._hasActiveAttempt = true;\n\n      const stateToPersist: RegistrationState = new RegistrationState();\n      stateToPersist.token = this.desiredState.token;\n      stateToPersist.notificationId = this.desiredState.notificationId;\n      stateToPersist.messageTypes = new Set(this.desiredState.messageTypes);\n\n      if (stateToPersist.messageTypes.size > 0) {\n        const persistedState = await this.updateRegistration(\n          stateToPersist,\n          reasons\n        );\n        this.currentState.token = persistedState.token;\n        this.currentState.notificationId = persistedState.notificationId;\n        this.currentState.messageTypes = new Set(persistedState.messageTypes);\n\n        // @todo twilsock emits registered(notificationContextId) when this context is reg'd\n        this.emit(\n          \"stateChanged\",\n          this.channelType,\n          \"registered\",\n          this.currentState\n        );\n      } else {\n        await this.removeRegistration();\n        this.currentState.token = stateToPersist.token;\n        this.currentState.notificationId = stateToPersist.notificationId;\n        this.currentState.messageTypes.clear();\n\n        this.emit(\n          \"stateChanged\",\n          this.channelType,\n          \"unregistered\",\n          this.currentState\n        );\n      }\n    } catch (e) {\n      throw e; // Forward any errors up\n    } finally {\n      this._hasActiveAttempt = false;\n    }\n  }\n\n  /**\n   * This one goes completely beside the state machine and removes all registrations.\n   * Use with caution: if it races with current state machine operations, madness will ensue.\n   */\n  public abstract sendDeviceRemoveRequest(\n    registrationId: string\n  ): Promise<void>;\n\n  protected abstract updateRegistration(\n    registration: RegistrationState,\n    reasons: Set<UpdateReason>\n  ): Promise<RegistrationState>;\n\n  protected abstract removeRegistration(): Promise<void>;\n}\n\nexport { UpdateReason, RegistrationState, ChannelType, Connector };\n","import { AsyncRetrier } from \"operation-retrier\";\nimport {\n  UpdateReason,\n  RegistrationState,\n  Connector,\n  ChannelType,\n} from \"./connector\";\nimport { TwilsockClient } from \"twilsock\";\nimport { log } from \"./logger\";\n\nconst retrierConfig = {\n  min: 2000, // ms\n  max: 120000, // ms\n  randomness: 0.2,\n};\n\nexport interface RegistrarContext {\n  protocolVersion: number;\n  productId: string;\n  platform: string;\n}\n\n/**\n * Manages the registrations on ERS service.\n * Deduplicates registrations and manages them automatically.\n */\nclass RegistrarConnector extends Connector {\n  private registrationId: string | null = null;\n\n  /**\n   * Creates new instance of the ERS registrar\n   *\n   * @param channelType {string} Channel this connector will be servicing.\n   * @param context {any} productId, platform, and protocolVersion.\n   * @param twilsock {TwilsockClient} connection transport.\n   * @param registrarUrl {string}\n   */\n  constructor(\n    channelType: ChannelType,\n    private readonly context: RegistrarContext, // context is separate from config because it's not shared with other connectors\n    private readonly twilsock: TwilsockClient,\n    private readonly registrarUrl: string\n  ) {\n    super(channelType);\n  }\n\n  protected async updateRegistration(\n    registration: RegistrationState,\n    reasons: Set<UpdateReason>\n  ): Promise<RegistrationState> {\n    if (reasons.has(\"notificationId\")) {\n      await this.removeRegistration();\n    }\n\n    if (!registration.notificationId || !registration.notificationId.length) {\n      log.error(`No push notification ID for registration`);\n      throw new Error(`No push notification ID for registration`); // @todo FSM update to error perhaps\n    }\n\n    log.trace(\"Registering\", this.channelType, registration);\n\n    const registrarRequest = {\n      endpoint_platform: this.context.platform,\n      channel_type: this.channelType,\n      version: this.context.protocolVersion.toString(),\n      message_types: Array.from(registration.messageTypes),\n      data: {\n        registration_id: registration.notificationId,\n      },\n      //ttl: 'PT24H' - This is totally ignored by notify, all bindings use PT1Y ttl.\n    };\n\n    const url = `${this.registrarUrl}?productId=${this.context.productId}`;\n    const headers = {\n      \"Content-Type\": \"application/json\",\n      // 'X-Twilio-Token': registration.token\n    };\n\n    log.trace(`Creating registration for channel ${this.channelType}`);\n    try {\n      const response = (await new AsyncRetrier(retrierConfig).run(() =>\n        this.twilsock.post(url, headers, registrarRequest)\n      )) as any;\n      this.registrationId = response.body.id;\n      log.debug(\"Registration created: \", response);\n    } catch (err) {\n      log.error(\"Registration failed: \", err);\n      throw err;\n    }\n\n    return registration;\n  }\n\n  protected async removeRegistration(): Promise<void> {\n    if (!this.registrationId) {\n      // No registration ID - no problem, finish successfully.\n      return;\n    }\n\n    const url = `${this.registrarUrl}/${this.registrationId}?productId=${this.context.productId}`;\n    const headers = {\n      \"Content-Type\": \"application/json\",\n      // 'X-Twilio-Token': this.config.token\n    };\n\n    log.trace(`Removing registration for ${this.channelType}`);\n    try {\n      await new AsyncRetrier(\n        Object.assign(retrierConfig, { maxAttemptsCount: 3 })\n      ).run(() => this.twilsock.delete(url, headers));\n      log.debug(`Registration removed for ${this.channelType}`);\n    } catch (err) {\n      log.error(\"Failed to remove registration \", this.channelType, err);\n      throw err;\n    }\n  }\n\n  public async sendDeviceRemoveRequest(registrationId: string): Promise<void> {\n    if (registrationId === \"\") {\n      throw new Error(\"Empty registration ID\");\n    }\n\n    const url = `${this.registrarUrl}?productId=${this.context.productId}`;\n    const headers = {\n      \"Content-Type\": \"application/json\",\n      // @todo Content-Length??\n    };\n    const payload = {\n      binding_type: this.channelType,\n      address: registrationId,\n    };\n\n    try {\n      log.trace(`Removing old registrations for ${this.channelType}`);\n      await new AsyncRetrier(\n        Object.assign(retrierConfig, { maxAttemptsCount: 3 })\n      ).run(() => this.twilsock.delete(url, headers, payload));\n      log.debug(`Registration removed for ${this.channelType}`);\n    } catch (err) {\n      log.error(\"Failed to remove registration \", this.channelType, err);\n      throw err;\n    }\n  }\n}\n\nexport { Connector, RegistrarConnector };\n","import { EventEmitter } from \"events\";\nimport { TwilsockClient, ConnectionState } from \"twilsock\";\nimport { Connector, ChannelType } from \"./connector\";\nimport { RegistrarConnector } from \"./registrar.connector\";\nimport { TwilsockConnector } from \"./twilsock.connector\";\nimport { log } from \"./logger\";\nimport {\n  validateTypesAsync,\n  validateTypes,\n  literal,\n  nonEmptyString,\n  validateConstructorTypes,\n  pureObject,\n} from \"twilio-sdk-type-validator\";\n\n// For validating Connector.ChannelType - keep synchronized!\nconst channelTypeRule = literal(\"apn\", \"fcm\", \"twilsock\");\n\ninterface PushNotification {\n  messageType: string;\n  payload: any;\n}\n\ninterface NotificationOptions {\n  region?: string;\n  ersUrl?: string;\n}\n\ninterface ClientOptions {\n  logLevel?: string;\n  minTokenRefreshInterval?: number;\n  productId?: string;\n  twilsockClient?: TwilsockClient;\n  notifications?: NotificationOptions;\n  region?: string;\n}\n\n/**\n * @class\n * @alias Notifications\n * @classdesc The helper library for the notification service.\n * Provides high level api for creating and managing notification subscriptions and receiving messages\n * Creates the instance of Notification helper library\n *\n * @constructor\n * @param {string} token - Twilio access token\n * @param {Notifications#ClientOptions} options - Options to customize client behavior\n *\n * @event stateChanged channelType (registered|unregistered) -- coming from connector, i.e. it's per-connector type!\n * @event transportState Forwarded from Twilsock's stateChanged event.\n * @event message Routed from twilsock as a notification event.\n */\n@validateConstructorTypes(nonEmptyString, [\n  pureObject,\n  \"undefined\",\n  literal(null),\n])\nclass Client extends EventEmitter {\n  private readonly twilsock?: TwilsockClient;\n  private readonly connectors: Map<ChannelType, Connector>;\n\n  constructor(token: string, options: ClientOptions = {}) {\n    super();\n\n    options.logLevel = options.logLevel ?? \"error\";\n    log.setLevel(options.logLevel);\n\n    const productId = options.productId ?? \"notifications\";\n\n    const startTwilsock = !options.twilsockClient;\n\n    const twilsock = (options.twilsockClient =\n      options.twilsockClient ?? new TwilsockClient(token, productId, options));\n\n    const config = options.notifications ?? {};\n    const region = config.region ?? options.region ?? \"us1\";\n    const defaultUrl = `https://ers.${region}.twilio.com/v1/registrations`;\n    const registrarUrl = config.ersUrl || defaultUrl;\n\n    this.connectors = new Map<ChannelType, Connector>();\n\n    const platform = Client._detectPlatform();\n\n    this.connectors.set(\n      \"apn\",\n      new RegistrarConnector(\n        \"apn\",\n        { protocolVersion: 4, productId, platform },\n        twilsock,\n        registrarUrl\n      )\n    );\n    this.connectors.set(\n      \"fcm\",\n      new RegistrarConnector(\n        \"fcm\",\n        { protocolVersion: 3, productId, platform },\n        twilsock,\n        registrarUrl\n      )\n    );\n    this.connectors.set(\n      \"twilsock\",\n      new TwilsockConnector(productId, platform, twilsock)\n    );\n\n    twilsock.on(\"stateChanged\", (state) => this.emit(\"transportState\", state));\n\n    this._connector(\"twilsock\").on(\"stateChanged\", (type, value, state) =>\n      this.emit(\"stateChanged\", type, value, state)\n    );\n    this._connector(\"apn\").on(\"stateChanged\", (type, value, state) =>\n      this.emit(\"stateChanged\", type, value, state)\n    );\n    this._connector(\"fcm\").on(\"stateChanged\", (type, value, state) =>\n      this.emit(\"stateChanged\", type, value, state)\n    );\n\n    // Router\n    twilsock.on(\"message\", (type, message) =>\n      this._routeMessage(type, message)\n    );\n\n    this.updateToken(token);\n\n    // Start only if we created twilsock locally,\n    // otherwise it's the responsibility of whoever created the Twilsock client.\n    if (startTwilsock) {\n      twilsock.connect();\n      this.twilsock = twilsock;\n    }\n  }\n\n  public async shutdown(): Promise<void> {\n    this.connectors.clear();\n    if (this.twilsock) {\n      await this.twilsock.disconnect();\n    }\n  }\n\n  /**\n   * Set OS-provided APNS/FCM registration binding for the given channel type. Not used for 'twilsock'.\n   *\n   * You must call this function once you've received the ID of your device from the underlying OS.\n   *\n   * @param {ChannelType} channelType Channel type ('apn'/'fcm').\n   * @param {string} pushRegistrationId Token received from FCM/APNS system on device.\n   */\n  @validateTypes(channelTypeRule, nonEmptyString)\n  public setPushRegistrationId(\n    channelType: ChannelType,\n    pushRegistrationId: string\n  ): void {\n    log.debug(\n      `Set ${channelType} push registration id '${pushRegistrationId}'`\n    );\n    this._connector(channelType).setNotificationId(pushRegistrationId);\n  }\n\n  /**\n   * Subscribe to a given message type for a given channel type.\n   *\n   * Creates a subscriptions to receive incoming messages according to message type.\n   * Subscription establishes a binding and you will receive a signal when a notification\n   * of this type has been received by the library.\n   *\n   * Subscribed binding is preserved for 1 year, after which time it needs to be re-subscribed.\n   * This is the responsibility of the client SDK.\n   *\n   * @param {ChannelType} channelType Supported are 'twilsock', 'apn' and 'fcm'\n   * @param {string} messageType The type of message that you want to receive\n   */\n  @validateTypes(channelTypeRule, nonEmptyString)\n  public subscribe(channelType: ChannelType, messageType: string): void {\n    log.debug(\n      `Add ${channelType} subscriptions for message type ${messageType}`\n    );\n    this._connector(channelType).subscribe(messageType);\n  }\n\n  /**\n   * Unsubscribe from a given message type.\n   *\n   * Unsubscribing breaks a binding and you will not receive more notifications for this message type.\n   * Please note that you have to call commitChanges() and receive a successful result before\n   * the subscription is actually removed.\n   *\n   * @param {ChannelType} channelType Supported are 'twilsock', 'apn' and 'fcm'\n   * @param {string} messageType The type of message that you don't want to receive anymore\n   */\n  @validateTypes(channelTypeRule, nonEmptyString)\n  public unsubscribe(channelType: ChannelType, messageType: string): void {\n    log.debug(\n      `Remove ${channelType} subscriptions for message type ${messageType}`\n    );\n    this._connector(channelType).unsubscribe(messageType);\n  }\n\n  /**\n   * Update subscription token. You must update the token when the old one expires.\n   *\n   * When you receive onTokenWillExpire event from twilsock, call this function with the new refreshed\n   * token _after_ you have updated twilsock and other associated objects with the new token.\n   *\n   * @param {string} token Authentication token for registrations\n   */\n  @validateTypes(nonEmptyString)\n  public updateToken(token: string): void {\n    this.connectors.forEach((connector) => connector.updateToken(token));\n  }\n\n  /**\n   * Commit all collected subscription changes as a batched update. This function tries to reduce\n   * number of network calls necessary to update bindings status.\n   */\n  public async commitChanges(): Promise<void> {\n    const promises: Promise<void>[] = [];\n    this.connectors.forEach((connector) =>\n      promises.push(connector.commitChanges())\n    );\n    await Promise.all(promises);\n  }\n\n  /**\n   * Clear existing registrations directly using provided device token.\n   * This is useful to ensure stopped subscriptions without resubscribing.\n   *\n   * This function goes completely beside the state machine and removes all registrations.\n   * Use with caution: if it races with current state machine operations, madness will ensue.\n   *\n   * @param {ChannelType} channelType Channel type ('apn'/'fcm').\n   * @param {string} registrationId Token received from FCM/APNS system on device.\n   */\n  @validateTypesAsync(channelTypeRule, nonEmptyString)\n  public async removeRegistrations(\n    channelType: ChannelType,\n    registrationId: string\n  ): Promise<void> {\n    await this._connector(channelType).sendDeviceRemoveRequest(registrationId);\n  }\n\n  /**\n   * Handle incoming push notification.\n   * Client application should call this method when it receives push notifications and pass the received data.\n   * @param {Object} message push message\n   * @return {PushNotification} A reformatted payload with extracted message type.\n   */\n  public handlePushNotification(message: any): PushNotification {\n    return {\n      messageType: message.twi_message_type,\n      payload: message.payload,\n    };\n  }\n\n  /**\n   * Routes messages to the external subscribers\n   */\n  private _routeMessage(type: string, message: string): void {\n    log.debug(\"Notification message arrived: \", type, message);\n    this.emit(\"message\", type, message);\n  }\n\n  /**\n   * @param {String} type Channel type\n   * @throws {Error} Error with description\n   */\n  private _connector(type: ChannelType): Connector {\n    const connector = this.connectors.get(type);\n    if (!connector) {\n      throw new Error(`Unknown channel type: ${type}`);\n    }\n    return connector;\n  }\n\n  /**\n   * Returns platform string limited to max 128 chars\n   */\n  private static _detectPlatform(): string {\n    let platform = \"\";\n    if (typeof navigator !== \"undefined\") {\n      platform = \"unknown\";\n      if (typeof navigator.product !== \"undefined\") {\n        platform = navigator.product;\n      }\n      if (typeof navigator.userAgent !== \"undefined\") {\n        platform = navigator.userAgent;\n      }\n    } else {\n      platform = \"web\";\n    }\n\n    return platform.substring(0, 128);\n  }\n}\n\n/**\n * @event Client#message\n * Fired when a new notification message arrives.\n * @param {string} type Message type\n * @param {Object} message Message payload\n */\n\n/**\n * @event Client#stateChanged\n * Fired when the registration state changes.\n * @param {ChannelType} type Type of channel\n * @param {string} status Status of registration (registered/unregistered)\n * @param {Object} state Registration state details\n *                       (token, notificationId, currently subscribed types)\n */\n\n/**\n * @event Client#transportState\n * Fired when the twilsock connection state changes.\n * @param {string} state New transport state. Coming directly from Twilsock#ConnectionState.\n */\n\n/**\n * These options can be passed to Client constructor\n * @typedef {Object} Notifications#ClientOptions\n * @property {String} [logLevel='error'] - The level of logging to enable. Valid options\n *   (from strictest to broadest): ['silent', 'error', 'warn', 'info', 'debug', 'trace']\n */\n\nexport { ChannelType, ConnectionState, PushNotification, Client };\n"]}