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,131 @@
|
|
|
1
|
+
import { CredentialsFromEnv } from "@distilled.cloud/stripe";
|
|
2
|
+
import { Layer } from "effect";
|
|
3
|
+
|
|
4
|
+
import * as FetchHttpClient from "effect/unstable/http/FetchHttpClient";
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
resourceGraphBuilderLayer,
|
|
8
|
+
resourceGraphStoreLayer,
|
|
9
|
+
resourceModelLayer,
|
|
10
|
+
} from "../../core/runtimeLayer.js";
|
|
11
|
+
import { StripeBillingConfigurationExportLifecycle } from "./stripeBillingConfigurationExport.js";
|
|
12
|
+
import { StripeBillingConfigurationExportResourcePolicy } from "./stripeBillingConfigurationExportResourcePolicy.js";
|
|
13
|
+
import { StripeBillingPortalConfigurationLifecycle } from "./stripeBillingPortalConfiguration.js";
|
|
14
|
+
import { StripeBillingPortalConfigurationResourcePolicy } from "./stripeBillingPortalConfigurationResourcePolicy.js";
|
|
15
|
+
import { StripeCustomerLifecycle } from "./stripeCustomer.js";
|
|
16
|
+
import { StripeCustomerResourcePolicy } from "./stripeCustomerResourcePolicy.js";
|
|
17
|
+
import { StripePriceLifecycle } from "./stripePrice.js";
|
|
18
|
+
import { StripePriceResourcePolicy } from "./stripePriceResourcePolicy.js";
|
|
19
|
+
import { StripeProductLifecycle } from "./stripeProduct.js";
|
|
20
|
+
import { StripeProductResourcePolicy } from "./stripeProductResourcePolicy.js";
|
|
21
|
+
import { StripeResources } from "./stripeResources.js";
|
|
22
|
+
import { StripeWebhookEndpointLifecycle } from "./stripeWebhookEndpoint.js";
|
|
23
|
+
import { StripeWebhookEndpointResourcePolicy } from "./stripeWebhookEndpointResourcePolicy.js";
|
|
24
|
+
|
|
25
|
+
const stripeOperationDependenciesLayer = CredentialsFromEnv.pipe(
|
|
26
|
+
Layer.provide(FetchHttpClient.layer),
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Every Stripe provider layer uses the same generated operation credentials and
|
|
31
|
+
* HTTP client. Products, Prices, Portal configuration, webhooks, and exports
|
|
32
|
+
* therefore run through the Nomoss provider graph rather than ad hoc setup
|
|
33
|
+
* scripts.
|
|
34
|
+
*/
|
|
35
|
+
export const stripeCustomerLifecycleLayerLive = Layer.effect(
|
|
36
|
+
StripeCustomerLifecycle,
|
|
37
|
+
StripeCustomerLifecycle.make,
|
|
38
|
+
).pipe(Layer.provideMerge(stripeOperationDependenciesLayer));
|
|
39
|
+
|
|
40
|
+
export const stripeProductLifecycleLayerLive = Layer.effect(
|
|
41
|
+
StripeProductLifecycle,
|
|
42
|
+
StripeProductLifecycle.make,
|
|
43
|
+
).pipe(Layer.provideMerge(stripeOperationDependenciesLayer));
|
|
44
|
+
|
|
45
|
+
export const stripePriceLifecycleLayerLive = Layer.effect(
|
|
46
|
+
StripePriceLifecycle,
|
|
47
|
+
StripePriceLifecycle.make,
|
|
48
|
+
).pipe(Layer.provideMerge(stripeOperationDependenciesLayer));
|
|
49
|
+
|
|
50
|
+
export const stripeWebhookEndpointLifecycleLayerLive = Layer.effect(
|
|
51
|
+
StripeWebhookEndpointLifecycle,
|
|
52
|
+
StripeWebhookEndpointLifecycle.make,
|
|
53
|
+
).pipe(Layer.provideMerge(stripeOperationDependenciesLayer));
|
|
54
|
+
|
|
55
|
+
export const stripeBillingPortalConfigurationLifecycleLayerLive = Layer.effect(
|
|
56
|
+
StripeBillingPortalConfigurationLifecycle,
|
|
57
|
+
StripeBillingPortalConfigurationLifecycle.make,
|
|
58
|
+
).pipe(Layer.provideMerge(stripeOperationDependenciesLayer));
|
|
59
|
+
|
|
60
|
+
export const stripeBillingConfigurationExportLifecycleLayerLive = Layer.effect(
|
|
61
|
+
StripeBillingConfigurationExportLifecycle,
|
|
62
|
+
StripeBillingConfigurationExportLifecycle.make,
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
export const stripeResourcesLayerLive = Layer.effect(
|
|
66
|
+
StripeResources,
|
|
67
|
+
StripeResources.make,
|
|
68
|
+
).pipe(Layer.provideMerge(resourceGraphBuilderLayer));
|
|
69
|
+
|
|
70
|
+
export const stripeCustomerResourcePolicyLayerLive = Layer.effect(
|
|
71
|
+
StripeCustomerResourcePolicy,
|
|
72
|
+
StripeCustomerResourcePolicy.make,
|
|
73
|
+
).pipe(
|
|
74
|
+
Layer.provideMerge(stripeCustomerLifecycleLayerLive),
|
|
75
|
+
Layer.provideMerge(resourceModelLayer),
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
export const stripeProductResourcePolicyLayerLive = Layer.effect(
|
|
79
|
+
StripeProductResourcePolicy,
|
|
80
|
+
StripeProductResourcePolicy.make,
|
|
81
|
+
).pipe(
|
|
82
|
+
Layer.provideMerge(stripeProductLifecycleLayerLive),
|
|
83
|
+
Layer.provideMerge(resourceModelLayer),
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
export const stripePriceResourcePolicyLayerLive = Layer.effect(
|
|
87
|
+
StripePriceResourcePolicy,
|
|
88
|
+
StripePriceResourcePolicy.make,
|
|
89
|
+
).pipe(
|
|
90
|
+
Layer.provideMerge(stripePriceLifecycleLayerLive),
|
|
91
|
+
Layer.provideMerge(resourceModelLayer),
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
export const stripeWebhookEndpointResourcePolicyLayerLive = Layer.effect(
|
|
95
|
+
StripeWebhookEndpointResourcePolicy,
|
|
96
|
+
StripeWebhookEndpointResourcePolicy.make,
|
|
97
|
+
).pipe(
|
|
98
|
+
Layer.provideMerge(stripeWebhookEndpointLifecycleLayerLive),
|
|
99
|
+
Layer.provideMerge(resourceModelLayer),
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
export const stripeBillingPortalConfigurationResourcePolicyLayerLive =
|
|
103
|
+
Layer.effect(
|
|
104
|
+
StripeBillingPortalConfigurationResourcePolicy,
|
|
105
|
+
StripeBillingPortalConfigurationResourcePolicy.make,
|
|
106
|
+
).pipe(
|
|
107
|
+
Layer.provideMerge(stripeBillingPortalConfigurationLifecycleLayerLive),
|
|
108
|
+
Layer.provideMerge(resourceModelLayer),
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
export const stripeBillingConfigurationExportResourcePolicyLayerLive =
|
|
112
|
+
Layer.effect(
|
|
113
|
+
StripeBillingConfigurationExportResourcePolicy,
|
|
114
|
+
StripeBillingConfigurationExportResourcePolicy.make,
|
|
115
|
+
).pipe(
|
|
116
|
+
Layer.provideMerge(stripeBillingConfigurationExportLifecycleLayerLive),
|
|
117
|
+
Layer.provideMerge(resourceModelLayer),
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
const stripeResourceGraphLayerLiveResources = stripeResourcesLayerLive.pipe(
|
|
121
|
+
Layer.provideMerge(resourceGraphStoreLayer),
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Standalone Nomoss programs use this graph layer when they need only Stripe
|
|
126
|
+
* resources and the shared graph store.
|
|
127
|
+
*/
|
|
128
|
+
export const stripeResourceGraphLayerLive = Layer.mergeAll(
|
|
129
|
+
resourceGraphStoreLayer,
|
|
130
|
+
stripeResourceGraphLayerLiveResources,
|
|
131
|
+
);
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import { Credentials } from "@distilled.cloud/stripe";
|
|
2
|
+
import type {
|
|
3
|
+
DeleteWebhookEndpointsWebhookEndpointInput,
|
|
4
|
+
GetWebhookEndpointsWebhookEndpointInput,
|
|
5
|
+
} from "@distilled.cloud/stripe/Operations";
|
|
6
|
+
import {
|
|
7
|
+
DeleteWebhookEndpointsWebhookEndpoint,
|
|
8
|
+
GetWebhookEndpointsWebhookEndpoint,
|
|
9
|
+
PostWebhookEndpoints,
|
|
10
|
+
PostWebhookEndpointsInput,
|
|
11
|
+
PostWebhookEndpointsOutput,
|
|
12
|
+
PostWebhookEndpointsWebhookEndpoint,
|
|
13
|
+
PostWebhookEndpointsWebhookEndpointInput,
|
|
14
|
+
} from "@distilled.cloud/stripe/Operations";
|
|
15
|
+
import { Config, Context, Effect, Option, Redacted, Schema } from "effect";
|
|
16
|
+
|
|
17
|
+
import { annotateResourceSchema } from "../../core/model.js";
|
|
18
|
+
import { StripeApiVersion } from "./stripeAccount.js";
|
|
19
|
+
|
|
20
|
+
export const StripeWebhookEndpointRequestPropsSchema =
|
|
21
|
+
PostWebhookEndpointsInput;
|
|
22
|
+
|
|
23
|
+
export type StripeWebhookEndpointRequestProps = Schema.Schema.Type<
|
|
24
|
+
typeof StripeWebhookEndpointRequestPropsSchema
|
|
25
|
+
>;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* `payments-infra` declares the Stripe endpoint that delivers billing events
|
|
29
|
+
* to Example's webhook route. `ResourceModel` records this annotation with
|
|
30
|
+
* the resource node so later endpoint updates retain the signing secret that
|
|
31
|
+
* Stripe returns only at creation.
|
|
32
|
+
*/
|
|
33
|
+
export const StripeWebhookEndpointPropsSchema = annotateResourceSchema(
|
|
34
|
+
Schema.Struct({
|
|
35
|
+
endpoint: StripeWebhookEndpointRequestPropsSchema,
|
|
36
|
+
rotationKey: Schema.optional(Schema.String),
|
|
37
|
+
}),
|
|
38
|
+
{
|
|
39
|
+
provider: "stripe",
|
|
40
|
+
service: "billing",
|
|
41
|
+
resource: "webhook-endpoint",
|
|
42
|
+
operation: "create",
|
|
43
|
+
stateSecretOutputKeys: ["WebhookSigningSecret"],
|
|
44
|
+
},
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
export type StripeWebhookEndpointProps = Schema.Schema.Type<
|
|
48
|
+
typeof StripeWebhookEndpointPropsSchema
|
|
49
|
+
>;
|
|
50
|
+
|
|
51
|
+
export const StripeWebhookEndpointUpdatePropsSchema =
|
|
52
|
+
PostWebhookEndpointsWebhookEndpointInput;
|
|
53
|
+
|
|
54
|
+
export type StripeWebhookEndpointUpdateProps = Schema.Schema.Type<
|
|
55
|
+
typeof StripeWebhookEndpointUpdatePropsSchema
|
|
56
|
+
>;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Stripe presents this credential only when a webhook endpoint is created.
|
|
60
|
+
* The applied endpoint output uses this named value so state persistence can
|
|
61
|
+
* retain its Keychain reference and later webhook updates can preserve it.
|
|
62
|
+
*/
|
|
63
|
+
export const StripeWebhookSigningSecretSchema = Schema.String.pipe(
|
|
64
|
+
Schema.brand("StripeWebhookSigningSecret"),
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
export type StripeWebhookSigningSecret = Schema.Schema.Type<
|
|
68
|
+
typeof StripeWebhookSigningSecretSchema
|
|
69
|
+
>;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Stripe returns a webhook signing secret when an endpoint is created, then
|
|
73
|
+
* omits it from later reads and updates. The applied resource node must retain
|
|
74
|
+
* that original output so an update response cannot erase the signing secret
|
|
75
|
+
* used to verify billing webhook deliveries.
|
|
76
|
+
*/
|
|
77
|
+
export const StripeWebhookEndpointOutputsSchema = Schema.Struct({
|
|
78
|
+
WebhookEndpointId: Schema.String,
|
|
79
|
+
WebhookSigningSecret: Schema.optional(StripeWebhookSigningSecretSchema),
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
export type StripeWebhookEndpointOutputs = Schema.Schema.Type<
|
|
83
|
+
typeof StripeWebhookEndpointOutputsSchema
|
|
84
|
+
>;
|
|
85
|
+
|
|
86
|
+
export const StripeWebhookEndpointObservedStateSchema =
|
|
87
|
+
PostWebhookEndpointsOutput;
|
|
88
|
+
|
|
89
|
+
export type StripeWebhookEndpointObservedState = Schema.Schema.Type<
|
|
90
|
+
typeof StripeWebhookEndpointObservedStateSchema
|
|
91
|
+
>;
|
|
92
|
+
|
|
93
|
+
const StripeWebhookEndpointBasicAuthConfig = Config.all({
|
|
94
|
+
username: Config.string("NOMOSS_STRIPE_WEBHOOK_BASIC_AUTH_USERNAME").pipe(
|
|
95
|
+
Config.option,
|
|
96
|
+
),
|
|
97
|
+
password: Config.string("NOMOSS_STRIPE_WEBHOOK_BASIC_AUTH_PASSWORD").pipe(
|
|
98
|
+
Config.option,
|
|
99
|
+
),
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
const webhookSigningSecretValue = (
|
|
103
|
+
secret: string | Redacted.Redacted<string>,
|
|
104
|
+
) =>
|
|
105
|
+
Option.match(Option.liftPredicate(secret, Redacted.isRedacted), {
|
|
106
|
+
onNone: () => secret,
|
|
107
|
+
onSome: Redacted.value,
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Stripe create and update responses become the applied resource node through
|
|
112
|
+
* this projection. When an update omits the creation-only signing secret, the
|
|
113
|
+
* prior node supplies the value that billing webhook verification still needs.
|
|
114
|
+
*/
|
|
115
|
+
export const stripeWebhookEndpointOutputsFromState = (
|
|
116
|
+
state: StripeWebhookEndpointObservedState,
|
|
117
|
+
previous?: StripeWebhookEndpointOutputs,
|
|
118
|
+
): StripeWebhookEndpointOutputs => {
|
|
119
|
+
const previousSigningSecret = Option.flatMap(
|
|
120
|
+
Option.fromNullishOr(previous),
|
|
121
|
+
({ WebhookSigningSecret }) => Option.fromUndefinedOr(WebhookSigningSecret),
|
|
122
|
+
);
|
|
123
|
+
const endpointSigningSecret = Option.fromNullishOr(state.secret).pipe(
|
|
124
|
+
Option.orElse(() => previousSigningSecret),
|
|
125
|
+
Option.flatMap((secret) =>
|
|
126
|
+
Schema.decodeUnknownOption(StripeWebhookSigningSecretSchema)(
|
|
127
|
+
webhookSigningSecretValue(secret),
|
|
128
|
+
),
|
|
129
|
+
),
|
|
130
|
+
);
|
|
131
|
+
const outputs = Option.match(endpointSigningSecret, {
|
|
132
|
+
onNone: (): StripeWebhookEndpointOutputs => ({
|
|
133
|
+
WebhookEndpointId: state.id,
|
|
134
|
+
}),
|
|
135
|
+
onSome: (WebhookSigningSecret): StripeWebhookEndpointOutputs => ({
|
|
136
|
+
WebhookEndpointId: state.id,
|
|
137
|
+
WebhookSigningSecret,
|
|
138
|
+
}),
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
return outputs;
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
export const pendingStripeWebhookEndpointOutputs = (
|
|
145
|
+
logicalId: string,
|
|
146
|
+
): StripeWebhookEndpointOutputs => {
|
|
147
|
+
const outputs: StripeWebhookEndpointOutputs = {
|
|
148
|
+
WebhookEndpointId: `nomoss:pending:stripe-webhook-endpoint-id:${logicalId}`,
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
return outputs;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Billing infrastructure invokes this service when the declared Stripe webhook
|
|
156
|
+
* endpoint must be created, read, updated, or removed. Its delivery URL may
|
|
157
|
+
* use dev-only Basic Auth, while the persisted resource node remains safe for
|
|
158
|
+
* later lifecycle runs and Stripe request verification.
|
|
159
|
+
*/
|
|
160
|
+
export class StripeWebhookEndpointLifecycle extends Context.Service<StripeWebhookEndpointLifecycle>()(
|
|
161
|
+
"nomoss/providers/stripe/stripeWebhookEndpoint/StripeWebhookEndpointLifecycle",
|
|
162
|
+
{
|
|
163
|
+
make: Effect.gen(function* () {
|
|
164
|
+
const stripeCredentials = yield* Credentials;
|
|
165
|
+
const basicAuth = yield* StripeWebhookEndpointBasicAuthConfig;
|
|
166
|
+
const deliveryUrlFor = (url: string) =>
|
|
167
|
+
Option.all(basicAuth).pipe(
|
|
168
|
+
Option.match({
|
|
169
|
+
onNone: () => url,
|
|
170
|
+
onSome: ({ username, password }) => {
|
|
171
|
+
const deliveryUrl = new URL(url);
|
|
172
|
+
deliveryUrl.username = username;
|
|
173
|
+
deliveryUrl.password = password;
|
|
174
|
+
|
|
175
|
+
return deliveryUrl.toString();
|
|
176
|
+
},
|
|
177
|
+
}),
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
return {
|
|
181
|
+
createWebhookEndpoint: Effect.fn(
|
|
182
|
+
"StripeWebhookEndpointLifecycle.createWebhookEndpoint",
|
|
183
|
+
)(function* (props: StripeWebhookEndpointRequestProps) {
|
|
184
|
+
const endpointProps =
|
|
185
|
+
yield* StripeWebhookEndpointRequestPropsSchema.makeEffect({
|
|
186
|
+
api_version: props.api_version,
|
|
187
|
+
connect: props.connect,
|
|
188
|
+
description: props.description,
|
|
189
|
+
enabled_events: props.enabled_events,
|
|
190
|
+
metadata: props.metadata,
|
|
191
|
+
url: deliveryUrlFor(props.url),
|
|
192
|
+
});
|
|
193
|
+
const endpoint = yield* PostWebhookEndpoints(endpointProps, {
|
|
194
|
+
apiVersion: StripeApiVersion.Dahlia,
|
|
195
|
+
}).pipe(Effect.provideService(Credentials, stripeCredentials));
|
|
196
|
+
|
|
197
|
+
return endpoint;
|
|
198
|
+
}),
|
|
199
|
+
|
|
200
|
+
rotateWebhookEndpoint: Effect.fn(
|
|
201
|
+
"StripeWebhookEndpointLifecycle.rotateWebhookEndpoint",
|
|
202
|
+
)(function* (
|
|
203
|
+
previousWebhookEndpointId: string,
|
|
204
|
+
props: StripeWebhookEndpointRequestProps,
|
|
205
|
+
) {
|
|
206
|
+
const endpointProps =
|
|
207
|
+
yield* StripeWebhookEndpointRequestPropsSchema.makeEffect({
|
|
208
|
+
api_version: props.api_version,
|
|
209
|
+
connect: props.connect,
|
|
210
|
+
description: props.description,
|
|
211
|
+
enabled_events: props.enabled_events,
|
|
212
|
+
metadata: props.metadata,
|
|
213
|
+
url: deliveryUrlFor(props.url),
|
|
214
|
+
});
|
|
215
|
+
const endpoint = yield* PostWebhookEndpoints(endpointProps, {
|
|
216
|
+
apiVersion: StripeApiVersion.Dahlia,
|
|
217
|
+
}).pipe(Effect.provideService(Credentials, stripeCredentials));
|
|
218
|
+
const deleteInput: DeleteWebhookEndpointsWebhookEndpointInput = {
|
|
219
|
+
webhook_endpoint: previousWebhookEndpointId,
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
yield* DeleteWebhookEndpointsWebhookEndpoint(deleteInput, {
|
|
223
|
+
apiVersion: StripeApiVersion.Dahlia,
|
|
224
|
+
}).pipe(Effect.provideService(Credentials, stripeCredentials));
|
|
225
|
+
|
|
226
|
+
return endpoint;
|
|
227
|
+
}),
|
|
228
|
+
|
|
229
|
+
readWebhookEndpoint: Effect.fn(
|
|
230
|
+
"StripeWebhookEndpointLifecycle.readWebhookEndpoint",
|
|
231
|
+
)(function* (webhookEndpointId: string) {
|
|
232
|
+
const input: GetWebhookEndpointsWebhookEndpointInput = {
|
|
233
|
+
webhook_endpoint: webhookEndpointId,
|
|
234
|
+
};
|
|
235
|
+
const endpoint = yield* GetWebhookEndpointsWebhookEndpoint(input, {
|
|
236
|
+
apiVersion: StripeApiVersion.Dahlia,
|
|
237
|
+
}).pipe(
|
|
238
|
+
Effect.provideService(Credentials, stripeCredentials),
|
|
239
|
+
Effect.flatMap((output) =>
|
|
240
|
+
Schema.decodeUnknownEffect(
|
|
241
|
+
StripeWebhookEndpointObservedStateSchema,
|
|
242
|
+
)(output),
|
|
243
|
+
),
|
|
244
|
+
Effect.map((output) => Option.some(output)),
|
|
245
|
+
);
|
|
246
|
+
|
|
247
|
+
return endpoint;
|
|
248
|
+
}),
|
|
249
|
+
|
|
250
|
+
updateWebhookEndpoint: Effect.fn(
|
|
251
|
+
"StripeWebhookEndpointLifecycle.updateWebhookEndpoint",
|
|
252
|
+
)(function* (input: StripeWebhookEndpointUpdateProps) {
|
|
253
|
+
const endpointInput = yield* Option.match(
|
|
254
|
+
Option.fromUndefinedOr(input.url),
|
|
255
|
+
{
|
|
256
|
+
onNone: () => Effect.succeed(input),
|
|
257
|
+
onSome: (url) =>
|
|
258
|
+
StripeWebhookEndpointUpdatePropsSchema.makeEffect({
|
|
259
|
+
description: input.description,
|
|
260
|
+
disabled: input.disabled,
|
|
261
|
+
enabled_events: input.enabled_events,
|
|
262
|
+
expand: input.expand,
|
|
263
|
+
metadata: input.metadata,
|
|
264
|
+
url: deliveryUrlFor(url),
|
|
265
|
+
webhook_endpoint: input.webhook_endpoint,
|
|
266
|
+
}),
|
|
267
|
+
},
|
|
268
|
+
);
|
|
269
|
+
const endpoint = yield* PostWebhookEndpointsWebhookEndpoint(
|
|
270
|
+
endpointInput,
|
|
271
|
+
{
|
|
272
|
+
apiVersion: StripeApiVersion.Dahlia,
|
|
273
|
+
},
|
|
274
|
+
).pipe(Effect.provideService(Credentials, stripeCredentials));
|
|
275
|
+
|
|
276
|
+
return endpoint;
|
|
277
|
+
}),
|
|
278
|
+
|
|
279
|
+
deleteWebhookEndpoint: Effect.fn(
|
|
280
|
+
"StripeWebhookEndpointLifecycle.deleteWebhookEndpoint",
|
|
281
|
+
)(function* (webhookEndpointId: string) {
|
|
282
|
+
const input: DeleteWebhookEndpointsWebhookEndpointInput = {
|
|
283
|
+
webhook_endpoint: webhookEndpointId,
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
yield* DeleteWebhookEndpointsWebhookEndpoint(input, {
|
|
287
|
+
apiVersion: StripeApiVersion.Dahlia,
|
|
288
|
+
}).pipe(Effect.provideService(Credentials, stripeCredentials));
|
|
289
|
+
}),
|
|
290
|
+
};
|
|
291
|
+
}),
|
|
292
|
+
},
|
|
293
|
+
) {}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { Context, Effect, Match, Option, Schema } 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
|
+
StripeWebhookEndpointLifecycle,
|
|
16
|
+
type StripeWebhookEndpointOutputs,
|
|
17
|
+
StripeWebhookEndpointOutputsSchema,
|
|
18
|
+
StripeWebhookEndpointPropsSchema,
|
|
19
|
+
StripeWebhookEndpointRequestPropsSchema,
|
|
20
|
+
StripeWebhookEndpointUpdatePropsSchema,
|
|
21
|
+
stripeWebhookEndpointOutputsFromState,
|
|
22
|
+
} from "./stripeWebhookEndpoint.js";
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Webhook endpoint commands keep Stripe event delivery setup in Nomoss while
|
|
26
|
+
* backend webhook code stays responsible for request verification and handling.
|
|
27
|
+
*/
|
|
28
|
+
export class StripeWebhookEndpointResourcePolicy extends Context.Service<StripeWebhookEndpointResourcePolicy>()(
|
|
29
|
+
"nomoss/providers/stripe/stripeWebhookEndpointResourcePolicy",
|
|
30
|
+
{
|
|
31
|
+
make: Effect.gen(function* () {
|
|
32
|
+
const lifecycle = yield* StripeWebhookEndpointLifecycle;
|
|
33
|
+
const model = yield* ResourceModel;
|
|
34
|
+
const schema = yield* readResourceSchemaAnnotation(
|
|
35
|
+
StripeWebhookEndpointPropsSchema,
|
|
36
|
+
).pipe(Effect.fromOption);
|
|
37
|
+
|
|
38
|
+
const resourceNode = Effect.fn(
|
|
39
|
+
"StripeWebhookEndpointResourcePolicy.resourceNode",
|
|
40
|
+
)(function* (node: ResourceNode, outputs: StripeWebhookEndpointOutputs) {
|
|
41
|
+
const props = yield* model.decodeProps(
|
|
42
|
+
node,
|
|
43
|
+
StripeWebhookEndpointPropsSchema,
|
|
44
|
+
);
|
|
45
|
+
const appliedNode = yield* model.nodeFromResource({
|
|
46
|
+
key: node.key,
|
|
47
|
+
propsSchema: StripeWebhookEndpointPropsSchema,
|
|
48
|
+
outputsSchema: StripeWebhookEndpointOutputsSchema,
|
|
49
|
+
props,
|
|
50
|
+
outputs,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
return appliedNode;
|
|
54
|
+
});
|
|
55
|
+
const currentProps = (current: ResourceNode) =>
|
|
56
|
+
Schema.decodeUnknownOption(StripeWebhookEndpointPropsSchema)(
|
|
57
|
+
current.props,
|
|
58
|
+
).pipe(
|
|
59
|
+
Option.match({
|
|
60
|
+
onNone: () =>
|
|
61
|
+
Effect.flatMap(
|
|
62
|
+
Schema.decodeUnknownEffect(
|
|
63
|
+
StripeWebhookEndpointRequestPropsSchema,
|
|
64
|
+
)(current.props),
|
|
65
|
+
(endpoint) =>
|
|
66
|
+
StripeWebhookEndpointPropsSchema.makeEffect({ endpoint }),
|
|
67
|
+
),
|
|
68
|
+
onSome: Effect.succeed,
|
|
69
|
+
}),
|
|
70
|
+
);
|
|
71
|
+
const create = Effect.fn("StripeWebhookEndpointResourcePolicy.create")(
|
|
72
|
+
function* (node: ResourceNode) {
|
|
73
|
+
const props = yield* model.decodeProps(
|
|
74
|
+
node,
|
|
75
|
+
StripeWebhookEndpointPropsSchema,
|
|
76
|
+
);
|
|
77
|
+
const endpoint = yield* lifecycle.createWebhookEndpoint(
|
|
78
|
+
props.endpoint,
|
|
79
|
+
);
|
|
80
|
+
const outputs = stripeWebhookEndpointOutputsFromState(endpoint);
|
|
81
|
+
const appliedNode = yield* resourceNode(node, outputs);
|
|
82
|
+
|
|
83
|
+
return ResourceCommandResult.Created({ node: appliedNode });
|
|
84
|
+
},
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
const update = Effect.fn("StripeWebhookEndpointResourcePolicy.update")(
|
|
88
|
+
function* (node: ResourceNode, current: ResourceNode) {
|
|
89
|
+
const props = yield* model.decodeProps(
|
|
90
|
+
node,
|
|
91
|
+
StripeWebhookEndpointPropsSchema,
|
|
92
|
+
);
|
|
93
|
+
const previousProps = yield* currentProps(current);
|
|
94
|
+
const currentOutputs = yield* model.decodeOutputs(
|
|
95
|
+
current,
|
|
96
|
+
StripeWebhookEndpointOutputsSchema,
|
|
97
|
+
);
|
|
98
|
+
const input =
|
|
99
|
+
yield* StripeWebhookEndpointUpdatePropsSchema.makeEffect({
|
|
100
|
+
webhook_endpoint: currentOutputs.WebhookEndpointId,
|
|
101
|
+
description: props.endpoint.description,
|
|
102
|
+
enabled_events: props.endpoint.enabled_events,
|
|
103
|
+
metadata: props.endpoint.metadata,
|
|
104
|
+
url: props.endpoint.url,
|
|
105
|
+
});
|
|
106
|
+
const endpoint = yield* Match.value(
|
|
107
|
+
props.rotationKey !== previousProps.rotationKey,
|
|
108
|
+
).pipe(
|
|
109
|
+
Match.when(true, () =>
|
|
110
|
+
lifecycle.rotateWebhookEndpoint(
|
|
111
|
+
currentOutputs.WebhookEndpointId,
|
|
112
|
+
props.endpoint,
|
|
113
|
+
),
|
|
114
|
+
),
|
|
115
|
+
Match.orElse(() => lifecycle.updateWebhookEndpoint(input)),
|
|
116
|
+
);
|
|
117
|
+
const outputs = stripeWebhookEndpointOutputsFromState(
|
|
118
|
+
endpoint,
|
|
119
|
+
currentOutputs,
|
|
120
|
+
);
|
|
121
|
+
const appliedNode = yield* resourceNode(node, outputs);
|
|
122
|
+
|
|
123
|
+
return ResourceCommandResult.Updated({ node: appliedNode });
|
|
124
|
+
},
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
const destroy = Effect.fn("StripeWebhookEndpointResourcePolicy.destroy")(
|
|
128
|
+
function* (node: ResourceNode) {
|
|
129
|
+
const outputs = yield* model.decodeOutputs(
|
|
130
|
+
node,
|
|
131
|
+
StripeWebhookEndpointOutputsSchema,
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
yield* lifecycle.deleteWebhookEndpoint(outputs.WebhookEndpointId);
|
|
135
|
+
|
|
136
|
+
return ResourceCommandResult.Destroyed({ node });
|
|
137
|
+
},
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
const apply = Effect.fn("StripeWebhookEndpointResourcePolicy.apply")(
|
|
141
|
+
function* (decision: PlanDecision) {
|
|
142
|
+
return yield* Match.value(decision).pipe(
|
|
143
|
+
Match.tagsExhaustive({
|
|
144
|
+
Create: ({ node }) => create(node),
|
|
145
|
+
Update: ({ node, current }) => update(node, current),
|
|
146
|
+
Destroy: ({ node }) => destroy(node),
|
|
147
|
+
NoOp: () =>
|
|
148
|
+
Effect.fail(
|
|
149
|
+
new ResourceCommandUnsupported({
|
|
150
|
+
command: ResourceCommand.Apply({ decision }),
|
|
151
|
+
}),
|
|
152
|
+
),
|
|
153
|
+
Repair: () =>
|
|
154
|
+
Effect.fail(
|
|
155
|
+
new ResourceCommandUnsupported({
|
|
156
|
+
command: ResourceCommand.Apply({ decision }),
|
|
157
|
+
}),
|
|
158
|
+
),
|
|
159
|
+
Delete: () =>
|
|
160
|
+
Effect.fail(
|
|
161
|
+
new ResourceCommandUnsupported({
|
|
162
|
+
command: ResourceCommand.Apply({ decision }),
|
|
163
|
+
}),
|
|
164
|
+
),
|
|
165
|
+
}),
|
|
166
|
+
);
|
|
167
|
+
},
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
return {
|
|
171
|
+
schema,
|
|
172
|
+
create,
|
|
173
|
+
update,
|
|
174
|
+
destroy,
|
|
175
|
+
apply,
|
|
176
|
+
execute: Effect.fn("StripeWebhookEndpointResourcePolicy.execute")(
|
|
177
|
+
function* (command: ResourceCommand) {
|
|
178
|
+
return yield* Match.value(command).pipe(
|
|
179
|
+
Match.tagsExhaustive({
|
|
180
|
+
Read: () =>
|
|
181
|
+
Effect.fail(new ResourceCommandUnsupported({ command })),
|
|
182
|
+
Diff: () =>
|
|
183
|
+
Effect.fail(new ResourceCommandUnsupported({ command })),
|
|
184
|
+
Apply: ({ decision }) => apply(decision),
|
|
185
|
+
Create: ({ node }) => create(node),
|
|
186
|
+
Update: () =>
|
|
187
|
+
Effect.fail(new ResourceCommandUnsupported({ command })),
|
|
188
|
+
Delete: () =>
|
|
189
|
+
Effect.fail(new ResourceCommandUnsupported({ command })),
|
|
190
|
+
Destroy: ({ node }) => destroy(node),
|
|
191
|
+
}),
|
|
192
|
+
);
|
|
193
|
+
},
|
|
194
|
+
),
|
|
195
|
+
};
|
|
196
|
+
}),
|
|
197
|
+
},
|
|
198
|
+
) {}
|