ecomcoder-cli 1.3.0 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +5 -0
- package/dist/cli.js.map +1 -1
- package/dist/commands/discount/create-basic.d.ts +6 -0
- package/dist/commands/discount/create-basic.d.ts.map +1 -0
- package/dist/commands/discount/create-basic.js +156 -0
- package/dist/commands/discount/create-basic.js.map +1 -0
- package/dist/commands/discount/create-bxgy.d.ts +17 -0
- package/dist/commands/discount/create-bxgy.d.ts.map +1 -0
- package/dist/commands/discount/create-bxgy.js +230 -0
- package/dist/commands/discount/create-bxgy.js.map +1 -0
- package/dist/commands/discount/create-shipping.d.ts +17 -0
- package/dist/commands/discount/create-shipping.d.ts.map +1 -0
- package/dist/commands/discount/create-shipping.js +170 -0
- package/dist/commands/discount/create-shipping.js.map +1 -0
- package/dist/commands/discount/delete.d.ts +6 -0
- package/dist/commands/discount/delete.d.ts.map +1 -0
- package/dist/commands/discount/delete.js +45 -0
- package/dist/commands/discount/delete.js.map +1 -0
- package/dist/commands/discount/index.d.ts +10 -0
- package/dist/commands/discount/index.d.ts.map +1 -0
- package/dist/commands/discount/index.js +98 -0
- package/dist/commands/discount/index.js.map +1 -0
- package/dist/commands/discount/list.d.ts +6 -0
- package/dist/commands/discount/list.d.ts.map +1 -0
- package/dist/commands/discount/list.js +84 -0
- package/dist/commands/discount/list.js.map +1 -0
- package/dist/commands/discount/queries.d.ts +14 -0
- package/dist/commands/discount/queries.d.ts.map +1 -0
- package/dist/commands/discount/queries.js +574 -0
- package/dist/commands/discount/queries.js.map +1 -0
- package/dist/commands/discount/service.d.ts +31 -0
- package/dist/commands/discount/service.d.ts.map +1 -0
- package/dist/commands/discount/service.js +684 -0
- package/dist/commands/discount/service.js.map +1 -0
- package/dist/commands/discount/types.d.ts +228 -0
- package/dist/commands/discount/types.d.ts.map +1 -0
- package/dist/commands/discount/types.js +5 -0
- package/dist/commands/discount/types.js.map +1 -0
- package/dist/commands/discount/utils.d.ts +51 -0
- package/dist/commands/discount/utils.d.ts.map +1 -0
- package/dist/commands/discount/utils.js +153 -0
- package/dist/commands/discount/utils.js.map +1 -0
- package/dist/commands/product/index.d.ts.map +1 -1
- package/dist/commands/product/index.js +10 -0
- package/dist/commands/product/index.js.map +1 -1
- package/dist/commands/product/service.d.ts +9 -1
- package/dist/commands/product/service.d.ts.map +1 -1
- package/dist/commands/product/service.js +36 -0
- package/dist/commands/product/service.js.map +1 -1
- package/dist/commands/product/types.d.ts +4 -0
- package/dist/commands/product/types.d.ts.map +1 -1
- package/dist/commands/product/update-title.d.ts +8 -0
- package/dist/commands/product/update-title.d.ts.map +1 -0
- package/dist/commands/product/update-title.js +94 -0
- package/dist/commands/product/update-title.js.map +1 -0
- package/package.json +2 -1
package/dist/cli.js
CHANGED
|
@@ -17,11 +17,13 @@ import { registerProductCommands } from './commands/product/index.js';
|
|
|
17
17
|
import { registerMetafieldCommands } from './commands/metafield/index.js';
|
|
18
18
|
import { registerProductsCommands } from './commands/products/index.js';
|
|
19
19
|
import { registerDocsCommands } from './commands/docs/index.js';
|
|
20
|
+
import { registerDiscountCommands } from './commands/discount/index.js';
|
|
20
21
|
// Initialize registry
|
|
21
22
|
registerProductCommands();
|
|
22
23
|
registerMetafieldCommands();
|
|
23
24
|
registerProductsCommands();
|
|
24
25
|
registerDocsCommands();
|
|
26
|
+
registerDiscountCommands();
|
|
25
27
|
function showMainHelp() {
|
|
26
28
|
console.log(`
|
|
27
29
|
EcomCoder CLI - Shopify Development Utilities
|
|
@@ -37,6 +39,9 @@ COMMANDS:
|
|
|
37
39
|
product update-description Update product description
|
|
38
40
|
product update-price Update product price and compare-at price
|
|
39
41
|
product update-template Change product template assignment
|
|
42
|
+
discount create-basic Create basic discount (percentage or fixed amount)
|
|
43
|
+
discount list List all discounts with filtering
|
|
44
|
+
discount delete Delete a discount by ID
|
|
40
45
|
metafield create Create metafield definition
|
|
41
46
|
metafield get Get metafield definition(s)
|
|
42
47
|
docs search Search Shopify theme documentation
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAErD,8BAA8B;AAC9B,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AACtE,OAAO,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AACxE,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAErD,8BAA8B;AAC9B,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AACtE,OAAO,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AACxE,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAExE,sBAAsB;AACtB,uBAAuB,EAAE,CAAC;AAC1B,yBAAyB,EAAE,CAAC;AAC5B,wBAAwB,EAAE,CAAC;AAC3B,oBAAoB,EAAE,CAAC;AACvB,wBAAwB,EAAE,CAAC;AAE3B,SAAS,YAAY;IACnB,OAAO,CAAC,GAAG,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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
/**
|
|
2
|
+
* Command: discount create-basic
|
|
3
|
+
* Create a basic discount (percentage or fixed amount off)
|
|
4
|
+
*/
|
|
5
|
+
import { parseArgs } from '../../lib/args-parser.js';
|
|
6
|
+
import { getCredentials } from '../../lib/api-client.js';
|
|
7
|
+
import { createBasicDiscount } from './service.js';
|
|
8
|
+
const HELP_TEXT = `
|
|
9
|
+
Create a basic discount (percentage or fixed amount off)
|
|
10
|
+
|
|
11
|
+
Usage:
|
|
12
|
+
ecomcoder discount create-basic [options]
|
|
13
|
+
|
|
14
|
+
Options:
|
|
15
|
+
--title <string> Discount title (required)
|
|
16
|
+
--code <string> Discount code (required for code discounts)
|
|
17
|
+
--automatic Create automatic discount (no code required)
|
|
18
|
+
--type <type> Discount type: percentage | fixed_amount (required)
|
|
19
|
+
--value <number> Discount value (0.00-1.00 for percentage, amount for fixed) (required)
|
|
20
|
+
--starts-at <datetime> Start date/time in ISO 8601 format (required)
|
|
21
|
+
--ends-at <datetime> End date/time in ISO 8601 format (optional)
|
|
22
|
+
--target <target> Target: all | collections | products (default: all)
|
|
23
|
+
--target-ids <ids> Comma-separated GIDs (required for collections/products target)
|
|
24
|
+
--min-subtotal <amount> Minimum subtotal required (optional)
|
|
25
|
+
--min-quantity <number> Minimum quantity required (optional)
|
|
26
|
+
--segments <ids> Comma-separated customer segment GIDs (optional)
|
|
27
|
+
--combine-order Allow combination with order discounts (default: true)
|
|
28
|
+
--combine-product Allow combination with product discounts (default: true)
|
|
29
|
+
--combine-shipping Allow combination with shipping discounts (default: true)
|
|
30
|
+
--usage-limit <number> Maximum number of uses (optional, code discounts only)
|
|
31
|
+
--once-per-customer Limit to one use per customer (code discounts only)
|
|
32
|
+
|
|
33
|
+
Examples:
|
|
34
|
+
# Percentage discount with code
|
|
35
|
+
ecomcoder discount create-basic \\
|
|
36
|
+
--title="Summer Sale" \\
|
|
37
|
+
--code="SUMMER25" \\
|
|
38
|
+
--type=percentage \\
|
|
39
|
+
--value=0.25 \\
|
|
40
|
+
--starts-at="2026-06-01T00:00:00Z" \\
|
|
41
|
+
--ends-at="2026-08-31T23:59:59Z"
|
|
42
|
+
|
|
43
|
+
# Fixed amount discount with minimum subtotal
|
|
44
|
+
ecomcoder discount create-basic \\
|
|
45
|
+
--title="$10 Off Orders Over $50" \\
|
|
46
|
+
--code="SAVE10" \\
|
|
47
|
+
--type=fixed_amount \\
|
|
48
|
+
--value=10.00 \\
|
|
49
|
+
--min-subtotal=50.00 \\
|
|
50
|
+
--starts-at="2026-06-01T00:00:00Z"
|
|
51
|
+
|
|
52
|
+
# Automatic discount on specific collections
|
|
53
|
+
ecomcoder discount create-basic \\
|
|
54
|
+
--title="VIP Collection Discount" \\
|
|
55
|
+
--automatic \\
|
|
56
|
+
--type=percentage \\
|
|
57
|
+
--value=0.15 \\
|
|
58
|
+
--target=collections \\
|
|
59
|
+
--target-ids="gid://shopify/Collection/123,gid://shopify/Collection/456" \\
|
|
60
|
+
--starts-at="2026-06-01T00:00:00Z"
|
|
61
|
+
|
|
62
|
+
# Discount with usage limit
|
|
63
|
+
ecomcoder discount create-basic \\
|
|
64
|
+
--title="Limited Offer" \\
|
|
65
|
+
--code="LIMITED100" \\
|
|
66
|
+
--type=percentage \\
|
|
67
|
+
--value=0.20 \\
|
|
68
|
+
--usage-limit=100 \\
|
|
69
|
+
--once-per-customer \\
|
|
70
|
+
--starts-at="2026-06-01T00:00:00Z"
|
|
71
|
+
`;
|
|
72
|
+
export async function run(cliArgs) {
|
|
73
|
+
const args = parseArgs(cliArgs);
|
|
74
|
+
if (args.help === 'true') {
|
|
75
|
+
console.log(HELP_TEXT);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
// Validate required arguments
|
|
79
|
+
if (!args.title) {
|
|
80
|
+
console.log(JSON.stringify({
|
|
81
|
+
success: false,
|
|
82
|
+
error: 'Missing required argument: --title'
|
|
83
|
+
}));
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (!args.type) {
|
|
87
|
+
console.log(JSON.stringify({
|
|
88
|
+
success: false,
|
|
89
|
+
error: 'Missing required argument: --type (percentage | fixed_amount)'
|
|
90
|
+
}));
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (!args.value) {
|
|
94
|
+
console.log(JSON.stringify({
|
|
95
|
+
success: false,
|
|
96
|
+
error: 'Missing required argument: --value'
|
|
97
|
+
}));
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (!args.startsAt) {
|
|
101
|
+
console.log(JSON.stringify({
|
|
102
|
+
success: false,
|
|
103
|
+
error: 'Missing required argument: --starts-at (ISO 8601 format)'
|
|
104
|
+
}));
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const isAutomatic = args.automatic === 'true';
|
|
108
|
+
if (!isAutomatic && !args.code) {
|
|
109
|
+
console.log(JSON.stringify({
|
|
110
|
+
success: false,
|
|
111
|
+
error: 'Missing required argument: --code (required for code discounts, or use --automatic)'
|
|
112
|
+
}));
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
// Parse target IDs if provided
|
|
116
|
+
let targetIds;
|
|
117
|
+
if (args.targetIds) {
|
|
118
|
+
targetIds = args.targetIds.split(',').map((id) => id.trim());
|
|
119
|
+
}
|
|
120
|
+
// Parse customer segments if provided
|
|
121
|
+
let customerSegments;
|
|
122
|
+
if (args.segments) {
|
|
123
|
+
customerSegments = args.segments.split(',').map((id) => id.trim());
|
|
124
|
+
}
|
|
125
|
+
// Build combinesWith object
|
|
126
|
+
const combinesWith = {
|
|
127
|
+
orderDiscounts: args.combineOrder !== 'false',
|
|
128
|
+
productDiscounts: args.combineProduct !== 'false',
|
|
129
|
+
shippingDiscounts: args.combineShipping !== 'false'
|
|
130
|
+
};
|
|
131
|
+
// Build input
|
|
132
|
+
const input = {
|
|
133
|
+
title: args.title,
|
|
134
|
+
code: args.code,
|
|
135
|
+
automatic: isAutomatic,
|
|
136
|
+
type: args.type,
|
|
137
|
+
value: args.value,
|
|
138
|
+
startsAt: args.startsAt,
|
|
139
|
+
endsAt: args.endsAt,
|
|
140
|
+
target: (args.target || 'all'),
|
|
141
|
+
targetIds,
|
|
142
|
+
minSubtotal: args.minSubtotal,
|
|
143
|
+
minQuantity: args.minQuantity,
|
|
144
|
+
customerSegments,
|
|
145
|
+
combinesWith,
|
|
146
|
+
usageLimit: args.usageLimit ? parseInt(args.usageLimit) : undefined,
|
|
147
|
+
appliesOncePerCustomer: args.oncePerCustomer === 'true'
|
|
148
|
+
};
|
|
149
|
+
// Get credentials
|
|
150
|
+
const sessionId = process.env.SESSION_ID || 'default';
|
|
151
|
+
const credentials = await getCredentials(sessionId);
|
|
152
|
+
// Create discount
|
|
153
|
+
const result = await createBasicDiscount(input, credentials);
|
|
154
|
+
console.log(JSON.stringify(result, null, 2));
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=create-basic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-basic.js","sourceRoot":"","sources":["../../../src/commands/discount/create-basic.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAGnD,MAAM,SAAS,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+DjB,CAAC;AAEF,MAAM,CAAC,KAAK,UAAU,GAAG,CAAC,OAAiB;IACzC,MAAM,IAAI,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC;IAEhC,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;QACzB,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QACvB,OAAO;IACT,CAAC;IAED,8BAA8B;IAC9B,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;QAChB,OAA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IAEpD,kBAAkB;IAClB,MAAM,MAAM,GAAG,MAAM,mBAAmB,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;IAE7D,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;AAC/C,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create BXGY (Buy X Get Y) Discount Command
|
|
3
|
+
*
|
|
4
|
+
* Design Pattern: Command Pattern
|
|
5
|
+
* - Thin orchestration layer
|
|
6
|
+
* - Delegates business logic to service layer
|
|
7
|
+
* - Single Responsibility: Parse args, validate, call service, format output
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Parse and execute create-bxgy command
|
|
11
|
+
*
|
|
12
|
+
* Following SOLID principles:
|
|
13
|
+
* - Single Responsibility: Parse args and orchestrate service call
|
|
14
|
+
* - Dependency Inversion: Depends on service abstraction
|
|
15
|
+
*/
|
|
16
|
+
export declare function run(cliArgs: string[]): Promise<void>;
|
|
17
|
+
//# sourceMappingURL=create-bxgy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-bxgy.d.ts","sourceRoot":"","sources":["../../../src/commands/discount/create-bxgy.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AA0HH;;;;;;GAMG;AACH,wBAAsB,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAyI1D"}
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create BXGY (Buy X Get Y) Discount Command
|
|
3
|
+
*
|
|
4
|
+
* Design Pattern: Command Pattern
|
|
5
|
+
* - Thin orchestration layer
|
|
6
|
+
* - Delegates business logic to service layer
|
|
7
|
+
* - Single Responsibility: Parse args, validate, call service, format output
|
|
8
|
+
*/
|
|
9
|
+
import { parseArgs } from '../../lib/args-parser.js';
|
|
10
|
+
import { getCredentials } from '../../lib/api-client.js';
|
|
11
|
+
import { createBxgyDiscount } from './service.js';
|
|
12
|
+
/**
|
|
13
|
+
* Show help for create-bxgy command
|
|
14
|
+
*/
|
|
15
|
+
function showHelp() {
|
|
16
|
+
console.log(`
|
|
17
|
+
Create BXGY (Buy X Get Y) Discount
|
|
18
|
+
|
|
19
|
+
USAGE:
|
|
20
|
+
ecomcoder discount create-bxgy [options]
|
|
21
|
+
|
|
22
|
+
REQUIRED OPTIONS:
|
|
23
|
+
--title <text> Discount title
|
|
24
|
+
--gets-quantity <number> Number of items customer gets discounted
|
|
25
|
+
--gets-percentage <0.0-1.0> Percentage off items (e.g., 0.50 for 50% off, 1.0 for free)
|
|
26
|
+
--starts-at <ISO8601> When discount becomes active
|
|
27
|
+
|
|
28
|
+
CUSTOMER BUYS (choose quantity OR amount):
|
|
29
|
+
--buys-quantity <number> Minimum quantity to purchase
|
|
30
|
+
--buys-amount <amount> Minimum spend amount (e.g., "50.00")
|
|
31
|
+
|
|
32
|
+
CUSTOMER BUYS TARGETING (required, choose one):
|
|
33
|
+
--buys-products <ids> Comma-separated product GIDs
|
|
34
|
+
--buys-collections <ids> Comma-separated collection GIDs
|
|
35
|
+
|
|
36
|
+
CUSTOMER GETS TARGETING (required, choose one):
|
|
37
|
+
--gets-products <ids> Comma-separated product GIDs customer gets discount on
|
|
38
|
+
--gets-collections <ids> Comma-separated collection GIDs customer gets discount on
|
|
39
|
+
|
|
40
|
+
DISCOUNT TYPE:
|
|
41
|
+
--code <CODE> Create code-based discount (default)
|
|
42
|
+
--automatic Create automatic discount (no code required)
|
|
43
|
+
|
|
44
|
+
DATE/TIME OPTIONS:
|
|
45
|
+
--ends-at <ISO8601> When discount expires (optional)
|
|
46
|
+
|
|
47
|
+
USAGE LIMITS:
|
|
48
|
+
--uses-per-order-limit <n> Max times discount applies per order
|
|
49
|
+
|
|
50
|
+
COMBINATION RULES:
|
|
51
|
+
--combines-with-orders Allow combining with order discounts
|
|
52
|
+
--combines-with-products Allow combining with product discounts
|
|
53
|
+
--combines-with-shipping Allow combining with shipping discounts
|
|
54
|
+
|
|
55
|
+
EXAMPLES:
|
|
56
|
+
# Buy 2 get 1 free (same product)
|
|
57
|
+
ecomcoder discount create-bxgy \\
|
|
58
|
+
--title="Buy 2 Get 1 Free" \\
|
|
59
|
+
--code="BUY2GET1" \\
|
|
60
|
+
--buys-quantity=2 \\
|
|
61
|
+
--buys-products="gid://shopify/Product/123" \\
|
|
62
|
+
--gets-quantity=1 \\
|
|
63
|
+
--gets-percentage=1.0 \\
|
|
64
|
+
--gets-products="gid://shopify/Product/123" \\
|
|
65
|
+
--starts-at="2026-06-01T00:00:00Z"
|
|
66
|
+
|
|
67
|
+
# Spend $50, get 50% off accessories
|
|
68
|
+
ecomcoder discount create-bxgy \\
|
|
69
|
+
--title="Spend $50, Get 50% Off Accessories" \\
|
|
70
|
+
--automatic \\
|
|
71
|
+
--buys-amount=50.00 \\
|
|
72
|
+
--buys-products="gid://shopify/Product/456" \\
|
|
73
|
+
--gets-quantity=1 \\
|
|
74
|
+
--gets-percentage=0.50 \\
|
|
75
|
+
--gets-collections="gid://shopify/Collection/123" \\
|
|
76
|
+
--starts-at="2026-06-01T00:00:00Z"
|
|
77
|
+
|
|
78
|
+
# Buy 3 shirts, get 1 pair of pants free
|
|
79
|
+
ecomcoder discount create-bxgy \\
|
|
80
|
+
--title="Buy 3 Shirts Get Free Pants" \\
|
|
81
|
+
--code="SHIRTS3" \\
|
|
82
|
+
--buys-quantity=3 \\
|
|
83
|
+
--buys-collections="gid://shopify/Collection/456" \\
|
|
84
|
+
--gets-quantity=1 \\
|
|
85
|
+
--gets-percentage=1.0 \\
|
|
86
|
+
--gets-collections="gid://shopify/Collection/789" \\
|
|
87
|
+
--starts-at="2026-06-01T00:00:00Z" \\
|
|
88
|
+
--uses-per-order-limit=1
|
|
89
|
+
|
|
90
|
+
NOTES:
|
|
91
|
+
- Use ISO 8601 format for dates: YYYY-MM-DDTHH:mm:ssZ
|
|
92
|
+
- Percentage values: 0.25 = 25% off, 0.50 = 50% off, 1.0 = 100% off (free)
|
|
93
|
+
- Must specify either --buys-quantity OR --buys-amount (not both)
|
|
94
|
+
- BXGY requires specific products/collections (cannot use "all items")
|
|
95
|
+
- Must specify what customer buys (--buys-products OR --buys-collections)
|
|
96
|
+
- Must specify what customer gets (--gets-products OR --gets-collections)
|
|
97
|
+
- BXGY discounts apply to line items (not order total)
|
|
98
|
+
`);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Parse and execute create-bxgy command
|
|
102
|
+
*
|
|
103
|
+
* Following SOLID principles:
|
|
104
|
+
* - Single Responsibility: Parse args and orchestrate service call
|
|
105
|
+
* - Dependency Inversion: Depends on service abstraction
|
|
106
|
+
*/
|
|
107
|
+
export async function run(cliArgs) {
|
|
108
|
+
const args = parseArgs(cliArgs);
|
|
109
|
+
if (args.help) {
|
|
110
|
+
showHelp();
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
// Validate required arguments
|
|
114
|
+
if (!args.title) {
|
|
115
|
+
console.error('Error: --title is required');
|
|
116
|
+
process.exit(1);
|
|
117
|
+
}
|
|
118
|
+
if (!args.getsQuantity) {
|
|
119
|
+
console.error('Error: --gets-quantity is required');
|
|
120
|
+
process.exit(1);
|
|
121
|
+
}
|
|
122
|
+
if (!args.getsPercentage) {
|
|
123
|
+
console.error('Error: --gets-percentage is required');
|
|
124
|
+
process.exit(1);
|
|
125
|
+
}
|
|
126
|
+
if (!args.startsAt) {
|
|
127
|
+
console.error('Error: --starts-at is required');
|
|
128
|
+
process.exit(1);
|
|
129
|
+
}
|
|
130
|
+
// Validate discount type
|
|
131
|
+
if (!args.automatic && !args.code) {
|
|
132
|
+
console.error('Error: --code is required for code-based discounts (or use --automatic)');
|
|
133
|
+
process.exit(1);
|
|
134
|
+
}
|
|
135
|
+
if (args.automatic && args.code) {
|
|
136
|
+
console.error('Error: Automatic discounts cannot have codes');
|
|
137
|
+
process.exit(1);
|
|
138
|
+
}
|
|
139
|
+
// Validate customerBuys requirements
|
|
140
|
+
const hasBuysQuantity = args.buysQuantity !== undefined;
|
|
141
|
+
const hasBuysAmount = args.buysAmount !== undefined;
|
|
142
|
+
if (!hasBuysQuantity && !hasBuysAmount) {
|
|
143
|
+
console.error('Error: Must specify either --buys-quantity OR --buys-amount');
|
|
144
|
+
process.exit(1);
|
|
145
|
+
}
|
|
146
|
+
if (hasBuysQuantity && hasBuysAmount) {
|
|
147
|
+
console.error('Error: Cannot specify both --buys-quantity AND --buys-amount - choose one');
|
|
148
|
+
process.exit(1);
|
|
149
|
+
}
|
|
150
|
+
// Validate customerGets targeting
|
|
151
|
+
if (!args.getsProducts && !args.getsCollections) {
|
|
152
|
+
console.error('Error: Must specify what customer gets (--gets-products OR --gets-collections)');
|
|
153
|
+
process.exit(1);
|
|
154
|
+
}
|
|
155
|
+
// Build customerBuys input
|
|
156
|
+
const customerBuys = {
|
|
157
|
+
items: {},
|
|
158
|
+
value: {}
|
|
159
|
+
};
|
|
160
|
+
if (args.buysAll) {
|
|
161
|
+
customerBuys.items.all = true;
|
|
162
|
+
}
|
|
163
|
+
else if (args.buysProducts) {
|
|
164
|
+
customerBuys.items.products = {
|
|
165
|
+
productsToAdd: args.buysProducts.split(',').map(id => id.trim())
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
else if (args.buysCollections) {
|
|
169
|
+
customerBuys.items.collections = {
|
|
170
|
+
collectionsToAdd: args.buysCollections.split(',').map(id => id.trim())
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
customerBuys.items.all = true; // Default to all products
|
|
175
|
+
}
|
|
176
|
+
if (hasBuysQuantity) {
|
|
177
|
+
customerBuys.value.quantity = args.buysQuantity;
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
customerBuys.value.amount = args.buysAmount;
|
|
181
|
+
}
|
|
182
|
+
// Build customerGets input
|
|
183
|
+
const percentage = parseFloat(args.getsPercentage);
|
|
184
|
+
if (isNaN(percentage) || percentage < 0 || percentage > 1.0) {
|
|
185
|
+
console.error('Error: --gets-percentage must be between 0.0 and 1.0 (e.g., 0.50 for 50% off)');
|
|
186
|
+
process.exit(1);
|
|
187
|
+
}
|
|
188
|
+
const customerGets = {
|
|
189
|
+
items: {},
|
|
190
|
+
value: {
|
|
191
|
+
discountOnQuantity: {
|
|
192
|
+
quantity: args.getsQuantity,
|
|
193
|
+
effect: {
|
|
194
|
+
percentage
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
if (args.getsProducts) {
|
|
200
|
+
const productsToAdd = args.getsProducts.split(',').map(id => id.trim());
|
|
201
|
+
customerGets.items.products = { productsToAdd };
|
|
202
|
+
}
|
|
203
|
+
else if (args.getsCollections) {
|
|
204
|
+
const collectionsToAdd = args.getsCollections.split(',').map(id => id.trim());
|
|
205
|
+
customerGets.items.collections = { collectionsToAdd };
|
|
206
|
+
}
|
|
207
|
+
// Build input
|
|
208
|
+
const input = {
|
|
209
|
+
title: args.title,
|
|
210
|
+
code: args.code,
|
|
211
|
+
automatic: args.automatic,
|
|
212
|
+
customerBuys,
|
|
213
|
+
customerGets,
|
|
214
|
+
startsAt: args.startsAt,
|
|
215
|
+
endsAt: args.endsAt,
|
|
216
|
+
usesPerOrderLimit: args.usesPerOrderLimit ? parseInt(args.usesPerOrderLimit) : undefined,
|
|
217
|
+
combinesWith: {
|
|
218
|
+
orderDiscounts: args.combinesWithOrders || false,
|
|
219
|
+
productDiscounts: args.combinesWithProducts || false,
|
|
220
|
+
shippingDiscounts: args.combinesWithShipping || false
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
// Get credentials
|
|
224
|
+
const sessionId = process.env.SESSION_ID || 'default';
|
|
225
|
+
const credentials = await getCredentials(sessionId);
|
|
226
|
+
// Create discount
|
|
227
|
+
const result = await createBxgyDiscount(input, credentials);
|
|
228
|
+
console.log(JSON.stringify(result, null, 2));
|
|
229
|
+
}
|
|
230
|
+
//# sourceMappingURL=create-bxgy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-bxgy.js","sourceRoot":"","sources":["../../../src/commands/discount/create-bxgy.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AA6BlD;;GAEG;AACH,SAAS,QAAQ;IACf,OAAO,CAAC,GAAG,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkFb,CAAC,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,GAAG,CAAC,OAAiB;IACzC,MAAM,IAAI,GAAG,SAAS,CAAC,OAAO,CAA+B,CAAC;IAC9D,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;QACd,QAAQ,EAAE,CAAC;QACX,OAAO;IACT,CAAC;IAED,8BAA8B;IAC9B,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;QAChB,OAAO,CAAC,KAAK,CAAC,4BAA4B,CAAC,CAAC;QAC5C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;QACvB,OAAO,CAAC,KAAK,CAAC,oCAAoC,CAAC,CAAC;QACpD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC;QACzB,OAAO,CAAC,KAAK,CAAC,sCAAsC,CAAC,CAAC;QACtD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;I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,IAAI,KAAK;YACpD,iBAAiB,EAAE,IAAI,CAAC,oBAAoB,IAAI,KAAK;SACtD;KACF,CAAC;IAEF,kBAAkB;IAClB,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,IAAI,SAAS,CAAC;IACtD,MAAM,WAAW,GAAG,MAAM,cAAc,CAAC,SAAS,CAAC,CAAC;IAEpD,kBAAkB;IAClB,MAAM,MAAM,GAAG,MAAM,kBAAkB,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;IAE5D,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;AAC/C,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create Free Shipping Discount Command
|
|
3
|
+
*
|
|
4
|
+
* Design Pattern: Command Pattern
|
|
5
|
+
* - Thin orchestration layer
|
|
6
|
+
* - Delegates business logic to service layer
|
|
7
|
+
* - Single Responsibility: Parse args, validate, call service, format output
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Parse and execute create-shipping command
|
|
11
|
+
*
|
|
12
|
+
* Following SOLID principles:
|
|
13
|
+
* - Single Responsibility: Parse args and orchestrate service call
|
|
14
|
+
* - Dependency Inversion: Depends on service abstraction
|
|
15
|
+
*/
|
|
16
|
+
export declare function run(cliArgs: string[]): Promise<void>;
|
|
17
|
+
//# sourceMappingURL=create-shipping.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-shipping.d.ts","sourceRoot":"","sources":["../../../src/commands/discount/create-shipping.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAoGH;;;;;;GAMG;AACH,wBAAsB,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAoF1D"}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create Free Shipping Discount Command
|
|
3
|
+
*
|
|
4
|
+
* Design Pattern: Command Pattern
|
|
5
|
+
* - Thin orchestration layer
|
|
6
|
+
* - Delegates business logic to service layer
|
|
7
|
+
* - Single Responsibility: Parse args, validate, call service, format output
|
|
8
|
+
*/
|
|
9
|
+
import { parseArgs } from '../../lib/args-parser.js';
|
|
10
|
+
import { getCredentials } from '../../lib/api-client.js';
|
|
11
|
+
import { createFreeShippingDiscount } from './service.js';
|
|
12
|
+
/**
|
|
13
|
+
* Show help for create-shipping command
|
|
14
|
+
*/
|
|
15
|
+
function showHelp() {
|
|
16
|
+
console.log(`
|
|
17
|
+
Create Free Shipping Discount
|
|
18
|
+
|
|
19
|
+
USAGE:
|
|
20
|
+
ecomcoder discount create-shipping [options]
|
|
21
|
+
|
|
22
|
+
REQUIRED OPTIONS:
|
|
23
|
+
--title <text> Discount title
|
|
24
|
+
--starts-at <ISO8601> When discount becomes active
|
|
25
|
+
|
|
26
|
+
MINIMUM REQUIREMENTS (optional):
|
|
27
|
+
--min-subtotal <amount> Minimum order subtotal (e.g., "50.00")
|
|
28
|
+
--min-quantity <number> Minimum item quantity
|
|
29
|
+
|
|
30
|
+
DESTINATION (optional, defaults to all countries):
|
|
31
|
+
--all-countries Apply to all countries (default)
|
|
32
|
+
--countries <codes> Comma-separated country codes (e.g., "US,CA,GB")
|
|
33
|
+
|
|
34
|
+
DISCOUNT TYPE:
|
|
35
|
+
--code <CODE> Create code-based discount (default)
|
|
36
|
+
--automatic Create automatic discount (no code required)
|
|
37
|
+
|
|
38
|
+
DATE/TIME OPTIONS:
|
|
39
|
+
--ends-at <ISO8601> When discount expires (optional)
|
|
40
|
+
|
|
41
|
+
COMBINATION RULES:
|
|
42
|
+
--combines-with-orders Allow combining with order discounts
|
|
43
|
+
--combines-with-products Allow combining with product discounts
|
|
44
|
+
--combines-with-shipping Allow combining with other shipping discounts
|
|
45
|
+
|
|
46
|
+
EXAMPLES:
|
|
47
|
+
# Free shipping with code
|
|
48
|
+
ecomcoder discount create-shipping \\
|
|
49
|
+
--title="Free Shipping" \\
|
|
50
|
+
--code="FREESHIP" \\
|
|
51
|
+
--starts-at="2026-06-01T00:00:00Z"
|
|
52
|
+
|
|
53
|
+
# Free shipping on orders over $50
|
|
54
|
+
ecomcoder discount create-shipping \\
|
|
55
|
+
--title="Free Shipping Over $50" \\
|
|
56
|
+
--code="SHIP50" \\
|
|
57
|
+
--min-subtotal=50.00 \\
|
|
58
|
+
--starts-at="2026-06-01T00:00:00Z"
|
|
59
|
+
|
|
60
|
+
# Automatic free shipping for US only
|
|
61
|
+
ecomcoder discount create-shipping \\
|
|
62
|
+
--title="US Free Shipping" \\
|
|
63
|
+
--automatic \\
|
|
64
|
+
--countries="US" \\
|
|
65
|
+
--starts-at="2026-06-01T00:00:00Z"
|
|
66
|
+
|
|
67
|
+
# Free shipping for US and Canada
|
|
68
|
+
ecomcoder discount create-shipping \\
|
|
69
|
+
--title="North America Free Shipping" \\
|
|
70
|
+
--code="NAFREE" \\
|
|
71
|
+
--countries="US,CA" \\
|
|
72
|
+
--starts-at="2026-06-01T00:00:00Z"
|
|
73
|
+
|
|
74
|
+
# Free shipping on 5+ items
|
|
75
|
+
ecomcoder discount create-shipping \\
|
|
76
|
+
--title="Bulk Order Free Shipping" \\
|
|
77
|
+
--automatic \\
|
|
78
|
+
--min-quantity=5 \\
|
|
79
|
+
--starts-at="2026-06-01T00:00:00Z"
|
|
80
|
+
|
|
81
|
+
NOTES:
|
|
82
|
+
- Use ISO 8601 format for dates: YYYY-MM-DDTHH:mm:ssZ
|
|
83
|
+
- Country codes must be ISO 3166-1 alpha-2 (e.g., US, CA, GB, AU)
|
|
84
|
+
- Cannot specify both --min-subtotal AND --min-quantity (choose one)
|
|
85
|
+
- Free shipping discounts apply to all shipping methods
|
|
86
|
+
`);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Parse and execute create-shipping command
|
|
90
|
+
*
|
|
91
|
+
* Following SOLID principles:
|
|
92
|
+
* - Single Responsibility: Parse args and orchestrate service call
|
|
93
|
+
* - Dependency Inversion: Depends on service abstraction
|
|
94
|
+
*/
|
|
95
|
+
export async function run(cliArgs) {
|
|
96
|
+
const args = parseArgs(cliArgs);
|
|
97
|
+
if (args.help) {
|
|
98
|
+
showHelp();
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
// Validate required arguments
|
|
102
|
+
if (!args.title) {
|
|
103
|
+
console.error('Error: --title is required');
|
|
104
|
+
process.exit(1);
|
|
105
|
+
}
|
|
106
|
+
if (!args.startsAt) {
|
|
107
|
+
console.error('Error: --starts-at is required');
|
|
108
|
+
process.exit(1);
|
|
109
|
+
}
|
|
110
|
+
// Validate discount type
|
|
111
|
+
if (!args.automatic && !args.code) {
|
|
112
|
+
console.error('Error: --code is required for code-based discounts (or use --automatic)');
|
|
113
|
+
process.exit(1);
|
|
114
|
+
}
|
|
115
|
+
if (args.automatic && args.code) {
|
|
116
|
+
console.error('Error: Automatic discounts cannot have codes');
|
|
117
|
+
process.exit(1);
|
|
118
|
+
}
|
|
119
|
+
// Validate minimum requirements (cannot have both)
|
|
120
|
+
if (args.minSubtotal && args.minQuantity) {
|
|
121
|
+
console.error('Error: Cannot specify both --min-subtotal AND --min-quantity - choose one');
|
|
122
|
+
process.exit(1);
|
|
123
|
+
}
|
|
124
|
+
// Build minimum requirement
|
|
125
|
+
let minimumRequirement = undefined;
|
|
126
|
+
if (args.minSubtotal) {
|
|
127
|
+
minimumRequirement = {
|
|
128
|
+
subtotal: args.minSubtotal
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
else if (args.minQuantity) {
|
|
132
|
+
minimumRequirement = {
|
|
133
|
+
quantity: args.minQuantity
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
// Build destination selection
|
|
137
|
+
let destinationSelection = { all: true };
|
|
138
|
+
if (args.countries) {
|
|
139
|
+
const countryCodes = args.countries.split(',').map(c => c.trim().toUpperCase());
|
|
140
|
+
destinationSelection = {
|
|
141
|
+
countries: countryCodes,
|
|
142
|
+
all: false
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
else if (args.allCountries) {
|
|
146
|
+
destinationSelection = { all: true };
|
|
147
|
+
}
|
|
148
|
+
// Build input
|
|
149
|
+
const input = {
|
|
150
|
+
title: args.title,
|
|
151
|
+
code: args.code,
|
|
152
|
+
automatic: args.automatic,
|
|
153
|
+
startsAt: args.startsAt,
|
|
154
|
+
endsAt: args.endsAt,
|
|
155
|
+
minimumRequirement,
|
|
156
|
+
destinationSelection,
|
|
157
|
+
combinesWith: {
|
|
158
|
+
orderDiscounts: args.combinesWithOrders || false,
|
|
159
|
+
productDiscounts: args.combinesWithProducts || false,
|
|
160
|
+
shippingDiscounts: args.combinesWithShipping || false
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
// Get credentials
|
|
164
|
+
const sessionId = process.env.SESSION_ID || 'default';
|
|
165
|
+
const credentials = await getCredentials(sessionId);
|
|
166
|
+
// Create discount
|
|
167
|
+
const result = await createFreeShippingDiscount(input, credentials);
|
|
168
|
+
console.log(JSON.stringify(result, null, 2));
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=create-shipping.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-shipping.js","sourceRoot":"","sources":["../../../src/commands/discount/create-shipping.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAmB1D;;GAEG;AACH,SAAS,QAAQ;IACf,OAAO,CAAC,GAAG,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsEb,CAAC,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,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