alchemy 0.24.0 → 0.25.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/lib/aws/control/client.js +1 -1
- package/lib/aws/control/client.js.map +1 -1
- package/lib/aws/control/resource.d.ts.map +1 -1
- package/lib/aws/control/resource.js +2 -1
- package/lib/aws/control/resource.js.map +1 -1
- package/lib/aws/function.d.ts.map +1 -1
- package/lib/aws/function.js +1 -4
- package/lib/aws/function.js.map +1 -1
- package/lib/cloudflare/ai.d.ts +21 -0
- package/lib/cloudflare/ai.d.ts.map +1 -1
- package/lib/cloudflare/ai.js +21 -0
- package/lib/cloudflare/ai.js.map +1 -1
- package/lib/cloudflare/bindings.d.ts +3 -3
- package/lib/cloudflare/bindings.d.ts.map +1 -1
- package/lib/cloudflare/bindings.js.map +1 -1
- package/lib/cloudflare/bound.d.ts +3 -3
- package/lib/cloudflare/bound.d.ts.map +1 -1
- package/lib/cloudflare/do-state-store/index.d.ts +2 -0
- package/lib/cloudflare/do-state-store/index.d.ts.map +1 -0
- package/lib/cloudflare/do-state-store/index.js +2 -0
- package/lib/cloudflare/do-state-store/index.js.map +1 -0
- package/lib/cloudflare/do-state-store/internal.d.ts +19 -0
- package/lib/cloudflare/do-state-store/internal.d.ts.map +1 -0
- package/lib/cloudflare/do-state-store/internal.js +163 -0
- package/lib/cloudflare/do-state-store/internal.js.map +1 -0
- package/lib/cloudflare/do-state-store/store.d.ts +59 -0
- package/lib/cloudflare/do-state-store/store.d.ts.map +1 -0
- package/lib/cloudflare/do-state-store/store.js +120 -0
- package/lib/cloudflare/do-state-store/store.js.map +1 -0
- package/lib/cloudflare/do-state-store/types.d.ts +82 -0
- package/lib/cloudflare/do-state-store/types.d.ts.map +1 -0
- package/lib/cloudflare/do-state-store/types.js +1 -0
- package/lib/cloudflare/do-state-store/types.js.map +1 -0
- package/lib/cloudflare/do-state-store/worker.d.ts +27 -0
- package/lib/cloudflare/do-state-store/worker.d.ts.map +1 -0
- package/lib/cloudflare/do-state-store/worker.js +170 -0
- package/lib/cloudflare/do-state-store/worker.js.map +1 -0
- package/lib/cloudflare/index.d.ts +1 -0
- package/lib/cloudflare/index.d.ts.map +1 -1
- package/lib/cloudflare/index.js +1 -0
- package/lib/cloudflare/index.js.map +1 -1
- package/lib/cloudflare/pipeline.js +1 -1
- package/lib/cloudflare/pipeline.js.map +1 -1
- package/lib/cloudflare/queue-consumer.d.ts +14 -1
- package/lib/cloudflare/queue-consumer.d.ts.map +1 -1
- package/lib/cloudflare/queue-consumer.js +17 -0
- package/lib/cloudflare/queue-consumer.js.map +1 -1
- package/lib/cloudflare/website.d.ts +30 -1
- package/lib/cloudflare/website.d.ts.map +1 -1
- package/lib/cloudflare/website.js +8 -5
- package/lib/cloudflare/website.js.map +1 -1
- package/lib/cloudflare/worker-assets.d.ts.map +1 -1
- package/lib/cloudflare/worker-assets.js +13 -3
- package/lib/cloudflare/worker-assets.js.map +1 -1
- package/lib/cloudflare/worker-metadata.js +1 -1
- package/lib/cloudflare/worker-metadata.js.map +1 -1
- package/lib/cloudflare/worker.d.ts +40 -1
- package/lib/cloudflare/worker.d.ts.map +1 -1
- package/lib/cloudflare/worker.js +40 -38
- package/lib/cloudflare/worker.js.map +1 -1
- package/lib/cloudflare/wrangler.json.js +1 -1
- package/lib/cloudflare/wrangler.json.js.map +1 -1
- package/lib/cloudflare/zone.d.ts +30 -2
- package/lib/cloudflare/zone.d.ts.map +1 -1
- package/lib/cloudflare/zone.js +53 -0
- package/lib/cloudflare/zone.js.map +1 -1
- package/lib/fs/file-system-state-store.d.ts +3 -1
- package/lib/fs/file-system-state-store.d.ts.map +1 -1
- package/lib/fs/file-system-state-store.js +2 -2
- package/lib/fs/file-system-state-store.js.map +1 -1
- package/lib/stripe/card.d.ts +171 -0
- package/lib/stripe/card.d.ts.map +1 -0
- package/lib/stripe/card.js +148 -0
- package/lib/stripe/card.js.map +1 -0
- package/lib/stripe/client.d.ts +9 -0
- package/lib/stripe/client.d.ts.map +1 -0
- package/lib/stripe/client.js +94 -0
- package/lib/stripe/client.js.map +1 -0
- package/lib/stripe/coupon.d.ts +135 -0
- package/lib/stripe/coupon.d.ts.map +1 -0
- package/lib/stripe/coupon.js +161 -0
- package/lib/stripe/coupon.js.map +1 -0
- package/lib/stripe/customer.d.ts +269 -0
- package/lib/stripe/customer.d.ts.map +1 -0
- package/lib/stripe/customer.js +289 -0
- package/lib/stripe/customer.js.map +1 -0
- package/lib/stripe/entitlements-feature.d.ts +84 -0
- package/lib/stripe/entitlements-feature.d.ts.map +1 -0
- package/lib/stripe/entitlements-feature.js +102 -0
- package/lib/stripe/entitlements-feature.js.map +1 -0
- package/lib/stripe/file.d.ts +143 -0
- package/lib/stripe/file.d.ts.map +1 -0
- package/lib/stripe/file.js +97 -0
- package/lib/stripe/file.js.map +1 -0
- package/lib/stripe/index.d.ts +11 -0
- package/lib/stripe/index.d.ts.map +1 -1
- package/lib/stripe/index.js +11 -0
- package/lib/stripe/index.js.map +1 -1
- package/lib/stripe/meter.d.ts +10 -1
- package/lib/stripe/meter.d.ts.map +1 -1
- package/lib/stripe/meter.js +13 -7
- package/lib/stripe/meter.js.map +1 -1
- package/lib/stripe/portal-configuration.d.ts +286 -0
- package/lib/stripe/portal-configuration.d.ts.map +1 -0
- package/lib/stripe/portal-configuration.js +320 -0
- package/lib/stripe/portal-configuration.js.map +1 -0
- package/lib/stripe/price.d.ts +10 -1
- package/lib/stripe/price.d.ts.map +1 -1
- package/lib/stripe/price.js +34 -13
- package/lib/stripe/price.js.map +1 -1
- package/lib/stripe/product-feature.d.ts +76 -0
- package/lib/stripe/product-feature.d.ts.map +1 -0
- package/lib/stripe/product-feature.js +74 -0
- package/lib/stripe/product-feature.js.map +1 -0
- package/lib/stripe/product.d.ts +10 -1
- package/lib/stripe/product.d.ts.map +1 -1
- package/lib/stripe/product.js +33 -14
- package/lib/stripe/product.js.map +1 -1
- package/lib/stripe/promotion-code.d.ts +138 -0
- package/lib/stripe/promotion-code.d.ts.map +1 -0
- package/lib/stripe/promotion-code.js +150 -0
- package/lib/stripe/promotion-code.js.map +1 -0
- package/lib/stripe/shipping-rate.d.ts +188 -0
- package/lib/stripe/shipping-rate.d.ts.map +1 -0
- package/lib/stripe/shipping-rate.js +198 -0
- package/lib/stripe/shipping-rate.js.map +1 -0
- package/lib/stripe/tax-rate.d.ts +130 -0
- package/lib/stripe/tax-rate.d.ts.map +1 -0
- package/lib/stripe/tax-rate.js +126 -0
- package/lib/stripe/tax-rate.js.map +1 -0
- package/lib/stripe/webhook.d.ts +10 -1
- package/lib/stripe/webhook.d.ts.map +1 -1
- package/lib/stripe/webhook.js +59 -14
- package/lib/stripe/webhook.js.map +1 -1
- package/lib/test/bun.d.ts.map +1 -1
- package/lib/test/bun.js +2 -6
- package/lib/test/bun.js.map +1 -1
- package/lib/test/vitest.d.ts.map +1 -1
- package/lib/test/vitest.js +3 -7
- package/lib/test/vitest.js.map +1 -1
- package/lib/util/retry.d.ts +1 -1
- package/lib/util/retry.d.ts.map +1 -1
- package/lib/util/retry.js.map +1 -1
- package/package.json +3 -2
- package/src/aws/control/client.ts +1 -1
- package/src/aws/control/resource.ts +2 -1
- package/src/aws/function.ts +3 -6
- package/src/cloudflare/ai.ts +21 -0
- package/src/cloudflare/bindings.ts +3 -2
- package/src/cloudflare/bound.ts +3 -3
- package/src/cloudflare/do-state-store/index.ts +1 -0
- package/src/cloudflare/do-state-store/internal.ts +215 -0
- package/src/cloudflare/do-state-store/store.ts +188 -0
- package/src/cloudflare/do-state-store/types.ts +74 -0
- package/src/cloudflare/do-state-store/worker.ts +199 -0
- package/src/cloudflare/index.ts +1 -0
- package/src/cloudflare/pipeline.ts +1 -1
- package/src/cloudflare/queue-consumer.ts +59 -1
- package/src/cloudflare/website.ts +38 -6
- package/src/cloudflare/worker-assets.ts +15 -3
- package/src/cloudflare/worker-metadata.ts +1 -1
- package/src/cloudflare/worker.ts +66 -46
- package/src/cloudflare/wrangler.json.ts +1 -1
- package/src/cloudflare/zone.ts +75 -2
- package/src/fs/file-system-state-store.ts +7 -2
- package/src/stripe/card.ts +320 -0
- package/src/stripe/client.ts +145 -0
- package/src/stripe/coupon.ts +280 -0
- package/src/stripe/customer.ts +528 -0
- package/src/stripe/entitlements-feature.ts +169 -0
- package/src/stripe/file.ts +219 -0
- package/src/stripe/index.ts +11 -0
- package/src/stripe/meter.ts +23 -7
- package/src/stripe/portal-configuration.ts +609 -0
- package/src/stripe/price.ts +47 -14
- package/src/stripe/product-feature.ts +150 -0
- package/src/stripe/product.ts +48 -15
- package/src/stripe/promotion-code.ts +268 -0
- package/src/stripe/shipping-rate.ts +362 -0
- package/src/stripe/tax-rate.ts +218 -0
- package/src/stripe/webhook.ts +82 -15
- package/src/test/bun.ts +2 -7
- package/src/test/vitest.ts +3 -8
- package/src/util/retry.ts +1 -1
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import type Stripe from "stripe";
|
|
2
|
+
import type { Context } from "../context.ts";
|
|
3
|
+
import { Resource } from "../resource.ts";
|
|
4
|
+
import type { Secret } from "../secret.ts";
|
|
5
|
+
import { createStripeClient, isStripeConflictError } from "./client.ts";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Properties for creating a Stripe file
|
|
9
|
+
*/
|
|
10
|
+
export interface FileProps {
|
|
11
|
+
/**
|
|
12
|
+
* A file to upload. The file should follow the specifications of RFC 2388
|
|
13
|
+
*/
|
|
14
|
+
file: any;
|
|
15
|
+
/**
|
|
16
|
+
* The purpose of the uploaded file
|
|
17
|
+
*/
|
|
18
|
+
purpose: Stripe.FileCreateParams.Purpose;
|
|
19
|
+
/**
|
|
20
|
+
* Optional parameters for the file link data
|
|
21
|
+
*/
|
|
22
|
+
fileLink?: {
|
|
23
|
+
/**
|
|
24
|
+
* Whether to create a file link for the uploaded file
|
|
25
|
+
*/
|
|
26
|
+
create: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* The time at which the file link expires
|
|
29
|
+
*/
|
|
30
|
+
expiresAt?: number;
|
|
31
|
+
/**
|
|
32
|
+
* Set of key-value pairs that you can attach to the file link
|
|
33
|
+
*/
|
|
34
|
+
metadata?: Record<string, string>;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* API key to use (overrides environment variable)
|
|
39
|
+
*/
|
|
40
|
+
apiKey?: Secret;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* If true, adopt existing resource if creation fails due to conflict
|
|
44
|
+
*/
|
|
45
|
+
adopt?: boolean;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Output from the Stripe file
|
|
50
|
+
*/
|
|
51
|
+
export interface File extends Resource<"stripe::File"> {
|
|
52
|
+
/**
|
|
53
|
+
* The ID of the file
|
|
54
|
+
*/
|
|
55
|
+
id: string;
|
|
56
|
+
/**
|
|
57
|
+
* String representing the object's type
|
|
58
|
+
*/
|
|
59
|
+
object: "file";
|
|
60
|
+
/**
|
|
61
|
+
* Time at which the object was created
|
|
62
|
+
*/
|
|
63
|
+
created: number;
|
|
64
|
+
/**
|
|
65
|
+
* The time at which the file expires and is no longer available
|
|
66
|
+
*/
|
|
67
|
+
expiresAt?: number;
|
|
68
|
+
/**
|
|
69
|
+
* A filename for the file, suitable for saving to a filesystem
|
|
70
|
+
*/
|
|
71
|
+
filename?: string;
|
|
72
|
+
/**
|
|
73
|
+
* Any links that have been created for the file
|
|
74
|
+
*/
|
|
75
|
+
links?: {
|
|
76
|
+
object: "list";
|
|
77
|
+
data: Array<{
|
|
78
|
+
id: string;
|
|
79
|
+
object: "file_link";
|
|
80
|
+
created: number;
|
|
81
|
+
expired: boolean;
|
|
82
|
+
expiresAt?: number;
|
|
83
|
+
file: string;
|
|
84
|
+
livemode: boolean;
|
|
85
|
+
metadata: Record<string, string>;
|
|
86
|
+
url?: string;
|
|
87
|
+
}>;
|
|
88
|
+
hasMore: boolean;
|
|
89
|
+
url: string;
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* The purpose of the uploaded file
|
|
93
|
+
*/
|
|
94
|
+
purpose: Stripe.File.Purpose;
|
|
95
|
+
/**
|
|
96
|
+
* The size in bytes of the file object
|
|
97
|
+
*/
|
|
98
|
+
size: number;
|
|
99
|
+
/**
|
|
100
|
+
* A user friendly title for the document
|
|
101
|
+
*/
|
|
102
|
+
title?: string;
|
|
103
|
+
/**
|
|
104
|
+
* The type of the file returned
|
|
105
|
+
*/
|
|
106
|
+
type?: string;
|
|
107
|
+
/**
|
|
108
|
+
* The URL from which the file can be downloaded
|
|
109
|
+
*/
|
|
110
|
+
url?: string;
|
|
111
|
+
/**
|
|
112
|
+
* Has the value true if the object exists in live mode or the value false if the object exists in test mode
|
|
113
|
+
*/
|
|
114
|
+
livemode: boolean;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Create and manage Stripe files for uploads
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* // Upload a dispute evidence file
|
|
122
|
+
* const disputeEvidence = await File("dispute-evidence", {
|
|
123
|
+
* file: fs.readFileSync("./evidence.pdf"),
|
|
124
|
+
* purpose: "dispute_evidence"
|
|
125
|
+
* });
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* // Upload an identity document
|
|
129
|
+
* const identityDocument = await File("identity-doc", {
|
|
130
|
+
* file: fs.readFileSync("./passport.jpg"),
|
|
131
|
+
* purpose: "identity_document"
|
|
132
|
+
* });
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* // Upload a business logo with file link
|
|
136
|
+
* const businessLogo = await File("business-logo", {
|
|
137
|
+
* file: fs.readFileSync("./logo.png"),
|
|
138
|
+
* purpose: "business_logo",
|
|
139
|
+
* fileLink: {
|
|
140
|
+
* create: true,
|
|
141
|
+
* expiresAt: Math.floor(Date.now() / 1000) + 86400,
|
|
142
|
+
* metadata: {
|
|
143
|
+
* brand: "company_logo"
|
|
144
|
+
* }
|
|
145
|
+
* }
|
|
146
|
+
* });
|
|
147
|
+
*/
|
|
148
|
+
export const File = Resource(
|
|
149
|
+
"stripe::File",
|
|
150
|
+
async function (
|
|
151
|
+
this: Context<File>,
|
|
152
|
+
_id: string,
|
|
153
|
+
props: FileProps,
|
|
154
|
+
): Promise<File> {
|
|
155
|
+
const stripe = createStripeClient({ apiKey: props.apiKey });
|
|
156
|
+
|
|
157
|
+
if (this.phase === "delete") {
|
|
158
|
+
return this.destroy();
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
try {
|
|
162
|
+
let file: Stripe.File;
|
|
163
|
+
|
|
164
|
+
if (this.phase === "update" && this.output?.id) {
|
|
165
|
+
file = await stripe.files.retrieve(this.output.id);
|
|
166
|
+
} else {
|
|
167
|
+
try {
|
|
168
|
+
file = await stripe.files.create({
|
|
169
|
+
file: props.file,
|
|
170
|
+
purpose: props.purpose,
|
|
171
|
+
});
|
|
172
|
+
} catch (error) {
|
|
173
|
+
if (isStripeConflictError(error) && props.adopt) {
|
|
174
|
+
throw new Error(
|
|
175
|
+
"File adoption is not supported - files are immutable and cannot be adopted",
|
|
176
|
+
);
|
|
177
|
+
} else {
|
|
178
|
+
throw error;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return this({
|
|
184
|
+
id: file.id,
|
|
185
|
+
object: file.object,
|
|
186
|
+
created: file.created,
|
|
187
|
+
expiresAt: file.expires_at || undefined,
|
|
188
|
+
filename: file.filename || undefined,
|
|
189
|
+
links: file.links
|
|
190
|
+
? {
|
|
191
|
+
object: file.links.object,
|
|
192
|
+
data: file.links.data.map((link) => ({
|
|
193
|
+
id: link.id,
|
|
194
|
+
object: link.object,
|
|
195
|
+
created: link.created,
|
|
196
|
+
expired: link.expired,
|
|
197
|
+
expiresAt: link.expires_at || undefined,
|
|
198
|
+
file: typeof link.file === "string" ? link.file : link.file.id,
|
|
199
|
+
livemode: link.livemode,
|
|
200
|
+
metadata: link.metadata,
|
|
201
|
+
url: link.url || undefined,
|
|
202
|
+
})),
|
|
203
|
+
hasMore: file.links.has_more,
|
|
204
|
+
url: file.links.url,
|
|
205
|
+
}
|
|
206
|
+
: undefined,
|
|
207
|
+
purpose: file.purpose as Stripe.File.Purpose,
|
|
208
|
+
size: file.size,
|
|
209
|
+
title: file.title || undefined,
|
|
210
|
+
type: file.type || undefined,
|
|
211
|
+
url: file.url || undefined,
|
|
212
|
+
livemode: true,
|
|
213
|
+
});
|
|
214
|
+
} catch (error) {
|
|
215
|
+
console.error("Error creating/retrieving file:", error);
|
|
216
|
+
throw error;
|
|
217
|
+
}
|
|
218
|
+
},
|
|
219
|
+
);
|
package/src/stripe/index.ts
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
|
+
export * from "./card.ts";
|
|
2
|
+
export * from "./client.ts";
|
|
3
|
+
export * from "./coupon.ts";
|
|
4
|
+
export * from "./customer.ts";
|
|
5
|
+
export * from "./entitlements-feature.ts";
|
|
6
|
+
export * from "./file.ts";
|
|
1
7
|
export * from "./meter.ts";
|
|
8
|
+
export * from "./portal-configuration.ts";
|
|
2
9
|
export * from "./price.ts";
|
|
3
10
|
export * from "./product.ts";
|
|
11
|
+
export * from "./product-feature.ts";
|
|
12
|
+
export * from "./promotion-code.ts";
|
|
13
|
+
export * from "./shipping-rate.ts";
|
|
14
|
+
export * from "./tax-rate.ts";
|
|
4
15
|
export * from "./webhook.ts";
|
package/src/stripe/meter.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import Stripe from "stripe";
|
|
1
|
+
import type Stripe from "stripe";
|
|
2
2
|
import type { Context } from "../context.ts";
|
|
3
3
|
import { Resource } from "../resource.ts";
|
|
4
|
+
import type { Secret } from "../secret.ts";
|
|
5
|
+
import { createStripeClient, isStripeConflictError } from "./client.ts";
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* Properties for creating or updating a Stripe Meter.
|
|
@@ -22,6 +24,14 @@ export interface MeterProps {
|
|
|
22
24
|
valueSettings: {
|
|
23
25
|
eventPayloadKey: string;
|
|
24
26
|
};
|
|
27
|
+
/**
|
|
28
|
+
* API key to use (overrides environment variable)
|
|
29
|
+
*/
|
|
30
|
+
apiKey?: Secret;
|
|
31
|
+
/**
|
|
32
|
+
* If true, adopt existing resource if creation fails due to conflict
|
|
33
|
+
*/
|
|
34
|
+
adopt?: boolean;
|
|
25
35
|
}
|
|
26
36
|
|
|
27
37
|
/**
|
|
@@ -144,11 +154,7 @@ export const Meter = Resource(
|
|
|
144
154
|
_logicalId: string,
|
|
145
155
|
props: MeterProps,
|
|
146
156
|
): Promise<Meter> {
|
|
147
|
-
const
|
|
148
|
-
if (!apiKey) {
|
|
149
|
-
throw new Error("STRIPE_API_KEY environment variable is required");
|
|
150
|
-
}
|
|
151
|
-
const stripe = new Stripe(apiKey);
|
|
157
|
+
const stripe = createStripeClient({ apiKey: props.apiKey });
|
|
152
158
|
|
|
153
159
|
const currentOutputId = this.output?.id;
|
|
154
160
|
|
|
@@ -292,7 +298,17 @@ export const Meter = Resource(
|
|
|
292
298
|
}
|
|
293
299
|
|
|
294
300
|
const createParams = mapPropsToStripeParams(props);
|
|
295
|
-
|
|
301
|
+
try {
|
|
302
|
+
stripeAPIResponse = await stripe.billing.meters.create(createParams);
|
|
303
|
+
} catch (error) {
|
|
304
|
+
if (isStripeConflictError(error) && props.adopt) {
|
|
305
|
+
throw new Error(
|
|
306
|
+
"Meter adoption is not supported - meters cannot be uniquely identified for adoption",
|
|
307
|
+
);
|
|
308
|
+
} else {
|
|
309
|
+
throw error;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
296
312
|
|
|
297
313
|
// If status 'inactive' is requested during creation, and Stripe created it as 'active'
|
|
298
314
|
if (
|