@kernhq/module-inventory 0.1.2 → 0.3.0

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 (213) hide show
  1. package/README.md +134 -9
  2. package/dist/contract/capabilities.d.ts +49 -0
  3. package/dist/contract/capabilities.d.ts.map +1 -0
  4. package/dist/contract/capabilities.js +94 -0
  5. package/dist/contract/capabilities.js.map +1 -0
  6. package/dist/contract/events.d.ts +76 -0
  7. package/dist/contract/events.d.ts.map +1 -0
  8. package/dist/contract/events.js +62 -0
  9. package/dist/contract/events.js.map +1 -0
  10. package/dist/contract/index.d.ts +16 -0
  11. package/dist/contract/index.d.ts.map +1 -0
  12. package/dist/contract/index.js +16 -0
  13. package/dist/contract/index.js.map +1 -0
  14. package/dist/contract/models.d.ts +468 -0
  15. package/dist/contract/models.d.ts.map +1 -0
  16. package/dist/contract/models.js +320 -0
  17. package/dist/contract/models.js.map +1 -0
  18. package/dist/contract/notifications.d.ts +24 -0
  19. package/dist/contract/notifications.d.ts.map +1 -0
  20. package/dist/contract/notifications.js +72 -0
  21. package/dist/contract/notifications.js.map +1 -0
  22. package/dist/contract/permissions.d.ts +72 -0
  23. package/dist/contract/permissions.d.ts.map +1 -0
  24. package/dist/contract/permissions.js +79 -0
  25. package/dist/contract/permissions.js.map +1 -0
  26. package/dist/contract/router.d.ts +1378 -0
  27. package/dist/contract/router.d.ts.map +1 -0
  28. package/dist/contract/router.js +266 -0
  29. package/dist/contract/router.js.map +1 -0
  30. package/dist/contract/settings.d.ts +20 -0
  31. package/dist/contract/settings.d.ts.map +1 -0
  32. package/dist/contract/settings.js +49 -0
  33. package/dist/contract/settings.js.map +1 -0
  34. package/dist/server/index.d.ts +8 -1
  35. package/dist/server/index.d.ts.map +1 -1
  36. package/dist/server/index.js +288 -8
  37. package/dist/server/index.js.map +1 -1
  38. package/dist/server/jobs.d.ts +48 -0
  39. package/dist/server/jobs.d.ts.map +1 -0
  40. package/dist/server/jobs.js +358 -0
  41. package/dist/server/jobs.js.map +1 -0
  42. package/dist/server/router.d.ts +1789 -0
  43. package/dist/server/router.d.ts.map +1 -0
  44. package/dist/server/router.js +439 -0
  45. package/dist/server/router.js.map +1 -0
  46. package/dist/server/schema.d.ts +156 -9
  47. package/dist/server/schema.d.ts.map +1 -1
  48. package/dist/server/schema.js +183 -11
  49. package/dist/server/schema.js.map +1 -1
  50. package/dist/server/services/assets.d.ts +139 -0
  51. package/dist/server/services/assets.d.ts.map +1 -0
  52. package/dist/server/services/assets.js +429 -0
  53. package/dist/server/services/assets.js.map +1 -0
  54. package/dist/server/services/attachments.d.ts +80 -0
  55. package/dist/server/services/attachments.d.ts.map +1 -0
  56. package/dist/server/services/attachments.js +182 -0
  57. package/dist/server/services/attachments.js.map +1 -0
  58. package/dist/server/services/audience.d.ts +15 -0
  59. package/dist/server/services/audience.d.ts.map +1 -0
  60. package/dist/server/services/audience.js +64 -0
  61. package/dist/server/services/audience.js.map +1 -0
  62. package/dist/server/services/categories.d.ts +57 -0
  63. package/dist/server/services/categories.d.ts.map +1 -0
  64. package/dist/server/services/categories.js +124 -0
  65. package/dist/server/services/categories.js.map +1 -0
  66. package/dist/server/services/cursor.d.ts +68 -0
  67. package/dist/server/services/cursor.d.ts.map +1 -0
  68. package/dist/server/services/cursor.js +39 -0
  69. package/dist/server/services/cursor.js.map +1 -0
  70. package/dist/server/services/custody.d.ts +175 -0
  71. package/dist/server/services/custody.d.ts.map +1 -0
  72. package/dist/server/services/custody.js +367 -0
  73. package/dist/server/services/custody.js.map +1 -0
  74. package/dist/server/services/db-errors.d.ts +7 -0
  75. package/dist/server/services/db-errors.d.ts.map +1 -0
  76. package/dist/server/services/db-errors.js +32 -0
  77. package/dist/server/services/db-errors.js.map +1 -0
  78. package/dist/server/services/index.d.ts +26 -0
  79. package/dist/server/services/index.d.ts.map +1 -0
  80. package/dist/server/services/index.js +39 -0
  81. package/dist/server/services/index.js.map +1 -0
  82. package/dist/server/services/members.d.ts +27 -0
  83. package/dist/server/services/members.d.ts.map +1 -0
  84. package/dist/server/services/members.js +39 -0
  85. package/dist/server/services/members.js.map +1 -0
  86. package/dist/server/services/notify.d.ts +105 -0
  87. package/dist/server/services/notify.d.ts.map +1 -0
  88. package/dist/server/services/notify.js +147 -0
  89. package/dist/server/services/notify.js.map +1 -0
  90. package/dist/server/services/offboarding.d.ts +70 -0
  91. package/dist/server/services/offboarding.d.ts.map +1 -0
  92. package/dist/server/services/offboarding.js +116 -0
  93. package/dist/server/services/offboarding.js.map +1 -0
  94. package/dist/server/services/repairs.d.ts +204 -0
  95. package/dist/server/services/repairs.d.ts.map +1 -0
  96. package/dist/server/services/repairs.js +476 -0
  97. package/dist/server/services/repairs.js.map +1 -0
  98. package/dist/server/services/search.d.ts +85 -0
  99. package/dist/server/services/search.d.ts.map +1 -0
  100. package/dist/server/services/search.js +142 -0
  101. package/dist/server/services/search.js.map +1 -0
  102. package/dist/server/services/stats.d.ts +42 -0
  103. package/dist/server/services/stats.d.ts.map +1 -0
  104. package/dist/server/services/stats.js +80 -0
  105. package/dist/server/services/stats.js.map +1 -0
  106. package/dist/server/services/status.d.ts +102 -0
  107. package/dist/server/services/status.d.ts.map +1 -0
  108. package/dist/server/services/status.js +71 -0
  109. package/dist/server/services/status.js.map +1 -0
  110. package/migrations/0000_init.sql +12 -3
  111. package/migrations/0001_rls.sql +24 -0
  112. package/migrations/0002_custody_and_categories.sql +23 -0
  113. package/migrations/0003_repairs.sql +23 -0
  114. package/migrations/0004_platform_surfaces.sql +51 -0
  115. package/migrations/0005_repair_dates.sql +35 -0
  116. package/migrations/0006_workspace_registry_read.sql +50 -0
  117. package/migrations/0007_history_sequence.sql +83 -0
  118. package/migrations/meta/0000_snapshot.json +40 -13
  119. package/migrations/meta/0002_snapshot.json +1054 -0
  120. package/migrations/meta/0003_snapshot.json +1070 -0
  121. package/migrations/meta/0004_snapshot.json +1130 -0
  122. package/migrations/meta/0005_snapshot.json +1135 -0
  123. package/migrations/meta/_journal.json +44 -2
  124. package/package.json +5 -4
  125. package/src/client/api-instance.ts +27 -2
  126. package/src/client/api.ts +1 -1
  127. package/src/client/bidi.test.ts +148 -0
  128. package/src/client/bidi.ts +85 -0
  129. package/src/client/components/AssetDetailPanel.svelte +614 -0
  130. package/src/client/components/AssetFormDialog.svelte +191 -59
  131. package/src/client/components/AssetPhoto.svelte +178 -0
  132. package/src/client/components/AttachmentsSection.svelte +327 -0
  133. package/src/client/components/CustodyDialog.svelte +201 -0
  134. package/src/client/components/RepairDialog.svelte +271 -0
  135. package/src/client/components/RepairsSection.svelte +318 -0
  136. package/src/client/components/Timeline.svelte +347 -0
  137. package/src/client/components/TimelineText.svelte +124 -0
  138. package/src/client/core-api.ts +71 -0
  139. package/src/client/custody.test.ts +31 -0
  140. package/src/client/custody.ts +34 -0
  141. package/src/client/errors.test.ts +365 -0
  142. package/src/client/errors.ts +201 -0
  143. package/src/client/i18n.ts +11 -166
  144. package/src/client/index.ts +8 -1
  145. package/src/client/links.test.ts +74 -0
  146. package/src/client/links.ts +44 -0
  147. package/src/client/members.test.ts +132 -0
  148. package/src/client/members.ts +116 -0
  149. package/src/client/messages.test.ts +296 -0
  150. package/src/client/messages.ts +1424 -0
  151. package/src/client/mock.test.ts +555 -0
  152. package/src/client/mock.ts +1261 -52
  153. package/src/client/module.ts +76 -2
  154. package/src/client/pages/AssetsPage.svelte +638 -145
  155. package/src/client/permissions.ts +8 -1
  156. package/src/client/price.test.ts +254 -0
  157. package/src/client/price.ts +279 -0
  158. package/src/client/query.test.ts +58 -0
  159. package/src/client/query.ts +51 -2
  160. package/src/client/repairs.test.ts +38 -0
  161. package/src/client/repairs.ts +38 -0
  162. package/src/client/settings/CategoriesSettings.svelte +421 -0
  163. package/src/client/settings/GeneralSettings.svelte +403 -0
  164. package/src/client/status.ts +29 -0
  165. package/src/client/timeline.test.ts +175 -0
  166. package/src/client/timeline.ts +206 -0
  167. package/src/client/widgets/OverviewWidget.svelte +140 -26
  168. package/src/client/widgets/RepairsWidget.svelte +124 -0
  169. package/src/contract/capabilities.ts +99 -0
  170. package/src/contract/events.ts +83 -0
  171. package/src/contract/index.ts +16 -0
  172. package/src/contract/models.ts +360 -0
  173. package/src/contract/notifications.ts +73 -0
  174. package/src/contract/permissions.ts +79 -0
  175. package/src/contract/router.ts +300 -0
  176. package/src/contract/settings.ts +50 -0
  177. package/src/module.test.ts +330 -7
  178. package/src/server/index.ts +318 -8
  179. package/src/server/inventory.int.test.ts +4374 -0
  180. package/src/server/jobs.ts +444 -0
  181. package/src/server/migrations.test.ts +251 -0
  182. package/src/server/router.ts +574 -0
  183. package/src/server/schema.ts +184 -10
  184. package/src/server/services/assets.ts +528 -0
  185. package/src/server/services/attachments.ts +215 -0
  186. package/src/server/services/audience.ts +77 -0
  187. package/src/server/services/categories.ts +136 -0
  188. package/src/server/services/cursor.ts +104 -0
  189. package/src/server/services/custody.ts +471 -0
  190. package/src/server/services/db-errors.ts +42 -0
  191. package/src/server/services/index.ts +56 -0
  192. package/src/server/services/members.ts +54 -0
  193. package/src/server/services/notify.ts +196 -0
  194. package/src/server/services/offboarding.ts +150 -0
  195. package/src/server/services/repairs.ts +567 -0
  196. package/src/server/services/search.ts +166 -0
  197. package/src/server/services/stats.ts +88 -0
  198. package/src/server/services/status.test.ts +34 -0
  199. package/src/server/services/status.ts +143 -0
  200. package/tsconfig.base.json +22 -0
  201. package/tsconfig.client.json +1 -1
  202. package/tsconfig.json +1 -1
  203. package/vitest.config.ts +18 -3
  204. package/dist/contract.d.ts +0 -387
  205. package/dist/contract.d.ts.map +0 -1
  206. package/dist/contract.js +0 -119
  207. package/dist/contract.js.map +0 -1
  208. package/dist/server/_impl.d.ts +0 -427
  209. package/dist/server/_impl.d.ts.map +0 -1
  210. package/dist/server/_impl.js +0 -204
  211. package/dist/server/_impl.js.map +0 -1
  212. package/src/contract.ts +0 -143
  213. package/src/server/_impl.ts +0 -275
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Which constraint Postgres refused a write with, dug out of what drizzle hands back.
3
+ *
4
+ * A database constraint is only half a feature. `inventory_custody_no_overlap` makes two open
5
+ * custody periods for one asset impossible — but two people pressing *Hand over* on the same laptop
6
+ * at the same instant means the loser is shown drizzle's own text, "Failed query: insert into
7
+ * mod_inventory.custody_periods …", which tells a person nothing they can act on and looks like the
8
+ * product broke rather than like somebody else got there first.
9
+ *
10
+ * So the service catches, asks these two questions, and throws a `KernError.conflict` with a
11
+ * sentence. Reaching through `cause` rather than reading the top frame is the load-bearing part:
12
+ * drizzle wraps the driver's error, and the driver's error is the only object carrying `code` and
13
+ * `constraint`. `src/server/inventory.int.test.ts` walks the same chain for the same reason.
14
+ */
15
+ const MAX_DEPTH = 5;
16
+ function walk(err, read) {
17
+ let cursor = err;
18
+ for (let depth = 0; depth < MAX_DEPTH && cursor; depth++) {
19
+ const found = read(cursor);
20
+ if (found)
21
+ return found;
22
+ cursor = cursor.cause;
23
+ }
24
+ return undefined;
25
+ }
26
+ /** The constraint's name, if a named one refused the write. */
27
+ export const constraintOf = (err) => walk(err, (e) => (typeof e.constraint === 'string' ? e.constraint : undefined));
28
+ /** The SQLSTATE, if one reached us. `23P01` is an exclusion violation, `23505` a unique one. */
29
+ export const sqlStateOf = (err) => walk(err, (e) => (typeof e.code === 'string' && /^[0-9A-Z]{5}$/.test(e.code) ? e.code : undefined));
30
+ /** Did this write lose to `name`, whichever way Postgres reported it? */
31
+ export const violated = (err, name) => constraintOf(err) === name;
32
+ //# sourceMappingURL=db-errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"db-errors.js","sourceRoot":"","sources":["../../../src/server/services/db-errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,MAAM,SAAS,GAAG,CAAC,CAAA;AAQnB,SAAS,IAAI,CAAC,GAAY,EAAE,IAA4C;IACtE,IAAI,MAAM,GAAY,GAAG,CAAA;IACzB,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,SAAS,IAAI,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;QACzD,MAAM,KAAK,GAAG,IAAI,CAAC,MAAqB,CAAC,CAAA;QACzC,IAAI,KAAK;YAAE,OAAO,KAAK,CAAA;QACvB,MAAM,GAAI,MAAsB,CAAC,KAAK,CAAA;IACxC,CAAC;IACD,OAAO,SAAS,CAAA;AAClB,CAAC;AAED,+DAA+D;AAC/D,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,GAAY,EAAsB,EAAE,CAC/D,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAA;AAEjF,gGAAgG;AAChG,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,GAAY,EAAsB,EAAE,CAC7D,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,KAAK,QAAQ,IAAI,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAA;AAErG,yEAAyE;AACzE,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,GAAY,EAAE,IAAY,EAAW,EAAE,CAAC,YAAY,CAAC,GAAG,CAAC,KAAK,IAAI,CAAA"}
@@ -0,0 +1,26 @@
1
+ import type { Kernel } from '@kernhq/kernel';
2
+ import { AssetService } from './assets.js';
3
+ import { AttachmentService } from './attachments.js';
4
+ import { CategoryService } from './categories.js';
5
+ import { CustodyService } from './custody.js';
6
+ import { NotifyService } from './notify.js';
7
+ import { OffboardingService } from './offboarding.js';
8
+ import { RepairService } from './repairs.js';
9
+ import { SearchService } from './search.js';
10
+ import { StatsService } from './stats.js';
11
+ export interface InventoryServices {
12
+ notify: NotifyService;
13
+ assets: AssetService;
14
+ categories: CategoryService;
15
+ custody: CustodyService;
16
+ repairs: RepairService;
17
+ attachments: AttachmentService;
18
+ stats: StatsService;
19
+ /** The workspace-wide index, and the documents behind `inventory:asset:<id>`. */
20
+ search: SearchService;
21
+ /** Somebody left holding company property. Raises a checklist; never moves custody. */
22
+ offboarding: OffboardingService;
23
+ }
24
+ /** One service graph per kernel instance; the router, jobs and procedures all share it. */
25
+ export declare function inventoryServices(kernel: Kernel): InventoryServices;
26
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/server/services/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAEzC,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,aAAa,CAAA;IACrB,MAAM,EAAE,YAAY,CAAA;IACpB,UAAU,EAAE,eAAe,CAAA;IAC3B,OAAO,EAAE,cAAc,CAAA;IACvB,OAAO,EAAE,aAAa,CAAA;IACtB,WAAW,EAAE,iBAAiB,CAAA;IAC9B,KAAK,EAAE,YAAY,CAAA;IACnB,iFAAiF;IACjF,MAAM,EAAE,aAAa,CAAA;IACrB,uFAAuF;IACvF,WAAW,EAAE,kBAAkB,CAAA;CAChC;AAID,2FAA2F;AAC3F,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,iBAAiB,CA2BnE"}
@@ -0,0 +1,39 @@
1
+ import { AssetService } from './assets.js';
2
+ import { AttachmentService } from './attachments.js';
3
+ import { CategoryService } from './categories.js';
4
+ import { CustodyService } from './custody.js';
5
+ import { NotifyService } from './notify.js';
6
+ import { OffboardingService } from './offboarding.js';
7
+ import { RepairService } from './repairs.js';
8
+ import { SearchService } from './search.js';
9
+ import { StatsService } from './stats.js';
10
+ const cache = new WeakMap();
11
+ /** One service graph per kernel instance; the router, jobs and procedures all share it. */
12
+ export function inventoryServices(kernel) {
13
+ const existing = cache.get(kernel);
14
+ if (existing)
15
+ return existing;
16
+ const notify = new NotifyService(kernel);
17
+ const assets = new AssetService(kernel, notify);
18
+ const categories = new CategoryService();
19
+ const custody = new CustodyService(notify);
20
+ const repairs = new RepairService(notify);
21
+ const attachments = new AttachmentService(kernel, notify);
22
+ const stats = new StatsService();
23
+ const search = new SearchService(kernel, notify);
24
+ const offboarding = new OffboardingService(kernel, notify);
25
+ const services = {
26
+ notify,
27
+ assets,
28
+ categories,
29
+ custody,
30
+ repairs,
31
+ attachments,
32
+ stats,
33
+ search,
34
+ offboarding,
35
+ };
36
+ cache.set(kernel, services);
37
+ return services;
38
+ }
39
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/server/services/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAE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@@
1
+ import { type Kernel } from '@kernhq/kernel';
2
+ /**
3
+ * Is this person somebody this workspace can hand a laptop to?
4
+ *
5
+ * **`custody.assign` and `custody.transfer` took any uuid.** The id arrives in the request, nothing
6
+ * looked it up, and the module then wrote it into `custody_periods.user_id` and
7
+ * `assets.custodian_user_id` — the two columns that answer "who is answerable for this" for the rest
8
+ * of the item's life — and sent a notification to it. So a member of one workspace could record a
9
+ * *stranger* as holding company property, and the product would then chase that stranger about it.
10
+ * Every screen renders an id it cannot resolve as "a former member", which is the honest thing for a
11
+ * screen to say and exactly what hides this: the register looks plausible and names nobody real.
12
+ *
13
+ * The check is a question for core, because membership is core's fact and this module has no copy of
14
+ * it. `core.users.principal` answers with one person rather than the workspace's whole roll, which
15
+ * matters on an instance where a workspace has thousands of seats and this runs on every handover.
16
+ *
17
+ * **`active`, not merely present.** An invitation nobody has accepted is not somebody who can be
18
+ * handed a thing, and a suspended account is one the workspace has deliberately shut out.
19
+ *
20
+ * **A failure here refuses rather than waves through.** Every other cross-service call this module
21
+ * makes is best-effort, and this one deliberately is not: swallowing the failure would mean the
22
+ * check silently stops existing exactly while core is unwell, which is indistinguishable from not
23
+ * having written it. `UNAVAILABLE` is 503 and says the true thing — the answer is not knowable right
24
+ * now — where a 400 would tell somebody their colleague is not a member.
25
+ */
26
+ export declare function requireWorkspaceMember(kernel: Kernel, workspaceId: string, userId: string): Promise<void>;
27
+ //# sourceMappingURL=members.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"members.d.ts","sourceRoot":"","sources":["../../../src/server/services/members.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,KAAK,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAEvD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAsB,sBAAsB,CAC1C,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CAsBf"}
@@ -0,0 +1,39 @@
1
+ import { KernError } from '@kernhq/kernel';
2
+ /**
3
+ * Is this person somebody this workspace can hand a laptop to?
4
+ *
5
+ * **`custody.assign` and `custody.transfer` took any uuid.** The id arrives in the request, nothing
6
+ * looked it up, and the module then wrote it into `custody_periods.user_id` and
7
+ * `assets.custodian_user_id` — the two columns that answer "who is answerable for this" for the rest
8
+ * of the item's life — and sent a notification to it. So a member of one workspace could record a
9
+ * *stranger* as holding company property, and the product would then chase that stranger about it.
10
+ * Every screen renders an id it cannot resolve as "a former member", which is the honest thing for a
11
+ * screen to say and exactly what hides this: the register looks plausible and names nobody real.
12
+ *
13
+ * The check is a question for core, because membership is core's fact and this module has no copy of
14
+ * it. `core.users.principal` answers with one person rather than the workspace's whole roll, which
15
+ * matters on an instance where a workspace has thousands of seats and this runs on every handover.
16
+ *
17
+ * **`active`, not merely present.** An invitation nobody has accepted is not somebody who can be
18
+ * handed a thing, and a suspended account is one the workspace has deliberately shut out.
19
+ *
20
+ * **A failure here refuses rather than waves through.** Every other cross-service call this module
21
+ * makes is best-effort, and this one deliberately is not: swallowing the failure would mean the
22
+ * check silently stops existing exactly while core is unwell, which is indistinguishable from not
23
+ * having written it. `UNAVAILABLE` is 503 and says the true thing — the answer is not knowable right
24
+ * now — where a 400 would tell somebody their colleague is not a member.
25
+ */
26
+ export async function requireWorkspaceMember(kernel, workspaceId, userId) {
27
+ let principal;
28
+ try {
29
+ principal = await kernel.call('core.users.principal', { userId });
30
+ }
31
+ catch (err) {
32
+ kernel.log.warn({ err: err instanceof Error ? err.message : String(err), workspaceId }, 'inventory: could not check whether the new custodian is a member');
33
+ throw new KernError('UNAVAILABLE', 'Who belongs to this workspace cannot be checked right now. Try again in a moment.');
34
+ }
35
+ const member = (principal?.memberships ?? []).some((m) => m.workspaceId === workspaceId && m.status === 'active');
36
+ if (!member)
37
+ throw KernError.badRequest('That person is not a member of this workspace, so nothing can be handed to them.');
38
+ }
39
+ //# sourceMappingURL=members.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"members.js","sourceRoot":"","sources":["../../../src/server/services/members.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAe,MAAM,gBAAgB,CAAA;AAEvD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,MAAc,EACd,WAAmB,EACnB,MAAc;IAEd,IAAI,SAA2B,CAAA;IAC/B,IAAI,CAAC;QACH,SAAS,GAAG,MAAM,MAAM,CAAC,IAAI,CAAmB,sBAAsB,EAAE,EAAE,MAAM,EAAE,CAAC,CAAA;IACrF,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,CAAC,GAAG,CAAC,IAAI,CACb,EAAE,GAAG,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,WAAW,EAAE,EACtE,kEAAkE,CACnE,CAAA;QACD,MAAM,IAAI,SAAS,CACjB,aAAa,EACb,mFAAmF,CACpF,CAAA;IACH,CAAC;IAED,MAAM,MAAM,GAAG,CAAC,SAAS,EAAE,WAAW,IAAI,EAAE,CAAC,CAAC,IAAI,CAChD,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,KAAK,WAAW,IAAI,CAAC,CAAC,MAAM,KAAK,QAAQ,CAC9D,CAAA;IACD,IAAI,CAAC,MAAM;QACT,MAAM,SAAS,CAAC,UAAU,CACxB,kFAAkF,CACnF,CAAA;AACL,CAAC"}
@@ -0,0 +1,105 @@
1
+ import type { core, EntityChange, ObjectRef } from '@kernhq/contracts';
2
+ import { type Kernel, type Tx } from '@kernhq/kernel';
3
+ export interface HistoryInput {
4
+ workspaceId: string;
5
+ assetId: string;
6
+ actorId: string | null;
7
+ action: string;
8
+ changes?: Array<{
9
+ field: string;
10
+ from: unknown;
11
+ to: unknown;
12
+ }>;
13
+ data?: Record<string, unknown>;
14
+ }
15
+ export interface NotifyInput {
16
+ workspaceId: string;
17
+ userIds: Iterable<string>;
18
+ type: string;
19
+ title: string;
20
+ body?: string | null;
21
+ object?: ObjectRef | null;
22
+ url?: string | null;
23
+ data?: Record<string, unknown>;
24
+ groupKey?: string | null;
25
+ actorId?: string | null;
26
+ /** never notify the person who caused the change */
27
+ exclude?: Iterable<string | null | undefined>;
28
+ }
29
+ /**
30
+ * Side effects that leave the module: activity, notifications, realtime and the search index.
31
+ *
32
+ * All of them are best-effort. An inventory mutation must not fail because the core service is
33
+ * briefly unavailable, so every cross-module call is swallowed and logged — the local
34
+ * `asset_history` row is written inside the caller's transaction and remains the authoritative
35
+ * record of what happened.
36
+ */
37
+ export declare class NotifyService {
38
+ private readonly kernel;
39
+ constructor(kernel: Kernel);
40
+ private best;
41
+ /**
42
+ * `best`, asked the other question: **did the call actually happen**, rather than what it returned.
43
+ *
44
+ * `best` cannot answer that — a procedure that legitimately answers `null` or `undefined` is
45
+ * indistinguishable from one that threw and was swallowed, and a caller writing "I have told
46
+ * them" into a database on the strength of that is writing a lie. So the value is thrown away
47
+ * here and the boolean is the whole answer.
48
+ */
49
+ private attempted;
50
+ /**
51
+ * Append to the asset's own history, inside the caller's transaction.
52
+ *
53
+ * This row is the authoritative record and belongs in the transaction it describes — if the write
54
+ * rolls back, so does its history. The mirror of it in core's activity feed is `activity()`, and
55
+ * it deliberately does **not** happen here: it used to, fired off with `void` while the
56
+ * transaction was still open, so a rollback left the workspace's feed showing an event for an id
57
+ * that never existed. The caller flushes it after the commit, beside the event and the realtime
58
+ * change, which is what everything else in this module already does.
59
+ */
60
+ history(tx: Tx, input: HistoryInput): Promise<void>;
61
+ /** The workspace-wide activity feed's copy. Best-effort, and only ever after the commit. */
62
+ activity(input: HistoryInput): Promise<void>;
63
+ /**
64
+ * Tell these people, and answer **who it was meant for and how many of them were actually
65
+ * written** — both numbers, because one of them cannot be checked without the other.
66
+ *
67
+ * Everything this class does is best-effort, so a failed `core.notifications.create` is swallowed
68
+ * and logged; a caller that then records "this one has been notified" has recorded something that
69
+ * never happened. The two nightly sweeps write exactly such a marker, once per row for ever, so a
70
+ * swallowed failure there is not a delayed notice but a notice nobody will ever receive.
71
+ *
72
+ * This used to answer a single count, and the sweeps marked the row whenever it was above zero —
73
+ * so a notice that reached one of three recipients was stamped *told*, and the two who missed it
74
+ * never heard. **A partial delivery is a failure for the people it did not reach**, and the row
75
+ * cannot record two answers, so the honest one is the pessimistic one: the sweeps mark nothing
76
+ * unless `delivered === targeted`, and say it again in the morning. The cost is that whoever did
77
+ * hear it hears it twice; `groupKey` collapses that in the notification centre, and it is a
78
+ * strictly smaller price than one person never being told at all.
79
+ *
80
+ * `targeted` is what is left after the de-duplication and the exclusions, which is why the caller
81
+ * cannot work it out from the list it passed in. `targeted: 0` means there was nobody to tell,
82
+ * which is also not "told".
83
+ */
84
+ notify(input: NotifyInput): Promise<{
85
+ targeted: number;
86
+ delivered: number;
87
+ }>;
88
+ /** Realtime cache invalidation for connected clients. */
89
+ change(workspaceId: string, entity: string, id: string, op: EntityChange['op'], opts?: {
90
+ patch?: Record<string, unknown>;
91
+ scope?: Record<string, string>;
92
+ }): Promise<void>;
93
+ /**
94
+ * The workspace-wide search index, written to by `SearchService` and by nothing else.
95
+ *
96
+ * These two spent a release with no caller: `objectTypes` had been taken off the module
97
+ * definition, because a declared type with no indexer and no resolver renders a link to nothing.
98
+ * Both halves exist now — `src/server/services/search.ts` builds the documents, `src/server/
99
+ * index.ts` declares the indexer and the resolver — and every asset mutation reindexes after it
100
+ * has committed.
101
+ */
102
+ index(documents: core.SearchDocument[]): Promise<void>;
103
+ unindex(workspaceId: string, type: string, ids: string[]): Promise<void>;
104
+ }
105
+ //# sourceMappingURL=notify.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"notify.d.ts","sourceRoot":"","sources":["../../../src/server/services/notify.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,mBAA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AAE,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAYzD,4FAA4F;IACtF,QAAQ,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAclD;;;;;;;;;;;;;;;;;;;;OAoBG;IACG,MAAM,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;IA0BlF,yDAAyD;IACnD,MAAM,CACV,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,MAAM,EACd,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,YAAY,CAAC,IAAI,CAAC,EACtB,IAAI,GAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAAO,GAC7E,OAAO,CAAC,IAAI,CAAC;IAahB;;;;;;;;OAQG;IACG,KAAK,CAAC,SAAS,EAAE,IAAI,CAAC,cAAc,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAKtD,OAAO,CAAC,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAQ/E"}
@@ -0,0 +1,147 @@
1
+ import { uuidv7 } from '@kernhq/kernel';
2
+ import { MODULE_ID } from '../../contract/models.js';
3
+ import { assetHistory } from '../schema.js';
4
+ /**
5
+ * Side effects that leave the module: activity, notifications, realtime and the search index.
6
+ *
7
+ * All of them are best-effort. An inventory mutation must not fail because the core service is
8
+ * briefly unavailable, so every cross-module call is swallowed and logged — the local
9
+ * `asset_history` row is written inside the caller's transaction and remains the authoritative
10
+ * record of what happened.
11
+ */
12
+ export class NotifyService {
13
+ kernel;
14
+ constructor(kernel) {
15
+ this.kernel = kernel;
16
+ }
17
+ async best(what, fn) {
18
+ try {
19
+ return await fn();
20
+ }
21
+ catch (err) {
22
+ this.kernel.log.warn({ err: err instanceof Error ? err.message : err, what }, 'inventory side effect failed');
23
+ return null;
24
+ }
25
+ }
26
+ /**
27
+ * `best`, asked the other question: **did the call actually happen**, rather than what it returned.
28
+ *
29
+ * `best` cannot answer that — a procedure that legitimately answers `null` or `undefined` is
30
+ * indistinguishable from one that threw and was swallowed, and a caller writing "I have told
31
+ * them" into a database on the strength of that is writing a lie. So the value is thrown away
32
+ * here and the boolean is the whole answer.
33
+ */
34
+ async attempted(what, fn) {
35
+ return ((await this.best(what, async () => {
36
+ await fn();
37
+ return true;
38
+ })) === true);
39
+ }
40
+ /**
41
+ * Append to the asset's own history, inside the caller's transaction.
42
+ *
43
+ * This row is the authoritative record and belongs in the transaction it describes — if the write
44
+ * rolls back, so does its history. The mirror of it in core's activity feed is `activity()`, and
45
+ * it deliberately does **not** happen here: it used to, fired off with `void` while the
46
+ * transaction was still open, so a rollback left the workspace's feed showing an event for an id
47
+ * that never existed. The caller flushes it after the commit, beside the event and the realtime
48
+ * change, which is what everything else in this module already does.
49
+ */
50
+ async history(tx, input) {
51
+ await tx.insert(assetHistory).values({
52
+ id: uuidv7(),
53
+ workspaceId: input.workspaceId,
54
+ assetId: input.assetId,
55
+ actorId: input.actorId,
56
+ action: input.action,
57
+ changes: input.changes ?? [],
58
+ data: input.data ?? {},
59
+ });
60
+ }
61
+ /** The workspace-wide activity feed's copy. Best-effort, and only ever after the commit. */
62
+ async activity(input) {
63
+ await this.best('activity.record', () => this.kernel.call('core.activity.record', {
64
+ workspaceId: input.workspaceId,
65
+ module: MODULE_ID,
66
+ object: { module: MODULE_ID, type: 'asset', id: input.assetId },
67
+ action: input.action,
68
+ actorId: input.actorId,
69
+ changes: input.changes ?? [],
70
+ data: input.data ?? {},
71
+ }));
72
+ }
73
+ /**
74
+ * Tell these people, and answer **who it was meant for and how many of them were actually
75
+ * written** — both numbers, because one of them cannot be checked without the other.
76
+ *
77
+ * Everything this class does is best-effort, so a failed `core.notifications.create` is swallowed
78
+ * and logged; a caller that then records "this one has been notified" has recorded something that
79
+ * never happened. The two nightly sweeps write exactly such a marker, once per row for ever, so a
80
+ * swallowed failure there is not a delayed notice but a notice nobody will ever receive.
81
+ *
82
+ * This used to answer a single count, and the sweeps marked the row whenever it was above zero —
83
+ * so a notice that reached one of three recipients was stamped *told*, and the two who missed it
84
+ * never heard. **A partial delivery is a failure for the people it did not reach**, and the row
85
+ * cannot record two answers, so the honest one is the pessimistic one: the sweeps mark nothing
86
+ * unless `delivered === targeted`, and say it again in the morning. The cost is that whoever did
87
+ * hear it hears it twice; `groupKey` collapses that in the notification centre, and it is a
88
+ * strictly smaller price than one person never being told at all.
89
+ *
90
+ * `targeted` is what is left after the de-duplication and the exclusions, which is why the caller
91
+ * cannot work it out from the list it passed in. `targeted: 0` means there was nobody to tell,
92
+ * which is also not "told".
93
+ */
94
+ async notify(input) {
95
+ const excluded = new Set([...(input.exclude ?? [])].filter(Boolean));
96
+ const targets = [...new Set(input.userIds)].filter((id) => id && !excluded.has(id));
97
+ if (!targets.length)
98
+ return { targeted: 0, delivered: 0 };
99
+ const written = await Promise.all(targets.map((userId) => this.attempted('notifications.create', () => this.kernel.call('core.notifications.create', {
100
+ userId,
101
+ workspaceId: input.workspaceId,
102
+ module: MODULE_ID,
103
+ type: input.type,
104
+ title: input.title,
105
+ body: input.body ?? null,
106
+ object: input.object ?? null,
107
+ url: input.url ?? null,
108
+ data: input.data ?? {},
109
+ groupKey: input.groupKey ?? null,
110
+ actorId: input.actorId ?? null,
111
+ }))));
112
+ return { targeted: targets.length, delivered: written.filter(Boolean).length };
113
+ }
114
+ /** Realtime cache invalidation for connected clients. */
115
+ async change(workspaceId, entity, id, op, opts = {}) {
116
+ await this.best('realtime.change', () => this.kernel.realtime.change(workspaceId, {
117
+ module: MODULE_ID,
118
+ entity,
119
+ id,
120
+ op,
121
+ ...(opts.patch ? { patch: opts.patch } : {}),
122
+ ...(opts.scope ? { scope: opts.scope } : {}),
123
+ }));
124
+ }
125
+ /**
126
+ * The workspace-wide search index, written to by `SearchService` and by nothing else.
127
+ *
128
+ * These two spent a release with no caller: `objectTypes` had been taken off the module
129
+ * definition, because a declared type with no indexer and no resolver renders a link to nothing.
130
+ * Both halves exist now — `src/server/services/search.ts` builds the documents, `src/server/
131
+ * index.ts` declares the indexer and the resolver — and every asset mutation reindexes after it
132
+ * has committed.
133
+ */
134
+ async index(documents) {
135
+ if (!documents.length)
136
+ return;
137
+ await this.best('search.index', () => this.kernel.call('core.search.index', { documents }));
138
+ }
139
+ async unindex(workspaceId, type, ids) {
140
+ if (!ids.length)
141
+ return;
142
+ await this.best('search.remove', () => this.kernel.call('core.search.remove', {
143
+ refs: ids.map((id) => ({ workspaceId, object: { module: MODULE_ID, type, id } })),
144
+ }));
145
+ }
146
+ }
147
+ //# sourceMappingURL=notify.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"notify.js","sourceRoot":"","sources":["../../../src/server/services/notify.ts"],"names":[],"mappings":"AACA,OAAO,EAAwB,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AA0B3C;;;;;;;GAOG;AACH,MAAM,OAAO,aAAa;IACK;IAA7B,YAA6B,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;IAAG,CAAC;IAEvC,KAAK,CAAC,IAAI,CAAI,IAAY,EAAE,EAAoB;QACtD,IAAI,CAAC;YACH,OAAO,MAAM,EAAE,EAAE,CAAA;QACnB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAClB,EAAE,GAAG,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,EACv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IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,oBAAoB,EAAE;YACrC,IAAI,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,WAAW,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;SAClF,CAAC,CACH,CAAA;IACH,CAAC;CACF"}
@@ -0,0 +1,70 @@
1
+ import type { Kernel } from '@kernhq/kernel';
2
+ import type { NotifyService } from './notify.js';
3
+ /** Why the checklist is being raised, which is the only difference between the two callers. */
4
+ export type Departure =
5
+ /** `core.member.removed` — the account is out of the workspace already. */
6
+ 'removed'
7
+ /** `hr.person.status_changed` to a status that ends employment — they may still be at their desk. */
8
+ | 'leaving';
9
+ export interface ReturnList {
10
+ items: Array<{
11
+ id: string;
12
+ code: string;
13
+ name: string;
14
+ }>;
15
+ /** Who was told. Empty when there was nothing to return, or nobody who could act on it. */
16
+ recipients: string[];
17
+ }
18
+ /**
19
+ * Somebody is leaving, and the register still says things are theirs.
20
+ *
21
+ * **This raises a checklist and notifies. It never moves anything.** Custody changes because a
22
+ * person did something — handed an item over, handed it on, took it back — and every one of those
23
+ * writes a period row and a line of history saying who did it. A hook that quietly returned an
24
+ * item on somebody's last day would write a handover nobody performed, into the one record the
25
+ * company later argues from; and the laptop would still be in their bag. So the answer is a message
26
+ * to the people who can take it back, and the register stays exactly as true as it was.
27
+ *
28
+ * **It is inert without HR.** Nothing here imports HR, depends on it, or assumes it is installed:
29
+ * `hr.person.status_changed` simply never arrives in a workspace that has no HR, and the second
30
+ * caller — `core.member.removed` — is core's own event and needs nothing at all. Both paths check
31
+ * the *inventory* module is switched on for the workspace before doing anything, because an event
32
+ * bus is instance-wide and a workspace that has never enabled this module must not be sent its
33
+ * notifications.
34
+ */
35
+ export declare class OffboardingService {
36
+ private readonly kernel;
37
+ private readonly notify;
38
+ constructor(kernel: Kernel, notify: NotifyService);
39
+ /**
40
+ * What one person is still recorded as holding.
41
+ *
42
+ * Read from `assets.custodian_user_id` — denormalised inside the transaction that writes the
43
+ * custody period, and indexed — rather than from an open-period join, which is the same choice
44
+ * `custody.byUser` makes and for the same reason. Archived rows cannot appear: an item somebody
45
+ * holds cannot be archived at all, because `assets.archive` refuses it.
46
+ */
47
+ held(workspaceId: string, userId: string): Promise<ReturnList['items']>;
48
+ /**
49
+ * Raise the return list, if there is one.
50
+ *
51
+ * Answers with what it found and who it told, so a test can assert both and a caller can log the
52
+ * count. Doing nothing is the ordinary case — most people leave holding nothing — and it is not
53
+ * an error.
54
+ *
55
+ * Redelivery sends the same message again: an event handler is retried, and `core.notifications
56
+ * .create` has no idempotency key. The two events behind this are rare enough that the cost is a
57
+ * duplicate row rather than a stream, and `groupKey` collapses them where a client groups. That
58
+ * is the same trade `module-tracker`'s `due-soon` makes, written down rather than assumed.
59
+ */
60
+ raise(workspaceId: string, userId: string, departure: Departure): Promise<ReturnList>;
61
+ /**
62
+ * What to call the person in the sentence.
63
+ *
64
+ * Core is asked, and a failure falls back to "a former member" rather than to the uuid: a
65
+ * notification with a uuid in the middle of it is the product admitting it does not know who it
66
+ * is talking about, and this module already refuses to print one on a screen for the same reason.
67
+ */
68
+ private nameOf;
69
+ }
70
+ //# sourceMappingURL=offboarding.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"offboarding.d.ts","sourceRoot":"","sources":["../../../src/server/services/offboarding.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAK5C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAYhD,+FAA+F;AAC/F,MAAM,MAAM,SAAS;AACnB,2EAA2E;AACzE,SAAS;AACX,qGAAqG;GACnG,SAAS,CAAA;AAEb,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;IACxD,2FAA2F;IAC3F,UAAU,EAAE,MAAM,EAAE,CAAA;CACrB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,kBAAkB;IAE3B,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBADN,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,aAAa;IAGxC;;;;;;;OAOG;IACG,IAAI,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IAiB7E;;;;;;;;;;;OAWG;IACG,KAAK,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC;IA8C3F;;;;;;OAMG;YACW,MAAM;CAMrB"}