@keboola/api-client 36.0.0 → 40.0.0

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 (529) hide show
  1. package/AGENTS.md +133 -103
  2. package/API-SURFACE.md +36 -2
  3. package/CHANGELOG.md +194 -0
  4. package/README.md +22 -20
  5. package/dist/{ManagementClientAuthError-DD4u0EU7.cjs → ManagementClientAuthError-DE7lNGZQ.cjs} +3 -2
  6. package/dist/{ManagementClientAuthError-DD4u0EU7.cjs.map → ManagementClientAuthError-DE7lNGZQ.cjs.map} +1 -1
  7. package/dist/{ManagementClientAuthError-ey-f03vy.js → ManagementClientAuthError-H30lti_Q.js} +3 -2
  8. package/dist/{ManagementClientAuthError-ey-f03vy.js.map → ManagementClientAuthError-H30lti_Q.js.map} +1 -1
  9. package/dist/{ValidationError-CLVJCCwH.cjs → ValidationError-D65QU0uq.cjs} +10 -16
  10. package/dist/ValidationError-D65QU0uq.cjs.map +1 -0
  11. package/dist/ValidationError-DjhtNMfZ.js +42 -0
  12. package/dist/ValidationError-DjhtNMfZ.js.map +1 -0
  13. package/dist/ai/index.cjs +2 -2
  14. package/dist/ai/index.d.cts +2 -2
  15. package/dist/ai/index.d.ts +2 -2
  16. package/dist/ai/index.js +2 -2
  17. package/dist/ai/types.d.cts +1 -1
  18. package/dist/ai/types.d.ts +1 -1
  19. package/dist/{appLogs-BjfUoWzs.cjs → appLogs-B9zFJIuy.cjs} +2 -2
  20. package/dist/{appLogs-BjfUoWzs.cjs.map → appLogs-B9zFJIuy.cjs.map} +1 -1
  21. package/dist/{appLogs-xsVkTriU.js → appLogs-BBkkUOW1.js} +2 -2
  22. package/dist/{appLogs-xsVkTriU.js.map → appLogs-BBkkUOW1.js.map} +1 -1
  23. package/dist/{appLogs-Ch7DYpzx.d.ts → appLogs-BS6ViVGR.d.ts} +2 -2
  24. package/dist/{appLogs-D5A13Y0y.d.cts → appLogs-C9YlJ2g8.d.cts} +2 -2
  25. package/dist/apps/index.cjs +30 -56
  26. package/dist/apps/index.cjs.map +1 -1
  27. package/dist/apps/index.d.cts +8 -13
  28. package/dist/apps/index.d.ts +8 -13
  29. package/dist/apps/index.js +30 -56
  30. package/dist/apps/index.js.map +1 -1
  31. package/dist/apps/types.d.cts +2 -2
  32. package/dist/apps/types.d.ts +2 -2
  33. package/dist/assets/index.cjs +1 -1
  34. package/dist/assets/index.d.cts +1 -1
  35. package/dist/assets/index.d.ts +1 -1
  36. package/dist/assets/index.js +1 -1
  37. package/dist/auth/index.cjs +8 -4
  38. package/dist/auth/index.d.cts +2 -2
  39. package/dist/auth/index.d.ts +2 -2
  40. package/dist/auth/index.js +2 -2
  41. package/dist/auth/types.d.cts +2 -2
  42. package/dist/auth/types.d.ts +2 -2
  43. package/dist/{auth-JQ33o3nU.cjs → auth-Dm0F2rOh.cjs} +2 -2
  44. package/dist/{auth-JQ33o3nU.cjs.map → auth-Dm0F2rOh.cjs.map} +1 -1
  45. package/dist/{auth-aItmDu45.js → auth-DworfoPy.js} +2 -2
  46. package/dist/{auth-aItmDu45.js.map → auth-DworfoPy.js.map} +1 -1
  47. package/dist/{authClient-_PpvGgZJ.cjs → authClient-BmuUo0J4.cjs} +141 -48
  48. package/dist/authClient-BmuUo0J4.cjs.map +1 -0
  49. package/dist/{authClient-D8i3JTM-.d.ts → authClient-CHXWJ9x3.d.ts} +109 -76
  50. package/dist/{authClient-D7W9vWPR.js → authClient-CgcDGd30.js} +108 -39
  51. package/dist/authClient-CgcDGd30.js.map +1 -0
  52. package/dist/{authClient-CTHNs6Tq.d.cts → authClient-vEt_7_uk.d.cts} +109 -76
  53. package/dist/billing/index.cjs +2 -2
  54. package/dist/billing/index.d.cts +1 -1
  55. package/dist/billing/index.d.ts +1 -1
  56. package/dist/billing/index.js +2 -2
  57. package/dist/billing/types.d.cts +1 -1
  58. package/dist/billing/types.d.ts +1 -1
  59. package/dist/businessWorkspaceApi/index.cjs +3 -0
  60. package/dist/businessWorkspaceApi/index.d.cts +2 -0
  61. package/dist/businessWorkspaceApi/index.d.ts +2 -0
  62. package/dist/businessWorkspaceApi/index.js +2 -0
  63. package/dist/businessWorkspaceApi/types.cjs +0 -0
  64. package/dist/businessWorkspaceApi/types.d.cts +2 -0
  65. package/dist/businessWorkspaceApi/types.d.ts +2 -0
  66. package/dist/businessWorkspaceApi/types.js +1 -0
  67. package/dist/businessWorkspaceApi-6tCDdpnY.cjs +66 -0
  68. package/dist/businessWorkspaceApi-6tCDdpnY.cjs.map +1 -0
  69. package/dist/businessWorkspaceApi-BLUdefRF.js +61 -0
  70. package/dist/businessWorkspaceApi-BLUdefRF.js.map +1 -0
  71. package/dist/businessWorkspaceApiClient-BHDJlHFo.d.cts +529 -0
  72. package/dist/businessWorkspaceApiClient-DI-z1VIH.d.ts +529 -0
  73. package/dist/chat/index.cjs +9 -5
  74. package/dist/chat/index.cjs.map +1 -1
  75. package/dist/chat/index.d.cts +3 -3
  76. package/dist/chat/index.d.ts +3 -3
  77. package/dist/chat/index.js +9 -5
  78. package/dist/chat/index.js.map +1 -1
  79. package/dist/chat/types.cjs +1 -3
  80. package/dist/chat/types.cjs.map +1 -1
  81. package/dist/chat/types.d.cts +2 -2
  82. package/dist/chat/types.d.ts +2 -2
  83. package/dist/chat/types.js +1 -3
  84. package/dist/chat/types.js.map +1 -1
  85. package/dist/{componentId-DkyQ8PM0.cjs → componentId-57vjsa2i.cjs} +4 -2
  86. package/dist/{componentId-DkyQ8PM0.cjs.map → componentId-57vjsa2i.cjs.map} +1 -1
  87. package/dist/{componentId-vJz-kWs6.js → componentId-C6WZa_R1.js} +4 -2
  88. package/dist/{componentId-vJz-kWs6.js.map → componentId-C6WZa_R1.js.map} +1 -1
  89. package/dist/{concurrent-CH9fbNr3.js → concurrent-BacWxPwi.js} +5 -7
  90. package/dist/concurrent-BacWxPwi.js.map +1 -0
  91. package/dist/{concurrent-tbiIa0UL.cjs → concurrent-CdVfR1N5.cjs} +5 -7
  92. package/dist/concurrent-CdVfR1N5.cjs.map +1 -0
  93. package/dist/{configurations-VtNE0nrT.js → configurations-BPKGGy-M.js} +14 -22
  94. package/dist/configurations-BPKGGy-M.js.map +1 -0
  95. package/dist/{configurations-CyFF9Dtu.cjs → configurations-BTRHVSRq.cjs} +20 -53
  96. package/dist/configurations-BTRHVSRq.cjs.map +1 -0
  97. package/dist/{configurations-BVvcimzo.js → configurations-Chg_JwJ1.js} +20 -53
  98. package/dist/configurations-Chg_JwJ1.js.map +1 -0
  99. package/dist/{configurations-zkNjr73Q.cjs → configurations-IYyOvhI3.cjs} +14 -22
  100. package/dist/configurations-IYyOvhI3.cjs.map +1 -0
  101. package/dist/constants/index.cjs +2 -2
  102. package/dist/constants/index.d.cts +2 -2
  103. package/dist/constants/index.d.ts +2 -2
  104. package/dist/constants/index.js +2 -2
  105. package/dist/{constants-wfbFsqqN.js → constants-C2tYAJSj.js} +10 -1
  106. package/dist/constants-C2tYAJSj.js.map +1 -0
  107. package/dist/{constants-C4DlsF_M.cjs → constants-C6xku_Vx.cjs} +10 -1
  108. package/dist/constants-C6xku_Vx.cjs.map +1 -0
  109. package/dist/{createFetchClient-DgMiqTJ8.cjs → createFetchClient-Cwp8max9.cjs} +24 -5
  110. package/dist/createFetchClient-Cwp8max9.cjs.map +1 -0
  111. package/dist/{createFetchClient-U-ZrwPl2.js → createFetchClient-DXHQK63w.js} +24 -5
  112. package/dist/createFetchClient-DXHQK63w.js.map +1 -0
  113. package/dist/{createGenericFetchClient-rxvUUbap.js → createGenericFetchClient-Dg1rgzmG.js} +2 -2
  114. package/dist/{createGenericFetchClient-rxvUUbap.js.map → createGenericFetchClient-Dg1rgzmG.js.map} +1 -1
  115. package/dist/{createGenericFetchClient-o3cPJeRn.cjs → createGenericFetchClient-Dl9cqTvR.cjs} +2 -2
  116. package/dist/{createGenericFetchClient-o3cPJeRn.cjs.map → createGenericFetchClient-Dl9cqTvR.cjs.map} +1 -1
  117. package/dist/{createOpenapiFetchClient-DhUU3M1W.cjs → createOpenapiFetchClient-BYqW-9tm.cjs} +2 -2
  118. package/dist/{createOpenapiFetchClient-DhUU3M1W.cjs.map → createOpenapiFetchClient-BYqW-9tm.cjs.map} +1 -1
  119. package/dist/{createOpenapiFetchClient-BVSc9ibR.js → createOpenapiFetchClient-DZUOVupy.js} +2 -2
  120. package/dist/{createOpenapiFetchClient-BVSc9ibR.js.map → createOpenapiFetchClient-DZUOVupy.js.map} +1 -1
  121. package/dist/dataScience/index.cjs +2 -2
  122. package/dist/dataScience/index.d.cts +2 -2
  123. package/dist/dataScience/index.d.ts +2 -2
  124. package/dist/dataScience/index.js +2 -2
  125. package/dist/dataScience/types.d.cts +2 -2
  126. package/dist/dataScience/types.d.ts +2 -2
  127. package/dist/{dataScience-0Rl_EuV_.cjs → dataScience-B5QxZnvW.cjs} +5 -5
  128. package/dist/{dataScience-0Rl_EuV_.cjs.map → dataScience-B5QxZnvW.cjs.map} +1 -1
  129. package/dist/{dataScience-C1gO5zUn.js → dataScience-OXcwdk1p.js} +5 -5
  130. package/dist/{dataScience-C1gO5zUn.js.map → dataScience-OXcwdk1p.js.map} +1 -1
  131. package/dist/dedupe-Cky1gSUu.js +21 -0
  132. package/dist/dedupe-Cky1gSUu.js.map +1 -0
  133. package/dist/dedupe-OSnnst2u.cjs +26 -0
  134. package/dist/dedupe-OSnnst2u.cjs.map +1 -0
  135. package/dist/developerPortal/index.cjs +1 -1
  136. package/dist/developerPortal/index.d.cts +2 -2
  137. package/dist/developerPortal/index.d.ts +2 -2
  138. package/dist/developerPortal/index.js +1 -1
  139. package/dist/developerPortal/types.d.cts +1 -1
  140. package/dist/developerPortal/types.d.ts +1 -1
  141. package/dist/{developerPortalClient-C_48z8BN.js → developerPortalClient-B1QZ1rYi.js} +6 -8
  142. package/dist/{developerPortalClient-C_48z8BN.js.map → developerPortalClient-B1QZ1rYi.js.map} +1 -1
  143. package/dist/{developerPortalClient-ki0XS_OD.cjs → developerPortalClient-CLPpBksD.cjs} +6 -8
  144. package/dist/{developerPortalClient-ki0XS_OD.cjs.map → developerPortalClient-CLPpBksD.cjs.map} +1 -1
  145. package/dist/domain/permissions/index.cjs +9 -30
  146. package/dist/domain/permissions/index.cjs.map +1 -1
  147. package/dist/domain/permissions/index.d.cts +29 -102
  148. package/dist/domain/permissions/index.d.ts +29 -102
  149. package/dist/domain/permissions/index.js +9 -30
  150. package/dist/domain/permissions/index.js.map +1 -1
  151. package/dist/domain/storageTable/index.d.cts +1 -1
  152. package/dist/domain/storageTable/index.d.ts +1 -1
  153. package/dist/editor/index.cjs +2 -2
  154. package/dist/editor/index.cjs.map +1 -1
  155. package/dist/editor/index.d.cts +2 -2
  156. package/dist/editor/index.d.ts +2 -2
  157. package/dist/editor/index.js +2 -2
  158. package/dist/editor/index.js.map +1 -1
  159. package/dist/editor/types.d.cts +1 -1
  160. package/dist/editor/types.d.ts +1 -1
  161. package/dist/encryption/index.cjs +2 -22
  162. package/dist/encryption/index.cjs.map +1 -1
  163. package/dist/encryption/index.d.cts +1 -1
  164. package/dist/encryption/index.d.ts +1 -1
  165. package/dist/encryption/index.js +2 -22
  166. package/dist/encryption/index.js.map +1 -1
  167. package/dist/encryption/types.d.cts +1 -1
  168. package/dist/encryption/types.d.ts +1 -1
  169. package/dist/import/index.cjs +1 -1
  170. package/dist/import/index.d.cts +3 -3
  171. package/dist/import/index.d.ts +3 -3
  172. package/dist/import/index.js +1 -1
  173. package/dist/{import-C83w7BKz.cjs → import-CNk89mqy.cjs} +3 -3
  174. package/dist/{import-C83w7BKz.cjs.map → import-CNk89mqy.cjs.map} +1 -1
  175. package/dist/{import-CROEK82b.js → import-DiMQCzLa.js} +3 -3
  176. package/dist/{import-CROEK82b.js.map → import-DiMQCzLa.js.map} +1 -1
  177. package/dist/{index-DR4QqItd.d.cts → index--ZpnE3YT.d.cts} +3 -3
  178. package/dist/{index-C77vTm2K.d.ts → index-BDZvaRud.d.ts} +6 -6
  179. package/dist/{index-KuQ79Mnz.d.ts → index-BVhHt5lx.d.cts} +18 -26
  180. package/dist/{index-NC1dXRTD.d.ts → index-BfqkgPGI.d.cts} +7 -13
  181. package/dist/{index-NC1dXRTD.d.cts → index-BfqkgPGI.d.ts} +7 -13
  182. package/dist/{index-V7XKUQm9.d.cts → index-BgR5zcjJ.d.ts} +18 -26
  183. package/dist/{index-2JM0gyAf.d.ts → index-BkqackZf.d.ts} +439 -289
  184. package/dist/{index-BDG-LKXj.d.cts → index-ByRpNVcs.d.cts} +88 -18
  185. package/dist/{index-pXN4LWUX.d.ts → index-C11JSxBY.d.ts} +8 -11
  186. package/dist/{index-GjcJTCbz.d.cts → index-C4TNAA8-.d.cts} +8 -11
  187. package/dist/{index-NaYLwG_h.d.cts → index-C8gRRWHL.d.cts} +11 -1
  188. package/dist/{index-NaYLwG_h.d.ts → index-C8gRRWHL.d.ts} +11 -1
  189. package/dist/{index-3LUk2rpD.d.ts → index-CPu4Nezo.d.cts} +34 -9
  190. package/dist/{index-BMqLPS6S.d.ts → index-CXcWpZQ2.d.cts} +4 -12
  191. package/dist/{index-BMqLPS6S.d.cts → index-CXcWpZQ2.d.ts} +4 -12
  192. package/dist/{index-Dx52hNLP.d.cts → index-CcMHJcuP.d.cts} +3 -3
  193. package/dist/{index-BgLnWTZU.d.cts → index-Cvbjp3jx.d.cts} +6 -6
  194. package/dist/{index-DppA4k3b.d.cts → index-Cz0MXhzs.d.cts} +5 -5
  195. package/dist/{index-6Xe81qN3.d.ts → index-D-VMgpGc.d.ts} +5 -5
  196. package/dist/{index-D8rcUbnk.d.ts → index-D7-o-oGa.d.ts} +3 -3
  197. package/dist/{index-BXF-bs2d.d.ts → index-DCRKjihs.d.ts} +88 -18
  198. package/dist/{kaiAgentClient-DhTaM3GC.d.cts → index-DNThyEej.d.cts} +19 -5
  199. package/dist/{index-DXSmFkol.d.cts → index-DOAZmWvh.d.cts} +6 -6
  200. package/dist/{index-DIAyi-EZ.d.cts → index-DXYASsPP.d.cts} +439 -289
  201. package/dist/{index-BuegqrS1.d.ts → index-D_-4uQF8.d.ts} +3 -3
  202. package/dist/{index-CW3Pj7DY.d.cts → index-Dazy-meb.d.ts} +34 -9
  203. package/dist/{index-CqgtL2NU.d.ts → index-DnQTuc6t.d.ts} +6 -6
  204. package/dist/{kaiAgentClient-BJj_2aqt.d.ts → index-Qb7X6-ph.d.ts} +19 -5
  205. package/dist/index.cjs +1503 -895
  206. package/dist/index.cjs.map +1 -1
  207. package/dist/index.d.cts +7 -7
  208. package/dist/index.d.ts +7 -7
  209. package/dist/index.js +1501 -896
  210. package/dist/index.js.map +1 -1
  211. package/dist/isLoginPageRedirect-XPwAOKK3.js +14 -0
  212. package/dist/isLoginPageRedirect-XPwAOKK3.js.map +1 -0
  213. package/dist/isLoginPageRedirect-jQHiLrG7.cjs +19 -0
  214. package/dist/isLoginPageRedirect-jQHiLrG7.cjs.map +1 -0
  215. package/dist/{jobStatus-0_Y3Sr4i.cjs → jobStatus-BMlsyXWI.cjs} +19 -45
  216. package/dist/jobStatus-BMlsyXWI.cjs.map +1 -0
  217. package/dist/{jobStatus-PSZJMTiA.js → jobStatus-CfRtsIpv.js} +19 -45
  218. package/dist/jobStatus-CfRtsIpv.js.map +1 -0
  219. package/dist/kaiAgent/index.cjs +1 -1
  220. package/dist/kaiAgent/index.d.cts +3 -2
  221. package/dist/kaiAgent/index.d.ts +3 -2
  222. package/dist/kaiAgent/index.js +1 -1
  223. package/dist/kaiAgent/types.d.cts +2 -2
  224. package/dist/kaiAgent/types.d.ts +2 -2
  225. package/dist/{kaiAgent-8LNzGhZc.js → kaiAgent-Dp20HLTh.js} +63 -7
  226. package/dist/kaiAgent-Dp20HLTh.js.map +1 -0
  227. package/dist/{kaiAgent-B_TaUPRt.cjs → kaiAgent-QNoeVKPs.cjs} +63 -7
  228. package/dist/kaiAgent-QNoeVKPs.cjs.map +1 -0
  229. package/dist/kaiMemory-CClSPInt.cjs +289 -0
  230. package/dist/kaiMemory-CClSPInt.cjs.map +1 -0
  231. package/dist/kaiMemory-D0Y_16U4.js +260 -0
  232. package/dist/kaiMemory-D0Y_16U4.js.map +1 -0
  233. package/dist/management/index.cjs +1 -1
  234. package/dist/management/index.d.cts +2 -2
  235. package/dist/management/index.d.ts +2 -2
  236. package/dist/management/index.js +1 -1
  237. package/dist/management/types.d.cts +2 -2
  238. package/dist/management/types.d.ts +2 -2
  239. package/dist/{management-BoxlRNg2.cjs → management-CCY0IYnq.cjs} +93 -25
  240. package/dist/management-CCY0IYnq.cjs.map +1 -0
  241. package/dist/{management-Bp440RsV.js → management-DvmPiG64.js} +93 -25
  242. package/dist/management-DvmPiG64.js.map +1 -0
  243. package/dist/metastore/index.cjs +1 -1
  244. package/dist/metastore/index.d.cts +1 -1
  245. package/dist/metastore/index.d.ts +1 -1
  246. package/dist/metastore/index.js +1 -1
  247. package/dist/metastore/types.d.cts +2 -2
  248. package/dist/metastore/types.d.ts +2 -2
  249. package/dist/{metastore-VCDRVhUT.js → metastore-BycJxe7A.js} +14 -8
  250. package/dist/metastore-BycJxe7A.js.map +1 -0
  251. package/dist/{metastore-BYYWTb3m.cjs → metastore-XtWciCZT.cjs} +14 -8
  252. package/dist/metastore-XtWciCZT.cjs.map +1 -0
  253. package/dist/microsoftGraph/index.cjs +2 -2
  254. package/dist/microsoftGraph/index.d.cts +2 -2
  255. package/dist/microsoftGraph/index.d.ts +2 -2
  256. package/dist/microsoftGraph/index.js +2 -2
  257. package/dist/microsoftGraph/types.d.cts +1 -1
  258. package/dist/microsoftGraph/types.d.ts +1 -1
  259. package/dist/middleware-CBwrtgQd.js +34 -0
  260. package/dist/middleware-CBwrtgQd.js.map +1 -0
  261. package/dist/middleware-IjYx3d5u.cjs +45 -0
  262. package/dist/middleware-IjYx3d5u.cjs.map +1 -0
  263. package/dist/notifications/index.cjs +4 -4
  264. package/dist/notifications/index.d.cts +2 -2
  265. package/dist/notifications/index.d.ts +2 -2
  266. package/dist/notifications/index.js +4 -4
  267. package/dist/notifications/types.d.cts +1 -1
  268. package/dist/notifications/types.d.ts +1 -1
  269. package/dist/oauth/index.cjs +1 -1
  270. package/dist/oauth/index.d.cts +2 -2
  271. package/dist/oauth/index.d.ts +2 -2
  272. package/dist/oauth/index.js +1 -1
  273. package/dist/oauth/types.d.cts +1 -1
  274. package/dist/oauth/types.d.ts +1 -1
  275. package/dist/{oauth-B8yqG6Sy.cjs → oauth--2p8jkJf.cjs} +5 -5
  276. package/dist/{oauth-B8yqG6Sy.cjs.map → oauth--2p8jkJf.cjs.map} +1 -1
  277. package/dist/{oauth--asfePw-.js → oauth-l5zE39cD.js} +5 -5
  278. package/dist/{oauth--asfePw-.js.map → oauth-l5zE39cD.js.map} +1 -1
  279. package/dist/omnisearch/index.cjs +6 -14
  280. package/dist/omnisearch/index.cjs.map +1 -1
  281. package/dist/omnisearch/index.d.cts +6 -14
  282. package/dist/omnisearch/index.d.ts +6 -14
  283. package/dist/omnisearch/index.js +6 -14
  284. package/dist/omnisearch/index.js.map +1 -1
  285. package/dist/omnisearch/types.d.cts +1 -1
  286. package/dist/omnisearch/types.d.ts +1 -1
  287. package/dist/{project-C2wvX0xZ.d.ts → project-B15gStbM.d.ts} +2 -2
  288. package/dist/{project-hePfzUY0.d.cts → project-cHKuGvqJ.d.cts} +2 -2
  289. package/dist/queryService/index.cjs +1 -1
  290. package/dist/queryService/index.d.cts +1 -1
  291. package/dist/queryService/index.d.ts +1 -1
  292. package/dist/queryService/index.js +1 -1
  293. package/dist/queryService/types.d.cts +1 -1
  294. package/dist/queryService/types.d.ts +1 -1
  295. package/dist/{queryService-Ca65E5KH.js → queryService-CCOYbRbw.js} +6 -6
  296. package/dist/{queryService-Ca65E5KH.js.map → queryService-CCOYbRbw.js.map} +1 -1
  297. package/dist/{queryService-BVtjkXy1.cjs → queryService-CQzclHdL.cjs} +6 -6
  298. package/dist/{queryService-BVtjkXy1.cjs.map → queryService-CQzclHdL.cjs.map} +1 -1
  299. package/dist/queue/index.cjs +1 -1
  300. package/dist/queue/index.d.cts +3 -3
  301. package/dist/queue/index.d.ts +3 -3
  302. package/dist/queue/index.js +1 -1
  303. package/dist/queue/types.d.cts +1 -1
  304. package/dist/queue/types.d.ts +1 -1
  305. package/dist/{queue-DyotLFJi.js → queue-Cowbg6bR.js} +8 -11
  306. package/dist/queue-Cowbg6bR.js.map +1 -0
  307. package/dist/{queue-OJJUUqc2.cjs → queue-UG_BWKIC.cjs} +8 -11
  308. package/dist/queue-UG_BWKIC.cjs.map +1 -0
  309. package/dist/scheduler/index.cjs +4 -4
  310. package/dist/scheduler/index.d.cts +2 -2
  311. package/dist/scheduler/index.d.ts +2 -2
  312. package/dist/scheduler/index.js +4 -4
  313. package/dist/scheduler/types.d.cts +1 -1
  314. package/dist/scheduler/types.d.ts +1 -1
  315. package/dist/sdk/configurations/index.cjs +1 -1
  316. package/dist/sdk/configurations/index.d.cts +11 -11
  317. package/dist/sdk/configurations/index.d.ts +11 -11
  318. package/dist/sdk/configurations/index.js +1 -1
  319. package/dist/sdk/developerPortal/index.cjs +10 -18
  320. package/dist/sdk/developerPortal/index.cjs.map +1 -1
  321. package/dist/sdk/developerPortal/index.d.cts +7 -15
  322. package/dist/sdk/developerPortal/index.d.ts +7 -15
  323. package/dist/sdk/developerPortal/index.js +7 -15
  324. package/dist/sdk/developerPortal/index.js.map +1 -1
  325. package/dist/sdk/kaiMemory/index.cjs +7 -0
  326. package/dist/sdk/kaiMemory/index.d.cts +41 -0
  327. package/dist/sdk/kaiMemory/index.d.ts +41 -0
  328. package/dist/sdk/kaiMemory/index.js +2 -0
  329. package/dist/sdk/kaiMemory/types.cjs +0 -0
  330. package/dist/sdk/kaiMemory/types.d.cts +2 -0
  331. package/dist/sdk/kaiMemory/types.d.ts +2 -0
  332. package/dist/sdk/kaiMemory/types.js +1 -0
  333. package/dist/sdk/queryService/index.cjs +2 -2
  334. package/dist/sdk/queryService/index.d.cts +1 -1
  335. package/dist/sdk/queryService/index.d.ts +1 -1
  336. package/dist/sdk/queryService/index.js +2 -2
  337. package/dist/sdk/semanticLayer/index.cjs +1 -1
  338. package/dist/sdk/semanticLayer/index.d.cts +16 -40
  339. package/dist/sdk/semanticLayer/index.d.ts +16 -40
  340. package/dist/sdk/semanticLayer/index.js +1 -1
  341. package/dist/sdk/semanticLayer/types.d.cts +1 -1
  342. package/dist/sdk/semanticLayer/types.d.ts +1 -1
  343. package/dist/sdk/storage/index.cjs +0 -5
  344. package/dist/sdk/storage/index.cjs.map +1 -1
  345. package/dist/sdk/storage/index.d.cts +2 -2
  346. package/dist/sdk/storage/index.d.ts +2 -2
  347. package/dist/sdk/storage/index.js +1 -5
  348. package/dist/sdk/storage/index.js.map +1 -1
  349. package/dist/sdk/tag/index.cjs +1 -1
  350. package/dist/sdk/tag/index.d.cts +3 -3
  351. package/dist/sdk/tag/index.d.ts +3 -3
  352. package/dist/sdk/tag/index.js +1 -1
  353. package/dist/sdk/tag/types.d.cts +1 -1
  354. package/dist/sdk/tag/types.d.ts +1 -1
  355. package/dist/sdk/vault/index.cjs +1 -1
  356. package/dist/sdk/vault/index.d.cts +1 -1
  357. package/dist/sdk/vault/index.d.ts +1 -1
  358. package/dist/sdk/vault/index.js +1 -1
  359. package/dist/{semanticLayer-E0Vilu8u.cjs → semanticLayer-CKDVkU56.cjs} +78 -166
  360. package/dist/semanticLayer-CKDVkU56.cjs.map +1 -0
  361. package/dist/{semanticLayer-CSqmtHRo.js → semanticLayer-pYy082Ju.js} +78 -166
  362. package/dist/semanticLayer-pYy082Ju.js.map +1 -0
  363. package/dist/{serviceIds-DRcoTnSd.d.cts → serviceIds-DC-H6ZD9.d.cts} +2 -1
  364. package/dist/{serviceIds-DRcoTnSd.d.ts → serviceIds-DC-H6ZD9.d.ts} +2 -1
  365. package/dist/status/index.cjs +1 -1
  366. package/dist/status/index.d.cts +1 -1
  367. package/dist/status/index.d.ts +1 -1
  368. package/dist/status/index.js +1 -1
  369. package/dist/storage/index.cjs +6 -5
  370. package/dist/storage/index.d.cts +3 -3
  371. package/dist/storage/index.d.ts +3 -3
  372. package/dist/storage/index.js +6 -6
  373. package/dist/storage/types.d.cts +3 -3
  374. package/dist/storage/types.d.ts +3 -3
  375. package/dist/{storage-LYwFQPNO.js → storage-CZQHZcXG.js} +127 -289
  376. package/dist/storage-CZQHZcXG.js.map +1 -0
  377. package/dist/{storage-BKm7cztt.cjs → storage-JinL1y1s.cjs} +132 -288
  378. package/dist/storage-JinL1y1s.cjs.map +1 -0
  379. package/dist/stream/index.cjs +3 -3
  380. package/dist/stream/index.d.cts +2 -2
  381. package/dist/stream/index.d.ts +2 -2
  382. package/dist/stream/index.js +3 -3
  383. package/dist/stream/types.d.cts +1 -1
  384. package/dist/stream/types.d.ts +1 -1
  385. package/dist/syncActions/index.cjs +1 -1
  386. package/dist/syncActions/index.d.cts +1 -1
  387. package/dist/syncActions/index.d.ts +1 -1
  388. package/dist/syncActions/index.js +1 -1
  389. package/dist/syncActions/types.d.cts +2 -2
  390. package/dist/syncActions/types.d.ts +2 -2
  391. package/dist/{syncActions-QeBhIVhG.js → syncActions-BmmoqZO_.js} +130 -111
  392. package/dist/syncActions-BmmoqZO_.js.map +1 -0
  393. package/dist/{syncActions-OEZdVffK.cjs → syncActions-CtcLGQiy.cjs} +130 -111
  394. package/dist/syncActions-CtcLGQiy.cjs.map +1 -0
  395. package/dist/{tag-CsoOZWB_.cjs → tag-DHS_soa7.cjs} +2 -2
  396. package/dist/{tag-CsoOZWB_.cjs.map → tag-DHS_soa7.cjs.map} +1 -1
  397. package/dist/{tag-DCsoewjL.js → tag-hh-1nhNr.js} +2 -2
  398. package/dist/{tag-DCsoewjL.js.map → tag-hh-1nhNr.js.map} +1 -1
  399. package/dist/telemetry/index.cjs +7 -11
  400. package/dist/telemetry/index.cjs.map +1 -1
  401. package/dist/telemetry/index.d.cts +5 -9
  402. package/dist/telemetry/index.d.ts +5 -9
  403. package/dist/telemetry/index.js +7 -11
  404. package/dist/telemetry/index.js.map +1 -1
  405. package/dist/telemetry/types.d.cts +1 -1
  406. package/dist/telemetry/types.d.ts +1 -1
  407. package/dist/{types-DqxIx9Pi.d.cts → types-6kuMW4JW.d.cts} +2 -2
  408. package/dist/{types-Ct0YPy2w.d.ts → types-B2w2TtSA.d.ts} +3 -3
  409. package/dist/{types-M46WuBSm.d.cts → types-B61aCifg.d.cts} +2 -2
  410. package/dist/{types-COL1kVEB.d.cts → types-B8N_k79M.d.cts} +2 -2
  411. package/dist/{types-Jw10xuOW.d.cts → types-BIECJYun.d.ts} +171 -44
  412. package/dist/{types-DZk3XHiN.d.cts → types-BLNB882w.d.cts} +3 -3
  413. package/dist/{types-BEe50G2r.d.cts → types-BPy5Ozee.d.cts} +2 -2
  414. package/dist/{types-DBOSvWtD.d.ts → types-BS4jwuMi.d.ts} +8 -15
  415. package/dist/{types-BrYkBQo4.d.ts → types-BTK7Bv3n.d.cts} +171 -44
  416. package/dist/{types-CW6lCqrC.d.cts → types-BYM9Ptz5.d.ts} +93 -43
  417. package/dist/{types-D6UmMa6E.d.ts → types-BZDV8DZk.d.ts} +3 -3
  418. package/dist/{types-Cz83RiVu.d.cts → types-B_iLJlp4.d.ts} +255 -12
  419. package/dist/{types-DjrRmQUe.d.cts → types-BiMahEK8.d.cts} +92 -238
  420. package/dist/{types-BH5LLeJy.d.ts → types-Bl03Cg2n.d.cts} +255 -12
  421. package/dist/{types-bGQb4Jtl.d.cts → types-ByLH46Dt.d.cts} +13 -8
  422. package/dist/{types-g3vU7hcg.d.cts → types-Bydx6ga_.d.cts} +2 -2
  423. package/dist/{types-DYzJ6K2e.d.ts → types-CFeZCQ9p.d.cts} +93 -43
  424. package/dist/{types-DEc55spK.d.ts → types-CKmTZSPG.d.ts} +92 -238
  425. package/dist/{types-CaYtinmA.d.cts → types-CMzQSHAQ.d.cts} +3 -3
  426. package/dist/{types-N3EChotg.d.cts → types-CP_LBmw3.d.cts} +2 -2
  427. package/dist/{types-zZBxJ0P-.d.ts → types-CWyXTMwy.d.ts} +2 -2
  428. package/dist/{types-CPB-eF82.d.ts → types-CZJlLCbA.d.ts} +2 -2
  429. package/dist/{types-l9o4gFsI.d.ts → types-CZXPu3gn.d.ts} +2 -2
  430. package/dist/{types-BztF4HeB.d.ts → types-CaOtNjSZ.d.ts} +6 -13
  431. package/dist/{types-BTWIPEiU.d.ts → types-CfwqVkEA.d.ts} +2 -2
  432. package/dist/types-Cg14ncdV.d.ts +63 -0
  433. package/dist/{types-Bxhh2SJr.d.ts → types-CoJVrRAD.d.ts} +2 -2
  434. package/dist/{types-CKiW3n6v.d.ts → types-D3wcs4tp.d.ts} +2 -2
  435. package/dist/{types-DPS8nwkV.d.cts → types-DDOa07rU.d.cts} +8 -15
  436. package/dist/{types-BW2BXUB4.d.cts → types-DE9hgr7i.d.cts} +2 -2
  437. package/dist/{types-BOqD3Hqy.d.cts → types-DEzW1CfI.d.cts} +3 -3
  438. package/dist/{types-OaD-cbbl.d.ts → types-DIiOMV-t.d.ts} +3 -3
  439. package/dist/{types-BuqxXXYP.d.ts → types-DKc1gmd9.d.ts} +949 -190
  440. package/dist/{types-BQsOHNI0.d.ts → types-DRCMBt89.d.ts} +3 -3
  441. package/dist/{types-BQvv4RaI.d.cts → types-DUMal2E-.d.cts} +5 -8
  442. package/dist/types-DWiLcrxt.d.cts +63 -0
  443. package/dist/{types-DNxOHnZI.d.cts → types-Dd31Lw4S.d.cts} +2 -2
  444. package/dist/{types-Dmu-8g4O.d.ts → types-DekYAlA-.d.ts} +3 -3
  445. package/dist/{types-B2U9cFcx.d.ts → types-DgJeO9Nd.d.ts} +2 -2
  446. package/dist/{types-nrviNdzZ.d.ts → types-DicSaNwq.d.ts} +2 -2
  447. package/dist/{types-f8W_j6qD.d.cts → types-DinIJ1D_.d.cts} +688 -201
  448. package/dist/{types-DhDNS-5B.d.ts → types-DlQw6FCi.d.ts} +13 -8
  449. package/dist/{types-_RhBCj4_.d.cts → types-DoZtE9tz.d.cts} +3 -3
  450. package/dist/{types-BsxLGDoC.d.cts → types-DrvKfXXd.d.cts} +2 -2
  451. package/dist/{types-CzsnuPFh.d.cts → types-Dtuvhm3K.d.cts} +949 -190
  452. package/dist/{types-CcrvrAJX.d.ts → types-DwVSj-Da.d.ts} +5 -8
  453. package/dist/{types-C2vefB4D.d.ts → types-FwRmjsNN.d.ts} +10 -34
  454. package/dist/{types-C0_2KZ-A.d.ts → types-RbrfiY8T.d.ts} +2 -2
  455. package/dist/{types-DfvdbRPL.d.ts → types-WZBztugL.d.ts} +2 -2
  456. package/dist/{types-52irAt99.d.cts → types-YHUEArkR.d.cts} +2 -2
  457. package/dist/{types-fX4gbxfV.d.cts → types-bc-4z_gc.d.cts} +10 -34
  458. package/dist/{types-3eUgOA7I.d.cts → types-ePSqbXRr.d.cts} +6 -13
  459. package/dist/{types-BupPADSm.d.ts → types-n4PTnLii.d.ts} +688 -201
  460. package/dist/{types-DXskkNp8.d.cts → types-pvQzbgNE.d.cts} +3 -3
  461. package/dist/{types-DajzGOKB.d.ts → types-q-1r_9d1.d.ts} +2 -2
  462. package/dist/{types-D8Rrz51O.d.cts → types-tKkeLa2B.d.cts} +2 -2
  463. package/dist/{validateConnectionStatus-olE2sQ3U.js → validateConnectionStatus-BEGu8wXT.js} +7 -10
  464. package/dist/validateConnectionStatus-BEGu8wXT.js.map +1 -0
  465. package/dist/{validateConnectionStatus-CsvYmCOI.cjs → validateConnectionStatus-BEYkQpu9.cjs} +7 -10
  466. package/dist/validateConnectionStatus-BEYkQpu9.cjs.map +1 -0
  467. package/dist/vault/index.cjs +4 -4
  468. package/dist/vault/index.d.cts +1 -1
  469. package/dist/vault/index.d.ts +1 -1
  470. package/dist/vault/index.js +4 -4
  471. package/dist/vault/types.d.cts +1 -1
  472. package/dist/vault/types.d.ts +1 -1
  473. package/package.json +58 -4
  474. package/surface/apps.md +3 -3
  475. package/surface/auth.md +13 -6
  476. package/surface/businessWorkspaceApi.md +12 -0
  477. package/surface/chat.md +7 -7
  478. package/surface/kaiAgent.md +13 -9
  479. package/surface/management.md +18 -5
  480. package/surface/metastore.md +2 -2
  481. package/surface/queue.md +3 -3
  482. package/surface/sdk.md +13 -3
  483. package/surface/storage.md +6 -6
  484. package/surface/syncActions.md +9 -0
  485. package/dist/ValidationError-BekhphAq.js +0 -48
  486. package/dist/ValidationError-BekhphAq.js.map +0 -1
  487. package/dist/ValidationError-CLVJCCwH.cjs.map +0 -1
  488. package/dist/authClient-D7W9vWPR.js.map +0 -1
  489. package/dist/authClient-_PpvGgZJ.cjs.map +0 -1
  490. package/dist/concurrent-CH9fbNr3.js.map +0 -1
  491. package/dist/concurrent-tbiIa0UL.cjs.map +0 -1
  492. package/dist/configurations-BVvcimzo.js.map +0 -1
  493. package/dist/configurations-CyFF9Dtu.cjs.map +0 -1
  494. package/dist/configurations-VtNE0nrT.js.map +0 -1
  495. package/dist/configurations-zkNjr73Q.cjs.map +0 -1
  496. package/dist/constants-C4DlsF_M.cjs.map +0 -1
  497. package/dist/constants-wfbFsqqN.js.map +0 -1
  498. package/dist/createFetchClient-DgMiqTJ8.cjs.map +0 -1
  499. package/dist/createFetchClient-U-ZrwPl2.js.map +0 -1
  500. package/dist/credential-CihSf_xs.js +0 -36
  501. package/dist/credential-CihSf_xs.js.map +0 -1
  502. package/dist/credential-DVWvJFJs.cjs +0 -47
  503. package/dist/credential-DVWvJFJs.cjs.map +0 -1
  504. package/dist/dedupe-CiskLkGR.cjs +0 -30
  505. package/dist/dedupe-CiskLkGR.cjs.map +0 -1
  506. package/dist/dedupe-DYIHgZoG.js +0 -25
  507. package/dist/dedupe-DYIHgZoG.js.map +0 -1
  508. package/dist/isLoginPageRedirect-B0EmRsHr.cjs +0 -25
  509. package/dist/isLoginPageRedirect-B0EmRsHr.cjs.map +0 -1
  510. package/dist/isLoginPageRedirect-BTTAedW-.js +0 -20
  511. package/dist/isLoginPageRedirect-BTTAedW-.js.map +0 -1
  512. package/dist/jobStatus-0_Y3Sr4i.cjs.map +0 -1
  513. package/dist/jobStatus-PSZJMTiA.js.map +0 -1
  514. package/dist/kaiAgent-8LNzGhZc.js.map +0 -1
  515. package/dist/kaiAgent-B_TaUPRt.cjs.map +0 -1
  516. package/dist/management-BoxlRNg2.cjs.map +0 -1
  517. package/dist/management-Bp440RsV.js.map +0 -1
  518. package/dist/metastore-BYYWTb3m.cjs.map +0 -1
  519. package/dist/metastore-VCDRVhUT.js.map +0 -1
  520. package/dist/queue-DyotLFJi.js.map +0 -1
  521. package/dist/queue-OJJUUqc2.cjs.map +0 -1
  522. package/dist/semanticLayer-CSqmtHRo.js.map +0 -1
  523. package/dist/semanticLayer-E0Vilu8u.cjs.map +0 -1
  524. package/dist/storage-BKm7cztt.cjs.map +0 -1
  525. package/dist/storage-LYwFQPNO.js.map +0 -1
  526. package/dist/syncActions-OEZdVffK.cjs.map +0 -1
  527. package/dist/syncActions-QeBhIVhG.js.map +0 -1
  528. package/dist/validateConnectionStatus-CsvYmCOI.cjs.map +0 -1
  529. package/dist/validateConnectionStatus-olE2sQ3U.js.map +0 -1
