@things-factory/figure-library 10.1.296 → 10.1.297

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.
@@ -22,5 +22,5 @@ export * from './source/figure-source-resolver';
22
22
  export * from './source/capability-push';
23
23
  export declare const entities: (typeof FigureLibraryRelease | typeof FigureTypeMapEntry)[];
24
24
  export declare const schema: {
25
- resolverClasses: (typeof FigureSourceResolver | typeof FigureLibraryResolver)[];
25
+ resolverClasses: (typeof FigureLibraryResolver | typeof FigureSourceResolver)[];
26
26
  };
@@ -27,6 +27,8 @@ function declareFigureCapabilityModule(declaration) {
27
27
  /** The app's declared module, or none. */
28
28
  const declaredFigureCapabilityModule = () => declared;
29
29
  exports.declaredFigureCapabilityModule = declaredFigureCapabilityModule;
30
+ /** The key the link uses cannot register capabilities: a key issued before every key could (ADR-0172 decision 14). */
31
+ const pushForbidden = source => new shell_1.Refusal('figure-capability-push-forbidden', { host: new URL(source.url).host, domain: source.domain }, "The token has no right to register capabilities. Issue a new key in the board server install keys of {domain} on {host}, and enter it as the token.");
30
32
  const PUSH = `mutation ($source: String!, $choices: Object) { pushFigureCapabilityModule(source: $source, choices: $choices) { provider version sha256 } }`;
31
33
  async function attribute(manager, domain, name) {
32
34
  return manager.getRepository(shell_1.EnvVar).findOne({ where: { domain: { id: domain.id }, name } });
@@ -69,7 +71,7 @@ async function pushCapabilityModule(manager, domain, source, options = {}) {
69
71
  const failed = (await attribute(manager, domain, exports.PUSH_ERROR))?.value;
70
72
  if (!options.force && last === hash && lastChoices === choicesHash && !failed)
71
73
  return capabilityPushState(manager, domain);
72
- await (0, source_client_1.sourceQuery)(source, PUSH, { source: bytes.toString('utf8'), ...(choices ? { choices } : {}) }, options.doFetch);
74
+ await (0, source_client_1.sourceQuery)(source, PUSH, { source: bytes.toString('utf8'), ...(choices ? { choices } : {}) }, options.doFetch, pushForbidden);
73
75
  await write(manager, domain, exports.PUSHED_HASH, hash);
74
76
  await write(manager, domain, exports.PUSHED_CHOICES_HASH, choicesHash);
75
77
  await write(manager, domain, exports.PUSH_ERROR, null);
@@ -1,3 +1,4 @@
1
+ import { Refusal } from '@things-factory/shell';
1
2
  import type { FigureSource } from './source-setting-rules';
2
3
  /**
3
4
  * The calls a board server makes to the figure server it installs from (ADR-0114 decisions 22 · 25 · 26). Only an
@@ -14,8 +15,10 @@ export interface SourceFetch {
14
15
  }
15
16
  /** The domain-scoped address of a REST door on the figure server: {url}/domain/{domain}/{path}. */
16
17
  export declare const sourceRestUrl: (source: FigureSource, path: string) => string;
17
- /** One GraphQL query on the figure server, as the token's domain. */
18
- export declare function sourceQuery<T>(source: FigureSource, query: string, variables: Record<string, unknown>, doFetch?: SourceFetch): Promise<T>;
18
+ /** What a refusal of the token's rights means for a call: by default, reading the domain's released figures. */
19
+ export type SourceForbidden = (source: FigureSource) => Refusal;
20
+ /** One GraphQL query on the figure server, as the token's domain. `forbidden` says what a refusal of the token's rights means for it. */
21
+ export declare function sourceQuery<T>(source: FigureSource, query: string, variables: Record<string, unknown>, doFetch?: SourceFetch, forbidden?: SourceForbidden): Promise<T>;
19
22
  /** A package of these releases from the figure server's `/figure-package` door, as bytes. */
20
23
  export declare function sourcePackage(source: FigureSource, refs: readonly string[], max: number, doFetch?: SourceFetch): Promise<Buffer>;
21
24
  /** The picture of a figure's latest release, as the figure server sends it; null when it has none. */
@@ -22,7 +22,8 @@ function headersOf(source, extra = {}) {
22
22
  /** The domain-scoped address of a REST door on the figure server: {url}/domain/{domain}/{path}. */
23
23
  const sourceRestUrl = (source, path) => `${source.url}/domain/${encodeURIComponent(source.domain)}/${path}`;
24
24
  exports.sourceRestUrl = sourceRestUrl;
25
- async function call(source, url, init, doFetch) {
25
+ const readForbidden = source => new shell_1.Refusal('figure-source-forbidden', { host: host(source), domain: source.domain }, 'The token has no right to read released figures of {domain} on {host}.');
26
+ async function call(source, url, init, doFetch, forbidden = readForbidden) {
26
27
  let response;
27
28
  try {
28
29
  response = await doFetch(url, { ...init, redirect: 'manual', signal: AbortSignal.timeout(exports.SOURCE_TIMEOUT_MS) });
@@ -33,7 +34,7 @@ async function call(source, url, init, doFetch) {
33
34
  if (response.status === 401)
34
35
  throw new shell_1.Refusal('figure-source-unauthorized', { host: host(source) }, 'The figure server {host} did not accept the token.');
35
36
  if (response.status === 403)
36
- throw new shell_1.Refusal('figure-source-forbidden', { host: host(source), domain: source.domain }, 'The token has no right to read released figures of {domain} on {host}.');
37
+ throw forbidden(source);
37
38
  if (response.status >= 300 && response.status < 400)
38
39
  throw new shell_1.Refusal('figure-source-unreachable', { host: host(source) }, 'Cannot connect to the figure server {host}.');
39
40
  return response;
@@ -71,9 +72,9 @@ async function refusalOf(source, response) {
71
72
  catch { }
72
73
  return new shell_1.Refusal('figure-source-failed', { host: host(source), status: response.status }, 'The figure server {host} answered {status}.');
73
74
  }
74
- /** One GraphQL query on the figure server, as the token's domain. */
75
- async function sourceQuery(source, query, variables, doFetch = fetch) {
76
- const response = await call(source, `${source.url}/graphql`, { method: 'POST', headers: headersOf(source, { 'content-type': 'application/json' }), body: JSON.stringify({ query, variables }) }, doFetch);
75
+ /** One GraphQL query on the figure server, as the token's domain. `forbidden` says what a refusal of the token's rights means for it. */
76
+ async function sourceQuery(source, query, variables, doFetch = fetch, forbidden = readForbidden) {
77
+ const response = await call(source, `${source.url}/graphql`, { method: 'POST', headers: headersOf(source, { 'content-type': 'application/json' }), body: JSON.stringify({ query, variables }) }, doFetch, forbidden);
77
78
  if (!response.ok)
78
79
  throw await refusalOf(source, response);
79
80
  const body = (await response.json());
@@ -81,7 +82,7 @@ async function sourceQuery(source, query, variables, doFetch = fetch) {
81
82
  const [error] = body.errors;
82
83
  const message = error.message ?? '';
83
84
  if (/unauthori[sz]ed|permission|privilege/i.test(message) || error.extensions?.code === 'FORBIDDEN')
84
- throw new shell_1.Refusal('figure-source-forbidden', { host: host(source), domain: source.domain }, 'The token has no right to read released figures of {domain} on {host}.');
85
+ throw forbidden(source);
85
86
  throw new shell_1.Refusal('figure-source-failed-message', { host: host(source), message }, 'The figure server {host} refused: {message}');
86
87
  }
87
88
  return body.data;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/figure-library",
3
- "version": "10.1.296",
3
+ "version": "10.1.297",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "dist-client/index.js",
6
6
  "files": [
@@ -55,13 +55,13 @@
55
55
  "@operato/slot-layout-editor": "^10.29.87",
56
56
  "@operato/styles": "^10.29.23",
57
57
  "@operato/utils": "^10.0.0",
58
- "@things-factory/attachment-base": "^10.1.296",
59
- "@things-factory/auth-base": "^10.1.296",
60
- "@things-factory/board-service": "^10.1.296",
61
- "@things-factory/env": "^10.1.296",
58
+ "@things-factory/attachment-base": "^10.1.297",
59
+ "@things-factory/auth-base": "^10.1.297",
60
+ "@things-factory/board-service": "^10.1.297",
61
+ "@things-factory/env": "^10.1.297",
62
62
  "@things-factory/figure-viewer": "^10.1.291",
63
- "@things-factory/setting-base": "^10.1.296",
64
- "@things-factory/shell": "^10.1.296",
63
+ "@things-factory/setting-base": "^10.1.297",
64
+ "@things-factory/shell": "^10.1.297",
65
65
  "graphql-scalars": "^1.22.4",
66
66
  "graphql-tag": "^2.12.6",
67
67
  "graphql-upload": "^15.0.2",
@@ -69,5 +69,5 @@
69
69
  "koa-router": "^7.4.0",
70
70
  "lit": "^3.1.2"
71
71
  },
72
- "gitHead": "0cd4b6207e4dfc557157f86630d82aed423b1dde"
72
+ "gitHead": "656ec78e5adf500b3b636eb9790cfe22f2a49ba9"
73
73
  }
@@ -176,6 +176,7 @@
176
176
  "error.figure-source-unreachable": "Cannot connect to the figure server {host}.",
177
177
  "error.figure-source-unauthorized": "The figure server {host} did not accept the token. Check the access token.",
178
178
  "error.figure-source-forbidden": "The token has no right to read released figures of {domain} on {host}.",
179
+ "error.figure-capability-push-forbidden": "The token has no right to register capabilities. Issue a new key in the board server install keys of {domain} on {host}, and enter it as the token.",
179
180
  "error.figure-source-failed": "The figure server {host} answered {status}.",
180
181
  "error.figure-source-failed-message": "The figure server {host} refused: {message}",
181
182
  "error.figure-source-url-invalid": "The address is a web address that starts with http:// or https://.",
@@ -176,6 +176,7 @@
176
176
  "error.figure-source-unreachable": "No se puede conectar con el servidor de figuras {host}.",
177
177
  "error.figure-source-unauthorized": "El servidor de figuras {host} no aceptó el token. Revise el token de acceso.",
178
178
  "error.figure-source-forbidden": "El token no tiene permiso para leer las figuras publicadas de {domain} en {host}.",
179
+ "error.figure-capability-push-forbidden": "El token no tiene permiso para registrar capacidades. Emita una clave nueva en las claves de instalación del servidor de tableros de {domain} en {host} e introdúzcala como token.",
179
180
  "error.figure-source-failed": "El servidor de figuras {host} respondió {status}.",
180
181
  "error.figure-source-failed-message": "El servidor de figuras {host} rechazó la solicitud: {message}",
181
182
  "error.figure-source-url-invalid": "La dirección debe empezar por http:// o https://.",
@@ -176,6 +176,7 @@
176
176
  "error.figure-source-unreachable": "Figure サーバー {host} に接続できません。",
177
177
  "error.figure-source-unauthorized": "Figure サーバー {host} でトークンを認証できませんでした。アクセストークンを確認してください。",
178
178
  "error.figure-source-forbidden": "アクセストークンに {host} の {domain} の発行済み Figure を参照する権限がありません。",
179
+ "error.figure-capability-push-forbidden": "アクセストークンに能力を登録する権限がありません。{host} の {domain} の「ボードサーバー設置キー」でキーを新しく発行し、アクセストークンとして入力してください。",
179
180
  "error.figure-source-failed": "Figure サーバー {host} でエラー({status})が発生しました。",
180
181
  "error.figure-source-failed-message": "Figure サーバー {host} が要求を拒否しました: {message}",
181
182
  "error.figure-source-url-invalid": "サーバーアドレスは http:// または https:// で始まる Web アドレスである必要があります。",
@@ -176,6 +176,7 @@
176
176
  "error.figure-source-unreachable": "피규어 서버 {host}에 연결할 수 없습니다.",
177
177
  "error.figure-source-unauthorized": "피규어 서버 {host}에서 토큰을 인증하지 못했습니다. 접속 토큰을 확인하세요.",
178
178
  "error.figure-source-forbidden": "접속 토큰에 {host}의 {domain} 사업장 발행 피규어를 조회할 권한이 없습니다.",
179
+ "error.figure-capability-push-forbidden": "접속 토큰에 능력 등록 권한이 없습니다. {host}의 {domain} 사업장 「보드 서버 설치 키」에서 키를 새로 발급해 접속 토큰으로 입력하세요.",
179
180
  "error.figure-source-failed": "피규어 서버 {host}에서 오류({status})가 발생했습니다.",
180
181
  "error.figure-source-failed-message": "피규어 서버 {host}에서 요청을 거절했습니다: {message}",
181
182
  "error.figure-source-url-invalid": "서버 주소는 http:// 또는 https://로 시작하는 웹 주소여야 합니다.",
@@ -176,6 +176,7 @@
176
176
  "error.figure-source-unreachable": "Tidak dapat menyambung ke pelayan figure {host}.",
177
177
  "error.figure-source-unauthorized": "Pelayan figure {host} tidak menerima token. Semak token akses.",
178
178
  "error.figure-source-forbidden": "Token tiada hak untuk membaca figure terbitan {domain} pada {host}.",
179
+ "error.figure-capability-push-forbidden": "Token tiada hak untuk mendaftar keupayaan. Keluarkan kunci baharu dalam kunci pemasangan pelayan papan {domain} pada {host}, dan masukkannya sebagai token.",
179
180
  "error.figure-source-failed": "Pelayan figure {host} menjawab {status}.",
180
181
  "error.figure-source-failed-message": "Pelayan figure {host} menolak: {message}",
181
182
  "error.figure-source-url-invalid": "Alamat mesti bermula dengan http:// atau https://.",
@@ -176,6 +176,7 @@
176
176
  "error.figure-source-unreachable": "无法连接到图形服务器 {host}。",
177
177
  "error.figure-source-unauthorized": "图形服务器 {host} 未能验证令牌。请检查访问令牌。",
178
178
  "error.figure-source-forbidden": "访问令牌无权读取 {host} 上 {domain} 的已发布图形。",
179
+ "error.figure-capability-push-forbidden": "访问令牌没有注册能力的权限。请在 {host} 的 {domain} 的“看板服务器安装密钥”中重新签发密钥,并将其作为访问令牌输入。",
179
180
  "error.figure-source-failed": "图形服务器 {host} 返回错误({status})。",
180
181
  "error.figure-source-failed-message": "图形服务器 {host} 拒绝了请求:{message}",
181
182
  "error.figure-source-url-invalid": "服务器地址必须是以 http:// 或 https:// 开头的网址。",