@better-giving/endowment 4.0.29 → 4.0.31

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.mjs CHANGED
@@ -3,7 +3,8 @@ import { BatchGetCommand, DeleteCommand, GetCommand, PutCommand, QueryCommand, T
3
3
  import { Db, Txs, UpdateBuilder, } from "@better-giving/db";
4
4
  import KSUID from "ksuid";
5
5
  import { med_key_filter, med_sk, to_imedia } from "./media.mjs";
6
- import { projection } from "./npo.mjs";
6
+ import { npo_fields } from "./npo.mjs";
7
+ import { projection } from "@better-giving/db/helpers";
7
8
  export class NpoDb extends Db {
8
9
  static table = "endowments_v3";
9
10
  static slug_env_gsi = "slug-env-gsi";
@@ -56,7 +57,7 @@ export class NpoDb extends Db {
56
57
  gsi1SK: med_sk(id, type, featured),
57
58
  };
58
59
  }
59
- async npos_get(ids, fields) {
60
+ async npos_get(ids, fields = Object.keys(npo_fields)) {
60
61
  if (ids.length === 0)
61
62
  return [];
62
63
  const { names, expression } = projection(fields);
@@ -227,7 +228,7 @@ export class NpoDb extends Db {
227
228
  });
228
229
  return this.client.send(cmd);
229
230
  }
230
- async npo(id, fields) {
231
+ async npo(id, fields = Object.keys(npo_fields)) {
231
232
  const { names, expression } = projection(fields);
232
233
  if (typeof id === "string") {
233
234
  const cmd = new QueryCommand({
package/dist/index.d.mts CHANGED
@@ -1,3 +1,3 @@
1
1
  export type * from "./interfaces.mjs";
2
2
  export { NpoDb } from "./db.mjs";
3
- export type { IAllocation, IIncrement, IMediaSearch, IMediaSearchObj, IMediaUpdate, IMilestone, IMilestoneNew, IMilestoneUpdate, INpo, INpoFields, INpoItem, INpoUpdate, IProgram, IProgramDb, IProgramNew, IProgramUpdate, ISocialMediaURLs, TMediaType, INposSearch, INposSearchObj, } from "./schema.mjs";
3
+ export type { IAllocation, IMediaSearch, IMediaSearchObj, IMediaUpdate, IMilestone, IMilestoneNew, IMilestoneUpdate, INpo, INpoFields, INpoItem, INpoUpdate, IProgram, IProgramDb, IProgramNew, IProgramUpdate, ISocialMediaURLs, TMediaType, INposSearch, INposSearchObj, } from "./schema.mjs";
package/dist/npo.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- export declare function projection(fields?: string[]): {
2
- expression: string;
3
- names: Record<string, string>;
1
+ import type { INpo } from "./schema.mjs";
2
+ export declare const npo_fields: {
3
+ [K in keyof Required<INpo>]: "";
4
4
  };
package/dist/npo.mjs CHANGED
@@ -1,4 +1,4 @@
1
- const npo_fields = {
1
+ export const npo_fields = {
2
2
  id: "",
3
3
  active_in_countries: "",
4
4
  endow_designation: "",
@@ -34,8 +34,3 @@ const npo_fields = {
34
34
  w_form: "",
35
35
  payout_minimum: "",
36
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
@@ -28,17 +28,7 @@ export declare const social_media_urls: v.ObjectSchema<{
28
28
  export interface ISocialMediaURLs extends v.InferOutput<typeof social_media_urls> {
29
29
  }
30
30
  export declare const MAX_RECEIPT_MSG_CHAR = 500;
31
- export declare const increment_val: v.SchemaWithPipe<[v.SchemaWithPipe<[v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<"required">, v.TrimAction]>, v.NonEmptyAction<string, "required">]>, v.TransformAction<string, number>, v.SchemaWithPipe<[v.NumberSchema<undefined>, v.MinValueAction<number, 0, "must be > 0">]>, v.TransformAction<number, string>]>, v.TransformAction<string, string>]>;
32
- export declare const MAX_NUM_INCREMENTS = 4;
33
- export declare const increment_label_max_chars = 60;
34
31
  export declare const tagline_max_chars = 140;
35
- export declare const increment_label: v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<"required">, v.TrimAction]>, v.MaxLengthAction<string, 60, ({ requirement: r }: v.MaxLengthIssue<string, 60>) => string>]>;
36
- export declare const increment: v.ObjectSchema<{
37
- readonly value: v.SchemaWithPipe<[v.SchemaWithPipe<[v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<"required">, v.TrimAction]>, v.NonEmptyAction<string, "required">]>, v.TransformAction<string, number>, v.SchemaWithPipe<[v.NumberSchema<undefined>, v.MinValueAction<number, 0, "must be > 0">]>, v.TransformAction<number, string>]>, v.TransformAction<string, string>]>;
38
- readonly label: v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<"required">, v.TrimAction]>, v.MaxLengthAction<string, 60, ({ requirement: r }: v.MaxLengthIssue<string, 60>) => string>]>;
39
- }, undefined>;
40
- export interface IIncrement extends v.InferOutput<typeof increment> {
41
- }
42
32
  export declare const npo: v.ObjectSchema<{
43
33
  readonly id: v.SchemaWithPipe<[v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>]>;
44
34
  readonly env: v.PicklistSchema<readonly ["staging", "production"], undefined>;
@@ -82,12 +72,15 @@ export declare const npo: v.ObjectSchema<{
82
72
  }, "must total to 100">]>, never>;
83
73
  readonly donateMethods: v.OptionalSchema<v.ArraySchema<v.PicklistSchema<readonly ["stripe", "crypto", "daf", "stocks"], "required">, undefined>, never>;
84
74
  readonly increments: v.OptionalSchema<v.SchemaWithPipe<[v.ArraySchema<v.ObjectSchema<{
85
- readonly value: v.SchemaWithPipe<[v.SchemaWithPipe<[v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<"required">, v.TrimAction]>, v.NonEmptyAction<string, "required">]>, v.TransformAction<string, number>, v.SchemaWithPipe<[v.NumberSchema<undefined>, v.MinValueAction<number, 0, "must be > 0">]>, v.TransformAction<number, string>]>, v.TransformAction<string, string>]>;
86
- readonly label: v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<"required">, v.TrimAction]>, v.MaxLengthAction<string, 60, ({ requirement: r }: v.MaxLengthIssue<string, 60>) => string>]>;
75
+ readonly value: import("valibot").SchemaWithPipe<[import("valibot").SchemaWithPipe<[import("valibot").SchemaWithPipe<[import("valibot").SchemaWithPipe<[import("valibot").StringSchema<"required">, import("valibot").TrimAction]>, import("valibot").NonEmptyAction<string, "required">]>, import("valibot").TransformAction<string, number>, import("valibot").SchemaWithPipe<[import("valibot").NumberSchema<undefined>, import("valibot").MinValueAction<number, 0, "must be > 0">]>, import("valibot").TransformAction<number, string>]>, import("valibot").TransformAction<string, string>]>;
76
+ readonly label: import("valibot").SchemaWithPipe<[import("valibot").SchemaWithPipe<[import("valibot").StringSchema<"required">, import("valibot").TrimAction]>, import("valibot").MaxLengthAction<string, 60, ({ requirement: r }: import("valibot").MaxLengthIssue<string, 60>) => string>]>;
87
77
  }, undefined>, undefined>, v.MaxLengthAction<{
88
78
  value: string;
89
79
  label: string;
90
- }[], 4, undefined>]>, never>;
80
+ }[], 4, ({ requirement }: v.MaxLengthIssue<{
81
+ value: string;
82
+ label: string;
83
+ }[], 4>) => string>]>, never>;
91
84
  readonly fund_opt_in: v.OptionalSchema<v.BooleanSchema<undefined>, never>;
