@umituz/web-cloudflare 1.4.8 → 1.4.10

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @umituz/web-cloudflare
2
2
 
3
- Comprehensive Cloudflare Workers integration with config-based patterns, middleware, router, workflows, and AI.
3
+ Comprehensive Cloudflare Workers & Pages integration with config-based patterns, middleware, router, workflows, and AI.
4
4
 
5
5
  ## 🚀 Features
6
6
 
@@ -177,6 +177,39 @@ const versions = await wrangler.versionsList();
177
177
  await wrangler.versionsRollback(versions[0].id);
178
178
  ```
179
179
 
180
+ ### Using Cloudflare Pages
181
+
182
+ ```typescript
183
+ import { PagesService } from '@umituz/web-cloudflare/pages';
184
+
185
+ const pages = new PagesService();
186
+
187
+ // Create a new Pages project
188
+ await pages.createProject('my-app', {
189
+ productionBranch: 'main',
190
+ });
191
+
192
+ // Deploy to Pages
193
+ const deployment = await pages.deploy({
194
+ projectName: 'my-app',
195
+ directory: 'dist', // Build output directory
196
+ branch: 'main',
197
+ environment: 'production',
198
+ vars: {
199
+ API_URL: 'https://api.example.com',
200
+ },
201
+ });
202
+
203
+ // List all projects
204
+ const projects = await pages.listProjects();
205
+
206
+ // List deployments for a project
207
+ const deployments = await pages.listDeployments('my-app');
208
+
209
+ // Delete a deployment
210
+ await pages.deleteDeployment('my-app', deployment.id);
211
+ ```
212
+
180
213
  **Note:** All services now follow Domain-Driven Design (DDD) architecture with their own domain structures:
181
214
  - Wrangler CLI: `src/domains/wrangler/`
182
215
  - Workers: `src/domains/workers/`
@@ -187,6 +220,7 @@ await wrangler.versionsRollback(versions[0].id);
187
220
  - Images: `src/domains/images/`
188
221
  - Analytics: `src/domains/analytics/`
189
222
  - Workflows: `src/domains/workflows/`
223
+ - Pages: `src/domains/pages/`
190
224
 
191
225
  ## 📚 Subpath Exports
192
226
 
@@ -216,6 +250,9 @@ import { WorkflowService } from '@umituz/web-cloudflare/workflows';
216
250
 
217
251
  // Wrangler CLI
218
252
  import { WranglerService } from '@umituz/web-cloudflare/wrangler';
253
+
254
+ // Pages deployment
255
+ import { PagesService, pagesService } from '@umituz/web-cloudflare/pages';
219
256
  ```
220
257
 
221
258
  ### Workflows & AI
@@ -680,7 +717,8 @@ Contributions are welcome!
680
717
  │ │ ├── kv/ # KV storage domain
681
718
  │ │ ├── images/ # Images optimization domain
682
719
  │ │ ├── analytics/ # Analytics domain
683
- │ │ └── workflows/ # Workflows domain
720
+ │ │ ├── workflows/ # Workflows domain
721
+ │ │ ├── pages/ # Pages deployment domain
684
722
  │ ├── infrastructure/
685
723
  │ │ ├── router/ # Express-like router
686
724
  │ │ ├── middleware/ # Middleware collection
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@umituz/web-cloudflare",
3
- "version": "1.4.8",
4
- "description": "Comprehensive Cloudflare Workers integration with config-based patterns, middleware, router, workflows, and AI (Patch-only versioning: only z in x.y.z increments)",
3
+ "version": "1.4.10",
4
+ "description": "Comprehensive Cloudflare Workers & Pages integration with config-based patterns, middleware, router, workflows, and AI (Patch-only versioning: only z in x.y.z increments)",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
7
7
  "sideEffects": false,
@@ -17,6 +17,7 @@
17
17
  "./ai-gateway": "./src/domains/ai-gateway/index.ts",
18
18
  "./workers-ai": "./src/domains/ai-gateway/index.ts",
19
19
  "./wrangler": "./src/domains/wrangler/index.ts",
20
+ "./pages": "./src/domains/pages/index.ts",
20
21
  "./middleware": "./src/domains/middleware/index.ts",
21
22
  "./router": "./src/infrastructure/router/index.ts",
22
23
  "./utils": "./src/infrastructure/utils/helpers.ts",
@@ -47,6 +48,10 @@
47
48
  "workflows",
48
49
  "ai-gateway",
49
50
  "workers-ai",
51
+ "pages",
52
+ "cloudflare-pages",
53
+ "static-site",
54
+ "deployment",
50
55
  "router",
51
56
  "middleware",
