@things-factory/ai-dashboard 0.0.0-stage → 10.1.213

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.
Files changed (108) hide show
  1. package/client/bootstrap.ts +25 -0
  2. package/client/components/card-dialogs.ts +422 -0
  3. package/client/components/card-library.ts +272 -0
  4. package/client/components/dashboard-card.ts +450 -0
  5. package/client/components/proposal-preview.ts +96 -0
  6. package/client/index.ts +3 -0
  7. package/client/pages/my-dashboard-page.ts +371 -0
  8. package/client/route.ts +8 -0
  9. package/client/tsconfig.json +13 -0
  10. package/client/utils/card-api.ts +110 -0
  11. package/client/utils/card-words.ts +80 -0
  12. package/dist-client/bootstrap.d.ts +2 -0
  13. package/dist-client/bootstrap.js +24 -0
  14. package/dist-client/bootstrap.js.map +1 -0
  15. package/dist-client/components/card-dialogs.d.ts +59 -0
  16. package/dist-client/components/card-dialogs.js +457 -0
  17. package/dist-client/components/card-dialogs.js.map +1 -0
  18. package/dist-client/components/card-library.d.ts +23 -0
  19. package/dist-client/components/card-library.js +276 -0
  20. package/dist-client/components/card-library.js.map +1 -0
  21. package/dist-client/components/dashboard-card.d.ts +35 -0
  22. package/dist-client/components/dashboard-card.js +490 -0
  23. package/dist-client/components/dashboard-card.js.map +1 -0
  24. package/dist-client/components/proposal-preview.d.ts +17 -0
  25. package/dist-client/components/proposal-preview.js +111 -0
  26. package/dist-client/components/proposal-preview.js.map +1 -0
  27. package/dist-client/index.d.ts +3 -0
  28. package/dist-client/index.js +4 -0
  29. package/dist-client/index.js.map +1 -0
  30. package/dist-client/pages/my-dashboard-page.d.ts +46 -0
  31. package/dist-client/pages/my-dashboard-page.js +376 -0
  32. package/dist-client/pages/my-dashboard-page.js.map +1 -0
  33. package/dist-client/route.d.ts +1 -0
  34. package/dist-client/route.js +9 -0
  35. package/dist-client/route.js.map +1 -0
  36. package/dist-client/tsconfig.tsbuildinfo +1 -0
  37. package/dist-client/utils/card-api.d.ts +95 -0
  38. package/dist-client/utils/card-api.js +39 -0
  39. package/dist-client/utils/card-api.js.map +1 -0
  40. package/dist-client/utils/card-words.d.ts +24 -0
  41. package/dist-client/utils/card-words.js +72 -0
  42. package/dist-client/utils/card-words.js.map +1 -0
  43. package/dist-server/index.d.ts +11 -0
  44. package/dist-server/index.js +19 -0
  45. package/dist-server/index.js.map +1 -0
  46. package/dist-server/role-tasks.d.ts +2 -0
  47. package/dist-server/role-tasks.js +13 -0
  48. package/dist-server/role-tasks.js.map +1 -0
  49. package/dist-server/service/card/card-access.d.ts +32 -0
  50. package/dist-server/service/card/card-access.js +45 -0
  51. package/dist-server/service/card/card-access.js.map +1 -0
  52. package/dist-server/service/card/card-definition.d.ts +100 -0
  53. package/dist-server/service/card/card-definition.js +237 -0
  54. package/dist-server/service/card/card-definition.js.map +1 -0
  55. package/dist-server/service/card/card-names.d.ts +5 -0
  56. package/dist-server/service/card/card-names.js +9 -0
  57. package/dist-server/service/card/card-names.js.map +1 -0
  58. package/dist-server/service/card/card-proposal.d.ts +21 -0
  59. package/dist-server/service/card/card-proposal.js +28 -0
  60. package/dist-server/service/card/card-proposal.js.map +1 -0
  61. package/dist-server/service/card/card-resolver.d.ts +29 -0
  62. package/dist-server/service/card/card-resolver.js +541 -0
  63. package/dist-server/service/card/card-resolver.js.map +1 -0
  64. package/dist-server/service/card/card-run.d.ts +48 -0
  65. package/dist-server/service/card/card-run.js +239 -0
  66. package/dist-server/service/card/card-run.js.map +1 -0
  67. package/dist-server/service/card/card-tool.d.ts +218 -0
  68. package/dist-server/service/card/card-tool.js +313 -0
  69. package/dist-server/service/card/card-tool.js.map +1 -0
  70. package/dist-server/service/card/card-types.d.ts +56 -0
  71. package/dist-server/service/card/card-types.js +212 -0
  72. package/dist-server/service/card/card-types.js.map +1 -0
  73. package/dist-server/service/card/dashboard-card.d.ts +87 -0
  74. package/dist-server/service/card/dashboard-card.js +388 -0
  75. package/dist-server/service/card/dashboard-card.js.map +1 -0
  76. package/dist-server/service/card/long-text.d.ts +6 -0
  77. package/dist-server/service/card/long-text.js +28 -0
  78. package/dist-server/service/card/long-text.js.map +1 -0
  79. package/dist-server/service/index.d.ts +12 -0
  80. package/dist-server/service/index.js +24 -0
  81. package/dist-server/service/index.js.map +1 -0
  82. package/dist-server/tsconfig.tsbuildinfo +1 -0
  83. package/package.json +47 -4
  84. package/server/index.ts +16 -0
  85. package/server/role-tasks.ts +12 -0
  86. package/server/service/card/card-access.test.ts +138 -0
  87. package/server/service/card/card-access.ts +53 -0
  88. package/server/service/card/card-definition.ts +298 -0
  89. package/server/service/card/card-names.ts +5 -0
  90. package/server/service/card/card-proposal.ts +37 -0
  91. package/server/service/card/card-resolver.ts +434 -0
  92. package/server/service/card/card-run.test.ts +237 -0
  93. package/server/service/card/card-run.ts +288 -0
  94. package/server/service/card/card-tool.ts +299 -0
  95. package/server/service/card/card-types.ts +145 -0
  96. package/server/service/card/dashboard-card.ts +301 -0
  97. package/server/service/card/long-text.ts +25 -0
  98. package/server/service/index.ts +16 -0
  99. package/test/translations.test.ts +42 -0
  100. package/things-factory.config.js +8 -0
  101. package/translations/en.json +126 -0
  102. package/translations/es.json +126 -0
  103. package/translations/ja.json +126 -0
  104. package/translations/ko.json +126 -0
  105. package/translations/ms.json +126 -0
  106. package/translations/zh.json +126 -0
  107. package/tsconfig.json +9 -0
  108. package/README.md +0 -3
