@viur/shop-components 0.0.1-dev.6 → 0.0.1-dev.61

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/.editorconfig +16 -0
  2. package/.github/workflows/npm-publish.yml +42 -0
  3. package/.gitmodules +3 -0
  4. package/LICENSE +21 -0
  5. package/README.md +13 -2
  6. package/old/client/HttpClient.js +111 -0
  7. package/old/client/ViURShopClient.js +472 -0
  8. package/old/client/index.js +23 -0
  9. package/old/client/types.js +10 -0
  10. package/old/components/ExampleUsage.vue +95 -0
  11. package/old/components/ShopCart.vue +91 -0
  12. package/old/components/ShopOrderComplete.vue +73 -0
  13. package/old/components/ShopOrderConfirm.vue +311 -0
  14. package/old/components/ShopOrderStepper.vue +352 -0
  15. package/old/components/ShopPaymentProvider.vue +113 -0
  16. package/old/components/ShopShippingMethod.vue +52 -0
  17. package/old/components/ShopSummary.vue +138 -0
  18. package/old/components/ShopUserData.vue +218 -0
  19. package/old/components/cart/CartLeaf.vue +277 -0
  20. package/old/components/cart/CartLeafModel.vue +312 -0
  21. package/old/components/cart/CartNode.vue +26 -0
  22. package/old/components/cart/CartTree.vue +67 -0
  23. package/old/components/cart/CartTreeWrapper.vue +73 -0
  24. package/old/components/cart/CartView.vue +82 -0
  25. package/old/components/cart/Discount.vue +91 -0
  26. package/old/components/generic/loadinghandler.vue +76 -0
  27. package/old/components/paymentProvider/paypalplus.vue +0 -0
  28. package/old/components/paymentProvider/prepayment.vue +0 -0
  29. package/old/components/paymentProvider/unzerPayment.vue +140 -0
  30. package/old/components/simple/ShopUserData.vue +161 -0
  31. package/old/components/simple/SimpleDefaultLayout.vue +116 -0
  32. package/old/components/ui/generic/CardSelector.vue +52 -0
  33. package/old/components/ui/generic/CartList.vue +69 -0
  34. package/old/components/ui/generic/ShippingInfo.vue +56 -0
  35. package/old/components/ui/generic/ShopPriceFormatter.vue +41 -0
  36. package/old/components/ui/generic/alerts/ShopAlert.vue +30 -0
  37. package/old/components/ui/payment/PaymentOption.vue +79 -0
  38. package/old/components/ui/payment/PaymentSelector.vue +158 -0
  39. package/old/components/ui/stepper/StepperItem.vue +90 -0
  40. package/old/components/ui/stepper/StepperTab.vue +161 -0
  41. package/old/components/ui/stepper/StepperTrigger.vue +69 -0
  42. package/old/components/ui/userdata/AddForm.vue +160 -0
  43. package/old/components/ui/userdata/AddressBox.vue +137 -0
  44. package/old/components/ui/userdata/BaseLayout.vue +77 -0
  45. package/old/components/ui/userdata/CustomBooleanBone.vue +58 -0
  46. package/old/components/ui/userdata/CustomSelectBone.vue +91 -0
  47. package/old/components/ui/userdata/CustomStringBone.vue +71 -0
  48. package/old/components/ui/userdata/DefaultLayout.vue +126 -0
  49. package/old/components/ui/userdata/SelectAddress.vue +21 -0
  50. package/old/components/ui/userdata/multi/ActionBar.vue +38 -0
  51. package/old/components/ui/userdata/multi/CartSelection.vue +42 -0
  52. package/old/ignite/.editorconfig +20 -0
  53. package/old/ignite/.github/workflows/ignite.yml +64 -0
  54. package/old/ignite/.github/workflows/node.yml +30 -0
  55. package/old/ignite/.postcssrc.cjs +25 -0
  56. package/old/ignite/CHANGELOG.md +244 -0
  57. package/old/ignite/LICENSE +21 -0
  58. package/old/ignite/README.md +92 -0
  59. package/old/ignite/dist/ignite.css +2019 -0
  60. package/old/ignite/dist/ignite.min.css +4 -0
  61. package/old/ignite/foundation/basic.css +371 -0
  62. package/old/ignite/foundation/color.css +323 -0
  63. package/old/ignite/foundation/config.css +188 -0
  64. package/old/ignite/foundation/grid.css +78 -0
  65. package/old/ignite/foundation/mediaqueries.css +71 -0
  66. package/old/ignite/foundation/reset.css +261 -0
  67. package/old/ignite/ignite.css +29 -0
  68. package/old/ignite/ignite.css.map +1 -0
  69. package/old/ignite/package-lock.json +5530 -0
  70. package/old/ignite/package.json +58 -0
  71. package/old/ignite/shoelace.css +19 -0
  72. package/old/ignite/themes/dark.css +12 -0
  73. package/old/ignite/themes/light.css +11 -0
  74. package/old/ignite/utilities/shoelace.css +537 -0
  75. package/old/ignite/utilities/utilities.css +24 -0
  76. package/old/stores/address.js +122 -0
  77. package/old/stores/cart.js +266 -0
  78. package/old/stores/message.js +21 -0
  79. package/old/stores/order.js +202 -0
  80. package/old/stores/payment.js +79 -0
  81. package/old/stores/shipping.js +78 -0
  82. package/package.json +23 -23
  83. package/src/Shop.vue +212 -0
  84. package/src/ShopOrderStepper.vue +89 -0
  85. package/src/ShopSummary.vue +170 -0
  86. package/src/Steps/ShopCart.vue +60 -0
  87. package/src/Steps/ShopOrderComplete.vue +24 -0
  88. package/src/Steps/ShopOrderConfirm.vue +295 -0
  89. package/src/Steps/ShopPaymentProvider.vue +53 -0
  90. package/src/Steps/ShopShippingMethod.vue +53 -0
  91. package/src/Steps/ShopUserDataGuest.vue +78 -0
  92. package/src/Steps/index.js +15 -0
  93. package/src/components/AddressForm.vue +84 -0
  94. package/src/components/AddressFormLayout.vue +107 -0
  95. package/src/components/CardSelector.vue +68 -0
  96. package/src/components/CartItem.vue +325 -0
  97. package/src/components/CartItemSmall.vue +257 -0
  98. package/src/components/LoadingHandler.vue +76 -0
  99. package/src/components/PaymentOption.vue +78 -0
  100. package/src/components/PaymentProviderUnzer.vue +201 -0
  101. package/src/components/PaymentSelector.vue +55 -0
  102. package/src/components/ShopAlert.vue +30 -0
  103. package/src/components/StepperTab.vue +132 -0
  104. package/src/components/dialogButton.vue +49 -0
  105. package/src/composables/address.js +95 -0
  106. package/src/composables/cart.js +132 -0
  107. package/src/composables/order.js +80 -0
  108. package/src/composables/payment.js +75 -0
  109. package/src/composables/shipping.js +32 -0
  110. package/src/main.js +44 -0
  111. package/src/shop.js +251 -0
  112. package/src/translations/de.js +15 -0
  113. package/src/translations/en.js +5 -0
  114. package/src/utils.js +49 -0
  115. package/vite.config.js +51 -0
  116. package/src/components/cart/CartView.vue +0 -692
  117. package/src/components/cart/ConfirmView.vue +0 -314
  118. package/src/components/order/category/CategoryList.vue +0 -83
  119. package/src/components/order/category/CategoryView.vue +0 -143
  120. package/src/components/order/information/UserInfoMulti.vue +0 -427
  121. package/src/components/order/information/UserInformation.vue +0 -332
  122. package/src/components/order/information/adress/ShippingAdress.vue +0 -143
  123. package/src/components/order/item/ItemCard.vue +0 -168
  124. package/src/components/order/item/ItemView.vue +0 -233
  125. package/src/components/order/process/ExampleUsage.vue +0 -100
  126. package/src/components/order/process/OrderComplete.vue +0 -41
  127. package/src/components/order/process/OrderTabHeader.vue +0 -7
  128. package/src/components/order/process/OrderView.vue +0 -210
  129. package/src/router/index.js +0 -103
  130. package/src/stores/cart.js +0 -111
  131. package/src/views/ViewMissing.vue +0 -20
