@shopify/cli-kit 3.59.0 → 3.59.2

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.
@@ -25,8 +25,8 @@ module ShopifyCLI
25
25
  ]
26
26
 
27
27
  class Proxy
28
- SESSION_COOKIE_NAME = "_secure_session_id"
29
- SESSION_COOKIE_REGEXP = /#{SESSION_COOKIE_NAME}=(\h+)/
28
+ SESSION_COOKIE_NAME = "_shopify_essential"
29
+ SESSION_COOKIE_REGEXP = /#{SESSION_COOKIE_NAME}=([^;]*)(;|$)/
30
30
  SESSION_COOKIE_MAX_AGE = 60 * 60 * 23 # 1 day - leeway of 1h
31
31
  IGNORED_ENDPOINTS = %w[
32
32
  shopify/monorail
@@ -58,7 +58,8 @@ module ShopifyCLI
58
58
  query = URI.decode_www_form(env["QUERY_STRING"])
59
59
  replace_templates = build_replacement_param(env)
60
60
 
61
- clean_sfr_cache(env, query, headers)
61
+ response = set_preview_theme_id(env, query, headers)
62
+ return serve_response(response, env) if response
62
63
 
63
64
  response = if replace_templates.any?
64
65
  # Pass to SFR the recently modified templates in `replace_templates` or
@@ -87,16 +88,14 @@ module ShopifyCLI
87
88
  @core_endpoints << env["PATH_INFO"]
88
89
  end
89
90
 
90
- body = patch_body(env, response.body)
91
- body = [body] unless body.respond_to?(:each)
92
- [response.code, headers, body]
91
+ serve_response(response, env, headers)
93
92
  end
94
93
 
95
94
  def secure_session_id
96
95
  if secure_session_id_expired?
97
- @ctx.debug("Refreshing preview _secure_session_id cookie")
96
+ @ctx.debug("Refreshing preview _shopify_essential cookie")
98
97
  response = request("HEAD", "/", query: [[:preview_theme_id, theme_id]])
99
- @secure_session_id = extract_secure_session_id_from_response_headers(response)
98
+ @secure_session_id = extract_shopify_essential_from_response_headers(response)
100
99
  @last_session_cookie_refresh = Time.now
101
100
  end
102
101
 
@@ -105,7 +104,13 @@ module ShopifyCLI
105
104
 
106
105
  private
107
106
 
108
- def clean_sfr_cache(env, query, headers)
107
+ def serve_response(response, env, headers = get_response_headers(response, env))
108
+ body = patch_body(env, response.body)
109
+ body = [body] unless body.respond_to?(:each)
110
+ [response.code, headers, body]
111
+ end
112
+
113
+ def set_preview_theme_id(env, query, headers)
109
114
  if env["PATH_INFO"].start_with?("/password")
110
115
  @cache_cleaned = false
111
116
  return
@@ -215,7 +220,7 @@ module ShopifyCLI
215
220
  Time.now - @last_session_cookie_refresh >= SESSION_COOKIE_MAX_AGE
216
221
  end
217
222
 
218
- def extract_secure_session_id_from_response_headers(headers)
223
+ def extract_shopify_essential_from_response_headers(headers)
219
224
  return unless headers["set-cookie"]
220
225
 
221
226
  headers["set-cookie"][SESSION_COOKIE_REGEXP, 1]
@@ -235,9 +240,9 @@ module ShopifyCLI
235
240
  response_headers["location"].gsub!(%r{(https://#{shop})}, "http://#{host(env)}")
236
241
  end
237
242
 
238
- new_session_id = extract_secure_session_id_from_response_headers(response_headers)
243
+ new_session_id = extract_shopify_essential_from_response_headers(response_headers)
239
244
  if new_session_id
240
- @ctx.debug("New _secure_session_id cookie from response")
245
+ @ctx.debug("New _shopify_essential cookie from response")
241
246
  @secure_session_id = new_session_id
242
247
  @last_session_cookie_refresh = Time.now
243
248
  end
@@ -4,6 +4,8 @@ module ShopifyCLI
4
4
  module Theme
5
5
  class Repl
6
6
  class Api
7
+ SESSION_COOKIE_NAME = DevServer::Proxy::SESSION_COOKIE_NAME
8
+
7
9
  attr_reader :ctx, :url, :repl
8
10
 
9
11
  def initialize(ctx, url, repl)
@@ -60,7 +62,7 @@ module ShopifyCLI
60
62
  end
61
63
 
62
64
  def cookie
63
- @cookie ||= "storefront_digest=#{repl.storefront_digest}; _secure_session_id=#{repl.secure_session_id}"
65
+ @cookie ||= "storefront_digest=#{repl.storefront_digest}; #{SESSION_COOKIE_NAME}=#{repl.secure_session_id}"
64
66
  end
65
67
 
66
68
  def shop
@@ -17,7 +17,7 @@ module ShopifyCLI
17
17
  @env = env
18
18
  @env["PATH_INFO"] = PASSWORD_PAGE_PATH if redirect_to_password?(@env)
19
19
 
20
- return @app.call(@env) if password_page?(@env)
20
+ return @app.call(@env) if password_page?(@env) || (storefront_session.nil? || secure_session.nil?)
21
21
 
22
22
  authenticate!
23
23
 
@@ -26,6 +26,9 @@ module ShopifyCLI
26
26
  # from shutting down the server.
27
27
  shutdown if index_page?(@env)
28
28
 
29
+ # Set preview_theme_id into the session.
30
+ @app.call(@env)
31
+
29
32
  [
30
33
  200,
31
34
  {
@@ -1 +1 @@
1
- export declare const CLI_KIT_VERSION = "3.59.0";
1
+ export declare const CLI_KIT_VERSION = "3.59.2";
@@ -1,2 +1,2 @@
1
- export const CLI_KIT_VERSION = '3.59.0';
1
+ export const CLI_KIT_VERSION = '3.59.2';
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,QAAQ,CAAA","sourcesContent":["export const CLI_KIT_VERSION = '3.59.0'\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.59.2'\n"]}