@mymehq/sdk 1.0.1 → 2.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Myme
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
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) => Promise<Item>;
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
- create: (input: CreateKeyInput) => Promise<{
139
- id: string;
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
@@ -173,15 +173,14 @@ function toConflictError(response, clientPatch) {
173
173
  clientPatch
174
174
  );
175
175
  }
176
- async function handleConflictUpdate(transport, itemId, clientPatch, version, strategy, resolver, threadId) {
176
+ async function handleConflictUpdate(transport, itemId, clientPatch, version, strategy, resolver) {
177
177
  let properties = clientPatch;
178
178
  let currentVersion = version;
179
179
  for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
180
180
  const result = await transport.requestWithConflict("PATCH", `/items/${itemId}`, {
181
181
  body: {
182
182
  properties,
183
- version: currentVersion,
184
- ...threadId !== void 0 && { thread_id: threadId }
183
+ version: currentVersion
185
184
  }
186
185
  });
187
186
  if (!isConflictResponse(result)) {
@@ -281,13 +280,20 @@ var MymeClient = class {
281
280
  properties,
282
281
  version,
283
282
  strategy,
284
- options?.resolve,
285
- options?.thread_id
283
+ options?.resolve
286
284
  );
287
285
  },
288
286
  delete: async (id) => {
289
287
  await this.transport.request("DELETE", `/items/${id}`);
290
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
+ },
291
297
  restore: async (id) => {
292
298
  const res = await this.transport.request(
293
299
  "POST",
@@ -315,7 +321,11 @@ var MymeClient = class {
315
321
  "GET",
316
322
  "/items/stats"
317
323
  );
318
- }
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)
319
329
  };
320
330
  // ---- Metadata ----
321
331
  metadata = {
@@ -429,6 +439,80 @@ var MymeClient = class {
429
439
  return res.item;
430
440
  }
431
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
+ };
432
516
  // ---- Blobs ----
433
517
  blobs = {
434
518
  upload: async (data, mimeType) => {
@@ -496,9 +580,16 @@ var MymeClient = class {
496
580
  };
497
581
  // ---- Keys ----
498
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). */
499
589
  create: async (input) => {
500
- const res = await this.transport.request("POST", "/keys", { body: input });
501
- return { id: res.id, key: res.key };
590
+ return this.transport.request("POST", "/keys", {
591
+ body: input
592
+ });
502
593
  },
503
594
  list: async () => {
504
595
  const res = await this.transport.request(
@@ -545,6 +636,29 @@ var MymeClient = class {
545
636
  return res.deliveries;
546
637
  }
547
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
+ };
548
662
  // ---- Internal ----
549
663
  throwRawError(status, body) {
550
664
  const parsed = body;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mymehq/sdk",
3
- "version": "1.0.1",
3
+ "version": "2.0.1",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org",
@@ -16,7 +16,7 @@
16
16
  "dist"
17
17
  ],
18
18
  "dependencies": {
19
- "@mymehq/shared": "1.0.0"
19
+ "@mymehq/shared": "2.0.1"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@types/node": "^22.0.0",