
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
cloudflare-kv-wrapper
Advanced tools
A javascript/typescript wrapper for Cloudflare's KV namespaces using REST API
A javascript/typescript wrapper for Cloudflare's KV namespaces using REST API. This helps access Cloudflare's KV data stores directly without requiring CF workers or Wrangler.
❕ NOTE: It is better to store the account ID and auth token credentials as part of your .env file and use it from there securely.

Install package via npm
npm install cloudflare-kv-wrapper
Import the appropriate module for use. You can also import their relevant types.
Initialize Used for setting the account ID and auth token for the KV namespace. Can optionally define a namespace ID as well.
import { init } from "cloudflare-kv-wrapper";
init({
accountId: "your-account-id",
authToken: "your-auth-token",
namespaceId: "your-optional-namespace-id",
});
Namespaces Used for handling KV namespaces. It is best to create a namespace from the cloudflare dashboard and use its ID directly in your code
import { ns } from "cloudflare-kv-wrapper";
import type { NSTypes } from "cloudflare-kv-wrapper";
KV Pair
Used for managing a single key-value pair.
import { kv } from "cloudflare-kv-wrapper";
import type { KVTypes } from "cloudflare-kv-wrapper";
KV Pair (Multi)
Used for managing key-value pairs in bulk.
import { kvm } from "cloudflare-kv-wrapper";
import type { KVMTypes } from "cloudflare-kv-wrapper";
And that is it! You can start using KV namespaces and their KV pairs. For usage examples, check out the /example folder.
All functions are async functions and are fully type-supported. Each function's source API link is attached as well for further queries. You can provide the credentials and/or namespace ID beforehand using the init function or provide them as parameters in each function call.
Creates a namespace under the given title. A 400 is returned if the account already owns a namespace with this title. A namespace must be explicitly deleted to be replaced.
ns.create();
// Parameters
NSTypes.Create {
accountId?: string;
authToken?: string;
title: string;
}
// Response
NSTypes.CreateResponse {
errors: Message[];
messages: Message[];
success: boolean;
result: {
id: string;
supports_url_encoding: boolean;
title: string;
};
}
Get the namespace corresponding to the given ID.
ns.get();
// Parameters
NSTypes.Get {
accountId?: string;
authToken?: string;
namespaceId?: string;
}
// Response
NSTypes.GetResponse {
errors: Message[];
messages: Message[];
success: boolean;
result: {
id: string;
supports_url_encoding: boolean;
title: string;
};
}
Returns the namespaces owned by an account.
ns.list();
// Parameters
NSTypes.List {
accountId?: string;
authToken?: string;
}
// Response
NSTypes.ListResponse {
errors: Message[];
messages: Message[];
success: boolean;
result: {
namespaces: {
id: string;
title: string;
}[];
};
}
Deletes the namespace corresponding to the given ID.
ns.remove();
// Parameters
NSTypes.Remove {
accountId?: string;
authToken?: string;
namespaceId?: string;
}
// Response
NSTypes.RemoveResponse {
errors: Message[];
messages: Message[];
success: boolean;
}
Modifies a namespace's title.
ns.rename();
// Parameters
NSTypes.Rename {
accountId?: string;
authToken?: string;
namespaceId?: string;
title: string;
}
// Response
NSTypes.RenameResponse {
errors: Message[];
messages: Message[];
success: boolean;
result: {
id: string;
supports_url_encoding: boolean;
title: string;
};
}
Lists a namespace's keys.
kv.list();
// Parameters
KVTypes.List {
accountId?: string;
authToken?: string;
namespaceId?: string;
}
// Response
KVTypes.ListResponse {
errors: Message[];
messages: Message[];
success: boolean;
result: {
keys: string[];
};
}
Returns the metadata associated with the given key in the given namespace. Use URL-encoding to use special characters (for example, :, !, %) in the key name.
kv.metadata();
// Parameters
KVTypes.Metadata {
accountId?: string;
authToken?: string;
namespaceId?: string;
key: string;
}
// Response
KVTypes.MetadataResponse {
errors: Message[];
messages: Message[];
success: boolean;
result: {
expiration: string;
expiration_ttl: number;
key: string;
metadata: {
[key: string]: string;
};
};
}
Returns the value associated with the given key in the given namespace. Use URL-encoding to use special characters (for example, :, !, %) in the key name. If the KV-pair is set to expire at some point, the expiration time as measured in seconds since the UNIX epoch will be returned in the expiration response header.
kv.read();
// Parameters
KVTypes.Read {
accountId?: string;
authToken?: string;
namespaceId?: string;
key: string;
}
// Response
KVTypes.ReadResponse {
errors: Message[];
messages: Message[];
success: boolean;
result: {
expiration: string;
expiration_ttl: number;
key: string;
value: string;
};
}
Write a value identified by a key. Use URL-encoding to use special characters (for example, :, !, %) in the key name. Body should be the value to be stored along with JSON metadata to be associated with the key/value pair. Existing values, expirations, and metadata will be overwritten. If neither expiration nor expiration_ttl is specified, the key-value pair will never expire. If both are set, expiration_ttl is used and expiration is ignored.
kv.write();
// Parameters
KVTypes.Write {
accountId?: string;
authToken?: string;
namespaceId?: string;
key: string;
value: string;
metadata: {
[key: string]: string;
};
expiration?: string;
expiration_ttl?: number;
}
// Response
KVTypes.WriteResponse {
errors: Message[];
messages: Message[];
success: boolean;
}
Remove a KV pair from the namespace. Use URL-encoding to use special characters (for example, :, !, %) in the key name.
kv.remove();
// Parameters
KVTypes.Remove {
accountId?: string;
authToken?: string;
namespaceId?: string;
key: string;
}
// Response
KVTypes.RemoveResponse {
errors: Message[];
messages: Message[];
success: boolean;
}
Write multiple keys and values at once. Body should be an array of up to 10,000 key-value pairs to be stored, along with optional expiration information. Existing values and expirations will be overwritten. If neither expiration nor expiration_ttl is specified, the key-value pair will never expire. If both are set, expiration_ttl is used and expiration is ignored. The entire request size must be 100 megabytes or less.
kvm.write();
// Parameters
KVMTypes.Write {
accountId?: string;
authToken?: string;
namespaceId?: string;
keys: string[];
}
// Response
KVMTypes.WriteResponse {
errors: Message[];
messages: Message[];
success: boolean;
result: {
keys: {
key: string;
value: string;
}[];
};
}
Remove multiple KV pairs from the namespace. Body should be an array of up to 10,000 keys to be removed.
kvm.remove();
// Parameters
KVMTypes.Remove {
accountId?: string;
authToken?: string;
namespaceId?: string;
keys: string[];
}
// Response
KVMTypes.RemoveResponse {
errors: Message[];
messages: Message[];
success: boolean;
}
If you face any issues, raise a request and I will try my best to solve it. Enjoy! 👍
FAQs
A javascript/typescript wrapper for Cloudflare's KV namespaces using REST API
We found that cloudflare-kv-wrapper demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.