alchemy 0.1.8 → 0.1.10

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.
Files changed (242) hide show
  1. package/lib/$.d.ts +7 -0
  2. package/lib/$.d.ts.map +1 -0
  3. package/lib/$.js +31 -0
  4. package/lib/$.js.map +1 -0
  5. package/lib/agent/ai.d.ts +40 -0
  6. package/lib/agent/ai.d.ts.map +1 -0
  7. package/lib/agent/ai.js +132 -0
  8. package/lib/agent/ai.js.map +1 -0
  9. package/lib/agent/anthropic.d.ts +9 -0
  10. package/lib/agent/anthropic.d.ts.map +1 -0
  11. package/lib/agent/anthropic.js +25 -0
  12. package/lib/agent/anthropic.js.map +1 -0
  13. package/lib/agent/dependencies.d.ts +4 -0
  14. package/lib/agent/dependencies.d.ts.map +1 -0
  15. package/lib/agent/dependencies.js +48 -0
  16. package/lib/agent/dependencies.js.map +1 -0
  17. package/lib/agent/file-context.d.ts +13 -0
  18. package/lib/agent/file-context.d.ts.map +1 -0
  19. package/lib/agent/file-context.js +6 -0
  20. package/lib/agent/file-context.js.map +1 -0
  21. package/lib/agent/index.d.ts +10 -0
  22. package/lib/agent/index.d.ts.map +1 -0
  23. package/lib/agent/index.js +10 -0
  24. package/lib/agent/index.js.map +1 -0
  25. package/lib/agent/model.d.ts +8 -0
  26. package/lib/agent/model.d.ts.map +1 -0
  27. package/lib/agent/model.js +29 -0
  28. package/lib/agent/model.js.map +1 -0
  29. package/lib/agent/module.d.ts +81 -0
  30. package/lib/agent/module.d.ts.map +1 -0
  31. package/lib/agent/module.js +309 -0
  32. package/lib/agent/module.js.map +1 -0
  33. package/lib/agent/openai.d.ts +6 -0
  34. package/lib/agent/openai.d.ts.map +1 -0
  35. package/lib/agent/openai.js +41 -0
  36. package/lib/agent/openai.js.map +1 -0
  37. package/lib/agent/program.d.ts +12 -0
  38. package/lib/agent/program.d.ts.map +1 -0
  39. package/lib/agent/program.js +21 -0
  40. package/lib/agent/program.js.map +1 -0
  41. package/lib/agent/prompts.d.ts +4 -0
  42. package/lib/agent/prompts.d.ts.map +1 -0
  43. package/lib/agent/prompts.js +11 -0
  44. package/lib/agent/prompts.js.map +1 -0
  45. package/lib/agent/scrape.d.ts +71 -0
  46. package/lib/agent/scrape.d.ts.map +1 -0
  47. package/lib/agent/scrape.js +45 -0
  48. package/lib/agent/scrape.js.map +1 -0
  49. package/lib/alchemize.d.ts +43 -0
  50. package/lib/alchemize.d.ts.map +1 -0
  51. package/lib/alchemize.js +105 -0
  52. package/lib/alchemize.js.map +1 -0
  53. package/lib/apply.d.ts +23 -0
  54. package/lib/apply.d.ts.map +1 -0
  55. package/lib/apply.js +84 -0
  56. package/lib/apply.js.map +1 -0
  57. package/lib/aws/auto/docs.d.ts +11 -0
  58. package/lib/aws/auto/docs.d.ts.map +1 -0
  59. package/lib/aws/auto/docs.js +56 -0
  60. package/lib/aws/auto/docs.js.map +1 -0
  61. package/lib/aws/auto/index.d.ts +5 -0
  62. package/lib/aws/auto/index.d.ts.map +1 -0
  63. package/lib/aws/auto/index.js +5 -0
  64. package/lib/aws/auto/index.js.map +1 -0
  65. package/lib/aws/auto/resource.d.ts +24 -0
  66. package/lib/aws/auto/resource.d.ts.map +1 -0
  67. package/lib/aws/auto/resource.js +194 -0
  68. package/lib/aws/auto/resource.js.map +1 -0
  69. package/lib/aws/auto/service.d.ts +10 -0
  70. package/lib/aws/auto/service.d.ts.map +1 -0
  71. package/lib/aws/auto/service.js +34 -0
  72. package/lib/aws/auto/service.js.map +1 -0
  73. package/lib/aws/auto/spec.d.ts +83 -0
  74. package/lib/aws/auto/spec.d.ts.map +1 -0
  75. package/lib/aws/auto/spec.js +58 -0
  76. package/lib/aws/auto/spec.js.map +1 -0
  77. package/lib/aws/bucket.d.ts +21 -0
  78. package/lib/aws/bucket.d.ts.map +1 -0
  79. package/lib/aws/bucket.js +114 -0
  80. package/lib/aws/bucket.js.map +1 -0
  81. package/lib/aws/function.d.ts +53 -0
  82. package/lib/aws/function.d.ts.map +1 -0
  83. package/lib/aws/function.js +195 -0
  84. package/lib/aws/function.js.map +1 -0
  85. package/lib/aws/index.d.ts +7 -0
  86. package/lib/aws/index.d.ts.map +1 -0
  87. package/lib/aws/index.js +7 -0
  88. package/lib/aws/index.js.map +1 -0
  89. package/lib/aws/policy.d.ts +46 -0
  90. package/lib/aws/policy.d.ts.map +1 -0
  91. package/lib/aws/policy.js +139 -0
  92. package/lib/aws/policy.js.map +1 -0
  93. package/lib/aws/queue.d.ts +38 -0
  94. package/lib/aws/queue.d.ts.map +1 -0
  95. package/lib/aws/queue.js +162 -0
  96. package/lib/aws/queue.js.map +1 -0
  97. package/lib/aws/role.d.ts +27 -0
  98. package/lib/aws/role.d.ts.map +1 -0
  99. package/lib/aws/role.js +149 -0
  100. package/lib/aws/role.js.map +1 -0
  101. package/lib/aws/table.d.ts +26 -0
  102. package/lib/aws/table.d.ts.map +1 -0
  103. package/lib/aws/table.js +120 -0
  104. package/lib/aws/table.js.map +1 -0
  105. package/lib/destroy.d.ts +19 -0
  106. package/lib/destroy.d.ts.map +1 -0
  107. package/lib/destroy.js +47 -0
  108. package/lib/destroy.js.map +1 -0
  109. package/lib/error.d.ts +2 -0
  110. package/lib/error.d.ts.map +1 -0
  111. package/lib/error.js +13 -0
  112. package/lib/error.js.map +1 -0
  113. package/lib/esbuild.d.ts +70 -0
  114. package/lib/esbuild.d.ts.map +1 -0
  115. package/lib/esbuild.js +58 -0
  116. package/lib/esbuild.js.map +1 -0
  117. package/lib/fs.d.ts +12 -0
  118. package/lib/fs.d.ts.map +1 -0
  119. package/lib/fs.js +41 -0
  120. package/lib/fs.js.map +1 -0
  121. package/lib/global.d.ts +18 -0
  122. package/lib/global.d.ts.map +1 -0
  123. package/lib/global.js +42 -0
  124. package/lib/global.js.map +1 -0
  125. package/lib/index.d.ts +9 -0
  126. package/lib/index.d.ts.map +1 -0
  127. package/lib/index.js +8 -0
  128. package/lib/index.js.map +1 -0
  129. package/lib/input.d.ts +6 -0
  130. package/lib/input.d.ts.map +1 -0
  131. package/lib/input.js +2 -0
  132. package/lib/input.js.map +1 -0
  133. package/lib/main.d.ts +3 -0
  134. package/lib/main.d.ts.map +1 -0
  135. package/lib/main.js +32 -0
  136. package/lib/main.js.map +1 -0
  137. package/lib/markdown/design.d.ts +17 -0
  138. package/lib/markdown/design.d.ts.map +1 -0
  139. package/lib/markdown/design.js +92 -0
  140. package/lib/markdown/design.js.map +1 -0
  141. package/lib/markdown/extract.d.ts +7 -0
  142. package/lib/markdown/extract.d.ts.map +1 -0
  143. package/lib/markdown/extract.js +10 -0
  144. package/lib/markdown/extract.js.map +1 -0
  145. package/lib/markdown/index.d.ts +4 -0
  146. package/lib/markdown/index.d.ts.map +1 -0
  147. package/lib/markdown/index.js +4 -0
  148. package/lib/markdown/index.js.map +1 -0
  149. package/lib/markdown/requirements.d.ts +79 -0
  150. package/lib/markdown/requirements.d.ts.map +1 -0
  151. package/lib/markdown/requirements.js +105 -0
  152. package/lib/markdown/requirements.js.map +1 -0
  153. package/lib/output.d.ts +19 -0
  154. package/lib/output.d.ts.map +1 -0
  155. package/lib/output.js +16 -0
  156. package/lib/output.js.map +1 -0
  157. package/lib/resource.d.ts +66 -0
  158. package/lib/resource.d.ts.map +1 -0
  159. package/lib/resource.js +242 -0
  160. package/lib/resource.js.map +1 -0
  161. package/lib/scope.d.ts +15 -0
  162. package/lib/scope.d.ts.map +1 -0
  163. package/lib/scope.js +38 -0
  164. package/lib/scope.js.map +1 -0
  165. package/lib/slug.d.ts +2 -0
  166. package/lib/slug.d.ts.map +1 -0
  167. package/lib/slug.js +4 -0
  168. package/lib/slug.js.map +1 -0
  169. package/lib/state.d.ts +40 -0
  170. package/lib/state.d.ts.map +1 -0
  171. package/lib/state.js +73 -0
  172. package/lib/state.js.map +1 -0
  173. package/lib/stripe/index.d.ts +4 -0
  174. package/lib/stripe/index.d.ts.map +1 -0
  175. package/lib/stripe/index.js +4 -0
  176. package/lib/stripe/index.js.map +1 -0
  177. package/lib/stripe/price.d.ts +109 -0
  178. package/lib/stripe/price.d.ts.map +1 -0
  179. package/lib/stripe/price.js +112 -0
  180. package/lib/stripe/price.js.map +1 -0
  181. package/lib/stripe/product.d.ts +86 -0
  182. package/lib/stripe/product.d.ts.map +1 -0
  183. package/lib/stripe/product.js +90 -0
  184. package/lib/stripe/product.js.map +1 -0
  185. package/lib/stripe/webhook.d.ts +73 -0
  186. package/lib/stripe/webhook.d.ts.map +1 -0
  187. package/lib/stripe/webhook.js +94 -0
  188. package/lib/stripe/webhook.js.map +1 -0
  189. package/lib/typescript/check-omission.d.ts +2 -0
  190. package/lib/typescript/check-omission.d.ts.map +1 -0
  191. package/lib/typescript/check-omission.js +43 -0
  192. package/lib/typescript/check-omission.js.map +1 -0
  193. package/lib/typescript/debug-type-errors.d.ts +3 -0
  194. package/lib/typescript/debug-type-errors.d.ts.map +1 -0
  195. package/lib/typescript/debug-type-errors.js +35 -0
  196. package/lib/typescript/debug-type-errors.js.map +1 -0
  197. package/lib/typescript/extract.d.ts +7 -0
  198. package/lib/typescript/extract.d.ts.map +1 -0
  199. package/lib/typescript/extract.js +10 -0
  200. package/lib/typescript/extract.js.map +1 -0
  201. package/lib/typescript/index.d.ts +7 -0
  202. package/lib/typescript/index.d.ts.map +1 -0
  203. package/lib/typescript/index.js +7 -0
  204. package/lib/typescript/index.js.map +1 -0
  205. package/lib/typescript/install-dependencies.d.ts +29 -0
  206. package/lib/typescript/install-dependencies.d.ts.map +1 -0
  207. package/lib/typescript/install-dependencies.js +52 -0
  208. package/lib/typescript/install-dependencies.js.map +1 -0
  209. package/lib/typescript/package.d.ts +157 -0
  210. package/lib/typescript/package.d.ts.map +1 -0
  211. package/lib/typescript/package.js +115 -0
  212. package/lib/typescript/package.js.map +1 -0
  213. package/lib/typescript/repair-omissions.d.ts +3 -0
  214. package/lib/typescript/repair-omissions.d.ts.map +1 -0
  215. package/lib/typescript/repair-omissions.js +23 -0
  216. package/lib/typescript/repair-omissions.js.map +1 -0
  217. package/lib/typescript/repair.d.ts +3 -0
  218. package/lib/typescript/repair.d.ts.map +1 -0
  219. package/lib/typescript/repair.js +34 -0
  220. package/lib/typescript/repair.js.map +1 -0
  221. package/lib/typescript/tsconfig.d.ts +469 -0
  222. package/lib/typescript/tsconfig.d.ts.map +1 -0
  223. package/lib/typescript/tsconfig.js +143 -0
  224. package/lib/typescript/tsconfig.js.map +1 -0
  225. package/lib/typescript/typescript.d.ts +107 -0
  226. package/lib/typescript/typescript.d.ts.map +1 -0
  227. package/lib/typescript/typescript.js +180 -0
  228. package/lib/typescript/typescript.js.map +1 -0
  229. package/lib/typescript/validate.d.ts +10 -0
  230. package/lib/typescript/validate.d.ts.map +1 -0
  231. package/lib/typescript/validate.js +49 -0
  232. package/lib/typescript/validate.js.map +1 -0
  233. package/package.json +4 -3
  234. package/test/aws/function.test.ts +0 -144
  235. package/test/aws/queue.test.ts +0 -85
  236. package/test/aws/role.test.ts +0 -153
  237. package/test/aws/table.test.ts +0 -73
  238. package/test/esbuild.test.ts +0 -41
  239. package/test/handler.ts +0 -9
  240. package/test/scope.test.ts +0 -67
  241. package/test/stripe/stripe.test.ts +0 -136
  242. package/tsconfig.json +0 -33
