@tinycloud/operations 0.3.2-beta.2 → 0.3.2-beta.4

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.
@@ -44,19 +44,19 @@ declare const PermissionEntrySchema: z.ZodObject<{
44
44
  path: string;
45
45
  actions: string[];
46
46
  space?: string | undefined;
47
- caveats?: Record<string, unknown>[] | undefined;
48
47
  skipPrefix?: boolean | undefined;
49
48
  expiry?: string | undefined;
50
49
  description?: string | undefined;
50
+ caveats?: Record<string, unknown>[] | undefined;
51
51
  }, {
52
52
  service: string;
53
53
  path: string;
54
54
  actions: string[];
55
55
  space?: string | undefined;
56
- caveats?: Record<string, unknown>[] | undefined;
57
56
  skipPrefix?: boolean | undefined;
58
57
  expiry?: string | undefined;
59
58
  description?: string | undefined;
59
+ caveats?: Record<string, unknown>[] | undefined;
60
60
  }>;
61
61
  declare const LegacyPermissionRequestArtifactSchema: z.ZodObject<{
62
62
  kind: z.ZodLiteral<"tinycloud.auth.request">;
@@ -77,51 +77,51 @@ declare const LegacyPermissionRequestArtifactSchema: z.ZodObject<{
77
77
  path: string;
78
78
  actions: string[];
79
79
  space?: string | undefined;
80
- caveats?: Record<string, unknown>[] | undefined;
81
80
  skipPrefix?: boolean | undefined;
82
81
  expiry?: string | undefined;
83
82
  description?: string | undefined;
83
+ caveats?: Record<string, unknown>[] | undefined;
84
84
  }, {
85
85
  service: string;
86
86
  path: string;
87
87
  actions: string[];
88
88
  space?: string | undefined;
89
- caveats?: Record<string, unknown>[] | undefined;
90
89
  skipPrefix?: boolean | undefined;
91
90
  expiry?: string | undefined;
92
91
  description?: string | undefined;
92
+ caveats?: Record<string, unknown>[] | undefined;
93
93
  }>, "many">;
94
94
  requestedExpiry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
95
95
  }, "strict", z.ZodTypeAny, {
96
- kind: "tinycloud.auth.request";
97
- version: 1;
98
96
  requestId: string;
97
+ kind: "tinycloud.auth.request";
99
98
  sessionDid: string;
99
+ version: 1;
100
100
  requested: {
101
101
  service: string;
102
102
  path: string;
103
103
  actions: string[];
104
104
  space?: string | undefined;
105
- caveats?: Record<string, unknown>[] | undefined;
106
105
  skipPrefix?: boolean | undefined;
107
106
  expiry?: string | undefined;
108
107
  description?: string | undefined;
108
+ caveats?: Record<string, unknown>[] | undefined;
109
109
  }[];
110
110
  requestedExpiry?: string | number | undefined;
111
111
  }, {
112
- kind: "tinycloud.auth.request";
113
- version: 1;
114
112
  requestId: string;
113
+ kind: "tinycloud.auth.request";
115
114
  sessionDid: string;
115
+ version: 1;
116
116
  requested: {
117
117
  service: string;
118
118
  path: string;
119
119
  actions: string[];
120
120
  space?: string | undefined;
121
- caveats?: Record<string, unknown>[] | undefined;
122
121
  skipPrefix?: boolean | undefined;
123
122
  expiry?: string | undefined;
124
123
  description?: string | undefined;
124
+ caveats?: Record<string, unknown>[] | undefined;
125
125
  }[];
126
126
  requestedExpiry?: string | number | undefined;
127
127
  }>;
@@ -153,19 +153,19 @@ declare const PermissionRequestArtifactSchema: z.ZodObject<{
153
153
  path: string;
154
154
  actions: string[];
155
155
  space?: string | undefined;
156
- caveats?: Record<string, unknown>[] | undefined;
157
156
  skipPrefix?: boolean | undefined;
158
157
  expiry?: string | undefined;
159
158
  description?: string | undefined;
159
+ caveats?: Record<string, unknown>[] | undefined;
160
160
  }, {
161
161
  service: string;
162
162
  path: string;
163
163
  actions: string[];
164
164
  space?: string | undefined;
165
- caveats?: Record<string, unknown>[] | undefined;
166
165
  skipPrefix?: boolean | undefined;
167
166
  expiry?: string | undefined;
168
167
  description?: string | undefined;
168
+ caveats?: Record<string, unknown>[] | undefined;
169
169
  }>, "many">;
