@better-giving/endowment 2.0.6 → 3.0.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,41 @@
1
+ import type { IPageKeyed } from "@better-giving/types/api";
2
+ import type { Ensure } from "@better-giving/types/utils";
3
+ import type { IMediaUpdate, INpo, TMediaType } from "./schema.mjs";
4
+ export type { IAllocation, INpo, INpoFields, INposSearch, INpoUpdate, IIncrement, IMediaSearch, IMediaSearchObj, TMediaType, IMediaUpdate, IMilestone, IMilestoneUpdate, IMilestoneNew, IProgramNew, IProgramUpdate, ISocialMediaURLs, } from "./schema.mjs";
5
+ export { type OrgDesignation as EndowDesignation, type Environment, type UnSdgNum, type DonateMethodId, https_url, } from "@better-giving/schemas";
6
+ export interface INpoDb extends INpo {
7
+ /** will only be present for unclaimed NPOs */
8
+ updated_at_auto?: string;
9
+ /** in USD @deprecated */
10
+ payout_minimum?: number;
11
+ /** @deprecated */
12
+ splitLiqPct?: number;
13
+ /** @deprecated */
14
+ splitFixed?: boolean;
15
+ /** @deprecated */
16
+ sfCompounded?: boolean;
17
+ }
18
+ export interface INpoReferredBy extends Ensure<INpo, "referrer" | "referrer_expiry"> {
19
+ }
20
+ export interface INpoWithRid extends Ensure<INpo, "referral_id"> {
21
+ }
22
+ export interface INpoWithRegNum extends Pick<INpo, "claimed" | "name" | "hq_country" | "id"> {
23
+ }
24
+ export interface IMedia extends Required<IMediaUpdate> {
25
+ id: string;
26
+ type: Extract<TMediaType, "video">;
27
+ dateCreated: string;
28
+ }
29
+ export interface IMediaDb extends Omit<IMedia, "featured"> {
30
+ }
31
+ export interface IMediaPage extends IPageKeyed<IMedia> {
32
+ }
33
+ export type TNpoDbKeys = keyof INpoDb;
34
+ export type TArrayValues<T extends readonly unknown[]> = T[number];
35
+ export type TNpoDbProjectedTo<T> = T extends TNpoDbKeys[] ? Pick<INpoDb, TArrayValues<T>> : INpoDb;
36
+ export type TBinFlag = "0" | "1";
37
+ export interface INposPage<T extends keyof INpoDb = keyof INpoDb> {
38
+ items: Pick<INpoDb, T>[];
39
+ page: number;
40
+ pages: number;
41
+ }
@@ -0,0 +1 @@
1
+ export { https_url, } from "@better-giving/schemas";
@@ -0,0 +1,11 @@
1
+ import type { TRecord } from "@better-giving/db";
2
+ import type { IMedia, TBinFlag } from "./interfaces.mjs";
3
+ import type { IMediaSearchObj, TMediaType } from "./schema.mjs";
4
+ export declare const med_sk: (ksuid: string, type: TMediaType, featured: TBinFlag) => string;
5
+ export declare const med_sk_attr: (sk: string) => {
6
+ featured: TBinFlag;
7
+ ksuid: string;
8
+ type: "album" | "article" | "video";
9
+ };
10
+ export declare function med_key_filter(PK: string, params: IMediaSearchObj): [string, Record<string, string>];
11
+ export declare const to_imedia: (d: TRecord) => IMedia;
package/dist/media.mjs ADDED
@@ -0,0 +1,48 @@
1
+ export const med_sk = (ksuid, type, featured) => `MediaList#${featured}#${ksuid}#${type}`;
2
+ export const med_sk_attr = (sk) => {
3
+ const [featured, ksuid, type] = sk.split("#").slice(1);
4
+ return { featured, ksuid, type };
5
+ };
6
+ export function med_key_filter(PK, params) {
7
+ /** KSUID string is base62, length:27 */
8
+ const min_ksuid = "0".repeat(27);
9
+ const max_ksuid = "z".repeat(27);
10
+ //media categories: get all media per type, all featured - sorted by date
11
+ if (params.featured && params.type) {
12
+ return [
13
+ `gsi1PK = :pk AND gsi1SK BETWEEN :startSK and :endSK`,
14
+ {
15
+ ":pk": PK,
16
+ ":startSK": med_sk(min_ksuid, params.type, "0"),
17
+ ":endSK": med_sk(max_ksuid, params.type, "0"),
18
+ },
19
+ ];
20
+ }
21
+ //media type page: get all media per type - sorted by featured and date
22
+ if (params.type) {
23
+ return [
24
+ `gsi1PK = :pk AND gsi1SK BETWEEN :startSK and :endSK`,
25
+ {
26
+ ":pk": PK,
27
+ ":startSK": med_sk(min_ksuid, params.type, "0"),
28
+ ":endSK": med_sk(max_ksuid, params.type, "1"),
29
+ },
30
+ ];
31
+ }
32
+ //endow-profile: get all media, all featured - sorted by date
33
+ if (params.featured) {
34
+ return [
35
+ `gsi1PK = :pk AND begins_with(gsi1SK, :sk)`,
36
+ { ":pk": PK, ":sk": `MediaList#0` },
37
+ ];
38
+ }
39
+ return [
40
+ `gsi1PK = :pk AND begins_with(gsi1SK, :sk)`,
41
+ { ":pk": PK, ":sk": `MediaList#` },
42
+ ];
43
+ }
44
+ export const to_imedia = (d) => {
45
+ const { gsi1SK, gsi1PK, PK, SK, ...rest } = d;
46
+ const x = med_sk_attr(gsi1SK);
47
+ return { ...rest, featured: x.featured === "1" };
48
+ };
package/dist/npo.d.mts ADDED
@@ -0,0 +1,4 @@
1
+ export declare function projection(fields?: string[]): {
2
+ expression: string;
3
+ names: Record<string, string>;
4
+ };
package/dist/npo.mjs ADDED
@@ -0,0 +1,41 @@
1
+ const npo_fields = {
2
+ id: "",
3
+ active_in_countries: "",
4
+ endow_designation: "",
5
+ fiscal_sponsored: "",
6
+ hide_bg_tip: "",
7
+ hq_country: "",
8
+ image: "",
9
+ kyc_donors_only: "",
10
+ logo: "",
11
+ name: "",
12
+ overview: "",
13
+ published: "",
14
+ registration_number: "",
15
+ social_media_urls: "",
16
+ sdgs: "",
17
+ street_address: "",
18
+ tagline: "",
19
+ url: "",
20
+ slug: "",
21
+ claimed: "",
22
+ card_img: "",
23
+ progDonationsAllowed: "",
24
+ allocation: "",
25
+ donateMethods: "",
26
+ increments: "",
27
+ receiptMsg: "",
28
+ fund_opt_in: "",
29
+ env: "",
30
+ target: "",
31
+ referrer: "",
32
+ referrer_expiry: "",
33
+ referral_id: "",
34
+ w_form: "",
35
+ payout_minimum: "",
36
+ };
37
+ export function projection(fields = Object.keys(npo_fields)) {
38
+ const expression = fields.map((n) => `#${n}`).join(",");
39
+ const names = fields.reduce((prev, curr) => ({ ...prev, [`#${curr}`]: curr }), {});
40
+ return { expression, names };
41
+ }
package/dist/schema.d.mts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { $, $int_gte1, $req, $req_num_gt0, donate_method_id, donate_method_ids, env, int_gte1, org_designation, unsdg_num } from "@better-giving/schemas";
2
- export { type OrgDesignation as EndowDesignation, type Environment, type UnSdgNum, type DonateMethodId, https_url, } from "@better-giving/schemas";
3
2
  export { org_designation as endow_designation, env, unsdg_num, donate_method_id, donate_method_ids, $int_gte1, int_gte1, $, $req_num_gt0, $req, };
