@dfinity/zod-schemas 2.0.0 → 2.1.0-beta-2025-09-25

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/LICENSE CHANGED
@@ -174,28 +174,3 @@
174
174
  of your accepting any such warranty or additional liability.
175
175
 
176
176
  END OF TERMS AND CONDITIONS
177
-
178
- APPENDIX: How to apply the Apache License to your work.
179
-
180
- To apply the Apache License to your work, attach the following
181
- boilerplate notice, with the fields enclosed by brackets "[]"
182
- replaced with your own identifying information. (Don't include
183
- the brackets!) The text should be enclosed in the appropriate
184
- comment syntax for the file format. We also recommend that a
185
- file or class name and description of purpose be included on the
186
- same "printed page" as the copyright notice for easier
187
- identification within third-party archives.
188
-
189
- Copyright 2025 DFINITY Stiftung.
190
-
191
- Licensed under the Apache License, Version 2.0 (the "License");
192
- you may not use this file except in compliance with the License.
193
- You may obtain a copy of the License at
194
-
195
- http://www.apache.org/licenses/LICENSE-2.0
196
-
197
- Unless required by applicable law or agreed to in writing, software
198
- distributed under the License is distributed on an "AS IS" BASIS,
199
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
- See the License for the specific language governing permissions and
201
- limitations under the License.
package/README.md CHANGED
@@ -20,7 +20,7 @@ npm i @dfinity/zod-schemas
20
20
  The bundle needs peer dependencies, be sure that following resources are available in your project as well.
21
21
 
22
22
  ```bash
23
- npm i @dfinity/principal
23
+ npm i @icp-sdk/core/principal
24
24
  ```
25
25
 
26
26
  ## Features
@@ -1,2 +1,2 @@
1
- "use strict";var u=Object.create;var l=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var d=Object.getPrototypeOf,P=Object.prototype.hasOwnProperty;var U=(r,t)=>{for(var o in t)l(r,o,{get:t[o],enumerable:!0})},a=(r,t,o,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of h(t))!P.call(r,e)&&e!==o&&l(r,e,{get:()=>t[e],enumerable:!(n=x(t,e))||n.enumerable});return r};var c=(r,t,o)=>(o=r!=null?u(d(r)):{},a(t||!r||!r.__esModule?l(o,"default",{value:r,enumerable:!0}):o,r)),y=r=>a(l({},"__esModule",{value:!0}),r);var L={};U(L,{PrincipalTextSchema:()=>z,UrlSchema:()=>w,createUrlSchema:()=>f});module.exports=y(L);var i=require("@dfinity/principal"),p=c(require("zod")),z=p.string().refine(r=>{try{return i.Principal.fromText(r),!0}catch{return!1}},{error:"Invalid textual representation of a Principal."});var s=c(require("zod")),f=({additionalProtocols:r=[],allowHttpLocally:t=!0})=>s.url().refine(o=>{try{let n=[...new Set(["https:",...r])],{protocol:e,hostname:m}=new URL(o);return t&&["localhost","127.0.0.1"].includes(m)?["http:",...n].includes(e):n.includes(e)}catch{return!1}},{error:"Invalid URL."}),w=f({});0&&(module.exports={PrincipalTextSchema,UrlSchema,createUrlSchema});
1
+ "use strict";var u=Object.create;var l=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var d=Object.getPrototypeOf,P=Object.prototype.hasOwnProperty;var U=(r,t)=>{for(var o in t)l(r,o,{get:t[o],enumerable:!0})},a=(r,t,o,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of h(t))!P.call(r,e)&&e!==o&&l(r,e,{get:()=>t[e],enumerable:!(n=x(t,e))||n.enumerable});return r};var c=(r,t,o)=>(o=r!=null?u(d(r)):{},a(t||!r||!r.__esModule?l(o,"default",{value:r,enumerable:!0}):o,r)),y=r=>a(l({},"__esModule",{value:!0}),r);var L={};U(L,{PrincipalTextSchema:()=>z,UrlSchema:()=>w,createUrlSchema:()=>f});module.exports=y(L);var i=require("@icp-sdk/core/principal"),p=c(require("zod")),z=p.string().refine(r=>{try{return i.Principal.fromText(r),!0}catch{return!1}},{error:"Invalid textual representation of a Principal."});var s=c(require("zod")),f=({additionalProtocols:r=[],allowHttpLocally:t=!0})=>s.url().refine(o=>{try{let n=[...new Set(["https:",...r])],{protocol:e,hostname:m}=new URL(o);return t&&["localhost","127.0.0.1"].includes(m)?["http:",...n].includes(e):n.includes(e)}catch{return!1}},{error:"Invalid URL."}),w=f({});0&&(module.exports={PrincipalTextSchema,UrlSchema,createUrlSchema});
2
2
  //# sourceMappingURL=index.cjs.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.ts", "../../src/principal.ts", "../../src/url.ts"],
