cloudflare / cloudflare-typescript Goto Github PK
View Code? Open in Web Editor NEWThe official Typescript library for the Cloudflare API
Home Page: https://developers.cloudflare.com/api
License: Apache License 2.0
The official Typescript library for the Cloudflare API
Home Page: https://developers.cloudflare.com/api
License: Apache License 2.0
When a Forwarding URL page rule is created via the Dashboard and then retrieved via the API then the action id is forwarding_url
. The TypeScript SDK requires this value to be forward_url
. However, when `` is called with forward_url
then the API returns an `HTTP 400` with a message `Unable to parse page rule`.
Change the SDK to use forwarding_url
instead of forward_url
.
I am using 3.0.0-beta.3
I am trying to create a NS dns record.
When calling client.dns.records.create we are meant to pass in an object of type RecordCreateParams
. According to the underlying API, this should be able to take a content
attribute and a type
attribute. Content will be the NS to point to. Type should be set to the value NS
.
However, RecordCreateParams
doesn't include a content
attribute in the root (it's there buried in an attribute named data
and if that's what I'm supposed to use then fine, but it doesn't seem like that's correct according to the underlying API or the code if I'm reading it right).
Also, RecordCreateParams
has the type
attribute hardcoded to URI
. Am I thinking about this wrong? This seems like a bug in your type.
Here's my code and what I had to do. Note I have not yet run this code as I feared jacking things up not knowing if this cloudflare library is really a good idea or not or whether I need to fall back to just hitting the underlying APIs directly myself. Thanks for the attention.
await client.dns.records.create({
zone_id: zoneId,
name: fullDomanName,
// The type for RecordCreateParams says this has to be URI but the API itself accepts NS
type: 'NS',
// The type for RecordCreateParams doesn't allow this but the API does
content: nsName
} as unknown as RecordCreateParams);
Hi!, I'm trying to upload the Cloudflare Worker, and receiving this error:
2 | import { castToError } from "./core.mjs";
3 | export class CloudflareError extends Error {
4 | }
5 | export class APIError extends CloudflareError {
6 | constructor(status, error, message, headers) {
7 | super(`${APIError.makeMessage(status, error, message)}`);
^
error: 400 {"result":null,"success":false,"errors":[{"code":10021,"message":"could not read content for part metadata"}],"messages":[]}
at new CloudflareError (:1:33)
at new APIError (/home/mrbye/Documents/GitHub/flow-server/node_modules/cloudflare/error.mjs:7:9)
at new BadRequestError (/home/mrbye/Documents/GitHub/flow-server/node_modules/cloudflare/error.mjs:85:9)
at generate (/home/mrbye/Documents/GitHub/flow-server/node_modules/cloudflare/error.mjs:36:20)
at /home/mrbye/Documents/GitHub/flow-server/node_modules/cloudflare/core.mjs:289:25
My current code, (the config is correct):
import Cloudflare, { toFile } from "cloudflare";
import { config } from "$app/config";
const cf = new Cloudflare({
apiToken: config.cloudflare.apiToken
});
cf.workers.scripts.update("test-worker", {
"<any part name>": [
await toFile(Buffer.from(`export default {
async fetch() {
return new Response("Hello!");
}
}`), "index.js", {
type: "application/javascript"
})
],
metadata: {
bindings: [],
main_module: "index.js",
},
account_id: config.cloudflare.accountId
})
Also, after reviewing the cloudflare
code, I tried following:
cf.workers.scripts.update("test-worker", {
"index.js": new File([`export default {
async fetch() {
return new Response("Hello!");
}
}`], "index.js", {
type: "application/javascript"
}),
metadata: new File([JSON.stringify({
bindings: [],
main_module: "index.js",
})], "metadata.json", {
type: "application/json"
}),
account_id: config.cloudflare.accountId
})
Which occurs another error:
2 | import { castToError } from "./core.mjs";
3 | export class CloudflareError extends Error {
4 | }
5 | export class APIError extends CloudflareError {
6 | constructor(status, error, message, headers) {
7 | super(`${APIError.makeMessage(status, error, message)}`);
^
error: 400 {"result":null,"success":false,"errors":[{"code":10021,"message":"Uncaught TypeError: Main module must be an ES module.\n"}],"messages":[]}
at new CloudflareError (:1:33)
at new APIError (/home/mrbye/Documents/GitHub/flow-server/node_modules/cloudflare/error.mjs:7:9)
at new BadRequestError (/home/mrbye/Documents/GitHub/flow-server/node_modules/cloudflare/error.mjs:85:9)
at generate (/home/mrbye/Documents/GitHub/flow-server/node_modules/cloudflare/error.mjs:36:20)
at /home/mrbye/Documents/GitHub/flow-server/node_modules/cloudflare/core.mjs:289:25
I'm getting invalid format error with await cloudflare.accounts.list()
Error: 400 {"success":false,"errors":[{"code":6003,"message":"Invalid request headers","error_chain":[{"code":6103,"message":"Invalid format for X-Auth-Key header"}]}],"messages":[],"result":null}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.