@mymehq/sdk 3.7.0 → 4.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 CHANGED
@@ -1,4 +1,4 @@
1
- import { MergeStrategy, ConflictSnapshot, MergePolicy, ItemState, Item, CreateItemInput, PaginatedResult, ItemWithMetadata, Version, Edge, Metadata, SearchResult, CreateEdgeInput, EdgeTypeSchema, TypeSchema, CreateKeyInput, ApiKey, UpdateKeyInput, CreateWebhookInput, Webhook, UpdateWebhookInput, WebhookDelivery, TenantConfig } from '@mymehq/shared';
1
+ import { MergeStrategy, ConflictSnapshot, MergePolicy, ItemState, Tier, Item, CreateItemInput, PaginatedResult, ItemWithMetadata, Version, Edge, Metadata, SearchResult, CreateEdgeInput, EdgeTypeSchema, TypeSchema, CreateKeyInput, ApiKey, UpdateKeyInput, CreateWebhookInput, Webhook, UpdateWebhookInput, WebhookDelivery, TenantConfig } from '@mymehq/shared';
2
2
  export { ApiKey, ConflictSnapshot, CreateItemInput, CreateKeyInput, Item, ItemState, MergePolicy, MergeStrategy, Metadata, PaginatedResult, SearchResult, TypeSchema, UpdateKeyInput, Version } from '@mymehq/shared';
3
3
 
4
4
  /**
@@ -94,9 +94,9 @@ interface UpdateOptions {
94
94
  conflict?: ConflictStrategy;
95
95
  /** Custom conflict resolver (required when `conflict` is `"callback"`). */
96
96
  resolve?: ConflictResolver;
97
- /** Toggle library / ambient state. Independent of the version-merge path
98
- * for `properties`; a library-only update never conflicts. */
99
- library?: boolean;
97
+ /** Toggle the tier (`library` `feed`). Independent of the version-merge
98
+ * path for `properties`; a tier-only update never conflicts. */
99
+ tier?: Tier;
100
100
  /**
101
101
  * Item type. Required by the `auto` strategy when a `keep_both_copies`
102
102
  * conflict spawns a sibling item. Omit to let the SDK pre-fetch it —
@@ -115,10 +115,9 @@ interface ListFilters {
115
115
  type?: string;
116
116
  state?: ItemState;
117
117
  source?: string;
118
- /** Tri-value library filter. `true` restricts to library items; `false`
119
- * restricts to ambient items; omitting the field returns both (the V0
120
- * default). */
121
- library?: boolean;
118
+ /** Tier filter. `"library"` restricts to library items; `"feed"` restricts
119
+ * to feed items; `"all"` (or omitting the field) returns both. */
120
+ tier?: Tier | "all";
122
121
  tags?: string[];
123
122
  /** Filter-language expression, e.g. `edge[parent-of] eq "<id>"` or
124
123
  * `edge[parent-of] not_exists`. The filter language replaces the
@@ -152,8 +151,8 @@ type ItemWithExtensions = Item & {
152
151
  interface SearchFilters {
153
152
  type?: string;
154
153
  state?: ItemState;
155
- /** Tri-value library filter, matching `ListFilters.library`. */
156
- library?: boolean;
154
+ /** Tier filter, matching `ListFilters.tier`. */
155
+ tier?: Tier | "all";
157
156
  /** Items must have ALL specified tags (AND semantics). Matches
158
157
  * `ListFilters.tags` and `/items?tags=`. */
159
158
  tags?: string[];
