@ericminassian/platform-engine 0.3.0 → 0.4.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/dist/clients.d.ts +8 -0
- package/dist/clients.js +22 -1
- package/dist/clients.js.map +1 -1
- package/dist/compat.d.ts +21 -9
- package/dist/compat.js +27 -7
- package/dist/compat.js.map +1 -1
- package/dist/drivers/appsync.d.ts +49 -0
- package/dist/drivers/appsync.js +155 -0
- package/dist/drivers/appsync.js.map +1 -0
- package/dist/drivers/cognito.d.ts +9 -3
- package/dist/drivers/cognito.js +18 -7
- package/dist/drivers/cognito.js.map +1 -1
- package/dist/drivers/ecr.d.ts +109 -0
- package/dist/drivers/ecr.js +303 -0
- package/dist/drivers/ecr.js.map +1 -0
- package/dist/drivers/ecs.d.ts +163 -0
- package/dist/drivers/ecs.js +447 -0
- package/dist/drivers/ecs.js.map +1 -0
- package/dist/drivers/events.d.ts +10 -0
- package/dist/drivers/events.js +13 -1
- package/dist/drivers/events.js.map +1 -1
- package/dist/drivers/index.d.ts +5 -0
- package/dist/drivers/index.js +5 -0
- package/dist/drivers/index.js.map +1 -1
- package/dist/drivers/kvs.d.ts +3 -0
- package/dist/drivers/kvs.js +14 -7
- package/dist/drivers/kvs.js.map +1 -1
- package/dist/drivers/lambda.d.ts +22 -0
- package/dist/drivers/lambda.js +74 -3
- package/dist/drivers/lambda.js.map +1 -1
- package/dist/drivers/request-function.d.ts +60 -0
- package/dist/drivers/request-function.js +167 -0
- package/dist/drivers/request-function.js.map +1 -0
- package/dist/drivers/s3.d.ts +5 -0
- package/dist/drivers/s3.js +26 -0
- package/dist/drivers/s3.js.map +1 -1
- package/dist/drivers/scheduler.d.ts +24 -0
- package/dist/drivers/scheduler.js +60 -5
- package/dist/drivers/scheduler.js.map +1 -1
- package/dist/drivers/ses.d.ts +77 -0
- package/dist/drivers/ses.js +181 -0
- package/dist/drivers/ses.js.map +1 -0
- package/dist/drivers/sqs.d.ts +11 -0
- package/dist/drivers/sqs.js +67 -1
- package/dist/drivers/sqs.js.map +1 -1
- package/dist/drivers/web-function.d.ts +11 -3
- package/dist/drivers/web-function.js +22 -5
- package/dist/drivers/web-function.js.map +1 -1
- package/dist/emulator.js.map +1 -1
- package/dist/images.d.ts +104 -0
- package/dist/images.js +182 -0
- package/dist/images.js.map +1 -0
- package/dist/index.d.ts +130 -6
- package/dist/index.js +11 -2
- package/dist/index.js.map +1 -1
- package/dist/local.js +222 -7
- package/dist/local.js.map +1 -1
- package/dist/policy.d.ts +47 -4
- package/dist/policy.js +365 -13
- package/dist/policy.js.map +1 -1
- package/dist/services.d.ts +155 -0
- package/dist/services.js +464 -0
- package/dist/services.js.map +1 -0
- package/dist/stage.d.ts +33 -8
- package/dist/stage.js +598 -125
- package/dist/stage.js.map +1 -1
- package/dist/static.d.ts +1 -1
- package/dist/static.js +2 -36
- package/dist/static.js.map +1 -1
- package/dist/util.d.ts +22 -0
- package/dist/util.js +18 -2
- package/dist/util.js.map +1 -1
- package/package.json +20 -14
- package/src/clients.ts +25 -1
- package/src/compat.ts +34 -11
- package/src/drivers/appsync.ts +220 -0
- package/src/drivers/cognito.ts +19 -9
- package/src/drivers/ecr.ts +457 -0
- package/src/drivers/ecs.ts +661 -0
- package/src/drivers/events.ts +29 -2
- package/src/drivers/index.ts +5 -0
- package/src/drivers/kvs.ts +21 -12
- package/src/drivers/lambda.ts +103 -2
- package/src/drivers/request-function.ts +295 -0
- package/src/drivers/s3.ts +38 -0
- package/src/drivers/scheduler.ts +88 -5
- package/src/drivers/ses.ts +267 -0
- package/src/drivers/sqs.ts +95 -0
- package/src/drivers/web-function.ts +29 -9
- package/src/emulator.ts +3 -3
- package/src/images.ts +254 -0
- package/src/index.ts +129 -7
- package/src/local.ts +251 -7
- package/src/policy.ts +446 -24
- package/src/services.ts +663 -0
- package/src/stage.ts +753 -140
- package/src/static.ts +2 -37
- package/src/util.ts +38 -4
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
import { CreateScheduleCommand, CreateScheduleGroupCommand, DeleteScheduleCommand, DeleteScheduleGroupCommand, GetScheduleCommand, GetScheduleGroupCommand, ListSchedulesCommand, UpdateScheduleCommand, } from '@aws-sdk/client-scheduler';
|
|
2
|
-
import {
|
|
2
|
+
import { atExpression } from '@ericminassian/platform-core';
|
|
3
|
+
import { ignoreNotFound, retry, tagList, waitFor } from '../util.js';
|
|
4
|
+
export { atExpression };
|
|
3
5
|
export async function ensureScheduleGroup(ctx, spec) {
|
|
4
6
|
const sch = ctx.clients.scheduler;
|
|
5
|
-
const
|
|
7
|
+
const get = () => ignoreNotFound(sch.send(new GetScheduleGroupCommand({ Name: spec.name })));
|
|
8
|
+
let existing = await get();
|
|
9
|
+
if (existing?.State === 'DELETING') {
|
|
10
|
+
// Groups are deleted asynchronously; one deleted by the previous deploy may still be going.
|
|
11
|
+
await waitFor(`schedule group ${spec.name} to finish deleting`, async () => !(await get()));
|
|
12
|
+
existing = undefined;
|
|
13
|
+
}
|
|
6
14
|
if (existing?.Arn)
|
|
7
15
|
return existing.Arn;
|
|
8
16
|
const res = await sch.send(new CreateScheduleGroupCommand({ Name: spec.name, Tags: spec.tags ? tagList(spec.tags) : undefined }));
|
|
@@ -23,16 +31,51 @@ export async function ensureSchedule(ctx, spec) {
|
|
|
23
31
|
RoleArn: spec.target.roleArn,
|
|
24
32
|
Input: spec.target.input,
|
|
25
33
|
RetryPolicy: { MaximumRetryAttempts: 2, MaximumEventAgeInSeconds: 3600 },
|
|
34
|
+
...(spec.deadLetterArn ? { DeadLetterConfig: { Arn: spec.deadLetterArn } } : {}),
|
|
26
35
|
},
|
|
27
36
|
};
|
|
28
37
|
const existing = await ignoreNotFound(sch.send(new GetScheduleCommand({ Name: spec.name, GroupName: spec.group })));
|
|
29
38
|
// A freshly created role may not be assumable by Scheduler yet.
|
|
30
39
|
await retry(() => existing
|
|
31
40
|
? sch.send(new UpdateScheduleCommand(definition))
|
|
32
|
-
: sch.send(new CreateScheduleCommand(definition)), { when: (e) => /assume the role|execution role/i.test(
|
|
41
|
+
: sch.send(new CreateScheduleCommand(definition)), { when: (e) => /assume the role|execution role/i.test(e.message), attempts: 12 });
|
|
33
42
|
if (!existing)
|
|
34
43
|
ctx.log('info', 'created schedule', `schedule ${spec.group}/${spec.name}`);
|
|
35
44
|
}
|
|
45
|
+
/** Inverse of {@link atExpression}. */
|
|
46
|
+
export function parseAtExpression(expression) {
|
|
47
|
+
const m = /^at\((\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2})\)$/.exec(expression ?? '');
|
|
48
|
+
return m ? new Date(`${m[1]}Z`) : undefined;
|
|
49
|
+
}
|
|
50
|
+
/** Create or move a schedule that fires once, then deletes itself. */
|
|
51
|
+
export async function ensureOneShotSchedule(ctx, spec) {
|
|
52
|
+
const sch = ctx.clients.scheduler;
|
|
53
|
+
const definition = {
|
|
54
|
+
Name: spec.name,
|
|
55
|
+
GroupName: spec.group,
|
|
56
|
+
ScheduleExpression: atExpression(spec.at),
|
|
57
|
+
ScheduleExpressionTimezone: 'UTC',
|
|
58
|
+
ActionAfterCompletion: 'DELETE',
|
|
59
|
+
FlexibleTimeWindow: { Mode: 'OFF' },
|
|
60
|
+
State: 'ENABLED',
|
|
61
|
+
Target: {
|
|
62
|
+
Arn: spec.target.arn,
|
|
63
|
+
RoleArn: spec.target.roleArn,
|
|
64
|
+
Input: spec.target.input,
|
|
65
|
+
RetryPolicy: { MaximumRetryAttempts: 5, MaximumEventAgeInSeconds: 3600 },
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
const existing = await ignoreNotFound(sch.send(new GetScheduleCommand({ Name: spec.name, GroupName: spec.group })));
|
|
69
|
+
await retry(() => existing
|
|
70
|
+
? sch.send(new UpdateScheduleCommand(definition))
|
|
71
|
+
: sch.send(new CreateScheduleCommand(definition)), { when: (e) => /assume the role|execution role/i.test(e.message), attempts: 12 });
|
|
72
|
+
ctx.log('info', `fires at ${spec.at.toISOString()}`, `schedule ${spec.group}/${spec.name}`);
|
|
73
|
+
}
|
|
74
|
+
/** When a one-shot schedule fires, or undefined when there is none (or it isn't one-shot). */
|
|
75
|
+
export async function getOneShotScheduleTime(ctx, group, name) {
|
|
76
|
+
const s = await ignoreNotFound(ctx.clients.scheduler.send(new GetScheduleCommand({ Name: name, GroupName: group })));
|
|
77
|
+
return parseAtExpression(s?.ScheduleExpression);
|
|
78
|
+
}
|
|
36
79
|
export async function listSchedules(ctx, group) {
|
|
37
80
|
const out = [];
|
|
38
81
|
let NextToken;
|
|
@@ -48,12 +91,24 @@ export async function listSchedules(ctx, group) {
|
|
|
48
91
|
return out;
|
|
49
92
|
}
|
|
50
93
|
export async function deleteSchedule(ctx, group, name) {
|
|
51
|
-
await ignoreNotFound(ctx.clients.scheduler.send(new DeleteScheduleCommand({ Name: name, GroupName: group })));
|
|
52
|
-
|
|
94
|
+
const res = await ignoreNotFound(ctx.clients.scheduler.send(new DeleteScheduleCommand({ Name: name, GroupName: group })));
|
|
95
|
+
if (res)
|
|
96
|
+
ctx.log('info', 'deleted schedule', `schedule ${group}/${name}`);
|
|
53
97
|
}
|
|
98
|
+
/** Delete the group and every schedule in it. */
|
|
54
99
|
export async function deleteScheduleGroup(ctx, group) {
|
|
55
100
|
for (const s of await listSchedules(ctx, group))
|
|
56
101
|
await deleteSchedule(ctx, group, s);
|
|
102
|
+
const exists = await ignoreNotFound(ctx.clients.scheduler.send(new GetScheduleGroupCommand({ Name: group })));
|
|
103
|
+
if (!exists || exists.State === 'DELETING')
|
|
104
|
+
return;
|
|
105
|
+
await ignoreNotFound(ctx.clients.scheduler.send(new DeleteScheduleGroupCommand({ Name: group })));
|
|
106
|
+
}
|
|
107
|
+
/** Delete the group if no schedule is left in it. */
|
|
108
|
+
export async function deleteScheduleGroupIfEmpty(ctx, group) {
|
|
109
|
+
const exists = await ignoreNotFound(ctx.clients.scheduler.send(new GetScheduleGroupCommand({ Name: group })));
|
|
110
|
+
if (!exists || exists.State === 'DELETING' || (await listSchedules(ctx, group)).length)
|
|
111
|
+
return;
|
|
57
112
|
await ignoreNotFound(ctx.clients.scheduler.send(new DeleteScheduleGroupCommand({ Name: group })));
|
|
58
113
|
}
|
|
59
114
|
//# sourceMappingURL=scheduler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scheduler.js","sourceRoot":"","sources":["../../src/drivers/scheduler.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,0BAA0B,EAC1B,qBAAqB,EACrB,0BAA0B,EAC1B,kBAAkB,EAClB,uBAAuB,EACvB,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAsB,cAAc,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"scheduler.js","sourceRoot":"","sources":["../../src/drivers/scheduler.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,0BAA0B,EAC1B,qBAAqB,EACrB,0BAA0B,EAC1B,kBAAkB,EAClB,uBAAuB,EACvB,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAsB,cAAc,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAEzF,OAAO,EAAE,YAAY,EAAE,CAAC;AAExB,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,GAAkB,EAClB,IAAqD;IAErD,MAAM,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC;IAClC,MAAM,GAAG,GAAG,GAAG,EAAE,CAAC,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,uBAAuB,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IAC7F,IAAI,QAAQ,GAAG,MAAM,GAAG,EAAE,CAAC;I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KAAK,UAAU,IAAI,CAAC,MAAM,aAAa,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,MAAM;QAAE,OAAO;IAC/F,MAAM,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,0BAA0B,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;AACpG,CAAC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { type GetConfigurationSetCommandOutput } from '@aws-sdk/client-sesv2';
|
|
2
|
+
import { type EngineContext } from '../util.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Amazon SES: each stage that declares `email` is a tenant plus a
|
|
5
|
+
* configuration set, both named `names.emailTenant`, associated with the
|
|
6
|
+
* platform's one domain identity (the foundation stack verifies it; the
|
|
7
|
+
* emulator's comes from `ensureLocal`). Found by name, like everything else
|
|
8
|
+
* the engine owns.
|
|
9
|
+
*
|
|
10
|
+
* The tenant is what isolates apps from each other: SES keeps its own
|
|
11
|
+
* suppression list, reports its metrics, and pauses only it when its
|
|
12
|
+
* reputation policy (SES's default, `standard`) sees too many bounces or
|
|
13
|
+
* complaints.
|
|
14
|
+
*/
|
|
15
|
+
/** Every stage tenant keeps its own list, fed by hard bounces and complaints. */
|
|
16
|
+
export declare const TENANT_SUPPRESSION: {
|
|
17
|
+
readonly SuppressedReasons: ["BOUNCE", "COMPLAINT"];
|
|
18
|
+
readonly SuppressionScope: 'TENANT';
|
|
19
|
+
};
|
|
20
|
+
export interface TenantState {
|
|
21
|
+
name: string;
|
|
22
|
+
id: string;
|
|
23
|
+
arn: string;
|
|
24
|
+
}
|
|
25
|
+
export declare function getConfigurationSet(ctx: EngineContext, name: string): Promise<GetConfigurationSetCommandOutput | undefined>;
|
|
26
|
+
/**
|
|
27
|
+
* The stage's configuration set, with reputation metrics on (they feed the
|
|
28
|
+
* console's bounce and complaint rates). Sends name it with the tenant, which
|
|
29
|
+
* is also what the stage role's grant covers.
|
|
30
|
+
*/
|
|
31
|
+
export declare function ensureConfigurationSet(ctx: EngineContext, spec: {
|
|
32
|
+
name: string;
|
|
33
|
+
tags: Record<string, string>;
|
|
34
|
+
}): Promise<{
|
|
35
|
+
name: string;
|
|
36
|
+
arn: string;
|
|
37
|
+
}>;
|
|
38
|
+
export declare function deleteConfigurationSet(ctx: EngineContext, name: string): Promise<boolean>;
|
|
39
|
+
export declare function getTenant(ctx: EngineContext, name: string): Promise<TenantState | undefined>;
|
|
40
|
+
/**
|
|
41
|
+
* The stage's tenant, created with the platform's suppression settings. An
|
|
42
|
+
* existing one keeps its id (and so its suppression list, metrics and any
|
|
43
|
+
* pause); only its tags and suppression settings are brought in line.
|
|
44
|
+
*/
|
|
45
|
+
export declare function ensureTenant(ctx: EngineContext, spec: {
|
|
46
|
+
name: string;
|
|
47
|
+
tags: Record<string, string>;
|
|
48
|
+
}): Promise<TenantState>;
|
|
49
|
+
/** Point the tenant at its own suppression list (`TENANT_SUPPRESSION`). */
|
|
50
|
+
export declare function putTenantSuppression(ctx: EngineContext, name: string): Promise<void>;
|
|
51
|
+
/** ARNs of everything associated with the tenant (identities, configuration sets, templates). */
|
|
52
|
+
export declare function listTenantResources(ctx: EngineContext, name: string): Promise<string[]>;
|
|
53
|
+
/**
|
|
54
|
+
* Associate exactly `resourceArns` (the domain identity and the stage's
|
|
55
|
+
* configuration set) with the tenant: a send that names the tenant may only
|
|
56
|
+
* use resources associated with it. SES refuses a second association of the
|
|
57
|
+
* same resource (AlreadyExists), so this lists first.
|
|
58
|
+
*/
|
|
59
|
+
export declare function ensureTenantResources(ctx: EngineContext, name: string, resourceArns: readonly string[]): Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Delete the tenant (its suppression list and metrics go with it). Its
|
|
62
|
+
* associations are removed first so the identity and configuration set are
|
|
63
|
+
* free of it whatever SES does with them on delete.
|
|
64
|
+
*/
|
|
65
|
+
export declare function deleteTenant(ctx: EngineContext, name: string): Promise<boolean>;
|
|
66
|
+
/**
|
|
67
|
+
* A domain identity, created when missing. Only `ensureLocal` uses this: in
|
|
68
|
+
* AWS the foundation stack owns the identity and its DNS records. Returns its
|
|
69
|
+
* ARN (SES doesn't report one).
|
|
70
|
+
*/
|
|
71
|
+
export declare function ensureEmailIdentity(ctx: EngineContext, spec: {
|
|
72
|
+
domain: string;
|
|
73
|
+
tags: Record<string, string>;
|
|
74
|
+
}): Promise<{
|
|
75
|
+
domain: string;
|
|
76
|
+
arn: string;
|
|
77
|
+
}>;
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { CreateConfigurationSetCommand, CreateEmailIdentityCommand, CreateTenantCommand, CreateTenantResourceAssociationCommand, DeleteConfigurationSetCommand, DeleteTenantCommand, DeleteTenantResourceAssociationCommand, GetConfigurationSetCommand, GetEmailIdentityCommand, GetTenantCommand, ListTenantResourcesCommand, PutConfigurationSetReputationOptionsCommand, PutTenantSuppressionAttributesCommand, TagResourceCommand, } from '@aws-sdk/client-sesv2';
|
|
2
|
+
import { configurationSetArn, emailIdentityArn } from '../policy.js';
|
|
3
|
+
import { ignoreNotFound, tagList } from '../util.js';
|
|
4
|
+
/**
|
|
5
|
+
* Amazon SES: each stage that declares `email` is a tenant plus a
|
|
6
|
+
* configuration set, both named `names.emailTenant`, associated with the
|
|
7
|
+
* platform's one domain identity (the foundation stack verifies it; the
|
|
8
|
+
* emulator's comes from `ensureLocal`). Found by name, like everything else
|
|
9
|
+
* the engine owns.
|
|
10
|
+
*
|
|
11
|
+
* The tenant is what isolates apps from each other: SES keeps its own
|
|
12
|
+
* suppression list, reports its metrics, and pauses only it when its
|
|
13
|
+
* reputation policy (SES's default, `standard`) sees too many bounces or
|
|
14
|
+
* complaints.
|
|
15
|
+
*/
|
|
16
|
+
/** Every stage tenant keeps its own list, fed by hard bounces and complaints. */
|
|
17
|
+
export const TENANT_SUPPRESSION = {
|
|
18
|
+
SuppressedReasons: ['BOUNCE', 'COMPLAINT'],
|
|
19
|
+
SuppressionScope: 'TENANT',
|
|
20
|
+
};
|
|
21
|
+
// ---------------------------------------------------------------- configuration sets
|
|
22
|
+
export async function getConfigurationSet(ctx, name) {
|
|
23
|
+
return ignoreNotFound(ctx.clients.ses.send(new GetConfigurationSetCommand({ ConfigurationSetName: name })));
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The stage's configuration set, with reputation metrics on (they feed the
|
|
27
|
+
* console's bounce and complaint rates). Sends name it with the tenant, which
|
|
28
|
+
* is also what the stage role's grant covers.
|
|
29
|
+
*/
|
|
30
|
+
export async function ensureConfigurationSet(ctx, spec) {
|
|
31
|
+
const arn = configurationSetArn(ctx.region, await ctx.accountId(), spec.name);
|
|
32
|
+
const existing = await getConfigurationSet(ctx, spec.name);
|
|
33
|
+
if (!existing) {
|
|
34
|
+
await ctx.clients.ses.send(new CreateConfigurationSetCommand({
|
|
35
|
+
ConfigurationSetName: spec.name,
|
|
36
|
+
ReputationOptions: { ReputationMetricsEnabled: true },
|
|
37
|
+
Tags: tagList(spec.tags),
|
|
38
|
+
}));
|
|
39
|
+
ctx.log('info', 'created configuration set', `configuration-set ${spec.name}`);
|
|
40
|
+
return { name: spec.name, arn };
|
|
41
|
+
}
|
|
42
|
+
if (!existing.ReputationOptions?.ReputationMetricsEnabled) {
|
|
43
|
+
await ctx.clients.ses.send(new PutConfigurationSetReputationOptionsCommand({
|
|
44
|
+
ConfigurationSetName: spec.name,
|
|
45
|
+
ReputationMetricsEnabled: true,
|
|
46
|
+
}));
|
|
47
|
+
ctx.log('info', 'turned on reputation metrics', `configuration-set ${spec.name}`);
|
|
48
|
+
}
|
|
49
|
+
await ensureTags(ctx, arn, existing.Tags, spec.tags);
|
|
50
|
+
return { name: spec.name, arn };
|
|
51
|
+
}
|
|
52
|
+
export async function deleteConfigurationSet(ctx, name) {
|
|
53
|
+
const res = await ignoreNotFound(ctx.clients.ses.send(new DeleteConfigurationSetCommand({ ConfigurationSetName: name })));
|
|
54
|
+
if (res === undefined)
|
|
55
|
+
return false;
|
|
56
|
+
ctx.log('info', 'deleted configuration set', `configuration-set ${name}`);
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
// ---------------------------------------------------------------- tenants
|
|
60
|
+
export async function getTenant(ctx, name) {
|
|
61
|
+
const res = await ignoreNotFound(ctx.clients.ses.send(new GetTenantCommand({ TenantName: name })));
|
|
62
|
+
return res?.Tenant ? tenantState(res.Tenant) : undefined;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The stage's tenant, created with the platform's suppression settings. An
|
|
66
|
+
* existing one keeps its id (and so its suppression list, metrics and any
|
|
67
|
+
* pause); only its tags and suppression settings are brought in line.
|
|
68
|
+
*/
|
|
69
|
+
export async function ensureTenant(ctx, spec) {
|
|
70
|
+
const existing = await ignoreNotFound(ctx.clients.ses.send(new GetTenantCommand({ TenantName: spec.name })));
|
|
71
|
+
if (!existing?.Tenant) {
|
|
72
|
+
const created = await ctx.clients.ses.send(new CreateTenantCommand({
|
|
73
|
+
TenantName: spec.name,
|
|
74
|
+
Tags: tagList(spec.tags),
|
|
75
|
+
SuppressionAttributes: TENANT_SUPPRESSION,
|
|
76
|
+
}));
|
|
77
|
+
ctx.log('info', 'created tenant', `email-tenant ${spec.name}`);
|
|
78
|
+
// Checked rather than assumed: a tenant left on the account's list would share
|
|
79
|
+
// suppressions (and their reputation cost) with every other app.
|
|
80
|
+
if (!sameSuppression(created.SuppressionAttributes))
|
|
81
|
+
await putTenantSuppression(ctx, spec.name);
|
|
82
|
+
return tenantState(created);
|
|
83
|
+
}
|
|
84
|
+
const state = tenantState(existing.Tenant);
|
|
85
|
+
await ensureTags(ctx, state.arn, existing.Tenant.Tags, spec.tags);
|
|
86
|
+
if (!sameSuppression(existing.Tenant.SuppressionAttributes))
|
|
87
|
+
await putTenantSuppression(ctx, spec.name);
|
|
88
|
+
return state;
|
|
89
|
+
}
|
|
90
|
+
/** Point the tenant at its own suppression list (`TENANT_SUPPRESSION`). */
|
|
91
|
+
export async function putTenantSuppression(ctx, name) {
|
|
92
|
+
await ctx.clients.ses.send(new PutTenantSuppressionAttributesCommand({ TenantName: name, ...TENANT_SUPPRESSION }));
|
|
93
|
+
ctx.log('info', 'tenant keeps its own suppression list', `email-tenant ${name}`);
|
|
94
|
+
}
|
|
95
|
+
/** ARNs of everything associated with the tenant (identities, configuration sets, templates). */
|
|
96
|
+
export async function listTenantResources(ctx, name) {
|
|
97
|
+
const out = [];
|
|
98
|
+
let NextToken;
|
|
99
|
+
do {
|
|
100
|
+
const res = await ctx.clients.ses.send(new ListTenantResourcesCommand({ TenantName: name, ...(NextToken ? { NextToken } : {}) }));
|
|
101
|
+
for (const r of res.TenantResources ?? [])
|
|
102
|
+
if (r.ResourceArn)
|
|
103
|
+
out.push(r.ResourceArn);
|
|
104
|
+
NextToken = res.NextToken;
|
|
105
|
+
} while (NextToken);
|
|
106
|
+
return out;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Associate exactly `resourceArns` (the domain identity and the stage's
|
|
110
|
+
* configuration set) with the tenant: a send that names the tenant may only
|
|
111
|
+
* use resources associated with it. SES refuses a second association of the
|
|
112
|
+
* same resource (AlreadyExists), so this lists first.
|
|
113
|
+
*/
|
|
114
|
+
export async function ensureTenantResources(ctx, name, resourceArns) {
|
|
115
|
+
const current = new Set(await listTenantResources(ctx, name));
|
|
116
|
+
for (const arn of resourceArns) {
|
|
117
|
+
if (current.has(arn))
|
|
118
|
+
continue;
|
|
119
|
+
await ctx.clients.ses.send(new CreateTenantResourceAssociationCommand({ TenantName: name, ResourceArn: arn }));
|
|
120
|
+
ctx.log('info', `associated ${arn.slice(arn.lastIndexOf(':') + 1)}`, `email-tenant ${name}`);
|
|
121
|
+
}
|
|
122
|
+
for (const arn of current) {
|
|
123
|
+
if (resourceArns.includes(arn))
|
|
124
|
+
continue;
|
|
125
|
+
await ignoreNotFound(ctx.clients.ses.send(new DeleteTenantResourceAssociationCommand({ TenantName: name, ResourceArn: arn })));
|
|
126
|
+
ctx.log('info', `dissociated ${arn.slice(arn.lastIndexOf(':') + 1)}`, `email-tenant ${name}`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Delete the tenant (its suppression list and metrics go with it). Its
|
|
131
|
+
* associations are removed first so the identity and configuration set are
|
|
132
|
+
* free of it whatever SES does with them on delete.
|
|
133
|
+
*/
|
|
134
|
+
export async function deleteTenant(ctx, name) {
|
|
135
|
+
const resources = await ignoreNotFound(listTenantResources(ctx, name));
|
|
136
|
+
if (resources === undefined)
|
|
137
|
+
return false;
|
|
138
|
+
for (const arn of resources) {
|
|
139
|
+
await ignoreNotFound(ctx.clients.ses.send(new DeleteTenantResourceAssociationCommand({ TenantName: name, ResourceArn: arn })));
|
|
140
|
+
}
|
|
141
|
+
const res = await ignoreNotFound(ctx.clients.ses.send(new DeleteTenantCommand({ TenantName: name })));
|
|
142
|
+
if (res === undefined)
|
|
143
|
+
return false;
|
|
144
|
+
ctx.log('info', 'deleted tenant', `email-tenant ${name}`);
|
|
145
|
+
return true;
|
|
146
|
+
}
|
|
147
|
+
// ---------------------------------------------------------------- identities
|
|
148
|
+
/**
|
|
149
|
+
* A domain identity, created when missing. Only `ensureLocal` uses this: in
|
|
150
|
+
* AWS the foundation stack owns the identity and its DNS records. Returns its
|
|
151
|
+
* ARN (SES doesn't report one).
|
|
152
|
+
*/
|
|
153
|
+
export async function ensureEmailIdentity(ctx, spec) {
|
|
154
|
+
const arn = emailIdentityArn(ctx.region, await ctx.accountId(), spec.domain);
|
|
155
|
+
const existing = await ignoreNotFound(ctx.clients.ses.send(new GetEmailIdentityCommand({ EmailIdentity: spec.domain })));
|
|
156
|
+
if (!existing) {
|
|
157
|
+
await ctx.clients.ses.send(new CreateEmailIdentityCommand({ EmailIdentity: spec.domain, Tags: tagList(spec.tags) }));
|
|
158
|
+
ctx.log('info', 'created domain identity', `email-identity ${spec.domain}`);
|
|
159
|
+
}
|
|
160
|
+
return { domain: spec.domain, arn };
|
|
161
|
+
}
|
|
162
|
+
// ---------------------------------------------------------------- helpers
|
|
163
|
+
function tenantState(t) {
|
|
164
|
+
if (!t.TenantName || !t.TenantId || !t.TenantArn)
|
|
165
|
+
throw new Error('SES returned a tenant without its name, id or ARN');
|
|
166
|
+
return { name: t.TenantName, id: t.TenantId, arn: t.TenantArn };
|
|
167
|
+
}
|
|
168
|
+
function sameSuppression(a) {
|
|
169
|
+
const reasons = (a?.SuppressedReasons ?? []).toSorted().join(',');
|
|
170
|
+
return (a?.SuppressionScope === TENANT_SUPPRESSION.SuppressionScope &&
|
|
171
|
+
reasons === TENANT_SUPPRESSION.SuppressedReasons.toSorted().join(','));
|
|
172
|
+
}
|
|
173
|
+
/** Add or correct the platform's tags; tags someone else added stay. */
|
|
174
|
+
async function ensureTags(ctx, arn, current, wanted) {
|
|
175
|
+
const have = new Map((current ?? []).map((t) => [t.Key, t.Value]));
|
|
176
|
+
const missing = Object.entries(wanted).filter(([k, v]) => have.get(k) !== v);
|
|
177
|
+
if (!missing.length)
|
|
178
|
+
return;
|
|
179
|
+
await ctx.clients.ses.send(new TagResourceCommand({ ResourceArn: arn, Tags: missing.map(([Key, Value]) => ({ Key, Value })) }));
|
|
180
|
+
}
|
|
181
|
+
//# sourceMappingURL=ses.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ses.js","sourceRoot":"","sources":["../../src/drivers/ses.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,6BAA6B,EAC7B,0BAA0B,EAC1B,mBAAmB,EACnB,sCAAsC,EACtC,6BAA6B,EAC7B,mBAAmB,EACnB,sCAAsC,EACtC,0BAA0B,EAE1B,uBAAuB,EACvB,gBAAgB,EAChB,0BAA0B,EAC1B,2CAA2C,EAC3C,qCAAqC,EAErC,kBAAkB,GAGnB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACrE,OAAO,EAAsB,cAAc,EAA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AAC;IAC7E,IAAI,CAAC,OAAO,CAAC,MAAM;QAAE,OAAO;IAC5B,MAAM,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CACxB,IAAI,kBAAkB,CAAC,EAAE,WAAW,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,CACpG,CAAC;AACJ,CAAC"}
|
package/dist/drivers/sqs.d.ts
CHANGED
|
@@ -6,6 +6,9 @@ export interface QueueState {
|
|
|
6
6
|
created: boolean;
|
|
7
7
|
}
|
|
8
8
|
export declare function getQueueUrl(ctx: EngineContext, name: string): Promise<string | undefined>;
|
|
9
|
+
/** A queue's visibility timeout in seconds; undefined when the queue doesn't exist. */
|
|
10
|
+
export declare function getQueueVisibility(ctx: EngineContext, name: string): Promise<number | undefined>;
|
|
11
|
+
export declare function setQueueAttributes(ctx: EngineContext, url: string, attributes: Record<string, string>): Promise<void>;
|
|
9
12
|
export declare function ensureQueue(ctx: EngineContext, spec: {
|
|
10
13
|
name: string;
|
|
11
14
|
attributes?: Record<string, string>;
|
|
@@ -16,3 +19,11 @@ export declare function listQueues(ctx: EngineContext, prefix: string): Promise<
|
|
|
16
19
|
name: string;
|
|
17
20
|
url: string;
|
|
18
21
|
}>>;
|
|
22
|
+
/** Messages a queue holds (visible, in flight and delayed); undefined when it doesn't exist. */
|
|
23
|
+
export declare function queueDepth(ctx: EngineContext, url: string): Promise<number | undefined>;
|
|
24
|
+
/**
|
|
25
|
+
* Moves every message visible on `from` to `to`, rewritten by `transform`,
|
|
26
|
+
* deleting each once it's sent. Answers how many moved. Messages in flight
|
|
27
|
+
* elsewhere stay where they are.
|
|
28
|
+
*/
|
|
29
|
+
export declare function moveMessages(ctx: EngineContext, from: string, to: string, transform: (body: string, receiveCount: number) => string): Promise<number>;
|
package/dist/drivers/sqs.js
CHANGED
|
@@ -1,9 +1,21 @@
|
|
|
1
|
-
import { CreateQueueCommand, DeleteQueueCommand, GetQueueAttributesCommand, GetQueueUrlCommand, ListQueuesCommand, SetQueueAttributesCommand, TagQueueCommand, } from '@aws-sdk/client-sqs';
|
|
1
|
+
import { CreateQueueCommand, DeleteMessageBatchCommand, DeleteQueueCommand, GetQueueAttributesCommand, GetQueueUrlCommand, ListQueuesCommand, ReceiveMessageCommand, SendMessageBatchCommand, SetQueueAttributesCommand, TagQueueCommand, } from '@aws-sdk/client-sqs';
|
|
2
2
|
import { ignoreNotFound } from '../util.js';
|
|
3
3
|
export async function getQueueUrl(ctx, name) {
|
|
4
4
|
const res = await ignoreNotFound(ctx.clients.sqs.send(new GetQueueUrlCommand({ QueueName: name })));
|
|
5
5
|
return res?.QueueUrl;
|
|
6
6
|
}
|
|
7
|
+
/** A queue's visibility timeout in seconds; undefined when the queue doesn't exist. */
|
|
8
|
+
export async function getQueueVisibility(ctx, name) {
|
|
9
|
+
const url = await getQueueUrl(ctx, name);
|
|
10
|
+
if (!url)
|
|
11
|
+
return undefined;
|
|
12
|
+
const res = await ignoreNotFound(ctx.clients.sqs.send(new GetQueueAttributesCommand({ QueueUrl: url, AttributeNames: ['VisibilityTimeout'] })));
|
|
13
|
+
const value = res?.Attributes?.VisibilityTimeout;
|
|
14
|
+
return value === undefined ? undefined : Number(value);
|
|
15
|
+
}
|
|
16
|
+
export async function setQueueAttributes(ctx, url, attributes) {
|
|
17
|
+
await ctx.clients.sqs.send(new SetQueueAttributesCommand({ QueueUrl: url, Attributes: attributes }));
|
|
18
|
+
}
|
|
7
19
|
export async function ensureQueue(ctx, spec) {
|
|
8
20
|
const sqs = ctx.clients.sqs;
|
|
9
21
|
let url = await getQueueUrl(ctx, spec.name);
|
|
@@ -43,4 +55,58 @@ export async function listQueues(ctx, prefix) {
|
|
|
43
55
|
} while (NextToken);
|
|
44
56
|
return out;
|
|
45
57
|
}
|
|
58
|
+
/** Messages a queue holds (visible, in flight and delayed); undefined when it doesn't exist. */
|
|
59
|
+
export async function queueDepth(ctx, url) {
|
|
60
|
+
const res = await ignoreNotFound(ctx.clients.sqs.send(new GetQueueAttributesCommand({
|
|
61
|
+
QueueUrl: url,
|
|
62
|
+
AttributeNames: [
|
|
63
|
+
'ApproximateNumberOfMessages',
|
|
64
|
+
'ApproximateNumberOfMessagesNotVisible',
|
|
65
|
+
'ApproximateNumberOfMessagesDelayed',
|
|
66
|
+
],
|
|
67
|
+
})));
|
|
68
|
+
if (!res)
|
|
69
|
+
return undefined;
|
|
70
|
+
const a = res.Attributes ?? {};
|
|
71
|
+
return (Number(a.ApproximateNumberOfMessages ?? 0) +
|
|
72
|
+
Number(a.ApproximateNumberOfMessagesNotVisible ?? 0) +
|
|
73
|
+
Number(a.ApproximateNumberOfMessagesDelayed ?? 0));
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Moves every message visible on `from` to `to`, rewritten by `transform`,
|
|
77
|
+
* deleting each once it's sent. Answers how many moved. Messages in flight
|
|
78
|
+
* elsewhere stay where they are.
|
|
79
|
+
*/
|
|
80
|
+
export async function moveMessages(ctx, from, to, transform) {
|
|
81
|
+
const sqs = ctx.clients.sqs;
|
|
82
|
+
let moved = 0;
|
|
83
|
+
for (;;) {
|
|
84
|
+
const res = await sqs.send(new ReceiveMessageCommand({
|
|
85
|
+
QueueUrl: from,
|
|
86
|
+
MaxNumberOfMessages: 10,
|
|
87
|
+
VisibilityTimeout: 60,
|
|
88
|
+
MessageSystemAttributeNames: ['ApproximateReceiveCount'],
|
|
89
|
+
}));
|
|
90
|
+
const messages = res.Messages ?? [];
|
|
91
|
+
if (messages.length === 0)
|
|
92
|
+
return moved;
|
|
93
|
+
const sent = await sqs.send(new SendMessageBatchCommand({
|
|
94
|
+
QueueUrl: to,
|
|
95
|
+
Entries: messages.map((m, i) => ({
|
|
96
|
+
Id: String(i),
|
|
97
|
+
MessageBody: transform(m.Body ?? '', Number(m.Attributes?.ApproximateReceiveCount ?? '1')),
|
|
98
|
+
})),
|
|
99
|
+
}));
|
|
100
|
+
const ok = new Set((sent.Successful ?? []).map((e) => e.Id));
|
|
101
|
+
const done = messages.filter((_, i) => ok.has(String(i)));
|
|
102
|
+
if (done.length)
|
|
103
|
+
await sqs.send(new DeleteMessageBatchCommand({
|
|
104
|
+
QueueUrl: from,
|
|
105
|
+
Entries: done.map((m, i) => ({ Id: String(i), ReceiptHandle: m.ReceiptHandle })),
|
|
106
|
+
}));
|
|
107
|
+
moved += done.length;
|
|
108
|
+
if (done.length < messages.length)
|
|
109
|
+
throw new Error(`could not move ${messages.length - done.length} messages from ${from}`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
46
112
|
//# sourceMappingURL=sqs.js.map
|
package/dist/drivers/sqs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqs.js","sourceRoot":"","sources":["../../src/drivers/sqs.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,yBAAyB,EACzB,kBAAkB,EAClB,iBAAiB,EACjB,yBAAyB,EACzB,eAAe,GAChB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAsB,cAAc,EAAE,MAAM,YAAY,CAAC;AAShE,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,GAAkB,EAAE,IAAY;IAChE,MAAM,GAAG,GAAG,MAAM,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,kBAAkB,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IACpG,OAAO,GAAG,EAAE,QAAQ,CAAC;AACvB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,GAAkB,EAClB,IAA0F;IAE1F,MAAM,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC;IAC5B,IAAI,GAAG,GAAG,MAAM,WAAW,CAAC,G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Q,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,kBAAkB,IAAI,EAAE,CAAC,CAAC;IAC7F,CAAC;AACH,CAAC"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { S3Location } from '../index.ts';
|
|
2
2
|
import { type EngineContext } from '../util.ts';
|
|
3
3
|
/**
|
|
4
|
-
* Lambda Web Functions (launched 2026-10)
|
|
5
|
-
* revisions; an endpoint routes traffic to up to
|
|
4
|
+
* Lambda Web Functions (launched 2026-10), a stage's server in instance mode:
|
|
5
|
+
* a function holds immutable revisions; an endpoint routes traffic to up to
|
|
6
|
+
* two revisions by weight.
|
|
6
7
|
*
|
|
7
8
|
* The engine gives each stage two endpoints and pins each to one revision
|
|
8
9
|
* (100%). A route record names an endpoint, so the route flip switches
|
|
@@ -34,6 +35,7 @@ export declare function ensureWebFunction(ctx: EngineContext, spec: {
|
|
|
34
35
|
initial: {
|
|
35
36
|
revision: RevisionSpec;
|
|
36
37
|
endpointName: string;
|
|
38
|
+
maxEnvironments?: number;
|
|
37
39
|
};
|
|
38
40
|
}): Promise<{
|
|
39
41
|
arn: string;
|
|
@@ -47,11 +49,15 @@ export interface EndpointState {
|
|
|
47
49
|
domainName: string;
|
|
48
50
|
revisionIds: string[];
|
|
49
51
|
}
|
|
50
|
-
/**
|
|
52
|
+
/**
|
|
53
|
+
* Ensure the endpoint exists and routes 100% to `revisionId`, with at most
|
|
54
|
+
* `maxEnvironments` environments when given (left as it is otherwise).
|
|
55
|
+
*/
|
|
51
56
|
export declare function ensureEndpoint(ctx: EngineContext, spec: {
|
|
52
57
|
functionName: string;
|
|
53
58
|
endpointName: string;
|
|
54
59
|
revisionId: string;
|
|
60
|
+
maxEnvironments?: number;
|
|
55
61
|
}): Promise<EndpointState>;
|
|
56
62
|
export declare function getEndpoint(ctx: EngineContext, functionName: string, endpointName: string): Promise<import("@aws-sdk/client-lambda-web").GetWebFunctionEndpointCommandOutput | undefined>;
|
|
57
63
|
export interface RevisionEndpoint {
|
|
@@ -74,6 +80,8 @@ export declare function endpointForRevision(ctx: EngineContext, spec: {
|
|
|
74
80
|
revisionId: string;
|
|
75
81
|
liveDomain?: string;
|
|
76
82
|
distributionArn?: string;
|
|
83
|
+
/** The endpoint's cap on environments; unchanged when absent. */
|
|
84
|
+
maxEnvironments?: number;
|
|
77
85
|
}): Promise<RevisionEndpoint>;
|
|
78
86
|
/**
|
|
79
87
|
* Allow only the platform's CloudFront distribution to invoke the endpoints
|