@beezer-pet/instant-cli 0.0.0-stage → 1.0.67-beezer.3
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
package/src/lib/login.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Effect, Schedule, Schema } from 'effect';
|
|
2
|
+
import { InstantHttp, withCommand } from './http.ts';
|
|
3
|
+
import { HttpClientRequest, HttpClientResponse } from '@effect/platform';
|
|
4
|
+
import { writeAuthToken } from '../auth/index.ts';
|
|
5
|
+
import { getBaseUrl } from './config.ts';
|
|
6
|
+
|
|
7
|
+
const LoginInfo = Schema.Struct({
|
|
8
|
+
secret: Schema.String,
|
|
9
|
+
ticket: Schema.String,
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
const TokenResult = Schema.Struct({
|
|
13
|
+
token: Schema.String,
|
|
14
|
+
email: Schema.String,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
export const getLoginTicketAndSecret = Effect.gen(function* () {
|
|
18
|
+
const http = yield* InstantHttp;
|
|
19
|
+
const res = yield* http
|
|
20
|
+
.pipe(withCommand('login'))
|
|
21
|
+
.post('/dash/cli/auth/register')
|
|
22
|
+
.pipe(Effect.flatMap(HttpClientResponse.schemaBodyJson(LoginInfo)));
|
|
23
|
+
return res;
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export const waitForAuthToken = Effect.fn(function* (secret: string) {
|
|
27
|
+
const http = (yield* InstantHttp).pipe(withCommand('login'));
|
|
28
|
+
const res = yield* HttpClientRequest.post('/dash/cli/auth/check').pipe(
|
|
29
|
+
HttpClientRequest.bodyUnsafeJson({
|
|
30
|
+
secret,
|
|
31
|
+
}),
|
|
32
|
+
http.execute,
|
|
33
|
+
Effect.flatMap(HttpClientResponse.schemaBodyJson(TokenResult)),
|
|
34
|
+
Effect.retry({
|
|
35
|
+
while: (e) =>
|
|
36
|
+
e._tag === 'InstantHttpError' &&
|
|
37
|
+
e.hint?.errors?.at(0)?.issue === 'waiting-for-user',
|
|
38
|
+
schedule: Schedule.fixed('1 seconds'),
|
|
39
|
+
times: 120,
|
|
40
|
+
}),
|
|
41
|
+
);
|
|
42
|
+
return res;
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
export const saveConfigAuthToken = Effect.fn(function* (token: string) {
|
|
46
|
+
const apiURI = yield* getBaseUrl;
|
|
47
|
+
yield* Effect.tryPromise(() => writeAuthToken(apiURI, token));
|
|
48
|
+
});
|
package/src/lib/oauth.ts
ADDED
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
import { HttpBody, HttpClientResponse } from '@effect/platform';
|
|
2
|
+
import { Effect, Schema } from 'effect';
|
|
3
|
+
import { CurrentApp } from '../context/currentApp.ts';
|
|
4
|
+
import { InstantHttpAuthed, withCommand } from './http.ts';
|
|
5
|
+
import { validateRequired } from './ui.ts';
|
|
6
|
+
import { UI } from '../ui/index.ts';
|
|
7
|
+
import { BadArgsError } from '../errors.ts';
|
|
8
|
+
import type { ClientTypeSchema } from '../commands/auth/client/add.ts';
|
|
9
|
+
import { Args } from './args.ts';
|
|
10
|
+
|
|
11
|
+
export const AuthorizedOriginService = Schema.Literal(
|
|
12
|
+
'generic',
|
|
13
|
+
'vercel',
|
|
14
|
+
'netlify',
|
|
15
|
+
'custom-scheme',
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
export const AuthorizedOrigin = Schema.Struct({
|
|
19
|
+
id: Schema.String,
|
|
20
|
+
service: AuthorizedOriginService,
|
|
21
|
+
params: Schema.Array(Schema.String).pipe(Schema.mutable),
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export const OAuthServiceProvider = Schema.Struct({
|
|
25
|
+
id: Schema.String,
|
|
26
|
+
provider_name: Schema.String,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
export const GoogleAppTypeSchema = Schema.Literal(
|
|
30
|
+
'web',
|
|
31
|
+
'ios',
|
|
32
|
+
'android',
|
|
33
|
+
'button-for-web',
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
const NullableString = Schema.Union(Schema.String, Schema.Null).pipe(
|
|
37
|
+
Schema.optional,
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
const NullableBoolean = Schema.Union(Schema.Boolean, Schema.Null).pipe(
|
|
41
|
+
Schema.optional,
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
const OAuthClientMeta = Schema.Struct({
|
|
45
|
+
// Currently the CLI only reads Google app type from meta. Other providers store
|
|
46
|
+
// different meta shapes, so keep the rest open until we have a clean
|
|
47
|
+
// top-level discriminator for a full provider-specific union.
|
|
48
|
+
appType: GoogleAppTypeSchema.pipe(Schema.optional),
|
|
49
|
+
}).pipe(
|
|
50
|
+
Schema.extend(Schema.Record({ key: Schema.String, value: Schema.Any })),
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
export const OAuthClient = Schema.Struct({
|
|
54
|
+
id: Schema.String,
|
|
55
|
+
client_name: Schema.String,
|
|
56
|
+
client_id: NullableString,
|
|
57
|
+
provider_id: Schema.String,
|
|
58
|
+
authorization_endpoint: NullableString,
|
|
59
|
+
token_endpoint: NullableString,
|
|
60
|
+
discovery_endpoint: NullableString,
|
|
61
|
+
redirect_to: NullableString,
|
|
62
|
+
meta: Schema.Union(OAuthClientMeta, Schema.Null).pipe(Schema.optional),
|
|
63
|
+
use_shared_credentials: NullableBoolean,
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
export const AddOAuthProviderResponse = Schema.Struct({
|
|
67
|
+
provider: OAuthServiceProvider,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
export const AddOAuthClientResponse = Schema.Struct({
|
|
71
|
+
client: OAuthClient,
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
export const AuthorizedOriginResponse = Schema.Struct({
|
|
75
|
+
origin: AuthorizedOrigin,
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const NullableArray = <A, I, R>(schema: Schema.Schema<A, I, R>) =>
|
|
79
|
+
Schema.Union(Schema.Array(schema).pipe(Schema.mutable), Schema.Null).pipe(
|
|
80
|
+
Schema.optional,
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
export const AppsAuthResponse = Schema.Struct({
|
|
84
|
+
authorized_redirect_origins: NullableArray(AuthorizedOrigin),
|
|
85
|
+
oauth_service_providers: NullableArray(OAuthServiceProvider),
|
|
86
|
+
oauth_clients: NullableArray(OAuthClient),
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
export const getAppsAuth = Effect.fn(function* () {
|
|
90
|
+
const http = (yield* InstantHttpAuthed).pipe(withCommand('auth'));
|
|
91
|
+
const targetAppId = (yield* CurrentApp).appId;
|
|
92
|
+
|
|
93
|
+
return yield* http
|
|
94
|
+
.get(`/dash/apps/${targetAppId}/auth`)
|
|
95
|
+
.pipe(Effect.flatMap(HttpClientResponse.schemaBodyJson(AppsAuthResponse)));
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
export const addOAuthProvider = Effect.fn(function* (params: {
|
|
99
|
+
appId?: string;
|
|
100
|
+
providerName: string;
|
|
101
|
+
}) {
|
|
102
|
+
const http = (yield* InstantHttpAuthed).pipe(withCommand('auth'));
|
|
103
|
+
const targetAppId = params.appId ?? (yield* CurrentApp).appId;
|
|
104
|
+
|
|
105
|
+
return yield* http
|
|
106
|
+
.post(`/dash/apps/${targetAppId}/oauth_service_providers`, {
|
|
107
|
+
body: HttpBody.unsafeJson({
|
|
108
|
+
provider_name: params.providerName,
|
|
109
|
+
}),
|
|
110
|
+
})
|
|
111
|
+
.pipe(
|
|
112
|
+
Effect.flatMap(
|
|
113
|
+
HttpClientResponse.schemaBodyJson(AddOAuthProviderResponse),
|
|
114
|
+
),
|
|
115
|
+
);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
export const addOAuthClient = Effect.fn(function* (params: {
|
|
119
|
+
appId?: string;
|
|
120
|
+
providerId: string;
|
|
121
|
+
clientName: string;
|
|
122
|
+
clientId?: string;
|
|
123
|
+
clientSecret?: string;
|
|
124
|
+
authorizationEndpoint?: string;
|
|
125
|
+
tokenEndpoint?: string;
|
|
126
|
+
discoveryEndpoint?: string;
|
|
127
|
+
redirectTo?: string;
|
|
128
|
+
meta?: unknown;
|
|
129
|
+
useSharedCredentials?: boolean;
|
|
130
|
+
}) {
|
|
131
|
+
const http = (yield* InstantHttpAuthed).pipe(withCommand('auth'));
|
|
132
|
+
const targetAppId = params.appId ?? (yield* CurrentApp).appId;
|
|
133
|
+
|
|
134
|
+
return yield* http
|
|
135
|
+
.post(`/dash/apps/${targetAppId}/oauth_clients`, {
|
|
136
|
+
body: HttpBody.unsafeJson({
|
|
137
|
+
provider_id: params.providerId,
|
|
138
|
+
client_name: params.clientName,
|
|
139
|
+
client_id: params.clientId,
|
|
140
|
+
client_secret: params.clientSecret,
|
|
141
|
+
authorization_endpoint: params.authorizationEndpoint,
|
|
142
|
+
token_endpoint: params.tokenEndpoint,
|
|
143
|
+
discovery_endpoint: params.discoveryEndpoint,
|
|
144
|
+
redirect_to: params.redirectTo,
|
|
145
|
+
meta: params.meta,
|
|
146
|
+
use_shared_credentials: params.useSharedCredentials,
|
|
147
|
+
}),
|
|
148
|
+
})
|
|
149
|
+
.pipe(
|
|
150
|
+
Effect.flatMap(HttpClientResponse.schemaBodyJson(AddOAuthClientResponse)),
|
|
151
|
+
);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
export const updateOAuthClient = Effect.fn(function* (params: {
|
|
155
|
+
oauthClientId: string;
|
|
156
|
+
clientId?: string | null;
|
|
157
|
+
clientSecret?: string | null;
|
|
158
|
+
discoveryEndpoint?: string | null;
|
|
159
|
+
redirectTo?: string | null;
|
|
160
|
+
meta?: unknown;
|
|
161
|
+
useSharedCredentials?: boolean | null;
|
|
162
|
+
}) {
|
|
163
|
+
const http = (yield* InstantHttpAuthed).pipe(withCommand('auth'));
|
|
164
|
+
const targetAppId = (yield* CurrentApp).appId;
|
|
165
|
+
|
|
166
|
+
return yield* http
|
|
167
|
+
.post(`/dash/apps/${targetAppId}/oauth_clients/${params.oauthClientId}`, {
|
|
168
|
+
body: HttpBody.unsafeJson({
|
|
169
|
+
client_id: params.clientId,
|
|
170
|
+
client_secret: params.clientSecret,
|
|
171
|
+
discovery_endpoint: params.discoveryEndpoint,
|
|
172
|
+
redirect_to: params.redirectTo,
|
|
173
|
+
meta: params.meta,
|
|
174
|
+
use_shared_credentials: params.useSharedCredentials,
|
|
175
|
+
}),
|
|
176
|
+
})
|
|
177
|
+
.pipe(
|
|
178
|
+
Effect.flatMap(HttpClientResponse.schemaBodyJson(AddOAuthClientResponse)),
|
|
179
|
+
);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
export const getOrCreateProvider = Effect.fn(function* (
|
|
183
|
+
type: typeof ClientTypeSchema.Type,
|
|
184
|
+
) {
|
|
185
|
+
const auth = yield* getAppsAuth();
|
|
186
|
+
const provider = auth.oauth_service_providers?.find(
|
|
187
|
+
(entry) => entry.provider_name === type,
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
if (provider) {
|
|
191
|
+
return { auth, provider };
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const created = yield* addOAuthProvider({ providerName: type });
|
|
195
|
+
return { auth, provider: created.provider };
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
// Returns prefix if unused; otherwise appends integers starting at 2.
|
|
199
|
+
// e.g. findName('google', new Set(['google', 'google2'])) returns 'google3'.
|
|
200
|
+
export const findName = (prefix: string, used: Set<string>) => {
|
|
201
|
+
if (!used.has(prefix)) {
|
|
202
|
+
return prefix;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
for (let i = 2; ; i++) {
|
|
206
|
+
const candidate = `${prefix}${i}`;
|
|
207
|
+
if (!used.has(candidate)) {
|
|
208
|
+
return candidate;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
export const getClientNameAndProvider = Effect.fn(function* (
|
|
214
|
+
providerType: typeof ClientTypeSchema.Type,
|
|
215
|
+
opts: Record<string, unknown>,
|
|
216
|
+
) {
|
|
217
|
+
const { auth, provider } = yield* getOrCreateProvider(providerType);
|
|
218
|
+
const usedClientNames = new Set(
|
|
219
|
+
(auth.oauth_clients ?? []).map((client) => client.client_name),
|
|
220
|
+
);
|
|
221
|
+
const suggestedClientName = findName(providerType, usedClientNames);
|
|
222
|
+
|
|
223
|
+
const clientName = yield* Args.text(opts, 'name').pipe(
|
|
224
|
+
Args.prompt({
|
|
225
|
+
prompt: 'Client Name:',
|
|
226
|
+
defaultValue: suggestedClientName,
|
|
227
|
+
placeholder: suggestedClientName,
|
|
228
|
+
validate: validateRequired,
|
|
229
|
+
modifyOutput: UI.modifiers.piped([
|
|
230
|
+
UI.modifiers.topPadding,
|
|
231
|
+
UI.modifiers.dimOnComplete,
|
|
232
|
+
]),
|
|
233
|
+
}),
|
|
234
|
+
Args.required(),
|
|
235
|
+
);
|
|
236
|
+
|
|
237
|
+
if (usedClientNames.has(clientName)) {
|
|
238
|
+
return yield* BadArgsError.make({
|
|
239
|
+
message: `The unique name '${clientName}' is already in use.`,
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
return { provider, clientName };
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
export const findClientByIdOrName = Effect.fn(function* (params: {
|
|
246
|
+
id?: string;
|
|
247
|
+
name?: string;
|
|
248
|
+
}) {
|
|
249
|
+
if (params.id && params.name) {
|
|
250
|
+
return yield* BadArgsError.make({
|
|
251
|
+
message: 'Cannot specify both --id and --name',
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
if (!params.id && !params.name) {
|
|
255
|
+
return yield* BadArgsError.make({
|
|
256
|
+
message: 'Must specify --id or --name',
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const auth = yield* getAppsAuth();
|
|
261
|
+
const clients = auth.oauth_clients ?? [];
|
|
262
|
+
const client = params.id
|
|
263
|
+
? clients.find((entry) => entry.id === params.id)
|
|
264
|
+
: clients.find((entry) => entry.client_name === params.name);
|
|
265
|
+
|
|
266
|
+
if (!client) {
|
|
267
|
+
const lookup = params.id ? `id ${params.id}` : `name ${params.name}`;
|
|
268
|
+
return yield* BadArgsError.make({
|
|
269
|
+
message: `OAuth client not found: ${lookup}`,
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
return { auth, client };
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
export const removeAuthorizedOrigin = Effect.fn(function* (originId: string) {
|
|
277
|
+
const http = (yield* InstantHttpAuthed).pipe(
|
|
278
|
+
withCommand('auth origin delete'),
|
|
279
|
+
);
|
|
280
|
+
const { appId } = yield* CurrentApp;
|
|
281
|
+
|
|
282
|
+
return yield* http
|
|
283
|
+
.del(`/dash/apps/${appId}/authorized_redirect_origins/${originId}`)
|
|
284
|
+
.pipe(
|
|
285
|
+
Effect.flatMap(
|
|
286
|
+
HttpClientResponse.schemaBodyJson(AuthorizedOriginResponse),
|
|
287
|
+
),
|
|
288
|
+
);
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
export const addAuthorizedOrigin = Effect.fn(function* (params: {
|
|
292
|
+
service: Schema.Schema.Type<typeof AuthorizedOriginService>;
|
|
293
|
+
params: string[];
|
|
294
|
+
}) {
|
|
295
|
+
const http = (yield* InstantHttpAuthed).pipe(withCommand('auth origin add'));
|
|
296
|
+
const { appId } = yield* CurrentApp;
|
|
297
|
+
|
|
298
|
+
return yield* http
|
|
299
|
+
.post(`/dash/apps/${appId}/authorized_redirect_origins`, {
|
|
300
|
+
body: HttpBody.unsafeJson({
|
|
301
|
+
service: params.service,
|
|
302
|
+
params: params.params,
|
|
303
|
+
}),
|
|
304
|
+
})
|
|
305
|
+
.pipe(
|
|
306
|
+
Effect.flatMap(
|
|
307
|
+
HttpClientResponse.schemaBodyJson(AuthorizedOriginResponse),
|
|
308
|
+
),
|
|
309
|
+
);
|
|
310
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Effect } from 'effect';
|
|
2
|
+
import { PlatformApi as InstantPlatformApi } from '@instantdb/platform';
|
|
3
|
+
import { AuthToken } from '../context/authToken.ts';
|
|
4
|
+
import { getBaseUrl } from './config.ts';
|
|
5
|
+
|
|
6
|
+
export const getAuthedPlatformApi = Effect.gen(function* () {
|
|
7
|
+
const apiURI = yield* getBaseUrl;
|
|
8
|
+
const authToken = yield* AuthToken;
|
|
9
|
+
const token = yield* authToken.getAuthToken;
|
|
10
|
+
return new InstantPlatformApi({ apiURI, auth: { token } });
|
|
11
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Effect, Option, Schema } from 'effect';
|
|
2
|
+
import { CurrentApp } from '../context/currentApp.ts';
|
|
3
|
+
import { InstantHttpAuthed, withCommand } from './http.ts';
|
|
4
|
+
import { HttpClientResponse } from '@effect/platform';
|
|
5
|
+
import { readLocalPermsFile } from '../old.js';
|
|
6
|
+
import { getPermsPathToWrite } from '../util/findConfigCandidates.ts';
|
|
7
|
+
import { promptOk } from './ui.ts';
|
|
8
|
+
import { UI } from '../ui/index.ts';
|
|
9
|
+
import { writeTypescript } from './pullSchema.ts';
|
|
10
|
+
import { generatePermsTypescriptFile } from '@instantdb/platform';
|
|
11
|
+
import { ProjectInfo } from '../context/projectInfo.ts';
|
|
12
|
+
import { Path } from '@effect/platform';
|
|
13
|
+
|
|
14
|
+
export const pullPerms = Effect.gen(function* () {
|
|
15
|
+
yield* Effect.log('\nPulling perms...');
|
|
16
|
+
const { appId } = yield* CurrentApp;
|
|
17
|
+
const http = yield* InstantHttpAuthed;
|
|
18
|
+
const permsResponse = yield* http
|
|
19
|
+
.pipe(withCommand('pull'))
|
|
20
|
+
.get(`/dash/apps/${appId}/perms/pull`)
|
|
21
|
+
.pipe(Effect.flatMap(HttpClientResponse.schemaBodyJson(Schema.Any))); // parse result body into "any"
|
|
22
|
+
|
|
23
|
+
const prevPermsFile = yield* Effect.tryPromise(readLocalPermsFile).pipe(
|
|
24
|
+
Effect.map(Option.fromNullable),
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
const shortPermsPath = Option.match(prevPermsFile, {
|
|
28
|
+
onSome: (file) => file.path,
|
|
29
|
+
onNone: () => getPermsPathToWrite(),
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
if (Option.isSome(prevPermsFile)) {
|
|
33
|
+
const shouldContinue = yield* promptOk({
|
|
34
|
+
promptText: `This will overwrite your local ${shortPermsPath} file, OK to proceed?`,
|
|
35
|
+
modifyOutput: UI.modifiers.yPadding,
|
|
36
|
+
inline: true,
|
|
37
|
+
});
|
|
38
|
+
if (!shouldContinue) return;
|
|
39
|
+
}
|
|
40
|
+
const { instantModuleName, pkgDir } = yield* ProjectInfo;
|
|
41
|
+
const fileContent = generatePermsTypescriptFile(
|
|
42
|
+
permsResponse?.perms || {},
|
|
43
|
+
instantModuleName,
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
const path = yield* Path.Path;
|
|
47
|
+
|
|
48
|
+
yield* writeTypescript(path.join(pkgDir, shortPermsPath), fileContent);
|
|
49
|
+
yield* Effect.log('✅ Wrote permissions to ' + shortPermsPath);
|
|
50
|
+
});
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { FileSystem, HttpClientResponse, Path } from '@effect/platform';
|
|
2
|
+
import {
|
|
3
|
+
apiSchemaToInstantSchemaDef,
|
|
4
|
+
generateSchemaTypescriptFile,
|
|
5
|
+
} from '@instantdb/platform';
|
|
6
|
+
import { Effect, Schema } from 'effect';
|
|
7
|
+
import prettier from 'prettier';
|
|
8
|
+
import { countEntities, readLocalSchemaFile } from '../old.js';
|
|
9
|
+
import { UI } from '../ui/index.ts';
|
|
10
|
+
import { getSchemaPathToWrite } from '../util/findConfigCandidates.ts';
|
|
11
|
+
import { CurrentApp } from '../context/currentApp.ts';
|
|
12
|
+
import { ProjectInfo } from '../context/projectInfo.ts';
|
|
13
|
+
import { InstantHttpAuthed, withCommand } from './http.ts';
|
|
14
|
+
import { promptOk } from './ui.ts';
|
|
15
|
+
import { ReadSchemaFileError } from './pushSchema.ts';
|
|
16
|
+
import { mergeSchema, MergeSchemaError } from '../util/mergeSchema.ts';
|
|
17
|
+
|
|
18
|
+
export const pullSchema = ({
|
|
19
|
+
experimentalTypePreservation,
|
|
20
|
+
}: {
|
|
21
|
+
experimentalTypePreservation?: boolean;
|
|
22
|
+
}) =>
|
|
23
|
+
Effect.gen(function* () {
|
|
24
|
+
yield* Effect.log('Pulling schema...');
|
|
25
|
+
const { appId } = yield* CurrentApp;
|
|
26
|
+
const http = yield* InstantHttpAuthed;
|
|
27
|
+
|
|
28
|
+
const schemaResponse = yield* http
|
|
29
|
+
.pipe(withCommand('pull'))
|
|
30
|
+
.get(`/dash/apps/${appId}/schema/pull`)
|
|
31
|
+
.pipe(Effect.flatMap(HttpClientResponse.schemaBodyJson(Schema.Any))); // parse result body into "any"
|
|
32
|
+
|
|
33
|
+
if (
|
|
34
|
+
!countEntities(schemaResponse.schema.refs) &&
|
|
35
|
+
!countEntities(schemaResponse.schema.blobs)
|
|
36
|
+
) {
|
|
37
|
+
yield* Effect.log('Schema is empty. Skipping.');
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const prevSchemaFile = yield* Effect.tryPromise(readLocalSchemaFile).pipe(
|
|
42
|
+
Effect.mapError((err) =>
|
|
43
|
+
ReadSchemaFileError.make({
|
|
44
|
+
message: `Error reading local schema file: ${err}`,
|
|
45
|
+
cause: err,
|
|
46
|
+
}),
|
|
47
|
+
),
|
|
48
|
+
);
|
|
49
|
+
const shortSchemaPath = getSchemaPathToWrite(prevSchemaFile?.path);
|
|
50
|
+
const path = yield* Path.Path;
|
|
51
|
+
const { pkgDir, instantModuleName } = yield* ProjectInfo;
|
|
52
|
+
const schemaPath = path.join(pkgDir, shortSchemaPath);
|
|
53
|
+
|
|
54
|
+
if (prevSchemaFile) {
|
|
55
|
+
const shouldContinue = yield* promptOk({
|
|
56
|
+
promptText: `This will overwrite your local ${shortSchemaPath} file, OK to proceed?`,
|
|
57
|
+
modifyOutput: UI.modifiers.yPadding,
|
|
58
|
+
inline: true,
|
|
59
|
+
});
|
|
60
|
+
if (!shouldContinue) return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
let newSchemaContent = generateSchemaTypescriptFile(
|
|
64
|
+
prevSchemaFile?.schema,
|
|
65
|
+
apiSchemaToInstantSchemaDef(schemaResponse.schema),
|
|
66
|
+
instantModuleName,
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
if (prevSchemaFile && experimentalTypePreservation) {
|
|
70
|
+
const fs = yield* FileSystem.FileSystem;
|
|
71
|
+
const oldSchemaContent = yield* fs.readFileString(prevSchemaFile.path);
|
|
72
|
+
newSchemaContent = yield* Effect.try(() =>
|
|
73
|
+
mergeSchema(oldSchemaContent, newSchemaContent),
|
|
74
|
+
).pipe(
|
|
75
|
+
Effect.mapError((e) => new MergeSchemaError({ message: e.message })),
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
yield* writeTypescript(schemaPath, newSchemaContent);
|
|
79
|
+
yield* Effect.log('✅ Wrote schema to ' + shortSchemaPath);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
export const writeTypescript = (path: string, content: string) =>
|
|
83
|
+
Effect.gen(function* () {
|
|
84
|
+
const prettierConfig = yield* Effect.tryPromise(() =>
|
|
85
|
+
prettier.resolveConfig(path),
|
|
86
|
+
);
|
|
87
|
+
const formattedCode = yield* Effect.tryPromise(() =>
|
|
88
|
+
prettier.format(content, {
|
|
89
|
+
...prettierConfig,
|
|
90
|
+
parser: 'typescript',
|
|
91
|
+
}),
|
|
92
|
+
);
|
|
93
|
+
const fs = yield* FileSystem.FileSystem;
|
|
94
|
+
yield* fs.writeFileString(path, formattedCode);
|
|
95
|
+
});
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { Effect, Option, Schema } from 'effect';
|
|
2
|
+
import jsonDiff from 'json-diff';
|
|
3
|
+
import { readLocalPermsFile } from '../old.js';
|
|
4
|
+
import { InstantHttpAuthed, withCommand } from './http.ts';
|
|
5
|
+
import {
|
|
6
|
+
HttpClient,
|
|
7
|
+
HttpClientRequest,
|
|
8
|
+
HttpClientResponse,
|
|
9
|
+
} from '@effect/platform';
|
|
10
|
+
import { CurrentApp } from '../context/currentApp.ts';
|
|
11
|
+
import { promptOk } from './ui.ts';
|
|
12
|
+
import boxen from 'boxen';
|
|
13
|
+
import chalk from 'chalk';
|
|
14
|
+
|
|
15
|
+
export class NoPermsFileError extends Schema.TaggedError<NoPermsFileError>(
|
|
16
|
+
'NoPermsFileError',
|
|
17
|
+
)('NoPermsFileError', {
|
|
18
|
+
message: Schema.String,
|
|
19
|
+
}) {}
|
|
20
|
+
|
|
21
|
+
const PullPermsResponse = Schema.Struct({
|
|
22
|
+
perms: Schema.Any.pipe(Schema.optional),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
export const pushPerms = Effect.gen(function* () {
|
|
26
|
+
yield* Effect.log('Planning perms...');
|
|
27
|
+
const { appId } = yield* CurrentApp;
|
|
28
|
+
const http = yield* InstantHttpAuthed;
|
|
29
|
+
|
|
30
|
+
const permsFile = yield* Effect.tryPromise(readLocalPermsFile).pipe(
|
|
31
|
+
Effect.flatMap(Option.fromNullable),
|
|
32
|
+
Effect.mapError(() =>
|
|
33
|
+
NoPermsFileError.make({
|
|
34
|
+
message: `We couldn't find your ${chalk.yellow('`instant.perms.ts`')} file. Make sure it's in the root directory. (Hint: You can use an INSTANT_PERMS_FILE_PATH environment variable to specify it.)`,
|
|
35
|
+
}),
|
|
36
|
+
),
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
const prodPerms = yield* http
|
|
40
|
+
.pipe(withCommand('push'))
|
|
41
|
+
.get(`/dash/apps/${appId}/perms/pull`)
|
|
42
|
+
.pipe(Effect.flatMap(HttpClientResponse.schemaBodyJson(PullPermsResponse))); // parse result body into "any"
|
|
43
|
+
|
|
44
|
+
const diffedStr = jsonDiff.diffString(
|
|
45
|
+
prodPerms.perms || {},
|
|
46
|
+
permsFile.perms || {},
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
if (!diffedStr.length) {
|
|
50
|
+
yield* Effect.log(chalk.bgGray('No perms changes to apply!'));
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const okPush = yield* promptOk({
|
|
55
|
+
promptText: 'Push these changes to your perms?',
|
|
56
|
+
modifyOutput: (output) => {
|
|
57
|
+
let both = diffedStr + '\n' + output;
|
|
58
|
+
return boxen(both, {
|
|
59
|
+
dimBorder: true,
|
|
60
|
+
padding: {
|
|
61
|
+
left: 1,
|
|
62
|
+
right: 1,
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
if (!okPush) return;
|
|
68
|
+
|
|
69
|
+
yield* http
|
|
70
|
+
.pipe(
|
|
71
|
+
withCommand('push'),
|
|
72
|
+
HttpClient.mapRequestInputEffect(
|
|
73
|
+
HttpClientRequest.bodyJson({ code: permsFile.perms }),
|
|
74
|
+
),
|
|
75
|
+
)
|
|
76
|
+
.post(`/dash/apps/${appId}/rules`)
|
|
77
|
+
.pipe(Effect.flatMap(HttpClientResponse.schemaBodyJson(Schema.Any)));
|
|
78
|
+
|
|
79
|
+
yield* Effect.log(chalk.green('Permissions updated!'));
|
|
80
|
+
});
|