Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Pass required params to Session constructor. Allow undefined in AuthScopes #169

Merged
merged 5 commits into from
Oct 25, 2021

Conversation

thecodepixi
Copy link
Contributor

@thecodepixi thecodepixi commented Apr 28, 2021

WHY are these changes introduced?

The parameters required by Session were previously not being passed to the constructor, and we were instantiating instances of Session with just their id. This caused some issues due to potentially missing required params.

An issue with scopes potentially being undefined and causing errors in the AuthScopes class is also fixed in this PR. This initially seemed like a Session issue but was able to be resolved in the AuthScope class itself by allowing undefined scopes in the constructor, which then translates to an empty array of scopes.

The change to AuthScopes should potentially fix #159 and similar issues.

WHAT is this pull request doing?

  • Moves all required Session params into the constructor.
    • this is a potentially breaking change, depending on how directly users interact with Session
  • Updates all testing where we call new Session to pass the required params.
  • Updates AuthScopes to allow for undefined in the constructor, and then check for the presence of scope.

important to note that a large portion of this PR is updates to test files

Type of change

  • Patch: Bug (non-breaking change which fixes an issue)
  • Minor: New feature (non-breaking change which adds functionality)
  • Major: Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

  • I have added a changelog entry, prefixed by the type of change noted above
  • I have added/updated tests for this change
  • I have documented new APIs/updated the documentation for modified APIs (for public APIs)

@thecodepixi thecodepixi force-pushed the thecodepixi/move-required-args-to-session-constructor branch 3 times, most recently from 679dd92 to 2444034 Compare April 28, 2021 21:09
@thecodepixi thecodepixi changed the title DRAFT Moves required Session args to constructor Pass required params to Session constructor. Allow undefined in AuthScopes Apr 28, 2021
@thecodepixi thecodepixi marked this pull request as ready for review April 28, 2021 21:22
Copy link
Contributor

@paulomarg paulomarg left a comment

Choose a reason for hiding this comment

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

Looks great, just had a couple of nits!

let scopesArray: string[] = [];
if (typeof scopes === 'string') {
scopesArray = scopes.split(new RegExp(`${AuthScopes.SCOPE_DELIMITER}\\s*`));
} else {
} else if (scopes) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we be extra sure that we only process accepted types?

Suggested change
} else if (scopes) {
} else if (scopes !== undefined) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good point. Should there be an exception/error at that point if scopes is not a string, array or undefined?

Copy link
Contributor

Choose a reason for hiding this comment

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

Technically, typescript would fail in that case, but javascript wouldn't. Then again, we don't check for that sort of thing in a lot of other places (and is that an excuse for not doing it here? 😅 ).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I'm unsure what the right move is here 😅

src/auth/session/session.ts Outdated Show resolved Hide resolved
@thecodepixi
Copy link
Contributor Author

This needs a good rebase and probably a bit of refactoring since we've merged #153. I'll get that taken care of so this should be in a good place soon.

@thecodepixi thecodepixi force-pushed the thecodepixi/move-required-args-to-session-constructor branch from 2444034 to 8bf068e Compare April 29, 2021 18:59
@thecodepixi thecodepixi requested a review from a team as a code owner April 29, 2021 18:59
@thecodepixi thecodepixi force-pushed the thecodepixi/move-required-args-to-session-constructor branch from 88bf9c8 to b772364 Compare April 29, 2021 19:03
CHANGELOG.md Outdated
## [1.2.1] - 2021-03-26
### Added
- Added `April21` to `ApiVersion` [#149](https://github.com/Shopify/shopify-node-api/pull/149)
- Sessions no longer default to `false` for `isOnline` [#169](https://github.com/Shopify/shopify-node-api/pull/169)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a little confused - is this part of v1.2.1?

Also, I think this might be a breaking change, right? It will essentially break any apps that build sessions (which might be the case for custom session storages made prior to the change to allow objects).
Update: I actually don't think it's breaking! It's OK to not get those values in the constructor (if we make the params optional), and since the properties are all public, they can continue to be set as they were.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ope, sorry. My changelog got all weird after I rebased. Will fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also yes, this would be breaking. I don't think these values can be optional? They need to be there for other parts of the code that handle the Session to work, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, but if you call the constructor and then set the fields, that's OK too, as long as the right fields continue to be set - i.e. apps that did it 'the old way' would continue to work if the constructor doesn't break because of missing params.

src/auth/session/session.ts Outdated Show resolved Hide resolved
@thecodepixi thecodepixi force-pushed the thecodepixi/move-required-args-to-session-constructor branch from 753a7e8 to 65226ed Compare April 29, 2021 19:28
@sagar-ranglani
Copy link

Any updates on this one?

@mariomx3
Copy link

Any update or a workaround for now?

@hgezim
Copy link

hgezim commented Oct 13, 2021

@thecodepixi Any chance you can resolve those conflicts?

@mariomx3
Copy link

Will this be merged in soon? Really critical

@paulomarg
Copy link
Contributor

Hi folks! Sorry for the delay on this one.

We're currently working on a few breaking changes that are going to make up v2 of the library. Since this is also a breaking change (because of the isOnline default), we'll make sure to include it in the new release.

Stay tuned, and thanks for your patience!

@mllemango mllemango changed the base branch from main to v2 October 25, 2021 14:35
@mllemango mllemango merged commit 650ebe2 into v2 Oct 25, 2021
@mllemango mllemango deleted the thecodepixi/move-required-args-to-session-constructor branch October 25, 2021 14:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Session scope check fails when scope is undefined
7 participants