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.
Files changed (81) hide show
  1. package/LICENSE +19 -0
  2. package/README.md +45 -0
  3. package/bin/nomoss +13 -0
  4. package/docs/code-documentation.md +36 -0
  5. package/docs/effect-native-development.md +55 -0
  6. package/docs/engine-design.md +93 -0
  7. package/docs/linting.md +88 -0
  8. package/docs/releasing.md +13 -0
  9. package/docs/resource-command-policy-stage.md +71 -0
  10. package/docs/resource-graph-mvp.md +31 -0
  11. package/docs/resource-graph-testing-approach.md +11 -0
  12. package/docs/resource-lifecycle-tracker.md +93 -0
  13. package/docs/testing.md +86 -0
  14. package/examples/upload-events/README.md +41 -0
  15. package/media/nomoss.gif +0 -0
  16. package/package.json +64 -0
  17. package/src/cli.ts +18 -0
  18. package/src/cliCommand.ts +186 -0
  19. package/src/cliRuntimeLayer.ts +49 -0
  20. package/src/core/index.ts +17 -0
  21. package/src/core/lifecycle.ts +127 -0
  22. package/src/core/model.ts +229 -0
  23. package/src/core/physicalNameStore.ts +226 -0
  24. package/src/core/planner.ts +645 -0
  25. package/src/core/resourceCommandPolicy.ts +79 -0
  26. package/src/core/resourceGraphBuilder.ts +167 -0
  27. package/src/core/resourceGraphStore.ts +288 -0
  28. package/src/core/resourceOutputResolver.ts +185 -0
  29. package/src/core/resourcePolicy.ts +77 -0
  30. package/src/core/resourceStackDefinition.ts +17 -0
  31. package/src/core/resourceStackLifecycle.ts +456 -0
  32. package/src/core/resourceStackOperations.ts +129 -0
  33. package/src/core/runtimeLayer.ts +73 -0
  34. package/src/core/stackWorkflowRenderer.ts +239 -0
  35. package/src/core/stateSecretService.ts +553 -0
  36. package/src/core/stateStore.ts +652 -0
  37. package/src/core/tracing.ts +26 -0
  38. package/src/index.ts +2 -0
  39. package/src/providers/aws/awsApply.ts +132 -0
  40. package/src/providers/aws/awsBucket.ts +329 -0
  41. package/src/providers/aws/awsBucketNotification.ts +351 -0
  42. package/src/providers/aws/awsBucketNotificationResourcePolicy.ts +251 -0
  43. package/src/providers/aws/awsBucketResourcePolicy.ts +198 -0
  44. package/src/providers/aws/awsProviderLayer.ts +274 -0
  45. package/src/providers/aws/awsQueue.ts +346 -0
  46. package/src/providers/aws/awsQueuePolicy.ts +419 -0
  47. package/src/providers/aws/awsQueuePolicyResourcePolicy.ts +215 -0
  48. package/src/providers/aws/awsQueueResourcePolicy.ts +270 -0
  49. package/src/providers/aws/awsReconciliation.ts +92 -0
  50. package/src/providers/aws/awsRefresh.ts +50 -0
  51. package/src/providers/aws/awsResourceLifecycle.ts +118 -0
  52. package/src/providers/aws/awsResourcePolicy.ts +83 -0
  53. package/src/providers/aws/awsResources.ts +274 -0
  54. package/src/providers/aws/awsRuntimeLayer.ts +21 -0
  55. package/src/providers/aws/awsSqsTransport.ts +33 -0
  56. package/src/providers/aws/awsStackLifecycle.ts +272 -0
  57. package/src/providers/aws/awsTagging.ts +186 -0
  58. package/src/providers/aws/constants.ts +3 -0
  59. package/src/providers/aws/index.ts +22 -0
  60. package/src/providers/aws/sampleStack.ts +65 -0
  61. package/src/providers/aws/stackWorkflow.ts +443 -0
  62. package/src/providers/index.ts +5 -0
  63. package/src/providers/provider.ts +5 -0
  64. package/src/providers/providerRuntimeLayer.ts +121 -0
  65. package/src/providers/resourceCommandPolicyLayer.ts +240 -0
  66. package/src/providers/stripe/index.ts +15 -0
  67. package/src/providers/stripe/stripeAccount.ts +139 -0
  68. package/src/providers/stripe/stripeBillingConfigurationExport.ts +180 -0
  69. package/src/providers/stripe/stripeBillingConfigurationExportResourcePolicy.ts +178 -0
  70. package/src/providers/stripe/stripeBillingPortalConfiguration.ts +153 -0
  71. package/src/providers/stripe/stripeBillingPortalConfigurationResourcePolicy.ts +177 -0
  72. package/src/providers/stripe/stripeCustomer.ts +148 -0
  73. package/src/providers/stripe/stripeCustomerResourcePolicy.ts +160 -0
  74. package/src/providers/stripe/stripePrice.ts +218 -0
  75. package/src/providers/stripe/stripePriceResourcePolicy.ts +151 -0
  76. package/src/providers/stripe/stripeProduct.ts +171 -0
  77. package/src/providers/stripe/stripeProductResourcePolicy.ts +161 -0
  78. package/src/providers/stripe/stripeResources.ts +454 -0
  79. package/src/providers/stripe/stripeRuntimeLayer.ts +131 -0
  80. package/src/providers/stripe/stripeWebhookEndpoint.ts +293 -0
  81. package/src/providers/stripe/stripeWebhookEndpointResourcePolicy.ts +198 -0
