@odla-ai/chapter 0.38.0 → 0.39.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
@@ -2507,9 +2507,21 @@ function webhookMutationId(eventId) {
2507
2507
  function findApplicationRef(obj) {
2508
2508
  const metaOf = (v) => v && typeof v === "object" ? v.metadata ?? {} : {};
2509
2509
  const pick = (m) => typeof m.applicationId === "string" ? m.applicationId : void 0;
2510
- const applicationId = pick(metaOf(obj)) ?? pick(metaOf(obj.subscription_details)) ?? pick(metaOf(obj.parent?.subscription_details));
2510
+ const candidates = [
2511
+ metaOf(obj),
2512
+ metaOf(obj.subscription_details),
2513
+ metaOf(obj.parent?.subscription_details)
2514
+ ];
2515
+ const applicationId = candidates.map(pick).find(Boolean);
2516
+ const appId = candidates.map((metadata) => typeof metadata.odlaAppId === "string" ? metadata.odlaAppId : void 0).find(Boolean);
2517
+ const environment = candidates.map((metadata) => typeof metadata.odlaEnvironment === "string" ? metadata.odlaEnvironment : void 0).find(Boolean);
2511
2518
  const customerId = typeof obj.customer === "string" ? obj.customer : void 0;
2512
- return { ...applicationId ? { applicationId } : {}, ...customerId ? { customerId } : {} };
2519
+ return {
2520
+ ...applicationId ? { applicationId } : {},
2521
+ ...customerId ? { customerId } : {},
2522
+ ...appId ? { appId } : {},
2523
+ ...environment ? { environment } : {}
2524
+ };
2513
2525
  }
2514
2526
  function findGiftRef(obj) {
2515
2527
  const metaOf = (value) => value && typeof value === "object" ? value.metadata ?? {} : {};
@@ -3135,10 +3147,10 @@ async function syncApplicationToCrm(deps, opts) {
3135
3147
  return recordId;
3136
3148
  }
3137
3149
  async function backfillCrm(deps) {
3138
- const [appsRes, usersRes] = await Promise.all([
3139
- deps.db.query({ applications: { $: { order: { createdAt: "desc" }, limit: 1e3 } } }),
3140
- deps.db.query({ $users: { $: { limit: 1e3 } } })
3141
- ]);
3150
+ const data = await deps.db.query({
3151
+ applications: { $: { order: { createdAt: "desc" }, limit: 1e3 } },
3152
+ $users: { $: { limit: 1e3 } }
3153
+ });
3142
3154
  const seen = /* @__PURE__ */ new Set();
3143
3155
  let synced = 0;
3144
3156
  const errors = [];
@@ -3153,8 +3165,8 @@ async function backfillCrm(deps) {
3153
3165
  errors.push({ email: key, error: err instanceof Error ? err.message : String(err) });
3154
3166
  }
3155
3167
  };
3156
- for (const a of appsRes.applications ?? []) await run(a, str(a.status));
3157
- for (const u of usersRes.$users ?? []) {
3168
+ for (const a of data.applications ?? []) await run(a, str(a.status));
3169
+ for (const u of data.$users ?? []) {
3158
3170
  if (u.deleted === true) continue;
3159
3171
  await run({ email: u.email, firstName: str(u.name) });
3160
3172
  }