@better-giving/endowment 4.0.6 → 4.0.8

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,7 +1,7 @@
1
1
  import { $int_gte1, org_designation, unsdg_num } from "@better-giving/schemas";
2
2
  import { array, boolean, keyof, mapItems, number, object, optional, pick, pipe, } from "valibot";
3
- import { $, csvStrs, npo } from "./schema.mjs";
4
- const boolCsv = pipe(csvStrs, mapItems((x) => x === "true"), array(boolean()));
3
+ import { $, csv_strs, npo } from "./schema.mjs";
4
+ const boolCsv = pipe(csv_strs, mapItems((x) => x === "true"), array(boolean()));
5
5
  export const cloudsearchEndowFields = object({
6
6
  contributions_total: number(),
7
7
  contributions_count: number(),
@@ -31,11 +31,11 @@ export const cloudSearchEndowFields = keyof(cloudsearchEndow);
31
31
  export const endowsQueryParams = object({
32
32
  query: optional($),
33
33
  page: optional($int_gte1),
34
- endow_designation: optional(pipe(csvStrs, array(org_designation))),
35
- sdgs: optional(pipe(csvStrs, mapItems((x) => +x), array(unsdg_num))),
34
+ endow_designation: optional(pipe(csv_strs, array(org_designation))),
35
+ sdgs: optional(pipe(csv_strs, mapItems((x) => +x), array(unsdg_num))),
36
36
  kyc_only: optional(boolCsv),
37
37
  fund_opt_in: optional(boolCsv),
38
38
  claimed: optional(boolCsv),
39
- countries: optional(pipe(csvStrs, array($))),
40
- fields: optional(pipe(csvStrs, array(cloudSearchEndowFields))),
39
+ countries: optional(pipe(csv_strs, array($))),
40
+ fields: optional(pipe(csv_strs, array(cloudSearchEndowFields))),
41
41
  });
package/dist/db.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Db, type UpdateComps } from "@better-giving/db";
2
2
  import type { IMedia, IMediaPage, INpoReferredBy, INpoWithRegNum, INpoWithRid, TBinFlag, TNpoDbKeys, TNpoDbProjectedTo } from "./interfaces.mjs";
3
- import type { IMediaSearchObj, IMilestone, IMilestoneUpdate, INpo, INpoUpdate, IProgram, IProgramDb, IProgramNew, IProgramUpdate, TMediaType } from "./schema.mjs";
3
+ import type { IMediaSearchObj, IMediaUpdate, IMilestone, IMilestoneUpdate, INpo, INpoUpdate, IProgram, IProgramDb, IProgramNew, IProgramUpdate, TMediaType } from "./schema.mjs";
4
4
  export declare class NpoDb extends Db {
5
5
  static readonly name = "endowments_v3";
6
6
  static readonly slug_env_gsi: "slug-env-gsi";
@@ -130,6 +130,7 @@ export declare class NpoDb extends Db {
130
130
  };
131
131
  npo_med_put(npo: number, url: string): Promise<string>;
132
132
  npo_med(npo: number, mid: string): Promise<IMedia | undefined>;
133
+ npo_med_update(npo: number, prev: IMedia, update: IMediaUpdate): Promise<Record<string, any>>;
133
134
  npo_med_delete(npo: number, mid: string): Promise<import("@aws-sdk/lib-dynamodb").DeleteCommandOutput>;
134
135
  npo<T extends TNpoDbKeys[]>(id: string | number, fields?: T): Promise<TNpoDbProjectedTo<T> | undefined>;
135
136
  npo_update_comps({ target, slug, social_media_urls, ...update }: INpoUpdate): UpdateComps;
package/dist/db.mjs CHANGED
@@ -185,6 +185,21 @@ export class NpoDb extends Db {
185
185
  const { Item: i } = await this.client.send(cmd);
186
186
  return i && to_imedia(i);
187
187
  }
188
+ async npo_med_update(npo, prev, update) {
189
+ const new_sk = med_sk(prev.id, prev.type, (update.featured ?? prev.featured) ? "0" : "1");
190
+ const cmd = new UpdateCommand({
191
+ TableName: NpoDb.name,
192
+ Key: this.key_npo_med(prev.id, npo),
193
+ UpdateExpression: "SET #url = :url, gsi1SK = :gsi1SK",
194
+ ExpressionAttributeNames: { "#url": "url" },
195
+ ExpressionAttributeValues: {
196
+ ":url": update.url ?? prev.url,
197
+ ":gsi1SK": new_sk,
198
+ },
199
+ ReturnValues: "ALL_NEW",
200
+ });
201
+ return this.client.send(cmd).then((res) => res.Attributes ?? {});
202
+ }
188
203
  async npo_med_delete(npo, mid) {
189
204
  const cmd = new DeleteCommand({
190
205
  TableName: NpoDb.name,
package/dist/schema.d.mts CHANGED
@@ -1,9 +1,8 @@
1
- import { $, $int_gte1, $req, $req_num_gt0, donate_method_id, donate_method_ids, env, https_url, int_gte1, org_designation, slug, unsdg_num } from "@better-giving/schemas";
2
- export { org_designation as endow_designation, env, unsdg_num, donate_method_id, donate_method_ids, $int_gte1, int_gte1, $, $req_num_gt0, $req, slug, https_url };
1
+ export { $, $req, $req_num_gt0, donate_method_id, env, https_url, int_gte1, $int_gte1, org_designation, slug, unsdg_num, } from "@better-giving/schemas";
3
2
  import * as v from "valibot";
4
3
  export declare const min_payout_amount = 50;
5
4
  export declare const csv: v.LazySchema<v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]> | v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.RegexAction<string, "invalid csv">]>>;
6
- export declare const csvStrs: 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[]>]>;
5
+ export declare const csv_strs: 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[]>]>;
7
6
  export declare const allocation: v.SchemaWithPipe<[v.ObjectSchema<{
8
7
  readonly cash: v.SchemaWithPipe<[v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>, v.MaxValueAction<number, 100, undefined>]>;
9
8
  readonly liq: v.SchemaWithPipe<[v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>, v.MaxValueAction<number, 100, undefined>]>;
@@ -810,7 +809,7 @@ export declare const media_search: v.ObjectSchema<{
810
809
  readonly type: v.OptionalSchema<v.PicklistSchema<readonly ["album", "article", "video"], undefined>, never>;
811
810
  readonly next: v.OptionalSchema<v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.Base64Action<string, undefined>]>, never>;
812
811
  readonly featured: v.OptionalSchema<v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.TransformAction<string, boolean>, v.BooleanSchema<undefined>]>, never>;
813
- 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>;
812
+ readonly limit: v.OptionalSchema<v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.TransformAction<string, number>, v.SchemaWithPipe<[v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>]>]>, never>;
814
813
  }, undefined>;