package/dist/index.cjs CHANGED
@@ -1,52 +1,54 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_rolldown_runtime = require("./rolldown-runtime-VH7oDXx4.cjs");
3
3
  const require_project = require("./project-BvFi19K_.cjs");
4
- const require_jobStatus = require("./jobStatus-0_Y3Sr4i.cjs");
5
- const require_queue = require("./queue-OJJUUqc2.cjs");
6
- const require_concurrent = require("./concurrent-tbiIa0UL.cjs");
7
- const require_dedupe = require("./dedupe-CiskLkGR.cjs");
4
+ const require_jobStatus = require("./jobStatus-BMlsyXWI.cjs");
5
+ const require_queue = require("./queue-UG_BWKIC.cjs");
6
+ const require_concurrent = require("./concurrent-CdVfR1N5.cjs");
7
+ const require_dedupe = require("./dedupe-OSnnst2u.cjs");
8
8
  const require_store = require("./store-xS-Cu_VS.cjs");
9
- const require_storage = require("./storage-BKm7cztt.cjs");
10
- const require_tag = require("./tag-CsoOZWB_.cjs");
9
+ const require_storage = require("./storage-JinL1y1s.cjs");
10
+ const require_tag = require("./tag-DHS_soa7.cjs");
11
11
  const require_generateUUID = require("./generateUUID-C6qKBPIv.cjs");
