shopify-cli 1.8.0 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop_todo.yml +15 -2
  3. data/CHANGELOG.md +4 -1
  4. data/Gemfile.lock +3 -3
  5. data/dev.yml +3 -0
  6. data/lib/graphql/extension_create.graphql +17 -2
  7. data/lib/project_types/extension/cli.rb +2 -0
  8. data/lib/project_types/extension/commands/extension_command.rb +4 -4
  9. data/lib/project_types/extension/commands/push.rb +2 -2
  10. data/lib/project_types/extension/commands/register.rb +4 -3
  11. data/lib/project_types/extension/commands/serve.rb +1 -35
  12. data/lib/project_types/extension/extension_project.rb +15 -4
  13. data/lib/project_types/extension/extension_project_keys.rb +2 -1
  14. data/lib/project_types/extension/features/argo.rb +6 -0
  15. data/lib/project_types/extension/features/argo_renderer_package.rb +32 -0
  16. data/lib/project_types/extension/features/argo_serve.rb +69 -0
  17. data/lib/project_types/extension/messages/message_loading.rb +3 -1
  18. data/lib/project_types/extension/models/registration.rb +1 -0
  19. data/lib/project_types/extension/models/specification.rb +2 -0
  20. data/lib/project_types/extension/models/specification_handlers/default.rb +8 -0
  21. data/lib/project_types/extension/tasks/configure_features.rb +2 -0
  22. data/lib/project_types/extension/tasks/converters/registration_converter.rb +2 -0
  23. data/lib/project_types/node/commands/generate.rb +0 -22
  24. data/lib/project_types/script/cli.rb +2 -8
  25. data/lib/project_types/script/commands/create.rb +0 -7
  26. data/lib/project_types/script/commands/push.rb +2 -2
  27. data/lib/project_types/script/config/extension_points.yml +2 -0
  28. data/lib/project_types/script/errors.rb +0 -19
  29. data/lib/project_types/script/forms/create.rb +3 -14
  30. data/lib/project_types/script/graphql/app_script_update_or_create.graphql +0 -3
  31. data/lib/project_types/script/graphql/script_service_proxy.graphql +1 -2
  32. data/lib/project_types/script/layers/application/build_script.rb +1 -2
  33. data/lib/project_types/script/layers/application/create_script.rb +30 -51
  34. data/lib/project_types/script/layers/application/extension_points.rb +3 -2
  35. data/lib/project_types/script/layers/application/push_script.rb +2 -4
  36. data/lib/project_types/script/layers/domain/extension_point.rb +56 -46
  37. data/lib/project_types/script/layers/domain/metadata.rb +18 -25
  38. data/lib/project_types/script/layers/domain/push_package.rb +0 -4
  39. data/lib/project_types/script/layers/domain/script_project.rb +34 -0
  40. data/lib/project_types/script/layers/infrastructure/assemblyscript_project_creator.rb +6 -2
  41. data/lib/project_types/script/layers/infrastructure/assemblyscript_task_runner.rb +4 -4
  42. data/lib/project_types/script/layers/infrastructure/errors.rb +12 -10
  43. data/lib/project_types/script/layers/infrastructure/push_package_repository.rb +10 -12
  44. data/lib/project_types/script/layers/infrastructure/rust_task_runner.rb +1 -1
  45. data/lib/project_types/script/layers/infrastructure/script_project_repository.rb +145 -0
  46. data/lib/project_types/script/layers/infrastructure/script_service.rb +9 -72
  47. data/lib/project_types/script/messages/messages.rb +0 -47
  48. data/lib/project_types/script/ui/error_handler.rb +7 -24
  49. data/lib/shopify-cli/context.rb +28 -0
  50. data/lib/shopify-cli/version.rb +1 -1
  51. metadata +6 -10
  52. data/lib/project_types/script/commands/disable.rb +0 -25
  53. data/lib/project_types/script/commands/enable.rb +0 -80
  54. data/lib/project_types/script/graphql/shop_script_delete.graphql +0 -14
  55. data/lib/project_types/script/graphql/shop_script_update_or_create.graphql +0 -28
  56. data/lib/project_types/script/layers/application/disable_script.rb +0 -21
  57. data/lib/project_types/script/layers/application/enable_script.rb +0 -23
  58. data/lib/project_types/script/layers/infrastructure/config_ui_repository.rb +0 -46
  59. data/lib/project_types/script/script_project.rb +0 -64
