@twilio/conversations 3.0.0-rc.9 → 3.0.1-rc.102

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.
Files changed (88) hide show
  1. package/README.md +38 -28
  2. package/builds/browser.js +1659 -264
  3. package/builds/browser.js.map +1 -1
  4. package/builds/lib.d.ts +650 -25
  5. package/builds/lib.js +1650 -264
  6. package/builds/lib.js.map +1 -1
  7. package/builds/twilio-conversations.js +4300 -1842
  8. package/builds/twilio-conversations.min.js +1 -1
  9. package/dist/aggregated-delivery-receipt.js +10 -1
  10. package/dist/aggregated-delivery-receipt.js.map +1 -1
  11. package/dist/channel-metadata-client.js +192 -0
  12. package/dist/channel-metadata-client.js.map +1 -0
  13. package/dist/client.js +70 -10
  14. package/dist/client.js.map +1 -1
  15. package/dist/command-executor.js +48 -6
  16. package/dist/command-executor.js.map +1 -1
  17. package/dist/configuration.js +14 -3
  18. package/dist/configuration.js.map +1 -1
  19. package/dist/content-client.js +184 -0
  20. package/dist/content-client.js.map +1 -0
  21. package/dist/content-template.js +310 -0
  22. package/dist/content-template.js.map +1 -0
  23. package/dist/conversation.js +59 -16
  24. package/dist/conversation.js.map +1 -1
  25. package/dist/data/conversations.js +25 -3
  26. package/dist/data/conversations.js.map +1 -1
  27. package/dist/data/messages.js +23 -6
  28. package/dist/data/messages.js.map +1 -1
  29. package/dist/data/participants.js +17 -8
  30. package/dist/data/participants.js.map +1 -1
  31. package/dist/data/users.js +9 -0
  32. package/dist/data/users.js.map +1 -1
  33. package/dist/detailed-delivery-receipt.js +9 -0
  34. package/dist/detailed-delivery-receipt.js.map +1 -1
  35. package/dist/index.js +14 -0
  36. package/dist/index.js.map +1 -1
  37. package/dist/interfaces/notification-types.js +9 -0
  38. package/dist/interfaces/notification-types.js.map +1 -1
  39. package/dist/interfaces/{attributes.js → rules.js} +26 -7
  40. package/dist/interfaces/rules.js.map +1 -0
  41. package/dist/logger.js +9 -0
  42. package/dist/logger.js.map +1 -1
  43. package/dist/media.js +9 -0
  44. package/dist/media.js.map +1 -1
  45. package/dist/message-builder.js +77 -6
  46. package/dist/message-builder.js.map +1 -1
  47. package/dist/message.js +156 -12
  48. package/dist/message.js.map +1 -1
  49. package/dist/node_modules/quick-lru/index.js +265 -0
  50. package/dist/node_modules/quick-lru/index.js.map +1 -0
  51. package/dist/node_modules/tslib/tslib.es6.js +9 -0
  52. package/dist/node_modules/tslib/tslib.es6.js.map +1 -1
  53. package/dist/packages/conversations/package.json.js +10 -1
  54. package/dist/packages/conversations/package.json.js.map +1 -1
  55. package/dist/participant.js +11 -2
  56. package/dist/participant.js.map +1 -1
  57. package/dist/push-notification.js +9 -0
  58. package/dist/push-notification.js.map +1 -1
  59. package/dist/rest-paginator.js +9 -0
  60. package/dist/rest-paginator.js.map +1 -1
  61. package/dist/services/network.js +9 -0
  62. package/dist/services/network.js.map +1 -1
  63. package/dist/services/typing-indicator.js +9 -0
  64. package/dist/services/typing-indicator.js.map +1 -1
  65. package/dist/unsent-message.js +9 -0
  66. package/dist/unsent-message.js.map +1 -1
  67. package/dist/user.js +20 -3
  68. package/dist/user.js.map +1 -1
  69. package/dist/util/deferred.js +9 -0
  70. package/dist/util/deferred.js.map +1 -1
  71. package/dist/util/index.js +9 -0
  72. package/dist/util/index.js.map +1 -1
  73. package/docs/assets/js/search.js +1 -1
  74. package/docs/classes/AggregatedDeliveryReceipt.html +1 -1
  75. package/docs/classes/ChannelMetadata.html +3050 -0
  76. package/docs/classes/Client.html +64 -25
  77. package/docs/classes/ContentTemplate.html +3116 -0
  78. package/docs/classes/ContentTemplateVariable.html +3116 -0
  79. package/docs/classes/Conversation.html +14 -9
  80. package/docs/classes/Message.html +76 -5
  81. package/docs/classes/MessageBuilder.html +41 -0
  82. package/docs/classes/Participant.html +2 -2
  83. package/docs/index.html +849 -25
  84. package/docs/interfaces/ClientOptions.html +16 -0
  85. package/docs/modules.html +848 -24
  86. package/package.json +18 -14
  87. package/CHANGELOG.md +0 -509
  88. package/dist/interfaces/attributes.js.map +0 -1
