@xenosystem/primitives 0.2.0 → 0.2.2
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/cjs/updates/index.d.ts +13 -4
- package/dist/cjs/updates/index.js +26 -11
- package/dist/esm/updates/index.d.ts +13 -4
- package/dist/esm/updates/index.js +25 -11
- package/package.json +44 -12
|
@@ -22,7 +22,7 @@ export interface AutoUpdaterLike {
|
|
|
22
22
|
provider: 'generic';
|
|
23
23
|
url: string;
|
|
24
24
|
}): void;
|
|
25
|
-
requestHeaders: Record<string,
|
|
25
|
+
requestHeaders: Record<string, unknown> | null;
|
|
26
26
|
disableDifferentialDownload: boolean;
|
|
27
27
|
autoDownload: boolean;
|
|
28
28
|
checkForUpdates(): Promise<{
|
|
@@ -36,8 +36,15 @@ export interface GrantedUpdaterOptions {
|
|
|
36
36
|
slug: string;
|
|
37
37
|
/** The platform origin, e.g. `https://xenosystem.ai`. */
|
|
38
38
|
platformBase: string;
|
|
39
|
-
/**
|
|
40
|
-
|
|
39
|
+
/**
|
|
40
|
+
* The request headers for one request, from the app's account SDK; `null` when signed out. Preferred: it
|
|
41
|
+
* carries sender-constrained (DPoP) proofs, which are bound to the exact method and URL.
|
|
42
|
+
*/
|
|
43
|
+
authorize?: (method: 'GET', url: string) => Promise<Record<string, string> | null>;
|
|
44
|
+
/** Or, for a plain bearer token: the account's current access token; `null` when signed out. */
|
|
45
|
+
getAccessToken?: () => Promise<string | null>;
|
|
46
|
+
/** `process.platform`; decides which feed file electron-updater fetches. */
|
|
47
|
+
platform?: string;
|
|
41
48
|
updater: AutoUpdaterLike;
|
|
42
49
|
/** The running app's version (`app.getVersion()`). */
|
|
43
50
|
currentVersion: string;
|
|
@@ -58,10 +65,12 @@ export type UpdateCheck = {
|
|
|
58
65
|
};
|
|
59
66
|
/** The gated feed for a product. electron-updater appends `/latest.yml` (or `-linux`/`-mac`) itself. */
|
|
60
67
|
export declare function gatedFeedUrl(platformBase: string, slug: string): string;
|
|
68
|
+
/** The file electron-updater's generic provider fetches on this platform. */
|
|
69
|
+
export declare function feedFileFor(platform?: string): string;
|
|
61
70
|
/** Compare dotted versions numerically; a pre-release tag sorts below its release. */
|
|
62
71
|
export declare function isNewer(candidate: string, current: string): boolean;
|
|
63
72
|
export declare function createGrantedUpdater(options: GrantedUpdaterOptions): {
|
|
64
73
|
feedUrl: string;
|
|
65
|
-
/** Configure the updater with
|
|
74
|
+
/** Configure the updater with FRESH credentials and ask the gated feed. Call before every check. */
|
|
66
75
|
check(): Promise<UpdateCheck>;
|
|
67
76
|
};
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
*/
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
21
|
exports.gatedFeedUrl = gatedFeedUrl;
|
|
22
|
+
exports.feedFileFor = feedFileFor;
|
|
22
23
|
exports.isNewer = isNewer;
|
|
23
24
|
exports.createGrantedUpdater = createGrantedUpdater;
|
|
24
25
|
/** The gated feed for a product. electron-updater appends `/latest.yml` (or `-linux`/`-mac`) itself. */
|
|
@@ -32,6 +33,10 @@ function gatedFeedUrl(platformBase, slug) {
|
|
|
32
33
|
}
|
|
33
34
|
return `${base}/api/updates/${slug}/feed`;
|
|
34
35
|
}
|
|
36
|
+
/** The file electron-updater's generic provider fetches on this platform. */
|
|
37
|
+
function feedFileFor(platform = process.platform) {
|
|
38
|
+
return platform === 'darwin' ? 'latest-mac.yml' : platform === 'linux' ? 'latest-linux.yml' : 'latest.yml';
|
|
39
|
+
}
|
|
35
40
|
/** Compare dotted versions numerically; a pre-release tag sorts below its release. */
|
|
36
41
|
function isNewer(candidate, current) {
|
|
37
42
|
const parse = (v) => {
|
|
@@ -63,25 +68,35 @@ const statusOf = (error) => {
|
|
|
63
68
|
return m ? Number(m[1]) : null;
|
|
64
69
|
};
|
|
65
70
|
function createGrantedUpdater(options) {
|
|
66
|
-
const { slug, platformBase, getAccessToken, updater, currentVersion } = options;
|
|
71
|
+
const { slug, platformBase, authorize, getAccessToken, updater, currentVersion } = options;
|
|
72
|
+
if (!authorize && !getAccessToken)
|
|
73
|
+
throw new Error('createGrantedUpdater needs authorize or getAccessToken');
|
|
67
74
|
const url = gatedFeedUrl(platformBase, slug);
|
|
75
|
+
const feedFile = `${url}/${feedFileFor(options.platform)}`;
|
|
76
|
+
const headersFor = async () => {
|
|
77
|
+
try {
|
|
78
|
+
if (authorize)
|
|
79
|
+
return await authorize('GET', feedFile);
|
|
80
|
+
const token = await getAccessToken();
|
|
81
|
+
return token ? { Authorization: `Bearer ${token}` } : null;
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
};
|
|
68
87
|
return {
|
|
69
88
|
feedUrl: url,
|
|
70
|
-
/** Configure the updater with
|
|
89
|
+
/** Configure the updater with FRESH credentials and ask the gated feed. Call before every check. */
|
|
71
90
|
async check() {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
token = await getAccessToken();
|
|
75
|
-
}
|
|
76
|
-
catch {
|
|
77
|
-
token = null;
|
|
78
|
-
}
|
|
79
|
-
if (!token) {
|
|
91
|
+
const headers = await headersFor();
|
|
92
|
+
if (!headers) {
|
|
80
93
|
updater.requestHeaders = null;
|
|
81
94
|
return { state: 'signed-out' };
|
|
82
95
|
}
|
|
83
96
|
updater.setFeedURL({ provider: 'generic', url });
|
|
84
|
-
|
|
97
|
+
// Only the feed request carries these. The installer is fetched from the grant URL inside the feed, which
|
|
98
|
+
// needs no credential; a DPoP proof is bound to the feed URL and would be refused anywhere else anyway.
|
|
99
|
+
updater.requestHeaders = headers;
|
|
85
100
|
// A grant URL with `.blockmap` appended is not a file; a full download is correct and is what runs.
|
|
86
101
|
updater.disableDifferentialDownload = true;
|
|
87
102
|
try {
|
|
@@ -22,7 +22,7 @@ export interface AutoUpdaterLike {
|
|
|
22
22
|
provider: 'generic';
|
|
23
23
|
url: string;
|
|
24
24
|
}): void;
|
|
25
|
-
requestHeaders: Record<string,
|
|
25
|
+
requestHeaders: Record<string, unknown> | null;
|
|
26
26
|
disableDifferentialDownload: boolean;
|
|
27
27
|
autoDownload: boolean;
|
|
28
28
|
checkForUpdates(): Promise<{
|
|
@@ -36,8 +36,15 @@ export interface GrantedUpdaterOptions {
|
|
|
36
36
|
slug: string;
|
|
37
37
|
/** The platform origin, e.g. `https://xenosystem.ai`. */
|
|
38
38
|
platformBase: string;
|
|
39
|
-
/**
|
|
40
|
-
|
|
39
|
+
/**
|
|
40
|
+
* The request headers for one request, from the app's account SDK; `null` when signed out. Preferred: it
|
|
41
|
+
* carries sender-constrained (DPoP) proofs, which are bound to the exact method and URL.
|
|
42
|
+
*/
|
|
43
|
+
authorize?: (method: 'GET', url: string) => Promise<Record<string, string> | null>;
|
|
44
|
+
/** Or, for a plain bearer token: the account's current access token; `null` when signed out. */
|
|
45
|
+
getAccessToken?: () => Promise<string | null>;
|
|
46
|
+
/** `process.platform`; decides which feed file electron-updater fetches. */
|
|
47
|
+
platform?: string;
|
|
41
48
|
updater: AutoUpdaterLike;
|
|
42
49
|
/** The running app's version (`app.getVersion()`). */
|
|
43
50
|
currentVersion: string;
|
|
@@ -58,10 +65,12 @@ export type UpdateCheck = {
|
|
|
58
65
|
};
|
|
59
66
|
/** The gated feed for a product. electron-updater appends `/latest.yml` (or `-linux`/`-mac`) itself. */
|
|
60
67
|
export declare function gatedFeedUrl(platformBase: string, slug: string): string;
|
|
68
|
+
/** The file electron-updater's generic provider fetches on this platform. */
|
|
69
|
+
export declare function feedFileFor(platform?: string): string;
|
|
61
70
|
/** Compare dotted versions numerically; a pre-release tag sorts below its release. */
|
|
62
71
|
export declare function isNewer(candidate: string, current: string): boolean;
|
|
63
72
|
export declare function createGrantedUpdater(options: GrantedUpdaterOptions): {
|
|
64
73
|
feedUrl: string;
|
|
65
|
-
/** Configure the updater with
|
|
74
|
+
/** Configure the updater with FRESH credentials and ask the gated feed. Call before every check. */
|
|
66
75
|
check(): Promise<UpdateCheck>;
|
|
67
76
|
};
|
|
@@ -27,6 +27,10 @@ export function gatedFeedUrl(platformBase, slug) {
|
|
|
27
27
|
}
|
|
28
28
|
return `${base}/api/updates/${slug}/feed`;
|
|
29
29
|
}
|
|
30
|
+
/** The file electron-updater's generic provider fetches on this platform. */
|
|
31
|
+
export function feedFileFor(platform = process.platform) {
|
|
32
|
+
return platform === 'darwin' ? 'latest-mac.yml' : platform === 'linux' ? 'latest-linux.yml' : 'latest.yml';
|
|
33
|
+
}
|
|
30
34
|
/** Compare dotted versions numerically; a pre-release tag sorts below its release. */
|
|
31
35
|
export function isNewer(candidate, current) {
|
|
32
36
|
const parse = (v) => {
|
|
@@ -58,25 +62,35 @@ const statusOf = (error) => {
|
|
|
58
62
|
return m ? Number(m[1]) : null;
|
|
59
63
|
};
|
|
60
64
|
export function createGrantedUpdater(options) {
|
|
61
|
-
const { slug, platformBase, getAccessToken, updater, currentVersion } = options;
|
|
65
|
+
const { slug, platformBase, authorize, getAccessToken, updater, currentVersion } = options;
|
|
66
|
+
if (!authorize && !getAccessToken)
|
|
67
|
+
throw new Error('createGrantedUpdater needs authorize or getAccessToken');
|
|
62
68
|
const url = gatedFeedUrl(platformBase, slug);
|
|
69
|
+
const feedFile = `${url}/${feedFileFor(options.platform)}`;
|
|
70
|
+
const headersFor = async () => {
|
|
71
|
+
try {
|
|
72
|
+
if (authorize)
|
|
73
|
+
return await authorize('GET', feedFile);
|
|
74
|
+
const token = await getAccessToken();
|
|
75
|
+
return token ? { Authorization: `Bearer ${token}` } : null;
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
63
81
|
return {
|
|
64
82
|
feedUrl: url,
|
|
65
|
-
/** Configure the updater with
|
|
83
|
+
/** Configure the updater with FRESH credentials and ask the gated feed. Call before every check. */
|
|
66
84
|
async check() {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
token = await getAccessToken();
|
|
70
|
-
}
|
|
71
|
-
catch {
|
|
72
|
-
token = null;
|
|
73
|
-
}
|
|
74
|
-
if (!token) {
|
|
85
|
+
const headers = await headersFor();
|
|
86
|
+
if (!headers) {
|
|
75
87
|
updater.requestHeaders = null;
|
|
76
88
|
return { state: 'signed-out' };
|
|
77
89
|
}
|
|
78
90
|
updater.setFeedURL({ provider: 'generic', url });
|
|
79
|
-
|
|
91
|
+
// Only the feed request carries these. The installer is fetched from the grant URL inside the feed, which
|
|
92
|
+
// needs no credential; a DPoP proof is bound to the feed URL and would be refused anywhere else anyway.
|
|
93
|
+
updater.requestHeaders = headers;
|
|
80
94
|
// A grant URL with `.blockmap` appended is not a file; a full download is correct and is what runs.
|
|
81
95
|
updater.disableDifferentialDownload = true;
|
|
82
96
|
try {
|
package/package.json
CHANGED
|
@@ -1,28 +1,57 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xenosystem/primitives",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "XENO back-end rung 1 primitives: dirs (the XENO local home), secrets (envelope-encrypted credentials) and updates (the gated app updater).",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"sideEffects": false,
|
|
8
|
-
"engines": {
|
|
9
|
-
|
|
8
|
+
"engines": {
|
|
9
|
+
"node": ">=22.18"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist",
|
|
13
|
+
"README.md"
|
|
14
|
+
],
|
|
10
15
|
"exports": {
|
|
11
16
|
"./dirs": {
|
|
12
|
-
"import": {
|
|
13
|
-
|
|
17
|
+
"import": {
|
|
18
|
+
"types": "./dist/esm/dirs/index.d.ts",
|
|
19
|
+
"default": "./dist/esm/dirs/index.js"
|
|
20
|
+
},
|
|
21
|
+
"require": {
|
|
22
|
+
"types": "./dist/cjs/dirs/index.d.ts",
|
|
23
|
+
"default": "./dist/cjs/dirs/index.js"
|
|
24
|
+
}
|
|
14
25
|
},
|
|
15
26
|
"./secrets": {
|
|
16
|
-
"import": {
|
|
17
|
-
|
|
27
|
+
"import": {
|
|
28
|
+
"types": "./dist/esm/secrets/index.d.ts",
|
|
29
|
+
"default": "./dist/esm/secrets/index.js"
|
|
30
|
+
},
|
|
31
|
+
"require": {
|
|
32
|
+
"types": "./dist/cjs/secrets/index.d.ts",
|
|
33
|
+
"default": "./dist/cjs/secrets/index.js"
|
|
34
|
+
}
|
|
18
35
|
},
|
|
19
36
|
"./updates": {
|
|
20
|
-
"import": {
|
|
21
|
-
|
|
37
|
+
"import": {
|
|
38
|
+
"types": "./dist/esm/updates/index.d.ts",
|
|
39
|
+
"default": "./dist/esm/updates/index.js"
|
|
40
|
+
},
|
|
41
|
+
"require": {
|
|
42
|
+
"types": "./dist/cjs/updates/index.d.ts",
|
|
43
|
+
"default": "./dist/cjs/updates/index.js"
|
|
44
|
+
}
|
|
22
45
|
},
|
|
23
46
|
"./secrets/testing": {
|
|
24
|
-
"import": {
|
|
25
|
-
|
|
47
|
+
"import": {
|
|
48
|
+
"types": "./dist/esm/secrets/testing.d.ts",
|
|
49
|
+
"default": "./dist/esm/secrets/testing.js"
|
|
50
|
+
},
|
|
51
|
+
"require": {
|
|
52
|
+
"types": "./dist/cjs/secrets/testing.d.ts",
|
|
53
|
+
"default": "./dist/cjs/secrets/testing.js"
|
|
54
|
+
}
|
|
26
55
|
},
|
|
27
56
|
"./package.json": "./package.json"
|
|
28
57
|
},
|
|
@@ -36,7 +65,10 @@
|
|
|
36
65
|
"test": "npm run typecheck && node --test \"src/**/*.test.ts\"",
|
|
37
66
|
"prepublishOnly": "node ../../scripts/release-gate.mjs"
|
|
38
67
|
},
|
|
39
|
-
"publishConfig": {
|
|
68
|
+
"publishConfig": {
|
|
69
|
+
"access": "public",
|
|
70
|
+
"registry": "https://registry.npmjs.org/"
|
|
71
|
+
},
|
|
40
72
|
"devDependencies": {
|
|
41
73
|
"@types/node": "24.19.2",
|
|
42
74
|
"typescript": "5.9.3"
|