@beezer-pet/instant-cli 0.0.0-stage → 1.0.67-beezer.4
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/README.md +34 -2
- package/__tests__/appCommands.test.ts +228 -0
- package/__tests__/args.test.ts +358 -0
- package/__tests__/auth.test.ts +128 -0
- package/__tests__/authClientAddApple.test.ts +376 -0
- package/__tests__/authClientAddClerk.test.ts +222 -0
- package/__tests__/authClientAddGithub.test.ts +245 -0
- package/__tests__/authClientAddGoogle.test.ts +373 -0
- package/__tests__/authClientAddLinkedin.test.ts +262 -0
- package/__tests__/authClientList.test.ts +90 -0
- package/__tests__/authClientUpdate.test.ts +583 -0
- package/__tests__/authOriginManagement.test.ts +308 -0
- package/__tests__/backupDownload.test.ts +206 -0
- package/__tests__/backups.test.ts +221 -0
- package/__tests__/config.test.ts +57 -0
- package/__tests__/e2e/cli.e2e.test.ts +1267 -0
- package/__tests__/e2e/helpers.ts +177 -0
- package/__tests__/effectHelpers.ts +45 -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__/sdkInstallSpec.test.ts +36 -0
- package/__tests__/select.test.ts +224 -0
- package/__tests__/webhooks.test.ts +728 -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 +30 -0
- package/dist/context/projectInfo.d.ts.map +1 -0
- package/dist/context/projectInfo.js +153 -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 +714 -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 +6 -0
- package/dist/lib/config.d.ts.map +1 -0
- package/dist/lib/config.js +39 -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 +99 -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 +17 -0
- package/dist/old.d.ts.map +1 -0
- package/dist/old.js +410 -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/findConfigCandidates.d.ts +13 -0
- package/dist/util/findConfigCandidates.d.ts.map +1 -0
- package/dist/util/findConfigCandidates.js +211 -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 +72 -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 +10 -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/util/sdkInstallSpec.d.ts +13 -0
- package/dist/util/sdkInstallSpec.d.ts.map +1 -0
- package/dist/util/sdkInstallSpec.js +37 -0
- package/dist/util/sdkInstallSpec.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 +91 -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 +20 -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 +219 -0
- package/src/errors.ts +7 -0
- package/src/index.ts +1212 -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 +73 -0
- package/src/lib/createApp.ts +28 -0
- package/src/lib/email.ts +93 -0
- package/src/lib/handleEnv.ts +122 -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 +487 -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/findConfigCandidates.ts +262 -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 +93 -0
- package/src/util/loadEnv.ts +11 -0
- package/src/util/mergeSchema.ts +374 -0
- package/src/util/projectDir.ts +54 -0
- package/src/util/renamePrompt.ts +79 -0
- package/src/util/sdkInstallSpec.ts +45 -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,143 @@
|
|
|
1
|
+
import { HttpClientResponse, Path } from '@effect/platform';
|
|
2
|
+
import { Effect, Schema } from 'effect';
|
|
3
|
+
import { ProjectInfo } from '../../../context/projectInfo.ts';
|
|
4
|
+
import { BadArgsError } from '../../../errors.ts';
|
|
5
|
+
import { readLocalEmailFile } from '../../../old.js';
|
|
6
|
+
import { UI } from '../../../ui/index.ts';
|
|
7
|
+
import { getEmailPathToWrite } from '../../../util/findConfigCandidates.ts';
|
|
8
|
+
import { writeTypescript } from '../../../lib/pullSchema.ts';
|
|
9
|
+
import { promptOk } from '../../../lib/ui.ts';
|
|
10
|
+
import { getEmailTemplateStatus, type EmailTemplateInfo } from './status.ts';
|
|
11
|
+
import type { authEmailPullDef, OptsFromCommand } from '../../../index.ts';
|
|
12
|
+
import { InstantHttp } from '../../../lib/http.ts';
|
|
13
|
+
import { getAppName } from '../../../util/getAppName.ts';
|
|
14
|
+
import type { EmailConfig } from '../../../lib/email.ts';
|
|
15
|
+
|
|
16
|
+
export const authEmailPullCmd = Effect.fn(function* (
|
|
17
|
+
opts: OptsFromCommand<typeof authEmailPullDef>,
|
|
18
|
+
) {
|
|
19
|
+
yield* pullEmail(opts.file);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
export type EmailConfig = (typeof EmailConfig.Type)['authEmail'];
|
|
23
|
+
|
|
24
|
+
type WriteEmailTemplateOpts = {
|
|
25
|
+
emailPath?: string;
|
|
26
|
+
confirmOverwrite?: boolean;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const pullEmail = (emailPath?: string) =>
|
|
30
|
+
Effect.gen(function* () {
|
|
31
|
+
yield* Effect.log('Pulling email template...');
|
|
32
|
+
|
|
33
|
+
const info = yield* getEmailTemplateStatus;
|
|
34
|
+
|
|
35
|
+
const emailConfig = info
|
|
36
|
+
? infoToEmailConfig(info)
|
|
37
|
+
: yield* getDefaultEmailTemplate;
|
|
38
|
+
|
|
39
|
+
yield* writeEmailTemplate(emailConfig, { emailPath });
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
export const writeEmailTemplate = (
|
|
43
|
+
emailConfig: EmailConfig,
|
|
44
|
+
{ emailPath, confirmOverwrite = true }: WriteEmailTemplateOpts = {},
|
|
45
|
+
) =>
|
|
46
|
+
Effect.gen(function* () {
|
|
47
|
+
const prevEmailFile = yield* Effect.tryPromise({
|
|
48
|
+
try: () => readLocalEmailFile(emailPath),
|
|
49
|
+
catch: (e) =>
|
|
50
|
+
BadArgsError.make({
|
|
51
|
+
message: `Error reading local email file: ${e}`,
|
|
52
|
+
}),
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const shortEmailPath =
|
|
56
|
+
prevEmailFile?.path ?? emailPath ?? getEmailPathToWrite();
|
|
57
|
+
|
|
58
|
+
if (prevEmailFile && confirmOverwrite) {
|
|
59
|
+
const shouldContinue = yield* promptOk({
|
|
60
|
+
promptText: `This will overwrite your local ${shortEmailPath} file, OK to proceed?`,
|
|
61
|
+
modifyOutput: UI.modifiers.yPadding,
|
|
62
|
+
inline: true,
|
|
63
|
+
});
|
|
64
|
+
if (!shouldContinue) {
|
|
65
|
+
yield* Effect.log('Cancelled email pull');
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const path = yield* Path.Path;
|
|
71
|
+
const { pkgDir } = yield* ProjectInfo;
|
|
72
|
+
const fullEmailPath = shortEmailPath.startsWith('/')
|
|
73
|
+
? shortEmailPath
|
|
74
|
+
: path.join(pkgDir, shortEmailPath);
|
|
75
|
+
|
|
76
|
+
const typescriptFile = yield* generateEmailTypescriptFile(emailConfig);
|
|
77
|
+
|
|
78
|
+
yield* writeTypescript(fullEmailPath, typescriptFile);
|
|
79
|
+
yield* Effect.log('Wrote email template to ' + shortEmailPath);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
const DefaultEmailTemplateSchema = Schema.Struct({
|
|
83
|
+
subject: Schema.String,
|
|
84
|
+
body: Schema.String,
|
|
85
|
+
'sender-email': Schema.String.pipe(Schema.optional),
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
export const getDefaultEmailTemplate = Effect.gen(function* () {
|
|
89
|
+
const http = yield* InstantHttp;
|
|
90
|
+
const template = yield* http
|
|
91
|
+
.get('/dash/default-email-template')
|
|
92
|
+
.pipe(
|
|
93
|
+
Effect.flatMap(
|
|
94
|
+
HttpClientResponse.schemaBodyJson(DefaultEmailTemplateSchema),
|
|
95
|
+
),
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
const appName = yield* getAppName;
|
|
99
|
+
|
|
100
|
+
return {
|
|
101
|
+
subject: template.subject,
|
|
102
|
+
senderName: appName,
|
|
103
|
+
senderEmail: template['sender-email'],
|
|
104
|
+
body: template.body,
|
|
105
|
+
};
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
const infoToEmailConfig = (info: EmailTemplateInfo) => ({
|
|
109
|
+
subject: info.subject,
|
|
110
|
+
senderName: info.name,
|
|
111
|
+
senderEmail: info.email,
|
|
112
|
+
body: info.body,
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
const generateEmailTypescriptFile = Effect.fn(function* (
|
|
116
|
+
emailConfig: EmailConfig,
|
|
117
|
+
) {
|
|
118
|
+
const senderEmail = emailConfig.senderEmail
|
|
119
|
+
? JSON.stringify(emailConfig.senderEmail)
|
|
120
|
+
: 'undefined';
|
|
121
|
+
|
|
122
|
+
return `
|
|
123
|
+
// We provide a few dynamic variables for you to use in your email:
|
|
124
|
+
// {code}, the magic code e.g. 123456
|
|
125
|
+
// {app_title}, your app's title, i.e. test-fresh
|
|
126
|
+
// {user_email}, the user's email address, e.g. happyuser@gmail.com
|
|
127
|
+
// {expiration}, the magic code expiration, e.g. 10 minutes
|
|
128
|
+
// Note: {code} is required in both the subject and body.
|
|
129
|
+
const email = {
|
|
130
|
+
authEmail: {
|
|
131
|
+
subject: ${JSON.stringify(emailConfig.subject)},
|
|
132
|
+
senderName: ${JSON.stringify(emailConfig.senderName)},
|
|
133
|
+
senderEmail: ${senderEmail},
|
|
134
|
+
body: ${toTemplateLiteral(emailConfig.body)},
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
export default email;
|
|
139
|
+
`;
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
const toTemplateLiteral = (value: string) =>
|
|
143
|
+
`\`${value.replace(/\\/g, '\\\\').replace(/`/g, '\\`').replace(/\$\{/g, '\\${')}\``;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { Effect, Schema } from 'effect';
|
|
2
|
+
import type { authEmailPushDef, OptsFromCommand } from '../../../index.ts';
|
|
3
|
+
import {
|
|
4
|
+
getVerification,
|
|
5
|
+
readEmailConfig,
|
|
6
|
+
sendSenderVerification,
|
|
7
|
+
} from '../../../lib/email.ts';
|
|
8
|
+
import { CurrentApp } from '../../../context/currentApp.ts';
|
|
9
|
+
import { InstantHttpAuthed, withCommand } from '../../../lib/http.ts';
|
|
10
|
+
import {
|
|
11
|
+
HttpClient,
|
|
12
|
+
HttpClientRequest,
|
|
13
|
+
HttpClientResponse,
|
|
14
|
+
} from '@effect/platform';
|
|
15
|
+
import boxen from 'boxen';
|
|
16
|
+
import {
|
|
17
|
+
formatSenderVerificationDnsRecords,
|
|
18
|
+
getEmailTemplateStatus,
|
|
19
|
+
} from './status.ts';
|
|
20
|
+
import chalk from 'chalk';
|
|
21
|
+
import { getDefaultEmailTemplate } from './pull.ts';
|
|
22
|
+
|
|
23
|
+
export const authEmailPushCmd = Effect.fn(function* (
|
|
24
|
+
opts: OptsFromCommand<typeof authEmailPushDef>,
|
|
25
|
+
) {
|
|
26
|
+
const emailConfig = yield* readEmailConfig(opts.file);
|
|
27
|
+
const { appId } = yield* CurrentApp;
|
|
28
|
+
const http = yield* InstantHttpAuthed;
|
|
29
|
+
const authEmail = emailConfig.authEmail;
|
|
30
|
+
const defTemplate = yield* getDefaultEmailTemplate;
|
|
31
|
+
const senderEmail =
|
|
32
|
+
// If the value in the code is the default instant-owned email, remove it from the request
|
|
33
|
+
authEmail.senderEmail === defTemplate.senderEmail
|
|
34
|
+
? undefined
|
|
35
|
+
: emailConfig.authEmail.senderEmail;
|
|
36
|
+
|
|
37
|
+
yield* http
|
|
38
|
+
.pipe(
|
|
39
|
+
withCommand('auth email push'),
|
|
40
|
+
HttpClient.mapRequestInputEffect(
|
|
41
|
+
HttpClientRequest.bodyJson({
|
|
42
|
+
'email-type': 'magic-code',
|
|
43
|
+
subject: authEmail.subject,
|
|
44
|
+
body: authEmail.body,
|
|
45
|
+
'sender-email': senderEmail,
|
|
46
|
+
'sender-name': authEmail.senderName,
|
|
47
|
+
}),
|
|
48
|
+
),
|
|
49
|
+
)
|
|
50
|
+
.post(`/dash/apps/${appId}/email_templates`)
|
|
51
|
+
.pipe(Effect.flatMap(HttpClientResponse.schemaBodyJson(Schema.Any)));
|
|
52
|
+
|
|
53
|
+
const info = yield* getEmailTemplateStatus;
|
|
54
|
+
|
|
55
|
+
yield* Effect.log(
|
|
56
|
+
[
|
|
57
|
+
chalk.green('Email template saved!'),
|
|
58
|
+
'',
|
|
59
|
+
chalk.bold('Pushed fields:'),
|
|
60
|
+
` Email type: ${chalk.cyan('magic-code')}`,
|
|
61
|
+
` Subject: ${chalk.cyan(authEmail.subject)}`,
|
|
62
|
+
` Sender name: ${chalk.cyan(authEmail.senderName)}`,
|
|
63
|
+
` Sender email: ${chalk.cyan(senderEmail || '(default)')}`,
|
|
64
|
+
` Body: ${chalk.cyan(`${authEmail.body.length} characters`)}`,
|
|
65
|
+
].join('\n'),
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
// Check if verification email needs to be sent
|
|
69
|
+
|
|
70
|
+
if (info?.verification_verified === false) {
|
|
71
|
+
yield* sendSenderVerification;
|
|
72
|
+
yield* Effect.log(
|
|
73
|
+
boxen(
|
|
74
|
+
"We've sent a confirmation email containing a six digit code to verify the sender email address.\nUse instant-cli auth email verify <code> to complete verification.",
|
|
75
|
+
{
|
|
76
|
+
borderColor: 'yellow',
|
|
77
|
+
padding: { right: 1, left: 1 },
|
|
78
|
+
},
|
|
79
|
+
),
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (
|
|
84
|
+
emailConfig.authEmail.senderEmail &&
|
|
85
|
+
emailConfig.authEmail.senderEmail !== defTemplate.senderEmail
|
|
86
|
+
) {
|
|
87
|
+
const verification = yield* getVerification;
|
|
88
|
+
if (verification.verification) {
|
|
89
|
+
yield* Effect.log(
|
|
90
|
+
formatSenderVerificationDnsRecords(verification.verification),
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { HttpClientRequest, HttpClientResponse } from '@effect/platform';
|
|
2
|
+
import { Effect, Schema } from 'effect';
|
|
3
|
+
import { CurrentApp } from '../../../context/currentApp.ts';
|
|
4
|
+
import { InstantHttpAuthed, withCommand } from '../../../lib/http.ts';
|
|
5
|
+
import { getDefaultEmailTemplate, writeEmailTemplate } from './pull.ts';
|
|
6
|
+
import { getEmailTemplateStatus } from './status.ts';
|
|
7
|
+
|
|
8
|
+
export const authEmailResetCmd = Effect.fn(function* () {
|
|
9
|
+
const { appId } = yield* CurrentApp;
|
|
10
|
+
const http = (yield* InstantHttpAuthed).pipe(withCommand('auth email reset'));
|
|
11
|
+
|
|
12
|
+
const status = yield* getEmailTemplateStatus;
|
|
13
|
+
|
|
14
|
+
if (!status) {
|
|
15
|
+
yield* Effect.log(
|
|
16
|
+
'No email template configured. Resetting local email template.',
|
|
17
|
+
);
|
|
18
|
+
} else {
|
|
19
|
+
yield* http
|
|
20
|
+
.execute(
|
|
21
|
+
HttpClientRequest.del(
|
|
22
|
+
`/dash/apps/${appId}/email_templates/${status.id}`,
|
|
23
|
+
),
|
|
24
|
+
)
|
|
25
|
+
.pipe(Effect.flatMap(HttpClientResponse.schemaBodyJson(Schema.Any)));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const defaultConfig = yield* getDefaultEmailTemplate;
|
|
29
|
+
|
|
30
|
+
yield* writeEmailTemplate(defaultConfig, {
|
|
31
|
+
confirmOverwrite: false,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
yield* Effect.log(
|
|
35
|
+
'instant.email.ts file reset to default. To apply this change, run instant-cli auth email push',
|
|
36
|
+
);
|
|
37
|
+
});
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import boxen from 'boxen';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { Effect, Option, Schema } from 'effect';
|
|
4
|
+
import { CurrentApp } from '../../../context/currentApp.ts';
|
|
5
|
+
import type { authEmailStatusDef, OptsFromCommand } from '../../../index.ts';
|
|
6
|
+
import { InstantHttpAuthed } from '../../../lib/http.ts';
|
|
7
|
+
import { HttpClientResponse } from '@effect/platform';
|
|
8
|
+
import { getVerification } from '../../../lib/email.ts';
|
|
9
|
+
|
|
10
|
+
const formatValue = (value: string | number | null | undefined) =>
|
|
11
|
+
value ?? 'n/a';
|
|
12
|
+
|
|
13
|
+
const formatVerified = (value: boolean | null | undefined) => {
|
|
14
|
+
if (value === true) {
|
|
15
|
+
return chalk.green('verified');
|
|
16
|
+
}
|
|
17
|
+
if (value === false) {
|
|
18
|
+
return chalk.yellow('pending');
|
|
19
|
+
}
|
|
20
|
+
return 'n/a';
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const formatDnsRecord = (type: string, name: string, value: string) =>
|
|
24
|
+
[chalk.bold(type), `Name: ${name}`, `Value: ${value}`].join('\n');
|
|
25
|
+
|
|
26
|
+
export const formatSenderVerificationDnsRecords = (verification: {
|
|
27
|
+
Confirmed: boolean;
|
|
28
|
+
DKIMPendingHost: string;
|
|
29
|
+
DKIMPendingTextValue: string;
|
|
30
|
+
ReturnPathDomain: string;
|
|
31
|
+
ReturnPathDomainCNAMEValue: string;
|
|
32
|
+
}) =>
|
|
33
|
+
boxen(
|
|
34
|
+
[
|
|
35
|
+
chalk.bold('Add these DNS records to verify your sender email:'),
|
|
36
|
+
'',
|
|
37
|
+
formatDnsRecord(
|
|
38
|
+
'TXT',
|
|
39
|
+
verification.DKIMPendingHost,
|
|
40
|
+
verification.DKIMPendingTextValue,
|
|
41
|
+
),
|
|
42
|
+
'',
|
|
43
|
+
formatDnsRecord(
|
|
44
|
+
'CNAME',
|
|
45
|
+
verification.ReturnPathDomain,
|
|
46
|
+
verification.ReturnPathDomainCNAMEValue,
|
|
47
|
+
),
|
|
48
|
+
].join('\n'),
|
|
49
|
+
{
|
|
50
|
+
borderColor: verification.Confirmed ? 'green' : 'yellow',
|
|
51
|
+
padding: { right: 1, left: 1 },
|
|
52
|
+
},
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
export const EmailTemplateInfoSchema = Schema.Struct({
|
|
56
|
+
id: Schema.String,
|
|
57
|
+
email: Schema.String.pipe(Schema.NullishOr),
|
|
58
|
+
name: Schema.String,
|
|
59
|
+
sender_id: Schema.String.pipe(Schema.NullishOr),
|
|
60
|
+
app_id: Schema.String,
|
|
61
|
+
postmark_id: Schema.Number.pipe(Schema.NullishOr),
|
|
62
|
+
verification_verified: Schema.Boolean.pipe(Schema.NullishOr),
|
|
63
|
+
verification_id: Schema.String.pipe(Schema.NullishOr),
|
|
64
|
+
email_type: Schema.String,
|
|
65
|
+
body: Schema.String,
|
|
66
|
+
subject: Schema.String,
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
export type EmailTemplateInfo = typeof EmailTemplateInfoSchema.Type;
|
|
70
|
+
|
|
71
|
+
export const EmailTemplateSchema = Schema.Union(
|
|
72
|
+
Schema.Struct({
|
|
73
|
+
info: EmailTemplateInfoSchema.pipe(Schema.NullishOr),
|
|
74
|
+
}),
|
|
75
|
+
Schema.Null,
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
export const getEmailTemplateStatus = Effect.gen(function* () {
|
|
79
|
+
const { appId } = yield* CurrentApp;
|
|
80
|
+
const http = yield* InstantHttpAuthed;
|
|
81
|
+
|
|
82
|
+
const app = yield* http
|
|
83
|
+
.get(`/dash/apps/${appId}/email_status`)
|
|
84
|
+
.pipe(
|
|
85
|
+
Effect.flatMap(HttpClientResponse.schemaBodyJson(EmailTemplateSchema)),
|
|
86
|
+
);
|
|
87
|
+
return app?.info;
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
export const emailStatusCmd = Effect.fn(function* (
|
|
91
|
+
opts: OptsFromCommand<typeof authEmailStatusDef>,
|
|
92
|
+
) {
|
|
93
|
+
const info = yield* getEmailTemplateStatus;
|
|
94
|
+
|
|
95
|
+
if (!info) {
|
|
96
|
+
yield* Effect.log(
|
|
97
|
+
"No custom magic code email associated with this app.\nTo add one, run 'instant-cli auth email pull', edit the file, then run 'instant-cli auth email push'",
|
|
98
|
+
);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const verification = yield* Option.match(
|
|
103
|
+
Option.fromNullable(info.sender_id),
|
|
104
|
+
{
|
|
105
|
+
onNone: () => Effect.succeed(null),
|
|
106
|
+
onSome: () => getVerification,
|
|
107
|
+
},
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
if (opts.json) {
|
|
111
|
+
const fullInfo = verification
|
|
112
|
+
? {
|
|
113
|
+
...info,
|
|
114
|
+
verification: verification,
|
|
115
|
+
}
|
|
116
|
+
: info;
|
|
117
|
+
|
|
118
|
+
yield* Effect.log(JSON.stringify(fullInfo, null, 2));
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
yield* Effect.log(chalk.cyan('Custom Magic Code Email'));
|
|
123
|
+
yield* Effect.log(` Sender name: ${info.name}`);
|
|
124
|
+
yield* Effect.log(` Sender email: ${formatValue(info.email)}`);
|
|
125
|
+
yield* Effect.log(` Subject: ${info.subject}`);
|
|
126
|
+
yield* Effect.log(` Body: ${info.body}`);
|
|
127
|
+
|
|
128
|
+
if (verification) {
|
|
129
|
+
yield* Effect.log(
|
|
130
|
+
'\n' +
|
|
131
|
+
boxen(
|
|
132
|
+
[
|
|
133
|
+
`Instant verified: ${formatVerified(verification.instant['verified?'])}`,
|
|
134
|
+
`Postmark verified: ${formatVerified(verification.verification?.Confirmed)}`,
|
|
135
|
+
].join('\n'),
|
|
136
|
+
{
|
|
137
|
+
title: 'Custom Sender Verification',
|
|
138
|
+
borderColor:
|
|
139
|
+
verification.instant['verified?'] &&
|
|
140
|
+
verification.verification?.Confirmed
|
|
141
|
+
? 'green'
|
|
142
|
+
: 'yellow',
|
|
143
|
+
padding: { right: 1, left: 1 },
|
|
144
|
+
},
|
|
145
|
+
),
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
if (verification.verification) {
|
|
149
|
+
yield* Effect.log(
|
|
150
|
+
'\n' + formatSenderVerificationDnsRecords(verification.verification),
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Effect } from 'effect';
|
|
2
|
+
import type { authEmailVerifyDef, OptsFromCommand } from '../../../index.ts';
|
|
3
|
+
import { getVerification, submitVerification } from '../../../lib/email.ts';
|
|
4
|
+
|
|
5
|
+
export const verifyCmd = Effect.fn(function* (
|
|
6
|
+
code: string,
|
|
7
|
+
_opts: OptsFromCommand<typeof authEmailVerifyDef>,
|
|
8
|
+
) {
|
|
9
|
+
yield* submitVerification(code);
|
|
10
|
+
|
|
11
|
+
// get verification status
|
|
12
|
+
const verificationInfo = yield* getVerification;
|
|
13
|
+
|
|
14
|
+
if (
|
|
15
|
+
verificationInfo.instant['verified?'] &&
|
|
16
|
+
verificationInfo.verification?.Confirmed
|
|
17
|
+
) {
|
|
18
|
+
yield* Effect.log('Verification successful for both Postmark and Instant!');
|
|
19
|
+
}
|
|
20
|
+
});
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { Effect, Match, Option, Schema } from 'effect';
|
|
2
|
+
import type { authOriginAddDef, OptsFromCommand } from '../../../index.ts';
|
|
3
|
+
import { BadArgsError } from '../../../errors.ts';
|
|
4
|
+
import { GlobalOpts } from '../../../context/globalOpts.ts';
|
|
5
|
+
import { Args } from '../../../lib/args.ts';
|
|
6
|
+
import { runUIEffect } from '../../../lib/ui.ts';
|
|
7
|
+
import { addAuthorizedOrigin } from '../../../lib/oauth.ts';
|
|
8
|
+
import { UI } from '../../../ui/index.ts';
|
|
9
|
+
import chalk from 'chalk';
|
|
10
|
+
import boxen from 'boxen';
|
|
11
|
+
import { originDisplay, originSource } from './list.ts';
|
|
12
|
+
|
|
13
|
+
export const OriginTypeSchema = Schema.Literal(
|
|
14
|
+
'website',
|
|
15
|
+
'vercel',
|
|
16
|
+
'netlify',
|
|
17
|
+
'custom-scheme',
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
type OriginParams = string[];
|
|
21
|
+
|
|
22
|
+
type Validated =
|
|
23
|
+
| { type: 'success'; params: OriginParams }
|
|
24
|
+
| { type: 'error'; message: string };
|
|
25
|
+
|
|
26
|
+
const validateGenericUrl = (input: string): Validated => {
|
|
27
|
+
const trimmed = input.trim();
|
|
28
|
+
try {
|
|
29
|
+
const url = new URL(trimmed);
|
|
30
|
+
const host = url.host;
|
|
31
|
+
if (!host) {
|
|
32
|
+
throw new Error('missing host');
|
|
33
|
+
}
|
|
34
|
+
if (host.split('.').length === 1 && !url.port) {
|
|
35
|
+
throw new Error('invalid url');
|
|
36
|
+
}
|
|
37
|
+
return { type: 'success', params: [host] };
|
|
38
|
+
} catch {
|
|
39
|
+
if (!trimmed.startsWith('http')) {
|
|
40
|
+
return validateGenericUrl(`http://${trimmed}`);
|
|
41
|
+
}
|
|
42
|
+
return { type: 'error', message: 'Invalid URL.' };
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const validateNetlifyUrl = (input: string): Validated => {
|
|
47
|
+
const trimmed = input.trim();
|
|
48
|
+
if (!trimmed) {
|
|
49
|
+
return { type: 'error', message: 'Netlify site name is required.' };
|
|
50
|
+
}
|
|
51
|
+
return { type: 'success', params: [trimmed] };
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const validateVercelUrl = (input: string): Validated => {
|
|
55
|
+
const trimmed = input.trim();
|
|
56
|
+
if (!trimmed) {
|
|
57
|
+
return { type: 'error', message: 'Vercel project name is required.' };
|
|
58
|
+
}
|
|
59
|
+
return { type: 'success', params: ['vercel.app', trimmed] };
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const validateCustomScheme = (input: string): Validated => {
|
|
63
|
+
const trimmed = input.trim();
|
|
64
|
+
try {
|
|
65
|
+
const url = new URL(trimmed);
|
|
66
|
+
const scheme = url.protocol.slice(0, -1);
|
|
67
|
+
return { type: 'success', params: [scheme] };
|
|
68
|
+
} catch {
|
|
69
|
+
return { type: 'error', message: 'Invalid scheme.' };
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const addOriginHandler = Effect.fn(function* (
|
|
74
|
+
type: Schema.Schema.Type<typeof OriginTypeSchema>,
|
|
75
|
+
validated: { params: OriginParams },
|
|
76
|
+
) {
|
|
77
|
+
const response = yield* addAuthorizedOrigin({
|
|
78
|
+
service: type === 'website' ? 'generic' : type,
|
|
79
|
+
params: validated.params,
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
yield* Effect.log(
|
|
83
|
+
'\n' +
|
|
84
|
+
boxen(
|
|
85
|
+
[
|
|
86
|
+
`Origin added: ${originDisplay(response.origin)}`,
|
|
87
|
+
`Type: ${originSource(response.origin)}`,
|
|
88
|
+
`ID: ${response.origin.id}`,
|
|
89
|
+
].join('\n'),
|
|
90
|
+
{ dimBorder: true, padding: { right: 1, left: 1 } },
|
|
91
|
+
),
|
|
92
|
+
);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
const handleGenericOrigin = Effect.fn(function* (
|
|
96
|
+
opts: Record<string, unknown>,
|
|
97
|
+
) {
|
|
98
|
+
const url = yield* Args.text(opts, 'url').pipe(
|
|
99
|
+
Args.prompt({
|
|
100
|
+
prompt: 'Website URL:',
|
|
101
|
+
placeholder: 'example.com',
|
|
102
|
+
modifyOutput: UI.modifiers.piped([
|
|
103
|
+
UI.modifiers.topPadding,
|
|
104
|
+
UI.modifiers.dimOnComplete,
|
|
105
|
+
]),
|
|
106
|
+
}),
|
|
107
|
+
Args.required(),
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
const validated = validateGenericUrl(url);
|
|
111
|
+
if (validated.type === 'error') {
|
|
112
|
+
return yield* BadArgsError.make({ message: validated.message });
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
yield* addOriginHandler('website', validated);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
const handleVercelOrigin = Effect.fn(function* (opts: Record<string, unknown>) {
|
|
119
|
+
const project = yield* Args.text(opts, 'project').pipe(
|
|
120
|
+
Args.prompt({
|
|
121
|
+
prompt: 'Vercel project name:',
|
|
122
|
+
placeholder: 'vercel-project-name',
|
|
123
|
+
modifyOutput: UI.modifiers.piped([
|
|
124
|
+
UI.modifiers.topPadding,
|
|
125
|
+
UI.modifiers.dimOnComplete,
|
|
126
|
+
]),
|
|
127
|
+
}),
|
|
128
|
+
Args.required(),
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
const validated = validateVercelUrl(project);
|
|
132
|
+
if (validated.type === 'error') {
|
|
133
|
+
return yield* BadArgsError.make({ message: validated.message });
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
yield* addOriginHandler('vercel', validated);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
const handleNetlifyOrigin = Effect.fn(function* (
|
|
140
|
+
opts: Record<string, unknown>,
|
|
141
|
+
) {
|
|
142
|
+
const site = yield* Args.text(opts, 'site').pipe(
|
|
143
|
+
Args.prompt({
|
|
144
|
+
prompt: 'Netlify site name:',
|
|
145
|
+
placeholder: 'netlify-site-name',
|
|
146
|
+
modifyOutput: UI.modifiers.piped([
|
|
147
|
+
UI.modifiers.topPadding,
|
|
148
|
+
UI.modifiers.dimOnComplete,
|
|
149
|
+
]),
|
|
150
|
+
}),
|
|
151
|
+
Args.required(),
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
const validated = validateNetlifyUrl(site);
|
|
155
|
+
if (validated.type === 'error') {
|
|
156
|
+
return yield* BadArgsError.make({ message: validated.message });
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
yield* addOriginHandler('netlify', validated);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
const handleCustomSchemeOrigin = Effect.fn(function* (
|
|
163
|
+
opts: Record<string, unknown>,
|
|
164
|
+
) {
|
|
165
|
+
const scheme = yield* Args.text(opts, 'scheme').pipe(
|
|
166
|
+
Args.prompt({
|
|
167
|
+
prompt: 'App scheme:',
|
|
168
|
+
placeholder: 'app-scheme://',
|
|
169
|
+
modifyOutput: UI.modifiers.piped([
|
|
170
|
+
UI.modifiers.topPadding,
|
|
171
|
+
UI.modifiers.dimOnComplete,
|
|
172
|
+
]),
|
|
173
|
+
}),
|
|
174
|
+
Args.required(),
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
const validated = validateCustomScheme(scheme);
|
|
178
|
+
if (validated.type === 'error') {
|
|
179
|
+
return yield* BadArgsError.make({ message: validated.message });
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
yield* addOriginHandler('custom-scheme', validated);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
export const authOriginAddCmd = Effect.fn(
|
|
186
|
+
function* (
|
|
187
|
+
opts: OptsFromCommand<typeof authOriginAddDef> & Record<string, unknown>,
|
|
188
|
+
) {
|
|
189
|
+
const { yes } = yield* GlobalOpts;
|
|
190
|
+
if (!opts.type && yes) {
|
|
191
|
+
return yield* BadArgsError.make({
|
|
192
|
+
message: `Missing required value for --type. Expected one of: ${OriginTypeSchema.literals.join(', ')}`,
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
const originType = yield* Option.fromNullable(opts.type).pipe(
|
|
196
|
+
Effect.catchTag('NoSuchElementException', () =>
|
|
197
|
+
runUIEffect(
|
|
198
|
+
new UI.Select({
|
|
199
|
+
options: [
|
|
200
|
+
{ label: 'Website', value: 'website' },
|
|
201
|
+
{ label: 'Vercel previews', value: 'vercel' },
|
|
202
|
+
{ label: 'Netlify previews', value: 'netlify' },
|
|
203
|
+
{ label: 'App scheme', value: 'custom-scheme' },
|
|
204
|
+
],
|
|
205
|
+
promptText: 'Select an origin type:',
|
|
206
|
+
modifyOutput: UI.modifiers.piped([UI.modifiers.dimOnComplete]),
|
|
207
|
+
}),
|
|
208
|
+
),
|
|
209
|
+
),
|
|
210
|
+
Effect.andThen((s) => Schema.decodeUnknown(OriginTypeSchema)(s)),
|
|
211
|
+
Effect.catchTag('ParseError', () =>
|
|
212
|
+
BadArgsError.make({
|
|
213
|
+
message: `Invalid origin type, must be one of: ${OriginTypeSchema.literals.join(', ')}`,
|
|
214
|
+
}),
|
|
215
|
+
),
|
|
216
|
+
);
|
|
217
|
+
|
|
218
|
+
yield* Match.value(originType).pipe(
|
|
219
|
+
Match.withReturnType<Effect.Effect<void, any, any>>(),
|
|
220
|
+
Match.when('website', () => handleGenericOrigin(opts)),
|
|
221
|
+
Match.when('vercel', () => handleVercelOrigin(opts)),
|
|
222
|
+
Match.when('netlify', () => handleNetlifyOrigin(opts)),
|
|
223
|
+
Match.when('custom-scheme', () => handleCustomSchemeOrigin(opts)),
|
|
224
|
+
Match.exhaustive,
|
|
225
|
+
);
|
|
226
|
+
},
|
|
227
|
+
Effect.catchTag('BadArgsError', (e) =>
|
|
228
|
+
Effect.gen(function* () {
|
|
229
|
+
yield* Effect.logError(e.message);
|
|
230
|
+
yield* Effect.log(
|
|
231
|
+
chalk.dim(
|
|
232
|
+
'hint: run `instant-cli auth origin add --help` for available arguments',
|
|
233
|
+
),
|
|
234
|
+
);
|
|
235
|
+
}),
|
|
236
|
+
),
|
|
237
|
+
);
|