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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c0c4574b0b307dbe68a4cfe4d47e76a4825dbc2bb208b2fd891e0192e3158690
4
- data.tar.gz: c365c04166d24b723c4b5d8e0612e722fec4e765f2efcc4a638d534ab60a645c
3
+ metadata.gz: c6192e829e79c4cfe8a1e6fe1214d17f57da63bcf3802de71a7171a0037a2c1a
4
+ data.tar.gz: 11f3a7167a24c5b011f930de1a9554176c6371c1a63350ea3a94d9965f521336
5
5
  SHA512:
6
- metadata.gz: baecd34e68711439ab4986652a21d00dc7c8443ef92497cf516e535cb91b979280293a3d86936a5b4260984739b28adab3ece18fdedfa35087d8ed1ee7411f2c
7
- data.tar.gz: c55111c54115aeb15b5c9cd29e48c1b42c2dbe89a79a509e74c3f2fdea0830ad693e9983ca00ad40468ed9c132c7202e0ca01681dc94866f191773c982811f14
6
+ metadata.gz: e35ac5b91dea19c5c443616063d1993eefe787b702a9813c4598361f264967baf09d6f4f34a54456b67c6c226cc96b032d3a2bb742ea5425c49fcd3ab843b1fe
7
+ data.tar.gz: c27174aeaf83c67b292a0374b591833f87be66df912e85389148d008e7df0d3c83252b81034d14e1388be2e9a34112f6e9bf925e26359fb11fbfe84cdd8bb875
data/CHANGELOG.md CHANGED
@@ -1,6 +1,10 @@
1
1
  Unreleased
2
2
  ------
3
3
 
4
+ Version 2.2.2
5
+ ------
6
+ * [1382](https://github.com/Shopify/shopify-cli/pull/1382): Client side module upload for Scripts
7
+
4
8
  Version 2.2.1
5
9
  ------
6
10
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- shopify-cli (2.2.1)
4
+ shopify-cli (2.2.2)
5
5
  listen (~> 3.5)
6
6
  theme-check (~> 1.1)
7
7
 
@@ -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
- }
@@ -0,0 +1,9 @@
1
+ mutation moduleUploadUrlGenerate {
2
+ moduleUploadUrlGenerate {
3
+ url
4
+ userErrors {
5
+ field
6
+ message
7
+ }
8
+ }
9
+ }
@@ -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,
@@ -93,6 +93,8 @@ module Script
93
93
  super("WebAssembly binary not found")
94
94
  end
95
95
  end
96
+
97
+ class ScriptUploadError < ScriptProjectError; end
96
98
  end
97
99
  end
98
100
  end
@@ -32,7 +32,6 @@ module Script
32
32
  uuid: script_project.uuid,
33
33
  extension_point_type: script_project.extension_point_type,
34
34
  script_content: script_content,
35
- compiled_type: compiled_type,
36
35
  metadata: metadata,
37
36
  script_json: script_project.script_json,
38
37
  )
@@ -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
- query_name = "app_script_update_or_create"
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 = script_service_request(query_name: query_name, api_key: api_key, variables: variables)
40
- user_errors = resp_hash["data"]["appScriptUpdateOrCreate"]["userErrors"]
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"]["appScriptUpdateOrCreate"]["appScript"]["uuid"] if user_errors.empty?
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
- script_service_request(query_name: query_name, api_key: api_key, variables: variables)["data"]["appScripts"]
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
- def script_service_request(query_name:, variables: nil, **options)
118
- resp = if bypass_partners_proxy
119
- ScriptServiceAPI.query(ctx, query_name, variables: variables, **options)
120
- else
121
- proxy_through_partners(query_name: query_name, variables: variables, **options)
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
- def bypass_partners_proxy
128
- !ENV["BYPASS_PARTNERS_PROXY"].nil?
129
- end
126
+ def self.bypass_partners_proxy
127
+ !ENV["BYPASS_PARTNERS_PROXY"].nil?
128
+ end
130
129
 
131
- def proxy_through_partners(query_name:, variables: nil, **options)
132
- options[:variables] = variables.to_json if variables
133
- resp = PartnersProxyAPI.query(ctx, query_name, **options)
134
- raise_if_graphql_failed(resp)
135
- JSON.parse(resp["data"]["scriptServiceProxy"])
136
- end
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
- def raise_if_graphql_failed(response)
139
- raise Errors::EmptyResponseError if response.nil?
140
-
141
- return unless response.key?("errors")
142
- case error_code(response["errors"])
143
- when "forbidden"
144
- raise Errors::ForbiddenError
145
- when "forbidden_on_shop"
146
- raise Errors::ShopAuthenticationError
147
- when "app_not_installed_on_shop"
148
- raise Errors::AppNotInstalledError
149
- else
150
- raise Errors::GraphqlError, response["errors"]
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
- def error_code(errors)
155
- errors.map do |e|
156
- code = e.dig("extensions", "code")
157
- return code if code
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
@@ -1,3 +1,3 @@
1
1
  module ShopifyCli
2
- VERSION = "2.2.1"
2
+ VERSION = "2.2.2"
3
3
  end
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.1
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-09 00:00:00.000000000 Z
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