@bitrix24/b24jssdk 0.4.10 → 1.0.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.
Files changed (258) hide show
  1. package/README-AI.md +2 -1
  2. package/dist/esm/_virtual/_commonjsHelpers.mjs +16 -0
  3. package/dist/esm/_virtual/_commonjsHelpers.mjs.map +1 -0
  4. package/dist/esm/_virtual/protobuf.mjs +16 -0
  5. package/dist/esm/_virtual/protobuf.mjs.map +1 -0
  6. package/dist/esm/_virtual/protobuf2.mjs +12 -0
  7. package/dist/esm/_virtual/protobuf2.mjs.map +1 -0
  8. package/dist/esm/core/abstract-b24.mjs +355 -0
  9. package/dist/esm/core/abstract-b24.mjs.map +1 -0
  10. package/dist/esm/core/actions/abstract-action.mjs +24 -0
  11. package/dist/esm/core/actions/abstract-action.mjs.map +1 -0
  12. package/dist/esm/core/actions/abstract-batch.mjs +95 -0
  13. package/dist/esm/core/actions/abstract-batch.mjs.map +1 -0
  14. package/dist/esm/core/actions/manager.mjs +53 -0
  15. package/dist/esm/core/actions/manager.mjs.map +1 -0
  16. package/dist/esm/core/actions/v2/batch-by-chunk.mjs +92 -0
  17. package/dist/esm/core/actions/v2/batch-by-chunk.mjs.map +1 -0
  18. package/dist/esm/core/actions/v2/batch.mjs +126 -0
  19. package/dist/esm/core/actions/v2/batch.mjs.map +1 -0
  20. package/dist/esm/core/actions/v2/call-list.mjs +131 -0
  21. package/dist/esm/core/actions/v2/call-list.mjs.map +1 -0
  22. package/dist/esm/core/actions/v2/call.mjs +68 -0
  23. package/dist/esm/core/actions/v2/call.mjs.map +1 -0
  24. package/dist/esm/core/actions/v2/fetch-list.mjs +132 -0
  25. package/dist/esm/core/actions/v2/fetch-list.mjs.map +1 -0
  26. package/dist/esm/core/actions/v2/manager-v2.mjs +74 -0
  27. package/dist/esm/core/actions/v2/manager-v2.mjs.map +1 -0
  28. package/dist/esm/core/actions/v3/batch-by-chunk.mjs +91 -0
  29. package/dist/esm/core/actions/v3/batch-by-chunk.mjs.map +1 -0
  30. package/dist/esm/core/actions/v3/batch.mjs +129 -0
  31. package/dist/esm/core/actions/v3/batch.mjs.map +1 -0
  32. package/dist/esm/core/actions/v3/call-list.mjs +127 -0
  33. package/dist/esm/core/actions/v3/call-list.mjs.map +1 -0
  34. package/dist/esm/core/actions/v3/call.mjs +58 -0
  35. package/dist/esm/core/actions/v3/call.mjs.map +1 -0
  36. package/dist/esm/core/actions/v3/fetch-list.mjs +125 -0
  37. package/dist/esm/core/actions/v3/fetch-list.mjs.map +1 -0
  38. package/dist/esm/core/actions/v3/manager-v3.mjs +74 -0
  39. package/dist/esm/core/actions/v3/manager-v3.mjs.map +1 -0
  40. package/dist/esm/core/http/abstract-http.mjs +563 -0
  41. package/dist/esm/core/http/abstract-http.mjs.map +1 -0
  42. package/dist/esm/core/http/ajax-error.mjs +107 -0
  43. package/dist/esm/core/http/ajax-error.mjs.map +1 -0
  44. package/dist/esm/core/http/ajax-result.mjs +176 -0
  45. package/dist/esm/core/http/ajax-result.mjs.map +1 -0
  46. package/dist/esm/core/http/limiters/adaptive-delayer.mjs +135 -0
  47. package/dist/esm/core/http/limiters/adaptive-delayer.mjs.map +1 -0
  48. package/dist/esm/core/http/limiters/manager.mjs +308 -0
  49. package/dist/esm/core/http/limiters/manager.mjs.map +1 -0
  50. package/dist/esm/core/http/limiters/operating-limiter.mjs +171 -0
  51. package/dist/esm/core/http/limiters/operating-limiter.mjs.map +1 -0
  52. package/dist/esm/core/http/limiters/params-factory.mjs +121 -0
  53. package/dist/esm/core/http/limiters/params-factory.mjs.map +1 -0
  54. package/dist/esm/core/http/limiters/rate-limiter.mjs +402 -0
  55. package/dist/esm/core/http/limiters/rate-limiter.mjs.map +1 -0
  56. package/dist/esm/core/http/v2.mjs +100 -0
  57. package/dist/esm/core/http/v2.mjs.map +1 -0
  58. package/dist/esm/core/http/v3.mjs +94 -0
  59. package/dist/esm/core/http/v3.mjs.map +1 -0
  60. package/dist/esm/core/interaction/batch/abstract-interaction-batch.mjs +69 -0
  61. package/dist/esm/core/interaction/batch/abstract-interaction-batch.mjs.map +1 -0
  62. package/dist/esm/core/interaction/batch/parse-row.mjs +67 -0
  63. package/dist/esm/core/interaction/batch/parse-row.mjs.map +1 -0
  64. package/dist/esm/core/interaction/batch/processing/interface-strategy.mjs +42 -0
  65. package/dist/esm/core/interaction/batch/processing/interface-strategy.mjs.map +1 -0
  66. package/dist/esm/core/interaction/batch/processing/v2/abstract-processing.mjs +121 -0
  67. package/dist/esm/core/interaction/batch/processing/v2/abstract-processing.mjs.map +1 -0
  68. package/dist/esm/core/interaction/batch/processing/v2/as-array.mjs +32 -0
  69. package/dist/esm/core/interaction/batch/processing/v2/as-array.mjs.map +1 -0
  70. package/dist/esm/core/interaction/batch/processing/v2/as-object.mjs +32 -0
  71. package/dist/esm/core/interaction/batch/processing/v2/as-object.mjs.map +1 -0
  72. package/dist/esm/core/interaction/batch/processing/v3/abstract-processing.mjs +118 -0
  73. package/dist/esm/core/interaction/batch/processing/v3/abstract-processing.mjs.map +1 -0
  74. package/dist/esm/core/interaction/batch/processing/v3/as-array.mjs +32 -0
  75. package/dist/esm/core/interaction/batch/processing/v3/as-array.mjs.map +1 -0
  76. package/dist/esm/core/interaction/batch/processing/v3/as-object.mjs +32 -0
  77. package/dist/esm/core/interaction/batch/processing/v3/as-object.mjs.map +1 -0
  78. package/dist/esm/core/interaction/batch/v2.mjs +44 -0
  79. package/dist/esm/core/interaction/batch/v2.mjs.map +1 -0
  80. package/dist/esm/core/interaction/batch/v3.mjs +42 -0
  81. package/dist/esm/core/interaction/batch/v3.mjs.map +1 -0
  82. package/dist/esm/core/language/list.mjs +56 -0
  83. package/dist/esm/core/language/list.mjs.map +1 -0
  84. package/dist/esm/core/request-id-generator.mjs +42 -0
  85. package/dist/esm/core/request-id-generator.mjs.map +1 -0
  86. package/dist/esm/core/result.mjs +101 -0
  87. package/dist/esm/core/result.mjs.map +1 -0
  88. package/dist/esm/core/sdk-error.mjs +83 -0
  89. package/dist/esm/core/sdk-error.mjs.map +1 -0
  90. package/dist/esm/core/tools/abstract-tool.mjs +24 -0
  91. package/dist/esm/core/tools/abstract-tool.mjs.map +1 -0
  92. package/dist/esm/core/tools/healthcheck.mjs +48 -0
  93. package/dist/esm/core/tools/healthcheck.mjs.map +1 -0
  94. package/dist/esm/core/tools/manager.mjs +50 -0
  95. package/dist/esm/core/tools/manager.mjs.map +1 -0
  96. package/dist/esm/core/tools/ping.mjs +56 -0
  97. package/dist/esm/core/tools/ping.mjs.map +1 -0
  98. package/dist/esm/core/version-manager.mjs +116 -0
  99. package/dist/esm/core/version-manager.mjs.map +1 -0
  100. package/dist/esm/frame/auth.mjs +98 -0
  101. package/dist/esm/frame/auth.mjs.map +1 -0
  102. package/dist/esm/frame/b24.mjs +170 -0
  103. package/dist/esm/frame/b24.mjs.map +1 -0
  104. package/dist/esm/frame/dialog.mjs +78 -0
  105. package/dist/esm/frame/dialog.mjs.map +1 -0
  106. package/dist/esm/frame/frame.mjs +101 -0
  107. package/dist/esm/frame/frame.mjs.map +1 -0
  108. package/dist/esm/frame/message/commands.mjs +37 -0
  109. package/dist/esm/frame/message/commands.mjs.map +1 -0
  110. package/dist/esm/frame/message/controller.mjs +177 -0
  111. package/dist/esm/frame/message/controller.mjs.map +1 -0
  112. package/dist/esm/frame/options.mjs +106 -0
  113. package/dist/esm/frame/options.mjs.map +1 -0
  114. package/dist/esm/frame/parent.mjs +250 -0
  115. package/dist/esm/frame/parent.mjs.map +1 -0
  116. package/dist/esm/frame/placement.mjs +131 -0
  117. package/dist/esm/frame/placement.mjs.map +1 -0
  118. package/dist/esm/frame/slider.mjs +156 -0
  119. package/dist/esm/frame/slider.mjs.map +1 -0
  120. package/dist/esm/helper/abstract-helper.mjs +52 -0
  121. package/dist/esm/helper/abstract-helper.mjs.map +1 -0
  122. package/dist/esm/helper/app-manager.mjs +37 -0
  123. package/dist/esm/helper/app-manager.mjs.map +1 -0
  124. package/dist/esm/helper/currency-manager.mjs +207 -0
  125. package/dist/esm/helper/currency-manager.mjs.map +1 -0
  126. package/dist/esm/helper/helper-manager.mjs +388 -0
  127. package/dist/esm/helper/helper-manager.mjs.map +1 -0
  128. package/dist/esm/helper/license-manager.mjs +50 -0
  129. package/dist/esm/helper/license-manager.mjs.map +1 -0
  130. package/dist/esm/helper/options-manager.mjs +196 -0
  131. package/dist/esm/helper/options-manager.mjs.map +1 -0
  132. package/dist/esm/helper/payment-manager.mjs +33 -0
  133. package/dist/esm/helper/payment-manager.mjs.map +1 -0
  134. package/dist/esm/helper/profile-manager.mjs +33 -0
  135. package/dist/esm/helper/profile-manager.mjs.map +1 -0
  136. package/dist/esm/helper/use-b24-helper.mjs +84 -0
  137. package/dist/esm/helper/use-b24-helper.mjs.map +1 -0
  138. package/dist/esm/hook/auth.mjs +77 -0
  139. package/dist/esm/hook/auth.mjs.map +1 -0
  140. package/dist/esm/hook/b24.mjs +115 -0
  141. package/dist/esm/hook/b24.mjs.map +1 -0
  142. package/dist/esm/index.d.mts +2757 -525
  143. package/dist/esm/index.d.ts +2757 -525
  144. package/dist/esm/index.mjs +70 -14111
  145. package/dist/esm/index.mjs.map +1 -1
  146. package/dist/esm/loader-b24frame.mjs +101 -0
  147. package/dist/esm/loader-b24frame.mjs.map +1 -0
  148. package/dist/esm/logger/abstract-logger.mjs +69 -0
  149. package/dist/esm/logger/abstract-logger.mjs.map +1 -0
  150. package/dist/esm/logger/browser.mjs +162 -0
  151. package/dist/esm/logger/browser.mjs.map +1 -0
  152. package/dist/esm/logger/formatter/abstract-formatter.mjs +34 -0
  153. package/dist/esm/logger/formatter/abstract-formatter.mjs.map +1 -0
  154. package/dist/esm/logger/formatter/json-formatter.mjs +34 -0
  155. package/dist/esm/logger/formatter/json-formatter.mjs.map +1 -0
  156. package/dist/esm/logger/formatter/line-formatter.mjs +41 -0
  157. package/dist/esm/logger/formatter/line-formatter.mjs.map +1 -0
  158. package/dist/esm/logger/formatter/telegram-formatter.mjs +103 -0
  159. package/dist/esm/logger/formatter/telegram-formatter.mjs.map +1 -0
  160. package/dist/esm/logger/handler/abstract-handler.mjs +39 -0
  161. package/dist/esm/logger/handler/abstract-handler.mjs.map +1 -0
  162. package/dist/esm/logger/handler/consola-adapter.mjs +62 -0
  163. package/dist/esm/logger/handler/consola-adapter.mjs.map +1 -0
  164. package/dist/esm/logger/handler/console-handler.mjs +98 -0
  165. package/dist/esm/logger/handler/console-handler.mjs.map +1 -0
  166. package/dist/esm/logger/handler/console-v2-handler.mjs +51 -0
  167. package/dist/esm/logger/handler/console-v2-handler.mjs.map +1 -0
  168. package/dist/esm/logger/handler/memory-handler.mjs +48 -0
  169. package/dist/esm/logger/handler/memory-handler.mjs.map +1 -0
  170. package/dist/esm/logger/handler/stream-handler.mjs +73 -0
  171. package/dist/esm/logger/handler/stream-handler.mjs.map +1 -0
  172. package/dist/esm/logger/handler/telegram-handler.mjs +157 -0
  173. package/dist/esm/logger/handler/telegram-handler.mjs.map +1 -0
  174. package/dist/esm/logger/handler/winston-adapter.mjs +57 -0
  175. package/dist/esm/logger/handler/winston-adapter.mjs.map +1 -0
  176. package/dist/esm/logger/logger-factory.mjs +67 -0
  177. package/dist/esm/logger/logger-factory.mjs.map +1 -0
  178. package/dist/esm/logger/logger.mjs +76 -0
  179. package/dist/esm/logger/logger.mjs.map +1 -0
  180. package/dist/esm/logger/null-logger.mjs +32 -0
  181. package/dist/esm/logger/null-logger.mjs.map +1 -0
  182. package/dist/esm/logger/processor/memory-usage-processor.mjs +20 -0
  183. package/dist/esm/logger/processor/memory-usage-processor.mjs.map +1 -0
  184. package/dist/esm/logger/processor/pid-processor.mjs +20 -0
  185. package/dist/esm/logger/processor/pid-processor.mjs.map +1 -0
  186. package/dist/esm/oauth/auth.mjs +211 -0
  187. package/dist/esm/oauth/auth.mjs.map +1 -0
  188. package/dist/esm/oauth/b24.mjs +117 -0
  189. package/dist/esm/oauth/b24.mjs.map +1 -0
  190. package/dist/esm/oauth/refresh-token-error.mjs +20 -0
  191. package/dist/esm/oauth/refresh-token-error.mjs.map +1 -0
  192. package/dist/esm/pullClient/abstract-connector.mjs +78 -0
  193. package/dist/esm/pullClient/abstract-connector.mjs.map +1 -0
  194. package/dist/esm/pullClient/channel-manager.mjs +89 -0
  195. package/dist/esm/pullClient/channel-manager.mjs.map +1 -0
  196. package/dist/esm/pullClient/client.mjs +2064 -0
  197. package/dist/esm/pullClient/client.mjs.map +1 -0
  198. package/dist/esm/pullClient/errors.mjs +31 -0
  199. package/dist/esm/pullClient/errors.mjs.map +1 -0
  200. package/dist/esm/pullClient/json-rpc.mjs +210 -0
  201. package/dist/esm/pullClient/json-rpc.mjs.map +1 -0
  202. package/dist/esm/pullClient/long-polling-connector.mjs +157 -0
  203. package/dist/esm/pullClient/long-polling-connector.mjs.map +1 -0
  204. package/dist/esm/pullClient/protobuf/index.mjs +17 -0
  205. package/dist/esm/pullClient/protobuf/index.mjs.map +1 -0
  206. package/dist/esm/pullClient/protobuf/model.mjs +1058 -0
  207. package/dist/esm/pullClient/protobuf/model.mjs.map +1 -0
  208. package/dist/esm/pullClient/protobuf/protobuf.mjs +4653 -0
  209. package/dist/esm/pullClient/protobuf/protobuf.mjs.map +1 -0
  210. package/dist/esm/pullClient/shared-config.mjs +133 -0
  211. package/dist/esm/pullClient/shared-config.mjs.map +1 -0
  212. package/dist/esm/pullClient/storage-manager.mjs +72 -0
  213. package/dist/esm/pullClient/storage-manager.mjs.map +1 -0
  214. package/dist/esm/pullClient/web-socket-connector.mjs +129 -0
  215. package/dist/esm/pullClient/web-socket-connector.mjs.map +1 -0
  216. package/dist/esm/tools/browser.mjs +154 -0
  217. package/dist/esm/tools/browser.mjs.map +1 -0
  218. package/dist/esm/tools/environment.mjs +29 -0
  219. package/dist/esm/tools/environment.mjs.map +1 -0
  220. package/dist/esm/tools/formatters/iban.mjs +304 -0
  221. package/dist/esm/tools/formatters/iban.mjs.map +1 -0
  222. package/dist/esm/tools/formatters/numbers.mjs +64 -0
  223. package/dist/esm/tools/formatters/numbers.mjs.map +1 -0
  224. package/dist/esm/tools/index.mjs +37 -0
  225. package/dist/esm/tools/index.mjs.map +1 -0
  226. package/dist/esm/tools/scroll-size.mjs +25 -0
  227. package/dist/esm/tools/scroll-size.mjs.map +1 -0
  228. package/dist/esm/tools/text.mjs +208 -0
  229. package/dist/esm/tools/text.mjs.map +1 -0
  230. package/dist/esm/tools/type.mjs +337 -0
  231. package/dist/esm/tools/type.mjs.map +1 -0
  232. package/dist/esm/tools/use-formatters.mjs +460 -0
  233. package/dist/esm/tools/use-formatters.mjs.map +1 -0
  234. package/dist/esm/tools/uuidv7.mjs +54 -0
  235. package/dist/esm/tools/uuidv7.mjs.map +1 -0
  236. package/dist/esm/types/b24-helper.mjs +56 -0
  237. package/dist/esm/types/b24-helper.mjs.map +1 -0
  238. package/dist/esm/types/b24.mjs +16 -0
  239. package/dist/esm/types/b24.mjs.map +1 -0
  240. package/dist/esm/types/bizproc/index.mjs +187 -0
  241. package/dist/esm/types/bizproc/index.mjs.map +1 -0
  242. package/dist/esm/types/catalog/index.mjs +35 -0
  243. package/dist/esm/types/catalog/index.mjs.map +1 -0
  244. package/dist/esm/types/common.mjs +31 -0
  245. package/dist/esm/types/common.mjs.map +1 -0
  246. package/dist/esm/types/crm/entity-type.mjs +57 -0
  247. package/dist/esm/types/crm/entity-type.mjs.map +1 -0
  248. package/dist/esm/types/crm/productrow.mjs +17 -0
  249. package/dist/esm/types/crm/productrow.mjs.map +1 -0
  250. package/dist/esm/types/logger.mjs +22 -0
  251. package/dist/esm/types/logger.mjs.map +1 -0
  252. package/dist/esm/types/pull.mjs +83 -0
  253. package/dist/esm/types/pull.mjs.map +1 -0
  254. package/dist/umd/index.js +31216 -26905
  255. package/dist/umd/index.js.map +1 -1
  256. package/dist/umd/index.min.js +63 -40
  257. package/dist/umd/index.min.js.map +1 -1
  258. package/package.json +36 -31
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manager.mjs","sources":["../../../../src/core/actions/manager.ts"],"sourcesContent":["import type { TypeB24 } from '../../types/b24'\nimport type { LoggerInterface } from '../../types/logger'\nimport { LoggerFactory } from '../../logger'\nimport { ApiVersion } from '../../types/b24'\nimport { ActionsManagerV2 } from './v2/manager-v2'\nimport { ActionsManagerV3 } from './v3/manager-v3'\n\nconst apiV2Name = Symbol(ApiVersion.v2)\nconst apiV3Name = Symbol(ApiVersion.v3)\n/**\n * Some actions for TypeB24\n */\nexport class ActionsManager {\n protected _b24: TypeB24\n protected _logger: LoggerInterface\n\n protected _mapActions: Map<symbol, any>\n\n constructor(b24: TypeB24) {\n this._b24 = b24\n this._logger = LoggerFactory.createNullLogger()\n\n this._mapActions = new Map()\n }\n\n public setLogger(logger: LoggerInterface): void {\n this._logger = logger\n this.v2.setLogger(this._logger)\n this.v3.setLogger(this._logger)\n }\n\n public getLogger(): LoggerInterface {\n return this._logger\n }\n\n get v2(): ActionsManagerV2 {\n if (!this._mapActions.has(apiV2Name)) {\n this._mapActions.set(apiV2Name, new ActionsManagerV2(this._b24))\n }\n return this._mapActions.get(apiV2Name)! as ActionsManagerV2\n }\n\n get v3(): ActionsManagerV3 {\n if (!this._mapActions.has(apiV3Name)) {\n this._mapActions.set(apiV3Name, new ActionsManagerV3(this._b24))\n }\n return this._mapActions.get(apiV3Name)! as ActionsManagerV3\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AAOA,MAAM,SAAA,GAAY,MAAA,CAAO,UAAA,CAAW,EAAE,CAAA;AACtC,MAAM,SAAA,GAAY,MAAA,CAAO,UAAA,CAAW,EAAE,CAAA;AAI/B,MAAM,cAAA,CAAe;AAAA,EAZ5B;AAY4B,IAAA,MAAA,CAAA,IAAA,EAAA,gBAAA,CAAA;AAAA;AAAA,EAChB,IAAA;AAAA,EACA,OAAA;AAAA,EAEA,WAAA;AAAA,EAEV,YAAY,GAAA,EAAc;AACxB,IAAA,IAAA,CAAK,IAAA,GAAO,GAAA;AACZ,IAAA,IAAA,CAAK,OAAA,GAAU,cAAc,gBAAA,EAAiB;AAE9C,IAAA,IAAA,CAAK,WAAA,uBAAkB,GAAA,EAAI;AAAA,EAC7B;AAAA,EAEO,UAAU,MAAA,EAA+B;AAC9C,IAAA,IAAA,CAAK,OAAA,GAAU,MAAA;AACf,IAAA,IAAA,CAAK,EAAA,CAAG,SAAA,CAAU,IAAA,CAAK,OAAO,CAAA;AAC9B,IAAA,IAAA,CAAK,EAAA,CAAG,SAAA,CAAU,IAAA,CAAK,OAAO,CAAA;AAAA,EAChC;AAAA,EAEO,SAAA,GAA6B;AAClC,IAAA,OAAO,IAAA,CAAK,OAAA;AAAA,EACd;AAAA,EAEA,IAAI,EAAA,GAAuB;AACzB,IAAA,IAAI,CAAC,IAAA,CAAK,WAAA,CAAY,GAAA,CAAI,SAAS,CAAA,EAAG;AACpC,MAAA,IAAA,CAAK,YAAY,GAAA,CAAI,SAAA,EAAW,IAAI,gBAAA,CAAiB,IAAA,CAAK,IAAI,CAAC,CAAA;AAAA,IACjE;AACA,IAAA,OAAO,IAAA,CAAK,WAAA,CAAY,GAAA,CAAI,SAAS,CAAA;AAAA,EACvC;AAAA,EAEA,IAAI,EAAA,GAAuB;AACzB,IAAA,IAAI,CAAC,IAAA,CAAK,WAAA,CAAY,GAAA,CAAI,SAAS,CAAA,EAAG;AACpC,MAAA,IAAA,CAAK,YAAY,GAAA,CAAI,SAAA,EAAW,IAAI,gBAAA,CAAiB,IAAA,CAAK,IAAI,CAAC,CAAA;AAAA,IACjE;AACA,IAAA,OAAO,IAAA,CAAK,WAAA,CAAY,GAAA,CAAI,SAAS,CAAA;AAAA,EACvC;AACF;;;;"}
@@ -0,0 +1,92 @@
1
+ /**
2
+ * @package @bitrix24/b24jssdk
3
+ * @version 1.0.1
4
+ * @copyright (c) 2026 Bitrix24
5
+ * @license MIT
6
+ * @see https://github.com/bitrix24/b24jssdk
7
+ * @see https://bitrix24.github.io/b24jssdk/
8
+ */
9
+ import { AbstractBatch } from '../abstract-batch.mjs';
10
+ import { ApiVersion } from '../../../types/b24.mjs';
11
+ import { Result } from '../../result.mjs';
12
+
13
+ var __defProp = Object.defineProperty;
14
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
15
+ class BatchByChunkV2 extends AbstractBatch {
16
+ static {
17
+ __name(this, "BatchByChunkV2");
18
+ }
19
+ /**
20
+ * Executes a batch request with automatic chunking for any number of commands.
21
+ * Unlike `BatchV2`, which is limited to 50 commands, this method automatically splits
22
+ * a large set of commands into multiple batches and executes them sequentially.
23
+ *
24
+ * @template T - The data type returned by commands (default: `unknown`)
25
+ *
26
+ * @param {ActionBatchByChunkV2} options - parameters for executing the request.
27
+ * - `calls: BatchCommandsArrayUniversal | BatchCommandsObjectUniversal` - Commands to execute in a batch.
28
+ * Supports several formats:
29
+ * 1. Array of tuples: `[['method1', params1], ['method2', params2], ...]`
30
+ * 2. Array of objects: `[{ method: 'method1', params: params1 }, { method: 'method2', params: params2 }, ...]`
31
+ * - Note: Named commands are not supported as they are difficult to process when chunking.
32
+ * - `options?: Omit<IB24BatchOptions, 'returnAjaxResult'>` - Additional options for executing a batch request.
33
+ * - `isHaltOnError?: boolean` - Whether to stop execution on the first error (default: true)
34
+ * - `requestId?: string` - Unique request identifier for tracking. Used for query deduplication and debugging (default: undefined)
35
+ *
36
+ * @returns {Promise<Result<T[]>>} A promise that is resolved by the result of executing all commands.
37
+ *
38
+ * @example
39
+ * import { EnumCrmEntityTypeId, Text } from '@bitrix24/b24jssdk'
40
+ *
41
+ * interface Contact { id: number, name: string }
42
+ * const commands = Array.from({ length: 150 }, (_, i) =>
43
+ * ['crm.item.get', { entityTypeId: EnumCrmEntityTypeId.contact, id: i + 1 }]
44
+ * )
45
+ *
46
+ * const response = await b24.actions.v2.batchByChunk.make<{ item: Contact }>({
47
+ * calls: commands,
48
+ * options: {
49
+ * isHaltOnError: false,
50
+ * requestId: 'batch-by-chunk-123'
51
+ * }
52
+ * })
53
+ * if (!response.isSuccess) {
54
+ * throw new Error(`Problem: ${response.getErrorMessages().join('; ')}`)
55
+ * }
56
+ *
57
+ * const resultData = response.getData()
58
+ * const items: Contact[] = []
59
+ * resultData.forEach((chunkRow) => {
60
+ * items.push(chunkRow.item)
61
+ * })
62
+ * console.log(`Successfully retrieved ${items.length} items`)
63
+ *
64
+ * @tip For very large command sets, consider using server-side task queues instead of bulk batch requests.
65
+ */
66
+ async make(options) {
67
+ const batchSize = 50;
68
+ const opts = {
69
+ ...options.options,
70
+ returnAjaxResult: false,
71
+ apiVersion: ApiVersion.v2
72
+ };
73
+ const result = new Result();
74
+ const dataResult = [];
75
+ const chunks = this.chunkArray(options.calls, batchSize);
76
+ for (const chunkRequest of chunks) {
77
+ const response = await this._b24.getHttpClient(ApiVersion.v2).batch(chunkRequest, opts);
78
+ if (!response.isSuccess) {
79
+ this._addBatchErrorsIfAny(response, result);
80
+ }
81
+ for (const [_index, data] of response.getData().result) {
82
+ if (data.isSuccess) {
83
+ dataResult.push(data.getData().result);
84
+ }
85
+ }
86
+ }
87
+ return result.setData(dataResult);
88
+ }
89
+ }
90
+
91
+ export { BatchByChunkV2 };
92
+ //# sourceMappingURL=batch-by-chunk.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"batch-by-chunk.mjs","sources":["../../../../../src/core/actions/v2/batch-by-chunk.ts"],"sourcesContent":["import type { ActionOptions } from '../abstract-action'\nimport type {\n BatchCommandsArrayUniversal,\n BatchCommandsObjectUniversal, BatchCommandsUniversal\n} from '../../../types/http'\nimport type { IB24BatchOptions } from '../../../types/b24'\nimport { AbstractBatch } from '../abstract-batch'\nimport { ApiVersion } from '../../../types/b24'\nimport { Result } from '../../result'\n\nexport type ActionBatchByChunkV2 = ActionOptions & {\n calls: BatchCommandsArrayUniversal | BatchCommandsObjectUniversal\n options?: Omit<IB24BatchOptions, 'returnAjaxResult'>\n}\n\n/**\n * Executes a batch request with automatic chunking for any number of commands. `restApi:v2`\n *\n * @todo add docs\n */\nexport class BatchByChunkV2 extends AbstractBatch {\n /**\n * Executes a batch request with automatic chunking for any number of commands.\n * Unlike `BatchV2`, which is limited to 50 commands, this method automatically splits\n * a large set of commands into multiple batches and executes them sequentially.\n *\n * @template T - The data type returned by commands (default: `unknown`)\n *\n * @param {ActionBatchByChunkV2} options - parameters for executing the request.\n * - `calls: BatchCommandsArrayUniversal | BatchCommandsObjectUniversal` - Commands to execute in a batch.\n * Supports several formats:\n * 1. Array of tuples: `[['method1', params1], ['method2', params2], ...]`\n * 2. Array of objects: `[{ method: 'method1', params: params1 }, { method: 'method2', params: params2 }, ...]`\n * - Note: Named commands are not supported as they are difficult to process when chunking.\n * - `options?: Omit<IB24BatchOptions, 'returnAjaxResult'>` - Additional options for executing a batch request.\n * - `isHaltOnError?: boolean` - Whether to stop execution on the first error (default: true)\n * - `requestId?: string` - Unique request identifier for tracking. Used for query deduplication and debugging (default: undefined)\n *\n * @returns {Promise<Result<T[]>>} A promise that is resolved by the result of executing all commands.\n *\n * @example\n * import { EnumCrmEntityTypeId, Text } from '@bitrix24/b24jssdk'\n *\n * interface Contact { id: number, name: string }\n * const commands = Array.from({ length: 150 }, (_, i) =>\n * ['crm.item.get', { entityTypeId: EnumCrmEntityTypeId.contact, id: i + 1 }]\n * )\n *\n * const response = await b24.actions.v2.batchByChunk.make<{ item: Contact }>({\n * calls: commands,\n * options: {\n * isHaltOnError: false,\n * requestId: 'batch-by-chunk-123'\n * }\n * })\n * if (!response.isSuccess) {\n * throw new Error(`Problem: ${response.getErrorMessages().join('; ')}`)\n * }\n *\n * const resultData = response.getData()\n * const items: Contact[] = []\n * resultData.forEach((chunkRow) => {\n * items.push(chunkRow.item)\n * })\n * console.log(`Successfully retrieved ${items.length} items`)\n *\n * @tip For very large command sets, consider using server-side task queues instead of bulk batch requests.\n */\n public override async make<T = unknown>(options: ActionBatchByChunkV2): Promise<Result<T[]>> {\n const batchSize = 50\n\n const opts = {\n ...options.options,\n returnAjaxResult: false,\n apiVersion: ApiVersion.v2\n }\n\n // callBatchByChunk\n const result = new Result<T[]>()\n\n const dataResult: T[] = []\n const chunks = this.chunkArray(options.calls as BatchCommandsUniversal, batchSize) as BatchCommandsArrayUniversal[] | BatchCommandsObjectUniversal[]\n\n for (const chunkRequest of chunks) {\n const response = await this._b24.getHttpClient(ApiVersion.v2).batch<T[]>(chunkRequest, opts)\n\n if (!response.isSuccess) {\n this._addBatchErrorsIfAny(response, result)\n }\n\n for (const [_index, data] of response.getData()!.result!) {\n // @memo Add only success rows\n if (data.isSuccess) {\n dataResult.push(data.getData()!.result)\n }\n }\n }\n\n return result.setData(dataResult)\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;AAoBO,MAAM,uBAAuB,aAAA,CAAc;AAAA,EApBlD;AAoBkD,IAAA,MAAA,CAAA,IAAA,EAAA,gBAAA,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAgDhD,MAAsB,KAAkB,OAAA,EAAqD;AAC3F,IAAA,MAAM,SAAA,GAAY,EAAA;AAElB,IAAA,MAAM,IAAA,GAAO;AAAA,MACX,GAAG,OAAA,CAAQ,OAAA;AAAA,MACX,gBAAA,EAAkB,KAAA;AAAA,MAClB,YAAY,UAAA,CAAW;AAAA,KACzB;AAGA,IAAA,MAAM,MAAA,GAAS,IAAI,MAAA,EAAY;AAE/B,IAAA,MAAM,aAAkB,EAAC;AACzB,IAAA,MAAM,MAAA,GAAS,IAAA,CAAK,UAAA,CAAW,OAAA,CAAQ,OAAiC,SAAS,CAAA;AAEjF,IAAA,KAAA,MAAW,gBAAgB,MAAA,EAAQ;AACjC,MAAA,MAAM,QAAA,GAAW,MAAM,IAAA,CAAK,IAAA,CAAK,aAAA,CAAc,WAAW,EAAE,CAAA,CAAE,KAAA,CAAW,YAAA,EAAc,IAAI,CAAA;AAE3F,MAAA,IAAI,CAAC,SAAS,SAAA,EAAW;AACvB,QAAA,IAAA,CAAK,oBAAA,CAAqB,UAAU,MAAM,CAAA;AAAA,MAC5C;AAEA,MAAA,KAAA,MAAW,CAAC,MAAA,EAAQ,IAAI,KAAK,QAAA,CAAS,OAAA,GAAW,MAAA,EAAS;AAExD,QAAA,IAAI,KAAK,SAAA,EAAW;AAClB,UAAA,UAAA,CAAW,IAAA,CAAK,IAAA,CAAK,OAAA,EAAQ,CAAG,MAAM,CAAA;AAAA,QACxC;AAAA,MACF;AAAA,IACF;AAEA,IAAA,OAAO,MAAA,CAAO,QAAQ,UAAU,CAAA;AAAA,EAClC;AACF;;;;"}
@@ -0,0 +1,126 @@
1
+ /**
2
+ * @package @bitrix24/b24jssdk
3
+ * @version 1.0.1
4
+ * @copyright (c) 2026 Bitrix24
5
+ * @license MIT
6
+ * @see https://github.com/bitrix24/b24jssdk
7
+ * @see https://bitrix24.github.io/b24jssdk/
8
+ */
9
+ import { AbstractBatch } from '../abstract-batch.mjs';
10
+ import { ApiVersion } from '../../../types/b24.mjs';
11
+
12
+ var __defProp = Object.defineProperty;
13
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
14
+ class BatchV2 extends AbstractBatch {
15
+ static {
16
+ __name(this, "BatchV2");
17
+ }
18
+ /**
19
+ * Executes a batch request to the Bitrix24 REST API with a maximum number of commands of no more than 50.
20
+ * Allows you to execute multiple requests in a single API call, significantly improving performance.
21
+ *
22
+ * @template T - The data type returned by batch query commands (default is `unknown`)
23
+ *
24
+ * @param {ActionBatchV2} options - parameters for executing the request.
25
+ * - `calls: BatchCommandsArrayUniversal | BatchCommandsObjectUniversal | BatchNamedCommandsUniversal` - Commands to execute in a batch.
26
+ * Supports several formats:
27
+ * 1. Array of tuples: `[['method1', params1], ['method2', params2], ...]`
28
+ * 2. Array of objects: `[{ method: 'method1', params: params1 }, { method: 'method2', params: params2 }, ...]`
29
+ * 3. An object with named commands: `{ cmd1: { method: 'method1', params: params1 }, cmd2: ['method2', params2], ...}`
30
+ * - `options?: IB24BatchOptions` - Additional options for executing a batch request.
31
+ * - `isHaltOnError?: boolean` - Whether to stop execution on the first error (default: true)
32
+ * - `requestId?: string` - Unique request identifier for tracking. Used for query deduplication and debugging (default: undefined)
33
+ * - `returnAjaxResult?: boolean` - Whether to return an AjaxResult object instead of data (default: false)
34
+ *
35
+ * @returns {Promise<CallBatchResult<T>>} A promise that is resolved by the result of executing a batch request:
36
+ * - On success: a `Result` object with the command execution results
37
+ * - The structure of the results depends on the format of the `calls` input data:
38
+ * - For an array of commands, an array of results in the same order
39
+ * - For named commands, an object with keys corresponding to the command names
40
+ *
41
+ * @example
42
+ * import { EnumCrmEntityTypeId } from '@bitrix24/b24jssdk'
43
+ *
44
+ * interface Contact { id: number, name: string }
45
+ * const response = await b24.actions.v2.batch.make<{ item: Contact }>({
46
+ * calls: [
47
+ * ['crm.item.get', { entityTypeId: EnumCrmEntityTypeId.contact, id: 1 }],
48
+ * ['crm.item.get', { entityTypeId: EnumCrmEntityTypeId.contact, id: 2 }],
49
+ * ['crm.item.get', { entityTypeId: EnumCrmEntityTypeId.contact, id: 3 }]
50
+ * ],
51
+ * options: {
52
+ * isHaltOnError: true,
53
+ * returnAjaxResult: true,
54
+ * requestId: 'batch-123'
55
+ * }
56
+ * })
57
+ * if (!response.isSuccess) {
58
+ * throw new Error(`Problem: ${response.getErrorMessages().join('; ')}`)
59
+ * }
60
+ *
61
+ * const resultData = (response as Result<AjaxResult<{ item: Contact }>[]>).getData()
62
+ * resultData.forEach((resultRow, index) => {
63
+ * if (resultRow.isSuccess) {
64
+ * console.log(`Item ${index + 1}:`, resultRow.getData().result.item)
65
+ * }
66
+ * })
67
+ *
68
+ * @example
69
+ * import { EnumCrmEntityTypeId } from '@bitrix24/b24jssdk'
70
+ *
71
+ * const response = await b24.actions.v2.batch.make({
72
+ * calls: [
73
+ * { method: 'crm.item.get', params: { entityTypeId: EnumCrmEntityTypeId.contact, id: 1 } },
74
+ * { method: 'crm.item.get', params: { entityTypeId: EnumCrmEntityTypeId.contact, id: 2 } }
75
+ * ],
76
+ * options: {
77
+ * isHaltOnError: true,
78
+ * returnAjaxResult: true,
79
+ * requestId: 'batch-123'
80
+ * }
81
+ * })
82
+ * if (!response.isSuccess) {
83
+ * throw new Error(`Problem: ${response.getErrorMessages().join('; ')}`)
84
+ * }
85
+ *
86
+ * @example
87
+ * import { EnumCrmEntityTypeId } from '@bitrix24/b24jssdk'
88
+ *
89
+ * interface Contact { id: number, name: string }
90
+ * interface Deal { id: number, title: string }
91
+ * const response = await b24.actions.v2.batch.make<{ item: Contact } | { item: Deal }>({
92
+ * calls: {
93
+ * Contact: { method: 'crm.item.get', params: { entityTypeId: EnumCrmEntityTypeId.contact, id: 1 } },
94
+ * Deal: ['crm.item.get', { entityTypeId: EnumCrmEntityTypeId.deal, id: 2 }]
95
+ * },
96
+ * options: {
97
+ * isHaltOnError: true,
98
+ * returnAjaxResult: true,
99
+ * requestId: 'batch-123'
100
+ * }
101
+ * })
102
+ * if (!response.isSuccess) {
103
+ * throw new Error(`Problem: ${response.getErrorMessages().join('; ')}`)
104
+ * }
105
+ *
106
+ * const results = response.getData() as Record<string, AjaxResult<{ item: Contact } | { item: Deal }>>
107
+ * console.log('Contact:', results.Contact.getData().result.item as Contact)
108
+ * console.log('Deal:', results.Deal.getData().result.item as Deal)
109
+ *
110
+ * @warning The maximum number of commands in one batch request is 50.
111
+ * @note A batch request executes faster than sequential single calls,
112
+ * but if one command fails, the entire batch may fail
113
+ * (depending on API settings and options).
114
+ */
115
+ async make(options) {
116
+ const opts = {
117
+ ...options.options,
118
+ apiVersion: ApiVersion.v2
119
+ };
120
+ const response = await this._b24.getHttpClient(ApiVersion.v2).batch(options.calls, opts);
121
+ return this._processBatchResponse(response, options.calls, opts);
122
+ }
123
+ }
124
+
125
+ export { BatchV2 };
126
+ //# sourceMappingURL=batch.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"batch.mjs","sources":["../../../../../src/core/actions/v2/batch.ts"],"sourcesContent":["import type { ActionOptions } from '../abstract-action'\nimport type { CallBatchResult, IB24BatchOptions } from '../../../types/b24'\nimport type {\n BatchCommandsArrayUniversal,\n BatchCommandsObjectUniversal,\n BatchNamedCommandsUniversal\n} from '../../../types/http'\nimport { AbstractBatch } from '../abstract-batch'\nimport { ApiVersion } from '../../../types/b24'\n\nexport type ActionBatchV2 = ActionOptions & {\n calls: BatchCommandsArrayUniversal | BatchCommandsObjectUniversal | BatchNamedCommandsUniversal\n options?: IB24BatchOptions\n}\n\n/**\n * Executes a batch request to the Bitrix24 REST API with a maximum number of commands of no more than 50. `restApi:v2`\n * Allows you to execute multiple requests in a single API call, significantly improving performance.\n *\n * @todo add docs\n */\nexport class BatchV2 extends AbstractBatch {\n /**\n * Executes a batch request to the Bitrix24 REST API with a maximum number of commands of no more than 50.\n * Allows you to execute multiple requests in a single API call, significantly improving performance.\n *\n * @template T - The data type returned by batch query commands (default is `unknown`)\n *\n * @param {ActionBatchV2} options - parameters for executing the request.\n * - `calls: BatchCommandsArrayUniversal | BatchCommandsObjectUniversal | BatchNamedCommandsUniversal` - Commands to execute in a batch.\n * Supports several formats:\n * 1. Array of tuples: `[['method1', params1], ['method2', params2], ...]`\n * 2. Array of objects: `[{ method: 'method1', params: params1 }, { method: 'method2', params: params2 }, ...]`\n * 3. An object with named commands: `{ cmd1: { method: 'method1', params: params1 }, cmd2: ['method2', params2], ...}`\n * - `options?: IB24BatchOptions` - Additional options for executing a batch request.\n * - `isHaltOnError?: boolean` - Whether to stop execution on the first error (default: true)\n * - `requestId?: string` - Unique request identifier for tracking. Used for query deduplication and debugging (default: undefined)\n * - `returnAjaxResult?: boolean` - Whether to return an AjaxResult object instead of data (default: false)\n *\n * @returns {Promise<CallBatchResult<T>>} A promise that is resolved by the result of executing a batch request:\n * - On success: a `Result` object with the command execution results\n * - The structure of the results depends on the format of the `calls` input data:\n * - For an array of commands, an array of results in the same order\n * - For named commands, an object with keys corresponding to the command names\n *\n * @example\n * import { EnumCrmEntityTypeId } from '@bitrix24/b24jssdk'\n *\n * interface Contact { id: number, name: string }\n * const response = await b24.actions.v2.batch.make<{ item: Contact }>({\n * calls: [\n * ['crm.item.get', { entityTypeId: EnumCrmEntityTypeId.contact, id: 1 }],\n * ['crm.item.get', { entityTypeId: EnumCrmEntityTypeId.contact, id: 2 }],\n * ['crm.item.get', { entityTypeId: EnumCrmEntityTypeId.contact, id: 3 }]\n * ],\n * options: {\n * isHaltOnError: true,\n * returnAjaxResult: true,\n * requestId: 'batch-123'\n * }\n * })\n * if (!response.isSuccess) {\n * throw new Error(`Problem: ${response.getErrorMessages().join('; ')}`)\n * }\n *\n * const resultData = (response as Result<AjaxResult<{ item: Contact }>[]>).getData()\n * resultData.forEach((resultRow, index) => {\n * if (resultRow.isSuccess) {\n * console.log(`Item ${index + 1}:`, resultRow.getData().result.item)\n * }\n * })\n *\n * @example\n * import { EnumCrmEntityTypeId } from '@bitrix24/b24jssdk'\n *\n * const response = await b24.actions.v2.batch.make({\n * calls: [\n * { method: 'crm.item.get', params: { entityTypeId: EnumCrmEntityTypeId.contact, id: 1 } },\n * { method: 'crm.item.get', params: { entityTypeId: EnumCrmEntityTypeId.contact, id: 2 } }\n * ],\n * options: {\n * isHaltOnError: true,\n * returnAjaxResult: true,\n * requestId: 'batch-123'\n * }\n * })\n * if (!response.isSuccess) {\n * throw new Error(`Problem: ${response.getErrorMessages().join('; ')}`)\n * }\n *\n * @example\n * import { EnumCrmEntityTypeId } from '@bitrix24/b24jssdk'\n *\n * interface Contact { id: number, name: string }\n * interface Deal { id: number, title: string }\n * const response = await b24.actions.v2.batch.make<{ item: Contact } | { item: Deal }>({\n * calls: {\n * Contact: { method: 'crm.item.get', params: { entityTypeId: EnumCrmEntityTypeId.contact, id: 1 } },\n * Deal: ['crm.item.get', { entityTypeId: EnumCrmEntityTypeId.deal, id: 2 }]\n * },\n * options: {\n * isHaltOnError: true,\n * returnAjaxResult: true,\n * requestId: 'batch-123'\n * }\n * })\n * if (!response.isSuccess) {\n * throw new Error(`Problem: ${response.getErrorMessages().join('; ')}`)\n * }\n *\n * const results = response.getData() as Record<string, AjaxResult<{ item: Contact } | { item: Deal }>>\n * console.log('Contact:', results.Contact.getData().result.item as Contact)\n * console.log('Deal:', results.Deal.getData().result.item as Deal)\n *\n * @warning The maximum number of commands in one batch request is 50.\n * @note A batch request executes faster than sequential single calls,\n * but if one command fails, the entire batch may fail\n * (depending on API settings and options).\n */\n public override async make<T = unknown>(options: ActionBatchV2): Promise<CallBatchResult<T>> {\n const opts = {\n ...options.options,\n apiVersion: ApiVersion.v2\n }\n\n const response = await this._b24.getHttpClient(ApiVersion.v2).batch<T>(options.calls, opts)\n\n return this._processBatchResponse<T>(response, options.calls, opts)\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;AAqBO,MAAM,gBAAgB,aAAA,CAAc;AAAA,EArB3C;AAqB2C,IAAA,MAAA,CAAA,IAAA,EAAA,SAAA,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAkGzC,MAAsB,KAAkB,OAAA,EAAqD;AAC3F,IAAA,MAAM,IAAA,GAAO;AAAA,MACX,GAAG,OAAA,CAAQ,OAAA;AAAA,MACX,YAAY,UAAA,CAAW;AAAA,KACzB;AAEA,IAAA,MAAM,QAAA,GAAW,MAAM,IAAA,CAAK,IAAA,CAAK,aAAA,CAAc,UAAA,CAAW,EAAE,CAAA,CAAE,KAAA,CAAS,OAAA,CAAQ,KAAA,EAAO,IAAI,CAAA;AAE1F,IAAA,OAAO,IAAA,CAAK,qBAAA,CAAyB,QAAA,EAAU,OAAA,CAAQ,OAAO,IAAI,CAAA;AAAA,EACpE;AACF;;;;"}
@@ -0,0 +1,131 @@
1
+ /**
2
+ * @package @bitrix24/b24jssdk
3
+ * @version 1.0.1
4
+ * @copyright (c) 2026 Bitrix24
5
+ * @license MIT
6
+ * @see https://github.com/bitrix24/b24jssdk
7
+ * @see https://bitrix24.github.io/b24jssdk/
8
+ */
9
+ import { AbstractAction } from '../abstract-action.mjs';
10
+ import { Result } from '../../result.mjs';
11
+
12
+ var __defProp = Object.defineProperty;
13
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
14
+ class CallListV2 extends AbstractAction {
15
+ static {
16
+ __name(this, "CallListV2");
17
+ }
18
+ /**
19
+ * Fast data retrieval without counting the total number of records.
20
+ *
21
+ * @template T - The type of the elements of the returned array (default is `unknown`).
22
+ *
23
+ * @param {ActionCallListV2} options - parameters for executing the request.
24
+ * - `method: string` - The name of the REST API method that returns a list of data (for example: `crm.item.list`, `tasks.task.list`)
25
+ * - `params?: Omit<TypeCallParams, 'start'>` - Request parameters, excluding the `start` parameter,
26
+ * since the method is designed to obtain all data in one call.
27
+ * Note: Use `filter`, `order`, and `select` to control the selection.
28
+ * - `idKey?: string` - The name of the field containing the unique identifier of the element.
29
+ * Default is 'ID' (uppercase). Alternatively, it can be 'id' (lowercase).
30
+ * or another field, depending on the REST API data structure.
31
+ * - `customKeyForResult?: string` - A custom key indicating that the response REST API will be
32
+ * grouped by this field.
33
+ * Example: `items` to group a list of CRM items.
34
+ * - `requestId?: string` - Unique request identifier for tracking. Used for query deduplication and debugging.
35
+ *
36
+ * @returns {Promise<Result<T[]>>} A promise that resolves to the result of an REST API call.
37
+ *
38
+ * @example
39
+ * import { EnumCrmEntityTypeId, Text } from '@bitrix24/b24jssdk'
40
+ *
41
+ * interface CrmItem { id: number, title: string }
42
+ * const sixMonthAgo = new Date()
43
+ * sixMonthAgo.setMonth((new Date()).getMonth() - 6)
44
+ * sixMonthAgo.setHours(0, 0, 0)
45
+ * const response = await b24.actions.v2.callList.make<CrmItem>({
46
+ * method: 'crm.item.list',
47
+ * params: {
48
+ * entityTypeId: EnumCrmEntityTypeId.company,
49
+ * filter: {
50
+ * '=%title': 'A%',
51
+ * '>=createdTime': Text.toB24Format(sixMonthAgo) // created at least 6 months ago
52
+ * },
53
+ * select: ['id', 'title']
54
+ * },
55
+ * idKey: 'id',
56
+ * customKeyForResult: 'items',
57
+ * requestId: 'list-123'
58
+ * })
59
+ * if (!response.isSuccess) {
60
+ * throw new Error(`Problem: ${response.getErrorMessages().join('; ')}`)
61
+ * }
62
+ * const list = response.getData()
63
+ * console.log(`Result: ${list?.length}`) // Number of items received
64
+ */
65
+ async make(options) {
66
+ const batchSize = 50;
67
+ const result = new Result();
68
+ const idKey = options?.idKey ?? "ID";
69
+ const customKeyForResult = options?.customKeyForResult ?? null;
70
+ const params = options?.params ?? {};
71
+ const moreIdKey = `>${idKey}`;
72
+ const requestParams = {
73
+ ...params,
74
+ order: { ...params["order"] || {}, [idKey]: "ASC" },
75
+ filter: { ...params["filter"] || {}, [moreIdKey]: 0 },
76
+ start: -1
77
+ };
78
+ let allItems = [];
79
+ let isContinue = true;
80
+ do {
81
+ const response = await this._b24.actions.v2.call.make({
82
+ method: options.method,
83
+ params: requestParams,
84
+ requestId: options.requestId
85
+ });
86
+ if (!response.isSuccess) {
87
+ this._logger.error("callFastListMethod", {
88
+ method: options.method,
89
+ requestId: options.requestId,
90
+ messages: response.getErrorMessages()
91
+ });
92
+ for (const [index, error] of response.errors) {
93
+ result.addError(error, index);
94
+ }
95
+ isContinue = false;
96
+ break;
97
+ }
98
+ const responseData = response.getData();
99
+ if (!responseData) {
100
+ isContinue = false;
101
+ break;
102
+ }
103
+ let resultData = [];
104
+ if (null === customKeyForResult) {
105
+ resultData = responseData.result;
106
+ } else {
107
+ resultData = responseData.result[customKeyForResult];
108
+ }
109
+ if (resultData.length === 0) {
110
+ isContinue = false;
111
+ break;
112
+ }
113
+ allItems = [...allItems, ...resultData];
114
+ if (resultData.length < batchSize) {
115
+ isContinue = false;
116
+ break;
117
+ }
118
+ const lastItem = resultData[resultData.length - 1];
119
+ if (lastItem && typeof lastItem[idKey] !== "undefined") {
120
+ requestParams.filter[moreIdKey] = Number.parseInt(lastItem[idKey]);
121
+ } else {
122
+ isContinue = false;
123
+ break;
124
+ }
125
+ } while (isContinue);
126
+ return result.setData(allItems);
127
+ }
128
+ }
129
+
130
+ export { CallListV2 };
131
+ //# sourceMappingURL=call-list.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"call-list.mjs","sources":["../../../../../src/core/actions/v2/call-list.ts"],"sourcesContent":["import type { ActionOptions } from '../abstract-action'\nimport type { TypeCallParams } from '../../../types/http'\nimport type { AjaxResult } from '../../http/ajax-result'\nimport { AbstractAction } from '../abstract-action'\nimport { Result } from '../../result'\n\nexport type ActionCallListV2 = ActionOptions & {\n method: string\n params?: Omit<TypeCallParams, 'start'>\n idKey?: string\n customKeyForResult?: string\n requestId?: string\n}\n\n/**\n * Fast data retrieval without counting the total number of records. `restApi:v2`\n *\n * @todo add docs\n */\nexport class CallListV2 extends AbstractAction {\n /**\n * Fast data retrieval without counting the total number of records.\n *\n * @template T - The type of the elements of the returned array (default is `unknown`).\n *\n * @param {ActionCallListV2} options - parameters for executing the request.\n * - `method: string` - The name of the REST API method that returns a list of data (for example: `crm.item.list`, `tasks.task.list`)\n * - `params?: Omit<TypeCallParams, 'start'>` - Request parameters, excluding the `start` parameter,\n * since the method is designed to obtain all data in one call.\n * Note: Use `filter`, `order`, and `select` to control the selection.\n * - `idKey?: string` - The name of the field containing the unique identifier of the element.\n * Default is 'ID' (uppercase). Alternatively, it can be 'id' (lowercase).\n * or another field, depending on the REST API data structure.\n * - `customKeyForResult?: string` - A custom key indicating that the response REST API will be\n * grouped by this field.\n * Example: `items` to group a list of CRM items.\n * - `requestId?: string` - Unique request identifier for tracking. Used for query deduplication and debugging.\n *\n * @returns {Promise<Result<T[]>>} A promise that resolves to the result of an REST API call.\n *\n * @example\n * import { EnumCrmEntityTypeId, Text } from '@bitrix24/b24jssdk'\n *\n * interface CrmItem { id: number, title: string }\n * const sixMonthAgo = new Date()\n * sixMonthAgo.setMonth((new Date()).getMonth() - 6)\n * sixMonthAgo.setHours(0, 0, 0)\n * const response = await b24.actions.v2.callList.make<CrmItem>({\n * method: 'crm.item.list',\n * params: {\n * entityTypeId: EnumCrmEntityTypeId.company,\n * filter: {\n * '=%title': 'A%',\n * '>=createdTime': Text.toB24Format(sixMonthAgo) // created at least 6 months ago\n * },\n * select: ['id', 'title']\n * },\n * idKey: 'id',\n * customKeyForResult: 'items',\n * requestId: 'list-123'\n * })\n * if (!response.isSuccess) {\n * throw new Error(`Problem: ${response.getErrorMessages().join('; ')}`)\n * }\n * const list = response.getData()\n * console.log(`Result: ${list?.length}`) // Number of items received\n */\n public override async make<T = unknown>(options: ActionCallListV2): Promise<Result<T[]>> {\n const batchSize = 50\n const result: Result<T[]> = new Result()\n\n const idKey = options?.idKey ?? 'ID'\n const customKeyForResult = options?.customKeyForResult ?? null\n const params = options?.params ?? {}\n\n const moreIdKey = `>${idKey}`\n const requestParams: TypeCallParams = {\n ...params,\n order: { ...(params['order'] || {}), [idKey]: 'ASC' },\n filter: { ...(params['filter'] || {}), [moreIdKey]: 0 },\n start: -1\n }\n\n let allItems: T[] = []\n let isContinue = true\n\n do {\n const response: AjaxResult<T> = await this._b24.actions.v2.call.make<T>({\n method: options.method,\n params: requestParams,\n requestId: options.requestId\n })\n\n if (!response.isSuccess) {\n this._logger.error('callFastListMethod', {\n method: options.method,\n requestId: options.requestId,\n messages: response.getErrorMessages()\n })\n for (const [index, error] of response.errors) {\n result.addError(error, index)\n }\n isContinue = false\n break\n }\n const responseData = response.getData()\n if (!responseData) {\n isContinue = false\n break\n }\n\n let resultData: T[] = []\n if (null === customKeyForResult) {\n resultData = responseData.result as T[]\n } else {\n resultData = responseData.result[customKeyForResult] as T[]\n }\n\n if (resultData.length === 0) {\n isContinue = false\n break\n }\n\n allItems = [...allItems, ...resultData]\n\n if (resultData.length < batchSize) {\n isContinue = false\n break\n }\n\n // Update the filter for the next iteration\n const lastItem = resultData[resultData.length - 1] as Record<string, any>\n if (\n lastItem\n && typeof lastItem[idKey] !== 'undefined'\n ) {\n requestParams.filter[moreIdKey] = Number.parseInt(lastItem[idKey])\n } else {\n isContinue = false\n break\n }\n } while (isContinue)\n\n return result.setData(allItems)\n }\n}\n"],"names":[],"mappings":"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"}
@@ -0,0 +1,68 @@
1
+ /**
2
+ * @package @bitrix24/b24jssdk
3
+ * @version 1.0.1
4
+ * @copyright (c) 2026 Bitrix24
5
+ * @license MIT
6
+ * @see https://github.com/bitrix24/b24jssdk
7
+ * @see https://bitrix24.github.io/b24jssdk/
8
+ */
9
+ import { AbstractAction } from '../abstract-action.mjs';
10
+ import { versionManager } from '../../version-manager.mjs';
11
+ import { ApiVersion } from '../../../types/b24.mjs';
12
+ import { LoggerFactory } from '../../../logger/logger-factory.mjs';
13
+
14
+ var __defProp = Object.defineProperty;
15
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
16
+ class CallV2 extends AbstractAction {
17
+ static {
18
+ __name(this, "CallV2");
19
+ }
20
+ /**
21
+ * Calls the Bitrix24 REST API method.
22
+ *
23
+ * @template T - The expected data type in the response (default is `unknown`).
24
+ *
25
+ * @param {ActionCallV2} options - parameters for executing the request.
26
+ * - `method: string` - REST API method name (eg: `crm.item.get`)
27
+ * - `params?: TypeCallParams` - Parameters for calling the method.
28
+ * - `requestId?: string` - Unique request identifier for tracking. Used for query deduplication and debugging.
29
+ *
30
+ * @returns {Promise<AjaxResult<T>>} A promise that resolves to the result of an REST API call.
31
+ *
32
+ * @example
33
+ * import { EnumCrmEntityTypeId } from '@bitrix24/b24jssdk'
34
+ *
35
+ * interface CrmItem { id: number, name: string, lastName: string }
36
+ * const response = await b24.actions.v2.call.make<{ item: CrmItem }>({
37
+ * method: 'crm.item.get',
38
+ * params: {
39
+ * entityTypeId: EnumCrmEntityTypeId.contact,
40
+ * id: 123
41
+ * },
42
+ * requestId: 'item-123'
43
+ * })
44
+ * if (!response.isSuccess) {
45
+ * throw new Error(`Problem: ${response.getErrorMessages().join('; ')}`)
46
+ * }
47
+ * console.log(response.getData().result.item.name)
48
+ */
49
+ async make(options) {
50
+ if (versionManager.isSupport(ApiVersion.v3, options.method)) {
51
+ LoggerFactory.forcedLog(
52
+ this._logger,
53
+ "warning",
54
+ `The method ${options.method} is available in restApi:v3. It's worth migrating to the new API.`,
55
+ {
56
+ method: options.method,
57
+ requestId: options.requestId,
58
+ code: "JSSDK_CORE_METHOD_AVAILABLE_IN_API_V3"
59
+ }
60
+ );
61
+ }
62
+ const params = options.params || {};
63
+ return this._b24.getHttpClient(ApiVersion.v2).call(options.method, params, options.requestId);
64
+ }
65
+ }
66
+
67
+ export { CallV2 };
68
+ //# sourceMappingURL=call.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"call.mjs","sources":["../../../../../src/core/actions/v2/call.ts"],"sourcesContent":["import type { ActionOptions } from '../abstract-action'\nimport type { TypeCallParams } from '../../../types/http'\nimport type { AjaxResult } from '../../http/ajax-result'\nimport { AbstractAction } from '../abstract-action'\nimport { versionManager } from '../../version-manager'\nimport { ApiVersion } from '../../../types/b24'\nimport { LoggerFactory } from '../../../logger'\n\nexport type ActionCallV2 = ActionOptions & {\n method: string\n params?: TypeCallParams\n requestId?: string\n}\n\n/**\n * Calls the Bitrix24 REST API method `restApi:v2`\n *\n * @todo add docs\n */\nexport class CallV2 extends AbstractAction {\n /**\n * Calls the Bitrix24 REST API method.\n *\n * @template T - The expected data type in the response (default is `unknown`).\n *\n * @param {ActionCallV2} options - parameters for executing the request.\n * - `method: string` - REST API method name (eg: `crm.item.get`)\n * - `params?: TypeCallParams` - Parameters for calling the method.\n * - `requestId?: string` - Unique request identifier for tracking. Used for query deduplication and debugging.\n *\n * @returns {Promise<AjaxResult<T>>} A promise that resolves to the result of an REST API call.\n *\n * @example\n * import { EnumCrmEntityTypeId } from '@bitrix24/b24jssdk'\n *\n * interface CrmItem { id: number, name: string, lastName: string }\n * const response = await b24.actions.v2.call.make<{ item: CrmItem }>({\n * method: 'crm.item.get',\n * params: {\n * entityTypeId: EnumCrmEntityTypeId.contact,\n * id: 123\n * },\n * requestId: 'item-123'\n * })\n * if (!response.isSuccess) {\n * throw new Error(`Problem: ${response.getErrorMessages().join('; ')}`)\n * }\n * console.log(response.getData().result.item.name)\n */\n public override async make<T = unknown>(options: ActionCallV2): Promise<AjaxResult<T>> {\n if (versionManager.isSupport(ApiVersion.v3, options.method)) {\n LoggerFactory.forcedLog(\n this._logger,\n 'warning',\n `The method ${options.method} is available in restApi:v3. It's worth migrating to the new API.`,\n {\n method: options.method,\n requestId: options.requestId,\n code: 'JSSDK_CORE_METHOD_AVAILABLE_IN_API_V3'\n }\n )\n }\n\n const params = options.params || {}\n return this._b24.getHttpClient(ApiVersion.v2).call<T>(options.method, params, options.requestId)\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AAmBO,MAAM,eAAe,cAAA,CAAe;AAAA,EAnB3C;AAmB2C,IAAA,MAAA,CAAA,IAAA,EAAA,QAAA,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA8BzC,MAAsB,KAAkB,OAAA,EAA+C;AACrF,IAAA,IAAI,eAAe,SAAA,CAAU,UAAA,CAAW,EAAA,EAAI,OAAA,CAAQ,MAAM,CAAA,EAAG;AAC3D,MAAA,aAAA,CAAc,SAAA;AAAA,QACZ,IAAA,CAAK,OAAA;AAAA,QACL,SAAA;AAAA,QACA,CAAA,WAAA,EAAc,QAAQ,MAAM,CAAA,iEAAA,CAAA;AAAA,QAC5B;AAAA,UACE,QAAQ,OAAA,CAAQ,MAAA;AAAA,UAChB,WAAW,OAAA,CAAQ,SAAA;AAAA,UACnB,IAAA,EAAM;AAAA;AACR,OACF;AAAA,IACF;AAEA,IAAA,MAAM,MAAA,GAAS,OAAA,CAAQ,MAAA,IAAU,EAAC;AAClC,IAAA,OAAO,IAAA,CAAK,IAAA,CAAK,aAAA,CAAc,UAAA,CAAW,EAAE,CAAA,CAAE,IAAA,CAAQ,OAAA,CAAQ,MAAA,EAAQ,MAAA,EAAQ,OAAA,CAAQ,SAAS,CAAA;AAAA,EACjG;AACF;;;;"}
@@ -0,0 +1,132 @@
1
+ /**
2
+ * @package @bitrix24/b24jssdk
3
+ * @version 1.0.1
4
+ * @copyright (c) 2026 Bitrix24
5
+ * @license MIT
6
+ * @see https://github.com/bitrix24/b24jssdk
7
+ * @see https://bitrix24.github.io/b24jssdk/
8
+ */
9
+ import { AbstractAction } from '../abstract-action.mjs';
10
+ import { SdkError } from '../../sdk-error.mjs';
11
+
12
+ var __defProp = Object.defineProperty;
13
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
14
+ class FetchListV2 extends AbstractAction {
15
+ static {
16
+ __name(this, "FetchListV2");
17
+ }
18
+ /**
19
+ * Calls a REST API list method and returns an async generator for efficient large data retrieval.
20
+ * Implements the fast algorithm for iterating over large datasets without loading all data into memory at once.
21
+ *
22
+ * @template T - The type of items in the returned arrays (default is `unknown`).
23
+ *
24
+ * @param {ActionFetchListV2} options - parameters for executing the request.
25
+ * - `method: string` - The name of the REST API method that returns a list of data (for example: `crm.item.list`, `tasks.task.list`)
26
+ * - `params?: Omit<TypeCallParams, 'start'>` - Request parameters, excluding the `start` parameter,
27
+ * since the method is designed to obtain all data in one call.
28
+ * Note: Use `filter`, `order`, and `select` to control the selection.
29
+ * - `idKey?: string` - The name of the field containing the unique identifier of the element.
30
+ * Default is 'ID' (uppercase). Alternatively, it can be 'id' (lowercase).
31
+ * or another field, depending on the REST API data structure.
32
+ * - `customKeyForResult?: string` - A custom key indicating that the response REST API will be
33
+ * grouped by this field.
34
+ * Example: `items` to group a list of CRM items.
35
+ * - `requestId?: string` - Unique request identifier for tracking. Used for query deduplication and debugging.
36
+ *
37
+ * @returns {AsyncGenerator<T[]>} An async generator that yields chunks of data as arrays of type `T`.
38
+ * Each iteration returns the next page/batch of results until all data is fetched.
39
+ *
40
+ * @example
41
+ * import { EnumCrmEntityTypeId, Text } from '@bitrix24/b24jssdk'
42
+ *
43
+ * interface CrmItem { id: number, title: string }
44
+ * const sixMonthAgo = new Date()
45
+ * sixMonthAgo.setMonth((new Date()).getMonth() - 6)
46
+ * sixMonthAgo.setHours(0, 0, 0)
47
+ * const generator = b24.actions.v2.fetchList.make<CrmItem>({
48
+ * method: 'crm.item.list',
49
+ * params: {
50
+ * entityTypeId: EnumCrmEntityTypeId.company,
51
+ * filter: {
52
+ * '=%title': 'A%',
53
+ * '>=createdTime': Text.toB24Format(sixMonthAgo) // created at least 6 months ago
54
+ * },
55
+ * select: ['id', 'title']
56
+ * },
57
+ * idKey: 'id',
58
+ * customKeyForResult: 'items',
59
+ * requestId: 'list-123'
60
+ * })
61
+ *
62
+ * for await (const chunk of generator) {
63
+ * // Process chunk (e.g., save to database, analyze, etc.)
64
+ * console.log(`Processing ${chunk.length} items`)
65
+ * }
66
+ *
67
+ * @see {@link https://apidocs.bitrix24.com/settings/performance/huge-data.html Bitrix24: Fast algorithm for large data}
68
+ */
69
+ async *make(options) {
70
+ const batchSize = 50;
71
+ const idKey = options?.idKey ?? "ID";
72
+ const customKeyForResult = options?.customKeyForResult ?? null;
73
+ const params = options?.params ?? {};
74
+ const moreIdKey = `>${idKey}`;
75
+ const requestParams = {
76
+ ...params,
77
+ order: { ...params["order"] || {}, [idKey]: "ASC" },
78
+ filter: { ...params["filter"] || {}, [moreIdKey]: 0 },
79
+ start: -1
80
+ };
81
+ let isContinue = true;
82
+ do {
83
+ const response = await this._b24.actions.v2.call.make({
84
+ method: options.method,
85
+ params: requestParams,
86
+ requestId: options.requestId
87
+ });
88
+ if (!response.isSuccess) {
89
+ this._logger.error("fetchListMethod", {
90
+ method: options.method,
91
+ requestId: options.requestId,
92
+ messages: response.getErrorMessages()
93
+ });
94
+ throw new SdkError({
95
+ code: "JSSDK_CORE_B24_FETCH_LIST_METHOD_API_V2",
96
+ description: `API Error: ${response.getErrorMessages().join("; ")}`,
97
+ status: 500
98
+ });
99
+ }
100
+ const responseData = response.getData();
101
+ if (!responseData) {
102
+ isContinue = false;
103
+ break;
104
+ }
105
+ let resultData = [];
106
+ if (null === customKeyForResult) {
107
+ resultData = responseData.result;
108
+ } else {
109
+ resultData = responseData.result[customKeyForResult];
110
+ }
111
+ if (resultData.length === 0) {
112
+ isContinue = false;
113
+ break;
114
+ }
115
+ yield resultData;
116
+ if (resultData.length < batchSize) {
117
+ isContinue = false;
118
+ break;
119
+ }
120
+ const lastItem = resultData[resultData.length - 1];
121
+ if (lastItem && typeof lastItem[idKey] !== "undefined") {
122
+ requestParams.filter[moreIdKey] = Number.parseInt(lastItem[idKey]);
123
+ } else {
124
+ isContinue = false;
125
+ break;
126
+ }
127
+ } while (isContinue);
128
+ }
129
+ }
130
+
131
+ export { FetchListV2 };
132
+ //# sourceMappingURL=fetch-list.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch-list.mjs","sources":["../../../../../src/core/actions/v2/fetch-list.ts"],"sourcesContent":["import type { ActionOptions } from '../abstract-action'\nimport type { TypeCallParams } from '../../../types/http'\nimport type { AjaxResult } from '../../http/ajax-result'\nimport { AbstractAction } from '../abstract-action'\nimport { SdkError } from '../../sdk-error'\n\nexport type ActionFetchListV2 = ActionOptions & {\n method: string\n params?: Omit<TypeCallParams, 'start'>\n idKey?: string\n customKeyForResult?: string\n requestId?: string\n}\n\n/**\n * Calls a REST API list method and returns an async generator for efficient large data retrieval. `restApi:v2`\n *\n * @todo add docs\n */\nexport class FetchListV2 extends AbstractAction {\n /**\n * Calls a REST API list method and returns an async generator for efficient large data retrieval.\n * Implements the fast algorithm for iterating over large datasets without loading all data into memory at once.\n *\n * @template T - The type of items in the returned arrays (default is `unknown`).\n *\n * @param {ActionFetchListV2} options - parameters for executing the request.\n * - `method: string` - The name of the REST API method that returns a list of data (for example: `crm.item.list`, `tasks.task.list`)\n * - `params?: Omit<TypeCallParams, 'start'>` - Request parameters, excluding the `start` parameter,\n * since the method is designed to obtain all data in one call.\n * Note: Use `filter`, `order`, and `select` to control the selection.\n * - `idKey?: string` - The name of the field containing the unique identifier of the element.\n * Default is 'ID' (uppercase). Alternatively, it can be 'id' (lowercase).\n * or another field, depending on the REST API data structure.\n * - `customKeyForResult?: string` - A custom key indicating that the response REST API will be\n * grouped by this field.\n * Example: `items` to group a list of CRM items.\n * - `requestId?: string` - Unique request identifier for tracking. Used for query deduplication and debugging.\n *\n * @returns {AsyncGenerator<T[]>} An async generator that yields chunks of data as arrays of type `T`.\n * Each iteration returns the next page/batch of results until all data is fetched.\n *\n * @example\n * import { EnumCrmEntityTypeId, Text } from '@bitrix24/b24jssdk'\n *\n * interface CrmItem { id: number, title: string }\n * const sixMonthAgo = new Date()\n * sixMonthAgo.setMonth((new Date()).getMonth() - 6)\n * sixMonthAgo.setHours(0, 0, 0)\n * const generator = b24.actions.v2.fetchList.make<CrmItem>({\n * method: 'crm.item.list',\n * params: {\n * entityTypeId: EnumCrmEntityTypeId.company,\n * filter: {\n * '=%title': 'A%',\n * '>=createdTime': Text.toB24Format(sixMonthAgo) // created at least 6 months ago\n * },\n * select: ['id', 'title']\n * },\n * idKey: 'id',\n * customKeyForResult: 'items',\n * requestId: 'list-123'\n * })\n *\n * for await (const chunk of generator) {\n * // Process chunk (e.g., save to database, analyze, etc.)\n * console.log(`Processing ${chunk.length} items`)\n * }\n *\n * @see {@link https://apidocs.bitrix24.com/settings/performance/huge-data.html Bitrix24: Fast algorithm for large data}\n */\n public override async* make<T = unknown>(options: ActionFetchListV2): AsyncGenerator<T[]> {\n const batchSize = 50\n\n const idKey = options?.idKey ?? 'ID'\n const customKeyForResult = options?.customKeyForResult ?? null\n const params = options?.params ?? {}\n\n const moreIdKey = `>${idKey}`\n const requestParams: TypeCallParams = {\n ...params,\n order: { ...(params['order'] || {}), [idKey]: 'ASC' },\n filter: { ...(params['filter'] || {}), [moreIdKey]: 0 },\n start: -1\n }\n\n let isContinue = true\n\n do {\n const response: AjaxResult<T> = await this._b24.actions.v2.call.make<T>({\n method: options.method,\n params: requestParams,\n requestId: options.requestId\n })\n\n if (!response.isSuccess) {\n this._logger.error('fetchListMethod', {\n method: options.method,\n requestId: options.requestId,\n messages: response.getErrorMessages()\n })\n throw new SdkError({\n code: 'JSSDK_CORE_B24_FETCH_LIST_METHOD_API_V2',\n description: `API Error: ${response.getErrorMessages().join('; ')}`,\n status: 500\n })\n }\n const responseData = response.getData()\n if (!responseData) {\n isContinue = false\n break\n }\n\n let resultData: T[] = []\n if (null === customKeyForResult) {\n resultData = responseData.result as T[]\n } else {\n resultData = responseData.result[customKeyForResult] as T[]\n }\n\n if (resultData.length === 0) {\n isContinue = false\n break\n }\n\n yield resultData\n\n if (resultData.length < batchSize) {\n isContinue = false\n break\n }\n\n // Update the filter for the next iteration\n const lastItem = resultData[resultData.length - 1] as Record<string, any>\n if (\n lastItem\n && typeof lastItem[idKey] !== 'undefined'\n ) {\n requestParams.filter[moreIdKey] = Number.parseInt(lastItem[idKey])\n } else {\n isContinue = false\n break\n }\n } while (isContinue)\n }\n}\n"],"names":[],"mappings":"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"}