@powerlines/plugin-cloudflare 0.4.2 → 0.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/index.cjs CHANGED
@@ -86,12 +86,14 @@ function plugin(options = {}) {
86
86
  else throw new Error("Unable to determine the Cloudflare API token. Please set the `CLOUDFLARE_API_TOKEN` environment variable.");
87
87
  }
88
88
  await this.pulumi.setConfig("cloudflare:apiToken", { value: apiToken });
89
+ const provider = new _pulumi_cloudflare.Provider("cloudflare-provider", { apiToken });
89
90
  const zone = await _pulumi_cloudflare.getZone({ filter: {
90
91
  account: { id: this.config.cloudflare.accountId },
91
92
  name: this.config.cloudflare.domain
92
- } });
93
+ } }, { provider });
93
94
  const workerScripts = [];
94
95
  const workerRoutes = [];
96
+ const dnsRecords = [];
95
97
  for (const worker of this.workers) {
96
98
  const workerScript = new _pulumi_cloudflare.WorkersScript(`${this.config.organization ? `${this.config.organization}.` : ""}${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.name) === (0, _stryke_string_format_kebab_case.kebabCase)(worker.metadata.name) ? (0, _stryke_string_format_kebab_case.kebabCase)(this.config.name) : `${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.name)}.${(0, _stryke_string_format_kebab_case.kebabCase)(worker.metadata.name)}`}.${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.mode)}.worker-script`, (0, defu.default)({
97
99
  accountId: this.config.cloudflare.accountId,
@@ -101,18 +103,28 @@ function plugin(options = {}) {
101
103
  }, worker.metadata, {
102
104
  compatibilityDate: this.config.compatibilityDate?.cloudflare?.toString(),
103
105
  compatibilityFlags: ["nodejs_als"]
104
- }));
106
+ }), { provider });
105
107
  workerScripts.push(workerScript);
106
108
  const workerRoute = new _pulumi_cloudflare.WorkersRoute(`${this.config.organization ? `${this.config.organization}.` : ""}${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.name) === (0, _stryke_string_format_kebab_case.kebabCase)(worker.metadata.name) ? (0, _stryke_string_format_kebab_case.kebabCase)(this.config.name) : `${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.name)}-${(0, _stryke_string_format_kebab_case.kebabCase)(worker.metadata.name)}`}.${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.mode)}.worker-route`, (0, defu.default)({
107
109
  zoneId: zone.id,
108
110
  pattern: worker.metadata.pattern.replace("{domain}", this.config.cloudflare.domain),
109
111
  script: workerScript.scriptName
110
- }, worker.metadata));
112
+ }, worker.metadata), { provider });
111
113
  workerRoutes.push(workerRoute);
114
+ const dnsRecord = new _pulumi_cloudflare.DnsRecord(`${this.config.organization ? `${this.config.organization}.` : ""}${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.name) === (0, _stryke_string_format_kebab_case.kebabCase)(worker.metadata.name) ? (0, _stryke_string_format_kebab_case.kebabCase)(this.config.name) : `${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.name)}-${(0, _stryke_string_format_kebab_case.kebabCase)(worker.metadata.name)}`}.${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.mode)}.dns-record`, {
115
+ name: workerRoute.pattern,
116
+ type: "A",
117
+ content: "192.0.2.1",
118
+ zoneId: zone.id,
119
+ proxied: true,
120
+ ttl: 1
121
+ }, { provider });
122
+ dnsRecords.push(dnsRecord);
112
123
  }
113
124
  return {
114
125
  workerScripts,
115
- workerRoutes
126
+ workerRoutes,
127
+ dnsRecords
116
128
  };
117
129
  }
