@stacksjs/payments 0.75.187 → 0.75.188
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/drivers/stripe.d.ts +52 -1
- package/dist/drivers/stripe.js +1 -1
- package/package.json +8 -8
package/dist/drivers/stripe.d.ts
CHANGED
|
@@ -1,6 +1,52 @@
|
|
|
1
1
|
import type Stripe from 'stripe';
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Whether the two things Stripe needs are actually present.
|
|
4
|
+
*
|
|
5
|
+
* Reported separately because an app that is missing both should be told
|
|
6
|
+
* both, and because the two are fixed in different places: one in the
|
|
7
|
+
* environment, one in the app's package.json (stacksjs/stacks#2911).
|
|
8
|
+
*/
|
|
9
|
+
export declare function stripeAvailability(): StripeAvailability;
|
|
10
|
+
/**
|
|
11
|
+
* Whether Stripe is usable in this process.
|
|
12
|
+
*
|
|
13
|
+
* This used to check only the secret key, so it answered `true` on a tree
|
|
14
|
+
* where every Stripe call would throw - which is the one answer that makes
|
|
15
|
+
* the function useless, since the reason to ask is to find that out.
|
|
16
|
+
*/
|
|
3
17
|
export declare function isStripeConfigured(): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Why Stripe cannot be used, or null when it can.
|
|
20
|
+
*
|
|
21
|
+
* Names everything that is missing rather than the first thing, so an app
|
|
22
|
+
* missing both the key and the SDK is not told to fix one, redeploy, and
|
|
23
|
+
* discover the other. Pure, so a caller can report on an availability it
|
|
24
|
+
* gathered earlier - a boot check, a health endpoint, `doctor`.
|
|
25
|
+
*/
|
|
26
|
+
export declare function describeStripeAvailability(available: StripeAvailability): string | null;
|
|
27
|
+
/**
|
|
28
|
+
* Say so, once, when this process is set up for Stripe but cannot use it.
|
|
29
|
+
*
|
|
30
|
+
* Returns the message it reported, or null when there was nothing to say.
|
|
31
|
+
*
|
|
32
|
+
* Called from the API entry points so a tree with no SDK is one line at boot
|
|
33
|
+
* rather than a 500 inside the first webhook (stacksjs/stacks#2911). It warns
|
|
34
|
+
* rather than refusing to start: a missing SDK breaks billing, but unlike an
|
|
35
|
+
* unresolvable middleware alias it cannot serve anything it should not, and
|
|
36
|
+
* refusing would take down an app carrying a `STRIPE_SECRET_KEY` it no longer
|
|
37
|
+
* uses.
|
|
38
|
+
*
|
|
39
|
+
* Only fires when a key is configured and the SDK is not. A key is what says
|
|
40
|
+
* the app means to use Stripe; the driver name does not, since `stripe` is
|
|
41
|
+
* the default for every app that never chose one. A missing key alone is
|
|
42
|
+
* ordinary in development and says nothing.
|
|
43
|
+
*/
|
|
44
|
+
export declare function reportStripeAvailability(options?: {
|
|
45
|
+
|
|
46
|
+
warn?: (message: string) => void
|
|
47
|
+
|
|
48
|
+
available?: StripeAvailability
|
|
49
|
+
}): string | null;
|
|
4
50
|
/**
|
|
5
51
|
* Lazy-initialized Stripe instance.
|
|
6
52
|
* Only throws when you actually try to use Stripe, not at module load time.
|
|
@@ -8,4 +54,9 @@ export declare function isStripeConfigured(): boolean;
|
|
|
8
54
|
* (e.g., in tests, CLI, or environments that don't use Stripe).
|
|
9
55
|
*/
|
|
10
56
|
export declare const stripe: Stripe;
|
|
57
|
+
/** What Stripe needs in order to work, reported separately. */
|
|
58
|
+
export declare interface StripeAvailability {
|
|
59
|
+
key: boolean
|
|
60
|
+
sdk: boolean
|
|
61
|
+
}
|
|
11
62
|
declare type StripeConstructor = typeof Stripe;
|
package/dist/drivers/stripe.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createRequire}from"node:module";import{services}from"@stacksjs/config";const require=createRequire(import.meta.url);function StripeCtor(){try{return require("stripe")}catch{throw Error("
|
|
1
|
+
import{createRequire}from"node:module";import{services}from"@stacksjs/config";const require=createRequire(import.meta.url);function StripeCtor(){try{return require("stripe")}catch{throw Error(describeStripeAvailability({key:!0,sdk:!1}))}}let _stripe=null;export function stripeAvailability(){return{key:Boolean(String(services?.stripe?.secretKey||"").trim()),sdk:isStripeSdkInstalled()}}function isStripeSdkInstalled(){try{require.resolve("stripe");return!0}catch{return!1}}export function isStripeConfigured(){const{key,sdk}=stripeAvailability();return key&&sdk}export function describeStripeAvailability(available){if(available.key&&available.sdk)return null;const reasons=[];if(!available.sdk)reasons.push("the `stripe` package is not installed (it is an optional peer, which Bun does not install for you - run `bun add stripe` in your app, pinned to an exact version)");if(!available.key)reasons.push("no Stripe secret key is configured (set STRIPE_SECRET_KEY in your .env)");return`Stripe is being used but is not usable here: ${reasons.join("; and ")}.`}export function reportStripeAvailability(options={}){const available=options.available??stripeAvailability();if(!available.key||available.sdk)return null;const message=describeStripeAvailability(available);(options.warn??console.warn)(`[stacks] ${message}`);return message}export const stripe=new Proxy({},{get(_target,prop){if(!_stripe){const unusable=describeStripeAvailability(stripeAvailability());if(unusable)throw Error(unusable);const apiKey=String(services?.stripe?.secretKey||"").trim(),Stripe=StripeCtor(),apiVersion=Stripe.API_VERSION,configuredVersion=services?.stripe?.apiVersion;if(configuredVersion&&configuredVersion!==apiVersion)throw Error(`Stripe API version ${configuredVersion} does not match the installed SDK version ${apiVersion}`);_stripe=new Stripe(apiKey,{apiVersion})}return _stripe[prop]}});
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@stacksjs/payments",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"sideEffects": false,
|
|
5
|
-
"version": "0.75.
|
|
5
|
+
"version": "0.75.188",
|
|
6
6
|
"description": "The Stacks payments package. Currently supporting Stripe.",
|
|
7
7
|
"author": "Chris Breuer",
|
|
8
8
|
"contributors": [
|
|
@@ -60,12 +60,12 @@
|
|
|
60
60
|
"prepublishOnly": "bun run build"
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
|
-
"@stacksjs/config": "0.75.
|
|
64
|
-
"@stacksjs/database": "0.75.
|
|
65
|
-
"@stacksjs/error-handling": "0.75.
|
|
66
|
-
"@stacksjs/logging": "0.75.
|
|
67
|
-
"@stacksjs/orm": "0.75.
|
|
68
|
-
"@stacksjs/types": "0.75.
|
|
63
|
+
"@stacksjs/config": "0.75.188",
|
|
64
|
+
"@stacksjs/database": "0.75.188",
|
|
65
|
+
"@stacksjs/error-handling": "0.75.188",
|
|
66
|
+
"@stacksjs/logging": "0.75.188",
|
|
67
|
+
"@stacksjs/orm": "0.75.188",
|
|
68
|
+
"@stacksjs/types": "0.75.188"
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
71
71
|
"@stripe/stripe-js": "^10.0.0",
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
}
|
|
81
81
|
},
|
|
82
82
|
"devDependencies": {
|
|
83
|
-
"@stacksjs/utils": "0.75.
|
|
83
|
+
"@stacksjs/utils": "0.75.188",
|
|
84
84
|
"@stripe/stripe-js": "^10.0.0",
|
|
85
85
|
"better-dx": "^0.2.24",
|
|
86
86
|
"stripe": "23.0.0"
|