@nylorun/admin 0.2.0-beta → 0.3.0-beta

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/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.0-beta
4
+
5
+ ### Minor Changes
6
+
7
+ - bf1c2da: **Tenants can register a Studio principal.** `CreateTenantRequest` gains optional `studioCredentialHash` behind the new protocol feature `studio-principal`; the Runtime stores it as application principal `studio`, and idempotent create compares it too. `@nylorun/admin` exports `deriveStudioToken(adminKey, tenantId)` (HMAC-SHA256 over `nylorun/studio/v1`, NUL, Tenant id) and `createTenant` sends the hash of that key, so Studio can reach any Tenant's API with a key derived from the admin key. Clients require the new feature, so upgrade the Runtime with them.
8
+
9
+ ### Patch Changes
10
+
11
+ - Pin core to the tested release.
12
+ - Updated dependencies [bf1c2da]
13
+ - Updated dependencies [ba1b239]
14
+ - Updated dependencies [bf1c2da]
15
+ - Updated dependencies [bf1c2da]
16
+ - Updated dependencies [bf1c2da]
17
+ - @nylorun/core@0.6.0-beta
18
+
3
19
  ## 0.2.0-beta
4
20
 
5
21
  ### Minor Changes
package/README.md CHANGED
@@ -23,6 +23,11 @@ idempotency key locally; only the key's hash is sent. On network error or
23
23
  `5xx` it retries up to three times with identical values. Persist the returned
24
24
  `applicationKey` — the Host never sees it in cleartext again.
25
25
 
26
+ `createTenant` also registers the Tenant's Studio principal (`studio`) by
27
+ sending the hash of `deriveStudioToken(adminKey, tenantId)`. Studio derives the
28
+ same key from the admin key to call that Tenant's API, so whoever holds the
29
+ admin key can reach every Tenant created this way.
30
+
26
31
  Local Host resolution reads `host.json` and `host-credentials.json` under
27
32
  `NYLORUN_HOME` / `~/.nylorun` (or `options.home`). On POSIX the credentials
28
33
  file must be owned by the user and not group- or world-readable. First use
@@ -33,5 +38,4 @@ Errors are `AdminError` with a registry `code` from `@nylorun/core`
33
38
  `compareVersions`.
34
39
 
35
40
  Developer applications do **not** depend on this package — only managing
36
- clients (CLI, desktop Runtime panel, CI) do. See
37
- [building a desktop client](../docs/building-a-desktop-client.md).
41
+ clients (CLI, desktop Runtime panel, CI) do.
package/dist/client.js CHANGED
@@ -4,6 +4,7 @@ import { homedir } from "node:os";
4
4
  import { join, resolve } from "node:path";
5
5
  import { AdminStatusSchema, AdminTenantSchema, AdminTenantStatusSchema, RejectedResponseSchema, TenantEnvelopeSchema, } from "@nylorun/core/contracts";
6
6
  import { PROTOCOL_FEATURES, PROTOCOL_HEADER, PROTOCOL_VERSION, checkCompatibility, newPrincipalId, newTenantId, } from "@nylorun/core/compatibility";
7
+ import { deriveStudioToken } from "./derived-credentials.js";
7
8
  import { AdminError } from "./errors.js";
8
9
  function env(name) {
9
10
  const value = process.env[name];
@@ -288,12 +289,14 @@ export class AdminClient {
288
289
  }
289
290
  async createTenant(options) {
290
291
  const applicationKey = mintApplicationKey();
292
+ const tenantId = newTenantId();
291
293
  const body = {
292
- tenantId: newTenantId(),
294
+ tenantId,
293
295
  name: options.name,
294
296
  principalId: newPrincipalId(),
295
297
  credentialHash: hashCredential(applicationKey),
296
298
  idempotencyKey: randomUUID(),
299
+ studioCredentialHash: hashCredential(deriveStudioToken(this.key, tenantId)),
297
300
  };
298
301
  let lastError;
299
302
  for (let attempt = 0; attempt < 3; attempt += 1) {
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Deterministic Studio key for one Tenant, derived from the admin key.
3
+ * Same admin key and Tenant always produce the same key. Studio derives it in
4
+ * memory; the Tenant stores only its hash, as principal `studio`.
5
+ */
6
+ export declare function deriveStudioToken(adminKey: string, tenantId: string): string;
@@ -0,0 +1,16 @@
1
+ import { createHmac } from "node:crypto";
2
+ /**
3
+ * Deterministic Studio key for one Tenant, derived from the admin key.
4
+ * Same admin key and Tenant always produce the same key. Studio derives it in
5
+ * memory; the Tenant stores only its hash, as principal `studio`.
6
+ */
7
+ export function deriveStudioToken(adminKey, tenantId) {
8
+ const message = Buffer.concat([
9
+ Buffer.from("nylorun/studio/v1", "utf8"),
10
+ Buffer.from([0]),
11
+ Buffer.from(tenantId, "utf8"),
12
+ ]);
13
+ return createHmac("sha256", Buffer.from(adminKey, "utf8"))
14
+ .update(message)
15
+ .digest("hex");
16
+ }
package/dist/index.d.ts CHANGED
@@ -1,9 +1,11 @@
1
1
  import type { AdminStatus, AdminTenant, AdminTenantStatus, TenantEnvelope } from "@nylorun/core/contracts";
2
2
  import { ERROR_CODES, PROTOCOL_FEATURES, compareVersions, type ErrorCode } from "@nylorun/core/compatibility";
3
+ import { deriveStudioToken } from "./derived-credentials.js";
3
4
  import { AdminError } from "./errors.js";
4
5
  export { ERROR_CODES, PROTOCOL_FEATURES, compareVersions };
5
6
  export type { ErrorCode };
6
7
  export { AdminError };
8
+ export { deriveStudioToken };
7
9
  export interface Admin {
8
10
  readonly url: string;
9
11
  readonly source: "options" | "environment" | "local-host";
package/dist/index.js CHANGED
@@ -1,8 +1,10 @@
1
1
  import { ERROR_CODES, PROTOCOL_FEATURES, compareVersions, } from "@nylorun/core/compatibility";
2
2
  import { AdminClient, resolveAdminConnection } from "./client.js";
3
+ import { deriveStudioToken } from "./derived-credentials.js";
3
4
  import { AdminError } from "./errors.js";
4
5
  export { ERROR_CODES, PROTOCOL_FEATURES, compareVersions };
5
6
  export { AdminError };
7
+ export { deriveStudioToken };
6
8
  export function createAdmin(options) {
7
9
  return new AdminClient(resolveAdminConnection(options));
8
10
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nylorun/admin",
3
- "version": "0.2.0-beta",
3
+ "version": "0.3.0-beta",
4
4
  "description": "Nylorun Admin API client for Tenants and Host status",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -24,7 +24,7 @@
24
24
  "clean": "node -e \"import('node:fs').then(({rmSync})=>rmSync('dist',{recursive:true,force:true}))\""
25
25
  },
26
26
  "dependencies": {
27
- "@nylorun/core": "0.5.0-beta"
27
+ "@nylorun/core": "0.6.0-beta"
28
28
  },
29
29
  "peerDependencies": {
30
30
  "zod": "^4.6.5"