@things-factory/figure-service 10.1.281 → 10.1.283
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-server/routers/figure-thumbnail-router.d.ts +3 -1
- package/dist-server/routers/figure-thumbnail-router.js +15 -2
- package/dist-server/service/figure/figure-mcp-agent.d.ts +63 -0
- package/dist-server/service/figure/figure-mcp-agent.js +221 -0
- package/dist-server/service/figure/figure-public.d.ts +5 -0
- package/dist-server/service/figure/figure-public.js +9 -0
- package/dist-server/service/figure/figure-query.d.ts +6 -0
- package/dist-server/service/figure/figure-query.js +18 -1
- package/dist-server/service/figure/figure-read.d.ts +13 -0
- package/dist-server/service/figure/figure-read.js +105 -0
- package/dist-server/service/figure/figure-release-catalog.d.ts +36 -0
- package/dist-server/service/figure/figure-release-catalog.js +149 -0
- package/dist-server/service/figure/figure-tools.js +72 -18
- package/dist-server/service/index.d.ts +3 -1
- package/dist-server/service/index.js +3 -1
- package/dist-server/service/install-key/figure-install-key.d.ts +37 -0
- package/dist-server/service/install-key/figure-install-key.js +164 -0
- package/mcp/figure-mcp-server.mjs +259 -0
- package/package.json +9 -8
- package/translations/en.json +15 -1
- package/translations/es.json +15 -1
- package/translations/ja.json +15 -1
- package/translations/ko.json +15 -1
- package/translations/ms.json +15 -1
- package/translations/zh.json +15 -1
|
@@ -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
|
|
@@ -42,6 +42,39 @@ const crypto_1 = require("crypto");
|
|
|
42
42
|
const typeorm_1 = require("typeorm");
|
|
43
43
|
const ai_client_base_1 = require("@things-factory/ai-client-base");
|
|
44
44
|
const figure_context_js_1 = require("./figure-context.js");
|
|
45
|
+
const figure_mcp_agent_js_1 = require("./figure-mcp-agent.js");
|
|
46
|
+
/**
|
|
47
|
+
* The person asking, for the agent's tools that reach the application: the tools their privileges open -- asked of the
|
|
48
|
+
* conversation's own tool gate -- and a token of theirs that lives as long as the agent may run. None when no tool
|
|
49
|
+
* opens, the conversation has no gate, or the request carries no user.
|
|
50
|
+
*/
|
|
51
|
+
async function mcpAgentCallerOf(ctx) {
|
|
52
|
+
const user = ctx?.state?.user;
|
|
53
|
+
const domain = ctx?.state?.domain;
|
|
54
|
+
if (!user || !domain || typeof user.sign !== 'function' || typeof ctx?.access !== 'function')
|
|
55
|
+
return undefined;
|
|
56
|
+
const tools = await (0, figure_mcp_agent_js_1.figureAppToolsFor)(ctx.access);
|
|
57
|
+
if (!tools.length)
|
|
58
|
+
return undefined;
|
|
59
|
+
return {
|
|
60
|
+
url: `http://127.0.0.1:${process.env.PORT || 3000}/graphql`,
|
|
61
|
+
token: await user.sign({ expiresIn: 25 * 60 }),
|
|
62
|
+
domain: domain.subdomain,
|
|
63
|
+
tools
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/** What the figure agent is doing, by the tool it calls: the English the translations default to. */
|
|
67
|
+
const AGENT_PROGRESS = {
|
|
68
|
+
get_guide: 'Reading how a figure is made…',
|
|
69
|
+
apply_steps: 'Building the figure (round {count})…',
|
|
70
|
+
read_figure: 'Reading where the parts are…',
|
|
71
|
+
try_pose: 'Checking how it moves…',
|
|
72
|
+
render: 'Looking at the figure…',
|
|
73
|
+
start_over: 'Starting the design again…',
|
|
74
|
+
find_figures: 'Looking through your figures…',
|
|
75
|
+
open_figure: 'Opening one of your figures…',
|
|
76
|
+
finish: 'Finishing…'
|
|
77
|
+
};
|
|
45
78
|
/** How many figures a list without search names. */
|
|
46
79
|
const LIST_LIMIT = 200;
|
|
47
80
|
/*
|
|
@@ -479,23 +512,35 @@ function figureToolSpecs() {
|
|
|
479
512
|
const { proposeFigureSteps } = getDeps();
|
|
480
513
|
let result;
|
|
481
514
|
try {
|
|
482
|
-
|
|
483
|
-
/* The agent
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
515
|
+
if ((0, figure_mcp_agent_js_1.figureMcpAgentOn)()) {
|
|
516
|
+
/* The agent with the figure tools (figure-mcp-agent.ts): what it is doing is what the person sees while waiting. */
|
|
517
|
+
ctx?.progress?.(ctx.t('figure.progress.agent.start', { defaultValue: 'Reading how a figure is made…' }));
|
|
518
|
+
result = await (0, figure_mcp_agent_js_1.buildByMcpAgent)({
|
|
519
|
+
caller: await mcpAgentCallerOf(ctx),
|
|
520
|
+
prompt,
|
|
521
|
+
base: base,
|
|
522
|
+
name: typeof args?.name === 'string' && args.name.trim() ? args.name.trim() : undefined,
|
|
523
|
+
onTool: (tool, count) => ctx?.progress?.(ctx.t(`figure.progress.agent.${tool}`, { count, defaultValue: AGENT_PROGRESS[tool] ?? 'Working on the figure…' }))
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
else
|
|
527
|
+
result = await proposeFigureSteps({
|
|
528
|
+
/* The agent of this conversation's turn - the one the person picked, or the domain default. */
|
|
529
|
+
client: await (0, ai_client_base_1.aiClientFor)({
|
|
530
|
+
domain: ctx?.state?.domain,
|
|
531
|
+
user: ctx?.state?.user,
|
|
532
|
+
agentId: ctx?.state?.aiAgentId,
|
|
533
|
+
modeKind: ctx?.mode?.kind
|
|
534
|
+
}),
|
|
535
|
+
prompt,
|
|
536
|
+
base,
|
|
537
|
+
name: typeof args?.name === 'string' && args.name.trim() ? args.name.trim() : undefined,
|
|
538
|
+
...(images.length ? { images } : {}),
|
|
539
|
+
...(focus && Object.keys(focus).length ? { focus } : {}),
|
|
540
|
+
...(!create && (stringsOf(args?.parts).length || stringsOf(args?.sections).length)
|
|
541
|
+
? { read: { parts: stringsOf(args?.parts), sections: stringsOf(args?.sections) } }
|
|
542
|
+
: {})
|
|
543
|
+
});
|
|
499
544
|
}
|
|
500
545
|
catch (error) {
|
|
501
546
|
/*
|
|
@@ -543,7 +588,15 @@ function figureToolSpecs() {
|
|
|
543
588
|
steps: result.steps,
|
|
544
589
|
score: result.score,
|
|
545
590
|
cost: result.cost,
|
|
546
|
-
attempts: result.attempts
|
|
591
|
+
attempts: result.attempts,
|
|
592
|
+
/*
|
|
593
|
+
What is still off by measure on the figure the agent made: what it did not fix, and notes. The person hears them
|
|
594
|
+
with the card, so nothing measured as wrong is presented as done.
|
|
595
|
+
*/
|
|
596
|
+
...(result.findings?.length ? { concerns: result.findings.map((f) => `${f.severity === 'fix' ? 'still wrong' : 'note'}: ${f.message}`) } : {}),
|
|
597
|
+
/* What the figure agent says it made, for the reply; and that it stopped before it said it was done. */
|
|
598
|
+
...(typeof result.summary === 'string' ? { made: result.summary } : {}),
|
|
599
|
+
...(result.finished === false ? { unfinished: 'The agent ended without saying the figure was done (it did not call finish). Check the card against the request before you say it is complete.' } : {})
|
|
547
600
|
};
|
|
548
601
|
}
|
|
549
602
|
}
|
|
@@ -565,6 +618,7 @@ function registerFigureToolCategories() {
|
|
|
565
618
|
' Writing "I made a proposal" or "press apply" without the call is **false**: no card appears, and the person looks for a button that does not exist.',
|
|
566
619
|
' A proposal is a list of modeller commands. The modeller applies it as one step only when the person runs it from the dock card, and one undo takes it all back. Do not say the figure has changed before that.',
|
|
567
620
|
' A revision can be proposed only for the figure open in the modeller. Say what the result\'s `steps` do as they are; do not invent changes the commands do not make.',
|
|
621
|
+
' When the result has `concerns`, say each in plain words before anything else about the card: "still wrong" ones are measured on the figure and were not fixed -- the person decides whether to run the card. `made` is what was built, in the builder\'s words.',
|
|
568
622
|
'- Never save the source yourself. Propose; the author decides on the screen whether to take it.',
|
|
569
623
|
'- In the prompt to `proposeFigureCandidate`, pass the person\'s words as they are: their sizes, counts and names. Do not turn them into axes; the writer knows the figure\'s axes. When you name an axis to the person, the figure\'s Y is up.',
|
|
570
624
|
'- **For a request to change a figure, call `getFigureSource` first.** Revising without reading proposes against a guess, and a renamed part breaks the bindings of the boards it is already placed on.',
|
|
@@ -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
|