4
3
  import * as v from "valibot";
5
4
  export declare const min_payout_amount = 50;
@@ -14,9 +13,9 @@ export declare const allocation: v.SchemaWithPipe<[v.ObjectSchema<{
14
13
  liq: number;
15
14
  lock: number;
16
15
  }, "must total to 100">]>;
17
- export interface Allocation extends v.InferOutput<typeof allocation> {
16
+ export interface IAllocation extends v.InferOutput<typeof allocation> {
18
17
  }
19
- export declare const segmentMaxChars = 30;
18
+ export declare const segment_max_chars = 30;
20
19
  export declare const segment: v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.MaxLengthAction<string, 30, ({ requirement: r }: v.MaxLengthIssue<string, 30>) => string>, v.RegexAction<string, "should not be an id">, v.RegexAction<string, "allowed: numbers | letters | - | . | _ | ~">, v.ExcludesAction<string, "..", "should not contain double periods">, v.CustomSchema<string, "should not start with dot">, v.CustomSchema<string, "should not end with dot">]>;
21
20
  export declare const slug: v.LazySchema<v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]> | v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.MaxLengthAction<string, 30, ({ requirement: r }: v.MaxLengthIssue<string, 30>) => string>, v.RegexAction<string, "should not be an id">, v.RegexAction<string, "allowed: numbers | letters | - | . | _ | ~">, v.ExcludesAction<string, "..", "should not contain double periods">, v.CustomSchema<string, "should not start with dot">, v.CustomSchema<string, "should not end with dot">]>>;
