diff --git a/.changeset/fast-numbers-prove.md b/.changeset/fast-numbers-prove.md new file mode 100644 index 000000000..437d48604 --- /dev/null +++ b/.changeset/fast-numbers-prove.md @@ -0,0 +1,5 @@ +--- +"@codemod-com/backend": patch +--- + +Fix receiving the namespace in the publish route diff --git a/.changeset/slimy-drinks-roll.md b/.changeset/slimy-drinks-roll.md new file mode 100644 index 000000000..892b2add4 --- /dev/null +++ b/.changeset/slimy-drinks-roll.md @@ -0,0 +1,5 @@ +--- +"codemod": patch +--- + +Add content type for publish request header diff --git a/apps/backend/package.json b/apps/backend/package.json index d5fce9c27..c9efd6dfa 100644 --- a/apps/backend/package.json +++ b/apps/backend/package.json @@ -4,7 +4,8 @@ "scripts": { "build": "tsc && node esbuild.config.js", "start": "node build/index.js", - "test": "vitest --run" + "test": "vitest --run", + "dev": "nodemon --exec tsx watch src/index.ts" }, "author": "Codemod inc.", "private": true, diff --git a/apps/backend/src/publishHandler.ts b/apps/backend/src/publishHandler.ts index c273348a2..d9d12d077 100644 --- a/apps/backend/src/publishHandler.ts +++ b/apps/backend/src/publishHandler.ts @@ -71,20 +71,23 @@ export const publishHandler: RouteHandler<{ let codemodTarArchiveBuffer: Buffer | null = null; let codemodZipArchiveBuffer: Buffer | null = null; - for await (const multipartFile of request.files({ - limits: { fileSize: 1024 * 1024 * 100 }, + let namespace: string | null = null; + for await (const part of request.parts({ + limits: { + fileSize: 1024 * 1024 * 100, + }, })) { - const buffer = await multipartFile.toBuffer(); - - if (multipartFile.fieldname === "codemod.tar.gz") { - codemodTarArchiveBuffer = buffer; - } - - if (multipartFile.fieldname === "codemod.zip") { - codemodZipArchiveBuffer = buffer; + if (part.fieldname === "namespace" && "value" in part) { + namespace = part.value as string; + } else if (part.fieldname === "codemod.tar.gz" && "file" in part) { + codemodTarArchiveBuffer = await (part as any).toBuffer(); + } else if (part.fieldname === "codemod.zip" && "file" in part) { + codemodZipArchiveBuffer = await (part as any).toBuffer(); } } + console.log(namespace, "namespace"); + let codemodArchiveBuffer: Buffer; if (codemodTarArchiveBuffer !== null) { codemodArchiveBuffer = codemodTarArchiveBuffer; @@ -176,14 +179,6 @@ export const publishHandler: RouteHandler<{ ? `${name}-${randomBytes(4).toString("hex")}` : name; - let namespace: string | null = null; - try { - const formData = await request.formData(); - namespace = formData.get("namespace")?.toString() ?? null; - } catch (err) { - // - } - let isPrivate = false; if (!namespace) { diff --git a/apps/backend/src/util.ts b/apps/backend/src/util.ts index a20c865db..364446734 100644 --- a/apps/backend/src/util.ts +++ b/apps/backend/src/util.ts @@ -1,5 +1,8 @@ +import { configDotenv } from "dotenv"; import { parseEnvironment } from "./schemata/env.js"; +configDotenv(); + export const buildTimeoutPromise = (ms: number) => new Promise((resolve) => { setTimeout(() => { diff --git a/apps/cli/src/api.ts b/apps/cli/src/api.ts index 8119efdbd..88076996a 100644 --- a/apps/cli/src/api.ts +++ b/apps/cli/src/api.ts @@ -128,7 +128,9 @@ export const publish = async ( }, formData: FormData, ): Promise => { - const headers: RawAxiosRequestHeaders = {}; + const headers: RawAxiosRequestHeaders = { + "Content-Type": "multipart/form-data", + }; if (credentials.accessToken) { headers.Authorization = `Bearer ${credentials.accessToken}`; } else if (credentials.apiKey) { diff --git a/apps/cli/test/api.test.ts b/apps/cli/test/api.test.ts index e59a30a5e..1458adc84 100644 --- a/apps/cli/test/api.test.ts +++ b/apps/cli/test/api.test.ts @@ -289,7 +289,10 @@ describe("API Client Tests", () => { "http://api.example.com/publish", mockFormData, { - headers: { Authorization: `Bearer ${mockAccessToken}` }, + headers: { + "Content-Type": "multipart/form-data", + Authorization: `Bearer ${mockAccessToken}`, + }, timeout: 10000, }, ); @@ -304,7 +307,10 @@ describe("API Client Tests", () => { "http://api.example.com/publish", mockFormData, { - headers: { "X-API-Key": mockApiKey }, + headers: { + "Content-Type": "multipart/form-data", + "X-API-Key": mockApiKey, + }, timeout: 10000, }, ); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 02f64ac4a..c76350a39 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -628,7 +628,7 @@ catalogs: specifier: ^0.3.5 version: 0.3.5 next: - specifier: ^14.2.26 + specifier: ^14.2.3 version: 14.2.28 next-sanity: specifier: ^8.5.0 @@ -16801,8 +16801,8 @@ snapshots: '@aws-crypto/sha1-browser': 5.2.0 '@aws-crypto/sha256-browser': 5.2.0 '@aws-crypto/sha256-js': 5.2.0 - '@aws-sdk/client-sso-oidc': 3.600.0(@aws-sdk/client-sts@3.600.0) - '@aws-sdk/client-sts': 3.600.0 + '@aws-sdk/client-sso-oidc': 3.600.0 + '@aws-sdk/client-sts': 3.600.0(@aws-sdk/client-sso-oidc@3.600.0) '@aws-sdk/core': 3.598.0 '@aws-sdk/credential-provider-node': 3.600.0(@aws-sdk/client-sso-oidc@3.600.0)(@aws-sdk/client-sts@3.600.0) '@aws-sdk/middleware-bucket-endpoint': 3.598.0 @@ -16859,11 +16859,11 @@ snapshots: transitivePeerDependencies: - aws-crt - '@aws-sdk/client-sso-oidc@3.600.0(@aws-sdk/client-sts@3.600.0)': + '@aws-sdk/client-sso-oidc@3.600.0': dependencies: '@aws-crypto/sha256-browser': 5.2.0 '@aws-crypto/sha256-js': 5.2.0 - '@aws-sdk/client-sts': 3.600.0 + '@aws-sdk/client-sts': 3.600.0(@aws-sdk/client-sso-oidc@3.600.0) '@aws-sdk/core': 3.598.0 '@aws-sdk/credential-provider-node': 3.600.0(@aws-sdk/client-sso-oidc@3.600.0)(@aws-sdk/client-sts@3.600.0) '@aws-sdk/middleware-host-header': 3.598.0 @@ -16902,7 +16902,6 @@ snapshots: '@smithy/util-utf8': 3.0.0 tslib: 2.8.1 transitivePeerDependencies: - - '@aws-sdk/client-sts' - aws-crt '@aws-sdk/client-sso@3.598.0': @@ -16948,11 +16947,11 @@ snapshots: transitivePeerDependencies: - aws-crt - '@aws-sdk/client-sts@3.600.0': + '@aws-sdk/client-sts@3.600.0(@aws-sdk/client-sso-oidc@3.600.0)': dependencies: '@aws-crypto/sha256-browser': 5.2.0 '@aws-crypto/sha256-js': 5.2.0 - '@aws-sdk/client-sso-oidc': 3.600.0(@aws-sdk/client-sts@3.600.0) + '@aws-sdk/client-sso-oidc': 3.600.0 '@aws-sdk/core': 3.598.0 '@aws-sdk/credential-provider-node': 3.600.0(@aws-sdk/client-sso-oidc@3.600.0)(@aws-sdk/client-sts@3.600.0) '@aws-sdk/middleware-host-header': 3.598.0 @@ -16991,6 +16990,7 @@ snapshots: '@smithy/util-utf8': 3.0.0 tslib: 2.8.1 transitivePeerDependencies: + - '@aws-sdk/client-sso-oidc' - aws-crt '@aws-sdk/core@3.598.0': @@ -17024,7 +17024,7 @@ snapshots: '@aws-sdk/credential-provider-ini@3.598.0(@aws-sdk/client-sso-oidc@3.600.0)(@aws-sdk/client-sts@3.600.0)': dependencies: - '@aws-sdk/client-sts': 3.600.0 + '@aws-sdk/client-sts': 3.600.0(@aws-sdk/client-sso-oidc@3.600.0) '@aws-sdk/credential-provider-env': 3.598.0 '@aws-sdk/credential-provider-http': 3.598.0 '@aws-sdk/credential-provider-process': 3.598.0 @@ -17082,7 +17082,7 @@ snapshots: '@aws-sdk/credential-provider-web-identity@3.598.0(@aws-sdk/client-sts@3.600.0)': dependencies: - '@aws-sdk/client-sts': 3.600.0 + '@aws-sdk/client-sts': 3.600.0(@aws-sdk/client-sso-oidc@3.600.0) '@aws-sdk/types': 3.598.0 '@smithy/property-provider': 3.1.2 '@smithy/types': 3.2.0 @@ -17209,7 +17209,7 @@ snapshots: '@aws-sdk/token-providers@3.598.0(@aws-sdk/client-sso-oidc@3.600.0)': dependencies: - '@aws-sdk/client-sso-oidc': 3.600.0(@aws-sdk/client-sts@3.600.0) + '@aws-sdk/client-sso-oidc': 3.600.0 '@aws-sdk/types': 3.598.0 '@smithy/property-provider': 3.1.2 '@smithy/shared-ini-file-loader': 3.1.2