@peers-app/peers-sdk 0.18.8 → 0.19.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/README.md +74 -1
- package/dist/data/files/file-read-stream.js +7 -0
- package/dist/data/files/file.types.d.ts +6 -0
- package/dist/data/files/file.types.js +18 -0
- package/dist/data/files/files.test.js +50 -7
- package/dist/data/package-version-resolver.test.js +1 -0
- package/dist/data/package-versions.d.ts +3 -0
- package/dist/data/package-versions.js +5 -0
- package/dist/data/packages.d.ts +6 -0
- package/dist/data/packages.js +8 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/package-installer/index.d.ts +10 -0
- package/dist/package-installer/index.js +26 -0
- package/dist/package-installer/package-author-signing.d.ts +48 -0
- package/dist/package-installer/package-author-signing.js +73 -0
- package/dist/package-installer/package-author-signing.test.d.ts +1 -0
- package/dist/package-installer/package-author-signing.test.js +189 -0
- package/dist/package-installer/package-cloner.d.ts +16 -0
- package/dist/package-installer/package-cloner.js +115 -0
- package/dist/package-installer/package-cloner.test.d.ts +1 -0
- package/dist/package-installer/package-cloner.test.js +276 -0
- package/dist/package-installer/package-creator.d.ts +22 -0
- package/dist/package-installer/package-creator.js +154 -0
- package/dist/package-installer/package-creator.test.d.ts +1 -0
- package/dist/package-installer/package-creator.test.js +354 -0
- package/dist/package-installer/package-installer.d.ts +32 -0
- package/dist/package-installer/package-installer.js +247 -0
- package/dist/package-installer/package-installer.test.d.ts +1 -0
- package/dist/package-installer/package-installer.test.js +666 -0
- package/dist/package-installer/package-propagation.d.ts +29 -0
- package/dist/package-installer/package-propagation.js +363 -0
- package/dist/package-installer/package-propagation.test.d.ts +1 -0
- package/dist/package-installer/package-propagation.test.js +1145 -0
- package/dist/package-installer/package-publisher.d.ts +50 -0
- package/dist/package-installer/package-publisher.js +67 -0
- package/dist/package-installer/package-publisher.test.d.ts +1 -0
- package/dist/package-installer/package-publisher.test.js +142 -0
- package/dist/package-installer/package-remote-checker.d.ts +54 -0
- package/dist/package-installer/package-remote-checker.js +186 -0
- package/dist/package-installer/package-remote-checker.test.d.ts +1 -0
- package/dist/package-installer/package-remote-checker.test.js +263 -0
- package/dist/package-installer/package-seed-installer.d.ts +45 -0
- package/dist/package-installer/package-seed-installer.js +108 -0
- package/dist/package-installer/package-seed-installer.test.d.ts +1 -0
- package/dist/package-installer/package-seed-installer.test.js +123 -0
- package/dist/package-installer/package-tarball.d.ts +35 -0
- package/dist/package-installer/package-tarball.js +57 -0
- package/dist/package-installer/package-tarball.test.d.ts +1 -0
- package/dist/package-installer/package-tarball.test.js +75 -0
- package/dist/package-installer/types.d.ts +110 -0
- package/dist/package-installer/types.js +2 -0
- package/dist/rpc-types.d.ts +14 -0
- package/dist/rpc-types.js +6 -0
- package/dist/system-ids.d.ts +1 -0
- package/dist/system-ids.js +2 -1
- package/package.json +3 -2
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const package_tarball_1 = require("./package-tarball");
|
|
4
|
+
const testPayload = {
|
|
5
|
+
packageId: "00mh0wlipjixk2gqmurbwee0o",
|
|
6
|
+
packageVersionId: "00mpdg7xstwt3oe51x9brk15i",
|
|
7
|
+
version: "1.2.3",
|
|
8
|
+
versionTag: "stable",
|
|
9
|
+
packageBundleFileHash: "abc123",
|
|
10
|
+
routesBundleFileHash: "def456",
|
|
11
|
+
uiBundleFileHash: "ghi789",
|
|
12
|
+
publicKey: "testPublicKey123",
|
|
13
|
+
packageAuthorSignature: "testSignature456",
|
|
14
|
+
};
|
|
15
|
+
describe("package-tarball", () => {
|
|
16
|
+
describe("packPeersTarball + unpackPeersTarball round-trip", () => {
|
|
17
|
+
it("round-trips all three bundles", async () => {
|
|
18
|
+
const opts = {
|
|
19
|
+
payload: testPayload,
|
|
20
|
+
packageBundle: "console.log('main bundle');",
|
|
21
|
+
routesBundle: "console.log('routes');",
|
|
22
|
+
uiBundle: "console.log('ui');",
|
|
23
|
+
};
|
|
24
|
+
const tarball = await (0, package_tarball_1.packPeersTarball)(opts);
|
|
25
|
+
expect(tarball).toBeInstanceOf(Uint8Array);
|
|
26
|
+
expect(tarball.length).toBeGreaterThan(0);
|
|
27
|
+
const result = await (0, package_tarball_1.unpackPeersTarball)(tarball);
|
|
28
|
+
expect(result.payload).toEqual(testPayload);
|
|
29
|
+
expect(result.packageBundle).toBe(opts.packageBundle);
|
|
30
|
+
expect(result.routesBundle).toBe(opts.routesBundle);
|
|
31
|
+
expect(result.uiBundle).toBe(opts.uiBundle);
|
|
32
|
+
});
|
|
33
|
+
it("round-trips with only package bundle (no routes/ui)", async () => {
|
|
34
|
+
const opts = {
|
|
35
|
+
payload: { ...testPayload, routesBundleFileHash: undefined, uiBundleFileHash: undefined },
|
|
36
|
+
packageBundle: "module.exports = {};",
|
|
37
|
+
};
|
|
38
|
+
const tarball = await (0, package_tarball_1.packPeersTarball)(opts);
|
|
39
|
+
const result = await (0, package_tarball_1.unpackPeersTarball)(tarball);
|
|
40
|
+
expect(result.payload.packageId).toBe(testPayload.packageId);
|
|
41
|
+
expect(result.packageBundle).toBe(opts.packageBundle);
|
|
42
|
+
expect(result.routesBundle).toBeUndefined();
|
|
43
|
+
expect(result.uiBundle).toBeUndefined();
|
|
44
|
+
});
|
|
45
|
+
it("handles large bundle content", async () => {
|
|
46
|
+
const largeBundle = "x".repeat(500_000);
|
|
47
|
+
const opts = {
|
|
48
|
+
payload: testPayload,
|
|
49
|
+
packageBundle: largeBundle,
|
|
50
|
+
};
|
|
51
|
+
const tarball = await (0, package_tarball_1.packPeersTarball)(opts);
|
|
52
|
+
// Gzip should compress the repetitive content significantly
|
|
53
|
+
expect(tarball.length).toBeLessThan(largeBundle.length);
|
|
54
|
+
const result = await (0, package_tarball_1.unpackPeersTarball)(tarball);
|
|
55
|
+
expect(result.packageBundle).toBe(largeBundle);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
describe("unpackPeersTarball validation", () => {
|
|
59
|
+
it("throws on empty/invalid data", async () => {
|
|
60
|
+
await expect((0, package_tarball_1.unpackPeersTarball)(new Uint8Array(0))).rejects.toThrow();
|
|
61
|
+
});
|
|
62
|
+
it("throws if pv-payload.json is missing", async () => {
|
|
63
|
+
const { createTarGzip } = await Promise.resolve().then(() => require("nanotar"));
|
|
64
|
+
const tarball = await createTarGzip([{ name: "package.bundle.js", data: "code" }]);
|
|
65
|
+
await expect((0, package_tarball_1.unpackPeersTarball)(tarball)).rejects.toThrow("missing pv-payload.json");
|
|
66
|
+
});
|
|
67
|
+
it("throws if package.bundle.js is missing", async () => {
|
|
68
|
+
const { createTarGzip } = await Promise.resolve().then(() => require("nanotar"));
|
|
69
|
+
const tarball = await createTarGzip([
|
|
70
|
+
{ name: "pv-payload.json", data: JSON.stringify(testPayload) },
|
|
71
|
+
]);
|
|
72
|
+
await expect((0, package_tarball_1.unpackPeersTarball)(tarball)).rejects.toThrow("missing package.bundle.js");
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
});
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import type { IPackageVersion } from "../data/package-versions";
|
|
2
|
+
import type { IPeersPackage } from "../types/peers-package";
|
|
3
|
+
/**
|
|
4
|
+
* Abstraction over local filesystem operations.
|
|
5
|
+
* Each runtime (Electron, CLI, tests) provides its own implementation.
|
|
6
|
+
*/
|
|
7
|
+
export interface IFileSystemDeps {
|
|
8
|
+
readFile(path: string): Promise<string>;
|
|
9
|
+
writeFile(path: string, content: string): Promise<void>;
|
|
10
|
+
exists(path: string): Promise<boolean>;
|
|
11
|
+
readJson<T = unknown>(path: string): Promise<T>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Abstraction over shell command execution (git, npm, etc.).
|
|
15
|
+
*/
|
|
16
|
+
export interface IShellDeps {
|
|
17
|
+
exec(cmd: string, opts?: {
|
|
18
|
+
cwd?: string;
|
|
19
|
+
}): Promise<{
|
|
20
|
+
stdout: string;
|
|
21
|
+
stderr: string;
|
|
22
|
+
}>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Abstraction over HTTP fetching for remote package updates.
|
|
26
|
+
* Each runtime provides its own implementation (Node fetch, browser fetch).
|
|
27
|
+
*/
|
|
28
|
+
export interface IHttpDeps {
|
|
29
|
+
fetchJson<T = unknown>(url: string): Promise<T>;
|
|
30
|
+
fetchBinary(url: string): Promise<Uint8Array>;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* All external dependencies needed by the package-installer module.
|
|
34
|
+
* Injected by the host runtime to keep the SDK runtime-agnostic.
|
|
35
|
+
*/
|
|
36
|
+
export interface IPackageInstallerDeps {
|
|
37
|
+
fs: IFileSystemDeps;
|
|
38
|
+
shell: IShellDeps;
|
|
39
|
+
resolvePath(...segments: string[]): string;
|
|
40
|
+
packagesRootDir: string;
|
|
41
|
+
/** Optional HTTP interface for remote package checking. No-op if omitted. */
|
|
42
|
+
http?: IHttpDeps;
|
|
43
|
+
}
|
|
44
|
+
/** Options for {@link installPackageFromBundles}. */
|
|
45
|
+
export interface IInstallOpts {
|
|
46
|
+
/** Override local path; otherwise read from the packageLocalPath device var. */
|
|
47
|
+
localPath?: string;
|
|
48
|
+
/** Version tag for the created PackageVersion. Defaults to `"dev"`. */
|
|
49
|
+
versionTag?: string;
|
|
50
|
+
/** Skip `packageLoader.loadPackage` (useful for batch installs). */
|
|
51
|
+
skipLoad?: boolean;
|
|
52
|
+
/** Skip `resolveDevicePackageVersion` after install. */
|
|
53
|
+
skipResolve?: boolean;
|
|
54
|
+
}
|
|
55
|
+
/** Result of {@link installPackageFromBundles}. */
|
|
56
|
+
export interface IInstallResult {
|
|
57
|
+
packageVersion: IPackageVersion;
|
|
58
|
+
loaded: IPeersPackage | undefined;
|
|
59
|
+
/** True when the on-disk bundles match the existing PackageVersion hash — no writes occurred. */
|
|
60
|
+
unchanged: boolean;
|
|
61
|
+
}
|
|
62
|
+
/** Metadata extracted from a local package directory's `package.json`. */
|
|
63
|
+
export interface IPackageInfo {
|
|
64
|
+
packageId?: string;
|
|
65
|
+
name: string;
|
|
66
|
+
description?: string;
|
|
67
|
+
version?: string;
|
|
68
|
+
remoteRepo?: string;
|
|
69
|
+
}
|
|
70
|
+
/** Options for {@link createPackage}. */
|
|
71
|
+
export interface ICreatePackageOpts {
|
|
72
|
+
/** Human-readable package name (e.g. "My Widget"). */
|
|
73
|
+
name: string;
|
|
74
|
+
/** Override default location (`{packagesRootDir}/{slug}`). */
|
|
75
|
+
location?: string;
|
|
76
|
+
/** Override the template repo URL. Defaults to peers-package-template on GitHub. */
|
|
77
|
+
templateRepo?: string;
|
|
78
|
+
/** Author name written into package.json. */
|
|
79
|
+
author?: string;
|
|
80
|
+
/**
|
|
81
|
+
* The user's personal DataContext for storing the signing key as a secret `userVar`.
|
|
82
|
+
* If omitted, keypair generation is skipped (useful for tests or contexts where
|
|
83
|
+
* personal storage isn't available). The migration script backfills these.
|
|
84
|
+
*/
|
|
85
|
+
personalContext?: import("../context/data-context").DataContext;
|
|
86
|
+
}
|
|
87
|
+
/** Result of {@link createPackage}. */
|
|
88
|
+
export interface ICreatePackageResult {
|
|
89
|
+
packageId: string;
|
|
90
|
+
localPath: string;
|
|
91
|
+
packageVersion: IPackageVersion;
|
|
92
|
+
}
|
|
93
|
+
/** Options for {@link clonePackage}. */
|
|
94
|
+
export interface IClonePackageOpts {
|
|
95
|
+
/** Remote git URL to clone. */
|
|
96
|
+
remoteRepo: string;
|
|
97
|
+
/** Override default location (`{packagesRootDir}/{repo-slug}`). */
|
|
98
|
+
location?: string;
|
|
99
|
+
/** Override auto-detection of disabled state. */
|
|
100
|
+
disabled?: boolean;
|
|
101
|
+
/** Skip `npm install` + `npm run build` (useful if pre-built). */
|
|
102
|
+
skipBuild?: boolean;
|
|
103
|
+
}
|
|
104
|
+
/** Result of {@link clonePackage}. */
|
|
105
|
+
export interface IClonePackageResult {
|
|
106
|
+
packageId: string;
|
|
107
|
+
localPath: string;
|
|
108
|
+
remoteRepo: string;
|
|
109
|
+
packageVersion: IPackageVersion;
|
|
110
|
+
}
|
package/dist/rpc-types.d.ts
CHANGED
|
@@ -36,6 +36,7 @@ export declare const rpcServerCalls: {
|
|
|
36
36
|
update?: boolean;
|
|
37
37
|
linkRemote?: boolean;
|
|
38
38
|
}) => Promise<string>;
|
|
39
|
+
seedBundledPeersCore: (dataContextId?: string) => Promise<boolean>;
|
|
39
40
|
setUserIdAndSecretKey: (userId: string, secretKey: string) => Promise<void>;
|
|
40
41
|
getUserId: () => Promise<string | undefined>;
|
|
41
42
|
encryptData: (value: string, groupId?: string) => Promise<string>;
|
|
@@ -69,6 +70,19 @@ export declare const rpcServerCalls: {
|
|
|
69
70
|
/** Deletes the pre-migration data directory after the user confirms. */
|
|
70
71
|
cleanupOldDataDir: () => Promise<void>;
|
|
71
72
|
importGroupShare: (groupShareJson: string) => Promise<string>;
|
|
73
|
+
/**
|
|
74
|
+
* Sign a package version with the package author's key (server-side only — key never leaves the server).
|
|
75
|
+
* Returns the base64url detached signature, or undefined if the signing key isn't available.
|
|
76
|
+
*/
|
|
77
|
+
signPackageAuthorVersion: (pvFields: {
|
|
78
|
+
packageId: string;
|
|
79
|
+
packageVersionId: string;
|
|
80
|
+
version: string;
|
|
81
|
+
versionTag?: string;
|
|
82
|
+
packageBundleFileHash: string;
|
|
83
|
+
routesBundleFileHash?: string;
|
|
84
|
+
uiBundleFileHash?: string;
|
|
85
|
+
}) => Promise<string | undefined>;
|
|
72
86
|
registerWithPeersServices: () => Promise<string>;
|
|
73
87
|
appQuit: () => Promise<void>;
|
|
74
88
|
appRestart: () => Promise<void>;
|
package/dist/rpc-types.js
CHANGED
|
@@ -17,6 +17,7 @@ exports.rpcServerCalls = {
|
|
|
17
17
|
openPath: rpcStub("openPath"),
|
|
18
18
|
openPackage: rpcStub("OpenPackage"),
|
|
19
19
|
addOrUpdatePackage: rpcStub("addOrUpdatePackage"),
|
|
20
|
+
seedBundledPeersCore: rpcStub("seedBundledPeersCore"),
|
|
20
21
|
setUserIdAndSecretKey: rpcStub("setUserIdAndSecretKey"),
|
|
21
22
|
getUserId: rpcStub("getUserId"),
|
|
22
23
|
encryptData: rpcStub("encryptData"),
|
|
@@ -39,6 +40,11 @@ exports.rpcServerCalls = {
|
|
|
39
40
|
/** Deletes the pre-migration data directory after the user confirms. */
|
|
40
41
|
cleanupOldDataDir: rpcStub("cleanupOldDataDir"),
|
|
41
42
|
importGroupShare: rpcStub("importGroupShare"),
|
|
43
|
+
/**
|
|
44
|
+
* Sign a package version with the package author's key (server-side only — key never leaves the server).
|
|
45
|
+
* Returns the base64url detached signature, or undefined if the signing key isn't available.
|
|
46
|
+
*/
|
|
47
|
+
signPackageAuthorVersion: rpcStub("signPackageAuthorVersion"),
|
|
42
48
|
registerWithPeersServices: rpcStub("registerWithPeersServices"),
|
|
43
49
|
// App lifecycle commands (for CLI control)
|
|
44
50
|
appQuit: rpcStub("appQuit"),
|
package/dist/system-ids.d.ts
CHANGED
|
@@ -6,3 +6,4 @@ export declare const defaultSendMessageToolId = "000peers0tool00000sendmsg";
|
|
|
6
6
|
export declare const runWorkflowToolId = "000peers0tool0runworkflow";
|
|
7
7
|
export declare const peersCorePackageId = "00mh0wlipjixk2gqmurbwee0o";
|
|
8
8
|
export declare const peersCorePackageRepoUrl = "https://github.com/peers-app/peers-core";
|
|
9
|
+
export declare const peersCorePublishPublicKey = "S7cQqnvVz-FVDO6Lk5zC7epSvcP_-NyBVZz9gdcj73c";
|
package/dist/system-ids.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.peersCorePackageRepoUrl = exports.peersCorePackageId = exports.runWorkflowToolId = exports.defaultSendMessageToolId = exports.defaultAssistantRunnerToolId = exports.openCodeAssistantId = exports.defaultAssistantId = exports.peersRootUserId = void 0;
|
|
3
|
+
exports.peersCorePublishPublicKey = exports.peersCorePackageRepoUrl = exports.peersCorePackageId = exports.runWorkflowToolId = exports.defaultSendMessageToolId = exports.defaultAssistantRunnerToolId = exports.openCodeAssistantId = exports.defaultAssistantId = exports.peersRootUserId = void 0;
|
|
4
4
|
exports.peersRootUserId = "000peers0user000000000001";
|
|
5
5
|
exports.defaultAssistantId = "000peers0bot00000000shell";
|
|
6
6
|
// export const defaultAssistantId = '000peers0bot000000000bot1';
|
|
@@ -10,3 +10,4 @@ exports.defaultSendMessageToolId = "000peers0tool00000sendmsg";
|
|
|
10
10
|
exports.runWorkflowToolId = "000peers0tool0runworkflow";
|
|
11
11
|
exports.peersCorePackageId = "00mh0wlipjixk2gqmurbwee0o";
|
|
12
12
|
exports.peersCorePackageRepoUrl = "https://github.com/peers-app/peers-core";
|
|
13
|
+
exports.peersCorePublishPublicKey = "S7cQqnvVz-FVDO6Lk5zC7epSvcP_-NyBVZz9gdcj73c";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peers-app/peers-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/peers-app/peers-sdk.git"
|
|
@@ -34,15 +34,16 @@
|
|
|
34
34
|
"release": "npm run release:patch"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"buffer": "^6.0.3",
|
|
38
37
|
"@msgpack/msgpack": "^3.1.2",
|
|
39
38
|
"@noble/hashes": "^1.8.0",
|
|
39
|
+
"buffer": "^6.0.3",
|
|
40
40
|
"ed2curve": "^0.3.0",
|
|
41
41
|
"fast-json-stable-stringify": "^2.1.0",
|
|
42
42
|
"fflate": "^0.8.2",
|
|
43
43
|
"lodash": "^4.17.21",
|
|
44
44
|
"moment": "^2.30.1",
|
|
45
45
|
"moment-timezone": "^0.5.46",
|
|
46
|
+
"nanotar": "^0.3.0",
|
|
46
47
|
"tweetnacl": "^1.0.3",
|
|
47
48
|
"tweetnacl-util": "^0.15.1",
|
|
48
49
|
"zod": "3.25.76"
|