22
21
  export declare const reg_number: v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.NonEmptyAction<string, "required">, v.RegexAction<string, "must only contain letters and numbers">]>;
@@ -30,21 +29,21 @@ export declare const social_media_urls: v.ObjectSchema<{
30
29
  readonly youtube: v.OptionalSchema<v.LazySchema<v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]> | v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.NonEmptyAction<string, "required">]> | v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.TransformAction<string, string>, v.UrlAction<string, "invalid url">]>>, never>;
31
30
  readonly tiktok: v.OptionalSchema<v.LazySchema<v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]> | v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.NonEmptyAction<string, "required">]> | v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.TransformAction<string, string>, v.UrlAction<string, "invalid url">]>>, never>;
32
31
  }, undefined>;
33
- export interface SocialMediaURLs extends v.InferOutput<typeof social_media_urls> {
32
+ export interface ISocialMediaURLs extends v.InferOutput<typeof social_media_urls> {
34
33
  }
35
34
  export declare const MAX_RECEIPT_MSG_CHAR = 500;
36
- export declare const incrementVal: v.SchemaWithPipe<[v.SchemaWithPipe<[v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.NonEmptyAction<string, "required">]>, v.TransformAction<string, number>, v.NumberSchema<"invalid number">, v.MinValueAction<number, 0, "must be > 0">, v.TransformAction<number, string>]>, v.TransformAction<string, string>]>;
35
+ export declare const increment_val: v.SchemaWithPipe<[v.SchemaWithPipe<[v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.NonEmptyAction<string, "required">]>, v.TransformAction<string, number>, v.NumberSchema<"invalid number">, v.MinValueAction<number, 0, "must be > 0">, v.TransformAction<number, string>]>, v.TransformAction<string, string>]>;
37
36
  export declare const MAX_NUM_INCREMENTS = 4;
38
- export declare const incrementLabelMaxChars = 60;
39
- export declare const taglineMaxChars = 140;
40
- export declare const incrementLabel: v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.MaxLengthAction<string, 60, ({ requirement: r }: v.MaxLengthIssue<string, 60>) => string>]>;
37
+ export declare const increment_label_max_chars = 60;
38
+ export declare const tagline_max_chars = 140;
39
+ export declare const increment_label: v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.MaxLengthAction<string, 60, ({ requirement: r }: v.MaxLengthIssue<string, 60>) => string>]>;
41
40
  export declare const increment: v.ObjectSchema<{
42
41
  readonly value: v.SchemaWithPipe<[v.SchemaWithPipe<[v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.NonEmptyAction<string, "required">]>, v.TransformAction<string, number>, v.NumberSchema<"invalid number">, v.MinValueAction<number, 0, "must be > 0">, v.TransformAction<number, string>]>, v.TransformAction<string, string>]>;
43
42
  readonly label: v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.MaxLengthAction<string, 60, ({ requirement: r }: v.MaxLengthIssue<string, 60>) => string>]>;
44
43
  }, undefined>;
