Skip to content

Commit f12c296

Browse files
authored
feat: Add all python enums as JS objects (#10)
1 parent acc2a94 commit f12c296

File tree

3 files changed

+136
-15
lines changed

3 files changed

+136
-15
lines changed

src/ViURShopClient.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {getSkey, request} from './HttpClient.js';
2+
import {QuantityMode} from './types.js';
23

34
// Note: Order of functions should always be RCUD (this is NOT a typo of CRUD!)
45

@@ -74,7 +75,7 @@ export class ViURShopClient {
7475
article_key,
7576
parent_cart_key,
7677
quantity = 1,
77-
quantity_mode = 'increase',
78+
quantity_mode = QuantityMode.INCREASE,
7879
} = {}) {
7980
return request(`${this.shop_api_url}/article_add`, {
8081
method: 'POST',
@@ -92,7 +93,7 @@ export class ViURShopClient {
9293
article_key,
9394
parent_cart_key,
9495
quantity = 1,
95-
quantity_mode = 'increase',
96+
quantity_mode = QuantityMode.INCREASE,
9697
} = {}) {
9798
return request(`${this.shop_api_url}/article_update`, {
9899
method: 'POST',

src/index.js

+15-12
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
1-
import {
1+
export {
22
HTTPError,
33
request,
44
getSkey,
55
errorHandler,
66
} from './HttpClient.js'
7-
import {
7+
8+
export {
89
ViURShopClient,
910
} from './ViURShopClient.js'
10-
import {
11-
CartType,
12-
CustomerType,
13-
} from './types.js';
1411

1512
export {
16-
HTTPError,
17-
request,
18-
getSkey,
19-
errorHandler,
20-
ViURShopClient,
13+
ArticleAvailability,
2114
CartType,
2215
CustomerType,
23-
}
16+
Salutation,
17+
AddressType,
18+
CodeType,
19+
ApplicationDomain,
20+
CustomerGroup,
21+
DiscountType,
22+
ConditionOperator,
23+
OrderState,
24+
QuantityMode,
25+
ShippingStatus,
26+
} from './types.js';

src/types.js

+118-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,127 @@
1+
/**
2+
* @enum {string}
3+
* Represents the availability status of an article.
4+
*/
5+
export const ArticleAvailability = Object.freeze({
6+
IN_STOCK: 'instock',
7+
OUT_OF_STOCK: 'outofstock',
8+
LIMITED: 'limited',
9+
DISCONTINUED: 'discontinued',
10+
PREORDER: 'preorder',
11+
});
12+
13+
/**
14+
* @enum {string}
15+
* Represents the type of cart.
16+
*/
117
export const CartType = Object.freeze({
218
WISHLIST: 'wishlist',
319
BASKET: 'basket',
420
});
521

6-
22+
/**
23+
* @enum {string}
24+
* Represents the type of customer.
25+
*/
726
export const CustomerType = Object.freeze({
827
PRIVATE: 'private',
928
BUSINESS: 'business',
1029
});
30+
31+
/**
32+
* @enum {string}
33+
* Represents different salutations for customers.
34+
*/
35+
export const Salutation = Object.freeze({
36+
FEMALE: 'female',
37+
MALE: 'male',
38+
OTHER: 'other',
39+
});
40+
41+
/**
42+
* @enum {string}
43+
* Represents the type of address.
44+
*/
45+
export const AddressType = Object.freeze({
46+
BILLING: 'billing',
47+
SHIPPING: 'shipping',
48+
});
49+
50+
/**
51+
* @enum {string}
52+
* Represents different types of codes.
53+
*/
54+
export const CodeType = Object.freeze({
55+
NONE: 'none',
56+
INDIVIDUAL: 'individual',
57+
UNIVERSAL: 'universal',
58+
});
59+
60+
/**
61+
* @enum {string}
62+
* Represents the domain of an application.
63+
*/
64+
export const ApplicationDomain = Object.freeze({
65+
BASKET: 'basket',
66+
ARTICLE: 'article',
67+
ALL: 'all', // Not care / both(all) / None
68+
});
69+
70+
/**
71+
* @enum {string}
72+
* Represents customer groups.
73+
*/
74+
export const CustomerGroup = Object.freeze({
75+
ALL: 'all', // All customers
76+
FIRST_ORDER: 'first_order', // First-time order
77+
FOLLOW_UP_ORDER: 'follow_up_order', // Follow-up order (repeat customers)
78+
});
79+
80+
/**
81+
* @enum {string}
82+
* Represents types of discounts.
83+
*/
84+
export const DiscountType = Object.freeze({
85+
PERCENTAGE: 'percentage', // Percentage discount
86+
ABSOLUTE: 'absolute', // Absolute discount
87+
FREE_ARTICLE: 'free_article', // Free article (and cart easter egg)
88+
FREE_SHIPPING: 'free_shipping', // Free shipping
89+
});
90+
91+
/**
92+
* @enum {string}
93+
* Represents logical operators for conditions.
94+
*/
95+
export const ConditionOperator = Object.freeze({
96+
ONE_OF: 'one_of', // One condition must be satisfied
97+
ALL: 'all', // All conditions must be satisfied
98+
});
99+
100+
/**
101+
* @enum {string}
102+
* Represents the state of an order.
103+
*/
104+
export const OrderState = Object.freeze({
105+
ORDERED: 'ordered', // Customer completed the order and clicked buy
106+
PAID: 'paid', // Payment completed
107+
RTS: 'rts', // Ready To Send (may not be paid yet)
108+
});
109+
110+
/**
111+
* @enum {string}
112+
* Represents the mode for handling quantity.
113+
*/
114+
export const QuantityMode = Object.freeze({
115+
REPLACE: 'replace', // Use the provided quantity as new value
116+
INCREASE: 'increase', // Add the provided quantity to the current value
117+
DECREASE: 'decrease', // Subtract the provided quantity from the current value
118+
});
119+
120+
/**
121+
* @enum {string}
122+
* Represents the status of shipping.
123+
*/
124+
export const ShippingStatus = Object.freeze({
125+
USER: 'user', // Shipping selected by a user
126+
CHEAPEST: 'cheapest', // Cheapest shipping selected
127+
});

0 commit comments

Comments
 (0)