Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Session Storage to shopify_app #1055

Merged
merged 19 commits into from
Nov 18, 2022

Conversation

nelsonwittwer
Copy link
Contributor

@nelsonwittwer nelsonwittwer commented Nov 7, 2022

Description

We would like to remove persistence responsibilities from this API library. Ideally, this API would just deal with API sessions and pass storing, loading, and deleting sessions responsibilities to Shopify App or some other middleware that has persistence.

This change makes config.session_storage optional and only makes store_session calls if the storage library is provided.

TODO

  • Add deprecation logging to SessionUtils
  • Add testing for new conditional store_session
  • Can we deprecate session storage

How has this been tested?

  1. Created a new embedded app
  2. Pointed to WIP shopify_app PR where we moved session persistence logic to that layer
  3. Verified I was able to install new app, reload sessions, and make API calls.

Checklist:

  • My commit message follow the pattern described in here
  • I have performed a self-review of my own code.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have updated the project documentation.
  • I have added a changelog line.

@nelsonwittwer nelsonwittwer requested a review from a team as a code owner November 7, 2022 18:48
@nelsonwittwer nelsonwittwer changed the title WIP - Deprecate Session Storage Move Session Storage to shopify_app Nov 15, 2022
andyw8 and others added 3 commits November 15, 2022 15:39
Co-authored-by: Andy Waite <andyw8@users.noreply.github.com>
Co-authored-by: Andy Waite <andyw8@users.noreply.github.com>
lib/shopify_api/context.rb Outdated Show resolved Hide resolved
Co-authored-by: Andy Waite <13400+andyw8@users.noreply.github.com>
@@ -17,12 +19,14 @@ class << self
).returns(T.nilable(Auth::Session))
end
def load_current_session(auth_header: nil, cookies: nil, is_online: false)
::ShopifyAPI::Context.logger.warn("ShopifyAPI::Utils::SessionUtils.load_current_session has been deprecated. The ShopifyAPI will no longer have responsibility for session persistence. Consider using the `shopify_app` gem which now owns this responsiblity.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need these now that we have the check in Context?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(also - extra space before 'will')

@@ -69,6 +69,11 @@ def setup(
@scope = Auth::AuthScopes.new(scope)
@is_embedded = is_embedded
@session_storage = session_storage
if @session_storage
# rubocop:disable Layout/LineLength
::ShopifyAPI::Context.logger.warn("SessionStorage has been deprecated. The ShopifyAPI will no longer have responsibility for session persistence. Consider using the `shopify_app` gem which now owns this responsiblity.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
::ShopifyAPI::Context.logger.warn("SessionStorage has been deprecated. The ShopifyAPI will no longer have responsibility for session persistence. Consider using the `shopify_app` gem which now owns this responsiblity.")
::ShopifyAPI::Context.logger.warn("SessionStorage has been deprecated. The ShopifyAPI will no longer have responsibility for session persistence. Consider using the `shopify_app` gem which now implements this responsibility.")

lib/shopify_api/utils/session_utils.rb Outdated Show resolved Hide resolved
@@ -33,10 +37,12 @@ def load_current_session(auth_header: nil, cookies: nil, is_online: false)
).returns(T::Boolean)
end
def delete_current_session(auth_header: nil, cookies: nil, is_online: false)
::ShopifyAPI::Context.logger.warn("ShopifyAPI::Utils::SessionUtils.delete_current_session has been deprecated. The ShopifyAPI will no longer have responsibility for session persistence. Consider using the `shopify_app` gem which now owns this responsiblity.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
::ShopifyAPI::Context.logger.warn("ShopifyAPI::Utils::SessionUtils.delete_current_session has been deprecated. The ShopifyAPI will no longer have responsibility for session persistence. Consider using the `shopify_app` gem which now owns this responsiblity.")
::ShopifyAPI::Context.logger.warn("ShopifyAPI::Utils::SessionUtils.delete_current_session has been deprecated. The ShopifyAPI will no longer have responsibility for session persistence. Consider using the `shopify_app` gem which now implements this responsibility.")

@@ -46,8 +52,10 @@ def delete_current_session(auth_header: nil, cookies: nil, is_online: false)
).returns(T.nilable(Auth::Session))
end
def load_offline_session(shop:, include_expired: false)
::ShopifyAPI::Context.logger.warn("ShopifyAPI::Utils::SessionUtils.load_offline_session has been deprecated. The ShopifyAPI will no longer have responsibility for session persistence. Consider using the `shopify_app` gem which now owns this responsiblity.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
::ShopifyAPI::Context.logger.warn("ShopifyAPI::Utils::SessionUtils.load_offline_session has been deprecated. The ShopifyAPI will no longer have responsibility for session persistence. Consider using the `shopify_app` gem which now owns this responsiblity.")
::ShopifyAPI::Context.logger.warn("ShopifyAPI::Utils::SessionUtils.load_offline_session has been deprecated. The ShopifyAPI will no longer have responsibility for session persistence. Consider using the `shopify_app` gem which now implements this responsibility.")

unless Context.private_shop
raise Errors::SessionNotFoundError, "Could not load private shop, Context.private_shop is nil."
end
::ShopifyAPI::Context.logger.warn("ShopifyAPI::Utils::SessionUtils.delete_offline_session has been deprecated. The ShopifyAPI will no longer have responsibility for session persistence. Consider using the `shopify_app` gem which now owns this responsiblity.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
::ShopifyAPI::Context.logger.warn("ShopifyAPI::Utils::SessionUtils.delete_offline_session has been deprecated. The ShopifyAPI will no longer have responsibility for session persistence. Consider using the `shopify_app` gem which now owns this responsiblity.")
::ShopifyAPI::Context.logger.warn("ShopifyAPI::Utils::SessionUtils.delete_offline_session has been deprecated. The ShopifyAPI will no longer have responsibility for session persistence. Consider using the `shopify_app` gem which now implements this responsibility.")

lib/shopify_api/context.rb Outdated Show resolved Hide resolved
raise Errors::SessionStorageError,
"Session could not be saved. Please check your session storage implementation."
end
Context.session_storage&.store_session(session)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably an edge case, but should we be retaining the previous behaviour of raising if store_session returns nil?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new normal is for Context.session_storage to be nil as it is deprecated. It's my hope that this will be nil :)

if @session_storage
::ShopifyAPI::Context.logger.warn("SessionStorage has been deprecated. " \
"The ShopifyAPI will no longer have responsibility for session persistence. " \
"Consider using the `shopify_app` gem which now implements this responsibility.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we point to any particular docs here?

lib/shopify_api/context.rb Outdated Show resolved Hide resolved
lib/shopify_api/context.rb Outdated Show resolved Hide resolved
def validate_session_storage_for_deprecated_utils
unless Context.session_storage
raise ShopifyAPI::Errors::SessionStorageError,
"session_storage is required in ShopifyAPI::Context when using deprecated Session utility methods."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"session_storage is required in ShopifyAPI::Context when using deprecated Session utility methods."
"session_storage is required in ShopifyAPI::Context when using deprecated Session utility methods."

If these session utility methods are deprecated, what's the recommended replacement? Presumably something in shopify_app? Should we point them towards that or does that create too much of a link between shopify-api-ruby and shopify_app?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this particular error will be super hard to reach. This error was put in place mainly because the sorbet one wasn't pretty. I think the upgrade logs we have in the Context.setup call should help give actionable steps on upgrade path.

nelsonwittwer and others added 3 commits November 18, 2022 14:00
Co-authored-by: Kevin O'Sullivan <56687600+mkevinosullivan@users.noreply.github.com>
Co-authored-by: Kevin O'Sullivan <56687600+mkevinosullivan@users.noreply.github.com>
@nelsonwittwer nelsonwittwer merged commit 5b5e0b4 into main Nov 18, 2022
@nelsonwittwer nelsonwittwer deleted the nelsonwittwer/deprecate_session_utils branch November 18, 2022 19:08
kaarelss added a commit to kaarelss/shopify-api-ruby that referenced this pull request Nov 29, 2022
…y-api-ruby into response_in_error_object

* 'response_in_error_object' of github.com:kaarelss/shopify-api-ruby:
  Added assertion that response is present in MaxHttpRetriesExceededError
  Added sorbet assertion
  Removed extra empty line
  ShopifyAPI::Clients::HttpResponse as argument for ShopifyAPI::Errors::HttpResponseError because code can be obtained from response as well as headers for custom retry logic
  Remove mentions of private apps (Shopify#1062)
  Fix ActiveSupport inflector dependency (Shopify#1063)
  Move Session Storage to `shopify_app` (Shopify#1055)
  Remove session argument from REST examples (Shopify#1064)
  Constrain Zeitwerk to 2.6.5 (Shopify#1059)
  Clarify statement about packages (Shopify#1057)
@nelsonwittwer nelsonwittwer mentioned this pull request May 15, 2023
5 tasks
takp added a commit to takp/shopify-api-ruby that referenced this pull request May 27, 2023
Configuring the API with session_storage is now deprecated.
Shopify#1055
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants