Minor improvements to Shopify-Node

This commit is contained in:
Jan Oberhauser 2020-08-10 14:44:18 +02:00
parent 520a456105
commit f9970f7157
4 changed files with 92 additions and 94 deletions

View file

@ -1,6 +1,6 @@
import { import {
OptionsWithUri, OptionsWithUri,
} from 'request'; } from 'request';
import { import {
IExecuteFunctions, IExecuteFunctions,
@ -35,15 +35,13 @@ export async function shopifyApiRequest(this: IHookFunctions | IExecuteFunctions
json: true json: true
}; };
console.log(options);
if (Object.keys(option).length !== 0) { if (Object.keys(option).length !== 0) {
Object.assign(options, option); Object.assign(options, option);
} }
if (Object.keys(body).length === 0) { if (Object.keys(body).length === 0) {
delete options.body; delete options.body;
} }
if (Object.keys(query).length === 0) { if (Object.keys(query).length === 0) {
delete options.qs; delete options.qs;
} }
try { try {
@ -53,7 +51,7 @@ export async function shopifyApiRequest(this: IHookFunctions | IExecuteFunctions
let message = ''; let message = '';
if (typeof error.response.body.errors === 'object') { if (typeof error.response.body.errors === 'object') {
for (const key of Object.keys(error.response.body.errors)) { for (const key of Object.keys(error.response.body.errors)) {
message+= error.response.body.errors[key]; message += error.response.body.errors[key];
} }
} else { } else {
message = `${error.response.body.errors} |`; message = `${error.response.body.errors} |`;
@ -67,7 +65,7 @@ export async function shopifyApiRequest(this: IHookFunctions | IExecuteFunctions
} }
export async function shopifyApiRequestAllItems(this: IHookFunctions | IExecuteFunctions| ILoadOptionsFunctions, propertyName: string, method: string, resource: string, body: any = {}, query: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any export async function shopifyApiRequestAllItems(this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions, propertyName: string, method: string, resource: string, body: any = {}, query: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
const returnData: IDataObject[] = []; const returnData: IDataObject[] = [];
@ -78,7 +76,7 @@ export async function shopifyApiRequestAllItems(this: IHookFunctions | IExecuteF
do { do {
responseData = await shopifyApiRequest.call(this, method, resource, body, query, uri, { resolveWithFullResponse: true }); responseData = await shopifyApiRequest.call(this, method, resource, body, query, uri, { resolveWithFullResponse: true });
if (responseData.headers.link) { if (responseData.headers.link) {
uri = responseData.headers['link'].split(';')[0].replace('<', '').replace('>',''); uri = responseData.headers['link'].split(';')[0].replace('<', '').replace('>', '');
} }
returnData.push.apply(returnData, responseData.body[propertyName]); returnData.push.apply(returnData, responseData.body[propertyName]);
} while ( } while (
@ -88,7 +86,7 @@ export async function shopifyApiRequestAllItems(this: IHookFunctions | IExecuteF
return returnData; return returnData;
} }
export function keysToSnakeCase(elements: IDataObject[] | IDataObject) : IDataObject[] { export function keysToSnakeCase(elements: IDataObject[] | IDataObject): IDataObject[] {
if (elements === undefined) { if (elements === undefined) {
return []; return [];
} }

View file

@ -1,6 +1,6 @@
import { import {
INodeProperties, INodeProperties,
} from 'n8n-workflow'; } from 'n8n-workflow';
export const orderOperations = [ export const orderOperations = [
{ {
@ -48,9 +48,9 @@ export const orderOperations = [
export const orderFields = [ export const orderFields = [
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* order:create */ /* order:create */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
displayName: 'Additional Fields', displayName: 'Additional Fields',
name: 'additionalFields', name: 'additionalFields',
@ -474,9 +474,9 @@ export const orderFields = [
}, },
], ],
}, },
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* order:delete */ /* order:delete */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
displayName: 'Order ID', displayName: 'Order ID',
name: 'orderId', name: 'orderId',
@ -494,9 +494,9 @@ export const orderFields = [
}, },
required: true, required: true,
}, },
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* order:get */ /* order:get */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
displayName: 'Order ID', displayName: 'Order ID',
name: 'orderId', name: 'orderId',
@ -540,9 +540,9 @@ export const orderFields = [
}, },
], ],
}, },
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* order:getAll */ /* order:getAll */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
displayName: 'Return All', displayName: 'Return All',
name: 'returnAll', name: 'returnAll',
@ -790,9 +790,9 @@ export const orderFields = [
}, },
], ],
}, },
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* order:update */ /* order:update */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
displayName: 'Order ID', displayName: 'Order ID',
name: 'orderId', name: 'orderId',