4
- "sourcesContent": ["export * from \"./principal\";\nexport * from \"./url\";\n", "import { Principal } from \"@dfinity/principal\";\nimport * as z from \"zod\";\n\n/**\n * Zod schema to validate a string as a valid textual representation of a Principal.\n *\n * This schema checks if the provided string can be converted into a `Principal` instance.\n * If the conversion fails, validation will return an error message.\n *\n * @example\n * ```typescript\n * const result = PrincipalTextSchema.safeParse('aaaaa-aa');\n * console.log(result.success); // true or false\n * ```\n */\nexport const PrincipalTextSchema = z.string().refine(\n (principal) => {\n try {\n Principal.fromText(principal);\n return true;\n } catch (_err: unknown) {\n return false;\n }\n },\n {\n error: \"Invalid textual representation of a Principal.\",\n },\n);\n\nexport type PrincipalText = z.infer<typeof PrincipalTextSchema>;\n", "import * as z from \"zod\";\n\n/**\n * A URL protocol as template literal type.\n * Example: \"https:\" or \"ftp:\"\n */\nexport type UrlProtocol = `${string}:`;\n\n/**\n * Creates a Zod schema for validating URLs. By default, it validates that the URL protocol is HTTPS and allow usage of HTTP only locally.\n *\n * @param {Object} options - Configuration options for the schema.\n * @param {UrlProtocol[]} [options.additionalProtocols=[]] - Additional protocols to allow (e.g., \"wss:\" or \"ftp:\"). \u26A0\uFE0F Usage of insecure protocols is discouraged.\n * @param {boolean} [options.allowHttpLocally=true] - Whether to allow HTTP for localhost and 127.0.0.1. Default: true.\n * @returns {z.ZodEffects<z.ZodString, string, string>} - The Zod schema with URL validation.\n *\n * @example\n * const schema = createUrlSchema({\n * additionalProtocols: [\"wss:\"],\n * allowHttpLocally: false\n * });\n *\n * schema.parse(\"https://example.com\"); // Valid\n * schema.parse(\"wss://example.com\"); // Valid\n * schema.parse(\"http://localhost\"); // Invalid if allowHttpLocally is false\n */\nexport const createUrlSchema = ({\n additionalProtocols = [],\n allowHttpLocally = true,\n}: {\n additionalProtocols?: UrlProtocol[];\n allowHttpLocally?: boolean;\n}): z.ZodURL =>\n z.url().refine(\n (url: string | URL): boolean => {\n try {\n const protocols = [...new Set([\"https:\", ...additionalProtocols])];\n\n const { protocol, hostname } = new URL(url);\n\n // We allow http for development locally\n if (allowHttpLocally && [\"localhost\", \"127.0.0.1\"].includes(hostname)) {\n return [\"http:\", ...protocols].includes(protocol);\n }\n\n return protocols.includes(protocol);\n } catch (_err: unknown) {\n return false;\n }\n },\n {\n error: \"Invalid URL.\",\n },\n );\n\n/**\n * Default URL schema that enforces HTTPS and allows HTTP locally.\n *\n * @constant {z.ZodEffects<z.ZodString, string, string>}\n * @example\n * UrlSchema.parse(\"https://example.com\"); // Valid\n * UrlSchema.parse(\"http://127.0.0.1\"); // Valid (localhost exception)\n */\nexport const UrlSchema = createUrlSchema({});\n"],
5
- "mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,yBAAAE,EAAA,cAAAC,EAAA,oBAAAC,IAAA,eAAAC,EAAAL,GCAA,IAAAM,EAA0B,8BAC1BC,EAAmB,kBAcNC,EAAwB,SAAO,EAAE,OAC3CC,GAAc,CACb,GAAI,CACF,mBAAU,SAASA,CAAS,EACrB,EACT,MAAwB,CACtB,MAAO,EACT,CACF,EACA,CACE,MAAO,gDACT,CACF,EC3BA,IAAAC,EAAmB,kBA0BNC,EAAkB,CAAC,CAC9B,oBAAAC,EAAsB,CAAC,EACvB,iBAAAC,EAAmB,EACrB,IAII,MAAI,EAAE,OACLC,GAA+B,CAC9B,GAAI,CACF,IAAMC,EAAY,CAAC,GAAG,IAAI,IAAI,CAAC,SAAU,GAAGH,CAAmB,CAAC,CAAC,EAE3D,CAAE,SAAAI,EAAU,SAAAC,CAAS,EAAI,IAAI,IAAIH,CAAG,EAG1C,OAAID,GAAoB,CAAC,YAAa,WAAW,EAAE,SAASI,CAAQ,EAC3D,CAAC,QAAS,GAAGF,CAAS,EAAE,SAASC,CAAQ,EAG3CD,EAAU,SAASC,CAAQ,CACpC,MAAwB,CACtB,MAAO,EACT,CACF,EACA,CACE,MAAO,cACT,CACF,EAUWE,EAAYP,EAAgB,CAAC,CAAC",
4
+ "sourcesContent": ["export * from \"./principal\";\nexport * from \"./url\";\n", "import { Principal } from \"@icp-sdk/core/principal\";\nimport * as z from \"zod\";\n\n/**\n * Zod schema to validate a string as a valid textual representation of a Principal.\n *\n * This schema checks if the provided string can be converted into a `Principal` instance.\n * If the conversion fails, validation will return an error message.\n *\n * @example\n * ```typescript\n * const result = PrincipalTextSchema.safeParse('aaaaa-aa');\n * console.log(result.success); // true or false\n * ```\n */\nexport const PrincipalTextSchema = z.string().refine(\n (principal) => {\n try {\n Principal.fromText(principal);\n return true;\n } catch (_err: unknown) {\n return false;\n }\n },\n {\n error: \"Invalid textual representation of a Principal.\",\n },\n);\n\nexport type PrincipalText = z.infer<typeof PrincipalTextSchema>;\n", "import * as z from \"zod\";\n\n/**\n * A URL protocol as template literal type.\n * Example: \"https:\" or \"ftp:\"\n */\nexport type UrlProtocol = `${string}:`;\n\n/**\n * Creates a Zod schema for validating URLs. By default, it validates that the URL protocol is HTTPS and allow usage of HTTP only locally.\n *\n * @param {Object} options - Configuration options for the schema.\n * @param {UrlProtocol[]} [options.additionalProtocols=[]] - Additional protocols to allow (e.g., \"wss:\" or \"ftp:\"). \u26A0\uFE0F Usage of insecure protocols is discouraged.\n * @param {boolean} [options.allowHttpLocally=true] - Whether to allow HTTP for localhost and 127.0.0.1. Default: true.\n * @returns {z.ZodEffects<z.ZodString, string, string>} - The Zod schema with URL validation.\n *\n * @example\n * const schema = createUrlSchema({\n * additionalProtocols: [\"wss:\"],\n * allowHttpLocally: false\n * });\n *\n * schema.parse(\"https://example.com\"); // Valid\n * schema.parse(\"wss://example.com\"); // Valid\n * schema.parse(\"http://localhost\"); // Invalid if allowHttpLocally is false\n */\nexport const createUrlSchema = ({\n additionalProtocols = [],\n allowHttpLocally = true,\n}: {\n additionalProtocols?: UrlProtocol[];\n allowHttpLocally?: boolean;\n}): z.ZodURL =>\n z.url().refine(\n (url: string | URL): boolean => {\n try {\n const protocols = [...new Set([\"https:\", ...additionalProtocols])];\n\n const { protocol, hostname } = new URL(url);\n\n // We allow http for development locally\n if (allowHttpLocally && [\"localhost\", \"127.0.0.1\"].includes(hostname)) {\n return [\"http:\", ...protocols].includes(protocol);\n }\n\n return protocols.includes(protocol);\n } catch (_err: unknown) {\n return false;\n }\n },\n {\n error: \"Invalid URL.\",\n },\n );\n\n/**\n * Default URL schema that enforces HTTPS and allows HTTP locally.\n *\n * @constant {z.ZodEffects<z.ZodString, string, string>}\n * @example\n * UrlSchema.parse(\"https://example.com\"); // Valid\n * UrlSchema.parse(\"http://127.0.0.1\"); // Valid (localhost exception)\n */\nexport const UrlSchema = createUrlSchema({});\n"],
5
+ "mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,yBAAAE,EAAA,cAAAC,EAAA,oBAAAC,IAAA,eAAAC,EAAAL,GCAA,IAAAM,EAA0B,mCAC1BC,EAAmB,kBAcNC,EAAwB,SAAO,EAAE,OAC3CC,GAAc,CACb,GAAI,CACF,mBAAU,SAASA,CAAS,EACrB,EACT,MAAwB,CACtB,MAAO,EACT,CACF,EACA,CACE,MAAO,gDACT,CACF,EC3BA,IAAAC,EAAmB,kBA0BNC,EAAkB,CAAC,CAC9B,oBAAAC,EAAsB,CAAC,EACvB,iBAAAC,EAAmB,EACrB,IAII,MAAI,EAAE,OACLC,GAA+B,CAC9B,GAAI,CACF,IAAMC,EAAY,CAAC,GAAG,IAAI,IAAI,CAAC,SAAU,GAAGH,CAAmB,CAAC,CAAC,EAE3D,CAAE,SAAAI,EAAU,SAAAC,CAAS,EAAI,IAAI,IAAIH,CAAG,EAG1C,OAAID,GAAoB,CAAC,YAAa,WAAW,EAAE,SAASI,CAAQ,EAC3D,CAAC,QAAS,GAAGF,CAAS,EAAE,SAASC,CAAQ,EAG3CD,EAAU,SAASC,CAAQ,CACpC,MAAwB,CACtB,MAAO,EACT,CACF,EACA,CACE,MAAO,cACT,CACF,EAUWE,EAAYP,EAAgB,CAAC,CAAC",
6
6
  "names": ["index_exports", "__export", "PrincipalTextSchema", "UrlSchema", "createUrlSchema", "__toCommonJS", "import_principal", "z", "PrincipalTextSchema", "principal", "z", "createUrlSchema", "additionalProtocols", "allowHttpLocally", "url", "protocols", "protocol", "hostname", "UrlSchema"]