@@ -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 { attributesValidator } from \"./interfaces/attributes\";\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 * Type of a participant.\n */\ntype ParticipantType = \"chat\" | \"sms\" | \"whatsapp\" | \"email\";\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(\"typingStarted\", this);\n\n this.conversation.emit(\"typingStarted\", this);\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(\"typingEnded\", this);\n\n this.conversation.emit(\"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(\"updated\", { participant: this, updateReasons: updateReasons });\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(attributesValidator)\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","isEqual","__decorate","validateTypesAsync","attributesValidator"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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EhD;;;;;;AAMG;AACa,WAAW,CAAA,WAAA,GAAG,aAAa,CAAC;AAE5C;;;;;;;;AAQG;AACa,WAAO,CAAA,OAAA,GAAG,SAAS,CAAC;AAgJpCC,oBAAA,CAAA;IADCC,2CAAkB,CAACC,8BAAmB,CAAC;;;;AAUvC,CAAA,EAAA,WAAA,CAAA,SAAA,EAAA,kBAAA,EAAA,IAAA,CAAA;;;;"}
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(\"typingStarted\", this);\n\n this.conversation.emit(\"typingStarted\", this);\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(\"typingEnded\", this);\n\n this.conversation.emit(\"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(\"updated\", { participant: this, updateReasons: updateReasons });\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","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;AAER,QAAA,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;AACjC,QAAA,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;AACnB,QAAA,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,KAAK,GAAG;AACX,YAAA,UAAU,EAAEC,qBAAe,CACzB,IAAI,CAAC,UAAU,EACf,kEAAkE;gBAChE,GAAG,EACL,GAAG,CACJ;AACD,YAAA,WAAW,EAAE,IAAI,CAAC,WAAW,GAAGC,eAAS,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,IAAI;AAClE,YAAA,WAAW,EAAE,IAAI,CAAC,WAAW,GAAGA,eAAS,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,IAAI;AAClE,YAAA,GAAG,EAAE,GAAG;AACR,YAAA,aAAa,EAAE,IAAI;AACnB,YAAA,QAAQ,EAAE,KAAK;YACf,QAAQ,EAAE,IAAI,CAAC,QAAQ;AACvB,YAAA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AC,cAAc,CAGhD,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE;AACzB,YAAA,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC;AACvC,SAAA,CAAC,CAAC;AAEH,QAAA,OAAO,IAAI,CAAC;KACb;;AApLD;;;;;;AAMG;AACa,WAAa,CAAA,aAAA,GAAG,eAAe,CAAC;AAEhD;;;;;;AAMG;AACa,WAAW,CAAA,WAAA,GAAG,aAAa,CAAC;AAE5C;;;;;;;;AAQG;AACa,WAAO,CAAA,OAAA,GAAG,SAAS,CAAC;AAgJpCC,oBAAA,CAAA;IADCC,2CAAkB,CAACC,UAAI,CAAC;;;;AAUxB,CAAA,EAAA,WAAA,CAAA,SAAA,EAAA,kBAAA,EAAA,IAAA,CAAA;;;;"}
@@ -128,6 +128,15 @@ This software includes platform.js under the following license.
128
128
  */
