@leavepulse/control-sdk 0.3.43 → 0.3.44
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/package.json +1 -1
- package/runtime/resource.ts +13 -4
package/package.json
CHANGED
package/runtime/resource.ts
CHANGED
|
@@ -16,8 +16,14 @@ import type { Identified } from "./cache";
|
|
|
16
16
|
/** Extract an instance id from a payload. Resources key on different fields:
|
|
17
17
|
* most use `id`, some use a domain id (`user_id`). When `idPath` is given the
|
|
18
18
|
* id lives at a nested path (`["summary", "id"]` for an envelope), so we walk it
|
|
19
|
-
* directly. Otherwise: top-level `id`, then
|
|
20
|
-
*
|
|
19
|
+
* directly. Otherwise: top-level `id`, then a `key` (resources addressed by
|
|
20
|
+
* name, like one env variable), then the first `*_id` field.
|
|
21
|
+
*
|
|
22
|
+
* `owner_id` and `owner` are excluded from that last guess: they identify what
|
|
23
|
+
* a resource BELONGS to, not the resource. Without that, one env variable —
|
|
24
|
+
* `{owner, owner_id, key}` — resolved its id to the owning service, so a write
|
|
25
|
+
* aimed at a variable addressed the owner's name instead and would have created
|
|
26
|
+
* a variable called after the service. */
|
|
21
27
|
export function extractId(
|
|
22
28
|
data: Record<string, unknown>,
|
|
23
29
|
idPath?: readonly string[],
|
|
@@ -34,9 +40,12 @@ export function extractId(
|
|
|
34
40
|
}
|
|
35
41
|
const direct = data.id;
|
|
36
42
|
if (typeof direct === "string" || typeof direct === "number") return direct;
|
|
37
|
-
|
|
43
|
+
const named = data.key;
|
|
44
|
+
if (typeof named === "string" || typeof named === "number") return named;
|
|
45
|
+
for (const [field, value] of Object.entries(data)) {
|
|
46
|
+
if (field === "owner_id" || field === "owner") continue;
|
|
38
47
|
if (
|
|
39
|
-
|
|
48
|
+
field.endsWith("_id") &&
|
|
40
49
|
(typeof value === "string" || typeof value === "number")
|
|
41
50
|
) {
|
|
42
51
|
return value;
|