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.
- package/lib/$.d.ts +7 -0
- package/lib/$.d.ts.map +1 -0
- package/lib/$.js +31 -0
- package/lib/$.js.map +1 -0
- package/lib/agent/ai.d.ts +40 -0
- package/lib/agent/ai.d.ts.map +1 -0
- package/lib/agent/ai.js +132 -0
- package/lib/agent/ai.js.map +1 -0
- package/lib/agent/anthropic.d.ts +9 -0
- package/lib/agent/anthropic.d.ts.map +1 -0
- package/lib/agent/anthropic.js +25 -0
- package/lib/agent/anthropic.js.map +1 -0
- package/lib/agent/dependencies.d.ts +4 -0
- package/lib/agent/dependencies.d.ts.map +1 -0
- package/lib/agent/dependencies.js +48 -0
- package/lib/agent/dependencies.js.map +1 -0
- package/lib/agent/file-context.d.ts +13 -0
- package/lib/agent/file-context.d.ts.map +1 -0
- package/lib/agent/file-context.js +6 -0
- package/lib/agent/file-context.js.map +1 -0
- package/lib/agent/index.d.ts +10 -0
- package/lib/agent/index.d.ts.map +1 -0
- package/lib/agent/index.js +10 -0
- package/lib/agent/index.js.map +1 -0
- package/lib/agent/model.d.ts +8 -0
- package/lib/agent/model.d.ts.map +1 -0
- package/lib/agent/model.js +29 -0
- package/lib/agent/model.js.map +1 -0
- package/lib/agent/module.d.ts +81 -0
- package/lib/agent/module.d.ts.map +1 -0
- package/lib/agent/module.js +309 -0
- package/lib/agent/module.js.map +1 -0
- package/lib/agent/openai.d.ts +6 -0
- package/lib/agent/openai.d.ts.map +1 -0
- package/lib/agent/openai.js +41 -0
- package/lib/agent/openai.js.map +1 -0
- package/lib/agent/program.d.ts +12 -0
- package/lib/agent/program.d.ts.map +1 -0
- package/lib/agent/program.js +21 -0
- package/lib/agent/program.js.map +1 -0
- package/lib/agent/prompts.d.ts +4 -0
- package/lib/agent/prompts.d.ts.map +1 -0
- package/lib/agent/prompts.js +11 -0
- package/lib/agent/prompts.js.map +1 -0
- package/lib/agent/scrape.d.ts +71 -0
- package/lib/agent/scrape.d.ts.map +1 -0
- package/lib/agent/scrape.js +45 -0
- package/lib/agent/scrape.js.map +1 -0
- package/lib/alchemize.d.ts +43 -0
- package/lib/alchemize.d.ts.map +1 -0
- package/lib/alchemize.js +105 -0
- package/lib/alchemize.js.map +1 -0
- package/lib/apply.d.ts +23 -0
- package/lib/apply.d.ts.map +1 -0
- package/lib/apply.js +84 -0
- package/lib/apply.js.map +1 -0
- package/lib/aws/auto/docs.d.ts +11 -0
- package/lib/aws/auto/docs.d.ts.map +1 -0
- package/lib/aws/auto/docs.js +56 -0
- package/lib/aws/auto/docs.js.map +1 -0
- package/lib/aws/auto/index.d.ts +5 -0
- package/lib/aws/auto/index.d.ts.map +1 -0
- package/lib/aws/auto/index.js +5 -0
- package/lib/aws/auto/index.js.map +1 -0
- package/lib/aws/auto/resource.d.ts +24 -0
- package/lib/aws/auto/resource.d.ts.map +1 -0
- package/lib/aws/auto/resource.js +194 -0
- package/lib/aws/auto/resource.js.map +1 -0
- package/lib/aws/auto/service.d.ts +10 -0
- package/lib/aws/auto/service.d.ts.map +1 -0
- package/lib/aws/auto/service.js +34 -0
- package/lib/aws/auto/service.js.map +1 -0
- package/lib/aws/auto/spec.d.ts +83 -0
- package/lib/aws/auto/spec.d.ts.map +1 -0
- package/lib/aws/auto/spec.js +58 -0
- package/lib/aws/auto/spec.js.map +1 -0
- package/lib/aws/bucket.d.ts +21 -0
- package/lib/aws/bucket.d.ts.map +1 -0
- package/lib/aws/bucket.js +114 -0
- package/lib/aws/bucket.js.map +1 -0
- package/lib/aws/function.d.ts +53 -0
- package/lib/aws/function.d.ts.map +1 -0
- package/lib/aws/function.js +195 -0
- package/lib/aws/function.js.map +1 -0
- package/lib/aws/index.d.ts +7 -0
- package/lib/aws/index.d.ts.map +1 -0
- package/lib/aws/index.js +7 -0
- package/lib/aws/index.js.map +1 -0
- package/lib/aws/policy.d.ts +46 -0
- package/lib/aws/policy.d.ts.map +1 -0
- package/lib/aws/policy.js +139 -0
- package/lib/aws/policy.js.map +1 -0
- package/lib/aws/queue.d.ts +38 -0
- package/lib/aws/queue.d.ts.map +1 -0
- package/lib/aws/queue.js +162 -0
- package/lib/aws/queue.js.map +1 -0
- package/lib/aws/role.d.ts +27 -0
- package/lib/aws/role.d.ts.map +1 -0
- package/lib/aws/role.js +149 -0
- package/lib/aws/role.js.map +1 -0
- package/lib/aws/table.d.ts +26 -0
- package/lib/aws/table.d.ts.map +1 -0
- package/lib/aws/table.js +120 -0
- package/lib/aws/table.js.map +1 -0
- package/lib/destroy.d.ts +19 -0
- package/lib/destroy.d.ts.map +1 -0
- package/lib/destroy.js +47 -0
- package/lib/destroy.js.map +1 -0
- package/lib/error.d.ts +2 -0
- package/lib/error.d.ts.map +1 -0
- package/lib/error.js +13 -0
- package/lib/error.js.map +1 -0
- package/lib/esbuild.d.ts +70 -0
- package/lib/esbuild.d.ts.map +1 -0
- package/lib/esbuild.js +58 -0
- package/lib/esbuild.js.map +1 -0
- package/lib/fs.d.ts +12 -0
- package/lib/fs.d.ts.map +1 -0
- package/lib/fs.js +41 -0
- package/lib/fs.js.map +1 -0
- package/lib/global.d.ts +18 -0
- package/lib/global.d.ts.map +1 -0
- package/lib/global.js +42 -0
- package/lib/global.js.map +1 -0
- package/lib/index.d.ts +9 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +8 -0
- package/lib/index.js.map +1 -0
- package/lib/input.d.ts +6 -0
- package/lib/input.d.ts.map +1 -0
- package/lib/input.js +2 -0
- package/lib/input.js.map +1 -0
- package/lib/main.d.ts +3 -0
- package/lib/main.d.ts.map +1 -0
- package/lib/main.js +32 -0
- package/lib/main.js.map +1 -0
- package/lib/markdown/design.d.ts +17 -0
- package/lib/markdown/design.d.ts.map +1 -0
- package/lib/markdown/design.js +92 -0
- package/lib/markdown/design.js.map +1 -0
- package/lib/markdown/extract.d.ts +7 -0
- package/lib/markdown/extract.d.ts.map +1 -0
- package/lib/markdown/extract.js +10 -0
- package/lib/markdown/extract.js.map +1 -0
- package/lib/markdown/index.d.ts +4 -0
- package/lib/markdown/index.d.ts.map +1 -0
- package/lib/markdown/index.js +4 -0
- package/lib/markdown/index.js.map +1 -0
- package/lib/markdown/requirements.d.ts +79 -0
- package/lib/markdown/requirements.d.ts.map +1 -0
- package/lib/markdown/requirements.js +105 -0
- package/lib/markdown/requirements.js.map +1 -0
- package/lib/output.d.ts +19 -0
- package/lib/output.d.ts.map +1 -0
- package/lib/output.js +16 -0
- package/lib/output.js.map +1 -0
- package/lib/resource.d.ts +66 -0
- package/lib/resource.d.ts.map +1 -0
- package/lib/resource.js +242 -0
- package/lib/resource.js.map +1 -0
- package/lib/scope.d.ts +15 -0
- package/lib/scope.d.ts.map +1 -0
- package/lib/scope.js +38 -0
- package/lib/scope.js.map +1 -0
- package/lib/slug.d.ts +2 -0
- package/lib/slug.d.ts.map +1 -0
- package/lib/slug.js +4 -0
- package/lib/slug.js.map +1 -0
- package/lib/state.d.ts +40 -0
- package/lib/state.d.ts.map +1 -0
- package/lib/state.js +73 -0
- package/lib/state.js.map +1 -0
- package/lib/stripe/index.d.ts +4 -0
- package/lib/stripe/index.d.ts.map +1 -0
- package/lib/stripe/index.js +4 -0
- package/lib/stripe/index.js.map +1 -0
- package/lib/stripe/price.d.ts +109 -0
- package/lib/stripe/price.d.ts.map +1 -0
- package/lib/stripe/price.js +112 -0
- package/lib/stripe/price.js.map +1 -0
- package/lib/stripe/product.d.ts +86 -0
- package/lib/stripe/product.d.ts.map +1 -0
- package/lib/stripe/product.js +90 -0
- package/lib/stripe/product.js.map +1 -0
- package/lib/stripe/webhook.d.ts +73 -0
- package/lib/stripe/webhook.d.ts.map +1 -0
- package/lib/stripe/webhook.js +94 -0
- package/lib/stripe/webhook.js.map +1 -0
- package/lib/typescript/check-omission.d.ts +2 -0
- package/lib/typescript/check-omission.d.ts.map +1 -0
- package/lib/typescript/check-omission.js +43 -0
- package/lib/typescript/check-omission.js.map +1 -0
- package/lib/typescript/debug-type-errors.d.ts +3 -0
- package/lib/typescript/debug-type-errors.d.ts.map +1 -0
- package/lib/typescript/debug-type-errors.js +35 -0
- package/lib/typescript/debug-type-errors.js.map +1 -0
- package/lib/typescript/extract.d.ts +7 -0
- package/lib/typescript/extract.d.ts.map +1 -0
- package/lib/typescript/extract.js +10 -0
- package/lib/typescript/extract.js.map +1 -0
- package/lib/typescript/index.d.ts +7 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/index.js +7 -0
- package/lib/typescript/index.js.map +1 -0
- package/lib/typescript/install-dependencies.d.ts +29 -0
- package/lib/typescript/install-dependencies.d.ts.map +1 -0
- package/lib/typescript/install-dependencies.js +52 -0
- package/lib/typescript/install-dependencies.js.map +1 -0
- package/lib/typescript/package.d.ts +157 -0
- package/lib/typescript/package.d.ts.map +1 -0
- package/lib/typescript/package.js +115 -0
- package/lib/typescript/package.js.map +1 -0
- package/lib/typescript/repair-omissions.d.ts +3 -0
- package/lib/typescript/repair-omissions.d.ts.map +1 -0
- package/lib/typescript/repair-omissions.js +23 -0
- package/lib/typescript/repair-omissions.js.map +1 -0
- package/lib/typescript/repair.d.ts +3 -0
- package/lib/typescript/repair.d.ts.map +1 -0
- package/lib/typescript/repair.js +34 -0
- package/lib/typescript/repair.js.map +1 -0
- package/lib/typescript/tsconfig.d.ts +469 -0
- package/lib/typescript/tsconfig.d.ts.map +1 -0
- package/lib/typescript/tsconfig.js +143 -0
- package/lib/typescript/tsconfig.js.map +1 -0
- package/lib/typescript/typescript.d.ts +107 -0
- package/lib/typescript/typescript.d.ts.map +1 -0
- package/lib/typescript/typescript.js +180 -0
- package/lib/typescript/typescript.js.map +1 -0
- package/lib/typescript/validate.d.ts +10 -0
- package/lib/typescript/validate.d.ts.map +1 -0
- package/lib/typescript/validate.js +49 -0
- package/lib/typescript/validate.js.map +1 -0
- package/package.json +4 -3
- package/test/aws/function.test.ts +0 -144
- package/test/aws/queue.test.ts +0 -85
- package/test/aws/role.test.ts +0 -153
- package/test/aws/table.test.ts +0 -73
- package/test/esbuild.test.ts +0 -41
- package/test/handler.ts +0 -9
- package/test/scope.test.ts +0 -67
- package/test/stripe/stripe.test.ts +0 -136
- package/tsconfig.json +0 -33
package/test/aws/role.test.ts
DELETED
|
@@ -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
|
-
}
|
package/test/aws/table.test.ts
DELETED
|
@@ -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
|
-
}
|
package/test/esbuild.test.ts
DELETED
|
@@ -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
package/test/scope.test.ts
DELETED
|
@@ -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
|
-
}
|