92
85
  readonly target: v.OptionalSchema<v.UnionSchema<[v.LiteralSchema<"smart", undefined>, v.SchemaWithPipe<[v.StringSchema<undefined>, v.TransformAction<string, number>, v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>, v.TransformAction<number, string>]>], undefined>, never>;
93
86
  /** endowment is not claimed if `false` only */
@@ -143,12 +136,15 @@ export declare const npo_update: Omit<Omit<v.ObjectSchema<{
143
136
  }, "must total to 100">]>, never>;
144
137
  readonly donateMethods: v.OptionalSchema<v.ArraySchema<v.PicklistSchema<readonly ["stripe", "crypto", "daf", "stocks"], "required">, undefined>, never>;
145
138
  readonly increments: v.OptionalSchema<v.SchemaWithPipe<[v.ArraySchema<v.ObjectSchema<{
146
- readonly value: v.SchemaWithPipe<[v.SchemaWithPipe<[v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<"required">, v.TrimAction]>, v.NonEmptyAction<string, "required">]>, v.TransformAction<string, number>, v.SchemaWithPipe<[v.NumberSchema<undefined>, v.MinValueAction<number, 0, "must be > 0">]>, v.TransformAction<number, string>]>, v.TransformAction<string, string>]>;
147
- readonly label: v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<"required">, v.TrimAction]>, v.MaxLengthAction<string, 60, ({ requirement: r }: v.MaxLengthIssue<string, 60>) => string>]>;
139
+ readonly value: import("valibot").SchemaWithPipe<[import("valibot").SchemaWithPipe<[import("valibot").SchemaWithPipe<[import("valibot").SchemaWithPipe<[import("valibot").StringSchema<"required">, import("valibot").TrimAction]>, import("valibot").NonEmptyAction<string, "required">]>, import("valibot").TransformAction<string, number>, import("valibot").SchemaWithPipe<[import("valibot").NumberSchema<undefined>, import("valibot").MinValueAction<number, 0, "must be > 0">]>, import("valibot").TransformAction<number, string>]>, import("valibot").TransformAction<string, string>]>;
140
+ readonly label: import("valibot").SchemaWithPipe<[import("valibot").SchemaWithPipe<[import("valibot").StringSchema<"required">, import("valibot").TrimAction]>, import("valibot").MaxLengthAction<string, 60, ({ requirement: r }: import("valibot").MaxLengthIssue<string, 60>) => string>]>;
148
141
  }, undefined>, undefined>, v.MaxLengthAction<{
149
142
  value: string;
150
143
  label: string;
151
- }[], 4, undefined>]>, never>;
144
+ }[], 4, ({ requirement }: v.MaxLengthIssue<{
145
+ value: string;
146
+ label: string;
147
+ }[], 4>) => string>]>, never>;
152
148
  readonly fund_opt_in: v.OptionalSchema<v.BooleanSchema<undefined>, never>;