@@ -170,7 +169,7 @@ interface BulkItemInput {
170
169
  type: string;
171
170
  properties?: Record<string, unknown>;
172
171
  state?: ItemState;
173
- library?: boolean;
172
+ tier?: Tier;
174
173
  timestamp?: string;
175
174
  /** Ignored on the wire — server stamps `source` from the credential.
176
175
  * Kept on the input shape for round-trip parity with /export output. */
@@ -217,6 +216,47 @@ interface BulkResult {
217
216
  /** Present only on archive-restore paths. */
218
217
  blobs_imported?: number;
219
218
  }
219
+ /** One edge to create or upsert in a `POST /edges/bulk` call. */
220
+ interface BulkEdgeInputItem {
221
+ /** Optional server-id override. Server-generated UUIDv7 otherwise. */
222
+ id?: string;
223
+ source_id: string;
224
+ target_id: string;
225
+ edge_type: string;
226
+ properties?: Record<string, unknown>;
227
+ }
228
+ interface BulkEdgeInput {
229
+ edges: BulkEdgeInputItem[];
230
+ /** Default: `"upsert"`. On duplicate `(source_id, target_id, edge_type)`:
231
+ * `"upsert"` replaces properties in place; `"create_only"` skips with
232
+ * reason `"duplicate_edge"`. */
233
+ mode?: BulkMode;
234
+ /** Default: `true`. When false, errors are collected per edge and the
235
+ * batch continues past failures. */
236
+ atomic?: boolean;
237
+ /** Default: `false`. Per-edge `edge.created` / `edge.deleted` webhook
238
+ * events are suppressed on bulk writes unless the caller opts in. */
239
+ emit_events?: boolean;
240
+ }
241
+ interface BulkEdgeResultEntry {
242
+ index: number;
243
+ outcome: BulkOutcome;
244
+ id?: string;
245
+ reason?: string;
246
+ error?: {
247
+ code: string;
248
+ message: string;
249
+ };
250
+ }
251
+ interface BulkEdgeResult {
252
+ counts: {
253
+ created: number;
254
+ updated: number;
255
+ skipped: number;
256
+ errored: number;
257
+ };
258
+ results: BulkEdgeResultEntry[];
259
+ }
220
260
  /** Filter shape for `POST /items/bulk_action`. Mirrors the `GET /items`
221
261
  * query grammar — every field is AND-composed, `filter` accepts the
222
262
  * full filter-SQL DSL. */
@@ -224,7 +264,7 @@ interface BulkActionFilter {
224
264
  type?: string;
225
265
  state?: ItemState;
226
266
  source?: string;
227
- library?: boolean;
267
+ tier?: Tier | "all";
228
268
  tags?: string[];
229
269
  since?: string;
230
270
  until?: string;
@@ -254,8 +294,8 @@ type BulkActionInput = (BulkActionBase & {
254
294
  add?: string[];
255
295
  remove?: string[];
256
296
  }) | (BulkActionBase & {
257
- action: "update_library";
258
- library: boolean;
297
+ action: "update_tier";
298
+ tier: Tier;
259
299
  }) | (BulkActionBase & {
260
300
  action: "update_properties";
261
301
  patch: Record<string, unknown>;
@@ -388,6 +428,21 @@ declare class MymeClient {
388
428
  * are immutable; server rejects with 400. */
389
429
  update: (id: string, properties: Record<string, unknown>) => Promise<Edge>;
390
430
  delete: (id: string) => Promise<void>;
431
+ /**
432
+ * Create or upsert many edges in one call (admin-only). Up to 5000
433
+ * edges per call.
434
+ *
435
+ * Modes: `"upsert"` (default) replaces properties on existing
436
+ * `(source_id, target_id, edge_type)` triples; `"create_only"` surfaces
437
+ * duplicates as `skipped` with reason `"duplicate_edge"`. `atomic: true`
438
+ * (default) rolls back the whole batch on any failure — per-edge errors
439
+ * for non-atomic mode land in each result entry.
440
+ *
441
+ * Sibling to `items.bulk` for the edges half of mode-transition
442
+ * migrations (where cross-item edges can't reliably ride along as
443
+ * inline-edge payloads on the item writes).
444
+ */
445
+ bulk: (input: BulkEdgeInput) => Promise<BulkEdgeResult>;
391
446
  /** Outbound edges — items where this id is source. Filter by edge type
392
447
  * (comma-separated string or array of type ids). */
393
448
  listFromSource: (sourceId: string, filters?: {
@@ -430,7 +485,7 @@ declare class MymeClient {
430
485
  readonly keys: {
431
486
  /** Creates an API key. The raw key value is returned exactly once on
432
487
  * creation; the rest of the shape mirrors the persisted ApiKey record
433
- * (source, default_origin, default_library, type_permissions, and
488
+ * (source, default_origin, default_tier, type_permissions, and
434
489
  * extension_permissions are all stamped at create time and visible
435
490
  * here so the caller doesn't need a follow-up GET /keys to inspect
436
491
  * them). */
@@ -518,6 +573,40 @@ declare class ConflictError extends MymeError {
518
573
  constructor(current: ConflictSnapshot, ancestor: ConflictSnapshot, conflictingFields: string[], clientPatch: Record<string, unknown>);
519
574
  }
520
575
 
576
+ /**
577
+ * Authoring helper for declaring custom Myme types in TypeScript (TSC42 §7).
578
+ *
579
+ * The function is a no-op at runtime — it returns its input unchanged. Its
580
+ * value is at the type level: `defineType` constrains the argument to a
581
+ * structurally-valid `TypeSchema`, surfacing field-shape mistakes at compile
582
+ * time rather than at `POST /types` rejection time. Pair with the SDK's
583
+ * `client.types.register(schema)` call to register the type with the server.
584
+ *
585
+ * Example:
586
+ *
587
+ * ```ts
588
+ * import { defineType } from "@mymehq/sdk";
589
+ *
590
+ * export const acmeDeal = defineType({
591
+ * id: "acme.deal",
592
+ * label: "Deal",
593
+ * description: "A sales pipeline opportunity",
594
+ * version: 1,
595
+ * fields: {
596
+ * name: { type: "string", description: "Deal name", required: true },
597
+ * amount: { type: "number", description: "Deal value (USD)" },
598
+ * },
599
+ * });
600
+ *
601
+ * await client.types.register(acmeDeal);
602
+ * ```
603
+ *
604
+ * The helper preserves the literal types of the schema (via the generic
605
+ * parameter), so downstream code that reads `acmeDeal.fields.name.type` sees
606
+ * the narrowed literal `"string"` rather than the wide `FieldType` union.
607
+ */
608
+ declare function defineType<T extends TypeSchema>(schema: T): T;
609
+
521
610
  /**
522
611
  * Reason a webhook signature did not validate. Receivers should treat
523
612
  * any non-`valid` result as "do not trust this delivery".
@@ -570,4 +659,4 @@ interface VerifyWebhookSignatureInput {
570
659
  */
571
660
  declare function verifyWebhookSignature(input: VerifyWebhookSignatureInput): WebhookVerifyResult;
572
661
 
573
- export { type BulkActionErrorEntry, type BulkActionFilter, type BulkActionInput, type BulkActionResult, type BulkInput, type BulkItemInput, type BulkMode, type BulkOutcome, type BulkResult, type BulkResultEntry, type ClientConfig, type ConflictAutoMergeListener, type ConflictAutoMergedEvent, type ConflictData, ConflictError, type ConflictResolver, type ConflictStrategy, ForbiddenError, type ItemWithExtensions, type ListFilters, type MetadataInput, MymeClient, MymeError, NotFoundError, type SearchFilters, UnauthorizedError, type UpdateOptions, ValidationError, type VerifyWebhookSignatureInput, type WebhookVerifyReason, type WebhookVerifyResult, verifyWebhookSignature };
662
+ export { type BulkActionErrorEntry, type BulkActionFilter, type BulkActionInput, type BulkActionResult, type BulkEdgeInput, type BulkEdgeInputItem, type BulkEdgeResult, type BulkEdgeResultEntry, type BulkInput, type BulkItemInput, type BulkMode, type BulkOutcome, type BulkResult, type BulkResultEntry, type ClientConfig, type ConflictAutoMergeListener, type ConflictAutoMergedEvent, type ConflictData, ConflictError, type ConflictResolver, type ConflictStrategy, ForbiddenError, type ItemWithExtensions, type ListFilters, type MetadataInput, MymeClient, MymeError, NotFoundError, type SearchFilters, UnauthorizedError, type UpdateOptions, ValidationError, type VerifyWebhookSignatureInput, type WebhookVerifyReason, type WebhookVerifyResult, defineType, verifyWebhookSignature };
package/dist/index.js CHANGED
@@ -239,7 +239,7 @@ function toConflictError(response, clientPatch) {
239
239
  clientPatch
240
240
  );
241
241
  }
242
- async function handleConflictUpdate(transport, itemId, itemType, clientPatch, version, strategy, resolver, library, onAutoMerge) {
242
+ async function handleConflictUpdate(transport, itemId, itemType, clientPatch, version, strategy, resolver, tier, onAutoMerge) {
243
243
  let properties = clientPatch;
244
244
  let currentVersion = version;
245
245
  let pendingAutoMergeEvent;
@@ -248,7 +248,7 @@ async function handleConflictUpdate(transport, itemId, itemType, clientPatch, ve
248
248
  body: {
249
249
  properties,
250
250
  version: currentVersion,
251
- ...library !== void 0 && { library }
251
+ ...tier !== void 0 && { tier }
252
252
  }
253
253
  });
254
254
  if (!isConflictResponse(result)) {
@@ -401,7 +401,7 @@ var MymeClient = class {
401
401
  version,
402
402
  strategy,
403
403
  options?.resolve,
404
- options?.library,
404
+ options?.tier,
405
405
  onAutoMerge
406
406
  );
407
407
  },
@@ -613,6 +613,25 @@ var MymeClient = class {
613
613
  delete: async (id) => {
614
614
  await this.transport.request("DELETE", `/edges/${id}`);
615
615
  },
616
+ /**
617
+ * Create or upsert many edges in one call (admin-only). Up to 5000
618
+ * edges per call.
619
+ *
620
+ * Modes: `"upsert"` (default) replaces properties on existing
621
+ * `(source_id, target_id, edge_type)` triples; `"create_only"` surfaces
622
+ * duplicates as `skipped` with reason `"duplicate_edge"`. `atomic: true`
623
+ * (default) rolls back the whole batch on any failure — per-edge errors
624
+ * for non-atomic mode land in each result entry.
625
+ *
626
+ * Sibling to `items.bulk` for the edges half of mode-transition
627
+ * migrations (where cross-item edges can't reliably ride along as
628
+ * inline-edge payloads on the item writes).
629
+ */
630
+ bulk: async (input) => {
631
+ return this.transport.request("POST", "/edges/bulk", {
632
+ body: input
633
+ });
634
+ },
616
635
  /** Outbound edges — items where this id is source. Filter by edge type
617
636
  * (comma-separated string or array of type ids). */
618
637
  listFromSource: async (sourceId, filters) => {
@@ -731,7 +750,7 @@ var MymeClient = class {
731
750
  keys = {
732
751
  /** Creates an API key. The raw key value is returned exactly once on
733
752
  * creation; the rest of the shape mirrors the persisted ApiKey record
734
- * (source, default_origin, default_library, type_permissions, and
753
+ * (source, default_origin, default_tier, type_permissions, and
735
754
  * extension_permissions are all stamped at create time and visible
736
755
  * here so the caller doesn't need a follow-up GET /keys to inspect
737
756
  * them). */
@@ -843,6 +862,11 @@ var MymeClient = class {
843
862
  }
844
863
  };
845
864
 
865
+ // src/define-type.ts
866
+ function defineType(schema) {
867
+ return schema;
868
+ }
869
+
846
870
  // src/webhooks.ts
847
871
  import { createHmac, timingSafeEqual } from "crypto";
848
872
  var STRIPE_HEADER_RE = /^t=(\d+),v1=([0-9a-f]+)$/;
@@ -881,5 +905,6 @@ export {
881
905
  NotFoundError,
882
906
  UnauthorizedError,
883
907
  ValidationError,
908
+ defineType,
884
909
  verifyWebhookSignature
885
910
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mymehq/sdk",
3
- "version": "3.7.0",
3
+ "version": "4.0.0",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org",
@@ -16,13 +16,13 @@
16
16
  "dist"
17
17
  ],
18
18
  "dependencies": {
19
- "@mymehq/shared": "3.5.0"
19
+ "@mymehq/shared": "4.0.0"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@types/node": "^22.0.0",
23
23
  "tsup": "^8.5.1",
24
24
  "typescript": "^6.0.2",
25
- "@mymehq/server": "0.0.1"
25
+ "@mymehq/server": "1.0.0"
26
26
  },
27
27
  "scripts": {
28
28
  "build": "tsup",