@mymehq/sdk 3.4.0 → 3.5.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 +19 -1
- package/dist/index.js +15 -4
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -69,6 +69,21 @@ interface ClientConfig {
|
|
|
69
69
|
cdnBaseUrl?: string;
|
|
70
70
|
}
|
|
71
71
|
interface UpdateOptions {
|
|
72
|
+
/**
|
|
73
|
+
* Version the caller expects the item to currently be at. When provided,
|
|
74
|
+
* the SDK skips the upfront `GET /items/:id` and PATCHes directly. If the
|
|
75
|
+
* server's actual version differs, the update 409s through the usual
|
|
76
|
+
* conflict path — the caller's retry policy is out of scope here.
|
|
77
|
+
*
|
|
78
|
+
* Prefer `expectedVersion` for bulk importers and sync loops that already
|
|
79
|
+
* know the version locally; one request instead of two.
|
|
80
|
+
*/
|
|
81
|
+
expectedVersion?: number;
|
|
82
|
+
/**
|
|
83
|
+
* Legacy alias for `expectedVersion`. Kept for backwards compatibility;
|
|
84
|
+
* new code should use `expectedVersion`.
|
|
85
|
+
* @deprecated Use `expectedVersion`.
|
|
86
|
+
*/
|
|
72
87
|
version?: number;
|
|
73
88
|
/**
|
|
74
89
|
* Override the client's default conflict strategy for this update.
|
|
@@ -84,7 +99,10 @@ interface UpdateOptions {
|
|
|
84
99
|
library?: boolean;
|
|
85
100
|
/**
|
|
86
101
|
* Item type. Required by the `auto` strategy when a `keep_both_copies`
|
|
87
|
-
* conflict spawns a sibling item. Omit to let the SDK pre-fetch it
|
|
102
|
+
* conflict spawns a sibling item. Omit to let the SDK pre-fetch it —
|
|
103
|
+
* when `expectedVersion` is also omitted the pre-fetch happens upfront;
|
|
104
|
+
* when `expectedVersion` is provided the fetch is deferred until a
|
|
105
|
+
* `keep_both_copies` conflict actually needs it.
|
|
88
106
|
*/
|
|
89
107
|
type?: string;
|
|
90
108
|
/**
|
package/dist/index.js
CHANGED
|
@@ -152,6 +152,13 @@ var HttpTransport = class {
|
|
|
152
152
|
};
|
|
153
153
|
|
|
154
154
|
// src/conflict.ts
|
|
155
|
+
async function fetchItemType(transport, itemId) {
|
|
156
|
+
const res = await transport.request(
|
|
157
|
+
"GET",
|
|
158
|
+
`/items/${itemId}`
|
|
159
|
+
);
|
|
160
|
+
return res.item.type;
|
|
161
|
+
}
|
|
155
162
|
var MAX_RETRIES = 3;
|
|
156
163
|
function isConflictResponse(body) {
|
|
157
164
|
return typeof body === "object" && body !== null && "error" in body && "current" in body && "conflicting_fields" in body;
|
|
@@ -235,9 +242,10 @@ async function handleConflictUpdate(transport, itemId, itemType, clientPatch, ve
|
|
|
235
242
|
const plan = planAutoMerge(conflict);
|
|
236
243
|
let conflictedCopyId;
|
|
237
244
|
if (plan.keepBothFields.length > 0) {
|
|
245
|
+
const effectiveType = itemType ?? await fetchItemType(transport, itemId);
|
|
238
246
|
const sibling = await keepBothFlow(
|
|
239
247
|
transport,
|
|
240
|
-
|
|
248
|
+
effectiveType,
|
|
241
249
|
result.current.properties,
|
|
242
250
|
clientPatch,
|
|
243
251
|
plan.keepBothFields
|
|
@@ -341,11 +349,14 @@ var MymeClient = class {
|
|
|
341
349
|
);
|
|
342
350
|
},
|
|
343
351
|
update: async (id, properties, options) => {
|
|
344
|
-
|
|
352
|
+
const expected = options?.expectedVersion ?? options?.version;
|
|
353
|
+
let version;
|
|
345
354
|
let type = options?.type;
|
|
346
|
-
if (
|
|
355
|
+
if (expected !== void 0) {
|
|
356
|
+
version = expected;
|
|
357
|
+
} else {
|
|
347
358
|
const item = await this.items.get(id);
|
|
348
|
-
version
|
|
359
|
+
version = item.version;
|
|
349
360
|
type ??= item.type;
|
|
350
361
|
}
|
|
351
362
|
const strategy = options?.conflict ?? this.defaultConflictStrategy;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mymehq/sdk",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0",
|
|
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": "3.4.
|
|
19
|
+
"@mymehq/shared": "3.4.1"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@types/node": "^22.0.0",
|