45
- export interface Increment extends v.InferOutput<typeof increment> {
44
+ export interface IIncrement extends v.InferOutput<typeof increment> {
46
45
  }
47
- export declare const endowment: v.ObjectSchema<{
46
+ export declare const npo: v.ObjectSchema<{
48
47
  readonly id: v.SchemaWithPipe<[v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>]>;
49
48
  readonly env: v.PicklistSchema<readonly ["staging", "production"], undefined>;
50
49
  readonly slug: v.OptionalSchema<v.LazySchema<v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]> | v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.MaxLengthAction<string, 30, ({ requirement: r }: v.MaxLengthIssue<string, 30>) => string>, v.RegexAction<string, "should not be an id">, v.RegexAction<string, "allowed: numbers | letters | - | . | _ | ~">, v.ExcludesAction<string, "..", "should not contain double periods">, v.CustomSchema<string, "should not start with dot">, v.CustomSchema<string, "should not end with dot">]>>, never>;
@@ -105,7 +104,7 @@ export declare const endowment: v.ObjectSchema<{
105
104
  readonly w_form: v.OptionalSchema<v.StringSchema<undefined>, never>;
106
105
  readonly payout_minimum: v.OptionalSchema<v.SchemaWithPipe<[v.NumberSchema<undefined>, v.MinValueAction<number, 50, undefined>]>, never>;
107
106
  }, undefined>;
108
- export declare const endowUpdate: Omit<Omit<v.ObjectSchema<{
107
+ export declare const npo_update: Omit<Omit<v.ObjectSchema<{
109
108
  readonly id: v.SchemaWithPipe<[v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>]>;
110
109
  readonly env: v.PicklistSchema<readonly ["staging", "production"], undefined>;
111
110
  readonly slug: v.OptionalSchema<v.LazySchema<v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]> | v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.MaxLengthAction<string, 30, ({ requirement: r }: v.MaxLengthIssue<string, 30>) => string>, v.RegexAction<string, "should not be an id">, v.RegexAction<string, "allowed: numbers | letters | - | . | _ | ~">, v.ExcludesAction<string, "..", "should not contain double periods">, v.CustomSchema<string, "should not start with dot">, v.CustomSchema<string, "should not end with dot">]>>, never>;
@@ -606,29 +605,27 @@ export declare const endowUpdate: Omit<Omit<v.ObjectSchema<{
606
605
  }[], 4> | v.LiteralIssue | v.UnionIssue<v.StringIssue | v.NumberIssue | v.MinValueIssue<number, 0> | v.LiteralIssue> | v.IsoTimestampIssue<string> | v.MinValueIssue<number, 50>;
607
606
  } | undefined;
608
607
  };
609
- export declare const endowFields: v.PicklistSchema<["url", "slug", "overview", "tagline", "image", "logo", "card_img", "active_in_countries", "street_address", "sdgs", "receiptMsg", "hide_bg_tip", "published", "progDonationsAllowed", "allocation", "donateMethods", "increments", "fund_opt_in", "target", "referral_id", "referrer", "referrer_expiry", "w_form", "payout_minimum", "id", "env", "registration_number", "name", "endow_designation", "hq_country", "social_media_urls", "claimed", "kyc_donors_only", "fiscal_sponsored"], undefined>;
610
- export interface Endowment extends v.InferOutput<typeof endowment> {
608
+ export declare const npo_fields: v.PicklistSchema<["url", "slug", "overview", "tagline", "image", "logo", "card_img", "active_in_countries", "street_address", "sdgs", "receiptMsg", "hide_bg_tip", "published", "progDonationsAllowed", "allocation", "donateMethods", "increments", "fund_opt_in", "target", "referral_id", "referrer", "referrer_expiry", "w_form", "payout_minimum", "id", "env", "registration_number", "name", "endow_designation", "hq_country", "social_media_urls", "claimed", "kyc_donors_only", "fiscal_sponsored"], undefined>;
609
+ export interface INpo extends v.InferOutput<typeof npo> {
611
610
  }
612
- export interface EndowUpdate extends v.InferOutput<typeof endowUpdate> {
611
+ export interface INpoUpdate extends v.InferOutput<typeof npo_update> {
613
612
  }
614
- export type EndowFields = v.InferOutput<typeof endowFields>;
613
+ export type INpoFields = v.InferOutput<typeof npo_fields>;
615
614
  /** for ein path, only fields in reg-num/env gsi is available */
616
- export declare const endowQueryParams: v.ObjectSchema<{
615
+ export declare const npo_search: v.ObjectSchema<{
617
616
  readonly fields: v.OptionalSchema<v.SchemaWithPipe<[v.SchemaWithPipe<[v.LazySchema<v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]> | v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.RegexAction<string, "invalid csv">]>>, v.TransformAction<string, string[]>, v.FilterItemsAction<string[]>]>, v.ArraySchema<v.PicklistSchema<["url", "slug", "overview", "tagline", "image", "logo", "card_img", "active_in_countries", "street_address", "sdgs", "receiptMsg", "hide_bg_tip", "published", "progDonationsAllowed", "allocation", "donateMethods", "increments", "fund_opt_in", "target", "referral_id", "referrer", "referrer_expiry", "w_form", "payout_minimum", "id", "env", "registration_number", "name", "endow_designation", "hq_country", "social_media_urls", "claimed", "kyc_donors_only", "fiscal_sponsored"], undefined>, undefined>]>, never>;
618
617
  }, undefined>;
619
- export interface EndowQueryParams extends v.InferInput<typeof endowQueryParams> {
618
+ export interface INposSearch extends v.InferInput<typeof npo_search> {
620
619
  }
621
- export declare const programId: v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.UuidAction<string, undefined>]>;
622
- export type ProgramId = v.InferOutput<typeof programId>;
623
- export declare const milestoneId: v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.UuidAction<string, undefined>]>;
624
- export type MilestoneId = v.InferOutput<typeof milestoneId>;
625
- export declare const newMilestone: v.ObjectSchema<{
620
+ export declare const program_id: v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.UuidAction<string, undefined>]>;
621
+ export declare const milestone_id: v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.UuidAction<string, undefined>]>;
622
+ export declare const milestone_new: v.ObjectSchema<{
626
623
  readonly date: v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.IsoTimestampAction<string, undefined>]>;
