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 store = new KeyValueStore(authenticatedEnv);
|
||||||
|
|
||||||
const { key } = parsedParams.data;
|
const decodedKey = decodeURIComponent(parsedParams.data.key);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
switch (parsedMethod.data) {
|
switch (parsedMethod.data) {
|
||||||
case "DELETE": {
|
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": {
|
case "PUT": {
|
||||||
const value = await request.text();
|
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: {
|
default: {
|
||||||
assertExhaustive(parsedMethod.data);
|
assertExhaustive(parsedMethod.data);
|
||||||
|
|||||||
@@ -595,7 +595,9 @@ export class ApiClient {
|
|||||||
data,
|
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 = {
|
const authHeader: HeadersInit = {
|
||||||
Authorization: `Bearer ${apiKey}`,
|
Authorization: `Bearer ${apiKey}`,
|
||||||
@@ -627,7 +629,7 @@ export class ApiClient {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
action: "HAS",
|
action: "HAS",
|
||||||
key: data.key,
|
key: encodedKey,
|
||||||
has: !!headResponse.ok,
|
has: !!headResponse.ok,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -307,6 +307,13 @@ client.defineJob({
|
|||||||
name: "store.example",
|
name: "store.example",
|
||||||
}),
|
}),
|
||||||
run: async (payload, io, ctx) => {
|
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
|
// value tests
|
||||||
await io.store.job.set("set-undefined", "test", undefined);
|
await io.store.job.set("set-undefined", "test", undefined);
|
||||||
await io.store.job.get("get-undefined", "test");
|
await io.store.job.get("get-undefined", "test");
|
||||||
|
|||||||
Reference in New Issue
Block a user