@north-light/sdk 0.3.450 → 0.3.452

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.d.ts CHANGED
@@ -63,6 +63,14 @@ export interface CrouterOptions {
63
63
  /** On a cold socket, run `crtr sys daemon start` and retry once. Node only. Defaults to true for a socket, false for `baseURL`. */
64
64
  autostart?: boolean;
65
65
  }
66
+ /** The namespaces of `Crouter` that only the owner's own daemon serves. A person's app listener answers them `404 unknown operation`. */
67
+ export type OwnerOnly = 'nodes' | 'bash' | 'canvas' | 'crons' | 'structuredRequests' | 'customObjects' | 'human' | 'models' | 'system' | 'auth';
68
+ /** What an app reaches on a person's runtime (the app listener): `Crouter` without the owner-daemon namespaces, `files.download`
69
+ * only, and `profiles.list` only. `Crouter` is assignable to it, so a function that takes `AppClient` takes either. */
70
+ export type AppClient = Omit<Crouter, OwnerOnly | 'files' | 'profiles'> & {
71
+ readonly files: Pick<Files, 'download'>;
72
+ readonly profiles: Pick<Crouter['profiles'], 'list'>;
73
+ };
66
74
  /**
67
75
  * The client, and the only class an application constructs. Each namespace below wraps a
68
76
  * family of daemon routes; `request` is the escape hatch for a route with no wrapper.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { Crouter as default, Crouter } from './client.js';
2
- export type { CrouterOptions } from './client.js';
2
+ export type { AppClient, CrouterOptions, OwnerOnly } from './client.js';
3
3
  export { NodeStream } from './resources/node-stream.js';
4
4
  export { RunStream } from './resources/run-stream.js';
5
5
  export { CustomObjects } from './resources/custom-objects.js';
@@ -1,6 +1,6 @@
1
1
  import { type JWK } from 'jose';
2
2
  import { type IdTokenClaims } from '@north-light/identity';
3
- import { Crouter, type CrouterOptions } from '../client.js';
3
+ import { type AppClient, type CrouterOptions } from '../client.js';
4
4
  import { RunWatcher, type RunWatchOptions } from '../resources/run-watcher.js';
5
5
  import { GrantWatcher, type GrantWatchOptions } from '../resources/grant-watcher.js';
6
6
  import { type Refusal } from './refusal.js';
@@ -104,9 +104,14 @@ export interface OAuth2Options {
104
104
  */
105
105
  timeoutMs?: number;
106
106
  }