153
149
  readonly target: v.OptionalSchema<v.UnionSchema<[v.LiteralSchema<"smart", undefined>, v.SchemaWithPipe<[v.StringSchema<undefined>, v.TransformAction<string, number>, v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>, v.TransformAction<number, string>]>], undefined>, never>;
154
150
  /** endowment is not claimed if `false` only */
@@ -204,12 +200,15 @@ export declare const npo_update: Omit<Omit<v.ObjectSchema<{
204
200
  }, "must total to 100">]>, never>;
205
201
  readonly donateMethods: v.OptionalSchema<v.ArraySchema<v.PicklistSchema<readonly ["stripe", "crypto", "daf", "stocks"], "required">, undefined>, never>;
206
202
  readonly increments: v.OptionalSchema<v.SchemaWithPipe<[v.ArraySchema<v.ObjectSchema<{
207
- readonly value: v.SchemaWithPipe<[v.SchemaWithPipe<[v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<"required">, v.TrimAction]>, v.NonEmptyAction<string, "required">]>, v.TransformAction<string, number>, v.SchemaWithPipe<[v.NumberSchema<undefined>, v.MinValueAction<number, 0, "must be > 0">]>, v.TransformAction<number, string>]>, v.TransformAction<string, string>]>;
208
- readonly label: v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<"required">, v.TrimAction]>, v.MaxLengthAction<string, 60, ({ requirement: r }: v.MaxLengthIssue<string, 60>) => string>]>;
203
+ readonly value: import("valibot").SchemaWithPipe<[import("valibot").SchemaWithPipe<[import("valibot").SchemaWithPipe<[import("valibot").SchemaWithPipe<[import("valibot").StringSchema<"required">, import("valibot").TrimAction]>, import("valibot").NonEmptyAction<string, "required">]>, import("valibot").TransformAction<string, number>, import("valibot").SchemaWithPipe<[import("valibot").NumberSchema<undefined>, import("valibot").MinValueAction<number, 0, "must be > 0">]>, import("valibot").TransformAction<number, string>]>, import("valibot").TransformAction<string, string>]>;
204
+ readonly label: import("valibot").SchemaWithPipe<[import("valibot").SchemaWithPipe<[import("valibot").StringSchema<"required">, import("valibot").TrimAction]>, import("valibot").MaxLengthAction<string, 60, ({ requirement: r }: import("valibot").MaxLengthIssue<string, 60>) => string>]>;
209
205
  }, undefined>, undefined>, v.MaxLengthAction<{
210
206
  value: string;
211
207
  label: string;
212
- }[], 4, undefined>]>, never>;
208
+ }[], 4, ({ requirement }: v.MaxLengthIssue<{
209
+ value: string;
210
+ label: string;
211
+ }[], 4>) => string>]>, never>;
213
212
  readonly fund_opt_in: v.OptionalSchema<v.BooleanSchema<undefined>, never>;
