Description
Overview
Every app needs to store some additional metadata about the merchant, e.g. external IDs like user oder tenant IDs, subscription data, etc. I usually store this data in a separate database table or even an external system, but some information would make sense to store in the session itself, since the session storage is natively integrated into the Shopify API library. That means the app has to make at least database access any way and it would give us a cheap and fast way to store data.
Status Quo
The SessionParams
types seems to allow additional properties, even though I'm not sure it was actually meant for this use case:
shopify-app-js/packages/apps/shopify-api/lib/session/types.ts
Lines 37 to 41 in 52134b2
Also the Session
, if instantiated from the constructor, keeps the additional properties:
shopify-app-js/packages/apps/shopify-api/lib/session/session.ts
Lines 170 to 172 in 52134b2
However, the toObject
method doesn't consider any additional properties:
shopify-app-js/packages/apps/shopify-api/lib/session/session.ts
Lines 225 to 246 in 52134b2
Suggestion
I think we could use TypeScripts module augmentation to extend the SessionParams
interface with additional properties which exist only in type-space. However, since we are mostly interacting with the Session
class return from the SessionStorage
, the Session
would need ti implement the SessionParams
interface. That should be a problem, since properties already exist in the class:
shopify-app-js/packages/apps/shopify-api/lib/session/session.ts
Lines 137 to 168 in 52134b2
The main problem is that toObject
removes any additional properties. We would need to keep track of the additional properties when creating a session from the constructor or the static fromPropertyArray
method.
Please let me know your thoughts and if you are willing to open the session for this use case.