wetaca-cli 0.2.3 → 0.2.4
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/bin/wetaca.js +11 -2
- package/package.json +1 -1
- package/src/commands.js +49 -0
- package/src/guide.js +4 -0
- package/src/queries.js +19 -0
package/bin/wetaca.js
CHANGED
|
@@ -31,7 +31,8 @@ COMMANDS
|
|
|
31
31
|
optional --notes --firstname --lastname --phone (inherit the current ones by default)
|
|
32
32
|
--dry-run shows the exact plan before executing
|
|
33
33
|
remove <id>: deletes an unused address
|
|
34
|
-
vouchers list
|
|
34
|
+
vouchers list | current | apply <CODE> | skip vouchers and applying them to next week
|
|
35
|
+
giftcards show | redeem <CODE> gift cards: limits and redeem into your wallet
|
|
35
36
|
wallet show
|
|
36
37
|
config path | list | get <k> | set <k> <v>
|
|
37
38
|
doctor diagnostics (node, network, session)
|
|
@@ -194,7 +195,15 @@ async function main() {
|
|
|
194
195
|
else throw usageUnknown(noun, verb);
|
|
195
196
|
break;
|
|
196
197
|
case 'vouchers':
|
|
197
|
-
if (verb === 'list') result = await C.vouchersList(args, flags, ctx);
|
|
198
|
+
if (verb === 'list' || verb === undefined) result = await C.vouchersList(args, flags, ctx);
|
|
199
|
+
else if (verb === 'apply') result = await C.vouchersApply(args, flags, ctx);
|
|
200
|
+
else if (verb === 'skip') result = await C.vouchersApply(['skip'], flags, ctx);
|
|
201
|
+
else if (verb === 'current') result = await C.vouchersCurrent(args, flags, ctx);
|
|
202
|
+
else throw usageUnknown(noun, verb);
|
|
203
|
+
break;
|
|
204
|
+
case 'giftcards':
|
|
205
|
+
if (verb === 'show' || verb === undefined) result = await C.giftShow(args, flags, ctx);
|
|
206
|
+
else if (verb === 'redeem') result = await C.giftRedeem(args, flags, ctx);
|
|
198
207
|
else throw usageUnknown(noun, verb);
|
|
199
208
|
break;
|
|
200
209
|
case 'wallet':
|
package/package.json
CHANGED
package/src/commands.js
CHANGED
|
@@ -637,6 +637,55 @@ export async function walletShow(args, flags, ctx) {
|
|
|
637
637
|
return { balance: d.walletBalance, balanceEur: cents(d.walletBalance) };
|
|
638
638
|
}
|
|
639
639
|
|
|
640
|
+
// ---------- vouchers apply / gift cards ----------
|
|
641
|
+
|
|
642
|
+
// `vouchers apply CODE` / `vouchers skip` — applies (or explicitly skips) a voucher
|
|
643
|
+
// on next week's suggestion.
|
|
644
|
+
export async function vouchersApply(args, flags, ctx) {
|
|
645
|
+
const skip = args[0] === 'skip' || flags.skip === true;
|
|
646
|
+
const code = skip ? undefined : args[0];
|
|
647
|
+
if (!skip && !code) throw usageError("Usage: vouchers apply <CODE> | vouchers skip (explicitly don't use a voucher).");
|
|
648
|
+
const sid = flags.suggestion || await nextSuggestionId(ctx.profile, ctx.debug);
|
|
649
|
+
const payload = { voucherCode: skip ? undefined : code, skipVoucher: skip, suggestionId: sid };
|
|
650
|
+
if (ctx.dryRun) return { dryRun: true, wouldSend: { mutation: 'assignNextSuggestionVoucher', variables: payload } };
|
|
651
|
+
await confirm(flags, skip ? `Skip voucher on next week's delivery (suggestion ${sid}).` : `Apply voucher ${code} to next week's delivery (suggestion ${sid}).`);
|
|
652
|
+
const d = await gql(Q.ASSIGN_NEXT_SUGGESTION_VOUCHER, payload, { profile: ctx.profile, debug: ctx.debug });
|
|
653
|
+
const r = d.assignNextSuggestionVoucher || {};
|
|
654
|
+
return {
|
|
655
|
+
ok: true,
|
|
656
|
+
applied: r.appliedVoucher ? { code: r.appliedVoucher.code, discount: r.appliedVoucher.appliedDiscount } : null,
|
|
657
|
+
skipped: r.skipVoucher === true,
|
|
658
|
+
suggestionId: sid,
|
|
659
|
+
};
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
// `vouchers current` — what voucher (if any) is applied to next week's suggestion.
|
|
663
|
+
export async function vouchersCurrent(args, flags, ctx) {
|
|
664
|
+
const d = await gql(Q.NEXT_SUGGESTION_APPLIED_VOUCHER, {}, { profile: ctx.profile, debug: ctx.debug });
|
|
665
|
+
const v = d.nextSuggestion?.appliedVoucher;
|
|
666
|
+
if (!v) return { applied: false, suggestionId: d.nextSuggestion?.id ?? null };
|
|
667
|
+
return { applied: true, suggestionId: d.nextSuggestion.id, code: v.code, discount: v.appliedDiscount };
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
// `giftcards show` — allowed min/max amounts.
|
|
671
|
+
export async function giftShow(args, flags, ctx) {
|
|
672
|
+
const d = await gql(Q.GIFT_CARDS_CONFIG, {}, { profile: ctx.profile, debug: ctx.debug });
|
|
673
|
+
const c = d.giftCardsConfiguration || {};
|
|
674
|
+
return { minAmount: c.minAmount, maxAmount: c.maxAmount };
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
// `giftcards redeem CODE` — adds the gift card balance to your wallet.
|
|
678
|
+
export async function giftRedeem(args, flags, ctx) {
|
|
679
|
+
const code = args[0];
|
|
680
|
+
if (!code) throw usageError('Usage: giftcards redeem <CODE>.');
|
|
681
|
+
const payload = { code: String(code).trim() };
|
|
682
|
+
if (ctx.dryRun) return { dryRun: true, wouldSend: { mutation: 'redeemGiftCard', variables: payload } };
|
|
683
|
+
await confirm(flags, `Redeem gift card ${payload.code} into your wallet.`);
|
|
684
|
+
const d = await gql(Q.REDEEM_GIFT_CARD, payload, { profile: ctx.profile, debug: ctx.debug });
|
|
685
|
+
const r = d.redeemGiftCard || {};
|
|
686
|
+
return { ok: true, code: r.code, amount: r.amount, amountEur: cents(r.amount) };
|
|
687
|
+
}
|
|
688
|
+
|
|
640
689
|
// ---------- config ----------
|
|
641
690
|
|
|
642
691
|
export async function configCmd(verb, args, flags, ctx) {
|
package/src/guide.js
CHANGED
|
@@ -57,6 +57,10 @@ Every command returns JSON on stdout by default; errors go to stderr.
|
|
|
57
57
|
(review the plan; repeat with --yes; optional --notes --firstname --lastname --phone)
|
|
58
58
|
wetaca addresses remove <id> deletes an address not in use
|
|
59
59
|
wetaca vouchers list
|
|
60
|
+
wetaca vouchers current voucher applied to next week (if any)
|
|
61
|
+
wetaca vouchers apply <CODE> apply a voucher to next week (--dry-run first, then --yes)
|
|
62
|
+
wetaca vouchers skip explicitly use no voucher next week
|
|
63
|
+
wetaca giftcards show | redeem <CODE> gift card limits / redeem into wallet
|
|
60
64
|
wetaca wallet
|
|
61
65
|
wetaca config path | list | get <k> | set <k> <v>
|
|
62
66
|
wetaca doctor
|
package/src/queries.js
CHANGED
|
@@ -230,6 +230,25 @@ export const VOUCHERS = `query customerVouchersCli {
|
|
|
230
230
|
}
|
|
231
231
|
}`;
|
|
232
232
|
|
|
233
|
+
export const NEXT_SUGGESTION_APPLIED_VOUCHER = `query nextSuggestionAppliedVoucher {
|
|
234
|
+
nextSuggestion { id appliedVoucher { code appliedDiscount } }
|
|
235
|
+
}`;
|
|
236
|
+
|
|
237
|
+
export const ASSIGN_NEXT_SUGGESTION_VOUCHER = `mutation assignNextSuggestionVoucher($voucherCode: String, $skipVoucher: Boolean!, $suggestionId: ModelId!) {
|
|
238
|
+
assignNextSuggestionVoucher(voucherCode: $voucherCode, skipVoucher: $skipVoucher, suggestionId: $suggestionId) {
|
|
239
|
+
appliedVoucher { code appliedDiscount }
|
|
240
|
+
skipVoucher
|
|
241
|
+
}
|
|
242
|
+
}`;
|
|
243
|
+
|
|
244
|
+
export const GIFT_CARDS_CONFIG = `query giftCardsConfiguration {
|
|
245
|
+
giftCardsConfiguration { minAmount maxAmount }
|
|
246
|
+
}`;
|
|
247
|
+
|
|
248
|
+
export const REDEEM_GIFT_CARD = `mutation redeemGiftCard($code: String!) {
|
|
249
|
+
redeemGiftCard(code: $code) { code amount }
|
|
250
|
+
}`;
|
|
251
|
+
|
|
233
252
|
export const WALLET = `query walletBalance { walletBalance }`;
|
|
234
253
|
|
|
235
254
|
export const LOGOUT = `query registerLogout { registerLogout }`;
|