@shopify/cli-kit 3.45.0-pre.5 → 3.45.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/README.md +2 -2
  2. package/assets/cli-ruby/lib/shopify_cli/api.rb +2 -3
  3. package/assets/cli-ruby/lib/shopify_cli/context.rb +4 -2
  4. package/assets/cli-ruby/lib/shopify_cli/messages/messages.rb +1 -1
  5. package/assets/cli-ruby/lib/shopify_cli/theme/dev_server/proxy.rb +6 -1
  6. package/dist/private/node/api/graphql.d.ts +5 -10
  7. package/dist/private/node/api/graphql.js +4 -16
  8. package/dist/private/node/api/graphql.js.map +1 -1
  9. package/dist/private/node/conf-store.d.ts +2 -1
  10. package/dist/private/node/conf-store.js +3 -2
  11. package/dist/private/node/conf-store.js.map +1 -1
  12. package/dist/private/node/session.d.ts +2 -2
  13. package/dist/private/node/session.js +4 -4
  14. package/dist/private/node/session.js.map +1 -1
  15. package/dist/private/node/ui/components/SelectPrompt.js +1 -1
  16. package/dist/private/node/ui/components/SelectPrompt.js.map +1 -1
  17. package/dist/private/node/ui/components/SelectPrompt.test.js +16 -0
  18. package/dist/private/node/ui/components/SelectPrompt.test.js.map +1 -1
  19. package/dist/public/common/version.d.ts +1 -1
  20. package/dist/public/common/version.js +1 -1
  21. package/dist/public/common/version.js.map +1 -1
  22. package/dist/public/node/api/admin.d.ts +1 -1
  23. package/dist/public/node/api/admin.js +10 -3
  24. package/dist/public/node/api/admin.js.map +1 -1
  25. package/dist/public/node/api/graphql.d.ts +27 -0
  26. package/dist/public/node/api/graphql.js +26 -0
  27. package/dist/public/node/api/graphql.js.map +1 -0
  28. package/dist/public/node/api/partners.d.ts +1 -1
  29. package/dist/public/node/api/partners.js +9 -2
  30. package/dist/public/node/api/partners.js.map +1 -1
  31. package/dist/public/node/crypto.d.ts +7 -0
  32. package/dist/public/node/crypto.js +9 -0
  33. package/dist/public/node/crypto.js.map +1 -1
  34. package/dist/public/node/environment.d.ts +12 -0
  35. package/dist/public/node/environment.js +17 -0
  36. package/dist/public/node/environment.js.map +1 -1
  37. package/dist/public/node/git.d.ts +15 -0
  38. package/dist/public/node/git.js +23 -0
  39. package/dist/public/node/git.js.map +1 -1
  40. package/dist/public/node/hooks/deprecations.js +1 -1
  41. package/dist/public/node/hooks/deprecations.js.map +1 -1
  42. package/dist/public/node/node-package-manager.js +14 -6
  43. package/dist/public/node/node-package-manager.js.map +1 -1
  44. package/dist/public/node/ruby.d.ts +7 -0
  45. package/dist/public/node/ruby.js +29 -8
  46. package/dist/public/node/ruby.js.map +1 -1
  47. package/dist/public/node/session.d.ts +2 -2
  48. package/dist/public/node/session.js +4 -4
  49. package/dist/public/node/session.js.map +1 -1
  50. package/dist/public/node/ui.d.ts +2 -1
  51. package/dist/public/node/ui.js +2 -1
  52. package/dist/public/node/ui.js.map +1 -1
  53. package/dist/tsconfig.tsbuildinfo +1 -1
  54. package/package.json +1 -1
  55. package/dist/public/node/api/oxygen.d.ts +0 -22
  56. package/dist/public/node/api/oxygen.js +0 -40
  57. package/dist/public/node/api/oxygen.js.map +0 -1
