@mtcute/core 0.12.1 → 0.12.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -22,19 +22,21 @@ function _initializeClient(opts) {
22
22
  this.log = this._client.log;
23
23
  // @ts-expect-error codegen
24
24
  this.storage = this._client.storage;
25
- const skipConversationUpdates = opts.skipConversationUpdates ?? true;
26
- const { messageGroupingInterval } = opts.updates ?? {};
27
- this._client.onUpdate(makeParsedUpdateHandler({
28
- messageGroupingInterval,
29
- onUpdate: (update) => {
30
- if (Conversation.handleUpdate(this._client, update) && skipConversationUpdates)
31
- return;
32
- this.emit('update', update);
33
- this.emit(update.name, update.data);
34
- },
35
- onRawUpdate: (update, peers) => {
36
- this.emit('raw_update', update, peers);
37
- },
38
- }));
25
+ if (!opts.disableUpdates) {
26
+ const skipConversationUpdates = opts.skipConversationUpdates ?? true;
27
+ const { messageGroupingInterval } = opts.updates ?? {};
28
+ this._client.onUpdate(makeParsedUpdateHandler({
29
+ messageGroupingInterval,
30
+ onUpdate: (update) => {
31
+ if (Conversation.handleUpdate(this._client, update) && skipConversationUpdates)
32
+ return;
33
+ this.emit('update', update);
34
+ this.emit(update.name, update.data);
35
+ },
36
+ onRawUpdate: (update, peers) => {
37
+ this.emit('raw_update', update, peers);
38
+ },
39
+ }));
40
+ }
39
41
  }
40
42
  //# sourceMappingURL=_init.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"_init.js","sourceRoot":"","sources":["../../../../src/highlevel/methods/_init.ts"],"names":[],"mappings":"AAAA,sDAAsD;AAEtD,QAAQ;AACR,OAAO,EAAE,kBAAkB,EAAe,MAAM,sBAAsB,CAAA;AACtE,OAAO,EAAE,kBAAkB,EAA6B,MAAM,YAAY,CAAA;AAK1E,QAAQ;AACR,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AACvD,QAAQ;AACR,OAAO,EAAE,uBAAuB,EAA6B,MAAM,sBAAsB,CAAA;AAwBzF,c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I,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,CAAC,CAAA;QAC1C,CAAC;KACJ,CAAC,CAAC,CAAA;AACP,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\n\n// @copy\nimport { MtUnsupportedError, PartialOnly } from '../../types/index.js'\nimport { BaseTelegramClient, BaseTelegramClientOptions } from '../base.js'\nimport { TelegramClient } from '../client.js'\nimport { ITelegramClient } from '../client.types.js'\n// @copy\nimport { ITelegramStorageProvider } from '../storage/provider.js'\n// @copy\nimport { Conversation } from '../types/conversation.js'\n// @copy\nimport { makeParsedUpdateHandler, ParsedUpdateHandlerParams } from '../updates/parsed.js'\n\n// @copy\ntype TelegramClientOptions = ((PartialOnly<Omit<BaseTelegramClientOptions, 'storage'>, 'transport' | 'crypto'> & {\n /**\n * Storage to use for this client.\n *\n * If a string is passed, it will be used as\n * a name for the default platform-specific storage provider to use.\n *\n * @default `\"client.session\"`\n */\n storage?: string | ITelegramStorageProvider\n}) | ({ client: ITelegramClient })) & {\n updates?: Omit<ParsedUpdateHandlerParams, 'onUpdate'>\n /**\n * If `true`, the updates that were handled by some {@link Conversation}\n * will not be dispatched any further.\n *\n * @default true\n */\n skipConversationUpdates?: boolean\n}\n\n// @initialize\n/** @internal */\nfunction _initializeClient(this: TelegramClient, opts: TelegramClientOptions) {\n if ('client' in opts) {\n this._client = opts.client\n } else {\n if (!opts.storage || typeof opts.storage === 'string' || !opts.transport || !opts.crypto) {\n throw new MtUnsupportedError('You need to explicitly provide storage, transport and crypto for @mtcute/core')\n }\n\n this._client = new BaseTelegramClient(opts as BaseTelegramClientOptions)\n }\n\n // @ts-expect-error codegen\n this.log = this._client.log\n // @ts-expect-error codegen\n this.storage = this._client.storage\n\n const skipConversationUpdates = opts.skipConversationUpdates ?? true\n const { messageGroupingInterval } = opts.updates ?? {}\n\n this._client.onUpdate(makeParsedUpdateHandler({\n messageGroupingInterval,\n onUpdate: (update) => {\n if (Conversation.handleUpdate(this._client, update) && skipConversationUpdates) return\n\n this.emit('update', update)\n this.emit(update.name, update.data)\n },\n onRawUpdate: (update, peers) => {\n this.emit('raw_update', update, peers)\n },\n }))\n}\n"]}
