wetaca-cli 0.0.0-stage → 0.2.0
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/LICENSE +21 -0
- package/README.md +93 -2
- package/bin/wetaca.js +248 -0
- package/docs/GUIA.md +118 -0
- package/docs/agent-guide.md +71 -0
- package/docs/api-operations/wetaca_bundle__Doc0.graphql +40 -0
- package/docs/api-operations/wetaca_bundle__Doc1.graphql +14 -0
- package/docs/api-operations/wetaca_bundle__Doc10.graphql +45 -0
- package/docs/api-operations/wetaca_bundle__Doc11.graphql +9 -0
- package/docs/api-operations/wetaca_bundle__Doc2.graphql +7 -0
- package/docs/api-operations/wetaca_bundle__Doc3.graphql +39 -0
- package/docs/api-operations/wetaca_bundle__Doc4.graphql +36 -0
- package/docs/api-operations/wetaca_bundle__Doc5.graphql +40 -0
- package/docs/api-operations/wetaca_bundle__Doc6.graphql +33 -0
- package/docs/api-operations/wetaca_bundle__Doc7.graphql +48 -0
- package/docs/api-operations/wetaca_bundle__Doc8.graphql +92 -0
- package/docs/api-operations/wetaca_bundle__Doc9.graphql +95 -0
- package/docs/api-operations/wetaca_bundle__SaveWeeklySurveyStep.graphql +3 -0
- package/docs/api-operations/wetaca_bundle__StartWeeklySurvey.graphql +33 -0
- package/docs/api-operations/wetaca_bundle__SubmitWeeklySurvey.graphql +16 -0
- package/docs/api-operations/wetaca_bundle__SubscriptionDeliveryChangePriceQueryV2.graphql +5 -0
- package/docs/api-operations/wetaca_bundle__SuggestionDeliveryChangePriceQueryV2.graphql +5 -0
- package/docs/api-operations/wetaca_bundle__activateSubscriptionAccount.graphql +45 -0
- package/docs/api-operations/wetaca_bundle__activeReferredReward.graphql +3 -0
- package/docs/api-operations/wetaca_bundle__addProductsToProfileWhitelist.graphql +9 -0
- package/docs/api-operations/wetaca_bundle__addProductsToSubscriptionProfileBlacklist.graphql +9 -0
- package/docs/api-operations/wetaca_bundle__addProfileToSubscriptionAccount.graphql +56 -0
- package/docs/api-operations/wetaca_bundle__addRecurrenceVoucherToCustomer.graphql +23 -0
- package/docs/api-operations/wetaca_bundle__addSubscriptionProfileSuggestionOverwrites.graphql +9 -0
- package/docs/api-operations/wetaca_bundle__addresses.graphql +17 -0
- package/docs/api-operations/wetaca_bundle__addressesInManager.graphql +17 -0
- package/docs/api-operations/wetaca_bundle__allRecommenderIngredients.graphql +6 -0
- package/docs/api-operations/wetaca_bundle__appendNewPaymentSubscriptionMethod.graphql +8 -0
- package/docs/api-operations/wetaca_bundle__applyOrderVoucher.graphql +33 -0
- package/docs/api-operations/wetaca_bundle__articleQuery.graphql +22 -0
- package/docs/api-operations/wetaca_bundle__articlesByCategoryQuery.graphql +13 -0
- package/docs/api-operations/wetaca_bundle__assignNextSuggestionVoucher.graphql +9 -0
- package/docs/api-operations/wetaca_bundle__authorizePaypalTokenGenerationPaymentIntention.graphql +7 -0
- package/docs/api-operations/wetaca_bundle__authorizeRedsysAppApplePayPayment.graphql +16 -0
- package/docs/api-operations/wetaca_bundle__authorizeRedsysAppGooglePayPayment.graphql +16 -0
- package/docs/api-operations/wetaca_bundle__authorizeRedsysApplePayPayment.graphql +16 -0
- package/docs/api-operations/wetaca_bundle__authorizeRedsysGooglePayPayment.graphql +16 -0
- package/docs/api-operations/wetaca_bundle__authorizeRedsysPaymentIntention.graphql +17 -0
- package/docs/api-operations/wetaca_bundle__bypassSMSValidationConfigQuery.graphql +5 -0
- package/docs/api-operations/wetaca_bundle__calculateNextProfileSuggestions.graphql +31 -0
- package/docs/api-operations/wetaca_bundle__cancelConfirmedOrder.graphql +6 -0
- package/docs/api-operations/wetaca_bundle__cancelSubscriptionAccount.graphql +45 -0
- package/docs/api-operations/wetaca_bundle__categoriesQuery.graphql +15 -0
- package/docs/api-operations/wetaca_bundle__changeOptionsQuery.graphql +21 -0
- package/docs/api-operations/wetaca_bundle__changeOrderDelivery.graphql +27 -0
- package/docs/api-operations/wetaca_bundle__changePasswordInProfile.graphql +3 -0
- package/docs/api-operations/wetaca_bundle__changeSubscriptionOptInMode.graphql +5 -0
- package/docs/api-operations/wetaca_bundle__changeSubscriptionPaymentPaymentMethodsEdit.graphql +8 -0
- package/docs/api-operations/wetaca_bundle__computeConfirmedOrderModificationPriceSummary.graphql +7 -0
- package/docs/api-operations/wetaca_bundle__confirmDeliveryReschedule.graphql +6 -0
- package/docs/api-operations/wetaca_bundle__confirmedOrderEditContext.graphql +95 -0
- package/docs/api-operations/wetaca_bundle__currentRecurrenceVouchers.graphql +23 -0
- package/docs/api-operations/wetaca_bundle__customer.graphql +11 -0
- package/docs/api-operations/wetaca_bundle__customerBillingAddresses.graphql +18 -0
- package/docs/api-operations/wetaca_bundle__customerFF.graphql +7 -0
- package/docs/api-operations/wetaca_bundle__customerFeatureFlagBySlug.graphql +7 -0
- package/docs/api-operations/wetaca_bundle__customerFeatureFlagForAnalytics.graphql +8 -0
- package/docs/api-operations/wetaca_bundle__customerHasReferralVouchers.graphql +11 -0
- package/docs/api-operations/wetaca_bundle__customerPaymentMethods.graphql +23 -0
- package/docs/api-operations/wetaca_bundle__customerVouchers.graphql +224 -0
- package/docs/api-operations/wetaca_bundle__customerWalletScheduledDeposits.graphql +15 -0
- package/docs/api-operations/wetaca_bundle__customerWithSegment.graphql +61 -0
- package/docs/api-operations/wetaca_bundle__deleteCustomerAccount.graphql +3 -0
- package/docs/api-operations/wetaca_bundle__deleteCustomerScheduledDeposit.graphql +3 -0
- package/docs/api-operations/wetaca_bundle__deliveryOptionsByZipcode.graphql +27 -0
- package/docs/api-operations/wetaca_bundle__deliveryRescheduleWithAvailability.graphql +53 -0
- package/docs/api-operations/wetaca_bundle__dish.graphql +39 -0
- package/docs/api-operations/wetaca_bundle__editAccountBillingAddress.graphql +5 -0
- package/docs/api-operations/wetaca_bundle__editDeliveryAccountInfo.graphql +5 -0
- package/docs/api-operations/wetaca_bundle__editProfileSuggestionMenu.graphql +9 -0
- package/docs/api-operations/wetaca_bundle__editSubscriptionDelivery.graphql +5 -0
- package/docs/api-operations/wetaca_bundle__editSubscriptionProfileAllergens.graphql +56 -0
- package/docs/api-operations/wetaca_bundle__editSubscriptionProfileDislikes.graphql +56 -0
- package/docs/api-operations/wetaca_bundle__editSubscriptionProfileMenu.graphql +56 -0
- package/docs/api-operations/wetaca_bundle__editSubscriptionProfileMenuAndNutrition.graphql +56 -0
- package/docs/api-operations/wetaca_bundle__editSubscriptionProfileSpicy.graphql +56 -0
- package/docs/api-operations/wetaca_bundle__editSubscriptionTastesProfile.graphql +38 -0
- package/docs/api-operations/wetaca_bundle__editSuggestionDelivery.graphql +5 -0
- package/docs/api-operations/wetaca_bundle__featuredArticlesQuery.graphql +16 -0
- package/docs/api-operations/wetaca_bundle__getChargingSuggestionMetadata.graphql +6 -0
- package/docs/api-operations/wetaca_bundle__getDeliveryConfigurationMaxQuantities.graphql +5 -0
- package/docs/api-operations/wetaca_bundle__getDeliveryConfigurationProductAvailability.graphql +13 -0
- package/docs/api-operations/wetaca_bundle__getDeliveryConfigurationProductAvailabilityWithExceptions.graphql +28 -0
- package/docs/api-operations/wetaca_bundle__getSubscriptionAccountDeliveryConfigurationProductAvailability.graphql +38 -0
- package/docs/api-operations/wetaca_bundle__getUseGoogleSocialLoginInIosAppConfiguration.graphql +3 -0
- package/docs/api-operations/wetaca_bundle__getWeeklySurveyConfig.graphql +7 -0
- package/docs/api-operations/wetaca_bundle__giftCardsConfiguration.graphql +6 -0
- package/docs/api-operations/wetaca_bundle__globalConfigurations.graphql +10 -0
- package/docs/api-operations/wetaca_bundle__initNewRedsysPaymentIntention.graphql +10 -0
- package/docs/api-operations/wetaca_bundle__initPaypalTokenGenerationPaymentIntention.graphql +7 -0
- package/docs/api-operations/wetaca_bundle__initializePaymentProcessEvent.graphql +3 -0
- package/docs/api-operations/wetaca_bundle__isNextSuggestionSkiped.graphql +6 -0
- package/docs/api-operations/wetaca_bundle__landingTemplateCollectionQuery.graphql +157 -0
- package/docs/api-operations/wetaca_bundle__landingTemplateFloatingBarQuery.graphql +8 -0
- package/docs/api-operations/wetaca_bundle__lastUsedOrderOptions.graphql +34 -0
- package/docs/api-operations/wetaca_bundle__linkGoogleAccountByPassword.graphql +3 -0
- package/docs/api-operations/wetaca_bundle__linkGoogleAccountBySMS.graphql +3 -0
- package/docs/api-operations/wetaca_bundle__linkGoogleAccountPhone.graphql +3 -0
- package/docs/api-operations/wetaca_bundle__linkPhoneNumberToAccount.graphql +3 -0
- package/docs/api-operations/wetaca_bundle__markSuggestionAsViewedInEditableState.graphql +3 -0
- package/docs/api-operations/wetaca_bundle__menuProductIds.graphql +8 -0
- package/docs/api-operations/wetaca_bundle__modifyConfirmedOrderProducts.graphql +7 -0
- package/docs/api-operations/wetaca_bundle__mostRecentZipCode.graphql +9 -0
- package/docs/api-operations/wetaca_bundle__myDetailsAccountWithProfiles.graphql +506 -0
- package/docs/api-operations/wetaca_bundle__newBlogLeadMutation.graphql +3 -0
- package/docs/api-operations/wetaca_bundle__nextDeliveries.graphql +190 -0
- package/docs/api-operations/wetaca_bundle__nextSubscriptionStartOfChargeTimeQuery.graphql +5 -0
- package/docs/api-operations/wetaca_bundle__nextSuggestion.graphql +231 -0
- package/docs/api-operations/wetaca_bundle__nextSuggestionAddVoucherPage.graphql +5 -0
- package/docs/api-operations/wetaca_bundle__nextSuggestionIdAndVoucher.graphql +8 -0
- package/docs/api-operations/wetaca_bundle__nextSuggestionVoucherAndPrice.graphql +10 -0
- package/docs/api-operations/wetaca_bundle__orderDetails.graphql +124 -0
- package/docs/api-operations/wetaca_bundle__pauseProfile.graphql +56 -0
- package/docs/api-operations/wetaca_bundle__pauseResumeProfile.graphql +56 -0
- package/docs/api-operations/wetaca_bundle__pauseSubscriptionQuery.graphql +17 -0
- package/docs/api-operations/wetaca_bundle__pauseSuggestion.graphql +6 -0
- package/docs/api-operations/wetaca_bundle__pauseSuggestionProfile.graphql +6 -0
- package/docs/api-operations/wetaca_bundle__paySubscriptionPendingOrderWithPaymentMethod.graphql +6 -0
- package/docs/api-operations/wetaca_bundle__payTransactionalOrder.graphql +39 -0
- package/docs/api-operations/wetaca_bundle__pendingDeliveryOrders.graphql +473 -0
- package/docs/api-operations/wetaca_bundle__pendingPaymentOrderById.graphql +63 -0
- package/docs/api-operations/wetaca_bundle__pendingTransactionalDeliveryOrders.graphql +80 -0
- package/docs/api-operations/wetaca_bundle__previousDeliveries.graphql +33 -0
- package/docs/api-operations/wetaca_bundle__profileHasEditTastes.graphql +3 -0
- package/docs/api-operations/wetaca_bundle__profileSuggestionBySuggestionId.graphql +190 -0
- package/docs/api-operations/wetaca_bundle__profileSuggestionWithProfileById.graphql +142 -0
- package/docs/api-operations/wetaca_bundle__purchaseGiftCard.graphql +10 -0
- package/docs/api-operations/wetaca_bundle__rechargeCustomerWalletWithPaymentMethod.graphql +6 -0
- package/docs/api-operations/wetaca_bundle__recommendedArticlesQuery.graphql +20 -0
- package/docs/api-operations/wetaca_bundle__recommenderIngredientsByNames.graphql +6 -0
- package/docs/api-operations/wetaca_bundle__recoverPassword.graphql +3 -0
- package/docs/api-operations/wetaca_bundle__recurrenceNextAssociatedVoucher.graphql +23 -0
- package/docs/api-operations/wetaca_bundle__redeemGiftCard.graphql +6 -0
- package/docs/api-operations/wetaca_bundle__referralConfig.graphql +61 -0
- package/docs/api-operations/wetaca_bundle__registerLogout.graphql +3 -0
- package/docs/api-operations/wetaca_bundle__registerPaymentProcessEvent.graphql +3 -0
- package/docs/api-operations/wetaca_bundle__removeAddress.graphql +5 -0
- package/docs/api-operations/wetaca_bundle__removeAddressInManager.graphql +5 -0
- package/docs/api-operations/wetaca_bundle__removeCreditCard.graphql +3 -0
- package/docs/api-operations/wetaca_bundle__removeCustomerBillingAddress.graphql +3 -0
- package/docs/api-operations/wetaca_bundle__removeProfileWithSuggestions.graphql +3 -0
- package/docs/api-operations/wetaca_bundle__requestDeliveryRescheduleSupport.graphql +6 -0
- package/docs/api-operations/wetaca_bundle__resetPassword.graphql +3 -0
- package/docs/api-operations/wetaca_bundle__resumeSuggestion.graphql +6 -0
- package/docs/api-operations/wetaca_bundle__resumeSuggestionProfile.graphql +6 -0
- package/docs/api-operations/wetaca_bundle__salesPlanCategory.graphql +5 -0
- package/docs/api-operations/wetaca_bundle__saveAddress.graphql +13 -0
- package/docs/api-operations/wetaca_bundle__saveCustomerBillingAddress.graphql +5 -0
- package/docs/api-operations/wetaca_bundle__saveSubscriptionShoppingCart.graphql +5 -0
- package/docs/api-operations/wetaca_bundle__scheduleNewCustomerWalletRecharges.graphql +3 -0
- package/docs/api-operations/wetaca_bundle__segmentBySlug.graphql +75 -0
- package/docs/api-operations/wetaca_bundle__segmentMenu.graphql +89 -0
- package/docs/api-operations/wetaca_bundle__sessionTokenByPassword.graphql +7 -0
- package/docs/api-operations/wetaca_bundle__sessionTokenBySms.graphql +3 -0
- package/docs/api-operations/wetaca_bundle__setPasswordInProfile.graphql +3 -0
- package/docs/api-operations/wetaca_bundle__shoppingCart.graphql +18 -0
- package/docs/api-operations/wetaca_bundle__signUp.graphql +3 -0
- package/docs/api-operations/wetaca_bundle__signUpWithGoogle.graphql +15 -0
- package/docs/api-operations/wetaca_bundle__someProfileHasEditTastes.graphql +3 -0
- package/docs/api-operations/wetaca_bundle__subscribeCustomer.graphql +11 -0
- package/docs/api-operations/wetaca_bundle__subscribeToReactivationUrlVoucher.graphql +5 -0
- package/docs/api-operations/wetaca_bundle__subscribeToVoucherAddVoucherPage.graphql +6 -0
- package/docs/api-operations/wetaca_bundle__subscriberAccountStatus.graphql +8 -0
- package/docs/api-operations/wetaca_bundle__subscriptionAccountByCustomerWithPayments.graphql +10 -0
- package/docs/api-operations/wetaca_bundle__subscriptionAccountChangePricing.graphql +92 -0
- package/docs/api-operations/wetaca_bundle__subscriptionAccountIntentPricing.graphql +156 -0
- package/docs/api-operations/wetaca_bundle__subscriptionAccountIntentPricingForMenu.graphql +134 -0
- package/docs/api-operations/wetaca_bundle__subscriptionAccountIntentPricingFunnelCart.graphql +26 -0
- package/docs/api-operations/wetaca_bundle__subscriptionAccountIntentPricingVoucher.graphql +9 -0
- package/docs/api-operations/wetaca_bundle__subscriptionAccountProductsSubscriptionPricing.graphql +26 -0
- package/docs/api-operations/wetaca_bundle__subscriptionAvailability.graphql +3 -0
- package/docs/api-operations/wetaca_bundle__subscriptionIntentMenuProductsPricing.graphql +26 -0
- package/docs/api-operations/wetaca_bundle__subscriptionMenuWithWelcomeVoucherQuery.graphql +66 -0
- package/docs/api-operations/wetaca_bundle__subscriptionSegmentMenu.graphql +48 -0
- package/docs/api-operations/wetaca_bundle__subscriptionVoucher.graphql +27 -0
- package/docs/api-operations/wetaca_bundle__subscriptionWelcomeVoucher.graphql +10 -0
- package/docs/api-operations/wetaca_bundle__suggestioMenuProductsPricing.graphql +26 -0
- package/docs/api-operations/wetaca_bundle__suggestionById.graphql +52 -0
- package/docs/api-operations/wetaca_bundle__suggestionByIdData.graphql +6 -0
- package/docs/api-operations/wetaca_bundle__suggestionChangePricing.graphql +122 -0
- package/docs/api-operations/wetaca_bundle__syncFeatureFlags.graphql +7 -0
- package/docs/api-operations/wetaca_bundle__tokenIsValid.graphql +3 -0
- package/docs/api-operations/wetaca_bundle__totalOrdersSummaryByCustomer.graphql +21 -0
- package/docs/api-operations/wetaca_bundle__trackInternalEvent.graphql +3 -0
- package/docs/api-operations/wetaca_bundle__trackInternalGEvent.graphql +3 -0
- package/docs/api-operations/wetaca_bundle__trackInternalLPEvent.graphql +3 -0
- package/docs/api-operations/wetaca_bundle__trackLoginInternalEvent.graphql +5 -0
- package/docs/api-operations/wetaca_bundle__transactionalSegmentMenu.graphql +47 -0
- package/docs/api-operations/wetaca_bundle__updateSubscriptionProfileCharacter.graphql +6 -0
- package/docs/api-operations/wetaca_bundle__updateSubscriptionProfileName.graphql +6 -0
- package/docs/api-operations/wetaca_bundle__updateUserProfile.graphql +10 -0
- package/docs/api-operations/wetaca_bundle__useCaptchaConfig.graphql +3 -0
- package/docs/api-operations/wetaca_bundle__userSessionSubscription.graphql +20 -0
- package/docs/api-operations/wetaca_bundle__validateSegment.graphql +19 -0
- package/docs/api-operations/wetaca_bundle__validateSubscriptionIntent.graphql +6 -0
- package/docs/api-operations/wetaca_bundle__voucherCustomDisplay.graphql +22 -0
- package/docs/api-operations/wetaca_bundle__walletBalance.graphql +3 -0
- package/docs/api-operations/wetaca_bundle__walletOperations.graphql +11 -0
- package/docs/cli-spec.md +113 -0
- package/package.json +38 -4
- package/src/commands.js +700 -0
- package/src/guide.js +73 -0
- package/src/lib.js +371 -0
- package/src/queries.js +235 -0
package/src/guide.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// AI-agent usage guide, embedded in the CLI (wetaca skills get wetaca-usage).
|
|
2
|
+
export const GUIDE = `# wetaca-cli — guide for AI agents
|
|
3
|
+
|
|
4
|
+
Manage the user's Wetaca account (weekly meal subscription) from the terminal.
|
|
5
|
+
Every command returns JSON on stdout by default; errors go to stderr.
|
|
6
|
+
|
|
7
|
+
## Before you start
|
|
8
|
+
|
|
9
|
+
1. Run \`wetaca doctor\` to check node, connectivity and session.
|
|
10
|
+
2. \`wetaca auth status\` tells you whether there is a valid session. If there isn't:
|
|
11
|
+
- \`wetaca auth login --cookies cookies.txt\` (export with the Cookie-Editor extension on wetaca.com while logged in) or \`--refresh-token COOKIE\` (a wetaca.com cookie, lasts ~120 days; the CLI renews the token on its own). No password involved.
|
|
12
|
+
- \`wetaca auth login --token T\` or \`--token --clipboard\`: token copied from the
|
|
13
|
+
\`authorization: Bearer *** header of any request to api.wetaca.com in the
|
|
14
|
+
user's DevTools (F12 → Network). This is the way to go if their account logs in with Google.
|
|
15
|
+
Never ask the user for their Google password and never automate their browser for the login.
|
|
16
|
+
|
|
17
|
+
## Output contract
|
|
18
|
+
|
|
19
|
+
- stdout: JSON (\`--format pretty\` for humans, \`jsonl\` for lists, one line each).
|
|
20
|
+
- \`--error-format json\`: error wrapper { error: { code, category, reason, retryable, message, suggested_commands } }.
|
|
21
|
+
- Stable exit codes: 0 ok · 1 unexpected · 2 usage/validation/confirmation denied · 3 auth ·
|
|
22
|
+
4 network · 5 not found · 6 the API rejected the operation · 7 contract drift (schema changed).
|
|
23
|
+
- \`reason: "auth_required"\` → nothing to retry; the user must log in.
|
|
24
|
+
- \`reason: "contract_drift"\` → don't reinvent the query; open an issue on the repo.
|
|
25
|
+
|
|
26
|
+
## Rules for operations with real effects
|
|
27
|
+
|
|
28
|
+
1. Nothing changes the account without confirmation: without a terminal, \`--yes\` is required. Pass \`--yes\` ONLY when
|
|
29
|
+
the user asked for exactly that operation and saw the summary.
|
|
30
|
+
2. Use \`--dry-run\` on \`suggestion edit\` and \`orders cancel\` to show what would be sent, before asking for confirmation.
|
|
31
|
+
3. \`suggestion pause\` skips next week's delivery (the already-billed week is NOT touched).
|
|
32
|
+
\`subscription pause --weeks N\` pauses the subscription for N weeks (temporary cancellation);
|
|
33
|
+
\`subscription resume\` reactivates it.
|
|
34
|
+
4. \`orders cancel <id>\` cancels a confirmed order and refunds the amount. Ids: \`deliveries next\`
|
|
35
|
+
(pending orders) and \`orders list\` (history).
|
|
36
|
+
5. Never manage payments: wetaca-cli does not touch cards or pending Redsys/PayPal payments.
|
|
37
|
+
If \`nextPaymentPendingOrder\` is not null, tell the user and have them pay on wetaca.com.
|
|
38
|
+
|
|
39
|
+
## Commands
|
|
40
|
+
|
|
41
|
+
wetaca auth login [--refresh-token COOKIE | --token T] | status | logout
|
|
42
|
+
wetaca me summary: customer + subscription + wallet
|
|
43
|
+
wetaca subscription show | pause [--weeks N] [--feedback S] | resume
|
|
44
|
+
wetaca suggestion show next week's menu per profile, prices, delivery window
|
|
45
|
+
wetaca suggestion pause | resume skip / reactivate next week
|
|
46
|
+
wetaca suggestion edit --profile-suggestion ID --set "productId:qty,..." [--dry-run]
|
|
47
|
+
wetaca deliveries next suggestions and pending orders (ids for orders/cancel)
|
|
48
|
+
wetaca orders list [--limit N] | show <id> | cancel <id> [--dry-run]
|
|
49
|
+
wetaca menu list dishes of the week (ids for suggestion edit)
|
|
50
|
+
wetaca dish show <slug> details/ingredients of a dish
|
|
51
|
+
wetaca deliveries options delivery slots available for your zip code
|
|
52
|
+
wetaca deliveries set-option <id> --dry-run changes the slot (review and repeat with --yes)
|
|
53
|
+
wetaca profiles list your profiles and their menu
|
|
54
|
+
wetaca profiles pause <id|name> pauses a profile (dry-run first)
|
|
55
|
+
wetaca addresses list
|
|
56
|
+
wetaca addresses save --street C --number N [--floor F] --zipcode ZIP --city CITY --dry-run
|
|
57
|
+
(review the plan; repeat with --yes; optional --notes --firstname --lastname --phone)
|
|
58
|
+
wetaca addresses remove <id> deletes an address not in use
|
|
59
|
+
wetaca vouchers list
|
|
60
|
+
wetaca wallet
|
|
61
|
+
wetaca config path | list | get <k> | set <k> <v>
|
|
62
|
+
wetaca doctor
|
|
63
|
+
wetaca skills get wetaca-usage this guide
|
|
64
|
+
|
|
65
|
+
## Typical flows
|
|
66
|
+
|
|
67
|
+
- "What's on this week?": \`wetaca suggestion show --format pretty\`
|
|
68
|
+
- "I don't want rice this week": \`suggestion show\` → locate the dish and its \`productSuggestionId\`
|
|
69
|
+
(\`profileSuggestionId\`) and \`productId\` → \`suggestion edit --profile-suggestion ID --set "..." --dry-run\`
|
|
70
|
+
→ show the plan → confirm → run with \`--yes\`.
|
|
71
|
+
- "Vacation for two weeks": \`subscription pause --weeks 2\` (summary → --yes) and then \`subscription resume\`.
|
|
72
|
+
- "Cancel tomorrow's order": \`deliveries next\` → \`orders cancel <id>\`.
|
|
73
|
+
`;
|
package/src/lib.js
ADDED
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
// wetaca-cli — core library: config, errors, GraphQL client, output.
|
|
2
|
+
// Zero dependencies. Node >= 18.
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import os from 'node:os';
|
|
6
|
+
import child_process from 'node:child_process';
|
|
7
|
+
import { createRequire } from 'node:module';
|
|
8
|
+
|
|
9
|
+
const require = createRequire(import.meta.url);
|
|
10
|
+
export const VERSION = require('../package.json').version;
|
|
11
|
+
|
|
12
|
+
// ---------- exit codes (stable contract) ----------
|
|
13
|
+
export const EXIT = {
|
|
14
|
+
OK: 0,
|
|
15
|
+
UNEXPECTED: 1, // bug or unknown failure
|
|
16
|
+
USAGE: 2, // bad flags/args, validation refused, declined confirmation
|
|
17
|
+
AUTH: 3, // no/invalid token -> run `wetaca auth login`
|
|
18
|
+
NETWORK: 4, // cannot reach api.wetaca.com
|
|
19
|
+
NOT_FOUND: 5, // unknown id / no resource
|
|
20
|
+
API: 6, // Wetaca API refused the operation (see details)
|
|
21
|
+
DRIFT: 7, // API contract drift: expected field missing / shape changed
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export class CliError extends Error {
|
|
25
|
+
constructor(exitCode, message, extra = {}) {
|
|
26
|
+
super(message);
|
|
27
|
+
this.exitCode = exitCode;
|
|
28
|
+
this.extra = extra; // { reason, retryable, suggested_commands, details }
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function usageError(message, extra = {}) {
|
|
33
|
+
return new CliError(EXIT.USAGE, message, { reason: 'usage', retryable: false, ...extra });
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// ---------- config ----------
|
|
37
|
+
export function configDir() {
|
|
38
|
+
if (process.env.WETACA_CONFIG_DIR) return process.env.WETACA_CONFIG_DIR;
|
|
39
|
+
const xdg = process.env.XDG_CONFIG_HOME;
|
|
40
|
+
return path.join(xdg || path.join(os.homedir(), '.config'), 'wetaca-cli');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function configPath() { return path.join(configDir(), 'config.json'); }
|
|
44
|
+
// Secretos (token/refreshToken) en fichero aparte con permisos restrictivos.
|
|
45
|
+
// El config.json nunca lleva secretos.
|
|
46
|
+
export function credentialsPath() { return path.join(configDir(), 'credentials.json'); }
|
|
47
|
+
|
|
48
|
+
const SECRET_KEYS = ['token', 'login', 'password', 'refreshToken'];
|
|
49
|
+
|
|
50
|
+
// Permisos restrictivos: 0600 en POSIX; en Windows, ACL solo para el usuario actual.
|
|
51
|
+
function restrictPerms(p) {
|
|
52
|
+
try {
|
|
53
|
+
if (process.platform === 'win32') {
|
|
54
|
+
const { execFileSync } = child_process;
|
|
55
|
+
execFileSync('icacls', [p, '/inheritance:r', '/grant:r', `${os.userInfo().username}:F`], { stdio: 'ignore', windowsHide: true });
|
|
56
|
+
} else {
|
|
57
|
+
fs.chmodSync(p, 0o600);
|
|
58
|
+
}
|
|
59
|
+
} catch { /* best effort: si falla, el fichero queda con permisos por defecto */ }
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function saveCreds(creds) {
|
|
63
|
+
fs.mkdirSync(configDir(), { recursive: true });
|
|
64
|
+
const tmp = credentialsPath() + '.tmp';
|
|
65
|
+
fs.writeFileSync(tmp, JSON.stringify(creds, null, 2) + '\n', { mode: 0o600 });
|
|
66
|
+
fs.renameSync(tmp, credentialsPath());
|
|
67
|
+
restrictPerms(credentialsPath());
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function loadCreds() {
|
|
71
|
+
try { return JSON.parse(fs.readFileSync(credentialsPath(), 'utf8')); } catch { return { profiles: {} }; }
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function loadConfig() {
|
|
75
|
+
try {
|
|
76
|
+
return JSON.parse(fs.readFileSync(configPath(), 'utf8'));
|
|
77
|
+
} catch {
|
|
78
|
+
return { defaultProfile: 'default', profiles: {} };
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function saveConfig(cfg) {
|
|
83
|
+
fs.mkdirSync(configDir(), { recursive: true });
|
|
84
|
+
const tmp = configPath() + '.tmp';
|
|
85
|
+
fs.writeFileSync(tmp, JSON.stringify(cfg, null, 2) + '\n');
|
|
86
|
+
fs.renameSync(tmp, configPath());
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function getProfile(name, { create = false } = {}) {
|
|
90
|
+
const cfg = loadConfig();
|
|
91
|
+
name = name || cfg.defaultProfile || 'default';
|
|
92
|
+
// combined view: config.json (public) + credentials.json (secrets); the legacy
|
|
93
|
+
// one with secrets inside config.json keeps being read until migrated
|
|
94
|
+
const creds = loadCreds().profiles?.[name] || {};
|
|
95
|
+
const legacy = cfg.profiles?.[name] || {};
|
|
96
|
+
const p = { ...legacy, ...creds };
|
|
97
|
+
if (!legacy.token && !legacy.email && !legacy.login && !legacy.password && !Object.keys(creds).length) {
|
|
98
|
+
if (!create) return { name, token: null, email: null };
|
|
99
|
+
cfg.profiles = { ...(cfg.profiles || {}), [name]: { token: null, email: null } };
|
|
100
|
+
saveConfig(cfg);
|
|
101
|
+
return { name, token: null, email: null };
|
|
102
|
+
}
|
|
103
|
+
return { name, ...p };
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function saveProfile(name, data) {
|
|
107
|
+
const cfg = loadConfig();
|
|
108
|
+
name = name || cfg.defaultProfile || 'default';
|
|
109
|
+
const creds = loadCreds();
|
|
110
|
+
let credsDirty = false;
|
|
111
|
+
// secretos → credentials.json; resto → config.json
|
|
112
|
+
const sec = {}, pub = {};
|
|
113
|
+
for (const [k, v] of Object.entries(data)) (SECRET_KEYS.includes(k) ? sec : pub)[k] = v;
|
|
114
|
+
if (Object.keys(sec).length) {
|
|
115
|
+
creds.profiles = { ...(creds.profiles || {}), [name]: { ...(creds.profiles?.[name] || {}), ...sec } };
|
|
116
|
+
credsDirty = true;
|
|
117
|
+
}
|
|
118
|
+
// migration of legacy config.json: token/refreshToken move to credentials.json;
|
|
119
|
+
// login/password are DELETED (the CLI no longer stores passwords, user's decision)
|
|
120
|
+
for (const [pname, p] of Object.entries(cfg.profiles || {})) {
|
|
121
|
+
const legacy = SECRET_KEYS.filter((k) => p[k] != null);
|
|
122
|
+
if (!legacy.length) continue;
|
|
123
|
+
for (const k of legacy) {
|
|
124
|
+
if (k === 'login' || k === 'password') { delete p[k]; continue; }
|
|
125
|
+
creds.profiles = { ...(creds.profiles || {}) };
|
|
126
|
+
creds.profiles[pname] = { ...(creds.profiles?.[pname] || {}) };
|
|
127
|
+
creds.profiles[pname][k] ??= p[k];
|
|
128
|
+
delete p[k];
|
|
129
|
+
}
|
|
130
|
+
credsDirty = true;
|
|
131
|
+
}
|
|
132
|
+
if (credsDirty) saveCreds(creds);
|
|
133
|
+
if (Object.keys(pub).length) {
|
|
134
|
+
cfg.profiles = { ...(cfg.profiles || {}), [name]: { ...(cfg.profiles?.[name] || {}), ...pub } };
|
|
135
|
+
}
|
|
136
|
+
if (!cfg.defaultProfile) cfg.defaultProfile = name;
|
|
137
|
+
saveConfig(cfg);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export function getToken(profileName) {
|
|
141
|
+
if (process.env.WETACA_TOKEN) return process.env.WETACA_TOKEN;
|
|
142
|
+
return getProfile(profileName).token || null;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// ---------- GraphQL client ----------
|
|
146
|
+
const API_URL = process.env.WETACA_API_URL || 'https://api.wetaca.com/graphql';
|
|
147
|
+
const UA = `wetaca-cli/${VERSION} (+https://github.com/gorgueugr/wetaca-cli)`;
|
|
148
|
+
|
|
149
|
+
async function rawRequest(query, variables, tok, debug) {
|
|
150
|
+
const headers = {
|
|
151
|
+
'Content-Type': 'application/json',
|
|
152
|
+
'User-Agent': UA,
|
|
153
|
+
};
|
|
154
|
+
if (tok) headers.authorization = `Bearer ${tok}`;
|
|
155
|
+
let res;
|
|
156
|
+
const started = Date.now();
|
|
157
|
+
try {
|
|
158
|
+
res = await fetch(API_URL, {
|
|
159
|
+
method: 'POST',
|
|
160
|
+
headers,
|
|
161
|
+
body: JSON.stringify({ query, variables: variables || {} }),
|
|
162
|
+
});
|
|
163
|
+
} catch (e) {
|
|
164
|
+
throw new CliError(EXIT.NETWORK, `Could not connect to the Wetaca API: ${e.cause?.code || e.message}`,
|
|
165
|
+
{ reason: 'network', retryable: true });
|
|
166
|
+
}
|
|
167
|
+
if (debug) console.error(`wetaca: POST ${API_URL} -> ${res.status} (${Date.now() - started} ms)`);
|
|
168
|
+
if (!res.ok) {
|
|
169
|
+
if (res.status === 401 || res.status === 403) {
|
|
170
|
+
const e = new CliError(EXIT.AUTH, 'The API rejected the session (401/403). The token may have expired.',
|
|
171
|
+
{ reason: 'auth_rejected', retryable: false, suggested_commands: ['wetaca auth login'] });
|
|
172
|
+
e.auth = true;
|
|
173
|
+
throw e;
|
|
174
|
+
}
|
|
175
|
+
throw new CliError(EXIT.API, `The API responded with HTTP ${res.status}`,
|
|
176
|
+
{ reason: 'http_' + res.status, retryable: res.status >= 500 || res.status === 429 });
|
|
177
|
+
}
|
|
178
|
+
let body;
|
|
179
|
+
try { body = await res.json(); } catch {
|
|
180
|
+
throw new CliError(EXIT.DRIFT, 'The API returned a non-JSON response (possible contract change).',
|
|
181
|
+
{ reason: 'contract_drift', retryable: false });
|
|
182
|
+
}
|
|
183
|
+
return body;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Stored credential for auto-refresh: ONLY the refresh-token (120-day cookie).
|
|
187
|
+
// The password is never requested nor stored (user's decision).
|
|
188
|
+
function storedRefreshToken(profile) {
|
|
189
|
+
if (process.env.WETACA_REFRESH_TOKEN) return process.env.WETACA_REFRESH_TOKEN;
|
|
190
|
+
const cfg = loadConfig();
|
|
191
|
+
const name = profile || cfg.defaultProfile || 'default';
|
|
192
|
+
const c = loadCreds().profiles?.[name];
|
|
193
|
+
return c?.refreshToken || null;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// Renews the token with the refresh-token cookie (120 days) via POST /session/refresh,
|
|
197
|
+
// just like the web does (bundles: auth-token + refresh-token cookies, x-wetaca-session).
|
|
198
|
+
// Also exported for `auth login --refresh-token`.
|
|
199
|
+
export async function sessionRefresh(rt, profile, debug) {
|
|
200
|
+
let res;
|
|
201
|
+
try {
|
|
202
|
+
res = await fetch(`${API_URL}/session/refresh`, {
|
|
203
|
+
method: 'POST',
|
|
204
|
+
headers: {
|
|
205
|
+
'Content-Type': 'application/json',
|
|
206
|
+
Cookie: `refresh-token=${rt}`,
|
|
207
|
+
'x-wetaca-session': '1',
|
|
208
|
+
'User-Agent': UA,
|
|
209
|
+
},
|
|
210
|
+
});
|
|
211
|
+
} catch (e) {
|
|
212
|
+
throw new CliError(EXIT.NETWORK, `Could not connect to the Wetaca API: ${e.cause?.code || e.message}`,
|
|
213
|
+
{ reason: 'network', retryable: true });
|
|
214
|
+
}
|
|
215
|
+
if (res.status === 400 || res.status === 401) {
|
|
216
|
+
throw new CliError(EXIT.AUTH, 'The refresh-token is invalid (copied incorrectly, expired, or revoked). Copy it from wetaca.com while logged in: F12 → Application → Cookies → wetaca.com → refresh-token (full value).',
|
|
217
|
+
{ reason: 'refresh_token_invalid', retryable: false, suggested_commands: ['wetaca auth login --token T'] });
|
|
218
|
+
}
|
|
219
|
+
if (!res.ok) {
|
|
220
|
+
throw new CliError(EXIT.API, `The API responded with HTTP ${res.status} while refreshing the session`,
|
|
221
|
+
{ reason: 'http_' + res.status, retryable: res.status >= 500 });
|
|
222
|
+
}
|
|
223
|
+
let j;
|
|
224
|
+
try { j = await res.json(); } catch {
|
|
225
|
+
throw new CliError(EXIT.DRIFT, 'The API returned a non-JSON response while refreshing the session.',
|
|
226
|
+
{ reason: 'contract_drift', retryable: false });
|
|
227
|
+
}
|
|
228
|
+
if (!j?.token) {
|
|
229
|
+
throw new CliError(EXIT.DRIFT, 'The refresh did not return a token (possible contract change).',
|
|
230
|
+
{ reason: 'contract_drift', retryable: false });
|
|
231
|
+
}
|
|
232
|
+
saveProfile(profile, { token: j.token });
|
|
233
|
+
// rotation: if the API issues a new refresh-token in Set-Cookie, we save it
|
|
234
|
+
const sc = res.headers.get('set-cookie');
|
|
235
|
+
const m = sc && sc.match(/(?:^|,\s*)refresh-token=([^;\s]+)/);
|
|
236
|
+
if (m && m[1] && m[1] !== rt) saveProfile(profile, { refreshToken: m[1] });
|
|
237
|
+
if (debug) console.error('wetaca: token automatically renewed (refresh-token)');
|
|
238
|
+
return j.token;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export async function gql(query, variables, { token, profile, debug, anon = false } = {}) {
|
|
242
|
+
const tok0 = token ?? getToken(profile);
|
|
243
|
+
if (!tok0 && !anon) {
|
|
244
|
+
throw new CliError(EXIT.AUTH, 'No session. Run `wetaca auth login` (or set WETACA_TOKEN).',
|
|
245
|
+
{ reason: 'auth_required', retryable: false, suggested_commands: ['wetaca auth login'] });
|
|
246
|
+
}
|
|
247
|
+
// Auto-refresh: if the request fails due to an expired session and a refresh-token is stored,
|
|
248
|
+
// renew via /session/refresh and retry ONCE (only with the stored token).
|
|
249
|
+
const canRefresh = !anon && !token && !!storedRefreshToken(profile);
|
|
250
|
+
const call = async (tok) => {
|
|
251
|
+
const body = await rawRequest(query, variables, tok, debug);
|
|
252
|
+
if (body.errors?.length) {
|
|
253
|
+
const codes = body.errors.map((e) => e.extensions?.code).filter(Boolean);
|
|
254
|
+
if (codes.includes('UNAUTHENTICATED')) {
|
|
255
|
+
const e = new CliError(EXIT.AUTH, 'The session is not valid for this operation.',
|
|
256
|
+
{ reason: 'auth_required', retryable: false, suggested_commands: ['wetaca auth login'] });
|
|
257
|
+
e.auth = true;
|
|
258
|
+
throw e;
|
|
259
|
+
}
|
|
260
|
+
throw new CliError(EXIT.API, body.errors.map((e) => e.message).join('; '),
|
|
261
|
+
{ reason: 'graphql_error', retryable: false, details: body.errors });
|
|
262
|
+
}
|
|
263
|
+
// OJO: los campos top-level null son NORMALES en esta API (p. ej. nextPaymentPendingOrder
|
|
264
|
+
// null = "no hay pagos pendientes"); no implican deriva de contrato. Cada comando decide.
|
|
265
|
+
return body.data;
|
|
266
|
+
};
|
|
267
|
+
try {
|
|
268
|
+
return await call(tok0);
|
|
269
|
+
} catch (e) {
|
|
270
|
+
if (!canRefresh || !e.auth) throw e;
|
|
271
|
+
const rt = storedRefreshToken(profile);
|
|
272
|
+
if (!rt) throw e;
|
|
273
|
+
return call(await sessionRefresh(rt, profile, debug));
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// ---------- money / dates helpers ----------
|
|
278
|
+
export function cents(v) {
|
|
279
|
+
if (v == null) return null;
|
|
280
|
+
return (v / 100).toFixed(2).replace('.', ',') + ' €';
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
export function fmtWindow(option) {
|
|
284
|
+
if (!option) return null;
|
|
285
|
+
return fmtDate(option.start) + ' → ' + fmtDate(option.end);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
export function fmtDate(iso) {
|
|
289
|
+
if (!iso) return null;
|
|
290
|
+
const d = new Date(iso);
|
|
291
|
+
if (isNaN(d)) return iso;
|
|
292
|
+
const wd = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'][d.getDay()];
|
|
293
|
+
const p = (n) => String(n).padStart(2, '0');
|
|
294
|
+
return `${wd} ${p(d.getDate())} ${['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'][d.getMonth()]} ${p(d.getHours())}:${p(d.getMinutes())}`;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// ---------- output ----------
|
|
298
|
+
export function isJsonFormat(fmt) { return fmt === 'json' || fmt === 'jsonl'; }
|
|
299
|
+
|
|
300
|
+
export function emit(data, { format, jsonl }) {
|
|
301
|
+
if (format === 'pretty') { printPretty(data); return; }
|
|
302
|
+
if (jsonl) {
|
|
303
|
+
const arr = Array.isArray(data) ? data : data.items;
|
|
304
|
+
if (Array.isArray(arr)) { for (const x of arr) console.log(JSON.stringify(x)); return; }
|
|
305
|
+
}
|
|
306
|
+
console.log(JSON.stringify(data, null, 2));
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
function printPretty(data, indent = '') {
|
|
310
|
+
if (Array.isArray(data)) {
|
|
311
|
+
if (data.length && typeof data[0] === 'object') printTable(data); else data.forEach((x) => console.log(indent + '- ' + x));
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
if (typeof data !== 'object' || data === null) { console.log(indent + String(data)); return; }
|
|
315
|
+
for (const [k, v] of Object.entries(data)) {
|
|
316
|
+
if (v == null) continue;
|
|
317
|
+
if (typeof v === 'object' && !Array.isArray(v)) {
|
|
318
|
+
console.log(indent + k + ':');
|
|
319
|
+
printPretty(v, indent + ' ');
|
|
320
|
+
} else if (Array.isArray(v)) {
|
|
321
|
+
console.log(indent + k + ':');
|
|
322
|
+
printPretty(v, indent + ' ');
|
|
323
|
+
} else {
|
|
324
|
+
// prices in cents → euros in pretty mode
|
|
325
|
+
const isCents = /price|toPay|balance/i.test(k) && typeof v === 'number' && v > 100;
|
|
326
|
+
console.log(indent + `${k}: ${isCents ? cents(v) : v}`);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
function printTable(rows) {
|
|
332
|
+
const cols = Object.keys(rows[0]);
|
|
333
|
+
const cell = (v, k) => {
|
|
334
|
+
if (v == null) return '';
|
|
335
|
+
if (Array.isArray(v)) return v.map((x) => cell(x)).join(', ');
|
|
336
|
+
if (typeof v === 'object') {
|
|
337
|
+
if (typeof v.name === 'string') return v.name;
|
|
338
|
+
return Object.entries(v).filter(([, x]) => x != null && typeof x !== 'object')
|
|
339
|
+
.map(([kk, x]) => `${kk}=${x}`).join(' ');
|
|
340
|
+
}
|
|
341
|
+
if (typeof v === 'number' && /price|toPay/i.test(k || '') && v > 100) return cents(v);
|
|
342
|
+
return String(v);
|
|
343
|
+
};
|
|
344
|
+
const w = {};
|
|
345
|
+
for (const c of cols) w[c] = Math.min(Math.max(c.length, ...rows.map((r) => cell(r[c], c).length)), 40);
|
|
346
|
+
const line = (l, m, r) => l + cols.map((c) => '─'.repeat(w[c])).join(m) + r;
|
|
347
|
+
console.log(line('┌', '┬', '┐'));
|
|
348
|
+
console.log('│' + cols.map((c) => c.padEnd(w[c])).join('│') + '│');
|
|
349
|
+
console.log(line('├', '┼', '┤'));
|
|
350
|
+
for (const r of rows) console.log('│' + cols.map((c) => cell(r[c], c).slice(0, w[c]).padEnd(w[c])).join('│') + '│');
|
|
351
|
+
console.log(line('└', '┴', '┘'));
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
export function printError(err, errorFormat, debug = false) {
|
|
355
|
+
if (errorFormat === 'json') {
|
|
356
|
+
console.error(JSON.stringify({
|
|
357
|
+
error: {
|
|
358
|
+
code: err.exitCode,
|
|
359
|
+
category: Object.entries(EXIT).find(([, v]) => v === err.exitCode)?.[0]?.toLowerCase() || 'unexpected',
|
|
360
|
+
reason: err.extra?.reason || 'unexpected',
|
|
361
|
+
retryable: !!err.extra?.retryable,
|
|
362
|
+
message: err.message,
|
|
363
|
+
suggested_commands: err.extra?.suggested_commands || [],
|
|
364
|
+
...(debug && err.extra?.details ? { details: err.extra.details } : {}),
|
|
365
|
+
},
|
|
366
|
+
}, null, 2));
|
|
367
|
+
} else {
|
|
368
|
+
console.error('wetaca: ' + err.message);
|
|
369
|
+
if (err.extra?.suggested_commands?.length) console.error(' → ' + err.extra.suggested_commands.join(' ; '));
|
|
370
|
+
}
|
|
371
|
+
}
|
package/src/queries.js
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
// GraphQL documents used by wetaca-cli.
|
|
2
|
+
// Field names verified against wetaca.com's web bundle (web app v49.6.0, oct 2026).
|
|
3
|
+
// Keep in sync with docs/cli-spec.md. The API is unofficial and can drift.
|
|
4
|
+
|
|
5
|
+
export const CUSTOMER = `query customer {
|
|
6
|
+
customer { id firstname lastname email phoneNumber }
|
|
7
|
+
}`;
|
|
8
|
+
|
|
9
|
+
export const TOKEN_IS_VALID = `query tokenIsValid($token: String!) {
|
|
10
|
+
tokenIsValid(token: $token)
|
|
11
|
+
}`;
|
|
12
|
+
|
|
13
|
+
export const SESSION_BY_PASSWORD = `query sessionTokenByPassword($login: String!, $password: String!, $segmentSlug: String) {
|
|
14
|
+
sessionTokenData: sessionTokenByPassword(username: $login, password: $password, segmentSlug: $segmentSlug) {
|
|
15
|
+
customerId
|
|
16
|
+
jwtToken
|
|
17
|
+
requirePhoneNumber
|
|
18
|
+
}
|
|
19
|
+
}`;
|
|
20
|
+
|
|
21
|
+
export const SUBSCRIBER_STATUS = `query subscriberAccountStatus {
|
|
22
|
+
subscriptionAccountByCustomer { id isActive cancelled pausedUntil nextSuggestionSkipped }
|
|
23
|
+
}`;
|
|
24
|
+
|
|
25
|
+
export const SUBSCRIPTION_FULL = `query subscriptionFull {
|
|
26
|
+
subscriptionAccountByCustomer {
|
|
27
|
+
id isActive cancelled pausedUntil dateCreated isOptInMutable
|
|
28
|
+
delivery {
|
|
29
|
+
type
|
|
30
|
+
address { id firstname lastname street number floor zipcode city phone }
|
|
31
|
+
option { id start end price customizedPrice }
|
|
32
|
+
}
|
|
33
|
+
subscriptionAccountPricing { toPay shipping }
|
|
34
|
+
recurringSubscriptionType { type dishesVariety }
|
|
35
|
+
profiles { id isActive name email price }
|
|
36
|
+
}
|
|
37
|
+
nextSuggestion { id skip validUntil isBeingCharged suggestionPricing { toPay } }
|
|
38
|
+
}`;
|
|
39
|
+
|
|
40
|
+
export const NEXT_SUGGESTION = `query nextSuggestionCli {
|
|
41
|
+
nextSuggestion {
|
|
42
|
+
id skip validUntil isOptIn pausedAt accountIsActive currentOrderStreakProgress
|
|
43
|
+
delivery {
|
|
44
|
+
address { id firstname lastname street number floor zipcode city phone }
|
|
45
|
+
option { id start end price customizedPrice }
|
|
46
|
+
}
|
|
47
|
+
suggestionPricing {
|
|
48
|
+
shipping toPay
|
|
49
|
+
profilesTotal { transactional subscription toPay }
|
|
50
|
+
salesPlan { packageOption { index } }
|
|
51
|
+
appliedVouchers { code appliedDiscount }
|
|
52
|
+
}
|
|
53
|
+
menuMetadata { week year dateFrom dateTo }
|
|
54
|
+
profileSuggestions {
|
|
55
|
+
id profileId skip hasChanges maxPriceWithoutChanges
|
|
56
|
+
profileId
|
|
57
|
+
products {
|
|
58
|
+
id slug name quantity price subscriptionPrice
|
|
59
|
+
category { slug name }
|
|
60
|
+
allergens tags
|
|
61
|
+
}
|
|
62
|
+
productMap { id quantity day }
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}`;
|
|
66
|
+
|
|
67
|
+
export const EDIT_PROFILE_SUGGESTION_MENU = `mutation editProfileSuggestionMenu($profileSuggestionId: ModelId!, $productsInput: [OrderProductMapGraph!]!, $resumeAccountSuggestion: Boolean) {
|
|
68
|
+
editProfileSuggestionProducts(profileSuggestionId: $profileSuggestionId, productsInput: $productsInput, resumeAccountSuggestion: $resumeAccountSuggestion) {
|
|
69
|
+
products { id quantity }
|
|
70
|
+
}
|
|
71
|
+
}`;
|
|
72
|
+
|
|
73
|
+
export const PAUSE_SUGGESTION = `mutation pauseSuggestion($suggestionId: ModelId!, $path: String!, $feedback: String) {
|
|
74
|
+
paused: pauseSuggestion(suggestionId: $suggestionId, path: $path, feedback: $feedback) { id skip }
|
|
75
|
+
}`;
|
|
76
|
+
|
|
77
|
+
export const RESUME_SUGGESTION = `mutation resumeSuggestion($suggestionId: ModelId!) {
|
|
78
|
+
resumed: resumeSuggestion(suggestionId: $suggestionId) { id skip }
|
|
79
|
+
}`;
|
|
80
|
+
|
|
81
|
+
export const CANCEL_SUBSCRIPTION = `mutation cancelSubscriptionAccount($subscriptionAccountId: ModelId!, $path: String!, $pausedWeeks: Int, $feedback: String) {
|
|
82
|
+
subscriptionAccount: cancelSubscriptionAccount(subscriptionAccountId: $subscriptionAccountId, path: $path, pausedWeeks: $pausedWeeks, feedback: $feedback) {
|
|
83
|
+
id isActive pausedUntil
|
|
84
|
+
delivery { option { start end } address { zipcode street } }
|
|
85
|
+
}
|
|
86
|
+
}`;
|
|
87
|
+
|
|
88
|
+
export const ACTIVATE_SUBSCRIPTION = `mutation activateSubscriptionAccount($subscriptionAccountId: ModelId!) {
|
|
89
|
+
subscriptionAccount: activateSubscriptionAccount(subscriptionAccountId: $subscriptionAccountId) {
|
|
90
|
+
id isActive pausedUntil
|
|
91
|
+
}
|
|
92
|
+
}`;
|
|
93
|
+
|
|
94
|
+
export const PENDING_DELIVERY = `query pendingDeliveryCli {
|
|
95
|
+
nextSuggestions {
|
|
96
|
+
id skip validUntil isBeingCharged
|
|
97
|
+
menuMetadata { week year dateFrom }
|
|
98
|
+
suggestionPricing { toPay shipping }
|
|
99
|
+
profileSuggestions { id profileId skip }
|
|
100
|
+
}
|
|
101
|
+
nextDeliveries {
|
|
102
|
+
order {
|
|
103
|
+
id reference state canChange price
|
|
104
|
+
delivery { option { start end } address { zipcode street city } }
|
|
105
|
+
products { id name quantity price subscriptionPrice slug }
|
|
106
|
+
}
|
|
107
|
+
validUntil
|
|
108
|
+
skip
|
|
109
|
+
}
|
|
110
|
+
nextPaymentPendingOrder { id reference state price invoiceUrl }
|
|
111
|
+
}`;
|
|
112
|
+
|
|
113
|
+
export const PREVIOUS_DELIVERIES = `query previousDeliveries($limit: Int!, $offset: Int) {
|
|
114
|
+
previousDeliveries(limit: $limit, offset: $offset) {
|
|
115
|
+
id reference dateCreated price state invoiceUrl
|
|
116
|
+
delivery { option { start end } }
|
|
117
|
+
}
|
|
118
|
+
}`;
|
|
119
|
+
|
|
120
|
+
export const ORDER_DETAILS = `query orderDetails($id: Int!) {
|
|
121
|
+
order(id: $id) {
|
|
122
|
+
id reference state canChange dateCreated price invoiceUrl
|
|
123
|
+
delivery {
|
|
124
|
+
type
|
|
125
|
+
address { firstname lastname street number floor zipcode city phone }
|
|
126
|
+
option { start end price }
|
|
127
|
+
}
|
|
128
|
+
products { id slug name price quantity allergens ingredients }
|
|
129
|
+
profilesProductMap { name products { id quantity day } }
|
|
130
|
+
payments { provider }
|
|
131
|
+
}
|
|
132
|
+
}`;
|
|
133
|
+
|
|
134
|
+
export const CANCEL_ORDER = `mutation cancelConfirmedOrder($orderId: Int!) {
|
|
135
|
+
cancelConfirmedOrder(orderId: $orderId) { amount outcome }
|
|
136
|
+
}`;
|
|
137
|
+
|
|
138
|
+
export const ADDRESSES = `query addresses {
|
|
139
|
+
addresses {
|
|
140
|
+
id firstname lastname street number floor zipcode city phone notes
|
|
141
|
+
isSubscriptionAddress isSuggestionAddress
|
|
142
|
+
}
|
|
143
|
+
}`;
|
|
144
|
+
|
|
145
|
+
export const SAVE_ADDRESS = `mutation saveAddress($address: AddressInput!) {
|
|
146
|
+
saveAddress(address: $address) {
|
|
147
|
+
id firstname lastname street number floor zipcode city phone
|
|
148
|
+
}
|
|
149
|
+
}`;
|
|
150
|
+
|
|
151
|
+
// Configuración de entrega actual (suscripción + sugerencia de la semana próxima)
|
|
152
|
+
export const DELIVERY_CONFIG = `query deliveryConfig {
|
|
153
|
+
subscriptionAccountByCustomer {
|
|
154
|
+
id
|
|
155
|
+
delivery {
|
|
156
|
+
type
|
|
157
|
+
option { id }
|
|
158
|
+
address { id firstname lastname street number floor zipcode city phone notes }
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
nextSuggestion {
|
|
162
|
+
id
|
|
163
|
+
delivery { type option { id } address { id } }
|
|
164
|
+
}
|
|
165
|
+
}`;
|
|
166
|
+
|
|
167
|
+
export const EDIT_SUBSCRIPTION_DELIVERY = `mutation editSubscriptionDelivery($subscriptionDeliveryInput: EditSubscriptionGraph!, $checkChargingSuggestion: Boolean) {
|
|
168
|
+
editDeliveryAccountInfo(subscriptionDeliveryInput: $subscriptionDeliveryInput, checkChargingSuggestion: $checkChargingSuggestion) { id }
|
|
169
|
+
}`;
|
|
170
|
+
|
|
171
|
+
export const EDIT_SUGGESTION_DELIVERY = `mutation editSuggestionDelivery($suggestionId: ModelId!, $suggestionDeliveryInput: EditSuggestionDeliveryGraph!) {
|
|
172
|
+
editSuggestionDelivery(suggestionId: $suggestionId, suggestionDeliveryInput: $suggestionDeliveryInput) { id }
|
|
173
|
+
}`;
|
|
174
|
+
|
|
175
|
+
// ---------- catálogo ----------
|
|
176
|
+
export const SEGMENT_MENU = `query segmentMenu($zipcode: Int, $isSubscriptionIntent: Boolean) {
|
|
177
|
+
segmentMenu(zipcode: $zipcode, isSubscriptionIntent: $isSubscriptionIntent) {
|
|
178
|
+
id week year dateFrom dateTo
|
|
179
|
+
dishes {
|
|
180
|
+
id name slug price subscriptionPrice isNew available tags
|
|
181
|
+
category { name slug }
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}`;
|
|
185
|
+
|
|
186
|
+
export const DISH = `query dish($slug: String!) {
|
|
187
|
+
dish(slug: $slug) {
|
|
188
|
+
id name slug available
|
|
189
|
+
description price subscriptionPrice
|
|
190
|
+
ingredients allergens tags features
|
|
191
|
+
customerRating customerRatingCount
|
|
192
|
+
category { name slug }
|
|
193
|
+
}
|
|
194
|
+
}`;
|
|
195
|
+
|
|
196
|
+
// ---------- franja de entrega ----------
|
|
197
|
+
export const DELIVERY_OPTIONS = `query deliveryOptionsByZipcode($zipcode: Int!) {
|
|
198
|
+
deliveryOptions: deliveryOptionsByZipcode(zipcode: $zipcode) { id start end price }
|
|
199
|
+
}`;
|
|
200
|
+
|
|
201
|
+
export const REMOVE_ADDRESS = `mutation removeAddress($addressId: Int!) {
|
|
202
|
+
removeAddress(addressId: $addressId) { id }
|
|
203
|
+
}`;
|
|
204
|
+
|
|
205
|
+
// ---------- perfiles ----------
|
|
206
|
+
export const PROFILES = `query profiles {
|
|
207
|
+
subscriptionAccountByCustomer {
|
|
208
|
+
id isActive pausedUntil
|
|
209
|
+
profiles {
|
|
210
|
+
id name email isActive
|
|
211
|
+
products { id name quantity price subscriptionPrice }
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}`;
|
|
215
|
+
|
|
216
|
+
export const PAUSE_PROFILE = `mutation pauseProfile($profileId: ModelId!) {
|
|
217
|
+
pauseProfile(profileId: $profileId) { id name isActive }
|
|
218
|
+
}`;
|
|
219
|
+
|
|
220
|
+
export const RESUME_PROFILE = `mutation resumeProfile($profileId: ModelId!) {
|
|
221
|
+
resumeProfile(profileId: $profileId) { id name isActive }
|
|
222
|
+
}`;
|
|
223
|
+
|
|
224
|
+
export const VOUCHERS = `query customerVouchersCli {
|
|
225
|
+
vouchers(limit: 50, skipExpired: false, skipFuture: false) {
|
|
226
|
+
code dateTo remainingUses isReferral
|
|
227
|
+
discount { price percent maximum }
|
|
228
|
+
subscriptionDiscount { price percent }
|
|
229
|
+
restrict { firstSubscription minimumAmount }
|
|
230
|
+
}
|
|
231
|
+
}`;
|
|
232
|
+
|
|
233
|
+
export const WALLET = `query walletBalance { walletBalance }`;
|
|
234
|
+
|
|
235
|
+
export const LOGOUT = `query registerLogout { registerLogout }`;
|