@peers-app/peers-sdk 0.20.6 → 0.21.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 (43) hide show
  1. package/dist/data/devices.d.ts +4 -4
  2. package/dist/data/voice-messages.d.ts +2 -2
  3. package/dist/device/binary-peer-connection-v2.d.ts +19 -2
  4. package/dist/device/binary-peer-connection-v2.js +127 -20
  5. package/dist/device/binary-peer-connection-v2.test.js +60 -0
  6. package/dist/device/binary-peer-connection.d.ts +13 -2
  7. package/dist/device/binary-peer-connection.js +77 -14
  8. package/dist/device/binary-peer-connection.test.js +21 -4
  9. package/dist/device/connection.d.ts +1 -1
  10. package/dist/device/device.d.ts +1 -1
  11. package/dist/device-pairing/constants.d.ts +34 -0
  12. package/dist/device-pairing/constants.js +37 -0
  13. package/dist/device-pairing/crypto.d.ts +45 -0
  14. package/dist/device-pairing/crypto.js +135 -0
  15. package/dist/device-pairing/device-pairing.test.d.ts +1 -0
  16. package/dist/device-pairing/device-pairing.test.js +174 -0
  17. package/dist/device-pairing/index.d.ts +6 -0
  18. package/dist/device-pairing/index.js +22 -0
  19. package/dist/device-pairing/invitation.d.ts +13 -0
  20. package/dist/device-pairing/invitation.js +85 -0
  21. package/dist/device-pairing/signaling.d.ts +9 -0
  22. package/dist/device-pairing/signaling.js +29 -0
  23. package/dist/device-pairing/transcript.d.ts +7 -0
  24. package/dist/device-pairing/transcript.js +38 -0
  25. package/dist/device-pairing/types.d.ts +1023 -0
  26. package/dist/device-pairing/types.js +304 -0
  27. package/dist/index.d.ts +1 -0
  28. package/dist/index.js +1 -0
  29. package/dist/package-installer/index.d.ts +1 -0
  30. package/dist/package-installer/index.js +1 -0
  31. package/dist/package-installer/package-author-signer.d.ts +25 -0
  32. package/dist/package-installer/package-author-signer.js +57 -0
  33. package/dist/package-installer/package-installer.d.ts +27 -0
  34. package/dist/package-installer/package-installer.js +88 -18
  35. package/dist/package-installer/package-installer.test.js +49 -0
  36. package/dist/package-installer/types.d.ts +1 -1
  37. package/dist/package-loader/package-loader.d.ts +3 -3
  38. package/dist/package-loader/package-loader.js +14 -4
  39. package/dist/package-loader/package-loader.test.d.ts +1 -0
  40. package/dist/package-loader/package-loader.test.js +81 -0
  41. package/dist/rpc-types.d.ts +14 -0
  42. package/dist/rpc-types.js +9 -0
  43. package/package.json +1 -1
