Skip to content

Commit 984af20

Browse files
committed
Simla: new action and source components
1 parent 3fb007b commit 984af20

File tree

11 files changed

+912
-8
lines changed

11 files changed

+912
-8
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
import app from "../../simla_com.app.mjs";
2+
3+
export default {
4+
key: "simla_com-create-customer",
5+
name: "Create Customer",
6+
description: "Creates a new customer profile. [See the documentation](https://docs.simla.com/Developers/API/APIVersions/APIv5#post--api-v5-customers-create).",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
firstName: {
12+
type: "string",
13+
label: "First Name",
14+
description: "The name of the customer.",
15+
},
16+
lastName: {
17+
type: "string",
18+
label: "Last Name",
19+
description: "The last name of the customer.",
20+
optional: true,
21+
},
22+
phones: {
23+
type: "string[]",
24+
label: "Phone Numbers",
25+
description: "The phone numbers of the customer.",
26+
optional: true,
27+
},
28+
email: {
29+
type: "string",
30+
label: "Email",
31+
description: "The email address of the customer.",
32+
optional: true,
33+
},
34+
postalCode: {
35+
type: "string",
36+
label: "Postal Code",
37+
description: "The postal code of the customer.",
38+
optional: true,
39+
},
40+
countryIso: {
41+
optional: true,
42+
propDefinition: [
43+
app,
44+
"countryIso",
45+
],
46+
},
47+
region: {
48+
type: "string",
49+
label: "Region",
50+
description: "The region of the customer.",
51+
optional: true,
52+
},
53+
city: {
54+
type: "string",
55+
label: "City",
56+
description: "The city of the customer.",
57+
optional: true,
58+
},
59+
street: {
60+
type: "string",
61+
label: "Street",
62+
description: "The street of the customer.",
63+
optional: true,
64+
},
65+
},
66+
methods: {
67+
createCustomer(args = {}) {
68+
return this.app.post({
69+
path: "/customers/create",
70+
...args,
71+
});
72+
},
73+
},
74+
async run({ $ }) {
75+
const {
76+
createCustomer,
77+
firstName,
78+
lastName,
79+
phones,
80+
email,
81+
postalCode,
82+
countryIso,
83+
region,
84+
city,
85+
street,
86+
} = this;
87+
88+
const response = await createCustomer({
89+
$,
90+
data: {
91+
customer: JSON.stringify({
92+
firstName,
93+
lastName,
94+
email,
95+
address: {
96+
index: postalCode,
97+
countryIso,
98+
region,
99+
city,
100+
street,
101+
},
102+
...(phones?.length && {
103+
phones: phones.map((number) => ({
104+
number,
105+
})),
106+
}),
107+
}),
108+
},
109+
});
110+
111+
$.export("$summary", `Successfully created customer with ID \`${response.id}\`.`);
112+
113+
return response;
114+
},
115+
};
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
import app from "../../simla_com.app.mjs";
2+
import utils from "../../common/utils.mjs";
3+
4+
export default {
5+
key: "simla_com-create-order",
6+
name: "Create Order",
7+
description: "Creates a new order with customer and order details. [See the documentation](https://docs.simla.com/Developers/API/APIVersions/APIv5#post--api-v5-orders-create).",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
app,
12+
site: {
13+
propDefinition: [
14+
app,
15+
"site",
16+
],
17+
},
18+
customerType: {
19+
propDefinition: [
20+
app,
21+
"customerType",
22+
],
23+
},
24+
customerId: {
25+
propDefinition: [
26+
app,
27+
"customerId",
28+
({ customerType }) => ({
29+
customerType,
30+
}),
31+
],
32+
},
33+
countryIso: {
34+
propDefinition: [
35+
app,
36+
"countryIso",
37+
],
38+
},
39+
orderType: {
40+
propDefinition: [
41+
app,
42+
"orderType",
43+
],
44+
},
45+
deliveryCost: {
46+
type: "string",
47+
label: "Delivery Cost",
48+
description: "The cost of delivery.",
49+
},
50+
deliveryNetCost: {
51+
type: "string",
52+
label: "Delivery Net Cost",
53+
description: "The net cost of delivery.",
54+
},
55+
numberOfItems: {
56+
type: "integer",
57+
label: "Number Of Items",
58+
description: "The number of items to be ordered.",
59+
default: 1,
60+
reloadProps: true,
61+
},
62+
},
63+
methods: {
64+
itemsPropsMapper(prefix) {
65+
const {
66+
[`${prefix}initialPrice`]: initialPrice,
67+
[`${prefix}quantity`]: quantity,
68+
[`${prefix}comment`]: comment,
69+
[`${prefix}purchasePrice`]: purchasePrice,
70+
[`${prefix}productName`]: productName,
71+
[`${prefix}discountManualAmount`]: discountManualAmount,
72+
[`${prefix}discountManualPercent`]: discountManualPercent,
73+
} = this;
74+
75+
return {
76+
initialPrice,
77+
quantity,
78+
comment,
79+
purchasePrice,
80+
productName,
81+
discountManualAmount,
82+
discountManualPercent,
83+
};
84+
},
85+
getItemsPropDefinitions({
86+
prefix,
87+
label,
88+
} = {}) {
89+
return {
90+
[`${prefix}initialPrice`]: {
91+
type: "string",
92+
label: `${label} - Initial Price`,
93+
description: "The initial price of the item.",
94+
optional: true,
95+
},
96+
[`${prefix}quantity`]: {
97+
type: "string",
98+
label: `${label} - Quantity`,
99+
description: "The quantity of the item.",
100+
optional: true,
101+
},
102+
[`${prefix}comment`]: {
103+
type: "string",
104+
label: `${label} - Comment`,
105+
description: "The comment for the item.",
106+
optional: true,
107+
},
108+
[`${prefix}purchasePrice`]: {
109+
type: "string",
110+
label: `${label} - Purchase Price`,
111+
description: "The purchase price of the item.",
112+
optional: true,
113+
},
114+
[`${prefix}productName`]: {
115+
type: "string",
116+
label: `${label} - Product Name`,
117+
description: "The name of the product.",
118+
optional: true,
119+
},
120+
[`${prefix}discountManualAmount`]: {
121+
type: "string",
122+
label: `${label} - Discount Manual Amount`,
123+
description: "The manual discount amount for the item.",
124+
optional: true,
125+
},
126+
[`${prefix}discountManualPercent`]: {
127+
type: "string",
128+
label: `${label} - Discount Manual Percent`,
129+
description: "The manual discount percent for the item.",
130+
optional: true,
131+
},
132+
};
133+
},
134+
createOrder(args = {}) {
135+
return this.app.post({
136+
path: "/orders/create",
137+
...args,
138+
});
139+
},
140+
},
141+
async additionalProps() {
142+
const {
143+
numberOfItems,
144+
getItemsPropDefinitions,
145+
} = this;
146+
147+
return utils.getAdditionalProps({
148+
numberOfFields: numberOfItems,
149+
fieldName: "item",
150+
getPropDefinitions: getItemsPropDefinitions,
151+
});
152+
},
153+
async run({ $ }) {
154+
const {
155+
numberOfItems,
156+
itemsPropsMapper,
157+
createOrder,
158+
countryIso,
159+
orderType,
160+
site,
161+
customerType,
162+
customerId,
163+
deliveryCost,
164+
deliveryNetCost,
165+
} = this;
166+
167+
const response = await createOrder({
168+
$,
169+
data: {
170+
site,
171+
customer: JSON.stringify({
172+
customerType,
173+
customerId,
174+
}),
175+
order: JSON.stringify({
176+
countryIso,
177+
orderType,
178+
customerType,
179+
customerId,
180+
delivery: {
181+
cost: deliveryCost,
182+
netCost: deliveryNetCost,
183+
},
184+
items: utils.getFieldsProps({
185+
numberOfFields: numberOfItems,
186+
fieldName: "item",
187+
propsMapper: itemsPropsMapper,
188+
}),
189+
}),
190+
},
191+
});
192+
$.export("$summary", `Successfully created order with ID \`${response.id}\`.`);
193+
return response;
194+
},
195+
};
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const SUBDOMAIN_PLACEHOLDER = "{subdomain}";
2+
const VERSION_PLACEHOLDER = "{version}";
3+
const BASE_URL = `https://${SUBDOMAIN_PLACEHOLDER}.simla.com/api/${VERSION_PLACEHOLDER}`;
4+
const IS_FIRST_RUN = "isFirstRun";
5+
const LAST_DATE_AT = "lastDateAt";
6+
const DEFAULT_LIMIT = 20;
7+
const DEFAULT_MAX = 200;
8+
9+
const CUSTOMER_TYPE = {
10+
CUSTOMER: {
11+
label: "Customer",
12+
value: "customer",
13+
},
14+
CORPORATE: {
15+
label: "Corporate Customer",
16+
value: "customer_corporate",
17+
},
18+
};
19+
20+
export default {
21+
SUBDOMAIN_PLACEHOLDER,
22+
VERSION_PLACEHOLDER,
23+
BASE_URL,
24+
IS_FIRST_RUN,
25+
CUSTOMER_TYPE,
26+
LAST_DATE_AT,
27+
DEFAULT_LIMIT,
28+
DEFAULT_MAX,
29+
};

0 commit comments

Comments
 (0)