@odla-ai/chapter 0.39.2 → 0.40.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.cjs CHANGED
@@ -402,6 +402,7 @@ var applicationAttrs = {
402
402
  tierId: attr("string", { indexed: true, optional: true }),
403
403
  stripeCustomerId: attr("string", { indexed: true, optional: true }),
404
404
  stripeSubscriptionId: attr("string", { indexed: true, optional: true }),
405
+ stripeRuntime: attr("string", { indexed: true, optional: true }),
405
406
  renewalAt: attr("number", { optional: true }),
406
407
  disclaimerAckAt: attr("number", { optional: true }),
407
408
  refundPolicyAckAt: attr("number", { optional: true }),
@@ -497,6 +498,7 @@ var giftPurchaseIntentsEntity = { attrs: {
497
498
  id: id2(),
498
499
  chapterId: attr3("string", { indexed: true }),
499
500
  environment: attr3("string", { indexed: true }),
501
+ runtime: attr3("string", { optional: true, indexed: true }),
500
502
  purchaserType: attr3("string", { indexed: true }),
501
503
  purchaserApplicationId: attr3("string", { optional: true, indexed: true }),
502
504
  purchaserUserId: attr3("string", { optional: true, indexed: true }),
@@ -2842,12 +2844,16 @@ function findApplicationRef(obj) {
2842
2844
  const applicationId = candidates.map(pick).find(Boolean);
2843
2845
  const appId = candidates.map((metadata) => typeof metadata.odlaAppId === "string" ? metadata.odlaAppId : void 0).find(Boolean);
2844
2846
  const environment = candidates.map((metadata) => typeof metadata.odlaEnvironment === "string" ? metadata.odlaEnvironment : void 0).find(Boolean);
2847
+ const dataEnvironment = candidates.map((metadata) => typeof metadata.odlaDataEnvironment === "string" ? metadata.odlaDataEnvironment : void 0).find(Boolean);
2848
+ const runtime = candidates.map((metadata) => typeof metadata.odlaRuntime === "string" ? metadata.odlaRuntime : void 0).find(Boolean);
2845
2849
  const customerId = typeof obj.customer === "string" ? obj.customer : void 0;
2846
2850
  return {
2847
2851
  ...applicationId ? { applicationId } : {},
2848
2852
  ...customerId ? { customerId } : {},
2849
2853
  ...appId ? { appId } : {},
2850
- ...environment ? { environment } : {}
2854
+ ...environment ? { environment } : {},
2855
+ ...dataEnvironment ? { dataEnvironment } : {},
2856
+ ...runtime ? { runtime } : {}
2851
2857
  };
2852
2858
  }
2853
2859
  function findGiftRef(obj) {
@@ -2857,17 +2863,31 @@ function findGiftRef(obj) {
2857
2863
  const subscription = obj.subscription_details ?? parent?.subscription_details;
2858
2864
  const giftIntentId = pick(metaOf(obj)) ?? pick(metaOf(subscription));
2859
2865
  const subscriptionId = typeof obj.subscription === "string" ? obj.subscription : typeof subscription?.subscription === "string" ? String(subscription.subscription) : void 0;
2860
- return { ...giftIntentId ? { giftIntentId } : {}, providerObjectId: subscriptionId ?? String(obj.id ?? "") };
2866
+ const candidates = [metaOf(obj), metaOf(subscription)];
2867
+ const pickIdentity = (name) => candidates.map((metadata) => typeof metadata[name] === "string" ? String(metadata[name]) : void 0).find(Boolean);
2868
+ const appId = pickIdentity("odlaAppId");
2869
+ const environment = pickIdentity("odlaEnvironment");
2870
+ const dataEnvironment = pickIdentity("odlaDataEnvironment");
2871
+ const runtime = pickIdentity("odlaRuntime");
2872
+ return {
2873
+ ...giftIntentId ? { giftIntentId } : {},
2874
+ providerObjectId: subscriptionId ?? String(obj.id ?? ""),
2875
+ ...appId ? { appId } : {},
2876
+ ...environment ? { environment } : {},
2877
+ ...dataEnvironment ? { dataEnvironment } : {},
2878
+ ...runtime ? { runtime } : {}
2879
+ };
2861
2880
  }
2862
2881
  function normalizeWebhookEvent(event) {
2863
2882
  const obj = event.data?.object ?? {};
2864
2883
  const gift = findGiftRef(obj);
2865
2884
  if (gift.giftIntentId) {
2885
+ const { giftIntentId, providerObjectId, ...identity } = gift;
2866
2886
  if (event.type === "payment_intent.succeeded" || event.type === "invoice.paid" && obj.billing_reason === "subscription_create") {
2867
- return { kind: "gift_paid", giftIntentId: gift.giftIntentId, providerObjectId: gift.providerObjectId };
2887
+ return { kind: "gift_paid", giftIntentId, providerObjectId, ...identity };
2868
2888
  }
2869
- if (event.type === "charge.refunded") return { kind: "gift_revoked", giftIntentId: gift.giftIntentId, reason: "refunded" };
2870
- if (event.type === "customer.subscription.deleted") return { kind: "gift_revoked", giftIntentId: gift.giftIntentId, reason: "canceled" };
2889
+ if (event.type === "charge.refunded") return { kind: "gift_revoked", giftIntentId, ...identity, reason: "refunded" };
2890
+ if (event.type === "customer.subscription.deleted") return { kind: "gift_revoked", giftIntentId, ...identity, reason: "canceled" };
2871
2891
  return { kind: "ignored", type: event.type };
2872
2892
  }
2873
2893
  const ref = findApplicationRef(obj);