@minion-stack/shared 0.7.0 → 0.8.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.
@@ -0,0 +1,34 @@
1
+ export interface ConnectClientInfo {
2
+ id: string;
3
+ displayName?: string;
4
+ version?: string;
5
+ platform?: string;
6
+ mode?: string;
7
+ }
8
+ export interface BuildConnectParamsInput {
9
+ /** Identifying info for this client (id, version, platform, …). */
10
+ client: ConnectClientInfo;
11
+ /** Connection role, e.g. "operator" | "node". */
12
+ role: string;
13
+ /** Requested scopes. Defaults to []. */
14
+ scopes?: string[];
15
+ /** Capability tags. Defaults to []. */
16
+ caps?: string[];
17
+ /** Shared-secret token (goes in `auth.token`). */
18
+ token?: string | null;
19
+ /** Shared-secret password (goes in `auth.password`). */
20
+ password?: string | null;
21
+ /** Hub-issued OIDC JWT for multi-tenant identity. */
22
+ jwt?: string | null;
23
+ /** User id for per-user RPC scoping. */
24
+ userId?: string | null;
25
+ /** Override the advertised min/max protocol (defaults to PROTOCOL_VERSION). */
26
+ minProtocol?: number;
27
+ maxProtocol?: number;
28
+ }
29
+ /**
30
+ * Build the params object for the `connect` request. Omits `auth`, `jwt`, and
31
+ * `userId` when not provided so the gateway sees a clean frame.
32
+ */
33
+ export declare function buildConnectParams(input: BuildConnectParamsInput): Record<string, unknown>;
34
+ //# sourceMappingURL=connect-params.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connect-params.d.ts","sourceRoot":"","sources":["../../src/gateway/connect-params.ts"],"names":[],"mappings":"AAYA,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,uBAAuB;IACtC,mEAAmE;IACnE,MAAM,EAAE,iBAAiB,CAAC;IAC1B,iDAAiD;IACjD,IAAI,EAAE,MAAM,CAAC;IACb,wCAAwC;IACxC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,uCAAuC;IACvC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,kDAAkD;IAClD,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,wDAAwD;IACxD,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,qDAAqD;IACrD,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,wCAAwC;IACxC,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,+EAA+E;IAC/E,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,uBAAuB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAiB1F"}
@@ -0,0 +1,34 @@
1
+ // Shared builder for the WebSocket `connect` handshake params (R8 of
2
+ // specs/2026-05-26-auth-token-simplification.md).
3
+ //
4
+ // The gateway protocol carries auth in the `connect` request params, not in the
5
+ // frame types — so every client (hub, site, paperclip) hand-rolled the same
6
+ // object shape inside its `onChallenge` callback (protocol version, role,
7
+ // scopes, auth.token, userId). This centralizes that shape so protocol-version
8
+ // bumps and field renames happen in one place. Returns `Record<string, unknown>`
9
+ // to drop straight into `GatewayClientOptions.onChallenge`.
10
+ import { PROTOCOL_VERSION } from "./client.js";
11
+ /**
12
+ * Build the params object for the `connect` request. Omits `auth`, `jwt`, and
13
+ * `userId` when not provided so the gateway sees a clean frame.
14
+ */
15
+ export function buildConnectParams(input) {
16
+ const auth = {};
17
+ if (input.token)
18
+ auth.token = input.token;
19
+ if (input.password)
20
+ auth.password = input.password;
21
+ const hasAuth = auth.token !== undefined || auth.password !== undefined;
22
+ return {
23
+ minProtocol: input.minProtocol ?? PROTOCOL_VERSION,
24
+ maxProtocol: input.maxProtocol ?? PROTOCOL_VERSION,
25
+ client: input.client,
26
+ role: input.role,
27
+ scopes: input.scopes ?? [],
28
+ caps: input.caps ?? [],
29
+ ...(hasAuth ? { auth } : {}),
30
+ ...(input.jwt ? { jwt: input.jwt } : {}),
31
+ ...(input.userId ? { userId: input.userId } : {}),
32
+ };
33
+ }
34
+ //# sourceMappingURL=connect-params.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connect-params.js","sourceRoot":"","sources":["../../src/gateway/connect-params.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,kDAAkD;AAClD,EAAE;AACF,gFAAgF;AAChF,4EAA4E;AAC5E,0EAA0E;AAC1E,+EAA+E;AAC/E,iFAAiF;AACjF,4DAA4D;AAE5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAgC/C;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAA8B;IAC/D,MAAM,IAAI,GAA0C,EAAE,CAAC;IACvD,IAAI,KAAK,CAAC,KAAK;QAAE,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;IAC1C,IAAI,KAAK,CAAC,QAAQ;QAAE,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;IACnD,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,KAAK,SAAS,IAAI,IAAI,CAAC,QAAQ,KAAK,SAAS,CAAC;IAExE,OAAO;QACL,WAAW,EAAE,KAAK,CAAC,WAAW,IAAI,gBAAgB;QAClD,WAAW,EAAE,KAAK,CAAC,WAAW,IAAI,gBAAgB;QAClD,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,MAAM,EAAE,KAAK,CAAC,MAAM,IAAI,EAAE;QAC1B,IAAI,EAAE,KAAK,CAAC,IAAI,IAAI,EAAE;QACtB,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC5B,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACxC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAClD,CAAC;AACJ,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=connect-params.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connect-params.test.d.ts","sourceRoot":"","sources":["../../src/gateway/connect-params.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,40 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { buildConnectParams } from './connect-params.js';
3
+ import { PROTOCOL_VERSION } from './client.js';
4
+ const client = { id: 'minion-control-ui', version: '1.0', platform: 'web' };
5
+ describe('buildConnectParams', () => {
6
+ it('defaults protocol to PROTOCOL_VERSION and scopes/caps to []', () => {
7
+ const p = buildConnectParams({ client, role: 'operator' });
8
+ expect(p.minProtocol).toBe(PROTOCOL_VERSION);
9
+ expect(p.maxProtocol).toBe(PROTOCOL_VERSION);
10
+ expect(p.scopes).toEqual([]);
11
+ expect(p.caps).toEqual([]);
12
+ expect(p.role).toBe('operator');
13
+ });
14
+ it('includes auth.token only when a token is provided', () => {
15
+ expect(buildConnectParams({ client, role: 'operator' }).auth).toBeUndefined();
16
+ const p = buildConnectParams({ client, role: 'operator', token: 'tok' });
17
+ expect(p.auth).toEqual({ token: 'tok' });
18
+ });
19
+ it('carries password, jwt and userId through when present', () => {
20
+ const p = buildConnectParams({
21
+ client,
22
+ role: 'operator',
23
+ password: 'pw',
24
+ jwt: 'jwt-abc',
25
+ userId: 'user-1',
26
+ scopes: ['operator.read'],
27
+ });
28
+ expect(p.auth).toEqual({ password: 'pw' });
29
+ expect(p.jwt).toBe('jwt-abc');
30
+ expect(p.userId).toBe('user-1');
31
+ expect(p.scopes).toEqual(['operator.read']);
32
+ });
33
+ it('omits jwt/userId/auth for empty-string and null inputs', () => {
34
+ const p = buildConnectParams({ client, role: 'node', token: '', jwt: null, userId: null });
35
+ expect(p.auth).toBeUndefined();
36
+ expect('jwt' in p).toBe(false);
37
+ expect('userId' in p).toBe(false);
38
+ });
39
+ });
40
+ //# sourceMappingURL=connect-params.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connect-params.test.js","sourceRoot":"","sources":["../../src/gateway/connect-params.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C,MAAM,MAAM,GAAG,EAAE,EAAE,EAAE,mBAAmB,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAc,EAAE,CAAC;AAErF,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE;IAClC,EAAE,CAAC,6DAA6D,EAAE,GAAG,EAAE;QACrE,MAAM,CAAC,GAAG,kBAAkB,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC;QAC3D,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;QAC7C,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;QAC7C,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAC7B,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAC3B,MAAM,CAAC,CAAC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MAAM,EAAE,KAAK,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;QAC3F,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,aAAa,EAAE,CAAC;QAC/B,MAAM,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC/B,MAAM,CAAC,QAAQ,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -2,6 +2,7 @@ export * from './types.js';
2
2
  export * from './protocol.js';
