alchemy 0.1.18 → 0.2.1
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/README.md +506 -0
- package/lib/alchemy.d.ts +67 -0
- package/lib/alchemy.js +48 -0
- package/lib/apply.d.ts +3 -20
- package/lib/apply.js +95 -82
- package/lib/aws/account-id.d.ts +0 -1
- package/lib/aws/account-id.js +0 -1
- package/lib/aws/bucket.d.ts +4 -7
- package/lib/aws/bucket.js +8 -12
- package/lib/aws/function.d.ts +4 -7
- package/lib/aws/function.js +9 -30
- package/lib/aws/index.d.ts +1 -1
- package/lib/aws/index.js +1 -1
- package/lib/aws/oidc/github-oidc-provider.d.ts +2 -6
- package/lib/aws/oidc/github-oidc-provider.js +10 -15
- package/lib/aws/oidc/index.d.ts +0 -1
- package/lib/aws/oidc/index.js +0 -1
- package/lib/aws/oidc/oidc-provider.d.ts +4 -6
- package/lib/aws/oidc/oidc-provider.js +9 -11
- package/lib/aws/policy-attachment.d.ts +9 -0
- package/lib/aws/policy-attachment.js +20 -0
- package/lib/aws/policy.d.ts +4 -16
- package/lib/aws/policy.js +9 -40
- package/lib/aws/queue.d.ts +4 -34
- package/lib/aws/queue.js +10 -20
- package/lib/aws/role.d.ts +4 -7
- package/lib/aws/role.js +17 -26
- package/lib/aws/ses.d.ts +4 -10
- package/lib/aws/ses.js +118 -131
- package/lib/aws/table.d.ts +4 -7
- package/lib/aws/table.js +8 -11
- package/lib/cloudflare/api.d.ts +0 -1
- package/lib/cloudflare/api.js +0 -1
- package/lib/cloudflare/asset-manifest.d.ts +0 -1
- package/lib/cloudflare/asset-manifest.js +0 -1
- package/lib/cloudflare/auth.d.ts +0 -1
- package/lib/cloudflare/auth.js +0 -1
- package/lib/cloudflare/bindings.d.ts +1 -1
- package/lib/cloudflare/bindings.js +3 -2
- package/lib/cloudflare/bound.d.ts +0 -1
- package/lib/cloudflare/bound.js +0 -1
- package/lib/cloudflare/bucket.d.ts +7 -15
- package/lib/cloudflare/bucket.js +12 -19
- package/lib/cloudflare/durable-object-namespace.d.ts +0 -3
- package/lib/cloudflare/durable-object-namespace.js +0 -4
- package/lib/cloudflare/generate-asset-manifest.d.ts +0 -1
- package/lib/cloudflare/generate-asset-manifest.js +1 -2
- package/lib/cloudflare/index.d.ts +2 -1
- package/lib/cloudflare/index.js +2 -1
- package/lib/cloudflare/kv-namespace.d.ts +6 -9
- package/lib/cloudflare/kv-namespace.js +16 -20
- package/lib/cloudflare/state.d.ts +0 -1
- package/lib/cloudflare/state.js +0 -1
- package/lib/cloudflare/static-site-router.d.ts +0 -1
- package/lib/cloudflare/static-site-router.js +0 -4
- package/lib/cloudflare/static-site.d.ts +5 -11
- package/lib/cloudflare/static-site.js +25 -37
- package/lib/cloudflare/types.d.ts +0 -1
- package/lib/cloudflare/types.js +0 -1
- package/lib/cloudflare/upload-asset-manifest.d.ts +0 -1
- package/lib/cloudflare/upload-asset-manifest.js +0 -1
- package/lib/cloudflare/worker-metadata.d.ts +0 -1
- package/lib/cloudflare/worker-metadata.js +0 -1
- package/lib/cloudflare/worker-migration.d.ts +0 -1
- package/lib/cloudflare/worker-migration.js +0 -1
- package/lib/cloudflare/worker.d.ts +8 -14
- package/lib/cloudflare/worker.js +38 -50
- package/lib/cloudflare/wrangler.json.d.ts +243 -0
- package/lib/cloudflare/wrangler.json.js +35 -0
- package/lib/cloudflare/zone-settings.d.ts +301 -0
- package/lib/cloudflare/zone-settings.js +1 -0
- package/lib/cloudflare/zone.d.ts +196 -0
- package/lib/cloudflare/zone.js +175 -0
- package/lib/context.d.ts +58 -0
- package/lib/context.js +36 -0
- package/lib/destroy.d.ts +10 -13
- package/lib/destroy.js +104 -43
- package/lib/{esbuild.d.ts → esbuild/bundle.d.ts} +4 -18
- package/lib/{esbuild.js → esbuild/bundle.js} +10 -24
- package/lib/esbuild/index.d.ts +1 -0
- package/lib/esbuild/index.js +1 -0
- package/lib/fs/file.d.ts +13 -0
- package/lib/fs/file.js +20 -0
- package/lib/fs/folder.d.ts +10 -0
- package/lib/fs/folder.js +16 -0
- package/lib/fs/index.d.ts +2 -0
- package/lib/fs/index.js +2 -0
- package/lib/github/client.d.ts +0 -1
- package/lib/github/client.js +0 -1
- package/lib/github/index.d.ts +0 -1
- package/lib/github/index.js +0 -1
- package/lib/github/secret.d.ts +4 -6
- package/lib/github/secret.js +10 -12
- package/lib/index.d.ts +6 -10
- package/lib/index.js +5 -9
- package/lib/project/index.d.ts +1 -0
- package/lib/project/index.js +1 -0
- package/lib/project/vite.d.ts +39 -0
- package/lib/project/vite.js +68 -0
- package/lib/resource.d.ts +34 -62
- package/lib/resource.js +29 -270
- package/lib/scope.d.ts +37 -14
- package/lib/scope.js +97 -23
- package/lib/secret.d.ts +2 -7
- package/lib/secret.js +7 -20
- package/lib/state.d.ts +14 -10
- package/lib/state.js +20 -14
- package/lib/stripe/index.d.ts +0 -1
- package/lib/stripe/index.js +0 -1
- package/lib/stripe/price.d.ts +4 -5
- package/lib/stripe/price.js +10 -20
- package/lib/stripe/product.d.ts +4 -5
- package/lib/stripe/product.js +10 -20
- package/lib/stripe/webhook.d.ts +4 -6
- package/lib/stripe/webhook.js +12 -25
- package/lib/test/bun.d.ts +19 -0
- package/lib/test/bun.js +55 -0
- package/lib/{utils → util}/content-type.d.ts +0 -1
- package/lib/{utils → util}/content-type.js +0 -1
- package/lib/{encrypt.d.ts → util/encrypt.d.ts} +0 -1
- package/lib/{encrypt.js → util/encrypt.js} +0 -1
- package/lib/{error.d.ts → util/ignore.d.ts} +0 -1
- package/lib/{error.js → util/ignore.js} +0 -1
- package/lib/{utils → util}/retry.d.ts +0 -1
- package/lib/{utils → util}/retry.js +0 -1
- package/lib/util/rm.d.ts +1 -0
- package/lib/util/rm.js +11 -0
- package/lib/util/serde.d.ts +3 -0
- package/lib/{serde.js → util/serde.js} +19 -10
- package/lib/util/slugify.d.ts +1 -0
- package/lib/util/slugify.js +3 -0
- package/package.json +7 -5
- package/src/alchemy.ts +127 -0
- package/src/apply.ts +116 -115
- package/src/aws/bucket.ts +11 -14
- package/src/aws/function.ts +13 -33
- package/src/aws/index.ts +1 -0
- package/src/aws/oidc/github-oidc-provider.ts +14 -19
- package/src/aws/oidc/oidc-provider.ts +19 -12
- package/src/aws/policy-attachment.ts +51 -0
- package/src/aws/policy.ts +15 -60
- package/src/aws/queue.ts +17 -21
- package/src/aws/role.ts +25 -28
- package/src/aws/ses.ts +150 -164
- package/src/aws/table.ts +15 -15
- package/src/cloudflare/bindings.ts +8 -0
- package/src/cloudflare/bucket.ts +39 -47
- package/src/cloudflare/durable-object-namespace.ts +0 -10
- package/src/cloudflare/generate-asset-manifest.ts +1 -1
- package/src/cloudflare/index.ts +2 -0
- package/src/cloudflare/kv-namespace.ts +35 -33
- package/src/cloudflare/static-site-router.ts +0 -3
- package/src/cloudflare/static-site.ts +55 -71
- package/src/cloudflare/worker.ts +106 -112
- package/src/cloudflare/wrangler.json.ts +309 -0
- package/src/cloudflare/zone-settings.ts +368 -0
- package/src/cloudflare/zone.ts +491 -0
- package/src/context.ts +122 -0
- package/src/destroy.ts +124 -73
- package/src/{esbuild.ts → esbuild/bundle.ts} +16 -28
- package/src/esbuild/index.ts +1 -0
- package/src/fs/file.ts +39 -0
- package/src/fs/folder.ts +32 -0
- package/src/fs/index.ts +2 -0
- package/src/github/secret.ts +19 -16
- package/src/index.ts +7 -15
- package/src/project/index.ts +1 -0
- package/src/project/vite.ts +152 -0
- package/src/resource.ts +101 -462
- package/src/scope.ts +125 -36
- package/src/secret.ts +9 -32
- package/src/state.ts +38 -21
- package/src/stripe/price.ts +17 -22
- package/src/stripe/product.ts +17 -22
- package/src/stripe/webhook.ts +21 -27
- package/src/test/bun.ts +105 -0
- package/src/util/rm.ts +11 -0
- package/src/util/serde.ts +53 -0
- package/src/util/slugify.ts +3 -0
- package/lib/$.d.ts +0 -12
- package/lib/$.d.ts.map +0 -1
- package/lib/$.js +0 -42
- package/lib/$.js.map +0 -1
- package/lib/alchemize.d.ts +0 -47
- package/lib/alchemize.d.ts.map +0 -1
- package/lib/alchemize.js +0 -116
- package/lib/alchemize.js.map +0 -1
- package/lib/apply.d.ts.map +0 -1
- package/lib/apply.js.map +0 -1
- package/lib/aws/account-id.d.ts.map +0 -1
- package/lib/aws/account-id.js.map +0 -1
- package/lib/aws/bucket.d.ts.map +0 -1
- package/lib/aws/bucket.js.map +0 -1
- package/lib/aws/function.d.ts.map +0 -1
- package/lib/aws/function.js.map +0 -1
- package/lib/aws/index.d.ts.map +0 -1
- package/lib/aws/index.js.map +0 -1
- package/lib/aws/oidc/github-oidc-provider.d.ts.map +0 -1
- package/lib/aws/oidc/github-oidc-provider.js.map +0 -1
- package/lib/aws/oidc/index.d.ts.map +0 -1
- package/lib/aws/oidc/index.js.map +0 -1
- package/lib/aws/oidc/oidc-provider.d.ts.map +0 -1
- package/lib/aws/oidc/oidc-provider.js.map +0 -1
- package/lib/aws/policy.d.ts.map +0 -1
- package/lib/aws/policy.js.map +0 -1
- package/lib/aws/queue.d.ts.map +0 -1
- package/lib/aws/queue.js.map +0 -1
- package/lib/aws/role.d.ts.map +0 -1
- package/lib/aws/role.js.map +0 -1
- package/lib/aws/ses.d.ts.map +0 -1
- package/lib/aws/ses.js.map +0 -1
- package/lib/aws/table.d.ts.map +0 -1
- package/lib/aws/table.js.map +0 -1
- package/lib/cloudflare/api.d.ts.map +0 -1
- package/lib/cloudflare/api.js.map +0 -1
- package/lib/cloudflare/asset-manifest.d.ts.map +0 -1
- package/lib/cloudflare/asset-manifest.js.map +0 -1
- package/lib/cloudflare/auth.d.ts.map +0 -1
- package/lib/cloudflare/auth.js.map +0 -1
- package/lib/cloudflare/bindings.d.ts.map +0 -1
- package/lib/cloudflare/bindings.js.map +0 -1
- package/lib/cloudflare/bound.d.ts.map +0 -1
- package/lib/cloudflare/bound.js.map +0 -1
- package/lib/cloudflare/bucket.d.ts.map +0 -1
- package/lib/cloudflare/bucket.js.map +0 -1
- package/lib/cloudflare/durable-object-namespace.d.ts.map +0 -1
- package/lib/cloudflare/durable-object-namespace.js.map +0 -1
- package/lib/cloudflare/generate-asset-manifest.d.ts.map +0 -1
- package/lib/cloudflare/generate-asset-manifest.js.map +0 -1
- package/lib/cloudflare/index.d.ts.map +0 -1
- package/lib/cloudflare/index.js.map +0 -1
- package/lib/cloudflare/kv-namespace.d.ts.map +0 -1
- package/lib/cloudflare/kv-namespace.js.map +0 -1
- package/lib/cloudflare/state.d.ts.map +0 -1
- package/lib/cloudflare/state.js.map +0 -1
- package/lib/cloudflare/static-site-router.d.ts.map +0 -1
- package/lib/cloudflare/static-site-router.js.map +0 -1
- package/lib/cloudflare/static-site.d.ts.map +0 -1
- package/lib/cloudflare/static-site.js.map +0 -1
- package/lib/cloudflare/types.d.ts.map +0 -1
- package/lib/cloudflare/types.js.map +0 -1
- package/lib/cloudflare/upload-asset-manifest.d.ts.map +0 -1
- package/lib/cloudflare/upload-asset-manifest.js.map +0 -1
- package/lib/cloudflare/worker-metadata.d.ts.map +0 -1
- package/lib/cloudflare/worker-metadata.js.map +0 -1
- package/lib/cloudflare/worker-migration.d.ts.map +0 -1
- package/lib/cloudflare/worker-migration.js.map +0 -1
- package/lib/cloudflare/worker.d.ts.map +0 -1
- package/lib/cloudflare/worker.js.map +0 -1
- package/lib/destroy.d.ts.map +0 -1
- package/lib/destroy.js.map +0 -1
- package/lib/encrypt.d.ts.map +0 -1
- package/lib/encrypt.js.map +0 -1
- package/lib/error.d.ts.map +0 -1
- package/lib/error.js.map +0 -1
- package/lib/esbuild.d.ts.map +0 -1
- package/lib/esbuild.js.map +0 -1
- package/lib/fs.d.ts +0 -12
- package/lib/fs.d.ts.map +0 -1
- package/lib/fs.js +0 -41
- package/lib/fs.js.map +0 -1
- package/lib/github/client.d.ts.map +0 -1
- package/lib/github/client.js.map +0 -1
- package/lib/github/index.d.ts.map +0 -1
- package/lib/github/index.js.map +0 -1
- package/lib/github/secret.d.ts.map +0 -1
- package/lib/github/secret.js.map +0 -1
- package/lib/global.d.ts +0 -16
- package/lib/global.d.ts.map +0 -1
- package/lib/global.js +0 -42
- package/lib/global.js.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/input.d.ts +0 -7
- package/lib/input.d.ts.map +0 -1
- package/lib/input.js +0 -2
- package/lib/input.js.map +0 -1
- package/lib/main.d.ts +0 -3
- package/lib/main.d.ts.map +0 -1
- package/lib/main.js +0 -32
- package/lib/main.js.map +0 -1
- package/lib/output.d.ts +0 -25
- package/lib/output.d.ts.map +0 -1
- package/lib/output.js +0 -23
- package/lib/output.js.map +0 -1
- package/lib/print.d.ts +0 -7
- package/lib/print.d.ts.map +0 -1
- package/lib/print.js +0 -10
- package/lib/print.js.map +0 -1
- package/lib/resource.d.ts.map +0 -1
- package/lib/resource.js.map +0 -1
- package/lib/scope.d.ts.map +0 -1
- package/lib/scope.js.map +0 -1
- package/lib/secret.d.ts.map +0 -1
- package/lib/secret.js.map +0 -1
- package/lib/serde.d.ts +0 -3
- package/lib/serde.d.ts.map +0 -1
- package/lib/serde.js.map +0 -1
- package/lib/slug.d.ts +0 -2
- package/lib/slug.d.ts.map +0 -1
- package/lib/slug.js +0 -4
- package/lib/slug.js.map +0 -1
- package/lib/state.d.ts.map +0 -1
- package/lib/state.js.map +0 -1
- package/lib/stripe/index.d.ts.map +0 -1
- package/lib/stripe/index.js.map +0 -1
- package/lib/stripe/price.d.ts.map +0 -1
- package/lib/stripe/price.js.map +0 -1
- package/lib/stripe/product.d.ts.map +0 -1
- package/lib/stripe/product.js.map +0 -1
- package/lib/stripe/webhook.d.ts.map +0 -1
- package/lib/stripe/webhook.js.map +0 -1
- package/lib/utils/content-type.d.ts.map +0 -1
- package/lib/utils/content-type.js.map +0 -1
- package/lib/utils/retry.d.ts.map +0 -1
- package/lib/utils/retry.js.map +0 -1
- package/src/$.ts +0 -69
- package/src/alchemize.ts +0 -195
- package/src/fs.ts +0 -47
- package/src/global.ts +0 -63
- package/src/input.ts +0 -19
- package/src/main.ts +0 -34
- package/src/output.ts +0 -75
- package/src/print.ts +0 -18
- package/src/serde.ts +0 -46
- package/src/slug.ts +0 -3
- /package/src/{utils → util}/content-type.ts +0 -0
- /package/src/{encrypt.ts → util/encrypt.ts} +0 -0
- /package/src/{error.ts → util/ignore.ts} +0 -0
- /package/src/{utils → util}/retry.ts +0 -0
package/lib/stripe/price.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import Stripe from "stripe";
|
|
2
|
+
import type { Context } from "../context";
|
|
3
|
+
import { Resource } from "../resource";
|
|
2
4
|
/**
|
|
3
5
|
* Properties for price recurring configuration
|
|
4
6
|
*/
|
|
@@ -80,7 +82,7 @@ export interface PriceProps {
|
|
|
80
82
|
/**
|
|
81
83
|
* Output from the Stripe price
|
|
82
84
|
*/
|
|
83
|
-
export interface
|
|
85
|
+
export interface Price extends Resource<"stripe::Price">, PriceProps {
|
|
84
86
|
/**
|
|
85
87
|
* The ID of the price
|
|
86
88
|
*/
|
|
@@ -102,8 +104,5 @@ export interface PriceOutput extends PriceProps {
|
|
|
102
104
|
*/
|
|
103
105
|
lookupKey?: string;
|
|
104
106
|
}
|
|
105
|
-
declare const
|
|
106
|
-
export declare class Price extends Price_base {
|
|
107
|
-
}
|
|
107
|
+
export declare const Price: ((this: Context<Price>, id: string, props: PriceProps) => Promise<Price>) | (((this: any, id: string, props: PriceProps) => never) & (new (_: never) => never));
|
|
108
108
|
export {};
|
|
109
|
-
//# sourceMappingURL=price.d.ts.map
|
package/lib/stripe/price.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Stripe from "stripe";
|
|
2
2
|
import { Resource } from "../resource";
|
|
3
|
-
export
|
|
3
|
+
export const Price = Resource("stripe::Price", async function (id, props) {
|
|
4
4
|
// Get Stripe API key from context or environment
|
|
5
5
|
const apiKey = process.env.STRIPE_API_KEY;
|
|
6
6
|
if (!apiKey) {
|
|
@@ -8,32 +8,25 @@ export class Price extends Resource("stripe::Price", async (ctx, props) => {
|
|
|
8
8
|
}
|
|
9
9
|
// Initialize Stripe client
|
|
10
10
|
const stripe = new Stripe(apiKey);
|
|
11
|
-
if (
|
|
11
|
+
if (this.phase === "delete") {
|
|
12
12
|
try {
|
|
13
|
-
if (
|
|
13
|
+
if (this.phase === "delete" && this.output?.id) {
|
|
14
14
|
// Prices can't be deleted, only deactivated
|
|
15
|
-
await stripe.prices.update(
|
|
15
|
+
await stripe.prices.update(this.output.id, { active: false });
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
catch (error) {
|
|
19
19
|
// Ignore if the price doesn't exist
|
|
20
20
|
console.error("Error deactivating price:", error);
|
|
21
21
|
}
|
|
22
|
-
|
|
23
|
-
return {
|
|
24
|
-
...props,
|
|
25
|
-
id: "",
|
|
26
|
-
createdAt: 0,
|
|
27
|
-
livemode: false,
|
|
28
|
-
type: (props.recurring ? "recurring" : "one_time"),
|
|
29
|
-
};
|
|
22
|
+
return this.destroy();
|
|
30
23
|
}
|
|
31
24
|
else {
|
|
32
25
|
try {
|
|
33
26
|
let price;
|
|
34
|
-
if (
|
|
27
|
+
if (this.phase === "update" && this.output?.id) {
|
|
35
28
|
// Update existing price (limited properties can be updated)
|
|
36
|
-
price = await stripe.prices.update(
|
|
29
|
+
price = await stripe.prices.update(this.output.id, {
|
|
37
30
|
active: props.active,
|
|
38
31
|
metadata: props.metadata,
|
|
39
32
|
nickname: props.nickname,
|
|
@@ -81,7 +74,7 @@ export class Price extends Resource("stripe::Price", async (ctx, props) => {
|
|
|
81
74
|
}
|
|
82
75
|
: undefined;
|
|
83
76
|
// Map Stripe API response to our output format
|
|
84
|
-
|
|
77
|
+
return this({
|
|
85
78
|
id: price.id,
|
|
86
79
|
product: typeof price.product === "string"
|
|
87
80
|
? price.product
|
|
@@ -99,14 +92,11 @@ export class Price extends Resource("stripe::Price", async (ctx, props) => {
|
|
|
99
92
|
livemode: price.livemode,
|
|
100
93
|
type: price.type,
|
|
101
94
|
lookupKey: price.lookup_key || undefined,
|
|
102
|
-
};
|
|
103
|
-
return output;
|
|
95
|
+
});
|
|
104
96
|
}
|
|
105
97
|
catch (error) {
|
|
106
98
|
console.error("Error creating/updating price:", error);
|
|
107
99
|
throw error;
|
|
108
100
|
}
|
|
109
101
|
}
|
|
110
|
-
})
|
|
111
|
-
}
|
|
112
|
-
//# sourceMappingURL=price.js.map
|
|
102
|
+
});
|
package/lib/stripe/product.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import Stripe from "stripe";
|
|
2
|
+
import type { Context } from "../context";
|
|
3
|
+
import { Resource } from "../resource";
|
|
2
4
|
type ProductType = Stripe.Product.Type;
|
|
3
5
|
/**
|
|
4
6
|
* Properties for creating a Stripe product
|
|
@@ -52,7 +54,7 @@ export interface ProductProps {
|
|
|
52
54
|
/**
|
|
53
55
|
* Output from the Stripe product
|
|
54
56
|
*/
|
|
55
|
-
export interface
|
|
57
|
+
export interface Product extends Resource<"stripe::Product">, ProductProps {
|
|
56
58
|
/**
|
|
57
59
|
* The ID of the product
|
|
58
60
|
*/
|
|
@@ -79,8 +81,5 @@ export interface ProductOutput extends ProductProps {
|
|
|
79
81
|
width: number;
|
|
80
82
|
};
|
|
81
83
|
}
|
|
82
|
-
declare const
|
|
83
|
-
export declare class Product extends Product_base {
|
|
84
|
-
}
|
|
84
|
+
export declare const Product: ((this: Context<Product>, id: string, props: ProductProps) => Promise<Product>) | (((this: any, id: string, props: ProductProps) => never) & (new (_: never) => never));
|
|
85
85
|
export {};
|
|
86
|
-
//# sourceMappingURL=product.d.ts.map
|
package/lib/stripe/product.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Stripe from "stripe";
|
|
2
2
|
import { Resource } from "../resource";
|
|
3
|
-
export
|
|
3
|
+
export const Product = Resource("stripe::Product", async function (id, props) {
|
|
4
4
|
// Get Stripe API key from context or environment
|
|
5
5
|
const apiKey = process.env.STRIPE_API_KEY;
|
|
6
6
|
if (!apiKey) {
|
|
@@ -8,10 +8,10 @@ export class Product extends Resource("stripe::Product", async (ctx, props) => {
|
|
|
8
8
|
}
|
|
9
9
|
// Initialize Stripe client
|
|
10
10
|
const stripe = new Stripe(apiKey);
|
|
11
|
-
if (
|
|
11
|
+
if (this.phase === "delete") {
|
|
12
12
|
try {
|
|
13
|
-
if (
|
|
14
|
-
await stripe.products.update(
|
|
13
|
+
if (this.phase === "delete" && this.output?.id) {
|
|
14
|
+
await stripe.products.update(this.output.id, { active: false });
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
catch (error) {
|
|
@@ -19,20 +19,14 @@ export class Product extends Resource("stripe::Product", async (ctx, props) => {
|
|
|
19
19
|
console.error("Error deactivating product:", error);
|
|
20
20
|
}
|
|
21
21
|
// Return a minimal output for deleted state
|
|
22
|
-
return
|
|
23
|
-
...props,
|
|
24
|
-
id: "",
|
|
25
|
-
createdAt: 0,
|
|
26
|
-
updatedAt: 0,
|
|
27
|
-
livemode: false,
|
|
28
|
-
};
|
|
22
|
+
return this.destroy();
|
|
29
23
|
}
|
|
30
24
|
else {
|
|
31
25
|
try {
|
|
32
26
|
let product;
|
|
33
|
-
if (
|
|
27
|
+
if (this.phase === "update" && this.output?.id) {
|
|
34
28
|
// Update existing product
|
|
35
|
-
product = await stripe.products.update(
|
|
29
|
+
product = await stripe.products.update(this.output.id, {
|
|
36
30
|
name: props.name,
|
|
37
31
|
description: props.description,
|
|
38
32
|
active: props.active,
|
|
@@ -59,8 +53,7 @@ export class Product extends Resource("stripe::Product", async (ctx, props) => {
|
|
|
59
53
|
tax_code: props.taxCode,
|
|
60
54
|
});
|
|
61
55
|
}
|
|
62
|
-
|
|
63
|
-
const output = {
|
|
56
|
+
return this({
|
|
64
57
|
id: product.id,
|
|
65
58
|
name: product.name,
|
|
66
59
|
description: product.description || undefined,
|
|
@@ -77,14 +70,11 @@ export class Product extends Resource("stripe::Product", async (ctx, props) => {
|
|
|
77
70
|
livemode: product.livemode,
|
|
78
71
|
updatedAt: product.updated,
|
|
79
72
|
packageDimensions: product.package_dimensions || undefined,
|
|
80
|
-
};
|
|
81
|
-
return output;
|
|
73
|
+
});
|
|
82
74
|
}
|
|
83
75
|
catch (error) {
|
|
84
76
|
console.error("Error creating/updating product:", error);
|
|
85
77
|
throw error;
|
|
86
78
|
}
|
|
87
79
|
}
|
|
88
|
-
})
|
|
89
|
-
}
|
|
90
|
-
//# sourceMappingURL=product.js.map
|
|
80
|
+
});
|
package/lib/stripe/webhook.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import Stripe from "stripe";
|
|
2
|
+
import type { Context } from "../context";
|
|
3
|
+
import { Resource } from "../resource";
|
|
2
4
|
export type EnabledEvent = Stripe.WebhookEndpointUpdateParams.EnabledEvent;
|
|
3
5
|
/**
|
|
4
6
|
* Properties for creating a Stripe webhook endpoint
|
|
@@ -36,7 +38,7 @@ export interface WebhookEndpointProps {
|
|
|
36
38
|
/**
|
|
37
39
|
* Output from the Stripe webhook endpoint
|
|
38
40
|
*/
|
|
39
|
-
export interface
|
|
41
|
+
export interface WebhookEndpoint extends Resource<"stripe::WebhookEndpoint">, WebhookEndpointProps {
|
|
40
42
|
/**
|
|
41
43
|
* The ID of the webhook
|
|
42
44
|
*/
|
|
@@ -66,8 +68,4 @@ export interface WebhookEndpointOutput extends WebhookEndpointProps {
|
|
|
66
68
|
*/
|
|
67
69
|
status: string;
|
|
68
70
|
}
|
|
69
|
-
declare const
|
|
70
|
-
export declare class WebhookEndpoint extends WebhookEndpoint_base {
|
|
71
|
-
}
|
|
72
|
-
export {};
|
|
73
|
-
//# sourceMappingURL=webhook.d.ts.map
|
|
71
|
+
export declare const WebhookEndpoint: ((this: Context<WebhookEndpoint>, id: string, props: WebhookEndpointProps) => Promise<WebhookEndpoint>) | (((this: any, id: string, props: WebhookEndpointProps) => never) & (new (_: never) => never));
|
package/lib/stripe/webhook.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Stripe from "stripe";
|
|
2
2
|
import { Resource } from "../resource";
|
|
3
|
-
export
|
|
3
|
+
export const WebhookEndpoint = Resource("stripe::WebhookEndpoint", async function (id, props) {
|
|
4
4
|
// Get Stripe API key from context or environment
|
|
5
5
|
const apiKey = process.env.STRIPE_API_KEY;
|
|
6
6
|
if (!apiKey) {
|
|
@@ -8,34 +8,25 @@ export class WebhookEndpoint extends Resource("stripe::WebhookEndpoint", async (
|
|
|
8
8
|
}
|
|
9
9
|
// Initialize Stripe client
|
|
10
10
|
const stripe = new Stripe(apiKey);
|
|
11
|
-
if (
|
|
11
|
+
if (this.phase === "delete") {
|
|
12
12
|
try {
|
|
13
13
|
// Get the webhook ID from the stored output
|
|
14
|
-
if (
|
|
15
|
-
await stripe.webhookEndpoints.del(
|
|
14
|
+
if (this.phase === "delete" && this.output?.id) {
|
|
15
|
+
await stripe.webhookEndpoints.del(this.output.id);
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
catch (error) {
|
|
19
19
|
// Ignore if the webhook doesn't exist
|
|
20
20
|
console.error("Error deleting webhook:", error);
|
|
21
21
|
}
|
|
22
|
-
|
|
23
|
-
return {
|
|
24
|
-
...props,
|
|
25
|
-
id: "",
|
|
26
|
-
secret: "",
|
|
27
|
-
createdAt: 0,
|
|
28
|
-
updatedAt: 0,
|
|
29
|
-
livemode: false,
|
|
30
|
-
status: "deleted",
|
|
31
|
-
};
|
|
22
|
+
return this.destroy();
|
|
32
23
|
}
|
|
33
24
|
else {
|
|
34
25
|
try {
|
|
35
26
|
let webhook;
|
|
36
|
-
if (
|
|
27
|
+
if (this.phase === "update" && this.output?.id) {
|
|
37
28
|
// Update existing webhook
|
|
38
|
-
webhook = await stripe.webhookEndpoints.update(
|
|
29
|
+
webhook = await stripe.webhookEndpoints.update(this.output.id, {
|
|
39
30
|
url: props.url,
|
|
40
31
|
enabled_events: props.enabledEvents,
|
|
41
32
|
description: props.description,
|
|
@@ -62,11 +53,10 @@ export class WebhookEndpoint extends Resource("stripe::WebhookEndpoint", async (
|
|
|
62
53
|
if (webhook.secret) {
|
|
63
54
|
secret = webhook.secret;
|
|
64
55
|
}
|
|
65
|
-
else if (
|
|
66
|
-
secret =
|
|
56
|
+
else if (this.phase === "update" && this.output?.secret) {
|
|
57
|
+
secret = this.output.secret;
|
|
67
58
|
}
|
|
68
|
-
|
|
69
|
-
const output = {
|
|
59
|
+
return this({
|
|
70
60
|
id: webhook.id,
|
|
71
61
|
url: webhook.url,
|
|
72
62
|
enabledEvents: webhook.enabled_events,
|
|
@@ -81,14 +71,11 @@ export class WebhookEndpoint extends Resource("stripe::WebhookEndpoint", async (
|
|
|
81
71
|
livemode: webhook.livemode,
|
|
82
72
|
updatedAt: webhook.created, // Using created timestamp as updated
|
|
83
73
|
status: webhook.status,
|
|
84
|
-
};
|
|
85
|
-
return output;
|
|
74
|
+
});
|
|
86
75
|
}
|
|
87
76
|
catch (error) {
|
|
88
77
|
console.error("Error creating/updating webhook:", error);
|
|
89
78
|
throw error;
|
|
90
79
|
}
|
|
91
80
|
}
|
|
92
|
-
})
|
|
93
|
-
}
|
|
94
|
-
//# sourceMappingURL=webhook.js.map
|
|
81
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Scope } from "../scope";
|
|
2
|
+
declare module "../alchemy" {
|
|
3
|
+
interface Alchemy {
|
|
4
|
+
test: typeof test;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
export interface TestOptions {
|
|
8
|
+
destroy?: boolean;
|
|
9
|
+
quiet?: boolean;
|
|
10
|
+
password?: string;
|
|
11
|
+
}
|
|
12
|
+
type test = {
|
|
13
|
+
(name: string, fn: (scope: Scope) => Promise<any>, timeout?: number): void;
|
|
14
|
+
(name: string, options: TestOptions, fn: (scope: Scope) => Promise<any>, timeout?: number): void;
|
|
15
|
+
skipIf(condition: boolean): test;
|
|
16
|
+
scope: Scope;
|
|
17
|
+
};
|
|
18
|
+
export declare function test(meta: ImportMeta, defaultOptions?: TestOptions): test;
|
|
19
|
+
export {};
|
package/lib/test/bun.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/// <reference types="bun" />
|
|
2
|
+
import { afterAll, it } from "bun:test";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { alchemy } from "../alchemy";
|
|
5
|
+
import { destroy } from "../destroy";
|
|
6
|
+
alchemy.test = test;
|
|
7
|
+
const globalTestScope = alchemy.scope("test");
|
|
8
|
+
export function test(meta, defaultOptions) {
|
|
9
|
+
test.skipIf = (condition) => {
|
|
10
|
+
if (condition) {
|
|
11
|
+
// TODO: proxy through to bun:test.skipIf
|
|
12
|
+
return (...args) => { };
|
|
13
|
+
}
|
|
14
|
+
return test;
|
|
15
|
+
};
|
|
16
|
+
const localTestScope = alchemy.scope(path.basename(meta.filename), {
|
|
17
|
+
parent: globalTestScope,
|
|
18
|
+
});
|
|
19
|
+
test.scope = localTestScope;
|
|
20
|
+
afterAll(() => alchemy.destroy(test.scope));
|
|
21
|
+
return test;
|
|
22
|
+
function test(...args) {
|
|
23
|
+
const testName = args[0];
|
|
24
|
+
const _options = typeof args[1] === "object" ? args[1] : undefined;
|
|
25
|
+
const spread = (obj) => obj && typeof obj === "object"
|
|
26
|
+
? Object.fromEntries(Object.entries(obj).flatMap(([k, v]) => v !== undefined ? [[k, v]] : []))
|
|
27
|
+
: {};
|
|
28
|
+
const options = {
|
|
29
|
+
destroy: false,
|
|
30
|
+
quiet: false,
|
|
31
|
+
password: "test-password",
|
|
32
|
+
...spread(defaultOptions),
|
|
33
|
+
...spread(_options),
|
|
34
|
+
};
|
|
35
|
+
const fn = typeof args[1] === "function" ? args[1] : args[2];
|
|
36
|
+
return alchemy.run(testName, {
|
|
37
|
+
...options,
|
|
38
|
+
parent: localTestScope,
|
|
39
|
+
}, async (scope) => {
|
|
40
|
+
return it(testName, async () => {
|
|
41
|
+
// bun will call from a different scope, so we need to enter the test's scope manually
|
|
42
|
+
scope.enter();
|
|
43
|
+
try {
|
|
44
|
+
await fn(scope);
|
|
45
|
+
}
|
|
46
|
+
finally {
|
|
47
|
+
if (options.destroy !== false) {
|
|
48
|
+
// TODO: auto-destroy resources
|
|
49
|
+
await destroy(scope);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -10,4 +10,3 @@
|
|
|
10
10
|
* @throws The last error encountered if all retries fail
|
|
11
11
|
*/
|
|
12
12
|
export declare function withExponentialBackoff<T>(operation: () => Promise<T>, isRetryable: (error: any) => boolean, maxAttempts?: number, initialDelayMs?: number): Promise<T>;
|
|
13
|
-
//# sourceMappingURL=retry.d.ts.map
|
package/lib/util/rm.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function rm(path: string): Promise<void>;
|
package/lib/util/rm.js
ADDED
|
@@ -1,37 +1,46 @@
|
|
|
1
|
+
import { Scope } from "../scope";
|
|
2
|
+
import { Secret } from "../secret";
|
|
1
3
|
import { decryptWithKey, encryptWithKey } from "./encrypt";
|
|
2
|
-
|
|
3
|
-
export async function serialize(value) {
|
|
4
|
+
export async function serialize(scope, value) {
|
|
4
5
|
if (Array.isArray(value)) {
|
|
5
|
-
return Promise.all(value.map(serialize));
|
|
6
|
+
return Promise.all(value.map((value) => serialize(scope, value)));
|
|
6
7
|
}
|
|
7
8
|
else if (value instanceof Secret) {
|
|
9
|
+
if (!scope.password) {
|
|
10
|
+
throw new Error("Cannot serialize secret without password");
|
|
11
|
+
}
|
|
8
12
|
return {
|
|
9
|
-
"@secret": await encryptWithKey(value.unencrypted,
|
|
13
|
+
"@secret": await encryptWithKey(value.unencrypted, scope.password),
|
|
10
14
|
};
|
|
11
15
|
}
|
|
16
|
+
else if (value instanceof Scope) {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
12
19
|
else if (value && typeof value === "object") {
|
|
13
20
|
return Object.fromEntries(await Promise.all(Object.entries(value).map(async ([key, value]) => [
|
|
14
21
|
key,
|
|
15
|
-
await serialize(value),
|
|
22
|
+
await serialize(scope, value),
|
|
16
23
|
])));
|
|
17
24
|
}
|
|
18
25
|
return value;
|
|
19
26
|
}
|
|
20
|
-
export async function deserialize(value) {
|
|
27
|
+
export async function deserialize(scope, value) {
|
|
21
28
|
if (Array.isArray(value)) {
|
|
22
|
-
return await Promise.all(value.map(async (item) => await deserialize(item)));
|
|
29
|
+
return await Promise.all(value.map(async (item) => await deserialize(scope, item)));
|
|
23
30
|
}
|
|
24
31
|
else if (value && typeof value === "object") {
|
|
25
32
|
if (typeof value["@secret"] === "string") {
|
|
26
|
-
|
|
33
|
+
if (!scope.password) {
|
|
34
|
+
throw new Error("Cannot deserialize secret without password");
|
|
35
|
+
}
|
|
36
|
+
return new Secret(await decryptWithKey(value["@secret"], scope.password));
|
|
27
37
|
}
|
|
28
38
|
else {
|
|
29
39
|
return Object.fromEntries(await Promise.all(Object.entries(value).map(async ([key, value]) => [
|
|
30
40
|
key,
|
|
31
|
-
await deserialize(value),
|
|
41
|
+
await deserialize(scope, value),
|
|
32
42
|
])));
|
|
33
43
|
}
|
|
34
44
|
}
|
|
35
45
|
return value;
|
|
36
46
|
}
|
|
37
|
-
//# sourceMappingURL=serde.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function slugify(str: string, delimiter?: string): string;
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "alchemy",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"module": "./lib/index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"publish:npm": "rm -rf ./*.tsbuildinfo && rm -rf ./lib && tsc -b && npm publish"
|
|
7
|
+
"publish:npm": "cp ../README.md . && rm -rf ./*.tsbuildinfo && rm -rf ./lib && tsc -b && npm publish && rm README.md"
|
|
8
8
|
},
|
|
9
9
|
"files": ["lib", "src"],
|
|
10
10
|
"exports": {
|
|
@@ -12,10 +12,12 @@
|
|
|
12
12
|
"./aws": "./lib/aws/index.js",
|
|
13
13
|
"./aws/oidc": "./lib/aws/oidc/index.js",
|
|
14
14
|
"./cloudflare": "./lib/cloudflare/index.js",
|
|
15
|
-
"./esbuild": "./lib/esbuild.js",
|
|
16
|
-
"./fs": "./lib/fs.js",
|
|
15
|
+
"./esbuild": "./lib/esbuild/index.js",
|
|
16
|
+
"./fs": "./lib/fs/index.js",
|
|
17
17
|
"./github": "./lib/github/index.js",
|
|
18
|
-
"./
|
|
18
|
+
"./project": "./lib/project/index.js",
|
|
19
|
+
"./stripe": "./lib/stripe/index.js",
|
|
20
|
+
"./test/bun": "./lib/test/bun.js"
|
|
19
21
|
},
|
|
20
22
|
"peerDependencies": {
|
|
21
23
|
"@ai-sdk/openai": "^1.1.9",
|