-
Notifications
You must be signed in to change notification settings - Fork 9
feat: fix the 451 CoreConsole error into a better user flow to accept developer terms #262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -18,8 +18,11 @@ const LibConsoleCLI = require('@adobe/aio-cli-lib-console') | |||||||||
| const { CLI } = require('@adobe/aio-lib-ims/src/context') | ||||||||||
| const { getCliEnv } = require('@adobe/aio-lib-env') | ||||||||||
| const yaml = require('js-yaml') | ||||||||||
| const hyperlinker = require('hyperlinker') | ||||||||||
| const { CONFIG_KEYS, API_KEYS } = require('../../config') | ||||||||||
|
|
||||||||||
| const DEV_TERMS_URL = 'https://www.adobe.com/go/developer-terms' | ||||||||||
|
|
||||||||||
| class ConsoleCommand extends Command { | ||||||||||
| async run () { | ||||||||||
| const help = new Help(this.config) | ||||||||||
|
|
@@ -89,6 +92,39 @@ class ConsoleCommand extends Command { | |||||||||
| LibConsoleCLI.cleanStdOut() | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * Ensure the Developer Terms of Service have been accepted for the given org. | ||||||||||
| * Mirrors the flow in @adobe/aio-cli-plugin-app's `app init` command so that | ||||||||||
| * `console` subcommands surface a CLI-native prompt instead of leaking a raw | ||||||||||
| * 451 "use POST /console/services/ims/organizations/:orgId/terms" message | ||||||||||
| * from the underlying SDK. | ||||||||||
| * | ||||||||||
| * @param {object} consoleCLI initialised @adobe/aio-cli-lib-console instance (this.consoleCLI) | ||||||||||
| * @param {string} orgId organization id to check | ||||||||||
| * @param {boolean} [skipPrompts] when true, fail fast instead of prompting (default false) | ||||||||||
| * @returns {Promise<void>} | ||||||||||
| */ | ||||||||||
| async ensureDevTermAccepted (consoleCLI, orgId, skipPrompts = false) { | ||||||||||
| const isTermAccepted = await consoleCLI.checkDevTermsForOrg(orgId) | ||||||||||
| if (isTermAccepted) { | ||||||||||
| return | ||||||||||
| } | ||||||||||
| if (skipPrompts) { | ||||||||||
| this.error('Developer Terms of Service have not been accepted for this organization. Please re-run this command without `--json`/`--yml`, or run `aio app init` to accept the terms first.') | ||||||||||
| } | ||||||||||
| const terms = await consoleCLI.getDevTermsForOrg() | ||||||||||
| const termsText = terms.text ? terms.text.trim() : '' | ||||||||||
| const confirmDevTerms = await consoleCLI.prompt.promptConfirm(`${termsText}\n\nYou have not accepted the Developer Terms of Service. Go to ${hyperlinker(DEV_TERMS_URL, DEV_TERMS_URL)} to view the terms. Do you accept the terms? (y/n):`) | ||||||||||
| if (!confirmDevTerms) { | ||||||||||
| this.error('The Developer Terms of Service were declined') | ||||||||||
| } | ||||||||||
| const accepted = await consoleCLI.acceptDevTermsForOrg(orgId) | ||||||||||
| if (!accepted) { | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Re-raised]
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Re-raised]
Suggested change
|
||||||||||
| this.error('The Developer Terms of Service could not be accepted') | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Re-raised] The prompt string contains a literal
Suggested change
|
||||||||||
| } | ||||||||||
| this.log(`The Developer Terms of Service were successfully accepted for org ${orgId}`) | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * Set console config | ||||||||||
| * | ||||||||||
|
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The prompt string has a raw newline followed by
\nand 4 spaces of indentation, which will render as an extra blank line with leading whitespace in the terminal. Flatten to a single consistent separator.