@su-sws/synthetic-web-team 0.2.7 → 0.2.9
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/AGENTS.md +6 -0
- package/README.md +113 -11
- package/package.json +3 -2
- package/packages/cli/bin/sws.mjs +162 -14
- package/packages/cli/src/acknowledged.mjs +6 -1
- package/packages/cli/src/brief.mjs +393 -0
- package/packages/cli/src/preflight.mjs +1 -1
- package/packages/cli/src/prior-art.mjs +329 -0
- package/packages/cli/src/report.mjs +21 -2
- package/packages/wizard/bin/wizard.mjs +299 -12
- package/packages/wizard/src/detect.mjs +111 -1
- package/packages/wizard/src/emit.mjs +130 -9
- package/skills/role-api-architect/SKILL.md +119 -61
- package/skills/role-backend-developer/SKILL.md +145 -55
- package/skills/role-compliance-officer/SKILL.md +133 -57
- package/skills/role-devops/SKILL.md +9 -6
- package/skills/role-fullstack-developer/SKILL.md +104 -37
- package/skills/role-identity-engineer/SKILL.md +126 -60
- package/skills/role-information-architect/SKILL.md +1 -1
- package/skills/role-infrastructure-architect/SKILL.md +105 -32
- package/skills/role-qa-engineer/SKILL.md +128 -57
- package/skills/role-security-operations/SKILL.md +137 -33
- package/skills/role-software-architect/SKILL.md +133 -63
- package/skills/role-staff-technical-architect/SKILL.md +112 -50
- package/skills/role-user-researcher/SKILL.md +119 -45
- package/skills/role-ux-designer/SKILL.md +1 -1
- package/skills/sws-compliance-check/SKILL.md +1 -1
- package/skills/sws-diverge/SKILL.md +2 -2
- package/skills/sws-github/SKILL.md +2 -0
- package/skills/sws-install/SKILL.md +1 -1
- package/skills/sws-netlify/SKILL.md +2 -0
- package/skills/sws-preflight/SKILL.md +5 -0
- package/skills/sws-vercel/SKILL.md +2 -0
- package/standards/hosting/github-pages.yml +1 -0
- package/standards/hosting/netlify.yml +1 -0
- package/standards/hosting/vercel.yml +1 -0
- package/standards/patterns/bolt-ons.md +1 -1
- package/standards/policy/identity.md +1 -1
|
@@ -74,10 +74,28 @@ const LEGACY_POINTER_COMMENT = `<!--
|
|
|
74
74
|
// copies is the floor rather than a design flaw -- see docs/skill-paths.md.
|
|
75
75
|
export const SKILL_TARGETS = ['.agents/skills', '.claude/skills'];
|
|
76
76
|
|
|
77
|
+
// HOW EACH TOOL GETS ITS SKILLS, where that is not a copy written here.
|
|
78
|
+
//
|
|
79
|
+
// The one entry so far: `{ 'claude-code': 'plugin' }`. The same skills ship as
|
|
80
|
+
// a Claude Code plugin, and with both in place Claude Code lists every skill
|
|
81
|
+
// twice, from two update channels. Someone who chose the plugin says so with
|
|
82
|
+
// `install --claude-plugin`, and from then on .claude/skills is not planned.
|
|
83
|
+
// Null, the default, means a copy at every target, which is what every release
|
|
84
|
+
// before this did and what everyone who never passes the flag still gets.
|
|
85
|
+
//
|
|
86
|
+
// .agents/skills is never dropped: it is what every other tool reads.
|
|
87
|
+
export const CLAUDE_SKILLS = '.claude/skills';
|
|
88
|
+
export const PLUGIN_DELIVERY = { 'claude-code': 'plugin' };
|
|
89
|
+
const viaPlugin = (delivery) => delivery?.['claude-code'] === 'plugin';
|
|
90
|
+
|
|
91
|
+
export function skillTargets(delivery = null) {
|
|
92
|
+
return SKILL_TARGETS.filter((t) => !(t === CLAUDE_SKILLS && viaPlugin(delivery)));
|
|
93
|
+
}
|
|
94
|
+
|
|
77
95
|
const skillNames = (source) => readdirSync(join(source, 'skills'))
|
|
78
96
|
.filter((d) => existsSync(join(source, 'skills', d, 'SKILL.md')));
|
|
79
97
|
|
|
80
|
-
export function plan({ root, source, editors, answers, tier, scope = 'project', layout = 'root' }) {
|
|
98
|
+
export function plan({ root, source, editors, answers, tier, scope = 'project', layout = 'root', delivery = null }) {
|
|
81
99
|
const files = [];
|
|
82
100
|
const add = (path, contents, note, opts = {}) => files.push({ path, contents, note, ...opts });
|
|
83
101
|
|
|
@@ -90,7 +108,7 @@ export function plan({ root, source, editors, answers, tier, scope = 'project',
|
|
|
90
108
|
//
|
|
91
109
|
// Nothing per-site is emitted here, because at this point there is no site.
|
|
92
110
|
if (scope === 'user') {
|
|
93
|
-
for (const target of
|
|
111
|
+
for (const target of skillTargets(delivery)) {
|
|
94
112
|
for (const name of skillNames(source)) {
|
|
95
113
|
add(`${target}/${name}/SKILL.md`,
|
|
96
114
|
readFileSync(join(source, 'skills', name, 'SKILL.md'), 'utf8'), null);
|
|
@@ -184,8 +202,12 @@ export function plan({ root, source, editors, answers, tier, scope = 'project',
|
|
|
184
202
|
// The server is a SECOND entry point, never a requirement: everything it
|
|
185
203
|
// exposes is also a file in .sws/standards/ that the agent can read directly.
|
|
186
204
|
// If the client cannot start it, nothing else stops working.
|
|
187
|
-
|
|
188
|
-
|
|
205
|
+
//
|
|
206
|
+
// Exported so a check can hold the Claude Code plugin's own `mcpServers` entry
|
|
207
|
+
// to exactly this. Claude Code connects one server when a project's .mcp.json
|
|
208
|
+
// and the plugin name the same command, and two when they drift apart.
|
|
209
|
+
export const SERVER_NAME = 'sws';
|
|
210
|
+
export const SERVER = { command: 'npx', args: ['-y', '@su-sws/synthetic-web-team-mcp'] };
|
|
189
211
|
|
|
190
212
|
const MD_POINTER = ['<!-- BEGIN:sws-pointer -->', '<!-- END:sws-pointer -->'];
|
|
191
213
|
const TOML_POINTER = ['# BEGIN:sws-pointer', '# END:sws-pointer'];
|
|
@@ -455,6 +477,14 @@ const ACKNOWLEDGED_TEMPLATE = `# Accepted risks.
|
|
|
455
477
|
* moved A file an earlier version wrote somewhere else, `standards/` at
|
|
456
478
|
* the root, now under .sws/. Listed separately in the result.
|
|
457
479
|
*
|
|
480
|
+
* And one at user scope only, when a tool's skills come from somewhere else:
|
|
481
|
+
*
|
|
482
|
+
* retired A copy this tool wrote into a skills directory it no longer
|
|
483
|
+
* plans, because `delivery` says that tool gets its skills another
|
|
484
|
+
* way. Deleted only when the record lists it and it still hashes
|
|
485
|
+
* to what was written; an edited one stays, as a conflict. See
|
|
486
|
+
* retire().
|
|
487
|
+
*
|
|
458
488
|
* Comparison is by content, never mtime: re-running the same version must be
|
|
459
489
|
* `unchanged` even though the source files have newer timestamps.
|
|
460
490
|
*
|
|
@@ -462,7 +492,7 @@ const ACKNOWLEDGED_TEMPLATE = `# Accepted risks.
|
|
|
462
492
|
* and writing the import through it would replace the contract with a line that
|
|
463
493
|
* imports itself.
|
|
464
494
|
*/
|
|
465
|
-
export function write(root, files, { force = false, version = null, scope = 'project', layout = 'root' } = {}) {
|
|
495
|
+
export function write(root, files, { force = false, version = null, scope = 'project', layout = 'root', delivery = null } = {}) {
|
|
466
496
|
const prev = readInstalled(root);
|
|
467
497
|
let planned = new Set(files.map((f) => f.path));
|
|
468
498
|
|
|
@@ -581,9 +611,18 @@ export function write(root, files, { force = false, version = null, scope = 'pro
|
|
|
581
611
|
results.push({ path: f.path, status, ...(reason ? { reason } : {}) });
|
|
582
612
|
}
|
|
583
613
|
|
|
614
|
+
// Copies in a skills directory that is no longer planned. Before the orphans
|
|
615
|
+
// are counted: a retired file is gone, so it is not one, and a kept one is a
|
|
616
|
+
// conflict, which is the louder of the two reports.
|
|
617
|
+
const retiring = scope === 'user'
|
|
618
|
+
? retire(root, prev, planned, delivery, { force })
|
|
619
|
+
: { retired: [], kept: [] };
|
|
620
|
+
const held = new Set(retiring.kept.map((k) => k.path));
|
|
621
|
+
|
|
584
622
|
// A moved file's old path no longer exists, so it drops out of the record
|
|
585
623
|
// here rather than reporting as an orphan.
|
|
586
|
-
const orphans = Object.keys(prev?.files ?? {})
|
|
624
|
+
const orphans = Object.keys(prev?.files ?? {})
|
|
625
|
+
.filter((x) => !planned.has(x) && !held.has(x) && existsSync(join(root, x)));
|
|
587
626
|
|
|
588
627
|
// Keep orphans in the record while the file still exists, so they are reported
|
|
589
628
|
// on EVERY run rather than once. A one-shot warning is easy to miss -- an agent
|
|
@@ -593,7 +632,12 @@ export function write(root, files, { force = false, version = null, scope = 'pro
|
|
|
593
632
|
// when it has been seen once.
|
|
594
633
|
for (const x of orphans) nextHashes[x] = prev.files[x];
|
|
595
634
|
|
|
596
|
-
|
|
635
|
+
// A copy that was kept stays in the record under the hash of what we wrote,
|
|
636
|
+
// for the reason a conflict does: it is reported on every run, `--remove`
|
|
637
|
+
// still knows it was ours, and switching back still sees it as edited.
|
|
638
|
+
for (const x of held) nextHashes[x] = prev.files[x];
|
|
639
|
+
|
|
640
|
+
writeInstalled(root, { version, files: nextHashes, scope, layout, delivery });
|
|
597
641
|
|
|
598
642
|
const count = (s) => results.filter((r) => r.status === s).length;
|
|
599
643
|
return {
|
|
@@ -601,16 +645,79 @@ export function write(root, files, { force = false, version = null, scope = 'pro
|
|
|
601
645
|
orphans,
|
|
602
646
|
moved,
|
|
603
647
|
deferred,
|
|
648
|
+
retired: retiring.retired,
|
|
649
|
+
kept: retiring.kept,
|
|
604
650
|
previousVersion: prev?.version ?? null,
|
|
605
651
|
created: count('created'),
|
|
606
652
|
updated: count('updated'),
|
|
607
653
|
unchanged: count('unchanged'),
|
|
608
654
|
preserved: count('preserved'),
|
|
609
655
|
merged: count('merged'),
|
|
610
|
-
conflicts: results.filter((r) => r.status === 'conflict').map((r) => r.path),
|
|
656
|
+
conflicts: [...results.filter((r) => r.status === 'conflict').map((r) => r.path), ...held],
|
|
611
657
|
};
|
|
612
658
|
}
|
|
613
659
|
|
|
660
|
+
// What a run would retire, and what it would keep, for a dry run and for the
|
|
661
|
+
// list shown before anything is written. Reads, never writes.
|
|
662
|
+
export function plannedRetire(root, files, { delivery = null, force = false } = {}) {
|
|
663
|
+
return retire(root, readInstalled(root), new Set(files.map((f) => f.path)), delivery, { dryRun: true, force });
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
/**
|
|
667
|
+
* Take back the copies this tool wrote into a skills directory it no longer
|
|
668
|
+
* writes, because the tool that reads it gets its skills another way.
|
|
669
|
+
*
|
|
670
|
+
* The case: `install` put 31 skills in ~/.claude/skills, and the person then
|
|
671
|
+
* installed the Claude Code plugin, which carries the same 31. Leaving both
|
|
672
|
+
* means every skill is listed twice and the home copy wins a bare reference,
|
|
673
|
+
* so choosing the plugin has to be able to remove the copies. `--remove`
|
|
674
|
+
* cannot do it: it takes ~/.agents/skills too, which other tools still read.
|
|
675
|
+
*
|
|
676
|
+
* Driven by the install record only, the rule `remove()` and `migrate()`
|
|
677
|
+
* follow, and narrower than either:
|
|
678
|
+
*
|
|
679
|
+
* - only a path the record lists, and only one of the exact shape a user
|
|
680
|
+
* install writes, `<target>/<name>/SKILL.md`. A home skills directory
|
|
681
|
+
* holds hundreds of other people's skills. None of them is in the record,
|
|
682
|
+
* so none of them is ever looked at.
|
|
683
|
+
* - only while it still hashes to what was written. An edited copy is
|
|
684
|
+
* somebody's work: it stays, and is reported as a conflict on every run
|
|
685
|
+
* until it is dealt with. `force` removes it, as it does for `--remove`.
|
|
686
|
+
* - never a symbolic link, with or without `force`.
|
|
687
|
+
* - a file already gone is simply dropped from the record.
|
|
688
|
+
*
|
|
689
|
+
* Emptied directories are pruned, so `.claude/skills/<name>/` goes with its
|
|
690
|
+
* SKILL.md and `.claude/skills/` itself survives while anything else is in it.
|
|
691
|
+
*/
|
|
692
|
+
function retire(root, prev, planned, delivery, { dryRun = false, force = false } = {}) {
|
|
693
|
+
const retired = [];
|
|
694
|
+
const kept = [];
|
|
695
|
+
const dropped = SKILL_TARGETS.filter((t) => !skillTargets(delivery).includes(t));
|
|
696
|
+
if (!dropped.length) return { retired, kept };
|
|
697
|
+
|
|
698
|
+
const ours = (rel) => dropped.some((t) => {
|
|
699
|
+
if (!rel.startsWith(`${t}/`)) return false;
|
|
700
|
+
const [name, file, ...more] = rel.slice(t.length + 1).split('/');
|
|
701
|
+
return file === 'SKILL.md' && !more.length && Boolean(name) && name !== '.' && name !== '..';
|
|
702
|
+
});
|
|
703
|
+
|
|
704
|
+
for (const [rel, recorded] of Object.entries(prev?.files ?? {})) {
|
|
705
|
+
if (planned.has(rel) || !ours(rel)) continue;
|
|
706
|
+
const p = join(root, rel);
|
|
707
|
+
const st = lstatSync(p, { throwIfNoEntry: false });
|
|
708
|
+
if (!st) continue;
|
|
709
|
+
if (st.isSymbolicLink()) { kept.push({ path: rel, reason: 'symlink' }); continue; }
|
|
710
|
+
if (!st.isFile() || (!force && hash(readFileSync(p, 'utf8')) !== recorded)) {
|
|
711
|
+
kept.push({ path: rel, reason: 'edited' });
|
|
712
|
+
continue;
|
|
713
|
+
}
|
|
714
|
+
if (!dryRun) rmSync(p);
|
|
715
|
+
retired.push(rel);
|
|
716
|
+
}
|
|
717
|
+
if (!dryRun) pruneEmpty(root, retired);
|
|
718
|
+
return { retired, kept };
|
|
719
|
+
}
|
|
720
|
+
|
|
614
721
|
// What a re-run would move, or why it would wait, for a dry run, which writes
|
|
615
722
|
// nothing.
|
|
616
723
|
export function plannedMigration(root, files, { force = false } = {}) {
|
|
@@ -1055,7 +1162,13 @@ export function readInstalled(root) {
|
|
|
1055
1162
|
}
|
|
1056
1163
|
}
|
|
1057
1164
|
|
|
1058
|
-
|
|
1165
|
+
// The delivery choice the record holds, or null. Anything this version does not
|
|
1166
|
+
// recognise reads as null, the default, rather than as a choice nobody made.
|
|
1167
|
+
export function readDelivery(root) {
|
|
1168
|
+
return viaPlugin(readInstalled(root)?.delivery) ? { ...PLUGIN_DELIVERY } : null;
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
function writeInstalled(root, { version, files, scope = 'project', layout = 'root', delivery = null }) {
|
|
1059
1172
|
// The advice differs by scope, and getting it wrong matters: "commit this" is
|
|
1060
1173
|
// right in a repository and nonsense in a home directory.
|
|
1061
1174
|
const advice = scope === 'user'
|
|
@@ -1072,6 +1185,10 @@ function writeInstalled(root, { version, files, scope = 'project', layout = 'roo
|
|
|
1072
1185
|
scope,
|
|
1073
1186
|
// Only when it is not the default, so a root install's record is unchanged.
|
|
1074
1187
|
...(layout === 'contained' ? { layout } : {}),
|
|
1188
|
+
// The same rule, at user scope: present only once someone has chosen the
|
|
1189
|
+
// plugin, so a plain `install` afterwards keeps the choice instead of
|
|
1190
|
+
// writing .claude/skills back.
|
|
1191
|
+
...(scope === 'user' && viaPlugin(delivery) ? { delivery: { ...PLUGIN_DELIVERY } } : {}),
|
|
1075
1192
|
version,
|
|
1076
1193
|
at: new Date().toISOString(),
|
|
1077
1194
|
files,
|
|
@@ -1124,6 +1241,10 @@ export function remove(root, { dryRun = false, force = false } = {}) {
|
|
|
1124
1241
|
writeInstalled(root, {
|
|
1125
1242
|
version: prev.version ?? null,
|
|
1126
1243
|
scope: prev.scope ?? 'project',
|
|
1244
|
+
// Carried, so the files that stayed are still read under the choice
|
|
1245
|
+
// they were kept under. With nothing kept the record goes, and the
|
|
1246
|
+
// choice with it: an uninstall leaves no settings behind.
|
|
1247
|
+
delivery: prev.delivery,
|
|
1127
1248
|
files: Object.fromEntries(kept.map((k) => [k, prev.files[k]])),
|
|
1128
1249
|
});
|
|
1129
1250
|
} else if (existsSync(recordPath)) {
|
|
@@ -1,65 +1,123 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: role-api-architect
|
|
3
|
-
description:
|
|
3
|
+
description: Data integration and API design for Stanford sites. Use when a site consumes a Stanford data source (events, news, profiles, MaIS Registry, Workgroup API), when designing a build-time fetch or scheduled snapshot, when shaping a small endpoint a site exposes, or when someone asks how to get university data onto a page.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
# API architecture
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
##
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
6
|
+
# API architecture and data integration
|
|
7
|
+
|
|
8
|
+
On a Stanford unit site this role is mostly about **consuming** university data
|
|
9
|
+
safely, not designing APIs. The house shape is build-time consumption, and the hard
|
|
10
|
+
parts are permissions, approvals, and data risk rather than HTTP.
|
|
11
|
+
|
|
12
|
+
## Default shape: fetch at build, never from the browser
|
|
13
|
+
|
|
14
|
+
The connector shape in `standards/connectors/README.md` is the starting point for
|
|
15
|
+
any external data:
|
|
16
|
+
|
|
17
|
+
1. **Fetch at build time or on a schedule**, never from the visitor's browser. No
|
|
18
|
+
key reaches the browser, a source outage does not break a page, and the content
|
|
19
|
+
is in the built HTML where `sws a11y` can see it.
|
|
20
|
+
2. **Snapshot into the repo.** A scheduled Actions job writes a data file and commits
|
|
21
|
+
it to `main`, which deploys. Every content change goes through the checks.
|
|
22
|
+
Fetching at build without committing is the alternative: fewer commits, no git
|
|
23
|
+
history of the content.
|
|
24
|
+
3. **Credentials live in Actions secrets**, never in the repo or the build output.
|
|
25
|
+
4. **Link back to the source.** The source stays authoritative.
|
|
26
|
+
5. **Permission belongs to the system owner.** Being able to reach an API is not the
|
|
27
|
+
same as being allowed to depend on it.
|
|
28
|
+
|
|
29
|
+
Whether a snapshot counts as "content from the repo" is an open call for SWS
|
|
30
|
+
(`standards/scope.md`). Say that if it matters to the decision.
|
|
31
|
+
|
|
32
|
+
## Before you integrate: five questions
|
|
33
|
+
|
|
34
|
+
Ask these in discovery. Each one can delay a launch by weeks if it surfaces late.
|
|
35
|
+
|
|
36
|
+
1. **What does the page actually need to show?** Fetch that, not the whole record.
|
|
37
|
+
2. **Who owns the source, and have they agreed?** If the owner is unknown, use the
|
|
38
|
+
general UIT contact and say so.
|
|
39
|
+
3. **What risk class is the data?** Person data is almost certainly Moderate or High
|
|
40
|
+
risk, which changes the tier of anything that stores it.
|
|
41
|
+
4. **What authentication does the source require, and how long does access take?**
|
|
42
|
+
5. **What happens when the source is down or changes shape?** The build should fail
|
|
43
|
+
loudly or keep the last good snapshot, never publish an empty page.
|
|
44
|
+
|
|
45
|
+
## Stanford sources
|
|
46
|
+
|
|
47
|
+
| Source | What is known | Status |
|
|
48
|
+
|---|---|---|
|
|
49
|
+
| **Events**, events.stanford.edu (Localist) | Public API confirmed reachable | Connector stub |
|
|
50
|
+
| **News**, news.stanford.edu | API not yet located | Connector stub |
|
|
51
|
+
| **Profiles**, cap.stanford.edu (CAP) | Access not yet confirmed | Connector stub |
|
|
52
|
+
| **MaIS Registry APIs** | Account, CourseClass, Person, Privilege and Authority, Student, Workgroup | See below |
|
|
53
|
+
| **Workgroup API 2.0** | JSON, at `workgroupsvc.stanford.edu/workgroups/2.0/`, with a UAT equivalent and an AWS API Gateway variant | See below |
|
|
54
|
+
|
|
55
|
+
None of the connectors is a tested integration. Read the connector file, use what is
|
|
56
|
+
known, and **do not invent endpoints, fields, or credentials.**
|
|
57
|
+
|
|
58
|
+
### MaIS Registry and Workgroup, which surprise people
|
|
59
|
+
|
|
60
|
+
- **Authentication is x509 mutual TLS**, not an API key and not OAuth. You submit a
|
|
61
|
+
CSR to the MaIS Certificate Manager and the certificate is added as a workgroup
|
|
62
|
+
admin for access.
|
|
63
|
+
- **Access requires data-owner approval** plus an intake ticket, with a lead time in
|
|
64
|
+
weeks. It belongs in discovery, not the build.
|
|
65
|
+
- **Workgroups are Stanford's authorisation primitive.** You ask whether someone is
|
|
66
|
+
in a workgroup instead of keeping your own list.
|
|
67
|
+
|
|
68
|
+
Say the mutual-TLS requirement and the approval lead time early. Both routinely
|
|
69
|
+
delay launches.
|
|
70
|
+
|
|
71
|
+
## Designing the integration
|
|
72
|
+
|
|
73
|
+
- **Type the boundary.** Validate the fetched payload against a schema at build
|
|
74
|
+
time, so a changed upstream fails the build instead of rendering `undefined`.
|
|
75
|
+
`adapt-directory` turns an OpenAPI spec into TypeScript types via codegen, which is
|
|
76
|
+
worth borrowing when a spec exists.
|
|
77
|
+
- **Mock the source for local work.** `adapt-directory` also runs a mock server for
|
|
78
|
+
when the upstream is unavailable. That pattern is worth stealing.
|
|
79
|
+
- **Keep the last good snapshot.** If a scheduled pull fails, do not commit an empty
|
|
80
|
+
file. Leave the previous one and surface the failure.
|
|
81
|
+
- **Normalise once.** Map the source's fields to the site's content model in one
|
|
82
|
+
place, so the templates never see the upstream shape.
|
|
83
|
+
- **Store less.** Do not keep person data because it was easy to fetch. Ask what the
|
|
84
|
+
site needs to display.
|
|
85
|
+
|
|
86
|
+
## If the site exposes an endpoint
|
|
87
|
+
|
|
88
|
+
Small endpoints on `astro-ssr` or `next-ssr` (a search route, a form handler) are in
|
|
89
|
+
scope and owned by `role-backend-developer`. Design notes:
|
|
90
|
+
|
|
91
|
+
- One job per endpoint, a stable URL, and errors as structured JSON with a useful
|
|
92
|
+
message.
|
|
93
|
+
- No authentication you invented. Stanford has workgroups and SSO; see
|
|
94
|
+
`role-identity-engineer`.
|
|
95
|
+
- No personal data in query strings, which end up in logs and referrers.
|
|
96
|
+
|
|
97
|
+
A standalone API with its own consumers is a different project from a website and
|
|
98
|
+
outside this package. The `engineering:architecture` and `engineering:system-design`
|
|
99
|
+
skills cover general design without Stanford specifics.
|
|
100
|
+
|
|
101
|
+
## When reviewing an integration
|
|
102
|
+
|
|
103
|
+
- Is the data fetched at build or on a schedule, and nowhere in the browser?
|
|
104
|
+
- Has the source owner agreed, and is that recorded?
|
|
105
|
+
- What risk class is the data, and did the tier move?
|
|
106
|
+
- Are credentials in Actions secrets or Vault, and absent from the build?
|
|
107
|
+
- Does a broken or changed source fail visibly without publishing an empty page?
|
|
108
|
+
- Does each item link back to its canonical source?
|
|
109
|
+
|
|
110
|
+
## Artifacts
|
|
111
|
+
|
|
112
|
+
| Artifact | Path |
|
|
113
|
+
|---|---|
|
|
114
|
+
| Data snapshots | `src/data/` |
|
|
115
|
+
| Fetch scripts | `scripts/`, so CI can call them |
|
|
116
|
+
| Scheduled workflow | `.github/workflows/` |
|
|
117
|
+
| Source, owner, and data class | `.sws/manifest.yml` under `divergences:` |
|
|
118
|
+
|
|
119
|
+
## Escalation
|
|
120
|
+
|
|
121
|
+
Data access requests route through the source's intake. For a Data Risk Assessment
|
|
122
|
+
or an unknown owner, route per `standards/policy/escalation.md`; those routes still
|
|
123
|
+
need confirming, so use the general contact and say that is what you are doing.
|
|
@@ -1,66 +1,156 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: role-backend-developer
|
|
3
|
-
description: Server-side development for a Stanford site. Use for
|
|
3
|
+
description: Server-side development for a Stanford site. Use for form handlers, search endpoints, redirects and rewrites, response headers, serverless or edge functions, scheduled data pulls, webhooks, or any question about whether a site needs a back end at all. Covers the server surface the astro-ssr and next-ssr recipes allow; CMS back ends are out of scope.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Back-end development
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
A Stanford unit site usually has very little back end, and the job is keeping it
|
|
9
|
+
that way on purpose. Every route you add is something to patch under MinSec for as
|
|
10
|
+
long as the site lives, and some routes move the compliance tier.
|
|
10
11
|
|
|
11
|
-
##
|
|
12
|
+
## What is in scope
|
|
13
|
+
|
|
14
|
+
`standards/scope.md` puts a server runtime in scope for four things, and content
|
|
15
|
+
still comes from the repo:
|
|
16
|
+
|
|
17
|
+
| Need | Where it lives | Notes |
|
|
18
|
+
|---|---|---|
|
|
19
|
+
| **Response headers** | Host config, not code | The default set is in `standards/hosting/capabilities.yml`. **You do not need a server runtime for headers**: a static build on Netlify or Vercel gets them from host config |
|
|
20
|
+
| **Redirects and rewrites** | Host config first | Same. A runtime only earns its place for redirects that depend on the request |
|
|
21
|
+
| **Search** | A build-time index, or a server route | A build-time index adds no third party. A hosted search service does, and that is a DRA question |
|
|
22
|
+
| **Forms** | A host form feature, a function, or a route handler | A tier question before it is a code question. See below |
|
|
12
23
|
|
|
13
|
-
|
|
14
|
-
|
|
24
|
+
Anything else on the server side, such as fetching content from a backend, is a
|
|
25
|
+
CMS by another name and is out of scope (`standards/scope.md`). Out of scope is not
|
|
26
|
+
forbidden: if the unit needs one, say so plainly. Do not build half of one.
|
|
27
|
+
|
|
28
|
+
## First, ask whether you need a back end
|
|
15
29
|
|
|
16
30
|
Common requirements that do **not** need one:
|
|
17
31
|
|
|
18
|
-
- **Content that changes often.**
|
|
19
|
-
site
|
|
20
|
-
- **
|
|
21
|
-
- **
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
32
|
+
- **Content that changes often.** A commit to `main` from the GitHub web UI rebuilds
|
|
33
|
+
the site and keeps it static.
|
|
34
|
+
- **Headers and redirects.** Host config, as above.
|
|
35
|
+
- **Search on a small site.** A static index generated at build time.
|
|
36
|
+
- **A contact form.** A `mailto:` link or a link to an existing central form is
|
|
37
|
+
often the cheapest compliant answer. Offer it before building anything.
|
|
38
|
+
- **Restricting content.** See `role-identity-engineer`. Often the answer is not
|
|
39
|
+
publishing it.
|
|
40
|
+
|
|
41
|
+
If nothing on the list needs a server, recommend `astro-static` and stop. The
|
|
42
|
+
recipes say the same: `output: 'static'` with a host adapter still gets headers,
|
|
43
|
+
redirects, and preview URLs.
|
|
44
|
+
|
|
45
|
+
## Forms, which is where tiers move
|
|
46
|
+
|
|
47
|
+
A form that collects personal information moves the site from `low` to
|
|
48
|
+
`moderate`, with the obligations in `standards/policy/minsec.md`: Duo, centralised
|
|
49
|
+
logging, secure SDLC, annual training, weekly encrypted backups. A third-party form
|
|
50
|
+
endpoint is also a new third-party service, which triggers a Data Risk Assessment
|
|
51
|
+
per `standards/policy/privacy.md`.
|
|
52
|
+
|
|
53
|
+
So before writing a handler:
|
|
54
|
+
|
|
55
|
+
1. **Ask what each field is for.** Delete the ones nobody can justify.
|
|
56
|
+
2. **Name the tier change, once, plainly.** Record it in `.sws/manifest.yml` under
|
|
57
|
+
`tier` and `tier_because`.
|
|
58
|
+
3. **Decide where submissions go.** GitHub Pages has no server, so it needs a
|
|
59
|
+
third-party endpoint. On Netlify, Netlify Forms or a function. On a server
|
|
60
|
+
recipe, a route handler.
|
|
61
|
+
4. **Put the transparency notice before the form**, per MinPriv.
|
|
62
|
+
5. **Then** write the handler.
|
|
63
|
+
|
|
64
|
+
The markup, labels, errors, and the opt-in `decanter/forms` import are in
|
|
65
|
+
`standards/patterns/forms.md`. Front-end owns those; you own what happens after
|
|
66
|
+
submit.
|
|
67
|
+
|
|
68
|
+
### Writing the handler
|
|
69
|
+
|
|
70
|
+
- **Validate on the server.** Client validation is a courtesy, not a control.
|
|
71
|
+
- **Return errors the form can render inline**, field by field, and never discard
|
|
72
|
+
what the user typed.
|
|
73
|
+
- **Rate-limit and add a spam control** proportionate to the form. Do not reach for
|
|
74
|
+
a third-party CAPTCHA without noting it is a third-party service.
|
|
75
|
+
- **Log the event, not the payload.** Personal data in logs is still personal data.
|
|
76
|
+
- **Send nothing to the client it does not need.** A success message, not an echo of
|
|
77
|
+
the record.
|
|
78
|
+
- **Fail closed and visibly.** A handler that swallows an error loses a submission
|
|
79
|
+
silently, and nobody finds out until someone complains.
|
|
80
|
+
|
|
81
|
+
## Secrets
|
|
82
|
+
|
|
83
|
+
Secrets come from HashiCorp Vault, the SWS norm, never from a committed `.env`.
|
|
84
|
+
`node-vault` is the host-portable option; `netlify-plugin-vault-variables` is the
|
|
85
|
+
Netlify build-plugin route. Scheduled jobs keep credentials in Actions secrets.
|
|
86
|
+
|
|
87
|
+
**Any key in a static build is public.** If a value reaches the browser bundle, treat
|
|
88
|
+
it as published. Committed credentials are the one blocking check in this system;
|
|
89
|
+
if one lands on `main`, **rotate first**, then clean history.
|
|
90
|
+
|
|
91
|
+
## Scheduled data pulls and webhooks
|
|
92
|
+
|
|
93
|
+
The connector shape in `standards/connectors/README.md` is the house pattern: fetch
|
|
94
|
+
at build time or on a schedule, never from the visitor's browser, snapshot into the
|
|
95
|
+
repo so the content goes through `sws a11y`, and link back to the source. All three
|
|
96
|
+
connectors there are stubs; do not invent endpoints, fields, or credentials.
|
|
97
|
+
|
|
98
|
+
A webhook receiver is a public endpoint. Verify the sender's signature, make the
|
|
99
|
+
handler idempotent, and keep it doing one thing. A CMS publish webhook is deferred
|
|
100
|
+
with the CMS (`standards/scope.md`).
|
|
101
|
+
|
|
102
|
+
## Recipe specifics worth knowing
|
|
103
|
+
|
|
104
|
+
- **Astro:** `output: 'server'`, not `'hybrid'`, which was removed. Opt pages back
|
|
105
|
+
into prerendering individually. **Do not set headers in middleware**: it does not
|
|
106
|
+
run for prerendered routes, so some pages get headers and some do not.
|
|
107
|
+
- **Next:** a static export forfeits headers, redirects, Proxy, Server Actions, and
|
|
108
|
+
makes Route Handlers `GET`-only. If you want a static export, you want
|
|
109
|
+
`astro-static`.
|
|
110
|
+
- **Changing hosts** means moving secrets, redirects, and headers too, not only the
|
|
111
|
+
adapter.
|
|
112
|
+
|
|
113
|
+
Read the recipe in `standards/recipes/` before improvising; it is more current than
|
|
114
|
+
this file.
|
|
115
|
+
|
|
116
|
+
## Prior art, for the shape and not the wiring
|
|
117
|
+
|
|
118
|
+
Check `sws prior-art find "<what you are building>"` first. Most SWS server-side
|
|
119
|
+
work is CMS-backed and Decanter 7 era, so borrow architecture, not CSS or CMS
|
|
120
|
+
wiring:
|
|
121
|
+
|
|
122
|
+
- **Serverless at SWS** is Netlify functions, edge functions, and blobs.
|
|
123
|
+
- **Decoupled Drupal** (`cardinalsites-nextjs`, `csp-nextjs`, `summer-nextjs` with
|
|
124
|
+
`graphql-request`; `sulgryphon-nextjs` with `next-drupal`) and **Storyblok**
|
|
125
|
+
(`ccc-bulletin` at `@storyblok/react` 6.x) are a factual record, not a recipe
|
|
126
|
+
here. The four Drupal repos run `--webpack`; **Turbopack is the forward default**.
|
|
127
|
+
- **`adapt-online-giving`** (Stripe, `adapt-auth-sdk`, Upstash Redis, TanStack Form,
|
|
128
|
+
transactional email) is high-tier work. Read it for patterns; never cite it as a
|
|
129
|
+
template for a unit site.
|
|
130
|
+
|
|
131
|
+
## When reviewing back-end code
|
|
132
|
+
|
|
133
|
+
- Does this route need to exist, or would host config or a build step do?
|
|
134
|
+
- Did the tier change, and is it recorded with a reason?
|
|
135
|
+
- Is input validated server-side, and are errors returned per field?
|
|
136
|
+
- Does anything personal reach logs, the client, or a third party?
|
|
137
|
+
- Are secrets read from Vault or Actions secrets, with nothing in the bundle?
|
|
138
|
+
- Are headers set in host config rather than middleware?
|
|
139
|
+
- Is the new dependency something you are willing to patch within 7 days?
|
|
140
|
+
|
|
141
|
+
## Artifacts
|
|
142
|
+
|
|
143
|
+
| Artifact | Path |
|
|
144
|
+
|---|---|
|
|
145
|
+
| Server routes | `src/pages/api/` (Astro) or `app/**/route.ts` (Next) |
|
|
146
|
+
| Host config | `netlify.toml`, `vercel.json`, or the adapter config |
|
|
147
|
+
| Tier and reason | `.sws/manifest.yml` |
|
|
148
|
+
| Third parties and divergences | `.sws/manifest.yml` under `divergences:` |
|
|
149
|
+
| Operations runbook | `docs/ops/runbook.md`, shared with `role-devops` |
|
|
150
|
+
|
|
151
|
+
## Escalation
|
|
152
|
+
|
|
153
|
+
A tier change or a new third-party service routes to UIT Security for the DRA, per
|
|
154
|
+
`standards/policy/escalation.md`. That route is still marked as needing
|
|
155
|
+
confirmation, so use the general contact and say so. Do not recommend or rank form,
|
|
156
|
+
search, or database vendors: state the obligation, name the office, stop.
|