@better-giving/schemas 1.1.2 → 1.2.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.
package/dist/index.d.mts CHANGED
@@ -17,3 +17,4 @@ export type Environment = InferOutput<typeof env>;
17
17
  export declare const donateMethodIds: readonly ["stripe", "crypto", "daf", "stocks"];
18
18
  export declare const donateMethodId: import("valibot").PicklistSchema<readonly ["stripe", "crypto", "daf", "stocks"], undefined>;
19
19
  export type DonateMethodId = InferOutput<typeof donateMethodId>;
20
+ export declare const https_url: (non_empty: boolean) => import("valibot").LazySchema<import("valibot").SchemaWithPipe<[import("valibot").StringSchema<undefined>, import("valibot").TrimAction]> | import("valibot").SchemaWithPipe<[import("valibot").SchemaWithPipe<[import("valibot").StringSchema<undefined>, import("valibot").TrimAction]>, import("valibot").NonEmptyAction<string, "required">]> | import("valibot").SchemaWithPipe<[import("valibot").SchemaWithPipe<[import("valibot").StringSchema<undefined>, import("valibot").TrimAction]>, import("valibot").TransformAction<string, string>, import("valibot").UrlAction<string, "invalid url">]>>;
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { url, object, picklist, pipe, string } from "valibot";
1
+ import { url, object, picklist, pipe, string, lazy, transform, trim, nonEmpty, } from "valibot";
2
2
  export const fileObject = object({
3
3
  name: string(),
4
4
  publicUrl: pipe(string(), url()),
@@ -19,3 +19,9 @@ export const envs = ["staging", "production"];
19
19
  export const env = picklist(envs);
20
20
  export const donateMethodIds = ["stripe", "crypto", "daf", "stocks"];
21
21
  export const donateMethodId = picklist(donateMethodIds);
22
+ const str = pipe(string(), trim());
23
+ export const https_url = (non_empty) => lazy((x) => {
24
+ if (!x)
25
+ return non_empty ? pipe(str, nonEmpty("required")) : str;
26
+ return pipe(str, transform((x) => (x.startsWith("https://") ? x : `https://${x}`)), url("invalid url"));
27
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@better-giving/schemas",
3
- "version": "1.1.2",
3
+ "version": "1.2.0",
4
4
  "devDependencies": {
5
5
  "@better-giving/config": "1.1.2"
6
6
  },
package/src/index.mts CHANGED
@@ -1,4 +1,15 @@
1
- import { url, type InferOutput, object, picklist, pipe, string } from "valibot";
1
+ import {
2
+ url,
3
+ type InferOutput,
4
+ object,
5
+ picklist,
6
+ pipe,
7
+ string,
8
+ lazy,
9
+ transform,
10
+ trim,
11
+ nonEmpty,
12
+ } from "valibot";
2
13
 
3
14
  export const fileObject = object({
4
15
  name: string(),
@@ -32,3 +43,14 @@ export type Environment = InferOutput<typeof env>;
32
43
  export const donateMethodIds = ["stripe", "crypto", "daf", "stocks"] as const;
33
44
  export const donateMethodId = picklist(donateMethodIds);
34
45
  export type DonateMethodId = InferOutput<typeof donateMethodId>;
46
+
47
+ const str = pipe(string(), trim());
48
+ export const https_url = (non_empty: boolean) =>
49
+ lazy((x) => {
50
+ if (!x) return non_empty ? pipe(str, nonEmpty("required")) : str;
51
+ return pipe(
52
+ str,
53
+ transform((x) => (x.startsWith("https://") ? x : `https://${x}`)),
54
+ url("invalid url")
55
+ );
56
+ });