@odla-ai/chapter 0.31.1 → 0.31.3
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 +11 -57
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -20
- package/dist/index.d.ts +4 -20
- package/dist/index.js +9 -55
- package/dist/index.js.map +1 -1
- package/dist/worker/index.cjs +10 -56
- package/dist/worker/index.cjs.map +1 -1
- package/dist/worker/index.js +10 -56
- package/dist/worker/index.js.map +1 -1
- package/package.json +3 -2
package/dist/worker/index.cjs
CHANGED
|
@@ -1481,50 +1481,7 @@ var handleSchedule = async (req, url, env, ctx) => {
|
|
|
1481
1481
|
};
|
|
1482
1482
|
|
|
1483
1483
|
// src/payments.ts
|
|
1484
|
-
|
|
1485
|
-
const parts = {};
|
|
1486
|
-
for (const p of header.split(",")) {
|
|
1487
|
-
const [k, v] = p.split("=", 2);
|
|
1488
|
-
if (k && v !== void 0) parts[k] = v;
|
|
1489
|
-
}
|
|
1490
|
-
return { t: parts.t, v1: parts.v1 };
|
|
1491
|
-
}
|
|
1492
|
-
function toHex(buf) {
|
|
1493
|
-
return [...new Uint8Array(buf)].map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
1494
|
-
}
|
|
1495
|
-
function timingSafeEqual(a, b) {
|
|
1496
|
-
if (a.length !== b.length) return false;
|
|
1497
|
-
let diff = 0;
|
|
1498
|
-
for (let i = 0; i < a.length; i++) diff |= a.charCodeAt(i) ^ b.charCodeAt(i);
|
|
1499
|
-
return diff === 0;
|
|
1500
|
-
}
|
|
1501
|
-
async function verifyStripeSignature(payload, header, secret, opts = {}) {
|
|
1502
|
-
const { t, v1 } = parseSigHeader(header);
|
|
1503
|
-
if (!t || !v1) return false;
|
|
1504
|
-
const ts = Number(t);
|
|
1505
|
-
if (!Number.isFinite(ts)) return false;
|
|
1506
|
-
const nowSec = (opts.now ?? Date.now()) / 1e3;
|
|
1507
|
-
const tolerance = opts.toleranceSec ?? 300;
|
|
1508
|
-
if (Math.abs(nowSec - ts) > tolerance) return false;
|
|
1509
|
-
const enc = new TextEncoder();
|
|
1510
|
-
const key = await crypto.subtle.importKey("raw", enc.encode(secret), { name: "HMAC", hash: "SHA-256" }, false, ["sign"]);
|
|
1511
|
-
const mac = await crypto.subtle.sign("HMAC", key, enc.encode(`${t}.${payload}`));
|
|
1512
|
-
return timingSafeEqual(toHex(mac), v1);
|
|
1513
|
-
}
|
|
1514
|
-
function stripeForm(params) {
|
|
1515
|
-
const out = new URLSearchParams();
|
|
1516
|
-
for (const [k, v] of Object.entries(params)) {
|
|
1517
|
-
if (v === void 0 || v === null) continue;
|
|
1518
|
-
if (typeof v === "object") {
|
|
1519
|
-
for (const [k2, v2] of Object.entries(v)) {
|
|
1520
|
-
if (v2 !== void 0 && v2 !== null) out.append(`${k}[${k2}]`, String(v2));
|
|
1521
|
-
}
|
|
1522
|
-
} else {
|
|
1523
|
-
out.append(k, String(v));
|
|
1524
|
-
}
|
|
1525
|
-
}
|
|
1526
|
-
return out.toString();
|
|
1527
|
-
}
|
|
1484
|
+
var import_stripe = require("@odla-ai/stripe");
|
|
1528
1485
|
function webhookMutationId(eventId) {
|
|
1529
1486
|
return `stripe:${eventId}`;
|
|
1530
1487
|
}
|
|
@@ -1571,18 +1528,15 @@ function canceledPatch() {
|
|
|
1571
1528
|
}
|
|
1572
1529
|
|
|
1573
1530
|
// src/payments-stripe.ts
|
|
1531
|
+
var import_stripe2 = require("@odla-ai/stripe");
|
|
1574
1532
|
async function stripeCall(sk, method, path, params, idempotencyKey) {
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
}
|
|
1583
|
-
const res = await fetch(`https://api.stripe.com${path}${qs}`, init);
|
|
1584
|
-
const body = await res.json().catch(() => ({}));
|
|
1585
|
-
return { ok: res.ok, status: res.status, body };
|
|
1533
|
+
return (0, import_stripe2.stripeRequest)(
|
|
1534
|
+
{ secretKey: sk },
|
|
1535
|
+
method,
|
|
1536
|
+
path,
|
|
1537
|
+
params,
|
|
1538
|
+
idempotencyKey ? { idempotencyKey } : {}
|
|
1539
|
+
);
|
|
1586
1540
|
}
|
|
1587
1541
|
function fail(op, r) {
|
|
1588
1542
|
const err = new Error(`stripe ${op} failed: ${r.status}`);
|
|
@@ -1645,7 +1599,7 @@ function createStripeProvider(config) {
|
|
|
1645
1599
|
return { customerId, subscriptionId: String(sub.body.id), clientSecret };
|
|
1646
1600
|
},
|
|
1647
1601
|
async ingestWebhook(rawBody, sigHeader) {
|
|
1648
|
-
if (!webhookSecret || !await verifyStripeSignature(rawBody, sigHeader, webhookSecret)) {
|
|
1602
|
+
if (!webhookSecret || !await (0, import_stripe2.verifyStripeSignature)(rawBody, sigHeader, webhookSecret)) {
|
|
1649
1603
|
return { ok: false, reason: "bad_signature" };
|
|
1650
1604
|
}
|
|
1651
1605
|
const event = JSON.parse(rawBody);
|