package/README.md CHANGED
@@ -54,8 +54,8 @@ Learn more in the docs: [Shopify CLI for Hydrogen storefronts](https://shopify.d
54
54
 
55
55
  If you encounter issues using the CLI or have feedback you'd like to share with us, below are some options:
56
56
 
57
- - [Open a GitHub issue](https://github.com/Shopify/cli/issues) - To report bugs or request new features, open an issue in the Shopify CLI repository.
58
- - [Shopify Community Forums](https://community.shopify.com/) - Visit our forums to connect with the community and learn more about Shopify CLI development.
57
+ - [Open a GitHub issue](https://github.com/Shopify/cli/issues) - To report bugs or request new features, open an issue in the Shopify CLI repository
58
+ - [Shopify Community Forums](https://community.shopify.com/) - Visit our forums to connect with the community and learn more about Shopify CLI development
59
59
  - [CLI Documentation - Apps](https://shopify.dev/apps/tools/cli) - To view CLI documentation for app development
60
60
  - [CLI Documentation - Themes](https://shopify.dev/themes/tools/cli) - To view CLI documentation for theme development
61
61
  - [CLI Documentation - Hydrogen](https://shopify.dev/custom-storefronts/tools/cli) - To view CLI documentation for Hydrogen (custom storefront) development
@@ -55,7 +55,6 @@ module ShopifyCLI
55
55
  # we delay this require so as to avoid a performance hit on starting the CLI
56
56
  require "shopify_cli/http_request"
57
57
  headers = default_headers.merge(headers)
58
- ctx.debug("#{method} #{uri} with X-Request-Id: #{headers["X-Request-Id"]}")
59
58
  response = if method == "POST"
60
59
  HttpRequest.post(uri, body, headers)
61
60
  elsif method == "PUT"
@@ -65,6 +64,7 @@ module ShopifyCLI
65
64
  elsif method == "DELETE"
66
65
  HttpRequest.delete(uri, body, headers)
67
66
  end
67
+ ctx.debug("#{method} #{uri} with request_id: #{response["x-request-id"]}")
68
68
  case response.code.to_i
69
69
  when 200..399
70
70
  [response.code.to_i, JSON.parse(response.body), response]
@@ -84,7 +84,7 @@ module ShopifyCLI
84
84
  raise APIRequestUnexpectedError.new("#{response.code}\n#{response.body}", response: response)
85
85
  end
86
86
  rescue Errno::ETIMEDOUT, Timeout::Error
87
- ctx.debug("timeout in #{method} #{uri} with X-Request-Id: #{headers["X-Request-Id"]}")
87
+ ctx.debug("timeout in #{method} #{uri}")
88
88
  raise APIRequestTimeoutError, "Timeout"
89
89
  end.retry_after(APIRequestRetriableError, retries: 3) do |e|
90
90
  sleep(1) if e.is_a?(APIRequestThrottledError)
@@ -117,7 +117,6 @@ module ShopifyCLI
117
117
  "User-Agent" => user_agent,
118
118
  "Sec-CH-UA" => sec_ch_ua,
119
119
  "Sec-CH-UA-PLATFORM" => ctx.os.to_s,
120
- "X-Request-Id" => SecureRandom.uuid,
121
120
  }.tap do |headers|
122
121
  headers["X-Shopify-Cli-Employee"] = "1" if Shopifolk.acting_as_shopify_organization?
123
122
  end.merge(auth_headers(token))
@@ -47,12 +47,14 @@ module ShopifyCLI
47
47
  str ? str % params : key
48
48
  end
49
49
 
50
- # a wrapper around Kernel.puts to allow for easy formatting
50
+ # a wrapper around $stdout.puts to allow for easy formatting
51
51
  #
52
52
  # #### Parameters
53
53
  # * `text` - a string message to output
54
54
  def puts(*args)
55
- Kernel.puts(CLI::UI.fmt(*args))
55
+ $stdout.puts(CLI::UI.fmt(*args)).tap do
56
+ $stdout.flush
57
+ end
56
58
  end
57
59
 
58
60
  # aborts the current running command and outputs an error message:
@@ -485,7 +485,7 @@ module ShopifyCLI
485
485
  error: {
486
486
  timeout: "Timed out while waiting for response from Shopify",
487
487
  local_identity_not_running: "Identity needs to be running locally in order to proceed.",
488
- reauthenticate: "Please login again with {{command:shopify login}}",
488
+ reauthenticate: "Please login again",
489
489
  invalid_destination: "The store %s doesn't exist. Please log out and try again.",
490
490
  },
491
491
 
@@ -28,7 +28,12 @@ module ShopifyCLI
28
28
  SESSION_COOKIE_NAME = "_secure_session_id"
29
29
  SESSION_COOKIE_REGEXP = /#{SESSION_COOKIE_NAME}=(\h+)/
30
30
  SESSION_COOKIE_MAX_AGE = 60 * 60 * 23 # 1 day - leeway of 1h
31
- IGNORED_ENDPOINTS = ["shopify/monorail", "mini-profiler-resources", "web-pixels-manager"]
31
+ IGNORED_ENDPOINTS = %w[
32
+ shopify/monorail
33
+ mini-profiler-resources
34
+ web-pixels-manager
35
+ wpm
36
+ ]
32
37
 
33
38
  def initialize(ctx, theme, param_builder)
34
39
  @ctx = ctx
@@ -1,10 +1,5 @@
1
- import { rawRequest, RequestDocument, Variables } from 'graphql-request';
2
- export interface GraphQLVariables {
3
- [key: string]: any;
4
- }
5
- export type GraphQLResponse<T> = Awaited<ReturnType<typeof rawRequest<T>>>;
6
- export interface GraphQLResponseOptions<T> {
7
- handleErrors?: boolean;
8
- onResponse?: (response: GraphQLResponse<T>) => void;
9
- }
10
- export declare function graphqlRequest<T>(query: RequestDocument, api: string, url: string, token: string, variables?: Variables, options?: GraphQLResponseOptions<T>): Promise<T>;
1
+ import { RequestDocument, Variables } from 'graphql-request';
2
+ export declare function debugLogRequestInfo<T>(api: string, query: RequestDocument, variables?: Variables, headers?: {
3
+ [key: string]: string;
4
+ }): void;
5
+ export declare function errorHandler<T>(api: string): (error: unknown) => Error | unknown;
@@ -1,20 +1,8 @@
1
- import { buildHeaders, httpsAgent, RequestClientError, sanitizedHeadersOutput } from './headers.js';
1
+ import { RequestClientError, sanitizedHeadersOutput } from './headers.js';
2
2
  import { stringifyMessage, outputContent, outputToken, outputDebug } from '../../../public/node/output.js';
3
3
  import { AbortError } from '../../../public/node/error.js';
4
- import { debugLogResponseInfo } from '../api.js';
5
- import { ClientError, GraphQLClient } from 'graphql-request';
6
- export async function graphqlRequest(query, api, url, token, variables, options) {
7
- const headers = buildHeaders(token);
8
- debugLogRequestInfo(api, query, variables, headers);
9
- const clientOptions = { agent: await httpsAgent(), headers };
10
- const client = new GraphQLClient(url, clientOptions);
11
- const response = await debugLogResponseInfo({ request: client.rawRequest(query, variables), url }, options?.handleErrors === false ? undefined : errorHandler(api));
12
- if (options?.onResponse) {
13
- options.onResponse(response);
14
- }
15
- return response.data;
16
- }
17
- function debugLogRequestInfo(api, query, variables, headers = {}) {
4
+ import { ClientError } from 'graphql-request';
5
+ export function debugLogRequestInfo(api, query, variables, headers = {}) {
18
6
  outputDebug(outputContent `Sending ${outputToken.json(api)} GraphQL request:
19
7
  ${outputToken.raw(query.toString().trim())}
20
8
  ${variables ? `\nWith variables:\n${JSON.stringify(variables, null, 2)}\n` : ''}
@@ -22,7 +10,7 @@ With request headers:
22
10
  ${sanitizedHeadersOutput(headers)}
23
11
  `);
24
12
  }
25
- function errorHandler(api) {
13
+ export function errorHandler(api) {
26
14
  return (error) => {
27
15
  if (error instanceof ClientError) {
28
16
  const errorMessage = stringifyMessage(outputContent `
@@ -1 +1 @@
1
- {"version":3,"file":"graphql.js","sourceRoot":"","sources":["../../../../src/private/node/api/graphql.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAE,UAAU,EAAE,kBAAkB,EAAE,sBAAsB,EAAC,MAAM,cAAc,CAAA;AACjG,OAAO,EAAC,gBAAgB,EAAE,aAAa,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SAAS,CAAC,CAAC,CAAC,sBAAsB,IAAI,CAAC,SAAS,CAAC,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE;;EAE7E,sBAAsB,CAAC,OAAO,CAAC;CAChC,CAAC,CAAA;AACF,CAAC;AAED,SAAS,YAAY,CAAI,GAAW;IAClC,OAAO,CAAC,KAAc,EAAE,EAAE;QACxB,IAAI,KAAK,YAAY,WAAW,EAAE;YAChC,MAAM,YAAY,GAAG,gBAAgB,CAAC,aAAa,CAAA;QACjD,WAAW,CAAC,GAAG,CACnB,GAAG,CACJ,8DAA8D,GAAG,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE;;IAEvF,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC;OACpC,CAAC,CAAA;YACF,IAAI,WAAkB,CAAA;YACtB,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,GAAG,GAAG,EAAE;gBAC/B,WAAW,GAAG,IAAI,kBAAkB,CAAC,YAAY,EAAE,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;aAC1E;iBAAM;gBACL,WAAW,GAAG,IAAI,UAAU,CAAC,YAAY,CAAC,CAAA;aAC3C;YACD,WAAW,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAA;YAC/B,OAAO,WAAW,CAAA;SACnB;aAAM;YACL,OAAO,KAAK,CAAA;SACb;IACH,CAAC,CAAA;AACH,CAAC","sourcesContent":["import {buildHeaders, httpsAgent, RequestClientError, sanitizedHeadersOutput} from './headers.js'\nimport {stringifyMessage, outputContent, outputToken, outputDebug} from '../../../public/node/output.js'\nimport {AbortError} from '../../../public/node/error.js'\nimport {debugLogResponseInfo} from '../api.js'\nimport {ClientError, GraphQLClient, rawRequest, RequestDocument, Variables} from 'graphql-request'\n\nexport interface GraphQLVariables {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n [key: string]: any\n}\n\nexport type GraphQLResponse<T> = Awaited<ReturnType<typeof rawRequest<T>>>\n\nexport interface GraphQLResponseOptions<T> {\n handleErrors?: boolean\n onResponse?: (response: GraphQLResponse<T>) => void\n}\n\nexport async function graphqlRequest<T>(\n query: RequestDocument,\n api: string,\n url: string,\n token: string,\n variables?: Variables,\n options?: GraphQLResponseOptions<T>,\n): Promise<T> {\n const headers = buildHeaders(token)\n debugLogRequestInfo(api, query, variables, headers)\n const clientOptions = {agent: await httpsAgent(), headers}\n const client = new GraphQLClient(url, clientOptions)\n const response = await debugLogResponseInfo(\n {request: client.rawRequest<T>(query as string, variables), url},\n options?.handleErrors === false ? undefined : errorHandler(api),\n )\n\n if (options?.onResponse) {\n options.onResponse(response)\n }\n\n return response.data\n}\n\nfunction debugLogRequestInfo<T>(\n api: string,\n query: RequestDocument,\n variables?: Variables,\n headers: {[key: string]: string} = {},\n) {\n outputDebug(outputContent`Sending ${outputToken.json(api)} GraphQL request:\n ${outputToken.raw(query.toString().trim())}\n${variables ? `\\nWith variables:\\n${JSON.stringify(variables, null, 2)}\\n` : ''}\nWith request headers:\n${sanitizedHeadersOutput(headers)}\n`)\n}\n\nfunction errorHandler<T>(api: string): (error: unknown) => Error | unknown {\n return (error: unknown) => {\n if (error instanceof ClientError) {\n const errorMessage = stringifyMessage(outputContent`\n The ${outputToken.raw(\n api,\n )} GraphQL API responded unsuccessfully with the HTTP status ${`${error.response.status}`} and errors:\n\n ${outputToken.json(error.response.errors)}\n `)\n let mappedError: Error\n if (error.response.status < 500) {\n mappedError = new RequestClientError(errorMessage, error.response.status)\n } else {\n mappedError = new AbortError(errorMessage)\n }\n mappedError.stack = error.stack\n return mappedError\n } else {\n return error\n }\n }\n}\n"]}
1
+ {"version":3,"file":"graphql.js","sourceRoot":"","sources":["../../../../src/private/node/api/graphql.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAE,sBAAsB,EAAC,MAAM,cAAc,CAAA;AACvE,OAAO,EAAC,gBAAgB,EAAE,aAAa,EAAE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B,OAAO,WAAW,CAAA;SACnB;aAAM;YACL,OAAO,KAAK,CAAA;SACb;IACH,CAAC,CAAA;AACH,CAAC","sourcesContent":["import {RequestClientError, sanitizedHeadersOutput} from './headers.js'\nimport {stringifyMessage, outputContent, outputToken, outputDebug} from '../../../public/node/output.js'\nimport {AbortError} from '../../../public/node/error.js'\nimport {ClientError, RequestDocument, Variables} from 'graphql-request'\n\nexport function debugLogRequestInfo<T>(\n api: string,\n query: RequestDocument,\n variables?: Variables,\n headers: {[key: string]: string} = {},\n) {\n outputDebug(outputContent`Sending ${outputToken.json(api)} GraphQL request:\n ${outputToken.raw(query.toString().trim())}\n${variables ? `\\nWith variables:\\n${JSON.stringify(variables, null, 2)}\\n` : ''}\nWith request headers:\n${sanitizedHeadersOutput(headers)}\n`)\n}\n\nexport function errorHandler<T>(api: string): (error: unknown) => Error | unknown {\n return (error: unknown) => {\n if (error instanceof ClientError) {\n const errorMessage = stringifyMessage(outputContent`\n The ${outputToken.raw(\n api,\n )} GraphQL API responded unsuccessfully with the HTTP status ${`${error.response.status}`} and errors:\n\n ${outputToken.json(error.response.errors)}\n `)\n let mappedError: Error\n if (error.response.status < 500) {\n mappedError = new RequestClientError(errorMessage, error.response.status)\n } else {\n mappedError = new AbortError(errorMessage)\n }\n mappedError.stack = error.stack\n return mappedError\n } else {\n return error\n }\n }\n}\n"]}
@@ -33,7 +33,8 @@ type CacheValueForKey<TKey extends keyof Cache> = NonNullable<Cache[TKey]>['valu
33
33
  * before returning it.
34
34
  * @param key - The key to use for the cache.
35
35
  * @param fn - The function to run to get the value to cache, if a cache miss occurs.
36
- * @param timeout - The maximum valid age of a cached value, in milliseconds. If the cached value is older than this, it will be refreshed.
36
+ * @param timeout - The maximum valid age of a cached value, in milliseconds.
37
+ * If the cached value is older than this, it will be refreshed.
37
38
  * @returns The value from the cache or the result of the function.
38
39
  */
39
40
  export declare function cacheRetrieveOrRepopulate(key: keyof Cache, fn: () => Promise<CacheValueForKey<typeof key>>, timeout?: number, config?: LocalStorage<ConfSchema>): Promise<CacheValueForKey<typeof key>>;
@@ -42,13 +42,14 @@ export function removeSession(config = cliKitStore()) {
42
42
  * before returning it.
43
43
  * @param key - The key to use for the cache.
44
44
  * @param fn - The function to run to get the value to cache, if a cache miss occurs.
45
- * @param timeout - The maximum valid age of a cached value, in milliseconds. If the cached value is older than this, it will be refreshed.
45
+ * @param timeout - The maximum valid age of a cached value, in milliseconds.
46
+ * If the cached value is older than this, it will be refreshed.
46
47
  * @returns The value from the cache or the result of the function.
47
48
  */
48
49
  export async function cacheRetrieveOrRepopulate(key, fn, timeout, config = cliKitStore()) {
49
50
  const cache = config.get('cache') || {};
50
51
  const cached = cache[key];
51
- if (cached && (timeout === undefined || Date.now() - cached.timestamp < timeout)) {
52
+ if (cached?.value !== undefined && (timeout === undefined || Date.now() - cached.timestamp < timeout)) {
52
53
  return cached.value;
53
54
  }
54
55
  const value = await fn();
@@ -1 +1 @@
1
- {"version":3,"file":"conf-store.js","sourceRoot":"","sources":["../../../src/private/node/conf-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,oCAAoC,CAAA;AAC/D,OAAO,EAAC,aAAa,EAAE,WAAW,EAAC,MAAM,8BAA8B,CAAA;AAkBvE,IAAI,SAA+C,CAAA;AAEnD;;;;GAIG;AACH,SAAS,WAAW;IAClB,IAAI,CAAC,SAAS,EAAE;QACd,SAAS,GAAG,IAAI,YAAY,CAAa,EAAC,WAAW,EAAE,iBAAiB,EAAC,CAAC,CAAA;KAC3E;IACD,OAAO,SAAS,CAAA;AAClB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,SAAmC,WAAW,EAAE;IACzE,WAAW,CAAC,aAAa,CAAA,0BAA0B,CAAC,CAAA;IACpD,OAAO,MAAM,CAAC,GAAG,CAAC,cAAc,CAAC,CAAA;AACnC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,OAAe,EAAE,SAAmC,WAAW,EAAE;IAC1F,WAAW,CAAC,aAAa,CAAA,0BAA0B,CAAC,CAAA;IACpD,MAAM,CAAC,GAAG,CAAC,cAAc,EAAE,OAAO,CAAC,CAAA;AACrC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,SAAmC,WAAW,EAAE;IAC5E,WAAW,CAAC,aAAa,CAAA,2BAA2B,CAAC,CAAA;IACrD,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,CAAA;AAC/B,CAAC;AAGD;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAC7C,GAAgB,EAChB,EAA+C,EAC/C,OAAgB,EAChB,MAAM,GAAG,WAAW,EAAE;IAEtB,MAAM,KAAK,GAAU,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,CAAA;IAC9C,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,CAAA;IAEzB,IAAI,MAAM,IAAI,CAAC,OAAO,KAAK,SAAS,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,SAAS,GAAG,OAAO,CAAC,EAAE;QAChF,OAAO,MAAM,CAAC,KAAK,CAAA;KACpB;IAED,MAAM,KAAK,GAAG,MAAM,EAAE,EAAE,CAAA;IACxB,KAAK,CAAC,GAAG,CAAC,GAAG,EAAC,KAAK,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,EAAC,CAAA;IAC3C,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;IAC1B,OAAO,KAAK,CAAA;AACd,CAAC","sourcesContent":["import {LocalStorage} from '../../public/node/local-storage.js'\nimport {outputContent, outputDebug} from '@shopify/cli-kit/node/output'\n\ninterface CacheValue<T> {\n value: T\n timestamp: number\n}\n\nexport type IntrospectionUrlKey = `identity-introspection-url-${string}`\n\ninterface Cache {\n [introspectionUrlKey: IntrospectionUrlKey]: CacheValue<string>\n}\n\nexport interface ConfSchema {\n sessionStore: string\n cache?: Cache\n}\n\nlet _instance: LocalStorage<ConfSchema> | undefined\n\n/**\n * CLIKIT Store.\n *\n * @returns CLIKitStore.\n */\nfunction cliKitStore() {\n if (!_instance) {\n _instance = new LocalStorage<ConfSchema>({projectName: 'shopify-cli-kit'})\n }\n return _instance\n}\n\n/**\n * Get session.\n *\n * @returns Session.\n */\nexport function getSession(config: LocalStorage<ConfSchema> = cliKitStore()): string | undefined {\n outputDebug(outputContent`Getting session store...`)\n return config.get('sessionStore')\n}\n\n/**\n * Set session.\n *\n * @param session - Session.\n */\nexport function setSession(session: string, config: LocalStorage<ConfSchema> = cliKitStore()): void {\n outputDebug(outputContent`Setting session store...`)\n config.set('sessionStore', session)\n}\n\n/**\n * Remove session.\n */\nexport function removeSession(config: LocalStorage<ConfSchema> = cliKitStore()): void {\n outputDebug(outputContent`Removing session store...`)\n config.delete('sessionStore')\n}\n\ntype CacheValueForKey<TKey extends keyof Cache> = NonNullable<Cache[TKey]>['value']\n/**\n * Fetch from cache, or run the provided function to get the value, and cache it\n * before returning it.\n * @param key - The key to use for the cache.\n * @param fn - The function to run to get the value to cache, if a cache miss occurs.\n * @param timeout - The maximum valid age of a cached value, in milliseconds. If the cached value is older than this, it will be refreshed.\n * @returns The value from the cache or the result of the function.\n */\nexport async function cacheRetrieveOrRepopulate(\n key: keyof Cache,\n fn: () => Promise<CacheValueForKey<typeof key>>,\n timeout?: number,\n config = cliKitStore(),\n): Promise<CacheValueForKey<typeof key>> {\n const cache: Cache = config.get('cache') || {}\n const cached = cache[key]\n\n if (cached && (timeout === undefined || Date.now() - cached.timestamp < timeout)) {\n return cached.value\n }\n\n const value = await fn()\n cache[key] = {value, timestamp: Date.now()}\n config.set('cache', cache)\n return value\n}\n"]}
1
+ {"version":3,"file":"conf-store.js","sourceRoot":"","sources":["../../../src/private/node/conf-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,oCAAoC,CAAA;AAC/D,OAAO,EAAC,aAAa,EAAE,W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AC,KAAK,CAAA;KACpB;IAED,MAAM,KAAK,GAAG,MAAM,EAAE,EAAE,CAAA;IACxB,KAAK,CAAC,GAAG,CAAC,GAAG,EAAC,KAAK,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,EAAC,CAAA;IAC3C,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;IAC1B,OAAO,KAAK,CAAA;AACd,CAAC","sourcesContent":["import {LocalStorage} from '../../public/node/local-storage.js'\nimport {outputContent, outputDebug} from '@shopify/cli-kit/node/output'\n\ninterface CacheValue<T> {\n value: T\n timestamp: number\n}\n\nexport type IntrospectionUrlKey = `identity-introspection-url-${string}`\n\ninterface Cache {\n [introspectionUrlKey: IntrospectionUrlKey]: CacheValue<string>\n}\n\nexport interface ConfSchema {\n sessionStore: string\n cache?: Cache\n}\n\nlet _instance: LocalStorage<ConfSchema> | undefined\n\n/**\n * CLIKIT Store.\n *\n * @returns CLIKitStore.\n */\nfunction cliKitStore() {\n if (!_instance) {\n _instance = new LocalStorage<ConfSchema>({projectName: 'shopify-cli-kit'})\n }\n return _instance\n}\n\n/**\n * Get session.\n *\n * @returns Session.\n */\nexport function getSession(config: LocalStorage<ConfSchema> = cliKitStore()): string | undefined {\n outputDebug(outputContent`Getting session store...`)\n return config.get('sessionStore')\n}\n\n/**\n * Set session.\n *\n * @param session - Session.\n */\nexport function setSession(session: string, config: LocalStorage<ConfSchema> = cliKitStore()): void {\n outputDebug(outputContent`Setting session store...`)\n config.set('sessionStore', session)\n}\n\n/**\n * Remove session.\n */\nexport function removeSession(config: LocalStorage<ConfSchema> = cliKitStore()): void {\n outputDebug(outputContent`Removing session store...`)\n config.delete('sessionStore')\n}\n\ntype CacheValueForKey<TKey extends keyof Cache> = NonNullable<Cache[TKey]>['value']\n/**\n * Fetch from cache, or run the provided function to get the value, and cache it\n * before returning it.\n * @param key - The key to use for the cache.\n * @param fn - The function to run to get the value to cache, if a cache miss occurs.\n * @param timeout - The maximum valid age of a cached value, in milliseconds.\n * If the cached value is older than this, it will be refreshed.\n * @returns The value from the cache or the result of the function.\n */\nexport async function cacheRetrieveOrRepopulate(\n key: keyof Cache,\n fn: () => Promise<CacheValueForKey<typeof key>>,\n timeout?: number,\n config = cliKitStore(),\n): Promise<CacheValueForKey<typeof key>> {\n const cache: Cache = config.get('cache') || {}\n const cached = cache[key]\n\n if (cached?.value !== undefined && (timeout === undefined || Date.now() - cached.timestamp < timeout)) {\n return cached.value\n }\n\n const value = await fn()\n cache[key] = {value, timestamp: Date.now()}\n config.set('cache', cache)\n return value\n}\n"]}
@@ -48,9 +48,9 @@ export interface OAuthSession {
48
48
  * This method ensures that we have a valid session to authenticate against the given applications using the provided scopes.
49
49
  *
50
50
  * @param applications - An object containing the applications we need to be authenticated with.
51
- * @param env - Optional environment variables to use.
51
+ * @param _env - Optional environment variables to use.
52
52
  * @param forceRefresh - Optional flag to force a refresh of the token.
53
53
  * @returns An instance with the access tokens organized by application.
54
54
  */
55
- export declare function ensureAuthenticated(applications: OAuthApplications, env?: NodeJS.ProcessEnv, forceRefresh?: boolean): Promise<OAuthSession>;
55
+ export declare function ensureAuthenticated(applications: OAuthApplications, _env?: NodeJS.ProcessEnv, forceRefresh?: boolean): Promise<OAuthSession>;
56
56
  export {};
@@ -6,7 +6,6 @@ import { authorize } from './session/authorize.js';
6
6
  import * as secureStore from './session/store.js';
7
7
  import { pollForDeviceAuthorization, requestDeviceAuthorization } from './session/device-authorization.js';
8
8
  import { RequestClientError } from './api/headers.js';
9
- import { environmentVariables } from './constants.js';
10
9
  import { outputContent, outputToken, outputDebug } from '../../public/node/output.js';
11
10
  import { firstPartyDev, useDeviceAuth } from '../../public/node/context/local.js';
12
11
  import { AbortError, BugError } from '../../public/node/error.js';
@@ -14,17 +13,18 @@ import { partnersRequest } from '../../public/node/api/partners.js';
14
13
  import { normalizeStoreFqdn, partnersFqdn, identityFqdn } from '../../public/node/context/fqdn.js';
15
14
  import { openURL } from '../../public/node/system.js';
16
15
  import { keypress } from '../../public/node/ui.js';
16
+ import { getPartnersToken } from '../../public/node/environment.js';
17
17
  import { gql } from 'graphql-request';
18
18
  import { outputCompleted, outputInfo, outputWarn } from '@shopify/cli-kit/node/output';
19
19
  /**
20
20
  * This method ensures that we have a valid session to authenticate against the given applications using the provided scopes.
21
21
  *
22
22
  * @param applications - An object containing the applications we need to be authenticated with.
23
- * @param env - Optional environment variables to use.
23
+ * @param _env - Optional environment variables to use.
24
24
  * @param forceRefresh - Optional flag to force a refresh of the token.
25
25
  * @returns An instance with the access tokens organized by application.
26
26
  */
27
- export async function ensureAuthenticated(applications, env = process.env, forceRefresh = false) {
27
+ export async function ensureAuthenticated(applications, _env, forceRefresh = false) {
28
28
  const fqdn = await identityFqdn();
29
29
  const previousStoreFqdn = applications.adminApi?.storeFqdn;
30
30
  if (previousStoreFqdn) {
@@ -71,7 +71,7 @@ ${outputToken.json(applications)}
71
71
  await secureStore.store(completeSession);
72
72
  const tokens = await tokensFor(applications, completeSession, fqdn);
73
73
  // Overwrite partners token if using a custom CLI Token
74
- const envToken = env[environmentVariables.partnersToken];
74
+ const envToken = getPartnersToken();
75
75
  if (envToken && applications.partnersApi) {
76
76
  tokens.partners = (await exchangeCustomPartnerToken(envToken)).accessToken;
77
77
  }
@@ -1 +1 @@
1
- {"version":3,"file":"session.js","sourceRoot":"","sources":["../../../src/private/node/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,uBAAuB,CAAA;AACnD,OAAO,EAAC,eAAe,EAAC,MAAM,uBAAuB,CAAA;AACrD,OAAO,EAAC,gBAAgB,EAAE,SAAS,EAAC,MAAM,qBAAqB,CAAA;AAC/D,OAAO,EACL,kCAAkC,EAClC,0BAA0B,EAC1B,0BAA0B,EAE1B,kBAAkB,EAClB,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAC,SAAS,EAAC,MAAM,wBAAwB,CAAA;AAEhD,OAAO,K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AG,UAAU,CAAC,CAAA;IAC7D,OAAO,gBAAgB,CAAC,eAAe,CAAC,CAAA;AAC1C,CAAC;AAED;;;;;GAKG;AACH,SAAS,iBAAiB,CAAC,IAAuB;IAChD,MAAM,UAAU,GAAG,IAAI,CAAC,QAAQ,EAAE,MAAM,IAAI,EAAE,CAAA;IAC9C,MAAM,YAAY,GAAG,IAAI,CAAC,WAAW,EAAE,MAAM,IAAI,EAAE,CAAA;IACnD,MAAM,gBAAgB,GAAG,IAAI,CAAC,qBAAqB,EAAE,MAAM,IAAI,EAAE,CAAA;IACjE,OAAO;QACL,KAAK,EAAE,SAAS,CAAC,OAAO,EAAE,UAAU,CAAC;QACrC,QAAQ,EAAE,SAAS,CAAC,UAAU,EAAE,YAAY,CAAC;QAC7C,UAAU,EAAE,SAAS,CAAC,qBAAqB,EAAE,gBAAgB,CAAC;KAC/D,CAAA;AACH,CAAC","sourcesContent":["import {applicationId} from './session/identity.js'\nimport {validateSession} from './session/validate.js'\nimport {allDefaultScopes, apiScopes} from './session/scopes.js'\nimport {\n exchangeAccessForApplicationTokens,\n exchangeCodeForAccessToken,\n exchangeCustomPartnerToken,\n ExchangeScopes,\n refreshAccessToken,\n InvalidGrantError,\n InvalidRequestError,\n} from './session/exchange.js'\nimport {authorize} from './session/authorize.js'\nimport {IdentityToken, Session} from './session/schema.js'\nimport * as secureStore from './session/store.js'\nimport {pollForDeviceAuthorization, requestDeviceAuthorization} from './session/device-authorization.js'\nimport {RequestClientError} from './api/headers.js'\nimport {environmentVariables} from './constants.js'\nimport {outputContent, outputToken, outputDebug} from '../../public/node/output.js'\nimport {firstPartyDev, useDeviceAuth} from '../../public/node/context/local.js'\nimport {AbortError, BugError} from '../../public/node/error.js'\nimport {partnersRequest} from '../../public/node/api/partners.js'\nimport {normalizeStoreFqdn, partnersFqdn, identityFqdn} from '../../public/node/context/fqdn.js'\nimport {openURL} from '../../public/node/system.js'\nimport {keypress} from '../../public/node/ui.js'\nimport {gql} from 'graphql-request'\nimport {AdminSession} from '@shopify/cli-kit/node/session'\nimport {outputCompleted, outputInfo, outputWarn} from '@shopify/cli-kit/node/output'\n\n/**\n * A scope supported by the Shopify Admin API.\n */\ntype AdminAPIScope = 'graphql' | 'themes' | 'collaborator' | string\n\n/**\n * It represents the options to authenticate against the Shopify Admin API.\n */\n\ninterface AdminAPIOAuthOptions {\n /** Store to request permissions for. */\n storeFqdn: string\n /** List of scopes to request permissions for. */\n scopes: AdminAPIScope[]\n}\n\n/**\n * A scope supported by the Partners API.\n */\ntype PartnersAPIScope = 'cli' | string\ninterface PartnersAPIOAuthOptions {\n /** List of scopes to request permissions for. */\n scopes: PartnersAPIScope[]\n}\n\n/**\n * A scope supported by the Storefront Renderer API.\n */\ntype StorefrontRendererScope = 'devtools' | string\ninterface StorefrontRendererAPIOAuthOptions {\n /** List of scopes to request permissions for. */\n scopes: StorefrontRendererScope[]\n}\n\n/**\n * It represents the authentication requirements and\n * is the input necessary to trigger the authentication\n * flow.\n */\nexport interface OAuthApplications {\n adminApi?: AdminAPIOAuthOptions\n storefrontRendererApi?: StorefrontRendererAPIOAuthOptions\n partnersApi?: PartnersAPIOAuthOptions\n}\n\nexport interface OAuthSession {\n admin?: AdminSession\n partners?: string\n storefront?: string\n}\n\n/**\n * This method ensures that we have a valid session to authenticate against the given applications using the provided scopes.\n *\n * @param applications - An object containing the applications we need to be authenticated with.\n * @param env - Optional environment variables to use.\n * @param forceRefresh - Optional flag to force a refresh of the token.\n * @returns An instance with the access tokens organized by application.\n */\nexport async function ensureAuthenticated(\n applications: OAuthApplications,\n env = process.env,\n forceRefresh = false,\n): Promise<OAuthSession> {\n const fqdn = await identityFqdn()\n\n const previousStoreFqdn = applications.adminApi?.storeFqdn\n if (previousStoreFqdn) {\n const normalizedStoreName = await normalizeStoreFqdn(previousStoreFqdn)\n if (previousStoreFqdn === applications.adminApi?.storeFqdn) {\n applications.adminApi.storeFqdn = normalizedStoreName\n }\n }\n\n const currentSession = (await secureStore.fetch()) || {}\n const fqdnSession = currentSession[fqdn]!\n const scopes = getFlattenScopes(applications)\n\n outputDebug(outputContent`Validating existing session against the scopes:\n${outputToken.json(scopes)}\nFor applications:\n${outputToken.json(applications)}\n`)\n const validationResult = await validateSession(scopes, applications, fqdnSession)\n\n let newSession = {}\n\n if (validationResult === 'needs_full_auth') {\n outputDebug(outputContent`Initiating the full authentication flow...`)\n newSession = await executeCompleteFlow(applications, fqdn)\n } else if (validationResult === 'needs_refresh' || forceRefresh) {\n outputDebug(outputContent`The current session is valid but needs refresh. Refreshing...`)\n try {\n newSession = await refreshTokens(fqdnSession.identity, applications, fqdn)\n } catch (error) {\n if (error instanceof InvalidGrantError) {\n newSession = await executeCompleteFlow(applications, fqdn)\n } else if (error instanceof InvalidRequestError) {\n await secureStore.remove()\n throw new AbortError('\\nError validating auth session', \"We've cleared the current session, please try again\")\n } else {\n throw error\n }\n }\n }\n\n const completeSession: Session = {...currentSession, ...newSession}\n // Save the new session info if it has changed\n if (Object.keys(newSession).length > 0) await secureStore.store(completeSession)\n const tokens = await tokensFor(applications, completeSession, fqdn)\n\n // Overwrite partners token if using a custom CLI Token\n const envToken = env[environmentVariables.partnersToken]\n if (envToken && applications.partnersApi) {\n tokens.partners = (await exchangeCustomPartnerToken(envToken)).accessToken\n }\n if (!envToken && tokens.partners) {\n await ensureUserHasPartnerAccount(tokens.partners)\n }\n\n return tokens\n}\n\n/**\n * Execute the full authentication flow.\n *\n * @param applications - An object containing the applications we need to be authenticated with.\n * @param identityFqdn - The identity FQDN.\n */\nasync function executeCompleteFlow(applications: OAuthApplications, identityFqdn: string): Promise<Session> {\n const scopes = getFlattenScopes(applications)\n const exchangeScopes = getExchangeScopes(applications)\n const store = applications.adminApi?.storeFqdn\n if (firstPartyDev()) {\n outputDebug(outputContent`Authenticating as Shopify Employee...`)\n scopes.push('employee')\n }\n\n let identityToken: IdentityToken\n if (useDeviceAuth()) {\n // Request a device code to authorize without a browser redirect.\n outputDebug(outputContent`Requesting device authorization code...`)\n const deviceAuth = await requestDeviceAuthorization(scopes)\n\n // Poll for the identity token\n outputDebug(outputContent`Starting polling for the identity token...`)\n identityToken = await pollForDeviceAuthorization(deviceAuth.deviceCode, deviceAuth.interval)\n } else {\n // Authorize user via browser\n outputDebug(outputContent`Authorizing through Identity's website...`)\n const code = await authorize(scopes)\n\n // Exchange code for identity token\n outputDebug(outputContent`Authorization code received. Exchanging it for a CLI token...`)\n identityToken = await exchangeCodeForAccessToken(code)\n }\n\n // Exchange identity token for application tokens\n outputDebug(outputContent`CLI token received. Exchanging it for application tokens...`)\n const result = await exchangeAccessForApplicationTokens(identityToken, exchangeScopes, store)\n\n const session: Session = {\n [identityFqdn]: {\n identity: identityToken,\n applications: result,\n },\n }\n\n outputCompleted('Logged in.')\n\n return session\n}\n\n/**\n * If the user creates an account from the Identity website, the created\n * account won't get a Partner organization created. We need to detect that\n * and take the user to create a partner organization.\n *\n * @param partnersToken - Partners token.\n */\nasync function ensureUserHasPartnerAccount(partnersToken: string) {\n outputDebug(outputContent`Verifying that the user has a Partner organization`)\n if (!(await hasPartnerAccount(partnersToken))) {\n outputInfo(`\\nA Shopify Partners organization is needed to proceed.`)\n outputInfo(`👉 Press any key to create one`)\n await keypress()\n await openURL(`https://${await partnersFqdn()}/signup`)\n outputInfo(outputContent`👉 Press any key when you have ${outputToken.cyan('created the organization')}`)\n outputWarn(outputContent`Make sure you've confirmed your Shopify and the Partner organization from the email`)\n await keypress()\n if (!(await hasPartnerAccount(partnersToken))) {\n throw new AbortError(\n `Couldn't find your Shopify Partners organization`,\n `Have you confirmed your accounts from the emails you received?`,\n )\n }\n }\n}\n\nconst getFirstOrganization = gql`\n {\n organizations(first: 1) {\n nodes {\n id\n }\n }\n }\n`\n\n/**\n * Validate if the current token is valid for partners API.\n *\n * @param partnersToken - Partners token.\n * @returns A promise that resolves to true if the token is valid for partners API.\n */\nasync function hasPartnerAccount(partnersToken: string): Promise<boolean> {\n try {\n await partnersRequest(getFirstOrganization, partnersToken)\n return true\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch (error) {\n if (error instanceof RequestClientError && error.statusCode === 404) {\n return false\n } else {\n return true\n }\n }\n}\n\n/**\n * Refresh the tokens for a given session.\n *\n * @param token - Identity token.\n * @param applications - An object containing the applications we need to be authenticated with.\n * @param fqdn - The identity FQDN.\n */\nasync function refreshTokens(token: IdentityToken, applications: OAuthApplications, fqdn: string): Promise<Session> {\n // Refresh Identity Token\n const identityToken = await refreshAccessToken(token)\n // Exchange new identity token for application tokens\n const exchangeScopes = getExchangeScopes(applications)\n const applicationTokens = await exchangeAccessForApplicationTokens(\n identityToken,\n exchangeScopes,\n applications.adminApi?.storeFqdn,\n )\n\n return {\n [fqdn]: {\n identity: identityToken,\n applications: applicationTokens,\n },\n }\n}\n\n/**\n * Get the application tokens for a given session.\n *\n * @param applications - An object containing the applications we need the tokens for.\n * @param session - The current session.\n * @param fqdn - The identity FQDN.\n */\nasync function tokensFor(applications: OAuthApplications, session: Session, fqdn: string): Promise<OAuthSession> {\n const fqdnSession = session[fqdn]\n if (!fqdnSession) {\n throw new BugError('No session found after ensuring authenticated')\n }\n const tokens: OAuthSession = {}\n if (applications.adminApi) {\n const appId = applicationId('admin')\n const realAppId = `${applications.adminApi.storeFqdn}-${appId}`\n const token = fqdnSession.applications[realAppId]?.accessToken\n if (token) {\n tokens.admin = {token, storeFqdn: applications.adminApi.storeFqdn}\n }\n }\n\n if (applications.partnersApi) {\n const appId = applicationId('partners')\n tokens.partners = fqdnSession.applications[appId]?.accessToken\n }\n\n if (applications.storefrontRendererApi) {\n const appId = applicationId('storefront-renderer')\n tokens.storefront = fqdnSession.applications[appId]?.accessToken\n }\n return tokens\n}\n\n// Scope Helpers\n/**\n * Get a flattened array of scopes for the given applications.\n *\n * @param apps - An object containing the applications we need the scopes for.\n * @returns A flattened array of scopes.\n */\nfunction getFlattenScopes(apps: OAuthApplications): string[] {\n const admin = apps.adminApi?.scopes || []\n const partner = apps.partnersApi?.scopes || []\n const storefront = apps.storefrontRendererApi?.scopes || []\n const requestedScopes = [...admin, ...partner, ...storefront]\n return allDefaultScopes(requestedScopes)\n}\n\n/**\n * Get the scopes for the given applications.\n *\n * @param apps - An object containing the applications we need the scopes for.\n * @returns An object containing the scopes for each application.\n */\nfunction getExchangeScopes(apps: OAuthApplications): ExchangeScopes {\n const adminScope = apps.adminApi?.scopes || []\n const partnerScope = apps.partnersApi?.scopes || []\n const storefrontScopes = apps.storefrontRendererApi?.scopes || []\n return {\n admin: apiScopes('admin', adminScope),\n partners: apiScopes('partners', partnerScope),\n storefront: apiScopes('storefront-renderer', storefrontScopes),\n }\n}\n"]}
1
+ {"version":3,"file":"session.js","sourceRoot":"","sources":["../../../src/private/node/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,uBAAuB,CAAA;AACnD,OAAO,EAAC,eAAe,EAAC,MAAM,uBAAuB,CAAA;AACrD,OAAO,EAAC,gBAAgB,EAAE,SAAS,EAAC,MAAM,qBAAqB,CAAA;AAC/D,OAAO,EACL,kCAAkC,EAClC,0BAA0B,EAC1B,0BAA0B,EAE1B,kBAAkB,EAClB,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAC,SAAS,EAAC,MAAM,wBAAwB,CAAA;AAEhD,OAAO,KAAK,WAAW,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAC,0BAA0B,EAAE,0BAA0B,EAAC,MAAM,mCAAmC,CAAA;AACxG,OAAO,EAAC,kBAAkB,EAAC,MAAM,kBAAkB,CAAA;AACnD,OAAO,EAAC,aAAa,EAAE,WAAW,EAAE,WAAW,EAAC,MAAM,6BAA6B,CAAA;AACnF,OAAO,EAAC,aAAa,EAAE,aAAa,EAAC,MAAM,oCAAoC,CAAA;AAC/E,OAAO,EAAC,UAAU,EAAE,QAAQ,EAAC,MAAM,4BAA4B,CAAA;AAC/D,OAAO,EAAC,eAAe,EAAC,MAAM,mCAAmC,CAAA;AACjE,O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,YAAY,CAAC;QAC7C,UAAU,EAAE,SAAS,CAAC,qBAAqB,EAAE,gBAAgB,CAAC;KAC/D,CAAA;AACH,CAAC","sourcesContent":["import {applicationId} from './session/identity.js'\nimport {validateSession} from './session/validate.js'\nimport {allDefaultScopes, apiScopes} from './session/scopes.js'\nimport {\n exchangeAccessForApplicationTokens,\n exchangeCodeForAccessToken,\n exchangeCustomPartnerToken,\n ExchangeScopes,\n refreshAccessToken,\n InvalidGrantError,\n InvalidRequestError,\n} from './session/exchange.js'\nimport {authorize} from './session/authorize.js'\nimport {IdentityToken, Session} from './session/schema.js'\nimport * as secureStore from './session/store.js'\nimport {pollForDeviceAuthorization, requestDeviceAuthorization} from './session/device-authorization.js'\nimport {RequestClientError} from './api/headers.js'\nimport {outputContent, outputToken, outputDebug} from '../../public/node/output.js'\nimport {firstPartyDev, useDeviceAuth} from '../../public/node/context/local.js'\nimport {AbortError, BugError} from '../../public/node/error.js'\nimport {partnersRequest} from '../../public/node/api/partners.js'\nimport {normalizeStoreFqdn, partnersFqdn, identityFqdn} from '../../public/node/context/fqdn.js'\nimport {openURL} from '../../public/node/system.js'\nimport {keypress} from '../../public/node/ui.js'\nimport {getPartnersToken} from '../../public/node/environment.js'\nimport {gql} from 'graphql-request'\nimport {AdminSession} from '@shopify/cli-kit/node/session'\nimport {outputCompleted, outputInfo, outputWarn} from '@shopify/cli-kit/node/output'\n\n/**\n * A scope supported by the Shopify Admin API.\n */\ntype AdminAPIScope = 'graphql' | 'themes' | 'collaborator' | string\n\n/**\n * It represents the options to authenticate against the Shopify Admin API.\n */\n\ninterface AdminAPIOAuthOptions {\n /** Store to request permissions for. */\n storeFqdn: string\n /** List of scopes to request permissions for. */\n scopes: AdminAPIScope[]\n}\n\n/**\n * A scope supported by the Partners API.\n */\ntype PartnersAPIScope = 'cli' | string\ninterface PartnersAPIOAuthOptions {\n /** List of scopes to request permissions for. */\n scopes: PartnersAPIScope[]\n}\n\n/**\n * A scope supported by the Storefront Renderer API.\n */\ntype StorefrontRendererScope = 'devtools' | string\ninterface StorefrontRendererAPIOAuthOptions {\n /** List of scopes to request permissions for. */\n scopes: StorefrontRendererScope[]\n}\n\n/**\n * It represents the authentication requirements and\n * is the input necessary to trigger the authentication\n * flow.\n */\nexport interface OAuthApplications {\n adminApi?: AdminAPIOAuthOptions\n storefrontRendererApi?: StorefrontRendererAPIOAuthOptions\n partnersApi?: PartnersAPIOAuthOptions\n}\n\nexport interface OAuthSession {\n admin?: AdminSession\n partners?: string\n storefront?: string\n}\n\n/**\n * This method ensures that we have a valid session to authenticate against the given applications using the provided scopes.\n *\n * @param applications - An object containing the applications we need to be authenticated with.\n * @param _env - Optional environment variables to use.\n * @param forceRefresh - Optional flag to force a refresh of the token.\n * @returns An instance with the access tokens organized by application.\n */\nexport async function ensureAuthenticated(\n applications: OAuthApplications,\n _env?: NodeJS.ProcessEnv,\n forceRefresh = false,\n): Promise<OAuthSession> {\n const fqdn = await identityFqdn()\n\n const previousStoreFqdn = applications.adminApi?.storeFqdn\n if (previousStoreFqdn) {\n const normalizedStoreName = await normalizeStoreFqdn(previousStoreFqdn)\n if (previousStoreFqdn === applications.adminApi?.storeFqdn) {\n applications.adminApi.storeFqdn = normalizedStoreName\n }\n }\n\n const currentSession = (await secureStore.fetch()) || {}\n const fqdnSession = currentSession[fqdn]!\n const scopes = getFlattenScopes(applications)\n\n outputDebug(outputContent`Validating existing session against the scopes:\n${outputToken.json(scopes)}\nFor applications:\n${outputToken.json(applications)}\n`)\n const validationResult = await validateSession(scopes, applications, fqdnSession)\n\n let newSession = {}\n\n if (validationResult === 'needs_full_auth') {\n outputDebug(outputContent`Initiating the full authentication flow...`)\n newSession = await executeCompleteFlow(applications, fqdn)\n } else if (validationResult === 'needs_refresh' || forceRefresh) {\n outputDebug(outputContent`The current session is valid but needs refresh. Refreshing...`)\n try {\n newSession = await refreshTokens(fqdnSession.identity, applications, fqdn)\n } catch (error) {\n if (error instanceof InvalidGrantError) {\n newSession = await executeCompleteFlow(applications, fqdn)\n } else if (error instanceof InvalidRequestError) {\n await secureStore.remove()\n throw new AbortError('\\nError validating auth session', \"We've cleared the current session, please try again\")\n } else {\n throw error\n }\n }\n }\n\n const completeSession: Session = {...currentSession, ...newSession}\n // Save the new session info if it has changed\n if (Object.keys(newSession).length > 0) await secureStore.store(completeSession)\n const tokens = await tokensFor(applications, completeSession, fqdn)\n\n // Overwrite partners token if using a custom CLI Token\n const envToken = getPartnersToken()\n if (envToken && applications.partnersApi) {\n tokens.partners = (await exchangeCustomPartnerToken(envToken)).accessToken\n }\n if (!envToken && tokens.partners) {\n await ensureUserHasPartnerAccount(tokens.partners)\n }\n\n return tokens\n}\n\n/**\n * Execute the full authentication flow.\n *\n * @param applications - An object containing the applications we need to be authenticated with.\n * @param identityFqdn - The identity FQDN.\n */\nasync function executeCompleteFlow(applications: OAuthApplications, identityFqdn: string): Promise<Session> {\n const scopes = getFlattenScopes(applications)\n const exchangeScopes = getExchangeScopes(applications)\n const store = applications.adminApi?.storeFqdn\n if (firstPartyDev()) {\n outputDebug(outputContent`Authenticating as Shopify Employee...`)\n scopes.push('employee')\n }\n\n let identityToken: IdentityToken\n if (useDeviceAuth()) {\n // Request a device code to authorize without a browser redirect.\n outputDebug(outputContent`Requesting device authorization code...`)\n const deviceAuth = await requestDeviceAuthorization(scopes)\n\n // Poll for the identity token\n outputDebug(outputContent`Starting polling for the identity token...`)\n identityToken = await pollForDeviceAuthorization(deviceAuth.deviceCode, deviceAuth.interval)\n } else {\n // Authorize user via browser\n outputDebug(outputContent`Authorizing through Identity's website...`)\n const code = await authorize(scopes)\n\n // Exchange code for identity token\n outputDebug(outputContent`Authorization code received. Exchanging it for a CLI token...`)\n identityToken = await exchangeCodeForAccessToken(code)\n }\n\n // Exchange identity token for application tokens\n outputDebug(outputContent`CLI token received. Exchanging it for application tokens...`)\n const result = await exchangeAccessForApplicationTokens(identityToken, exchangeScopes, store)\n\n const session: Session = {\n [identityFqdn]: {\n identity: identityToken,\n applications: result,\n },\n }\n\n outputCompleted('Logged in.')\n\n return session\n}\n\n/**\n * If the user creates an account from the Identity website, the created\n * account won't get a Partner organization created. We need to detect that\n * and take the user to create a partner organization.\n *\n * @param partnersToken - Partners token.\n */\nasync function ensureUserHasPartnerAccount(partnersToken: string) {\n outputDebug(outputContent`Verifying that the user has a Partner organization`)\n if (!(await hasPartnerAccount(partnersToken))) {\n outputInfo(`\\nA Shopify Partners organization is needed to proceed.`)\n outputInfo(`👉 Press any key to create one`)\n await keypress()\n await openURL(`https://${await partnersFqdn()}/signup`)\n outputInfo(outputContent`👉 Press any key when you have ${outputToken.cyan('created the organization')}`)\n outputWarn(outputContent`Make sure you've confirmed your Shopify and the Partner organization from the email`)\n await keypress()\n if (!(await hasPartnerAccount(partnersToken))) {\n throw new AbortError(\n `Couldn't find your Shopify Partners organization`,\n `Have you confirmed your accounts from the emails you received?`,\n )\n }\n }\n}\n\nconst getFirstOrganization = gql`\n {\n organizations(first: 1) {\n nodes {\n id\n }\n }\n }\n`\n\n/**\n * Validate if the current token is valid for partners API.\n *\n * @param partnersToken - Partners token.\n * @returns A promise that resolves to true if the token is valid for partners API.\n */\nasync function hasPartnerAccount(partnersToken: string): Promise<boolean> {\n try {\n await partnersRequest(getFirstOrganization, partnersToken)\n return true\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch (error) {\n if (error instanceof RequestClientError && error.statusCode === 404) {\n return false\n } else {\n return true\n }\n }\n}\n\n/**\n * Refresh the tokens for a given session.\n *\n * @param token - Identity token.\n * @param applications - An object containing the applications we need to be authenticated with.\n * @param fqdn - The identity FQDN.\n */\nasync function refreshTokens(token: IdentityToken, applications: OAuthApplications, fqdn: string): Promise<Session> {\n // Refresh Identity Token\n const identityToken = await refreshAccessToken(token)\n // Exchange new identity token for application tokens\n const exchangeScopes = getExchangeScopes(applications)\n const applicationTokens = await exchangeAccessForApplicationTokens(\n identityToken,\n exchangeScopes,\n applications.adminApi?.storeFqdn,\n )\n\n return {\n [fqdn]: {\n identity: identityToken,\n applications: applicationTokens,\n },\n }\n}\n\n/**\n * Get the application tokens for a given session.\n *\n * @param applications - An object containing the applications we need the tokens for.\n * @param session - The current session.\n * @param fqdn - The identity FQDN.\n */\nasync function tokensFor(applications: OAuthApplications, session: Session, fqdn: string): Promise<OAuthSession> {\n const fqdnSession = session[fqdn]\n if (!fqdnSession) {\n throw new BugError('No session found after ensuring authenticated')\n }\n const tokens: OAuthSession = {}\n if (applications.adminApi) {\n const appId = applicationId('admin')\n const realAppId = `${applications.adminApi.storeFqdn}-${appId}`\n const token = fqdnSession.applications[realAppId]?.accessToken\n if (token) {\n tokens.admin = {token, storeFqdn: applications.adminApi.storeFqdn}\n }\n }\n\n if (applications.partnersApi) {\n const appId = applicationId('partners')\n tokens.partners = fqdnSession.applications[appId]?.accessToken\n }\n\n if (applications.storefrontRendererApi) {\n const appId = applicationId('storefront-renderer')\n tokens.storefront = fqdnSession.applications[appId]?.accessToken\n }\n return tokens\n}\n\n// Scope Helpers\n/**\n * Get a flattened array of scopes for the given applications.\n *\n * @param apps - An object containing the applications we need the scopes for.\n * @returns A flattened array of scopes.\n */\nfunction getFlattenScopes(apps: OAuthApplications): string[] {\n const admin = apps.adminApi?.scopes || []\n const partner = apps.partnersApi?.scopes || []\n const storefront = apps.storefrontRendererApi?.scopes || []\n const requestedScopes = [...admin, ...partner, ...storefront]\n return allDefaultScopes(requestedScopes)\n}\n\n/**\n * Get the scopes for the given applications.\n *\n * @param apps - An object containing the applications we need the scopes for.\n * @returns An object containing the scopes for each application.\n */\nfunction getExchangeScopes(apps: OAuthApplications): ExchangeScopes {\n const adminScope = apps.adminApi?.scopes || []\n const partnerScope = apps.partnersApi?.scopes || []\n const storefrontScopes = apps.storefrontRendererApi?.scopes || []\n return {\n admin: apiScopes('admin', adminScope),\n partners: apiScopes('partners', partnerScope),\n storefront: apiScopes('storefront-renderer', storefrontScopes),\n }\n}\n"]}
@@ -13,7 +13,7 @@ function SelectPrompt({ message, choices, infoTable, onSubmit, defaultValue, sub
13
13
  if (choices.length === 0) {
14
14
  throw new Error('SelectPrompt requires at least one choice');
15
15
  }
16
- const initialValue = defaultValue ? choices.find((choice) => choice.value === defaultValue) : undefined;
16
+ const initialValue = typeof defaultValue === 'undefined' ? undefined : choices.find((choice) => choice.value === defaultValue);
17
17
  const [answer, setAnswer] = useState(undefined);
18
18
  const { exit: unmountInk } = useApp();
19
19
  const [submitted, setSubmitted] = useState(false);
@@ -1 +1 @@
1
- {"version":3,"file":"SelectPrompt.js","sourceRoot":"","sources":["../../../../../src/private/node/ui/components/SelectPrompt.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAuC,MAAM,kBAAkB,CAAA;AAClF,OAAO,EAAC,SAAS,EAAiB,MAAM,wBAAwB,CAAA;AAChE,OAAO,EAAoC,aAAa,EAAC,MAAM,oBAAoB,CAAA;AACnF,OAAO,EAAC,WAAW,EAAC,MAAM,aAAa,CAAA;AACvC,OAAO,EAAC,sBAAsB,EAAC,MAAM,iBAAiB,CAAA;AACtD,OAAO,EAAC,MAAM,EAAC,MAAM,oCAAoC,CAAA;AACzD,OAAO,KAAK,EAAE,EAAe,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAC,MAAM,OAAO,CAAA;AAC3E,OAAO,EAAC,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAC,MAAM,KAAK,CAAA;AAC1E,OAAO,OAAO,MAAM,SAAS,CAAA;AAC7B,OAAO,WAAW,MAAM,cAAc,CAAA;AAWtC,+DAA+D;AAC/D,SAAS,YAAY,CAAI,EACvB,OAAO,EACP,OAAO,EACP,SAAS,EACT,QAAQ,EACR,YAAY,EACZ,mBAAmB,GAAG,KAAK,GACmB;IAC9C,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE;QACxB,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAA;KAC7D;IACD,MAAM,YAAY,GAAG,YAAY,CAAC,CAAC,C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AAC,IAAI,EAAE,YAAY,EAAC,EAAE,EAAE;oBACjC,SAAS,CAAC,IAAI,CAAC,CAAA;oBAEf,IAAI,mBAAmB,IAAI,YAAY,IAAI,IAAI,EAAE;wBAC/C,YAAY,CAAC,IAAI,CAAC,CAAA;qBACnB;gBACH,CAAC,EACD,KAAK,EAAE,KAAK,EACZ,GAAG,EAAE,QAAQ,GACb,CACE,CACP,CACG,CACP,CAAA;AACH,CAAC;AAED,OAAO,EAAC,YAAY,EAAC,CAAA","sourcesContent":["import {SelectInput, SelectInputProps, Item as SelectItem} from './SelectInput.js'\nimport {InfoTable, InfoTableProps} from './Prompts/InfoTable.js'\nimport {InlineToken, LinkToken, TokenItem, TokenizedText} from './TokenizedText.js'\nimport {handleCtrlC} from '../../ui.js'\nimport {messageWithPunctuation} from '../utilities.js'\nimport {uniqBy} from '../../../../public/common/array.js'\nimport React, {ReactElement, useCallback, useEffect, useState} from 'react'\nimport {Box, measureElement, Text, useApp, useInput, useStdout} from 'ink'\nimport figures from 'figures'\nimport ansiEscapes from 'ansi-escapes'\n\nexport interface SelectPromptProps<T> {\n message: TokenItem<Exclude<InlineToken, LinkToken>>\n choices: SelectInputProps<T>['items']\n onSubmit: (value: T) => void\n infoTable?: InfoTableProps['table']\n defaultValue?: T\n submitWithShortcuts?: boolean\n}\n\n// eslint-disable-next-line react/function-component-definition\nfunction SelectPrompt<T>({\n message,\n choices,\n infoTable,\n onSubmit,\n defaultValue,\n submitWithShortcuts = false,\n}: React.PropsWithChildren<SelectPromptProps<T>>): ReactElement | null {\n if (choices.length === 0) {\n throw new Error('SelectPrompt requires at least one choice')\n }\n const initialValue = defaultValue ? choices.find((choice) => choice.value === defaultValue) : undefined\n const [answer, setAnswer] = useState<SelectItem<T> | undefined>(undefined)\n const {exit: unmountInk} = useApp()\n const [submitted, setSubmitted] = useState(false)\n const {stdout} = useStdout()\n const [wrapperHeight, setWrapperHeight] = useState(0)\n const [selectInputHeight, setSelectInputHeight] = useState(0)\n const [limit, setLimit] = useState(choices.length)\n const numberOfGroups = uniqBy(\n choices.filter((choice) => choice.group),\n 'group',\n ).length\n\n const wrapperRef = useCallback((node) => {\n if (node !== null) {\n const {height} = measureElement(node)\n setWrapperHeight(height)\n }\n }, [])\n\n const inputRef = useCallback((node) => {\n if (node !== null) {\n const {height} = measureElement(node)\n setSelectInputHeight(height)\n }\n }, [])\n\n useEffect(() => {\n function onResize() {\n const availableSpace = stdout.rows - (wrapperHeight - selectInputHeight)\n // rough estimate of the limit needed based on the space available\n const newLimit = Math.max(2, availableSpace - numberOfGroups * 2 - 6)\n\n if (newLimit < limit) {\n stdout.write(ansiEscapes.clearTerminal)\n }\n\n setLimit(Math.min(newLimit, choices.length))\n }\n\n onResize()\n\n stdout.on('resize', onResize)\n return () => {\n stdout.off('resize', onResize)\n }\n }, [wrapperHeight, selectInputHeight, choices.length, numberOfGroups, stdout, limit])\n\n const submitAnswer = useCallback(\n (answer: SelectItem<T>) => {\n if (stdout && wrapperHeight >= stdout.rows) {\n stdout.write(ansiEscapes.clearTerminal)\n }\n setSubmitted(true)\n unmountInk()\n onSubmit(answer.value)\n },\n [stdout, wrapperHeight, unmountInk, onSubmit],\n )\n\n useInput((input, key) => {\n handleCtrlC(input, key)\n\n if (key.return && answer) {\n submitAnswer(answer)\n }\n })\n\n return (\n <Box flexDirection=\"column\" marginBottom={1} ref={wrapperRef}>\n <Box>\n <Box marginRight={2}>\n <Text>?</Text>\n </Box>\n <TokenizedText item={messageWithPunctuation(message)} />\n </Box>\n {infoTable && !submitted ? (\n <Box marginLeft={7} marginTop={1}>\n <InfoTable table={infoTable} />\n </Box>\n ) : null}\n {submitted ? (\n <Box>\n <Box marginRight={2}>\n <Text color=\"cyan\">{figures.tick}</Text>\n </Box>\n\n <Text color=\"cyan\">{answer!.label}</Text>\n </Box>\n ) : (\n <Box marginTop={1}>\n <SelectInput\n defaultValue={initialValue}\n items={choices}\n infoMessage={\n submitWithShortcuts\n ? `Press ${figures.arrowUp}${figures.arrowDown} arrows to select, enter or a shortcut to confirm`\n : undefined\n }\n onChange={({item, usedShortcut}) => {\n setAnswer(item)\n\n if (submitWithShortcuts && usedShortcut && item) {\n submitAnswer(item)\n }\n }}\n limit={limit}\n ref={inputRef}\n />\n </Box>\n )}\n </Box>\n )\n}\n\nexport {SelectPrompt}\n"]}
1
+ {"version":3,"file":"SelectPrompt.js","sourceRoot":"","sources":["../../../../../src/private/node/ui/components/SelectPrompt.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAuC,MAAM,kBAAkB,CAAA;AAClF,OAAO,EAAC,SAAS,EAAiB,MAAM,wBAAwB,CAAA;AAChE,OAAO,EAAoC,aAAa,EAAC,MAAM,oBAAoB,CAAA;AACnF,OAAO,EAAC,WAAW,EAAC,MAAM,aAAa,CAAA;AACvC,OAAO,EAAC,sBAAsB,EAAC,MAAM,iBAAiB,CAAA;AACtD,OAAO,EAAC,MAAM,EAAC,MAAM,oCAAoC,CAAA;AACzD,OAAO,KAAK,EAAE,EAAe,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAC,MAAM,OAAO,CAAA;AAC3E,OAAO,EAAC,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAC,MAAM,KAAK,CAAA;AAC1E,OAAO,OAAO,MAAM,SAAS,CAAA;AAC7B,OAAO,WAAW,MAAM,cAAc,CAAA;AAWtC,+DAA+D;AAC/D,SAAS,YAAY,CAAI,EACvB,OAAO,EACP,OAAO,EACP,SAAS,EACT,QAAQ,EACR,YAAY,EACZ,mBAAmB,GAAG,KAAK,GACmB;IAC9C,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE;QACxB,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAA;KAC7D;IACD,MAAM,YAAY,GAChB,OAAO,YAAY,KAAK,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MA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IAAI,CAAC,CAAA;oBAEf,IAAI,mBAAmB,IAAI,YAAY,IAAI,IAAI,EAAE;wBAC/C,YAAY,CAAC,IAAI,CAAC,CAAA;qBACnB;gBACH,CAAC,EACD,KAAK,EAAE,KAAK,EACZ,GAAG,EAAE,QAAQ,GACb,CACE,CACP,CACG,CACP,CAAA;AACH,CAAC;AAED,OAAO,EAAC,YAAY,EAAC,CAAA","sourcesContent":["import {SelectInput, SelectInputProps, Item as SelectItem} from './SelectInput.js'\nimport {InfoTable, InfoTableProps} from './Prompts/InfoTable.js'\nimport {InlineToken, LinkToken, TokenItem, TokenizedText} from './TokenizedText.js'\nimport {handleCtrlC} from '../../ui.js'\nimport {messageWithPunctuation} from '../utilities.js'\nimport {uniqBy} from '../../../../public/common/array.js'\nimport React, {ReactElement, useCallback, useEffect, useState} from 'react'\nimport {Box, measureElement, Text, useApp, useInput, useStdout} from 'ink'\nimport figures from 'figures'\nimport ansiEscapes from 'ansi-escapes'\n\nexport interface SelectPromptProps<T> {\n message: TokenItem<Exclude<InlineToken, LinkToken>>\n choices: SelectInputProps<T>['items']\n onSubmit: (value: T) => void\n infoTable?: InfoTableProps['table']\n defaultValue?: T\n submitWithShortcuts?: boolean\n}\n\n// eslint-disable-next-line react/function-component-definition\nfunction SelectPrompt<T>({\n message,\n choices,\n infoTable,\n onSubmit,\n defaultValue,\n submitWithShortcuts = false,\n}: React.PropsWithChildren<SelectPromptProps<T>>): ReactElement | null {\n if (choices.length === 0) {\n throw new Error('SelectPrompt requires at least one choice')\n }\n const initialValue =\n typeof defaultValue === 'undefined' ? undefined : choices.find((choice) => choice.value === defaultValue)\n const [answer, setAnswer] = useState<SelectItem<T> | undefined>(undefined)\n const {exit: unmountInk} = useApp()\n const [submitted, setSubmitted] = useState(false)\n const {stdout} = useStdout()\n const [wrapperHeight, setWrapperHeight] = useState(0)\n const [selectInputHeight, setSelectInputHeight] = useState(0)\n const [limit, setLimit] = useState(choices.length)\n const numberOfGroups = uniqBy(\n choices.filter((choice) => choice.group),\n 'group',\n ).length\n\n const wrapperRef = useCallback((node) => {\n if (node !== null) {\n const {height} = measureElement(node)\n setWrapperHeight(height)\n }\n }, [])\n\n const inputRef = useCallback((node) => {\n if (node !== null) {\n const {height} = measureElement(node)\n setSelectInputHeight(height)\n }\n }, [])\n\n useEffect(() => {\n function onResize() {\n const availableSpace = stdout.rows - (wrapperHeight - selectInputHeight)\n // rough estimate of the limit needed based on the space available\n const newLimit = Math.max(2, availableSpace - numberOfGroups * 2 - 6)\n\n if (newLimit < limit) {\n stdout.write(ansiEscapes.clearTerminal)\n }\n\n setLimit(Math.min(newLimit, choices.length))\n }\n\n onResize()\n\n stdout.on('resize', onResize)\n return () => {\n stdout.off('resize', onResize)\n }\n }, [wrapperHeight, selectInputHeight, choices.length, numberOfGroups, stdout, limit])\n\n const submitAnswer = useCallback(\n (answer: SelectItem<T>) => {\n if (stdout && wrapperHeight >= stdout.rows) {\n stdout.write(ansiEscapes.clearTerminal)\n }\n setSubmitted(true)\n unmountInk()\n onSubmit(answer.value)\n },\n [stdout, wrapperHeight, unmountInk, onSubmit],\n )\n\n useInput((input, key) => {\n handleCtrlC(input, key)\n\n if (key.return && answer) {\n submitAnswer(answer)\n }\n })\n\n return (\n <Box flexDirection=\"column\" marginBottom={1} ref={wrapperRef}>\n <Box>\n <Box marginRight={2}>\n <Text>?</Text>\n </Box>\n <TokenizedText item={messageWithPunctuation(message)} />\n </Box>\n {infoTable && !submitted ? (\n <Box marginLeft={7} marginTop={1}>\n <InfoTable table={infoTable} />\n </Box>\n ) : null}\n {submitted ? (\n <Box>\n <Box marginRight={2}>\n <Text color=\"cyan\">{figures.tick}</Text>\n </Box>\n\n <Text color=\"cyan\">{answer!.label}</Text>\n </Box>\n ) : (\n <Box marginTop={1}>\n <SelectInput\n defaultValue={initialValue}\n items={choices}\n infoMessage={\n submitWithShortcuts\n ? `Press ${figures.arrowUp}${figures.arrowDown} arrows to select, enter or a shortcut to confirm`\n : undefined\n }\n onChange={({item, usedShortcut}) => {\n setAnswer(item)\n\n if (submitWithShortcuts && usedShortcut && item) {\n submitAnswer(item)\n }\n }}\n limit={limit}\n ref={inputRef}\n />\n </Box>\n )}\n </Box>\n )\n}\n\nexport {SelectPrompt}\n"]}
@@ -236,5 +236,21 @@ describe('SelectPrompt', async () => {
236
236
  "
237
237
  `);
238
238
  });
239
+ test('allows passing false as the default value', async () => {
240
+ const items = [
241
+ { label: 'yes', value: true },
242
+ { label: 'no', value: false },
243
+ ];
244
+ const renderInstance = render(React.createElement(SelectPrompt, { message: "Associate your project with the org Castile Ventures?", choices: items, onSubmit: () => { }, defaultValue: false }));
245
+ expect(renderInstance.lastFrame()).toMatchInlineSnapshot(`
246
+ "? Associate your project with the org Castile Ventures?
247
+
248
+ (1) yes
249
+ > (2) no
250
+
251
+ Press ↑↓ arrows to select, enter to confirm
252
+ "
253
+ `);
254
+ });
239
255
  });
240
256
  //# sourceMappingURL=SelectPrompt.test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"SelectPrompt.test.js","sourceRoot":"","sources":["../../../../../src/private/node/ui/components/SelectPrompt.test.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,mBAAmB,CAAA;AAC9C,OAAO,EAAC,wBAAwB,EAAE,yBAAyB,EAAE,sBAAsB,EAAC,MAAM,qBAAqB,CAAA;AAC/G,OAAO,EAAC,QAAQ,EAAC,MAAM,mCAAmC,CAAA;AAC1D,OAAO,EAAC,YAAY,EAAC,MAAM,aAAa,CAAA;AACxC,OAAO,EAAC,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAC,MAAM,QAAQ,CAAA;AAC7D,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAC,MAAM,EAAC,MAAM,qBAAqB,CAAA;AAC1C,OAAO,EAAC,SAAS,EAAC,MAAM,KAAK,CAAA;AAE7B,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,IAA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AAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,aAAa,EAAE,GAAG,EAAE,GAAG,EAAC;YAClE,EAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,gBAAgB,EAAC;YACzD,EAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,gBAAgB,EAAC;YAC3D,EAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,EAAC;YAC1C,EAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAC;YAChC,EAAC,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAC;YACpC,EAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAC;YAClC,EAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAC;YAChC,EAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAC;SACjC,CAAA;QAED,MAAM,cAAc,GAAG,MAAM,CAC3B,oBAAC,YAAY,IACX,OAAO,EAAC,uDAAuD,EAC/D,OAAO,EAAE,KAAK,EACd,QAAQ,EAAE,GAAG,EAAE,GAAE,CAAC,GAClB,CACH,CAAA;QAED,MAAM,CAAC,cAAc,CAAC,SAAS,EAAE,CAAC,CAAC,qBAAqB,CAAC;;;;;;;;;;KAUxD,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["import {SelectPrompt} from './SelectPrompt.js'\nimport {getLastFrameAfterUnmount, sendInputAndWaitForChange, waitForInputsToBeReady} from '../../testing/ui.js'\nimport {unstyled} from '../../../../public/node/output.js'\nimport {OutputStream} from '../../ui.js'\nimport {beforeEach, describe, expect, test, vi} from 'vitest'\nimport React from 'react'\nimport {render} from 'ink-testing-library'\nimport {useStdout} from 'ink'\n\nvi.mock('ink', async () => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const original: any = await vi.importActual('ink')\n return {\n ...original,\n useStdout: vi.fn(),\n }\n})\n\nconst ARROW_DOWN = '\\u001B[B'\nconst ENTER = '\\r'\n\nbeforeEach(() => {\n vi.mocked(useStdout).mockReturnValue({\n stdout: new OutputStream({\n columns: 80,\n rows: 80,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n }) as any,\n write: () => {},\n })\n})\n\ndescribe('SelectPrompt', async () => {\n test('choose an answer', async () => {\n const onEnter = vi.fn()\n\n const items = [\n {label: 'first', value: 'first'},\n {label: 'second', value: 'second'},\n {label: 'third', value: 'third'},\n ]\n\n const infoTable = {Add: ['new-ext'], Remove: ['integrated-demand-ext', 'order-discount']}\n\n const renderInstance = render(\n <SelectPrompt\n message=\"Associate your project with the org Castile Ventures?\"\n choices={items}\n infoTable={infoTable}\n onSubmit={onEnter}\n />,\n )\n\n await waitForInputsToBeReady()\n await sendInputAndWaitForChange(renderInstance, ARROW_DOWN)\n await sendInputAndWaitForChange(renderInstance, ENTER)\n\n expect(getLastFrameAfterUnmount(renderInstance)).toMatchInlineSnapshot(`\n \"? Associate your project with the org Castile Ventures?\n \u001b[36m✔\u001b[39m \u001b[36msecond\u001b[39m\n \"\n `)\n\n expect(onEnter).toHaveBeenCalledWith(items[1]!.value)\n })\n\n test('renders groups', async () => {\n const items = [\n {label: 'first', value: 'first', group: 'Automations', key: 'f'},\n {label: 'second', value: 'second', group: 'Automations', key: 's'},\n {label: 'third', value: 'third', group: 'Merchant Admin'},\n {label: 'fourth', value: 'fourth', group: 'Merchant Admin'},\n {label: 'fifth', value: 'fifth', key: 'a'},\n {label: 'sixth', value: 'sixth'},\n {label: 'seventh', value: 'seventh'},\n {label: 'eighth', value: 'eighth'},\n {label: 'ninth', value: 'ninth'},\n {label: 'tenth', value: 'tenth'},\n ]\n\n const renderInstance = render(\n <SelectPrompt\n message=\"Associate your project with the org Castile Ventures?\"\n choices={items}\n onSubmit={() => {}}\n />,\n )\n\n expect(renderInstance.lastFrame()).toMatchInlineSnapshot(`\n \"? Associate your project with the org Castile Ventures?\n\n \u001b[1mAutomations\u001b[22m\n \u001b[36m>\u001b[39m \u001b[36m(f) first\u001b[39m\n (s) second\n\n \u001b[1mMerchant Admin\u001b[22m\n (3) third\n (4) fourth\n\n \u001b[1mOther\u001b[22m\n (a) fifth\n (6) sixth\n (7) seventh\n (8) eighth\n (9) ninth\n (10) tenth\n\n \u001b[2mPress ↑↓ arrows to select, enter to confirm\u001b[22m\n \"\n `)\n })\n\n test('supports an info table', async () => {\n const items = [\n {label: 'first', value: 'first'},\n {label: 'second', value: 'second'},\n {label: 'third', value: 'third'},\n {label: 'fourth', value: 'fourth'},\n ]\n\n const infoTable = {\n Add: ['new-ext'],\n Remove: ['integrated-demand-ext', ['order-discount', {subdued: '(1)'}]],\n }\n\n const renderInstance = render(\n <SelectPrompt\n message=\"Associate your project with the org Castile Ventures?\"\n choices={items}\n infoTable={infoTable}\n onSubmit={() => {}}\n />,\n )\n\n expect(renderInstance.lastFrame()).toMatchInlineSnapshot(`\n \"? Associate your project with the org Castile Ventures?\n\n Add: • new-ext\n\n Remove: • integrated-demand-ext\n • order-discount \u001b[2m(1)\u001b[22m\n\n \u001b[36m>\u001b[39m \u001b[36m(1) first\u001b[39m\n (2) second\n (3) third\n (4) fourth\n\n \u001b[2mPress ↑↓ arrows to select, enter to confirm\u001b[22m\n \"\n `)\n })\n\n test(\"it doesn't submit if there are no choices\", async () => {\n const onEnter = vi.fn()\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const items: any[] = []\n\n const renderInstance = render(\n <SelectPrompt\n message=\"Associate your project with the org Castile Ventures?\"\n choices={items}\n onSubmit={onEnter}\n />,\n )\n\n expect(unstyled(getLastFrameAfterUnmount(renderInstance)!)).toContain(\n 'ERROR SelectPrompt requires at least one choice',\n )\n })\n\n test(\"doesn't append a colon to the message if it ends with a question mark\", async () => {\n const {lastFrame} = render(\n <SelectPrompt choices={[{label: 'a', value: 'a'}]} onSubmit={() => {}} message=\"Test question?\" />,\n )\n\n expect(unstyled(lastFrame()!)).toMatchInlineSnapshot(`\n \"? Test question?\n\n > (1) a\n\n Press ↑↓ arrows to select, enter to confirm\n \"\n `)\n })\n\n test('accepts a default value', async () => {\n const onEnter = vi.fn()\n const items = [\n {label: 'a', value: 'a'},\n {label: 'b', value: 'b'},\n ]\n\n const renderInstance = render(\n <SelectPrompt choices={items} onSubmit={onEnter} message=\"Test question?\" defaultValue=\"b\" />,\n )\n\n expect(unstyled(renderInstance.lastFrame()!)).toMatchInlineSnapshot(`\n \"? Test question?\n\n (1) a\n > (2) b\n\n Press ↑↓ arrows to select, enter to confirm\n \"\n `)\n\n await waitForInputsToBeReady()\n await sendInputAndWaitForChange(renderInstance, ENTER)\n\n expect(getLastFrameAfterUnmount(renderInstance)).toMatchInlineSnapshot(`\n \"? Test question?\n \u001b[36m✔\u001b[39m \u001b[36mb\u001b[39m\n \"\n `)\n expect(onEnter).toHaveBeenCalledWith(items[1]!.value)\n })\n\n test('can submit the initial value', async () => {\n const onEnter = vi.fn()\n const items = [\n {label: 'a', value: 'a'},\n {label: 'b', value: 'b'},\n ]\n\n const renderInstance = render(<SelectPrompt choices={items} onSubmit={onEnter} message=\"Test question?\" />)\n\n expect(unstyled(renderInstance.lastFrame()!)).toMatchInlineSnapshot(`\n \"? Test question?\n\n > (1) a\n (2) b\n\n Press ↑↓ arrows to select, enter to confirm\n \"\n `)\n\n await waitForInputsToBeReady()\n await sendInputAndWaitForChange(renderInstance, ENTER)\n\n expect(getLastFrameAfterUnmount(renderInstance)).toMatchInlineSnapshot(`\n \"? Test question?\n \u001b[36m✔\u001b[39m \u001b[36ma\u001b[39m\n \"\n `)\n expect(onEnter).toHaveBeenCalledWith(items[0]!.value)\n })\n\n test('allow submitting with a shortcut directly', async () => {\n const onEnter = vi.fn()\n const items = [\n {label: 'a', value: 'a', key: 'a'},\n {label: 'b', value: 'b', key: 'b'},\n ]\n\n const renderInstance = render(\n <SelectPrompt choices={items} onSubmit={onEnter} message=\"Test question?\" submitWithShortcuts />,\n )\n\n expect(unstyled(renderInstance.lastFrame()!)).toMatchInlineSnapshot(`\n \"? Test question?\n\n > (a) a\n (b) b\n\n Press ↑↓ arrows to select, enter or a shortcut to confirm\n \"\n `)\n\n await waitForInputsToBeReady()\n await sendInputAndWaitForChange(renderInstance, 'b')\n\n expect(getLastFrameAfterUnmount(renderInstance)).toMatchInlineSnapshot(`\n \"? Test question?\n \u001b[36m✔\u001b[39m \u001b[36mb\u001b[39m\n \"\n `)\n expect(onEnter).toHaveBeenCalledWith(items[1]!.value)\n })\n\n test('adapts to the height of the container', async () => {\n vi.mocked(useStdout).mockReturnValue({\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n stdout: new OutputStream({rows: 10}) as any,\n write: () => {},\n })\n\n const items = [\n {label: 'first', value: 'first', group: 'Automations', key: 'f'},\n {label: 'second', value: 'second', group: 'Automations', key: 's'},\n {label: 'third', value: 'third', group: 'Merchant Admin'},\n {label: 'fourth', value: 'fourth', group: 'Merchant Admin'},\n {label: 'fifth', value: 'fifth', key: 'a'},\n {label: 'sixth', value: 'sixth'},\n {label: 'seventh', value: 'seventh'},\n {label: 'eighth', value: 'eighth'},\n {label: 'ninth', value: 'ninth'},\n {label: 'tenth', value: 'tenth'},\n ]\n\n const renderInstance = render(\n <SelectPrompt\n message=\"Associate your project with the org Castile Ventures?\"\n choices={items}\n onSubmit={() => {}}\n />,\n )\n\n expect(renderInstance.lastFrame()).toMatchInlineSnapshot(`\n \"? Associate your project with the org Castile Ventures?\n\n \u001b[1mAutomations\u001b[22m\n \u001b[36m>\u001b[39m \u001b[36m(f) first\u001b[39m\n (s) second\n\n \u001b[2mShowing 2 of 10 items.\u001b[22m\n \u001b[2mPress ↑↓ arrows to select, enter to confirm\u001b[22m\n \"\n `)\n })\n})\n"]}
1
+ {"version":3,"file":"SelectPrompt.test.js","sourceRoot":"","sources":["../../../../../src/private/node/ui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,cAAc,GAAG,MAAM,CAC3B,oBAAC,YAAY,IACX,OAAO,EAAC,uDAAuD,EAC/D,OAAO,EAAE,KAAK,EACd,QAAQ,EAAE,GAAG,EAAE,GAAE,CAAC,GAClB,CACH,CAAA;QAED,MAAM,CAAC,cAAc,CAAC,SAAS,EAAE,CAAC,CAAC,qBAAqB,CAAC;;;;;;;;;;KAUxD,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IAEF,IAAI,CAAC,2CAA2C,EAAE,KAAK,IAAI,EAAE;QAC3D,MAAM,KAAK,GAAG;YACZ,EAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAC;YAC3B,EAAC,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAC;SAC5B,CAAA;QAED,MAAM,cAAc,GAAG,MAAM,CAC3B,oBAAC,YAAY,IACX,OAAO,EAAC,uDAAuD,EAC/D,OAAO,EAAE,KAAK,EACd,QAAQ,EAAE,GAAG,EAAE,GAAE,CAAC,EAClB,YAAY,EAAE,KAAK,GACnB,CACH,CAAA;QAED,MAAM,CAAC,cAAc,CAAC,SAAS,EAAE,CAAC,CAAC,qBAAqB,CAAC;;;;;;;;KAQxD,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["import {SelectPrompt} from './SelectPrompt.js'\nimport {getLastFrameAfterUnmount, sendInputAndWaitForChange, waitForInputsToBeReady} from '../../testing/ui.js'\nimport {unstyled} from '../../../../public/node/output.js'\nimport {OutputStream} from '../../ui.js'\nimport {beforeEach, describe, expect, test, vi} from 'vitest'\nimport React from 'react'\nimport {render} from 'ink-testing-library'\nimport {useStdout} from 'ink'\n\nvi.mock('ink', async () => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const original: any = await vi.importActual('ink')\n return {\n ...original,\n useStdout: vi.fn(),\n }\n})\n\nconst ARROW_DOWN = '\\u001B[B'\nconst ENTER = '\\r'\n\nbeforeEach(() => {\n vi.mocked(useStdout).mockReturnValue({\n stdout: new OutputStream({\n columns: 80,\n rows: 80,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n }) as any,\n write: () => {},\n })\n})\n\ndescribe('SelectPrompt', async () => {\n test('choose an answer', async () => {\n const onEnter = vi.fn()\n\n const items = [\n {label: 'first', value: 'first'},\n {label: 'second', value: 'second'},\n {label: 'third', value: 'third'},\n ]\n\n const infoTable = {Add: ['new-ext'], Remove: ['integrated-demand-ext', 'order-discount']}\n\n const renderInstance = render(\n <SelectPrompt\n message=\"Associate your project with the org Castile Ventures?\"\n choices={items}\n infoTable={infoTable}\n onSubmit={onEnter}\n />,\n )\n\n await waitForInputsToBeReady()\n await sendInputAndWaitForChange(renderInstance, ARROW_DOWN)\n await sendInputAndWaitForChange(renderInstance, ENTER)\n\n expect(getLastFrameAfterUnmount(renderInstance)).toMatchInlineSnapshot(`\n \"? Associate your project with the org Castile Ventures?\n \u001b[36m✔\u001b[39m \u001b[36msecond\u001b[39m\n \"\n `)\n\n expect(onEnter).toHaveBeenCalledWith(items[1]!.value)\n })\n\n test('renders groups', async () => {\n const items = [\n {label: 'first', value: 'first', group: 'Automations', key: 'f'},\n {label: 'second', value: 'second', group: 'Automations', key: 's'},\n {label: 'third', value: 'third', group: 'Merchant Admin'},\n {label: 'fourth', value: 'fourth', group: 'Merchant Admin'},\n {label: 'fifth', value: 'fifth', key: 'a'},\n {label: 'sixth', value: 'sixth'},\n {label: 'seventh', value: 'seventh'},\n {label: 'eighth', value: 'eighth'},\n {label: 'ninth', value: 'ninth'},\n {label: 'tenth', value: 'tenth'},\n ]\n\n const renderInstance = render(\n <SelectPrompt\n message=\"Associate your project with the org Castile Ventures?\"\n choices={items}\n onSubmit={() => {}}\n />,\n )\n\n expect(renderInstance.lastFrame()).toMatchInlineSnapshot(`\n \"? Associate your project with the org Castile Ventures?\n\n \u001b[1mAutomations\u001b[22m\n \u001b[36m>\u001b[39m \u001b[36m(f) first\u001b[39m\n (s) second\n\n \u001b[1mMerchant Admin\u001b[22m\n (3) third\n (4) fourth\n\n \u001b[1mOther\u001b[22m\n (a) fifth\n (6) sixth\n (7) seventh\n (8) eighth\n (9) ninth\n (10) tenth\n\n \u001b[2mPress ↑↓ arrows to select, enter to confirm\u001b[22m\n \"\n `)\n })\n\n test('supports an info table', async () => {\n const items = [\n {label: 'first', value: 'first'},\n {label: 'second', value: 'second'},\n {label: 'third', value: 'third'},\n {label: 'fourth', value: 'fourth'},\n ]\n\n const infoTable = {\n Add: ['new-ext'],\n Remove: ['integrated-demand-ext', ['order-discount', {subdued: '(1)'}]],\n }\n\n const renderInstance = render(\n <SelectPrompt\n message=\"Associate your project with the org Castile Ventures?\"\n choices={items}\n infoTable={infoTable}\n onSubmit={() => {}}\n />,\n )\n\n expect(renderInstance.lastFrame()).toMatchInlineSnapshot(`\n \"? Associate your project with the org Castile Ventures?\n\n Add: • new-ext\n\n Remove: • integrated-demand-ext\n • order-discount \u001b[2m(1)\u001b[22m\n\n \u001b[36m>\u001b[39m \u001b[36m(1) first\u001b[39m\n (2) second\n (3) third\n (4) fourth\n\n \u001b[2mPress ↑↓ arrows to select, enter to confirm\u001b[22m\n \"\n `)\n })\n\n test(\"it doesn't submit if there are no choices\", async () => {\n const onEnter = vi.fn()\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const items: any[] = []\n\n const renderInstance = render(\n <SelectPrompt\n message=\"Associate your project with the org Castile Ventures?\"\n choices={items}\n onSubmit={onEnter}\n />,\n )\n\n expect(unstyled(getLastFrameAfterUnmount(renderInstance)!)).toContain(\n 'ERROR SelectPrompt requires at least one choice',\n )\n })\n\n test(\"doesn't append a colon to the message if it ends with a question mark\", async () => {\n const {lastFrame} = render(\n <SelectPrompt choices={[{label: 'a', value: 'a'}]} onSubmit={() => {}} message=\"Test question?\" />,\n )\n\n expect(unstyled(lastFrame()!)).toMatchInlineSnapshot(`\n \"? Test question?\n\n > (1) a\n\n Press ↑↓ arrows to select, enter to confirm\n \"\n `)\n })\n\n test('accepts a default value', async () => {\n const onEnter = vi.fn()\n const items = [\n {label: 'a', value: 'a'},\n {label: 'b', value: 'b'},\n ]\n\n const renderInstance = render(\n <SelectPrompt choices={items} onSubmit={onEnter} message=\"Test question?\" defaultValue=\"b\" />,\n )\n\n expect(unstyled(renderInstance.lastFrame()!)).toMatchInlineSnapshot(`\n \"? Test question?\n\n (1) a\n > (2) b\n\n Press ↑↓ arrows to select, enter to confirm\n \"\n `)\n\n await waitForInputsToBeReady()\n await sendInputAndWaitForChange(renderInstance, ENTER)\n\n expect(getLastFrameAfterUnmount(renderInstance)).toMatchInlineSnapshot(`\n \"? Test question?\n \u001b[36m✔\u001b[39m \u001b[36mb\u001b[39m\n \"\n `)\n expect(onEnter).toHaveBeenCalledWith(items[1]!.value)\n })\n\n test('can submit the initial value', async () => {\n const onEnter = vi.fn()\n const items = [\n {label: 'a', value: 'a'},\n {label: 'b', value: 'b'},\n ]\n\n const renderInstance = render(<SelectPrompt choices={items} onSubmit={onEnter} message=\"Test question?\" />)\n\n expect(unstyled(renderInstance.lastFrame()!)).toMatchInlineSnapshot(`\n \"? Test question?\n\n > (1) a\n (2) b\n\n Press ↑↓ arrows to select, enter to confirm\n \"\n `)\n\n await waitForInputsToBeReady()\n await sendInputAndWaitForChange(renderInstance, ENTER)\n\n expect(getLastFrameAfterUnmount(renderInstance)).toMatchInlineSnapshot(`\n \"? Test question?\n \u001b[36m✔\u001b[39m \u001b[36ma\u001b[39m\n \"\n `)\n expect(onEnter).toHaveBeenCalledWith(items[0]!.value)\n })\n\n test('allow submitting with a shortcut directly', async () => {\n const onEnter = vi.fn()\n const items = [\n {label: 'a', value: 'a', key: 'a'},\n {label: 'b', value: 'b', key: 'b'},\n ]\n\n const renderInstance = render(\n <SelectPrompt choices={items} onSubmit={onEnter} message=\"Test question?\" submitWithShortcuts />,\n )\n\n expect(unstyled(renderInstance.lastFrame()!)).toMatchInlineSnapshot(`\n \"? Test question?\n\n > (a) a\n (b) b\n\n Press ↑↓ arrows to select, enter or a shortcut to confirm\n \"\n `)\n\n await waitForInputsToBeReady()\n await sendInputAndWaitForChange(renderInstance, 'b')\n\n expect(getLastFrameAfterUnmount(renderInstance)).toMatchInlineSnapshot(`\n \"? Test question?\n \u001b[36m✔\u001b[39m \u001b[36mb\u001b[39m\n \"\n `)\n expect(onEnter).toHaveBeenCalledWith(items[1]!.value)\n })\n\n test('adapts to the height of the container', async () => {\n vi.mocked(useStdout).mockReturnValue({\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n stdout: new OutputStream({rows: 10}) as any,\n write: () => {},\n })\n\n const items = [\n {label: 'first', value: 'first', group: 'Automations', key: 'f'},\n {label: 'second', value: 'second', group: 'Automations', key: 's'},\n {label: 'third', value: 'third', group: 'Merchant Admin'},\n {label: 'fourth', value: 'fourth', group: 'Merchant Admin'},\n {label: 'fifth', value: 'fifth', key: 'a'},\n {label: 'sixth', value: 'sixth'},\n {label: 'seventh', value: 'seventh'},\n {label: 'eighth', value: 'eighth'},\n {label: 'ninth', value: 'ninth'},\n {label: 'tenth', value: 'tenth'},\n ]\n\n const renderInstance = render(\n <SelectPrompt\n message=\"Associate your project with the org Castile Ventures?\"\n choices={items}\n onSubmit={() => {}}\n />,\n )\n\n expect(renderInstance.lastFrame()).toMatchInlineSnapshot(`\n \"? Associate your project with the org Castile Ventures?\n\n \u001b[1mAutomations\u001b[22m\n \u001b[36m>\u001b[39m \u001b[36m(f) first\u001b[39m\n (s) second\n\n \u001b[2mShowing 2 of 10 items.\u001b[22m\n \u001b[2mPress ↑↓ arrows to select, enter to confirm\u001b[22m\n \"\n `)\n })\n\n test('allows passing false as the default value', async () => {\n const items = [\n {label: 'yes', value: true},\n {label: 'no', value: false},\n ]\n\n const renderInstance = render(\n <SelectPrompt\n message=\"Associate your project with the org Castile Ventures?\"\n choices={items}\n onSubmit={() => {}}\n defaultValue={false}\n />,\n )\n\n expect(renderInstance.lastFrame()).toMatchInlineSnapshot(`\n \"? Associate your project with the org Castile Ventures?\n\n (1) yes\n \u001b[36m>\u001b[39m \u001b[36m(2) no\u001b[39m\n\n \u001b[2mPress ↑↓ arrows to select, enter to confirm\u001b[22m\n \"\n `)\n })\n})\n"]}
@@ -1 +1 @@
1
- export declare const CLI_KIT_VERSION = "3.45.0-pre.5";
1
+ export declare const CLI_KIT_VERSION = "3.45.1";
@@ -1,2 +1,2 @@
1
- export const CLI_KIT_VERSION = '3.45.0-pre.5';
1
+ export const CLI_KIT_VERSION = '3.45.1';
2
2
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../../src/public/common/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,eAAe,GAAG,cAAc,CAAA","sourcesContent":["export const CLI_KIT_VERSION = '3.45.0-pre.5'\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../../src/public/common/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,eAAe,GAAG,QAAQ,CAAA","sourcesContent":["export const CLI_KIT_VERSION = '3.45.1'\n"]}
@@ -1,5 +1,5 @@
1
+ import { GraphQLVariables } from './graphql.js';
1
2
  import { AdminSession } from '../session.js';
2
- import { GraphQLVariables } from '../../../private/node/api/graphql.js';
3
3
  /**
4
4
  * Executes a GraphQL query against the Admin API.
5
5
  *
@@ -1,6 +1,6 @@
1
+ import { graphqlRequest } from './graphql.js';
1
2
  import { outputContent, outputToken } from '../../../public/node/output.js';
2
3
  import { BugError, AbortError } from '../error.js';
3
- import { graphqlRequest } from '../../../private/node/api/graphql.js';
4
4
  import { restRequestBody, restRequestHeaders, restRequestUrl } from '../../../private/node/api/rest.js';
5
5
  import { fetch } from '../http.js';
6
6
  import { ClientError, gql } from 'graphql-request';
@@ -16,7 +16,7 @@ export async function adminRequest(query, session, variables) {
16
16
  const api = 'Admin';
17
17
  const version = await fetchApiVersion(session);
18
18
  const url = adminUrl(session.storeFqdn, version);
19
- return graphqlRequest(query, api, url, session.token, variables);
19
+ return graphqlRequest({ query, api, url, token: session.token, variables });
20
20
  }
21
21
  /**
22
22
  * GraphQL query to retrieve the latest supported API version.
@@ -28,7 +28,14 @@ async function fetchApiVersion(session) {
28
28
  const url = adminUrl(session.storeFqdn, 'unstable');
29
29
  const query = apiVersionQuery();
30
30
  try {
31
- const data = await graphqlRequest(query, 'Admin', url, session.token, {}, { handleErrors: false });
31
+ const data = await graphqlRequest({
32
+ query,
33
+ api: 'Admin',
34
+ url,
35
+ token: session.token,
36
+ variables: {},
37
+ responseOptions: { handleErrors: false },
38
+ });
32
39
  return data.publicApiVersions
33
40
  .filter((item) => item.supported)
34
41
  .map((item) => item.handle)