118
130
  }];
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.tsx"],"mappings":";;;;;;;;;YA6CY,MAAA;IACR,UAAA,GAAa,uBAAA;EAAA;AAAA;;AAJY;;iBAWb,MAAA,kBACG,uBAAA,GAA0B,uBAAA,CAAA,CAC3C,OAAA,GAAS,uBAAA,GAkLJ,MAAA,CAAO,QAAA"}
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.tsx"],"mappings":";;;;;;;;;YA6CY,MAAA;IACR,UAAA,GAAa,uBAAA;EAAA;AAAA;;AAJY;;iBAWb,MAAA,kBACG,uBAAA,GAA0B,uBAAA,CAAA,CAC3C,OAAA,GAAS,uBAAA,GAgNJ,MAAA,CAAO,QAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.tsx"],"mappings":";;;;;;;;;YA6CY,MAAA;IACR,UAAA,GAAa,uBAAA;EAAA;AAAA;;AAJY;;iBAWb,MAAA,kBACG,uBAAA,GAA0B,uBAAA,CAAA,CAC3C,OAAA,GAAS,uBAAA,GAkLJ,MAAA,CAAO,QAAA"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.tsx"],"mappings":";;;;;;;;;YA6CY,MAAA;IACR,UAAA,GAAa,uBAAA;EAAA;AAAA;;AAJY;;iBAWb,MAAA,kBACG,uBAAA,GAA0B,uBAAA,CAAA,CAC3C,OAAA,GAAS,uBAAA,GAgNJ,MAAA,CAAO,QAAA"}
package/dist/index.mjs CHANGED
@@ -81,12 +81,14 @@ function plugin(options = {}) {
81
81
  else throw new Error("Unable to determine the Cloudflare API token. Please set the `CLOUDFLARE_API_TOKEN` environment variable.");
82
82
  }
83
83
  await this.pulumi.setConfig("cloudflare:apiToken", { value: apiToken });
84
+ const provider = new pulumiCloudflare.Provider("cloudflare-provider", { apiToken });
84
85
  const zone = await pulumiCloudflare.getZone({ filter: {
85
86
  account: { id: this.config.cloudflare.accountId },
86
87
  name: this.config.cloudflare.domain
87
- } });
88
+ } }, { provider });
88
89
  const workerScripts = [];
89
90
  const workerRoutes = [];
91
+ const dnsRecords = [];
90
92
  for (const worker of this.workers) {
91
93
  const workerScript = new pulumiCloudflare.WorkersScript(`${this.config.organization ? `${this.config.organization}.` : ""}${kebabCase(this.config.name) === kebabCase(worker.metadata.name) ? kebabCase(this.config.name) : `${kebabCase(this.config.name)}.${kebabCase(worker.metadata.name)}`}.${kebabCase(this.config.mode)}.worker-script`, defu({
92
94
  accountId: this.config.cloudflare.accountId,
@@ -96,18 +98,28 @@ function plugin(options = {}) {
96
98
  }, worker.metadata, {
97
99
  compatibilityDate: this.config.compatibilityDate?.cloudflare?.toString(),
98
100
  compatibilityFlags: ["nodejs_als"]
99
- }));
101
+ }), { provider });
100
102
  workerScripts.push(workerScript);
101
103
  const workerRoute = new pulumiCloudflare.WorkersRoute(`${this.config.organization ? `${this.config.organization}.` : ""}${kebabCase(this.config.name) === kebabCase(worker.metadata.name) ? kebabCase(this.config.name) : `${kebabCase(this.config.name)}-${kebabCase(worker.metadata.name)}`}.${kebabCase(this.config.mode)}.worker-route`, defu({
102
104
  zoneId: zone.id,
103
105
  pattern: worker.metadata.pattern.replace("{domain}", this.config.cloudflare.domain),
104
106
  script: workerScript.scriptName
105
- }, worker.metadata));
107
+ }, worker.metadata), { provider });
106
108
  workerRoutes.push(workerRoute);
109
+ const dnsRecord = new pulumiCloudflare.DnsRecord(`${this.config.organization ? `${this.config.organization}.` : ""}${kebabCase(this.config.name) === kebabCase(worker.metadata.name) ? kebabCase(this.config.name) : `${kebabCase(this.config.name)}-${kebabCase(worker.metadata.name)}`}.${kebabCase(this.config.mode)}.dns-record`, {
110
+ name: workerRoute.pattern,
111
+ type: "A",
112
+ content: "192.0.2.1",
113
+ zoneId: zone.id,
114
+ proxied: true,
115
+ ttl: 1
116
+ }, { provider });
117
+ dnsRecords.push(dnsRecord);
107
118
  }
