Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Store Cloudflare KV with more control and power.
kv.put
...) avoid hitting the 50 subrequest to fast.For more example check test
folder
import { KVNamespaceApi } from 'superkv'
import { ulid } from 'ulid'
interface User {
username: string
points: number
active: boolean
timestamp: number
}
const userTableDefinition = {
name: 'users',
prefix: {
'username': {
keyValue: (metadata) => metadata.username
},
'>500points': {
filter: (metadata) => metadata.points > 500,
},
'isActive': {
sortValue: (metadata) => metadata.active ? 'true' : 'false',
},
'timestamp_desc': {
sortValue: (metadata) => ulid(timestamp),
},
}
} as KVTableDefinition<User>
const main = async () => {
const accountId = '', authToken = ''
const kvNamespaceApi = new KVNamespaceApi({ accountId }, { authToken })
const namespace = await kvNamespaceApi.createOrGetNamespace('worker_namespace')
const kvApi = kvNamespaceApi.useKVApi()
const kvUsers = kvApi.useKVTable(userTableDefinition)
// Get user by key
const user = await kvUsers.getMetadata('{key}')
// Get user by username
const user = await kvUsers.getMetadata('{username}'. 'username')
// Get users with lease 500 points
const prefix = kvUsers.createPrefixKey('>500points')
const list = await kvUsers.list({ prefix })
// Get active users
const prefix = kvUsers.createPrefixKey('isActive', 'true')
const list = await kvUsers.list({ prefix })
// Get latest users
const prefix = kvUsers.createPrefixKey('timestamp_desc')
const list = await kvUsers.list({ prefix })
}
main()
import { KVNamespaceApi } from 'superkv'
const accountId = '', authToken = ''
const kvNamespaceApi = new KVNamespaceApi({ accountId }, { authToken })
const res = await kvNamespaceApi.createNamespace('{title}')
// { success, errors, messages }
const namespace = res.result
// { id, title, supports_url_encoding }
const res = await kvNamespaceApi.renameNamespace('{namespaceId}', '{title}')
const res = await kvNamespaceApi.removeNamespace('{namespaceId}')
const res = await kvNamespaceApi.listNamespaces()
const res = await kvNamespaceApi.listNamespaces({ direction: 'desc', order: 'id', page: 0, per_page: 1 })
const namespace = await kvNamespaceApi.createOrGetNamespace('{namespaceTitle}')
I usually use this for testing and want to purge data every run
const namespace = await kvNamespaceApi.resetAndGetNamespace('{namespaceTitle}')
const namespace = await kvNamespaceApi.createOrGetNamespace('{namespaceTitle}')
const kvApi = kvNamespaceApi.useKVApi(namespace.id)
// or
const kvApi = new KVApi({ kvNamespaceApi, namespaceId: namespace.id })
const res = await kvApi.readKeyValuePair('{key}')
// { success, errors, messages }
const value = res.result
const res = await kvApi.writeKeyValuePair('{key}', '{value}')
const res = await kvApi.writeKeyValuePair('{key}', '{value}', metadata, { expiration: 1578435000, expiration_ttl: 300 })
const res = await kvApi.writeMultipleKeyValuePairs([
{ key: '{key}', value: '{value}' }
{ key: '{key}', value: '{value}', metadata: {} },
{ key: '{key}', value: '{value}', metadata: {}, expiration: 1578435000, expiration_ttl: 300 }
])
const res = await kvApi.deleteKeyValuePair('{key}')
const res = await kvApi.deleteMultipleKeyValuePairs(['{key}', '{key}'])
const res = await kvApi.listKeys({ prefix: '', limit: 10, cursor: '' })
const result = res.result
// { name, expiration, metadata }[]
const result_info = res.result_info
// { count, cursor }
const tableDefinition = { name, prefix, ... }
const kvUser = kvApi.useKVTable<Metadata>(tableDefinition)
// or
const kvUser = new KVTable<Metadata>({ kvApi, tableDefinition })
const user = { username: 'fred', emai: 'fred@mail.com', ... }
await kvUsers.set('{key}', user)
await kvUsers.del('{key}')
await kvUsers.del('{key}')
const list = await kvUsers.list()
const result = list.result
// { key: name, expiration, metadata }[]
const cursor = list.cursor
// or list by prefix
const prefix = kvUsers.createPrefixKey('{prefixName}')
const list = await kvUsers.list({ prefix })
const prefix = kvUsers.createPrefixKey('{prefixName}')
const it = kvUsers.iterator(prefix)
let result = await it.next()
while (!result.done) {
const list = result.value
}
await kvUsers.updatePrefix()
await kvUsers.delPrefix('{prefixName}')
const kvBatch = kvApi.useKVBig()
// or
const kvBatch = new KVBig({ kvApi })
for (const user of users) {
await kvBatch.set('{key}', metadata, '{value}')
}
await kvBatch.finish()
for (const user of users) {
await kvBatch.del('{key}')
}
await kvBatch.finish()
const kvBig = kvApi.useKVBig()
// or
const kvBig = new KVBig({ kvApi })
import { open } from 'fs/promises'
const fd = await open('./data.txt', 'r')
await kvBig.set('{key}', fd.createReadStream())
import { open } from 'fs/promises'
const fd = await open('./data.txt', 'a')
await kvBig.get('{key}', fd.createWriteStream())
https://github.com/g45t345rt/cf-kvprefix
cf-kvprefix
is deprecated in a favor of superkv
FAQs
Store Cloudflare KV with more control and power
We found that superkv demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.