7
7
  }
@@ -0,0 +1,2 @@
1
+ import{Principal as t}from"@icp-sdk/core/principal";import*as r from"zod";var a=r.string().refine(e=>{try{return t.fromText(e),!0}catch{return!1}},{error:"Invalid textual representation of a Principal."});export{a};
2
+ //# sourceMappingURL=chunk-2SF3C7FG.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/principal.ts"],
4
+ "sourcesContent": ["import { Principal } from \"@icp-sdk/core/principal\";\nimport * as z from \"zod\";\n\n/**\n * Zod schema to validate a string as a valid textual representation of a Principal.\n *\n * This schema checks if the provided string can be converted into a `Principal` instance.\n * If the conversion fails, validation will return an error message.\n *\n * @example\n * ```typescript\n * const result = PrincipalTextSchema.safeParse('aaaaa-aa');\n * console.log(result.success); // true or false\n * ```\n */\nexport const PrincipalTextSchema = z.string().refine(\n (principal) => {\n try {\n Principal.fromText(principal);\n return true;\n } catch (_err: unknown) {\n return false;\n }\n },\n {\n error: \"Invalid textual representation of a Principal.\",\n },\n);\n\nexport type PrincipalText = z.infer<typeof PrincipalTextSchema>;\n"],
5
+ "mappings": "AAAA,OAAS,aAAAA,MAAiB,0BAC1B,UAAYC,MAAO,MAcZ,IAAMC,EAAwB,SAAO,EAAE,OAC3CC,GAAc,CACb,GAAI,CACF,OAAAH,EAAU,SAASG,CAAS,EACrB,EACT,MAAwB,CACtB,MAAO,EACT,CACF,EACA,CACE,MAAO,gDACT,CACF",
6
+ "names": ["Principal", "z", "PrincipalTextSchema", "principal"]
7
+ }
package/dist/esm/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import{a as o}from"./chunk-W6PRVPKK.js";import{a as r,b as e}from"./chunk-NPK6AQOT.js";export{o as PrincipalTextSchema,e as UrlSchema,r as createUrlSchema};
1
+ import{a as o}from"./chunk-2SF3C7FG.js";import{a as r,b as e}from"./chunk-NPK6AQOT.js";export{o as PrincipalTextSchema,e as UrlSchema,r as createUrlSchema};
2
2
  //# sourceMappingURL=index.js.map
