Skip to content

Commit 5cebea6

Browse files
Merge pull request #2672 from cloudflare/release-please--branches--main--changes--next--components--cloudflare
release: 5.1.0
2 parents 83fb4ef + 5a8a6e9 commit 5cebea6

File tree

16 files changed

+106
-88
lines changed

16 files changed

+106
-88
lines changed

.release-please-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
".": "5.0.0"
2+
".": "5.1.0"
33
}

.stats.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 1809
22
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-77d61495fecd0d26b9adff1af0ab3510b06a3cc2c6781b9a40aabcad2f10588a.yml
33
openapi_spec_hash: 95dee3be411dda77306a41dc7d49eb35
4-
config_hash: db0ff227af424d15b1c84f467e04c023
4+
config_hash: ac04197a992afb1d8c3b416fc46e8c8e

CHANGELOG.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,28 @@
11
# Changelog
22

3+
## 5.1.0 (2025-09-12)
4+
5+
Full Changelog: [v5.0.0...v5.1.0](https://github.com/cloudflare/cloudflare-typescript/compare/v5.0.0...v5.1.0)
6+
7+
### Features
8+
9+
* Merge branch 'vaishak/skip-worker-test' into 'main' ([a556698](https://github.com/cloudflare/cloudflare-typescript/commit/a5566983ae47453ffc4d5d9a266d7480ed620d51))
10+
11+
12+
### Bug Fixes
13+
14+
* coerce nullable values to undefined ([7847e84](https://github.com/cloudflare/cloudflare-typescript/commit/7847e845eb146f099a63f32931e5991840799c9c))
15+
* correctly handle sending multipart/form-data requests with JSON ([e9deab6](https://github.com/cloudflare/cloudflare-typescript/commit/e9deab61fad243c4339df7362529fd9b92693f8a))
16+
17+
18+
### Chores
19+
20+
* ci build action ([23d3577](https://github.com/cloudflare/cloudflare-typescript/commit/23d3577a92a835ffc1aeffb3004801b75efeb136))
21+
* fix lint on the examples ([dd14379](https://github.com/cloudflare/cloudflare-typescript/commit/dd143796d0494f2c9a57493a330f229ce5d2533a))
22+
* fix lint on the examples ([dd14379](https://github.com/cloudflare/cloudflare-typescript/commit/dd143796d0494f2c9a57493a330f229ce5d2533a))
23+
* fix lint on the examples ([5b2f145](https://github.com/cloudflare/cloudflare-typescript/commit/5b2f145f72d68b9f9bfde59c55323b4abb89ca71))
24+
* **internal:** codegen related update ([2860479](https://github.com/cloudflare/cloudflare-typescript/commit/2860479dc7310af6a02647597900aba2c76c554c))
25+
326
## 5.0.0 (2025-09-02)
427

528
Full Changelog: [v4.5.0...v5.0.0](https://github.com/cloudflare/cloudflare-typescript/compare/v4.5.0...v5.0.0)

examples/workers/script-upload.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
/**
44
* Create and deploy a Worker
5-
*
5+
*
66
* Docs:
77
* - https://developers.cloudflare.com/workers/configuration/versions-and-deployments/
88
* - https://developers.cloudflare.com/workers/platform/infrastructure-as-code/
9-
*
9+
*
1010
* Prerequisites:
1111
* 1. Generate an API token: https://developers.cloudflare.com/fundamentals/api/get-started/create-token/
1212
* 2. Find your account ID: https://developers.cloudflare.com/fundamentals/setup/find-account-and-zone-ids/
@@ -72,15 +72,17 @@ async function main(): Promise<void> {
7272
return new Response(env.MESSAGE, { status: 200 });
7373
},
7474
}`.trim();
75-
75+
7676
let worker;
7777
try {
7878
worker = await client.workers.beta.workers.get(config.workerName, {
7979
account_id: config.accountId,
8080
});
8181
console.log(`♻️ Worker ${config.workerName} already exists. Using it.`);
8282
} catch (error) {
83-
if (!(error instanceof Cloudflare.NotFoundError)) { throw error; }
83+
if (!(error instanceof Cloudflare.NotFoundError)) {
84+
throw error;
85+
}
8486
console.log(`✏️ Creating Worker ${config.workerName}...`);
8587
worker = await client.workers.beta.workers.create({
8688
account_id: config.accountId,
@@ -96,7 +98,7 @@ async function main(): Promise<void> {
9698

9799
console.log(`⚙️ Worker id: ${worker.id}`);
98100
console.log('✏️ Creating Worker version...');
99-
101+
100102
// Create the first version of the Worker
101103
const version = await client.workers.beta.workers.versions.create(worker.id, {
102104
account_id: config.accountId,
@@ -120,21 +122,21 @@ async function main(): Promise<void> {
120122

121123
console.log(`⚙️ Version id: ${version.id}`);
122124
console.log('🚚 Creating Worker deployment...');
123-
125+
124126
// Create a deployment and point all traffic to the version we created
125127
await client.workers.scripts.deployments.create(config.workerName, {
126128
account_id: config.accountId,
127129
strategy: 'percentage',
128130
versions: [
129131
{
130-
percentage: 100,
131-
version_id: version.id,
132-
},
133-
],
132+
percentage: 100,
133+
version_id: version.id,
134+
},
135+
],
134136
});
135-
137+
136138
console.log('✅ Deployment successful!');
137-
139+
138140
if (config.subdomain) {
139141
console.log(`
140142
🌍 Your Worker is live!

examples/workers/script-with-assets-upload.ts

Lines changed: 51 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
/**
44
* Create a Worker that serves static assets
5-
*
5+
*
66
* This example demonstrates how to:
77
* - Upload static assets to Cloudflare Workers
88
* - Create and deploy a Worker that serves those assets
9-
*
9+
*
1010
* Docs:
1111
* - https://developers.cloudflare.com/workers/static-assets/direct-upload
1212
*
@@ -17,7 +17,7 @@
1717
*
1818
* Environment variables:
1919
* - CLOUDFLARE_API_TOKEN (required)
20-
* - CLOUDFLARE_ACCOUNT_ID (required)
20+
* - CLOUDFLARE_ACCOUNT_ID (required)
2121
* - ASSETS_DIRECTORY (required)
2222
* - CLOUDFLARE_SUBDOMAIN (optional)
2323
*
@@ -99,11 +99,11 @@ const client = new Cloudflare({
9999
*/
100100
function createManifest(directory: string): AssetManifest {
101101
const manifest: AssetManifest = {};
102-
102+
103103
function processDirectory(currentDir: string, basePath = ''): void {
104104
try {
105105
const entries = fs.readdirSync(currentDir, { withFileTypes: true });
106-
106+
107107
for (const entry of entries) {
108108
const fullPath = path.join(currentDir, entry.name);
109109
const relativePath = path.join(basePath, entry.name);
@@ -124,12 +124,12 @@ function createManifest(directory: string): AssetManifest {
124124

125125
// Normalize path separators to forward slashes
126126
const manifestPath = `/${relativePath.replace(/\\/g, '/')}`;
127-
127+
128128
manifest[manifestPath] = {
129129
hash,
130130
size: fileContent.length,
131131
};
132-
132+
133133
console.log(`Added to manifest: ${manifestPath} (${fileContent.length} bytes)`);
134134
} catch (error) {
135135
console.warn(`Failed to process file ${fullPath}:`, error);
@@ -140,13 +140,13 @@ function createManifest(directory: string): AssetManifest {
140140
throw new Error(`Failed to read directory ${currentDir}: ${error}`);
141141
}
142142
}
143-
143+
144144
processDirectory(directory);
145-
145+
146146
if (Object.keys(manifest).length === 0) {
147147
throw new Error(`No files found in assets directory: ${directory}`);
148148
}
149-
149+
150150
console.log(`Created manifest with ${Object.keys(manifest).length} files`);
151151
return manifest;
152152
}
@@ -201,26 +201,24 @@ export default {
201201
async function createUploadPayloads(
202202
buckets: string[][],
203203
manifest: AssetManifest,
204-
assetsDirectory: string
204+
assetsDirectory: string,
205205
): Promise<UploadPayload[]> {
206206
const payloads: UploadPayload[] = [];
207-
207+
208208
for (const bucket of buckets) {
209209
const payload: UploadPayload = {};
210-
210+
211211
for (const hash of bucket) {
212212
// Find the file path for this hash
213-
const manifestEntry = Object.entries(manifest).find(
214-
([_, data]) => data.hash === hash
215-
);
216-
213+
const manifestEntry = Object.entries(manifest).find(([_, data]) => data.hash === hash);
214+
217215
if (!manifestEntry) {
218216
throw new Error(`Could not find file for hash: ${hash}`);
219217
}
220-
218+
221219
const [relativePath] = manifestEntry;
222220
const fullPath = path.join(assetsDirectory, relativePath);
223-
221+
224222
try {
225223
const fileContent = await readFile(fullPath);
226224
payload[hash] = fileContent.toString('base64');
@@ -229,10 +227,10 @@ async function createUploadPayloads(
229227
throw new Error(`Failed to read file ${fullPath}: ${error}`);
230228
}
231229
}
232-
230+
233231
payloads.push(payload);
234232
}
235-
233+
236234
return payloads;
237235
}
238236

@@ -242,16 +240,16 @@ async function createUploadPayloads(
242240
async function uploadAssets(
243241
payloads: UploadPayload[],
244242
uploadJwt: string,
245-
accountId: string
243+
accountId: string,
246244
): Promise<string> {
247245
let completionJwt: string | undefined;
248-
246+
249247
console.log(`Uploading ${payloads.length} payload(s)...`);
250-
248+
251249
for (let i = 0; i < payloads.length; i++) {
252250
const payload = payloads[i]!;
253251
console.log(`Uploading payload ${i + 1}/${payloads.length}...`);
254-
252+
255253
try {
256254
const response = await client.workers.assets.upload.create(
257255
{
@@ -261,21 +259,21 @@ async function uploadAssets(
261259
},
262260
{
263261
headers: { Authorization: `Bearer ${uploadJwt}` },
264-
}
262+
},
265263
);
266-
264+
267265
if (response?.jwt) {
268266
completionJwt = response.jwt;
269267
}
270268
} catch (error) {
271269
throw new Error(`Failed to upload payload ${i + 1}: ${error}`);
272270
}
273271
}
274-
272+
275273
if (!completionJwt) {
276274
throw new Error('Upload completed but no completion JWT received');
277275
}
278-
276+
279277
console.log('✅ All assets uploaded successfully');
280278
return completionJwt;
281279
}
@@ -284,21 +282,23 @@ async function main(): Promise<void> {
284282
try {
285283
console.log('🚀 Starting Worker creation and deployment with static assets...');
286284
console.log(`📁 Assets directory: ${config.assetsDirectory}`);
287-
285+
288286
console.log('📝 Creating asset manifest...');
289287
const manifest = createManifest(config.assetsDirectory);
290288
const exampleFile = Object.keys(manifest)[0]?.replace(/^\//, '') || 'file.txt';
291289

292290
const scriptContent = generateWorkerScript(exampleFile);
293-
291+
294292
let worker;
295293
try {
296294
worker = await client.workers.beta.workers.get(config.workerName, {
297295
account_id: config.accountId,
298296
});
299297
console.log(`♻️ Worker ${config.workerName} already exists. Using it.`);
300298
} catch (error) {
301-
if (!(error instanceof Cloudflare.NotFoundError)) { throw error; }
299+
if (!(error instanceof Cloudflare.NotFoundError)) {
300+
throw error;
301+
}
302302
console.log(`✏️ Creating Worker ${config.workerName}...`);
303303
worker = await client.workers.beta.workers.create({
304304
account_id: config.accountId,
@@ -314,39 +314,28 @@ async function main(): Promise<void> {
314314

315315
console.log(`⚙️ Worker id: ${worker.id}`);
316316
console.log('🔄 Starting asset upload session...');
317-
318-
const uploadResponse = await client.workers.scripts.assets.upload.create(
319-
config.workerName,
320-
{
321-
account_id: config.accountId,
322-
manifest,
323-
}
324-
);
325-
317+
318+
const uploadResponse = await client.workers.scripts.assets.upload.create(config.workerName, {
319+
account_id: config.accountId,
320+
manifest,
321+
});
322+
326323
const { buckets, jwt: uploadJwt } = uploadResponse;
327-
324+
328325
if (!uploadJwt || !buckets) {
329326
throw new Error('Failed to start asset upload session');
330327
}
331-
328+
332329
let completionJwt: string;
333-
330+
334331
if (buckets.length === 0) {
335332
console.log('✅ No new assets to upload!');
336333
// Use the initial upload JWT as completion JWT when no uploads are needed
337334
completionJwt = uploadJwt;
338335
} else {
339-
const payloads = await createUploadPayloads(
340-
buckets,
341-
manifest,
342-
config.assetsDirectory
343-
);
344-
345-
completionJwt = await uploadAssets(
346-
payloads,
347-
uploadJwt,
348-
config.accountId
349-
);
336+
const payloads = await createUploadPayloads(buckets, manifest, config.assetsDirectory);
337+
338+
completionJwt = await uploadAssets(payloads, uploadJwt, config.accountId);
350339
}
351340

352341
console.log('✏️ Creating Worker version...');
@@ -373,23 +362,23 @@ async function main(): Promise<void> {
373362
},
374363
],
375364
});
376-
365+
377366
console.log('🚚 Creating Worker deployment...');
378-
367+
379368
// Create a deployment and point all traffic to the version we created
380369
await client.workers.scripts.deployments.create(config.workerName, {
381370
account_id: config.accountId,
382371
strategy: 'percentage',
383372
versions: [
384373
{
385-
percentage: 100,
386-
version_id: version.id,
387-
},
388-
],
374+
percentage: 100,
375+
version_id: version.id,
376+
},
377+
],
389378
});
390379

391380
console.log('✅ Deployment successful!');
392-
381+
393382
if (config.subdomain) {
394383
console.log(`
395384
🌍 Your Worker is live!

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cloudflare",
3-
"version": "5.0.0",
3+
"version": "5.1.0",
44
"description": "The official TypeScript library for the Cloudflare API",
55
"author": "Cloudflare <[email protected]>",
66
"types": "dist/index.d.ts",

0 commit comments

Comments
 (0)