@shipstatic/types 0.9.8 → 0.9.9

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.
package/README.md CHANGED
@@ -68,7 +68,7 @@ try { response = await fetch(url); }
68
68
  catch (cause) { throw ShipError.fromFetchError(cause, 'Get account'); }
69
69
  ```
70
70
 
71
- `fromHttpResponse` trusts the body's `error` field when it's a known server-producible `ErrorType` — so a server's `ShipError.validation(...)` round-trips back to `ErrorType.Validation` on the client. For non-API responses (CDN errors, intermediaries) or malformed bodies it falls back to status-derived (401 → `Authentication`, 429 → `RateLimit`, else → `Api`). Body's `message` and `details` are preserved best-effort.
71
+ `fromHttpResponse` trusts the body's `error` field when it's a known server-producible `ErrorType` — so a server's `ShipError.validation(...)` round-trips back to `ErrorType.Validation` on the client. For non-API responses (CDN errors, intermediaries) or malformed bodies it falls back to status-derived (401 → `Authentication`, 403 → `Forbidden`, 429 → `RateLimit`, else → `Api`). Client-only types (`Network`, `Cancelled`, `File`, `Config`) are filtered out of the trusted set. Body's `message` and `details` are preserved best-effort.
72
72
 
73
73
  `fromFetchError` routes by the thrown cause: an existing `ShipError` is returned unchanged, `AbortError` becomes `Cancelled`, a fetch `TypeError` becomes `Network`, anything else becomes `Api` (with no HTTP status — the request never reached the server).
74
74
 
@@ -159,6 +159,15 @@ import {
159
159
  } from '@shipstatic/types';
160
160
  ```
161
161
 
162
+ ### Password Utilities
163
+
164
+ ```typescript
165
+ import {
166
+ PASSWORD_CONSTRAINTS, // { MIN_LENGTH: 6, MAX_LENGTH: 128 }
167
+ validatePassword, // (value: unknown) => string | undefined
168
+ } from '@shipstatic/types';
169
+ ```
170
+
162
171
  ### Constants
163
172
 
164
173
  ```typescript
package/dist/index.d.ts CHANGED
@@ -1012,3 +1012,17 @@ export declare const PASSWORD_CONSTRAINTS: {
1012
1012
  /** Maximum password length in characters */
1013
1013
  readonly MAX_LENGTH: 128;
1014
1014
  };
1015
+ /**
1016
+ * Validate an optional deployment password and return it normalized.
1017
+ *
1018
+ * Absent (`undefined` / `null`) → returns `undefined`; an unprotected
1019
+ * deployment is a valid choice. Present → must be a string within
1020
+ * `PASSWORD_CONSTRAINTS` length bounds. Whitespace is preserved verbatim —
1021
+ * significant. Throws `ShipError.validation` on breach.
1022
+ *
1023
+ * Single source of truth shared by SDK (client-side validation, return
1024
+ * ignored) and API (server-side enforcement, return threaded into config).
1025
+ * Length is part of the wire-format contract; strength rules, if added later,
1026
+ * stay server-side. See `CLAUDE.md` "Validation: format vs policy".
1027
+ */
1028
+ export declare function validatePassword(value: unknown): string | undefined;
package/dist/index.js CHANGED
@@ -661,3 +661,28 @@ export const PASSWORD_CONSTRAINTS = {
661
661
  /** Maximum password length in characters */
662
662
  MAX_LENGTH: 128,
663
663
  };
664
+ /**
665
+ * Validate an optional deployment password and return it normalized.
666
+ *
667
+ * Absent (`undefined` / `null`) → returns `undefined`; an unprotected
668
+ * deployment is a valid choice. Present → must be a string within
669
+ * `PASSWORD_CONSTRAINTS` length bounds. Whitespace is preserved verbatim —
670
+ * significant. Throws `ShipError.validation` on breach.
671
+ *
672
+ * Single source of truth shared by SDK (client-side validation, return
673
+ * ignored) and API (server-side enforcement, return threaded into config).
674
+ * Length is part of the wire-format contract; strength rules, if added later,
675
+ * stay server-side. See `CLAUDE.md` "Validation: format vs policy".
676
+ */
677
+ export function validatePassword(value) {
678
+ if (value === undefined || value === null)
679
+ return undefined;
680
+ if (typeof value !== 'string') {
681
+ throw ShipError.validation('Password must be a string');
682
+ }
683
+ if (value.length < PASSWORD_CONSTRAINTS.MIN_LENGTH ||
684
+ value.length > PASSWORD_CONSTRAINTS.MAX_LENGTH) {
685
+ throw ShipError.validation(`Password must be between ${PASSWORD_CONSTRAINTS.MIN_LENGTH} and ${PASSWORD_CONSTRAINTS.MAX_LENGTH} characters`);
686
+ }
687
+ return value;
688
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shipstatic/types",
3
- "version": "0.9.8",
3
+ "version": "0.9.9",
4
4
  "description": "Shared types for ShipStatic platform",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
package/src/index.ts CHANGED
@@ -1524,4 +1524,33 @@ export const PASSWORD_CONSTRAINTS = {
1524
1524
  MIN_LENGTH: 6,
1525
1525
  /** Maximum password length in characters */
1526
1526
  MAX_LENGTH: 128,
1527
- } as const;
1527
+ } as const;
1528
+
1529
+ /**
1530
+ * Validate an optional deployment password and return it normalized.
1531
+ *
1532
+ * Absent (`undefined` / `null`) → returns `undefined`; an unprotected
1533
+ * deployment is a valid choice. Present → must be a string within
1534
+ * `PASSWORD_CONSTRAINTS` length bounds. Whitespace is preserved verbatim —
1535
+ * significant. Throws `ShipError.validation` on breach.
1536
+ *
1537
+ * Single source of truth shared by SDK (client-side validation, return
1538
+ * ignored) and API (server-side enforcement, return threaded into config).
1539
+ * Length is part of the wire-format contract; strength rules, if added later,
1540
+ * stay server-side. See `CLAUDE.md` "Validation: format vs policy".
1541
+ */
1542
+ export function validatePassword(value: unknown): string | undefined {
1543
+ if (value === undefined || value === null) return undefined;
1544
+ if (typeof value !== 'string') {
1545
+ throw ShipError.validation('Password must be a string');
1546
+ }
1547
+ if (
1548
+ value.length < PASSWORD_CONSTRAINTS.MIN_LENGTH ||
1549
+ value.length > PASSWORD_CONSTRAINTS.MAX_LENGTH
1550
+ ) {
1551
+ throw ShipError.validation(
1552
+ `Password must be between ${PASSWORD_CONSTRAINTS.MIN_LENGTH} and ${PASSWORD_CONSTRAINTS.MAX_LENGTH} characters`,
1553
+ );
1554
+ }
1555
+ return value;
1556
+ }