@uidu/client 3.0.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.
Files changed (74) hide show
  1. package/.env.example +9 -0
  2. package/CHANGELOG.md +7 -0
  3. package/codegen.ts +42 -0
  4. package/dist/uidu-client.cjs.d.ts +2 -0
  5. package/dist/uidu-client.cjs.js +16 -0
  6. package/package.json +45 -0
  7. package/src/bookings.ts +77 -0
  8. package/src/calls.ts +29 -0
  9. package/src/campaigns.ts +39 -0
  10. package/src/client.ts +60 -0
  11. package/src/cms.ts +46 -0
  12. package/src/contacts.ts +49 -0
  13. package/src/courses.ts +77 -0
  14. package/src/donations.ts +39 -0
  15. package/src/events.ts +39 -0
  16. package/src/forms.ts +49 -0
  17. package/src/generated/index.ts +47209 -0
  18. package/src/help-center.ts +18 -0
  19. package/src/index.ts +106 -0
  20. package/src/kb.ts +53 -0
  21. package/src/people.ts +43 -0
  22. package/src/queries/bookings/GetBooking.graphql +26 -0
  23. package/src/queries/bookings/GetCalendar.graphql +13 -0
  24. package/src/queries/bookings/GetCalendarEvent.graphql +29 -0
  25. package/src/queries/bookings/ListBookings.graphql +30 -0
  26. package/src/queries/bookings/ListCalendarEvents.graphql +45 -0
  27. package/src/queries/bookings/ListCalendars.graphql +19 -0
  28. package/src/queries/calls/GetCall.graphql +31 -0
  29. package/src/queries/calls/ListCalls.graphql +32 -0
  30. package/src/queries/campaigns/GetCampaign.graphql +19 -0
  31. package/src/queries/campaigns/ListCampaigns.graphql +27 -0
  32. package/src/queries/campaigns/ListEmailCampaigns.graphql +34 -0
  33. package/src/queries/cms/GetPage.graphql +80 -0
  34. package/src/queries/cms/GetTemplate.graphql +41 -0
  35. package/src/queries/cms/ListPages.graphql +20 -0
  36. package/src/queries/contacts/GetContact.graphql +15 -0
  37. package/src/queries/contacts/GetDeal.graphql +30 -0
  38. package/src/queries/contacts/ListContacts.graphql +12 -0
  39. package/src/queries/contacts/ListDeals.graphql +30 -0
  40. package/src/queries/courses/GetCourse.graphql +22 -0
  41. package/src/queries/courses/GetEnrollment.graphql +25 -0
  42. package/src/queries/courses/GetLecture.graphql +36 -0
  43. package/src/queries/courses/ListCourses.graphql +27 -0
  44. package/src/queries/courses/ListEnrollments.graphql +31 -0
  45. package/src/queries/courses/ListLectures.graphql +45 -0
  46. package/src/queries/donations/CreateDonation.graphql +18 -0
  47. package/src/queries/donations/GetDonationCampaign.graphql +28 -0
  48. package/src/queries/donations/ListDonationCampaigns.graphql +24 -0
  49. package/src/queries/events/CreateAttendance.graphql +16 -0
  50. package/src/queries/events/GetEvent.graphql +43 -0
  51. package/src/queries/events/ListEvents.graphql +32 -0
  52. package/src/queries/forms/CreateFormResponse.graphql +12 -0
  53. package/src/queries/forms/FormFields.graphql +35 -0
  54. package/src/queries/forms/FormResponseFields.graphql +15 -0
  55. package/src/queries/forms/GetForm.graphql +7 -0
  56. package/src/queries/forms/ListForms.graphql +20 -0
  57. package/src/queries/forms/UpdateFormResponse.graphql +12 -0
  58. package/src/queries/help-center/GetChannel.graphql +45 -0
  59. package/src/queries/kb/GetKbArticle.graphql +17 -0
  60. package/src/queries/kb/GetKbCollection.graphql +28 -0
  61. package/src/queries/kb/ListKbArticles.graphql +29 -0
  62. package/src/queries/kb/ListKbCollections.graphql +26 -0
  63. package/src/queries/people/GetEmployee.graphql +47 -0
  64. package/src/queries/people/ListEmployees.graphql +30 -0
  65. package/src/queries/search/Search.graphql +29 -0
  66. package/src/queries/stories/GetStory.graphql +15 -0
  67. package/src/queries/stories/ListStories.graphql +21 -0
  68. package/src/queries/system/CurrentUser.graphql +6 -0
  69. package/src/search.ts +18 -0
  70. package/src/stories.ts +29 -0
  71. package/src/types.ts +28 -0
  72. package/src/utils/paginate.ts +64 -0
  73. package/src/utils/relay.ts +8 -0
  74. package/tsconfig.json +8 -0
