@oatscenter/trellis 0.100.0-rc.54 → 0.100.0-rc.56
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/auth/connection.js +3 -3
- package/auth/protocol_wasm/client/trellis_protocol_wasm_bg.wasm +0 -0
- package/auth/protocol_wasm/provider/trellis_protocol_wasm_bg.wasm +0 -0
- package/backoff.d.ts +19 -0
- package/backoff.js +32 -0
- package/device.d.ts +1 -1
- package/device.js +18 -4
- package/index.d.ts +1 -1
- package/internal_sdk/generated/_internal/evidence.js +4 -4
- package/internal_sdk/generated/apis/auth/mod.d.ts +110 -3
- package/internal_sdk/generated/apis/auth/mod.js +77 -1
- package/internal_sdk/generated/apps/cli/mod.d.ts +55 -2
- package/internal_sdk/generated/apps/cli/mod.js +26 -0
- package/internal_sdk/generated/apps/console/mod.d.ts +55 -2
- package/internal_sdk/generated/apps/console/mod.js +26 -0
- package/internal_sdk/generated/package.json +2 -2
- package/internal_sdk/generated/participants/eventsRuntime/mod.d.ts +5 -0
- package/internal_sdk/generated/participants/eventsRuntime/mod.js +5 -0
- package/internal_sdk/generated/participants/jobsRuntime/mod.d.ts +5 -0
- package/internal_sdk/generated/participants/jobsRuntime/mod.js +5 -0
- package/internal_sdk/generated/participants/platform/mod.d.ts +51 -4
- package/internal_sdk/generated/participants/platform/mod.js +7 -2
- package/internal_sdk/generated/types/_internal/p0.d.ts +787 -0
- package/internal_sdk/generated/types/_internal/p0.js +232 -0
- package/internal_sdk/generated/types/index.d.ts +78 -0
- package/internal_sdk/generated/types/index.js +39 -0
- package/live/client_open.js +5 -4
- package/package.json +2 -2
- package/service/config.d.ts +122 -11
- package/service/config.js +507 -48
- package/service/mod.d.ts +1 -1
- package/service/runtime/enrollment.js +6 -8
- package/service/runtime/service.d.ts +3 -10
- package/service/runtime/service.js +29 -22
- package/session.d.ts +7 -0
- package/session.js +32 -4
- package/service/runtime/bootstrap.d.ts +0 -3
- package/service/runtime/bootstrap.js +0 -7
- package/service/runtime/runtime.d.ts +0 -16
- package/service/runtime/runtime.js +0 -1
package/auth/connection.js
CHANGED
|
@@ -9,6 +9,7 @@ import { base64urlDecode, base64urlEncode, sha256, utf8 } from "./utils.js";
|
|
|
9
9
|
import { initializeProtocolWasm, signProvisionedAdmissionWasm, verifyOAuthAdmissionWasm, createSessionAuthorityHandleWasm, assertSessionAuthorityHandleCurrentWasm, transportAuthorizationDigestWasm, classifyTransportAuthorizationWasm, } from "./protocol_wasm.js";
|
|
10
10
|
import { loadDefaultRuntimeTransport, } from "../runtime_transport.js";
|
|
11
11
|
import { TransportGenerationManager, } from "../transport/generations.js";
|
|
12
|
+
import { Backoff } from "../backoff.js";
|
|
12
13
|
/** Subjects on which Auth announces a new provider of an API the session calls. */
|
|
13
14
|
const PROVIDERS_NOTICE_SUBJECT_PREFIX = "trellis.auth.providers.";
|
|
14
15
|
const ISSUER_NOTICE_SUBJECT = "trellis.auth.issuers";
|
|
@@ -662,7 +663,7 @@ export async function connectAdmitted(options) {
|
|
|
662
663
|
? AbortSignal.any([options.signal, controller.signal])
|
|
663
664
|
: controller.signal;
|
|
664
665
|
void (async () => {
|
|
665
|
-
|
|
666
|
+
const backoff = new Backoff(100, 5_000);
|
|
666
667
|
while (!signal.aborted && !manager.isClosed() && owner.mirrorFailed) {
|
|
667
668
|
try {
|
|
668
669
|
const lease = await manager.acquirePublishedAttachment();
|
|
@@ -693,12 +694,11 @@ export async function connectAdmitted(options) {
|
|
|
693
694
|
signal.removeEventListener("abort", done);
|
|
694
695
|
resolve();
|
|
695
696
|
};
|
|
696
|
-
const timer = setTimeout(done,
|
|
697
|
+
const timer = setTimeout(done, backoff.failed());
|
|
697
698
|
signal.addEventListener("abort", done, { once: true });
|
|
698
699
|
if (signal.aborted)
|
|
699
700
|
done();
|
|
700
701
|
});
|
|
701
|
-
delay = Math.min(delay * 2, 5_000);
|
|
702
702
|
}
|
|
703
703
|
}
|
|
704
704
|
})().finally(() => {
|
|
Binary file
|
|
Binary file
|
package/backoff.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The waits between attempts of work that keeps failing: `firstMs` after the
|
|
3
|
+
* first failure, doubling with each further failure up to `longestMs`, and
|
|
4
|
+
* back to `firstMs` once the work succeeds.
|
|
5
|
+
*
|
|
6
|
+
* Retry loops in the SDK share this so they all wait the same way (see
|
|
7
|
+
* `design/core/engineering-patterns.md`). It is internal to the package.
|
|
8
|
+
*/
|
|
9
|
+
export declare class Backoff {
|
|
10
|
+
#private;
|
|
11
|
+
/** Waits that start at `firstMs` and double up to `longestMs`. */
|
|
12
|
+
constructor(firstMs: number, longestMs: number);
|
|
13
|
+
/** The wait the next failure returns, in milliseconds, without counting one. */
|
|
14
|
+
get nextDelayMs(): number;
|
|
15
|
+
/** Counts a failure and returns how long to wait, in milliseconds, before trying again. */
|
|
16
|
+
failed(): number;
|
|
17
|
+
/** Starts the waits over after the work succeeded. */
|
|
18
|
+
succeeded(): void;
|
|
19
|
+
}
|
package/backoff.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The waits between attempts of work that keeps failing: `firstMs` after the
|
|
3
|
+
* first failure, doubling with each further failure up to `longestMs`, and
|
|
4
|
+
* back to `firstMs` once the work succeeds.
|
|
5
|
+
*
|
|
6
|
+
* Retry loops in the SDK share this so they all wait the same way (see
|
|
7
|
+
* `design/core/engineering-patterns.md`). It is internal to the package.
|
|
8
|
+
*/
|
|
9
|
+
export class Backoff {
|
|
10
|
+
#firstMs;
|
|
11
|
+
#longestMs;
|
|
12
|
+
#failures = 0;
|
|
13
|
+
/** Waits that start at `firstMs` and double up to `longestMs`. */
|
|
14
|
+
constructor(firstMs, longestMs) {
|
|
15
|
+
this.#firstMs = firstMs;
|
|
16
|
+
this.#longestMs = longestMs;
|
|
17
|
+
}
|
|
18
|
+
/** The wait the next failure returns, in milliseconds, without counting one. */
|
|
19
|
+
get nextDelayMs() {
|
|
20
|
+
return Math.min(this.#firstMs * 2 ** Math.min(this.#failures, 31), this.#longestMs);
|
|
21
|
+
}
|
|
22
|
+
/** Counts a failure and returns how long to wait, in milliseconds, before trying again. */
|
|
23
|
+
failed() {
|
|
24
|
+
const delay = this.nextDelayMs;
|
|
25
|
+
this.#failures += 1;
|
|
26
|
+
return delay;
|
|
27
|
+
}
|
|
28
|
+
/** Starts the waits over after the work succeeded. */
|
|
29
|
+
succeeded() {
|
|
30
|
+
this.#failures = 0;
|
|
31
|
+
}
|
|
32
|
+
}
|
package/device.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "./auth/protocol_wasm_provider.ts";
|
|
2
2
|
import type { NatsConnection } from "@nats-io/nats-core";
|
|
3
3
|
export { checkDeviceActivation } from "./device/activation.ts";
|
|
4
|
-
export type { ConfigChange, ParticipantConfig, ParticipantConfigOf, } from "./service/config.ts";
|
|
4
|
+
export type { ConfigChange, ConfigCheck, ConfigCheckContext, DeriveOptions, DerivedConfig, ParticipantConfig, ParticipantConfigOf, } from "./service/config.ts";
|
|
5
5
|
export type { CheckDeviceActivationArgs, TrellisDeviceActivatedStatus, TrellisDeviceActivationRequiredStatus, TrellisDeviceActivationStatus, TrellisDeviceNotReadyStatus, } from "./device/activation.ts";
|
|
6
6
|
import { AsyncResult, UnexpectedError } from "@oatscenter/result";
|
|
7
7
|
import { type ProvisionedConnectionOptions } from "./auth/connection.ts";
|
package/device.js
CHANGED
|
@@ -21,7 +21,7 @@ import { Value } from "typebox/value";
|
|
|
21
21
|
import { observeTrellisConnection, transitionConnectionAvailability, } from "./connection.js";
|
|
22
22
|
import { createCallerRuntime } from "./caller.js";
|
|
23
23
|
import { getParticipantRuntime, participantEvidence, } from "./participant_runtime/participant.js";
|
|
24
|
-
import {
|
|
24
|
+
import { ConfigHandle, loadConfig, ownReading, } from "./service/config.js";
|
|
25
25
|
import { API as AUTH_API } from "./internal_sdk/generated/apis/auth/mod.js";
|
|
26
26
|
function deviceConnectResult(promise) {
|
|
27
27
|
return AsyncResult.from(promise.then((value) => Result.ok(value), (cause) => Result.err(cause instanceof TransportError
|
|
@@ -372,7 +372,11 @@ export async function connectDeviceWithDeps(args, deps) {
|
|
|
372
372
|
participantId: args.participant.identity,
|
|
373
373
|
fields: configFields,
|
|
374
374
|
read,
|
|
375
|
+
report: (outcome) => trellis.reportOwnConfig(outcome),
|
|
375
376
|
log: resolveDeviceLogger(args.log),
|
|
377
|
+
// A device has no serving phase: reading its settings is putting
|
|
378
|
+
// them to use, after the checks it registers at startup.
|
|
379
|
+
startsOnRead: true,
|
|
376
380
|
});
|
|
377
381
|
config.watch({
|
|
378
382
|
transport: manager,
|
|
@@ -383,9 +387,12 @@ export async function connectDeviceWithDeps(args, deps) {
|
|
|
383
387
|
read: async (atConnect) => ownReading(await read(atConnect)),
|
|
384
388
|
timeoutMs: args.timeout ?? 30_000,
|
|
385
389
|
});
|
|
386
|
-
const watching = config;
|
|
387
|
-
void manager.closed().finally(() => watching.stop());
|
|
388
390
|
}
|
|
391
|
+
// A device without settings still has a handle of its own, so what it
|
|
392
|
+
// registers or derives goes with this connection.
|
|
393
|
+
const settings = config ??
|
|
394
|
+
new ConfigHandle({}, { values: {}, revision: {} }, resolveDeviceLogger(args.log));
|
|
395
|
+
void manager.closed().finally(() => settings.retire());
|
|
389
396
|
const health = new ServiceHealthRuntime({
|
|
390
397
|
serviceName: args.participant.identity,
|
|
391
398
|
kind: "device",
|
|
@@ -415,6 +422,13 @@ export async function connectDeviceWithDeps(args, deps) {
|
|
|
415
422
|
resolveDeviceLogger(args.log).warn({ error }, "Device heartbeat publication failed");
|
|
416
423
|
}
|
|
417
424
|
};
|
|
425
|
+
// A revision the device's own checks rejected degrades its health until
|
|
426
|
+
// one is accepted, and each outcome is reported at once.
|
|
427
|
+
if (config) {
|
|
428
|
+
const watched = config;
|
|
429
|
+
health.add("settings", () => watched.healthCheck());
|
|
430
|
+
watched.onOutcome(() => void publishHealth());
|
|
431
|
+
}
|
|
418
432
|
await publishHealth();
|
|
419
433
|
const heartbeat = setInterval(() => void publishHealth(), health.publishIntervalMs);
|
|
420
434
|
void manager.closed().finally(() => clearInterval(heartbeat));
|
|
@@ -429,7 +443,7 @@ export async function connectDeviceWithDeps(args, deps) {
|
|
|
429
443
|
return Object.assign(createCallerRuntime(trellis, args.participant), {
|
|
430
444
|
health,
|
|
431
445
|
companion,
|
|
432
|
-
config:
|
|
446
|
+
config: settings,
|
|
433
447
|
});
|
|
434
448
|
}
|
|
435
449
|
catch (error) {
|
package/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/** Portable Trellis application API. */
|
|
2
2
|
export * from "./portable.ts";
|
|
3
|
-
export type { AppConfigOf, ConfigChange, ConfigRevision, ParticipantConfig, } from "./service/config.ts";
|
|
3
|
+
export type { AppConfigOf, ConfigChange, ConfigCheck, ConfigCheckContext, ConfigRevision, DeriveOptions, DerivedConfig, ParticipantConfig, } from "./service/config.ts";
|