170
170
  command: z.ZodOptional<z.ZodObject<{
171
171
  argv: z.ZodArray<z.ZodString, "many">;
@@ -178,55 +178,55 @@ declare const PermissionRequestArtifactSchema: z.ZodObject<{
178
178
  cwd: string;
179
179
  }>>;
180
180
  }, "strict", z.ZodTypeAny, {
181
- kind: "tinycloud.auth.request";
182
- version: 1;
181
+ createdAt: string;
183
182
  requestId: string;
183
+ kind: "tinycloud.auth.request";
184
+ operatorType: "human" | "agent";
184
185
  sessionDid: string;
186
+ version: 1;
185
187
  requested: {
186
188
  service: string;
187
189
  path: string;
188
190
  actions: string[];
189
191
  space?: string | undefined;
190
- caveats?: Record<string, unknown>[] | undefined;
191
192
  skipPrefix?: boolean | undefined;
192
193
  expiry?: string | undefined;
193
194
  description?: string | undefined;
195
+ caveats?: Record<string, unknown>[] | undefined;
194
196
  }[];
195
197
  host: string;
196
- createdAt: string;
197
198
  profile: string;
198
199
  posture: "owner-openkey" | "delegate-session" | "local-owner-key" | "unauthenticated";
199
- operatorType: "human" | "agent";
200
+ ownerDid?: string | undefined;
200
201
  requestedExpiry?: string | number | undefined;
201
202
  spaceId?: string | undefined;
202
- ownerDid?: string | undefined;
203
203
  command?: {
204
204
  argv: string[];
205
205
  cwd: string;
206
206
  } | undefined;
207
207
  }, {
208
- kind: "tinycloud.auth.request";
209
- version: 1;
208
+ createdAt: string;
210
209
  requestId: string;
210
+ kind: "tinycloud.auth.request";
211
+ operatorType: "human" | "agent";
211
212
  sessionDid: string;
213
+ version: 1;
212
214
  requested: {
213
215
  service: string;
214
216
  path: string;
215
217
  actions: string[];
216
218
  space?: string | undefined;
217
- caveats?: Record<string, unknown>[] | undefined;
218
219
  skipPrefix?: boolean | undefined;
219
220
  expiry?: string | undefined;
220
221
  description?: string | undefined;
222
+ caveats?: Record<string, unknown>[] | undefined;
221
223
  }[];
222
224
  host: string;
223
- createdAt: string;
224
225
  profile: string;
225
226
  posture: "owner-openkey" | "delegate-session" | "local-owner-key" | "unauthenticated";
226
- operatorType: "human" | "agent";
227
+ ownerDid?: string | undefined;
227
228
  requestedExpiry?: string | number | undefined;
228
229
  spaceId?: string | undefined;
229
- ownerDid?: string | undefined;
230
230
  command?: {
231
231
  argv: string[];
232
232
  cwd: string;
@@ -253,26 +253,26 @@ declare const DelegationImportArtifactSchema: z.ZodObject<{
253
253
  path: string;
254
254
  actions: string[];
255
255
  space?: string | undefined;
256
- caveats?: Record<string, unknown>[] | undefined;
257
256
  skipPrefix?: boolean | undefined;
258
257
  expiry?: string | undefined;
259
258
  description?: string | undefined;
259
+ caveats?: Record<string, unknown>[] | undefined;
260
260
  }, {
261
261
  service: string;
262
262
  path: string;
263
263
  actions: string[];
264
264
  space?: string | undefined;
265
- caveats?: Record<string, unknown>[] | undefined;
266
265
  skipPrefix?: boolean | undefined;
267
266
  expiry?: string | undefined;
268
267
  description?: string | undefined;
268
+ caveats?: Record<string, unknown>[] | undefined;
269
269
  }>, "many">>;
270
270
  expiry: z.ZodOptional<z.ZodString>;
271
271
  prompted: z.ZodOptional<z.ZodBoolean>;
272
272
  }, "strict", z.ZodTypeAny, {
273
+ requestId: string;
273
274
  kind: "tinycloud.auth.delegation";
274
275
  version: 1;
275
- requestId: string;
276
276
  delegation: Record<string, unknown>;
277
277
  expiry?: string | undefined;
278
278
  delegationCid?: string | undefined;
@@ -281,16 +281,16 @@ declare const DelegationImportArtifactSchema: z.ZodObject<{
281
281
  path: string;
282
282
  actions: string[];
283
283
  space?: string | undefined;
284
- caveats?: Record<string, unknown>[] | undefined;
285
284
  skipPrefix?: boolean | undefined;
286
285
  expiry?: string | undefined;
287
286
  description?: string | undefined;
287
+ caveats?: Record<string, unknown>[] | undefined;
288
288
  }[] | undefined;
289
289
  prompted?: boolean | undefined;
290
290
  }, {
291
+ requestId: string;
291
292
  kind: "tinycloud.auth.delegation";
292
293
  version: 1;
293
- requestId: string;
294
294
  delegation: Record<string, unknown>;
295
295
  expiry?: string | undefined;
296
296
  delegationCid?: string | undefined;
@@ -299,10 +299,10 @@ declare const DelegationImportArtifactSchema: z.ZodObject<{
299
299
  path: string;
300
300
  actions: string[];
301
301
  space?: string | undefined;
302
- caveats?: Record<string, unknown>[] | undefined;
303
302
  skipPrefix?: boolean | undefined;
304
303
  expiry?: string | undefined;
305
304
  description?: string | undefined;
305
+ caveats?: Record<string, unknown>[] | undefined;
306
306
  }[] | undefined;
307
307
  prompted?: boolean | undefined;
308
308
  }>;
@@ -44,19 +44,19 @@ declare const PermissionEntrySchema: z.ZodObject<{
44
44
  path: string;
45
45
  actions: string[];
46
46
  space?: string | undefined;
47
- caveats?: Record<string, unknown>[] | undefined;
48
47
  skipPrefix?: boolean | undefined;
49
48
  expiry?: string | undefined;
50
49
  description?: string | undefined;
50
+ caveats?: Record<string, unknown>[] | undefined;
51
51
  }, {
52
52
  service: string;
53
53
  path: string;
54
54
  actions: string[];
55
55
  space?: string | undefined;
56
- caveats?: Record<string, unknown>[] | undefined;
57
56
  skipPrefix?: boolean | undefined;
58
57
  expiry?: string | undefined;
59
58
  description?: string | undefined;
59
+ caveats?: Record<string, unknown>[] | undefined;
60
60
  }>;
61
61
  declare const LegacyPermissionRequestArtifactSchema: z.ZodObject<{
62
62
  kind: z.ZodLiteral<"tinycloud.auth.request">;
@@ -77,51 +77,51 @@ declare const LegacyPermissionRequestArtifactSchema: z.ZodObject<{
77
77
  path: string;
78
78
  actions: string[];
79
79
  space?: string | undefined;
80
- caveats?: Record<string, unknown>[] | undefined;
81
80
  skipPrefix?: boolean | undefined;
82
81
  expiry?: string | undefined;
83
82
  description?: string | undefined;
83
+ caveats?: Record<string, unknown>[] | undefined;
84
84
  }, {
85
85
  service: string;
86
86
  path: string;
87
87
  actions: string[];
88
88
  space?: string | undefined;
89
- caveats?: Record<string, unknown>[] | undefined;
90
89
  skipPrefix?: boolean | undefined;
91
90
  expiry?: string | undefined;
92
91
  description?: string | undefined;
92
+ caveats?: Record<string, unknown>[] | undefined;
93
93
  }>, "many">;
94
94
  requestedExpiry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
95
95
  }, "strict", z.ZodTypeAny, {
96
- kind: "tinycloud.auth.request";
97
- version: 1;
98
96
  requestId: string;
97
+ kind: "tinycloud.auth.request";
99
98
  sessionDid: string;
99
+ version: 1;
100
100
  requested: {
101
101
  service: string;
102
102
  path: string;
103
103
  actions: string[];
104
104
  space?: string | undefined;
105
- caveats?: Record<string, unknown>[] | undefined;
106
105
  skipPrefix?: boolean | undefined;
107
106
  expiry?: string | undefined;
108
107
  description?: string | undefined;
108
+ caveats?: Record<string, unknown>[] | undefined;
109
109
  }[];
110
110
  requestedExpiry?: string | number | undefined;
111
111
  }, {
112
- kind: "tinycloud.auth.request";
113
- version: 1;
114
112
  requestId: string;
113
+ kind: "tinycloud.auth.request";
115
114
  sessionDid: string;
115
+ version: 1;
116
116
  requested: {
117
117
  service: string;
118
118
  path: string;
119
119
  actions: string[];
120
120
  space?: string | undefined;
121
- caveats?: Record<string, unknown>[] | undefined;
122
121
  skipPrefix?: boolean | undefined;
123
122
  expiry?: string | undefined;
124
123
  description?: string | undefined;
124
+ caveats?: Record<string, unknown>[] | undefined;
125
125
  }[];
126
126
  requestedExpiry?: string | number | undefined;
127
127
  }>;
@@ -153,19 +153,19 @@ declare const PermissionRequestArtifactSchema: z.ZodObject<{
153
153
  path: string;
154
154
  actions: string[];
155
155
  space?: string | undefined;
156
- caveats?: Record<string, unknown>[] | undefined;
157
156
  skipPrefix?: boolean | undefined;
158
157
  expiry?: string | undefined;
159
158
  description?: string | undefined;
159
+ caveats?: Record<string, unknown>[] | undefined;
160
160
  }, {
161
161
  service: string;
162
162
  path: string;
163
163
  actions: string[];
164
164
  space?: string | undefined;
165
- caveats?: Record<string, unknown>[] | undefined;
166
165
  skipPrefix?: boolean | undefined;
167
166
  expiry?: string | undefined;
168
167
  description?: string | undefined;
168
+ caveats?: Record<string, unknown>[] | undefined;
169
169
  }>, "many">;
170
170
  command: z.ZodOptional<z.ZodObject<{
171
171
  argv: z.ZodArray<z.ZodString, "many">;
@@ -178,55 +178,55 @@ declare const PermissionRequestArtifactSchema: z.ZodObject<{
178
178
  cwd: string;
179
179
  }>>;
180
180
  }, "strict", z.ZodTypeAny, {
181
- kind: "tinycloud.auth.request";
182
- version: 1;
181
+ createdAt: string;
183
182
  requestId: string;
183
+ kind: "tinycloud.auth.request";
184
+ operatorType: "human" | "agent";
184
185
  sessionDid: string;
186
+ version: 1;
185
187
  requested: {
186
188
  service: string;
187
189
  path: string;
188
190
  actions: string[];
189
191
  space?: string | undefined;
190
- caveats?: Record<string, unknown>[] | undefined;
191
192
  skipPrefix?: boolean | undefined;
192
193
  expiry?: string | undefined;
193
194
  description?: string | undefined;
195
+ caveats?: Record<string, unknown>[] | undefined;
194
196
  }[];
195
197
  host: string;
196
- createdAt: string;
197
198
  profile: string;
198
199
  posture: "owner-openkey" | "delegate-session" | "local-owner-key" | "unauthenticated";
199
- operatorType: "human" | "agent";
200
+ ownerDid?: string | undefined;
200
201
  requestedExpiry?: string | number | undefined;
201
202
  spaceId?: string | undefined;
202
- ownerDid?: string | undefined;
203
203
  command?: {
204
204
  argv: string[];
205
205
  cwd: string;
206
206
  } | undefined;
207
207
  }, {
208
- kind: "tinycloud.auth.request";
209
- version: 1;
208
+ createdAt: string;
210
209
  requestId: string;
210
+ kind: "tinycloud.auth.request";
211
+ operatorType: "human" | "agent";
211
212
  sessionDid: string;
213
+ version: 1;
212
214
  requested: {
213
215
  service: string;
214
216
  path: string;
215
217
  actions: string[];
216
218
  space?: string | undefined;
217
- caveats?: Record<string, unknown>[] | undefined;
218
219
  skipPrefix?: boolean | undefined;
219
220
  expiry?: string | undefined;
220
221
  description?: string | undefined;
222
+ caveats?: Record<string, unknown>[] | undefined;
221
223
  }[];
222
224
  host: string;
223
- createdAt: string;
224
225
  profile: string;
225
226
  posture: "owner-openkey" | "delegate-session" | "local-owner-key" | "unauthenticated";
226
- operatorType: "human" | "agent";
227
+ ownerDid?: string | undefined;
227
228
  requestedExpiry?: string | number | undefined;
228
229
  spaceId?: string | undefined;
229
- ownerDid?: string | undefined;
230
230
  command?: {
231
231
  argv: string[];
232
232
  cwd: string;
@@ -253,26 +253,26 @@ declare const DelegationImportArtifactSchema: z.ZodObject<{
253
253
  path: string;
254
254
  actions: string[];
255
255
  space?: string | undefined;
256
- caveats?: Record<string, unknown>[] | undefined;
257
256
  skipPrefix?: boolean | undefined;
258
257
  expiry?: string | undefined;
259
258
  description?: string | undefined;
259
+ caveats?: Record<string, unknown>[] | undefined;
260
260
  }, {
261
261
  service: string;
262
262
  path: string;
263
263
  actions: string[];
264
264
  space?: string | undefined;
265
- caveats?: Record<string, unknown>[] | undefined;
266
265
  skipPrefix?: boolean | undefined;
267
266
  expiry?: string | undefined;
268
267
  description?: string | undefined;
268
+ caveats?: Record<string, unknown>[] | undefined;
269
269
  }>, "many">>;
270
270
  expiry: z.ZodOptional<z.ZodString>;
271
271
  prompted: z.ZodOptional<z.ZodBoolean>;
272
272
  }, "strict", z.ZodTypeAny, {
273
+ requestId: string;
273
274
  kind: "tinycloud.auth.delegation";
274
275
  version: 1;
275
- requestId: string;
276
276
  delegation: Record<string, unknown>;
277
277
  expiry?: string | undefined;
278
278
  delegationCid?: string | undefined;
@@ -281,16 +281,16 @@ declare const DelegationImportArtifactSchema: z.ZodObject<{
281
281
  path: string;
282
282
  actions: string[];
283
283
  space?: string | undefined;
284
- caveats?: Record<string, unknown>[] | undefined;
285
284
  skipPrefix?: boolean | undefined;
286
285
  expiry?: string | undefined;
287
286
  description?: string | undefined;
287
+ caveats?: Record<string, unknown>[] | undefined;
288
288
  }[] | undefined;
289
289
  prompted?: boolean | undefined;
290
290
  }, {
291
+ requestId: string;
291
292
  kind: "tinycloud.auth.delegation";
292
293
  version: 1;
293
- requestId: string;
294
294
  delegation: Record<string, unknown>;
295
295
  expiry?: string | undefined;
296
296
  delegationCid?: string | undefined;
@@ -299,10 +299,10 @@ declare const DelegationImportArtifactSchema: z.ZodObject<{
299
299
  path: string;
300
300
  actions: string[];
301
301
  space?: string | undefined;
302
- caveats?: Record<string, unknown>[] | undefined;
303
302
  skipPrefix?: boolean | undefined;
304
303
  expiry?: string | undefined;
305
304
  description?: string | undefined;
305
+ caveats?: Record<string, unknown>[] | undefined;
306
306
  }[] | undefined;
307
307
  prompted?: boolean | undefined;
308
308
  }>;
package/dist/artifacts.js CHANGED
@@ -2237,6 +2237,7 @@ var KVService = class extends BaseService {
2237
2237
  }
2238
2238
  seen.add(path);
2239
2239
  }
2240
+ let requestMayHaveDispatched = false;
2240
2241
  try {
2241
2242
  const body = new FormData();
2242
2243
  for (let index = 0; index < items.length; index++) {
@@ -2254,14 +2255,31 @@ var KVService = class extends BaseService {
2254
2255
  action: KVAction.PUT
2255
2256
  }))
2256
2257
  );
