shopify-cli 1.7.1 → 1.11.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.
- checksums.yaml +4 -4
- data/.github/PULL_REQUEST_TEMPLATE.md +1 -0
- data/.github/workflows/build.yml +28 -0
- data/.rubocop_todo.yml +15 -2
- data/CHANGELOG.md +25 -0
- data/Gemfile.lock +15 -15
- data/README.md +2 -1
- data/dev.yml +3 -0
- data/lib/docgen/markdown.rb +1 -1
- data/lib/graphql/extension_create.graphql +17 -2
- data/lib/graphql/fetch_specifications.graphql +14 -0
- data/lib/project_types/extension/cli.rb +8 -10
- data/lib/project_types/extension/commands/create.rb +2 -2
- data/lib/project_types/extension/commands/extension_command.rb +10 -6
- data/lib/project_types/extension/commands/push.rb +2 -2
- data/lib/project_types/extension/commands/register.rb +6 -5
- data/lib/project_types/extension/commands/serve.rb +64 -22
- data/lib/project_types/extension/commands/tunnel.rb +3 -1
- data/lib/project_types/extension/extension_project.rb +20 -4
- data/lib/project_types/extension/extension_project_keys.rb +2 -1
- data/lib/project_types/extension/features/argo.rb +19 -44
- data/lib/project_types/extension/features/argo_runtime.rb +63 -0
- data/lib/project_types/extension/features/argo_serve.rb +79 -0
- data/lib/project_types/extension/features/argo_serve_options.rb +40 -0
- data/lib/project_types/extension/features/argo_setup.rb +1 -1
- data/lib/project_types/extension/forms/questions/ask_type.rb +16 -5
- data/lib/project_types/extension/messages/message_loading.rb +3 -1
- data/lib/project_types/extension/messages/messages.rb +9 -6
- data/lib/project_types/extension/models/npm_package.rb +14 -0
- data/lib/project_types/extension/models/registration.rb +1 -0
- data/lib/project_types/extension/models/specification.rb +7 -2
- data/lib/project_types/extension/models/specification_handlers/checkout_argo_extension.rb +18 -0
- data/lib/project_types/extension/models/specification_handlers/default.rb +35 -2
- data/lib/project_types/extension/models/specifications.rb +12 -1
- data/lib/project_types/extension/models/version.rb +1 -1
- data/lib/project_types/extension/tasks/choose_next_available_port.rb +36 -0
- data/lib/project_types/extension/tasks/configure_features.rb +5 -1
- data/lib/project_types/extension/tasks/converters/registration_converter.rb +2 -0
- data/lib/project_types/extension/tasks/fetch_specifications.rb +8 -28
- data/lib/project_types/extension/tasks/find_npm_packages.rb +106 -0
- data/lib/project_types/node/commands/generate.rb +0 -22
- data/lib/project_types/node/forms/create.rb +10 -1
- data/lib/project_types/node/messages/messages.rb +5 -4
- data/lib/project_types/rails/forms/create.rb +11 -1
- data/lib/project_types/rails/messages/messages.rb +5 -4
- data/lib/project_types/script/cli.rb +7 -8
- data/lib/project_types/script/commands/create.rb +0 -7
- data/lib/project_types/script/commands/push.rb +3 -3
- data/lib/project_types/script/config/extension_points.yml +17 -0
- data/lib/project_types/script/errors.rb +0 -19
- data/lib/project_types/script/forms/create.rb +3 -14
- data/lib/project_types/script/graphql/app_script_update_or_create.graphql +5 -5
- data/lib/project_types/script/graphql/get_app_scripts.graphql +6 -0
- data/lib/project_types/script/graphql/script_service_proxy.graphql +1 -2
- data/lib/project_types/script/layers/application/build_script.rb +1 -2
- data/lib/project_types/script/layers/application/create_script.rb +32 -49
- data/lib/project_types/script/layers/application/extension_points.rb +3 -2
- data/lib/project_types/script/layers/application/push_script.rb +5 -5
- data/lib/project_types/script/layers/domain/errors.rb +0 -2
- data/lib/project_types/script/layers/domain/extension_point.rb +60 -45
- data/lib/project_types/script/layers/domain/metadata.rb +18 -25
- data/lib/project_types/script/layers/domain/push_package.rb +4 -4
- data/lib/project_types/script/layers/domain/script_project.rb +54 -0
- data/lib/project_types/script/layers/infrastructure/assemblyscript_project_creator.rb +39 -14
- data/lib/project_types/script/layers/infrastructure/assemblyscript_task_runner.rb +14 -43
- data/lib/project_types/script/layers/infrastructure/command_runner.rb +19 -0
- data/lib/project_types/script/layers/infrastructure/errors.rb +40 -20
- data/lib/project_types/script/layers/infrastructure/push_package_repository.rb +12 -13
- data/lib/project_types/script/layers/infrastructure/rust_project_creator.rb +9 -10
- data/lib/project_types/script/layers/infrastructure/rust_task_runner.rb +6 -7
- data/lib/project_types/script/layers/infrastructure/script_project_repository.rb +172 -0
- data/lib/project_types/script/layers/infrastructure/script_service.rb +25 -76
- data/lib/project_types/script/messages/messages.rb +20 -53
- data/lib/project_types/script/tasks/ensure_env.rb +85 -0
- data/lib/project_types/script/ui/error_handler.rb +32 -41
- data/lib/shopify-cli/context.rb +28 -0
- data/lib/shopify-cli/js_system.rb +2 -2
- data/lib/shopify-cli/messages/messages.rb +50 -45
- data/lib/shopify-cli/method_object.rb +4 -4
- data/lib/shopify-cli/oauth.rb +9 -3
- data/lib/shopify-cli/packager.rb +1 -1
- data/lib/shopify-cli/partners_api/organizations.rb +3 -3
- data/lib/shopify-cli/resolve_constant.rb +1 -1
- data/lib/shopify-cli/resources/env_file.rb +1 -1
- data/lib/shopify-cli/tasks/ensure_dev_store.rb +1 -1
- data/lib/shopify-cli/tasks/select_org_and_shop.rb +6 -4
- data/lib/shopify-cli/transform_data_structure.rb +2 -2
- data/lib/shopify-cli/tunnel.rb +22 -1
- data/lib/shopify-cli/version.rb +1 -1
- data/lib/shopify_cli.rb +0 -1
- data/vendor/deps/smart_properties/REVISION +1 -1
- data/vendor/deps/smart_properties/lib/smart_properties/property.rb +7 -1
- data/vendor/deps/smart_properties/lib/smart_properties/version.rb +1 -1
- metadata +17 -12
- data/.travis.yml +0 -14
- data/lib/project_types/script/commands/disable.rb +0 -25
- data/lib/project_types/script/commands/enable.rb +0 -80
- data/lib/project_types/script/graphql/shop_script_delete.graphql +0 -14
- data/lib/project_types/script/graphql/shop_script_update_or_create.graphql +0 -28
- data/lib/project_types/script/layers/application/disable_script.rb +0 -21
- data/lib/project_types/script/layers/application/enable_script.rb +0 -23
- data/lib/project_types/script/layers/infrastructure/config_ui_repository.rb +0 -46
- data/lib/project_types/script/script_project.rb +0 -64
|
@@ -11,11 +11,11 @@ module Script
|
|
|
11
11
|
property! :ctx, accepts: ShopifyCli::Context
|
|
12
12
|
|
|
13
13
|
def push(
|
|
14
|
+
uuid:,
|
|
14
15
|
extension_point_type:,
|
|
15
16
|
script_name:,
|
|
16
17
|
script_content:,
|
|
17
18
|
compiled_type:,
|
|
18
|
-
description: nil,
|
|
19
19
|
api_key: nil,
|
|
20
20
|
force: false,
|
|
21
21
|
metadata:,
|
|
@@ -23,10 +23,10 @@ module Script
|
|
|
23
23
|
)
|
|
24
24
|
query_name = "app_script_update_or_create"
|
|
25
25
|
variables = {
|
|
26
|
+
uuid: uuid,
|
|
26
27
|
extensionPointName: extension_point_type.upcase,
|
|
27
28
|
title: script_name,
|
|
28
|
-
|
|
29
|
-
configUi: config_ui.content,
|
|
29
|
+
configUi: config_ui&.content,
|
|
30
30
|
sourceCode: Base64.encode64(script_content),
|
|
31
31
|
language: compiled_type,
|
|
32
32
|
force: force,
|
|
@@ -37,104 +37,53 @@ module Script
|
|
|
37
37
|
resp_hash = script_service_request(query_name: query_name, api_key: api_key, variables: variables)
|
|
38
38
|
user_errors = resp_hash["data"]["appScriptUpdateOrCreate"]["userErrors"]
|
|
39
39
|
|
|
40
|
-
return resp_hash if user_errors.empty?
|
|
40
|
+
return resp_hash["data"]["appScriptUpdateOrCreate"]["appScript"]["uuid"] if user_errors.empty?
|
|
41
41
|
|
|
42
42
|
if user_errors.any? { |e| e["tag"] == "already_exists_error" }
|
|
43
|
-
raise Errors::ScriptRepushError,
|
|
43
|
+
raise Errors::ScriptRepushError, uuid
|
|
44
44
|
elsif (e = user_errors.any? { |err| err["tag"] == "config_ui_syntax_error" })
|
|
45
|
-
raise Errors::ConfigUiSyntaxError, config_ui
|
|
45
|
+
raise Errors::ConfigUiSyntaxError, config_ui&.filename
|
|
46
46
|
elsif (e = user_errors.find { |err| err["tag"] == "config_ui_missing_keys_error" })
|
|
47
|
-
raise Errors::ConfigUiMissingKeysError.new(config_ui
|
|
47
|
+
raise Errors::ConfigUiMissingKeysError.new(config_ui&.filename, e["message"])
|
|
48
|
+
elsif (e = user_errors.find { |err| err["tag"] == "config_ui_invalid_input_mode_error" })
|
|
49
|
+
raise Errors::ConfigUiInvalidInputModeError.new(config_ui&.filename, e["message"])
|
|
48
50
|
elsif (e = user_errors.find { |err| err["tag"] == "config_ui_fields_missing_keys_error" })
|
|
49
|
-
raise Errors::ConfigUiFieldsMissingKeysError.new(config_ui
|
|
51
|
+
raise Errors::ConfigUiFieldsMissingKeysError.new(config_ui&.filename, e["message"])
|
|
52
|
+
elsif (e = user_errors.find { |err| err["tag"] == "config_ui_fields_invalid_type_error" })
|
|
53
|
+
raise Errors::ConfigUiFieldsInvalidTypeError.new(config_ui&.filename, e["message"])
|
|
54
|
+
elsif user_errors.find { |err| %w(not_use_msgpack_error schema_version_argument_error).include?(err["tag"]) }
|
|
55
|
+
raise Domain::Errors::MetadataValidationError
|
|
50
56
|
else
|
|
51
|
-
raise Errors::
|
|
57
|
+
raise Errors::GraphqlError, user_errors
|
|
52
58
|
end
|
|
53
59
|
end
|
|
54
60
|
|
|
55
|
-
def
|
|
56
|
-
query_name = "
|
|
57
|
-
variables = {
|
|
58
|
-
|
|
59
|
-
configuration: configuration,
|
|
60
|
-
title: title,
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
resp_hash = script_service_request(
|
|
64
|
-
query_name: query_name,
|
|
65
|
-
api_key: api_key,
|
|
66
|
-
shop_domain: format_shop_domain(shop_domain),
|
|
67
|
-
variables: variables,
|
|
68
|
-
)
|
|
69
|
-
user_errors = resp_hash["data"]["shopScriptUpdateOrCreate"]["userErrors"]
|
|
70
|
-
|
|
71
|
-
return resp_hash if user_errors.empty?
|
|
72
|
-
|
|
73
|
-
if user_errors.any? { |e| e["tag"] == "app_script_not_found" }
|
|
74
|
-
raise Errors::AppScriptUndefinedError, api_key
|
|
75
|
-
elsif user_errors.any? { |e| e["tag"] == "shop_script_conflict" }
|
|
76
|
-
raise Errors::ShopScriptConflictError
|
|
77
|
-
elsif user_errors.any? { |e| e["tag"] == "app_script_not_pushed" }
|
|
78
|
-
raise Errors::AppScriptNotPushedError
|
|
79
|
-
else
|
|
80
|
-
raise Errors::ScriptServiceUserError.new(query_name, user_errors.to_s)
|
|
81
|
-
end
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
def disable(api_key:, shop_domain:, extension_point_type:)
|
|
85
|
-
query_name = "shop_script_delete"
|
|
86
|
-
variables = {
|
|
87
|
-
extensionPointName: extension_point_type.upcase,
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
resp_hash = script_service_request(
|
|
91
|
-
query_name: query_name,
|
|
92
|
-
api_key: api_key,
|
|
93
|
-
shop_domain: format_shop_domain(shop_domain),
|
|
94
|
-
variables: variables,
|
|
95
|
-
)
|
|
96
|
-
user_errors = resp_hash["data"]["shopScriptDelete"]["userErrors"]
|
|
97
|
-
return resp_hash if user_errors.empty?
|
|
98
|
-
|
|
99
|
-
if user_errors.any? { |e| e["tag"] == "shop_script_not_found" }
|
|
100
|
-
raise Errors::ShopScriptUndefinedError, api_key
|
|
101
|
-
else
|
|
102
|
-
raise Errors::ScriptServiceUserError.new(query_name, user_errors.to_s)
|
|
103
|
-
end
|
|
61
|
+
def get_app_scripts(api_key:, extension_point_type:)
|
|
62
|
+
query_name = "get_app_scripts"
|
|
63
|
+
variables = { appKey: api_key, extensionPointName: extension_point_type.upcase }
|
|
64
|
+
script_service_request(query_name: query_name, api_key: api_key, variables: variables)["data"]["appScripts"]
|
|
104
65
|
end
|
|
105
66
|
|
|
106
67
|
private
|
|
107
68
|
|
|
108
|
-
def format_shop_domain(shop_domain)
|
|
109
|
-
shop_domain.delete_suffix("/")
|
|
110
|
-
end
|
|
111
|
-
|
|
112
69
|
class ScriptServiceAPI < ShopifyCli::API
|
|
113
70
|
property(:api_key, accepts: String)
|
|
114
|
-
property(:shop_id, accepts: Integer)
|
|
115
71
|
|
|
116
|
-
def self.query(ctx, query_name, api_key: nil,
|
|
117
|
-
api_client(ctx, api_key
|
|
72
|
+
def self.query(ctx, query_name, api_key: nil, variables: {})
|
|
73
|
+
api_client(ctx, api_key).query(query_name, variables: variables)
|
|
118
74
|
end
|
|
119
75
|
|
|
120
|
-
def self.api_client(ctx, api_key
|
|
76
|
+
def self.api_client(ctx, api_key)
|
|
121
77
|
new(
|
|
122
78
|
ctx: ctx,
|
|
123
79
|
url: "https://script-service.myshopify.io/graphql",
|
|
124
80
|
token: "",
|
|
125
|
-
api_key: api_key
|
|
126
|
-
shop_id: infer_shop_id(shop_domain)
|
|
81
|
+
api_key: api_key
|
|
127
82
|
)
|
|
128
83
|
end
|
|
129
84
|
|
|
130
|
-
def self.infer_shop_id(shop_domain)
|
|
131
|
-
return unless shop_domain
|
|
132
|
-
|
|
133
|
-
[shop_domain.to_i, 1].max
|
|
134
|
-
end
|
|
135
|
-
|
|
136
85
|
def auth_headers(*)
|
|
137
|
-
tokens = { "APP_KEY" => api_key
|
|
86
|
+
tokens = { "APP_KEY" => api_key }.compact.to_json
|
|
138
87
|
{ "X-Shopify-Authenticated-Tokens" => tokens }
|
|
139
88
|
end
|
|
140
89
|
end
|
|
@@ -177,7 +126,7 @@ module Script
|
|
|
177
126
|
when "app_not_installed_on_shop"
|
|
178
127
|
raise Errors::AppNotInstalledError
|
|
179
128
|
else
|
|
180
|
-
raise Errors::GraphqlError, response["errors"]
|
|
129
|
+
raise Errors::GraphqlError, response["errors"]
|
|
181
130
|
end
|
|
182
131
|
end
|
|
183
132
|
|
|
@@ -64,17 +64,22 @@ module Script
|
|
|
64
64
|
"%{missing_keys}.",
|
|
65
65
|
config_ui_missing_keys_error_help: "Add the keys and try again.",
|
|
66
66
|
|
|
67
|
+
config_ui_invalid_input_mode_error_cause: "The UI configuration file %{filename} only accept "\
|
|
68
|
+
"one of the following input mode(s): %{valid_input_modes}.",
|
|
69
|
+
config_ui_invalid_input_mode_error_help: "Change the input modes and try again.",
|
|
70
|
+
|
|
67
71
|
config_ui_fields_missing_keys_error_cause: "A field entry in the UI configuration file %{filename} is "\
|
|
68
72
|
"missing required keys: %{missing_keys}.",
|
|
69
73
|
config_ui_fields_missing_keys_error_help: "Add the keys and try again.",
|
|
70
74
|
|
|
71
|
-
|
|
75
|
+
config_ui_fields_invalid_type_error_cause: "The UI configuration file %{filename} fields only accept "\
|
|
76
|
+
"one of the following type(s): %{valid_types}.",
|
|
77
|
+
config_ui_fields_invalid_type_error_help: "Change the types and try again.",
|
|
72
78
|
|
|
73
|
-
|
|
74
|
-
service_failure_help: "Ensure the 'shopify/scripts-toolchain-as' package is up to date.",
|
|
79
|
+
script_not_found_cause: "Couldn't find script %s for extension point %s",
|
|
75
80
|
|
|
76
|
-
|
|
77
|
-
|
|
81
|
+
system_call_failure_cause: "An error was returned while running {{command:%{cmd}}}.",
|
|
82
|
+
system_call_failure_help: "Review the following error and try again.\n{{red:%{out}}}",
|
|
78
83
|
|
|
79
84
|
metadata_validation_cause: "Invalid script extension metadata.",
|
|
80
85
|
metadata_validation_help: "Ensure the 'shopify/scripts-toolchain-as' package is up to date.",
|
|
@@ -94,8 +99,6 @@ module Script
|
|
|
94
99
|
"'--metadata build/metadata.json' argument",
|
|
95
100
|
app_not_installed_cause: "App not installed on store.",
|
|
96
101
|
|
|
97
|
-
app_script_not_pushed_help: "Script isn't on the app. Run {{command:shopify push}}, and then try again.",
|
|
98
|
-
|
|
99
102
|
build_error_cause: "Something went wrong while building the script.",
|
|
100
103
|
build_error_help: "Correct the errors and try again.",
|
|
101
104
|
|
|
@@ -110,21 +113,12 @@ module Script
|
|
|
110
113
|
graphql_error_cause: "An error was returned: %s.",
|
|
111
114
|
graphql_error_help: "\nReview the error and try again.",
|
|
112
115
|
|
|
113
|
-
script_repush_cause: "A script with
|
|
116
|
+
script_repush_cause: "A script with this UUID already exists (UUID: %s).",
|
|
114
117
|
script_repush_help: "Use {{cyan:--force}} to replace the existing script.",
|
|
115
118
|
|
|
116
119
|
shop_auth_cause: "Unable to authenticate with the store.",
|
|
117
120
|
shop_auth_help: "Try again.",
|
|
118
121
|
|
|
119
|
-
shop_script_conflict_cause: "Another app in this store has already enabled a script "\
|
|
120
|
-
"on this extension point.",
|
|
121
|
-
shop_script_conflict_help: "Disable that script or uninstall that app and try again.",
|
|
122
|
-
|
|
123
|
-
shop_script_undefined_cause: "Script is already turned off in store.",
|
|
124
|
-
|
|
125
|
-
packages_outdated_cause: "These npm packages are out of date: %s.",
|
|
126
|
-
packages_outdated_help: "To update them, run {{cyan:npm install --save-dev %s}}.",
|
|
127
|
-
|
|
128
122
|
invalid_build_script: "The root package.json contains an invalid build command that " \
|
|
129
123
|
"is needed to compile your script to WebAssembly.",
|
|
130
124
|
build_script_not_found: "The root package.json is missing the build command that " \
|
|
@@ -145,7 +139,6 @@ module Script
|
|
|
145
139
|
Usage: {{command:%1$s create script}}
|
|
146
140
|
Options:
|
|
147
141
|
{{command:--name=NAME}} Script project name. Use any string.
|
|
148
|
-
{{command:--description=DESCRIPTION}} Description of the project. Use any string.
|
|
149
142
|
{{command:--extension-point=TYPE}} Extension point name. Allowed values: %2$s.
|
|
150
143
|
{{command:--no-config-ui}} Specify this option if you don’t want Scripts to render an interface in the Shopify admin.
|
|
151
144
|
HELP
|
|
@@ -174,40 +167,6 @@ module Script
|
|
|
174
167
|
script_pushed: "{{v}} Script pushed to app (API key: %{api_key}).",
|
|
175
168
|
},
|
|
176
169
|
|
|
177
|
-
disable: {
|
|
178
|
-
help: <<~HELP,
|
|
179
|
-
Turn off script in store.
|
|
180
|
-
Usage: {{command:%s disable}}
|
|
181
|
-
HELP
|
|
182
|
-
|
|
183
|
-
error: {
|
|
184
|
-
operation_failed: "Can't disable script.",
|
|
185
|
-
},
|
|
186
|
-
|
|
187
|
-
script_disabled: "{{v}} Script disabled. Script is turned off in store.",
|
|
188
|
-
},
|
|
189
|
-
|
|
190
|
-
enable: {
|
|
191
|
-
help: <<~HELP,
|
|
192
|
-
Turn on script in store.
|
|
193
|
-
Usage: {{command:%s enable}}
|
|
194
|
-
Options:
|
|
195
|
-
{{command:--config-props='name1:value1, name2:value2'}} Optional. Define the configuration of your script by passing individual name and value pairs. If used with --config_file, then matching values in --config-props will override those set in the file.
|
|
196
|
-
{{command:--config_file=<path/to/YAMLFilename>}} Optional. Define the configuration of your script using a YAML formatted file. --config-props values override properties in this file.
|
|
197
|
-
HELP
|
|
198
|
-
|
|
199
|
-
info: "{{*}} A script always remains enabled until you disable it - even after pushing "\
|
|
200
|
-
"script changes with the same extension point to an app. To disable a script, use "\
|
|
201
|
-
"the 'disable' command.",
|
|
202
|
-
|
|
203
|
-
error: {
|
|
204
|
-
operation_failed: "Can't enable script.",
|
|
205
|
-
},
|
|
206
|
-
|
|
207
|
-
script_enabled: "{{v}} Script enabled. %{type} script %{title} in app (API key: %{api_key}) "\
|
|
208
|
-
"is turned on in store {{green:%{shop_domain}}}",
|
|
209
|
-
},
|
|
210
|
-
|
|
211
170
|
project_deps: {
|
|
212
171
|
none_required: "{{v}} None required",
|
|
213
172
|
checking_with_npm: "Checking dependencies with npm",
|
|
@@ -220,7 +179,6 @@ module Script
|
|
|
220
179
|
select_extension_point: "Which extension point do you want to use?",
|
|
221
180
|
select_language: "Which language do you want to use?",
|
|
222
181
|
script_name: "Script Name",
|
|
223
|
-
description: "Description",
|
|
224
182
|
},
|
|
225
183
|
},
|
|
226
184
|
|
|
@@ -234,6 +192,15 @@ module Script
|
|
|
234
192
|
disabled: "Disabled",
|
|
235
193
|
enabling: "Enabling",
|
|
236
194
|
enabled: "Enabled",
|
|
195
|
+
ensure_env: {
|
|
196
|
+
organization: "Partner organization {{green:%s (%s)}}.",
|
|
197
|
+
organization_select: "Which partner organization do you want to use?",
|
|
198
|
+
app: "Script will be pushed to app {{green:%s}}.",
|
|
199
|
+
app_select: "Which app do you want to push this script to?",
|
|
200
|
+
ask_connect_to_existing_script: "The selected app has some scripts. Do you want to replace any of the "\
|
|
201
|
+
"existing scripts with the current script?",
|
|
202
|
+
ask_which_script_to_connect_to: "Which script do you want to replace?",
|
|
203
|
+
},
|
|
237
204
|
},
|
|
238
205
|
},
|
|
239
206
|
}.freeze
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
require "shopify_cli"
|
|
2
|
+
|
|
3
|
+
module Script
|
|
4
|
+
module Tasks
|
|
5
|
+
class EnsureEnv < ShopifyCli::Task
|
|
6
|
+
attr_accessor :ctx
|
|
7
|
+
|
|
8
|
+
def call(ctx)
|
|
9
|
+
self.ctx = ctx
|
|
10
|
+
|
|
11
|
+
script_project_repo = Layers::Infrastructure::ScriptProjectRepository.new(ctx: ctx)
|
|
12
|
+
script_project = script_project_repo.get
|
|
13
|
+
|
|
14
|
+
return if script_project.api_key && script_project.api_secret && script_project.uuid_defined?
|
|
15
|
+
|
|
16
|
+
org = ask_org
|
|
17
|
+
app = ask_app(org["apps"])
|
|
18
|
+
uuid = ask_script_uuid(app, script_project.extension_point_type)
|
|
19
|
+
|
|
20
|
+
script_project_repo.create_env(
|
|
21
|
+
api_key: app["apiKey"],
|
|
22
|
+
secret: app["apiSecretKeys"].first["secret"],
|
|
23
|
+
uuid: uuid
|
|
24
|
+
)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
private
|
|
28
|
+
|
|
29
|
+
def ask_org
|
|
30
|
+
if ShopifyCli::Shopifolk.check && wants_to_run_against_shopify_org?
|
|
31
|
+
ShopifyCli::Shopifolk.act_as_shopify_organization
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
orgs = ShopifyCli::PartnersAPI::Organizations.fetch_with_app(ctx)
|
|
35
|
+
if orgs.count == 1
|
|
36
|
+
default = orgs.first
|
|
37
|
+
ctx.puts(ctx.message("script.application.ensure_env.organization", default["businessName"], default["id"]))
|
|
38
|
+
default
|
|
39
|
+
elsif orgs.count > 0
|
|
40
|
+
CLI::UI::Prompt.ask(ctx.message("script.application.ensure_env.organization_select")) do |handler|
|
|
41
|
+
orgs.each do |org|
|
|
42
|
+
handler.option("#{org["businessName"]} (#{org["id"]})") { org }
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
else
|
|
46
|
+
raise Errors::NoExistingOrganizationsError
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def ask_app(apps)
|
|
51
|
+
unless ShopifyCli::Shopifolk.acting_as_shopify_organization?
|
|
52
|
+
apps = apps.select { |app| app["appType"] == "custom" }
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
if apps.count == 1
|
|
56
|
+
default = apps.first
|
|
57
|
+
ctx.puts(ctx.message("script.application.ensure_env.app", default["title"]))
|
|
58
|
+
default
|
|
59
|
+
elsif apps.count > 0
|
|
60
|
+
CLI::UI::Prompt.ask(ctx.message("script.application.ensure_env.app_select")) do |handler|
|
|
61
|
+
apps.each do |app|
|
|
62
|
+
handler.option(app["title"]) { app }
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
else
|
|
66
|
+
raise Errors::NoExistingAppsError
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def ask_script_uuid(app, extension_point_type)
|
|
71
|
+
script_service = Layers::Infrastructure::ScriptService.new(ctx: ctx)
|
|
72
|
+
scripts = script_service.get_app_scripts(api_key: app["apiKey"], extension_point_type: extension_point_type)
|
|
73
|
+
|
|
74
|
+
return nil unless scripts.count > 0 &&
|
|
75
|
+
CLI::UI::Prompt.confirm(ctx.message("script.application.ensure_env.ask_connect_to_existing_script"))
|
|
76
|
+
|
|
77
|
+
CLI::UI::Prompt.ask(ctx.message("script.application.ensure_env.ask_which_script_to_connect_to")) do |handler|
|
|
78
|
+
scripts.each do |script|
|
|
79
|
+
handler.option("#{script["title"]} (#{script["uuid"]})") { script["uuid"] }
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
@@ -39,7 +39,7 @@ module Script
|
|
|
39
39
|
cause_of_error: ShopifyCli::Context.message("script.error.oauth_cause"),
|
|
40
40
|
help_suggestion: ShopifyCli::Context.message("script.error.oauth_help"),
|
|
41
41
|
}
|
|
42
|
-
when Errors::InvalidContextError
|
|
42
|
+
when Layers::Infrastructure::Errors::InvalidContextError
|
|
43
43
|
{
|
|
44
44
|
cause_of_error: ShopifyCli::Context.message("script.error.invalid_context_cause"),
|
|
45
45
|
help_suggestion: ShopifyCli::Context.message("script.error.invalid_context_help"),
|
|
@@ -53,7 +53,7 @@ module Script
|
|
|
53
53
|
{
|
|
54
54
|
cause_of_error: ShopifyCli::Context.message("script.error.invalid_config", e.config_file),
|
|
55
55
|
}
|
|
56
|
-
when Errors::InvalidLanguageError
|
|
56
|
+
when Layers::Infrastructure::Errors::InvalidLanguageError
|
|
57
57
|
{
|
|
58
58
|
cause_of_error: ShopifyCli::Context.message("script.error.invalid_language_cause", e.language),
|
|
59
59
|
help_suggestion: ShopifyCli::Context.message(
|
|
@@ -84,12 +84,12 @@ module Script
|
|
|
84
84
|
organization_id: e.organization_id
|
|
85
85
|
),
|
|
86
86
|
}
|
|
87
|
-
when Errors::ScriptProjectAlreadyExistsError
|
|
87
|
+
when Layers::Infrastructure::Errors::ScriptProjectAlreadyExistsError
|
|
88
88
|
{
|
|
89
89
|
cause_of_error: ShopifyCli::Context.message("script.error.project_exists_cause"),
|
|
90
90
|
help_suggestion: ShopifyCli::Context.message("script.error.project_exists_help"),
|
|
91
91
|
}
|
|
92
|
-
when Errors::DeprecatedEPError
|
|
92
|
+
when Layers::Infrastructure::Errors::DeprecatedEPError
|
|
93
93
|
{
|
|
94
94
|
cause_of_error: ShopifyCli::Context.message("script.error.deprecated_ep", e.ep),
|
|
95
95
|
help_suggestion: ShopifyCli::Context.message("script.error.deprecated_ep_cause"),
|
|
@@ -110,11 +110,6 @@ module Script
|
|
|
110
110
|
e.extension_point_type
|
|
111
111
|
),
|
|
112
112
|
}
|
|
113
|
-
when Layers::Domain::Errors::ServiceFailureError
|
|
114
|
-
{
|
|
115
|
-
cause_of_error: ShopifyCli::Context.message("script.error.service_failure_cause"),
|
|
116
|
-
help_suggestion: ShopifyCli::Context.message("script.error.service_failure_help"),
|
|
117
|
-
}
|
|
118
113
|
when Layers::Domain::Errors::MetadataValidationError
|
|
119
114
|
{
|
|
120
115
|
cause_of_error: ShopifyCli::Context.message("script.error.metadata_validation_cause"),
|
|
@@ -141,11 +136,6 @@ module Script
|
|
|
141
136
|
{
|
|
142
137
|
cause_of_error: ShopifyCli::Context.message("script.error.app_not_installed_cause"),
|
|
143
138
|
}
|
|
144
|
-
when Layers::Infrastructure::Errors::AppScriptNotPushedError,
|
|
145
|
-
Layers::Infrastructure::Errors::AppScriptUndefinedError
|
|
146
|
-
{
|
|
147
|
-
cause_of_error: ShopifyCli::Context.message("script.error.app_script_not_pushed_help"),
|
|
148
|
-
}
|
|
149
139
|
when Layers::Infrastructure::Errors::BuildError
|
|
150
140
|
{
|
|
151
141
|
cause_of_error: ShopifyCli::Context.message("script.error.build_error_cause"),
|
|
@@ -168,6 +158,15 @@ module Script
|
|
|
168
158
|
),
|
|
169
159
|
help_suggestion: ShopifyCli::Context.message("script.error.config_ui_missing_keys_error_help"),
|
|
170
160
|
}
|
|
161
|
+
when Layers::Infrastructure::Errors::ConfigUiInvalidInputModeError
|
|
162
|
+
{
|
|
163
|
+
cause_of_error: ShopifyCli::Context.message(
|
|
164
|
+
"script.error.config_ui_invalid_input_mode_error_cause",
|
|
165
|
+
filename: e.filename,
|
|
166
|
+
valid_input_modes: e.valid_input_modes
|
|
167
|
+
),
|
|
168
|
+
help_suggestion: ShopifyCli::Context.message("script.error.config_ui_invalid_input_mode_error_help"),
|
|
169
|
+
}
|
|
171
170
|
when Layers::Infrastructure::Errors::ConfigUiFieldsMissingKeysError
|
|
172
171
|
{
|
|
173
172
|
cause_of_error: ShopifyCli::Context.message(
|
|
@@ -177,6 +176,15 @@ module Script
|
|
|
177
176
|
),
|
|
178
177
|
help_suggestion: ShopifyCli::Context.message("script.error.config_ui_fields_missing_keys_error_help"),
|
|
179
178
|
}
|
|
179
|
+
when Layers::Infrastructure::Errors::ConfigUiFieldsInvalidTypeError
|
|
180
|
+
{
|
|
181
|
+
cause_of_error: ShopifyCli::Context.message(
|
|
182
|
+
"script.error.config_ui_fields_invalid_type_error_cause",
|
|
183
|
+
filename: e.filename,
|
|
184
|
+
valid_types: e.valid_types
|
|
185
|
+
),
|
|
186
|
+
help_suggestion: ShopifyCli::Context.message("script.error.config_ui_fields_invalid_type_error_help"),
|
|
187
|
+
}
|
|
180
188
|
when Layers::Infrastructure::Errors::DependencyInstallError
|
|
181
189
|
{
|
|
182
190
|
cause_of_error: ShopifyCli::Context.message("script.error.dependency_install_cause"),
|
|
@@ -193,44 +201,27 @@ module Script
|
|
|
193
201
|
}
|
|
194
202
|
when Layers::Infrastructure::Errors::GraphqlError
|
|
195
203
|
{
|
|
196
|
-
cause_of_error: ShopifyCli::Context.message(
|
|
204
|
+
cause_of_error: ShopifyCli::Context.message(
|
|
205
|
+
"script.error.graphql_error_cause", JSON.pretty_generate(e.errors)
|
|
206
|
+
),
|
|
197
207
|
help_suggestion: ShopifyCli::Context.message("script.error.graphql_error_help"),
|
|
198
208
|
}
|
|
199
|
-
when Layers::Infrastructure::Errors::
|
|
209
|
+
when Layers::Infrastructure::Errors::SystemCallFailureError
|
|
200
210
|
{
|
|
201
|
-
cause_of_error: ShopifyCli::Context
|
|
202
|
-
|
|
211
|
+
cause_of_error: ShopifyCli::Context
|
|
212
|
+
.message("script.error.system_call_failure_cause", cmd: e.cmd),
|
|
213
|
+
help_suggestion: ShopifyCli::Context.message("script.error.system_call_failure_help", out: e.out),
|
|
203
214
|
}
|
|
204
|
-
when Layers::Infrastructure::Errors::
|
|
215
|
+
when Layers::Infrastructure::Errors::ScriptRepushError
|
|
205
216
|
{
|
|
206
|
-
cause_of_error: ShopifyCli::Context.message("script.error.
|
|
207
|
-
help_suggestion: ShopifyCli::Context.message("script.error.
|
|
217
|
+
cause_of_error: ShopifyCli::Context.message("script.error.script_repush_cause", e.uuid),
|
|
218
|
+
help_suggestion: ShopifyCli::Context.message("script.error.script_repush_help"),
|
|
208
219
|
}
|
|
209
220
|
when Layers::Infrastructure::Errors::ShopAuthenticationError
|
|
210
221
|
{
|
|
211
222
|
cause_of_error: ShopifyCli::Context.message("script.error.shop_auth_cause"),
|
|
212
223
|
help_suggestion: ShopifyCli::Context.message("script.error.shop_auth_help"),
|
|
213
224
|
}
|
|
214
|
-
when Layers::Infrastructure::Errors::ShopScriptConflictError
|
|
215
|
-
{
|
|
216
|
-
cause_of_error: ShopifyCli::Context.message("script.error.shop_script_conflict_cause"),
|
|
217
|
-
help_suggestion: ShopifyCli::Context.message("script.error.shop_script_conflict_help"),
|
|
218
|
-
}
|
|
219
|
-
when Layers::Infrastructure::Errors::ShopScriptUndefinedError
|
|
220
|
-
{
|
|
221
|
-
cause_of_error: ShopifyCli::Context.message("script.error.shop_script_undefined_cause"),
|
|
222
|
-
}
|
|
223
|
-
when Layers::Infrastructure::Errors::PackagesOutdatedError
|
|
224
|
-
{
|
|
225
|
-
cause_of_error: ShopifyCli::Context.message(
|
|
226
|
-
"script.error.packages_outdated_cause",
|
|
227
|
-
e.outdated_packages.join(", ")
|
|
228
|
-
),
|
|
229
|
-
help_suggestion: ShopifyCli::Context.message(
|
|
230
|
-
"script.error.packages_outdated_help",
|
|
231
|
-
e.outdated_packages.collect { |package| "#{package}@latest" }.join(" ")
|
|
232
|
-
),
|
|
233
|
-
}
|
|
234
225
|
when Layers::Infrastructure::Errors::BuildScriptNotFoundError
|
|
235
226
|
{
|
|
236
227
|
cause_of_error: ShopifyCli::Context.message("script.error.build_script_not_found"),
|