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

feat: expose token validation #367

Merged
merged 4 commits into from
Nov 27, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: add optional config flag for disabling auto cart creation and c…
…art functionality
  • Loading branch information
samblacklock committed Nov 25, 2020
commit bd00a86c842e915bd02d9490110d10a33cef8f42
4 changes: 3 additions & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class Config {
storage,
custom_fetch,
custom_authenticator,
headers
headers,
disableCart
} = options

this.application = application
Expand All @@ -36,6 +37,7 @@ class Config {
this.storage = storage || new LocalStorageFactory()
this.custom_authenticator = custom_authenticator
this.headers = headers || {}
this.disableCart = disableCart || false
}
}

Expand Down
9 changes: 6 additions & 3 deletions src/moltin.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@ import AccountsEndpoint from './endpoints/accounts'
import PromotionsEndpoint from './endpoints/promotions'
import VariationsEndpoint from './endpoints/variations'

import { cartIdentifier } from './utils/helpers'
import { cartIdentifier, tokenInvalid } from './utils/helpers'

export default class Moltin {
constructor(config) {
this.config = config
this.cartId = cartIdentifier(config.storage)

if (!config.disableCart) this.cartId = cartIdentifier(config.storage)

this.tokenInvalid = () => tokenInvalid(config)

this.request = new RequestFactory(config)
this.storage = config.storage
Expand Down Expand Up @@ -61,7 +64,7 @@ export default class Moltin {

// Expose `Cart` class on Moltin class
Cart(id = this.cartId) {
return new CartEndpoint(this.request, id)
return id ? new CartEndpoint(this.request, id) : null
}

// Expose `authenticate` function on the Moltin class
Expand Down