Skip to content

Commit b23759e

Browse files
Merge pull request #184 from CodeForPhilly/develop
Release: v0.2.5
2 parents b97232c + 6436f60 commit b23759e

2 files changed

Lines changed: 57 additions & 1 deletion

File tree

‎apps/api/src/saml/config.ts‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,18 @@
1010
* NameID + attribute statement template that produces the assertion shape
1111
* required by specs/api/saml.md.
1212
*/
13-
import * as samlify from 'samlify';
13+
import * as samlifyNs from 'samlify';
14+
15+
// samlify is CommonJS. Under Node's ESM loader, cjs-module-lexer does not
16+
// detect `SamlLib` (it is re-exported through a getter), so `import * as`
17+
// leaves it undefined and only `default` (the whole module.exports) carries
18+
// it. vitest's interop exposes it as a named export, which is why the tests
19+
// never saw the production 500. Resolve from whichever view has it.
20+
type SamlifyModule = typeof samlifyNs;
21+
const samlify: SamlifyModule =
22+
(samlifyNs as SamlifyModule & { default?: SamlifyModule }).default?.SamlLib !== undefined
23+
? (samlifyNs as SamlifyModule & { default: SamlifyModule }).default
24+
: samlifyNs;
1425

1526
const { IdentityProvider, ServiceProvider, Constants, SamlLib, setSchemaValidator } = samlify;
1627

‎plans/samlify-esm-interop.md‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
status: done
3+
depends: [saml-login-return-path]
4+
specs:
5+
- specs/api/saml.md
6+
issues: []
7+
pr: 183
8+
---
9+
10+
# Plan: samlify ESM/CJS interop in the production build
11+
12+
## Scope
13+
14+
The first signed-in Slack SSO attempt against the live site 500'd:
15+
`Cannot read properties of undefined (reading 'replaceTagsByValue')` in
16+
`dist/saml/config.js`. samlify is CommonJS; under Node's ESM loader,
17+
cjs-module-lexer does not detect `SamlLib` (re-exported through a getter),
18+
so `import * as samlify` leaves it undefined and only `default`
19+
(module.exports) carries it. vitest's interop exposes it as a named export,
20+
which is why all 19 SAML tests passed while production failed.
21+
22+
In: resolve the module from whichever view carries `SamlLib`; verify the
23+
compiled output under plain Node. Out: replacing samlify.
24+
25+
## Implements
26+
27+
- [api/saml.md](../specs/api/saml.md) — no behaviour change; the assertion
28+
pipeline works as specified once the library resolves.
29+
30+
## Approach
31+
32+
`apps/api/src/saml/config.ts`: pick `samlifyNs.default` when it carries
33+
`SamlLib`, else the namespace. Verified with
34+
`node -e "import('./dist/saml/config.js')"` after `npm run build`.
35+
36+
## Validation
37+
38+
- `npm run type-check && npm run lint`; SAML suite 19/19.
39+
- Post-deploy: Slack "Test configuration" completes for a signed-in user.
40+
41+
## Follow-ups
42+
43+
- Tracked as: a build-output smoke test (import the compiled API under plain
44+
Node in CI) would have caught this before release — worth adding to
45+
`ci.yml` after `npm run build`.

0 commit comments

Comments
 (0)