@honor-claw/yoyo 1.1.2 → 1.1.4-beta.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.
Files changed (66) hide show
  1. package/index.ts +25 -25
  2. package/package.json +5 -5
  3. package/src/apis/claw-cloud.ts +124 -124
  4. package/src/apis/helpers.ts +10 -10
  5. package/src/apis/honor-auth.ts +158 -158
  6. package/src/apis/http-client.ts +239 -239
  7. package/src/apis/index.ts +8 -8
  8. package/src/apis/types.ts +77 -73
  9. package/src/cloud-channel/channel.ts +117 -117
  10. package/src/cloud-channel/client.ts +3 -3
  11. package/src/cloud-channel/index.ts +4 -4
  12. package/src/cloud-channel/message-handler.ts +50 -42
  13. package/src/cloud-channel/session-manager.ts +14 -9
  14. package/src/cloud-channel/types.ts +115 -115
  15. package/src/commands/env/impl.ts +58 -58
  16. package/src/commands/env/index.ts +1 -1
  17. package/src/commands/index.ts +30 -30
  18. package/src/commands/login/impl.ts +30 -30
  19. package/src/commands/login/index.ts +1 -1
  20. package/src/commands/logout/index.ts +1 -1
  21. package/src/commands/status/index.ts +194 -194
  22. package/src/gateway-client/client.ts +90 -90
  23. package/src/gateway-client/device/auth.ts +57 -57
  24. package/src/gateway-client/device/builder.ts +105 -105
  25. package/src/gateway-client/device/helpers.ts +40 -40
  26. package/src/gateway-client/device/identity.ts +251 -251
  27. package/src/gateway-client/device/index.ts +40 -40
  28. package/src/gateway-client/device/types.ts +57 -57
  29. package/src/gateway-client/index.ts +5 -5
  30. package/src/gateway-client/protocol-client.ts +49 -34
  31. package/src/honor-auth/browser.ts +2 -2
  32. package/src/honor-auth/callback-server.ts +109 -109
  33. package/src/honor-auth/cloud.ts +57 -57
  34. package/src/honor-auth/config.ts +43 -43
  35. package/src/honor-auth/index.ts +3 -3
  36. package/src/honor-auth/token-manager.ts +90 -90
  37. package/src/honor-auth/types.ts +50 -50
  38. package/src/index.ts +10 -10
  39. package/src/modules/claw-configs/config-manager.ts +409 -409
  40. package/src/modules/claw-configs/hosts.ts +48 -48
  41. package/src/modules/claw-configs/index.ts +8 -8
  42. package/src/modules/claw-configs/provider.ts +394 -394
  43. package/src/modules/claw-configs/types.ts +34 -34
  44. package/src/modules/device/device-info.ts +1 -1
  45. package/src/modules/device/index.ts +3 -3
  46. package/src/modules/device/providers/base.ts +32 -32
  47. package/src/modules/device/providers/pad.ts +107 -107
  48. package/src/modules/device/providers/windows.ts +130 -130
  49. package/src/modules/device/registry.ts +48 -43
  50. package/src/modules/login/impl.ts +31 -26
  51. package/src/modules/login/index.ts +6 -6
  52. package/src/schemas.ts +23 -23
  53. package/src/services/connection/impl.ts +339 -339
  54. package/src/services/connection/status-tracker/events.ts +127 -127
  55. package/src/services/connection/status-tracker/index.ts +31 -31
  56. package/src/services/connection/status-tracker/storage.ts +133 -133
  57. package/src/services/connection/status-tracker/tracker.ts +370 -370
  58. package/src/services/connection/status-tracker/types.ts +131 -131
  59. package/src/services/connection/types.ts +20 -20
  60. package/src/types.ts +64 -64
  61. package/src/utils/id.ts +8 -8
  62. package/src/utils/jwt.ts +37 -37
  63. package/src/utils/logger.ts +20 -20
  64. package/src/utils/proxy.ts +58 -58
  65. package/src/utils/version.ts +29 -29
  66. package/src/utils/ws.ts +21 -21
