@odla-ai/chapter 0.38.1 → 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 +14 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +14 -2
- package/dist/index.js.map +1 -1
- package/dist/worker/index.cjs +27 -3
- package/dist/worker/index.cjs.map +1 -1
- package/dist/worker/index.js +27 -3
- package/dist/worker/index.js.map +1 -1
- package/package.json +1 -1
package/dist/worker/index.cjs
CHANGED
|
@@ -3373,9 +3373,21 @@ function webhookMutationId(eventId) {
|
|
|
3373
3373
|
function findApplicationRef(obj) {
|
|
3374
3374
|
const metaOf = (v) => v && typeof v === "object" ? v.metadata ?? {} : {};
|
|
3375
3375
|
const pick = (m) => typeof m.applicationId === "string" ? m.applicationId : void 0;
|
|
3376
|
-
const
|
|
3376
|
+
const candidates = [
|
|
3377
|
+
metaOf(obj),
|
|
3378
|
+
metaOf(obj.subscription_details),
|
|
3379
|
+
metaOf(obj.parent?.subscription_details)
|
|
3380
|
+
];
|
|
3381
|
+
const applicationId = candidates.map(pick).find(Boolean);
|
|
3382
|
+
const appId = candidates.map((metadata) => typeof metadata.odlaAppId === "string" ? metadata.odlaAppId : void 0).find(Boolean);
|
|
3383
|
+
const environment = candidates.map((metadata) => typeof metadata.odlaEnvironment === "string" ? metadata.odlaEnvironment : void 0).find(Boolean);
|
|
3377
3384
|
const customerId = typeof obj.customer === "string" ? obj.customer : void 0;
|
|
3378
|
-
return {
|
|
3385
|
+
return {
|
|
3386
|
+
...applicationId ? { applicationId } : {},
|
|
3387
|
+
...customerId ? { customerId } : {},
|
|
3388
|
+
...appId ? { appId } : {},
|
|
3389
|
+
...environment ? { environment } : {}
|
|
3390
|
+
};
|
|
3379
3391
|
}
|
|
3380
3392
|
function findGiftRef(obj) {
|
|
3381
3393
|
const metaOf = (value) => value && typeof value === "object" ? value.metadata ?? {} : {};
|
|
@@ -3466,7 +3478,13 @@ function createStripeProvider(config) {
|
|
|
3466
3478
|
return {
|
|
3467
3479
|
async createSubscription(input) {
|
|
3468
3480
|
const sk = requireSecret(secretKey);
|
|
3469
|
-
const meta = {
|
|
3481
|
+
const meta = {
|
|
3482
|
+
applicationId: input.applicationId,
|
|
3483
|
+
groupId: input.groupId,
|
|
3484
|
+
email: input.email,
|
|
3485
|
+
odlaAppId: input.appId,
|
|
3486
|
+
odlaEnvironment: input.environment
|
|
3487
|
+
};
|
|
3470
3488
|
let customerId = input.existingCustomerId;
|
|
3471
3489
|
if (!customerId) {
|
|
3472
3490
|
const cust = await stripeCall(
|
|
@@ -3986,6 +4004,8 @@ async function startSubscription(req, env, ctx) {
|
|
|
3986
4004
|
let result;
|
|
3987
4005
|
try {
|
|
3988
4006
|
result = await provider.createSubscription({
|
|
4007
|
+
appId: env.ODLA_APP_ID,
|
|
4008
|
+
environment: env.ODLA_ENV,
|
|
3989
4009
|
applicationId,
|
|
3990
4010
|
groupId: String(group.id),
|
|
3991
4011
|
email: String(app.email ?? ""),
|
|
@@ -4015,6 +4035,10 @@ async function ingestWebhook(req, env, ctx) {
|
|
|
4015
4035
|
if (!ingest.ok) return json({ error: "invalid signature" }, 400);
|
|
4016
4036
|
const { eventId, event } = ingest;
|
|
4017
4037
|
if (event.kind === "ignored") return json({ ok: true, ignored: event.type });
|
|
4038
|
+
const identifiedEnvironment = event.appId !== void 0 || event.environment !== void 0;
|
|
4039
|
+
if (env.ODLA_APP_ID && identifiedEnvironment && (event.appId !== env.ODLA_APP_ID || event.environment !== env.ODLA_ENV)) {
|
|
4040
|
+
return json({ ok: true, matched: false });
|
|
4041
|
+
}
|
|
4018
4042
|
if (event.kind === "gift_paid" || event.kind === "gift_revoked") {
|
|
4019
4043
|
const intent = await firstRow2(db, "giftPurchaseIntents", { where: { id: event.giftIntentId }, limit: 1 });
|
|
4020
4044
|
if (!intent || intent.chapterId !== ctx.chapter.id || intent.environment !== env.ODLA_ENV) {
|