View file

@ -4,14 +4,14 @@ import {
export interface IImage { export interface IImage {
id?: string; id?: string;
product_id?: string; product_id?: string;
position?: number; position?: number;
created_at?: string, created_at?: string;
updated_at?: string, updated_at?: string;
width?: number; width?: number;
height?: number; height?: number;
src?: string; src?: string;
variant_ids?: number[]; variant_ids?: number[];
} }
export interface IPrice { export interface IPrice {
@ -54,7 +54,7 @@ export interface IProduct {
body_html?: string; body_html?: string;
handle?: string; handle?: string;
images?: IImage[]; images?: IImage[];
options?: IDataObject[], options?: IDataObject[];
product_type?: string; product_type?: string;
published_at?: string; published_at?: string;
published_scope?: string; published_scope?: string;

View file

@ -56,240 +56,240 @@ export class ShopifyTrigger implements INodeType {
[ [
{ {
name: 'App uninstalled', name: 'App uninstalled',
value: 'app/uninstalled' value: 'app/uninstalled',
}, },
{ {
name: 'Carts create', name: 'Carts create',
value: 'carts/create' value: 'carts/create',
}, },
{ {
name: 'Carts update', name: 'Carts update',
value: 'carts/update' value: 'carts/update',
}, },
{ {
name: 'Checkouts create', name: 'Checkouts create',
value: 'checkouts/create' value: 'checkouts/create',
}, },
{ {
name: 'Checkouts delete', name: 'Checkouts delete',
value: 'checkouts/delete' value: 'checkouts/delete',
}, },
{ {
name: 'Checkouts update', name: 'Checkouts update',
value: 'checkouts/update' value: 'checkouts/update',
}, },
{ {
name: 'Collection listings add', name: 'Collection listings add',
value: 'collection_listings/add' value: 'collection_listings/add',
}, },
{ {
name: 'Collection listings remove', name: 'Collection listings remove',
value: 'collection_listings/remove' value: 'collection_listings/remove',
}, },
{ {
name: 'Collection listings update', name: 'Collection listings update',
value: 'collection_listings/update' value: 'collection_listings/update',
}, },
{ {
name: 'Collections create', name: 'Collections create',
value: 'collections/create' value: 'collections/create',
}, },
{ {
name: 'Collections delete', name: 'Collections delete',
value: 'collections/delete' value: 'collections/delete',
}, },
{ {
name: 'Collections update', name: 'Collections update',
value: 'collections/update' value: 'collections/update',
}, },
{ {
name: 'Customer groups create', name: 'Customer groups create',
value: 'customer_groups/create' value: 'customer_groups/create',
}, },
{ {
name: 'Customer groups delete', name: 'Customer groups delete',
value: 'customer_groups/delete' value: 'customer_groups/delete',
}, },
{ {
name: 'Customer groups update', name: 'Customer groups update',
value: 'customer_groups/update' value: 'customer_groups/update',
}, },
{ {
name: 'Customers create', name: 'Customers create',
value: 'customers/create' value: 'customers/create',
}, },
{ {
name: 'Customers delete', name: 'Customers delete',
value: 'customers/delete' value: 'customers/delete',
}, },
{ {
name: 'Customers disable', name: 'Customers disable',
value: 'customers/disable' value: 'customers/disable',
}, },
{ {
name: 'Customers enable', name: 'Customers enable',
value: 'customers/enable' value: 'customers/enable',
}, },
{ {
name: 'Customers update', name: 'Customers update',
value: 'customers/update' value: 'customers/update',
}, },
{ {
name: 'Draft orders create', name: 'Draft orders create',
value: 'draft_orders/create' value: 'draft_orders/create',
}, },
{ {
name: 'Draft orders delete', name: 'Draft orders delete',
value: 'draft_orders/delete' value: 'draft_orders/delete',
}, },
{ {
name: 'Draft orders update', name: 'Draft orders update',
value: 'draft_orders/update' value: 'draft_orders/update',
}, },
{ {
name: 'Fulfillment events create', name: 'Fulfillment events create',
value: 'fulfillment_events/create' value: 'fulfillment_events/create',
}, },
{ {
name: 'Fulfillment events delete', name: 'Fulfillment events delete',
value: 'fulfillment_events/delete' value: 'fulfillment_events/delete',
}, },
{ {
name: 'Fulfillments create', name: 'Fulfillments create',
value: 'fulfillments/create' value: 'fulfillments/create',
}, },
{ {
name: 'Fulfillments update', name: 'Fulfillments update',
value: 'fulfillments/update' value: 'fulfillments/update',
}, },
{ {
name: 'Inventory_items create', name: 'Inventory_items create',
value: 'inventory_items/create' value: 'inventory_items/create',
}, },
{ {
name: 'Inventory_items delete', name: 'Inventory_items delete',
value: 'inventory_items/delete' value: 'inventory_items/delete',
}, },
{ {
name: 'Inventory_items update', name: 'Inventory_items update',
value: 'inventory_items/update' value: 'inventory_items/update',
}, },
{ {
name: 'Inventory_levels connect', name: 'Inventory_levels connect',
value: 'inventory_levels/connect' value: 'inventory_levels/connect',
}, },
{ {
name: 'Inventory_levels disconnect', name: 'Inventory_levels disconnect',
value: 'inventory_levels/disconnect' value: 'inventory_levels/disconnect',
}, },
{ {
name: 'Inventory_levels update', name: 'Inventory_levels update',
value: 'inventory_levels/update' value: 'inventory_levels/update',
}, },
{ {
name: 'Locales create', name: 'Locales create',
value: 'locales/create' value: 'locales/create',
}, },
{ {
name: 'Locales update', name: 'Locales update',
value: 'locales/update' value: 'locales/update',
}, },
{ {
name: 'Locations create', name: 'Locations create',
value: 'locations/create' value: 'locations/create',
}, },
{ {
name: 'Locations delete', name: 'Locations delete',
value: 'locations/delete' value: 'locations/delete',
}, },
{ {
name: 'Locations update', name: 'Locations update',
value: 'locations/update' value: 'locations/update',
}, },
{ {
name: 'Order transactions create', name: 'Order transactions create',
value: 'order_transactions/create' value: 'order_transactions/create',
}, },
{ {
name: 'Orders cancelled', name: 'Orders cancelled',
value: 'orders/cancelled' value: 'orders/cancelled',
}, },
{ {
name: 'Orders create', name: 'Orders create',
value: 'orders/create' value: 'orders/create',
}, },
{ {
name: 'Orders delete', name: 'Orders delete',
value: 'orders/delete' value: 'orders/delete',
}, },
{ {
name: 'Orders fulfilled', name: 'Orders fulfilled',
value: 'orders/fulfilled' value: 'orders/fulfilled',
}, },
{ {
name: 'Orders paid', name: 'Orders paid',
value: 'orders/paid' value: 'orders/paid',
}, },
{ {
name: 'Orders partially fulfilled', name: 'Orders partially fulfilled',
value: 'orders/partially_fulfilled' value: 'orders/partially_fulfilled',
}, },
{ {
name: 'Orders updated', name: 'Orders updated',
value: 'orders/updated' value: 'orders/updated',
}, },
{ {
name: 'Product listings add', name: 'Product listings add',
value: 'product_listings/add' value: 'product_listings/add',
}, },
{ {
name: 'Product listings remove', name: 'Product listings remove',
value: 'product_listings/remove' value: 'product_listings/remove',
}, },
{ {
name: 'Product listings update', name: 'Product listings update',
value: 'product_listings/update' value: 'product_listings/update',
}, },
{ {
name: 'Products create', name: 'Products create',
value: 'products/create' value: 'products/create',
}, },
{ {
name: 'Products delete', name: 'Products delete',
value: 'products/delete' value: 'products/delete',
}, },
{ {
name: 'Products update', name: 'Products update',
value: 'products/update' value: 'products/update',
}, },
{ {
name: 'Refunds create', name: 'Refunds create',
value: 'refunds/create' value: 'refunds/create',
}, },
{ {
name: 'Shop update', name: 'Shop update',
value: 'shop/update' value: 'shop/update',
}, },
{ {
name: 'Tender transactions create', name: 'Tender transactions create',
value: 'tender_transactions/create' value: 'tender_transactions/create',
}, },
{ {
name: 'Themes create', name: 'Themes create',
value: 'themes/create' value: 'themes/create',
}, },
{ {
name: 'Themes delete', name: 'Themes delete',
value: 'themes/delete' value: 'themes/delete',
}, },
{ {
name: 'Themes publish', name: 'Themes publish',
value: 'themes/publish' value: 'themes/publish',
}, },
{ {
name: 'Themes update', name: 'Themes update',
value: 'themes/update' value: 'themes/update',
} },
], ],
description: 'Event that triggers the webhook', description: 'Event that triggers the webhook',
}, },