@comms-id/website-logo 0.0.0-stage → 0.3.2

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.
Files changed (47) hide show
  1. package/LICENSE +15 -0
  2. package/README.md +43 -2
  3. package/dist/browser.d.ts +5 -0
  4. package/dist/browser.js +6 -0
  5. package/dist/controller.d.ts +13 -0
  6. package/dist/controller.js +9 -0
  7. package/dist/descriptor.d.ts +11 -0
  8. package/dist/descriptor.js +15 -0
  9. package/dist/fixtures.d.ts +5 -0
  10. package/dist/fixtures.js +10 -0
  11. package/dist/generated/client.d.ts +8 -0
  12. package/dist/generated/client.js +6 -0
  13. package/dist/generated/fixtures.d.ts +2 -0
  14. package/dist/generated/fixtures.js +27 -0
  15. package/dist/generated/operations.d.ts +6 -0
  16. package/dist/generated/operations.js +214 -0
  17. package/dist/generated/types.d.ts +29 -0
  18. package/dist/generated/types.js +2 -0
  19. package/dist/index.d.ts +7 -0
  20. package/dist/index.js +4 -0
  21. package/dist/local/profile.d.ts +12 -0
  22. package/dist/local/profile.js +77 -0
  23. package/dist/runtime/browser-core.d.ts +23 -0
  24. package/dist/runtime/browser-core.js +41 -0
  25. package/dist/runtime/environment.d.ts +5 -0
  26. package/dist/runtime/environment.js +30 -0
  27. package/dist/runtime/errors.d.ts +29 -0
  28. package/dist/runtime/errors.js +40 -0
  29. package/dist/runtime/fixture-core.d.ts +7 -0
  30. package/dist/runtime/fixture-core.js +26 -0
  31. package/dist/runtime/http.d.ts +34 -0
  32. package/dist/runtime/http.js +172 -0
  33. package/dist/runtime/image-controller.d.ts +7 -0
  34. package/dist/runtime/image-controller.js +184 -0
  35. package/dist/runtime/image-types.d.ts +112 -0
  36. package/dist/runtime/image-types.js +8 -0
  37. package/dist/runtime/public-core.d.ts +12 -0
  38. package/dist/runtime/public-core.js +16 -0
  39. package/dist/runtime/server-core.d.ts +26 -0
  40. package/dist/runtime/server-core.js +39 -0
  41. package/dist/runtime/sign.d.ts +24 -0
  42. package/dist/runtime/sign.js +43 -0
  43. package/dist/runtime/validate.d.ts +57 -0
  44. package/dist/runtime/validate.js +175 -0
  45. package/dist/server.d.ts +9 -0
  46. package/dist/server.js +8 -0
  47. package/package.json +63 -3
