@wix/himalaya-cli 0.1763.0 → 0.1764.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 (40) hide show
  1. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/screens/src/file-share-client.d.ts +115 -0
  2. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/screens/src/file-share-screen.d.ts +57 -0
  3. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/screens/src/file-share-service.d.ts +441 -0
  4. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/screens/src/index.d.ts +2 -0
  5. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/screens.mjs +1032 -117
  6. package/dist/cli.mjs +169 -10
  7. package/guides/getting-started.md +2 -0
  8. package/guides/himi-skill.md +2 -0
  9. package/guides/index.json +6 -0
  10. package/guides/wix-file-share.md +168 -0
  11. package/guides/wix-site-to-himi-app.md +1 -0
  12. package/package.json +2 -2
  13. package/templates/branded-lite/l10n/ar.json +0 -135
  14. package/templates/branded-lite/l10n/cs.json +0 -135
  15. package/templates/branded-lite/l10n/da.json +0 -135
  16. package/templates/branded-lite/l10n/de.json +0 -135
  17. package/templates/branded-lite/l10n/el.json +0 -135
  18. package/templates/branded-lite/l10n/es.json +0 -135
  19. package/templates/branded-lite/l10n/fi.json +0 -135
  20. package/templates/branded-lite/l10n/fr.json +0 -135
  21. package/templates/branded-lite/l10n/he.json +0 -108
  22. package/templates/branded-lite/l10n/hu.json +0 -135
  23. package/templates/branded-lite/l10n/id.json +0 -135
  24. package/templates/branded-lite/l10n/it.json +0 -135
  25. package/templates/branded-lite/l10n/ja.json +0 -135
  26. package/templates/branded-lite/l10n/ko.json +0 -135
  27. package/templates/branded-lite/l10n/lt.json +0 -135
  28. package/templates/branded-lite/l10n/nl.json +0 -135
  29. package/templates/branded-lite/l10n/no.json +0 -135
  30. package/templates/branded-lite/l10n/pl.json +0 -135
  31. package/templates/branded-lite/l10n/pt.json +0 -135
  32. package/templates/branded-lite/l10n/ru.json +0 -135
  33. package/templates/branded-lite/l10n/sv.json +0 -135
  34. package/templates/branded-lite/l10n/th.json +0 -135
  35. package/templates/branded-lite/l10n/tr.json +0 -135
  36. package/templates/branded-lite/l10n/uk.json +0 -135
  37. package/templates/branded-lite/l10n/vi.json +0 -135
  38. package/templates/branded-lite/l10n/zh.json +0 -135
  39. package/templates/branded-lite/tier5-src/himi-branded-lite-file-share/index.ts +8 -631
  40. package/templates/branded-lite/tier5-src/_shared/wix-file-share.ts +0 -332
@@ -324,6 +324,916 @@ function createBusinessContactService(opts = {}) {
324
324
  return svc;
325
325
  }
326
326
 