214
213
  readonly target: v.OptionalSchema<v.UnionSchema<[v.LiteralSchema<"smart", undefined>, v.SchemaWithPipe<[v.StringSchema<undefined>, v.TransformAction<string, number>, v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>, v.TransformAction<number, string>]>], undefined>, never>;
215
214
  /** endowment is not claimed if `false` only */
@@ -226,7 +225,7 @@ export declare const npo_update: Omit<Omit<v.ObjectSchema<{
226
225
  cash: number;
227
226
  liq: number;
228
227
  lock: number;
229
- }> | v.NonEmptyIssue<string> | v.UrlIssue<string> | v.MaxLengthIssue<string, 60> | v.PicklistIssue | v.CustomIssue | v.MaxLengthIssue<string, 30> | v.ExcludesIssue<string, ".."> | v.MaxLengthIssue<string, 140> | v.ArrayIssue | v.NonEmptyIssue<string[]> | v.MinLengthIssue<(2 | 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17)[], 1> | v.MaxLengthIssue<string, 500> | v.BooleanIssue | v.MaxLengthIssue<{
228
+ }> | v.NonEmptyIssue<string> | v.UrlIssue<string> | v.PicklistIssue | v.CustomIssue | v.MaxLengthIssue<string, 30> | v.ExcludesIssue<string, ".."> | v.MaxLengthIssue<string, 140> | v.ArrayIssue | v.NonEmptyIssue<string[]> | v.MinLengthIssue<(2 | 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17)[], 1> | v.MaxLengthIssue<string, 500> | v.BooleanIssue | v.MaxLengthIssue<string, 60> | v.MaxLengthIssue<{
230
229
  value: string;
231
230
  label: string;
232
231
  }[], 4> | v.LiteralIssue | v.UnionIssue<v.StringIssue | v.NumberIssue | v.MinValueIssue<number, 0> | v.LiteralIssue> | v.IsoTimestampIssue<string> | v.MinValueIssue<number, 50>>): v.Dataset<{
@@ -278,7 +277,7 @@ export declare const npo_update: Omit<Omit<v.ObjectSchema<{
278
277
  cash: number;
279
278
  liq: number;
280
279
  lock: number;
281
- }> | v.NonEmptyIssue<string> | v.UrlIssue<string> | v.MaxLengthIssue<string, 60> | v.PicklistIssue | v.CustomIssue | v.MaxLengthIssue<string, 30> | v.ExcludesIssue<string, ".."> | v.MaxLengthIssue<string, 140> | v.ArrayIssue | v.NonEmptyIssue<string[]> | v.MinLengthIssue<(2 | 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17)[], 1> | v.MaxLengthIssue<string, 500> | v.BooleanIssue | v.MaxLengthIssue<{
280
+ }> | v.NonEmptyIssue<string> | v.UrlIssue<string> | v.PicklistIssue | v.CustomIssue | v.MaxLengthIssue<string, 30> | v.ExcludesIssue<string, ".."> | v.MaxLengthIssue<string, 140> | v.ArrayIssue | v.NonEmptyIssue<string[]> | v.MinLengthIssue<(2 | 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17)[], 1> | v.MaxLengthIssue<string, 500> | v.BooleanIssue | v.MaxLengthIssue<string, 60> | v.MaxLengthIssue<{
282
281
  value: string;
283
282
  label: string;
284
283
  }[], 4> | v.LiteralIssue | v.UnionIssue<v.StringIssue | v.NumberIssue | v.MinValueIssue<number, 0> | v.LiteralIssue> | v.IsoTimestampIssue<string> | v.MinValueIssue<number, 50>>;
@@ -379,7 +378,7 @@ export declare const npo_update: Omit<Omit<v.ObjectSchema<{
379
378
  cash: number;
380
379
  liq: number;
381
380
  lock: number;
382
- }> | v.NonEmptyIssue<string> | v.UrlIssue<string> | v.MaxLengthIssue<string, 60> | v.PicklistIssue | v.CustomIssue | v.MaxLengthIssue<string, 30> | v.ExcludesIssue<string, ".."> | v.MaxLengthIssue<string, 140> | v.ArrayIssue | v.NonEmptyIssue<string[]> | v.MinLengthIssue<(2 | 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17)[], 1> | v.MaxLengthIssue<string, 500> | v.BooleanIssue | v.MaxLengthIssue<{
381
+ }> | v.NonEmptyIssue<string> | v.UrlIssue<string> | v.PicklistIssue | v.CustomIssue | v.MaxLengthIssue<string, 30> | v.ExcludesIssue<string, ".."> | v.MaxLengthIssue<string, 140> | v.ArrayIssue | v.NonEmptyIssue<string[]> | v.MinLengthIssue<(2 | 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17)[], 1> | v.MaxLengthIssue<string, 500> | v.BooleanIssue | v.MaxLengthIssue<string, 60> | v.MaxLengthIssue<{
383
382
  value: string;
384
383
  label: string;
385
384
  }[], 4> | v.LiteralIssue | v.UnionIssue<v.StringIssue | v.NumberIssue | v.MinValueIssue<number, 0> | v.LiteralIssue> | v.IsoTimestampIssue<string> | v.MinValueIssue<number, 50>;
@@ -411,12 +410,15 @@ export declare const npo_update: Omit<Omit<v.ObjectSchema<{
411
410
  }, "must total to 100">]>, never>, never>;
