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,240 @@
|
|
|
1
|
+
import { Context, Effect, Layer, Match, Option } from "effect";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
type ResourceCommand,
|
|
5
|
+
ResourceCommandUnsupported,
|
|
6
|
+
} from "../core/lifecycle.js";
|
|
7
|
+
import type { ResourceSchemaAnnotation } from "../core/model.js";
|
|
8
|
+
import { resourceSchemaString } from "../core/model.js";
|
|
9
|
+
import {
|
|
10
|
+
ResourceCommandExecutionFailed,
|
|
11
|
+
type ResourceCommandFailure,
|
|
12
|
+
ResourceCommandPolicy,
|
|
13
|
+
} from "../core/resourceCommandPolicy.js";
|
|
14
|
+
import { QueueResourcePolicy } from "./aws/awsQueueResourcePolicy.js";
|
|
15
|
+
import { StripeBillingConfigurationExportResourcePolicy } from "./stripe/stripeBillingConfigurationExportResourcePolicy.js";
|
|
16
|
+
import { StripeBillingPortalConfigurationResourcePolicy } from "./stripe/stripeBillingPortalConfigurationResourcePolicy.js";
|
|
17
|
+
import { StripeCustomerResourcePolicy } from "./stripe/stripeCustomerResourcePolicy.js";
|
|
18
|
+
import { StripePriceResourcePolicy } from "./stripe/stripePriceResourcePolicy.js";
|
|
19
|
+
import { StripeProductResourcePolicy } from "./stripe/stripeProductResourcePolicy.js";
|
|
20
|
+
import { StripeWebhookEndpointResourcePolicy } from "./stripe/stripeWebhookEndpointResourcePolicy.js";
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Persisted resource commands carry schema metadata, not live provider service
|
|
24
|
+
* references. This private command target is the runtime service resolved from
|
|
25
|
+
* that metadata before stack lifecycle asks a provider to apply or delete a
|
|
26
|
+
* resource node.
|
|
27
|
+
*/
|
|
28
|
+
type ProviderResourceCommandPolicy = {
|
|
29
|
+
readonly execute: (
|
|
30
|
+
command: ResourceCommand,
|
|
31
|
+
) => ReturnType<(typeof ResourceCommandPolicy)["Service"]["execute"]>;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The schema annotation string is the stable Effect service key shared by the
|
|
36
|
+
* persisted resource graph and the provider layer graph. It lets command
|
|
37
|
+
* execution find the provider operation for a node without importing provider
|
|
38
|
+
* modules into core lifecycle code.
|
|
39
|
+
*
|
|
40
|
+
* Effect principle used here:
|
|
41
|
+
* - `Context.Service` defines a service tag. The tag is the lookup key.
|
|
42
|
+
* - `Layer.succeed(tag, service)` provides an implementation for that tag.
|
|
43
|
+
* - `Effect.serviceOption(tag)` asks the current runtime context whether an
|
|
44
|
+
* implementation for that tag was provided.
|
|
45
|
+
*
|
|
46
|
+
* This file derives the tag from resource schema metadata. Provider metadata
|
|
47
|
+
* layers provide `{ execute }` at that tag. Command execution resolves the tag
|
|
48
|
+
* from the running Effect context and calls the provided `execute` function.
|
|
49
|
+
*
|
|
50
|
+
* Example for Stripe prices:
|
|
51
|
+
*
|
|
52
|
+
* Schema source:
|
|
53
|
+
* `StripePricePropsSchema = annotateResourceSchema(PostPricesInput, {
|
|
54
|
+
* provider: "stripe",
|
|
55
|
+
* service: "billing",
|
|
56
|
+
* resource: "price",
|
|
57
|
+
* operation: "create",
|
|
58
|
+
* stateSecretOutputKeys: [],
|
|
59
|
+
* })`
|
|
60
|
+
*
|
|
61
|
+
* Persisted node metadata:
|
|
62
|
+
* `node.schema = {
|
|
63
|
+
* provider: "stripe",
|
|
64
|
+
* service: "billing",
|
|
65
|
+
* resource: "price",
|
|
66
|
+
* operation: "create",
|
|
67
|
+
* stateSecretOutputKeys: [],
|
|
68
|
+
* }`
|
|
69
|
+
*
|
|
70
|
+
* Service key:
|
|
71
|
+
* `resourceSchemaString(node.schema)` => `stripe:billing:price:create`
|
|
72
|
+
* `providerCommandPolicyTag(node.schema)` =>
|
|
73
|
+
* `nomoss/providers/resourceCommandPolicyLayer/stripe:billing:price:create`
|
|
74
|
+
*
|
|
75
|
+
* Execution path:
|
|
76
|
+
* `stripePriceResourceCommandMetadataLayer`
|
|
77
|
+
* => `bindProviderCommandPolicy(StripePriceResourcePolicy)`
|
|
78
|
+
* => `Layer.succeed(providerCommandPolicyTag(schema), { execute })`
|
|
79
|
+
*
|
|
80
|
+
* When stack lifecycle submits an apply/delete command,
|
|
81
|
+
* `providerResourceCommandPolicyLayerLive` reads `command.node.schema`, builds
|
|
82
|
+
* the same tag, resolves it with `Effect.serviceOption`, and calls the resolved
|
|
83
|
+
* service's `execute(command)`. For the key above, that `execute` delegates to
|
|
84
|
+
* `StripePriceResourcePolicy.execute`.
|
|
85
|
+
*/
|
|
86
|
+
const providerCommandPolicyTag = (schema: ResourceSchemaAnnotation) =>
|
|
87
|
+
Context.Service<ProviderResourceCommandPolicy, ProviderResourceCommandPolicy>(
|
|
88
|
+
`nomoss/providers/resourceCommandPolicyLayer/${resourceSchemaString(schema)}`,
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
const providerCommandError = (
|
|
92
|
+
command: ResourceCommand,
|
|
93
|
+
cause: ResourceCommandFailure,
|
|
94
|
+
) =>
|
|
95
|
+
new ResourceCommandExecutionFailed({
|
|
96
|
+
command,
|
|
97
|
+
cause,
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Provider policy metadata preserves the provider's own service method and
|
|
102
|
+
* changes only its error at the runtime registration point. Stack lifecycle
|
|
103
|
+
* receives one command contract while provider policies retain their local
|
|
104
|
+
* implementation and failure types.
|
|
105
|
+
*/
|
|
106
|
+
/**
|
|
107
|
+
* Provider modules contribute schema-keyed command metadata beside their normal
|
|
108
|
+
* resource policy services. Maintaining this list explicitly keeps provider
|
|
109
|
+
* assembly visible while command selection stays data-driven through the
|
|
110
|
+
* resource node schema.
|
|
111
|
+
*
|
|
112
|
+
* A queue command and a Stripe price command both enter stack lifecycle as the
|
|
113
|
+
* same `ResourceCommand` shape. The schema on the command node selects the
|
|
114
|
+
* matching metadata-provided service; no command-name switch is needed.
|
|
115
|
+
*/
|
|
116
|
+
export const awsQueueResourceCommandMetadataLayer = Layer.unwrap(
|
|
117
|
+
Effect.map(QueueResourcePolicy, ({ schema, execute }) =>
|
|
118
|
+
Layer.succeed(providerCommandPolicyTag(schema), {
|
|
119
|
+
execute: (command) =>
|
|
120
|
+
execute(command).pipe(
|
|
121
|
+
Effect.mapError((cause) => providerCommandError(command, cause)),
|
|
122
|
+
),
|
|
123
|
+
}),
|
|
124
|
+
),
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
export const stripeCustomerResourceCommandMetadataLayer = Layer.unwrap(
|
|
128
|
+
Effect.map(StripeCustomerResourcePolicy, ({ schema, execute }) =>
|
|
129
|
+
Layer.succeed(providerCommandPolicyTag(schema), {
|
|
130
|
+
execute: (command) =>
|
|
131
|
+
execute(command).pipe(
|
|
132
|
+
Effect.mapError((cause) => providerCommandError(command, cause)),
|
|
133
|
+
),
|
|
134
|
+
}),
|
|
135
|
+
),
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
export const stripeProductResourceCommandMetadataLayer = Layer.unwrap(
|
|
139
|
+
Effect.map(StripeProductResourcePolicy, ({ schema, execute }) =>
|
|
140
|
+
Layer.succeed(providerCommandPolicyTag(schema), {
|
|
141
|
+
execute: (command) =>
|
|
142
|
+
execute(command).pipe(
|
|
143
|
+
Effect.mapError((cause) => providerCommandError(command, cause)),
|
|
144
|
+
),
|
|
145
|
+
}),
|
|
146
|
+
),
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
export const stripePriceResourceCommandMetadataLayer = Layer.unwrap(
|
|
150
|
+
Effect.map(StripePriceResourcePolicy, ({ schema, execute }) =>
|
|
151
|
+
Layer.succeed(providerCommandPolicyTag(schema), {
|
|
152
|
+
execute: (command) =>
|
|
153
|
+
execute(command).pipe(
|
|
154
|
+
Effect.mapError((cause) => providerCommandError(command, cause)),
|
|
155
|
+
),
|
|
156
|
+
}),
|
|
157
|
+
),
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
export const stripeWebhookEndpointResourceCommandMetadataLayer = Layer.unwrap(
|
|
161
|
+
Effect.map(StripeWebhookEndpointResourcePolicy, ({ schema, execute }) =>
|
|
162
|
+
Layer.succeed(providerCommandPolicyTag(schema), {
|
|
163
|
+
execute: (command) =>
|
|
164
|
+
execute(command).pipe(
|
|
165
|
+
Effect.mapError((cause) => providerCommandError(command, cause)),
|
|
166
|
+
),
|
|
167
|
+
}),
|
|
168
|
+
),
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
export const stripeBillingPortalConfigurationResourceCommandMetadataLayer =
|
|
172
|
+
Layer.unwrap(
|
|
173
|
+
Effect.map(
|
|
174
|
+
StripeBillingPortalConfigurationResourcePolicy,
|
|
175
|
+
({ schema, execute }) =>
|
|
176
|
+
Layer.succeed(providerCommandPolicyTag(schema), {
|
|
177
|
+
execute: (command) =>
|
|
178
|
+
execute(command).pipe(
|
|
179
|
+
Effect.mapError((cause) => providerCommandError(command, cause)),
|
|
180
|
+
),
|
|
181
|
+
}),
|
|
182
|
+
),
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
export const stripeBillingConfigurationExportResourceCommandMetadataLayer =
|
|
186
|
+
Layer.unwrap(
|
|
187
|
+
Effect.map(
|
|
188
|
+
StripeBillingConfigurationExportResourcePolicy,
|
|
189
|
+
({ schema, execute }) =>
|
|
190
|
+
Layer.succeed(providerCommandPolicyTag(schema), {
|
|
191
|
+
execute: (command) =>
|
|
192
|
+
execute(command).pipe(
|
|
193
|
+
Effect.mapError((cause) => providerCommandError(command, cause)),
|
|
194
|
+
),
|
|
195
|
+
}),
|
|
196
|
+
),
|
|
197
|
+
);
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Stack lifecycle depends on the core `ResourceCommandPolicy` service, while
|
|
201
|
+
* each command names a persisted resource node. This layer resolves that node's
|
|
202
|
+
* schema metadata to the active provider command service and runs the provider
|
|
203
|
+
* operation through the shared Effect layer graph.
|
|
204
|
+
*
|
|
205
|
+
* Apply commands read the target node from the planner decision. Delete commands
|
|
206
|
+
* already carry the target node. Both forms use the node schema for provider
|
|
207
|
+
* selection, then delegate unchanged command data to the provider policy.
|
|
208
|
+
*/
|
|
209
|
+
export const providerResourceCommandPolicyLayerLive = Layer.effect(
|
|
210
|
+
ResourceCommandPolicy,
|
|
211
|
+
Effect.gen(function* () {
|
|
212
|
+
return {
|
|
213
|
+
execute: Effect.fn("ProviderResourceCommandPolicy.execute")(
|
|
214
|
+
function* (command) {
|
|
215
|
+
const commandNode = Match.value(command).pipe(
|
|
216
|
+
Match.when({ _tag: "Apply" }, ({ decision }) => decision.node),
|
|
217
|
+
Match.orElse(({ node }) => node),
|
|
218
|
+
);
|
|
219
|
+
|
|
220
|
+
const policyOption = yield* Effect.serviceOption(
|
|
221
|
+
providerCommandPolicyTag(commandNode.schema),
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
const policy = yield* Option.match(policyOption, {
|
|
225
|
+
onNone: () =>
|
|
226
|
+
Effect.fail(
|
|
227
|
+
new ResourceCommandExecutionFailed({
|
|
228
|
+
command,
|
|
229
|
+
cause: new ResourceCommandUnsupported({ command }),
|
|
230
|
+
}),
|
|
231
|
+
),
|
|
232
|
+
onSome: Effect.succeed,
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
return yield* policy.execute(command);
|
|
236
|
+
},
|
|
237
|
+
),
|
|
238
|
+
};
|
|
239
|
+
}),
|
|
240
|
+
);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export * from "./stripeAccount.js";
|
|
2
|
+
export * from "./stripeBillingConfigurationExport.js";
|
|
3
|
+
export * from "./stripeBillingConfigurationExportResourcePolicy.js";
|
|
4
|
+
export * from "./stripeBillingPortalConfiguration.js";
|
|
5
|
+
export * from "./stripeBillingPortalConfigurationResourcePolicy.js";
|
|
6
|
+
export * from "./stripeCustomer.js";
|
|
7
|
+
export * from "./stripeCustomerResourcePolicy.js";
|
|
8
|
+
export * from "./stripePrice.js";
|
|
9
|
+
export * from "./stripePriceResourcePolicy.js";
|
|
10
|
+
export * from "./stripeProduct.js";
|
|
11
|
+
export * from "./stripeProductResourcePolicy.js";
|
|
12
|
+
export * from "./stripeResources.js";
|
|
13
|
+
export * from "./stripeRuntimeLayer.js";
|
|
14
|
+
export * from "./stripeWebhookEndpoint.js";
|
|
15
|
+
export * from "./stripeWebhookEndpointResourcePolicy.js";
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { Credentials } from "@distilled.cloud/stripe";
|
|
2
|
+
import type {
|
|
3
|
+
GetV2CoreAccountsIdInput,
|
|
4
|
+
PostV2CoreAccountsIdCloseInput,
|
|
5
|
+
} from "@distilled.cloud/stripe/Operations";
|
|
6
|
+
import {
|
|
7
|
+
GetV2CoreAccountsId,
|
|
8
|
+
GetV2CoreAccountsIdOutput,
|
|
9
|
+
PostV2CoreAccounts,
|
|
10
|
+
PostV2CoreAccountsId,
|
|
11
|
+
PostV2CoreAccountsIdClose,
|
|
12
|
+
PostV2CoreAccountsIdInput,
|
|
13
|
+
PostV2CoreAccountsInput,
|
|
14
|
+
} from "@distilled.cloud/stripe/Operations";
|
|
15
|
+
import { Context, Effect, Option, Schema } from "effect";
|
|
16
|
+
|
|
17
|
+
import { annotateResourceSchema } from "../../core/model.js";
|
|
18
|
+
|
|
19
|
+
export enum StripeApiVersion {
|
|
20
|
+
Dahlia = "2026-06-24.dahlia",
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const StripeAccountPropsSchema = annotateResourceSchema(
|
|
24
|
+
PostV2CoreAccountsInput,
|
|
25
|
+
{
|
|
26
|
+
provider: "stripe",
|
|
27
|
+
service: "core",
|
|
28
|
+
resource: "account",
|
|
29
|
+
operation: "create",
|
|
30
|
+
stateSecretOutputKeys: [],
|
|
31
|
+
},
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
export type StripeAccountProps = Schema.Schema.Type<
|
|
35
|
+
typeof StripeAccountPropsSchema
|
|
36
|
+
>;
|
|
37
|
+
|
|
38
|
+
export const StripeAccountUpdatePropsSchema = PostV2CoreAccountsIdInput;
|
|
39
|
+
|
|
40
|
+
export type StripeAccountUpdateProps = Schema.Schema.Type<
|
|
41
|
+
typeof StripeAccountUpdatePropsSchema
|
|
42
|
+
>;
|
|
43
|
+
|
|
44
|
+
export const StripeAccountOutputsSchema = Schema.Struct({
|
|
45
|
+
AccountId: Schema.String,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
export type StripeAccountOutputs = Schema.Schema.Type<
|
|
49
|
+
typeof StripeAccountOutputsSchema
|
|
50
|
+
>;
|
|
51
|
+
|
|
52
|
+
export const StripeAccountObservedStateSchema = annotateResourceSchema(
|
|
53
|
+
GetV2CoreAccountsIdOutput,
|
|
54
|
+
{
|
|
55
|
+
provider: "stripe",
|
|
56
|
+
service: "core",
|
|
57
|
+
resource: "account",
|
|
58
|
+
operation: "read",
|
|
59
|
+
stateSecretOutputKeys: [],
|
|
60
|
+
},
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
export type StripeAccountObservedState = Schema.Schema.Type<
|
|
64
|
+
typeof StripeAccountObservedStateSchema
|
|
65
|
+
>;
|
|
66
|
+
|
|
67
|
+
export const stripeAccountOutputsFromState = (
|
|
68
|
+
state: StripeAccountObservedState,
|
|
69
|
+
): StripeAccountOutputs => {
|
|
70
|
+
const outputs: StripeAccountOutputs = {
|
|
71
|
+
AccountId: state.id,
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
return outputs;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Stripe account lifecycle calls the generated v2 Core Account operations.
|
|
79
|
+
* The API version stays explicit so provider behavior tracks the checked-in
|
|
80
|
+
* Stripe OpenAPI reference.
|
|
81
|
+
*/
|
|
82
|
+
export class StripeAccountLifecycleService extends Context.Service<StripeAccountLifecycleService>()(
|
|
83
|
+
"nomoss/providers/stripe/stripeAccount/StripeAccountLifecycleService",
|
|
84
|
+
{
|
|
85
|
+
make: Effect.gen(function* () {
|
|
86
|
+
const stripeCredentials = yield* Credentials;
|
|
87
|
+
|
|
88
|
+
return {
|
|
89
|
+
create: Effect.fn("StripeAccountLifecycleService.create")(function* (
|
|
90
|
+
props: StripeAccountProps,
|
|
91
|
+
) {
|
|
92
|
+
const account = yield* PostV2CoreAccounts(props, {
|
|
93
|
+
apiVersion: StripeApiVersion.Dahlia,
|
|
94
|
+
}).pipe(Effect.provideService(Credentials, stripeCredentials));
|
|
95
|
+
|
|
96
|
+
return account;
|
|
97
|
+
}),
|
|
98
|
+
|
|
99
|
+
read: Effect.fn("StripeAccountLifecycleService.read")(function* (
|
|
100
|
+
accountId: string,
|
|
101
|
+
) {
|
|
102
|
+
const input: GetV2CoreAccountsIdInput = {
|
|
103
|
+
id: accountId,
|
|
104
|
+
};
|
|
105
|
+
const account = yield* GetV2CoreAccountsId(input, {
|
|
106
|
+
apiVersion: StripeApiVersion.Dahlia,
|
|
107
|
+
}).pipe(
|
|
108
|
+
Effect.provideService(Credentials, stripeCredentials),
|
|
109
|
+
Effect.map((output) => Option.some(output)),
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
return account;
|
|
113
|
+
}),
|
|
114
|
+
|
|
115
|
+
update: Effect.fn("StripeAccountLifecycleService.update")(function* (
|
|
116
|
+
input: StripeAccountUpdateProps,
|
|
117
|
+
) {
|
|
118
|
+
const account = yield* PostV2CoreAccountsId(input, {
|
|
119
|
+
apiVersion: StripeApiVersion.Dahlia,
|
|
120
|
+
}).pipe(Effect.provideService(Credentials, stripeCredentials));
|
|
121
|
+
|
|
122
|
+
return account;
|
|
123
|
+
}),
|
|
124
|
+
|
|
125
|
+
close: Effect.fn("StripeAccountLifecycleService.close")(function* (
|
|
126
|
+
accountId: string,
|
|
127
|
+
) {
|
|
128
|
+
const input: PostV2CoreAccountsIdCloseInput = {
|
|
129
|
+
id: accountId,
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
yield* PostV2CoreAccountsIdClose(input, {
|
|
133
|
+
apiVersion: StripeApiVersion.Dahlia,
|
|
134
|
+
}).pipe(Effect.provideService(Credentials, stripeCredentials));
|
|
135
|
+
}),
|
|
136
|
+
};
|
|
137
|
+
}),
|
|
138
|
+
},
|
|
139
|
+
) {}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { Context, Effect, FileSystem, Schema } from "effect";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
annotateResourceSchema,
|
|
5
|
+
ResourceOutputRefSchema,
|
|
6
|
+
} from "../../core/model.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Runtime applications read this document after Nomoss has applied the Stripe
|
|
10
|
+
* catalog. The document stores concrete Stripe ids instead of declaration-time
|
|
11
|
+
* refs, so backend and website code can load billing configuration without
|
|
12
|
+
* dashboard lookups or hardcoded environment ids.
|
|
13
|
+
*/
|
|
14
|
+
export const StripeBillingConfigurationExportDocumentSchema = Schema.Struct({
|
|
15
|
+
apiVersion: Schema.String,
|
|
16
|
+
billingPortalConfigurationId: Schema.String,
|
|
17
|
+
mode: Schema.Literals(["test", "live"]),
|
|
18
|
+
prices: Schema.Struct({
|
|
19
|
+
activeMonthly: Schema.String,
|
|
20
|
+
advancedMonthly: Schema.String,
|
|
21
|
+
starterMonthly: Schema.String,
|
|
22
|
+
}),
|
|
23
|
+
products: Schema.Struct({
|
|
24
|
+
active: Schema.String,
|
|
25
|
+
advanced: Schema.String,
|
|
26
|
+
starter: Schema.String,
|
|
27
|
+
}),
|
|
28
|
+
webhookEndpoint: Schema.Struct({
|
|
29
|
+
id: Schema.String,
|
|
30
|
+
}),
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
export type StripeBillingConfigurationExportDocument = Schema.Schema.Type<
|
|
34
|
+
typeof StripeBillingConfigurationExportDocumentSchema
|
|
35
|
+
>;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Export declarations keep Price refs until apply because Stripe generates
|
|
39
|
+
* Price ids during resource creation. The resource policy resolves these refs
|
|
40
|
+
* from saved Nomoss state after dependent resources have applied.
|
|
41
|
+
*/
|
|
42
|
+
export const StripeBillingConfigurationExportReferenceSetSchema = Schema.Struct(
|
|
43
|
+
{
|
|
44
|
+
activeMonthly: ResourceOutputRefSchema,
|
|
45
|
+
advancedMonthly: ResourceOutputRefSchema,
|
|
46
|
+
starterMonthly: ResourceOutputRefSchema,
|
|
47
|
+
},
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
export const StripeBillingConfigurationExportWebhookEndpointReferenceSetSchema =
|
|
51
|
+
Schema.Struct({
|
|
52
|
+
id: ResourceOutputRefSchema,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
export const StripeBillingConfigurationExportProductReferenceSetSchema =
|
|
56
|
+
Schema.Struct({
|
|
57
|
+
active: ResourceOutputRefSchema,
|
|
58
|
+
advanced: ResourceOutputRefSchema,
|
|
59
|
+
starter: ResourceOutputRefSchema,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The export resource participates in the dependency graph through refs while
|
|
64
|
+
* the written file remains a plain runtime configuration document. The stack
|
|
65
|
+
* planner can therefore order the export after Product, Price, and Portal
|
|
66
|
+
* resources.
|
|
67
|
+
*/
|
|
68
|
+
export const StripeBillingConfigurationExportPropsSchema =
|
|
69
|
+
annotateResourceSchema(
|
|
70
|
+
Schema.Struct({
|
|
71
|
+
apiVersion: Schema.String,
|
|
72
|
+
billingPortalConfigurationId: ResourceOutputRefSchema,
|
|
73
|
+
mode: Schema.Literals(["test", "live"]),
|
|
74
|
+
outputPath: Schema.NonEmptyString,
|
|
75
|
+
prices: StripeBillingConfigurationExportReferenceSetSchema,
|
|
76
|
+
products: StripeBillingConfigurationExportProductReferenceSetSchema,
|
|
77
|
+
webhookEndpoint:
|
|
78
|
+
StripeBillingConfigurationExportWebhookEndpointReferenceSetSchema,
|
|
79
|
+
}),
|
|
80
|
+
{
|
|
81
|
+
provider: "stripe",
|
|
82
|
+
service: "billing",
|
|
83
|
+
resource: "configuration-export",
|
|
84
|
+
operation: "create",
|
|
85
|
+
stateSecretOutputKeys: [],
|
|
86
|
+
},
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
export type StripeBillingConfigurationExportProps = Schema.Schema.Type<
|
|
90
|
+
typeof StripeBillingConfigurationExportPropsSchema
|
|
91
|
+
>;
|
|
92
|
+
|
|
93
|
+
export const StripeBillingConfigurationExportResolvedPropsSchema =
|
|
94
|
+
annotateResourceSchema(
|
|
95
|
+
Schema.Struct({
|
|
96
|
+
apiVersion: Schema.String,
|
|
97
|
+
billingPortalConfigurationId: Schema.String,
|
|
98
|
+
mode: Schema.Literals(["test", "live"]),
|
|
99
|
+
outputPath: Schema.NonEmptyString,
|
|
100
|
+
prices: StripeBillingConfigurationExportDocumentSchema.fields.prices,
|
|
101
|
+
products: StripeBillingConfigurationExportDocumentSchema.fields.products,
|
|
102
|
+
webhookEndpoint:
|
|
103
|
+
StripeBillingConfigurationExportDocumentSchema.fields.webhookEndpoint,
|
|
104
|
+
}),
|
|
105
|
+
{
|
|
106
|
+
provider: "stripe",
|
|
107
|
+
service: "billing",
|
|
108
|
+
resource: "configuration-export",
|
|
109
|
+
operation: "create",
|
|
110
|
+
stateSecretOutputKeys: [],
|
|
111
|
+
},
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
export type StripeBillingConfigurationExportResolvedProps = Schema.Schema.Type<
|
|
115
|
+
typeof StripeBillingConfigurationExportResolvedPropsSchema
|
|
116
|
+
>;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* The filesystem lifecycle receives only the final document and output path.
|
|
120
|
+
* The resource policy resolves refs before file writing, so this lifecycle does
|
|
121
|
+
* not depend on Nomoss graph or state services.
|
|
122
|
+
*/
|
|
123
|
+
export const StripeBillingConfigurationExportWriteInputSchema = Schema.Struct({
|
|
124
|
+
document: StripeBillingConfigurationExportDocumentSchema,
|
|
125
|
+
outputPath: Schema.NonEmptyString,
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
export type StripeBillingConfigurationExportWriteInput = Schema.Schema.Type<
|
|
129
|
+
typeof StripeBillingConfigurationExportWriteInputSchema
|
|
130
|
+
>;
|
|
131
|
+
|
|
132
|
+
export const StripeBillingConfigurationExportOutputsSchema = Schema.Struct({
|
|
133
|
+
OutputPath: Schema.String,
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
export type StripeBillingConfigurationExportOutputs = Schema.Schema.Type<
|
|
137
|
+
typeof StripeBillingConfigurationExportOutputsSchema
|
|
138
|
+
>;
|
|
139
|
+
|
|
140
|
+
const StripeBillingConfigurationExportFileSchema = Schema.fromJsonString(
|
|
141
|
+
StripeBillingConfigurationExportDocumentSchema,
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* This lifecycle writes the already-resolved billing configuration artifact.
|
|
146
|
+
* The provider policy is responsible for turning Nomoss resource refs into
|
|
147
|
+
* concrete ids before calling this filesystem lifecycle.
|
|
148
|
+
*/
|
|
149
|
+
export class StripeBillingConfigurationExportLifecycle extends Context.Service<StripeBillingConfigurationExportLifecycle>()(
|
|
150
|
+
"nomoss/providers/stripe/stripeBillingConfigurationExport/StripeBillingConfigurationExportLifecycle",
|
|
151
|
+
{
|
|
152
|
+
make: Effect.gen(function* () {
|
|
153
|
+
const fs = yield* FileSystem.FileSystem;
|
|
154
|
+
|
|
155
|
+
return {
|
|
156
|
+
writeBillingConfigurationExport: Effect.fn(
|
|
157
|
+
"StripeBillingConfigurationExportLifecycle.writeBillingConfigurationExport",
|
|
158
|
+
)(function* (props: StripeBillingConfigurationExportWriteInput) {
|
|
159
|
+
const encoded = yield* Schema.encodeEffect(
|
|
160
|
+
StripeBillingConfigurationExportFileSchema,
|
|
161
|
+
)(props.document);
|
|
162
|
+
|
|
163
|
+
yield* fs.writeFileString(props.outputPath, encoded);
|
|
164
|
+
|
|
165
|
+
const outputs: StripeBillingConfigurationExportOutputs = {
|
|
166
|
+
OutputPath: props.outputPath,
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
return outputs;
|
|
170
|
+
}),
|
|
171
|
+
|
|
172
|
+
deleteBillingConfigurationExport: Effect.fn(
|
|
173
|
+
"StripeBillingConfigurationExportLifecycle.deleteBillingConfigurationExport",
|
|
174
|
+
)(function* (outputPath: string) {
|
|
175
|
+
yield* Effect.when(fs.remove(outputPath), fs.exists(outputPath));
|
|
176
|
+
}),
|
|
177
|
+
};
|
|
178
|
+
}),
|
|
179
|
+
},
|
|
180
|
+
) {}
|