@monetizationos/proxy 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,10 @@
1
1
  /**
2
- * Supplies platform-specific request metadata forwarded to the surface-decisions API
3
- * under the `cloudflare` field of the request payload (kept for backwards-compat;
4
- * future schema may rename).
2
+ * Supplies platform-specific request metadata. The returned object is spread
3
+ * into the surface-decisions request body at the top level, so each runtime
4
+ * picks its own key — matching the shape the MOS API already accepts from the
5
+ * platform-native workers.
5
6
  *
6
- * - Cloudflare: `{ cf: request.cf }`
7
+ * - Cloudflare: `{ cloudflare: { cf: request.cf } }`
7
8
  * - Fastly: `{ fastly: { client: event.client, sigsci: {...} } }`
8
9
  * - Akamai / unknown: `{}` is fine
9
10
  */
@@ -1 +1 @@
1
- {"version":3,"file":"ClientMetadataProvider.js","sourceRoot":"","sources":["../../src/adapters/ClientMetadataProvider.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Supplies platform-specific request metadata forwarded to the surface-decisions API\n * under the `cloudflare` field of the request payload (kept for backwards-compat;\n * future schema may rename).\n *\n * - Cloudflare: `{ cf: request.cf }`\n * - Fastly: `{ fastly: { client: event.client, sigsci: {...} } }`\n * - Akamai / unknown: `{}` is fine\n */\nexport interface ClientMetadataProvider {\n build(request: Request): Record<string, unknown>\n}\n"]}
1
+ {"version":3,"file":"ClientMetadataProvider.js","sourceRoot":"","sources":["../../src/adapters/ClientMetadataProvider.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Supplies platform-specific request metadata. The returned object is spread\n * into the surface-decisions request body at the top level, so each runtime\n * picks its own key matching the shape the MOS API already accepts from the\n * platform-native workers.\n *\n * - Cloudflare: `{ cloudflare: { cf: request.cf } }`\n * - Fastly: `{ fastly: { client: event.client, sigsci: {...} } }`\n * - Akamai / unknown: `{}` is fine\n */\nexport interface ClientMetadataProvider {\n build(request: Request): Record<string, unknown>\n}\n"]}
@@ -1,4 +1,4 @@
1
1
  export declare const MOS_PROXY_VERSION_HEADER = "X-MOS-Proxy-Version";
2
- export declare const MOS_PROXY_PACKAGE_VERSION = "1.0.0";
2
+ export declare const MOS_PROXY_PACKAGE_VERSION = "1.0.1";
3
3
  export declare const setMosProxyVersionHeader: (headers: Headers) => void;
4
4
  export declare const withMosProxyVersionHeader: (headers?: HeadersInit) => Headers;
@@ -1,5 +1,5 @@
1
1
  export const MOS_PROXY_VERSION_HEADER = 'X-MOS-Proxy-Version';
2
- export const MOS_PROXY_PACKAGE_VERSION = '1.0.0';
2
+ export const MOS_PROXY_PACKAGE_VERSION = '1.0.1';
3
3
  export const setMosProxyVersionHeader = (headers) => {
4
4
  headers.set(MOS_PROXY_VERSION_HEADER, MOS_PROXY_PACKAGE_VERSION);
5
5
  };