package/.editorconfig ADDED
@@ -0,0 +1,16 @@
1
+ # http://editorconfig.org
2
+
3
+ root = true
4
+
5
+ [*]
6
+ charset = utf-8
7
+ indent_style = space
8
+ indent_size = 2
9
+ end_of_line = lf
10
+ insert_final_newline = true
11
+ trim_trailing_whitespace = true
12
+ max_line_width = 120
13
+
14
+ [*.md]
15
+ insert_final_newline = false
16
+ trim_trailing_whitespace = false
@@ -0,0 +1,42 @@
1
+ # This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
2
+ # For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
3
+
4
+ name: Node.js Package
5
+
6
+ on:
7
+ push:
8
+ tags:
9
+ - v*
10
+
11
+ jobs:
12
+ publish-npm:
13
+ runs-on: ubuntu-latest
14
+ steps:
15
+ - name: Checkout
16
+ uses: actions/checkout@v4
17
+ - uses: actions/setup-node@v3
18
+ with:
19
+ node-version: 16
20
+ registry-url: https://registry.npmjs.org/
21
+ - run: npm ci
22
+ - name: Publish npm package
23
+ run: npm publish
24
+ env:
25
+ NODE_AUTH_TOKEN: ${{secrets.NPM_API_TOKEN}}
26
+
27
+
28
+ gh-release:
29
+ runs-on: ubuntu-latest
30
+ permissions: write-all
31
+ steps:
32
+ - name: Checkout
33
+ uses: actions/checkout@v4
34
+ - name: debug
35
+ run: |
36
+ echo "${{ contains(github.ref_name, 'dev') }}"
37
+ - name: Release
38
+ uses: softprops/action-gh-release@v1
39
+ # if: "!startsWith(github.ref_name, 'v-test-')"
40
+ with:
41
+ generate_release_notes: true
42
+ prerelease: ${{ contains(github.ref_name, 'dev') }}
package/.gitmodules ADDED
@@ -0,0 +1,3 @@
1
+ [submodule "src/style/ignite"]
2
+ path = src/style/ignite
3
+ url = git@github.com:viur-framework/ignite.git
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 ViUR
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -6,6 +6,17 @@
6
6
  <a href="LICENSE">
