shopifymo
Version:
- Module get product information, customer, order history. - Get customer information by token and authenticate through email login, password
59 lines • 2.23 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const shopify_api_1 = require("@shopify/shopify-api");
class AdminRestApi {
constructor(shopifyApi, config) {
this.findCustomer = async (customer_id, fields) => {
try {
let customer = await this.shopifyApi.rest.Customer.find({
session: this.session,
id: customer_id
});
return customer;
}
catch (error) {
console.log('findCustomer ' + error.toString());
}
return null;
};
this.findOrderOnCustomer = async (customer_id, status = 'any') => {
try {
let ordersHistory = await this.shopifyApi.rest.Customer.orders({
session: this.session,
id: customer_id,
status
});
return ordersHistory;
}
catch (error) {
console.log('findCustomerOrder ' + error.toString());
}
return null;
};
this.getStorefrontAccessToken = async () => {
const client = new this.shopifyApi.clients.Rest({ session: this.session });
const storefrontTokenResponse = await client.post({
path: 'storefront_access_tokens',
type: shopify_api_1.DataType.JSON,
data: {
storefront_access_token: {
title: 'This is my test access token',
},
},
});
const storefrontAccessToken = storefrontTokenResponse.body['storefront_access_token']['access_token'];
return storefrontAccessToken;
};
this.shopifyApi = shopifyApi;
const sessionId = this.shopifyApi.session.getOfflineId(config.domain);
this.session = new shopify_api_1.Session({
id: sessionId,
shop: config.domain,
state: 'state',
isOnline: false,
accessToken: config.adminApiAccessToken
});
}
}
exports.default = AdminRestApi;
//# sourceMappingURL=admin-rest-api.js.map