2257
- const response = await this.context.fetch(`${this.host}/invoke`, {
2258
+ const url = `${this.host}/invoke`;
2259
+ const init = {
2258
2260
  method: "POST",
2259
2261
  headers,
2260
2262
  body,
2261
2263
  signal: this.combineSignals(options?.signal)
2262
- });
2264
+ };
2265
+ const fetchFn = this.context.fetch;
2266
+ requestMayHaveDispatched = true;
2267
+ const response = await fetchFn(url, init);
2263
2268
  if (!response.ok) {
2264
- const errorText = await response.text();
2269
+ let errorText;
2270
+ try {
2271
+ errorText = await response.text();
2272
+ } catch (textError) {
2273
+ const cause = textError instanceof Error ? textError : new Error(String(textError));
2274
+ return err(
2275
+ serviceError(
2276
+ ErrorCodes.KV_WRITE_FAILED,
2277
+ `Failed to batch put ${items.length} key(s): ${response.status} - <response body could not be read: ${cause.message}>`,
2278
+ "kv",
2279
+ { cause, meta: { status: response.status, statusText: response.statusText } }
2280
+ )
2281
+ );
2282
+ }
2265
2283
  if (response.status === 401 || response.status === 403) {
2266
2284
  const { resource, action } = parseAuthError(errorText);
2267
2285
  return err(authUnauthorizedError("kv", errorText, {
@@ -2287,19 +2305,73 @@ var KVService = class extends BaseService {
2287
2305
  )
2288
2306
  );
2289
2307
  }
2290
- const batchResponse = this.normalizeBatchPutResponse(await response.json());
2291
- if (!batchResponse || batchResponse.count !== batchResponse.written.length) {
2308
+ let rawBody;
2309
+ try {
2310
+ rawBody = await response.json();
2311
+ } catch (jsonError) {
2312
+ const cause = jsonError instanceof Error ? jsonError : new Error(String(jsonError));
2313
+ return err(
2314
+ serviceError(
2315
+ ErrorCodes.NETWORK_ERROR,
2316
+ `KV batchPut response was not valid JSON: ${cause.message}`,
2317
+ "kv",
2318
+ {
2319
+ cause,
2320
+ meta: {
2321
+ requestMayHaveDispatched: true,
2322
+ responseReceived: true,
2323
+ status: response.status,
2324
+ outcome: "batch-unconfirmed"
2325
+ }
2326
+ }
2327
+ )
2328
+ );
2329
+ }
2330
+ const batchResponse = this.normalizeBatchPutResponse(rawBody);
2331
+ if (!batchResponse) {
2292
2332
  return err(
2293
2333
  serviceError(
2294
2334
  ErrorCodes.NETWORK_ERROR,
2295
2335
  "KV batchPut response did not include matching written keys and count",
2296
- "kv"
2336
+ "kv",
2337
+ {
2338
+ meta: {
2339
+ requestMayHaveDispatched: true,
2340
+ responseReceived: true,
2341
+ status: response.status,
2342
+ outcome: "batch-unconfirmed"
2343
+ }
2344
+ }
2345
+ )
2346
+ );
2347
+ }
2348
+ const requestedPaths = new Set(paths);
2349
+ const writtenPaths = new Set(batchResponse.written);
2350
+ const matchesRequest = batchResponse.count === paths.length && batchResponse.written.length === paths.length && writtenPaths.size === paths.length && batchResponse.written.every((key) => requestedPaths.has(key));
2351
+ if (!matchesRequest) {
2352
+ return err(
2353
+ serviceError(
2354
+ ErrorCodes.NETWORK_ERROR,
2355
+ `KV batchPut response did not confirm all ${paths.length} requested key(s) were written`,
2356
+ "kv",
2357
+ {
2358
+ meta: {
2359
+ requestMayHaveDispatched: true,
2360
+ responseReceived: true,
2361
+ status: response.status,
2362
+ outcome: "batch-unconfirmed"
2363
+ }
2364
+ }
2297
2365
  )
2298
2366
  );
2299
2367
  }
2300
2368
  return ok(batchResponse);
2301
2369
  } catch (error) {
2302
- return err(wrapError("kv", error));
2370
+ const wrapped = wrapError("kv", error);
2371
+ return err({
2372
+ ...wrapped,
2373
+ meta: { ...wrapped.meta, requestMayHaveDispatched }
2374
+ });
2303
2375
  }
2304
2376
  });
2305
2377
  }