108
119
  return {
109
120
  workerScripts,
110
- workerRoutes
121
+ workerRoutes,
122
+ dnsRecords
111
123
  };
112
124
  }
113
125
  }];
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/index.tsx"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { For } from \"@alloy-js/core\";\nimport { getCloudflarePreset } from \"@cloudflare/unenv-preset\";\nimport { render } from \"@powerlines/plugin-alloy/render\";\nimport { readEnvTypeReflection } from \"@powerlines/plugin-env/helpers\";\nimport { resolveModule } from \"@powerlines/plugin-esbuild/helpers/resolve\";\nimport unenv from \"@powerlines/plugin-unenv\";\nimport * as pulumiCloudflare from \"@pulumi/cloudflare\";\nimport { omit } from \"@stryke/helpers/omit\";\nimport { joinPaths, replaceExtension } from \"@stryke/path\";\nimport { kebabCase } from \"@stryke/string-format/kebab-case\";\nimport { isFunction } from \"@stryke/type-checks/is-function\";\nimport defu from \"defu\";\nimport { Plugin } from \"powerlines\";\nimport { CloudflareEnvBuiltin } from \"./components\";\nimport { CloudflareBuiltin } from \"./components/cloudflare-builtin\";\nimport { WorkerEntry } from \"./components/worker-entry\";\nimport {\n CloudflarePluginContext,\n CloudflarePluginOptions,\n CloudflareWorkerEntryModule\n} from \"./types/plugin\";\nimport { WorkerModule } from \"./types/worker-module\";\n\nexport * from \"./components\";\nexport type * from \"./types\";\n\ndeclare module \"powerlines\" {\n interface Config {\n cloudflare?: CloudflarePluginOptions;\n }\n}\n\n/**\n * A Powerlines plugin to assist in developing other Powerlines plugins.\n */\nexport function plugin<\n TContext extends CloudflarePluginContext = CloudflarePluginContext\n>(options: CloudflarePluginOptions = {}) {\n return [\n unenv(options.unenv),\n {\n name: \"cloudflare\",\n config() {\n return {\n cloudflare: defu(omit(options, [\"unenv\"]), {}),\n resolve: {\n skipNodeModulesBundle: false\n },\n unenv: {\n presets: [\n // eslint-disable-next-line ts/no-unsafe-call\n getCloudflarePreset({\n compatibilityDate: this.config.compatibilityDate?.toString(),\n compatibilityFlags: [\"nodejs_als\"]\n })\n ]\n }\n };\n },\n configResolved() {\n this.devDependencies[\"@cloudflare/workers-types\"] = \"^4.20240616.0\";\n },\n async prepare() {\n const result = await readEnvTypeReflection(this, \"env\");\n\n return render(\n this,\n <>\n <CloudflareBuiltin />\n <CloudflareEnvBuiltin reflection={result} />\n </>\n );\n },\n build: {\n order: \"pre\",\n async handler() {\n this.workers = await Promise.all(\n this.entry.map(async (entry, i, arr) => {\n if (!entry.input) {\n throw new Error(\n `Cloudflare Worker entry \"${entry.file}\" is missing an input file.`\n );\n }\n\n const workerModule = await resolveModule<WorkerModule>(\n this,\n entry.input\n );\n if (!workerModule?.default) {\n throw new Error(\n `Cloudflare Worker entry \"${\n entry.file\n }\" does not export a default handler. The Powerlines Cloudflare plugin expects each Worker entry module to export a default object matching the \\`ExportedHandler\\` interface from \"@cloudflare/workers-types\".`\n );\n }\n\n const name =\n workerModule.metadata?.name ||\n replaceExtension(entry.input.file || entry.file) ||\n arr.length > 1\n ? `${this.config.name}-${i}`\n : this.config.name;\n\n return {\n metadata: {\n name,\n pattern: `${name}.{domain}`,\n entry\n },\n fetch: isFunction(workerModule.default.fetch),\n tail: isFunction(workerModule.default.tail),\n trace: isFunction(workerModule.default.trace),\n tailStream: isFunction(workerModule.default.tailStream),\n scheduled: isFunction(workerModule.default.scheduled),\n test: isFunction(workerModule.default.test),\n email: isFunction(workerModule.default.email),\n queue: isFunction(workerModule.default.queue)\n } satisfies CloudflareWorkerEntryModule;\n })\n );\n\n return render(\n this,\n <For each={this.workers}>\n {worker => <WorkerEntry worker={worker} />}\n </For>\n );\n }\n },\n async deployPulumi() {\n let apiToken = process.env.CLOUDFLARE_API_TOKEN;\n if (!apiToken) {\n apiToken = this.config.cloudflare.apiToken;\n if (apiToken) {\n this.warn(\n \"If possible, please use the `CLOUDFLARE_API_TOKEN` environment variable instead of using the `apiToken` option directly. The `apiToken` option will work; however, this is a less secure method of configuration.\"\n );\n } else {\n throw new Error(\n \"Unable to determine the Cloudflare API token. Please set the `CLOUDFLARE_API_TOKEN` environment variable.\"\n );\n }\n }\n\n await this.pulumi.setConfig(\"cloudflare:apiToken\", {\n value: apiToken\n });\n\n const zone = await pulumiCloudflare.getZone({\n filter: {\n account: { id: this.config.cloudflare.accountId },\n name: this.config.cloudflare.domain\n }\n });\n\n const workerScripts = [] as pulumiCloudflare.WorkersScript[];\n const workerRoutes = [] as pulumiCloudflare.WorkersRoute[];\n for (const worker of this.workers) {\n const workerScript = new pulumiCloudflare.WorkersScript(\n `${this.config.organization ? `${this.config.organization}.` : \"\"}${\n kebabCase(this.config.name) === kebabCase(worker.metadata.name)\n ? kebabCase(this.config.name)\n : `${kebabCase(this.config.name)}.${kebabCase(\n worker.metadata.name\n )}`\n }.${kebabCase(this.config.mode)}.worker-script`,\n defu(\n {\n accountId: this.config.cloudflare.accountId,\n scriptName: worker.metadata.name,\n contentFile: joinPaths(\n this.config.output.publishPath,\n \"index.js\"\n ),\n module: true\n },\n worker.metadata,\n {\n compatibilityDate:\n this.config.compatibilityDate?.cloudflare?.toString() as string,\n compatibilityFlags: [\"nodejs_als\"]\n }\n ) as pulumiCloudflare.WorkersScriptArgs\n );\n workerScripts.push(workerScript);\n\n const workerRoute = new pulumiCloudflare.WorkersRoute(\n `${this.config.organization ? `${this.config.organization}.` : \"\"}${\n kebabCase(this.config.name) === kebabCase(worker.metadata.name)\n ? kebabCase(this.config.name)\n : `${kebabCase(this.config.name)}-${kebabCase(\n worker.metadata.name\n )}`\n }.${kebabCase(this.config.mode)}.worker-route`,\n defu(\n {\n zoneId: zone.id,\n pattern: worker.metadata.pattern.replace(\n \"{domain}\",\n this.config.cloudflare.domain\n ),\n script: workerScript.scriptName\n },\n worker.metadata\n )\n );\n workerRoutes.push(workerRoute);\n }\n\n return {\n workerScripts,\n workerRoutes\n };\n }\n }\n ] as Plugin<TContext>[];\n}\n\nexport default plugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAgDA,SAAA,OAAA,UAAA,EAAA,EAAA;;EAEE,MAAA;EACE,SAAC;AACH,UAAA;IACK,YAAS,KAAM,KAAA,SAAA,CAA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A,KAAA,OAAA,KAAA,CAAA,GAAA,UAAA,OAAA,SAAA,KAAA,GAAA,GAAA,UAAA,KAAA,OAAA,KAAA,CAAA,gBAAA,KAAA;KACb,QAAQ,KAAG;KACX,SAAI,OAAU,SAAA,QAAA,QAAA,YAAA,KAAA,OAAA,WAAA,OAAA;KACd,QAAO,aAAI;KACZ,EAAE,OAAO,SAAS,CAAC;AACpB,iBAAK,KAAA,YAAA;;AAEP,UAAM;IACJ;IACA;IACD"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/index.tsx"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { For } from \"@alloy-js/core\";\nimport { getCloudflarePreset } from \"@cloudflare/unenv-preset\";\nimport { render } from \"@powerlines/plugin-alloy/render\";\nimport { readEnvTypeReflection } from \"@powerlines/plugin-env/helpers\";\nimport { resolveModule } from \"@powerlines/plugin-esbuild/helpers/resolve\";\nimport unenv from \"@powerlines/plugin-unenv\";\nimport * as pulumiCloudflare from \"@pulumi/cloudflare\";\nimport { omit } from \"@stryke/helpers/omit\";\nimport { joinPaths, replaceExtension } from \"@stryke/path\";\nimport { kebabCase } from \"@stryke/string-format/kebab-case\";\nimport { isFunction } from \"@stryke/type-checks/is-function\";\nimport defu from \"defu\";\nimport { Plugin } from \"powerlines\";\nimport { CloudflareEnvBuiltin } from \"./components\";\nimport { CloudflareBuiltin } from \"./components/cloudflare-builtin\";\nimport { WorkerEntry } from \"./components/worker-entry\";\nimport {\n CloudflarePluginContext,\n CloudflarePluginOptions,\n CloudflareWorkerEntryModule\n} from \"./types/plugin\";\nimport { WorkerModule } from \"./types/worker-module\";\n\nexport * from \"./components\";\nexport type * from \"./types\";\n\ndeclare module \"powerlines\" {\n interface Config {\n cloudflare?: CloudflarePluginOptions;\n }\n}\n\n/**\n * A Powerlines plugin to assist in developing other Powerlines plugins.\n */\nexport function plugin<\n TContext extends CloudflarePluginContext = CloudflarePluginContext\n>(options: CloudflarePluginOptions = {}) {\n return [\n unenv(options.unenv),\n {\n name: \"cloudflare\",\n config() {\n return {\n cloudflare: defu(omit(options, [\"unenv\"]), {}),\n resolve: {\n skipNodeModulesBundle: false\n },\n unenv: {\n presets: [\n getCloudflarePreset({\n compatibilityDate: this.config.compatibilityDate?.toString(),\n compatibilityFlags: [\"nodejs_als\"]\n })\n ]\n }\n };\n },\n configResolved() {\n this.devDependencies[\"@cloudflare/workers-types\"] = \"^4.20240616.0\";\n },\n async prepare() {\n const result = await readEnvTypeReflection(this, \"env\");\n\n return render(\n this,\n <>\n <CloudflareBuiltin />\n <CloudflareEnvBuiltin reflection={result} />\n </>\n );\n },\n build: {\n order: \"pre\",\n async handler() {\n this.workers = await Promise.all(\n this.entry.map(async (entry, i, arr) => {\n if (!entry.input) {\n throw new Error(\n `Cloudflare Worker entry \"${entry.file}\" is missing an input file.`\n );\n }\n\n const workerModule = await resolveModule<WorkerModule>(\n this,\n entry.input\n );\n if (!workerModule?.default) {\n throw new Error(\n `Cloudflare Worker entry \"${\n entry.file\n }\" does not export a default handler. The Powerlines Cloudflare plugin expects each Worker entry module to export a default object matching the \\`ExportedHandler\\` interface from \"@cloudflare/workers-types\".`\n );\n }\n\n const name =\n workerModule.metadata?.name ||\n replaceExtension(entry.input.file || entry.file) ||\n arr.length > 1\n ? `${this.config.name}-${i}`\n : this.config.name;\n\n return {\n metadata: {\n name,\n pattern: `${name}.{domain}`,\n entry\n },\n fetch: isFunction(workerModule.default.fetch),\n tail: isFunction(workerModule.default.tail),\n trace: isFunction(workerModule.default.trace),\n tailStream: isFunction(workerModule.default.tailStream),\n scheduled: isFunction(workerModule.default.scheduled),\n test: isFunction(workerModule.default.test),\n email: isFunction(workerModule.default.email),\n queue: isFunction(workerModule.default.queue)\n } satisfies CloudflareWorkerEntryModule;\n })\n );\n\n return render(\n this,\n <For each={this.workers}>\n {worker => <WorkerEntry worker={worker} />}\n </For>\n );\n }\n },\n async deployPulumi() {\n let apiToken = process.env.CLOUDFLARE_API_TOKEN;\n if (!apiToken) {\n apiToken = this.config.cloudflare.apiToken;\n if (apiToken) {\n this.warn(\n \"If possible, please use the `CLOUDFLARE_API_TOKEN` environment variable instead of using the `apiToken` option directly. The `apiToken` option will work; however, this is a less secure method of configuration.\"\n );\n } else {\n throw new Error(\n \"Unable to determine the Cloudflare API token. Please set the `CLOUDFLARE_API_TOKEN` environment variable.\"\n );\n }\n }\n\n await this.pulumi.setConfig(\"cloudflare:apiToken\", {\n value: apiToken\n });\n\n const provider = new pulumiCloudflare.Provider(\"cloudflare-provider\", {\n apiToken\n });\n\n const zone = await pulumiCloudflare.getZone(\n {\n filter: {\n account: { id: this.config.cloudflare.accountId },\n name: this.config.cloudflare.domain\n }\n },\n { provider }\n );\n\n const workerScripts = [] as pulumiCloudflare.WorkersScript[];\n const workerRoutes = [] as pulumiCloudflare.WorkersRoute[];\n const dnsRecords = [] as pulumiCloudflare.DnsRecord[];\n for (const worker of this.workers) {\n const workerScript = new pulumiCloudflare.WorkersScript(\n `${this.config.organization ? `${this.config.organization}.` : \"\"}${\n kebabCase(this.config.name) === kebabCase(worker.metadata.name)\n ? kebabCase(this.config.name)\n : `${kebabCase(this.config.name)}.${kebabCase(\n worker.metadata.name\n )}`\n }.${kebabCase(this.config.mode)}.worker-script`,\n defu(\n {\n accountId: this.config.cloudflare.accountId,\n scriptName: worker.metadata.name,\n contentFile: joinPaths(\n this.config.output.publishPath,\n \"index.js\"\n ),\n module: true\n },\n worker.metadata,\n {\n compatibilityDate:\n this.config.compatibilityDate?.cloudflare?.toString() as string,\n compatibilityFlags: [\"nodejs_als\"]\n }\n ) as pulumiCloudflare.WorkersScriptArgs,\n { provider }\n );\n workerScripts.push(workerScript);\n\n const workerRoute = new pulumiCloudflare.WorkersRoute(\n `${this.config.organization ? `${this.config.organization}.` : \"\"}${\n kebabCase(this.config.name) === kebabCase(worker.metadata.name)\n ? kebabCase(this.config.name)\n : `${kebabCase(this.config.name)}-${kebabCase(\n worker.metadata.name\n )}`\n }.${kebabCase(this.config.mode)}.worker-route`,\n defu(\n {\n zoneId: zone.id,\n pattern: worker.metadata.pattern.replace(\n \"{domain}\",\n this.config.cloudflare.domain\n ),\n script: workerScript.scriptName\n },\n worker.metadata\n ),\n { provider }\n );\n workerRoutes.push(workerRoute);\n\n const dnsRecord = new pulumiCloudflare.DnsRecord(\n `${this.config.organization ? `${this.config.organization}.` : \"\"}${\n kebabCase(this.config.name) === kebabCase(worker.metadata.name)\n ? kebabCase(this.config.name)\n : `${kebabCase(this.config.name)}-${kebabCase(\n worker.metadata.name\n )}`\n }.${kebabCase(this.config.mode)}.dns-record`,\n {\n name: workerRoute.pattern,\n type: \"A\",\n content: \"192.0.2.1\",\n zoneId: zone.id,\n proxied: true,\n ttl: 1\n },\n { provider }\n );\n dnsRecords.push(dnsRecord);\n }\n\n return {\n workerScripts,\n workerRoutes,\n dnsRecords\n };\n }\n }\n ] as Plugin<TContext>[];\n}\n\nexport default plugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAgDA,SAAA,OAAA,UAAA,EAAA,EAAA;;EAEE,MAAA;EACE,SAAC;AACH,UAAA;IACK,YAAS,KAAM,KAAA,SAAA,CAAA,QAAA,CAAA,EAAA,EAAA,CAAA;IACpB,SAAS,EACD,uBAAC,OACF;IACL,OAAM,EACN,SAAA,CAAA,oBAAA;KACQ,mBAAY,KAAA,OAAA,mBAAA,UAAA;KACZ,oBAAG,CAAA,aAAA;KACP,CAAA,CAAA,EACC;IACF;;EAEH,iBAAO;AACL,QAAI,gBAAO,+BAAA;;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KAAA,CAAA,GAAA,UAAA,OAAA,SAAA,KAAA,GAAA,GAAA,UAAA,KAAA,OAAA,KAAA,CAAA,gBAAA,KAAA;KACjB,QAAK,KAAO;KACZ,SAAG,OAAA,SAAA,QAAA,QAAA,YAAA,KAAA,OAAA,WAAA,OAAA;KACH,QAAA,aAAA;KACF,EAAA,OAAA,SAAA,EAAA,YAEA,CAAA;AACA,iBAAS,KAAA,YAAA;IACT,MAAE,YAAA,IAAA,iBAAA,UAAA,GAAA,KAAA,OAAA,eAAA,GAAA,KAAA,OAAA,aAAA,KAAA,KAAA,UAAA,KAAA,OAAA,KAAA,KAAA,UAAA,OAAA,SAAA,KAAA,GAAA,UAAA,KAAA,OAAA,KAAA,GAAA,GAAA,UAAA,KAAA,OAAA,KAAA,CAAA,GAAA,UAAA,OAAA,SAAA,KAAA,GAAA,GAAA,UAAA,KAAA,OAAA,KAAA,CAAA,cAAA;;KAEF,MAAM;KACJ,SAAA;KACA,QAAA,KAAA;;KAEF,KAAM;KACL,EAAC,EACA,UACD,CAAC;AACF,eAAW,KAAK,UAAQ;;AAE1B,UAAK;IACH;IACA;;IAED;;EAEJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powerlines/plugin-cloudflare",
3
- "version": "0.4.2",
3
+ "version": "0.5.0",
4
4
  "private": false,