@@ -0,0 +1,299 @@
1
+ /*
2
+ * proposeDashboardCard - the assistant writes a card's definition in a conversation; the person saves it by pressing
3
+ * the card (ADR-0160 decision 9).
4
+ *
5
+ * The server checks the definition against the read it names and runs it once as the person, so a card that cannot
6
+ * be drawn is sent back with what the read has - never offered. The proposal carries the definition only: the
7
+ * preview on the card is run again by whoever looks at the conversation, as themselves (decision 6), and the model
8
+ * is told no values - its answer is read by everyone the conversation lets in, whatever door they pass.
9
+ */
10
+ import { registerToolCategory, type ToolCategory, type ToolSpec } from '@things-factory/ai-client-base'
11
+ import {
12
+ detailReadKeys,
13
+ detailReadOf,
14
+ readTargetKeys,
15
+ readTargetOf,
16
+ registerConversationCategory,
17
+ runAsCaller,
18
+ toolAccessFor
19
+ } from '@things-factory/ai-assistant'
20
+
21
+ import { CARD_SCHEMA_VERSION, checkDefinition, MATCH_OPS, sourceOf, todayIn, VIEW_KINDS, type CardDefinition, type CardSource } from './card-definition.js'
22
+ import { runCard, shapedColumnNames } from './card-run.js'
23
+
24
+ import { CARD_CATEGORY, CARD_TOOL, DASHBOARD_PAGE } from './card-names.js'
25
+
26
+ export { CARD_CATEGORY, CARD_TOOL, DASHBOARD_PAGE }
27
+
28
+ /** What a read offers a card - for a refusal the model fixes the definition from. */
29
+ function sourceSheet(source: CardSource, groupBy?: string) {
30
+ return {
31
+ read: source.key,
32
+ ...(source.list ? { list: source.list.key } : {}),
33
+ /* What the rows are - a state as of today or a ledger over time - decides whether a period is a filter at all. */
34
+ description: source.description,
35
+ conditions: source.conditions.map(one => ({ name: one.name, type: one.type, ...(one.required ? { required: true } : {}), ...(one.values ? { values: one.values } : {}), ...(one.description ? { description: one.description } : {}) })),
36
+ columns: source.columns.map(one => ({ name: one.name, type: one.type, ...(one.currency ? { currency: one.currency } : {}) })),
37
+ ...(groupBy ? { columnsAfterGroupBy: [...shapedColumnNames(source, { groupBy }).keys()] } : {})
38
+ }
39
+ }
40
+
41
+ /** The reads a card may name - list read targets, and detail reads with declared lists (`key/list`). */
42
+ export function cardSources(): string[] {
43
+ return [
44
+ ...readTargetKeys(),
45
+ ...detailReadKeys().flatMap(key => (detailReadOf(key)?.lists ?? []).map(list => `${key}/${list.key}`))
46
+ ]
47
+ }
48
+
49
+ /** A saved card as a change needs it - whose it is and its version. */
50
+ export type CardOf = (id: string) => Promise<{ ownerId?: string; version: number } | undefined>
51
+
52
+ /** The card in the person's domain - loaded late so the rules are tested without a database. */
53
+ const cardInDomain =
54
+ (context: any): CardOf =>
55
+ async id => {
56
+ const [{ getRepository }, { DashboardCard }] = await Promise.all([import('@things-factory/shell'), import('./dashboard-card.js')])
57
+ const card = await getRepository(DashboardCard).findOne({ where: { id, domain: { id: context?.state?.domain?.id } } as any })
58
+ return card ? { ownerId: card.ownerId, version: card.version } : undefined
59
+ }
60
+
61
+ export async function proposeDashboardCard(args: any, context: any, deps: { run?: any; passesDoor?: (door: string) => Promise<boolean>; today?: string; cardOf?: CardOf } = {}) {
62
+ const name = typeof args?.name === 'string' ? args.name.trim().slice(0, 100) : ''
63
+ if (!name) return { rejected: true, error: 'no-name', message: 'give the card a short name in the person\'s language.' }
64
+ const definition: CardDefinition = {
65
+ schemaVersion: CARD_SCHEMA_VERSION,
66
+ source: { read: args?.source?.read, ...(args?.source?.list ? { list: args.source.list } : {}), ...(args?.source?.where ? { where: args.source.where } : {}) },
67
+ ...(args?.rows && Object.keys(args.rows).length ? { rows: args.rows } : {}),
68
+ view: args?.view
69
+ }
70
+ const { source, issue } = sourceOf(definition.source, readTargetOf, detailReadOf)
71
+ if (!source) {
72
+ return {
73
+ rejected: true,
74
+ error: issue!.code,
75
+ ...issue!.params,
76
+ ...(issue!.code === 'unknown-read' || issue!.code === 'not-a-card-source' ? { sources: cardSources() } : {}),
77
+ message: 'the card must read one of the sources listed (a detail read by `read` and `list`). Read the data with its tool first, then call again.'
78
+ }
79
+ }
80
+ const issues = checkDefinition(definition, source)
81
+ if (issues.length) {
82
+ return {
83
+ rejected: true,
84
+ error: 'definition-unfit',
85
+ issues,
86
+ source: sourceSheet(source, definition.rows?.groupBy),
87
+ message:
88
+ 'fix every issue against the source below and call again now, in this turn - do not ask the person. source.where takes only the conditions listed (give every required one); ' +
89
+ 'a column is filtered with rows.match; a period with no date condition is a rows.match on a date column, or left out when the source is a state as of today.'
90
+ }
91
+ }
92
+
93
+ /* A change is of one's own card, from the version it was read at - a newer version is not overwritten unseen. */
94
+ const cardId = typeof args?.cardId === 'string' && args.cardId ? args.cardId : undefined
95
+ let baseVersion: number | undefined
96
+ if (cardId) {
97
+ const saved = await (deps.cardOf ?? cardInDomain(context))(cardId)
98
+ if (!saved) return { rejected: true, error: 'unknown-card', message: 'there is no such card - leave cardId out to offer a new one.' }
99
+ if (saved.ownerId !== context?.state?.user?.id) return { rejected: true, error: 'not-your-card', message: 'only its owner changes a card - offer a new card instead, without cardId.' }
100
+ baseVersion = Number.isInteger(args?.baseVersion) ? args.baseVersion : saved.version
101
+ if (baseVersion !== saved.version) return { rejected: true, error: 'stale-version', current: saved.version, message: `the card is at version ${saved.version} now - start from it and call again.` }
102
+ }
103
+
104
+ /* Run once as the person - what cannot be drawn is not offered. */
105
+ const ran = await runCard(definition, {
106
+ readTargetOf,
107
+ detailReadOf,
108
+ passesDoor: deps.passesDoor ?? (door => toolAccessFor(context)(door)),
109
+ run: deps.run ?? runAsCaller(context),
110
+ today: deps.today ?? todayIn(context?.state?.domain?.timezone)
111
+ })
112
+ if (ran.issue) {
113
+ return { rejected: true, error: ran.issue.code, ...(ran.issue.params ? { params: ran.issue.params } : {}), source: sourceSheet(source, definition.rows?.groupBy), message: 'the card could not be drawn - fix the definition and call again in this turn; say plainly if it cannot be.' }
114
+ }
115
+ /*
116
+ * A table or chart that draws nothing today is offered only when the person asked for something that may be empty - a
117
+ * request that expects rows was most likely read wrong (2026-10-24: 「이번 달 미수금」 filtered a state of today by the
118
+ * contract date and drew nothing).
119
+ */
120
+ if (ran.counts && ran.counts.shown === 0 && definition.view.kind !== 'number' && args?.allowEmpty !== true) {
121
+ return {
122
+ rejected: true,
123
+ error: 'draws-nothing',
124
+ read: ran.counts.read,
125
+ source: sourceSheet(source, definition.rows?.groupBy),
126
+ message:
127
+ `no row meets these conditions today (${ran.counts.read} read). Read the source's description: a state as of today takes no period filter. ` +
128
+ 'Fix the conditions and call again now; only if the person asked for something that may well be empty, call again with allowEmpty: true.'
129
+ }
130
+ }
131
+ /*
132
+ * Bars or a line whose names repeat cannot be read - two bars of one customer are two contracts the reader cannot tell
133
+ * apart (2026-10-24: 「미수금 상위 5곳」 drew one customer twice). Asked when the card is offered; a saved card draws as
134
+ * its data stands.
135
+ */
136
+ const x: unknown[] = Array.isArray((ran.block as any)?.x) ? (ran.block as any).x : []
137
+ if (!definition.rows?.groupBy && new Set(x).size < x.length) {
138
+ const label = definition.view.label!
139
+ return {
140
+ rejected: true,
141
+ error: 'label-repeats',
142
+ label,
143
+ use: `rows.groupBy: '${label}' (and sortBy a summed value)`,
144
+ source: sourceSheet(source, label),
145
+ message: `the bars' names (${label}) repeat - one name stands for several rows. Group by it so each name is one bar, and call again now, in this turn.`
146
+ }
147
+ }
148
+
149
+ return {
150
+ proposed: true,
151
+ kind: 'dashboard-card',
152
+ icon: 'dashboard_customize',
153
+ label: name,
154
+ card: {
155
+ name,
156
+ ...(typeof args?.description === 'string' && args.description.trim() ? { description: args.description.trim().slice(0, 300) } : {}),
157
+ definition,
158
+ ...(cardId ? { cardId, baseVersion } : {})
159
+ },
160
+ message:
161
+ 'the card is offered with its preview; the person saves it to their dashboard by pressing it. Say in one line what it shows. ' +
162
+ 'Do not ask whether to save it, and do not repeat its numbers - the preview shows them to whoever looks.'
163
+ }
164
+ }
165
+
166
+ const COLUMN = { type: 'string' }
167
+
168
+ const spec = {
169
+ kind: 'read',
170
+ name: CARD_TOOL,
171
+ /* Only someone who may save a card is offered one. The data's doors are asked when it runs, as the person. */
172
+ doors: ['Mutation.saveDashboardCardProposal'],
173
+ description:
174
+ 'Offer a dashboard card - a definition the person saves to 나의 대시보드, drawn afterwards from the data without you. ' +
175
+ 'source.read is a read you have (a list target, or a detail read with source.list naming one of its lists); source.where holds its conditions or arguments - ' +
176
+ 'for a period use relative values (today, this-month-start, this-month-end, last-month-start, this-year-start, -30d; for an integer year or month: this-year, last-month) so the card stays current. ' +
177
+ `rows: match [{column, op: ${MATCH_OPS.join('|')}, value}], groupBy (a date groups by month), sortBy (a column, or count when grouped), desc, limit. ` +
178
+ `view.kind: ${VIEW_KINDS.join('|')}; label is the column along the bottom of a chart (the groupBy column by default); values are the number columns summed or drawn (none counts rows); columns lists a table's columns. ` +
179
+ 'To change a saved card, pass its cardId and the version you changed as baseVersion.',
180
+ schema: {
181
+ type: 'object',
182
+ properties: {
183
+ name: { type: 'string', description: 'The card name, short, in the person\'s language.' },
184
+ description: { type: 'string', description: 'One line of what it shows.' },
185
+ source: {
186
+ type: 'object',
187
+ properties: {
188
+ read: { type: 'string', description: 'The read key - office.receivables, office.cash-transaction.' },
189
+ list: { type: 'string', description: 'A detail read\'s list key.' },
190
+ where: { type: 'object', description: 'Conditions or arguments by name; dates may be relative.', additionalProperties: true }
191
+ },
192
+ required: ['read']
193
+ },
194
+ rows: {
195
+ type: 'object',
196
+ properties: {
197
+ match: {
198
+ type: 'array',
199
+ items: { type: 'object', properties: { column: COLUMN, op: { type: 'string', enum: [...MATCH_OPS] }, value: { type: 'string', description: 'A number, a day, a word or a relative date.' } }, required: ['column', 'op', 'value'] }
200
+ },
201
+ groupBy: COLUMN,
202
+ sortBy: COLUMN,
203
+ desc: { type: 'boolean' },
204
+ limit: { type: 'integer' }
205
+ }
206
+ },
207
+ view: {
208
+ type: 'object',
209
+ properties: {
210
+ kind: { type: 'string', enum: [...VIEW_KINDS] },
211
+ label: COLUMN,
212
+ values: { type: 'array', items: COLUMN },
213
+ columns: { type: 'array', items: COLUMN },
214
+ unit: { type: 'string' }
215
+ },
216
+ required: ['kind']
217
+ },
218
+ allowEmpty: { type: 'boolean', description: 'true only when the person asked for something that may be empty today (overdue items, alerts).' },
219
+ cardId: { type: 'string', description: 'A saved card being changed.' },
220
+ baseVersion: { type: 'integer', description: 'The version of that card the change starts from.' }
221
+ },
222
+ required: ['name', 'source', 'view']
223
+ },
224
+ builder: (args: any, context: any) => proposeDashboardCard(args, context)
225
+ } as ToolSpec
226
+
227
+ /**
228
+ * A saved card's name, version and definition - no values - for a change asked from the dashboard (「AI로 고치기」 picks
229
+ * the card; the model reads it here, then offers the changed definition with cardId and baseVersion).
230
+ */
231
+ export async function readDashboardCard(args: any, context: any, cardOf?: (id: string) => Promise<{ card?: any; access?: string }>) {
232
+ const id = typeof args?.id === 'string' ? args.id.trim().replace(/^dashboard-card:/, '') : ''
233
+ if (!id) return { rejected: true, error: 'no-id', message: 'give the card id the person picked.' }
234
+ const found = await (cardOf ?? usableInDomain(context))(id)
235
+ if (!found?.card) return { rejected: true, error: 'unknown-card', message: 'there is no such card - say so.' }
236
+ if (!found.access) return { rejected: true, error: 'card-not-shared', message: 'this card is not shared with the person - say so.' }
237
+ const { card, access } = found
238
+ return {
239
+ id: card.id,
240
+ name: card.name,
241
+ version: card.version,
242
+ access,
243
+ definition: card.definition,
244
+ message:
245
+ access === 'owner'
246
+ ? `to change it, call ${CARD_TOOL} with the whole changed definition, cardId "${card.id}" and baseVersion ${card.version}.`
247
+ : `the person does not own it - offer a new card (no cardId) made from this definition.`
248
+ }
249
+ }
250
+
251
+ /** A card in the person's domain and how they may use it - loaded late so the rules are tested without a database. */
252
+ const usableInDomain =
253
+ (context: any) =>
254
+ async (id: string): Promise<{ card?: any; access?: string }> => {
255
+ const [{ getRepository }, { DashboardCard, DashboardCardShare }, { cardAccessOf, departmentsOfEmployees }] = await Promise.all([
256
+ import('@things-factory/shell'),
257
+ import('./dashboard-card.js'),
258
+ import('./card-access.js')
259
+ ])
260
+ const domainId = context?.state?.domain?.id
261
+ const card = await getRepository(DashboardCard).findOne({ where: { id, domain: { id: domainId } } as any })
262
+ if (!card) return {}
263
+ const shares = await getRepository(DashboardCardShare).find({ where: { card: { id: card.id } } as any })
264
+ let records: any[] | undefined
265
+ try {
266
+ const answer = await runAsCaller(context)('query { myEmployees { active department { id } } }', {})
267
+ records = answer.errors?.length ? [] : answer.data?.myEmployees
268
+ } catch {
269
+ records = []
270
+ }
271
+ const access = cardAccessOf(card, { userId: context?.state?.user?.id, domainId, departmentIds: departmentsOfEmployees(records) }, shares)
272
+ return { card, access }
273
+ }
274
+
275
+ const readSpec = {
276
+ kind: 'read',
277
+ name: 'readDashboardCard',
278
+ doors: ['Query.dashboardCardRun'],
279
+ description: 'Read a saved dashboard card the person picked - its name, version and definition, never its values - before changing it.',
280
+ schema: { type: 'object', properties: { id: { type: 'string', description: 'The card id the person picked.' } }, required: ['id'] },
281
+ builder: (args: any, context: any) => readDashboardCard(args, context)
282
+ } as ToolSpec
283
+
284
+ export const cardCategory: ToolCategory = {
285
+ name: CARD_CATEGORY,
286
+ description: 'dashboard cards - definitions the person saves and the dashboard draws from the data',
287
+ guidance: [
288
+ `- When the person asks for a card, a tile, a chart or a table on their dashboard (대시보드 카드, 카드로 만들어 줘), read the data with its read tool to learn its columns, then call ${CARD_TOOL} in the same turn. Never ask whether to make or save it; the card is the answer.`,
289
+ `- A card is drawn later from the data as whoever opens it - you are not there. Put periods as relative values in source.where, never today's dates; say "this month" as this-month-start / this-month-end.`,
290
+ `- "Top N" is rows.sortBy the amount, desc: true, limit N. Counting customers, places or months (상위 5곳, 거래처별, 월별) is rows.groupBy that column with view.values - each name one bar. Amounts in two currencies are never added - group or match by the currency, or use a column already in won.`,
291
+ `- When ${CARD_TOOL} refuses, fix the definition from what it returns and call again in the same turn; if the data cannot be drawn this way, say so in one line.`,
292
+ `- When the person picked a dashboard card to change (its id after [keys] dashboardCards), call readDashboardCard, then ${CARD_TOOL} with the whole changed definition, cardId and baseVersion - in the same turn. When the change makes its name untrue (top 5 → top 10), give it a true name.`
293
+ ].join('\n'),
294
+ specs: [spec, readSpec]
295
+ }
296
+
297
+ registerToolCategory(cardCategory)
298
+ /* In reach of every conversation, in front on the dashboard page only (ADR-0061 decision 9). */
299
+ registerConversationCategory({ name: CARD_CATEGORY, frontPages: [DASHBOARD_PAGE] })
@@ -0,0 +1,145 @@
1
+ import { Field, ID, InputType, Int, ObjectType } from 'type-graphql'
2
+ import { GraphQLJSON } from 'graphql-scalars'
3
+
4
+ import { DashboardCardShareScope } from './dashboard-card.js'
5
+
6
+ @ObjectType({ description: 'Who a card is shared with, as its owner sees it.' })
7
+ export class DashboardCardShareItem {
8
+ @Field(type => DashboardCardShareScope, { description: 'A person, a department or the domain.' })
9
+ scope: DashboardCardShareScope
10
+
11
+ @Field({ description: 'The user, department or domain id.' })
12
+ targetId: string
13
+
14
+ @Field({ nullable: true, description: 'Its name when it was shared.' })
15
+ targetName?: string
16
+ }
17
+
18
+ @ObjectType({ description: 'A dashboard card as the viewer may use it.' })
19
+ export class DashboardCardItem {
20
+ @Field(type => ID, { description: 'Card id.' })
21
+ id: string
22
+
23
+ @Field({ description: 'The card name.' })
24
+ name: string
25
+
26
+ @Field({ nullable: true, description: 'What it shows, in a line.' })
27
+ description?: string
28
+
29
+ @Field(type => Int, { description: 'The current version.' })
30
+ version: number
31
+
32
+ @Field(type => GraphQLJSON, { description: 'The current definition.' })
33
+ definition: unknown
34
+
35
+ @Field({ description: "'owner' when the viewer made it, 'shared' when it was shared with them." })
36
+ access: string
37
+
38
+ @Field({ nullable: true, description: 'Who made it.' })
39
+ ownerName?: string
40
+
41
+ @Field({ nullable: true, description: 'The card it was copied from.' })
42
+ copiedFromId?: string
43
+
44
+ @Field({ description: 'Whether the viewer has placed it on their dashboard.' })
45
+ placed: boolean
46
+
47
+ @Field(type => [DashboardCardShareItem], { nullable: true, description: 'Who it is shared with - its owner only.' })
48
+ shares?: DashboardCardShareItem[]
49
+
50
+ @Field({ nullable: true, description: 'When it was changed last.' })
51
+ updatedAt?: Date
52
+ }
53
+
54
+ @ObjectType({ description: 'One card placed on the viewer\'s dashboard.' })
55
+ export class DashboardPlaceItem {
56
+ @Field(type => ID, { description: 'Place id.' })
57
+ id: string
58
+
59
+ @Field(type => Int, { description: 'Its order in the grid.' })
60
+ order: number
61
+
62
+ @Field(type => Int, { description: 'Columns it spans, 1 to 4.' })
63
+ width: number
64
+
65
+ @Field(type => Int, { description: 'Rows it spans, 1 to 2.' })
66
+ height: number
67
+
68
+ @Field(type => DashboardCardItem, { description: 'The card.' })
69
+ card: DashboardCardItem
70
+ }
71
+
72
+ @ObjectType({ description: 'A version of a card, as its owner sees it.' })
73
+ export class DashboardCardVersionItem {
74
+ @Field(type => Int, { description: 'The version number.' })
75
+ version: number
76
+
77
+ @Field({ description: 'The name in this version.' })
78
+ name: string
79
+
80
+ @Field(type => GraphQLJSON, { description: 'The definition in this version.' })
81
+ definition: unknown
82
+
83
+ @Field({ nullable: true, description: 'Who saved it.' })
84
+ creatorName?: string
85
+
86
+ @Field({ nullable: true, description: 'When it was saved.' })
87
+ createdAt?: Date
88
+ }
89
+
90
+ @ObjectType({ description: 'A department or person a card may be shared with.' })
91
+ export class DashboardShareChoice {
92
+ @Field({ description: 'The department id, or the user id of a person.' })
93
+ id: string
94
+
95
+ @Field({ description: 'The name.' })
96
+ name: string
97
+
98
+ @Field({ nullable: true, description: 'Where the person works.' })
99
+ note?: string
100
+ }
101
+
102
+ @ObjectType({ description: 'What a card may be shared with by the viewer.' })
103
+ export class DashboardShareOptions {
104
+ @Field({ description: 'The domain - the whole-domain share names it.' })
105
+ domainId: string
106
+
107
+ @Field({ description: 'The domain name.' })
108
+ domainName: string
109
+
110
+ @Field({ description: 'Whether departments are known here (the organization module).' })
111
+ departmentsAvailable: boolean
112
+
113
+ @Field(type => [DashboardShareChoice], { description: "The viewer's own departments." })
114
+ departments: DashboardShareChoice[]
115
+
116
+ @Field({ description: 'Whether the viewer may look people up to share with them.' })
117
+ peopleAvailable: boolean
118
+ }
119
+
120
+ @InputType({ description: 'One share of a card.' })
121
+ export class DashboardCardShareInput {
122
+ @Field(type => DashboardCardShareScope, { description: 'A person, a department or the domain.' })
123
+ scope: DashboardCardShareScope
124
+
125
+ @Field({ description: 'The user, department or domain id.' })
126
+ targetId: string
127
+
128
+ @Field({ nullable: true, description: 'Its name, shown to the owner.' })
129
+ targetName?: string
130
+ }
131
+
132
+ @InputType({ description: 'Where one placed card goes.' })
133
+ export class DashboardPlaceInput {
134
+ @Field(type => ID, { description: 'Place id.' })
135
+ id: string
136
+
137
+ @Field(type => Int, { description: 'Its order.' })
138
+ order: number
139
+
140
+ @Field(type => Int, { description: 'Columns, 1 to 4.' })
141
+ width: number
142
+
143
+ @Field(type => Int, { description: 'Rows, 1 to 2.' })
144
+ height: number
145
+ }