412
411
  readonly donateMethods: v.OptionalSchema<v.OptionalSchema<v.ArraySchema<v.PicklistSchema<readonly ["stripe", "crypto", "daf", "stocks"], "required">, undefined>, never>, never>;
413
412
  readonly increments: v.OptionalSchema<v.OptionalSchema<v.SchemaWithPipe<[v.ArraySchema<v.ObjectSchema<{
414
- readonly value: v.SchemaWithPipe<[v.SchemaWithPipe<[v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<"required">, v.TrimAction]>, v.NonEmptyAction<string, "required">]>, v.TransformAction<string, number>, v.SchemaWithPipe<[v.NumberSchema<undefined>, v.MinValueAction<number, 0, "must be > 0">]>, v.TransformAction<number, string>]>, v.TransformAction<string, string>]>;
415
- readonly label: v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<"required">, v.TrimAction]>, v.MaxLengthAction<string, 60, ({ requirement: r }: v.MaxLengthIssue<string, 60>) => string>]>;
413
+ readonly value: import("valibot").SchemaWithPipe<[import("valibot").SchemaWithPipe<[import("valibot").SchemaWithPipe<[import("valibot").SchemaWithPipe<[import("valibot").StringSchema<"required">, import("valibot").TrimAction]>, import("valibot").NonEmptyAction<string, "required">]>, import("valibot").TransformAction<string, number>, import("valibot").SchemaWithPipe<[import("valibot").NumberSchema<undefined>, import("valibot").MinValueAction<number, 0, "must be > 0">]>, import("valibot").TransformAction<number, string>]>, import("valibot").TransformAction<string, string>]>;
414
+ readonly label: import("valibot").SchemaWithPipe<[import("valibot").SchemaWithPipe<[import("valibot").StringSchema<"required">, import("valibot").TrimAction]>, import("valibot").MaxLengthAction<string, 60, ({ requirement: r }: import("valibot").MaxLengthIssue<string, 60>) => string>]>;
416
415
  }, undefined>, undefined>, v.MaxLengthAction<{
417
416
  value: string;
418
417
  label: string;
419
- }[], 4, undefined>]>, never>, never>;
418
+ }[], 4, ({ requirement }: v.MaxLengthIssue<{
419
+ value: string;
420
+ label: string;
421
+ }[], 4>) => string>]>, never>, never>;
420
422
  readonly fund_opt_in: v.OptionalSchema<v.OptionalSchema<v.BooleanSchema<undefined>, never>, never>;
421
423
  readonly target: v.OptionalSchema<v.OptionalSchema<v.UnionSchema<[v.LiteralSchema<"smart", undefined>, v.SchemaWithPipe<[v.StringSchema<undefined>, v.TransformAction<string, number>, v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>, v.TransformAction<number, string>]>], undefined>, never>, never>;
422
424
  readonly referral_id: v.OptionalSchema<v.OptionalSchema<v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<"required">, v.TrimAction]>, v.NonEmptyAction<string, "required">]>, never>, never>;
