Comparing version 0.12.2 to 0.13.0-rc.0
/// <reference types="node" /> | ||
import { LogLevelDesc } from "loglevel"; | ||
import { EventEmitter } from "events"; | ||
import { LogLevelDesc } from "loglevel"; | ||
import { ReplayEventEmitter } from "@twilio/replay-event-emitter"; | ||
import { CloseEvent } from "ws"; | ||
declare class InitRegistration { | ||
@@ -215,2 +217,162 @@ product: string; | ||
} | ||
declare namespace Messages { | ||
type MessageType = "notification" | "message" | "reply" | "ping" | "close" | "init" | "telemetry.v1" | "client_update"; | ||
type Method = "GET" | "POST" | "PUT" | "DELETE" | "put_notification_ctx" | "delete_notification_ctx"; | ||
type Headers = { | ||
[id: string]: string; | ||
}; | ||
type Params = { | ||
[id: string]: string; | ||
}; | ||
interface Request { | ||
host: string; | ||
path: string; | ||
method: Method; | ||
headers: Headers; | ||
params: Params; | ||
} | ||
interface Address { | ||
method: Method; | ||
host: string; | ||
path: string; | ||
headers: Headers; | ||
params: Params; | ||
} | ||
type StatusType = { | ||
status: string; | ||
description?: string; | ||
code: number; | ||
errorCode?: number; | ||
}; | ||
interface Header { | ||
method: MessageType; | ||
id: string; | ||
payload_type?: string; | ||
payload_size?: number; | ||
notification_ctx_id?: string; | ||
http_request?: Request; | ||
http_status?: Record<string, unknown>; | ||
http_headers?: Headers; | ||
continuation_token_status?: Record<string, unknown>; | ||
capabilities?: string[]; | ||
token?: string; | ||
active_grant?: string; | ||
status: StatusType; | ||
message_type?: string; | ||
client_update_type?: string; | ||
offline_storage?: Record<string, unknown>; | ||
continuation_token?: string | null; | ||
events?: unknown[]; | ||
} | ||
type Context<T extends Record<string, unknown> = Record<string, unknown>> = T & { | ||
backoff_policy?: { | ||
reconnect_min_ms: number; | ||
reconnect_max_ms: number; | ||
}; | ||
headers?: Record<string, string>; | ||
}; | ||
class AbstractMessage { | ||
readonly id: string; | ||
constructor(id?: string); | ||
} | ||
class InitRegistration { | ||
product: string; | ||
type: string; | ||
notification_protocol_version: number; | ||
message_types: string[]; // It's a Set<string> but TS cannot serialize Sets properly. | ||
constructor(product: string); | ||
/* | ||
* @internal | ||
* | ||
* Populate init registrations section in the Twilsock configuration generically with | ||
* passed-in list of types to register. | ||
* | ||
* Used only by the SDK, ignore. | ||
* | ||
* @param {string[]} types List of types to add to init registrations in options. | ||
* @param {object} options Twilsock options object to update. Omit to create a new one. | ||
*/ | ||
populateInitRegistrations(types: string[]): void; | ||
} | ||
class Init extends AbstractMessage { | ||
readonly method: MessageType; | ||
readonly token: string; | ||
readonly continuation_token: string | null; | ||
readonly capabilities: string[]; | ||
readonly metadata?: Record<string, unknown>; | ||
readonly registrations?: InitRegistration[] | null; | ||
readonly tweaks?: Record<string, unknown> | null; | ||
constructor(token: string, continuationToken: string | null, metadata?: Record<string, unknown>, registrations?: InitRegistration[] | null, tweaks?: Record<string, unknown> | null); | ||
} | ||
interface ContinuationTokenStatus { | ||
reissued: boolean; | ||
reissue_message: string; | ||
} | ||
class InitReply extends AbstractMessage { | ||
readonly continuationToken: string; | ||
readonly continuationTokenStatus?: ContinuationTokenStatus; | ||
readonly offlineStorage?: string; | ||
readonly initRegistrations?: string; | ||
readonly debugInfo?: string; | ||
readonly confirmedCapabilities: Set<string>; | ||
constructor(id: string, continuationToken: string, confirmedCapabilities: Set<string>, continuationTokenStatus?: ContinuationTokenStatus, offlineStorage?: string, initRegistrations?: string, debugInfo?: string); | ||
} | ||
class Update extends AbstractMessage { | ||
readonly method: MessageType; | ||
readonly token: string; | ||
constructor(token: string); | ||
} | ||
class Message extends AbstractMessage { | ||
readonly method: MessageType; | ||
readonly active_grant: string; | ||
readonly payload_type: string; | ||
readonly http_request: Request; | ||
constructor(grant: string, contentType: string, request: Request); | ||
} | ||
type ReplyType = { | ||
id: string; | ||
method?: MessageType; | ||
payload_type?: string; | ||
status: { | ||
status: string; | ||
code: number; | ||
errorCode?: number; | ||
description?: string; | ||
}; | ||
header: Header; | ||
body: string; | ||
}; | ||
class Reply extends AbstractMessage { | ||
readonly method = "reply"; | ||
readonly payload_type = "application/json"; | ||
readonly status: { | ||
code: number; | ||
status: string; | ||
}; | ||
readonly header: any; | ||
readonly body: any; | ||
constructor(id: string); | ||
} | ||
class Close extends AbstractMessage { | ||
readonly method: MessageType; | ||
constructor(); | ||
} | ||
class TelemetryEvent { | ||
readonly start: number; | ||
// relative to event send time | ||
readonly end: number; | ||
// relative to event send time | ||
readonly title: string; | ||
readonly details: string; | ||
readonly id?: string | undefined; | ||
// optional, default will be random assigned by backend | ||
readonly type?: string | undefined; | ||
constructor(start: number, end: number, title: string, details: string, id?: string | undefined, type?: string | undefined); // optional, default will be "SDK" assigned by backend | ||
} | ||
class Telemetry extends AbstractMessage { | ||
readonly method: MessageType; | ||
events: TelemetryEvent[]; | ||
constructor(events: TelemetryEvent[]); | ||
} | ||
} | ||
interface PacketResponse { | ||
@@ -294,2 +456,11 @@ id: string; | ||
} | ||
declare class InitReply extends AbstractMessage { | ||
readonly continuationToken: string; | ||
readonly continuationTokenStatus?: ContinuationTokenStatus; | ||
readonly offlineStorage?: string; | ||
readonly initRegistrations?: string; | ||
readonly debugInfo?: string; | ||
readonly confirmedCapabilities: Set<string>; | ||
constructor(id: string, continuationToken: string, confirmedCapabilities: Set<string>, continuationTokenStatus?: ContinuationTokenStatus, offlineStorage?: string, initRegistrations?: string, debugInfo?: string); | ||
} | ||
type ReplyType = { | ||
@@ -322,3 +493,9 @@ id: string; | ||
} | ||
declare class WebSocketChannel extends EventEmitter implements Channel { | ||
type WebSocketChannelEvents = { | ||
connected: () => void; | ||
message: (data: unknown) => void; | ||
disconnected: (closeEvent: CloseEvent) => void; | ||
socketError: (error: Error) => void; | ||
}; | ||
declare class WebSocketChannel extends ReplayEventEmitter<WebSocketChannelEvents> implements Channel { | ||
private readonly url; | ||
@@ -333,6 +510,22 @@ private readonly WebSocket; | ||
} | ||
type TwilsockChannelEvents = { | ||
stateChanged: (state: ConnectionState) => void; | ||
beforeConnect: () => void; | ||
connecting: () => void; | ||
connected: () => void; | ||
beforeSendInit: () => void; | ||
sendInitFailed: () => void; | ||
initialized: (initReply: Messages.InitReply) => void; | ||
tokenAboutToExpire: () => void; | ||
tokenExpired: () => void; | ||
tokenUpdated: (error?: Error) => void; | ||
message: (messageType: string | undefined, payload: string) => void; | ||
disconnected: () => void; | ||
connectionError: (data: ConnectionError) => void; | ||
error: (terminal: boolean, message: string, httpStatusCode?: number | null, errorCode?: number | null) => void; | ||
}; | ||
/** | ||
* Twilsock channel level protocol implementation | ||
*/ | ||
declare class TwilsockChannel extends EventEmitter { | ||
declare class TwilsockChannel extends ReplayEventEmitter<TwilsockChannelEvents> { | ||
private readonly config; | ||
@@ -394,2 +587,6 @@ private readonly fsm; | ||
} | ||
type RegistrationsEvents = { | ||
registered: (contextId: string) => void; | ||
registrationFailed: (contextId: string, error: Error) => void; | ||
}; | ||
/** | ||
@@ -399,3 +596,3 @@ * Registrations module handles all operations with registration contexts through twilsock. | ||
*/ | ||
declare class Registrations extends EventEmitter { | ||
declare class Registrations extends ReplayEventEmitter<RegistrationsEvents> { | ||
private readonly transport; | ||
@@ -515,3 +712,3 @@ private readonly registrations; | ||
*/ | ||
type ConnectionState = "unknown" | "disconnecting" | "disconnected" | "connecting" | "connected" | "denied" | "error"; | ||
type ConnectionState = "unknown" | "disconnecting" | "disconnected" | "retrying" | "connecting" | "connected" | "denied" | "error"; | ||
type ClientOptionsType = { | ||
@@ -541,2 +738,19 @@ continuationToken?: string | null; | ||
}; | ||
type ConnectionError = { | ||
terminal: boolean; | ||
message: string; | ||
httpStatusCode?: number | null; | ||
errorCode?: number | null; | ||
}; | ||
type TwilsockClientEvents = { | ||
stateChanged: (state: ConnectionState) => void; | ||
registered: (id: string) => void; | ||
initialized: (initReply: InitReply) => void; | ||
connected: () => void; | ||
message: (type: string | undefined, message: string) => void; | ||
tokenAboutToExpire: () => void; | ||
tokenExpired: () => void; | ||
disconnected: () => void; | ||
connectionError: (error: ConnectionError) => void; | ||
}; | ||
/** | ||
@@ -554,3 +768,3 @@ * @alias Twilsock | ||
*/ | ||
declare class TwilsockClient extends EventEmitter { | ||
declare class TwilsockClient extends ReplayEventEmitter<TwilsockClientEvents> { | ||
private readonly config; | ||
@@ -569,3 +783,3 @@ private readonly channel; | ||
constructor(token: string, productId: string, options: Partial<ClientOptionsType>); | ||
emit(event: string | symbol, ...args: unknown[]): boolean; | ||
emit<E extends Extract<keyof TwilsockClientEvents, string>>(event: E, ...args: Parameters<TwilsockClientEvents[E]>): boolean; | ||
private handleStorageId; | ||
@@ -678,2 +892,2 @@ /** | ||
} | ||
export { TwilsockClient, TwilsockClient as Twilsock, ConnectionState, TwilsockError, TransportUnavailableError, Transport, Headers as TransportHeaders, Result as TransportResult, InitRegistration, TelemetryTracker, TelemetryEventDescription, TelemetryPoint, EventSendingLimitation }; | ||
export { TwilsockClient, TwilsockClient as Twilsock, ConnectionError, ConnectionState, TwilsockError, TransportUnavailableError, Transport, Result as TransportResult, InitRegistration, TelemetryTracker, TelemetryEventDescription, TelemetryPoint, EventSendingLimitation }; |
@@ -6,2 +6,16 @@ # Change Log | ||
## [0.13.0-rc.0](https://github.com/twilio/rtd-sdk-monorepo-js/compare/twilsock@0.12.2...twilsock@0.13.0-rc.0) (2022-04-13) | ||
### Features | ||
* Migrate Twilsock to ReplayEventEmitter ([6db99dd](https://github.com/twilio/rtd-sdk-monorepo-js/commit/6db99dd3cc207298870aff1835acad6f866d7c05)) | ||
### Bug Fixes | ||
* Add retrying state in case of connection errors ([bde622a](https://github.com/twilio/rtd-sdk-monorepo-js/commit/bde622ac2c7dad186b7790e461c469c9509293a4)) | ||
### [0.12.2](https://github.com/twilio/rtd-sdk-monorepo-js/compare/twilsock@0.12.2-rc.0...twilsock@0.12.2) (2022-03-03) | ||
@@ -8,0 +22,0 @@ |
@@ -98,6 +98,6 @@ /* | ||
var _polyfillNode_events = require('./_virtual/_polyfill-node_events.js'); | ||
var operationRetrier = require('@twilio/operation-retrier'); | ||
var replayEventEmitter = require('@twilio/replay-event-emitter'); | ||
class BackoffRetrier extends _polyfillNode_events['default'] { | ||
class BackoffRetrier extends replayEventEmitter.ReplayEventEmitter { | ||
constructor(options) { | ||
@@ -104,0 +104,0 @@ super(); |
@@ -99,3 +99,2 @@ /* | ||
var tslib_es6 = require('./node_modules/tslib/tslib.es6.js'); | ||
var _polyfillNode_events = require('./_virtual/_polyfill-node_events.js'); | ||
var declarativeTypeValidator = require('@twilio/declarative-type-validator'); | ||
@@ -115,2 +114,3 @@ var logger = require('./logger.js'); | ||
var _package = require('./packages/twilsock/package.json.js'); | ||
var replayEventEmitter = require('@twilio/replay-event-emitter'); | ||
@@ -133,3 +133,3 @@ class TelemetryEvents { | ||
*/ | ||
exports.TwilsockClient = class TwilsockClient extends _polyfillNode_events['default'] { | ||
exports.TwilsockClient = class TwilsockClient extends replayEventEmitter.ReplayEventEmitter { | ||
/** | ||
@@ -136,0 +136,0 @@ * @param {string} token Twilio access token |
@@ -98,5 +98,5 @@ /* | ||
var version = "0.12.2"; | ||
var version = "0.13.0-rc.0"; | ||
exports.version = version; | ||
//# sourceMappingURL=package.json.js.map |
@@ -99,5 +99,5 @@ /* | ||
var logger = require('../logger.js'); | ||
var _polyfillNode_events = require('../_virtual/_polyfill-node_events.js'); | ||
var uuid = require('uuid'); | ||
var twilsockerror = require('../error/twilsockerror.js'); | ||
var replayEventEmitter = require('@twilio/replay-event-emitter'); | ||
@@ -108,3 +108,3 @@ /** | ||
*/ | ||
class Registrations extends _polyfillNode_events['default'] { | ||
class Registrations extends replayEventEmitter.ReplayEventEmitter { | ||
constructor(transport) { | ||
@@ -111,0 +111,0 @@ super(); |
@@ -98,3 +98,2 @@ /* | ||
var _polyfillNode_events = require('./_virtual/_polyfill-node_events.js'); | ||
var StateMachine = require('javascript-state-machine'); | ||
@@ -108,2 +107,3 @@ var logger = require('./logger.js'); | ||
var backoffretrier = require('./backoffretrier.js'); | ||
var replayEventEmitter = require('@twilio/replay-event-emitter'); | ||
@@ -142,3 +142,3 @@ function _interopNamespace(e) { | ||
*/ | ||
class TwilsockChannel extends _polyfillNode_events['default'] { | ||
class TwilsockChannel extends replayEventEmitter.ReplayEventEmitter { | ||
constructor(websocket, transport, config) { | ||
@@ -155,8 +155,11 @@ super(); | ||
this.websocket.on("message", (message) => this.onIncomingMessage(message)); | ||
this.websocket.on("socketError", (e) => this.emit("connectionError", { | ||
terminal: false, | ||
message: `Socket error: ${e.message}`, | ||
httpStatusCode: null, | ||
errorCode: null, | ||
})); | ||
this.websocket.on("socketError", (e) => { | ||
this.emit("connectionError", { | ||
terminal: false, | ||
message: `Socket error: ${e.message}`, | ||
httpStatusCode: null, | ||
errorCode: null, | ||
}); | ||
this.emit("stateChanged", "retrying"); | ||
}); | ||
this.transport = transport; | ||
@@ -163,0 +166,0 @@ this.config = config; |
@@ -98,6 +98,6 @@ /* | ||
var _polyfillNode_events = require('./_virtual/_polyfill-node_events.js'); | ||
var logger = require('./logger.js'); | ||
var replayEventEmitter = require('@twilio/replay-event-emitter'); | ||
class WebSocketChannel extends _polyfillNode_events['default'] { | ||
class WebSocketChannel extends replayEventEmitter.ReplayEventEmitter { | ||
constructor(url) { | ||
@@ -104,0 +104,0 @@ super(); |
{ | ||
"name": "twilsock", | ||
"version": "0.12.2", | ||
"version": "0.13.0-rc.0", | ||
"description": "Client library for TwilSock service", | ||
@@ -5,0 +5,0 @@ "main": "./builds/lib.js", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1772901
73
25506