7
7
  <img src="https://img.shields.io/github/license/viur-framework/shop-components" alt="Badge displaying the license" title="License badge">
8
8
  </a>
9
- <br>
10
- A collection of Vue.js components for the <a href="https://www.viur.dev">ViUR</a> <a href="https://github.com/viur-framework/viur-shop">shop</a>.
9
+ <br />
10
+ A collection of Vue.js components for the <a href="https://www.viur.dev">ViUR</a>
11
+ <a href="https://github.com/viur-framework/viur-shop">shop</a>.
11
12
  </div>
13
+
14
+ ### Structure
15
+ * **Main components** have to be exported in `./src/main.js`. Main Components should be in folder `./src/components`.
16
+ * **Ui Elements** for main components should be in `./src/components/ui` so everyone who contributes can see if there is an element/component already for their use.
17
+ * Components should be as small as possible to make the code easier to access and understand, thats why the directory structure has importance.
18
+ * Every logic/function according to articles/items/cart or anything else should be in the `cartStore` in `./src/stores/cart.js` - reason is as follows - all components get their data with so called props which are not "reactive" by nature. We want to trigger a rerender if we change/add/edit... items thats why anything according to that should be in the cartStore. Read the cartStore carefully and use the already existing states to grant a clean rerender/reactive process. The props all get updated as soon as the main states get updated in the `cartStore` -> rerender --> profit...
19
+
20
+ Try to understand this structure and adopt it with new components for easy implementation without much effort.
21
+
22
+ Real documentation is coming soon...
@@ -0,0 +1,111 @@
1
+ class HTTPError extends Error {
2
+ constructor(code, statusText, message, response) {
3
+ super(message || statusText);
4
+ if (arguments.length >= 4 && response) {
5
+ Object.assign(this, response);
6
+ }
7
+ this.statusText = statusText;
8
+ this.statusCode = code;
9
+ this.response = response;
10
+ }
11
+ }
12
+
13
+ /**
14
+ * Wrapper for fetch.
15
+ * Inspired by https://kentcdodds.com/blog/replace-axios-with-a-simple-custom-fetch-wrapper
16
+ *
17
+ * @param {String} url The url of the ressource to fetch.
18
+ * @param {Object=} json Optional. Data used as json-serialized payload.
19
+ * @param {String=} method Optional. The HTTP method, e.g. POST. Default: GET (if json is unset).
20
+ * @param {Object=} params Optional. Params used as body for POST and get-query-String for others.
21
+ * @param {Object=} customConfig Some custom values for the fetch call.
22
+ * @returns {Promise<Response>} Returns the raw request a promise, or throws a HTTPError.
23
+ */
24
+ function request(url, {json, method, params, ...customConfig} = {}) {
25
+ if (!method) {
26
+ method = json ? 'POST' : 'GET'
27
+ }
28
+ const config = {
29
+ credentials: 'include',
30
+ method: method,
31
+ headers: {
32
+ ...customConfig.headers,
33
+ },
34
+ ...customConfig,
35
+ }
36
+ if (url.startsWith('/') || url.startsWith(window.location.origin)) {
37
+ // TODO: Additional headers causes CORS problems
38
+ // and preflight OPTION requests are not working with the current viur-core
39
+ config.headers['X-Requested-With'] = 'Fetch';
40
+ }
41
+ if (json) {
42
+ config.body = JSON.stringify(json);
43
+ config.headers['Content-Type'] = 'application/json';
44
+ } else if (params && method === 'POST') {
45
+ if (typeof params === 'string' || params instanceof String) {
46
+ // provided a query string, e.g.: foo=1&bar=2
47
+ config.body = new URLSearchParams(params);
48
+ } else if (params instanceof HTMLFormElement) {
49
+ // provided a HTML form element
50
+ config.body = new FormData(params);
51
+ } else {
52
+ // provided a object, e.g.: {foo: 1, bar: 2, baz: [3, 4]}
53
+ config.body = new FormData();
54
+ Object.entries(params).forEach(([key, value]) => {
55
+ if (Array.isArray(value)) {
56
+ for (const val of value) {
57
+ config.body.append(key, val)
58
+ }
59
+ } else {
60
+ config.body.append(key, value)
61
+ }
62
+ });
63
+ }
64
+ }
65
+ if (params && (method === 'GET' || json)) {
66
+ const getParams = new URLSearchParams(params)
67
+ url += `?${getParams.toString()}`;
68
+ }
69
+ return window
70
+ .fetch(url, config)
71
+ .then(async response => {
72
+ if (response.ok || (config.mode === 'no-cors' && response.type === 'opaque')) {
73
+ return response
74
+ } else {
75
+ const errorMessage = `${response.status} ${response.statusText}: ${response.headers.get('x-viur-error')}`
76
+ return Promise.reject(new HTTPError(response.status, response.statusText, errorMessage, response))
77
+ }
78
+ }).catch((error) => {
79
+ const errorMessage = `${error.statusCode} ${error.statusText}: ${error.response.headers.get('x-viur-error')}`
80
+ return Promise.reject(new HTTPError(error.statusCode, error.statusText, errorMessage, error))
81
+ })
82
+ }
83
+
84
+ /**
85
+ * Return a new skey.
86
+ * @returns {Promise<String>} The resolved json-Promise (the skey).
87
+ */
88
+ function getSkey() {
89
+ return request('/json/skey')
90
+ .then(request => request.json())
91
+ }
92
+
93
+ /**
94
+ * Shows a alert with an error-message.
95
+ * @param {any} error The exception. Could be an instance of HTTPError or any other error/value.
96
+ */
97
+ function errorHandler(error) {
98
+ console.error(error);
99
+ let headline = `Error`;
100
+ if (error instanceof HTTPError) {
101
+ headline += ` ${error.statusCode} ${error.statusText}`;
102
+ }
103
+ alert(
104
+ `Sorry, an unexpected error occurred.
105
+ ${headline}
106
+ ${error}
107
+ Please try again our contact our customer service.`,
108
+ )
109
+ }
110
+
111
+ export {HTTPError, request, getSkey, errorHandler};
@@ -0,0 +1,472 @@
1
+ import {getSkey, request} from './HttpClient.js';
2
+
3
+ // Note: Order of functions should always be RCUD (this is NOT a typo of CRUD!)
4
+
5
+ /**
6
+ * ViUR Shop Client
7
+ */
8
+ export class ViURShopClient {
9
+
10
+ /**
11
+ * URL to the shop-backend (ViUR server)
12
+ */
13
+ host_url;
14
+
15
+ /**
16
+ * Name of the shop root module
17
+ */
18
+ shop_module;
19
+
20
+ /**
21
+ * URL to shop root module with the default renderer
22
+ */
23
+ shop_url;
24
+
25
+ /**
26
+ * URL to shop root module with the json renderer
27
+ */
28
+ shop_json_url;
29
+
30
+ /**
31
+ * URL to shop API module with the default renderer
32
+ */
33
+ shop_api_url;
34
+
35
+ constructor({
36
+ host_url = null,
37
+ shop_module = 'shop',
38
+ } = {}) {
39
+ if (host_url === null) {
40
+ try {
41
+ this.host_url = import.meta.env.VITE_API_URL ? import.meta.env.VITE_API_URL : window.location.origin;
42
+ } catch (e) {
43
+ // The import crashes in a bundled runtime
44
+ this.host_url = window.location.origin;
45
+ }
46
+ } else {
47
+ this.host_url = host_url;
48
+ }
49
+ this.shop_module = shop_module;
50
+ this.shop_url = `${this.host_url}/${this.shop_module}`;
51
+ this.shop_json_url = `${this.host_url}/json/${this.shop_module}`;
52
+ this.shop_api_url = `${this.shop_url}/api`;
53
+ this.getStructure_url = `${this.host_url}/vi/getStructure`;
54
+ }
55
+
56
+
57
+ // --- Article ------------------------------------------------------------
58
+
59
+ article_view({
60
+ article_key,
61
+ parent_cart_key,
62
+ } = {}) {
63
+ return request(`${this.shop_api_url}/article_view`, {
64
+ params: {
65
+ 'article_key': article_key,
66
+ 'parent_cart_key': parent_cart_key,
67
+ },
68
+ })
69
+ .then(req => req.json());
70
+ }
71
+
72
+
73
+ article_add({
74
+ article_key,
75
+ parent_cart_key,
76
+ quantity = 1,
77
+ quantity_mode = 'increase',
78
+ } = {}) {
79
+ return request(`${this.shop_api_url}/article_add`, {
80
+ method: 'POST',
81
+ params: {
82
+ article_key,
83
+ parent_cart_key,
84
+ quantity,
85
+ quantity_mode,
86
+ },
87
+ })
88
+ .then(req => req.json());
89
+ }
90
+
91
+ article_update({
92
+ article_key,
93
+ parent_cart_key,
94
+ quantity = 1,
95
+ quantity_mode = 'increase',
96
+ } = {}) {
97
+ return request(`${this.shop_api_url}/article_update`, {
98
+ method: 'POST',
99
+ params: {
100
+ article_key,
101
+ parent_cart_key,
102
+ quantity,
103
+ quantity_mode,
104
+ },
105
+ })
106
+ .then(req => req.json());
107
+ }
108
+
109
+
110
+ article_remove({
111
+ article_key,
112
+ parent_cart_key,
113
+ } = {}) {
114
+ return request(`${this.shop_api_url}/article_remove`, {
115
+ method: 'POST',
116
+ params: {
117
+ article_key,
118
+ parent_cart_key,
119
+ },
120
+ })
121
+ .then(req => req.json());
122
+ }
123
+
124
+ // --- Basket ---------------------------------------------------------------
125
+ basket_list() {
126
+ return request(`${this.shop_api_url}/basket_list`).then(req => req.json());
127
+ }
128
+
129
+ // --- Cart ---------------------------------------------------------------
130
+
131
+ /**
132
+ * List root nodes or children of a cart
133
+ *
134
+ * If a cart key is provided, the direct children (nodes and leafs) will
135
+ * be returned.
136
+ * Otherwise (without a key), the root nodes will be returned.
137
+ *
138
+ * @param {string} cart_key list direct children (nodes and leafs) of this parent node
139
+ * @returns {Promise<Response>}
140
+ */
141
+ cart_list({cart_key = null} = {}) {
142
+ const self = this;
143
+ return request(`${this.shop_api_url}/cart_list`, {
144
+ params: cart_key === null ? {} : {cart_key},
145
+ })
146
+ .then(req => req.json());
147
+ }
148
+
149
+ /**
150
+ * Add a new cart node
151
+ *
152
+ * @param {string} parent_cart_key Key of the parent cart
153
+ * @param {CartType} cart_type Type of the cart node, see `CartType`
154
+ * @param {string=} name Optional. Name of the cart node
155
+ * @param {string=} customer_comment Optional. Comment to this node, by customer.
156
+ * @param {string=} shipping_address_key Optional. Key of the address
157
+ * @param {string=} shipping_key Optional. Key of the shipping
158
+ * @param {string=} discount_key Optional. Key of the discount
159
+ * @returns {Promise<Response>}
160
+ */
161
+ cart_add({
162
+ parent_cart_key,
163
+ cart_type,
164
+ name,
165
+ customer_comment,
166
+ shipping_address_key,
167
+ shipping_key,
168
+ discount_key,
169
+ } = {}) {
170
+ return request(`${this.shop_api_url}/cart_add`, {
171
+ method: 'POST',
172
+ params: this.removeUndefinedValues({
173
+ parent_cart_key,
174
+ name,
175
+ cart_type,
176
+ customer_comment,
177
+ shipping_address_key,
178
+ shipping_key,
179
+ discount_key,
180
+ }),
181
+ })
182
+ .then(req => req.json());
183
+ }
184
+
185
+ /**
186
+ * Update an existing cart node
187
+ *
188
+ * @param {string} cart_key Key of the cart node to be updated
189
+ * @param {CartType} cart_type Type of the cart node, see `CartType`
190
+ * @param {string=} name Optional. Name of the cart node
191
+ * @param {string=} customer_comment Optional. Comment to this node, by customer.
192
+ * @param {string=} shipping_address_key Optional. Key of the address
193
+ * @param {string=} shipping_key Optional. Key of the shipping
194
+ * @param {string=} discount_key Optional. Key of the discount
195
+ * @returns {Promise<Response>}
196
+ */
197
+ cart_update({
198
+ cart_key,
199
+ cart_type,
200
+ name,
201
+ customer_comment,
202
+ shipping_address_key,
203
+ shipping_key,
204
+ discount_key,
205
+ } = {}) {
206
+ return request(`${this.shop_api_url}/cart_update`, {
207
+ method: 'POST',
208
+ params: this.removeUndefinedValues({
209
+ cart_key,
210
+ cart_type,
211
+ name,
212
+ customer_comment,
213
+ shipping_address_key,
214
+ shipping_key,
215
+ discount_key,
216
+ }),
217
+ })
218
+ .then(req => req.json());
219
+ }
220
+
221
+ /**
222
+ * Remove a cart node.
223
+ * Removes itself and all children
224
+ *
225
+ * @param {string} cart_key Key of the cart node to be removed
226
+ * @returns {Promise<Response>}
227
+ */
228
+ cart_remove({cart_key} = {}) {
229
+ return request(`${this.shop_api_url}/cart_remove`, {
230
+ method: 'POST',
231
+ params: {
232
+ cart_key,
233
+ },
234
+ })
235
+ .then(req => req.json());
236
+ }
237
+
238
+ cart_structure() {
239
+ return request(`${this.getStructure_url}/${this.shop_module}.cart`, {
240
+ method: 'GET',
241
+ })
242
+ .then(req => req.json());
243
+ }
244
+
245
+ // --- Address ------------------------------------------------------------
246
+
247
+ address_list({} = {}) {
248
+ const self = this;
249
+ return request(`${this.shop_json_url}/address/list`, {
250
+ params: {
251
+ limit: 100,
252
+ },
253
+ })
254
+ .then(req => req.json())
255
+ .then(response => response.skellist);
256
+ }
257
+
258
+ address_add({
259
+ customer_type,
260
+ salutation,
261
+ company_name,
262
+ firstname,
263
+ lastname,
264
+ street_name,
265
+ street_number,
266
+ address_addition,
267
+ zip_code,
268
+ city,
269
+ country,
270
+ customer_key,
271
+ is_default,
272
+ address_type,
273
+ } = {}) {
274
+ return getSkey()
275
+ .then(skey => {
276
+ return request(`${this.shop_json_url}/address/add`, {
277
+ method: 'POST',
278
+ params: this.removeUndefinedValues({
279
+ skey,
280
+ customer_type,
281
+ salutation,
282
+ company_name,
283
+ firstname,
284
+ lastname,
285
+ street_name,
286
+ street_number,
287
+ address_addition,
288
+ zip_code,
289
+ city,
290
+ country,
291
+ customer: customer_key,
292
+ is_default,
293
+ address_type,
294
+ }),
295
+ })
296
+ .then(req => req.json())
297
+ .then(response => response.values);
298
+ });
299
+ }
300
+
301
+ address_structure() {
302
+ return request(`${this.shop_json_url}/address/structure`, {
303
+ method: 'GET',
304
+ })
305
+ .then(req => req.json());
306
+ }
307
+
308
+ // --- Order --------------------------------------------------------------
309
+
310
+ payment_providers_list({} = {}) {
311
+ return request(`${this.shop_url}/order/payment_providers_list`)
312
+ .then(req => req.json());
313
+ }
314
+
315
+ order_add({
316
+ cart_key,
317
+ payment_provider,
318
+ billing_address_key,
319
+ email,
320
+ customer_key,
321
+ state_ordered,
322
+ state_paid,
323
+ state_rts,
324
+ } = {}) {
325
+ return request(`${this.shop_api_url}/order_add`, {
326
+ method: 'POST',
327
+ params: this.removeUndefinedValues({
328
+ cart_key,
329
+ payment_provider,
330
+ billing_address_key,
331
+ email,
332
+ customer_key,
333
+ state_ordered,
334
+ state_paid,
335
+ state_rts,
336
+ }),
337
+ })
338
+ .then(req => req.json());
339
+ }
340
+
341
+ order_update({
342
+ order_key,
343
+ payment_provider,
344
+ billing_address_key,
345
+ email,
346
+ customer_key,
347
+ state_ordered,
348
+ state_paid,
349
+ state_rts,
350
+ } = {}) {
351
+ return request(`${this.shop_api_url}/order_update`, {
352
+ method: 'POST',
353
+ params: this.removeUndefinedValues({
354
+ order_key,
355
+ payment_provider,
356
+ billing_address_key,
357
+ email,
358
+ customer_key,
359
+ state_ordered,
360
+ state_paid,
361
+ state_rts,
362
+ }),
363
+ })
364
+ .then(req => req.json());
365
+ }
366
+
367
+ order_checkout_start({
368
+ order_key,
369
+ } = {}) {
370
+ return request(`${this.shop_url}/order/checkout_start`, {
371
+ method: 'POST',
372
+ params: {order_key},
373
+ })
374
+ .then(req => req.json());
375
+ }
376
+
377
+ order_checkout_order({
378
+ order_key,
379
+ } = {}) {
380
+ return request(`${this.shop_url}/order/checkout_order`, {
381
+ method: 'POST',
382
+ params: {order_key},
383
+ })
384
+ .then(req => req.json());
385
+ }
386
+
387
+ order_pp_get_settings({
388
+ order_key,
389
+ } = {}) {
390
+ return request(`${this.shop_url}/order/checkout_order`, {
391
+ method: 'POST',
392
+ params: {order_key},
393
+ })
394
+ .then(req => req.json());
395
+ }
396
+
397
+
398
+ // --- User ---------------------------------------------------------------
399
+
400
+ user_view({
401
+ user_key = 'self',
402
+ } = {}) {
403
+ return request(`${this.host_url}/json/user/view/${user_key}`)
404
+ .then(req => req.json())
405
+ .then(response => response.values);
406
+ }
407
+
408
+
409
+ // --- Discount -----------------------------------------------------------
410
+ /**
411
+ * Add a Discount to the current Cart.
412
+ * @param {string} code Human readable Discount Code
413
+ * @param {string} discount_key Database Key from a Discount.
414
+ * @returns {Response<Response>}
415
+ */
416
+ discount_add({
417
+ code,
418
+ discount_key,
419
+ } = {}) {
420
+ return request(`${this.shop_api_url}/discount_add`, {
421
+ method: 'POST',
422
+ params: this.removeUndefinedValues({
423
+ code,
424
+ discount_key,
425
+ }),
426
+ })
427
+ .then(req => req.json());
428
+ }
429
+
430
+ /**
431
+ * Removes a Discount by the Database Key
432
+ * @param {string} discount_key Database Key from a Discount.
433
+ * @returns {Promise<Response>}
434
+ */
435
+ discount_remove({
436
+ discount_key,
437
+ } = {}) {
438
+ return request(`${this.shop_api_url}/discount_remove`, {
439
+ method: 'POST',
440
+ params: {discount_key},
441
+ })
442
+ .then(req => req.json());
443
+ }
444
+
445
+
446
+ // --- Shipping -----------------------------------------------------------
447
+
448
+ /**
449
+ * Lists available shipping options for a (sub)cart
450
+ * @param {string} cart_key Key of the parent cart
451
+ * @returns {Promise<Response>} List of ShippingsSkels
452
+ */
453
+ shipping_list({
454
+ cart_key,
455
+ } = {}) {
456
+ return request(`${this.shop_api_url}/shipping_list`, {
457
+ method: 'GET',
458
+ params: {cart_key},
459
+ })
460
+ .then(req => req.json());
461
+ }
462
+
463
+
464
+ // --- Utils -------------------------------------------------------------
465
+
466
+ removeUndefinedValues(obj) {
467
+ return Object.fromEntries(
468
+ Object.entries(obj)
469
+ .filter(([key, value]) => value !== undefined),
470
+ );
471
+ }
472
+ }