@uidu/client 3.13.1 → 3.14.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/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@uidu/client",
3
- "version": "3.13.1",
3
+ "version": "3.14.0",
4
4
  "description": "Typed GraphQL client for the uidu platform. Server-first, framework-agnostic.",
5
5
  "license": "MIT",
6
6
  "author": "uidu",
7
- "repository": "https://github.com/uidu-org/api.js/tree/main/packages/client",
7
+ "repository": "https://github.com/uidu-org/developers/tree/main/packages/client",
8
8
  "type": "module",
9
9
  "sideEffects": false,
10
10
  "engines": {
@@ -20,8 +20,9 @@ import { nodes } from './utils/relay';
20
20
  *
21
21
  * Reads (`listApplications`) require a Bearer token (`apiKey`): applications
22
22
  * hold private candidate data. Writes (`createApplication`,
23
- * `updateApplication`, `completeApplication`) are the public "apply to this
24
- * job" path.
23
+ * `updateApplication`, `completeApplication`) are how a candidate applies to a
24
+ * job — visitor-facing, but still submitted from the server (a server action),
25
+ * never with a publicToken from the browser.
25
26
  */
26
27
  export type Application = NonNullable<
27
28
  NonNullable<
@@ -0,0 +1,57 @@
1
+ import { describe, expect, it, vi } from 'vitest';
2
+ import type { UiduClient } from './client';
3
+ import { listDonations } from './donations';
4
+
5
+ const donation = (id: string, status: string) => ({
6
+ id,
7
+ amount: 5000,
8
+ currency: 'EUR',
9
+ status,
10
+ createdAt: '2026-10-09T10:00:00Z',
11
+ body: null,
12
+ dedication: null,
13
+ preferences: null,
14
+ contact: { id: `c-${id}`, name: 'Ada Lovelace', avatar: null },
15
+ });
16
+
17
+ const withDonations = (nodes: ReturnType<typeof donation>[]) => ({
18
+ currentWorkspace: {
19
+ donationCampaign: {
20
+ donations: {
21
+ pageInfo: { hasNextPage: false, endCursor: null },
22
+ edges: nodes.map((node) => ({ node })),
23
+ },
24
+ },
25
+ },
26
+ });
27
+
28
+ describe('listDonations', () => {
29
+ it('passes the campaign and paging through to the query', async () => {
30
+ const query = vi.fn().mockResolvedValue(withDonations([]));
31
+ const client = { query } as unknown as UiduClient;
32
+
33
+ await listDonations(client, { campaignId: 'dc1', first: 3, after: 'x' });
34
+
35
+ expect(query.mock.calls[0][1]).toEqual({ campaignId: 'dc1', first: 3, after: 'x' });
36
+ });
37
+
38
+ it('returns the nodes in order without abandoned checkouts', async () => {
39
+ const query = vi
40
+ .fn()
41
+ .mockResolvedValue(
42
+ withDonations([donation('d1', 'paid'), donation('d2', 'abandoned'), donation('d3', 'placed')]),
43
+ );
44
+ const client = { query } as unknown as UiduClient;
45
+
46
+ const result = await listDonations(client, { campaignId: 'dc1' });
47
+
48
+ expect(result.map((d) => d.id)).toEqual(['d1', 'd3']);
49
+ });
50
+
51
+ it('returns an empty array when the campaign does not exist', async () => {
52
+ const query = vi.fn().mockResolvedValue({ currentWorkspace: { donationCampaign: null } });
53
+ const client = { query } as unknown as UiduClient;
54
+
55
+ expect(await listDonations(client, { campaignId: 'missing' })).toEqual([]);
56
+ });
57
+ });
package/src/donations.ts CHANGED
@@ -9,6 +9,9 @@ import {
9
9
  type GetDonationCampaignQueryVariables,
10
10
  ListDonationCampaignsDocument,
11
11
  type ListDonationCampaignsQueryVariables,
12
+ ListDonationsDocument,
13
+ type ListDonationsQuery,
14
+ type ListDonationsQueryVariables,
12
15
  } from './generated';
13
16
  import { nodes } from './utils/relay';
14
17
 
@@ -40,6 +43,31 @@ export async function listDonationCampaigns(
40
43
  return nodes(result.currentWorkspace?.donationCampaigns);
41
44
  }
42
45
 
46
+ export type Donation = NonNullable<
47
+ NonNullable<
48
+ NonNullable<
49
+ NonNullable<ListDonationsQuery['currentWorkspace']>['donationCampaign']
50
+ >['donations']['edges']
51
+ >[number]
52
+ >['node'] & {};
53
+
54
+ /**
55
+ * A campaign's donations, newest first, with the donor's display name and
56
+ * message; abandoned checkouts are left out.
57
+ *
58
+ * Reads need a Bearer. The selection stops at what a public "recent
59
+ * donations" list shows: no email, no payment details.
60
+ */
61
+ export async function listDonations(
62
+ client: UiduClient,
63
+ variables: ListDonationsQueryVariables,
64
+ ): Promise<Donation[]> {
65
+ const result = await client.query(ListDonationsDocument, variables);
66
+ return nodes(result.currentWorkspace?.donationCampaign?.donations).filter(
67
+ (donation) => donation.status !== 'abandoned',
68
+ );
69
+ }
70
+
43
71
  /**
44
72
  * Record a donation (amount in cents) to a campaign, creating the donor's
45
73
  * contact inline; returns `{ errors, donation }` as-is.