52
57
  "config-patterns",
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Pages Domain Entities
3
+ * Defines entities for Cloudflare Pages operations
4
+ */
5
+
6
+ /**
7
+ * Pages project info
8
+ */
9
+ export interface PagesProject {
10
+ name: string;
11
+ production_branch?: string;
12
+ created_on?: string;
13
+ deployment_configs?: {
14
+ preview?: {
15
+ branch?: string;
16
+ env_vars?: Record<string, string>;
17
+ };
18
+ production?: {
19
+ branch?: string;
20
+ env_vars?: Record<string, string>;
21
+ };
22
+ };
23
+ }
24
+
25
+ /**
26
+ * Pages deployment info
27
+ */
28
+ export interface PagesDeployment {
29
+ id: string;
30
+ project: string;
31
+ url: string;
32
+ latest_stage?: string;
33
+ created_on?: string;
34
+ deployment_trigger?: {
35
+ metadata?: {
36
+ branch?: string;
37
+ commit_hash?: string;
38
+ };
39
+ };
40
+ stages?: {
41
+ environment: string;
42
+ function?: string;
43
+ url?: string;
44
+ }[];
45
+ }
46
+
47
+ /**
48
+ * Pages deploy options
49
+ */
50
+ export interface PagesDeployOptions {
51
+ projectName: string;
52
+ directory?: string; // Build output directory (default: dist)
53
+ branch?: string;
54
+ preview?: boolean;
55
+ environment?: 'preview' | 'production';
56
+ compatibilityDate?: string;
57
+ compatibilityFlags?: string[];
58
+ vars?: Record<string, string>;
59
+ functions?: boolean; // Deploy with functions
60
+ }
61
+
62
+ /**
63
+ * Pages function info
64
+ */
65
+ export interface PagesFunction {
66
+ name: string;
67
+ scriptPath?: string;
68
+ compatibilityDate?: string;
69
+ compatibilityFlags?: string[];
70
+ }
71
+
72
+ /**
73
+ * Pages deployment result
74
+ */
75
+ export interface PagesDeploymentResult {
76
+ deployment: PagesDeployment;
77
+ url?: string;
78
+ alias?: string;
79
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Pages Domain
3
+ * Cloudflare Pages deployment and management
4
+ */
5
+
6
+ // Entities
7
+ export * from './entities';
8
+
9
+ // Types
10
+ export * from './types';
11
+
12
+ // Services
13
+ export * from './services';
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Pages Domain Services
3
+ */
4
+
5
+ export { PagesService, pagesService } from './pages.service';
@@ -0,0 +1,144 @@
1
+ /**
2
+ * Pages Service Implementation
3
+ * Cloudflare Pages deployment and management
4
+ *
5
+ * ⚠️ NODE.JS ONLY: This service requires Node.js runtime and is NOT compatible
6
+ * with Cloudflare Workers runtime. Use this service only in build/development
7
+ * scripts running in Node.js environment.
8
+ */
9
+
10
+ import { execSync } from 'child_process';
11
+ import type { IPagesService } from '../types/service.interface';
12
+ import type {
13
+ PagesProject,
14
+ PagesDeployment,
15
+ PagesDeployOptions,
16
+ PagesFunction,
17
+ PagesDeploymentResult,
18
+ } from '../entities';
19
+
20
+ export class PagesService implements IPagesService {
21
+ private readonly wranglerCommand: string;
22
+
23
+ constructor(options?: { wranglerPath?: string }) {
24
+ this.wranglerCommand = options?.wranglerPath || 'npx wrangler';
25
+ }
26
+
27
+ /**
28
+ * Create a new Pages project
29
+ */
30
+ async createProject(
31
+ projectName: string,
32
+ options?: {
33
+ productionBranch?: string;
34
+ compatibilityDate?: string;
35
+ }
36
+ ): Promise<{ success: boolean; data?: PagesProject; error?: string }> {
37
+ return this.nodeNotRequired();
38
+ }
39
+
40
+ /**
41
+ * List all Pages projects
42
+ */
43
+ async listProjects(): Promise<{ success: boolean; data?: PagesProject[]; error?: string }> {
44
+ return this.nodeNotRequired();
45
+ }
46
+
47
+ /**
48
+ * Get project details
49
+ */
50
+ async getProject(projectName: string): Promise<{ success: boolean; data?: PagesProject; error?: string }> {
51
+ return this.nodeNotRequired();
52
+ }
53
+
54
+ /**
55
+ * Deploy to Pages
56
+ */
57
+ async deploy(
58
+ options: PagesDeployOptions
59
+ ): Promise<{ success: boolean; data?: PagesDeploymentResult; error?: string }> {
60
+ return this.nodeNotRequired();
61
+ }
62
+
63
+ /**
64
+ * Create a Pages function
65
+ */
66
+ async createFunction(
67
+ projectName: string,
68
+ functionName: string,
69
+ options?: {
70
+ compatibilityDate?: string;
71
+ compatibilityFlags?: string[];
72
+ }
73
+ ): Promise<{ success: boolean; data?: PagesFunction; error?: string }> {
74
+ return this.nodeNotRequired();
75
+ }
76
+
77
+ /**
78
+ * List deployments for a project
79
+ */
80
+ async listDeployments(
81
+ projectName: string
82
+ ): Promise<{ success: boolean; data?: PagesDeployment[]; error?: string }> {
83
+ return this.nodeNotRequired();
84
+ }
85
+
86
+ /**
87
+ * Get deployment details
88
+ */
89
+ async getDeployment(
90
+ projectName: string,
91
+ deploymentId: string
92
+ ): Promise<{ success: boolean; data?: PagesDeployment; error?: string }> {
93
+ return this.nodeNotRequired();
94
+ }
95
+
96
+ /**
97
+ * Delete a deployment
98
+ */
99
+ async deleteDeployment(
100
+ projectName: string,
101
+ deploymentId: string
102
+ ): Promise<{ success: boolean; error?: string }> {
103
+ return this.nodeNotRequired();
104
+ }
105
+
106
+ /**
107
+ * Execute wrangler pages command
108
+ */
109
+ private executeWranglerPages(
110
+ args: string[],
111
+ options?: { cwd?: string; env?: Record<string, string> }
112
+ ): { success: boolean; stdout: string; stderr: string; exitCode?: number } {
113
+ try {
114
+ const command = `${this.wranglerCommand} pages ${args.join(' ')}`;
115
+ const stdout = execSync(command, {
116
+ cwd: options?.cwd,
117
+ env: { ...process.env, ...options?.env },
118
+ encoding: 'utf-8',
119
+ });
120
+ return { success: true, stdout, stderr: '', exitCode: 0 };
121
+ } catch (error: unknown) {
122
+ if (error instanceof Error) {
123
+ const err = error as { stdout?: string; stderr?: string; code?: number };
124
+ return {
125
+ success: false,
126
+ stdout: err.stdout || '',
127
+ stderr: err.stderr || error.message,
128
+ exitCode: err.code,
129
+ };
130
+ }
131
+ return { success: false, stdout: '', stderr: 'Unknown error', exitCode: -1 };
132
+ }
133
+ }
134
+
135
+ private nodeNotRequired<T>(): never {
136
+ throw new Error(
137
+ 'PagesService requires Node.js runtime. ' +
138
+ 'This service only works in Node.js environment, not in Cloudflare Workers. ' +
139
+ 'Use this service in build scripts or deployment tools only.'
140
+ );
141
+ }
142
+ }
143
+
144
+ export const pagesService = new PagesService();
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Pages Domain Types
3
+ */
4
+
5
+ export * from './service.interface';
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Pages Service Interface
3
+ * Defines the contract for Cloudflare Pages operations
4
+ */
5
+
6
+ import type {
7
+ PagesProject,
8
+ PagesDeployment,
9
+ PagesDeployOptions,
10
+ PagesFunction,
11
+ PagesDeploymentResult,
12
+ } from '../entities';
13
+
14
+ export interface IPagesService {
15
+ /**
16
+ * Create a new Pages project
17
+ */
18
+ createProject(
19
+ projectName: string,
20
+ options?: {
21
+ productionBranch?: string;
22
+ compatibilityDate?: string;
23
+ }
24
+ ): Promise<{ success: boolean; data?: PagesProject; error?: string }>;
25
+
26
+ /**
27
+ * List all Pages projects
28
+ */
29
+ listProjects(): Promise<{ success: boolean; data?: PagesProject[]; error?: string }>;
30
+
31
+ /**
32
+ * Get project details
33
+ */
34
+ getProject(projectName: string): Promise<{ success: boolean; data?: PagesProject; error?: string }>;
35
+
36
+ /**
37
+ * Deploy to Pages
38
+ */
39
+ deploy(
40
+ options: PagesDeployOptions
41
+ ): Promise<{ success: boolean; data?: PagesDeploymentResult; error?: string }>;
42
+
43
+ /**
44
+ * Create a Pages function
45
+ */
46
+ createFunction(
47
+ projectName: string,
48
+ functionName: string,
49
+ options?: {
50
+ compatibilityDate?: string;
51
+ compatibilityFlags?: string[];
52
+ }
53
+ ): Promise<{ success: boolean; data?: PagesFunction; error?: string }>;
54
+
55
+ /**
56
+ * List deployments for a project
57
+ */
58
+ listDeployments(
59
+ projectName: string
60
+ ): Promise<{ success: boolean; data?: PagesDeployment[]; error?: string }>;
61
+
62
+ /**
63
+ * Get deployment details
64
+ */
65
+ getDeployment(
66
+ projectName: string,
67
+ deploymentId: string
68
+ ): Promise<{ success: boolean; data?: PagesDeployment; error?: string }>;
69
+
70
+ /**
71
+ * Delete a deployment
72
+ */
73
+ deleteDeployment(
74
+ projectName: string,
75
+ deploymentId: string
76
+ ): Promise<{ success: boolean; error?: string }>;
77
+ }
@@ -53,6 +53,12 @@ export enum WranglerCommand {
53
53
  // Versions
54
54
  VERSIONS_LIST = 'versions list',
55
55
  VERSIONS_ROLLBACK = 'versions rollback',
56
+
57
+ // Pages operations
58
+ PAGES_PROJECT_CREATE = 'pages project create',
59
+ PAGES_PROJECT_LIST = 'pages project list',
60
+ PAGES_DEPLOY = 'pages deploy',
61
+ PAGES_FUNCTION = 'pages function',
56
62
  }
57
63
 
58
64
  /**
@@ -140,3 +146,54 @@ export interface WranglerAnalyticsData {
140
146
  statusCodes?: Record<string, number>;
141
147
  countries?: Record<string, number>;
142
148
  }
149
+
150
+ /**
151
+ * Pages project info
152
+ */
153
+ export interface PagesProjectInfo {
154
+ name: string;
155
+ production_branch?: string;
156
+ creation_date?: string;
157
+ deployment_configs?: {
158
+ preview?: {
159
+ branch?: string;
160
+ env_vars?: Record<string, string>;
161
+ };
162
+ production?: {
163
+ branch?: string;
164
+ env_vars?: Record<string, string>;
165
+ };
166
+ };
167
+ }
168
+
169
+ /**
170
+ * Pages deployment info
171
+ */
172
+ export interface PagesDeploymentInfo {
173
+ id: string;
174
+ project: string;
175
+ url: string;
176
+ latest_stage?: string;
177
+ created_on?: string;
178
+ deployment_trigger?: {
179
+ metadata?: {
180
+ branch?: string;
181
+ commit_hash?: string;
182
+ };
183
+ };
184
+ }
185
+
186
+ /**
187
+ * Pages deploy options
188
+ */
189
+ export interface PagesDeployOptions {
190
+ projectName: string;
191
+ directory?: string;
192
+ branch?: string;
193
+ preview?: boolean;
194
+ environment?: 'preview' | 'production';
195
+ compatibilityDate?: string;
196
+ compatibilityFlags?: string[];
197
+ vars?: Record<string, string>;
198
+ }
199
+
@@ -13,6 +13,9 @@ import type {
13
13
  SecretInfo,
14
14
  WorkerVersionInfo,
15
15
  WranglerAnalyticsData,
16
+ PagesProjectInfo,
17
+ PagesDeploymentInfo,
18
+ PagesDeployOptions,
16
19
  } from '../entities';
17
20
 
18
21
  export interface IWranglerService {
@@ -127,4 +130,21 @@ export interface IWranglerService {
127
130
  args: string[],
128
131
  options?: WranglerCommandOptions
129
132
  ): Promise<WranglerResult<string>>;
133
+
134
+ // Pages operations
135
+ pagesProjectCreate(
136
+ projectName: string,
137
+ options?: WranglerCommandOptions & { productionBranch?: string }
138
+ ): Promise<WranglerResult<PagesProjectInfo>>;
139
+ pagesProjectList(
140
+ options?: WranglerCommandOptions
141
+ ): Promise<WranglerResult<PagesProjectInfo[]>>;
142
+ pagesDeploy(
143
+ options: PagesDeployOptions & WranglerCommandOptions
144
+ ): Promise<WranglerResult<PagesDeploymentInfo>>;
145
+ pagesFunctionCreate(
146
+ projectName: string,
147
+ functionName: string,
148
+ options?: WranglerCommandOptions
149
+ ): Promise<WranglerResult<void>>;
130
150
  }
package/src/index.ts CHANGED
@@ -35,6 +35,15 @@ export { d1Service, D1Service } from "./domains/d1";
35
35
  export { kvService, KVService } from "./domains/kv";
36
36
  export { imagesService, ImagesService } from "./domains/images";
37
37
  export { analyticsService, AnalyticsService } from "./domains/analytics";
38
+ // Pages - Node.js-only service
39
+ export { pagesService, PagesService } from "./domains/pages";
40
+ export type {
41
+ PagesProject,
42
+ PagesDeployment,
43
+ PagesDeployOptions,
44
+ PagesFunction,
45
+ PagesDeploymentResult,
46
+ } from "./domains/pages";
38
47
  // Workflows - selective exports to avoid conflicts
39
48
  export type {
40
49
  WorkflowStep,