@sidekickdb/cli 0.0.0-stage → 2.0.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/.turbo/turbo-build.log +4 -0
- package/LICENSE.md +202 -0
- package/NOTICE +27 -0
- package/README.md +68 -2
- package/__tests__/appCommands.test.ts +229 -0
- package/__tests__/args.test.ts +358 -0
- package/__tests__/auth.test.ts +128 -0
- package/__tests__/authClientAddApple.test.ts +377 -0
- package/__tests__/authClientAddClerk.test.ts +223 -0
- package/__tests__/authClientAddGithub.test.ts +245 -0
- package/__tests__/authClientAddGoogle.test.ts +374 -0
- package/__tests__/authClientAddLinkedin.test.ts +263 -0
- package/__tests__/authClientList.test.ts +90 -0
- package/__tests__/authClientUpdate.test.ts +584 -0
- package/__tests__/authOriginManagement.test.ts +308 -0
- package/__tests__/backupDownload.test.ts +206 -0
- package/__tests__/backups.test.ts +222 -0
- package/__tests__/config.test.ts +164 -0
- package/__tests__/configAliases.test.ts +232 -0
- package/__tests__/e2e/cli.e2e.test.ts +1269 -0
- package/__tests__/e2e/helpers.ts +186 -0
- package/__tests__/effectHelpers.ts +45 -0
- package/__tests__/legacyPackageCompat.test.ts +104 -0
- package/__tests__/mergeSchema.test.ts +197 -0
- package/__tests__/multiSelect.test.ts +236 -0
- package/__tests__/oauthMock.ts +76 -0
- package/__tests__/promptOk.test.ts +44 -0
- package/__tests__/redirectUriPrompt.test.ts +40 -0
- package/__tests__/select.test.ts +224 -0
- package/__tests__/webhooks.test.ts +729 -0
- package/bin/index.js +3 -0
- package/dist/auth/index.d.ts +4 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +103 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/commands/app/delete.d.ts +7 -0
- package/dist/commands/app/delete.d.ts.map +1 -0
- package/dist/commands/app/delete.js +57 -0
- package/dist/commands/app/delete.js.map +1 -0
- package/dist/commands/app/list.d.ts +6 -0
- package/dist/commands/app/list.d.ts.map +1 -0
- package/dist/commands/app/list.js +29 -0
- package/dist/commands/app/list.js.map +1 -0
- package/dist/commands/auth/client/add.d.ts +9 -0
- package/dist/commands/auth/client/add.d.ts.map +1 -0
- package/dist/commands/auth/client/add.js +409 -0
- package/dist/commands/auth/client/add.js.map +1 -0
- package/dist/commands/auth/client/delete.d.ts +11 -0
- package/dist/commands/auth/client/delete.d.ts.map +1 -0
- package/dist/commands/auth/client/delete.js +48 -0
- package/dist/commands/auth/client/delete.js.map +1 -0
- package/dist/commands/auth/client/list.d.ts +6 -0
- package/dist/commands/auth/client/list.d.ts.map +1 -0
- package/dist/commands/auth/client/list.js +38 -0
- package/dist/commands/auth/client/list.js.map +1 -0
- package/dist/commands/auth/client/shared.d.ts +70 -0
- package/dist/commands/auth/client/shared.d.ts.map +1 -0
- package/dist/commands/auth/client/shared.js +140 -0
- package/dist/commands/auth/client/shared.js.map +1 -0
- package/dist/commands/auth/client/update.d.ts +8 -0
- package/dist/commands/auth/client/update.d.ts.map +1 -0
- package/dist/commands/auth/client/update.js +445 -0
- package/dist/commands/auth/client/update.js.map +1 -0
- package/dist/commands/auth/email/pull.d.ts +24 -0
- package/dist/commands/auth/email/pull.d.ts.map +1 -0
- package/dist/commands/auth/email/pull.js +100 -0
- package/dist/commands/auth/email/pull.js.map +1 -0
- package/dist/commands/auth/email/push.d.ts +8 -0
- package/dist/commands/auth/email/push.d.ts.map +1 -0
- package/dist/commands/auth/email/push.js +58 -0
- package/dist/commands/auth/email/push.js.map +1 -0
- package/dist/commands/auth/email/resend.d.ts +3 -0
- package/dist/commands/auth/email/resend.d.ts.map +1 -0
- package/dist/commands/auth/email/resend.js +7 -0
- package/dist/commands/auth/email/resend.js.map +1 -0
- package/dist/commands/auth/email/reset.d.ts +5 -0
- package/dist/commands/auth/email/reset.d.ts.map +1 -0
- package/dist/commands/auth/email/reset.js +25 -0
- package/dist/commands/auth/email/reset.js.map +1 -0
- package/dist/commands/auth/email/status.d.ts +57 -0
- package/dist/commands/auth/email/status.d.ts.map +1 -0
- package/dist/commands/auth/email/status.js +96 -0
- package/dist/commands/auth/email/status.js.map +1 -0
- package/dist/commands/auth/email/verify.d.ts +5 -0
- package/dist/commands/auth/email/verify.d.ts.map +1 -0
- package/dist/commands/auth/email/verify.js +12 -0
- package/dist/commands/auth/email/verify.js.map +1 -0
- package/dist/commands/auth/origin/add.d.ts +12 -0
- package/dist/commands/auth/origin/add.d.ts.map +1 -0
- package/dist/commands/auth/origin/add.js +153 -0
- package/dist/commands/auth/origin/add.js.map +1 -0
- package/dist/commands/auth/origin/delete.d.ts +8 -0
- package/dist/commands/auth/origin/delete.d.ts.map +1 -0
- package/dist/commands/auth/origin/delete.js +38 -0
- package/dist/commands/auth/origin/delete.js.map +1 -0
- package/dist/commands/auth/origin/list.d.ts +9 -0
- package/dist/commands/auth/origin/list.d.ts.map +1 -0
- package/dist/commands/auth/origin/list.js +52 -0
- package/dist/commands/auth/origin/list.js.map +1 -0
- package/dist/commands/backup/download.d.ts +10 -0
- package/dist/commands/backup/download.d.ts.map +1 -0
- package/dist/commands/backup/download.js +174 -0
- package/dist/commands/backup/download.js.map +1 -0
- package/dist/commands/backup/list.d.ts +11 -0
- package/dist/commands/backup/list.d.ts.map +1 -0
- package/dist/commands/backup/list.js +74 -0
- package/dist/commands/backup/list.js.map +1 -0
- package/dist/commands/claim.d.ts +6 -0
- package/dist/commands/claim.d.ts.map +1 -0
- package/dist/commands/claim.js +22 -0
- package/dist/commands/claim.js.map +1 -0
- package/dist/commands/explorer.d.ts +6 -0
- package/dist/commands/explorer.d.ts.map +1 -0
- package/dist/commands/explorer.js +13 -0
- package/dist/commands/explorer.js.map +1 -0
- package/dist/commands/info.d.ts +9 -0
- package/dist/commands/info.d.ts.map +1 -0
- package/dist/commands/info.js +41 -0
- package/dist/commands/info.js.map +1 -0
- package/dist/commands/init.d.ts +5 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +41 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/initWithoutFiles.d.ts +6 -0
- package/dist/commands/initWithoutFiles.d.ts.map +1 -0
- package/dist/commands/initWithoutFiles.js +64 -0
- package/dist/commands/initWithoutFiles.js.map +1 -0
- package/dist/commands/login.d.ts +9 -0
- package/dist/commands/login.d.ts.map +1 -0
- package/dist/commands/login.js +44 -0
- package/dist/commands/login.js.map +1 -0
- package/dist/commands/logout.d.ts +3 -0
- package/dist/commands/logout.d.ts.map +1 -0
- package/dist/commands/logout.js +14 -0
- package/dist/commands/logout.js.map +1 -0
- package/dist/commands/pull.d.ts +5 -0
- package/dist/commands/pull.d.ts.map +1 -0
- package/dist/commands/pull.js +15 -0
- package/dist/commands/pull.js.map +1 -0
- package/dist/commands/push.d.ts +6 -0
- package/dist/commands/push.d.ts.map +1 -0
- package/dist/commands/push.js +20 -0
- package/dist/commands/push.js.map +1 -0
- package/dist/commands/query.d.ts +7 -0
- package/dist/commands/query.d.ts.map +1 -0
- package/dist/commands/query.js +52 -0
- package/dist/commands/query.js.map +1 -0
- package/dist/commands/webhooks/add.d.ts +9 -0
- package/dist/commands/webhooks/add.d.ts.map +1 -0
- package/dist/commands/webhooks/add.js +75 -0
- package/dist/commands/webhooks/add.js.map +1 -0
- package/dist/commands/webhooks/delete.d.ts +6 -0
- package/dist/commands/webhooks/delete.d.ts.map +1 -0
- package/dist/commands/webhooks/delete.js +17 -0
- package/dist/commands/webhooks/delete.js.map +1 -0
- package/dist/commands/webhooks/disable.d.ts +7 -0
- package/dist/commands/webhooks/disable.d.ts.map +1 -0
- package/dist/commands/webhooks/disable.js +18 -0
- package/dist/commands/webhooks/disable.js.map +1 -0
- package/dist/commands/webhooks/enable.d.ts +6 -0
- package/dist/commands/webhooks/enable.d.ts.map +1 -0
- package/dist/commands/webhooks/enable.js +18 -0
- package/dist/commands/webhooks/enable.js.map +1 -0
- package/dist/commands/webhooks/events/list.d.ts +7 -0
- package/dist/commands/webhooks/events/list.d.ts.map +1 -0
- package/dist/commands/webhooks/events/list.js +31 -0
- package/dist/commands/webhooks/events/list.js.map +1 -0
- package/dist/commands/webhooks/events/payload.d.ts +8 -0
- package/dist/commands/webhooks/events/payload.d.ts.map +1 -0
- package/dist/commands/webhooks/events/payload.js +39 -0
- package/dist/commands/webhooks/events/payload.js.map +1 -0
- package/dist/commands/webhooks/events/resend.d.ts +8 -0
- package/dist/commands/webhooks/events/resend.d.ts.map +1 -0
- package/dist/commands/webhooks/events/resend.js +43 -0
- package/dist/commands/webhooks/events/resend.js.map +1 -0
- package/dist/commands/webhooks/list.d.ts +8 -0
- package/dist/commands/webhooks/list.d.ts.map +1 -0
- package/dist/commands/webhooks/list.js +29 -0
- package/dist/commands/webhooks/list.js.map +1 -0
- package/dist/commands/webhooks/shared.d.ts +40 -0
- package/dist/commands/webhooks/shared.d.ts.map +1 -0
- package/dist/commands/webhooks/shared.js +248 -0
- package/dist/commands/webhooks/shared.js.map +1 -0
- package/dist/commands/webhooks/update.d.ts +10 -0
- package/dist/commands/webhooks/update.d.ts.map +1 -0
- package/dist/commands/webhooks/update.js +189 -0
- package/dist/commands/webhooks/update.js.map +1 -0
- package/dist/context/authToken.d.ts +29 -0
- package/dist/context/authToken.d.ts.map +1 -0
- package/dist/context/authToken.js +73 -0
- package/dist/context/authToken.js.map +1 -0
- package/dist/context/currentApp.d.ts +38 -0
- package/dist/context/currentApp.d.ts.map +1 -0
- package/dist/context/currentApp.js +222 -0
- package/dist/context/currentApp.js.map +1 -0
- package/dist/context/globalOpts.d.ts +11 -0
- package/dist/context/globalOpts.d.ts.map +1 -0
- package/dist/context/globalOpts.js +13 -0
- package/dist/context/globalOpts.js.map +1 -0
- package/dist/context/platformApi.d.ts +19 -0
- package/dist/context/platformApi.d.ts.map +1 -0
- package/dist/context/platformApi.js +24 -0
- package/dist/context/platformApi.js.map +1 -0
- package/dist/context/projectInfo.d.ts +32 -0
- package/dist/context/projectInfo.d.ts.map +1 -0
- package/dist/context/projectInfo.js +160 -0
- package/dist/context/projectInfo.js.map +1 -0
- package/dist/errors.d.ts +10 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +6 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +159 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +721 -0
- package/dist/index.js.map +1 -0
- package/dist/layer.d.ts +25 -0
- package/dist/layer.d.ts.map +1 -0
- package/dist/layer.js +119 -0
- package/dist/layer.js.map +1 -0
- package/dist/lib/args.d.ts +212 -0
- package/dist/lib/args.d.ts.map +1 -0
- package/dist/lib/args.js +313 -0
- package/dist/lib/args.js.map +1 -0
- package/dist/lib/backupDownload.d.ts +21 -0
- package/dist/lib/backupDownload.d.ts.map +1 -0
- package/dist/lib/backupDownload.js +151 -0
- package/dist/lib/backupDownload.js.map +1 -0
- package/dist/lib/backups.d.ts +12 -0
- package/dist/lib/backups.d.ts.map +1 -0
- package/dist/lib/backups.js +26 -0
- package/dist/lib/backups.js.map +1 -0
- package/dist/lib/config.d.ts +13 -0
- package/dist/lib/config.d.ts.map +1 -0
- package/dist/lib/config.js +62 -0
- package/dist/lib/config.js.map +1 -0
- package/dist/lib/createApp.d.ts +12 -0
- package/dist/lib/createApp.d.ts.map +1 -0
- package/dist/lib/createApp.js +15 -0
- package/dist/lib/createApp.js.map +1 -0
- package/dist/lib/email.d.ts +47 -0
- package/dist/lib/email.d.ts.map +1 -0
- package/dist/lib/email.js +71 -0
- package/dist/lib/email.js.map +1 -0
- package/dist/lib/handleEnv.d.ts +7 -0
- package/dist/lib/handleEnv.d.ts.map +1 -0
- package/dist/lib/handleEnv.js +103 -0
- package/dist/lib/handleEnv.js.map +1 -0
- package/dist/lib/http.d.ts +30 -0
- package/dist/lib/http.d.ts.map +1 -0
- package/dist/lib/http.js +55 -0
- package/dist/lib/http.js.map +1 -0
- package/dist/lib/login.d.ts +12 -0
- package/dist/lib/login.d.ts.map +1 -0
- package/dist/lib/login.js +38 -0
- package/dist/lib/login.js.map +1 -0
- package/dist/lib/oauth.d.ts +306 -0
- package/dist/lib/oauth.d.ts.map +1 -0
- package/dist/lib/oauth.js +195 -0
- package/dist/lib/oauth.js.map +1 -0
- package/dist/lib/platformApi.d.ts +5 -0
- package/dist/lib/platformApi.d.ts.map +1 -0
- package/dist/lib/platformApi.js +11 -0
- package/dist/lib/platformApi.js.map +1 -0
- package/dist/lib/pullPerms.d.ts +7 -0
- package/dist/lib/pullPerms.d.ts.map +1 -0
- package/dist/lib/pullPerms.js +41 -0
- package/dist/lib/pullPerms.js.map +1 -0
- package/dist/lib/pullSchema.d.ts +12 -0
- package/dist/lib/pullSchema.d.ts.map +1 -0
- package/dist/lib/pullSchema.js +62 -0
- package/dist/lib/pullSchema.js.map +1 -0
- package/dist/lib/pushPerms.d.ts +13 -0
- package/dist/lib/pushPerms.d.ts.map +1 -0
- package/dist/lib/pushPerms.js +54 -0
- package/dist/lib/pushPerms.js.map +1 -0
- package/dist/lib/pushSchema.d.ts +53 -0
- package/dist/lib/pushSchema.d.ts.map +1 -0
- package/dist/lib/pushSchema.js +165 -0
- package/dist/lib/pushSchema.js.map +1 -0
- package/dist/lib/ui.d.ts +18 -0
- package/dist/lib/ui.d.ts.map +1 -0
- package/dist/lib/ui.js +32 -0
- package/dist/lib/ui.js.map +1 -0
- package/dist/lib/webhooks.d.ts +27 -0
- package/dist/lib/webhooks.d.ts.map +1 -0
- package/dist/lib/webhooks.js +95 -0
- package/dist/lib/webhooks.js.map +1 -0
- package/dist/logging.d.ts +5 -0
- package/dist/logging.d.ts.map +1 -0
- package/dist/logging.js +25 -0
- package/dist/logging.js.map +1 -0
- package/dist/old.d.ts +18 -0
- package/dist/old.d.ts.map +1 -0
- package/dist/old.js +423 -0
- package/dist/old.js.map +1 -0
- package/dist/program.d.ts +3 -0
- package/dist/program.d.ts.map +1 -0
- package/dist/program.js +3 -0
- package/dist/program.js.map +1 -0
- package/dist/renderSchemaPlan.d.ts +19 -0
- package/dist/renderSchemaPlan.d.ts.map +1 -0
- package/dist/renderSchemaPlan.js +220 -0
- package/dist/renderSchemaPlan.js.map +1 -0
- package/dist/ui/index.d.ts +292 -0
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +1296 -0
- package/dist/ui/index.js.map +1 -0
- package/dist/ui/lib.d.ts +124 -0
- package/dist/ui/lib.d.ts.map +1 -0
- package/dist/ui/lib.js +333 -0
- package/dist/ui/lib.js.map +1 -0
- package/dist/util/envAliases.d.ts +25 -0
- package/dist/util/envAliases.d.ts.map +1 -0
- package/dist/util/envAliases.js +47 -0
- package/dist/util/envAliases.js.map +1 -0
- package/dist/util/findConfigCandidates.d.ts +33 -0
- package/dist/util/findConfigCandidates.d.ts.map +1 -0
- package/dist/util/findConfigCandidates.js +230 -0
- package/dist/util/findConfigCandidates.js.map +1 -0
- package/dist/util/fs.d.ts +4 -0
- package/dist/util/fs.d.ts.map +1 -0
- package/dist/util/fs.js +22 -0
- package/dist/util/fs.js.map +1 -0
- package/dist/util/getAppName.d.ts +5 -0
- package/dist/util/getAppName.d.ts.map +1 -0
- package/dist/util/getAppName.js +14 -0
- package/dist/util/getAppName.js.map +1 -0
- package/dist/util/instantConfig.d.ts +9 -0
- package/dist/util/instantConfig.d.ts.map +1 -0
- package/dist/util/instantConfig.js +13 -0
- package/dist/util/instantConfig.js.map +1 -0
- package/dist/util/isHeadlessEnvironment.d.ts +4 -0
- package/dist/util/isHeadlessEnvironment.d.ts.map +1 -0
- package/dist/util/isHeadlessEnvironment.js +11 -0
- package/dist/util/isHeadlessEnvironment.js.map +1 -0
- package/dist/util/loadConfig.d.ts +3 -0
- package/dist/util/loadConfig.d.ts.map +1 -0
- package/dist/util/loadConfig.js +80 -0
- package/dist/util/loadConfig.js.map +1 -0
- package/dist/util/loadEnv.d.ts +2 -0
- package/dist/util/loadEnv.d.ts.map +1 -0
- package/dist/util/loadEnv.js +16 -0
- package/dist/util/loadEnv.js.map +1 -0
- package/dist/util/mergeSchema.d.ts +10 -0
- package/dist/util/mergeSchema.d.ts.map +1 -0
- package/dist/util/mergeSchema.js +338 -0
- package/dist/util/mergeSchema.js.map +1 -0
- package/dist/util/projectDir.d.ts +7 -0
- package/dist/util/projectDir.d.ts.map +1 -0
- package/dist/util/projectDir.js +43 -0
- package/dist/util/projectDir.js.map +1 -0
- package/dist/util/renamePrompt.d.ts +15 -0
- package/dist/util/renamePrompt.d.ts.map +1 -0
- package/dist/util/renamePrompt.js +57 -0
- package/dist/util/renamePrompt.js.map +1 -0
- package/dist/version.d.ts +3 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +3 -0
- package/dist/version.js.map +1 -0
- package/package.json +88 -3
- package/src/auth/index.ts +125 -0
- package/src/commands/app/delete.ts +82 -0
- package/src/commands/app/list.ts +44 -0
- package/src/commands/auth/client/add.ts +744 -0
- package/src/commands/auth/client/delete.ts +60 -0
- package/src/commands/auth/client/list.ts +60 -0
- package/src/commands/auth/client/shared.ts +190 -0
- package/src/commands/auth/client/update.ts +830 -0
- package/src/commands/auth/email/pull.ts +143 -0
- package/src/commands/auth/email/push.ts +94 -0
- package/src/commands/auth/email/resend.ts +8 -0
- package/src/commands/auth/email/reset.ts +37 -0
- package/src/commands/auth/email/status.ts +154 -0
- package/src/commands/auth/email/verify.ts +22 -0
- package/src/commands/auth/origin/add.ts +237 -0
- package/src/commands/auth/origin/delete.ts +50 -0
- package/src/commands/auth/origin/list.ts +66 -0
- package/src/commands/backup/download.ts +231 -0
- package/src/commands/backup/list.ts +94 -0
- package/src/commands/claim.ts +31 -0
- package/src/commands/explorer.ts +21 -0
- package/src/commands/info.ts +57 -0
- package/src/commands/init.ts +60 -0
- package/src/commands/initWithoutFiles.ts +107 -0
- package/src/commands/login.ts +62 -0
- package/src/commands/logout.ts +22 -0
- package/src/commands/pull.ts +22 -0
- package/src/commands/push.ts +25 -0
- package/src/commands/query.ts +61 -0
- package/src/commands/webhooks/add.ts +111 -0
- package/src/commands/webhooks/delete.ts +23 -0
- package/src/commands/webhooks/disable.ts +24 -0
- package/src/commands/webhooks/enable.ts +24 -0
- package/src/commands/webhooks/events/list.ts +38 -0
- package/src/commands/webhooks/events/payload.ts +56 -0
- package/src/commands/webhooks/events/resend.ts +66 -0
- package/src/commands/webhooks/list.ts +41 -0
- package/src/commands/webhooks/shared.ts +339 -0
- package/src/commands/webhooks/update.ts +276 -0
- package/src/context/authToken.ts +134 -0
- package/src/context/currentApp.ts +301 -0
- package/src/context/globalOpts.ts +22 -0
- package/src/context/platformApi.ts +35 -0
- package/src/context/projectInfo.ts +227 -0
- package/src/errors.ts +7 -0
- package/src/index.ts +1222 -0
- package/src/layer.ts +211 -0
- package/src/lib/args.ts +453 -0
- package/src/lib/backupDownload.ts +188 -0
- package/src/lib/backups.ts +33 -0
- package/src/lib/config.ts +107 -0
- package/src/lib/createApp.ts +28 -0
- package/src/lib/email.ts +93 -0
- package/src/lib/handleEnv.ts +126 -0
- package/src/lib/http.ts +128 -0
- package/src/lib/login.ts +48 -0
- package/src/lib/oauth.ts +310 -0
- package/src/lib/platformApi.ts +11 -0
- package/src/lib/pullPerms.ts +50 -0
- package/src/lib/pullSchema.ts +95 -0
- package/src/lib/pushPerms.ts +80 -0
- package/src/lib/pushSchema.ts +248 -0
- package/src/lib/ui.ts +48 -0
- package/src/lib/webhooks.ts +118 -0
- package/src/logging.ts +41 -0
- package/src/old.js +502 -0
- package/src/program.ts +3 -0
- package/src/renderSchemaPlan.ts +324 -0
- package/src/ui/index.ts +1615 -0
- package/src/ui/lib.ts +424 -0
- package/src/util/envAliases.ts +53 -0
- package/src/util/findConfigCandidates.ts +288 -0
- package/src/util/fs.ts +26 -0
- package/src/util/getAppName.ts +14 -0
- package/src/util/instantConfig.ts +21 -0
- package/src/util/isHeadlessEnvironment.ts +15 -0
- package/src/util/loadConfig.ts +101 -0
- package/src/util/loadEnv.ts +19 -0
- package/src/util/mergeSchema.ts +374 -0
- package/src/util/projectDir.ts +54 -0
- package/src/util/renamePrompt.ts +79 -0
- package/src/version.js +3 -0
- package/tsconfig.build.json +20 -0
- package/tsconfig.json +23 -0
- package/vitest.config.ts +22 -0
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { test, expect, describe, vi, beforeEach } from 'vitest';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { Effect, Layer, Logger } from 'effect';
|
|
5
|
+
import { GlobalOpts } from '../src/context/globalOpts.ts';
|
|
6
|
+
import { AuthToken } from '../src/context/authToken.ts';
|
|
7
|
+
import { CurrentApp } from '../src/context/currentApp.ts';
|
|
8
|
+
|
|
9
|
+
vi.mock('../src/index.ts', () => ({}));
|
|
10
|
+
|
|
11
|
+
const state = vi.hoisted(() => ({
|
|
12
|
+
manager: undefined as any,
|
|
13
|
+
downloadResult: undefined as any,
|
|
14
|
+
downloadError: undefined as Error | undefined,
|
|
15
|
+
downloadCalls: [] as any[],
|
|
16
|
+
promptResponses: [] as unknown[],
|
|
17
|
+
}));
|
|
18
|
+
|
|
19
|
+
// Mock at the SDK boundary: any `new InstantPlatformApi(...)` returns a stub
|
|
20
|
+
// whose `.backups(appId)` is the per-test fake manager.
|
|
21
|
+
vi.mock('@sidekickdb/platform', async (importOriginal) => {
|
|
22
|
+
const orig: any = await importOriginal();
|
|
23
|
+
return {
|
|
24
|
+
...orig,
|
|
25
|
+
PlatformApi: class {
|
|
26
|
+
backups(_appId: string) {
|
|
27
|
+
return state.manager;
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// The download pipeline is network- and disk-heavy; the command tests only
|
|
34
|
+
// care that it's invoked with the right backup and destination.
|
|
35
|
+
vi.mock('../src/lib/backupDownload.ts', () => ({
|
|
36
|
+
downloadBackupToFile: vi.fn(async (opts: any) => {
|
|
37
|
+
state.downloadCalls.push(opts);
|
|
38
|
+
if (state.downloadError) throw state.downloadError;
|
|
39
|
+
return state.downloadResult;
|
|
40
|
+
}),
|
|
41
|
+
}));
|
|
42
|
+
|
|
43
|
+
vi.mock('../src/ui/lib.ts', async (importOriginal) => {
|
|
44
|
+
const orig: any = await importOriginal();
|
|
45
|
+
return {
|
|
46
|
+
...orig,
|
|
47
|
+
renderUnwrap: () => {
|
|
48
|
+
if (state.promptResponses.length === 0) {
|
|
49
|
+
return Promise.reject(new Error('No prompt response queued'));
|
|
50
|
+
}
|
|
51
|
+
return Promise.resolve(state.promptResponses.shift());
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const { backupListCmd } = await import('../src/commands/backup/list.ts');
|
|
57
|
+
const { backupDownloadCmd } = await import(
|
|
58
|
+
'../src/commands/backup/download.ts'
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
let logs: string[] = [];
|
|
62
|
+
|
|
63
|
+
const makeBackup = (overrides: any = {}) => ({
|
|
64
|
+
id: 'backup-1',
|
|
65
|
+
isn: '1',
|
|
66
|
+
backupAt: new Date('2026-08-01T00:00:00Z'),
|
|
67
|
+
filesSize: 1000,
|
|
68
|
+
dbSize: 2000,
|
|
69
|
+
uncompressedSize: 3000,
|
|
70
|
+
description: 'Automated Daily Snapshot',
|
|
71
|
+
expiresAt: new Date('2026-08-08T00:00:00Z'),
|
|
72
|
+
...overrides,
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
const buildManager = (backups: any[]) => ({
|
|
76
|
+
list: vi.fn(async () => backups),
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
const outPath = () => join(tmpdir(), `backup-test-${Date.now()}.zip`);
|
|
80
|
+
|
|
81
|
+
const run = (effect: any, opts: { yes: boolean }) =>
|
|
82
|
+
Effect.runPromise(
|
|
83
|
+
effect.pipe(
|
|
84
|
+
Effect.provide(
|
|
85
|
+
Layer.mergeAll(
|
|
86
|
+
Layer.succeed(GlobalOpts, { yes: opts.yes }),
|
|
87
|
+
Layer.succeed(AuthToken, {
|
|
88
|
+
getAuthToken: Effect.succeed('test-token'),
|
|
89
|
+
getSource: Effect.succeed('env' as const),
|
|
90
|
+
setAuthToken: () => Effect.succeed(undefined),
|
|
91
|
+
}),
|
|
92
|
+
Layer.succeed(CurrentApp, {
|
|
93
|
+
appId: 'test-app',
|
|
94
|
+
source: 'env' as const,
|
|
95
|
+
}),
|
|
96
|
+
Logger.replace(
|
|
97
|
+
Logger.defaultLogger,
|
|
98
|
+
Logger.make(({ message }) => {
|
|
99
|
+
logs.push(String(message));
|
|
100
|
+
}),
|
|
101
|
+
),
|
|
102
|
+
),
|
|
103
|
+
),
|
|
104
|
+
),
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
beforeEach(() => {
|
|
108
|
+
vi.stubEnv('INSTANT_CLI_API_URI', 'https://api.sidekick.test');
|
|
109
|
+
logs = [];
|
|
110
|
+
state.manager = buildManager([]);
|
|
111
|
+
state.downloadResult = { entities: 3, files: 2, zipBytes: 1234 };
|
|
112
|
+
state.downloadError = undefined;
|
|
113
|
+
state.downloadCalls = [];
|
|
114
|
+
state.promptResponses = [];
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
describe('backup list', () => {
|
|
118
|
+
test('renders backups as a table', async () => {
|
|
119
|
+
state.manager = buildManager([makeBackup()]);
|
|
120
|
+
await run(backupListCmd({}), { yes: true });
|
|
121
|
+
const output = logs.join('\n');
|
|
122
|
+
expect(output).toContain('CREATED AT');
|
|
123
|
+
expect(output).toContain('EXPIRES AT');
|
|
124
|
+
expect(output).toContain('backup-1');
|
|
125
|
+
expect(output).toContain('Automated Daily Snapshot');
|
|
126
|
+
expect(output).toMatch(/\d+ (minutes?|hours?|days?) ago/);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test('outputs JSON with --json', async () => {
|
|
130
|
+
state.manager = buildManager([makeBackup()]);
|
|
131
|
+
await run(backupListCmd({ json: true }), { yes: true });
|
|
132
|
+
const parsed = JSON.parse(logs.join('\n'));
|
|
133
|
+
expect(parsed).toHaveLength(1);
|
|
134
|
+
expect(parsed[0].id).toBe('backup-1');
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
test('handles no backups', async () => {
|
|
138
|
+
await run(backupListCmd({}), { yes: true });
|
|
139
|
+
expect(logs.join('\n')).toContain('No backups yet.');
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
describe('backup download', () => {
|
|
144
|
+
test('downloads by id', async () => {
|
|
145
|
+
const backup = makeBackup();
|
|
146
|
+
state.manager = buildManager([backup]);
|
|
147
|
+
const out = outPath();
|
|
148
|
+
await run(backupDownloadCmd('backup-1', { out }), { yes: true });
|
|
149
|
+
expect(state.downloadCalls).toHaveLength(1);
|
|
150
|
+
expect(state.downloadCalls[0].backup).toEqual(backup);
|
|
151
|
+
expect(state.downloadCalls[0].outPath).toBe(out);
|
|
152
|
+
expect(logs.join('\n')).toContain('Saved 3 namespaces and 2 storage files');
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
test('rejects a backup id combined with --latest', async () => {
|
|
156
|
+
state.manager = buildManager([makeBackup()]);
|
|
157
|
+
await expect(
|
|
158
|
+
run(backupDownloadCmd('backup-1', { latest: true, out: outPath() }), {
|
|
159
|
+
yes: true,
|
|
160
|
+
}),
|
|
161
|
+
).rejects.toThrow(/not both/);
|
|
162
|
+
expect(state.downloadCalls).toHaveLength(0);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
test('rejects an output path that is a directory', async () => {
|
|
166
|
+
state.manager = buildManager([makeBackup()]);
|
|
167
|
+
await expect(
|
|
168
|
+
run(backupDownloadCmd('backup-1', { out: tmpdir() }), { yes: true }),
|
|
169
|
+
).rejects.toThrow(/is a directory/);
|
|
170
|
+
expect(state.downloadCalls).toHaveLength(0);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
test('errors on an unknown id', async () => {
|
|
174
|
+
state.manager = buildManager([makeBackup()]);
|
|
175
|
+
await expect(
|
|
176
|
+
run(backupDownloadCmd('nope', { out: outPath() }), { yes: true }),
|
|
177
|
+
).rejects.toThrow(/No backup found with id nope/);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
test('--latest picks the newest backup', async () => {
|
|
181
|
+
const older = makeBackup();
|
|
182
|
+
const newer = makeBackup({
|
|
183
|
+
id: 'backup-2',
|
|
184
|
+
backupAt: new Date('2026-08-02T00:00:00Z'),
|
|
185
|
+
});
|
|
186
|
+
state.manager = buildManager([older, newer]);
|
|
187
|
+
await run(backupDownloadCmd(undefined, { latest: true, out: outPath() }), {
|
|
188
|
+
yes: true,
|
|
189
|
+
});
|
|
190
|
+
expect(state.downloadCalls[0].backup.id).toBe('backup-2');
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
test('requires an id or --latest when prompts are skipped', async () => {
|
|
194
|
+
state.manager = buildManager([makeBackup()]);
|
|
195
|
+
await expect(
|
|
196
|
+
run(backupDownloadCmd(undefined, {}), { yes: true }),
|
|
197
|
+
).rejects.toThrow(/Must specify a backup id or --latest/);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
test('prompts for a backup and confirmation interactively', async () => {
|
|
201
|
+
const backup = makeBackup();
|
|
202
|
+
state.manager = buildManager([backup]);
|
|
203
|
+
// First the backup picker, then the download confirmation.
|
|
204
|
+
state.promptResponses = [backup, true];
|
|
205
|
+
await run(backupDownloadCmd(undefined, { out: outPath() }), {
|
|
206
|
+
yes: false,
|
|
207
|
+
});
|
|
208
|
+
expect(state.downloadCalls).toHaveLength(1);
|
|
209
|
+
expect(state.downloadCalls[0].backup).toEqual(backup);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
test('reports a cancelled download', async () => {
|
|
213
|
+
state.manager = buildManager([makeBackup()]);
|
|
214
|
+
state.downloadError = Object.assign(new Error('aborted'), {
|
|
215
|
+
name: 'AbortError',
|
|
216
|
+
});
|
|
217
|
+
await run(backupDownloadCmd('backup-1', { out: outPath() }), {
|
|
218
|
+
yes: true,
|
|
219
|
+
});
|
|
220
|
+
expect(logs.join('\n')).toContain('Download cancelled.');
|
|
221
|
+
});
|
|
222
|
+
});
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { Effect } from 'effect';
|
|
2
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
3
|
+
|
|
4
|
+
const mocks = vi.hoisted(() => ({
|
|
5
|
+
readInstantConfigFile: vi.fn(),
|
|
6
|
+
}));
|
|
7
|
+
|
|
8
|
+
vi.mock('../src/util/instantConfig.ts', () => ({
|
|
9
|
+
readInstantConfigFile: mocks.readInstantConfigFile,
|
|
10
|
+
}));
|
|
11
|
+
|
|
12
|
+
import {
|
|
13
|
+
getBaseUrl,
|
|
14
|
+
getDashUrl,
|
|
15
|
+
getOAuthCallbackUrl,
|
|
16
|
+
getOptionalDashUrl,
|
|
17
|
+
missingApiUrlMessage,
|
|
18
|
+
missingDashUrlMessage,
|
|
19
|
+
} from '../src/lib/config.ts';
|
|
20
|
+
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
vi.stubEnv('INSTANT_CLI_API_URI', undefined);
|
|
23
|
+
vi.stubEnv('INSTANT_CLI_DASH_URI', undefined);
|
|
24
|
+
vi.stubEnv('INSTANT_CLI_DEV', undefined);
|
|
25
|
+
mocks.readInstantConfigFile.mockResolvedValue({});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
afterEach(() => {
|
|
29
|
+
vi.unstubAllEnvs();
|
|
30
|
+
vi.clearAllMocks();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
describe('dashboard URL configuration', () => {
|
|
34
|
+
it('reads dashURI from instant.config.ts', async () => {
|
|
35
|
+
mocks.readInstantConfigFile.mockResolvedValue({
|
|
36
|
+
dashURI: 'https://dash.instant.example',
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
await expect(Effect.runPromise(getDashUrl)).resolves.toBe(
|
|
40
|
+
'https://dash.instant.example',
|
|
41
|
+
);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('prefers INSTANT_CLI_DASH_URI over instant.config.ts', async () => {
|
|
45
|
+
vi.stubEnv('INSTANT_CLI_DASH_URI', 'https://dash.env.example');
|
|
46
|
+
mocks.readInstantConfigFile.mockResolvedValue({
|
|
47
|
+
dashURI: 'https://dash.config.example',
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
await expect(Effect.runPromise(getDashUrl)).resolves.toBe(
|
|
51
|
+
'https://dash.env.example',
|
|
52
|
+
);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
describe('OAuth callback URL configuration', () => {
|
|
57
|
+
it('uses the configured API URL', async () => {
|
|
58
|
+
vi.stubEnv('INSTANT_CLI_API_URI', 'https://api.instant.example/');
|
|
59
|
+
|
|
60
|
+
await expect(Effect.runPromise(getOAuthCallbackUrl)).resolves.toBe(
|
|
61
|
+
'https://api.instant.example/runtime/oauth/callback',
|
|
62
|
+
);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
describe('API URL configuration', () => {
|
|
67
|
+
it('fails with a clear error when no API URL is configured', async () => {
|
|
68
|
+
await expect(Effect.runPromise(getBaseUrl)).rejects.toThrow(
|
|
69
|
+
missingApiUrlMessage,
|
|
70
|
+
);
|
|
71
|
+
expect(missingApiUrlMessage).toContain('INSTANT_CLI_API_URI');
|
|
72
|
+
expect(missingApiUrlMessage).toContain('instant.config.ts');
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('treats a blank INSTANT_CLI_API_URI as unset', async () => {
|
|
76
|
+
vi.stubEnv('INSTANT_CLI_API_URI', ' ');
|
|
77
|
+
|
|
78
|
+
await expect(Effect.runPromise(getBaseUrl)).rejects.toThrow(
|
|
79
|
+
missingApiUrlMessage,
|
|
80
|
+
);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('falls back to instant.config.ts when INSTANT_CLI_API_URI is blank', async () => {
|
|
84
|
+
vi.stubEnv('INSTANT_CLI_API_URI', ' ');
|
|
85
|
+
mocks.readInstantConfigFile.mockResolvedValue({
|
|
86
|
+
apiURI: 'https://api.config.example',
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
await expect(Effect.runPromise(getBaseUrl)).resolves.toBe(
|
|
90
|
+
'https://api.config.example',
|
|
91
|
+
);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('uses INSTANT_CLI_API_URI unchanged', async () => {
|
|
95
|
+
vi.stubEnv('INSTANT_CLI_API_URI', 'https://api.env.example/');
|
|
96
|
+
|
|
97
|
+
await expect(Effect.runPromise(getBaseUrl)).resolves.toBe(
|
|
98
|
+
'https://api.env.example/',
|
|
99
|
+
);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('reads apiURI from instant.config.ts', async () => {
|
|
103
|
+
mocks.readInstantConfigFile.mockResolvedValue({
|
|
104
|
+
apiURI: 'https://api.config.example',
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
await expect(Effect.runPromise(getBaseUrl)).resolves.toBe(
|
|
108
|
+
'https://api.config.example',
|
|
109
|
+
);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('uses the local server in CLI dev mode', async () => {
|
|
113
|
+
vi.stubEnv('INSTANT_CLI_DEV', 'true');
|
|
114
|
+
|
|
115
|
+
await expect(Effect.runPromise(getBaseUrl)).resolves.toBe(
|
|
116
|
+
'http://localhost:8888',
|
|
117
|
+
);
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
describe('dashboard URL without configuration', () => {
|
|
122
|
+
it('fails with a clear error when no dashboard URL is configured', async () => {
|
|
123
|
+
await expect(Effect.runPromise(getDashUrl)).rejects.toThrow(
|
|
124
|
+
missingDashUrlMessage,
|
|
125
|
+
);
|
|
126
|
+
expect(missingDashUrlMessage).toContain('INSTANT_CLI_DASH_URI');
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('treats a blank INSTANT_CLI_DASH_URI as unset', async () => {
|
|
130
|
+
vi.stubEnv('INSTANT_CLI_DASH_URI', ' ');
|
|
131
|
+
|
|
132
|
+
await expect(Effect.runPromise(getDashUrl)).rejects.toThrow(
|
|
133
|
+
missingDashUrlMessage,
|
|
134
|
+
);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('returns none from getOptionalDashUrl', async () => {
|
|
138
|
+
const dashUrl = await Effect.runPromise(getOptionalDashUrl);
|
|
139
|
+
expect(dashUrl._tag).toBe('None');
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('uses the local dashboard in CLI dev mode', async () => {
|
|
143
|
+
vi.stubEnv('INSTANT_CLI_DEV', 'true');
|
|
144
|
+
|
|
145
|
+
await expect(Effect.runPromise(getDashUrl)).resolves.toBe(
|
|
146
|
+
'http://localhost:3000',
|
|
147
|
+
);
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
describe('indexing job dashboard links', () => {
|
|
152
|
+
it('reads dashURI from instant.config.ts', async () => {
|
|
153
|
+
const { readDashOrigin } = await import('../src/old.js');
|
|
154
|
+
mocks.readInstantConfigFile.mockResolvedValue({
|
|
155
|
+
dashURI: 'https://dash.config.example',
|
|
156
|
+
});
|
|
157
|
+
await expect(readDashOrigin()).resolves.toBe('https://dash.config.example');
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('returns null when no dashboard is configured', async () => {
|
|
161
|
+
const { readDashOrigin } = await import('../src/old.js');
|
|
162
|
+
await expect(readDashOrigin()).resolves.toBeNull();
|
|
163
|
+
});
|
|
164
|
+
});
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
|
|
5
|
+
import {
|
|
6
|
+
applyEnvAliases,
|
|
7
|
+
envNameForDisplay,
|
|
8
|
+
legacyEnvName,
|
|
9
|
+
} from '../src/util/envAliases.ts';
|
|
10
|
+
import {
|
|
11
|
+
getEmailReadCandidates,
|
|
12
|
+
getPermsReadCandidates,
|
|
13
|
+
getSchemaReadCandidates,
|
|
14
|
+
withSidekickFileNames,
|
|
15
|
+
} from '../src/util/findConfigCandidates.ts';
|
|
16
|
+
import { readInstantConfigFile } from '../src/util/instantConfig.ts';
|
|
17
|
+
|
|
18
|
+
describe('legacyEnvName', () => {
|
|
19
|
+
test('maps SIDEKICK_ names onto INSTANT_ names', () => {
|
|
20
|
+
expect(legacyEnvName('SIDEKICK_APP_ID')).toBe('INSTANT_APP_ID');
|
|
21
|
+
expect(legacyEnvName('SIDEKICK_CLI_API_URI')).toBe('INSTANT_CLI_API_URI');
|
|
22
|
+
expect(legacyEnvName('SIDEKICK_SCHEMA_FILE_PATH')).toBe(
|
|
23
|
+
'INSTANT_SCHEMA_FILE_PATH',
|
|
24
|
+
);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test('keeps a framework prefix', () => {
|
|
28
|
+
expect(legacyEnvName('NEXT_PUBLIC_SIDEKICK_APP_ID')).toBe(
|
|
29
|
+
'NEXT_PUBLIC_INSTANT_APP_ID',
|
|
30
|
+
);
|
|
31
|
+
expect(legacyEnvName('VITE_SIDEKICK_APP_ID')).toBe('VITE_INSTANT_APP_ID');
|
|
32
|
+
expect(legacyEnvName('PUBLIC_SIDEKICK_APP_ID')).toBe(
|
|
33
|
+
'PUBLIC_INSTANT_APP_ID',
|
|
34
|
+
);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('ignores every other name', () => {
|
|
38
|
+
expect(legacyEnvName('INSTANT_APP_ID')).toBeNull();
|
|
39
|
+
expect(legacyEnvName('PATH')).toBeNull();
|
|
40
|
+
expect(legacyEnvName('SIDEKICK')).toBeNull();
|
|
41
|
+
expect(legacyEnvName('SIDEKICK_')).toBeNull();
|
|
42
|
+
expect(legacyEnvName('MYSIDEKICK_APP_ID')).toBeNull();
|
|
43
|
+
expect(legacyEnvName('sidekick_app_id')).toBeNull();
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe('applyEnvAliases', () => {
|
|
48
|
+
test('a SIDEKICK_ variable sets its INSTANT_ name', () => {
|
|
49
|
+
const env: Record<string, string | undefined> = {
|
|
50
|
+
SIDEKICK_CLI_API_URI: 'https://new.example',
|
|
51
|
+
NEXT_PUBLIC_SIDEKICK_APP_ID: 'new-app',
|
|
52
|
+
PATH: '/bin',
|
|
53
|
+
};
|
|
54
|
+
expect(applyEnvAliases(env)).toEqual({
|
|
55
|
+
INSTANT_CLI_API_URI: 'SIDEKICK_CLI_API_URI',
|
|
56
|
+
NEXT_PUBLIC_INSTANT_APP_ID: 'NEXT_PUBLIC_SIDEKICK_APP_ID',
|
|
57
|
+
});
|
|
58
|
+
expect(env.INSTANT_CLI_API_URI).toBe('https://new.example');
|
|
59
|
+
expect(env.NEXT_PUBLIC_INSTANT_APP_ID).toBe('new-app');
|
|
60
|
+
expect(env.PATH).toBe('/bin');
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test('the SIDEKICK_ name wins when both are set', () => {
|
|
64
|
+
const env: Record<string, string | undefined> = {
|
|
65
|
+
INSTANT_APP_ID: 'old-app',
|
|
66
|
+
SIDEKICK_APP_ID: 'new-app',
|
|
67
|
+
};
|
|
68
|
+
applyEnvAliases(env);
|
|
69
|
+
expect(env.INSTANT_APP_ID).toBe('new-app');
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test('a blank SIDEKICK_ value counts as unset', () => {
|
|
73
|
+
const env: Record<string, string | undefined> = {
|
|
74
|
+
INSTANT_APP_ID: 'old-app',
|
|
75
|
+
SIDEKICK_APP_ID: ' ',
|
|
76
|
+
SIDEKICK_ADMIN_TOKEN: '',
|
|
77
|
+
};
|
|
78
|
+
expect(applyEnvAliases(env)).toEqual({});
|
|
79
|
+
expect(env.INSTANT_APP_ID).toBe('old-app');
|
|
80
|
+
expect('INSTANT_ADMIN_TOKEN' in env).toBe(false);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test('the INSTANT_ names keep working on their own', () => {
|
|
84
|
+
const env: Record<string, string | undefined> = {
|
|
85
|
+
INSTANT_APP_ID: 'old-app',
|
|
86
|
+
};
|
|
87
|
+
expect(applyEnvAliases(env)).toEqual({});
|
|
88
|
+
expect(env).toEqual({ INSTANT_APP_ID: 'old-app' });
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
describe('on process.env', () => {
|
|
92
|
+
afterEach(() => {
|
|
93
|
+
vi.unstubAllEnvs();
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test('messages show the name the value was set under', () => {
|
|
97
|
+
vi.stubEnv('SIDEKICK_PERMS_FILE_PATH', 'perms/custom.ts');
|
|
98
|
+
vi.stubEnv('INSTANT_PERMS_FILE_PATH', undefined);
|
|
99
|
+
vi.stubEnv('INSTANT_EMAIL_FILE_PATH', 'email/custom.ts');
|
|
100
|
+
applyEnvAliases();
|
|
101
|
+
|
|
102
|
+
expect(process.env.INSTANT_PERMS_FILE_PATH).toBe('perms/custom.ts');
|
|
103
|
+
expect(envNameForDisplay('INSTANT_PERMS_FILE_PATH')).toBe(
|
|
104
|
+
'SIDEKICK_PERMS_FILE_PATH',
|
|
105
|
+
);
|
|
106
|
+
expect(envNameForDisplay('INSTANT_EMAIL_FILE_PATH')).toBe(
|
|
107
|
+
'INSTANT_EMAIL_FILE_PATH',
|
|
108
|
+
);
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
describe('sidekick.* config file names', () => {
|
|
114
|
+
const transform = (code: string) => code;
|
|
115
|
+
|
|
116
|
+
test('each instant.* candidate gets a sidekick.* one, listed first', () => {
|
|
117
|
+
const candidates = [
|
|
118
|
+
{ files: 'instant.schema', extensions: ['ts'], transform },
|
|
119
|
+
{ files: 'src/lib/instant.schema', extensions: ['ts'], transform },
|
|
120
|
+
{ files: 'app/instant.schema', extensions: ['ts'], transform },
|
|
121
|
+
];
|
|
122
|
+
expect(withSidekickFileNames(candidates).map((c) => c.files)).toEqual([
|
|
123
|
+
'sidekick.schema',
|
|
124
|
+
'src/lib/sidekick.schema',
|
|
125
|
+
'app/sidekick.schema',
|
|
126
|
+
'instant.schema',
|
|
127
|
+
'src/lib/instant.schema',
|
|
128
|
+
'app/instant.schema',
|
|
129
|
+
]);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test('only the file name changes', () => {
|
|
133
|
+
const candidates = [
|
|
134
|
+
{ files: 'src/instant.app/instant.perms', transform },
|
|
135
|
+
{ files: 'my-instant.email', transform },
|
|
136
|
+
];
|
|
137
|
+
expect(withSidekickFileNames(candidates).map((c) => c.files)).toEqual([
|
|
138
|
+
'src/instant.app/sidekick.perms',
|
|
139
|
+
'src/instant.app/instant.perms',
|
|
140
|
+
'my-instant.email',
|
|
141
|
+
]);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
describe('read candidates', () => {
|
|
145
|
+
beforeEach(() => {
|
|
146
|
+
vi.stubEnv('INSTANT_SCHEMA_FILE_PATH', undefined);
|
|
147
|
+
vi.stubEnv('INSTANT_PERMS_FILE_PATH', undefined);
|
|
148
|
+
vi.stubEnv('INSTANT_EMAIL_FILE_PATH', undefined);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
afterEach(() => {
|
|
152
|
+
vi.unstubAllEnvs();
|
|
153
|
+
vi.restoreAllMocks();
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
test.each([
|
|
157
|
+
['schema', getSchemaReadCandidates],
|
|
158
|
+
['perms', getPermsReadCandidates],
|
|
159
|
+
['email', () => getEmailReadCandidates()],
|
|
160
|
+
] as const)('%s: sidekick.* comes before instant.*', (kind, candidates) => {
|
|
161
|
+
const files = candidates().map((c) => c.files);
|
|
162
|
+
const firstLegacy = files.findIndex((f) => f.includes('instant.'));
|
|
163
|
+
|
|
164
|
+
expect(files[0]).toBe(`sidekick.${kind}`);
|
|
165
|
+
expect(files).toContain(`app/sidekick.${kind}`);
|
|
166
|
+
expect(files).toContain(`instant.${kind}`);
|
|
167
|
+
expect(files).toContain(`app/instant.${kind}`);
|
|
168
|
+
expect(firstLegacy).toBeGreaterThan(0);
|
|
169
|
+
expect(
|
|
170
|
+
files.slice(firstLegacy).some((f) => f.includes('sidekick.')),
|
|
171
|
+
).toBe(false);
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
test('an explicit path is used as it is', () => {
|
|
175
|
+
vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
176
|
+
vi.stubEnv('INSTANT_SCHEMA_FILE_PATH', 'db/instant.schema.ts');
|
|
177
|
+
expect(getSchemaReadCandidates().map((c) => c.files)).toEqual([
|
|
178
|
+
'db/instant.schema.ts',
|
|
179
|
+
]);
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
describe('sidekick.config', () => {
|
|
185
|
+
let dir: string;
|
|
186
|
+
let cwd: { mockRestore: () => void };
|
|
187
|
+
|
|
188
|
+
beforeEach(() => {
|
|
189
|
+
dir = mkdtempSync(join(tmpdir(), 'sidekick-cli-config-'));
|
|
190
|
+
writeFileSync(join(dir, 'package.json'), '{"name":"config-test"}');
|
|
191
|
+
cwd = vi.spyOn(process, 'cwd').mockReturnValue(dir);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
afterEach(() => {
|
|
195
|
+
cwd.mockRestore();
|
|
196
|
+
rmSync(dir, { recursive: true, force: true });
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
test('instant.config.json still works', async () => {
|
|
200
|
+
writeFileSync(
|
|
201
|
+
join(dir, 'instant.config.json'),
|
|
202
|
+
JSON.stringify({ apiURI: 'https://old.example' }),
|
|
203
|
+
);
|
|
204
|
+
expect(await readInstantConfigFile()).toEqual({
|
|
205
|
+
apiURI: 'https://old.example',
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
test('sidekick.config.json is read', async () => {
|
|
210
|
+
writeFileSync(
|
|
211
|
+
join(dir, 'sidekick.config.json'),
|
|
212
|
+
JSON.stringify({ apiURI: 'https://new.example' }),
|
|
213
|
+
);
|
|
214
|
+
expect(await readInstantConfigFile()).toEqual({
|
|
215
|
+
apiURI: 'https://new.example',
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
test('sidekick.config wins over instant.config', async () => {
|
|
220
|
+
writeFileSync(
|
|
221
|
+
join(dir, 'instant.config.json'),
|
|
222
|
+
JSON.stringify({ apiURI: 'https://old.example' }),
|
|
223
|
+
);
|
|
224
|
+
writeFileSync(
|
|
225
|
+
join(dir, 'sidekick.config.json'),
|
|
226
|
+
JSON.stringify({ apiURI: 'https://new.example' }),
|
|
227
|
+
);
|
|
228
|
+
expect(await readInstantConfigFile()).toEqual({
|
|
229
|
+
apiURI: 'https://new.example',
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
});
|