@bitrix24/b24jssdk 0.1.7 → 0.2.1

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.
@@ -294,6 +294,10 @@ declare class TypeManager {
294
294
  }
295
295
  declare const Type: TypeManager;
296
296
 
297
+ declare function pick<Data extends object, Keys extends keyof Data>(data: Data, keys: Keys[]): Pick<Data, Keys>;
298
+ declare function omit<Data extends object, Keys extends keyof Data>(data: Data, keys: Keys[]): Omit<Data, Keys>;
299
+ declare function isArrayOfArray<A>(item: A[] | A[][]): item is A[][];
300
+
297
301
  /**
298
302
  * The `Text` class provides a set of utility methods for working with text data.
299
303
  * It includes functions for encoding and decoding HTML entities, generating random strings,
@@ -383,50 +387,59 @@ declare const Browser: BrowserManager;
383
387
  /**
384
388
  * Interface defining the structure and methods of a Result object.
385
389
  */
386
- interface IResult {
390
+ interface IResult<T = any> {
387
391
  /**
388
392
  * Indicates whether the operation resulted in success (no errors).
389
393
  */
390
- isSuccess: boolean;
394
+ readonly isSuccess: boolean;
395
+ /**
396
+ * Collection of errors
397
+ */
398
+ readonly errors: Map<string, Error>;
391
399
  /**
392
400
  * Sets the data associated with the result.
393
401
  *
394
402
  * @param data The data to be stored in the result.
395
403
  * @returns The current Result object for chaining methods.
396
404
  */
397
- setData: (data: any) => IResult;
405
+ setData: (data: T) => IResult<T>;
398
406
  /**
399
407
  * Retrieves the data associated with the result.
400
408
  *
401
409
  * @returns The data stored in the result, if any.
402
410
  */
403
- getData: () => any;
411
+ getData: () => T | null;
404
412
  /**
405
413
  * Adds an error message or Error object to the result.
406
- *
407
414
  * @param error The error message or Error object to be added.
408
- * @returns The current Result object for chaining methods.
415
+ * @param key Error key. You can leave it blank. Then it will be generated automatically.
416
+ * @returns {IResult} The current Result object for chaining methods.
409
417
  */
410
- addError: (error: Error | string) => IResult;
418
+ addError: (error: Error | string, key?: string) => IResult;
411
419
  /**
412
420
  * Adds multiple errors to the result in a single call.
413
421
  *
414
422
  * @param errors An array of errors or strings that will be converted to errors.
415
- * @returns The current Result object for chaining methods.
423
+ * @returns {IResult} The current Result object for chaining methods.
416
424
  */
417
425
  addErrors: (errors: (Error | string)[]) => IResult;
418
426
  /**
419
427
  * Retrieves an iterator for the errors collected in the result.
420
428
  *
421
- * @returns An iterator over the stored Error objects.
429
+ * @returns {IterableIterator<Error>} An iterator over the stored Error objects.
422
430
  */
423
431
  getErrors: () => IterableIterator<Error>;
424
432
  /**
425
433
  * Retrieves an array of error messages from the collected errors.
426
434
  *
427
- * @returns An array of strings representing the error messages.
435
+ * @returns {string[]} An array of strings representing the error messages.
428
436
  */
429
437
  getErrorMessages: () => string[];
438
+ /**
439
+ * Checks for an error in a collection by key
440
+ * @param key - Error key
441
+ */
442
+ hasError(key: string): boolean;
430
443
  /**
431
444
  * Converts the Result object to a string.
432
445
  *
@@ -439,49 +452,18 @@ interface IResult {
439
452
  * Similar to \Bitrix\Main\Result from Bitrix Framework.
440
453
  * @link https://dev.1c-bitrix.ru/api_d7/bitrix/main/result/index.php
441
454
  */
442
- declare class Result implements IResult {
443
- private _errorCollection;
444
- protected _data: any;
445
- constructor();
446
- /**
447
- * Getter for the `isSuccess` property.
448
- * Checks if the `_errorCollection` is empty to determine success.
449
- *
450
- * @returns Whether the operation resulted in success (no errors).
451
- */
455
+ declare class Result<T = any> implements IResult<T> {
456
+ protected _errors: Map<string, Error>;
457
+ protected _data: T | null;
458
+ constructor(data?: T);
452
459
  get isSuccess(): boolean;
453
- /**
454
- * Sets the data associated with the result.
455
- *
456
- * @param data The data to be stored in the result.
457
- * @returns The current Result object for chaining methods.
458
- */
459
- setData(data: any): Result;
460
- /**
461
- * Retrieves the data associated with the result.
462
- *
463
- * @returns The data stored in the result, if any.
464
- */
465
- getData(): any;
466
- /**
467
- * Adds an error message or Error object to the result.
468
- *
469
- * @param error The error message or Error object to be added.
470
- * @returns The current Result object for chaining methods.
471
- */
472
- addError(error: Error | string): Result;
473
- /**
474
- * Adds multiple errors to the result in a single call.
475
- *
476
- * @param errors An array of errors or strings that will be converted to errors.
477
- * @returns The current Result object for chaining methods.
478
- */
479
- addErrors(errors: (Error | string)[]): Result;
480
- /**
481
- * Retrieves an iterator for the errors collected in the result.
482
- * @returns An iterator over the stored Error objects.
483
- */
460
+ get errors(): Map<string, Error>;
461
+ setData(data: T | null): Result<T>;
462
+ getData(): T | null;
463
+ addError(error: Error | string, key?: string): Result<T>;
464
+ addErrors(errors: (Error | string)[]): Result<T>;
484
465
  getErrors(): IterableIterator<Error>;
466
+ hasError(key: string): boolean;
485
467
  /**
486
468
  * Retrieves an array of error messages from the collected errors.
487
469
  *
@@ -495,6 +477,10 @@ declare class Result implements IResult {
495
477
  * @returns {string} Returns a string representation of the result operation
496
478
  */
497
479
  toString(): string;
480
+ private safeStringify;
481
+ private replacer;
482
+ static ok<U>(data?: U): Result<U>;
483
+ static fail<U>(error: Error | string, key?: string): Result<U>;
498
484
  }
499
485
 
500
486
  type PayloadTime = {
@@ -538,36 +524,52 @@ type BatchPayload<C> = {
538
524
  };
539
525
  type Payload<P> = GetPayload<P> | ListPayload<P> | BatchPayload<P>;
540
526
 
541
- type AjaxQuery = {
527
+ type AjaxQuery = Readonly<{
542
528
  method: string;
543
- params: object;
529
+ params: Readonly<object>;
544
530
  start: number;
545
- };
546
- type AjaxResultParams = {
531
+ }>;
532
+ type AjaxResultParams<T = unknown> = Readonly<{
547
533
  error?: string | {
548
534
  error: string;
549
- error_description: string;
535
+ error_description?: string;
550
536
  };
551
537
  error_description?: string;
552
- result: any;
538
+ result: T;
553
539
  next?: NumberString;
554
540
  total?: NumberString;
555
- };
541
+ time: PayloadTime;
542
+ }>;
543
+ type AjaxResultOptions<T> = Readonly<{
544
+ answer: AjaxResultParams<T>;
545
+ query: AjaxQuery;
546
+ status: number;
547
+ }>;
556
548
  /**
557
549
  * Result of request to Rest Api
558
550
  */
559
- declare class AjaxResult extends Result implements IResult {
551
+ declare class AjaxResult<T = unknown> extends Result<Payload<T>> implements IResult<Payload<T>> {
552
+ #private;
560
553
  private readonly _status;
561
554
  private readonly _query;
562
- protected _data: AjaxResultParams;
563
- constructor(answer: AjaxResultParams, query: AjaxQuery, status: number);
564
- setData(data: any): Result;
565
- getData(): Payload<unknown>;
555
+ protected _data: AjaxResultParams<T>;
556
+ constructor(options: AjaxResultOptions<T>);
557
+ getData(): Payload<T>;
558
+ /**
559
+ * Alias for isMore
560
+ */
561
+ hasMore(): boolean;
566
562
  isMore(): boolean;
567
563
  getTotal(): number;
568
564
  getStatus(): number;
569
- getQuery(): AjaxQuery;
570
- getNext(http: TypeHttp): Promise<false | AjaxResult>;
565
+ getQuery(): Readonly<AjaxQuery>;
566
+ /**
567
+ * Alias for getNext
568
+ * @param http
569
+ */
570
+ fetchNext(http: TypeHttp): Promise<AjaxResult<T> | null>;
571
+ getNext(http: TypeHttp): Promise<AjaxResult<T> | false>;
572
+ setData(): never;
571
573
  }
572
574
 
573
575
  type TypeHttp = {
@@ -1360,18 +1362,81 @@ type AjaxErrorParams = {
1360
1362
  answerError: AnswerError;
1361
1363
  cause?: Error;
1362
1364
  };
1365
+ type ErrorDetails = {
1366
+ code: string;
1367
+ description?: string;
1368
+ status: number;
1369
+ requestInfo?: {
1370
+ method?: string;
1371
+ url?: string;
1372
+ params?: Record<string, unknown> | unknown;
1373
+ };
1374
+ originalError?: unknown;
1375
+ };
1363
1376
  /**
1364
1377
  * Error requesting RestApi
1365
1378
  */
1366
1379
  declare class AjaxError extends Error {
1367
- cause: null | Error;
1380
+ readonly code: string;
1368
1381
  private _status;
1369
- private _answerError;
1370
- constructor(params: AjaxErrorParams);
1382
+ readonly requestInfo?: ErrorDetails['requestInfo'];
1383
+ readonly timestamp: Date;
1384
+ readonly originalError?: unknown;
1385
+ constructor(details: ErrorDetails);
1386
+ /**
1387
+ * @deprecated
1388
+ */
1371
1389
  get answerError(): AnswerError;
1372
1390
  get status(): number;
1391
+ /**
1392
+ * @deprecated
1393
+ */
1373
1394
  set status(status: number);
1395
+ /**
1396
+ * Creates AjaxError from HTTP response
1397
+ */
1398
+ static fromResponse(response: {
1399
+ status: number;
1400
+ data?: {
1401
+ error?: string;
1402
+ error_description?: string;
1403
+ };
1404
+ config?: {
1405
+ method?: string;
1406
+ url?: string;
1407
+ params?: unknown;
1408
+ };
1409
+ }): AjaxError;
1410
+ /**
1411
+ * Creates AjaxError from exception
1412
+ */
1413
+ static fromException(error: unknown, context?: {
1414
+ code?: string;
1415
+ status?: number;
1416
+ requestInfo?: ErrorDetails['requestInfo'];
1417
+ }): AjaxError;
1418
+ /**
1419
+ * Serializes error for logging and debugging
1420
+ */
1421
+ toJSON(): {
1422
+ name: string;
1423
+ code: string;
1424
+ message: string;
1425
+ status: number;
1426
+ timestamp: string;
1427
+ requestInfo: {
1428
+ method?: string;
1429
+ url?: string;
1430
+ params?: Record<string, unknown> | unknown;
1431
+ } | undefined;
1432
+ stack: string | undefined;
1433
+ };
1434
+ /**
1435
+ * Formats error information for human-readable output
1436
+ */
1374
1437
  toString(): string;
1438
+ private static formatErrorMessage;
1439
+ private cleanErrorStack;
1375
1440
  }
1376
1441
 
1377
1442
  declare abstract class AbstractB24 implements TypeB24 {
@@ -1724,11 +1789,13 @@ declare class AppFrame {
1724
1789
  * Parent Window Request Parameters
1725
1790
  * @prop isSafely auto completion mode Promise.resolve()
1726
1791
  * @prop safelyTime after what time (900 ms) should it be automatically resolved Promise
1792
+ * @prop callBack for placement event
1727
1793
  */
1728
1794
  interface SendParams {
1729
1795
  [index: string]: any;
1730
1796
  isSafely?: boolean;
1731
1797
  safelyTime?: number;
1798
+ callBack?: (...args: any[]) => void;
1732
1799
  }
1733
1800
  /**
1734
1801
  * Parent Window Communication Manager at B24
@@ -1736,7 +1803,7 @@ interface SendParams {
1736
1803
  declare class MessageManager {
1737
1804
  #private;
1738
1805
  protected _logger: null | LoggerBrowser;
1739
- private runCallbackHandler;
1806
+ private readonly runCallbackHandler;
1740
1807
  constructor(appFrame: AppFrame);
1741
1808
  setLogger(logger: LoggerBrowser): void;
1742
1809
  getLogger(): LoggerBrowser;
@@ -2162,11 +2229,12 @@ declare class PlacementManager {
2162
2229
  /**
2163
2230
  * Set Up the Interface Event Handler
2164
2231
  * @param {string} eventName
2232
+ * @param {(...args: any[]) => void} callBack
2165
2233
  * @return {Promise<any>}
2166
2234
  *
2167
2235
  * @link https://apidocs.bitrix24.com/api-reference/widgets/ui-interaction/bx24-placement-bind-event.html
2168
2236
  */
2169
- bindEvent(eventName: string): Promise<any>;
2237
+ bindEvent(eventName: string, callBack: (...args: any[]) => void): Promise<any>;
2170
2238
  /**
2171
2239
  * Call the Registered Interface Command
2172
2240
  * @param {string} command
@@ -2868,4 +2936,4 @@ declare class PullClient implements ConnectorParent {
2868
2936
 
2869
2937
  declare function initializeB24Frame(): Promise<B24Frame>;
2870
2938
 
2871
- export { AbstractB24, AjaxError, type AjaxErrorParams, type AjaxQuery, AjaxResult, type AjaxResultParams, type AnswerError, AppFrame, type AuthActions, type AuthData, AuthHookManager, AuthManager, B24Frame, type B24FrameQueryParams, B24Hook, type B24HookParams, B24LangList, PullClient as B24PullClientManager, type BatchPayload, type BoolString, Browser, CloseReasons, type CommandHandlerFunctionV1, type CommandHandlerFunctionV2, ConnectionType, type ConnectorCallbacks, type ConnectorConfig, type ConnectorParent, type Currency, type CurrencyFormat, DataType, DialogManager, EnumAppStatus, EnumCrmEntityType, EnumCrmEntityTypeId, type Fields, type GenderString, type GetPayload, type IPlacementUF, type IRequestIdGenerator, type IResult, type ISODate, type JsonRpcRequest, type ListPayload, ListRpcError, LoadDataType, LoggerBrowser, LoggerType, LsKeys, MessageCommands, type MessageInitData, MessageManager, type MultiField, type MultiFieldArray, type NumberString, OptionsManager$1 as OptionsManager, ParentManager, type Payload, type PayloadTime, PlacementManager, type PlacementViewMode, PullStatus, type RefreshAuthData, RestrictionManagerParamsBase, RestrictionManagerParamsForEnterprise, Result, type RpcCommand, type RpcCommandResult, type RpcError, RpcMethod, type RpcRequest, type SelectCRMParams, type SelectCRMParamsEntityType, type SelectCRMParamsValue, type SelectedAccess, type SelectedCRM, type SelectedCRMEntity, type SelectedUser, type SendParams, SenderType, ServerMode, type SharedConfigCallbacks, type SharedConfigParams, SliderManager, type StatusClose, StatusDescriptions, type StorageManagerParams, SubscriptionType, SystemCommands, Text, Type, type TypeApp, type TypeB24, type TypeB24Form, type TypeChanel, type TypeChannelManagerParams, type TypeConnector, type TypeDescriptionError, type TypeEnumAppStatus, type TypeHttp, type TypeJsonRpcConfig, type TypeLicense, TypeOption, type TypePayment, type TypePublicIdDescriptor, type TypePullClientConfig, type TypePullClientEmitConfig, type TypePullClientMessageBatch, type TypePullClientMessageBody, type TypePullClientParams, type TypePullClientSession, type TypePullMessage, type TypeRestrictionManagerParams, type TypeRpcResponseAwaiters, type TypeSessionEvent, TypeSpecificUrl, type TypeStorageManager, type TypeSubscriptionCommandHandler, type TypeSubscriptionOptions, type TypeUser, type UserBasic, type UserBrief, type UserFieldType, type UserStatusCallback, initializeB24Frame, useB24Helper, useFormatter };
2939
+ export { AbstractB24, AjaxError, type AjaxErrorParams, type AjaxQuery, AjaxResult, type AjaxResultParams, type AnswerError, AppFrame, type AuthActions, type AuthData, AuthHookManager, AuthManager, B24Frame, type B24FrameQueryParams, B24Hook, type B24HookParams, B24LangList, PullClient as B24PullClientManager, type BatchPayload, type BoolString, Browser, CloseReasons, type CommandHandlerFunctionV1, type CommandHandlerFunctionV2, ConnectionType, type ConnectorCallbacks, type ConnectorConfig, type ConnectorParent, type Currency, type CurrencyFormat, DataType, DialogManager, EnumAppStatus, EnumCrmEntityType, EnumCrmEntityTypeId, type Fields, type GenderString, type GetPayload, type IPlacementUF, type IRequestIdGenerator, type IResult, type ISODate, type JsonRpcRequest, type ListPayload, ListRpcError, LoadDataType, LoggerBrowser, LoggerType, LsKeys, MessageCommands, type MessageInitData, MessageManager, type MultiField, type MultiFieldArray, type NumberString, OptionsManager$1 as OptionsManager, ParentManager, type Payload, type PayloadTime, PlacementManager, type PlacementViewMode, PullStatus, type RefreshAuthData, RestrictionManagerParamsBase, RestrictionManagerParamsForEnterprise, Result, type RpcCommand, type RpcCommandResult, type RpcError, RpcMethod, type RpcRequest, type SelectCRMParams, type SelectCRMParamsEntityType, type SelectCRMParamsValue, type SelectedAccess, type SelectedCRM, type SelectedCRMEntity, type SelectedUser, type SendParams, SenderType, ServerMode, type SharedConfigCallbacks, type SharedConfigParams, SliderManager, type StatusClose, StatusDescriptions, type StorageManagerParams, SubscriptionType, SystemCommands, Text, Type, type TypeApp, type TypeB24, type TypeB24Form, type TypeChanel, type TypeChannelManagerParams, type TypeConnector, type TypeDescriptionError, type TypeEnumAppStatus, type TypeHttp, type TypeJsonRpcConfig, type TypeLicense, TypeOption, type TypePayment, type TypePublicIdDescriptor, type TypePullClientConfig, type TypePullClientEmitConfig, type TypePullClientMessageBatch, type TypePullClientMessageBody, type TypePullClientParams, type TypePullClientSession, type TypePullMessage, type TypeRestrictionManagerParams, type TypeRpcResponseAwaiters, type TypeSessionEvent, TypeSpecificUrl, type TypeStorageManager, type TypeSubscriptionCommandHandler, type TypeSubscriptionOptions, type TypeUser, type UserBasic, type UserBrief, type UserFieldType, type UserStatusCallback, initializeB24Frame, isArrayOfArray, omit, pick, useB24Helper, useFormatter };