Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: shopify demo use cases #384

Draft
wants to merge 7 commits into
base: main_wasm
Choose a base branch
from
Draft
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
71 changes: 71 additions & 0 deletions grid/customer-management/create-customer/maps/shopify.suma.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
function CreateCustomer({ input, services }) {
const url = `${services.default}/admin/api/2023-04/customers.json`;
const options = {
method: 'POST',
body: input,
headers: {
'Content-Type': 'application/json',
},
security: 'apiKey',
};

const response = std.unstable.fetch(url, options).response();
const body = response.bodyAuto() ?? {};

if (response.status !== 201) {
let errorMessage = 'An error occurred while creating the customer.';
if (response.status === 401) {
errorMessage = '[API] Invalid API key or access token (unrecognized login or wrong password)';
} else if (response.status === 402) {
errorMessage = "This shop's plan does not have access to this feature";
} else if (response.status === 403) {
errorMessage = 'User does not have access';
} else if (response.status === 404) {
errorMessage = 'Not Found';
} else if (response.status === 422) {
errorMessage = 'The request body contains semantic errors.';
} else if (response.status === 429) {
errorMessage = 'Exceeded 2 calls per second for api client. Reduce request rates to resume uninterrupted service.';
} else if (response.status >= 500) {
errorMessage = 'An unexpected error occurred';
}

throw new std.unstable.MapError({
errors: errorMessage,
status: response.status,
retryAfter: response.headers['Retry-After']?.[0] ? Number(response.headers['Retry-After'][0]) : null,
xShopifyShopApiCallLimit: response.headers['X-Shopify-Shop-Api-Call-Limit']?.[0] ? response.headers['X-Shopify-Shop-Api-Call-Limit'][0] : null,
});
}

const result = {
customer: {
id: body.customer.id,
email: body.customer.email,
created_at: body.customer.created_at,
updated_at: body.customer.updated_at,
first_name: body.customer.first_name,
last_name: body.customer.last_name,
orders_count: body.customer.orders_count,
state: body.customer.state,
total_spent: body.customer.total_spent,
last_order_id: body.customer.last_order_id,
note: body.customer.note,
verified_email: body.customer.verified_email,
multipass_identifier: body.customer.multipass_identifier,
tax_exempt: body.customer.tax_exempt,
tags: body.customer.tags,
last_order_name: body.customer.last_order_name,
currency: body.customer.currency,
phone: body.customer.phone,
addresses: body.customer.addresses,
tax_exemptions: body.customer.tax_exemptions,
email_marketing_consent: body.customer.email_marketing_consent,
sms_marketing_consent: body.customer.sms_marketing_consent,
admin_graphql_api_id: body.customer.admin_graphql_api_id,
default_address: body.customer.default_address,
},
};

return result;
}
250 changes: 250 additions & 0 deletions grid/customer-management/create-customer/profile.supr
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
name = "customer-management/create-customer"
version = "0.0.0"

