@fy-stack/event-construct 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/README.md +7 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/lib/event-construct.d.ts +14 -0
- package/dist/lib/event-construct.d.ts.map +1 -0
- package/dist/lib/event-construct.js +57 -0
- package/dist/lib/types.d.ts +21 -0
- package/dist/lib/types.d.ts.map +1 -0
- package/dist/lib/types.js +2 -0
- package/package.json +22 -0
package/README.md
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,YAAY,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EventConstruct = void 0;
|
|
4
|
+
var event_construct_1 = require("./lib/event-construct");
|
|
5
|
+
Object.defineProperty(exports, "EventConstruct", { enumerable: true, get: function () { return event_construct_1.EventConstruct; } });
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Attachable, Grantable } from '@fy-stack/types';
|
|
2
|
+
import { IGrantable } from 'aws-cdk-lib/aws-iam';
|
|
3
|
+
import * as sns from 'aws-cdk-lib/aws-sns';
|
|
4
|
+
import { Construct } from 'constructs';
|
|
5
|
+
import { EventConstructProps } from './types';
|
|
6
|
+
export declare class EventConstruct extends Construct implements Attachable, Grantable {
|
|
7
|
+
readonly topic: sns.Topic;
|
|
8
|
+
constructor(scope: Construct, id: string, props: EventConstructProps);
|
|
9
|
+
attachable(): {
|
|
10
|
+
topic: string;
|
|
11
|
+
};
|
|
12
|
+
grantable(grant: IGrantable): void;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=event-construct.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-construct.d.ts","sourceRoot":"","sources":["../../src/lib/event-construct.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAGxD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,KAAK,GAAG,MAAM,qBAAqB,CAAC;AAE3C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAE9C,qBAAa,cAAe,SAAQ,SAAU,YAAW,UAAU,EAAE,SAAS;IAC5E,SAAgB,KAAK,EAAE,GAAG,CAAC,KAAK,CAAC;gBAErB,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,mBAAmB;IA4CpE,UAAU;;;IAMV,SAAS,CAAC,KAAK,EAAE,UAAU;CAG5B"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EventConstruct = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const events = tslib_1.__importStar(require("aws-cdk-lib/aws-events"));
|
|
6
|
+
const eventsTarget = tslib_1.__importStar(require("aws-cdk-lib/aws-events-targets"));
|
|
7
|
+
const sns = tslib_1.__importStar(require("aws-cdk-lib/aws-sns"));
|
|
8
|
+
const constructs_1 = require("constructs");
|
|
9
|
+
class EventConstruct extends constructs_1.Construct {
|
|
10
|
+
topic;
|
|
11
|
+
constructor(scope, id, props) {
|
|
12
|
+
super(scope, id);
|
|
13
|
+
this.topic = new sns.Topic(this, 'AppTopic');
|
|
14
|
+
for (const i in props.events?.messages ?? []) {
|
|
15
|
+
const appMessage = props.events?.messages?.[i];
|
|
16
|
+
if (!appMessage)
|
|
17
|
+
continue;
|
|
18
|
+
const app = props.resources?.[appMessage.$app];
|
|
19
|
+
if (!app)
|
|
20
|
+
throw new Error(`${appMessage.$app} not found`);
|
|
21
|
+
const filterPolicy = {
|
|
22
|
+
filterPolicyWithMessageBody: {
|
|
23
|
+
message: sns.FilterOrPolicy.filter(sns.SubscriptionFilter.stringFilter({
|
|
24
|
+
allowlist: appMessage.messages,
|
|
25
|
+
})),
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
this.topic.addSubscription(app.subscription(filterPolicy));
|
|
29
|
+
}
|
|
30
|
+
for (const i in props.events?.cron ?? []) {
|
|
31
|
+
const job = props.events?.cron?.[i];
|
|
32
|
+
if (!job)
|
|
33
|
+
continue;
|
|
34
|
+
for (const message of job.messages) {
|
|
35
|
+
new events.Rule(this, `ScheduleRule${i}${message}`, {
|
|
36
|
+
schedule: events.Schedule.cron(job.cron),
|
|
37
|
+
targets: [
|
|
38
|
+
new eventsTarget.SnsTopic(this.topic, {
|
|
39
|
+
message: events.RuleTargetInput.fromObject({
|
|
40
|
+
message,
|
|
41
|
+
}),
|
|
42
|
+
}),
|
|
43
|
+
],
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
attachable() {
|
|
49
|
+
return {
|
|
50
|
+
topic: this.topic.topicArn,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
grantable(grant) {
|
|
54
|
+
this.topic.grantPublish(grant);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.EventConstruct = EventConstruct;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Event } from '@fy-stack/types';
|
|
2
|
+
import type { CronOptions } from 'aws-cdk-lib/aws-events';
|
|
3
|
+
export type AppRef = {
|
|
4
|
+
$app: string;
|
|
5
|
+
};
|
|
6
|
+
export type AppMessage = AppRef & {
|
|
7
|
+
messages: string[];
|
|
8
|
+
publish?: boolean;
|
|
9
|
+
};
|
|
10
|
+
export type AppCron = {
|
|
11
|
+
messages: string[];
|
|
12
|
+
cron: CronOptions;
|
|
13
|
+
};
|
|
14
|
+
export interface EventConstructProps {
|
|
15
|
+
resources?: Record<string, Event>;
|
|
16
|
+
events?: {
|
|
17
|
+
messages?: AppMessage[];
|
|
18
|
+
cron?: AppCron[];
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAE1D,MAAM,MAAM,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAEtC,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG;IAChC,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IACpB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,IAAI,EAAE,WAAW,CAAC;CACnB,CAAC;AAEF,MAAM,WAAW,mBAAmB;IAClC,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAClC,MAAM,CAAC,EAAE;QACP,QAAQ,CAAC,EAAE,UAAU,EAAE,CAAC;QACxB,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC;KAClB,CAAC;CACH"}
|
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fy-stack/event-construct",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"dependencies": {
|
|
5
|
+
"tslib": "^2.3.0"
|
|
6
|
+
},
|
|
7
|
+
"peerDependencies": {
|
|
8
|
+
"aws-cdk-lib": "2.164.1",
|
|
9
|
+
"constructs": "10.4.2",
|
|
10
|
+
"@fy-stack/types": "0.0.1"
|
|
11
|
+
},
|
|
12
|
+
"type": "commonjs",
|
|
13
|
+
"main": "./dist/index.js",
|
|
14
|
+
"typings": "./dist/index.d.ts",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"!**/*.tsbuildinfo"
|
|
18
|
+
],
|
|
19
|
+
"nx": {
|
|
20
|
+
"name": "event-construct"
|
|
21
|
+
}
|
|
22
|
+
}
|