@@ -1,57 +1,57 @@
1
- import { normalizeDeviceMetadataForAuth } from "./helpers.js";
2
- import type {
3
- DeviceAuthPayloadParams,
4
- DeviceAuthPayloadV3Params,
5
- } from "./types.js";
6
-
7
- export { normalizeDeviceMetadataForAuth };
8
-
9
- /**
10
- * Build device authentication payload (v2)
11
- * @param params - Authentication parameters
12
- * @returns Pipe-delimited payload string
13
- */
14
- export function buildDeviceAuthPayload(
15
- params: DeviceAuthPayloadParams
16
- ): string {
17
- const scopes = params.scopes.join(",");
18
- const token = params.token ?? "";
19
- return [
20
- "v2",
21
- params.deviceId,
22
- params.clientId,
23
- params.clientMode,
24
- params.role,
25
- scopes,
26
- String(params.signedAtMs),
27
- token,
28
- params.nonce,
29
- ].join("|");
30
- }
31
-
32
- /**
33
- * Build device authentication payload (v3) with platform and device family
34
- * @param params - Authentication parameters including platform and device family
35
- * @returns Pipe-delimited payload string
36
- */
37
- export function buildDeviceAuthPayloadV3(
38
- params: DeviceAuthPayloadV3Params
39
- ): string {
40
- const scopes = params.scopes.join(",");
41
- const token = params.token ?? "";
42
- const platform = normalizeDeviceMetadataForAuth(params.platform);
43
- const deviceFamily = normalizeDeviceMetadataForAuth(params.deviceFamily);
44
- return [
45
- "v3",
46
- params.deviceId,
47
- params.clientId,
48
- params.clientMode,
49
- params.role,
50
- scopes,
51
- String(params.signedAtMs),
52
- token,
53
- params.nonce,
54
- platform,
55
- deviceFamily,
56
- ].join("|");
57
- }
1
+ import { normalizeDeviceMetadataForAuth } from "./helpers.js";
2
+ import type {
3
+ DeviceAuthPayloadParams,
4
+ DeviceAuthPayloadV3Params,
5
+ } from "./types.js";
6
+
7
+ export { normalizeDeviceMetadataForAuth };
8
+
9
+ /**
10
+ * Build device authentication payload (v2)
11
+ * @param params - Authentication parameters
12
+ * @returns Pipe-delimited payload string
13
+ */
14
+ export function buildDeviceAuthPayload(
15
+ params: DeviceAuthPayloadParams
16
+ ): string {
17
+ const scopes = params.scopes.join(",");
18
+ const token = params.token ?? "";
19
+ return [
20
+ "v2",
21
+ params.deviceId,
22
+ params.clientId,
23
+ params.clientMode,
24
+ params.role,
25
+ scopes,
26
+ String(params.signedAtMs),
27
+ token,
28
+ params.nonce,
29
+ ].join("|");
30
+ }
31
+
32
+ /**
33
+ * Build device authentication payload (v3) with platform and device family
34
+ * @param params - Authentication parameters including platform and device family
35
+ * @returns Pipe-delimited payload string
36
+ */
37
+ export function buildDeviceAuthPayloadV3(
38
+ params: DeviceAuthPayloadV3Params
39
+ ): string {
40
+ const scopes = params.scopes.join(",");
41
+ const token = params.token ?? "";
42
+ const platform = normalizeDeviceMetadataForAuth(params.platform);
43
+ const deviceFamily = normalizeDeviceMetadataForAuth(params.deviceFamily);
44
+ return [
45
+ "v3",
46
+ params.deviceId,
47
+ params.clientId,
48
+ params.clientMode,
49
+ params.role,
50
+ scopes,
51
+ String(params.signedAtMs),
52
+ token,
53
+ params.nonce,
54
+ platform,
55
+ deviceFamily,
56
+ ].join("|");
57
+ }
@@ -1,105 +1,105 @@
1
- import { GATEWAY_CLIENT_MODES, GATEWAY_CLIENT_IDS } from "../protocol/index.js";
2
- import { buildDeviceAuthPayloadV3 } from "./auth.js";
3
- import {
4
- publicKeyRawBase64UrlFromPem,
5
- signDevicePayload,
6
- } from "./identity.js";
7
- import {
8
- type DeviceBuilderOptions,
9
- type DeviceInfo,
10
- } from "./types.js";
11
-
12
- /**
13
- * Build device information for gateway connection
14
- * This is the main function to generate device authentication data
15
- *
16
- * @param options - Device builder options
17
- * @returns Device information object or undefined if no device identity provided
18
- *
19
- * @example
20
- * ```typescript
21
- * const deviceInfo = buildDeviceInfo({
22
- * deviceIdentity: loadOrCreateDeviceIdentity(),
23
- * clientName: "my-client",
24
- * role: "node",
25
- * scopes: ["node.invoke"],
26
- * nonce: "challenge-nonce",
27
- * platform: "ios",
28
- * deviceFamily: "iPhone"
29
- * });
30
- * ```
31
- */
32
- export function buildDeviceInfo(options: DeviceBuilderOptions): DeviceInfo | undefined {
33
- const {
34
- deviceIdentity,
35
- clientName = GATEWAY_CLIENT_IDS.GATEWAY_CLIENT,
36
- clientMode = GATEWAY_CLIENT_MODES.BACKEND,
37
- role = "operator",
38
- scopes = ["operator.admin"],
39
- platform = process.platform,
40
- deviceFamily,
41
- authToken = null,
42
- nonce,
43
- signedAtMs = Date.now(),
44
- } = options;
45
-
46
- if (!deviceIdentity) {
47
- return undefined;
48
- }
49
-
50
- // Build authentication payload
51
- const payload = buildDeviceAuthPayloadV3({
52
- deviceId: deviceIdentity.deviceId,
53
- clientId: clientName,
54
- clientMode,
55
- role,
56
- scopes,
57
- signedAtMs,
58
- token: authToken,
59
- nonce,
60
- platform,
61
- deviceFamily,
62
- });
63
-
64
- // Sign the payload
65
- const signature = signDevicePayload(deviceIdentity.privateKeyPem, payload);
66
-
67
- // Return device information
68
- return {
69
- id: deviceIdentity.deviceId,
70
- publicKey: publicKeyRawBase64UrlFromPem(deviceIdentity.publicKeyPem),
71
- signature,
72
- signedAt: signedAtMs,
73
- nonce,
74
- };
75
- }
76
-
77
- /**
78
- * Build device information for node role
79
- * Convenience function for node connections
80
- *
81
- * @param options - Device builder options
82
- * @returns Device information object or undefined
83
- */
84
- export function buildNodeDeviceInfo(options: Omit<DeviceBuilderOptions, "role">): DeviceInfo | undefined {
85
- return buildDeviceInfo({
86
- ...options,
87
- role: "node",
88
- scopes: options.scopes ?? ["node.invoke"],
89
- });
90
- }
91
-
92
- /**
93
- * Build device information for operator role
94
- * Convenience function for operator connections
95
- *
96
- * @param options - Device builder options
97
- * @returns Device information object or undefined
98
- */
99
- export function buildOperatorDeviceInfo(options: Omit<DeviceBuilderOptions, "role">): DeviceInfo | undefined {
100
- return buildDeviceInfo({
101
- ...options,
102
- role: "operator",
103
- scopes: options.scopes ?? ["operator.admin"],
104
- });
105
- }
1
+ import { GATEWAY_CLIENT_MODES, GATEWAY_CLIENT_IDS } from "../protocol/index.js";
2
+ import { buildDeviceAuthPayloadV3 } from "./auth.js";
3
+ import {
4
+ publicKeyRawBase64UrlFromPem,
5
+ signDevicePayload,
6
+ } from "./identity.js";
7
+ import {
8
+ type DeviceBuilderOptions,
9
+ type DeviceInfo,
10
+ } from "./types.js";
11
+
12
+ /**
13
+ * Build device information for gateway connection
14
+ * This is the main function to generate device authentication data
15
+ *
16
+ * @param options - Device builder options
17
+ * @returns Device information object or undefined if no device identity provided
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * const deviceInfo = buildDeviceInfo({
22
+ * deviceIdentity: loadOrCreateDeviceIdentity(),
23
+ * clientName: "my-client",
24
+ * role: "node",
25
+ * scopes: ["node.invoke"],
26
+ * nonce: "challenge-nonce",
27
+ * platform: "ios",
28
+ * deviceFamily: "iPhone"
29
+ * });
30
+ * ```
31
+ */
32
+ export function buildDeviceInfo(options: DeviceBuilderOptions): DeviceInfo | undefined {
33
+ const {
34
+ deviceIdentity,
35
+ clientName = GATEWAY_CLIENT_IDS.GATEWAY_CLIENT,
36
+ clientMode = GATEWAY_CLIENT_MODES.BACKEND,
37
+ role = "operator",
38
+ scopes = ["operator.admin"],
39
+ platform = process.platform,
40
+ deviceFamily,
41
+ authToken = null,
42
+ nonce,
43
+ signedAtMs = Date.now(),
44
+ } = options;
45
+
46
+ if (!deviceIdentity) {
47
+ return undefined;
48
+ }
49
+
50
+ // Build authentication payload
51
+ const payload = buildDeviceAuthPayloadV3({
52
+ deviceId: deviceIdentity.deviceId,
53
+ clientId: clientName,
54
+ clientMode,
55
+ role,
56
+ scopes,
57
+ signedAtMs,
58
+ token: authToken,
59
+ nonce,
60
+ platform,
61
+ deviceFamily,
62
+ });
63
+
64
+ // Sign the payload
65
+ const signature = signDevicePayload(deviceIdentity.privateKeyPem, payload);
66
+
67
+ // Return device information
68
+ return {
69
+ id: deviceIdentity.deviceId,
70
+ publicKey: publicKeyRawBase64UrlFromPem(deviceIdentity.publicKeyPem),
71
+ signature,
72
+ signedAt: signedAtMs,
73
+ nonce,
74
+ };
75
+ }
76
+
77
+ /**
78
+ * Build device information for node role
79
+ * Convenience function for node connections
80
+ *
81
+ * @param options - Device builder options
82
+ * @returns Device information object or undefined
83
+ */
84
+ export function buildNodeDeviceInfo(options: Omit<DeviceBuilderOptions, "role">): DeviceInfo | undefined {
85
+ return buildDeviceInfo({
86
+ ...options,
87
+ role: "node",
88
+ scopes: options.scopes ?? ["node.invoke"],
89
+ });
90
+ }
91
+
92
+ /**
93
+ * Build device information for operator role
94
+ * Convenience function for operator connections
95
+ *
96
+ * @param options - Device builder options
97
+ * @returns Device information object or undefined
98
+ */
99
+ export function buildOperatorDeviceInfo(options: Omit<DeviceBuilderOptions, "role">): DeviceInfo | undefined {
100
+ return buildDeviceInfo({
101
+ ...options,
102
+ role: "operator",
103
+ scopes: options.scopes ?? ["operator.admin"],
104
+ });
105
+ }
@@ -1,40 +1,40 @@
1
- /**
2
- * Normalize device metadata for authentication payloads
3
- * Keeps cross-runtime normalization deterministic (TS/Swift/Kotlin)
4
- * by only lowercasing ASCII metadata fields used in auth payloads.
5
- */
6
- function normalizeTrimmedMetadata(value?: string | null): string {
7
- if (typeof value !== "string") {
8
- return "";
9
- }
10
- const trimmed = value.trim();
11
- return trimmed ? trimmed : "";
12
- }
13
-
14
- function toLowerAscii(input: string): string {
15
- return input.replace(/[A-Z]/g, (char) => String.fromCharCode(char.charCodeAt(0) + 32));
16
- }
17
-
18
- export function normalizeDeviceMetadataForAuth(value?: string | null): string {
19
- const trimmed = normalizeTrimmedMetadata(value);
20
- if (!trimmed) {
21
- return "";
22
- }
23
- // Keep cross-runtime normalization deterministic (TS/Swift/Kotlin) by only
24
- // lowercasing ASCII metadata fields used in auth payloads.
25
- return toLowerAscii(trimmed);
26
- }
27
-
28
- /**
29
- * Normalize device metadata for policy classification
30
- * Collapses Unicode confusables to stable ASCII-like tokens before matching platform/family rules.
31
- */
32
- export function normalizeDeviceMetadataForPolicy(value?: string | null): string {
33
- const trimmed = normalizeTrimmedMetadata(value);
34
- if (!trimmed) {
35
- return "";
36
- }
37
- // Policy classification should collapse Unicode confusables to stable ASCII-ish
38
- // tokens where possible before matching platform/family rules.
39
- return trimmed.normalize("NFKD").replace(/\p{M}/gu, "").toLowerCase();
40
- }
1
+ /**
2
+ * Normalize device metadata for authentication payloads
3
+ * Keeps cross-runtime normalization deterministic (TS/Swift/Kotlin)
4
+ * by only lowercasing ASCII metadata fields used in auth payloads.
5
+ */
6
+ function normalizeTrimmedMetadata(value?: string | null): string {
7
+ if (typeof value !== "string") {
8
+ return "";
9
+ }
10
+ const trimmed = value.trim();
11
+ return trimmed ? trimmed : "";
12
+ }
13
+
14
+ function toLowerAscii(input: string): string {
15
+ return input.replace(/[A-Z]/g, (char) => String.fromCharCode(char.charCodeAt(0) + 32));
16
+ }
17
+
18
+ export function normalizeDeviceMetadataForAuth(value?: string | null): string {
19
+ const trimmed = normalizeTrimmedMetadata(value);
20
+ if (!trimmed) {
21
+ return "";
22
+ }
23
+ // Keep cross-runtime normalization deterministic (TS/Swift/Kotlin) by only
24
+ // lowercasing ASCII metadata fields used in auth payloads.
25
+ return toLowerAscii(trimmed);
26
+ }
27
+
28
+ /**
29
+ * Normalize device metadata for policy classification
30
+ * Collapses Unicode confusables to stable ASCII-like tokens before matching platform/family rules.
31
+ */
32
+ export function normalizeDeviceMetadataForPolicy(value?: string | null): string {
33
+ const trimmed = normalizeTrimmedMetadata(value);
34
+ if (!trimmed) {
35
+ return "";
36
+ }
37
+ // Policy classification should collapse Unicode confusables to stable ASCII-ish
38
+ // tokens where possible before matching platform/family rules.
39
+ return trimmed.normalize("NFKD").replace(/\p{M}/gu, "").toLowerCase();
40
+ }