1
+ {"version":3,"file":"_init.js","sourceRoot":"","sources":["../../../../src/highlevel/methods/_init.ts"],"names":[],"mappings":"AAAA,sDAAsD;AAEtD,QAAQ;AACR,OAAO,EAAE,kBAAkB,EAAe,MAAM,sBAAsB,CAAA;AACtE,OAAO,EAAE,kBAAkB,EAA6B,MAAM,YAAY,CAAA;AAK1E,QAAQ;AACR,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AACvD,QAAQ;AACR,OAAO,EAAE,uBAAuB,EAA6B,MAAM,sBAAsB,CAAA;AAmCzF,cAAc;AACd,gBAAgB;AAChB,SAAS,iBAAiB,CAAuB,IAA2B;IACxE,IAAI,QAAQ,IAAI,IAAI,EAAE,CAAC;QACnB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,MAAM,CAAA;IAC9B,CAAC;SAAM,CAAC;QACJ,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,OAAO,IAAI,CAAC,OAAO,KAAK,QAAQ,IAAI,CAAC,IAAI,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YACvF,MAAM,IAAI,kBAAkB,CACxB,+EAA+E,CAClF,CAAA;QACL,CAAC;QAED,IAAI,CAAC,OAAO,GAAG,IAAI,kBAAkB,CAAC,IAAiC,CAAC,CAAA;IAC5E,CAAC;IAED,2BAA2B;IAC3B,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAA;IAC3B,2BAA2B;IAC3B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAA;IAEnC,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC;QACvB,MAAM,uBAAuB,GAAG,IAAI,CAAC,uBAAuB,IAAI,IAAI,CAAA;QACpE,MAAM,EAAE,uBAAuB,EAAE,GAAG,IAAI,CAAC,OAAO,IAAI,EAAE,CAAA;QAEtD,IAAI,CAAC,OAAO,CAAC,QAAQ,CACjB,uBAAuB,CAAC;YACpB,uBAAuB;YACvB,QAAQ,EAAE,CAAC,MAAM,EAAE,EAAE;gBACjB,IAAI,YAAY,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,uBAAuB;oBAAE,OAAM;gBAEtF,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;gBAC3B,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;YACvC,CAAC;YACD,WAAW,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;gBAC3B,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,CAAC,CAAA;YAC1C,CAAC;SACJ,CAAC,CACL,CAAA;IACL,CAAC;AACL,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\n\n// @copy\nimport { MtUnsupportedError, PartialOnly } from '../../types/index.js'\nimport { BaseTelegramClient, BaseTelegramClientOptions } from '../base.js'\nimport { TelegramClient } from '../client.js'\nimport { ITelegramClient } from '../client.types.js'\n// @copy\nimport { ITelegramStorageProvider } from '../storage/provider.js'\n// @copy\nimport { Conversation } from '../types/conversation.js'\n// @copy\nimport { makeParsedUpdateHandler, ParsedUpdateHandlerParams } from '../updates/parsed.js'\n\n// @copy\ntype TelegramClientOptions = (\n | (PartialOnly<Omit<BaseTelegramClientOptions, 'storage'>, 'transport' | 'crypto'> & {\n /**\n * Storage to use for this client.\n *\n * If a string is passed, it will be used as\n * a name for the default platform-specific storage provider to use.\n *\n * @default `\"client.session\"`\n */\n storage?: string | ITelegramStorageProvider\n })\n | { client: ITelegramClient }\n) & {\n /**\n * If true, all API calls will be wrapped with `tl.invokeWithoutUpdates`,\n * effectively disabling the server-sent events for the clients.\n * May be useful in some cases.\n *\n * @default false\n */\n disableUpdates?: boolean\n updates?: Omit<ParsedUpdateHandlerParams, 'onUpdate'>\n /**\n * If `true`, the updates that were handled by some {@link Conversation}\n * will not be dispatched any further.\n *\n * @default true\n */\n skipConversationUpdates?: boolean\n}\n\n// @initialize\n/** @internal */\nfunction _initializeClient(this: TelegramClient, opts: TelegramClientOptions) {\n if ('client' in opts) {\n this._client = opts.client\n } else {\n if (!opts.storage || typeof opts.storage === 'string' || !opts.transport || !opts.crypto) {\n throw new MtUnsupportedError(\n 'You need to explicitly provide storage, transport and crypto for @mtcute/core',\n )\n }\n\n this._client = new BaseTelegramClient(opts as BaseTelegramClientOptions)\n }\n\n // @ts-expect-error codegen\n this.log = this._client.log\n // @ts-expect-error codegen\n this.storage = this._client.storage\n\n if (!opts.disableUpdates) {\n const skipConversationUpdates = opts.skipConversationUpdates ?? true\n const { messageGroupingInterval } = opts.updates ?? {}\n\n this._client.onUpdate(\n makeParsedUpdateHandler({\n messageGroupingInterval,\n onUpdate: (update) => {\n if (Conversation.handleUpdate(this._client, update) && skipConversationUpdates) return\n\n this.emit('update', update)\n this.emit(update.name, update.data)\n },\n onRawUpdate: (update, peers) => {\n this.emit('raw_update', update, peers)\n },\n }),\n )\n }\n}\n"]}
@@ -94,14 +94,10 @@ export interface MtClientOptions {
94
94
  */
95
95
  maxRetryCount?: number;
96
96
  /**
97
- * If true, every single API call will be wrapped with `tl.invokeWithoutUpdates`,
97
+ * If true, all API calls will be wrapped with `tl.invokeWithoutUpdates`,
98
98
  * effectively disabling the server-sent events for the clients.
99
99
  * May be useful in some cases.
100
100
  *
101
- * Note that this only wraps calls made with `.call()` within the primary
102
- * connection. Additional connections and direct `.sendForResult()` calls
103
- * must be wrapped manually.
104
- *
105
101
  * @default false
106
102
  */
107
103
  disableUpdates?: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/network/client.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,OA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CAAA;QACrB,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAA;IACzB,CAAC;IAED;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,IAAI,CACN,OAAmC,EACnC,MAAuB;QAEvB,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAA;QAE9D,+DAA+D;QAC/D,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,CAAA;IACpD,CAAC;IAED;;;;OAIG;IACH,OAAO,CAAC,OAA+B;QACnC,IAAI,CAAC,SAAS,GAAG,OAAO,CAAA;IAC5B,CAAC;CACJ","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport EventEmitter from 'events'\n\nimport { tl } from '@mtcute/tl'\nimport { __tlReaderMap as defaultReaderMap } from '@mtcute/tl/binary/reader.js'\nimport { __tlWriterMap as defaultWriterMap } from '@mtcute/tl/binary/writer.js'\nimport { TlReaderMap, TlWriterMap } from '@mtcute/tl-runtime'\n\nimport { IMtStorageProvider } from '../storage/provider.js'\nimport { StorageManager, StorageManagerExtraOptions } from '../storage/storage.js'\nimport { MustEqual } from '../types/index.js'\nimport {\n asyncResettable,\n DcOptions,\n defaultProductionDc,\n defaultProductionIpv6Dc,\n defaultTestDc,\n defaultTestIpv6Dc,\n ICryptoProvider,\n Logger,\n LogManager,\n} from '../utils/index.js'\nimport { ConfigManager } from './config-manager.js'\nimport { NetworkManager, NetworkManagerExtraParams, RpcCallOptions } from './network-manager.js'\nimport { PersistentConnectionParams } from './persistent-connection.js'\nimport { ReconnectionStrategy } from './reconnection.js'\nimport { SessionConnection } from './session-connection.js'\nimport { TransportFactory } from './transports/index.js'\n\n/** Options for {@link MtClient} */\nexport interface MtClientOptions {\n /**\n * API ID from my.telegram.org\n */\n apiId: number\n /**\n * API hash from my.telegram.org\n */\n apiHash: string\n\n /**\n * Storage to use for this client.\n */\n storage: IMtStorageProvider\n\n /** Additional options for the storage manager */\n storageOptions?: StorageManagerExtraOptions\n\n /**\n * Cryptography provider to allow delegating\n * crypto to native addon, worker, etc.\n */\n crypto: ICryptoProvider\n\n /**\n * Whether to use IPv6 datacenters\n * (IPv6 will be preferred when choosing a DC by id)\n * (default: false)\n */\n useIpv6?: boolean\n\n /**\n * Primary DC to use for initial connection.\n * This does not mean this will be the only DC used,\n * nor that this DC will actually be primary, this only\n * determines the first DC the library will try to connect to.\n * Can be used to connect to other networks (like test DCs).\n *\n * When session already contains primary DC, this parameter is ignored.\n *\n * @default Production DC 2.\n */\n defaultDcs?: DcOptions\n\n /**\n * Whether to connect to test servers.\n *\n * If passed, {@link defaultDc} defaults to Test DC 2.\n *\n * **Must** be passed if using test servers, even if\n * you passed custom {@link defaultDc}\n */\n testMode?: boolean\n\n /**\n * Additional options for initConnection call.\n * `apiId` and `query` are not available and will be ignored.\n * Omitted values will be filled with defaults\n */\n initConnectionOptions?: Partial<Omit<tl.RawInitConnectionRequest, 'apiId' | 'query'>>\n\n /**\n * Transport factory to use in the client.\n *\n * @default platform-specific transport: WebSocket on the web, TCP in node\n */\n transport: TransportFactory\n\n /**\n * Reconnection strategy.\n *\n * @default simple reconnection strategy: first 0ms, then up to 5s (increasing by 1s)\n */\n reconnectionStrategy?: ReconnectionStrategy<PersistentConnectionParams>\n\n /**\n * Maximum duration of a flood_wait that will be waited automatically.\n * Flood waits above this threshold will throw a FloodWaitError.\n * Set to 0 to disable. Can be overridden with `throwFlood` parameter in call() params\n *\n * @default 10000\n */\n floodSleepThreshold?: number\n\n /**\n * Maximum number of retries when calling RPC methods.\n * Call is retried when InternalError or FloodWaitError is encountered.\n * Can be set to Infinity.\n *\n * @default 5\n */\n maxRetryCount?: number\n\n /**\n * If true, every single API call will be wrapped with `tl.invokeWithoutUpdates`,\n * effectively disabling the server-sent events for the clients.\n * May be useful in some cases.\n *\n * Note that this only wraps calls made with `.call()` within the primary\n * connection. Additional connections and direct `.sendForResult()` calls\n * must be wrapped manually.\n *\n * @default false\n */\n disableUpdates?: boolean\n\n /**\n * mtcute can send all unknown RPC errors to [danog](https://github.com/danog)'s\n * [error reporting service](https://rpc.pwrtelegram.xyz/).\n *\n * This is fully anonymous (except maybe IP) and is only used to improve the library\n * and developer experience for everyone working with MTProto. This is fully opt-in,\n * and if you're too paranoid, you can disable it by manually passing `enableErrorReporting: false` to the client.\n *\n * @default false\n */\n enableErrorReporting?: boolean\n\n /**\n * If true, RPC errors will have a stack trace of the initial `.call()`\n * or `.sendForResult()` call position, which drastically improves\n * debugging experience.<br>\n * If false, they will have a stack trace of mtcute internals.\n *\n * Internally this creates a stack capture before every RPC call\n * and stores it until the result is received. This might\n * use a lot more memory than normal, thus can be disabled here.\n *\n * @default true\n */\n niceStacks?: boolean\n\n /**\n * Extra parameters for {@link NetworkManager}\n */\n network?: NetworkManagerExtraParams\n\n /**\n * Logger instance for the client.\n * If not passed, a new one will be created.\n */\n logger?: Logger\n\n /**\n * Set logging level for the client.\n * Shorthand for `client.log.level = level`.\n *\n * See static members of {@link LogManager} for possible values.\n */\n logLevel?: number\n\n /**\n * **EXPERT USE ONLY!**\n *\n * Override TL layer used for the connection.\n *\n * **Does not** change the schema used.\n */\n overrideLayer?: number\n\n /**\n * **EXPERT USE ONLY**\n *\n * Override reader map used for the connection.\n */\n readerMap?: TlReaderMap\n\n /**\n * **EXPERT USE ONLY**\n *\n * Override writer map used for the connection.\n */\n writerMap?: TlWriterMap\n}\n\n/**\n * Basic MTProto client implementation, only doing the bare minimum\n * to make RPC calls and receive low-level updates, as well as providing\n * some APIs to manage that.\n */\nexport class MtClient extends EventEmitter {\n /**\n * Crypto provider taken from {@link MtClientOptions.crypto}\n */\n readonly crypto: ICryptoProvider\n\n /** Storage manager */\n readonly storage: StorageManager\n\n /**\n * \"Test mode\" taken from {@link MtClientOptions.testMode}\n */\n protected readonly _testMode: boolean\n\n /**\n * Primary DCs taken from {@link MtClientOptions.defaultDcs},\n * loaded from session or changed by other means (like redirecting).\n */\n _defaultDcs: DcOptions\n\n private _niceStacks: boolean\n /** TL layer used by the client */\n readonly _layer: number\n /** TL readers map used by the client */\n readonly _readerMap: TlReaderMap\n /** TL writers map used by the client */\n readonly _writerMap: TlWriterMap\n\n readonly _config = new ConfigManager(() => this.call({ _: 'help.getConfig' }))\n\n private _emitError?: (err: unknown, connection?: SessionConnection) => void\n\n readonly log: Logger\n readonly network: NetworkManager\n\n constructor(readonly params: MtClientOptions) {\n super()\n\n this.log = params.logger ?? new LogManager()\n\n if (params.logLevel !== undefined) {\n this.log.mgr.level = params.logLevel\n }\n\n this.crypto = params.crypto\n this._testMode = Boolean(params.testMode)\n\n let dc = params.defaultDcs\n\n if (!dc) {\n if (params.testMode) {\n dc = params.useIpv6 ? defaultTestIpv6Dc : defaultTestDc\n } else {\n dc = params.useIpv6 ? defaultProductionIpv6Dc : defaultProductionDc\n }\n }\n\n this._defaultDcs = dc\n this._niceStacks = params.niceStacks ?? true\n\n this._layer = params.overrideLayer ?? tl.LAYER\n this._readerMap = params.readerMap ?? defaultReaderMap\n this._writerMap = params.writerMap ?? defaultWriterMap\n\n this.storage = new StorageManager({\n provider: params.storage,\n log: this.log,\n readerMap: this._readerMap,\n writerMap: this._writerMap,\n ...params.storageOptions,\n })\n\n this.network = new NetworkManager(\n {\n apiId: params.apiId,\n crypto: this.crypto,\n disableUpdates: params.disableUpdates ?? false,\n initConnectionOptions: params.initConnectionOptions,\n layer: this._layer,\n log: this.log,\n readerMap: this._readerMap,\n writerMap: this._writerMap,\n reconnectionStrategy: params.reconnectionStrategy,\n storage: this.storage,\n testMode: Boolean(params.testMode),\n transport: params.transport,\n emitError: this.emitError.bind(this),\n floodSleepThreshold: params.floodSleepThreshold ?? 10000,\n maxRetryCount: params.maxRetryCount ?? 5,\n isPremium: false,\n useIpv6: Boolean(params.useIpv6),\n enableErrorReporting: params.enableErrorReporting ?? false,\n onUsable: () => this.emit('usable'),\n onConnecting: () => this.emit('connecting'),\n onNetworkChanged: (connected) => this.emit('networkChanged', connected),\n onUpdate: (upd) => this.emit('update', upd),\n ...params.network,\n },\n this._config,\n )\n }\n\n emitError(err: unknown, connection?: SessionConnection): void {\n if (this._emitError) {\n this._emitError(err, connection)\n } else {\n this.log.error('unhandled error:', err)\n }\n }\n\n private _prepare = asyncResettable(async () => {\n await this.crypto.initialize?.()\n await this.storage.load()\n\n const primaryDc = await this.storage.dcs.fetch()\n if (primaryDc !== null) this._defaultDcs = primaryDc\n })\n\n /**\n * **ADVANCED**\n *\n * Do all the preparations, but don't connect just yet.\n * Useful when you want to do some preparations before\n * connecting, like setting up session.\n *\n * Call {@link connect} to actually connect.\n */\n prepare() {\n return this._prepare.run()\n }\n\n private _connect = asyncResettable(async () => {\n await this._prepare.run()\n await this.network.connect(this._defaultDcs)\n })\n\n /**\n * Initialize the connection to the primary DC.\n *\n * You shouldn't usually call this method directly as it is called\n * implicitly the first time you call {@link call}.\n */\n async connect(): Promise<void> {\n return this._connect.run()\n }\n\n /**\n * Close all connections and finalize the client.\n */\n async close(): Promise<void> {\n this._config.destroy()\n await this.network.destroy()\n\n await this.storage.save()\n await this.storage.destroy?.()\n\n this._prepare.reset()\n this._connect.reset()\n }\n\n /**\n * Make an RPC call.\n *\n * The connection must have been {@link connect}-ed\n * before calling this method.\n *\n * This method is still quite low-level and you shouldn't use this\n * when using high-level API provided by `@mtcute/client`.\n *\n * @param message RPC method to call\n * @param params Additional call parameters\n */\n async call<T extends tl.RpcMethod>(\n message: MustEqual<T, tl.RpcMethod>,\n params?: RpcCallOptions,\n ): Promise<tl.RpcCallReturn[T['_']]> {\n const stack = this._niceStacks ? new Error().stack : undefined\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return this.network.call(message, params, stack)\n }\n\n /**\n * Register an error handler for the client\n *\n * @param handler Error handler.\n */\n onError(handler: (err: unknown) => void): void {\n this.emitError = handler\n }\n}\n"]}
1
+ {"version":3,"file":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AAC,OAAO,EAAE,EAAE,CAAA;QAE9B,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAA;QACrB,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAA;IACzB,CAAC;IAED;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,IAAI,CACN,OAAmC,EACnC,MAAuB;QAEvB,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAA;QAE9D,+DAA+D;QAC/D,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,CAAA;IACpD,CAAC;IAED;;;;OAIG;IACH,OAAO,CAAC,OAA+B;QACnC,IAAI,CAAC,SAAS,GAAG,OAAO,CAAA;IAC5B,CAAC;CACJ","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport EventEmitter from 'events'\n\nimport { tl } from '@mtcute/tl'\nimport { __tlReaderMap as defaultReaderMap } from '@mtcute/tl/binary/reader.js'\nimport { __tlWriterMap as defaultWriterMap } from '@mtcute/tl/binary/writer.js'\nimport { TlReaderMap, TlWriterMap } from '@mtcute/tl-runtime'\n\nimport { IMtStorageProvider } from '../storage/provider.js'\nimport { StorageManager, StorageManagerExtraOptions } from '../storage/storage.js'\nimport { MustEqual } from '../types/index.js'\nimport {\n asyncResettable,\n DcOptions,\n defaultProductionDc,\n defaultProductionIpv6Dc,\n defaultTestDc,\n defaultTestIpv6Dc,\n ICryptoProvider,\n Logger,\n LogManager,\n} from '../utils/index.js'\nimport { ConfigManager } from './config-manager.js'\nimport { NetworkManager, NetworkManagerExtraParams, RpcCallOptions } from './network-manager.js'\nimport { PersistentConnectionParams } from './persistent-connection.js'\nimport { ReconnectionStrategy } from './reconnection.js'\nimport { SessionConnection } from './session-connection.js'\nimport { TransportFactory } from './transports/index.js'\n\n/** Options for {@link MtClient} */\nexport interface MtClientOptions {\n /**\n * API ID from my.telegram.org\n */\n apiId: number\n /**\n * API hash from my.telegram.org\n */\n apiHash: string\n\n /**\n * Storage to use for this client.\n */\n storage: IMtStorageProvider\n\n /** Additional options for the storage manager */\n storageOptions?: StorageManagerExtraOptions\n\n /**\n * Cryptography provider to allow delegating\n * crypto to native addon, worker, etc.\n */\n crypto: ICryptoProvider\n\n /**\n * Whether to use IPv6 datacenters\n * (IPv6 will be preferred when choosing a DC by id)\n * (default: false)\n */\n useIpv6?: boolean\n\n /**\n * Primary DC to use for initial connection.\n * This does not mean this will be the only DC used,\n * nor that this DC will actually be primary, this only\n * determines the first DC the library will try to connect to.\n * Can be used to connect to other networks (like test DCs).\n *\n * When session already contains primary DC, this parameter is ignored.\n *\n * @default Production DC 2.\n */\n defaultDcs?: DcOptions\n\n /**\n * Whether to connect to test servers.\n *\n * If passed, {@link defaultDc} defaults to Test DC 2.\n *\n * **Must** be passed if using test servers, even if\n * you passed custom {@link defaultDc}\n */\n testMode?: boolean\n\n /**\n * Additional options for initConnection call.\n * `apiId` and `query` are not available and will be ignored.\n * Omitted values will be filled with defaults\n */\n initConnectionOptions?: Partial<Omit<tl.RawInitConnectionRequest, 'apiId' | 'query'>>\n\n /**\n * Transport factory to use in the client.\n *\n * @default platform-specific transport: WebSocket on the web, TCP in node\n */\n transport: TransportFactory\n\n /**\n * Reconnection strategy.\n *\n * @default simple reconnection strategy: first 0ms, then up to 5s (increasing by 1s)\n */\n reconnectionStrategy?: ReconnectionStrategy<PersistentConnectionParams>\n\n /**\n * Maximum duration of a flood_wait that will be waited automatically.\n * Flood waits above this threshold will throw a FloodWaitError.\n * Set to 0 to disable. Can be overridden with `throwFlood` parameter in call() params\n *\n * @default 10000\n */\n floodSleepThreshold?: number\n\n /**\n * Maximum number of retries when calling RPC methods.\n * Call is retried when InternalError or FloodWaitError is encountered.\n * Can be set to Infinity.\n *\n * @default 5\n */\n maxRetryCount?: number\n\n /**\n * If true, all API calls will be wrapped with `tl.invokeWithoutUpdates`,\n * effectively disabling the server-sent events for the clients.\n * May be useful in some cases.\n *\n * @default false\n */\n disableUpdates?: boolean\n\n /**\n * mtcute can send all unknown RPC errors to [danog](https://github.com/danog)'s\n * [error reporting service](https://rpc.pwrtelegram.xyz/).\n *\n * This is fully anonymous (except maybe IP) and is only used to improve the library\n * and developer experience for everyone working with MTProto. This is fully opt-in,\n * and if you're too paranoid, you can disable it by manually passing `enableErrorReporting: false` to the client.\n *\n * @default false\n */\n enableErrorReporting?: boolean\n\n /**\n * If true, RPC errors will have a stack trace of the initial `.call()`\n * or `.sendForResult()` call position, which drastically improves\n * debugging experience.<br>\n * If false, they will have a stack trace of mtcute internals.\n *\n * Internally this creates a stack capture before every RPC call\n * and stores it until the result is received. This might\n * use a lot more memory than normal, thus can be disabled here.\n *\n * @default true\n */\n niceStacks?: boolean\n\n /**\n * Extra parameters for {@link NetworkManager}\n */\n network?: NetworkManagerExtraParams\n\n /**\n * Logger instance for the client.\n * If not passed, a new one will be created.\n */\n logger?: Logger\n\n /**\n * Set logging level for the client.\n * Shorthand for `client.log.level = level`.\n *\n * See static members of {@link LogManager} for possible values.\n */\n logLevel?: number\n\n /**\n * **EXPERT USE ONLY!**\n *\n * Override TL layer used for the connection.\n *\n * **Does not** change the schema used.\n */\n overrideLayer?: number\n\n /**\n * **EXPERT USE ONLY**\n *\n * Override reader map used for the connection.\n */\n readerMap?: TlReaderMap\n\n /**\n * **EXPERT USE ONLY**\n *\n * Override writer map used for the connection.\n */\n writerMap?: TlWriterMap\n}\n\n/**\n * Basic MTProto client implementation, only doing the bare minimum\n * to make RPC calls and receive low-level updates, as well as providing\n * some APIs to manage that.\n */\nexport class MtClient extends EventEmitter {\n /**\n * Crypto provider taken from {@link MtClientOptions.crypto}\n */\n readonly crypto: ICryptoProvider\n\n /** Storage manager */\n readonly storage: StorageManager\n\n /**\n * \"Test mode\" taken from {@link MtClientOptions.testMode}\n */\n protected readonly _testMode: boolean\n\n /**\n * Primary DCs taken from {@link MtClientOptions.defaultDcs},\n * loaded from session or changed by other means (like redirecting).\n */\n _defaultDcs: DcOptions\n\n private _niceStacks: boolean\n /** TL layer used by the client */\n readonly _layer: number\n /** TL readers map used by the client */\n readonly _readerMap: TlReaderMap\n /** TL writers map used by the client */\n readonly _writerMap: TlWriterMap\n\n readonly _config = new ConfigManager(() => this.call({ _: 'help.getConfig' }))\n\n private _emitError?: (err: unknown, connection?: SessionConnection) => void\n\n readonly log: Logger\n readonly network: NetworkManager\n\n constructor(readonly params: MtClientOptions) {\n super()\n\n this.log = params.logger ?? new LogManager()\n\n if (params.logLevel !== undefined) {\n this.log.mgr.level = params.logLevel\n }\n\n this.crypto = params.crypto\n this._testMode = Boolean(params.testMode)\n\n let dc = params.defaultDcs\n\n if (!dc) {\n if (params.testMode) {\n dc = params.useIpv6 ? defaultTestIpv6Dc : defaultTestDc\n } else {\n dc = params.useIpv6 ? defaultProductionIpv6Dc : defaultProductionDc\n }\n }\n\n this._defaultDcs = dc\n this._niceStacks = params.niceStacks ?? true\n\n this._layer = params.overrideLayer ?? tl.LAYER\n this._readerMap = params.readerMap ?? defaultReaderMap\n this._writerMap = params.writerMap ?? defaultWriterMap\n\n this.storage = new StorageManager({\n provider: params.storage,\n log: this.log,\n readerMap: this._readerMap,\n writerMap: this._writerMap,\n ...params.storageOptions,\n })\n\n this.network = new NetworkManager(\n {\n apiId: params.apiId,\n crypto: this.crypto,\n disableUpdates: params.disableUpdates ?? false,\n initConnectionOptions: params.initConnectionOptions,\n layer: this._layer,\n log: this.log,\n readerMap: this._readerMap,\n writerMap: this._writerMap,\n reconnectionStrategy: params.reconnectionStrategy,\n storage: this.storage,\n testMode: Boolean(params.testMode),\n transport: params.transport,\n emitError: this.emitError.bind(this),\n floodSleepThreshold: params.floodSleepThreshold ?? 10000,\n maxRetryCount: params.maxRetryCount ?? 5,\n isPremium: false,\n useIpv6: Boolean(params.useIpv6),\n enableErrorReporting: params.enableErrorReporting ?? false,\n onUsable: () => this.emit('usable'),\n onConnecting: () => this.emit('connecting'),\n onNetworkChanged: (connected) => this.emit('networkChanged', connected),\n onUpdate: (upd) => this.emit('update', upd),\n ...params.network,\n },\n this._config,\n )\n }\n\n emitError(err: unknown, connection?: SessionConnection): void {\n if (this._emitError) {\n this._emitError(err, connection)\n } else {\n this.log.error('unhandled error:', err)\n }\n }\n\n private _prepare = asyncResettable(async () => {\n await this.crypto.initialize?.()\n await this.storage.load()\n\n const primaryDc = await this.storage.dcs.fetch()\n if (primaryDc !== null) this._defaultDcs = primaryDc\n })\n\n /**\n * **ADVANCED**\n *\n * Do all the preparations, but don't connect just yet.\n * Useful when you want to do some preparations before\n * connecting, like setting up session.\n *\n * Call {@link connect} to actually connect.\n */\n prepare() {\n return this._prepare.run()\n }\n\n private _connect = asyncResettable(async () => {\n await this._prepare.run()\n await this.network.connect(this._defaultDcs)\n })\n\n /**\n * Initialize the connection to the primary DC.\n *\n * You shouldn't usually call this method directly as it is called\n * implicitly the first time you call {@link call}.\n */\n async connect(): Promise<void> {\n return this._connect.run()\n }\n\n /**\n * Close all connections and finalize the client.\n */\n async close(): Promise<void> {\n this._config.destroy()\n await this.network.destroy()\n\n await this.storage.save()\n await this.storage.destroy?.()\n\n this._prepare.reset()\n this._connect.reset()\n }\n\n /**\n * Make an RPC call.\n *\n * The connection must have been {@link connect}-ed\n * before calling this method.\n *\n * This method is still quite low-level and you shouldn't use this\n * when using high-level API provided by `@mtcute/client`.\n *\n * @param message RPC method to call\n * @param params Additional call parameters\n */\n async call<T extends tl.RpcMethod>(\n message: MustEqual<T, tl.RpcMethod>,\n params?: RpcCallOptions,\n ): Promise<tl.RpcCallReturn[T['_']]> {\n const stack = this._niceStacks ? new Error().stack : undefined\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return this.network.call(message, params, stack)\n }\n\n /**\n * Register an error handler for the client\n *\n * @param handler Error handler.\n */\n onError(handler: (err: unknown) => void): void {\n this.emitError = handler\n }\n}\n"]}
@@ -244,7 +244,7 @@ export class NetworkManager {
244
244
  _: 'initConnection',
245
245
  deviceModel,
246
246
  systemVersion: '1.0',
247
- appVersion: '0.12.1',
247
+ appVersion: '0.12.2',
248
248
  systemLangCode: 'en',
249
249
  langPack: '', // "langPacks are for official apps only"
250
250
  langCode: 'en',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mtcute/core",
3
- "version": "0.12.1",
3
+ "version": "0.12.2",
4
4
  "description": "Type-safe library for MTProto (Telegram API)",
5
5
  "author": "alina sireneva <alina@tei.su>",
6
6
  "license": "MIT",