Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@commercelayer/cli-plugin-resources

Package Overview
Dependencies
Maintainers
3
Versions
267
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@commercelayer/cli-plugin-resources - npm Package Compare versions

Comparing version 1.2.1 to 2.0.0-alpha.0

48

lib/base.d.ts
import Command, { flags } from '@oclif/command';
import { Resource } from './commands/resources';
declare type KeyVal = {
[key: string]: string | number | boolean | undefined | null;
};
declare type KeyValString = {
[key: string]: string;
};
declare type KeyValArray = {
[key: string]: string[];
};
declare type KeyValRel = {
[key: string]: {
readonly id: string;
readonly type: string;
};
};
declare type KeyValObj = {
[key: string]: any;
};
declare type KeyValSort = {
[key: string]: 'asc' | 'desc';
};
export default abstract class extends Command {

@@ -24,20 +45,13 @@ static flags: {

checkResourceId(resource: string, resourceId: string, required?: boolean): any;
includeValuesArray(flag: string[]): string[];
objectValuesMap(flag: string[]): Map<string, any>;
fieldsValuesMap(flag: string[]): Map<string, string[]>;
mapToSdkObject(map: Map<string, any>, { camelCase, nullValues, fixTypes, }?: {
camelCase?: boolean | undefined;
nullValues?: boolean | undefined;
includeFlag(flag: string[]): string[];
objectFlag(flag: string[]): KeyValObj;
fieldsFlag(flag: string[], type: string): KeyValArray;
whereFlag(flag: string[]): KeyValString;
sortFlag(flag: string[]): KeyValSort;
_keyvalFlag(flag: string[], type?: string): KeyValString;
attributeFlag(flag: string[]): KeyValObj;
metadataFlag(flag: string[], { fixTypes }?: {
fixTypes?: boolean | undefined;
}): any;
mapToSdkParam(map: Map<string, any>): any[];
/**
* @deprecated The method should not be used
*/
whereValuesMap(flag: string[]): Map<string, string>;
orderingValuesMap(flag: string[]): Map<string, string>;
_simpleValuesMap(flag: string[], type?: string): Map<string, string>;
attributeValuesMap(flag: string[]): any;
relationshipValuesMap(flag: string[]): Map<string, any>;
metadataValuesMap(flag: string[]): any;
}): KeyVal;
relationshipFlag(flag: string[]): KeyValRel;
printOutput(output: any, flags: any | undefined): void;

@@ -44,0 +58,0 @@ printError(error: any, flags?: any): void;

@@ -16,2 +16,3 @@ "use strict";

const common_1 = require("./common");
const sdk_1 = require("@commercelayer/sdk");
const update_notifier_1 = (0, tslib_1.__importDefault)(require("update-notifier"));

@@ -76,3 +77,3 @@ const pkg = require('../package.json');

}
includeValuesArray(flag) {
includeFlag(flag) {
const values = [];

@@ -87,4 +88,4 @@ if (flag) {

}
objectValuesMap(flag) {
const objects = new Map();
objectFlag(flag) {
const objects = {};
if (flag && (flag.length > 0)) {

@@ -114,5 +115,5 @@ flag.forEach(f => {

});
if (objects.get(name) === undefined)
objects.set(name, {});
objects.set(name, Object.assign(Object.assign({}, objects.get(name)), obj));
if (objects[name] === undefined)
objects[name] = {};
objects[name] = Object.assign(Object.assign({}, objects[name]), obj);
});

@@ -122,7 +123,8 @@ }

}
fieldsValuesMap(flag) {
const fields = new Map();
fieldsFlag(flag, type) {
const fields = {};
if (flag && (flag.length > 0)) {
flag.forEach(f => {
var _a, _b;
let res = type;
let val = f;
if (f.indexOf('/') > -1) {

@@ -132,21 +134,12 @@ const kv = f.split('/');

this.error('Can be defined only one resource for each fields flag', { suggestions: [`Split the value ${chalk_1.default.italic(f)} into two fields flags`] });
const res = kv[0].replace('[', '').replace(']', '');
res = kv[0].replace('[', '').replace(']', '');
this.checkResource(res);
/*
if (res.split('.').length > 3) this.error('Can be defined only resources within the 3rd level',
{ suggestions: [`Reduce total depth of the requested resource ${chalk.italic(res)}`] }
)
*/
const values = kv[1].split(',').map(v => v.trim());
if (values[0].trim() === '')
this.error(`No fields defined for resource ${chalk_1.default.italic(res)}`);
if (fields.get(res) === undefined)
fields.set(res, []);
(_a = fields.get(res)) === null || _a === void 0 ? void 0 : _a.push(...values);
val = kv[1];
}
else {
if (fields.get('__self') === undefined)
fields.set('__self', []);
(_b = fields.get('__self')) === null || _b === void 0 ? void 0 : _b.push(...f.split(',').map(v => v.trim()));
}
const values = val.split(',').map(v => v.trim());
if (values[0].trim() === '')
this.error(`No fields defined for resource ${chalk_1.default.italic(res)}`);
if (fields[res] === undefined)
fields[res] = [];
fields[res].push(...values);
});

@@ -156,82 +149,35 @@ }

}
mapToSdkObject(map, { camelCase = true, nullValues = true, fixTypes = false, } = {}) {
const object = {};
map.forEach((val, key) => {
const k = (camelCase && !key.startsWith('_')) ? lodash_1.default.camelCase(key) : key;
let v = ((val === 'null') && nullValues) ? null : val;
if (fixTypes)
v = (0, common_1.fixType)(v);
object[k] = v;
/* it should never happen in real use cases
if (object[k] === undefined) object[k] = val
else object[k] = [...val, object[k]]
*/
});
return object;
}
mapToSdkParam(map) {
const param = map.get('__self') || [];
let subfields = null;
map.forEach((val, key) => {
if (key !== '__self') {
if (subfields === null)
subfields = {};
subfields[key] = val;
/* it should never happenin real use cases
if (subfields[key] === undefined) subfields[key] = val
else subfields[key] = [...val, subfields[key]]
*/
}
});
if (subfields !== null)
param.push(subfields);
return param;
}
// eslint-disable-next-line valid-jsdoc
/**
* @deprecated The method should not be used
*/
/*
mapToSdkParamExtended(map: Map<string, string[]>): any[] {
const param: any[] = map.get('__self') as any[] || []
let subfields: any = null
map.forEach((val, key) => {
if (key !== '__self') {
if (subfields === null) subfields = {}
const kt = key.split('.')
let s = subfields
for (let i = 0; i < kt.length; i++) {
const k = kt[i]
if (i === (kt.length - 1)) {
if (s[k] === undefined) s[k] = val
else s[k] = [...val, s[k]]
} else
if (s[k] === undefined) s = s[k] = {}
else
if (Array.isArray(s[k])) {
const o = s[k].find((x: any) => (typeof x === 'object'))
if (o === undefined) s[k].push(s = {})
else s = o
} else s = s[k]
}
}
})
if (subfields !== null) param.push(subfields)
return param
}
*/
whereValuesMap(flag) {
const wheres = new Map();
mapToSdkObject(map: Map<string, string>, {
fixTypes = false,
} = {}): any {
const object: any = {}
map.forEach((val, key) => {
const v = fixTypes ? fixType(val) : val
object[key] = v
})
return object
}
mapToSdkParam(map: Map<string, string[]>,): { [key: string]: string[] } {
const param: { [key: string]: string[] } = {}
map.forEach((val, key) => {
param[key] = val
})
return param
}
*/
whereFlag(flag) {
const wheres = {};
if (flag && (flag.length > 0)) {
flag.forEach(f => {
/*
const po = f.indexOf('(') + 1
const pc = f.indexOf(')') + 1
if ((po < 2) || (pc < f.length) || (po > pc)) this.error(`Filter flag must be in the form ${chalk.italic('predicate(value)')}`)
*/
let sepChar = '/';

@@ -245,3 +191,2 @@ let si = f.indexOf(sepChar);

}
// const wt = f.split('(')
const wt = f.split(sepChar);

@@ -254,5 +199,4 @@ const w = wt[0];

});
// const v = wt[1].substring(0, (wt[1].length - 1))
const v = wt[1];
wheres.set(w, v);
wheres[w] = v;
});

@@ -262,4 +206,4 @@ }

}
orderingValuesMap(flag) {
const orderings = new Map();
sortFlag(flag) {
const sort = {};
if (flag && (flag.length > 0)) {

@@ -280,3 +224,3 @@ if (flag.some(f => {

this.error(`Invalid sort flag: ${chalk_1.default.redBright(f)}`, { suggestions: [`Sort direction can assume only the values ${chalk_1.default.italic('asc')} or ${chalk_1.default.italic('desc')}`] });
orderings.set(of, sd);
sort[of] = sd;
});

@@ -290,3 +234,3 @@ }

const sd = desc ? 'desc' : 'asc';
orderings.set(of, sd);
sort[of] = sd;
});

@@ -296,6 +240,6 @@ });

}
return orderings;
return sort;
}
_simpleValuesMap(flag, type = 'attribute') {
const map = new Map();
_keyvalFlag(flag, type = 'attribute') {
const param = {};
if (flag && (flag.length > 0)) {

@@ -310,14 +254,27 @@ flag.forEach(f => {

const value = f.substr(eqi + 1);
if (map.get(name))
if (param[name])
this.warn(`${lodash_1.default.capitalize(type)} ${chalk_1.default.yellow(name)} has already been defined`);
map.set(name, value);
param[name] = value;
});
}
return map;
return param;
}
attributeValuesMap(flag) {
return this._simpleValuesMap(flag, 'attribute');
attributeFlag(flag) {
const attr = this._keyvalFlag(flag, 'attribute');
const attributes = {};
Object.entries(attr).forEach(([k, v]) => {
attributes[k] = (v === 'null') ? null : v;
});
return attributes;
}
relationshipValuesMap(flag) {
const relationships = new Map();
metadataFlag(flag, { fixTypes = false } = {}) {
const md = this._keyvalFlag(flag, 'metadata');
const metadata = {};
Object.keys(md).forEach(k => {
metadata[k] = fixTypes ? (0, common_1.fixType)(md[k]) : md[k];
});
return metadata;
}
relationshipFlag(flag) {
const relationships = {};
if (flag && (flag.length > 0)) {

@@ -332,8 +289,8 @@ flag.forEach(f => {

const name = rt[0];
const id = vt[1];
const type = vt[0];
const id = vt[1];
const res = this.checkResource(type);
if (relationships.get(name))
// const res = this.checkResource(type)
if (relationships[name])
this.warn(`Relationship ${chalk_1.default.yellow(name)} has already been defined`);
relationships.set(name, { type, id, sdk: res === null || res === void 0 ? void 0 : res.sdk });
relationships[name] = { id, type };
});

@@ -343,5 +300,2 @@ }

}
metadataValuesMap(flag) {
return this._simpleValuesMap(flag, 'metadata');
}
printOutput(output, flags) {

@@ -353,18 +307,15 @@ if (output)

let err = error;
if (error.response) {
if (sdk_1.CommerceLayerStatic.isApiError(err)) {
err = err.errors;
}
else if (error.response) {
if (error.response.status === 401)
this.error(chalk_1.default.bgRed(`${error.response.statusText} [${error.response.status}]`), { suggestions: ['Execute login to get access to the selected resource'] });
else if (error.response.status === 500)
this.error('We\'re sorry, but something went wrong (500)');
this.error(`We're sorry, but something went wrong (${error.response.status})`);
else if (error.response.status === 429)
this.error(`You have done too many requests in the last 5 minutes (${error.response.status})`);
else
err = error.response.data.errors;
}
else if (error.errors)
err = error.errors().toArray();
else if (error.toArray)
err = error.toArray().map((e) => {
if (e.code)
e.code = lodash_1.default.snakeCase(e.code).toUpperCase(); // Fix SDK camelCase issue
return e;
});
else if (error.message)

@@ -444,2 +395,3 @@ err = error.message;

description: 'print out the raw API response',
hidden: false,
}),

@@ -446,0 +398,0 @@ };

import Command, { flags } from '../../base';
import { CommerceLayerClient } from '@commercelayer/sdk';
export default class ResourcesAll extends Command {

@@ -31,4 +32,4 @@ static description: string;

}[];
checkAccessToken(jwtData: any, flags: any, baseUrl: string): Promise<any>;
checkAccessToken(jwtData: any, flags: any, client: CommerceLayerClient): Promise<any>;
run(): Promise<any>;
}

@@ -9,5 +9,4 @@ "use strict";

const common_1 = require("../../common");
const js_sdk_1 = (0, tslib_1.__importDefault)(require("@commercelayer/js-sdk"));
const sdk_1 = (0, tslib_1.__importDefault)(require("@commercelayer/sdk"));
const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
const jsonapi_1 = require("../../jsonapi");
const cli_ux_1 = (0, tslib_1.__importDefault)(require("cli-ux"));

@@ -29,10 +28,12 @@ const node_notifier_1 = (0, tslib_1.__importDefault)(require("node-notifier"));

class ResourcesAll extends base_1.default {
async checkAccessToken(jwtData, flags, baseUrl) {
async checkAccessToken(jwtData, flags, client) {
var _a;
if (((jwtData.exp - securityInterval) * 1000) <= Date.now()) {
await cli_ux_1.default.wait((securityInterval + 1) * 1000);
const organization = flags.organization;
const domain = flags.domain;
const token = await ((_a = (0, js_auth_1.getIntegrationToken)({
clientId: flags.clientId || '',
clientSecret: flags.clientSecret || '',
endpoint: baseUrl,
endpoint: (0, common_1.baseURL)(organization, domain),
})) === null || _a === void 0 ? void 0 : _a.catch(error => {

@@ -42,3 +43,3 @@ this.error('Unable to refresh access token: ' + error.message);

const accessToken = (token === null || token === void 0 ? void 0 : token.accessToken) || '';
js_sdk_1.default.init({ accessToken, endpoint: baseUrl });
client.config({ organization, domain, accessToken });
jwtData = jsonwebtoken_1.default.decode(accessToken);

@@ -53,27 +54,30 @@ }

const resource = this.checkResource(args.resource);
const baseUrl = (0, common_1.baseURL)(flags.organization, flags.domain);
const organization = flags.organization;
const domain = flags.domain;
const accessToken = flags.accessToken;
let notification = flags.notify;
// Include flags
const include = this.includeValuesArray(flags.include);
const include = this.includeFlag(flags.include);
// Fields flags
const fields = this.mapToSdkParam(this.fieldsValuesMap(flags.fields));
const fields = this.fieldsFlag(flags.fields, resource.api);
// Where flags
const wheres = this.mapToSdkParam(this.whereValuesMap(flags.where));
// Order flags
const order = this.mapToSdkParam(this.orderingValuesMap(flags.sort));
const wheres = this.whereFlag(flags.where);
// Sort flags
const sort = this.sortFlag(flags.sort);
try {
const resObj = js_sdk_1.default[resource.sdk];
let req = resObj;
const cl = (0, sdk_1.default)({ organization, domain, accessToken });
let jwtData = jsonwebtoken_1.default.decode(accessToken);
const resSdk = cl[resource.api];
const params = {};
if (include && (include.length > 0))
req = req.includes(...include);
if (fields && (fields.length > 0))
req = req.select(...fields);
if (wheres && (wheres.length > 0))
req = req.where(...wheres);
if (order && (order.length > 0))
req = req.order(...order);
params.include = include;
if (fields && (Object.keys(fields).length > 0))
params.fields = fields;
if (wheres && (Object.keys(wheres).length > 0))
params.filters = wheres;
if (sort && (Object.keys(sort).length > 0))
params.sort = sort;
else
req = req.order({ created_at: 'asc' }); // query order issue
req = req.perPage(maxPageItems);
params.sort = { created_at: 'asc' }; // query order issue
params.pageSize = maxPageItems;
const resources = [];

@@ -89,4 +93,2 @@ let page = 0;

});
js_sdk_1.default.init({ accessToken, endpoint: baseUrl });
let jwtData = jsonwebtoken_1.default.decode(accessToken);
do {

@@ -101,6 +103,7 @@ page++;

await cli_ux_1.default.wait((pages < 600) ? 200 : 500);
jwtData = await this.checkAccessToken(jwtData, flags, baseUrl);
const res = await req.page(page).all({ rawResponse: true });
pages = res.meta.page_count; // pages count can change during extraction
const recordCount = res.meta.record_count;
jwtData = await this.checkAccessToken(jwtData, flags, cl);
params.pageNumber = page;
const res = await resSdk.list(params);
pages = res.meta.pageCount; // pages count can change during extraction
const recordCount = res.meta.recordCount;
if (recordCount > 0) {

@@ -119,4 +122,4 @@ if (page === 1) {

progressBar.setTotal(recordCount);
resources.push(...(flags.raw ? res.data : (0, jsonapi_1.denormalize)(res)));
progressBar.increment(res.data.length);
resources.push(...res);
progressBar.increment(res.length);
}

@@ -126,2 +129,4 @@ } while ((pages === -1) || (page < pages));

const out = resources;
if (out.meta)
delete out.meta;
// Print and save output

@@ -128,0 +133,0 @@ if (out.length > 0) {

@@ -6,4 +6,3 @@ "use strict";

const common_1 = require("../../common");
const js_sdk_1 = (0, tslib_1.__importDefault)(require("@commercelayer/js-sdk"));
const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
const sdk_1 = (0, tslib_1.__importDefault)(require("@commercelayer/sdk"));
const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));

@@ -16,3 +15,4 @@ const raw_1 = require("../../raw");

const resource = this.checkResource(args.resource, { singular: true });
const baseUrl = (0, common_1.baseURL)(flags.organization, flags.domain);
const organization = flags.organization;
const domain = flags.domain;
const accessToken = flags.accessToken;

@@ -22,2 +22,3 @@ // Raw request

try {
const baseUrl = (0, common_1.baseURL)(flags.organization, flags.domain);
const rawRes = await (0, raw_1.rawRequest)({ operation: raw_1.Operation.Create, baseUrl, accessToken, resource: resource.api }, (0, raw_1.readDataFile)(flags.data));

@@ -33,24 +34,25 @@ const out = flags.raw ? rawRes : (0, jsonapi_1.denormalize)(rawRes);

}
const cl = (0, sdk_1.default)({ organization, domain, accessToken });
// Attributes flags
const attributes = this.mapToSdkObject(this.attributeValuesMap(flags.attribute));
const attributes = this.attributeFlag(flags.attribute);
// Objects flags
const objects = this.objectValuesMap(flags.object);
const objects = this.objectFlag(flags.object);
// Relationships flags
const relationships = this.relationshipValuesMap(flags.relationship);
const relationships = this.relationshipFlag(flags.relationship);
// Metadata flags
const metadata = this.mapToSdkObject(this.metadataValuesMap(flags.metadata), { camelCase: false, fixTypes: true });
const metadata = this.metadataFlag(flags.metadata, { fixTypes: true });
// Relationships
if (relationships && (relationships.size > 0))
relationships.forEach((value, key) => {
const relSdk = js_sdk_1.default[value.sdk];
const rel = relSdk.build({ id: value.id });
attributes[lodash_1.default.camelCase(key)] = rel;
if (relationships && (Object.keys(relationships).length > 0))
Object.entries(relationships).forEach(([key, value]) => {
const relSdk = cl[value.type];
const rel = relSdk.relationship(value);
attributes[key] = rel;
});
// Objects
if (objects && (objects.size > 0)) {
for (const o of objects.keys()) {
if (objects && (Object.keys(objects).length > 0)) {
for (const o of Object.keys(objects)) {
if (Object.keys(attributes).includes(o))
this.warn(`Object ${o} will overwrite attribute ${o}`);
else
attributes[o] = objects.get(o);
attributes[o] = objects[o];
}

@@ -64,10 +66,9 @@ }

}
js_sdk_1.default.init({ accessToken, endpoint: baseUrl });
try {
const resSdk = js_sdk_1.default[resource.sdk];
const res = await resSdk.create(attributes, { rawResponse: true });
const out = flags.raw ? res : (0, jsonapi_1.denormalize)(res);
const resSdk = cl[resource.api];
const res = await resSdk.create(attributes);
const out = res;
this.printOutput(out, flags);
// if (res.valid())
this.log(`\n${chalk_1.default.greenBright('Successfully')} created new resource of type ${chalk_1.default.bold(resource.api)} with id ${chalk_1.default.bold(res.data.id)}\n`);
this.log(`\n${chalk_1.default.greenBright('Successfully')} created new resource of type ${chalk_1.default.bold(resource.api)} with id ${chalk_1.default.bold(res.id)}\n`);
return out;

@@ -82,3 +83,3 @@ }

ResourcesCreate.description = 'create a new resource';
ResourcesCreate.aliases = ['create', 'rc', 'res:create'];
ResourcesCreate.aliases = ['create', 'rc', 'res:create', 'post'];
ResourcesCreate.examples = [

@@ -85,0 +86,0 @@ '$ commercelayer resources:create customers -a email=user@test.com',

@@ -5,4 +5,3 @@ "use strict";

const base_1 = (0, tslib_1.__importDefault)(require("../../base"));
const common_1 = require("../../common");
const js_sdk_1 = (0, tslib_1.__importDefault)(require("@commercelayer/js-sdk"));
const sdk_1 = (0, tslib_1.__importDefault)(require("@commercelayer/sdk"));
const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));

@@ -14,14 +13,10 @@ class ResourcesDelete extends base_1.default {

const resource = this.checkResource(res, { singular: true });
const baseUrl = (0, common_1.baseURL)(flags.organization, flags.domain);
const organization = flags.organization;
const domain = flags.domain;
const accessToken = flags.accessToken;
js_sdk_1.default.init({ accessToken, endpoint: baseUrl });
const cl = (0, sdk_1.default)({ organization, domain, accessToken });
try {
const resSdk = js_sdk_1.default[resource.sdk];
const res = await resSdk.find(id).then((r) => {
return r.destroy();
});
// this.printOutput(res, flags)
// if (res.valid())
this.log(`\n${chalk_1.default.greenBright('Successfully')} deleted resource of type ${chalk_1.default.bold(resource.api)} with id ${chalk_1.default.bold(res.id)}\n`);
// return res
const resSdk = cl[resource.api];
await resSdk.delete(id);
this.log(`\n${chalk_1.default.greenBright('Successfully')} deleted resource of type ${chalk_1.default.bold(resource.api)} with id ${chalk_1.default.bold(id)}\n`);
}

@@ -28,0 +23,0 @@ catch (error) {

@@ -15,3 +15,3 @@ import { Command } from '@oclif/command';

api: string;
sdk: string;
model: string;
singleton?: boolean;

@@ -18,0 +18,0 @@ }

@@ -42,88 +42,92 @@ "use strict";

const resources = [
{ name: 'address', api: 'addresses', sdk: 'Address' },
{ name: 'adjustment', api: 'adjustments', sdk: 'Adjustment' },
{ name: 'adyen_gateway', api: 'adyen_gateways', sdk: 'AdyenGateway' },
{ name: 'adyen_payment', api: 'adyen_payments', sdk: 'AdyenPayment' },
{ name: 'application', api: 'applications', sdk: 'Application', singleton: true },
// { name: 'attachable', api: 'attachables', sdk: 'Attachable' },
{ name: 'attachment', api: 'attachments', sdk: 'Attachment' },
{ name: 'authorization', api: 'authorizations', sdk: 'Authorization' },
{ name: 'avalara_account', api: 'avalara_accounts', sdk: 'AvalaraAccount' },
{ name: 'billing_info_validation_rule', api: 'billing_info_validation_rules', sdk: 'BillingInfoValidationRule' },
{ name: 'braintree_gateway', api: 'braintree_gateways', sdk: 'BraintreeGateway' },
{ name: 'braintree_payment', api: 'braintree_payments', sdk: 'BraintreePayment' },
{ name: 'capture', api: 'captures', sdk: 'Capture' },
{ name: 'carrier_account', api: 'carrier_accounts', sdk: 'CarrierAccount' },
{ name: 'coupon', api: 'coupons', sdk: 'Coupon' },
{ name: 'coupon_codes_promotion_rule', api: 'coupon_codes_promotion_rules', sdk: 'CouponCodesPromotionRule' },
{ name: 'customer', api: 'customers', sdk: 'Customer' },
{ name: 'customer_address', api: 'customer_addresses', sdk: 'CustomerAddress' },
{ name: 'customer_group', api: 'customer_groups', sdk: 'CustomerGroup' },
{ name: 'customer_password_reset', api: 'customer_password_resets', sdk: 'CustomerPasswordReset' },
{ name: 'customer_payment_source', api: 'customer_payment_sources', sdk: 'CustomerPaymentSource' },
{ name: 'customer_subscription', api: 'customer_subscriptions', sdk: 'CustomerSubscription' },
{ name: 'delivery_lead_time', api: 'delivery_lead_times', sdk: 'DeliveryLeadTime' },
{ name: 'external_gateway', api: 'external_gateways', sdk: 'ExternalGateway' },
{ name: 'external_payment', api: 'external_payments', sdk: 'ExternalPayment' },
{ name: 'external_promotion', api: 'external_promotions', sdk: 'ExternalPromotion' },
{ name: 'external_tax_calculator', api: 'external_tax_calculators', sdk: 'ExternalTaxCalculator' },
{ name: 'fixed_amount_promotion', api: 'fixed_amount_promotions', sdk: 'FixedAmountPromotion' },
{ name: 'free_shipping_promotion', api: 'free_shipping_promotions', sdk: 'FreeShippingPromotion' },
// { name: 'geocoder', api: 'geocoders', sdk: 'Geocoder' },
{ name: 'gift_card', api: 'gift_cards', sdk: 'GiftCard' },
{ name: 'gift_card_recipient', api: 'gift_card_recipients', sdk: 'GiftCardRecipient' },
{ name: 'import', api: 'imports', sdk: 'Import' },
{ name: 'in_stock_subscription', api: 'in_stock_subscriptions', sdk: 'InStockSubscription' },
{ name: 'inventory_model', api: 'inventory_models', sdk: 'InventoryModel' },
{ name: 'inventory_return_location', api: 'inventory_return_locations', sdk: 'InventoryReturnLocation' },
{ name: 'inventory_stock_location', api: 'inventory_stock_locations', sdk: 'InventoryStockLocation' },
{ name: 'item', api: 'items', sdk: 'Item' },
{ name: 'line_item', api: 'line_items', sdk: 'LineItem' },
{ name: 'line_item_option', api: 'line_item_options', sdk: 'LineItemOption' },
{ name: 'manual_gateway', api: 'manual_gateways', sdk: 'ManualGateway' },
{ name: 'manual_tax_calculator', api: 'manual_tax_calculators', sdk: 'ManualTaxCalculator' },
{ name: 'market', api: 'markets', sdk: 'Market' },
{ name: 'merchant', api: 'merchants', sdk: 'Merchant' },
{ name: 'order', api: 'orders', sdk: 'Order' },
{ name: 'order_amount_promotion_rule', api: 'order_amount_promotion_rules', sdk: 'OrderAmountPromotionRule' },
{ name: 'organization', api: 'organization', sdk: 'Organization', singleton: true },
{ name: 'package', api: 'packages', sdk: 'Package' },
{ name: 'parcel', api: 'parcels', sdk: 'Parcel' },
{ name: 'parcel_line_item', api: 'parcel_line_items', sdk: 'ParcelLineItem' },
{ name: 'payment_gateway', api: 'payment_gateways', sdk: 'PaymentGateway' },
{ name: 'payment_method', api: 'payment_methods', sdk: 'PaymentMethod' },
{ name: 'payment_source', api: 'payment_sources', sdk: 'PaymentSource' },
{ name: 'paypal_gateway', api: 'paypal_gateways', sdk: 'PaypalGateway' },
{ name: 'paypal_payment', api: 'paypal_payments', sdk: 'PaypalPayment' },
{ name: 'percentage_discount_promotion', api: 'percentage_discount_promotions', sdk: 'PercentageDiscountPromotion' },
{ name: 'price', api: 'prices', sdk: 'Price' },
{ name: 'price_list', api: 'price_lists', sdk: 'PriceList' },
{ name: 'promotion', api: 'promotions', sdk: 'Promotion' },
{ name: 'promotion_rule', api: 'promotion_rules', sdk: 'PromotionRule' },
{ name: 'refund', api: 'refunds', sdk: 'Refund' },
{ name: 'return', api: 'returns', sdk: 'Return' },
{ name: 'return_line_item', api: 'return_line_items', sdk: 'ReturnLineItem' },
{ name: 'shipment', api: 'shipments', sdk: 'Shipment' },
// { name: 'shipment_line_item', api: 'shipment_line_items', sdk: 'ShipmentLineItem' },
{ name: 'shipping_category', api: 'shipping_categories', sdk: 'ShippingCategory' },
{ name: 'shipping_method', api: 'shipping_methods', sdk: 'ShippingMethod' },
{ name: 'shipping_zone', api: 'shipping_zones', sdk: 'ShippingZone' },
{ name: 'sku', api: 'skus', sdk: 'Sku' },
{ name: 'sku_list', api: 'sku_lists', sdk: 'SkuList' },
{ name: 'sku_list_item', api: 'sku_list_items', sdk: 'SkuListItem' },
{ name: 'sku_list_promotion_rule', api: 'sku_list_promotion_rules', sdk: 'SkuListPromotionRule' },
{ name: 'sku_option', api: 'sku_options', sdk: 'SkuOption' },
{ name: 'stock_item', api: 'stock_items', sdk: 'StockItem' },
{ name: 'stock_location', api: 'stock_locations', sdk: 'StockLocation' },
{ name: 'stock_transfer', api: 'stock_transfers', sdk: 'StockTransfer' },
{ name: 'stripe_gateway', api: 'stripe_gateways', sdk: 'StripeGateway' },
{ name: 'stripe_payment', api: 'stripe_payments', sdk: 'StripePayment' },
{ name: 'tax_calculator', api: 'tax_calculators', sdk: 'TaxCalculator' },
{ name: 'tax_category', api: 'tax_categories', sdk: 'TaxCategory' },
{ name: 'tax_rule', api: 'tax_rules', sdk: 'TaxRule' },
{ name: 'taxjar_account', api: 'taxjar_accounts', sdk: 'TaxjarAccount' },
{ name: 'transaction', api: 'transactions', sdk: 'Transaction' },
{ name: 'void', api: 'voids', sdk: 'Void' },
{ name: 'webhook', api: 'webhooks', sdk: 'Webhook' },
{ name: 'wire_transfer', api: 'wire_transfers', sdk: 'WireTransfer' },
{ name: 'address', api: 'addresses', model: 'Address' },
{ name: 'adjustment', api: 'adjustments', model: 'Adjustment' },
{ name: 'adyen_gateway', api: 'adyen_gateways', model: 'AdyenGateway' },
{ name: 'adyen_payment', api: 'adyen_payments', model: 'AdyenPayment' },
{ name: 'application', api: 'application', model: 'Application', singleton: true },
{ name: 'attachment', api: 'attachments', model: 'Attachment' },
{ name: 'authorization', api: 'authorizations', model: 'Authorization' },
{ name: 'avalara_account', api: 'avalara_accounts', model: 'AvalaraAccount' },
{ name: 'billing_info_validation_rule', api: 'billing_info_validation_rules', model: 'BillingInfoValidationRule' },
{ name: 'bing_geocoder', api: 'bing_geocoders', model: 'BingGeocoder' },
{ name: 'braintree_gateway', api: 'braintree_gateways', model: 'BraintreeGateway' },
{ name: 'braintree_payment', api: 'braintree_payments', model: 'BraintreePayment' },
{ name: 'bundle', api: 'bundles', model: 'Bundle' },
{ name: 'capture', api: 'captures', model: 'Capture' },
{ name: 'carrier_account', api: 'carrier_accounts', model: 'CarrierAccount' },
{ name: 'checkout_com_gateway', api: 'checkout_com_gateways', model: 'CheckoutComGateway' },
{ name: 'checkout_com_payment', api: 'checkout_com_payments', model: 'CheckoutComPayment' },
{ name: 'coupon_codes_promotion_rule', api: 'coupon_codes_promotion_rules', model: 'CouponCodesPromotionRule' },
{ name: 'coupon', api: 'coupons', model: 'Coupon' },
{ name: 'customer_address', api: 'customer_addresses', model: 'CustomerAddress' },
{ name: 'customer_group', api: 'customer_groups', model: 'CustomerGroup' },
{ name: 'customer_password_reset', api: 'customer_password_resets', model: 'CustomerPasswordReset' },
{ name: 'customer_payment_source', api: 'customer_payment_sources', model: 'CustomerPaymentSource' },
{ name: 'customer_subscription', api: 'customer_subscriptions', model: 'CustomerSubscription' },
{ name: 'customer', api: 'customers', model: 'Customer' },
{ name: 'delivery_lead_time', api: 'delivery_lead_times', model: 'DeliveryLeadTime' },
{ name: 'external_gateway', api: 'external_gateways', model: 'ExternalGateway' },
{ name: 'external_payment', api: 'external_payments', model: 'ExternalPayment' },
{ name: 'external_promotion', api: 'external_promotions', model: 'ExternalPromotion' },
{ name: 'external_tax_calculator', api: 'external_tax_calculators', model: 'ExternalTaxCalculator' },
{ name: 'fixed_amount_promotion', api: 'fixed_amount_promotions', model: 'FixedAmountPromotion' },
{ name: 'free_shipping_promotion', api: 'free_shipping_promotions', model: 'FreeShippingPromotion' },
{ name: 'geocoder', api: 'geocoders', model: 'Geocoder' },
{ name: 'gift_card_recipient', api: 'gift_card_recipients', model: 'GiftCardRecipient' },
{ name: 'gift_card', api: 'gift_cards', model: 'GiftCard' },
{ name: 'google_geocoder', api: 'google_geocoders', model: 'GoogleGeocoder' },
{ name: 'import', api: 'imports', model: 'Import' },
{ name: 'in_stock_subscription', api: 'in_stock_subscriptions', model: 'InStockSubscription' },
{ name: 'inventory_model', api: 'inventory_models', model: 'InventoryModel' },
{ name: 'inventory_return_location', api: 'inventory_return_locations', model: 'InventoryReturnLocation' },
{ name: 'inventory_stock_location', api: 'inventory_stock_locations', model: 'InventoryStockLocation' },
{ name: 'line_item_option', api: 'line_item_options', model: 'LineItemOption' },
{ name: 'line_item', api: 'line_items', model: 'LineItem' },
{ name: 'manual_gateway', api: 'manual_gateways', model: 'ManualGateway' },
{ name: 'manual_tax_calculator', api: 'manual_tax_calculators', model: 'ManualTaxCalculator' },
{ name: 'market', api: 'markets', model: 'Market' },
{ name: 'merchant', api: 'merchants', model: 'Merchant' },
{ name: 'order_amount_promotion_rule', api: 'order_amount_promotion_rules', model: 'OrderAmountPromotionRule' },
{ name: 'order_copy', api: 'order_copies', model: 'OrderCopy' },
{ name: 'order_subscription', api: 'order_subscriptions', model: 'OrderSubscription' },
{ name: 'order', api: 'orders', model: 'Order' },
{ name: 'organization', api: 'organization', model: 'Organization', singleton: true },
{ name: 'package', api: 'packages', model: 'Package' },
{ name: 'parcel_line_item', api: 'parcel_line_items', model: 'ParcelLineItem' },
{ name: 'parcel', api: 'parcels', model: 'Parcel' },
{ name: 'payment_gateway', api: 'payment_gateways', model: 'PaymentGateway' },
{ name: 'payment_method', api: 'payment_methods', model: 'PaymentMethod' },
{ name: 'paypal_gateway', api: 'paypal_gateways', model: 'PaypalGateway' },
{ name: 'paypal_payment', api: 'paypal_payments', model: 'PaypalPayment' },
{ name: 'percentage_discount_promotion', api: 'percentage_discount_promotions', model: 'PercentageDiscountPromotion' },
{ name: 'price_list', api: 'price_lists', model: 'PriceList' },
{ name: 'price', api: 'prices', model: 'Price' },
{ name: 'promotion_rule', api: 'promotion_rules', model: 'PromotionRule' },
{ name: 'promotion', api: 'promotions', model: 'Promotion' },
{ name: 'refund', api: 'refunds', model: 'Refund' },
{ name: 'return_line_item', api: 'return_line_items', model: 'ReturnLineItem' },
{ name: 'return', api: 'returns', model: 'Return' },
{ name: 'shipment', api: 'shipments', model: 'Shipment' },
{ name: 'shipping_category', api: 'shipping_categories', model: 'ShippingCategory' },
{ name: 'shipping_method', api: 'shipping_methods', model: 'ShippingMethod' },
{ name: 'shipping_zone', api: 'shipping_zones', model: 'ShippingZone' },
{ name: 'sku_list_item', api: 'sku_list_items', model: 'SkuListItem' },
{ name: 'sku_list_promotion_rule', api: 'sku_list_promotion_rules', model: 'SkuListPromotionRule' },
{ name: 'sku_list', api: 'sku_lists', model: 'SkuList' },
{ name: 'sku_option', api: 'sku_options', model: 'SkuOption' },
{ name: 'sku', api: 'skus', model: 'Sku' },
{ name: 'stock_item', api: 'stock_items', model: 'StockItem' },
{ name: 'stock_line_item', api: 'stock_line_items', model: 'StockLineItem' },
{ name: 'stock_location', api: 'stock_locations', model: 'StockLocation' },
{ name: 'stock_transfer', api: 'stock_transfers', model: 'StockTransfer' },
{ name: 'stripe_gateway', api: 'stripe_gateways', model: 'StripeGateway' },
{ name: 'stripe_payment', api: 'stripe_payments', model: 'StripePayment' },
{ name: 'tax_calculator', api: 'tax_calculators', model: 'TaxCalculator' },
{ name: 'tax_category', api: 'tax_categories', model: 'TaxCategory' },
{ name: 'tax_rule', api: 'tax_rules', model: 'TaxRule' },
{ name: 'taxjar_account', api: 'taxjar_accounts', model: 'TaxjarAccount' },
{ name: 'transaction', api: 'transactions', model: 'Transaction' },
{ name: 'void', api: 'voids', model: 'Void' },
{ name: 'webhook', api: 'webhooks', model: 'Webhook' },
{ name: 'wire_transfer', api: 'wire_transfers', model: 'WireTransfer' },
];

@@ -130,0 +134,0 @@ const findResource = (res, { singular = false } = {}) => {

@@ -5,6 +5,4 @@ "use strict";

const base_1 = (0, tslib_1.__importStar)(require("../../base"));
const common_1 = require("../../common");
const js_sdk_1 = (0, tslib_1.__importDefault)(require("@commercelayer/js-sdk"));
const sdk_1 = (0, tslib_1.__importDefault)(require("@commercelayer/sdk"));
const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
const jsonapi_1 = require("../../jsonapi");
const cli_ux_1 = (0, tslib_1.__importDefault)(require("cli-ux"));

@@ -15,37 +13,41 @@ class ResourcesList extends base_1.default {

const resource = this.checkResource(args.resource);
const baseUrl = (0, common_1.baseURL)(flags.organization, flags.domain);
// const baseUrl = baseURL(flags.organization, flags.domain)
const organization = flags.organization;
const domain = flags.domain;
const accessToken = flags.accessToken;
// Include flags
const include = this.includeValuesArray(flags.include);
const include = this.includeFlag(flags.include);
// Fields flags
const fields = this.mapToSdkParam(this.fieldsValuesMap(flags.fields));
const fields = this.fieldsFlag(flags.fields, resource.api);
// Where flags
const wheres = this.mapToSdkParam(this.whereValuesMap(flags.where));
// Order flags
const order = this.mapToSdkParam(this.orderingValuesMap(flags.sort));
const wheres = this.whereFlag(flags.where);
// Sort flags
const sort = this.sortFlag(flags.sort);
const page = flags.page;
const perPage = flags.pageSize;
js_sdk_1.default.init({ accessToken, endpoint: baseUrl });
const cl = (0, sdk_1.default)({ organization, domain, accessToken });
try {
const resObj = js_sdk_1.default[resource.sdk];
let req = resObj;
const resSdk = cl[resource.api];
const params = {};
if (include && (include.length > 0))
req = req.includes(...include);
if (fields && (fields.length > 0))
req = req.select(...fields);
if (wheres && (wheres.length > 0))
req = req.where(...wheres);
if (order && (order.length > 0))
req = req.order(...order);
params.include = include;
if (fields && (Object.keys(fields).length > 0))
params.fields = fields;
if (wheres && (Object.keys(wheres).length > 0))
params.filters = wheres;
if (sort && (Object.keys(sort).length > 0))
params.sort = sort;
if (perPage && (perPage > 0))
req = req.perPage(perPage);
params.pageSize = perPage;
if (page && (page > 0))
req = req.page(page);
params.pageNumber = page;
cli_ux_1.default.action.start(`Fetching ${resource.api.replace(/_/g, ' ')}`);
const res = await req.all({ rawResponse: true });
const res = await resSdk.list(params);
cli_ux_1.default.action.stop();
const out = flags.raw ? res : (0, jsonapi_1.denormalize)(res);
if (res.data && (res.data.length > 0)) {
const out = res;
const meta = res.meta;
delete out.meta;
if (res && (res.length > 0)) {
this.printOutput(out, flags);
this.log(`\nRecords: ${chalk_1.default.blueBright(res.data.length)} of ${res.meta.record_count} | Page: ${chalk_1.default.blueBright(String(flags.page || 1))} of ${res.meta.page_count}\n`);
this.log(`\nRecords: ${chalk_1.default.blueBright(res.length)} of ${meta.recordCount} | Page: ${chalk_1.default.blueBright(String(flags.page || 1))} of ${meta.pageCount}\n`);
if (flags.save || flags['save-path'])

@@ -52,0 +54,0 @@ this.saveOutput(out, flags);

@@ -5,5 +5,3 @@ "use strict";

const base_1 = (0, tslib_1.__importStar)(require("../../base"));
const common_1 = require("../../common");
const js_sdk_1 = (0, tslib_1.__importDefault)(require("@commercelayer/js-sdk"));
const jsonapi_1 = require("../../jsonapi");
const sdk_1 = (0, tslib_1.__importDefault)(require("@commercelayer/sdk"));
class ResourcesRetrieve extends base_1.default {

@@ -14,18 +12,19 @@ async run() {

const resource = this.checkResource(res, { singular: true });
const baseUrl = (0, common_1.baseURL)(flags.organization, flags.domain);
const organization = flags.organization;
const domain = flags.domain;
const accessToken = flags.accessToken;
// Include flags
const include = this.includeValuesArray(flags.include);
const include = this.includeFlag(flags.include);
// Fields flags
const fields = this.mapToSdkParam(this.fieldsValuesMap(flags.fields));
js_sdk_1.default.init({ accessToken, endpoint: baseUrl });
const fields = this.fieldsFlag(flags.fields, resource.api);
const cl = (0, sdk_1.default)({ organization, domain, accessToken });
try {
const resObj = js_sdk_1.default[resource.sdk];
let req = resObj;
const resSdk = cl[resource.api];
const params = resSdk;
if (include && (include.length > 0))
req = req.includes(...include);
if (fields && (fields.length > 0))
req = req.select(...fields);
const res = await req.find(resource.singleton ? undefined : id, { rawResponse: true });
const out = flags.raw ? res : (0, jsonapi_1.denormalize)(res);
params.include = include;
if (fields && (Object.keys(fields).length > 0))
params.fields = fields;
const res = await resSdk.retrieve(id, params);
const out = res;
this.printOutput(out, flags);

@@ -32,0 +31,0 @@ if (flags.save || flags['save-path'])

@@ -6,4 +6,3 @@ "use strict";

const common_1 = require("../../common");
const js_sdk_1 = (0, tslib_1.__importDefault)(require("@commercelayer/js-sdk"));
const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
const sdk_1 = (0, tslib_1.__importDefault)(require("@commercelayer/sdk"));
const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));

@@ -17,3 +16,4 @@ const raw_1 = require("../../raw");

const resource = this.checkResource(res, { singular: true });
const baseUrl = (0, common_1.baseURL)(flags.organization, flags.domain);
const organization = flags.organization;
const domain = flags.domain;
const accessToken = flags.accessToken;

@@ -23,6 +23,7 @@ // Raw request

try {
const baseUrl = (0, common_1.baseURL)(flags.organization, flags.domain);
const rawRes = await (0, raw_1.rawRequest)({ operation: raw_1.Operation.Update, baseUrl, accessToken, resource: resource.api }, (0, raw_1.readDataFile)(flags.data), id);
const out = flags.raw ? rawRes : (0, jsonapi_1.denormalize)(rawRes);
this.printOutput(out, flags);
this.log(`\n${chalk_1.default.greenBright('Successfully')} updated resource of type ${chalk_1.default.bold(resource.api)} with id ${chalk_1.default.bold(rawRes.data.id)}\n`);
this.log(`\n${chalk_1.default.greenBright('Successfully')} updated resource of type ${chalk_1.default.bold(resource.api)} with id ${chalk_1.default.bold(rawRes.id)}\n`);
return out;

@@ -34,24 +35,25 @@ }

}
const cl = (0, sdk_1.default)({ organization, domain, accessToken });
// Attributes flags
const attributes = this.mapToSdkObject(this.attributeValuesMap(flags.attribute));
const attributes = this.attributeFlag(flags.attribute);
// Objects flags
const objects = this.objectValuesMap(flags.object);
const objects = this.objectFlag(flags.object);
// Relationships flags
const relationships = this.relationshipValuesMap(flags.relationship);
const relationships = this.relationshipFlag(flags.relationship);
// Metadata flags
const metadata = this.mapToSdkObject(this.metadataValuesMap(flags.metadata || flags['metadata-replace']), { camelCase: false, fixTypes: true });
const metadata = this.metadataFlag(flags.metadata || flags['metadata-replace']);
// Relationships
if (relationships && (relationships.size > 0))
relationships.forEach((value, key) => {
const relSdk = js_sdk_1.default[value.sdk];
const rel = relSdk.build({ id: value.id });
attributes[lodash_1.default.camelCase(key)] = rel;
if (relationships && Object.keys(relationships).length > 0)
Object.entries(relationships).forEach(([key, value]) => {
const relSdk = cl[value.type];
const rel = relSdk.relationship(value);
attributes[key] = rel;
});
// Objects
if (objects && (objects.size > 0)) {
for (const o of objects.keys()) {
if (objects && (Object.keys(objects).length > 0)) {
for (const o of Object.keys(objects)) {
if (Object.keys(attributes).includes(o))
this.warn(`Object ${o} will overwrite attribute ${o}`);
else
attributes[o] = objects.get(o);
attributes[o] = objects[o];
}

@@ -65,17 +67,20 @@ }

}
js_sdk_1.default.init({ accessToken, endpoint: baseUrl });
try {
const resSdk = js_sdk_1.default[resource.sdk];
const resSdk = cl[resource.api];
// Metadata attributes merge
if (flags.metadata) {
const remRes = await resSdk.select('metadata').find(id, { rawResponse: true });
const remMeta = remRes.data.attributes.metadata;
const params = { fields: {} };
if (params === null || params === void 0 ? void 0 : params.fields)
params.fields[resource.api] = ['metadata'];
const remRes = await resSdk.retrieve(id, params);
const remMeta = remRes.metadata;
if (remMeta && (Object.keys(remMeta).length > 0))
attributes.metadata = Object.assign(Object.assign({}, remMeta), metadata);
}
const res = await resSdk.build({ id }).update(attributes, undefined, { rawResponse: true });
const out = flags.raw ? res : (0, jsonapi_1.denormalize)(res);
attributes.id = id;
const res = await resSdk.update(attributes);
const out = res;
this.printOutput(out, flags);
// if (res.valid())
this.log(`\n${chalk_1.default.greenBright('Successfully')} updated resource of type ${chalk_1.default.bold(resource.api)} with id ${chalk_1.default.bold(res.data.id)}\n`);
this.log(`\n${chalk_1.default.greenBright('Successfully')} updated resource of type ${chalk_1.default.bold(resource.api)} with id ${chalk_1.default.bold(res.id)}\n`);
return out;

@@ -90,3 +95,3 @@ }

ResourcesUpdate.description = 'update an existing resource';
ResourcesUpdate.aliases = ['update', 'ru', 'res:update'];
ResourcesUpdate.aliases = ['update', 'ru', 'res:update', 'patch'];
ResourcesUpdate.examples = [

@@ -93,0 +98,0 @@ '$ commercelayer resources:update customers/<customerId> -a reference=referenceId',

@@ -5,3 +5,3 @@ "use strict";

const axios_1 = (0, tslib_1.__importDefault)(require("axios"));
const js_sdk_1 = (0, tslib_1.__importDefault)(require("@commercelayer/js-sdk"));
const sdk_1 = require("@commercelayer/sdk");
const resUrl = 'https://core.commercelayer.io/api/public/resources';

@@ -32,3 +32,3 @@ const resFile = './resources.json';

const isSingleton = (res) => {
return ['organization'].includes(res);
return ['organization', 'application'].includes(res);
};

@@ -40,8 +40,7 @@ const parseResourcesSchema = async () => {

const resList = resJson.data.map((r) => {
const singleton = isSingleton(r.id);
const item = {
name: r.id,
api: singleton ? r.id : Inflector.pluralize(r.id),
sdk: Inflector.camelize(r.id),
singleton,
api: r.attributes.singleton ? r.id : Inflector.pluralize(r.id),
model: Inflector.camelize(r.id),
singleton: r.attributes.singleton,
};

@@ -56,10 +55,9 @@ return item;

const Inflector = require('inflector-js');
const resList = Object.keys(js_sdk_1.default).filter(r => (r.charAt(0) === r.charAt(0).toUpperCase())).map(r => {
const name = Inflector.underscore(r);
const singleton = isSingleton(name);
const resList = sdk_1.CommerceLayerStatic.resources().map(r => {
const singular = Inflector.singularize(r);
const item = {
name: name,
api: singleton ? name : Inflector.pluralize(name),
sdk: r,
singleton,
name: singular,
api: r,
model: Inflector.camelize(singular),
singleton: isSingleton(r),
};

@@ -76,6 +74,6 @@ return item;

let item = `${tab ? '\t' : ''}{ `;
item += `name: '${res.name}', api: '${res.api}', sdk: '${res.sdk}'`;
item += `name: '${res.name}', api: '${res.api}', model: '${res.model}'`;
if (res.singleton)
item += ', singleton: true';
item += ' }';
item += ' },';
console.log(item);

@@ -85,3 +83,5 @@ });

console.log(']\n');
console.log('\nResources generated from: ' + source + '\n');
};
exportResources({ array: true, tab: true });
const source = (process.argv.length > 2) ? (['sdk', 'online'].includes(process.argv[2]) ? process.argv[2] : 'sdk') : undefined;
exportResources({ source, array: true, tab: true });

@@ -1,1 +0,1 @@

{"version":"1.2.1","commands":{"order:actions":{"id":"order:actions","description":"show a list of possible actions","pluginName":"@commercelayer/cli-plugin-resources","pluginType":"core","hidden":false,"aliases":[],"flags":{},"args":[]},"order:approve":{"id":"order:approve","description":"approve an order","pluginName":"@commercelayer/cli-plugin-resources","pluginType":"core","hidden":false,"aliases":[],"flags":{"organization":{"name":"organization","type":"option","char":"o","description":"the slug of your organization","required":true},"domain":{"name":"domain","type":"option","char":"d","hidden":true,"required":false},"accessToken":{"name":"accessToken","type":"option","hidden":true,"required":true},"json":{"name":"json","type":"boolean","char":"j","description":"convert output in standard JSON format","allowNo":false},"unformatted":{"name":"unformatted","type":"boolean","char":"u","description":"print unformatted JSON output","allowNo":false},"raw":{"name":"raw","type":"boolean","char":"R","description":"print out the raw API response","allowNo":false}},"args":[{"name":"id","description":"the id of the order to approve","required":true}]},"order:capture":{"id":"order:capture","description":"capture an order","pluginName":"@commercelayer/cli-plugin-resources","pluginType":"core","hidden":false,"aliases":[],"flags":{"organization":{"name":"organization","type":"option","char":"o","description":"the slug of your organization","required":true},"domain":{"name":"domain","type":"option","char":"d","hidden":true,"required":false},"accessToken":{"name":"accessToken","type":"option","hidden":true,"required":true},"json":{"name":"json","type":"boolean","char":"j","description":"convert output in standard JSON format","allowNo":false},"unformatted":{"name":"unformatted","type":"boolean","char":"u","description":"print unformatted JSON output","allowNo":false},"raw":{"name":"raw","type":"boolean","char":"R","description":"print out the raw API response","allowNo":false}},"args":[{"name":"id","description":"the id of the order to capture","required":true}]},"order":{"id":"order","description":"execute an action on the order (place, approve, capture ...","pluginName":"@commercelayer/cli-plugin-resources","pluginType":"core","hidden":false,"aliases":[],"flags":{"organization":{"name":"organization","type":"option","char":"o","description":"the slug of your organization","required":true},"domain":{"name":"domain","type":"option","char":"d","hidden":true,"required":false},"accessToken":{"name":"accessToken","type":"option","hidden":true,"required":true},"json":{"name":"json","type":"boolean","char":"j","description":"convert output in standard JSON format","allowNo":false},"unformatted":{"name":"unformatted","type":"boolean","char":"u","description":"print unformatted JSON output","allowNo":false},"raw":{"name":"raw","type":"boolean","char":"R","description":"print out the raw API response","allowNo":false}},"args":[{"name":"action","description":"the action to execute on the order","required":true},{"name":"id","description":"the id of the order","required":false}]},"order:place":{"id":"order:place","description":"place an order","pluginName":"@commercelayer/cli-plugin-resources","pluginType":"core","hidden":false,"aliases":[],"flags":{"organization":{"name":"organization","type":"option","char":"o","description":"the slug of your organization","required":true},"domain":{"name":"domain","type":"option","char":"d","hidden":true,"required":false},"accessToken":{"name":"accessToken","type":"option","hidden":true,"required":true},"json":{"name":"json","type":"boolean","char":"j","description":"convert output in standard JSON format","allowNo":false},"unformatted":{"name":"unformatted","type":"boolean","char":"u","description":"print unformatted JSON output","allowNo":false},"raw":{"name":"raw","type":"boolean","char":"R","description":"print out the raw API response","allowNo":false}},"args":[{"name":"id","description":"the id of the order to place","required":true}]},"resources:all":{"id":"resources:all","description":"fetch all resources","pluginName":"@commercelayer/cli-plugin-resources","pluginType":"core","hidden":true,"aliases":["all","ra","res:all"],"examples":["$ commercelayer resources:all customers -f id,email -i customer_group -s updated_at","$ cl res:all -i customer_group -f customer_groups/name -w customer_group_name_eq=\"GROUP NAME\"","$ cl all -s -created_at --json"],"flags":{"organization":{"name":"organization","type":"option","char":"o","description":"the slug of your organization","required":true},"domain":{"name":"domain","type":"option","char":"d","hidden":true,"required":false},"accessToken":{"name":"accessToken","type":"option","hidden":true,"required":true},"json":{"name":"json","type":"boolean","char":"j","description":"convert output in standard JSON format","allowNo":false},"unformatted":{"name":"unformatted","type":"boolean","char":"u","description":"print unformatted JSON output","allowNo":false},"raw":{"name":"raw","type":"boolean","char":"R","description":"print out the raw API response","allowNo":false},"include":{"name":"include","type":"option","char":"i","description":"comma separated resources to include"},"fields":{"name":"fields","type":"option","char":"f","description":"comma separeted list of fields in the format [resource]=field1,field2..."},"where":{"name":"where","type":"option","char":"w","description":"comma separated list of query filters"},"sort":{"name":"sort","type":"option","char":"s","description":"defines results ordering"},"save":{"name":"save","type":"option","char":"x","description":"save command output to file"},"save-path":{"name":"save-path","type":"option","char":"X","description":"save command output to file and create missing path directories"},"notify":{"name":"notify","type":"boolean","char":"N","description":"force system notification when export has finished","hidden":true,"allowNo":false},"clientId":{"name":"clientId","type":"option","char":"i","description":"organization client_id","hidden":true,"required":false},"clientSecret":{"name":"clientSecret","type":"option","char":"s","description":"organization client_secret","hidden":true,"required":false},"csv":{"name":"csv","type":"boolean","char":"C","description":"export fields in csv format","allowNo":false},"header":{"name":"header","type":"option","char":"H","description":"comma-separated list of values field:\"renamed title\""}},"args":[{"name":"resource","description":"the resource type","required":true}]},"resources:create":{"id":"resources:create","description":"create a new resource","pluginName":"@commercelayer/cli-plugin-resources","pluginType":"core","aliases":["create","rc","res:create"],"examples":["$ commercelayer resources:create customers -a email=user@test.com","$ clayer res:create customers -a email=\"user@test-com\" -r customer_group=customer_groups/<customerGroupId>","$ cl create customers -a email=user@test.com -m meta_key=\"meta value\"","$ cl rc customers -D /path/to/data/file/data.json"],"flags":{"organization":{"name":"organization","type":"option","char":"o","description":"the slug of your organization","required":true},"domain":{"name":"domain","type":"option","char":"d","hidden":true,"required":false},"accessToken":{"name":"accessToken","type":"option","hidden":true,"required":true},"json":{"name":"json","type":"boolean","char":"j","description":"convert output in standard JSON format","allowNo":false},"unformatted":{"name":"unformatted","type":"boolean","char":"u","description":"print unformatted JSON output","allowNo":false},"raw":{"name":"raw","type":"boolean","char":"R","description":"print out the raw API response","allowNo":false},"attribute":{"name":"attribute","type":"option","char":"a","description":"define a resource attribute"},"object":{"name":"object","type":"option","char":"O","description":"define a resource object attribute"},"relationship":{"name":"relationship","type":"option","char":"r","description":"define a relationship with another resource"},"metadata":{"name":"metadata","type":"option","char":"m","description":"define a metadata attribute or a set of metadata attributes"},"data":{"name":"data","type":"option","char":"D","description":"the data file to use as request body"}},"args":[{"name":"resource","description":"the resource type","required":true}]},"resources:delete":{"id":"resources:delete","description":"delete an existing resource","pluginName":"@commercelayer/cli-plugin-resources","pluginType":"core","aliases":["delete","rd","res:delete"],"examples":["$ commercelayer resources:delete customers/<customerId>","$ cl delete customers <customerId>"],"flags":{"organization":{"name":"organization","type":"option","char":"o","description":"the slug of your organization","required":true},"domain":{"name":"domain","type":"option","char":"d","hidden":true,"required":false},"accessToken":{"name":"accessToken","type":"option","hidden":true,"required":true},"json":{"name":"json","type":"boolean","char":"j","description":"convert output in standard JSON format","allowNo":false},"unformatted":{"name":"unformatted","type":"boolean","char":"u","description":"print unformatted JSON output","allowNo":false},"raw":{"name":"raw","type":"boolean","char":"R","description":"print out the raw API response","allowNo":false}},"args":[{"name":"resource","description":"the resource type","required":true},{"name":"id","description":"id of the resource to retrieve","required":false}]},"resources:doc":{"id":"resources:doc","description":"show the online documentation of the resource in the browser","pluginName":"@commercelayer/cli-plugin-resources","pluginType":"core","aliases":["res:doc","rdoc"],"examples":["$ commercelayer rdoc customers","$ cl res:doc cusatomers"],"flags":{},"args":[{"name":"resource","description":"the resource for wich you want to access the online documentation","required":true}]},"resources:filters":{"id":"resources:filters","description":"show a list of all available filter predicates","pluginName":"@commercelayer/cli-plugin-resources","pluginType":"core","aliases":["res:filters"],"examples":["$ commercelayer resources:filters","$ cl res:filters"],"flags":{},"args":[]},"resources:get":{"id":"resources:get","description":"retrieve a resource or list a set of resources","pluginName":"@commercelayer/cli-plugin-resources","pluginType":"core","aliases":["get","res:get"],"examples":["$ commercelayer resources:get customers","$ commercelayer res:get customers","$ clayer res:get customers/<customerId>","$ cl get customers <customerId>"],"flags":{"organization":{"name":"organization","type":"option","char":"o","description":"the slug of your organization","required":true},"domain":{"name":"domain","type":"option","char":"d","hidden":true,"required":false},"accessToken":{"name":"accessToken","type":"option","hidden":true,"required":true},"json":{"name":"json","type":"boolean","char":"j","description":"convert output in standard JSON format","allowNo":false},"unformatted":{"name":"unformatted","type":"boolean","char":"u","description":"print unformatted JSON output","allowNo":false},"raw":{"name":"raw","type":"boolean","char":"R","description":"print out the raw API response","allowNo":false},"include":{"name":"include","type":"option","char":"i","description":"comma separated resources to include"},"fields":{"name":"fields","type":"option","char":"f","description":"comma separeted list of fields in the format [resource]=field1,field2..."},"where":{"name":"where","type":"option","char":"w","description":"comma separated list of query filters"},"page":{"name":"page","type":"option","char":"p","description":"page number"},"pageSize":{"name":"pageSize","type":"option","char":"n","description":"number of elements per page"},"sort":{"name":"sort","type":"option","char":"s","description":"defines results ordering"},"save":{"name":"save","type":"option","char":"x","description":"save command output to file"},"save-path":{"name":"save-path","type":"option","char":"X","description":"save command output to file and create missing path directories"}},"args":[{"name":"resource","description":"the resource type","required":true},{"name":"id","description":"id of the resource to retrieve","required":false}]},"resources":{"id":"resources","description":"list all the available Commerce Layer API resources","pluginName":"@commercelayer/cli-plugin-resources","pluginType":"core","aliases":[],"examples":["$ cl-resources resources","$ cl-res resources","$ commercelayer resources","$ cl resources"],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[]},"resources:list":{"id":"resources:list","description":"fetch a collection of resources","pluginName":"@commercelayer/cli-plugin-resources","pluginType":"core","aliases":["list","rl","res:list"],"examples":["$ commercelayer resources:list customers -f id,email -i customer_group -s updated_at","$ cl res:list -i customer_group -f customer_groups/name -w customer_group_name_eq=\"GROUP NAME\"","$ cl list -p 5 -n 10 -s -created_at --raw"],"flags":{"organization":{"name":"organization","type":"option","char":"o","description":"the slug of your organization","required":true},"domain":{"name":"domain","type":"option","char":"d","hidden":true,"required":false},"accessToken":{"name":"accessToken","type":"option","hidden":true,"required":true},"json":{"name":"json","type":"boolean","char":"j","description":"convert output in standard JSON format","allowNo":false},"unformatted":{"name":"unformatted","type":"boolean","char":"u","description":"print unformatted JSON output","allowNo":false},"raw":{"name":"raw","type":"boolean","char":"R","description":"print out the raw API response","allowNo":false},"include":{"name":"include","type":"option","char":"i","description":"comma separated resources to include"},"fields":{"name":"fields","type":"option","char":"f","description":"comma separeted list of fields in the format [resource]=field1,field2..."},"where":{"name":"where","type":"option","char":"w","description":"comma separated list of query filters"},"page":{"name":"page","type":"option","char":"p","description":"page number"},"pageSize":{"name":"pageSize","type":"option","char":"n","description":"number of elements per page"},"sort":{"name":"sort","type":"option","char":"s","description":"defines results ordering"},"save":{"name":"save","type":"option","char":"x","description":"save command output to file"},"save-path":{"name":"save-path","type":"option","char":"X","description":"save command output to file and create missing path directories"}},"args":[{"name":"resource","description":"the resource type","required":true}]},"resources:retrieve":{"id":"resources:retrieve","description":"fetch a single resource","pluginName":"@commercelayer/cli-plugin-resources","pluginType":"core","aliases":["retrieve","rr","res:retrieve"],"examples":["$ commercelayer resources:retrieve customers/<customerId>","$ commercelayer retrieve customers <customerId>","$ cl res:retrieve customers <customerId>","$ clayer rr customers/<customerId>"],"flags":{"organization":{"name":"organization","type":"option","char":"o","description":"the slug of your organization","required":true},"domain":{"name":"domain","type":"option","char":"d","hidden":true,"required":false},"accessToken":{"name":"accessToken","type":"option","hidden":true,"required":true},"json":{"name":"json","type":"boolean","char":"j","description":"convert output in standard JSON format","allowNo":false},"unformatted":{"name":"unformatted","type":"boolean","char":"u","description":"print unformatted JSON output","allowNo":false},"raw":{"name":"raw","type":"boolean","char":"R","description":"print out the raw API response","allowNo":false},"include":{"name":"include","type":"option","char":"i","description":"comma separated resources to include"},"fields":{"name":"fields","type":"option","char":"f","description":"comma separeted list of fields in the format [resource]=field1,field2..."},"save":{"name":"save","type":"option","char":"x","description":"save command output to file"},"save-path":{"name":"save-path","type":"option","char":"X","description":"save command output to file and create missing path directories"}},"args":[{"name":"resource","description":"the resource type","required":true},{"name":"id","description":"id of the resource to retrieve","required":false}]},"resources:update":{"id":"resources:update","description":"update an existing resource","pluginName":"@commercelayer/cli-plugin-resources","pluginType":"core","aliases":["update","ru","res:update"],"examples":["$ commercelayer resources:update customers/<customerId> -a reference=referenceId","$ commercelayer res:update customers <customerId> -a reference_origin=\"Ref Origin\"","$ cl update customers/<customerId> -m meta_key=\"meta value\"","$ cl ru customers <customerId> -M mete_keu=\"metadata overwrite","$ clayer update customers <customerId> -D /path/to/data/file/data.json"],"flags":{"organization":{"name":"organization","type":"option","char":"o","description":"the slug of your organization","required":true},"domain":{"name":"domain","type":"option","char":"d","hidden":true,"required":false},"accessToken":{"name":"accessToken","type":"option","hidden":true,"required":true},"json":{"name":"json","type":"boolean","char":"j","description":"convert output in standard JSON format","allowNo":false},"unformatted":{"name":"unformatted","type":"boolean","char":"u","description":"print unformatted JSON output","allowNo":false},"raw":{"name":"raw","type":"boolean","char":"R","description":"print out the raw API response","allowNo":false},"attribute":{"name":"attribute","type":"option","char":"a","description":"define a resource attribute"},"object":{"name":"object","type":"option","char":"O","description":"define a resource object attribute"},"relationship":{"name":"relationship","type":"option","char":"r","description":"define a relationship with another resource"},"metadata":{"name":"metadata","type":"option","char":"m","description":"define a metadata attribute and merge it with the metadata already present in the remote resource"},"metadata-replace":{"name":"metadata-replace","type":"option","char":"M","description":"define a metadata attribute and replace every item already presente in the remote resource"},"data":{"name":"data","type":"option","char":"D","description":"the data file to use as request body"}},"args":[{"name":"resource","description":"the resource type","required":true},{"name":"id","description":"id of the resource to retrieve","required":false}]}}}
{"version":"2.0.0-alpha.0","commands":{"order:actions":{"id":"order:actions","description":"show a list of possible actions","pluginName":"@commercelayer/cli-plugin-resources","pluginType":"core","hidden":false,"aliases":[],"flags":{},"args":[]},"order:approve":{"id":"order:approve","description":"approve an order","pluginName":"@commercelayer/cli-plugin-resources","pluginType":"core","hidden":false,"aliases":[],"flags":{"organization":{"name":"organization","type":"option","char":"o","description":"the slug of your organization","required":true},"domain":{"name":"domain","type":"option","char":"d","hidden":true,"required":false},"accessToken":{"name":"accessToken","type":"option","hidden":true,"required":true},"json":{"name":"json","type":"boolean","char":"j","description":"convert output in standard JSON format","allowNo":false},"unformatted":{"name":"unformatted","type":"boolean","char":"u","description":"print unformatted JSON output","allowNo":false},"raw":{"name":"raw","type":"boolean","char":"R","description":"print out the raw API response","hidden":false,"allowNo":false}},"args":[{"name":"id","description":"the id of the order to approve","required":true}]},"order:capture":{"id":"order:capture","description":"capture an order","pluginName":"@commercelayer/cli-plugin-resources","pluginType":"core","hidden":false,"aliases":[],"flags":{"organization":{"name":"organization","type":"option","char":"o","description":"the slug of your organization","required":true},"domain":{"name":"domain","type":"option","char":"d","hidden":true,"required":false},"accessToken":{"name":"accessToken","type":"option","hidden":true,"required":true},"json":{"name":"json","type":"boolean","char":"j","description":"convert output in standard JSON format","allowNo":false},"unformatted":{"name":"unformatted","type":"boolean","char":"u","description":"print unformatted JSON output","allowNo":false},"raw":{"name":"raw","type":"boolean","char":"R","description":"print out the raw API response","hidden":false,"allowNo":false}},"args":[{"name":"id","description":"the id of the order to capture","required":true}]},"order":{"id":"order","description":"execute an action on the order (place, approve, capture ...","pluginName":"@commercelayer/cli-plugin-resources","pluginType":"core","hidden":false,"aliases":[],"flags":{"organization":{"name":"organization","type":"option","char":"o","description":"the slug of your organization","required":true},"domain":{"name":"domain","type":"option","char":"d","hidden":true,"required":false},"accessToken":{"name":"accessToken","type":"option","hidden":true,"required":true},"json":{"name":"json","type":"boolean","char":"j","description":"convert output in standard JSON format","allowNo":false},"unformatted":{"name":"unformatted","type":"boolean","char":"u","description":"print unformatted JSON output","allowNo":false},"raw":{"name":"raw","type":"boolean","char":"R","description":"print out the raw API response","hidden":false,"allowNo":false}},"args":[{"name":"action","description":"the action to execute on the order","required":true},{"name":"id","description":"the id of the order","required":false}]},"order:place":{"id":"order:place","description":"place an order","pluginName":"@commercelayer/cli-plugin-resources","pluginType":"core","hidden":false,"aliases":[],"flags":{"organization":{"name":"organization","type":"option","char":"o","description":"the slug of your organization","required":true},"domain":{"name":"domain","type":"option","char":"d","hidden":true,"required":false},"accessToken":{"name":"accessToken","type":"option","hidden":true,"required":true},"json":{"name":"json","type":"boolean","char":"j","description":"convert output in standard JSON format","allowNo":false},"unformatted":{"name":"unformatted","type":"boolean","char":"u","description":"print unformatted JSON output","allowNo":false},"raw":{"name":"raw","type":"boolean","char":"R","description":"print out the raw API response","hidden":false,"allowNo":false}},"args":[{"name":"id","description":"the id of the order to place","required":true}]},"resources:all":{"id":"resources:all","description":"fetch all resources","pluginName":"@commercelayer/cli-plugin-resources","pluginType":"core","hidden":true,"aliases":["all","ra","res:all"],"examples":["$ commercelayer resources:all customers -f id,email -i customer_group -s updated_at","$ cl res:all -i customer_group -f customer_groups/name -w customer_group_name_eq=\"GROUP NAME\"","$ cl all -s -created_at --json"],"flags":{"organization":{"name":"organization","type":"option","char":"o","description":"the slug of your organization","required":true},"domain":{"name":"domain","type":"option","char":"d","hidden":true,"required":false},"accessToken":{"name":"accessToken","type":"option","hidden":true,"required":true},"json":{"name":"json","type":"boolean","char":"j","description":"convert output in standard JSON format","allowNo":false},"unformatted":{"name":"unformatted","type":"boolean","char":"u","description":"print unformatted JSON output","allowNo":false},"raw":{"name":"raw","type":"boolean","char":"R","description":"print out the raw API response","hidden":false,"allowNo":false},"include":{"name":"include","type":"option","char":"i","description":"comma separated resources to include"},"fields":{"name":"fields","type":"option","char":"f","description":"comma separeted list of fields in the format [resource]=field1,field2..."},"where":{"name":"where","type":"option","char":"w","description":"comma separated list of query filters"},"sort":{"name":"sort","type":"option","char":"s","description":"defines results ordering"},"save":{"name":"save","type":"option","char":"x","description":"save command output to file"},"save-path":{"name":"save-path","type":"option","char":"X","description":"save command output to file and create missing path directories"},"notify":{"name":"notify","type":"boolean","char":"N","description":"force system notification when export has finished","hidden":true,"allowNo":false},"clientId":{"name":"clientId","type":"option","char":"i","description":"organization client_id","hidden":true,"required":false},"clientSecret":{"name":"clientSecret","type":"option","char":"s","description":"organization client_secret","hidden":true,"required":false},"csv":{"name":"csv","type":"boolean","char":"C","description":"export fields in csv format","allowNo":false},"header":{"name":"header","type":"option","char":"H","description":"comma-separated list of values field:\"renamed title\""}},"args":[{"name":"resource","description":"the resource type","required":true}]},"resources:create":{"id":"resources:create","description":"create a new resource","pluginName":"@commercelayer/cli-plugin-resources","pluginType":"core","aliases":["create","rc","res:create","post"],"examples":["$ commercelayer resources:create customers -a email=user@test.com","$ clayer res:create customers -a email=\"user@test-com\" -r customer_group=customer_groups/<customerGroupId>","$ cl create customers -a email=user@test.com -m meta_key=\"meta value\"","$ cl rc customers -D /path/to/data/file/data.json"],"flags":{"organization":{"name":"organization","type":"option","char":"o","description":"the slug of your organization","required":true},"domain":{"name":"domain","type":"option","char":"d","hidden":true,"required":false},"accessToken":{"name":"accessToken","type":"option","hidden":true,"required":true},"json":{"name":"json","type":"boolean","char":"j","description":"convert output in standard JSON format","allowNo":false},"unformatted":{"name":"unformatted","type":"boolean","char":"u","description":"print unformatted JSON output","allowNo":false},"raw":{"name":"raw","type":"boolean","char":"R","description":"print out the raw API response","hidden":false,"allowNo":false},"attribute":{"name":"attribute","type":"option","char":"a","description":"define a resource attribute"},"object":{"name":"object","type":"option","char":"O","description":"define a resource object attribute"},"relationship":{"name":"relationship","type":"option","char":"r","description":"define a relationship with another resource"},"metadata":{"name":"metadata","type":"option","char":"m","description":"define a metadata attribute or a set of metadata attributes"},"data":{"name":"data","type":"option","char":"D","description":"the data file to use as request body"}},"args":[{"name":"resource","description":"the resource type","required":true}]},"resources:delete":{"id":"resources:delete","description":"delete an existing resource","pluginName":"@commercelayer/cli-plugin-resources","pluginType":"core","aliases":["delete","rd","res:delete"],"examples":["$ commercelayer resources:delete customers/<customerId>","$ cl delete customers <customerId>"],"flags":{"organization":{"name":"organization","type":"option","char":"o","description":"the slug of your organization","required":true},"domain":{"name":"domain","type":"option","char":"d","hidden":true,"required":false},"accessToken":{"name":"accessToken","type":"option","hidden":true,"required":true},"json":{"name":"json","type":"boolean","char":"j","description":"convert output in standard JSON format","allowNo":false},"unformatted":{"name":"unformatted","type":"boolean","char":"u","description":"print unformatted JSON output","allowNo":false},"raw":{"name":"raw","type":"boolean","char":"R","description":"print out the raw API response","hidden":false,"allowNo":false}},"args":[{"name":"resource","description":"the resource type","required":true},{"name":"id","description":"id of the resource to retrieve","required":false}]},"resources:doc":{"id":"resources:doc","description":"show the online documentation of the resource in the browser","pluginName":"@commercelayer/cli-plugin-resources","pluginType":"core","aliases":["res:doc","rdoc"],"examples":["$ commercelayer rdoc customers","$ cl res:doc cusatomers"],"flags":{},"args":[{"name":"resource","description":"the resource for wich you want to access the online documentation","required":true}]},"resources:filters":{"id":"resources:filters","description":"show a list of all available filter predicates","pluginName":"@commercelayer/cli-plugin-resources","pluginType":"core","aliases":["res:filters"],"examples":["$ commercelayer resources:filters","$ cl res:filters"],"flags":{},"args":[]},"resources:get":{"id":"resources:get","description":"retrieve a resource or list a set of resources","pluginName":"@commercelayer/cli-plugin-resources","pluginType":"core","aliases":["get","res:get"],"examples":["$ commercelayer resources:get customers","$ commercelayer res:get customers","$ clayer res:get customers/<customerId>","$ cl get customers <customerId>"],"flags":{"organization":{"name":"organization","type":"option","char":"o","description":"the slug of your organization","required":true},"domain":{"name":"domain","type":"option","char":"d","hidden":true,"required":false},"accessToken":{"name":"accessToken","type":"option","hidden":true,"required":true},"json":{"name":"json","type":"boolean","char":"j","description":"convert output in standard JSON format","allowNo":false},"unformatted":{"name":"unformatted","type":"boolean","char":"u","description":"print unformatted JSON output","allowNo":false},"raw":{"name":"raw","type":"boolean","char":"R","description":"print out the raw API response","hidden":false,"allowNo":false},"include":{"name":"include","type":"option","char":"i","description":"comma separated resources to include"},"fields":{"name":"fields","type":"option","char":"f","description":"comma separeted list of fields in the format [resource]=field1,field2..."},"where":{"name":"where","type":"option","char":"w","description":"comma separated list of query filters"},"page":{"name":"page","type":"option","char":"p","description":"page number"},"pageSize":{"name":"pageSize","type":"option","char":"n","description":"number of elements per page"},"sort":{"name":"sort","type":"option","char":"s","description":"defines results ordering"},"save":{"name":"save","type":"option","char":"x","description":"save command output to file"},"save-path":{"name":"save-path","type":"option","char":"X","description":"save command output to file and create missing path directories"}},"args":[{"name":"resource","description":"the resource type","required":true},{"name":"id","description":"id of the resource to retrieve","required":false}]},"resources":{"id":"resources","description":"list all the available Commerce Layer API resources","pluginName":"@commercelayer/cli-plugin-resources","pluginType":"core","aliases":[],"examples":["$ cl-resources resources","$ cl-res resources","$ commercelayer resources","$ cl resources"],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[]},"resources:list":{"id":"resources:list","description":"fetch a collection of resources","pluginName":"@commercelayer/cli-plugin-resources","pluginType":"core","aliases":["list","rl","res:list"],"examples":["$ commercelayer resources:list customers -f id,email -i customer_group -s updated_at","$ cl res:list -i customer_group -f customer_groups/name -w customer_group_name_eq=\"GROUP NAME\"","$ cl list -p 5 -n 10 -s -created_at --raw"],"flags":{"organization":{"name":"organization","type":"option","char":"o","description":"the slug of your organization","required":true},"domain":{"name":"domain","type":"option","char":"d","hidden":true,"required":false},"accessToken":{"name":"accessToken","type":"option","hidden":true,"required":true},"json":{"name":"json","type":"boolean","char":"j","description":"convert output in standard JSON format","allowNo":false},"unformatted":{"name":"unformatted","type":"boolean","char":"u","description":"print unformatted JSON output","allowNo":false},"raw":{"name":"raw","type":"boolean","char":"R","description":"print out the raw API response","hidden":false,"allowNo":false},"include":{"name":"include","type":"option","char":"i","description":"comma separated resources to include"},"fields":{"name":"fields","type":"option","char":"f","description":"comma separeted list of fields in the format [resource]=field1,field2..."},"where":{"name":"where","type":"option","char":"w","description":"comma separated list of query filters"},"page":{"name":"page","type":"option","char":"p","description":"page number"},"pageSize":{"name":"pageSize","type":"option","char":"n","description":"number of elements per page"},"sort":{"name":"sort","type":"option","char":"s","description":"defines results ordering"},"save":{"name":"save","type":"option","char":"x","description":"save command output to file"},"save-path":{"name":"save-path","type":"option","char":"X","description":"save command output to file and create missing path directories"}},"args":[{"name":"resource","description":"the resource type","required":true}]},"resources:retrieve":{"id":"resources:retrieve","description":"fetch a single resource","pluginName":"@commercelayer/cli-plugin-resources","pluginType":"core","aliases":["retrieve","rr","res:retrieve"],"examples":["$ commercelayer resources:retrieve customers/<customerId>","$ commercelayer retrieve customers <customerId>","$ cl res:retrieve customers <customerId>","$ clayer rr customers/<customerId>"],"flags":{"organization":{"name":"organization","type":"option","char":"o","description":"the slug of your organization","required":true},"domain":{"name":"domain","type":"option","char":"d","hidden":true,"required":false},"accessToken":{"name":"accessToken","type":"option","hidden":true,"required":true},"json":{"name":"json","type":"boolean","char":"j","description":"convert output in standard JSON format","allowNo":false},"unformatted":{"name":"unformatted","type":"boolean","char":"u","description":"print unformatted JSON output","allowNo":false},"raw":{"name":"raw","type":"boolean","char":"R","description":"print out the raw API response","hidden":false,"allowNo":false},"include":{"name":"include","type":"option","char":"i","description":"comma separated resources to include"},"fields":{"name":"fields","type":"option","char":"f","description":"comma separeted list of fields in the format [resource]=field1,field2..."},"save":{"name":"save","type":"option","char":"x","description":"save command output to file"},"save-path":{"name":"save-path","type":"option","char":"X","description":"save command output to file and create missing path directories"}},"args":[{"name":"resource","description":"the resource type","required":true},{"name":"id","description":"id of the resource to retrieve","required":false}]},"resources:update":{"id":"resources:update","description":"update an existing resource","pluginName":"@commercelayer/cli-plugin-resources","pluginType":"core","aliases":["update","ru","res:update","patch"],"examples":["$ commercelayer resources:update customers/<customerId> -a reference=referenceId","$ commercelayer res:update customers <customerId> -a reference_origin=\"Ref Origin\"","$ cl update customers/<customerId> -m meta_key=\"meta value\"","$ cl ru customers <customerId> -M mete_keu=\"metadata overwrite","$ clayer update customers <customerId> -D /path/to/data/file/data.json"],"flags":{"organization":{"name":"organization","type":"option","char":"o","description":"the slug of your organization","required":true},"domain":{"name":"domain","type":"option","char":"d","hidden":true,"required":false},"accessToken":{"name":"accessToken","type":"option","hidden":true,"required":true},"json":{"name":"json","type":"boolean","char":"j","description":"convert output in standard JSON format","allowNo":false},"unformatted":{"name":"unformatted","type":"boolean","char":"u","description":"print unformatted JSON output","allowNo":false},"raw":{"name":"raw","type":"boolean","char":"R","description":"print out the raw API response","hidden":false,"allowNo":false},"attribute":{"name":"attribute","type":"option","char":"a","description":"define a resource attribute"},"object":{"name":"object","type":"option","char":"O","description":"define a resource object attribute"},"relationship":{"name":"relationship","type":"option","char":"r","description":"define a relationship with another resource"},"metadata":{"name":"metadata","type":"option","char":"m","description":"define a metadata attribute and merge it with the metadata already present in the remote resource"},"metadata-replace":{"name":"metadata-replace","type":"option","char":"M","description":"define a metadata attribute and replace every item already presente in the remote resource"},"data":{"name":"data","type":"option","char":"D","description":"the data file to use as request body"}},"args":[{"name":"resource","description":"the resource type","required":true},{"name":"id","description":"id of the resource to retrieve","required":false}]}}}
{
"name": "@commercelayer/cli-plugin-resources",
"description": "Commerce Layer CLI Resources plugin",
"version": "1.2.1",
"version": "2.0.0-alpha.0",
"author": "Pierluigi Viti <pierluigi@commercelayer.io>",

@@ -27,2 +27,3 @@ "bin": {

"inflector-js": "^1.0.1",
"jsonapi-typescript": "^0.1.3",
"mocha": "^5.2.0",

@@ -77,7 +78,8 @@ "nyc": "^14.1.1",

"@commercelayer/js-auth": "^2.0.4",
"@commercelayer/js-sdk": "^4.1.0",
"@commercelayer/sdk": "^2.1.0-alpha.7",
"@oclif/command": "^1.8.0",
"@oclif/config": "^1.17.0",
"axios": "^0.21.1",
"cli-ux": "^5.5.1",
"axios": "^0.21.4",
"chalk": "^2.4.2",
"cli-ux": "^5.6.3",
"json-2-csv": "^3.14.4",

@@ -84,0 +86,0 @@ "jsonwebtoken": "^8.5.1",

@@ -68,3 +68,3 @@ @commercelayer/cli-plugin-resources

_See code: [src/commands/order/index.ts](https://github.com/commercelayer/commercelayer-cli-plugin-resources/blob/v1.2.1/src/commands/order/index.ts)_
_See code: [src/commands/order/index.ts](https://github.com/commercelayer/commercelayer-cli-plugin-resources/blob/v2.0.0-alpha.0/src/commands/order/index.ts)_

@@ -80,3 +80,3 @@ ### `cl-resources order:actions`

_See code: [src/commands/order/actions.ts](https://github.com/commercelayer/commercelayer-cli-plugin-resources/blob/v1.2.1/src/commands/order/actions.ts)_
_See code: [src/commands/order/actions.ts](https://github.com/commercelayer/commercelayer-cli-plugin-resources/blob/v2.0.0-alpha.0/src/commands/order/actions.ts)_

@@ -101,3 +101,3 @@ ### `cl-resources order:approve ID`

_See code: [src/commands/order/approve.ts](https://github.com/commercelayer/commercelayer-cli-plugin-resources/blob/v1.2.1/src/commands/order/approve.ts)_
_See code: [src/commands/order/approve.ts](https://github.com/commercelayer/commercelayer-cli-plugin-resources/blob/v2.0.0-alpha.0/src/commands/order/approve.ts)_

@@ -122,3 +122,3 @@ ### `cl-resources order:capture ID`

_See code: [src/commands/order/capture.ts](https://github.com/commercelayer/commercelayer-cli-plugin-resources/blob/v1.2.1/src/commands/order/capture.ts)_
_See code: [src/commands/order/capture.ts](https://github.com/commercelayer/commercelayer-cli-plugin-resources/blob/v2.0.0-alpha.0/src/commands/order/capture.ts)_

@@ -143,3 +143,3 @@ ### `cl-resources order:place ID`

_See code: [src/commands/order/place.ts](https://github.com/commercelayer/commercelayer-cli-plugin-resources/blob/v1.2.1/src/commands/order/place.ts)_
_See code: [src/commands/order/place.ts](https://github.com/commercelayer/commercelayer-cli-plugin-resources/blob/v2.0.0-alpha.0/src/commands/order/place.ts)_

@@ -164,3 +164,3 @@ ### `cl-resources resources`

_See code: [src/commands/resources/index.ts](https://github.com/commercelayer/commercelayer-cli-plugin-resources/blob/v1.2.1/src/commands/resources/index.ts)_
_See code: [src/commands/resources/index.ts](https://github.com/commercelayer/commercelayer-cli-plugin-resources/blob/v2.0.0-alpha.0/src/commands/resources/index.ts)_

@@ -193,2 +193,3 @@ ### `cl-resources resources:create RESOURCE`

$ cl-resources res:create
$ cl-resources post

@@ -202,3 +203,3 @@ EXAMPLES

_See code: [src/commands/resources/create.ts](https://github.com/commercelayer/commercelayer-cli-plugin-resources/blob/v1.2.1/src/commands/resources/create.ts)_
_See code: [src/commands/resources/create.ts](https://github.com/commercelayer/commercelayer-cli-plugin-resources/blob/v2.0.0-alpha.0/src/commands/resources/create.ts)_

@@ -233,3 +234,3 @@ ### `cl-resources resources:delete RESOURCE [ID]`

_See code: [src/commands/resources/delete.ts](https://github.com/commercelayer/commercelayer-cli-plugin-resources/blob/v1.2.1/src/commands/resources/delete.ts)_
_See code: [src/commands/resources/delete.ts](https://github.com/commercelayer/commercelayer-cli-plugin-resources/blob/v2.0.0-alpha.0/src/commands/resources/delete.ts)_

@@ -256,3 +257,3 @@ ### `cl-resources resources:doc RESOURCE`

_See code: [src/commands/resources/doc.ts](https://github.com/commercelayer/commercelayer-cli-plugin-resources/blob/v1.2.1/src/commands/resources/doc.ts)_
_See code: [src/commands/resources/doc.ts](https://github.com/commercelayer/commercelayer-cli-plugin-resources/blob/v2.0.0-alpha.0/src/commands/resources/doc.ts)_

@@ -275,3 +276,3 @@ ### `cl-resources resources:filters`

_See code: [src/commands/resources/filters.ts](https://github.com/commercelayer/commercelayer-cli-plugin-resources/blob/v1.2.1/src/commands/resources/filters.ts)_
_See code: [src/commands/resources/filters.ts](https://github.com/commercelayer/commercelayer-cli-plugin-resources/blob/v2.0.0-alpha.0/src/commands/resources/filters.ts)_

@@ -315,3 +316,3 @@ ### `cl-resources resources:get RESOURCE [ID]`

_See code: [src/commands/resources/get.ts](https://github.com/commercelayer/commercelayer-cli-plugin-resources/blob/v1.2.1/src/commands/resources/get.ts)_
_See code: [src/commands/resources/get.ts](https://github.com/commercelayer/commercelayer-cli-plugin-resources/blob/v2.0.0-alpha.0/src/commands/resources/get.ts)_

@@ -354,3 +355,3 @@ ### `cl-resources resources:list RESOURCE`

_See code: [src/commands/resources/list.ts](https://github.com/commercelayer/commercelayer-cli-plugin-resources/blob/v1.2.1/src/commands/resources/list.ts)_
_See code: [src/commands/resources/list.ts](https://github.com/commercelayer/commercelayer-cli-plugin-resources/blob/v2.0.0-alpha.0/src/commands/resources/list.ts)_

@@ -391,3 +392,3 @@ ### `cl-resources resources:retrieve RESOURCE [ID]`

_See code: [src/commands/resources/retrieve.ts](https://github.com/commercelayer/commercelayer-cli-plugin-resources/blob/v1.2.1/src/commands/resources/retrieve.ts)_
_See code: [src/commands/resources/retrieve.ts](https://github.com/commercelayer/commercelayer-cli-plugin-resources/blob/v2.0.0-alpha.0/src/commands/resources/retrieve.ts)_

@@ -433,2 +434,3 @@ ### `cl-resources resources:update RESOURCE [ID]`

$ cl-resources res:update
$ cl-resources patch

@@ -443,3 +445,3 @@ EXAMPLES

_See code: [src/commands/resources/update.ts](https://github.com/commercelayer/commercelayer-cli-plugin-resources/blob/v1.2.1/src/commands/resources/update.ts)_
_See code: [src/commands/resources/update.ts](https://github.com/commercelayer/commercelayer-cli-plugin-resources/blob/v2.0.0-alpha.0/src/commands/resources/update.ts)_
<!-- commandsstop -->
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc