@ai4b-team/fsaos-gateway-sdk 5.6.1 → 5.7.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.
package/dist/index.js CHANGED
@@ -67,6 +67,8 @@ __export(src_exports, {
67
67
  fetchVfsItem: () => fetchVfsItem,
68
68
  fetchVfsItemById: () => fetchVfsItemById,
69
69
  fetchVfsTree: () => fetchVfsTree,
70
+ filePurchaseNextUrl: () => filePurchaseNextUrl,
71
+ funnelCheckoutLink: () => funnelCheckoutLink,
70
72
  gatewayCall: () => gatewayCall,
71
73
  getAccessToken: () => getAccessToken,
72
74
  getAnchor: () => getAnchor,
@@ -74,6 +76,7 @@ __export(src_exports, {
74
76
  getAnchorVersion: () => getAnchorVersion,
75
77
  getAssetUrl: () => getAssetUrl,
76
78
  getDefaultSort: () => getDefaultSort,
79
+ getFilePurchase: () => getFilePurchase,
77
80
  getHomeAnchor: () => getHomeAnchor,
78
81
  getInvitation: () => getInvitation,
79
82
  getMountVersion: () => getMountVersion,
@@ -141,6 +144,7 @@ __export(src_exports, {
141
144
  setScope: () => setScope,
142
145
  setupRequireShim: () => setupRequireShim,
143
146
  signal: () => signal,
147
+ startFileCheckout: () => startFileCheckout,
144
148
  startTracking: () => startTracking,
145
149
  steerTurn: () => steerTurn,
146
150
  submitForm: () => submitForm,
@@ -1746,7 +1750,7 @@ function normalizeItem(raw) {
1746
1750
  const path = raw.path || raw.item_path || "";
1747
1751
  const segments = path.split("/");
1748
1752
  segments.pop();
1749
- const parentPath = segments.join("/");
1753
+ const parentPath2 = segments.join("/");
1750
1754
  const typeData = raw.type_data || {};
1751
1755
  if (typeData.allowed_parent_types && !typeData.accepts) {
1752
1756
  typeData.accepts = typeData.allowed_parent_types;
@@ -1757,7 +1761,7 @@ function normalizeItem(raw) {
1757
1761
  name: raw.name || raw.item_name || "",
1758
1762
  item_type: raw.item_type || "unknown",
1759
1763
  path,
1760
- parent_path: parentPath,
1764
+ parent_path: parentPath2,
1761
1765
  is_active: raw.is_active !== false,
1762
1766
  has_children: raw.has_children ?? false,
1763
1767
  created_at: raw.created_at || nowISO(),
@@ -2388,9 +2392,9 @@ function invalidatePathAndParent(path, fallbackParent) {
2388
2392
  invalidateChildren(path);
2389
2393
  const segments = path.split("/");
2390
2394
  segments.pop();
2391
- const parentPath = segments.join("/") || fallbackParent;
2392
- if (parentPath) {
2393
- invalidateChildren(parentPath);
2395
+ const parentPath2 = segments.join("/") || fallbackParent;
2396
+ if (parentPath2) {
2397
+ invalidateChildren(parentPath2);
2394
2398
  }
2395
2399
  }
2396
2400
  function invalidateSubtree(path) {
@@ -2528,22 +2532,22 @@ function handleVfsChange(data) {
2528
2532
  if (!path) return;
2529
2533
  const segments = path.split("/");
2530
2534
  segments.pop();
2531
- const parentPath = segments.join("/") || "/root";
2532
- let changes = pendingChanges.get(parentPath);
2535
+ const parentPath2 = segments.join("/") || "/root";
2536
+ let changes = pendingChanges.get(parentPath2);
2533
2537
  if (!changes) {
2534
2538
  changes = /* @__PURE__ */ new Map();
2535
- pendingChanges.set(parentPath, changes);
2539
+ pendingChanges.set(parentPath2, changes);
2536
2540
  }
2537
2541
  changes.set(path, { action, itemId: typeof data.item_id === "string" ? data.item_id : void 0 });
2538
- const existing = debounceTimers.get(parentPath);
2542
+ const existing = debounceTimers.get(parentPath2);
2539
2543
  if (existing) clearTimeout(existing);
2540
2544
  const timer = setTimeout(() => {
2541
- debounceTimers.delete(parentPath);
2542
- const flushed = pendingChanges.get(parentPath);
2543
- pendingChanges.delete(parentPath);
2544
- if (flushed) applyInvalidation(parentPath, flushed);
2545
+ debounceTimers.delete(parentPath2);
2546
+ const flushed = pendingChanges.get(parentPath2);
2547
+ pendingChanges.delete(parentPath2);
2548
+ if (flushed) applyInvalidation(parentPath2, flushed);
2545
2549
  }, DEBOUNCE_MS);
2546
- debounceTimers.set(parentPath, timer);
2550
+ debounceTimers.set(parentPath2, timer);
2547
2551
  }
2548
2552
  function handleCcmChange(data) {
2549
2553
  if (!data || typeof data !== "object") return;
@@ -2565,7 +2569,7 @@ function handleCcmChange(data) {
2565
2569
  }, DEBOUNCE_MS);
2566
2570
  debounceTimers.set(debounceKey, timer);
2567
2571
  }
2568
- function applyInvalidation(parentPath, changes) {
2572
+ function applyInvalidation(parentPath2, changes) {
2569
2573
  const client2 = getQueryClient();
2570
2574
  for (const [path, change] of changes) {
2571
2575
  if ((change.action || "").toUpperCase() === "DELETE") {
@@ -2579,7 +2583,7 @@ function applyInvalidation(parentPath, changes) {
2579
2583
  client2.invalidateQueries({ queryKey: vfsKeys.itemById(change.itemId) });
2580
2584
  }
2581
2585
  }
2582
- client2.invalidateQueries({ queryKey: vfsKeys.children(parentPath) });
2586
+ client2.invalidateQueries({ queryKey: vfsKeys.children(parentPath2) });
2583
2587
  const changed = [...changes.keys()];
2584
2588
  client2.invalidateQueries({
2585
2589
  predicate: (query) => {
@@ -2954,9 +2958,57 @@ function channelMessageChange(event, channelPath, parentId, messages) {
2954
2958
  });
2955
2959
  }
2956
2960
 
2957
- // src/channel-realtime.ts
2961
+ // src/channel-transcript-realtime.ts
2958
2962
  var watches = /* @__PURE__ */ new WeakMap();
2959
- function watchChannels(client2, key, normalize) {
2963
+ var parentPath = (path) => path.slice(0, path.lastIndexOf("/"));
2964
+ var actionOf = (change) => change.action?.toLowerCase();
2965
+ function isNewPost(change, channel) {
2966
+ return change.item_type === "message" && actionOf(change) === "insert" && parentPath(change.path) === channel && !change.old_path;
2967
+ }
2968
+ function affectedMessages(page, ids, paths) {
2969
+ return page.messages.filter((message) => ids.has(message.id) || paths.has(message.path));
2970
+ }
2971
+ function updateTranscript(cached, targets, revised, tail) {
2972
+ const pages = cached.pages.slice();
2973
+ const replacements = new Map(revised?.messages.map((message) => [message.id, message]));
2974
+ for (const [index, affected] of targets) {
2975
+ const page = pages[index];
2976
+ const wanted = new Set(affected.map((message) => message.id));
2977
+ const messageCards2 = new Map(page.messageCards);
2978
+ for (const message of affected) {
2979
+ messageCards2.delete(message.path);
2980
+ const replacement = replacements.get(message.id);
2981
+ const cards = replacement && revised?.messageCards.get(replacement.path);
2982
+ if (replacement && cards?.length) messageCards2.set(replacement.path, cards);
2983
+ }
2984
+ pages[index] = {
2985
+ ...page,
2986
+ messages: page.messages.flatMap((message) => {
2987
+ if (!wanted.has(message.id)) return [message];
2988
+ const replacement = replacements.get(message.id);
2989
+ return replacement ? [replacement] : [];
2990
+ }),
2991
+ messageCards: messageCards2
2992
+ };
2993
+ }
2994
+ const snapshot = tail ?? revised;
2995
+ const latest = pages[0];
2996
+ const messageCards = new Map(latest.messageCards);
2997
+ for (const message of latest.activityMessages ?? []) messageCards.delete(message.path);
2998
+ for (const message of [...snapshot.activityMessages ?? [], ...tail?.messages ?? []]) {
2999
+ const cards = snapshot.messageCards.get(message.path);
3000
+ if (cards?.length) messageCards.set(message.path, cards);
3001
+ }
3002
+ pages[0] = {
3003
+ ...latest,
3004
+ messages: tail ? [...latest.messages, ...tail.messages] : latest.messages,
3005
+ activityMessages: snapshot.activityMessages,
3006
+ siblingCards: snapshot.siblingCards,
3007
+ messageCards
3008
+ };
3009
+ return { ...cached, pages };
3010
+ }
3011
+ function watchChannelTranscript(client2, key, channel, limit) {
2960
3012
  let entries = watches.get(client2);
2961
3013
  if (!entries) {
2962
3014
  entries = /* @__PURE__ */ new Map();
@@ -2964,6 +3016,133 @@ function watchChannels(client2, key, normalize) {
2964
3016
  }
2965
3017
  const hash = JSON.stringify(key);
2966
3018
  let watch = entries.get(hash);
3019
+ if (!watch) {
3020
+ let timer;
3021
+ let running2 = false;
3022
+ let stopped = false;
3023
+ const pending4 = /* @__PURE__ */ new Map();
3024
+ const current = () => client2.getQueryData(key);
3025
+ const query = () => client2.getQueryCache().find({ queryKey: key, exact: true });
3026
+ const reload = () => refreshQuery(client2, key, { exact: true });
3027
+ const read = (after_seq, before_seq) => fetchChannelMessagesPage(channel, { transcriptOnly: true, limit, after_seq, before_seq });
3028
+ const schedule2 = () => {
3029
+ if (stopped || running2 || timer || !pending4.size) return;
3030
+ timer = setTimeout(() => {
3031
+ timer = void 0;
3032
+ void flush();
3033
+ }, 500);
3034
+ };
3035
+ const flush = async () => {
3036
+ running2 = true;
3037
+ const changes = [...pending4.values()];
3038
+ pending4.clear();
3039
+ const owner = query();
3040
+ try {
3041
+ if (owner?.state.fetchStatus === "fetching") await owner.promise?.catch(() => void 0);
3042
+ if (stopped || owner !== query()) return;
3043
+ const cached = current();
3044
+ if (!cached?.pages.length) {
3045
+ await reload();
3046
+ return;
3047
+ }
3048
+ const ids = /* @__PURE__ */ new Set();
3049
+ const paths = /* @__PURE__ */ new Set();
3050
+ const possiblyAdmitted = /* @__PURE__ */ new Set();
3051
+ let append = false;
3052
+ for (const change of changes) {
3053
+ if (isNewPost(change, channel)) {
3054
+ append = true;
3055
+ continue;
3056
+ }
3057
+ if (change.inserted) append = true;
3058
+ if (change.item_type === "message" && parentPath(change.path) === channel && !change.inserted && actionOf(change) !== "delete") possiblyAdmitted.add(change.path);
3059
+ if (change.item_id) ids.add(change.item_id);
3060
+ if (change.parent_id) ids.add(change.parent_id);
3061
+ for (const path of [change.path, change.old_path]) {
3062
+ if (path && isChannelPath(path, channel)) {
3063
+ paths.add(path);
3064
+ paths.add(parentPath(path));
3065
+ }
3066
+ }
3067
+ }
3068
+ const targets = /* @__PURE__ */ new Map();
3069
+ let low = Infinity;
3070
+ let high = 0;
3071
+ if (ids.size || paths.size) {
3072
+ cached.pages.forEach((page, index) => {
3073
+ const affected = affectedMessages(page, ids, paths);
3074
+ if (affected.length) targets.set(index, affected);
3075
+ for (const message of affected) {
3076
+ possiblyAdmitted.delete(message.path);
3077
+ low = Math.min(low, message.seq);
3078
+ high = Math.max(high, message.seq);
3079
+ }
3080
+ });
3081
+ }
3082
+ for (const activity of cached.pages[0].activityMessages ?? []) possiblyAdmitted.delete(activity.path);
3083
+ if (possiblyAdmitted.size) {
3084
+ await reload();
3085
+ return;
3086
+ }
3087
+ if (targets.size && (!Number.isSafeInteger(low) || low < 1 || !Number.isSafeInteger(high + 1))) {
3088
+ await reload();
3089
+ return;
3090
+ }
3091
+ const latest = cached.pages.find((page) => page.messages.length)?.messages.at(-1)?.seq ?? 0;
3092
+ const [revised, tail] = await Promise.all([
3093
+ targets.size ? read(low - 1, high + 1) : void 0,
3094
+ append || !targets.size ? read(latest) : void 0
3095
+ ]);
3096
+ if (stopped || owner !== query()) return;
3097
+ const settled = current();
3098
+ if (owner?.state.fetchStatus === "fetching" || cached.pages.some((page, index) => settled?.pages[index] !== page) || revised && revised.messages.length >= limit && (revised.messages.at(-1)?.seq ?? 0) < high || tail && tail.messages.length >= limit) {
3099
+ await reload();
3100
+ return;
3101
+ }
3102
+ client2.setQueryData(key, (data) => data && updateTranscript(data, targets, revised, tail));
3103
+ } catch {
3104
+ if (!stopped && owner === query()) await reload();
3105
+ } finally {
3106
+ running2 = false;
3107
+ schedule2();
3108
+ }
3109
+ };
3110
+ const stop = subscribeToEvents("vfs_change", (change) => {
3111
+ const id = change.item_id ?? change.path;
3112
+ const previous = pending4.get(id);
3113
+ pending4.set(id, previous && (previous.inserted || isNewPost(previous, channel)) && actionOf(change) === "update" && previous.path === change.path ? { ...change, inserted: true } : change);
3114
+ schedule2();
3115
+ }, (change) => channelMessageChange(change, channel, void 0, []) || !!change.old_path && channelMessageChange({ ...change, path: change.old_path }, channel, void 0, []) || change.item_type === "message" && !!change.parent_id && isChannelPath(change.path, channel) && !!current()?.pages.some((page) => page.messages.some((root) => root.id === change.parent_id)));
3116
+ watch = { users: 0, stop: () => {
3117
+ stopped = true;
3118
+ stop();
3119
+ if (timer) clearTimeout(timer);
3120
+ pending4.clear();
3121
+ } };
3122
+ entries.set(hash, watch);
3123
+ }
3124
+ watch.users++;
3125
+ let released = false;
3126
+ return () => {
3127
+ if (released) return;
3128
+ released = true;
3129
+ if (--watch.users === 0) {
3130
+ watch.stop();
3131
+ entries.delete(hash);
3132
+ }
3133
+ };
3134
+ }
3135
+
3136
+ // src/channel-realtime.ts
3137
+ var watches2 = /* @__PURE__ */ new WeakMap();
3138
+ function watchChannels(client2, key, normalize) {
3139
+ let entries = watches2.get(client2);
3140
+ if (!entries) {
3141
+ entries = /* @__PURE__ */ new Map();
3142
+ watches2.set(client2, entries);
3143
+ }
3144
+ const hash = JSON.stringify(key);
3145
+ let watch = entries.get(hash);
2967
3146
  if (!watch) {
2968
3147
  let stopped = false;
2969
3148
  let timer;
@@ -3079,12 +3258,12 @@ function watchChannels(client2, key, normalize) {
3079
3258
  }
3080
3259
 
3081
3260
  // src/message-replies-realtime.ts
3082
- var watches2 = /* @__PURE__ */ new WeakMap();
3261
+ var watches3 = /* @__PURE__ */ new WeakMap();
3083
3262
  function watchMessageReplies(client2, key, target) {
3084
- let entries = watches2.get(client2);
3263
+ let entries = watches3.get(client2);
3085
3264
  if (!entries) {
3086
3265
  entries = /* @__PURE__ */ new Map();
3087
- watches2.set(client2, entries);
3266
+ watches3.set(client2, entries);
3088
3267
  }
3089
3268
  const hash = JSON.stringify(key);
3090
3269
  let watch = entries.get(hash);
@@ -4567,14 +4746,14 @@ function useMessageReplies(options) {
4567
4746
  return { ...query, messages };
4568
4747
  }
4569
4748
  function useInfiniteChannelMessages(options) {
4570
- useScopeKey();
4749
+ const scopeKey = useScopeKey();
4571
4750
  const { channelPath, parentMessageId, limit = 50, realtime = true, enabled: enabled2 = true, conversationsOnly = false, transcriptOnly = false } = options;
4572
4751
  const isThread = !!parentMessageId;
4573
4752
  const queryEnabled = enabled2 && !!channelPath;
4574
4753
  const query = useInfiniteQuery({
4575
4754
  queryKey: [...vfsKeys.channelMessages(channelPath || "", parentMessageId), "infinite", limit, "latest-first", ...conversationsOnly ? ["conversations"] : [], ...transcriptOnly ? ["transcript"] : []],
4576
4755
  queryFn: async ({ pageParam }) => {
4577
- return fetchChannelMessagesPage(channelPath, {
4756
+ const page = await fetchChannelMessagesPage(channelPath, {
4578
4757
  parentMessageId,
4579
4758
  limit,
4580
4759
  conversationsOnly,
@@ -4582,6 +4761,7 @@ function useInfiniteChannelMessages(options) {
4582
4761
  before_seq: pageParam?.before_seq,
4583
4762
  after_seq: pageParam?.after_seq
4584
4763
  });
4764
+ return transcriptOnly && page.messages.length >= limit ? { ...page, olderBefore: page.messages[0]?.seq } : page;
4585
4765
  },
4586
4766
  initialPageParam: void 0,
4587
4767
  getPreviousPageParam: (lastPage) => {
@@ -4591,6 +4771,7 @@ function useInfiniteChannelMessages(options) {
4591
4771
  return maxSeq == null ? void 0 : { after_seq: maxSeq };
4592
4772
  },
4593
4773
  getNextPageParam: (firstPage) => {
4774
+ if (transcriptOnly) return firstPage.olderBefore == null ? void 0 : { before_seq: firstPage.olderBefore };
4594
4775
  if (firstPage.messages.length < limit) return void 0;
4595
4776
  const minSeq = firstPage.messages[0]?.seq;
4596
4777
  return minSeq == null ? void 0 : { before_seq: minSeq };
@@ -4616,8 +4797,10 @@ function useInfiniteChannelMessages(options) {
4616
4797
  const sc = [];
4617
4798
  if (!query.data?.pages) return { messageCards: mc, siblingCards: sc };
4618
4799
  const seenCards = /* @__PURE__ */ new Set();
4619
- for (const page of query.data.pages) {
4800
+ for (const [index, page] of query.data.pages.entries()) {
4801
+ const pagePaths = transcriptOnly && index > 0 ? new Set(page.messages.map((message) => message.path)) : null;
4620
4802
  for (const [path, cards] of page.messageCards) {
4803
+ if (pagePaths && !pagePaths.has(path)) continue;
4621
4804
  for (const card of cards) {
4622
4805
  if (seenCards.has(card.id)) continue;
4623
4806
  seenCards.add(card.id);
@@ -4626,6 +4809,7 @@ function useInfiniteChannelMessages(options) {
4626
4809
  mc.set(path, existing);
4627
4810
  }
4628
4811
  }
4812
+ if (transcriptOnly && index > 0) continue;
4629
4813
  for (const card of page.siblingCards) {
4630
4814
  if (seenCards.has(card.id)) continue;
4631
4815
  seenCards.add(card.id);
@@ -4633,21 +4817,22 @@ function useInfiniteChannelMessages(options) {
4633
4817
  }
4634
4818
  }
4635
4819
  return { messageCards: mc, siblingCards: sc };
4636
- }, [query.data?.pages]);
4820
+ }, [query.data?.pages, transcriptOnly]);
4637
4821
  const qc = useQueryClient();
4638
4822
  const debounceRef = useRef(null);
4639
4823
  const stableKey = useMemo(
4640
4824
  () => [...vfsKeys.channelMessages(channelPath || "", parentMessageId), "infinite", limit, "latest-first", ...conversationsOnly ? ["conversations"] : [], ...transcriptOnly ? ["transcript"] : []],
4641
- [channelPath, parentMessageId, limit, conversationsOnly, transcriptOnly]
4825
+ [channelPath, parentMessageId, limit, conversationsOnly, transcriptOnly, scopeKey]
4642
4826
  );
4643
4827
  useEffect(() => {
4644
4828
  if (!realtime || !channelPath || !queryEnabled) return;
4829
+ if (transcriptOnly) return watchChannelTranscript(qc, stableKey, channelPath, limit);
4645
4830
  const reload = () => void refreshQuery(qc, stableKey, { exact: true });
4646
4831
  let tailRunning = false;
4647
4832
  let tailAgain = false;
4648
4833
  let disposed = false;
4649
4834
  const tailOnce = async () => {
4650
- if (conversationsOnly || transcriptOnly) {
4835
+ if (conversationsOnly) {
4651
4836
  reload();
4652
4837
  return;
4653
4838
  }
@@ -4741,7 +4926,7 @@ function useInfiniteChannelMessages(options) {
4741
4926
  void tail();
4742
4927
  }, 500);
4743
4928
  },
4744
- (data) => (conversationsOnly || transcriptOnly) && data?.item_type === "message" && (qc.getQueryData(stableKey)?.pages ?? []).some((page) => page.messages.some((root) => root.id === data.parent_id)) || channelMessageChange(
4929
+ (data) => conversationsOnly && data?.item_type === "message" && (qc.getQueryData(stableKey)?.pages ?? []).some((page) => page.messages.some((root) => root.id === data.parent_id)) || channelMessageChange(
4745
4930
  data,
4746
4931
  channelPath,
4747
4932
  parentMessageId,
@@ -4972,9 +5157,9 @@ function useCreate() {
4972
5157
  return useMutation$1({
4973
5158
  mutationFn: (params) => gatewayCall("create", params),
4974
5159
  onSuccess: (_data, variables) => {
4975
- const parentPath = variables.parent_path;
4976
- if (parentPath) {
4977
- qc.invalidateQueries({ queryKey: vfsKeys.children(parentPath) });
5160
+ const parentPath2 = variables.parent_path;
5161
+ if (parentPath2) {
5162
+ qc.invalidateQueries({ queryKey: vfsKeys.children(parentPath2) });
4978
5163
  }
4979
5164
  }
4980
5165
  });
@@ -4989,9 +5174,9 @@ function useUpdate() {
4989
5174
  qc.invalidateQueries({ queryKey: vfsKeys.item(path) });
4990
5175
  const segments = path.split("/");
4991
5176
  segments.pop();
4992
- const parentPath = segments.join("/");
4993
- if (parentPath) {
4994
- qc.invalidateQueries({ queryKey: vfsKeys.children(parentPath) });
5177
+ const parentPath2 = segments.join("/");
5178
+ if (parentPath2) {
5179
+ qc.invalidateQueries({ queryKey: vfsKeys.children(parentPath2) });
4995
5180
  }
4996
5181
  }
4997
5182
  }
@@ -5027,9 +5212,9 @@ function useDelete() {
5027
5212
  qc.removeQueries({ queryKey: vfsKeys.item(path) });
5028
5213
  const segments = path.split("/");
5029
5214
  segments.pop();
5030
- const parentPath = segments.join("/");
5031
- if (parentPath) {
5032
- qc.invalidateQueries({ queryKey: vfsKeys.children(parentPath) });
5215
+ const parentPath2 = segments.join("/");
5216
+ if (parentPath2) {
5217
+ qc.invalidateQueries({ queryKey: vfsKeys.children(parentPath2) });
5033
5218
  }
5034
5219
  }
5035
5220
  }
@@ -6102,6 +6287,49 @@ async function submitForm(capabilityId, fields, options = {}) {
6102
6287
  }, fillId, pageUrl, identity, options.signal);
6103
6288
  return payload;
6104
6289
  }
6290
+
6291
+ // src/commerce.ts
6292
+ async function startFileCheckout(options) {
6293
+ return gatewayCall("commerce-file-sale", {
6294
+ action: "checkout",
6295
+ product_id: options.productId,
6296
+ expected_product_revision_id: options.productRevisionId,
6297
+ destination_id: options.destinationId,
6298
+ request_key: options.requestKey,
6299
+ _scope_path: options.scopePath,
6300
+ ...options.journey ? { journey: options.journey } : {}
6301
+ });
6302
+ }
6303
+ async function getFilePurchase(licenseId, scopePath) {
6304
+ return gatewayCall("commerce-file-sale", { action: "get", license_id: licenseId, _scope_path: scopePath });
6305
+ }
6306
+ function funnelCheckoutLink(options) {
6307
+ const host = new URL(options.hostOrigin);
6308
+ if (host.protocol !== "https:" && !(host.protocol === "http:" && host.hostname === "127.0.0.1") || host.username || host.password || host.search || host.hash || host.pathname !== "/") {
6309
+ throw new TypeError("hostOrigin must be an HTTPS origin or the local 127.0.0.1 app");
6310
+ }
6311
+ const page = new URL(options.pageUrl ?? window.location.href);
6312
+ if (page.protocol !== "https:" || page.username || page.password || page.hash || page.port) {
6313
+ throw new TypeError("The funnel must be a published HTTPS page");
6314
+ }
6315
+ const link = new URL("/v2/revven", host);
6316
+ link.search = new URLSearchParams({
6317
+ surface: "library",
6318
+ offer: options.productId,
6319
+ sale_page: page.href,
6320
+ sale_action: options.capabilityId
6321
+ }).toString();
6322
+ return link.href;
6323
+ }
6324
+ function filePurchaseNextUrl(receipt) {
6325
+ if (receipt.success !== true || receipt.state !== "ready" || !receipt.item_id || !receipt.file_id || !receipt.journey?.next_url) return null;
6326
+ const next = new URL(receipt.journey.next_url);
6327
+ const source = new URL(receipt.journey.return_url);
6328
+ if (next.protocol !== "https:" || source.protocol !== "https:" || next.origin !== source.origin || next.username || next.password || next.hash || next.searchParams.getAll("funnel_id").length !== 1 || next.searchParams.get("funnel_id") !== receipt.journey.funnel_id) {
6329
+ throw new Error("The purchase destination could not be verified");
6330
+ }
6331
+ return next.href;
6332
+ }
6105
6333
  function readItem(path) {
6106
6334
  return gatewayCall("read", { path });
6107
6335
  }
@@ -7197,6 +7425,6 @@ function usePersonalSections(contextId, collection) {
7197
7425
  // src/index.ts
7198
7426
  __registerSdkExports(src_exports);
7199
7427
 
7200
- export { CHANNEL_AI_MODES, ComponentRenderer, EnforcementDeniedError, FormSubmissionError, GatewayRequestError, HostSessionUnavailableError, InteractionTrackingError, KernelProvider, acceptInvitation, acceptInvite, answerInput, assignPersonalSection, auth, awaitAnchorReady, awaitScopeReady, callTool, cancelInvitation, cancelQueuedTurn, cancelTurn, clearCachedToken, clearSession, configureGatewayReads, connectHostSession, createAgent, createInvitation, createItem, disconnectSSE, disposeVfsRealtimeWs, electHomeAnchor, emitEvent, fetchChannelMessages, fetchChannelMessagesPage, fetchChannelMessagesWithCards, fetchEdgesForItem, fetchItemHistory, fetchItemVersions, fetchItems, fetchMemberFocus, fetchMessageReplies, fetchMessageReplyContexts, fetchOpenEnvelope, fetchRecentActivity, fetchResolvedItems, fetchTimelineHistory, fetchTurnQueueEntries, fetchTypeDefinitions, fetchVfsChildren, fetchVfsChildrenPage, fetchVfsItem, fetchVfsItemById, fetchVfsTree, gatewayCall, getAccessToken, getAnchor, getAnchorRef, getAnchorVersion, getAssetUrl, getDefaultSort, getHomeAnchor, getInvitation, getMountVersion, getMounts, getPathSubscriptionState, getQueryClient, getRequiredFormFields, getScope, getScopeVersion, getServerClockOffsetMs, getServerClockSyncedAt, getSessionEntry, hasServerClock, initSession, initVfsRealtimeWs, initializeFsaos, initializeWorkspace, interpretSchema, invalidateAllVfs, invalidateChannelMessages, invalidateChildren, invalidateItem, invalidateOpenEnvelope, invalidatePathAndParent, invalidateSubtree, invalidateTypes, inviteMember, isAnchorReady, isChannelPath, isListableItemsFilter, isScopeReady, itemsFilterFromQueryFilter, listChildren, listInvitations, loadMounts, loadPublishedBundle, mount2 as mount, mountRealtimeScope, normalizeItem, onConnectionStateChange, pathSubscriptionMatches, personalSectionsKey, ping, pushChanges, queryClient, readItem, refreshQuery, registerCleanup, rejectInvitation, replaceMounts, resendInvitation, resetAllSdkState, resolvePrincipalId, resubscribePath, seatMember, selectMount, sendMessage2 as sendMessage, serveHostSession, serverDeadlinePassed, serverMsUntil, serverNow, setAnchor, setCachedToken, setQueryClient, setScope, setupRequireShim, signal, startTracking, steerTurn, submitForm, subscribeAnchor, subscribeArtifactStream, subscribeMounts, subscribeScope, subscribeToEvents, subscribeToPath, subscribeToScope, trackAction, trackEvent, trackPageView, unmountRealtimeScope, updateItem, uploadFile, useAcceptInvite, useAccounts, useAgentTimeline, useAllChannels, useAnswerInput, useArrangement, useArtifactStream, useAsset, useAuth, useChannelMessages, useChannels, useChildren, useComponent, useCreate, useCreateAgent, useDelete, useDmChannels, useEdges, useEventStream, useFileUpload, useIncrementalItems, useInfiniteChannelMessages, useInfiniteChildren, useInfiniteItems, useInviteMember, useItem, useItemById, useItemHistory, useItemVersions, useItems, useLink, useList, useMemberFocus, useMessageReplies, useMintedAsset, useMounts, useMove, useMutation, useNotifications, useOpen, usePermission, usePermissions, usePersonalItemOrder, usePersonalSections, usePinnedItems, usePrincipal, usePublishedComponent, useRealtimeQuery, useRecentActivity, useResolve, useResolvedItems, useScope, useScopeReady, useSearch, useSeatMember, useTheme, useTimelineHistory, useTree, useType, useTypeHelpers, useTypes, useUnreadCounts, useUpdate, useUpdatePrincipal, vfsKeys, waitForPathReady };
7428
+ export { CHANNEL_AI_MODES, ComponentRenderer, EnforcementDeniedError, FormSubmissionError, GatewayRequestError, HostSessionUnavailableError, InteractionTrackingError, KernelProvider, acceptInvitation, acceptInvite, answerInput, assignPersonalSection, auth, awaitAnchorReady, awaitScopeReady, callTool, cancelInvitation, cancelQueuedTurn, cancelTurn, clearCachedToken, clearSession, configureGatewayReads, connectHostSession, createAgent, createInvitation, createItem, disconnectSSE, disposeVfsRealtimeWs, electHomeAnchor, emitEvent, fetchChannelMessages, fetchChannelMessagesPage, fetchChannelMessagesWithCards, fetchEdgesForItem, fetchItemHistory, fetchItemVersions, fetchItems, fetchMemberFocus, fetchMessageReplies, fetchMessageReplyContexts, fetchOpenEnvelope, fetchRecentActivity, fetchResolvedItems, fetchTimelineHistory, fetchTurnQueueEntries, fetchTypeDefinitions, fetchVfsChildren, fetchVfsChildrenPage, fetchVfsItem, fetchVfsItemById, fetchVfsTree, filePurchaseNextUrl, funnelCheckoutLink, gatewayCall, getAccessToken, getAnchor, getAnchorRef, getAnchorVersion, getAssetUrl, getDefaultSort, getFilePurchase, getHomeAnchor, getInvitation, getMountVersion, getMounts, getPathSubscriptionState, getQueryClient, getRequiredFormFields, getScope, getScopeVersion, getServerClockOffsetMs, getServerClockSyncedAt, getSessionEntry, hasServerClock, initSession, initVfsRealtimeWs, initializeFsaos, initializeWorkspace, interpretSchema, invalidateAllVfs, invalidateChannelMessages, invalidateChildren, invalidateItem, invalidateOpenEnvelope, invalidatePathAndParent, invalidateSubtree, invalidateTypes, inviteMember, isAnchorReady, isChannelPath, isListableItemsFilter, isScopeReady, itemsFilterFromQueryFilter, listChildren, listInvitations, loadMounts, loadPublishedBundle, mount2 as mount, mountRealtimeScope, normalizeItem, onConnectionStateChange, pathSubscriptionMatches, personalSectionsKey, ping, pushChanges, queryClient, readItem, refreshQuery, registerCleanup, rejectInvitation, replaceMounts, resendInvitation, resetAllSdkState, resolvePrincipalId, resubscribePath, seatMember, selectMount, sendMessage2 as sendMessage, serveHostSession, serverDeadlinePassed, serverMsUntil, serverNow, setAnchor, setCachedToken, setQueryClient, setScope, setupRequireShim, signal, startFileCheckout, startTracking, steerTurn, submitForm, subscribeAnchor, subscribeArtifactStream, subscribeMounts, subscribeScope, subscribeToEvents, subscribeToPath, subscribeToScope, trackAction, trackEvent, trackPageView, unmountRealtimeScope, updateItem, uploadFile, useAcceptInvite, useAccounts, useAgentTimeline, useAllChannels, useAnswerInput, useArrangement, useArtifactStream, useAsset, useAuth, useChannelMessages, useChannels, useChildren, useComponent, useCreate, useCreateAgent, useDelete, useDmChannels, useEdges, useEventStream, useFileUpload, useIncrementalItems, useInfiniteChannelMessages, useInfiniteChildren, useInfiniteItems, useInviteMember, useItem, useItemById, useItemHistory, useItemVersions, useItems, useLink, useList, useMemberFocus, useMessageReplies, useMintedAsset, useMounts, useMove, useMutation, useNotifications, useOpen, usePermission, usePermissions, usePersonalItemOrder, usePersonalSections, usePinnedItems, usePrincipal, usePublishedComponent, useRealtimeQuery, useRecentActivity, useResolve, useResolvedItems, useScope, useScopeReady, useSearch, useSeatMember, useTheme, useTimelineHistory, useTree, useType, useTypeHelpers, useTypes, useUnreadCounts, useUpdate, useUpdatePrincipal, vfsKeys, waitForPathReady };
7201
7429
  //# sourceMappingURL=index.js.map
7202
7430
  //# sourceMappingURL=index.js.map