@better-giving/endowment 1.0.8 → 1.0.10

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.
@@ -1,6 +1,6 @@
1
1
  import type { ToDoc, ToHitFields, ToUpdate } from "@better-giving/types/cloudsearch";
2
2
  import type { Endow, Environment } from "./db.mjs";
3
- export type Fields = Pick<Endow.DBRecord, "card_img" | "name" | "tagline" | "hq_country" | "sdgs" | "active_in_countries" | "endow_designation" | "registration_number" | "kyc_donors_only" | "claimed" | "env" | "id" | "published" | "fund_opt_in"> & {
3
+ export type Fields = Pick<Endow.DbRecord, "card_img" | "name" | "tagline" | "hq_country" | "sdgs" | "active_in_countries" | "endow_designation" | "registration_number" | "kyc_donors_only" | "claimed" | "env" | "id" | "published" | "fund_opt_in"> & {
4
4
  contributions_total: number;
5
5
  contributions_count: number;
6
6
  };
package/dist/db.d.mts CHANGED
@@ -1,5 +1,9 @@
1
- import type { EndowId, Endowment as EndowmentShape, Environment, Milestone as MilestoneShape, MilestoneId, Program as ProgramShape, ProgramId } from "./schema.mjs";
1
+ import type { EndowId, Endowment as EndowmentShape, Environment, MediaId, MediaType, Milestone as MilestoneShape, MilestoneId, Program as ProgramShape, ProgramId } from "./schema.mjs";
2
2
  export type { EndowId, SocialMediaURLs, Allocation, Increment, EndowDesignation, Environment, ProgramId, } from "./schema.mjs";
3
+ export declare const endowGsi: {
4
+ readonly regnumEnv: "regnum-env-gsi";
5
+ readonly slugEnv: "slug-env-gsi";
6
+ };
3
7
  export declare namespace EndowCount {
4
8
  interface Keys {
5
9
  PK: "Count";
@@ -25,19 +29,20 @@ export declare namespace Endow {
25
29
  splitLiqPct?: number;
26
30
  /** @deprecated */
27
31
  splitFixed?: boolean;
32
+ /** @deprecated */
28
33
  sfCompounded?: boolean;
29
34
  };
30
- type DBRecord = Keys & NonKeyAttributes;
35
+ type DbRecord = Keys & NonKeyAttributes;
31
36
  }
32
37
  export declare namespace RegNumEnvGsi {
33
- type Name = "regnum-env-gsi";
38
+ type Name = typeof endowGsi.regnumEnv;
34
39
  type Keys = Pick<Endow.NonKeyAttributes, "registration_number" | "env">;
35
- type DBRecord = Keys & Endow.Keys & Pick<Endow.NonKeyAttributes, "claimed" | "name" | "hq_country" | "id">;
40
+ type DbRecord = Keys & Endow.Keys & Pick<Endow.NonKeyAttributes, "claimed" | "name" | "hq_country" | "id">;
36
41
  }
37
42
  export declare namespace SlugEnvGsi {
38
- type Name = "slug-env-gsi";
43
+ type Name = typeof endowGsi.slugEnv;
39
44
  type Keys = Pick<Endow.NonKeyAttributes, "slug" | "env">;
40
- type DBRecord = Endow.DBRecord;
45
+ type DbRecord = Endow.DbRecord;
41
46
  }
42
47
  export declare namespace Program {
43
48
  type Keys = {
@@ -48,7 +53,7 @@ export declare namespace Program {
48
53
  /** in USD */
49
54
  totalDonations?: number;
50
55
  };
51
- export type DBRecord = Keys & NonKeyAttributes;
56
+ export type DbRecord = Keys & NonKeyAttributes;
52
57
  export {};
53
58
  }
54
59
  export declare namespace Milestone {
@@ -56,6 +61,35 @@ export declare namespace Milestone {
56
61
  PK: `Prog#${string}#${Environment}`;
57
62
  SK: `Mile#${MilestoneId}`;
58
63
  };
59
- export type DBRecord = Keys & MilestoneShape;
64
+ export type DbRecord = Keys & MilestoneShape;
60
65
  export {};
61
66
  }
67
+ export declare const mediaGsi: {
68
+ readonly 1: "gsi1";
69
+ };
70
+ export declare namespace Media {
71
+ type Keys = {
72
+ PK: `Endow#${EndowId}#${Environment}`;
73
+ SK: `Media#${MediaId}`;
74
+ };
75
+ /** "0" - featured (goes before 1), "1" - not-featured */
76
+ type FeaturedFlag = "0" | "1";
77
+ type NonKeyAttributes = {
78
+ id: MediaId;
79
+ gsi1PK: Keys["PK"];
80
+ gsi1SK: `MediaList#${FeaturedFlag}#${MediaId}#${MediaType}`;
81
+ /** iso string */
82
+ dateCreated: string;
83
+ };
84
+ type VideoAttributes = NonKeyAttributes & {
85
+ type: Extract<MediaType, "video">;
86
+ url: string;
87
+ };
88
+ type VideoDbRecord = Keys & VideoAttributes;
89
+ type DbRecord = VideoDbRecord;
90
+ namespace Gsi1 {
91
+ type Name = (typeof mediaGsi)[1];
92
+ type Keys = Pick<NonKeyAttributes, "gsi1PK" | "gsi1SK">;
93
+ type DbRecord = Keys & NonKeyAttributes;
94
+ }
95
+ }
package/dist/db.mjs CHANGED
@@ -1 +1,7 @@
1
- export {};
1
+ export const endowGsi = {
2
+ regnumEnv: "regnum-env-gsi",
3
+ slugEnv: "slug-env-gsi",
4
+ };
5
+ export const mediaGsi = {
6
+ 1: "gsi1",
7
+ };
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { Fields as FundItem } from "./cloudsearch.mjs";
2
2
  import type { Endow as NEndow } from "./db.mjs";
3
- export type { Allocation, DonateMethodId, EndowByEinParams, EndowDesignation, EndowQueryParam, EndowsQueryParams, EndowUpdate, Environment, Increment, Milestone, MilestoneUpdate, NewMilestone, NewProgram, Program, ProgramUpdate, SocialMediaURLs, UnSdgNum, } from "./schema.mjs";
3
+ export type { Allocation, DonateMethodId, EndowByEinParams, EndowDesignation, EndowQueryParam, EndowsQueryParams, EndowUpdate, Environment, Increment, Milestone, MilestoneUpdate, NewMilestone, NewProgram, Program, ProgramUpdate, SocialMediaURLs, UnSdgNum, MediaQueryParams, MediaType, } from "./schema.mjs";
4
4
  export type { FundItem };
5
- export type Endow = Pick<NEndow.DBRecord, "id" | "slug" | "active_in_countries" | "endow_designation" | "fiscal_sponsored" | "hide_bg_tip" | "hq_country" | "image" | "card_img" | "kyc_donors_only" | "logo" | "name" | "overview" | "published" | "registration_number" | "sdgs" | "social_media_urls" | "street_address" | "tagline" | "url" | "claimed" | "progDonationsAllowed" | "donateMethods" | "allocation" | "increments" | "receiptMsg">;
5
+ export type Endow = Pick<NEndow.DbRecord, "id" | "slug" | "active_in_countries" | "endow_designation" | "fiscal_sponsored" | "hide_bg_tip" | "hq_country" | "image" | "card_img" | "kyc_donors_only" | "logo" | "name" | "overview" | "published" | "registration_number" | "sdgs" | "social_media_urls" | "street_address" | "tagline" | "url" | "claimed" | "progDonationsAllowed" | "donateMethods" | "allocation" | "increments" | "receiptMsg">;
package/dist/schema.d.mts CHANGED
@@ -727,3 +727,24 @@ export declare const programUpdate: Omit<Omit<import("valibot").ObjectSchema<{
727
727
  export type NewProgram = InferOutput<typeof newProgram>;
728
728
  export type Program = InferOutput<typeof program>;
729
729
  export type ProgramUpdate = InferOutput<typeof programUpdate>;
730
+ export declare const mediaUrl: import("valibot").SchemaWithPipe<[import("valibot").SchemaWithPipe<[import("valibot").StringSchema<undefined>, import("valibot").TrimAction]>, import("valibot").UrlAction<string, undefined>]>;
731
+ /**
732
+ * so that media is automatically sorted by date
733
+ * @see https://github.com/segmentio/ksuid
734
+ * */
735
+ export declare const mediaKsuid: import("valibot").SchemaWithPipe<[import("valibot").SchemaWithPipe<[import("valibot").StringSchema<undefined>, import("valibot").TrimAction]>, import("valibot").NonEmptyAction<string, undefined>]>;
736
+ export declare const mediaTypes: readonly ["album", "article", "video"];
737
+ export declare const mediaType: import("valibot").PicklistSchema<readonly ["album", "article", "video"], undefined>;
738
+ export type MediaType = InferOutput<typeof mediaType>;
739
+ export declare const mediaUpdate: import("valibot").ObjectSchema<{
740
+ readonly url: import("valibot").OptionalSchema<import("valibot").SchemaWithPipe<[import("valibot").SchemaWithPipe<[import("valibot").StringSchema<undefined>, import("valibot").TrimAction]>, import("valibot").UrlAction<string, undefined>]>, never>;
741
+ readonly featured: import("valibot").OptionalSchema<import("valibot").BooleanSchema<undefined>, never>;
742
+ }, undefined>;
743
+ export type MediaId = InferOutput<typeof mediaKsuid>;
744
+ export declare const mediaQueryParams: import("valibot").ObjectSchema<{
745
+ readonly type: import("valibot").PicklistSchema<readonly ["album", "article", "video"], undefined>;
746
+ readonly nextPageKey: import("valibot").OptionalSchema<import("valibot").SchemaWithPipe<[import("valibot").SchemaWithPipe<[import("valibot").StringSchema<undefined>, import("valibot").TrimAction]>, import("valibot").Base64Action<string, undefined>]>, never>;
747
+ readonly featured: import("valibot").OptionalSchema<import("valibot").SchemaWithPipe<[import("valibot").SchemaWithPipe<[import("valibot").StringSchema<undefined>, import("valibot").TrimAction]>, import("valibot").TransformAction<string, boolean>, import("valibot").BooleanSchema<undefined>]>, never>;
748
+ readonly limit: import("valibot").OptionalSchema<import("valibot").SchemaWithPipe<[import("valibot").StringSchema<undefined>, import("valibot").TransformAction<string, number>, import("valibot").NumberSchema<undefined>, import("valibot").IntegerAction<number, undefined>, import("valibot").MinValueAction<number, 1, undefined>]>, never>;
749
+ }, undefined>;
750
+ export type MediaQueryParams = InferInput<typeof mediaQueryParams>;
package/dist/schema.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { env, orgDesignation, unSdgNum } from "@better-giving/schemas";
2
2
  export { orgDesignation as endowDesignation, env, unSdgNum };
3
- import { url, array, boolean, check, custom, excludes, integer, isoDate, keyof, lazy, maxLength, maxValue, minLength, minValue, nonEmpty, nullish, number, object, omit, optional, partial, picklist, pipe, regex, string, transform, trim, uuid, startsWith, } from "valibot";
3
+ import { url, array, base64, boolean, check, custom, excludes, integer, isoDate, keyof, lazy, maxLength, maxValue, minLength, minValue, nonEmpty, nullish, number, object, omit, optional, partial, picklist, pipe, regex, startsWith, string, transform, trim, uuid, } from "valibot";
4
4
  export const str = pipe(string(), trim());
5
5
  const pct = pipe(number(), integer(), minValue(0), maxValue(100));
6
6
  export const allocation = pipe(object({
@@ -131,3 +131,21 @@ export const program = object({
131
131
  id: programId,
132
132
  });
133
133
  export const programUpdate = partial(omit(newProgram, ["milestones"]));
134
+ export const mediaUrl = pipe(str, url());
135
+ /**
136
+ * so that media is automatically sorted by date
137
+ * @see https://github.com/segmentio/ksuid
138
+ * */
139
+ export const mediaKsuid = pipe(str, nonEmpty() /** base62? */);
140
+ export const mediaTypes = ["album", "article", "video"];
141
+ export const mediaType = picklist(mediaTypes);
142
+ export const mediaUpdate = object({
143
+ url: optional(mediaUrl),
144
+ featured: optional(boolean()),
145
+ });
146
+ export const mediaQueryParams = object({
147
+ type: mediaType,
148
+ nextPageKey: optional(pipe(str, base64())),
149
+ featured: optional(pipe(str, transform((x) => Boolean(x)), boolean())),
150
+ limit: optional(pipe(string(), transform((x) => +x), number(), integer(), minValue(1))),
151
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@better-giving/endowment",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "peerDependencies": {
5
5
  "@better-giving/schemas": "1.0.1",
6
6
  "@better-giving/types": "1.0.1"
@@ -6,7 +6,7 @@ import type {
6
6
  import type { Endow, Environment } from "./db.mjs";
7
7
 
8
8
  export type Fields = Pick<
9
- Endow.DBRecord,
9
+ Endow.DbRecord,
10
10
  //card UI attribures
11
11
  | "card_img"
12
12
  | "name"
package/src/db.mts CHANGED
@@ -2,6 +2,8 @@ import type {
2
2
  EndowId,
3
3
  Endowment as EndowmentShape,
4
4
  Environment,
5
+ MediaId,
6
+ MediaType,
5
7
  Milestone as MilestoneShape,
6
8
  MilestoneId,
7
9
  Program as ProgramShape,
@@ -17,6 +19,11 @@ export type {
17
19
  ProgramId,
18
20
  } from "./schema.mjs";
19
21
 
22
+ export const endowGsi = {
23
+ regnumEnv: "regnum-env-gsi",
24
+ slugEnv: "slug-env-gsi",
25
+ } as const;
26
+
20
27
  export namespace EndowCount {
21
28
  export interface Keys {
22
29
  PK: "Count";
@@ -45,27 +52,28 @@ export namespace Endow {
45
52
  splitLiqPct?: number;
46
53
  /** @deprecated */
47
54
  splitFixed?: boolean;
55
+ /** @deprecated */
48
56
  sfCompounded?: boolean;
49
57
  };
50
58
 
51
- export type DBRecord = Keys & NonKeyAttributes;
59
+ export type DbRecord = Keys & NonKeyAttributes;
52
60
  }
53
61
 
54
62
  export namespace RegNumEnvGsi {
55
- export type Name = "regnum-env-gsi";
63
+ export type Name = typeof endowGsi.regnumEnv;
56
64
  export type Keys = Pick<
57
65
  Endow.NonKeyAttributes,
58
66
  "registration_number" | "env"
59
67
  >;
60
- export type DBRecord = Keys &
68
+ export type DbRecord = Keys &
61
69
  Endow.Keys &
62
70
  Pick<Endow.NonKeyAttributes, "claimed" | "name" | "hq_country" | "id">;
63
71
  }
64
72
 
65
73
  export namespace SlugEnvGsi {
66
- export type Name = "slug-env-gsi";
74
+ export type Name = typeof endowGsi.slugEnv;
67
75
  export type Keys = Pick<Endow.NonKeyAttributes, "slug" | "env">;
68
- export type DBRecord = Endow.DBRecord; //all attributes are copied to this index
76
+ export type DbRecord = Endow.DbRecord; //all attributes are copied to this index
69
77
  }
70
78
 
71
79
  export namespace Program {
@@ -78,7 +86,7 @@ export namespace Program {
78
86
  /** in USD */
79
87
  totalDonations?: number;
80
88
  };
81
- export type DBRecord = Keys & NonKeyAttributes;
89
+ export type DbRecord = Keys & NonKeyAttributes;
82
90
  }
83
91
 
84
92
  export namespace Milestone {
@@ -86,5 +94,39 @@ export namespace Milestone {
86
94
  PK: `Prog#${string}#${Environment}`;
87
95
  SK: `Mile#${MilestoneId}`;
88
96
  };
89
- export type DBRecord = Keys & MilestoneShape;
97
+ export type DbRecord = Keys & MilestoneShape;
98
+ }
99
+
100
+ export const mediaGsi = {
101
+ 1: "gsi1",
102
+ } as const;
103
+ export namespace Media {
104
+ export type Keys = {
105
+ PK: `Endow#${EndowId}#${Environment}`;
106
+ SK: `Media#${MediaId}`;
107
+ };
108
+
109
+ /** "0" - featured (goes before 1), "1" - not-featured */
110
+ export type FeaturedFlag = "0" | "1";
111
+ export type NonKeyAttributes = {
112
+ id: MediaId;
113
+ gsi1PK: Keys["PK"];
114
+ gsi1SK: `MediaList#${FeaturedFlag}#${MediaId}#${MediaType}`;
115
+ /** iso string */
116
+ dateCreated: string;
117
+ };
118
+
119
+ export type VideoAttributes = NonKeyAttributes & {
120
+ type: Extract<MediaType, "video">;
121
+ url: string;
122
+ };
123
+
124
+ export type VideoDbRecord = Keys & VideoAttributes;
125
+ export type DbRecord = VideoDbRecord; // | album | article
126
+
127
+ export namespace Gsi1 {
128
+ export type Name = (typeof mediaGsi)[1];
129
+ export type Keys = Pick<NonKeyAttributes, "gsi1PK" | "gsi1SK">;
130
+ export type DbRecord = Keys & NonKeyAttributes;
131
+ }
90
132
  }
package/src/index.mts CHANGED
@@ -18,11 +18,13 @@ export type {
18
18
  ProgramUpdate,
19
19
  SocialMediaURLs,
20
20
  UnSdgNum,
21
+ MediaQueryParams,
22
+ MediaType,
21
23
  } from "./schema.mjs";
22
24
  export type { FundItem };
23
25
 
24
26
  export type Endow = Pick<
25
- NEndow.DBRecord,
27
+ NEndow.DbRecord,
26
28
  | "id"
27
29
  | "slug"
28
30
  | "active_in_countries"
package/src/schema.mts CHANGED
@@ -10,6 +10,7 @@ import {
10
10
  type InferInput,
11
11
  type InferOutput,
12
12
  array,
13
+ base64,
13
14
  boolean,
14
15
  check,
15
16
  custom,
@@ -32,11 +33,11 @@ import {
32
33
  picklist,
33
34
  pipe,
34
35
  regex,
36
+ startsWith,
35
37
  string,
36
38
  transform,
37
39
  trim,
38
40
  uuid,
39
- startsWith,
40
41
  } from "valibot";
41
42
 
42
43
  export const str = pipe(string(), trim());
@@ -290,3 +291,42 @@ export const programUpdate = partial(omit(newProgram, ["milestones"]));
290
291
  export type NewProgram = InferOutput<typeof newProgram>;
291
292
  export type Program = InferOutput<typeof program>;
292
293
  export type ProgramUpdate = InferOutput<typeof programUpdate>;
294
+
295
+ export const mediaUrl = pipe(str, url());
296
+ /**
297
+ * so that media is automatically sorted by date
298
+ * @see https://github.com/segmentio/ksuid
299
+ * */
300
+ export const mediaKsuid = pipe(str, nonEmpty() /** base62? */);
301
+ export const mediaTypes = ["album", "article", "video"] as const;
302
+ export const mediaType = picklist(mediaTypes);
303
+ export type MediaType = InferOutput<typeof mediaType>;
304
+
305
+ export const mediaUpdate = object({
306
+ url: optional(mediaUrl),
307
+ featured: optional(boolean()),
308
+ });
309
+
310
+ export type MediaId = InferOutput<typeof mediaKsuid>;
311
+
312
+ export const mediaQueryParams = object({
313
+ type: mediaType,
314
+ nextPageKey: optional(pipe(str, base64())),
315
+ featured: optional(
316
+ pipe(
317
+ str,
318
+ transform((x) => Boolean(x)),
319
+ boolean()
320
+ )
321
+ ),
322
+ limit: optional(
323
+ pipe(
324
+ string(),
325
+ transform((x) => +x),
326
+ number(),
327
+ integer(),
328
+ minValue(1)
329
+ )
330
+ ),
331
+ });
332
+ export type MediaQueryParams = InferInput<typeof mediaQueryParams>;