shopify-cli 2.2.1 → 2.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/lib/project_types/script/graphql/app_script_set.graphql +40 -0
- data/lib/project_types/script/graphql/app_script_update_or_create.graphql +0 -44
- data/lib/project_types/script/graphql/module_upload_url_generate.graphql +9 -0
- data/lib/project_types/script/layers/domain/push_package.rb +1 -2
- data/lib/project_types/script/layers/infrastructure/errors.rb +2 -0
- data/lib/project_types/script/layers/infrastructure/push_package_repository.rb +0 -1
- data/lib/project_types/script/layers/infrastructure/script_service.rb +95 -45
- data/lib/project_types/script/messages/messages.rb +3 -0
- data/lib/project_types/script/ui/error_handler.rb +5 -0
- data/lib/shopify-cli/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c6192e829e79c4cfe8a1e6fe1214d17f57da63bcf3802de71a7171a0037a2c1a
|
4
|
+
data.tar.gz: 11f3a7167a24c5b011f930de1a9554176c6371c1a63350ea3a94d9965f521336
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e35ac5b91dea19c5c443616063d1993eefe787b702a9813c4598361f264967baf09d6f4f34a54456b67c6c226cc96b032d3a2bb742ea5425c49fcd3ab843b1fe
|
7
|
+
data.tar.gz: c27174aeaf83c67b292a0374b591833f87be66df912e85389148d008e7df0d3c83252b81034d14e1388be2e9a34112f6e9bf925e26359fb11fbfe84cdd8bb875
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -0,0 +1,40 @@
|
|
1
|
+
mutation AppScriptSet(
|
2
|
+
$uuid: String
|
3
|
+
$extensionPointName: ExtensionPointName!,
|
4
|
+
$title: String!,
|
5
|
+
$description: String,
|
6
|
+
$force: Boolean,
|
7
|
+
$schemaMajorVersion: String,
|
8
|
+
$schemaMinorVersion: String,
|
9
|
+
$scriptJsonVersion: String!,
|
10
|
+
$configurationUi: Boolean!,
|
11
|
+
$configurationDefinition: String!,
|
12
|
+
$moduleUploadUrl: String!,
|
13
|
+
) {
|
14
|
+
appScriptSet(
|
15
|
+
uuid: $uuid
|
16
|
+
extensionPointName: $extensionPointName
|
17
|
+
title: $title
|
18
|
+
description: $description
|
19
|
+
force: $force
|
20
|
+
schemaMajorVersion: $schemaMajorVersion
|
21
|
+
schemaMinorVersion: $schemaMinorVersion,
|
22
|
+
scriptJsonVersion: $scriptJsonVersion,
|
23
|
+
configurationUi: $configurationUi,
|
24
|
+
configurationDefinition: $configurationDefinition,
|
25
|
+
moduleUploadUrl: $moduleUploadUrl,
|
26
|
+
) {
|
27
|
+
userErrors {
|
28
|
+
field
|
29
|
+
message
|
30
|
+
tag
|
31
|
+
}
|
32
|
+
appScript {
|
33
|
+
uuid
|
34
|
+
appKey
|
35
|
+
configSchema
|
36
|
+
extensionPointName
|
37
|
+
title
|
38
|
+
}
|
39
|
+
}
|
40
|
+
}
|
@@ -1,44 +0,0 @@
|
|
1
|
-
mutation AppScriptUpdateOrCreate(
|
2
|
-
$extensionPointName: ExtensionPointName!,
|
3
|
-
$title: String,
|
4
|
-
$description: String,
|
5
|
-
$sourceCode: String,
|
6
|
-
$language: String,
|
7
|
-
$force: Boolean,
|
8
|
-
$schemaMajorVersion: String,
|
9
|
-
$schemaMinorVersion: String,
|
10
|
-
$useMsgpack: Boolean,
|
11
|
-
$uuid: String,
|
12
|
-
$configurationUi: Boolean!,
|
13
|
-
$scriptJsonVersion: String!,
|
14
|
-
$configurationDefinition: String!,
|
15
|
-
) {
|
16
|
-
appScriptUpdateOrCreate(
|
17
|
-
extensionPointName: $extensionPointName
|
18
|
-
title: $title
|
19
|
-
description: $description
|
20
|
-
sourceCode: $sourceCode
|
21
|
-
language: $language
|
22
|
-
force: $force
|
23
|
-
schemaMajorVersion: $schemaMajorVersion
|
24
|
-
schemaMinorVersion: $schemaMinorVersion
|
25
|
-
useMsgpack: $useMsgpack,
|
26
|
-
uuid: $uuid
|
27
|
-
configurationUi: $configurationUi
|
28
|
-
scriptJsonVersion: $scriptJsonVersion
|
29
|
-
configurationDefinition: $configurationDefinition
|
30
|
-
) {
|
31
|
-
userErrors {
|
32
|
-
field
|
33
|
-
message
|
34
|
-
tag
|
35
|
-
}
|
36
|
-
appScript {
|
37
|
-
uuid
|
38
|
-
appKey
|
39
|
-
configSchema
|
40
|
-
extensionPointName
|
41
|
-
title
|
42
|
-
}
|
43
|
-
}
|
44
|
-
}
|
@@ -17,7 +17,7 @@ module Script
|
|
17
17
|
uuid:,
|
18
18
|
extension_point_type:,
|
19
19
|
script_content:,
|
20
|
-
compiled_type
|
20
|
+
compiled_type: nil,
|
21
21
|
metadata:,
|
22
22
|
script_json:
|
23
23
|
)
|
@@ -35,7 +35,6 @@ module Script
|
|
35
35
|
uuid: @uuid,
|
36
36
|
extension_point_type: @extension_point_type,
|
37
37
|
script_content: @script_content,
|
38
|
-
compiled_type: @compiled_type,
|
39
38
|
api_key: api_key,
|
40
39
|
force: force,
|
41
40
|
metadata: @metadata,
|
@@ -14,32 +14,31 @@ module Script
|
|
14
14
|
uuid:,
|
15
15
|
extension_point_type:,
|
16
16
|
script_content:,
|
17
|
-
compiled_type:,
|
18
17
|
api_key: nil,
|
19
18
|
force: false,
|
20
19
|
metadata:,
|
21
20
|
script_json:
|
22
21
|
)
|
23
|
-
|
22
|
+
url = UploadScript.new(ctx).call(api_key, script_content)
|
23
|
+
|
24
|
+
query_name = "app_script_set"
|
24
25
|
variables = {
|
25
26
|
uuid: uuid,
|
26
27
|
extensionPointName: extension_point_type.upcase,
|
27
28
|
title: script_json.title,
|
28
29
|
description: script_json.description,
|
29
|
-
sourceCode: Base64.encode64(script_content),
|
30
|
-
language: compiled_type,
|
31
30
|
force: force,
|
32
31
|
schemaMajorVersion: metadata.schema_major_version.to_s, # API expects string value
|
33
32
|
schemaMinorVersion: metadata.schema_minor_version.to_s, # API expects string value
|
34
|
-
useMsgpack: metadata.use_msgpack,
|
35
33
|
scriptJsonVersion: script_json.version,
|
36
34
|
configurationUi: script_json.configuration_ui,
|
37
35
|
configurationDefinition: script_json.configuration&.to_json,
|
36
|
+
moduleUploadUrl: url,
|
38
37
|
}
|
39
|
-
resp_hash =
|
40
|
-
user_errors = resp_hash["data"]["
|
38
|
+
resp_hash = MakeRequest.new(ctx).call(query_name: query_name, api_key: api_key, variables: variables)
|
39
|
+
user_errors = resp_hash["data"]["appScriptSet"]["userErrors"]
|
41
40
|
|
42
|
-
return resp_hash["data"]["
|
41
|
+
return resp_hash["data"]["appScriptSet"]["appScript"]["uuid"] if user_errors.empty?
|
43
42
|
|
44
43
|
if user_errors.any? { |e| e["tag"] == "already_exists_error" }
|
45
44
|
raise Errors::ScriptRepushError, uuid
|
@@ -67,11 +66,14 @@ module Script
|
|
67
66
|
def get_app_scripts(api_key:, extension_point_type:)
|
68
67
|
query_name = "get_app_scripts"
|
69
68
|
variables = { appKey: api_key, extensionPointName: extension_point_type.upcase }
|
70
|
-
|
69
|
+
response = MakeRequest.new(ctx).call(
|
70
|
+
query_name: query_name,
|
71
|
+
api_key: api_key,
|
72
|
+
variables: variables
|
73
|
+
)
|
74
|
+
response["data"]["appScripts"]
|
71
75
|
end
|
72
76
|
|
73
|
-
private
|
74
|
-
|
75
77
|
class ScriptServiceAPI < ShopifyCli::API
|
76
78
|
property(:api_key, accepts: String)
|
77
79
|
|
@@ -114,47 +116,95 @@ module Script
|
|
114
116
|
end
|
115
117
|
private_constant(:PartnersProxyAPI)
|
116
118
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
119
|
+
class MakeRequest
|
120
|
+
attr_reader :ctx
|
121
|
+
|
122
|
+
def initialize(ctx)
|
123
|
+
@ctx = ctx
|
122
124
|
end
|
123
|
-
raise_if_graphql_failed(resp)
|
124
|
-
resp
|
125
|
-
end
|
126
125
|
|
127
|
-
|
128
|
-
|
129
|
-
|
126
|
+
def self.bypass_partners_proxy
|
127
|
+
!ENV["BYPASS_PARTNERS_PROXY"].nil?
|
128
|
+
end
|
130
129
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
130
|
+
def call(query_name:, variables: nil, **options)
|
131
|
+
resp = if MakeRequest.bypass_partners_proxy
|
132
|
+
ScriptServiceAPI.query(ctx, query_name, variables: variables, **options)
|
133
|
+
else
|
134
|
+
proxy_through_partners(query_name: query_name, variables: variables, **options)
|
135
|
+
end
|
136
|
+
raise_if_graphql_failed(resp)
|
137
|
+
resp
|
138
|
+
end
|
137
139
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
raise Errors::
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
140
|
+
def proxy_through_partners(query_name:, variables: nil, **options)
|
141
|
+
options[:variables] = variables.to_json if variables
|
142
|
+
resp = PartnersProxyAPI.query(ctx, query_name, **options)
|
143
|
+
raise_if_graphql_failed(resp)
|
144
|
+
JSON.parse(resp["data"]["scriptServiceProxy"])
|
145
|
+
end
|
146
|
+
|
147
|
+
def raise_if_graphql_failed(response)
|
148
|
+
raise Errors::EmptyResponseError if response.nil?
|
149
|
+
|
150
|
+
return unless response.key?("errors")
|
151
|
+
case error_code(response["errors"])
|
152
|
+
when "forbidden"
|
153
|
+
raise Errors::ForbiddenError
|
154
|
+
when "forbidden_on_shop"
|
155
|
+
raise Errors::ShopAuthenticationError
|
156
|
+
when "app_not_installed_on_shop"
|
157
|
+
raise Errors::AppNotInstalledError
|
158
|
+
else
|
159
|
+
raise Errors::GraphqlError, response["errors"]
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
def error_code(errors)
|
164
|
+
errors.map do |e|
|
165
|
+
code = e.dig("extensions", "code")
|
166
|
+
return code if code
|
167
|
+
end
|
151
168
|
end
|
152
169
|
end
|
153
170
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
171
|
+
class UploadScript
|
172
|
+
attr_reader :ctx
|
173
|
+
|
174
|
+
def initialize(ctx)
|
175
|
+
@ctx = ctx
|
176
|
+
end
|
177
|
+
|
178
|
+
def call(api_key, script_content)
|
179
|
+
apply_module_upload_url(api_key).tap do |url|
|
180
|
+
upload(url, script_content)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
private
|
185
|
+
|
186
|
+
def apply_module_upload_url(api_key)
|
187
|
+
query_name = "module_upload_url_generate"
|
188
|
+
variables = {}
|
189
|
+
resp_hash = MakeRequest.new(ctx).call(query_name: query_name, api_key: api_key, variables: variables)
|
190
|
+
user_errors = resp_hash["data"]["moduleUploadUrlGenerate"]["userErrors"]
|
191
|
+
|
192
|
+
raise Errors::GraphqlError, user_errors if user_errors.any?
|
193
|
+
resp_hash["data"]["moduleUploadUrlGenerate"]["url"]
|
194
|
+
end
|
195
|
+
|
196
|
+
def upload(url, script_content)
|
197
|
+
url = URI(url)
|
198
|
+
|
199
|
+
https = Net::HTTP.new(url.host, url.port)
|
200
|
+
https.use_ssl = true
|
201
|
+
|
202
|
+
request = Net::HTTP::Put.new(url)
|
203
|
+
request["Content-Type"] = "application/wasm"
|
204
|
+
request.body = script_content
|
205
|
+
|
206
|
+
response = https.request(request)
|
207
|
+
raise Errors::ScriptUploadError unless response.code == "200"
|
158
208
|
end
|
159
209
|
end
|
160
210
|
end
|
@@ -141,6 +141,9 @@ module Script
|
|
141
141
|
web_assembly_binary_not_found_suggestion: "No WebAssembly binary found." \
|
142
142
|
"Check that your build npm script outputs the generated binary to the root of the directory." \
|
143
143
|
"Generated binary should match the script name: <script_name>.wasm",
|
144
|
+
|
145
|
+
script_upload_cause: "Fail to upload script.",
|
146
|
+
script_upload_help: "Try again.",
|
144
147
|
},
|
145
148
|
|
146
149
|
create: {
|
@@ -237,6 +237,11 @@ module Script
|
|
237
237
|
cause_of_error: ShopifyCli::Context.message("script.error.web_assembly_binary_not_found"),
|
238
238
|
help_suggestion: ShopifyCli::Context.message("script.error.web_assembly_binary_not_found_suggestion"),
|
239
239
|
}
|
240
|
+
when Layers::Infrastructure::Errors::ScriptUploadError
|
241
|
+
{
|
242
|
+
cause_of_error: ShopifyCli::Context.message("script.error.script_upload_cause"),
|
243
|
+
help_suggestion: ShopifyCli::Context.message("script.error.script_upload_help"),
|
244
|
+
}
|
240
245
|
end
|
241
246
|
end
|
242
247
|
end
|
data/lib/shopify-cli/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shopify-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shopify
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-08-
|
11
|
+
date: 2021-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -256,8 +256,10 @@ files:
|
|
256
256
|
- lib/project_types/script/config/extension_points.yml
|
257
257
|
- lib/project_types/script/errors.rb
|
258
258
|
- lib/project_types/script/forms/create.rb
|
259
|
+
- lib/project_types/script/graphql/app_script_set.graphql
|
259
260
|
- lib/project_types/script/graphql/app_script_update_or_create.graphql
|
260
261
|
- lib/project_types/script/graphql/get_app_scripts.graphql
|
262
|
+
- lib/project_types/script/graphql/module_upload_url_generate.graphql
|
261
263
|
- lib/project_types/script/graphql/script_service_proxy.graphql
|
262
264
|
- lib/project_types/script/layers/application/build_script.rb
|
263
265
|
- lib/project_types/script/layers/application/create_script.rb
|