@things-factory/figure-service 10.1.281 → 10.1.282

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.
@@ -30,4 +30,6 @@ export declare const figureThumbnailRouter: any;
30
30
  export declare function sendFigureThumbnail(context: any, next: () => Promise<any>, id: string, domain: {
31
31
  id: string;
32
32
  parentId?: string;
33
- }, files?: ThumbnailFiles): Promise<void>;
33
+ }, files?: ThumbnailFiles, { released }?: {
34
+ released?: boolean;
35
+ }): Promise<void>;
@@ -55,6 +55,19 @@ exports.figureThumbnailRouter.get('/figure-thumbnail/:id', async (context, next)
55
55
  }
56
56
  await sendFigureThumbnail(context, next, context.params.id, domain);
57
57
  });
58
+ /**
59
+ * The picture of a figure's latest release, for a server choosing what to install (ADR-0114 decision 25): behind the
60
+ * same door as `/figure-package` and `figureReleaseCatalog` (`figure-published`), never the draft's picture.
61
+ */
62
+ exports.figureThumbnailRouter.get('/figure-release-thumbnail/:id', async (context, next) => {
63
+ const { domain, user, unsafeIP, prohibitedPrivileges } = context.state;
64
+ const allowed = await (0, auth_base_1.checkPermission)({ category: 'figure-published', privilege: 'query', owner: true }, user, domain, unsafeIP, prohibitedPrivileges);
65
+ if (!allowed) {
66
+ context.status = 403;
67
+ return;
68
+ }
69
+ await sendFigureThumbnail(context, next, context.params.id, domain, undefined, { released: true });
70
+ });
58
71
  /** A public figure's picture as its latest release keeps it, on the figure's domain. */
