@deepdynamic/cli 0.0.0-stage → 0.1.1
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 +201 -0
- package/README.md +32 -2
- package/THIRD_PARTY_NOTICES.txt +102 -0
- package/dist/agents/content.js +12 -0
- package/dist/agents/edit.js +140 -0
- package/dist/agents/install.js +190 -0
- package/dist/agents/refresh.js +20 -0
- package/dist/agents/setup.js +29 -0
- package/dist/agents/targets.js +91 -0
- package/dist/auth/credentials.js +63 -0
- package/dist/auth/session.js +49 -0
- package/dist/cli.js +198 -0
- package/dist/commands/account.js +96 -0
- package/dist/commands/activity.js +80 -0
- package/dist/commands/blocked.js +89 -0
- package/dist/commands/deploy/agents.js +11 -0
- package/dist/commands/deploy/files.js +62 -0
- package/dist/commands/deploy/index.js +95 -0
- package/dist/commands/deploy/manifest.js +24 -0
- package/dist/commands/deploy/minify.js +27 -0
- package/dist/commands/deploy/progress.js +85 -0
- package/dist/commands/deploy/ship.js +117 -0
- package/dist/commands/deploy/upload.js +125 -0
- package/dist/commands/deployments.js +60 -0
- package/dist/commands/dns.js +777 -0
- package/dist/commands/domains.js +639 -0
- package/dist/commands/emails.js +74 -0
- package/dist/commands/env.js +194 -0
- package/dist/commands/help.js +148 -0
- package/dist/commands/keys.js +263 -0
- package/dist/commands/login/flow.js +155 -0
- package/dist/commands/login/index.js +26 -0
- package/dist/commands/logout.js +71 -0
- package/dist/commands/mail.js +241 -0
- package/dist/commands/notifications.js +133 -0
- package/dist/commands/plan.js +355 -0
- package/dist/commands/projects.js +838 -0
- package/dist/commands/reference.js +2187 -0
- package/dist/commands/search.js +86 -0
- package/dist/commands/server.js +301 -0
- package/dist/commands/sessions.js +114 -0
- package/dist/commands/sites.js +102 -0
- package/dist/commands/sms.js +65 -0
- package/dist/commands/status.js +87 -0
- package/dist/commands/support.js +115 -0
- package/dist/commands/update.js +100 -0
- package/dist/commands/usage.js +51 -0
- package/dist/commands/verify.js +149 -0
- package/dist/commands/version.js +6 -0
- package/dist/guide.js +37 -0
- package/dist/http/call.js +6 -0
- package/dist/http/request.js +54 -0
- package/dist/index.js +11 -0
- package/dist/metadata.js +4 -0
- package/dist/output.js +9 -0
- package/dist/pretty.js +70 -0
- package/dist/refresh-skills.js +5 -0
- package/dist/registry.js +688 -0
- package/dist/runtime/browser.js +15 -0
- package/dist/runtime/card-request.js +55 -0
- package/dist/runtime/confirm.js +21 -0
- package/dist/runtime/development.js +13 -0
- package/dist/runtime/domain-name.js +5 -0
- package/dist/runtime/dry-run.js +28 -0
- package/dist/runtime/env-file.js +55 -0
- package/dist/runtime/error-hints.js +26 -0
- package/dist/runtime/flags.js +48 -0
- package/dist/runtime/login-screen.js +78 -0
- package/dist/runtime/page.js +18 -0
- package/dist/runtime/project-name.js +1 -0
- package/dist/runtime/run-mode.js +7 -0
- package/dist/runtime/server-options.js +28 -0
- package/dist/runtime/spinner.js +17 -0
- package/dist/runtime/suggest.js +22 -0
- package/dist/runtime/support.js +13 -0
- package/dist/runtime/text-file.js +20 -0
- package/dist/runtime/timeout.js +22 -0
- package/dist/runtime/update-check.js +158 -0
- package/dist/runtime/update-install.js +80 -0
- package/dist/runtime/usage-error.js +9 -0
- package/dist/setup-agents.js +15 -0
- package/dist/site.js +1 -0
- package/dist/update-refresh.js +5 -0
- package/package.json +46 -3
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
import { defaultAuthDeps } from "../auth/session.js";
|
|
2
|
+
import { failureError, httpFailure } from "../http/request.js";
|
|
3
|
+
import { agentResult } from "../output.js";
|
|
4
|
+
import { prettyResult } from "../pretty.js";
|
|
5
|
+
import { confirmationRequired, splitYes } from "../runtime/confirm.js";
|
|
6
|
+
import { plannedChange, plannedRequest } from "../runtime/dry-run.js";
|
|
7
|
+
import { unknownArgument } from "../runtime/flags.js";
|
|
8
|
+
import { spec } from "../registry.js";
|
|
9
|
+
import { supportFailure } from "../runtime/support.js";
|
|
10
|
+
import { rehearsed } from "./dns.js";
|
|
11
|
+
export const PLAN_PATH = '/api/v1/billing';
|
|
12
|
+
const SUBSCRIPTION_PATH = `${PLAN_PATH}/subscription`;
|
|
13
|
+
const PRICES = { pro: 9900, team: 29000 };
|
|
14
|
+
const SHOW = spec('plan');
|
|
15
|
+
const SUBSCRIBE = spec('plan subscribe');
|
|
16
|
+
const CANCEL = spec('plan cancel');
|
|
17
|
+
const RESUME = spec('plan resume');
|
|
18
|
+
const PAY = spec('plan pay');
|
|
19
|
+
const PAY_PATH = `${PLAN_PATH}/charges/pay`;
|
|
20
|
+
const PAY_FAILED = 'Could not pay the unpaid charges.';
|
|
21
|
+
const SUBSCRIBE_FAILED = 'Could not change the plan.';
|
|
22
|
+
const ASK = 'Confirm with the user, then run it again with --yes.';
|
|
23
|
+
const krw = (amount) => `${amount.toLocaleString('en-US')} KRW`;
|
|
24
|
+
const unpaidCharges = (count) => `${count.toLocaleString('en-US')} unpaid ${count === 1 ? 'charge' : 'charges'}`;
|
|
25
|
+
const known = (code, message) => ({ code, message, display: message });
|
|
26
|
+
const UNAVAILABLE = supportFailure('unavailable');
|
|
27
|
+
const CHANGE_UNAVAILABLE = supportFailure('unavailable', {
|
|
28
|
+
note: 'The change may already have been applied, so check deepdynamic plan before retrying.'
|
|
29
|
+
});
|
|
30
|
+
const CHARGE_PENDING = known('charge_pending', 'A payment for this subscription is still being processed, so nothing was changed. Check deepdynamic plan a little later and contact support with deepdynamic support contact if it stays pending.');
|
|
31
|
+
const NO_SUBSCRIPTION = known('no_subscription', 'The account has no paid subscription, so nothing was changed. Check it with deepdynamic plan.');
|
|
32
|
+
const DECLINED = {
|
|
33
|
+
code: 'payment_declined',
|
|
34
|
+
message: 'The card company declined the payment, so nothing was charged or changed. reason holds its answer when it gave one. Ask the user to check the card or register another one, then run the same command again.',
|
|
35
|
+
display: 'The card company declined the payment, so nothing was charged. Check the card or register another one, then try again.'
|
|
36
|
+
};
|
|
37
|
+
const NO_UNPAID = known('no_unpaid', 'The account has no unpaid charge, so nothing was charged. Check it with deepdynamic plan.');
|
|
38
|
+
const SUBSCRIBE_FAILURES = {
|
|
39
|
+
unavailable: CHANGE_UNAVAILABLE,
|
|
40
|
+
charge_pending: CHARGE_PENDING,
|
|
41
|
+
invalid_plan: known('invalid_plan', 'The server accepts only pro or team as the plan, so nothing was changed.'),
|
|
42
|
+
unpaid_charges: known('unpaid_charges', 'The account has unpaid charges, so the plan was not raised and nothing was charged. Pay them with deepdynamic plan pay, then run the same command again.'),
|
|
43
|
+
payment_unavailable: supportFailure('payment_unavailable', { note: 'Nothing was charged or changed.' })
|
|
44
|
+
};
|
|
45
|
+
const SHOW_STEPS = [
|
|
46
|
+
{ stage: 'check_options', message: 'Checking the options.' },
|
|
47
|
+
{ stage: 'prepare_request', message: 'Preparing the plan request.' }
|
|
48
|
+
];
|
|
49
|
+
const SUBSCRIBE_STEPS = [
|
|
50
|
+
{ stage: 'check_options', message: 'Checking the plan options.' },
|
|
51
|
+
{ stage: 'calculate_charge', message: 'Calculating the monthly price of the plan.' },
|
|
52
|
+
{ stage: 'check_consent', message: 'Checking the payment consent.' },
|
|
53
|
+
{ stage: 'prepare_request', message: 'Preparing the plan change request.' }
|
|
54
|
+
];
|
|
55
|
+
const CANCEL_STEPS = [
|
|
56
|
+
{ stage: 'check_options', message: 'Checking the cancellation options.' },
|
|
57
|
+
{ stage: 'summarize_impact', message: 'Summarizing the remaining period and refunds after cancelling.' },
|
|
58
|
+
{ stage: 'prepare_request', message: 'Preparing the cancellation request.' }
|
|
59
|
+
];
|
|
60
|
+
const RESUME_STEPS = [
|
|
61
|
+
{ stage: 'check_options', message: 'Checking the options for undoing the cancellation.' },
|
|
62
|
+
{ stage: 'summarize_impact', message: 'Summarizing the automatic payments that resume.' },
|
|
63
|
+
{ stage: 'prepare_request', message: 'Preparing the request to undo the cancellation.' }
|
|
64
|
+
];
|
|
65
|
+
const PAY_STEPS = [
|
|
66
|
+
{ stage: 'check_options', message: 'Checking the payment options.' },
|
|
67
|
+
{ stage: 'check_consent', message: 'Checking the payment consent.' },
|
|
68
|
+
{ stage: 'prepare_request', message: 'Preparing the request to pay the unpaid charges.' }
|
|
69
|
+
];
|
|
70
|
+
const CANCEL_IMPACT = 'Cancelling ends the paid plan. If the current billing period\'s payment has been made, the plan stays until the day before the next billing date and deepdynamic plan resume can undo it. If it has not been made yet, the subscription ends now, the account is on free at once and it cannot be undone.';
|
|
71
|
+
const CANCEL_CONFIRM = { message: CANCEL_IMPACT, display: `${CANCEL_IMPACT} ${ASK}` };
|
|
72
|
+
const RESUMABLE = ['Undo', 'Run deepdynamic plan resume before the next billing date to undo the scheduled cancellation.'];
|
|
73
|
+
const CANCEL_ROWS = [
|
|
74
|
+
['Cancellation', 'If this billing period is paid, the current plan stays until the day before the next billing date and then returns to free.'],
|
|
75
|
+
['Unpaid period', 'If this billing period is not paid yet, the plan ends now and the account is on free from now on.'],
|
|
76
|
+
['Refund', 'Amounts already paid are not refunded.'],
|
|
77
|
+
RESUMABLE
|
|
78
|
+
];
|
|
79
|
+
const RESUME_ROWS = [
|
|
80
|
+
['Undo', 'Removes the scheduled cancellation, so the current plan continues.'],
|
|
81
|
+
['Auto-pay', 'From the next billing date, the registered card is charged on the same day every month again.']
|
|
82
|
+
];
|
|
83
|
+
const SUBSCRIBE_MESSAGES = {
|
|
84
|
+
subscribed: ({ plan }) => `Subscribed to the ${plan} plan.`,
|
|
85
|
+
upgraded: ({ plan, monthlyAmount }, charged) => `Upgraded to the ${plan} plan.${charged ? '' : ` The ${krw(monthlyAmount)} for this billing period is charged with the scheduled payment.`}`,
|
|
86
|
+
downgraded: ({ plan, monthlyAmount }) => `Downgraded to the ${plan} plan. Amounts already paid are not refunded, and ${krw(monthlyAmount)} a month is charged from the next scheduled payment.`,
|
|
87
|
+
resumed: ({ plan }) => `Undid the scheduled cancellation. The ${plan} plan continues.`,
|
|
88
|
+
unchanged: ({ plan }) => `Already on the ${plan} plan, so nothing was changed.`
|
|
89
|
+
};
|
|
90
|
+
const CANCEL_MESSAGES = {
|
|
91
|
+
scheduled: ({ plan, endsOn }) => `Scheduled the cancellation. The ${plan} plan stays until ${endsOn} and then returns to free.`,
|
|
92
|
+
cancelled: ({ plan }) => `Cancelled the ${plan} plan. This billing period was not paid yet, so it ended now and the account is on free.`,
|
|
93
|
+
unchanged: ({ plan, endsOn }) => `The cancellation is already scheduled. The ${plan} plan stays until ${endsOn}.`
|
|
94
|
+
};
|
|
95
|
+
const RESUME_MESSAGES = {
|
|
96
|
+
resumed: ({ plan }) => `Undid the scheduled cancellation. The ${plan} plan renews automatically next month.`,
|
|
97
|
+
unchanged: ({ plan }) => `No cancellation is scheduled, so nothing was changed. The ${plan} plan renews automatically every month.`
|
|
98
|
+
};
|
|
99
|
+
const succeeded = ({ status }) => status === 200;
|
|
100
|
+
const monthly = (plan, amount) => `${plan} · ${krw(amount)}/month`;
|
|
101
|
+
const planText = ({ plan, monthlyAmount }) => monthly(plan, monthlyAmount);
|
|
102
|
+
const cardText = ({ brand, last4, expMonth, expYear }) => `${brand} ····${last4} · expires ${String(expMonth).padStart(2, '0')}/${expYear}`;
|
|
103
|
+
const chargeText = ({ period, amount, status }) => `${period} · ${krw(amount)} · ${status}`;
|
|
104
|
+
const gb = (bytes) => `${Number((bytes / 1e9).toFixed(1))}GB`;
|
|
105
|
+
const bandwidthText = ({ period, usedBytes, limitBytes, limited }) => `${period} · ${gb(usedBytes)} / ${gb(limitBytes)}${limitBytes > 0 ? ` (${Math.floor((usedBytes * 100) / limitBytes)}%)` : ''}${limited ? ' · over the limit, sites are redirected to limited.deepdynamic.net' : ''}`;
|
|
106
|
+
function subscriptionText({ status, monthlyAmount, endsOn }) {
|
|
107
|
+
if (status === 'cancelled')
|
|
108
|
+
return 'Cancelled · free from now on';
|
|
109
|
+
return endsOn ? `Cancellation scheduled · stays until ${endsOn}, then free` : `${krw(monthlyAmount)} paid automatically every month`;
|
|
110
|
+
}
|
|
111
|
+
function parseSubscribe(args) {
|
|
112
|
+
const { args: plain, yes } = splitYes(args);
|
|
113
|
+
const [plan, ...extra] = plain;
|
|
114
|
+
if (plan === undefined || plan.startsWith('-'))
|
|
115
|
+
return { error: 'Specify the plan first: pro or team.' };
|
|
116
|
+
if (!Object.hasOwn(PRICES, plan))
|
|
117
|
+
return { error: `The plan must be pro or team: ${plan}. To return to free, run deepdynamic plan cancel.` };
|
|
118
|
+
if (extra.length)
|
|
119
|
+
return { error: unknownArgument(extra[0]) };
|
|
120
|
+
return { plan: plan, consented: yes };
|
|
121
|
+
}
|
|
122
|
+
function subscribeRows(plan, consented) {
|
|
123
|
+
return [
|
|
124
|
+
['Plan', monthly(plan, PRICES[plan])],
|
|
125
|
+
['Payment', 'Without a subscription, the first month is charged now and that date becomes the monthly billing day. Upgrading from pro to team charges the team price minus what was paid for this billing period now. Downgrading from team to pro applies at once with no charge or refund.'],
|
|
126
|
+
['Auto-pay', `After that, ${krw(PRICES[plan])} is charged to the registered card every month.`],
|
|
127
|
+
['Consent', consented ? 'Given (--yes). Any amount due now is charged at once.' : 'Required to subscribe or upgrade. Add --yes once the user agrees to the amount.']
|
|
128
|
+
];
|
|
129
|
+
}
|
|
130
|
+
function shown(command, pretty, depth, body, siteUrl) {
|
|
131
|
+
const { plan, subscription, card, charges, unpaid = { count: 0, amount: 0, charges: [] }, bandwidth } = body;
|
|
132
|
+
if (!pretty)
|
|
133
|
+
return agentResult(0, { command, siteUrl, plan, subscription, card, charges, unpaid, ...(bandwidth ? { bandwidth } : {}), currency: 'KRW' });
|
|
134
|
+
return prettyResult(0, depth, command, `The current plan is ${plan}.`, [
|
|
135
|
+
['Server', siteUrl],
|
|
136
|
+
['Plan', subscription ? planText(subscription) : plan],
|
|
137
|
+
['Subscription', subscription ? subscriptionText(subscription) : 'None'],
|
|
138
|
+
['Billing card', card ? cardText(card) : 'Not registered'],
|
|
139
|
+
['Last charge', charges.length ? chargeText(charges[0]) : 'None'],
|
|
140
|
+
['Unpaid', unpaid.count ? `${unpaidCharges(unpaid.count)} · ${krw(unpaid.amount)} · pay with deepdynamic plan pay` : 'None'],
|
|
141
|
+
...(bandwidth ? [['Bandwidth', bandwidthText(bandwidth)]] : [])
|
|
142
|
+
]);
|
|
143
|
+
}
|
|
144
|
+
function consentNeeded(command, args, pretty, depth, plan, { chargeNow, monthlyAmount, previousMonthlyAmount }) {
|
|
145
|
+
const subscribing = previousMonthlyAmount === 0;
|
|
146
|
+
const now = chargeNow ? `charges ${chargeNow} KRW now` : 'charges nothing now';
|
|
147
|
+
const charge = chargeNow ? `charges ${krw(chargeNow)} now` : 'charges nothing now';
|
|
148
|
+
return confirmationRequired(command, args, pretty, depth, subscribing
|
|
149
|
+
? {
|
|
150
|
+
message: `Subscribing to ${plan} ${now} and ${monthlyAmount} KRW every month after that, so it needs the user's consent.`,
|
|
151
|
+
display: `Subscribing to ${plan} ${charge} and ${krw(monthlyAmount)} automatically every month after that. ${ASK}`
|
|
152
|
+
}
|
|
153
|
+
: {
|
|
154
|
+
message: `Changing to ${plan} ${now} and raises the monthly payment from ${previousMonthlyAmount} to ${monthlyAmount} KRW, so it needs the user's consent.`,
|
|
155
|
+
display: `Changing to ${plan} ${charge} and raises the automatic monthly payment from ${krw(previousMonthlyAmount)} to ${krw(monthlyAmount)}. ${ASK}`
|
|
156
|
+
}, { plan, chargeNow, monthlyAmount, previousMonthlyAmount, currency: 'KRW' });
|
|
157
|
+
}
|
|
158
|
+
function declined(command, pretty, depth, siteUrl, reason, headline = SUBSCRIBE_FAILED) {
|
|
159
|
+
return pretty
|
|
160
|
+
? prettyResult(1, depth, command, headline, [['Server', siteUrl], ['Reason', DECLINED.display], ...(reason ? [['Issuer response', reason]] : [])])
|
|
161
|
+
: agentResult(1, { command, siteUrl, error: failureError(DECLINED), reason });
|
|
162
|
+
}
|
|
163
|
+
function subscribeAnswer(command, args, plan, pretty, depth) {
|
|
164
|
+
return ({ status, body }, siteUrl) => {
|
|
165
|
+
const answer = body;
|
|
166
|
+
if (status === 402 && answer?.code === 'payment_declined')
|
|
167
|
+
return declined(command, pretty, depth, siteUrl, typeof answer.reason === 'string' ? answer.reason : null);
|
|
168
|
+
if (status !== 400 || answer?.code !== 'consent_required')
|
|
169
|
+
return null;
|
|
170
|
+
const { chargeNow, monthlyAmount, previousMonthlyAmount } = answer;
|
|
171
|
+
if (typeof chargeNow !== 'number' || typeof monthlyAmount !== 'number' || typeof previousMonthlyAmount !== 'number')
|
|
172
|
+
return null;
|
|
173
|
+
return consentNeeded(command, args, pretty, depth, plan, { chargeNow, monthlyAmount, previousMonthlyAmount });
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
function payAnswer(command, args, pretty, depth) {
|
|
177
|
+
return ({ status, body }, siteUrl) => {
|
|
178
|
+
const answer = body;
|
|
179
|
+
if (status === 402 && answer?.code === 'payment_declined')
|
|
180
|
+
return declined(command, pretty, depth, siteUrl, typeof answer.reason === 'string' ? answer.reason : null, PAY_FAILED);
|
|
181
|
+
if (status !== 400 || answer?.code !== 'payment_consent_required' || !answer.unpaid)
|
|
182
|
+
return null;
|
|
183
|
+
const { count, amount } = answer.unpaid;
|
|
184
|
+
return confirmationRequired(command, args, pretty, depth, {
|
|
185
|
+
message: `Paying the unpaid charges charges ${amount} KRW for ${count} charge(s) to the billing card now, so it needs the user's consent.`,
|
|
186
|
+
display: `This pays ${unpaidCharges(count)}, ${krw(amount)} in total, with the registered card now. ${ASK}`
|
|
187
|
+
}, { unpaid: answer.unpaid, currency: 'KRW' });
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
function paid(command, pretty, depth, body, siteUrl) {
|
|
191
|
+
const { paid: charges, charged } = body;
|
|
192
|
+
if (!pretty)
|
|
193
|
+
return agentResult(0, { command, siteUrl, applied: true, paid: charges, charged, currency: 'KRW' });
|
|
194
|
+
return prettyResult(0, depth, command, `Paid ${unpaidCharges(charges.length)}, ${krw(charged)} in total.`, [
|
|
195
|
+
['Server', siteUrl],
|
|
196
|
+
...charges.map(({ period, amount }) => [period, krw(amount)])
|
|
197
|
+
]);
|
|
198
|
+
}
|
|
199
|
+
function subscribed(command, pretty, depth, body, siteUrl) {
|
|
200
|
+
const { result, charged, subscription } = body;
|
|
201
|
+
if (!pretty)
|
|
202
|
+
return agentResult(0, { command, siteUrl, applied: result !== 'unchanged', result, charged, currency: 'KRW', subscription });
|
|
203
|
+
return prettyResult(0, depth, command, SUBSCRIBE_MESSAGES[result](subscription, charged), [
|
|
204
|
+
['Server', siteUrl],
|
|
205
|
+
['Plan', planText(subscription)],
|
|
206
|
+
['Charged', charged ? krw(charged) : 'None'],
|
|
207
|
+
['Subscription', subscriptionText(subscription)]
|
|
208
|
+
]);
|
|
209
|
+
}
|
|
210
|
+
function cancelled(command, pretty, depth, body, siteUrl) {
|
|
211
|
+
const { result, subscription } = body;
|
|
212
|
+
if (!pretty)
|
|
213
|
+
return agentResult(0, { command, siteUrl, applied: result !== 'unchanged', result, currency: 'KRW', subscription });
|
|
214
|
+
return prettyResult(0, depth, command, CANCEL_MESSAGES[result](subscription), [
|
|
215
|
+
['Server', siteUrl],
|
|
216
|
+
['Cancelled plan', planText(subscription)],
|
|
217
|
+
['Subscription', subscriptionText(subscription)],
|
|
218
|
+
...(result === 'cancelled' ? [] : [RESUMABLE])
|
|
219
|
+
]);
|
|
220
|
+
}
|
|
221
|
+
function resumed(command, pretty, depth, body, siteUrl) {
|
|
222
|
+
const { result, subscription } = body;
|
|
223
|
+
if (!pretty)
|
|
224
|
+
return agentResult(0, { command, siteUrl, applied: result === 'resumed', result, currency: 'KRW', subscription });
|
|
225
|
+
return prettyResult(0, depth, command, RESUME_MESSAGES[result](subscription), [
|
|
226
|
+
['Server', siteUrl],
|
|
227
|
+
['Plan', planText(subscription)],
|
|
228
|
+
['Subscription', subscriptionText(subscription)]
|
|
229
|
+
]);
|
|
230
|
+
}
|
|
231
|
+
export async function runPlanShow(args, pretty, depth, deps = defaultAuthDeps(pretty, depth)) {
|
|
232
|
+
const command = SHOW.name;
|
|
233
|
+
return rehearsed(command, args, pretty, depth, deps, (rest) => {
|
|
234
|
+
if (rest.length)
|
|
235
|
+
return { error: unknownArgument(rest[0]) };
|
|
236
|
+
const url = (siteUrl) => new URL(PLAN_PATH, siteUrl).href;
|
|
237
|
+
return {
|
|
238
|
+
steps: SHOW_STEPS,
|
|
239
|
+
result: (siteUrl) => plannedRequest(command, pretty, depth, siteUrl, url(siteUrl)),
|
|
240
|
+
send: {
|
|
241
|
+
method: 'GET',
|
|
242
|
+
url,
|
|
243
|
+
spinner: 'Loading the plan details.',
|
|
244
|
+
failed: 'Could not load the plan details.',
|
|
245
|
+
notFound: httpFailure(404),
|
|
246
|
+
failures: { unavailable: UNAVAILABLE },
|
|
247
|
+
succeeded,
|
|
248
|
+
done: (body, siteUrl) => shown(command, pretty, depth, body, siteUrl)
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
export async function runPlanSubscribe(args, pretty, depth, deps = defaultAuthDeps(pretty, depth)) {
|
|
254
|
+
const command = SUBSCRIBE.name;
|
|
255
|
+
return rehearsed(command, args, pretty, depth, deps, (rest) => {
|
|
256
|
+
const parsed = parseSubscribe(rest);
|
|
257
|
+
if ('error' in parsed)
|
|
258
|
+
return parsed;
|
|
259
|
+
const { plan, consented } = parsed;
|
|
260
|
+
const body = { plan, ...(consented ? { consented: true } : {}) };
|
|
261
|
+
const url = (siteUrl) => new URL(SUBSCRIPTION_PATH, siteUrl).href;
|
|
262
|
+
return {
|
|
263
|
+
steps: SUBSCRIBE_STEPS,
|
|
264
|
+
result: (siteUrl) => plannedChange(command, pretty, depth, siteUrl, { url: url(siteUrl), body }, 'Checked the plan change. Nothing was charged.', subscribeRows(plan, consented), { plan, monthlyAmount: PRICES[plan], currency: 'KRW', consentRequired: true, consented }),
|
|
265
|
+
send: {
|
|
266
|
+
method: 'POST',
|
|
267
|
+
url,
|
|
268
|
+
body,
|
|
269
|
+
spinner: 'Changing the plan.',
|
|
270
|
+
failed: SUBSCRIBE_FAILED,
|
|
271
|
+
notFound: httpFailure(404),
|
|
272
|
+
failures: SUBSCRIBE_FAILURES,
|
|
273
|
+
intercept: subscribeAnswer(command, rest, plan, pretty, depth),
|
|
274
|
+
succeeded,
|
|
275
|
+
done: (result, siteUrl) => subscribed(command, pretty, depth, result, siteUrl)
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
export async function runPlanCancel(args, pretty, depth, deps = defaultAuthDeps(pretty, depth)) {
|
|
281
|
+
const command = CANCEL.name;
|
|
282
|
+
const consented = splitYes(args).yes;
|
|
283
|
+
return rehearsed(command, args, pretty, depth, deps, (rest) => {
|
|
284
|
+
if (rest.length)
|
|
285
|
+
return { error: unknownArgument(rest[0]) };
|
|
286
|
+
const url = (siteUrl) => new URL(`${SUBSCRIPTION_PATH}/cancel`, siteUrl).href;
|
|
287
|
+
return {
|
|
288
|
+
steps: CANCEL_STEPS,
|
|
289
|
+
result: (siteUrl) => plannedChange(command, pretty, depth, siteUrl, { url: url(siteUrl), body: {} }, 'Checked the cancellation. The plan was not cancelled.', [...CANCEL_ROWS, ['Consent', consented ? 'Given (--yes).' : 'Required. Confirm with the user, then add --yes.']], { autoRenew: false, refund: false, consented }),
|
|
290
|
+
send: {
|
|
291
|
+
method: 'POST',
|
|
292
|
+
url,
|
|
293
|
+
body: {},
|
|
294
|
+
spinner: 'Cancelling the plan.',
|
|
295
|
+
failed: 'Could not cancel the plan.',
|
|
296
|
+
notFound: httpFailure(404),
|
|
297
|
+
failures: { unavailable: CHANGE_UNAVAILABLE, charge_pending: CHARGE_PENDING, no_subscription: NO_SUBSCRIPTION },
|
|
298
|
+
succeeded,
|
|
299
|
+
done: (body, siteUrl) => cancelled(command, pretty, depth, body, siteUrl)
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
}, CANCEL_CONFIRM);
|
|
303
|
+
}
|
|
304
|
+
export async function runPlanResume(args, pretty, depth, deps = defaultAuthDeps(pretty, depth)) {
|
|
305
|
+
const command = RESUME.name;
|
|
306
|
+
return rehearsed(command, args, pretty, depth, deps, (rest) => {
|
|
307
|
+
if (rest.length)
|
|
308
|
+
return { error: unknownArgument(rest[0]) };
|
|
309
|
+
const url = (siteUrl) => new URL(`${SUBSCRIPTION_PATH}/resume`, siteUrl).href;
|
|
310
|
+
return {
|
|
311
|
+
steps: RESUME_STEPS,
|
|
312
|
+
result: (siteUrl) => plannedChange(command, pretty, depth, siteUrl, { url: url(siteUrl), body: {} }, 'Checked undoing the cancellation. Nothing was changed.', RESUME_ROWS, { autoRenew: true }),
|
|
313
|
+
send: {
|
|
314
|
+
method: 'POST',
|
|
315
|
+
url,
|
|
316
|
+
body: {},
|
|
317
|
+
spinner: 'Undoing the scheduled cancellation.',
|
|
318
|
+
failed: 'Could not undo the scheduled cancellation.',
|
|
319
|
+
notFound: httpFailure(404),
|
|
320
|
+
failures: { unavailable: CHANGE_UNAVAILABLE, no_subscription: NO_SUBSCRIPTION },
|
|
321
|
+
succeeded,
|
|
322
|
+
done: (body, siteUrl) => resumed(command, pretty, depth, body, siteUrl)
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
export async function runPlanPay(args, pretty, depth, deps = defaultAuthDeps(pretty, depth)) {
|
|
328
|
+
const command = PAY.name;
|
|
329
|
+
return rehearsed(command, args, pretty, depth, deps, (rest) => {
|
|
330
|
+
const { args: extra, yes } = splitYes(rest);
|
|
331
|
+
if (extra.length)
|
|
332
|
+
return { error: unknownArgument(extra[0]) };
|
|
333
|
+
const body = yes ? { consented: true } : {};
|
|
334
|
+
const url = (siteUrl) => new URL(PAY_PATH, siteUrl).href;
|
|
335
|
+
return {
|
|
336
|
+
steps: PAY_STEPS,
|
|
337
|
+
result: (siteUrl) => plannedChange(command, pretty, depth, siteUrl, { url: url(siteUrl), body }, 'Checked paying the unpaid charges. Nothing was charged.', [
|
|
338
|
+
['Payment', 'Charges the unpaid monthly charges to the registered card now, oldest month first.'],
|
|
339
|
+
['Consent', yes ? 'Given (--yes).' : 'Required. Confirm the amount with the user, then add --yes.']
|
|
340
|
+
], { currency: 'KRW', consentRequired: true, consented: yes }),
|
|
341
|
+
send: {
|
|
342
|
+
method: 'POST',
|
|
343
|
+
url,
|
|
344
|
+
body,
|
|
345
|
+
spinner: 'Paying the unpaid charges.',
|
|
346
|
+
failed: PAY_FAILED,
|
|
347
|
+
notFound: NO_UNPAID,
|
|
348
|
+
failures: { unavailable: CHANGE_UNAVAILABLE, charge_pending: CHARGE_PENDING, no_unpaid: NO_UNPAID, payment_unavailable: SUBSCRIBE_FAILURES.payment_unavailable },
|
|
349
|
+
intercept: payAnswer(command, rest, pretty, depth),
|
|
350
|
+
succeeded,
|
|
351
|
+
done: (result, siteUrl) => paid(command, pretty, depth, result, siteUrl)
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
});
|
|
355
|
+
}
|