From 9b01609048f9c4aa2ec02879a18c8e6900cc1e52 Mon Sep 17 00:00:00 2001 From: Andrew Heberle Date: Wed, 7 Oct 2026 09:08:31 +0800 Subject: [PATCH] refactor: change bundling and no longer use extensionless imports --- packages/core/.gitignore | 1 + packages/core/src/api/v3/index.ts | 25 +++++----- packages/core/src/api/v3/schema.ts | 6 +-- packages/core/src/certificate.ts | 20 ++++---- packages/core/src/db/index.ts | 8 ++-- packages/core/src/db/migrations/index.ts | 2 +- packages/core/src/index.ts | 8 ++-- packages/core/src/krl.ts | 2 +- packages/core/src/logger.ts | 2 +- packages/core/src/proof.ts | 12 +++-- packages/core/src/router.ts | 6 +-- packages/core/src/sshsig/formats.ts | 2 +- packages/core/src/sshsig/index.ts | 6 +-- packages/core/src/sshsig/sig.ts | 2 +- packages/core/src/sshsig/sig_parser.ts | 8 ++-- packages/core/src/sshsig/verifier.ts | 6 +-- packages/core/src/utils.ts | 18 ++++--- packages/core/src/verify.ts | 6 +-- packages/core/tests/certificate.test.ts | 16 +++---- packages/core/tests/db.test.ts | 4 +- packages/core/tests/env.ts | 2 +- packages/core/tests/esm-output.test.ts | 48 +++++++++++++++++++ packages/core/tests/helpers/proof.ts | 2 +- packages/core/tests/host-certificate.test.ts | 14 +++--- .../core/tests/issuance-db-failure.test.ts | 16 +++---- packages/core/tests/krl.test.ts | 8 ++-- packages/core/tests/proof.test.ts | 2 +- packages/core/tests/schema-headers.test.ts | 6 +-- .../tests/schema-revoke-certificate.test.ts | 10 ++-- .../tests/schema-user-certificate.test.ts | 10 ++-- packages/core/tests/sshsig.test.ts | 8 ++-- packages/core/tests/utils.test.ts | 18 +++---- packages/core/tsconfig.json | 4 +- 33 files changed, 181 insertions(+), 127 deletions(-) create mode 100644 packages/core/tests/esm-output.test.ts diff --git a/packages/core/.gitignore b/packages/core/.gitignore index 17998065..066163ec 100644 --- a/packages/core/.gitignore +++ b/packages/core/.gitignore @@ -1 +1,2 @@ openapi.json +.esm-check-* diff --git a/packages/core/src/api/v3/index.ts b/packages/core/src/api/v3/index.ts index fceabbce..be8c45a0 100644 --- a/packages/core/src/api/v3/index.ts +++ b/packages/core/src/api/v3/index.ts @@ -11,8 +11,8 @@ import { UnprocessableEntityException, } from "chanfana" import { Hono } from "hono" -import { AppContext } from "../../router" -import { CertificateSignerResponse } from "../../types" +import { AppContext } from "../../router.js" +import { CertificateSignerResponse } from "../../types.js" import { BadIssuerError, CreateCertificateOptions, @@ -20,16 +20,14 @@ import { createSignedCertificate, createSignedHostCertificate, -} from "../../certificate" +} from "../../certificate.js" import { getPrivateKey, getPublic, split, UnsupportedKeyError, -} from "../../utils" -import { - KeyParseError, -} from "sshpk" +} from "../../utils.js" +import sshpk from "sshpk" import { CertificateType, getRevocationList, @@ -37,8 +35,8 @@ import { RevocationStatus, revocationStatus, revokeCertificate, -} from "../../db" -import { KRLBuilder } from "../../krl" +} from "../../db/index.js" +import { KRLBuilder } from "../../krl.js" import { CaPublicKeyEndpointSchema, createUserCertificateRequestEndpointSchema, @@ -46,9 +44,12 @@ import { createHostCertificateRequestEndpointSchema, createHostCertificateRenewEndpointSchema, createRevokeCertificateEndpointSchema, -} from "./schema" -import { logger } from "../../logger" -import type { SshCaBindings } from "../../types" +} from "./schema.js" +import { logger } from "../../logger.js" +import type { SshCaBindings } from "../../types.js" + +// sshpk is CommonJS and Node's ESM loader cannot detect most of its named exports, so values are taken from the default import +const { KeyParseError } = sshpk const CaPublicKeyEndpoint = (env: SshCaBindings) => { return class extends OpenAPIRoute { diff --git a/packages/core/src/api/v3/schema.ts b/packages/core/src/api/v3/schema.ts index e8dae91d..8270a42c 100644 --- a/packages/core/src/api/v3/schema.ts +++ b/packages/core/src/api/v3/schema.ts @@ -1,5 +1,5 @@ import z from "zod" -import type { SshCaBindings } from "../../types" +import type { SshCaBindings } from "../../types.js" import { split, refineCertificateRequest, @@ -12,7 +12,7 @@ import { refineHostCertificateRenewal, refineRevokeCertificate, transformIdentityToken, -} from "../../utils" +} from "../../utils.js" import { ConflictException, contentJson, @@ -23,7 +23,7 @@ import { UnprocessableEntityException, } from "chanfana" import { seconds } from "itty-time" -import { isRevoked } from "../../db" +import { isRevoked } from "../../db/index.js" const openapiStringByte = z.base64() .transform((v) => { diff --git a/packages/core/src/certificate.ts b/packages/core/src/certificate.ts index fd447e75..e911f01f 100644 --- a/packages/core/src/certificate.ts +++ b/packages/core/src/certificate.ts @@ -1,16 +1,12 @@ import { seconds } from "itty-time" -import { - Certificate, - createCertificate, - Identity, - identityForHost, - identityForUser, - identityFromDN, - Key, - PrivateKey } from "sshpk" -import { SSHExtension } from "./types" -import { getPrivateKey, split } from "./utils" -import type { SshCaBindings } from "./types" +import sshpk from "sshpk" +import type { Certificate, Identity, Key, PrivateKey } from "sshpk" +import { SSHExtension } from "./types.js" +import { getPrivateKey, split } from "./utils.js" +import type { SshCaBindings } from "./types.js" + +// sshpk is CommonJS and Node's ESM loader cannot detect most of its named exports, so values are taken from the default import +const { createCertificate, identityForHost, identityForUser, identityFromDN } = sshpk // const sshCertificateExtensions = split(env.SSH_CERTIFICATE_EXTENSIONS) diff --git a/packages/core/src/db/index.ts b/packages/core/src/db/index.ts index 96721b96..65d88a93 100644 --- a/packages/core/src/db/index.ts +++ b/packages/core/src/db/index.ts @@ -1,8 +1,8 @@ -import { Certificate, Format, Identity } from "sshpk" -import { logger } from "../logger" -import type { SshCaBindings } from "../types" +import type { Certificate, Format, Identity } from "sshpk" +import { logger } from "../logger.js" +import type { SshCaBindings } from "../types.js" import { D1QB } from "workers-qb" -import { migrations } from "./migrations" +import { migrations } from "./migrations/index.js" export enum CertificateType { User, diff --git a/packages/core/src/db/migrations/index.ts b/packages/core/src/db/migrations/index.ts index e76eb31f..bc08f623 100644 --- a/packages/core/src/db/migrations/index.ts +++ b/packages/core/src/db/migrations/index.ts @@ -1,5 +1,5 @@ import { type Migration } from "workers-qb" -import { migration as initialSchema0001 } from "./0001_initial_schema" +import { migration as initialSchema0001 } from "./0001_initial_schema.js" export const migrations: Migration[] = [ initialSchema0001 diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index da869262..d15666cc 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -1,7 +1,7 @@ -import { dbCleanup } from "./db" -import { createApp } from "./router" -import type { SshCaBindings } from "./types" -export type { SshCaBindings } from "./types" +import { dbCleanup } from "./db/index.js" +import { createApp } from "./router.js" +import type { SshCaBindings } from "./types.js" +export type { SshCaBindings } from "./types.js" let app: ReturnType | undefined diff --git a/packages/core/src/krl.ts b/packages/core/src/krl.ts index f66dd769..647b958f 100644 --- a/packages/core/src/krl.ts +++ b/packages/core/src/krl.ts @@ -1,5 +1,5 @@ import type { AlgorithmPart, PrivateKey } from "sshpk" -import { toFixedWidth } from "./sshsig/sig_parser" +import { toFixedWidth } from "./sshsig/sig_parser.js" // ── Constants ──────────────────────────────────────────────────────────────── diff --git a/packages/core/src/logger.ts b/packages/core/src/logger.ts index 4f1eac85..81da687a 100644 --- a/packages/core/src/logger.ts +++ b/packages/core/src/logger.ts @@ -1,4 +1,4 @@ -import type { SshCaBindings } from "./types" +import type { SshCaBindings } from "./types.js" import { Logger, LogLevel } from "@andrewheberle/ts-slog" export const logger = (env: SshCaBindings): Logger => { diff --git a/packages/core/src/proof.ts b/packages/core/src/proof.ts index 2e9597ef..224335cf 100644 --- a/packages/core/src/proof.ts +++ b/packages/core/src/proof.ts @@ -1,10 +1,14 @@ import { ms } from "itty-time" -import { Fingerprint, FingerprintFormatError, Key, parseFingerprint, parseKey } from "sshpk" -import { verify } from "./sshsig" -import { parse } from "./sshsig/sig_parser" -import { Sig } from "./sshsig/sig" +import sshpk from "sshpk" +import type { Fingerprint, Key } from "sshpk" +import { verify } from "./sshsig/index.js" +import { parse } from "./sshsig/sig_parser.js" +import { Sig } from "./sshsig/sig.js" import { group, Logger, LogLevel } from "@andrewheberle/ts-slog" +// sshpk is CommonJS and Node's ESM loader cannot detect most of its named exports, so values are taken from the default import +const { FingerprintFormatError, parseFingerprint, parseKey } = sshpk + export const Namespace = "proof-of-possession@com.github.serverless-ssh-ca.andrewheberle" export class PossessionParseError extends Error { diff --git a/packages/core/src/router.ts b/packages/core/src/router.ts index 706a8798..ca40b78d 100644 --- a/packages/core/src/router.ts +++ b/packages/core/src/router.ts @@ -1,9 +1,9 @@ import { fromHono } from "chanfana" import { Hono, type Context } from "hono" -import { createApi as apiv3 } from "./api/v3" +import { createApi as apiv3 } from "./api/v3/index.js" import { HTTPException } from "hono/http-exception" -import { logger } from "./logger" -import type { SshCaBindings } from "./types" +import { logger } from "./logger.js" +import type { SshCaBindings } from "./types.js" export type CFArgs = [SshCaBindings, ExecutionContext] export type AppContext = Context<{ Bindings: SshCaBindings }> diff --git a/packages/core/src/sshsig/formats.ts b/packages/core/src/sshsig/formats.ts index 37dedf26..e7b44f95 100644 --- a/packages/core/src/sshsig/formats.ts +++ b/packages/core/src/sshsig/formats.ts @@ -1,4 +1,4 @@ -import { Reader } from "./reader"; +import { Reader } from "./reader.js"; /** * Represents an SSH public key. diff --git a/packages/core/src/sshsig/index.ts b/packages/core/src/sshsig/index.ts index f7c3338d..73d830e5 100644 --- a/packages/core/src/sshsig/index.ts +++ b/packages/core/src/sshsig/index.ts @@ -1,6 +1,6 @@ -import { Sig } from "./sig"; -import { verify as rawVerify } from "./verifier"; -import { parse } from "./sig_parser"; +import { Sig } from "./sig.js"; +import { verify as rawVerify } from "./verifier.js"; +import { parse } from "./sig_parser.js"; /** * Verifies SSH signature against provided data. diff --git a/packages/core/src/sshsig/sig.ts b/packages/core/src/sshsig/sig.ts index aff4d622..298538d3 100644 --- a/packages/core/src/sshsig/sig.ts +++ b/packages/core/src/sshsig/sig.ts @@ -1,4 +1,4 @@ -import { Pubkey } from "./formats"; +import { Pubkey } from "./formats.js"; /** * Represents a parsed SSH signature. diff --git a/packages/core/src/sshsig/sig_parser.ts b/packages/core/src/sshsig/sig_parser.ts index 8f401c2a..3b6367d3 100644 --- a/packages/core/src/sshsig/sig_parser.ts +++ b/packages/core/src/sshsig/sig_parser.ts @@ -1,7 +1,7 @@ -import { Sig } from "./sig"; -import { Reader } from "./reader"; -import { parsePubkey } from "./formats"; -import { dearmor } from "./armor"; +import { Sig } from "./sig.js"; +import { Reader } from "./reader.js"; +import { parsePubkey } from "./formats.js"; +import { dearmor } from "./armor.js"; /** * ECDSA signature algorithms whose signatures need converting from SSH diff --git a/packages/core/src/sshsig/verifier.ts b/packages/core/src/sshsig/verifier.ts index 6204df60..5ddada27 100644 --- a/packages/core/src/sshsig/verifier.ts +++ b/packages/core/src/sshsig/verifier.ts @@ -1,6 +1,6 @@ -import { Sig } from "./sig"; -import { convertAlgorithm, convertHash, convertPublicKey } from "./formats"; -import { Writer } from "./writer"; +import { Sig } from "./sig.js"; +import { convertAlgorithm, convertHash, convertPublicKey } from "./formats.js"; +import { Writer } from "./writer.js"; export async function verify( subtle: SubtleCrypto, diff --git a/packages/core/src/utils.ts b/packages/core/src/utils.ts index 5c756b93..322b78ce 100644 --- a/packages/core/src/utils.ts +++ b/packages/core/src/utils.ts @@ -1,15 +1,19 @@ -import type { SshCaBindings } from "./types" +import type { SshCaBindings } from "./types.js" import { JWKInvalid, JWKSInvalid, JWSInvalid, JWSSignatureVerificationFailed, JWTClaimValidationFailed, JWTExpired, JWTInvalid } from "jose/errors" -import { Certificate, Key, KeyParseError, CertificateParseError, parseCertificate, parseKey, parsePrivateKey, PrivateKey } from "sshpk" +import sshpk from "sshpk" +import type { Certificate, Key, PrivateKey } from "sshpk" import z from "zod" -import { verifyJWT } from "./verify" -import { CertificateRequestJWTPayload } from "./types" -import { RenewalProofOfPossession, ProofOfPossession, PossessionParseError } from "./proof" -import type { isRevoked as IsRevokedFn } from "./db" -import { logger } from "./logger" +import { verifyJWT } from "./verify.js" +import { CertificateRequestJWTPayload } from "./types.js" +import { RenewalProofOfPossession, ProofOfPossession, PossessionParseError } from "./proof.js" +import type { isRevoked as IsRevokedFn } from "./db/index.js" +import { logger } from "./logger.js" import { ms } from "itty-time" import { InternalServerErrorException } from "chanfana" +// sshpk is CommonJS and Node's ESM loader cannot detect most of its named exports, so values are taken from the default import +const { KeyParseError, CertificateParseError, parseCertificate, parseKey, parsePrivateKey } = sshpk + export const fatalIssue = (ctx: z.RefinementCtx, message: string, val: unknown) => { ctx.issues.push({ code: "custom", diff --git a/packages/core/src/verify.ts b/packages/core/src/verify.ts index 386aaea6..a7f46957 100644 --- a/packages/core/src/verify.ts +++ b/packages/core/src/verify.ts @@ -1,7 +1,7 @@ import { createRemoteJWKSet, jwtVerify } from "jose" -import { CertificateRequestJWTPayload } from "./types" -import type { SshCaBindings } from "./types" -import { split } from "./utils" +import { CertificateRequestJWTPayload } from "./types.js" +import type { SshCaBindings } from "./types.js" +import { split } from "./utils.js" type VerifyOptions = { aud?: string | string[] diff --git a/packages/core/tests/certificate.test.ts b/packages/core/tests/certificate.test.ts index f14cfb1f..784968d9 100644 --- a/packages/core/tests/certificate.test.ts +++ b/packages/core/tests/certificate.test.ts @@ -1,14 +1,14 @@ -import { key as rsaKey } from "./keys/rsa" -import { key as ecdsaKey } from "./keys/ecdsa" -import { key as ed25519Key } from "./keys/ed25519" +import { key as rsaKey } from "./keys/rsa.js" +import { key as ecdsaKey } from "./keys/ecdsa.js" +import { key as ed25519Key } from "./keys/ed25519.js" import { describe, expect, it } from "vitest" -import { createSignedCertificate, generateCertificate, generateSerial } from "../src/certificate" +import { createSignedCertificate, generateCertificate, generateSerial } from "../src/certificate.js" import { seconds } from "itty-time" -import { split, UnsupportedKeyError } from "../src/utils" -import { makeEnv } from "./env" -import { MockSecretStore } from "./helpers/secret" +import { split, UnsupportedKeyError } from "../src/utils.js" +import { makeEnv } from "./env.js" +import { MockSecretStore } from "./helpers/secret.js" import { Format, Identity, identityForUser, PrivateKey } from "sshpk" -import { SshCaBindings } from "../src/types" +import { SshCaBindings } from "../src/types.js" const lifetimeString = "24 hours" diff --git a/packages/core/tests/db.test.ts b/packages/core/tests/db.test.ts index 64942673..13a9ce2b 100644 --- a/packages/core/tests/db.test.ts +++ b/packages/core/tests/db.test.ts @@ -1,6 +1,6 @@ import { describe, it, expect } from "vitest" -import { dbCleanup } from "../src/db" -import { makeEnv } from "./env" +import { dbCleanup } from "../src/db/index.js" +import { makeEnv } from "./env.js" // a D1 binding that records any use of it const trackedDatabase = (): { db: D1Database, used: PropertyKey[] } => { diff --git a/packages/core/tests/env.ts b/packages/core/tests/env.ts index 77722106..5d5b5641 100644 --- a/packages/core/tests/env.ts +++ b/packages/core/tests/env.ts @@ -1,4 +1,4 @@ -import type { SshCaBindings } from "../src/types" +import type { SshCaBindings } from "../src/types.js" const port = parseInt(process.env.OIDC_PORT ?? "4567") diff --git a/packages/core/tests/esm-output.test.ts b/packages/core/tests/esm-output.test.ts new file mode 100644 index 00000000..c85ea8dc --- /dev/null +++ b/packages/core/tests/esm-output.test.ts @@ -0,0 +1,48 @@ +import { describe, it, expect } from "vitest" +import { spawnSync } from "node:child_process" +import { mkdtempSync, rmSync } from "node:fs" +import { createRequire } from "node:module" +import { dirname, join, resolve } from "node:path" +import { fileURLToPath, pathToFileURL } from "node:url" +import { z } from "zod" + +const packageRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..") + +// Vitest resolves extensionless and directory imports itself, so the compiled +// output is loaded by a separate plain Node process to catch anything that only +// works under a bundler (missing extensions, CommonJS named exports, etc) +describe("compiled output", () => { + it("should be importable by Node without a bundler", () => { + // emitted inside the package so "type": "module" and node_modules resolution apply + const outDir = mkdtempSync(join(packageRoot, ".esm-check-")) + + try { + // typescript's "exports" map hides bin/tsc, so locate it via the package's "bin" field + const require = createRequire(import.meta.url) + const pkgJson = require.resolve("typescript/package.json") + const { bin } = z.object({ bin: z.object({ tsc: z.string() }) }).parse(require(pkgJson)) + const tsc = join(dirname(pkgJson), bin.tsc) + const build = spawnSync(process.execPath, [ + tsc, + "-p", join(packageRoot, "tsconfig.json"), + "--outDir", outDir, + "--declaration", "false", + "--declarationMap", "false", + "--sourceMap", "false", + ], { encoding: "utf-8" }) + expect(build.status, build.stdout + build.stderr).toBe(0) + + const entry = pathToFileURL(join(outDir, "index.js")).href + const script = ` + const mod = await import(${JSON.stringify(entry)}) + if (typeof mod.default?.fetch !== "function" || typeof mod.default?.scheduled !== "function") { + throw new Error("default export is missing fetch or scheduled handlers") + } + ` + const run = spawnSync(process.execPath, ["--input-type=module", "-e", script], { encoding: "utf-8" }) + expect(run.status, run.stderr).toBe(0) + } finally { + rmSync(outDir, { recursive: true, force: true }) + } + }, 60_000) +}) diff --git a/packages/core/tests/helpers/proof.ts b/packages/core/tests/helpers/proof.ts index 581879fa..d15b65ad 100644 --- a/packages/core/tests/helpers/proof.ts +++ b/packages/core/tests/helpers/proof.ts @@ -3,7 +3,7 @@ import { writeFileSync, readFileSync, unlinkSync, mkdtempSync } from "node:fs" import { tmpdir } from "node:os" import { join } from "node:path" import { PrivateKey } from "sshpk" -import { Namespace } from "../../src/proof" +import { Namespace } from "../../src/proof.js" export const generateProof = (key: PrivateKey): string => { const timestamp = Date.now() diff --git a/packages/core/tests/host-certificate.test.ts b/packages/core/tests/host-certificate.test.ts index 69c2520d..9c74a2dd 100644 --- a/packages/core/tests/host-certificate.test.ts +++ b/packages/core/tests/host-certificate.test.ts @@ -1,13 +1,13 @@ -import { key as rsaKey } from "./keys/rsa" -import { key as ecdsaKey } from "./keys/ecdsa" -import { key as ed25519Key } from "./keys/ed25519" +import { key as rsaKey } from "./keys/rsa.js" +import { key as ecdsaKey } from "./keys/ecdsa.js" +import { key as ed25519Key } from "./keys/ed25519.js" import { describe, expect, it } from "vitest" -import { createSignedHostCertificate } from "../src/certificate" +import { createSignedHostCertificate } from "../src/certificate.js" import { seconds } from "itty-time" -import { makeEnv } from "./env" +import { makeEnv } from "./env.js" import { Format, Identity, type PrivateKey } from "sshpk" -import { MockSecretStore } from "./helpers/secret" -import { UnsupportedKeyError } from "../src/utils" +import { MockSecretStore } from "./helpers/secret.js" +import { UnsupportedKeyError } from "../src/utils.js" type Test = { name: string diff --git a/packages/core/tests/issuance-db-failure.test.ts b/packages/core/tests/issuance-db-failure.test.ts index 96030836..1ebc5520 100644 --- a/packages/core/tests/issuance-db-failure.test.ts +++ b/packages/core/tests/issuance-db-failure.test.ts @@ -1,16 +1,16 @@ import { describe, it, expect, vi } from "vitest" -import { createApp } from "../src/router" -import { createSignedHostCertificate } from "../src/certificate" -import { makeEnv } from "./env" -import { MockSecretStore } from "./helpers/secret" -import { getAccessToken, getIdentityToken } from "./helpers/token" -import { generateProof } from "./helpers/proof" -import { key as ecdsaKey } from "./keys/ecdsa" +import { createApp } from "../src/router.js" +import { createSignedHostCertificate } from "../src/certificate.js" +import { makeEnv } from "./env.js" +import { MockSecretStore } from "./helpers/secret.js" +import { getAccessToken, getIdentityToken } from "./helpers/token.js" +import { generateProof } from "./helpers/proof.js" +import { key as ecdsaKey } from "./keys/ecdsa.js" // fail every database write, but report nothing as revoked so renewals get // as far as recording the certificate vi.mock("../src/db", async (importOriginal) => { - const original = await importOriginal() + const original = await importOriginal() return { ...original, isRevoked: vi.fn(async () => false), diff --git a/packages/core/tests/krl.test.ts b/packages/core/tests/krl.test.ts index 498a15a1..a8eeee85 100644 --- a/packages/core/tests/krl.test.ts +++ b/packages/core/tests/krl.test.ts @@ -1,9 +1,9 @@ import { describe, it, expect } from "vitest" import { generatePrivateKey, parsePrivateKey, type PrivateKey } from "sshpk" -import { KRLBuilder } from "../src/krl" -import { verify } from "../src/sshsig" -import { key as ecdsaKey } from "./keys/ecdsa" -import { key as ed25519Key } from "./keys/ed25519" +import { KRLBuilder } from "../src/krl.js" +import { verify } from "../src/sshsig/index.js" +import { key as ecdsaKey } from "./keys/ecdsa.js" +import { key as ed25519Key } from "./keys/ed25519.js" const namespace = "krl@com.github.serverless-ssh-ca.andrewheberle" diff --git a/packages/core/tests/proof.test.ts b/packages/core/tests/proof.test.ts index d4db9be2..46124701 100644 --- a/packages/core/tests/proof.test.ts +++ b/packages/core/tests/proof.test.ts @@ -1,5 +1,5 @@ import { describe, it, expect } from "vitest" -import { ProofOfPossession } from "../src/proof" +import { ProofOfPossession } from "../src/proof.js" import { Key, parseKey } from "sshpk" type testSig = { diff --git a/packages/core/tests/schema-headers.test.ts b/packages/core/tests/schema-headers.test.ts index f71eb811..c03d3ad6 100644 --- a/packages/core/tests/schema-headers.test.ts +++ b/packages/core/tests/schema-headers.test.ts @@ -1,7 +1,7 @@ import { describe, it, expect } from "vitest" -import { createAccessTokenSchema, createIdentityTokenSchema } from "../src/api/v3/schema" -import { makeEnv } from "./env" -import { getAccessToken, getIdentityToken } from "./helpers/token" +import { createAccessTokenSchema, createIdentityTokenSchema } from "../src/api/v3/schema.js" +import { makeEnv } from "./env.js" +import { getAccessToken, getIdentityToken } from "./helpers/token.js" const env = makeEnv() diff --git a/packages/core/tests/schema-revoke-certificate.test.ts b/packages/core/tests/schema-revoke-certificate.test.ts index ec2fa76b..5eb79301 100644 --- a/packages/core/tests/schema-revoke-certificate.test.ts +++ b/packages/core/tests/schema-revoke-certificate.test.ts @@ -1,9 +1,9 @@ import { describe, it, expect } from "vitest" -import { revokeCertificateEndpointBodySchema } from "../src/api/v3/schema" -import { createApp } from "../src/router" -import { makeEnv } from "./env" -import { key as ecdsaKey } from "./keys/ecdsa" -import { generateProof } from "./helpers/proof" +import { revokeCertificateEndpointBodySchema } from "../src/api/v3/schema.js" +import { createApp } from "../src/router.js" +import { makeEnv } from "./env.js" +import { key as ecdsaKey } from "./keys/ecdsa.js" +import { generateProof } from "./helpers/proof.js" const env = makeEnv() diff --git a/packages/core/tests/schema-user-certificate.test.ts b/packages/core/tests/schema-user-certificate.test.ts index 8db13453..6ff2ea16 100644 --- a/packages/core/tests/schema-user-certificate.test.ts +++ b/packages/core/tests/schema-user-certificate.test.ts @@ -1,9 +1,9 @@ import { describe, it, expect } from "vitest" -import { createHeaderSchema, createIdentityTokenSchema, userCertificateRequestEndpointBodySchema } from "../src/api/v3/schema" -import { makeEnv } from "./env" -import { getAccessToken, getIdentityToken } from "./helpers/token" -import { key as ecdsaKey } from "./keys/ecdsa" -import { generateProof } from "./helpers/proof" +import { createHeaderSchema, createIdentityTokenSchema, userCertificateRequestEndpointBodySchema } from "../src/api/v3/schema.js" +import { makeEnv } from "./env.js" +import { getAccessToken, getIdentityToken } from "./helpers/token.js" +import { key as ecdsaKey } from "./keys/ecdsa.js" +import { generateProof } from "./helpers/proof.js" import { seconds } from "itty-time" const env = makeEnv() diff --git a/packages/core/tests/sshsig.test.ts b/packages/core/tests/sshsig.test.ts index bc3204a4..7cdfe333 100644 --- a/packages/core/tests/sshsig.test.ts +++ b/packages/core/tests/sshsig.test.ts @@ -1,9 +1,9 @@ import { describe, it, expect } from "vitest" import { generatePrivateKey } from "sshpk" -import { verify } from "../src/sshsig" -import { parse, ecdsaComponentSize, toFixedWidth } from "../src/sshsig/sig_parser" -import { Namespace, ProofOfPossession } from "../src/proof" -import { generateProof } from "./helpers/proof" +import { verify } from "../src/sshsig/index.js" +import { parse, ecdsaComponentSize, toFixedWidth } from "../src/sshsig/sig_parser.js" +import { Namespace, ProofOfPossession } from "../src/proof.js" +import { generateProof } from "./helpers/proof.js" type fixture = { name: string diff --git a/packages/core/tests/utils.test.ts b/packages/core/tests/utils.test.ts index bef24e57..43f256a8 100644 --- a/packages/core/tests/utils.test.ts +++ b/packages/core/tests/utils.test.ts @@ -1,16 +1,16 @@ import { describe, it, expect } from "vitest" import { InternalServerErrorException } from "chanfana" import { createCertificate, identityForHost, identityFromDN, KeyParseError } from "sshpk" -import { RenewalProofOfPossession } from "../src/proof" -import { generateProof } from "./helpers/proof" +import { RenewalProofOfPossession } from "../src/proof.js" +import { generateProof } from "./helpers/proof.js" import type { z } from "zod" -import { getPrivateKey, getPublic, identityPrincipals, PrincipalsClaimError, refineHostCertificateRenewal, split, UnsupportedKeyError } from "../src/utils" -import type { CertificateRequestJWTPayload } from "../src/types" -import { env, makeEnv } from "./env" -import { MockSecretStore } from "./helpers/secret" -import { key as rsaKey } from "./keys/rsa" -import { key as ecdsaKey } from "./keys/ecdsa" -import { key as ed25519Key } from "./keys/ed25519" +import { getPrivateKey, getPublic, identityPrincipals, PrincipalsClaimError, refineHostCertificateRenewal, split, UnsupportedKeyError } from "../src/utils.js" +import type { CertificateRequestJWTPayload } from "../src/types.js" +import { env, makeEnv } from "./env.js" +import { MockSecretStore } from "./helpers/secret.js" +import { key as rsaKey } from "./keys/rsa.js" +import { key as ecdsaKey } from "./keys/ecdsa.js" +import { key as ed25519Key } from "./keys/ed25519.js" describe("split", () => { it ("with empty string", () => { diff --git a/packages/core/tsconfig.json b/packages/core/tsconfig.json index 5329f33e..0a37160f 100644 --- a/packages/core/tsconfig.json +++ b/packages/core/tsconfig.json @@ -1,8 +1,8 @@ { "compilerOptions": { "target": "es2024", - "module": "esnext", - "moduleResolution": "bundler", + "module": "nodenext", + "moduleResolution": "nodenext", "strict": true, "outDir": "./dist", "rootDir": "./src",