{"version":3,"file":"pull.mjs","sources":["../../../src/types/pull.ts"],"sourcesContent":["import type { LoggerInterface } from '../logger'\nimport type { TypeB24 } from './b24'\nimport type { ISODate, NumberString } from './common'\n\nexport type TypePullMessage = {\n  command: string\n  params: Record<string, any>\n  extra: Record<string, any>\n}\n\nexport type TypePullClientMessageBody = {\n  module_id: string\n  command: string\n  params: any\n  extra?: {\n    revision_web?: number\n    sender?: {\n      type: SenderType\n    }\n    server_time_unix?: number\n    server_time_ago?: number\n  }\n}\n\nexport enum ConnectionType {\n  Undefined = 'undefined',\n  WebSocket = 'webSocket',\n  LongPolling = 'longPolling'\n}\n\nexport type TypeConnector = {\n  setLogger(logger: LoggerInterface): void\n  destroy(): void\n  connect(): void\n  disconnect(code: number, reason: string): void\n  send(buffer: ArrayBuffer | string): boolean\n  connected: boolean\n  connectionPath: string\n}\n\nexport type ConnectorParent = {\n  session: TypePullClientSession\n  getConnectionPath(connectionType: ConnectionType): string\n  getPublicationPath(): string\n  setLastMessageId(lastMessageId: string): void\n  isProtobufSupported(): boolean\n  isJsonRpc(): boolean\n}\n\nexport type ConnectorCallbacks = {\n  onOpen: () => void\n  onDisconnect: (response: { code: number, reason: string }) => void\n  onError: (error: Error) => void\n  onMessage: (response: string | ArrayBuffer) => void\n}\n\nexport type ConnectorConfig = {\n  parent: ConnectorParent\n  onOpen?: () => void\n  onDisconnect?: (response: { code: number, reason: string }) => void\n  onError?: (error: Error) => void\n  onMessage?: (response: string | ArrayBuffer) => void\n}\n\nexport type StorageManagerParams = {\n  userId?: number\n  siteId?: string\n}\n\nexport type TypeStorageManager = {\n  setLogger(logger: LoggerInterface): void\n  getLogger(): LoggerInterface\n\n  set(name: string, value: any): void\n  get(name: string, defaultValue: any): any\n  remove(name: string): void\n  compareKey(eventKey: string, userKey: string): boolean\n}\n\nexport enum LsKeys {\n  PullConfig = 'bx-pull-config',\n  WebsocketBlocked = 'bx-pull-websocket-blocked',\n  LongPollingBlocked = 'bx-pull-longpolling-blocked',\n  LoggingEnabled = 'bx-pull-logging-enabled'\n}\n\nexport type SharedConfigCallbacks = {\n  onWebSocketBlockChanged: (response: { isWebSocketBlocked: boolean }) => void\n}\n\nexport type SharedConfigParams = {\n  storage?: TypeStorageManager\n  onWebSocketBlockChanged?: (response: { isWebSocketBlocked: boolean }) => void\n}\n\nexport enum PullStatus {\n  Online = 'online',\n  Offline = 'offline',\n  Connecting = 'connect'\n}\n\nexport enum SenderType {\n  Unknown = 0,\n  Client = 1,\n  Backend = 2\n}\n\nexport enum SubscriptionType {\n  Server = 'server',\n  Client = 'client',\n  Online = 'online',\n  Status = 'status',\n  Revision = 'revision'\n}\n\nexport type TypeSubscriptionOptions = {\n  /**\n   * Subscription type\n   */\n  type?: SubscriptionType\n\n  /**\n   * Name of the module\n   */\n  moduleId?: string\n\n  /**\n   * Name of the command\n   */\n  command?: null | string\n\n  /**\n   * Function, that will be called for incoming messages\n   */\n  // eslint-disable-next-line\n\tcallback: Function\n}\n\nexport interface UserStatusCallback {\n  (params: { userId: number, isOnline: boolean }): void\n}\n\nexport interface CommandHandlerFunctionV1 {\n  (\n    data: Record<string, any>,\n    info?: {\n      type: SubscriptionType\n      moduleId?: string\n    }\n  ): void\n}\n\nexport interface CommandHandlerFunctionV2 {\n  (\n    params: Record<string, any>,\n    extra: Record<string, any>,\n    command: string,\n    info?: {\n      type: SubscriptionType\n      moduleId: string\n    }\n  ): void\n}\n\nexport interface TypeSubscriptionCommandHandler {\n  getModuleId: () => string\n  getSubscriptionType?: () => SubscriptionType\n  getMap?: () => Record<string, CommandHandlerFunctionV2>\n  [key: string]: CommandHandlerFunctionV2 | undefined\n}\n\nexport type TypePullClientEmitConfig = {\n  type: SubscriptionType\n  moduleId?: string\n  data?: Record<string, any>\n}\n\nexport enum CloseReasons {\n  NORMAL_CLOSURE = 1000,\n  SERVER_DIE = 1001,\n  CONFIG_REPLACED = 3000,\n  CHANNEL_EXPIRED = 3001,\n  SERVER_RESTARTED = 3002,\n  CONFIG_EXPIRED = 3003,\n  MANUAL = 3004,\n  STUCK = 3005,\n  WRONG_CHANNEL_ID = 4010\n}\n\nexport enum SystemCommands {\n  CHANNEL_EXPIRE = 'CHANNEL_EXPIRE',\n  CONFIG_EXPIRE = 'CONFIG_EXPIRE',\n  SERVER_RESTART = 'SERVER_RESTART'\n}\n\nexport enum ServerMode {\n  Shared = 'shared',\n  Personal = 'personal'\n}\n\nexport type RpcError = {\n  code: number\n  message: string\n}\n\nexport const ListRpcError = {\n  Parse: { code: -32700, message: 'Parse error' } as RpcError,\n  InvalidRequest: { code: -32600, message: 'Invalid Request' } as RpcError,\n  MethodNotFound: { code: -32601, message: 'Method not found' } as RpcError,\n  InvalidParams: { code: -32602, message: 'Invalid params' } as RpcError,\n  Internal: { code: -32603, message: 'Internal error' } as RpcError\n} as const\n\nexport type JsonRpcRequest = {\n  method: string\n  params: any\n  id: number\n}\n\nexport type RpcCommand = {\n  jsonrpc: string\n  method: string\n  params: any\n  id: number\n}\n\nexport type RpcRequest = RpcCommand & {}\n\nexport type RpcCommandResult = {\n  jsonrpc?: string\n  id?: number\n  /**\n   * @fix this TypeRpcResponseAwaiters.resolve(response)\n   */\n  result?: any\n  error?: RpcError\n}\n\nexport enum RpcMethod {\n  Publish = 'publish',\n  GetUsersLastSeen = 'getUsersLastSeen',\n  Ping = 'ping',\n  ListChannels = 'listChannels',\n  SubscribeStatusChange = 'subscribeStatusChange',\n  UnsubscribeStatusChange = 'unsubscribeStatusChange'\n}\n\nexport type TypeRpcResponseAwaiters = {\n  /**\n   * @fix this RpcCommandResult.result\n   */\n  resolve: (response: any) => void\n  reject: (error: string | RpcError) => void\n  timeout: number\n}\n\nexport type TypeJsonRpcConfig = {\n  connector: TypeConnector\n  handlers: Record<string, (params: any) => RpcCommandResult>\n}\n\nexport type TypePublicIdDescriptor = {\n  id?: string\n  user_id?: NumberString\n  public_id?: string\n  signature?: string\n  start: ISODate\n  end: ISODate\n  type?: string\n}\n\nexport type TypeChanel = {\n  userId: number\n  publicId: string\n  signature: string\n  start: Date\n  end: Date\n}\n\nexport type TypeChannelManagerParams = {\n  b24: TypeB24\n  getPublicListMethod: string\n}\n\nexport type TypePullClientSession = {\n  mid: null | string\n  tag: null | string\n  time: null | number\n  history: any\n  lastMessageIds: string[]\n  messageCount: number\n}\n\nexport type TypeSessionEvent = {\n  mid: string\n  tag?: string\n  time?: number\n  text: Record<string, any> | TypePullClientMessageBody\n}\n\nexport type TypePullClientParams = {\n  b24: TypeB24\n  skipCheckRevision?: boolean\n  restApplication?: string\n  siteId?: string\n\n  guestMode?: boolean\n  guestUserId?: number\n\n  userId?: number\n\n  serverEnabled?: boolean\n  configGetMethod?: string\n  getPublicListMethod?: string\n  skipStorageInit?: boolean\n  configTimestamp?: number\n}\n\nexport type TypePullClientConfig = {\n  /**\n   * @fix this\n   */\n  clientId: null\n  api: {\n    revision_mobile: number\n    revision_web: number\n  }\n  channels: {\n    private?: TypePublicIdDescriptor\n    shared?: TypePublicIdDescriptor\n  }\n  publicChannels: Record<string, TypePublicIdDescriptor>\n  server: {\n    timeShift: number\n    config_timestamp: number\n    long_polling: string\n    long_pooling_secure: string\n    mode: string\n    publish: string\n    publish_enabled: boolean\n    publish_secure: string\n    server_enabled: boolean\n    version: number\n    websocket: string\n    websocket_enabled: boolean\n    websocket_secure: string\n  }\n  jwt: null | string\n  exp: number\n}\n\nexport type TypePullClientMessageBatch = {\n  userList?: number[]\n  channelList?: (\n    | string\n    | {\n      publicId: string\n      signature: string\n    }\n  )[]\n  body: TypePullClientMessageBody\n  expiry?: number\n}\n"],"names":["ConnectionType","LsKeys","PullStatus","SenderType","SubscriptionType","CloseReasons","SystemCommands","ServerMode","RpcMethod"],"mappings":";;;;;;;;AAwBO,IAAK,cAAA,qBAAAA,eAAAA,KAAL;AACL,EAAAA,gBAAA,WAAA,CAAA,GAAY,WAAA;AACZ,EAAAA,gBAAA,WAAA,CAAA,GAAY,WAAA;AACZ,EAAAA,gBAAA,aAAA,CAAA,GAAc,aAAA;A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