@@ -0,0 +1,178 @@
1
+ import { Context, Effect, Match } from "effect";
2
+
3
+ import {
4
+ type PlanDecision,
5
+ ResourceCommand,
6
+ ResourceCommandResult,
7
+ ResourceCommandUnsupported,
8
+ } from "../../core/lifecycle.js";
9
+ import {
10
+ ResourceModel,
11
+ type ResourceNode,
12
+ readResourceSchemaAnnotation,
13
+ } from "../../core/model.js";
14
+ import {
15
+ type StripeBillingConfigurationExportDocument,
16
+ StripeBillingConfigurationExportLifecycle,
17
+ type StripeBillingConfigurationExportOutputs,
18
+ StripeBillingConfigurationExportOutputsSchema,
19
+ StripeBillingConfigurationExportPropsSchema,
20
+ StripeBillingConfigurationExportResolvedPropsSchema,
21
+ } from "./stripeBillingConfigurationExport.js";
22
+
23
+ /**
24
+ * The export policy receives props after core lifecycle has resolved resource
25
+ * refs, then writes the runtime billing document consumed by application code.
26
+ */
27
+ export class StripeBillingConfigurationExportResourcePolicy extends Context.Service<StripeBillingConfigurationExportResourcePolicy>()(
28
+ "nomoss/providers/stripe/stripeBillingConfigurationExportResourcePolicy",
29
+ {
30
+ make: Effect.gen(function* () {
31
+ const lifecycle = yield* StripeBillingConfigurationExportLifecycle;
32
+ const model = yield* ResourceModel;
33
+ const schema = yield* readResourceSchemaAnnotation(
34
+ StripeBillingConfigurationExportPropsSchema,
35
+ ).pipe(Effect.fromOption);
36
+
37
+ const resourceNode = Effect.fn(
38
+ "StripeBillingConfigurationExportResourcePolicy.resourceNode",
39
+ )(function* (
40
+ node: ResourceNode,
41
+ outputs: StripeBillingConfigurationExportOutputs,
42
+ ) {
43
+ const props = yield* model.decodeProps(
44
+ node,
45
+ StripeBillingConfigurationExportResolvedPropsSchema,
46
+ );
47
+ const appliedNode = yield* model.nodeFromResource({
48
+ key: node.key,
49
+ propsSchema: StripeBillingConfigurationExportResolvedPropsSchema,
50
+ outputsSchema: StripeBillingConfigurationExportOutputsSchema,
51
+ props,
52
+ outputs,
53
+ });
54
+
55
+ return appliedNode;
56
+ });
57
+
58
+ const create = Effect.fn(
59
+ "StripeBillingConfigurationExportResourcePolicy.create",
60
+ )(function* (node: ResourceNode) {
61
+ const props = yield* model.decodeProps(
62
+ node,
63
+ StripeBillingConfigurationExportResolvedPropsSchema,
64
+ );
65
+ const document: StripeBillingConfigurationExportDocument = {
66
+ apiVersion: props.apiVersion,
67
+ billingPortalConfigurationId: props.billingPortalConfigurationId,
68
+ mode: props.mode,
69
+ prices: props.prices,
70
+ products: props.products,
71
+ webhookEndpoint: props.webhookEndpoint,
72
+ };
73
+ const outputs = yield* lifecycle.writeBillingConfigurationExport({
74
+ document,
75
+ outputPath: props.outputPath,
76
+ });
77
+ const appliedNode = yield* resourceNode(node, outputs);
78
+
79
+ return ResourceCommandResult.Created({ node: appliedNode });
80
+ });
81
+
82
+ const update = Effect.fn(
83
+ "StripeBillingConfigurationExportResourcePolicy.update",
84
+ )(function* (node: ResourceNode) {
85
+ const props = yield* model.decodeProps(
86
+ node,
87
+ StripeBillingConfigurationExportResolvedPropsSchema,
88
+ );
89
+ const document: StripeBillingConfigurationExportDocument = {
90
+ apiVersion: props.apiVersion,
91
+ billingPortalConfigurationId: props.billingPortalConfigurationId,
92
+ mode: props.mode,
93
+ prices: props.prices,
94
+ products: props.products,
95
+ webhookEndpoint: props.webhookEndpoint,
96
+ };
97
+ const outputs = yield* lifecycle.writeBillingConfigurationExport({
98
+ document,
99
+ outputPath: props.outputPath,
100
+ });
101
+ const appliedNode = yield* resourceNode(node, outputs);
102
+
103
+ return ResourceCommandResult.Updated({ node: appliedNode });
104
+ });
105
+
106
+ const destroy = Effect.fn(
107
+ "StripeBillingConfigurationExportResourcePolicy.destroy",
108
+ )(function* (node: ResourceNode) {
109
+ const outputs = yield* model.decodeOutputs(
110
+ node,
111
+ StripeBillingConfigurationExportOutputsSchema,
112
+ );
113
+
114
+ yield* lifecycle.deleteBillingConfigurationExport(outputs.OutputPath);
115
+
116
+ return ResourceCommandResult.Destroyed({ node });
117
+ });
118
+
119
+ const apply = Effect.fn(
120
+ "StripeBillingConfigurationExportResourcePolicy.apply",
121
+ )(function* (decision: PlanDecision) {
122
+ return yield* Match.value(decision).pipe(
123
+ Match.tagsExhaustive({
124
+ Create: ({ node }) => create(node),
125
+ Update: ({ node }) => update(node),
126
+ Destroy: ({ node }) => destroy(node),
127
+ NoOp: () =>
128
+ Effect.fail(
129
+ new ResourceCommandUnsupported({
130
+ command: ResourceCommand.Apply({ decision }),
131
+ }),
132
+ ),
133
+ Repair: () =>
134
+ Effect.fail(
135
+ new ResourceCommandUnsupported({
136
+ command: ResourceCommand.Apply({ decision }),
137
+ }),
138
+ ),
139
+ Delete: () =>
140
+ Effect.fail(
141
+ new ResourceCommandUnsupported({
142
+ command: ResourceCommand.Apply({ decision }),
143
+ }),
144
+ ),
145
+ }),
146
+ );
147
+ });
148
+
149
+ return {
150
+ schema,
151
+ create,
152
+ update,
153
+ destroy,
154
+ apply,
155
+ execute: Effect.fn(
156
+ "StripeBillingConfigurationExportResourcePolicy.execute",
157
+ )(function* (command: ResourceCommand) {
158
+ return yield* Match.value(command).pipe(
159
+ Match.tagsExhaustive({
160
+ Read: () =>
161
+ Effect.fail(new ResourceCommandUnsupported({ command })),
162
+ Diff: () =>
163
+ Effect.fail(new ResourceCommandUnsupported({ command })),
164
+ Apply: ({ decision }) => apply(decision),
165
+ Create: () =>
166
+ Effect.fail(new ResourceCommandUnsupported({ command })),
167
+ Update: () =>
168
+ Effect.fail(new ResourceCommandUnsupported({ command })),
169
+ Delete: () =>
170
+ Effect.fail(new ResourceCommandUnsupported({ command })),
171
+ Destroy: ({ node }) => destroy(node),
172
+ }),
173
+ );
174
+ }),
175
+ };
176
+ }),
177
+ },
178
+ ) {}
@@ -0,0 +1,153 @@
1
+ import { Credentials } from "@distilled.cloud/stripe";
2
+ import type { GetBillingPortalConfigurationsConfigurationInput } from "@distilled.cloud/stripe/Operations";
3
+ import {
4
+ GetBillingPortalConfigurationsConfiguration,
5
+ PostBillingPortalConfigurations,
6
+ PostBillingPortalConfigurationsConfiguration,
7
+ PostBillingPortalConfigurationsConfigurationInput,
8
+ PostBillingPortalConfigurationsInput,
9
+ PostBillingPortalConfigurationsOutput,
10
+ } from "@distilled.cloud/stripe/Operations";
11
+ import { Context, Effect, Option, Schema } from "effect";
12
+
13
+ import {
14
+ annotateResourceSchema,
15
+ ResourceOutputRefSchema,
16
+ } from "../../core/model.js";
17
+ import { StripeApiVersion } from "./stripeAccount.js";
18
+
19
+ export const StripeBillingPortalConfigurationPropsSchema =
20
+ annotateResourceSchema(PostBillingPortalConfigurationsInput, {
21
+ provider: "stripe",
22
+ service: "billing",
23
+ resource: "billing-portal-configuration",
24
+ operation: "create",
25
+ stateSecretOutputKeys: [],
26
+ });
27
+
28
+ export type StripeBillingPortalConfigurationProps = Schema.Schema.Type<
29
+ typeof StripeBillingPortalConfigurationPropsSchema
30
+ >;
31
+
32
+ export const StripeBillingPortalConfigurationSubscriptionUpdateProductDeclarationSchema =
33
+ Schema.Struct({
34
+ prices: Schema.Array(ResourceOutputRefSchema),
35
+ product: ResourceOutputRefSchema,
36
+ });
37
+
38
+ export type StripeBillingPortalConfigurationSubscriptionUpdateProductDeclaration =
39
+ Schema.Schema.Type<
40
+ typeof StripeBillingPortalConfigurationSubscriptionUpdateProductDeclarationSchema
41
+ >;
42
+
43
+ export const StripeBillingPortalConfigurationUpdatePropsSchema =
44
+ PostBillingPortalConfigurationsConfigurationInput;
45
+
46
+ export type StripeBillingPortalConfigurationUpdateProps = Schema.Schema.Type<
47
+ typeof StripeBillingPortalConfigurationUpdatePropsSchema
48
+ >;
49
+
50
+ export const StripeBillingPortalConfigurationOutputsSchema = Schema.Struct({
51
+ BillingPortalConfigurationId: Schema.String,
52
+ });
53
+
54
+ export type StripeBillingPortalConfigurationOutputs = Schema.Schema.Type<
55
+ typeof StripeBillingPortalConfigurationOutputsSchema
56
+ >;
57
+
58
+ export const StripeBillingPortalConfigurationObservedStateSchema =
59
+ PostBillingPortalConfigurationsOutput;
60
+
61
+ export type StripeBillingPortalConfigurationObservedState = Schema.Schema.Type<
62
+ typeof StripeBillingPortalConfigurationObservedStateSchema
63
+ >;
64
+
65
+ export const stripeBillingPortalConfigurationOutputsFromState = (
66
+ state: StripeBillingPortalConfigurationObservedState,
67
+ ): StripeBillingPortalConfigurationOutputs => {
68
+ const outputs: StripeBillingPortalConfigurationOutputs = {
69
+ BillingPortalConfigurationId: state.id,
70
+ };
71
+
72
+ return outputs;
73
+ };
74
+
75
+ export const pendingStripeBillingPortalConfigurationOutputs = (
76
+ logicalId: string,
77
+ ): StripeBillingPortalConfigurationOutputs => {
78
+ const outputs: StripeBillingPortalConfigurationOutputs = {
79
+ BillingPortalConfigurationId: `nomoss:pending:stripe-billing-portal-configuration-id:${logicalId}`,
80
+ };
81
+
82
+ return outputs;
83
+ };
84
+
85
+ export class StripeBillingPortalConfigurationLifecycle extends Context.Service<StripeBillingPortalConfigurationLifecycle>()(
86
+ "nomoss/providers/stripe/stripeBillingPortalConfiguration/StripeBillingPortalConfigurationLifecycle",
87
+ {
88
+ make: Effect.gen(function* () {
89
+ const stripeCredentials = yield* Credentials;
90
+
91
+ return {
92
+ createBillingPortalConfiguration: Effect.fn(
93
+ "StripeBillingPortalConfigurationLifecycle.createBillingPortalConfiguration",
94
+ )(function* (props: StripeBillingPortalConfigurationProps) {
95
+ const configuration = yield* PostBillingPortalConfigurations(props, {
96
+ apiVersion: StripeApiVersion.Dahlia,
97
+ }).pipe(Effect.provideService(Credentials, stripeCredentials));
98
+
99
+ return configuration;
100
+ }),
101
+
102
+ readBillingPortalConfiguration: Effect.fn(
103
+ "StripeBillingPortalConfigurationLifecycle.readBillingPortalConfiguration",
104
+ )(function* (configurationId: string) {
105
+ const input: GetBillingPortalConfigurationsConfigurationInput = {
106
+ configuration: configurationId,
107
+ };
108
+ const configuration =
109
+ yield* GetBillingPortalConfigurationsConfiguration(input, {
110
+ apiVersion: StripeApiVersion.Dahlia,
111
+ }).pipe(
112
+ Effect.provideService(Credentials, stripeCredentials),
113
+ Effect.flatMap((output) =>
114
+ Schema.decodeUnknownEffect(
115
+ StripeBillingPortalConfigurationObservedStateSchema,
116
+ )(output),
117
+ ),
118
+ Effect.map((output) => Option.some(output)),
119
+ );
120
+
121
+ return configuration;
122
+ }),
123
+
124
+ updateBillingPortalConfiguration: Effect.fn(
125
+ "StripeBillingPortalConfigurationLifecycle.updateBillingPortalConfiguration",
126
+ )(function* (input: StripeBillingPortalConfigurationUpdateProps) {
127
+ const configuration =
128
+ yield* PostBillingPortalConfigurationsConfiguration(input, {
129
+ apiVersion: StripeApiVersion.Dahlia,
130
+ }).pipe(Effect.provideService(Credentials, stripeCredentials));
131
+
132
+ return configuration;
133
+ }),
134
+
135
+ deactivateBillingPortalConfiguration: Effect.fn(
136
+ "StripeBillingPortalConfigurationLifecycle.deactivateBillingPortalConfiguration",
137
+ )(function* (configurationId: string) {
138
+ const input =
139
+ yield* StripeBillingPortalConfigurationUpdatePropsSchema.makeEffect(
140
+ {
141
+ active: false,
142
+ configuration: configurationId,
143
+ },
144
+ );
145
+
146
+ yield* PostBillingPortalConfigurationsConfiguration(input, {
147
+ apiVersion: StripeApiVersion.Dahlia,
148
+ }).pipe(Effect.provideService(Credentials, stripeCredentials));
149
+ }),
150
+ };
151
+ }),
152
+ },
153
+ ) {}
@@ -0,0 +1,177 @@
1
+ import { Context, Effect, Match } from "effect";
2
+
3
+ import {
4
+ type PlanDecision,
5
+ ResourceCommand,
6
+ ResourceCommandResult,
7
+ ResourceCommandUnsupported,
8
+ } from "../../core/lifecycle.js";
9
+ import {
10
+ ResourceModel,
11
+ type ResourceNode,
12
+ readResourceSchemaAnnotation,
13
+ } from "../../core/model.js";
14
+ import {
15
+ StripeBillingPortalConfigurationLifecycle,
16
+ type StripeBillingPortalConfigurationOutputs,
17
+ StripeBillingPortalConfigurationOutputsSchema,
18
+ StripeBillingPortalConfigurationPropsSchema,
19
+ StripeBillingPortalConfigurationUpdatePropsSchema,
20
+ stripeBillingPortalConfigurationOutputsFromState,
21
+ } from "./stripeBillingPortalConfiguration.js";
22
+
23
+ /**
24
+ * Billing Portal configuration commands let applications create customer
25
+ * self-service policy through Nomoss instead of Stripe Dashboard setup.
26
+ */
27
+ export class StripeBillingPortalConfigurationResourcePolicy extends Context.Service<StripeBillingPortalConfigurationResourcePolicy>()(
28
+ "nomoss/providers/stripe/stripeBillingPortalConfigurationResourcePolicy",
29
+ {
30
+ make: Effect.gen(function* () {
31
+ const lifecycle = yield* StripeBillingPortalConfigurationLifecycle;
32
+ const model = yield* ResourceModel;
33
+ const schema = yield* readResourceSchemaAnnotation(
34
+ StripeBillingPortalConfigurationPropsSchema,
35
+ ).pipe(Effect.fromOption);
36
+
37
+ const resourceNode = Effect.fn(
38
+ "StripeBillingPortalConfigurationResourcePolicy.resourceNode",
39
+ )(function* (
40
+ node: ResourceNode,
41
+ outputs: StripeBillingPortalConfigurationOutputs,
42
+ ) {
43
+ const props = yield* model.decodeProps(
44
+ node,
45
+ StripeBillingPortalConfigurationPropsSchema,
46
+ );
47
+ const appliedNode = yield* model.nodeFromResource({
48
+ key: node.key,
49
+ propsSchema: StripeBillingPortalConfigurationPropsSchema,
50
+ outputsSchema: StripeBillingPortalConfigurationOutputsSchema,
51
+ props,
52
+ outputs,
53
+ });
54
+
55
+ return appliedNode;
56
+ });
57
+
58
+ const create = Effect.fn(
59
+ "StripeBillingPortalConfigurationResourcePolicy.create",
60
+ )(function* (node: ResourceNode) {
61
+ const props = yield* model.decodeProps(
62
+ node,
63
+ StripeBillingPortalConfigurationPropsSchema,
64
+ );
65
+ const configuration =
66
+ yield* lifecycle.createBillingPortalConfiguration(props);
67
+ const outputs =
68
+ stripeBillingPortalConfigurationOutputsFromState(configuration);
69
+ const appliedNode = yield* resourceNode(node, outputs);
70
+
71
+ return ResourceCommandResult.Created({ node: appliedNode });
72
+ });
73
+
74
+ const update = Effect.fn(
75
+ "StripeBillingPortalConfigurationResourcePolicy.update",
76
+ )(function* (node: ResourceNode, current: ResourceNode) {
77
+ const props = yield* model.decodeProps(
78
+ node,
79
+ StripeBillingPortalConfigurationPropsSchema,
80
+ );
81
+ const currentOutputs = yield* model.decodeOutputs(
82
+ current,
83
+ StripeBillingPortalConfigurationOutputsSchema,
84
+ );
85
+ const input =
86
+ yield* StripeBillingPortalConfigurationUpdatePropsSchema.makeEffect({
87
+ business_profile: props.business_profile,
88
+ configuration: currentOutputs.BillingPortalConfigurationId,
89
+ default_return_url: props.default_return_url,
90
+ features: props.features,
91
+ login_page: props.login_page,
92
+ metadata: props.metadata,
93
+ name: props.name,
94
+ });
95
+ const configuration =
96
+ yield* lifecycle.updateBillingPortalConfiguration(input);
97
+ const outputs =
98
+ stripeBillingPortalConfigurationOutputsFromState(configuration);
99
+ const appliedNode = yield* resourceNode(node, outputs);
100
+
101
+ return ResourceCommandResult.Updated({ node: appliedNode });
102
+ });
103
+
104
+ const destroy = Effect.fn(
105
+ "StripeBillingPortalConfigurationResourcePolicy.destroy",
106
+ )(function* (node: ResourceNode) {
107
+ const outputs = yield* model.decodeOutputs(
108
+ node,
109
+ StripeBillingPortalConfigurationOutputsSchema,
110
+ );
111
+
112
+ yield* lifecycle.deactivateBillingPortalConfiguration(
113
+ outputs.BillingPortalConfigurationId,
114
+ );
115
+
116
+ return ResourceCommandResult.Destroyed({ node });
117
+ });
118
+
119
+ const apply = Effect.fn(
120
+ "StripeBillingPortalConfigurationResourcePolicy.apply",
121
+ )(function* (decision: PlanDecision) {
122
+ return yield* Match.value(decision).pipe(
123
+ Match.tagsExhaustive({
124
+ Create: ({ node }) => create(node),
125
+ Update: ({ node, current }) => update(node, current),
126
+ Destroy: ({ node }) => destroy(node),
127
+ NoOp: () =>
128
+ Effect.fail(
129
+ new ResourceCommandUnsupported({
130
+ command: ResourceCommand.Apply({ decision }),
131
+ }),
132
+ ),
133
+ Repair: () =>
134
+ Effect.fail(
135
+ new ResourceCommandUnsupported({
136
+ command: ResourceCommand.Apply({ decision }),
137
+ }),
138
+ ),
139
+ Delete: () =>
140
+ Effect.fail(
141
+ new ResourceCommandUnsupported({
142
+ command: ResourceCommand.Apply({ decision }),
143
+ }),
144
+ ),
145
+ }),
146
+ );
147
+ });
148
+
149
+ return {
150
+ schema,
151
+ create,
152
+ update,
153
+ destroy,
154
+ apply,
155
+ execute: Effect.fn(
156
+ "StripeBillingPortalConfigurationResourcePolicy.execute",
157
+ )(function* (command: ResourceCommand) {
158
+ return yield* Match.value(command).pipe(
159
+ Match.tagsExhaustive({
160
+ Read: () =>
161
+ Effect.fail(new ResourceCommandUnsupported({ command })),
162
+ Diff: () =>
163
+ Effect.fail(new ResourceCommandUnsupported({ command })),
164
+ Apply: ({ decision }) => apply(decision),
165
+ Create: ({ node }) => create(node),
166
+ Update: () =>
167
+ Effect.fail(new ResourceCommandUnsupported({ command })),
168
+ Delete: () =>
169
+ Effect.fail(new ResourceCommandUnsupported({ command })),
170
+ Destroy: ({ node }) => destroy(node),
171
+ }),
172
+ );
173
+ }),
174
+ };
175
+ }),
176
+ },
177
+ ) {}
@@ -0,0 +1,148 @@
1
+ import { Credentials } from "@distilled.cloud/stripe";
2
+ import type {
3
+ DeleteCustomersCustomerInput,
4
+ GetCustomersCustomerInput,
5
+ } from "@distilled.cloud/stripe/Operations";
6
+ import {
7
+ DeleteCustomersCustomer,
8
+ GetCustomersCustomer,
9
+ PostCustomers,
10
+ PostCustomersCustomer,
11
+ PostCustomersCustomerInput as PostCustomersCustomerInputSchema,
12
+ PostCustomersInput,
13
+ PostCustomersOutput,
14
+ } from "@distilled.cloud/stripe/Operations";
15
+ import { type Cause, Context, Data, Effect, Option, Schema } from "effect";
16
+
17
+ import { annotateResourceSchema } from "../../core/model.js";
18
+ import { StripeApiVersion } from "./stripeAccount.js";
19
+
20
+ export const StripeCustomerPropsSchema = annotateResourceSchema(
21
+ PostCustomersInput,
22
+ {
23
+ provider: "stripe",
24
+ service: "billing",
25
+ resource: "customer",
26
+ operation: "create",
27
+ stateSecretOutputKeys: [],
28
+ },
29
+ );
30
+
31
+ export type StripeCustomerProps = Schema.Schema.Type<
32
+ typeof StripeCustomerPropsSchema
33
+ >;
34
+
35
+ export const StripeCustomerUpdatePropsSchema = PostCustomersCustomerInputSchema;
36
+
37
+ export type StripeCustomerUpdateProps = Schema.Schema.Type<
38
+ typeof StripeCustomerUpdatePropsSchema
39
+ >;
40
+
41
+ export const StripeCustomerOutputsSchema = Schema.Struct({
42
+ CustomerId: Schema.String,
43
+ });
44
+
45
+ export type StripeCustomerOutputs = Schema.Schema.Type<
46
+ typeof StripeCustomerOutputsSchema
47
+ >;
48
+
49
+ export const StripeCustomerObservedStateSchema = PostCustomersOutput;
50
+
51
+ export type StripeCustomerObservedState = Schema.Schema.Type<
52
+ typeof StripeCustomerObservedStateSchema
53
+ >;
54
+
55
+ export const stripeCustomerOutputsFromState = (
56
+ state: StripeCustomerObservedState,
57
+ ): StripeCustomerOutputs => {
58
+ const outputs: StripeCustomerOutputs = {
59
+ CustomerId: state.id,
60
+ };
61
+
62
+ return outputs;
63
+ };
64
+
65
+ export class StripeCustomerCreateFailed extends Data.TaggedError(
66
+ "StripeCustomerCreateFailed",
67
+ )<{
68
+ readonly cause: Cause.Cause<unknown>;
69
+ }> {}
70
+
71
+ export const pendingStripeCustomerOutputs = (
72
+ logicalId: string,
73
+ ): StripeCustomerOutputs => {
74
+ const outputs: StripeCustomerOutputs = {
75
+ CustomerId: `nomoss:pending:stripe-customer-id:${logicalId}`,
76
+ };
77
+
78
+ return outputs;
79
+ };
80
+
81
+ export class StripeCustomerLifecycle extends Context.Service<StripeCustomerLifecycle>()(
82
+ "nomoss/providers/stripe/stripeCustomer/StripeCustomerLifecycle",
83
+ {
84
+ make: Effect.gen(function* () {
85
+ const stripeCredentials = yield* Credentials;
86
+
87
+ return {
88
+ createCustomer: Effect.fn("StripeCustomerLifecycle/createCustomer")(
89
+ function* (props: StripeCustomerProps) {
90
+ const customer = yield* PostCustomers(props, {
91
+ apiVersion: StripeApiVersion.Dahlia,
92
+ }).pipe(
93
+ Effect.provideService(Credentials, stripeCredentials),
94
+ Effect.catchCause((cause) =>
95
+ Effect.fail(new StripeCustomerCreateFailed({ cause })),
96
+ ),
97
+ );
98
+
99
+ return customer;
100
+ },
101
+ ),
102
+
103
+ readCustomer: Effect.fn("StripeCustomerLifecycle/readCustomer")(
104
+ function* (customerId: string) {
105
+ const input: GetCustomersCustomerInput = {
106
+ customer: customerId,
107
+ };
108
+ const customer = yield* GetCustomersCustomer(input, {
109
+ apiVersion: StripeApiVersion.Dahlia,
110
+ }).pipe(
111
+ Effect.provideService(Credentials, stripeCredentials),
112
+ Effect.flatMap((output) =>
113
+ Schema.decodeUnknownEffect(StripeCustomerObservedStateSchema)(
114
+ output,
115
+ ),
116
+ ),
117
+ Effect.map((output) => Option.some(output)),
118
+ );
119
+
120
+ return customer;
121
+ },
122
+ ),
123
+
124
+ updateCustomer: Effect.fn("StripeCustomerLifecycle/updateCustomer")(
125
+ function* (input: StripeCustomerUpdateProps) {
126
+ const customer = yield* PostCustomersCustomer(input, {
127
+ apiVersion: StripeApiVersion.Dahlia,
128
+ }).pipe(Effect.provideService(Credentials, stripeCredentials));
129
+
130
+ return customer;
131
+ },
132
+ ),
133
+
134
+ deleteCustomer: Effect.fn("StripeCustomerLifecycle/deleteCustomer")(
135
+ function* (customerId: string) {
136
+ const input: DeleteCustomersCustomerInput = {
137
+ customer: customerId,
138
+ };
139
+
140
+ yield* DeleteCustomersCustomer(input, {
141
+ apiVersion: StripeApiVersion.Dahlia,
142
+ }).pipe(Effect.provideService(Credentials, stripeCredentials));
143
+ },
144
+ ),
145
+ };
146
+ }),
147
+ },
148
+ ) {}