@@ -1 +1 @@
1
- {"version":3,"file":"apiRequestHeaders.js","sourceRoot":"","sources":["../src/apiRequestHeaders.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,wBAAwB,GAAG,qBAAqB,CAAA;AAC7D,MAAM,CAAC,MAAM,yBAAyB,GAAG,OAAO,CAAA;AAEhD,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,OAAgB,EAAQ,EAAE;IAC/D,OAAO,CAAC,GAAG,CAAC,wBAAwB,EAAE,yBAAyB,CAAC,CAAA;AACpE,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,OAAqB,EAAW,EAAE;IACxE,MAAM,IAAI,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,CAAA;IACjC,wBAAwB,CAAC,IAAI,CAAC,CAAA;IAC9B,OAAO,IAAI,CAAA;AACf,CAAC,CAAA","sourcesContent":["export const MOS_PROXY_VERSION_HEADER = 'X-MOS-Proxy-Version'\nexport const MOS_PROXY_PACKAGE_VERSION = '1.0.0'\n\nexport const setMosProxyVersionHeader = (headers: Headers): void => {\n headers.set(MOS_PROXY_VERSION_HEADER, MOS_PROXY_PACKAGE_VERSION)\n}\n\nexport const withMosProxyVersionHeader = (headers?: HeadersInit): Headers => {\n const next = new Headers(headers)\n setMosProxyVersionHeader(next)\n return next\n}\n"]}
1
+ {"version":3,"file":"apiRequestHeaders.js","sourceRoot":"","sources":["../src/apiRequestHeaders.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,wBAAwB,GAAG,qBAAqB,CAAA;AAC7D,MAAM,CAAC,MAAM,yBAAyB,GAAG,OAAO,CAAA;AAEhD,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,OAAgB,EAAQ,EAAE;IAC/D,OAAO,CAAC,GAAG,CAAC,wBAAwB,EAAE,yBAAyB,CAAC,CAAA;AACpE,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,OAAqB,EAAW,EAAE;IACxE,MAAM,IAAI,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,CAAA;IACjC,wBAAwB,CAAC,IAAI,CAAC,CAAA;IAC9B,OAAO,IAAI,CAAA;AACf,CAAC,CAAA","sourcesContent":["export const MOS_PROXY_VERSION_HEADER = 'X-MOS-Proxy-Version'\nexport const MOS_PROXY_PACKAGE_VERSION = '1.0.1'\n\nexport const setMosProxyVersionHeader = (headers: Headers): void => {\n headers.set(MOS_PROXY_VERSION_HEADER, MOS_PROXY_PACKAGE_VERSION)\n}\n\nexport const withMosProxyVersionHeader = (headers?: HeadersInit): Headers => {\n const next = new Headers(headers)\n setMosProxyVersionHeader(next)\n return next\n}\n"]}
@@ -2,6 +2,7 @@ import { withMosProxyVersionHeader } from '../apiRequestHeaders';
2
2
  export default async function fetchSurfaceDecisions(ctx, { anonymousIdentifier, userJwt, path, url, clientMetadata, pageMetadata, userAgent, originStatus }, apiFetcher) {
3
3
  const { config } = ctx;
4
4
  const body = JSON.stringify({
5
+ ...clientMetadata,
5
6
  surfaceSlug: config.surfaceSlug,
6
7
  identity: buildIdentity({ anonymousIdentifier, userJwt }),
7
8
  resource: {
@@ -15,8 +16,6 @@ export default async function fetchSurfaceDecisions(ctx, { anonymousIdentifier,
15
16
  status: originStatus,
16
17
  },
17
18
  },
18
- // Legacy field name kept to avoid breaking the API schema; opaque to the proxy core.
19
- cloudflare: clientMetadata,
20
19
  });
21
20
  const request = new Request(new URL('/api/v1/surface-decisions', config.mosHost), {
22
21
  method: 'POST',
@@ -1 +1 @@
1
- {"version":3,"file":"fetchSurfaceDecisions.js","sourceRoot":"","sources":["../../src/stages/fetchSurfaceDecisions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAA;AA8BhE,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,qBAAqB,CAC/C,GAAoB,EACpB,EAAE,mBAAmB,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,cAAc,EAAE,YAAY,EAAE,SAAS,EAAE,YAAY,EAA6B,EAC7H,UAAmB;IAEnB,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,CAAA;IACtB,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC;QACxB,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,QAAQ,EAAE,aAAa,CAAC,EAAE,mBAAmB,EAAE,OAAO,EAAE,CAAC;QACzD,QAAQ,EAAE;YACN,EAAE,EAAE,IAAI;YACR,IAAI,EAAE,YAAY;SACrB;QACD,IAAI,EAAE;YACF,GAAG;YACH,SAAS;YACT,WAAW,EAAE;gBACT,MAAM,EAAE,YAAY;aACvB;SACJ;QACD,qFAAqF;QACrF,UAAU,EAAE,cAAc;KAC7B,CAAC,CAAA;IAEF,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,IAAI,GAAG,CAAC,2BAA2B,EAAE,MAAM,CAAC,OAAO,CAAC,EAAE;QAC9E,MAAM,EAAE,MAAM;QACd,IAAI;QACJ,OAAO,EAAE,yBAAyB,CAAC;YAC/B,cAAc,EAAE,kBAAkB;YAClC,aAAa,EAAE,UAAU,MAAM,CAAC,YAAY,EAAE;SACj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} from '../context'\nimport type { PageMetadata, SurfaceDecisionError, SurfaceDecisionResponse } from '../types'\n\nexport type FetchSurfaceDecisionsArgs = {\n anonymousIdentifier?: string | undefined\n userJwt?: string | undefined\n path: string\n url: string\n clientMetadata: Record<string, unknown>\n pageMetadata?: PageMetadata\n userAgent?: string | undefined\n originStatus: number\n}\n\nexport type FetchSurfaceDecisionsFailureReason = 'request-failed' | 'invalid-json' | 'api-error' | 'http-error' | 'invalid-response'\n\nexport type FetchSurfaceDecisionsResult =\n | {\n ok: true\n data: SurfaceDecisionResponse\n }\n | {\n ok: false\n reason: FetchSurfaceDecisionsFailureReason\n error: unknown\n status?: number\n statusCode?: number\n }\n\nexport default async function fetchSurfaceDecisions(\n ctx: PipelineContext,\n { anonymousIdentifier, userJwt, path, url, clientMetadata, pageMetadata, userAgent, originStatus }: FetchSurfaceDecisionsArgs,\n apiFetcher: Fetcher,\n): Promise<FetchSurfaceDecisionsResult> {\n const { config } = ctx\n const body = JSON.stringify({\n surfaceSlug: config.surfaceSlug,\n identity: buildIdentity({ anonymousIdentifier, userJwt }),\n resource: {\n id: path,\n meta: pageMetadata,\n },\n http: {\n url,\n userAgent,\n proxyOrigin: {\n status: originStatus,\n },\n },\n // Legacy field name kept to avoid breaking the API schema; opaque to the proxy core.\n cloudflare: clientMetadata,\n })\n\n const request = new Request(new URL('/api/v1/surface-decisions', config.mosHost), {\n method: 'POST',\n body,\n headers: withMosProxyVersionHeader({\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${config.mosSecretKey}`,\n }),\n })\n\n let response: Response\n try {\n response = await apiFetcher(request)\n } catch (error) {\n return { ok: false, reason: 'request-failed', error }\n }\n\n let data: unknown\n try {\n data = await response.json()\n } catch (error) {\n return { ok: false, reason: 'invalid-json', error, status: response.status }\n }\n\n if (isSurfaceDecisionError(data)) {\n return {\n ok: false,\n reason: 'api-error',\n error: new Error(data.message),\n status: response.status,\n statusCode: data.statusCode,\n }\n }\n\n if (!response.ok) {\n return {\n ok: false,\n reason: 'http-error',\n error: new Error(`Surface decisions API returned HTTP ${response.status}`),\n status: response.status,\n }\n }\n\n if (!isSurfaceDecisionResponse(data)) {\n return {\n ok: false,\n reason: 'invalid-response',\n error: new Error('Surface decisions API returned an invalid response shape'),\n status: response.status,\n }\n }\n\n return { ok: true, data }\n}\n\nconst isRecord = (value: unknown): value is Record<string, unknown> => typeof value === 'object' && value !== null\n\nconst buildIdentity = ({ anonymousIdentifier, userJwt }: Pick<FetchSurfaceDecisionsArgs, 'anonymousIdentifier' | 'userJwt'>) => {\n if (!anonymousIdentifier && !userJwt) {\n return { createAnonymousIdentifier: true }\n }\n return userJwt ? { userJwt } : { anonymousIdentifier }\n}\n\nconst isSurfaceDecisionError = (value: unknown): value is SurfaceDecisionError =>\n isRecord(value) && value.status === 'error' && typeof value.message === 'string' && typeof value.statusCode === 'number'\n\nconst isSurfaceDecisionResponse = (value: unknown): value is SurfaceDecisionResponse =>\n isRecord(value) &&\n value.status === 'success' &&\n isRecord(value.identity) &&\n isRecord(value.features) &&\n isRecord(value.customer) &&\n isRecord(value.surfaceBehavior) &&\n typeof value.componentsSkipped === 'boolean' &&\n isRecord(value.componentBehaviors)\n"]}
1
+ {"version":3,"file":"fetchSurfaceDecisions.js","sourceRoot":"","sources":["../../src/stages/fetchSurfaceDecisions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAA;AA8BhE,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,qBAAqB,CAC/C,GAAoB,EACpB,EAAE,mBAAmB,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,cAAc,EAAE,YAAY,EAAE,SAAS,EAAE,YAAY,EAA6B,EAC7H,UAAmB;IAEnB,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,CAAA;IACtB,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC;QACxB,GAAG,cAAc;QACjB,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,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QAAQ,CAAA;AAE5H,MAAM,yBAAyB,GAAG,CAAC,KAAc,EAAoC,EAAE,CACnF,QAAQ,CAAC,KAAK,CAAC;IACf,KAAK,CAAC,MAAM,KAAK,SAAS;IAC1B,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC;IACxB,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC;IACxB,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC;IACxB,QAAQ,CAAC,KAAK,CAAC,eAAe,CAAC;IAC/B,OAAO,KAAK,CAAC,iBAAiB,KAAK,SAAS;IAC5C,QAAQ,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAA","sourcesContent":["import type { Fetcher } from '../adapters/Fetcher'\nimport { withMosProxyVersionHeader } from '../apiRequestHeaders'\nimport type { PipelineContext } from '../context'\nimport type { PageMetadata, SurfaceDecisionError, SurfaceDecisionResponse } from '../types'\n\nexport type FetchSurfaceDecisionsArgs = {\n anonymousIdentifier?: string | undefined\n userJwt?: string | undefined\n path: string\n url: string\n clientMetadata: Record<string, unknown>\n pageMetadata?: PageMetadata\n userAgent?: string | undefined\n originStatus: number\n}\n\nexport type FetchSurfaceDecisionsFailureReason = 'request-failed' | 'invalid-json' | 'api-error' | 'http-error' | 'invalid-response'\n\nexport type FetchSurfaceDecisionsResult =\n | {\n ok: true\n data: SurfaceDecisionResponse\n }\n | {\n ok: false\n reason: FetchSurfaceDecisionsFailureReason\n error: unknown\n status?: number\n statusCode?: number\n }\n\nexport default async function fetchSurfaceDecisions(\n ctx: PipelineContext,\n { anonymousIdentifier, userJwt, path, url, clientMetadata, pageMetadata, userAgent, originStatus }: FetchSurfaceDecisionsArgs,\n apiFetcher: Fetcher,\n): Promise<FetchSurfaceDecisionsResult> {\n const { config } = ctx\n const body = JSON.stringify({\n ...clientMetadata,\n surfaceSlug: config.surfaceSlug,\n identity: buildIdentity({ anonymousIdentifier, userJwt }),\n resource: {\n id: path,\n meta: pageMetadata,\n },\n http: {\n url,\n userAgent,\n proxyOrigin: {\n status: originStatus,\n },\n },\n })\n\n const request = new Request(new URL('/api/v1/surface-decisions', config.mosHost), {\n method: 'POST',\n body,\n headers: withMosProxyVersionHeader({\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${config.mosSecretKey}`,\n }),\n })\n\n let response: Response\n try {\n response = await apiFetcher(request)\n } catch (error) {\n return { ok: false, reason: 'request-failed', error }\n }\n\n let data: unknown\n try {\n data = await response.json()\n } catch (error) {\n return { ok: false, reason: 'invalid-json', error, status: response.status }\n }\n\n if (isSurfaceDecisionError(data)) {\n return {\n ok: false,\n reason: 'api-error',\n error: new Error(data.message),\n status: response.status,\n statusCode: data.statusCode,\n }\n }\n\n if (!response.ok) {\n return {\n ok: false,\n reason: 'http-error',\n error: new Error(`Surface decisions API returned HTTP ${response.status}`),\n status: response.status,\n }\n }\n\n if (!isSurfaceDecisionResponse(data)) {\n return {\n ok: false,\n reason: 'invalid-response',\n error: new Error('Surface decisions API returned an invalid response shape'),\n status: response.status,\n }\n }\n\n return { ok: true, data }\n}\n\nconst isRecord = (value: unknown): value is Record<string, unknown> => typeof value === 'object' && value !== null\n\nconst buildIdentity = ({ anonymousIdentifier, userJwt }: Pick<FetchSurfaceDecisionsArgs, 'anonymousIdentifier' | 'userJwt'>) => {\n if (!anonymousIdentifier && !userJwt) {\n return { createAnonymousIdentifier: true }\n }\n return userJwt ? { userJwt } : { anonymousIdentifier }\n}\n\nconst isSurfaceDecisionError = (value: unknown): value is SurfaceDecisionError =>\n isRecord(value) && value.status === 'error' && typeof value.message === 'string' && typeof value.statusCode === 'number'\n\nconst isSurfaceDecisionResponse = (value: unknown): value is SurfaceDecisionResponse =>\n isRecord(value) &&\n value.status === 'success' &&\n isRecord(value.identity) &&\n isRecord(value.features) &&\n isRecord(value.customer) &&\n isRecord(value.surfaceBehavior) &&\n typeof value.componentsSkipped === 'boolean' &&\n isRecord(value.componentBehaviors)\n"]}
package/package.json CHANGED
@@ -1,57 +1,66 @@
1
1
  {
2
- "name": "@monetizationos/proxy",
3
- "version": "1.0.0",
4
- "description": "Platform-agnostic MonetizationOS proxy core",
5
- "license": "MIT",
6
- "type": "module",
7
- "types": "./dist/index.d.ts",
8
- "exports": {
9
- ".": {
10
- "types": "./dist/index.d.ts",
11
- "import": "./dist/index.js"
12
- },
13
- "./package.json": "./package.json"
2
+ "name": "@monetizationos/proxy",
3
+ "version": "1.0.1",
4
+ "description": "Platform-agnostic MonetizationOS proxy core",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
14
12
  },
15
- "files": ["dist", "README.md", "LICENSE"],
16
- "sideEffects": false,
17
- "repository": {
18
- "type": "git",
19
- "url": "git+https://github.com/MonetizationOS/mos-proxy.git"
20
- },
21
- "bugs": {
22
- "url": "https://github.com/MonetizationOS/mos-proxy/issues"
23
- },
24
- "homepage": "https://github.com/MonetizationOS/mos-proxy#readme",
25
- "keywords": ["monetization", "proxy", "cloudflare-workers", "fastly", "akamai", "html-rewriter"],
26
- "engines": {
27
- "node": ">=22"
28
- },
29
- "packageManager": "pnpm@10.32.1",
30
- "publishConfig": {
31
- "access": "public"
32
- },
33
- "scripts": {
34
- "build": "tsc -p tsconfig.build.json",
35
- "test": "vitest",
36
- "test:run": "vitest run",
37
- "typecheck": "tsc --noEmit",
38
- "lint": "biome check --diagnostic-level=error --no-errors-on-unmatched",
39
- "format": "biome check --write --no-errors-on-unmatched",
40
- "changeset": "changeset",
41
- "version": "changeset version && node scripts/sync-version.mjs && pnpm run format",
42
- "release": "changeset publish",
43
- "prepublishOnly": "pnpm run typecheck && pnpm run test:run && pnpm run build"
44
- },
45
- "dependencies": {
46
- "cookie": "^1.1.1"
47
- },
48
- "devDependencies": {
49
- "@biomejs/biome": "2.4.15",
50
- "@changesets/changelog-github": "^0.7.0",
51
- "@changesets/cli": "^2.31.0",
52
- "@types/node": "^24.12.3",
53
- "html-rewriter-wasm": "^0.4.1",
54
- "typescript": "^6.0.3",
55
- "vitest": "~4.1.5"
56
- }
57
- }
13
+ "./package.json": "./package.json"
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "README.md",
18
+ "LICENSE"
19
+ ],
20
+ "sideEffects": false,
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/MonetizationOS/mos-proxy.git"
24
+ },
25
+ "bugs": {
26
+ "url": "https://github.com/MonetizationOS/mos-proxy/issues"
27
+ },
28
+ "homepage": "https://github.com/MonetizationOS/mos-proxy#readme",
29
+ "keywords": [
30
+ "monetization",
31
+ "proxy",
32
+ "cloudflare-workers",
33
+ "fastly",
34
+ "akamai",
35
+ "html-rewriter"
36
+ ],
37
+ "engines": {
38
+ "node": ">=22"
39
+ },
40
+ "publishConfig": {
41
+ "access": "public"
42
+ },
43
+ "dependencies": {
44
+ "cookie": "^1.1.1"
45
+ },
46
+ "devDependencies": {
47
+ "@biomejs/biome": "2.4.15",
48
+ "@changesets/changelog-github": "^0.7.0",
49
+ "@changesets/cli": "^2.31.0",
50
+ "@types/node": "^24.12.3",
51
+ "html-rewriter-wasm": "^0.4.1",
52
+ "typescript": "^6.0.3",
53
+ "vitest": "~4.1.5"
54
+ },
55
+ "scripts": {
56
+ "build": "tsc -p tsconfig.build.json",
57
+ "test": "vitest",
58
+ "test:run": "vitest run",
59
+ "typecheck": "tsc --noEmit",
60
+ "lint": "biome check --diagnostic-level=error --no-errors-on-unmatched",
61
+ "format": "biome check --write --no-errors-on-unmatched",
62
+ "changeset": "changeset",
63
+ "version": "changeset version && node scripts/sync-version.mjs && pnpm run format",
64
+ "release": "changeset publish"
65
+ }
66
+ }