@react-consulting/rc-kit 0.0.0-stage → 0.13.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.
- package/LICENSE +21 -0
- package/README.md +93 -2
- package/devkit/README.md +301 -0
- package/devkit/cli.test.ts +211 -0
- package/devkit/cli.ts +120 -0
- package/devkit/commands/build.ts +127 -0
- package/devkit/commands/checks.ts +123 -0
- package/devkit/commands/context.ts +47 -0
- package/devkit/commands/db.ts +154 -0
- package/devkit/commands/deploy.ts +46 -0
- package/devkit/commands/dev.ts +191 -0
- package/devkit/commands/doctor.ts +25 -0
- package/devkit/commands/kit.ts +45 -0
- package/devkit/commands/new.ts +81 -0
- package/devkit/commands/registry.ts +20 -0
- package/devkit/commands/secrets.ts +254 -0
- package/devkit/lib/args.ts +65 -0
- package/devkit/lib/audit.test.ts +405 -0
- package/devkit/lib/audit.ts +813 -0
- package/devkit/lib/config.test.ts +203 -0
- package/devkit/lib/config.ts +417 -0
- package/devkit/lib/database/index.test.ts +223 -0
- package/devkit/lib/database/index.ts +314 -0
- package/devkit/lib/database/neon.test.ts +233 -0
- package/devkit/lib/database/neon.ts +357 -0
- package/devkit/lib/database/prepare.ts +54 -0
- package/devkit/lib/deploy-config.test.ts +217 -0
- package/devkit/lib/deploy-config.ts +133 -0
- package/devkit/lib/deploy.test.ts +275 -0
- package/devkit/lib/deploy.ts +177 -0
- package/devkit/lib/dev-gateway.test.ts +128 -0
- package/devkit/lib/dev-gateway.ts +162 -0
- package/devkit/lib/dev-menu.test.ts +114 -0
- package/devkit/lib/dev-menu.ts +332 -0
- package/devkit/lib/dev-secrets.test.ts +156 -0
- package/devkit/lib/dev-secrets.ts +97 -0
- package/devkit/lib/dev.test.ts +194 -0
- package/devkit/lib/dev.ts +119 -0
- package/devkit/lib/doctor.test.ts +144 -0
- package/devkit/lib/doctor.ts +264 -0
- package/devkit/lib/env-file.test.ts +102 -0
- package/devkit/lib/env-file.ts +96 -0
- package/devkit/lib/glob.ts +31 -0
- package/devkit/lib/infisical.test.ts +208 -0
- package/devkit/lib/infisical.ts +139 -0
- package/devkit/lib/json-schema.ts +220 -0
- package/devkit/lib/jsonc.test.ts +53 -0
- package/devkit/lib/jsonc.ts +93 -0
- package/devkit/lib/kit-migrate.test.ts +215 -0
- package/devkit/lib/kit-migrate.ts +624 -0
- package/devkit/lib/kit-package.test.ts +83 -0
- package/devkit/lib/kit-package.ts +57 -0
- package/devkit/lib/kit-version.ts +22 -0
- package/devkit/lib/naming.test.ts +547 -0
- package/devkit/lib/naming.ts +796 -0
- package/devkit/lib/paths.ts +7 -0
- package/devkit/lib/process.ts +78 -0
- package/devkit/lib/project-checks.ts +86 -0
- package/devkit/lib/scaffold.test.ts +302 -0
- package/devkit/lib/scaffold.ts +315 -0
- package/devkit/lib/secrets.test.ts +101 -0
- package/devkit/lib/secrets.ts +125 -0
- package/devkit/lib/sourcemaps.test.ts +86 -0
- package/devkit/lib/sourcemaps.ts +98 -0
- package/devkit/lib/test-utils.ts +68 -0
- package/devkit/lib/workspace.ts +87 -0
- package/devkit/lib/wrangler.ts +231 -0
- package/docs/rc-config.md +93 -0
- package/package.json +86 -4
- package/presets/build.d.ts +15 -0
- package/presets/build.js +53 -0
- package/presets/vite-plus.d.ts +28 -0
- package/presets/vite-plus.js +153 -0
- package/registry/README.md +294 -0
- package/registry/public/r/avatar-stack.json +18 -0
- package/registry/public/r/avatar.json +20 -0
- package/registry/public/r/back-link.json +21 -0
- package/registry/public/r/badge.json +17 -0
- package/registry/public/r/button.json +18 -0
- package/registry/public/r/calendar-days.json +14 -0
- package/registry/public/r/calendar-popover.json +24 -0
- package/registry/public/r/calendar.json +23 -0
- package/registry/public/r/callout.json +20 -0
- package/registry/public/r/card.json +18 -0
- package/registry/public/r/character-counter.json +17 -0
- package/registry/public/r/checkbox.json +22 -0
- package/registry/public/r/choice-cards.json +22 -0
- package/registry/public/r/color-tag.json +17 -0
- package/registry/public/r/combobox.json +24 -0
- package/registry/public/r/confirm-button.json +24 -0
- package/registry/public/r/confirm-dialog.json +23 -0
- package/registry/public/r/copy-button.json +24 -0
- package/registry/public/r/date-picker.json +24 -0
- package/registry/public/r/date-range-picker.json +28 -0
- package/registry/public/r/detail-header.json +17 -0
- package/registry/public/r/detail-row.json +17 -0
- package/registry/public/r/dev-inbox-api.json +33 -0
- package/registry/public/r/dev-toolbar.json +109 -0
- package/registry/public/r/dev-tools-contract.json +15 -0
- package/registry/public/r/dialog.json +23 -0
- package/registry/public/r/empty-state.json +20 -0
- package/registry/public/r/error-state.json +23 -0
- package/registry/public/r/eyebrow.json +17 -0
- package/registry/public/r/fab.json +20 -0
- package/registry/public/r/field-error.json +17 -0
- package/registry/public/r/field-grid.json +17 -0
- package/registry/public/r/field.json +19 -0
- package/registry/public/r/file-picker.json +22 -0
- package/registry/public/r/filter-chips.json +17 -0
- package/registry/public/r/form-section.json +17 -0
- package/registry/public/r/form-sheet.json +22 -0
- package/registry/public/r/icon-button.json +23 -0
- package/registry/public/r/input.json +18 -0
- package/registry/public/r/label.json +18 -0
- package/registry/public/r/list-row.json +17 -0
- package/registry/public/r/loading-state.json +18 -0
- package/registry/public/r/localized-field.json +23 -0
- package/registry/public/r/markdown-text.json +17 -0
- package/registry/public/r/menu.json +21 -0
- package/registry/public/r/money-input.json +17 -0
- package/registry/public/r/month-day-select.json +18 -0
- package/registry/public/r/numbered-step.json +20 -0
- package/registry/public/r/page-actions.json +14 -0
- package/registry/public/r/page-header.json +17 -0
- package/registry/public/r/pending.json +17 -0
- package/registry/public/r/person-option.json +21 -0
- package/registry/public/r/popover.json +20 -0
- package/registry/public/r/progress-bar.json +17 -0
- package/registry/public/r/query-view.json +22 -0
- package/registry/public/r/registry.json +1352 -0
- package/registry/public/r/retry-button.json +21 -0
- package/registry/public/r/rich-text-editor.json +32 -0
- package/registry/public/r/save-bar.json +22 -0
- package/registry/public/r/search-input.json +23 -0
- package/registry/public/r/search-select.json +24 -0
- package/registry/public/r/section-tabs.json +17 -0
- package/registry/public/r/segmented.json +18 -0
- package/registry/public/r/select.json +23 -0
- package/registry/public/r/sheet.json +24 -0
- package/registry/public/r/skeleton.json +17 -0
- package/registry/public/r/spinner.json +20 -0
- package/registry/public/r/stale-notice.json +23 -0
- package/registry/public/r/stat-tile.json +23 -0
- package/registry/public/r/stepper.json +23 -0
- package/registry/public/r/suggestion-strip.json +21 -0
- package/registry/public/r/swatch-picker.json +22 -0
- package/registry/public/r/switch.json +21 -0
- package/registry/public/r/tabs.json +20 -0
- package/registry/public/r/textarea.json +18 -0
- package/registry/public/r/theme.json +15 -0
- package/registry/public/r/timezone-select.json +19 -0
- package/registry/public/r/toaster.json +21 -0
- package/registry/public/r/tooltip.json +17 -0
- package/registry/public/r/ui-labels.json +14 -0
- package/registry/public/r/use-copy-to-clipboard.json +20 -0
- package/registry/public/r/use-online.json +14 -0
- package/registry/public/r/use-stale-queries.json +17 -0
- package/registry/public/r/utils.json +18 -0
- package/registry/public/r/weekday-picker.json +19 -0
- package/registry/public/r/yes-no.json +20 -0
- package/registry/serve.ts +29 -0
- package/rules/architecture.md +47 -0
- package/rules/cloudflare.md +74 -0
- package/rules/code.md +12 -0
- package/rules/git.md +10 -0
- package/rules/index.md +14 -0
- package/rules/observability.md +13 -0
- package/rules/performance.md +39 -0
- package/rules/runtime.md +9 -0
- package/rules/secrets.md +11 -0
- package/rules/stack.md +33 -0
- package/rules/ui.md +23 -0
- package/runtime/ai.test.ts +106 -0
- package/runtime/ai.ts +125 -0
- package/runtime/observability/allowlists.ts +42 -0
- package/runtime/observability/anonymize.test.ts +111 -0
- package/runtime/observability/anonymize.ts +249 -0
- package/runtime/observability/browser.test.ts +46 -0
- package/runtime/observability/browser.ts +126 -0
- package/runtime/observability/server.test.ts +84 -0
- package/runtime/observability/server.ts +152 -0
- package/runtime/observability/tunnel.test.ts +276 -0
- package/runtime/observability/tunnel.ts +360 -0
- package/runtime/observability/user-agent.ts +51 -0
- package/schema/rc.config.schema.json +333 -0
- package/template/.gitattributes +1 -0
- package/template/.github/workflows/ci.yml +64 -0
- package/template/CLAUDE.md +48 -0
- package/template/README.md +50 -0
- package/template/apps/admin/.dev.vars.example +5 -0
- package/template/apps/admin/components.json +24 -0
- package/template/apps/admin/package.json +48 -0
- package/template/apps/admin/public/favicon.svg +1 -0
- package/template/apps/admin/src/components/app-shell.tsx +41 -0
- package/template/apps/admin/src/components/dev-sign-in-links.tsx +57 -0
- package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-context.ts +13 -0
- package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-environment-panel.tsx +105 -0
- package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-inbox-list.tsx +54 -0
- package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-inbox-message.tsx +104 -0
- package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-inbox-panel.tsx +130 -0
- package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-launcher.tsx +45 -0
- package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-panel.tsx +90 -0
- package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-types.ts +11 -0
- package/template/apps/admin/src/components/dev-toolbar/dev-toolbar.tsx +61 -0
- package/template/apps/admin/src/components/dev-toolbar/development-devtools.tsx +32 -0
- package/template/apps/admin/src/components/login-form.tsx +115 -0
- package/template/apps/admin/src/components/login-sent.tsx +23 -0
- package/template/apps/admin/src/components/message-list.tsx +44 -0
- package/template/apps/admin/src/components/turnstile-challenge.tsx +140 -0
- package/template/apps/admin/src/components/ui/button.tsx +87 -0
- package/template/apps/admin/src/components/ui/callout.tsx +84 -0
- package/template/apps/admin/src/components/ui/card.tsx +48 -0
- package/template/apps/admin/src/components/ui/eyebrow.tsx +33 -0
- package/template/apps/admin/src/components/ui/field-error.tsx +24 -0
- package/template/apps/admin/src/components/ui/field.tsx +100 -0
- package/template/apps/admin/src/components/ui/input.tsx +73 -0
- package/template/apps/admin/src/components/ui/label.tsx +39 -0
- package/template/apps/admin/src/components/ui/skeleton.tsx +225 -0
- package/template/apps/admin/src/components/ui/spinner.tsx +12 -0
- package/template/apps/admin/src/components/ui/toaster.tsx +33 -0
- package/template/apps/admin/src/components/ui/tooltip.tsx +51 -0
- package/template/apps/admin/src/hooks/use-dev-inbox.ts +25 -0
- package/template/apps/admin/src/hooks/use-dev-toolbar-state.ts +48 -0
- package/template/apps/admin/src/lib/api.ts +39 -0
- package/template/apps/admin/src/lib/auth-client.ts +7 -0
- package/template/apps/admin/src/lib/dev-inbox-links.ts +66 -0
- package/template/apps/admin/src/lib/dev-tools-client.ts +54 -0
- package/template/apps/admin/src/lib/dev-tools-contract.ts +52 -0
- package/template/apps/admin/src/lib/messages.ts +5 -0
- package/template/apps/admin/src/lib/query-keys.ts +3 -0
- package/template/apps/admin/src/lib/security-headers.ts +18 -0
- package/template/apps/admin/src/lib/session.ts +27 -0
- package/template/apps/admin/src/lib/site-url.ts +7 -0
- package/template/apps/admin/src/lib/turnstile.ts +70 -0
- package/template/apps/admin/src/lib/ui-labels.tsx +182 -0
- package/template/apps/admin/src/lib/utils.ts +6 -0
- package/template/apps/admin/src/routeTree.gen.ts +109 -0
- package/template/apps/admin/src/router.tsx +29 -0
- package/template/apps/admin/src/routes/__root.tsx +56 -0
- package/template/apps/admin/src/routes/_app/index.tsx +38 -0
- package/template/apps/admin/src/routes/_app.tsx +26 -0
- package/template/apps/admin/src/routes/login.tsx +48 -0
- package/template/apps/admin/src/styles/app.css +11 -0
- package/template/apps/admin/src/worker.ts +88 -0
- package/template/apps/admin/tsconfig.json +19 -0
- package/template/apps/admin/vite.config.ts +69 -0
- package/template/apps/admin/wrangler.jsonc +92 -0
- package/template/apps/web/.env.example +1 -0
- package/template/apps/web/astro.config.ts +46 -0
- package/template/apps/web/package.json +33 -0
- package/template/apps/web/public/favicon.svg +1 -0
- package/template/apps/web/src/components/ContactForm.astro +78 -0
- package/template/apps/web/src/env.d.ts +11 -0
- package/template/apps/web/src/layouts/BaseLayout.astro +32 -0
- package/template/apps/web/src/lib/api.ts +8 -0
- package/template/apps/web/src/pages/api/messages.ts +32 -0
- package/template/apps/web/src/pages/index.astro +26 -0
- package/template/apps/web/src/pages/media/[...key].ts +4 -0
- package/template/apps/web/src/scripts/contact-form.ts +105 -0
- package/template/apps/web/src/scripts/error-reporting.ts +4 -0
- package/template/apps/web/src/scripts/turnstile.ts +177 -0
- package/template/apps/web/src/styles/global.css +11 -0
- package/template/apps/web/src/worker.ts +34 -0
- package/template/apps/web/tsconfig.json +11 -0
- package/template/apps/web/wrangler.jsonc +45 -0
- package/template/bun.lock +1925 -0
- package/template/bunfig.toml +2 -0
- package/template/gitignore +23 -0
- package/template/package.json +74 -0
- package/template/packages/api/components.json +21 -0
- package/template/packages/api/package.json +30 -0
- package/template/packages/api/src/client.ts +13 -0
- package/template/packages/api/src/cloudflare-env.d.ts +26 -0
- package/template/packages/api/src/emails/escape-html.ts +13 -0
- package/template/packages/api/src/emails/layout.ts +22 -0
- package/template/packages/api/src/emails/magic-link.ts +32 -0
- package/template/packages/api/src/emails/new-message.ts +32 -0
- package/template/packages/api/src/emails/send.ts +14 -0
- package/template/packages/api/src/lib/auth-guard.ts +16 -0
- package/template/packages/api/src/lib/auth.ts +108 -0
- package/template/packages/api/src/lib/context.ts +7 -0
- package/template/packages/api/src/lib/dev-inbox/routes.ts +77 -0
- package/template/packages/api/src/lib/dev-inbox/send.ts +57 -0
- package/template/packages/api/src/lib/dev-inbox/store.ts +185 -0
- package/template/packages/api/src/lib/dev-inbox.ts +6 -0
- package/template/packages/api/src/lib/dev-tools-contract.ts +52 -0
- package/template/packages/api/src/lib/environment.ts +17 -0
- package/template/packages/api/src/lib/turnstile.ts +33 -0
- package/template/packages/api/src/media.ts +45 -0
- package/template/packages/api/src/routes/admin-messages.ts +21 -0
- package/template/packages/api/src/routes/dev.ts +31 -0
- package/template/packages/api/src/routes/health.ts +7 -0
- package/template/packages/api/src/routes/messages.ts +58 -0
- package/template/packages/api/src/schemas.ts +18 -0
- package/template/packages/api/src/server.ts +29 -0
- package/template/packages/api/tsconfig.json +10 -0
- package/template/packages/db/migrations/0001_init.sql +79 -0
- package/template/packages/db/package.json +34 -0
- package/template/packages/db/prisma/schema.prisma +95 -0
- package/template/packages/db/prisma.config.ts +9 -0
- package/template/packages/db/scripts/migrate.ts +15 -0
- package/template/packages/db/scripts/new-migration.ts +185 -0
- package/template/packages/db/scripts/reset.ts +54 -0
- package/template/packages/db/scripts/seed.ts +44 -0
- package/template/packages/db/scripts/wrangler.ts +35 -0
- package/template/packages/db/src/d1.ts +7 -0
- package/template/packages/db/src/migration-guard.test.ts +43 -0
- package/template/packages/db/src/migration-guard.ts +51 -0
- package/template/packages/db/src/new-migration.test.ts +16 -0
- package/template/packages/db/src/scope.ts +38 -0
- package/template/packages/db/src/seed.ts +30 -0
- package/template/packages/db/src/sql.ts +42 -0
- package/template/packages/db/tsconfig.json +8 -0
- package/template/packages/shared/components.json +21 -0
- package/template/packages/shared/package.json +33 -0
- package/template/packages/shared/src/edge/origins.ts +20 -0
- package/template/packages/shared/src/edge/turnstile.ts +11 -0
- package/template/packages/shared/src/locales.ts +13 -0
- package/template/packages/shared/src/message-rules.ts +16 -0
- package/template/packages/shared/src/messages.test.ts +26 -0
- package/template/packages/shared/src/messages.ts +30 -0
- package/template/packages/shared/src/observability/build-release.ts +9 -0
- package/template/packages/shared/src/observability/error-reporting.ts +31 -0
- package/template/packages/shared/src/observability/error-tunnel.ts +20 -0
- package/template/packages/shared/src/observability/sentry-browser.ts +1 -0
- package/template/packages/shared/src/observability/server-errors.ts +74 -0
- package/template/packages/shared/src/project.ts +1 -0
- package/template/packages/shared/src/styles/rc-theme.css +138 -0
- package/template/packages/shared/src/styles/theme.css +9 -0
- package/template/packages/shared/tsconfig.json +10 -0
- package/template/rc.config.json +25 -0
- package/template/scripts/bootstrap-local.ts +42 -0
- package/template/tsconfig.base.json +20 -0
- package/template/tsconfig.json +8 -0
- package/template/tsconfig.worker.json +7 -0
- package/template/turbo.json +40 -0
- package/template/vite.config.ts +8 -0
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs"
|
|
2
|
+
import { join } from "node:path"
|
|
3
|
+
|
|
4
|
+
import { ConfigError, loadConfig } from "./config"
|
|
5
|
+
import {
|
|
6
|
+
hasLfAttributes,
|
|
7
|
+
installedKitDir,
|
|
8
|
+
isLocalSpec,
|
|
9
|
+
isPortableImport,
|
|
10
|
+
KIT_PACKAGE,
|
|
11
|
+
LEGACY_KIT_PACKAGE,
|
|
12
|
+
linkedKitTarget,
|
|
13
|
+
RULES_IMPORT,
|
|
14
|
+
resolveImport,
|
|
15
|
+
rulesImportsOf,
|
|
16
|
+
} from "./kit-package"
|
|
17
|
+
import { kitVersionError } from "./kit-version"
|
|
18
|
+
import type { Runner } from "./process"
|
|
19
|
+
import { dependenciesOf, readPackageJson } from "./workspace"
|
|
20
|
+
|
|
21
|
+
export const MIN_BUN_VERSION = "1.4.4"
|
|
22
|
+
|
|
23
|
+
export type DoctorStatus = "ok" | "warn" | "fail"
|
|
24
|
+
|
|
25
|
+
export interface DoctorCheck {
|
|
26
|
+
status: DoctorStatus
|
|
27
|
+
label: string
|
|
28
|
+
detail?: string
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface DoctorInput {
|
|
32
|
+
root: string
|
|
33
|
+
kitVersion: string
|
|
34
|
+
bunVersion: string
|
|
35
|
+
runner: Runner
|
|
36
|
+
which: (command: string) => string | null
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function ok(label: string, detail?: string): DoctorCheck {
|
|
40
|
+
return { status: "ok", label, detail }
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function warn(label: string, detail: string): DoctorCheck {
|
|
44
|
+
return { status: "warn", label, detail }
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function fail(label: string, detail: string): DoctorCheck {
|
|
48
|
+
return { status: "fail", label, detail }
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function readText(path: string): string | null {
|
|
52
|
+
return existsSync(path) ? readFileSync(path, "utf8") : null
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function bunCheck(input: DoctorInput): DoctorCheck {
|
|
56
|
+
const label = `Bun ${MIN_BUN_VERSION} ou plus`
|
|
57
|
+
|
|
58
|
+
return Bun.semver.satisfies(input.bunVersion, `>=${MIN_BUN_VERSION}`)
|
|
59
|
+
? ok(label, input.bunVersion)
|
|
60
|
+
: fail(label, `Bun ${input.bunVersion} : lance « bun upgrade ».`)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function dependencyChecks(input: DoctorInput): DoctorCheck[] {
|
|
64
|
+
const pkg = readPackageJson(input.root)
|
|
65
|
+
|
|
66
|
+
if (!pkg) {
|
|
67
|
+
return [fail("package.json racine", `absent de ${input.root}`)]
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const deps = dependenciesOf(pkg)
|
|
71
|
+
const spec = deps[KIT_PACKAGE]
|
|
72
|
+
const label = `${KIT_PACKAGE} dans les devDependencies`
|
|
73
|
+
const checks: DoctorCheck[] = []
|
|
74
|
+
|
|
75
|
+
if (deps[LEGACY_KIT_PACKAGE]) {
|
|
76
|
+
checks.push(
|
|
77
|
+
fail(
|
|
78
|
+
`pas d'ancienne dépendance ${LEGACY_KIT_PACKAGE}`,
|
|
79
|
+
`remplace « ${LEGACY_KIT_PACKAGE} » par « ${KIT_PACKAGE} » (version publiée) puis « bun install ».`
|
|
80
|
+
)
|
|
81
|
+
)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (!spec) {
|
|
85
|
+
checks.push(fail(label, `absent : lance « bun add -d ${KIT_PACKAGE} ».`))
|
|
86
|
+
} else if (isLocalSpec(spec)) {
|
|
87
|
+
checks.push(
|
|
88
|
+
fail(
|
|
89
|
+
label,
|
|
90
|
+
`« ${spec} » ne marche que sur ce poste : déclare une version publiée (« bun add -d ${KIT_PACKAGE} ») et utilise « bun link ${KIT_PACKAGE} » pour tester un clone.`
|
|
91
|
+
)
|
|
92
|
+
)
|
|
93
|
+
} else {
|
|
94
|
+
checks.push(ok(label, spec))
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return [...checks, installCheck(input)]
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function installCheck(input: DoctorInput): DoctorCheck {
|
|
101
|
+
const label = `${KIT_PACKAGE} installé`
|
|
102
|
+
const linked = linkedKitTarget(input.root)
|
|
103
|
+
|
|
104
|
+
if (linked) {
|
|
105
|
+
return warn(
|
|
106
|
+
label,
|
|
107
|
+
`lié au clone ${linked} par bun link : « bun install --force » rétablit la version publiée.`
|
|
108
|
+
)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return existsSync(join(installedKitDir(input.root), "package.json"))
|
|
112
|
+
? ok(label, input.kitVersion)
|
|
113
|
+
: fail(label, "absent de node_modules : lance « bun install ».")
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function configChecks(input: DoctorInput): DoctorCheck[] {
|
|
117
|
+
try {
|
|
118
|
+
const { config } = loadConfig({ root: input.root })
|
|
119
|
+
const versionError = kitVersionError(config.kit, input.kitVersion)
|
|
120
|
+
|
|
121
|
+
if (!config.kit) {
|
|
122
|
+
return [
|
|
123
|
+
ok("rc.config.json valide"),
|
|
124
|
+
warn(
|
|
125
|
+
"version du kit déclarée",
|
|
126
|
+
`ajoute "kit": ">=${input.kitVersion}" à rc.config.json pour refuser une version installée trop ancienne.`
|
|
127
|
+
),
|
|
128
|
+
]
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return [
|
|
132
|
+
ok("rc.config.json valide"),
|
|
133
|
+
versionError
|
|
134
|
+
? fail(`${KIT_PACKAGE} ${config.kit}`, versionError)
|
|
135
|
+
: ok(`${KIT_PACKAGE} ${config.kit}`, input.kitVersion),
|
|
136
|
+
]
|
|
137
|
+
} catch (error) {
|
|
138
|
+
const details =
|
|
139
|
+
error instanceof ConfigError
|
|
140
|
+
? [error.message, ...error.details].join(" ")
|
|
141
|
+
: String(error)
|
|
142
|
+
|
|
143
|
+
return [fail("rc.config.json valide", details)]
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function rulesCheck(input: DoctorInput): DoctorCheck {
|
|
148
|
+
const label = "règles communes importées depuis le paquet"
|
|
149
|
+
const files = ["CLAUDE.md", "AGENTS.md"]
|
|
150
|
+
.map((name) => ({ name, text: readText(join(input.root, name)) }))
|
|
151
|
+
.filter((file) => file.text !== null)
|
|
152
|
+
const imports = files.flatMap((file) =>
|
|
153
|
+
rulesImportsOf(file.text ?? "").map((spec) => ({ file: file.name, spec }))
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
if (imports.length === 0) {
|
|
157
|
+
return fail(
|
|
158
|
+
label,
|
|
159
|
+
`ni CLAUDE.md ni AGENTS.md n'importe les règles : ajoute « ${RULES_IMPORT} » en première ligne.`
|
|
160
|
+
)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const problems = imports.flatMap(({ file, spec }) => {
|
|
164
|
+
if (!isPortableImport(spec)) {
|
|
165
|
+
return [
|
|
166
|
+
`${file} : « @${spec} » dépend du poste, remplace-le par « ${RULES_IMPORT} »`,
|
|
167
|
+
]
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return existsSync(resolveImport(spec, input.root))
|
|
171
|
+
? []
|
|
172
|
+
: [
|
|
173
|
+
`${file} : « @${spec} » ne mène à aucun fichier (lance « bun install », ou remplace-le par « ${RULES_IMPORT} »)`,
|
|
174
|
+
]
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
return problems.length === 0 ? ok(label) : fail(label, problems.join(" ; "))
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function gitattributesCheck(input: DoctorInput): DoctorCheck {
|
|
181
|
+
const label = ".gitattributes impose les fins de ligne LF"
|
|
182
|
+
|
|
183
|
+
return hasLfAttributes(readText(join(input.root, ".gitattributes")))
|
|
184
|
+
? ok(label)
|
|
185
|
+
: fail(
|
|
186
|
+
label,
|
|
187
|
+
"ajoute « * text=auto eol=lf » à .gitattributes (sinon Git sous Windows extrait en CRLF et vp fmt --check échoue)."
|
|
188
|
+
)
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function infisicalCheck(input: DoctorInput): DoctorCheck {
|
|
192
|
+
const label = "CLI Infisical (infisical)"
|
|
193
|
+
|
|
194
|
+
if (!input.which("infisical")) {
|
|
195
|
+
return warn(
|
|
196
|
+
label,
|
|
197
|
+
"infisical introuvable (brew install infisical/get-cli/infisical) : rc secrets:pull garde les fichiers locaux tels quels, rc secrets:push ne marchera pas."
|
|
198
|
+
)
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return input.runner(["infisical", "login", "status"]).exitCode === 0
|
|
202
|
+
? ok(label)
|
|
203
|
+
: warn(label, "pas de session Infisical : lance « infisical login ».")
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function usesNeon(root: string): boolean {
|
|
207
|
+
try {
|
|
208
|
+
return loadConfig({ root }).config.database?.provider === "neon"
|
|
209
|
+
} catch {
|
|
210
|
+
return false
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function neonctlChecks(input: DoctorInput): DoctorCheck[] {
|
|
215
|
+
if (!usesNeon(input.root)) {
|
|
216
|
+
return []
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const label = "CLI Neon (neonctl)"
|
|
220
|
+
|
|
221
|
+
if (!input.which("neonctl")) {
|
|
222
|
+
return [
|
|
223
|
+
warn(
|
|
224
|
+
label,
|
|
225
|
+
"neonctl introuvable (bun install -g neonctl) : rc db:env ne peut pas écrire les chaînes de dev."
|
|
226
|
+
),
|
|
227
|
+
]
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return [
|
|
231
|
+
input.runner(["neonctl", "me", "-o", "json"], { env: { BROWSER: "true" } })
|
|
232
|
+
.exitCode === 0
|
|
233
|
+
? ok(label)
|
|
234
|
+
: warn(label, "pas de session neonctl : lance « neonctl auth »."),
|
|
235
|
+
]
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export function runDoctor(input: DoctorInput): DoctorCheck[] {
|
|
239
|
+
return [
|
|
240
|
+
bunCheck(input),
|
|
241
|
+
...dependencyChecks(input),
|
|
242
|
+
...configChecks(input),
|
|
243
|
+
rulesCheck(input),
|
|
244
|
+
gitattributesCheck(input),
|
|
245
|
+
infisicalCheck(input),
|
|
246
|
+
...neonctlChecks(input),
|
|
247
|
+
]
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const MARKS: Record<DoctorStatus, string> = {
|
|
251
|
+
ok: "✓",
|
|
252
|
+
warn: "!",
|
|
253
|
+
fail: "✗",
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export function formatDoctor(checks: readonly DoctorCheck[]): string {
|
|
257
|
+
return `${checks
|
|
258
|
+
.map((check) =>
|
|
259
|
+
[`${MARKS[check.status]} ${check.label}`, check.detail]
|
|
260
|
+
.filter(Boolean)
|
|
261
|
+
.join(" : ")
|
|
262
|
+
)
|
|
263
|
+
.join("\n")}\n`
|
|
264
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test"
|
|
2
|
+
|
|
3
|
+
import { applyEnvValues, isWritableEnvValue, parseEnvFile } from "./env-file"
|
|
4
|
+
import { filterKeys, matchesAny } from "./glob"
|
|
5
|
+
|
|
6
|
+
const AWKWARD_VALUES = {
|
|
7
|
+
BACKSLASH: "a\\b\\nc",
|
|
8
|
+
DOUBLE_QUOTE: 'pa"ss',
|
|
9
|
+
HASH: "abc#def",
|
|
10
|
+
JWK: '{"crv":"Ed25519","d":"x","kty":"OKP","x":"y"}',
|
|
11
|
+
PLAIN: "postgresql://u:p@host/db?sslmode=require",
|
|
12
|
+
SINGLE_QUOTE: "it's",
|
|
13
|
+
SPACES: " padded ",
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
describe("parseEnvFile", () => {
|
|
17
|
+
test("reads the forms dotenv accepts", () => {
|
|
18
|
+
const env = parseEnvFile(
|
|
19
|
+
[
|
|
20
|
+
"# comment",
|
|
21
|
+
"export EXPORTED=1",
|
|
22
|
+
"UNQUOTED=value # trailing comment",
|
|
23
|
+
"SINGLE='a \\n b'",
|
|
24
|
+
'DOUBLE="a\\nb"',
|
|
25
|
+
'HASHED="quoted # not a comment"',
|
|
26
|
+
"EMPTY=",
|
|
27
|
+
"",
|
|
28
|
+
].join("\n")
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
expect(Object.fromEntries(env)).toEqual({
|
|
32
|
+
DOUBLE: "a\nb",
|
|
33
|
+
EMPTY: "",
|
|
34
|
+
EXPORTED: "1",
|
|
35
|
+
HASHED: "quoted # not a comment",
|
|
36
|
+
SINGLE: "a \\n b",
|
|
37
|
+
UNQUOTED: "value",
|
|
38
|
+
})
|
|
39
|
+
})
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
describe("applyEnvValues", () => {
|
|
43
|
+
test("gives back every value it writes, verbatim", () => {
|
|
44
|
+
const written = applyEnvValues("", AWKWARD_VALUES)
|
|
45
|
+
|
|
46
|
+
expect(Object.fromEntries(parseEnvFile(written))).toEqual(AWKWARD_VALUES)
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
test("rewrites a key in place, keeps comments and appends new keys", () => {
|
|
50
|
+
expect(
|
|
51
|
+
applyEnvValues("# header\nA=old\nB=keep", { A: "new", C: "added" })
|
|
52
|
+
).toBe('# header\nA="new"\nB=keep\nC="added"')
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
test("appends before the final newline", () => {
|
|
56
|
+
expect(
|
|
57
|
+
applyEnvValues("# secrets\nA=old\nB=keep\n", { A: "new", C: "added" })
|
|
58
|
+
).toBe('# secrets\nA="new"\nB=keep\nC="added"\n')
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
test("writes a fresh file with a trailing newline", () => {
|
|
62
|
+
expect(applyEnvValues("", { A: "1" })).toBe('A="1"\n')
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
test("leaves a key that already holds a value alone when asked to", () => {
|
|
66
|
+
const next = applyEnvValues("A=set\nB=\n", { A: "x", B: "y", C: "z" }, true)
|
|
67
|
+
|
|
68
|
+
expect(next).toBe('A=set\nB="y"\nC="z"\n')
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
test("refuses a value it could not write back verbatim", () => {
|
|
72
|
+
expect(() => applyEnvValues("", { KEY: "line\nbreak" })).toThrow("KEY")
|
|
73
|
+
expect(isWritableEnvValue("line\nbreak")).toBe(false)
|
|
74
|
+
expect(isWritableEnvValue("`'\"")).toBe(false)
|
|
75
|
+
expect(isWritableEnvValue('it\'s "quoted"')).toBe(true)
|
|
76
|
+
})
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
describe("filterKeys", () => {
|
|
80
|
+
const values = { PUBLIC_SITE_KEY: "a", SECRET: "b", PUBLIC_TURNSTILE: "c" }
|
|
81
|
+
|
|
82
|
+
test("keeps every key without patterns", () => {
|
|
83
|
+
expect(filterKeys(values)).toEqual(values)
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
test("applies include then exclude globs", () => {
|
|
87
|
+
expect(filterKeys(values, ["PUBLIC_*"])).toEqual({
|
|
88
|
+
PUBLIC_SITE_KEY: "a",
|
|
89
|
+
PUBLIC_TURNSTILE: "c",
|
|
90
|
+
})
|
|
91
|
+
expect(filterKeys(values, undefined, ["PUBLIC_*"])).toEqual({ SECRET: "b" })
|
|
92
|
+
expect(filterKeys(values, ["PUBLIC_*"], ["*TURNSTILE"])).toEqual({
|
|
93
|
+
PUBLIC_SITE_KEY: "a",
|
|
94
|
+
})
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
test("matches globs literally apart from * and ?", () => {
|
|
98
|
+
expect(matchesAny("A.B", ["A.B"])).toBe(true)
|
|
99
|
+
expect(matchesAny("AXB", ["A.B"])).toBe(false)
|
|
100
|
+
expect(matchesAny("KEY_1", ["KEY_?"])).toBe(true)
|
|
101
|
+
})
|
|
102
|
+
})
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
const DOTENV_LINE_RE =
|
|
2
|
+
/^\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?$/gm
|
|
3
|
+
const SURROUNDING_QUOTES_RE = /^(['"`])([\s\S]*)\1$/m
|
|
4
|
+
const CARRIAGE_RETURN_RE = /\r\n?/g
|
|
5
|
+
const ESCAPED_NEWLINE_RE = /\\n/g
|
|
6
|
+
const ESCAPED_RETURN_RE = /\\r/g
|
|
7
|
+
const ENV_ASSIGNMENT_RE = /^(?:export\s+)?([A-Za-z0-9_]+)=/
|
|
8
|
+
const LINE_BREAK_RE = /[\r\n]/
|
|
9
|
+
|
|
10
|
+
export function parseEnvFile(content: string): Map<string, string> {
|
|
11
|
+
const env = new Map<string, string>()
|
|
12
|
+
const source = content.replace(CARRIAGE_RETURN_RE, "\n")
|
|
13
|
+
|
|
14
|
+
for (const [, key = "", raw = ""] of source.matchAll(DOTENV_LINE_RE)) {
|
|
15
|
+
const trimmed = raw.trim()
|
|
16
|
+
const unquoted = trimmed.replace(SURROUNDING_QUOTES_RE, "$2")
|
|
17
|
+
|
|
18
|
+
env.set(
|
|
19
|
+
key,
|
|
20
|
+
trimmed.startsWith('"')
|
|
21
|
+
? unquoted
|
|
22
|
+
.replace(ESCAPED_NEWLINE_RE, "\n")
|
|
23
|
+
.replace(ESCAPED_RETURN_RE, "\r")
|
|
24
|
+
: unquoted
|
|
25
|
+
)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return env
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// dotenv (Wrangler, Vite, Astro) never unescapes \" or \\, so the quote style is picked to need no escaping.
|
|
32
|
+
function formatEnvValue(key: string, value: string): string {
|
|
33
|
+
if (!LINE_BREAK_RE.test(value)) {
|
|
34
|
+
if (!(value.includes('"') || value.includes("\\"))) {
|
|
35
|
+
return `"${value}"`
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (!value.includes("'")) {
|
|
39
|
+
return `'${value}'`
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (!value.includes("`")) {
|
|
43
|
+
return `\`${value}\``
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
throw new Error(
|
|
48
|
+
`${key} ne peut pas être écrite telle quelle dans un fichier env : elle tient sur plusieurs lignes ou mélange tous les guillemets.`
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function isWritableEnvValue(value: string): boolean {
|
|
53
|
+
if (LINE_BREAK_RE.test(value)) {
|
|
54
|
+
return false
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const needsEscaping = value.includes('"') || value.includes("\\")
|
|
58
|
+
|
|
59
|
+
return !needsEscaping || !value.includes("'") || !value.includes("`")
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function applyEnvValues(
|
|
63
|
+
content: string,
|
|
64
|
+
values: Record<string, string>,
|
|
65
|
+
onlyMissing = false
|
|
66
|
+
): string {
|
|
67
|
+
const env = parseEnvFile(content)
|
|
68
|
+
const seen = new Set<string>()
|
|
69
|
+
const endsWithNewline = content === "" || content.endsWith("\n")
|
|
70
|
+
const body = content.endsWith("\n") ? content.slice(0, -1) : content
|
|
71
|
+
const lines = (body === "" ? [] : body.split("\n")).map((line) => {
|
|
72
|
+
const key = line.match(ENV_ASSIGNMENT_RE)?.[1]
|
|
73
|
+
|
|
74
|
+
if (!(key && Object.hasOwn(values, key))) {
|
|
75
|
+
return line
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
seen.add(key)
|
|
79
|
+
|
|
80
|
+
if (onlyMissing && env.get(key)) {
|
|
81
|
+
return line
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return `${key}=${formatEnvValue(key, values[key] ?? "")}`
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
for (const [key, value] of Object.entries(values)) {
|
|
88
|
+
if (seen.has(key) || (onlyMissing && env.get(key))) {
|
|
89
|
+
continue
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
lines.push(`${key}=${formatEnvValue(key, value)}`)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return lines.join("\n") + (endsWithNewline && lines.length > 0 ? "\n" : "")
|
|
96
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const SPECIAL_RE = /[.+^${}()|[\]\\]/g
|
|
2
|
+
|
|
3
|
+
export function globToRegExp(pattern: string): RegExp {
|
|
4
|
+
const source = pattern
|
|
5
|
+
.replace(SPECIAL_RE, "\\$&")
|
|
6
|
+
.replaceAll("*", ".*")
|
|
7
|
+
.replaceAll("?", ".")
|
|
8
|
+
|
|
9
|
+
return new RegExp(`^${source}$`)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function matchesAny(
|
|
13
|
+
value: string,
|
|
14
|
+
patterns: readonly string[]
|
|
15
|
+
): boolean {
|
|
16
|
+
return patterns.some((pattern) => globToRegExp(pattern).test(value))
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function filterKeys(
|
|
20
|
+
values: Record<string, string>,
|
|
21
|
+
include?: readonly string[],
|
|
22
|
+
exclude?: readonly string[]
|
|
23
|
+
): Record<string, string> {
|
|
24
|
+
return Object.fromEntries(
|
|
25
|
+
Object.entries(values).filter(
|
|
26
|
+
([key]) =>
|
|
27
|
+
(!include?.length || matchesAny(key, include)) &&
|
|
28
|
+
!(exclude?.length && matchesAny(key, exclude))
|
|
29
|
+
)
|
|
30
|
+
)
|
|
31
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { afterAll, describe, expect, test } from "bun:test"
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
type SecretsResult,
|
|
5
|
+
TOKEN_FILE,
|
|
6
|
+
parseSecrets,
|
|
7
|
+
readProjectSecrets,
|
|
8
|
+
readProjectToken,
|
|
9
|
+
readSecrets,
|
|
10
|
+
} from "./infisical"
|
|
11
|
+
import { cleanupTempDirs, fakeRunner, tempDir, writeTree } from "./test-utils"
|
|
12
|
+
import type { RunResult } from "./process"
|
|
13
|
+
|
|
14
|
+
const TARGET = {
|
|
15
|
+
projectId: "22222222-2222-4222-8222-222222222222",
|
|
16
|
+
environment: "prod",
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const EXPORT = JSON.stringify([
|
|
20
|
+
{ key: "BETTER_AUTH_SECRET", value: "fake-auth-secret" },
|
|
21
|
+
{ key: "TURNSTILE_SECRET_KEY", value: "fake-turnstile-secret" },
|
|
22
|
+
{ key: "WHATSAPP_ACCESS_TOKEN", value: "" },
|
|
23
|
+
{ key: "not a key", value: "ignored" },
|
|
24
|
+
{ key: "MULTILINE", value: "a\nb" },
|
|
25
|
+
])
|
|
26
|
+
|
|
27
|
+
function infisicalRunner(exportResult: Partial<RunResult> = {}) {
|
|
28
|
+
return fakeRunner((command) => {
|
|
29
|
+
if (command[1] === "--version") {
|
|
30
|
+
return { stdout: "0.45.4" }
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (command[1] === "export") {
|
|
34
|
+
return { stdout: EXPORT, ...exportResult }
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return { exitCode: 1 }
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function reasonOf(result: SecretsResult): string {
|
|
42
|
+
return result.ok ? "" : result.reason
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
describe("parseSecrets", () => {
|
|
46
|
+
test("keeps one value per UPPER_SNAKE key, empty values meaning unset", () => {
|
|
47
|
+
expect(parseSecrets(EXPORT)).toEqual({
|
|
48
|
+
BETTER_AUTH_SECRET: "fake-auth-secret",
|
|
49
|
+
TURNSTILE_SECRET_KEY: "fake-turnstile-secret",
|
|
50
|
+
MULTILINE: "a\nb",
|
|
51
|
+
})
|
|
52
|
+
})
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
describe("readSecrets", () => {
|
|
56
|
+
test("exports the project's environment as JSON, without prompting", () => {
|
|
57
|
+
const { runner, calls } = infisicalRunner()
|
|
58
|
+
const result = readSecrets(TARGET, runner)
|
|
59
|
+
|
|
60
|
+
expect(result.ok).toBe(true)
|
|
61
|
+
expect(calls[1]?.command).toEqual([
|
|
62
|
+
"infisical",
|
|
63
|
+
"export",
|
|
64
|
+
"--projectId",
|
|
65
|
+
"22222222-2222-4222-8222-222222222222",
|
|
66
|
+
"--env",
|
|
67
|
+
"prod",
|
|
68
|
+
"--format",
|
|
69
|
+
"json",
|
|
70
|
+
"--silent",
|
|
71
|
+
])
|
|
72
|
+
expect(calls[1]?.options.input).toBe("")
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
test("tells how to install the CLI when it is missing", () => {
|
|
76
|
+
const { runner } = fakeRunner(() => ({ exitCode: 127 }))
|
|
77
|
+
|
|
78
|
+
expect(reasonOf(readSecrets(TARGET, runner))).toContain(
|
|
79
|
+
"brew install infisical/get-cli/infisical"
|
|
80
|
+
)
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
test("tells to log in when the export is refused, without throwing", () => {
|
|
84
|
+
const { runner } = infisicalRunner({
|
|
85
|
+
exitCode: 1,
|
|
86
|
+
stderr: "not logged in",
|
|
87
|
+
})
|
|
88
|
+
const reason = reasonOf(readSecrets(TARGET, runner))
|
|
89
|
+
|
|
90
|
+
expect(reason).toContain("infisical login")
|
|
91
|
+
expect(reason).toContain("not logged in")
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
test("reports an unreadable export instead of throwing", () => {
|
|
95
|
+
const { runner } = infisicalRunner({ stdout: "not json" })
|
|
96
|
+
|
|
97
|
+
expect(reasonOf(readSecrets(TARGET, runner))).toContain("réponse illisible")
|
|
98
|
+
})
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
afterAll(cleanupTempDirs)
|
|
102
|
+
|
|
103
|
+
function untrackedRunner() {
|
|
104
|
+
return fakeRunner((command) => {
|
|
105
|
+
if (command[0] === "git") {
|
|
106
|
+
return { exitCode: 1 }
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (command[1] === "--version") {
|
|
110
|
+
return { stdout: "0.45.4" }
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (command[1] === "export") {
|
|
114
|
+
return { stdout: EXPORT }
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return { exitCode: 1 }
|
|
118
|
+
})
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
describe("readProjectToken", () => {
|
|
122
|
+
test("finds nothing without a token file", () => {
|
|
123
|
+
const { runner, calls } = untrackedRunner()
|
|
124
|
+
|
|
125
|
+
expect(readProjectToken(tempDir(), runner)).toEqual({ ok: true })
|
|
126
|
+
expect(calls).toHaveLength(0)
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
test("reads the token without surrounding whitespace", () => {
|
|
130
|
+
const root = writeTree(tempDir(), {
|
|
131
|
+
[TOKEN_FILE]: " fake-project-token\r\n",
|
|
132
|
+
})
|
|
133
|
+
const { runner } = untrackedRunner()
|
|
134
|
+
|
|
135
|
+
expect(readProjectToken(root, runner)).toEqual({
|
|
136
|
+
ok: true,
|
|
137
|
+
token: "fake-project-token",
|
|
138
|
+
})
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
test("refuses a token file tracked by git, without echoing it", () => {
|
|
142
|
+
const root = writeTree(tempDir(), { [TOKEN_FILE]: "fake-project-token" })
|
|
143
|
+
const { runner } = fakeRunner(() => ({ exitCode: 0 }))
|
|
144
|
+
const result = readProjectToken(root, runner)
|
|
145
|
+
|
|
146
|
+
expect(result.ok).toBe(false)
|
|
147
|
+
expect(result.ok ? "" : result.reason).toContain("suivi par git")
|
|
148
|
+
expect(result.ok ? "" : result.reason).not.toContain("fake-project-token")
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
test("refuses an empty token file", () => {
|
|
152
|
+
const root = writeTree(tempDir(), { [TOKEN_FILE]: "\n" })
|
|
153
|
+
const { runner } = untrackedRunner()
|
|
154
|
+
const result = readProjectToken(root, runner)
|
|
155
|
+
|
|
156
|
+
expect(result.ok ? "" : result.reason).toContain("est vide")
|
|
157
|
+
})
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
describe("readProjectSecrets", () => {
|
|
161
|
+
test("hands the project token to the CLI through INFISICAL_TOKEN", () => {
|
|
162
|
+
const root = writeTree(tempDir(), { [TOKEN_FILE]: "fake-project-token\n" })
|
|
163
|
+
const { runner, calls } = untrackedRunner()
|
|
164
|
+
const result = readProjectSecrets(TARGET, root, runner)
|
|
165
|
+
const exportCall = calls.find((call) => call.command[1] === "export")
|
|
166
|
+
|
|
167
|
+
expect(result.ok).toBe(true)
|
|
168
|
+
expect(exportCall?.options.env).toEqual({
|
|
169
|
+
INFISICAL_TOKEN: "fake-project-token",
|
|
170
|
+
})
|
|
171
|
+
expect(exportCall?.command.join(" ")).not.toContain("fake-project-token")
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
test("keeps the login session without a token file", () => {
|
|
175
|
+
const { runner, calls } = untrackedRunner()
|
|
176
|
+
const result = readProjectSecrets(TARGET, tempDir(), runner)
|
|
177
|
+
const exportCall = calls.find((call) => call.command[1] === "export")
|
|
178
|
+
|
|
179
|
+
expect(result.ok).toBe(true)
|
|
180
|
+
expect(exportCall?.options.env).toBeUndefined()
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
test("blames the token file, not the session, when the token is refused", () => {
|
|
184
|
+
const root = writeTree(tempDir(), { [TOKEN_FILE]: "fake-project-token" })
|
|
185
|
+
const { runner } = fakeRunner((command) => {
|
|
186
|
+
if (command[0] === "git") {
|
|
187
|
+
return { exitCode: 1 }
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
return command[1] === "export" ? { exitCode: 1, stderr: "401" } : {}
|
|
191
|
+
})
|
|
192
|
+
const result = readProjectSecrets(TARGET, root, runner)
|
|
193
|
+
const reason = result.ok ? "" : result.reason
|
|
194
|
+
|
|
195
|
+
expect(reason).toContain(`jeton de ${TOKEN_FILE} refusé`)
|
|
196
|
+
expect(reason).not.toContain("infisical login")
|
|
197
|
+
expect(reason).not.toContain("fake-project-token")
|
|
198
|
+
})
|
|
199
|
+
|
|
200
|
+
test("reads nothing when the token file is tracked", () => {
|
|
201
|
+
const root = writeTree(tempDir(), { [TOKEN_FILE]: "fake-project-token" })
|
|
202
|
+
const { runner, calls } = fakeRunner(() => ({ exitCode: 0 }))
|
|
203
|
+
const result = readProjectSecrets(TARGET, root, runner)
|
|
204
|
+
|
|
205
|
+
expect(result.ok).toBe(false)
|
|
206
|
+
expect(calls.some((call) => call.command[1] === "export")).toBe(false)
|
|
207
|
+
})
|
|
208
|
+
})
|