@ai4b-team/fsaos-gateway-sdk 5.5.0 → 5.5.2

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/dist/iife/ui.js CHANGED
@@ -1,3 +1,3 @@
1
- /* @fsaos/ui v2.0.0 — FSAOS UI Primitives — 2026-11-15T02:30:26.137Z */
1
+ /* @fsaos/ui v2.0.0 — FSAOS UI Primitives — 2026-11-15T22:46:38.568Z */
2
2
  "use strict";var __FSAOS_UI__=(()=>{var m=Object.create;var r=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,h=Object.prototype.hasOwnProperty;var y=(e,i)=>()=>(i||e((i={exports:{}}).exports,i),i.exports),N=(e,i)=>{for(var a in i)r(e,a,{get:i[a],enumerable:!0})},s=(e,i,a,l)=>{if(i&&typeof i=="object"||typeof i=="function")for(let t of u(i))!h.call(e,t)&&t!==a&&r(e,t,{get:()=>i[t],enumerable:!(l=g(i,t))||l.enumerable});return e};var x=(e,i,a)=>(a=e!=null?m(f(e)):{},s(i||!e||!e.__esModule?r(a,"default",{value:e,enumerable:!0}):a,e)),b=e=>s(r({},"__esModule",{value:!0}),e);var d=y((V,c)=>{c.exports=React});var P={};N(P,{Badge:()=>z,Breadcrumbs:()=>A,Button:()=>D,Card:()=>w,DataView:()=>R,Detail:()=>_,Empty:()=>I,FilePreview:()=>O,Form:()=>F,Grid:()=>k,Image:()=>G,Link:()=>E,Page:()=>v,Router:()=>T,Sidebar:()=>S,Spinner:()=>B,Stack:()=>C,Table:()=>j,Tabs:()=>W,Video:()=>H});var n=x(d(),1);function o(){return(typeof window<"u"&&window.__FSAOS_CONFIG__||{}).edgeBaseUrl||""}function v(e){return(0,n.createElement)("div",{style:{minHeight:"100vh",display:"flex",flexDirection:"column"},className:e.className||""},e.children)}function C(e){let i=e.direction||"vertical";return(0,n.createElement)("div",{style:{display:"flex",flexDirection:i==="horizontal"?"row":"column",gap:e.gap||"0.5rem",padding:e.padding||"0",alignItems:e.align||"stretch",justifyContent:e.justify||"flex-start",flex:e.flex||"initial"},className:e.className||""},e.children)}function k(e){return(0,n.createElement)("div",{style:{display:"grid",gridTemplateColumns:"repeat("+(e.columns||3)+", 1fr)",gap:e.gap||"1rem",padding:e.padding||"0"},className:e.className||""},e.children)}function S(e){return(0,n.createElement)("div",{style:{display:"flex",flexDirection:"row",minHeight:"100vh"},className:e.className||""},e.children)}function w(e){return(0,n.createElement)("div",{style:{border:"1px solid var(--color-border, #e5e7eb)",borderRadius:"var(--border-radius, 0.5rem)",padding:e.padding||"1rem",background:"var(--color-surface, #fff)"},className:e.className||"",onClick:e.onClick},e.children)}function z(e){return(0,n.createElement)("span",{style:{display:"inline-flex",alignItems:"center",padding:"0.125rem 0.5rem",fontSize:"0.75rem",fontWeight:"500",borderRadius:"9999px",background:e.color||"#e5e7eb",color:e.textColor||"#374151"},className:e.className||""},e.children||e.label)}function B(e){let i=e.size||"1.5rem";return(0,n.createElement)("div",{style:{width:i,height:i,border:"2px solid #e5e7eb",borderTopColor:"var(--color-primary, #3b82f6)",borderRadius:"50%",animation:"fsaos-spin 0.6s linear infinite"}})}function D(e){return(0,n.createElement)("button",{style:{display:"inline-flex",alignItems:"center",justifyContent:"center",padding:"0.5rem 1rem",fontSize:"0.875rem",fontWeight:"500",borderRadius:"var(--border-radius, 0.375rem)",border:e.variant==="outline"?"1px solid var(--color-border, #d1d5db)":"none",background:e.variant==="outline"||e.variant==="ghost"?"transparent":"var(--color-primary, #3b82f6)",color:e.variant==="outline"||e.variant==="ghost"?"var(--color-text, #1a1a1a)":"#fff",cursor:e.disabled?"not-allowed":"pointer",opacity:e.disabled?"0.5":"1",gap:"0.5rem"},className:e.className||"",onClick:e.onClick,disabled:e.disabled},e.children||e.label)}function I(e){return(0,n.createElement)("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",padding:"3rem",color:"var(--color-text-secondary, #6b7280)",textAlign:"center"}},e.icon?(0,n.createElement)("div",{style:{fontSize:"2rem",marginBottom:"0.5rem"}},e.icon):null,(0,n.createElement)("div",{style:{fontWeight:500,marginBottom:"0.25rem"}},e.title||e.message||e.children||"No items"),e.description?(0,n.createElement)("div",{style:{fontSize:"0.875rem",opacity:.7}},e.description):null)}function R(e){return(0,n.createElement)("div",{className:e.className||""},e.children)}function j(e){return(0,n.createElement)("table",{className:e.className||""},e.children)}function F(e){return(0,n.createElement)("form",{className:e.className||"",onSubmit:e.onSubmit},e.children)}function _(e){return(0,n.createElement)("div",{className:e.className||""},e.children)}function T(e){return(0,n.createElement)("div",null,e.children)}function E(e){return(0,n.createElement)("a",{href:e.href||e.to,className:e.className||"",onClick:e.onClick},e.children)}function W(e){return(0,n.createElement)("div",{className:e.className||""},e.children)}function A(e){return(0,n.createElement)("nav",{className:e.className||""},e.children)}function G(e){return(0,n.createElement)("img",{src:e.src||(e.path?o()+e.path:""),alt:e.alt||"",className:e.className||"",style:e.style})}function H(e){return(0,n.createElement)("video",{src:e.src||(e.path?o()+e.path:""),controls:!0,className:e.className||""})}function O(e){return(0,n.createElement)("div",{className:e.className||""},e.children||"File preview")}return b(P);})();
