@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.
- package/dist/cjs/client.d.ts +7 -0
- package/dist/cjs/client.d.ts.map +1 -1
- package/dist/cjs/client.js +8 -0
- package/dist/cjs/client.js.map +1 -1
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/json-api/link.d.ts +40 -0
- package/dist/cjs/json-api/link.d.ts.map +1 -0
- package/dist/cjs/json-api/link.js +68 -0
- package/dist/cjs/json-api/link.js.map +1 -0
- package/dist/cjs/resources/resources.d.ts +208 -0
- package/dist/cjs/resources/resources.d.ts.map +1 -0
- package/dist/cjs/resources/resources.js +172 -0
- package/dist/cjs/resources/resources.js.map +1 -0
- package/dist/esm/client.d.ts +7 -0
- package/dist/esm/client.d.ts.map +1 -1
- package/dist/esm/client.js +8 -0
- package/dist/esm/client.js.map +1 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +3 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/json-api/link.d.ts +40 -0
- package/dist/esm/json-api/link.d.ts.map +1 -0
- package/dist/esm/json-api/link.js +68 -0
- package/dist/esm/json-api/link.js.map +1 -0
- package/dist/esm/resources/resources.d.ts +208 -0
- package/dist/esm/resources/resources.d.ts.map +1 -0
- package/dist/esm/resources/resources.js +172 -0
- package/dist/esm/resources/resources.js.map +1 -0
- package/dist/types/client.d.ts +7 -0
- package/dist/types/client.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/json-api/link.d.ts +40 -0
- package/dist/types/json-api/link.d.ts.map +1 -0
- package/dist/types/resources/resources.d.ts +208 -0
- package/dist/types/resources/resources.d.ts.map +1 -0
- package/package.json +3 -3
package/dist/esm/client.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.ClarifyClient = void 0;
|
|
|
4
4
|
const index_js_1 = require("./errors/index.js");
|
|
5
5
|
const http_client_js_1 = require("./http/http-client.js");
|
|
6
6
|
const records_js_1 = require("./resources/records.js");
|
|
7
|
+
const resources_js_1 = require("./resources/resources.js");
|
|
7
8
|
const index_js_2 = require("./types/index.js");
|
|
8
9
|
/**
|
|
9
10
|
* The main client for interacting with the Clarify API.
|
|
@@ -31,6 +32,12 @@ const index_js_2 = require("./types/index.js");
|
|
|
31
32
|
class ClarifyClient {
|
|
32
33
|
/** Resource for managing records */
|
|
33
34
|
records;
|
|
35
|
+
/**
|
|
36
|
+
* Resource for querying and creating resources via the `/resources` endpoints.
|
|
37
|
+
* Responses include relationships and an `included` array.
|
|
38
|
+
* Use `linkJsonApi` to resolve relationship references into inline objects.
|
|
39
|
+
*/
|
|
40
|
+
resources;
|
|
34
41
|
config;
|
|
35
42
|
httpClient;
|
|
36
43
|
/**
|
|
@@ -43,6 +50,7 @@ class ClarifyClient {
|
|
|
43
50
|
this.config = this.resolveConfig(config);
|
|
44
51
|
this.httpClient = new http_client_js_1.HttpClient(this.config);
|
|
45
52
|
this.records = new records_js_1.RecordsResource(this.httpClient, this.config);
|
|
53
|
+
this.resources = new resources_js_1.ResourcesResource(this.httpClient, this.config);
|
|
46
54
|
}
|
|
47
55
|
/**
|
|
48
56
|
* Resolves configuration with defaults and validates required fields.
|
package/dist/esm/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":";;;AAAA,gDAA2D;AAC3D,0DAAmD;AACnD,uDAAyD;
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":";;;AAAA,gDAA2D;AAC3D,0DAAmD;AACnD,uDAAyD;AACzD,2DAA6D;AAE7D,+CAAkD;AAElD;;;;;;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,CAAC,MAAM;YACrB,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,yBAAc,CAAC,OAAO;YACjD,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,yBAAc,CAAC,OAAO;YACjD,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC;SACzD,CAAC;IACJ,CAAC;CACF;AA3DD,sCA2DC"}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -3,4 +3,5 @@ export { ClarifyError, ClarifyApiError, ClarifyValidationError, ClarifyTimeoutEr
|
|
|
3
3
|
export type { ApiErrorDetail } from './errors/index.js';
|
|
4
4
|
export type { ClarifyClientConfig, ResourceIdentifier, Resource, ResourceCreate, ResourceUpdate, SingleResponse, ListResponse, PaginationLinks, PaginationMeta, PaginationOptions, FilterOptions, SortOptions, ListOptions, GetRecordOptions, FieldOperationRules, UpdateRecordOptions, } from './types/index.js';
|
|
5
5
|
export { RecordsResource } from './resources/records.js';
|
|
6
|
+
export { ResourcesResource, type ResourceLinked, type SingleResourceResponse, type ListResourceResponse, type SortDirection, type ResourceGetParams, type ResourceListParams, type ResourceRelationshipInput, type ResourceRelationshipsInput, type ResourceCreateParams, type ResourceDeleteParams, } from './resources/resources.js';
|
|
6
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAG5C,OAAO,EACL,YAAY,EACZ,eAAe,EACf,sBAAsB,EACtB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAGxD,YAAY,EACV,mBAAmB,EACnB,kBAAkB,EAClB,QAAQ,EACR,cAAc,EACd,cAAc,EACd,cAAc,EACd,YAAY,EACZ,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,aAAa,EACb,WAAW,EACX,WAAW,EACX,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAG5C,OAAO,EACL,YAAY,EACZ,eAAe,EACf,sBAAsB,EACtB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAGxD,YAAY,EACV,mBAAmB,EACnB,kBAAkB,EAClB,QAAQ,EACR,cAAc,EACd,cAAc,EACd,cAAc,EACd,YAAY,EACZ,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,aAAa,EACb,WAAW,EACX,WAAW,EACX,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EACL,iBAAiB,EACjB,KAAK,cAAc,EACnB,KAAK,sBAAsB,EAC3B,KAAK,oBAAoB,EACzB,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,yBAAyB,EAC9B,KAAK,0BAA0B,EAC/B,KAAK,oBAAoB,EACzB,KAAK,oBAAoB,GAC1B,MAAM,0BAA0B,CAAC"}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RecordsResource = exports.ClarifyNetworkError = exports.ClarifyTimeoutError = exports.ClarifyValidationError = exports.ClarifyApiError = exports.ClarifyError = exports.ClarifyClient = void 0;
|
|
3
|
+
exports.ResourcesResource = exports.RecordsResource = exports.ClarifyNetworkError = exports.ClarifyTimeoutError = exports.ClarifyValidationError = exports.ClarifyApiError = exports.ClarifyError = exports.ClarifyClient = void 0;
|
|
4
4
|
// Main client export
|
|
5
5
|
var client_js_1 = require("./client.js");
|
|
6
6
|
Object.defineProperty(exports, "ClarifyClient", { enumerable: true, get: function () { return client_js_1.ClarifyClient; } });
|
|
@@ -14,4 +14,6 @@ Object.defineProperty(exports, "ClarifyNetworkError", { enumerable: true, get: f
|
|
|
14
14
|
// Resource exports for advanced usage
|
|
15
15
|
var records_js_1 = require("./resources/records.js");
|
|
16
16
|
Object.defineProperty(exports, "RecordsResource", { enumerable: true, get: function () { return records_js_1.RecordsResource; } });
|
|
17
|
+
var resources_js_1 = require("./resources/resources.js");
|
|
18
|
+
Object.defineProperty(exports, "ResourcesResource", { enumerable: true, get: function () { return resources_js_1.ResourcesResource; } });
|
|
17
19
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,qBAAqB;AACrB,yCAA4C;AAAnC,0GAAA,aAAa,OAAA;AAEtB,gBAAgB;AAChB,8CAM2B;AALzB,wGAAA,YAAY,OAAA;AACZ,2GAAA,eAAe,OAAA;AACf,kHAAA,sBAAsB,OAAA;AACtB,+GAAA,mBAAmB,OAAA;AACnB,+GAAA,mBAAmB,OAAA;AAwBrB,sCAAsC;AACtC,qDAAyD;AAAhD,6GAAA,eAAe,OAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,qBAAqB;AACrB,yCAA4C;AAAnC,0GAAA,aAAa,OAAA;AAEtB,gBAAgB;AAChB,8CAM2B;AALzB,wGAAA,YAAY,OAAA;AACZ,2GAAA,eAAe,OAAA;AACf,kHAAA,sBAAsB,OAAA;AACtB,+GAAA,mBAAmB,OAAA;AACnB,+GAAA,mBAAmB,OAAA;AAwBrB,sCAAsC;AACtC,qDAAyD;AAAhD,6GAAA,eAAe,OAAA;AACxB,yDAYkC;AAXhC,iHAAA,iBAAiB,OAAA"}
|
|
@@ -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,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// NOTE: This is a standalone adaptation of the shared implementation at
|
|
3
|
+
// packages/shared/src/json-api/link.ts. If you update the core linking logic
|
|
4
|
+
// here, apply the same change there (and vice versa).
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.linkJsonApi = linkJsonApi;
|
|
7
|
+
function makeKey(r) {
|
|
8
|
+
return `${r.type}:${r.id}`;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Resolves relationship references in a JSON:API document by replacing
|
|
12
|
+
* `{ type, id }` stubs with the full resource objects from `included`.
|
|
13
|
+
*
|
|
14
|
+
* The function operates on a deep clone of the document so the original
|
|
15
|
+
* is never mutated.
|
|
16
|
+
*
|
|
17
|
+
* @throws {Error} If a referenced resource is not present in `included`
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const linked = linkJsonApi(response);
|
|
22
|
+
* // linked.data.relationships.company.data now contains the full company object
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
function linkJsonApi(doc) {
|
|
26
|
+
const document = structuredClone(doc);
|
|
27
|
+
const resourceMap = new Map();
|
|
28
|
+
const items = Array.isArray(document.data)
|
|
29
|
+
? document.data
|
|
30
|
+
: [document.data];
|
|
31
|
+
for (const r of items) {
|
|
32
|
+
resourceMap.set(makeKey(r), r);
|
|
33
|
+
}
|
|
34
|
+
if (document.included) {
|
|
35
|
+
for (const r of document.included) {
|
|
36
|
+
resourceMap.set(makeKey(r), r);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
for (const r of resourceMap.values()) {
|
|
40
|
+
linkResource(r, resourceMap);
|
|
41
|
+
}
|
|
42
|
+
return document;
|
|
43
|
+
}
|
|
44
|
+
function linkResource(resource, resourceMap) {
|
|
45
|
+
if (!resource.relationships) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
for (const rel of Object.values(resource.relationships)) {
|
|
49
|
+
if (!rel.data) {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (Array.isArray(rel.data)) {
|
|
53
|
+
rel.data = rel.data.map((ref) => resolveRef(ref, resourceMap));
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
rel.data = resolveRef(rel.data, resourceMap);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function resolveRef(ref, resourceMap) {
|
|
61
|
+
const key = makeKey(ref);
|
|
62
|
+
const resource = resourceMap.get(key);
|
|
63
|
+
if (!resource) {
|
|
64
|
+
throw new Error(`JSON:API payload is malformed: "${key}" was referenced in a relationship but not found in included`);
|
|
65
|
+
}
|
|
66
|
+
return resource;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=link.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"link.js","sourceRoot":"","sources":["../../../src/json-api/link.ts"],"names":[],"mappings":";AAAA,wEAAwE;AACxE,6EAA6E;AAC7E,sDAAsD;;AAkDtD,kCAuBC;AA1CD,SAAS,OAAO,CAAC,CAAS;IACxB,OAAO,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,EAAE,CAAC;AAC7B,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,SAAgB,WAAW,CAA4B,GAAM;IAC3D,MAAM,QAAQ,GAAG,eAAe,CAAC,GAAG,CAAM,CAAC;IAC3C,MAAM,WAAW,GAAG,IAAI,GAAG,EAA4B,CAAC;IAExD,MAAM,KAAK,GAAkB,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC;QACvD,CAAC,CAAE,QAAQ,CAAC,IAAsB;QAClC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAmB,CAAC,CAAC;IAEnC,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE,CAAC;QACtB,WAAW,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACjC,CAAC;IAED,IAAI,QAAQ,CAAC,QAAQ,EAAE,CAAC;QACtB,KAAK,MAAM,CAAC,IAAI,QAAQ,CAAC,QAAQ,EAAE,CAAC;YAClC,WAAW,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACjC,CAAC;IACH,CAAC;IAED,KAAK,MAAM,CAAC,IAAI,WAAW,CAAC,MAAM,EAAE,EAAE,CAAC;QACrC,YAAY,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC;IAC/B,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,SAAS,YAAY,CACnB,QAAqB,EACrB,WAA0C;IAE1C,IAAI,CAAC,QAAQ,CAAC,aAAa,EAAE,CAAC;QAC5B,OAAO;IACT,CAAC;IAED,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC;QACxD,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;YACd,SAAS;QACX,CAAC;QAED,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;YAC3B,GAAG,CAAC,IAAgB,GAAG,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAW,EAAE,EAAE,CACnD,UAAU,CAAC,GAAG,EAAE,WAAW,CAAC,CAC7B,CAAC;QACJ,CAAC;aAAM,CAAC;YACL,GAAG,CAAC,IAAgB,GAAG,UAAU,CAChC,GAAG,CAAC,IAAc,EAClB,WAAW,CACZ,CAAC;QACJ,CAAC;IACH,CAAC;AACH,CAAC;AAED,SAAS,UAAU,CACjB,GAAW,EACX,WAA0C;IAE1C,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IACzB,MAAM,QAAQ,GAAG,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAEtC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CACb,mCAAmC,GAAG,8DAA8D,CACrG,CAAC;IACJ,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -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,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACzD,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,CAAC,CAAC;IACd,aAAa,EAAE,MAAM,CACnB,MAAM,EACN;QAAE,IAAI,EAAE,cAAc,GAAG,cAAc,EAAE,GAAG,IAAI,CAAA;KAAE,CACnD,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAA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;IAkBrC;;;;;;;OAOG;IACG,MAAM,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;CAS1D"}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ResourcesResource = void 0;
|
|
4
|
+
const link_js_1 = require("../json-api/link.js");
|
|
5
|
+
const base_resource_js_1 = require("./base-resource.js");
|
|
6
|
+
/**
|
|
7
|
+
* Manages read and create operations for resources
|
|
8
|
+
* (objects accessed via the `/resources` endpoints).
|
|
9
|
+
*
|
|
10
|
+
* Responses include a `relationships` map with fully resolved related records.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* // List meetings with attendees included
|
|
15
|
+
* const response = await clarify.resources.list({
|
|
16
|
+
* type: 'meeting',
|
|
17
|
+
* include: ['users', 'people'],
|
|
18
|
+
* filter: { 'meeting.users._id': currentUserId },
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* const firstMeetingUsers = response.data[0].relationships.users.data;
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
class ResourcesResource extends base_resource_js_1.BaseResource {
|
|
25
|
+
constructor(httpClient, config) {
|
|
26
|
+
super(httpClient, config);
|
|
27
|
+
}
|
|
28
|
+
getEntityPath(type) {
|
|
29
|
+
return `${this.basePath}/objects/${type}/resources`;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Retrieves a single resource by ID.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* const response = await clarify.resources.get({
|
|
37
|
+
* type: 'meeting',
|
|
38
|
+
* id: 'abc123',
|
|
39
|
+
* include: ['users', 'people'],
|
|
40
|
+
* });
|
|
41
|
+
*
|
|
42
|
+
* const attendees = response.data.relationships.users.data;
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
async get(params) {
|
|
46
|
+
const query = {};
|
|
47
|
+
if (params.include && params.include.length > 0) {
|
|
48
|
+
query.include = params.include.join(',');
|
|
49
|
+
}
|
|
50
|
+
const raw = await this.httpClient.request({
|
|
51
|
+
method: 'GET',
|
|
52
|
+
path: `${this.getEntityPath(params.type)}/${params.id}`,
|
|
53
|
+
query,
|
|
54
|
+
});
|
|
55
|
+
return (0, link_js_1.linkJsonApi)(raw);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Lists resources with optional filtering, includes, and pagination.
|
|
59
|
+
*
|
|
60
|
+
* Filters support simple equality as well as operator-based filtering:
|
|
61
|
+
* - Simple: `{ name: 'Acme' }` → `filter[name]=Acme`
|
|
62
|
+
* - Operator: `{ amount: { 'Is greater than': '100' } }` → `filter[amount][Is greater than]=100`
|
|
63
|
+
* - Nested path: `{ 'meeting.users._id': userId }` → `filter[meeting.users._id]=userId`
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* const response = await clarify.resources.list({
|
|
68
|
+
* type: 'meeting',
|
|
69
|
+
* include: ['users'],
|
|
70
|
+
* filter: {
|
|
71
|
+
* 'meeting.users._id': currentUserId,
|
|
72
|
+
* start: { 'Is on or after': new Date().toISOString() },
|
|
73
|
+
* },
|
|
74
|
+
* sortOrder: { column: 'start', dir: 'ASC' },
|
|
75
|
+
* page: { limit: 50 },
|
|
76
|
+
* });
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
async list(params) {
|
|
80
|
+
const query = {};
|
|
81
|
+
if (params.include && params.include.length > 0) {
|
|
82
|
+
query.include = params.include.join(',');
|
|
83
|
+
}
|
|
84
|
+
if (params.page?.offset !== undefined) {
|
|
85
|
+
query['page[offset]'] = params.page.offset;
|
|
86
|
+
}
|
|
87
|
+
if (params.page?.limit !== undefined) {
|
|
88
|
+
query['page[limit]'] = params.page.limit;
|
|
89
|
+
}
|
|
90
|
+
if (params.sortOrder) {
|
|
91
|
+
query['sortOrder[column]'] = params.sortOrder.column;
|
|
92
|
+
query['sortOrder[dir]'] = params.sortOrder.dir;
|
|
93
|
+
}
|
|
94
|
+
if (params.filter) {
|
|
95
|
+
for (const [key, value] of Object.entries(params.filter)) {
|
|
96
|
+
if (typeof value === 'string') {
|
|
97
|
+
query[`filter[${key}]`] = value;
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
for (const [op, opValue] of Object.entries(value)) {
|
|
101
|
+
query[`filter[${key}][${op}]`] = opValue;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
const raw = await this.httpClient.request({
|
|
107
|
+
method: 'GET',
|
|
108
|
+
path: this.getEntityPath(params.type),
|
|
109
|
+
query,
|
|
110
|
+
});
|
|
111
|
+
return (0, link_js_1.linkJsonApi)(raw);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Creates a new resource, optionally setting relationships at the same time.
|
|
115
|
+
*
|
|
116
|
+
* To-one and to-many relationships are both supported via `relationships`:
|
|
117
|
+
* - To-one: `{ data: { type: 'user', id: 'u-123' } }`
|
|
118
|
+
* - To-many: `{ data: [{ type: 'person', id: 'p-1' }, { type: 'person', id: 'p-2' }] }`
|
|
119
|
+
* - Clear to-one: `{ data: null }`
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```typescript
|
|
123
|
+
* // Create a meeting and immediately set its attendees
|
|
124
|
+
* const response = await clarify.resources.create({
|
|
125
|
+
* type: 'meeting',
|
|
126
|
+
* attributes: {
|
|
127
|
+
* title: 'Team standup',
|
|
128
|
+
* start: new Date().toISOString(),
|
|
129
|
+
* },
|
|
130
|
+
* relationships: {
|
|
131
|
+
* users: { data: [{ type: 'user', id: 'u-1' }, { type: 'user', id: 'u-2' }] },
|
|
132
|
+
* people: { data: [{ type: 'person', id: 'p-1' }] },
|
|
133
|
+
* },
|
|
134
|
+
* });
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
async create(params) {
|
|
138
|
+
const raw = await this.httpClient.request({
|
|
139
|
+
method: 'POST',
|
|
140
|
+
path: this.getEntityPath(params.type),
|
|
141
|
+
body: {
|
|
142
|
+
data: {
|
|
143
|
+
type: params.type,
|
|
144
|
+
attributes: params.attributes,
|
|
145
|
+
...(params.relationships
|
|
146
|
+
? { relationships: params.relationships }
|
|
147
|
+
: undefined),
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
return (0, link_js_1.linkJsonApi)(raw);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Deletes a resource by ID.
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```typescript
|
|
158
|
+
* await clarify.resources.delete({ type: 'meeting', id: 'abc123' });
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
async delete(params) {
|
|
162
|
+
// The /resources endpoint does not yet expose a DELETE route, so we
|
|
163
|
+
// delegate to the equivalent /records path. This is a convenience shim —
|
|
164
|
+
// the resources API should eventually support deletion directly.
|
|
165
|
+
await this.httpClient.request({
|
|
166
|
+
method: 'DELETE',
|
|
167
|
+
path: `${this.basePath}/objects/${params.type}/records/${params.id}`,
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
exports.ResourcesResource = ResourcesResource;
|
|
172
|
+
//# sourceMappingURL=resources.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resources.js","sourceRoot":"","sources":["../../../src/resources/resources.ts"],"names":[],"mappings":";;;AAAA,iDAAwE;AAGxE,yDAAkD;AA2HlD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAa,iBAAkB,SAAQ,+BAAY;IACjD,YAAY,UAAsB,EAAE,MAAsB;QACxD,KAAK,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IAC5B,CAAC;IAEO,aAAa,CAAC,IAAY;QAChC,OAAO,GAAG,IAAI,CAAC,QAAQ,YAA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,IAAI;oBACjB,UAAU,EAAE,MAAM,CAAC,UAAU;oBAC7B,GAAG,CAAC,MAAM,CAAC,aAAa;wBACtB,CAAC,CAAC,EAAE,aAAa,EAAE,MAAM,CAAC,aAAa,EAAE;wBACzC,CAAC,CAAC,SAAS,CAAC;iBACf;aACF;SACF,CAAC,CAAC;QAEH,OAAO,IAAA,qBAAW,EAAC,GAAG,CAAyC,CAAC;IAClE,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,MAAM,CAAC,MAA4B;QACvC,oEAAoE;QACpE,yEAAyE;QACzE,iEAAiE;QACjE,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAAwB;YACnD,MAAM,EAAE,QAAQ;YAChB,IAAI,EAAE,GAAG,IAAI,CAAC,QAAQ,YAAY,MAAM,CAAC,IAAI,YAAY,MAAM,CAAC,EAAE,EAAE;SACrE,CAAC,CAAC;IACL,CAAC;CACF;AA1KD,8CA0KC"}
|
package/dist/types/client.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { RecordsResource } from './resources/records.js';
|
|
2
|
+
import { ResourcesResource } from './resources/resources.js';
|
|
2
3
|
import type { ClarifyClientConfig } from './types/index.js';
|
|
3
4
|
/**
|
|
4
5
|
* The main client for interacting with the Clarify API.
|
|
@@ -26,6 +27,12 @@ import type { ClarifyClientConfig } from './types/index.js';
|
|
|
26
27
|
export declare class ClarifyClient {
|
|
27
28
|
/** Resource for managing records */
|
|
28
29
|
readonly records: RecordsResource;
|
|
30
|
+
/**
|
|
31
|
+
* Resource for querying and creating resources via the `/resources` endpoints.
|
|
32
|
+
* Responses include relationships and an `included` array.
|
|
33
|
+
* Use `linkJsonApi` to resolve relationship references into inline objects.
|
|
34
|
+
*/
|
|
35
|
+
readonly resources: ResourcesResource;
|
|
29
36
|
private readonly config;
|
|
30
37
|
private readonly httpClient;
|
|
31
38
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,KAAK,EAAE,mBAAmB,EAAkB,MAAM,kBAAkB,CAAC;AAG5E;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,aAAa;IACxB,oCAAoC;IACpC,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAC;IAElC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAiB;IACxC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAa;IAExC;;;;;OAKG;gBACS,MAAM,EAAE,mBAAmB;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,KAAK,EAAE,mBAAmB,EAAkB,MAAM,kBAAkB,CAAC;AAG5E;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,aAAa;IACxB,oCAAoC;IACpC,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAC;IAElC;;;;OAIG;IACH,QAAQ,CAAC,SAAS,EAAE,iBAAiB,CAAC;IAEtC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAiB;IACxC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAa;IAExC;;;;;OAKG;gBACS,MAAM,EAAE,mBAAmB;IAQvC;;OAEG;IACH,OAAO,CAAC,aAAa;CA4BtB"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -3,4 +3,5 @@ export { ClarifyError, ClarifyApiError, ClarifyValidationError, ClarifyTimeoutEr
|
|
|
3
3
|
export type { ApiErrorDetail } from './errors/index.js';
|
|
4
4
|
export type { ClarifyClientConfig, ResourceIdentifier, Resource, ResourceCreate, ResourceUpdate, SingleResponse, ListResponse, PaginationLinks, PaginationMeta, PaginationOptions, FilterOptions, SortOptions, ListOptions, GetRecordOptions, FieldOperationRules, UpdateRecordOptions, } from './types/index.js';
|
|
5
5
|
export { RecordsResource } from './resources/records.js';
|
|
6
|
+
export { ResourcesResource, type ResourceLinked, type SingleResourceResponse, type ListResourceResponse, type SortDirection, type ResourceGetParams, type ResourceListParams, type ResourceRelationshipInput, type ResourceRelationshipsInput, type ResourceCreateParams, type ResourceDeleteParams, } from './resources/resources.js';
|
|
6
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAG5C,OAAO,EACL,YAAY,EACZ,eAAe,EACf,sBAAsB,EACtB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAGxD,YAAY,EACV,mBAAmB,EACnB,kBAAkB,EAClB,QAAQ,EACR,cAAc,EACd,cAAc,EACd,cAAc,EACd,YAAY,EACZ,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,aAAa,EACb,WAAW,EACX,WAAW,EACX,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAG5C,OAAO,EACL,YAAY,EACZ,eAAe,EACf,sBAAsB,EACtB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAGxD,YAAY,EACV,mBAAmB,EACnB,kBAAkB,EAClB,QAAQ,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