@better-giving/fundraiser 3.0.13 → 3.0.15

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
@@ -1,5 +1,5 @@
1
- import { BatchGetCommand, QueryCommand, UpdateCommand, } from "@aws-sdk/lib-dynamodb";
2
- import { Db, UpdateBuilder } from "@better-giving/db";
1
+ import { BatchGetCommand, GetCommand, QueryCommand, UpdateCommand, } from "@aws-sdk/lib-dynamodb";
2
+ import { Db, UpdateBuilder, } from "@better-giving/db";
3
3
  import { UUID_REGEX } from "valibot";
4
4
  export class FundDb extends Db {
5
5
  static table = "funds";
@@ -24,24 +24,30 @@ export class FundDb extends Db {
24
24
  }
25
25
  /**@param id - slug or uuid */
26
26
  async fund(id) {
27
- const q = {
28
- TableName: FundDb.table,
29
- Limit: 1,
30
- };
27
+ let item;
31
28
  if (UUID_REGEX.test(id)) {
32
- q.KeyConditionExpression = "PK = :PK AND SK = :SK";
33
- q.ExpressionAttributeValues = this.key_fund(id);
29
+ const cmd = new GetCommand({
30
+ TableName: FundDb.table,
31
+ Key: this.key_fund(id),
32
+ });
33
+ const res = await this.client.send(cmd);
34
+ item = res.Item;
34
35
  }
35
36
  else {
36
- q.IndexName = FundDb.slug_env_gsi;
37
- q.KeyConditionExpression = "slug = :slug AND env = :env";
38
- q.ExpressionAttributeValues = {
39
- ":slug": id,
40
- ":env": this.env,
41
- };
37
+ const cmd = new QueryCommand({
38
+ TableName: FundDb.table,
39
+ Limit: 1,
40
+ IndexName: FundDb.slug_env_gsi,
41
+ KeyConditionExpression: "slug = :slug AND env = :env",
42
+ ExpressionAttributeValues: {
43
+ ":slug": id,
44
+ ":env": this.env,
45
+ },
46
+ });
47
+ const { Items: i = [] } = await this.client.send(cmd);
48
+ item = i[0];
42
49
  }
43
- const { Items: i = [] } = await this.client.send(new QueryCommand(q));
44
- return i[0] && this.sans_keys(i[0]);
50
+ return item && this.sans_keys(item);
45
51
  }
46
52
  async funds_get(ids) {
47
53
  const cmd = new BatchGetCommand({
package/dist/index.d.mts CHANGED
@@ -1,5 +1,9 @@
1
+ import type { IPageNumbered } from "@better-giving/types/api";
2
+ import type { CloudsearchFund } from "./cloudsearch.mjs";
1
3
  export type { CloudsearchFund as FundItem } from "./cloudsearch.mjs";
2
4
  export type { IFundNew, IFundUpdate, IFundsNpoMemberOfSearchObj, IFundsSearchObj, DonateMethodId, Environment, } from "./schema.mjs";
3
5
  export { MAX_EXPIRATION } from "./schema.mjs";
4
6
  export type * from "./interfaces.mjs";
5
7
  export { FundDb } from "./db.mjs";
8
+ export interface IFundsPage extends IPageNumbered<CloudsearchFund> {
9
+ }
@@ -1,6 +1,4 @@
1
1
  import type { DonateMethodId, Environment } from "@better-giving/schemas";
2
- import type { IPageNumbered } from "@better-giving/types/api";
3
- import type { CloudsearchFund } from "./cloudsearch.mjs";
4
2
  import type { IFundNew } from "./schema.mjs";
5
3
  export interface IFundSettings {
6
4
  hide_bg_tip: boolean;
@@ -24,5 +22,3 @@ export interface IFundInternal extends IFundCreator {
24
22
  }
25
23
  export interface IFund extends IFundNew, IFundInternal {
26
24
  }
27
- export interface IFundsPage extends IPageNumbered<CloudsearchFund> {
28
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@better-giving/fundraiser",
3
- "version": "3.0.13",
3
+ "version": "3.0.15",
4
4
  "peerDependencies": {
5
5
  "valibot": "0.42.0",
6
6
  "@better-giving/schemas": "2.0.0",
package/src/db.mts CHANGED
@@ -1,10 +1,15 @@
1
1
  import {
2
2
  BatchGetCommand,
3
+ GetCommand,
3
4
  QueryCommand,
4
- type QueryCommandInput,
5
5
  UpdateCommand,
6
6
  } from "@aws-sdk/lib-dynamodb";
7
- import { Db, type TxType, UpdateBuilder } from "@better-giving/db";
7
+ import {
8
+ Db,
9
+ type TRecord,
10
+ type TxType,
11
+ UpdateBuilder,
12
+ } from "@better-giving/db";
8
13
  import { UUID_REGEX } from "valibot";
9
14
  import type { IFund } from "./interfaces.mjs";
10
15
  import type { IFundUpdate } from "./schema.mjs";
@@ -32,24 +37,29 @@ export class FundDb extends Db {
32
37
  }
33
38
  /**@param id - slug or uuid */
34
39
  async fund(id: string): Promise<IFund | undefined> {
35
- const q: QueryCommandInput = {
36
- TableName: FundDb.table,
37
- Limit: 1,
38
- };
40
+ let item: TRecord | undefined;
39
41
  if (UUID_REGEX.test(id)) {
40
- q.KeyConditionExpression = "PK = :PK AND SK = :SK";
41
- q.ExpressionAttributeValues = this.key_fund(id);
42
+ const cmd = new GetCommand({
43
+ TableName: FundDb.table,
44
+ Key: this.key_fund(id),
45
+ });
46
+ const res = await this.client.send(cmd);
47
+ item = res.Item;
42
48
  } else {
43
- q.IndexName = FundDb.slug_env_gsi;
44
- q.KeyConditionExpression = "slug = :slug AND env = :env";
45
- q.ExpressionAttributeValues = {
46
- ":slug": id,
47
- ":env": this.env,
48
- };
49
+ const cmd = new QueryCommand({
50
+ TableName: FundDb.table,
51
+ Limit: 1,
52
+ IndexName: FundDb.slug_env_gsi,
53
+ KeyConditionExpression: "slug = :slug AND env = :env",
54
+ ExpressionAttributeValues: {
55
+ ":slug": id,
56
+ ":env": this.env,
57
+ },
58
+ });
59
+ const { Items: i = [] } = await this.client.send(cmd);
60
+ item = i[0];
49
61
  }
50
-
51
- const { Items: i = [] } = await this.client.send(new QueryCommand(q));
52
- return i[0] && this.sans_keys(i[0]);
62
+ return item && this.sans_keys(item);
53
63
  }
54
64
 
55
65
  async funds_get(ids: string[]): Promise<IFund[]> {
package/src/index.mts CHANGED
@@ -1,3 +1,6 @@
1
+ import type { IPageNumbered } from "@better-giving/types/api";
2
+ import type { CloudsearchFund } from "./cloudsearch.mjs";
3
+
1
4
  export type { CloudsearchFund as FundItem } from "./cloudsearch.mjs";
2
5
  export type {
3
6
  IFundNew,
@@ -10,3 +13,5 @@ export type {
10
13
  export { MAX_EXPIRATION } from "./schema.mjs";
11
14
  export type * from "./interfaces.mjs";
12
15
  export { FundDb } from "./db.mjs";
16
+
17
+ export interface IFundsPage extends IPageNumbered<CloudsearchFund> {}
@@ -1,6 +1,4 @@
1
1
  import type { DonateMethodId, Environment } from "@better-giving/schemas";
2
- import type { IPageNumbered } from "@better-giving/types/api";
3
- import type { CloudsearchFund } from "./cloudsearch.mjs";
4
2
  import type { IFundNew } from "./schema.mjs";
5
3
 
6
4
  export interface IFundSettings {
@@ -27,5 +25,3 @@ export interface IFundInternal extends IFundCreator {
27
25
  }
28
26
 
29
27
  export interface IFund extends IFundNew, IFundInternal {}
30
-
31
- export interface IFundsPage extends IPageNumbered<CloudsearchFund> {}