3
3
  //# sourceMappingURL=ui.js.map
package/dist/index.cjs CHANGED
@@ -2226,6 +2226,9 @@ function parseChannelMessages(rawItems) {
2226
2226
  seq: td.seq || 0,
2227
2227
  principal_id: td.principal_id,
2228
2228
  member_id: typeof td.member_id === "string" ? td.member_id : void 0,
2229
+ sender_display_name: typeof td.sender_display_name === "string" ? td.sender_display_name : void 0,
2230
+ sender_is_ai: typeof td.sender_is_ai === "boolean" ? td.sender_is_ai : void 0,
2231
+ sender_role_display_name: typeof td.sender_role_display_name === "string" ? td.sender_role_display_name : void 0,
2229
2232
  reply_count: td.reply_count || 0,
2230
2233
  member_count: td.member_count || 0,
2231
2234
  parent_message_id: td.parent_message_id,
@@ -6261,6 +6264,32 @@ function getRequiredFormFields(typeDef) {
6261
6264
  (f) => required.has(f.key) || f.default_value === void 0
6262
6265
  );
6263
6266
  }
6267
+
6268
+ // src/upload-integrity.ts
6269
+ var MAX_BUFFERED_HASH_BYTES = 16 * 1024 * 1024;
6270
+ var hashing = Promise.resolve();
6271
+ function checkUploadCancelled(signal2) {
6272
+ if (signal2?.aborted) throw new Error("Upload cancelled");
6273
+ }
6274
+ async function prepareUploadIntegrity(file, signal2) {
6275
+ checkUploadCancelled(signal2);
6276
+ if (file.size > MAX_BUFFERED_HASH_BYTES || !globalThis.crypto?.subtle) return {};
6277
+ const operation = hashing.then(async () => {
6278
+ checkUploadCancelled(signal2);
6279
+ const bytes = await file.arrayBuffer();
6280
+ checkUploadCancelled(signal2);
6281
+ const digest = await globalThis.crypto.subtle.digest("SHA-256", bytes);
6282
+ checkUploadCancelled(signal2);
6283
+ return {
6284
+ expected_sha256: Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, "0")).join(""),
6285
+ expected_size_bytes: file.size
6286
+ };
6287
+ });
6288
+ hashing = operation.catch(() => void 0);
6289
+ return operation;
6290
+ }
6291
+
6292
+ // src/upload.ts
6264
6293
  function generateUploadId() {
6265
6294
  if (globalThis.crypto?.randomUUID) return globalThis.crypto.randomUUID();
6266
6295
  const bytes = new Uint8Array(16);
@@ -6282,6 +6311,12 @@ async function uploadFile(file, options, onProgress, signal2) {
6282
6311
  const itemType = options.itemType || "file";
6283
6312
  const collisionPolicy = options.collisionPolicy || "keep_both";
6284
6313
  const uploadId = collisionPolicy === "keep_both" ? generateUploadId() : void 0;
6314
+ const scopeVersion = getScopeVersion(), sessionGeneration2 = getSessionGeneration();
6315
+ const integrity = await prepareUploadIntegrity(file, signal2);
6316
+ checkUploadCancelled(signal2);
6317
+ if (scopeVersion !== getScopeVersion() || sessionGeneration2 !== getSessionGeneration()) {
6318
+ throw new Error("The account or Space changed while preparing the upload. Start it again.");
6319
+ }
6285
6320
  const createParams = {
6286
6321
  parent_path: options.parentPath,
6287
6322
  item_type: itemType,
@@ -6292,7 +6327,8 @@ async function uploadFile(file, options, onProgress, signal2) {
6292
6327
  type: "upload",
6293
6328
  content_type: contentType,
6294
6329
  collision_policy: collisionPolicy,
6295
- ...uploadId ? { upload_id: uploadId } : {}
6330
+ ...uploadId ? { upload_id: uploadId } : {},
6331
+ ...integrity
6296
6332
  }
6297
6333
  }
6298
6334
  };
@@ -6300,6 +6336,7 @@ async function uploadFile(file, options, onProgress, signal2) {
6300
6336
  createParams.card_parent_path = options.cardParentPath;
6301
6337
  }
6302
6338
  const createResult = await gatewayCall("create", createParams);
6339
+ checkUploadCancelled(signal2);
6303
6340
  const result = createResult;
6304
6341
  if (!result.id) {
6305
6342
  throw new Error(result.error || result.message || "Failed to create file item");
@@ -6316,7 +6353,8 @@ async function uploadFile(file, options, onProgress, signal2) {
6316
6353
  throw new Error("Gateway returned no storage_key \u2014 file_source may not be supported for this item type");
6317
6354
  }
6318
6355
  await uploadBinaryXHR(storageWorkerUrl, storageKey, uploadToken, file, contentType, onProgress, signal2);
6319
- const fileRef = await confirmUpload(itemId, storageKey, contentType);
6356
+ checkUploadCancelled(signal2);
6357
+ const fileRef = await confirmUpload(itemId, storageKey, contentType, uploadToken, integrity.expected_sha256, file.size);
6320
6358
  return { itemId, itemPath, fileRef };
6321
6359
  }
6322
6360
  function uploadBinaryXHR(storageWorkerUrl, storageKey, uploadToken, body, contentType, onProgress, signal2) {
@@ -6342,6 +6380,7 @@ function uploadBinaryXHR(storageWorkerUrl, storageKey, uploadToken, body, conten
6342
6380
  };
6343
6381
  xhr.onerror = () => reject(new Error("Storage upload network error"));
6344
6382
  xhr.ontimeout = () => reject(new Error("Storage upload timed out"));
6383
+ xhr.onabort = () => reject(new Error("Upload cancelled"));
6345
6384
  if (signal2) {
6346
6385
  if (signal2.aborted) {
6347
6386
  reject(new Error("Upload cancelled"));
@@ -6355,7 +6394,7 @@ function uploadBinaryXHR(storageWorkerUrl, storageKey, uploadToken, body, conten
6355
6394
  xhr.send(body);
6356
6395
  });
6357
6396
  }
6358
- async function confirmUpload(itemId, storageKey, contentType) {
6397
+ async function confirmUpload(itemId, storageKey, contentType, uploadToken, contentSha256, sizeBytes) {
6359
6398
  const token = await getAccessToken();
6360
6399
  const response = await fetch(`${GATEWAY_URL}/storage/upload-complete`, {
6361
6400
  method: "POST",
@@ -6366,7 +6405,9 @@ async function confirmUpload(itemId, storageKey, contentType) {
6366
6405
  body: JSON.stringify({
6367
6406
  item_id: itemId,
6368
6407
  storage_key: storageKey,
6369
- content_type: contentType
6408
+ content_type: contentType,
6409
+ ...uploadToken ? { upload_token: uploadToken } : {},
6410
+ ...contentSha256 ? { hash: contentSha256 } : {}
6370
6411
  })
6371
6412
  });
6372
6413
  if (!response.ok) {
@@ -6377,6 +6418,9 @@ async function confirmUpload(itemId, storageKey, contentType) {
6377
6418
  if (!result.success) {
6378
6419
  throw new Error(result.error || result.message || "Upload confirmation rejected");
6379
6420
  }
6421
+ if (contentSha256 && (result.file_ref?.content_sha256 !== contentSha256 || result.file_ref?.size_bytes !== sizeBytes || result.file_ref?.content_type !== contentType)) {
6422
+ throw new Error("Stored file did not confirm the expected checksum, size and type");
6423
+ }
6380
6424
  return result.file_ref;
6381
6425
  }
6382
6426
  function useFileUpload() {
@@ -6384,6 +6428,7 @@ function useFileUpload() {
6384
6428
  const qc = reactQuery.useQueryClient();
6385
6429
  const uploadsRef = React.useRef(uploads);
6386
6430
  uploadsRef.current = uploads;
6431
+ const attempts = React.useRef(/* @__PURE__ */ new Map());
6387
6432
  const updateUpload = React.useCallback((id, patch) => {
6388
6433
  setUploads((prev) => prev.map((u) => u.id === id ? { ...u, ...patch } : u));
6389
6434
  }, []);
@@ -6400,9 +6445,20 @@ function useFileUpload() {
6400
6445
  let storageKey = existingState?.storageKey || null;
6401
6446
  let uploadToken = existingState?.uploadToken || null;
6402
6447
  let storageWorkerUrl = existingState?.storageWorkerUrl || null;
6448
+ let contentSha256 = existingState?.contentSha256 || void 0;
6449
+ const controller = new AbortController();
6450
+ const scopeVersion = getScopeVersion(), sessionGeneration2 = getSessionGeneration();
6451
+ attempts.current.get(uploadId)?.abort();
6452
+ attempts.current.set(uploadId, controller);
6403
6453
  try {
6404
6454
  if (!resumeFrom || resumeFrom === "create") {
6405
6455
  updateUpload(uploadId, { status: "creating", error: null, _failedAt: null });
6456
+ const integrity = await prepareUploadIntegrity(file, controller.signal);
6457
+ checkUploadCancelled(controller.signal);
6458
+ if (scopeVersion !== getScopeVersion() || sessionGeneration2 !== getSessionGeneration()) {
6459
+ throw new Error("The account or Space changed while preparing the upload. Start it again.");
6460
+ }
6461
+ contentSha256 = integrity.expected_sha256;
6406
6462
  const createResult = await gatewayCall("create", {
6407
6463
  parent_path: options.parentPath,
6408
6464
  item_type: itemType,
@@ -6413,10 +6469,12 @@ function useFileUpload() {
6413
6469
  type: "upload",
6414
6470
  content_type: contentType,
6415
6471
  collision_policy: collisionPolicy,
6416
- ...collisionPolicy === "keep_both" ? { upload_id: uploadId } : {}
6472
+ ...collisionPolicy === "keep_both" ? { upload_id: uploadId } : {},
6473
+ ...integrity
6417
6474
  }
6418
6475
  }
6419
6476
  });
6477
+ checkUploadCancelled(controller.signal);
6420
6478
  const result = createResult;
6421
6479
  if (!result.id) {
6422
6480
  throw Object.assign(
@@ -6442,7 +6500,8 @@ function useFileUpload() {
6442
6500
  updateUpload(uploadId, {
6443
6501
  _storageKey: storageKey,
6444
6502
  _uploadToken: uploadToken,
6445
- _storageWorkerUrl: storageWorkerUrl
6503
+ _storageWorkerUrl: storageWorkerUrl,
6504
+ _contentSha256: contentSha256 || null
6446
6505
  });
6447
6506
  if (!storageKey) {
6448
6507
  throw Object.assign(
@@ -6485,19 +6544,27 @@ function useFileUpload() {
6485
6544
  new Error("Storage upload timed out"),
6486
6545
  { _step: "upload" }
6487
6546
  ));
6547
+ xhr.onabort = () => reject(Object.assign(new Error("Upload cancelled"), { _step: "upload" }));
6548
+ controller.signal.addEventListener("abort", () => xhr.abort(), { once: true });
6549
+ checkUploadCancelled(controller.signal);
6488
6550
  xhr.send(file);
6489
6551
  });
6490
6552
  await xhrPromise;
6553
+ checkUploadCancelled(controller.signal);
6491
6554
  updateUpload(uploadId, { progress: 100, _xhr: null });
6492
6555
  }
6493
6556
  updateUpload(uploadId, { status: "confirming", error: null, _failedAt: null });
6494
- const fileRef = await confirmUpload(itemId, storageKey, contentType);
6557
+ const fileRef = await confirmUpload(itemId, storageKey, contentType, uploadToken || "", contentSha256, file.size).catch((error) => {
6558
+ throw Object.assign(error, { _step: "confirm" });
6559
+ });
6560
+ checkUploadCancelled(controller.signal);
6495
6561
  updateUpload(uploadId, {
6496
6562
  status: "complete",
6497
6563
  fileRef
6498
6564
  });
6499
6565
  qc.invalidateQueries({ queryKey: vfsKeys.children(options.parentPath) });
6500
6566
  } catch (err) {
6567
+ if (attempts.current.get(uploadId) !== controller) return;
6501
6568
  const message = err?.message || String(err);
6502
6569
  const failedAt = err?._step || "create";
6503
6570
  updateUpload(uploadId, {
@@ -6506,6 +6573,8 @@ function useFileUpload() {
6506
6573
  _failedAt: failedAt,
6507
6574
  _xhr: null
6508
6575
  });
6576
+ } finally {
6577
+ if (attempts.current.get(uploadId) === controller) attempts.current.delete(uploadId);
6509
6578
  }
6510
6579
  }, [updateUpload, qc]);
6511
6580
  const upload = React.useCallback((file, options) => {
@@ -6523,6 +6592,7 @@ function useFileUpload() {
6523
6592
  _storageKey: null,
6524
6593
  _uploadToken: null,
6525
6594
  _storageWorkerUrl: null,
6595
+ _contentSha256: null,
6526
6596
  _xhr: null,
6527
6597
  _failedAt: null
6528
6598
  };
@@ -6543,11 +6613,13 @@ function useFileUpload() {
6543
6613
  uploadToken: item._uploadToken || "",
6544
6614
  storageWorkerUrl: item._storageWorkerUrl || "https://fsaos-storage.radns.workers.dev",
6545
6615
  itemId: item.itemId,
6546
- itemPath: item.itemPath || ""
6616
+ itemPath: item.itemPath || "",
6617
+ contentSha256: item._contentSha256
6547
6618
  } : void 0;
6548
6619
  executeUpload(uploadId, item.file, item.options, resumeFrom, existingState);
6549
6620
  }, [executeUpload]);
6550
6621
  const cancelUpload = React.useCallback((uploadId) => {
6622
+ attempts.current.get(uploadId)?.abort();
6551
6623
  const item = uploadsRef.current.find((u) => u.id === uploadId);
6552
6624
  if (!item) return;
6553
6625
  if (item._xhr) {
@@ -6561,6 +6633,8 @@ function useFileUpload() {
6561
6633
  });
6562
6634
  }, [updateUpload]);
6563
6635
  const removeUpload = React.useCallback((uploadId) => {
6636
+ attempts.current.get(uploadId)?.abort();
6637
+ attempts.current.delete(uploadId);
6564
6638
  setUploads((prev) => prev.filter((u) => u.id !== uploadId));
6565
6639
  }, []);
6566
6640
  const clearCompleted = React.useCallback(() => {
@@ -6569,7 +6643,7 @@ function useFileUpload() {
6569
6643
  const isUploading = uploads.some(
6570
6644
  (u) => u.status === "creating" || u.status === "uploading" || u.status === "confirming"
6571
6645
  );
6572
- const publicUploads = uploads.map(({ _storageKey, _uploadToken, _storageWorkerUrl, _xhr, _failedAt, ...rest }) => rest);
6646
+ const publicUploads = uploads.map(({ _storageKey, _uploadToken, _storageWorkerUrl, _contentSha256, _xhr, _failedAt, ...rest }) => rest);
6573
6647
  return {
6574
6648
  upload,
6575
6649
  uploadMultiple,