@hearthkit/payments 0.1.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/package.json +50 -0
- package/src/create-checkout-session.test.ts +268 -0
- package/src/create-checkout-session.ts +216 -0
- package/src/create-customer-portal-session.test.ts +160 -0
- package/src/create-customer-portal-session.ts +66 -0
- package/src/create-payments-client.test.ts +231 -0
- package/src/create-payments-client.ts +90 -0
- package/src/handle-stripe-webhook-ignored.test.ts +293 -0
- package/src/handle-stripe-webhook-purchase.test.ts +279 -0
- package/src/handle-stripe-webhook-signature.test.ts +194 -0
- package/src/handle-stripe-webhook-subscription.test.ts +376 -0
- package/src/handle-stripe-webhook.ts +133 -0
- package/src/hearthkit-payments-drizzle-schema.test.ts +214 -0
- package/src/hearthkit-payments-drizzle-schema.ts +80 -0
- package/src/index.ts +267 -0
- package/src/list-payments-purchases.test.ts +132 -0
- package/src/list-payments-purchases.ts +57 -0
- package/src/payments-catalog-lookup.ts +23 -0
- package/src/payments-catalog-validation.ts +190 -0
- package/src/payments-client-secrets.ts +47 -0
- package/src/payments-contract.ts +1038 -0
- package/src/payments-customer-record.ts +89 -0
- package/src/payments-database-unavailable.test.ts +152 -0
- package/src/payments-env-schema-fragment.test.ts +197 -0
- package/src/payments-failure-results.ts +185 -0
- package/src/payments-input-invalid.test.ts +201 -0
- package/src/payments-purchase-record.ts +63 -0
- package/src/payments-row-identifier.ts +10 -0
- package/src/payments-stripe-unreachable.test.ts +91 -0
- package/src/payments-subscription-record.ts +77 -0
- package/src/read-payments-subscription.test.ts +126 -0
- package/src/read-payments-subscription.ts +61 -0
- package/src/redact-payments-secrets.ts +18 -0
- package/src/stripe-catalog-price-sync.ts +101 -0
- package/src/stripe-catalog-product-sync.ts +75 -0
- package/src/stripe-checkout-session-event.ts +204 -0
- package/src/stripe-event-payload-fields.ts +39 -0
- package/src/stripe-price-lookup-key.ts +26 -0
- package/src/stripe-subscription-event.ts +112 -0
- package/src/stripe-webhook-delivery-results.ts +46 -0
- package/src/sync-payments-catalog.test.ts +208 -0
- package/src/sync-payments-catalog.ts +65 -0
- package/src/thrown-payments-error-details.ts +134 -0
- package/src/thrown-payments-error-failure.ts +74 -0
- package/src/verify-payments-tables-exist.test.ts +84 -0
- package/src/verify-payments-tables-exist.ts +67 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { PaymentsClient } from './payments-contract.ts'
|
|
2
|
+
import { redactPaymentsSecrets } from './redact-payments-secrets.ts'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The two secrets a client was built with, held beside the handle rather than on it. `PaymentsClient`
|
|
6
|
+
* carries the webhook secret because handing it to `handleStripeWebhook` is its whole job, but it
|
|
7
|
+
* deliberately does not carry the API key — the Stripe client already holds that internally — so the
|
|
8
|
+
* key is kept in a WeakMap here, where nothing can serialise it and it dies with the handle.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
type PaymentsClientSecrets = {
|
|
12
|
+
stripeSecretKey: string
|
|
13
|
+
stripeWebhookSecret: string
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const secretsByPaymentsClient = new WeakMap<PaymentsClient, PaymentsClientSecrets>()
|
|
17
|
+
|
|
18
|
+
/** Records the secrets a client was built with, so a failure can scrub them out of Stripe's own words. */
|
|
19
|
+
export function rememberPaymentsClientSecrets(
|
|
20
|
+
paymentsClient: PaymentsClient,
|
|
21
|
+
secrets: PaymentsClientSecrets,
|
|
22
|
+
): void {
|
|
23
|
+
secretsByPaymentsClient.set(paymentsClient, secrets)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Every secret that must never appear in a message this client produces; empty for a handle this package did not build. */
|
|
27
|
+
export function readPaymentsClientSecrets(
|
|
28
|
+
paymentsClient: PaymentsClient | undefined,
|
|
29
|
+
): readonly string[] {
|
|
30
|
+
if (paymentsClient === undefined) {
|
|
31
|
+
return []
|
|
32
|
+
}
|
|
33
|
+
const secrets = secretsByPaymentsClient.get(paymentsClient)
|
|
34
|
+
const webhookSecret = String(paymentsClient.stripeWebhookSecret ?? '')
|
|
35
|
+
if (secrets === undefined) {
|
|
36
|
+
return webhookSecret.length > 0 ? [webhookSecret] : []
|
|
37
|
+
}
|
|
38
|
+
return [secrets.stripeSecretKey, secrets.stripeWebhookSecret, webhookSecret]
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Third-party text with this client's secrets removed, ready to quote into a returned failure. */
|
|
42
|
+
export function redactPaymentsClientSecrets(
|
|
43
|
+
text: string,
|
|
44
|
+
paymentsClient: PaymentsClient | undefined,
|
|
45
|
+
): string {
|
|
46
|
+
return redactPaymentsSecrets(text, readPaymentsClientSecrets(paymentsClient))
|
|
47
|
+
}
|