@gradientedge/cdk-utils 9.4.0 → 9.5.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/construct/index.d.ts +1 -0
- package/dist/src/lib/cloudflare/construct/index.js +1 -0
- package/dist/src/lib/cloudflare/construct/worker-site/index.d.ts +2 -0
- package/dist/src/lib/cloudflare/construct/worker-site/index.js +18 -0
- package/dist/src/lib/cloudflare/construct/worker-site/main.d.ts +43 -0
- package/dist/src/lib/cloudflare/construct/worker-site/main.js +80 -0
- package/dist/src/lib/cloudflare/construct/worker-site/types.d.ts +9 -0
- package/dist/src/lib/cloudflare/construct/worker-site/types.js +2 -0
- package/package.json +1 -1
- package/src/lib/cloudflare/construct/index.ts +1 -0
- package/src/lib/cloudflare/construct/worker-site/index.ts +2 -0
- package/src/lib/cloudflare/construct/worker-site/main.ts +94 -0
- package/src/lib/cloudflare/construct/worker-site/types.ts +10 -0
|
@@ -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,43 @@
|
|
|
1
|
+
import { DataCloudflareZone } from '@cdktf/provider-cloudflare/lib/data-cloudflare-zone';
|
|
2
|
+
import { WorkerScript, WorkerScriptPlainTextBinding, WorkerScriptSecretTextBinding } from '@cdktf/provider-cloudflare/lib/worker-script';
|
|
3
|
+
import { Zone } from '@cdktf/provider-cloudflare/lib/zone';
|
|
4
|
+
import { Construct } from 'constructs';
|
|
5
|
+
import { CommonCloudflareConstruct } from '../../common';
|
|
6
|
+
import { CloudflareWorkerSiteProps } from './types';
|
|
7
|
+
/**
|
|
8
|
+
* @classdesc Provides a construct to create and deploy a cloudflare worker site
|
|
9
|
+
* @example
|
|
10
|
+
* import { CloudflareWorkerSite, CloudflareWorkerSiteProps } '@gradientedge/cdk-utils'
|
|
11
|
+
* import { Construct } from 'constructs'
|
|
12
|
+
*
|
|
13
|
+
* class CustomConstruct extends CloudflareWorkerSite {
|
|
14
|
+
* constructor(parent: Construct, id: string, props: CloudflareWorkerSiteProps) {
|
|
15
|
+
* super(parent, id, props)
|
|
16
|
+
* this.props = props
|
|
17
|
+
* this.id = id
|
|
18
|
+
* this.initResources()
|
|
19
|
+
* }
|
|
20
|
+
* }
|
|
21
|
+
*/
|
|
22
|
+
export declare class CloudflareWorkerSite extends CommonCloudflareConstruct {
|
|
23
|
+
props: CloudflareWorkerSiteProps;
|
|
24
|
+
siteZone: DataCloudflareZone | Zone;
|
|
25
|
+
siteWorkerScript: WorkerScript;
|
|
26
|
+
workerPlainTextBindingEnvironmentVariables: WorkerScriptPlainTextBinding[];
|
|
27
|
+
workerSecretTextBindingEnvironmentVariables: WorkerScriptSecretTextBinding[];
|
|
28
|
+
constructor(parent: Construct, id: string, props: CloudflareWorkerSiteProps);
|
|
29
|
+
/**
|
|
30
|
+
* @summary Initialise and provision resources
|
|
31
|
+
*/
|
|
32
|
+
protected initResources(): void;
|
|
33
|
+
/**
|
|
34
|
+
* @summary Resolve the zone to use for the worker site
|
|
35
|
+
*/
|
|
36
|
+
protected resolveZone(): void;
|
|
37
|
+
/**
|
|
38
|
+
* @summary Resolve the environment variables to use for the static site
|
|
39
|
+
*/
|
|
40
|
+
protected resolveEnvironmentVariables(): void;
|
|
41
|
+
protected createWorker(): void;
|
|
42
|
+
protected createWorkerDomain(): void;
|
|
43
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CloudflareWorkerSite = void 0;
|
|
4
|
+
const cdktf_1 = require("cdktf");
|
|
5
|
+
const common_1 = require("../../common");
|
|
6
|
+
/**
|
|
7
|
+
* @classdesc Provides a construct to create and deploy a cloudflare worker site
|
|
8
|
+
* @example
|
|
9
|
+
* import { CloudflareWorkerSite, CloudflareWorkerSiteProps } '@gradientedge/cdk-utils'
|
|
10
|
+
* import { Construct } from 'constructs'
|
|
11
|
+
*
|
|
12
|
+
* class CustomConstruct extends CloudflareWorkerSite {
|
|
13
|
+
* constructor(parent: Construct, id: string, props: CloudflareWorkerSiteProps) {
|
|
14
|
+
* super(parent, id, props)
|
|
15
|
+
* this.props = props
|
|
16
|
+
* this.id = id
|
|
17
|
+
* this.initResources()
|
|
18
|
+
* }
|
|
19
|
+
* }
|
|
20
|
+
*/
|
|
21
|
+
class CloudflareWorkerSite extends common_1.CommonCloudflareConstruct {
|
|
22
|
+
/* worker site resources */
|
|
23
|
+
siteZone;
|
|
24
|
+
siteWorkerScript;
|
|
25
|
+
workerPlainTextBindingEnvironmentVariables;
|
|
26
|
+
workerSecretTextBindingEnvironmentVariables;
|
|
27
|
+
constructor(parent, id, props) {
|
|
28
|
+
super(parent, id, props);
|
|
29
|
+
this.props = props;
|
|
30
|
+
this.id = id;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* @summary Initialise and provision resources
|
|
34
|
+
*/
|
|
35
|
+
initResources() {
|
|
36
|
+
this.resolveZone();
|
|
37
|
+
this.resolveEnvironmentVariables();
|
|
38
|
+
this.createWorker();
|
|
39
|
+
this.createWorkerDomain();
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* @summary Resolve the zone to use for the worker site
|
|
43
|
+
*/
|
|
44
|
+
resolveZone() {
|
|
45
|
+
if (this.props.useExistingZone) {
|
|
46
|
+
this.siteZone = this.zoneManager.resolveZone(`${this.id}-zone`, this);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
this.siteZone = this.zoneManager.createZone(`${this.id}-zone`, this, this.props.siteZone);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* @summary Resolve the environment variables to use for the static site
|
|
54
|
+
*/
|
|
55
|
+
resolveEnvironmentVariables() {
|
|
56
|
+
this.props.siteWorkerScript = {
|
|
57
|
+
...this.props.siteWorkerScript,
|
|
58
|
+
plainTextBinding: this.workerPlainTextBindingEnvironmentVariables,
|
|
59
|
+
secretTextBinding: this.workerSecretTextBindingEnvironmentVariables,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
createWorker() {
|
|
63
|
+
const workerContent = new cdktf_1.TerraformAsset(this, `${this.id}-worker-content`, {
|
|
64
|
+
path: this.props.siteWorkerAsset,
|
|
65
|
+
type: cdktf_1.AssetType.FILE,
|
|
66
|
+
});
|
|
67
|
+
this.siteWorkerScript = this.workerManager.createWorkerScript(`${this.id}-worker-script`, this, {
|
|
68
|
+
...this.props.siteWorkerScript,
|
|
69
|
+
content: cdktf_1.Fn.file(workerContent.path),
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
createWorkerDomain() {
|
|
73
|
+
this.workerManager.createWorkerDomain(`${this.id}-worker-domain`, this, {
|
|
74
|
+
...this.props.siteWorkerDomain,
|
|
75
|
+
hostname: `${this.props.siteSubDomain}.${this.props.domainName}`,
|
|
76
|
+
service: this.siteWorkerScript.name,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.CloudflareWorkerSite = CloudflareWorkerSite;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CommonCloudflareStackProps } from '../../common';
|
|
2
|
+
import { WorkerDomainProps, WorkerScriptProps, ZoneProps } from '../../services';
|
|
3
|
+
export interface CloudflareWorkerSiteProps extends CommonCloudflareStackProps {
|
|
4
|
+
siteSubDomain: string;
|
|
5
|
+
siteZone: ZoneProps;
|
|
6
|
+
siteWorkerScript: WorkerScriptProps;
|
|
7
|
+
siteWorkerDomain: WorkerDomainProps;
|
|
8
|
+
siteWorkerAsset: string;
|
|
9
|
+
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { DataCloudflareZone } from '@cdktf/provider-cloudflare/lib/data-cloudflare-zone'
|
|
2
|
+
import {
|
|
3
|
+
WorkerScript,
|
|
4
|
+
WorkerScriptPlainTextBinding,
|
|
5
|
+
WorkerScriptSecretTextBinding,
|
|
6
|
+
} from '@cdktf/provider-cloudflare/lib/worker-script'
|
|
7
|
+
import { Zone } from '@cdktf/provider-cloudflare/lib/zone'
|
|
8
|
+
import { Fn, TerraformAsset, AssetType } from 'cdktf'
|
|
9
|
+
import { Construct } from 'constructs'
|
|
10
|
+
import { CommonCloudflareConstruct } from '../../common'
|
|
11
|
+
import { CloudflareWorkerSiteProps } from './types'
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @classdesc Provides a construct to create and deploy a cloudflare worker site
|
|
15
|
+
* @example
|
|
16
|
+
* import { CloudflareWorkerSite, CloudflareWorkerSiteProps } '@gradientedge/cdk-utils'
|
|
17
|
+
* import { Construct } from 'constructs'
|
|
18
|
+
*
|
|
19
|
+
* class CustomConstruct extends CloudflareWorkerSite {
|
|
20
|
+
* constructor(parent: Construct, id: string, props: CloudflareWorkerSiteProps) {
|
|
21
|
+
* super(parent, id, props)
|
|
22
|
+
* this.props = props
|
|
23
|
+
* this.id = id
|
|
24
|
+
* this.initResources()
|
|
25
|
+
* }
|
|
26
|
+
* }
|
|
27
|
+
*/
|
|
28
|
+
export class CloudflareWorkerSite extends CommonCloudflareConstruct {
|
|
29
|
+
declare props: CloudflareWorkerSiteProps
|
|
30
|
+
|
|
31
|
+
/* worker site resources */
|
|
32
|
+
siteZone: DataCloudflareZone | Zone
|
|
33
|
+
siteWorkerScript: WorkerScript
|
|
34
|
+
workerPlainTextBindingEnvironmentVariables: WorkerScriptPlainTextBinding[]
|
|
35
|
+
workerSecretTextBindingEnvironmentVariables: WorkerScriptSecretTextBinding[]
|
|
36
|
+
|
|
37
|
+
constructor(parent: Construct, id: string, props: CloudflareWorkerSiteProps) {
|
|
38
|
+
super(parent, id, props)
|
|
39
|
+
this.props = props
|
|
40
|
+
this.id = id
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @summary Initialise and provision resources
|
|
45
|
+
*/
|
|
46
|
+
protected initResources() {
|
|
47
|
+
this.resolveZone()
|
|
48
|
+
this.resolveEnvironmentVariables()
|
|
49
|
+
this.createWorker()
|
|
50
|
+
this.createWorkerDomain()
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @summary Resolve the zone to use for the worker site
|
|
55
|
+
*/
|
|
56
|
+
protected resolveZone() {
|
|
57
|
+
if (this.props.useExistingZone) {
|
|
58
|
+
this.siteZone = this.zoneManager.resolveZone(`${this.id}-zone`, this)
|
|
59
|
+
} else {
|
|
60
|
+
this.siteZone = this.zoneManager.createZone(`${this.id}-zone`, this, this.props.siteZone)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @summary Resolve the environment variables to use for the static site
|
|
66
|
+
*/
|
|
67
|
+
protected resolveEnvironmentVariables() {
|
|
68
|
+
this.props.siteWorkerScript = {
|
|
69
|
+
...this.props.siteWorkerScript,
|
|
70
|
+
plainTextBinding: this.workerPlainTextBindingEnvironmentVariables,
|
|
71
|
+
secretTextBinding: this.workerSecretTextBindingEnvironmentVariables,
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
protected createWorker() {
|
|
76
|
+
const workerContent = new TerraformAsset(this, `${this.id}-worker-content`, {
|
|
77
|
+
path: this.props.siteWorkerAsset,
|
|
78
|
+
type: AssetType.FILE,
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
this.siteWorkerScript = this.workerManager.createWorkerScript(`${this.id}-worker-script`, this, {
|
|
82
|
+
...this.props.siteWorkerScript,
|
|
83
|
+
content: Fn.file(workerContent.path),
|
|
84
|
+
})
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
protected createWorkerDomain() {
|
|
88
|
+
this.workerManager.createWorkerDomain(`${this.id}-worker-domain`, this, {
|
|
89
|
+
...this.props.siteWorkerDomain,
|
|
90
|
+
hostname: `${this.props.siteSubDomain}.${this.props.domainName}`,
|
|
91
|
+
service: this.siteWorkerScript.name,
|
|
92
|
+
})
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CommonCloudflareStackProps } from '../../common'
|
|
2
|
+
import { WorkerDomainProps, WorkerScriptProps, RecordProps, ZoneProps } from '../../services'
|
|
3
|
+
|
|
4
|
+
export interface CloudflareWorkerSiteProps extends CommonCloudflareStackProps {
|
|
5
|
+
siteSubDomain: string
|
|
6
|
+
siteZone: ZoneProps
|
|
7
|
+
siteWorkerScript: WorkerScriptProps
|
|
8
|
+
siteWorkerDomain: WorkerDomainProps
|
|
9
|
+
siteWorkerAsset: string
|
|
10
|
+
}
|