@platform-sec/sensitive-string-zod 0.0.0-stage → 0.2.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.
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Shared types for the Zod integration.
3
+ *
4
+ * @packageDocumentation
5
+ */
6
+ import type { z } from 'zod';
7
+ import type { RevealContext, SensitiveString, SensitivityClass } from '@platform-sec/sensitive-string-core';
8
+ /**
9
+ * A predicate run against the raw value of an already-wrapped SensitiveString.
10
+ *
11
+ * Returning a promise is supported, but only under `parseAsync`. Zod throws
12
+ * `$ZodAsyncError: Encountered Promise during synchronous parse. Use
13
+ * .parseAsync() instead.` if a promise-returning check is reached from
14
+ * `parse()`, so an async check can never be silently skipped.
15
+ */
16
+ export type SensitiveCheck = (rawValue: string) => boolean | Promise<boolean>;
17
+ /**
18
+ * Options for `refineSensitive`.
19
+ */
20
+ export interface RefineSensitiveParams {
21
+ /**
22
+ * The message attached to the issue when the check fails.
23
+ *
24
+ * It must describe the rule, never the value: this string ends up in a
25
+ * `ZodError` that callers routinely log and return to clients.
26
+ */
27
+ message?: string;
28
+ /** Path appended to the issue, for refinements that report against a nested field. */
29
+ path?: (string | number)[];
30
+ /**
31
+ * Stop parsing after this issue rather than collecting further ones.
32
+ *
33
+ * Zod 4 spells this `continue: false` internally and keeps `fatal` as a
34
+ * documented v3 compatibility path. The name stays here because it is the
35
+ * public API of this package, and a test pins that it still aborts.
36
+ */
37
+ fatal?: boolean;
38
+ /**
39
+ * Reveal context used to read the raw value.
40
+ *
41
+ * Left unset, the check reveals under whatever context is ambient, exactly
42
+ * as a `reveal()` written by hand at the same point would. The refinement
43
+ * deliberately does not manufacture a context of its own: a policy that
44
+ * refuses a context-free reveal must keep refusing here too.
45
+ */
46
+ context?: RevealContext;
47
+ }
48
+ /**
49
+ * A Zod schema that produces a `SensitiveString` of a known class, carrying the
50
+ * refinement helper that reads the raw value under audit.
51
+ *
52
+ * The declared shape is `z.ZodType` rather than the concrete `z.ZodPipe` the
53
+ * factories build, because the intersection with `SensitiveSchemaMethods` needs
54
+ * a name that does not move when a factory changes how it composes. Naming the
55
+ * pipe would put each factory's internal shape in the public type.
56
+ *
57
+ * `refineSensitive` is attached to the schemas this package builds. Standard Zod
58
+ * combinators (`.optional()`, `.array()`, `.default()`) return plain Zod schemas
59
+ * and drop it; apply refinements before those, or call the standalone
60
+ * {@link refineSensitive} function.
61
+ */
62
+ export type SensitiveSchema<C extends SensitivityClass, Input = string> = z.ZodType<SensitiveString<C>, Input> & SensitiveSchemaMethods<C, Input>;
63
+ /**
64
+ * Methods added to every schema this package builds.
65
+ */
66
+ export interface SensitiveSchemaMethods<C extends SensitivityClass, Input> {
67
+ /**
68
+ * Validate the wrapped value against a predicate that receives the raw string.
69
+ *
70
+ * This is a reveal: the ambient `RevealContext` authorizes it and its
71
+ * `auditReveal` hook records it.
72
+ */
73
+ refineSensitive(check: SensitiveCheck, params?: RefineSensitiveParams): SensitiveSchema<C, Input>;
74
+ }
75
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,KAAK,EACV,aAAa,EACb,eAAe,EACf,gBAAgB,EACjB,MAAM,qCAAqC,CAAC;AAE7C;;;;;;;GAOG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AAE9E;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,sFAAsF;IACtF,IAAI,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;IAC3B;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB;;;;;;;OAOG;IACH,OAAO,CAAC,EAAE,aAAa,CAAC;CACzB;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,gBAAgB,EAAE,KAAK,GAAG,MAAM,IAAI,CAAC,CAAC,OAAO,CACjF,eAAe,CAAC,CAAC,CAAC,EAClB,KAAK,CACN,GACC,sBAAsB,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;AAEnC;;GAEG;AACH,MAAM,WAAW,sBAAsB,CAAC,CAAC,SAAS,gBAAgB,EAAE,KAAK;IACvE;;;;;OAKG;IACH,eAAe,CAAC,KAAK,EAAE,cAAc,EAAE,MAAM,CAAC,EAAE,qBAAqB,GAAG,eAAe,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;CACnG"}
package/dist/types.js ADDED
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ /**
3
+ * Shared types for the Zod integration.
4
+ *
5
+ * @packageDocumentation
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA;;;;GAIG"}
package/package.json CHANGED
@@ -1,6 +1,49 @@
1
1
  {
2
2
  "name": "@platform-sec/sensitive-string-zod",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.2.1",
4
+ "description": "Zod integration for SensitiveString - parse input directly into sensitive types",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "default": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "keywords": [
18
+ "zod",
19
+ "validation",
20
+ "security",
21
+ "sensitive-data",
22
+ "typescript"
23
+ ],
24
+ "license": "MIT",
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/platform-sec/sensitive-string-js.git",
28
+ "directory": "packages/sensitive-zod"
29
+ },
30
+ "engines": {
31
+ "node": ">=22.12.0"
32
+ },
33
+ "peerDependencies": {
34
+ "@platform-sec/sensitive-string-core": "^0.6.0",
35
+ "zod": "^4.0.0"
36
+ },
37
+ "devDependencies": {
38
+ "@types/node": "^22.20.5",
39
+ "typescript": "^5.9.3",
40
+ "vitest": "^4.1.12",
41
+ "zod": "^4.6.7",
42
+ "@platform-sec/sensitive-string-core": "0.6.1"
43
+ },
44
+ "scripts": {
45
+ "build": "tsc",
46
+ "test": "vitest run --root ../.. packages/sensitive-zod/",
47
+ "test:watch": "vitest --root ../.. packages/sensitive-zod/"
48
+ }
6
49
  }