"Creates a new customer with the provided information."
usecase CreateCustomer unsafe {
input {
customer! {
"The customer's first name."
first_name! string!

"The customer's last name."
last_name! string!

"The customer's email address."
email! string!

"The customer's phone number."
phone! string!

"Whether the customer has verified their email address."
verified_email! boolean!

"A list of the customer's addresses."
addresses! [{
"The first line of the address."
address1! string!

"The city of the address."
city! string!

"The province or state of the address."
province! string!

"The phone number associated with the address."
phone! string!

"The postal or zip code of the address."
zip! string!

"The last name of the person associated with the address."
last_name! string!

"The first name of the person associated with the address."
first_name! string!

"The country of the address."
country! string!
}!]!

"The customer's password."
password! string!

"The confirmation of the customer's password."
password_confirmation! string!

"Whether to send a welcome email to the customer."
send_email_welcome! boolean!
}!
}
result {
"The new customer object."
customer {
"The customer's ID."
id! number!

"The unique email address of the customer. Attempting to assign the same email address to multiple customers returns an error."
email! string!

"The date and time (ISO 8601 format) when the customer was created."
created_at! string!

"The date and time (ISO 8601 format) when the customer information was last updated."
updated_at! string!

first_name! string!

last_name! string!

orders_count! number!

state! string!

"The total amount of money that the customer has spent across their order history."
total_spent! string!

last_order_id! number!

"A note about the customer."
note string

"Whether the customer has verified their email address."
verified_email! boolean!

"A unique identifier for the customer that's used with Multipass login."
multipass_identifier string

"Whether the customer is exempt from paying taxes on their order. If true, then taxes won't be applied to an order at checkout. If false, then taxes will be applied at checkout."
tax_exempt! boolean!

"Tags that the shop owner has attached to the customer, formatted as a string of comma-separated values. A customer can have up to 250 tags. Each tag can have up to 255 characters."
tags! string!

"The name of the customer's last order. This is directly related to the name field on the Order resource."
last_order_name! string!

"The three-letter code (ISO 4217 format) for the currency that the customer used when they paid for their last order. Defaults to the shop currency. Returns the shop currency for test orders."
currency! string!

"The unique phone number (E.164 format) for this customer. Attempting to assign the same phone number to multiple customers returns an error."
phone! string!

addresses! [{
id! number!

customer_id! number!

first_name string

last_name string

company string

address1! string!

address2 string!

city! string!

province! string!

country! string!

zip! string!

phone! string!

name! string!

province_code! string!

country_code! string!

country_name! string!

default! boolean!
}!]!

tax_exemptions [string!]!

"The marketing consent information when the customer consented to receiving marketing material by email. The email property is required to create a customer with email consent information and to update a customer for email consent that doesn't have an email recorded. The customer must have a unique email address associated to the record. The email marketing consent has the following properties:"
email_marketing_consent! {
state! string!

opt_in_level string

consent_updated_at! string!
}!

"The marketing consent information when the customer consented to receiving marketing material by SMS. The phone property is required to create a customer with SMS consent information and to perform an SMS update on a customer that doesn't have a phone number recorded. The customer must have a unique phone number associated to the record. The SMS marketing consent has the following properties:"
sms_marketing_consent! {
state! string!

opt_in_level! string!

consent_updated_at! string!

consent_collected_from! string!
}!

admin_graphql_api_id! string!

"The default address for the customer."
default_address! {
id! number!

customer_id! number!

first_name string

last_name string

company string

address1! string!

address2 string!

city! string!

province! string!

country! string!

zip! string!

phone! string!

name! string!

province_code! string!

country_code! string!

country_name! string!

default! boolean!
}!
}!
}!
error {
"Error message describing the reason for the failed operation."
errors! string!

"HTTP status code associated with the error."
status! number!

"The number of seconds to wait before retrying the query. This property is only present in case of a 429 Too Many Requests error."
retryAfter number

"The header showing the number of requests made by the client and the total number of requests allowed per minute. This property is only present in the response headers."
xShopifyShopApiCallLimit string
}!
example InputExample {
input {
customer = {
first_name = 'Steve',
last_name = 'Lastnameson',
email = '[email protected]',
phone = '+15142546011',
verified_email = true,
addresses = [
{
address1 = '123 Oak St',
city = 'Ottawa',
province = 'ON',
phone = '555-1212',
zip = '123 ABC',
last_name = 'Lastnameson',
first_name = 'Mother',
country = 'CA',
}
],
password = 'newpass',
password_confirmation = 'newpass',
send_email_welcome = false,
},
}
}
}

48 changes: 48 additions & 0 deletions grid/customer-management/get-customer/maps/shopify.suma.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
function RetrieveCustomer({ input, services }) {
const url = `${services.default}/admin/api/2023-04/customers/${input.customer_id}.json`;
const options = {
method: 'GET',
query: {
fields: input.fields,
},
headers: {
'Content-Type': 'application/json',
},
security: 'apiKey',
};

const response = std.unstable.fetch(url, options).response();
const body = response.bodyAuto() ?? {};

if (response.status !== 200) {
let errorMessage = 'An error occurred while retrieving the customer.';
if (response.status === 401) {
errorMessage = '[API] Invalid API key or access token (unrecognized login or wrong password)';
} else if (response.status === 402) {
errorMessage = "This shop's plan does not have access to this feature";
} else if (response.status === 403) {
errorMessage = 'User does not have access';
} else if (response.status === 404) {
errorMessage = 'Not Found';
} else if (response.status === 422) {
errorMessage = 'The request body contains semantic errors.';
} else if (response.status === 429) {
errorMessage = 'Exceeded 2 calls per second for api client. Reduce request rates to resume uninterrupted service.';
} else if (response.status >= 500) {
errorMessage = 'An unexpected error occurred';
}

throw new std.unstable.MapError({
errors: errorMessage,
status: response.status,
retryAfter: response.headers['Retry-After']?.[0] ? Number(response.headers['Retry-After'][0]) : null,
xShopifyShopApiCallLimit: response.headers['X-Shopify-Shop-Api-Call-Limit']?.[0] ? response.headers['X-Shopify-Shop-Api-Call-Limit'][0] : null,
});
}

const result = {
customer: body.customer,
};

return result;
}
Loading