Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
import { ConfigurationError } from "@pipedream/platform";
import app from "../../afosto.app.mjs";
import { parseObject } from "../../common/utils.mjs";

export default {
key: "afosto-add-information-to-cart",
name: "Add Information to Cart",
description: "Add customer information to a cart. [See the documentation](https://afosto.com/docs/developers/storefront-js-client/custom-checkout/collecting-customer-data/)",
version: "0.0.1",
type: "action",
props: {
app,
cartId: {
propDefinition: [
app,
"cartId",
],
},
email: {
type: "string",
label: "Email",
description: "The email of the customer",
optional: true,
},
isGuest: {
type: "boolean",
label: "Is Guest",
description: "Whether the customer is a guest",
optional: true,
},
givenName: {
type: "string",
label: "Given Name",
description: "The given name of the customer",
optional: true,
},
additionalName: {
type: "string",
label: "Additional Name",
description: "The additional name of the customer",
optional: true,
},
familyName: {
type: "string",
label: "Family Name",
description: "The family name of the customer",
optional: true,
},
organisationName: {
type: "string",
label: "Organisation Name",
description: "The name of the organisation",
optional: true,
},
organisationIsGuest: {
type: "boolean",
label: "Organisation Is Guest",
description: "Whether the organisation is a guest",
optional: true,
},
organisationEmail: {
type: "string",
label: "Organisation Email",
description: "The email of the organisation",
optional: true,
},
organisationCountryCode: {
type: "string",
label: "Organisation Country Code",
description: "The country code of the organisation",
optional: true,
},
organisationNumber: {
type: "string",
label: "Organisation Number",
description: "The number of the organisation",
optional: true,
},
countryCode: {
type: "string",
label: "Phone Number Country Code",
description: "The country code of the phone number",
optional: true,
},
number: {
type: "string",
label: "Phone Number",
description: "The number of the phone number",
optional: true,
},
shippingAddressData: {
type: "object",
label: "Shipping Address Data",
description: "The shipping address data. **E.g. {\"country_code\": \"US\", \"postal_code\": \"10001\", \"address_line_1\": \"123 Main St\", \"given_name\": \"John\", \"family_name\": \"Smith\", \"organisation\": \"Organization Name\"}** [See the documentation](https://afosto.com/docs/developers/storefront-js-client/custom-checkout/collecting-customer-data/)",
},
billingAddressData: {
type: "object",
label: "Billing Address Data",
description: "The billing address data. **E.g. {\"country_code\": \"US\", \"postal_code\": \"10001\", \"address_line_1\": \"123 Main St\", \"given_name\": \"John\", \"family_name\": \"Smith\", \"organisation\": \"Organization Name\"}** [See the documentation](https://afosto.com/docs/developers/storefront-js-client/custom-checkout/collecting-customer-data/)",
},
},
async run({ $ }) {
const cartId = this.cartId;

const phoneNumberData = {
country_code: this.countryCode,
number: this.number,
};

const parsedBillingAddressData = parseObject(this.billingAddressData);

const variables = {
customerInput: {
cart_id: cartId,
customer: {
contact: {
email: this.email,
is_guest: this.isGuest,
given_name: this.givenName,
additional_name: this.additionalName,
family_name: this.familyName,
phone_numbers: [
phoneNumberData,
],
},
organisation: {
name: this.organisationName,
is_guest: this.organisationIsGuest,
administration: {
email: this.organisationEmail,
},
registration: {
country_code: this.organisationCountryCode,
number: this.organisationNumber,
},
},
},
},
phoneNumberInput: {
cart_id: cartId,
phone_number: phoneNumberData,
},
shippingAddressInput: {
address: parseObject(this.shippingAddressData),
cart_id: cartId,
type: "ADDRESS",
},
billingAddressInput: {
address: parsedBillingAddressData,
cart_id: cartId,
},
countryCode: parsedBillingAddressData?.country_code,
postalCode: parsedBillingAddressData?.postal_code,
};

const response = await this.app.addInformationToCart({
$,
variables,
});

if (response.errors) {
throw new ConfigurationError(JSON.stringify(response.errors[0]));
}

$.export("$summary", `Successfully added information to cart with ID: ${this.cartId}`);
return response.data;
},
};
51 changes: 51 additions & 0 deletions components/afosto/actions/add-item-to-cart/add-item-to-cart.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { ConfigurationError } from "@pipedream/platform";
import app from "../../afosto.app.mjs";

