@sssb/kit 0.4.0 → 0.5.0
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/release.json +1 -1
- package/package.json +3 -1
- package/src/adapters/email-message.ts +30 -0
- package/src/adapters/fake/analytics.ts +1 -1
- package/src/adapters/fake/auth.ts +18 -2
- package/src/adapters/fake/data-dir.ts +32 -2
- package/src/adapters/fake/email.ts +2 -0
- package/src/adapters/real/accept-invite-form.tsx +32 -14
- package/src/adapters/real/analytics.ts +29 -2
- package/src/adapters/real/auth.ts +54 -18
- package/src/adapters/real/contract-postgres.ts +15 -11
- package/src/adapters/real/email.ts +2 -0
- package/src/adapters/real/jobs-in-process.ts +32 -14
- package/src/adapters/real/jobs.ts +6 -3
- package/src/adapters/real/migrate-handler.ts +3 -1
- package/src/adapters/real/rds-data-codec.ts +88 -4
- package/src/adapters/real/rds-data-emulator.ts +12 -4
- package/src/adapters/real/sign-in-form.tsx +29 -13
- package/src/authz/app-exemptions.ts +79 -9
- package/src/authz/route-scan.ts +626 -55
- package/src/components/auth/accept-invite-screen.tsx +5 -1
- package/src/components/auth/people-picker.tsx +20 -2
- package/src/components/profile-screen.tsx +27 -2
- package/src/core/inbound-email.ts +41 -6
- package/src/db/jobs.ts +15 -6
- package/src/db/keyset.ts +8 -6
- package/src/db/migrations/0015_app_user_grant.ts +1 -1
- package/src/db/rls-coverage.ts +51 -17
- package/src/db/schedules.ts +9 -3
- package/src/demo-static/actor-drivers.ts +8 -2
- package/src/demo-static/email-html.ts +9 -0
- package/src/demo-static/tour/use-tours.tsx +8 -2
- package/src/demo-static/world.ts +76 -37
- package/src/email/send.ts +6 -2
- package/src/guide.md +20 -6
- package/src/i18n/messages/en.json +3 -0
- package/src/i18n/messages/es.json +3 -0
- package/src/i18n/messages.ts +3 -2
- package/src/server-lib/scheduled-tick.ts +5 -1
- package/src/server-lib/webhook-dispatch.ts +3 -0
- package/src/service-auth/mailgun.ts +19 -4
- package/src/testing/conformance/auth-provider.ts +17 -5
- package/src/testing/conformance/authz.ts +6 -2
- package/src/testing/conformance/i18n.ts +99 -5
- package/src/testing/conformance/suite.ts +63 -3
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { existsSync, realpathSync } from 'node:fs'
|
|
1
2
|
import path from 'node:path'
|
|
3
|
+
import { expect } from 'vitest'
|
|
2
4
|
import { realAuthProvider } from './auth-provider'
|
|
3
5
|
import { authzMutations } from './authz'
|
|
4
6
|
import { appRolesCheck, migrationOrder, rlsPglite } from './db'
|
|
@@ -46,16 +48,74 @@ export interface ConformanceOptions {
|
|
|
46
48
|
optOut?: Readonly<Record<string, string>>
|
|
47
49
|
}
|
|
48
50
|
|
|
51
|
+
/** The nearest directory at or above `file` that holds a package.json, or null. */
|
|
52
|
+
function packageDirOf(file: string): string | null {
|
|
53
|
+
for (let dir = path.dirname(file); ; dir = path.dirname(dir)) {
|
|
54
|
+
if (existsSync(path.join(dir, 'package.json'))) return dir
|
|
55
|
+
if (path.dirname(dir) === dir) return null
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const realOrNull = (dir: string) => {
|
|
60
|
+
try {
|
|
61
|
+
// The native call: on a case-insensitive file system it answers the name as stored, where the JS one keeps
|
|
62
|
+
// the caller's casing, so `/apps/Starter` and `/apps/starter` would compare unequal.
|
|
63
|
+
return realpathSync.native(dir)
|
|
64
|
+
} catch {
|
|
65
|
+
return null
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Why `appDir` is not the app whose suite file `testPath` is, or null when it is. The app is the nearest directory at
|
|
71
|
+
* or above the test file that holds a package.json; both sides are compared by native real path, so `..`, symbolic
|
|
72
|
+
* links and (on a case-insensitive file system) letter case do not matter. A suite file in one app pointed at another would otherwise run every file-reading check over the
|
|
73
|
+
* other app's files and pass.
|
|
74
|
+
*/
|
|
75
|
+
export function appDirMismatch(appDir: string, testPath: string): string | null {
|
|
76
|
+
const own = packageDirOf(realOrNull(testPath) ?? testPath)
|
|
77
|
+
const given = realOrNull(path.resolve(appDir))
|
|
78
|
+
const ownReal = own === null ? null : realOrNull(own)
|
|
79
|
+
if (given !== null && ownReal !== null && given === ownReal) return null
|
|
80
|
+
return (
|
|
81
|
+
`conformanceSuite: appDir is ${path.resolve(appDir)}, but the suite file ${testPath} belongs to ` +
|
|
82
|
+
`${own ?? 'no package (no package.json above it)'}; appDir must be the directory of the app that runs it`
|
|
83
|
+
)
|
|
84
|
+
}
|
|
85
|
+
|
|
49
86
|
/** Registers the conformance suite in the calling test file. Call it once, at the file's top level. */
|
|
50
87
|
export function conformanceSuite(options: ConformanceOptions): void {
|
|
51
|
-
//
|
|
52
|
-
//
|
|
53
|
-
|
|
88
|
+
// Only the two published options are read: anything else an app passes is ignored, so nothing it writes can turn
|
|
89
|
+
// the appDir check below off.
|
|
90
|
+
registerConformanceSuite({ appDir: options.appDir, ...(options.optOut ? { optOut: options.optOut } : {}) })
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* SSSB's own entry, not a published subpath (`@sssb/kit/testing` exports `conformanceSuite` only): the suite with
|
|
95
|
+
* `appDirOutsideCaller`, the reason `appDir` is not the calling test file's package. The kit runs the suite against
|
|
96
|
+
* its fixture, `packages/kit/test-fixture`, from a test file in `packages/kit`; an app never has a reason to.
|
|
97
|
+
*/
|
|
98
|
+
export function registerConformanceSuite(options: ConformanceOptions & { appDirOutsideCaller?: string }): void {
|
|
54
99
|
const optOut = options.optOut ?? {}
|
|
55
100
|
checkOptOut('conformanceSuite', 'unit', optOut)
|
|
56
101
|
if (typeof options.appDir !== 'string' || options.appDir === '') {
|
|
57
102
|
throw new Error('conformanceSuite: appDir must name the app directory')
|
|
58
103
|
}
|
|
104
|
+
// Refused while the file is collected, before anything is registered.
|
|
105
|
+
const outside = options.appDirOutsideCaller
|
|
106
|
+
if (outside !== undefined) {
|
|
107
|
+
if (typeof outside !== 'string' || !outside.trim()) {
|
|
108
|
+
throw new Error('conformanceSuite: appDirOutsideCaller needs a reason')
|
|
109
|
+
}
|
|
110
|
+
} else {
|
|
111
|
+
const testPath = expect.getState().testPath
|
|
112
|
+
if (!testPath) throw new Error('conformanceSuite: call it at the top level of a Vitest test file')
|
|
113
|
+
const mismatch = appDirMismatch(options.appDir, testPath)
|
|
114
|
+
if (mismatch) throw new Error(mismatch)
|
|
115
|
+
}
|
|
116
|
+
// Before the checks, so the scratch directories' cleanup is this file's own, at its top level, and runs after the
|
|
117
|
+
// checks' teardown, even under `isolate: false`, where the helper loads once per worker (../tmp-dir.ts).
|
|
118
|
+
registerTestTmpDirCleanup()
|
|
59
119
|
const context: CheckContext = { appDir: path.resolve(options.appDir) }
|
|
60
120
|
registerChecks({ caller: 'conformanceSuite', runner: 'unit', implementations: IMPLEMENTATIONS, optOut, context })
|
|
61
121
|
}
|