107
- /** A runtime client on one person's stored connection (`oauth.client(userId)`): a `Crouter` that refreshes its
108
- * token through the `OAuth2Client`'s store, plus whose connection it is and the runtime it calls. */
109
- export declare class ConnectedCrouter extends Crouter {
107
+ /** The class `ConnectedCrouter` extends: `Crouter`'s implementation under the type of what a person's app listener serves. */
108
+ declare const AppCrouter: new (options: CrouterOptions) => AppClient;
109
+ /** A runtime client on one person's stored connection (`oauth.client(userId)`): an `AppClient` that refreshes its
110
+ * token through the `OAuth2Client`'s store, plus whose connection it is and the runtime it calls. It offers only what
111
+ * the person's app listener serves. The owner-daemon namespaces (`nodes`, `crons`, `canvas`, …) are absent from its
112
+ * type and throw `CrouterError` if reached anyway; `files` is `download` only and `profiles` is `list` only.
113
+ * `request` still sends any route. */
114
+ export declare class ConnectedCrouter extends AppCrouter {
110
115
  /** The person whose connection this client uses (`user:<id>`). */
111
116
  readonly userId: string;
112
117
  /** The person's runtime URL this client calls, as the stored connection named it. */
@@ -62,9 +62,15 @@ function httpsUrl(value) {
62
62
  return undefined;
63
63
  }
64
64
  }
65
- /** A runtime client on one person's stored connection (`oauth.client(userId)`): a `Crouter` that refreshes its
66
- * token through the `OAuth2Client`'s store, plus whose connection it is and the runtime it calls. */
67
- export class ConnectedCrouter extends Crouter {
65
+ const OWNER_ONLY = ['nodes', 'bash', 'canvas', 'crons', 'structuredRequests', 'customObjects', 'human', 'models', 'system', 'auth'];
66
+ /** The class `ConnectedCrouter` extends: `Crouter`'s implementation under the type of what a person's app listener serves. */
67
+ const AppCrouter = Crouter;
68
+ /** A runtime client on one person's stored connection (`oauth.client(userId)`): an `AppClient` that refreshes its
69
+ * token through the `OAuth2Client`'s store, plus whose connection it is and the runtime it calls. It offers only what
70
+ * the person's app listener serves. The owner-daemon namespaces (`nodes`, `crons`, `canvas`, …) are absent from its
71
+ * type and throw `CrouterError` if reached anyway; `files` is `download` only and `profiles` is `list` only.
72
+ * `request` still sends any route. */
73
+ export class ConnectedCrouter extends AppCrouter {
68
74
  /** The person whose connection this client uses (`user:<id>`). */
69
75
  userId;
70
76
  /** The person's runtime URL this client calls, as the stored connection named it. */
@@ -73,6 +79,14 @@ export class ConnectedCrouter extends Crouter {
73
79
  super({ ...options, baseURL: connection.runtimeUrl });
74
80
  this.userId = connection.userId;
75
81
  this.runtimeUrl = connection.runtimeUrl;
82
+ for (const name of OWNER_ONLY) {
83
+ Object.defineProperty(this, name, { configurable: true, get() {
84
+ throw new CrouterError(`client.${name} is not served on an app's runtime connection; it belongs to the owner's own daemon (new Crouter() on its socket)`);
85
+ } });
86
+ }
87
+ const { files, profiles } = this;
88
+ Object.defineProperty(this, 'files', { value: { download: files.download.bind(files) } });
89
+ Object.defineProperty(this, 'profiles', { value: { list: profiles.list } });
76
90
  }
77
91
  }
78
92
  /** The default deadline of one directory operation (`OAuth2Options.timeoutMs`): a discovery read is forgotten when it passes. */
@@ -1,7 +1,7 @@
1
- import type { Crouter } from '../client.js';
1
+ import type { AppClient } from '../client.js';
2
2
  /** Native EventSource sends Last-Event-ID on reconnect; it takes precedence over the URL cursor. */
3
3
  export declare function cursorFromRequest(request: Request): number;
4
- export declare function forwardRunEvents(crouter: Crouter, runId: string, options: {
4
+ export declare function forwardRunEvents(crouter: AppClient, runId: string, options: {
5
5
  after: number;
6
6
  signal?: AbortSignal;
7
7
  }): Response;
@@ -1,5 +1,5 @@
1
1
  import type { GrantGetDTO } from '@north-light/api';
2
- import type { Crouter } from '../client.js';
2
+ import type { AppClient } from '../client.js';
3
3
  /** One grant reading `GrantWatcher` hands to `onChanged`. `previous` is the grant last delivered for this user in this
4
4
  * process, or `null` on the first delivery (also after a restart, or after the user left and re-entered `users()`). */
5
5
  export interface GrantChanged {
@@ -46,7 +46,7 @@ export declare class GrantWatcher {
46
46
  /** Users whose last held read answered at once with the same version: their next turn pauses first. */
47
47
  private readonly unheld;
48
48
  private readonly follower;
49
- constructor(open: (userId: string) => Promise<Crouter>, options: GrantWatchOptions);
49
+ constructor(open: (userId: string) => Promise<AppClient>, options: GrantWatchOptions);
50
50
  /** Read `users()` and begin following; sweeps repeat every `sweepMs` until `stop()`. Resolves after the first sweep. */
51
51
  start(): Promise<void>;
52
52
  /** Sweep now instead of waiting for `sweepMs`, for example right after the app starts waiting on someone. */
@@ -1,4 +1,4 @@
1
- import type { Crouter } from '../client.js';
1
+ import type { AppClient } from '../client.js';
2
2
  import type { RunActivity, RunObject } from './runs.js';
3
3
  /** A run the app is still waiting on: whose runtime holds it, and its id. `pending()` returns these from the app's own rows. */
4
4
  export interface PendingRun {
@@ -87,7 +87,7 @@ export declare class RunWatcher {
87
87
  /** Runs that rested and were delivered: re-read only on sweeps. */
88
88
  private readonly resting;
89
89
  private readonly follower;
90
- constructor(open: (userId: string) => Promise<Crouter>, options: RunWatchOptions);
90
+ constructor(open: (userId: string) => Promise<AppClient>, options: RunWatchOptions);
91
91
  private get running();
92
92
  /** Read `pending()` and begin following; sweeps repeat every `sweepMs` until `stop()`. Resolves after the first sweep. */
93
93
  start(): Promise<void>;
package/dist/version.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /** This SDK's release version. Informational only: compatibility is the contract level, not this number. */
2
- export declare const SDK_VERSION = "0.3.450";
2
+ export declare const SDK_VERSION = "0.3.452";
3
3
  /** The release sent in `Crouter-Minimum-Runtime-Version` on every request. It is frozen, so a runtime from before the
4
4
  * contract level existed (which only knows this header) refuses this SDK, while every later runtime accepts it. */
5
5
  export declare const LEGACY_FLOOR = "0.3.423";
package/dist/version.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // SDK_VERSION is written by scripts/release-version.mjs on every release; do not edit by hand.
2
2
  /** This SDK's release version. Informational only: compatibility is the contract level, not this number. */
3
- export const SDK_VERSION = '0.3.450';
3
+ export const SDK_VERSION = '0.3.452';
4
4
  // LEGACY_FLOOR is written once by `scripts/contract.mjs release`, at the first release that carries the contract level
5
5
  // (the `0.0.0` placeholder is replaced there and never again); do not edit by hand.
6
6
  /** The release sent in `Crouter-Minimum-Runtime-Version` on every request. It is frozen, so a runtime from before the
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@north-light/sdk",
3
- "version": "0.3.450",
4
- "crouterContract": "1.2",
3
+ "version": "0.3.452",
4
+ "crouterContract": "1.3",
5
5
  "description": "Typed Node and browser client for running crouter agents through the crtrd /v1 API.",
6
6
  "type": "module",
7
7
  "main": "./dist/index.js",
@@ -41,8 +41,8 @@
41
41
  "prepublishOnly": "node -e \"if (process.env.npm_config_tag !== 'next') { console.error('@north-light/sdk publishes only with --tag next; scripts/promote-sdk.mjs is the only mover of latest.'); process.exit(1); }\""
42
42
  },
43
43
  "dependencies": {
44
- "@north-light/api": "0.3.450",
45
- "@north-light/identity": "0.3.450",
44
+ "@north-light/api": "0.3.452",
45
+ "@north-light/identity": "0.3.452",
46
46
  "jose": "^6.2.1"
47
47
  },
48
48
  "peerDependencies": {