From 255e7d714cfb901cf38960c22009de93ab7135ff Mon Sep 17 00:00:00 2001 From: James Lees Date: Wed, 5 Feb 2020 09:30:00 +0000 Subject: [PATCH 1/6] include automatically generated declarations --- tsconfig.json | 3 +- types/index.d.ts | 15 ++++++ .../helpers/node/mock-dom-dependencies.d.ts | 1 + .../helpers/pusher_integration_class.d.ts | 4 ++ types/src/core/auth/auth_transports.d.ts | 8 +++ types/src/core/auth/options.d.ts | 16 ++++++ types/src/core/auth/pusher_authorizer.d.ts | 13 +++++ types/src/core/base64.d.ts | 1 + types/src/core/channels/channel.d.ts | 20 ++++++++ types/src/core/channels/channel_table.d.ts | 5 ++ types/src/core/channels/channels.d.ts | 12 +++++ .../src/core/channels/encrypted_channel.d.ts | 11 ++++ types/src/core/channels/members.d.ts | 14 ++++++ types/src/core/channels/metadata.d.ts | 4 ++ types/src/core/channels/presence_channel.d.ts | 13 +++++ types/src/core/channels/private_channel.d.ts | 4 ++ types/src/core/config.d.ts | 20 ++++++++ types/src/core/connection/callbacks.d.ts | 18 +++++++ types/src/core/connection/connection.d.ts | 16 ++++++ .../core/connection/connection_manager.d.ts | 50 +++++++++++++++++++ .../connection_manager_options.d.ts | 10 ++++ .../handshake/handshake_payload.d.ts | 8 +++ .../src/core/connection/handshake/index.d.ts | 12 +++++ .../src/core/connection/protocol/action.d.ts | 7 +++ .../connection/protocol/message-types.d.ts | 7 +++ .../core/connection/protocol/protocol.d.ts | 10 ++++ types/src/core/defaults.d.ts | 23 +++++++++ types/src/core/errors.d.ts | 21 ++++++++ types/src/core/events/callback.d.ts | 5 ++ types/src/core/events/callback_registry.d.ts | 11 ++++ types/src/core/events/callback_table.d.ts | 5 ++ types/src/core/events/dispatcher.d.ts | 14 ++++++ types/src/core/http/ajax.d.ts | 16 ++++++ types/src/core/http/http_factory.d.ts | 13 +++++ types/src/core/http/http_polling_socket.d.ts | 3 ++ types/src/core/http/http_request.d.ts | 17 +++++++ types/src/core/http/http_socket.d.ts | 32 ++++++++++++ .../src/core/http/http_streaming_socket.d.ts | 3 ++ types/src/core/http/request_hooks.d.ts | 6 +++ types/src/core/http/socket_hooks.d.ts | 8 +++ types/src/core/http/state.d.ts | 6 +++ types/src/core/http/url_location.d.ts | 5 ++ types/src/core/index.d.ts | 6 +++ types/src/core/logger.d.ts | 11 ++++ types/src/core/options.d.ts | 43 ++++++++++++++++ types/src/core/pusher.d.ts | 45 +++++++++++++++++ types/src/core/reachability.d.ts | 5 ++ types/src/core/socket.d.ts | 12 +++++ .../best_connected_ever_strategy.d.ts | 10 ++++ .../src/core/strategies/cached_strategy.d.ts | 20 ++++++++ .../src/core/strategies/delayed_strategy.d.ts | 15 ++++++ .../strategies/first_connected_strategy.d.ts | 8 +++ types/src/core/strategies/if_strategy.d.ts | 10 ++++ .../core/strategies/sequential_strategy.d.ts | 16 ++++++ types/src/core/strategies/strategy.d.ts | 6 +++ .../src/core/strategies/strategy_builder.d.ts | 3 ++ .../src/core/strategies/strategy_options.d.ts | 12 +++++ .../src/core/strategies/strategy_runner.d.ts | 5 ++ .../core/strategies/transport_strategy.d.ts | 15 ++++++ types/src/core/timeline/level.d.ts | 6 +++ types/src/core/timeline/timeline.d.ts | 25 ++++++++++ types/src/core/timeline/timeline_sender.d.ts | 13 +++++ .../src/core/timeline/timeline_transport.d.ts | 6 +++ .../assistant_to_the_transport_manager.d.ts | 14 ++++++ .../core/transports/ping_delay_options.d.ts | 6 +++ types/src/core/transports/transport.d.ts | 8 +++ .../core/transports/transport_connection.d.ts | 35 +++++++++++++ .../transport_connection_options.d.ts | 6 +++ .../src/core/transports/transport_hooks.d.ts | 13 +++++ .../core/transports/transport_manager.d.ts | 14 ++++++ .../src/core/transports/transports_table.d.ts | 10 ++++ types/src/core/transports/url_scheme.d.ts | 11 ++++ types/src/core/transports/url_schemes.d.ts | 4 ++ types/src/core/util.d.ts | 8 +++ types/src/core/utils/collections.d.ts | 18 +++++++ types/src/core/utils/factory.d.ts | 30 +++++++++++ .../src/core/utils/timers/abstract_timer.d.ts | 10 ++++ types/src/core/utils/timers/index.d.ts | 9 ++++ types/src/core/utils/timers/scheduling.d.ts | 8 +++ .../src/core/utils/timers/timed_callback.d.ts | 4 ++ types/src/core/utils/url_store.d.ts | 4 ++ types/src/runtimes/interface.d.ts | 40 +++++++++++++++ .../runtimes/isomorphic/auth/xhr_auth.d.ts | 3 ++ .../runtimes/isomorphic/default_strategy.d.ts | 3 ++ types/src/runtimes/isomorphic/http/http.d.ts | 3 ++ .../isomorphic/http/http_xhr_request.d.ts | 3 ++ types/src/runtimes/isomorphic/runtime.d.ts | 2 + .../isomorphic/timeline/xhr_timeline.d.ts | 6 +++ .../transport_connection_initializer.d.ts | 1 + .../isomorphic/transports/transports.d.ts | 5 ++ types/src/runtimes/node/net_info.d.ts | 6 +++ types/src/runtimes/node/runtime.d.ts | 3 ++ types/src/runtimes/react-native/net_info.d.ts | 8 +++ types/src/runtimes/react-native/runtime.d.ts | 3 ++ .../react-native/tweetnacl-dummy.d.ts | 5 ++ .../react-native/tweetnacl-util-dummy.d.ts | 7 +++ types/src/runtimes/web/auth/jsonp_auth.d.ts | 3 ++ types/src/runtimes/web/browser.d.ts | 19 +++++++ types/src/runtimes/web/default_strategy.d.ts | 3 ++ types/src/runtimes/web/dom/dependencies.d.ts | 4 ++ .../runtimes/web/dom/dependency_loader.d.ts | 10 ++++ types/src/runtimes/web/dom/jsonp_request.d.ts | 10 ++++ .../src/runtimes/web/dom/script_receiver.d.ts | 7 +++ .../web/dom/script_receiver_factory.d.ts | 10 ++++ .../src/runtimes/web/dom/script_request.d.ts | 9 ++++ types/src/runtimes/web/http/http.d.ts | 2 + .../web/http/http_xdomain_request.d.ts | 3 ++ types/src/runtimes/web/net_info.d.ts | 7 +++ types/src/runtimes/web/runtime.d.ts | 3 ++ .../runtimes/web/timeline/jsonp_timeline.d.ts | 6 +++ .../transport_connection_initializer.d.ts | 1 + .../runtimes/web/transports/transports.d.ts | 2 + .../src/runtimes/worker/auth/fetch_auth.d.ts | 3 ++ types/src/runtimes/worker/net_info.d.ts | 6 +++ types/src/runtimes/worker/runtime.d.ts | 3 ++ .../worker/timeline/fetch_timeline.d.ts | 6 +++ 116 files changed, 1208 insertions(+), 1 deletion(-) create mode 100644 types/index.d.ts create mode 100644 types/spec/javascripts/helpers/node/mock-dom-dependencies.d.ts create mode 100644 types/spec/javascripts/helpers/pusher_integration_class.d.ts create mode 100644 types/src/core/auth/auth_transports.d.ts create mode 100644 types/src/core/auth/options.d.ts create mode 100644 types/src/core/auth/pusher_authorizer.d.ts create mode 100644 types/src/core/base64.d.ts create mode 100644 types/src/core/channels/channel.d.ts create mode 100644 types/src/core/channels/channel_table.d.ts create mode 100644 types/src/core/channels/channels.d.ts create mode 100644 types/src/core/channels/encrypted_channel.d.ts create mode 100644 types/src/core/channels/members.d.ts create mode 100644 types/src/core/channels/metadata.d.ts create mode 100644 types/src/core/channels/presence_channel.d.ts create mode 100644 types/src/core/channels/private_channel.d.ts create mode 100644 types/src/core/config.d.ts create mode 100644 types/src/core/connection/callbacks.d.ts create mode 100644 types/src/core/connection/connection.d.ts create mode 100644 types/src/core/connection/connection_manager.d.ts create mode 100644 types/src/core/connection/connection_manager_options.d.ts create mode 100644 types/src/core/connection/handshake/handshake_payload.d.ts create mode 100644 types/src/core/connection/handshake/index.d.ts create mode 100644 types/src/core/connection/protocol/action.d.ts create mode 100644 types/src/core/connection/protocol/message-types.d.ts create mode 100644 types/src/core/connection/protocol/protocol.d.ts create mode 100644 types/src/core/defaults.d.ts create mode 100644 types/src/core/errors.d.ts create mode 100644 types/src/core/events/callback.d.ts create mode 100644 types/src/core/events/callback_registry.d.ts create mode 100644 types/src/core/events/callback_table.d.ts create mode 100644 types/src/core/events/dispatcher.d.ts create mode 100644 types/src/core/http/ajax.d.ts create mode 100644 types/src/core/http/http_factory.d.ts create mode 100644 types/src/core/http/http_polling_socket.d.ts create mode 100644 types/src/core/http/http_request.d.ts create mode 100644 types/src/core/http/http_socket.d.ts create mode 100644 types/src/core/http/http_streaming_socket.d.ts create mode 100644 types/src/core/http/request_hooks.d.ts create mode 100644 types/src/core/http/socket_hooks.d.ts create mode 100644 types/src/core/http/state.d.ts create mode 100644 types/src/core/http/url_location.d.ts create mode 100644 types/src/core/index.d.ts create mode 100644 types/src/core/logger.d.ts create mode 100644 types/src/core/options.d.ts create mode 100644 types/src/core/pusher.d.ts create mode 100644 types/src/core/reachability.d.ts create mode 100644 types/src/core/socket.d.ts create mode 100644 types/src/core/strategies/best_connected_ever_strategy.d.ts create mode 100644 types/src/core/strategies/cached_strategy.d.ts create mode 100644 types/src/core/strategies/delayed_strategy.d.ts create mode 100644 types/src/core/strategies/first_connected_strategy.d.ts create mode 100644 types/src/core/strategies/if_strategy.d.ts create mode 100644 types/src/core/strategies/sequential_strategy.d.ts create mode 100644 types/src/core/strategies/strategy.d.ts create mode 100644 types/src/core/strategies/strategy_builder.d.ts create mode 100644 types/src/core/strategies/strategy_options.d.ts create mode 100644 types/src/core/strategies/strategy_runner.d.ts create mode 100644 types/src/core/strategies/transport_strategy.d.ts create mode 100644 types/src/core/timeline/level.d.ts create mode 100644 types/src/core/timeline/timeline.d.ts create mode 100644 types/src/core/timeline/timeline_sender.d.ts create mode 100644 types/src/core/timeline/timeline_transport.d.ts create mode 100644 types/src/core/transports/assistant_to_the_transport_manager.d.ts create mode 100644 types/src/core/transports/ping_delay_options.d.ts create mode 100644 types/src/core/transports/transport.d.ts create mode 100644 types/src/core/transports/transport_connection.d.ts create mode 100644 types/src/core/transports/transport_connection_options.d.ts create mode 100644 types/src/core/transports/transport_hooks.d.ts create mode 100644 types/src/core/transports/transport_manager.d.ts create mode 100644 types/src/core/transports/transports_table.d.ts create mode 100644 types/src/core/transports/url_scheme.d.ts create mode 100644 types/src/core/transports/url_schemes.d.ts create mode 100644 types/src/core/util.d.ts create mode 100644 types/src/core/utils/collections.d.ts create mode 100644 types/src/core/utils/factory.d.ts create mode 100644 types/src/core/utils/timers/abstract_timer.d.ts create mode 100644 types/src/core/utils/timers/index.d.ts create mode 100644 types/src/core/utils/timers/scheduling.d.ts create mode 100644 types/src/core/utils/timers/timed_callback.d.ts create mode 100644 types/src/core/utils/url_store.d.ts create mode 100644 types/src/runtimes/interface.d.ts create mode 100644 types/src/runtimes/isomorphic/auth/xhr_auth.d.ts create mode 100644 types/src/runtimes/isomorphic/default_strategy.d.ts create mode 100644 types/src/runtimes/isomorphic/http/http.d.ts create mode 100644 types/src/runtimes/isomorphic/http/http_xhr_request.d.ts create mode 100644 types/src/runtimes/isomorphic/runtime.d.ts create mode 100644 types/src/runtimes/isomorphic/timeline/xhr_timeline.d.ts create mode 100644 types/src/runtimes/isomorphic/transports/transport_connection_initializer.d.ts create mode 100644 types/src/runtimes/isomorphic/transports/transports.d.ts create mode 100644 types/src/runtimes/node/net_info.d.ts create mode 100644 types/src/runtimes/node/runtime.d.ts create mode 100644 types/src/runtimes/react-native/net_info.d.ts create mode 100644 types/src/runtimes/react-native/runtime.d.ts create mode 100644 types/src/runtimes/react-native/tweetnacl-dummy.d.ts create mode 100644 types/src/runtimes/react-native/tweetnacl-util-dummy.d.ts create mode 100644 types/src/runtimes/web/auth/jsonp_auth.d.ts create mode 100644 types/src/runtimes/web/browser.d.ts create mode 100644 types/src/runtimes/web/default_strategy.d.ts create mode 100644 types/src/runtimes/web/dom/dependencies.d.ts create mode 100644 types/src/runtimes/web/dom/dependency_loader.d.ts create mode 100644 types/src/runtimes/web/dom/jsonp_request.d.ts create mode 100644 types/src/runtimes/web/dom/script_receiver.d.ts create mode 100644 types/src/runtimes/web/dom/script_receiver_factory.d.ts create mode 100644 types/src/runtimes/web/dom/script_request.d.ts create mode 100644 types/src/runtimes/web/http/http.d.ts create mode 100644 types/src/runtimes/web/http/http_xdomain_request.d.ts create mode 100644 types/src/runtimes/web/net_info.d.ts create mode 100644 types/src/runtimes/web/runtime.d.ts create mode 100644 types/src/runtimes/web/timeline/jsonp_timeline.d.ts create mode 100644 types/src/runtimes/web/transports/transport_connection_initializer.d.ts create mode 100644 types/src/runtimes/web/transports/transports.d.ts create mode 100644 types/src/runtimes/worker/auth/fetch_auth.d.ts create mode 100644 types/src/runtimes/worker/net_info.d.ts create mode 100644 types/src/runtimes/worker/runtime.d.ts create mode 100644 types/src/runtimes/worker/timeline/fetch_timeline.d.ts diff --git a/tsconfig.json b/tsconfig.json index 8548dcda5..bed4d10cb 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,7 +2,8 @@ "compilerOptions": { "sourceMap": true, "module": "es6", - "declaration": false, + "declaration": true, + "declarationDir": "types", "target": "es3", "removeComments": true, "moduleResolution": "node", diff --git a/types/index.d.ts b/types/index.d.ts new file mode 100644 index 000000000..d94d9b7e0 --- /dev/null +++ b/types/index.d.ts @@ -0,0 +1,15 @@ +import Pusher from './src/core/pusher' +import { Authorizer, AuthOptions, AuthorizerGenerator } from './src/core/auth/options'; +import { Options } from './src/core/options' +import Channel from './src/core/channels/channel'; +import Runtime from './src/runtimes/interface' + +export { + Options, + AuthOptions, + AuthorizerGenerator, + Authorizer, + Channel, + Runtime, +} +export default Pusher diff --git a/types/spec/javascripts/helpers/node/mock-dom-dependencies.d.ts b/types/spec/javascripts/helpers/node/mock-dom-dependencies.d.ts new file mode 100644 index 000000000..662598c0a --- /dev/null +++ b/types/spec/javascripts/helpers/node/mock-dom-dependencies.d.ts @@ -0,0 +1 @@ +export declare var Dependencies: {}; diff --git a/types/spec/javascripts/helpers/pusher_integration_class.d.ts b/types/spec/javascripts/helpers/pusher_integration_class.d.ts new file mode 100644 index 000000000..72c9a8a2b --- /dev/null +++ b/types/spec/javascripts/helpers/pusher_integration_class.d.ts @@ -0,0 +1,4 @@ +import Pusher from '../../../src/core/pusher'; +export default class PusherIntegration extends Pusher { + static Integration: any; +} diff --git a/types/src/core/auth/auth_transports.d.ts b/types/src/core/auth/auth_transports.d.ts new file mode 100644 index 000000000..5909918e6 --- /dev/null +++ b/types/src/core/auth/auth_transports.d.ts @@ -0,0 +1,8 @@ +import AbstractRuntime from 'runtimes/interface'; +interface AuthTransport { + (context: AbstractRuntime, socketId: string, callback: Function): void; +} +interface AuthTransports { + [index: string]: AuthTransport; +} +export { AuthTransport, AuthTransports }; diff --git a/types/src/core/auth/options.d.ts b/types/src/core/auth/options.d.ts new file mode 100644 index 000000000..e0161ad47 --- /dev/null +++ b/types/src/core/auth/options.d.ts @@ -0,0 +1,16 @@ +import Channel from '../channels/channel'; +export interface AuthOptions { + params: any; + headers: any; +} +export interface Authorizer { + authorize(socketId: string, callback: Function): any; +} +export interface AuthorizerGenerator { + (channel: Channel, options: AuthorizerOptions): Authorizer; +} +export interface AuthorizerOptions { + authTransport: 'ajax' | 'jsonp'; + auth: AuthOptions; + authorizer: AuthorizerGenerator; +} diff --git a/types/src/core/auth/pusher_authorizer.d.ts b/types/src/core/auth/pusher_authorizer.d.ts new file mode 100644 index 000000000..d64cfef75 --- /dev/null +++ b/types/src/core/auth/pusher_authorizer.d.ts @@ -0,0 +1,13 @@ +import Channel from '../channels/channel'; +import { AuthTransports } from './auth_transports'; +import { AuthOptions, AuthorizerOptions, Authorizer } from './options'; +export default class PusherAuthorizer implements Authorizer { + static authorizers: AuthTransports; + channel: Channel; + type: string; + options: AuthorizerOptions; + authOptions: AuthOptions; + constructor(channel: Channel, options: AuthorizerOptions); + composeQuery(socketId: string): string; + authorize(socketId: string, callback: Function): any; +} diff --git a/types/src/core/base64.d.ts b/types/src/core/base64.d.ts new file mode 100644 index 000000000..4953dc483 --- /dev/null +++ b/types/src/core/base64.d.ts @@ -0,0 +1 @@ +export default function encode(s: any): string; diff --git a/types/src/core/channels/channel.d.ts b/types/src/core/channels/channel.d.ts new file mode 100644 index 000000000..917e65eee --- /dev/null +++ b/types/src/core/channels/channel.d.ts @@ -0,0 +1,20 @@ +import { default as EventsDispatcher } from '../events/dispatcher'; +import Pusher from '../pusher'; +import { PusherEvent } from '../connection/protocol/message-types'; +export default class Channel extends EventsDispatcher { + name: string; + pusher: Pusher; + subscribed: boolean; + subscriptionPending: boolean; + subscriptionCancelled: boolean; + constructor(name: string, pusher: Pusher); + authorize(socketId: string, callback: Function): any; + trigger(event: string, data: any): boolean; + disconnect(): void; + handleEvent(event: PusherEvent): void; + handleSubscriptionSucceededEvent(event: PusherEvent): void; + subscribe(): void; + unsubscribe(): void; + cancelSubscription(): void; + reinstateSubscription(): void; +} diff --git a/types/src/core/channels/channel_table.d.ts b/types/src/core/channels/channel_table.d.ts new file mode 100644 index 000000000..1a9626b70 --- /dev/null +++ b/types/src/core/channels/channel_table.d.ts @@ -0,0 +1,5 @@ +import Channel from './channel'; +interface ChannelTable { + [index: string]: Channel; +} +export default ChannelTable; diff --git a/types/src/core/channels/channels.d.ts b/types/src/core/channels/channels.d.ts new file mode 100644 index 000000000..713dae703 --- /dev/null +++ b/types/src/core/channels/channels.d.ts @@ -0,0 +1,12 @@ +import Channel from './channel'; +import ChannelTable from './channel_table'; +import Pusher from '../pusher'; +export default class Channels { + channels: ChannelTable; + constructor(); + add(name: string, pusher: Pusher): Channel; + all(): Channel[]; + find(name: string): Channel; + remove(name: string): Channel; + disconnect(): void; +} diff --git a/types/src/core/channels/encrypted_channel.d.ts b/types/src/core/channels/encrypted_channel.d.ts new file mode 100644 index 000000000..afb54beb1 --- /dev/null +++ b/types/src/core/channels/encrypted_channel.d.ts @@ -0,0 +1,11 @@ +import PrivateChannel from './private_channel'; +import Dispatcher from '../events/dispatcher'; +import { PusherEvent } from '../connection/protocol/message-types'; +export default class EncryptedChannel extends PrivateChannel { + key: Uint8Array; + authorize(socketId: string, callback: Function): void; + trigger(event: string, data: any): boolean; + handleEvent(event: PusherEvent): void; + private handleEncryptedEvent; + emitJSON(eventName: string, data?: any): Dispatcher; +} diff --git a/types/src/core/channels/members.d.ts b/types/src/core/channels/members.d.ts new file mode 100644 index 000000000..f6f00d172 --- /dev/null +++ b/types/src/core/channels/members.d.ts @@ -0,0 +1,14 @@ +export default class Members { + members: any; + count: number; + myID: any; + me: any; + constructor(); + get(id: string): any; + each(callback: Function): void; + setMyID(id: string): void; + onSubscription(subscriptionData: any): void; + addMember(memberData: any): any; + removeMember(memberData: any): any; + reset(): void; +} diff --git a/types/src/core/channels/metadata.d.ts b/types/src/core/channels/metadata.d.ts new file mode 100644 index 000000000..2c84dfdbe --- /dev/null +++ b/types/src/core/channels/metadata.d.ts @@ -0,0 +1,4 @@ +interface Metadata { + user_id?: string; +} +export default Metadata; diff --git a/types/src/core/channels/presence_channel.d.ts b/types/src/core/channels/presence_channel.d.ts new file mode 100644 index 000000000..652711cf3 --- /dev/null +++ b/types/src/core/channels/presence_channel.d.ts @@ -0,0 +1,13 @@ +import PrivateChannel from './private_channel'; +import Members from './members'; +import Pusher from '../pusher'; +import { PusherEvent } from '../connection/protocol/message-types'; +export default class PresenceChannel extends PrivateChannel { + members: Members; + constructor(name: string, pusher: Pusher); + authorize(socketId: string, callback: Function): void; + handleEvent(event: PusherEvent): void; + handleInternalEvent(event: PusherEvent): void; + handleSubscriptionSucceededEvent(event: PusherEvent): void; + disconnect(): void; +} diff --git a/types/src/core/channels/private_channel.d.ts b/types/src/core/channels/private_channel.d.ts new file mode 100644 index 000000000..d9d39c435 --- /dev/null +++ b/types/src/core/channels/private_channel.d.ts @@ -0,0 +1,4 @@ +import Channel from './channel'; +export default class PrivateChannel extends Channel { + authorize(socketId: string, callback: Function): any; +} diff --git a/types/src/core/config.d.ts b/types/src/core/config.d.ts new file mode 100644 index 000000000..c54c790e4 --- /dev/null +++ b/types/src/core/config.d.ts @@ -0,0 +1,20 @@ +export declare var getGlobalConfig: () => { + wsHost: string; + wsPort: number; + wssPort: number; + wsPath: string; + httpHost: string; + httpPort: number; + httpsPort: number; + httpPath: string; + statsHost: string; + authEndpoint: string; + authTransport: string; + activityTimeout: number; + pongTimeout: number; + unavailableTimeout: number; +}; +export declare var getClusterConfig: (clusterName: any) => { + wsHost: string; + httpHost: string; +}; diff --git a/types/src/core/connection/callbacks.d.ts b/types/src/core/connection/callbacks.d.ts new file mode 100644 index 000000000..c20e6abce --- /dev/null +++ b/types/src/core/connection/callbacks.d.ts @@ -0,0 +1,18 @@ +import HandshakePayload from './handshake/handshake_payload'; +import Action from './protocol/action'; +export interface ErrorCallbacks { + tls_only: (result: Action | HandshakePayload) => void; + refused: (result: Action | HandshakePayload) => void; + backoff: (result: Action | HandshakePayload) => void; + retry: (result: Action | HandshakePayload) => void; +} +export interface HandshakeCallbacks { + connected: (handshake: HandshakePayload) => void; +} +export interface ConnectionCallbacks { + message: (message: any) => void; + ping: () => void; + activity: () => void; + error: (error: any) => void; + closed: () => void; +} diff --git a/types/src/core/connection/connection.d.ts b/types/src/core/connection/connection.d.ts new file mode 100644 index 000000000..03b13b825 --- /dev/null +++ b/types/src/core/connection/connection.d.ts @@ -0,0 +1,16 @@ +import { default as EventsDispatcher } from '../events/dispatcher'; +import TransportConnection from '../transports/transport_connection'; +import Socket from '../socket'; +export default class Connection extends EventsDispatcher implements Socket { + id: string; + transport: TransportConnection; + activityTimeout: number; + constructor(id: string, transport: TransportConnection); + handlesActivityChecks(): boolean; + send(data: any): boolean; + send_event(name: string, data: any, channel?: string): boolean; + ping(): void; + close(): void; + private bindListeners; + private handleCloseEvent; +} diff --git a/types/src/core/connection/connection_manager.d.ts b/types/src/core/connection/connection_manager.d.ts new file mode 100644 index 000000000..30240913f --- /dev/null +++ b/types/src/core/connection/connection_manager.d.ts @@ -0,0 +1,50 @@ +import { default as EventsDispatcher } from '../events/dispatcher'; +import { OneOffTimer as Timer } from '../utils/timers'; +import Connection from './connection'; +import Strategy from '../strategies/strategy'; +import StrategyRunner from '../strategies/strategy_runner'; +import Timeline from '../timeline/timeline'; +import ConnectionManagerOptions from './connection_manager_options'; +import { ErrorCallbacks, HandshakeCallbacks, ConnectionCallbacks } from './callbacks'; +export default class ConnectionManager extends EventsDispatcher { + key: string; + options: ConnectionManagerOptions; + state: string; + connection: Connection; + usingTLS: boolean; + timeline: Timeline; + socket_id: string; + unavailableTimer: Timer; + activityTimer: Timer; + retryTimer: Timer; + activityTimeout: number; + strategy: Strategy; + runner: StrategyRunner; + errorCallbacks: ErrorCallbacks; + handshakeCallbacks: HandshakeCallbacks; + connectionCallbacks: ConnectionCallbacks; + constructor(key: string, options: any); + connect(): void; + send(data: any): boolean; + send_event(name: string, data: any, channel?: string): boolean; + disconnect(): void; + isUsingTLS(): boolean; + private startConnecting; + private abortConnecting; + private disconnectInternally; + private updateStrategy; + private retryIn; + private clearRetryTimer; + private setUnavailableTimer; + private clearUnavailableTimer; + private sendActivityCheck; + private resetActivityCheck; + private stopActivityCheck; + private buildConnectionCallbacks; + private buildHandshakeCallbacks; + private buildErrorCallbacks; + private setConnection; + private abandonConnection; + private updateState; + private shouldRetry; +} diff --git a/types/src/core/connection/connection_manager_options.d.ts b/types/src/core/connection/connection_manager_options.d.ts new file mode 100644 index 000000000..be8c736ff --- /dev/null +++ b/types/src/core/connection/connection_manager_options.d.ts @@ -0,0 +1,10 @@ +import Timeline from '../timeline/timeline'; +import Strategy from '../strategies/strategy'; +interface ConnectionManagerOptions { + timeline: Timeline; + getStrategy: (StrategyOptions: any) => Strategy; + unavailableTimeout: number; + pongTimeout: number; + activityTimeout: number; +} +export default ConnectionManagerOptions; diff --git a/types/src/core/connection/handshake/handshake_payload.d.ts b/types/src/core/connection/handshake/handshake_payload.d.ts new file mode 100644 index 000000000..d5062c314 --- /dev/null +++ b/types/src/core/connection/handshake/handshake_payload.d.ts @@ -0,0 +1,8 @@ +import TransportConnection from '../../transports/transport_connection'; +import Action from '../protocol/action'; +import Connection from '../connection'; +interface HandshakePayload extends Action { + transport: TransportConnection; + connection?: Connection; +} +export default HandshakePayload; diff --git a/types/src/core/connection/handshake/index.d.ts b/types/src/core/connection/handshake/index.d.ts new file mode 100644 index 000000000..e840dba17 --- /dev/null +++ b/types/src/core/connection/handshake/index.d.ts @@ -0,0 +1,12 @@ +import TransportConnection from '../../transports/transport_connection'; +export default class Handshake { + transport: TransportConnection; + callback: (HandshakePayload: any) => void; + onMessage: Function; + onClosed: Function; + constructor(transport: TransportConnection, callback: (HandshakePayload: any) => void); + close(): void; + private bindListeners; + private unbindListeners; + private finish; +} diff --git a/types/src/core/connection/protocol/action.d.ts b/types/src/core/connection/protocol/action.d.ts new file mode 100644 index 000000000..a1d57d403 --- /dev/null +++ b/types/src/core/connection/protocol/action.d.ts @@ -0,0 +1,7 @@ +interface Action { + action: string; + id?: string; + activityTimeout?: number; + error?: any; +} +export default Action; diff --git a/types/src/core/connection/protocol/message-types.d.ts b/types/src/core/connection/protocol/message-types.d.ts new file mode 100644 index 000000000..1106309b2 --- /dev/null +++ b/types/src/core/connection/protocol/message-types.d.ts @@ -0,0 +1,7 @@ +interface PusherEvent { + event: string; + channel?: string; + data?: any; + user_id?: string; +} +export { PusherEvent }; diff --git a/types/src/core/connection/protocol/protocol.d.ts b/types/src/core/connection/protocol/protocol.d.ts new file mode 100644 index 000000000..ce03ca904 --- /dev/null +++ b/types/src/core/connection/protocol/protocol.d.ts @@ -0,0 +1,10 @@ +import Action from './action'; +import { PusherEvent } from './message-types'; +declare const Protocol: { + decodeMessage: (messageEvent: MessageEvent) => PusherEvent; + encodeMessage: (event: PusherEvent) => string; + processHandshake: (messageEvent: MessageEvent) => Action; + getCloseAction: (closeEvent: any) => string; + getCloseError: (closeEvent: any) => any; +}; +export default Protocol; diff --git a/types/src/core/defaults.d.ts b/types/src/core/defaults.d.ts new file mode 100644 index 000000000..2c176f8a2 --- /dev/null +++ b/types/src/core/defaults.d.ts @@ -0,0 +1,23 @@ +export interface DefaultConfig { + VERSION: string; + PROTOCOL: number; + host: string; + ws_port: number; + wss_port: number; + ws_path: string; + sockjs_host: string; + sockjs_http_port: number; + sockjs_https_port: number; + sockjs_path: string; + stats_host: string; + channel_auth_endpoint: string; + channel_auth_transport: string; + activity_timeout: number; + pong_timeout: number; + unavailable_timeout: number; + cdn_http?: string; + cdn_https?: string; + dependency_suffix?: string; +} +declare var Defaults: DefaultConfig; +export default Defaults; diff --git a/types/src/core/errors.d.ts b/types/src/core/errors.d.ts new file mode 100644 index 000000000..c64cf72fe --- /dev/null +++ b/types/src/core/errors.d.ts @@ -0,0 +1,21 @@ +export declare class BadEventName extends Error { + constructor(msg?: string); +} +export declare class RequestTimedOut extends Error { + constructor(msg?: string); +} +export declare class TransportPriorityTooLow extends Error { + constructor(msg?: string); +} +export declare class TransportClosed extends Error { + constructor(msg?: string); +} +export declare class UnsupportedFeature extends Error { + constructor(msg?: string); +} +export declare class UnsupportedTransport extends Error { + constructor(msg?: string); +} +export declare class UnsupportedStrategy extends Error { + constructor(msg?: string); +} diff --git a/types/src/core/events/callback.d.ts b/types/src/core/events/callback.d.ts new file mode 100644 index 000000000..5687c0f71 --- /dev/null +++ b/types/src/core/events/callback.d.ts @@ -0,0 +1,5 @@ +interface Callback { + fn: Function; + context: any; +} +export default Callback; diff --git a/types/src/core/events/callback_registry.d.ts b/types/src/core/events/callback_registry.d.ts new file mode 100644 index 000000000..fc53ce254 --- /dev/null +++ b/types/src/core/events/callback_registry.d.ts @@ -0,0 +1,11 @@ +import Callback from './callback'; +import CallbackTable from './callback_table'; +export default class CallbackRegistry { + _callbacks: CallbackTable; + constructor(); + get(name: string): Callback[]; + add(name: string, callback: Function, context: any): void; + remove(name?: string, callback?: Function, context?: any): void; + private removeCallback; + private removeAllCallbacks; +} diff --git a/types/src/core/events/callback_table.d.ts b/types/src/core/events/callback_table.d.ts new file mode 100644 index 000000000..6445294c2 --- /dev/null +++ b/types/src/core/events/callback_table.d.ts @@ -0,0 +1,5 @@ +import Callback from './callback'; +interface CallbackTable { + [index: string]: Callback[]; +} +export default CallbackTable; diff --git a/types/src/core/events/dispatcher.d.ts b/types/src/core/events/dispatcher.d.ts new file mode 100644 index 000000000..e2c681dfd --- /dev/null +++ b/types/src/core/events/dispatcher.d.ts @@ -0,0 +1,14 @@ +import Metadata from '../channels/metadata'; +import CallbackRegistry from './callback_registry'; +export default class Dispatcher { + callbacks: CallbackRegistry; + global_callbacks: Function[]; + failThrough: Function; + constructor(failThrough?: Function); + bind(eventName: string, callback: Function, context?: any): this; + bind_global(callback: Function): this; + unbind(eventName?: string, callback?: Function, context?: any): this; + unbind_global(callback?: Function): this; + unbind_all(): this; + emit(eventName: string, data?: any, metadata?: Metadata): Dispatcher; +} diff --git a/types/src/core/http/ajax.d.ts b/types/src/core/http/ajax.d.ts new file mode 100644 index 000000000..e0dd6fcb7 --- /dev/null +++ b/types/src/core/http/ajax.d.ts @@ -0,0 +1,16 @@ +interface Ajax { + open(method: string, url: string, async?: boolean, user?: string, password?: string): void; + send(payload?: any): void; + setRequestHeader(key: string, value: string): void; + onreadystatechange: Function; + readyState: number; + responseText: string; + status: number; + withCredentials?: boolean; + ontimeout: Function; + onerror: Function; + onprogress: Function; + onload: Function; + abort: Function; +} +export default Ajax; diff --git a/types/src/core/http/http_factory.d.ts b/types/src/core/http/http_factory.d.ts new file mode 100644 index 000000000..8af8b0e16 --- /dev/null +++ b/types/src/core/http/http_factory.d.ts @@ -0,0 +1,13 @@ +import HTTPSocket from './http_socket'; +import SocketHooks from './socket_hooks'; +import HTTPRequest from './http_request'; +import RequestHooks from './request_hooks'; +interface HTTPFactory { + createStreamingSocket(url: string): HTTPSocket; + createPollingSocket(url: string): HTTPSocket; + createSocket(hooks: SocketHooks, url: string): HTTPSocket; + createXHR(method: string, url: string): HTTPRequest; + createXDR?(method: string, url: string): HTTPRequest; + createRequest(hooks: RequestHooks, method: string, url: string): HTTPRequest; +} +export default HTTPFactory; diff --git a/types/src/core/http/http_polling_socket.d.ts b/types/src/core/http/http_polling_socket.d.ts new file mode 100644 index 000000000..d40020737 --- /dev/null +++ b/types/src/core/http/http_polling_socket.d.ts @@ -0,0 +1,3 @@ +import SocketHooks from './socket_hooks'; +declare var hooks: SocketHooks; +export default hooks; diff --git a/types/src/core/http/http_request.d.ts b/types/src/core/http/http_request.d.ts new file mode 100644 index 000000000..38587f11e --- /dev/null +++ b/types/src/core/http/http_request.d.ts @@ -0,0 +1,17 @@ +import RequestHooks from './request_hooks'; +import Ajax from './ajax'; +import { default as EventsDispatcher } from '../events/dispatcher'; +export default class HTTPRequest extends EventsDispatcher { + hooks: RequestHooks; + method: string; + url: string; + position: number; + xhr: Ajax; + unloader: Function; + constructor(hooks: RequestHooks, method: string, url: string); + start(payload?: any): void; + close(): void; + onChunk(status: number, data: any): void; + private advanceBuffer; + private isBufferTooLong; +} diff --git a/types/src/core/http/http_socket.d.ts b/types/src/core/http/http_socket.d.ts new file mode 100644 index 000000000..f0222b8d2 --- /dev/null +++ b/types/src/core/http/http_socket.d.ts @@ -0,0 +1,32 @@ +import URLLocation from './url_location'; +import State from './state'; +import Socket from '../socket'; +import SocketHooks from './socket_hooks'; +import HTTPRequest from './http_request'; +declare class HTTPSocket implements Socket { + hooks: SocketHooks; + session: string; + location: URLLocation; + readyState: State; + stream: HTTPRequest; + onopen: () => void; + onerror: (error: any) => void; + onclose: (closeEvent: any) => void; + onmessage: (message: any) => void; + onactivity: () => void; + constructor(hooks: SocketHooks, url: string); + send(payload: any): boolean; + ping(): void; + close(code: any, reason: any): void; + sendRaw(payload: any): boolean; + reconnect(): void; + onClose(code: any, reason: any, wasClean: any): void; + private onChunk; + private onOpen; + private onEvent; + private onActivity; + private onError; + private openStream; + private closeStream; +} +export default HTTPSocket; diff --git a/types/src/core/http/http_streaming_socket.d.ts b/types/src/core/http/http_streaming_socket.d.ts new file mode 100644 index 000000000..d40020737 --- /dev/null +++ b/types/src/core/http/http_streaming_socket.d.ts @@ -0,0 +1,3 @@ +import SocketHooks from './socket_hooks'; +declare var hooks: SocketHooks; +export default hooks; diff --git a/types/src/core/http/request_hooks.d.ts b/types/src/core/http/request_hooks.d.ts new file mode 100644 index 000000000..988afdb76 --- /dev/null +++ b/types/src/core/http/request_hooks.d.ts @@ -0,0 +1,6 @@ +import Ajax from './ajax'; +interface RequestHooks { + getRequest(HTTPRequest: any): Ajax; + abortRequest(HTTPRequest: any): void; +} +export default RequestHooks; diff --git a/types/src/core/http/socket_hooks.d.ts b/types/src/core/http/socket_hooks.d.ts new file mode 100644 index 000000000..70edfaedc --- /dev/null +++ b/types/src/core/http/socket_hooks.d.ts @@ -0,0 +1,8 @@ +import URLLocation from './url_location'; +interface SocketHooks { + getReceiveURL(url: URLLocation, session: string): string; + onHeartbeat(Socket: any): void; + sendHeartbeat(Socket: any): void; + onFinished(Socket: any, Status: any): void; +} +export default SocketHooks; diff --git a/types/src/core/http/state.d.ts b/types/src/core/http/state.d.ts new file mode 100644 index 000000000..d92f1bbc1 --- /dev/null +++ b/types/src/core/http/state.d.ts @@ -0,0 +1,6 @@ +declare enum State { + CONNECTING = 0, + OPEN = 1, + CLOSED = 3 +} +export default State; diff --git a/types/src/core/http/url_location.d.ts b/types/src/core/http/url_location.d.ts new file mode 100644 index 000000000..c3d2d6497 --- /dev/null +++ b/types/src/core/http/url_location.d.ts @@ -0,0 +1,5 @@ +interface URLLocation { + base: string; + queryString: string; +} +export default URLLocation; diff --git a/types/src/core/index.d.ts b/types/src/core/index.d.ts new file mode 100644 index 000000000..e10b4ecae --- /dev/null +++ b/types/src/core/index.d.ts @@ -0,0 +1,6 @@ + +import Pusher from './pusher' +import { Options } from './options' + +export { Options } +export default Pusher diff --git a/types/src/core/logger.d.ts b/types/src/core/logger.d.ts new file mode 100644 index 000000000..1910d2861 --- /dev/null +++ b/types/src/core/logger.d.ts @@ -0,0 +1,11 @@ +declare class Logger { + debug(...args: any[]): void; + warn(...args: any[]): void; + error(...args: any[]): void; + private globalLog; + private globalLogWarn; + private globalLogError; + private log; +} +declare const _default: Logger; +export default _default; diff --git a/types/src/core/options.d.ts b/types/src/core/options.d.ts new file mode 100644 index 000000000..ed79af525 --- /dev/null +++ b/types/src/core/options.d.ts @@ -0,0 +1,43 @@ +import { AuthOptions, AuthorizerGenerator } from './auth/options'; +export interface PusherOptions { + cluster: string; + disableStats: boolean; + statsHost: string; + activity_timeout: number; + pong_timeout: number; + unavailable_timeout: number; + forceTLS: boolean; + encrypted: boolean; + timelineParams: any; + authTransport: 'ajax' | 'jsonp'; + auth: AuthOptions; + authorizer: AuthorizerGenerator; +} +declare type Transport = 'ws' | 'wss' | 'xhr_streaming' | 'xhr_polling' | 'sockjs'; +declare type AuthTransport = 'ajax' | 'jsonp'; +export interface Options { + activityTimeout?: number; + disableStats?: boolean; + authEndpoint?: string; + auth?: AuthOptions; + authTransport?: AuthTransport; + authorizer?: AuthorizerGenerator; + disabledTransports?: Transport[]; + enabledTransports?: Transport[]; + encrypted?: boolean; + forceTLS?: boolean; + ignoreNullOrigin?: boolean; + pongTimeout?: number; + statsHost?: string; + timelineParams?: any; + unavailable_timeout?: number; + cluster?: string; + wsHost?: string; + httpHost?: string; + wsPath?: string; + wsPort?: number; + wssPort?: number; + httpPort?: number; + httpsPort?: number; +} +export {}; diff --git a/types/src/core/pusher.d.ts b/types/src/core/pusher.d.ts new file mode 100644 index 000000000..2e03c4475 --- /dev/null +++ b/types/src/core/pusher.d.ts @@ -0,0 +1,45 @@ +import AbstractRuntime from 'runtimes/interface'; +import Channels from './channels/channels'; +import Channel from './channels/channel'; +import { default as EventsDispatcher } from './events/dispatcher'; +import Timeline from './timeline/timeline'; +import TimelineSender from './timeline/timeline_sender'; +import ConnectionManager from './connection/connection_manager'; +import { PeriodicTimer } from './utils/timers'; +import { PusherOptions, Options } from './options'; +export default class Pusher { + static instances: Pusher[]; + static isReady: boolean; + static logToConsole: boolean; + static Runtime: AbstractRuntime; + static ScriptReceivers: any; + static DependenciesReceivers: any; + static auth_callbacks: any; + static ready(): void; + static log: (message: any) => void; + private static getClientFeatures; + key: string; + config: PusherOptions; + channels: Channels; + global_emitter: EventsDispatcher; + sessionID: number; + timeline: Timeline; + timelineSender: TimelineSender; + connection: ConnectionManager; + timelineSenderTimer: PeriodicTimer; + constructor(app_key: string, options: Options); + channel(name: string): Channel; + allChannels(): Channel[]; + connect(): void; + disconnect(): void; + bind(event_name: string, callback: Function, context?: any): Pusher; + unbind(event_name?: string, callback?: Function, context?: any): Pusher; + bind_global(callback: Function): Pusher; + unbind_global(callback?: Function): Pusher; + unbind_all(callback?: Function): Pusher; + subscribeAll(): void; + subscribe(channel_name: string): Channel; + unsubscribe(channel_name: string): void; + send_event(event_name: string, data: any, channel?: string): boolean; + shouldUseTLS(): boolean; +} diff --git a/types/src/core/reachability.d.ts b/types/src/core/reachability.d.ts new file mode 100644 index 000000000..daa979594 --- /dev/null +++ b/types/src/core/reachability.d.ts @@ -0,0 +1,5 @@ +import { default as EventsDispatcher } from './events/dispatcher'; +interface Reachability extends EventsDispatcher { + isOnline(): boolean; +} +export default Reachability; diff --git a/types/src/core/socket.d.ts b/types/src/core/socket.d.ts new file mode 100644 index 000000000..279e158ce --- /dev/null +++ b/types/src/core/socket.d.ts @@ -0,0 +1,12 @@ +interface Socket { + send(payload: any): void; + ping?(): void; + close(code?: any, reason?: any): any; + sendRaw?(payload: any): boolean; + onopen?(evt?: any): void; + onerror?(error: any): void; + onclose?(closeEvent: any): void; + onmessage?(message: any): void; + onactivity?(): void; +} +export default Socket; diff --git a/types/src/core/strategies/best_connected_ever_strategy.d.ts b/types/src/core/strategies/best_connected_ever_strategy.d.ts new file mode 100644 index 000000000..15708b8a8 --- /dev/null +++ b/types/src/core/strategies/best_connected_ever_strategy.d.ts @@ -0,0 +1,10 @@ +import Strategy from './strategy'; +export default class BestConnectedEverStrategy implements Strategy { + strategies: Strategy[]; + constructor(strategies: Strategy[]); + isSupported(): boolean; + connect(minPriority: number, callback: Function): { + abort: () => void; + forceMinPriority: (p: any) => void; + }; +} diff --git a/types/src/core/strategies/cached_strategy.d.ts b/types/src/core/strategies/cached_strategy.d.ts new file mode 100644 index 000000000..cbfd9d2aa --- /dev/null +++ b/types/src/core/strategies/cached_strategy.d.ts @@ -0,0 +1,20 @@ +import Strategy from './strategy'; +import StrategyOptions from './strategy_options'; +import TransportStrategy from './transport_strategy'; +import Timeline from '../timeline/timeline'; +export interface TransportStrategyDictionary { + [key: string]: TransportStrategy; +} +export default class CachedStrategy implements Strategy { + strategy: Strategy; + transports: TransportStrategyDictionary; + ttl: number; + usingTLS: boolean; + timeline: Timeline; + constructor(strategy: Strategy, transports: TransportStrategyDictionary, options: StrategyOptions); + isSupported(): boolean; + connect(minPriority: number, callback: Function): { + abort: () => void; + forceMinPriority: (p: any) => void; + }; +} diff --git a/types/src/core/strategies/delayed_strategy.d.ts b/types/src/core/strategies/delayed_strategy.d.ts new file mode 100644 index 000000000..dc97c854d --- /dev/null +++ b/types/src/core/strategies/delayed_strategy.d.ts @@ -0,0 +1,15 @@ +import Strategy from './strategy'; +export default class DelayedStrategy implements Strategy { + strategy: Strategy; + options: { + delay: number; + }; + constructor(strategy: Strategy, { delay: number }: { + delay: any; + }); + isSupported(): boolean; + connect(minPriority: number, callback: Function): { + abort: () => void; + forceMinPriority: (p: any) => void; + }; +} diff --git a/types/src/core/strategies/first_connected_strategy.d.ts b/types/src/core/strategies/first_connected_strategy.d.ts new file mode 100644 index 000000000..8f89cb1da --- /dev/null +++ b/types/src/core/strategies/first_connected_strategy.d.ts @@ -0,0 +1,8 @@ +import Strategy from './strategy'; +import StrategyRunner from './strategy_runner'; +export default class FirstConnectedStrategy implements Strategy { + strategy: Strategy; + constructor(strategy: Strategy); + isSupported(): boolean; + connect(minPriority: number, callback: Function): StrategyRunner; +} diff --git a/types/src/core/strategies/if_strategy.d.ts b/types/src/core/strategies/if_strategy.d.ts new file mode 100644 index 000000000..f7396602c --- /dev/null +++ b/types/src/core/strategies/if_strategy.d.ts @@ -0,0 +1,10 @@ +import Strategy from './strategy'; +import StrategyRunner from './strategy_runner'; +export default class IfStrategy implements Strategy { + test: () => boolean; + trueBranch: Strategy; + falseBranch: Strategy; + constructor(test: () => boolean, trueBranch: Strategy, falseBranch: Strategy); + isSupported(): boolean; + connect(minPriority: number, callback: Function): StrategyRunner; +} diff --git a/types/src/core/strategies/sequential_strategy.d.ts b/types/src/core/strategies/sequential_strategy.d.ts new file mode 100644 index 000000000..8c36ae8a2 --- /dev/null +++ b/types/src/core/strategies/sequential_strategy.d.ts @@ -0,0 +1,16 @@ +import Strategy from './strategy'; +import StrategyOptions from './strategy_options'; +export default class SequentialStrategy implements Strategy { + strategies: Strategy[]; + loop: boolean; + failFast: boolean; + timeout: number; + timeoutLimit: number; + constructor(strategies: Strategy[], options: StrategyOptions); + isSupported(): boolean; + connect(minPriority: number, callback: Function): { + abort: () => void; + forceMinPriority: (p: any) => void; + }; + private tryStrategy; +} diff --git a/types/src/core/strategies/strategy.d.ts b/types/src/core/strategies/strategy.d.ts new file mode 100644 index 000000000..c04379488 --- /dev/null +++ b/types/src/core/strategies/strategy.d.ts @@ -0,0 +1,6 @@ +import StrategyRunner from './strategy_runner'; +interface Strategy { + isSupported(): boolean; + connect(minPriority: number, callback: Function): StrategyRunner; +} +export default Strategy; diff --git a/types/src/core/strategies/strategy_builder.d.ts b/types/src/core/strategies/strategy_builder.d.ts new file mode 100644 index 000000000..2449c0a25 --- /dev/null +++ b/types/src/core/strategies/strategy_builder.d.ts @@ -0,0 +1,3 @@ +import TransportManager from '../transports/transport_manager'; +import Strategy from './strategy'; +export declare var defineTransport: (config: any, name: string, type: string, priority: number, options: any, manager?: TransportManager) => Strategy; diff --git a/types/src/core/strategies/strategy_options.d.ts b/types/src/core/strategies/strategy_options.d.ts new file mode 100644 index 000000000..bd94b7d26 --- /dev/null +++ b/types/src/core/strategies/strategy_options.d.ts @@ -0,0 +1,12 @@ +interface StrategyOptions { + ttl?: number; + timeline?: any; + useTLS?: boolean; + ignoreNullOrigin?: boolean; + loop?: boolean; + failFast?: boolean; + timeout?: number; + timeoutLimit?: number; + key?: string; +} +export default StrategyOptions; diff --git a/types/src/core/strategies/strategy_runner.d.ts b/types/src/core/strategies/strategy_runner.d.ts new file mode 100644 index 000000000..bc8fe1bae --- /dev/null +++ b/types/src/core/strategies/strategy_runner.d.ts @@ -0,0 +1,5 @@ +interface StrategyRunner { + forceMinPriority: (number: any) => void; + abort: () => void; +} +export default StrategyRunner; diff --git a/types/src/core/strategies/transport_strategy.d.ts b/types/src/core/strategies/transport_strategy.d.ts new file mode 100644 index 000000000..0a9c36f41 --- /dev/null +++ b/types/src/core/strategies/transport_strategy.d.ts @@ -0,0 +1,15 @@ +import Strategy from './strategy'; +import Transport from '../transports/transport'; +import StrategyOptions from './strategy_options'; +export default class TransportStrategy implements Strategy { + name: string; + priority: number; + transport: Transport; + options: StrategyOptions; + constructor(name: string, priority: number, transport: Transport, options: StrategyOptions); + isSupported(): boolean; + connect(minPriority: number, callback: Function): { + abort: () => void; + forceMinPriority: (p: any) => void; + }; +} diff --git a/types/src/core/timeline/level.d.ts b/types/src/core/timeline/level.d.ts new file mode 100644 index 000000000..31d4f566e --- /dev/null +++ b/types/src/core/timeline/level.d.ts @@ -0,0 +1,6 @@ +declare enum TimelineLevel { + ERROR = 3, + INFO = 6, + DEBUG = 7 +} +export default TimelineLevel; diff --git a/types/src/core/timeline/timeline.d.ts b/types/src/core/timeline/timeline.d.ts new file mode 100644 index 000000000..d7d9009af --- /dev/null +++ b/types/src/core/timeline/timeline.d.ts @@ -0,0 +1,25 @@ +import { default as Level } from './level'; +export interface TimelineOptions { + level?: Level; + limit?: number; + version?: string; + cluster?: string; + features?: string[]; + params?: any; +} +export default class Timeline { + key: string; + session: number; + events: any[]; + options: TimelineOptions; + sent: number; + uniqueID: number; + constructor(key: string, session: number, options: TimelineOptions); + log(level: any, event: any): void; + error(event: any): void; + info(event: any): void; + debug(event: any): void; + isEmpty(): boolean; + send(sendfn: any, callback: any): boolean; + generateUniqueID(): number; +} diff --git a/types/src/core/timeline/timeline_sender.d.ts b/types/src/core/timeline/timeline_sender.d.ts new file mode 100644 index 000000000..1e4b3bf61 --- /dev/null +++ b/types/src/core/timeline/timeline_sender.d.ts @@ -0,0 +1,13 @@ +import Timeline from './timeline'; +export interface TimelineSenderOptions { + host?: string; + port?: number; + path?: string; +} +export default class TimelineSender { + timeline: Timeline; + options: TimelineSenderOptions; + host: string; + constructor(timeline: Timeline, options: TimelineSenderOptions); + send(useTLS: boolean, callback?: Function): void; +} diff --git a/types/src/core/timeline/timeline_transport.d.ts b/types/src/core/timeline/timeline_transport.d.ts new file mode 100644 index 000000000..54173b16f --- /dev/null +++ b/types/src/core/timeline/timeline_transport.d.ts @@ -0,0 +1,6 @@ +import TimelineSender from 'core/timeline/timeline_sender'; +interface TimelineTransport { + name: string; + getAgent: (sender: TimelineSender, useTLS: boolean) => (data: any, callback: Function) => void; +} +export default TimelineTransport; diff --git a/types/src/core/transports/assistant_to_the_transport_manager.d.ts b/types/src/core/transports/assistant_to_the_transport_manager.d.ts new file mode 100644 index 000000000..4c0b6f1f3 --- /dev/null +++ b/types/src/core/transports/assistant_to_the_transport_manager.d.ts @@ -0,0 +1,14 @@ +import TransportManager from './transport_manager'; +import TransportConnection from './transport_connection'; +import Transport from './transport'; +import PingDelayOptions from './ping_delay_options'; +export default class AssistantToTheTransportManager { + manager: TransportManager; + transport: Transport; + minPingDelay: number; + maxPingDelay: number; + pingDelay: number; + constructor(manager: TransportManager, transport: Transport, options: PingDelayOptions); + createConnection(name: string, priority: number, key: string, options: Object): TransportConnection; + isSupported(environment: string): boolean; +} diff --git a/types/src/core/transports/ping_delay_options.d.ts b/types/src/core/transports/ping_delay_options.d.ts new file mode 100644 index 000000000..c52772ad6 --- /dev/null +++ b/types/src/core/transports/ping_delay_options.d.ts @@ -0,0 +1,6 @@ +interface PingDelayOptions { + minPingDelay?: number; + maxPingDelay?: number; + pingDelay?: number; +} +export default PingDelayOptions; diff --git a/types/src/core/transports/transport.d.ts b/types/src/core/transports/transport.d.ts new file mode 100644 index 000000000..f33da3b2c --- /dev/null +++ b/types/src/core/transports/transport.d.ts @@ -0,0 +1,8 @@ +import TransportHooks from './transport_hooks'; +import TransportConnection from './transport_connection'; +export default class Transport { + hooks: TransportHooks; + constructor(hooks: TransportHooks); + isSupported(environment: any): boolean; + createConnection(name: string, priority: number, key: string, options: any): TransportConnection; +} diff --git a/types/src/core/transports/transport_connection.d.ts b/types/src/core/transports/transport_connection.d.ts new file mode 100644 index 000000000..88f68188e --- /dev/null +++ b/types/src/core/transports/transport_connection.d.ts @@ -0,0 +1,35 @@ +import { default as EventsDispatcher } from '../events/dispatcher'; +import TransportHooks from './transport_hooks'; +import Socket from '../socket'; +import Timeline from '../timeline/timeline'; +import TransportConnectionOptions from './transport_connection_options'; +export default class TransportConnection extends EventsDispatcher { + hooks: TransportHooks; + name: string; + priority: number; + key: string; + options: TransportConnectionOptions; + state: string; + timeline: Timeline; + activityTimeout: number; + id: number; + socket: Socket; + beforeOpen: Function; + initialize: Function; + constructor(hooks: TransportHooks, name: string, priority: number, key: string, options: TransportConnectionOptions); + handlesActivityChecks(): boolean; + supportsPing(): boolean; + connect(): boolean; + close(): boolean; + send(data: any): boolean; + ping(): void; + private onOpen; + private onError; + private onClose; + private onMessage; + private onActivity; + private bindListeners; + private unbindListeners; + private changeState; + buildTimelineMessage(message: any): any; +} diff --git a/types/src/core/transports/transport_connection_options.d.ts b/types/src/core/transports/transport_connection_options.d.ts new file mode 100644 index 000000000..4825bf498 --- /dev/null +++ b/types/src/core/transports/transport_connection_options.d.ts @@ -0,0 +1,6 @@ +import Timeline from '../timeline/timeline'; +interface TransportConnectionOptions { + timeline: Timeline; + activityTimeout: number; +} +export default TransportConnectionOptions; diff --git a/types/src/core/transports/transport_hooks.d.ts b/types/src/core/transports/transport_hooks.d.ts new file mode 100644 index 000000000..4468655dc --- /dev/null +++ b/types/src/core/transports/transport_hooks.d.ts @@ -0,0 +1,13 @@ +import URLScheme from './url_scheme'; +import Socket from '../socket'; +interface TransportHooks { + file?: string; + urls: URLScheme; + handlesActivityChecks: boolean; + supportsPing: boolean; + isInitialized(): boolean; + isSupported(environment?: any): boolean; + getSocket(url: string, options?: any): Socket; + beforeOpen?: Function; +} +export default TransportHooks; diff --git a/types/src/core/transports/transport_manager.d.ts b/types/src/core/transports/transport_manager.d.ts new file mode 100644 index 000000000..8fb17dfc3 --- /dev/null +++ b/types/src/core/transports/transport_manager.d.ts @@ -0,0 +1,14 @@ +import AssistantToTheTransportManager from './assistant_to_the_transport_manager'; +import Transport from './transport'; +import PingDelayOptions from './ping_delay_options'; +export interface TransportManagerOptions extends PingDelayOptions { + lives?: number; +} +export default class TransportManager { + options: TransportManagerOptions; + livesLeft: number; + constructor(options: TransportManagerOptions); + getAssistant(transport: Transport): AssistantToTheTransportManager; + isAlive(): boolean; + reportDeath(): void; +} diff --git a/types/src/core/transports/transports_table.d.ts b/types/src/core/transports/transports_table.d.ts new file mode 100644 index 000000000..be27e8ee8 --- /dev/null +++ b/types/src/core/transports/transports_table.d.ts @@ -0,0 +1,10 @@ +import Transport from './transport'; +interface TransportsTable { + ws: Transport; + xhr_streaming: Transport; + xdr_streaming?: Transport; + xhr_polling: Transport; + xdr_polling?: Transport; + sockjs?: Transport; +} +export default TransportsTable; diff --git a/types/src/core/transports/url_scheme.d.ts b/types/src/core/transports/url_scheme.d.ts new file mode 100644 index 000000000..4435d14f3 --- /dev/null +++ b/types/src/core/transports/url_scheme.d.ts @@ -0,0 +1,11 @@ +export interface URLSchemeParams { + useTLS: boolean; + hostTLS: string; + hostNonTLS: string; + httpPath: string; +} +interface URLScheme { + getInitial(key: string, params: any): string; + getPath?(key: string, options: any): string; +} +export default URLScheme; diff --git a/types/src/core/transports/url_schemes.d.ts b/types/src/core/transports/url_schemes.d.ts new file mode 100644 index 000000000..14e94b359 --- /dev/null +++ b/types/src/core/transports/url_schemes.d.ts @@ -0,0 +1,4 @@ +import { default as URLScheme } from './url_scheme'; +export declare var ws: URLScheme; +export declare var http: URLScheme; +export declare var sockjs: URLScheme; diff --git a/types/src/core/util.d.ts b/types/src/core/util.d.ts new file mode 100644 index 000000000..42df50091 --- /dev/null +++ b/types/src/core/util.d.ts @@ -0,0 +1,8 @@ +import TimedCallback from './utils/timers/timed_callback'; +import { OneOffTimer } from './utils/timers'; +declare var Util: { + now(): number; + defer(callback: TimedCallback): OneOffTimer; + method(name: string, ...args: any[]): Function; +}; +export default Util; diff --git a/types/src/core/utils/collections.d.ts b/types/src/core/utils/collections.d.ts new file mode 100644 index 000000000..4e7aa1523 --- /dev/null +++ b/types/src/core/utils/collections.d.ts @@ -0,0 +1,18 @@ +export declare function extend(target: any, ...sources: any[]): T; +export declare function stringify(): string; +export declare function arrayIndexOf(array: any[], item: any): number; +export declare function objectApply(object: any, f: Function): void; +export declare function keys(object: any): string[]; +export declare function values(object: any): any[]; +export declare function apply(array: any[], f: Function, context?: any): void; +export declare function map(array: any[], f: Function): any[]; +export declare function mapObject(object: any, f: Function): any; +export declare function filter(array: any[], test: Function): any[]; +export declare function filterObject(object: Object, test: Function): {}; +export declare function flatten(object: Object): any[]; +export declare function any(array: any[], test: Function): boolean; +export declare function all(array: any[], test: Function): boolean; +export declare function encodeParamsObject(data: any): string; +export declare function buildQueryString(data: any): string; +export declare function decycleObject(object: any): any; +export declare function safeJSONStringify(source: any): string; diff --git a/types/src/core/utils/factory.d.ts b/types/src/core/utils/factory.d.ts new file mode 100644 index 000000000..238e90f0d --- /dev/null +++ b/types/src/core/utils/factory.d.ts @@ -0,0 +1,30 @@ +import AssistantToTheTransportManager from '../transports/assistant_to_the_transport_manager'; +import PingDelayOptions from '../transports/ping_delay_options'; +import Transport from '../transports/transport'; +import TransportManager from '../transports/transport_manager'; +import Handshake from '../connection/handshake'; +import TransportConnection from '../transports/transport_connection'; +import { AuthorizerOptions, Authorizer } from '../auth/options'; +import Timeline from '../timeline/timeline'; +import { default as TimelineSender, TimelineSenderOptions } from '../timeline/timeline_sender'; +import PresenceChannel from '../channels/presence_channel'; +import PrivateChannel from '../channels/private_channel'; +import EncryptedChannel from '../channels/encrypted_channel'; +import Channel from '../channels/channel'; +import ConnectionManager from '../connection/connection_manager'; +import ConnectionManagerOptions from '../connection/connection_manager_options'; +import Channels from '../channels/channels'; +import Pusher from '../pusher'; +declare var Factory: { + createChannels(): Channels; + createConnectionManager(key: string, options: ConnectionManagerOptions): ConnectionManager; + createChannel(name: string, pusher: Pusher): Channel; + createPrivateChannel(name: string, pusher: Pusher): PrivateChannel; + createPresenceChannel(name: string, pusher: Pusher): PresenceChannel; + createEncryptedChannel(name: string, pusher: Pusher): EncryptedChannel; + createTimelineSender(timeline: Timeline, options: TimelineSenderOptions): TimelineSender; + createAuthorizer(channel: Channel, options: AuthorizerOptions): Authorizer; + createHandshake(transport: TransportConnection, callback: (HandshakePayload: any) => void): Handshake; + createAssistantToTheTransportManager(manager: TransportManager, transport: Transport, options: PingDelayOptions): AssistantToTheTransportManager; +}; +export default Factory; diff --git a/types/src/core/utils/timers/abstract_timer.d.ts b/types/src/core/utils/timers/abstract_timer.d.ts new file mode 100644 index 000000000..53bdea17b --- /dev/null +++ b/types/src/core/utils/timers/abstract_timer.d.ts @@ -0,0 +1,10 @@ +import TimedCallback from './timed_callback'; +import { Delay, Scheduler, Canceller } from './scheduling'; +declare abstract class Timer { + protected clear: Canceller; + protected timer: number | void; + constructor(set: Scheduler, clear: Canceller, delay: Delay, callback: TimedCallback); + isRunning(): boolean; + ensureAborted(): void; +} +export default Timer; diff --git a/types/src/core/utils/timers/index.d.ts b/types/src/core/utils/timers/index.d.ts new file mode 100644 index 000000000..8254ff034 --- /dev/null +++ b/types/src/core/utils/timers/index.d.ts @@ -0,0 +1,9 @@ +import Timer from './abstract_timer'; +import TimedCallback from './timed_callback'; +import { Delay } from './scheduling'; +export declare class OneOffTimer extends Timer { + constructor(delay: Delay, callback: TimedCallback); +} +export declare class PeriodicTimer extends Timer { + constructor(delay: Delay, callback: TimedCallback); +} diff --git a/types/src/core/utils/timers/scheduling.d.ts b/types/src/core/utils/timers/scheduling.d.ts new file mode 100644 index 000000000..bab076e8b --- /dev/null +++ b/types/src/core/utils/timers/scheduling.d.ts @@ -0,0 +1,8 @@ +interface Scheduler { + (TimedCallback: any, number: any): number; +} +interface Canceller { + (number: any): void; +} +declare type Delay = number; +export { Scheduler, Canceller, Delay }; diff --git a/types/src/core/utils/timers/timed_callback.d.ts b/types/src/core/utils/timers/timed_callback.d.ts new file mode 100644 index 000000000..b90ca5c2c --- /dev/null +++ b/types/src/core/utils/timers/timed_callback.d.ts @@ -0,0 +1,4 @@ +interface TimedCallback { + (number?: any): number | void; +} +export default TimedCallback; diff --git a/types/src/core/utils/url_store.d.ts b/types/src/core/utils/url_store.d.ts new file mode 100644 index 000000000..caa2cee8d --- /dev/null +++ b/types/src/core/utils/url_store.d.ts @@ -0,0 +1,4 @@ +declare const _default: { + buildLogSuffix: (key: string) => string; +}; +export default _default; diff --git a/types/src/runtimes/interface.d.ts b/types/src/runtimes/interface.d.ts new file mode 100644 index 000000000..4e6631f27 --- /dev/null +++ b/types/src/runtimes/interface.d.ts @@ -0,0 +1,40 @@ +import { AuthTransports } from 'core/auth/auth_transports'; +import TimelineTransport from 'core/timeline/timeline_transport'; +import Ajax from 'core/http/ajax'; +import Reachability from 'core/reachability'; +import TransportsTable from 'core/transports/transports_table'; +import Socket from 'core/socket'; +import HTTPFactory from 'core/http/http_factory'; +import HTTPRequest from 'core/http/http_request'; +import Pusher from 'core/pusher'; +import JSONPRequest from './web/dom/jsonp_request'; +import Strategy from 'core/strategies/strategy'; +interface Runtime { + setup(PusherClass: { + new (key: string, options: any): Pusher; + ready(): void; + }): void; + getProtocol(): string; + getAuthorizers(): AuthTransports; + getLocalStorage(): any; + TimelineTransport: TimelineTransport; + createXHR(): Ajax; + createWebSocket(url: string): Socket; + getNetwork(): Reachability; + getDefaultStrategy(config: any, defineTransport: Function): Strategy; + Transports: TransportsTable; + getWebSocketAPI(): new (url: string) => Socket; + getXHRAPI(): new () => Ajax; + addUnloadListener(listener: Function): void; + removeUnloadListener(listener: Function): void; + transportConnectionInitializer: Function; + HTTPFactory: HTTPFactory; + isXHRSupported(): boolean; + createSocketRequest(method: string, url: string): HTTPRequest; + getDocument?(): Document; + createScriptRequest?(url: string): any; + createJSONPRequest?(url: string, data: any): JSONPRequest; + ScriptReceivers?: any; + isXDRSupported?(useTLS?: boolean): boolean; +} +export default Runtime; diff --git a/types/src/runtimes/isomorphic/auth/xhr_auth.d.ts b/types/src/runtimes/isomorphic/auth/xhr_auth.d.ts new file mode 100644 index 000000000..6af57025f --- /dev/null +++ b/types/src/runtimes/isomorphic/auth/xhr_auth.d.ts @@ -0,0 +1,3 @@ +import { AuthTransport } from 'core/auth/auth_transports'; +declare var ajax: AuthTransport; +export default ajax; diff --git a/types/src/runtimes/isomorphic/default_strategy.d.ts b/types/src/runtimes/isomorphic/default_strategy.d.ts new file mode 100644 index 000000000..3225978a8 --- /dev/null +++ b/types/src/runtimes/isomorphic/default_strategy.d.ts @@ -0,0 +1,3 @@ +import Strategy from 'core/strategies/strategy'; +declare var getDefaultStrategy: (config: any, defineTransport: Function) => Strategy; +export default getDefaultStrategy; diff --git a/types/src/runtimes/isomorphic/http/http.d.ts b/types/src/runtimes/isomorphic/http/http.d.ts new file mode 100644 index 000000000..416a3c323 --- /dev/null +++ b/types/src/runtimes/isomorphic/http/http.d.ts @@ -0,0 +1,3 @@ +import HTTPFactory from 'core/http/http_factory'; +declare var HTTP: HTTPFactory; +export default HTTP; diff --git a/types/src/runtimes/isomorphic/http/http_xhr_request.d.ts b/types/src/runtimes/isomorphic/http/http_xhr_request.d.ts new file mode 100644 index 000000000..24092a16c --- /dev/null +++ b/types/src/runtimes/isomorphic/http/http_xhr_request.d.ts @@ -0,0 +1,3 @@ +import RequestHooks from 'core/http/request_hooks'; +declare var hooks: RequestHooks; +export default hooks; diff --git a/types/src/runtimes/isomorphic/runtime.d.ts b/types/src/runtimes/isomorphic/runtime.d.ts new file mode 100644 index 000000000..0e2dc2df7 --- /dev/null +++ b/types/src/runtimes/isomorphic/runtime.d.ts @@ -0,0 +1,2 @@ +declare var Isomorphic: any; +export default Isomorphic; diff --git a/types/src/runtimes/isomorphic/timeline/xhr_timeline.d.ts b/types/src/runtimes/isomorphic/timeline/xhr_timeline.d.ts new file mode 100644 index 000000000..74fdae634 --- /dev/null +++ b/types/src/runtimes/isomorphic/timeline/xhr_timeline.d.ts @@ -0,0 +1,6 @@ +import TimelineSender from 'core/timeline/timeline_sender'; +declare var xhr: { + name: string; + getAgent: (sender: TimelineSender, useTLS: boolean) => (data: any, callback: Function) => void; +}; +export default xhr; diff --git a/types/src/runtimes/isomorphic/transports/transport_connection_initializer.d.ts b/types/src/runtimes/isomorphic/transports/transport_connection_initializer.d.ts new file mode 100644 index 000000000..399a90f26 --- /dev/null +++ b/types/src/runtimes/isomorphic/transports/transport_connection_initializer.d.ts @@ -0,0 +1 @@ +export default function (): void; diff --git a/types/src/runtimes/isomorphic/transports/transports.d.ts b/types/src/runtimes/isomorphic/transports/transports.d.ts new file mode 100644 index 000000000..13c94259f --- /dev/null +++ b/types/src/runtimes/isomorphic/transports/transports.d.ts @@ -0,0 +1,5 @@ +import TransportsTable from 'core/transports/transports_table'; +export declare var streamingConfiguration: unknown; +export declare var pollingConfiguration: unknown; +declare var Transports: TransportsTable; +export default Transports; diff --git a/types/src/runtimes/node/net_info.d.ts b/types/src/runtimes/node/net_info.d.ts new file mode 100644 index 000000000..7a721d6c2 --- /dev/null +++ b/types/src/runtimes/node/net_info.d.ts @@ -0,0 +1,6 @@ +import { default as EventsDispatcher } from 'core/events/dispatcher'; +import Reachability from 'core/reachability'; +export declare class NetInfo extends EventsDispatcher implements Reachability { + isOnline(): boolean; +} +export declare var Network: NetInfo; diff --git a/types/src/runtimes/node/runtime.d.ts b/types/src/runtimes/node/runtime.d.ts new file mode 100644 index 000000000..58d5c1f10 --- /dev/null +++ b/types/src/runtimes/node/runtime.d.ts @@ -0,0 +1,3 @@ +import Runtime from '../interface'; +declare const NodeJS: Runtime; +export default NodeJS; diff --git a/types/src/runtimes/react-native/net_info.d.ts b/types/src/runtimes/react-native/net_info.d.ts new file mode 100644 index 000000000..e2c4bd5cb --- /dev/null +++ b/types/src/runtimes/react-native/net_info.d.ts @@ -0,0 +1,8 @@ +import EventsDispatcher from 'core/events/dispatcher'; +import Reachability from 'core/reachability'; +export declare class NetInfo extends EventsDispatcher implements Reachability { + online: boolean; + constructor(); + isOnline(): boolean; +} +export declare var Network: NetInfo; diff --git a/types/src/runtimes/react-native/runtime.d.ts b/types/src/runtimes/react-native/runtime.d.ts new file mode 100644 index 000000000..1a9d9eacb --- /dev/null +++ b/types/src/runtimes/react-native/runtime.d.ts @@ -0,0 +1,3 @@ +import Runtime from '../interface'; +declare const ReactNative: Runtime; +export default ReactNative; diff --git a/types/src/runtimes/react-native/tweetnacl-dummy.d.ts b/types/src/runtimes/react-native/tweetnacl-dummy.d.ts new file mode 100644 index 000000000..4619916e5 --- /dev/null +++ b/types/src/runtimes/react-native/tweetnacl-dummy.d.ts @@ -0,0 +1,5 @@ +declare const _default: { + secretbox: {}; + randomBytes: {}; +}; +export default _default; diff --git a/types/src/runtimes/react-native/tweetnacl-util-dummy.d.ts b/types/src/runtimes/react-native/tweetnacl-util-dummy.d.ts new file mode 100644 index 000000000..e44315ba8 --- /dev/null +++ b/types/src/runtimes/react-native/tweetnacl-util-dummy.d.ts @@ -0,0 +1,7 @@ +declare const _default: { + encodeUTF8: {}; + decodeUTF8: {}; + encodeBase64: {}; + decodeBase64: {}; +}; +export default _default; diff --git a/types/src/runtimes/web/auth/jsonp_auth.d.ts b/types/src/runtimes/web/auth/jsonp_auth.d.ts new file mode 100644 index 000000000..a1c126f9c --- /dev/null +++ b/types/src/runtimes/web/auth/jsonp_auth.d.ts @@ -0,0 +1,3 @@ +import { AuthTransport } from 'core/auth/auth_transports'; +declare var jsonp: AuthTransport; +export default jsonp; diff --git a/types/src/runtimes/web/browser.d.ts b/types/src/runtimes/web/browser.d.ts new file mode 100644 index 000000000..135e21b5c --- /dev/null +++ b/types/src/runtimes/web/browser.d.ts @@ -0,0 +1,19 @@ +import AbstractRuntime from 'runtimes/interface'; +import { ScriptReceiverFactory } from './dom/script_receiver_factory'; +import ScriptRequest from './dom/script_request'; +import JSONPRequest from './dom/jsonp_request'; +import Ajax from 'core/http/ajax'; +interface Browser extends AbstractRuntime { + nextAuthCallbackID: number; + auth_callbacks: any; + ScriptReceivers: ScriptReceiverFactory; + DependenciesReceivers: ScriptReceiverFactory; + onDocumentBody(callback: Function): any; + getDocument(): any; + createJSONPRequest(url: string, data: any): JSONPRequest; + createScriptRequest(src: string): ScriptRequest; + isXDRSupported(useTLS?: boolean): boolean; + createXMLHttpRequest(): Ajax; + createMicrosoftXHR(): Ajax; +} +export default Browser; diff --git a/types/src/runtimes/web/default_strategy.d.ts b/types/src/runtimes/web/default_strategy.d.ts new file mode 100644 index 000000000..3225978a8 --- /dev/null +++ b/types/src/runtimes/web/default_strategy.d.ts @@ -0,0 +1,3 @@ +import Strategy from 'core/strategies/strategy'; +declare var getDefaultStrategy: (config: any, defineTransport: Function) => Strategy; +export default getDefaultStrategy; diff --git a/types/src/runtimes/web/dom/dependencies.d.ts b/types/src/runtimes/web/dom/dependencies.d.ts new file mode 100644 index 000000000..18c1a456b --- /dev/null +++ b/types/src/runtimes/web/dom/dependencies.d.ts @@ -0,0 +1,4 @@ +import { ScriptReceiverFactory } from './script_receiver_factory'; +import DependencyLoader from './dependency_loader'; +export declare var DependenciesReceivers: ScriptReceiverFactory; +export declare var Dependencies: DependencyLoader; diff --git a/types/src/runtimes/web/dom/dependency_loader.d.ts b/types/src/runtimes/web/dom/dependency_loader.d.ts new file mode 100644 index 000000000..b5ba7cc2a --- /dev/null +++ b/types/src/runtimes/web/dom/dependency_loader.d.ts @@ -0,0 +1,10 @@ +import { ScriptReceiverFactory } from './script_receiver_factory'; +export default class DependencyLoader { + options: any; + receivers: ScriptReceiverFactory; + loading: any; + constructor(options: any); + load(name: string, options: any, callback: Function): void; + getRoot(options: any): string; + getPath(name: string, options: any): string; +} diff --git a/types/src/runtimes/web/dom/jsonp_request.d.ts b/types/src/runtimes/web/dom/jsonp_request.d.ts new file mode 100644 index 000000000..79dcb5547 --- /dev/null +++ b/types/src/runtimes/web/dom/jsonp_request.d.ts @@ -0,0 +1,10 @@ +import ScriptReceiver from './script_receiver'; +import ScriptRequest from './script_request'; +export default class JSONPRequest { + url: string; + data: any; + request: ScriptRequest; + constructor(url: string, data: any); + send(receiver: ScriptReceiver): void; + cleanup(): void; +} diff --git a/types/src/runtimes/web/dom/script_receiver.d.ts b/types/src/runtimes/web/dom/script_receiver.d.ts new file mode 100644 index 000000000..f1db8144b --- /dev/null +++ b/types/src/runtimes/web/dom/script_receiver.d.ts @@ -0,0 +1,7 @@ +interface ScriptReceiver { + number: number; + id: string; + name: string; + callback: Function; +} +export default ScriptReceiver; diff --git a/types/src/runtimes/web/dom/script_receiver_factory.d.ts b/types/src/runtimes/web/dom/script_receiver_factory.d.ts new file mode 100644 index 000000000..d3ae126a3 --- /dev/null +++ b/types/src/runtimes/web/dom/script_receiver_factory.d.ts @@ -0,0 +1,10 @@ +import ScriptReceiver from './script_receiver'; +export declare class ScriptReceiverFactory { + lastId: number; + prefix: string; + name: string; + constructor(prefix: string, name: string); + create(callback: Function): ScriptReceiver; + remove(receiver: ScriptReceiver): void; +} +export declare var ScriptReceivers: ScriptReceiverFactory; diff --git a/types/src/runtimes/web/dom/script_request.d.ts b/types/src/runtimes/web/dom/script_request.d.ts new file mode 100644 index 000000000..f04435ae9 --- /dev/null +++ b/types/src/runtimes/web/dom/script_request.d.ts @@ -0,0 +1,9 @@ +import ScriptReceiver from './script_receiver'; +export default class ScriptRequest { + src: string; + script: any; + errorScript: any; + constructor(src: string); + send(receiver: ScriptReceiver): void; + cleanup(): void; +} diff --git a/types/src/runtimes/web/http/http.d.ts b/types/src/runtimes/web/http/http.d.ts new file mode 100644 index 000000000..36612edb1 --- /dev/null +++ b/types/src/runtimes/web/http/http.d.ts @@ -0,0 +1,2 @@ +import HTTP from 'isomorphic/http/http'; +export default HTTP; diff --git a/types/src/runtimes/web/http/http_xdomain_request.d.ts b/types/src/runtimes/web/http/http_xdomain_request.d.ts new file mode 100644 index 000000000..24092a16c --- /dev/null +++ b/types/src/runtimes/web/http/http_xdomain_request.d.ts @@ -0,0 +1,3 @@ +import RequestHooks from 'core/http/request_hooks'; +declare var hooks: RequestHooks; +export default hooks; diff --git a/types/src/runtimes/web/net_info.d.ts b/types/src/runtimes/web/net_info.d.ts new file mode 100644 index 000000000..a032f5978 --- /dev/null +++ b/types/src/runtimes/web/net_info.d.ts @@ -0,0 +1,7 @@ +import Reachability from 'core/reachability'; +import { default as EventsDispatcher } from 'core/events/dispatcher'; +export declare class NetInfo extends EventsDispatcher implements Reachability { + constructor(); + isOnline(): boolean; +} +export declare var Network: NetInfo; diff --git a/types/src/runtimes/web/runtime.d.ts b/types/src/runtimes/web/runtime.d.ts new file mode 100644 index 000000000..c71f927f2 --- /dev/null +++ b/types/src/runtimes/web/runtime.d.ts @@ -0,0 +1,3 @@ +import Browser from './browser'; +declare var Runtime: Browser; +export default Runtime; diff --git a/types/src/runtimes/web/timeline/jsonp_timeline.d.ts b/types/src/runtimes/web/timeline/jsonp_timeline.d.ts new file mode 100644 index 000000000..c3fdf06b4 --- /dev/null +++ b/types/src/runtimes/web/timeline/jsonp_timeline.d.ts @@ -0,0 +1,6 @@ +import TimelineSender from 'core/timeline/timeline_sender'; +declare var jsonp: { + name: string; + getAgent: (sender: TimelineSender, useTLS: boolean) => (data: any, callback: Function) => void; +}; +export default jsonp; diff --git a/types/src/runtimes/web/transports/transport_connection_initializer.d.ts b/types/src/runtimes/web/transports/transport_connection_initializer.d.ts new file mode 100644 index 000000000..399a90f26 --- /dev/null +++ b/types/src/runtimes/web/transports/transport_connection_initializer.d.ts @@ -0,0 +1 @@ +export default function (): void; diff --git a/types/src/runtimes/web/transports/transports.d.ts b/types/src/runtimes/web/transports/transports.d.ts new file mode 100644 index 000000000..4f18d423c --- /dev/null +++ b/types/src/runtimes/web/transports/transports.d.ts @@ -0,0 +1,2 @@ +import { default as Transports } from 'isomorphic/transports/transports'; +export default Transports; diff --git a/types/src/runtimes/worker/auth/fetch_auth.d.ts b/types/src/runtimes/worker/auth/fetch_auth.d.ts new file mode 100644 index 000000000..02ff53a2a --- /dev/null +++ b/types/src/runtimes/worker/auth/fetch_auth.d.ts @@ -0,0 +1,3 @@ +import { AuthTransport } from 'core/auth/auth_transports'; +declare var fetchAuth: AuthTransport; +export default fetchAuth; diff --git a/types/src/runtimes/worker/net_info.d.ts b/types/src/runtimes/worker/net_info.d.ts new file mode 100644 index 000000000..7a721d6c2 --- /dev/null +++ b/types/src/runtimes/worker/net_info.d.ts @@ -0,0 +1,6 @@ +import { default as EventsDispatcher } from 'core/events/dispatcher'; +import Reachability from 'core/reachability'; +export declare class NetInfo extends EventsDispatcher implements Reachability { + isOnline(): boolean; +} +export declare var Network: NetInfo; diff --git a/types/src/runtimes/worker/runtime.d.ts b/types/src/runtimes/worker/runtime.d.ts new file mode 100644 index 000000000..d7ce80289 --- /dev/null +++ b/types/src/runtimes/worker/runtime.d.ts @@ -0,0 +1,3 @@ +import Runtime from '../interface'; +declare const Worker: Runtime; +export default Worker; diff --git a/types/src/runtimes/worker/timeline/fetch_timeline.d.ts b/types/src/runtimes/worker/timeline/fetch_timeline.d.ts new file mode 100644 index 000000000..440ec260a --- /dev/null +++ b/types/src/runtimes/worker/timeline/fetch_timeline.d.ts @@ -0,0 +1,6 @@ +import TimelineSender from 'core/timeline/timeline_sender'; +declare var fetchTimeline: { + name: string; + getAgent: (sender: TimelineSender, useTLS: boolean) => (data: any, callback: Function) => void; +}; +export default fetchTimeline; From 2206b72772275e3d3753e5e323322c18470ef763 Mon Sep 17 00:00:00 2001 From: James Lees Date: Wed, 5 Feb 2020 12:05:23 +0000 Subject: [PATCH 2/6] use a real type for the authorizer --- src/core/auth/options.ts | 11 ++++++++++- src/core/auth/pusher_authorizer.ts | 9 ++++----- src/core/channels/channel.ts | 6 ++++-- src/core/channels/encrypted_channel.ts | 3 ++- src/core/channels/presence_channel.ts | 2 ++ src/core/channels/private_channel.ts | 3 ++- src/runtimes/web/auth/jsonp_auth.ts | 3 ++- 7 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/core/auth/options.ts b/src/core/auth/options.ts index 528440053..17a61843a 100644 --- a/src/core/auth/options.ts +++ b/src/core/auth/options.ts @@ -5,8 +5,17 @@ export interface AuthOptions { headers: any; } +export interface AuthData { + auth: string; + channel_data?: string; +} + +export type AuthInfo = AuthData | string + +export type AuthorizerCallback = (error: boolean, authInfo: AuthInfo)=> void; + export interface Authorizer { - authorize(socketId: string, callback: Function); + authorize(socketId: string, callback: AuthorizerCallback): void; } export interface AuthorizerGenerator { diff --git a/src/core/auth/pusher_authorizer.ts b/src/core/auth/pusher_authorizer.ts index 59ec90e08..b047db794 100644 --- a/src/core/auth/pusher_authorizer.ts +++ b/src/core/auth/pusher_authorizer.ts @@ -3,7 +3,7 @@ import Channel from '../channels/channel'; import Factory from '../utils/factory'; import Runtime from 'runtime'; import { AuthTransports } from './auth_transports'; -import { AuthOptions, AuthorizerOptions, Authorizer } from './options'; +import { AuthOptions, AuthorizerOptions, Authorizer, AuthorizerCallback } from './options'; export default class PusherAuthorizer implements Authorizer { static authorizers: AuthTransports; @@ -45,10 +45,9 @@ export default class PusherAuthorizer implements Authorizer { return query; } - authorize(socketId: string, callback: Function): any { - PusherAuthorizer.authorizers = - PusherAuthorizer.authorizers || Runtime.getAuthorizers(); - return PusherAuthorizer.authorizers[this.type].call( + authorize(socketId: string, callback: AuthorizerCallback): void { + PusherAuthorizer.authorizers = PusherAuthorizer.authorizers || Runtime.getAuthorizers(); + PusherAuthorizer.authorizers[this.type].call( this, Runtime, socketId, diff --git a/src/core/channels/channel.ts b/src/core/channels/channel.ts index 53a15cf12..df1173e19 100644 --- a/src/core/channels/channel.ts +++ b/src/core/channels/channel.ts @@ -5,6 +5,7 @@ import Pusher from '../pusher'; import { PusherEvent } from '../connection/protocol/message-types'; import Metadata from './metadata'; import UrlStore from '../utils/url_store'; +import { AuthData, AuthorizerCallback } from '../auth/options'; /** Provides base public channel interface with an event emitter. * @@ -38,8 +39,8 @@ export default class Channel extends EventsDispatcher { * * @param {Function} callback */ - authorize(socketId: string, callback: Function) { - return callback(false, {}); + authorize(socketId: string, callback: AuthorizerCallback) { + return callback(false, {auth: ''}); } /** Triggers an event */ @@ -104,6 +105,7 @@ export default class Channel extends EventsDispatcher { Logger.error(data); this.emit('pusher:subscription_error', data); } else { + data = (data as AuthData) this.pusher.send_event('pusher:subscribe', { auth: data.auth, channel_data: data.channel_data, diff --git a/src/core/channels/encrypted_channel.ts b/src/core/channels/encrypted_channel.ts index f94b51be5..cbffefe06 100644 --- a/src/core/channels/encrypted_channel.ts +++ b/src/core/channels/encrypted_channel.ts @@ -5,6 +5,7 @@ import { secretbox } from 'tweetnacl'; import { encodeUTF8, decodeBase64 } from 'tweetnacl-util'; import Dispatcher from '../events/dispatcher'; import { PusherEvent } from '../connection/protocol/message-types'; +import { AuthorizerCallback } from '../auth/options'; /** Extends private channels to provide encrypted channel interface. * @@ -19,7 +20,7 @@ export default class EncryptedChannel extends PrivateChannel { * @param {String} socketId * @param {Function} callback */ - authorize(socketId: string, callback: Function) { + authorize(socketId: string, callback: AuthorizerCallback) { super.authorize(socketId, (error, authData) => { if (error) { callback(true, authData); diff --git a/src/core/channels/presence_channel.ts b/src/core/channels/presence_channel.ts index 093741d32..944acc12b 100644 --- a/src/core/channels/presence_channel.ts +++ b/src/core/channels/presence_channel.ts @@ -5,6 +5,7 @@ import Pusher from '../pusher'; import UrlStore from 'core/utils/url_store'; import { PusherEvent } from '../connection/protocol/message-types'; import Metadata from './metadata'; +import { AuthData } from '../auth/options' export default class PresenceChannel extends PrivateChannel { members: Members; @@ -27,6 +28,7 @@ export default class PresenceChannel extends PrivateChannel { authorize(socketId: string, callback: Function) { super.authorize(socketId, (error, authData) => { if (!error) { + authData = (authData as AuthData) if (authData.channel_data === undefined) { let suffix = UrlStore.buildLogSuffix('authenticationEndpoint'); Logger.error( diff --git a/src/core/channels/private_channel.ts b/src/core/channels/private_channel.ts index bfa71af5b..a08da776f 100644 --- a/src/core/channels/private_channel.ts +++ b/src/core/channels/private_channel.ts @@ -1,5 +1,6 @@ import Factory from '../utils/factory'; import Channel from './channel'; +import { AuthorizerCallback } from '../auth/options'; /** Extends public channels to provide private channel interface. * @@ -12,7 +13,7 @@ export default class PrivateChannel extends Channel { * @param {String} socketId * @param {Function} callback */ - authorize(socketId: string, callback: Function) { + authorize(socketId: string, callback: AuthorizerCallback) { var authorizer = Factory.createAuthorizer(this, this.pusher.config); return authorizer.authorize(socketId, callback); } diff --git a/src/runtimes/web/auth/jsonp_auth.ts b/src/runtimes/web/auth/jsonp_auth.ts index 56a6aa760..38992451d 100644 --- a/src/runtimes/web/auth/jsonp_auth.ts +++ b/src/runtimes/web/auth/jsonp_auth.ts @@ -3,8 +3,9 @@ import Logger from 'core/logger'; import JSONPRequest from '../dom/jsonp_request'; import { ScriptReceivers } from '../dom/script_receiver_factory'; import { AuthTransport } from 'core/auth/auth_transports'; +import { AuthorizerCallback } from 'core/auth/options'; -var jsonp: AuthTransport = function(context: Browser, socketId, callback) { +var jsonp: AuthTransport = function(context: Browser, socketId: string, callback: AuthorizerCallback) { if (this.authOptions.headers !== undefined) { Logger.warn( 'To send headers with the auth request, you must use AJAX, rather than JSONP.' From 8ac63d96b391feaff6469dfdce1521ab282dcd21 Mon Sep 17 00:00:00 2001 From: James Lees Date: Wed, 5 Feb 2020 12:05:53 +0000 Subject: [PATCH 3/6] expose a public options type --- src/core/options.ts | 31 +++++++++++++++++++++++++++++-- src/core/pusher.ts | 4 ++-- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/core/options.ts b/src/core/options.ts index 6989b5d54..7cca218ba 100644 --- a/src/core/options.ts +++ b/src/core/options.ts @@ -1,7 +1,7 @@ import ConnectionManager from './connection/connection_manager'; import { AuthOptions, AuthorizerGenerator } from './auth/options'; -interface PusherOptions { +export interface PusherOptions { cluster: string; disableStats: boolean; enableStats: boolean; @@ -17,4 +17,31 @@ interface PusherOptions { authorizer: AuthorizerGenerator; } -export default PusherOptions; +type Transport = 'ws' | 'wss' | 'xhr_streaming' | 'xhr_polling' | 'sockjs'; +type AuthTransport = 'ajax' | 'jsonp'; + +export interface Options { + activityTimeout?: number; + disableStats?: boolean; + authEndpoint?: string; + auth?: AuthOptions; + authTransport?: AuthTransport; + authorizer?: AuthorizerGenerator; + disabledTransports?: Transport[]; + enabledTransports?: Transport[]; + encrypted?: boolean; + forceTLS?: boolean; + ignoreNullOrigin?: boolean; + pongTimeout?: number; + statsHost?: string; + timelineParams?: any; + unavailable_timeout?: number; + cluster?: string; + wsHost?: string; + httpHost?: string; + wsPath?: string; + wsPort?: number; + wssPort?: number; + httpPort?: number; + httpsPort?: number; +} diff --git a/src/core/pusher.ts b/src/core/pusher.ts index 4cf546e3e..0dd0522ee 100644 --- a/src/core/pusher.ts +++ b/src/core/pusher.ts @@ -16,7 +16,7 @@ import Defaults from './defaults'; import * as DefaultConfig from './config'; import Logger from './logger'; import Factory from './utils/factory'; -import PusherOptions from './options'; +import {PusherOptions, Options} from './options'; import UrlStore from 'core/utils/url_store'; export default class Pusher { @@ -59,7 +59,7 @@ export default class Pusher { connection: ConnectionManager; timelineSenderTimer: PeriodicTimer; - constructor(app_key: string, options: any) { + constructor(app_key: string, options: Options) { checkAppKey(app_key); options = options || {}; if (!options.cluster && !(options.wsHost || options.httpHost)) { From 172106260a7701ae3b088a927b65e89216562c76 Mon Sep 17 00:00:00 2001 From: James Lees Date: Wed, 5 Feb 2020 12:06:53 +0000 Subject: [PATCH 4/6] add type declarations --- index.d.ts | 16 ++++++++++++++++ .../unit/core/channels/channel_spec.js | 2 +- src/core/auth/options.ts | 4 ++-- src/core/auth/pusher_authorizer.ts | 10 ++++++++-- src/core/channels/channel.ts | 4 ++-- src/core/channels/presence_channel.ts | 4 ++-- src/core/pusher.ts | 2 +- src/runtimes/web/auth/jsonp_auth.ts | 6 +++++- types/src/core/auth/options.d.ts | 8 +++++++- types/src/core/auth/pusher_authorizer.d.ts | 4 ++-- types/src/core/channels/channel.d.ts | 3 ++- types/src/core/channels/encrypted_channel.d.ts | 3 ++- types/src/core/channels/private_channel.d.ts | 3 ++- types/src/core/config.d.ts | 6 +++--- 14 files changed, 55 insertions(+), 20 deletions(-) create mode 100644 index.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 000000000..dde3c10dc --- /dev/null +++ b/index.d.ts @@ -0,0 +1,16 @@ +export { + AuthInfo, + Authorizer, + AuthOptions, + AuthorizerGenerator, + AuthorizerCallback, +} from './types/src/core/auth/options'; +export { Options } from './types/src/core/options' + +export {default as Channel} from './types/src/core/channels/channel'; +export {default as PresenceChannel} from './types/src/core/channels/presence_channel'; +export {default as Members} from './types/src/core/channels/members'; +export {default as Runtime} from './types/src/runtimes/interface' +export {default as ConnectionManager} from './types/src/core/connection/connection_manager' + +export {default} from './types/src/core/pusher' diff --git a/spec/javascripts/unit/core/channels/channel_spec.js b/spec/javascripts/unit/core/channels/channel_spec.js index 9d63fa6e6..4eef5fab9 100644 --- a/spec/javascripts/unit/core/channels/channel_spec.js +++ b/spec/javascripts/unit/core/channels/channel_spec.js @@ -30,7 +30,7 @@ describe("Channel", function() { it("should call back with false, {} immediately", function() { var callback = jasmine.createSpy("callback"); channel.authorize("1.1", callback); - expect(callback).toHaveBeenCalledWith(false, {}); + expect(callback).toHaveBeenCalledWith(false, {auth: ''}); }); }); diff --git a/src/core/auth/options.ts b/src/core/auth/options.ts index 17a61843a..8d9f79a93 100644 --- a/src/core/auth/options.ts +++ b/src/core/auth/options.ts @@ -10,9 +10,9 @@ export interface AuthData { channel_data?: string; } -export type AuthInfo = AuthData | string +export type AuthInfo = AuthData | string; -export type AuthorizerCallback = (error: boolean, authInfo: AuthInfo)=> void; +export type AuthorizerCallback = (error: boolean, authInfo: AuthInfo) => void; export interface Authorizer { authorize(socketId: string, callback: AuthorizerCallback): void; diff --git a/src/core/auth/pusher_authorizer.ts b/src/core/auth/pusher_authorizer.ts index b047db794..2a0bb8c45 100644 --- a/src/core/auth/pusher_authorizer.ts +++ b/src/core/auth/pusher_authorizer.ts @@ -3,7 +3,12 @@ import Channel from '../channels/channel'; import Factory from '../utils/factory'; import Runtime from 'runtime'; import { AuthTransports } from './auth_transports'; -import { AuthOptions, AuthorizerOptions, Authorizer, AuthorizerCallback } from './options'; +import { + AuthOptions, + AuthorizerOptions, + Authorizer, + AuthorizerCallback +} from './options'; export default class PusherAuthorizer implements Authorizer { static authorizers: AuthTransports; @@ -46,7 +51,8 @@ export default class PusherAuthorizer implements Authorizer { } authorize(socketId: string, callback: AuthorizerCallback): void { - PusherAuthorizer.authorizers = PusherAuthorizer.authorizers || Runtime.getAuthorizers(); + PusherAuthorizer.authorizers = + PusherAuthorizer.authorizers || Runtime.getAuthorizers(); PusherAuthorizer.authorizers[this.type].call( this, Runtime, diff --git a/src/core/channels/channel.ts b/src/core/channels/channel.ts index df1173e19..204ecc268 100644 --- a/src/core/channels/channel.ts +++ b/src/core/channels/channel.ts @@ -40,7 +40,7 @@ export default class Channel extends EventsDispatcher { * @param {Function} callback */ authorize(socketId: string, callback: AuthorizerCallback) { - return callback(false, {auth: ''}); + return callback(false, { auth: '' }); } /** Triggers an event */ @@ -105,7 +105,7 @@ export default class Channel extends EventsDispatcher { Logger.error(data); this.emit('pusher:subscription_error', data); } else { - data = (data as AuthData) + data = data as AuthData; this.pusher.send_event('pusher:subscribe', { auth: data.auth, channel_data: data.channel_data, diff --git a/src/core/channels/presence_channel.ts b/src/core/channels/presence_channel.ts index 944acc12b..a09a8ff68 100644 --- a/src/core/channels/presence_channel.ts +++ b/src/core/channels/presence_channel.ts @@ -5,7 +5,7 @@ import Pusher from '../pusher'; import UrlStore from 'core/utils/url_store'; import { PusherEvent } from '../connection/protocol/message-types'; import Metadata from './metadata'; -import { AuthData } from '../auth/options' +import { AuthData } from '../auth/options'; export default class PresenceChannel extends PrivateChannel { members: Members; @@ -28,7 +28,7 @@ export default class PresenceChannel extends PrivateChannel { authorize(socketId: string, callback: Function) { super.authorize(socketId, (error, authData) => { if (!error) { - authData = (authData as AuthData) + authData = authData as AuthData; if (authData.channel_data === undefined) { let suffix = UrlStore.buildLogSuffix('authenticationEndpoint'); Logger.error( diff --git a/src/core/pusher.ts b/src/core/pusher.ts index 0dd0522ee..634c15c6c 100644 --- a/src/core/pusher.ts +++ b/src/core/pusher.ts @@ -16,7 +16,7 @@ import Defaults from './defaults'; import * as DefaultConfig from './config'; import Logger from './logger'; import Factory from './utils/factory'; -import {PusherOptions, Options} from './options'; +import { PusherOptions, Options } from './options'; import UrlStore from 'core/utils/url_store'; export default class Pusher { diff --git a/src/runtimes/web/auth/jsonp_auth.ts b/src/runtimes/web/auth/jsonp_auth.ts index 38992451d..be954bb5f 100644 --- a/src/runtimes/web/auth/jsonp_auth.ts +++ b/src/runtimes/web/auth/jsonp_auth.ts @@ -5,7 +5,11 @@ import { ScriptReceivers } from '../dom/script_receiver_factory'; import { AuthTransport } from 'core/auth/auth_transports'; import { AuthorizerCallback } from 'core/auth/options'; -var jsonp: AuthTransport = function(context: Browser, socketId: string, callback: AuthorizerCallback) { +var jsonp: AuthTransport = function( + context: Browser, + socketId: string, + callback: AuthorizerCallback +) { if (this.authOptions.headers !== undefined) { Logger.warn( 'To send headers with the auth request, you must use AJAX, rather than JSONP.' diff --git a/types/src/core/auth/options.d.ts b/types/src/core/auth/options.d.ts index e0161ad47..dfa505d22 100644 --- a/types/src/core/auth/options.d.ts +++ b/types/src/core/auth/options.d.ts @@ -3,8 +3,14 @@ export interface AuthOptions { params: any; headers: any; } +export interface AuthData { + auth: string; + channel_data?: string; +} +export declare type AuthInfo = AuthData | string; +export declare type AuthorizerCallback = (error: boolean, authInfo: AuthInfo) => void; export interface Authorizer { - authorize(socketId: string, callback: Function): any; + authorize(socketId: string, callback: AuthorizerCallback): void; } export interface AuthorizerGenerator { (channel: Channel, options: AuthorizerOptions): Authorizer; diff --git a/types/src/core/auth/pusher_authorizer.d.ts b/types/src/core/auth/pusher_authorizer.d.ts index d64cfef75..1214d6b06 100644 --- a/types/src/core/auth/pusher_authorizer.d.ts +++ b/types/src/core/auth/pusher_authorizer.d.ts @@ -1,6 +1,6 @@ import Channel from '../channels/channel'; import { AuthTransports } from './auth_transports'; -import { AuthOptions, AuthorizerOptions, Authorizer } from './options'; +import { AuthOptions, AuthorizerOptions, Authorizer, AuthorizerCallback } from './options'; export default class PusherAuthorizer implements Authorizer { static authorizers: AuthTransports; channel: Channel; @@ -9,5 +9,5 @@ export default class PusherAuthorizer implements Authorizer { authOptions: AuthOptions; constructor(channel: Channel, options: AuthorizerOptions); composeQuery(socketId: string): string; - authorize(socketId: string, callback: Function): any; + authorize(socketId: string, callback: AuthorizerCallback): void; } diff --git a/types/src/core/channels/channel.d.ts b/types/src/core/channels/channel.d.ts index 917e65eee..d24d4fca6 100644 --- a/types/src/core/channels/channel.d.ts +++ b/types/src/core/channels/channel.d.ts @@ -1,6 +1,7 @@ import { default as EventsDispatcher } from '../events/dispatcher'; import Pusher from '../pusher'; import { PusherEvent } from '../connection/protocol/message-types'; +import { AuthorizerCallback } from '../auth/options'; export default class Channel extends EventsDispatcher { name: string; pusher: Pusher; @@ -8,7 +9,7 @@ export default class Channel extends EventsDispatcher { subscriptionPending: boolean; subscriptionCancelled: boolean; constructor(name: string, pusher: Pusher); - authorize(socketId: string, callback: Function): any; + authorize(socketId: string, callback: AuthorizerCallback): void; trigger(event: string, data: any): boolean; disconnect(): void; handleEvent(event: PusherEvent): void; diff --git a/types/src/core/channels/encrypted_channel.d.ts b/types/src/core/channels/encrypted_channel.d.ts index afb54beb1..3675b0a05 100644 --- a/types/src/core/channels/encrypted_channel.d.ts +++ b/types/src/core/channels/encrypted_channel.d.ts @@ -1,9 +1,10 @@ import PrivateChannel from './private_channel'; import Dispatcher from '../events/dispatcher'; import { PusherEvent } from '../connection/protocol/message-types'; +import { AuthorizerCallback } from '../auth/options'; export default class EncryptedChannel extends PrivateChannel { key: Uint8Array; - authorize(socketId: string, callback: Function): void; + authorize(socketId: string, callback: AuthorizerCallback): void; trigger(event: string, data: any): boolean; handleEvent(event: PusherEvent): void; private handleEncryptedEvent; diff --git a/types/src/core/channels/private_channel.d.ts b/types/src/core/channels/private_channel.d.ts index d9d39c435..094c8874b 100644 --- a/types/src/core/channels/private_channel.d.ts +++ b/types/src/core/channels/private_channel.d.ts @@ -1,4 +1,5 @@ import Channel from './channel'; +import { AuthorizerCallback } from '../auth/options'; export default class PrivateChannel extends Channel { - authorize(socketId: string, callback: Function): any; + authorize(socketId: string, callback: AuthorizerCallback): void; } diff --git a/types/src/core/config.d.ts b/types/src/core/config.d.ts index c54c790e4..6860b1e0d 100644 --- a/types/src/core/config.d.ts +++ b/types/src/core/config.d.ts @@ -10,9 +10,9 @@ export declare var getGlobalConfig: () => { statsHost: string; authEndpoint: string; authTransport: string; - activityTimeout: number; - pongTimeout: number; - unavailableTimeout: number; + activity_timeout: number; + pong_timeout: number; + unavailable_timeout: number; }; export declare var getClusterConfig: (clusterName: any) => { wsHost: string; From 86f40acf7bfacbe73feeadc75b3662100c505710 Mon Sep 17 00:00:00 2001 From: James Lees Date: Tue, 11 Feb 2020 09:21:30 +0000 Subject: [PATCH 5/6] add enableStats option --- src/core/options.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/options.ts b/src/core/options.ts index 7cca218ba..f18c5c7d4 100644 --- a/src/core/options.ts +++ b/src/core/options.ts @@ -22,7 +22,8 @@ type AuthTransport = 'ajax' | 'jsonp'; export interface Options { activityTimeout?: number; - disableStats?: boolean; + enableStats?: boolean; + disableStats?: boolean; // deprecated authEndpoint?: string; auth?: AuthOptions; authTransport?: AuthTransport; From 308314e913914b871c7489c44487f6f486e8d31e Mon Sep 17 00:00:00 2001 From: James Lees Date: Tue, 11 Feb 2020 09:42:58 +0000 Subject: [PATCH 6/6] make options arg optional --- src/core/pusher.ts | 2 +- types/src/core/options.d.ts | 2 ++ types/src/core/pusher.d.ts | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/core/pusher.ts b/src/core/pusher.ts index 634c15c6c..24d447e6e 100644 --- a/src/core/pusher.ts +++ b/src/core/pusher.ts @@ -59,7 +59,7 @@ export default class Pusher { connection: ConnectionManager; timelineSenderTimer: PeriodicTimer; - constructor(app_key: string, options: Options) { + constructor(app_key: string, options?: Options) { checkAppKey(app_key); options = options || {}; if (!options.cluster && !(options.wsHost || options.httpHost)) { diff --git a/types/src/core/options.d.ts b/types/src/core/options.d.ts index ed79af525..509d2bac1 100644 --- a/types/src/core/options.d.ts +++ b/types/src/core/options.d.ts @@ -2,6 +2,7 @@ import { AuthOptions, AuthorizerGenerator } from './auth/options'; export interface PusherOptions { cluster: string; disableStats: boolean; + enableStats: boolean; statsHost: string; activity_timeout: number; pong_timeout: number; @@ -17,6 +18,7 @@ declare type Transport = 'ws' | 'wss' | 'xhr_streaming' | 'xhr_polling' | 'sockj declare type AuthTransport = 'ajax' | 'jsonp'; export interface Options { activityTimeout?: number; + enableStats?: boolean; disableStats?: boolean; authEndpoint?: string; auth?: AuthOptions; diff --git a/types/src/core/pusher.d.ts b/types/src/core/pusher.d.ts index 2e03c4475..95ae1da97 100644 --- a/types/src/core/pusher.d.ts +++ b/types/src/core/pusher.d.ts @@ -27,7 +27,7 @@ export default class Pusher { timelineSender: TimelineSender; connection: ConnectionManager; timelineSenderTimer: PeriodicTimer; - constructor(app_key: string, options: Options); + constructor(app_key: string, options?: Options); channel(name: string): Channel; allChannels(): Channel[]; connect(): void;