627
624
  readonly title: v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>;
628
625
  readonly description: v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>;
629
626
  readonly media: v.OptionalSchema<v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.UrlAction<string, undefined>]>, never>;
630
627
  }, undefined>;
631
- export declare const milestoneUpdate: Omit<v.ObjectSchema<{
628
+ export declare const milestone_update: Omit<v.ObjectSchema<{
632
629
  readonly date: v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.IsoTimestampAction<string, undefined>]>;
633
630
  readonly title: v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>;
634
631
  readonly description: v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>;
@@ -662,9 +659,9 @@ export declare const milestoneUpdate: Omit<v.ObjectSchema<{
662
659
  readonly issue: v.StringIssue | v.ObjectIssue | v.UrlIssue<string> | v.IsoTimestampIssue<string>;
663
660
  } | undefined;
664
661
  };
665
- export interface MilestoneUpdate extends v.InferOutput<typeof milestoneUpdate> {
662
+ export interface IMilestoneUpdate extends v.InferOutput<typeof milestone_update> {
666
663
  }
667
- export interface NewMilestone extends v.InferOutput<typeof newMilestone> {
664
+ export interface IMilestoneNew extends v.InferOutput<typeof milestone_new> {
668
665
  }
669
666
  export declare const milestone: v.ObjectSchema<{
670
667
  readonly id: v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.UuidAction<string, undefined>]>;
@@ -673,9 +670,9 @@ export declare const milestone: v.ObjectSchema<{
673
670
  readonly description: v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>;
674
671
  readonly media: v.OptionalSchema<v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.UrlAction<string, undefined>]>, never>;
675
672
  }, undefined>;
676
- export interface Milestone extends v.InferOutput<typeof milestone> {
673
+ export interface IMilestone extends v.InferOutput<typeof milestone> {
677
674
  }
678
- export declare const newProgram: v.ObjectSchema<{
675
+ export declare const program_new: v.ObjectSchema<{
679
676
  readonly title: v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>;
680
677
  readonly description: v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>;
681
678
  readonly banner: v.OptionalSchema<v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.UrlAction<string, undefined>]>, never>;
@@ -702,7 +699,7 @@ export declare const program: v.ObjectSchema<{
702
699
  readonly banner: v.OptionalSchema<v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.UrlAction<string, undefined>]>, never>;
703
700
  readonly targetRaise: v.NullishSchema<v.SchemaWithPipe<[v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>]>, never>;
704
701
  }, undefined>;
705
- export declare const programUpdate: Omit<Omit<v.ObjectSchema<{
702
+ export declare const program_update: Omit<Omit<v.ObjectSchema<{
706
703
  readonly title: v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>;
707
704
  readonly description: v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>;
708
705
  readonly banner: v.OptionalSchema<v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.UrlAction<string, undefined>]>, never>;
@@ -788,35 +785,37 @@ export declare const programUpdate: Omit<Omit<v.ObjectSchema<{
788
785
  readonly issue: v.StringIssue | v.NumberIssue | v.MinValueIssue<number, 0> | v.ObjectIssue | v.UrlIssue<string>;
789
786
  } | undefined;
790
787
  };
791
- export interface NewProgram extends v.InferOutput<typeof newProgram> {
788
+ export interface IProgramNew extends v.InferOutput<typeof program_new> {
792
789
  }
793
- export interface Program extends v.InferOutput<typeof program> {
790
+ export interface IProgramDb extends v.InferOutput<typeof program> {
794
791
  }
795
- export interface ProgramUpdate extends v.InferOutput<typeof programUpdate> {
792
+ export interface IProgram extends v.InferOutput<typeof program> {
793
+ milestones: IMilestone[];
796
794
  }
797
- export declare const mediaUrl: v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.UrlAction<string, undefined>]>;
795
+ export interface IProgramUpdate extends v.InferOutput<typeof program_update> {
796
+ }
797
+ export declare const media_url: v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.UrlAction<string, undefined>]>;
798
798
  /**
799
799
  * so that media is automatically sorted by date
800
800
  * @see https://github.com/segmentio/ksuid
801
801
  * */
802
- export declare const mediaKsuid: v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.NonEmptyAction<string, "required">]>;
803
- export declare const mediaTypes: readonly ["album", "article", "video"];
804
- export declare const mediaType: v.PicklistSchema<readonly ["album", "article", "video"], undefined>;
805
- export type MediaType = v.InferOutput<typeof mediaType>;
806
- export declare const mediaUpdate: v.ObjectSchema<{
802
+ export declare const media_ksuid: v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.NonEmptyAction<string, "required">]>;
803
+ export declare const media_types: readonly ["album", "article", "video"];
804
+ export declare const media_type: v.PicklistSchema<readonly ["album", "article", "video"], undefined>;
805
+ export type TMediaType = v.InferOutput<typeof media_type>;
806
+ export declare const media_update: v.ObjectSchema<{
807
807
  readonly url: v.OptionalSchema<v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.UrlAction<string, undefined>]>, never>;
808
808
  readonly featured: v.OptionalSchema<v.BooleanSchema<undefined>, never>;
809
809
  }, undefined>;
810
- export interface MediaUpdate extends v.InferOutput<typeof mediaUpdate> {
810
+ export interface IMediaUpdate extends v.InferOutput<typeof media_update> {
811
811
  }
812
- export type MediaId = v.InferOutput<typeof mediaKsuid>;
813
- export declare const mediaQueryParams: v.ObjectSchema<{
812
+ export declare const media_search: v.ObjectSchema<{
814
813
  readonly type: v.OptionalSchema<v.PicklistSchema<readonly ["album", "article", "video"], undefined>, never>;
815
- readonly nextPageKey: v.OptionalSchema<v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.Base64Action<string, undefined>]>, never>;
814
+ readonly next: v.OptionalSchema<v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.Base64Action<string, undefined>]>, never>;
816
815
  readonly featured: v.OptionalSchema<v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.TransformAction<string, boolean>, v.BooleanSchema<undefined>]>, never>;
817
816
  readonly limit: v.OptionalSchema<v.SchemaWithPipe<[v.StringSchema<undefined>, v.TransformAction<string, number>, v.SchemaWithPipe<[v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>]>]>, never>;
818
817
  }, undefined>;