129
129
  'use strict';
130
130
 
131
+ var global =
132
+ typeof global !== "undefined"
133
+ ? global
134
+ : typeof self !== "undefined"
135
+ ? self
136
+ : typeof window !== "undefined"
137
+ ? window
138
+ : {};
139
+
131
140
  Object.defineProperty(exports, '__esModule', { value: true });
132
141
 
133
142
  /**
@@ -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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;"}
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;;;;"}
@@ -128,6 +128,15 @@ This software includes platform.js under the following license.
128
128
  */
129
129
  'use strict';
130
130
 
131
+ var global =
132
+ typeof global !== "undefined"
133
+ ? global
134
+ : typeof self !== "undefined"
135
+ ? self
136
+ : typeof window !== "undefined"
137
+ ? window
138
+ : {};
139
+
131
140
  Object.defineProperty(exports, '__esModule', { value: true });
132
141
 
133
142
  /**
@@ -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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;"}
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;;;;"}
@@ -128,6 +128,15 @@ This software includes platform.js under the following license.
128
128
  */
129
129
  'use strict';
130
130
 
131
+ var global =
132
+ typeof global !== "undefined"
133
+ ? global
134
+ : typeof self !== "undefined"
135
+ ? self
136
+ : typeof window !== "undefined"
137
+ ? window
138
+ : {};
139
+
131
140
  Object.defineProperty(exports, '__esModule', { value: true });
132
141
 
133
142
  var operationRetrier = require('@twilio/operation-retrier');
@@ -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":["Retrier"],"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,Y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AED,MAAM,OAAO,GAAG,EAAE,CAAC;AACnB,QAAA,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAC1C,MACE,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,GAAG,CACzB,GAAG,EACH,OAAO,EACP,IAAI,CAAC,aAAa,CAAC,SAAS,CAC7B,EACH,IAAI,CAAC,aAAa,CAAC,kBAAkB,CACtC,CAAC;AACF,QAAA,IAAI,CAAC,KAAK,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;;;;"}
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":["Retrier"],"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,K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C;QACvC,IAAI,UAAU,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE;YACvD,OAAO,UAAU,CAAC,QAA8B,CAAC;AAClD,SAAA;QAED,MAAM,OAAO,GAAG,EAAE,CAAC;AACnB,QAAA,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAC1C,MACE,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,GAAG,CACzB,GAAG,EACH,OAAO,EACP,IAAI,CAAC,aAAa,CAAC,SAAS,CAC7B,EACH,IAAI,CAAC,aAAa,CAAC,kBAAkB,CACtC,CAAC;AACF,QAAA,IAAI,CAAC,KAAK,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;;;;"}
@@ -128,6 +128,15 @@ This software includes platform.js under the following license.
128
128
  */
129
129
  'use strict';
130
130
 
131
+ var global =
132
+ typeof global !== "undefined"
133
+ ? global
134
+ : typeof self !== "undefined"
135
+ ? self
136
+ : typeof window !== "undefined"
137
+ ? window
138
+ : {};
139
+
131
140
  Object.defineProperty(exports, '__esModule', { value: true });
132
141
 
133
142
  var logger = require('../logger.js');
