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 3 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
59 changes: 59 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,59 @@
function CreateCustomer({ input, parameters, services }) {
const url = `${services.default}/admin/api/2023-04/customers.json`;
const options = {
method: 'POST',
body: input.customer,
headers: {
'Content-Type': 'application/json',
},
security: 'apiKey',
};

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

if (response.status !== 201) {
throw new std.unstable.MapError({
errors: [
{
message: 'Failed to create customer',
code: response.status.toString(),
},
],
});
}

const result = {
customer: {
id: body.customer?.id,
email: body.customer?.email,
accepts_marketing: body.customer?.accepts_marketing,
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,
accepts_marketing_updated_at: body.customer?.accepts_marketing_updated_at,
marketing_opt_in_level: body.customer?.marketing_opt_in_level,
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;
}
231 changes: 231 additions & 0 deletions grid/customer-management/create-customer/profile.supr
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
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 unique email address of the customer."
email! string!

"The unique phone number (E.164 format) for this customer."
phone! string!

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

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 customer's password that's confirmed."
password_confirmation! string!

"Whether to send a welcome email to the customer."
send_email_welcome! boolean!
}!
}
result {
customer {
id number!

email string!

accepts_marketing boolean!

created_at string!

updated_at string!

first_name string!

last_name string!

orders_count number!

state string!

total_spent string!

last_order_id number!

note string

verified_email boolean!

multipass_identifier string

tax_exempt boolean!

tags string!

last_order_name string!

currency string!

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!
}!]!

accepts_marketing_updated_at string!

marketing_opt_in_level string

tax_exemptions [string!]!

email_marketing_consent {
state string!

opt_in_level string

consent_updated_at string!
}!

sms_marketing_consent {
state string!

opt_in_level string!

consent_updated_at string!

consent_collected_from string!
}!

admin_graphql_api_id string!

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 {
errors! [{
message! string!
code 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,
},
}
}
}

33 changes: 33 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,33 @@
function RetrieveCustomer({ input, parameters, 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) {
throw new std.unstable.MapError({
errors: [
{
message: 'Failed to fetch customer data',
code: response.status.toString(),
},
],
});
}

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

return result;
}
Loading