@@ -1,153 +0,0 @@
1
- import {
2
- GetRoleCommand,
3
- IAMClient,
4
- NoSuchEntityException,
5
- } from "@aws-sdk/client-iam";
6
- import { describe, expect, test } from "bun:test";
7
- import { apply } from "../../src/apply";
8
- import type { PolicyDocument } from "../../src/aws/policy";
9
- import { Role, type RoleProps } from "../../src/aws/role";
10
- import { destroy } from "../../src/destroy";
11
-
12
- // Verify role was deleted
13
- const iam = new IAMClient({});
14
-
15
- describe("AWS Resources", () => {
16
- describe("Role", () => {
17
- const assumeRolePolicy: PolicyDocument = {
18
- Version: "2012-10-17",
19
- Statement: [
20
- {
21
- Effect: "Allow",
22
- Principal: {
23
- Service: "lambda.amazonaws.com",
24
- },
25
- Action: "sts:AssumeRole",
26
- },
27
- ],
28
- };
29
-
30
- const inlinePolicy: PolicyDocument = {
31
- Version: "2012-10-17",
32
- Statement: [
33
- {
34
- Effect: "Allow",
35
- Action: [
36
- "logs:CreateLogGroup",
37
- "logs:CreateLogStream",
38
- "logs:PutLogEvents",
39
- ],
40
- Resource: "*",
41
- },
42
- ],
43
- };
44
-
45
- test("create role", async () => {
46
- const role = new Role("alchemy-test-create-role", {
47
- roleName: "alchemy-test-create-role",
48
- assumeRolePolicy,
49
- description: "Test role for IAC",
50
- tags: {
51
- Environment: "test",
52
- },
53
- policies: [
54
- {
55
- policyName: "logs",
56
- policyDocument: inlinePolicy,
57
- },
58
- ],
59
- });
60
-
61
- const output = await apply(role);
62
- expect(output.id).toBe("alchemy-test-create-role");
63
- expect(output.arn).toMatch(
64
- /^arn:aws:iam::\d+:role\/alchemy-test-create-role$/,
65
- );
66
- expect(output.uniqueId).toBeTruthy();
67
- expect(output.roleId).toBeTruthy();
68
- expect(output.createDate).toBeInstanceOf(Date);
69
-
70
- await destroy(role);
71
-
72
- await assertRoleNotExists("alchemy-test-create-role");
73
- });
74
-
75
- test("update role", async () => {
76
- const roleProps: RoleProps = {
77
- roleName: "alchemy-test-update-role",
78
- assumeRolePolicy,
79
- description: "Updated test role for IAC",
80
- maxSessionDuration: 7200,
81
- tags: {
82
- Environment: "test",
83
- Updated: "true",
84
- },
85
- policies: [
86
- {
87
- policyName: "logs",
88
- policyDocument: inlinePolicy,
89
- },
90
- {
91
- policyName: "extra",
92
- policyDocument: {
93
- Version: "2012-10-17",
94
- Statement: [
95
- {
96
- Effect: "Allow",
97
- Action: "s3:ListBucket",
98
- Resource: "*",
99
- },
100
- ],
101
- },
102
- },
103
- ],
104
- };
105
- let role = new Role("alchemy-test-update-role", roleProps);
106
-
107
- let output = await apply(role);
108
- expect(output.id).toBe("alchemy-test-update-role");
109
- expect(output.description).toBe("Updated test role for IAC");
110
- expect(output.maxSessionDuration).toBe(7200);
111
- expect(output.tags).toEqual({
112
- Environment: "test",
113
- Updated: "true",
114
- });
115
-
116
- role = new Role("alchemy-test-update-role", {
117
- ...roleProps,
118
- description: "Updated test role for IAC",
119
- policies: [
120
- {
121
- policyName: "logs",
122
- policyDocument: inlinePolicy,
123
- },
124
- // 1 policy removed
125
- ],
126
- });
127
-
128
- output = await apply(role);
129
-
130
- expect(output.description).toBe("Updated test role for IAC");
131
- expect(output.policies).toEqual([
132
- {
133
- policyName: "logs",
134
- policyDocument: inlinePolicy,
135
- },
136
- ]);
137
-
138
- await destroy(role);
139
-
140
- await assertRoleNotExists("alchemy-test-update-role");
141
- });
142
- });
143
- });
144
-
145
- async function assertRoleNotExists(roleName: string) {
146
- await expect(
147
- iam.send(
148
- new GetRoleCommand({
149
- RoleName: "alchemy-test-create-role",
150
- }),
151
- ),
152
- ).rejects.toThrow(NoSuchEntityException);
153
- }
@@ -1,73 +0,0 @@
1
- import {
2
- DescribeTableCommand,
3
- DynamoDBClient,
4
- ResourceNotFoundException,
5
- } from "@aws-sdk/client-dynamodb";
6
- import { describe, expect, test } from "bun:test";
7
- import { apply } from "../../src/apply";
8
- import { Table } from "../../src/aws/table";
9
- import { destroy } from "../../src/destroy";
10
-
11
- const dynamo = new DynamoDBClient({});
12
-
13
- describe("AWS Resources", () => {
14
- describe("Table", () => {
15
- test("create table", async () => {
16
- const table = new Table("alchemy-test-create-table", {
17
- tableName: "alchemy-test-create-table",
18
- partitionKey: {
19
- name: "id",
20
- type: "S",
21
- },
22
- sortKey: {
23
- name: "timestamp",
24
- type: "N",
25
- },
26
- tags: {
27
- Environment: "test",
28
- },
29
- });
30
-
31
- const output = await apply(table);
32
- expect(output.id).toBe("alchemy-test-create-table");
33
- expect(output.arn).toMatch(
34
- /^arn:aws:dynamodb:[a-z0-9-]+:\d+:table\/alchemy-test-create-table$/,
35
- );
36
- expect(output.tableId).toBeTruthy();
37
- expect(output.partitionKey).toEqual({
38
- name: "id",
39
- type: "S",
40
- });
41
- expect(output.sortKey).toEqual({
42
- name: "timestamp",
43
- type: "N",
44
- });
45
- expect(output.tags).toEqual({
46
- Environment: "test",
47
- });
48
-
49
- // Verify table exists and is active
50
- const describeResponse = await dynamo.send(
51
- new DescribeTableCommand({
52
- TableName: "alchemy-test-create-table",
53
- }),
54
- );
55
- expect(describeResponse.Table?.TableStatus).toBe("ACTIVE");
56
-
57
- await destroy(table);
58
-
59
- // Verify table is fully deleted
60
- await assertTableNotExists("alchemy-test-create-table");
61
- });
62
- });
63
- });
64
-
65
- async function assertTableNotExists(tableName: string) {
66
- await expect(
67
- dynamo.send(
68
- new DescribeTableCommand({
69
- TableName: tableName,
70
- }),
71
- ),
72
- ).rejects.toThrow(ResourceNotFoundException);
73
- }
@@ -1,41 +0,0 @@
1
- import { describe, expect, test } from "bun:test";
2
- import fs from "node:fs";
3
- import path from "node:path";
4
- import { apply } from "../src/apply";
5
- import { destroy } from "../src/destroy";
6
- import { Bundle } from "../src/esbuild";
7
-
8
- const __dirname = path.dirname(new URL(import.meta.url).pathname);
9
-
10
- describe("esbuild", () => {
11
- describe("Bundle", () => {
12
- const outputDir = ".out";
13
- const outputFile = path.join(outputDir, "handler.js");
14
-
15
- test("bundle and cleanup", async () => {
16
- const bundle = new Bundle("test-bundle", {
17
- entryPoint: path.join(__dirname, "handler.ts"),
18
- outdir: outputDir,
19
- format: "esm",
20
- platform: "node",
21
- target: "node18",
22
- });
23
-
24
- // Apply the bundle
25
- const output = await apply(bundle);
26
- expect(output.path).toBe(outputFile);
27
- expect(output.hash).toBeTruthy();
28
-
29
- // Verify the file exists and contains our code
30
- expect(fs.existsSync(outputFile)).toBe(true);
31
- const contents = await fs.promises.readFile(outputFile, "utf-8");
32
- expect(contents).toContain("Hello from bundled handler");
33
-
34
- // Destroy the bundle
35
- await destroy(bundle);
36
-
37
- // Verify the file is deleted
38
- expect(fs.existsSync(outputFile)).toBe(false);
39
- });
40
- });
41
- });
package/test/handler.ts DELETED
@@ -1,9 +0,0 @@
1
- export async function handler(event: any) {
2
- return {
3
- statusCode: 200,
4
- body: JSON.stringify({
5
- message: "Hello from bundled handler!",
6
- event,
7
- }),
8
- };
9
- }
@@ -1,67 +0,0 @@
1
- import { describe, expect, it } from "bun:test";
2
- import { apply } from "../src/apply";
3
- import type { PolicyDocument } from "../src/aws/policy";
4
- import { Role } from "../src/aws/role";
5
- import { destroy } from "../src/destroy";
6
- import { File } from "../src/fs";
7
- import { rootScope } from "../src/global";
8
- import { type Context, Resource } from "../src/resource";
9
- import { Scope, getScope, withScope } from "../src/scope";
10
-
11
- describe("Scope", () => {
12
- it("should maintain scope context and track resources", async () => {
13
- const testScope = new Scope("test");
14
-
15
- await withScope(testScope, async () => {
16
- new File("test-file", "test.txt", "Hello World");
17
-
18
- const currentScope = getScope();
19
- expect(currentScope).toEqual(testScope);
20
- });
21
- expect(testScope.nodes.size).toBe(1);
22
- expect(testScope).toBe(testScope);
23
- expect(testScope).not.toBe(rootScope);
24
- });
25
-
26
- it("should handle nested resources with AWS Role", async () => {
27
- class ServiceResources extends Resource(
28
- "service-resources",
29
- async (
30
- ctx: Context<{ roleArn: string }>,
31
- props: { roleName: string },
32
- ) => {
33
- const assumeRolePolicy: PolicyDocument = {
34
- Version: "2012-10-17",
35
- Statement: [
36
- {
37
- Effect: "Allow",
38
- Principal: {
39
- Service: "lambda.amazonaws.com",
40
- },
41
- Action: "sts:AssumeRole",
42
- },
43
- ],
44
- };
45
-
46
- const role = new Role(`role`, {
47
- roleName: props.roleName,
48
- assumeRolePolicy,
49
- });
50
-
51
- return {
52
- roleArn: role.arn,
53
- };
54
- },
55
- ) {}
56
-
57
- const service = new ServiceResources("test-service", {
58
- roleName: "alchemy-test-scope-role",
59
- });
60
-
61
- // Apply the parent resource which should create the role
62
- const output = await apply(service);
63
-
64
- // Clean up
65
- await destroy(service);
66
- });
67
- });
@@ -1,136 +0,0 @@
1
- import { describe, expect, test } from "bun:test";
2
- import Stripe from "stripe";
3
- import { apply } from "../../src/apply";
4
- import { destroy } from "../../src/destroy";
5
- import { Price } from "../../src/stripe/price";
6
- import { Product } from "../../src/stripe/product";
7
- import { WebhookEndpoint } from "../../src/stripe/webhook";
8
-
9
- const stripeApiKey = process.env.STRIPE_API_KEY;
10
- if (!stripeApiKey) {
11
- throw new Error("STRIPE_API_KEY environment variable is required");
12
- }
13
-
14
- // Initialize a Stripe client for verification
15
- const stripe = new Stripe(stripeApiKey);
16
-
17
- describe("Stripe Resources", () => {
18
- test("create and destroy stripe resources", async () => {
19
- // Create a test product
20
- const product = new Product("alchemy-test-product", {
21
- name: "Alchemy Test Product",
22
- description: "A product created by Alchemy tests",
23
- });
24
-
25
- // Apply the product first to get its ID
26
- const productOutput = await apply(product);
27
- expect(productOutput.id).toBeTruthy();
28
- expect(productOutput.name).toBe("Alchemy Test Product");
29
-
30
- // Verify with Stripe API
31
- const stripeProduct = await stripe.products.retrieve(productOutput.id);
32
- expect(stripeProduct.name).toBe("Alchemy Test Product");
33
-
34
- // Create a price for the product
35
- const price = new Price("alchemy-test-price", {
36
- product: productOutput.id,
37
- currency: "usd",
38
- unitAmount: 1500, // $15.00
39
- recurring: {
40
- interval: "month",
41
- },
42
- });
43
-
44
- // Apply the price
45
- const priceOutput = await apply(price);
46
- expect(priceOutput.id).toBeTruthy();
47
- expect(priceOutput.unitAmount).toBe(1500);
48
- expect(priceOutput.recurring?.interval).toBe("month");
49
-
50
- // Verify with Stripe API
51
- const stripePrice = await stripe.prices.retrieve(priceOutput.id);
52
- expect(stripePrice.unit_amount).toBe(1500);
53
-
54
- // Create a webhook endpoint
55
- const webhook = new WebhookEndpoint("alchemy-test-webhook", {
56
- url: "https://example.com/alchemy-webhook",
57
- enabledEvents: [
58
- "checkout.session.completed",
59
- "customer.subscription.created",
60
- ],
61
- description: "Webhook for Alchemy tests",
62
- });
63
-
64
- // Apply the webhook
65
- const webhookOutput = await apply(webhook);
66
- expect(webhookOutput.id).toBeTruthy();
67
- expect(webhookOutput.url).toBe("https://example.com/alchemy-webhook");
68
- expect(webhookOutput.secret).toBeTruthy();
69
-
70
- // Verify with Stripe API
71
- const stripeWebhook = await stripe.webhookEndpoints.retrieve(
72
- webhookOutput.id,
73
- );
74
- expect(stripeWebhook.url).toBe("https://example.com/alchemy-webhook");
75
-
76
- // Clean up resources
77
- console.log("Cleaning up Stripe resources...");
78
- await destroy(webhook);
79
- await destroy(price);
80
- await destroy(product);
81
-
82
- // Verify clean up
83
- await assertProductDeactivated(productOutput.id);
84
- await assertPriceDeactivated(priceOutput.id);
85
- await assertWebhookDeleted(webhookOutput.id);
86
- });
87
- });
88
-
89
- // Helper functions for verification
90
- async function assertProductDeactivated(productId: string) {
91
- try {
92
- const product = await stripe.products.retrieve(productId);
93
- // Products are deactivated, not deleted
94
- expect(product.active).toBe(false);
95
- } catch (error) {
96
- // If product is not found, that's also acceptable
97
- if (
98
- error instanceof Stripe.errors.StripeError &&
99
- error.code === "resource_missing"
100
- ) {
101
- return;
102
- }
103
- throw error;
104
- }
105
- }
106
-
107
- async function assertPriceDeactivated(priceId: string) {
108
- try {
109
- const price = await stripe.prices.retrieve(priceId);
110
- // Prices are deactivated, not deleted
111
- expect(price.active).toBe(false);
112
- } catch (error) {
113
- // If price is not found, that's also acceptable
114
- if (
115
- error instanceof Stripe.errors.StripeError &&
116
- error.code === "resource_missing"
117
- ) {
118
- return;
119
- }
120
- throw error;
121
- }
122
- }
123
-
124
- async function assertWebhookDeleted(webhookId: string) {
125
- try {
126
- await stripe.webhookEndpoints.retrieve(webhookId);
127
- throw new Error("Webhook still exists");
128
- } catch (error) {
129
- // Webhook should be deleted, so we expect a resource_missing error
130
- if (error instanceof Stripe.errors.StripeError) {
131
- expect(error.code).toBe("resource_missing");
132
- } else {
133
- throw error;
134
- }
135
- }
136
- }
package/tsconfig.json DELETED
@@ -1,33 +0,0 @@
1
- {
2
- "include": ["src/**/*"],
3
- "compilerOptions": {
4
- "rootDir": "./src",
5
- "outDir": "./lib",
6
- "noEmit": false,
7
- // Enable latest features
8
- "lib": ["ESNext", "DOM"],
9
- "target": "ESNext",
10
- "module": "ESNext",
11
- "moduleDetection": "force",
12
- "jsx": "react-jsx",
13
- "allowJs": true,
14
- "esModuleInterop": true,
15
- "declaration": true,
16
- "declarationMap": true,
17
- "sourceMap": true,
18
-
19
- // Bundler mode
20
- "moduleResolution": "bundler",
21
- "verbatimModuleSyntax": true,
22
-
23
- // Best practices
24
- "strict": true,
25
- "skipLibCheck": true,
26
- "noFallthroughCasesInSwitch": true,
27
-
28
- // Some stricter flags (disabled by default)
29
- "noUnusedLocals": false,
30
- "noUnusedParameters": false,
31
- "noPropertyAccessFromIndexSignature": false
32
- }
33
- }