@principal-ai/subsystems-react 0.56.40 → 0.56.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +7 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/subsystem/C4ContainersPanel.d.ts +32 -2
- package/dist/subsystem/C4ContainersPanel.d.ts.map +1 -1
- package/dist/subsystem/C4ContainersPanel.js +89 -21
- package/dist/subsystem/C4ContainersPanel.js.map +1 -1
- package/dist/subsystem/C4Graph.d.ts +13 -0
- package/dist/subsystem/C4Graph.d.ts.map +1 -1
- package/dist/subsystem/C4Graph.js +19 -2
- package/dist/subsystem/C4Graph.js.map +1 -1
- package/dist/subsystem/C4NodeCard.d.ts +15 -2
- package/dist/subsystem/C4NodeCard.d.ts.map +1 -1
- package/dist/subsystem/C4NodeCard.js +124 -7
- package/dist/subsystem/C4NodeCard.js.map +1 -1
- package/dist/subsystem/C4ProjectionView.d.ts +8 -1
- package/dist/subsystem/C4ProjectionView.d.ts.map +1 -1
- package/dist/subsystem/C4ProjectionView.js +3 -3
- package/dist/subsystem/C4ProjectionView.js.map +1 -1
- package/dist/subsystem/C4SketchView.d.ts +9 -1
- package/dist/subsystem/C4SketchView.d.ts.map +1 -1
- package/dist/subsystem/C4SketchView.js +2 -2
- package/dist/subsystem/C4SketchView.js.map +1 -1
- package/dist/subsystem/__fixtures__/c4Deployments.d.ts +18 -0
- package/dist/subsystem/__fixtures__/c4Deployments.d.ts.map +1 -0
- package/dist/subsystem/__fixtures__/c4Deployments.js +185 -0
- package/dist/subsystem/__fixtures__/c4Deployments.js.map +1 -0
- package/dist/subsystem/c4.d.ts +63 -0
- package/dist/subsystem/c4.d.ts.map +1 -1
- package/dist/subsystem/c4.js.map +1 -1
- package/dist/subsystem/c4Deployment.d.ts +78 -0
- package/dist/subsystem/c4Deployment.d.ts.map +1 -0
- package/dist/subsystem/c4Deployment.js +68 -0
- package/dist/subsystem/c4Deployment.js.map +1 -0
- package/dist/subsystem/techIcons/cloudflare.d.ts +15 -0
- package/dist/subsystem/techIcons/cloudflare.d.ts.map +1 -0
- package/dist/subsystem/techIcons/cloudflare.js +15 -0
- package/dist/subsystem/techIcons/cloudflare.js.map +1 -0
- package/dist/subsystem/techIcons/index.d.ts +14 -1
- package/dist/subsystem/techIcons/index.d.ts.map +1 -1
- package/dist/subsystem/techIcons/index.js +17 -0
- package/dist/subsystem/techIcons/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +25 -1
- package/src/stories/Canvases/C4/C4Sketch.stories.tsx +51 -0
- package/src/subsystem/C4ContainersPanel.test.tsx +90 -2
- package/src/subsystem/C4ContainersPanel.tsx +142 -35
- package/src/subsystem/C4Graph.tsx +49 -3
- package/src/subsystem/C4NodeCard.tsx +217 -7
- package/src/subsystem/C4ProjectionView.tsx +12 -0
- package/src/subsystem/C4SketchView.tsx +13 -0
- package/src/subsystem/__fixtures__/c4Deployments.ts +196 -0
- package/src/subsystem/c4.ts +62 -0
- package/src/subsystem/c4Deployment.test.tsx +211 -0
- package/src/subsystem/c4Deployment.tsx +137 -0
- package/src/subsystem/techIcons/cloudflare.ts +14 -0
- package/src/subsystem/techIcons/index.tsx +30 -1
- package/src/subsystem/techIcons/techIcons.test.ts +12 -2
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Storybook fixture: two Workers and their stores, shaped the way
|
|
3
|
+
* `infraToC4` (subsystems-core) projects a pair of wrangler configs — each
|
|
4
|
+
* container carries its configured `deployment` anchor.
|
|
5
|
+
*
|
|
6
|
+
* The observations are invented: they stand in for what credentialed tooling
|
|
7
|
+
* would report, and cover every state a badge can be in.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { C4DeploymentObservation } from '../c4';
|
|
11
|
+
import type { C4Sketch } from '../c4Sketch';
|
|
12
|
+
|
|
13
|
+
const wrangler = (pointer: string) => ({ tool: 'wrangler', file: 'wrangler.jsonc', pointer });
|
|
14
|
+
|
|
15
|
+
export const DEPLOYMENT_SKETCH: C4Sketch = {
|
|
16
|
+
id: 'c4s-deployments',
|
|
17
|
+
title: 'dev-feed and topic-share on Cloudflare',
|
|
18
|
+
repoKeys: ['pkg:github/acme/dev-feed', 'pkg:github/acme/topic-share'],
|
|
19
|
+
author: 'storybook',
|
|
20
|
+
description:
|
|
21
|
+
'Containers proposed from two wrangler configs. Each carries the resource it was declared as; the badge shows whether it was observed live.',
|
|
22
|
+
createdAt: '2026-11-29T00:00:00.000Z',
|
|
23
|
+
updatedAt: '2026-11-29T00:00:00.000Z',
|
|
24
|
+
model: {
|
|
25
|
+
view: 'container',
|
|
26
|
+
system: { id: 'system:feeds', label: 'Feeds' },
|
|
27
|
+
nodes: [
|
|
28
|
+
{
|
|
29
|
+
kind: 'container',
|
|
30
|
+
id: 'container:dev-feed',
|
|
31
|
+
label: 'dev-feed',
|
|
32
|
+
containerKind: 'application',
|
|
33
|
+
technology: 'Cloudflare Worker',
|
|
34
|
+
state: 'proposed',
|
|
35
|
+
description: 'Merged-PR activity feed: API plus the single-page app it serves.',
|
|
36
|
+
deployment: {
|
|
37
|
+
resourceKey: 'cloudflare:worker:dev-feed',
|
|
38
|
+
provider: 'cloudflare',
|
|
39
|
+
resourceType: 'worker',
|
|
40
|
+
name: 'dev-feed',
|
|
41
|
+
source: wrangler(''),
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
kind: 'container',
|
|
46
|
+
id: 'container:cache-kv',
|
|
47
|
+
label: 'CACHE',
|
|
48
|
+
containerKind: 'data-store',
|
|
49
|
+
technology: 'Cloudflare KV',
|
|
50
|
+
state: 'proposed',
|
|
51
|
+
description: 'Cached feed responses.',
|
|
52
|
+
deployment: {
|
|
53
|
+
resourceKey: 'cloudflare:kv_namespace:0000000000000000',
|
|
54
|
+
provider: 'cloudflare',
|
|
55
|
+
resourceType: 'kv_namespace',
|
|
56
|
+
name: '0000000000000000',
|
|
57
|
+
source: wrangler('/kv_namespaces/0'),
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
kind: 'container',
|
|
62
|
+
id: 'container:topic-share',
|
|
63
|
+
label: 'topic-share',
|
|
64
|
+
containerKind: 'application',
|
|
65
|
+
technology: 'Cloudflare Worker',
|
|
66
|
+
state: 'proposed',
|
|
67
|
+
description: 'Publishes shared topics and sweeps expired ones daily.',
|
|
68
|
+
deployment: {
|
|
69
|
+
resourceKey: 'cloudflare:worker:topic-share',
|
|
70
|
+
provider: 'cloudflare',
|
|
71
|
+
resourceType: 'worker',
|
|
72
|
+
name: 'topic-share',
|
|
73
|
+
source: wrangler(''),
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
kind: 'container',
|
|
78
|
+
id: 'container:topic-share-r2',
|
|
79
|
+
label: 'topic-share',
|
|
80
|
+
containerKind: 'data-store',
|
|
81
|
+
technology: 'Cloudflare R2',
|
|
82
|
+
state: 'proposed',
|
|
83
|
+
description: 'Topic blobs.',
|
|
84
|
+
deployment: {
|
|
85
|
+
resourceKey: 'cloudflare:r2_bucket:topic-share',
|
|
86
|
+
provider: 'cloudflare',
|
|
87
|
+
resourceType: 'r2_bucket',
|
|
88
|
+
name: 'topic-share',
|
|
89
|
+
source: wrangler('/r2_buckets/0'),
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
kind: 'container',
|
|
94
|
+
id: 'container:topic-share-d1',
|
|
95
|
+
label: 'topic-share',
|
|
96
|
+
containerKind: 'data-store',
|
|
97
|
+
technology: 'Cloudflare D1',
|
|
98
|
+
state: 'proposed',
|
|
99
|
+
description: 'Index of shared topics and their expiry.',
|
|
100
|
+
deployment: {
|
|
101
|
+
resourceKey: 'cloudflare:d1_database:topic-share',
|
|
102
|
+
provider: 'cloudflare',
|
|
103
|
+
resourceType: 'd1_database',
|
|
104
|
+
name: 'topic-share',
|
|
105
|
+
source: wrangler('/d1_databases/0'),
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
kind: 'container',
|
|
110
|
+
id: 'container:legacy-api',
|
|
111
|
+
label: 'legacy-api',
|
|
112
|
+
containerKind: 'application',
|
|
113
|
+
technology: 'Node',
|
|
114
|
+
state: 'proposed',
|
|
115
|
+
description: 'Hosted somewhere we hold no mark for.',
|
|
116
|
+
deployment: {
|
|
117
|
+
resourceKey: 'fly:app:legacy-api',
|
|
118
|
+
provider: 'fly',
|
|
119
|
+
resourceType: 'app',
|
|
120
|
+
name: 'legacy-api',
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
],
|
|
124
|
+
edges: [
|
|
125
|
+
{
|
|
126
|
+
id: 'edge:dev-feed->cache',
|
|
127
|
+
source: 'container:dev-feed',
|
|
128
|
+
target: 'container:cache-kv',
|
|
129
|
+
label: 'env.CACHE',
|
|
130
|
+
draft: true,
|
|
131
|
+
mechanisms: [],
|
|
132
|
+
count: 0,
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
id: 'edge:topic-share->r2',
|
|
136
|
+
source: 'container:topic-share',
|
|
137
|
+
target: 'container:topic-share-r2',
|
|
138
|
+
label: 'env.TOPIC_BLOBS',
|
|
139
|
+
draft: true,
|
|
140
|
+
mechanisms: [],
|
|
141
|
+
count: 0,
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
id: 'edge:topic-share->d1',
|
|
145
|
+
source: 'container:topic-share',
|
|
146
|
+
target: 'container:topic-share-d1',
|
|
147
|
+
label: 'env.SHARE_INDEX',
|
|
148
|
+
draft: true,
|
|
149
|
+
mechanisms: [],
|
|
150
|
+
count: 0,
|
|
151
|
+
},
|
|
152
|
+
],
|
|
153
|
+
},
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
const OBSERVED_AT = '2026-11-29T09:00:00.000Z';
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* dev-feed and its cache are live; topic-share is declared but was never
|
|
160
|
+
* checked; its bucket was looked for and is missing; its database could not be
|
|
161
|
+
* checked.
|
|
162
|
+
*/
|
|
163
|
+
export const DEPLOYMENT_OBSERVATIONS: ReadonlyMap<string, C4DeploymentObservation> = new Map(
|
|
164
|
+
(
|
|
165
|
+
[
|
|
166
|
+
{
|
|
167
|
+
resourceKey: 'cloudflare:worker:dev-feed',
|
|
168
|
+
status: 'deployed',
|
|
169
|
+
liveUrls: ['https://dev-feed.example.workers.dev'],
|
|
170
|
+
consoleUrl: 'https://dash.example.com/workers/dev-feed',
|
|
171
|
+
observedAt: OBSERVED_AT,
|
|
172
|
+
source: 'cloudflare-api',
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
resourceKey: 'cloudflare:kv_namespace:0000000000000000',
|
|
176
|
+
status: 'deployed',
|
|
177
|
+
consoleUrl: 'https://dash.example.com/kv/0000000000000000',
|
|
178
|
+
observedAt: OBSERVED_AT,
|
|
179
|
+
source: 'cloudflare-api',
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
resourceKey: 'cloudflare:r2_bucket:topic-share',
|
|
183
|
+
status: 'not-found',
|
|
184
|
+
consoleUrl: 'https://dash.example.com/r2',
|
|
185
|
+
observedAt: OBSERVED_AT,
|
|
186
|
+
source: 'cloudflare-api',
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
resourceKey: 'cloudflare:d1_database:topic-share',
|
|
190
|
+
status: 'unknown',
|
|
191
|
+
observedAt: OBSERVED_AT,
|
|
192
|
+
source: 'cloudflare-api',
|
|
193
|
+
},
|
|
194
|
+
] satisfies C4DeploymentObservation[]
|
|
195
|
+
).map((observation) => [observation.resourceKey, observation]),
|
|
196
|
+
);
|
package/src/subsystem/c4.ts
CHANGED
|
@@ -94,6 +94,63 @@ interface C4MemberList {
|
|
|
94
94
|
*/
|
|
95
95
|
export type C4ContainerKind = 'application' | 'data-store';
|
|
96
96
|
|
|
97
|
+
/**
|
|
98
|
+
* Which declared piece of infrastructure a container is — the *configured*
|
|
99
|
+
* anchor, read from a wrangler config or terraform JSON at a commit.
|
|
100
|
+
*
|
|
101
|
+
* It says where the container is meant to run, which is enough to draw the
|
|
102
|
+
* provider's mark. It holds no live fact: whether the thing is actually
|
|
103
|
+
* running, and at what URL, is a {@link C4DeploymentObservation} supplied
|
|
104
|
+
* separately and joined on `resourceKey`. Architecture identity and runtime
|
|
105
|
+
* state are kept apart on purpose — accepting a container never implies it is
|
|
106
|
+
* deployed.
|
|
107
|
+
*
|
|
108
|
+
* Structurally identical to `InfraC4Deployment` in `subsystems-core`, which
|
|
109
|
+
* produces these.
|
|
110
|
+
*/
|
|
111
|
+
export interface C4Deployment {
|
|
112
|
+
/** `<provider>:<resourceType>:<identifier>`, e.g. `cloudflare:worker:topic-share`. */
|
|
113
|
+
resourceKey: string;
|
|
114
|
+
/** Hosting provider, lowercase: `cloudflare`. */
|
|
115
|
+
provider: string;
|
|
116
|
+
/** `worker`, `r2_bucket`, `d1_database`, `kv_namespace`, … */
|
|
117
|
+
resourceType: string;
|
|
118
|
+
/** The provider's own name or id for the resource. */
|
|
119
|
+
name: string;
|
|
120
|
+
/** Where it was declared. Absent on a hand-authored anchor. */
|
|
121
|
+
source?: { tool: string; file: string; pointer: string };
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Whether a declared resource was found live. `unknown` means the check could
|
|
126
|
+
* not be made — never treat it as `not-found`.
|
|
127
|
+
*/
|
|
128
|
+
export type C4DeploymentStatus = 'deployed' | 'not-found' | 'unknown';
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* One observation of one declared resource in a live account. Supplied by the
|
|
132
|
+
* host, never stored on the element. Carries no credential or secret.
|
|
133
|
+
*
|
|
134
|
+
* Structurally identical to `InfraDeploymentObservation` in `subsystems-core`.
|
|
135
|
+
*/
|
|
136
|
+
export interface C4DeploymentObservation {
|
|
137
|
+
/** Joins to {@link C4Deployment.resourceKey}. */
|
|
138
|
+
resourceKey: string;
|
|
139
|
+
status: C4DeploymentStatus;
|
|
140
|
+
resourceId?: string;
|
|
141
|
+
/** Where the running thing answers. The first is the one a reader is sent to. */
|
|
142
|
+
liveUrls?: string[];
|
|
143
|
+
/** The provider dashboard page for this resource. */
|
|
144
|
+
consoleUrl?: string;
|
|
145
|
+
version?: string;
|
|
146
|
+
/** When that version went live (ISO). */
|
|
147
|
+
deployedAt?: string;
|
|
148
|
+
/** When we looked (ISO). */
|
|
149
|
+
observedAt: string;
|
|
150
|
+
/** Who said so: `cloudflare-api`, `terraform-state`, `authored`. */
|
|
151
|
+
source: string;
|
|
152
|
+
}
|
|
153
|
+
|
|
97
154
|
/** A deployable unit or a store — the C4 level 2 box. */
|
|
98
155
|
export interface C4Container extends C4ElementBase {
|
|
99
156
|
kind: 'container';
|
|
@@ -107,6 +164,11 @@ export interface C4Container extends C4ElementBase {
|
|
|
107
164
|
* the components inside resolve from the model document.
|
|
108
165
|
*/
|
|
109
166
|
process?: string;
|
|
167
|
+
/**
|
|
168
|
+
* The declared infrastructure this container is, when a config file names
|
|
169
|
+
* it. Drives the provider mark on the card.
|
|
170
|
+
*/
|
|
171
|
+
deployment?: C4Deployment;
|
|
110
172
|
}
|
|
111
173
|
|
|
112
174
|
/**
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { afterEach, describe, expect, test } from 'bun:test';
|
|
2
|
+
import { createElement } from 'react';
|
|
3
|
+
import { Window } from 'happy-dom';
|
|
4
|
+
import { cleanup, fireEvent, render } from '@testing-library/react/pure';
|
|
5
|
+
import { ThemeProvider, defaultEditorTheme } from '@principal-ade/industry-theme';
|
|
6
|
+
import { C4NodeCard, deploymentSummary } from './C4NodeCard';
|
|
7
|
+
import { elementStanding, resolveDeploymentView, safeExternalUrl } from './c4Deployment';
|
|
8
|
+
import type { C4DeploymentLinkKind } from './c4Deployment';
|
|
9
|
+
import type { C4Container, C4Deployment, C4DeploymentObservation } from './c4';
|
|
10
|
+
|
|
11
|
+
// Bun's happy-dom test environment isn't registered, so wire the DOM
|
|
12
|
+
// primitives React DOM needs before rendering.
|
|
13
|
+
const dom = new Window();
|
|
14
|
+
const globals = globalThis as unknown as Record<string, unknown>;
|
|
15
|
+
globals.window = dom;
|
|
16
|
+
globals.document = dom.document;
|
|
17
|
+
globals.navigator = dom.navigator;
|
|
18
|
+
globals.HTMLElement = dom.HTMLElement;
|
|
19
|
+
globals.customElements = dom.customElements;
|
|
20
|
+
globals.Node = dom.Node;
|
|
21
|
+
globals.Element = dom.Element;
|
|
22
|
+
globals.Event = dom.Event;
|
|
23
|
+
globals.getComputedStyle = dom.getComputedStyle.bind(dom);
|
|
24
|
+
globals.requestAnimationFrame = dom.requestAnimationFrame.bind(dom);
|
|
25
|
+
globals.cancelAnimationFrame = dom.cancelAnimationFrame.bind(dom);
|
|
26
|
+
globals.localStorage = dom.localStorage;
|
|
27
|
+
globals.matchMedia = dom.matchMedia.bind(dom);
|
|
28
|
+
|
|
29
|
+
afterEach(cleanup);
|
|
30
|
+
|
|
31
|
+
const DEPLOYMENT: C4Deployment = {
|
|
32
|
+
resourceKey: 'cloudflare:worker:topic-share',
|
|
33
|
+
provider: 'cloudflare',
|
|
34
|
+
resourceType: 'worker',
|
|
35
|
+
name: 'topic-share',
|
|
36
|
+
source: { tool: 'wrangler', file: 'wrangler.jsonc', pointer: '' },
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const OBSERVED: C4DeploymentObservation = {
|
|
40
|
+
resourceKey: DEPLOYMENT.resourceKey,
|
|
41
|
+
status: 'deployed',
|
|
42
|
+
liveUrls: ['https://topic-share.example.workers.dev'],
|
|
43
|
+
consoleUrl: 'https://dash.cloudflare.com/example',
|
|
44
|
+
observedAt: '2026-11-29T00:00:00.000Z',
|
|
45
|
+
source: 'cloudflare-api',
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
describe('safeExternalUrl', () => {
|
|
49
|
+
test('passes http(s) and rejects everything else', () => {
|
|
50
|
+
expect(safeExternalUrl('https://example.com/a')).toBe('https://example.com/a');
|
|
51
|
+
expect(safeExternalUrl('http://localhost:8787')).toBe('http://localhost:8787/');
|
|
52
|
+
expect(safeExternalUrl('javascript:alert(1)')).toBeUndefined();
|
|
53
|
+
expect(safeExternalUrl('file:///etc/passwd')).toBeUndefined();
|
|
54
|
+
expect(safeExternalUrl('not a url')).toBeUndefined();
|
|
55
|
+
expect(safeExternalUrl(undefined)).toBeUndefined();
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
describe('resolveDeploymentView', () => {
|
|
60
|
+
test('no observation is configured-only, with nowhere to go', () => {
|
|
61
|
+
const view = resolveDeploymentView(DEPLOYMENT, undefined);
|
|
62
|
+
expect(view.phase).toBe('configured');
|
|
63
|
+
expect(view.liveUrl).toBeUndefined();
|
|
64
|
+
expect(view.consoleUrl).toBeUndefined();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test('a failed check reads as configured, never as not-found', () => {
|
|
68
|
+
const view = resolveDeploymentView(DEPLOYMENT, { ...OBSERVED, status: 'unknown' });
|
|
69
|
+
expect(view.phase).toBe('configured');
|
|
70
|
+
// No live link for something we could not confirm; the console still helps.
|
|
71
|
+
expect(view.liveUrl).toBeUndefined();
|
|
72
|
+
expect(view.consoleUrl).toBe('https://dash.cloudflare.com/example');
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test('deployed offers the first usable live URL', () => {
|
|
76
|
+
const view = resolveDeploymentView(DEPLOYMENT, {
|
|
77
|
+
...OBSERVED,
|
|
78
|
+
liveUrls: ['javascript:alert(1)', 'https://share.example.com'],
|
|
79
|
+
});
|
|
80
|
+
expect(view.phase).toBe('deployed');
|
|
81
|
+
expect(view.liveUrl).toBe('https://share.example.com/');
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test('not-found drops the live URL', () => {
|
|
85
|
+
const view = resolveDeploymentView(DEPLOYMENT, { ...OBSERVED, status: 'not-found' });
|
|
86
|
+
expect(view.phase).toBe('not-found');
|
|
87
|
+
expect(view.liveUrl).toBeUndefined();
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
describe('deploymentSummary', () => {
|
|
92
|
+
test('says which of the three states the badge is in', () => {
|
|
93
|
+
expect(deploymentSummary(resolveDeploymentView(DEPLOYMENT, undefined))).toBe(
|
|
94
|
+
'Configured for Cloudflare in wrangler.jsonc · worker topic-share · live state not checked',
|
|
95
|
+
);
|
|
96
|
+
expect(deploymentSummary(resolveDeploymentView(DEPLOYMENT, OBSERVED))).toContain(
|
|
97
|
+
'Deployed on Cloudflare',
|
|
98
|
+
);
|
|
99
|
+
expect(
|
|
100
|
+
deploymentSummary(resolveDeploymentView(DEPLOYMENT, { ...OBSERVED, status: 'not-found' })),
|
|
101
|
+
).toContain('not found');
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
const NODE: C4Container = {
|
|
106
|
+
kind: 'container',
|
|
107
|
+
id: 'container:topic-share',
|
|
108
|
+
label: 'topic-share',
|
|
109
|
+
containerKind: 'application',
|
|
110
|
+
technology: 'Cloudflare Worker',
|
|
111
|
+
state: 'proposed',
|
|
112
|
+
deployment: DEPLOYMENT,
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
function renderCard(
|
|
116
|
+
observation: C4DeploymentObservation | undefined,
|
|
117
|
+
onOpen?: (kind: C4DeploymentLinkKind, url: string) => void,
|
|
118
|
+
onClick?: () => void,
|
|
119
|
+
) {
|
|
120
|
+
return render(
|
|
121
|
+
createElement(
|
|
122
|
+
ThemeProvider,
|
|
123
|
+
{ theme: defaultEditorTheme },
|
|
124
|
+
createElement(C4NodeCard, {
|
|
125
|
+
node: NODE,
|
|
126
|
+
onClick,
|
|
127
|
+
deploymentView: resolveDeploymentView(DEPLOYMENT, observation),
|
|
128
|
+
onOpenDeployment: onOpen,
|
|
129
|
+
}),
|
|
130
|
+
),
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
describe('C4NodeCard deployment badge', () => {
|
|
135
|
+
test('a card with no deployment draws no badge', () => {
|
|
136
|
+
const { container } = render(
|
|
137
|
+
createElement(
|
|
138
|
+
ThemeProvider,
|
|
139
|
+
{ theme: defaultEditorTheme },
|
|
140
|
+
createElement(C4NodeCard, { node: { ...NODE, deployment: undefined } }),
|
|
141
|
+
),
|
|
142
|
+
);
|
|
143
|
+
expect(container.querySelector('[data-deployment-phase]')).toBeNull();
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test('configured-only shows the provider mark and no links', () => {
|
|
147
|
+
const { container } = renderCard(undefined, () => {});
|
|
148
|
+
const badge = container.querySelector('[data-deployment-phase]')!;
|
|
149
|
+
expect(badge.getAttribute('data-deployment-phase')).toBe('configured');
|
|
150
|
+
expect(badge.querySelector('[aria-label="Cloudflare"]')).not.toBeNull();
|
|
151
|
+
expect(badge.querySelectorAll('button')).toHaveLength(0);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
test('deployed offers live and console links, and a click does not select the card', () => {
|
|
155
|
+
const opened: Array<[string, string]> = [];
|
|
156
|
+
let selected = 0;
|
|
157
|
+
const { getByLabelText } = renderCard(
|
|
158
|
+
OBSERVED,
|
|
159
|
+
(kind, url) => opened.push([kind, url]),
|
|
160
|
+
() => {
|
|
161
|
+
selected += 1;
|
|
162
|
+
},
|
|
163
|
+
);
|
|
164
|
+
fireEvent.click(getByLabelText('Open live deployment'));
|
|
165
|
+
fireEvent.click(getByLabelText('Open in Cloudflare'));
|
|
166
|
+
expect(opened).toEqual([
|
|
167
|
+
['live', 'https://topic-share.example.workers.dev/'],
|
|
168
|
+
['console', 'https://dash.cloudflare.com/example'],
|
|
169
|
+
]);
|
|
170
|
+
expect(selected).toBe(0);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
test('without a host opener the mark is drawn but nothing is clickable', () => {
|
|
174
|
+
const { container } = renderCard(OBSERVED);
|
|
175
|
+
const badge = container.querySelector('[data-deployment-phase="deployed"]')!;
|
|
176
|
+
expect(badge.querySelectorAll('button')).toHaveLength(0);
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
describe('elementStanding', () => {
|
|
181
|
+
test('a proposed container observed running is deployed, not proposed', () => {
|
|
182
|
+
expect(elementStanding(NODE, OBSERVED)).toBe('deployed');
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
test('anything short of an observed deployment leaves it proposed', () => {
|
|
186
|
+
expect(elementStanding(NODE, undefined)).toBe('proposed');
|
|
187
|
+
expect(elementStanding(NODE, { ...OBSERVED, status: 'unknown' })).toBe('proposed');
|
|
188
|
+
expect(elementStanding(NODE, { ...OBSERVED, status: 'not-found' })).toBe('proposed');
|
|
189
|
+
// An observation of some other resource proves nothing about this one.
|
|
190
|
+
expect(elementStanding(NODE, { ...OBSERVED, resourceKey: 'cloudflare:worker:other' })).toBe(
|
|
191
|
+
'proposed',
|
|
192
|
+
);
|
|
193
|
+
expect(elementStanding({ ...NODE, deployment: undefined }, OBSERVED)).toBe('proposed');
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
test('a human decision is never overridden', () => {
|
|
197
|
+
expect(elementStanding({ ...NODE, state: 'accepted' }, OBSERVED)).toBe('accepted');
|
|
198
|
+
expect(elementStanding({ ...NODE, state: 'rejected' }, OBSERVED)).toBe('rejected');
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
describe('C4NodeCard border', () => {
|
|
203
|
+
const borderOf = (observation: C4DeploymentObservation | undefined) =>
|
|
204
|
+
(renderCard(observation).container.firstElementChild as HTMLElement).style.border;
|
|
205
|
+
|
|
206
|
+
test('dashed while proposed, solid once observed running', () => {
|
|
207
|
+
expect(borderOf(undefined)).toContain('dashed');
|
|
208
|
+
expect(borderOf({ ...OBSERVED, status: 'not-found' })).toContain('dashed');
|
|
209
|
+
expect(borderOf(OBSERVED)).toContain('solid');
|
|
210
|
+
});
|
|
211
|
+
});
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deployment state for C4 cards — the join between a container's configured
|
|
3
|
+
* anchor and what the host observed live, and the context that carries the
|
|
4
|
+
* observations to the cards.
|
|
5
|
+
*
|
|
6
|
+
* A context rather than node data: observations arrive and refresh on their
|
|
7
|
+
* own clock, and threading them through the graph's node build would re-run
|
|
8
|
+
* layout every time one changed. The card box does not depend on them.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { createContext, useContext } from 'react';
|
|
12
|
+
import type { C4Deployment, C4DeploymentObservation, C4Element } from './c4';
|
|
13
|
+
|
|
14
|
+
/** What a reader can be sent to. */
|
|
15
|
+
export type C4DeploymentLinkKind = 'live' | 'console';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* How a container's deployment reads on its card.
|
|
19
|
+
*
|
|
20
|
+
* - `deployed` — observed live.
|
|
21
|
+
* - `not-found` — declared, looked for, and absent.
|
|
22
|
+
* - `configured` — declared, and either never checked or the check could not
|
|
23
|
+
* be made. Deliberately one state: both mean "we cannot say it is running".
|
|
24
|
+
*/
|
|
25
|
+
export type C4DeploymentPhase = 'deployed' | 'not-found' | 'configured';
|
|
26
|
+
|
|
27
|
+
export interface C4DeploymentView {
|
|
28
|
+
deployment: C4Deployment;
|
|
29
|
+
phase: C4DeploymentPhase;
|
|
30
|
+
observation?: C4DeploymentObservation;
|
|
31
|
+
/** The running thing, when it has a usable URL. Only ever set when deployed. */
|
|
32
|
+
liveUrl?: string;
|
|
33
|
+
/** The provider's page for the resource, when it has a usable URL. */
|
|
34
|
+
consoleUrl?: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Only http(s) is ever handed to the host to open — an observation is data, not trusted markup. */
|
|
38
|
+
export function safeExternalUrl(url: string | undefined): string | undefined {
|
|
39
|
+
if (!url) return undefined;
|
|
40
|
+
try {
|
|
41
|
+
const parsed = new URL(url);
|
|
42
|
+
return parsed.protocol === 'https:' || parsed.protocol === 'http:' ? parsed.href : undefined;
|
|
43
|
+
} catch {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** The deployment anchor an element carries, if it is a container with one. */
|
|
49
|
+
export function elementDeployment(element: C4Element): C4Deployment | undefined {
|
|
50
|
+
return element.kind === 'container' ? element.deployment : undefined;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Resolve what a card should show for a deployment anchor.
|
|
55
|
+
*
|
|
56
|
+
* A live URL is offered only when the resource was observed deployed: a URL
|
|
57
|
+
* for something we could not find is a link to nowhere. The console link
|
|
58
|
+
* survives `not-found` and `unknown`, since the dashboard is where a reader
|
|
59
|
+
* goes to find out why.
|
|
60
|
+
*/
|
|
61
|
+
export function resolveDeploymentView(
|
|
62
|
+
deployment: C4Deployment,
|
|
63
|
+
observation: C4DeploymentObservation | undefined,
|
|
64
|
+
): C4DeploymentView {
|
|
65
|
+
const phase: C4DeploymentPhase =
|
|
66
|
+
observation?.status === 'deployed'
|
|
67
|
+
? 'deployed'
|
|
68
|
+
: observation?.status === 'not-found'
|
|
69
|
+
? 'not-found'
|
|
70
|
+
: 'configured';
|
|
71
|
+
const liveUrl =
|
|
72
|
+
phase === 'deployed'
|
|
73
|
+
? observation?.liveUrls?.map(safeExternalUrl).find((url): url is string => !!url)
|
|
74
|
+
: undefined;
|
|
75
|
+
const consoleUrl = safeExternalUrl(observation?.consoleUrl);
|
|
76
|
+
return {
|
|
77
|
+
deployment,
|
|
78
|
+
phase,
|
|
79
|
+
...(observation ? { observation } : {}),
|
|
80
|
+
...(liveUrl ? { liveUrl } : {}),
|
|
81
|
+
...(consoleUrl ? { consoleUrl } : {}),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Where an element stands, for display: its review state, lifted by evidence.
|
|
87
|
+
*
|
|
88
|
+
* `proposed` means "a hypothesis nobody has confirmed". An observation that the
|
|
89
|
+
* thing is running confirms it exists, so a proposed element observed deployed
|
|
90
|
+
* reads as `deployed` instead — it is no longer theoretical. The stored review
|
|
91
|
+
* state is not changed: this is derived on every render, so it falls back to
|
|
92
|
+
* `proposed` by itself when the observation goes away or stops saying
|
|
93
|
+
* `deployed`. A human decision is never overridden — `accepted` and `rejected`
|
|
94
|
+
* stand as they are.
|
|
95
|
+
*/
|
|
96
|
+
export type C4Standing = 'accepted' | 'proposed' | 'rejected' | 'deployed';
|
|
97
|
+
|
|
98
|
+
export function elementStanding(
|
|
99
|
+
element: C4Element,
|
|
100
|
+
observation: C4DeploymentObservation | undefined,
|
|
101
|
+
): C4Standing {
|
|
102
|
+
if (element.state !== 'proposed') return element.state;
|
|
103
|
+
const deployment = elementDeployment(element);
|
|
104
|
+
return deployment &&
|
|
105
|
+
observation?.resourceKey === deployment.resourceKey &&
|
|
106
|
+
observation.status === 'deployed'
|
|
107
|
+
? 'deployed'
|
|
108
|
+
: 'proposed';
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** What the host is told when a reader follows a deployment link. */
|
|
112
|
+
export interface C4OpenExternalRequest {
|
|
113
|
+
url: string;
|
|
114
|
+
kind: C4DeploymentLinkKind;
|
|
115
|
+
/** The element the link was on. */
|
|
116
|
+
elementId: string;
|
|
117
|
+
resourceKey: string;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export interface C4DeploymentContextValue {
|
|
121
|
+
/** Observations keyed by `resourceKey`. */
|
|
122
|
+
observations?: ReadonlyMap<string, C4DeploymentObservation>;
|
|
123
|
+
/**
|
|
124
|
+
* Open a URL outside the app. The views never navigate themselves — a
|
|
125
|
+
* desktop host opens the system browser, a web host a new tab. Without it
|
|
126
|
+
* the links are not drawn.
|
|
127
|
+
*/
|
|
128
|
+
onOpenExternal?: (request: C4OpenExternalRequest) => void;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const EMPTY: C4DeploymentContextValue = {};
|
|
132
|
+
|
|
133
|
+
export const C4DeploymentContext = createContext<C4DeploymentContextValue>(EMPTY);
|
|
134
|
+
|
|
135
|
+
export function useC4Deployments(): C4DeploymentContextValue {
|
|
136
|
+
return useContext(C4DeploymentContext);
|
|
137
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cloudflare mark — the cloud from the official logo, without the wordmark.
|
|
3
|
+
*
|
|
4
|
+
* Source: https://www.cloudflare.com/img/logo-web-badges/cf-logo-on-white-bg.svg.
|
|
5
|
+
* The two cloud paths and their fills are taken unmodified; the wordmark, the backing rectangle and the
|
|
6
|
+
* Illustrator wrapper are dropped, and the viewBox is cropped to the cloud so
|
|
7
|
+
* the mark fills a square slot.
|
|
8
|
+
*
|
|
9
|
+
* Cloudflare and the Cloudflare logo are trademarks of Cloudflare, Inc. Used
|
|
10
|
+
* here for identification only, with no endorsement implied.
|
|
11
|
+
*
|
|
12
|
+
* Root sized to 100% so the card's wrapper controls the box.
|
|
13
|
+
*/
|
|
14
|
+
export const cloudflareSvg = `<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="126.8 24.5 91.2 42.3"><path fill="#F48220" d="M189.1,63.6c0.5-1.9,0.3-3.6-0.6-4.9c-0.8-1.2-2.2-1.9-3.9-1.9l-32.2-0.4c-0.2,0-0.4-0.1-0.5-0.3 c-0.1-0.2-0.1-0.4-0.1-0.6c0.1-0.3,0.4-0.6,0.7-0.6l32.5-0.4c3.9-0.2,8-3.3,9.5-7.1l1.9-4.8c0.1-0.2,0.1-0.4,0.1-0.6 c-2.1-9.5-10.5-16.5-20.6-16.5c-9.3,0-17.2,6-20,14.3c-1.8-1.4-4.2-2.1-6.7-1.8c-4.5,0.4-8,4-8.5,8.5c-0.1,1.2,0,2.3,0.2,3.3 c-7.3,0.2-13.1,6.2-13.1,13.5c0,0.7,0.1,1.3,0.1,2c0,0.3,0.3,0.5,0.6,0.5l59.4,0c0.3,0,0.7-0.2,0.8-0.6L189.1,63.6z"/><path fill="#FBAD40" d="M199.3,42.9c-0.3,0-0.6,0-0.9,0c-0.2,0-0.4,0.2-0.5,0.4l-1.3,4.4c-0.5,1.9-0.3,3.6,0.6,4.9 c0.8,1.2,2.2,1.9,3.9,1.9l6.9,0.4c0.2,0,0.4,0.1,0.5,0.3c0.1,0.2,0.1,0.4,0.1,0.6c-0.1,0.3-0.4,0.6-0.7,0.6l-7.1,0.4 c-3.9,0.2-8,3.3-9.5,7.1l-0.5,1.3c-0.1,0.2,0.1,0.5,0.4,0.5h24.5c0.3,0,0.6-0.2,0.6-0.5c0.4-1.5,0.7-3.1,0.7-4.8 C216.9,50.8,209,42.9,199.3,42.9"/></svg>`;
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
import { bunSvg } from './bun';
|
|
15
|
+
import { cloudflareSvg } from './cloudflare';
|
|
15
16
|
import { nodeSvg } from './node';
|
|
16
17
|
import { reactSvg } from './react';
|
|
17
18
|
|
|
@@ -67,13 +68,41 @@ export function technologyBrand(technology: string | undefined): TechBrand | und
|
|
|
67
68
|
return TECH_BRANDS.find((brand) => brand.match.test(technology));
|
|
68
69
|
}
|
|
69
70
|
|
|
71
|
+
/**
|
|
72
|
+
* A hosting provider's mark — where a container is deployed, as opposed to
|
|
73
|
+
* what it is built with. Kept out of `TECH_BRANDS` on purpose: "built with
|
|
74
|
+
* Bun" and "runs on Cloudflare" are different facts drawn in different slots,
|
|
75
|
+
* and a provider is matched by its exact id, not by scanning free text.
|
|
76
|
+
*/
|
|
77
|
+
export interface ProviderBrand extends Omit<TechBrand, 'match'> {
|
|
78
|
+
/** The provider id a deployment carries, lowercase: `cloudflare`. */
|
|
79
|
+
provider: string;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export const PROVIDER_BRANDS: readonly ProviderBrand[] = [
|
|
83
|
+
{
|
|
84
|
+
provider: 'cloudflare',
|
|
85
|
+
name: 'Cloudflare',
|
|
86
|
+
source: 'https://www.cloudflare.com/img/logo-web-badges/cf-logo-on-white-bg.svg',
|
|
87
|
+
svg: cloudflareSvg,
|
|
88
|
+
color: '#f48220',
|
|
89
|
+
},
|
|
90
|
+
];
|
|
91
|
+
|
|
92
|
+
/** The official mark for a provider id, or undefined when we hold none. */
|
|
93
|
+
export function providerBrand(provider: string | undefined): ProviderBrand | undefined {
|
|
94
|
+
if (!provider) return undefined;
|
|
95
|
+
const id = provider.toLowerCase();
|
|
96
|
+
return PROVIDER_BRANDS.find((brand) => brand.provider === id);
|
|
97
|
+
}
|
|
98
|
+
|
|
70
99
|
/** A brand mark sized to the top row. Full-colour, not tinted by state. */
|
|
71
100
|
export function TechMark({
|
|
72
101
|
brand,
|
|
73
102
|
size = 14,
|
|
74
103
|
showTitle = true,
|
|
75
104
|
}: {
|
|
76
|
-
brand: TechBrand
|
|
105
|
+
brand: Pick<TechBrand, 'name' | 'source' | 'svg'>;
|
|
77
106
|
size?: number;
|
|
78
107
|
/** Render the attribution tooltip. Off inside rows that already explain themselves. */
|
|
79
108
|
showTitle?: boolean;
|