@@ -1,2 +1,2 @@
1
- import{a}from"./chunk-W6PRVPKK.js";export{a as PrincipalTextSchema};
1
+ import{a}from"./chunk-2SF3C7FG.js";export{a as PrincipalTextSchema};
2
2
  //# sourceMappingURL=principal.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dfinity/zod-schemas",
3
- "version": "2.0.0",
3
+ "version": "2.1.0-beta-2025-09-25",
4
4
  "description": "A collection of reusable Zod schemas and validators for common data patterns in ICP applications",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/cjs/index.cjs.js",
@@ -47,7 +47,7 @@
47
47
  "service-nervous-system"
48
48
  ],
49
49
  "peerDependencies": {
50
- "@dfinity/principal": "^2.0.0",
51
- "zod": "^4"
50
+ "@icp-sdk/core": "*",
51
+ "zod": "*"
52
52
  }
53
- }
53
+ }
@@ -1,2 +0,0 @@
1
- import{Principal as t}from"@dfinity/principal";import*as r from"zod";var a=r.string().refine(e=>{try{return t.fromText(e),!0}catch{return!1}},{error:"Invalid textual representation of a Principal."});export{a};
2
- //# sourceMappingURL=chunk-W6PRVPKK.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/principal.ts"],
4
- "sourcesContent": ["import { Principal } from \"@dfinity/principal\";\nimport * as z from \"zod\";\n\n/**\n * Zod schema to validate a string as a valid textual representation of a Principal.\n *\n * This schema checks if the provided string can be converted into a `Principal` instance.\n * If the conversion fails, validation will return an error message.\n *\n * @example\n * ```typescript\n * const result = PrincipalTextSchema.safeParse('aaaaa-aa');\n * console.log(result.success); // true or false\n * ```\n */\nexport const PrincipalTextSchema = z.string().refine(\n (principal) => {\n try {\n Principal.fromText(principal);\n return true;\n } catch (_err: unknown) {\n return false;\n }\n },\n {\n error: \"Invalid textual representation of a Principal.\",\n },\n);\n\nexport type PrincipalText = z.infer<typeof PrincipalTextSchema>;\n"],
5
- "mappings": "AAAA,OAAS,aAAAA,MAAiB,qBAC1B,UAAYC,MAAO,MAcZ,IAAMC,EAAwB,SAAO,EAAE,OAC3CC,GAAc,CACb,GAAI,CACF,OAAAH,EAAU,SAASG,CAAS,EACrB,EACT,MAAwB,CACtB,MAAO,EACT,CACF,EACA,CACE,MAAO,gDACT,CACF",
6
- "names": ["Principal", "z", "PrincipalTextSchema", "principal"]
7
- }