@@ -0,0 +1,16 @@
1
+ // Runtime template: copied into every generated client package as src/runtime/public-core.ts.
2
+ // The transport of a product whose contract says x-comms-id-auth { "kind": "none" } (ADR-0072):
3
+ // public protocol metadata such as OpenID discovery and a JWKS. It sends no token, so it needs no
4
+ // app id, no key and no relay. A signed product never uses it.
5
+ import { resolveBaseUrl } from "./environment.js";
6
+ const TRAILING_SLASHES = /\/+$/;
7
+ export const createPublicTransport = (options = {}) => {
8
+ const base = resolveBaseUrl(options.environment, options.baseUrl).replace(TRAILING_SLASHES, "");
9
+ return {
10
+ urlFor: (operation) => `${base}${operation.path}`,
11
+ headers: () => Promise.resolve({}),
12
+ ...(options.fetch === undefined ? {} : { fetch: options.fetch }),
13
+ ...(options.deadlineMs === undefined ? {} : { deadlineMs: options.deadlineMs }),
14
+ ...(options.maxRetries === undefined ? {} : { maxRetries: options.maxRetries }),
15
+ };
16
+ };
@@ -0,0 +1,26 @@
1
+ import { type Environment } from "./environment.js";
2
+ import type { TransportConfig } from "./http.js";
3
+ import { type PrivateJwk } from "./sign.js";
4
+ export declare const DEFAULT_BASE_URL: string;
5
+ export interface ServerOptions {
6
+ /** Another host. It wins over `environment`. */
7
+ readonly baseUrl?: string;
8
+ /** The registered app id (COMMS_ID_CLIENT_ID). */
9
+ readonly clientId: string;
10
+ readonly deadlineMs?: number;
11
+ /** "live" (the default) or "test": synthetic replies for apps registered in the development directory. */
12
+ readonly environment?: Environment;
13
+ readonly fetch?: typeof fetch;
14
+ readonly maxRetries?: number;
15
+ readonly now?: () => number;
16
+ /** The app's private ML-DSA-87 key (COMMS_ID_PRIVATE_JWK). */
17
+ readonly privateJwk: PrivateJwk;
18
+ /** Seconds each signed token stays valid: 120 by default, 600 at most. */
19
+ readonly tokenLifetimeSeconds?: number;
20
+ }
21
+ /** What the service verifies: its audience and scope, written into the generated client. */
22
+ export interface ServerTarget {
23
+ readonly audience: string;
24
+ readonly scope: string;
25
+ }
26
+ export declare const createServerTransport: (options: ServerOptions, target: ServerTarget) => TransportConfig;
@@ -0,0 +1,39 @@
1
+ // Runtime template: copied into every generated client package as src/runtime/server-core.ts.
2
+ // Server entry only. The private key never leaves the consumer's server.
3
+ import { BASE_URLS, resolveBaseUrl } from "./environment.js";
4
+ import { CommsIdError } from "./errors.js";
5
+ import { createTokenSigner } from "./sign.js";
6
+ export const DEFAULT_BASE_URL = BASE_URLS.live;
7
+ const TRAILING_SLASHES = /\/+$/;
8
+ /** A transport that signs a fresh short-lived token for every call. */
9
+ const notConfigured = (message) => new CommsIdError({ code: "NOT_CONFIGURED", message, status: 0, retryable: false });
10
+ /** A client with no identified caller is a configuration error: it never sends an unsigned request. */
11
+ const requireCaller = (options) => {
12
+ if (typeof options.clientId !== "string" || options.clientId.trim() === "") {
13
+ throw notConfigured("clientId is empty: set COMMS_ID_CLIENT_ID to your registered app id.");
14
+ }
15
+ const key = options.privateJwk;
16
+ if (key?.kty !== "AKP" || key.alg !== "ML-DSA-87" || typeof key.pub !== "string" || typeof key.priv !== "string") {
17
+ throw notConfigured("privateJwk is missing or not an ML-DSA-87 private key: set COMMS_ID_PRIVATE_JWK.");
18
+ }
19
+ };
20
+ export const createServerTransport = (options, target) => {
21
+ requireCaller(options);
22
+ const sign = createTokenSigner(options.privateJwk);
23
+ const base = resolveBaseUrl(options.environment, options.baseUrl).replace(TRAILING_SLASHES, "");
24
+ return {
25
+ urlFor: (operation) => `${base}${operation.path}`,
26
+ headers: async () => ({
27
+ authorization: `Bearer ${await sign({
28
+ clientId: options.clientId,
29
+ audience: target.audience,
30
+ scope: target.scope,
31
+ ...(options.tokenLifetimeSeconds === undefined ? {} : { lifetimeSeconds: options.tokenLifetimeSeconds }),
32
+ ...(options.now === undefined ? {} : { now: options.now }),
33
+ })}`,
34
+ }),
35
+ ...(options.fetch === undefined ? {} : { fetch: options.fetch }),
36
+ ...(options.deadlineMs === undefined ? {} : { deadlineMs: options.deadlineMs }),
37
+ ...(options.maxRetries === undefined ? {} : { maxRetries: options.maxRetries }),
38
+ };
39
+ };
@@ -0,0 +1,24 @@
1
+ /** An ML-DSA-87 private key as a JWK: the key pair's private half stays on the consumer's server. */
2
+ export interface PrivateJwk {
3
+ readonly alg: "ML-DSA-87";
4
+ readonly kty: "AKP";
5
+ /** The 32-byte seed, base64url. */
6
+ readonly priv: string;
7
+ /** The 2592-byte public key, base64url. */
8
+ readonly pub: string;
9
+ }
10
+ export interface TokenInput {
11
+ /** The service the token is for. */
12
+ readonly audience: string;
13
+ /** The registered app id, sent as the token issuer. */
14
+ readonly clientId: string;
15
+ /** Seconds the token stays valid: 120 by default, 600 at most. */
16
+ readonly lifetimeSeconds?: number;
17
+ readonly now?: () => number;
18
+ readonly scope: string;
19
+ }
20
+ /**
21
+ * Returns a function that signs one short-lived token for each call. The key is imported once.
22
+ * The token is a JWT with alg ML-DSA-87 and the claims iss, aud, sub, jti, iat, exp and scope.
23
+ */
24
+ export declare const createTokenSigner: (privateJwk: PrivateJwk) => ((input: TokenInput) => Promise<string>);
@@ -0,0 +1,43 @@
1
+ // Runtime template: copied into every generated client package as src/runtime/sign.ts.
2
+ // Server entry only: the browser entry never imports this file. Web Crypto, no dependencies.
3
+ // ML-DSA-87 needs Node.js 24.7 or later, or a Cloudflare Worker with the
4
+ // webcrypto_modern_algorithms compatibility flag.
5
+ const DEFAULT_LIFETIME_SECONDS = 120;
6
+ const MAX_LIFETIME_SECONDS = 600;
7
+ const encoder = new TextEncoder();
8
+ const base64url = (bytes) => {
9
+ let binary = "";
10
+ for (const byte of bytes) {
11
+ binary += String.fromCharCode(byte);
12
+ }
13
+ return btoa(binary).replaceAll("+", "-").replaceAll("/", "_").replaceAll("=", "");
14
+ };
15
+ const encodeJson = (value) => base64url(encoder.encode(JSON.stringify(value)));
16
+ /**
17
+ * Returns a function that signs one short-lived token for each call. The key is imported once.
18
+ * The token is a JWT with alg ML-DSA-87 and the claims iss, aud, sub, jti, iat, exp and scope.
19
+ */
20
+ export const createTokenSigner = (privateJwk) => {
21
+ let key;
22
+ const importKey = () => {
23
+ key ??= crypto.subtle.importKey("jwk", privateJwk, { name: "ML-DSA-87" }, false, ["sign"]);
24
+ return key;
25
+ };
26
+ return async (input) => {
27
+ const lifetime = Math.min(Math.max(input.lifetimeSeconds ?? DEFAULT_LIFETIME_SECONDS, 1), MAX_LIFETIME_SECONDS);
28
+ const issuedAt = Math.floor((input.now?.() ?? Date.now()) / 1000);
29
+ const header = encodeJson({ alg: "ML-DSA-87" });
30
+ const payload = encodeJson({
31
+ scope: input.scope,
32
+ iss: input.clientId,
33
+ aud: input.audience,
34
+ sub: crypto.randomUUID(),
35
+ jti: crypto.randomUUID(),
36
+ iat: issuedAt,
37
+ exp: issuedAt + lifetime,
38
+ });
39
+ const signingInput = `${header}.${payload}`;
40
+ const signature = await crypto.subtle.sign({ name: "ML-DSA-87" }, await importKey(), encoder.encode(signingInput));
41
+ return `${signingInput}.${base64url(new Uint8Array(signature))}`;
42
+ };
43
+ };
@@ -0,0 +1,57 @@
1
+ /** The JSON Schema subset that generated clients check, in a compact form the generator writes. */
2
+ export type Schema = {
3
+ readonly t: "str";
4
+ readonly min?: number;
5
+ readonly max?: number;
6
+ readonly values?: readonly string[];
7
+ /** A JSON Schema pattern: checked in a request only. */
8
+ readonly pattern?: string;
9
+ } | {
10
+ readonly t: "int" | "num";
11
+ readonly min?: number;
12
+ readonly max?: number;
13
+ /** exclusiveMinimum and exclusiveMaximum, checked in a request only. */
14
+ readonly exMin?: number;
15
+ readonly exMax?: number;
16
+ readonly values?: readonly number[];
17
+ } | {
18
+ readonly t: "bool";
19
+ } | {
20
+ readonly t: "null";
21
+ } | {
22
+ readonly t: "any";
23
+ } | {
24
+ readonly t: "const";
25
+ readonly value: string | number | boolean | null;
26
+ } | {
27
+ readonly t: "arr";
28
+ readonly of: Schema;
29
+ readonly min?: number;
30
+ readonly max?: number;
31
+ } | {
32
+ readonly t: "tup";
33
+ readonly of: readonly Schema[];
34
+ } | {
35
+ readonly t: "map";
36
+ readonly of: Schema;
37
+ } | {
38
+ readonly t: "obj";
39
+ readonly props: Readonly<Record<string, Schema>>;
40
+ readonly req: readonly string[];
41
+ readonly extra: boolean;
42
+ } | {
43
+ readonly t: "any_of";
44
+ readonly of: readonly Schema[];
45
+ };
46
+ /**
47
+ * A request is checked against every constraint before it leaves the client. A response is
48
+ * checked for shape only: unknown properties, new enum values and size limits are accepted, so
49
+ * a service can add to a reply in a minor version without breaking an installed client.
50
+ */
51
+ export type Mode = "request" | "response";
52
+ export interface Issue {
53
+ readonly message: string;
54
+ readonly path: string;
55
+ }
56
+ /** Returns the problems found, at most eight, or an empty array when the value is acceptable. */
57
+ export declare const validate: (schema: Schema, value: unknown, mode: Mode) => readonly Issue[];
@@ -0,0 +1,175 @@
1
+ // Runtime template: copied into every generated client package as src/runtime/validate.ts.
2
+ // It has no imports, so the copy is identical to this file.
3
+ const MAX_ISSUES = 8;
4
+ const describe = (value) => {
5
+ if (value === null) {
6
+ return "null";
7
+ }
8
+ return Array.isArray(value) ? "array" : typeof value;
9
+ };
10
+ const add = (issues, path, message) => {
11
+ if (issues.length < MAX_ISSUES) {
12
+ issues.push({ path, message });
13
+ }
14
+ };
15
+ const strictSize = (mode, size, min, max) => {
16
+ if (mode !== "request") {
17
+ return undefined;
18
+ }
19
+ if (min !== undefined && size < min) {
20
+ return `must be at least ${min}`;
21
+ }
22
+ if (max !== undefined && size > max) {
23
+ return `must be at most ${max}`;
24
+ }
25
+ return undefined;
26
+ };
27
+ /** A pattern the runtime cannot compile is not checked here: the service checks it. */
28
+ const matches = (pattern, value) => {
29
+ try {
30
+ return new RegExp(pattern).test(value);
31
+ }
32
+ catch {
33
+ return true;
34
+ }
35
+ };
36
+ const checkString = (schema, value, path, mode, issues) => {
37
+ if (typeof value !== "string") {
38
+ add(issues, path, `expected a string, got ${describe(value)}`);
39
+ return;
40
+ }
41
+ const size = strictSize(mode, value.length, schema.min, schema.max);
42
+ if (size !== undefined) {
43
+ add(issues, path, `length ${size}`);
44
+ }
45
+ if (mode === "request" && schema.values !== undefined && !schema.values.includes(value)) {
46
+ add(issues, path, `must be one of ${schema.values.join(", ")}`);
47
+ }
48
+ if (mode === "request" && schema.pattern !== undefined && !matches(schema.pattern, value)) {
49
+ add(issues, path, `must match the pattern ${schema.pattern}`);
50
+ }
51
+ };
52
+ const checkNumber = (schema, value, path, mode, issues) => {
53
+ const ok = typeof value === "number" && Number.isFinite(value) && (schema.t === "num" || Number.isInteger(value));
54
+ if (!ok) {
55
+ add(issues, path, `expected ${schema.t === "int" ? "an integer" : "a number"}, got ${describe(value)}`);
56
+ return;
57
+ }
58
+ const size = strictSize(mode, value, schema.min, schema.max);
59
+ if (size !== undefined) {
60
+ add(issues, path, `value ${size}`);
61
+ }
62
+ if (mode === "request" && schema.exMin !== undefined && value <= schema.exMin) {
63
+ add(issues, path, `value must be greater than ${schema.exMin}`);
64
+ }
65
+ if (mode === "request" && schema.exMax !== undefined && value >= schema.exMax) {
66
+ add(issues, path, `value must be less than ${schema.exMax}`);
67
+ }
68
+ if (mode === "request" && schema.values !== undefined && !schema.values.includes(value)) {
69
+ add(issues, path, `must be one of ${schema.values.join(", ")}`);
70
+ }
71
+ };
72
+ const checkArray = (schema, value, path, mode, issues) => {
73
+ if (!Array.isArray(value)) {
74
+ add(issues, path, `expected an array, got ${describe(value)}`);
75
+ return;
76
+ }
77
+ const size = strictSize(mode, value.length, schema.min, schema.max);
78
+ if (size !== undefined) {
79
+ add(issues, path, `item count ${size}`);
80
+ }
81
+ value.forEach((item, index) => {
82
+ check(schema.of, item, `${path}[${index}]`, mode, issues);
83
+ });
84
+ };
85
+ const checkTuple = (schema, value, path, mode, issues) => {
86
+ if (!Array.isArray(value) || value.length !== schema.of.length) {
87
+ add(issues, path, `expected an array of ${schema.of.length} items`);
88
+ return;
89
+ }
90
+ schema.of.forEach((member, index) => {
91
+ check(member, value[index], `${path}[${index}]`, mode, issues);
92
+ });
93
+ };
94
+ const checkObject = (schema, value, path, mode, issues) => {
95
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
96
+ add(issues, path, `expected an object, got ${describe(value)}`);
97
+ return;
98
+ }
99
+ const record = value;
100
+ for (const key of schema.req) {
101
+ if (!(key in record) || record[key] === undefined) {
102
+ add(issues, `${path}.${key}`, "is required");
103
+ }
104
+ }
105
+ for (const [key, member] of Object.entries(record)) {
106
+ const known = schema.props[key];
107
+ if (known !== undefined) {
108
+ if (member !== undefined) {
109
+ check(known, member, `${path}.${key}`, mode, issues);
110
+ }
111
+ }
112
+ else if (mode === "request" && !schema.extra) {
113
+ add(issues, `${path}.${key}`, "is not a known property");
114
+ }
115
+ }
116
+ };
117
+ const checkMap = (schema, value, path, mode, issues) => {
118
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
119
+ add(issues, path, `expected an object, got ${describe(value)}`);
120
+ return;
121
+ }
122
+ for (const [key, member] of Object.entries(value)) {
123
+ if (member !== undefined) {
124
+ check(schema.of, member, `${path}.${key}`, mode, issues);
125
+ }
126
+ }
127
+ };
128
+ const checkUnion = (schema, value, path, mode, issues) => {
129
+ const matches = schema.of.some((member) => {
130
+ const nested = [];
131
+ check(member, value, path, mode, nested);
132
+ return nested.length === 0;
133
+ });
134
+ if (!matches) {
135
+ add(issues, path, "does not match any allowed shape");
136
+ }
137
+ };
138
+ const checkers = {
139
+ str: checkString,
140
+ int: checkNumber,
141
+ num: checkNumber,
142
+ arr: checkArray,
143
+ tup: checkTuple,
144
+ map: checkMap,
145
+ obj: checkObject,
146
+ any_of: checkUnion,
147
+ };
148
+ const checkSimple = (schema, value, path, issues) => {
149
+ if (schema.t === "bool" && typeof value !== "boolean") {
150
+ add(issues, path, `expected a boolean, got ${describe(value)}`);
151
+ }
152
+ else if (schema.t === "null" && value !== null) {
153
+ add(issues, path, `expected null, got ${describe(value)}`);
154
+ }
155
+ else if (schema.t === "const" && value !== schema.value) {
156
+ add(issues, path, `must be ${JSON.stringify(schema.value)}`);
157
+ }
158
+ };
159
+ const check = (schema, value, path, mode, issues) => {
160
+ if (issues.length >= MAX_ISSUES || schema.t === "any") {
161
+ return;
162
+ }
163
+ const checker = checkers[schema.t];
164
+ if (checker === undefined) {
165
+ checkSimple(schema, value, path, issues);
166
+ return;
167
+ }
168
+ checker(schema, value, path, mode, issues);
169
+ };
170
+ /** Returns the problems found, at most eight, or an empty array when the value is acceptable. */
171
+ export const validate = (schema, value, mode) => {
172
+ const issues = [];
173
+ check(schema, value, "$", mode, issues);
174
+ return issues;
175
+ };
@@ -0,0 +1,9 @@
1
+ import { type WebsiteLogoClient } from "./generated/client.js";
2
+ import { type ServerOptions } from "./runtime/server-core.js";
3
+ export type { Environment } from "./runtime/environment.js";
4
+ export type { PrivateJwk } from "./runtime/sign.js";
5
+ export type { ServerOptions } from "./runtime/server-core.js";
6
+ /** What the service verifies in the token. */
7
+ export declare const AUDIENCE = "website-logo";
8
+ export declare const SCOPE = "website-logo";
9
+ export declare const createWebsiteLogoClient: (options: ServerOptions) => WebsiteLogoClient;
package/dist/server.js ADDED
@@ -0,0 +1,8 @@
1
+ // Generated by @comms-id/forge-transformers from the service's OpenAPI contract. Do not edit: change the contract and regenerate.
2
+ // Server entry: signs a short-lived token for each call with the app's private key.
3
+ import { buildClient } from "./generated/client.js";
4
+ import { createServerTransport } from "./runtime/server-core.js";
5
+ /** What the service verifies in the token. */
6
+ export const AUDIENCE = "website-logo";
7
+ export const SCOPE = "website-logo";
8
+ export const createWebsiteLogoClient = (options) => buildClient(createServerTransport(options, { audience: AUDIENCE, scope: SCOPE }));
package/package.json CHANGED
@@ -1,6 +1,66 @@
1
1
  {
2
2
  "name": "@comms-id/website-logo",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.3.2",
4
+ "description": "Typed client for the Comms.ID Website logo API: a company's logo, resolved from its website address",
5
+ "type": "module",
6
+ "sideEffects": false,
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "default": "./dist/index.js"
13
+ },
14
+ "./server": {
15
+ "types": "./dist/server.d.ts",
16
+ "default": "./dist/server.js"
17
+ },
18
+ "./browser": {
19
+ "types": "./dist/browser.d.ts",
20
+ "default": "./dist/browser.js"
21
+ },
22
+ "./controller": {
23
+ "types": "./dist/controller.d.ts",
24
+ "default": "./dist/controller.js"
25
+ },
26
+ "./fixtures": {
27
+ "types": "./dist/fixtures.d.ts",
28
+ "default": "./dist/fixtures.js"
29
+ },
30
+ "./descriptor": {
31
+ "types": "./dist/descriptor.d.ts",
32
+ "default": "./dist/descriptor.js"
33
+ }
34
+ },
35
+ "homepage": "https://comms.id",
36
+ "bugs": {
37
+ "url": "https://github.com/comms-id/platform/issues"
38
+ },
39
+ "license": "SEE LICENSE IN LICENSE",
40
+ "author": "COMMS.ID PTY LTD",
41
+ "repository": {
42
+ "type": "git",
43
+ "url": "git+https://github.com/comms-id/platform.git",
44
+ "directory": "packages/website-logo"
45
+ },
46
+ "files": [
47
+ "dist",
48
+ "LICENSE",
49
+ "README.md"
50
+ ],
51
+ "devDependencies": {
52
+ "@types/node": "24.19.2",
53
+ "typescript": "7.0.2",
54
+ "vitest": "5.0.4"
55
+ },
56
+ "publishConfig": {
57
+ "access": "public",
58
+ "registry": "https://registry.npmjs.org"
59
+ },
60
+ "scripts": {
61
+ "build": "tsc -p tsconfig.build.json",
62
+ "lint": "biome check .",
63
+ "check-types": "tsc -p tsconfig.json --noEmit",
64
+ "test": "vitest run"
65
+ }
6
66
  }