@ultrst-armada/kloks 2.0.4 → 2.1.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 (143) hide show
  1. package/package.json +76 -1
  2. package/packages/backend/dist/api/index.js +2 -1
  3. package/packages/backend/dist/chunk-23LS4LWC.js +746 -0
  4. package/packages/backend/dist/chunk-3UZFKB4M.js +28 -0
  5. package/packages/backend/dist/chunk-5GW5PJWQ.js +96 -0
  6. package/packages/backend/dist/chunk-5SXOQAAX.js +41 -0
  7. package/packages/backend/dist/chunk-5UVJDX7Q.js +44 -0
  8. package/packages/backend/dist/{chunk-5F5V7NAG.js → chunk-5Y7K7HAT.js} +4 -1
  9. package/packages/backend/dist/chunk-6BL5DXFZ.js +43 -0
  10. package/packages/backend/dist/{chunk-OXEP3AP6.js → chunk-6I7I4C6H.js} +158 -1
  11. package/packages/backend/dist/{chunk-SQKG3S6P.js → chunk-AUNIGE6Q.js} +2 -2
  12. package/packages/backend/dist/{chunk-NY2SQOXI.js → chunk-CDRHYO44.js} +4 -1
  13. package/packages/backend/dist/{chunk-ZBNSK26X.js → chunk-CV55JMT7.js} +6 -5
  14. package/packages/backend/dist/{chunk-KPLDYX5Z.js → chunk-DJ457D5D.js} +33 -26
  15. package/packages/backend/dist/{chunk-FK3OAUXM.js → chunk-DTPCWHQJ.js} +4 -2
  16. package/packages/backend/dist/{chunk-OWMQLML7.js → chunk-EMSSTOOK.js} +33 -2
  17. package/packages/backend/dist/{chunk-Z6G32NQQ.js → chunk-ENMIBY2V.js} +12 -9
  18. package/packages/backend/dist/chunk-EQFZX3JT.js +63 -0
  19. package/packages/backend/dist/chunk-FKK23J2A.js +363 -0
  20. package/packages/backend/dist/chunk-GTKW4IGC.js +197 -0
  21. package/packages/backend/dist/chunk-GVMVYC6C.js +0 -0
  22. package/packages/backend/dist/chunk-HRJCGJTR.js +261 -0
  23. package/packages/backend/dist/chunk-I6T64MLT.js +171 -0
  24. package/packages/backend/dist/chunk-IKDYKRVH.js +51 -0
  25. package/packages/backend/dist/chunk-IP6XWQU2.js +48 -0
  26. package/packages/backend/dist/chunk-JGR6BJVX.js +74 -0
  27. package/packages/backend/dist/{chunk-POLVHTHJ.js → chunk-KCPQWJBO.js} +4 -1
  28. package/packages/backend/dist/chunk-LC6ULEM2.js +125 -0
  29. package/packages/backend/dist/{chunk-NTKUQVCQ.js → chunk-LMUMMVTU.js} +14 -2
  30. package/packages/backend/dist/chunk-LMY6MGFD.js +78 -0
  31. package/packages/backend/dist/chunk-NFK6YFTA.js +157 -0
  32. package/packages/backend/dist/chunk-NZWCPJDJ.js +82 -0
  33. package/packages/backend/dist/chunk-OT2PSPBK.js +74 -0
  34. package/packages/backend/dist/chunk-QYWVZBI6.js +54 -0
  35. package/packages/backend/dist/chunk-TOLAWKAY.js +1132 -0
  36. package/packages/backend/dist/{chunk-OQRQCDS6.js → chunk-TRJVVNO7.js} +2 -2
  37. package/packages/backend/dist/chunk-U7T65YUP.js +889 -0
  38. package/packages/backend/dist/chunk-YFMHT77Z.js +58 -0
  39. package/packages/backend/dist/client-JXGCPWEA.js +7 -0
  40. package/packages/backend/dist/control-plane/index.js +3 -1
  41. package/packages/backend/dist/core/b2DirectCore.test.d.ts +1 -0
  42. package/packages/backend/dist/core/cloudflareIntegrationCore.test.d.ts +1 -0
  43. package/packages/backend/dist/core/googleDriveOAuthCore.d.ts +51 -0
  44. package/packages/backend/dist/core/googleDriveOAuthCore.test.d.ts +1 -0
  45. package/packages/backend/dist/core/index.d.ts +3 -0
  46. package/packages/backend/dist/core/storageConnectionCore.d.ts +136 -0
  47. package/packages/backend/dist/core/storageConnectionCore.test.d.ts +1 -0
  48. package/packages/backend/dist/core/storageConnectionRuntimeCore.d.ts +57 -0
  49. package/packages/backend/dist/core/storageConnectionRuntimeCore.test.d.ts +1 -0
  50. package/packages/backend/dist/core/storageContracts.d.ts +77 -0
  51. package/packages/backend/dist/core/storageProviderRegistry.d.ts +7 -0
  52. package/packages/backend/dist/core/systemCredentialsCore.d.ts +46 -0
  53. package/packages/backend/dist/core/unifiedDb.d.ts +12 -2
  54. package/packages/backend/dist/core/unifiedDb.errors.test.d.ts +1 -0
  55. package/packages/backend/dist/core/unifiedDbNodeAdapter.d.ts +6 -0
  56. package/packages/backend/dist/core/workspaceBucketSyncCore.d.ts +3 -4
  57. package/packages/backend/dist/core/workspaceBucketSyncCore.test.d.ts +1 -0
  58. package/packages/backend/dist/core/workspaceCore.d.ts +25 -6
  59. package/packages/backend/dist/core/workspaceDataCore.test.d.ts +1 -0
  60. package/packages/backend/dist/core/workspaceFileCore.d.ts +25 -7
  61. package/packages/backend/dist/core/workspaceFileCore.test.d.ts +1 -0
  62. package/packages/backend/dist/core/workspaceFileNodeAdapter.d.ts +6 -0
  63. package/packages/backend/dist/core/workspaceStorageDetailsCore.d.ts +4 -8
  64. package/packages/backend/dist/core/workspaceStorageDetailsCore.test.d.ts +1 -0
  65. package/packages/backend/dist/development/index.js +1 -1
  66. package/packages/backend/dist/development/playwrightInspectionService.js +1 -1
  67. package/packages/backend/dist/development/playwrightInspectionSupport.d.ts +1 -0
  68. package/packages/backend/dist/index.d.ts +1 -0
  69. package/packages/backend/dist/index.js +130 -15
  70. package/packages/backend/dist/krnl-services.d.ts +0 -22
  71. package/packages/backend/dist/krnl-services.js +8 -19
  72. package/packages/backend/dist/krnl-services.node.d.ts +28 -0
  73. package/packages/backend/dist/node.d.ts +4 -0
  74. package/packages/backend/dist/node.js +670 -454
  75. package/packages/backend/dist/provider-services/capacity.d.ts +2 -0
  76. package/packages/backend/dist/provider-services/client.d.ts +18 -0
  77. package/packages/backend/dist/provider-services/cloudflare.d.ts +6 -0
  78. package/packages/backend/dist/provider-services/facades.d.ts +44 -0
  79. package/packages/backend/dist/provider-services/gemini.d.ts +8 -0
  80. package/packages/backend/dist/provider-services/google/cloud-run.d.ts +1 -0
  81. package/packages/backend/dist/provider-services/google/cloud-run.js +9 -0
  82. package/packages/backend/dist/provider-services/google/cloud-shell.d.ts +1 -0
  83. package/packages/backend/dist/provider-services/google/cloud-shell.js +9 -0
  84. package/packages/backend/dist/provider-services/google/cloud-storage.d.ts +1 -0
  85. package/packages/backend/dist/provider-services/google/cloud-storage.js +9 -0
  86. package/packages/backend/dist/provider-services/google/drive.d.ts +4 -0
  87. package/packages/backend/dist/provider-services/google/drive.js +20 -0
  88. package/packages/backend/dist/provider-services/google/gemini.d.ts +2 -0
  89. package/packages/backend/dist/provider-services/google/gemini.js +10 -0
  90. package/packages/backend/dist/provider-services/google/index.d.ts +3 -0
  91. package/packages/backend/dist/provider-services/google/index.js +17 -0
  92. package/packages/backend/dist/provider-services/google/vertex-ai.d.ts +1 -0
  93. package/packages/backend/dist/provider-services/google/vertex-ai.js +9 -0
  94. package/packages/backend/dist/provider-services/index.d.ts +11 -0
  95. package/packages/backend/dist/provider-services/index.js +118 -0
  96. package/packages/backend/dist/provider-services/node.d.ts +4 -0
  97. package/packages/backend/dist/provider-services/node.js +40 -0
  98. package/packages/backend/dist/provider-services/operations.d.ts +28 -0
  99. package/packages/backend/dist/provider-services/operations.test.d.ts +1 -0
  100. package/packages/backend/dist/provider-services/provider-services.test.d.ts +1 -0
  101. package/packages/backend/dist/provider-services/registry.d.ts +16 -0
  102. package/packages/backend/dist/provider-services/storage/backblaze-b2.d.ts +7 -0
  103. package/packages/backend/dist/provider-services/storage/backblaze-b2.js +8 -0
  104. package/packages/backend/dist/provider-services/storage/contract.d.ts +45 -0
  105. package/packages/backend/dist/provider-services/storage/dropbox.d.ts +3 -0
  106. package/packages/backend/dist/provider-services/storage/dropbox.js +12 -0
  107. package/packages/backend/dist/provider-services/storage/github.d.ts +4 -0
  108. package/packages/backend/dist/provider-services/storage/github.js +12 -0
  109. package/packages/backend/dist/provider-services/storage/google-drive.d.ts +4 -0
  110. package/packages/backend/dist/provider-services/storage/index.d.ts +7 -0
  111. package/packages/backend/dist/provider-services/storage/node.d.ts +2 -0
  112. package/packages/backend/dist/provider-services/storage/node.js +17 -0
  113. package/packages/backend/dist/provider-services/storage/service.d.ts +27 -0
  114. package/packages/backend/dist/provider-services/storage/storage-contract.test.d.ts +1 -0
  115. package/packages/backend/dist/provider-services/storage-facades.d.ts +55 -0
  116. package/packages/backend/dist/provider-services/storage-node.d.ts +11 -0
  117. package/packages/backend/dist/provider-services/storage-providers.d.ts +30 -0
  118. package/packages/backend/dist/provider-services/storage-providers.test.d.ts +1 -0
  119. package/packages/backend/dist/provider-services/storage.d.ts +3 -0
  120. package/packages/backend/dist/provider-services/storage.js +29 -0
  121. package/packages/backend/dist/provider-services/types.d.ts +61 -0
  122. package/packages/backend/dist/provider-services/vercel.d.ts +13 -0
  123. package/packages/backend/dist/resolver/index.js +13 -0
  124. package/packages/backend/dist/resolver/systemDatabaseUrl.d.ts +16 -12
  125. package/packages/backend/dist/services/node.js +12 -10
  126. package/packages/backend/dist/srkl/index.js +6 -4
  127. package/packages/backend/dist/storage/B2DirectClient.d.ts +7 -13
  128. package/packages/backend/dist/storage/B2DirectClient.test.d.ts +1 -0
  129. package/packages/backend/dist/storage/GoogleDriveWorkspaceService.d.ts +5 -0
  130. package/packages/backend/dist/storage/index.js +4 -3
  131. package/packages/backend/dist/storage/node.js +7 -6
  132. package/packages/backend/dist/storage-workspace.js +1 -1
  133. package/packages/backend/dist/workspace/index.js +2 -1
  134. package/packages/backend/dist/workspace/node.js +12 -7
  135. package/packages/backend/dist/workspaceFileCore-RQO7YMRD.js +28 -0
  136. package/packages/backend/package.json +78 -3
  137. package/packages/services/dist/index.js +8 -2
  138. package/packages/backend/dist/chunk-4QEMALXF.js +0 -90
  139. package/packages/backend/dist/chunk-AOZSDRNY.js +0 -159
  140. package/packages/backend/dist/chunk-GYSZ6CAX.js +0 -19
  141. package/packages/backend/dist/chunk-JCMB7BIM.js +0 -211
  142. package/packages/backend/dist/chunk-JGUWYVOL.js +0 -570
  143. package/packages/backend/dist/chunk-LMOM7CST.js +0 -427
