@principal-ai/subsystems-react 0.56.39 → 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/SubsystemComponentGraph.d.ts +5 -0
- package/dist/subsystem/SubsystemComponentGraph.d.ts.map +1 -1
- package/dist/subsystem/SubsystemComponentGraph.js +2 -2
- package/dist/subsystem/SubsystemComponentGraph.js.map +1 -1
- package/dist/subsystem/TrailIcon.d.ts +18 -4
- package/dist/subsystem/TrailIcon.d.ts.map +1 -1
- package/dist/subsystem/TrailIcon.js +35 -24
- package/dist/subsystem/TrailIcon.js.map +1 -1
- package/dist/subsystem/TrailsPanel.d.ts +3 -1
- package/dist/subsystem/TrailsPanel.d.ts.map +1 -1
- package/dist/subsystem/TrailsPanel.js +28 -17
- package/dist/subsystem/TrailsPanel.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/SubsystemComponentGraph.tsx +7 -1
- package/src/subsystem/TrailIcon.tsx +60 -34
- package/src/subsystem/TrailsPanel.test.tsx +51 -0
- package/src/subsystem/TrailsPanel.tsx +40 -11
- 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,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;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, test } from 'bun:test';
|
|
2
|
-
import { TECH_BRANDS, technologyBrand } from './index';
|
|
2
|
+
import { PROVIDER_BRANDS, TECH_BRANDS, providerBrand, technologyBrand } from './index';
|
|
3
3
|
|
|
4
4
|
describe('technologyBrand', () => {
|
|
5
5
|
test('matches the brand named in the technology string', () => {
|
|
@@ -28,7 +28,7 @@ describe('technologyBrand', () => {
|
|
|
28
28
|
});
|
|
29
29
|
|
|
30
30
|
test('every vendored brand carries a source and an SVG', () => {
|
|
31
|
-
for (const brand of TECH_BRANDS) {
|
|
31
|
+
for (const brand of [...TECH_BRANDS, ...PROVIDER_BRANDS]) {
|
|
32
32
|
expect(brand.source).toMatch(/^https?:\/\//);
|
|
33
33
|
expect(brand.svg.startsWith('<svg')).toBe(true);
|
|
34
34
|
// Root sized to 100%, so the card wrapper controls the box.
|
|
@@ -36,4 +36,14 @@ describe('technologyBrand', () => {
|
|
|
36
36
|
expect(brand.svg).toContain('height="100%"');
|
|
37
37
|
}
|
|
38
38
|
});
|
|
39
|
+
|
|
40
|
+
test('a provider is matched by exact id, and is not a technology', () => {
|
|
41
|
+
expect(providerBrand('cloudflare')?.name).toBe('Cloudflare');
|
|
42
|
+
expect(providerBrand('Cloudflare')?.name).toBe('Cloudflare');
|
|
43
|
+
expect(providerBrand('aws')).toBeUndefined();
|
|
44
|
+
expect(providerBrand(undefined)).toBeUndefined();
|
|
45
|
+
// A container built for Workers still gets no technology mark: the
|
|
46
|
+
// provider logo belongs to the deployment slot, not the technology row.
|
|
47
|
+
expect(technologyBrand('Cloudflare Worker')).toBeUndefined();
|
|
48
|
+
});
|
|
39
49
|
});
|