59
72
  async function releasedPictureOf(row) {
60
73
  const release = await (0, shell_1.getRepository)(figure_history_js_1.FigureHistory).findOne({
@@ -68,7 +81,7 @@ async function releasedPictureOf(row) {
68
81
  * The picture of a figure the caller may read, by its hash (ADR-0104 decision 6). Exported for tests, which give
69
82
  * their own `files`.
70
83
  */
71
- async function sendFigureThumbnail(context, next, id, domain, files = (0, figure_thumbnail_store_js_1.thumbnailFiles)()) {
84
+ async function sendFigureThumbnail(context, next, id, domain, files = (0, figure_thumbnail_store_js_1.thumbnailFiles)(), { released = false } = {}) {
72
85
  /*
73
86
  읽기는 부모 도메인까지 본다 — `figure` 질의와 같은 범위다. 물려받은 형상을 목록에는 보여 주고
74
87
  그림만 404 를 내면, 화면은 「그림이 아직 없다」고 거짓말하게 된다.
@@ -79,7 +92,7 @@ async function sendFigureThumbnail(context, next, id, domain, files = (0, figure
79
92
  Another domain is shown the picture of the latest release, as its list is (2026-11-03 audit 1): the row's picture
80
93
  may be of a draft not released.
81
94
  */
82
- const found = row && (0, figure_public_js_1.foreignPublic)(domain, row) ? await releasedPictureOf(row) : row;
95
+ const found = row && (released || (0, figure_public_js_1.foreignPublic)(domain, row)) ? await releasedPictureOf(row) : row;
83
96
  if (!found?.thumbnailHash) {
84
97
  context.status = 404;
85
98
  return;
@@ -3,6 +3,11 @@ type Reader = {
3
3
  id: string;
4
4
  parentId?: string | null;
5
5
  };
6
+ /**
7
+ * The join of a figure row to its releases: `{row}.id` (uuid) against `{originalId}` (text). Postgres compares the two
8
+ * only with a cast ("operator does not exist: uuid = character varying"); sqlite stores both as text and needs none.
9
+ */
10
+ export declare function figureRowOfRelease(row: string, originalId: string): string;
6
11
  /** The domains a reader reads as its own: itself and its parent. */
7
12
  export declare const ownScope: (domain: Reader) => import("typeorm").FindOperator<any>;
8
13
  /** A figure the reader may read the releases of: its own or its parent's, or any domain's public one. */
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ownScope = void 0;
4
+ exports.figureRowOfRelease = figureRowOfRelease;
4
5
  exports.readableFigure = readableFigure;
5
6
  exports.foreignPublic = foreignPublic;
6
7
  exports.publicFigureOfName = publicFigureOfName;
@@ -9,6 +10,14 @@ const typeorm_1 = require("typeorm");
9
10
  const shell_1 = require("@things-factory/shell");
10
11
  const figure_js_1 = require("./figure.js");
11
12
  const figure_history_js_1 = require("./figure-history.js");
13
+ /**
14
+ * The join of a figure row to its releases: `{row}.id` (uuid) against `{originalId}` (text). Postgres compares the two
15
+ * only with a cast ("operator does not exist: uuid = character varying"); sqlite stores both as text and needs none.
16
+ */
17
+ function figureRowOfRelease(row, originalId) {
18
+ const type = (0, shell_1.getRepository)(figure_js_1.Figure).manager.connection.options.type;
19
+ return type === 'postgres' ? `CAST(${row}.id AS text) = ${originalId}` : `${row}.id = ${originalId}`;
20
+ }
12
21
  /** The domains a reader reads as its own: itself and its parent. */
13
22
  const ownScope = (domain) => (0, typeorm_1.In)([domain.id, domain.parentId].filter(Boolean));
14
23
  exports.ownScope = ownScope;
@@ -3,6 +3,7 @@ import { Figure } from './figure.js';
3
3
  import { FigureHistory } from './figure-history.js';
4
4
  import { FigureInspection, FigureList, FigureProposalOutcome } from './figure-type.js';
5
5
  import { FigureReplacedDraft } from './figure-replaced-draft.js';
6
+ import { FigureReleaseCatalog } from './figure-release-catalog.js';
6
7
  export declare class FigureQuery {
7
8
  figure(id: string, context: ResolverContext): Promise<Figure>;
8
9
  figures(params: ListParam, context: ResolverContext): Promise<FigureList>;
@@ -18,6 +19,11 @@ export declare class FigureQuery {
18
19
  * figure as a whole is shown: that it is public and whether it is retired. Tags are not recorded with a release, so a
19
20
  * public figure shows none.
20
21
  */
22
+ /**
23
+ * The releases another server may install (ADR-0114 decision 24): each readable figure as its latest release. Behind
24
+ * the same door as `/figure-package` (`figure-published`), so a board server's token needs no right to read drafts.
25
+ */
26
+ figureReleaseCatalog(params: ListParam, context: ResolverContext): Promise<FigureReleaseCatalog>;
21
27
  publicFigures(params: ListParam, context: ResolverContext): Promise<FigureList>;
22
28
  /**
23
29
  * 등록된 타입 이름 목록.
@@ -17,6 +17,7 @@ const figure_proposal_js_1 = require("./figure-proposal.js");
17
17
  const figure_mesh_store_js_1 = require("./figure-mesh-store.js");
18
18
  const figure_public_js_1 = require("./figure-public.js");
19
19
  const figure_categories_js_1 = require("./figure-categories.js");
20
+ const figure_release_catalog_js_1 = require("./figure-release-catalog.js");
20
21
  /** What a figure list finds figures by - tags too, see `figures` - and its state counts alike. */
21
22
  const FIGURE_SEARCHABLES = ['type', 'name', 'description', 'category', 'tags'];
22
23
  /** A release records no tags (`FigureHistory`). */
@@ -70,6 +71,13 @@ let FigureQuery = class FigureQuery {
70
71
  * figure as a whole is shown: that it is public and whether it is retired. Tags are not recorded with a release, so a
71
72
  * public figure shows none.
72
73
  */
74
+ /**
75
+ * The releases another server may install (ADR-0114 decision 24): each readable figure as its latest release. Behind
76
+ * the same door as `/figure-package` (`figure-published`), so a board server's token needs no right to read drafts.
77
+ */
78
+ async figureReleaseCatalog(params, context) {
79
+ return (0, figure_release_catalog_js_1.figureReleaseCatalogOf)(context.state.domain, params);
80
+ }
73
81
  async publicFigures(params, context) {
74
82
  const { domain } = context.state;
75
83
  const mine = [domain.id, domain.parentId].filter(Boolean);
@@ -79,7 +87,7 @@ let FigureQuery = class FigureQuery {
79
87
  alias: 'figure',
80
88
  searchables: PUBLIC_FIGURE_SEARCHABLES
81
89
  })
82
- .innerJoinAndMapOne('figure.row', figure_js_1.Figure, 'row', 'row.id = figure.originalId AND row.public = :public AND row.deletedAt IS NULL', { public: true })
90
+ .innerJoinAndMapOne('figure.row', figure_js_1.Figure, 'row', `${(0, figure_public_js_1.figureRowOfRelease)('row', 'figure.originalId')} AND row.public = :public AND row.deletedAt IS NULL`, { public: true })
83
91
  .leftJoinAndSelect('figure.domain', 'owner')
84
92
  .leftJoinAndSelect('figure.updater', 'releaser')
85
93
  .andWhere('owner.id NOT IN (:...mine)', { mine })
@@ -377,6 +385,15 @@ tslib_1.__decorate([
377
385
  tslib_1.__metadata("design:paramtypes", [shell_1.ListParam, Object]),
378
386
  tslib_1.__metadata("design:returntype", Promise)
379
387
  ], FigureQuery.prototype, "figureStateCounts", null);
388
+ tslib_1.__decorate([
389
+ (0, type_graphql_1.Directive)('@privilege(category: "figure-published", privilege: "query", domainOwnerGranted: true)'),
390
+ (0, type_graphql_1.Query)(returns => figure_release_catalog_js_1.FigureReleaseCatalog, { description: 'The figures this domain may install elsewhere - its own, its parent\'s and public ones - each as its latest release.' }),
391
+ tslib_1.__param(0, (0, type_graphql_1.Args)()),
392
+ tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
393
+ tslib_1.__metadata("design:type", Function),
394
+ tslib_1.__metadata("design:paramtypes", [shell_1.ListParam, Object]),
395
+ tslib_1.__metadata("design:returntype", Promise)
396
+ ], FigureQuery.prototype, "figureReleaseCatalog", null);
380
397
  tslib_1.__decorate([
381
398
  (0, type_graphql_1.Directive)('@privilege(category: "figure", privilege: "query", domainOwnerGranted: true)'),
382
399
  (0, type_graphql_1.Query)(returns => figure_type_js_1.FigureList, { description: "Other domains' public figures, each as its latest release. Read only: their releases, never their drafts." }),
@@ -0,0 +1,36 @@
1
+ import { ListParam } from '@things-factory/shell';
2
+ /**
3
+ * One figure as another server installs it (ADR-0114 decision 24): its latest release, never its draft. A board server
4
+ * lists these to choose what to install, then asks `/figure-package` for the chosen refs.
5
+ */
6
+ export declare class FigureReleaseCatalogItem {
7
+ figureId: string;
8
+ fullName: string;
9
+ ref: string;
10
+ namespace: string;
11
+ type: string;
12
+ version: number;
13
+ name?: string;
14
+ names?: Record<string, string>;
15
+ description?: string;
16
+ category?: string;
17
+ deprecated: boolean;
18
+ supersededBy?: string;
19
+ public: boolean;
20
+ assetFormat?: string;
21
+ kernelVersion?: string;
22
+ releasedAt?: Date;
23
+ thumbnailHash?: string;
24
+ }
25
+ export declare class FigureReleaseCatalog {
26
+ items: FigureReleaseCatalogItem[];
27
+ total: number;
28
+ }
29
+ /**
30
+ * The figures a domain may read the releases of - its own, its parent's and any domain's public one, the scope of
31
+ * `figureBlueprint` and `/figure-package` - each as its latest release. Figures never released are not listed.
32
+ */
33
+ export declare function figureReleaseCatalogOf(domain: {
34
+ id: string;
35
+ parentId?: string | null;
36
+ }, params: ListParam): Promise<FigureReleaseCatalog>;
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FigureReleaseCatalog = exports.FigureReleaseCatalogItem = void 0;
4
+ exports.figureReleaseCatalogOf = figureReleaseCatalogOf;
5
+ const tslib_1 = require("tslib");
6
+ const type_graphql_1 = require("type-graphql");
7
+ const graphql_scalars_1 = require("graphql-scalars");
8
+ const shell_1 = require("@things-factory/shell");
9
+ const figure_js_1 = require("./figure.js");
10
+ const figure_history_js_1 = require("./figure-history.js");
11
+ const figure_public_js_1 = require("./figure-public.js");
12
+ /**
13
+ * One figure as another server installs it (ADR-0114 decision 24): its latest release, never its draft. A board server
14
+ * lists these to choose what to install, then asks `/figure-package` for the chosen refs.
15
+ */
16
+ let FigureReleaseCatalogItem = class FigureReleaseCatalogItem {
17
+ };
18
+ exports.FigureReleaseCatalogItem = FigureReleaseCatalogItem;
19
+ tslib_1.__decorate([
20
+ (0, type_graphql_1.Field)({ description: 'The figure id - the picture of its latest release is /figure-release-thumbnail/{figureId}.' }),
21
+ tslib_1.__metadata("design:type", String)
22
+ ], FigureReleaseCatalogItem.prototype, "figureId", void 0);
23
+ tslib_1.__decorate([
24
+ (0, type_graphql_1.Field)({ description: 'The full name {namespace}/{type}.' }),
25
+ tslib_1.__metadata("design:type", String)
26
+ ], FigureReleaseCatalogItem.prototype, "fullName", void 0);
27
+ tslib_1.__decorate([
28
+ (0, type_graphql_1.Field)({ description: 'The latest release, {namespace}/{type}@{version}.' }),
29
+ tslib_1.__metadata("design:type", String)
30
+ ], FigureReleaseCatalogItem.prototype, "ref", void 0);
31
+ tslib_1.__decorate([
32
+ (0, type_graphql_1.Field)({ description: 'The namespace of the figure.' }),
33
+ tslib_1.__metadata("design:type", String)
34
+ ], FigureReleaseCatalogItem.prototype, "namespace", void 0);
35
+ tslib_1.__decorate([
36
+ (0, type_graphql_1.Field)({ description: 'The type of the figure, unique within its namespace.' }),
37
+ tslib_1.__metadata("design:type", String)
38
+ ], FigureReleaseCatalogItem.prototype, "type", void 0);
39
+ tslib_1.__decorate([
40
+ (0, type_graphql_1.Field)(type => type_graphql_1.Int, { description: 'The version of the latest release.' }),
41
+ tslib_1.__metadata("design:type", Number)
42
+ ], FigureReleaseCatalogItem.prototype, "version", void 0);
43
+ tslib_1.__decorate([
44
+ (0, type_graphql_1.Field)({ nullable: true, description: 'The display name, as released.' }),
45
+ tslib_1.__metadata("design:type", String)
46
+ ], FigureReleaseCatalogItem.prototype, "name", void 0);
47
+ tslib_1.__decorate([
48
+ (0, type_graphql_1.Field)(type => graphql_scalars_1.GraphQLJSON, { nullable: true, description: 'The name in each language, as released.' }),
49
+ tslib_1.__metadata("design:type", Object)
50
+ ], FigureReleaseCatalogItem.prototype, "names", void 0);
51
+ tslib_1.__decorate([
52
+ (0, type_graphql_1.Field)({ nullable: true, description: 'The description, as released.' }),
53
+ tslib_1.__metadata("design:type", String)
54
+ ], FigureReleaseCatalogItem.prototype, "description", void 0);
55
+ tslib_1.__decorate([
56
+ (0, type_graphql_1.Field)({ nullable: true, description: 'The category, as released.' }),
57
+ tslib_1.__metadata("design:type", String)
58
+ ], FigureReleaseCatalogItem.prototype, "category", void 0);
59
+ tslib_1.__decorate([
60
+ (0, type_graphql_1.Field)({ description: 'Its author advises not to use it (supersededBy names what to use instead).' }),
61
+ tslib_1.__metadata("design:type", Boolean)
62
+ ], FigureReleaseCatalogItem.prototype, "deprecated", void 0);
63
+ tslib_1.__decorate([
64
+ (0, type_graphql_1.Field)({ nullable: true, description: 'The full name to use instead, when deprecated.' }),
65
+ tslib_1.__metadata("design:type", String)
66
+ ], FigureReleaseCatalogItem.prototype, "supersededBy", void 0);
67
+ tslib_1.__decorate([
68
+ (0, type_graphql_1.Field)({ description: 'Another domain made it public; the reader does not own it.' }),
69
+ tslib_1.__metadata("design:type", Boolean)
70
+ ], FigureReleaseCatalogItem.prototype, "public", void 0);
71
+ tslib_1.__decorate([
72
+ (0, type_graphql_1.Field)({ nullable: true, description: 'The definition format of the release.' }),
73
+ tslib_1.__metadata("design:type", String)
74
+ ], FigureReleaseCatalogItem.prototype, "assetFormat", void 0);
75
+ tslib_1.__decorate([
76
+ (0, type_graphql_1.Field)({ nullable: true, description: 'The figure kernel version that made the release.' }),
77
+ tslib_1.__metadata("design:type", String)
78
+ ], FigureReleaseCatalogItem.prototype, "kernelVersion", void 0);
79
+ tslib_1.__decorate([
80
+ (0, type_graphql_1.Field)({ nullable: true, description: 'When the latest release was made.' }),
81
+ tslib_1.__metadata("design:type", Date)
82
+ ], FigureReleaseCatalogItem.prototype, "releasedAt", void 0);
83
+ tslib_1.__decorate([
84
+ (0, type_graphql_1.Field)({ nullable: true, description: 'The hash of the release picture - a cache key; none when it has no picture.' }),
85
+ tslib_1.__metadata("design:type", String)
86
+ ], FigureReleaseCatalogItem.prototype, "thumbnailHash", void 0);
87
+ exports.FigureReleaseCatalogItem = FigureReleaseCatalogItem = tslib_1.__decorate([
88
+ (0, type_graphql_1.ObjectType)({ description: 'A figure as its latest release - what a board server chooses from before it installs.' })
89
+ ], FigureReleaseCatalogItem);
90
+ let FigureReleaseCatalog = class FigureReleaseCatalog {
91
+ };
92
+ exports.FigureReleaseCatalog = FigureReleaseCatalog;
93
+ tslib_1.__decorate([
94
+ (0, type_graphql_1.Field)(type => [FigureReleaseCatalogItem], { description: 'The figures on this page.' }),
95
+ tslib_1.__metadata("design:type", Array)
96
+ ], FigureReleaseCatalog.prototype, "items", void 0);
97
+ tslib_1.__decorate([
98
+ (0, type_graphql_1.Field)(type => type_graphql_1.Int, { description: 'How many figures match the query.' }),
99
+ tslib_1.__metadata("design:type", Number)
100
+ ], FigureReleaseCatalog.prototype, "total", void 0);
101
+ exports.FigureReleaseCatalog = FigureReleaseCatalog = tslib_1.__decorate([
102
+ (0, type_graphql_1.ObjectType)({ description: 'A page of the release catalog.' })
103
+ ], FigureReleaseCatalog);
104
+ /** What the catalog is searched by: the release's own fields (a release records no tags). */
105
+ const CATALOG_SEARCHABLES = ['type', 'namespace', 'name', 'description', 'category'];
106
+ /**
107
+ * The figures a domain may read the releases of - its own, its parent's and any domain's public one, the scope of
108
+ * `figureBlueprint` and `/figure-package` - each as its latest release. Figures never released are not listed.
109
+ */
110
+ async function figureReleaseCatalogOf(domain, params) {
111
+ const mine = [domain.id, domain.parentId].filter(Boolean);
112
+ const queryBuilder = (0, shell_1.getQueryBuilderFromListParams)({
113
+ repository: (0, shell_1.getRepository)(figure_history_js_1.FigureHistory),
114
+ params,
115
+ alias: 'release',
116
+ searchables: CATALOG_SEARCHABLES
117
+ })
118
+ .innerJoinAndMapOne('release.row', figure_js_1.Figure, 'row', `${(0, figure_public_js_1.figureRowOfRelease)('row', 'release.originalId')} AND row.deletedAt IS NULL`)
119
+ .leftJoinAndSelect('row.domain', 'owner')
120
+ .andWhere('(owner.id IN (:...mine) OR row.public = :public)', { mine, public: true })
121
+ .andWhere(query => {
122
+ const latest = query.subQuery().select('MAX(latest.version)').from(figure_history_js_1.FigureHistory, 'latest').where('latest.originalId = release.originalId').getQuery();
123
+ return `release.version = ${latest}`;
124
+ });
125
+ if (!params?.sortings?.length)
126
+ queryBuilder.orderBy('release.namespace', 'ASC').addOrderBy('release.type', 'ASC');
127
+ const [releases, total] = await queryBuilder.getManyAndCount();
128
+ const items = releases.map(({ row, ...release }) => ({
129
+ figureId: release.originalId,
130
+ fullName: `${release.namespace}/${release.type}`,
131
+ ref: `${release.namespace}/${release.type}@${release.version}`,
132
+ namespace: release.namespace,
133
+ type: release.type,
134
+ version: release.version,
135
+ name: release.name ?? undefined,
136
+ names: release.names ?? undefined,
137
+ description: release.description ?? undefined,
138
+ category: release.category ?? undefined,
139
+ deprecated: !!row.deprecated,
140
+ supersededBy: row.supersededBy ?? undefined,
141
+ public: !mine.includes(row.domain.id),
142
+ assetFormat: release.assetFormat ?? undefined,
143
+ kernelVersion: release.kernelVersion ?? undefined,
144
+ releasedAt: release.createdAt,
145
+ thumbnailHash: release.thumbnailHash ?? undefined
146
+ }));
147
+ return { items, total };
148
+ }
149
+ //# sourceMappingURL=figure-release-catalog.js.map
@@ -4,8 +4,10 @@ export * from './figure/figure-format.js';
4
4
  export * from './figure/figure-history.js';
5
5
  export * from './figure-recipe/figure-recipe-type.js';
6
6
  export { recipeTemplates, inLanguage, RECIPE_DIR } from './figure-recipe/figure-recipe-templates.js';
7
+ import { FigureInstallKeyResolver } from './install-key/figure-install-key.js';
8
+ export * from './install-key/figure-install-key.js';
7
9
  export declare const entities: (typeof import("./figure/figure.js").Figure | typeof import("./figure/figure-history.js").FigureHistory | typeof import("./figure/figure-replaced-draft.js").FigureReplacedDraft | typeof import("./figure/figure-proposal-record.js").FigureProposalRecord | typeof import("./figure/figure-namespace-entity.js").FigureNamespace)[];
8
10
  export declare const subscribers: typeof import("./figure/event-subscriber.js").FigureHistoryEntitySubscriber[];
9
11
  export declare const schema: {
10
- resolverClasses: (typeof import("./figure/figure-query.js").FigureQuery | typeof import("./figure/figure-mutation.js").FigureMutation | typeof import("./figure/figure-namespace-resolver.js").FigureNamespaceResolver | typeof import("./figure-recipe/figure-recipe-resolver.js").FigureRecipeTemplateQuery)[];
12
+ resolverClasses: (typeof import("./figure/figure-query.js").FigureQuery | typeof import("./figure/figure-mutation.js").FigureMutation | typeof import("./figure/figure-namespace-resolver.js").FigureNamespaceResolver | typeof import("./figure-recipe/figure-recipe-resolver.js").FigureRecipeTemplateQuery | typeof FigureInstallKeyResolver)[];
11
13
  };
@@ -15,6 +15,8 @@ Object.defineProperty(exports, "RECIPE_DIR", { enumerable: true, get: function (
15
15
  // Entities, resolvers
16
16
  const index_js_1 = require("./figure/index.js");
17
17
  const index_js_2 = require("./figure-recipe/index.js");
18
+ const figure_install_key_js_1 = require("./install-key/figure-install-key.js");
19
+ tslib_1.__exportStar(require("./install-key/figure-install-key.js"), exports);
18
20
  exports.entities = [...index_js_1.entities];
19
21
  /* 버전 스냅샷을 뜨는 구독자. 셸이 이 이름으로 모아 TypeORM 에 등록한다(board-service 와 같다). */
20
22
  exports.subscribers = [...index_js_1.subscribers];
@@ -29,6 +31,6 @@ exports.subscribers = [...index_js_1.subscribers];
29
31
  * board-service, ops-master and font-base all export the shape below.
30
32
  */
31
33
  exports.schema = {
32
- resolverClasses: [...index_js_1.resolvers, ...index_js_2.resolvers]
34
+ resolverClasses: [...index_js_1.resolvers, ...index_js_2.resolvers, figure_install_key_js_1.FigureInstallKeyResolver]
33
35
  };
34
36
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,37 @@
1
+ import { EntityManager } from 'typeorm';
2
+ import { Role, User } from '@things-factory/auth-base';
3
+ /** The appliance model that marks an install key. */
4
+ export declare const INSTALL_KEY_MODEL = "figure-install-key";
5
+ /** The role every install key's user holds, made the first time a key is issued. */
6
+ export declare const INSTALL_KEY_ROLE = "figure-install-reader";
7
+ export declare class FigureInstallKey {
8
+ id: string;
9
+ name: string;
10
+ issuedAt?: Date;
11
+ issuedBy?: string;
12
+ }
13
+ export declare class IssuedFigureInstallKey extends FigureInstallKey {
14
+ token: string;
15
+ }
16
+ /** The role install keys hold: `figure-published` query only. Made once per domain. */
17
+ export declare function installReaderRole(tx: EntityManager, domain: {
18
+ id: string;
19
+ }, user: User): Promise<Role>;
20
+ export declare function installKeysOf(tx: EntityManager, domain: {
21
+ id: string;
22
+ }): Promise<FigureInstallKey[]>;
23
+ /** Issues a new key: an install-key appliance, its user given the reader role, its secret signed. */
24
+ export declare function issueInstallKey(tx: EntityManager, domain: {
25
+ id: string;
26
+ subdomain?: string;
27
+ }, user: User, name: string): Promise<IssuedFigureInstallKey>;
28
+ /** Revokes a key for good: the appliance and its user go, so its token is refused from the next request. */
29
+ export declare function revokeInstallKey(tx: EntityManager, domain: {
30
+ id: string;
31
+ }, id: string): Promise<boolean>;
32
+ /** The Settings card's doors. Issuing a credential is a security change, as an appliance's is. */
33
+ export declare class FigureInstallKeyResolver {
34
+ figureInstallKeys(context: ResolverContext): Promise<FigureInstallKey[]>;
35
+ issueFigureInstallKey(name: string, context: ResolverContext): Promise<IssuedFigureInstallKey>;
36
+ revokeFigureInstallKey(id: string, context: ResolverContext): Promise<boolean>;
37
+ }
@@ -0,0 +1,164 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FigureInstallKeyResolver = exports.IssuedFigureInstallKey = exports.FigureInstallKey = exports.INSTALL_KEY_ROLE = exports.INSTALL_KEY_MODEL = void 0;
4
+ exports.installReaderRole = installReaderRole;
5
+ exports.installKeysOf = installKeysOf;
6
+ exports.issueInstallKey = issueInstallKey;
7
+ exports.revokeInstallKey = revokeInstallKey;
8
+ const tslib_1 = require("tslib");
9
+ const type_graphql_1 = require("type-graphql");
10
+ const auth_base_1 = require("@things-factory/auth-base");
11
+ const shell_1 = require("@things-factory/shell");
12
+ /*
13
+ * A board server's key to install figures from this server (ADR-0114 decision 21, amended 2026-11-15). The user:
14
+ * 「단말장치 키를 사용하는 곳이 없는데 세팅에 없는데」 - an appliance alone said nothing of what it was for and could
15
+ * read nothing (its user had no role). A key here is an appliance marked as an install key, whose user holds one
16
+ * role: reading released figures (`figure-published` query) - the catalog, the package and the release picture.
17
+ * Issuing, signing and revoking are the appliance's own (`issueApplianceSecret`, `deleteApplianceWithUser`).
18
+ */
19
+ /** The appliance model that marks an install key. */
20
+ exports.INSTALL_KEY_MODEL = 'figure-install-key';
21
+ /** The role every install key's user holds, made the first time a key is issued. */
22
+ exports.INSTALL_KEY_ROLE = 'figure-install-reader';
23
+ let FigureInstallKey = class FigureInstallKey {
24
+ };
25
+ exports.FigureInstallKey = FigureInstallKey;
26
+ tslib_1.__decorate([
27
+ (0, type_graphql_1.Field)({ description: 'The key id.' }),
28
+ tslib_1.__metadata("design:type", String)
29
+ ], FigureInstallKey.prototype, "id", void 0);
30
+ tslib_1.__decorate([
31
+ (0, type_graphql_1.Field)({ description: 'What the key is for, e.g. the board server it was given to.' }),
32
+ tslib_1.__metadata("design:type", String)
33
+ ], FigureInstallKey.prototype, "name", void 0);
34
+ tslib_1.__decorate([
35
+ (0, type_graphql_1.Field)({ nullable: true, description: 'When it was issued.' }),
36
+ tslib_1.__metadata("design:type", Date)
37
+ ], FigureInstallKey.prototype, "issuedAt", void 0);
38
+ tslib_1.__decorate([
39
+ (0, type_graphql_1.Field)({ nullable: true, description: 'Who issued it.' }),
40
+ tslib_1.__metadata("design:type", String)
41
+ ], FigureInstallKey.prototype, "issuedBy", void 0);
42
+ exports.FigureInstallKey = FigureInstallKey = tslib_1.__decorate([
43
+ (0, type_graphql_1.ObjectType)({ description: 'A key a board server installs figures from this server with - never the token after it is issued.' })
44
+ ], FigureInstallKey);
45
+ let IssuedFigureInstallKey = class IssuedFigureInstallKey extends FigureInstallKey {
46
+ };
47
+ exports.IssuedFigureInstallKey = IssuedFigureInstallKey;
48
+ tslib_1.__decorate([
49
+ (0, type_graphql_1.Field)({ description: 'The access token the board server enters in its Settings. Not shown again.' }),
50
+ tslib_1.__metadata("design:type", String)
51
+ ], IssuedFigureInstallKey.prototype, "token", void 0);
52
+ exports.IssuedFigureInstallKey = IssuedFigureInstallKey = tslib_1.__decorate([
53
+ (0, type_graphql_1.ObjectType)({ description: 'A key just issued, with its token - shown this once.' })
54
+ ], IssuedFigureInstallKey);
55
+ /** The role install keys hold: `figure-published` query only. Made once per domain. */
56
+ async function installReaderRole(tx, domain, user) {
57
+ const roles = tx.getRepository(auth_base_1.Role);
58
+ const found = await roles.findOne({ where: { domain: { id: domain.id }, name: exports.INSTALL_KEY_ROLE }, relations: { privileges: true } });
59
+ if (found)
60
+ return found;
61
+ const privilege = await tx.getRepository(auth_base_1.Privilege).findOne({ where: { category: 'figure-published', name: 'query' } });
62
+ if (!privilege)
63
+ throw new shell_1.Refusal('figure-install-key-privilege-missing', {}, 'This server has no privilege to read released figures.');
64
+ return await roles.save({
65
+ domain,
66
+ name: exports.INSTALL_KEY_ROLE,
67
+ description: 'Board servers installing figures (ADR-0114): reads released figures only',
68
+ privileges: [privilege],
69
+ creator: user,
70
+ updater: user
71
+ });
72
+ }
73
+ const keyOf = (appliance) => ({
74
+ id: appliance.id,
75
+ name: appliance.name,
76
+ issuedAt: appliance.updatedAt,
77
+ issuedBy: appliance.updater?.name ?? undefined
78
+ });
79
+ async function installKeysOf(tx, domain) {
80
+ const keys = await tx.getRepository(auth_base_1.Appliance).find({
81
+ where: { domain: { id: domain.id }, model: exports.INSTALL_KEY_MODEL },
82
+ relations: { updater: true },
83
+ order: { createdAt: 'DESC' }
84
+ });
85
+ return keys.map(keyOf);
86
+ }
87
+ /** Issues a new key: an install-key appliance, its user given the reader role, its secret signed. */
88
+ async function issueInstallKey(tx, domain, user, name) {
89
+ const label = String(name ?? '').trim();
90
+ if (!label)
91
+ throw new shell_1.Refusal('figure-install-key-name-missing', {}, 'Name the key - what board server it is for.');
92
+ if (label.length > 100)
93
+ throw new shell_1.Refusal('figure-install-key-name-too-long', { max: 100 }, 'A key name is at most {max} characters.');
94
+ const appliance = await (0, auth_base_1.createApplianceWithUser)(tx, domain, user, {
95
+ name: label,
96
+ serialNo: `install-key-${Date.now()}`,
97
+ brand: 'operato-figure',
98
+ model: exports.INSTALL_KEY_MODEL,
99
+ description: 'Board server install key (ADR-0114)'
100
+ });
101
+ const role = await installReaderRole(tx, domain, user);
102
+ const shadow = await tx.getRepository(auth_base_1.User).findOne({ where: { reference: appliance.id, userType: 'appliance' }, relations: { roles: true } });
103
+ shadow.roles = [role];
104
+ await tx.getRepository(auth_base_1.User).save(shadow);
105
+ const issued = await (0, auth_base_1.issueApplianceSecret)(tx, domain, user, appliance.id);
106
+ return { ...keyOf({ ...issued, updater: user }), token: issued.accessToken };
107
+ }
108
+ /** Revokes a key for good: the appliance and its user go, so its token is refused from the next request. */
109
+ async function revokeInstallKey(tx, domain, id) {
110
+ const key = await tx.getRepository(auth_base_1.Appliance).findOne({ where: { domain: { id: domain.id }, id, model: exports.INSTALL_KEY_MODEL } });
111
+ if (!key)
112
+ throw new shell_1.Refusal('figure-install-key-not-found', {}, 'There is no such install key.');
113
+ await (0, auth_base_1.deleteApplianceWithUser)(tx, domain, id);
114
+ return true;
115
+ }
116
+ /** The Settings card's doors. Issuing a credential is a security change, as an appliance's is. */
117
+ let FigureInstallKeyResolver = class FigureInstallKeyResolver {
118
+ async figureInstallKeys(context) {
119
+ const { domain, tx } = context.state;
120
+ return await installKeysOf(tx ?? (0, shell_1.getRepository)(auth_base_1.Appliance).manager, domain);
121
+ }
122
+ async issueFigureInstallKey(name, context) {
123
+ const { domain, user, tx } = context.state;
124
+ return await issueInstallKey(tx, domain, user, name);
125
+ }
126
+ async revokeFigureInstallKey(id, context) {
127
+ const { domain, tx } = context.state;
128
+ return await revokeInstallKey(tx, domain, id);
129
+ }
130
+ };
131
+ exports.FigureInstallKeyResolver = FigureInstallKeyResolver;
132
+ tslib_1.__decorate([
133
+ (0, type_graphql_1.Directive)('@privilege(category: "security", privilege: "query", domainOwnerGranted: true)'),
134
+ (0, type_graphql_1.Query)(returns => [FigureInstallKey], { description: 'The keys board servers install figures from this domain with.' }),
135
+ tslib_1.__param(0, (0, type_graphql_1.Ctx)()),
136
+ tslib_1.__metadata("design:type", Function),
137
+ tslib_1.__metadata("design:paramtypes", [Object]),
138
+ tslib_1.__metadata("design:returntype", Promise)
139
+ ], FigureInstallKeyResolver.prototype, "figureInstallKeys", null);
140
+ tslib_1.__decorate([
141
+ (0, type_graphql_1.Directive)('@transaction'),
142
+ (0, type_graphql_1.Directive)('@privilege(category: "security", privilege: "mutation", domainOwnerGranted: true)'),
143
+ (0, type_graphql_1.Mutation)(returns => IssuedFigureInstallKey, { description: 'Issues a key a board server installs figures with. Its token is answered this once.' }),
144
+ tslib_1.__param(0, (0, type_graphql_1.Arg)('name', { description: 'What the key is for.' })),
145
+ tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
146
+ tslib_1.__metadata("design:type", Function),
147
+ tslib_1.__metadata("design:paramtypes", [String, Object]),
148
+ tslib_1.__metadata("design:returntype", Promise)
149
+ ], FigureInstallKeyResolver.prototype, "issueFigureInstallKey", null);
150
+ tslib_1.__decorate([
151
+ (0, type_graphql_1.Directive)('@transaction'),
152
+ (0, type_graphql_1.Directive)('@privilege(category: "security", privilege: "mutation", domainOwnerGranted: true)'),
153
+ (0, type_graphql_1.Mutation)(returns => Boolean, { description: 'Revokes an install key: the board server using it can no longer install.' }),
154
+ tslib_1.__param(0, (0, type_graphql_1.Arg)('id', { description: 'The key id.' })),
155
+ tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
156
+ tslib_1.__metadata("design:type", Function),
157
+ tslib_1.__metadata("design:paramtypes", [String, Object]),
158
+ tslib_1.__metadata("design:returntype", Promise)
159
+ ], FigureInstallKeyResolver.prototype, "revokeFigureInstallKey", null);
160
+ exports.FigureInstallKeyResolver = FigureInstallKeyResolver = tslib_1.__decorate([
161
+ (0, type_graphql_1.Resolver)(),
162
+ (0, type_graphql_1.UseMiddleware)(shell_1.SpeakRefusals)
163
+ ], FigureInstallKeyResolver);
164
+ //# sourceMappingURL=figure-install-key.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/figure-service",
3
- "version": "10.1.281",
3
+ "version": "10.1.282",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "@things-factory:registry": "https://registry.npmjs.org"
@@ -42,16 +42,16 @@
42
42
  "dependencies": {
43
43
  "@hatiolab/figure-model": "^0.12.4",
44
44
  "@operato/typeorm-history": "^10.0.0",
45
- "@things-factory/ai-client-base": "^10.1.281",
46
- "@things-factory/attachment-base": "^10.1.281",
47
- "@things-factory/auth-base": "^10.1.281",
45
+ "@things-factory/ai-client-base": "^10.1.282",
46
+ "@things-factory/attachment-base": "^10.1.282",
47
+ "@things-factory/auth-base": "^10.1.282",
48
48
  "@things-factory/env": "^10.1.281",
49
- "@things-factory/setting-base": "^10.1.281",
50
- "@things-factory/shell": "^10.1.281",
49
+ "@things-factory/setting-base": "^10.1.282",
50
+ "@things-factory/shell": "^10.1.282",
51
51
  "graphql-scalars": "^1.22.4",
52
52
  "graphql-upload": "^15.0.2",
53
53
  "jszip": "^3.10.1",
54
54
  "koa-router": "^7.4.0"
55
55
  },
56
- "gitHead": "c872f4723dcd72808f3c60a7d6c95521d4c2bbca"
56
+ "gitHead": "6a232e670bdb52e1420b1d33cdeeb37ceb0f26b8"
57
57
  }
@@ -190,5 +190,9 @@
190
190
  "figure.gate.contract.data-table-changed.message": "The table '{binding}' changed.",
191
191
  "figure.gate.contract.data-table-changed.why": "Where no legend is chosen, the same value may look different after this release.",
192
192
  "figure.gate.contract.data-table-role-changed.message": "The legend role of the table '{binding}' changed from '{before}' to '{after}'.",
193
- "figure.gate.contract.data-table-role-changed.why": "A legend a board chose for the old role is not used after this release. Choose one for the new role."
193
+ "figure.gate.contract.data-table-role-changed.why": "A legend a board chose for the old role is not used after this release. Choose one for the new role.",
194
+ "error.figure-install-key-name-missing": "Name the key - what board server it is for.",
195
+ "error.figure-install-key-name-too-long": "A key name is at most {max} characters.",
196
+ "error.figure-install-key-not-found": "There is no such install key.",
197
+ "error.figure-install-key-privilege-missing": "This server has no privilege to read released figures."
194
198
  }
@@ -190,5 +190,9 @@
190
190
  "figure.gate.contract.data-table-changed.message": "La tabla '{binding}' cambió.",
191
191
  "figure.gate.contract.data-table-changed.why": "Donde no se eligió leyenda, el mismo valor puede verse distinto tras esta publicación.",
192
192
  "figure.gate.contract.data-table-role-changed.message": "El rol de leyenda de la tabla '{binding}' cambió de '{before}' a '{after}'.",
193
- "figure.gate.contract.data-table-role-changed.why": "La leyenda elegida para el rol anterior no se usa tras esta publicación. Elija una para el rol nuevo."
193
+ "figure.gate.contract.data-table-role-changed.why": "La leyenda elegida para el rol anterior no se usa tras esta publicación. Elija una para el rol nuevo.",
194
+ "error.figure-install-key-name-missing": "Indique el nombre de la clave: el servidor de tableros que la usará.",
195
+ "error.figure-install-key-name-too-long": "El nombre de la clave tiene como máximo {max} caracteres.",
196
+ "error.figure-install-key-not-found": "No existe esa clave de instalación.",
197
+ "error.figure-install-key-privilege-missing": "Este servidor no tiene el permiso para leer figuras publicadas."
194
198
  }
@@ -190,5 +190,9 @@
190
190
  "figure.gate.contract.data-table-changed.message": "表 '{binding}' の内容が変わりました。",
191
191
  "figure.gate.contract.data-table-changed.why": "凡例を選んでいない所では、同じ値がこの発行から違って見えることがあります。",
192
192
  "figure.gate.contract.data-table-role-changed.message": "表 '{binding}' の凡例の役割が '{before}' から '{after}' に変わりました。",
193
- "figure.gate.contract.data-table-role-changed.why": "ボードが古い役割に選んだ凡例は、この発行から使われません。新しい役割に凡例を選びます。"
193
+ "figure.gate.contract.data-table-role-changed.why": "ボードが古い役割に選んだ凡例は、この発行から使われません。新しい役割に凡例を選びます。",
194
+ "error.figure-install-key-name-missing": "キー名を入力してください。このキーを使うボードサーバー名を入力します。",
195
+ "error.figure-install-key-name-too-long": "キー名は {max} 文字以内で入力してください。",
196
+ "error.figure-install-key-not-found": "該当するインストールキーがありません。",
197
+ "error.figure-install-key-privilege-missing": "このサーバーに発行済み Figure の参照権限が定義されていません。"
194
198
  }
@@ -190,5 +190,9 @@
190
190
  "figure.gate.contract.data-table-changed.message": "'{binding}' 표 연결의 표가 바뀌었습니다.",
191
191
  "figure.gate.contract.data-table-changed.why": "범례를 고르지 않은 곳에서는 같은 값이 이 발행부터 다르게 보일 수 있습니다.",
192
192
  "figure.gate.contract.data-table-role-changed.message": "'{binding}' 표 연결의 범례 역할이 '{before}' 이름에서 '{after}' 이름으로 바뀌었습니다.",
193
- "figure.gate.contract.data-table-role-changed.why": "보드가 옛 역할에 고른 범례는 이 발행부터 쓰이지 않습니다. 새 역할에 범례를 고릅니다."
193
+ "figure.gate.contract.data-table-role-changed.why": "보드가 옛 역할에 고른 범례는 이 발행부터 쓰이지 않습니다. 새 역할에 범례를 고릅니다.",
194
+ "error.figure-install-key-name-missing": "키 이름을 입력하세요. 이 키를 사용할 보드 서버를 적으면 됩니다.",
195
+ "error.figure-install-key-name-too-long": "키 이름은 {max}자 이하로 입력하세요.",
196
+ "error.figure-install-key-not-found": "해당 설치 키가 없습니다.",
197
+ "error.figure-install-key-privilege-missing": "이 서버에 발행 피규어 조회 권한이 정의되어 있지 않습니다."
194
198
  }
@@ -190,5 +190,9 @@
190
190
  "figure.gate.contract.data-table-changed.message": "Jadual '{binding}' telah berubah.",
191
191
  "figure.gate.contract.data-table-changed.why": "Di tempat tiada petunjuk dipilih, nilai yang sama mungkin kelihatan berbeza selepas keluaran ini.",
192
192
  "figure.gate.contract.data-table-role-changed.message": "Peranan petunjuk jadual '{binding}' berubah daripada '{before}' kepada '{after}'.",
193
- "figure.gate.contract.data-table-role-changed.why": "Petunjuk yang dipilih bagi peranan lama tidak digunakan selepas keluaran ini. Pilih satu bagi peranan baharu."
193
+ "figure.gate.contract.data-table-role-changed.why": "Petunjuk yang dipilih bagi peranan lama tidak digunakan selepas keluaran ini. Pilih satu bagi peranan baharu.",
194
+ "error.figure-install-key-name-missing": "Namakan kunci - pelayan papan yang akan menggunakannya.",
195
+ "error.figure-install-key-name-too-long": "Nama kunci paling banyak {max} aksara.",
196
+ "error.figure-install-key-not-found": "Tiada kunci pemasangan sedemikian.",
197
+ "error.figure-install-key-privilege-missing": "Pelayan ini tiada keistimewaan untuk membaca figure terbitan."
194
198
  }
@@ -190,5 +190,9 @@
190
190
  "figure.gate.contract.data-table-changed.message": "表 '{binding}' 已更改。",
191
191
  "figure.gate.contract.data-table-changed.why": "未选择图例的地方,同一值从本次发布起可能显示不同。",
192
192
  "figure.gate.contract.data-table-role-changed.message": "表 '{binding}' 的图例角色由 '{before}' 改为 '{after}'。",
193
- "figure.gate.contract.data-table-role-changed.why": "看板为旧角色选择的图例从本次发布起不再使用。请为新角色选择图例。"
193
+ "figure.gate.contract.data-table-role-changed.why": "看板为旧角色选择的图例从本次发布起不再使用。请为新角色选择图例。",
194
+ "error.figure-install-key-name-missing": "请输入密钥名称,即使用该密钥的看板服务器。",
195
+ "error.figure-install-key-name-too-long": "密钥名称最多 {max} 个字符。",
196
+ "error.figure-install-key-not-found": "没有该安装密钥。",
197
+ "error.figure-install-key-privilege-missing": "此服务器未定义读取已发布图形的权限。"
194
198
  }