@@ -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":["Logger","NotificationTypes"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA,MAAM,GAAG,GAAGA,aAAM,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;AAO5C;;;;;;;;;AASG;AAEH;;;;;AAKG;AACH,MAAM,eAAe,CAAA;AAQnB,IAAA,WAAA,CACE,eAAmE,EACnE,MAAqB,EACrB,QAAiC,EAAA;AAEjC,QAAA,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC;AAC5B,QAAA,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;AACzB,QAAA,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;AAEvC,QAAA,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC;AAC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AG,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;;;;"}
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"],"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A;AACnC,QAAA,GAAG,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAC;QAEtC,MAAM,GAAG,GAAG,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,MAAM,CAAC;AAC5C,QAAA,MAAM,OAAO,GAAG;AACd,YAAA,cAAc,EAAE,mCAAmC;SACpD,CAAC;AACF,QAAA,MAAM,IAAI,GAAG,CAAc,WAAA,EAAA,eAAe,EAAE,CAAC;AAE7C,QAAA,OAAO,IAAI,CAAC,QAAQ,CAAC,cAAc;AAChC,aAAA,IAAI,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;;;;"}
@@ -128,6 +128,15 @@ This software includes platform.js under the following license.
128
128
  */
129
129
  'use strict';
130
130
 
131
+ var global =
132
+ typeof global !== "undefined"
133
+ ? global
134
+ : typeof self !== "undefined"
135
+ ? self
136
+ : typeof window !== "undefined"
137
+ ? window
138
+ : {};
139
+
131
140
  Object.defineProperty(exports, '__esModule', { value: true });
132
141
 
133
142
  var mcsClient = require('@twilio/mcs-client');
@@ -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\";\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\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":["CancellablePromise","parseToNumber"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA;;AAEG;AACH,MAAM,aAAa,CAAA;AAMjB;;AAEG;AACH,IAAA,WAAA,CAAoB,cAAwB,EAAA;QAAxB,IAAc,CAAA,cAAA,GAAd,cAAc,CAAU;QAPrC,IAAU,CAAA,UAAA,GAAc,EAAE,CAAC;QAC3B,IAAY,CAAA,YAAA,GAAmD,EAAE,CAAC;QAClE,IAAY,CAAA,YAAA,GAAqB,EAAE,CAAC;KAKK;AAEhD;;;AAGG;IACH,IAAI,GAAA;QACF,OAAO,IAAIA,4BAAkB,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,CAACC,mBAAa,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;;;;"}
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":["CancellablePromise","parseToNumber"],"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,IAAIA,4BAAkB,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,CAACC,mBAAa,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;;;;"}
package/dist/user.js CHANGED
@@ -128,13 +128,22 @@ This software includes platform.js under the following license.
128
128
  */
129
129
  'use strict';
130
130
 
131
+ var global =
132
+ typeof global !== "undefined"
133
+ ? global
134
+ : typeof self !== "undefined"
135
+ ? self
136
+ : typeof window !== "undefined"
137
+ ? window
138
+ : {};
139
+
131
140
  Object.defineProperty(exports, '__esModule', { value: true });
132
141
 
133
142
  var tslib_es6 = require('./node_modules/tslib/tslib.es6.js');
134
143
  var logger = require('./logger.js');
135
144
  var index = require('./util/index.js');
136
145
  var declarativeTypeValidator = require('@twilio/declarative-type-validator');
137
- var attributes = require('./interfaces/attributes.js');
146
+ var rules = require('./interfaces/rules.js');
138
147
  var replayEventEmitter = require('@twilio/replay-event-emitter');
139
148
  var isEqual = require('lodash.isequal');
140
149
 
@@ -313,6 +322,14 @@ class User extends replayEventEmitter.ReplayEventEmitter {
313
322
  args.item.key);
314
323
  return this._update(args.item.key, args.item.data);
315
324
  });
