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
108 changes: 108 additions & 0 deletions components/snipcart/actions/create-discount/create-discount.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import app from "../../snipcart.app.mjs";

export default {
key: "snipcart-create-discount",
name: "Create Discount",
description: "Create a new Discount. [See the documentation](https://docs.snipcart.com/v3/api-reference/discounts#post-discounts)",
version: "0.0.1",
type: "action",
props: {
app,
name: {
propDefinition: [
app,
"name",
],
},
trigger: {
propDefinition: [
app,
"trigger",
],
reloadProps: true,
},
code: {
propDefinition: [
app,
"code",
],
optional: true,
hidden: true,
},
totalToReach: {
propDefinition: [
app,
"totalToReach",
],
optional: true,
hidden: true,
},
type: {
propDefinition: [
app,
"type",
],
reloadProps: true,
},
amount: {
propDefinition: [
app,
"amount",
],
optional: true,
hidden: true,
},
rate: {
propDefinition: [
app,
"rate",
],
optional: true,
hidden: true,
},
maxNumberOfUsages: {
propDefinition: [
app,
"maxNumberOfUsages",
],
},
},
async additionalProps(props) {
const triggerIsCode = this.trigger === "Code";
const triggerIsTotal = this.trigger === "Total";

props.code.hidden = !triggerIsCode;
props.code.optional = !triggerIsCode;
props.totalToReach.hidden = !triggerIsTotal;
props.totalToReach.optional = !triggerIsTotal;

const typeIsFixedAmount = this.type === "FixedAmount";
const typeIsRate = this.type === "Rate";

props.amount.hidden = !typeIsFixedAmount;
props.amount.optional = !typeIsFixedAmount;
props.rate.hidden = !typeIsRate;
props.rate.optional = !typeIsRate;

return {};
},
async run({ $ }) {
const response = await this.app.createDiscount({
$,
data: {
name: this.name,
maxNumberOfUsages: this.maxNumberOfUsages,
trigger: this.trigger,
code: this.code,
totalToReach: this.totalToReach,
type: this.type,
amount: this.amount,
rate: this.rate,
},
});

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

return response;
},
};
28 changes: 28 additions & 0 deletions components/snipcart/actions/delete-discount/delete-discount.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import app from "../../snipcart.app.mjs";

export default {
key: "snipcart-delete-discount",
name: "Delete Discount",
description: "Delete a Discount. [See the documentation](https://docs.snipcart.com/v3/api-reference/discounts#delete-discountsid)",
version: "0.0.1",
type: "action",
props: {
app,
discountId: {
propDefinition: [
app,
"discountId",
],
},
},
async run({ $ }) {
const response = await this.app.deleteDiscount({
$,
id: this.discountId,
});

$.export("$summary", `Successfully deleted Discount with ID '${this.discountId}'`);

return response;
},
};
122 changes: 122 additions & 0 deletions components/snipcart/actions/update-discount/update-discount.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import app from "../../snipcart.app.mjs";

export default {
key: "snipcart-update-discount",
name: "Update Discount",
description: "Update a Discount. [See the documentation](https://docs.snipcart.com/v3/api-reference/discounts#put-discountsid)",
version: "0.0.1",
type: "action",
props: {
app,
discountId: {
propDefinition: [
app,
"discountId",
],
},
name: {
propDefinition: [
app,
"name",
],
optional: true,
},
trigger: {
propDefinition: [
app,
"trigger",
],
optional: true,
reloadProps: true,
},
code: {
propDefinition: [
app,
"code",
],
optional: true,
hidden: true,
},
totalToReach: {
propDefinition: [
app,
"totalToReach",
],
optional: true,
hidden: true,
},
type: {
propDefinition: [
app,
"type",
],
optional: true,
reloadProps: true,
},
amount: {
propDefinition: [
app,
"amount",
],
optional: true,
hidden: true,
},
rate: {
propDefinition: [
app,
"rate",
],
optional: true,
hidden: true,
},
maxNumberOfUsages: {
propDefinition: [
app,
"maxNumberOfUsages",
],
},
},
async additionalProps(props) {
const triggerIsCode = this.trigger === "Code";
const triggerIsTotal = this.trigger === "Total";

props.code.hidden = !triggerIsCode;
props.code.optional = !triggerIsCode;
props.totalToReach.hidden = !triggerIsTotal;
props.totalToReach.optional = !triggerIsTotal;

const typeIsFixedAmount = this.type === "FixedAmount";
const typeIsRate = this.type === "Rate";

props.amount.hidden = !typeIsFixedAmount;
props.amount.optional = !typeIsFixedAmount;
props.rate.hidden = !typeIsRate;
props.rate.optional = !typeIsRate;

return {};
},
async run({ $ }) {
const discount = await this.app.getDiscount({
$,
id: this.discountId,
});
const response = await this.app.updateDiscount({
$,
id: this.discountId,
data: {
name: this.name || discount.name,
maxNumberOfUsages: this.maxNumberOfUsages || discount.maxNumberOfUsages,
trigger: this.trigger || discount.trigger,
code: this.code || discount.code,
totalToReach: this.totalToReach || discount.totalToReach,
type: this.type || discount.type,
amount: this.amount || discount.amount,
rate: this.rate || discount.rate,
},
});

$.export("$summary", `Successfully updated Discount with ID '${response.id}'`);

return response;
},
};
10 changes: 10 additions & 0 deletions components/snipcart/common/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default {
TRIGGER_OPTIONS: [
"Total",
"Code",
],
TYPE_OPTIONS: [
"FixedAmount",
"Rate",
],
};
18 changes: 18 additions & 0 deletions components/snipcart/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "@pipedream/snipcart",
"version": "0.1.0",
"description": "Pipedream Snipcart Components",
"main": "snipcart.app.mjs",
"keywords": [
"pipedream",
"snipcart"
],
"homepage": "https://pipedream.com/apps/snipcart",
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.0"
}
}
Loading
Loading