Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
115 changes: 115 additions & 0 deletions components/simla_com/actions/create-customer/create-customer.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import app from "../../simla_com.app.mjs";

export default {
key: "simla_com-create-customer",
name: "Create Customer",
description: "Creates a new customer profile. [See the documentation](https://docs.simla.com/Developers/API/APIVersions/APIv5#post--api-v5-customers-create).",
version: "0.0.1",
type: "action",
props: {
app,
firstName: {
type: "string",
label: "First Name",
description: "The name of the customer.",
},
lastName: {
type: "string",
label: "Last Name",
description: "The last name of the customer.",
optional: true,
},
phones: {
type: "string[]",
label: "Phone Numbers",
description: "The phone numbers of the customer.",
optional: true,
},
email: {
type: "string",
label: "Email",
description: "The email address of the customer.",
optional: true,
},
postalCode: {
type: "string",
label: "Postal Code",
description: "The postal code of the customer.",
optional: true,
},
countryIso: {
optional: true,
propDefinition: [
app,
"countryIso",
],
},
region: {
type: "string",
label: "Region",
description: "The region of the customer.",
optional: true,
},
city: {
type: "string",
label: "City",
description: "The city of the customer.",
optional: true,
},
street: {
type: "string",
label: "Street",
description: "The street of the customer.",
optional: true,
},
},
methods: {
createCustomer(args = {}) {
return this.app.post({
path: "/customers/create",
...args,
});
},
},
async run({ $ }) {
const {
createCustomer,
firstName,
lastName,
phones,
email,
postalCode,
countryIso,
region,
city,
street,
} = this;

const response = await createCustomer({
$,
data: {
customer: JSON.stringify({
firstName,
lastName,
email,
address: {
index: postalCode,
countryIso,
region,
city,
street,
},
...(phones?.length && {
phones: phones.map((number) => ({
number,
})),
}),
}),
},
});

$.export("$summary", `Successfully created customer with ID \`${response.id}\`.`);

return response;
},
};
195 changes: 195 additions & 0 deletions components/simla_com/actions/create-order/create-order.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
import app from "../../simla_com.app.mjs";
import utils from "../../common/utils.mjs";

export default {
key: "simla_com-create-order",
name: "Create Order",
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).",
version: "0.0.1",
type: "action",
props: {
app,
site: {
propDefinition: [
app,
"site",
],
},
customerType: {
propDefinition: [
app,
"customerType",
],
},
customerId: {
propDefinition: [
app,
"customerId",
({ customerType }) => ({
customerType,
}),
],
},
countryIso: {
propDefinition: [
app,
"countryIso",
],
},
orderType: {
propDefinition: [
app,
"orderType",
],
},
deliveryCost: {
type: "string",
label: "Delivery Cost",
description: "The cost of delivery.",
},
deliveryNetCost: {
type: "string",
label: "Delivery Net Cost",
description: "The net cost of delivery.",
},
numberOfItems: {
type: "integer",
label: "Number Of Items",
description: "The number of items to be ordered.",
default: 1,
reloadProps: true,
},
},
methods: {
itemsPropsMapper(prefix) {
const {
[`${prefix}initialPrice`]: initialPrice,
[`${prefix}quantity`]: quantity,
[`${prefix}comment`]: comment,
[`${prefix}purchasePrice`]: purchasePrice,
[`${prefix}productName`]: productName,
[`${prefix}discountManualAmount`]: discountManualAmount,
[`${prefix}discountManualPercent`]: discountManualPercent,
} = this;

return {
initialPrice,
quantity,
comment,
purchasePrice,
productName,
discountManualAmount,
discountManualPercent,
};
},
getItemsPropDefinitions({
prefix,
label,
} = {}) {
return {
[`${prefix}initialPrice`]: {
type: "string",
label: `${label} - Initial Price`,
description: "The initial price of the item.",
optional: true,
},
[`${prefix}quantity`]: {
type: "string",
label: `${label} - Quantity`,
description: "The quantity of the item.",
optional: true,
},
[`${prefix}comment`]: {
type: "string",
label: `${label} - Comment`,
description: "The comment for the item.",
optional: true,
},
[`${prefix}purchasePrice`]: {
type: "string",
label: `${label} - Purchase Price`,
description: "The purchase price of the item.",
optional: true,
},
[`${prefix}productName`]: {
type: "string",
label: `${label} - Product Name`,
description: "The name of the product.",
optional: true,
},
[`${prefix}discountManualAmount`]: {
type: "string",
label: `${label} - Discount Manual Amount`,
description: "The manual discount amount for the item.",
optional: true,
},
[`${prefix}discountManualPercent`]: {
type: "string",
label: `${label} - Discount Manual Percent`,
description: "The manual discount percent for the item.",
optional: true,
},
};
},
createOrder(args = {}) {
return this.app.post({
path: "/orders/create",
...args,
});
},
},
async additionalProps() {
const {
numberOfItems,
getItemsPropDefinitions,
} = this;

return utils.getAdditionalProps({
numberOfFields: numberOfItems,
fieldName: "item",
getPropDefinitions: getItemsPropDefinitions,
});
},
async run({ $ }) {
const {
numberOfItems,
itemsPropsMapper,
createOrder,
countryIso,
orderType,
site,
customerType,
customerId,
deliveryCost,
deliveryNetCost,
} = this;

const response = await createOrder({
$,
data: {
site,
customer: JSON.stringify({
customerType,
customerId,
}),
order: JSON.stringify({
countryIso,
orderType,
customerType,
customerId,
delivery: {
cost: deliveryCost,
netCost: deliveryNetCost,
},
items: utils.getFieldsProps({
numberOfFields: numberOfItems,
fieldName: "item",
propsMapper: itemsPropsMapper,
}),
}),
},
});
$.export("$summary", `Successfully created order with ID \`${response.id}\`.`);
return response;
},
};
29 changes: 29 additions & 0 deletions components/simla_com/common/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const SUBDOMAIN_PLACEHOLDER = "{subdomain}";
const VERSION_PLACEHOLDER = "{version}";
const BASE_URL = `https://${SUBDOMAIN_PLACEHOLDER}.simla.com/api/${VERSION_PLACEHOLDER}`;
const IS_FIRST_RUN = "isFirstRun";
const LAST_DATE_AT = "lastDateAt";
const DEFAULT_LIMIT = 20;
const DEFAULT_MAX = 200;

const CUSTOMER_TYPE = {
CUSTOMER: {
label: "Customer",
value: "customer",
},
CORPORATE: {
label: "Corporate Customer",
value: "customer_corporate",
},
};

export default {
SUBDOMAIN_PLACEHOLDER,
VERSION_PLACEHOLDER,
BASE_URL,
IS_FIRST_RUN,
CUSTOMER_TYPE,
LAST_DATE_AT,
DEFAULT_LIMIT,
DEFAULT_MAX,
};
Loading
Loading