@@ -442,7 +444,7 @@ export declare const npo_update: Omit<Omit<v.ObjectSchema<{
442
444
  cash: number;
443
445
  liq: number;
444
446
  lock: number;
445
- }> | v.NonEmptyIssue<string> | v.UrlIssue<string> | v.MaxLengthIssue<string, 60> | v.PicklistIssue | v.CustomIssue | v.MaxLengthIssue<string, 30> | v.ExcludesIssue<string, ".."> | v.MaxLengthIssue<string, 140> | v.ArrayIssue | v.NonEmptyIssue<string[]> | v.MinLengthIssue<(2 | 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17)[], 1> | v.MaxLengthIssue<string, 500> | v.BooleanIssue | v.MaxLengthIssue<{
447
+ }> | v.NonEmptyIssue<string> | v.UrlIssue<string> | v.PicklistIssue | v.CustomIssue | v.MaxLengthIssue<string, 30> | v.ExcludesIssue<string, ".."> | v.MaxLengthIssue<string, 140> | v.ArrayIssue | v.NonEmptyIssue<string[]> | v.MinLengthIssue<(2 | 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17)[], 1> | v.MaxLengthIssue<string, 500> | v.BooleanIssue | v.MaxLengthIssue<string, 60> | v.MaxLengthIssue<{
446
448
  value: string;
447
449
  label: string;
448
450
  }[], 4> | v.LiteralIssue | v.UnionIssue<v.StringIssue | v.NumberIssue | v.MinValueIssue<number, 0> | v.LiteralIssue> | v.IsoTimestampIssue<string> | v.MinValueIssue<number, 50>>): v.Dataset<{
@@ -494,7 +496,7 @@ export declare const npo_update: Omit<Omit<v.ObjectSchema<{
494
496
  cash: number;
495
497
  liq: number;
496
498
  lock: number;
497
- }> | v.NonEmptyIssue<string> | v.UrlIssue<string> | v.MaxLengthIssue<string, 60> | v.PicklistIssue | v.CustomIssue | v.MaxLengthIssue<string, 30> | v.ExcludesIssue<string, ".."> | v.MaxLengthIssue<string, 140> | v.ArrayIssue | v.NonEmptyIssue<string[]> | v.MinLengthIssue<(2 | 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17)[], 1> | v.MaxLengthIssue<string, 500> | v.BooleanIssue | v.MaxLengthIssue<{
499
+ }> | v.NonEmptyIssue<string> | v.UrlIssue<string> | v.PicklistIssue | v.CustomIssue | v.MaxLengthIssue<string, 30> | v.ExcludesIssue<string, ".."> | v.MaxLengthIssue<string, 140> | v.ArrayIssue | v.NonEmptyIssue<string[]> | v.MinLengthIssue<(2 | 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17)[], 1> | v.MaxLengthIssue<string, 500> | v.BooleanIssue | v.MaxLengthIssue<string, 60> | v.MaxLengthIssue<{
498
500
  value: string;
499
501
  label: string;
500
502
  }[], 4> | v.LiteralIssue | v.UnionIssue<v.StringIssue | v.NumberIssue | v.MinValueIssue<number, 0> | v.LiteralIssue> | v.IsoTimestampIssue<string> | v.MinValueIssue<number, 50>>;
@@ -595,7 +597,7 @@ export declare const npo_update: Omit<Omit<v.ObjectSchema<{
595
597
  cash: number;
596
598
  liq: number;
597
599
  lock: number;
598
- }> | v.NonEmptyIssue<string> | v.UrlIssue<string> | v.MaxLengthIssue<string, 60> | v.PicklistIssue | v.CustomIssue | v.MaxLengthIssue<string, 30> | v.ExcludesIssue<string, ".."> | v.MaxLengthIssue<string, 140> | v.ArrayIssue | v.NonEmptyIssue<string[]> | v.MinLengthIssue<(2 | 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17)[], 1> | v.MaxLengthIssue<string, 500> | v.BooleanIssue | v.MaxLengthIssue<{
600
+ }> | v.NonEmptyIssue<string> | v.UrlIssue<string> | v.PicklistIssue | v.CustomIssue | v.MaxLengthIssue<string, 30> | v.ExcludesIssue<string, ".."> | v.MaxLengthIssue<string, 140> | v.ArrayIssue | v.NonEmptyIssue<string[]> | v.MinLengthIssue<(2 | 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17)[], 1> | v.MaxLengthIssue<string, 500> | v.BooleanIssue | v.MaxLengthIssue<string, 60> | v.MaxLengthIssue<{
599
601
  value: string;
600
602
  label: string;
601
603
  }[], 4> | v.LiteralIssue | v.UnionIssue<v.StringIssue | v.NumberIssue | v.MinValueIssue<number, 0> | v.LiteralIssue> | v.IsoTimestampIssue<string> | v.MinValueIssue<number, 50>;
package/dist/schema.mjs CHANGED
@@ -1,4 +1,4 @@
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";
1
+ import { $, $int_gte1, $req, MAX_NUM_INCREMENTS, donate_method_id, env, https_url, increment, int_gte1, org_designation, slug, target, unsdg_num, } from "@better-giving/schemas";
2
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;
@@ -26,17 +26,7 @@ export const social_media_urls = v.object({
26
26
  tiktok: v.optional(https_url({})),
27
27
  });
28
28
  export const MAX_RECEIPT_MSG_CHAR = 500;
29
- export const increment_val = v.pipe($req_num_gt0,
30
- //parsed output
31
- v.transform((x) => x.toString()));
32
- export const MAX_NUM_INCREMENTS = 4;
33
- export const increment_label_max_chars = 60;
34
29
  export const tagline_max_chars = 140;
35
- export const increment_label = v.pipe($, v.maxLength(increment_label_max_chars, ({ requirement: r }) => `cannot exceed ${r} characters`));
36
- export const increment = v.object({
37
- value: increment_val,
38
- label: increment_label,
39
- });
40
30
  export const npo = v.object({
41
31
  id: int_gte1,
42
32
  env,
@@ -64,13 +54,9 @@ export const npo = v.object({
64
54
  progDonationsAllowed: v.optional(v.boolean()),
65
55
  allocation: v.optional(allocation),
66
56
  donateMethods: v.optional(v.array(donate_method_id)),
67
- increments: v.optional(v.pipe(v.array(increment), v.maxLength(MAX_NUM_INCREMENTS))),
57
+ increments: v.optional(v.pipe(v.array(increment), v.maxLength(MAX_NUM_INCREMENTS, ({ requirement }) => `cannot have more than ${requirement} increments`))),
68
58
  fund_opt_in: v.optional(v.boolean()),
69
- target: v.optional(v.union([
70
- v.literal("smart"),
71
- // "0" - none, `${number}` - fixed
72
- v.pipe(v.string(), v.transform((v) => +v), v.number(), v.minValue(0), v.transform((v) => v.toString())),
73
- ])),
59
+ target: v.optional(target),
74
60
  /** endowment is not claimed if `false` only */
75
61
  claimed: v.boolean(),
76
62
  kyc_donors_only: v.boolean(),
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@better-giving/endowment",
3
- "version": "4.0.29",
3
+ "version": "4.0.31",
4
4
  "dependencies": {
5
5
  "ksuid": "3.0.0"
6
6
  },
7
7
  "peerDependencies": {
8
- "@better-giving/schemas": "2.0.3",
8
+ "@better-giving/schemas": "2.0.4",
9
9
  "@better-giving/types": "1.1.8",
10
- "@better-giving/db": "2.0.6",
10
+ "@better-giving/db": "2.0.7",
11
11
  "@aws-sdk/lib-dynamodb": "3.485.0",
12
12
  "valibot": "0.42.0"
13
13
  },
package/src/db.mts CHANGED
@@ -28,7 +28,6 @@ import type {
28
28
  TNpoDbProjectedTo,
29
29
  } from "./interfaces.mjs";
30
30
  import { med_key_filter, med_sk, to_imedia } from "./media.mjs";
31
- import { projection } from "./npo.mjs";
32
31
  import type {
33
32
  IMediaSearchObj,
34
33
  IMediaUpdate,
@@ -43,6 +42,8 @@ import type {
43
42
  IProgramUpdate,
44
43
  TMediaType,
45
44
  } from "./schema.mjs";
45
+ import { npo_fields } from "./npo.mjs";
46
+ import { projection } from "@better-giving/db/helpers";
46
47
 
47
48
  export class NpoDb extends Db {
48
49
  static readonly table = "endowments_v3";
@@ -104,7 +105,7 @@ export class NpoDb extends Db {
104
105
 
105
106
  async npos_get<T extends TNpoDbKeys[]>(
106
107
  ids: number[],
107
- fields?: T
108
+ fields: T = Object.keys(npo_fields) as T
108
109
  ): Promise<TNpoDbProjectedTo<T>[]> {
109
110
  if (ids.length === 0) return [];
110
111
  const { names, expression } = projection(fields);
@@ -307,7 +308,7 @@ export class NpoDb extends Db {
307
308
 
308
309
  async npo<T extends TNpoDbKeys[]>(
309
310
  id: string | number,
310
- fields?: T
311
+ fields: T = Object.keys(npo_fields) as T
311
312
  ): Promise<TNpoDbProjectedTo<T> | undefined> {
312
313
  const { names, expression } = projection(fields);
313
314
 
package/src/index.mts CHANGED
@@ -2,7 +2,6 @@ export type * from "./interfaces.mjs";
2
2
  export { NpoDb } from "./db.mjs";
3
3
  export type {
4
4
  IAllocation,
5
- IIncrement,
6
5
  IMediaSearch,
7
6
  IMediaSearchObj,
8
7
  IMediaUpdate,
package/src/npo.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { INpo } from "./schema.mjs";
2
2
 
3
- const npo_fields: { [K in keyof Required<INpo>]: "" } = {
3
+ export const npo_fields: { [K in keyof Required<INpo>]: "" } = {
4
4
  id: "",
5
5
  active_in_countries: "",
6
6
  endow_designation: "",
@@ -36,12 +36,3 @@ const npo_fields: { [K in keyof Required<INpo>]: "" } = {
36
36
  w_form: "",
37
37
  payout_minimum: "",
38
38
  };
39
-
40
- export function projection(fields: string[] = Object.keys(npo_fields)) {
41
- const expression = fields.map((n) => `#${n}`).join(",");
42
- const names = fields.reduce(
43
- (prev, curr) => ({ ...prev, [`#${curr}`]: curr }),
44
- {} as Record<string, string>
45
- );
46
- return { expression, names };
47
- }
package/src/schema.mts CHANGED
@@ -2,13 +2,15 @@ import {
2
2
  $,
3
3
  $int_gte1,
4
4
  $req,
5
- $req_num_gt0,
5
+ MAX_NUM_INCREMENTS,
6
6
  donate_method_id,
7
7
  env,
8
8
  https_url,
9
+ increment,
9
10
  int_gte1,
10
11
  org_designation,
11
12
  slug,
13
+ target,
12
14
  unsdg_num,
13
15
  } from "@better-giving/schemas";
14
16
  export {
@@ -72,31 +74,8 @@ export interface ISocialMediaURLs
72
74
 
73
75
  export const MAX_RECEIPT_MSG_CHAR = 500;
74
76
 
75
- export const increment_val = v.pipe(
76
- $req_num_gt0,
77
- //parsed output
78
- v.transform((x) => x.toString())
79
- );
80
-
81
- export const MAX_NUM_INCREMENTS = 4;
82
- export const increment_label_max_chars = 60;
83
77
  export const tagline_max_chars = 140;
84
78
 
85
- export const increment_label = v.pipe(
86
- $,
87
- v.maxLength(
88
- increment_label_max_chars,
89
- ({ requirement: r }) => `cannot exceed ${r} characters`
90
- )
91
- );
92
-
93
- export const increment = v.object({
94
- value: increment_val,
95
- label: increment_label,
96
- });
97
-
98
- export interface IIncrement extends v.InferOutput<typeof increment> {}
99
-
100
79
  export const npo = v.object({
101
80
  id: int_gte1,
102
81
  env,
@@ -126,22 +105,16 @@ export const npo = v.object({
126
105
  allocation: v.optional(allocation),
127
106
  donateMethods: v.optional(v.array(donate_method_id)),
128
107
  increments: v.optional(
129
- v.pipe(v.array(increment), v.maxLength(MAX_NUM_INCREMENTS))
108
+ v.pipe(
109
+ v.array(increment),
110
+ v.maxLength(
111
+ MAX_NUM_INCREMENTS,
112
+ ({ requirement }) => `cannot have more than ${requirement} increments`
113
+ )
114
+ )
130
115
  ),
131
116
  fund_opt_in: v.optional(v.boolean()),
132
- target: v.optional(
133
- v.union([
134
- v.literal("smart"),
135
- // "0" - none, `${number}` - fixed
136
- v.pipe(
137
- v.string(),
138
- v.transform((v) => +v),
139
- v.number(),
140
- v.minValue(0),
141
- v.transform((v) => v.toString())
142
- ),
143
- ])
144
- ),
117
+ target: v.optional(target),
145
118
  /** endowment is not claimed if `false` only */
146
119
  claimed: v.boolean(),
147
120
  kyc_donors_only: v.boolean(),