815
814
  export interface IMediaSearch extends v.InferInput<typeof media_search> {
816
815
  }
package/dist/schema.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { $, $int_gte1, $req, $req_num_gt0, donate_method_id, donate_method_ids, env, https_url, int_gte1, org_designation, slug, unsdg_num, } from "@better-giving/schemas";
2
- export { org_designation as endow_designation, env, unsdg_num, donate_method_id, donate_method_ids, $int_gte1, int_gte1, $, $req_num_gt0, $req, slug, https_url };
1
+ import { $, $int_gte1, $req, $req_num_gt0, donate_method_id, env, https_url, int_gte1, org_designation, slug, unsdg_num, } from "@better-giving/schemas";
2
+ export { $, $req, $req_num_gt0, donate_method_id, env, https_url, int_gte1, $int_gte1, org_designation, slug, unsdg_num, } from "@better-giving/schemas";
3
3
  import * as v from "valibot";
4
4
  export const min_payout_amount = 50;
5
5
  export const csv = v.lazy((x) => {
@@ -7,7 +7,7 @@ export const csv = v.lazy((x) => {
7
7
  return $;
8
8
  return v.pipe($, v.regex(/^[^,]+(?:,[^,]+)*$/, "invalid csv"));
9
9
  });
10
- export const csvStrs = v.pipe(csv, v.transform((x) => x.split(",")), v.filterItems((x) => x.length > 0));
10
+ export const csv_strs = v.pipe(csv, v.transform((x) => x.split(",")), v.filterItems((x) => x.length > 0));
11
11
  const pct = v.pipe(v.number(), v.integer(), v.minValue(0), v.maxValue(100));
12
12
  export const allocation = v.pipe(v.object({
13
13
  cash: pct,
@@ -85,7 +85,7 @@ export const npo_update = v.partial(v.omit(npo, ["id", "claimed", "kyc_donors_on
85
85
  export const npo_fields = v.keyof(npo);
86
86
  /** for ein path, only fields in reg-num/env gsi is available */
87
87
  export const npo_search = v.object({
88
- fields: v.optional(v.pipe(csvStrs, v.array(npo_fields))),
88
+ fields: v.optional(v.pipe(csv_strs, v.array(npo_fields))),
89
89
  });
90
90
  const amnt = v.pipe(v.number(), v.minValue(0));
91
91
  export const program_id = v.pipe($, v.uuid());
@@ -132,5 +132,5 @@ export const media_search = v.object({
132
132
  type: v.optional(media_type),
133
133
  next: v.optional(v.pipe($, v.base64())),
134
134
  featured: v.optional(v.pipe($, v.transform((x) => Boolean(x)), v.boolean())),
135
- limit: v.optional(v.pipe(v.string(), v.transform((x) => +x), int_gte1)),
135
+ limit: v.optional($int_gte1),
136
136
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@better-giving/endowment",
3
- "version": "4.0.6",
3
+ "version": "4.0.8",
4
4
  "dependencies": {
5
5
  "ksuid": "3.0.0"
6
6
  },
@@ -18,10 +18,10 @@ import {
18
18
  pick,
19
19
  pipe,
20
20
  } from "valibot";
21
- import { $, csvStrs, npo } from "./schema.mjs";
21
+ import { $, csv_strs, npo } from "./schema.mjs";
22
22
 
23
23
  const boolCsv = pipe(
24
- csvStrs,
24
+ csv_strs,
25
25
  mapItems((x) => x === "true"),
26
26
  array(boolean())
27
27
  );
@@ -58,10 +58,10 @@ export const cloudSearchEndowFields = keyof(cloudsearchEndow);
58
58
  export const endowsQueryParams = object({
59
59
  query: optional($),
60
60
  page: optional($int_gte1),
61
- endow_designation: optional(pipe(csvStrs, array(org_designation))),
61
+ endow_designation: optional(pipe(csv_strs, array(org_designation))),
62
62
  sdgs: optional(
63
63
  pipe(
64
- csvStrs,
64
+ csv_strs,
65
65
  mapItems((x) => +x),
66
66
  array(unsdg_num)
67
67
  )
@@ -69,8 +69,8 @@ export const endowsQueryParams = object({
69
69
  kyc_only: optional(boolCsv),
70
70
  fund_opt_in: optional(boolCsv),
71
71
  claimed: optional(boolCsv),
72
- countries: optional(pipe(csvStrs, array($))),
73
- fields: optional(pipe(csvStrs, array(cloudSearchEndowFields))),
72
+ countries: optional(pipe(csv_strs, array($))),
73
+ fields: optional(pipe(csv_strs, array(cloudSearchEndowFields))),
74
74
  });
75
75
 
76
76
  export interface CloudsearchEndowsQueryParamsObj
package/src/db.mts CHANGED
@@ -23,6 +23,7 @@ import { med_key_filter, med_sk, to_imedia } from "./media.mjs";
23
23
  import { projection } from "./npo.mjs";
24
24
  import type {
25
25
  IMediaSearchObj,
26
+ IMediaUpdate,
26
27
  IMilestone,
27
28
  IMilestoneUpdate,
28
29
  INpo,
@@ -244,6 +245,27 @@ export class NpoDb extends Db {
244
245
  return i && to_imedia(i);
245
246
  }
246
247
 
248
+ async npo_med_update(npo: number, prev: IMedia, update: IMediaUpdate) {
249
+ const new_sk = med_sk(
250
+ prev.id,
251
+ prev.type,
252
+ (update.featured ?? prev.featured) ? "0" : "1"
253
+ );
254
+
255
+ const cmd = new UpdateCommand({
256
+ TableName: NpoDb.name,
257
+ Key: this.key_npo_med(prev.id, npo),
258
+ UpdateExpression: "SET #url = :url, gsi1SK = :gsi1SK",
259
+ ExpressionAttributeNames: { "#url": "url" },
260
+ ExpressionAttributeValues: {
261
+ ":url": update.url ?? prev.url,
262
+ ":gsi1SK": new_sk,
263
+ },
264
+ ReturnValues: "ALL_NEW",
265
+ });
266
+ return this.client.send(cmd).then((res) => res.Attributes ?? {});
267
+ }
268
+
247
269
  async npo_med_delete(npo: number, mid: string) {
248
270
  const cmd = new DeleteCommand({
249
271
  TableName: NpoDb.name,
package/src/schema.mts CHANGED
@@ -4,7 +4,6 @@ import {
4
4
  $req,
5
5
  $req_num_gt0,
6
6
  donate_method_id,
7
- donate_method_ids,
8
7
  env,
9
8
  https_url,
10
9
  int_gte1,
@@ -13,19 +12,18 @@ import {
13
12
  unsdg_num,
14
13
  } from "@better-giving/schemas";
15
14
  export {
16
- org_designation as endow_designation,
17
- env,
18
- unsdg_num,
19
- donate_method_id,
20
- donate_method_ids,
21
- $int_gte1,
22
- int_gte1,
23
15
  $,
24
- $req_num_gt0,
25
16
  $req,
17
+ $req_num_gt0,
18
+ donate_method_id,
19
+ env,
20
+ https_url,
21
+ int_gte1,
22
+ $int_gte1,
23
+ org_designation,
26
24
  slug,
27
- https_url
28
- };
25
+ unsdg_num,
26
+ } from "@better-giving/schemas";
29
27
  import * as v from "valibot";
30
28
 
31
29
  export const min_payout_amount = 50;
@@ -34,7 +32,7 @@ export const csv = v.lazy((x) => {
34
32
  if (!x) return $;
35
33
  return v.pipe($, v.regex(/^[^,]+(?:,[^,]+)*$/, "invalid csv"));
36
34
  });
37
- export const csvStrs = v.pipe(
35
+ export const csv_strs = v.pipe(
38
36
  csv,
39
37
  v.transform((x) => x.split(",")),
40
38
  v.filterItems((x) => x.length > 0)
@@ -166,7 +164,7 @@ export type INpoFields = v.InferOutput<typeof npo_fields>;
166
164
 
167
165
  /** for ein path, only fields in reg-num/env gsi is available */
168
166
  export const npo_search = v.object({
169
- fields: v.optional(v.pipe(csvStrs, v.array(npo_fields))),
167
+ fields: v.optional(v.pipe(csv_strs, v.array(npo_fields))),
170
168
  });
171
169
 
172
170
  export interface INposSearch extends v.InferInput<typeof npo_search> {}
@@ -244,13 +242,7 @@ export const media_search = v.object({
244
242
  v.boolean()
245
243
  )
246
244
  ),
247
- limit: v.optional(
248
- v.pipe(
249
- v.string(),
250
- v.transform((x) => +x),
251
- int_gte1
252
- )
253
- ),
245
+ limit: v.optional($int_gte1),
254
246
  });
255
247
  export interface IMediaSearch extends v.InferInput<typeof media_search> {}
256
248
  export interface IMediaSearchObj extends v.InferOutput<typeof media_search> {}