@@ -42,6 +42,14 @@ module Extension
42
42
  []
43
43
  end
44
44
 
45
+ def serve(context)
46
+ Features::ArgoServe.new(specification_handler: self, context: context).call
47
+ end
48
+
49
+ def renderer_package(context)
50
+ argo.renderer_package(context)
51
+ end
52
+
45
53
  protected
46
54
 
47
55
  def argo
@@ -40,6 +40,8 @@ module Extension
40
40
  admin: {
41
41
  git_template: "https://github.com/Shopify/argo-admin-template.git",
42
42
  renderer_package_name: "@shopify/argo-admin",
43
+ required_fields: [:shop, :api_key],
44
+ required_shop_beta_flags: [:argo_admin_beta],
43
45
  },
44
46
  checkout: {
45
47
  git_template: "https://github.com/Shopify/argo-checkout-template.git",
@@ -6,6 +6,7 @@ module Extension
6
6
  module Converters
7
7
  module RegistrationConverter
8
8
  ID_FIELD = "id"
9
+ UUID_FIELD = "uuid"
9
10
  TYPE_FIELD = "type"
10
11
  TITLE_FIELD = "title"
11
12
  DRAFT_VERSION_FIELD = "draftVersion"
@@ -15,6 +16,7 @@ module Extension
15
16
 
16
17
  Models::Registration.new(
17
18
  id: hash[ID_FIELD].to_i,
19
+ uuid: hash[UUID_FIELD],
18
20
  type: hash[TYPE_FIELD],
19
21
  title: hash[TITLE_FIELD],
20
22
  draft_version: VersionConverter.from_hash(context, hash[DRAFT_VERSION_FIELD])
@@ -4,10 +4,6 @@ require "shopify_cli"
4
4
  module Node
5
5
  module Commands
6
6
  class Generate < ShopifyCli::Command
7
- subcommand :Page, "page", Project.project_filepath("commands/generate/page")
8
- subcommand :Billing, "billing", Project.project_filepath("commands/generate/billing")
9
- subcommand :Webhook, "webhook", Project.project_filepath("commands/generate/webhook")
10
-
11
7
  def call(*)
12
8
  @ctx.puts(self.class.help)
13
9
  end
@@ -19,24 +15,6 @@ module Node
19
15
  def self.extended_help
20
16
  help
21
17
  end
22
-
23
- def self.run_generate(script, name, ctx)
24
- stat = ctx.system(script)
25
- unless stat.success?
26
- ctx.abort(response(stat.exitstatus, name, ctx))
27
- end
28
- end
29
-
30
- def self.response(code, name, ctx)
31
- case code
32
- when 1
33
- ctx.message("node.generate.error.generic", name)
34
- when 2
35
- ctx.message("node.generate.error.name_exists", name)
36
- else
37
- ctx.message("node.error.generic")
38
- end
39
- end
40
18
  end
41
19
  end
42
20
  end
@@ -7,8 +7,6 @@ module Script
7
7
  creator("Script::Commands::Create")
8
8
 
9
9
  register_command("Script::Commands::Push", "push")
10
- register_command("Script::Commands::Disable", "disable")
11
- register_command("Script::Commands::Enable", "enable")
12
10
 
13
11
  require Project.project_filepath("messages/messages")
14
12
  register_messages(Script::Messages::MESSAGES)
@@ -18,8 +16,6 @@ module Script
18
16
  module Commands
19
17
  autoload :Create, Project.project_filepath("commands/create")
20
18
  autoload :Push, Project.project_filepath("commands/push")
21
- autoload :Disable, Project.project_filepath("commands/disable")
22
- autoload :Enable, Project.project_filepath("commands/enable")
23
19
  end
24
20
 
25
21
  # define/autoload project specific Forms
@@ -33,8 +29,6 @@ module Script
33
29
  autoload :BuildScript, Project.project_filepath("layers/application/build_script")
34
30
  autoload :CreateScript, Project.project_filepath("layers/application/create_script")
35
31
  autoload :PushScript, Project.project_filepath("layers/application/push_script")
36
- autoload :DisableScript, Project.project_filepath("layers/application/disable_script")
37
- autoload :EnableScript, Project.project_filepath("layers/application/enable_script")
38
32
  autoload :ExtensionPoints, Project.project_filepath("layers/application/extension_points")
39
33
  autoload :ProjectDependencies, Project.project_filepath("layers/application/project_dependencies")
40
34
  end
@@ -45,6 +39,7 @@ module Script
45
39
  autoload :PushPackage, Project.project_filepath("layers/domain/push_package")
46
40
  autoload :Metadata, Project.project_filepath("layers/domain/metadata")
47
41
  autoload :ExtensionPoint, Project.project_filepath("layers/domain/extension_point")
42
+ autoload :ScriptProject, Project.project_filepath("layers/domain/script_project")
48
43
  end
49
44
 
50
45
  module Infrastructure
@@ -59,10 +54,10 @@ module Script
59
54
  Project.project_filepath("layers/infrastructure/rust_project_creator.rb")
60
55
  autoload :RustTaskRunner, Project.project_filepath("layers/infrastructure/rust_task_runner")
61
56
 
62
- autoload :ConfigUiRepository, Project.project_filepath("layers/infrastructure/config_ui_repository")
63
57
  autoload :PushPackageRepository, Project.project_filepath("layers/infrastructure/push_package_repository")
64
58
  autoload :ExtensionPointRepository, Project.project_filepath("layers/infrastructure/extension_point_repository")
65
59
  autoload :ProjectCreator, Project.project_filepath("layers/infrastructure/project_creator")
60
+ autoload :ScriptProjectRepository, Project.project_filepath("layers/infrastructure/script_project_repository")
66
61
  autoload :ScriptService, Project.project_filepath("layers/infrastructure/script_service")
67
62
  autoload :TaskRunner, Project.project_filepath("layers/infrastructure/task_runner")
68
63
  end
@@ -74,7 +69,6 @@ module Script
74
69
  autoload :StrictSpinner, Project.project_filepath("ui/strict_spinner")
75
70
  end
76
71
 
77
- autoload :ScriptProject, Project.project_filepath("script_project")
78
72
  autoload :Errors, Project.project_filepath("errors")
79
73
 
80
74
  class ScriptProjectError < StandardError; end
@@ -5,7 +5,6 @@ module Script
5
5
  class Create < ShopifyCli::SubCommand
6
6
  options do |parser, flags|
7
7
  parser.on("--name=NAME") { |name| flags[:name] = name }
8
- parser.on("--description=DESCRIPTION") { |description| flags[:description] = description }
9
8
  parser.on("--extension_point=EP_NAME") { |ep_name| flags[:extension_point] = ep_name }
10
9
  parser.on("--extension-point=EP_NAME") { |ep_name| flags[:extension_point] = ep_name }
11
10
  parser.on("--language=LANGUAGE") { |language| flags[:language] = language }
@@ -13,8 +12,6 @@ module Script
13
12
  end
14
13
 
15
14
  def call(args, _name)
16
- cur_dir = @ctx.root
17
-
18
15
  form = Forms::Create.ask(@ctx, args, options.flags)
19
16
  return @ctx.puts(self.class.help) if form.nil?
20
17
 
@@ -27,14 +24,10 @@ module Script
27
24
  language: form.language,
28
25
  script_name: form.name,
29
26
  extension_point_type: form.extension_point,
30
- description: form.description,
31
27
  no_config_ui: options.flags.key?(:no_config_ui)
32
28
  )
33
29
  @ctx.puts(@ctx.message("script.create.change_directory_notice", project.script_name))
34
- rescue Script::Errors::ScriptProjectAlreadyExistsError => e
35
- UI::ErrorHandler.pretty_print_and_raise(e, failed_op: @ctx.message("script.create.error.operation_failed"))
36
30
  rescue StandardError => e
37
- ScriptProject.cleanup(ctx: @ctx, script_name: form.name, root_dir: cur_dir) if form
38
31
  UI::ErrorHandler.pretty_print_and_raise(e, failed_op: @ctx.message("script.create.error.operation_failed"))
39
32
  end
40
33
 
@@ -10,13 +10,13 @@ module Script
10
10
  def call(_args, _name)
11
11
  ShopifyCli::Tasks::EnsureEnv.call(@ctx, required: [:api_key, :secret, :shop])
12
12
 
13
- api_key = ScriptProject.current.api_key
13
+ api_key = Layers::Infrastructure::ScriptProjectRepository.new(ctx: @ctx).get.api_key
14
14
  return @ctx.puts(self.class.help) unless api_key
15
15
 
16
16
  Layers::Application::PushScript.call(ctx: @ctx, force: options.flags.key?(:force))
17
17
  @ctx.puts(@ctx.message("script.push.script_pushed", api_key: api_key))
18
18
  rescue StandardError => e
19
- msg = @ctx.message("script.push.error.operation_failed", api_key: ShopifyCli::Project.current.env.api_key)
19
+ msg = @ctx.message("script.push.error.operation_failed", api_key: api_key)
20
20
  UI::ErrorHandler.pretty_print_and_raise(e, failed_op: msg)
21
21
  end
22
22
 
@@ -5,6 +5,7 @@ discount:
5
5
  sdk-version: "^9.0.0"
6
6
  toolchain-version: "^5.0.0"
7
7
  unit_limit_per_order:
8
+ beta: true
8
9
  assemblyscript:
9
10
  package: "@shopify/extension-point-as-unit-limit-per-order"
10
11
  sdk-version: "^9.0.0"
@@ -23,6 +24,7 @@ shipping_filter:
23
24
  sdk-version: "^9.0.0"
24
25
  toolchain-version: "^5.0.0"
25
26
  tax_filter:
27
+ beta: true
26
28
  assemblyscript:
27
29
  package: "@shopify/extension-point-as-tax-filter"
28
30
  sdk-version: "^9.0.0"
@@ -2,7 +2,6 @@
2
2
 
3
3
  module Script
4
4
  module Errors
5
- class InvalidContextError < ScriptProjectError; end
6
5
  class InvalidScriptNameError < ScriptProjectError; end
7
6
 
8
7
  class NoExistingAppsError < ScriptProjectError; end
@@ -16,7 +15,6 @@ module Script
16
15
  end
17
16
  end
18
17
 
19
- class ScriptProjectAlreadyExistsError < ScriptProjectError; end
20
18
  class InvalidConfigProps < ScriptProjectError; end
21
19
 
22
20
  class InvalidConfigYAMLError < ScriptProjectError
@@ -26,22 +24,5 @@ module Script
26
24
  @config_file = config_file
27
25
  end
28
26
  end
29
-
30
- class InvalidLanguageError < ScriptProjectError
31
- attr_reader :language, :extension_point_type
32
- def initialize(language, extension_point_type)
33
- super()
34
- @language = language
35
- @extension_point_type = extension_point_type
36
- end
37
- end
38
-
39
- class DeprecatedEPError < ScriptProjectError
40
- attr_reader :ep
41
- def initialize(ep)
42
- super()
43
- @ep = ep
44
- end
45
- end
46
27
  end
47
28
  end
@@ -3,11 +3,10 @@
3
3
  module Script
4
4
  module Forms
5
5
  class Create < ShopifyCli::Form
6
- flag_arguments :extension_point, :name, :language, :description
6
+ flag_arguments :extension_point, :name, :language
7
7
 
8
8
  def ask
9
9
  self.name = valid_name
10
- self.description ||= ask_description
11
10
  self.extension_point ||= ask_extension_point
12
11
  self.language = ask_language
13
12
  end
@@ -17,7 +16,7 @@ module Script
17
16
  def ask_extension_point
18
17
  CLI::UI::Prompt.ask(
19
18
  @ctx.message("script.forms.create.select_extension_point"),
20
- options: Layers::Application::ExtensionPoints.non_deprecated_types
19
+ options: Layers::Application::ExtensionPoints.available_types
21
20
  )
22
21
  end
23
22
 
@@ -25,10 +24,6 @@ module Script
25
24
  CLI::UI::Prompt.ask(@ctx.message("script.forms.create.script_name"))
26
25
  end
27
26
 
28
- def ask_description
29
- CLI::UI::Prompt.ask(@ctx.message("script.forms.create.description"))
30
- end
31
-
32
27
  def valid_name
33
28
  n = (name || ask_name).downcase.gsub(" ", "_")
34
29
  return n if n.match?(/^[0-9A-Za-z_-]*$/)
@@ -36,13 +31,7 @@ module Script
36
31
  end
37
32
 
38
33
  def ask_language
39
- if language
40
- if Layers::Application::ExtensionPoints.supported_language?(type: extension_point, language: language)
41
- return language.downcase
42
- else
43
- raise Errors::InvalidLanguageError.new(language, extension_point)
44
- end
45
- end
34
+ return language.downcase if language
46
35
 
47
36
  all_languages = Layers::Application::ExtensionPoints.languages(type: extension_point)
48
37
  return all_languages.first if all_languages.count == 1
@@ -1,7 +1,6 @@
1
1
  mutation AppScriptUpdateOrCreate(
2
2
  $extensionPointName: ExtensionPointName!,
3
3
  $title: String,
4
- $description: String,
5
4
  $configUi: String,
6
5
  $sourceCode: String,
7
6
  $language: String,
@@ -13,7 +12,6 @@ mutation AppScriptUpdateOrCreate(
13
12
  appScriptUpdateOrCreate(
14
13
  extensionPointName: $extensionPointName
15
14
  title: $title
16
- description: $description
17
15
  configUi: $configUi
18
16
  sourceCode: $sourceCode
19
17
  language: $language
@@ -32,7 +30,6 @@ mutation AppScriptUpdateOrCreate(
32
30
  configSchema
33
31
  extensionPointName
34
32
  title
35
- description
36
33
  }
37
34
  }
38
35
  }
@@ -1,7 +1,6 @@
1
- query ProxyRequest($api_key: String, $shop_domain: String, $query: String!, $variables: String) {
1
+ query ProxyRequest($api_key: String, $query: String!, $variables: String) {
2
2
  scriptServiceProxy(
3
3
  apiKey: $api_key
4
- shopDomain: $shop_domain
5
4
  query: $query
6
5
  variables: $variables
7
6
  )
@@ -5,7 +5,7 @@ module Script
5
5
  module Application
6
6
  class BuildScript
7
7
  class << self
8
- def call(ctx:, task_runner:, script_project:, config_ui:)
8
+ def call(ctx:, task_runner:, script_project:)
9
9
  CLI::UI::Frame.open(ctx.message("script.application.building")) do
10
10
  begin
11
11
  UI::StrictSpinner.spin(ctx.message("script.application.building_script")) do |spinner|
@@ -14,7 +14,6 @@ module Script
14
14
  script_content: task_runner.build,
15
15
  compiled_type: task_runner.compiled_type,
16
16
  metadata: task_runner.metadata,
17
- config_ui: config_ui,
18
17
  )
19
18
  spinner.update_title(ctx.message("script.application.built"))
20
19
  end
@@ -7,54 +7,27 @@ module Script
7
7
  module Application
8
8
  class CreateScript
9
9
  class << self
10
- def call(ctx:, language:, script_name:, extension_point_type:, description:, no_config_ui:)
11
- extension_point = ExtensionPoints.get(type: extension_point_type)
12
- project = setup_project(
13
- ctx: ctx,
14
- language: language,
15
- script_name: script_name,
16
- extension_point: extension_point,
17
- description: description,
18
- no_config_ui: no_config_ui
19
- )
20
- project_creator = Infrastructure::ProjectCreator
21
- .for(ctx, language, extension_point, script_name, project.directory)
22
- install_dependencies(ctx, language, script_name, project_creator)
23
- bootstrap(ctx, project_creator)
24
- project
10
+ def call(ctx:, language:, script_name:, extension_point_type:, no_config_ui:)
11
+ raise Infrastructure::Errors::ScriptProjectAlreadyExistsError, script_name if ctx.dir_exist?(script_name)
12
+
13
+ in_new_directory_context(ctx, script_name) do
14
+ extension_point = ExtensionPoints.get(type: extension_point_type)
15
+ project = Infrastructure::ScriptProjectRepository.new(ctx: ctx).create(
16
+ script_name: script_name,
17
+ extension_point_type: extension_point_type,
18
+ language: language,
19
+ no_config_ui: no_config_ui
20
+ )
21
+ project_creator = Infrastructure::ProjectCreator
22
+ .for(ctx, language, extension_point, script_name, project.id)
23
+ install_dependencies(ctx, language, script_name, project_creator)
24
+ bootstrap(ctx, project_creator)
25
+ project
26
+ end
25
27
  end
26
28
 
27
29
  private
28
30
 
29
- DEFAULT_CONFIG_UI_FILENAME = "config-ui.yml"
30
-
31
- def setup_project(ctx:, language:, script_name:, extension_point:, description:, no_config_ui:)
32
- ScriptProject.create(ctx, script_name)
33
-
34
- identifiers = {
35
- extension_point_type: extension_point.type,
36
- script_name: script_name,
37
- language: language,
38
- description: description,
39
- }
40
-
41
- unless no_config_ui
42
- require "yaml" # takes 20ms, so deferred as late as possible.
43
- identifiers.merge!(config_ui_file: DEFAULT_CONFIG_UI_FILENAME)
44
- Infrastructure::ConfigUiRepository
45
- .new(ctx: ctx)
46
- .create_config_ui(DEFAULT_CONFIG_UI_FILENAME, default_config_ui_content(script_name))
47
- end
48
-
49
- ScriptProject.write(
50
- ctx,
51
- project_type: :script,
52
- organization_id: nil, # TODO: can you provide this at creation
53
- **identifiers
54
- )
55
- ScriptProject.current
56
- end
57
-
58
31
  def install_dependencies(ctx, language, script_name, project_creator)
59
32
  task_runner = Infrastructure::TaskRunner.for(ctx, language, script_name)
60
33
  project_creator.setup_dependencies
@@ -68,13 +41,19 @@ module Script
68
41
  end
69
42
  end
70
43
 
71
- def default_config_ui_content(title)
72
- YAML.dump({
73
- "version" => 1,
74
- "type" => "single",
75
- "title" => title,
76
- "fields" => [],
77
- })
44
+ def in_new_directory_context(ctx, directory)
45
+ initial_directory = ctx.root
46
+ begin
47
+ ctx.mkdir_p(directory)
48
+ ctx.chdir(directory)
49
+ yield
50
+ rescue
51
+ ctx.chdir(initial_directory)
52
+ ctx.rm_r(directory)
53
+ raise
54
+ ensure
55
+ ctx.chdir(initial_directory)
56
+ end
78
57
  end
79
58
  end
80
59
  end
@@ -12,9 +12,10 @@ module Script
12
12
  Infrastructure::ExtensionPointRepository.new.extension_point_types
13
13
  end
14
14
 
15
- def self.non_deprecated_types
15
+ def self.available_types
16
16
  Infrastructure::ExtensionPointRepository.new.extension_points.select do |ep|
17
- !ep.deprecated?
17
+ next false if ep.deprecated?
18
+ !ep.beta? || ShopifyCli::Feature.enabled?(:scripts_beta_extension_points)
18
19
  end.map(&:type)
19
20
  end
20
21