@@ -0,0 +1,47 @@
1
+ query GetEmployee($id: ID!, $weekStartingAt: ISO8601Date!) {
2
+ currentWorkspace {
3
+ employee(id: $id) {
4
+ id
5
+ employeeCode
6
+ user {
7
+ id
8
+ name
9
+ firstName
10
+ lastName
11
+ email
12
+ }
13
+ currentEmployment {
14
+ id
15
+ jobTitle
16
+ contractType
17
+ contractLevel
18
+ classification
19
+ isActive
20
+ startDate
21
+ endDate
22
+ fteRatio
23
+ primaryOffice {
24
+ id
25
+ name
26
+ }
27
+ }
28
+ todayTimeClocks {
29
+ id
30
+ beginsAt
31
+ finishesAt
32
+ kind
33
+ }
34
+ weeklyShifts(weekStartingAt: $weekStartingAt, first: 20) {
35
+ edges {
36
+ node {
37
+ id
38
+ name
39
+ beginsAt
40
+ finishesAt
41
+ aasmState
42
+ }
43
+ }
44
+ }
45
+ }
46
+ }
47
+ }
@@ -0,0 +1,30 @@
1
+ query ListEmployees($first: Int, $after: String) {
2
+ currentWorkspace {
3
+ employees(first: $first, after: $after) {
4
+ pageInfo {
5
+ hasNextPage
6
+ endCursor
7
+ }
8
+ edges {
9
+ node {
10
+ id
11
+ employeeCode
12
+ user {
13
+ id
14
+ name
15
+ firstName
16
+ lastName
17
+ email
18
+ }
19
+ currentEmployment {
20
+ id
21
+ jobTitle
22
+ contractType
23
+ isActive
24
+ startDate
25
+ }
26
+ }
27
+ }
28
+ }
29
+ }
30
+ }
@@ -0,0 +1,29 @@
1
+ query Search(
2
+ $models: [String!]
3
+ $params: SearchParams
4
+ $first: Int
5
+ $after: String
6
+ ) {
7
+ currentWorkspace {
8
+ id
9
+ search(models: $models, params: $params, first: $first, after: $after) {
10
+ totalCount
11
+ totalPages
12
+ term
13
+ took
14
+ pageInfo {
15
+ hasNextPage
16
+ endCursor
17
+ }
18
+ edges {
19
+ cursor
20
+ node {
21
+ __typename
22
+ ... on Node {
23
+ id
24
+ }
25
+ }
26
+ }
27
+ }
28
+ }
29
+ }
@@ -0,0 +1,15 @@
1
+ query GetStory($id: String!) {
2
+ currentWorkspace {
3
+ story(id: $id) {
4
+ id
5
+ name
6
+ body
7
+ cover
8
+ coverData
9
+ published
10
+ publishedAt
11
+ publicPath
12
+ publicUrl
13
+ }
14
+ }
15
+ }
@@ -0,0 +1,21 @@
1
+ query ListStories($first: Int, $after: String) {
2
+ currentWorkspace {
3
+ storiesConnection(first: $first, after: $after) {
4
+ pageInfo {
5
+ hasNextPage
6
+ endCursor
7
+ }
8
+ edges {
9
+ node {
10
+ id
11
+ name
12
+ cover
13
+ coverData
14
+ published
15
+ publishedAt
16
+ publicPath
17
+ }
18
+ }
19
+ }
20
+ }
21
+ }
@@ -0,0 +1,6 @@
1
+ query CurrentUser {
2
+ currentUser {
3
+ id
4
+ currentVisit
5
+ }
6
+ }
package/src/search.ts ADDED
@@ -0,0 +1,18 @@
1
+ import type { UiduClient } from './client';
2
+ import {
3
+ SearchDocument,
4
+ type SearchQuery,
5
+ type SearchQueryVariables,
6
+ } from './generated';
7
+
8
+ export type SearchResult = NonNullable<
9
+ NonNullable<SearchQuery['currentWorkspace']>['search']
10
+ >;
11
+
12
+ export async function search(
13
+ client: UiduClient,
14
+ variables: SearchQueryVariables,
15
+ ): Promise<SearchResult | null> {
16
+ const result = await client.query(SearchDocument, variables);
17
+ return result.currentWorkspace?.search ?? null;
18
+ }
package/src/stories.ts ADDED
@@ -0,0 +1,29 @@
1
+ import type { UiduClient } from './client';
2
+ import {
3
+ GetStoryDocument,
4
+ type GetStoryQuery,
5
+ type GetStoryQueryVariables,
6
+ ListStoriesDocument,
7
+ type ListStoriesQueryVariables,
8
+ } from './generated';
9
+ import { nodes } from './utils/relay';
10
+
11
+ export type Story = NonNullable<
12
+ NonNullable<GetStoryQuery['currentWorkspace']>['story']
13
+ >;
14
+
15
+ export async function getStory(
16
+ client: UiduClient,
17
+ variables: GetStoryQueryVariables,
18
+ ): Promise<Story | null> {
19
+ const result = await client.query(GetStoryDocument, variables);
20
+ return result.currentWorkspace?.story ?? null;
21
+ }
22
+
23
+ export async function listStories(
24
+ client: UiduClient,
25
+ variables: ListStoriesQueryVariables = {},
26
+ ) {
27
+ const result = await client.query(ListStoriesDocument, variables);
28
+ return nodes(result.currentWorkspace?.storiesConnection);
29
+ }
package/src/types.ts ADDED
@@ -0,0 +1,28 @@
1
+ export interface UiduClientConfig {
2
+ workspace: string;
3
+ publicToken?: string;
4
+ apiKey?: string;
5
+ endpoint?: string;
6
+ headers?: Record<string, string>;
7
+ }
8
+
9
+ export interface UiduErrorOptions {
10
+ code: string;
11
+ message: string;
12
+ graphQLErrors?: ReadonlyArray<unknown>;
13
+ cause?: unknown;
14
+ }
15
+
16
+ export class UiduError extends Error {
17
+ readonly code: string;
18
+ readonly graphQLErrors: ReadonlyArray<unknown>;
19
+ readonly cause?: unknown;
20
+
21
+ constructor(opts: UiduErrorOptions) {
22
+ super(opts.message);
23
+ this.name = 'UiduError';
24
+ this.code = opts.code;
25
+ this.graphQLErrors = opts.graphQLErrors ?? [];
26
+ this.cause = opts.cause;
27
+ }
28
+ }
@@ -0,0 +1,64 @@
1
+ import type { TypedDocumentNode } from '@graphql-typed-document-node/core';
2
+ import type { UiduClient } from '../client';
3
+
4
+ type RelayPageInfo = {
5
+ endCursor?: string | null;
6
+ hasNextPage: boolean;
7
+ };
8
+
9
+ type RelayConnection<TNode> = {
10
+ edges?: ReadonlyArray<{ node?: TNode | null } | null> | null;
11
+ pageInfo?: RelayPageInfo | null;
12
+ };
13
+
14
+ export type PaginateOptions<TResult, TVars, TNode> = {
15
+ /** Variables for the first page. `after` is set by paginate itself. */
16
+ variables?: Omit<TVars, 'after'>;
17
+ /** Pluck the Relay connection out of the query result. */
18
+ extract: (data: TResult) => RelayConnection<TNode> | null | undefined;
19
+ /** Safety bound on iterations. Defaults to 1000. */
20
+ maxPages?: number;
21
+ };
22
+
23
+ /**
24
+ * Walks every page of a Relay-style connection and returns a flat array of nodes.
25
+ *
26
+ * @example
27
+ * import { paginate, ListEventsDocument } from '@uidu/client';
28
+ * const all = await paginate(client, ListEventsDocument, {
29
+ * variables: { first: 100 },
30
+ * extract: (d) => d.currentWorkspace?.events,
31
+ * });
32
+ */
33
+ export async function paginate<
34
+ TResult,
35
+ TVars extends { after?: string | null },
36
+ TNode,
37
+ >(
38
+ client: UiduClient,
39
+ document: TypedDocumentNode<TResult, TVars>,
40
+ options: PaginateOptions<TResult, TVars, TNode>,
41
+ ): Promise<TNode[]> {
42
+ const { variables, extract, maxPages = 1000 } = options;
43
+ const out: TNode[] = [];
44
+ let after: string | null = null;
45
+ let pages = 0;
46
+
47
+ while (pages < maxPages) {
48
+ const vars = { ...(variables ?? {}), after } as unknown as TVars;
49
+ const result = await client.query(document, vars);
50
+ const conn = extract(result);
51
+ if (!conn) break;
52
+
53
+ for (const edge of conn.edges ?? []) {
54
+ if (edge?.node) out.push(edge.node);
55
+ }
56
+
57
+ const next = conn.pageInfo?.endCursor ?? null;
58
+ if (!conn.pageInfo?.hasNextPage || !next) break;
59
+ after = next;
60
+ pages++;
61
+ }
62
+
63
+ return out;
64
+ }
@@ -0,0 +1,8 @@
1
+ type Connection<T> = {
2
+ edges?: ReadonlyArray<{ node?: T | null } | null> | null;
3
+ };
4
+
5
+ export function nodes<T>(connection: Connection<T> | null | undefined): T[] {
6
+ if (!connection?.edges) return [];
7
+ return connection.edges.flatMap((edge) => (edge?.node ? [edge.node] : []));
8
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "rootDir": "src",
5
+ "outDir": "dist"
6
+ },
7
+ "include": ["src/**/*.ts", "src/**/*.tsx"]
8
+ }