@@ -0,0 +1,261 @@
1
+ import {
2
+ fetchCloudflareCapacity,
3
+ fetchVercelCapacity
4
+ } from "./chunk-NFK6YFTA.js";
5
+ import {
6
+ getGeminiQuotaStatus,
7
+ listGeminiModels
8
+ } from "./chunk-3UZFKB4M.js";
9
+ import {
10
+ getGoogleAccountProfile,
11
+ listCloudflareAccounts,
12
+ listCloudflarePages,
13
+ listCloudflareWorkers,
14
+ listVercelDeployments,
15
+ listVercelProjects
16
+ } from "./chunk-EQFZX3JT.js";
17
+ import {
18
+ continueDropboxFolder,
19
+ listDropboxFolder,
20
+ listGitHubRepositories,
21
+ listGitHubRepositoryContents,
22
+ listGitLabProjects,
23
+ listGitLabRepositoryTree
24
+ } from "./chunk-5GW5PJWQ.js";
25
+ import {
26
+ b2ListBuckets,
27
+ b2ListFileNames
28
+ } from "./chunk-I6T64MLT.js";
29
+ import {
30
+ GoogleDriveWorkspaceService
31
+ } from "./chunk-EMSSTOOK.js";
32
+
33
+ // src/provider-services/facades.ts
34
+ import { createService, createServiceDefinition } from "@ultrst-armada/krnl";
35
+ var defs = {
36
+ cloudflare: createServiceDefinition({
37
+ id: "kloks.external.cloudflare",
38
+ name: "Cloudflare Provider Service",
39
+ version: "1.0.0",
40
+ operations: {
41
+ listAccounts: {
42
+ id: "cloudflare.listAccounts",
43
+ name: "listAccounts",
44
+ handler: (input) => listCloudflareAccounts(input.connection)
45
+ },
46
+ listWorkers: {
47
+ id: "cloudflare.listWorkers",
48
+ name: "listWorkers",
49
+ handler: (input) => listCloudflareWorkers(input.connection)
50
+ },
51
+ listPages: {
52
+ id: "cloudflare.listPages",
53
+ name: "listPages",
54
+ handler: (input) => listCloudflarePages(input.connection)
55
+ },
56
+ quota: {
57
+ id: "cloudflare.quota",
58
+ name: "quota",
59
+ handler: (input) => fetchCloudflareCapacity(input.connection, input.plan)
60
+ }
61
+ }
62
+ }),
63
+ vercel: createServiceDefinition({
64
+ id: "kloks.external.vercel",
65
+ name: "Vercel Provider Service",
66
+ version: "1.0.0",
67
+ operations: {
68
+ listProjects: {
69
+ id: "vercel.listProjects",
70
+ name: "listProjects",
71
+ handler: (input) => listVercelProjects(input.connection)
72
+ },
73
+ listDeployments: {
74
+ id: "vercel.listDeployments",
75
+ name: "listDeployments",
76
+ handler: (input) => listVercelDeployments(input.connection)
77
+ },
78
+ quota: {
79
+ id: "vercel.quota",
80
+ name: "quota",
81
+ handler: (input) => fetchVercelCapacity(input.connection, input.options)
82
+ }
83
+ }
84
+ }),
85
+ google: createServiceDefinition({
86
+ id: "kloks.external.google",
87
+ name: "Google Account Service",
88
+ version: "1.0.0",
89
+ operations: {
90
+ profile: {
91
+ id: "google.profile",
92
+ name: "profile",
93
+ handler: (input) => getGoogleAccountProfile(input.connection)
94
+ }
95
+ }
96
+ }),
97
+ gemini: createServiceDefinition({
98
+ id: "kloks.external.google.gemini",
99
+ name: "Google Gemini Service",
100
+ version: "1.0.0",
101
+ operations: {
102
+ listModels: {
103
+ id: "gemini.listModels",
104
+ name: "listModels",
105
+ handler: (input) => listGeminiModels(input.connection)
106
+ },
107
+ quota: {
108
+ id: "gemini.quota",
109
+ name: "quota",
110
+ handler: (input) => getGeminiQuotaStatus(input.connection.accountId)
111
+ }
112
+ }
113
+ })
114
+ };
115
+ function facade(definition) {
116
+ const instance = createService(definition);
117
+ return {
118
+ id: definition.id,
119
+ name: definition.name,
120
+ version: definition.version,
121
+ runtime: "server",
122
+ deployment: "local",
123
+ definition,
124
+ get telemetry() {
125
+ return instance.telemetry;
126
+ },
127
+ createInstance: () => createService(definition),
128
+ execute: async (operation, input) => {
129
+ await instance.start();
130
+ return instance.call(operation, input);
131
+ }
132
+ };
133
+ }
134
+ var CloudflareProviderService = facade(defs.cloudflare);
135
+ var VercelProviderService = facade(defs.vercel);
136
+ var GoogleAccountProviderService = facade(defs.google);
137
+ var GeminiProviderService = facade(defs.gemini);
138
+
139
+ // src/provider-services/storage-facades.ts
140
+ import { createService as createService2, createServiceDefinition as createServiceDefinition2 } from "@ultrst-armada/krnl";
141
+ var github = createServiceDefinition2({
142
+ id: "kloks.external.github",
143
+ name: "GitHub Provider Service",
144
+ version: "1.0.0",
145
+ operations: {
146
+ listRepositories: {
147
+ id: "github.listRepositories",
148
+ name: "listRepositories",
149
+ handler: ({ connection }) => listGitHubRepositories(connection)
150
+ },
151
+ listContents: {
152
+ id: "github.listContents",
153
+ name: "listContents",
154
+ handler: (input) => listGitHubRepositoryContents(input.connection, input.owner, input.repo, input.path)
155
+ }
156
+ }
157
+ });
158
+ var gitlab = createServiceDefinition2({
159
+ id: "kloks.external.gitlab",
160
+ name: "GitLab Provider Service",
161
+ version: "1.0.0",
162
+ operations: {
163
+ listProjects: {
164
+ id: "gitlab.listProjects",
165
+ name: "listProjects",
166
+ handler: ({ connection }) => listGitLabProjects(connection)
167
+ },
168
+ listTree: {
169
+ id: "gitlab.listTree",
170
+ name: "listTree",
171
+ handler: (input) => listGitLabRepositoryTree(input.connection, input.project, input.path)
172
+ }
173
+ }
174
+ });
175
+ var dropbox = createServiceDefinition2({
176
+ id: "kloks.external.dropbox",
177
+ name: "Dropbox Provider Service",
178
+ version: "1.0.0",
179
+ operations: {
180
+ listFolder: {
181
+ id: "dropbox.listFolder",
182
+ name: "listFolder",
183
+ handler: (input) => listDropboxFolder(input.connection, input.path)
184
+ },
185
+ continueFolder: {
186
+ id: "dropbox.continueFolder",
187
+ name: "continueFolder",
188
+ handler: (input) => continueDropboxFolder(input.connection, input.cursor)
189
+ }
190
+ }
191
+ });
192
+ var backblaze = createServiceDefinition2({
193
+ id: "kloks.external.backblaze-b2",
194
+ name: "Backblaze B2 Provider Service",
195
+ version: "1.0.0",
196
+ operations: {
197
+ listBuckets: {
198
+ id: "backblaze.listBuckets",
199
+ name: "listBuckets",
200
+ handler: (input) => b2ListBuckets(input.keyId, input.applicationKey)
201
+ },
202
+ listFiles: {
203
+ id: "backblaze.listFiles",
204
+ name: "listFiles",
205
+ handler: (input) => b2ListFileNames(input.keyId, input.applicationKey, input.bucketName)
206
+ }
207
+ }
208
+ });
209
+ var drive = createServiceDefinition2({
210
+ id: "kloks.external.google.drive",
211
+ name: "Google Drive Provider Service",
212
+ version: "1.0.0",
213
+ operations: {
214
+ listFolders: {
215
+ id: "google.drive.listFolders",
216
+ name: "listFolders",
217
+ handler: (input) => new GoogleDriveWorkspaceService(input.options).listFolders(input.parentFolderId)
218
+ },
219
+ listFiles: {
220
+ id: "google.drive.listFiles",
221
+ name: "listFiles",
222
+ handler: (input) => new GoogleDriveWorkspaceService(input.options).list(input.path)
223
+ }
224
+ }
225
+ });
226
+ function serviceFacade(definition) {
227
+ const instance = createService2(definition);
228
+ return {
229
+ id: definition.id,
230
+ name: definition.name,
231
+ version: definition.version,
232
+ runtime: "server",
233
+ deployment: "local",
234
+ definition,
235
+ get telemetry() {
236
+ return instance.telemetry;
237
+ },
238
+ createInstance: () => createService2(definition),
239
+ execute: async (operation, input) => {
240
+ await instance.start();
241
+ return instance.call(operation, input);
242
+ }
243
+ };
244
+ }
245
+ var GitHubProviderService = serviceFacade(github);
246
+ var GitLabProviderService = serviceFacade(gitlab);
247
+ var DropboxProviderService = serviceFacade(dropbox);
248
+ var BackblazeB2ProviderService = serviceFacade(backblaze);
249
+ var GoogleDriveProviderService = serviceFacade(drive);
250
+
251
+ export {
252
+ CloudflareProviderService,
253
+ VercelProviderService,
254
+ GoogleAccountProviderService,
255
+ GeminiProviderService,
256
+ GitHubProviderService,
257
+ GitLabProviderService,
258
+ DropboxProviderService,
259
+ BackblazeB2ProviderService,
260
+ GoogleDriveProviderService
261
+ };
@@ -0,0 +1,171 @@
1
+ // src/core/b2DirectCore.ts
2
+ var authCache = /* @__PURE__ */ new Map();
3
+ var bucketIdCache = /* @__PURE__ */ new Map();
4
+ async function authorizeB2(keyId, applicationKey) {
5
+ const normalizedKeyId = keyId.trim();
6
+ const normalizedApplicationKey = applicationKey.trim();
7
+ if (!normalizedKeyId || !normalizedApplicationKey) {
8
+ throw new Error("B2 credentials are required.");
9
+ }
10
+ const cacheKey = `${normalizedKeyId}:${normalizedApplicationKey}`;
11
+ const cached = authCache.get(cacheKey);
12
+ if (cached && Date.now() < cached.expiresAt) return cached.auth;
13
+ const authHeader = btoa(`${normalizedKeyId}:${normalizedApplicationKey}`);
14
+ let res;
15
+ try {
16
+ res = await fetch("https://api.backblazeb2.com/b2api/v2/b2_authorize_account", {
17
+ headers: { Authorization: `Basic ${authHeader}` },
18
+ signal: AbortSignal.timeout(1e4)
19
+ });
20
+ if (!res.ok) {
21
+ res = await fetch("https://api.backblazeb2.com/b2api/v4/b2_authorize_account", {
22
+ headers: { Authorization: `Basic ${authHeader}` },
23
+ signal: AbortSignal.timeout(1e4)
24
+ });
25
+ }
26
+ } catch {
27
+ throw new Error("Backblaze B2 authorization failed before receiving a response.");
28
+ }
29
+ if (!res.ok) throw new Error(`Backblaze B2 authorization failed with HTTP ${res.status}.`);
30
+ const data = await res.json();
31
+ const apiUrl = data.apiInfo?.storageApi?.apiUrl || data.apiUrl;
32
+ const downloadUrl = data.apiInfo?.storageApi?.downloadUrl || data.downloadUrl || apiUrl;
33
+ if (typeof data.accountId !== "string" || !data.accountId || typeof data.authorizationToken !== "string" || !data.authorizationToken || typeof apiUrl !== "string" || typeof downloadUrl !== "string") {
34
+ throw new Error("Backblaze B2 authorization returned an invalid response.");
35
+ }
36
+ const auth = {
37
+ accountId: data.accountId,
38
+ authorizationToken: data.authorizationToken,
39
+ apiUrl: apiUrl.replace(/\/+$/, ""),
40
+ downloadUrl: downloadUrl.replace(/\/+$/, ""),
41
+ s3ApiUrl: data.apiInfo?.storageApi?.s3ApiUrl || data.s3ApiUrl,
42
+ allowed: data.apiInfo?.storageApi?.allowed || data.allowed
43
+ };
44
+ authCache.set(cacheKey, { auth, expiresAt: Date.now() + 20 * 60 * 1e3 });
45
+ return auth;
46
+ }
47
+ async function b2ListBuckets(keyId, applicationKey, bucketId, bucketName) {
48
+ const auth = await authorizeB2(keyId, applicationKey);
49
+ const allowed = auth.allowed;
50
+ if (allowed?.bucketId || allowed?.bucketName || Array.isArray(allowed?.buckets)) {
51
+ const candidates = Array.isArray(allowed.buckets) ? allowed.buckets : allowed.bucketId && allowed.bucketName ? [{ bucketId: allowed.bucketId, bucketName: allowed.bucketName }] : [];
52
+ return candidates.filter(
53
+ (bucket) => (!bucketId || bucket.bucketId === bucketId) && (!bucketName || bucket.bucketName === bucketName) && typeof bucket.bucketId === "string" && Boolean(bucket.bucketId) && typeof bucket.bucketName === "string" && Boolean(bucket.bucketName)
54
+ );
55
+ }
56
+ let response;
57
+ try {
58
+ response = await fetch(`${auth.apiUrl}/b2api/v2/b2_list_buckets`, {
59
+ method: "POST",
60
+ headers: { Authorization: auth.authorizationToken, "Content-Type": "application/json" },
61
+ body: JSON.stringify({ accountId: auth.accountId }),
62
+ signal: AbortSignal.timeout(8e3)
63
+ });
64
+ } catch {
65
+ throw new Error("Backblaze B2 bucket discovery failed before receiving a response.");
66
+ }
67
+ if (!response.ok) {
68
+ throw new Error(`Backblaze B2 bucket discovery failed with HTTP ${response.status}.`);
69
+ }
70
+ const data = await response.json();
71
+ if (!Array.isArray(data.buckets)) {
72
+ throw new Error("Backblaze B2 bucket discovery returned an invalid response.");
73
+ }
74
+ return data.buckets;
75
+ }
76
+ async function getB2BucketId(keyId, applicationKey, bucketName) {
77
+ const cacheKey = `${keyId.trim()}:${applicationKey.trim()}:${bucketName.trim()}`;
78
+ if (bucketIdCache.has(cacheKey)) return bucketIdCache.get(cacheKey);
79
+ const buckets = await b2ListBuckets(keyId, applicationKey, void 0, bucketName);
80
+ const match = buckets.find((b) => b.bucketName === bucketName);
81
+ if (!match) throw new Error(`B2 bucket "${bucketName}" not found in account`);
82
+ bucketIdCache.set(cacheKey, match.bucketId);
83
+ return match.bucketId;
84
+ }
85
+ async function b2UploadFile(keyId, applicationKey, bucketName, fileName, buffer, contentType = "b2/x-auto") {
86
+ const auth = await authorizeB2(keyId, applicationKey);
87
+ const bucketId = await getB2BucketId(keyId, applicationKey, bucketName);
88
+ const urlRes = await fetch(`${auth.apiUrl}/b2api/v2/b2_get_upload_url`, {
89
+ method: "POST",
90
+ headers: { Authorization: auth.authorizationToken, "Content-Type": "application/json" },
91
+ body: JSON.stringify({ bucketId })
92
+ });
93
+ if (!urlRes.ok) throw new Error(`B2 upload URL request failed with HTTP ${urlRes.status}.`);
94
+ const { uploadUrl, authorizationToken } = await urlRes.json();
95
+ const bytes = new Uint8Array(buffer.byteLength);
96
+ bytes.set(buffer);
97
+ const digest = await crypto.subtle.digest("SHA-1", bytes);
98
+ const sha1 = Array.from(new Uint8Array(digest)).map((byte) => byte.toString(16).padStart(2, "0")).join("");
99
+ const encodedFileName = encodeURIComponent(fileName).replace(/%2F/g, "/");
100
+ const uploadRes = await fetch(uploadUrl, {
101
+ method: "POST",
102
+ headers: {
103
+ Authorization: authorizationToken,
104
+ "X-Bz-File-Name": encodedFileName,
105
+ "Content-Type": contentType,
106
+ "X-Bz-Content-Sha1": sha1
107
+ },
108
+ body: bytes
109
+ });
110
+ if (!uploadRes.ok) throw new Error(`B2 upload failed with HTTP ${uploadRes.status}.`);
111
+ return uploadRes.json();
112
+ }
113
+ async function b2DownloadFile(keyId, applicationKey, bucketName, fileName) {
114
+ const auth = await authorizeB2(keyId, applicationKey);
115
+ const encodedName = encodeURIComponent(fileName).replace(/%2F/g, "/");
116
+ const res = await fetch(`${auth.downloadUrl}/file/${bucketName}/${encodedName}`, { headers: { Authorization: auth.authorizationToken } });
117
+ if (res.status === 404) return null;
118
+ if (!res.ok) throw new Error(`B2 file download failed with HTTP ${res.status}.`);
119
+ return new Uint8Array(await res.arrayBuffer());
120
+ }
121
+ async function b2ListFileNames(keyId, applicationKey, bucketName, prefix = "") {
122
+ const auth = await authorizeB2(keyId, applicationKey);
123
+ const bucketId = await getB2BucketId(keyId, applicationKey, bucketName);
124
+ const res = await fetch(`${auth.apiUrl}/b2api/v2/b2_list_file_names`, {
125
+ method: "POST",
126
+ headers: { Authorization: auth.authorizationToken, "Content-Type": "application/json" },
127
+ body: JSON.stringify({ bucketId, prefix, maxFileCount: 1e3 })
128
+ });
129
+ if (!res.ok) throw new Error(`B2 file listing failed with HTTP ${res.status}.`);
130
+ const data = await res.json();
131
+ if (!Array.isArray(data.files)) throw new Error("B2 file listing returned an invalid response.");
132
+ return data.files;
133
+ }
134
+ async function b2DeleteFileVersion(keyId, applicationKey, fileName, fileId) {
135
+ const auth = await authorizeB2(keyId, applicationKey);
136
+ const res = await fetch(`${auth.apiUrl}/b2api/v2/b2_delete_file_version`, {
137
+ method: "POST",
138
+ headers: { Authorization: auth.authorizationToken, "Content-Type": "application/json" },
139
+ body: JSON.stringify({ fileName, fileId })
140
+ });
141
+ if (!res.ok) throw new Error(`B2 delete file version failed (${res.status})`);
142
+ return res.json();
143
+ }
144
+ async function b2DeleteFolder(keyId, applicationKey, bucketName, folderPrefix) {
145
+ const cleanPrefix = folderPrefix.replace(/\/+$/, "") + "/";
146
+ const files = await b2ListFileNames(keyId, applicationKey, bucketName, cleanPrefix);
147
+ let deletedCount = 0;
148
+ for (const file of files) {
149
+ await b2DeleteFileVersion(keyId, applicationKey, file.fileName, file.fileId);
150
+ deletedCount++;
151
+ }
152
+ return { success: true, deletedCount };
153
+ }
154
+
155
+ // src/storage/B2DirectClient.ts
156
+ function b2UploadFile2(keyId, applicationKey, bucketName, fileName, content, contentType = "application/json") {
157
+ const bytes = typeof content === "string" ? new TextEncoder().encode(content) : content;
158
+ return b2UploadFile(keyId, applicationKey, bucketName, fileName, bytes, contentType);
159
+ }
160
+
161
+ export {
162
+ authorizeB2,
163
+ b2ListBuckets,
164
+ getB2BucketId,
165
+ b2UploadFile,
166
+ b2DownloadFile,
167
+ b2ListFileNames,
168
+ b2DeleteFileVersion,
169
+ b2DeleteFolder,
170
+ b2UploadFile2
171
+ };
@@ -0,0 +1,51 @@
1
+ import {
2
+ createDropboxStorageService
3
+ } from "./chunk-OT2PSPBK.js";
4
+ import {
5
+ createGitHubStorageService
6
+ } from "./chunk-NZWCPJDJ.js";
7
+ import {
8
+ createGoogleDriveStorageService
9
+ } from "./chunk-6BL5DXFZ.js";
10
+ import {
11
+ createBackblazeB2StorageService
12
+ } from "./chunk-JGR6BJVX.js";
13
+
14
+ // src/provider-services/storage/service.ts
15
+ var CONTRACTS = {
16
+ github: { list: true, read: true, write: false, delete: false },
17
+ dropbox: { list: true, read: true, write: true, delete: true },
18
+ "backblaze-b2": { list: true, read: true, write: true, delete: false },
19
+ "google-drive": { list: true, read: true, write: true, delete: true }
20
+ };
21
+ function listCanonicalStorageProviders() {
22
+ return Object.keys(CONTRACTS).map((id) => ({
23
+ id,
24
+ capabilities: Object.freeze({ ...CONTRACTS[id] })
25
+ }));
26
+ }
27
+ function getCanonicalStorageCapabilities(id) {
28
+ if (!Object.prototype.hasOwnProperty.call(CONTRACTS, id))
29
+ throw new Error("Unsupported canonical storage provider");
30
+ return Object.freeze({ ...CONTRACTS[id] });
31
+ }
32
+ function createCanonicalStorageService(config) {
33
+ switch (config.providerId) {
34
+ case "github":
35
+ return createGitHubStorageService(config.connection, config.transport);
36
+ case "dropbox":
37
+ return createDropboxStorageService(config.connection, config.transport);
38
+ case "backblaze-b2":
39
+ return createBackblazeB2StorageService(config.credentials);
40
+ case "google-drive":
41
+ return createGoogleDriveStorageService(config.options);
42
+ default:
43
+ throw new Error("Unsupported canonical storage provider");
44
+ }
45
+ }
46
+
47
+ export {
48
+ listCanonicalStorageProviders,
49
+ getCanonicalStorageCapabilities,
50
+ createCanonicalStorageService
51
+ };
@@ -0,0 +1,48 @@
1
+ // src/resolver/systemDatabaseUrl.ts
2
+ function normalizeUrl(value) {
3
+ if (typeof value !== "string") return "";
4
+ return value.trim().replace(/^["']|["']$/g, "").trim();
5
+ }
6
+ function resolveSystemDatabaseUrlCandidates(env = {}) {
7
+ const urls = [
8
+ normalizeUrl(env.SYSTEM_DATABASE_URL),
9
+ normalizeUrl(env.SYSTEM_DATABASE_URL_2),
10
+ normalizeUrl(env.SYSTEM_DATABASE_URL_3)
11
+ ];
12
+ return [...new Set(urls.filter(Boolean))];
13
+ }
14
+ function tryResolveSystemDatabaseUrl(env = {}) {
15
+ return normalizeUrl(env.SYSTEM_DATABASE_URL) || normalizeUrl(env.SYSTEM_DATABASE_URL_2) || normalizeUrl(env.SYSTEM_DATABASE_URL_3) || null;
16
+ }
17
+ function resolveSystemDatabaseUrl(env = {}) {
18
+ const url = tryResolveSystemDatabaseUrl(env);
19
+ if (url) return url;
20
+ throw new Error(
21
+ "[SKIPO DATABASE_INVARIANT] Missing system database configuration. Set SYSTEM_DATABASE_URL (primary), SYSTEM_DATABASE_URL_2, or SYSTEM_DATABASE_URL_3. DATABASE_URL and SYSTEM_DATABASE_URL_1 are not supported configuration aliases."
22
+ );
23
+ }
24
+ function normalizeSystemEnvironment(env = {}, runtimeEnvironment = {}, requestUrl) {
25
+ const normalized = { ...env };
26
+ for (const key of ["SYSTEM_DATABASE_URL", "SYSTEM_DATABASE_URL_2", "SYSTEM_DATABASE_URL_3"]) {
27
+ const value = normalizeUrl(env[key]) || normalizeUrl(runtimeEnvironment[key]);
28
+ if (value) normalized[key] = value;
29
+ else if (Object.prototype.hasOwnProperty.call(env, key)) normalized[key] = void 0;
30
+ }
31
+ const configuredAppUrl = normalizeUrl(env.APP_URL) || normalizeUrl(runtimeEnvironment.APP_URL);
32
+ if (configuredAppUrl) {
33
+ normalized.APP_URL = configuredAppUrl;
34
+ } else if (requestUrl) {
35
+ try {
36
+ normalized.APP_URL = new URL(requestUrl).origin;
37
+ } catch {
38
+ }
39
+ }
40
+ return normalized;
41
+ }
42
+
43
+ export {
44
+ resolveSystemDatabaseUrlCandidates,
45
+ tryResolveSystemDatabaseUrl,
46
+ resolveSystemDatabaseUrl,
47
+ normalizeSystemEnvironment
48
+ };
@@ -0,0 +1,74 @@
1
+ import {
2
+ UnsupportedStorageOperation,
3
+ normalizeStoragePath
4
+ } from "./chunk-5UVJDX7Q.js";
5
+ import {
6
+ b2DownloadFile,
7
+ b2ListBuckets,
8
+ b2ListFileNames,
9
+ b2UploadFile2 as b2UploadFile
10
+ } from "./chunk-I6T64MLT.js";
11
+
12
+ // src/provider-services/storage/backblaze-b2.ts
13
+ function createBackblazeB2StorageService(creds) {
14
+ if (!creds.keyId?.trim() || !creds.applicationKey?.trim())
15
+ throw new Error("Backblaze application key and key ID required");
16
+ const splitPath = (path) => {
17
+ const [bucket, ...rest] = normalizeStoragePath(path).split("/");
18
+ if (!bucket) throw new Error("Backblaze bucket is required");
19
+ return { bucket, file: rest.join("/") };
20
+ };
21
+ return {
22
+ providerId: "backblaze-b2",
23
+ capabilities: Object.freeze({ list: true, read: true, write: true, delete: false }),
24
+ async list(path = "", cursor) {
25
+ if (cursor) throw new Error("B2 native adapter does not provide continuation tokens");
26
+ if (!normalizeStoragePath(path)) {
27
+ const buckets = await b2ListBuckets(creds.keyId, creds.applicationKey);
28
+ return { entries: buckets.map((b) => ({
29
+ id: b.bucketId,
30
+ name: b.bucketName,
31
+ path: "/" + b.bucketName,
32
+ kind: "bucket"
33
+ })), nextCursor: null, complete: true };
34
+ }
35
+ const { bucket, file } = splitPath(path);
36
+ const items = await b2ListFileNames(creds.keyId, creds.applicationKey, bucket, file);
37
+ if (items.length >= 1e3)
38
+ throw new Error("B2 listing might be truncated; refusing to report an incomplete list");
39
+ return { entries: items.map((item) => ({
40
+ id: item.fileId,
41
+ name: item.fileName.split("/").pop() || item.fileName,
42
+ path: "/" + bucket + "/" + item.fileName,
43
+ kind: "file",
44
+ size: item.contentLength
45
+ })), nextCursor: null, complete: true };
46
+ },
47
+ async read(path) {
48
+ const { bucket, file } = splitPath(path);
49
+ if (!file) throw new Error("Backblaze file path is required");
50
+ const data = await b2DownloadFile(creds.keyId, creds.applicationKey, bucket, file);
51
+ if (!data) throw new Error("Backblaze file not found");
52
+ return data;
53
+ },
54
+ async write(path, data, contentType) {
55
+ const { bucket, file } = splitPath(path);
56
+ if (!file) throw new Error("Backblaze file path is required");
57
+ await b2UploadFile(
58
+ creds.keyId,
59
+ creds.applicationKey,
60
+ bucket,
61
+ file,
62
+ data,
63
+ contentType || "application/octet-stream"
64
+ );
65
+ },
66
+ async delete() {
67
+ throw new UnsupportedStorageOperation("backblaze-b2", "delete");
68
+ }
69
+ };
70
+ }
71
+
72
+ export {
73
+ createBackblazeB2StorageService
74
+ };
@@ -1,5 +1,8 @@
1
+ import {
2
+ SkipoBase
3
+ } from "./chunk-LMY6MGFD.js";
4
+
1
5
  // src/api/BaseApiRoute.ts
2
- import { SkipoBase } from "@ultrst-armada/kloks/functions/base";
3
6
  var BaseApiRoute = class extends SkipoBase {
4
7
  config;
5
8
  constructor(config = {}) {