shopifymo
Version:
- Module get product information, customer, order history. - Get customer information by token and authenticate through email login, password
93 lines • 2.95 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class StorefrontApi {
constructor(shopifyApi, config) {
this.customerAccessTokenCreate = async (input) => {
const data = await this.storefrontClient.query({
data: `mutation customerAccessTokenCreate {
customerAccessTokenCreate(input: {email: "${input.email}", password: "${input.password}"}) {
customerAccessToken {
accessToken
expiresAt
}
customerUserErrors {
message
}
}
}`,
});
return data;
};
this.getCustomer = async (input) => {
let token = input.customerAccessToken.body.data.customerAccessTokenCreate.customerAccessToken.accessToken;
const data = await this.storefrontClient.query({
data: `query {
customer(customerAccessToken: "${token}") {
id
firstName
lastName
acceptsMarketing
email
phone
}
}`,
});
return data;
};
this.getProductAll = async () => {
const products = await this.storefrontClient.query({
data: `{
products(first: 10) {
edges {
node {
id
createdAt
description
images(first: 10) {
edges {
node {
url
src
originalSrc
id
height
altText
}
}
}
title
updatedAt
productType
publishedAt
tags
totalInventory
}
}
}
}
`,
});
return products;
};
this.getProduct = async (product_id) => {
const product = await this.storefrontClient.query({
data: `{
product(id: ${product_id}) {
createdAt
title
totalInventory
updatedAt
}
}`,
});
return product;
};
this.shopifyApi = shopifyApi;
this.storefrontClient = new this.shopifyApi.clients.Storefront({
domain: config.domain,
storefrontAccessToken: config.storefrontAccessToken
});
}
}
exports.default = StorefrontApi;
//# sourceMappingURL=storefront-api.js.map