327
+ // ../../core/sdk/files/src/index.ts
328
+ function refToPath(ref) {
329
+ return typeof ref === "string" ? ref : ref.uri;
330
+ }
331
+ function basename(p) {
332
+ const i = p.lastIndexOf("/");
333
+ return i >= 0 ? p.slice(i + 1) : p;
334
+ }
335
+ function toHandle(r, fallbackPath) {
336
+ return {
337
+ uri: r?.uri ?? fallbackPath,
338
+ name: r?.name ?? basename(fallbackPath),
339
+ mimeType: r?.mimeType ?? "application/octet-stream",
340
+ sizeBytes: typeof r?.sizeBytes === "number" ? r.sizeBytes : 0,
341
+ ...r?.ownerScope ? { ownerScope: r.ownerScope } : {}
342
+ };
343
+ }
344
+ async function readBase64(ref) {
345
+ const r = await dispatch("capability.files.readBase64", { uri: refToPath(ref), ...typeof ref !== "string" && ref.ownerScope ? { ownerScope: ref.ownerScope } : {} });
346
+ if (r?.error) throw new Error(`files.readBase64: ${r.error}`);
347
+ return r?.base64 ?? "";
348
+ }
349
+ async function remove(ref) {
350
+ await dispatch("capability.files.remove", {
351
+ uri: refToPath(ref),
352
+ ...typeof ref !== "string" && ref.ownerScope ? { ownerScope: ref.ownerScope } : {}
353
+ });
354
+ }
355
+ function filesError(code, message, status2) {
356
+ const e = new Error(message);
357
+ e.name = "FilesError";
358
+ e.code = code;
359
+ if (typeof status2 === "number") e.status = status2;
360
+ return e;
361
+ }
362
+ function isFilesError(e) {
363
+ return e instanceof Error && e.name === "FilesError" && typeof e.code === "string";
364
+ }
365
+ var ERROR_CODES = ["invalid_url", "too_large", "http_error", "network", "unavailable"];
366
+ function throwIfError(verb, r) {
367
+ const e = r?.error;
368
+ if (e == null) return;
369
+ const obj = typeof e === "object" ? e : { message: e };
370
+ const code = ERROR_CODES.includes(obj.code) ? obj.code : "network";
371
+ const message = typeof obj.message === "string" && obj.message ? obj.message : code;
372
+ throw filesError(code, `files.${verb}: ${message}`, typeof obj.status === "number" ? obj.status : void 0);
373
+ }
374
+ var DEFAULT_DOWNLOAD_MAX_BYTES = 100 * 1024 * 1024;
375
+ var MAX_DOWNLOAD_BYTES = 1024 * 1024 * 1024;
376
+ async function download(url, opts) {
377
+ const params = { url };
378
+ if (opts?.name) params.name = opts.name;
379
+ if (typeof opts?.maxBytes === "number" && opts.maxBytes > 0) params.maxBytes = String(Math.floor(opts.maxBytes));
380
+ const r = await dispatch("capability.files.download", params);
381
+ throwIfError("download", r);
382
+ return toHandle(r, opts?.name ?? "download");
383
+ }
384
+ async function exportFile(file, opts) {
385
+ const params = { uri: refToPath(file) };
386
+ if (typeof file !== "string" && file.ownerScope) params.ownerScope = file.ownerScope;
387
+ if (opts?.suggestedName) params.suggestedName = opts.suggestedName;
388
+ const mimeType = opts?.mimeType ?? (typeof file !== "string" ? file.mimeType : void 0);
389
+ if (mimeType) params.mimeType = mimeType;
390
+ const r = await dispatch("capability.files.export", params);
391
+ throwIfError("export", r);
392
+ return { exported: r?.exported === true };
393
+ }
394
+
395
+ // ../../core/sdk/file-picker/src/index.ts
396
+ async function pickDetailed(options) {
397
+ const params = {};
398
+ if (options?.types?.length) params.types = options.types.join(",");
399
+ if (options?.multiple) params.multiple = "true";
400
+ for (const key of ["maxBytes", "maxImageBytes", "maxItems", "maxTotalBytes"]) {
401
+ const n = options?.[key];
402
+ if (n !== void 0) {
403
+ if (!Number.isSafeInteger(n) || n <= 0) throw new Error(`file-picker: ${key} must be a positive safe integer`);
404
+ params[key] = String(n);
405
+ }
406
+ }
407
+ const r = await dispatch("capability.file_picker.pick", params);
408
+ return { items: Array.isArray(r?.items) ? r.items : [], rejected: Array.isArray(r?.rejected) ? r.rejected : [] };
409
+ }
410
+
411
+ // ../../core/sdk/presigned-upload/src/index.ts
412
+ var MAX_INLINE_BASE64_BYTES = 8 * 1024 * 1024;
413
+ var MAX_UPLOAD_BYTES = 32 * 1024 * 1024;
414
+ function normalize(r) {
415
+ const o = r ?? {};
416
+ const status2 = typeof o.status === "number" ? o.status : Number(o.status ?? 0) || 0;
417
+ return {
418
+ status: status2,
419
+ ok: status2 >= 200 && status2 < 300,
420
+ body: typeof o.body === "string" ? o.body : "",
421
+ bytesSent: typeof o.bytesSent === "number" ? o.bytesSent : Number(o.bytesSent ?? 0) || 0
422
+ };
423
+ }
424
+ async function put(url, bytes, opts) {
425
+ return normalize(
426
+ await dispatch("capability.presigned_upload.put", {
427
+ url: url ?? "",
428
+ base64: bytes?.base64 ?? "",
429
+ contentType: opts?.contentType ?? "",
430
+ method: opts?.method ?? "PUT"
431
+ })
432
+ );
433
+ }
434
+
435
+ // ../../stdlib/wix-sdk/users/src/index.ts
436
+ function wixCall(method, path, body, readOptions) {
437
+ if (!globalThis.himalaya?.wixApi) {
438
+ return Promise.reject(
439
+ new Error("@himalaya/wix-users: host did not install the wixApi bridge")
440
+ );
441
+ }
442
+ const api = globalThis.himalaya.wixApi;
443
+ if (readOptions?.cache || readOptions?.onCacheResult) {
444
+ if (!api.read) return Promise.reject(new Error("READ_LIFECYCLE_UNSUPPORTED: update the Himalaya runtime"));
445
+ return api.read(method, path, body, readOptions.site ? { "wix-site-id": readOptions.site } : void 0, { cache: readOptions.cache ?? "default" }).then((result) => {
446
+ readOptions.onCacheResult?.(result.cache);
447
+ return result.data;
448
+ });
449
+ }
450
+ return readOptions?.site ? api.call(method, path, body, { "wix-site-id": readOptions.site }) : api.call(method, path, body);
451
+ }
452
+ function getMyData(options) {
453
+ return wixCall("GET", "https://users.wix.com/wix-users/v1/users/my-data?includeProfile=true", void 0, options);
454
+ }
455
+
456
+ // ../../stdlib/flows/screens/src/file-share-client.ts
457
+ var FILE_SHARE_APP_DEF_ID = "1537b24e-29d1-6d8f-b8e1-d6860f2f70b9";
458
+ var FILE_SHARE_BASE = "/file-sharing/api/v1/file-sharing";
459
+ var FILE_SHARE_CAPABILITIES = Object.freeze(["wix_api", "open_url", "files", "file_picker", "presigned_upload"]);
460
+ var PAGE_SIZE = 50;
461
+ var SEARCH_MAX = 50;
462
+ var UPLOAD_RESPONSE_MAX = 4096;
463
+ var UPLOAD_MAX_BYTES = 7 * 1024 * 1024;
464
+ async function call(method, path, body) {
465
+ const wixApi2 = globalThis.himalaya?.wixApi;
466
+ if (!wixApi2) throw new Error("wix-file-share: host did not install the wixApi bridge");
467
+ return body === void 0 ? await wixApi2.call(method, `${FILE_SHARE_BASE}${path}`) : await wixApi2.call(method, `${FILE_SHARE_BASE}${path}`, body);
468
+ }
469
+ function httpStatus(error) {
470
+ if (!error || typeof error !== "object") return void 0;
471
+ const row = error;
472
+ for (const value of [row.status, row.statusCode, row.response?.status]) {
473
+ if (typeof value === "number" && value >= 100) return value;
474
+ }
475
+ const match = typeof row.message === "string" ? /^(?:HTTP\s*)?(\d{3})\b/i.exec(row.message.trim()) : null;
476
+ return match ? Number(match[1]) : void 0;
477
+ }
478
+ function page(raw) {
479
+ const data = raw ?? {};
480
+ const next = data.metaData?.nextCursor;
481
+ return {
482
+ items: Array.isArray(data.libraryItems) ? data.libraryItems : [],
483
+ // A StringValue arrives as a bare string; tolerate the wrapped form too.
484
+ nextCursor: typeof next === "string" ? next : typeof next?.value === "string" ? String(next.value) : ""
485
+ };
486
+ }
487
+ function paging(cursor) {
488
+ return cursor ? { limit: PAGE_SIZE, cursor } : { limit: PAGE_SIZE };
489
+ }
490
+ async function queryFolder(folderId, cursor = "") {
491
+ return page(await call("POST", "/library-folder-items/query", {
492
+ ...folderId ? { filter: { parentLibraryItemIds: [folderId] } } : {},
493
+ paging: paging(cursor)
494
+ }));
495
+ }
496
+ async function searchLibrary(text2, folderId, cursor = "") {
497
+ const search = text2.trim().slice(0, SEARCH_MAX);
498
+ return page(await call("POST", "/library-items/query", {
499
+ filter: { search, ...folderId ? { descendantsOfFolderId: folderId } : {} },
500
+ paging: paging(cursor)
501
+ }));
502
+ }
503
+ async function appSettings() {
504
+ const data = await call("GET", "/settings");
505
+ return {
506
+ rootFolderId: typeof data?.rootFolderId === "string" ? data.rootFolderId : "",
507
+ whoCanDownload: typeof data?.settings?.downloadSettings?.whoCanDownload === "string" ? data.settings.downloadSettings.whoCanDownload : ""
508
+ };
509
+ }
510
+ async function authorize(itemIds, parentFolderId) {
511
+ const data = await call(
512
+ "POST",
513
+ "/authorize-actions",
514
+ { libraryItemIds: itemIds.slice(0, 100), ...parentFolderId ? { parentFolderId } : {} }
515
+ );
516
+ const items = /* @__PURE__ */ new Map();
517
+ const refusals = /* @__PURE__ */ new Map();
518
+ for (const row of data?.authorizedActions ?? []) {
519
+ if (!row?.itemId || !row.action) continue;
520
+ if (row.status === "ALLOWED") {
521
+ if (!items.has(row.itemId)) items.set(row.itemId, /* @__PURE__ */ new Set());
522
+ items.get(row.itemId).add(row.action);
523
+ } else {
524
+ if (!refusals.has(row.itemId)) refusals.set(row.itemId, /* @__PURE__ */ new Map());
525
+ refusals.get(row.itemId).set(row.action, row.reason ?? "");
526
+ }
527
+ }
528
+ const folder = /* @__PURE__ */ new Set();
529
+ for (const row of data?.folderAuthorizedActions ?? []) {
530
+ if (row?.action && row.status === "ALLOWED") folder.add(row.action);
531
+ }
532
+ return { items, refusals, folder };
533
+ }
534
+ async function downloadUrl(itemId) {
535
+ const data = await call("POST", "/library-items/download", { action: { libraryItemIds: [itemId] } });
536
+ if (typeof data?.url !== "string" || !data.url) throw new Error("wix-file-share: download returned no url");
537
+ return data.url;
538
+ }
539
+ async function viewUrl(itemId) {
540
+ const data = await call("POST", "/library-items/view-file", { actions: [{ libraryItemId: itemId }] });
541
+ const url = (data?.urls ?? []).find((row) => row?.libraryItemId === itemId)?.url ?? data?.urls?.[0]?.url;
542
+ if (typeof url !== "string" || !url) throw new Error("wix-file-share: view-file returned no url");
543
+ return url;
544
+ }
545
+ function refusalOf(row) {
546
+ const tooBig = row?.fileTooBig;
547
+ if (tooBig) return { kind: "tooBig", ...Number.isFinite(Number(tooBig.maxSize)) ? { maxSize: Number(tooBig.maxSize) } : {} };
548
+ const ext = row?.fileExtensionNotSupported;
549
+ if (ext) return { kind: "extension", ...typeof ext.extension === "string" ? { extension: ext.extension } : {} };
550
+ if (row?.quotaExceeded) return { kind: "quota" };
551
+ if (row?.videoFilesForbidden) return { kind: "video" };
552
+ return { kind: "unknown" };
553
+ }
554
+ async function startUpload(file, folderId, actionId) {
555
+ const data = await call("POST", "/files/start-upload", {
556
+ actions: [{ name: file.name, sizeInBytes: String(file.sizeBytes), ...folderId ? { parentFolderId: folderId } : {}, actionId }]
557
+ });
558
+ const failure4 = (data?.failures ?? []).find((row2) => row2?.actionId === actionId) ?? data?.failures?.[0];
559
+ if (failure4) return { refusal: refusalOf(failure4) };
560
+ const row = (data?.urls ?? []).find((candidate) => candidate?.actionId === actionId) ?? data?.urls?.[0];
561
+ const url = typeof row?.url === "string" ? row.url : "";
562
+ if (!url) return { refusal: { kind: "unknown" } };
563
+ const params = {};
564
+ for (const [key, value] of Object.entries(row?.requestParameters ?? {})) {
565
+ if (value !== void 0 && value !== null) params[key] = String(value);
566
+ }
567
+ return { target: { url, requestParameters: params, actionId } };
568
+ }
569
+ async function completeUpload(uploadResponse, folderId, actionId) {
570
+ const data = await call("POST", "/files/complete-upload", {
571
+ actions: [{ uploadResponse, ...folderId ? { parentFolderId: folderId } : {}, actionId }]
572
+ });
573
+ const failure4 = (data?.failures ?? []).find((row) => row?.actionId === actionId) ?? data?.failures?.[0];
574
+ if (failure4) return { refusal: refusalOf(failure4) };
575
+ const item = data?.libraryItems?.[0];
576
+ return item?.id ? { item } : { refusal: { kind: "unknown" } };
577
+ }
578
+ var B64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
579
+ function utf8Bytes(text2) {
580
+ const out = [];
581
+ for (const ch of text2) {
582
+ let code = ch.codePointAt(0);
583
+ if (code < 128) out.push(code);
584
+ else if (code < 2048) out.push(192 | code >> 6, 128 | code & 63);
585
+ else if (code < 65536) out.push(224 | code >> 12, 128 | code >> 6 & 63, 128 | code & 63);
586
+ else {
587
+ code = Math.min(code, 1114111);
588
+ out.push(240 | code >> 18, 128 | code >> 12 & 63, 128 | code >> 6 & 63, 128 | code & 63);
589
+ }
590
+ }
591
+ return out;
592
+ }
593
+ function base64Encode(bytes) {
594
+ let out = "";
595
+ for (let i = 0; i < bytes.length; i += 3) {
596
+ const a = bytes[i], b = bytes[i + 1], c = bytes[i + 2];
597
+ const n = a << 16 | (b ?? 0) << 8 | (c ?? 0);
598
+ out += B64[n >> 18 & 63] + B64[n >> 12 & 63] + (b === void 0 ? "=" : B64[n >> 6 & 63]) + (c === void 0 ? "=" : B64[n & 63]);
599
+ }
600
+ return out;
601
+ }
602
+ function decodeQuantum(quantum) {
603
+ const values = [...quantum].map((ch) => ch === "=" ? -1 : B64.indexOf(ch));
604
+ if (values.length !== 4 || values[0] < 0 || values[1] < 0 || values[2] < 0 && values[3] >= 0) {
605
+ throw new Error("wix-file-share: invalid base64");
606
+ }
607
+ const n = values[0] << 18 | values[1] << 12 | Math.max(values[2], 0) << 6 | Math.max(values[3], 0);
608
+ const bytes = [n >> 16 & 255];
609
+ if (values[2] >= 0) bytes.push(n >> 8 & 255);
610
+ if (values[3] >= 0) bytes.push(n & 255);
611
+ return bytes;
612
+ }
613
+ function quoted(value) {
614
+ return value.replace(/[\r\n]+/g, " ").replace(/["\\]/g, (ch) => `\\${ch}`);
615
+ }
616
+ function multipartBase64(fields, file, boundary) {
617
+ if (!/^[A-Za-z0-9'()+_,.\/:=?-]{1,70}$/.test(boundary)) throw new Error("wix-file-share: invalid boundary");
618
+ const fileB64 = file.base64.replace(/\s+/g, "");
619
+ if (fileB64.length % 4 !== 0 || /[^A-Za-z0-9+/=]/.test(fileB64) || /=[^=]/.test(fileB64)) throw new Error("wix-file-share: invalid base64");
620
+ const mime = /^[A-Za-z0-9!#$&^_.+-]+\/[A-Za-z0-9!#$&^_.+-]+$/.test(file.mimeType) ? file.mimeType : "application/octet-stream";
621
+ let head = "";
622
+ for (const [name, value] of Object.entries(fields)) {
623
+ head += `--${boundary}\r
624
+ Content-Disposition: form-data; name="${quoted(name)}"\r
625
+ \r
626
+ ${value}\r
627
+ `;
628
+ }
629
+ head += `--${boundary}\r
630
+ Content-Disposition: form-data; name="file"; filename="${quoted(file.name)}"\r
631
+ Content-Type: ${mime}\r
632
+ \r
633
+ `;
634
+ const headBytes = utf8Bytes(head);
635
+ const preamble = [[], [13, 10], [13, 10, 13, 10]][headBytes.length % 3];
636
+ const prefix = [...preamble, ...headBytes];
637
+ const body = fileB64.slice(0, Math.max(0, fileB64.length - 4));
638
+ const last = fileB64.length ? decodeQuantum(fileB64.slice(-4)) : [];
639
+ const tail = [...last, ...utf8Bytes(`\r
640
+ --${boundary}--\r
641
+ `)];
642
+ return base64Encode(prefix) + body + base64Encode(tail);
643
+ }
644
+ function formatSize(bytes) {
645
+ if (!Number.isFinite(bytes) || bytes < 0) return "";
646
+ if (bytes < 1024) return `${bytes} B`;
647
+ const units = ["KB", "MB", "GB", "TB"];
648
+ let value = bytes / 1024;
649
+ let unit = 0;
650
+ while (value >= 1024 && unit < units.length - 1) {
651
+ value /= 1024;
652
+ unit += 1;
653
+ }
654
+ return `${value >= 10 || Number.isInteger(value) ? Math.round(value) : value.toFixed(1)} ${units[unit]}`;
655
+ }
656
+ function sizeOf(item) {
657
+ const raw = item.fileFields?.sizeInBytes ?? item.fileFields?.size;
658
+ const n = typeof raw === "string" ? Number(raw) : raw;
659
+ return typeof n === "number" && Number.isFinite(n) && n >= 0 ? n : -1;
660
+ }
661
+
662
+ // ../../stdlib/flows/screens/src/file-share-service.ts
663
+ var SAVE_MAX_BYTES = 100 * 1024 * 1024;
664
+ var FILE_SHARE_INITIAL = Object.freeze({
665
+ status: "loading",
666
+ folderId: "",
667
+ trail: [],
668
+ folderTitle: "",
669
+ query: "",
670
+ rows: [],
671
+ nextCursor: "",
672
+ canUpload: false,
673
+ busy: false,
674
+ moreBusy: false,
675
+ message: "",
676
+ emptyText: "",
677
+ loadingHidden: false,
678
+ contentHidden: true,
679
+ emptyHidden: true,
680
+ errorHidden: true,
681
+ signInHidden: true,
682
+ forbiddenHidden: true,
683
+ notInstalledHidden: true,
684
+ moreHidden: true,
685
+ backHidden: true,
686
+ uploadHidden: true,
687
+ messageHidden: true
688
+ });
689
+ function readerChanged() {
690
+ const error = new Error("Member access changed");
691
+ error.name = "MemberAccessChanged";
692
+ return error;
693
+ }
694
+ async function currentReader() {
695
+ let email = "";
696
+ let identityUnavailable = false;
697
+ try {
698
+ const value = await dispatch("himi.wix.memberIdentity");
699
+ const raw = value?.email ?? value?.payload?.email;
700
+ email = typeof raw === "string" ? raw.trim().toLowerCase() : "";
701
+ } catch {
702
+ identityUnavailable = true;
703
+ }
704
+ if (!email && identityUnavailable) {
705
+ try {
706
+ const profile = await getMyData();
707
+ const raw = profile.email ?? profile.contactEmail;
708
+ email = typeof raw === "string" ? raw.trim().toLowerCase() : "";
709
+ } catch {
710
+ }
711
+ }
712
+ const input = globalThis.himalaya?.input;
713
+ const account = input?.__himiPreferenceAccount, business = input?.__himiPreferenceBusiness;
714
+ const valid = (v) => typeof v === "string" && /^[A-Za-z0-9_.:-]{1,128}$/.test(v) && v !== "default";
715
+ return {
716
+ email,
717
+ scope: email && valid(account) && valid(business) ? JSON.stringify([account, business, email]) : "",
718
+ tenant: JSON.stringify([account ?? "", business ?? ""])
719
+ };
720
+ }
721
+ async function assertSameReader(reader) {
722
+ const now = await currentReader();
723
+ if (now.email !== reader.email || now.scope !== reader.scope || now.tenant !== reader.tenant) throw readerChanged();
724
+ }
725
+ var isReaderChange = (error) => error?.name === "MemberAccessChanged";
726
+ function iconOf(item) {
727
+ if (item.folderFields || !item.fileFields) return "folder";
728
+ const category = item.fileFields.category ?? "";
729
+ if (category === "IMAGE") return "image";
730
+ if (category === "VIDEO") return "play";
731
+ if (category === "MUSIC") return "music";
732
+ return "doc";
733
+ }
734
+ function safeName(name) {
735
+ const cleaned = name.replace(/[\\/:*?"<>|\u0000-\u001f]+/g, "_").replace(/^\.+/, "").slice(0, 120);
736
+ return cleaned || "file";
737
+ }
738
+ async function discard(handle) {
739
+ if (handle) await remove(handle).catch(() => void 0);
740
+ }
741
+ var ROOT_POSITION = { folderId: "", trail: [], folderTitle: "", query: "" };
742
+ function createFileShareService(opts = {}) {
743
+ const overrides = opts.copy ?? {};
744
+ const t = opts.text ?? ((key, fallback) => typeof overrides[key] === "string" && overrides[key] !== "" ? overrides[key] : fallback);
745
+ const tf = (key, fallback, values) => t(key, fallback).replace(/\{([A-Za-z0-9_]+)\}/g, (_all, name) => name in values ? String(values[name]) : "");
746
+ let generation = 0;
747
+ let reader = "";
748
+ let rootFolderId = "";
749
+ let actionInFlight = false;
750
+ let known = /* @__PURE__ */ new Map();
751
+ let uploadSeq = 0;
752
+ const readerKey = (r) => JSON.stringify([r.email, r.scope, r.tenant]);
753
+ const current = (fallback) => svc?.getState?.() ?? fallback;
754
+ function subtitleOf(item, searching) {
755
+ const parts = [];
756
+ if (item.fileFields) {
757
+ const ext = (item.fileFields.extension ?? "").trim().toUpperCase();
758
+ if (ext) parts.push(ext);
759
+ const size = sizeOf(item);
760
+ if (size >= 0) parts.push(formatSize(size));
761
+ } else {
762
+ const count = Number(item.folderFields?.childrenCount);
763
+ if (Number.isFinite(count) && count >= 0) {
764
+ parts.push(count === 1 ? t("fileShare.itemCountOne", "1 item") : tf("fileShare.itemCount", "{count} items", { count }));
765
+ }
766
+ }
767
+ const availability2 = item.availability ?? item.folderFields?.availability;
768
+ if (availability2 === "MEMBER") parts.push(t("fileShare.membersOnly", "Members only"));
769
+ if (availability2 === "PAID") parts.push(t("fileShare.paidOnly", "Plan required"));
770
+ if (searching) {
771
+ const where = (item.path ?? []).map((p) => (p?.name ?? "").trim()).filter((name) => name && name !== "/");
772
+ if (where.length) parts.push(where.join(" / "));
773
+ }
774
+ return parts.join(" \xB7 ");
775
+ }
776
+ function rowsOf(items, access, searching) {
777
+ return items.filter((item) => item.id && item.name).map((item) => {
778
+ const isFolder = !item.fileFields;
779
+ const canSave = !isFolder && (!access.known || access.auth.items.get(item.id)?.has("DOWNLOAD") === true);
780
+ return {
781
+ id: item.id,
782
+ name: item.name,
783
+ isFolder,
784
+ subtitle: subtitleOf(item, searching),
785
+ icon: iconOf(item),
786
+ sizeBytes: sizeOf(item),
787
+ saveHidden: !canSave
788
+ };
789
+ });
790
+ }
791
+ function shown(state, rows, nextCursor, canUpload) {
792
+ known = new Map([...known, ...rows.map((row) => [row.id, row])]);
793
+ const searching = state.query.trim() !== "";
794
+ return {
795
+ ...state,
796
+ status: "ready",
797
+ rows,
798
+ nextCursor,
799
+ canUpload,
800
+ moreBusy: false,
801
+ emptyText: searching ? t("fileShare.noResults", "No files match your search.") : state.folderId ? t("fileShare.emptyFolder", "This folder is empty.") : t("fileShare.emptyLibrary", "No documents have been shared yet."),
802
+ loadingHidden: true,
803
+ contentHidden: rows.length === 0,
804
+ emptyHidden: rows.length > 0,
805
+ errorHidden: true,
806
+ signInHidden: true,
807
+ forbiddenHidden: true,
808
+ notInstalledHidden: true,
809
+ moreHidden: !nextCursor,
810
+ backHidden: state.trail.length === 0,
811
+ uploadHidden: !canUpload || searching
812
+ };
813
+ }
814
+ function failedState(state, next) {
815
+ return {
816
+ ...state,
817
+ status: next,
818
+ rows: [],
819
+ nextCursor: "",
820
+ canUpload: false,
821
+ moreBusy: false,
822
+ loadingHidden: true,
823
+ contentHidden: true,
824
+ emptyHidden: true,
825
+ errorHidden: next !== "error",
826
+ signInHidden: next !== "signIn",
827
+ forbiddenHidden: next !== "forbidden",
828
+ notInstalledHidden: next !== "notInstalled",
829
+ moreHidden: true,
830
+ backHidden: state.trail.length === 0,
831
+ uploadHidden: true
832
+ };
833
+ }
834
+ async function failureOf2(error) {
835
+ const status2 = httpStatus(error);
836
+ if (status2 === 428) return "notInstalled";
837
+ if (status2 === 401 || status2 === 403) {
838
+ const signedIn = await currentReader().then((r) => !!r.email).catch(() => false);
839
+ return signedIn ? "forbidden" : "signIn";
840
+ }
841
+ return "error";
842
+ }
843
+ async function authorizationFor(items, folderId) {
844
+ const files = items.filter((item) => item.id && item.fileFields).map((item) => item.id);
845
+ if (!files.length && !folderId) return { known: false };
846
+ try {
847
+ return { known: true, auth: await authorize(files, folderId) };
848
+ } catch (error) {
849
+ console.warn("[file-share] authorize-actions failed", error);
850
+ return { known: false };
851
+ }
852
+ }
853
+ async function fetchPage(snapshot, cursor, mine, given) {
854
+ try {
855
+ const access = given ?? await currentReader();
856
+ const searching = snapshot.query.trim() !== "";
857
+ const [root, page2] = await Promise.all([
858
+ rootFolderId ? Promise.resolve(rootFolderId) : appSettings().then((s2) => s2.rootFolderId).catch(() => ""),
859
+ searching ? searchLibrary(snapshot.query, snapshot.folderId, cursor) : queryFolder(snapshot.folderId, cursor)
860
+ ]);
861
+ const authFolder = searching ? "" : snapshot.folderId || root || (page2.items.find((item) => item.parentFolderId)?.parentFolderId ?? "");
862
+ const auth = await authorizationFor(page2.items, authFolder);
863
+ await assertSameReader(access);
864
+ if (root && mine === generation) rootFolderId = root;
865
+ return {
866
+ generation: mine,
867
+ cursor,
868
+ rows: rowsOf(page2.items, auth, searching),
869
+ nextCursor: page2.nextCursor,
870
+ canUpload: !searching && auth.known && auth.auth.folder.has("UPLOAD_FILE")
871
+ };
872
+ } catch (error) {
873
+ if (isReaderChange(error)) return { generation: mine, cursor, readerChanged: true };
874
+ return { generation: mine, cursor, failure: await failureOf2(error) };
875
+ }
876
+ }
877
+ async function applyRead(state, result) {
878
+ if (result.generation !== generation) return state;
879
+ if (result.readerChanged) return load(state);
880
+ if (result.failure) {
881
+ if (result.cursor) {
882
+ return { ...state, moreBusy: false, message: t("fileShare.moreFailed", "More files couldn't be loaded. Try again."), messageHidden: false };
883
+ }
884
+ return failedState(state, result.failure);
885
+ }
886
+ const rows = result.rows ?? [];
887
+ return shown(
888
+ state,
889
+ result.cursor ? [...state.rows, ...rows] : rows,
890
+ result.nextCursor ?? "",
891
+ result.cursor ? state.canUpload || result.canUpload === true : result.canUpload === true
892
+ );
893
+ }
894
+ function startRead(next, cursor = "") {
895
+ const mine = ++generation;
896
+ void fetchPage(next, cursor, mine).then((result) => svc.settleRead(result));
897
+ return next;
898
+ }
899
+ function loading(state, patch) {
900
+ return {
901
+ ...state,
902
+ ...patch,
903
+ status: "loading",
904
+ rows: [],
905
+ nextCursor: "",
906
+ canUpload: false,
907
+ moreBusy: false,
908
+ loadingHidden: false,
909
+ contentHidden: true,
910
+ emptyHidden: true,
911
+ errorHidden: true,
912
+ signInHidden: true,
913
+ forbiddenHidden: true,
914
+ notInstalledHidden: true,
915
+ moreHidden: true,
916
+ uploadHidden: true,
917
+ message: "",
918
+ messageHidden: true,
919
+ backHidden: (patch.trail ?? state.trail).length === 0
920
+ };
921
+ }
922
+ const titleFor = (trail) => trail.length ? trail[trail.length - 1].name : "";
923
+ async function load(state, arg) {
924
+ if (arg !== void 0) opts.onAppearArgs?.(arg);
925
+ const access = await currentReader().catch(() => void 0);
926
+ const key = access ? readerKey(access) : "";
927
+ const same = key !== "" && key === reader;
928
+ reader = key;
929
+ if (!same) {
930
+ rootFolderId = "";
931
+ known = /* @__PURE__ */ new Map();
932
+ }
933
+ const next = { ...loading(state, same ? {} : ROOT_POSITION), busy: actionInFlight };
934
+ const mine = ++generation;
935
+ const result = await fetchPage(next, "", mine, access);
936
+ return applyRead(result.generation === generation ? next : current(next), result);
937
+ }
938
+ function retry2(state) {
939
+ return startRead(loading(state, {}));
940
+ }
941
+ function openFolder(state, id2, name) {
942
+ const trail = [...state.trail, { id: id2, name }];
943
+ return startRead(loading(state, { folderId: id2, trail, folderTitle: titleFor(trail), query: "" }));
944
+ }
945
+ function back(state) {
946
+ if (!state.trail.length || state.busy) return state;
947
+ const trail = state.trail.slice(0, -1);
948
+ return startRead(loading(state, { folderId: trail.length ? trail[trail.length - 1].id : "", trail, folderTitle: titleFor(trail), query: "" }));
949
+ }
950
+ function search(state, arg) {
951
+ const query = String(arg?.value ?? "").slice(0, SEARCH_MAX);
952
+ if (query.trim() === state.query.trim()) return { ...state, query };
953
+ return startRead(loading(state, { query }));
954
+ }
955
+ function loadMore(state) {
956
+ if (!state.nextCursor || state.status !== "ready" || state.moreBusy) return state;
957
+ return startRead({ ...state, moreBusy: true, message: "", messageHidden: true }, state.nextCursor);
958
+ }
959
+ async function actionError(error, fallback) {
960
+ const status2 = httpStatus(error);
961
+ if (status2 === 401 || status2 === 403) {
962
+ const signedIn = await currentReader().then((r) => !!r.email).catch(() => false);
963
+ return signedIn ? t("fileShare.noAccess", "You don't have access to this file.") : t("fileShare.signInToOpen", "Sign in to open this file.");
964
+ }
965
+ if (status2 === 404) return t("fileShare.gone", "This file is no longer in the library.");
966
+ return fallback;
967
+ }
968
+ function settle(state, arg) {
969
+ const message = typeof arg?.message === "string" ? arg.message : "";
970
+ const next = { ...state, busy: false, message, messageHidden: !message };
971
+ const folder = typeof arg?.refreshFolder === "string" ? arg.refreshFolder : void 0;
972
+ return folder !== void 0 && folder === state.folderId && !state.query.trim() && state.status === "ready" ? startRead(next) : next;
973
+ }
974
+ function progress(state, arg) {
975
+ const message = typeof arg?.message === "string" ? arg.message : "";
976
+ return { ...state, message, messageHidden: !message };
977
+ }
978
+ function runAction(state, startMessage, work) {
979
+ actionInFlight = true;
980
+ const startedFor = reader;
981
+ void work().catch((error) => isReaderChange(error) ? "reload" : { message: t("fileShare.actionFailed", "That didn't work. Try again.") }).then(async (outcome) => {
982
+ actionInFlight = false;
983
+ if (reader !== startedFor) {
984
+ await svc.settle({ message: "" });
985
+ return;
986
+ }
987
+ if (outcome === "reload") {
988
+ await svc.settle({ message: "" });
989
+ await svc.load();
990
+ return;
991
+ }
992
+ await svc.settle(outcome);
993
+ });
994
+ return { ...state, busy: true, message: startMessage, messageHidden: !startMessage };
995
+ }
996
+ function openItem(state, arg) {
997
+ const id2 = String(arg?.id ?? "");
998
+ const row = state.rows.find((candidate) => candidate.id === id2);
999
+ if (!row || state.busy || actionInFlight) return state;
1000
+ if (row.isFolder) return openFolder(state, row.id, row.name);
1001
+ const failedText = t("fileShare.openFailed", "This file couldn't be opened. Try Save instead.");
1002
+ return runAction(state, "", async () => {
1003
+ const access = await currentReader();
1004
+ try {
1005
+ const url = await viewUrl(row.id);
1006
+ await assertSameReader(access);
1007
+ const { opened } = await open(url, "in_app_browser");
1008
+ return { message: opened ? "" : failedText };
1009
+ } catch (error) {
1010
+ if (isReaderChange(error)) return "reload";
1011
+ return { message: await actionError(error, failedText) };
1012
+ }
1013
+ });
1014
+ }
1015
+ function saveItem(state, arg) {
1016
+ const id2 = String(arg?.id ?? "");
1017
+ const row = state.rows.find((candidate) => candidate.id === id2) ?? known.get(id2);
1018
+ if (!row || row.isFolder || state.busy || actionInFlight) return state;
1019
+ const tooLarge = t("fileShare.tooLargeToSave", "This file is larger than 100 MB. Open it to view it in the browser.");
1020
+ if (row.sizeBytes > SAVE_MAX_BYTES) return { ...state, message: tooLarge, messageHidden: false };
1021
+ return runAction(state, t("fileShare.saving", "Preparing the file\u2026"), async () => {
1022
+ const access = await currentReader();
1023
+ let handle;
1024
+ const fetchFile = async () => {
1025
+ const url = await downloadUrl(row.id);
1026
+ await assertSameReader(access);
1027
+ return download(url, { name: `file-share/${row.id}/${safeName(row.name)}` });
1028
+ };
1029
+ try {
1030
+ try {
1031
+ handle = await fetchFile();
1032
+ } catch (error) {
1033
+ if (!(isFilesError(error) && error.code === "http_error" && error.status === 410)) throw error;
1034
+ handle = await fetchFile();
1035
+ }
1036
+ await assertSameReader(access);
1037
+ const { exported } = await exportFile(handle);
1038
+ return { message: exported ? tf("fileShare.saved", "Saved {name}.", { name: row.name }) : "" };
1039
+ } catch (error) {
1040
+ if (isReaderChange(error)) return "reload";
1041
+ if (isFilesError(error)) {
1042
+ if (error.code === "too_large") return { message: tooLarge };
1043
+ if (error.code === "unavailable") return { message: t("fileShare.saveUnavailable", "Saving files isn't available on this device. Open the file instead.") };
1044
+ return { message: t("fileShare.saveFailed", "The file couldn't be saved. Try again.") };
1045
+ }
1046
+ return { message: await actionError(error, t("fileShare.saveFailed", "The file couldn't be saved. Try again.")) };
1047
+ } finally {
1048
+ await discard(handle);
1049
+ }
1050
+ });
1051
+ }
1052
+ const uploadFailed = () => t("fileShare.uploadFailed", "The upload didn't finish. Nothing was added. Try again.");
1053
+ const appLimit = () => t("fileShare.uploadAppLimit", "Files over 7 MB can't be uploaded from the app. Upload them from the website.");
1054
+ function refusalText(refusal) {
1055
+ if (refusal.kind === "tooBig") {
1056
+ return refusal.maxSize ? tf("fileShare.uploadTooBigFor", "This file is too large for the library. The limit is {size}.", { size: formatSize(refusal.maxSize) }) : t("fileShare.uploadTooBig", "This file is too large for the library.");
1057
+ }
1058
+ if (refusal.kind === "extension") return t("fileShare.uploadType", "The library doesn't accept this type of file.");
1059
+ if (refusal.kind === "quota") return t("fileShare.uploadQuota", "The library is out of storage. Contact the business.");
1060
+ if (refusal.kind === "video") return t("fileShare.uploadVideo", "The library doesn't accept videos.");
1061
+ return uploadFailed();
1062
+ }
1063
+ function upload(state) {
1064
+ if (!state.canUpload || state.busy || actionInFlight || state.query.trim()) return state;
1065
+ const folderId = state.folderId;
1066
+ return runAction(state, "", async () => {
1067
+ const access = await currentReader();
1068
+ const picked = await pickDetailed({ maxBytes: UPLOAD_MAX_BYTES, maxItems: 1 }).catch(() => ({ items: [], rejected: [] }));
1069
+ const file = picked.items[0];
1070
+ if (!file) {
1071
+ const reason = picked.rejected[0]?.reason;
1072
+ if (!reason) return { message: "" };
1073
+ return { message: reason === "size" ? appLimit() : t("fileShare.uploadOne", "Pick one file at a time.") };
1074
+ }
1075
+ try {
1076
+ if (file.sizeBytes > UPLOAD_MAX_BYTES) return { message: appLimit() };
1077
+ await svc.progress({ message: tf("fileShare.uploading", "Uploading {name}\u2026", { name: file.name }) });
1078
+ const actionId = `himi-upload-${Date.now().toString(36)}-${uploadSeq += 1}`;
1079
+ const started = await startUpload({ name: file.name, sizeBytes: file.sizeBytes }, folderId, actionId);
1080
+ if (!started.target) return { message: refusalText(started.refusal ?? { kind: "unknown" }) };
1081
+ const boundary = `----himi${actionId.replace(/[^A-Za-z0-9]/g, "")}`;
1082
+ const body = multipartBase64(started.target.requestParameters, { name: file.name, mimeType: file.mimeType, base64: await readBase64(file) }, boundary);
1083
+ const sent = await put(started.target.url, { base64: body }, { method: "POST", contentType: `multipart/form-data; boundary=${boundary}` });
1084
+ if (!sent.ok || !sent.body || sent.body.length > UPLOAD_RESPONSE_MAX) return { message: uploadFailed() };
1085
+ await assertSameReader(access);
1086
+ const done = await completeUpload(sent.body, folderId, actionId);
1087
+ if (!done.item) return { message: refusalText(done.refusal ?? { kind: "unknown" }) };
1088
+ return { message: tf("fileShare.uploaded", "Added {name}.", { name: done.item.name ?? file.name }), refreshFolder: folderId };
1089
+ } catch (error) {
1090
+ if (isReaderChange(error)) return "reload";
1091
+ if (/presigned_upload/i.test(String(error?.message ?? ""))) {
1092
+ return { message: t("fileShare.uploadUnsupported", "Uploading to this library isn't available in the app yet. Upload from the website.") };
1093
+ }
1094
+ return { message: await actionError(error, uploadFailed()) };
1095
+ } finally {
1096
+ await discard(file);
1097
+ }
1098
+ });
1099
+ }
1100
+ const runOnlyKeys = Object.keys(FILE_SHARE_INITIAL);
1101
+ const svc = defineService(opts.service ?? "fileShare", {
1102
+ state: { ...FILE_SHARE_INITIAL },
1103
+ notHydrated: runOnlyKeys,
1104
+ notPersisted: runOnlyKeys,
1105
+ actions: {
1106
+ load,
1107
+ retry: retry2,
1108
+ back,
1109
+ search,
1110
+ loadMore,
1111
+ open: openItem,
1112
+ save: saveItem,
1113
+ upload,
1114
+ // Background completions (see STATE above), not UI actions.
1115
+ settleRead: applyRead,
1116
+ settle,
1117
+ progress
1118
+ }
1119
+ });
1120
+ return svc;
1121
+ }
1122
+
1123
+ // ../../stdlib/flows/screens/src/file-share-screen.ts
1124
+ var node2 = (id2, type, props, modifiers) => ({ id: id2, body: { package: "himalaya", type, props }, ...modifiers ? { modifiers } : {} });
1125
+ var DEFAULT_COPY = {
1126
+ title: "Documents",
1127
+ subtitle: "Files shared by this business.",
1128
+ searchPlaceholder: "Search documents",
1129
+ back: "Back",
1130
+ upload: "Upload a file",
1131
+ loading: "Loading documents\u2026",
1132
+ save: "Save",
1133
+ more: "Show more",
1134
+ errorTitle: "Documents are temporarily unavailable",
1135
+ errorBody: "Try again without leaving the app.",
1136
+ retry: "Try again",
1137
+ signInTitle: "Sign in to see these documents",
1138
+ signInBody: "Some documents are only for site members.",
1139
+ signIn: "Sign in",
1140
+ forbiddenTitle: "You don't have access",
1141
+ forbiddenBody: "This folder is limited to certain members or plans.",
1142
+ notInstalledTitle: "Documents are not set up",
1143
+ notInstalledBody: "This business hasn't added a file library yet."
1144
+ };
1145
+ function fileShareScreen(opts) {
1146
+ const s2 = opts.service ?? "fileShare";
1147
+ const id2 = opts.screenId ?? "file_share";
1148
+ const c = { ...DEFAULT_COPY, ...opts.copy ?? {} };
1149
+ const S = (field) => `$service:${s2}.${field}`;
1150
+ const act = (name, params) => ({ actionId: `tier5.${s2}.${name}`, ...params ? { params } : {} });
1151
+ const hidden = (n, field) => ({ ...n, modifiers: { ...n.modifiers ?? {}, hiddenPath: S(field) } });
1152
+ const text2 = (value, style, extra = {}, nodeId = "") => node2(nodeId, "Text", { text: value, style, ...extra });
1153
+ const card = (nodeId, children, field) => hidden(node2(nodeId, "VStack", { spacing: 8, alignment: "leading", children }, {
1154
+ background: { token: "surfaceSecondary" },
1155
+ border: { width: 1, color: { token: "border" } },
1156
+ cornerRadius: 4,
1157
+ padding: { leading: 16, trailing: 16, top: 16, bottom: 16 }
1158
+ }), field);
1159
+ const skeleton = (n) => node2(`${id2}.loading_line_${n}`, "Skeleton", { height: 18, cornerRadius: 8 }, {
1160
+ height: 18,
1161
+ background: { token: "surfaceSecondary" },
1162
+ cornerRadius: 8,
1163
+ accessibilityRole: "decorative"
1164
+ });
1165
+ const row = node2(`${id2}.row`, "ListItem", {
1166
+ leading: node2("", "Icon", { name: "$item.icon", size: 22, tint: "textSecondary" }, { accessibilityRole: "decorative" }),
1167
+ title: "$item.name",
1168
+ subtitle: "$item.subtitle",
1169
+ trailing: node2(`${id2}.save`, "Button", {
1170
+ title: c.save,
1171
+ action: act("save", { id: "$item.id" }),
1172
+ style: "tertiary",
1173
+ iconOnly: true,
1174
+ leadingIcon: "download",
1175
+ cornerRadius: 22,
1176
+ minHeight: 44,
1177
+ disabledPath: S("busy")
1178
+ }, { width: 44, height: 44, accessibilityLabel: c.save, accessibilityRole: "button", hiddenPath: "$item.saveHidden" }),
1179
+ onTap: act("open", { id: "$item.id" })
1180
+ });
1181
+ const root = node2(`${id2}.root`, "VStack", {
1182
+ spacing: 16,
1183
+ alignment: "leading",
1184
+ children: [
1185
+ text2(c.title, "title1", {}, `${id2}.title`),
1186
+ text2(c.subtitle, "body", { color: "textSecondary" }),
1187
+ node2(`${id2}.search`, "SearchField", { placeholder: c.searchPlaceholder, value: S("query"), debounceMs: 300, onChange: act("search") }),
1188
+ hidden(node2("", "HStack", {
1189
+ spacing: 8,
1190
+ alignment: "center",
1191
+ children: [
1192
+ node2(`${id2}.back`, "Button", { title: c.back, style: "tertiary", leadingIcon: "chevron_left", disabledPath: S("busy"), action: act("back") }),
1193
+ text2(S("folderTitle"), "bodyEmphasis", { maxLines: 1, collapseWhenEmpty: true }, `${id2}.folder_title`),
1194
+ node2("", "Spacer", {})
1195
+ ]
1196
+ }), "backHidden"),
1197
+ hidden(node2(`${id2}.upload`, "Button", { title: c.upload, style: "primary", leadingIcon: "plus", fullWidth: true, disabledPath: S("busy"), action: act("upload") }), "uploadHidden"),
1198
+ hidden(text2(S("message"), "footnote", { color: "textSecondary", collapseWhenEmpty: true }, `${id2}.message`), "messageHidden"),
1199
+ card(`${id2}.loading`, [text2(c.loading, "body", { color: "textSecondary" }), skeleton(1), skeleton(2), skeleton(3)], "loadingHidden"),
1200
+ hidden(node2(`${id2}.rows`, "Grid", { columns: 1, spacing: 0, itemsPath: S("rows"), items: [row] }), "contentHidden"),
1201
+ hidden(node2(`${id2}.more`, "Button", { title: c.more, style: "secondary", fullWidth: true, disabledPath: S("moreBusy"), action: act("loadMore") }), "moreHidden"),
1202
+ card(`${id2}.empty`, [
1203
+ node2("", "Icon", { name: "folder", size: 28, tint: "textSecondary" }, { accessibilityRole: "decorative" }),
1204
+ text2(S("emptyText"), "body", { color: "textSecondary", collapseWhenEmpty: true })
1205
+ ], "emptyHidden"),
1206
+ card(`${id2}.error`, [
1207
+ text2(c.errorTitle, "bodyEmphasis"),
1208
+ text2(c.errorBody, "footnote", { color: "textSecondary" }),
1209
+ node2(`${id2}.retry`, "Button", { title: c.retry, style: "secondary", action: act("retry") })
1210
+ ], "errorHidden"),
1211
+ card(`${id2}.sign_in_card`, [
1212
+ text2(c.signInTitle, "bodyEmphasis"),
1213
+ text2(c.signInBody, "footnote", { color: "textSecondary" }),
1214
+ node2(`${id2}.sign_in`, "Button", { title: c.signIn, style: "primary", leadingIcon: "person", action: { actionId: "himi.open", params: { screenId: opts.signInScreenId ?? "signin" } } })
1215
+ ], "signInHidden"),
1216
+ card(`${id2}.forbidden`, [text2(c.forbiddenTitle, "bodyEmphasis"), text2(c.forbiddenBody, "footnote", { color: "textSecondary" })], "forbiddenHidden"),
1217
+ card(`${id2}.not_installed`, [text2(c.notInstalledTitle, "bodyEmphasis"), text2(c.notInstalledBody, "footnote", { color: "textSecondary" })], "notInstalledHidden")
1218
+ ]
1219
+ }, {
1220
+ background: { token: "surfacePrimary" },
1221
+ padding: { leading: 16, trailing: 16, top: 18, bottom: 28 },
1222
+ onAppear: act("load")
1223
+ });
1224
+ return {
1225
+ screenId: id2,
1226
+ renderer: "sdui_intent",
1227
+ // The body carries the large title; a bar title too would show it twice.
1228
+ title: "",
1229
+ schemaVersion: 1,
1230
+ cacheControl: { maxAge: 0, staleWhileRevalidate: 0 },
1231
+ logicBundle: { url: opts.bundleUrl, integrity: "", declaredCapabilities: [...FILE_SHARE_CAPABILITIES] },
1232
+ // The root's modifiers carry the onAppear load: the payload is the whole node.
1233
+ payload: root
1234
+ };
1235
+ }
1236
+
327
1237
  // ../../stdlib/wix-sdk/media/src/rendition.ts
328
1238
  var FLUID_WIDTHS = [320, 640, 768, 1024, 1280, 1400, 2048];
329
1239
  var DESKTOP_PREVIEW_WIDTHS = [...FLUID_WIDTHS, 2560, 3072, 4096];
@@ -478,8 +1388,8 @@ function deeperThan(nodes, depth, max) {
478
1388
  var isObj = (v) => !!v && typeof v === "object" && !Array.isArray(v);
479
1389
  function ricosToPlainText(doc) {
480
1390
  const kids = (v) => Array.isArray(v) ? v.filter(isObj) : [];
481
- const inline = (node4) => typeof node4.textData?.text === "string" ? node4.textData.text : kids(node4.nodes).map(inline).join("");
482
- const blocks = (nodes) => nodes.flatMap((node4) => node4.type === "PARAGRAPH" || node4.type === "HEADING" || node4.type === "TEXT" ? [inline(node4)] : blocks(kids(node4.nodes)));
1391
+ const inline = (node5) => typeof node5.textData?.text === "string" ? node5.textData.text : kids(node5.nodes).map(inline).join("");
1392
+ const blocks = (nodes) => nodes.flatMap((node5) => node5.type === "PARAGRAPH" || node5.type === "HEADING" || node5.type === "TEXT" ? [inline(node5)] : blocks(kids(node5.nodes)));
483
1393
  return blocks(kids(doc?.nodes)).join("\n\n");
484
1394
  }
485
1395
  function plainTextToRicos(text2) {
@@ -554,29 +1464,29 @@ function cleanNodes(nodes, base, depth, ctx, parentType) {
554
1464
  if (!isObj(raw)) continue;
555
1465
  if (depth > RICH_CONTENT_LIMITS.maxDepth) throw TOO_DEEP;
556
1466
  const path = base === "" ? String(out.length) : `${base}.${out.length}`;
557
- const node4 = cleanNode({ ...raw }, path, depth, ctx, parentType);
558
- if (node4) out.push(node4);
1467
+ const node5 = cleanNode({ ...raw }, path, depth, ctx, parentType);
1468
+ if (node5) out.push(node5);
559
1469
  }
560
1470
  return out;
561
1471
  }
562
- function cleanNode(node4, path, depth, ctx, parentType) {
563
- if (node4.type === "TEXT") {
564
- const decorations = node4.textData?.decorations;
1472
+ function cleanNode(node5, path, depth, ctx, parentType) {
1473
+ if (node5.type === "TEXT") {
1474
+ const decorations = node5.textData?.decorations;
565
1475
  if (Array.isArray(decorations)) {
566
1476
  const kept = decorations.flatMap((d) => {
567
1477
  if (!(isObj(d) && d.type === "LINK")) return [d];
568
1478
  const next = rewriteAt(d, LINK_DECORATION_URL, cleanLink);
569
1479
  return getAt(next, LINK_DECORATION_URL) === void 0 ? [] : [next];
570
1480
  });
571
- node4.textData = { ...node4.textData, decorations: kept };
1481
+ node5.textData = { ...node5.textData, decorations: kept };
572
1482
  }
573
- } else if (node4.type === "IMAGE") {
574
- const data = isObj(node4.imageData) ? node4.imageData : {};
1483
+ } else if (node5.type === "IMAGE") {
1484
+ const data = isObj(node5.imageData) ? node5.imageData : {};
575
1485
  const url = ricosImageUrl(data, ctx.imageWidth);
576
1486
  if (!url) return null;
577
- node4.imageData = { ...data, image: { ...isObj(data.image) ? data.image : {}, src: { url } } };
578
- } else if (node4.type === "GALLERY") {
579
- const data = isObj(node4.galleryData) ? node4.galleryData : {};
1487
+ node5.imageData = { ...data, image: { ...isObj(data.image) ? data.image : {}, src: { url } } };
1488
+ } else if (node5.type === "GALLERY") {
1489
+ const data = isObj(node5.galleryData) ? node5.galleryData : {};
580
1490
  const items = (Array.isArray(data.items) ? data.items : []).flatMap((item) => {
581
1491
  if (!isObj(item) || !isObj(item.image)) return [];
582
1492
  const media = isObj(item.image.media) ? item.image.media : {};
@@ -584,9 +1494,9 @@ function cleanNode(node4, path, depth, ctx, parentType) {
584
1494
  return url ? [{ ...item, image: { ...item.image, media: { ...media, src: { url } } } }] : [];
585
1495
  });
586
1496
  if (items.length === 0) return null;
587
- node4.galleryData = { ...data, items };
588
- } else if (node4.type === "VIDEO") {
589
- const data = isObj(node4.videoData) ? { ...node4.videoData } : {};
1497
+ node5.galleryData = { ...data, items };
1498
+ } else if (node5.type === "VIDEO") {
1499
+ const data = isObj(node5.videoData) ? { ...node5.videoData } : {};
590
1500
  const video = isObj(data.video) ? data.video : {};
591
1501
  const url = ricosVideoUrl(video.src);
592
1502
  if (!url) return null;
@@ -594,32 +1504,32 @@ function cleanNode(node4, path, depth, ctx, parentType) {
594
1504
  const poster = ricosImageUrl({ image: data.thumbnail }, ctx.tileWidth);
595
1505
  if (poster) data.thumbnail = { ...data.thumbnail, src: { url: poster } };
596
1506
  else delete data.thumbnail;
597
- node4.videoData = data;
598
- } else if (node4.type === "BUTTON" || node4.type === "LINK_BUTTON") {
599
- node4.buttonData = rewriteAt(node4.buttonData, BUTTON_URL, cleanLink);
600
- if (getAt(node4.buttonData, BUTTON_URL) === void 0) return null;
601
- } else if (node4.type === "HTML") {
602
- node4.htmlData = rewriteAt(node4.htmlData, ["html"], drop);
603
- } else if (node4.type === "EMBED") {
604
- node4.embedData = rewriteAt(node4.embedData, ["oembed", "html"], drop);
605
- }
606
- for (const [field, ...rest] of (typeof node4.type === "string" ? LINK_FIELDS[node4.type] : void 0) ?? []) {
607
- if (field in node4) node4[field] = rewriteAt(node4[field], rest, cleanLink);
1507
+ node5.videoData = data;
1508
+ } else if (node5.type === "BUTTON" || node5.type === "LINK_BUTTON") {
1509
+ node5.buttonData = rewriteAt(node5.buttonData, BUTTON_URL, cleanLink);
1510
+ if (getAt(node5.buttonData, BUTTON_URL) === void 0) return null;
1511
+ } else if (node5.type === "HTML") {
1512
+ node5.htmlData = rewriteAt(node5.htmlData, ["html"], drop);
1513
+ } else if (node5.type === "EMBED") {
1514
+ node5.embedData = rewriteAt(node5.embedData, ["oembed", "html"], drop);
1515
+ }
1516
+ for (const [field, ...rest] of (typeof node5.type === "string" ? LINK_FIELDS[node5.type] : void 0) ?? []) {
1517
+ if (field in node5) node5[field] = rewriteAt(node5[field], rest, cleanLink);
608
1518
  }
609
1519
  const inBlocks = holdsBlocks(parentType);
610
- if (node4.type !== "TEXT" || inBlocks) {
611
- const own = typeof node4.id === "string" ? node4.id : "";
1520
+ if (node5.type !== "TEXT" || inBlocks) {
1521
+ const own = typeof node5.id === "string" ? node5.id : "";
612
1522
  const usable = own !== "" && !unusableId(own);
613
- if (inBlocks && !isWrapper(node4.type)) {
1523
+ if (inBlocks && !isWrapper(node5.type)) {
614
1524
  if (usable && !ctx.ids.has(own)) ctx.ids.add(own);
615
- else node4.id = path;
616
- } else if (!usable) node4.id = path;
1525
+ else node5.id = path;
1526
+ } else if (!usable) node5.id = path;
617
1527
  }
618
- if (Array.isArray(node4.nodes)) node4.nodes = cleanNodes(node4.nodes, path, depth + 1, ctx, typeof node4.type === "string" ? node4.type : "");
619
- return node4;
1528
+ if (Array.isArray(node5.nodes)) node5.nodes = cleanNodes(node5.nodes, path, depth + 1, ctx, typeof node5.type === "string" ? node5.type : "");
1529
+ return node5;
620
1530
  }
621
1531
  function countNodes(nodes) {
622
- return nodes.reduce((n, node4) => isObj(node4) ? n + 1 + (Array.isArray(node4.nodes) ? countNodes(node4.nodes) : 0) : n, 0);
1532
+ return nodes.reduce((n, node5) => isObj(node5) ? n + 1 + (Array.isArray(node5.nodes) ? countNodes(node5.nodes) : 0) : n, 0);
623
1533
  }
624
1534
  function canonicalJson(v, depth, max) {
625
1535
  if (depth > max) throw TOO_DEEP;
@@ -655,7 +1565,7 @@ var unsupported = () => failure("unsupported", "The referenced page uses an unsu
655
1565
  var isOneAppPageId = (value) => typeof value === "string" && /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(value);
656
1566
  function normalizeWebsiteLinks(nodes) {
657
1567
  let changed = 0;
658
- const normalize = (link) => {
1568
+ const normalize2 = (link) => {
659
1569
  const value = typeof link?.url === "string" ? link.url.trim() : "";
660
1570
  if (link && value && !/[\s\\@\u0000-\u001f\u007f]/.test(value) && /^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,63}(?:[/?#].*)?$/i.test(value)) {
661
1571
  link.url = `https://${value}`;
@@ -674,18 +1584,18 @@ function normalizeWebsiteLinks(nodes) {
674
1584
  GIF: [["gifData", "original", "gif"]],
675
1585
  IMAGE: [["imageData", "link", "url"]]
676
1586
  };
677
- for (const node4 of nodes) {
678
- for (const path of linkFields[node4.type ?? ""] ?? []) {
679
- const parent = object(path.slice(0, -1).reduce((value, key2) => object(value)[key2], node4));
1587
+ for (const node5 of nodes) {
1588
+ for (const path of linkFields[node5.type ?? ""] ?? []) {
1589
+ const parent = object(path.slice(0, -1).reduce((value, key2) => object(value)[key2], node5));
680
1590
  const key = path[path.length - 1];
681
1591
  const holder = { url: parent[key] };
682
- normalize(holder);
1592
+ normalize2(holder);
683
1593
  if (typeof holder.url === "string") parent[key] = holder.url;
684
1594
  }
685
- if (Array.isArray(node4.textData?.decorations)) for (const decoration of node4.textData.decorations) {
686
- if (object(decoration).type === "LINK") normalize(object(object(decoration).linkData).link);
1595
+ if (Array.isArray(node5.textData?.decorations)) for (const decoration of node5.textData.decorations) {
1596
+ if (object(decoration).type === "LINK") normalize2(object(object(decoration).linkData).link);
687
1597
  }
688
- if (Array.isArray(node4.nodes)) changed += normalizeWebsiteLinks(node4.nodes);
1598
+ if (Array.isArray(node5.nodes)) changed += normalizeWebsiteLinks(node5.nodes);
689
1599
  }
690
1600
  return changed;
691
1601
  }
@@ -788,14 +1698,14 @@ function decodeOneAppPage(response, expectedPageId) {
788
1698
  if (!encoded.json && authored) return unsupported();
789
1699
  return { pageId: expectedPageId, title: typeof content.title === "string" ? content.title : "", contentType, documentJson: encoded.json, plainText, empty: !authored, normalizedWebsiteLinks };
790
1700
  }
791
- function oneAppPageSection(page, options) {
1701
+ function oneAppPageSection(page2, options) {
792
1702
  if (!options.id) throw new Error("oneAppPageSection requires a stable placement id");
793
- if (page.empty) return { id: options.id, body: { package: "himalaya", type: "VStack", props: { spacing: 8, children: [
1703
+ if (page2.empty) return { id: options.id, body: { package: "himalaya", type: "VStack", props: { spacing: 8, children: [
794
1704
  { id: `${options.id}.empty_title`, body: { package: "himalaya", type: "Text", props: { text: options.emptyTitle ?? "No content yet", style: "bodyEmphasis" } } },
795
1705
  ...options.emptyDescription ? [{ id: `${options.id}.empty_description`, body: { package: "himalaya", type: "Text", props: { text: options.emptyDescription, style: "body" } } }] : []
796
1706
  ] } } };
797
1707
  return { id: options.id, body: { package: "himalaya", type: "RichContent", props: {
798
- documentJson: page.documentJson
1708
+ documentJson: page2.documentJson
799
1709
  } } };
800
1710
  }
801
1711
 
@@ -1635,7 +2545,7 @@ function mapPodcastFeed(response, describe = plain) {
1635
2545
  }
1636
2546
  return { ok: true, episodes, unplayable };
1637
2547
  }
1638
- var node2 = (id2, type, props, modifiers) => ({ id: id2, body: { package: "himalaya", type, props }, ...modifiers ? { modifiers } : {} });
2548
+ var node3 = (id2, type, props, modifiers) => ({ id: id2, body: { package: "himalaya", type, props }, ...modifiers ? { modifiers } : {} });
1639
2549
  var PODCAST_SCREEN_CAPABILITIES = ["wix_api", "media_playback"];
1640
2550
  function podcastFeedSetting(raw) {
1641
2551
  const configured = podcastFeedUrl(raw);
@@ -1661,47 +2571,47 @@ function podcastScreen(opts) {
1661
2571
  };
1662
2572
  const bind = (field) => `$service:${s2}.${field}`;
1663
2573
  const act = (action2, params) => ({ actionId: `tier5.${s2}.${action2}`, ...params ? { params } : {} });
1664
- const text2 = (key, value, style, extra = {}) => node2(`${id2}.${key}`, "Text", { text: value, style, collapseWhenEmpty: true, ...extra });
2574
+ const text2 = (key, value, style, extra = {}) => node3(`${id2}.${key}`, "Text", { text: value, style, collapseWhenEmpty: true, ...extra });
1665
2575
  const hiddenWhen = (n, field) => ({ ...n, modifiers: { ...n.modifiers ?? {}, hiddenPath: bind(field) } });
1666
- const iconButton = (key, icon, label, action2) => node2(`${id2}.${key}`, "Button", { title: label, leadingIcon: icon, iconOnly: true, style: "plain", action: action2 });
1667
- const row = node2(`${id2}.episode`, "ListItem", {
2576
+ const iconButton = (key, icon, label, action2) => node3(`${id2}.${key}`, "Button", { title: label, leadingIcon: icon, iconOnly: true, style: "plain", action: action2 });
2577
+ const row = node3(`${id2}.episode`, "ListItem", {
1668
2578
  title: "$item.title",
1669
2579
  subtitle: "$item.subtitle",
1670
2580
  overline: "$item.progressLabel",
1671
- leading: node2(`${id2}.episode_art`, "Image", { url: "$item.image", initials: "P", width: 56, height: 56, contentMode: "fill", shape: "rounded", contentDescription: "$item.title" }),
2581
+ leading: node3(`${id2}.episode_art`, "Image", { url: "$item.image", initials: "P", width: 56, height: 56, contentMode: "fill", shape: "rounded", contentDescription: "$item.title" }),
1672
2582
  trailing: iconButton("episode_queue", "list", c.queue, act("queueEpisode", { id: "$item.id" })),
1673
2583
  onTap: act("playEpisode", { id: "$item.id" })
1674
2584
  }, { accessibilityLabel: "$item.title" });
1675
- const list = node2(`${id2}.episodes`, "LazyList", { itemsPath: bind("episodes"), items: [row], spacing: 0 });
1676
- const feedStatus = node2(`${id2}.feed_status`, "VStack", { spacing: 8, alignment: "leading", children: [
2585
+ const list = node3(`${id2}.episodes`, "LazyList", { itemsPath: bind("episodes"), items: [row], spacing: 0 });
2586
+ const feedStatus = node3(`${id2}.feed_status`, "VStack", { spacing: 8, alignment: "leading", children: [
1677
2587
  text2("feed_message", bind("emptyText"), "body", { color: "textSecondary" }),
1678
- hiddenWhen(node2(`${id2}.feed_retry`, "Button", { title: c.retry, style: "secondary", action: act("retryFeed") }), "hideFeedRetry")
2588
+ hiddenWhen(node3(`${id2}.feed_retry`, "Button", { title: c.retry, style: "secondary", action: act("retryFeed") }), "hideFeedRetry")
1679
2589
  ] });
1680
- const payload = node2(`${id2}.root`, "VStack", { spacing: 16, alignment: "leading", children: [
2590
+ const payload = node3(`${id2}.root`, "VStack", { spacing: 16, alignment: "leading", children: [
1681
2591
  text2("title", c.title, "title1"),
1682
2592
  list,
1683
2593
  feedStatus
1684
2594
  ] }, { padding: { leading: 16, trailing: 16, top: 16, bottom: 24 }, onAppear: act("load", { feedUrl }) });
1685
- const player = hiddenWhen(node2(`${id2}.player`, "VStack", { spacing: 8, alignment: "leading", children: [
2595
+ const player = hiddenWhen(node3(`${id2}.player`, "VStack", { spacing: 8, alignment: "leading", children: [
1686
2596
  text2("now_title", bind("nowTitle"), "body", { maxLines: 1 }),
1687
2597
  text2("now_subtitle", bind("nowSubtitle"), "caption", { color: "textSecondary", maxLines: 1 }),
1688
- node2(
2598
+ node3(
1689
2599
  `${id2}.scrubber`,
1690
2600
  "Slider",
1691
2601
  { value: 0, min: 0, max: 1, step: 1e-3, valuePath: bind("progress"), debounceMs: 250, onChange: act("seek") },
1692
2602
  { accessibilityLabel: c.seek, accessibilityValue: bind("progressLabel") }
1693
2603
  ),
1694
2604
  text2("progress", bind("progressLabel"), "caption", { color: "textSecondary" }),
1695
- node2(`${id2}.controls`, "HStack", { spacing: 8, children: [
2605
+ node3(`${id2}.controls`, "HStack", { spacing: 8, children: [
1696
2606
  iconButton("previous", "skip_previous", c.previous, act("previousEpisode")),
1697
2607
  iconButton("back", "undo", c.back, act("seekBy", { deltaMs: "-15000" })),
1698
- node2(`${id2}.toggle`, "Button", { title: bind("playLabel"), leadingIcon: bind("playIcon"), style: "primary", action: act("togglePlay") }),
2608
+ node3(`${id2}.toggle`, "Button", { title: bind("playLabel"), leadingIcon: bind("playIcon"), style: "primary", action: act("togglePlay") }),
1699
2609
  iconButton("forward", "refresh", c.forward, act("seekBy", { deltaMs: "30000" })),
1700
2610
  iconButton("next", "skip_next", c.next, act("nextEpisode"))
1701
2611
  ] }),
1702
- hiddenWhen(node2(`${id2}.playback_error`, "VStack", { spacing: 6, alignment: "leading", children: [
2612
+ hiddenWhen(node3(`${id2}.playback_error`, "VStack", { spacing: 6, alignment: "leading", children: [
1703
2613
  text2("playback_error_text", bind("playbackErrorText"), "caption", { color: "danger" }),
1704
- hiddenWhen(node2(`${id2}.playback_retry`, "Button", { title: c.retry, style: "secondary", action: act("retryPlayback") }), "hidePlaybackRetry")
2614
+ hiddenWhen(node3(`${id2}.playback_retry`, "Button", { title: c.retry, style: "secondary", action: act("retryPlayback") }), "hidePlaybackRetry")
1705
2615
  ] }), "hidePlaybackError")
1706
2616
  ] }, { background: { token: "surfaceSecondary" }, padding: { leading: 16, trailing: 16, top: 10, bottom: 12 } }), "hidePlayer");
1707
2617
  return {
@@ -2247,7 +3157,7 @@ function normalizeStatus(raw) {
2247
3157
  }
2248
3158
 
2249
3159
  // ../../stdlib/wix-sdk/pricing-plans/src/index.ts
2250
- function wixCall(method, path, body, readOptions) {
3160
+ function wixCall2(method, path, body, readOptions) {
2251
3161
  if (!globalThis.himalaya?.wixApi) {
2252
3162
  return Promise.reject(
2253
3163
  new Error("@himalaya/wix-pricing-plans: host did not install the wixApi bridge")
@@ -2264,7 +3174,7 @@ function wixCall(method, path, body, readOptions) {
2264
3174
  return readOptions?.site ? api.call(method, path, body, { "wix-site-id": readOptions.site }) : api.call(method, path, body);
2265
3175
  }
2266
3176
  function listPublicPlans(readOptions) {
2267
- return wixCall("GET", "/pricing-plans/v2/plans/public", void 0, readOptions);
3177
+ return wixCall2("GET", "/pricing-plans/v2/plans/public", void 0, readOptions);
2268
3178
  }
2269
3179
  function listMyPlanOrders(opts = {}, readOptions) {
2270
3180
  const qs = [
@@ -2274,10 +3184,10 @@ function listMyPlanOrders(opts = {}, readOptions) {
2274
3184
  ...opts.fieldSet === void 0 ? [] : [`fieldSet=${encodeURIComponent(opts.fieldSet)}`]
2275
3185
  ];
2276
3186
  const path = "/pricing-plans/v2/member/orders" + (qs.length ? `?${qs.join("&")}` : "");
2277
- return wixCall("GET", path, void 0, readOptions);
3187
+ return wixCall2("GET", path, void 0, readOptions);
2278
3188
  }
2279
3189
  function createOnlineOrder(planId, couponCode) {
2280
- return wixCall("POST", "/pricing-plans/v2/checkout/orders/online", couponCode ? { planId, couponCode } : { planId });
3190
+ return wixCall2("POST", "/pricing-plans/v2/checkout/orders/online", couponCode ? { planId, couponCode } : { planId });
2281
3191
  }
2282
3192
 
2283
3193
  // ../../stdlib/flows/checkout/src/index.ts
@@ -2288,9 +3198,9 @@ async function entitlement(planId) {
2288
3198
  for (let offset = 0; ; offset += 50) {
2289
3199
  const res = await listMyPlanOrders({ statuses: [GRANTS_ACCESS], limit: 50, offset });
2290
3200
  const orders = res.orders ?? [];
2291
- const page = JSON.stringify(orders.map((order) => [order.id, order.planId, order.status]));
2292
- if (orders.length === 50 && pages.has(page)) break;
2293
- pages.add(page);
3201
+ const page2 = JSON.stringify(orders.map((order) => [order.id, order.planId, order.status]));
3202
+ if (orders.length === 50 && pages.has(page2)) break;
3203
+ pages.add(page2);
2294
3204
  const active = orders.find((order) => order.status === GRANTS_ACCESS && (!planId || order.planId === planId));
2295
3205
  if (active) return { entitled: true, planName: active.planName ?? "", planId: active.planId ?? "" };
2296
3206
  if (orders.length < 50) break;
@@ -2679,12 +3589,12 @@ function createPurchaseCoordinator(deps) {
2679
3589
  function isCurrent(session) {
2680
3590
  return !disposed && session.generation === generation && sessionMatches();
2681
3591
  }
2682
- async function settle(session, call) {
3592
+ async function settle(session, call2) {
2683
3593
  const stale = staleSignal.waiter();
2684
3594
  try {
2685
3595
  const pending = Promise.resolve().then(() => {
2686
3596
  if (!isCurrent(session)) throw ABANDONED;
2687
- return call();
3597
+ return call2();
2688
3598
  });
2689
3599
  const settled = await Promise.race([pending.then((value) => ({ kind: "value", value })), stale.fired.then(() => STALE)]);
2690
3600
  return isCurrent(session) ? settled : STALE;
@@ -2762,9 +3672,9 @@ var FINISH_ALLOWED_STATE = {
2762
3672
  var noDelivery = () => ({ finished: false, confirmedProducts: [], signInLost: false });
2763
3673
  var STALE = { kind: "stale" };
2764
3674
  var ABANDONED = { abandoned: true };
2765
- async function storeCall(call) {
3675
+ async function storeCall(call2) {
2766
3676
  try {
2767
- return await call();
3677
+ return await call2();
2768
3678
  } catch {
2769
3679
  return { status: "failed", code: "storeError" };
2770
3680
  }
@@ -3082,12 +3992,12 @@ function createWixIapMappingSource(deps) {
3082
3992
  }
3083
3993
  var PATH = `${HIMALAYA_SERVE_IAP_ROUTE.prefix}/mappings`;
3084
3994
  var BATCH = 100;
3085
- async function resolveAll(call, binding, ids) {
3995
+ async function resolveAll(call2, binding, ids) {
3086
3996
  const mapped = /* @__PURE__ */ new Map();
3087
3997
  const wanted = new Set(ids);
3088
3998
  for (let at = 0; at < ids.length; at += BATCH) {
3089
3999
  const batch = ids.slice(at, at + BATCH);
3090
- const reply = await call("POST", PATH, { appId: binding.purchasesAppId, appProductIds: batch }, { "wix-site-id": binding.siteId });
4000
+ const reply = await call2("POST", PATH, { appId: binding.purchasesAppId, appProductIds: batch }, { "wix-site-id": binding.siteId });
3091
4001
  for (const [id2, mapping] of decodeMappings(reply)) if (wanted.has(id2)) mapped.set(id2, mapping);
3092
4002
  }
3093
4003
  return mapped;
@@ -3545,15 +4455,15 @@ function failure2(operation, kind) {
3545
4455
  return { status: "failed", operation, kind };
3546
4456
  }
3547
4457
  function classifyHttp(refusal) {
3548
- const { operation, codes: codes2, httpStatus, code } = refusal;
4458
+ const { operation, codes: codes2, httpStatus: httpStatus2, code } = refusal;
3549
4459
  if (code === "PRINCIPAL_CHANGED") return failure2(operation, "sessionChanged");
3550
- if (isOneOf(codes2, code)) return { status: "failed", operation, kind: "application", code, httpStatus };
3551
- return { status: "failed", operation, kind: kindForStatus(httpStatus, code), httpStatus };
4460
+ if (isOneOf(codes2, code)) return { status: "failed", operation, kind: "application", code, httpStatus: httpStatus2 };
4461
+ return { status: "failed", operation, kind: kindForStatus(httpStatus2, code), httpStatus: httpStatus2 };
3552
4462
  }
3553
- function kindForStatus(httpStatus, code) {
3554
- if (code === "UNAVAILABLE" || httpStatus === 408 || httpStatus === 429 || httpStatus >= 500) return "unavailable";
3555
- if (httpStatus === 401 || code === "UNAUTHENTICATED") return "authRequired";
3556
- if (httpStatus === 403 || code === "PERMISSION_DENIED") return "notPermitted";
4463
+ function kindForStatus(httpStatus2, code) {
4464
+ if (code === "UNAVAILABLE" || httpStatus2 === 408 || httpStatus2 === 429 || httpStatus2 >= 500) return "unavailable";
4465
+ if (httpStatus2 === 401 || code === "UNAUTHENTICATED") return "authRequired";
4466
+ if (httpStatus2 === 403 || code === "PERMISSION_DENIED") return "notPermitted";
3557
4467
  return "unrecognized";
3558
4468
  }
3559
4469
  function post(scope, route, body) {
@@ -3727,9 +4637,9 @@ function createWixIapClient(deps) {
3727
4637
  }
3728
4638
  return { startPayment, startItemPayment, completePayment, getPayment, cancelPayment };
3729
4639
  }
3730
- async function attempt2(transport, call, spec, expectation) {
4640
+ async function attempt2(transport, call2, spec, expectation) {
3731
4641
  try {
3732
- const answer = expectation ? await transport.call(call.method, call.path, call.body, call.headers, expectation) : await transport.call(call.method, call.path, call.body, call.headers);
4642
+ const answer = expectation ? await transport.call(call2.method, call2.path, call2.body, call2.headers, expectation) : await transport.call(call2.method, call2.path, call2.body, call2.headers);
3733
4643
  return { answer };
3734
4644
  } catch (error) {
3735
4645
  return { failure: classifyFailure(error, spec.operation, spec.codes), handedOff: true };
@@ -3746,9 +4656,9 @@ function outcomeUnknown(failed) {
3746
4656
  const status2 = failed.httpStatus === void 0 ? {} : { httpStatus: failed.httpStatus };
3747
4657
  return { status: "outcomeUnknown", operation: "startItemPayment", kind: failed.kind, ...status2 };
3748
4658
  }
3749
- async function read(call, operation) {
4659
+ async function read(call2, operation) {
3750
4660
  try {
3751
- return { value: await call() };
4661
+ return { value: await call2() };
3752
4662
  } catch (error) {
3753
4663
  return { failure: classifyFailure(error, operation, []) };
3754
4664
  }
@@ -4240,14 +5150,14 @@ var EVICTABLE = /* @__PURE__ */ new Set(["fulfilled", "ordered", "charged", "sta
4240
5150
  // ../../stdlib/flows/iap-checkout/src/wix-bridge.ts
4241
5151
  function bindBridge(session, provider, bridge) {
4242
5152
  const isCurrent = () => session.kind === "member" && provider.current().generation === session.generation;
4243
- async function call(method, path, body) {
5153
+ async function call2(method, path, body) {
4244
5154
  if (!isCurrent()) return SESSION_CHANGED;
4245
5155
  const expectation = boundExpectation(session, provider, bridge);
4246
5156
  if (expectation === "refuse") return { status: "notEnabled" };
4247
5157
  const outcome = await attempt3(bridge, method, path, body, expectation);
4248
5158
  return isCurrent() ? outcome : SESSION_CHANGED;
4249
5159
  }
4250
- return { call, isCurrent };
5160
+ return { call: call2, isCurrent };
4251
5161
  }
4252
5162
  function hostBridge() {
4253
5163
  const himalaya = globalThis.himalaya;
@@ -4260,7 +5170,7 @@ async function attempt3(bridge, method, path, body, expectation) {
4260
5170
  const answer = expectation ? await bridge.call(method, path, body, void 0, expectation) : await bridge.call(method, path, body);
4261
5171
  return { status: "ok", body: answer };
4262
5172
  } catch (error) {
4263
- return refusalOf(error);
5173
+ return refusalOf2(error);
4264
5174
  }
4265
5175
  }
4266
5176
  function boundExpectation(session, provider, bridge) {
@@ -4274,7 +5184,7 @@ function isLiveHost(bridge) {
4274
5184
  const api = globalThis.himalaya?.wixApi;
4275
5185
  return api != null && (bridge === api || bridge.call === api.call);
4276
5186
  }
4277
- function refusalOf(error) {
5187
+ function refusalOf2(error) {
4278
5188
  const message = error?.message;
4279
5189
  const text2 = typeof message === "string" ? message : "";
4280
5190
  if (BRIDGE_REFUSAL2.test(text2)) return { status: "notEnabled" };
@@ -4283,10 +5193,10 @@ function refusalOf(error) {
4283
5193
  if (!http) return { status: "unavailable" };
4284
5194
  return httpRefusal(Number(http[1]), http[2] ?? "");
4285
5195
  }
4286
- function httpRefusal(httpStatus, code) {
5196
+ function httpRefusal(httpStatus2, code) {
4287
5197
  if (code === "PRINCIPAL_CHANGED") return SESSION_CHANGED;
4288
- if (code === "UNAVAILABLE" || httpStatus === 408 || httpStatus === 429 || httpStatus >= 500) return { status: "unavailable" };
4289
- return { status: "http", httpStatus, code };
5198
+ if (code === "UNAVAILABLE" || httpStatus2 === 408 || httpStatus2 === 429 || httpStatus2 >= 500) return { status: "unavailable" };
5199
+ return { status: "http", httpStatus: httpStatus2, code };
4290
5200
  }
4291
5201
  var SESSION_CHANGED = { status: "sessionChanged" };
4292
5202
  var BRIDGE_REFUSAL2 = /^(wixApi not enabled|capability wix_api not allowed)\b|^NotInstalled\(\)$/;
@@ -5660,9 +6570,9 @@ async function planAccess(planId, bridge) {
5660
6570
  if (isRefusal(answer)) return accessRefused(answer);
5661
6571
  const orders = answer.body?.orders;
5662
6572
  if (!Array.isArray(orders)) return "unavailable";
5663
- const page = JSON.stringify(orders.map((order) => [order.id, order.planId, order.status]));
5664
- if (orders.length === 50 && pages.has(page)) return "unavailable";
5665
- pages.add(page);
6573
+ const page2 = JSON.stringify(orders.map((order) => [order.id, order.planId, order.status]));
6574
+ if (orders.length === 50 && pages.has(page2)) return "unavailable";
6575
+ pages.add(page2);
5666
6576
  const selected = orders.filter((order) => order.planId === planId);
5667
6577
  if (selected.some((order) => order.status === "ACTIVE")) return "granted";
5668
6578
  pending || (pending = selected.some((order) => order.status === "PENDING" || order.status === "DRAFT"));
@@ -5737,9 +6647,9 @@ async function readAccess(verticalRef, port) {
5737
6647
  return ENDED.has(purchase.status) ? "none" : "unavailable";
5738
6648
  }
5739
6649
  function dataAt(body, path) {
5740
- let node4 = isObject7(body) && isObject7(body.data) ? body.data : body;
5741
- for (const key of path) node4 = isObject7(node4) ? node4[key] : void 0;
5742
- return isObject7(node4) ? node4 : null;
6650
+ let node5 = isObject7(body) && isObject7(body.data) ? body.data : body;
6651
+ for (const key of path) node5 = isObject7(node5) ? node5[key] : void 0;
6652
+ return isObject7(node5) ? node5 : null;
5743
6653
  }
5744
6654
  var ENDED = /* @__PURE__ */ new Set(["DECLINED", "EXPIRED", "CANCELED", "REFUNDED", "FAILED"]);
5745
6655
  var UNPAID = /* @__PURE__ */ new Set(["INITIALIZED", "PENDING"]);
@@ -5761,7 +6671,7 @@ function wixCallHeaders(opts) {
5761
6671
  const site = opts?.site?.trim();
5762
6672
  return site ? { "wix-site-id": site } : void 0;
5763
6673
  }
5764
- function wixCall2(method, path, body, opts) {
6674
+ function wixCall3(method, path, body, opts) {
5765
6675
  if (!globalThis.himalaya?.wixApi) {
5766
6676
  return Promise.reject(
5767
6677
  new Error(
@@ -5791,7 +6701,7 @@ function wixCall2(method, path, body, opts) {
5791
6701
  return api.call(method, path, body, wixCallHeaders(opts));
5792
6702
  }
5793
6703
  function createRedirectSession(req = {}, opts) {
5794
- return wixCall2(
6704
+ return wixCall3(
5795
6705
  "POST",
5796
6706
  "/_api/redirects-api/v1/redirect-session",
5797
6707
  req,
@@ -5801,14 +6711,14 @@ function createRedirectSession(req = {}, opts) {
5801
6711
 
5802
6712
  // ../../stdlib/flows/screens/src/index.ts
5803
6713
  var PKG = "himalaya";
5804
- var node3 = (id2, type, props) => ({ id: id2, body: { package: PKG, type, props } });
6714
+ var node4 = (id2, type, props) => ({ id: id2, body: { package: PKG, type, props } });
5805
6715
  var hideWhen = (n, path) => ({
5806
6716
  ...n,
5807
6717
  modifiers: { ...n.modifiers ?? {}, hiddenPath: path }
5808
6718
  });
5809
- var text = (id2, value, style = "body") => node3(id2, "Text", { text: value, style });
5810
- var vstack = (id2, children, spacing = 12, alignment = "leading") => node3(id2, "VStack", { spacing, alignment, children });
5811
- var button = (id2, title, action2, style = "primary") => node3(id2, "Button", { title, style, fullWidth: true, action: action2 });
6719
+ var text = (id2, value, style = "body") => node4(id2, "Text", { text: value, style });
6720
+ var vstack = (id2, children, spacing = 12, alignment = "leading") => node4(id2, "VStack", { spacing, alignment, children });
6721
+ var button = (id2, title, action2, style = "primary") => node4(id2, "Button", { title, style, fullWidth: true, action: action2 });
5812
6722
  var openScreen = (screenId) => ({ actionId: "himi.open", params: { screenId } });
5813
6723
  function detailedHeader(opts) {
5814
6724
  const id2 = opts.id ?? "detailed_header";
@@ -5816,7 +6726,7 @@ function detailedHeader(opts) {
5816
6726
  if (opts.logoUrl || opts.locationLabel) {
5817
6727
  const identity = [];
5818
6728
  if (opts.logoUrl) {
5819
- identity.push(node3(`${id2}.logo`, "Image", {
6729
+ identity.push(node4(`${id2}.logo`, "Image", {
5820
6730
  url: opts.logoUrl,
5821
6731
  width: 56,
5822
6732
  height: 56,
@@ -5827,12 +6737,12 @@ function detailedHeader(opts) {
5827
6737
  }
5828
6738
  if (opts.locationLabel) {
5829
6739
  if (opts.locationAction) {
5830
- identity.push(node3(`${id2}.locationGroup`, "HStack", {
6740
+ identity.push(node4(`${id2}.locationGroup`, "HStack", {
5831
6741
  spacing: 8,
5832
6742
  alignment: "center",
5833
6743
  children: [
5834
6744
  text(`${id2}.location`, opts.locationLabel, "caption"),
5835
- node3(`${id2}.location.action`, "Button", {
6745
+ node4(`${id2}.location.action`, "Button", {
5836
6746
  title: opts.locationAction.label,
5837
6747
  style: opts.locationAction.style ?? "plain",
5838
6748
  fullWidth: false,
@@ -5844,10 +6754,10 @@ function detailedHeader(opts) {
5844
6754
  identity.push(text(`${id2}.location`, opts.locationLabel, "caption"));
5845
6755
  }
5846
6756
  }
5847
- cardChildren.push(node3(`${id2}.identity`, "HStack", { spacing: 12, alignment: "center", children: identity }));
6757
+ cardChildren.push(node4(`${id2}.identity`, "HStack", { spacing: 12, alignment: "center", children: identity }));
5848
6758
  }
5849
6759
  if (opts.memberCaption || opts.memberAvatarsPath || opts.memberAvatars?.length) {
5850
- cardChildren.push(node3(`${id2}.members`, "AvatarStrip", {
6760
+ cardChildren.push(node4(`${id2}.members`, "AvatarStrip", {
5851
6761
  size: 36,
5852
6762
  maxVisible: 5,
5853
6763
  ...opts.memberCaption ? { caption: opts.memberCaption } : {},
@@ -5862,7 +6772,7 @@ function detailedHeader(opts) {
5862
6772
  ]) {
5863
6773
  if (action2) cardChildren.push(button(`${id2}.${key}`, action2.label, action2.action, action2.style ?? (key === "primary" ? "primary" : "secondary")));
5864
6774
  }
5865
- const card = node3(`${id2}.card`, "VStack", {
6775
+ const card = node4(`${id2}.card`, "VStack", {
5866
6776
  spacing: 14,
5867
6777
  alignment: "leading",
5868
6778
  children: cardChildren
@@ -5875,7 +6785,7 @@ function detailedHeader(opts) {
5875
6785
  fillMaxWidth: true
5876
6786
  };
5877
6787
  const fixed = opts.collapsible === false;
5878
- return node3(id2, "CollapsingHeader", {
6788
+ return node4(id2, "CollapsingHeader", {
5879
6789
  ...opts.imageUrl ? { imageUrl: opts.imageUrl } : {},
5880
6790
  title: opts.title,
5881
6791
  ...opts.subtitle ? { subtitle: opts.subtitle } : {},
@@ -5901,7 +6811,7 @@ function authScreen(opts) {
5901
6811
  const screenId = opts.screenId ?? "signin";
5902
6812
  const c = opts.copy ?? {};
5903
6813
  const withRegister = opts.register !== false;
5904
- const field = (key, label, action2, extra = {}) => node3(`${s2}.${key}`, "TextField", {
6814
+ const field = (key, label, action2, extra = {}) => node4(`${s2}.${key}`, "TextField", {
5905
6815
  label,
5906
6816
  placeholder: label,
5907
6817
  valuePath: `$service:${s2}.${key}`,
@@ -5921,7 +6831,7 @@ function authScreen(opts) {
5921
6831
  `$service:${s2}.signedIn`
5922
6832
  ),
5923
6833
  hideWhen(
5924
- node3(`${s2}.submit`, "Button", {
6834
+ node4(`${s2}.submit`, "Button", {
5925
6835
  title: `$service:${s2}.submitCta`,
5926
6836
  style: "primary",
5927
6837
  fullWidth: true,
@@ -5933,7 +6843,7 @@ function authScreen(opts) {
5933
6843
  if (withRegister) {
5934
6844
  children.push(
5935
6845
  hideWhen(
5936
- node3(`${s2}.toggle`, "Button", {
6846
+ node4(`${s2}.toggle`, "Button", {
5937
6847
  title: `$service:${s2}.switchCta`,
5938
6848
  style: "secondary",
5939
6849
  fullWidth: true,
@@ -5953,7 +6863,7 @@ function authScreen(opts) {
5953
6863
  }
5954
6864
  children.push(
5955
6865
  hideWhen(
5956
- node3(`${s2}.signout`, "Button", {
6866
+ node4(`${s2}.signout`, "Button", {
5957
6867
  title: c.signOutCta ?? "Sign out",
5958
6868
  style: "secondary",
5959
6869
  fullWidth: true,
@@ -6411,7 +7321,7 @@ function checkoutScreen(opts) {
6411
7321
  // someone the thing they are currently paying for is the obvious next bug.
6412
7322
  hideWhen(text(`${s2}.row_joined`, "$item.joinedLabel", "bodyEmphasis"), "$item.notJoined"),
6413
7323
  hideWhen(
6414
- node3(`${s2}.row_join`, "Button", {
7324
+ node4(`${s2}.row_join`, "Button", {
6415
7325
  title: "$item.cta",
6416
7326
  disabledPath: "$item.joinDisabled",
6417
7327
  style: "primary",
@@ -6450,7 +7360,7 @@ function checkoutScreen(opts) {
6450
7360
  }
6451
7361
  children.push(
6452
7362
  hideWhen(
6453
- node3(`${s2}.list`, "LazyList", { itemsPath: `$service:${s2}.rows`, spacing: 18, items: [row] }),
7363
+ node4(`${s2}.list`, "LazyList", { itemsPath: `$service:${s2}.rows`, spacing: 18, items: [row] }),
6454
7364
  `$service:${s2}.noRows`
6455
7365
  )
6456
7366
  );
@@ -6462,6 +7372,9 @@ function checkoutScreen(opts) {
6462
7372
  });
6463
7373
  }
6464
7374
  export {
7375
+ FILE_SHARE_APP_DEF_ID,
7376
+ FILE_SHARE_CAPABILITIES,
7377
+ FILE_SHARE_INITIAL,
6465
7378
  ONE_APP_MEMBER_ONLY_SECTIONS,
6466
7379
  PODCAST_EPISODES_QUERY,
6467
7380
  PODCAST_FEED_ENDPOINT,
@@ -6475,6 +7388,7 @@ export {
6475
7388
  createAuthService,
6476
7389
  createBusinessContactService,
6477
7390
  createCheckoutService,
7391
+ createFileShareService,
6478
7392
  createInviteAvailabilityService,
6479
7393
  createInviteService,
6480
7394
  createOneAppSectionService,
@@ -6482,6 +7396,7 @@ export {
6482
7396
  decodeOneAppPage,
6483
7397
  detailedHeader,
6484
7398
  entitlement,
7399
+ fileShareScreen,
6485
7400
  inviteAction,
6486
7401
  inviteButton,
6487
7402
  inviteScreen,