@zswarm/core 0.4.0 → 0.4.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/dist/ops/delivery.d.ts +7 -3
- package/dist/ops/delivery.js +13 -9
- package/dist/schema.js +1 -1
- package/package.json +1 -1
package/dist/ops/delivery.d.ts
CHANGED
|
@@ -21,8 +21,9 @@ export type SenderOrigin = {
|
|
|
21
21
|
};
|
|
22
22
|
/**
|
|
23
23
|
* Clean one origin part for the `[zswarm from=…]` header: non-strings and
|
|
24
|
-
* blanks become null, header-breaking characters
|
|
25
|
-
*
|
|
24
|
+
* blanks become null, header-breaking characters and whitespace runs become a
|
|
25
|
+
* single `_` (a value never holds a space, so `key=value` pairs stay
|
|
26
|
+
* splittable), and the result is capped at 64 chars.
|
|
26
27
|
*/
|
|
27
28
|
export declare function sanitizeOriginPart(raw: unknown): string | null;
|
|
28
29
|
/** The origin of the caller's own process, read from its environment. */
|
|
@@ -33,7 +34,10 @@ export declare function resolveSenderOrigin(env: NodeJS.ProcessEnv): SenderOrigi
|
|
|
33
34
|
* client) keeps every part null but still records that serve carried it.
|
|
34
35
|
*/
|
|
35
36
|
export declare function originFromServeRequest(raw: unknown): SenderOrigin;
|
|
36
|
-
/**
|
|
37
|
+
/**
|
|
38
|
+
* " src=session/pane host=host via=serve" (only the parts that are known).
|
|
39
|
+
* `from=` stays the bare label, so a reader can split the header on spaces.
|
|
40
|
+
*/
|
|
37
41
|
export declare function originSuffix(origin: SenderOrigin | null | undefined): string;
|
|
38
42
|
export type DeliveryResult = {
|
|
39
43
|
to: string;
|
package/dist/ops/delivery.js
CHANGED
|
@@ -6,18 +6,19 @@ import { isTrue, numberArg, optionalString } from "./util.js";
|
|
|
6
6
|
const ORIGIN_PART_MAX = 64;
|
|
7
7
|
/**
|
|
8
8
|
* Clean one origin part for the `[zswarm from=…]` header: non-strings and
|
|
9
|
-
* blanks become null, header-breaking characters
|
|
10
|
-
*
|
|
9
|
+
* blanks become null, header-breaking characters and whitespace runs become a
|
|
10
|
+
* single `_` (a value never holds a space, so `key=value` pairs stay
|
|
11
|
+
* splittable), and the result is capped at 64 chars.
|
|
11
12
|
*/
|
|
12
13
|
export function sanitizeOriginPart(raw) {
|
|
13
14
|
if (typeof raw !== "string")
|
|
14
15
|
return null;
|
|
15
|
-
const cleaned = raw.replace(/[\r\n[\]]+/g, " ").replace(
|
|
16
|
+
const cleaned = raw.replace(/[\r\n[\]\s]+/g, " ").trim().replace(/ /g, "_");
|
|
16
17
|
if (!cleaned)
|
|
17
18
|
return null;
|
|
18
19
|
return cleaned.length <= ORIGIN_PART_MAX
|
|
19
20
|
? cleaned
|
|
20
|
-
: cleaned.slice(0, ORIGIN_PART_MAX).
|
|
21
|
+
: cleaned.slice(0, ORIGIN_PART_MAX).replace(/_+$/, "");
|
|
21
22
|
}
|
|
22
23
|
/** The origin of the caller's own process, read from its environment. */
|
|
23
24
|
export function resolveSenderOrigin(env) {
|
|
@@ -50,15 +51,18 @@ export function originFromServeRequest(raw) {
|
|
|
50
51
|
via: "serve",
|
|
51
52
|
};
|
|
52
53
|
}
|
|
53
|
-
/**
|
|
54
|
+
/**
|
|
55
|
+
* " src=session/pane host=host via=serve" (only the parts that are known).
|
|
56
|
+
* `from=` stays the bare label, so a reader can split the header on spaces.
|
|
57
|
+
*/
|
|
54
58
|
export function originSuffix(origin) {
|
|
55
59
|
if (!origin)
|
|
56
60
|
return "";
|
|
57
61
|
const { session, pane, host, via } = origin;
|
|
58
|
-
const
|
|
59
|
-
return ((
|
|
60
|
-
(host ? "
|
|
61
|
-
(via === "serve" ? " via
|
|
62
|
+
const src = session && pane ? `${session}/${pane}` : (pane ?? session ?? null);
|
|
63
|
+
return ((src ? " src=" + src : "") +
|
|
64
|
+
(host ? " host=" + host : "") +
|
|
65
|
+
(via === "serve" ? " via=serve" : ""));
|
|
62
66
|
}
|
|
63
67
|
/**
|
|
64
68
|
* An args-supplied origin, cleaned again (a direct caller may skip dispatch),
|
package/dist/schema.js
CHANGED
|
@@ -281,7 +281,7 @@ export const PARAMS = [
|
|
|
281
281
|
type: "string",
|
|
282
282
|
flags: ["--from", "-f"],
|
|
283
283
|
ops: ["send", "broadcast"],
|
|
284
|
-
description: "send: sender label in the [zswarm from=…] prefix (default: ZSWARM_FROM, else the sending pane's title, else swarm). zswarm appends
|
|
284
|
+
description: "send: sender label in the [zswarm from=…] prefix (default: ZSWARM_FROM, else the sending pane's title, else swarm). zswarm appends src=<session>/<pane>, host=<host> (ZSWARM_HOST) and via=serve",
|
|
285
285
|
},
|
|
286
286
|
{
|
|
287
287
|
name: "raw",
|