@better-giving/endowment 5.0.0 → 6.1.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/db.d.mts CHANGED
@@ -1,10 +1,11 @@
1
1
  import { Db, type TxItems, type TxType, type UpdateComps } from "@better-giving/db";
2
- import type { IMedia, IMediaPage, INpoReferredBy, INpoWithRegNum, INpoWithRid, TBinFlag, TNpoDbKeys, TNpoDbProjectedTo } from "./interfaces.mjs";
2
+ import type { IMedia, IMediaPage, INpoReferredBy, INpoWithKeyword, INpoWithRegNum, INpoWithRid, TBinFlag, TNpoDbKeys, TNpoDbProjectedTo } from "./interfaces.mjs";
3
3
  import type { IMediaSearchObj, IMediaUpdate, IMilestone, IMilestoneNew, IMilestoneUpdate, INpo, INpoUpdate, IProgram, IProgramDb, IProgramNew, IProgramUpdate, TMediaType } from "./schema.mjs";
4
4
  export declare class NpoDb extends Db {
5
5
  static readonly table = "endowments_v3";
6
6
  static readonly slug_env_gsi: "slug-env-gsi";
7
7
  static readonly regnum_env_gsi: "regnum-env-gsi";
8
+ static readonly keyword_env_gsi: "keyword-env-gsi";
8
9
  key_npo(id: number): {
9
10
  PK: string;
10
11
  SK: import("@better-giving/types/list").Environment;
@@ -25,11 +26,11 @@ export declare class NpoDb extends Db {
25
26
  PK: string;
26
27
  SK: string;
27
28
  };
28
- gsi1_npo(id: string): {
29
+ gsi1_npo_ref_by_key(id: string): {
29
30
  gsi1PK: string;
30
31
  gsi1SK: import("@better-giving/types/list").Environment;
31
32
  };
32
- gsi2_npo(id: string): {
33
+ gsi2_npo_w_rid_key(id: string): {
33
34
  gsi2PK: string;
34
35
  gsi2SK: string;
35
36
  };
@@ -42,6 +43,7 @@ export declare class NpoDb extends Db {
42
43
  npo_media(npo: number, opts: IMediaSearchObj): Promise<IMediaPage>;
43
44
  npo_referred_by(id: string): Promise<INpoReferredBy[]>;
44
45
  npo_with_rid(id: string): Promise<INpoWithRid | undefined>;
46
+ npo_with_keyword(keyword: string, env?: import("@better-giving/types/list").Environment): Promise<INpoWithKeyword | undefined>;
45
47
  npo_with_regnum(regnum: string, country?: string): Promise<INpoWithRegNum | undefined>;
46
48
  npo_record(data: INpo): {
47
49
  gsi2PK?: string | undefined;
@@ -51,6 +53,7 @@ export declare class NpoDb extends Db {
51
53
  id: number;
52
54
  env: "staging" | "production";
53
55
  slug?: string | undefined;
56
+ keyword?: string | undefined;
54
57
  registration_number: string;
55
58
  name: string;
56
59
  endow_designation: "Charity" | "Religious Organization" | "University" | "Hospital" | "Other";
@@ -72,7 +75,7 @@ export declare class NpoDb extends Db {
72
75
  tiktok?: string | undefined;
73
76
  };
74
77
  url?: string | undefined;
75
- sdgs: (2 | 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17)[];
78
+ sdgs: (2 | 1 | 10 | 5 | 3 | 4 | 6 | 7 | 8 | 9 | 11 | 12 | 13 | 14 | 15 | 16 | 17)[];
76
79
  receiptMsg?: string | undefined;
77
80
  hide_bg_tip?: boolean | undefined;
78
81
  published?: boolean | undefined;
package/dist/db.mjs CHANGED
@@ -9,6 +9,7 @@ export class NpoDb extends Db {
9
9
  static table = "endowments_v3";
10
10
  static slug_env_gsi = "slug-env-gsi";
11
11
  static regnum_env_gsi = "regnum-env-gsi";
12
+ static keyword_env_gsi = "keyword-env-gsi";
12
13
  key_npo(id) {
13
14
  return {
14
15
  PK: `Endow#${id}`,
@@ -39,13 +40,13 @@ export class NpoDb extends Db {
39
40
  SK: `Media#${ksuid}`,
40
41
  };
41
42
  }
42
- gsi1_npo(id) {
43
+ gsi1_npo_ref_by_key(id) {
43
44
  return {
44
45
  gsi1PK: `ReferredBy#${id}`,
45
46
  gsi1SK: this.env,
46
47
  };
47
48
  }
48
- gsi2_npo(id) {
49
+ gsi2_npo_w_rid_key(id) {
49
50
  return {
50
51
  gsi2PK: `Rid#${id}`,
51
52
  gsi2SK: `Rid#${id}`,
@@ -109,7 +110,7 @@ export class NpoDb extends Db {
109
110
  IndexName: "gsi1",
110
111
  KeyConditionExpression: "#pk = :pk",
111
112
  ExpressionAttributeValues: {
112
- ":pk": this.gsi1_npo(id).gsi1PK,
113
+ ":pk": this.gsi1_npo_ref_by_key(id).gsi1PK,
113
114
  },
114
115
  ExpressionAttributeNames: { "#pk": "gsi1PK" },
115
116
  });
@@ -122,7 +123,26 @@ export class NpoDb extends Db {
122
123
  IndexName: "gsi2",
123
124
  KeyConditionExpression: "gsi2PK = :pk",
124
125
  ExpressionAttributeValues: {
125
- ":pk": this.gsi2_npo(id).gsi2PK,
126
+ ":pk": this.gsi2_npo_w_rid_key(id).gsi2PK,
127
+ },
128
+ Limit: 1,
129
+ });
130
+ const { Items = [] } = await this.client.send(cmd);
131
+ const i = Items[0];
132
+ return i && this.sans_keys(i);
133
+ }
134
+ async npo_with_keyword(keyword, env = this.env) {
135
+ const cmd = new QueryCommand({
136
+ TableName: NpoDb.table,
137
+ IndexName: NpoDb.keyword_env_gsi,
138
+ KeyConditionExpression: "#kw = :kw AND #env = :env",
139
+ ExpressionAttributeNames: {
140
+ "#kw": "keyword",
141
+ "#env": "env",
142
+ },
143
+ ExpressionAttributeValues: {
144
+ ":kw": keyword,
145
+ ":env": env,
126
146
  },
127
147
  Limit: 1,
128
148
  });
@@ -156,8 +176,8 @@ export class NpoDb extends Db {
156
176
  return {
157
177
  ...this.key_npo(data.id),
158
178
  ...data,
159
- ...(data.referrer ? this.gsi1_npo(data.referrer) : {}),
160
- ...(data.referral_id ? this.gsi2_npo(data.referral_id) : {}),
179
+ ...(data.referrer ? this.gsi1_npo_ref_by_key(data.referrer) : {}),
180
+ ...(data.referral_id ? this.gsi2_npo_w_rid_key(data.referral_id) : {}),
161
181
  };
162
182
  }
163
183
  npo_prog_record(npo, data) {
@@ -0,0 +1,7 @@
1
+ import type { TId } from "./interfaces.mjs";
2
+ export declare const is_id: (id: TId) => id is {
3
+ id: number | string;
4
+ };
5
+ export declare const is_slug: (id: TId) => id is {
6
+ slug: string;
7
+ };
@@ -0,0 +1,6 @@
1
+ export const is_id = (id) => {
2
+ return "id" in id;
3
+ };
4
+ export const is_slug = (id) => {
5
+ return "slug" in id;
6
+ };
@@ -18,6 +18,8 @@ export interface INpoReferredBy extends Ensure<INpo, "referrer" | "referrer_expi
18
18
  }
19
19
  export interface INpoWithRid extends Ensure<INpo, "referral_id"> {
20
20
  }
21
+ export interface INpoWithKeyword extends Ensure<INpo, "keyword"> {
22
+ }
21
23
  export interface INpoWithRegNum extends Pick<INpo, "registration_number" | "env" | "claimed" | "name" | "hq_country" | "id"> {
22
24
  }
23
25
  export interface IMedia extends Required<IMediaUpdate> {
package/dist/npo.mjs CHANGED
@@ -18,6 +18,7 @@ export const npo_fields = {
18
18
  tagline: "",
19
19
  url: "",
20
20
  slug: "",
21
+ keyword: "",
21
22
  claimed: "",
22
23
  card_img: "",
23
24
  progDonationsAllowed: "",