325
+ map.on("itemAdded", (args) => {
326
+ log.debug(this.state.entityName +
327
+ " (" +
328
+ this.state.identity +
329
+ ") itemAdded: " +
330
+ args.item.key);
331
+ return this._update(args.item.key, args.item.data);
332
+ });
316
333
  return Promise.all([
317
334
  map
318
335
  .get("friendlyName")
@@ -386,7 +403,7 @@ class User extends replayEventEmitter.ReplayEventEmitter {
386
403
  this.identity = identity;
387
404
  this.entityName = entityName;
388
405
  this.links = {
389
- self: `${this.configuration.links.users}/${this.identity}`,
406
+ self: `${this.configuration.links.users}/${encodeURIComponent(this.identity)}`,
390
407
  };
391
408
  this._resolveInitializationPromise();
392
409
  if (emitUpdated) {
@@ -403,7 +420,7 @@ class User extends replayEventEmitter.ReplayEventEmitter {
403
420
  }
404
421
  }
405
422
  tslib_es6.__decorate([
406
- declarativeTypeValidator.validateTypesAsync(attributes.attributesValidator),
423
+ declarativeTypeValidator.validateTypesAsync(rules.json),
407
424
  tslib_es6.__metadata("design:type", Function),
408
425
  tslib_es6.__metadata("design:paramtypes", [Object]),
409
426
  tslib_es6.__metadata("design:returntype", Promise)
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 { attributesValidator } from \"./interfaces/attributes\";\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 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(attributesValidator)\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}/${this.identity}`,\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","attributesValidator"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBA,MAAM,GAAG,GAAGA,aAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;AA0CjC;;;;;AAKG;AACH,MAAM,IAAK,SAAQC,qCAA8B,CAAA;A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;QAC7B,IAAI,CAAC,KAAK,GAAG;AACX,YAAA,IAAI,EAAE,CAAA,EAAG,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,KAAK,CAAA,CAAA,EAAI,IAAI,CAAC,QAAQ,CAAE,CAAA;SAC3D,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;AAjFCC,oBAAA,CAAA;IADCC,2CAAkB,CAACC,8BAAmB,CAAC;;;;AAgBvC,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":["Logger","ReplayEventEmitter","parseAttributes","isEqual","__decorate","validateTypesAsync","json"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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A,CAAA,SAAA,EAAA,oBAAA,EAAA,IAAA,CAAA;;;;"}
@@ -128,6 +128,15 @@ This software includes platform.js under the following license.
128
128
  */
129
129
  'use strict';
130
130
 
131
+ var global =
132
+ typeof global !== "undefined"
133
+ ? global
134
+ : typeof self !== "undefined"
135
+ ? self
136
+ : typeof window !== "undefined"
137
+ ? window
138
+ : {};
139
+
131
140
  Object.defineProperty(exports, '__esModule', { value: true });
132
141
 
133
142
  class Deferred {
@@ -1 +1 @@
1
- {"version":3,"file":"deferred.js","sources":["../../src/util/deferred.ts"],"sourcesContent":["class Deferred<T> {\n private _promise: Promise<T>;\n private _resolve;\n private _reject;\n\n public current!: T;\n\n constructor() {\n this._promise = new Promise<T>((resolve, reject) => {\n this._resolve = resolve;\n this._reject = reject;\n });\n }\n\n public get promise(): Promise<T> {\n return this._promise;\n }\n\n update(value: T) {\n this._resolve(value);\n }\n\n set(value: T) {\n this.current = value;\n this._resolve(value);\n }\n\n fail(e) {\n this._reject(e);\n }\n}\n\nexport { Deferred };\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,MAAM,QAAQ,CAAA;AAOZ,IAAA,WAAA,GAAA;QACE,IAAI,CAAC,QAAQ,GAAG,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,KAAI;AACjD,YAAA,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;AACxB,YAAA,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;AACxB,SAAC,CAAC,CAAC;KACJ;AAED,IAAA,IAAW,OAAO,GAAA;QAChB,OAAO,IAAI,CAAC,QAAQ,CAAC;KACtB;AAED,IAAA,MAAM,CAAC,KAAQ,EAAA;AACb,QAAA,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;KACtB;AAED,IAAA,GAAG,CAAC,KAAQ,EAAA;AACV,QAAA,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;AACrB,QAAA,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;KACtB;AAED,IAAA,IAAI,CAAC,CAAC,EAAA;AACJ,QAAA,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;KACjB;AACF;;;;"}
1
+ {"version":3,"file":"deferred.js","sources":["../../src/util/deferred.ts"],"sourcesContent":["class Deferred<T> {\n private _promise: Promise<T>;\n private _resolve;\n private _reject;\n\n public current!: T;\n\n constructor() {\n this._promise = new Promise<T>((resolve, reject) => {\n this._resolve = resolve;\n this._reject = reject;\n });\n }\n\n public get promise(): Promise<T> {\n return this._promise;\n }\n\n update(value: T) {\n this._resolve(value);\n }\n\n set(value: T) {\n this.current = value;\n this._resolve(value);\n }\n\n fail(e) {\n this._reject(e);\n }\n}\n\nexport { Deferred };\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,MAAM,QAAQ,CAAA;AAOZ,IAAA,WAAA,GAAA;QACE,IAAI,CAAC,QAAQ,GAAG,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,KAAI;AACjD,YAAA,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;AACxB,YAAA,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;AACxB,SAAC,CAAC,CAAC;KACJ;AAED,IAAA,IAAW,OAAO,GAAA;QAChB,OAAO,IAAI,CAAC,QAAQ,CAAC;KACtB;AAED,IAAA,MAAM,CAAC,KAAQ,EAAA;AACb,QAAA,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;KACtB;AAED,IAAA,GAAG,CAAC,KAAQ,EAAA;AACV,QAAA,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;AACrB,QAAA,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;KACtB;AAED,IAAA,IAAI,CAAC,CAAC,EAAA;AACJ,QAAA,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;KACjB;AACF;;;;"}
@@ -128,6 +128,15 @@ This software includes platform.js under the following license.
128
128
  */
129
129
  'use strict';
130
130
 
131
+ var global =
132
+ typeof global !== "undefined"
133
+ ? global
134
+ : typeof self !== "undefined"
135
+ ? self
136
+ : typeof window !== "undefined"
137
+ ? window
138
+ : {};
139
+
131
140
  Object.defineProperty(exports, '__esModule', { value: true });
132
141
 
133
142
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/util/index.ts"],"sourcesContent":["import { Logger } from \"../logger\";\nimport { JSONValue } from \"../types\";\n\n/**\n * Deep-clone an object. Note that this does not work on object containing\n * functions.\n * @param {object} obj - the object to deep-clone\n * @returns {object}\n */\nfunction deepClone<T>(obj: T): T {\n return JSON.parse(JSON.stringify(obj)) as T;\n}\n\nfunction parseToNumber(value) {\n if (typeof value !== \"undefined\" && !isNaN(Number(value))) {\n return Number(value);\n }\n return null;\n}\n\n// timeString cannot be typed `string` because in member.ts\n// call to parseTime(data.lastReadTimestamp) uses number not a string for timestamp.\nfunction parseTime(timeString): Date | null {\n try {\n return new Date(timeString);\n } catch (e) {\n return null;\n }\n}\n\nfunction parseAttributes(\n rawAttributes,\n warningMessage: string,\n log: Logger\n): JSONValue {\n let attributes = {};\n if (rawAttributes) {\n try {\n attributes = JSON.parse(rawAttributes);\n } catch (e) {\n log.warn(warningMessage, e);\n }\n }\n\n return attributes;\n}\n\n/**\n * Construct URI with query parameters\n */\nclass UriBuilder {\n private base: string;\n private args: string[];\n private paths: string[];\n\n constructor(base: string) {\n this.base = base.replace(/\\/$/, \"\");\n this.args = [];\n this.paths = [];\n }\n\n public arg(name: string, value: string | number | boolean): UriBuilder {\n if (typeof value !== \"undefined\") {\n this.args.push(\n encodeURIComponent(name) + \"=\" + encodeURIComponent(value)\n );\n }\n return this;\n }\n\n public path(name: string): UriBuilder {\n this.paths.push(encodeURIComponent(name));\n return this;\n }\n\n public build(): string {\n let result = this.base;\n if (this.paths.length) {\n result += \"/\" + this.paths.join(\"/\");\n }\n\n if (this.args.length) {\n result += \"?\" + this.args.join(\"&\");\n }\n return result;\n }\n}\n\nexport { deepClone, UriBuilder, parseToNumber, parseTime, parseAttributes };\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA;;;;;AAKG;AACH,SAAS,SAAS,CAAI,GAAM,EAAA;IAC1B,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAM,CAAC;AAC9C,CAAC;AAED,SAAS,aAAa,CAAC,KAAK,EAAA;AAC1B,IAAA,IAAI,OAAO,KAAK,KAAK,WAAW,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE;AACzD,QAAA,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACtB,KAAA;AACD,IAAA,OAAO,IAAI,CAAC;AACd,CAAC;AAED;AACA;AACA,SAAS,SAAS,CAAC,UAAU,EAAA;IAC3B,IAAI;AACF,QAAA,OAAO,IAAI,IAAI,CAAC,UAAU,CAAC,CAAC;AAC7B,KAAA;AAAC,IAAA,OAAO,CAAC,EAAE;AACV,QAAA,OAAO,IAAI,CAAC;AACb,KAAA;AACH,CAAC;AAED,SAAS,eAAe,CACtB,aAAa,EACb,cAAsB,EACtB,GAAW,EAAA;IAEX,IAAI,UAAU,GAAG,EAAE,CAAC;AACpB,IAAA,IAAI,aAAa,EAAE;QACjB,IAAI;AACF,YAAA,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IAAI,CAAC,GAAG,CAAC,CAAC;AACrC,SAAA;AACD,QAAA,OAAO,MAAM,CAAC;KACf;AACF;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/util/index.ts"],"sourcesContent":["import { Logger } from \"../logger\";\nimport { JSONValue } from \"../types\";\n\n/**\n * Deep-clone an object. Note that this does not work on object containing\n * functions.\n * @param {object} obj - the object to deep-clone\n * @returns {object}\n */\nfunction deepClone<T>(obj: T): T {\n return JSON.parse(JSON.stringify(obj)) as T;\n}\n\nfunction parseToNumber(value) {\n if (typeof value !== \"undefined\" && !isNaN(Number(value))) {\n return Number(value);\n }\n return null;\n}\n\n// timeString cannot be typed `string` because in member.ts\n// call to parseTime(data.lastReadTimestamp) uses number not a string for timestamp.\nfunction parseTime(timeString): Date | null {\n try {\n return new Date(timeString);\n } catch (e) {\n return null;\n }\n}\n\nfunction parseAttributes(\n rawAttributes,\n warningMessage: string,\n log: Logger\n): JSONValue {\n let attributes = {};\n if (rawAttributes) {\n try {\n attributes = JSON.parse(rawAttributes);\n } catch (e) {\n log.warn(warningMessage, e);\n }\n }\n\n return attributes;\n}\n\n/**\n * Construct URI with query parameters\n */\nclass UriBuilder {\n private base: string;\n private args: string[];\n private paths: string[];\n\n constructor(base: string) {\n this.base = base.replace(/\\/$/, \"\");\n this.args = [];\n this.paths = [];\n }\n\n public arg(name: string, value: string | number | boolean): UriBuilder {\n if (typeof value !== \"undefined\") {\n this.args.push(\n encodeURIComponent(name) + \"=\" + encodeURIComponent(value)\n );\n }\n return this;\n }\n\n public path(name: string): UriBuilder {\n this.paths.push(encodeURIComponent(name));\n return this;\n }\n\n public build(): string {\n let result = this.base;\n if (this.paths.length) {\n result += \"/\" + this.paths.join(\"/\");\n }\n\n if (this.args.length) {\n result += \"?\" + this.args.join(\"&\");\n }\n return result;\n }\n}\n\nexport { deepClone, UriBuilder, parseToNumber, parseTime, parseAttributes };\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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