cdk-amazon-connect-constructs 0.1.0-alpha.0

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.
@@ -0,0 +1,196 @@
1
+ import { aws_connect as connect } from 'aws-cdk-lib';
2
+ import { Construct } from 'constructs';
3
+ import { IConnectInstance } from './connect-instance';
4
+ import { IQueue } from './queue';
5
+
6
+ /**
7
+ * Amazon Connect contact channels.
8
+ */
9
+ export enum Channel {
10
+ VOICE = 'VOICE',
11
+ CHAT = 'CHAT',
12
+ TASK = 'TASK',
13
+ EMAIL = 'EMAIL',
14
+ }
15
+
16
+ /**
17
+ * Channel concurrency for a routing profile.
18
+ */
19
+ export interface MediaConcurrency {
20
+ /**
21
+ * Contact channel.
22
+ */
23
+ readonly channel: Channel;
24
+
25
+ /**
26
+ * Number of simultaneous contacts allowed for the channel.
27
+ */
28
+ readonly concurrency: number;
29
+ }
30
+
31
+ /**
32
+ * Queue association settings for a routing profile.
33
+ */
34
+ export interface RoutingProfileQueueConfig {
35
+ /**
36
+ * Queue to associate.
37
+ */
38
+ readonly queue: IQueue;
39
+
40
+ /**
41
+ * Contact channel for this queue association.
42
+ *
43
+ * @default Channel.VOICE
44
+ */
45
+ readonly channel?: Channel;
46
+
47
+ /**
48
+ * Queue priority. Lower values are higher priority.
49
+ *
50
+ * @default 1
51
+ */
52
+ readonly priority?: number;
53
+
54
+ /**
55
+ * Delay before contacts are routed to agents, in seconds.
56
+ *
57
+ * @default 0
58
+ */
59
+ readonly delay?: number;
60
+ }
61
+
62
+ /**
63
+ * An Amazon Connect routing profile reference.
64
+ */
65
+ export interface IRoutingProfile {
66
+ /**
67
+ * The routing profile ARN.
68
+ */
69
+ readonly routingProfileArn: string;
70
+ }
71
+
72
+ /**
73
+ * Properties for RoutingProfile.
74
+ */
75
+ export interface RoutingProfileProps {
76
+ /**
77
+ * The Amazon Connect instance that owns this routing profile.
78
+ */
79
+ readonly instance: IConnectInstance;
80
+
81
+ /**
82
+ * Routing profile name.
83
+ */
84
+ readonly name: string;
85
+
86
+ /**
87
+ * Routing profile description.
88
+ */
89
+ readonly description: string;
90
+
91
+ /**
92
+ * Default outbound queue.
93
+ */
94
+ readonly defaultOutboundQueue: IQueue;
95
+
96
+ /**
97
+ * Media concurrency settings.
98
+ *
99
+ * @default - one concurrent voice contact
100
+ */
101
+ readonly mediaConcurrencies?: MediaConcurrency[];
102
+
103
+ /**
104
+ * Queue associations.
105
+ *
106
+ * @default - associate only the default outbound queue for voice
107
+ */
108
+ readonly queueConfigs?: RoutingProfileQueueConfig[];
109
+ }
110
+
111
+ /**
112
+ * L2-style wrapper for AWS::Connect::RoutingProfile.
113
+ */
114
+ export class RoutingProfile extends Construct implements IRoutingProfile {
115
+ /**
116
+ * The underlying CloudFormation resource.
117
+ */
118
+ public readonly resource: connect.CfnRoutingProfile;
119
+
120
+ /**
121
+ * The routing profile ARN.
122
+ */
123
+ public readonly routingProfileArn: string;
124
+
125
+ public constructor(scope: Construct, id: string, props: RoutingProfileProps) {
126
+ super(scope, id);
127
+
128
+ if (!props.name.trim()) {
129
+ throw new Error('name must not be empty.');
130
+ }
131
+ if (!props.description.trim()) {
132
+ throw new Error('description must not be empty.');
133
+ }
134
+
135
+ const mediaConcurrencies = props.mediaConcurrencies ?? [
136
+ { channel: Channel.VOICE, concurrency: 1 },
137
+ ];
138
+ const queueConfigs = props.queueConfigs ?? [
139
+ { queue: props.defaultOutboundQueue, channel: Channel.VOICE, priority: 1, delay: 0 },
140
+ ];
141
+
142
+ if (mediaConcurrencies.length === 0) {
143
+ throw new Error('mediaConcurrencies must include at least one channel.');
144
+ }
145
+ if (queueConfigs.length === 0) {
146
+ throw new Error('queueConfigs must include at least one queue association.');
147
+ }
148
+
149
+ this.resource = new connect.CfnRoutingProfile(this, 'Resource', {
150
+ defaultOutboundQueueArn: props.defaultOutboundQueue.queueArn,
151
+ description: props.description,
152
+ instanceArn: props.instance.instanceArn,
153
+ mediaConcurrencies: mediaConcurrencies.map(toCfnMediaConcurrency),
154
+ name: props.name,
155
+ queueConfigs: queueConfigs.map(toCfnQueueConfig),
156
+ });
157
+
158
+ this.routingProfileArn = this.resource.getAtt('RoutingProfileArn').toString();
159
+ }
160
+ }
161
+
162
+ function toCfnMediaConcurrency(
163
+ media: MediaConcurrency,
164
+ ): connect.CfnRoutingProfile.MediaConcurrencyProperty {
165
+ if (media.concurrency < 1 || !Number.isInteger(media.concurrency)) {
166
+ throw new Error('media concurrency must be a positive integer.');
167
+ }
168
+
169
+ return {
170
+ channel: media.channel,
171
+ concurrency: media.concurrency,
172
+ };
173
+ }
174
+
175
+ function toCfnQueueConfig(
176
+ config: RoutingProfileQueueConfig,
177
+ ): connect.CfnRoutingProfile.RoutingProfileQueueConfigProperty {
178
+ const priority = config.priority ?? 1;
179
+ const delay = config.delay ?? 0;
180
+
181
+ if (priority < 1 || !Number.isInteger(priority)) {
182
+ throw new Error('queue priority must be a positive integer.');
183
+ }
184
+ if (delay < 0 || !Number.isInteger(delay)) {
185
+ throw new Error('queue delay must be a non-negative integer.');
186
+ }
187
+
188
+ return {
189
+ delay,
190
+ priority,
191
+ queueReference: {
192
+ channel: config.channel ?? Channel.VOICE,
193
+ queueArn: config.queue.queueArn,
194
+ },
195
+ };
196
+ }
@@ -0,0 +1,40 @@
1
+ {
2
+ "compilerOptions": {
3
+ "alwaysStrict": true,
4
+ "declaration": true,
5
+ "declarationMap": true,
6
+ "esModuleInterop": true,
7
+ "experimentalDecorators": true,
8
+ "inlineSourceMap": true,
9
+ "inlineSources": true,
10
+ "lib": [
11
+ "es2020"
12
+ ],
13
+ "module": "commonjs",
14
+ "noEmitOnError": true,
15
+ "noFallthroughCasesInSwitch": true,
16
+ "noImplicitAny": true,
17
+ "noImplicitReturns": true,
18
+ "noImplicitThis": true,
19
+ "noUnusedLocals": true,
20
+ "noUnusedParameters": true,
21
+ "outDir": "lib",
22
+ "resolveJsonModule": true,
23
+ "rootDir": "src",
24
+ "skipLibCheck": true,
25
+ "strict": true,
26
+ "strictNullChecks": true,
27
+ "stripInternal": true,
28
+ "target": "ES2020"
29
+ },
30
+ "include": [
31
+ "src/**/*.ts"
32
+ ],
33
+ "exclude": [
34
+ "node_modules",
35
+ "lib",
36
+ "dist",
37
+ "test",
38
+ "examples"
39
+ ]
40
+ }