3
3
  export * from './connection.js';
4
4
  export * from './client.js';
5
+ export * from './connect-params.js';
5
6
  export * from './cache-events.js';
6
7
  export * from './secrets.js';
7
8
  export * from './shells.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/gateway/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/gateway/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC"}
@@ -2,6 +2,7 @@ export * from './types.js';
2
2
  export * from './protocol.js';
3
3
  export * from './connection.js';
4
4
  export * from './client.js';
5
+ export * from './connect-params.js';
5
6
  export * from './cache-events.js';
6
7
  export * from './secrets.js';
7
8
  export * from './shells.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/gateway/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/gateway/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC"}
@@ -1,2 +1,2 @@
1
- export declare function uuid(): string;
1
+ export declare const uuid: () => string;
2
2
  //# sourceMappingURL=uuid.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"uuid.d.ts","sourceRoot":"","sources":["../../src/utils/uuid.ts"],"names":[],"mappings":"AAAA,wBAAgB,IAAI,IAAI,MAAM,CAM7B"}
1
+ {"version":3,"file":"uuid.d.ts","sourceRoot":"","sources":["../../src/utils/uuid.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,IAAI,QAAO,MAA6B,CAAC"}
@@ -1,9 +1,4 @@
1
- export function uuid() {
2
- if (typeof crypto !== 'undefined' && crypto.randomUUID)
3
- return crypto.randomUUID();
4
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
5
- const r = (Math.random() * 16) | 0;
6
- return (c === 'x' ? r : (r & 0x3) | 0x8).toString(16);
7
- });
8
- }
1
+ // ponytail: crypto.randomUUID is native in Node 15.7+ and all browser secure
2
+ // contexts (https + localhost). No fallback needed.
3
+ export const uuid = () => crypto.randomUUID();
9
4
  //# sourceMappingURL=uuid.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"uuid.js","sourceRoot":"","sources":["../../src/utils/uuid.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,IAAI;IAClB,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,CAAC,UAAU;QAAE,OAAO,MAAM,CAAC,UAAU,EAAE,CAAC;IACnF,OAAO,sCAAsC,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE;QACnE,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC;QACnC,OAAO,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACxD,CAAC,CAAC,CAAC;AACL,CAAC"}
1
+ {"version":3,"file":"uuid.js","sourceRoot":"","sources":["../../src/utils/uuid.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,oDAAoD;AACpD,MAAM,CAAC,MAAM,IAAI,GAAG,GAAW,EAAE,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@minion-stack/shared",
3
- "version": "0.7.0",
3
+ "version": "0.8.1",
4
4
  "description": "Shared gateway protocol types and utilities for the Minion platform.",
5
5
  "license": "MIT",
6
6
  "repository": {