Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Socket
Sign inDemoInstall

stream-chat

Package Overview
Dependencies
Maintainers
13
Versions
296
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stream-chat - npm Package Compare versions

Comparing version 3.13.1 to 4.0.0-offline-caching.0

34

dist/types/channel_state.d.ts
import { Channel } from './channel';
import { ChannelMemberResponse, ChannelMembership, FormatMessageResponse, Event, LiteralStringForUnion, MessageResponse, ReactionResponse, UnknownType, UserResponse } from './types';
export declare type ChannelStateData<AttachmentType extends UnknownType = UnknownType, ChannelType extends UnknownType = UnknownType, CommandType extends string = LiteralStringForUnion, EventType extends UnknownType = UnknownType, MessageType extends UnknownType = UnknownType, ReactionType extends UnknownType = UnknownType, UserType extends UnknownType = UnknownType> = {
isUpToDate: boolean;
last_message_at: string | null;
members: Record<string, ChannelMemberResponse<UserType>>;
membership: ChannelMembership<UserType>;
messages: MessageResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>[];
mutedUsers: Array<UserResponse<UserType>>;
pinnedMessages: MessageResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>[];
read: Record<string, {
last_read: string;
user: UserResponse<UserType>;
}>;
threads: Record<string, Array<MessageResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>>>;
typing: Record<string, Event<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>>;
unreadCount: number;
watcher_count: number;
watchers: Record<string, UserResponse<UserType>>;
};
/**

@@ -114,2 +132,18 @@ * ChannelState - A container class for the channel state.

_addToMessageList(messages: Array<ReturnType<ChannelState<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>['formatMessage']>>, message: ReturnType<ChannelState<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>['formatMessage']>, timestampChanged?: boolean, sortBy?: 'pinned_at' | 'created_at', addIfDoesNotExist?: boolean): FormatMessageResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>[];
getStateData(): {
read: Record<string, {
last_read: Date;
user: UserResponse<UserType>;
}>;
messages: FormatMessageResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>[];
pinnedMessages: FormatMessageResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>[];
threads: Record<string, FormatMessageResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>[]>;
mutedUsers: UserResponse<UserType>[];
members: Record<string, ChannelMemberResponse<UserType>>;
membership: ChannelMembership<UserType>;
unreadCount: number;
isUpToDate: boolean;
last_message_at: Date | null;
};
reInitializeWithState(channelState: ChannelStateData<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>): void;
/**

@@ -116,0 +150,0 @@ * removeMessage - Description

33

dist/types/channel.d.ts
/// <reference types="node" />
import { ChannelState } from './channel_state';
import { ChannelState, ChannelStateData } from './channel_state';
import { StreamChat } from './client';
import { APIResponse, BanUserOptions, ChannelAPIResponse, ChannelData, ChannelMemberAPIResponse, ChannelQueryOptions, ChannelResponse, DeleteChannelAPIResponse, Event, EventAPIResponse, EventHandler, EventTypes, FormatMessageResponse, GetMultipleMessagesAPIResponse, GetReactionsAPIResponse, GetRepliesAPIResponse, InviteOptions, LiteralStringForUnion, MarkReadOptions, Message, MessageFilters, MessageResponse, MuteChannelAPIResponse, PaginationOptions, PartialUpdateChannel, PartialUpdateChannelAPIResponse, QueryMembersOptions, Reaction, ReactionAPIResponse, SearchOptions, SearchAPIResponse, SendMessageAPIResponse, TruncateChannelAPIResponse, UnknownType, UpdateChannelAPIResponse, UserFilters, UserResponse, UserSort } from './types';
import { APIResponse, BanUserOptions, ChannelAPIResponse, ChannelData, ChannelMemberAPIResponse, ChannelMemberResponse, ChannelQueryOptions, ChannelResponse, DeleteChannelAPIResponse, Event, EventAPIResponse, EventHandler, EventTypes, FormatMessageResponse, GetMultipleMessagesAPIResponse, GetReactionsAPIResponse, GetRepliesAPIResponse, InviteOptions, LiteralStringForUnion, MarkReadOptions, Message, MessageFilters, MessageResponse, MuteChannelAPIResponse, PaginationOptions, PartialUpdateChannel, PartialUpdateChannelAPIResponse, QueryMembersOptions, Reaction, ReactionAPIResponse, SearchOptions, SearchAPIResponse, SendMessageAPIResponse, TruncateChannelAPIResponse, UnknownType, UpdateChannelAPIResponse, UserFilters, UserResponse, UserSort } from './types';
import { Role } from './permissions';
export declare type ChannelStateAndData<AttachmentType extends UnknownType = UnknownType, ChannelType extends UnknownType = UnknownType, CommandType extends string = LiteralStringForUnion, EventType extends UnknownType = UnknownType, MessageType extends UnknownType = UnknownType, ReactionType extends UnknownType = UnknownType, UserType extends UnknownType = UnknownType> = {
_data: ChannelResponse<ChannelType, CommandType, UserType> | undefined;
data: ChannelResponse<ChannelType, CommandType, UserType> | undefined;
id: string | undefined;
state: ChannelStateData<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>;
type: string;
};
/**

@@ -468,4 +475,26 @@ * Channel - The Channel class manages it's own state.

_initializeState(state: ChannelAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>): void;
getStateData(): {
state: {
read: Record<string, {
last_read: Date;
user: UserResponse<UserType>;
}>;
messages: FormatMessageResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>[];
pinnedMessages: FormatMessageResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>[];
threads: Record<string, FormatMessageResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>[]>;
mutedUsers: UserResponse<UserType>[];
members: Record<string, ChannelMemberResponse<UserType>>;
membership: import("./types").ChannelMembership<UserType>;
unreadCount: number;
isUpToDate: boolean;
last_message_at: Date | null;
};
data: ChannelData<ChannelType> | ChannelResponse<ChannelType, CommandType, UserType> | undefined;
_data: ChannelData<ChannelType> | ChannelResponse<ChannelType, CommandType, UserType>;
id: string | undefined;
type: string;
};
reInitializeWithState(channelState: ChannelStateAndData<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>): void;
_disconnect(): void;
}
//# sourceMappingURL=channel.d.ts.map

@@ -5,2 +5,12 @@ import { UnknownType, UserResponse } from './types';

*/
export declare type ClientStateData<UserType = UnknownType> = {
userChannelReferences: {
[key: string]: {
[key: string]: boolean;
};
};
users: {
[key: string]: UserResponse<UserType>;
};
};
export declare class ClientState<UserType = UnknownType> {

@@ -20,3 +30,14 @@ users: {

deleteAllChannelReference(channelID: string): void;
getStateData(): {
users: {
[key: string]: UserResponse<UserType>;
};
userChannelReferences: {
[key: string]: {
[key: string]: boolean;
};
};
};
reInitializeWithState(clientState: ClientStateData<UserType>): void;
}
//# sourceMappingURL=client_state.d.ts.map
/// <reference types="node" />
import { AxiosRequestConfig, AxiosInstance, AxiosResponse } from 'axios';
import WebSocket from 'isomorphic-ws';
import { Channel } from './channel';
import { ClientState } from './client_state';
import { Channel, ChannelStateAndData } from './channel';
import { ClientState, ClientStateData } from './client_state';
import { StableWSConnection } from './connection';
import { TokenManager } from './token_manager';
import { APIResponse, AppSettings, AppSettingsAPIResponse, BannedUsersFilters, BannedUsersPaginationOptions, BannedUsersResponse, BannedUsersSort, BanUserOptions, BlockList, BlockListResponse, ChannelAPIResponse, ChannelData, ChannelFilters, ChannelMute, ChannelOptions, ChannelSort, CheckPushResponse, CheckSQSResponse, Configs, ConnectAPIResponse, CreateChannelOptions, CreateChannelResponse, CreateCommandOptions, CreateCommandResponse, CustomPermissionOptions, DeleteCommandResponse, Device, EndpointName, Event, EventHandler, ExportChannelRequest, ExportChannelResponse, ExportChannelStatusResponse, MessageFlagsFilters, MessageFlagsPaginationOptions, MessageFlagsResponse, FlagMessageResponse, FlagUserResponse, GetChannelTypeResponse, GetCommandResponse, GetRateLimitsResponse, ListChannelResponse, ListCommandsResponse, LiteralStringForUnion, Logger, MarkAllReadOptions, MessageFilters, MessageResponse, Mute, MuteUserOptions, MuteUserResponse, OwnUserResponse, PartialMessageUpdate, PartialUserUpdate, PermissionAPIResponse, PermissionsAPIResponse, ReactionResponse, SearchOptions, SearchAPIResponse, SendFileAPIResponse, StreamChatOptions, TestPushDataInput, TestSQSDataInput, TokenOrProvider, UnBanUserOptions, UnknownType, UpdateChannelOptions, UpdateChannelResponse, UpdateCommandOptions, UpdateCommandResponse, UpdatedMessage, UpdateMessageAPIResponse, UserCustomEvent, UserFilters, UserOptions, UserResponse, UserSort, SegmentData, Segment, Campaign, CampaignData } from './types';
import { APIResponse, AppSettings, AppSettingsAPIResponse, BaseDeviceFields, BannedUsersFilters, BannedUsersPaginationOptions, BannedUsersResponse, BannedUsersSort, BanUserOptions, BlockList, BlockListResponse, ChannelAPIResponse, ChannelData, ChannelFilters, ChannelMute, ChannelOptions, ChannelSort, ChannelStateOptions, CheckPushResponse, CheckSQSResponse, Configs, ConnectAPIResponse, CreateChannelOptions, CreateChannelResponse, CreateCommandOptions, CreateCommandResponse, CustomPermissionOptions, DeleteCommandResponse, Device, EndpointName, Event, EventHandler, ExportChannelRequest, ExportChannelResponse, ExportChannelStatusResponse, MessageFlagsFilters, MessageFlagsPaginationOptions, MessageFlagsResponse, FlagMessageResponse, FlagUserResponse, GetChannelTypeResponse, GetCommandResponse, GetRateLimitsResponse, ListChannelResponse, ListCommandsResponse, LiteralStringForUnion, Logger, MarkAllReadOptions, MessageFilters, MessageResponse, Mute, MuteUserOptions, MuteUserResponse, OwnUserResponse, PartialMessageUpdate, PartialUserUpdate, PermissionAPIResponse, PermissionsAPIResponse, ReactionResponse, SearchOptions, SearchAPIResponse, SendFileAPIResponse, StreamChatOptions, TestPushDataInput, TestSQSDataInput, TokenOrProvider, UnBanUserOptions, UnknownType, UpdateChannelOptions, UpdateChannelResponse, UpdateCommandOptions, UpdateCommandResponse, UpdatedMessage, UpdateMessageAPIResponse, UserCustomEvent, UserFilters, UserOptions, UserResponse, UserSort, SegmentData, Segment, Campaign, CampaignData } from './types';
export declare type ClientStateAndData<ChannelType extends UnknownType = UnknownType, CommandType extends string = LiteralStringForUnion, UserType extends UnknownType = UnknownType> = {
state: ClientStateData<UserType>;
token: string;
user: OwnUserResponse<ChannelType, CommandType, UserType> | UserResponse<UserType>;
};
export declare class StreamChat<AttachmentType extends UnknownType = UnknownType, ChannelType extends UnknownType = UnknownType, CommandType extends string = LiteralStringForUnion, EventType extends UnknownType = UnknownType, MessageType extends UnknownType = UnknownType, ReactionType extends UnknownType = UnknownType, UserType extends UnknownType = UnknownType> {

@@ -104,2 +109,3 @@ private static _instance?;

_hasConnectionID: () => boolean;
_setUserConnection: (user: OwnUserResponse<ChannelType, CommandType, UserType> | UserResponse<UserType>, userTokenOrProvider: TokenOrProvider) => void;
/**

@@ -113,3 +119,3 @@ * connectUser - Set the current user and open a WebSocket connection

*/
connectUser: (user: OwnUserResponse<ChannelType, CommandType, UserType> | UserResponse<UserType>, userTokenOrProvider: TokenOrProvider) => ConnectAPIResponse<ChannelType, CommandType, UserType>;
connectUser: (user: OwnUserResponse<ChannelType, CommandType, UserType> | UserResponse<UserType>, userTokenOrProvider: TokenOrProvider) => Promise<void | import("./types").ConnectionOpen<ChannelType, CommandType, UserType>>;
/**

@@ -125,3 +131,3 @@ * @deprecated Please use connectUser() function instead. Its naming is more consistent with its functionality.

*/
setUser: (user: OwnUserResponse<ChannelType, CommandType, UserType> | UserResponse<UserType>, userTokenOrProvider: TokenOrProvider) => ConnectAPIResponse<ChannelType, CommandType, UserType>;
setUser: (user: OwnUserResponse<ChannelType, CommandType, UserType> | UserResponse<UserType>, userTokenOrProvider: TokenOrProvider) => Promise<void | import("./types").ConnectionOpen<ChannelType, CommandType, UserType>>;
_setToken: (user: UserResponse<UserType>, userTokenOrProvider: TokenOrProvider) => Promise<void>;

@@ -416,2 +422,41 @@ _setUser(user: OwnUserResponse<ChannelType, CommandType, UserType> | UserResponse<UserType>): void;

queryMessageFlags(filterConditions?: MessageFlagsFilters, options?: MessageFlagsPaginationOptions): Promise<MessageFlagsResponse<ChannelType, CommandType, UserType, UnknownType, UnknownType, UnknownType>>;
getStateData(): {
client: {
state: {
users: {
[key: string]: UserResponse<UserType>;
};
userChannelReferences: {
[key: string]: {
[key: string]: boolean;
};
};
};
user: OwnUserResponse<ChannelType, CommandType, UserType> | UserResponse<UserType> | undefined;
token: string | null | undefined;
};
channels: {
state: {
read: Record<string, {
last_read: Date;
user: UserResponse<UserType>;
}>;
messages: import("./types").FormatMessageResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>[];
pinnedMessages: import("./types").FormatMessageResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>[];
threads: Record<string, import("./types").FormatMessageResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>[]>;
mutedUsers: UserResponse<UserType>[];
members: Record<string, import("./types").ChannelMemberResponse<UserType>>;
membership: import("./types").ChannelMembership<UserType>;
unreadCount: number;
isUpToDate: boolean;
last_message_at: Date | null;
};
data: import("./types").ChannelResponse<ChannelType, CommandType, UserType> | ChannelData<ChannelType> | undefined;
_data: import("./types").ChannelResponse<ChannelType, CommandType, UserType> | ChannelData<ChannelType>;
id: string | undefined;
type: string;
}[];
};
reInitializeAuthState(user: OwnUserResponse<ChannelType, CommandType, UserType> | UserResponse<UserType>, userTokenOrProvider: TokenOrProvider): Promise<void>;
reInitializeWithState(clientData: ClientStateAndData<ChannelType, CommandType, UserType>, channelsData: ChannelStateAndData<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>[]): void;
/**

@@ -424,6 +469,8 @@ * queryChannels - Query channels

* @param {ChannelOptions} [options] Options object
* @param {ChannelStateOptions} [stateOptions] State options object. These options will only be used for state management and won't be sent in the request.
* - stateOptions.skipInitialization - Skips the initialization of the state for the channels matching the ids in the list.
*
* @return {Promise<APIResponse & { channels: Array<ChannelAPIResponse<AttachmentType,ChannelType,CommandType,MessageType,ReactionType,UserType>>}> } search channels response
*/
queryChannels(filterConditions: ChannelFilters<ChannelType, CommandType, UserType>, sort?: ChannelSort<ChannelType>, options?: ChannelOptions): Promise<Channel<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>[]>;
queryChannels(filterConditions: ChannelFilters<ChannelType, CommandType, UserType>, sort?: ChannelSort<ChannelType>, options?: ChannelOptions, stateOptions?: ChannelStateOptions): Promise<Channel<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>[]>;
/**

@@ -440,2 +487,11 @@ * search - Query messages

/**
* setLocalDevice - Set the device info for the current client(device) that will be sent via WS connection automatically
*
* @param {BaseDeviceFields} device the device object
* @param {string} device.id device id
* @param {string} device.push_provider the push provider (apn or firebase)
*
*/
setLocalDevice(device: BaseDeviceFields): void;
/**
* addDevice - Adds a push device for a user.

@@ -995,3 +1051,6 @@ *

*/
listSegments(): Promise<Segment[]>;
listSegments(options: {
limit?: number;
offset?: number;
}): Promise<Segment[]>;
/**

@@ -1036,3 +1095,6 @@ * updateSegment - Update a Campaign Segment

*/
listCampaigns(): Promise<Campaign[]>;
listCampaigns(options: {
limit?: number;
offset?: number;
}): Promise<Campaign[]>;
/**

@@ -1039,0 +1101,0 @@ * updateCampaign - Update a Campaign

@@ -5,3 +5,3 @@ /// <reference types="node" />

import { TokenManager } from './token_manager';
import { ConnectAPIResponse, ConnectionChangeEvent, ConnectionOpen, LiteralStringForUnion, Logger, UnknownType, UserResponse } from './types';
import { BaseDeviceFields, ConnectAPIResponse, ConnectionChangeEvent, ConnectionOpen, LiteralStringForUnion, Logger, UnknownType, UserResponse } from './types';
declare type Constructor<ChannelType extends UnknownType = UnknownType, CommandType extends string = LiteralStringForUnion, UserType extends UnknownType = UnknownType> = {

@@ -20,2 +20,3 @@ apiKey: string;

wsBaseURL: string;
device?: BaseDeviceFields;
};

@@ -52,2 +53,3 @@ /**

wsBaseURL: Constructor<ChannelType, CommandType, UserType>['wsBaseURL'];
device: Constructor<ChannelType, CommandType, UserType>['device'];
connectionID?: string;

@@ -73,3 +75,3 @@ connectionOpen?: ConnectAPIResponse<ChannelType, CommandType, UserType>;

wsID: number;
constructor({ apiKey, authType, clientID, eventCallback, logger, messageCallback, recoverCallback, tokenManager, user, userAgent, userID, wsBaseURL, }: Constructor<ChannelType, CommandType, UserType>);
constructor({ apiKey, authType, clientID, eventCallback, logger, messageCallback, recoverCallback, tokenManager, user, userAgent, userID, wsBaseURL, device, }: Constructor<ChannelType, CommandType, UserType>);
/**

@@ -81,2 +83,8 @@ * connect - Connect to the WS URL

connect(): Promise<void | ConnectionOpen<ChannelType, CommandType, UserType>>;
/**
* _waitForHealthy polls the promise connection to see if its resolved until it times out
* the default 15s timeout allows between 2~3 tries
* @param timeout duration(ms)
*/
_waitForHealthy(timeout?: number): Promise<void | ConnectionOpen<ChannelType, CommandType, UserType>>;
_buildUrl: () => string;

@@ -83,0 +91,0 @@ /**

24

dist/types/types.d.ts

@@ -58,2 +58,3 @@ import { AxiosRequestConfig } from 'axios';

before_message_send_hook_url?: string;
campaign_enabled?: boolean;
custom_action_handler_url?: string;

@@ -485,2 +486,5 @@ disable_auth_checks?: boolean;

};
export declare type ChannelStateOptions = {
skipInitialization?: string[];
};
export declare type CreateChannelOptions<CommandType extends string = LiteralStringForUnion> = {

@@ -603,2 +607,3 @@ automod?: ChannelConfigAutomod;

browser?: boolean;
device?: BaseDeviceFields;
logger?: Logger;

@@ -993,8 +998,10 @@ /**

};
export declare type DeviceFields = {
export declare type BaseDeviceFields = {
id: string;
push_provider: 'apn' | 'firebase';
};
export declare type DeviceFields = BaseDeviceFields & {
created_at: string;
disabled?: boolean;
disabled_reason?: string;
id?: string;
push_provider?: 'apn' | 'firebase';
};

@@ -1161,7 +1168,8 @@ export declare type EndpointName = 'Connect' | 'DeleteFile' | 'DeleteImage' | 'DeleteMessage' | 'DeleteUser' | 'DeactivateUser' | 'ExportUser' | 'DeleteReaction' | 'UpdateChannel' | 'UpdateChannelPartial' | 'UpdateMessage' | 'GetMessage' | 'GetManyMessages' | 'UpdateUsers' | 'UpdateUsersPartial' | 'CreateGuest' | 'GetOrCreateChannel' | 'StopWatchingChannel' | 'QueryChannels' | 'Search' | 'QueryUsers' | 'QueryMembers' | 'QueryBannedUsers' | 'GetReactions' | 'GetReplies' | 'Ban' | 'Unban' | 'Mute' | 'MuteChannel' | 'UnmuteChannel' | 'UnmuteUser' | 'RunMessageAction' | 'SendEvent' | 'MarkRead' | 'MarkAllRead' | 'SendMessage' | 'ImportChannelMessages' | 'UploadFile' | 'UploadImage' | 'UpdateApp' | 'GetApp' | 'CreateDevice' | 'DeleteDevice' | 'SendReaction' | 'Flag' | 'Unflag' | 'CreateChannelType' | 'DeleteChannel' | 'DeleteChannelType' | 'GetChannelType' | 'ListChannelTypes' | 'ListDevices' | 'TruncateChannel' | 'UpdateChannelType' | 'CheckPush' | 'PrivateSubmitModeration' | 'ReactivateUser' | 'HideChannel' | 'ShowChannel' | 'CreatePermission' | 'UpdatePermission' | 'GetPermission' | 'DeletePermission' | 'ListPermissions' | 'CreateRole' | 'DeleteRole' | 'ListRoles' | 'Sync' | 'TranslateMessage' | 'CreateCommand' | 'GetCommand' | 'UpdateCommand' | 'DeleteCommand' | 'ListCommands' | 'CreateBlockList' | 'UpdateBlockList' | 'GetBlockList' | 'ListBlockLists' | 'DeleteBlockList' | 'ExportChannels' | 'GetExportChannelsStatus' | 'CheckSQS' | 'GetRateLimits' | 'MessageUpdatePartial';

defaults: Record<string, string>;
name: string;
segment_id: string;
text: string;
description?: string;
push_notifications?: boolean;
sender_id?: string;
track_opened?: boolean;
};

@@ -1173,7 +1181,3 @@ export declare type CampaignStatus = {

failed_at?: string;
progress?: {
delivered: number;
errored: number;
sent: number;
};
progress?: number;
resumed_at?: string;

@@ -1188,5 +1192,3 @@ scheduled_at?: string;

updated_at: string;
test?: boolean;
test_original_id?: string;
} & CampaignData & CampaignStatus;
//# sourceMappingURL=types.d.ts.map
{
"name": "stream-chat",
"version": "3.13.1",
"version": "4.0.0-offline-caching.0",
"description": "JS SDK for the Stream Chat API",

@@ -121,5 +121,5 @@ "author": "GetStream",

"eslint-fix": "npx eslint --fix '**/*.{js,md,ts}' --max-warnings 0 --ignore-path ./.eslintignore",
"test-unit": "NODE_ENV=test mocha --exit --bail --timeout 3000 --require ./babel-register test/unit/*.js",
"test-unit": "NODE_ENV=test mocha --exit --bail --timeout 20000 --require ./babel-register test/unit/*.js",
"test": "yarn test-unit",
"testwatch": "NODE_ENV=test nodemon ./node_modules/.bin/mocha --timeout 15000 --require test-entry.js test/test.js",
"testwatch": "NODE_ENV=test nodemon ./node_modules/.bin/mocha --timeout 20000 --require test-entry.js test/test.js",
"lint": "yarn run prettier && yarn run eslint",

@@ -129,4 +129,3 @@ "lint-fix": "yarn run prettier-fix && yarn run eslint-fix",

"preversion": "yarn && yarn lint && yarn test-unit",
"version": "git add yarn.lock",
"postversion": "git push && git push --tags && npm publish"
"version": "git add yarn.lock"
},

@@ -133,0 +132,0 @@ "husky": {

@@ -14,2 +14,63 @@ import { Channel } from './channel';

export type ChannelStateData<
AttachmentType extends UnknownType = UnknownType,
ChannelType extends UnknownType = UnknownType,
CommandType extends string = LiteralStringForUnion,
EventType extends UnknownType = UnknownType,
MessageType extends UnknownType = UnknownType,
ReactionType extends UnknownType = UnknownType,
UserType extends UnknownType = UnknownType
> = {
isUpToDate: boolean;
last_message_at: string | null;
members: Record<string, ChannelMemberResponse<UserType>>;
membership: ChannelMembership<UserType>;
messages: MessageResponse<
AttachmentType,
ChannelType,
CommandType,
MessageType,
ReactionType,
UserType
>[];
mutedUsers: Array<UserResponse<UserType>>;
pinnedMessages: MessageResponse<
AttachmentType,
ChannelType,
CommandType,
MessageType,
ReactionType,
UserType
>[];
read: Record<string, { last_read: string; user: UserResponse<UserType> }>;
threads: Record<
string,
Array<
MessageResponse<
AttachmentType,
ChannelType,
CommandType,
MessageType,
ReactionType,
UserType
>
>
>;
typing: Record<
string,
Event<
AttachmentType,
ChannelType,
CommandType,
EventType,
MessageType,
ReactionType,
UserType
>
>;
unreadCount: number;
watcher_count: number;
watchers: Record<string, UserResponse<UserType>>;
};
/**

@@ -660,2 +721,50 @@ * ChannelState - A container class for the channel state.

getStateData() {
return {
read: this.read,
messages: this.messages,
pinnedMessages: this.pinnedMessages,
threads: this.threads,
mutedUsers: this.mutedUsers,
members: this.members,
membership: this.membership,
unreadCount: this.unreadCount,
isUpToDate: this.isUpToDate,
last_message_at: this.last_message_at,
};
}
reInitializeWithState(
channelState: ChannelStateData<
AttachmentType,
ChannelType,
CommandType,
EventType,
MessageType,
ReactionType,
UserType
>,
) {
this.read = Object.entries(channelState.read).reduce((acc, next) => {
const [id, value] = next;
acc[id] = { ...value, last_read: new Date(value.last_read) };
return acc;
}, {} as Record<string, { last_read: Date; user: UserResponse<UserType> }>);
this.messages = channelState.messages.map((m) => this.formatMessage(m));
this.pinnedMessages = channelState.pinnedMessages.map((m) => this.formatMessage(m));
this.threads = Object.entries(channelState.threads).reduce((acc, next) => {
const [id, value] = next;
acc[id] = value.map((m) => this.formatMessage(m));
return acc;
}, {} as Record<string, Array<ReturnType<ChannelState<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>['formatMessage']>>>);
this.mutedUsers = channelState.mutedUsers;
this.members = channelState.members;
this.membership = channelState.membership;
this.unreadCount = channelState.unreadCount;
this.isUpToDate = channelState.isUpToDate;
this.last_message_at = channelState.last_message_at
? new Date(channelState.last_message_at)
: null;
}
/**

@@ -662,0 +771,0 @@ * removeMessage - Description

@@ -1,2 +0,2 @@

import { ChannelState } from './channel_state';
import { ChannelState, ChannelStateData } from './channel_state';
import { isValidEventType } from './events';

@@ -51,2 +51,26 @@ import { logChatPromiseExecution, normalizeQuerySort } from './utils';

export type ChannelStateAndData<
AttachmentType extends UnknownType = UnknownType,
ChannelType extends UnknownType = UnknownType,
CommandType extends string = LiteralStringForUnion,
EventType extends UnknownType = UnknownType,
MessageType extends UnknownType = UnknownType,
ReactionType extends UnknownType = UnknownType,
UserType extends UnknownType = UnknownType
> = {
_data: ChannelResponse<ChannelType, CommandType, UserType> | undefined;
data: ChannelResponse<ChannelType, CommandType, UserType> | undefined;
id: string | undefined;
state: ChannelStateData<
AttachmentType,
ChannelType,
CommandType,
EventType,
MessageType,
ReactionType,
UserType
>;
type: string;
};
/**

@@ -1786,2 +1810,32 @@ * Channel - The Channel class manages it's own state.

getStateData() {
return {
state: this.state.getStateData(),
data: this.data,
_data: this._data,
id: this.id,
type: this.type,
};
}
reInitializeWithState(
channelState: ChannelStateAndData<
AttachmentType,
ChannelType,
CommandType,
EventType,
MessageType,
ReactionType,
UserType
>,
) {
this.state.reInitializeWithState(channelState.state);
this.data = channelState.data;
if (channelState._data) {
this._data = channelState._data;
}
this.id = channelState.id;
this.type = channelState.type;
}
_disconnect() {

@@ -1788,0 +1842,0 @@ this._client.logger(

@@ -6,2 +6,10 @@ import { UnknownType, UserResponse } from './types';

*/
export type ClientStateData<UserType = UnknownType> = {
userChannelReferences: { [key: string]: { [key: string]: boolean } };
users: {
[key: string]: UserResponse<UserType>;
};
};
export class ClientState<UserType = UnknownType> {

@@ -48,2 +56,14 @@ users: {

}
getStateData() {
return {
users: this.users,
userChannelReferences: this.userChannelReferences,
};
}
reInitializeWithState(clientState: ClientStateData<UserType>) {
this.users = clientState.users;
this.userChannelReferences = clientState.userChannelReferences;
}
}

@@ -5,2 +5,3 @@ import WebSocket from 'isomorphic-ws';

import {
BaseDeviceFields,
ConnectAPIResponse,

@@ -43,2 +44,3 @@ ConnectionChangeEvent,

wsBaseURL: string;
device?: BaseDeviceFields;
};

@@ -80,2 +82,3 @@

wsBaseURL: Constructor<ChannelType, CommandType, UserType>['wsBaseURL'];
device: Constructor<ChannelType, CommandType, UserType>['device'];

@@ -118,2 +121,3 @@ connectionID?: string;

wsBaseURL,
device,
}: Constructor<ChannelType, CommandType, UserType>) {

@@ -128,2 +132,3 @@ this.wsBaseURL = wsBaseURL;

this.tokenManager = tokenManager;
this.device = device;
/** consecutive failures influence the duration of the timeout */

@@ -158,3 +163,2 @@ this.consecutiveFailures = 0;

async connect() {
let healthCheck: ConnectionOpen<ChannelType, CommandType, UserType> | undefined;
if (this.isConnecting) {

@@ -165,4 +169,5 @@ throw Error(

}
try {
healthCheck = await this._connect();
const healthCheck = await this._connect();
this.isConnecting = false;

@@ -178,3 +183,2 @@ this.consecutiveFailures = 0;

);
return healthCheck;
} catch (error) {

@@ -184,2 +188,3 @@ this.isConnecting = false;

this.consecutiveFailures += 1;
if (error.code === chatCodes.TOKEN_EXPIRED && !this.tokenManager.isStatic()) {

@@ -193,8 +198,5 @@ this.logger(

);
return this._reconnect({ refreshToken: true });
}
if (!error.isWSFailure) {
// This is a permanent failure, throw the error...
// We are keeping the error consistent with http error.
this._reconnect({ refreshToken: true });
} else if (!error.isWSFailure) {
// API rejected the connection and we should not retry
throw new Error(

@@ -210,4 +212,47 @@ JSON.stringify({

}
return await this._waitForHealthy();
}
/**
* _waitForHealthy polls the promise connection to see if its resolved until it times out
* the default 15s timeout allows between 2~3 tries
* @param timeout duration(ms)
*/
async _waitForHealthy(timeout = 15000) {
return Promise.race([
(async () => {
const interval = 50; // ms
for (let i = 0; i <= timeout; i += interval) {
try {
return await this.connectionOpen;
} catch (error) {
if (i === timeout) {
throw new Error(
JSON.stringify({
code: error.code,
StatusCode: error.StatusCode,
message: error.message,
isWSFailure: error.isWSFailure,
}),
);
}
await sleep(interval);
}
}
})(),
(async () => {
await sleep(timeout);
throw new Error(
JSON.stringify({
code: '',
StatusCode: '',
message: 'initial WS connection could not be established',
isWSFailure: true,
}),
);
})(),
]);
}
_buildUrl = () => {

@@ -219,2 +264,3 @@ const params = {

server_determines_connection_id: true,
device: this.device,
};

@@ -221,0 +267,0 @@ const qs = encodeURIComponent(JSON.stringify(params));

@@ -84,2 +84,3 @@ import { AxiosRequestConfig } from 'axios';

before_message_send_hook_url?: string;
campaign_enabled?: boolean;
custom_action_handler_url?: string;

@@ -832,2 +833,6 @@ disable_auth_checks?: boolean;

export type ChannelStateOptions = {
skipInitialization?: string[];
};
export type CreateChannelOptions<CommandType extends string = LiteralStringForUnion> = {

@@ -975,2 +980,3 @@ automod?: ChannelConfigAutomod;

browser?: boolean;
device?: BaseDeviceFields;
logger?: Logger;

@@ -1684,8 +1690,11 @@ /**

export type DeviceFields = {
export type BaseDeviceFields = {
id: string;
push_provider: 'apn' | 'firebase';
};
export type DeviceFields = BaseDeviceFields & {
created_at: string;
disabled?: boolean;
disabled_reason?: string;
id?: string;
push_provider?: 'apn' | 'firebase';
};

@@ -2098,7 +2107,8 @@

defaults: Record<string, string>;
name: string;
segment_id: string;
text: string;
description?: string;
push_notifications?: boolean;
sender_id?: string;
track_opened?: boolean;
};

@@ -2118,7 +2128,3 @@

failed_at?: string;
progress?: {
delivered: number;
errored: number;
sent: number;
};
progress?: number;
resumed_at?: string;

@@ -2134,5 +2140,3 @@ scheduled_at?: string;

updated_at: string;
test?: boolean;
test_original_id?: string;
} & CampaignData &
CampaignStatus;

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc