@hattoriai/poney-ext-security 0.0.0-stage → 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Rui Freitas
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,12 @@
1
- # Temporary Holding Version
1
+ # @hattoriai/poney-ext-security
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A Poney extension: trust zones (`security/zone`), sensitive data classes on data types (personal, secret, payment, health), and how each connection is protected (encryption, authentication). Its lints warn where sensitive data crosses a zone unprotected.
4
+
5
+ ```ts
6
+ import { security } from '@hattoriai/poney-ext-security'
7
+ import { checkDocument } from '@hattoriai/poney-core'
8
+
9
+ checkDocument(doc, { extensions: [security] }).warnings
10
+ ```
11
+
12
+ Part of [Poney](https://github.com/hattoriai/poney): the format, the renderers, and tools to explain software. MIT licensed.
@@ -0,0 +1,1094 @@
1
+ import * as _hattoriai_poney_core from '@hattoriai/poney-core';
2
+ import { Relationship, Entity, DataType, PoneyDocument } from '@hattoriai/poney-core';
3
+ import { z } from 'zod';
4
+
5
+ /**
6
+ * The security extension: where trust ends, which data is sensitive, and how
7
+ * each connection is protected.
8
+ *
9
+ * It adds:
10
+ * - an entity kind, "security/zone": a trust zone. Inside a zone, parts trust
11
+ * each other; a line between zones crosses a boundary;
12
+ * - facets: an entity's zone, a data type's classes (personal, secret,
13
+ * payment, health), and a relationship's protection (encryption, auth);
14
+ * - lints that read those together, e.g. "personal data leaves a zone
15
+ * without encryption".
16
+ *
17
+ * A part without a zone takes the zone of its parent. Zones are drawn with
18
+ * the core views (an architecture view's groups); the extension adds no view
19
+ * type of its own.
20
+ */
21
+ /** Classes of sensitive data. */
22
+ declare const DataClass: z.ZodEnum<["personal", "secret", "payment", "health"]>;
23
+ type DataClass = z.infer<typeof DataClass>;
24
+ declare const CLASS_LABEL: Record<DataClass, string>;
25
+ /** How much a zone is trusted: public (anyone can reach it), internal, restricted. */
26
+ declare const Trust: z.ZodEnum<["public", "internal", "restricted"]>;
27
+ type Trust = z.infer<typeof Trust>;
28
+ declare const EntityFacet: z.ZodObject<{
29
+ /** The trust zone this part runs in: an entity of kind "security/zone". */
30
+ zone: z.ZodOptional<z.ZodString>;
31
+ /** For zones: how much the zone is trusted. */
32
+ trust: z.ZodOptional<z.ZodEnum<["public", "internal", "restricted"]>>;
33
+ }, "strict", z.ZodTypeAny, {
34
+ zone?: string | undefined;
35
+ trust?: "public" | "internal" | "restricted" | undefined;
36
+ }, {
37
+ zone?: string | undefined;
38
+ trust?: "public" | "internal" | "restricted" | undefined;
39
+ }>;
40
+ type EntityFacet = z.infer<typeof EntityFacet>;
41
+ declare const DataTypeFacet: z.ZodObject<{
42
+ /** What kind of sensitive data this type holds. */
43
+ classes: z.ZodArray<z.ZodEnum<["personal", "secret", "payment", "health"]>, "many">;
44
+ }, "strict", z.ZodTypeAny, {
45
+ classes: ("personal" | "secret" | "payment" | "health")[];
46
+ }, {
47
+ classes: ("personal" | "secret" | "payment" | "health")[];
48
+ }>;
49
+ type DataTypeFacet = z.infer<typeof DataTypeFacet>;
50
+ declare const RelationshipFacet: z.ZodObject<{
51
+ /** The data is encrypted in transit (TLS counts). */
52
+ encrypted: z.ZodOptional<z.ZodBoolean>;
53
+ /** How the caller proves who it is, e.g. "mTLS", "OAuth token", "session cookie", or "none". */
54
+ auth: z.ZodOptional<z.ZodString>;
55
+ }, "strict", z.ZodTypeAny, {
56
+ encrypted?: boolean | undefined;
57
+ auth?: string | undefined;
58
+ }, {
59
+ encrypted?: boolean | undefined;
60
+ auth?: string | undefined;
61
+ }>;
62
+ type RelationshipFacet = z.infer<typeof RelationshipFacet>;
63
+ declare const ZONE_KIND = "security/zone";
64
+ declare const security: {
65
+ readonly name: "security";
66
+ readonly version: "0.1.0";
67
+ readonly description: "Trust zones, sensitive data, and how connections are protected.";
68
+ readonly entityKinds: {
69
+ readonly zone: {
70
+ readonly label: "Trust zone";
71
+ readonly description: "Where parts trust each other. A line between zones crosses a trust boundary.";
72
+ };
73
+ };
74
+ readonly facets: {
75
+ readonly entity: z.ZodObject<{
76
+ /** The trust zone this part runs in: an entity of kind "security/zone". */
77
+ zone: z.ZodOptional<z.ZodString>;
78
+ /** For zones: how much the zone is trusted. */
79
+ trust: z.ZodOptional<z.ZodEnum<["public", "internal", "restricted"]>>;
80
+ }, "strict", z.ZodTypeAny, {
81
+ zone?: string | undefined;
82
+ trust?: "public" | "internal" | "restricted" | undefined;
83
+ }, {
84
+ zone?: string | undefined;
85
+ trust?: "public" | "internal" | "restricted" | undefined;
86
+ }>;
87
+ readonly dataType: z.ZodObject<{
88
+ /** What kind of sensitive data this type holds. */
89
+ classes: z.ZodArray<z.ZodEnum<["personal", "secret", "payment", "health"]>, "many">;
90
+ }, "strict", z.ZodTypeAny, {
91
+ classes: ("personal" | "secret" | "payment" | "health")[];
92
+ }, {
93
+ classes: ("personal" | "secret" | "payment" | "health")[];
94
+ }>;
95
+ readonly relationship: z.ZodObject<{
96
+ /** The data is encrypted in transit (TLS counts). */
97
+ encrypted: z.ZodOptional<z.ZodBoolean>;
98
+ /** How the caller proves who it is, e.g. "mTLS", "OAuth token", "session cookie", or "none". */
99
+ auth: z.ZodOptional<z.ZodString>;
100
+ }, "strict", z.ZodTypeAny, {
101
+ encrypted?: boolean | undefined;
102
+ auth?: string | undefined;
103
+ }, {
104
+ encrypted?: boolean | undefined;
105
+ auth?: string | undefined;
106
+ }>;
107
+ };
108
+ readonly validate: (doc: {
109
+ views: ({
110
+ type: "architecture";
111
+ id: string;
112
+ description: string;
113
+ ext: Record<string, unknown>;
114
+ entities: string[];
115
+ title: string;
116
+ category: string;
117
+ positions: Record<string, {
118
+ x: number;
119
+ y: number;
120
+ }>;
121
+ groups: {
122
+ id: string;
123
+ label: string;
124
+ members: string[];
125
+ description?: string | undefined;
126
+ }[];
127
+ collapsed: string[];
128
+ layout: {
129
+ direction: "right" | "down";
130
+ };
131
+ relationships?: string[] | undefined;
132
+ } | {
133
+ type: "map";
134
+ id: string;
135
+ description: string;
136
+ ext: Record<string, unknown>;
137
+ entities: string[];
138
+ title: string;
139
+ category: string;
140
+ positions: Record<string, {
141
+ x: number;
142
+ y: number;
143
+ }>;
144
+ collapsed: string[];
145
+ layout: {
146
+ direction: "right" | "down";
147
+ };
148
+ passThrough: string[];
149
+ relationships?: string[] | undefined;
150
+ } | {
151
+ type: "sequence";
152
+ id: string;
153
+ description: string;
154
+ ext: Record<string, unknown>;
155
+ interaction: string;
156
+ title: string;
157
+ category: string;
158
+ positions: Record<string, {
159
+ x: number;
160
+ y: number;
161
+ }>;
162
+ } | {
163
+ type: "dataflow";
164
+ id: string;
165
+ description: string;
166
+ ext: Record<string, unknown>;
167
+ flows: string[];
168
+ title: string;
169
+ category: string;
170
+ positions: Record<string, {
171
+ x: number;
172
+ y: number;
173
+ }>;
174
+ showControlFlow: boolean;
175
+ } | {
176
+ type: "activity";
177
+ id: string;
178
+ description: string;
179
+ ext: Record<string, unknown>;
180
+ process: string;
181
+ title: string;
182
+ category: string;
183
+ positions: Record<string, {
184
+ x: number;
185
+ y: number;
186
+ }>;
187
+ swimlanes: boolean;
188
+ } | {
189
+ type: "erd";
190
+ id: string;
191
+ description: string;
192
+ ext: Record<string, unknown>;
193
+ dataTypes: string[];
194
+ title: string;
195
+ category: string;
196
+ positions: Record<string, {
197
+ x: number;
198
+ y: number;
199
+ }>;
200
+ groupByStore: boolean;
201
+ fieldLimit: number;
202
+ } | {
203
+ type: "state";
204
+ id: string;
205
+ description: string;
206
+ ext: Record<string, unknown>;
207
+ title: string;
208
+ category: string;
209
+ positions: Record<string, {
210
+ x: number;
211
+ y: number;
212
+ }>;
213
+ stateMachine: string;
214
+ } | {
215
+ type: "usecase";
216
+ id: string;
217
+ description: string;
218
+ ext: Record<string, unknown>;
219
+ capabilities: string[];
220
+ title: string;
221
+ category: string;
222
+ positions: Record<string, {
223
+ x: number;
224
+ y: number;
225
+ }>;
226
+ } | {
227
+ type: "dependency";
228
+ id: string;
229
+ description: string;
230
+ ext: Record<string, unknown>;
231
+ entities: string[];
232
+ title: string;
233
+ category: string;
234
+ positions: Record<string, {
235
+ x: number;
236
+ y: number;
237
+ }>;
238
+ layers: {
239
+ id: string;
240
+ label: string;
241
+ members: string[];
242
+ description?: string | undefined;
243
+ }[];
244
+ relationships?: string[] | undefined;
245
+ } | {
246
+ type: "extension";
247
+ id: string;
248
+ description: string;
249
+ ext: Record<string, unknown>;
250
+ entities: string[];
251
+ title: string;
252
+ category: string;
253
+ positions: Record<string, {
254
+ x: number;
255
+ y: number;
256
+ }>;
257
+ extension: string;
258
+ data?: unknown;
259
+ })[];
260
+ walkthroughs: {
261
+ overview: string | undefined;
262
+ scenes: {
263
+ view: string | undefined;
264
+ code: {
265
+ hunks: {
266
+ lines: {
267
+ kind: "add" | "del" | "ctx";
268
+ text: string;
269
+ new?: number | undefined;
270
+ old?: number | undefined;
271
+ }[];
272
+ header?: string | undefined;
273
+ }[];
274
+ path: string;
275
+ notes: {
276
+ line: number;
277
+ text: string;
278
+ }[];
279
+ title?: string | undefined;
280
+ }[];
281
+ id: string;
282
+ title: string;
283
+ text: string;
284
+ risk: "look" | "routine";
285
+ focus: string[];
286
+ callouts: {
287
+ target: string;
288
+ text: string;
289
+ }[];
290
+ cases: {
291
+ when: string;
292
+ then: string;
293
+ note?: string | undefined;
294
+ }[];
295
+ proof: {
296
+ text: string;
297
+ missing: boolean;
298
+ source?: string | undefined;
299
+ test?: string | undefined;
300
+ }[];
301
+ questions: string[];
302
+ trace: {
303
+ ref: string;
304
+ caption?: string | undefined;
305
+ }[];
306
+ effects: {
307
+ target: string;
308
+ as: "flow" | "attention" | "hot-path" | "slow" | "failing" | "blocked";
309
+ tone?: string | undefined;
310
+ }[];
311
+ badges: {
312
+ target: string;
313
+ text: string;
314
+ tone?: string | undefined;
315
+ }[];
316
+ question?: string | undefined;
317
+ }[];
318
+ id: string;
319
+ kind: "change" | "tour";
320
+ summary: string;
321
+ title: string;
322
+ removed: {
323
+ entities: {
324
+ id: string;
325
+ name: string;
326
+ kind: string;
327
+ summary: string;
328
+ tags: string[];
329
+ sourceRefs: {
330
+ path: string;
331
+ symbol?: string | undefined;
332
+ repository?: string | undefined;
333
+ line?: number | undefined;
334
+ }[];
335
+ metadata: Record<string, string | number | boolean>;
336
+ ext: Record<string, unknown>;
337
+ description?: string | undefined;
338
+ parent?: string | undefined;
339
+ technology?: string | undefined;
340
+ }[];
341
+ relationships: {
342
+ id: string;
343
+ kind: string;
344
+ metadata: Record<string, string | number | boolean>;
345
+ ext: Record<string, unknown>;
346
+ source: string;
347
+ target: string;
348
+ label: string;
349
+ data: string[];
350
+ description?: string | undefined;
351
+ protocol?: string | undefined;
352
+ }[];
353
+ transitions: {
354
+ stateMachine: string;
355
+ transition: {
356
+ id: string;
357
+ event: string;
358
+ from: string;
359
+ to: string;
360
+ actions: string[];
361
+ description?: string | undefined;
362
+ guard?: string | undefined;
363
+ triggeredBy?: string | undefined;
364
+ };
365
+ }[];
366
+ };
367
+ story: {
368
+ text: string;
369
+ before?: string | undefined;
370
+ after?: string | undefined;
371
+ };
372
+ marks: {
373
+ state: "removed" | "new" | "changed";
374
+ ref: string;
375
+ note?: string | undefined;
376
+ }[];
377
+ source?: {
378
+ kind: string;
379
+ repository?: string | undefined;
380
+ ref?: string | undefined;
381
+ head?: string | undefined;
382
+ url?: string | undefined;
383
+ base?: string | undefined;
384
+ author?: string | undefined;
385
+ files?: number | undefined;
386
+ added?: number | undefined;
387
+ removed?: number | undefined;
388
+ } | undefined;
389
+ verdict?: {
390
+ risk: "look" | "routine";
391
+ facts: {
392
+ value: string;
393
+ label: string;
394
+ }[];
395
+ findings: {
396
+ text: string;
397
+ severity: "risk" | "note";
398
+ scene?: string | undefined;
399
+ }[];
400
+ } | undefined;
401
+ }[];
402
+ poneyVersion: "0.1.0";
403
+ project: {
404
+ id: string;
405
+ name: string;
406
+ description: string;
407
+ repository?: string | undefined;
408
+ defaultView?: string | undefined;
409
+ };
410
+ extensions: {
411
+ name: string;
412
+ version: string;
413
+ required: boolean;
414
+ }[];
415
+ model: {
416
+ entities: {
417
+ id: string;
418
+ name: string;
419
+ kind: string;
420
+ summary: string;
421
+ tags: string[];
422
+ sourceRefs: {
423
+ path: string;
424
+ symbol?: string | undefined;
425
+ repository?: string | undefined;
426
+ line?: number | undefined;
427
+ }[];
428
+ metadata: Record<string, string | number | boolean>;
429
+ ext: Record<string, unknown>;
430
+ description?: string | undefined;
431
+ parent?: string | undefined;
432
+ technology?: string | undefined;
433
+ }[];
434
+ relationships: {
435
+ id: string;
436
+ kind: string;
437
+ metadata: Record<string, string | number | boolean>;
438
+ ext: Record<string, unknown>;
439
+ source: string;
440
+ target: string;
441
+ label: string;
442
+ data: string[];
443
+ description?: string | undefined;
444
+ protocol?: string | undefined;
445
+ }[];
446
+ dataTypes: {
447
+ id: string;
448
+ name: string;
449
+ kind: "table" | "record" | "event" | "document";
450
+ summary: string;
451
+ sourceRefs: {
452
+ path: string;
453
+ symbol?: string | undefined;
454
+ repository?: string | undefined;
455
+ line?: number | undefined;
456
+ }[];
457
+ ext: Record<string, unknown>;
458
+ fields: {
459
+ type: string;
460
+ name: string;
461
+ primaryKey: boolean;
462
+ nullable: boolean;
463
+ unique: boolean;
464
+ description?: string | undefined;
465
+ references?: {
466
+ dataType: string;
467
+ field: string;
468
+ } | undefined;
469
+ }[];
470
+ description?: string | undefined;
471
+ ownedBy?: string | undefined;
472
+ storedIn?: string | undefined;
473
+ }[];
474
+ dataRelations: {
475
+ id: string;
476
+ label: string;
477
+ from: string;
478
+ to: string;
479
+ fromCardinality: "many" | "one" | "zero-or-one" | "one-or-many";
480
+ toCardinality: "many" | "one" | "zero-or-one" | "one-or-many";
481
+ logical: boolean;
482
+ via?: string | undefined;
483
+ }[];
484
+ dataFlows: {
485
+ id: string;
486
+ source: string;
487
+ target: string;
488
+ label: string;
489
+ data: string[];
490
+ description?: string | undefined;
491
+ via?: string | undefined;
492
+ }[];
493
+ behaviors: ({
494
+ id: string;
495
+ name: string;
496
+ kind: "interaction";
497
+ summary: string;
498
+ participants: string[];
499
+ steps: _hattoriai_poney_core.Step[];
500
+ description?: string | undefined;
501
+ } | {
502
+ id: string;
503
+ name: string;
504
+ kind: "process";
505
+ summary: string;
506
+ nodes: {
507
+ id: string;
508
+ kind: "join" | "start" | "end" | "action" | "decision" | "merge" | "fork";
509
+ label: string;
510
+ description?: string | undefined;
511
+ performedBy?: string | undefined;
512
+ outcome?: "success" | "failure" | undefined;
513
+ }[];
514
+ flows: {
515
+ id: string;
516
+ from: string;
517
+ to: string;
518
+ guard?: string | undefined;
519
+ }[];
520
+ description?: string | undefined;
521
+ } | {
522
+ id: string;
523
+ name: string;
524
+ kind: "state-machine";
525
+ summary: string;
526
+ states: {
527
+ id: string;
528
+ name: string;
529
+ kind: "initial" | "normal" | "final";
530
+ outcome: "success" | "failure" | "neutral";
531
+ entryActions: string[];
532
+ description?: string | undefined;
533
+ }[];
534
+ transitions: {
535
+ id: string;
536
+ event: string;
537
+ from: string;
538
+ to: string;
539
+ actions: string[];
540
+ description?: string | undefined;
541
+ guard?: string | undefined;
542
+ triggeredBy?: string | undefined;
543
+ }[];
544
+ description?: string | undefined;
545
+ subject?: string | undefined;
546
+ owner?: string | undefined;
547
+ })[];
548
+ capabilities: {
549
+ includes: string[];
550
+ id: string;
551
+ name: string;
552
+ summary: string;
553
+ ext: Record<string, unknown>;
554
+ behaviors: string[];
555
+ area: string;
556
+ actors: string[];
557
+ supporting: string[];
558
+ realizedBy: string[];
559
+ }[];
560
+ };
561
+ presentation: {
562
+ relationships: Record<string, {
563
+ head: "arrow" | "open-arrow" | "none" | "triangle";
564
+ pattern: "solid" | "dashed" | "dotted";
565
+ }>;
566
+ views: Record<string, Record<string, {
567
+ tone?: string | undefined;
568
+ icon?: string | undefined;
569
+ width?: number | undefined;
570
+ height?: number | undefined;
571
+ emphasis?: boolean | undefined;
572
+ }>>;
573
+ kinds: Record<string, {
574
+ label: string;
575
+ shape: "person" | "card" | "cylinder" | "stack" | "frame" | "chip";
576
+ tone: string;
577
+ icon: string;
578
+ }>;
579
+ elements: Record<string, {
580
+ tone?: string | undefined;
581
+ icon?: string | undefined;
582
+ width?: number | undefined;
583
+ height?: number | undefined;
584
+ emphasis?: boolean | undefined;
585
+ }>;
586
+ };
587
+ }, { index, report }: _hattoriai_poney_core.ExtensionContext) => void;
588
+ readonly lint: (doc: {
589
+ views: ({
590
+ type: "architecture";
591
+ id: string;
592
+ description: string;
593
+ ext: Record<string, unknown>;
594
+ entities: string[];
595
+ title: string;
596
+ category: string;
597
+ positions: Record<string, {
598
+ x: number;
599
+ y: number;
600
+ }>;
601
+ groups: {
602
+ id: string;
603
+ label: string;
604
+ members: string[];
605
+ description?: string | undefined;
606
+ }[];
607
+ collapsed: string[];
608
+ layout: {
609
+ direction: "right" | "down";
610
+ };
611
+ relationships?: string[] | undefined;
612
+ } | {
613
+ type: "map";
614
+ id: string;
615
+ description: string;
616
+ ext: Record<string, unknown>;
617
+ entities: string[];
618
+ title: string;
619
+ category: string;
620
+ positions: Record<string, {
621
+ x: number;
622
+ y: number;
623
+ }>;
624
+ collapsed: string[];
625
+ layout: {
626
+ direction: "right" | "down";
627
+ };
628
+ passThrough: string[];
629
+ relationships?: string[] | undefined;
630
+ } | {
631
+ type: "sequence";
632
+ id: string;
633
+ description: string;
634
+ ext: Record<string, unknown>;
635
+ interaction: string;
636
+ title: string;
637
+ category: string;
638
+ positions: Record<string, {
639
+ x: number;
640
+ y: number;
641
+ }>;
642
+ } | {
643
+ type: "dataflow";
644
+ id: string;
645
+ description: string;
646
+ ext: Record<string, unknown>;
647
+ flows: string[];
648
+ title: string;
649
+ category: string;
650
+ positions: Record<string, {
651
+ x: number;
652
+ y: number;
653
+ }>;
654
+ showControlFlow: boolean;
655
+ } | {
656
+ type: "activity";
657
+ id: string;
658
+ description: string;
659
+ ext: Record<string, unknown>;
660
+ process: string;
661
+ title: string;
662
+ category: string;
663
+ positions: Record<string, {
664
+ x: number;
665
+ y: number;
666
+ }>;
667
+ swimlanes: boolean;
668
+ } | {
669
+ type: "erd";
670
+ id: string;
671
+ description: string;
672
+ ext: Record<string, unknown>;
673
+ dataTypes: string[];
674
+ title: string;
675
+ category: string;
676
+ positions: Record<string, {
677
+ x: number;
678
+ y: number;
679
+ }>;
680
+ groupByStore: boolean;
681
+ fieldLimit: number;
682
+ } | {
683
+ type: "state";
684
+ id: string;
685
+ description: string;
686
+ ext: Record<string, unknown>;
687
+ title: string;
688
+ category: string;
689
+ positions: Record<string, {
690
+ x: number;
691
+ y: number;
692
+ }>;
693
+ stateMachine: string;
694
+ } | {
695
+ type: "usecase";
696
+ id: string;
697
+ description: string;
698
+ ext: Record<string, unknown>;
699
+ capabilities: string[];
700
+ title: string;
701
+ category: string;
702
+ positions: Record<string, {
703
+ x: number;
704
+ y: number;
705
+ }>;
706
+ } | {
707
+ type: "dependency";
708
+ id: string;
709
+ description: string;
710
+ ext: Record<string, unknown>;
711
+ entities: string[];
712
+ title: string;
713
+ category: string;
714
+ positions: Record<string, {
715
+ x: number;
716
+ y: number;
717
+ }>;
718
+ layers: {
719
+ id: string;
720
+ label: string;
721
+ members: string[];
722
+ description?: string | undefined;
723
+ }[];
724
+ relationships?: string[] | undefined;
725
+ } | {
726
+ type: "extension";
727
+ id: string;
728
+ description: string;
729
+ ext: Record<string, unknown>;
730
+ entities: string[];
731
+ title: string;
732
+ category: string;
733
+ positions: Record<string, {
734
+ x: number;
735
+ y: number;
736
+ }>;
737
+ extension: string;
738
+ data?: unknown;
739
+ })[];
740
+ walkthroughs: {
741
+ overview: string | undefined;
742
+ scenes: {
743
+ view: string | undefined;
744
+ code: {
745
+ hunks: {
746
+ lines: {
747
+ kind: "add" | "del" | "ctx";
748
+ text: string;
749
+ new?: number | undefined;
750
+ old?: number | undefined;
751
+ }[];
752
+ header?: string | undefined;
753
+ }[];
754
+ path: string;
755
+ notes: {
756
+ line: number;
757
+ text: string;
758
+ }[];
759
+ title?: string | undefined;
760
+ }[];
761
+ id: string;
762
+ title: string;
763
+ text: string;
764
+ risk: "look" | "routine";
765
+ focus: string[];
766
+ callouts: {
767
+ target: string;
768
+ text: string;
769
+ }[];
770
+ cases: {
771
+ when: string;
772
+ then: string;
773
+ note?: string | undefined;
774
+ }[];
775
+ proof: {
776
+ text: string;
777
+ missing: boolean;
778
+ source?: string | undefined;
779
+ test?: string | undefined;
780
+ }[];
781
+ questions: string[];
782
+ trace: {
783
+ ref: string;
784
+ caption?: string | undefined;
785
+ }[];
786
+ effects: {
787
+ target: string;
788
+ as: "flow" | "attention" | "hot-path" | "slow" | "failing" | "blocked";
789
+ tone?: string | undefined;
790
+ }[];
791
+ badges: {
792
+ target: string;
793
+ text: string;
794
+ tone?: string | undefined;
795
+ }[];
796
+ question?: string | undefined;
797
+ }[];
798
+ id: string;
799
+ kind: "change" | "tour";
800
+ summary: string;
801
+ title: string;
802
+ removed: {
803
+ entities: {
804
+ id: string;
805
+ name: string;
806
+ kind: string;
807
+ summary: string;
808
+ tags: string[];
809
+ sourceRefs: {
810
+ path: string;
811
+ symbol?: string | undefined;
812
+ repository?: string | undefined;
813
+ line?: number | undefined;
814
+ }[];
815
+ metadata: Record<string, string | number | boolean>;
816
+ ext: Record<string, unknown>;
817
+ description?: string | undefined;
818
+ parent?: string | undefined;
819
+ technology?: string | undefined;
820
+ }[];
821
+ relationships: {
822
+ id: string;
823
+ kind: string;
824
+ metadata: Record<string, string | number | boolean>;
825
+ ext: Record<string, unknown>;
826
+ source: string;
827
+ target: string;
828
+ label: string;
829
+ data: string[];
830
+ description?: string | undefined;
831
+ protocol?: string | undefined;
832
+ }[];
833
+ transitions: {
834
+ stateMachine: string;
835
+ transition: {
836
+ id: string;
837
+ event: string;
838
+ from: string;
839
+ to: string;
840
+ actions: string[];
841
+ description?: string | undefined;
842
+ guard?: string | undefined;
843
+ triggeredBy?: string | undefined;
844
+ };
845
+ }[];
846
+ };
847
+ story: {
848
+ text: string;
849
+ before?: string | undefined;
850
+ after?: string | undefined;
851
+ };
852
+ marks: {
853
+ state: "removed" | "new" | "changed";
854
+ ref: string;
855
+ note?: string | undefined;
856
+ }[];
857
+ source?: {
858
+ kind: string;
859
+ repository?: string | undefined;
860
+ ref?: string | undefined;
861
+ head?: string | undefined;
862
+ url?: string | undefined;
863
+ base?: string | undefined;
864
+ author?: string | undefined;
865
+ files?: number | undefined;
866
+ added?: number | undefined;
867
+ removed?: number | undefined;
868
+ } | undefined;
869
+ verdict?: {
870
+ risk: "look" | "routine";
871
+ facts: {
872
+ value: string;
873
+ label: string;
874
+ }[];
875
+ findings: {
876
+ text: string;
877
+ severity: "risk" | "note";
878
+ scene?: string | undefined;
879
+ }[];
880
+ } | undefined;
881
+ }[];
882
+ poneyVersion: "0.1.0";
883
+ project: {
884
+ id: string;
885
+ name: string;
886
+ description: string;
887
+ repository?: string | undefined;
888
+ defaultView?: string | undefined;
889
+ };
890
+ extensions: {
891
+ name: string;
892
+ version: string;
893
+ required: boolean;
894
+ }[];
895
+ model: {
896
+ entities: {
897
+ id: string;
898
+ name: string;
899
+ kind: string;
900
+ summary: string;
901
+ tags: string[];
902
+ sourceRefs: {
903
+ path: string;
904
+ symbol?: string | undefined;
905
+ repository?: string | undefined;
906
+ line?: number | undefined;
907
+ }[];
908
+ metadata: Record<string, string | number | boolean>;
909
+ ext: Record<string, unknown>;
910
+ description?: string | undefined;
911
+ parent?: string | undefined;
912
+ technology?: string | undefined;
913
+ }[];
914
+ relationships: {
915
+ id: string;
916
+ kind: string;
917
+ metadata: Record<string, string | number | boolean>;
918
+ ext: Record<string, unknown>;
919
+ source: string;
920
+ target: string;
921
+ label: string;
922
+ data: string[];
923
+ description?: string | undefined;
924
+ protocol?: string | undefined;
925
+ }[];
926
+ dataTypes: {
927
+ id: string;
928
+ name: string;
929
+ kind: "table" | "record" | "event" | "document";
930
+ summary: string;
931
+ sourceRefs: {
932
+ path: string;
933
+ symbol?: string | undefined;
934
+ repository?: string | undefined;
935
+ line?: number | undefined;
936
+ }[];
937
+ ext: Record<string, unknown>;
938
+ fields: {
939
+ type: string;
940
+ name: string;
941
+ primaryKey: boolean;
942
+ nullable: boolean;
943
+ unique: boolean;
944
+ description?: string | undefined;
945
+ references?: {
946
+ dataType: string;
947
+ field: string;
948
+ } | undefined;
949
+ }[];
950
+ description?: string | undefined;
951
+ ownedBy?: string | undefined;
952
+ storedIn?: string | undefined;
953
+ }[];
954
+ dataRelations: {
955
+ id: string;
956
+ label: string;
957
+ from: string;
958
+ to: string;
959
+ fromCardinality: "many" | "one" | "zero-or-one" | "one-or-many";
960
+ toCardinality: "many" | "one" | "zero-or-one" | "one-or-many";
961
+ logical: boolean;
962
+ via?: string | undefined;
963
+ }[];
964
+ dataFlows: {
965
+ id: string;
966
+ source: string;
967
+ target: string;
968
+ label: string;
969
+ data: string[];
970
+ description?: string | undefined;
971
+ via?: string | undefined;
972
+ }[];
973
+ behaviors: ({
974
+ id: string;
975
+ name: string;
976
+ kind: "interaction";
977
+ summary: string;
978
+ participants: string[];
979
+ steps: _hattoriai_poney_core.Step[];
980
+ description?: string | undefined;
981
+ } | {
982
+ id: string;
983
+ name: string;
984
+ kind: "process";
985
+ summary: string;
986
+ nodes: {
987
+ id: string;
988
+ kind: "join" | "start" | "end" | "action" | "decision" | "merge" | "fork";
989
+ label: string;
990
+ description?: string | undefined;
991
+ performedBy?: string | undefined;
992
+ outcome?: "success" | "failure" | undefined;
993
+ }[];
994
+ flows: {
995
+ id: string;
996
+ from: string;
997
+ to: string;
998
+ guard?: string | undefined;
999
+ }[];
1000
+ description?: string | undefined;
1001
+ } | {
1002
+ id: string;
1003
+ name: string;
1004
+ kind: "state-machine";
1005
+ summary: string;
1006
+ states: {
1007
+ id: string;
1008
+ name: string;
1009
+ kind: "initial" | "normal" | "final";
1010
+ outcome: "success" | "failure" | "neutral";
1011
+ entryActions: string[];
1012
+ description?: string | undefined;
1013
+ }[];
1014
+ transitions: {
1015
+ id: string;
1016
+ event: string;
1017
+ from: string;
1018
+ to: string;
1019
+ actions: string[];
1020
+ description?: string | undefined;
1021
+ guard?: string | undefined;
1022
+ triggeredBy?: string | undefined;
1023
+ }[];
1024
+ description?: string | undefined;
1025
+ subject?: string | undefined;
1026
+ owner?: string | undefined;
1027
+ })[];
1028
+ capabilities: {
1029
+ includes: string[];
1030
+ id: string;
1031
+ name: string;
1032
+ summary: string;
1033
+ ext: Record<string, unknown>;
1034
+ behaviors: string[];
1035
+ area: string;
1036
+ actors: string[];
1037
+ supporting: string[];
1038
+ realizedBy: string[];
1039
+ }[];
1040
+ };
1041
+ presentation: {
1042
+ relationships: Record<string, {
1043
+ head: "arrow" | "open-arrow" | "none" | "triangle";
1044
+ pattern: "solid" | "dashed" | "dotted";
1045
+ }>;
1046
+ views: Record<string, Record<string, {
1047
+ tone?: string | undefined;
1048
+ icon?: string | undefined;
1049
+ width?: number | undefined;
1050
+ height?: number | undefined;
1051
+ emphasis?: boolean | undefined;
1052
+ }>>;
1053
+ kinds: Record<string, {
1054
+ label: string;
1055
+ shape: "person" | "card" | "cylinder" | "stack" | "frame" | "chip";
1056
+ tone: string;
1057
+ icon: string;
1058
+ }>;
1059
+ elements: Record<string, {
1060
+ tone?: string | undefined;
1061
+ icon?: string | undefined;
1062
+ width?: number | undefined;
1063
+ height?: number | undefined;
1064
+ emphasis?: boolean | undefined;
1065
+ }>;
1066
+ };
1067
+ }, { warn }: _hattoriai_poney_core.ExtensionLintContext) => void;
1068
+ };
1069
+ /** The zone of a part: its own, else its parent's, and so on up. */
1070
+ declare function zoneOf(doc: PoneyDocument, entity: Entity | undefined): Entity | undefined;
1071
+ /** The sensitive data classes of a data type. */
1072
+ declare const classesOf: (d: DataType | undefined) => DataClass[];
1073
+ /** How a relationship is protected, as the document says. */
1074
+ declare const protectionOf: (r: Relationship | undefined) => {
1075
+ encrypted?: boolean | undefined;
1076
+ auth?: string | undefined;
1077
+ } | undefined;
1078
+ interface Crossing {
1079
+ index: number;
1080
+ relationship: Relationship;
1081
+ from: Entity;
1082
+ to: Entity;
1083
+ fromZone: Entity;
1084
+ toZone: Entity;
1085
+ /** Sensitive data on the line: from the relationship's data, and from data flows that go through it. */
1086
+ classes: DataClass[];
1087
+ protection?: RelationshipFacet;
1088
+ }
1089
+ /** Every relationship whose ends are in different zones. */
1090
+ declare function crossings(doc: PoneyDocument): Crossing[];
1091
+ /** The parts in a zone, directly or through a parent. */
1092
+ declare function inZone(doc: PoneyDocument, zoneId: string): Entity[];
1093
+
1094
+ export { CLASS_LABEL, type Crossing, DataClass, DataTypeFacet, EntityFacet, RelationshipFacet, Trust, ZONE_KIND, classesOf, crossings, inZone, protectionOf, security, zoneOf };
package/dist/index.js ADDED
@@ -0,0 +1,113 @@
1
+ import { z } from 'zod';
2
+ import { Id, defineExtension, readFacet } from '@hattoriai/poney-core';
3
+
4
+ // src/index.ts
5
+ var DataClass = z.enum(["personal", "secret", "payment", "health"]);
6
+ var CLASS_LABEL = { personal: "Personal data", secret: "Secrets", payment: "Payment data", health: "Health data" };
7
+ var Trust = z.enum(["public", "internal", "restricted"]);
8
+ var EntityFacet = z.object({
9
+ /** The trust zone this part runs in: an entity of kind "security/zone". */
10
+ zone: Id.optional(),
11
+ /** For zones: how much the zone is trusted. */
12
+ trust: Trust.optional()
13
+ }).strict();
14
+ var DataTypeFacet = z.object({
15
+ /** What kind of sensitive data this type holds. */
16
+ classes: z.array(DataClass).min(1)
17
+ }).strict();
18
+ var RelationshipFacet = z.object({
19
+ /** The data is encrypted in transit (TLS counts). */
20
+ encrypted: z.boolean().optional(),
21
+ /** How the caller proves who it is, e.g. "mTLS", "OAuth token", "session cookie", or "none". */
22
+ auth: z.string().min(1).optional()
23
+ }).strict();
24
+ var ZONE_KIND = "security/zone";
25
+ var security = defineExtension({
26
+ name: "security",
27
+ version: "0.1.0",
28
+ description: "Trust zones, sensitive data, and how connections are protected.",
29
+ entityKinds: {
30
+ zone: { label: "Trust zone", description: "Where parts trust each other. A line between zones crosses a trust boundary." }
31
+ },
32
+ facets: { entity: EntityFacet, dataType: DataTypeFacet, relationship: RelationshipFacet },
33
+ validate(doc, { index, report }) {
34
+ doc.model.entities.forEach((e, i) => {
35
+ const zone = readFacet(security, "entity", e)?.zone;
36
+ if (!zone) return;
37
+ const target = index.entities.get(zone);
38
+ if (!target) report(`model.entities.${i}.ext.security.zone`, `Unknown zone "${zone}"`);
39
+ else if (target.kind !== ZONE_KIND) report(`model.entities.${i}.ext.security.zone`, `"${zone}" is not a zone (kind "${ZONE_KIND}")`);
40
+ });
41
+ },
42
+ lint(doc, { warn }) {
43
+ for (const c of crossings(doc)) {
44
+ if (!c.classes.length) continue;
45
+ const what = c.classes.map((k) => CLASS_LABEL[k].toLowerCase()).join(" and ");
46
+ const where = `from ${c.from.name} to ${c.to.name}`;
47
+ if (c.protection?.encrypted !== true)
48
+ warn(
49
+ `model.relationships.${c.index}`,
50
+ "security-unencrypted-crossing",
51
+ `"${c.relationship.label}" carries ${what} ${where} without encryption.`,
52
+ "If it is encrypted (TLS counts), set ext.security.encrypted to true on the relationship. If not, the data should not cross this boundary as it is."
53
+ );
54
+ if (!c.protection?.auth)
55
+ warn(
56
+ `model.relationships.${c.index}`,
57
+ "security-unknown-auth",
58
+ `"${c.relationship.label}" carries ${what} ${where}, and the document does not say how the caller is authenticated.`,
59
+ 'Set ext.security.auth on the relationship, e.g. "mTLS", "OAuth token" or "none".'
60
+ );
61
+ }
62
+ doc.model.relationships.forEach((r, i) => {
63
+ const auth = readFacet(security, "relationship", r)?.auth;
64
+ const target = doc.model.entities.find((e) => e.id === r.target);
65
+ const zone = zoneOf(doc, target);
66
+ if (auth?.toLowerCase() === "none" && zone && readFacet(security, "entity", zone)?.trust === "restricted")
67
+ warn(`model.relationships.${i}`, "security-open-restricted", `"${r.label}" reaches the restricted zone ${zone.name} with no authentication.`, "Name the authentication, or say why this part of a restricted zone is open.");
68
+ });
69
+ doc.model.dataTypes.forEach((d, i) => {
70
+ if (!classesOf(d).length || !d.storedIn) return;
71
+ const store = doc.model.entities.find((e) => e.id === d.storedIn);
72
+ const zone = zoneOf(doc, store);
73
+ if (zone && readFacet(security, "entity", zone)?.trust === "public")
74
+ warn(`model.dataTypes.${i}`, "security-sensitive-in-public", `${d.name} holds ${classesOf(d).map((k) => CLASS_LABEL[k].toLowerCase()).join(" and ")}, and is stored in ${store.name}, in the public zone ${zone.name}.`, "Move the store to a zone that is not public, or check that the zone is right.");
75
+ });
76
+ }
77
+ });
78
+ function zoneOf(doc, entity) {
79
+ const byId = new Map(doc.model.entities.map((e) => [e.id, e]));
80
+ const seen = /* @__PURE__ */ new Set();
81
+ for (let e = entity; e && !seen.has(e.id); e = e.parent ? byId.get(e.parent) : void 0) {
82
+ seen.add(e.id);
83
+ if (e.kind === ZONE_KIND) return e;
84
+ const zone = readFacet(security, "entity", e)?.zone;
85
+ if (zone) return byId.get(zone);
86
+ }
87
+ return void 0;
88
+ }
89
+ var classesOf = (d) => readFacet(security, "dataType", d)?.classes ?? [];
90
+ var protectionOf = (r) => readFacet(security, "relationship", r);
91
+ function crossings(doc) {
92
+ const entities = new Map(doc.model.entities.map((e) => [e.id, e]));
93
+ const dataTypes = new Map(doc.model.dataTypes.map((d) => [d.id, d]));
94
+ const out = [];
95
+ doc.model.relationships.forEach((r, index) => {
96
+ const from = entities.get(r.source);
97
+ const to = entities.get(r.target);
98
+ const fromZone = zoneOf(doc, from);
99
+ const toZone = zoneOf(doc, to);
100
+ if (!from || !to || !fromZone || !toZone || fromZone.id === toZone.id) return;
101
+ const data = /* @__PURE__ */ new Set([...r.data, ...doc.model.dataFlows.filter((f) => f.via === r.id).flatMap((f) => f.data)]);
102
+ const classes = [...new Set([...data].flatMap((id) => classesOf(dataTypes.get(id))))];
103
+ out.push({ index, relationship: r, from, to, fromZone, toZone, classes, protection: protectionOf(r) });
104
+ });
105
+ return out;
106
+ }
107
+ function inZone(doc, zoneId) {
108
+ return doc.model.entities.filter((e) => e.id !== zoneId && e.kind !== ZONE_KIND && zoneOf(doc, e)?.id === zoneId);
109
+ }
110
+
111
+ export { CLASS_LABEL, DataClass, DataTypeFacet, EntityFacet, RelationshipFacet, Trust, ZONE_KIND, classesOf, crossings, inZone, protectionOf, security, zoneOf };
112
+ //# sourceMappingURL=index.js.map
113
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;AAqBO,IAAM,SAAA,GAAY,EAAE,IAAA,CAAK,CAAC,YAAY,QAAA,EAAU,SAAA,EAAW,QAAQ,CAAC;AAGpE,IAAM,WAAA,GAAyC,EAAE,QAAA,EAAU,eAAA,EAAiB,QAAQ,SAAA,EAAW,OAAA,EAAS,cAAA,EAAgB,MAAA,EAAQ,aAAA;AAGhI,IAAM,QAAQ,CAAA,CAAE,IAAA,CAAK,CAAC,QAAA,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,IAAA,mBAAO,IAAI,GAAA,CAAI,CAAC,GAAG,EAAE,IAAA,EAAM,GAAG,GAAA,CAAI,KAAA,CAAM,SAAA,CAAU,MAAA,CAAO,CAAC,CAAA,KAAM,CAAA,CAAE,GAAA,KAAQ,CAAA,CAAE,EAAE,CAAA,CAAE,OAAA,CAAQ,CAAC,CAAA,KAAM,CAAA,CAAE,IAAI,CAAC,CAAC,CAAA;AAC7G,IAAA,MAAM,UAAU,CAAC,GAAG,IAAI,GAAA,CAAI,CAAC,GAAG,IAAI,CAAA,CAAE,QAAQ,CAAC,EAAA,KAAO,UAAU,SAAA,CAAU,GAAA,CAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;AACpF,IAAA,GAAA,CAAI,IAAA,CAAK,EAAE,KAAA,EAAO,YAAA,EAAc,GAAG,IAAA,EAAM,EAAA,EAAI,QAAA,EAAU,MAAA,EAAQ,OAAA,EAAS,UAAA,EAAY,YAAA,CAAa,CAAC,GAAG,CAAA;AAAA,EACvG,CAAC,CAAA;AACD,EAAA,OAAO,GAAA;AACT;AAGO,SAAS,MAAA,CAAO,KAAoB,MAAA,EAA0B;AACnE,EAAA,OAAO,IAAI,KAAA,CAAM,QAAA,CAAS,MAAA,CAAO,CAAC,MAAM,CAAA,CAAE,EAAA,KAAO,MAAA,IAAU,CAAA,CAAE,SAAS,SAAA,IAAa,MAAA,CAAO,KAAK,CAAC,CAAA,EAAG,OAAO,MAAM,CAAA;AAClH","file":"index.js","sourcesContent":["import { z } from 'zod'\nimport { Id, defineExtension, readFacet, type DataType, type Entity, type PoneyDocument, type Relationship } from '@hattoriai/poney-core'\n\n/**\n * The security extension: where trust ends, which data is sensitive, and how\n * each connection is protected.\n *\n * It adds:\n * - an entity kind, \"security/zone\": a trust zone. Inside a zone, parts trust\n * each other; a line between zones crosses a boundary;\n * - facets: an entity's zone, a data type's classes (personal, secret,\n * payment, health), and a relationship's protection (encryption, auth);\n * - lints that read those together, e.g. \"personal data leaves a zone\n * without encryption\".\n *\n * A part without a zone takes the zone of its parent. Zones are drawn with\n * the core views (an architecture view's groups); the extension adds no view\n * type of its own.\n */\n\n/** Classes of sensitive data. */\nexport const DataClass = z.enum(['personal', 'secret', 'payment', 'health'])\nexport type DataClass = z.infer<typeof DataClass>\n\nexport const CLASS_LABEL: Record<DataClass, string> = { personal: 'Personal data', secret: 'Secrets', payment: 'Payment data', health: 'Health data' }\n\n/** How much a zone is trusted: public (anyone can reach it), internal, restricted. */\nexport const Trust = z.enum(['public', 'internal', 'restricted'])\nexport type Trust = z.infer<typeof Trust>\n\nexport const EntityFacet = z\n .object({\n /** The trust zone this part runs in: an entity of kind \"security/zone\". */\n zone: Id.optional(),\n /** For zones: how much the zone is trusted. */\n trust: Trust.optional(),\n })\n .strict()\nexport type EntityFacet = z.infer<typeof EntityFacet>\n\nexport const DataTypeFacet = z\n .object({\n /** What kind of sensitive data this type holds. */\n classes: z.array(DataClass).min(1),\n })\n .strict()\nexport type DataTypeFacet = z.infer<typeof DataTypeFacet>\n\nexport const RelationshipFacet = z\n .object({\n /** The data is encrypted in transit (TLS counts). */\n encrypted: z.boolean().optional(),\n /** How the caller proves who it is, e.g. \"mTLS\", \"OAuth token\", \"session cookie\", or \"none\". */\n auth: z.string().min(1).optional(),\n })\n .strict()\nexport type RelationshipFacet = z.infer<typeof RelationshipFacet>\n\nexport const ZONE_KIND = 'security/zone'\n\nexport const security = defineExtension({\n name: 'security',\n version: '0.1.0',\n description: 'Trust zones, sensitive data, and how connections are protected.',\n entityKinds: {\n zone: { label: 'Trust zone', description: 'Where parts trust each other. A line between zones crosses a trust boundary.' },\n },\n facets: { entity: EntityFacet, dataType: DataTypeFacet, relationship: RelationshipFacet },\n validate(doc, { index, report }) {\n doc.model.entities.forEach((e, i) => {\n const zone = readFacet(security, 'entity', e)?.zone\n if (!zone) return\n const target = index.entities.get(zone)\n if (!target) report(`model.entities.${i}.ext.security.zone`, `Unknown zone \"${zone}\"`)\n else if (target.kind !== ZONE_KIND) report(`model.entities.${i}.ext.security.zone`, `\"${zone}\" is not a zone (kind \"${ZONE_KIND}\")`)\n })\n },\n lint(doc, { warn }) {\n for (const c of crossings(doc)) {\n if (!c.classes.length) continue\n const what = c.classes.map((k) => CLASS_LABEL[k].toLowerCase()).join(' and ')\n const where = `from ${c.from.name} to ${c.to.name}`\n if (c.protection?.encrypted !== true)\n warn(\n `model.relationships.${c.index}`,\n 'security-unencrypted-crossing',\n `\"${c.relationship.label}\" carries ${what} ${where} without encryption.`,\n 'If it is encrypted (TLS counts), set ext.security.encrypted to true on the relationship. If not, the data should not cross this boundary as it is.',\n )\n if (!c.protection?.auth)\n warn(\n `model.relationships.${c.index}`,\n 'security-unknown-auth',\n `\"${c.relationship.label}\" carries ${what} ${where}, and the document does not say how the caller is authenticated.`,\n 'Set ext.security.auth on the relationship, e.g. \"mTLS\", \"OAuth token\" or \"none\".',\n )\n }\n doc.model.relationships.forEach((r, i) => {\n const auth = readFacet(security, 'relationship', r)?.auth\n const target = doc.model.entities.find((e) => e.id === r.target)\n const zone = zoneOf(doc, target)\n if (auth?.toLowerCase() === 'none' && zone && readFacet(security, 'entity', zone)?.trust === 'restricted')\n warn(`model.relationships.${i}`, 'security-open-restricted', `\"${r.label}\" reaches the restricted zone ${zone.name} with no authentication.`, 'Name the authentication, or say why this part of a restricted zone is open.')\n })\n doc.model.dataTypes.forEach((d, i) => {\n if (!classesOf(d).length || !d.storedIn) return\n const store = doc.model.entities.find((e) => e.id === d.storedIn)\n const zone = zoneOf(doc, store)\n if (zone && readFacet(security, 'entity', zone)?.trust === 'public')\n warn(`model.dataTypes.${i}`, 'security-sensitive-in-public', `${d.name} holds ${classesOf(d).map((k) => CLASS_LABEL[k].toLowerCase()).join(' and ')}, and is stored in ${store!.name}, in the public zone ${zone.name}.`, 'Move the store to a zone that is not public, or check that the zone is right.')\n })\n },\n})\n\n/** The zone of a part: its own, else its parent's, and so on up. */\nexport function zoneOf(doc: PoneyDocument, entity: Entity | undefined): Entity | undefined {\n const byId = new Map(doc.model.entities.map((e) => [e.id, e]))\n const seen = new Set<string>()\n for (let e = entity; e && !seen.has(e.id); e = e.parent ? byId.get(e.parent) : undefined) {\n seen.add(e.id)\n if (e.kind === ZONE_KIND) return e\n const zone = readFacet(security, 'entity', e)?.zone\n if (zone) return byId.get(zone)\n }\n return undefined\n}\n\n/** The sensitive data classes of a data type. */\nexport const classesOf = (d: DataType | undefined): DataClass[] => readFacet(security, 'dataType', d)?.classes ?? []\n\n/** How a relationship is protected, as the document says. */\nexport const protectionOf = (r: Relationship | undefined) => readFacet(security, 'relationship', r)\n\nexport interface Crossing {\n index: number\n relationship: Relationship\n from: Entity\n to: Entity\n fromZone: Entity\n toZone: Entity\n /** Sensitive data on the line: from the relationship's data, and from data flows that go through it. */\n classes: DataClass[]\n protection?: RelationshipFacet\n}\n\n/** Every relationship whose ends are in different zones. */\nexport function crossings(doc: PoneyDocument): Crossing[] {\n const entities = new Map(doc.model.entities.map((e) => [e.id, e]))\n const dataTypes = new Map(doc.model.dataTypes.map((d) => [d.id, d]))\n const out: Crossing[] = []\n doc.model.relationships.forEach((r, index) => {\n const from = entities.get(r.source)\n const to = entities.get(r.target)\n const fromZone = zoneOf(doc, from)\n const toZone = zoneOf(doc, to)\n if (!from || !to || !fromZone || !toZone || fromZone.id === toZone.id) return\n const data = new Set([...r.data, ...doc.model.dataFlows.filter((f) => f.via === r.id).flatMap((f) => f.data)])\n const classes = [...new Set([...data].flatMap((id) => classesOf(dataTypes.get(id))))]\n out.push({ index, relationship: r, from, to, fromZone, toZone, classes, protection: protectionOf(r) })\n })\n return out\n}\n\n/** The parts in a zone, directly or through a parent. */\nexport function inZone(doc: PoneyDocument, zoneId: string): Entity[] {\n return doc.model.entities.filter((e) => e.id !== zoneId && e.kind !== ZONE_KIND && zoneOf(doc, e)?.id === zoneId)\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,38 @@
1
1
  {
2
2
  "name": "@hattoriai/poney-ext-security",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "description": "Poney extension: trust zones, sensitive data, and how connections are protected; with lints.",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/hattoriai/poney.git",
10
+ "directory": "packages/ext-security"
11
+ },
12
+ "homepage": "https://github.com/hattoriai/poney#readme",
13
+ "bugs": "https://github.com/hattoriai/poney/issues",
14
+ "exports": {
15
+ ".": {
16
+ "poney-source": "./src/index.ts",
17
+ "types": "./dist/index.d.ts",
18
+ "default": "./dist/index.js"
19
+ }
20
+ },
21
+ "files": [
22
+ "dist"
23
+ ],
24
+ "scripts": {
25
+ "build": "tsup"
26
+ },
27
+ "publishConfig": {
28
+ "access": "public",
29
+ "provenance": true
30
+ },
31
+ "dependencies": {
32
+ "@hattoriai/poney-core": "0.1.0",
33
+ "zod": "^3.25.76"
34
+ },
35
+ "devDependencies": {
36
+ "tsup": "8.5.1"
37
+ }
38
+ }