@spacelr/sdk 0.9.2 → 0.10.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.mts +52 -19
- package/dist/index.d.ts +52 -19
- package/dist/index.js +60 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +60 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -614,6 +614,57 @@ var PERMANENT_STREAM_ACK_ERRORS = /* @__PURE__ */ new Set([
|
|
|
614
614
|
"Not a member of this project",
|
|
615
615
|
"Subscribe denied"
|
|
616
616
|
]);
|
|
617
|
+
function isWhereScalar(value) {
|
|
618
|
+
const t = typeof value;
|
|
619
|
+
return t === "string" || t === "number" || t === "boolean";
|
|
620
|
+
}
|
|
621
|
+
function isWhereOperator(value) {
|
|
622
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
623
|
+
return false;
|
|
624
|
+
}
|
|
625
|
+
const keys = Object.keys(value);
|
|
626
|
+
if (keys.length !== 1) return false;
|
|
627
|
+
const op = keys[0];
|
|
628
|
+
if (op !== "in" && op !== "array-contains-any") return false;
|
|
629
|
+
const candidates = value[op];
|
|
630
|
+
return Array.isArray(candidates) && candidates.every(isWhereScalar);
|
|
631
|
+
}
|
|
632
|
+
var WHERE_PATH_ABSENT = /* @__PURE__ */ Symbol("where-path-absent");
|
|
633
|
+
var WHERE_PATH_UNRESOLVABLE = /* @__PURE__ */ Symbol("where-path-unresolvable");
|
|
634
|
+
var RESERVED_PATH_SEGMENTS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
635
|
+
var MAX_WHERE_PATH_SEGMENTS = 16;
|
|
636
|
+
function resolveWherePath(document2, key) {
|
|
637
|
+
const segments = key.split(".");
|
|
638
|
+
if (segments.length > MAX_WHERE_PATH_SEGMENTS) return WHERE_PATH_ABSENT;
|
|
639
|
+
let cur = document2;
|
|
640
|
+
for (const segment of segments) {
|
|
641
|
+
if (RESERVED_PATH_SEGMENTS.has(segment)) return WHERE_PATH_ABSENT;
|
|
642
|
+
if (cur === null || cur === void 0) return WHERE_PATH_ABSENT;
|
|
643
|
+
if (Array.isArray(cur)) return WHERE_PATH_UNRESOLVABLE;
|
|
644
|
+
if (typeof cur !== "object") return WHERE_PATH_ABSENT;
|
|
645
|
+
if (!Object.prototype.hasOwnProperty.call(cur, segment)) {
|
|
646
|
+
return WHERE_PATH_ABSENT;
|
|
647
|
+
}
|
|
648
|
+
cur = cur[segment];
|
|
649
|
+
}
|
|
650
|
+
return cur === void 0 ? WHERE_PATH_ABSENT : cur;
|
|
651
|
+
}
|
|
652
|
+
function whereValueMatches(actual, expected) {
|
|
653
|
+
if (actual === WHERE_PATH_ABSENT || actual === WHERE_PATH_UNRESOLVABLE) {
|
|
654
|
+
return false;
|
|
655
|
+
}
|
|
656
|
+
if (isWhereOperator(expected)) {
|
|
657
|
+
if ("in" in expected) {
|
|
658
|
+
if (Array.isArray(actual)) return false;
|
|
659
|
+
return expected.in.includes(actual);
|
|
660
|
+
}
|
|
661
|
+
if (!Array.isArray(actual)) return false;
|
|
662
|
+
const candidates = expected["array-contains-any"];
|
|
663
|
+
return actual.some((el) => candidates.includes(el));
|
|
664
|
+
}
|
|
665
|
+
if (Array.isArray(actual)) return actual.includes(expected);
|
|
666
|
+
return actual === expected;
|
|
667
|
+
}
|
|
617
668
|
var RealtimeClient = class {
|
|
618
669
|
constructor(config) {
|
|
619
670
|
this.socket = null;
|
|
@@ -1002,12 +1053,7 @@ var RealtimeClient = class {
|
|
|
1002
1053
|
if (!where) return false;
|
|
1003
1054
|
if (!event.document) return false;
|
|
1004
1055
|
for (const [key, value] of Object.entries(where)) {
|
|
1005
|
-
|
|
1006
|
-
if (Array.isArray(docValue)) {
|
|
1007
|
-
if (!docValue.includes(value)) {
|
|
1008
|
-
return false;
|
|
1009
|
-
}
|
|
1010
|
-
} else if (docValue !== value) {
|
|
1056
|
+
if (!whereValueMatches(resolveWherePath(event.document, key), value)) {
|
|
1011
1057
|
return false;
|
|
1012
1058
|
}
|
|
1013
1059
|
}
|
|
@@ -2968,10 +3014,14 @@ var FunctionsModule = class {
|
|
|
2968
3014
|
* `config.apiUrl` (which already carries the `/api/v1` prefix).
|
|
2969
3015
|
*
|
|
2970
3016
|
* Auth defaults, based on `invokeMode` semantics:
|
|
2971
|
-
* - webhook:
|
|
2972
|
-
* - authenticated:
|
|
2973
|
-
*
|
|
2974
|
-
* -
|
|
3017
|
+
* - webhook: pass `secret` → Authorization is NOT attached
|
|
3018
|
+
* - authenticated: pass nothing → Authorization IS attached (from token manager);
|
|
3019
|
+
* caller must be a member of the target project
|
|
3020
|
+
* - public: pass nothing → Authorization is attached if logged in, else omitted
|
|
3021
|
+
* - hybrid: pass both `secret` and `authenticated: true`; JWT path
|
|
3022
|
+
* requires project membership like `authenticated`
|
|
3023
|
+
* - platform-authenticated: pass nothing → Authorization IS attached (from token manager);
|
|
3024
|
+
* any signed-in user is accepted, still just attaches the bearer token
|
|
2975
3025
|
*
|
|
2976
3026
|
* To force a specific behaviour, set `authenticated` explicitly — it wins
|
|
2977
3027
|
* over the `secret`-based default.
|