URI encode keys (#758)
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@trigger.dev/sdk": patch
|
||||
---
|
||||
|
||||
Fix: `Key-Value Store` keys will now be URI encoded
|
||||
@@ -42,14 +42,14 @@ export async function action({ request, params }: ActionFunctionArgs) {
|
||||
|
||||
const store = new KeyValueStore(authenticatedEnv);
|
||||
|
||||
const { key } = parsedParams.data;
|
||||
const decodedKey = decodeURIComponent(parsedParams.data.key);
|
||||
|
||||
try {
|
||||
switch (parsedMethod.data) {
|
||||
case "DELETE": {
|
||||
const deleted = await store.delete(key);
|
||||
const deleted = await store.delete(decodedKey);
|
||||
|
||||
return json({ action: "DELETE", key, deleted });
|
||||
return json({ action: "DELETE", key: decodedKey, deleted });
|
||||
}
|
||||
case "PUT": {
|
||||
const value = await request.text();
|
||||
@@ -65,9 +65,9 @@ export async function action({ request, params }: ActionFunctionArgs) {
|
||||
);
|
||||
}
|
||||
|
||||
const setValue = await store.set(key, value);
|
||||
const setValue = await store.set(decodedKey, value);
|
||||
|
||||
return json({ action: "SET", key, value: setValue });
|
||||
return json({ action: "SET", key: decodedKey, value: setValue });
|
||||
}
|
||||
default: {
|
||||
assertExhaustive(parsedMethod.data);
|
||||
|
||||
@@ -595,7 +595,9 @@ export class ApiClient {
|
||||
data,
|
||||
});
|
||||
|
||||
const STORE_URL = `${this.#apiUrl}/api/v1/store/${data.key}`;
|
||||
const encodedKey = encodeURIComponent(data.key);
|
||||
|
||||
const STORE_URL = `${this.#apiUrl}/api/v1/store/${encodedKey}`;
|
||||
|
||||
const authHeader: HeadersInit = {
|
||||
Authorization: `Bearer ${apiKey}`,
|
||||
@@ -627,7 +629,7 @@ export class ApiClient {
|
||||
|
||||
return {
|
||||
action: "HAS",
|
||||
key: data.key,
|
||||
key: encodedKey,
|
||||
has: !!headResponse.ok,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -307,6 +307,13 @@ client.defineJob({
|
||||
name: "store.example",
|
||||
}),
|
||||
run: async (payload, io, ctx) => {
|
||||
// key tests
|
||||
await io.store.job.set("set-emoji", "🍔", "🐮");
|
||||
await io.store.job.get("get-emoji", "🍔");
|
||||
|
||||
await io.store.job.set("set-url", "https://example.com/?foo=bar", "url");
|
||||
await io.store.job.get("get-url", "https://example.com/?foo=bar");
|
||||
|
||||
// value tests
|
||||
await io.store.job.set("set-undefined", "test", undefined);
|
||||
await io.store.job.get("get-undefined", "test");
|
||||
|
||||
Reference in New Issue
Block a user