5
5
  "description": "A Powerlines plugin that provides integration with Cloudflare services.",
6
6
  "keywords": ["powerlines", "storm-software", "powerlines-plugin"],
@@ -162,9 +162,9 @@
162
162
  "@alloy-js/core": "0.23.0-dev.8",
163
163
  "@alloy-js/typescript": "0.23.0-dev.4",
164
164
  "@cloudflare/workers-types": "^4.20260317.1",
165
- "@powerlines/plugin-env": "^0.16.79",
166
- "@powerlines/plugin-pulumi": "^0.5.39",
167
- "@powerlines/plugin-unenv": "^0.1.347",
165
+ "@powerlines/plugin-env": "^0.16.80",
166
+ "@powerlines/plugin-pulumi": "^0.6.0",
167
+ "@powerlines/plugin-unenv": "^0.1.348",
168
168
  "@pulumi/cloudflare": "^6.13.0",
169
169
  "@pulumi/pulumi": "^3.226.0",
170
170
  "@storm-software/config-tools": "^1.189.39",
@@ -175,16 +175,16 @@
175
175
  "@stryke/type-checks": "^0.5.41",
176
176
  "@stryke/types": "^0.11.1",
177
177
  "defu": "^6.1.4",
178
- "powerlines": "^0.41.23"
178
+ "powerlines": "^0.42.0"
179
179
  },
180
180
  "devDependencies": {
181
181
  "@cloudflare/unenv-preset": "^2.15.0",
182
182
  "@cloudflare/workers-types": "^4.20260317.1",
183
- "@powerlines/plugin-alloy": "^0.25.44",
184
- "@powerlines/plugin-plugin": "^0.12.309",
183
+ "@powerlines/plugin-alloy": "^0.25.45",
184
+ "@powerlines/plugin-plugin": "^0.12.310",
185
185
  "@types/node": "^25.5.0"
186
186
  },
187
187
  "publishConfig": { "access": "public" },
188
188
  "inlinedDependencies": { "@cloudflare/unenv-preset": "2.15.0" },
189
- "gitHead": "c6ab4089999ed8b1f08214f9358d527de33dfa5e"
189
+ "gitHead": "27305574e9a8dbc8107e4127b2feba7a10fa9c89"
190
190
  }