@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,139 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs"
|
|
2
|
+
import { join } from "node:path"
|
|
3
|
+
|
|
4
|
+
import type { InfisicalTarget } from "./config"
|
|
5
|
+
import { type Runner, runCommand } from "./process"
|
|
6
|
+
|
|
7
|
+
const KEY_RE = /^[A-Z][A-Z0-9_]*$/
|
|
8
|
+
|
|
9
|
+
export const TOKEN_FILE = ".infisical-token"
|
|
10
|
+
|
|
11
|
+
export type SecretsResult =
|
|
12
|
+
| { ok: true; values: Record<string, string> }
|
|
13
|
+
| { ok: false; reason: string }
|
|
14
|
+
|
|
15
|
+
export type ProjectToken =
|
|
16
|
+
| { ok: true; token?: string }
|
|
17
|
+
| { ok: false; reason: string }
|
|
18
|
+
|
|
19
|
+
interface InfisicalSecret {
|
|
20
|
+
key?: unknown
|
|
21
|
+
value?: unknown
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function parseSecrets(json: string): Record<string, string> {
|
|
25
|
+
const rows = JSON.parse(json) as InfisicalSecret[]
|
|
26
|
+
const values: Record<string, string> = {}
|
|
27
|
+
|
|
28
|
+
for (const row of rows) {
|
|
29
|
+
if (
|
|
30
|
+
typeof row.key !== "string" ||
|
|
31
|
+
!KEY_RE.test(row.key) ||
|
|
32
|
+
typeof row.value !== "string" ||
|
|
33
|
+
row.value === ""
|
|
34
|
+
) {
|
|
35
|
+
continue
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
values[row.key] = row.value
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return values
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function infisicalAvailable(runner: Runner = runCommand): boolean {
|
|
45
|
+
return runner(["infisical", "--version"]).exitCode === 0
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function isTokenFileTracked(
|
|
49
|
+
root: string,
|
|
50
|
+
runner: Runner = runCommand
|
|
51
|
+
): boolean {
|
|
52
|
+
return (
|
|
53
|
+
runner(["git", "ls-files", "--error-unmatch", TOKEN_FILE], { cwd: root })
|
|
54
|
+
.exitCode === 0
|
|
55
|
+
)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function readProjectToken(
|
|
59
|
+
root: string,
|
|
60
|
+
runner: Runner = runCommand
|
|
61
|
+
): ProjectToken {
|
|
62
|
+
const file = join(root, TOKEN_FILE)
|
|
63
|
+
|
|
64
|
+
if (!existsSync(file)) {
|
|
65
|
+
return { ok: true }
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (isTokenFileTracked(root, runner)) {
|
|
69
|
+
return {
|
|
70
|
+
ok: false,
|
|
71
|
+
reason: `${TOKEN_FILE} est suivi par git : retire-le de l'index (\`git rm --cached ${TOKEN_FILE}\`), ajoute-le à .gitignore, puis relance.`,
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const token = readFileSync(file, "utf8").trim()
|
|
76
|
+
|
|
77
|
+
return token === ""
|
|
78
|
+
? { ok: false, reason: `${TOKEN_FILE} est vide.` }
|
|
79
|
+
: { ok: true, token }
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function readSecrets(
|
|
83
|
+
target: InfisicalTarget,
|
|
84
|
+
runner: Runner = runCommand,
|
|
85
|
+
token?: string
|
|
86
|
+
): SecretsResult {
|
|
87
|
+
if (!infisicalAvailable(runner)) {
|
|
88
|
+
return {
|
|
89
|
+
ok: false,
|
|
90
|
+
reason:
|
|
91
|
+
"la CLI Infisical (`infisical`) est introuvable. Installe-la avec `brew install infisical/get-cli/infisical` (ou la méthode de ton système), puis lance `infisical login`.",
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const result = runner(
|
|
96
|
+
[
|
|
97
|
+
"infisical",
|
|
98
|
+
"export",
|
|
99
|
+
"--projectId",
|
|
100
|
+
target.projectId,
|
|
101
|
+
"--env",
|
|
102
|
+
target.environment,
|
|
103
|
+
"--format",
|
|
104
|
+
"json",
|
|
105
|
+
"--silent",
|
|
106
|
+
],
|
|
107
|
+
{ input: "", env: token ? { INFISICAL_TOKEN: token } : undefined }
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
if (result.exitCode !== 0) {
|
|
111
|
+
return {
|
|
112
|
+
ok: false,
|
|
113
|
+
reason: `impossible de lire les secrets de l'environnement « ${target.environment} » du projet Infisical ${target.projectId} (${token ? `jeton de ${TOKEN_FILE} refusé, expiré ou sans accès à cet environnement` : "session fermée ? lance `infisical login`"}).\n ${result.stderr.trim() || "erreur inconnue"}`,
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
try {
|
|
118
|
+
return { ok: true, values: parseSecrets(result.stdout) }
|
|
119
|
+
} catch {
|
|
120
|
+
return {
|
|
121
|
+
ok: false,
|
|
122
|
+
reason: "réponse illisible de `infisical export`.",
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export function readProjectSecrets(
|
|
128
|
+
target: InfisicalTarget,
|
|
129
|
+
root: string,
|
|
130
|
+
runner: Runner = runCommand
|
|
131
|
+
): SecretsResult {
|
|
132
|
+
const project = readProjectToken(root, runner)
|
|
133
|
+
|
|
134
|
+
if (!project.ok) {
|
|
135
|
+
return { ok: false, reason: project.reason }
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return readSecrets(target, runner, project.token)
|
|
139
|
+
}
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
export interface JsonSchema {
|
|
2
|
+
$ref?: string
|
|
3
|
+
$defs?: Record<string, JsonSchema>
|
|
4
|
+
type?: string | string[]
|
|
5
|
+
enum?: unknown[]
|
|
6
|
+
const?: unknown
|
|
7
|
+
properties?: Record<string, JsonSchema>
|
|
8
|
+
required?: string[]
|
|
9
|
+
additionalProperties?: boolean | JsonSchema
|
|
10
|
+
propertyNames?: JsonSchema
|
|
11
|
+
minProperties?: number
|
|
12
|
+
items?: JsonSchema
|
|
13
|
+
uniqueItems?: boolean
|
|
14
|
+
minItems?: number
|
|
15
|
+
minLength?: number
|
|
16
|
+
pattern?: string
|
|
17
|
+
[keyword: string]: unknown
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface SchemaError {
|
|
21
|
+
path: string
|
|
22
|
+
message: string
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function typeOf(value: unknown): string {
|
|
26
|
+
if (value === null) {
|
|
27
|
+
return "null"
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (Array.isArray(value)) {
|
|
31
|
+
return "array"
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (typeof value === "number" && Number.isInteger(value)) {
|
|
35
|
+
return "integer"
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return typeof value
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function matchesType(value: unknown, expected: string): boolean {
|
|
42
|
+
const actual = typeOf(value)
|
|
43
|
+
|
|
44
|
+
return actual === expected || (expected === "number" && actual === "integer")
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function resolveRef(root: JsonSchema, ref: string): JsonSchema {
|
|
48
|
+
const prefix = "#/$defs/"
|
|
49
|
+
const target = ref.startsWith(prefix)
|
|
50
|
+
? root.$defs?.[ref.slice(prefix.length)]
|
|
51
|
+
: undefined
|
|
52
|
+
|
|
53
|
+
if (!target) {
|
|
54
|
+
throw new Error(`Unsupported $ref ${ref}`)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return target
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function pointer(path: string, key: string | number): string {
|
|
61
|
+
return `${path}/${String(key).replaceAll("~", "~0").replaceAll("/", "~1")}`
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function validateObject(
|
|
65
|
+
value: Record<string, unknown>,
|
|
66
|
+
schema: JsonSchema,
|
|
67
|
+
root: JsonSchema,
|
|
68
|
+
path: string,
|
|
69
|
+
errors: SchemaError[]
|
|
70
|
+
): void {
|
|
71
|
+
const keys = Object.keys(value)
|
|
72
|
+
|
|
73
|
+
for (const key of schema.required ?? []) {
|
|
74
|
+
if (!(key in value)) {
|
|
75
|
+
errors.push({ path, message: `propriété requise « ${key} » absente` })
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (
|
|
80
|
+
schema.minProperties !== undefined &&
|
|
81
|
+
keys.length < schema.minProperties
|
|
82
|
+
) {
|
|
83
|
+
errors.push({
|
|
84
|
+
path,
|
|
85
|
+
message: `au moins ${schema.minProperties} propriété(s) attendue(s)`,
|
|
86
|
+
})
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
for (const key of keys) {
|
|
90
|
+
const childPath = pointer(path, key)
|
|
91
|
+
|
|
92
|
+
if (schema.propertyNames) {
|
|
93
|
+
validateNode(key, schema.propertyNames, root, childPath, errors)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const property = schema.properties?.[key]
|
|
97
|
+
|
|
98
|
+
if (property) {
|
|
99
|
+
validateNode(value[key], property, root, childPath, errors)
|
|
100
|
+
continue
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (schema.additionalProperties === false) {
|
|
104
|
+
errors.push({ path: childPath, message: "propriété inconnue" })
|
|
105
|
+
} else if (typeof schema.additionalProperties === "object") {
|
|
106
|
+
validateNode(
|
|
107
|
+
value[key],
|
|
108
|
+
schema.additionalProperties,
|
|
109
|
+
root,
|
|
110
|
+
childPath,
|
|
111
|
+
errors
|
|
112
|
+
)
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function validateArray(
|
|
118
|
+
value: unknown[],
|
|
119
|
+
schema: JsonSchema,
|
|
120
|
+
root: JsonSchema,
|
|
121
|
+
path: string,
|
|
122
|
+
errors: SchemaError[]
|
|
123
|
+
): void {
|
|
124
|
+
if (schema.minItems !== undefined && value.length < schema.minItems) {
|
|
125
|
+
errors.push({
|
|
126
|
+
path,
|
|
127
|
+
message: `au moins ${schema.minItems} élément(s) attendu(s)`,
|
|
128
|
+
})
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (schema.uniqueItems) {
|
|
132
|
+
const seen = new Set(value.map((item) => JSON.stringify(item)))
|
|
133
|
+
|
|
134
|
+
if (seen.size !== value.length) {
|
|
135
|
+
errors.push({ path, message: "éléments en double" })
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (schema.items) {
|
|
140
|
+
for (const [index, item] of value.entries()) {
|
|
141
|
+
validateNode(item, schema.items, root, pointer(path, index), errors)
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function validateString(
|
|
147
|
+
value: string,
|
|
148
|
+
schema: JsonSchema,
|
|
149
|
+
path: string,
|
|
150
|
+
errors: SchemaError[]
|
|
151
|
+
): void {
|
|
152
|
+
if (schema.minLength !== undefined && value.length < schema.minLength) {
|
|
153
|
+
errors.push({ path, message: "chaîne vide" })
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (schema.pattern && !new RegExp(schema.pattern, "u").test(value)) {
|
|
157
|
+
errors.push({
|
|
158
|
+
path,
|
|
159
|
+
message: `« ${value} » ne respecte pas ${schema.pattern}`,
|
|
160
|
+
})
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function validateNode(
|
|
165
|
+
value: unknown,
|
|
166
|
+
schema: JsonSchema,
|
|
167
|
+
root: JsonSchema,
|
|
168
|
+
path: string,
|
|
169
|
+
errors: SchemaError[]
|
|
170
|
+
): void {
|
|
171
|
+
if (schema.$ref) {
|
|
172
|
+
validateNode(value, resolveRef(root, schema.$ref), root, path, errors)
|
|
173
|
+
return
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (schema.type) {
|
|
177
|
+
const types = Array.isArray(schema.type) ? schema.type : [schema.type]
|
|
178
|
+
|
|
179
|
+
if (!types.some((type) => matchesType(value, type))) {
|
|
180
|
+
errors.push({
|
|
181
|
+
path,
|
|
182
|
+
message: `type ${types.join(" | ")} attendu, ${typeOf(value)} trouvé`,
|
|
183
|
+
})
|
|
184
|
+
return
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (schema.enum && !schema.enum.some((option) => option === value)) {
|
|
189
|
+
errors.push({
|
|
190
|
+
path,
|
|
191
|
+
message: `valeur attendue parmi ${schema.enum.map((option) => JSON.stringify(option)).join(", ")}`,
|
|
192
|
+
})
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if ("const" in schema && schema.const !== value) {
|
|
196
|
+
errors.push({
|
|
197
|
+
path,
|
|
198
|
+
message: `valeur attendue ${JSON.stringify(schema.const)}`,
|
|
199
|
+
})
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if (typeOf(value) === "object") {
|
|
203
|
+
validateObject(value as Record<string, unknown>, schema, root, path, errors)
|
|
204
|
+
} else if (Array.isArray(value)) {
|
|
205
|
+
validateArray(value, schema, root, path, errors)
|
|
206
|
+
} else if (typeof value === "string") {
|
|
207
|
+
validateString(value, schema, path, errors)
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export function validateSchema(
|
|
212
|
+
value: unknown,
|
|
213
|
+
schema: JsonSchema
|
|
214
|
+
): SchemaError[] {
|
|
215
|
+
const errors: SchemaError[] = []
|
|
216
|
+
|
|
217
|
+
validateNode(value, schema, schema, "", errors)
|
|
218
|
+
|
|
219
|
+
return errors
|
|
220
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test"
|
|
2
|
+
|
|
3
|
+
import { parseJsonc, stripJsonc } from "./jsonc"
|
|
4
|
+
|
|
5
|
+
describe("parseJsonc", () => {
|
|
6
|
+
test("drops line and block comments outside strings", () => {
|
|
7
|
+
const source = `{
|
|
8
|
+
// the local level
|
|
9
|
+
"name": "gio-web-local", /* inline */
|
|
10
|
+
"url": "https://example.com/a//b",
|
|
11
|
+
"glob": "/* not a comment */"
|
|
12
|
+
}`
|
|
13
|
+
|
|
14
|
+
expect(parseJsonc(source)).toEqual({
|
|
15
|
+
name: "gio-web-local",
|
|
16
|
+
url: "https://example.com/a//b",
|
|
17
|
+
glob: "/* not a comment */",
|
|
18
|
+
})
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
test("drops trailing commas, even before a comment", () => {
|
|
22
|
+
expect(
|
|
23
|
+
parseJsonc('{ "a": [1, 2, ], "b": { "c": true, // last\n }, }')
|
|
24
|
+
).toEqual({
|
|
25
|
+
a: [1, 2],
|
|
26
|
+
b: { c: true },
|
|
27
|
+
})
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
test("keeps commas and escaped quotes inside strings", () => {
|
|
31
|
+
expect(parseJsonc('{ "a": "x, }", "b": "say \\"hi\\", ]" }')).toEqual({
|
|
32
|
+
a: "x, }",
|
|
33
|
+
b: 'say "hi", ]',
|
|
34
|
+
})
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
test("refuses an unterminated block comment", () => {
|
|
38
|
+
expect(() => stripJsonc('{ /* open "a": 1 }')).toThrow("Unterminated")
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
test("reads a real Wrangler config shape", () => {
|
|
42
|
+
const config = parseJsonc<{ env: { production: { name: string } } }>(`{
|
|
43
|
+
"$schema": "node_modules/wrangler/config-schema.json",
|
|
44
|
+
"name": "adv-admin-local",
|
|
45
|
+
"env": {
|
|
46
|
+
// Fabrikam Motors
|
|
47
|
+
"production": { "name": "adv-admin-prod", },
|
|
48
|
+
},
|
|
49
|
+
}`)
|
|
50
|
+
|
|
51
|
+
expect(config.env.production.name).toBe("adv-admin-prod")
|
|
52
|
+
})
|
|
53
|
+
})
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
function skipString(source: string, start: number): number {
|
|
2
|
+
let index = start + 1
|
|
3
|
+
|
|
4
|
+
while (index < source.length && source[index] !== '"') {
|
|
5
|
+
index += source[index] === "\\" ? 2 : 1
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
return index + 1
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function skipComment(source: string, start: number): number {
|
|
12
|
+
if (source[start + 1] === "/") {
|
|
13
|
+
const end = source.indexOf("\n", start)
|
|
14
|
+
|
|
15
|
+
return end === -1 ? source.length : end
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const end = source.indexOf("*/", start + 2)
|
|
19
|
+
|
|
20
|
+
if (end === -1) {
|
|
21
|
+
throw new SyntaxError(`Unterminated block comment at offset ${start}`)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return end + 2
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function isCommentStart(source: string, index: number): boolean {
|
|
28
|
+
return (
|
|
29
|
+
source[index] === "/" &&
|
|
30
|
+
(source[index + 1] === "/" || source[index + 1] === "*")
|
|
31
|
+
)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function nextSignificant(source: string, start: number): string | undefined {
|
|
35
|
+
let index = start
|
|
36
|
+
|
|
37
|
+
while (index < source.length) {
|
|
38
|
+
if (isCommentStart(source, index)) {
|
|
39
|
+
index = skipComment(source, index)
|
|
40
|
+
continue
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const char = source[index] ?? ""
|
|
44
|
+
|
|
45
|
+
if (!/\s/.test(char)) {
|
|
46
|
+
return char
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
index += 1
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return undefined
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function stripJsonc(source: string): string {
|
|
56
|
+
let out = ""
|
|
57
|
+
let index = 0
|
|
58
|
+
|
|
59
|
+
while (index < source.length) {
|
|
60
|
+
const char = source[index]
|
|
61
|
+
|
|
62
|
+
if (char === '"') {
|
|
63
|
+
const end = skipString(source, index)
|
|
64
|
+
|
|
65
|
+
out += source.slice(index, end)
|
|
66
|
+
index = end
|
|
67
|
+
continue
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (isCommentStart(source, index)) {
|
|
71
|
+
index = skipComment(source, index)
|
|
72
|
+
continue
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (char === ",") {
|
|
76
|
+
const next = nextSignificant(source, index + 1)
|
|
77
|
+
|
|
78
|
+
if (next === "}" || next === "]") {
|
|
79
|
+
index += 1
|
|
80
|
+
continue
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
out += char
|
|
85
|
+
index += 1
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return out
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function parseJsonc<T = unknown>(source: string): T {
|
|
92
|
+
return JSON.parse(stripJsonc(source)) as T
|
|
93
|
+
}
|