@intentius/behold 0.29.57 → 0.30.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/AGENTS.md +388 -57
  2. package/README.md +67 -50
  3. package/demos.json +1 -1
  4. package/dist/cli.js +9958 -3080
  5. package/example-choudoufu-estate/chant.workspace.json +1 -1
  6. package/example-terraform-estate/README.md +10 -10
  7. package/example-terraform-estate/chant.workspace.json +1 -1
  8. package/example-three-cloud/README.md +17 -9
  9. package/example-three-cloud/aws/chant.config.ts +1 -1
  10. package/example-three-cloud/aws/site.component.ts +13 -0
  11. package/example-three-cloud/azure/chant.config.ts +1 -1
  12. package/example-three-cloud/azure/src/site.component.ts +13 -0
  13. package/example-three-cloud/azure/src/site.ts +5 -7
  14. package/example-three-cloud/dns/chant.config.ts +1 -1
  15. package/example-three-cloud/dns/src/records.component.ts +14 -0
  16. package/example-three-cloud/dns/src/route53.ts +4 -5
  17. package/example-three-cloud/gcp/chant.config.ts +1 -1
  18. package/example-three-cloud/gcp/src/site.component.ts +13 -0
  19. package/example-three-cloud/gcp/src/site.ts +7 -7
  20. package/example-three-cloud/package-lock.json +19 -19
  21. package/example-three-cloud/package.json +4 -4
  22. package/example-three-cloud/scripts/front-door.ts +89 -15
  23. package/package.json +10 -11
  24. package/web/agent-move.js +60 -0
  25. package/web/agent-move.test.js +55 -0
  26. package/web/app.js +622 -79
  27. package/web/dots-lod.js +1 -1
  28. package/web/embed.d.ts +3 -0
  29. package/web/embed.js +5 -3
  30. package/web/embed.test.js +8 -0
  31. package/web/index.html +64 -9
  32. package/web/layout-store.js +3 -3
  33. package/web/panel.js +28 -4
  34. package/web/release.js +6 -4
  35. package/web/release.test.js +2 -2
  36. package/web/search-view.d.ts +27 -0
  37. package/web/search-view.js +213 -0
  38. package/web/search-view.test.js +144 -0
  39. package/web/shot-frame.d.ts +5 -0
  40. package/web/shot-frame.js +116 -0
  41. package/web/shot-frame.test.js +90 -0
  42. package/web/themes.js +1 -1
  43. package/web/view-url.d.ts +18 -0
  44. package/web/view-url.js +153 -6
  45. package/web/view-url.test.js +72 -1
  46. package/example-three-cloud/azure/composites/container-app-site.ts +0 -77
  47. package/example-three-cloud/dns/composites/latency-entry.ts +0 -73
  48. package/example-three-cloud/gcp/composites/public-cloud-run.ts +0 -102
@@ -1,5 +1,5 @@
1
1
  import { describe, expect, it } from "vitest";
2
- import { readViewQuery, writeViewQuery, settleView, settlePlace, refusalLine, isEnvName, withOpening, defaultEnv } from "./view-url.js";
2
+ import { readViewQuery, writeViewQuery, settleView, settlePlace, refusalLine, isEnvName, withOpening, defaultEnv, checkQuery, checkSnapshot, QUERY_MAX, viewFromObject, restoreViewQuery } from "./view-url.js";
3
3
 
