@mymehq/sdk 1.0.0 → 2.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.
- package/dist/index.d.ts +80 -6
- package/dist/index.js +128 -9
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ConflictSnapshot, ItemState, CreateItemInput, Item, PaginatedResult, ItemWithMetadata, Version, Metadata, SearchResult, Thread, TypeSchema, CreateKeyInput, ApiKey, CreateWebhookInput, Webhook, UpdateWebhookInput, WebhookDelivery } from '@mymehq/shared';
|
|
1
|
+
import { ConflictSnapshot, ItemState, CreateItemInput, Item, PaginatedResult, ItemWithMetadata, Version, Edge, Metadata, SearchResult, Thread, CreateEdgeInput, EdgeTypeSchema, TypeSchema, CreateKeyInput, ApiKey, CreateWebhookInput, Webhook, UpdateWebhookInput, WebhookDelivery, TenantConfig } from '@mymehq/shared';
|
|
2
2
|
export { ApiKey, ConflictSnapshot, CreateItemInput, CreateKeyInput, Item, ItemState, Metadata, PaginatedResult, SearchResult, Thread, TypeSchema, Version } from '@mymehq/shared';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -36,7 +36,6 @@ interface ClientConfig {
|
|
|
36
36
|
}
|
|
37
37
|
interface UpdateOptions {
|
|
38
38
|
version?: number;
|
|
39
|
-
thread_id?: string | null;
|
|
40
39
|
/**
|
|
41
40
|
* Override the client's default conflict strategy for this update.
|
|
42
41
|
* - `"auto"`: auto-merge non-conflicting fields (default)
|
|
@@ -51,9 +50,21 @@ interface ListFilters {
|
|
|
51
50
|
type?: string;
|
|
52
51
|
state?: ItemState;
|
|
53
52
|
source?: string;
|
|
53
|
+
/** Filter to items whose parent-of source is this id. Kept as a
|
|
54
|
+
* server-side convenience alias after the parent_id column was
|
|
55
|
+
* dropped in Wave 2 PR 4; the server translates it into an
|
|
56
|
+
* `edge[parent-of]` existence check. */
|
|
54
57
|
parent_id?: string;
|
|
58
|
+
/** Filter to items in this thread. Server translates to
|
|
59
|
+
* `edge[in-thread]` check after the thread_id column was dropped. */
|
|
55
60
|
thread_id?: string;
|
|
56
61
|
root_only?: boolean;
|
|
62
|
+
/** When set, restricts the result to library items (true) or ambient
|
|
63
|
+
* items (false). Per V0 spec, the default unrestricted view returns
|
|
64
|
+
* library items only on a fresh /items query — the explicit filter
|
|
65
|
+
* here lets callers opt into the ambient slice or be explicit about
|
|
66
|
+
* the library slice. */
|
|
67
|
+
library?: boolean;
|
|
57
68
|
tags?: string[];
|
|
58
69
|
filter?: string;
|
|
59
70
|
sort?: "created_at" | "updated_at" | "timestamp";
|
|
@@ -71,7 +82,6 @@ interface SearchFilters {
|
|
|
71
82
|
}
|
|
72
83
|
interface MetadataInput {
|
|
73
84
|
tags?: string[];
|
|
74
|
-
about?: string[];
|
|
75
85
|
}
|
|
76
86
|
declare class MymeClient {
|
|
77
87
|
private readonly transport;
|
|
@@ -80,16 +90,36 @@ declare class MymeClient {
|
|
|
80
90
|
private readonly cdnBaseUrl?;
|
|
81
91
|
constructor(config: ClientConfig);
|
|
82
92
|
readonly items: {
|
|
83
|
-
create: (input: CreateItemInput
|
|
93
|
+
create: (input: CreateItemInput & {
|
|
94
|
+
/** Atomic edges payload: for each edge type, listed ids become
|
|
95
|
+
* targets with the new item as source. Replaces legacy parent_id
|
|
96
|
+
* / thread_id / about which were dropped in Wave 2 PR 4. */
|
|
97
|
+
edges?: Record<string, string[]>;
|
|
98
|
+
}) => Promise<Item>;
|
|
84
99
|
get: (id: string) => Promise<Item>;
|
|
85
100
|
list: (filters?: ListFilters) => Promise<PaginatedResult<Item>>;
|
|
86
101
|
listWithMetadata: (filters?: Omit<ListFilters, "include">) => Promise<PaginatedResult<ItemWithMetadata>>;
|
|
87
102
|
update: (id: string, properties: Record<string, unknown>, options?: UpdateOptions) => Promise<Item>;
|
|
88
103
|
delete: (id: string) => Promise<void>;
|
|
104
|
+
/** Permanently delete a trashed item (admin only). Item must already
|
|
105
|
+
* be in state "trashed"; returns 400 otherwise. Irreversible. */
|
|
106
|
+
purge: (id: string) => Promise<void>;
|
|
89
107
|
restore: (id: string) => Promise<Item>;
|
|
90
108
|
transition: (id: string, state: string) => Promise<Item>;
|
|
91
109
|
versions: (id: string) => Promise<Version[]>;
|
|
92
110
|
stats: () => Promise<Record<string, number>>;
|
|
111
|
+
/** Outbound edges from this item. Shortcut for edges.listFromSource. */
|
|
112
|
+
edges: (itemId: string, filters?: {
|
|
113
|
+
edge_type?: string | string[];
|
|
114
|
+
limit?: number;
|
|
115
|
+
cursor?: string;
|
|
116
|
+
}) => Promise<PaginatedResult<Edge>>;
|
|
117
|
+
/** Inbound edges targeting this item. Shortcut for edges.listToTarget. */
|
|
118
|
+
backrefs: (itemId: string, filters?: {
|
|
119
|
+
edge_type?: string | string[];
|
|
120
|
+
limit?: number;
|
|
121
|
+
cursor?: string;
|
|
122
|
+
}) => Promise<PaginatedResult<Edge>>;
|
|
93
123
|
};
|
|
94
124
|
readonly metadata: {
|
|
95
125
|
get: (itemId: string) => Promise<Metadata>;
|
|
@@ -115,6 +145,34 @@ declare class MymeClient {
|
|
|
115
145
|
addItem: (threadId: string, itemId: string) => Promise<Item>;
|
|
116
146
|
removeItem: (threadId: string, itemId: string) => Promise<Item>;
|
|
117
147
|
};
|
|
148
|
+
readonly edges: {
|
|
149
|
+
/** Create a single edge. Server enforces cardinality / type
|
|
150
|
+
* constraints / cycle prevention; throws on violation. */
|
|
151
|
+
create: (input: CreateEdgeInput) => Promise<Edge>;
|
|
152
|
+
/** Update properties on an existing edge. edge_type / source / target
|
|
153
|
+
* are immutable; server rejects with 400. */
|
|
154
|
+
update: (id: string, properties: Record<string, unknown>) => Promise<Edge>;
|
|
155
|
+
delete: (id: string) => Promise<void>;
|
|
156
|
+
/** Outbound edges — items where this id is source. Filter by edge type
|
|
157
|
+
* (comma-separated string or array of type ids). */
|
|
158
|
+
listFromSource: (sourceId: string, filters?: {
|
|
159
|
+
edge_type?: string | string[];
|
|
160
|
+
limit?: number;
|
|
161
|
+
cursor?: string;
|
|
162
|
+
}) => Promise<PaginatedResult<Edge>>;
|
|
163
|
+
/** Inbound edges — items where this id is target. */
|
|
164
|
+
listToTarget: (targetId: string, filters?: {
|
|
165
|
+
edge_type?: string | string[];
|
|
166
|
+
limit?: number;
|
|
167
|
+
cursor?: string;
|
|
168
|
+
}) => Promise<PaginatedResult<Edge>>;
|
|
169
|
+
/** Custom edge-type registration + listing. */
|
|
170
|
+
types: {
|
|
171
|
+
create: (schema: EdgeTypeSchema) => Promise<EdgeTypeSchema>;
|
|
172
|
+
list: () => Promise<EdgeTypeSchema[]>;
|
|
173
|
+
delete: (id: string) => Promise<void>;
|
|
174
|
+
};
|
|
175
|
+
};
|
|
118
176
|
readonly blobs: {
|
|
119
177
|
upload: (data: Uint8Array | ArrayBuffer, mimeType: string) => Promise<{
|
|
120
178
|
hash: string;
|
|
@@ -135,8 +193,13 @@ declare class MymeClient {
|
|
|
135
193
|
}) => Promise<void>;
|
|
136
194
|
};
|
|
137
195
|
readonly keys: {
|
|
138
|
-
|
|
139
|
-
|
|
196
|
+
/** Creates an API key. The raw key value is returned exactly once on
|
|
197
|
+
* creation; the rest of the shape mirrors the persisted ApiKey record
|
|
198
|
+
* (source, default_origin, default_library, type_permissions, and
|
|
199
|
+
* extension_permissions are all stamped at create time and visible
|
|
200
|
+
* here so the caller doesn't need a follow-up GET /keys to inspect
|
|
201
|
+
* them). */
|
|
202
|
+
create: (input: CreateKeyInput) => Promise<ApiKey & {
|
|
140
203
|
key: string;
|
|
141
204
|
}>;
|
|
142
205
|
list: () => Promise<ApiKey[]>;
|
|
@@ -152,6 +215,17 @@ declare class MymeClient {
|
|
|
152
215
|
limit?: number;
|
|
153
216
|
}) => Promise<WebhookDelivery[]>;
|
|
154
217
|
};
|
|
218
|
+
/** Tenant-scoped configuration (per-type ambient retention overrides
|
|
219
|
+
* today; future tenant-level settings will live here). All endpoints
|
|
220
|
+
* are admin-only. */
|
|
221
|
+
readonly tenants: {
|
|
222
|
+
/** Returns the current tenant's config. Empty object when nothing
|
|
223
|
+
* is configured. */
|
|
224
|
+
getConfig: () => Promise<TenantConfig>;
|
|
225
|
+
/** Replaces the current tenant's config. Server validates that any
|
|
226
|
+
* type IDs in retention overrides resolve in the registry. */
|
|
227
|
+
setConfig: (config: TenantConfig) => Promise<TenantConfig>;
|
|
228
|
+
};
|
|
155
229
|
private throwRawError;
|
|
156
230
|
}
|
|
157
231
|
|
package/dist/index.js
CHANGED
|
@@ -118,7 +118,12 @@ var HttpTransport = class {
|
|
|
118
118
|
if (!query) return url;
|
|
119
119
|
const params = new URLSearchParams();
|
|
120
120
|
for (const [key, value] of Object.entries(query)) {
|
|
121
|
-
if (value
|
|
121
|
+
if (value === void 0) continue;
|
|
122
|
+
if (Array.isArray(value)) {
|
|
123
|
+
params.set(key, value.join(","));
|
|
124
|
+
} else if (typeof value === "boolean") {
|
|
125
|
+
params.set(key, value ? "true" : "false");
|
|
126
|
+
} else {
|
|
122
127
|
params.set(key, String(value));
|
|
123
128
|
}
|
|
124
129
|
}
|
|
@@ -168,15 +173,14 @@ function toConflictError(response, clientPatch) {
|
|
|
168
173
|
clientPatch
|
|
169
174
|
);
|
|
170
175
|
}
|
|
171
|
-
async function handleConflictUpdate(transport, itemId, clientPatch, version, strategy, resolver
|
|
176
|
+
async function handleConflictUpdate(transport, itemId, clientPatch, version, strategy, resolver) {
|
|
172
177
|
let properties = clientPatch;
|
|
173
178
|
let currentVersion = version;
|
|
174
179
|
for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
|
|
175
180
|
const result = await transport.requestWithConflict("PATCH", `/items/${itemId}`, {
|
|
176
181
|
body: {
|
|
177
182
|
properties,
|
|
178
|
-
version: currentVersion
|
|
179
|
-
...threadId !== void 0 && { thread_id: threadId }
|
|
183
|
+
version: currentVersion
|
|
180
184
|
}
|
|
181
185
|
});
|
|
182
186
|
if (!isConflictResponse(result)) {
|
|
@@ -276,13 +280,20 @@ var MymeClient = class {
|
|
|
276
280
|
properties,
|
|
277
281
|
version,
|
|
278
282
|
strategy,
|
|
279
|
-
options?.resolve
|
|
280
|
-
options?.thread_id
|
|
283
|
+
options?.resolve
|
|
281
284
|
);
|
|
282
285
|
},
|
|
283
286
|
delete: async (id) => {
|
|
284
287
|
await this.transport.request("DELETE", `/items/${id}`);
|
|
285
288
|
},
|
|
289
|
+
/** Permanently delete a trashed item (admin only). Item must already
|
|
290
|
+
* be in state "trashed"; returns 400 otherwise. Irreversible. */
|
|
291
|
+
purge: async (id) => {
|
|
292
|
+
await this.transport.request(
|
|
293
|
+
"DELETE",
|
|
294
|
+
`/items/${id}/purge`
|
|
295
|
+
);
|
|
296
|
+
},
|
|
286
297
|
restore: async (id) => {
|
|
287
298
|
const res = await this.transport.request(
|
|
288
299
|
"POST",
|
|
@@ -310,7 +321,11 @@ var MymeClient = class {
|
|
|
310
321
|
"GET",
|
|
311
322
|
"/items/stats"
|
|
312
323
|
);
|
|
313
|
-
}
|
|
324
|
+
},
|
|
325
|
+
/** Outbound edges from this item. Shortcut for edges.listFromSource. */
|
|
326
|
+
edges: (itemId, filters) => this.edges.listFromSource(itemId, filters),
|
|
327
|
+
/** Inbound edges targeting this item. Shortcut for edges.listToTarget. */
|
|
328
|
+
backrefs: (itemId, filters) => this.edges.listToTarget(itemId, filters)
|
|
314
329
|
};
|
|
315
330
|
// ---- Metadata ----
|
|
316
331
|
metadata = {
|
|
@@ -424,6 +439,80 @@ var MymeClient = class {
|
|
|
424
439
|
return res.item;
|
|
425
440
|
}
|
|
426
441
|
};
|
|
442
|
+
// ---- Edges ----
|
|
443
|
+
edges = {
|
|
444
|
+
/** Create a single edge. Server enforces cardinality / type
|
|
445
|
+
* constraints / cycle prevention; throws on violation. */
|
|
446
|
+
create: async (input) => {
|
|
447
|
+
const res = await this.transport.request(
|
|
448
|
+
"POST",
|
|
449
|
+
"/edges",
|
|
450
|
+
{ body: input }
|
|
451
|
+
);
|
|
452
|
+
return res.edge;
|
|
453
|
+
},
|
|
454
|
+
/** Update properties on an existing edge. edge_type / source / target
|
|
455
|
+
* are immutable; server rejects with 400. */
|
|
456
|
+
update: async (id, properties) => {
|
|
457
|
+
const res = await this.transport.request(
|
|
458
|
+
"PATCH",
|
|
459
|
+
`/edges/${id}`,
|
|
460
|
+
{ body: { properties } }
|
|
461
|
+
);
|
|
462
|
+
return res.edge;
|
|
463
|
+
},
|
|
464
|
+
delete: async (id) => {
|
|
465
|
+
await this.transport.request("DELETE", `/edges/${id}`);
|
|
466
|
+
},
|
|
467
|
+
/** Outbound edges — items where this id is source. Filter by edge type
|
|
468
|
+
* (comma-separated string or array of type ids). */
|
|
469
|
+
listFromSource: async (sourceId, filters) => {
|
|
470
|
+
const edgeType = Array.isArray(filters?.edge_type) ? filters.edge_type.join(",") : filters?.edge_type;
|
|
471
|
+
return this.transport.request(
|
|
472
|
+
"GET",
|
|
473
|
+
`/items/${sourceId}/edges`,
|
|
474
|
+
{
|
|
475
|
+
query: {
|
|
476
|
+
...edgeType && { edge_type: edgeType },
|
|
477
|
+
...filters?.limit !== void 0 && { limit: filters.limit },
|
|
478
|
+
...filters?.cursor && { cursor: filters.cursor }
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
);
|
|
482
|
+
},
|
|
483
|
+
/** Inbound edges — items where this id is target. */
|
|
484
|
+
listToTarget: async (targetId, filters) => {
|
|
485
|
+
const edgeType = Array.isArray(filters?.edge_type) ? filters.edge_type.join(",") : filters?.edge_type;
|
|
486
|
+
return this.transport.request(
|
|
487
|
+
"GET",
|
|
488
|
+
`/items/${targetId}/backrefs`,
|
|
489
|
+
{
|
|
490
|
+
query: {
|
|
491
|
+
...edgeType && { edge_type: edgeType },
|
|
492
|
+
...filters?.limit !== void 0 && { limit: filters.limit },
|
|
493
|
+
...filters?.cursor && { cursor: filters.cursor }
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
);
|
|
497
|
+
},
|
|
498
|
+
/** Custom edge-type registration + listing. */
|
|
499
|
+
types: {
|
|
500
|
+
create: async (schema) => {
|
|
501
|
+
const res = await this.transport.request("POST", "/edges/types", { body: schema });
|
|
502
|
+
return res.edge_type;
|
|
503
|
+
},
|
|
504
|
+
list: async () => {
|
|
505
|
+
const res = await this.transport.request("GET", "/edges/types");
|
|
506
|
+
return res.edge_types;
|
|
507
|
+
},
|
|
508
|
+
delete: async (id) => {
|
|
509
|
+
await this.transport.request(
|
|
510
|
+
"DELETE",
|
|
511
|
+
`/edges/types/${id}`
|
|
512
|
+
);
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
};
|
|
427
516
|
// ---- Blobs ----
|
|
428
517
|
blobs = {
|
|
429
518
|
upload: async (data, mimeType) => {
|
|
@@ -491,9 +580,16 @@ var MymeClient = class {
|
|
|
491
580
|
};
|
|
492
581
|
// ---- Keys ----
|
|
493
582
|
keys = {
|
|
583
|
+
/** Creates an API key. The raw key value is returned exactly once on
|
|
584
|
+
* creation; the rest of the shape mirrors the persisted ApiKey record
|
|
585
|
+
* (source, default_origin, default_library, type_permissions, and
|
|
586
|
+
* extension_permissions are all stamped at create time and visible
|
|
587
|
+
* here so the caller doesn't need a follow-up GET /keys to inspect
|
|
588
|
+
* them). */
|
|
494
589
|
create: async (input) => {
|
|
495
|
-
|
|
496
|
-
|
|
590
|
+
return this.transport.request("POST", "/keys", {
|
|
591
|
+
body: input
|
|
592
|
+
});
|
|
497
593
|
},
|
|
498
594
|
list: async () => {
|
|
499
595
|
const res = await this.transport.request(
|
|
@@ -540,6 +636,29 @@ var MymeClient = class {
|
|
|
540
636
|
return res.deliveries;
|
|
541
637
|
}
|
|
542
638
|
};
|
|
639
|
+
// ---- Tenants (admin) ----
|
|
640
|
+
/** Tenant-scoped configuration (per-type ambient retention overrides
|
|
641
|
+
* today; future tenant-level settings will live here). All endpoints
|
|
642
|
+
* are admin-only. */
|
|
643
|
+
tenants = {
|
|
644
|
+
/** Returns the current tenant's config. Empty object when nothing
|
|
645
|
+
* is configured. */
|
|
646
|
+
getConfig: async () => {
|
|
647
|
+
return this.transport.request(
|
|
648
|
+
"GET",
|
|
649
|
+
"/tenants/current/config"
|
|
650
|
+
);
|
|
651
|
+
},
|
|
652
|
+
/** Replaces the current tenant's config. Server validates that any
|
|
653
|
+
* type IDs in retention overrides resolve in the registry. */
|
|
654
|
+
setConfig: async (config) => {
|
|
655
|
+
return this.transport.request(
|
|
656
|
+
"PUT",
|
|
657
|
+
"/tenants/current/config",
|
|
658
|
+
{ body: config }
|
|
659
|
+
);
|
|
660
|
+
}
|
|
661
|
+
};
|
|
543
662
|
// ---- Internal ----
|
|
544
663
|
throwRawError(status, body) {
|
|
545
664
|
const parsed = body;
|