@gradientedge/cdk-utils 8.137.0 → 8.138.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.
- package/dist/src/lib/cloudflare/common/construct.d.ts +2 -1
- package/dist/src/lib/cloudflare/common/construct.js +2 -0
- package/dist/src/lib/cloudflare/services/index.d.ts +1 -0
- package/dist/src/lib/cloudflare/services/index.js +1 -0
- package/dist/src/lib/cloudflare/services/worker/index.d.ts +2 -0
- package/dist/src/lib/cloudflare/services/worker/index.js +18 -0
- package/dist/src/lib/cloudflare/services/worker/main.d.ts +75 -0
- package/dist/src/lib/cloudflare/services/worker/main.js +148 -0
- package/dist/src/lib/cloudflare/services/worker/types.d.ts +18 -0
- package/dist/src/lib/cloudflare/services/worker/types.js +2 -0
- package/package.json +1 -1
- package/src/lib/cloudflare/common/construct.ts +3 -1
- package/src/lib/cloudflare/services/index.ts +1 -0
- package/src/lib/cloudflare/services/worker/index.ts +2 -0
- package/src/lib/cloudflare/services/worker/main.ts +173 -0
- package/src/lib/cloudflare/services/worker/types.ts +13 -0
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { TerraformStack } from 'cdktf';
|
|
2
2
|
import { Construct } from 'constructs';
|
|
3
|
-
import { CloudflareZoneManager } from '../services';
|
|
3
|
+
import { CloudflareWorkerManager, CloudflareZoneManager } from '../services';
|
|
4
4
|
import { CommonCloudflareStackProps } from './types';
|
|
5
5
|
export declare class CommonCloudflareConstruct extends TerraformStack {
|
|
6
6
|
props: CommonCloudflareStackProps;
|
|
7
7
|
id: string;
|
|
8
8
|
fullyQualifiedDomainName: string;
|
|
9
|
+
workerManager: CloudflareWorkerManager;
|
|
9
10
|
zoneManager: CloudflareZoneManager;
|
|
10
11
|
constructor(scope: Construct, id: string, props: CommonCloudflareStackProps);
|
|
11
12
|
/**
|
|
@@ -8,12 +8,14 @@ const services_1 = require("../services");
|
|
|
8
8
|
class CommonCloudflareConstruct extends cdktf_1.TerraformStack {
|
|
9
9
|
id;
|
|
10
10
|
fullyQualifiedDomainName;
|
|
11
|
+
workerManager;
|
|
11
12
|
zoneManager;
|
|
12
13
|
constructor(scope, id, props) {
|
|
13
14
|
super(scope, id);
|
|
14
15
|
this.props = props;
|
|
15
16
|
this.id = id;
|
|
16
17
|
this.zoneManager = new services_1.CloudflareZoneManager();
|
|
18
|
+
this.workerManager = new services_1.CloudflareWorkerManager();
|
|
17
19
|
this.determineFullyQualifiedDomain();
|
|
18
20
|
new provider_1.CloudflareProvider(this, `${this.id}-provider`, this.props);
|
|
19
21
|
}
|
|
@@ -14,4 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./worker"), exports);
|
|
17
18
|
__exportStar(require("./zone"), exports);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./main"), exports);
|
|
18
|
+
__exportStar(require("./types"), exports);
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { WorkerDomain } from '@cdktf/provider-cloudflare/lib/worker-domain';
|
|
2
|
+
import { WorkerRoute } from '@cdktf/provider-cloudflare/lib/worker-route';
|
|
3
|
+
import { WorkerScript } from '@cdktf/provider-cloudflare/lib/worker-script';
|
|
4
|
+
import { CommonCloudflareConstruct } from '../../common';
|
|
5
|
+
import { WorkerCronTriggerProps, WorkerDomainProps, WorkerRouteProps, WorkerScriptProps, WorkersKvNamespaceProps, WorkersKvProps } from './types';
|
|
6
|
+
import { WorkersKvNamespace } from '@cdktf/provider-cloudflare/lib/workers-kv-namespace';
|
|
7
|
+
import { WorkersKv } from '@cdktf/provider-cloudflare/lib/workers-kv';
|
|
8
|
+
import { WorkerCronTrigger } from '@cdktf/provider-cloudflare/lib/worker-cron-trigger';
|
|
9
|
+
/**
|
|
10
|
+
* @classdesc Provides operations on Cloudflare Worker
|
|
11
|
+
* - A new instance of this class is injected into {@link CommonCloudflareConstruct} constructor.
|
|
12
|
+
* - If a custom construct extends {@link CommonCloudflareConstruct}, an instance is available within the context.
|
|
13
|
+
* @example
|
|
14
|
+
* ```
|
|
15
|
+
* import { CommonCloudflareConstruct, CommonCloudflareConstruct } from '@gradientedge/cdk-utils'
|
|
16
|
+
*
|
|
17
|
+
* class CustomConstruct extends CommonCloudflareConstruct {
|
|
18
|
+
* constructor(parent: Construct, id: string, props: CommonCloudflareStackProps) {
|
|
19
|
+
* super(parent, id, props)
|
|
20
|
+
* this.props = props
|
|
21
|
+
* this.workerManager.createWorkerDomain('MyWorkerDomain', this, props)
|
|
22
|
+
* }
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare class CloudflareWorkerManager {
|
|
27
|
+
/**
|
|
28
|
+
* @summary Method to create a new Cloudflare Worker Domain
|
|
29
|
+
* @param id scoped id of the resource
|
|
30
|
+
* @param scope scope in which this resource is defined
|
|
31
|
+
* @param props worker domain properties
|
|
32
|
+
* @see [CDKTF Worker Domain Module]{@link https://github.com/cdktf/cdktf-provider-cloudflare/blob/main/docs/workerDomain.typescript.md}
|
|
33
|
+
*/
|
|
34
|
+
createWorkerDomain(id: string, scope: CommonCloudflareConstruct, props: WorkerDomainProps): WorkerDomain;
|
|
35
|
+
/**
|
|
36
|
+
* @summary Method to create a new Cloudflare Worker Route
|
|
37
|
+
* @param id scoped id of the resource
|
|
38
|
+
* @param scope scope in which this resource is defined
|
|
39
|
+
* @param props worker route properties
|
|
40
|
+
* @see [CDKTF Worker Route Module]{@link https://github.com/cdktf/cdktf-provider-cloudflare/blob/main/docs/workerRoute.typescript.md}
|
|
41
|
+
*/
|
|
42
|
+
createWorkerRoute(id: string, scope: CommonCloudflareConstruct, props: WorkerRouteProps): WorkerRoute;
|
|
43
|
+
/**
|
|
44
|
+
* @summary Method to create a new Cloudflare Worker Script
|
|
45
|
+
* @param id scoped id of the resource
|
|
46
|
+
* @param scope scope in which this resource is defined
|
|
47
|
+
* @param props worker script properties
|
|
48
|
+
* @see [CDKTF Worker Script Module]{@link https://github.com/cdktf/cdktf-provider-cloudflare/blob/main/docs/workerScript.typescript.md}
|
|
49
|
+
*/
|
|
50
|
+
createWorkerScript(id: string, scope: CommonCloudflareConstruct, props: WorkerScriptProps): WorkerScript;
|
|
51
|
+
/**
|
|
52
|
+
* @summary Method to create a new Cloudflare Workers KV Namespace
|
|
53
|
+
* @param id scoped id of the resource
|
|
54
|
+
* @param scope scope in which this resource is defined
|
|
55
|
+
* @param props workers kv namespace properties
|
|
56
|
+
* @see [CDKTF Workers KV Namespace Module]{@link https://github.com/cdktf/cdktf-provider-cloudflare/blob/main/docs/workersKvNamespace.typescript.md}
|
|
57
|
+
*/
|
|
58
|
+
createWorkersKvNamespace(id: string, scope: CommonCloudflareConstruct, props: WorkersKvNamespaceProps): WorkersKvNamespace;
|
|
59
|
+
/**
|
|
60
|
+
* @summary Method to create a new Cloudflare Workers KV
|
|
61
|
+
* @param id scoped id of the resource
|
|
62
|
+
* @param scope scope in which this resource is defined
|
|
63
|
+
* @param props workers kv properties
|
|
64
|
+
* @see [CDKTF Workers KV Module]{@link https://github.com/cdktf/cdktf-provider-cloudflare/blob/main/docs/workersKv.typescript.md}
|
|
65
|
+
*/
|
|
66
|
+
createWorkersKv(id: string, scope: CommonCloudflareConstruct, props: WorkersKvProps): WorkersKv;
|
|
67
|
+
/**
|
|
68
|
+
* @summary Method to create a new Cloudflare Worker Cron Trigger
|
|
69
|
+
* @param id scoped id of the resource
|
|
70
|
+
* @param scope scope in which this resource is defined
|
|
71
|
+
* @param props workers cron trigger properties
|
|
72
|
+
* @see [CDKTF Workers Cron Trigger Module]{@link https://github.com/cdktf/cdktf-provider-cloudflare/blob/main/docs/workerCronTrigger.typescript.md}
|
|
73
|
+
*/
|
|
74
|
+
createWorkerCronTrigger(id: string, scope: CommonCloudflareConstruct, props: WorkerCronTriggerProps): WorkerCronTrigger;
|
|
75
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CloudflareWorkerManager = void 0;
|
|
4
|
+
const worker_domain_1 = require("@cdktf/provider-cloudflare/lib/worker-domain");
|
|
5
|
+
const worker_route_1 = require("@cdktf/provider-cloudflare/lib/worker-route");
|
|
6
|
+
const worker_script_1 = require("@cdktf/provider-cloudflare/lib/worker-script");
|
|
7
|
+
const utils_1 = require("../../utils");
|
|
8
|
+
const workers_kv_namespace_1 = require("@cdktf/provider-cloudflare/lib/workers-kv-namespace");
|
|
9
|
+
const workers_kv_1 = require("@cdktf/provider-cloudflare/lib/workers-kv");
|
|
10
|
+
const worker_cron_trigger_1 = require("@cdktf/provider-cloudflare/lib/worker-cron-trigger");
|
|
11
|
+
/**
|
|
12
|
+
* @classdesc Provides operations on Cloudflare Worker
|
|
13
|
+
* - A new instance of this class is injected into {@link CommonCloudflareConstruct} constructor.
|
|
14
|
+
* - If a custom construct extends {@link CommonCloudflareConstruct}, an instance is available within the context.
|
|
15
|
+
* @example
|
|
16
|
+
* ```
|
|
17
|
+
* import { CommonCloudflareConstruct, CommonCloudflareConstruct } from '@gradientedge/cdk-utils'
|
|
18
|
+
*
|
|
19
|
+
* class CustomConstruct extends CommonCloudflareConstruct {
|
|
20
|
+
* constructor(parent: Construct, id: string, props: CommonCloudflareStackProps) {
|
|
21
|
+
* super(parent, id, props)
|
|
22
|
+
* this.props = props
|
|
23
|
+
* this.workerManager.createWorkerDomain('MyWorkerDomain', this, props)
|
|
24
|
+
* }
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
class CloudflareWorkerManager {
|
|
29
|
+
/**
|
|
30
|
+
* @summary Method to create a new Cloudflare Worker Domain
|
|
31
|
+
* @param id scoped id of the resource
|
|
32
|
+
* @param scope scope in which this resource is defined
|
|
33
|
+
* @param props worker domain properties
|
|
34
|
+
* @see [CDKTF Worker Domain Module]{@link https://github.com/cdktf/cdktf-provider-cloudflare/blob/main/docs/workerDomain.typescript.md}
|
|
35
|
+
*/
|
|
36
|
+
createWorkerDomain(id, scope, props) {
|
|
37
|
+
if (!props)
|
|
38
|
+
throw `Props undefined for ${id}`;
|
|
39
|
+
const zoneId = props.zoneId
|
|
40
|
+
? props.zoneId
|
|
41
|
+
: scope.zoneManager.resolveZone(`${id}-data-zone`, scope, { name: scope.props.domainName })?.id;
|
|
42
|
+
const workerDomain = new worker_domain_1.WorkerDomain(scope, `${id}`, {
|
|
43
|
+
...props,
|
|
44
|
+
accountId: props.accountId ?? scope.props.accountId,
|
|
45
|
+
zoneId,
|
|
46
|
+
});
|
|
47
|
+
(0, utils_1.createCloudflareTfOutput)(`${id}-workerDomainFriendlyUniqueId`, scope, workerDomain.friendlyUniqueId);
|
|
48
|
+
(0, utils_1.createCloudflareTfOutput)(`${id}-workerDomainId`, scope, workerDomain.id);
|
|
49
|
+
return workerDomain;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* @summary Method to create a new Cloudflare Worker Route
|
|
53
|
+
* @param id scoped id of the resource
|
|
54
|
+
* @param scope scope in which this resource is defined
|
|
55
|
+
* @param props worker route properties
|
|
56
|
+
* @see [CDKTF Worker Route Module]{@link https://github.com/cdktf/cdktf-provider-cloudflare/blob/main/docs/workerRoute.typescript.md}
|
|
57
|
+
*/
|
|
58
|
+
createWorkerRoute(id, scope, props) {
|
|
59
|
+
if (!props)
|
|
60
|
+
throw `Props undefined for ${id}`;
|
|
61
|
+
const zoneId = props.zoneId
|
|
62
|
+
? props.zoneId
|
|
63
|
+
: scope.zoneManager.resolveZone(`${id}-data-zone`, scope, { name: scope.props.domainName })?.id;
|
|
64
|
+
const workerRoute = new worker_route_1.WorkerRoute(scope, `${id}`, {
|
|
65
|
+
...props,
|
|
66
|
+
scriptName: `${props.scriptName}-${scope.props.stage}`,
|
|
67
|
+
zoneId,
|
|
68
|
+
});
|
|
69
|
+
(0, utils_1.createCloudflareTfOutput)(`${id}-workerRouteFriendlyUniqueId`, scope, workerRoute.friendlyUniqueId);
|
|
70
|
+
(0, utils_1.createCloudflareTfOutput)(`${id}-workerRouteId`, scope, workerRoute.id);
|
|
71
|
+
return workerRoute;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* @summary Method to create a new Cloudflare Worker Script
|
|
75
|
+
* @param id scoped id of the resource
|
|
76
|
+
* @param scope scope in which this resource is defined
|
|
77
|
+
* @param props worker script properties
|
|
78
|
+
* @see [CDKTF Worker Script Module]{@link https://github.com/cdktf/cdktf-provider-cloudflare/blob/main/docs/workerScript.typescript.md}
|
|
79
|
+
*/
|
|
80
|
+
createWorkerScript(id, scope, props) {
|
|
81
|
+
if (!props)
|
|
82
|
+
throw `Props undefined for ${id}`;
|
|
83
|
+
const workerScript = new worker_script_1.WorkerScript(scope, `${id}`, {
|
|
84
|
+
...props,
|
|
85
|
+
accountId: props.accountId ?? scope.props.accountId,
|
|
86
|
+
name: `${props.name}-${scope.props.stage}`,
|
|
87
|
+
});
|
|
88
|
+
(0, utils_1.createCloudflareTfOutput)(`${id}-workerScriptFriendlyUniqueId`, scope, workerScript.friendlyUniqueId);
|
|
89
|
+
(0, utils_1.createCloudflareTfOutput)(`${id}-workerScriptId`, scope, workerScript.id);
|
|
90
|
+
return workerScript;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* @summary Method to create a new Cloudflare Workers KV Namespace
|
|
94
|
+
* @param id scoped id of the resource
|
|
95
|
+
* @param scope scope in which this resource is defined
|
|
96
|
+
* @param props workers kv namespace properties
|
|
97
|
+
* @see [CDKTF Workers KV Namespace Module]{@link https://github.com/cdktf/cdktf-provider-cloudflare/blob/main/docs/workersKvNamespace.typescript.md}
|
|
98
|
+
*/
|
|
99
|
+
createWorkersKvNamespace(id, scope, props) {
|
|
100
|
+
if (!props)
|
|
101
|
+
throw `Props undefined for ${id}`;
|
|
102
|
+
const workersKvNamespace = new workers_kv_namespace_1.WorkersKvNamespace(scope, `${id}`, {
|
|
103
|
+
...props,
|
|
104
|
+
accountId: props.accountId ?? scope.props.accountId,
|
|
105
|
+
title: scope.isProductionStage() ? props.title : `${props.title}-${scope.props.stage}`,
|
|
106
|
+
});
|
|
107
|
+
(0, utils_1.createCloudflareTfOutput)(`${id}-workersKvNamespaceFriendlyUniqueId`, scope, workersKvNamespace.friendlyUniqueId);
|
|
108
|
+
(0, utils_1.createCloudflareTfOutput)(`${id}-workersKvNamespaceId`, scope, workersKvNamespace.id);
|
|
109
|
+
return workersKvNamespace;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* @summary Method to create a new Cloudflare Workers KV
|
|
113
|
+
* @param id scoped id of the resource
|
|
114
|
+
* @param scope scope in which this resource is defined
|
|
115
|
+
* @param props workers kv properties
|
|
116
|
+
* @see [CDKTF Workers KV Module]{@link https://github.com/cdktf/cdktf-provider-cloudflare/blob/main/docs/workersKv.typescript.md}
|
|
117
|
+
*/
|
|
118
|
+
createWorkersKv(id, scope, props) {
|
|
119
|
+
if (!props)
|
|
120
|
+
throw `Props undefined for ${id}`;
|
|
121
|
+
const workersKv = new workers_kv_1.WorkersKv(scope, `${id}`, {
|
|
122
|
+
...props,
|
|
123
|
+
accountId: props.accountId ?? scope.props.accountId,
|
|
124
|
+
});
|
|
125
|
+
(0, utils_1.createCloudflareTfOutput)(`${id}-workersKvFriendlyUniqueId`, scope, workersKv.friendlyUniqueId);
|
|
126
|
+
(0, utils_1.createCloudflareTfOutput)(`${id}-workersKvId`, scope, workersKv.id);
|
|
127
|
+
return workersKv;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* @summary Method to create a new Cloudflare Worker Cron Trigger
|
|
131
|
+
* @param id scoped id of the resource
|
|
132
|
+
* @param scope scope in which this resource is defined
|
|
133
|
+
* @param props workers cron trigger properties
|
|
134
|
+
* @see [CDKTF Workers Cron Trigger Module]{@link https://github.com/cdktf/cdktf-provider-cloudflare/blob/main/docs/workerCronTrigger.typescript.md}
|
|
135
|
+
*/
|
|
136
|
+
createWorkerCronTrigger(id, scope, props) {
|
|
137
|
+
if (!props)
|
|
138
|
+
throw `Props undefined for ${id}`;
|
|
139
|
+
const workerCronTrigger = new worker_cron_trigger_1.WorkerCronTrigger(scope, `${id}`, {
|
|
140
|
+
...props,
|
|
141
|
+
accountId: props.accountId ?? scope.props.accountId,
|
|
142
|
+
});
|
|
143
|
+
(0, utils_1.createCloudflareTfOutput)(`${id}-workerCronTriggerFriendlyUniqueId`, scope, workerCronTrigger.friendlyUniqueId);
|
|
144
|
+
(0, utils_1.createCloudflareTfOutput)(`${id}-workerCronTriggerId`, scope, workerCronTrigger.id);
|
|
145
|
+
return workerCronTrigger;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
exports.CloudflareWorkerManager = CloudflareWorkerManager;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { WorkerCronTriggerConfig } from '@cdktf/provider-cloudflare/lib/worker-cron-trigger';
|
|
2
|
+
import { WorkerDomainConfig } from '@cdktf/provider-cloudflare/lib/worker-domain';
|
|
3
|
+
import { WorkerRouteConfig } from '@cdktf/provider-cloudflare/lib/worker-route';
|
|
4
|
+
import { WorkerScriptConfig } from '@cdktf/provider-cloudflare/lib/worker-script';
|
|
5
|
+
import { WorkersKvConfig } from '@cdktf/provider-cloudflare/lib/workers-kv';
|
|
6
|
+
import { WorkersKvNamespaceConfig } from '@cdktf/provider-cloudflare/lib/workers-kv-namespace';
|
|
7
|
+
export interface WorkerDomainProps extends WorkerDomainConfig {
|
|
8
|
+
}
|
|
9
|
+
export interface WorkerRouteProps extends WorkerRouteConfig {
|
|
10
|
+
}
|
|
11
|
+
export interface WorkerScriptProps extends WorkerScriptConfig {
|
|
12
|
+
}
|
|
13
|
+
export interface WorkersKvNamespaceProps extends WorkersKvNamespaceConfig {
|
|
14
|
+
}
|
|
15
|
+
export interface WorkersKvProps extends WorkersKvConfig {
|
|
16
|
+
}
|
|
17
|
+
export interface WorkerCronTriggerProps extends WorkerCronTriggerConfig {
|
|
18
|
+
}
|
package/package.json
CHANGED
|
@@ -2,13 +2,14 @@ import { CloudflareProvider } from '@cdktf/provider-cloudflare/lib/provider'
|
|
|
2
2
|
import { TerraformStack } from 'cdktf'
|
|
3
3
|
import { Construct } from 'constructs'
|
|
4
4
|
import { isDevStage, isPrdStage, isTestStage, isUatStage } from '../../common'
|
|
5
|
-
import { CloudflareZoneManager } from '../services'
|
|
5
|
+
import { CloudflareWorkerManager, CloudflareZoneManager } from '../services'
|
|
6
6
|
import { CommonCloudflareStackProps } from './types'
|
|
7
7
|
|
|
8
8
|
export class CommonCloudflareConstruct extends TerraformStack {
|
|
9
9
|
declare props: CommonCloudflareStackProps
|
|
10
10
|
id: string
|
|
11
11
|
fullyQualifiedDomainName: string
|
|
12
|
+
workerManager: CloudflareWorkerManager
|
|
12
13
|
zoneManager: CloudflareZoneManager
|
|
13
14
|
|
|
14
15
|
constructor(scope: Construct, id: string, props: CommonCloudflareStackProps) {
|
|
@@ -17,6 +18,7 @@ export class CommonCloudflareConstruct extends TerraformStack {
|
|
|
17
18
|
this.id = id
|
|
18
19
|
|
|
19
20
|
this.zoneManager = new CloudflareZoneManager()
|
|
21
|
+
this.workerManager = new CloudflareWorkerManager()
|
|
20
22
|
|
|
21
23
|
this.determineFullyQualifiedDomain()
|
|
22
24
|
new CloudflareProvider(this, `${this.id}-provider`, this.props)
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { WorkerDomain } from '@cdktf/provider-cloudflare/lib/worker-domain'
|
|
2
|
+
import { WorkerRoute } from '@cdktf/provider-cloudflare/lib/worker-route'
|
|
3
|
+
import { WorkerScript } from '@cdktf/provider-cloudflare/lib/worker-script'
|
|
4
|
+
import { CommonCloudflareConstruct } from '../../common'
|
|
5
|
+
import { createCloudflareTfOutput } from '../../utils'
|
|
6
|
+
import {
|
|
7
|
+
WorkerCronTriggerProps,
|
|
8
|
+
WorkerDomainProps,
|
|
9
|
+
WorkerRouteProps,
|
|
10
|
+
WorkerScriptProps,
|
|
11
|
+
WorkersKvNamespaceProps,
|
|
12
|
+
WorkersKvProps,
|
|
13
|
+
} from './types'
|
|
14
|
+
import { WorkersKvNamespace } from '@cdktf/provider-cloudflare/lib/workers-kv-namespace'
|
|
15
|
+
import { WorkersKv } from '@cdktf/provider-cloudflare/lib/workers-kv'
|
|
16
|
+
import { WorkerCronTrigger } from '@cdktf/provider-cloudflare/lib/worker-cron-trigger'
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @classdesc Provides operations on Cloudflare Worker
|
|
20
|
+
* - A new instance of this class is injected into {@link CommonCloudflareConstruct} constructor.
|
|
21
|
+
* - If a custom construct extends {@link CommonCloudflareConstruct}, an instance is available within the context.
|
|
22
|
+
* @example
|
|
23
|
+
* ```
|
|
24
|
+
* import { CommonCloudflareConstruct, CommonCloudflareConstruct } from '@gradientedge/cdk-utils'
|
|
25
|
+
*
|
|
26
|
+
* class CustomConstruct extends CommonCloudflareConstruct {
|
|
27
|
+
* constructor(parent: Construct, id: string, props: CommonCloudflareStackProps) {
|
|
28
|
+
* super(parent, id, props)
|
|
29
|
+
* this.props = props
|
|
30
|
+
* this.workerManager.createWorkerDomain('MyWorkerDomain', this, props)
|
|
31
|
+
* }
|
|
32
|
+
* }
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export class CloudflareWorkerManager {
|
|
36
|
+
/**
|
|
37
|
+
* @summary Method to create a new Cloudflare Worker Domain
|
|
38
|
+
* @param id scoped id of the resource
|
|
39
|
+
* @param scope scope in which this resource is defined
|
|
40
|
+
* @param props worker domain properties
|
|
41
|
+
* @see [CDKTF Worker Domain Module]{@link https://github.com/cdktf/cdktf-provider-cloudflare/blob/main/docs/workerDomain.typescript.md}
|
|
42
|
+
*/
|
|
43
|
+
public createWorkerDomain(id: string, scope: CommonCloudflareConstruct, props: WorkerDomainProps) {
|
|
44
|
+
if (!props) throw `Props undefined for ${id}`
|
|
45
|
+
|
|
46
|
+
const zoneId = props.zoneId
|
|
47
|
+
? props.zoneId
|
|
48
|
+
: scope.zoneManager.resolveZone(`${id}-data-zone`, scope, { name: scope.props.domainName })?.id
|
|
49
|
+
|
|
50
|
+
const workerDomain = new WorkerDomain(scope, `${id}`, {
|
|
51
|
+
...props,
|
|
52
|
+
accountId: props.accountId ?? scope.props.accountId,
|
|
53
|
+
zoneId,
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
createCloudflareTfOutput(`${id}-workerDomainFriendlyUniqueId`, scope, workerDomain.friendlyUniqueId)
|
|
57
|
+
createCloudflareTfOutput(`${id}-workerDomainId`, scope, workerDomain.id)
|
|
58
|
+
|
|
59
|
+
return workerDomain
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* @summary Method to create a new Cloudflare Worker Route
|
|
64
|
+
* @param id scoped id of the resource
|
|
65
|
+
* @param scope scope in which this resource is defined
|
|
66
|
+
* @param props worker route properties
|
|
67
|
+
* @see [CDKTF Worker Route Module]{@link https://github.com/cdktf/cdktf-provider-cloudflare/blob/main/docs/workerRoute.typescript.md}
|
|
68
|
+
*/
|
|
69
|
+
public createWorkerRoute(id: string, scope: CommonCloudflareConstruct, props: WorkerRouteProps) {
|
|
70
|
+
if (!props) throw `Props undefined for ${id}`
|
|
71
|
+
|
|
72
|
+
const zoneId = props.zoneId
|
|
73
|
+
? props.zoneId
|
|
74
|
+
: scope.zoneManager.resolveZone(`${id}-data-zone`, scope, { name: scope.props.domainName })?.id
|
|
75
|
+
|
|
76
|
+
const workerRoute = new WorkerRoute(scope, `${id}`, {
|
|
77
|
+
...props,
|
|
78
|
+
scriptName: `${props.scriptName}-${scope.props.stage}`,
|
|
79
|
+
zoneId,
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
createCloudflareTfOutput(`${id}-workerRouteFriendlyUniqueId`, scope, workerRoute.friendlyUniqueId)
|
|
83
|
+
createCloudflareTfOutput(`${id}-workerRouteId`, scope, workerRoute.id)
|
|
84
|
+
|
|
85
|
+
return workerRoute
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* @summary Method to create a new Cloudflare Worker Script
|
|
90
|
+
* @param id scoped id of the resource
|
|
91
|
+
* @param scope scope in which this resource is defined
|
|
92
|
+
* @param props worker script properties
|
|
93
|
+
* @see [CDKTF Worker Script Module]{@link https://github.com/cdktf/cdktf-provider-cloudflare/blob/main/docs/workerScript.typescript.md}
|
|
94
|
+
*/
|
|
95
|
+
public createWorkerScript(id: string, scope: CommonCloudflareConstruct, props: WorkerScriptProps) {
|
|
96
|
+
if (!props) throw `Props undefined for ${id}`
|
|
97
|
+
|
|
98
|
+
const workerScript = new WorkerScript(scope, `${id}`, {
|
|
99
|
+
...props,
|
|
100
|
+
accountId: props.accountId ?? scope.props.accountId,
|
|
101
|
+
name: `${props.name}-${scope.props.stage}`,
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
createCloudflareTfOutput(`${id}-workerScriptFriendlyUniqueId`, scope, workerScript.friendlyUniqueId)
|
|
105
|
+
createCloudflareTfOutput(`${id}-workerScriptId`, scope, workerScript.id)
|
|
106
|
+
|
|
107
|
+
return workerScript
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* @summary Method to create a new Cloudflare Workers KV Namespace
|
|
112
|
+
* @param id scoped id of the resource
|
|
113
|
+
* @param scope scope in which this resource is defined
|
|
114
|
+
* @param props workers kv namespace properties
|
|
115
|
+
* @see [CDKTF Workers KV Namespace Module]{@link https://github.com/cdktf/cdktf-provider-cloudflare/blob/main/docs/workersKvNamespace.typescript.md}
|
|
116
|
+
*/
|
|
117
|
+
public createWorkersKvNamespace(id: string, scope: CommonCloudflareConstruct, props: WorkersKvNamespaceProps) {
|
|
118
|
+
if (!props) throw `Props undefined for ${id}`
|
|
119
|
+
|
|
120
|
+
const workersKvNamespace = new WorkersKvNamespace(scope, `${id}`, {
|
|
121
|
+
...props,
|
|
122
|
+
accountId: props.accountId ?? scope.props.accountId,
|
|
123
|
+
title: scope.isProductionStage() ? props.title : `${props.title}-${scope.props.stage}`,
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
createCloudflareTfOutput(`${id}-workersKvNamespaceFriendlyUniqueId`, scope, workersKvNamespace.friendlyUniqueId)
|
|
127
|
+
createCloudflareTfOutput(`${id}-workersKvNamespaceId`, scope, workersKvNamespace.id)
|
|
128
|
+
|
|
129
|
+
return workersKvNamespace
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* @summary Method to create a new Cloudflare Workers KV
|
|
134
|
+
* @param id scoped id of the resource
|
|
135
|
+
* @param scope scope in which this resource is defined
|
|
136
|
+
* @param props workers kv properties
|
|
137
|
+
* @see [CDKTF Workers KV Module]{@link https://github.com/cdktf/cdktf-provider-cloudflare/blob/main/docs/workersKv.typescript.md}
|
|
138
|
+
*/
|
|
139
|
+
public createWorkersKv(id: string, scope: CommonCloudflareConstruct, props: WorkersKvProps) {
|
|
140
|
+
if (!props) throw `Props undefined for ${id}`
|
|
141
|
+
|
|
142
|
+
const workersKv = new WorkersKv(scope, `${id}`, {
|
|
143
|
+
...props,
|
|
144
|
+
accountId: props.accountId ?? scope.props.accountId,
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
createCloudflareTfOutput(`${id}-workersKvFriendlyUniqueId`, scope, workersKv.friendlyUniqueId)
|
|
148
|
+
createCloudflareTfOutput(`${id}-workersKvId`, scope, workersKv.id)
|
|
149
|
+
|
|
150
|
+
return workersKv
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* @summary Method to create a new Cloudflare Worker Cron Trigger
|
|
155
|
+
* @param id scoped id of the resource
|
|
156
|
+
* @param scope scope in which this resource is defined
|
|
157
|
+
* @param props workers cron trigger properties
|
|
158
|
+
* @see [CDKTF Workers Cron Trigger Module]{@link https://github.com/cdktf/cdktf-provider-cloudflare/blob/main/docs/workerCronTrigger.typescript.md}
|
|
159
|
+
*/
|
|
160
|
+
public createWorkerCronTrigger(id: string, scope: CommonCloudflareConstruct, props: WorkerCronTriggerProps) {
|
|
161
|
+
if (!props) throw `Props undefined for ${id}`
|
|
162
|
+
|
|
163
|
+
const workerCronTrigger = new WorkerCronTrigger(scope, `${id}`, {
|
|
164
|
+
...props,
|
|
165
|
+
accountId: props.accountId ?? scope.props.accountId,
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
createCloudflareTfOutput(`${id}-workerCronTriggerFriendlyUniqueId`, scope, workerCronTrigger.friendlyUniqueId)
|
|
169
|
+
createCloudflareTfOutput(`${id}-workerCronTriggerId`, scope, workerCronTrigger.id)
|
|
170
|
+
|
|
171
|
+
return workerCronTrigger
|
|
172
|
+
}
|
|
173
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { WorkerCronTriggerConfig } from '@cdktf/provider-cloudflare/lib/worker-cron-trigger'
|
|
2
|
+
import { WorkerDomainConfig } from '@cdktf/provider-cloudflare/lib/worker-domain'
|
|
3
|
+
import { WorkerRouteConfig } from '@cdktf/provider-cloudflare/lib/worker-route'
|
|
4
|
+
import { WorkerScriptConfig } from '@cdktf/provider-cloudflare/lib/worker-script'
|
|
5
|
+
import { WorkersKvConfig } from '@cdktf/provider-cloudflare/lib/workers-kv'
|
|
6
|
+
import { WorkersKvNamespaceConfig } from '@cdktf/provider-cloudflare/lib/workers-kv-namespace'
|
|
7
|
+
|
|
8
|
+
export interface WorkerDomainProps extends WorkerDomainConfig {}
|
|
9
|
+
export interface WorkerRouteProps extends WorkerRouteConfig {}
|
|
10
|
+
export interface WorkerScriptProps extends WorkerScriptConfig {}
|
|
11
|
+
export interface WorkersKvNamespaceProps extends WorkersKvNamespaceConfig {}
|
|
12
|
+
export interface WorkersKvProps extends WorkersKvConfig {}
|
|
13
|
+
export interface WorkerCronTriggerProps extends WorkerCronTriggerConfig {}
|