@burdenoff/be-sdk 2026.1110.2 → 2026.1110.3
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.
- package/configs/eslint/index.js +1 -1
- package/configs/tsconfig/tsconfig.json +1 -1
- package/dist/EventQueueFactory-9NGZV9jl.js +1457 -0
- package/dist/EventQueueFactory-9NGZV9jl.js.map +1 -0
- package/dist/RedisStreamsConnection-CY8WySJy.js +283 -0
- package/dist/RedisStreamsConnection-CY8WySJy.js.map +1 -0
- package/dist/ai-credits/index.d.ts +2 -3
- package/dist/ai-credits/index.js +3 -4
- package/dist/ai-credits/index.js.map +1 -1
- package/dist/ai-credits-Ca-NNcVx.js +546 -0
- package/dist/ai-credits-Ca-NNcVx.js.map +1 -0
- package/dist/{assistant-session-CJZhF4D6.d.ts → assistant-session-DA5ZKJOr.d.ts} +4 -5
- package/dist/auth/index.d.ts +2 -77
- package/dist/auth/index.js +3 -7
- package/dist/auth/index.js.map +1 -1
- package/dist/auth-CEuBEBQN.js +228 -0
- package/dist/auth-CEuBEBQN.js.map +1 -0
- package/dist/cache/index.d.ts +2 -3
- package/dist/cache/index.js +3 -7
- package/dist/cache/index.js.map +1 -1
- package/dist/cache-CU0uLwcS.js +1837 -0
- package/dist/cache-CU0uLwcS.js.map +1 -0
- package/dist/captcha/index.d.ts +2 -1
- package/dist/captcha/index.js +3 -3
- package/dist/captcha/index.js.map +1 -1
- package/dist/captcha-BT7yh1YS.js +77 -0
- package/dist/captcha-BT7yh1YS.js.map +1 -0
- package/dist/client/internal-client.d.ts +4 -7
- package/dist/client/internal-client.js +172 -4
- package/dist/client/internal-client.js.map +1 -1
- package/dist/client-BgAEvDC2.d.ts +86 -0
- package/dist/client-DcZ3iGES.js +565 -0
- package/dist/client-DcZ3iGES.js.map +1 -0
- package/dist/collector-endpoint-iyQYeI50.js +50 -0
- package/dist/collector-endpoint-iyQYeI50.js.map +1 -0
- package/dist/context-CZnXf2yb.js +247 -0
- package/dist/context-CZnXf2yb.js.map +1 -0
- package/dist/crypto/index.d.ts +2 -1
- package/dist/crypto/index.js +3 -3
- package/dist/crypto/index.js.map +1 -1
- package/dist/crypto-DO9fM0FO.js +145 -0
- package/dist/crypto-DO9fM0FO.js.map +1 -0
- package/dist/database/index.d.ts +104 -108
- package/dist/database/index.js +468 -6
- package/dist/database/index.js.map +1 -1
- package/dist/dataloader/index.d.ts +2 -1
- package/dist/dataloader/index.js +3 -3
- package/dist/dataloader/index.js.map +1 -1
- package/dist/dataloader-DwpT3YoS.js +294 -0
- package/dist/dataloader-DwpT3YoS.js.map +1 -0
- package/dist/deployed-environment-p_Tdl3sT.js +38 -0
- package/dist/deployed-environment-p_Tdl3sT.js.map +1 -0
- package/dist/dist-BGKdXVy3.js +1718 -0
- package/dist/dist-BGKdXVy3.js.map +1 -0
- package/dist/env-DdaoGjIt.js +74 -0
- package/dist/env-DdaoGjIt.js.map +1 -0
- package/dist/event-queue/index.d.ts +2 -7
- package/dist/event-queue/index.js +7 -9
- package/dist/event-queue/index.js.map +1 -1
- package/dist/event-queue-Cw-YJPY_.js +1384 -0
- package/dist/event-queue-Cw-YJPY_.js.map +1 -0
- package/dist/{explicit-activity-scope-CCoxVwAr.d.ts → explicit-activity-scope-D8VeGGpt.d.ts} +1 -2
- package/dist/export/index.d.ts +2 -2
- package/dist/export/index.js +3 -14
- package/dist/export/index.js.map +1 -1
- package/dist/export-B6fphx8a.js +642 -0
- package/dist/export-B6fphx8a.js.map +1 -0
- package/dist/feature-flags/index.d.ts +2 -10
- package/dist/feature-flags/index.js +3 -6
- package/dist/feature-flags/index.js.map +1 -1
- package/dist/feature-flags-71oDkrUe.js +422 -0
- package/dist/feature-flags-71oDkrUe.js.map +1 -0
- package/dist/files/index.d.ts +2 -3
- package/dist/files/index.js +3 -4
- package/dist/files/index.js.map +1 -1
- package/dist/files-DjH0099H.js +830 -0
- package/dist/files-DjH0099H.js.map +1 -0
- package/dist/gateway/index.d.ts +4 -6
- package/dist/gateway/index.js +7 -13
- package/dist/gateway/index.js.map +1 -1
- package/dist/gateway/security/index.d.ts +2 -2
- package/dist/gateway/security/index.js +3 -5
- package/dist/gateway/security/index.js.map +1 -1
- package/dist/gateway-DBFmxWks.js +50 -0
- package/dist/gateway-DBFmxWks.js.map +1 -0
- package/dist/graph/index.d.ts +3 -10
- package/dist/graph/index.js +4 -13
- package/dist/graph/index.js.map +1 -1
- package/dist/graph-DDYgIryR.js +2152 -0
- package/dist/graph-DDYgIryR.js.map +1 -0
- package/dist/graph-emitter-CdOXP7Tn.js +621 -0
- package/dist/graph-emitter-CdOXP7Tn.js.map +1 -0
- package/dist/graphql/index.d.ts +3 -2
- package/dist/graphql/index.js +4 -6
- package/dist/graphql/index.js.map +1 -1
- package/dist/graphql/services/index.d.ts +2 -24
- package/dist/graphql/services/index.js +3 -4
- package/dist/graphql/services/index.js.map +1 -1
- package/dist/graphql-DHAHHcww.js +161 -0
- package/dist/graphql-DHAHHcww.js.map +1 -0
- package/dist/graphql-DNkMkGBZ.d.ts +21 -0
- package/dist/i18n/index.d.ts +3 -3
- package/dist/i18n/index.js +3 -4
- package/dist/i18n/index.js.map +1 -1
- package/dist/i18n-BBMYFd0P.js +860 -0
- package/dist/i18n-BBMYFd0P.js.map +1 -0
- package/dist/import-optional-peer-B82VYxeX.js +18 -0
- package/dist/import-optional-peer-B82VYxeX.js.map +1 -0
- package/dist/index-3KOZ1zN9.d.ts +233 -0
- package/dist/index-BBqooJ52.d.ts +45 -0
- package/dist/index-BGzMYJsm.d.ts +209 -0
- package/dist/index-BKwHQtHQ.d.ts +63 -0
- package/dist/index-BMIMnp6T.d.ts +8 -0
- package/dist/index-BQDsNAMR.d.ts +81 -0
- package/dist/index-BVOL7458.d.ts +10 -0
- package/dist/index-BcqQs-Uq.d.ts +69 -0
- package/dist/index-BeVtqGO-.d.ts +208 -0
- package/dist/index-BiTzGUZP.d.ts +114 -0
- package/dist/index-BqYfCQSP.d.ts +500 -0
- package/dist/index-C0qLquY0.d.ts +150 -0
- package/dist/index-C5uEKchX.d.ts +60 -0
- package/dist/index-CDOqxSIi.d.ts +37 -0
- package/dist/index-CG6wj66Y.d.ts +148 -0
- package/dist/index-CIgoeobA.d.ts +145 -0
- package/dist/index-CPQDMSFS.d.ts +103 -0
- package/dist/index-CSRcgkVi.d.ts +23 -0
- package/dist/index-CZTnQIRU.d.ts +341 -0
- package/dist/index-CaM9JUcc.d.ts +144 -0
- package/dist/index-CkT2aUr3.d.ts +704 -0
- package/dist/index-CliOgq6L.d.ts +203 -0
- package/dist/index-CnzbJZP7.d.ts +999 -0
- package/dist/index-D6UeLAye.d.ts +63 -0
- package/dist/index-DGgh9DWn.d.ts +59 -0
- package/dist/index-DY3dNhMN.d.ts +420 -0
- package/dist/index-DZC-2o9R.d.ts +207 -0
- package/dist/index-DqbGqfAy.d.ts +127 -0
- package/dist/index-Dt1HJPTX.d.ts +12 -0
- package/dist/index-DtI6aBtB.d.ts +22 -0
- package/dist/index-FKohsiex.d.ts +38 -0
- package/dist/index-FbXPfen7.d.ts +132 -0
- package/dist/index-MArCb8Aq.d.ts +306 -0
- package/dist/index-N-huORcj.d.ts +303 -0
- package/dist/index-YOShAwkq.d.ts +45 -0
- package/dist/index-bZKZUvBu.d.ts +646 -0
- package/dist/index-yBSjMY32.d.ts +24 -0
- package/dist/index.d.ts +501 -544
- package/dist/index.js +1820 -2171
- package/dist/index.js.map +1 -1
- package/dist/init/index.d.ts +2 -2
- package/dist/init/index.js +3 -16
- package/dist/init/index.js.map +1 -1
- package/dist/init-Dy3KhT6Y.js +325 -0
- package/dist/init-Dy3KhT6Y.js.map +1 -0
- package/dist/instrumentation/index.d.ts +3 -4
- package/dist/instrumentation/index.js +5 -5
- package/dist/instrumentation/index.js.map +1 -1
- package/dist/instrumentation-xkkmDgJ0.js +1678 -0
- package/dist/instrumentation-xkkmDgJ0.js.map +1 -0
- package/dist/lake/index.d.ts +50 -54
- package/dist/lake/index.js +169 -193
- package/dist/lake/index.js.map +1 -1
- package/dist/layer/index.d.ts +3 -2
- package/dist/layer/index.js +4 -5
- package/dist/layer/index.js.map +1 -1
- package/dist/layer-BZBZZWeV.d.ts +69 -0
- package/dist/layer-Bcix-WCl.js +105 -0
- package/dist/layer-Bcix-WCl.js.map +1 -0
- package/dist/layer-CEKy6cm8.js +252 -0
- package/dist/layer-CEKy6cm8.js.map +1 -0
- package/dist/lifecycle/index.d.ts +2 -1
- package/dist/lifecycle/index.js +3 -4
- package/dist/lifecycle/index.js.map +1 -1
- package/dist/lifecycle-DeoLSX0U.js +76 -0
- package/dist/lifecycle-DeoLSX0U.js.map +1 -0
- package/dist/logger/index.d.ts +2 -3
- package/dist/logger/index.js +3 -3
- package/dist/logger/index.js.map +1 -1
- package/dist/logger-B6rCpb7D.js +290 -0
- package/dist/logger-B6rCpb7D.js.map +1 -0
- package/dist/metrics/index.d.ts +13 -14
- package/dist/metrics/index.js +3 -4
- package/dist/metrics/index.js.map +1 -1
- package/dist/metrics-BrLwNUrb.js +52 -0
- package/dist/metrics-BrLwNUrb.js.map +1 -0
- package/dist/metrics-collector-C2eShrlW.js +922 -0
- package/dist/metrics-collector-C2eShrlW.js.map +1 -0
- package/dist/middleware/index.d.ts +3 -3
- package/dist/middleware/index.js +3 -4
- package/dist/middleware/index.js.map +1 -1
- package/dist/middleware-CUxJVUpD.js +1243 -0
- package/dist/middleware-CUxJVUpD.js.map +1 -0
- package/dist/middleware-Cq0zFMGp.js +253 -0
- package/dist/middleware-Cq0zFMGp.js.map +1 -0
- package/dist/notifications/index.d.ts +2 -5
- package/dist/notifications/index.js +3 -6
- package/dist/notifications/index.js.map +1 -1
- package/dist/notifications-CdETrtFK.js +869 -0
- package/dist/notifications-CdETrtFK.js.map +1 -0
- package/dist/observability/index.d.ts +2 -3
- package/dist/observability/index.js +3 -4
- package/dist/observability/index.js.map +1 -1
- package/dist/observability-DBDXipTU.js +272 -0
- package/dist/observability-DBDXipTU.js.map +1 -0
- package/dist/platform/index.d.ts +2 -1
- package/dist/platform/index.js +3 -5
- package/dist/platform/index.js.map +1 -1
- package/dist/platform-DZwczW7v.js +1510 -0
- package/dist/platform-DZwczW7v.js.map +1 -0
- package/dist/prisma/generator/index.d.ts +1 -1
- package/dist/prisma/generator/index.js +97 -84
- package/dist/prisma/generator/index.js.map +1 -1
- package/dist/prisma/index.d.ts +4 -7
- package/dist/prisma/index.js +5 -12
- package/dist/prisma/index.js.map +1 -1
- package/dist/prisma-BzOOdt79.js +863 -0
- package/dist/prisma-BzOOdt79.js.map +1 -0
- package/dist/prisma-extension-Cfl09swM.d.ts +172 -0
- package/dist/product-alias/index.d.ts +2 -1
- package/dist/product-alias/index.js +3 -3
- package/dist/product-alias/index.js.map +1 -1
- package/dist/product-alias-BPqtskMq.js +273 -0
- package/dist/product-alias-BPqtskMq.js.map +1 -0
- package/dist/rbac/index.d.ts +2 -122
- package/dist/rbac/index.js +3 -6
- package/dist/rbac/index.js.map +1 -1
- package/dist/rbac-BB9l9Xph.js +1486 -0
- package/dist/rbac-BB9l9Xph.js.map +1 -0
- package/dist/resource-caps/index.d.ts +66 -72
- package/dist/resource-caps/index.js +430 -5
- package/dist/resource-caps/index.js.map +1 -1
- package/dist/rolldown-runtime-ad2WFvuA.js +17 -0
- package/dist/sdk-Dju9o-sq.js +124 -0
- package/dist/sdk-Dju9o-sq.js.map +1 -0
- package/dist/security-DIG-95Ic.js +1647 -0
- package/dist/security-DIG-95Ic.js.map +1 -0
- package/dist/server/index.d.ts +7 -164
- package/dist/server/index.js +2000 -1507
- package/dist/server/index.js.map +1 -1
- package/dist/service-jwt-Bu-WNA_-.js +80 -0
- package/dist/service-jwt-Bu-WNA_-.js.map +1 -0
- package/dist/services-BWzfz7vG.js +102 -0
- package/dist/services-BWzfz7vG.js.map +1 -0
- package/dist/sharding/index.d.ts +41 -44
- package/dist/sharding/index.js +156 -137
- package/dist/sharding/index.js.map +1 -1
- package/dist/sharing/index.d.ts +2 -1
- package/dist/sharing/index.js +3 -4
- package/dist/sharing/index.js.map +1 -1
- package/dist/sharing-CflDsSJ-.js +911 -0
- package/dist/sharing-CflDsSJ-.js.map +1 -0
- package/dist/stub-BqwKn4eh.js +630 -0
- package/dist/stub-BqwKn4eh.js.map +1 -0
- package/dist/tags/index.d.ts +2 -3
- package/dist/tags/index.js +3 -4
- package/dist/tags/index.js.map +1 -1
- package/dist/tags-B5xpbgsk.js +868 -0
- package/dist/{chunk-PBZFAAOM.js.map → tags-B5xpbgsk.js.map} +1 -1
- package/dist/telemetry/index.d.ts +64 -76
- package/dist/telemetry/index.js +369 -201
- package/dist/telemetry/index.js.map +1 -1
- package/dist/temporal/index.d.ts +2 -148
- package/dist/temporal/index.js +3 -5
- package/dist/temporal/index.js.map +1 -1
- package/dist/temporal-B534uYK8.js +706 -0
- package/dist/temporal-B534uYK8.js.map +1 -0
- package/dist/tracker/index.d.ts +5 -11
- package/dist/tracker/index.js +5 -20
- package/dist/tracker/index.js.map +1 -1
- package/dist/tracker-BQVoEFUo.js +839 -0
- package/dist/tracker-BQVoEFUo.js.map +1 -0
- package/dist/types-BYMYND1L.js +44 -0
- package/dist/types-BYMYND1L.js.map +1 -0
- package/dist/types-C6EKaS3V.d.ts +106 -0
- package/dist/types-CWybW61E.d.ts +323 -0
- package/dist/types-C_yfu3XK.d.ts +34 -0
- package/dist/types-Cj2RWXbz.js +90 -0
- package/dist/types-Cj2RWXbz.js.map +1 -0
- package/dist/types-DgaQqvxo.d.ts +70 -0
- package/dist/usage/index.d.ts +2 -213
- package/dist/usage/index.js +3 -15
- package/dist/usage/index.js.map +1 -1
- package/dist/usage-BKFZiWQn.js +682 -0
- package/dist/usage-BKFZiWQn.js.map +1 -0
- package/dist/utils/index.d.ts +2 -1
- package/dist/utils/index.js +3 -3
- package/dist/utils/index.js.map +1 -1
- package/dist/utils-DL85Tnbn.js +500 -0
- package/dist/utils-DL85Tnbn.js.map +1 -0
- package/dist/validation/index.d.ts +2 -2
- package/dist/validation/index.js +3 -3
- package/dist/validation/index.js.map +1 -1
- package/dist/validation-CPUITdMk.js +762 -0
- package/dist/validation-CPUITdMk.js.map +1 -0
- package/dist/workspace-extension-COrC0dYi.js +979 -0
- package/dist/workspace-extension-COrC0dYi.js.map +1 -0
- package/dist/{workspace-extension-BGwTOV_r.d.ts → workspace-extension-DTFTdGVF.d.ts} +43 -45
- package/package.json +7 -10
- package/dist/EventQueueFactory-GXC3A7DH.js +0 -8
- package/dist/EventQueueFactory-GXC3A7DH.js.map +0 -1
- package/dist/chunk-4XIBXZ6J.js +0 -276
- package/dist/chunk-4XIBXZ6J.js.map +0 -1
- package/dist/chunk-554Z4C2K.js +0 -1006
- package/dist/chunk-554Z4C2K.js.map +0 -1
- package/dist/chunk-5CAFHK2Z.js +0 -107
- package/dist/chunk-5CAFHK2Z.js.map +0 -1
- package/dist/chunk-63ZXJ42X.js +0 -451
- package/dist/chunk-63ZXJ42X.js.map +0 -1
- package/dist/chunk-6XEXJATV.js +0 -304
- package/dist/chunk-6XEXJATV.js.map +0 -1
- package/dist/chunk-726AR6Q7.js +0 -1532
- package/dist/chunk-726AR6Q7.js.map +0 -1
- package/dist/chunk-A5F6Z5UE.js +0 -21
- package/dist/chunk-A5F6Z5UE.js.map +0 -1
- package/dist/chunk-A6DE32ZS.js +0 -1507
- package/dist/chunk-A6DE32ZS.js.map +0 -1
- package/dist/chunk-AXJDGQPE.js +0 -690
- package/dist/chunk-AXJDGQPE.js.map +0 -1
- package/dist/chunk-BJQOGOVW.js +0 -602
- package/dist/chunk-BJQOGOVW.js.map +0 -1
- package/dist/chunk-CFXWH2IS.js +0 -52
- package/dist/chunk-CFXWH2IS.js.map +0 -1
- package/dist/chunk-DRWH5XCJ.js +0 -876
- package/dist/chunk-DRWH5XCJ.js.map +0 -1
- package/dist/chunk-E4QNLVY4.js +0 -909
- package/dist/chunk-E4QNLVY4.js.map +0 -1
- package/dist/chunk-EBDHIL7V.js +0 -774
- package/dist/chunk-EBDHIL7V.js.map +0 -1
- package/dist/chunk-ELU7VL3E.js +0 -245
- package/dist/chunk-ELU7VL3E.js.map +0 -1
- package/dist/chunk-FZRODKIN.js +0 -31
- package/dist/chunk-FZRODKIN.js.map +0 -1
- package/dist/chunk-GCIB76AJ.js +0 -882
- package/dist/chunk-GCIB76AJ.js.map +0 -1
- package/dist/chunk-HC6MPUIH.js +0 -1571
- package/dist/chunk-HC6MPUIH.js.map +0 -1
- package/dist/chunk-HNMHPSAM.js +0 -272
- package/dist/chunk-HNMHPSAM.js.map +0 -1
- package/dist/chunk-HTLEGD3Q.js +0 -1480
- package/dist/chunk-HTLEGD3Q.js.map +0 -1
- package/dist/chunk-I3KOWRT3.js +0 -89
- package/dist/chunk-I3KOWRT3.js.map +0 -1
- package/dist/chunk-ID3WR4JS.js +0 -509
- package/dist/chunk-ID3WR4JS.js.map +0 -1
- package/dist/chunk-JS52ZHTK.js +0 -1346
- package/dist/chunk-JS52ZHTK.js.map +0 -1
- package/dist/chunk-JVMAQOA3.js +0 -521
- package/dist/chunk-JVMAQOA3.js.map +0 -1
- package/dist/chunk-KH4TRQCO.js +0 -1063
- package/dist/chunk-KH4TRQCO.js.map +0 -1
- package/dist/chunk-KJOSPVB2.js +0 -57
- package/dist/chunk-KJOSPVB2.js.map +0 -1
- package/dist/chunk-KO2ZXZ7W.js +0 -61
- package/dist/chunk-KO2ZXZ7W.js.map +0 -1
- package/dist/chunk-KS2HQCJR.js +0 -56
- package/dist/chunk-KS2HQCJR.js.map +0 -1
- package/dist/chunk-LA5KPWZ2.js +0 -413
- package/dist/chunk-LA5KPWZ2.js.map +0 -1
- package/dist/chunk-MESLAC5W.js +0 -574
- package/dist/chunk-MESLAC5W.js.map +0 -1
- package/dist/chunk-MWPYA2HD.js +0 -94
- package/dist/chunk-MWPYA2HD.js.map +0 -1
- package/dist/chunk-NUB5GQTU.js +0 -270
- package/dist/chunk-NUB5GQTU.js.map +0 -1
- package/dist/chunk-OBBCR6WY.js +0 -277
- package/dist/chunk-OBBCR6WY.js.map +0 -1
- package/dist/chunk-OQDSAOG3.js +0 -1908
- package/dist/chunk-OQDSAOG3.js.map +0 -1
- package/dist/chunk-OXNCBE7P.js +0 -971
- package/dist/chunk-OXNCBE7P.js.map +0 -1
- package/dist/chunk-PBZFAAOM.js +0 -941
- package/dist/chunk-PN6GIF3R.js +0 -1185
- package/dist/chunk-PN6GIF3R.js.map +0 -1
- package/dist/chunk-PYD44IHJ.js +0 -728
- package/dist/chunk-PYD44IHJ.js.map +0 -1
- package/dist/chunk-QVPIACWD.js +0 -679
- package/dist/chunk-QVPIACWD.js.map +0 -1
- package/dist/chunk-QWNNFE4P.js +0 -41
- package/dist/chunk-QWNNFE4P.js.map +0 -1
- package/dist/chunk-RU266375.js +0 -327
- package/dist/chunk-RU266375.js.map +0 -1
- package/dist/chunk-RYTSVGGA.js +0 -1624
- package/dist/chunk-RYTSVGGA.js.map +0 -1
- package/dist/chunk-RZOFS2BQ.js +0 -225
- package/dist/chunk-RZOFS2BQ.js.map +0 -1
- package/dist/chunk-SBS4S2PJ.js +0 -100
- package/dist/chunk-SBS4S2PJ.js.map +0 -1
- package/dist/chunk-SPRG6G6G.js +0 -530
- package/dist/chunk-SPRG6G6G.js.map +0 -1
- package/dist/chunk-STWFX5E2.js +0 -233
- package/dist/chunk-STWFX5E2.js.map +0 -1
- package/dist/chunk-UNASM5VJ.js +0 -419
- package/dist/chunk-UNASM5VJ.js.map +0 -1
- package/dist/chunk-VAT66FJA.js +0 -245
- package/dist/chunk-VAT66FJA.js.map +0 -1
- package/dist/chunk-VFCMR5GX.js +0 -49
- package/dist/chunk-VFCMR5GX.js.map +0 -1
- package/dist/chunk-VGAHZKNJ.js +0 -66
- package/dist/chunk-VGAHZKNJ.js.map +0 -1
- package/dist/chunk-VTJTAAXC.js +0 -627
- package/dist/chunk-VTJTAAXC.js.map +0 -1
- package/dist/chunk-VXVLKRU6.js +0 -758
- package/dist/chunk-VXVLKRU6.js.map +0 -1
- package/dist/chunk-WWUU5ETI.js +0 -163
- package/dist/chunk-WWUU5ETI.js.map +0 -1
- package/dist/chunk-XE4OXN2W.js +0 -10
- package/dist/chunk-XE4OXN2W.js.map +0 -1
- package/dist/chunk-XOJORS75.js +0 -1853
- package/dist/chunk-XOJORS75.js.map +0 -1
- package/dist/chunk-YMZEUTD2.js +0 -110
- package/dist/chunk-YMZEUTD2.js.map +0 -1
- package/dist/chunk-Z77BTSOK.js +0 -617
- package/dist/chunk-Z77BTSOK.js.map +0 -1
- package/dist/chunk-ZZK3WEDI.js +0 -181
- package/dist/chunk-ZZK3WEDI.js.map +0 -1
- package/dist/client-CCXpAZ2r.d.ts +0 -89
- package/dist/client-DSI_760t.d.ts +0 -36
- package/dist/client-JU6T3UPB.js +0 -11
- package/dist/client-JU6T3UPB.js.map +0 -1
- package/dist/dist-2X4Q7PJA.js +0 -1491
- package/dist/dist-2X4Q7PJA.js.map +0 -1
- package/dist/env-4UWSUS64.js +0 -4
- package/dist/env-4UWSUS64.js.map +0 -1
- package/dist/graph-emitter-r5TylDBm.d.ts +0 -47
- package/dist/graphql-CMHMQjvd.d.ts +0 -23
- package/dist/i18n-Qm2AkPC-.d.ts +0 -33
- package/dist/index--yvpa6ay.d.ts +0 -83
- package/dist/index-4gKQKZ2B.d.ts +0 -71
- package/dist/index-5x0XMKXN.d.ts +0 -149
- package/dist/index-B70b5mYS.d.ts +0 -33
- package/dist/index-B8KrxO4j.d.ts +0 -755
- package/dist/index-BOuDKnqD.d.ts +0 -201
- package/dist/index-BTMt4OjA.d.ts +0 -201
- package/dist/index-BejbszA7.d.ts +0 -39
- package/dist/index-BkeOYZye.d.ts +0 -198
- package/dist/index-BuAj5nXg.d.ts +0 -83
- package/dist/index-BvkVcW8I.d.ts +0 -349
- package/dist/index-CWmH_-RZ.d.ts +0 -247
- package/dist/index-CbgWNcus.d.ts +0 -258
- package/dist/index-CmfPeQza.d.ts +0 -166
- package/dist/index-CmpG-zak.d.ts +0 -607
- package/dist/index-CoMKgL-p.d.ts +0 -12
- package/dist/index-D8HGwglK.d.ts +0 -541
- package/dist/index-DCaVm66D.d.ts +0 -1101
- package/dist/index-DE2w7E0d.d.ts +0 -83
- package/dist/index-DSOpj8DI.d.ts +0 -17
- package/dist/index-DW9q22GH.d.ts +0 -75
- package/dist/index-DnjJ9CwI.d.ts +0 -347
- package/dist/index-DwMJZ8PP.d.ts +0 -317
- package/dist/index-PaojfSdd.d.ts +0 -71
- package/dist/index-aHtYvc3i.d.ts +0 -284
- package/dist/index-e_18DzAg.d.ts +0 -18
- package/dist/index-ffmipXSA.d.ts +0 -55
- package/dist/index-joONjwLt.d.ts +0 -33
- package/dist/index-kssw5ziY.d.ts +0 -250
- package/dist/index-lFffh5-G.d.ts +0 -125
- package/dist/index-pxYge_6k.d.ts +0 -79
- package/dist/layer-Cv9vSwBx.d.ts +0 -70
- package/dist/pino-logger-H4HPW5P6.js +0 -5
- package/dist/pino-logger-H4HPW5P6.js.map +0 -1
- package/dist/prisma-extension-gYhYriA0.d.ts +0 -174
- package/dist/sdk-L75WWUP3.js +0 -156
- package/dist/sdk-L75WWUP3.js.map +0 -1
- package/dist/shutdown-registry-CW9LryO8.d.ts +0 -10
- package/dist/types-Bo2wkjSP.d.ts +0 -35
- package/dist/types-DVpvrAhd.d.ts +0 -71
- package/dist/types-DgJ4lDYA.d.ts +0 -108
- package/dist/types-USOv09qy.d.ts +0 -327
- package/dist/workspace-guard-NXVYYBVJ.js +0 -5
- package/dist/workspace-guard-NXVYYBVJ.js.map +0 -1
|
@@ -0,0 +1,830 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-ad2WFvuA.js";
|
|
2
|
+
import { n as GatewayError } from "./types-BYMYND1L.js";
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
|
|
5
|
+
// src/files/types.ts
|
|
6
|
+
/** Actor types the gateway forwards in `x-actor-type`. */
|
|
7
|
+
const FILE_ACTOR_TYPES = [
|
|
8
|
+
"user",
|
|
9
|
+
"app",
|
|
10
|
+
"service",
|
|
11
|
+
"super_admin"
|
|
12
|
+
];
|
|
13
|
+
/** `FileVisibility` enum members accepted by wspace-files-svc. */
|
|
14
|
+
const FILE_VISIBILITIES = [
|
|
15
|
+
"PRIVATE",
|
|
16
|
+
"PUBLIC",
|
|
17
|
+
"TEAM",
|
|
18
|
+
"WORKSPACE"
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
// src/files/errors.ts
|
|
22
|
+
/**
|
|
23
|
+
* Files client — error type.
|
|
24
|
+
*
|
|
25
|
+
* Services map {@link FilesClientError} onto their own i18n GraphQL errors; the
|
|
26
|
+
* `code` is stable so that mapping never parses messages. Upstream detail
|
|
27
|
+
* (files-svc messages, storage status codes) lives in `details` for logging and
|
|
28
|
+
* must not be returned to clients verbatim.
|
|
29
|
+
*/
|
|
30
|
+
/** GraphQL `extensions.code` each {@link FilesClientErrorCode} should surface as. */
|
|
31
|
+
const FILES_CLIENT_GRAPHQL_CODES = {
|
|
32
|
+
INVALID_INPUT: "BAD_USER_INPUT",
|
|
33
|
+
MISSING_CONTEXT: "UNAUTHENTICATED",
|
|
34
|
+
NOT_FOUND: "NOT_FOUND",
|
|
35
|
+
QUOTA_EXCEEDED: "QUOTA_EXCEEDED",
|
|
36
|
+
TOO_LARGE: "BAD_USER_INPUT",
|
|
37
|
+
STORAGE_ERROR: "INTERNAL_SERVER_ERROR",
|
|
38
|
+
UPSTREAM_ERROR: "INTERNAL_SERVER_ERROR",
|
|
39
|
+
CONFIGURATION_ERROR: "INTERNAL_SERVER_ERROR"
|
|
40
|
+
};
|
|
41
|
+
var FilesClientError = class extends Error {
|
|
42
|
+
code;
|
|
43
|
+
details;
|
|
44
|
+
constructor(code, message, details = {}) {
|
|
45
|
+
super(message);
|
|
46
|
+
this.name = "FilesClientError";
|
|
47
|
+
this.code = code;
|
|
48
|
+
this.details = details;
|
|
49
|
+
}
|
|
50
|
+
/** The GraphQL `extensions.code` this error maps to. */
|
|
51
|
+
get graphqlCode() {
|
|
52
|
+
return FILES_CLIENT_GRAPHQL_CODES[this.code];
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
function isFilesClientError(error) {
|
|
56
|
+
return error instanceof FilesClientError;
|
|
57
|
+
}
|
|
58
|
+
const NOT_FOUND_UPSTREAM_CODES = /* @__PURE__ */ new Set(["NOT_FOUND", "FORBIDDEN"]);
|
|
59
|
+
const QUOTA_UPSTREAM_CODES = /* @__PURE__ */ new Set([
|
|
60
|
+
"QUOTA_EXCEEDED",
|
|
61
|
+
"QUOTA_EXHAUSTED",
|
|
62
|
+
"USAGE_LIMIT_EXCEEDED"
|
|
63
|
+
]);
|
|
64
|
+
const INVALID_UPSTREAM_CODES = /* @__PURE__ */ new Set(["BAD_USER_INPUT", "EXPIRED"]);
|
|
65
|
+
function upstreamCode(error) {
|
|
66
|
+
const code = error.extensions?.["code"];
|
|
67
|
+
return typeof code === "string" ? code : null;
|
|
68
|
+
}
|
|
69
|
+
/** Classify files-svc GraphQL errors into a {@link FilesClientErrorCode}. */
|
|
70
|
+
function classifyFilesErrors(errors) {
|
|
71
|
+
const codes = errors.map(upstreamCode).filter((code) => code !== null);
|
|
72
|
+
if (codes.some((code) => QUOTA_UPSTREAM_CODES.has(code))) return "QUOTA_EXCEEDED";
|
|
73
|
+
if (codes.some((code) => NOT_FOUND_UPSTREAM_CODES.has(code))) return "NOT_FOUND";
|
|
74
|
+
if (codes.some((code) => INVALID_UPSTREAM_CODES.has(code))) return "INVALID_INPUT";
|
|
75
|
+
return "UPSTREAM_ERROR";
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Normalise anything a files-svc call threw (a `GatewayError` carrying GraphQL
|
|
79
|
+
* errors, a timeout, a network error, …) into a {@link FilesClientError}.
|
|
80
|
+
*/
|
|
81
|
+
function toFilesClientError(error, operation) {
|
|
82
|
+
if (error instanceof FilesClientError) return error;
|
|
83
|
+
if (error instanceof GatewayError) {
|
|
84
|
+
const graphqlErrors = error.graphqlErrors ?? [];
|
|
85
|
+
const code = graphqlErrors.length > 0 ? classifyFilesErrors(graphqlErrors) : "UPSTREAM_ERROR";
|
|
86
|
+
return new FilesClientError(code, `wspace-files-svc ${operation} failed: ${error.message}`, {
|
|
87
|
+
operation,
|
|
88
|
+
gatewayErrorType: error.type,
|
|
89
|
+
statusCode: error.statusCode,
|
|
90
|
+
errors: graphqlErrors.map((graphqlError) => ({
|
|
91
|
+
message: graphqlError.message,
|
|
92
|
+
code: upstreamCode(graphqlError)
|
|
93
|
+
}))
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
97
|
+
return new FilesClientError("UPSTREAM_ERROR", `wspace-files-svc ${operation} failed: ${message}`, { operation });
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// src/files/client.ts
|
|
101
|
+
/**
|
|
102
|
+
* FilesClient — store and read workspace blobs through wspace-files-svc.
|
|
103
|
+
*
|
|
104
|
+
* Module ownership makes wspace-files-svc the canonical owner of blobs, yet
|
|
105
|
+
* services kept re-implementing storage: VibeControls hand-rolled SigV4 with
|
|
106
|
+
* static S3 keys for security evidence, FluidGrids passed attachments between
|
|
107
|
+
* nodes as base64, HealthyBowl carried its own three-step uploader. This class
|
|
108
|
+
* is the shared client: a service hands it bytes and gets back an opaque
|
|
109
|
+
* `fileId`, and resolves that id back to metadata, a short-lived download URL or
|
|
110
|
+
* the bytes themselves.
|
|
111
|
+
*
|
|
112
|
+
* Every call is same-layer M2M through the internal workspace gateway
|
|
113
|
+
* (`GatewayClient.internalQuery`, which signs the service JWT; the gateway adds
|
|
114
|
+
* its own trusted token toward files-svc). The CALLER's actor and workspace are
|
|
115
|
+
* forwarded explicitly, so the File row is owned by the user who asked for it,
|
|
116
|
+
* shows up in their library, and files-svc applies quota, folder access and read
|
|
117
|
+
* permission to that user. The internal gateway enforces neither `@rbac` nor
|
|
118
|
+
* `@usage` for the product's own resolver, so the service must already have
|
|
119
|
+
* authorized the action (its own `@rbac` plus a workspace-scoped row lookup).
|
|
120
|
+
*
|
|
121
|
+
* Upload is the files-svc protocol: `initiateUpload` → presigned PUT (DIRECT) or
|
|
122
|
+
* per-part PUTs + `registerUploadedPart` (MULTIPART, which files-svc picks for
|
|
123
|
+
* files over 5 MiB) → `completeUpload` with the same `fileSize` (required: it
|
|
124
|
+
* must match the size declared at initiate). A failed upload aborts its session.
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```ts
|
|
128
|
+
* import { FilesClient, toFileReference } from '@burdenoff/be-sdk/files';
|
|
129
|
+
*
|
|
130
|
+
* const files = new FilesClient({ serviceName: 'wspace-vibecontrols-svc' });
|
|
131
|
+
*
|
|
132
|
+
* const stored = await files.uploadFile(
|
|
133
|
+
* { fileName: 'access-review.pdf', data: pdfBytes, mimeType: 'application/pdf', description: 'SOC 2 evidence' },
|
|
134
|
+
* { actorId: ctx.actorId, workspaceId: ctx.workspaceId }
|
|
135
|
+
* );
|
|
136
|
+
* await db.securityEvidence.update({ where: { id }, data: { fileId: stored.fileId } });
|
|
137
|
+
*
|
|
138
|
+
* const url = await files.getDownloadUrl(evidence.fileId, actor, { expiresInSeconds: 300 });
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
const MIB = 1048576;
|
|
142
|
+
/** S3 refuses presigned URLs that live longer than 7 days; files-svc 500s above it. */
|
|
143
|
+
const MAX_DOWNLOAD_URL_TTL_SECONDS = 604800;
|
|
144
|
+
/** Shortest URL lifetime the client will request. */
|
|
145
|
+
const MIN_DOWNLOAD_URL_TTL_SECONDS = 60;
|
|
146
|
+
const DEFAULT_REQUEST_TIMEOUT_MS = 15e3;
|
|
147
|
+
const DEFAULT_TRANSFER_TIMEOUT_MS = 12e4;
|
|
148
|
+
const DEFAULT_MAX_UPLOAD_BYTES = 100 * MIB;
|
|
149
|
+
const DEFAULT_MAX_DOWNLOAD_BYTES = 25 * MIB;
|
|
150
|
+
const DEFAULT_DOWNLOAD_URL_TTL_SECONDS = 3600;
|
|
151
|
+
/** TTL of the URL `downloadFile` mints for its own immediate GET. */
|
|
152
|
+
const INTERNAL_DOWNLOAD_URL_TTL_SECONDS = 300;
|
|
153
|
+
const PART_URL_BATCH_SIZE = 20;
|
|
154
|
+
const SHA256_HEX = /^[0-9a-f]{64}$/;
|
|
155
|
+
const FILE_FIELDS = "id name mimeType extension size status visibility workspaceId folderId uploadedById description sha256Hash createdAt updatedAt canRead canDelete";
|
|
156
|
+
const INITIATE_UPLOAD = `mutation FilesClientInitiateUpload($input: InitiateUploadInput!) {
|
|
157
|
+
initiateUpload(input: $input) {
|
|
158
|
+
uploadUrl
|
|
159
|
+
session { id uploadType partSize totalParts fileSize expiresAt }
|
|
160
|
+
}
|
|
161
|
+
}`;
|
|
162
|
+
const PART_URLS = `query FilesClientPartUploadUrls($sessionId: ID!, $partNumbers: [Int!]!) {
|
|
163
|
+
getBatchPartUploadUrls(sessionId: $sessionId, partNumbers: $partNumbers) { partNumber url }
|
|
164
|
+
}`;
|
|
165
|
+
const REGISTER_PART = `mutation FilesClientRegisterUploadedPart($input: UploadPartInput!) {
|
|
166
|
+
registerUploadedPart(input: $input) { session { id uploadedParts } }
|
|
167
|
+
}`;
|
|
168
|
+
const COMPLETE_UPLOAD = `mutation FilesClientCompleteUpload($input: CompleteUploadInput!) {
|
|
169
|
+
completeUpload(input: $input) { fileId file { id name mimeType size workspaceId sha256Hash } }
|
|
170
|
+
}`;
|
|
171
|
+
const ABORT_UPLOAD = `mutation FilesClientAbortUpload($sessionId: ID!) { abortUpload(sessionId: $sessionId) }`;
|
|
172
|
+
const GET_FILE = `query FilesClientGetFile($id: ID!) { getFile(id: $id) { ${FILE_FIELDS} } }`;
|
|
173
|
+
const GET_DOWNLOAD_URL = `query FilesClientGetFileDownloadUrl($id: ID!, $expiresIn: Int) {
|
|
174
|
+
getFileDownloadUrl(id: $id, expiresIn: $expiresIn)
|
|
175
|
+
}`;
|
|
176
|
+
const RESOLVE_FOR_DOWNLOAD = `query FilesClientResolveForDownload($id: ID!, $expiresIn: Int) {
|
|
177
|
+
getFile(id: $id) { ${FILE_FIELDS} }
|
|
178
|
+
getFileDownloadUrl(id: $id, expiresIn: $expiresIn)
|
|
179
|
+
}`;
|
|
180
|
+
const DELETE_FILE = `mutation FilesClientDeleteFile($id: ID!) { deleteFile(id: $id) }`;
|
|
181
|
+
const PERMANENTLY_DELETE_FILE = `mutation FilesClientPermanentlyDeleteFile($id: ID!) { permanentlyDeleteFile(id: $id) }`;
|
|
182
|
+
function requireNonEmpty(value, field) {
|
|
183
|
+
const trimmed = typeof value === "string" ? value.trim() : "";
|
|
184
|
+
if (!trimmed) throw new FilesClientError("INVALID_INPUT", `${field} is required`, { field });
|
|
185
|
+
return trimmed;
|
|
186
|
+
}
|
|
187
|
+
function requirePositiveInteger(value, field) {
|
|
188
|
+
if (!Number.isSafeInteger(value) || value <= 0) throw new FilesClientError("CONFIGURATION_ERROR", `${field} must be a positive integer`, {
|
|
189
|
+
field,
|
|
190
|
+
value
|
|
191
|
+
});
|
|
192
|
+
return value;
|
|
193
|
+
}
|
|
194
|
+
function toNumber(value, field) {
|
|
195
|
+
const parsed = typeof value === "number" ? value : Number(value);
|
|
196
|
+
if (!Number.isSafeInteger(parsed) || parsed < 0) throw new FilesClientError("UPSTREAM_ERROR", `wspace-files-svc returned an invalid ${field}`, {
|
|
197
|
+
field,
|
|
198
|
+
value
|
|
199
|
+
});
|
|
200
|
+
return parsed;
|
|
201
|
+
}
|
|
202
|
+
function toDate(value) {
|
|
203
|
+
if (!value) return null;
|
|
204
|
+
const date = new Date(value);
|
|
205
|
+
return Number.isNaN(date.getTime()) ? null : date;
|
|
206
|
+
}
|
|
207
|
+
/** A view over `data` backed by a plain `ArrayBuffer` (what `fetch` bodies accept). */
|
|
208
|
+
function toBytes(data) {
|
|
209
|
+
if (data instanceof ArrayBuffer) return new Uint8Array(data);
|
|
210
|
+
const { buffer } = data;
|
|
211
|
+
if (buffer instanceof ArrayBuffer) return new Uint8Array(buffer, data.byteOffset, data.byteLength);
|
|
212
|
+
return new Uint8Array(data);
|
|
213
|
+
}
|
|
214
|
+
/** Extension for `fileName` (`report.PDF` → `pdf`), or `bin` when it has none. */
|
|
215
|
+
function fileExtensionOf(fileName) {
|
|
216
|
+
const base = fileName.trim().split(/[\\/]/).pop() ?? "";
|
|
217
|
+
const dot = base.lastIndexOf(".");
|
|
218
|
+
if (dot <= 0 || dot === base.length - 1) return "bin";
|
|
219
|
+
return base.slice(dot + 1).toLowerCase().replace(/[^a-z0-9]/g, "") || "bin";
|
|
220
|
+
}
|
|
221
|
+
/** Clamp a requested URL lifetime to what files-svc / S3 accept. */
|
|
222
|
+
function clampDownloadUrlTtl(seconds, fallback) {
|
|
223
|
+
return Math.min(Math.max(Math.trunc(seconds === null || seconds === void 0 || !Number.isFinite(seconds) ? fallback : seconds), 60), MAX_DOWNLOAD_URL_TTL_SECONDS);
|
|
224
|
+
}
|
|
225
|
+
function isHttpUrl(value) {
|
|
226
|
+
if (typeof value !== "string" || value.length === 0) return false;
|
|
227
|
+
try {
|
|
228
|
+
const { protocol } = new URL(value);
|
|
229
|
+
return protocol === "https:" || protocol === "http:";
|
|
230
|
+
} catch {
|
|
231
|
+
return false;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
/** Lowercase a declared SHA-256 and reject anything that is not 64 hex characters. */
|
|
235
|
+
function normalizeSha256(value) {
|
|
236
|
+
if (value === null || value === void 0 || value.trim() === "") return null;
|
|
237
|
+
const normalized = value.trim().toLowerCase();
|
|
238
|
+
if (!SHA256_HEX.test(normalized)) throw new FilesClientError("INVALID_INPUT", "sha256Hash must be 64 hex characters", { field: "sha256Hash" });
|
|
239
|
+
return normalized;
|
|
240
|
+
}
|
|
241
|
+
/** Validate MULTIPART part ETags: positive, unique part numbers with a non-empty ETag, sorted. */
|
|
242
|
+
function normalizeUploadedParts(parts) {
|
|
243
|
+
const seen = /* @__PURE__ */ new Set();
|
|
244
|
+
return parts.map((part) => {
|
|
245
|
+
const etag = typeof part.etag === "string" ? part.etag.trim() : "";
|
|
246
|
+
if (!Number.isSafeInteger(part.partNumber) || part.partNumber <= 0 || seen.has(part.partNumber) || !etag) throw new FilesClientError("INVALID_INPUT", "parts must have unique positive part numbers and an ETag", {
|
|
247
|
+
field: "parts",
|
|
248
|
+
partNumber: part.partNumber
|
|
249
|
+
});
|
|
250
|
+
seen.add(part.partNumber);
|
|
251
|
+
return {
|
|
252
|
+
partNumber: part.partNumber,
|
|
253
|
+
etag
|
|
254
|
+
};
|
|
255
|
+
}).sort((a, b) => a.partNumber - b.partNumber);
|
|
256
|
+
}
|
|
257
|
+
/** Map a files-svc `File` selection onto {@link FileMetadata}. */
|
|
258
|
+
function mapFileMetadata(raw) {
|
|
259
|
+
return {
|
|
260
|
+
id: raw.id,
|
|
261
|
+
name: raw.name,
|
|
262
|
+
mimeType: raw.mimeType,
|
|
263
|
+
extension: raw.extension,
|
|
264
|
+
size: toNumber(raw.size, "size"),
|
|
265
|
+
status: raw.status,
|
|
266
|
+
visibility: raw.visibility,
|
|
267
|
+
workspaceId: raw.workspaceId,
|
|
268
|
+
folderId: raw.folderId ?? null,
|
|
269
|
+
uploadedById: raw.uploadedById,
|
|
270
|
+
description: raw.description ?? null,
|
|
271
|
+
sha256Hash: raw.sha256Hash ?? null,
|
|
272
|
+
createdAt: toDate(raw.createdAt),
|
|
273
|
+
updatedAt: toDate(raw.updatedAt),
|
|
274
|
+
canRead: raw.canRead ?? null,
|
|
275
|
+
canDelete: raw.canDelete ?? null
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
var FilesClient = class {
|
|
279
|
+
clientOption;
|
|
280
|
+
serviceName;
|
|
281
|
+
fetchImpl;
|
|
282
|
+
requestTimeoutMs;
|
|
283
|
+
transferTimeoutMs;
|
|
284
|
+
maxUploadBytes;
|
|
285
|
+
maxDownloadBytes;
|
|
286
|
+
defaultDownloadUrlTtlSeconds;
|
|
287
|
+
clientPromise = null;
|
|
288
|
+
constructor(options = {}) {
|
|
289
|
+
this.clientOption = options.client;
|
|
290
|
+
this.serviceName = options.serviceName;
|
|
291
|
+
this.fetchImpl = options.fetch ?? ((url, init) => fetch(url, init));
|
|
292
|
+
this.requestTimeoutMs = requirePositiveInteger(options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS, "requestTimeoutMs");
|
|
293
|
+
this.transferTimeoutMs = requirePositiveInteger(options.transferTimeoutMs ?? DEFAULT_TRANSFER_TIMEOUT_MS, "transferTimeoutMs");
|
|
294
|
+
this.maxUploadBytes = requirePositiveInteger(options.maxUploadBytes ?? DEFAULT_MAX_UPLOAD_BYTES, "maxUploadBytes");
|
|
295
|
+
this.maxDownloadBytes = requirePositiveInteger(options.maxDownloadBytes ?? DEFAULT_MAX_DOWNLOAD_BYTES, "maxDownloadBytes");
|
|
296
|
+
const ttl = options.defaultDownloadUrlTtlSeconds ?? DEFAULT_DOWNLOAD_URL_TTL_SECONDS;
|
|
297
|
+
if (!Number.isSafeInteger(ttl) || ttl < 60 || ttl > 604800) throw new FilesClientError("CONFIGURATION_ERROR", `defaultDownloadUrlTtlSeconds must be between ${60} and ${MAX_DOWNLOAD_URL_TTL_SECONDS}`, { value: ttl });
|
|
298
|
+
this.defaultDownloadUrlTtlSeconds = ttl;
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Store bytes in the actor's workspace file library and return the File's id.
|
|
302
|
+
* Throws {@link FilesClientError}; on any failure after the session was opened
|
|
303
|
+
* the session is aborted so no half-uploaded object is left behind.
|
|
304
|
+
*/
|
|
305
|
+
async uploadFile(input, actor) {
|
|
306
|
+
const context = this.requireActor(actor);
|
|
307
|
+
const fileName = requireNonEmpty(input.fileName, "fileName");
|
|
308
|
+
const mimeType = requireNonEmpty(input.mimeType, "mimeType");
|
|
309
|
+
const bytes = toBytes(input.data);
|
|
310
|
+
if (bytes.byteLength === 0) throw new FilesClientError("INVALID_INPUT", "data must not be empty", { field: "data" });
|
|
311
|
+
if (bytes.byteLength > this.maxUploadBytes) throw new FilesClientError("TOO_LARGE", `File is larger than ${this.maxUploadBytes} bytes`, {
|
|
312
|
+
size: bytes.byteLength,
|
|
313
|
+
maxBytes: this.maxUploadBytes
|
|
314
|
+
});
|
|
315
|
+
if (input.visibility !== void 0 && !FILE_VISIBILITIES.includes(input.visibility)) throw new FilesClientError("INVALID_INPUT", `Unknown file visibility "${String(input.visibility)}"`, { field: "visibility" });
|
|
316
|
+
const extension = input.extension?.trim() ? input.extension.trim().replace(/^\./, "").toLowerCase() : fileExtensionOf(fileName);
|
|
317
|
+
const fileSize = String(bytes.byteLength);
|
|
318
|
+
const sha256Hash = input.declareSha256 === false ? null : createHash("sha256").update(bytes).digest("hex");
|
|
319
|
+
const folderId = input.folderId?.trim() || void 0;
|
|
320
|
+
const initiated = await this.request("initiateUpload", INITIATE_UPLOAD, { input: {
|
|
321
|
+
fileName,
|
|
322
|
+
fileSize,
|
|
323
|
+
mimeType,
|
|
324
|
+
extension,
|
|
325
|
+
...folderId ? { folderId } : {},
|
|
326
|
+
...input.visibility ? { visibility: input.visibility } : {},
|
|
327
|
+
...sha256Hash ? { sha256Hash } : {}
|
|
328
|
+
} }, context);
|
|
329
|
+
const rawSession = initiated.initiateUpload?.session;
|
|
330
|
+
if (!rawSession?.id) throw new FilesClientError("UPSTREAM_ERROR", "wspace-files-svc initiateUpload returned no session");
|
|
331
|
+
const session = {
|
|
332
|
+
id: rawSession.id,
|
|
333
|
+
uploadType: rawSession.uploadType,
|
|
334
|
+
partSize: toNumber(rawSession.partSize, "partSize"),
|
|
335
|
+
totalParts: toNumber(rawSession.totalParts, "totalParts")
|
|
336
|
+
};
|
|
337
|
+
try {
|
|
338
|
+
if (session.uploadType === "MULTIPART") await this.uploadParts(session, bytes, context);
|
|
339
|
+
else await this.putDirect(initiated.initiateUpload?.uploadUrl, bytes, mimeType);
|
|
340
|
+
return await this.completeSession(session.id, {
|
|
341
|
+
fileSize,
|
|
342
|
+
fallbackName: fileName,
|
|
343
|
+
fallbackMimeType: mimeType,
|
|
344
|
+
fallbackSize: bytes.byteLength,
|
|
345
|
+
sha256Hash,
|
|
346
|
+
folderId,
|
|
347
|
+
description: input.description ?? null
|
|
348
|
+
}, context);
|
|
349
|
+
} catch (error) {
|
|
350
|
+
await this.abortQuietly(session.id, context);
|
|
351
|
+
throw toFilesClientError(error, "uploadFile");
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Open a files-svc upload session on the actor's behalf for bytes that
|
|
356
|
+
* someone else holds (an agent, a CLI, a browser), and return the presigned
|
|
357
|
+
* URL(s) to hand them. The uploader PUTs the bytes — one PUT to `uploadUrl`
|
|
358
|
+
* for DIRECT, one PUT per `parts` entry for MULTIPART (files-svc picks
|
|
359
|
+
* MULTIPART above 5 MiB) — and the service then calls
|
|
360
|
+
* {@link completeUploadSession} with the same `fileSize` (and the part ETags)
|
|
361
|
+
* to turn the session into a File. The service never sees the bytes and never
|
|
362
|
+
* holds storage credentials.
|
|
363
|
+
*
|
|
364
|
+
* Throws {@link FilesClientError}. If files-svc opened the session but the
|
|
365
|
+
* client cannot hand it out (an unsupported upload type, missing part URLs),
|
|
366
|
+
* the session is aborted before the error is thrown.
|
|
367
|
+
*/
|
|
368
|
+
async createUploadSession(input, actor) {
|
|
369
|
+
const context = this.requireActor(actor);
|
|
370
|
+
const fileName = requireNonEmpty(input.fileName, "fileName");
|
|
371
|
+
const mimeType = requireNonEmpty(input.mimeType, "mimeType");
|
|
372
|
+
if (!Number.isSafeInteger(input.fileSize) || input.fileSize <= 0) throw new FilesClientError("INVALID_INPUT", "fileSize must be a positive integer", { field: "fileSize" });
|
|
373
|
+
if (input.fileSize > this.maxUploadBytes) throw new FilesClientError("TOO_LARGE", `File is larger than ${this.maxUploadBytes} bytes`, {
|
|
374
|
+
size: input.fileSize,
|
|
375
|
+
maxBytes: this.maxUploadBytes
|
|
376
|
+
});
|
|
377
|
+
if (input.visibility !== void 0 && !FILE_VISIBILITIES.includes(input.visibility)) throw new FilesClientError("INVALID_INPUT", `Unknown file visibility "${String(input.visibility)}"`, { field: "visibility" });
|
|
378
|
+
const sha256Hash = normalizeSha256(input.sha256Hash);
|
|
379
|
+
const extension = input.extension?.trim() ? input.extension.trim().replace(/^\./, "").toLowerCase() : fileExtensionOf(fileName);
|
|
380
|
+
const folderId = input.folderId?.trim() || void 0;
|
|
381
|
+
const initiated = await this.request("initiateUpload", INITIATE_UPLOAD, { input: {
|
|
382
|
+
fileName,
|
|
383
|
+
fileSize: String(input.fileSize),
|
|
384
|
+
mimeType,
|
|
385
|
+
extension,
|
|
386
|
+
...folderId ? { folderId } : {},
|
|
387
|
+
...input.visibility ? { visibility: input.visibility } : {},
|
|
388
|
+
...sha256Hash ? { sha256Hash } : {}
|
|
389
|
+
} }, context);
|
|
390
|
+
const rawSession = initiated.initiateUpload?.session;
|
|
391
|
+
if (!rawSession?.id) throw new FilesClientError("UPSTREAM_ERROR", "wspace-files-svc initiateUpload returned no session");
|
|
392
|
+
try {
|
|
393
|
+
const partSize = toNumber(rawSession.partSize, "partSize");
|
|
394
|
+
const totalParts = toNumber(rawSession.totalParts, "totalParts");
|
|
395
|
+
const base = {
|
|
396
|
+
sessionId: rawSession.id,
|
|
397
|
+
partSize,
|
|
398
|
+
totalParts,
|
|
399
|
+
fileSize: input.fileSize,
|
|
400
|
+
sha256Hash,
|
|
401
|
+
expiresAt: toDate(rawSession.expiresAt)
|
|
402
|
+
};
|
|
403
|
+
if (rawSession.uploadType === "MULTIPART") {
|
|
404
|
+
const session = {
|
|
405
|
+
id: rawSession.id,
|
|
406
|
+
uploadType: "MULTIPART",
|
|
407
|
+
partSize,
|
|
408
|
+
totalParts
|
|
409
|
+
};
|
|
410
|
+
this.assertMultipartPlan(session, input.fileSize);
|
|
411
|
+
const parts = await this.presignParts(session, input.fileSize, context);
|
|
412
|
+
return {
|
|
413
|
+
...base,
|
|
414
|
+
uploadType: "MULTIPART",
|
|
415
|
+
uploadUrl: null,
|
|
416
|
+
requiredHeaders: {},
|
|
417
|
+
parts
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
if (rawSession.uploadType !== "DIRECT") throw new FilesClientError("UPSTREAM_ERROR", `wspace-files-svc opened an unsupported ${String(rawSession.uploadType)} session`, { sessionId: rawSession.id });
|
|
421
|
+
const uploadUrl = initiated.initiateUpload?.uploadUrl;
|
|
422
|
+
if (!isHttpUrl(uploadUrl)) throw new FilesClientError("UPSTREAM_ERROR", "wspace-files-svc initiateUpload returned no upload URL", { sessionId: rawSession.id });
|
|
423
|
+
return {
|
|
424
|
+
...base,
|
|
425
|
+
uploadType: "DIRECT",
|
|
426
|
+
uploadUrl,
|
|
427
|
+
requiredHeaders: { "Content-Type": mimeType },
|
|
428
|
+
parts: []
|
|
429
|
+
};
|
|
430
|
+
} catch (error) {
|
|
431
|
+
await this.abortQuietly(rawSession.id, context);
|
|
432
|
+
throw toFilesClientError(error, "createUploadSession");
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Turn a session opened by {@link createUploadSession} into a File once the
|
|
437
|
+
* uploader has PUT the bytes: registers the MULTIPART part ETags, then runs
|
|
438
|
+
* `completeUpload` with the declared size (and SHA-256). files-svc verifies
|
|
439
|
+
* the stored object; a size or checksum mismatch surfaces as `INVALID_INPUT`.
|
|
440
|
+
* The session is left open on failure so the caller can retry or
|
|
441
|
+
* {@link abortUploadSession} it.
|
|
442
|
+
*/
|
|
443
|
+
async completeUploadSession(sessionId, input, actor) {
|
|
444
|
+
const context = this.requireActor(actor);
|
|
445
|
+
const id = requireNonEmpty(sessionId, "sessionId");
|
|
446
|
+
if (!Number.isSafeInteger(input.fileSize) || input.fileSize <= 0) throw new FilesClientError("INVALID_INPUT", "fileSize must be a positive integer", { field: "fileSize" });
|
|
447
|
+
const sha256Hash = normalizeSha256(input.sha256Hash);
|
|
448
|
+
const parts = normalizeUploadedParts(input.parts ?? []);
|
|
449
|
+
const folderId = input.folderId?.trim() || void 0;
|
|
450
|
+
for (const part of parts) await this.request("registerUploadedPart", REGISTER_PART, { input: {
|
|
451
|
+
sessionId: id,
|
|
452
|
+
partNumber: part.partNumber,
|
|
453
|
+
etag: part.etag
|
|
454
|
+
} }, context);
|
|
455
|
+
return this.completeSession(id, {
|
|
456
|
+
fileSize: String(input.fileSize),
|
|
457
|
+
fallbackName: "",
|
|
458
|
+
fallbackMimeType: "",
|
|
459
|
+
fallbackSize: input.fileSize,
|
|
460
|
+
sha256Hash,
|
|
461
|
+
folderId,
|
|
462
|
+
description: input.description ?? null
|
|
463
|
+
}, context);
|
|
464
|
+
}
|
|
465
|
+
/** Abandon a session opened by {@link createUploadSession}. `true` when files-svc aborted it. */
|
|
466
|
+
async abortUploadSession(sessionId, actor) {
|
|
467
|
+
const id = requireNonEmpty(sessionId, "sessionId");
|
|
468
|
+
return (await this.request("abortUpload", ABORT_UPLOAD, { sessionId: id }, actor)).abortUpload === true;
|
|
469
|
+
}
|
|
470
|
+
/** File metadata, or `null` when it does not exist or the actor cannot see it. */
|
|
471
|
+
async getFile(fileId, actor) {
|
|
472
|
+
const id = requireNonEmpty(fileId, "fileId");
|
|
473
|
+
try {
|
|
474
|
+
const data = await this.request("getFile", GET_FILE, { id }, actor);
|
|
475
|
+
return data.getFile ? mapFileMetadata(data.getFile) : null;
|
|
476
|
+
} catch (error) {
|
|
477
|
+
if (error instanceof FilesClientError && error.code === "NOT_FOUND") return null;
|
|
478
|
+
throw error;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* Prove that an opaque file id the caller supplied names a File in the actor's
|
|
483
|
+
* workspace that they may read, before the service stores or acts on it.
|
|
484
|
+
* Throws `NOT_FOUND` (never a permission error) otherwise.
|
|
485
|
+
*/
|
|
486
|
+
async requireFile(fileId, actor, options = {}) {
|
|
487
|
+
const context = this.requireActor(actor);
|
|
488
|
+
const file = await this.getFile(fileId, context);
|
|
489
|
+
this.assertUsable(file, fileId, context, options);
|
|
490
|
+
return file;
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* A presigned download URL for the file, minted for the actor. Mint it when the
|
|
494
|
+
* user opens the file; never persist it. The lifetime is clamped to
|
|
495
|
+
* [60, 604800] seconds.
|
|
496
|
+
*/
|
|
497
|
+
async getDownloadUrl(fileId, actor, options = {}) {
|
|
498
|
+
const id = requireNonEmpty(fileId, "fileId");
|
|
499
|
+
const expiresIn = clampDownloadUrlTtl(options.expiresInSeconds, this.defaultDownloadUrlTtlSeconds);
|
|
500
|
+
const data = await this.request("getFileDownloadUrl", GET_DOWNLOAD_URL, {
|
|
501
|
+
id,
|
|
502
|
+
expiresIn
|
|
503
|
+
}, actor);
|
|
504
|
+
if (!isHttpUrl(data.getFileDownloadUrl)) throw new FilesClientError("UPSTREAM_ERROR", "wspace-files-svc returned no usable download URL", { fileId: id });
|
|
505
|
+
return data.getFileDownloadUrl;
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* Fetch the file's bytes for server-side processing (vision models, parsers,
|
|
509
|
+
* workflow nodes). Checks the file is active, readable by the actor and within
|
|
510
|
+
* `maxBytes` before downloading, and verifies the downloaded size.
|
|
511
|
+
*/
|
|
512
|
+
async downloadFile(fileId, actor, options = {}) {
|
|
513
|
+
const context = this.requireActor(actor);
|
|
514
|
+
const id = requireNonEmpty(fileId, "fileId");
|
|
515
|
+
const maxBytes = options.maxBytes ?? this.maxDownloadBytes;
|
|
516
|
+
if (!Number.isSafeInteger(maxBytes) || maxBytes <= 0) throw new FilesClientError("INVALID_INPUT", "maxBytes must be a positive integer", { field: "maxBytes" });
|
|
517
|
+
const data = await this.request("downloadFile", RESOLVE_FOR_DOWNLOAD, {
|
|
518
|
+
id,
|
|
519
|
+
expiresIn: INTERNAL_DOWNLOAD_URL_TTL_SECONDS
|
|
520
|
+
}, context);
|
|
521
|
+
const file = data.getFile ? mapFileMetadata(data.getFile) : null;
|
|
522
|
+
this.assertUsable(file, id, context, {});
|
|
523
|
+
if (file.size > maxBytes) throw new FilesClientError("TOO_LARGE", `File is larger than ${maxBytes} bytes`, {
|
|
524
|
+
fileId: id,
|
|
525
|
+
size: file.size,
|
|
526
|
+
maxBytes
|
|
527
|
+
});
|
|
528
|
+
const url = data.getFileDownloadUrl;
|
|
529
|
+
if (!isHttpUrl(url)) throw new FilesClientError("UPSTREAM_ERROR", "wspace-files-svc returned no usable download URL", { fileId: id });
|
|
530
|
+
const response = await this.transfer(url, { method: "GET" }, "download");
|
|
531
|
+
const bytes = await this.readBounded(response, maxBytes, id);
|
|
532
|
+
if (bytes.byteLength !== file.size) throw new FilesClientError("STORAGE_ERROR", "Downloaded size does not match the stored file size", {
|
|
533
|
+
fileId: id,
|
|
534
|
+
expected: file.size,
|
|
535
|
+
actual: bytes.byteLength
|
|
536
|
+
});
|
|
537
|
+
return {
|
|
538
|
+
bytes,
|
|
539
|
+
mimeType: file.mimeType,
|
|
540
|
+
name: file.name,
|
|
541
|
+
size: bytes.byteLength
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
/** {@link downloadFile} as base64, for payloads that must stay JSON (model inputs). */
|
|
545
|
+
async downloadFileAsBase64(fileId, actor, options = {}) {
|
|
546
|
+
const file = await this.downloadFile(fileId, actor, options);
|
|
547
|
+
return {
|
|
548
|
+
base64: Buffer.from(file.bytes).toString("base64"),
|
|
549
|
+
mimeType: file.mimeType,
|
|
550
|
+
name: file.name,
|
|
551
|
+
size: file.size
|
|
552
|
+
};
|
|
553
|
+
}
|
|
554
|
+
/** Move the file to trash (or hard-delete with `permanent`). `true` when files-svc deleted it. */
|
|
555
|
+
async deleteFile(fileId, actor, options = {}) {
|
|
556
|
+
const id = requireNonEmpty(fileId, "fileId");
|
|
557
|
+
if (options.permanent) return (await this.request("permanentlyDeleteFile", PERMANENTLY_DELETE_FILE, { id }, actor)).permanentlyDeleteFile === true;
|
|
558
|
+
return (await this.request("deleteFile", DELETE_FILE, { id }, actor)).deleteFile === true;
|
|
559
|
+
}
|
|
560
|
+
async putDirect(uploadUrl, bytes, mimeType) {
|
|
561
|
+
if (!isHttpUrl(uploadUrl)) throw new FilesClientError("UPSTREAM_ERROR", "wspace-files-svc initiateUpload returned no upload URL");
|
|
562
|
+
await this.transfer(uploadUrl, {
|
|
563
|
+
method: "PUT",
|
|
564
|
+
body: bytes,
|
|
565
|
+
headers: { "Content-Type": mimeType }
|
|
566
|
+
}, "upload");
|
|
567
|
+
}
|
|
568
|
+
async uploadParts(session, bytes, actor) {
|
|
569
|
+
this.assertMultipartPlan(session, bytes.byteLength);
|
|
570
|
+
for (let first = 1; first <= session.totalParts; first += PART_URL_BATCH_SIZE) {
|
|
571
|
+
const partNumbers = [];
|
|
572
|
+
for (let part = first; part < first + PART_URL_BATCH_SIZE && part <= session.totalParts; part += 1) partNumbers.push(part);
|
|
573
|
+
const data = await this.request("getBatchPartUploadUrls", PART_URLS, {
|
|
574
|
+
sessionId: session.id,
|
|
575
|
+
partNumbers
|
|
576
|
+
}, actor);
|
|
577
|
+
const urls = new Map((data.getBatchPartUploadUrls ?? []).map((entry) => [entry.partNumber, entry.url]));
|
|
578
|
+
for (const partNumber of partNumbers) {
|
|
579
|
+
const url = urls.get(partNumber);
|
|
580
|
+
if (!isHttpUrl(url)) throw new FilesClientError("UPSTREAM_ERROR", `wspace-files-svc returned no URL for part ${partNumber}`, {
|
|
581
|
+
sessionId: session.id,
|
|
582
|
+
partNumber
|
|
583
|
+
});
|
|
584
|
+
const start = (partNumber - 1) * session.partSize;
|
|
585
|
+
const body = bytes.subarray(start, Math.min(start + session.partSize, bytes.byteLength));
|
|
586
|
+
const etag = (await this.transfer(url, {
|
|
587
|
+
method: "PUT",
|
|
588
|
+
body
|
|
589
|
+
}, "upload")).headers.get("etag");
|
|
590
|
+
if (!etag) throw new FilesClientError("STORAGE_ERROR", `Object storage returned no ETag for part ${partNumber}`, {
|
|
591
|
+
sessionId: session.id,
|
|
592
|
+
partNumber
|
|
593
|
+
});
|
|
594
|
+
await this.request("registerUploadedPart", REGISTER_PART, { input: {
|
|
595
|
+
sessionId: session.id,
|
|
596
|
+
partNumber,
|
|
597
|
+
etag
|
|
598
|
+
} }, actor);
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
async completeSession(sessionId, args, actor) {
|
|
603
|
+
const completed = await this.request("completeUpload", COMPLETE_UPLOAD, { input: {
|
|
604
|
+
sessionId,
|
|
605
|
+
fileSize: args.fileSize,
|
|
606
|
+
...args.folderId ? { folderId: args.folderId } : {},
|
|
607
|
+
...args.description ? { description: args.description } : {},
|
|
608
|
+
...args.sha256Hash ? { sha256Hash: args.sha256Hash } : {}
|
|
609
|
+
} }, actor);
|
|
610
|
+
const file = completed.completeUpload?.file;
|
|
611
|
+
const fileId = completed.completeUpload?.fileId ?? file?.id;
|
|
612
|
+
if (!fileId) throw new FilesClientError("UPSTREAM_ERROR", "wspace-files-svc completeUpload returned no fileId", { sessionId });
|
|
613
|
+
return {
|
|
614
|
+
fileId,
|
|
615
|
+
name: file?.name ?? args.fallbackName,
|
|
616
|
+
mimeType: file?.mimeType ?? args.fallbackMimeType,
|
|
617
|
+
size: file ? toNumber(file.size, "size") : args.fallbackSize,
|
|
618
|
+
workspaceId: file?.workspaceId ?? actor.workspaceId,
|
|
619
|
+
sha256Hash: file?.sha256Hash ?? args.sha256Hash
|
|
620
|
+
};
|
|
621
|
+
}
|
|
622
|
+
assertMultipartPlan(session, size) {
|
|
623
|
+
if (session.partSize <= 0 || session.totalParts !== Math.ceil(size / session.partSize)) throw new FilesClientError("UPSTREAM_ERROR", "wspace-files-svc returned an inconsistent multipart plan", {
|
|
624
|
+
sessionId: session.id,
|
|
625
|
+
partSize: session.partSize,
|
|
626
|
+
totalParts: session.totalParts,
|
|
627
|
+
size
|
|
628
|
+
});
|
|
629
|
+
}
|
|
630
|
+
/** Presigned URL for every part, fetched in batches. */
|
|
631
|
+
async partUrls(session, actor) {
|
|
632
|
+
const urls = /* @__PURE__ */ new Map();
|
|
633
|
+
for (let first = 1; first <= session.totalParts; first += PART_URL_BATCH_SIZE) {
|
|
634
|
+
const partNumbers = [];
|
|
635
|
+
for (let part = first; part < first + PART_URL_BATCH_SIZE && part <= session.totalParts; part += 1) partNumbers.push(part);
|
|
636
|
+
const data = await this.request("getBatchPartUploadUrls", PART_URLS, {
|
|
637
|
+
sessionId: session.id,
|
|
638
|
+
partNumbers
|
|
639
|
+
}, actor);
|
|
640
|
+
for (const entry of data.getBatchPartUploadUrls ?? []) urls.set(entry.partNumber, entry.url);
|
|
641
|
+
}
|
|
642
|
+
return urls;
|
|
643
|
+
}
|
|
644
|
+
async presignParts(session, size, actor) {
|
|
645
|
+
const urls = await this.partUrls(session, actor);
|
|
646
|
+
const parts = [];
|
|
647
|
+
for (let partNumber = 1; partNumber <= session.totalParts; partNumber += 1) {
|
|
648
|
+
const url = urls.get(partNumber);
|
|
649
|
+
if (!isHttpUrl(url)) throw new FilesClientError("UPSTREAM_ERROR", `wspace-files-svc returned no URL for part ${partNumber}`, {
|
|
650
|
+
sessionId: session.id,
|
|
651
|
+
partNumber
|
|
652
|
+
});
|
|
653
|
+
const offset = (partNumber - 1) * session.partSize;
|
|
654
|
+
parts.push({
|
|
655
|
+
partNumber,
|
|
656
|
+
url,
|
|
657
|
+
offset,
|
|
658
|
+
length: Math.min(session.partSize, size - offset)
|
|
659
|
+
});
|
|
660
|
+
}
|
|
661
|
+
return parts;
|
|
662
|
+
}
|
|
663
|
+
async abortQuietly(sessionId, actor) {
|
|
664
|
+
try {
|
|
665
|
+
await this.request("abortUpload", ABORT_UPLOAD, { sessionId }, actor);
|
|
666
|
+
} catch {}
|
|
667
|
+
}
|
|
668
|
+
assertUsable(file, fileId, actor, options) {
|
|
669
|
+
const requireActive = options.requireActive ?? true;
|
|
670
|
+
const requireReadable = options.requireReadable ?? true;
|
|
671
|
+
if (!file || file.id !== fileId.trim() || file.workspaceId !== actor.workspaceId || requireActive && file.status !== "ACTIVE" || requireReadable && file.canRead !== true) throw new FilesClientError("NOT_FOUND", "File not found", { fileId });
|
|
672
|
+
}
|
|
673
|
+
async transfer(url, init, leg) {
|
|
674
|
+
let response;
|
|
675
|
+
try {
|
|
676
|
+
response = await this.fetchImpl(url, {
|
|
677
|
+
...init,
|
|
678
|
+
signal: AbortSignal.timeout(this.transferTimeoutMs)
|
|
679
|
+
});
|
|
680
|
+
} catch (error) {
|
|
681
|
+
throw new FilesClientError("STORAGE_ERROR", `Object storage ${leg} failed`, {
|
|
682
|
+
leg,
|
|
683
|
+
cause: error instanceof Error ? error.message : String(error)
|
|
684
|
+
});
|
|
685
|
+
}
|
|
686
|
+
if (!response.ok) throw new FilesClientError("STORAGE_ERROR", `Object storage ${leg} failed with HTTP ${response.status}`, {
|
|
687
|
+
leg,
|
|
688
|
+
status: response.status
|
|
689
|
+
});
|
|
690
|
+
return response;
|
|
691
|
+
}
|
|
692
|
+
async readBounded(response, maxBytes, fileId) {
|
|
693
|
+
const tooLarge = () => new FilesClientError("TOO_LARGE", `File is larger than ${maxBytes} bytes`, {
|
|
694
|
+
fileId,
|
|
695
|
+
maxBytes
|
|
696
|
+
});
|
|
697
|
+
const declared = Number(response.headers.get("content-length") ?? NaN);
|
|
698
|
+
if (Number.isFinite(declared) && declared > maxBytes) throw tooLarge();
|
|
699
|
+
if (!response.body) {
|
|
700
|
+
const buffer = new Uint8Array(await response.arrayBuffer());
|
|
701
|
+
if (buffer.byteLength > maxBytes) throw tooLarge();
|
|
702
|
+
return buffer;
|
|
703
|
+
}
|
|
704
|
+
const reader = response.body.getReader();
|
|
705
|
+
const chunks = [];
|
|
706
|
+
let total = 0;
|
|
707
|
+
for (;;) {
|
|
708
|
+
const { done, value } = await reader.read();
|
|
709
|
+
if (done) break;
|
|
710
|
+
total += value.byteLength;
|
|
711
|
+
if (total > maxBytes) {
|
|
712
|
+
await reader.cancel();
|
|
713
|
+
throw tooLarge();
|
|
714
|
+
}
|
|
715
|
+
chunks.push(value);
|
|
716
|
+
}
|
|
717
|
+
const bytes = new Uint8Array(total);
|
|
718
|
+
let offset = 0;
|
|
719
|
+
for (const chunk of chunks) {
|
|
720
|
+
bytes.set(chunk, offset);
|
|
721
|
+
offset += chunk.byteLength;
|
|
722
|
+
}
|
|
723
|
+
return bytes;
|
|
724
|
+
}
|
|
725
|
+
requireActor(actor) {
|
|
726
|
+
if (!actor.actorId?.trim() || !actor.workspaceId?.trim()) throw new FilesClientError("MISSING_CONTEXT", "File operations need an authenticated actor and a workspace");
|
|
727
|
+
if (actor.actorType !== void 0 && !FILE_ACTOR_TYPES.includes(actor.actorType)) throw new FilesClientError("MISSING_CONTEXT", `Unknown actor type "${String(actor.actorType)}"`);
|
|
728
|
+
return actor;
|
|
729
|
+
}
|
|
730
|
+
getClient() {
|
|
731
|
+
if (!this.clientPromise) {
|
|
732
|
+
const option = this.clientOption;
|
|
733
|
+
this.clientPromise = (async () => {
|
|
734
|
+
try {
|
|
735
|
+
if (typeof option === "function") return await option();
|
|
736
|
+
if (option) return option;
|
|
737
|
+
const gateway = await import("./client-DcZ3iGES.js").then((n) => n.n);
|
|
738
|
+
if (this.serviceName) return new gateway.GatewayClient({
|
|
739
|
+
layer: "wspace",
|
|
740
|
+
serviceName: this.serviceName,
|
|
741
|
+
serviceIdentity: this.serviceName
|
|
742
|
+
});
|
|
743
|
+
return gateway.createGatewayClientFromEnv();
|
|
744
|
+
} catch (error) {
|
|
745
|
+
throw new FilesClientError("CONFIGURATION_ERROR", "Files gateway client is not configured", { cause: error instanceof Error ? error.message : String(error) });
|
|
746
|
+
}
|
|
747
|
+
})();
|
|
748
|
+
this.clientPromise.catch(() => {
|
|
749
|
+
this.clientPromise = null;
|
|
750
|
+
});
|
|
751
|
+
}
|
|
752
|
+
return this.clientPromise;
|
|
753
|
+
}
|
|
754
|
+
async request(operation, query, variables, actor) {
|
|
755
|
+
const { actorId, workspaceId, actorType } = this.requireActor(actor);
|
|
756
|
+
const client = await this.getClient();
|
|
757
|
+
let response;
|
|
758
|
+
try {
|
|
759
|
+
response = await client.internalQuery({
|
|
760
|
+
query,
|
|
761
|
+
variables,
|
|
762
|
+
timeout: this.requestTimeoutMs,
|
|
763
|
+
headers: {
|
|
764
|
+
"x-actor-id": actorId,
|
|
765
|
+
"x-actor-type": actorType ?? "user",
|
|
766
|
+
"x-workspace-id": workspaceId
|
|
767
|
+
}
|
|
768
|
+
});
|
|
769
|
+
} catch (error) {
|
|
770
|
+
throw toFilesClientError(error, operation);
|
|
771
|
+
}
|
|
772
|
+
if (response.errors?.length) throw new FilesClientError(classifyFilesErrors(response.errors), `wspace-files-svc ${operation} failed`, {
|
|
773
|
+
operation,
|
|
774
|
+
errors: response.errors.map((error) => ({
|
|
775
|
+
message: error.message,
|
|
776
|
+
code: error.extensions?.["code"] ?? null
|
|
777
|
+
}))
|
|
778
|
+
});
|
|
779
|
+
if (!response.data) throw new FilesClientError("UPSTREAM_ERROR", `wspace-files-svc ${operation} returned no data`, { operation });
|
|
780
|
+
return response.data;
|
|
781
|
+
}
|
|
782
|
+
};
|
|
783
|
+
|
|
784
|
+
// src/files/reference.ts
|
|
785
|
+
/** Discriminator value of {@link FileReference.kind}. */
|
|
786
|
+
const FILE_REFERENCE_KIND = "burdenoff.file";
|
|
787
|
+
/** Build a {@link FileReference} from an upload result or file metadata. */
|
|
788
|
+
function toFileReference(file) {
|
|
789
|
+
return {
|
|
790
|
+
kind: FILE_REFERENCE_KIND,
|
|
791
|
+
fileId: "fileId" in file ? file.fileId : file.id,
|
|
792
|
+
name: file.name,
|
|
793
|
+
mimeType: file.mimeType,
|
|
794
|
+
size: file.size,
|
|
795
|
+
sha256Hash: file.sha256Hash
|
|
796
|
+
};
|
|
797
|
+
}
|
|
798
|
+
function isRecord(value) {
|
|
799
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
800
|
+
}
|
|
801
|
+
/** Type guard for a {@link FileReference} read back from JSON (node output, DB column, …). */
|
|
802
|
+
function isFileReference(value) {
|
|
803
|
+
if (!isRecord(value)) return false;
|
|
804
|
+
const size = value["size"];
|
|
805
|
+
const sha256Hash = value["sha256Hash"];
|
|
806
|
+
return value["kind"] === "burdenoff.file" && typeof value["fileId"] === "string" && value["fileId"].length > 0 && typeof value["name"] === "string" && typeof value["mimeType"] === "string" && typeof size === "number" && Number.isSafeInteger(size) && size >= 0 && (sha256Hash === null || sha256Hash === void 0 || typeof sha256Hash === "string");
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
// src/files/index.ts
|
|
810
|
+
var files_exports = /* @__PURE__ */ __exportAll({
|
|
811
|
+
FILES_CLIENT_GRAPHQL_CODES: () => FILES_CLIENT_GRAPHQL_CODES,
|
|
812
|
+
FILE_ACTOR_TYPES: () => FILE_ACTOR_TYPES,
|
|
813
|
+
FILE_REFERENCE_KIND: () => FILE_REFERENCE_KIND,
|
|
814
|
+
FILE_VISIBILITIES: () => FILE_VISIBILITIES,
|
|
815
|
+
FilesClient: () => FilesClient,
|
|
816
|
+
FilesClientError: () => FilesClientError,
|
|
817
|
+
MAX_DOWNLOAD_URL_TTL_SECONDS: () => MAX_DOWNLOAD_URL_TTL_SECONDS,
|
|
818
|
+
MIN_DOWNLOAD_URL_TTL_SECONDS: () => 60,
|
|
819
|
+
clampDownloadUrlTtl: () => clampDownloadUrlTtl,
|
|
820
|
+
classifyFilesErrors: () => classifyFilesErrors,
|
|
821
|
+
fileExtensionOf: () => fileExtensionOf,
|
|
822
|
+
isFileReference: () => isFileReference,
|
|
823
|
+
isFilesClientError: () => isFilesClientError,
|
|
824
|
+
mapFileMetadata: () => mapFileMetadata,
|
|
825
|
+
toFileReference: () => toFileReference,
|
|
826
|
+
toFilesClientError: () => toFilesClientError
|
|
827
|
+
});
|
|
828
|
+
|
|
829
|
+
export { FILE_VISIBILITIES as _, FilesClient as a, clampDownloadUrlTtl as c, FILES_CLIENT_GRAPHQL_CODES as d, FilesClientError as f, FILE_ACTOR_TYPES as g, toFilesClientError as h, toFileReference as i, fileExtensionOf as l, isFilesClientError as m, FILE_REFERENCE_KIND as n, MAX_DOWNLOAD_URL_TTL_SECONDS as o, classifyFilesErrors as p, isFileReference as r, MIN_DOWNLOAD_URL_TTL_SECONDS as s, files_exports as t, mapFileMetadata as u };
|
|
830
|
+
//# sourceMappingURL=files-DjH0099H.js.map
|