nomoss 0.0.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/LICENSE +19 -0
- package/README.md +45 -0
- package/bin/nomoss +13 -0
- package/docs/code-documentation.md +36 -0
- package/docs/effect-native-development.md +55 -0
- package/docs/engine-design.md +93 -0
- package/docs/linting.md +88 -0
- package/docs/releasing.md +13 -0
- package/docs/resource-command-policy-stage.md +71 -0
- package/docs/resource-graph-mvp.md +31 -0
- package/docs/resource-graph-testing-approach.md +11 -0
- package/docs/resource-lifecycle-tracker.md +93 -0
- package/docs/testing.md +86 -0
- package/examples/upload-events/README.md +41 -0
- package/media/nomoss.gif +0 -0
- package/package.json +64 -0
- package/src/cli.ts +18 -0
- package/src/cliCommand.ts +186 -0
- package/src/cliRuntimeLayer.ts +49 -0
- package/src/core/index.ts +17 -0
- package/src/core/lifecycle.ts +127 -0
- package/src/core/model.ts +229 -0
- package/src/core/physicalNameStore.ts +226 -0
- package/src/core/planner.ts +645 -0
- package/src/core/resourceCommandPolicy.ts +79 -0
- package/src/core/resourceGraphBuilder.ts +167 -0
- package/src/core/resourceGraphStore.ts +288 -0
- package/src/core/resourceOutputResolver.ts +185 -0
- package/src/core/resourcePolicy.ts +77 -0
- package/src/core/resourceStackDefinition.ts +17 -0
- package/src/core/resourceStackLifecycle.ts +456 -0
- package/src/core/resourceStackOperations.ts +129 -0
- package/src/core/runtimeLayer.ts +73 -0
- package/src/core/stackWorkflowRenderer.ts +239 -0
- package/src/core/stateSecretService.ts +553 -0
- package/src/core/stateStore.ts +652 -0
- package/src/core/tracing.ts +26 -0
- package/src/index.ts +2 -0
- package/src/providers/aws/awsApply.ts +132 -0
- package/src/providers/aws/awsBucket.ts +329 -0
- package/src/providers/aws/awsBucketNotification.ts +351 -0
- package/src/providers/aws/awsBucketNotificationResourcePolicy.ts +251 -0
- package/src/providers/aws/awsBucketResourcePolicy.ts +198 -0
- package/src/providers/aws/awsProviderLayer.ts +274 -0
- package/src/providers/aws/awsQueue.ts +346 -0
- package/src/providers/aws/awsQueuePolicy.ts +419 -0
- package/src/providers/aws/awsQueuePolicyResourcePolicy.ts +215 -0
- package/src/providers/aws/awsQueueResourcePolicy.ts +270 -0
- package/src/providers/aws/awsReconciliation.ts +92 -0
- package/src/providers/aws/awsRefresh.ts +50 -0
- package/src/providers/aws/awsResourceLifecycle.ts +118 -0
- package/src/providers/aws/awsResourcePolicy.ts +83 -0
- package/src/providers/aws/awsResources.ts +274 -0
- package/src/providers/aws/awsRuntimeLayer.ts +21 -0
- package/src/providers/aws/awsSqsTransport.ts +33 -0
- package/src/providers/aws/awsStackLifecycle.ts +272 -0
- package/src/providers/aws/awsTagging.ts +186 -0
- package/src/providers/aws/constants.ts +3 -0
- package/src/providers/aws/index.ts +22 -0
- package/src/providers/aws/sampleStack.ts +65 -0
- package/src/providers/aws/stackWorkflow.ts +443 -0
- package/src/providers/index.ts +5 -0
- package/src/providers/provider.ts +5 -0
- package/src/providers/providerRuntimeLayer.ts +121 -0
- package/src/providers/resourceCommandPolicyLayer.ts +240 -0
- package/src/providers/stripe/index.ts +15 -0
- package/src/providers/stripe/stripeAccount.ts +139 -0
- package/src/providers/stripe/stripeBillingConfigurationExport.ts +180 -0
- package/src/providers/stripe/stripeBillingConfigurationExportResourcePolicy.ts +178 -0
- package/src/providers/stripe/stripeBillingPortalConfiguration.ts +153 -0
- package/src/providers/stripe/stripeBillingPortalConfigurationResourcePolicy.ts +177 -0
- package/src/providers/stripe/stripeCustomer.ts +148 -0
- package/src/providers/stripe/stripeCustomerResourcePolicy.ts +160 -0
- package/src/providers/stripe/stripePrice.ts +218 -0
- package/src/providers/stripe/stripePriceResourcePolicy.ts +151 -0
- package/src/providers/stripe/stripeProduct.ts +171 -0
- package/src/providers/stripe/stripeProductResourcePolicy.ts +161 -0
- package/src/providers/stripe/stripeResources.ts +454 -0
- package/src/providers/stripe/stripeRuntimeLayer.ts +131 -0
- package/src/providers/stripe/stripeWebhookEndpoint.ts +293 -0
- package/src/providers/stripe/stripeWebhookEndpointResourcePolicy.ts +198 -0
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import * as Credentials from "@distilled.cloud/aws/Credentials";
|
|
2
|
+
import * as Region from "@distilled.cloud/aws/Region";
|
|
3
|
+
import type * as S3 from "@distilled.cloud/aws/s3";
|
|
4
|
+
import * as s3 from "@distilled.cloud/aws/s3";
|
|
5
|
+
import type * as SQS from "@distilled.cloud/aws/sqs";
|
|
6
|
+
import * as sqs from "@distilled.cloud/aws/sqs";
|
|
7
|
+
import {
|
|
8
|
+
Array as Arr,
|
|
9
|
+
Context,
|
|
10
|
+
Data,
|
|
11
|
+
Effect,
|
|
12
|
+
Layer,
|
|
13
|
+
Match,
|
|
14
|
+
Record,
|
|
15
|
+
} from "effect";
|
|
16
|
+
|
|
17
|
+
import * as FetchHttpClient from "effect/unstable/http/FetchHttpClient";
|
|
18
|
+
|
|
19
|
+
const awsGeneratedOperationLayer = Layer.mergeAll(
|
|
20
|
+
Credentials.fromChain(),
|
|
21
|
+
Region.fromEnv(),
|
|
22
|
+
FetchHttpClient.layer,
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
export type AwsTaggingTarget =
|
|
26
|
+
| {
|
|
27
|
+
readonly _tag: "S3Bucket";
|
|
28
|
+
readonly bucket: string;
|
|
29
|
+
}
|
|
30
|
+
| {
|
|
31
|
+
readonly _tag: "SqsQueue";
|
|
32
|
+
readonly queueUrl: string;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export class AwsTaggingFailed extends Data.TaggedError("AwsTaggingFailed")<{
|
|
36
|
+
readonly cause:
|
|
37
|
+
| S3.DeleteBucketTaggingError
|
|
38
|
+
| S3.PutBucketTaggingError
|
|
39
|
+
| SQS.TagQueueError
|
|
40
|
+
| SQS.UntagQueueError;
|
|
41
|
+
}> {}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Queue and bucket policies use this adapter to reconcile tags without leaking
|
|
45
|
+
* S3 and SQS request differences into graph-level resource logic.
|
|
46
|
+
*/
|
|
47
|
+
export class AwsTagging extends Context.Service<AwsTagging>()(
|
|
48
|
+
"nomoss/providers/aws/awsTagging",
|
|
49
|
+
{
|
|
50
|
+
make: Effect.gen(function* () {
|
|
51
|
+
const deleteBucketTagging = yield* s3.deleteBucketTagging;
|
|
52
|
+
const putBucketTagging = yield* s3.putBucketTagging;
|
|
53
|
+
const tagQueue = yield* sqs.tagQueue;
|
|
54
|
+
const untagQueue = yield* sqs.untagQueue;
|
|
55
|
+
|
|
56
|
+
type SqsTagOperation =
|
|
57
|
+
| {
|
|
58
|
+
readonly _tag: "Add";
|
|
59
|
+
readonly tags: Record<string, string>;
|
|
60
|
+
}
|
|
61
|
+
| {
|
|
62
|
+
readonly _tag: "Remove";
|
|
63
|
+
readonly tagKeys: ReadonlyArray<string>;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const sqsTagsToAdd = (
|
|
67
|
+
desiredTags: Record<string, string>,
|
|
68
|
+
observedTags: Record<string, string>,
|
|
69
|
+
) =>
|
|
70
|
+
Record.filter(desiredTags, (value, key) => observedTags[key] !== value);
|
|
71
|
+
|
|
72
|
+
const sqsTagKeysToRemove = (
|
|
73
|
+
desiredTags: Record<string, string>,
|
|
74
|
+
observedTags: Record<string, string>,
|
|
75
|
+
) =>
|
|
76
|
+
Record.keys(
|
|
77
|
+
Record.filter(
|
|
78
|
+
observedTags,
|
|
79
|
+
(_value, key) => desiredTags[key] === undefined,
|
|
80
|
+
),
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
const sqsTagOperations = (
|
|
84
|
+
desiredTags: Record<string, string>,
|
|
85
|
+
observedTags: Record<string, string>,
|
|
86
|
+
): ReadonlyArray<SqsTagOperation> =>
|
|
87
|
+
Arr.appendAll(
|
|
88
|
+
Match.value(sqsTagsToAdd(desiredTags, observedTags)).pipe(
|
|
89
|
+
Match.when(Record.isEmptyReadonlyRecord, () => []),
|
|
90
|
+
Match.orElse(
|
|
91
|
+
(tags): ReadonlyArray<SqsTagOperation> => [{ _tag: "Add", tags }],
|
|
92
|
+
),
|
|
93
|
+
),
|
|
94
|
+
Match.value(sqsTagKeysToRemove(desiredTags, observedTags)).pipe(
|
|
95
|
+
Match.when(Arr.isReadonlyArrayEmpty, () => []),
|
|
96
|
+
Match.orElse(
|
|
97
|
+
(tagKeys): ReadonlyArray<SqsTagOperation> => [
|
|
98
|
+
{ _tag: "Remove", tagKeys },
|
|
99
|
+
],
|
|
100
|
+
),
|
|
101
|
+
),
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
const deleteBucketTags = (bucket: string) =>
|
|
105
|
+
deleteBucketTagging({ Bucket: bucket }).pipe(
|
|
106
|
+
Effect.provide(awsGeneratedOperationLayer),
|
|
107
|
+
Effect.mapError((cause) => new AwsTaggingFailed({ cause })),
|
|
108
|
+
);
|
|
109
|
+
const putBucketTags = (
|
|
110
|
+
bucket: string,
|
|
111
|
+
desiredTags: ReadonlyArray<{
|
|
112
|
+
readonly Key: string;
|
|
113
|
+
readonly Value: string;
|
|
114
|
+
}>,
|
|
115
|
+
) =>
|
|
116
|
+
putBucketTagging({
|
|
117
|
+
Bucket: bucket,
|
|
118
|
+
Tagging: { TagSet: Arr.fromIterable(desiredTags) },
|
|
119
|
+
}).pipe(
|
|
120
|
+
Effect.provide(awsGeneratedOperationLayer),
|
|
121
|
+
Effect.mapError((cause) => new AwsTaggingFailed({ cause })),
|
|
122
|
+
);
|
|
123
|
+
const addQueueTags = (queueUrl: string, tags: Record<string, string>) =>
|
|
124
|
+
tagQueue({ QueueUrl: queueUrl, Tags: tags }).pipe(
|
|
125
|
+
Effect.provide(awsGeneratedOperationLayer),
|
|
126
|
+
Effect.mapError((cause) => new AwsTaggingFailed({ cause })),
|
|
127
|
+
);
|
|
128
|
+
const removeQueueTags = (
|
|
129
|
+
queueUrl: string,
|
|
130
|
+
tagKeys: ReadonlyArray<string>,
|
|
131
|
+
) =>
|
|
132
|
+
untagQueue({
|
|
133
|
+
QueueUrl: queueUrl,
|
|
134
|
+
TagKeys: Arr.fromIterable(tagKeys),
|
|
135
|
+
}).pipe(
|
|
136
|
+
Effect.provide(awsGeneratedOperationLayer),
|
|
137
|
+
Effect.mapError((cause) => new AwsTaggingFailed({ cause })),
|
|
138
|
+
);
|
|
139
|
+
const applySqsTagOperation = (
|
|
140
|
+
queueUrl: string,
|
|
141
|
+
operation: SqsTagOperation,
|
|
142
|
+
) =>
|
|
143
|
+
Match.value(operation).pipe(
|
|
144
|
+
Match.tagsExhaustive({
|
|
145
|
+
Add: ({ tags }) => addQueueTags(queueUrl, tags),
|
|
146
|
+
Remove: ({ tagKeys }) => removeQueueTags(queueUrl, tagKeys),
|
|
147
|
+
}),
|
|
148
|
+
);
|
|
149
|
+
const reconcileS3BucketTags = (
|
|
150
|
+
bucket: string,
|
|
151
|
+
desiredTags: Record<string, string>,
|
|
152
|
+
) =>
|
|
153
|
+
Match.value(
|
|
154
|
+
Arr.map(Record.toEntries(desiredTags), ([Key, Value]) => ({
|
|
155
|
+
Key,
|
|
156
|
+
Value,
|
|
157
|
+
})),
|
|
158
|
+
).pipe(
|
|
159
|
+
Match.when(Arr.isReadonlyArrayEmpty, () => deleteBucketTags(bucket)),
|
|
160
|
+
Match.orElse((desired) => putBucketTags(bucket, desired)),
|
|
161
|
+
);
|
|
162
|
+
|
|
163
|
+
return {
|
|
164
|
+
reconcile: Effect.fn("AwsTagging.reconcile")(function* (input: {
|
|
165
|
+
readonly target: AwsTaggingTarget;
|
|
166
|
+
readonly desiredTags: Record<string, string>;
|
|
167
|
+
readonly observedTags: Record<string, string>;
|
|
168
|
+
}) {
|
|
169
|
+
yield* Match.value(input.target).pipe(
|
|
170
|
+
Match.when({ _tag: "S3Bucket" }, ({ bucket }) =>
|
|
171
|
+
reconcileS3BucketTags(bucket, input.desiredTags),
|
|
172
|
+
),
|
|
173
|
+
Match.when({ _tag: "SqsQueue" }, ({ queueUrl }) =>
|
|
174
|
+
Effect.forEach(
|
|
175
|
+
sqsTagOperations(input.desiredTags, input.observedTags),
|
|
176
|
+
(operation) => applySqsTagOperation(queueUrl, operation),
|
|
177
|
+
{ discard: true },
|
|
178
|
+
),
|
|
179
|
+
),
|
|
180
|
+
Match.exhaustive,
|
|
181
|
+
);
|
|
182
|
+
}),
|
|
183
|
+
};
|
|
184
|
+
}).pipe(Effect.provide(awsGeneratedOperationLayer)),
|
|
185
|
+
},
|
|
186
|
+
) {}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export * from "./awsApply.js";
|
|
2
|
+
export * from "./awsBucket.js";
|
|
3
|
+
export * from "./awsBucketNotification.js";
|
|
4
|
+
export * from "./awsBucketNotificationResourcePolicy.js";
|
|
5
|
+
export * from "./awsBucketResourcePolicy.js";
|
|
6
|
+
export * from "./awsProviderLayer.js";
|
|
7
|
+
export * from "./awsQueue.js";
|
|
8
|
+
export * from "./awsQueuePolicy.js";
|
|
9
|
+
export * from "./awsQueuePolicyResourcePolicy.js";
|
|
10
|
+
export * from "./awsQueueResourcePolicy.js";
|
|
11
|
+
export * from "./awsReconciliation.js";
|
|
12
|
+
export * from "./awsRefresh.js";
|
|
13
|
+
export * from "./awsResourcePolicy.js";
|
|
14
|
+
export * from "./awsResourceLifecycle.js";
|
|
15
|
+
export * from "./awsResources.js";
|
|
16
|
+
export * from "./awsRuntimeLayer.js";
|
|
17
|
+
export * from "./awsSqsTransport.js";
|
|
18
|
+
export * from "./awsStackLifecycle.js";
|
|
19
|
+
export * from "./awsTagging.js";
|
|
20
|
+
export * from "./constants.js";
|
|
21
|
+
export * from "./sampleStack.js";
|
|
22
|
+
export * from "./stackWorkflow.js";
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Context, Data, Effect, Option, Schema } from "effect";
|
|
2
|
+
|
|
3
|
+
import { Aws } from "./awsResources.js";
|
|
4
|
+
import { uploadEventsTarget } from "./constants.js";
|
|
5
|
+
|
|
6
|
+
export type StackName = "upload-events";
|
|
7
|
+
|
|
8
|
+
export const StackNameSchema = Schema.Literal("upload-events");
|
|
9
|
+
|
|
10
|
+
export class StackNotFound extends Data.TaggedError("StackNotFound")<{
|
|
11
|
+
readonly name: string;
|
|
12
|
+
}> { }
|
|
13
|
+
|
|
14
|
+
export const uploadEventsStack = {
|
|
15
|
+
name: "upload-events",
|
|
16
|
+
description: "S3 bucket publishing object-created notifications to SQS",
|
|
17
|
+
region: uploadEventsTarget.region,
|
|
18
|
+
// The stack is just one explicit Effect program that registers resources.
|
|
19
|
+
graph: Effect.gen(function* () {
|
|
20
|
+
const bucket = yield* Aws.Bucket({
|
|
21
|
+
logicalId: "Uploads",
|
|
22
|
+
forceDestroy: true,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const queue = yield* Aws.Queue({
|
|
26
|
+
logicalId: "UploadEvents",
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// Resource constructors return output refs, so dependencies stay typed.
|
|
30
|
+
const queuePolicy = yield* Aws.QueuePolicy({
|
|
31
|
+
logicalId: "UploadEventsPolicy",
|
|
32
|
+
bucketArn: bucket.BucketArn,
|
|
33
|
+
queueUrl: queue.QueueUrl,
|
|
34
|
+
queueArn: queue.QueueArn,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
yield* Aws.BucketNotification({
|
|
38
|
+
logicalId: "UploadEventsNotification",
|
|
39
|
+
bucketName: bucket.Bucket,
|
|
40
|
+
queueArn: queue.QueueArn,
|
|
41
|
+
queuePolicy: queuePolicy.key,
|
|
42
|
+
});
|
|
43
|
+
}),
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const stacks: Record<StackName, typeof uploadEventsStack> = {
|
|
47
|
+
"upload-events": uploadEventsStack,
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export class StackCatalog extends Context.Service<StackCatalog>()(
|
|
51
|
+
"nomoss/providers/aws/sampleStack/StackCatalog",
|
|
52
|
+
{
|
|
53
|
+
make: Effect.succeed({
|
|
54
|
+
names: [uploadEventsStack.name] as const,
|
|
55
|
+
get: (name: StackName) =>
|
|
56
|
+
Option.fromUndefinedOr(stacks[name]).pipe(
|
|
57
|
+
Option.match({
|
|
58
|
+
onNone: () => Effect.fail(new StackNotFound({ name })),
|
|
59
|
+
onSome: Effect.succeed,
|
|
60
|
+
}),
|
|
61
|
+
),
|
|
62
|
+
}),
|
|
63
|
+
},
|
|
64
|
+
) {
|
|
65
|
+
}
|