@odla-ai/chapter 0.31.2 → 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 +2 -1
package/dist/index.cjs
CHANGED
|
@@ -106,7 +106,7 @@ __export(index_exports, {
|
|
|
106
106
|
slotWindow: () => slotWindow,
|
|
107
107
|
stageIndex: () => stageIndex,
|
|
108
108
|
stripeCall: () => stripeCall,
|
|
109
|
-
stripeForm: () => stripeForm,
|
|
109
|
+
stripeForm: () => import_stripe.stripeForm,
|
|
110
110
|
subAnnualCents: () => subAnnualCents,
|
|
111
111
|
submitApplication: () => submitApplication,
|
|
112
112
|
subscriptionIdempotencyKey: () => subscriptionIdempotencyKey,
|
|
@@ -116,7 +116,7 @@ __export(index_exports, {
|
|
|
116
116
|
updateClerkUserMetadata: () => updateClerkUserMetadata,
|
|
117
117
|
updateClerkUserMetadataByEmail: () => updateClerkUserMetadataByEmail,
|
|
118
118
|
validateScheduling: () => validateScheduling,
|
|
119
|
-
verifyStripeSignature: () => verifyStripeSignature,
|
|
119
|
+
verifyStripeSignature: () => import_stripe.verifyStripeSignature,
|
|
120
120
|
webhookMutationId: () => webhookMutationId
|
|
121
121
|
});
|
|
122
122
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -1680,53 +1680,10 @@ function emailGroupFrom(row) {
|
|
|
1680
1680
|
}
|
|
1681
1681
|
|
|
1682
1682
|
// src/payments.ts
|
|
1683
|
-
|
|
1684
|
-
const parts = {};
|
|
1685
|
-
for (const p of header.split(",")) {
|
|
1686
|
-
const [k, v] = p.split("=", 2);
|
|
1687
|
-
if (k && v !== void 0) parts[k] = v;
|
|
1688
|
-
}
|
|
1689
|
-
return { t: parts.t, v1: parts.v1 };
|
|
1690
|
-
}
|
|
1691
|
-
function toHex(buf) {
|
|
1692
|
-
return [...new Uint8Array(buf)].map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
1693
|
-
}
|
|
1694
|
-
function timingSafeEqual(a, b) {
|
|
1695
|
-
if (a.length !== b.length) return false;
|
|
1696
|
-
let diff = 0;
|
|
1697
|
-
for (let i = 0; i < a.length; i++) diff |= a.charCodeAt(i) ^ b.charCodeAt(i);
|
|
1698
|
-
return diff === 0;
|
|
1699
|
-
}
|
|
1700
|
-
async function verifyStripeSignature(payload, header, secret, opts = {}) {
|
|
1701
|
-
const { t, v1 } = parseSigHeader(header);
|
|
1702
|
-
if (!t || !v1) return false;
|
|
1703
|
-
const ts = Number(t);
|
|
1704
|
-
if (!Number.isFinite(ts)) return false;
|
|
1705
|
-
const nowSec = (opts.now ?? Date.now()) / 1e3;
|
|
1706
|
-
const tolerance = opts.toleranceSec ?? 300;
|
|
1707
|
-
if (Math.abs(nowSec - ts) > tolerance) return false;
|
|
1708
|
-
const enc = new TextEncoder();
|
|
1709
|
-
const key = await crypto.subtle.importKey("raw", enc.encode(secret), { name: "HMAC", hash: "SHA-256" }, false, ["sign"]);
|
|
1710
|
-
const mac = await crypto.subtle.sign("HMAC", key, enc.encode(`${t}.${payload}`));
|
|
1711
|
-
return timingSafeEqual(toHex(mac), v1);
|
|
1712
|
-
}
|
|
1683
|
+
var import_stripe = require("@odla-ai/stripe");
|
|
1713
1684
|
function paymentsReady(group, hasSecretKey) {
|
|
1714
1685
|
return Boolean(group.stripePublishableKey && group.stripePriceId && hasSecretKey);
|
|
1715
1686
|
}
|
|
1716
|
-
function stripeForm(params) {
|
|
1717
|
-
const out = new URLSearchParams();
|
|
1718
|
-
for (const [k, v] of Object.entries(params)) {
|
|
1719
|
-
if (v === void 0 || v === null) continue;
|
|
1720
|
-
if (typeof v === "object") {
|
|
1721
|
-
for (const [k2, v2] of Object.entries(v)) {
|
|
1722
|
-
if (v2 !== void 0 && v2 !== null) out.append(`${k}[${k2}]`, String(v2));
|
|
1723
|
-
}
|
|
1724
|
-
} else {
|
|
1725
|
-
out.append(k, String(v));
|
|
1726
|
-
}
|
|
1727
|
-
}
|
|
1728
|
-
return out.toString();
|
|
1729
|
-
}
|
|
1730
1687
|
function subscriptionIdempotencyKey(applicationId) {
|
|
1731
1688
|
return `sub:${applicationId}`;
|
|
1732
1689
|
}
|
|
@@ -2110,18 +2067,15 @@ function subAnnualCents(sub) {
|
|
|
2110
2067
|
}
|
|
2111
2068
|
|
|
2112
2069
|
// src/payments-stripe.ts
|
|
2070
|
+
var import_stripe2 = require("@odla-ai/stripe");
|
|
2113
2071
|
async function stripeCall(sk, method, path, params, idempotencyKey) {
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
}
|
|
2122
|
-
const res = await fetch(`https://api.stripe.com${path}${qs}`, init);
|
|
2123
|
-
const body = await res.json().catch(() => ({}));
|
|
2124
|
-
return { ok: res.ok, status: res.status, body };
|
|
2072
|
+
return (0, import_stripe2.stripeRequest)(
|
|
2073
|
+
{ secretKey: sk },
|
|
2074
|
+
method,
|
|
2075
|
+
path,
|
|
2076
|
+
params,
|
|
2077
|
+
idempotencyKey ? { idempotencyKey } : {}
|
|
2078
|
+
);
|
|
2125
2079
|
}
|
|
2126
2080
|
|
|
2127
2081
|
// src/clerk.ts
|