@better-giving/endowment 1.0.9 → 1.0.11

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,6 +1,6 @@
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 gsi: {
3
+ export declare const endowGsi: {
4
4
  readonly regnumEnv: "regnum-env-gsi";
5
5
  readonly slugEnv: "slug-env-gsi";
6
6
  };
@@ -32,17 +32,17 @@ export declare namespace Endow {
32
32
  /** @deprecated */
33
33
  sfCompounded?: boolean;
34
34
  };
35
- type DBRecord = Keys & NonKeyAttributes;
35
+ type DbRecord = Keys & NonKeyAttributes;
36
36
  }
37
37
  export declare namespace RegNumEnvGsi {
38
- type Name = typeof gsi.regnumEnv;
38
+ type Name = typeof endowGsi.regnumEnv;
39
39
  type Keys = Pick<Endow.NonKeyAttributes, "registration_number" | "env">;
40
- 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">;
41
41
  }
42
42
  export declare namespace SlugEnvGsi {
43
- type Name = typeof gsi.slugEnv;
43
+ type Name = typeof endowGsi.slugEnv;
44
44
  type Keys = Pick<Endow.NonKeyAttributes, "slug" | "env">;
45
- type DBRecord = Endow.DBRecord;
45
+ type DbRecord = Endow.DbRecord;
46
46
  }
47
47
  export declare namespace Program {
48
48
  type Keys = {
@@ -53,7 +53,7 @@ export declare namespace Program {
53
53
  /** in USD */
54
54
  totalDonations?: number;
55
55
  };
56
- export type DBRecord = Keys & NonKeyAttributes;
56
+ export type DbRecord = Keys & NonKeyAttributes;
57
57
  export {};
58
58
  }
59
59
  export declare namespace Milestone {
@@ -61,6 +61,35 @@ export declare namespace Milestone {
61
61
  PK: `Prog#${string}#${Environment}`;
62
62
  SK: `Mile#${MilestoneId}`;
63
63
  };
64
- export type DBRecord = Keys & MilestoneShape;
64
+ export type DbRecord = Keys & MilestoneShape;
65
65
  export {};
66
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,4 +1,7 @@
1
- export const gsi = {
1
+ export const endowGsi = {
2
2
  regnumEnv: "regnum-env-gsi",
3
3
  slugEnv: "slug-env-gsi",
4
4
  };
5
+ export const mediaGsi = {
6
+ 1: "gsi1",
7
+ };
package/dist/index.d.mts CHANGED
@@ -1,5 +1,13 @@
1
1
  import type { Fields as FundItem } from "./cloudsearch.mjs";
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";
2
+ import type { Media, 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, 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">;
6
+ /** web-app format */
7
+ export type TMedia = Omit<Media.DbRecord, "PK" | "SK" | "gsi1PK" | "gsi1SK"> & {
8
+ featured: boolean;
9
+ };
10
+ export type MediaPage = {
11
+ items: TMedia[];
12
+ nextPageKey?: string;
13
+ };
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, startsWith, string, transform, trim, uuid, } 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.9",
3
+ "version": "1.0.11",
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/index.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { Fields as FundItem } from "./cloudsearch.mjs";
2
- import type { Endow as NEndow } from "./db.mjs";
2
+ import type { Media, Endow as NEndow } from "./db.mjs";
3
3
  export type {
4
4
  Allocation,
5
5
  DonateMethodId,
@@ -52,3 +52,13 @@ export type Endow = Pick<
52
52
  | "increments"
53
53
  | "receiptMsg"
54
54
  >;
55
+
56
+ /** web-app format */
57
+ export type TMedia = Omit<Media.DbRecord, "PK" | "SK" | "gsi1PK" | "gsi1SK"> & {
58
+ featured: boolean;
59
+ };
60
+
61
+ export type MediaPage = {
62
+ items: TMedia[];
63
+ nextPageKey?: string;
64
+ };