@getclarify/nodejs-sdk 0.0.3 → 0.0.4

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 (41) hide show
  1. package/dist/cjs/client.d.ts +7 -0
  2. package/dist/cjs/client.d.ts.map +1 -1
  3. package/dist/cjs/client.js +8 -0
  4. package/dist/cjs/client.js.map +1 -1
  5. package/dist/cjs/index.d.ts +1 -0
  6. package/dist/cjs/index.d.ts.map +1 -1
  7. package/dist/cjs/index.js +3 -1
  8. package/dist/cjs/index.js.map +1 -1
  9. package/dist/cjs/json-api/link.d.ts +40 -0
  10. package/dist/cjs/json-api/link.d.ts.map +1 -0
  11. package/dist/cjs/json-api/link.js +68 -0
  12. package/dist/cjs/json-api/link.js.map +1 -0
  13. package/dist/cjs/resources/resources.d.ts +208 -0
  14. package/dist/cjs/resources/resources.d.ts.map +1 -0
  15. package/dist/cjs/resources/resources.js +172 -0
  16. package/dist/cjs/resources/resources.js.map +1 -0
  17. package/dist/esm/client.d.ts +7 -0
  18. package/dist/esm/client.d.ts.map +1 -1
  19. package/dist/esm/client.js +8 -0
  20. package/dist/esm/client.js.map +1 -1
  21. package/dist/esm/index.d.ts +1 -0
  22. package/dist/esm/index.d.ts.map +1 -1
  23. package/dist/esm/index.js +3 -1
  24. package/dist/esm/index.js.map +1 -1
  25. package/dist/esm/json-api/link.d.ts +40 -0
  26. package/dist/esm/json-api/link.d.ts.map +1 -0
  27. package/dist/esm/json-api/link.js +68 -0
  28. package/dist/esm/json-api/link.js.map +1 -0
  29. package/dist/esm/resources/resources.d.ts +208 -0
  30. package/dist/esm/resources/resources.d.ts.map +1 -0
  31. package/dist/esm/resources/resources.js +172 -0
  32. package/dist/esm/resources/resources.js.map +1 -0
  33. package/dist/types/client.d.ts +7 -0
  34. package/dist/types/client.d.ts.map +1 -1
  35. package/dist/types/index.d.ts +1 -0
  36. package/dist/types/index.d.ts.map +1 -1
  37. package/dist/types/json-api/link.d.ts +40 -0
  38. package/dist/types/json-api/link.d.ts.map +1 -0
  39. package/dist/types/resources/resources.d.ts +208 -0
  40. package/dist/types/resources/resources.d.ts.map +1 -0
  41. package/package.json +3 -3
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Internal representation of a resource that may have relationships
3
+ * either as raw refs (before linking) or as full resources (after linking).
4
+ */
5
+ interface AnyResource {
6
+ type: string;
7
+ id: string;
8
+ attributes: Record<string, unknown>;
9
+ relationships?: Record<string, {
10
+ data: unknown;
11
+ }>;
12
+ }
13
+ /**
14
+ * Minimal shape of a raw JSON:API document as returned by the API,
15
+ * before relationship references are resolved.
16
+ */
17
+ export interface JsonApiDocument {
18
+ data: AnyResource | AnyResource[];
19
+ included?: AnyResource[];
20
+ meta?: Record<string, unknown>;
21
+ links?: Record<string, string | undefined>;
22
+ }
23
+ /**
24
+ * Resolves relationship references in a JSON:API document by replacing
25
+ * `{ type, id }` stubs with the full resource objects from `included`.
26
+ *
27
+ * The function operates on a deep clone of the document so the original
28
+ * is never mutated.
29
+ *
30
+ * @throws {Error} If a referenced resource is not present in `included`
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * const linked = linkJsonApi(response);
35
+ * // linked.data.relationships.company.data now contains the full company object
36
+ * ```
37
+ */
38
+ export declare function linkJsonApi<T extends JsonApiDocument>(doc: T): T;
39
+ export {};
40
+ //# sourceMappingURL=link.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../../../src/json-api/link.ts"],"names":[],"mappings":"AAWA;;;GAGG;AACH,UAAU,WAAW;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACpC,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;CACnD;AAED;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,WAAW,GAAG,WAAW,EAAE,CAAC;IAClC,QAAQ,CAAC,EAAE,WAAW,EAAE,CAAC;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;CAC5C;AAMD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,eAAe,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAuBhE"}
@@ -0,0 +1,208 @@
1
+ import type { HttpClient } from '../http/http-client.js';
2
+ import type { PaginationLinks, PaginationMeta, ResolvedConfig, ResourceIdentifier } from '../types/index.js';
3
+ import { BaseResource } from './base-resource.js';
4
+ /**
5
+ * A resource with fully resolved inline relationships.
6
+ * Each entry in `relationships` holds the complete resource object(s),
7
+ * not bare `{ type, id }` references.
8
+ */
9
+ export interface ResourceLinked<T = Record<string, unknown>> {
10
+ type: string;
11
+ id: string;
12
+ attributes: T;
13
+ relationships: Record<string, {
14
+ data: ResourceLinked | ResourceLinked[] | null;
15
+ }>;
16
+ }
17
+ /**
18
+ * Single resource response from the resources endpoint.
19
+ */
20
+ export interface SingleResourceResponse<T = Record<string, unknown>> {
21
+ data: ResourceLinked<T>;
22
+ included?: ResourceLinked[];
23
+ meta?: Record<string, unknown>;
24
+ }
25
+ /**
26
+ * List resource response from the resources endpoint.
27
+ */
28
+ export interface ListResourceResponse<T = Record<string, unknown>> {
29
+ data: ResourceLinked<T>[];
30
+ included?: ResourceLinked[];
31
+ links?: PaginationLinks;
32
+ meta?: PaginationMeta;
33
+ }
34
+ /**
35
+ * Sort direction for resource list requests.
36
+ */
37
+ export type SortDirection = 'ASC' | 'DESC';
38
+ /**
39
+ * Parameters for retrieving a single resource.
40
+ */
41
+ export interface ResourceGetParams {
42
+ /** The entity type (e.g., 'meeting', 'company') */
43
+ type: string;
44
+ /** The resource ID */
45
+ id: string;
46
+ /** Relationships to include in the response */
47
+ include?: string[];
48
+ }
49
+ /**
50
+ * Parameters for listing resources.
51
+ *
52
+ * Filters support simple equality as well as operator-based filtering:
53
+ * - Simple: `{ name: 'Acme' }` → `filter[name]=Acme`
54
+ * - Operator: `{ amount: { 'Is greater than': '100' } }` → `filter[amount][Is greater than]=100`
55
+ * - Nested path: `{ 'meeting.users._id': userId }` → `filter[meeting.users._id]=userId`
56
+ */
57
+ export interface ResourceListParams {
58
+ /** The entity type (e.g., 'meeting', 'company') */
59
+ type: string;
60
+ /** Relationships to include in the response */
61
+ include?: string[];
62
+ /** Filter options */
63
+ filter?: Record<string, string | Record<string, string>>;
64
+ /** Sort order for the results */
65
+ sortOrder?: {
66
+ column: string;
67
+ dir: SortDirection;
68
+ };
69
+ /** Pagination options using offset/limit */
70
+ page?: {
71
+ offset?: number;
72
+ limit?: number;
73
+ };
74
+ }
75
+ /**
76
+ * A to-one or to-many relationship reference for use when creating a resource.
77
+ *
78
+ * - To-one: `{ data: { type: 'user', id: 'u-123' } }`
79
+ * - To-many: `{ data: [{ type: 'person', id: 'p-1' }, { type: 'person', id: 'p-2' }] }`
80
+ * - Clear to-one: `{ data: null }`
81
+ */
82
+ export interface ResourceRelationshipInput {
83
+ data: ResourceIdentifier | ResourceIdentifier[] | null;
84
+ }
85
+ /**
86
+ * Map of relationship name → relationship input, passed to `resources.create()`.
87
+ */
88
+ export type ResourceRelationshipsInput = Record<string, ResourceRelationshipInput>;
89
+ /**
90
+ * Parameters for creating a resource.
91
+ */
92
+ export interface ResourceCreateParams<T = Record<string, unknown>> {
93
+ /** The entity type (e.g., 'meeting', 'company') */
94
+ type: string;
95
+ /** The resource attributes */
96
+ attributes: T;
97
+ /**
98
+ * Relationships to set on the new resource.
99
+ * - To-one: `{ data: { type: 'user', id: 'u-123' } }`
100
+ * - To-many: `{ data: [{ type: 'person', id: 'p-1' }, { type: 'person', id: 'p-2' }] }`
101
+ * - Clear to-one: `{ data: null }`
102
+ */
103
+ relationships?: ResourceRelationshipsInput;
104
+ }
105
+ /**
106
+ * Parameters for deleting a resource.
107
+ */
108
+ export interface ResourceDeleteParams {
109
+ /** The entity type (e.g., 'meeting', 'company') */
110
+ type: string;
111
+ /** The resource ID to delete */
112
+ id: string;
113
+ }
114
+ /**
115
+ * Manages read and create operations for resources
116
+ * (objects accessed via the `/resources` endpoints).
117
+ *
118
+ * Responses include a `relationships` map with fully resolved related records.
119
+ *
120
+ * @example
121
+ * ```typescript
122
+ * // List meetings with attendees included
123
+ * const response = await clarify.resources.list({
124
+ * type: 'meeting',
125
+ * include: ['users', 'people'],
126
+ * filter: { 'meeting.users._id': currentUserId },
127
+ * });
128
+ *
129
+ * const firstMeetingUsers = response.data[0].relationships.users.data;
130
+ * ```
131
+ */
132
+ export declare class ResourcesResource extends BaseResource {
133
+ constructor(httpClient: HttpClient, config: ResolvedConfig);
134
+ private getEntityPath;
135
+ /**
136
+ * Retrieves a single resource by ID.
137
+ *
138
+ * @example
139
+ * ```typescript
140
+ * const response = await clarify.resources.get({
141
+ * type: 'meeting',
142
+ * id: 'abc123',
143
+ * include: ['users', 'people'],
144
+ * });
145
+ *
146
+ * const attendees = response.data.relationships.users.data;
147
+ * ```
148
+ */
149
+ get<T = Record<string, unknown>>(params: ResourceGetParams): Promise<SingleResourceResponse<T>>;
150
+ /**
151
+ * Lists resources with optional filtering, includes, and pagination.
152
+ *
153
+ * Filters support simple equality as well as operator-based filtering:
154
+ * - Simple: `{ name: 'Acme' }` → `filter[name]=Acme`
155
+ * - Operator: `{ amount: { 'Is greater than': '100' } }` → `filter[amount][Is greater than]=100`
156
+ * - Nested path: `{ 'meeting.users._id': userId }` → `filter[meeting.users._id]=userId`
157
+ *
158
+ * @example
159
+ * ```typescript
160
+ * const response = await clarify.resources.list({
161
+ * type: 'meeting',
162
+ * include: ['users'],
163
+ * filter: {
164
+ * 'meeting.users._id': currentUserId,
165
+ * start: { 'Is on or after': new Date().toISOString() },
166
+ * },
167
+ * sortOrder: { column: 'start', dir: 'ASC' },
168
+ * page: { limit: 50 },
169
+ * });
170
+ * ```
171
+ */
172
+ list<T = Record<string, unknown>>(params: ResourceListParams): Promise<ListResourceResponse<T>>;
173
+ /**
174
+ * Creates a new resource, optionally setting relationships at the same time.
175
+ *
176
+ * To-one and to-many relationships are both supported via `relationships`:
177
+ * - To-one: `{ data: { type: 'user', id: 'u-123' } }`
178
+ * - To-many: `{ data: [{ type: 'person', id: 'p-1' }, { type: 'person', id: 'p-2' }] }`
179
+ * - Clear to-one: `{ data: null }`
180
+ *
181
+ * @example
182
+ * ```typescript
183
+ * // Create a meeting and immediately set its attendees
184
+ * const response = await clarify.resources.create({
185
+ * type: 'meeting',
186
+ * attributes: {
187
+ * title: 'Team standup',
188
+ * start: new Date().toISOString(),
189
+ * },
190
+ * relationships: {
191
+ * users: { data: [{ type: 'user', id: 'u-1' }, { type: 'user', id: 'u-2' }] },
192
+ * people: { data: [{ type: 'person', id: 'p-1' }] },
193
+ * },
194
+ * });
195
+ * ```
196
+ */
197
+ create<T = Record<string, unknown>>(params: ResourceCreateParams<T>): Promise<SingleResourceResponse<T>>;
198
+ /**
199
+ * Deletes a resource by ID.
200
+ *
201
+ * @example
202
+ * ```typescript
203
+ * await clarify.resources.delete({ type: 'meeting', id: 'abc123' });
204
+ * ```
205
+ */
206
+ delete(params: ResourceDeleteParams): Promise<void>;
207
+ }
208
+ //# sourceMappingURL=resources.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resources.d.ts","sourceRoot":"","sources":["../../../src/resources/resources.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC7G,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD;;;;GAIG;AACH,MAAM,WAAW,cAAc,C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;OAqBG;IACG,IAAI,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACpC,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC;IA4CnC;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACG,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACtC,MAAM,EAAE,oBAAoB,CAAC,CAAC,CAAC,GAC9B,OAAO,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC;IAkBrC;;;;;;;OAOG;IACG,MAAM,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;CAS1D"}
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@getclarify/nodejs-sdk",
3
3
  "description": "JavaScript/TypeScript SDK for Clarify platform",
4
- "version": "0.0.3",
4
+ "version": "0.0.4",
5
5
  "devDependencies": {
6
- "@vitest/coverage-v8": "^3.1.2",
6
+ "@vitest/coverage-v8": "^3.2.4",
7
7
  "eslint": "^9.39.0",
8
8
  "eslint-config-prettier": "^10.1.8",
9
9
  "prettier": "^3.7.4",
10
10
  "typescript": "^5.9.3",
11
11
  "typescript-eslint": "^8.47.0",
12
12
  "vite": "^7.3.1",
13
- "vitest": "^3.0.8"
13
+ "vitest": "^3.2.4"
14
14
  },
15
15
  "engines": {
16
16
  "node": ">=24"