New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@cloudflare/workers-shared

Package Overview
Dependencies
Maintainers
0
Versions
947
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cloudflare/workers-shared - npm Package Compare versions

Comparing version

to
0.0.0-a3527988e

3

dist/utils/constants.d.ts

@@ -23,1 +23,4 @@ /** Reserved header at the start of the whole manifest, NOT in each entry (currently unused)

export declare const MAX_ASSET_SIZE: number;
export declare const CF_ASSETS_IGNORE_FILENAME = ".assetsignore";
export declare const REDIRECTS_FILENAME = "_redirects";
export declare const HEADERS_FILENAME = "_headers";

@@ -0,3 +1,22 @@

import type { PathOrFileDescriptor } from "node:fs";
/** normalises sep for windows and prefix with `/` */
export declare const normalizeFilePath: (relativeFilepath: string) => string;
export declare const getContentType: (absFilePath: string) => string;
/**
* Generate a function that can match relative filepaths against a list of gitignore formatted patterns.
*/
export declare function createPatternMatcher(patterns: string[], exclude: boolean): (filePath: string) => boolean;
export declare function thrownIsDoesNotExistError(thrown: unknown): thrown is Error & {
code: "ENOENT";
};
export declare function maybeGetFile(filePath: PathOrFileDescriptor): string;
/**
* Create a function for filtering out ignored assets.
*
* The generated function takes an asset path, relative to the asset directory,
* and returns true if the asset should not be ignored.
*/
export declare function createAssetsIgnoreFunction(dir: string): Promise<{
assetsIgnoreFunction: (filePath: string) => boolean;
assetsIgnoreFilePresent: boolean;
}>;
import { z } from "zod";
export declare const RoutingConfigSchema: z.ZodObject<{
export declare const RouterConfigSchema: z.ZodObject<{
account_id: z.ZodOptional<z.ZodNumber>;
script_id: z.ZodOptional<z.ZodNumber>;
invoke_user_worker_ahead_of_assets: z.ZodOptional<z.ZodBoolean>;
has_user_worker: z.ZodOptional<z.ZodBoolean>;
}, "strip", z.ZodTypeAny, {
account_id?: number;
script_id?: number;
invoke_user_worker_ahead_of_assets?: boolean;
has_user_worker?: boolean;
}, {
account_id?: number;
script_id?: number;
invoke_user_worker_ahead_of_assets?: boolean;
has_user_worker?: boolean;
}>;
declare const MetadataStaticRedirects: z.ZodRecord<z.ZodString, z.ZodObject<{
status: z.ZodNumber;
to: z.ZodString;
lineNumber: z.ZodNumber;
}, "strip", z.ZodTypeAny, {
status?: number;
to?: string;
lineNumber?: number;
}, {
status?: number;
to?: string;
lineNumber?: number;
}>>;
export type MetadataStaticRedirects = z.infer<typeof MetadataStaticRedirects>;
declare const MetadataRedirects: z.ZodRecord<z.ZodString, z.ZodObject<{
status: z.ZodNumber;
to: z.ZodString;
}, "strip", z.ZodTypeAny, {
status?: number;
to?: string;
}, {
status?: number;
to?: string;
}>>;
export type MetadataRedirects = z.infer<typeof MetadataRedirects>;
declare const MetadataHeaders: z.ZodRecord<z.ZodString, z.ZodObject<{
set: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
unset: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
}, "strip", z.ZodTypeAny, {
set?: Record<string, string>;
unset?: string[];
}, {
set?: Record<string, string>;
unset?: string[];
}>>;
export type MetadataHeaders = z.infer<typeof MetadataHeaders>;
export declare const RedirectsSchema: z.ZodOptional<z.ZodObject<{
version: z.ZodLiteral<1>;
staticRules: z.ZodRecord<z.ZodString, z.ZodObject<{
status: z.ZodNumber;
to: z.ZodString;
lineNumber: z.ZodNumber;
}, "strip", z.ZodTypeAny, {
status?: number;
to?: string;
lineNumber?: number;
}, {
status?: number;
to?: string;
lineNumber?: number;
}>>;
rules: z.ZodRecord<z.ZodString, z.ZodObject<{
status: z.ZodNumber;
to: z.ZodString;
}, "strip", z.ZodTypeAny, {
status?: number;
to?: string;
}, {
status?: number;
to?: string;
}>>;
}, "strip", z.ZodTypeAny, {
version?: 1;
staticRules?: Record<string, {
status?: number;
to?: string;
lineNumber?: number;
}>;
rules?: Record<string, {
status?: number;
to?: string;
}>;
}, {
version?: 1;
staticRules?: Record<string, {
status?: number;
to?: string;
lineNumber?: number;
}>;
rules?: Record<string, {
status?: number;
to?: string;
}>;
}>>;
export declare const HeadersSchema: z.ZodOptional<z.ZodObject<{
version: z.ZodLiteral<2>;
rules: z.ZodRecord<z.ZodString, z.ZodObject<{
set: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
unset: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
}, "strip", z.ZodTypeAny, {
set?: Record<string, string>;
unset?: string[];
}, {
set?: Record<string, string>;
unset?: string[];
}>>;
}, "strip", z.ZodTypeAny, {
version?: 2;
rules?: Record<string, {
set?: Record<string, string>;
unset?: string[];
}>;
}, {
version?: 2;
rules?: Record<string, {
set?: Record<string, string>;
unset?: string[];
}>;
}>>;
export declare const AssetConfigSchema: z.ZodObject<{
account_id: z.ZodOptional<z.ZodNumber>;
script_id: z.ZodOptional<z.ZodNumber>;
compatibility_date: z.ZodOptional<z.ZodString>;
compatibility_flags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
html_handling: z.ZodOptional<z.ZodEnum<["auto-trailing-slash", "force-trailing-slash", "drop-trailing-slash", "none"]>>;
not_found_handling: z.ZodOptional<z.ZodEnum<["single-page-application", "404-page", "none"]>>;
redirects: z.ZodOptional<z.ZodObject<{
version: z.ZodLiteral<1>;
staticRules: z.ZodRecord<z.ZodString, z.ZodObject<{
status: z.ZodNumber;
to: z.ZodString;
lineNumber: z.ZodNumber;
}, "strip", z.ZodTypeAny, {
status?: number;
to?: string;
lineNumber?: number;
}, {
status?: number;
to?: string;
lineNumber?: number;
}>>;
rules: z.ZodRecord<z.ZodString, z.ZodObject<{
status: z.ZodNumber;
to: z.ZodString;
}, "strip", z.ZodTypeAny, {
status?: number;
to?: string;
}, {
status?: number;
to?: string;
}>>;
}, "strip", z.ZodTypeAny, {
version?: 1;
staticRules?: Record<string, {
status?: number;
to?: string;
lineNumber?: number;
}>;
rules?: Record<string, {
status?: number;
to?: string;
}>;
}, {
version?: 1;
staticRules?: Record<string, {
status?: number;
to?: string;
lineNumber?: number;
}>;
rules?: Record<string, {
status?: number;
to?: string;
}>;
}>>;
headers: z.ZodOptional<z.ZodObject<{
version: z.ZodLiteral<2>;
rules: z.ZodRecord<z.ZodString, z.ZodObject<{
set: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
unset: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
}, "strip", z.ZodTypeAny, {
set?: Record<string, string>;
unset?: string[];
}, {
set?: Record<string, string>;
unset?: string[];
}>>;
}, "strip", z.ZodTypeAny, {
version?: 2;
rules?: Record<string, {
set?: Record<string, string>;
unset?: string[];
}>;
}, {
version?: 2;
rules?: Record<string, {
set?: Record<string, string>;
unset?: string[];
}>;
}>>;
}, "strip", z.ZodTypeAny, {
account_id?: number;
script_id?: number;
compatibility_date?: string;
compatibility_flags?: string[];
html_handling?: "none" | "auto-trailing-slash" | "force-trailing-slash" | "drop-trailing-slash";
not_found_handling?: "none" | "single-page-application" | "404-page";
redirects?: {
version?: 1;
staticRules?: Record<string, {
status?: number;
to?: string;
lineNumber?: number;
}>;
rules?: Record<string, {
status?: number;
to?: string;
}>;
};
headers?: {
version?: 2;
rules?: Record<string, {
set?: Record<string, string>;
unset?: string[];
}>;
};
}, {
account_id?: number;
script_id?: number;
compatibility_date?: string;
compatibility_flags?: string[];
html_handling?: "none" | "auto-trailing-slash" | "force-trailing-slash" | "drop-trailing-slash";
not_found_handling?: "none" | "single-page-application" | "404-page";
redirects?: {
version?: 1;
staticRules?: Record<string, {
status?: number;
to?: string;
lineNumber?: number;
}>;
rules?: Record<string, {
status?: number;
to?: string;
}>;
};
headers?: {
version?: 2;
rules?: Record<string, {
set?: Record<string, string>;
unset?: string[];
}>;
};
}>;
export type RoutingConfig = z.infer<typeof RoutingConfigSchema>;
export type RouterConfig = z.infer<typeof RouterConfigSchema>;
export type AssetConfig = z.infer<typeof AssetConfigSchema>;

@@ -25,1 +266,31 @@ export interface UnsafePerformanceTimer {

}
export interface JaegerTracing {
enterSpan<T extends unknown[], R = void>(name: string, span: (s: Span, ...args: T) => R, ...args: T): R;
getSpanContext(): SpanContext | null;
runWithSpanContext<T extends unknown[]>(spanContext: SpanContext | null, callback: (...args: T) => unknown, ...args: T): unknown;
readonly traceId: string | null;
readonly spanId: string | null;
readonly parentSpanId: string | null;
readonly cfTraceIdHeader: string | null;
}
export interface Span {
addLogs(logs: JaegerRecord): void;
setTags(tags: JaegerRecord): void;
end(): void;
isRecording: boolean;
}
export interface SpanContext {
traceId: string;
spanId: string;
parentSpanId: string;
traceFlags: number;
}
export type JaegerValue = string | number | boolean;
export type JaegerRecord = Record<string, JaegerValue>;
export interface ColoMetadata {
metalId: number;
coloId: number;
coloRegion: string;
coloTier: number;
}
export {};

41

package.json
{
"name": "@cloudflare/workers-shared",
"version": "0.0.0-a33a133f8",
"version": "0.0.0-a3527988e",
"description": "Package that is used at Cloudflare to power some internal features of Cloudflare Workers.",

@@ -30,10 +30,13 @@ "keywords": [

"devDependencies": {
"@cloudflare/workers-types": "^4.20241022.0",
"@cloudflare/vitest-pool-workers": "^0.5.41",
"@cloudflare/workers-types": "^4.20250224.0",
"@sentry/cli": "^2.37.0",
"@types/mime": "^3.0.4",
"concurrently": "^8.2.2",
"esbuild": "0.17.19",
"rimraf": "^6.0.1",
"toucan-js": "^3.3.1",
"typescript": "^5.5.4",
"vitest": "~2.1.1",
"ignore": "^5.2.0",
"rimraf": "^5.0.10",
"toucan-js": "4.0.0",
"typescript": "^5.7.2",
"vitest": "~2.1.0",
"@cloudflare/eslint-config-worker": "1.1.0",

@@ -60,12 +63,24 @@ "@cloudflare/workers-tsconfig": "0.0.0"

"check:type": "pnpm run check:type:tests && tsc",
"check:type:tests": "tsc -p ./asset-worker/tests/tsconfig.json",
"check:type:tests": "tsc -p ./asset-worker/tests/tsconfig.json && tsc -p ./router-worker/tests/tsconfig.json",
"clean": "rimraf dist",
"deploy": "pnpm run deploy:router-worker && pnpm run deploy:asset-worker",
"deploy:asset-worker": "CLOUDFLARE_API_TOKEN=$WORKERS_DEPLOY_AND_CONFIG_CLOUDFLARE_API_TOKEN pnpx wrangler versions upload --experimental-versions -c asset-worker/wrangler.toml",
"deploy:router-worker": "CLOUDFLARE_API_TOKEN=$WORKERS_DEPLOY_AND_CONFIG_CLOUDFLARE_API_TOKEN pnpx wrangler versions upload --experimental-versions -c router-worker/wrangler.toml",
"deploy": "pnpm run generate-sourcemaps && pnpm run deploy:router-worker && pnpm run deploy:asset-worker && pnpm run upload-sourcemaps",
"deploy:asset-worker": "CLOUDFLARE_API_TOKEN=$WORKERS_DEPLOY_AND_CONFIG_CLOUDFLARE_API_TOKEN pnpx wrangler versions upload -c asset-worker/wrangler.toml --tag aw-$(node -r esbuild-register ./scripts/get-version-tag.ts)",
"deploy:asset-worker-staging": "CLOUDFLARE_API_TOKEN=$WORKERS_DEPLOY_AND_CONFIG_CLOUDFLARE_API_TOKEN pnpx wrangler deploy -c asset-worker/wrangler.toml -e staging",
"deploy:router-worker": "CLOUDFLARE_API_TOKEN=$WORKERS_DEPLOY_AND_CONFIG_CLOUDFLARE_API_TOKEN pnpx wrangler versions upload -c router-worker/wrangler.toml --tag rw-$(node -r esbuild-register ./scripts/get-version-tag.ts)",
"deploy:router-worker-staging": "CLOUDFLARE_API_TOKEN=$WORKERS_DEPLOY_AND_CONFIG_CLOUDFLARE_API_TOKEN pnpx wrangler deploy -c router-worker/wrangler.toml -e staging",
"deploy:staging": "pnpm run deploy:router-worker-staging && pnpm run deploy:asset-worker-staging",
"dev": "pnpm run clean && concurrently -n bundle:asset-worker,bundle:router-worker -c blue,magenta \"pnpm run bundle:asset-worker --watch\" \"pnpm run bundle:router-worker --watch\"",
"test": "vitest",
"test:ci": "vitest run",
"types:emit": "tsc index.ts --declaration --emitDeclarationOnly --declarationDir ./dist"
"generate-sourcemaps": "pnpm run generate-sourcemaps:asset-worker && pnpm generate-sourcemaps:router-worker",
"generate-sourcemaps:asset-worker": "pnpx wrangler versions upload -c asset-worker/wrangler.toml --dry-run --outdir=./dist",
"generate-sourcemaps:router-worker": "pnpx wrangler versions upload -c router-worker/wrangler.toml --dry-run --outdir=./dist",
"test": "concurrently --group -n router-worker,asset-worker,utils \"pnpm run test:router-worker\" \"pnpm run test:asset-worker\" \"pnpm run test:utils\"",
"test:asset-worker": "vitest -c asset-worker/vitest.config.mts --dir asset-worker",
"test:ci": "concurrently --group -n router-worker,asset-worker,utils \"pnpm run test:router-worker --run\" \"pnpm run test:asset-worker --run\" \"pnpm run test:utils --run\"",
"test:router-worker": "vitest -c router-worker/vitest.config.mts --dir router-worker",
"test:utils": "vitest --dir utils",
"types:emit": "tsc index.ts --declaration --emitDeclarationOnly --declarationDir ./dist",
"upload-sourcemaps": "pnpm run upload-sourcemaps:asset-worker && pnpm run upload-sourcemaps:router-worker",
"upload-sourcemaps:asset-worker": "node -r esbuild-register ./scripts/upload-sourcemaps.ts --worker asset-worker --tag aw-$(node -r esbuild-register ./scripts/get-version-tag.ts)",
"upload-sourcemaps:router-worker": "node -r esbuild-register ./scripts/upload-sourcemaps.ts --worker router-worker --tag rw-$(node -r esbuild-register ./scripts/get-version-tag.ts)"
}
}

@@ -5,2 +5,6 @@ # `@cloudflare/workers-shared`

> [!NOTE]
> Since code in this package is used by the Workers infrastructure, it is important that PRs are given careful review with regards to how they could cause a failure in production.
> Ideally, there should be comprehensive tests for changes being made to give extra confidence about the behavior.
## `asset-worker`

@@ -18,4 +22,13 @@

> [!NOTE]
> Since code in this package is used by the Workers infrastructure, it is important that PRs are given careful review with regards to how they could cause a failure in production.
> Ideally, there should be comprehensive tests for changes being made to give extra confidence about the behavior.
## `Worker Deployment`
Router-worker and asset-worker are both version uploaded through the run `deploy` target in this package, which uploads a new version of these Workers.
There are two ways that the `deploy` script target can be invoked:
- The `changesets` workflow will execute whenever there is a release of `@cloudflare/workers-shared`
- If a change is needed prior to a workers-shared release, it can be done manually, via the `workers-shared-deploy-production` workflow. This workflow will upload new vesions of asset-worker and router-worker based on the code in the `main` branch. (Note, a duplicate version may be uploaded on the next workers-shared release, if there is an associated changeset)
The pnpm `deploy` script should not be run manually.
Once new versions are uploaded (through either the manual workflow, or the changesets workflow), they can be safely deployed and monitored using Gradual Deployments through Health Mediated Deployments.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet