@kindgi/types 0.1.5 → 0.1.6-rc.0

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.
@@ -0,0 +1,9 @@
1
+ /** Why fetch can't send `value` in a header, or `undefined` when it can. */
2
+ export declare function headerValueProblem(value: string): string | undefined;
3
+ /**
4
+ * Why fetch can't send `Bearer <token>` in `Authorization`, or `undefined`
5
+ * when it can: the token checked as it's sent, after `Bearer `, where a
6
+ * leading line break is an inner one.
7
+ */
8
+ export declare function bearerValueProblem(token: string): string | undefined;
9
+ //# sourceMappingURL=header-value.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"header-value.d.ts","sourceRoot":"","sources":["../src/header-value.ts"],"names":[],"mappings":"AAoBA,4EAA4E;AAC5E,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CASpE;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAEpE"}
@@ -0,0 +1,40 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Copyright (C) 2026 Kindgi Inc.
3
+ /**
4
+ * Whether fetch can send a value in a header. Fetch trims leading and
5
+ * trailing whitespace (tab, space, CR, LF), then throws on a NUL or a line
6
+ * break with an error that quotes the value: `Headers.append: "<value>" is an
7
+ * invalid header value.` It throws on a character above U+00FF too, and the
8
+ * request refuses any other control character. A secret sent in a header is
9
+ * checked with this first, so a bad one is refused by the header's name and
10
+ * never quoted into an error, a log or a run.
11
+ *
12
+ * Check the value **as it's sent**: `Bearer ` and a secret that starts with a
13
+ * line break make that break an inner one, which fetch refuses
14
+ * (`bearerValueProblem`).
15
+ */
16
+ /** Leading and trailing HTTP whitespace, which fetch trims before it checks. */
17
+ const EDGE_WHITESPACE = /^[\t\n\r ]+|[\t\n\r ]+$/g;
18
+ /** Why fetch can't send `value` in a header, or `undefined` when it can. */
19
+ export function headerValueProblem(value) {
20
+ const sent = value.replace(EDGE_WHITESPACE, '');
21
+ for (let i = 0; i < sent.length; i++) {
22
+ const code = sent.charCodeAt(i);
23
+ if (code === 0x0a || code === 0x0d)
24
+ return 'a line break';
25
+ if (code > 0xff)
26
+ return 'a character above U+00FF';
27
+ if ((code < 0x20 && code !== 0x09) || code === 0x7f)
28
+ return 'a control character';
29
+ }
30
+ return undefined;
31
+ }
32
+ /**
33
+ * Why fetch can't send `Bearer <token>` in `Authorization`, or `undefined`
34
+ * when it can: the token checked as it's sent, after `Bearer `, where a
35
+ * leading line break is an inner one.
36
+ */
37
+ export function bearerValueProblem(token) {
38
+ return headerValueProblem(`Bearer ${token}`);
39
+ }
40
+ //# sourceMappingURL=header-value.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"header-value.js","sourceRoot":"","sources":["../src/header-value.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,iCAAiC;AAEjC;;;;;;;;;;;;GAYG;AAEH,gFAAgF;AAChF,MAAM,eAAe,GAAG,0BAA0B,CAAC;AAEnD,4EAA4E;AAC5E,MAAM,UAAU,kBAAkB,CAAC,KAAa;IAC9C,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC;IAChD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAChC,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,IAAI;YAAE,OAAO,cAAc,CAAC;QAC1D,IAAI,IAAI,GAAG,IAAI;YAAE,OAAO,0BAA0B,CAAC;QACnD,IAAI,CAAC,IAAI,GAAG,IAAI,IAAI,IAAI,KAAK,IAAI,CAAC,IAAI,IAAI,KAAK,IAAI;YAAE,OAAO,qBAAqB,CAAC;IACpF,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAa;IAC9C,OAAO,kBAAkB,CAAC,UAAU,KAAK,EAAE,CAAC,CAAC;AAC/C,CAAC"}
package/dist/index.d.ts CHANGED
@@ -7,4 +7,5 @@ export type * from './result.js';
7
7
  export type * from './temporal.js';
8
8
  export type * from './version.js';
9
9
  export { makeEnvName } from './ids.js';
10
+ export { bearerValueProblem, headerValueProblem } from './header-value.js';
10
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,mBAAmB,aAAa,CAAC;AACjC,mBAAmB,WAAW,CAAC;AAC/B,mBAAmB,UAAU,CAAC;AAC9B,mBAAmB,WAAW,CAAC;AAC/B,mBAAmB,WAAW,CAAC;AAC/B,mBAAmB,aAAa,CAAC;AACjC,mBAAmB,eAAe,CAAC;AACnC,mBAAmB,cAAc,CAAC;AAKlC,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,mBAAmB,aAAa,CAAC;AACjC,mBAAmB,WAAW,CAAC;AAC/B,mBAAmB,UAAU,CAAC;AAC9B,mBAAmB,WAAW,CAAC;AAC/B,mBAAmB,WAAW,CAAC;AAC/B,mBAAmB,aAAa,CAAC;AACjC,mBAAmB,eAAe,CAAC;AACnC,mBAAmB,cAAc,CAAC;AAKlC,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAIvC,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC"}
package/dist/index.js CHANGED
@@ -4,4 +4,7 @@
4
4
  // separate value re-export so the `export type *` barrels above stay
5
5
  // pure-type — value exports live only where explicitly listed.
6
6
  export { makeEnvName } from './ids.js';
7
+ // Whether fetch can send a value in a header: a secret is checked by its
8
+ // header's name before fetch, whose own error would quote it.
9
+ export { bearerValueProblem, headerValueProblem } from './header-value.js';
7
10
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,iCAAiC;AAWjC,uEAAuE;AACvE,qEAAqE;AACrE,+DAA+D;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,iCAAiC;AAWjC,uEAAuE;AACvE,qEAAqE;AACrE,+DAA+D;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC,yEAAyE;AACzE,8DAA8D;AAC9D,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kindgi/types",
3
- "version": "0.1.5",
3
+ "version": "0.1.6-rc.0",
4
4
  "description": "Foundational TypeScript types shared across Kindgi. Branded IDs, timestamps, hashes, refs, Result, list filter / page shapes. Zero runtime dependencies; the only runtime export is the makeEnvName validator.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -0,0 +1,40 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Copyright (C) 2026 Kindgi Inc.
3
+
4
+ /**
5
+ * Whether fetch can send a value in a header. Fetch trims leading and
6
+ * trailing whitespace (tab, space, CR, LF), then throws on a NUL or a line
7
+ * break with an error that quotes the value: `Headers.append: "<value>" is an
8
+ * invalid header value.` It throws on a character above U+00FF too, and the
9
+ * request refuses any other control character. A secret sent in a header is
10
+ * checked with this first, so a bad one is refused by the header's name and
11
+ * never quoted into an error, a log or a run.
12
+ *
13
+ * Check the value **as it's sent**: `Bearer ` and a secret that starts with a
14
+ * line break make that break an inner one, which fetch refuses
15
+ * (`bearerValueProblem`).
16
+ */
17
+
18
+ /** Leading and trailing HTTP whitespace, which fetch trims before it checks. */
19
+ const EDGE_WHITESPACE = /^[\t\n\r ]+|[\t\n\r ]+$/g;
20
+
21
+ /** Why fetch can't send `value` in a header, or `undefined` when it can. */
22
+ export function headerValueProblem(value: string): string | undefined {
23
+ const sent = value.replace(EDGE_WHITESPACE, '');
24
+ for (let i = 0; i < sent.length; i++) {
25
+ const code = sent.charCodeAt(i);
26
+ if (code === 0x0a || code === 0x0d) return 'a line break';
27
+ if (code > 0xff) return 'a character above U+00FF';
28
+ if ((code < 0x20 && code !== 0x09) || code === 0x7f) return 'a control character';
29
+ }
30
+ return undefined;
31
+ }
32
+
33
+ /**
34
+ * Why fetch can't send `Bearer <token>` in `Authorization`, or `undefined`
35
+ * when it can: the token checked as it's sent, after `Bearer `, where a
36
+ * leading line break is an inner one.
37
+ */
38
+ export function bearerValueProblem(token: string): string | undefined {
39
+ return headerValueProblem(`Bearer ${token}`);
40
+ }
package/src/index.ts CHANGED
@@ -14,3 +14,7 @@ export type * from './version.js';
14
14
  // separate value re-export so the `export type *` barrels above stay
15
15
  // pure-type — value exports live only where explicitly listed.
16
16
  export { makeEnvName } from './ids.js';
17
+
18
+ // Whether fetch can send a value in a header: a secret is checked by its
19
+ // header's name before fetch, whose own error would quote it.
20
+ export { bearerValueProblem, headerValueProblem } from './header-value.js';