4
4
  describe("readViewQuery (#475)", () => {
5
5
  it("reads the view keys and nothing else", () => {
@@ -20,6 +20,11 @@ describe("readViewQuery (#475)", () => {
20
20
  });
21
21
 
22
22
  describe("writeViewQuery (#475)", () => {
23
+ it("writes alike only when an estate draws every card, since stacked is the default (#877)", () => {
24
+ expect(writeViewQuery("", { zoom: "resources", alike: true })).toBe("?zoom=resources");
25
+ expect(writeViewQuery("", { zoom: "resources", alike: false })).toBe("?zoom=resources&alike=0");
26
+ expect(writeViewQuery("", { zoom: "logical", alike: undefined })).toBe("?zoom=logical");
27
+ });
23
28
  it("keeps parameters that are not the view's, and leaves defaults out", () => {
24
29
  const q = writeViewQuery("?embed=1&host=http%3A%2F%2Fa&member=old", { member: "delivery", zoom: "resources", env: null, lens: "drift", radial: false, node: null });
25
30
  expect(q).toBe("?embed=1&host=http%3A%2F%2Fa&member=delivery&zoom=resources");
@@ -157,3 +162,69 @@ describe("an export's opening view (#827)", () => {
157
162
  expect(writeViewQuery("", { zoom: "composites", env: null }, { env: defaultEnv({ env: "frozen" }, null) })).toBe("?zoom=composites&env=");
158
163
  });
159
164
  });
165
+
166
+ describe("q and snapshot (#913, #914)", () => {
167
+ it("reads and writes q and snapshot through the URL, + for a space and %2B for a plus", () => {
168
+ const q = "attr:internetFacing=true attr:effectiveIngress=tcp:22:0.0.0.0/0 a+b";
169
+ const search = writeViewQuery("", { zoom: "resources", env: "prod", q, snapshot: "latest" });
170
+ expect(search).toBe("?zoom=resources&env=prod&q=attr%3AinternetFacing%3Dtrue+attr%3AeffectiveIngress%3Dtcp%3A22%3A0.0.0.0%2F0+a%2Bb&snapshot=latest");
171
+ expect(readViewQuery(search)).toEqual({ zoom: "resources", env: "prod", q, snapshot: "latest" });
172
+ expect(readViewQuery("?q=")).toEqual({ q: null });
173
+ });
174
+ it("checkQuery passes chant's grammar through and refuses control characters, length and non-strings", () => {
175
+ expect(checkQuery(' ->kind:Bucket !"x <-a ')).toEqual({ ok: true, value: '->kind:Bucket !"x <-a' });
176
+ expect(checkQuery("")).toEqual({ ok: true, value: null });
177
+ expect(checkQuery(null)).toEqual({ ok: true, value: null });
178
+ expect(checkQuery("a\tb").ok).toBe(false);
179
+ expect(checkQuery("a\u007fb").ok).toBe(false);
180
+ expect(checkQuery("x".repeat(QUERY_MAX)).ok).toBe(true);
181
+ expect(checkQuery("x".repeat(QUERY_MAX + 1)).ok).toBe(false);
182
+ expect(checkQuery(3).ok).toBe(false);
183
+ });
184
+ it("settleView takes q, and a snapshot only on an env", () => {
185
+ expect(settleView({ q: "kind:Bucket" }, {})).toEqual({ apply: { q: "kind:Bucket" }, refused: [] });
186
+ expect(settleView({ q: "a\nb" }, {}).refused[0].key).toBe("q");
187
+ expect(settleView({ snapshot: "latest", env: "prod" }, { envs: ["prod"] }).apply).toEqual({ env: "prod", snapshot: "latest" });
188
+ expect(settleView({ snapshot: "latest" }, { env: "prod" }).apply).toEqual({ snapshot: "latest" });
189
+ expect(settleView({ snapshot: "latest" }, {}).refused[0]).toMatchObject({ key: "snapshot", reason: "a snapshot is of an env; name one with env" });
190
+ expect(settleView({ snapshot: "a b" }, { env: "prod" }).refused[0].key).toBe("snapshot");
191
+ expect(settleView({ snapshot: null }, {}).apply).toEqual({ snapshot: null });
192
+ expect(checkSnapshot("latest")).toEqual({ ok: true, value: "latest" });
193
+ });
194
+ });
195
+
196
+ describe("viewFromObject (#914)", () => {
197
+ it("takes the view keys and names everything else", () => {
198
+ const { want, refused } = viewFromObject({ q: "x", env: "", member: null, radial: true, zoom: "resources", at: "abc", other: 1, focus: 3 });
199
+ expect(want).toEqual({ q: "x", env: null, member: null, radial: true, zoom: "resources" });
200
+ expect(refused.map((r) => r.key)).toEqual(["at", "other", "focus"]);
201
+ expect(refused[0].reason).toMatch(/git revision/);
202
+ });
203
+ it("refuses a view that isn't an object", () => {
204
+ expect(viewFromObject("q=x").refused[0].key).toBe("view");
205
+ expect(viewFromObject(null).want).toEqual({});
206
+ });
207
+ });
208
+
209
+ describe("restoreViewQuery (#914)", () => {
210
+ it("clears what the URL leaves out, so Back undoes a move", () => {
211
+ expect(restoreViewQuery("?zoom=resources", { env: "prod", lens: "cost" })).toEqual({
212
+ zoom: "resources",
213
+ member: null,
214
+ gates: null,
215
+ focus: null,
216
+ run: null,
217
+ pull: null,
218
+ q: null,
219
+ snapshot: null,
220
+ countBy: null, // behold#922: no countBy is no grouping
221
+ radial: false,
222
+ plan: false, // behold#922: no plan is the declared source
223
+ alike: true,
224
+ env: "prod",
225
+ lens: "cost",
226
+ });
227
+ expect(restoreViewQuery("?zoom=logical&env=&q=kind%3AX").env).toBe(null);
228
+ expect(restoreViewQuery("?zoom=logical&env=&q=kind%3AX").q).toBe("kind:X");
229
+ });
230
+ });
@@ -1,77 +0,0 @@
1
- // A website on Azure Container Apps, set up the way a production environment
2
- // is, as two composites: ContainerAppNetwork, the VNet with a subnet delegated
3
- // to Container Apps, and ContainerAppSite, an environment in that subnet that
4
- // ships its logs to a Log Analytics workspace, with an app running as a
5
- // user-assigned identity.
6
- // Container Apps brings its own ingress and load balancing, so there is no
7
- // load balancer to declare.
8
- //
9
- // The body is a list of `const`s and a `return`, so `chant build` reads it
10
- // rather than running it and records which argument fed which field.
11
- import { Composite } from "@intentius/chant";
12
- import { LogAnalyticsWorkspace, ManagedIdentity, Subnet, VirtualNetwork, managedEnvironments, containerApps } from "@intentius/chant-lexicon-azure";
13
-
14
- export interface ContainerAppNetworkProps {
15
- /** The network is named `<name>-vnet`, its subnet `apps`. */
16
- name: string;
17
- location: string;
18
- addressSpace: string;
19
- /** The environment's subnet: a /23 or larger, delegated to Container Apps. */
20
- subnetPrefix: string;
21
- }
22
-
23
- /** The VNet a Container Apps environment sits in, with its delegated subnet. */
24
- export const ContainerAppNetwork = Composite((props: ContainerAppNetworkProps) => {
25
- const vnet = new VirtualNetwork({ name: `${props.name}-vnet`, location: props.location, addressSpace: { addressPrefixes: [props.addressSpace] } });
26
- const subnet = new Subnet({
27
- name: `${props.name}-vnet/apps`,
28
- addressPrefix: props.subnetPrefix,
29
- delegations: [{ name: "apps", properties: { serviceName: "Microsoft.App/environments" } }],
30
- });
31
- return { vnet, subnet };
32
- }, "ContainerAppNetwork");
33
-
34
- export interface ContainerAppSiteProps {
35
- /** The environment's name; the workspace, network and identity are named after it. */
36
- name: string;
37
- /** The app's name. */
38
- app: string;
39
- location: string;
40
- /** The subnet the environment goes in: a ContainerAppNetwork's. */
41
- subnet: { id: string };
42
- image: string;
43
- /** The port the container listens on; ingress forwards to it. */
44
- port: number;
45
- replicas: number;
46
- }
47
-
48
- export const ContainerAppSite = Composite((props: ContainerAppSiteProps) => {
49
- const logs = new LogAnalyticsWorkspace({ name: `${props.name}-logs`, location: props.location, sku: { name: "PerGB2018" }, retentionInDays: 30 });
50
- const identity = new ManagedIdentity({ name: `${props.name}-${props.app}`, location: props.location });
51
- const env = new managedEnvironments({
52
- name: props.name,
53
- location: props.location,
54
- vnetConfiguration: { infrastructureSubnetId: props.subnet.id, internal: false },
55
- appLogsConfiguration: {
56
- destination: "log-analytics",
57
- logAnalyticsConfiguration: {
58
- customerId: `[reference(resourceId('Microsoft.OperationalInsights/workspaces', '${props.name}-logs')).customerId]`,
59
- sharedKey: `[listKeys(resourceId('Microsoft.OperationalInsights/workspaces', '${props.name}-logs'), '2023-09-01').primarySharedKey]`,
60
- },
61
- },
62
- workloadProfiles: [{ name: "Consumption", workloadProfileType: "Consumption" }],
63
- });
64
- const app = new containerApps({
65
- name: props.app,
66
- location: props.location,
67
- identity: { type: "UserAssigned", userAssignedIdentities: { [`[resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', '${props.name}-${props.app}')]`]: {} } },
68
- managedEnvironmentId: env.id,
69
- workloadProfileName: "Consumption",
70
- configuration: { ingress: { external: true, targetPort: props.port, transport: "auto" } },
71
- template: {
72
- containers: [{ name: props.app, image: props.image, resources: { cpu: 0.25, memory: "0.5Gi" } }],
73
- scale: { minReplicas: props.replicas, maxReplicas: props.replicas },
74
- },
75
- });
76
- return { logs, identity, env, app };
77
- }, "ContainerAppSite");
@@ -1,73 +0,0 @@
1
- // One cloud's way in through Route 53: a latency record for the shared name,
2
- // guarded by a health check on that cloud's endpoint. A record whose check
3
- // fails stops answering, and the other clouds' records take its traffic.
4
- //
5
- // Two shapes, by what the cloud hands over. HostnameEntry is for an endpoint
6
- // with a hostname (a load balancer's, a Container App's): the record is a
7
- // CNAME to it and the check probes it by name. AddressEntry is for an
8
- // endpoint that is an IP address (a GCP load balancer): it gets a name of its
9
- // own, an A record, the latency record points at that name, and the check
10
- // probes the address.
11
- //
12
- // Latency records sharing a name must share a type, which is why the address
13
- // gets its own A record instead of the latency record being one.
14
- //
15
- // The bodies are `const`s and a `return`, so `chant build` reads them rather
16
- // than running them.
17
- import { Composite } from "@intentius/chant";
18
- import { HealthCheck, RecordSet } from "@intentius/chant-lexicon-aws";
19
-
20
- export interface EntryProps {
21
- /** The hosted zone's id (`zone.Id`). */
22
- zoneId: string;
23
- /** The name every cloud answers for. */
24
- name: string;
25
- /** The cloud, as the record's set identifier. */
26
- id: string;
27
- /** The AWS region whose latency this record is chosen for. */
28
- region: string;
29
- /** The cloud's endpoint: a hostname, or for AddressEntry an IP address. */
30
- endpoint: string;
31
- }
32
-
33
- export const HostnameEntry = Composite((props: EntryProps) => {
34
- const check = new HealthCheck({
35
- HealthCheckConfig: { Type: "HTTP", FullyQualifiedDomainName: props.endpoint, ResourcePath: "/", RequestInterval: 10, FailureThreshold: 1 },
36
- });
37
- const record = new RecordSet({
38
- HostedZoneId: props.zoneId,
39
- Name: props.name,
40
- Type: "CNAME",
41
- TTL: "60",
42
- SetIdentifier: props.id,
43
- Region: props.region,
44
- ResourceRecords: [props.endpoint],
45
- HealthCheckId: check.HealthCheckId,
46
- });
47
- return { check, record };
48
- }, "HostnameEntry");
49
-
50
- export interface AddressEntryProps extends EntryProps {
51
- /** The name the address is published under (an A record), which the latency record points at. */
52
- origin: string;
53
- /** The port the check probes. */
54
- port: number;
55
- }
56
-
57
- export const AddressEntry = Composite((props: AddressEntryProps) => {
58
- const check = new HealthCheck({
59
- HealthCheckConfig: { Type: "HTTP", IPAddress: props.endpoint, Port: props.port, ResourcePath: "/", RequestInterval: 10, FailureThreshold: 1 },
60
- });
61
- const origin = new RecordSet({ HostedZoneId: props.zoneId, Name: props.origin, Type: "A", TTL: "60", ResourceRecords: [props.endpoint] });
62
- const record = new RecordSet({
63
- HostedZoneId: props.zoneId,
64
- Name: props.name,
65
- Type: "CNAME",
66
- TTL: "60",
67
- SetIdentifier: props.id,
68
- Region: props.region,
69
- ResourceRecords: [props.origin],
70
- HealthCheckId: check.HealthCheckId,
71
- });
72
- return { check, origin, record };
73
- }, "AddressEntry");
@@ -1,102 +0,0 @@
1
- // A website on Cloud Run behind a global external Application Load Balancer,
2
- // set up the way production is, as two composites: PrivateEgressNetwork, a
3
- // custom VPC with a subnet for the service's egress, and PublicCloudRun, the
4
- // service running as its own service account and reached through a
5
- // reserved address, a forwarding rule, an HTTP proxy, a URL map, a backend
6
- // service and a serverless network endpoint group that names it.
7
- //
8
- // The body is a list of `const`s and a `return`, so `chant build` reads it
9
- // rather than running it and records which argument fed which field.
10
- import { Composite } from "@intentius/chant";
11
- import {
12
- BackendService,
13
- CloudRunServiceComposite,
14
- ComputeAddress,
15
- ForwardingRule,
16
- GCPServiceAccount,
17
- RegionNetworkEndpointGroup,
18
- Subnetwork,
19
- TargetHTTPProxy,
20
- URLMap,
21
- VPCNetwork,
22
- } from "@intentius/chant-lexicon-gcp";
23
-
24
- export interface PrivateEgressNetworkProps {
25
- /** The network is named `<name>-vpc`, its subnet `<name>-apps`. */
26
- name: string;
27
- region: string;
28
- /** The subnet a service's egress goes into. */
29
- subnetCidr: string;
30
- }
31
-
32
- /** A custom-mode VPC with one subnet in the region a service sends its egress into. */
33
- export const PrivateEgressNetwork = Composite((props: PrivateEgressNetworkProps) => {
34
- const vpc = new VPCNetwork({ metadata: { name: `${props.name}-vpc` }, autoCreateSubnetworks: false, routingMode: "REGIONAL" });
35
- const subnet = new Subnetwork({ metadata: { name: `${props.name}-apps` }, region: props.region, ipCidrRange: props.subnetCidr, networkRef: { name: vpc.name } });
36
- return { vpc, subnet };
37
- }, "PrivateEgressNetwork");
38
-
39
- export interface PublicCloudRunProps {
40
- /** The prefix every resource is named with. */
41
- name: string;
42
- project: string;
43
- region: string;
44
- /** The network its egress goes into: a PrivateEgressNetwork's VPC and subnet. */
45
- vpc: { name: string };
46
- subnet: { name: string };
47
- image: string;
48
- /** The port the container listens on. */
49
- port: number;
50
- instances: number;
51
- }
52
-
53
- export const PublicCloudRun = Composite((props: PublicCloudRunProps) => {
54
- const runtime = new GCPServiceAccount({ metadata: { name: `${props.name}-run` }, displayName: `${props.name} website runtime` });
55
- const run = CloudRunServiceComposite({
56
- name: `${props.name}-site`,
57
- image: props.image,
58
- projectId: props.project,
59
- location: props.region,
60
- port: props.port,
61
- minInstanceCount: props.instances,
62
- maxInstanceCount: props.instances,
63
- publicAccess: true,
64
- serviceAccount: `${props.name}-run`,
65
- defaults: {
66
- service: {
67
- template: {
68
- vpcAccess: { egress: "PRIVATE_RANGES_ONLY", networkInterfaces: [{ networkRef: { name: props.vpc.name }, subnetworkRef: { name: props.subnet.name } }] },
69
- },
70
- },
71
- },
72
- });
73
- const service = run.service;
74
- const publicAccess = run.publicIam;
75
- const neg = new RegionNetworkEndpointGroup({
76
- metadata: { name: `${props.name}-neg` },
77
- region: props.region,
78
- networkEndpointType: "SERVERLESS",
79
- cloudRun: { serviceRef: { name: service.name } },
80
- });
81
- // A backend service over a serverless NEG takes no health check: Cloud Run
82
- // reports its own readiness.
83
- const backend = new BackendService({
84
- metadata: { name: `${props.name}-backend` },
85
- location: "global",
86
- loadBalancingScheme: "EXTERNAL_MANAGED",
87
- protocol: "HTTP",
88
- backend: [{ group: { networkEndpointGroupRef: { name: neg.name } } }],
89
- });
90
- const urlMap = new URLMap({ metadata: { name: `${props.name}-map` }, location: "global", defaultService: { backendServiceRef: { name: backend.name } } });
91
- const proxy = new TargetHTTPProxy({ metadata: { name: `${props.name}-proxy` }, location: "global", urlMapRef: { name: urlMap.name } });
92
- const address = new ComputeAddress({ metadata: { name: `${props.name}-ip` }, location: "global" });
93
- const rule = new ForwardingRule({
94
- metadata: { name: `${props.name}-rule` },
95
- location: "global",
96
- loadBalancingScheme: "EXTERNAL_MANAGED",
97
- portRange: String(props.port),
98
- ipAddress: { addressRef: { name: address.name } },
99
- target: { targetHTTPProxyRef: { name: proxy.name } },
100
- });
101
- return { runtime, service, publicAccess, neg, backend, urlMap, proxy, address, rule };
102
- }, "PublicCloudRun");