@@ -47,7 +47,7 @@ export interface IInstallOpts {
47
47
  localPath?: string;
48
48
  /** Version tag for the created PackageVersion. Defaults to `"dev"`. */
49
49
  versionTag?: string;
50
- /** Skip `packageLoader.loadPackage` (useful for batch installs). */
50
+ /** Skip keeping the package in the loader cache for activation. AppNavs are still backfilled when missing. */
51
51
  skipLoad?: boolean;
52
52
  /** Skip `resolveDevicePackageVersion` after install. */
53
53
  skipResolve?: boolean;
@@ -23,9 +23,9 @@ export declare class PackageLoader {
23
23
  private _readLocalBundle;
24
24
  /**
25
25
  * Post-correction: if the package definition carries a version string,
26
- * update the active IPackageVersion record to match. This fixes cases where
27
- * the PV record was created with stale or placeholder values (e.g. "0.0.1")
28
- * before the bundle was evaluated.
26
+ * update the active IPackageVersion record to match — but only when that
27
+ * active version is the mutable `dev` working copy. Never rewrite
28
+ * beta/stable version labels from a local package.json bump.
29
29
  */
30
30
  private correctPackageVersion;
31
31
  private _evaluateBundle;
@@ -104,9 +104,9 @@ class PackageLoader {
104
104
  }
105
105
  /**
106
106
  * Post-correction: if the package definition carries a version string,
107
- * update the active IPackageVersion record to match. This fixes cases where
108
- * the PV record was created with stale or placeholder values (e.g. "0.0.1")
109
- * before the bundle was evaluated.
107
+ * update the active IPackageVersion record to match — but only when that
108
+ * active version is the mutable `dev` working copy. Never rewrite
109
+ * beta/stable version labels from a local package.json bump.
110
110
  */
111
111
  correctPackageVersion(pkg, def) {
112
112
  if (!pkg.activePackageVersionId)
@@ -119,8 +119,18 @@ class PackageLoader {
119
119
  .then((pv) => {
120
120
  if (!pv)
121
121
  return;
122
+ if (pv.versionTag !== "dev")
123
+ return;
122
124
  if (def.version && pv.version !== def.version) {
123
- return pvTable.signAndSave({ ...pv, version: def.version });
125
+ const packageVersionHash = (0, package_versions_1.computePackageVersionHash)(def.version, pv.versionTag || "dev", pv.packageBundleFileHash, pv.routesBundleFileHash, pv.uiBundleFileHash);
126
+ // Version is part of both the content hash and the author-signed
127
+ // payload — clear any prior author signature so it cannot go stale.
128
+ const { packageAuthorSignature: _staleSig, ...rest } = pv;
129
+ return pvTable.signAndSave({
130
+ ...rest,
131
+ version: def.version,
132
+ packageVersionHash,
133
+ });
124
134
  }
125
135
  })
126
136
  .catch((err) => {
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const mockGet = jest.fn();
4
+ const mockSignAndSave = jest.fn();
5
+ const mockComputePackageVersionHash = jest.fn((version, _tag, packageBundleFileHash, _routesBundleFileHash, _uiBundleFileHash) => `hash-${version}-${packageBundleFileHash}`);
6
+ jest.mock("../data/package-versions", () => ({
7
+ PackageVersions: () => ({
8
+ get: (...args) => mockGet(...args),
9
+ signAndSave: (...args) => mockSignAndSave(...args),
10
+ }),
11
+ computePackageVersionHash: (version, versionTag, packageBundleFileHash, routesBundleFileHash, uiBundleFileHash) => mockComputePackageVersionHash(version, versionTag, packageBundleFileHash, routesBundleFileHash, uiBundleFileHash),
12
+ }));
13
+ const package_loader_1 = require("./package-loader");
14
+ describe("PackageLoader.correctPackageVersion", () => {
15
+ const activePvId = "pv-active";
16
+ const pkg = {
17
+ packageId: "pkg-1",
18
+ name: "Test Package",
19
+ activePackageVersionId: activePvId,
20
+ };
21
+ const def = { version: "0.3.6" };
22
+ let loader;
23
+ beforeEach(() => {
24
+ jest.clearAllMocks();
25
+ mockSignAndSave.mockResolvedValue(undefined);
26
+ loader = new package_loader_1.PackageLoader({ dataContextId: "ctx" });
27
+ });
28
+ async function correctPackageVersion() {
29
+ loader.correctPackageVersion(pkg, def);
30
+ // Flush the fire-and-forget promise chain
31
+ await new Promise((r) => setImmediate(r));
32
+ }
33
+ it("updates the active PV hash and clears a stale author signature", async () => {
34
+ mockGet.mockResolvedValue({
35
+ packageVersionId: activePvId,
36
+ version: "0.3.1",
37
+ versionTag: "dev",
38
+ packageBundleFileHash: "bundle-hash",
39
+ routesBundleFileHash: "routes-hash",
40
+ uiBundleFileHash: "ui-hash",
41
+ packageAuthorSignature: "stale-sig",
42
+ packageVersionHash: "old-hash",
43
+ });
44
+ await correctPackageVersion();
45
+ expect(mockComputePackageVersionHash).toHaveBeenCalledWith("0.3.6", "dev", "bundle-hash", "routes-hash", "ui-hash");
46
+ expect(mockSignAndSave).toHaveBeenCalledWith(expect.objectContaining({
47
+ packageVersionId: activePvId,
48
+ version: "0.3.6",
49
+ versionTag: "dev",
50
+ packageVersionHash: "hash-0.3.6-bundle-hash",
51
+ }));
52
+ expect(mockSignAndSave.mock.calls[0][0].packageAuthorSignature).toBeUndefined();
53
+ });
54
+ it("does not update the active PV when it is stable", async () => {
55
+ mockGet.mockResolvedValue({
56
+ packageVersionId: activePvId,
57
+ version: "0.3.5",
58
+ versionTag: "stable",
59
+ });
60
+ await correctPackageVersion();
61
+ expect(mockSignAndSave).not.toHaveBeenCalled();
62
+ });
63
+ it("does not update the active PV when it is beta", async () => {
64
+ mockGet.mockResolvedValue({
65
+ packageVersionId: activePvId,
66
+ version: "0.3.5",
67
+ versionTag: "beta",
68
+ });
69
+ await correctPackageVersion();
70
+ expect(mockSignAndSave).not.toHaveBeenCalled();
71
+ });
72
+ it("does nothing when the active PV version already matches", async () => {
73
+ mockGet.mockResolvedValue({
74
+ packageVersionId: activePvId,
75
+ version: "0.3.6",
76
+ versionTag: "dev",
77
+ });
78
+ await correctPackageVersion();
79
+ expect(mockSignAndSave).not.toHaveBeenCalled();
80
+ });
81
+ });
@@ -1,6 +1,8 @@
1
1
  import type { IDeviceDatabaseQueryResult, IDeviceOperationStatus, IDeviceToolRunInput } from "./contracts/system/device-operations-contract";
2
2
  import type { ITool } from "./data/tools";
3
+ import type { DevicePairingCeremonyAction, DevicePairingStartDestinationInput, DevicePairingStartSourceResult, DevicePairingState } from "./device-pairing";
3
4
  import type { IConsoleLog } from "./logging/console-logs.table";
5
+ import type { IAppNav } from "./types/app-nav";
4
6
  /** Named event payload sent across the frontend RPC bridge. */
5
7
  export interface IEventData<T = any> {
6
8
  name: string;
@@ -63,6 +65,13 @@ export declare const rpcServerCalls: {
63
65
  seedBundledPeersCore: (dataContextId?: string) => Promise<boolean>;
64
66
  setUserIdAndSecretKey: (userId: string, secretKey: string) => Promise<void>;
65
67
  getUserId: () => Promise<string | undefined>;
68
+ devicePairingStartSource: () => Promise<DevicePairingStartSourceResult>;
69
+ devicePairingStartDestination: (input: DevicePairingStartDestinationInput) => Promise<DevicePairingState>;
70
+ devicePairingApprove: (input: DevicePairingCeremonyAction) => Promise<DevicePairingState>;
71
+ devicePairingReject: (input: DevicePairingCeremonyAction) => Promise<DevicePairingState>;
72
+ devicePairingCancel: (input: DevicePairingCeremonyAction) => Promise<DevicePairingState>;
73
+ devicePairingGetState: () => Promise<DevicePairingState>;
74
+ devicePairingGetInvitationUrl: () => Promise<string | undefined>;
66
75
  encryptData: (value: string, groupId?: string) => Promise<string>;
67
76
  /**
68
77
  * Decrypt (if secret) and copy a persistent variable's value to the system clipboard
@@ -107,6 +116,8 @@ export declare const rpcServerCalls: {
107
116
  /**
108
117
  * Sign a package version with the package author's key (server-side only — key never leaves the server).
109
118
  * Returns the base64url detached signature, or undefined if the signing key isn't available.
119
+ * Optional fields (appNavs, createdBy, createdAt) must match the PV record when present so
120
+ * propagation verification of the full record succeeds.
110
121
  */
111
122
  signPackageAuthorVersion: (pvFields: {
112
123
  packageId: string;
@@ -116,6 +127,9 @@ export declare const rpcServerCalls: {
116
127
  packageBundleFileHash: string;
117
128
  routesBundleFileHash?: string;
118
129
  uiBundleFileHash?: string;
130
+ appNavs?: IAppNav[];
131
+ createdBy?: string;
132
+ createdAt?: string;
119
133
  }) => Promise<string | undefined>;
120
134
  registerWithPeersServices: () => Promise<string>;
121
135
  appQuit: () => Promise<void>;
package/dist/rpc-types.js CHANGED
@@ -21,6 +21,13 @@ exports.rpcServerCalls = {
21
21
  seedBundledPeersCore: rpcStub("seedBundledPeersCore"),
22
22
  setUserIdAndSecretKey: rpcStub("setUserIdAndSecretKey"),
23
23
  getUserId: rpcStub("getUserId"),
24
+ devicePairingStartSource: rpcStub("devicePairingStartSource"),
25
+ devicePairingStartDestination: rpcStub("devicePairingStartDestination"),
26
+ devicePairingApprove: rpcStub("devicePairingApprove"),
27
+ devicePairingReject: rpcStub("devicePairingReject"),
28
+ devicePairingCancel: rpcStub("devicePairingCancel"),
29
+ devicePairingGetState: rpcStub("devicePairingGetState"),
30
+ devicePairingGetInvitationUrl: rpcStub("devicePairingGetInvitationUrl"),
24
31
  encryptData: rpcStub("encryptData"),
25
32
  /**
26
33
  * Decrypt (if secret) and copy a persistent variable's value to the system clipboard
@@ -51,6 +58,8 @@ exports.rpcServerCalls = {
51
58
  /**
52
59
  * Sign a package version with the package author's key (server-side only — key never leaves the server).
53
60
  * Returns the base64url detached signature, or undefined if the signing key isn't available.
61
+ * Optional fields (appNavs, createdBy, createdAt) must match the PV record when present so
62
+ * propagation verification of the full record succeeds.
54
63
  */
55
64
  signPackageAuthorVersion: rpcStub("signPackageAuthorVersion"),
56
65
  registerWithPeersServices: rpcStub("registerWithPeersServices"),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peers-app/peers-sdk",
3
- "version": "0.20.6",
3
+ "version": "0.21.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/peers-app/peers-sdk.git"