12
12
  const require_isPlainObject = require("./isPlainObject-BB3iy87C.cjs");
13
- const require_configurations = require("./configurations-zkNjr73Q.cjs");
13
+ const require_configurations = require("./configurations-IYyOvhI3.cjs");
14
14
  const require_UserError = require("./UserError-CSGO1qII.cjs");
15
- const require_createFetchClient = require("./createFetchClient-DgMiqTJ8.cjs");
16
- const require_validateConnectionStatus = require("./validateConnectionStatus-CsvYmCOI.cjs");
17
- const require_ManagementClientAuthError = require("./ManagementClientAuthError-DD4u0EU7.cjs");
15
+ const require_createFetchClient = require("./createFetchClient-Cwp8max9.cjs");
16
+ const require_validateConnectionStatus = require("./validateConnectionStatus-BEYkQpu9.cjs");
17
+ const require_ManagementClientAuthError = require("./ManagementClientAuthError-DE7lNGZQ.cjs");
18
18
  const require_QueryJobTimeoutError = require("./QueryJobTimeoutError-CVNPdCWX.cjs");
19
19
  const require_SyncActionError = require("./SyncActionError-BG0zwchi.cjs");
20
- const require_ValidationError = require("./ValidationError-CLVJCCwH.cjs");
21
- const require_createGenericFetchClient = require("./createGenericFetchClient-o3cPJeRn.cjs");
22
- const require_import = require("./import-C83w7BKz.cjs");
23
- const require_authClient = require("./authClient-_PpvGgZJ.cjs");
24
- const require_management = require("./management-BoxlRNg2.cjs");
25
- const require_constants = require("./constants-C4DlsF_M.cjs");
20
+ const require_ValidationError = require("./ValidationError-D65QU0uq.cjs");
21
+ const require_createGenericFetchClient = require("./createGenericFetchClient-Dl9cqTvR.cjs");
22
+ const require_import = require("./import-CNk89mqy.cjs");
23
+ const require_authClient = require("./authClient-BmuUo0J4.cjs");
24
+ const require_management = require("./management-CCY0IYnq.cjs");
25
+ const require_constants = require("./constants-C6xku_Vx.cjs");
26
26
  const require_storageTable = require("./storageTable-C9crh4Ef.cjs");
27
- const require_semanticLayer = require("./semanticLayer-E0Vilu8u.cjs");
27
+ const require_kaiMemory = require("./kaiMemory-CClSPInt.cjs");
28
+ const require_semanticLayer = require("./semanticLayer-CKDVkU56.cjs");
28
29
  const require_sdk_storage_index = require("./sdk/storage/index.cjs");
29
30
  const require_sdk_vault_index = require("./sdk/vault/index.cjs");
30
31
  const require_ai_index = require("./ai/index.cjs");
31
- const require_appLogs = require("./appLogs-BjfUoWzs.cjs");
32
+ const require_appLogs = require("./appLogs-B9zFJIuy.cjs");
32
33
  const require_apps_index = require("./apps/index.cjs");
33
34
  const require_billing_index = require("./billing/index.cjs");
35
+ const require_businessWorkspaceApi = require("./businessWorkspaceApi-6tCDdpnY.cjs");
34
36
  const require_chat_index = require("./chat/index.cjs");
35
- const require_dataScience = require("./dataScience-0Rl_EuV_.cjs");
37
+ const require_dataScience = require("./dataScience-B5QxZnvW.cjs");
36
38
  const require_editor_index = require("./editor/index.cjs");
37
39
  const require_encryption_index = require("./encryption/index.cjs");
38
- const require_kaiAgent = require("./kaiAgent-B_TaUPRt.cjs");
39
- const require_metastore = require("./metastore-BYYWTb3m.cjs");
40
+ const require_kaiAgent = require("./kaiAgent-QNoeVKPs.cjs");
41
+ const require_metastore = require("./metastore-XtWciCZT.cjs");
40
42
  const require_notifications_index = require("./notifications/index.cjs");
41
- const require_oauth = require("./oauth-B8yqG6Sy.cjs");
43
+ const require_oauth = require("./oauth--2p8jkJf.cjs");
42
44
  const require_omnisearch_index = require("./omnisearch/index.cjs");
43
- const require_queryService = require("./queryService-BVtjkXy1.cjs");
45
+ const require_queryService = require("./queryService-CQzclHdL.cjs");
44
46
  const require_scheduler_index = require("./scheduler/index.cjs");
45
47
  const require_stream_index = require("./stream/index.cjs");
46
- const require_syncActions = require("./syncActions-OEZdVffK.cjs");
48
+ const require_syncActions = require("./syncActions-CtcLGQiy.cjs");
47
49
  const require_telemetry_index = require("./telemetry/index.cjs");
48
50
  const require_vault_index = require("./vault/index.cjs");
49
- const require_credential = require("./credential-DVWvJFJs.cjs");
51
+ const require_middleware = require("./middleware-IjYx3d5u.cjs");
50
52
  const require_sdk_queryService_index = require("./sdk/queryService/index.cjs");
51
53
  let zod = require("zod");
52
54
  zod = require_rolldown_runtime.__toESM(zod, 1);
@@ -55,22 +57,29 @@ function assert(value, message) {
55
57
  if (value == null) throw new Error(message);
56
58
  }
57
59
  //#endregion
60
+ //#region src/utils/ensure.ts
61
+ /**
62
+ * Read a key, or build its value and keep it.
63
+ *
64
+ * `Map.prototype.getOrInsertComputed` is this natively — swap to it once it clears the app's
65
+ * `baseline-widely-available` build target. Vite transpiles syntax, not methods, so adopting it
66
+ * early fails in the browser rather than at build.
67
+ */
68
+ const ensure = (map, key, build) => {
69
+ const existing = map.get(key);
70
+ if (existing !== void 0) return existing;
71
+ const created = build();
72
+ map.set(key, created);
73
+ return created;
74
+ };
75
+ //#endregion
58
76
  //#region src/utils/async/coalesce.ts
59
77
  /**
60
78
  * Coalesces concurrent triggers onto a single, never-parallel run of `task`.
61
- * Triggers fired while a run is busy collapse into one trailing run, and each
62
- * resolves with the first run that started after it — so it never sees stale state.
63
- *
64
- * Example — A triggers, then B and C trigger while A's run is still going:
65
- * 1. trigger A → run #1 starts
66
- * 2. trigger B, C → run #1 busy, so they wait
67
- * 3. run #1 done → A resolves
68
- * 4. run #2 starts → covers B and C together (one trailing run, not two)
69
- * 5. run #2 done → B and C resolve
70
79
  *
71
- * @returns a trigger; each call returns a promise of the task result.
72
- * @throws The returned promise rejects with whatever `task` throws or rejects
73
- * with — the caller handles it (try/catch, or `.catch` on `void trigger()`).
80
+ * - Triggers fired while a run is busy collapse into one trailing run.
81
+ * - Each trigger resolves with the first run started after it, so it never sees stale state.
82
+ * - The returned promise rejects with whatever `task` throws.
74
83
  */
75
84
  const coalesce = (task) => {
76
85
  let running = false;
@@ -390,8 +399,7 @@ const createProjectRefreshMiddleware = (shouldRefresh, requestRefresh) => (next)
390
399
  return response;
391
400
  };
392
401
  /**
393
- * The live project store: seeded from the verified token, re-verified (coalesced) after a
394
- * token-mutating request or an explicit re-scope. Its `middleware` drives the auto re-verify.
402
+ * The live project store, re-verified (coalesced) after a token-mutating request or a re-scope.
395
403
  */