export default {
key: "afosto-add-item-to-cart",
name: "Add Item to Cart",
description: "Add an item to a cart. [See the documentation](https://afosto.com/docs/developers/storefront-js-client/integration/add-and-remove-items/)",
version: "0.0.1",
type: "action",
props: {
app,
sku: {
type: "string",
label: "SKU",
description: "The SKU of the item to add to the cart.",
},
quantity: {
type: "integer",
label: "Quantity",
description: "The quantity of the item to add to the cart.",
},
cartId: {
propDefinition: [
app,
"cartId",
],
},
},
async run({ $ }) {
const response = await this.app.addItemToCart({
$,
variables: {
input: {
cart_id: this.cartId,
items: [
{
sku: this.sku,
quantity: this.quantity,
},
],
},
},
});

if (response.errors) {
throw new ConfigurationError(JSON.stringify(response.errors[0]));
}
$.export("$summary", `Successfully added item to cart with SKU: ${response.data.addItemsToCart.cart.items[0].sku}`);
return response.data.addItemsToCart.cart;
},
};
42 changes: 42 additions & 0 deletions components/afosto/actions/add-note-to-cart/add-note-to-cart.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { ConfigurationError } from "@pipedream/platform";
import app from "../../afosto.app.mjs";

export default {
key: "afosto-add-note-to-cart",
name: "Add Note to Cart",
description: "Add a note to a cart. [See the documentation](https://afosto.com/docs/developers/storefront-js-client/custom-checkout/checkout-summary/)",
version: "0.0.1",
type: "action",
props: {
app,
cartId: {
propDefinition: [
app,
"cartId",
],
},
note: {
type: "string",
label: "Note",
description: "The note to add to the cart",
},
},
async run({ $ }) {
const variables = {
cartId: this.cartId,
note: this.note,
};

const response = await this.app.addNoteToCart({
$,
variables,
});

if (response.errors) {
throw new ConfigurationError(JSON.stringify(response.errors[0]));
}

$.export("$summary", `Successfully added note to cart with ID: ${this.cartId}`);
return response.data.setNoteForCart.cart;
},
};
34 changes: 34 additions & 0 deletions components/afosto/actions/confirm-cart/confirm-cart.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { ConfigurationError } from "@pipedream/platform";
import app from "../../afosto.app.mjs";

export default {
key: "afosto-confirm-cart",
name: "Confirm Cart",
description: "Confirm a cart. [See the documentation](https://afosto.com/docs/developers/storefront-js-client/custom-checkout/payment-process/)",
version: "0.0.1",
type: "action",
props: {
app,
cartId: {
propDefinition: [
app,
"cartId",
],
},
},
async run({ $ }) {
const response = await this.app.confirmCart({
$,
variables: {
cartId: this.cartId,
},
});

if (response.errors) {
throw new ConfigurationError(JSON.stringify(response.errors[0]));
}

$.export("$summary", `Successfully confirmed cart with ID: ${response.data.confirmCart.order.id}`);
return response.data.confirmCart.order;
},
};
25 changes: 25 additions & 0 deletions components/afosto/actions/create-cart/create-cart.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { ConfigurationError } from "@pipedream/platform";
import app from "../../afosto.app.mjs";

export default {
key: "afosto-create-cart",
name: "Create Cart",
description: "Create a new cart. [See the documentation](https://afosto.com/docs/developers/storefront-js-client/integration/create-a-cart/)",
version: "0.0.1",
type: "action",
props: {
app,
},
async run({ $ }) {
const response = await this.app.createCart({
$,
});

if (response.errors) {
throw new ConfigurationError(JSON.stringify(response.errors[0]));
}

$.export("$summary", `Successfully created cart with ID: ${response.data.createCart.cart.id}`);
return response.data.createCart.cart;
},
};
Loading
Loading