@uidu/client 3.0.0 → 3.1.1
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/CHANGELOG.md +17 -0
- package/README.md +56 -0
- package/dist/declarations/src/bookings.d.ts +58 -0
- package/dist/declarations/src/calls.d.ts +26 -0
- package/dist/declarations/src/campaigns.d.ts +39 -0
- package/dist/declarations/src/client.d.ts +10 -0
- package/dist/declarations/src/cms.d.ts +75 -0
- package/dist/declarations/src/contacts.d.ts +36 -0
- package/dist/declarations/src/courses.d.ts +68 -0
- package/dist/declarations/src/donations.d.ts +51 -0
- package/dist/declarations/src/events.d.ts +59 -0
- package/dist/declarations/src/forms.d.ts +69 -0
- package/dist/declarations/src/generated/index.d.ts +45142 -0
- package/dist/declarations/src/help-center.d.ts +4 -0
- package/dist/declarations/src/index.d.ts +39 -0
- package/dist/declarations/src/kb.d.ts +30 -0
- package/dist/declarations/src/mutations.d.ts +394 -0
- package/dist/declarations/src/notes.d.ts +18 -0
- package/dist/declarations/src/people.d.ts +31 -0
- package/dist/declarations/src/search.d.ts +4 -0
- package/dist/declarations/src/spaces.d.ts +19 -0
- package/dist/declarations/src/stories.d.ts +28 -0
- package/dist/declarations/src/system.d.ts +36 -0
- package/dist/declarations/src/tasks.d.ts +16 -0
- package/dist/declarations/src/types.d.ts +19 -0
- package/dist/declarations/src/utils/paginate.d.ts +34 -0
- package/dist/uidu-client.cjs.d.ts +2 -2
- package/dist/uidu-client.cjs.dev.js +588 -0
- package/dist/uidu-client.cjs.js +6 -15
- package/dist/uidu-client.cjs.prod.js +588 -0
- package/dist/uidu-client.esm.js +477 -0
- package/package.json +8 -3
- package/src/cms.ts +43 -0
- package/src/donations.ts +10 -0
- package/src/events.ts +10 -0
- package/src/generated/index.ts +2899 -84
- package/src/index.ts +53 -3
- package/src/mutations.ts +167 -0
- package/src/notes.ts +15 -0
- package/src/people.test.ts +28 -0
- package/src/queries/cms/CreateFieldValue.graphql +16 -0
- package/src/queries/cms/CreatePage.graphql +15 -0
- package/src/queries/cms/CreatePageBlock.graphql +14 -0
- package/src/queries/cms/CreateProject.graphql +16 -0
- package/src/queries/contacts/ContactMutations.graphql +53 -0
- package/src/queries/courses/CourseMutations.graphql +38 -0
- package/src/queries/donations/CreateDonationCampaign.graphql +13 -0
- package/src/queries/donations/DonationCampaignMutations.graphql +25 -0
- package/src/queries/events/CreateEvent.graphql +13 -0
- package/src/queries/events/UpdateEvent.graphql +12 -0
- package/src/queries/forms/FormMutations.graphql +40 -0
- package/src/queries/help-center/ChannelMutations.graphql +40 -0
- package/src/queries/kb/KbMutations.graphql +81 -0
- package/src/queries/notes/CreateNote.graphql +14 -0
- package/src/queries/notes/NoteMutations.graphql +25 -0
- package/src/queries/spaces/CreateSpace.graphql +15 -0
- package/src/queries/spaces/SpaceMutations.graphql +25 -0
- package/src/queries/stories/CreateStory.graphql +13 -0
- package/src/queries/stories/UpdateStory.graphql +12 -0
- package/src/queries/system/CreateWorkspace.graphql +15 -0
- package/src/queries/system/GenerateWorkspaceApiCredentials.graphql +18 -0
- package/src/queries/tasks/CreateTask.graphql +13 -0
- package/src/queries/tasks/TaskMutations.graphql +25 -0
- package/src/spaces.ts +15 -0
- package/src/stories.ts +10 -0
- package/src/system.ts +33 -0
- package/src/tasks.ts +15 -0
- package/src/utils/paginate.test.ts +116 -0
- package/src/utils/relay.test.ts +35 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
mutation UpdateNote($input: UpdateNoteInput!) {
|
|
2
|
+
updateNote(input: $input) {
|
|
3
|
+
note {
|
|
4
|
+
id
|
|
5
|
+
}
|
|
6
|
+
errors {
|
|
7
|
+
key
|
|
8
|
+
name
|
|
9
|
+
type
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
mutation DeleteNote($input: DeleteNoteInput!) {
|
|
15
|
+
deleteNote(input: $input) {
|
|
16
|
+
note {
|
|
17
|
+
id
|
|
18
|
+
}
|
|
19
|
+
errors {
|
|
20
|
+
key
|
|
21
|
+
name
|
|
22
|
+
type
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
mutation UpdateSpace($input: UpdateSpaceInput!) {
|
|
2
|
+
updateSpace(input: $input) {
|
|
3
|
+
space {
|
|
4
|
+
id
|
|
5
|
+
}
|
|
6
|
+
errors {
|
|
7
|
+
key
|
|
8
|
+
name
|
|
9
|
+
type
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
mutation DeleteSpace($input: DeleteSpaceInput!) {
|
|
15
|
+
deleteSpace(input: $input) {
|
|
16
|
+
space {
|
|
17
|
+
id
|
|
18
|
+
}
|
|
19
|
+
errors {
|
|
20
|
+
key
|
|
21
|
+
name
|
|
22
|
+
type
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Staged for codegen — validated on the next `yarn codegen` run against the live
|
|
2
|
+
# schema (needs UIDU_WORKSPACE + UIDU_PUBLIC_TOKEN). See plans/ai-connector.md.
|
|
3
|
+
mutation CreateWorkspace($input: CreateWorkspaceInput!) {
|
|
4
|
+
createWorkspace(input: $input) {
|
|
5
|
+
workspace {
|
|
6
|
+
id
|
|
7
|
+
name
|
|
8
|
+
}
|
|
9
|
+
errors {
|
|
10
|
+
key
|
|
11
|
+
name
|
|
12
|
+
type
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Staged for codegen — validated on the next `yarn codegen` run. See plans/ai-connector.md.
|
|
2
|
+
mutation GenerateWorkspaceApiCredentials(
|
|
3
|
+
$input: GenerateWorkspaceApiCredentialsInput!
|
|
4
|
+
) {
|
|
5
|
+
generateWorkspaceApiCredentials(input: $input) {
|
|
6
|
+
apiKey
|
|
7
|
+
apiSecret
|
|
8
|
+
workspace {
|
|
9
|
+
id
|
|
10
|
+
name
|
|
11
|
+
}
|
|
12
|
+
errors {
|
|
13
|
+
key
|
|
14
|
+
name
|
|
15
|
+
type
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
mutation UpdateTask($input: UpdateTaskInput!) {
|
|
2
|
+
updateTask(input: $input) {
|
|
3
|
+
task {
|
|
4
|
+
id
|
|
5
|
+
}
|
|
6
|
+
errors {
|
|
7
|
+
key
|
|
8
|
+
name
|
|
9
|
+
type
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
mutation DeleteTask($input: DeleteTaskInput!) {
|
|
15
|
+
deleteTask(input: $input) {
|
|
16
|
+
task {
|
|
17
|
+
id
|
|
18
|
+
}
|
|
19
|
+
errors {
|
|
20
|
+
key
|
|
21
|
+
name
|
|
22
|
+
type
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
package/src/spaces.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { UiduClient } from './client';
|
|
2
|
+
import {
|
|
3
|
+
CreateSpaceDocument,
|
|
4
|
+
type CreateSpaceMutationVariables,
|
|
5
|
+
} from './generated';
|
|
6
|
+
|
|
7
|
+
// Authoring (Bearer / doorkeeper token). Returns the payload, incl. `errors`.
|
|
8
|
+
|
|
9
|
+
export async function createSpace(
|
|
10
|
+
client: UiduClient,
|
|
11
|
+
variables: CreateSpaceMutationVariables,
|
|
12
|
+
) {
|
|
13
|
+
const result = await client.mutate(CreateSpaceDocument, variables);
|
|
14
|
+
return result.createSpace ?? null;
|
|
15
|
+
}
|
package/src/stories.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { UiduClient } from './client';
|
|
2
2
|
import {
|
|
3
|
+
CreateStoryDocument,
|
|
4
|
+
type CreateStoryMutationVariables,
|
|
3
5
|
GetStoryDocument,
|
|
4
6
|
type GetStoryQuery,
|
|
5
7
|
type GetStoryQueryVariables,
|
|
@@ -27,3 +29,11 @@ export async function listStories(
|
|
|
27
29
|
const result = await client.query(ListStoriesDocument, variables);
|
|
28
30
|
return nodes(result.currentWorkspace?.storiesConnection);
|
|
29
31
|
}
|
|
32
|
+
|
|
33
|
+
export async function createStory(
|
|
34
|
+
client: UiduClient,
|
|
35
|
+
variables: CreateStoryMutationVariables,
|
|
36
|
+
) {
|
|
37
|
+
const result = await client.mutate(CreateStoryDocument, variables);
|
|
38
|
+
return result.createStory ?? null;
|
|
39
|
+
}
|
package/src/system.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { UiduClient } from './client';
|
|
2
|
+
import {
|
|
3
|
+
CreateWorkspaceDocument,
|
|
4
|
+
type CreateWorkspaceMutationVariables,
|
|
5
|
+
GenerateWorkspaceApiCredentialsDocument,
|
|
6
|
+
type GenerateWorkspaceApiCredentialsMutationVariables,
|
|
7
|
+
} from './generated';
|
|
8
|
+
|
|
9
|
+
// Workspace-level authoring. Requires a doorkeeper Bearer token (apiKey on the
|
|
10
|
+
// client) — these run as the authenticated account, subject to its Pundit role.
|
|
11
|
+
|
|
12
|
+
export async function createWorkspace(
|
|
13
|
+
client: UiduClient,
|
|
14
|
+
variables: CreateWorkspaceMutationVariables,
|
|
15
|
+
) {
|
|
16
|
+
const result = await client.mutate(CreateWorkspaceDocument, variables);
|
|
17
|
+
return result.createWorkspace ?? null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Rotate + return a workspace's API credentials (apiKey/apiSecret). Operates on
|
|
22
|
+
* the current workspace. Use the returned credentials to wire a scaffolded app.
|
|
23
|
+
*/
|
|
24
|
+
export async function generateWorkspaceApiCredentials(
|
|
25
|
+
client: UiduClient,
|
|
26
|
+
variables: GenerateWorkspaceApiCredentialsMutationVariables,
|
|
27
|
+
) {
|
|
28
|
+
const result = await client.mutate(
|
|
29
|
+
GenerateWorkspaceApiCredentialsDocument,
|
|
30
|
+
variables,
|
|
31
|
+
);
|
|
32
|
+
return result.generateWorkspaceApiCredentials ?? null;
|
|
33
|
+
}
|
package/src/tasks.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { UiduClient } from './client';
|
|
2
|
+
import {
|
|
3
|
+
CreateTaskDocument,
|
|
4
|
+
type CreateTaskMutationVariables,
|
|
5
|
+
} from './generated';
|
|
6
|
+
|
|
7
|
+
// Authoring (Bearer / doorkeeper token). Returns the payload, incl. `errors`.
|
|
8
|
+
|
|
9
|
+
export async function createTask(
|
|
10
|
+
client: UiduClient,
|
|
11
|
+
variables: CreateTaskMutationVariables,
|
|
12
|
+
) {
|
|
13
|
+
const result = await client.mutate(CreateTaskDocument, variables);
|
|
14
|
+
return result.createTask ?? null;
|
|
15
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import type { UiduClient } from '../client';
|
|
3
|
+
import { paginate } from './paginate';
|
|
4
|
+
|
|
5
|
+
type Page = {
|
|
6
|
+
connection: {
|
|
7
|
+
edges: { node: string }[];
|
|
8
|
+
pageInfo: { endCursor: string | null; hasNextPage: boolean };
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
function makeClient(pages: Page[]) {
|
|
13
|
+
const query = vi.fn(async (_doc: unknown, vars: { after?: string | null }) => {
|
|
14
|
+
const index = vars?.after
|
|
15
|
+
? pages.findIndex(
|
|
16
|
+
(p) => p.connection.pageInfo.endCursor === vars.after,
|
|
17
|
+
) + 1
|
|
18
|
+
: 0;
|
|
19
|
+
return pages[index];
|
|
20
|
+
});
|
|
21
|
+
const client = { query } as unknown as UiduClient;
|
|
22
|
+
return { client, query };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const extract = (data: Page) => data?.connection;
|
|
26
|
+
|
|
27
|
+
describe('paginate', () => {
|
|
28
|
+
it('walks multiple pages and concatenates nodes in order', async () => {
|
|
29
|
+
const pages: Page[] = [
|
|
30
|
+
{
|
|
31
|
+
connection: {
|
|
32
|
+
edges: [{ node: 'a' }, { node: 'b' }],
|
|
33
|
+
pageInfo: { endCursor: 'cursor-1', hasNextPage: true },
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
connection: {
|
|
38
|
+
edges: [{ node: 'c' }],
|
|
39
|
+
pageInfo: { endCursor: 'cursor-2', hasNextPage: false },
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
];
|
|
43
|
+
const { client } = makeClient(pages);
|
|
44
|
+
const result = await paginate(client, {} as never, { extract });
|
|
45
|
+
expect(result).toEqual(['a', 'b', 'c']);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('stops when hasNextPage is false', async () => {
|
|
49
|
+
const pages: Page[] = [
|
|
50
|
+
{
|
|
51
|
+
connection: {
|
|
52
|
+
edges: [{ node: 'a' }],
|
|
53
|
+
pageInfo: { endCursor: 'cursor-1', hasNextPage: false },
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
];
|
|
57
|
+
const { client, query } = makeClient(pages);
|
|
58
|
+
const result = await paginate(client, {} as never, { extract });
|
|
59
|
+
expect(result).toEqual(['a']);
|
|
60
|
+
expect(query).toHaveBeenCalledTimes(1);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('stops when endCursor is null/missing even if hasNextPage is true', async () => {
|
|
64
|
+
const pages: Page[] = [
|
|
65
|
+
{
|
|
66
|
+
connection: {
|
|
67
|
+
edges: [{ node: 'a' }],
|
|
68
|
+
pageInfo: { endCursor: null, hasNextPage: true },
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
];
|
|
72
|
+
const { client, query } = makeClient(pages);
|
|
73
|
+
const result = await paginate(client, {} as never, { extract });
|
|
74
|
+
expect(result).toEqual(['a']);
|
|
75
|
+
expect(query).toHaveBeenCalledTimes(1);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('returns [] when extract yields null/undefined', async () => {
|
|
79
|
+
const query = vi.fn(async () => ({}) as Page);
|
|
80
|
+
const client = { query } as unknown as UiduClient;
|
|
81
|
+
const result = await paginate(client, {} as never, {
|
|
82
|
+
extract: () => null,
|
|
83
|
+
});
|
|
84
|
+
expect(result).toEqual([]);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('bounds the loop with maxPages', async () => {
|
|
88
|
+
const pages: Page[] = [
|
|
89
|
+
{
|
|
90
|
+
connection: {
|
|
91
|
+
edges: [{ node: 'a' }],
|
|
92
|
+
pageInfo: { endCursor: 'cursor-1', hasNextPage: true },
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
connection: {
|
|
97
|
+
edges: [{ node: 'b' }],
|
|
98
|
+
pageInfo: { endCursor: 'cursor-2', hasNextPage: true },
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
connection: {
|
|
103
|
+
edges: [{ node: 'c' }],
|
|
104
|
+
pageInfo: { endCursor: 'cursor-3', hasNextPage: false },
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
];
|
|
108
|
+
const { client, query } = makeClient(pages);
|
|
109
|
+
const result = await paginate(client, {} as never, {
|
|
110
|
+
extract,
|
|
111
|
+
maxPages: 1,
|
|
112
|
+
});
|
|
113
|
+
expect(query).toHaveBeenCalledTimes(1);
|
|
114
|
+
expect(result).toEqual(['a']);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { nodes } from './relay';
|
|
3
|
+
|
|
4
|
+
describe('nodes', () => {
|
|
5
|
+
it('returns [] for a null connection', () => {
|
|
6
|
+
expect(nodes(null)).toEqual([]);
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
it('returns [] for an undefined connection', () => {
|
|
10
|
+
expect(nodes(undefined)).toEqual([]);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('returns [] when edges is missing', () => {
|
|
14
|
+
expect(nodes({})).toEqual([]);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('filters out null edges and null nodes', () => {
|
|
18
|
+
const connection = {
|
|
19
|
+
edges: [
|
|
20
|
+
{ node: 'a' },
|
|
21
|
+
null,
|
|
22
|
+
{ node: null },
|
|
23
|
+
{ node: 'b' },
|
|
24
|
+
],
|
|
25
|
+
};
|
|
26
|
+
expect(nodes(connection)).toEqual(['a', 'b']);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('returns nodes in order for a normal connection', () => {
|
|
30
|
+
const connection = {
|
|
31
|
+
edges: [{ node: 'a' }, { node: 'b' }, { node: 'c' }],
|
|
32
|
+
};
|
|
33
|
+
expect(nodes(connection)).toEqual(['a', 'b', 'c']);
|
|
34
|
+
});
|
|
35
|
+
});
|