@twilio/conversations 2.5.0 → 2.6.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/builds/browser.esm.js +10713 -0
- package/builds/browser.esm.js.map +1 -0
- package/builds/browser.js +158 -1
- package/builds/browser.js.map +1 -1
- package/builds/lib.esm.d.ts +3166 -0
- package/builds/lib.esm.js +10712 -0
- package/builds/lib.js +167 -1
- package/builds/lib.js.map +1 -1
- package/builds/twilio-conversations.js +309 -322
- package/builds/twilio-conversations.min.js +1 -1
- package/dist/aggregated-delivery-receipt.js +3 -5
- package/dist/aggregated-delivery-receipt.js.map +1 -1
- package/dist/channel-metadata-client.js +7 -9
- package/dist/channel-metadata-client.js.map +1 -1
- package/dist/client.js +189 -154
- package/dist/client.js.map +1 -1
- package/dist/command-executor.js +8 -8
- package/dist/command-executor.js.map +1 -1
- package/dist/configuration.js +12 -9
- package/dist/configuration.js.map +1 -1
- package/dist/content-client.js +11 -8
- package/dist/content-client.js.map +1 -1
- package/dist/content-template.js +3 -5
- package/dist/content-template.js.map +1 -1
- package/dist/conversation.js +113 -87
- package/dist/conversation.js.map +1 -1
- package/dist/data/conversations.js +34 -42
- package/dist/data/conversations.js.map +1 -1
- package/dist/data/messages.js +23 -21
- package/dist/data/messages.js.map +1 -1
- package/dist/data/participants.js +25 -23
- package/dist/data/participants.js.map +1 -1
- package/dist/data/users.js +15 -13
- package/dist/data/users.js.map +1 -1
- package/dist/detailed-delivery-receipt.js +3 -5
- package/dist/detailed-delivery-receipt.js.map +1 -1
- package/dist/index.js +17 -49
- package/dist/index.js.map +1 -1
- package/dist/interfaces/notification-types.js +1 -5
- package/dist/interfaces/notification-types.js.map +1 -1
- package/dist/interfaces/rules.js +13 -10
- package/dist/interfaces/rules.js.map +1 -1
- package/dist/logger.js +25 -26
- package/dist/logger.js.map +1 -1
- package/dist/media.js +11 -8
- package/dist/media.js.map +1 -1
- package/dist/message-builder.js +48 -40
- package/dist/message-builder.js.map +1 -1
- package/dist/message-recipients-client.js +10 -12
- package/dist/message-recipients-client.js.map +1 -1
- package/dist/message.js +88 -75
- package/dist/message.js.map +1 -1
- package/dist/node_modules/quick-lru/index.js +1 -5
- package/dist/node_modules/quick-lru/index.js.map +1 -1
- package/dist/node_modules/tslib/tslib.es6.js +1 -7
- package/dist/node_modules/tslib/tslib.es6.js.map +1 -1
- package/dist/packages/conversations/package.json.js +2 -6
- package/dist/packages/conversations/package.json.js.map +1 -1
- package/dist/participant.js +34 -29
- package/dist/participant.js.map +1 -1
- package/dist/push-notification.js +5 -4
- package/dist/push-notification.js.map +1 -1
- package/dist/rest-paginator.js +6 -4
- package/dist/rest-paginator.js.map +1 -1
- package/dist/services/network.js +3 -7
- package/dist/services/network.js.map +1 -1
- package/dist/services/typing-indicator.js +11 -8
- package/dist/services/typing-indicator.js.map +1 -1
- package/dist/unsent-message.js +9 -8
- package/dist/unsent-message.js.map +1 -1
- package/dist/user.js +27 -24
- package/dist/user.js.map +1 -1
- package/dist/util/deferred.js +6 -4
- package/dist/util/deferred.js.map +1 -1
- package/dist/util/index.js +1 -9
- package/dist/util/index.js.map +1 -1
- package/docs/index.html +3 -3
- package/docs/modules.html +2 -2
- package/package.json +7 -7
package/dist/participant.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"participant.js","sources":["../src/participant.ts"],"sourcesContent":["import { Users } from \"./data/users\";\nimport { User } from \"./user\";\nimport { parseTime, parseAttributes } from \"./util\";\nimport { Logger } from \"./logger\";\nimport { Conversation } from \"./conversation\";\nimport { json } from \"./interfaces/rules\";\nimport { validateTypesAsync } from \"@twilio/declarative-type-validator\";\nimport { CommandExecutor } from \"./command-executor\";\nimport { EditParticipantRequest } from \"./interfaces/commands/edit-participant\";\nimport { ParticipantResponse } from \"./interfaces/commands/participant-response\";\nimport { ReplayEventEmitter } from \"@twilio/replay-event-emitter\";\nimport isEqual from \"lodash.isequal\";\nimport { JSONValue } from \"./types\";\n\ntype ParticipantEvents = {\n typingEnded: (participant: Participant) => void;\n typingStarted: (participant: Participant) => void;\n updated: (data: {\n participant: Participant;\n updateReasons: ParticipantUpdateReason[];\n }) => void;\n};\n\nconst log = Logger.scope(\"Participant\");\n\ninterface ParticipantDescriptor {\n attributes?: JSONValue;\n dateCreated: Date | null;\n dateUpdated: Date | null;\n identity: string;\n roleSid?: string;\n lastConsumedMessageIndex: number | null;\n lastConsumptionTimestamp: number | null;\n type: ParticipantType;\n userInfo?: string;\n bindings?: ParticipantBindings;\n}\n\ninterface ParticipantState {\n attributes: JSONValue;\n dateCreated: Date | null;\n dateUpdated: Date | null;\n identity: string;\n isTyping: boolean;\n lastReadMessageIndex: number | null;\n lastReadTimestamp: Date | null;\n roleSid: string;\n sid: string;\n type: ParticipantType;\n typingTimeout: number | null;\n userInfo?: string;\n bindings?: ParticipantBindings;\n}\n\ninterface ParticipantServices {\n users: Users;\n commandExecutor: CommandExecutor;\n}\n\ninterface ParticipantLinks {\n self: string;\n}\n\n/**\n * The reason for the `updated` event being emitted by a participant.\n */\ntype ParticipantUpdateReason =\n | \"attributes\"\n | \"dateCreated\"\n | \"dateUpdated\"\n | \"roleSid\"\n | \"lastReadMessageIndex\"\n | \"lastReadTimestamp\"\n | \"bindings\";\n\n/**\n * Participant type. The string variant can be used to denote new types of\n * participant that aren't supported by this version of the SDK.\n */\ntype ParticipantType = \"chat\" | \"sms\" | \"whatsapp\" | \"email\" | string;\n\ninterface ParticipantUpdatedEventArgs {\n participant: Participant;\n updateReasons: ParticipantUpdateReason[];\n}\n\n/**\n * Bindings for conversation participant.\n */\ninterface ParticipantBindings {\n email?: ParticipantEmailBinding;\n}\n\n/**\n * Email participation level.\n * to = to/from\n * cc = cc\n */\ntype ParticipantEmailLevel = \"to\" | \"cc\";\n\n/**\n * Bindings for email participant.\n */\ninterface ParticipantEmailBinding {\n name: string;\n address: string;\n level: ParticipantEmailLevel;\n}\n\n/**\n * A participant represents a remote client in a conversation.\n */\nclass Participant extends ReplayEventEmitter<ParticipantEvents> {\n private state: ParticipantState;\n private readonly links: ParticipantLinks;\n private readonly services: ParticipantServices;\n\n /**\n * Conversation that the remote client is a participant of.\n */\n public readonly conversation: Conversation;\n\n /**\n * The server-assigned unique identifier for the participant.\n */\n public get sid(): string {\n return this.state.sid;\n }\n\n /**\n * Custom attributes of the participant.\n */\n public get attributes(): JSONValue {\n return this.state.attributes;\n }\n\n /**\n * Date this participant was created on.\n */\n public get dateCreated(): Date | null {\n return this.state.dateCreated;\n }\n\n /**\n * Date this participant was last updated on.\n */\n public get dateUpdated(): Date | null {\n return this.state.dateUpdated;\n }\n\n /**\n * Identity of the participant.\n */\n public get identity(): string | null {\n return this.state.identity;\n }\n\n /**\n * Indicates whether the participant is currently typing.\n */\n public get isTyping(): boolean {\n return this.state.isTyping;\n }\n\n /**\n * The index of the last read message by the participant.\n * Note that retrieving messages on a client endpoint does not mean that messages are read,\n * please consider reading about the [Read Horizon feature](https://www.twilio.com/docs/api/chat/guides/consumption-horizon)\n * to find out about the proper way to mark messages as read.\n */\n public get lastReadMessageIndex(): number | null {\n return this.state.lastReadMessageIndex;\n }\n\n /**\n * Date of the most recent read horizon update.\n */\n public get lastReadTimestamp(): Date | null {\n return this.state.lastReadTimestamp;\n }\n\n public get roleSid(): string {\n return this.state.roleSid;\n }\n\n /**\n * Type of the participant.\n */\n public get type(): ParticipantType {\n return this.state.type;\n }\n\n /**\n * Get the bindings mapping for the current participant.\n * Available binding depends on the participant type.\n * You could access it as `participant.bindings.sms?.address` or\n * using the type dynamically `participant.bindings[participant.type]`\n * just be aware that the binding information has different structure for\n * each participant type.\n * See also {ParticipantEmailBinding}, the only available currently binding descriptor.\n */\n public get bindings(): ParticipantBindings {\n return this.state.bindings ?? {};\n }\n\n /**\n * @internal\n */\n constructor(\n data: ParticipantDescriptor,\n sid: string,\n conversation: Conversation,\n links: ParticipantLinks,\n services: ParticipantServices\n ) {\n super();\n\n this.conversation = conversation;\n this.links = links;\n this.services = services;\n this.state = {\n attributes: parseAttributes(\n data.attributes,\n \"Retrieved malformed attributes from the server for participant: \" +\n sid,\n log\n ),\n dateCreated: data.dateCreated ? parseTime(data.dateCreated) : null,\n dateUpdated: data.dateCreated ? parseTime(data.dateUpdated) : null,\n sid: sid,\n typingTimeout: null,\n isTyping: false,\n identity: data.identity,\n roleSid: data.roleSid ?? \"\",\n lastReadMessageIndex: Number.isInteger(data.lastConsumedMessageIndex)\n ? data.lastConsumedMessageIndex\n : null,\n lastReadTimestamp: data.lastConsumptionTimestamp\n ? parseTime(data.lastConsumptionTimestamp)\n : null,\n type: data.type || \"chat\",\n userInfo: data.userInfo,\n bindings: data.bindings ?? {},\n };\n\n if (!data.identity && !data.type) {\n throw new Error(\n \"Received invalid Participant object from server: Missing identity or type of Participant.\"\n );\n }\n }\n\n /**\n * Fired when the participant has started typing.\n *\n * Parameters:\n * 1. {@link Participant} `participant` - the participant in question\n * @event\n */\n static readonly typingStarted = \"typingStarted\";\n\n /**\n * Fired when the participant has stopped typing.\n *\n * Parameters:\n * 1. {@link Participant} `participant` - the participant in question\n * @event\n */\n static readonly typingEnded = \"typingEnded\";\n\n /**\n * Fired when the fields of the participant have been updated.\n *\n * Parameters:\n * 1. object `data` - info object provided with the event. It has the following properties:\n * * {@link Participant} participant - the participant in question\n * * {@link ParticipantUpdateReason}[] updateReasons - array of reasons for the update\n * @event\n */\n static readonly updated = \"updated\";\n\n /**\n * Internal method used to start or reset the typing indicator timeout (with event emitting).\n * @internal\n */\n _startTyping(timeout) {\n if (this.state.typingTimeout) {\n clearTimeout(this.state.typingTimeout);\n }\n\n this.state.isTyping = true;\n this.emit(Participant.typingStarted, this);\n\n this.conversation.emit(Conversation.typingStarted, this); // @fixme layering violation\n\n this.state.typingTimeout = Number(\n setTimeout(() => this._endTyping(), timeout)\n );\n return this;\n }\n\n /**\n * Internal method function used to stop the typing indicator timeout (with event emitting).\n * @internal\n */\n _endTyping() {\n if (!this.state.typingTimeout) {\n return;\n }\n\n this.state.isTyping = false;\n this.emit(Participant.typingEnded, this);\n\n this.conversation.emit(Conversation.typingEnded, this);\n\n clearInterval(this.state.typingTimeout);\n this.state.typingTimeout = null;\n }\n\n /**\n * Internal method function used update local object's property roleSid with a new value.\n * @internal\n */\n _update(data) {\n const updateReasons: ParticipantUpdateReason[] = [];\n\n const updateAttributes = parseAttributes(\n data.attributes,\n \"Retrieved malformed attributes from the server for participant: \" +\n this.state.sid,\n log\n );\n\n if (data.attributes && !isEqual(this.state.attributes, updateAttributes)) {\n this.state.attributes = updateAttributes;\n updateReasons.push(\"attributes\");\n }\n\n const updatedDateUpdated = parseTime(data.dateUpdated);\n if (\n data.dateUpdated &&\n updatedDateUpdated?.getTime() !==\n (this.state.dateUpdated && this.state.dateUpdated.getTime())\n ) {\n this.state.dateUpdated = updatedDateUpdated;\n updateReasons.push(\"dateUpdated\");\n }\n\n const updatedDateCreated = parseTime(data.dateCreated);\n if (\n data.dateCreated &&\n updatedDateCreated?.getTime() !==\n (this.state.dateCreated && this.state.dateCreated.getTime())\n ) {\n this.state.dateCreated = updatedDateCreated;\n updateReasons.push(\"dateCreated\");\n }\n\n if (data.roleSid && this.state.roleSid !== data.roleSid) {\n this.state.roleSid = data.roleSid;\n updateReasons.push(\"roleSid\");\n }\n\n if (\n (Number.isInteger(data.lastConsumedMessageIndex) ||\n data.lastConsumedMessageIndex === null) &&\n this.state.lastReadMessageIndex !== data.lastConsumedMessageIndex\n ) {\n this.state.lastReadMessageIndex = data.lastConsumedMessageIndex;\n updateReasons.push(\"lastReadMessageIndex\");\n }\n\n if (data.lastConsumptionTimestamp) {\n const lastReadTimestamp = new Date(data.lastConsumptionTimestamp);\n if (\n !this.state.lastReadTimestamp ||\n this.state.lastReadTimestamp.getTime() !== lastReadTimestamp.getTime()\n ) {\n this.state.lastReadTimestamp = lastReadTimestamp;\n updateReasons.push(\"lastReadTimestamp\");\n }\n }\n\n if (data.bindings && !isEqual(this.state.bindings, data.bindings)) {\n this.state.bindings = data.bindings;\n updateReasons.push(\"bindings\");\n }\n\n if (updateReasons.length > 0) {\n this.emit(Participant.updated, {\n participant: this,\n updateReasons: updateReasons,\n });\n }\n\n return this;\n }\n\n /**\n * Get the user for this participant and subscribes to it. Supported only for participants of type `chat`.\n */\n async getUser(): Promise<User> {\n if (this.type != \"chat\") {\n throw new Error(\n \"Getting User is not supported for this Participant type: \" + this.type\n );\n }\n\n return this.services.users.getUser(\n this.state.identity,\n this.state.userInfo\n );\n }\n\n /**\n * Remove the participant from the conversation.\n */\n async remove() {\n return this.conversation.removeParticipant(this);\n }\n\n /**\n * Update the attributes of the participant.\n * @param attributes New attributes.\n */\n @validateTypesAsync(json)\n async updateAttributes(attributes: JSONValue): Promise<Participant> {\n await this.services.commandExecutor.mutateResource<\n EditParticipantRequest,\n ParticipantResponse\n >(\"post\", this.links.self, {\n attributes: JSON.stringify(attributes),\n });\n\n return this;\n }\n}\n\nexport {\n ParticipantDescriptor,\n ParticipantServices,\n Participant,\n ParticipantUpdateReason,\n ParticipantType,\n ParticipantUpdatedEventArgs,\n ParticipantBindings,\n ParticipantEmailBinding,\n ParticipantEmailLevel,\n};\n"],"names":["Logger","ReplayEventEmitter","parseAttributes","parseTime","Conversation","isEqual","__decorate","validateTypesAsync","json"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAM,GAAG,GAAGA,aAAM,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;AAsFxC;;AAEG;AACH,MAAM,WAAY,SAAQC,qCAAqC,CAAA;AA6F7D;;AAEG;IACH,WACE,CAAA,IAA2B,EAC3B,GAAW,EACX,YAA0B,EAC1B,KAAuB,EACvB,QAA6B,EAAA;;AAE7B,QAAA,KAAK,EAAE,CAAC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],"sourcesContent":["import { Users } from \"./data/users\";\nimport { User } from \"./user\";\nimport { parseTime, parseAttributes } from \"./util\";\nimport { Logger } from \"./logger\";\nimport { Conversation } from \"./conversation\";\nimport { json } from \"./interfaces/rules\";\nimport { validateTypesAsync } from \"@twilio/declarative-type-validator\";\nimport { CommandExecutor } from \"./command-executor\";\nimport { EditParticipantRequest } from \"./interfaces/commands/edit-participant\";\nimport { ParticipantResponse } from \"./interfaces/commands/participant-response\";\nimport { ReplayEventEmitter } from \"@twilio/replay-event-emitter\";\nimport isEqual from \"lodash.isequal\";\nimport { JSONValue } from \"./types\";\n\ntype ParticipantEvents = {\n typingEnded: (participant: Participant) => void;\n typingStarted: (participant: Participant) => void;\n updated: (data: {\n participant: Participant;\n updateReasons: ParticipantUpdateReason[];\n }) => void;\n};\n\nconst log = Logger.scope(\"Participant\");\n\ninterface ParticipantDescriptor {\n attributes?: JSONValue;\n dateCreated: Date | null;\n dateUpdated: Date | null;\n identity: string;\n roleSid?: string;\n lastConsumedMessageIndex: number | null;\n lastConsumptionTimestamp: number | null;\n type: ParticipantType;\n userInfo?: string;\n bindings?: ParticipantBindings;\n}\n\ninterface ParticipantState {\n attributes: JSONValue;\n dateCreated: Date | null;\n dateUpdated: Date | null;\n identity: string;\n isTyping: boolean;\n lastReadMessageIndex: number | null;\n lastReadTimestamp: Date | null;\n roleSid: string;\n sid: string;\n type: ParticipantType;\n typingTimeout: number | null;\n userInfo?: string;\n bindings?: ParticipantBindings;\n}\n\ninterface ParticipantServices {\n users: Users;\n commandExecutor: CommandExecutor;\n}\n\ninterface ParticipantLinks {\n self: string;\n}\n\n/**\n * The reason for the `updated` event being emitted by a participant.\n */\ntype ParticipantUpdateReason =\n | \"attributes\"\n | \"dateCreated\"\n | \"dateUpdated\"\n | \"roleSid\"\n | \"lastReadMessageIndex\"\n | \"lastReadTimestamp\"\n | \"bindings\";\n\n/**\n * Participant type. The string variant can be used to denote new types of\n * participant that aren't supported by this version of the SDK.\n */\ntype ParticipantType = \"chat\" | \"sms\" | \"whatsapp\" | \"email\" | string;\n\ninterface ParticipantUpdatedEventArgs {\n participant: Participant;\n updateReasons: ParticipantUpdateReason[];\n}\n\n/**\n * Bindings for conversation participant.\n */\ninterface ParticipantBindings {\n email?: ParticipantEmailBinding;\n}\n\n/**\n * Email participation level.\n * to = to/from\n * cc = cc\n */\ntype ParticipantEmailLevel = \"to\" | \"cc\";\n\n/**\n * Bindings for email participant.\n */\ninterface ParticipantEmailBinding {\n name: string;\n address: string;\n level: ParticipantEmailLevel;\n}\n\n/**\n * A participant represents a remote client in a conversation.\n */\nclass Participant extends ReplayEventEmitter<ParticipantEvents> {\n private state: ParticipantState;\n private readonly links: ParticipantLinks;\n private readonly services: ParticipantServices;\n\n /**\n * Conversation that the remote client is a participant of.\n */\n public readonly conversation: Conversation;\n\n /**\n * The server-assigned unique identifier for the participant.\n */\n public get sid(): string {\n return this.state.sid;\n }\n\n /**\n * Custom attributes of the participant.\n */\n public get attributes(): JSONValue {\n return this.state.attributes;\n }\n\n /**\n * Date this participant was created on.\n */\n public get dateCreated(): Date | null {\n return this.state.dateCreated;\n }\n\n /**\n * Date this participant was last updated on.\n */\n public get dateUpdated(): Date | null {\n return this.state.dateUpdated;\n }\n\n /**\n * Identity of the participant.\n */\n public get identity(): string | null {\n return this.state.identity;\n }\n\n /**\n * Indicates whether the participant is currently typing.\n */\n public get isTyping(): boolean {\n return this.state.isTyping;\n }\n\n /**\n * The index of the last read message by the participant.\n * Note that retrieving messages on a client endpoint does not mean that messages are read,\n * please consider reading about the [Read Horizon feature](https://www.twilio.com/docs/api/chat/guides/consumption-horizon)\n * to find out about the proper way to mark messages as read.\n */\n public get lastReadMessageIndex(): number | null {\n return this.state.lastReadMessageIndex;\n }\n\n /**\n * Date of the most recent read horizon update.\n */\n public get lastReadTimestamp(): Date | null {\n return this.state.lastReadTimestamp;\n }\n\n public get roleSid(): string {\n return this.state.roleSid;\n }\n\n /**\n * Type of the participant.\n */\n public get type(): ParticipantType {\n return this.state.type;\n }\n\n /**\n * Get the bindings mapping for the current participant.\n * Available binding depends on the participant type.\n * You could access it as `participant.bindings.sms?.address` or\n * using the type dynamically `participant.bindings[participant.type]`\n * just be aware that the binding information has different structure for\n * each participant type.\n * See also {ParticipantEmailBinding}, the only available currently binding descriptor.\n */\n public get bindings(): ParticipantBindings {\n return this.state.bindings ?? {};\n }\n\n /**\n * @internal\n */\n constructor(\n data: ParticipantDescriptor,\n sid: string,\n conversation: Conversation,\n links: ParticipantLinks,\n services: ParticipantServices\n ) {\n super();\n\n this.conversation = conversation;\n this.links = links;\n this.services = services;\n this.state = {\n attributes: parseAttributes(\n data.attributes,\n \"Retrieved malformed attributes from the server for participant: \" +\n sid,\n log\n ),\n dateCreated: data.dateCreated ? parseTime(data.dateCreated) : null,\n dateUpdated: data.dateCreated ? parseTime(data.dateUpdated) : null,\n sid: sid,\n typingTimeout: null,\n isTyping: false,\n identity: data.identity,\n roleSid: data.roleSid ?? \"\",\n lastReadMessageIndex: Number.isInteger(data.lastConsumedMessageIndex)\n ? data.lastConsumedMessageIndex\n : null,\n lastReadTimestamp: data.lastConsumptionTimestamp\n ? parseTime(data.lastConsumptionTimestamp)\n : null,\n type: data.type || \"chat\",\n userInfo: data.userInfo,\n bindings: data.bindings ?? {},\n };\n\n if (!data.identity && !data.type) {\n throw new Error(\n \"Received invalid Participant object from server: Missing identity or type of Participant.\"\n );\n }\n }\n\n /**\n * Fired when the participant has started typing.\n *\n * Parameters:\n * 1. {@link Participant} `participant` - the participant in question\n * @event\n */\n static readonly typingStarted = \"typingStarted\";\n\n /**\n * Fired when the participant has stopped typing.\n *\n * Parameters:\n * 1. {@link Participant} `participant` - the participant in question\n * @event\n */\n static readonly typingEnded = \"typingEnded\";\n\n /**\n * Fired when the fields of the participant have been updated.\n *\n * Parameters:\n * 1. object `data` - info object provided with the event. It has the following properties:\n * * {@link Participant} participant - the participant in question\n * * {@link ParticipantUpdateReason}[] updateReasons - array of reasons for the update\n * @event\n */\n static readonly updated = \"updated\";\n\n /**\n * Internal method used to start or reset the typing indicator timeout (with event emitting).\n * @internal\n */\n _startTyping(timeout) {\n if (this.state.typingTimeout) {\n clearTimeout(this.state.typingTimeout);\n }\n\n this.state.isTyping = true;\n this.emit(Participant.typingStarted, this);\n\n this.conversation.emit(Conversation.typingStarted, this); // @fixme layering violation\n\n this.state.typingTimeout = Number(\n setTimeout(() => this._endTyping(), timeout)\n );\n return this;\n }\n\n /**\n * Internal method function used to stop the typing indicator timeout (with event emitting).\n * @internal\n */\n _endTyping() {\n if (!this.state.typingTimeout) {\n return;\n }\n\n this.state.isTyping = false;\n this.emit(Participant.typingEnded, this);\n\n this.conversation.emit(Conversation.typingEnded, this);\n\n clearInterval(this.state.typingTimeout);\n this.state.typingTimeout = null;\n }\n\n /**\n * Internal method function used update local object's property roleSid with a new value.\n * @internal\n */\n _update(data) {\n const updateReasons: ParticipantUpdateReason[] = [];\n\n const updateAttributes = parseAttributes(\n data.attributes,\n \"Retrieved malformed attributes from the server for participant: \" +\n this.state.sid,\n log\n );\n\n if (data.attributes && !isEqual(this.state.attributes, updateAttributes)) {\n this.state.attributes = updateAttributes;\n updateReasons.push(\"attributes\");\n }\n\n const updatedDateUpdated = parseTime(data.dateUpdated);\n if (\n data.dateUpdated &&\n updatedDateUpdated?.getTime() !==\n (this.state.dateUpdated && this.state.dateUpdated.getTime())\n ) {\n this.state.dateUpdated = updatedDateUpdated;\n updateReasons.push(\"dateUpdated\");\n }\n\n const updatedDateCreated = parseTime(data.dateCreated);\n if (\n data.dateCreated &&\n updatedDateCreated?.getTime() !==\n (this.state.dateCreated && this.state.dateCreated.getTime())\n ) {\n this.state.dateCreated = updatedDateCreated;\n updateReasons.push(\"dateCreated\");\n }\n\n if (data.roleSid && this.state.roleSid !== data.roleSid) {\n this.state.roleSid = data.roleSid;\n updateReasons.push(\"roleSid\");\n }\n\n if (\n (Number.isInteger(data.lastConsumedMessageIndex) ||\n data.lastConsumedMessageIndex === null) &&\n this.state.lastReadMessageIndex !== data.lastConsumedMessageIndex\n ) {\n this.state.lastReadMessageIndex = data.lastConsumedMessageIndex;\n updateReasons.push(\"lastReadMessageIndex\");\n }\n\n if (data.lastConsumptionTimestamp) {\n const lastReadTimestamp = new Date(data.lastConsumptionTimestamp);\n if (\n !this.state.lastReadTimestamp ||\n this.state.lastReadTimestamp.getTime() !== lastReadTimestamp.getTime()\n ) {\n this.state.lastReadTimestamp = lastReadTimestamp;\n updateReasons.push(\"lastReadTimestamp\");\n }\n }\n\n if (data.bindings && !isEqual(this.state.bindings, data.bindings)) {\n this.state.bindings = data.bindings;\n updateReasons.push(\"bindings\");\n }\n\n if (updateReasons.length > 0) {\n this.emit(Participant.updated, {\n participant: this,\n updateReasons: updateReasons,\n });\n }\n\n return this;\n }\n\n /**\n * Get the user for this participant and subscribes to it. Supported only for participants of type `chat`.\n */\n async getUser(): Promise<User> {\n if (this.type != \"chat\") {\n throw new Error(\n \"Getting User is not supported for this Participant type: \" + this.type\n );\n }\n\n return this.services.users.getUser(\n this.state.identity,\n this.state.userInfo\n );\n }\n\n /**\n * Remove the participant from the conversation.\n */\n async remove() {\n return this.conversation.removeParticipant(this);\n }\n\n /**\n * Update the attributes of the participant.\n * @param attributes New attributes.\n */\n @validateTypesAsync(json)\n async updateAttributes(attributes: JSONValue): Promise<Participant> {\n await this.services.commandExecutor.mutateResource<\n EditParticipantRequest,\n ParticipantResponse\n >(\"post\", this.links.self, {\n attributes: JSON.stringify(attributes),\n });\n\n return this;\n }\n}\n\nexport {\n ParticipantDescriptor,\n ParticipantServices,\n Participant,\n ParticipantUpdateReason,\n ParticipantType,\n ParticipantUpdatedEventArgs,\n ParticipantBindings,\n ParticipantEmailBinding,\n ParticipantEmailLevel,\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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W,CAAA,WAAA,GAAG,aAAa,CAAC;AAE5C;;;;;;;;AAQG;AACa,WAAO,CAAA,OAAA,GAAG,SAAS,CAAC;AAmJpC,UAAA,CAAA;IADC,kBAAkB,CAAC,IAAI,CAAC;;;;AAUxB,CAAA,EAAA,WAAA,CAAA,SAAA,EAAA,kBAAA,EAAA,IAAA,CAAA;;;;"};;;AAQG;AACa,WAAO,CAAA,OAAA,GAAG,SAAS,CAAC;AAmJpCC,oBAAA,CAAA;IADCC,2CAAkB,CAACC,UAAI,CAAC;;;;AAUxB,CAAA,EAAA,WAAA,CAAA,SAAA,EAAA,kBAAA,EAAA,IAAA,CAAA;;;;"}
|
@@ -126,8 +126,6 @@ This software includes platform.js under the following license.
|
|
126
126
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
127
127
|
|
128
128
|
*/
|
129
|
-
'use strict';
|
130
|
-
|
131
129
|
var global =
|
132
130
|
typeof global !== "undefined"
|
133
131
|
? global
|
@@ -137,8 +135,6 @@ var global =
|
|
137
135
|
? window
|
138
136
|
: {};
|
139
137
|
|
140
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
141
|
-
|
142
138
|
/**
|
143
139
|
* Push notification for a Conversations client.
|
144
140
|
*/
|
@@ -157,5 +153,10 @@ class PushNotification {
|
|
157
153
|
}
|
158
154
|
}
|
159
155
|
|
156
|
+
export { PushNotification };
|
157
|
+
//# sourceMappingURL=push-notification.js.map
|
158
|
+
|
159
|
+
}
|
160
|
+
|
160
161
|
exports.PushNotification = PushNotification;
|
161
162
|
//# sourceMappingURL=push-notification.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"push-notification.js","sources":["../src/push-notification.ts"],"sourcesContent":["/**\n * Push notification type.\n */\nimport { Media } from \"./media\";\n\ntype PushNotificationType =\n | \"twilio.conversations.new_message\"\n | \"twilio.conversations.added_to_conversation\"\n | \"twilio.conversations.removed_from_conversation\";\n\ninterface PushNotificationDescriptor {\n title: string | null;\n body: string | null;\n sound: string | null;\n badge: number | null;\n action: string | null;\n type: PushNotificationType;\n data: Record<string, unknown>;\n}\n\n/**\n * Additional data for a given push notification.\n */\ninterface PushNotificationData {\n /**\n * SID of the conversation.\n */\n conversationSid?: string;\n\n /**\n * Title of the conversation.\n */\n conversationTitle?: string;\n\n /**\n * Index of the message in the conversation.\n */\n messageIndex?: number;\n\n /**\n * SID of the message in the conversation.\n */\n messageSid?: string;\n\n /**\n * Media of the notification\n */\n media?: Media;\n\n /**\n * Count of the attached media of the message.\n */\n mediaCount?: number;\n}\n\n/**\n * Push notification for a Conversations client.\n */\nclass PushNotification {\n /**\n * Title of the notification.\n */\n public readonly title: string | null;\n\n /**\n * Text of the notification.\n */\n public readonly body: string | null;\n\n /**\n * Sound of the notification.\n */\n public readonly sound: string | null;\n\n /**\n * Number of the badge.\n */\n public readonly badge: number | null;\n\n /**\n * Notification action (`click_action` in FCM terms and `category` in APN terms).\n */\n public readonly action: string | null;\n\n /**\n * Type of the notification.\n */\n public readonly type: PushNotificationType;\n\n /**\n * Additional data of the conversation.\n */\n public readonly data: PushNotificationData;\n\n /**\n * @internal\n */\n constructor(data: PushNotificationDescriptor) {\n this.title = data.title || null;\n this.body = data.body || null;\n this.sound = data.sound || null;\n this.badge = data.badge || null;\n this.action = data.action || null;\n this.type = data.type || null;\n this.data = data.data || {};\n }\n}\n\nexport {\n PushNotification,\n PushNotificationType,\n PushNotificationDescriptor,\n PushNotificationData,\n};\n"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"push-notification.js","sources":["../src/push-notification.ts"],"sourcesContent":["/**\n * Push notification type.\n */\nimport { Media } from \"./media\";\n\ntype PushNotificationType =\n | \"twilio.conversations.new_message\"\n | \"twilio.conversations.added_to_conversation\"\n | \"twilio.conversations.removed_from_conversation\";\n\ninterface PushNotificationDescriptor {\n title: string | null;\n body: string | null;\n sound: string | null;\n badge: number | null;\n action: string | null;\n type: PushNotificationType;\n data: Record<string, unknown>;\n}\n\n/**\n * Additional data for a given push notification.\n */\ninterface PushNotificationData {\n /**\n * SID of the conversation.\n */\n conversationSid?: string;\n\n /**\n * Title of the conversation.\n */\n conversationTitle?: string;\n\n /**\n * Index of the message in the conversation.\n */\n messageIndex?: number;\n\n /**\n * SID of the message in the conversation.\n */\n messageSid?: string;\n\n /**\n * Media of the notification\n */\n media?: Media;\n\n /**\n * Count of the attached media of the message.\n */\n mediaCount?: number;\n}\n\n/**\n * Push notification for a Conversations client.\n */\nclass PushNotification {\n /**\n * Title of the notification.\n */\n public readonly title: string | null;\n\n /**\n * Text of the notification.\n */\n public readonly body: string | null;\n\n /**\n * Sound of the notification.\n */\n public readonly sound: string | null;\n\n /**\n * Number of the badge.\n */\n public readonly badge: number | null;\n\n /**\n * Notification action (`click_action` in FCM terms and `category` in APN terms).\n */\n public readonly action: string | null;\n\n /**\n * Type of the notification.\n */\n public readonly type: PushNotificationType;\n\n /**\n * Additional data of the conversation.\n */\n public readonly data: PushNotificationData;\n\n /**\n * @internal\n */\n constructor(data: PushNotificationDescriptor) {\n this.title = data.title || null;\n this.body = data.body || null;\n this.sound = data.sound || null;\n this.badge = data.badge || null;\n this.action = data.action || null;\n this.type = data.type || null;\n this.data = data.data || {};\n }\n}\n\nexport {\n PushNotification,\n PushNotificationType,\n PushNotificationDescriptor,\n PushNotificationData,\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuDA;;AAEG;AACH,MAAM,gBAAgB,CAAA;AAoCpB;;AAEG;AACH,IAAA,WAAA,CAAY,IAAgC,EAAA;QAC1C,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC;QAChC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC;QAC9B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC;QAChC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC;QAChC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC;QAClC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC;QAC9B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,EAAE,CAAC;KAC7B;AACF;;;;"};;"}
|
package/dist/rest-paginator.js
CHANGED
@@ -126,8 +126,6 @@ This software includes platform.js under the following license.
|
|
126
126
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
127
127
|
|
128
128
|
*/
|
129
|
-
'use strict';
|
130
|
-
|
131
129
|
var global =
|
132
130
|
typeof global !== "undefined"
|
133
131
|
? global
|
@@ -137,8 +135,6 @@ var global =
|
|
137
135
|
? window
|
138
136
|
: {};
|
139
137
|
|
140
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
141
|
-
|
142
138
|
/**
|
143
139
|
* Pagination helper class.
|
144
140
|
*/
|
@@ -190,5 +186,11 @@ class RestPaginator {
|
|
190
186
|
}
|
191
187
|
}
|
192
188
|
|
189
|
+
export { RestPaginator };
|
190
|
+
//# sourceMappingURL=rest-paginator.js.map
|
191
|
+
|
192
|
+
}
|
193
|
+
}
|
194
|
+
|
193
195
|
exports.RestPaginator = RestPaginator;
|
194
196
|
//# sourceMappingURL=rest-paginator.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"rest-paginator.js","sources":["../src/rest-paginator.ts"],"sourcesContent":["import { Paginator } from \"./interfaces/paginator\";\n\ninterface PaginatorState<T> {\n source: (token: string) => Promise<RestPaginator<T>>;\n nextToken: string;\n prevToken: string;\n items: T[];\n}\n\n/**\n * Pagination helper class.\n */\nclass RestPaginator<T> implements Paginator<T> {\n private state: PaginatorState<T>;\n\n /**\n * Indicates the existence of the next page.\n */\n public get hasNextPage(): boolean {\n return !!this.state.nextToken;\n }\n\n /**\n * Indicates the existence of the previous page\n */\n public get hasPrevPage(): boolean {\n return !!this.state.prevToken;\n }\n\n /**\n * Array of elements on the current page.\n */\n public get items(): T[] {\n return this.state.items;\n }\n\n /**\n * @internal\n */\n constructor(items, source, prevToken, nextToken) {\n this.state = {\n prevToken,\n nextToken,\n source,\n items,\n };\n }\n\n /**\n * Request the next page. Does not modify the existing object.\n */\n nextPage(): Promise<RestPaginator<T>> {\n return this.hasNextPage\n ? this.state.source(this.state.nextToken)\n : Promise.reject(new Error(\"No next page\"));\n }\n\n /**\n * Request the previous page. Does not modify the existing object.\n */\n prevPage(): Promise<RestPaginator<T>> {\n return this.hasPrevPage\n ? this.state.source(this.state.prevToken)\n : Promise.reject(new Error(\"No previous page\"));\n }\n}\n\nexport { RestPaginator };\n"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"rest-paginator.js","sources":["../src/rest-paginator.ts"],"sourcesContent":["import { Paginator } from \"./interfaces/paginator\";\n\ninterface PaginatorState<T> {\n source: (token: string) => Promise<RestPaginator<T>>;\n nextToken: string;\n prevToken: string;\n items: T[];\n}\n\n/**\n * Pagination helper class.\n */\nclass RestPaginator<T> implements Paginator<T> {\n private state: PaginatorState<T>;\n\n /**\n * Indicates the existence of the next page.\n */\n public get hasNextPage(): boolean {\n return !!this.state.nextToken;\n }\n\n /**\n * Indicates the existence of the previous page\n */\n public get hasPrevPage(): boolean {\n return !!this.state.prevToken;\n }\n\n /**\n * Array of elements on the current page.\n */\n public get items(): T[] {\n return this.state.items;\n }\n\n /**\n * @internal\n */\n constructor(items, source, prevToken, nextToken) {\n this.state = {\n prevToken,\n nextToken,\n source,\n items,\n };\n }\n\n /**\n * Request the next page. Does not modify the existing object.\n */\n nextPage(): Promise<RestPaginator<T>> {\n return this.hasNextPage\n ? this.state.source(this.state.nextToken)\n : Promise.reject(new Error(\"No next page\"));\n }\n\n /**\n * Request the previous page. Does not modify the existing object.\n */\n prevPage(): Promise<RestPaginator<T>> {\n return this.hasPrevPage\n ? this.state.source(this.state.prevToken)\n : Promise.reject(new Error(\"No previous page\"));\n }\n}\n\nexport { RestPaginator };\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA;;AAEG;AACH,MAAM,aAAa,CAAA;AAwBjB;;AAEG;AACH,IAAA,WAAA,CAAY,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAA;QAC7C,IAAI,CAAC,KAAK,GAAG;YACX,SAAS;YACT,SAAS;YACT,MAAM;YACN,KAAK;SACN,CAAC;KACH;AA/BD;;AAEG;AACH,IAAA,IAAW,WAAW,GAAA;AACpB,QAAA,OAAO,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC;KAC/B;AAED;;AAEG;AACH,IAAA,IAAW,WAAW,GAAA;AACpB,QAAA,OAAO,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC;KAC/B;AAED;;AAEG;AACH,IAAA,IAAW,KAAK,GAAA;AACd,QAAA,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC;KACzB;AAcD;;AAEG;IACH,QAAQ,GAAA;QACN,OAAO,IAAI,CAAC,WAAW;AACrB,cAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC;cACvC,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC;KAC/C;AAED;;AAEG;IACH,QAAQ,GAAA;QACN,OAAO,IAAI,CAAC,WAAW;AACrB,cAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC;cACvC,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC,CAAC;KACnD;AACF;;;;"};;"}
|
package/dist/services/network.js
CHANGED
@@ -126,8 +126,6 @@ This software includes platform.js under the following license.
|
|
126
126
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
127
127
|
|
128
128
|
*/
|
129
|
-
'use strict';
|
130
|
-
|
131
129
|
var global =
|
132
130
|
typeof global !== "undefined"
|
133
131
|
? global
|
@@ -137,9 +135,7 @@ var global =
|
|
137
135
|
? window
|
138
136
|
: {};
|
139
137
|
|
140
|
-
|
141
|
-
|
142
|
-
var operationRetrier = require('@twilio/operation-retrier');
|
138
|
+
import { Retrier } from '@twilio/operation-retrier';
|
143
139
|
|
144
140
|
class Network {
|
145
141
|
constructor(configuration, services) {
|
@@ -173,7 +169,7 @@ class Network {
|
|
173
169
|
if (retryWhenThrottled) {
|
174
170
|
codesToRetryOn.push(429);
|
175
171
|
}
|
176
|
-
const retrier = new
|
172
|
+
const retrier = new Retrier(this.configuration.backoffConfiguration);
|
177
173
|
retrier.on("attempt", () => {
|
178
174
|
request()
|
179
175
|
.then((result) => retrier.succeeded(result))
|
@@ -214,5 +210,5 @@ class Network {
|
|
214
210
|
}
|
215
211
|
}
|
216
212
|
|
217
|
-
|
213
|
+
export { Network };
|
218
214
|
//# sourceMappingURL=network.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"network.js","sources":["../../src/services/network.ts"],"sourcesContent":["import { Retrier } from \"@twilio/operation-retrier\";\nimport { Transport, TransportResult } from \"twilsock\";\nimport { Configuration } from \"../configuration\";\n\nimport Timeout = NodeJS.Timeout;\n\ninterface CacheEntry {\n response: TransportResult<unknown>;\n timestamp: number;\n}\n\nexport interface NetworkServices {\n transport: Transport;\n}\n\nclass Network {\n private readonly configuration: Configuration;\n private readonly services: NetworkServices;\n private cacheLifetime: number;\n\n private readonly cache: Map<string, CacheEntry>;\n private timer!: number | NodeJS.Timeout;\n\n constructor(configuration, services) {\n this.configuration = configuration;\n this.services = services;\n this.cache = new Map<string, CacheEntry>();\n this.cacheLifetime = this.configuration.httpCacheInterval * 100;\n this.cleanupCache();\n }\n\n private isExpired(timestamp: number): boolean {\n return !this.cacheLifetime || Date.now() - timestamp > this.cacheLifetime;\n }\n\n private cleanupCache() {\n for (const [k, v] of this.cache) {\n if (this.isExpired(v.timestamp)) {\n this.cache.delete(k);\n }\n }\n\n if (this.cache.size === 0) {\n clearInterval(this.timer as Timeout);\n }\n }\n\n pokeTimer() {\n this.timer =\n this.timer ||\n setInterval(() => this.cleanupCache(), this.cacheLifetime * 2);\n }\n\n private executeWithRetry<T>(\n request,\n retryWhenThrottled = false\n ): Promise<TransportResult<T>> {\n return new Promise((resolve, reject) => {\n const codesToRetryOn = [502, 503, 504];\n if (retryWhenThrottled) {\n codesToRetryOn.push(429);\n }\n\n const retrier = new Retrier(this.configuration.backoffConfiguration);\n retrier.on(\"attempt\", () => {\n request()\n .then((result) => retrier.succeeded(result))\n .catch((err) => {\n if (codesToRetryOn.indexOf(err.status) > -1) {\n retrier.failed(err);\n } else if (err.message === \"Twilsock disconnected\") {\n // Ugly hack. We must make a proper exceptions for twilsock\n retrier.failed(err);\n } else {\n // Fatal error\n retrier.removeAllListeners();\n retrier.cancel();\n reject(err);\n }\n });\n });\n\n retrier.on(\"succeeded\", (result) => {\n resolve(result);\n });\n retrier.on(\"cancelled\", (err) => reject(err));\n retrier.on(\"failed\", (err) => reject(err));\n\n retrier.start();\n });\n }\n\n async get<T>(url: string): Promise<TransportResult<T>> {\n const cacheEntry = this.cache.get(url);\n if (cacheEntry && !this.isExpired(cacheEntry.timestamp)) {\n return cacheEntry.response as TransportResult<T>;\n }\n\n const headers = {};\n const response = await this.executeWithRetry<T>(\n () =>\n this.services.transport.get<T>(\n url,\n headers,\n this.configuration.productId\n ),\n this.configuration.retryWhenThrottled\n );\n this.cache.set(url, { response, timestamp: Date.now() });\n this.pokeTimer();\n return response;\n }\n}\n\nexport { Network };\n"],"names":[
|
1
|
+
{"version":3,"file":"network.js","sources":["../../src/services/network.ts"],"sourcesContent":["import { Retrier } from \"@twilio/operation-retrier\";\nimport { Transport, TransportResult } from \"twilsock\";\nimport { Configuration } from \"../configuration\";\n\nimport Timeout = NodeJS.Timeout;\n\ninterface CacheEntry {\n response: TransportResult<unknown>;\n timestamp: number;\n}\n\nexport interface NetworkServices {\n transport: Transport;\n}\n\nclass Network {\n private readonly configuration: Configuration;\n private readonly services: NetworkServices;\n private cacheLifetime: number;\n\n private readonly cache: Map<string, CacheEntry>;\n private timer!: number | NodeJS.Timeout;\n\n constructor(configuration, services) {\n this.configuration = configuration;\n this.services = services;\n this.cache = new Map<string, CacheEntry>();\n this.cacheLifetime = this.configuration.httpCacheInterval * 100;\n this.cleanupCache();\n }\n\n private isExpired(timestamp: number): boolean {\n return !this.cacheLifetime || Date.now() - timestamp > this.cacheLifetime;\n }\n\n private cleanupCache() {\n for (const [k, v] of this.cache) {\n if (this.isExpired(v.timestamp)) {\n this.cache.delete(k);\n }\n }\n\n if (this.cache.size === 0) {\n clearInterval(this.timer as Timeout);\n }\n }\n\n pokeTimer() {\n this.timer =\n this.timer ||\n setInterval(() => this.cleanupCache(), this.cacheLifetime * 2);\n }\n\n private executeWithRetry<T>(\n request,\n retryWhenThrottled = false\n ): Promise<TransportResult<T>> {\n return new Promise((resolve, reject) => {\n const codesToRetryOn = [502, 503, 504];\n if (retryWhenThrottled) {\n codesToRetryOn.push(429);\n }\n\n const retrier = new Retrier(this.configuration.backoffConfiguration);\n retrier.on(\"attempt\", () => {\n request()\n .then((result) => retrier.succeeded(result))\n .catch((err) => {\n if (codesToRetryOn.indexOf(err.status) > -1) {\n retrier.failed(err);\n } else if (err.message === \"Twilsock disconnected\") {\n // Ugly hack. We must make a proper exceptions for twilsock\n retrier.failed(err);\n } else {\n // Fatal error\n retrier.removeAllListeners();\n retrier.cancel();\n reject(err);\n }\n });\n });\n\n retrier.on(\"succeeded\", (result) => {\n resolve(result);\n });\n retrier.on(\"cancelled\", (err) => reject(err));\n retrier.on(\"failed\", (err) => reject(err));\n\n retrier.start();\n });\n }\n\n async get<T>(url: string): Promise<TransportResult<T>> {\n const cacheEntry = this.cache.get(url);\n if (cacheEntry && !this.isExpired(cacheEntry.timestamp)) {\n return cacheEntry.response as TransportResult<T>;\n }\n\n const headers = {};\n const response = await this.executeWithRetry<T>(\n () =>\n this.services.transport.get<T>(\n url,\n headers,\n this.configuration.productId\n ),\n this.configuration.retryWhenThrottled\n );\n this.cache.set(url, { response, timestamp: Date.now() });\n this.pokeTimer();\n return response;\n }\n}\n\nexport { Network };\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeA,MAAM,OAAO,CAAA;IAQX,WAAY,CAAA,aAAa,EAAE,QAAQ,EAAA;AACjC,QAAA,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;AACnC,QAAA,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;AACzB,QAAA,IAAI,CAAC,KAAK,GAAG,IAAI,GAAG,EAAsB,CAAC;QAC3C,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,aAAa,CAAC,iBAAiB,GAAG,GAAG,CAAC;QAChE,IAAI,CAAC,YAAY,EAAE,CAAC;KACrB;AAEO,IAAA,SAAS,CAAC,SAAiB,EAAA;AACjC,QAAA,OAAO,CAAC,IAAI,CAAC,aAAa,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,GAAG,IAAI,CAAC,aAAa,CAAC;KAC3E;IAEO,YAAY,GAAA;QAClB,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,EAAE;YAC/B,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K,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;QACzD,IAAI,CAAC,SAAS,EAAE,CAAC;AACjB,QAAA,OAAO,QAAQ,CAAC;KACjB;AACF;;;;"}
|
@@ -126,8 +126,6 @@ This software includes platform.js under the following license.
|
|
126
126
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
127
127
|
|
128
128
|
*/
|
129
|
-
'use strict';
|
130
|
-
|
131
129
|
var global =
|
132
130
|
typeof global !== "undefined"
|
133
131
|
? global
|
@@ -137,12 +135,10 @@ var global =
|
|
137
135
|
? window
|
138
136
|
: {};
|
139
137
|
|
140
|
-
|
141
|
-
|
142
|
-
var logger = require('../logger.js');
|
143
|
-
var notificationTypes = require('../interfaces/notification-types.js');
|
138
|
+
import { Logger } from '../logger.js';
|
139
|
+
import { NotificationTypes } from '../interfaces/notification-types.js';
|
144
140
|
|
145
|
-
const log =
|
141
|
+
const log = Logger.scope("TypingIndicator");
|
146
142
|
/**
|
147
143
|
* An important note in regards to typing timeout timers. There are two places that the SDK can get the "typing_timeout" attribute from. The first
|
148
144
|
* place that the attribute appears in is the response received from POST -> /v1/typing REST call. In the body of that response, the value of the
|
@@ -180,7 +176,7 @@ class TypingIndicator {
|
|
180
176
|
initialize() {
|
181
177
|
// this.services.notificationClient.subscribe(NotificationTypes.TYPING_INDICATOR, 'twilsock');
|
182
178
|
this.services.notificationClient.on("message", async (type, message) => {
|
183
|
-
if (type ===
|
179
|
+
if (type === NotificationTypes.TYPING_INDICATOR) {
|
184
180
|
await this._handleRemoteTyping(message);
|
185
181
|
}
|
186
182
|
});
|
@@ -243,5 +239,12 @@ class TypingIndicator {
|
|
243
239
|
}
|
244
240
|
}
|
245
241
|
|
242
|
+
export { TypingIndicator };
|
243
|
+
//# sourceMappingURL=typing-indicator.js.map
|
244
|
+
ow err;
|
245
|
+
});
|
246
|
+
}
|
247
|
+
}
|
248
|
+
|
246
249
|
exports.TypingIndicator = TypingIndicator;
|
247
250
|
//# sourceMappingURL=typing-indicator.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"typing-indicator.js","sources":["../../src/services/typing-indicator.ts"],"sourcesContent":["import { Logger } from \"../logger\";\n\nimport { Notifications } from \"@twilio/notifications\";\n\nimport { NotificationTypes } from \"../interfaces/notification-types\";\nimport { TwilsockClient } from \"twilsock\";\nimport { Configuration } from \"../configuration\";\nimport { Conversation } from \"../conversation\";\n\nconst log = Logger.scope(\"TypingIndicator\");\n\nexport interface TypingIndicatorServices {\n twilsockClient: TwilsockClient;\n notificationClient: Notifications;\n}\n\n/**\n * An important note in regards to typing timeout timers. There are two places that the SDK can get the \"typing_timeout\" attribute from. The first\n * place that the attribute appears in is the response received from POST -> /v1/typing REST call. In the body of that response, the value of the\n * \"typing_timeout\" attribute will be exactly the same as defined in the console. The second place that the attribute appears in is from a\n * notification of type \"twilio.ipmsg.typing_indicator\". In this case, the \"typing_timeout\" value will be +1 of that in the console. This\n * intentional. The timeout returned from the POST -> /v1/typing call should be used to disable further calls for that period of time. On contrary,\n * the timeout returned from the notification should be used as the timeout for the \"typingEnded\" event, +1 is to account for latency.\n *\n * @private\n */\n\n/**\n * @class TypingIndicator\n *\n * @constructor\n * @private\n */\nclass TypingIndicator {\n private readonly services: TypingIndicatorServices;\n private readonly configuration: Configuration;\n\n private sentUpdates: Map<string, number>;\n private getConversation: (conversationSid: string) => Promise<Conversation>;\n private serviceTypingTimeout;\n\n constructor(\n getConversation: (conversationSid: string) => Promise<Conversation>,\n config: Configuration,\n services: TypingIndicatorServices\n ) {\n this.configuration = config;\n this.services = services;\n this.getConversation = getConversation;\n\n this.serviceTypingTimeout = null;\n this.sentUpdates = new Map();\n }\n\n public get typingTimeout(): number {\n return (\n this.configuration.typingIndicatorTimeoutOverride ||\n this.serviceTypingTimeout ||\n this.configuration.typingIndicatorTimeoutDefault\n );\n }\n\n /**\n * Initialize TypingIndicator controller\n * Registers for needed message types and sets listeners\n * @private\n */\n initialize(): void {\n // this.services.notificationClient.subscribe(NotificationTypes.TYPING_INDICATOR, 'twilsock');\n this.services.notificationClient.on(\"message\", async (type, message) => {\n if (type === NotificationTypes.TYPING_INDICATOR) {\n await this._handleRemoteTyping(message);\n }\n });\n }\n\n /**\n * Remote participants typing events handler\n */\n private async _handleRemoteTyping(message) {\n log.trace(\"Got new typing indicator \", message);\n\n this.getConversation(message.channel_sid)\n .then((conversation) => {\n if (!conversation) {\n return;\n }\n\n conversation._participants.forEach((participant) => {\n if (participant.identity !== message.identity) {\n return;\n }\n\n const timeout = this.configuration.typingIndicatorTimeoutOverride\n ? this.configuration.typingIndicatorTimeoutOverride + 1000\n : message.typing_timeout * 1000;\n participant._startTyping(timeout);\n });\n })\n .catch((err) => {\n log.error(err);\n throw err;\n });\n }\n\n /**\n * Send typing event for the given conversation sid\n * @param {String} conversationSid\n */\n send(conversationSid: string) {\n const lastUpdate = this.sentUpdates.get(conversationSid);\n if (lastUpdate && lastUpdate > Date.now() - this.typingTimeout) {\n return Promise.resolve();\n }\n\n this.sentUpdates.set(conversationSid, Date.now());\n return this._send(conversationSid);\n }\n\n private _send(conversationSid: string) {\n log.trace(\"Sending typing indicator\");\n\n const url = this.configuration.links.typing;\n const headers = {\n \"Content-Type\": \"application/x-www-form-urlencoded\",\n };\n const body = `ChannelSid=${conversationSid}`;\n\n return this.services.twilsockClient\n .post<{ typing_timeout: number }>(\n url,\n headers,\n body,\n this.configuration.productId\n )\n .then((response) => {\n if (response.body.hasOwnProperty(\"typing_timeout\")) {\n this.serviceTypingTimeout = response.body.typing_timeout * 1000;\n }\n })\n .catch((err) => {\n log.error(\"Failed to send typing indicator:\", err);\n throw err;\n });\n }\n}\n\nexport { TypingIndicator };\n"],"names":[
|
1
|
+
{"version":3,"file":"typing-indicator.js","sources":["../../src/services/typing-indicator.ts"],"sourcesContent":["import { Logger } from \"../logger\";\n\nimport { Notifications } from \"@twilio/notifications\";\n\nimport { NotificationTypes } from \"../interfaces/notification-types\";\nimport { TwilsockClient } from \"twilsock\";\nimport { Configuration } from \"../configuration\";\nimport { Conversation } from \"../conversation\";\n\nconst log = Logger.scope(\"TypingIndicator\");\n\nexport interface TypingIndicatorServices {\n twilsockClient: TwilsockClient;\n notificationClient: Notifications;\n}\n\n/**\n * An important note in regards to typing timeout timers. There are two places that the SDK can get the \"typing_timeout\" attribute from. The first\n * place that the attribute appears in is the response received from POST -> /v1/typing REST call. In the body of that response, the value of the\n * \"typing_timeout\" attribute will be exactly the same as defined in the console. The second place that the attribute appears in is from a\n * notification of type \"twilio.ipmsg.typing_indicator\". In this case, the \"typing_timeout\" value will be +1 of that in the console. This\n * intentional. The timeout returned from the POST -> /v1/typing call should be used to disable further calls for that period of time. On contrary,\n * the timeout returned from the notification should be used as the timeout for the \"typingEnded\" event, +1 is to account for latency.\n *\n * @private\n */\n\n/**\n * @class TypingIndicator\n *\n * @constructor\n * @private\n */\nclass TypingIndicator {\n private readonly services: TypingIndicatorServices;\n private readonly configuration: Configuration;\n\n private sentUpdates: Map<string, number>;\n private getConversation: (conversationSid: string) => Promise<Conversation>;\n private serviceTypingTimeout;\n\n constructor(\n getConversation: (conversationSid: string) => Promise<Conversation>,\n config: Configuration,\n services: TypingIndicatorServices\n ) {\n this.configuration = config;\n this.services = services;\n this.getConversation = getConversation;\n\n this.serviceTypingTimeout = null;\n this.sentUpdates = new Map();\n }\n\n public get typingTimeout(): number {\n return (\n this.configuration.typingIndicatorTimeoutOverride ||\n this.serviceTypingTimeout ||\n this.configuration.typingIndicatorTimeoutDefault\n );\n }\n\n /**\n * Initialize TypingIndicator controller\n * Registers for needed message types and sets listeners\n * @private\n */\n initialize(): void {\n // this.services.notificationClient.subscribe(NotificationTypes.TYPING_INDICATOR, 'twilsock');\n this.services.notificationClient.on(\"message\", async (type, message) => {\n if (type === NotificationTypes.TYPING_INDICATOR) {\n await this._handleRemoteTyping(message);\n }\n });\n }\n\n /**\n * Remote participants typing events handler\n */\n private async _handleRemoteTyping(message) {\n log.trace(\"Got new typing indicator \", message);\n\n this.getConversation(message.channel_sid)\n .then((conversation) => {\n if (!conversation) {\n return;\n }\n\n conversation._participants.forEach((participant) => {\n if (participant.identity !== message.identity) {\n return;\n }\n\n const timeout = this.configuration.typingIndicatorTimeoutOverride\n ? this.configuration.typingIndicatorTimeoutOverride + 1000\n : message.typing_timeout * 1000;\n participant._startTyping(timeout);\n });\n })\n .catch((err) => {\n log.error(err);\n throw err;\n });\n }\n\n /**\n * Send typing event for the given conversation sid\n * @param {String} conversationSid\n */\n send(conversationSid: string) {\n const lastUpdate = this.sentUpdates.get(conversationSid);\n if (lastUpdate && lastUpdate > Date.now() - this.typingTimeout) {\n return Promise.resolve();\n }\n\n this.sentUpdates.set(conversationSid, Date.now());\n return this._send(conversationSid);\n }\n\n private _send(conversationSid: string) {\n log.trace(\"Sending typing indicator\");\n\n const url = this.configuration.links.typing;\n const headers = {\n \"Content-Type\": \"application/x-www-form-urlencoded\",\n };\n const body = `ChannelSid=${conversationSid}`;\n\n return this.services.twilsockClient\n .post<{ typing_timeout: number }>(\n url,\n headers,\n body,\n this.configuration.productId\n )\n .then((response) => {\n if (response.body.hasOwnProperty(\"typing_timeout\")) {\n this.serviceTypingTimeout = response.body.typing_timeout * 1000;\n }\n })\n .catch((err) => {\n log.error(\"Failed to send typing indicator:\", err);\n throw err;\n });\n }\n}\n\nexport { TypingIndicator };\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;AAO5C;;;;;;;;;AASG;AAEH;;;;;AAKG;AACH,MAAM,eAAe,CAAA;AAQnB,IAA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CACH,GAAG,EACH,OAAO,EACP,IAAI,EACJ,IAAI,CAAC,aAAa,CAAC,SAAS,CAC7B;AACA,aAAA,IAAI,CAAC,CAAC,QAAQ,KAAI;YACjB,IAAI,QAAQ,CAAC,IAAI,CAAC,cAAc,CAAC,gBAAgB,CAAC,EAAE;gBAClD,IAAI,CAAC,oBAAoB,GAAG,QAAQ,CAAC,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;AACjE,aAAA;AACH,SAAC,CAAC;AACD,aAAA,KAAK,CAAC,CAAC,GAAG,KAAI;AACb,YAAA,GAAG,CAAC,KAAK,CAAC,kCAAkC,EAAE,GAAG,CAAC,CAAC;AACnD,YAAA,MAAM,GAAG,CAAC;AACZ,SAAC,CAAC,CAAC;KACN;AACF;;;;"}ACZ,SAAC,CAAC,CAAC;KACN;AACF;;;;"}
|
package/dist/unsent-message.js
CHANGED
@@ -126,8 +126,6 @@ This software includes platform.js under the following license.
|
|
126
126
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
127
127
|
|
128
128
|
*/
|
129
|
-
'use strict';
|
130
|
-
|
131
129
|
var global =
|
132
130
|
typeof global !== "undefined"
|
133
131
|
? global
|
@@ -137,10 +135,8 @@ var global =
|
|
137
135
|
? window
|
138
136
|
: {};
|
139
137
|
|
140
|
-
|
141
|
-
|
142
|
-
var mcsClient = require('@twilio/mcs-client');
|
143
|
-
var index = require('./util/index.js');
|
138
|
+
import { CancellablePromise } from '@twilio/mcs-client';
|
139
|
+
import { parseToNumber } from './util/index.js';
|
144
140
|
|
145
141
|
/**
|
146
142
|
* An unsent message. Returned from {@link MessageBuilder.build}.
|
@@ -160,12 +156,12 @@ class UnsentMessage {
|
|
160
156
|
* @returns Index of the new message in the conversation.
|
161
157
|
*/
|
162
158
|
send() {
|
163
|
-
return new
|
159
|
+
return new CancellablePromise(async (resolve, reject, onCancel) => {
|
164
160
|
const request = this.messagesEntity.sendV2(this);
|
165
161
|
onCancel(() => request.cancel());
|
166
162
|
try {
|
167
163
|
const response = await request;
|
168
|
-
resolve(
|
164
|
+
resolve(parseToNumber(response.index));
|
169
165
|
}
|
170
166
|
catch (e) {
|
171
167
|
reject(e);
|
@@ -174,5 +170,10 @@ class UnsentMessage {
|
|
174
170
|
}
|
175
171
|
}
|
176
172
|
|
173
|
+
export { UnsentMessage };
|
174
|
+
//# sourceMappingURL=unsent-message.js.map
|
175
|
+
}
|
176
|
+
}
|
177
|
+
|
177
178
|
exports.UnsentMessage = UnsentMessage;
|
178
179
|
//# sourceMappingURL=unsent-message.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"unsent-message.js","sources":["../src/unsent-message.ts"],"sourcesContent":["import { MediaCategory, CancellablePromise } from \"@twilio/mcs-client\";\nimport { parseToNumber } from \"./util\";\nimport { SendEmailOptions, SendMediaOptions } from \"./conversation\";\nimport { JSONValue } from \"./types\";\nimport { Messages } from \"./data/messages\";\nimport { ContentTemplateVariable } from \"./content-template\";\n\n/**\n * An unsent message. Returned from {@link MessageBuilder.build}.\n */\nclass UnsentMessage {\n public text?: string;\n public attributes: JSONValue = {};\n public mediaContent: [MediaCategory, FormData | SendMediaOptions][] = [];\n public emailOptions: SendEmailOptions = {};\n public contentSid?: string;\n public contentVariables?: ContentTemplateVariable[];\n\n /**\n * @internal\n */\n constructor(private messagesEntity: Messages) {}\n\n /**\n * Send the prepared message to the conversation.\n * @returns Index of the new message in the conversation.\n */\n send(): CancellablePromise<number | null> {\n return new CancellablePromise(async (resolve, reject, onCancel) => {\n const request = this.messagesEntity.sendV2(this);\n onCancel(() => request.cancel());\n try {\n const response = await request;\n resolve(parseToNumber(response.index));\n } catch (e) {\n reject(e);\n }\n });\n }\n}\n\nexport { UnsentMessage };\n"],"names":[
|
1
|
+
{"version":3,"file":"unsent-message.js","sources":["../src/unsent-message.ts"],"sourcesContent":["import { MediaCategory, CancellablePromise } from \"@twilio/mcs-client\";\nimport { parseToNumber } from \"./util\";\nimport { SendEmailOptions, SendMediaOptions } from \"./conversation\";\nimport { JSONValue } from \"./types\";\nimport { Messages } from \"./data/messages\";\nimport { ContentTemplateVariable } from \"./content-template\";\n\n/**\n * An unsent message. Returned from {@link MessageBuilder.build}.\n */\nclass UnsentMessage {\n public text?: string;\n public attributes: JSONValue = {};\n public mediaContent: [MediaCategory, FormData | SendMediaOptions][] = [];\n public emailOptions: SendEmailOptions = {};\n public contentSid?: string;\n public contentVariables?: ContentTemplateVariable[];\n\n /**\n * @internal\n */\n constructor(private messagesEntity: Messages) {}\n\n /**\n * Send the prepared message to the conversation.\n * @returns Index of the new message in the conversation.\n */\n send(): CancellablePromise<number | null> {\n return new CancellablePromise(async (resolve, reject, onCancel) => {\n const request = this.messagesEntity.sendV2(this);\n onCancel(() => request.cancel());\n try {\n const response = await request;\n resolve(parseToNumber(response.index));\n } catch (e) {\n reject(e);\n }\n });\n }\n}\n\nexport { UnsentMessage };\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA;;AAEG;AACH,MAAM,aAAa,CAAA;AAQjB;;AAEG;AACH,IAAA,WAAA,CAAoB,cAAwB,EAAA;QAAxB,IAAc,CAAA,cAAA,GAAd,cAAc,CAAU;QATrC,IAAU,CAAA,UAAA,GAAc,EAAE,CAAC;QAC3B,IAAY,CAAA,YAAA,GAAmD,EAAE,CAAC;QAClE,IAAY,CAAA,YAAA,GAAqB,EAAE,CAAC;KAOK;AAEhD;;;AAGG;IACH,IAAI,GAAA;QACF,OAAO,IAAI,kBAAkB,CAAC,OAAO,OAAO,EAAE,MAAM,EAAE,QAAQ,KAAI;YAChE,MAAM,OAAO,GAAG,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YACjD,QAAQ,CAAC,MAAM,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;YACjC,IAAI;AACF,gBAAA,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC;gBAC/B,OAAO,CAAC,aAAa,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;AACxC,aAAA;AAAC,YAAA,OAAO,CAAC,EAAE;gBACV,MAAM,CAAC,CAAC,CAAC,CAAC;AACX,aAAA;AACH,SAAC,CAAC,CAAC;KACJ;AACF;;;;"}CX,aAAA;AACH,SAAC,CAAC,CAAC;KACJ;AACF;;;;"}
|
package/dist/user.js
CHANGED
@@ -126,8 +126,6 @@ This software includes platform.js under the following license.
|
|
126
126
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
127
127
|
|
128
128
|
*/
|
129
|
-
'use strict';
|
130
|
-
|
131
129
|
var global =
|
132
130
|
typeof global !== "undefined"
|
133
131
|
? global
|
@@ -137,28 +135,22 @@ var global =
|
|
137
135
|
? window
|
138
136
|
: {};
|
139
137
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
var replayEventEmitter = require('@twilio/replay-event-emitter');
|
148
|
-
var isEqual = require('lodash.isequal');
|
149
|
-
|
150
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
138
|
+
import { __decorate, __metadata } from './node_modules/tslib/tslib.es6.js';
|
139
|
+
import { Logger } from './logger.js';
|
140
|
+
import { parseAttributes } from './util/index.js';
|
141
|
+
import { validateTypesAsync } from '@twilio/declarative-type-validator';
|
142
|
+
import { json } from './interfaces/rules.js';
|
143
|
+
import { ReplayEventEmitter } from '@twilio/replay-event-emitter';
|
144
|
+
import isEqual from 'lodash.isequal';
|
151
145
|
|
152
|
-
|
153
|
-
|
154
|
-
const log = logger.Logger.scope("User");
|
146
|
+
const log = Logger.scope("User");
|
155
147
|
/**
|
156
148
|
* Extended user information.
|
157
149
|
* Note that `isOnline` and `isNotifiable` properties are eligible
|
158
150
|
* for use only if the reachability function is enabled.
|
159
151
|
* You may check if it is enabled by reading the value of {@link Client.reachabilityEnabled}.
|
160
152
|
*/
|
161
|
-
class User extends
|
153
|
+
class User extends ReplayEventEmitter {
|
162
154
|
/**
|
163
155
|
* @internal
|
164
156
|
*/
|
@@ -264,8 +256,8 @@ class User extends replayEventEmitter.ReplayEventEmitter {
|
|
264
256
|
}
|
265
257
|
break;
|
266
258
|
case "attributes":
|
267
|
-
const updateAttributes =
|
268
|
-
if (!
|
259
|
+
const updateAttributes = parseAttributes(value.value, `Retrieved malformed attributes from the server for user: ${this.state.identity}`, log);
|
260
|
+
if (!isEqual(this.state.attributes, updateAttributes)) {
|
269
261
|
this.state.attributes = updateAttributes;
|
270
262
|
updateReasons.push("attributes");
|
271
263
|
}
|
@@ -419,11 +411,22 @@ class User extends replayEventEmitter.ReplayEventEmitter {
|
|
419
411
|
}
|
420
412
|
}
|
421
413
|
}
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
414
|
+
__decorate([
|
415
|
+
validateTypesAsync(json),
|
416
|
+
__metadata("design:type", Function),
|
417
|
+
__metadata("design:paramtypes", [Object]),
|
418
|
+
__metadata("design:returntype", Promise)
|
419
|
+
], User.prototype, "updateAttributes", null);
|
420
|
+
__decorate([
|
421
|
+
validateTypesAsync(["string"]),
|
422
|
+
__metadata("design:type", Function),
|
423
|
+
__metadata("design:paramtypes", [String]),
|
424
|
+
__metadata("design:returntype", Promise)
|
425
|
+
], User.prototype, "updateFriendlyName", null);
|
426
|
+
|
427
|
+
export { User };
|
428
|
+
//# sourceMappingURL=user.js.map
|
429
|
+
__metadata("design:returntype", Promise)
|
427
430
|
], User.prototype, "updateAttributes", null);
|
428
431
|
tslib_es6.__decorate([
|
429
432
|
declarativeTypeValidator.validateTypesAsync(["string"]),
|
package/dist/user.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"user.js","sources":["../src/user.ts"],"sourcesContent":["import { Logger } from \"./logger\";\nimport { SyncClient } from \"twilio-sync\";\nimport { parseAttributes } from \"./util\";\nimport { validateTypesAsync } from \"@twilio/declarative-type-validator\";\nimport { json } from \"./interfaces/rules\";\nimport { Configuration } from \"./configuration\";\nimport { CommandExecutor } from \"./command-executor\";\nimport {\n EditUserRequest,\n EditUserResponse,\n} from \"./interfaces/commands/edit-user\";\nimport { ReplayEventEmitter } from \"@twilio/replay-event-emitter\";\nimport isEqual from \"lodash.isequal\";\nimport { JSONValue } from \"./types\";\n\ntype UserEvents = {\n updated: (data: { user: User; updateReasons: UserUpdateReason[] }) => void;\n userSubscribed: (user: User) => void;\n userUnsubscribed: (user: User) => void;\n};\n\nconst log = Logger.scope(\"User\");\n\ninterface UserState {\n identity: string;\n entityName: string;\n friendlyName: string | null;\n attributes: JSONValue;\n online: boolean | null;\n notifiable: boolean | null;\n}\n\ninterface UpdateValue {\n value: string;\n notifiable: boolean | null;\n online: boolean | null;\n}\n\ninterface UserServices {\n syncClient: SyncClient;\n commandExecutor: CommandExecutor;\n}\n\ninterface UserLinks {\n self: string;\n}\n\ntype SubscriptionState = \"initializing\" | \"subscribed\" | \"unsubscribed\";\n\n/**\n * The reason for the `updated` event being emitted by a user.\n */\ntype UserUpdateReason =\n | \"friendlyName\"\n | \"attributes\"\n | \"reachabilityOnline\"\n | \"reachabilityNotifiable\";\n\ninterface UserUpdatedEventArgs {\n user: User;\n updateReasons: UserUpdateReason[];\n}\n\n/**\n * Extended user information.\n * Note that `isOnline` and `isNotifiable` properties are eligible\n * for use only if the reachability function is enabled.\n * You may check if it is enabled by reading the value of {@link Client.reachabilityEnabled}.\n */\nclass User extends ReplayEventEmitter<UserEvents> {\n private links!: UserLinks;\n private configuration!: Configuration;\n private readonly services: UserServices;\n\n private entity;\n private state: UserState;\n private promiseToFetch: Promise<User> | null = null;\n private subscribed: SubscriptionState;\n\n private _initializationPromise: Promise<void>;\n private _resolveInitializationPromise;\n\n /**\n * @internal\n */\n constructor(\n identity: string,\n entityName: string,\n configuration: Configuration | null,\n services: UserServices\n ) {\n super();\n\n this.services = services;\n\n this.subscribed = \"initializing\";\n this.setMaxListeners(0);\n\n this.state = {\n identity,\n entityName,\n friendlyName: null,\n attributes: {},\n online: null,\n notifiable: null,\n };\n\n this._initializationPromise = new Promise((resolve) => {\n this._resolveInitializationPromise = resolve;\n });\n\n if (configuration !== null) {\n this._resolveInitialization(configuration, identity, entityName, false);\n }\n }\n\n /**\n * Fired when the properties or the reachability status of the message has been updated.\n *\n * Parameters:\n * 1. object `data` - info object provided with the event. It has the following properties:\n * * {@link User} `user` - the user in question\n * * {@link UserUpdateReason}[] `updateReasons` - array of reasons for the update\n * @event\n */\n public readonly updated = \"updated\";\n\n /**\n * Fired when the client has subscribed to the user.\n *\n * Parameters:\n * 1. {@link User} `user` - the user in question\n * @event\n */\n public readonly userSubscribed = \"userSubscribed\";\n\n /**\n * Fired when the client has unsubscribed from the user.\n *\n * Parameters:\n * 1. {@link User} `user` - the user in question\n * @event\n */\n public readonly userUnsubscribed = \"userUnsubscribed\";\n\n /**\n * User identity.\n */\n public get identity(): string {\n return this.state.identity;\n }\n\n public set identity(identity: string) {\n this.state.identity = identity;\n }\n\n public set entityName(name: string) {\n this.state.entityName = name;\n }\n\n /**\n * Custom attributes of the user.\n */\n public get attributes() {\n return this.state.attributes;\n }\n\n /**\n * Friendly name of the user, null if not set.\n */\n public get friendlyName(): string | null {\n return this.state.friendlyName;\n }\n\n /**\n * Status of the real-time conversation connection of the user.\n */\n public get isOnline(): boolean | null {\n return this.state.online;\n }\n\n /**\n * User push notification registration status.\n */\n public get isNotifiable(): boolean | null {\n return this.state.notifiable;\n }\n\n /**\n * True if this user is receiving real-time status updates.\n */\n public get isSubscribed(): boolean {\n return this.subscribed == \"subscribed\";\n }\n\n // Handles service updates\n async _update(\n key: string,\n value: { value: string; notifiable: boolean | null; online: boolean | null }\n ) {\n await this._initializationPromise;\n\n const updateReasons: UserUpdateReason[] = [];\n log.debug(\"User for\", this.state.identity, \"updated:\", key, value);\n switch (key) {\n case \"friendlyName\":\n if (this.state.friendlyName !== value.value) {\n updateReasons.push(\"friendlyName\");\n this.state.friendlyName = value.value;\n }\n break;\n case \"attributes\":\n const updateAttributes = parseAttributes(\n value.value,\n `Retrieved malformed attributes from the server for user: ${this.state.identity}`,\n log\n );\n if (!isEqual(this.state.attributes, updateAttributes)) {\n this.state.attributes = updateAttributes;\n updateReasons.push(\"attributes\");\n }\n break;\n case \"reachability\":\n if (this.state.online !== value.online) {\n this.state.online = value.online;\n updateReasons.push(\"reachabilityOnline\");\n }\n if (this.state.notifiable !== value.notifiable) {\n this.state.notifiable = value.notifiable;\n updateReasons.push(\"reachabilityNotifiable\");\n }\n break;\n default:\n return;\n }\n if (updateReasons.length > 0) {\n this.emit(\"updated\", { user: this, updateReasons: updateReasons });\n }\n }\n\n // Fetch reachability info\n private async _updateReachabilityInfo(map, update) {\n await this._initializationPromise;\n\n if (!this.configuration.reachabilityEnabled) {\n return Promise.resolve();\n }\n\n return map\n .get(\"reachability\")\n .then(update)\n .catch((err) => {\n log.warn(\n \"Failed to get reachability info for \",\n this.state.identity,\n err\n );\n });\n }\n\n // Fetch user\n async _fetch(): Promise<User> {\n await this._initializationPromise;\n\n if (!this.state.entityName) {\n return this;\n }\n\n this.promiseToFetch = this.services.syncClient\n .map({\n id: this.state.entityName,\n mode: \"open_existing\",\n includeItems: true,\n })\n .then((map) => {\n this.entity = map;\n map.on(\"itemUpdated\", (args) => {\n log.debug(\n this.state.entityName +\n \" (\" +\n this.state.identity +\n \") itemUpdated: \" +\n args.item.key\n );\n return this._update(args.item.key, args.item.data);\n });\n map.on(\"itemAdded\", (args) => {\n log.debug(\n this.state.entityName +\n \" (\" +\n this.state.identity +\n \") itemAdded: \" +\n args.item.key\n );\n return this._update(args.item.key, args.item.data);\n });\n return Promise.all([\n map\n .get(\"friendlyName\")\n .then((item) => this._update(item.key, item.data as UpdateValue)),\n map\n .get(\"attributes\")\n .then((item) => this._update(item.key, item.data as UpdateValue)),\n this._updateReachabilityInfo(map, (item) =>\n this._update(item.key, item.data)\n ),\n ]);\n })\n .then(() => {\n log.debug(\"Fetched for\", this.identity);\n this.subscribed = \"subscribed\";\n this.emit(\"userSubscribed\", this);\n return this;\n })\n .catch((err) => {\n this.promiseToFetch = null;\n throw err;\n });\n return this.promiseToFetch;\n }\n\n async _ensureFetched() {\n await this._initializationPromise;\n return this.promiseToFetch || this._fetch();\n }\n\n /**\n * Edit user attributes.\n * @param attributes New attributes.\n */\n @validateTypesAsync(json)\n public async updateAttributes(attributes: JSONValue): Promise<User> {\n await this._initializationPromise;\n\n if (this.subscribed == \"unsubscribed\") {\n throw new Error(\"Can't modify unsubscribed object\");\n }\n\n await this.services.commandExecutor.mutateResource<\n EditUserRequest,\n EditUserResponse\n >(\"post\", this.links.self, {\n attributes: JSON.stringify(attributes),\n });\n\n return this;\n }\n\n /**\n * Update the friendly name of the user.\n * @param friendlyName New friendly name.\n */\n @validateTypesAsync([\"string\"])\n public async updateFriendlyName(friendlyName: string): Promise<User> {\n await this._initializationPromise;\n\n if (this.subscribed == \"unsubscribed\") {\n throw new Error(\"Can't modify unsubscribed object\");\n }\n\n await this.services.commandExecutor.mutateResource<\n EditUserRequest,\n EditUserResponse\n >(\"post\", this.links.self, {\n friendly_name: friendlyName,\n });\n\n return this;\n }\n\n /**\n * Remove the user from the subscription list.\n * @return A promise of completion.\n */\n async unsubscribe(): Promise<void> {\n await this._initializationPromise;\n\n if (this.promiseToFetch) {\n await this.promiseToFetch;\n this.entity.close();\n this.promiseToFetch = null;\n this.subscribed = \"unsubscribed\";\n this.emit(\"userUnsubscribed\", this);\n }\n }\n\n public _resolveInitialization(\n configuration: Configuration,\n identity: string,\n entityName: string,\n emitUpdated: boolean\n ): void {\n this.configuration = configuration;\n this.identity = identity;\n this.entityName = entityName;\n this.links = {\n self: `${this.configuration.links.users}/${encodeURIComponent(\n this.identity\n )}`,\n };\n this._resolveInitializationPromise();\n\n if (emitUpdated) {\n this.emit(\"updated\", {\n user: this,\n updateReasons: [\n \"friendlyName\",\n \"attributes\",\n \"reachabilityOnline\",\n \"reachabilityNotifiable\",\n ],\n });\n }\n }\n}\n\nexport {\n User,\n UserServices,\n SubscriptionState,\n UserUpdateReason,\n UserUpdatedEventArgs,\n};\n"],"names":["Logger","ReplayEventEmitter","parseAttributes","isEqual","__decorate","validateTypesAsync","json"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBA,MAAM,GAAG,GAAGA,aAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;AA0CjC;;;;;AAKG;AACH,MAAM,IAAK,SAAQC,qCAA8B,CAAA;AAa/C;;AAEG;AACH,IAAA,WAAA,CACE,QAAgB,EAChB,UAAkB,EAClB,aAAmC,EACnC,QAAsB,EAAA;AAEtB,QAAA,KAAK,EAAE,CAAC;QAfF,IAAc,CAAA,cAAA,GAAyB,IAAI,CAAC;AAwCpD;;;;;;;;AAQG;QACa,IAAO,CAAA,OAAA,GAAG,SAAS,CAAC;AAEpC;;;;;;AAMG;QACa,IAAc,CAAA,cAAA,GAAG,gBAAgB,CAAC;AAElD;;;;;;AAMG;QACa,IAAgB,CAAA,gBAAA,GAAG,kBAAkB,CAAC;AAlDpD,QAAA,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;AAEzB,QAAA,IAAI,CAAC,UAAU,GAAG,cAAc,CAAC;AACjC,QAAA,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;QAExB,IAAI,CAAC,KAAK,GAAG;YACX,QAAQ;YACR,UAAU;AACV,YAAA,YAAY,EAAE,IAAI;AAClB,YAAA,UAAU,EAAE,EAAE;AACd,YAAA,MAAM,EAAE,IA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E;AACf,YAAA,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;AACnB,gBAAA,IAAI,EAAE,IAAI;AACV,gBAAA,aAAa,EAAE;oBACb,cAAc;oBACd,YAAY;oBACZ,oBAAoB;oBACpB,wBAAwB;AACzB,iBAAA;AACF,aAAA,CAAC,CAAC;AACJ,SAAA;KACF;AACF,CAAA;AAnFCC,oBAAA,CAAA;IADCC,2CAAkB,CAACC,UAAI,CAAC;;;;AAgBxB,CAAA,EAAA,IAAA,CAAA,SAAA,EAAA,kBAAA,EAAA,IAAA,CAAA,CAAA;AAODF,oBAAA,CAAA;AADC,IAAAC,2CAAkB,CAAC,CAAC,QAAQ,CAAC,CAAC;;;;AAgB9B,CAAA,EAAA,IAAA,CAAA,SAAA,EAAA,oBAAA,EAAA,IAAA,CAAA;;;;"}
|
1
|
+
{"version":3,"file":"user.js","sources":["../src/user.ts"],"sourcesContent":["import { Logger } from \"./logger\";\nimport { SyncClient } from \"twilio-sync\";\nimport { parseAttributes } from \"./util\";\nimport { validateTypesAsync } from \"@twilio/declarative-type-validator\";\nimport { json } from \"./interfaces/rules\";\nimport { Configuration } from \"./configuration\";\nimport { CommandExecutor } from \"./command-executor\";\nimport {\n EditUserRequest,\n EditUserResponse,\n} from \"./interfaces/commands/edit-user\";\nimport { ReplayEventEmitter } from \"@twilio/replay-event-emitter\";\nimport isEqual from \"lodash.isequal\";\nimport { JSONValue } from \"./types\";\n\ntype UserEvents = {\n updated: (data: { user: User; updateReasons: UserUpdateReason[] }) => void;\n userSubscribed: (user: User) => void;\n userUnsubscribed: (user: User) => void;\n};\n\nconst log = Logger.scope(\"User\");\n\ninterface UserState {\n identity: string;\n entityName: string;\n friendlyName: string | null;\n attributes: JSONValue;\n online: boolean | null;\n notifiable: boolean | null;\n}\n\ninterface UpdateValue {\n value: string;\n notifiable: boolean | null;\n online: boolean | null;\n}\n\ninterface UserServices {\n syncClient: SyncClient;\n commandExecutor: CommandExecutor;\n}\n\ninterface UserLinks {\n self: string;\n}\n\ntype SubscriptionState = \"initializing\" | \"subscribed\" | \"unsubscribed\";\n\n/**\n * The reason for the `updated` event being emitted by a user.\n */\ntype UserUpdateReason =\n | \"friendlyName\"\n | \"attributes\"\n | \"reachabilityOnline\"\n | \"reachabilityNotifiable\";\n\ninterface UserUpdatedEventArgs {\n user: User;\n updateReasons: UserUpdateReason[];\n}\n\n/**\n * Extended user information.\n * Note that `isOnline` and `isNotifiable` properties are eligible\n * for use only if the reachability function is enabled.\n * You may check if it is enabled by reading the value of {@link Client.reachabilityEnabled}.\n */\nclass User extends ReplayEventEmitter<UserEvents> {\n private links!: UserLinks;\n private configuration!: Configuration;\n private readonly services: UserServices;\n\n private entity;\n private state: UserState;\n private promiseToFetch: Promise<User> | null = null;\n private subscribed: SubscriptionState;\n\n private _initializationPromise: Promise<void>;\n private _resolveInitializationPromise;\n\n /**\n * @internal\n */\n constructor(\n identity: string,\n entityName: string,\n configuration: Configuration | null,\n services: UserServices\n ) {\n super();\n\n this.services = services;\n\n this.subscribed = \"initializing\";\n this.setMaxListeners(0);\n\n this.state = {\n identity,\n entityName,\n friendlyName: null,\n attributes: {},\n online: null,\n notifiable: null,\n };\n\n this._initializationPromise = new Promise((resolve) => {\n this._resolveInitializationPromise = resolve;\n });\n\n if (configuration !== null) {\n this._resolveInitialization(configuration, identity, entityName, false);\n }\n }\n\n /**\n * Fired when the properties or the reachability status of the message has been updated.\n *\n * Parameters:\n * 1. object `data` - info object provided with the event. It has the following properties:\n * * {@link User} `user` - the user in question\n * * {@link UserUpdateReason}[] `updateReasons` - array of reasons for the update\n * @event\n */\n public readonly updated = \"updated\";\n\n /**\n * Fired when the client has subscribed to the user.\n *\n * Parameters:\n * 1. {@link User} `user` - the user in question\n * @event\n */\n public readonly userSubscribed = \"userSubscribed\";\n\n /**\n * Fired when the client has unsubscribed from the user.\n *\n * Parameters:\n * 1. {@link User} `user` - the user in question\n * @event\n */\n public readonly userUnsubscribed = \"userUnsubscribed\";\n\n /**\n * User identity.\n */\n public get identity(): string {\n return this.state.identity;\n }\n\n public set identity(identity: string) {\n this.state.identity = identity;\n }\n\n public set entityName(name: string) {\n this.state.entityName = name;\n }\n\n /**\n * Custom attributes of the user.\n */\n public get attributes() {\n return this.state.attributes;\n }\n\n /**\n * Friendly name of the user, null if not set.\n */\n public get friendlyName(): string | null {\n return this.state.friendlyName;\n }\n\n /**\n * Status of the real-time conversation connection of the user.\n */\n public get isOnline(): boolean | null {\n return this.state.online;\n }\n\n /**\n * User push notification registration status.\n */\n public get isNotifiable(): boolean | null {\n return this.state.notifiable;\n }\n\n /**\n * True if this user is receiving real-time status updates.\n */\n public get isSubscribed(): boolean {\n return this.subscribed == \"subscribed\";\n }\n\n // Handles service updates\n async _update(\n key: string,\n value: { value: string; notifiable: boolean | null; online: boolean | null }\n ) {\n await this._initializationPromise;\n\n const updateReasons: UserUpdateReason[] = [];\n log.debug(\"User for\", this.state.identity, \"updated:\", key, value);\n switch (key) {\n case \"friendlyName\":\n if (this.state.friendlyName !== value.value) {\n updateReasons.push(\"friendlyName\");\n this.state.friendlyName = value.value;\n }\n break;\n case \"attributes\":\n const updateAttributes = parseAttributes(\n value.value,\n `Retrieved malformed attributes from the server for user: ${this.state.identity}`,\n log\n );\n if (!isEqual(this.state.attributes, updateAttributes)) {\n this.state.attributes = updateAttributes;\n updateReasons.push(\"attributes\");\n }\n break;\n case \"reachability\":\n if (this.state.online !== value.online) {\n this.state.online = value.online;\n updateReasons.push(\"reachabilityOnline\");\n }\n if (this.state.notifiable !== value.notifiable) {\n this.state.notifiable = value.notifiable;\n updateReasons.push(\"reachabilityNotifiable\");\n }\n break;\n default:\n return;\n }\n if (updateReasons.length > 0) {\n this.emit(\"updated\", { user: this, updateReasons: updateReasons });\n }\n }\n\n // Fetch reachability info\n private async _updateReachabilityInfo(map, update) {\n await this._initializationPromise;\n\n if (!this.configuration.reachabilityEnabled) {\n return Promise.resolve();\n }\n\n return map\n .get(\"reachability\")\n .then(update)\n .catch((err) => {\n log.warn(\n \"Failed to get reachability info for \",\n this.state.identity,\n err\n );\n });\n }\n\n // Fetch user\n async _fetch(): Promise<User> {\n await this._initializationPromise;\n\n if (!this.state.entityName) {\n return this;\n }\n\n this.promiseToFetch = this.services.syncClient\n .map({\n id: this.state.entityName,\n mode: \"open_existing\",\n includeItems: true,\n })\n .then((map) => {\n this.entity = map;\n map.on(\"itemUpdated\", (args) => {\n log.debug(\n this.state.entityName +\n \" (\" +\n this.state.identity +\n \") itemUpdated: \" +\n args.item.key\n );\n return this._update(args.item.key, args.item.data);\n });\n map.on(\"itemAdded\", (args) => {\n log.debug(\n this.state.entityName +\n \" (\" +\n this.state.identity +\n \") itemAdded: \" +\n args.item.key\n );\n return this._update(args.item.key, args.item.data);\n });\n return Promise.all([\n map\n .get(\"friendlyName\")\n .then((item) => this._update(item.key, item.data as UpdateValue)),\n map\n .get(\"attributes\")\n .then((item) => this._update(item.key, item.data as UpdateValue)),\n this._updateReachabilityInfo(map, (item) =>\n this._update(item.key, item.data)\n ),\n ]);\n })\n .then(() => {\n log.debug(\"Fetched for\", this.identity);\n this.subscribed = \"subscribed\";\n this.emit(\"userSubscribed\", this);\n return this;\n })\n .catch((err) => {\n this.promiseToFetch = null;\n throw err;\n });\n return this.promiseToFetch;\n }\n\n async _ensureFetched() {\n await this._initializationPromise;\n return this.promiseToFetch || this._fetch();\n }\n\n /**\n * Edit user attributes.\n * @param attributes New attributes.\n */\n @validateTypesAsync(json)\n public async updateAttributes(attributes: JSONValue): Promise<User> {\n await this._initializationPromise;\n\n if (this.subscribed == \"unsubscribed\") {\n throw new Error(\"Can't modify unsubscribed object\");\n }\n\n await this.services.commandExecutor.mutateResource<\n EditUserRequest,\n EditUserResponse\n >(\"post\", this.links.self, {\n attributes: JSON.stringify(attributes),\n });\n\n return this;\n }\n\n /**\n * Update the friendly name of the user.\n * @param friendlyName New friendly name.\n */\n @validateTypesAsync([\"string\"])\n public async updateFriendlyName(friendlyName: string): Promise<User> {\n await this._initializationPromise;\n\n if (this.subscribed == \"unsubscribed\") {\n throw new Error(\"Can't modify unsubscribed object\");\n }\n\n await this.services.commandExecutor.mutateResource<\n EditUserRequest,\n EditUserResponse\n >(\"post\", this.links.self, {\n friendly_name: friendlyName,\n });\n\n return this;\n }\n\n /**\n * Remove the user from the subscription list.\n * @return A promise of completion.\n */\n async unsubscribe(): Promise<void> {\n await this._initializationPromise;\n\n if (this.promiseToFetch) {\n await this.promiseToFetch;\n this.entity.close();\n this.promiseToFetch = null;\n this.subscribed = \"unsubscribed\";\n this.emit(\"userUnsubscribed\", this);\n }\n }\n\n public _resolveInitialization(\n configuration: Configuration,\n identity: string,\n entityName: string,\n emitUpdated: boolean\n ): void {\n this.configuration = configuration;\n this.identity = identity;\n this.entityName = entityName;\n this.links = {\n self: `${this.configuration.links.users}/${encodeURIComponent(\n this.identity\n )}`,\n };\n this._resolveInitializationPromise();\n\n if (emitUpdated) {\n this.emit(\"updated\", {\n user: this,\n updateReasons: [\n \"friendlyName\",\n \"attributes\",\n \"reachabilityOnline\",\n \"reachabilityNotifiable\",\n ],\n });\n }\n }\n}\n\nexport {\n User,\n UserServices,\n SubscriptionState,\n UserUpdateReason,\n UserUpdatedEventArgs,\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBA,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;AA0CjC;;;;;AAKG;AACH,MAAM,IAAK,SAAQ,kBAA8B,CAAA;AAa/C;;AAEG;AACH,IAAA,WAAA,CACE,QAAgB,EAChB,UAAkB,EAClB,aAAmC,EACnC,QAAsB,EAAA;AAEtB,QAAA,KAAK,EAAE,CAAC;QAfF,IAAc,CAAA,cAAA,GAAyB,IAAI,CAAC;AAwC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A,sBAAsB,CAC3B,aAA4B,EAC5B,QAAgB,EAChB,UAAkB,EAClB,WAAoB,EAAA;AAEpB,QAAA,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;AACnC,QAAA,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;AACzB,QAAA,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,KAAK,GAAG;AACX,YAAA,IAAI,EAAE,CAAG,EAAA,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,KAAK,CAAA,CAAA,EAAI,kBAAkB,CAC3D,IAAI,CAAC,QAAQ,CACd,CAAE,CAAA;SACJ,CAAC;QACF,IAAI,CAAC,6BAA6B,EAAE,CAAC;AAErC,QAAA,IAAI,WAAW,EAAE;AACf,YAAA,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;AACnB,gBAAA,IAAI,EAAE,IAAI;AACV,gBAAA,aAAa,EAAE;oBACb,cAAc;oBACd,YAAY;oBACZ,oBAAoB;oBACpB,wBAAwB;AACzB,iBAAA;AACF,aAAA,CAAC,CAAC;AACJ,SAAA;KACF;AACF,CAAA;AAnFC,UAAA,CAAA;IADC,kBAAkB,CAAC,IAAI,CAAC;;;;AAgBxB,CAAA,EAAA,IAAA,CAAA,SAAA,EAAA,kBAAA,EAAA,IAAA,CAAA,CAAA;AAOD,UAAA,CAAA;AADC,IAAA,kBAAkB,CAAC,CAAC,QAAQ,CAAC,CAAC;;;;AAgB9B,CAAA,EAAA,IAAA,CAAA,SAAA,EAAA,oBAAA,EAAA,IAAA,CAAA;;;;"}BAAA,CAAA;AADC,IAAAC,2CAAkB,CAAC,CAAC,QAAQ,CAAC,CAAC;;;;AAgB9B,CAAA,EAAA,IAAA,CAAA,SAAA,EAAA,oBAAA,EAAA,IAAA,CAAA;;;;"}
|
package/dist/util/deferred.js
CHANGED
@@ -126,8 +126,6 @@ This software includes platform.js under the following license.
|
|
126
126
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
127
127
|
|
128
128
|
*/
|
129
|
-
'use strict';
|
130
|
-
|
131
129
|
var global =
|
132
130
|
typeof global !== "undefined"
|
133
131
|
? global
|
@@ -137,8 +135,6 @@ var global =
|
|
137
135
|
? window
|
138
136
|
: {};
|
139
137
|
|
140
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
141
|
-
|
142
138
|
class Deferred {
|
143
139
|
constructor() {
|
144
140
|
this._promise = new Promise((resolve, reject) => {
|
@@ -161,5 +157,11 @@ class Deferred {
|
|
161
157
|
}
|
162
158
|
}
|
163
159
|
|
160
|
+
export { Deferred };
|
161
|
+
//# sourceMappingURL=deferred.js.map
|
162
|
+
_reject(e);
|
163
|
+
}
|
164
|
+
}
|
165
|
+
|
164
166
|
exports.Deferred = Deferred;
|
165
167
|
//# sourceMappingURL=deferred.js.map
|