819
- export interface MediaQueryParams extends v.InferInput<typeof mediaQueryParams> {
818
+ export interface IMediaSearch extends v.InferInput<typeof media_search> {
820
819
  }
821
- export interface MediaQueryParamsObj extends v.InferOutput<typeof mediaQueryParams> {
820
+ export interface IMediaSearchObj extends v.InferOutput<typeof media_search> {
822
821
  }
package/dist/schema.mjs CHANGED
@@ -1,5 +1,4 @@
1
1
  import { $, $int_gte1, $req, $req_num_gt0, donate_method_id, donate_method_ids, env, https_url, int_gte1, org_designation, unsdg_num, } from "@better-giving/schemas";
2
- export { https_url, } from "@better-giving/schemas";
3
2
  export { org_designation as endow_designation, env, unsdg_num, donate_method_id, donate_method_ids, $int_gte1, int_gte1, $, $req_num_gt0, $req, };
4
3
  import * as v from "valibot";
5
4
  export const min_payout_amount = 50;
@@ -15,8 +14,8 @@ export const allocation = v.pipe(v.object({
15
14
  liq: pct,
16
15
  lock: pct,
17
16
  }), v.check((x) => x.cash + x.liq + x.lock === 100, "must total to 100"));
18
- export const segmentMaxChars = 30;
19
- export const segment = v.pipe($, v.maxLength(segmentMaxChars, ({ requirement: r }) => `cannot exceed ${r} chars`),
17
+ export const segment_max_chars = 30;
18
+ export const segment = v.pipe($, v.maxLength(segment_max_chars, ({ requirement: r }) => `cannot exceed ${r} chars`),
20
19
  //must not be id-like
21
20
  v.regex(/^(?!^\d+$)/, "should not be an id"),
22
21
  //valid characters
@@ -34,18 +33,18 @@ export const social_media_urls = v.object({
34
33
  tiktok: v.optional(https_url(false)),
35
34
  });
36
35
  export const MAX_RECEIPT_MSG_CHAR = 500;
37
- export const incrementVal = v.pipe($req_num_gt0,
36
+ export const increment_val = v.pipe($req_num_gt0,
38
37
  //parsed output
39
38
  v.transform((x) => x.toString()));
40
39
  export const MAX_NUM_INCREMENTS = 4;
41
- export const incrementLabelMaxChars = 60;
42
- export const taglineMaxChars = 140;
43
- export const incrementLabel = v.pipe($, v.maxLength(incrementLabelMaxChars, ({ requirement: r }) => `cannot exceed ${r} characters`));
40
+ export const increment_label_max_chars = 60;
41
+ export const tagline_max_chars = 140;
42
+ export const increment_label = v.pipe($, v.maxLength(increment_label_max_chars, ({ requirement: r }) => `cannot exceed ${r} characters`));
44
43
  export const increment = v.object({
45
- value: incrementVal,
46
- label: incrementLabel,
44
+ value: increment_val,
45
+ label: increment_label,
47
46
  });
48
- export const endowment = v.object({
47
+ export const npo = v.object({
49
48
  id: int_gte1,
50
49
  env,
51
50
  slug: v.optional(slug),
@@ -53,7 +52,7 @@ export const endowment = v.object({
53
52
  name: $req,
54
53
  endow_designation: org_designation,
55
54
  overview: v.optional($),
56
- tagline: v.optional(v.pipe($, v.maxLength(taglineMaxChars))),
55
+ tagline: v.optional(v.pipe($, v.maxLength(tagline_max_chars))),
57
56
  image: v.optional(_url),
58
57
  logo: v.optional(_url),
59
58
  card_img: v.optional(_url),
@@ -89,59 +88,56 @@ export const endowment = v.object({
89
88
  w_form: v.optional(v.string()),
90
89
  payout_minimum: v.optional(v.pipe(v.number(), v.minValue(min_payout_amount))),
91
90
  });
92
- export const endowUpdate = v.partial(v.omit(endowment, [
93
- "id",
94
- "claimed",
95
- "kyc_donors_only",
96
- "env",
97
- "fiscal_sponsored",
98
- ]));
99
- export const endowFields = v.keyof(endowment);
91
+ export const npo_update = v.partial(v.omit(npo, ["id", "claimed", "kyc_donors_only", "env", "fiscal_sponsored"]));
92
+ export const npo_fields = v.keyof(npo);
100
93
  /** for ein path, only fields in reg-num/env gsi is available */
101
- export const endowQueryParams = v.object({
102
- fields: v.optional(v.pipe(csvStrs, v.array(endowFields))),
94
+ export const npo_search = v.object({
95
+ fields: v.optional(v.pipe(csvStrs, v.array(npo_fields))),
103
96
  });
104
97
  const amnt = v.pipe(v.number(), v.minValue(0));
105
- export const programId = v.pipe($, v.uuid());
106
- export const milestoneId = v.pipe($, v.uuid());
107
- export const newMilestone = v.object({
98
+ export const program_id = v.pipe($, v.uuid());
99
+ export const milestone_id = v.pipe($, v.uuid());
100
+ export const milestone_new = v.object({
108
101
  date: v.pipe($, v.isoTimestamp()),
109
102
  title: $,
110
103
  description: $,
111
104
  media: v.optional(_url),
112
105
  });
113
- export const milestoneUpdate = v.partial(newMilestone, ["date"]);
114
- export const milestone = v.object({ ...newMilestone.entries, id: milestoneId });
115
- export const newProgram = v.object({
106
+ export const milestone_update = v.partial(milestone_new, ["date"]);
107
+ export const milestone = v.object({
108
+ ...milestone_new.entries,
109
+ id: milestone_id,
110
+ });
111
+ export const program_new = v.object({
116
112
  title: $,
117
113
  description: $,
118
114
  banner: v.optional(_url),
119
115
  /** null unsets target */
120
116
  targetRaise: v.nullish(amnt),
121
- milestones: v.pipe(v.array(newMilestone), v.maxLength(24)),
117
+ milestones: v.pipe(v.array(milestone_new), v.maxLength(24)),
122
118
  });
123
119
  export const program = v.object({
124
- ...v.omit(newProgram, ["milestones"]).entries,
120
+ ...v.omit(program_new, ["milestones"]).entries,
125
121
  /** in USD */
126
122
  totalDonations: v.optional(v.number()),
127
- id: programId,
123
+ id: program_id,
128
124
  });
129
- export const programUpdate = v.partial(v.omit(newProgram, ["milestones"]));
130
- export const mediaUrl = v.pipe($, v.url());
125
+ export const program_update = v.partial(v.omit(program_new, ["milestones"]));
126
+ export const media_url = v.pipe($, v.url());
131
127
  /**
132
128
  * so that media is automatically sorted by date
133
129
  * @see https://github.com/segmentio/ksuid
134
130
  * */
135
- export const mediaKsuid = $req; // base62;
136
- export const mediaTypes = ["album", "article", "video"];
137
- export const mediaType = v.picklist(mediaTypes);
138
- export const mediaUpdate = v.object({
139
- url: v.optional(mediaUrl),
131
+ export const media_ksuid = $req; // base62;
132
+ export const media_types = ["album", "article", "video"];
133
+ export const media_type = v.picklist(media_types);
134
+ export const media_update = v.object({
135
+ url: v.optional(media_url),
140
136
  featured: v.optional(v.boolean()),
141
137
  });
142
- export const mediaQueryParams = v.object({
143
- type: v.optional(mediaType),
144
- nextPageKey: v.optional(v.pipe($, v.base64())),
138
+ export const media_search = v.object({
139
+ type: v.optional(media_type),
140
+ next: v.optional(v.pipe($, v.base64())),
145
141
  featured: v.optional(v.pipe($, v.transform((x) => Boolean(x)), v.boolean())),
146
142
  limit: v.optional(v.pipe(v.string(), v.transform((x) => +x), int_gte1)),
147
143
  });
package/package.json CHANGED
@@ -1,9 +1,14 @@
1
1
  {
2
2
  "name": "@better-giving/endowment",
3
- "version": "2.0.6",
3
+ "version": "3.0.0",
4
+ "dependencies": {
5
+ "ksuid": "3.0.0"
6
+ },
4
7
  "peerDependencies": {
5
8
  "@better-giving/schemas": "1.2.2",
6
9
  "@better-giving/types": "1.1.8",
10
+ "@better-giving/db": "1.0.11",
11
+ "@aws-sdk/lib-dynamodb": "3.485.0",
7
12
  "valibot": "0.42.0"
8
13
  },
9
14
  "devDependencies": {
@@ -17,7 +17,8 @@ import {
17
17
  pick,
18
18
  pipe,
19
19
  } from "valibot";
20
- import { $, type Environment, csvStrs, endowment } from "./schema.mjs";
20
+ import { $, csvStrs, npo } from "./schema.mjs";
21
+ import type { Environment } from "@better-giving/types/list";
21
22
 
22
23
  const boolCsv = pipe(
23
24
  csvStrs,
@@ -31,7 +32,7 @@ export const cloudsearchEndowFields = object({
31
32
  });
32
33
 
33
34
  export const cloudsearchEndow = object({
34
- ...pick(endowment, [
35
+ ...pick(npo, [
35
36
  "card_img",
36
37
  "name",
37
38
  "tagline",