396
404
  const createLiveProject = ({ initialToken, verify }) => {
397
405
  const store = require_store.createStore(require_project.createProject({ sapiToken: initialToken }));
@@ -414,24 +422,30 @@ const createLiveProject = ({ initialToken, verify }) => {
414
422
  const KeboolaErrorType = {
415
423
  Unconfigured: "unconfigured",
416
424
  NotAuthenticated: "not-authenticated",
425
+ SignInEnded: "sign-in-ended",
417
426
  AlreadyAuthenticated: "already-authenticated",
418
427
  NoStorageToken: "no-storage-token",
419
428
  NoManagementToken: "no-management-token",
420
429
  MissingProject: "missing-project",
421
430
  NotBearer: "not-bearer",
422
431
  NotReady: "not-ready",
423
- InvalidBuildTransition: "invalid-build-transition"
432
+ InvalidBuildTransition: "invalid-build-transition",
433
+ StackActive: "stack-active",
434
+ CredentialKindMismatch: "credential-kind-mismatch"
424
435
  };
425
436
  const MESSAGES = {
426
437
  [KeboolaErrorType.Unconfigured]: "The session is not configured — set a baseUrl first.",
427
438
  [KeboolaErrorType.NotAuthenticated]: "The session is not authenticated — sign in first.",
439
+ [KeboolaErrorType.SignInEnded]: "The sign-in this operation started under has ended — its result belongs to nobody.",
428
440
  [KeboolaErrorType.AlreadyAuthenticated]: "The session is already authenticated — reset before authenticating again.",
429
441
  [KeboolaErrorType.NoStorageToken]: "No storage token — authenticate the storage realm first.",
430
442
  [KeboolaErrorType.NoManagementToken]: "No management token — authenticate the management realm first.",
431
443
  [KeboolaErrorType.MissingProject]: "A bearer storage session requires a project — call setProject(projectId) first.",
432
444
  [KeboolaErrorType.NotBearer]: "This operation requires a bearer (OAuth) session.",
433
445
  [KeboolaErrorType.NotReady]: "The client is not ready — authenticate the storage realm first.",
434
- [KeboolaErrorType.InvalidBuildTransition]: "Invalid storage build transition — the build goes idle → initializing → ready | failed."
446
+ [KeboolaErrorType.InvalidBuildTransition]: "Invalid storage build transition — the build goes idle → initializing → ready | failed.",
447
+ [KeboolaErrorType.StackActive]: "The active stack cannot be closed — select another first.",
448
+ [KeboolaErrorType.CredentialKindMismatch]: "This client renews the other credential kind — log in the way its `credentials` mode expects."
435
449
  };
436
450
  var KeboolaError = class KeboolaError extends Error {
437
451
  type;
@@ -448,168 +462,6 @@ function assert$1(value, type) {
448
462
  if (value == null) throw new KeboolaError(type);
449
463
  }
450
464
  //#endregion
451
- //#region src/middlewares/loggingMiddleware.ts
452
- const CORRELATION_ID_HEADER = "X-Correlation-ID";
453
- const ALWAYS_REDACTED_HEADERS = [
454
- require_createFetchClient.KeboolaHttpHeader.MANAGEMENT_API_TOKEN,
455
- require_createFetchClient.KeboolaHttpHeader.STORAGE_API_TOKEN,
456
- "authorization",
457
- "cookie",
458
- "set-cookie"
459
- ];
460
- const ALWAYS_REDACTED_QUERY_PARAMS = /* @__PURE__ */ new Set([
461
- "token",
462
- "apikey",
463
- "api_key",
464
- "access_token",
465
- "refresh_token",
466
- "code",
467
- "state",
468
- "signature",
469
- "sig",
470
- "x-amz-signature",
471
- "x-amz-credential",
472
- "x-amz-security-token",
473
- "password",
474
- "secret"
475
- ]);
476
- const REDACTED = "[REDACTED]";
477
- const getRedactedUrl = (rawUrl) => {
478
- const url = new URL(rawUrl);
479
- if (url.username) url.username = REDACTED;
480
- if (url.password) url.password = REDACTED;
481
- url.searchParams.forEach((_value, key) => {
482
- if (ALWAYS_REDACTED_QUERY_PARAMS.has(key.toLowerCase())) url.searchParams.set(key, REDACTED);
483
- });
484
- return url.toString();
485
- };
486
- const ensureCorrelationId = (request) => {
487
- const correlationId = request.headers.get(CORRELATION_ID_HEADER) ?? require_generateUUID.generateUUID();
488
- request.headers.set(CORRELATION_ID_HEADER, correlationId);
489
- return correlationId;
490
- };
491
- const getRedactedHeaders = (headers, redacted) => {
492
- const redactedSet = new Set([...ALWAYS_REDACTED_HEADERS, ...redacted].map((h) => h.toLowerCase()));
493
- const result = {};
494
- headers.forEach((value, name) => {
495
- result[name] = redactedSet.has(name.toLowerCase()) ? REDACTED : value;
496
- });
497
- return result;
498
- };
499
- const getRequestLog = (request, redactedHeaders) => ({
500
- url: getRedactedUrl(request.url),
501
- headers: getRedactedHeaders(request.headers, redactedHeaders)
502
- });
503
- const getResponseLog = (response, redactedHeaders) => ({
504
- status: response.status,
505
- statusText: response.statusText,
506
- headers: getRedactedHeaders(response.headers, redactedHeaders)
507
- });
508
- const redactApiError = (error, redactedHeaders) => new require_createFetchClient.ApiError({
509
- request: new Request(getRedactedUrl(error.request.url), {
510
- method: error.request.method,
511
- headers: getRedactedHeaders(error.request.headers, redactedHeaders)
512
- }),
513
- response: new Response(null, {
514
- status: error.response.status,
515
- statusText: error.response.statusText,
516
- headers: getRedactedHeaders(error.response.headers, redactedHeaders)
517
- }),
518
- data: error.data
519
- });
520
- const formatLog = (level, log) => {
521
- const parts = [
522
- `[${level.toUpperCase()}]`,
523
- `${Math.round(log.durationMs)}ms`,
524
- log.method
525
- ];
526
- parts.push(log.request.url);
527
- if ("response" in log) parts.push(String(log.response.status));
528
- return parts.join(" ");
529
- };
530
- const createSafeLogger = (logger, level = "error-only") => {
531
- return {
532
- info: (log) => {
533
- if (level !== "all") return;
534
- try {
535
- if (logger?.info) {
536
- logger.info(log);
537
- return;
538
- }
539
- console.info(formatLog("info", log));
540
- } catch {}
541
- },
542
- error: (log) => {
543
- try {
544
- if (logger?.error) {
545
- logger.error(log);
546
- return;
547
- }
548
- console.error(formatLog("error", log));
549
- } catch {}
550
- }
551
- };
552
- };
553
- const createLoggingMiddleware = (options = {}) => {
554
- const safeLogger = createSafeLogger(options.logger, options.level);
555
- const redactHeaders = options.redactHeaders ?? [];
556
- return (next) => async (fetchRequest) => {
557
- const correlationId = ensureCorrelationId(fetchRequest.request);
558
- const start = performance.now();
559
- const method = fetchRequest.request.method.toLowerCase();
560
- const requestLog = getRequestLog(fetchRequest.request, redactHeaders);
561
- try {
562
- const result = await next(fetchRequest);
563
- safeLogger.info({
564
- correlationId,
565
- method,
566
- durationMs: performance.now() - start,
567
- request: requestLog,
568
- response: getResponseLog(result.response, redactHeaders)
569
- });
570
- return result;
571
- } catch (error) {
572
- if (error instanceof Error) safeLogger.error({
573
- correlationId,
574
- method,
575
- durationMs: performance.now() - start,
576
- request: requestLog,
577
- error: require_createFetchClient.isApiError(error) ? redactApiError(error, redactHeaders) : error
578
- });
579
- throw error;
580
- }
581
- };
582
- };
583
- //#endregion
584
- //#region src/middlewares/retryMiddleware.ts
585
- const DEFAULT_MAX_RETRIES = 5;
586
- const DEFAULT_RETRYABLE_STATUSES = [
587
- require_createFetchClient.HttpStatus.INTERNAL_SERVER_ERROR,
588
- require_createFetchClient.HttpStatus.BAD_GATEWAY,
589
- require_createFetchClient.HttpStatus.SERVICE_UNAVAILABLE,
590
- require_createFetchClient.HttpStatus.GATEWAY_TIMEOUT
591
- ];
592
- const DEFAULT_BACKOFF_FACTOR = .3;
593
- const defaultShouldRetry = (error) => error instanceof require_createFetchClient.ApiError && DEFAULT_RETRYABLE_STATUSES.includes(error.response.status);
594
- const createRetryMiddleware = (options) => {
595
- const { maxRetries = DEFAULT_MAX_RETRIES, backoffFactor = DEFAULT_BACKOFF_FACTOR, shouldRetry = defaultShouldRetry } = options ?? {};
596
- if (!Number.isInteger(maxRetries) || maxRetries < 0) throw new RangeError("maxRetries must be a non-negative integer");
597
- if (!Number.isFinite(backoffFactor) || backoffFactor < 0) throw new RangeError("backoffFactor must be a finite non-negative number");
598
- return (next) => async (request) => {
599
- for (let attempt = 0; attempt <= maxRetries; attempt++) try {
600
- return await next({
601
- ...request,
602
- request: request.request.clone()
603
- });
604
- } catch (error) {
605
- if (attempt === maxRetries || !shouldRetry(error, attempt)) throw error;
606
- const delayMs = backoffFactor * 1e3 * Math.pow(2, attempt);
607
- await require_jobStatus.delay(delayMs, request.request.signal ?? void 0);
608
- }
609
- throw new Error("unreachable");
610
- };
611
- };
612
- //#endregion
613
465
  //#region src/serviceClientRegistry/utils.ts
614
466
  const isBuiltInProperty = (property) => typeof property === "symbol" || property === "then" || property === "constructor" || property === "toString" || property === "valueOf";
615
467
  /**
@@ -698,146 +550,40 @@ const createMiddlewareFor = (middlewares) => {
698
550
  };
699
551
  };
700
552
  //#endregion
701
- //#region src/keboola/bearer/createConfig.ts
702
- const INITIAL = {
703
- status: "anonymous",
704
- baseUrl: null
705
- };
706
- const stamp = (tokens) => ({
707
- ...tokens,
708
- issuedAt: Date.now()
709
- });
710
- const createConfig$1 = (initial = INITIAL) => {
711
- const store = require_store.createStore(initial);
712
- let expiredNotified = false;
713
- let epoch = 0;
553
+ //#region src/keboola/legacy/createConfig.ts
554
+ const createConfig = () => {
555
+ const store = require_store.createStore({
556
+ baseUrl: null,
557
+ sapiToken: null,
558
+ managementToken: null
559
+ });
714
560
  const setBaseUrl = (baseUrl) => {
715
- if (store.get().status !== "anonymous") throw new KeboolaError(KeboolaErrorType.AlreadyAuthenticated);
716
561
  store.set({
717
- status: "anonymous",
562
+ ...store.get(),
718
563
  baseUrl
719
564
  });
720
565
  };
721
566
  const authenticate = (tokens) => {
722
- const state = store.get();
723
- if (state.status !== "anonymous") throw new KeboolaError(KeboolaErrorType.AlreadyAuthenticated);
724
- if (!state.baseUrl) throw new KeboolaError(KeboolaErrorType.Unconfigured);
725
- expiredNotified = false;
726
- epoch += 1;
727
- store.set({
728
- status: "authenticated",
729
- baseUrl: state.baseUrl,
730
- credential: stamp(tokens)
731
- });
732
- };
733
- const setProjectId = (projectId) => {
734
- const state = store.get();
735
- if (state.status === "anonymous") throw new KeboolaError(KeboolaErrorType.NotAuthenticated);
736
- store.set({
737
- status: "scoped",
738
- baseUrl: state.baseUrl,
739
- credential: state.credential,
740
- projectId
741
- });
742
- };
743
- /**
744
- * Drop the project scope, keeping the credential — the inverse of `setProjectId`, for leaving a
745
- * project without signing out. The project clients are keyed on the scope, so they tear down and
746
- * the storage build returns to `idle`; the session stays usable for `auth` and `management`.
747
- * No-op unless currently scoped.
748
- */
749
- const clearProjectId = () => {
750
- const state = store.get();
751
- if (state.status !== "scoped") return;
752
- store.set({
753
- status: "authenticated",
754
- baseUrl: state.baseUrl,
755
- credential: state.credential
756
- });
757
- };
758
- /** Drop the credential (sign out); keeps the configured baseUrl. */
759
- const reset = () => {
760
- epoch += 1;
761
- store.set({
762
- status: "anonymous",
763
- baseUrl: store.get().baseUrl
764
- });
765
- };
766
- /** Apply a token refresh: replace the credential (fresh tokens, new issue time); no-op before auth. */
767
- const applyRefresh = (tokens) => {
768
- const state = store.get();
769
- if (state.status === "anonymous") return;
770
- store.set({
771
- ...state,
772
- credential: stamp(tokens)
773
- });
774
- };
775
- /**
776
- * Dev/test lever: backdate the current token's issue time by a full lifetime so it reads as
777
- * expired, making the refresh policy rotate it on the next request. No-op before auth.
778
- */
779
- const forceExpire = () => {
780
- const state = store.get();
781
- if (state.status === "anonymous") return;
782
- const issuedAt = Date.now() - state.credential.expiresIn * 1e3;
567
+ const current = store.get();
783
568
  store.set({
784
- ...state,
785
- credential: {
786
- ...state.credential,
787
- issuedAt
788
- }
569
+ ...current,
570
+ sapiToken: tokens.sapiToken ?? current.sapiToken,
571
+ managementToken: tokens.managementToken ?? current.managementToken
789
572
  });
790
573
  };
791
- /**
792
- * The current credential, asserting the session is authenticated (or scoped). Single point for that
793
- * check so callers (token attach, refresh) don't each re-narrow the state.
794
- */
795
- const requireCredential = () => {
796
- const state = store.get();
797
- if (state.status === "anonymous") throw new KeboolaError(KeboolaErrorType.NotAuthenticated);
798
- return state.credential;
799
- };
800
- const getBaseUrl = () => store.get().baseUrl;
801
- /**
802
- * Which sign-in this is — a counter, bumped by `authenticate` and `reset`.
803
- *
804
- * - For anything long-lived that must not outlive the credential it was built against: capture it,
805
- * compare it later. A rotation does not move it; only a new session or a sign-out does.
806
- * - Distinct from `notifyExpired`'s latch, which answers "report this death once" rather than
807
- * "which session are we in".
808
- */
809
- const getEpoch = () => epoch;
810
- /**
811
- * Session-expiry latch (fire-once):
812
- * - why: concurrent 401s all report expiry, but the app must sign out once; and the credential /
813
- * auth middleware are long-lived singletons, so the latch can't live in them — it must reset
814
- * per session.
815
- * - how: returns `true` only for the first call since the last `authenticate` (which re-arms it),
816
- * so the caller runs its sign-out exactly once per session death.
817
- */
818
- const notifyExpired = () => {
819
- if (expiredNotified) return false;
820
- expiredNotified = true;
821
- return true;
822
- };
574
+ const getStorageToken = () => store.get().sapiToken ?? "";
575
+ const setStorageToken = (sapiToken) => store.set({
576
+ ...store.get(),
577
+ sapiToken
578
+ });
579
+ /** Current state, for diagnostics. */
823
580
  const debug = () => store.get();
824
581
  return {
825
- store: {
826
- get: store.get,
827
- subscribe: store.subscribe,
828
- dispose: store.dispose
829
- },
582
+ store,
830
583
  setBaseUrl,
831
584
  authenticate,
832
- setProjectId,
833
- clearProjectId,
834
- reset,
835
- applyRefresh,
836
- forceExpire,
837
- requireCredential,
838
- getBaseUrl,
839
- getEpoch,
840
- notifyExpired,
585
+ getStorageToken,
586
+ setStorageToken,
841
587
  debug
842
588
  };
843
589
  };
@@ -978,6 +724,7 @@ const createVariablesSdk = ({ storageClient }) => {
978
724
  };
979
725
  //#endregion
980
726
  //#region src/keboola/createServiceClients.ts
727
+ const withPath = (serviceBaseUrl, path) => typeof serviceBaseUrl === "string" ? `${serviceBaseUrl}${path}` : async () => `${await serviceBaseUrl()}${path}`;
981
728
  const createServiceClients = ({ baseUrl, auth, getServiceBaseUrl, middlewareFor, attachTokenMiddleware }) => createServiceClientRegistry()({
982
729
  getServiceBaseUrl,
983
730
  onUnavailable: ({ serviceId, path, clientName }) => {
@@ -1003,7 +750,7 @@ const createServiceClients = ({ baseUrl, auth, getServiceBaseUrl, middlewareFor,
1003
750
  serviceId: "data-science",
1004
751
  clientName: "apps",
1005
752
  clientFn: (serviceBaseUrl) => require_apps_index.createAppsClient({
1006
- baseUrl: `${serviceBaseUrl}/v2`,
753
+ baseUrl: withPath(serviceBaseUrl, "/v2"),
1007
754
  middlewares: middlewareFor("apps", [attachTokenMiddleware]),
1008
755
  auth
1009
756
  })
@@ -1075,7 +822,7 @@ const createServiceClients = ({ baseUrl, auth, getServiceBaseUrl, middlewareFor,
1075
822
  serviceId: "ai",
1076
823
  clientName: "omnisearch",
1077
824
  clientFn: (serviceBaseUrl) => require_omnisearch_index.createOmnisearchClient({
1078
- baseUrl: `${serviceBaseUrl}/omnisearch`,
825
+ baseUrl: withPath(serviceBaseUrl, "/omnisearch"),
1079
826
  middlewares: middlewareFor("omnisearch", [attachTokenMiddleware]),
1080
827
  auth
1081
828
  })
@@ -1095,6 +842,15 @@ const createServiceClients = ({ baseUrl, auth, getServiceBaseUrl, middlewareFor,
1095
842
  middlewares: middlewareFor("kaiAgent", [attachTokenMiddleware]),
1096
843
  auth
1097
844
  })
845
+ }).add({
846
+ serviceId: "business-workspace",
847
+ clientName: "businessWorkspaceApi",
848
+ clientFn: (serviceBaseUrl) => require_businessWorkspaceApi.createBusinessWorkspaceApiClient({
849
+ baseUrl: serviceBaseUrl,
850
+ middlewares: middlewareFor("businessWorkspaceApi", [attachTokenMiddleware]),
851
+ publicMiddlewares: middlewareFor("businessWorkspaceApi"),
852
+ auth
853
+ })
1098
854
  }).add({
1099
855
  serviceId: "oauth",
1100
856
  clientName: "oauth",
@@ -1145,571 +901,18 @@ const createServiceClients = ({ baseUrl, auth, getServiceBaseUrl, middlewareFor,
1145
901
  })
1146
902
  }).build();
1147
903
  //#endregion
1148
- //#region src/keboola/bearer/createProjectClients.ts
1149
- /**
1150
- * Bearer (OAuth) project surface. Same handshake + assembly as the legacy build. The
1151
- * `Authorization: Bearer` header + transparent refresh come from the engine-shared `authMiddleware`
1152
- * (one instance for management + every project client). This build only adds the project-scoped
1153
- * `X-KBC-ProjectId` header, composed *outside* the auth middleware so the header is present
1154
- * before it clones the request for the 401 replay. Bearer has no static token header, so this
1155
- * combined `attach` rides on every client — including the operational storage and the bootstrap reader.
1156
- */
1157
- const createProjectClients$1 = async ({ baseUrl, projectId, authMiddleware, middlewareFor, clientServiceUrls }) => {
904
+ //#region src/keboola/legacy/createProjectClients.ts
905
+ const createAttachStorageToken = (getToken) => (next) => (request) => {
906
+ request.request.headers.set(require_createFetchClient.KeboolaHttpHeader.STORAGE_API_TOKEN, getToken());
907
+ return next(request);
908
+ };
909
+ const createProjectClients = async ({ baseUrl, getStorageToken, onStorageTokenRefreshed, middlewareFor, clientServiceUrls }) => {
1158
910
  const auth = {
1159
- type: "bearer",
1160
- token: "",
1161
- projectId
1162
- };
1163
- const projectIdMiddleware = (next) => (request) => {
1164
- request.request.headers.set(require_createFetchClient.KeboolaHttpHeader.PROJECT_ID, String(projectId));
1165
- return next(request);
911
+ type: "sapi-token",
912
+ token: getStorageToken()
1166
913
  };
1167
- const attach = (next) => projectIdMiddleware(authMiddleware(next));
1168
- const reader = require_storage.createStorageClient({
1169
- baseUrl,
1170
- auth,
1171
- middlewares: [attach]
1172
- });
1173
- const [stackInfo, sapiToken, devBranches] = await Promise.all([
1174
- reader.getStackInfo({ exclude: "componentDetails" }),
1175
- reader.tokens.verify(),
1176
- reader.branches.getDevBranches()
1177
- ]);
1178
- const stack = createStack({
1179
- stackInfo,
1180
- clientServiceUrls
1181
- });
1182
- const defaultBranch = createDefaultBranch({ devBranches });
1183
- const liveProject = createLiveProject({
1184
- initialToken: sapiToken,
1185
- verify: () => reader.tokens.verify()
1186
- });
1187
- const storageTableStore = createDerivedStore({
1188
- source: liveProject.store,
1189
- build: require_storageTable.createStorageTable,
1190
- dependsOn: (project) => ({
1191
- useLegacyBucketPrefix: !project.hasFeature(require_constants.ProjectFeature.DisableLegacyBucketPrefix),
1192
- hasProtectedDefaultBranch: project.hasFeature(require_constants.ProjectFeature.SoxProtectedDefaultBranch),
1193
- hasStorageBranches: project.hasFeature(require_constants.ProjectFeature.StorageBranches)
1194
- })
1195
- });
1196
- const context = {
1197
- baseUrl: require_createFetchClient.normalizeBaseUrl(baseUrl),
1198
- stack,
1199
- defaultBranch,
1200
- get project() {
1201
- return liveProject.getProject();
1202
- },
1203
- get st() {
1204
- return storageTableStore.get();
1205
- }
1206
- };
1207
- const storage = require_storage.createStorageClient({
1208
- baseUrl,
1209
- auth,
1210
- middlewares: middlewareFor("storage", [attach, liveProject.middleware])
1211
- });
1212
- const { client: services, meta: serviceMeta } = createServiceClients({
1213
- baseUrl,
1214
- auth,
1215
- getServiceBaseUrl: context.stack.getServiceUrl,
1216
- middlewareFor,
1217
- attachTokenMiddleware: attach
1218
- });
1219
- const sdk = {
1220
- configuration: require_configurations.createConfigurationSdk({
1221
- storageClient: storage,
1222
- encryptionClient: services.encryption,
1223
- context
1224
- }),
1225
- tag: require_tag.createTagSdk({ metastoreClient: services.metastore }),
1226
- semanticLayer: require_semanticLayer.createSemanticLayerSdk({ metastoreClient: services.metastore }),
1227
- storage: require_sdk_storage_index.createStorageSdk({ storageClient: storage }),
1228
- vault: require_sdk_vault_index.createVaultSdk({
1229
- vaultClient: services.vault,
1230
- encryptionClient: services.encryption
1231
- }),
1232
- variables: createVariablesSdk({ storageClient: storage })
1233
- };
1234
- return {
1235
- context,
1236
- serviceMeta,
1237
- storage,
1238
- ...services,
1239
- sdk
1240
- };
1241
- };
1242
- //#endregion
1243
- //#region src/keboola/bearer/middleware.ts
1244
- /**
1245
- * Bearer auth for every outgoing request:
1246
- * - Stamps the current access token (from the credential) as the `Authorization` header.
1247
- * - On a 401, force-refreshes the token and replays the request once.
1248
- * - If the replay still 401s, the fresh token is rejected → marks the session expired.
1249
- *
1250
- * When the session is anonymous (`getAccessToken` → `null`) the request is passed through untouched
1251
- * with no 401 dance — so pre-auth calls on the auth client (`login`, `refresh`) work and a failed
1252
- * login is never mistaken for session expiry.
1253
- *
1254
- * Holds no token and never touches config — all token and refresh state lives in the credential.
1255
- */
1256
- const createBearerAuthMiddleware = (credential) => {
1257
- return (next) => async (request) => {
1258
- const token = await credential.getAccessToken({ forceRefresh: false });
1259
- if (token === null) return next(request);
1260
- const retryRequest = request.request.clone();
1261
- request.request.headers.set(require_createFetchClient.HttpHeader.AUTHORIZATION, `Bearer ${token}`);
1262
- try {
1263
- return await next(request);
1264
- } catch (error) {
1265
- if (!require_credential.isUnauthorized(error)) throw error;
1266
- const refreshed = await credential.getAccessToken({ forceRefresh: true });
1267
- if (refreshed === null) throw error;
1268
- retryRequest.headers.set(require_createFetchClient.HttpHeader.AUTHORIZATION, `Bearer ${refreshed}`);
1269
- try {
1270
- return await next({
1271
- ...request,
1272
- request: retryRequest
1273
- });
1274
- } catch (retryError) {
1275
- if (require_credential.isUnauthorized(retryError)) credential.notifyExpired();
1276
- throw retryError;
1277
- }
1278
- }
1279
- };
1280
- };
1281
- //#endregion
1282
- //#region src/keboola/bearer/persistor.ts
1283
- const SESSION_KEY = "keboola:bearer-session";
1284
- const persistedSessionSchema = zod.object({
1285
- baseUrl: zod.string().nullable(),
1286
- projectId: zod.number().nullable(),
1287
- refreshToken: zod.string().nullable()
1288
- });
1289
- const EMPTY_PERSISTED_SESSION = {
1290
- baseUrl: null,
1291
- projectId: null,
1292
- refreshToken: null
1293
- };
1294
- const createSessionPersistor = (storage) => createPersistor({
1295
- storage,
1296
- key: SESSION_KEY,
1297
- schema: persistedSessionSchema,
1298
- defaultValue: EMPTY_PERSISTED_SESSION
1299
- });
1300
- //#endregion
1301
- //#region src/keboola/bearer/keboola.ts
1302
- const createKeboola = (options = {}) => {
1303
- const persistor = createSessionPersistor(options.storage);
1304
- const config = createConfig$1();
1305
- const middlewareFor = createMiddlewareFor(options.middlewares);
1306
- const retryContention = createRetryMiddleware({ shouldRetry: (error) => error instanceof require_createFetchClient.ApiError && error.response.status === require_createFetchClient.HttpStatus.SERVICE_UNAVAILABLE });
1307
- const authClientBare = createDerivedStore({
1308
- source: config.store,
1309
- dependsOn: (state) => state.baseUrl,
1310
- build: (baseUrl) => baseUrl ? require_authClient.createAuthClient({
1311
- baseUrl,
1312
- middlewares: middlewareFor("auth", [retryContention])
1313
- }) : null
1314
- });
1315
- const refresh = async () => {
1316
- const client = authClientBare.get();
1317
- assert$1(client, KeboolaErrorType.NotReady);
1318
- const epoch = config.getEpoch();
1319
- const refreshed = await client.token.refresh(config.requireCredential().refreshToken).catch((error) => {
1320
- if (config.getEpoch() !== epoch) throw new KeboolaError(KeboolaErrorType.NotAuthenticated);
1321
- throw error;
1322
- });
1323
- if (config.getEpoch() !== epoch) throw new KeboolaError(KeboolaErrorType.NotAuthenticated);
1324
- config.applyRefresh(refreshed);
1325
- return refreshed.accessToken;
1326
- };
1327
- const getToken = () => {
1328
- const state = config.store.get();
1329
- if (state.status === "anonymous") return null;
1330
- const { accessToken, issuedAt, expiresIn } = state.credential;
1331
- return {
1332
- accessToken,
1333
- timing: {
1334
- issuedAt,
1335
- expiresIn
1336
- }
1337
- };
1338
- };
1339
- /**
1340
- * The session's state, once it is known to carry a credential.
1341
- *
1342
- * - Returns the state rather than nothing, so the caller reads `baseUrl` and `credential` off a
1343
- * narrowed union instead of re-checking the status to get at them.
1344
- * - `NotAuthenticated`, the same refusal `requireScopedProject` opens with. The two differ only in
1345
- * how far they go: this one stops at "somebody is signed in", which is all a request naming its
1346
- * own project needs.
1347
- */
1348
- const requireAuthenticated = () => {
1349
- const state = config.store.get();
1350
- if (state.status === "anonymous") throw new KeboolaError(KeboolaErrorType.NotAuthenticated);
1351
- return state;
1352
- };
1353
- /**
1354
- * The project this session is scoped to, right now.
1355
- *
1356
- * - Read at every point that stamps a project, never snapshotted across an `await`: the scope moves
1357
- * with `setProject`/`clearProject`, and neither ends the session, so it is not in the epoch and
1358
- * `assertSameSession` cannot see it change.
1359
- * - `NotReady` rather than `NotAuthenticated` when merely unscoped — the credential is fine, the
1360
- * project is what is missing. A credential alone does not authorize a project request: kai-agent
1361
- * reads the project from the header, not the token, and cannot attribute a call that omits it.
1362
- */
1363
- const requireScopedProject = () => {
1364
- const state = requireAuthenticated();
1365
- if (state.status !== "scoped") throw new KeboolaError(KeboolaErrorType.NotReady);
1366
- return state.projectId;
1367
- };
1368
- /**
1369
- * The project client sets `forProject` has handed out, keyed by project id.
1370
- *
1371
- * - Not keyed by stack: `setBaseUrl` throws once authenticated and `signOut` empties this, so one
1372
- * entry can never belong to a different `baseUrl` than the live session.
1373
- * - A `lazy` per key, not a bare promise: concurrent callers share one bootstrap, later ones replay
1374
- * the resolved set, and a rejected build clears only its own slot — so a build orphaned by a
1375
- * sign-out cannot evict the entry that replaced it.
1376
- */
1377
- const extraProjects = /* @__PURE__ */ new Map();
1378
- const signOut = () => {
1379
- config.reset();
1380
- credential.abandonRefresh();
1381
- extraProjects.clear();
1382
- persistor.clear();
1383
- };
1384
- const onSessionExpired = () => {
1385
- if (config.notifyExpired()) signOut();
1386
- };
1387
- const credential = require_credential.createBearerCredential({
1388
- refresh,
1389
- getToken,
1390
- onSessionExpired
1391
- });
1392
- const sessionGuard = (epoch) => () => {
1393
- if (config.getEpoch() !== epoch) throw new KeboolaError(KeboolaErrorType.NotAuthenticated);
1394
- };
1395
- /**
1396
- * The auth middleware, refusing to carry a request across a change of session.
1397
- *
1398
- * - The middleware holds no token — it reads the credential live — so anything built on it acts as
1399
- * whoever is signed in *at request time*, not whoever built it. Rebuilding a store on sign-out
1400
- * only stops new reads; a request already in flight completes as the next user, still stamped
1401
- * with the old project. `config`'s epoch moves on `authenticate` and `reset` and never on a
1402
- * rotation, so it is exactly "which sign-in is this".
1403
- * - `epochFor` says which sign-in a request answers to, resolved per request:
1404
- * 1. a client set pins to the sign-in that *built* it (`pinToSession`) — a set the caller still
1405
- * holds must not ride the session that replaced it;
1406
- * 2. `api.auth` pins to the sign-in the request *started* on, because its store is keyed on
1407
- * `baseUrl` alone: it is built once, while anonymous, so a build-time pin would freeze at that
1408
- * epoch and refuse every authenticated call.
1409
- * - The guard covers every credential read, not only the wire request, so it wraps the credential
1410
- * rather than sitting beside it. The 401 path rotates the token by calling the credential
1411
- * directly: a straggler from a dead session would otherwise spend the *live* session's
1412
- * single-use refresh token, and sign that session out if the rotation itself came back 401.
1413
- * - `expiresSession` decides whether a 401 that survives a rotation means the session is dead.
1414
- * True for this session's own realms; false where the 401 may be about the project instead of
1415
- * the credential (see `forProject`).
1416
- * - `inner` is for middleware that **re-invokes `next`** — a retry. Composed outside the pin it
1417
- * would re-enter it per attempt, and with a per-request `epochFor` each attempt would re-pin to
1418
- * whoever is signed in by then: a 503 backoff is exactly long enough for a sign-out to land, and
1419
- * the retry then goes out as the next user. Inside, one epoch covers every attempt and each
1420
- * attempt still passes the guard. Anything new that retries belongs here, not in the array.
1421
- */
1422
- const createPinnedAuthMiddleware = (epochFor, { expiresSession = true, inner = [] } = {}) => {
1423
- return (next) => (request) => {
1424
- const assertSameSession = sessionGuard(epochFor());
1425
- const pinnedCredential = {
1426
- ...credential,
1427
- getAccessToken: async (options) => {
1428
- assertSameSession();
1429
- return credential.getAccessToken(options);
1430
- },
1431
- notifyExpired: expiresSession ? credential.notifyExpired : () => {}
1432
- };
1433
- const guarded = (wire) => (repeated) => {
1434
- assertSameSession();
1435
- return wire(repeated);
1436
- };
1437
- const chain = inner.reduceRight((acc, middleware) => middleware(acc), guarded(next));
1438
- return createBearerAuthMiddleware(pinnedCredential)(chain)(request);
1439
- };
1440
- };
1441
- /**
1442
- * Pin something long-lived to the sign-in live right now.
1443
- *
1444
- * - `assertSameSession` is for whatever no middleware chain covers: a bootstrap whose every
1445
- * request passed the guard before the sign-out resolves anyway and must not be handed back, and
1446
- * `getAuthHeaders`, which emits the credential by hand.
1447
- */
1448
- const pinToSession = (options) => {
1449
- const epoch = config.getEpoch();
1450
- return {
1451
- assertSameSession: sessionGuard(epoch),
1452
- pinnedAuthMiddleware: createPinnedAuthMiddleware(() => epoch, options)
1453
- };
1454
- };
1455
- const authClient = createDerivedStore({
1456
- source: config.store,
1457
- dependsOn: (state) => state.baseUrl,
1458
- build: (baseUrl) => baseUrl ? require_authClient.createAuthClient({
1459
- baseUrl,
1460
- middlewares: middlewareFor("auth", [createPinnedAuthMiddleware(config.getEpoch, { inner: [retryContention] })])
1461
- }) : null
1462
- });
1463
- const management = createDerivedStore({
1464
- source: config.store,
1465
- dependsOn: (state) => state.status === "anonymous" ? null : state.baseUrl,
1466
- build: (baseUrl) => baseUrl ? require_management.createManagementClient({
1467
- baseUrl,
1468
- auth: {
1469
- type: "bearer",
1470
- token: ""
1471
- },
1472
- middlewares: middlewareFor("management", [pinToSession().pinnedAuthMiddleware])
1473
- }) : null
1474
- });
1475
- const projectClientsAsync = createDerivedAsyncStore({
1476
- source: config.store,
1477
- dependsOn: (state) => state.status === "scoped" ? {
1478
- baseUrl: state.baseUrl,
1479
- projectId: state.projectId
1480
- } : null,
1481
- build: ({ baseUrl, projectId }) => {
1482
- return createProjectClients$1({
1483
- baseUrl,
1484
- authMiddleware: pinToSession().pinnedAuthMiddleware,
1485
- projectId,
1486
- middlewareFor,
1487
- clientServiceUrls: options.clientServiceUrls
1488
- });
1489
- }
1490
- });
1491
- const forProject = async (projectId) => {
1492
- const state = requireAuthenticated();
1493
- const cached = extraProjects.get(projectId);
1494
- if (cached) return cached();
1495
- const { assertSameSession, pinnedAuthMiddleware } = pinToSession({ expiresSession: false });
1496
- const build = require_jobStatus.lazy(async () => {
1497
- const clients = await createProjectClients$1({
1498
- baseUrl: state.baseUrl,
1499
- authMiddleware: pinnedAuthMiddleware,
1500
- projectId,
1501
- middlewareFor,
1502
- clientServiceUrls: options.clientServiceUrls
1503
- });
1504
- assertSameSession();
1505
- return clients;
1506
- });
1507
- extraProjects.set(projectId, build);
1508
- return build();
1509
- };
1510
- if (options.baseUrl) config.setBaseUrl(options.baseUrl);
1511
- config.store.subscribe((state) => {
1512
- if (state.status === "anonymous") return;
1513
- persistor.persist({
1514
- baseUrl: state.baseUrl,
1515
- projectId: state.status === "scoped" ? state.projectId : null,
1516
- refreshToken: state.credential.refreshToken
1517
- });
1518
- });
1519
- const debug = () => ({
1520
- type: "Bearer",
1521
- config: config.debug(),
1522
- authReady: authClient.get() !== null,
1523
- managementReady: management.get() !== null,
1524
- storage: projectClientsAsync.store.get().state
1525
- });
1526
- const session = {
1527
- hasPersistedValue: persistor.hasPersistedValue,
1528
- setBaseUrl: config.setBaseUrl,
1529
- isStorageReady: () => projectClientsAsync.store.get().state === "ready",
1530
- authenticate: (tokens) => config.authenticate(tokens),
1531
- setProject: config.setProjectId,
1532
- setProjectAsync: async (projectId) => {
1533
- config.setProjectId(projectId);
1534
- await projectClientsAsync.settled();
1535
- },
1536
- /**
1537
- * Leave the current project but stay signed in — the storage build returns to `idle`, so a
1538
- * consumer gating on it falls back to its project picker. The persisted session is rewritten with
1539
- * `projectId: null` by the subscription above, so a reload lands on the picker rather than
1540
- * re-entering the project. Use `reset` to sign out instead.
1541
- */
1542
- clearProject: config.clearProjectId,
1543
- /**
1544
- * The clients for one project, off this session — for reaching a second project without leaving
1545
- * the first.
1546
- *
1547
- * - `setProjectAsync` *moves* the session (and `api`) to another project; this *adds* one. The
1548
- * returned set is the caller's to hold and never appears on `api`.
1549
- * - Every set shares this session's auth middleware, so one rotation serves all of them. A second
1550
- * `createKeboola()` does not: both hold the same single-use refresh token, and the first to
1551
- * rotate invalidates the other's, whose next refresh 401s and signs it out.
1552
- * - Independent of the scope, including for the scoped project itself — asking for that one
1553
- * builds a second set with its own `liveProject`, so prefer `api.*` there.
1554
- */
1555
- forProject,
1556
- reset: signOut,
1557
- /**
1558
- * Dev/test only: mark the current access token as expired so the bearer credential rotates it on
1559
- * the next request. Pair with any authenticated call (e.g. `api.storage.tokens.verify()`) to force
1560
- * the rotation immediately and observe the new credential.
1561
- */
1562
- debugForceRefresh: config.forceExpire,
1563
- /**
1564
- * The headers that authorize one off-client request, resolved fresh each call.
1565
- *
1566
- * - For a transport this package does not own — the chat SSE stream, whose `fetch` the AI SDK
1567
- * holds. Anything with a service client on `api` should use that instead.
1568
- * - Returns the assembled bag, never the bare token: no caller handles the credential as a
1569
- * string, and `X-KBC-ProjectId` is composed here rather than in every consuming app.
1570
- * - Resolved per call, through the credential — so a near-expiry token rotates and a revoked
1571
- * one is never re-sent. A snapshot held by the caller would do neither.
1572
- * - Throws rather than emitting a half-formed `Bearer null`: a session with no credential has
1573
- * nothing to authorize with.
1574
- * - Pinned to the sign-in it was called on, like every client here. This is the one
1575
- * credential-emitting surface with no middleware chain for the guard to sit in, so the check
1576
- * is written out around the `await` that rotates the token.
1577
- *
1578
- * `projectId` names the project the headers authorize, for a caller reaching a project the
1579
- * session is not scoped to:
1580
- *
1581
- * - **Omitted**, the session's own scope answers — unchanged, and re-read *after* the rotation
1582
- * rather than carried across it. The epoch the pin compares moves on a sign-in and a sign-out
1583
- * only, so a project switch mid-rotation is invisible to it.
1584
- * - **Given**, it is what the header says, and the scope is not consulted at all. A caller that
1585
- * names a project has said everything the request needs: the credential is user-level and the
1586
- * project is a header on top of it, so an authenticated session suffices where an unnamed call
1587
- * requires a scoped one. Nothing about the session can change the answer, so there is nothing
1588
- * to re-read after the `await`.
1589
- * - **Not checked against an access set**, because this session cannot acquire one:
1590
- * `forProject` — the only other surface taking a caller-supplied project id — records that
1591
- * connection collapses every bearer failure into a single `invalid_token` 401, so "no access
1592
- * to this project" and "revoked token" are the same response. Whether the caller may reach a
1593
- * project is the caller's own knowledge, from `token.introspect`. What is guaranteed here is
1594
- * that the header names what was asked for and never something else — which is the failure
1595
- * worth preventing: a turn sent somewhere the transcript above it did not come from.
1596
- */
1597
- getAuthHeaders: async (projectId) => {
1598
- const { assertSameSession } = pinToSession();
1599
- if (projectId === void 0) requireScopedProject();
1600
- else requireAuthenticated();
1601
- const accessToken = await credential.getAccessToken();
1602
- assertSameSession();
1603
- const authorizedProjectId = projectId ?? requireScopedProject();
1604
- assert$1(accessToken, KeboolaErrorType.NotAuthenticated);
1605
- return {
1606
- [require_createFetchClient.HttpHeader.AUTHORIZATION]: `Bearer ${accessToken}`,
1607
- [require_createFetchClient.KeboolaHttpHeader.PROJECT_ID]: String(authorizedProjectId)
1608
- };
1609
- },
1610
- restore: async () => {
1611
- const persisted = persistor.hydrate();
1612
- if (!persisted.refreshToken || !persisted.baseUrl) return { status: "empty" };
1613
- const configured = config.getBaseUrl();
1614
- if (configured && configured !== persisted.baseUrl) {
1615
- persistor.clear();
1616
- return { status: "empty" };
1617
- }
1618
- if (!configured) config.setBaseUrl(persisted.baseUrl);
1619
- const client = authClientBare.get();
1620
- assert$1(client, KeboolaErrorType.NotReady);
1621
- const startedOn = config.getEpoch();
1622
- try {
1623
- const refreshed = await client.token.refresh(persisted.refreshToken);
1624
- if (config.getEpoch() !== startedOn) return { status: "empty" };
1625
- config.authenticate(refreshed);
1626
- if (persisted.projectId !== null) {
1627
- config.setProjectId(persisted.projectId);
1628
- await projectClientsAsync.settled();
1629
- }
1630
- return { status: "restored" };
1631
- } catch (err) {
1632
- if (config.getEpoch() !== startedOn) return { status: "empty" };
1633
- if (require_credential.isUnauthorized(err)) {
1634
- persistor.clear();
1635
- return { status: "expired" };
1636
- }
1637
- throw err;
1638
- }
1639
- },
1640
- subscribe: (listener) => {
1641
- const unsubscribeConfig = config.store.subscribe(() => listener(debug()));
1642
- const unsubscribeBuild = projectClientsAsync.store.subscribe(() => listener(debug()));
1643
- return () => {
1644
- unsubscribeConfig();
1645
- unsubscribeBuild();
1646
- };
1647
- },
1648
- debug
1649
- };
1650
- return {
1651
- api: createApi({
1652
- getAuthClient: () => authClient.get(),
1653
- getManagementClient: () => management.get(),
1654
- getProjectClients: () => {
1655
- const state = projectClientsAsync.store.get();
1656
- return state.state === "ready" ? state.value : null;
1657
- }
1658
- }),
1659
- session
1660
- };
1661
- };
1662
- //#endregion
1663
- //#region src/keboola/legacy/createConfig.ts
1664
- const createConfig = () => {
1665
- const store = require_store.createStore({
1666
- baseUrl: null,
1667
- sapiToken: null,
1668
- managementToken: null
1669
- });
1670
- const setBaseUrl = (baseUrl) => {
1671
- store.set({
1672
- ...store.get(),
1673
- baseUrl
1674
- });
1675
- };
1676
- const authenticate = (tokens) => {
1677
- const current = store.get();
1678
- store.set({
1679
- ...current,
1680
- sapiToken: tokens.sapiToken ?? current.sapiToken,
1681
- managementToken: tokens.managementToken ?? current.managementToken
1682
- });
1683
- };
1684
- const getStorageToken = () => store.get().sapiToken ?? "";
1685
- const setStorageToken = (sapiToken) => store.set({
1686
- ...store.get(),
1687
- sapiToken
1688
- });
1689
- /** Current state, for diagnostics. */
1690
- const debug = () => store.get();
1691
- return {
1692
- store,
1693
- setBaseUrl,
1694
- authenticate,
1695
- getStorageToken,
1696
- setStorageToken,
1697
- debug
1698
- };
1699
- };
1700
- //#endregion
1701
- //#region src/keboola/legacy/createProjectClients.ts
1702
- const createAttachStorageToken = (getToken) => (next) => (request) => {
1703
- request.request.headers.set(require_createFetchClient.KeboolaHttpHeader.STORAGE_API_TOKEN, getToken());
1704
- return next(request);
1705
- };
1706
- const createProjectClients = async ({ baseUrl, getStorageToken, onStorageTokenRefreshed, middlewareFor, clientServiceUrls }) => {
1707
- const auth = {
1708
- type: "sapi-token",
1709
- token: getStorageToken()
1710
- };
1711
- const attach = createAttachStorageToken(getStorageToken);
1712
- const _storage = require_storage.createStorageClient({
914
+ const attach = createAttachStorageToken(getStorageToken);
915
+ const _storage = require_storage.createStorageClient({
1713
916
  baseUrl,
1714
917
  auth,
1715
918
  middlewares: [attach]
@@ -1769,6 +972,7 @@ const createProjectClients = async ({ baseUrl, getStorageToken, onStorageTokenRe
1769
972
  }),
1770
973
  tag: require_tag.createTagSdk({ metastoreClient: services.metastore }),
1771
974
  semanticLayer: require_semanticLayer.createSemanticLayerSdk({ metastoreClient: services.metastore }),
975
+ kaiMemory: require_kaiMemory.createKaiMemorySdk({ metastoreClient: services.metastore }),
1772
976
  storage: require_sdk_storage_index.createStorageSdk({ storageClient: storage }),
1773
977
  vault: require_sdk_vault_index.createVaultSdk({
1774
978
  vaultClient: services.vault,
@@ -1866,6 +1070,1407 @@ const createLegacyKeboola = (options = {}) => {
1866
1070
  };
1867
1071
  };
1868
1072
  //#endregion
1073
+ //#region src/keboola/bearer/credentials/renewal.ts
1074
+ const renewalGrant = (credential) => credential.type === "token" ? {
1075
+ type: "token",
1076
+ refreshToken: credential.refreshToken
1077
+ } : {
1078
+ type: "cookie",
1079
+ sessionId: credential.sessionId
1080
+ };
1081
+ const renew = async (client, grant) => {
1082
+ if (grant.type === "cookie") {
1083
+ const { accessToken, expiresIn, sessionId } = await client.token.refreshWithSession({ sessionId: grant.sessionId });
1084
+ return {
1085
+ type: "cookie",
1086
+ accessToken,
1087
+ expiresIn,
1088
+ sessionId
1089
+ };
1090
+ }
1091
+ const { accessToken, expiresIn, refreshToken } = await client.token.refreshWithToken({ refreshToken: grant.refreshToken });
1092
+ if (!refreshToken) throw new KeboolaError(KeboolaErrorType.NotAuthenticated);
1093
+ return {
1094
+ type: "token",
1095
+ accessToken,
1096
+ expiresIn,
1097
+ refreshToken
1098
+ };
1099
+ };
1100
+ //#endregion
1101
+ //#region src/keboola/bearer/credentials/credentials.ts
1102
+ const DEFAULT_REFRESH_THRESHOLD = .9;
1103
+ const signInEnded = () => new KeboolaError(KeboolaErrorType.SignInEnded);
1104
+ const createCredentials = ({ state, persistor, middlewares, mode = "token", refreshThreshold = DEFAULT_REFRESH_THRESHOLD, onSignedOut }) => {
1105
+ const rotationMap = /* @__PURE__ */ new Map();
1106
+ const generations = /* @__PURE__ */ new Map();
1107
+ const generationOf = (baseUrl) => generations.get(baseUrl) ?? 0;
1108
+ const refresh = async (baseUrl, grant) => {
1109
+ const client = require_authClient.createAuthClient({
1110
+ baseUrl,
1111
+ middlewares
1112
+ });
1113
+ const epochBefore = require_jobStatus.Result.unwrap(state.auth.getEpoch(baseUrl));
1114
+ const generationBefore = generationOf(baseUrl);
1115
+ const refreshed = await require_jobStatus.Result.tryCatchAsync(() => renew(client, grant));
1116
+ return require_jobStatus.Result.unwrapOr(state.auth.getEpoch(baseUrl), -1) === epochBefore && generationOf(baseUrl) === generationBefore ? refreshed : require_jobStatus.Result.failure(signInEnded());
1117
+ };
1118
+ /**
1119
+ * A stack's teardown, from the credential's side.
1120
+ *
1121
+ * - Bumps the generation, so an in-flight rotation can no longer write.
1122
+ * - Drops the deduped entry, so nothing joins that rotation.
1123
+ */
1124
+ const forget = (baseUrl) => {
1125
+ generations.set(baseUrl, generationOf(baseUrl) + 1);
1126
+ rotationMap.delete(baseUrl);
1127
+ };
1128
+ /**
1129
+ * The rotation, and the one place a credential is declared dead.
1130
+ *
1131
+ * - A refused refresh token or session is unambiguous.
1132
+ * - The triggering 401 is not (an unreachable project answers the same), so never sign out on a replay.
1133
+ */
1134
+ const rotateOnce = async (baseUrl) => {
1135
+ const credential = state.auth.requireCredentialOf(baseUrl, mode);
1136
+ if (!credential.success) return credential;
1137
+ const refreshed = await refresh(baseUrl, renewalGrant(credential.data));
1138
+ if (!refreshed.success) {
1139
+ if (require_middleware.isUnauthorized(refreshed.error)) expire(baseUrl);
1140
+ return refreshed;
1141
+ }
1142
+ return require_jobStatus.Result.map(state.auth.applyRefresh(baseUrl, refreshed.data), () => refreshed.data.accessToken);
1143
+ };
1144
+ const rotate = (baseUrl) => ensure(rotationMap, baseUrl, () => require_dedupe.dedupe(() => rotateOnce(baseUrl)))();
1145
+ const restoreStack = async (baseUrl, grant) => {
1146
+ if (!state.auth.startRestore(baseUrl).success) return "unreachable";
1147
+ const refreshed = await refresh(baseUrl, grant);
1148
+ if (!refreshed.success) {
1149
+ state.auth.cancelRestore(baseUrl);
1150
+ return require_middleware.isUnauthorized(refreshed.error) ? "refused" : "unreachable";
1151
+ }
1152
+ state.auth.authenticate(baseUrl, refreshed.data);
1153
+ return "restored";
1154
+ };
1155
+ const restoreProjects = (baseUrl, projects) => {
1156
+ for (const { projectId } of projects) state.projects.open(baseUrl, projectId);
1157
+ };
1158
+ /**
1159
+ * Every persisted stack back into the table, with whatever credential it can hand back.
1160
+ *
1161
+ * - Never writes the scope. `lastActive` is what was scoped when the session was stored, for the
1162
+ * caller to select.
1163
+ * - `status` reports what became of `lastActive`'s credential; the client reads it to decide
1164
+ * when persistence may start.
1165
+ */
1166
+ const restore = async () => {
1167
+ const hydrated = persistor.hydrate();
1168
+ const stacks = hydrated.stacks.map((stack) => stack.credential && stack.credential.type !== "static" && stack.credential.type !== mode ? {
1169
+ ...stack,
1170
+ credential: null
1171
+ } : stack);
1172
+ const { current } = hydrated;
1173
+ const scoped = stacks.find(({ baseUrl }) => baseUrl === current?.baseUrl);
1174
+ const restored = stacks.map(async ({ baseUrl, credential, projects }) => {
1175
+ state.stacks.ensure(baseUrl);
1176
+ if (!credential) return "unreachable";
1177
+ if (require_jobStatus.Result.unwrapOr(state.auth.getEpoch(baseUrl), 0) > 0) return "skipped";
1178
+ const outcome = credential.type === "static" ? state.auth.authenticate(baseUrl, credential).success ? "restored" : "refused" : await restoreStack(baseUrl, credential);
1179
+ if (outcome === "restored") restoreProjects(baseUrl, projects);
1180
+ return outcome;
1181
+ });
1182
+ const results = await Promise.all(restored);
1183
+ const outcome = scoped?.credential ? results[stacks.indexOf(scoped)] : void 0;
1184
+ return {
1185
+ lastActive: current,
1186
+ status: outcome === void 0 || outcome === "skipped" ? "empty" : outcome === "restored" ? "restored" : outcome === "unreachable" ? "unreachable" : "expired"
1187
+ };
1188
+ };
1189
+ const isStale = (baseUrl) => {
1190
+ const ageing = require_jobStatus.Result.map(state.auth.requireCredentialOf(baseUrl, mode), ({ issuedAt, expiresIn }) => Date.now() >= issuedAt + expiresIn * 1e3 * refreshThreshold);
1191
+ return require_jobStatus.Result.unwrapOr(ageing, false);
1192
+ };
1193
+ const signOut = (baseUrl) => {
1194
+ rotationMap.delete(baseUrl);
1195
+ const signedOut = state.auth.signOut(baseUrl);
1196
+ onSignedOut?.(baseUrl);
1197
+ return signedOut;
1198
+ };
1199
+ const expire = (baseUrl) => {
1200
+ if (state.auth.notifyExpired(baseUrl)) signOut(baseUrl);
1201
+ };
1202
+ const canRefresh = (baseUrl) => state.auth.requireCredentialOf(baseUrl, mode).success;
1203
+ const middleware = (baseUrl) => require_middleware.createBearerAuthMiddleware({ getAccessToken: async ({ forceRefresh = false } = {}) => {
1204
+ if (forceRefresh) return canRefresh(baseUrl) ? require_jobStatus.Result.unwrap(await rotate(baseUrl)) : null;
1205
+ if (!isStale(baseUrl)) return state.auth.getAccessToken(baseUrl);
1206
+ return require_jobStatus.Result.unwrapOr(await rotate(baseUrl), state.auth.getAccessToken(baseUrl));
1207
+ } });
1208
+ return {
1209
+ middleware,
1210
+ rotate,
1211
+ restore,
1212
+ signOut,
1213
+ forget
1214
+ };
1215
+ };
1216
+ //#endregion
1217
+ //#region src/keboola/bearer/state/factories.ts
1218
+ /**
1219
+ * Everything the table constructs: the entries themselves, and the failures reading them produces.
1220
+ *
1221
+ * Nothing here touches the store — a factory takes what it is told and returns a value, so the
1222
+ * namespaces the tables build on can be read without following a dependency.
1223
+ */
1224
+ const projectEntryId = (baseUrl, projectId) => `${baseUrl}#${projectId}`;
1225
+ /** What every project entry of one stack shares — the one thing a per-stack teardown matches on. */
1226
+ const projectEntryPrefix = (baseUrl) => `${baseUrl}#`;
1227
+ const isUnderStack = (baseUrl) => (id) => id.startsWith(projectEntryPrefix(baseUrl));
1228
+ const anonymousAuth = () => ({ status: "anonymous" });
1229
+ const restoringAuth = () => ({ status: "restoring" });
1230
+ const authenticatedAuth = (credential) => ({
1231
+ status: "authenticated",
1232
+ credential
1233
+ });
1234
+ const bearerCredential = (input) => input.type === "static" ? input : {
1235
+ ...input,
1236
+ issuedAt: Date.now()
1237
+ };
1238
+ const expiredCredential = (credential) => ({
1239
+ ...credential,
1240
+ issuedAt: Date.now() - credential.expiresIn * 1e3
1241
+ });
1242
+ const stack = (baseUrl) => ({
1243
+ baseUrl,
1244
+ context: "idle",
1245
+ epoch: 0,
1246
+ auth: anonymousAuth()
1247
+ });
1248
+ const project = (baseUrl, projectId) => ({
1249
+ id: projectEntryId(baseUrl, projectId),
1250
+ baseUrl,
1251
+ projectId,
1252
+ context: "idle"
1253
+ });
1254
+ const stackAddress = (baseUrl) => ({
1255
+ baseUrl,
1256
+ projectId: null
1257
+ });
1258
+ const projectAddress = (baseUrl, projectId) => ({
1259
+ baseUrl,
1260
+ projectId
1261
+ });
1262
+ const table = (defaultBaseUrl) => ({
1263
+ active: stackAddress(defaultBaseUrl),
1264
+ stacks: { [defaultBaseUrl]: stack(defaultBaseUrl) },
1265
+ projects: {}
1266
+ });
1267
+ const Entry = {
1268
+ projectEntryId,
1269
+ isUnderStack,
1270
+ stack,
1271
+ project,
1272
+ stackAddress,
1273
+ projectAddress,
1274
+ table,
1275
+ anonymousAuth,
1276
+ restoringAuth,
1277
+ authenticatedAuth,
1278
+ bearerCredential,
1279
+ expiredCredential
1280
+ };
1281
+ /**
1282
+ * Every failure the table can produce.
1283
+ *
1284
+ * - The typed ones carry a `KeboolaErrorType` a consumer branches on; the rest are plain `Error`s
1285
+ * whose message names the entry, because nothing branches on them.
1286
+ */
1287
+ const Errors = {
1288
+ notAuthenticated: () => new KeboolaError(KeboolaErrorType.NotAuthenticated),
1289
+ stackActive: () => new KeboolaError(KeboolaErrorType.StackActive),
1290
+ /** A stack that was never opened — nothing has been configured for it. */
1291
+ unconfigured: () => new KeboolaError(KeboolaErrorType.Unconfigured),
1292
+ alreadyAuthenticated: () => new KeboolaError(KeboolaErrorType.AlreadyAuthenticated),
1293
+ notReady: () => new KeboolaError(KeboolaErrorType.NotReady),
1294
+ alreadyRestoring: (baseUrl) => /* @__PURE__ */ new Error(`Stack "${baseUrl}" is already being restored`),
1295
+ notRestoring: (baseUrl) => /* @__PURE__ */ new Error(`Stack "${baseUrl}" is not being restored`),
1296
+ unexpectedCredentialKind: (baseUrl, kind) => /* @__PURE__ */ new Error(`Stack "${baseUrl}" holds a ${kind} credential`),
1297
+ notRotatingCredential: (baseUrl) => /* @__PURE__ */ new Error(`Stack "${baseUrl}" holds a static credential`),
1298
+ credentialKindChanged: (from, to) => /* @__PURE__ */ new Error(`A ${from} credential cannot become ${to}`),
1299
+ missingProject: (id) => /* @__PURE__ */ new Error(`No project "${id}"`)
1300
+ };
1301
+ const authenticated = (auth) => auth.status === "authenticated" ? require_jobStatus.Result.success(auth.credential) : require_jobStatus.Result.failure(Errors.notAuthenticated());
1302
+ //#endregion
1303
+ //#region src/keboola/bearer/state/auth.ts
1304
+ /**
1305
+ * Fire-once per sign-in: the first report of a dead credential returns `true`, the rest `false`,
1306
+ * and `authenticate` re-arms it. Held beside the table because it is not state anyone restores.
1307
+ */
1308
+ const createExpiryLatch = () => {
1309
+ const notified = /* @__PURE__ */ new Map();
1310
+ return {
1311
+ arm: (baseUrl) => notified.set(baseUrl, false),
1312
+ forget: (baseUrl) => notified.delete(baseUrl),
1313
+ report: (baseUrl) => {
1314
+ if (notified.get(baseUrl)) return false;
1315
+ notified.set(baseUrl, true);
1316
+ return true;
1317
+ }
1318
+ };
1319
+ };
1320
+ /**
1321
+ * The stack's credential and its sign-in pin.
1322
+ *
1323
+ * - `epoch` moves on `authenticate` and `signOut` and never on a rotation, so it is exactly "which
1324
+ * sign-in is this" — what an in-flight exchange compares itself against.
1325
+ */
1326
+ const createAuth = ({ stacks, projects, expiry }) => {
1327
+ const requireUnauthenticated = (baseUrl) => require_jobStatus.Result.andThen(stacks.get(baseUrl), (stack) => stack.auth.status === "authenticated" ? require_jobStatus.Result.failure(Errors.alreadyAuthenticated()) : require_jobStatus.Result.success(stack));
1328
+ const requireAnonymous = (baseUrl) => require_jobStatus.Result.andThen(requireUnauthenticated(baseUrl), (stack) => stack.auth.status === "restoring" ? require_jobStatus.Result.failure(Errors.alreadyRestoring(baseUrl)) : require_jobStatus.Result.success(stack));
1329
+ const requireRestoring = (baseUrl) => require_jobStatus.Result.andThen(stacks.get(baseUrl), (stack) => stack.auth.status === "restoring" ? require_jobStatus.Result.success(stack) : require_jobStatus.Result.failure(Errors.notRestoring(baseUrl)));
1330
+ const requireRotatingCredential = (baseUrl) => require_jobStatus.Result.andThen(stacks.requireCredential(baseUrl), (credential) => credential.type === "static" ? require_jobStatus.Result.failure(Errors.notRotatingCredential(baseUrl)) : require_jobStatus.Result.success(credential));
1331
+ const requireCredentialOf = (baseUrl, mode) => require_jobStatus.Result.andThen(requireRotatingCredential(baseUrl), (credential) => credential.type === mode ? require_jobStatus.Result.success(credential) : require_jobStatus.Result.failure(Errors.unexpectedCredentialKind(baseUrl, credential.type)));
1332
+ const startRestore = (baseUrl) => require_jobStatus.Result.map(requireAnonymous(baseUrl), (stack) => stacks.set({
1333
+ ...stack,
1334
+ auth: Entry.restoringAuth()
1335
+ }));
1336
+ const cancelRestore = (baseUrl) => require_jobStatus.Result.map(requireRestoring(baseUrl), (stack) => stacks.set({
1337
+ ...stack,
1338
+ auth: Entry.anonymousAuth()
1339
+ }));
1340
+ const authenticate = (baseUrl, input) => require_jobStatus.Result.map(requireUnauthenticated(baseUrl), (stack) => {
1341
+ expiry.arm(baseUrl);
1342
+ return stacks.set({
1343
+ ...stack,
1344
+ epoch: stack.epoch + 1,
1345
+ auth: Entry.authenticatedAuth(Entry.bearerCredential(input))
1346
+ });
1347
+ });
1348
+ const applyRefresh = (baseUrl, input) => require_jobStatus.Result.andThen(requireRotatingCredential(baseUrl), (credential) => credential.type !== input.type ? require_jobStatus.Result.failure(Errors.credentialKindChanged(credential.type, input.type)) : require_jobStatus.Result.map(stacks.get(baseUrl), (stack) => stacks.set({
1349
+ ...stack,
1350
+ auth: Entry.authenticatedAuth(Entry.bearerCredential(input))
1351
+ })));
1352
+ const forceExpire = (baseUrl) => require_jobStatus.Result.andThen(requireRotatingCredential(baseUrl), (credential) => require_jobStatus.Result.map(stacks.get(baseUrl), (stack) => stacks.set({
1353
+ ...stack,
1354
+ auth: Entry.authenticatedAuth(Entry.expiredCredential(credential))
1355
+ })));
1356
+ const signOut = (baseUrl) => require_jobStatus.Result.map(stacks.get(baseUrl), (stack) => {
1357
+ projects.closeAll(baseUrl);
1358
+ return stacks.set({
1359
+ ...stack,
1360
+ epoch: stack.epoch + 1,
1361
+ auth: Entry.anonymousAuth()
1362
+ });
1363
+ });
1364
+ const getEpoch = (baseUrl) => require_jobStatus.Result.map(stacks.get(baseUrl), (stack) => stack.epoch);
1365
+ const getAccessToken = (baseUrl) => require_jobStatus.Result.unwrapOr(require_jobStatus.Result.map(stacks.requireCredential(baseUrl), ({ accessToken }) => accessToken), null);
1366
+ return {
1367
+ startRestore,
1368
+ cancelRestore,
1369
+ authenticate,
1370
+ applyRefresh,
1371
+ forceExpire,
1372
+ signOut,
1373
+ notifyExpired: expiry.report,
1374
+ requireCredential: stacks.requireCredential,
1375
+ requireRotatingCredential,
1376
+ requireCredentialOf,
1377
+ getEpoch,
1378
+ getAccessToken
1379
+ };
1380
+ };
1381
+ //#endregion
1382
+ //#region src/keboola/bearer/state/projects.ts
1383
+ /** The projects open under a stack, and what authorizes a request to one. */
1384
+ const createProjects = ({ store, stacks }) => {
1385
+ const has = (id) => id in store.get().projects;
1386
+ const get = (id) => {
1387
+ const project = store.get().projects[id];
1388
+ return project ? require_jobStatus.Result.success(project) : require_jobStatus.Result.failure(Errors.missingProject(id));
1389
+ };
1390
+ const list = (baseUrl) => Object.values(store.get().projects).filter((project) => project.baseUrl === baseUrl);
1391
+ /** Every open project with this id, whatever stack it sits on — a project number is not unique. */
1392
+ const findAll = (projectId) => Object.values(store.get().projects).filter((project) => project.projectId === projectId);
1393
+ const set = (project) => {
1394
+ const state = store.get();
1395
+ store.set({
1396
+ ...state,
1397
+ projects: {
1398
+ ...state.projects,
1399
+ [project.id]: project
1400
+ }
1401
+ });
1402
+ return project;
1403
+ };
1404
+ const update = (id, updater) => require_jobStatus.Result.map(get(id), (project) => set(updater(project)));
1405
+ const removeMany = (ids, nextActive) => {
1406
+ const state = store.get();
1407
+ const projects = { ...state.projects };
1408
+ for (const id of ids) delete projects[id];
1409
+ store.set({
1410
+ ...state,
1411
+ active: nextActive,
1412
+ projects
1413
+ });
1414
+ };
1415
+ const requireCredential = (id) => require_jobStatus.Result.andThen(get(id), (project) => stacks.requireCredential(project.baseUrl));
1416
+ const open = (baseUrl, projectId) => {
1417
+ const id = Entry.projectEntryId(baseUrl, projectId);
1418
+ if (has(id)) return get(id);
1419
+ return require_jobStatus.Result.map(stacks.requireCredential(baseUrl), () => set(Entry.project(baseUrl, projectId)));
1420
+ };
1421
+ const close = (id) => require_jobStatus.Result.tap(get(id), ({ baseUrl, projectId }) => {
1422
+ const { active } = store.get();
1423
+ const isScoped = active.baseUrl === baseUrl && active.projectId === projectId;
1424
+ removeMany([id], isScoped ? Entry.stackAddress(baseUrl) : active);
1425
+ });
1426
+ /** Every project under a stack, with the scope falling back to the stack itself. */
1427
+ const closeAll = (baseUrl) => {
1428
+ const ids = list(baseUrl).map((project) => project.id);
1429
+ const { active } = store.get();
1430
+ removeMany(ids, active.baseUrl === baseUrl ? Entry.stackAddress(baseUrl) : active);
1431
+ };
1432
+ const updateContext = (id, context) => update(id, (project) => ({
1433
+ ...project,
1434
+ context
1435
+ }));
1436
+ return {
1437
+ has,
1438
+ get,
1439
+ list,
1440
+ findAll,
1441
+ set,
1442
+ update,
1443
+ open,
1444
+ close,
1445
+ closeAll,
1446
+ updateContext,
1447
+ requireCredential
1448
+ };
1449
+ };
1450
+ //#endregion
1451
+ //#region src/keboola/bearer/state/scope.ts
1452
+ /**
1453
+ * What `api.*` addresses: the `active` slot, and the address in it resolved against the tables it
1454
+ * points into.
1455
+ *
1456
+ * The tables never write here — they read `active` through the pure helpers in `address.ts`, so
1457
+ * that this can depend on them rather than the other way round.
1458
+ */
1459
+ const createScope = ({ store, stacks, projects }) => {
1460
+ const get = () => store.get().active;
1461
+ const isSame = (a, b) => a === b || a.baseUrl === b.baseUrl && a.projectId === b.projectId;
1462
+ const set = (active) => {
1463
+ if (isSame(store.get().active, active)) return;
1464
+ store.set({
1465
+ ...store.get(),
1466
+ active
1467
+ });
1468
+ };
1469
+ const locate = (active) => {
1470
+ const stack = stacks.get(active.baseUrl);
1471
+ if (!stack.success) return null;
1472
+ if (active.projectId === null) return {
1473
+ stack: stack.data,
1474
+ project: null
1475
+ };
1476
+ const project = projects.get(Entry.projectEntryId(active.baseUrl, active.projectId));
1477
+ if (!project.success) return null;
1478
+ return {
1479
+ stack: stack.data,
1480
+ project: project.data
1481
+ };
1482
+ };
1483
+ const getActive = () => {
1484
+ const location = locate(get());
1485
+ if (!location) throw new Error(`The scope names no row: ${JSON.stringify(get())}`);
1486
+ return location;
1487
+ };
1488
+ const getActiveStack = () => getActive().stack;
1489
+ const activateStack = (baseUrl) => require_jobStatus.Result.map(stacks.get(baseUrl), (stack) => {
1490
+ const next = Entry.stackAddress(stack.baseUrl);
1491
+ set(next);
1492
+ return next;
1493
+ });
1494
+ const activateProject = (baseUrl, projectId) => require_jobStatus.Result.map(projects.requireCredential(Entry.projectEntryId(baseUrl, projectId)), () => {
1495
+ const next = Entry.projectAddress(baseUrl, projectId);
1496
+ set(next);
1497
+ return next;
1498
+ });
1499
+ const selectStack = (baseUrl) => {
1500
+ const stack = stacks.ensure(baseUrl);
1501
+ return require_jobStatus.Result.map(activateStack(stack.baseUrl), () => stack);
1502
+ };
1503
+ const selectProject = (projectId) => {
1504
+ const { baseUrl } = getActiveStack();
1505
+ const project = projects.open(baseUrl, projectId);
1506
+ if (!project.success) return project;
1507
+ return require_jobStatus.Result.map(activateProject(baseUrl, projectId), () => project.data);
1508
+ };
1509
+ const deactivate = () => {
1510
+ const active = get();
1511
+ if (active.projectId === null) return;
1512
+ set(Entry.stackAddress(active.baseUrl));
1513
+ };
1514
+ const requireActiveProject = () => {
1515
+ const { project } = getActive();
1516
+ return project ? require_jobStatus.Result.success(project) : require_jobStatus.Result.failure(Errors.notReady());
1517
+ };
1518
+ return {
1519
+ get,
1520
+ getActive,
1521
+ activateStack,
1522
+ activateProject,
1523
+ selectStack,
1524
+ selectProject,
1525
+ deactivate,
1526
+ getActiveStack,
1527
+ requireActiveProject
1528
+ };
1529
+ };
1530
+ //#endregion
1531
+ //#region src/keboola/bearer/state/stacks.ts
1532
+ /** One entry per stack: the entries, and the verbs that open and close them. */
1533
+ const createStacks = ({ store, forgetExpiry }) => {
1534
+ const has = (baseUrl) => baseUrl in store.get().stacks;
1535
+ const get = (baseUrl) => {
1536
+ const stack = store.get().stacks[baseUrl];
1537
+ return stack ? require_jobStatus.Result.success(stack) : require_jobStatus.Result.failure(Errors.unconfigured());
1538
+ };
1539
+ const list = () => Object.values(store.get().stacks);
1540
+ const set = (stack) => {
1541
+ const state = store.get();
1542
+ store.set({
1543
+ ...state,
1544
+ stacks: {
1545
+ ...state.stacks,
1546
+ [stack.baseUrl]: stack
1547
+ }
1548
+ });
1549
+ return stack;
1550
+ };
1551
+ const update = (baseUrl, updater) => require_jobStatus.Result.map(get(baseUrl), (stack) => set(updater(stack)));
1552
+ const requireCredential = (baseUrl) => require_jobStatus.Result.andThen(get(baseUrl), (stack) => authenticated(stack.auth));
1553
+ const ensure = (baseUrl) => {
1554
+ const existing = get(baseUrl);
1555
+ if (existing.success) return existing.data;
1556
+ return set(Entry.stack(baseUrl));
1557
+ };
1558
+ const close = (baseUrl) => {
1559
+ const stack = get(baseUrl);
1560
+ if (!stack.success) return stack;
1561
+ const state = store.get();
1562
+ if (state.active.baseUrl === baseUrl) return require_jobStatus.Result.failure(Errors.stackActive());
1563
+ const stacks = { ...state.stacks };
1564
+ delete stacks[baseUrl];
1565
+ const projects = Object.fromEntries(Object.entries(state.projects).filter(([, project]) => project.baseUrl !== baseUrl));
1566
+ store.set({
1567
+ active: state.active,
1568
+ stacks,
1569
+ projects
1570
+ });
1571
+ forgetExpiry(baseUrl);
1572
+ return stack;
1573
+ };
1574
+ const updateContext = (baseUrl, context) => update(baseUrl, (stack) => ({
1575
+ ...stack,
1576
+ context
1577
+ }));
1578
+ return {
1579
+ has,
1580
+ get,
1581
+ list,
1582
+ set,
1583
+ update,
1584
+ ensure,
1585
+ close,
1586
+ updateContext,
1587
+ requireCredential
1588
+ };
1589
+ };
1590
+ //#endregion
1591
+ //#region src/keboola/bearer/state/state.ts
1592
+ /**
1593
+ * The stack table and the rules over it, one namespace per concern.
1594
+ *
1595
+ * - Built in dependency order: a project reads its stack's credential, and the scope resolves
1596
+ * the active address against both tables.
1597
+ */
1598
+ const createState = (defaultBaseUrl) => {
1599
+ const store = require_store.createStore(Entry.table(defaultBaseUrl));
1600
+ const expiry = createExpiryLatch();
1601
+ const stacks = createStacks({
1602
+ store,
1603
+ forgetExpiry: expiry.forget
1604
+ });
1605
+ const projects = createProjects({
1606
+ store,
1607
+ stacks
1608
+ });
1609
+ const scope = createScope({
1610
+ store,
1611
+ stacks,
1612
+ projects
1613
+ });
1614
+ const auth = createAuth({
1615
+ stacks,
1616
+ projects,
1617
+ expiry
1618
+ });
1619
+ return {
1620
+ store: store.asReadable(),
1621
+ stacks,
1622
+ projects,
1623
+ auth,
1624
+ scope
1625
+ };
1626
+ };
1627
+ //#endregion
1628
+ //#region src/keboola/bearer/context/resource.ts
1629
+ /**
1630
+ * Owns fetching one async value per key — a caller names what it needs and never orchestrates the
1631
+ * request. Backs the stack and project contexts.
1632
+ *
1633
+ * - One fetch per key: concurrent askers share it, a landed value is never refetched.
1634
+ * - A failure is held, not thrown away — nothing here needs a rejection handler.
1635
+ * - Status lives here and nowhere else; a consumer that has to mirror it subscribes.
1636
+ */
1637
+ const createResource = ({ key, fetch }) => {
1638
+ const entries = /* @__PURE__ */ new Map();
1639
+ const changes = require_store.createEmitter();
1640
+ const set = (id, entry) => {
1641
+ entries.set(id, entry);
1642
+ changes.emit({
1643
+ key: id,
1644
+ status: entry.status
1645
+ });
1646
+ };
1647
+ const run = (id, input) => {
1648
+ const settle = (next) => {
1649
+ if (entries.get(id) === entry) set(id, {
1650
+ input,
1651
+ ...next
1652
+ });
1653
+ return next;
1654
+ };
1655
+ const attempt = async () => await fetch(input);
1656
+ const entry = {
1657
+ input,
1658
+ status: "pending",
1659
+ settled: attempt().then((value) => settle({
1660
+ status: "ready",
1661
+ value
1662
+ }), (error) => settle({
1663
+ status: "errored",
1664
+ error
1665
+ }))
1666
+ };
1667
+ set(id, entry);
1668
+ return entry;
1669
+ };
1670
+ const get = (id) => {
1671
+ const entry = entries.get(id);
1672
+ return entry?.status === "ready" ? entry.value : null;
1673
+ };
1674
+ const getAsync = async (input) => {
1675
+ const id = key(input);
1676
+ const cached = entries.get(id);
1677
+ const entry = cached === void 0 || cached.status === "errored" ? run(id, input) : cached;
1678
+ const settled = entry.status === "pending" ? await entry.settled : entry;
1679
+ if (settled.status === "errored") throw settled.error;
1680
+ return settled.value;
1681
+ };
1682
+ const forget = (matches) => {
1683
+ for (const id of entries.keys()) if (matches(id)) entries.delete(id);
1684
+ };
1685
+ const prefetch = (input) => {
1686
+ const id = key(input);
1687
+ if (!entries.has(id)) run(id, input);
1688
+ };
1689
+ const retry = (id) => {
1690
+ const entry = entries.get(id);
1691
+ if (entry !== void 0) run(id, entry.input);
1692
+ };
1693
+ return {
1694
+ get,
1695
+ getAsync,
1696
+ prefetch,
1697
+ retry,
1698
+ forget,
1699
+ subscribe: changes.subscribe
1700
+ };
1701
+ };
1702
+ //#endregion
1703
+ //#region src/keboola/bearer/context/project.ts
1704
+ const createProjectContext = ({ state, credentials, stackContext }) => {
1705
+ const resource = createResource({
1706
+ key: (project) => project.id,
1707
+ fetch: async ({ baseUrl, projectId }) => {
1708
+ const withProjectId = (next) => (request) => {
1709
+ request.request.headers.set(require_createFetchClient.KeboolaHttpHeader.PROJECT_ID, String(projectId));
1710
+ return next(request);
1711
+ };
1712
+ const client = require_storage.createStorageClient({
1713
+ baseUrl,
1714
+ auth: {
1715
+ type: "bearer",
1716
+ token: "",
1717
+ projectId
1718
+ },
1719
+ middlewares: [(next) => withProjectId(credentials.middleware(baseUrl)(next))]
1720
+ });
1721
+ const [token, devBranches] = await Promise.all([
1722
+ client.tokens.verify(),
1723
+ client.branches.getDevBranches(),
1724
+ stackContext.getAsync(baseUrl)
1725
+ ]);
1726
+ return {
1727
+ token,
1728
+ defaultBranch: createDefaultBranch({ devBranches })
1729
+ };
1730
+ }
1731
+ });
1732
+ resource.subscribe(({ key, status }) => {
1733
+ state.projects.updateContext(key, status);
1734
+ });
1735
+ const subscriber = ({ projects }) => {
1736
+ for (const project of Object.values(projects)) resource.prefetch(project);
1737
+ };
1738
+ /**
1739
+ * Dropped with the sign-in that fetched them: a verified token is what a credential answered
1740
+ * for, so it belongs to that credential and not to the project id it was keyed by.
1741
+ */
1742
+ const forgetUnder = (baseUrl) => resource.forget(Entry.isUnderStack(baseUrl));
1743
+ /** One project, closed on purpose. */
1744
+ const forget = (id) => resource.forget((key) => key === id);
1745
+ return {
1746
+ subscriber,
1747
+ get: resource.get,
1748
+ getAsync: resource.getAsync,
1749
+ retry: resource.retry,
1750
+ forget,
1751
+ forgetUnder
1752
+ };
1753
+ };
1754
+ //#endregion
1755
+ //#region src/keboola/bearer/context/stack.ts
1756
+ const createStackContext = (state) => {
1757
+ const resource = createResource({
1758
+ key: (baseUrl) => baseUrl,
1759
+ fetch: (baseUrl) => require_storage.createStorageClient({
1760
+ baseUrl,
1761
+ auth: {
1762
+ type: "sapi-token",
1763
+ token: ""
1764
+ }
1765
+ }).getStackInfo({ exclude: "componentDetails" })
1766
+ });
1767
+ resource.subscribe(({ key, status }) => {
1768
+ state.stacks.updateContext(key, status);
1769
+ });
1770
+ const subscriber = ({ stacks }) => {
1771
+ for (const { baseUrl } of Object.values(stacks)) resource.prefetch(baseUrl);
1772
+ };
1773
+ /** Dropped with the stack itself — a stack that comes back re-reads its index. */
1774
+ const forget = (baseUrl) => resource.forget((key) => key === baseUrl);
1775
+ return {
1776
+ subscriber,
1777
+ get: resource.get,
1778
+ getAsync: resource.getAsync,
1779
+ retry: resource.retry,
1780
+ forget
1781
+ };
1782
+ };
1783
+ //#endregion
1784
+ //#region src/keboola/bearer/perProject.ts
1785
+ const once = (build) => {
1786
+ let value = null;
1787
+ return () => value ??= build();
1788
+ };
1789
+ /**
1790
+ * Everything one project derives, and the one call that drops it.
1791
+ *
1792
+ * Every field belongs to the credential that built it — a client set carries its middleware chain,
1793
+ * the storage client holds a `liveProject` seeded with its token, a fetched context *is* what it
1794
+ * answered for `tokens.verify` — so the record dies with the sign-in, and `forgetUnder` is the
1795
+ * only thing that ends one.
1796
+ */
1797
+ const createPerProject = ({ state, credentials, middlewareFor, stack, clientServiceUrls, buildApi }) => {
1798
+ const context = createProjectContext({
1799
+ state,
1800
+ credentials,
1801
+ stackContext: stack.context
1802
+ });
1803
+ const attachFor = ({ baseUrl, projectId }) => {
1804
+ const withProjectId = (next) => (request) => {
1805
+ request.request.headers.set(require_createFetchClient.KeboolaHttpHeader.PROJECT_ID, String(projectId));
1806
+ return next(request);
1807
+ };
1808
+ return (next) => withProjectId(credentials.middleware(baseUrl)(next));
1809
+ };
1810
+ const buildClients = ({ baseUrl, projectId }, attach) => createServiceClients({
1811
+ baseUrl,
1812
+ auth: {
1813
+ type: "bearer",
1814
+ token: "",
1815
+ projectId
1816
+ },
1817
+ getServiceBaseUrl: (serviceId) => async () => {
1818
+ const stackInfo = await stack.context.getAsync(baseUrl);
1819
+ const serviceUrl = createStack({
1820
+ stackInfo,
1821
+ clientServiceUrls
1822
+ }).getServiceUrl(serviceId);
1823
+ assert$1(serviceUrl, KeboolaErrorType.NotReady);
1824
+ return serviceUrl;
1825
+ },
1826
+ middlewareFor,
1827
+ attachTokenMiddleware: attach
1828
+ });
1829
+ /**
1830
+ * `api.storage` and `api.context`, built together: both read one live token — the storage client
1831
+ * carries its re-verify middleware, the context reports the project it re-verifies.
1832
+ *
1833
+ * - Both fetches it reads are already running. `NotReady` covers the window before they land,
1834
+ * which the table reports as `project.context`.
1835
+ * - `storage` is gated on the stack index too, though it addresses the project's own `baseUrl`
1836
+ * and does not need it — that is the gate as it stands, not a requirement.
1837
+ */
1838
+ const buildLive = (project, attach) => {
1839
+ const stackInfo = stack.context.get(project.baseUrl);
1840
+ assert$1(stackInfo, KeboolaErrorType.NotReady);
1841
+ const fetched = context.get(project.id);
1842
+ assert$1(fetched, KeboolaErrorType.NotReady);
1843
+ const { baseUrl, projectId } = project;
1844
+ const auth = {
1845
+ type: "bearer",
1846
+ token: "",
1847
+ projectId
1848
+ };
1849
+ const reader = require_storage.createStorageClient({
1850
+ baseUrl,
1851
+ auth,
1852
+ middlewares: [attach]
1853
+ });
1854
+ const liveProject = createLiveProject({
1855
+ initialToken: fetched.token,
1856
+ verify: () => reader.tokens.verify()
1857
+ });
1858
+ const storageTableStore = createDerivedStore({
1859
+ source: liveProject.store,
1860
+ build: require_storageTable.createStorageTable,
1861
+ dependsOn: (live) => ({
1862
+ useLegacyBucketPrefix: !live.hasFeature(require_constants.ProjectFeature.DisableLegacyBucketPrefix),
1863
+ hasProtectedDefaultBranch: live.hasFeature(require_constants.ProjectFeature.SoxProtectedDefaultBranch),
1864
+ hasStorageBranches: live.hasFeature(require_constants.ProjectFeature.StorageBranches)
1865
+ })
1866
+ });
1867
+ return {
1868
+ storage: require_storage.createStorageClient({
1869
+ baseUrl,
1870
+ auth,
1871
+ middlewares: middlewareFor("storage", [attach, liveProject.middleware])
1872
+ }),
1873
+ context: {
1874
+ baseUrl,
1875
+ stack: createStack({
1876
+ stackInfo,
1877
+ clientServiceUrls
1878
+ }),
1879
+ defaultBranch: fetched.defaultBranch,
1880
+ get project() {
1881
+ return liveProject.getProject();
1882
+ },
1883
+ get st() {
1884
+ return storageTableStore.get();
1885
+ }
1886
+ }
1887
+ };
1888
+ };
1889
+ const build = (project) => {
1890
+ const attach = attachFor(project);
1891
+ const live = once(() => buildLive(project, attach));
1892
+ const clients = once(() => buildClients(project, attach));
1893
+ return {
1894
+ api: buildApi(project),
1895
+ get clients() {
1896
+ return clients();
1897
+ },
1898
+ get storage() {
1899
+ return live().storage;
1900
+ },
1901
+ get context() {
1902
+ return live().context;
1903
+ }
1904
+ };
1905
+ };
1906
+ const derived = /* @__PURE__ */ new Map();
1907
+ const get = (project) => ensure(derived, project.id, () => build(project));
1908
+ /** One project, closed on purpose — a handle for it stops answering from the next read. */
1909
+ const forget = (id) => {
1910
+ derived.delete(id);
1911
+ context.forget(id);
1912
+ };
1913
+ const forgetUnder = (baseUrl) => {
1914
+ const isUnder = Entry.isUnderStack(baseUrl);
1915
+ for (const id of derived.keys()) if (isUnder(id)) derived.delete(id);
1916
+ context.forgetUnder(baseUrl);
1917
+ };
1918
+ return {
1919
+ context,
1920
+ get,
1921
+ forget,
1922
+ forgetUnder
1923
+ };
1924
+ };
1925
+ //#endregion
1926
+ //#region src/keboola/bearer/persistor.ts
1927
+ /**
1928
+ * Where a bearer session is persisted, under whichever adapter the client was given.
1929
+ *
1930
+ * Exported because a consumer sometimes has to drop a session a client cannot reach: the adapter is
1931
+ * chosen at construction, so a client built without one holds no handle to the storage its own
1932
+ * session is sitting in. `AppAuthStrategy` in kbc-ui is that case.
1933
+ */
1934
+ const SESSION_STORAGE_KEY = "keboola:session";
1935
+ /**
1936
+ * What survives a reload, per credential kind.
1937
+ *
1938
+ * - `token`: the refresh token. It rotates, is single-use and is server-revocable, so a leaked
1939
+ * snapshot has limited and revocable value. The access token is never written.
1940
+ * - `static`: the token itself — a long-lived PAT the user pasted, which nothing can re-mint.
1941
+ * - `cookie`: the session id. The session cookie is the durable half and the browser keeps it;
1942
+ * the id alone renews nothing.
1943
+ */
1944
+ const persistedCredentialSchema = zod.discriminatedUnion("type", [
1945
+ zod.object({
1946
+ type: zod.literal("token"),
1947
+ refreshToken: zod.string()
1948
+ }),
1949
+ zod.object({
1950
+ type: zod.literal("cookie"),
1951
+ sessionId: zod.string()
1952
+ }),
1953
+ zod.object({
1954
+ type: zod.literal("static"),
1955
+ accessToken: zod.string()
1956
+ })
1957
+ ]);
1958
+ /** A record per project rather than a bare id, so a project can grow a field without a migration. */
1959
+ const persistedProjectSchema = zod.object({ projectId: zod.number() });
1960
+ const persistedSessionSchema = zod.object({
1961
+ current: zod.object({
1962
+ baseUrl: zod.string(),
1963
+ projectId: zod.number().nullable()
1964
+ }).nullable(),
1965
+ stacks: zod.array(zod.object({
1966
+ baseUrl: zod.string(),
1967
+ credential: persistedCredentialSchema.nullable(),
1968
+ projects: zod.array(persistedProjectSchema)
1969
+ }))
1970
+ });
1971
+ const EMPTY_PERSISTED_SESSION = {
1972
+ current: null,
1973
+ stacks: []
1974
+ };
1975
+ const durableCredential = (stack) => {
1976
+ if (stack.auth.status !== "authenticated") return null;
1977
+ const { credential } = stack.auth;
1978
+ if (credential.type === "token") return {
1979
+ type: "token",
1980
+ refreshToken: credential.refreshToken
1981
+ };
1982
+ if (credential.type === "cookie") return {
1983
+ type: "cookie",
1984
+ sessionId: credential.sessionId
1985
+ };
1986
+ return {
1987
+ type: "static",
1988
+ accessToken: credential.accessToken
1989
+ };
1990
+ };
1991
+ const createSessionPersistor = (storage) => {
1992
+ const persistor = createPersistor({
1993
+ storage,
1994
+ key: SESSION_STORAGE_KEY,
1995
+ schema: persistedSessionSchema,
1996
+ defaultValue: EMPTY_PERSISTED_SESSION
1997
+ });
1998
+ const persist = ({ active, stacks, projects }) => persistor.persist({
1999
+ current: {
2000
+ baseUrl: active.baseUrl,
2001
+ projectId: active.projectId
2002
+ },
2003
+ stacks: Object.values(stacks).map((stack) => ({
2004
+ baseUrl: stack.baseUrl,
2005
+ credential: durableCredential(stack),
2006
+ projects: Object.values(projects).filter((project) => project.baseUrl === stack.baseUrl).map(({ projectId }) => ({ projectId }))
2007
+ }))
2008
+ });
2009
+ return {
2010
+ ...persistor,
2011
+ persist
2012
+ };
2013
+ };
2014
+ //#endregion
2015
+ //#region src/keboola/bearer/perStack.ts
2016
+ /**
2017
+ * Everything one stack derives, and the one call that drops it.
2018
+ *
2019
+ * Outlives a sign-out, unlike anything in `perProject`: both clients read the credential live per
2020
+ * request, so neither belongs to one sign-in, and the stack index is public.
2021
+ */
2022
+ const createPerStack = ({ state, credentials, middlewareFor }) => {
2023
+ const context = createStackContext(state);
2024
+ const derived = /* @__PURE__ */ new Map();
2025
+ const get = (baseUrl) => ensure(derived, baseUrl, () => ({
2026
+ auth: require_authClient.createAuthClient({
2027
+ baseUrl,
2028
+ middlewares: middlewareFor("auth", [credentials.middleware(baseUrl)])
2029
+ }),
2030
+ management: require_management.createManagementClient({
2031
+ baseUrl,
2032
+ auth: {
2033
+ type: "bearer",
2034
+ token: ""
2035
+ },
2036
+ middlewares: middlewareFor("management", [credentials.middleware(baseUrl)])
2037
+ })
2038
+ }));
2039
+ const forget = (baseUrl) => {
2040
+ derived.delete(baseUrl);
2041
+ context.forget(baseUrl);
2042
+ };
2043
+ return {
2044
+ context,
2045
+ get,
2046
+ forget
2047
+ };
2048
+ };
2049
+ //#endregion
2050
+ //#region src/keboola/bearer/keboola.ts
2051
+ /**
2052
+ * The bearer client: the session table, its two scopes, and the surface they back.
2053
+ *
2054
+ * - Credential-derived state is owned by the scope whose end ends it (`perStack`, `perProject`).
2055
+ */
2056
+ const createKeboola = ({ defaultBaseUrl, storage, middlewares, clientServiceUrls, credentials: mode = "token" }) => {
2057
+ const state = createState(require_createFetchClient.normalizeBaseUrl(defaultBaseUrl));
2058
+ const persistor = createSessionPersistor(storage);
2059
+ const middlewareFor = createMiddlewareFor(middlewares);
2060
+ const credentials = createCredentials({
2061
+ state,
2062
+ persistor,
2063
+ middlewares: middlewareFor("auth"),
2064
+ mode,
2065
+ onSignedOut: (baseUrl) => perProject.forgetUnder(baseUrl)
2066
+ });
2067
+ const perStack = createPerStack({
2068
+ state,
2069
+ credentials,
2070
+ middlewareFor
2071
+ });
2072
+ const perProject = createPerProject({
2073
+ state,
2074
+ credentials,
2075
+ middlewareFor,
2076
+ stack: perStack,
2077
+ clientServiceUrls,
2078
+ buildApi: (project) => createApiFor({
2079
+ stackUrl: () => project.baseUrl,
2080
+ project: () => require_jobStatus.Result.unwrap(state.projects.get(project.id)),
2081
+ pinned: true
2082
+ })
2083
+ });
2084
+ state.store.subscribe(perStack.context.subscriber);
2085
+ perStack.context.subscriber(state.store.get());
2086
+ state.store.subscribe(perProject.context.subscriber);
2087
+ const selectStack = (baseUrl) => require_jobStatus.Result.unwrap(state.scope.selectStack(require_createFetchClient.normalizeBaseUrl(baseUrl)));
2088
+ const selectProject = (projectId) => require_jobStatus.Result.unwrap(state.scope.selectProject(projectId));
2089
+ /** The scoped stack, or a named one — normalised to key like `select`. */
2090
+ const requireStackUrl = (baseUrl) => baseUrl === void 0 ? state.scope.getActiveStack().baseUrl : require_createFetchClient.normalizeBaseUrl(baseUrl);
2091
+ /** The scoped project, or the row a table id names — on whichever stack that is. */
2092
+ const requireProjectEntry = (id) => id === void 0 ? require_jobStatus.Result.unwrap(state.scope.requireActiveProject()) : require_jobStatus.Result.unwrap(state.projects.get(id));
2093
+ /**
2094
+ * The scoped project, or a named open one.
2095
+ *
2096
+ * - An id is ambiguous across stacks: the active stack decides, else the single one open elsewhere.
2097
+ */
2098
+ const requireProject = (projectId) => {
2099
+ if (projectId === void 0) return require_jobStatus.Result.unwrap(state.scope.requireActiveProject());
2100
+ const scoped = state.projects.get(Entry.projectEntryId(requireStackUrl(), projectId));
2101
+ if (scoped.success) return scoped.data;
2102
+ const [only, ...rest] = state.projects.findAll(projectId);
2103
+ return only !== void 0 && rest.length === 0 ? only : require_jobStatus.Result.unwrap(scoped);
2104
+ };
2105
+ /**
2106
+ * Auth headers for a non-fetch transport (the chat stream).
2107
+ *
2108
+ * - A read, not a rotation: no middleware recovers a 401 there; the fetch clients keep it fresh.
2109
+ */
2110
+ const getAuthHeaders = (projectId) => {
2111
+ const project = requireProject(projectId);
2112
+ const credential = require_jobStatus.Result.unwrap(state.auth.requireCredential(project.baseUrl));
2113
+ return {
2114
+ [require_createFetchClient.HttpHeader.AUTHORIZATION]: `Bearer ${credential.accessToken}`,
2115
+ [require_createFetchClient.KeboolaHttpHeader.PROJECT_ID]: String(project.projectId)
2116
+ };
2117
+ };
2118
+ const authenticate = (input) => {
2119
+ const stack = state.scope.getActiveStack();
2120
+ if (input.type !== "static" && input.type !== mode) throw new KeboolaError(KeboolaErrorType.CredentialKindMismatch);
2121
+ if (input.type !== "token") return require_jobStatus.Result.unwrap(state.auth.authenticate(stack.baseUrl, input));
2122
+ const { refreshToken } = input;
2123
+ if (!refreshToken) throw new KeboolaError(KeboolaErrorType.NotAuthenticated);
2124
+ return require_jobStatus.Result.unwrap(state.auth.authenticate(stack.baseUrl, {
2125
+ ...input,
2126
+ refreshToken
2127
+ }));
2128
+ };
2129
+ /**
2130
+ * The flat product surface: `auth` and `management` per stack, the rest per project.
2131
+ *
2132
+ * - Both resolvers run per property read: that re-points the active handle and makes a pinned
2133
+ * one throw once its project is gone.
2134
+ */
2135
+ const createApiFor = (resolve) => new Proxy({}, { get: (_target, property) => {
2136
+ if (isBuiltInProperty(property)) return void 0;
2137
+ if (property === "auth" || property === "management") {
2138
+ if (resolve.pinned) resolve.project();
2139
+ return perStack.get(resolve.stackUrl())[property];
2140
+ }
2141
+ const derived = perProject.get(resolve.project());
2142
+ if (property === "context") return derived.context;
2143
+ if (property === "storage") return derived.storage;
2144
+ const { client, meta } = derived.clients;
2145
+ if (property === "serviceMeta") return meta;
2146
+ return client[property];
2147
+ } });
2148
+ const activeApi = createApiFor({
2149
+ stackUrl: () => state.scope.getActiveStack().baseUrl,
2150
+ project: () => require_jobStatus.Result.unwrap(state.scope.requireActiveProject())
2151
+ });
2152
+ /** The scoped project's surface. Re-points when the scope moves. */
2153
+ const getActiveApi = () => activeApi;
2154
+ /**
2155
+ * One project's surface, on the active stack — one credential serves all of them.
2156
+ *
2157
+ * - Pinned: never re-points; stops once the project closes (`session.project.close`, sign-out).
2158
+ * - Memoised per project: a React `key` or a hook dep compares handles by identity.
2159
+ */
2160
+ const getApi = (projectId) => {
2161
+ const { baseUrl } = state.scope.getActiveStack();
2162
+ const project = Entry.project(baseUrl, projectId);
2163
+ require_jobStatus.Result.unwrapOr(state.projects.open(baseUrl, projectId), null);
2164
+ return perProject.get(project).api;
2165
+ };
2166
+ /** The scope's sign-in, or a named stack's — and everything that sign-in derived. */
2167
+ const signOut = (baseUrl) => {
2168
+ const target = requireStackUrl(baseUrl);
2169
+ return require_jobStatus.Result.unwrap(credentials.signOut(target));
2170
+ };
2171
+ /**
2172
+ * `input` replaces the active stack's sign-in, whatever it holds.
2173
+ *
2174
+ * - Signs out first, always: a sign-out moves the epoch even on an anonymous stack, so a stored
2175
+ * session still being restored cannot land on top of this one.
2176
+ */
2177
+ const replace = (input) => {
2178
+ signOut();
2179
+ return authenticate(input);
2180
+ };
2181
+ /**
2182
+ * A server-injected `token` credential, adopted whatever this client's mode.
2183
+ *
2184
+ * @deprecated Temporary, for the agent-project claim page only: Connection injects an API-mode
2185
+ * session through `UiConfig.programmaticAuth`. Remove together with that injection.
2186
+ *
2187
+ * - Replaces the active stack's sign-in, like `replace`.
2188
+ * - A cookie-mode client never rotates it, so it lasts as long as its access token.
2189
+ */
2190
+ const adoptInjected = (input) => {
2191
+ signOut();
2192
+ return require_jobStatus.Result.unwrap(state.auth.authenticate(getActiveStack().baseUrl, input));
2193
+ };
2194
+ /**
2195
+ * Leave one project: its row and everything built for it; its handles stop answering.
2196
+ *
2197
+ * - Counterpart of `getApi(projectId)`; without it the project is held and persisted until sign-out.
2198
+ */
2199
+ const closeProject = (projectId) => {
2200
+ const id = Entry.projectEntryId(requireStackUrl(), projectId);
2201
+ const closed = require_jobStatus.Result.unwrapOr(state.projects.close(id), null);
2202
+ if (closed === null) return null;
2203
+ perProject.forget(id);
2204
+ return closed;
2205
+ };
2206
+ const closeStack = (baseUrl) => {
2207
+ const target = require_createFetchClient.normalizeBaseUrl(baseUrl);
2208
+ if (state.scope.get().baseUrl === target) throw new KeboolaError(KeboolaErrorType.StackActive);
2209
+ const closed = require_jobStatus.Result.unwrapOr(state.stacks.close(target), null);
2210
+ if (closed === null) return null;
2211
+ perProject.forgetUnder(target);
2212
+ perStack.forget(target);
2213
+ credentials.forget(target);
2214
+ return closed;
2215
+ };
2216
+ let persisting = false;
2217
+ /**
2218
+ * Persistence starts only once the restore has settled.
2219
+ *
2220
+ * - Mid-hydration an unexchanged stack is `anonymous`; `durableCredential` would erase the
2221
+ * refresh token the exchange is about to spend.
2222
+ * - Writes the settled table once: the subscription fires only on the next change.
2223
+ */
2224
+ const enablePersistence = () => {
2225
+ if (persisting) return;
2226
+ persisting = true;
2227
+ persistor.persist(state.store.get());
2228
+ state.store.subscribe(persistor.persist);
2229
+ };
2230
+ /**
2231
+ * The same, deferred until a sign-in.
2232
+ *
2233
+ * - After an unreachable restore the table is anonymous but the stored token is still good;
2234
+ * writing earlier would drop it.
2235
+ */
2236
+ const enablePersistenceOnSignIn = () => {
2237
+ const stop = state.store.subscribe((next) => {
2238
+ if (!Object.values(next.stacks).some(({ auth }) => auth.status === "authenticated")) return;
2239
+ stop();
2240
+ enablePersistence();
2241
+ });
2242
+ };
2243
+ const restore = require_jobStatus.lazy(() => credentials.restore().then((restored) => {
2244
+ if (restored.status === "unreachable") enablePersistenceOnSignIn();
2245
+ else enablePersistence();
2246
+ return restored;
2247
+ }, (error) => {
2248
+ enablePersistenceOnSignIn();
2249
+ throw error;
2250
+ }));
2251
+ const getActiveStack = state.scope.getActiveStack;
2252
+ const isAuthenticated = () => getActiveStack().auth.status === "authenticated";
2253
+ /**
2254
+ * Picks up where the stored session left off, once.
2255
+ *
2256
+ * 1. A stored stack becomes active again, with its project if its credential came back.
2257
+ * 2. Nothing stored, or the restore failed: `defaultBaseUrl` stays active; a failure rethrows.
2258
+ * 3. The caller got there first (a select, sign-in or sign-out): its scope and sign-ins stand.
2259
+ *
2260
+ * - Resolves with the stored credential's fate — only this tells `expired` from `empty`.
2261
+ * - Other stacks still come back, persistence still starts; repeat calls share one promise.
2262
+ */
2263
+ const resume = require_jobStatus.lazy(() => restore().then(({ lastActive, status }) => {
2264
+ if (!lastActive || callerScoped) return status;
2265
+ const stack = selectStack(lastActive.baseUrl);
2266
+ if (lastActive.projectId !== null && stack.auth.status === "authenticated") selectProject(lastActive.projectId);
2267
+ return status;
2268
+ }));
2269
+ let callerScoped = false;
2270
+ const byCaller = (verb) => (...args) => {
2271
+ callerScoped = true;
2272
+ return verb(...args);
2273
+ };
2274
+ return {
2275
+ getActiveApi,
2276
+ getApi,
2277
+ session: {
2278
+ getState: state.store.get,
2279
+ subscribe: state.store.subscribe,
2280
+ resume,
2281
+ stack: {
2282
+ getActive: getActiveStack,
2283
+ select: byCaller(selectStack),
2284
+ close: closeStack,
2285
+ retryContext: perStack.context.retry,
2286
+ getContext: (baseUrl) => perStack.context.get(requireStackUrl(baseUrl)),
2287
+ getContextAsync: (baseUrl) => perStack.context.getAsync(requireStackUrl(baseUrl))
2288
+ },
2289
+ project: {
2290
+ select: byCaller(selectProject),
2291
+ close: closeProject,
2292
+ deactivate: state.scope.deactivate,
2293
+ retryContext: perProject.context.retry,
2294
+ getContext: (id) => perProject.context.get(id ?? requireProjectEntry().id),
2295
+ getContextAsync: (id) => perProject.context.getAsync(requireProjectEntry(id))
2296
+ },
2297
+ auth: {
2298
+ authenticate: byCaller(authenticate),
2299
+ replace: byCaller(replace),
2300
+ adoptInjected: byCaller(adoptInjected),
2301
+ signOut: byCaller(signOut),
2302
+ /** Whether the active stack holds a credential — `restoring` is not one yet. */
2303
+ isAuthenticated,
2304
+ isAuthenticatedAsync: () => resume().then(isAuthenticated),
2305
+ rotate: (baseUrl) => credentials.rotate(baseUrl).then(require_jobStatus.Result.unwrap),
2306
+ getHeaders: getAuthHeaders
2307
+ }
2308
+ }
2309
+ };
2310
+ };
2311
+ //#endregion
2312
+ //#region src/middlewares/loggingMiddleware.ts
2313
+ const CORRELATION_ID_HEADER = "X-Correlation-ID";
2314
+ const ALWAYS_REDACTED_HEADERS = [
2315
+ require_createFetchClient.KeboolaHttpHeader.MANAGEMENT_API_TOKEN,
2316
+ require_createFetchClient.KeboolaHttpHeader.STORAGE_API_TOKEN,
2317
+ "authorization",
2318
+ "cookie",
2319
+ "set-cookie"
2320
+ ];
2321
+ const ALWAYS_REDACTED_QUERY_PARAMS = /* @__PURE__ */ new Set([
2322
+ "token",
2323
+ "apikey",
2324
+ "api_key",
2325
+ "access_token",
2326
+ "refresh_token",
2327
+ "code",
2328
+ "state",
2329
+ "signature",
2330
+ "sig",
2331
+ "x-amz-signature",
2332
+ "x-amz-credential",
2333
+ "x-amz-security-token",
2334
+ "password",
2335
+ "secret"
2336
+ ]);
2337
+ const REDACTED = "[REDACTED]";
2338
+ const getRedactedUrl = (rawUrl) => {
2339
+ const url = new URL(rawUrl);
2340
+ if (url.username) url.username = REDACTED;
2341
+ if (url.password) url.password = REDACTED;
2342
+ url.searchParams.forEach((_value, key) => {
2343
+ if (ALWAYS_REDACTED_QUERY_PARAMS.has(key.toLowerCase())) url.searchParams.set(key, REDACTED);
2344
+ });
2345
+ return url.toString();
2346
+ };
2347
+ const ensureCorrelationId = (request) => {
2348
+ const correlationId = request.headers.get(CORRELATION_ID_HEADER) ?? require_generateUUID.generateUUID();
2349
+ request.headers.set(CORRELATION_ID_HEADER, correlationId);
2350
+ return correlationId;
2351
+ };
2352
+ const getRedactedHeaders = (headers, redacted) => {
2353
+ const redactedSet = new Set([...ALWAYS_REDACTED_HEADERS, ...redacted].map((h) => h.toLowerCase()));
2354
+ const result = {};
2355
+ headers.forEach((value, name) => {
2356
+ result[name] = redactedSet.has(name.toLowerCase()) ? REDACTED : value;
2357
+ });
2358
+ return result;
2359
+ };
2360
+ const getRequestLog = (request, redactedHeaders) => ({
2361
+ url: getRedactedUrl(request.url),
2362
+ headers: getRedactedHeaders(request.headers, redactedHeaders)
2363
+ });
2364
+ const getResponseLog = (response, redactedHeaders) => ({
2365
+ status: response.status,
2366
+ statusText: response.statusText,
2367
+ headers: getRedactedHeaders(response.headers, redactedHeaders)
2368
+ });
2369
+ const redactApiError = (error, redactedHeaders) => new require_createFetchClient.ApiError({
2370
+ request: new Request(getRedactedUrl(error.request.url), {
2371
+ method: error.request.method,
2372
+ headers: getRedactedHeaders(error.request.headers, redactedHeaders)
2373
+ }),
2374
+ response: new Response(null, {
2375
+ status: error.response.status,
2376
+ statusText: error.response.statusText,
2377
+ headers: getRedactedHeaders(error.response.headers, redactedHeaders)
2378
+ }),
2379
+ data: error.data
2380
+ });
2381
+ const formatLog = (level, log) => {
2382
+ const parts = [
2383
+ `[${level.toUpperCase()}]`,
2384
+ `${Math.round(log.durationMs)}ms`,
2385
+ log.method
2386
+ ];
2387
+ parts.push(log.request.url);
2388
+ if ("response" in log) parts.push(String(log.response.status));
2389
+ return parts.join(" ");
2390
+ };
2391
+ const createSafeLogger = (logger, level = "error-only") => {
2392
+ return {
2393
+ info: (log) => {
2394
+ if (level !== "all") return;
2395
+ try {
2396
+ if (logger?.info) {
2397
+ logger.info(log);
2398
+ return;
2399
+ }
2400
+ console.info(formatLog("info", log));
2401
+ } catch {}
2402
+ },
2403
+ error: (log) => {
2404
+ try {
2405
+ if (logger?.error) {
2406
+ logger.error(log);
2407
+ return;
2408
+ }
2409
+ console.error(formatLog("error", log));
2410
+ } catch {}
2411
+ }
2412
+ };
2413
+ };
2414
+ const createLoggingMiddleware = (options = {}) => {
2415
+ const safeLogger = createSafeLogger(options.logger, options.level);
2416
+ const redactHeaders = options.redactHeaders ?? [];
2417
+ return (next) => async (fetchRequest) => {
2418
+ const correlationId = ensureCorrelationId(fetchRequest.request);
2419
+ const start = performance.now();
2420
+ const method = fetchRequest.request.method.toLowerCase();
2421
+ const requestLog = getRequestLog(fetchRequest.request, redactHeaders);
2422
+ try {
2423
+ const result = await next(fetchRequest);
2424
+ safeLogger.info({
2425
+ correlationId,
2426
+ method,
2427
+ durationMs: performance.now() - start,
2428
+ request: requestLog,
2429
+ response: getResponseLog(result.response, redactHeaders)
2430
+ });
2431
+ return result;
2432
+ } catch (error) {
2433
+ if (error instanceof Error) safeLogger.error({
2434
+ correlationId,
2435
+ method,
2436
+ durationMs: performance.now() - start,
2437
+ request: requestLog,
2438
+ error: require_createFetchClient.isApiError(error) ? redactApiError(error, redactHeaders) : error
2439
+ });
2440
+ throw error;
2441
+ }
2442
+ };
2443
+ };
2444
+ //#endregion
2445
+ //#region src/middlewares/retryMiddleware.ts
2446
+ const DEFAULT_MAX_RETRIES = 5;
2447
+ const DEFAULT_RETRYABLE_STATUSES = [
2448
+ require_createFetchClient.HttpStatus.INTERNAL_SERVER_ERROR,
2449
+ require_createFetchClient.HttpStatus.BAD_GATEWAY,
2450
+ require_createFetchClient.HttpStatus.SERVICE_UNAVAILABLE,
2451
+ require_createFetchClient.HttpStatus.GATEWAY_TIMEOUT
2452
+ ];
2453
+ const DEFAULT_BACKOFF_FACTOR = .3;
2454
+ const defaultShouldRetry = (error) => error instanceof require_createFetchClient.ApiError && DEFAULT_RETRYABLE_STATUSES.includes(error.response.status);
2455
+ const createRetryMiddleware = (options) => {
2456
+ const { maxRetries = DEFAULT_MAX_RETRIES, backoffFactor = DEFAULT_BACKOFF_FACTOR, shouldRetry = defaultShouldRetry } = options ?? {};
2457
+ if (!Number.isInteger(maxRetries) || maxRetries < 0) throw new RangeError("maxRetries must be a non-negative integer");
2458
+ if (!Number.isFinite(backoffFactor) || backoffFactor < 0) throw new RangeError("backoffFactor must be a finite non-negative number");
2459
+ return (next) => async (request) => {
2460
+ for (let attempt = 0; attempt <= maxRetries; attempt++) try {
2461
+ return await next({
2462
+ ...request,
2463
+ request: request.request.clone()
2464
+ });
2465
+ } catch (error) {
2466
+ if (attempt === maxRetries || !shouldRetry(error, attempt)) throw error;
2467
+ const delayMs = backoffFactor * 1e3 * Math.pow(2, attempt);
2468
+ await require_jobStatus.delay(delayMs, request.request.signal ?? void 0);
2469
+ }
2470
+ throw new Error("unreachable");
2471
+ };
2472
+ };
2473
+ //#endregion
1869
2474
  exports.ApiError = require_createFetchClient.ApiError;
1870
2475
  exports.HtmlResponseError = require_validateConnectionStatus.HtmlResponseError;
1871
2476
  exports.HttpContentType = require_createFetchClient.HttpContentType;
@@ -1877,6 +2482,7 @@ exports.ManagementClientAuthError = require_ManagementClientAuthError.Management
1877
2482
  exports.QueryJobError = require_QueryJobTimeoutError.QueryJobError;
1878
2483
  exports.QueryJobTimeoutError = require_QueryJobTimeoutError.QueryJobTimeoutError;
1879
2484
  exports.Result = require_jobStatus.Result;
2485
+ exports.SESSION_STORAGE_KEY = SESSION_STORAGE_KEY;
1880
2486
  exports.ServiceUnavailableError = require_storage.ServiceUnavailableError;
1881
2487
  exports.SyncActionError = require_SyncActionError.SyncActionError;
1882
2488
  exports.UserError = require_UserError.UserError;
@@ -1907,6 +2513,7 @@ exports.dedupe = require_dedupe.dedupe;
1907
2513
  exports.deepMerge = deepMerge;
1908
2514
  exports.delay = require_jobStatus.delay;
1909
2515
  exports.emitter = require_jobStatus.emitter;
2516
+ exports.ensure = ensure;
1910
2517
  exports.failureOf = require_jobStatus.failureOf;
1911
2518
  exports.formatValidationIssues = require_ValidationError.formatValidationIssues;
1912
2519
  exports.generateUUID = require_generateUUID.generateUUID;
@@ -1931,6 +2538,7 @@ exports.parseLogLines = require_appLogs.parseLogLines;
1931
2538
  exports.parseOrThrow = require_ValidationError.parseOrThrow;
1932
2539
  exports.poll = require_jobStatus.poll;
1933
2540
  exports.poller = require_jobStatus.poller;
2541
+ exports.readableReason = require_storage.readableReason;
1934
2542
  exports.schemaGuidedMerge = require_configurations.schemaGuidedMerge;
1935
2543
  exports.series = require_storage.series;
1936
2544
  exports.shallowEqual = shallowEqual;