@faynosync/sdk-js 0.1.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/dist/client.js ADDED
@@ -0,0 +1,211 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Client = void 0;
4
+ const errors_1 = require("./errors");
5
+ const DEFAULT_TIMEOUT_MS = 30_000;
6
+ const USER_AGENT = 'faynosync-js/1.0';
7
+ class Client {
8
+ baseURL;
9
+ edgeURL;
10
+ fetchFn;
11
+ timeoutMs;
12
+ constructor(cfg) {
13
+ this.baseURL = cfg.baseURL;
14
+ this.edgeURL = cfg.edgeURL ?? '';
15
+ this.fetchFn = cfg.fetch ?? globalThis.fetch.bind(globalThis);
16
+ this.timeoutMs = cfg.timeoutMs ?? DEFAULT_TIMEOUT_MS;
17
+ }
18
+ async checkForUpdates(opts, signal) {
19
+ this.validateConfig();
20
+ validateCheckOptions(opts);
21
+ const sig = signal ?? null;
22
+ let edgeError;
23
+ if (this.edgeURL !== '') {
24
+ try {
25
+ const resp = await this.checkEdge(opts, sig);
26
+ if (opts.deviceId) {
27
+ try {
28
+ await this.sendEdgeTelemetryBeacon(opts, !resp.updateAvailable, sig);
29
+ }
30
+ catch {
31
+ // telemetry failures don't affect the update check result
32
+ }
33
+ }
34
+ return { ...resp, source: 'edge' };
35
+ }
36
+ catch (err) {
37
+ edgeError = err;
38
+ if (signal?.aborted === true) {
39
+ throw new errors_1.CheckError(edgeError);
40
+ }
41
+ }
42
+ }
43
+ try {
44
+ const resp = await this.checkAPI(opts, sig);
45
+ return { ...resp, source: 'api' };
46
+ }
47
+ catch (apiError) {
48
+ throw new errors_1.CheckError(edgeError, apiError);
49
+ }
50
+ }
51
+ validateConfig() {
52
+ if (this.baseURL.trim() === '') {
53
+ throw errors_1.ErrMissingBaseURL;
54
+ }
55
+ parseAbsoluteURL(this.baseURL, errors_1.ErrInvalidBaseURL);
56
+ }
57
+ async checkEdge(opts, signal) {
58
+ const url = this.buildEdgeCheckURL(opts);
59
+ return this.doUpdateRequest(url, opts.deviceId, 'edge', signal);
60
+ }
61
+ async checkAPI(opts, signal) {
62
+ const url = this.buildAPICheckURL(opts);
63
+ return this.doUpdateRequest(url, opts.deviceId, 'api', signal);
64
+ }
65
+ async doUpdateRequest(url, deviceId, source, signal) {
66
+ const headers = {
67
+ Accept: 'application/json',
68
+ 'User-Agent': USER_AGENT,
69
+ };
70
+ if (deviceId) {
71
+ headers['X-Device-ID'] = deviceId;
72
+ }
73
+ const reqSignal = createRequestSignal(signal, this.timeoutMs);
74
+ let res;
75
+ try {
76
+ res = await this.fetchFn(url, { headers, signal: reqSignal });
77
+ }
78
+ catch (err) {
79
+ throw new errors_1.EndpointError(source, url, undefined, err);
80
+ }
81
+ if (res.status !== 200) {
82
+ await res.body?.cancel();
83
+ throw new errors_1.EndpointError(source, url, res.status);
84
+ }
85
+ let raw;
86
+ try {
87
+ raw = (await res.json());
88
+ }
89
+ catch (err) {
90
+ throw new errors_1.EndpointError(source, url, undefined, err);
91
+ }
92
+ return parseUpdateResponse(raw);
93
+ }
94
+ buildAPICheckURL(opts) {
95
+ const u = parseAbsoluteURL(this.baseURL, errors_1.ErrInvalidBaseURL);
96
+ u.pathname = joinURLPath(u.pathname, 'checkVersion');
97
+ u.search = new URLSearchParams({
98
+ app_name: opts.appName,
99
+ version: opts.version,
100
+ channel: opts.channel ?? '',
101
+ platform: opts.platform ?? '',
102
+ arch: opts.arch ?? '',
103
+ owner: opts.owner,
104
+ }).toString();
105
+ return u.toString();
106
+ }
107
+ buildEdgeCheckURL(opts) {
108
+ const u = parseAbsoluteURL(this.edgeURL, errors_1.ErrInvalidEdgeURL);
109
+ const segments = [
110
+ 'responses',
111
+ opts.owner,
112
+ opts.appName,
113
+ opts.channel ?? '',
114
+ opts.platform ?? '',
115
+ opts.arch ?? '',
116
+ `${opts.version}.json`,
117
+ ];
118
+ const base = (u.origin + u.pathname).replace(/\/+$/, '');
119
+ return `${base}/${segments.map(encodeURIComponent).join('/')}`;
120
+ }
121
+ buildEdgeTelemetryBeaconURL(opts, isLatest) {
122
+ const u = parseAbsoluteURL(this.baseURL, errors_1.ErrInvalidBaseURL);
123
+ u.pathname = joinURLPath(u.pathname, 'telemetry/beacon');
124
+ u.search = new URLSearchParams({
125
+ app_name: opts.appName,
126
+ version: opts.version,
127
+ channel: opts.channel ?? '',
128
+ platform: opts.platform ?? '',
129
+ arch: opts.arch ?? '',
130
+ owner: opts.owner,
131
+ is_latest: String(isLatest),
132
+ }).toString();
133
+ return u.toString();
134
+ }
135
+ async sendEdgeTelemetryBeacon(opts, isLatest, signal) {
136
+ const url = this.buildEdgeTelemetryBeaconURL(opts, isLatest);
137
+ const headers = { 'User-Agent': USER_AGENT };
138
+ if (opts.deviceId) {
139
+ headers['X-Device-ID'] = opts.deviceId;
140
+ }
141
+ const reqSignal = createRequestSignal(signal, this.timeoutMs);
142
+ const res = await this.fetchFn(url, { headers, signal: reqSignal });
143
+ await res.body?.cancel();
144
+ if (res.status !== 200) {
145
+ throw new errors_1.EndpointError('edge', url, res.status);
146
+ }
147
+ }
148
+ }
149
+ exports.Client = Client;
150
+ function validateCheckOptions(opts) {
151
+ if (!opts.owner)
152
+ throw errors_1.ErrMissingOwner;
153
+ if (!opts.appName)
154
+ throw errors_1.ErrMissingAppName;
155
+ if (!opts.version)
156
+ throw errors_1.ErrMissingVersion;
157
+ }
158
+ function parseAbsoluteURL(raw, sentinel) {
159
+ let u;
160
+ try {
161
+ u = new URL(raw);
162
+ }
163
+ catch {
164
+ throw sentinel;
165
+ }
166
+ if (!u.protocol || !u.hostname) {
167
+ throw sentinel;
168
+ }
169
+ return u;
170
+ }
171
+ function joinURLPath(basePath, segment) {
172
+ if (basePath === '' || basePath === '/') {
173
+ return `/${segment}`;
174
+ }
175
+ return `${basePath.replace(/\/+$/, '')}/${segment}`;
176
+ }
177
+ function createRequestSignal(userSignal, timeoutMs) {
178
+ const timeoutSignal = AbortSignal.timeout(timeoutMs);
179
+ if (userSignal === null)
180
+ return timeoutSignal;
181
+ if (userSignal.aborted) {
182
+ const c = new AbortController();
183
+ c.abort(userSignal.reason);
184
+ return c.signal;
185
+ }
186
+ const controller = new AbortController();
187
+ const abort = (reason) => controller.abort(reason);
188
+ userSignal.addEventListener('abort', () => abort(userSignal.reason), { once: true });
189
+ timeoutSignal.addEventListener('abort', () => abort(timeoutSignal.reason), { once: true });
190
+ return controller.signal;
191
+ }
192
+ function parseUpdateResponse(raw) {
193
+ const packageUrls = [];
194
+ for (const [key, value] of Object.entries(raw)) {
195
+ if (key.startsWith('update_url_') && typeof value === 'string') {
196
+ packageUrls.push({ package: key.slice('update_url_'.length), url: value });
197
+ }
198
+ }
199
+ packageUrls.sort((a, b) => a.package.localeCompare(b.package));
200
+ return {
201
+ updateAvailable: raw.update_available ?? false,
202
+ updateUrl: raw.update_url ?? '',
203
+ changelog: raw.changelog ?? '',
204
+ critical: raw.critical ?? false,
205
+ isIntermediateRequired: raw.is_intermediate_required ?? false,
206
+ possibleRollback: raw.possible_rollback ?? false,
207
+ packageUrls,
208
+ source: 'unknown',
209
+ };
210
+ }
211
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;AACA,qCAUkB;AAElB,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAClC,MAAM,UAAU,GAAG,kBAAkB,CAAC;AAmBtC,MAAa,MAAM;IACA,OAAO,CAAS;IAChB,OAAO,CAAS;IAChB,OAAO,CAA0B;IACjC,SAAS,CAAS;IAEnC,YAAY,GAAW;QACrB,IAAI,CAAC,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC;QAC3B,IAAI,CAAC,OAAO,GAAG,GAAG,CAAC,OAAO,IAAI,EAAE,CAAC;QACjC,IAAI,CAAC,OAAO,GAAG,GAAG,CAAC,KAAK,IAAI,UAAU,CAAC,KAAK,CAAC,IAAI,CAA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,MAAM,CAAC;AAC3B,CAAC;AAED,SAAS,mBAAmB,CAAC,GAAsB;IACjD,MAAM,WAAW,GAAuB,EAAE,CAAC;IAE3C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QAC/C,IAAI,GAAG,CAAC,UAAU,CAAC,aAAa,CAAC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC/D,WAAW,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,GAAG,CAAC,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC;QAC7E,CAAC;IACH,CAAC;IAED,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;IAE/D,OAAO;QACL,eAAe,EAAE,GAAG,CAAC,gBAAgB,IAAI,KAAK;QAC9C,SAAS,EAAE,GAAG,CAAC,UAAU,IAAI,EAAE;QAC/B,SAAS,EAAE,GAAG,CAAC,SAAS,IAAI,EAAE;QAC9B,QAAQ,EAAE,GAAG,CAAC,QAAQ,IAAI,KAAK;QAC/B,sBAAsB,EAAE,GAAG,CAAC,wBAAwB,IAAI,KAAK;QAC7D,gBAAgB,EAAE,GAAG,CAAC,iBAAiB,IAAI,KAAK;QAChD,WAAW;QACX,MAAM,EAAE,SAAS;KAClB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,28 @@
1
+ import type { UpdateSource } from './types';
2
+ export declare class FaynoSyncError extends Error {
3
+ constructor(message: string);
4
+ }
5
+ export declare class ValidationError extends FaynoSyncError {
6
+ constructor(message: string);
7
+ }
8
+ export declare class RequestFailedError extends FaynoSyncError {
9
+ constructor(message: string);
10
+ }
11
+ export declare class EndpointError extends RequestFailedError {
12
+ readonly source: UpdateSource;
13
+ readonly endpointUrl: string;
14
+ readonly statusCode?: number | undefined;
15
+ constructor(source: UpdateSource, endpointUrl: string, statusCode?: number | undefined, cause?: Error);
16
+ }
17
+ export declare class CheckError extends RequestFailedError {
18
+ readonly edgeError?: Error | undefined;
19
+ readonly apiError?: Error | undefined;
20
+ constructor(edgeError?: Error | undefined, apiError?: Error | undefined);
21
+ }
22
+ export declare const ErrMissingBaseURL: ValidationError;
23
+ export declare const ErrInvalidBaseURL: ValidationError;
24
+ export declare const ErrInvalidEdgeURL: ValidationError;
25
+ export declare const ErrMissingOwner: ValidationError;
26
+ export declare const ErrMissingAppName: ValidationError;
27
+ export declare const ErrMissingVersion: ValidationError;
28
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C,qBAAa,cAAe,SAAQ,KAAK;gBAC3B,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,eAAgB,SAAQ,cAAc;gBACrC,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,kBAAmB,SAAQ,cAAc;gBACxC,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,aAAc,SAAQ,kBAAkB;aAEjC,MAAM,EAAE,YAAY;aACpB,WAAW,EAAE,MAAM;aACnB,UAAU,CAAC,EAAE,MAAM;gBAFnB,MAAM,EAAE,YAAY,EACpB,WAAW,EAAE,MAAM,EACnB,UAAU,CAAC,EAAE,MAAM,YAAA,EACnC,KAAK,CAAC,EAAE,KAAK;CAgBhB;AAED,qBAAa,UAAW,SAAQ,kBAAkB;aAE9B,SAAS,CAAC,EAAE,KAAK;aACjB,QAAQ,CAAC,EAAE,KAAK;gBADhB,SAAS,CAAC,EAAE,KAAK,YAAA,EACjB,QAAQ,CAAC,EAAE,KAAK,YAAA;CAenC;AAED,eAAO,MAAM,iBAAiB,iBAAqD,CAAC;AACpF,eAAO,MAAM,iBAAiB,iBAAqD,CAAC;AACpF,eAAO,MAAM,iBAAiB,iBAAqD,CAAC;AACpF,eAAO,MAAM,eAAe,iBAAkD,CAAC;AAC/E,eAAO,MAAM,iBAAiB,iBAAqD,CAAC;AACpF,eAAO,MAAM,iBAAiB,iBAAoD,CAAC"}
package/dist/errors.js ADDED
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ErrMissingVersion = exports.ErrMissingAppName = exports.ErrMissingOwner = exports.ErrInvalidEdgeURL = exports.ErrInvalidBaseURL = exports.ErrMissingBaseURL = exports.CheckError = exports.EndpointError = exports.RequestFailedError = exports.ValidationError = exports.FaynoSyncError = void 0;
4
+ class FaynoSyncError extends Error {
5
+ constructor(message) {
6
+ super(message);
7
+ this.name = 'FaynoSyncError';
8
+ }
9
+ }
10
+ exports.FaynoSyncError = FaynoSyncError;
11
+ class ValidationError extends FaynoSyncError {
12
+ constructor(message) {
13
+ super(message);
14
+ this.name = 'ValidationError';
15
+ }
16
+ }
17
+ exports.ValidationError = ValidationError;
18
+ class RequestFailedError extends FaynoSyncError {
19
+ constructor(message) {
20
+ super(message);
21
+ this.name = 'RequestFailedError';
22
+ }
23
+ }
24
+ exports.RequestFailedError = RequestFailedError;
25
+ class EndpointError extends RequestFailedError {
26
+ source;
27
+ endpointUrl;
28
+ statusCode;
29
+ constructor(source, endpointUrl, statusCode, cause) {
30
+ let msg;
31
+ if (statusCode !== undefined) {
32
+ msg = `faynosync: request failed: ${endpointUrl} returned HTTP ${statusCode}`;
33
+ }
34
+ else if (cause !== undefined) {
35
+ msg = `faynosync: request failed: ${endpointUrl}: ${cause.message}`;
36
+ }
37
+ else {
38
+ msg = `faynosync: request failed: ${endpointUrl}`;
39
+ }
40
+ super(msg);
41
+ this.source = source;
42
+ this.endpointUrl = endpointUrl;
43
+ this.statusCode = statusCode;
44
+ this.name = 'EndpointError';
45
+ if (cause !== undefined) {
46
+ this.cause = cause;
47
+ }
48
+ }
49
+ }
50
+ exports.EndpointError = EndpointError;
51
+ class CheckError extends RequestFailedError {
52
+ edgeError;
53
+ apiError;
54
+ constructor(edgeError, apiError) {
55
+ let msg;
56
+ if (edgeError !== undefined && apiError !== undefined) {
57
+ msg = `faynosync: request failed: edge failed: ${edgeError.message}; api failed: ${apiError.message}`;
58
+ }
59
+ else if (edgeError !== undefined) {
60
+ msg = `faynosync: request failed: edge failed: ${edgeError.message}`;
61
+ }
62
+ else if (apiError !== undefined) {
63
+ msg = `faynosync: request failed: api failed: ${apiError.message}`;
64
+ }
65
+ else {
66
+ msg = 'faynosync: request failed';
67
+ }
68
+ super(msg);
69
+ this.edgeError = edgeError;
70
+ this.apiError = apiError;
71
+ this.name = 'CheckError';
72
+ }
73
+ }
74
+ exports.CheckError = CheckError;
75
+ exports.ErrMissingBaseURL = new ValidationError('faynosync: missing base URL');
76
+ exports.ErrInvalidBaseURL = new ValidationError('faynosync: invalid base URL');
77
+ exports.ErrInvalidEdgeURL = new ValidationError('faynosync: invalid edge URL');
78
+ exports.ErrMissingOwner = new ValidationError('faynosync: missing owner');
79
+ exports.ErrMissingAppName = new ValidationError('faynosync: missing app name');
80
+ exports.ErrMissingVersion = new ValidationError('faynosync: missing version');
81
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AAEA,MAAa,cAAe,SAAQ,KAAK;IACvC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAC/B,CAAC;CACF;AALD,wCAKC;AAED,MAAa,eAAgB,SAAQ,cAAc;IACjD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF;AALD,0CAKC;AAED,MAA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C,OAAO,EAAE,CAAC;QACvE,CAAC;aAAM,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;YAClC,GAAG,GAAG,0CAA0C,QAAQ,CAAC,OAAO,EAAE,CAAC;QACrE,CAAC;aAAM,CAAC;YACN,GAAG,GAAG,2BAA2B,CAAC;QACpC,CAAC;QACD,KAAK,CAAC,GAAG,CAAC,CAAC;QAbK,cAAS,GAAT,SAAS,CAAQ;QACjB,aAAQ,GAAR,QAAQ,CAAQ;QAahC,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;IAC3B,CAAC;CACF;AAlBD,gCAkBC;AAEY,QAAA,iBAAiB,GAAG,IAAI,eAAe,CAAC,6BAA6B,CAAC,CAAC;AACvE,QAAA,iBAAiB,GAAG,IAAI,eAAe,CAAC,6BAA6B,CAAC,CAAC;AACvE,QAAA,iBAAiB,GAAG,IAAI,eAAe,CAAC,6BAA6B,CAAC,CAAC;AACvE,QAAA,eAAe,GAAG,IAAI,eAAe,CAAC,0BAA0B,CAAC,CAAC;AAClE,QAAA,iBAAiB,GAAG,IAAI,eAAe,CAAC,6BAA6B,CAAC,CAAC;AACvE,QAAA,iBAAiB,GAAG,IAAI,eAAe,CAAC,4BAA4B,CAAC,CAAC"}
@@ -0,0 +1,6 @@
1
+ export { Client } from './client';
2
+ export type { Config } from './client';
3
+ export type { CheckOptions, PackageUpdateURL, UpdateResponse, UpdateSource } from './types';
4
+ export { CheckError, EndpointError, ErrInvalidBaseURL, ErrInvalidEdgeURL, ErrMissingAppName, ErrMissingBaseURL, ErrMissingOwner, ErrMissingVersion, FaynoSyncError, RequestFailedError, ValidationError, } from './errors';
5
+ export { systemArch, systemPlatform } from './system';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,YAAY,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACvC,YAAY,EAAE,YAAY,EAAE,gBAAgB,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC5F,OAAO,EACL,UAAU,EACV,aAAa,EACb,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,cAAc,EACd,kBAAkB,EAClB,eAAe,GAChB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.systemPlatform = exports.systemArch = exports.ValidationError = exports.RequestFailedError = exports.FaynoSyncError = exports.ErrMissingVersion = exports.ErrMissingOwner = exports.ErrMissingBaseURL = exports.ErrMissingAppName = exports.ErrInvalidEdgeURL = exports.ErrInvalidBaseURL = exports.EndpointError = exports.CheckError = exports.Client = void 0;
4
+ var client_1 = require("./client");
5
+ Object.defineProperty(exports, "Client", { enumerable: true, get: function () { return client_1.Client; } });
6
+ var errors_1 = require("./errors");
7
+ Object.defineProperty(exports, "CheckError", { enumerable: true, get: function () { return errors_1.CheckError; } });
8
+ Object.defineProperty(exports, "EndpointError", { enumerable: true, get: function () { return errors_1.EndpointError; } });
9
+ Object.defineProperty(exports, "ErrInvalidBaseURL", { enumerable: true, get: function () { return errors_1.ErrInvalidBaseURL; } });
10
+ Object.defineProperty(exports, "ErrInvalidEdgeURL", { enumerable: true, get: function () { return errors_1.ErrInvalidEdgeURL; } });
11
+ Object.defineProperty(exports, "ErrMissingAppName", { enumerable: true, get: function () { return errors_1.ErrMissingAppName; } });
12
+ Object.defineProperty(exports, "ErrMissingBaseURL", { enumerable: true, get: function () { return errors_1.ErrMissingBaseURL; } });
13
+ Object.defineProperty(exports, "ErrMissingOwner", { enumerable: true, get: function () { return errors_1.ErrMissingOwner; } });
14
+ Object.defineProperty(exports, "ErrMissingVersion", { enumerable: true, get: function () { return errors_1.ErrMissingVersion; } });
15
+ Object.defineProperty(exports, "FaynoSyncError", { enumerable: true, get: function () { return errors_1.FaynoSyncError; } });
16
+ Object.defineProperty(exports, "RequestFailedError", { enumerable: true, get: function () { return errors_1.RequestFailedError; } });
17
+ Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function () { return errors_1.ValidationError; } });
18
+ var system_1 = require("./system");
19
+ Object.defineProperty(exports, "systemArch", { enumerable: true, get: function () { return system_1.systemArch; } });
20
+ Object.defineProperty(exports, "systemPlatform", { enumerable: true, get: function () { return system_1.systemPlatform; } });
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mCAAkC;AAAzB,gGAAA,MAAM,OAAA;AAGf,mCAYkB;AAXhB,oGAAA,UAAU,OAAA;AACV,uGAAA,aAAa,OAAA;AACb,2GAAA,iBAAiB,OAAA;AACjB,2GAAA,iBAAiB,OAAA;AACjB,2GAAA,iBAAiB,OAAA;AACjB,2GAAA,iBAAiB,OAAA;AACjB,yGAAA,eAAe,OAAA;AACf,2GAAA,iBAAiB,OAAA;AACjB,wGAAA,cAAc,OAAA;AACd,4GAAA,kBAAkB,OAAA;AAClB,yGAAA,eAAe,OAAA;AAEjB,mCAAsD;AAA7C,oGAAA,UAAU,OAAA;AAAE,wGAAA,cAAc,OAAA"}
@@ -0,0 +1,3 @@
1
+ export declare function systemPlatform(): string;
2
+ export declare function systemArch(): string;
3
+ //# sourceMappingURL=system.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"system.d.ts","sourceRoot":"","sources":["../src/system.ts"],"names":[],"mappings":"AAAA,wBAAgB,cAAc,IAAI,MAAM,CAEvC;AAED,wBAAgB,UAAU,IAAI,MAAM,CAEnC"}
package/dist/system.js ADDED
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.systemPlatform = systemPlatform;
4
+ exports.systemArch = systemArch;
5
+ function systemPlatform() {
6
+ return process.platform;
7
+ }
8
+ function systemArch() {
9
+ return process.arch;
10
+ }
11
+ //# sourceMappingURL=system.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"system.js","sourceRoot":"","sources":["../src/system.ts"],"names":[],"mappings":";;AAAA,wCAEC;AAED,gCAEC;AAND,SAAgB,cAAc;IAC5B,OAAO,OAAO,CAAC,QAAQ,CAAC;AAC1B,CAAC;AAED,SAAgB,UAAU;IACxB,OAAO,OAAO,CAAC,IAAI,CAAC;AACtB,CAAC"}
@@ -0,0 +1,25 @@
1
+ export type UpdateSource = 'unknown' | 'edge' | 'api';
2
+ export interface PackageUpdateURL {
3
+ readonly package: string;
4
+ readonly url: string;
5
+ }
6
+ export interface CheckOptions {
7
+ readonly owner: string;
8
+ readonly appName: string;
9
+ readonly version: string;
10
+ readonly channel?: string;
11
+ readonly platform?: string;
12
+ readonly arch?: string;
13
+ readonly deviceId?: string;
14
+ }
15
+ export interface UpdateResponse {
16
+ readonly updateAvailable: boolean;
17
+ readonly updateUrl: string;
18
+ readonly changelog: string;
19
+ readonly critical: boolean;
20
+ readonly isIntermediateRequired: boolean;
21
+ readonly possibleRollback: boolean;
22
+ readonly packageUrls: readonly PackageUpdateURL[];
23
+ readonly source: UpdateSource;
24
+ }
25
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,MAAM,GAAG,KAAK,CAAC;AAEtD,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,eAAe,EAAE,OAAO,CAAC;IAClC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,sBAAsB,EAAE,OAAO,CAAC;IACzC,QAAQ,CAAC,gBAAgB,EAAE,OAAO,CAAC;IACnC,QAAQ,CAAC,WAAW,EAAE,SAAS,gBAAgB,EAAE,CAAC;IAClD,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;CAC/B"}
package/dist/types.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,17 @@
1
+ # basic
2
+
3
+ Minimal update check using the faynoSync JS SDK.
4
+
5
+ Demonstrates:
6
+
7
+ - Creating a `Client` with only `baseURL`
8
+ - Using `systemPlatform()` and `systemArch()` to pass Node.js runtime values
9
+ - Distinguishing request failures (`RequestFailedError`) from validation errors
10
+
11
+ ## Run
12
+
13
+ ```sh
14
+ npx ts-node examples/basic/index.ts
15
+ ```
16
+
17
+ Expects a faynoSync server running at `http://localhost:9000`.
@@ -0,0 +1,75 @@
1
+ import { Client, RequestFailedError, systemArch, systemPlatform } from '../../src';
2
+ import type { UpdateResponse, UpdateSource } from '../../src';
3
+
4
+ const client = new Client({
5
+ baseURL: 'http://localhost:9000',
6
+ });
7
+
8
+ async function main(): Promise<void> {
9
+ let resp: UpdateResponse;
10
+ try {
11
+ resp = await client.checkForUpdates({
12
+ owner: 'admin',
13
+ appName: 'test',
14
+ version: '0.0.0.1',
15
+ channel: 'nightly',
16
+ platform: systemPlatform(),
17
+ arch: systemArch(),
18
+ });
19
+ } catch (err) {
20
+ if (err instanceof RequestFailedError) {
21
+ console.error('update check request failed:', err.message);
22
+ } else {
23
+ console.error('invalid update check options:', (err as Error).message);
24
+ }
25
+ process.exit(1);
26
+ }
27
+
28
+ printUpdateResponse(resp);
29
+ }
30
+
31
+ function printUpdateResponse(resp: UpdateResponse): void {
32
+ const pad = ' ';
33
+
34
+ console.log('-- Update check response --');
35
+ console.log(`${pad}update_available: ${resp.updateAvailable}`);
36
+ console.log(`${pad}critical: ${resp.critical}`);
37
+ console.log(`${pad}is_intermediate_required: ${resp.isIntermediateRequired}`);
38
+ console.log(`${pad}possible_rollback: ${resp.possibleRollback}`);
39
+ console.log(`${pad}source: ${formatUpdateSource(resp.source)}`);
40
+
41
+ if (resp.updateUrl !== '') {
42
+ console.log(`${pad}update_url: ${resp.updateUrl}`);
43
+ } else {
44
+ console.log(`${pad}update_url: (empty)`);
45
+ }
46
+
47
+ if (resp.changelog !== '') {
48
+ console.log(`${pad}changelog:`);
49
+ for (const line of resp.changelog.trimEnd().split('\n')) {
50
+ console.log(`${pad} ${line}`);
51
+ }
52
+ } else {
53
+ console.log(`${pad}changelog: (empty)`);
54
+ }
55
+
56
+ if (resp.packageUrls.length === 0) {
57
+ console.log(`${pad}package_urls: (none)`);
58
+ return;
59
+ }
60
+
61
+ console.log(`${pad}package_urls:`);
62
+ for (const pkg of resp.packageUrls) {
63
+ console.log(`${pad} ${pkg.package.padEnd(12)} ${pkg.url}`);
64
+ }
65
+ }
66
+
67
+ function formatUpdateSource(source: UpdateSource): string {
68
+ switch (source) {
69
+ case 'edge': return 'edge';
70
+ case 'api': return 'api';
71
+ default: return 'unknown';
72
+ }
73
+ }
74
+
75
+ main();
@@ -0,0 +1,29 @@
1
+ # custom-fetch
2
+
3
+ Update check with a custom `fetch` function and explicit timeout.
4
+
5
+ Demonstrates:
6
+
7
+ - Supplying a custom `fetch` to `Client` for connection reuse via `https.Agent`
8
+ - Setting `timeoutMs` to control per-request deadline
9
+ - Passing `deviceId` alongside a custom transport
10
+
11
+ ## When to use a custom `fetch`
12
+
13
+ The default `globalThis.fetch` (Node.js 18+ built-in) creates a new connection for every request. For applications that poll frequently, supply a custom `fetch` backed by an agent with `keepAlive: true` to reuse connections and reduce latency.
14
+
15
+ ```ts
16
+ const client = new Client({
17
+ baseURL: 'https://api.example.com',
18
+ fetch: myFetch, // e.g. wraps undici or node-fetch with a shared agent
19
+ timeoutMs: 10_000,
20
+ });
21
+ ```
22
+
23
+ ## Run
24
+
25
+ ```sh
26
+ npx ts-node examples/custom-fetch/index.ts
27
+ ```
28
+
29
+ Expects a faynoSync server running at `http://localhost:9000`.