@zeltjs/adapter-cloudflare-workers 0.0.1 → 0.4.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 9wick / Kohei Kido
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,45 +1,69 @@
1
1
  # @zeltjs/adapter-cloudflare-workers
2
2
 
3
- ## ⚠️ IMPORTANT NOTICE ⚠️
3
+ Cloudflare Workers adapter for Zelt.
4
4
 
5
- **This package is created solely for the purpose of setting up OIDC (OpenID Connect) trusted publishing with npm.**
5
+ ## Installation
6
6
 
7
- This is **NOT** a functional package and contains **NO** code or functionality beyond the OIDC setup configuration.
7
+ ```bash
8
+ pnpm add @zeltjs/adapter-cloudflare-workers
9
+ ```
8
10
 
9
- ## Purpose
11
+ ## Usage
10
12
 
11
- This package exists to:
12
- 1. Configure OIDC trusted publishing for the package name `@zeltjs/adapter-cloudflare-workers`
13
- 2. Enable secure, token-less publishing from CI/CD workflows
14
- 3. Establish provenance for packages published under this name
13
+ ```typescript
14
+ import { createHttpApp, Controller, Get } from '@zeltjs/core';
15
+ import { onCloudflareWorkers } from '@zeltjs/adapter-cloudflare-workers';
15
16
 
16
- ## What is OIDC Trusted Publishing?
17
+ @Controller('/hello')
18
+ class HelloController {
19
+ @Get('/')
20
+ greet() {
21
+ return { message: 'Hello from Workers!' };
22
+ }
23
+ }
17
24
 
18
- OIDC trusted publishing allows package maintainers to publish packages directly from their CI/CD workflows without needing to manage npm access tokens. Instead, it uses OpenID Connect to establish trust between the CI/CD provider (like GitHub Actions) and npm.
25
+ const app = createHttpApp({ controllers: [HelloController] });
19
26
 
20
- ## Setup Instructions
27
+ const workers = await onCloudflareWorkers(app);
21
28
 
22
- To properly configure OIDC trusted publishing for this package:
29
+ export default { fetch: workers.fetch };
30
+ ```
23
31
 
