Skip to content

Commit a80e88f

Browse files
committed
small tweaks to example
1 parent acecef7 commit a80e88f

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

src/content/changelog/workers/2025-06-17-workers-terraform-sdk-api-fixes.mdx

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ We've simplified the programmatic deployment of Workers via our [Cloudflare SDKs
1616

1717
This new interface is available in:
1818

19-
- [cloudlfare-typescript](https://github.com/cloudflare/cloudflare-typescript) (4.4.1)
19+
- [cloudflare-typescript](https://github.com/cloudflare/cloudflare-typescript) (4.4.1)
2020
- [cloudflare-python](https://github.com/cloudflare/cloudflare-python) (4.3.1)
2121

2222
For complete examples, see our guide on [programmatic Worker deployments](/workers/platform/infrastructure-as-code).
@@ -55,24 +55,35 @@ EOF
5555

5656
With the new SDK interface, you can now define your entire Worker configuration using a single, structured object.
5757

58-
This approach allows you to specify metadata like `main_module`, `bindings`, and `compatibility_date` as top-level properties directly alongside your script content. Our SDK takes this logical object and automatically constructs the complex multipart/form-data API request behind the scenes.
58+
This approach allows you to specify metadata like `main_module`, `bindings`, and `compatibility_date` as clearer properties directly alongside your script content. Our SDK takes this logical object and automatically constructs the complex multipart/form-data API request behind the scenes.
5959

60-
Here's how you can now programmatically deploy a Worker via the [`cloudlfare-typescript` SDK](https://github.com/cloudflare/cloudflare-typescript)
60+
Here's how you can now programmatically deploy a Worker via the [`cloudflare-typescript` SDK](https://github.com/cloudflare/cloudflare-typescript)
6161

6262
<TypeScriptExample>
6363
```ts
64+
import Cloudflare from 'cloudflare';
65+
import { toFile } from 'cloudflare/index';
66+
67+
// ... client setup, script content, etc.
68+
6469
const script = await client.workers.scripts.update(scriptName, {
6570
account_id: accountID,
66-
main_module: `${scriptName}.mjs`,
67-
body: scriptContent,
68-
bindings: [
69-
{},
70-
],
71+
metadata: {
72+
main_module: scriptFileName,
73+
bindings: [],
74+
},
75+
files: {
76+
[scriptFileName]: await toFile(Buffer.from(scriptContent), scriptFileName, {
77+
type: 'application/javascript+module',
78+
}),
79+
},
7180
});
72-
````
81+
```
7382

7483
</TypeScriptExample>
7584

85+
View the complete example here: https://github.com/cloudflare/cloudflare-typescript/blob/main/examples/workers/script-upload.ts
86+
7687
## Terraform provider improvements
7788

7889
We've also made several fixes and enhancements to the [Cloudflare Terraform provider](https://github.com/cloudflare/terraform-provider-cloudflare):
@@ -85,3 +96,6 @@ We've also made several fixes and enhancements to the [Cloudflare Terraform prov
8596
## API improvements
8697

8798
We've also properly documented the [Workers Script And Version Settings](/api/resources/workers/subresources/scripts/subresources/script_and_version_settings) in our public OpenAPI spec and SDKs.
99+
100+
101+
```

0 commit comments

Comments
 (0)