/
moltin.js
131 lines (119 loc) · 6.27 KB
/
moltin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import './utils/fetch-polyfill'
import 'es6-promise'
import Config from './config'
import RequestFactory from './factories/request'
import ProductsEndpoint from './endpoints/products'
import CurrenciesEndpoint from './endpoints/currencies'
import BrandsEndpoint from './endpoints/brands'
import CartEndpoint from './endpoints/cart'
import PCMEndpoint from './endpoints/pcm'
import CategoriesEndpoint from './endpoints/categories'
import CollectionsEndpoint from './endpoints/collections'
import IntegrationsEndpoint from './endpoints/integrations'
import OrdersEndpoint from './endpoints/orders'
import GatewaysEndpoint from './endpoints/gateways'
import CustomersEndpoint from './endpoints/customers'
import InventoriesEndpoint from './endpoints/inventories'
import JobsEndpoint from './endpoints/jobs'
import FlowsEndpoint from './endpoints/flows'
import PriceBooksEndpoint from './endpoints/price-books'
import FieldsEndpoint from './endpoints/fields'
import FilesEndpoint from './endpoints/files'
import CustomerAddressesEndpoint from './endpoints/customer-addresses'
import AccountAddressesEndpoint from './endpoints/account-addresses'
import TransactionsEndpoint from './endpoints/transactions'
import SettingsEndpoint from './endpoints/settings'
import LocalStorageFactory from './factories/local-storage'
import MemoryStorageFactory from './factories/memory-storage'
import PromotionsEndpoint from './endpoints/promotions'
import VariationsEndpoint from './endpoints/variations'
import AuthenticationRealmEndpoint from './endpoints/authentication-realm'
import OidcProfileEndpoint from './endpoints/oidc-profile'
import UserAuthenticationInfoEndpoint from './endpoints/user-authentication-info'
import PasswordProfileEndpoint from './endpoints/password-profile'
import UserAuthenticationPasswordProfileEndpoint from './endpoints/user-authentication-password-profile'
import AuthenticationSettingsEndpoint from './endpoints/authentication-settings'
import HierarchiesEndpoint from './endpoints/hierarchies'
import MerchantRealmMappingsEndpoint from './endpoints/merchant-realm-mappings'
import Accounts from './endpoints/accounts'
import AccountMembersEndpoint from './endpoints/account-members'
import AccountAuthenticationSettingsEndpoint from './endpoints/account-authentication-settings'
import AccountMembershipsEndpoint from './endpoints/account-memberships'
import PCMVariationsEndpoint from './endpoints/pcm-variations'
import MetricsEndpoint from './endpoints/metrics'
import PersonalDataEndpoint from './endpoints/personal-data'
import DataEntriesEndpoint from './endpoints/data-entry'
import AccountMembershipSettingsEndpoint from './endpoints/account-membership-settings'
import ErasureRequestsEndpoint from './endpoints/erasure-requests'
import ApplicationKeysEndpoint from './endpoints/application-keys'
import {cartIdentifier, tokenInvalid, getCredentials, resolveCredentialsStorageKey} from './utils/helpers'
import CatalogsEndpoint from './endpoints/catalogs'
import ShopperCatalogEndpoint from './endpoints/catalog'
export default class Moltin {
constructor(config) {
this.config = config
if (!config.disableCart) this.cartId = cartIdentifier(config.storage, config.name)
this.tokenInvalid = () => tokenInvalid(config)
this.request = new RequestFactory(config)
this.storage = config.storage
this.credentials = () => getCredentials(config.storage, resolveCredentialsStorageKey(config.name))
this.Products = new ProductsEndpoint(config)
this.PCM = new PCMEndpoint(config)
this.Catalogs = new CatalogsEndpoint(config)
this.ShopperCatalog = new ShopperCatalogEndpoint(config)
this.Currencies = new CurrenciesEndpoint(config)
this.Brands = new BrandsEndpoint(config)
this.PriceBooks = new PriceBooksEndpoint(config)
this.Categories = new CategoriesEndpoint(config)
this.Hierarchies = new HierarchiesEndpoint(config)
this.Collections = new CollectionsEndpoint(config)
this.Integrations = new IntegrationsEndpoint(config)
this.Orders = new OrdersEndpoint(config)
this.Gateways = new GatewaysEndpoint(config)
this.Customers = new CustomersEndpoint(config)
this.Inventories = new InventoriesEndpoint(config)
this.Jobs = new JobsEndpoint(config)
this.Files = new FilesEndpoint(config)
this.Flows = new FlowsEndpoint(config)
this.Fields = new FieldsEndpoint(config)
this.CustomerAddresses = new CustomerAddressesEndpoint(config)
this.AccountAddresses = new AccountAddressesEndpoint(config)
this.Transactions = new TransactionsEndpoint(config)
this.Settings = new SettingsEndpoint(config)
this.Promotions = new PromotionsEndpoint(config)
this.Variations = new VariationsEndpoint(config)
this.PCMVariations = new PCMVariationsEndpoint(config)
this.PersonalData = new PersonalDataEndpoint(config)
this.DataEntries = new DataEntriesEndpoint(config)
this.ErasureRequests = new ErasureRequestsEndpoint(config)
this.AuthenticationRealm = new AuthenticationRealmEndpoint(config)
this.OidcProfile = new OidcProfileEndpoint(config)
this.UserAuthenticationInfo = new UserAuthenticationInfoEndpoint(config)
this.PasswordProfile = new PasswordProfileEndpoint(config)
this.AuthenticationSettings = new AuthenticationSettingsEndpoint(config)
this.MerchantRealmMappings = new MerchantRealmMappingsEndpoint(config)
this.Accounts = new Accounts(config)
this.AccountAuthenticationSettings =
new AccountAuthenticationSettingsEndpoint(config)
this.AccountMembers = new AccountMembersEndpoint(config)
this.AccountMemberships = new AccountMembershipsEndpoint(config)
this.AccountMembershipSettings = new AccountMembershipSettingsEndpoint(
config
)
this.UserAuthenticationPasswordProfile =
new UserAuthenticationPasswordProfileEndpoint(config)
this.Metrics = new MetricsEndpoint(config)
this.ApplicationKeys = new ApplicationKeysEndpoint(config)
}
// Expose `Cart` class on Moltin class
Cart(id = this.cartId) {
return !this.config.disableCart ? new CartEndpoint(this.request, id) : null
}
// Expose `authenticate` function on the Moltin class
Authenticate() {
return this.request.authenticate()
}
}
// Export a function to instantiate the Moltin class
const gateway = config => new Moltin(new Config(config))
export { gateway, MemoryStorageFactory, LocalStorageFactory }