24
- 1. Go to [npmjs.com](https://www.npmjs.com/) and navigate to your package settings
25
- 2. Configure the trusted publisher (e.g., GitHub Actions)
26
- 3. Specify the repository and workflow that should be allowed to publish
27
- 4. Use the configured workflow to publish your actual package
32
+ ## Options
28
33
 
29
- ## DO NOT USE THIS PACKAGE
34
+ ```typescript
35
+ onCloudflareWorkers(app, {
36
+ warmup: false, // default: false (lazy mode for cold start optimization)
37
+ });
38
+ ```
30
39
 
31
- This package is a placeholder for OIDC configuration only. It:
32
- - Contains no executable code
33
- - Provides no functionality
34
- - Should not be installed as a dependency
35
- - Exists only for administrative purposes
40
+ - `warmup: false` (default) - Controllers are resolved on first request (optimized for serverless)
41
+ - `warmup: true` - All controllers are resolved during initialization
36
42
 
37
- ## More Information
43
+ ## Environment Variables
38
44
 
39
- For more details about npm's trusted publishing feature, see:
40
- - [npm Trusted Publishing Documentation](https://docs.npmjs.com/generating-provenance-statements)
41
- - [GitHub Actions OIDC Documentation](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect)
45
+ When using `EnvConfig`, it is automatically replaced with `CloudflareWorkersEnvConfig` which reads from `cloudflare:workers` env:
42
46
 
43
- ---
47
+ ```typescript
48
+ import { createHttpApp, Controller, Get, EnvConfig, EnvService, inject } from '@zeltjs/core';
49
+ import { onCloudflareWorkers } from '@zeltjs/adapter-cloudflare-workers';
44
50
 
45
- **Maintained for OIDC setup purposes only**
51
+ @Controller('/config')
52
+ class ConfigController {
53
+ constructor(private env = inject(EnvService)) {}
54
+
55
+ @Get('/')
56
+ getApiHost() {
57
+ return { apiHost: this.env.get('API_HOST') };
58
+ }
59
+ }
60
+
61
+ const app = createHttpApp({
62
+ controllers: [ConfigController],
63
+ configs: [EnvConfig],
64
+ });
65
+
66
+ const workers = await onCloudflareWorkers(app);
67
+
68
+ export default { fetch: workers.fetch };
69
+ ```
@@ -0,0 +1,24 @@
1
+ import { ControllerRouteInfo, EnvConfig, HttpApp, HttpMetadata, ReadyResult } from "@zeltjs/core";
2
+
3
+ //#region src/cloudflare-workers-env.config.d.ts
4
+ declare class CloudflareWorkersEnvConfig extends EnvConfig {
5
+ get(key: string): string | undefined;
6
+ }
7
+ //#endregion
8
+ //#region src/on-cloudflare-workers.d.ts
9
+ type DynamicMeta = HttpMetadata;
10
+ type CloudflareWorkersOptions = {
11
+ readonly warmup?: boolean;
12
+ readonly dynamic?: boolean;
13
+ };
14
+ type BaseCloudflareWorkersApp = ReadyResult & {
15
+ readonly fetch: (request: Request, env: unknown, ctx: ExecutionContext) => Promise<Response>;
16
+ readonly shutdown: () => Promise<void>;
17
+ };
18
+ type CloudflareWorkersApp = BaseCloudflareWorkersApp & {
19
+ readonly __dynamicMeta?: DynamicMeta;
20
+ };
21
+ declare const onCloudflareWorkers: (app: HttpApp, options?: CloudflareWorkersOptions) => Promise<CloudflareWorkersApp>;
22
+ //#endregion
23
+ export { type CloudflareWorkersApp, CloudflareWorkersEnvConfig, type CloudflareWorkersOptions, type ControllerRouteInfo, type DynamicMeta, type HttpMetadata, onCloudflareWorkers };
24
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/cloudflare-workers-env.config.ts","../src/on-cloudflare-workers.ts"],"mappings":";;;cAIa,0BAAA,SAAmC,SAAA;EACrC,GAAA,CAAI,GAAA;AAAA;;;KCOH,WAAA,GAAc,YAAA;AAAA,KAEd,wBAAA;EAAA,SACD,MAAA;EAAA,SACA,OAAA;AAAA;AAAA,KAGN,wBAAA,GAA2B,WAAA;EAAA,SACrB,KAAA,GAAQ,OAAA,EAAS,OAAA,EAAS,GAAA,WAAc,GAAA,EAAK,gBAAA,KAAqB,OAAA,CAAQ,QAAA;EAAA,SAC1E,QAAA,QAAgB,OAAA;AAAA;AAAA,KAGf,oBAAA,GAAuB,wBAAA;EAAA,SACxB,aAAA,GAAgB,WAAA;AAAA;AAAA,cAGd,mBAAA,GACX,GAAA,EAAK,OAAA,EACL,OAAA,GAAS,wBAAA,KACR,OAAA,CAAQ,oBAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,47 @@
1
+ import { env } from "cloudflare:workers";
2
+ import { Config, EnvConfig } from "@zeltjs/core";
3
+ //#region \0@oxc-project+runtime@0.127.0/helpers/decorate.js
4
+ function __decorate(decorators, target, key, desc) {
5
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
6
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
7
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
8
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
9
+ }
10
+ //#endregion
11
+ //#region src/cloudflare-workers-env.config.ts
12
+ let CloudflareWorkersEnvConfig = class CloudflareWorkersEnvConfig extends EnvConfig {
13
+ get(key) {
14
+ const value = env[key];
15
+ return typeof value === "string" ? value : void 0;
16
+ }
17
+ };
18
+ CloudflareWorkersEnvConfig = __decorate([Config], CloudflareWorkersEnvConfig);
19
+ //#endregion
20
+ //#region src/on-cloudflare-workers.ts
21
+ const onCloudflareWorkers = async (app, options = {}) => {
22
+ app.addFallbackConfig(CloudflareWorkersEnvConfig);
23
+ const readyOptions = { warmup: options.warmup ?? false };
24
+ const resolver = await app.ready(readyOptions);
25
+ const fetch = async (request, _env, ctx) => {
26
+ const response = app.fetch(request);
27
+ ctx.waitUntil(response.then(() => {}));
28
+ return response;
29
+ };
30
+ const base = {
31
+ ...resolver,
32
+ fetch,
33
+ shutdown: app.shutdown
34
+ };
35
+ if (options.dynamic) {
36
+ const __dynamicMeta = app.getMetadata();
37
+ return {
38
+ ...base,
39
+ __dynamicMeta
40
+ };
41
+ }
42
+ return base;
43
+ };
44
+ //#endregion
45
+ export { CloudflareWorkersEnvConfig, onCloudflareWorkers };
46
+
47
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/cloudflare-workers-env.config.ts","../src/on-cloudflare-workers.ts"],"sourcesContent":["import { env } from 'cloudflare:workers';\nimport { Config, EnvConfig } from '@zeltjs/core';\n\n@Config\nexport class CloudflareWorkersEnvConfig extends EnvConfig {\n override get(key: string): string | undefined {\n const value: unknown = (env as Record<string, unknown>)[key];\n return typeof value === 'string' ? value : undefined;\n }\n}\n","import type {\n ControllerRouteInfo,\n HttpApp,\n HttpMetadata,\n ReadyOptions,\n ReadyResult,\n} from '@zeltjs/core';\n\nimport { CloudflareWorkersEnvConfig } from './cloudflare-workers-env.config';\n\nexport type { ControllerRouteInfo, HttpMetadata };\n\nexport type DynamicMeta = HttpMetadata;\n\nexport type CloudflareWorkersOptions = {\n readonly warmup?: boolean;\n readonly dynamic?: boolean;\n};\n\ntype BaseCloudflareWorkersApp = ReadyResult & {\n readonly fetch: (request: Request, env: unknown, ctx: ExecutionContext) => Promise<Response>;\n readonly shutdown: () => Promise<void>;\n};\n\nexport type CloudflareWorkersApp = BaseCloudflareWorkersApp & {\n readonly __dynamicMeta?: DynamicMeta;\n};\n\nexport const onCloudflareWorkers = async (\n app: HttpApp,\n options: CloudflareWorkersOptions = {},\n): Promise<CloudflareWorkersApp> => {\n app.addFallbackConfig(CloudflareWorkersEnvConfig);\n\n const readyOptions: ReadyOptions = { warmup: options.warmup ?? false };\n const resolver = await app.ready(readyOptions);\n\n const fetch = async (\n request: Request,\n _env: unknown,\n ctx: ExecutionContext,\n ): Promise<Response> => {\n const response = app.fetch(request);\n ctx.waitUntil(response.then(() => {}));\n return response;\n };\n\n const base: BaseCloudflareWorkersApp = { ...resolver, fetch, shutdown: app.shutdown };\n\n if (options.dynamic) {\n const __dynamicMeta = app.getMetadata();\n return { ...base, __dynamicMeta };\n }\n\n return base;\n};\n"],"mappings":";;;;;;;;;;;AAIO,IAAA,6BAAA,MAAM,mCAAmC,UAAU;CACxD,IAAa,KAAiC;EAC5C,MAAM,QAAkB,IAAgC;AACxD,SAAO,OAAO,UAAU,WAAW,QAAQ,KAAA;;;yCAJ9C,OAAA,EAAA,2BAAA;;;ACyBD,MAAa,sBAAsB,OACjC,KACA,UAAoC,EAAE,KACJ;AAClC,KAAI,kBAAkB,2BAA2B;CAEjD,MAAM,eAA6B,EAAE,QAAQ,QAAQ,UAAU,OAAO;CACtE,MAAM,WAAW,MAAM,IAAI,MAAM,aAAa;CAE9C,MAAM,QAAQ,OACZ,SACA,MACA,QACsB;EACtB,MAAM,WAAW,IAAI,MAAM,QAAQ;AACnC,MAAI,UAAU,SAAS,WAAW,GAAG,CAAC;AACtC,SAAO;;CAGT,MAAM,OAAiC;EAAE,GAAG;EAAU;EAAO,UAAU,IAAI;EAAU;AAErF,KAAI,QAAQ,SAAS;EACnB,MAAM,gBAAgB,IAAI,aAAa;AACvC,SAAO;GAAE,GAAG;GAAM;GAAe;;AAGnC,QAAO"}
package/package.json CHANGED
@@ -1,10 +1,37 @@
1
1
  {
2
2
  "name": "@zeltjs/adapter-cloudflare-workers",
3
- "version": "0.0.1",
4
- "description": "OIDC trusted publishing setup package for @zeltjs/adapter-cloudflare-workers",
5
- "keywords": [
6
- "oidc",
7
- "trusted-publishing",
8
- "setup"
9
- ]
10
- }
3
+ "version": "0.4.0",
4
+ "type": "module",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/zeltjs/zelt.git",
9
+ "directory": "packages/adapter-cloudflare-workers"
10
+ },
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/index.d.ts",
17
+ "import": "./dist/index.js"
18
+ }
19
+ },
20
+ "files": [
21
+ "dist"
22
+ ],
23
+ "dependencies": {
24
+ "@zeltjs/core": "0.4.0"
25
+ },
26
+ "devDependencies": {
27
+ "@cloudflare/workers-types": "4.20250523.0"
28
+ },
29
+ "volta": {
30
+ "extends": "../../package.json"
31
+ },
32
+ "scripts": {
33
+ "build": "tsdown",
34
+ "test": "vitest run",
35
+ "typecheck": "tsc -b"
36
+ }
37
+ }