diff --git a/package.json b/package.json index 030eca609..c8bd2c6d2 100644 --- a/package.json +++ b/package.json @@ -62,8 +62,6 @@ "version:bump": "node scripts/bump-version.mjs" }, "devDependencies": { - "@peac/contracts": "workspace:^", - "@peac/mappings-tap": "workspace:^", "@types/node": "^22.19.11", "@eslint/js": "^10.0.1", "ajv": "^8.18.0", diff --git a/packages/worker-shared/package.json b/packages/worker-shared/package.json new file mode 100644 index 000000000..9301dce44 --- /dev/null +++ b/packages/worker-shared/package.json @@ -0,0 +1,33 @@ +{ + "name": "@peac/worker-shared", + "version": "0.10.13", + "private": true, + "description": "Shared runtime-neutral TAP verification logic for edge worker surfaces", + "type": "module", + "main": "./src/index.ts", + "types": "./src/index.ts", + "exports": { + ".": { + "types": "./src/index.ts", + "import": "./src/index.ts", + "default": "./src/index.ts" + } + }, + "repository": { + "type": "git", + "url": "https://github.com/peacprotocol/peac.git", + "directory": "packages/worker-shared" + }, + "author": "PEAC Protocol Contributors", + "license": "Apache-2.0", + "scripts": { + "build": "tsc --noEmit", + "typecheck": "tsc --noEmit", + "clean": "node -e \"/* no-op: source-exports package has no build artifacts */\"" + }, + "dependencies": { + "@peac/contracts": "workspace:*", + "@peac/mappings-tap": "workspace:*" + }, + "sideEffects": false +} diff --git a/surfaces/workers/_shared/core/config.ts b/packages/worker-shared/src/config.ts similarity index 100% rename from surfaces/workers/_shared/core/config.ts rename to packages/worker-shared/src/config.ts diff --git a/surfaces/workers/_shared/core/errors.ts b/packages/worker-shared/src/errors.ts similarity index 100% rename from surfaces/workers/_shared/core/errors.ts rename to packages/worker-shared/src/errors.ts diff --git a/surfaces/workers/_shared/core/hash.ts b/packages/worker-shared/src/hash.ts similarity index 100% rename from surfaces/workers/_shared/core/hash.ts rename to packages/worker-shared/src/hash.ts diff --git a/surfaces/workers/_shared/core/index.ts b/packages/worker-shared/src/index.ts similarity index 100% rename from surfaces/workers/_shared/core/index.ts rename to packages/worker-shared/src/index.ts diff --git a/surfaces/workers/_shared/core/types.ts b/packages/worker-shared/src/types.ts similarity index 100% rename from surfaces/workers/_shared/core/types.ts rename to packages/worker-shared/src/types.ts diff --git a/surfaces/workers/_shared/core/verification.ts b/packages/worker-shared/src/verification.ts similarity index 100% rename from surfaces/workers/_shared/core/verification.ts rename to packages/worker-shared/src/verification.ts diff --git a/packages/worker-shared/tsconfig.json b/packages/worker-shared/tsconfig.json new file mode 100644 index 000000000..5e3cc116e --- /dev/null +++ b/packages/worker-shared/tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "composite": false, + "noEmit": true + }, + "include": ["src"] +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b2456b9ef..ac1c6fce8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -15,12 +15,6 @@ importers: '@eslint/js': specifier: ^10.0.1 version: 10.0.1(eslint@10.0.1) - '@peac/contracts': - specifier: workspace:^ - version: link:packages/contracts - '@peac/mappings-tap': - specifier: workspace:^ - version: link:packages/mappings/tap '@types/node': specifier: ^22.19.11 version: 22.19.11 @@ -1544,6 +1538,15 @@ importers: specifier: ^4.0.0 version: 4.0.18(@opentelemetry/api@1.9.0)(@types/node@22.19.11)(tsx@4.21.0) + packages/worker-shared: + dependencies: + '@peac/contracts': + specifier: workspace:* + version: link:../contracts + '@peac/mappings-tap': + specifier: workspace:* + version: link:../mappings/tap + surfaces/analytics: dependencies: '@peac/kernel': @@ -1605,6 +1608,9 @@ importers: '@peac/mappings-tap': specifier: workspace:* version: link:../../../packages/mappings/tap + '@peac/worker-shared': + specifier: workspace:* + version: link:../../../packages/worker-shared devDependencies: typescript: specifier: ^5.3.0 @@ -1627,6 +1633,9 @@ importers: '@peac/mappings-tap': specifier: workspace:* version: link:../../../packages/mappings/tap + '@peac/worker-shared': + specifier: workspace:* + version: link:../../../packages/worker-shared devDependencies: '@cloudflare/workers-types': specifier: ^4.20260214.0 @@ -1655,6 +1664,9 @@ importers: '@peac/mappings-tap': specifier: workspace:* version: link:../../../packages/mappings/tap + '@peac/worker-shared': + specifier: workspace:* + version: link:../../../packages/worker-shared devDependencies: '@fastly/js-compute': specifier: ^3.0.0 diff --git a/surfaces/_shared/contracts/error-contract.ts b/surfaces/_shared/contracts/error-contract.ts deleted file mode 100644 index bc0cec15e..000000000 --- a/surfaces/_shared/contracts/error-contract.ts +++ /dev/null @@ -1,30 +0,0 @@ -/** - * PEAC Surface Error Contract (Re-export) - * - * DEPRECATED: Import from @peac/contracts directly in new code. - * This re-export is kept for backwards compatibility only. - * - * @deprecated Import from @peac/contracts instead - * @see https://www.npmjs.com/package/@peac/contracts - */ - -export { - CANONICAL_ERROR_CODES, - CANONICAL_STATUS_MAPPINGS, - CANONICAL_TITLES, - PROBLEM_TYPE_BASE, - MODE_BEHAVIOR, - WWW_AUTHENTICATE_STATUSES, - ERROR_CATALOG, - problemTypeFor, - getStatusForCode, - requiresWwwAuthenticate, - buildWwwAuthenticate, - isPeacErrorCode, - type PeacErrorCode, - type PeacHttpStatus, - type VerificationMode, - type ErrorCatalogEntry, - type HandlerAction, - type ModeBehavior, -} from '@peac/contracts'; diff --git a/surfaces/_shared/contracts/index.ts b/surfaces/_shared/contracts/index.ts deleted file mode 100644 index 7c2869070..000000000 --- a/surfaces/_shared/contracts/index.ts +++ /dev/null @@ -1,22 +0,0 @@ -/** - * PEAC Surface Contracts - * - * Shared contracts that all surface implementations must adhere to. - * Used for parity testing across Cloudflare Worker, Next.js, and future surfaces. - */ - -export { - CANONICAL_ERROR_CODES, - CANONICAL_STATUS_MAPPINGS, - CANONICAL_TITLES, - PROBLEM_TYPE_BASE, - MODE_BEHAVIOR, - WWW_AUTHENTICATE_STATUSES, - ERROR_CATALOG, - problemTypeFor, - getStatusForCode, - requiresWwwAuthenticate, - type PeacErrorCode, - type VerificationMode, - type ErrorCatalogEntry, -} from './error-contract.js'; diff --git a/surfaces/workers/akamai/package.json b/surfaces/workers/akamai/package.json index 16d7b1dff..31352061f 100644 --- a/surfaces/workers/akamai/package.json +++ b/surfaces/workers/akamai/package.json @@ -35,7 +35,8 @@ "@peac/contracts": "workspace:^", "@peac/http-signatures": "workspace:*", "@peac/jwks-cache": "workspace:*", - "@peac/mappings-tap": "workspace:*" + "@peac/mappings-tap": "workspace:*", + "@peac/worker-shared": "workspace:*" }, "devDependencies": { "typescript": "^5.3.0", diff --git a/surfaces/workers/akamai/src/config.ts b/surfaces/workers/akamai/src/config.ts index 0d46e9881..72fc3e070 100644 --- a/surfaces/workers/akamai/src/config.ts +++ b/surfaces/workers/akamai/src/config.ts @@ -8,7 +8,7 @@ */ import type { WorkerConfig, EWRequest } from './types.js'; -import { parseConfigFromEnv } from '../../_shared/core/index.js'; +import { parseConfigFromEnv } from '@peac/worker-shared'; /** * Parse config from Akamai Property Manager variables. @@ -44,4 +44,4 @@ export function parseConfigFromRecord(env: Record): } // Re-export config utilities from shared core -export { matchesBypassPath, isIssuerAllowed } from '../../_shared/core/index.js'; +export { matchesBypassPath, isIssuerAllowed } from '@peac/worker-shared'; diff --git a/surfaces/workers/akamai/src/errors.ts b/surfaces/workers/akamai/src/errors.ts index 4db437214..aaf7e0532 100644 --- a/surfaces/workers/akamai/src/errors.ts +++ b/surfaces/workers/akamai/src/errors.ts @@ -8,7 +8,7 @@ */ import type { ProblemDetails, EWRequestHandler } from './types.js'; -import { ErrorCodes, createProblemDetails } from '../../_shared/core/index.js'; +import { ErrorCodes, createProblemDetails } from '@peac/worker-shared'; // Re-export error codes from shared core export { ErrorCodes }; diff --git a/surfaces/workers/akamai/src/index.ts b/surfaces/workers/akamai/src/index.ts index 26030adab..7886b0bc3 100644 --- a/surfaces/workers/akamai/src/index.ts +++ b/surfaces/workers/akamai/src/index.ts @@ -32,11 +32,7 @@ import { ErrorCodes, createErrorResponse, } from './errors.js'; -import { - handleVerification, - type HandlerResult, - type RequestLike, -} from '../../_shared/core/index.js'; +import { handleVerification, type HandlerResult, type RequestLike } from '@peac/worker-shared'; // Re-export types and utilities export type { diff --git a/surfaces/workers/akamai/src/replay-store.ts b/surfaces/workers/akamai/src/replay-store.ts index c3f133d57..2d6405f6c 100644 --- a/surfaces/workers/akamai/src/replay-store.ts +++ b/surfaces/workers/akamai/src/replay-store.ts @@ -15,7 +15,7 @@ */ import type { ReplayStore, ReplayContext, EdgeKVConfig } from './types.js'; -import { hashReplayKey } from '../../_shared/core/index.js'; +import { hashReplayKey } from '@peac/worker-shared'; // Re-export hash function for testing export { hashReplayKey }; diff --git a/surfaces/workers/akamai/src/types.ts b/surfaces/workers/akamai/src/types.ts index e58a77968..94673cfd8 100644 --- a/surfaces/workers/akamai/src/types.ts +++ b/surfaces/workers/akamai/src/types.ts @@ -14,7 +14,7 @@ export type { ReplayStore, VerificationResult, ProblemDetails, -} from '../../_shared/core/index.js'; +} from '@peac/worker-shared'; /** * Akamai EdgeWorkers environment configuration. diff --git a/surfaces/workers/cloudflare/package.json b/surfaces/workers/cloudflare/package.json index a7ef6abc2..b3bdf5b73 100644 --- a/surfaces/workers/cloudflare/package.json +++ b/surfaces/workers/cloudflare/package.json @@ -36,7 +36,8 @@ "@peac/contracts": "workspace:^", "@peac/http-signatures": "workspace:*", "@peac/jwks-cache": "workspace:*", - "@peac/mappings-tap": "workspace:*" + "@peac/mappings-tap": "workspace:*", + "@peac/worker-shared": "workspace:*" }, "devDependencies": { "@cloudflare/workers-types": "^4.20260214.0", diff --git a/surfaces/workers/cloudflare/src/config.ts b/surfaces/workers/cloudflare/src/config.ts index 21a990e1e..f59d6681d 100644 --- a/surfaces/workers/cloudflare/src/config.ts +++ b/surfaces/workers/cloudflare/src/config.ts @@ -8,12 +8,8 @@ */ import type { Env } from './types.js'; -import type { WorkerConfig } from '../../_shared/core/index.js'; -import { - parseConfigFromEnv, - matchesBypassPath, - isIssuerAllowed, -} from '../../_shared/core/index.js'; +import type { WorkerConfig } from '@peac/worker-shared'; +import { parseConfigFromEnv, matchesBypassPath, isIssuerAllowed } from '@peac/worker-shared'; // Re-export shared utilities export { matchesBypassPath, isIssuerAllowed }; diff --git a/surfaces/workers/cloudflare/src/errors.ts b/surfaces/workers/cloudflare/src/errors.ts index 7562b63cf..cf4627d7c 100644 --- a/surfaces/workers/cloudflare/src/errors.ts +++ b/surfaces/workers/cloudflare/src/errors.ts @@ -8,7 +8,7 @@ */ import type { ProblemDetails } from './types.js'; -import { ErrorCodes, createProblemDetails } from '../../_shared/core/index.js'; +import { ErrorCodes, createProblemDetails } from '@peac/worker-shared'; // Re-export error codes from shared core export { ErrorCodes }; diff --git a/surfaces/workers/cloudflare/src/index.ts b/surfaces/workers/cloudflare/src/index.ts index aa1c3e61a..c7e0fac58 100644 --- a/surfaces/workers/cloudflare/src/index.ts +++ b/surfaces/workers/cloudflare/src/index.ts @@ -21,11 +21,7 @@ import type { Env, WorkerConfig } from './types.js'; import { parseConfig } from './config.js'; import { createReplayStore } from './replay-store.js'; import { createErrorResponse, createChallengeResponse, ErrorCodes } from './errors.js'; -import { - handleVerification, - type HandlerResult, - type RequestLike, -} from '../../_shared/core/index.js'; +import { handleVerification, type HandlerResult, type RequestLike } from '@peac/worker-shared'; // Re-export types and utilities export type { diff --git a/surfaces/workers/cloudflare/src/replay-store.ts b/surfaces/workers/cloudflare/src/replay-store.ts index a1906da28..c31405ac0 100644 --- a/surfaces/workers/cloudflare/src/replay-store.ts +++ b/surfaces/workers/cloudflare/src/replay-store.ts @@ -17,7 +17,7 @@ import type { ReplayStore, ReplayContext } from './types.js'; import type { Env } from './types.js'; -import { hashReplayKey } from '../../_shared/core/index.js'; +import { hashReplayKey } from '@peac/worker-shared'; // Re-export hash function for testing export { hashReplayKey }; diff --git a/surfaces/workers/cloudflare/src/types.ts b/surfaces/workers/cloudflare/src/types.ts index 88fd208d2..01eaa4f46 100644 --- a/surfaces/workers/cloudflare/src/types.ts +++ b/surfaces/workers/cloudflare/src/types.ts @@ -14,7 +14,7 @@ export type { ReplayStore, VerificationResult, ProblemDetails, -} from '../../_shared/core/index.js'; +} from '@peac/worker-shared'; /** * Cloudflare Worker environment bindings. diff --git a/surfaces/workers/fastly/package.json b/surfaces/workers/fastly/package.json index 005aa154b..056e285f0 100644 --- a/surfaces/workers/fastly/package.json +++ b/surfaces/workers/fastly/package.json @@ -35,7 +35,8 @@ "@peac/contracts": "workspace:^", "@peac/http-signatures": "workspace:*", "@peac/jwks-cache": "workspace:*", - "@peac/mappings-tap": "workspace:*" + "@peac/mappings-tap": "workspace:*", + "@peac/worker-shared": "workspace:*" }, "devDependencies": { "@fastly/js-compute": "^3.0.0", diff --git a/surfaces/workers/fastly/src/config.ts b/surfaces/workers/fastly/src/config.ts index 08ca765e7..1256f67c7 100644 --- a/surfaces/workers/fastly/src/config.ts +++ b/surfaces/workers/fastly/src/config.ts @@ -8,7 +8,7 @@ */ import type { WorkerConfig } from './types.js'; -import { parseConfigFromEnv } from '../../_shared/core/index.js'; +import { parseConfigFromEnv } from '@peac/worker-shared'; /** * Parse config from Fastly Edge Dictionary. @@ -80,4 +80,4 @@ function getDictionary(name: string): Map | null { } // Re-export config utilities from shared core -export { matchesBypassPath, isIssuerAllowed } from '../../_shared/core/index.js'; +export { matchesBypassPath, isIssuerAllowed } from '@peac/worker-shared'; diff --git a/surfaces/workers/fastly/src/errors.ts b/surfaces/workers/fastly/src/errors.ts index 9538d6815..c3b637496 100644 --- a/surfaces/workers/fastly/src/errors.ts +++ b/surfaces/workers/fastly/src/errors.ts @@ -8,7 +8,7 @@ */ import type { ProblemDetails } from './types.js'; -import { ErrorCodes, createProblemDetails } from '../../_shared/core/index.js'; +import { ErrorCodes, createProblemDetails } from '@peac/worker-shared'; // Re-export error codes from shared core export { ErrorCodes }; diff --git a/surfaces/workers/fastly/src/index.ts b/surfaces/workers/fastly/src/index.ts index c4365dea8..c2da0fad3 100644 --- a/surfaces/workers/fastly/src/index.ts +++ b/surfaces/workers/fastly/src/index.ts @@ -21,11 +21,7 @@ import type { WorkerConfig, FastlyBackendConfig } from './types.js'; import { parseConfig } from './config.js'; import { createReplayStore } from './replay-store.js'; import { createErrorResponse, createChallengeResponse, ErrorCodes } from './errors.js'; -import { - handleVerification, - type HandlerResult, - type RequestLike, -} from '../../_shared/core/index.js'; +import { handleVerification, type HandlerResult, type RequestLike } from '@peac/worker-shared'; // Re-export types and utilities export type { diff --git a/surfaces/workers/fastly/src/replay-store.ts b/surfaces/workers/fastly/src/replay-store.ts index 4a24ae3d0..8fc88fdc3 100644 --- a/surfaces/workers/fastly/src/replay-store.ts +++ b/surfaces/workers/fastly/src/replay-store.ts @@ -15,7 +15,7 @@ */ import type { ReplayStore, ReplayContext } from './types.js'; -import { hashReplayKey } from '../../_shared/core/index.js'; +import { hashReplayKey } from '@peac/worker-shared'; // Re-export hash function for testing export { hashReplayKey }; diff --git a/surfaces/workers/fastly/src/types.ts b/surfaces/workers/fastly/src/types.ts index 3da83641d..3a77e094c 100644 --- a/surfaces/workers/fastly/src/types.ts +++ b/surfaces/workers/fastly/src/types.ts @@ -14,7 +14,7 @@ export type { ReplayStore, VerificationResult, ProblemDetails, -} from '../../_shared/core/index.js'; +} from '@peac/worker-shared'; /** * Fastly Compute environment configuration. diff --git a/tsconfig.base.json b/tsconfig.base.json index fcc3030ec..1aadf7db2 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -54,7 +54,8 @@ "@peac/mappings-mcp": ["./packages/mappings/mcp/src"], "@peac/mappings-ucp": ["./packages/mappings/ucp/src"], "@peac/mappings-aipref": ["./packages/mappings/aipref/src"], - "@peac/mcp-server": ["./packages/mcp-server/src"] + "@peac/mcp-server": ["./packages/mcp-server/src"], + "@peac/worker-shared": ["./packages/worker-shared/src"] } }, "exclude": ["node_modules", "dist", "build", "lib", "coverage"]