@deepdynamic/cli 0.0.0-stage → 0.1.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.
Files changed (82) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +32 -2
  3. package/THIRD_PARTY_NOTICES.txt +102 -0
  4. package/dist/agents/content.js +12 -0
  5. package/dist/agents/edit.js +140 -0
  6. package/dist/agents/install.js +180 -0
  7. package/dist/agents/setup.js +29 -0
  8. package/dist/agents/targets.js +91 -0
  9. package/dist/auth/credentials.js +63 -0
  10. package/dist/auth/session.js +49 -0
  11. package/dist/cli.js +198 -0
  12. package/dist/commands/account.js +96 -0
  13. package/dist/commands/activity.js +80 -0
  14. package/dist/commands/blocked.js +89 -0
  15. package/dist/commands/deploy/agents.js +11 -0
  16. package/dist/commands/deploy/files.js +62 -0
  17. package/dist/commands/deploy/index.js +95 -0
  18. package/dist/commands/deploy/manifest.js +24 -0
  19. package/dist/commands/deploy/minify.js +27 -0
  20. package/dist/commands/deploy/progress.js +85 -0
  21. package/dist/commands/deploy/ship.js +117 -0
  22. package/dist/commands/deploy/upload.js +125 -0
  23. package/dist/commands/deployments.js +59 -0
  24. package/dist/commands/dns.js +791 -0
  25. package/dist/commands/domains.js +711 -0
  26. package/dist/commands/emails.js +74 -0
  27. package/dist/commands/env.js +194 -0
  28. package/dist/commands/help.js +149 -0
  29. package/dist/commands/keys.js +269 -0
  30. package/dist/commands/login/flow.js +155 -0
  31. package/dist/commands/login/index.js +26 -0
  32. package/dist/commands/logout.js +71 -0
  33. package/dist/commands/mail.js +241 -0
  34. package/dist/commands/notifications.js +132 -0
  35. package/dist/commands/plan.js +371 -0
  36. package/dist/commands/projects.js +836 -0
  37. package/dist/commands/reference.js +2180 -0
  38. package/dist/commands/search.js +75 -0
  39. package/dist/commands/server.js +314 -0
  40. package/dist/commands/sessions.js +120 -0
  41. package/dist/commands/sites.js +102 -0
  42. package/dist/commands/sms.js +65 -0
  43. package/dist/commands/status.js +87 -0
  44. package/dist/commands/support.js +115 -0
  45. package/dist/commands/update.js +98 -0
  46. package/dist/commands/usage.js +51 -0
  47. package/dist/commands/verify.js +149 -0
  48. package/dist/commands/version.js +6 -0
  49. package/dist/guide.js +76 -0
  50. package/dist/http/call.js +6 -0
  51. package/dist/http/request.js +54 -0
  52. package/dist/index.js +11 -0
  53. package/dist/metadata.js +4 -0
  54. package/dist/output.js +9 -0
  55. package/dist/pretty.js +70 -0
  56. package/dist/registry.js +760 -0
  57. package/dist/runtime/browser.js +15 -0
  58. package/dist/runtime/card-request.js +55 -0
  59. package/dist/runtime/confirm.js +21 -0
  60. package/dist/runtime/development.js +13 -0
  61. package/dist/runtime/domain-name.js +5 -0
  62. package/dist/runtime/dry-run.js +28 -0
  63. package/dist/runtime/env-file.js +58 -0
  64. package/dist/runtime/error-hints.js +26 -0
  65. package/dist/runtime/flags.js +50 -0
  66. package/dist/runtime/login-screen.js +78 -0
  67. package/dist/runtime/page.js +18 -0
  68. package/dist/runtime/project-name.js +1 -0
  69. package/dist/runtime/run-mode.js +7 -0
  70. package/dist/runtime/server-options.js +32 -0
  71. package/dist/runtime/spinner.js +15 -0
  72. package/dist/runtime/suggest.js +22 -0
  73. package/dist/runtime/support.js +14 -0
  74. package/dist/runtime/text-file.js +20 -0
  75. package/dist/runtime/timeout.js +22 -0
  76. package/dist/runtime/update-check.js +124 -0
  77. package/dist/runtime/update-install.js +50 -0
  78. package/dist/runtime/usage-error.js +9 -0
  79. package/dist/setup-agents.js +8 -0
  80. package/dist/site.js +1 -0
  81. package/dist/update-refresh.js +5 -0
  82. package/package.json +46 -3
@@ -0,0 +1,371 @@
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 { fail, 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 = '미결제 요금을 결제하지 못했습니다.';
21
+ const SUBSCRIBE_FAILED = '요금제를 바꾸지 못했습니다.';
22
+ const CHARGE_STATES = { paid: '결제됨', pending: '처리 중', failed: '실패', waived: '면제' };
23
+ const won = (amount) => `${amount.toLocaleString('ko-KR')}원`;
24
+ const UNAVAILABLE = supportFailure('unavailable');
25
+ const CHANGE_UNAVAILABLE = supportFailure('unavailable', {
26
+ note: { en: 'The change may already have been applied, so check deepdynamic plan before retrying.', ko: '이미 반영됐을 수 있으니 deepdynamic plan 으로 확인한 뒤 다시 시도하세요.' }
27
+ });
28
+ const CHARGE_PENDING = {
29
+ code: 'charge_pending',
30
+ message: '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
+ display: '처리 중인 결제가 있어 바꾸지 않았습니다. 잠시 뒤 deepdynamic plan 으로 확인하세요.'
32
+ };
33
+ const NO_SUBSCRIPTION = {
34
+ code: 'no_subscription',
35
+ message: 'The account has no paid subscription, so nothing was changed. Check it with deepdynamic plan.',
36
+ display: '이용 중인 유료 요금제가 없습니다. deepdynamic plan 으로 확인하세요.'
37
+ };
38
+ const DECLINED = {
39
+ code: 'payment_declined',
40
+ 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.',
41
+ display: '카드사가 결제를 거절해 결제하지 않았습니다. 카드를 확인하거나 다른 카드를 등록한 뒤 다시 시도하세요.'
42
+ };
43
+ const NO_UNPAID = {
44
+ code: 'no_unpaid',
45
+ message: 'The account has no unpaid charge, so nothing was charged. Check it with deepdynamic plan.',
46
+ display: '결제되지 않은 요금이 없습니다. deepdynamic plan 으로 확인하세요.'
47
+ };
48
+ const SUBSCRIBE_FAILURES = {
49
+ unavailable: CHANGE_UNAVAILABLE,
50
+ charge_pending: CHARGE_PENDING,
51
+ invalid_plan: {
52
+ code: 'invalid_plan',
53
+ message: 'The server accepts only pro or team as the plan, so nothing was changed.',
54
+ display: '요금제는 pro 나 team 만 지정할 수 있습니다.'
55
+ },
56
+ payment_unavailable: supportFailure('payment_unavailable', { note: { en: 'Nothing was charged or changed.', ko: '결제하지 않았습니다.' } })
57
+ };
58
+ const SHOW_STEPS = [
59
+ { stage: 'check_options', message: '조회 옵션을 확인하고 있습니다.' },
60
+ { stage: 'prepare_request', message: '요금제 조회 요청을 준비하고 있습니다.' }
61
+ ];
62
+ const SUBSCRIBE_STEPS = [
63
+ { stage: 'check_options', message: '요금제 옵션을 확인하고 있습니다.' },
64
+ { stage: 'calculate_charge', message: '요금제 월 요금을 계산하고 있습니다.' },
65
+ { stage: 'check_consent', message: '결제 동의를 확인하고 있습니다.' },
66
+ { stage: 'prepare_request', message: '요금제 변경 요청을 준비하고 있습니다.' }
67
+ ];
68
+ const CANCEL_STEPS = [
69
+ { stage: 'check_options', message: '해지 옵션을 확인하고 있습니다.' },
70
+ { stage: 'summarize_impact', message: '해지 뒤 이용 기간과 환불을 정리하고 있습니다.' },
71
+ { stage: 'prepare_request', message: '요금제 해지 요청을 준비하고 있습니다.' }
72
+ ];
73
+ const RESUME_STEPS = [
74
+ { stage: 'check_options', message: '해지 취소 옵션을 확인하고 있습니다.' },
75
+ { stage: 'summarize_impact', message: '다시 이어질 자동 결제를 정리하고 있습니다.' },
76
+ { stage: 'prepare_request', message: '해지 취소 요청을 준비하고 있습니다.' }
77
+ ];
78
+ const PAY_STEPS = [
79
+ { stage: 'check_options', message: '결제 옵션을 확인하고 있습니다.' },
80
+ { stage: 'check_consent', message: '결제 동의를 확인하고 있습니다.' },
81
+ { stage: 'prepare_request', message: '미결제 요금 결제 요청을 준비하고 있습니다.' }
82
+ ];
83
+ const CANCEL_CONFIRM = {
84
+ message: '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.',
85
+ display: '해지하면 유료 요금제가 끝납니다. 이번 결제 기간 요금을 결제했으면 다음 결제일 전날까지 쓰고 deepdynamic plan resume 으로 되돌릴 수 있지만, 아직 결제하지 않았으면 바로 끝나 free 가 되고 되돌릴 수 없습니다. 사용자에게 확인한 뒤 --yes 를 붙여 실행하세요.'
86
+ };
87
+ const RESUMABLE = ['되돌리기', '다음 결제일이 되기 전에 deepdynamic plan resume 으로 해지 예약을 취소할 수 있습니다.'];
88
+ const CANCEL_ROWS = [
89
+ ['해지', '이번 결제 기간 요금을 결제했으면 다음 결제일 전날까지 지금 요금제를 쓰고 그다음 free 로 돌아갑니다.'],
90
+ ['결제 전', '이번 결제 기간 요금을 아직 결제하지 않았으면 바로 끝나고 지금부터 free 입니다.'],
91
+ ['환불', '이미 결제한 금액은 환불되지 않습니다.'],
92
+ RESUMABLE
93
+ ];
94
+ const RESUME_ROWS = [
95
+ ['해지 취소', '해지 예약을 없애 지금 요금제를 계속 씁니다.'],
96
+ ['자동 결제', '다음 결제일부터 다시 매달 같은 날 등록한 카드로 결제됩니다.']
97
+ ];
98
+ const SUBSCRIBE_MESSAGES = {
99
+ subscribed: ({ plan }) => `${plan} 요금제를 구독했습니다.`,
100
+ upgraded: ({ plan, monthlyAmount }, charged) => `${plan} 요금제로 올렸습니다.${charged ? '' : ` 이번 결제 기간 요금은 정기 결제 때 ${won(monthlyAmount)}으로 결제됩니다.`}`,
101
+ downgraded: ({ plan, monthlyAmount }) => `${plan} 요금제로 낮췄습니다. 이미 결제한 금액은 환불되지 않고 다음 정기 결제부터 월 ${won(monthlyAmount)}이 결제됩니다.`,
102
+ resumed: ({ plan }) => `해지 예약을 취소했습니다. ${plan} 요금제를 계속 씁니다.`,
103
+ unchanged: ({ plan }) => `이미 ${plan} 요금제를 쓰고 있어 바꾸지 않았습니다.`
104
+ };
105
+ const CANCEL_MESSAGES = {
106
+ scheduled: ({ plan, endsOn }) => `해지를 예약했습니다. ${endsOn}까지 ${plan} 요금제를 쓰고 그다음 free 로 돌아갑니다.`,
107
+ cancelled: ({ plan }) => `${plan} 요금제를 해지했습니다. 이번 결제 기간 요금을 결제하기 전이라 바로 끝났고 지금부터 free 입니다.`,
108
+ unchanged: ({ plan, endsOn }) => `이미 해지를 예약해 두었습니다. ${endsOn}까지 ${plan} 요금제를 씁니다.`
109
+ };
110
+ const RESUME_MESSAGES = {
111
+ resumed: ({ plan }) => `해지 예약을 취소했습니다. ${plan} 요금제가 다음 달에도 자동 결제됩니다.`,
112
+ unchanged: ({ plan }) => `해지 예약이 없어 바꾸지 않았습니다. ${plan} 요금제가 매달 자동 결제되고 있습니다.`
113
+ };
114
+ const succeeded = ({ status }) => status === 200;
115
+ const planText = ({ plan, monthlyAmount }) => `${plan} · 월 ${won(monthlyAmount)}`;
116
+ const cardText = ({ brand, last4, expMonth, expYear }) => `${brand} ····${last4} · 유효기간 ${String(expMonth).padStart(2, '0')}/${expYear}`;
117
+ const chargeText = ({ period, amount, status }) => `${period} · ${won(amount)} · ${CHARGE_STATES[status] ?? status}`;
118
+ const gb = (bytes) => `${Number((bytes / 1e9).toFixed(1))}GB`;
119
+ const bandwidthText = ({ period, usedBytes, limitBytes, limited }) => `${period} · ${gb(usedBytes)} / ${gb(limitBytes)}${limitBytes > 0 ? ` (${Math.floor((usedBytes * 100) / limitBytes)}%)` : ''}${limited ? ' · 한도를 넘어 사이트를 limited.deepdynamic.net 으로 돌리는 중' : ''}`;
120
+ function subscriptionText({ status, monthlyAmount, endsOn }) {
121
+ if (status === 'cancelled')
122
+ return '해지됨 · 지금부터 free';
123
+ return endsOn ? `해지 예약됨 · ${endsOn}까지 쓰고 free 로 돌아감` : `매달 ${won(monthlyAmount)} 자동 결제`;
124
+ }
125
+ function parseSubscribe(args, pretty) {
126
+ const { args: plain, yes } = splitYes(args);
127
+ const [plan, ...extra] = plain;
128
+ if (plan === undefined || plan.startsWith('-'))
129
+ return fail(pretty, 'Specify the plan first: pro or team.', '요금제(pro 또는 team)를 먼저 지정하세요.');
130
+ if (!Object.hasOwn(PRICES, plan)) {
131
+ return fail(pretty, `The plan must be pro or team: ${plan}. To return to free, run deepdynamic plan cancel.`, `요금제에는 pro 나 team 을 지정하세요: ${plan}. free 로 돌아가려면 deepdynamic plan cancel 을 실행하세요.`);
132
+ }
133
+ if (extra.length)
134
+ return { error: unknownArgument(extra[0], pretty) };
135
+ return { plan: plan, consented: yes };
136
+ }
137
+ function subscribeRows(plan, consented) {
138
+ return [
139
+ ['요금제', `${plan} · 월 ${won(PRICES[plan])}`],
140
+ ['결제', '구독 중이 아니면 첫 달 요금을 지금 결제하고, 그 날짜가 매달 결제일이 됩니다. pro 에서 team 으로 올리면 이번 결제 기간에 결제한 금액을 뺀 차액을 지금 결제하고, team 에서 pro 로 낮추면 결제·환불 없이 바로 바뀝니다.'],
141
+ ['자동 결제', `그다음부터 매달 ${won(PRICES[plan])}이 등록한 카드로 결제됩니다.`],
142
+ ['결제 동의', consented ? '동의함 (--yes). 지금 결제할 금액이 있으면 바로 결제됩니다.' : '구독하거나 올릴 때 필요합니다. 금액에 동의하면 --yes 를 붙이세요.']
143
+ ];
144
+ }
145
+ function shown(command, pretty, depth, body, siteUrl) {
146
+ const { plan, subscription, card, charges, unpaid = { count: 0, amount: 0, charges: [] }, bandwidth } = body;
147
+ if (!pretty)
148
+ return agentResult(0, { command, siteUrl, plan, subscription, card, charges, unpaid, ...(bandwidth ? { bandwidth } : {}), currency: 'KRW' });
149
+ return prettyResult(0, depth, command, `지금 요금제는 ${plan}입니다.`, [
150
+ ['서버', siteUrl],
151
+ ['요금제', subscription ? planText(subscription) : plan],
152
+ ['구독', subscription ? subscriptionText(subscription) : '없음'],
153
+ ['결제 카드', card ? cardText(card) : '등록되지 않음'],
154
+ ['최근 결제', charges.length ? chargeText(charges[0]) : '없음'],
155
+ ['미결제', unpaid.count ? `${unpaid.count}건 · ${won(unpaid.amount)} · deepdynamic plan pay 로 결제` : '없음'],
156
+ ...(bandwidth ? [['대역폭', bandwidthText(bandwidth)]] : [])
157
+ ]);
158
+ }
159
+ function consentNeeded(command, args, pretty, depth, plan, { chargeNow, monthlyAmount, previousMonthlyAmount }) {
160
+ const subscribing = previousMonthlyAmount === 0;
161
+ const now = chargeNow ? `charges ${chargeNow} KRW now` : 'charges nothing now';
162
+ const charge = chargeNow ? `지금 ${won(chargeNow)}이 결제되고` : '지금 결제되는 금액은 없고';
163
+ const ask = '사용자에게 확인한 뒤 --yes 를 붙여 실행하세요.';
164
+ return confirmationRequired(command, args, pretty, depth, subscribing
165
+ ? {
166
+ message: `Subscribing to ${plan} ${now} and ${monthlyAmount} KRW every month after that, so it needs the user's consent.`,
167
+ display: `${plan} 요금제를 구독하면 ${charge} 매달 ${won(monthlyAmount)}이 자동 결제됩니다. ${ask}`
168
+ }
169
+ : {
170
+ message: `Changing to ${plan} ${now} and raises the monthly payment from ${previousMonthlyAmount} to ${monthlyAmount} KRW, so it needs the user's consent.`,
171
+ display: `${plan} 요금제로 바꾸면 ${charge} 매달 자동 결제 금액이 ${won(previousMonthlyAmount)}에서 ${won(monthlyAmount)}으로 늘어납니다. ${ask}`
172
+ }, { plan, chargeNow, monthlyAmount, previousMonthlyAmount, currency: 'KRW' });
173
+ }
174
+ function declined(command, pretty, depth, siteUrl, reason, headline = SUBSCRIBE_FAILED) {
175
+ return pretty
176
+ ? prettyResult(1, depth, command, headline, [['서버', siteUrl], ['원인', DECLINED.display], ...(reason ? [['카드사 응답', reason]] : [])])
177
+ : agentResult(1, { command, siteUrl, error: failureError(DECLINED), reason });
178
+ }
179
+ function subscribeAnswer(command, args, plan, pretty, depth) {
180
+ return ({ status, body }, siteUrl) => {
181
+ const answer = body;
182
+ if (status === 402 && answer?.code === 'payment_declined')
183
+ return declined(command, pretty, depth, siteUrl, typeof answer.reason === 'string' ? answer.reason : null);
184
+ if (status !== 400 || answer?.code !== 'consent_required')
185
+ return null;
186
+ const { chargeNow, monthlyAmount, previousMonthlyAmount } = answer;
187
+ if (typeof chargeNow !== 'number' || typeof monthlyAmount !== 'number' || typeof previousMonthlyAmount !== 'number')
188
+ return null;
189
+ return consentNeeded(command, args, pretty, depth, plan, { chargeNow, monthlyAmount, previousMonthlyAmount });
190
+ };
191
+ }
192
+ function payAnswer(command, args, pretty, depth) {
193
+ return ({ status, body }, siteUrl) => {
194
+ const answer = body;
195
+ if (status === 402 && answer?.code === 'payment_declined')
196
+ return declined(command, pretty, depth, siteUrl, typeof answer.reason === 'string' ? answer.reason : null, PAY_FAILED);
197
+ if (status !== 400 || answer?.code !== 'payment_consent_required' || !answer.unpaid)
198
+ return null;
199
+ const { count, amount } = answer.unpaid;
200
+ return confirmationRequired(command, args, pretty, depth, {
201
+ message: `Paying the unpaid charges charges ${amount} KRW for ${count} charge(s) to the billing card now, so it needs the user's consent.`,
202
+ display: `결제되지 않은 요금 ${count}건 ${won(amount)}이 등록한 카드로 지금 결제됩니다. 사용자에게 확인한 뒤 --yes 를 붙여 실행하세요.`
203
+ }, { unpaid: answer.unpaid, currency: 'KRW' });
204
+ };
205
+ }
206
+ function paid(command, pretty, depth, body, siteUrl) {
207
+ const { paid: charges, charged } = body;
208
+ if (!pretty)
209
+ return agentResult(0, { command, siteUrl, applied: true, paid: charges, charged, currency: 'KRW' });
210
+ return prettyResult(0, depth, command, `미결제 요금 ${charges.length}건 ${won(charged)}을 결제했습니다.`, [
211
+ ['서버', siteUrl],
212
+ ...charges.map(({ period, amount }) => [period, won(amount)])
213
+ ]);
214
+ }
215
+ function subscribed(command, pretty, depth, body, siteUrl) {
216
+ const { result, charged, subscription } = body;
217
+ if (!pretty)
218
+ return agentResult(0, { command, siteUrl, applied: result !== 'unchanged', result, charged, currency: 'KRW', subscription });
219
+ return prettyResult(0, depth, command, SUBSCRIBE_MESSAGES[result](subscription, charged), [
220
+ ['서버', siteUrl],
221
+ ['요금제', planText(subscription)],
222
+ ['결제한 금액', charged ? won(charged) : '없음'],
223
+ ['구독', subscriptionText(subscription)]
224
+ ]);
225
+ }
226
+ function cancelled(command, pretty, depth, body, siteUrl) {
227
+ const { result, subscription } = body;
228
+ if (!pretty)
229
+ return agentResult(0, { command, siteUrl, applied: result !== 'unchanged', result, currency: 'KRW', subscription });
230
+ return prettyResult(0, depth, command, CANCEL_MESSAGES[result](subscription), [
231
+ ['서버', siteUrl],
232
+ ['해지한 요금제', planText(subscription)],
233
+ ['구독', subscriptionText(subscription)],
234
+ ...(result === 'cancelled' ? [] : [RESUMABLE])
235
+ ]);
236
+ }
237
+ function resumed(command, pretty, depth, body, siteUrl) {
238
+ const { result, subscription } = body;
239
+ if (!pretty)
240
+ return agentResult(0, { command, siteUrl, applied: result === 'resumed', result, currency: 'KRW', subscription });
241
+ return prettyResult(0, depth, command, RESUME_MESSAGES[result](subscription), [
242
+ ['서버', siteUrl],
243
+ ['요금제', planText(subscription)],
244
+ ['구독', subscriptionText(subscription)]
245
+ ]);
246
+ }
247
+ export async function runPlanShow(args, pretty, depth, deps = defaultAuthDeps(pretty, depth)) {
248
+ const command = SHOW.name;
249
+ return rehearsed(command, args, pretty, depth, deps, (rest) => {
250
+ if (rest.length)
251
+ return { error: unknownArgument(rest[0], pretty) };
252
+ const url = (siteUrl) => new URL(PLAN_PATH, siteUrl).href;
253
+ return {
254
+ steps: SHOW_STEPS,
255
+ result: (siteUrl) => plannedRequest(command, pretty, depth, siteUrl, url(siteUrl)),
256
+ send: {
257
+ method: 'GET',
258
+ url,
259
+ spinner: '요금제 정보를 불러오고 있습니다.',
260
+ failed: '요금제 정보를 불러오지 못했습니다.',
261
+ notFound: httpFailure(404),
262
+ failures: { unavailable: UNAVAILABLE },
263
+ succeeded,
264
+ done: (body, siteUrl) => shown(command, pretty, depth, body, siteUrl)
265
+ }
266
+ };
267
+ });
268
+ }
269
+ export async function runPlanSubscribe(args, pretty, depth, deps = defaultAuthDeps(pretty, depth)) {
270
+ const command = SUBSCRIBE.name;
271
+ return rehearsed(command, args, pretty, depth, deps, (rest) => {
272
+ const parsed = parseSubscribe(rest, pretty);
273
+ if ('error' in parsed)
274
+ return parsed;
275
+ const { plan, consented } = parsed;
276
+ const body = { plan, ...(consented ? { consented: true } : {}) };
277
+ const url = (siteUrl) => new URL(SUBSCRIPTION_PATH, siteUrl).href;
278
+ return {
279
+ steps: SUBSCRIBE_STEPS,
280
+ result: (siteUrl) => plannedChange(command, pretty, depth, siteUrl, { url: url(siteUrl), body }, '요금제 변경을 확인했습니다. 결제하지 않았습니다.', subscribeRows(plan, consented), { plan, monthlyAmount: PRICES[plan], currency: 'KRW', consentRequired: true, consented }),
281
+ send: {
282
+ method: 'POST',
283
+ url,
284
+ body,
285
+ spinner: '요금제를 바꾸고 있습니다.',
286
+ failed: SUBSCRIBE_FAILED,
287
+ notFound: httpFailure(404),
288
+ failures: SUBSCRIBE_FAILURES,
289
+ intercept: subscribeAnswer(command, rest, plan, pretty, depth),
290
+ succeeded,
291
+ done: (result, siteUrl) => subscribed(command, pretty, depth, result, siteUrl)
292
+ }
293
+ };
294
+ });
295
+ }
296
+ export async function runPlanCancel(args, pretty, depth, deps = defaultAuthDeps(pretty, depth)) {
297
+ const command = CANCEL.name;
298
+ const consented = splitYes(args).yes;
299
+ return rehearsed(command, args, pretty, depth, deps, (rest) => {
300
+ if (rest.length)
301
+ return { error: unknownArgument(rest[0], pretty) };
302
+ const url = (siteUrl) => new URL(`${SUBSCRIPTION_PATH}/cancel`, siteUrl).href;
303
+ return {
304
+ steps: CANCEL_STEPS,
305
+ result: (siteUrl) => plannedChange(command, pretty, depth, siteUrl, { url: url(siteUrl), body: {} }, '요금제 해지를 확인했습니다. 해지하지 않았습니다.', [...CANCEL_ROWS, ['해지 동의', consented ? '동의함 (--yes).' : '필요합니다. 사용자에게 확인한 뒤 --yes 를 붙이세요.']], { autoRenew: false, refund: false, consented }),
306
+ send: {
307
+ method: 'POST',
308
+ url,
309
+ body: {},
310
+ spinner: '요금제를 해지하고 있습니다.',
311
+ failed: '요금제를 해지하지 못했습니다.',
312
+ notFound: httpFailure(404),
313
+ failures: { unavailable: CHANGE_UNAVAILABLE, charge_pending: CHARGE_PENDING, no_subscription: NO_SUBSCRIPTION },
314
+ succeeded,
315
+ done: (body, siteUrl) => cancelled(command, pretty, depth, body, siteUrl)
316
+ }
317
+ };
318
+ }, CANCEL_CONFIRM);
319
+ }
320
+ export async function runPlanResume(args, pretty, depth, deps = defaultAuthDeps(pretty, depth)) {
321
+ const command = RESUME.name;
322
+ return rehearsed(command, args, pretty, depth, deps, (rest) => {
323
+ if (rest.length)
324
+ return { error: unknownArgument(rest[0], pretty) };
325
+ const url = (siteUrl) => new URL(`${SUBSCRIPTION_PATH}/resume`, siteUrl).href;
326
+ return {
327
+ steps: RESUME_STEPS,
328
+ result: (siteUrl) => plannedChange(command, pretty, depth, siteUrl, { url: url(siteUrl), body: {} }, '해지 취소를 확인했습니다. 바꾸지 않았습니다.', RESUME_ROWS, { autoRenew: true }),
329
+ send: {
330
+ method: 'POST',
331
+ url,
332
+ body: {},
333
+ spinner: '해지 예약을 취소하고 있습니다.',
334
+ failed: '해지 예약을 취소하지 못했습니다.',
335
+ notFound: httpFailure(404),
336
+ failures: { unavailable: CHANGE_UNAVAILABLE, no_subscription: NO_SUBSCRIPTION },
337
+ succeeded,
338
+ done: (body, siteUrl) => resumed(command, pretty, depth, body, siteUrl)
339
+ }
340
+ };
341
+ });
342
+ }
343
+ export async function runPlanPay(args, pretty, depth, deps = defaultAuthDeps(pretty, depth)) {
344
+ const command = PAY.name;
345
+ return rehearsed(command, args, pretty, depth, deps, (rest) => {
346
+ const { args: extra, yes } = splitYes(rest);
347
+ if (extra.length)
348
+ return { error: unknownArgument(extra[0], pretty) };
349
+ const body = yes ? { consented: true } : {};
350
+ const url = (siteUrl) => new URL(PAY_PATH, siteUrl).href;
351
+ return {
352
+ steps: PAY_STEPS,
353
+ result: (siteUrl) => plannedChange(command, pretty, depth, siteUrl, { url: url(siteUrl), body }, '미결제 요금 결제를 확인했습니다. 결제하지 않았습니다.', [
354
+ ['결제', '결제되지 않은 정기 결제 요금을 오래된 달부터 등록한 카드로 지금 결제합니다.'],
355
+ ['결제 동의', yes ? '동의함 (--yes).' : '필요합니다. 금액을 사용자에게 확인한 뒤 --yes 를 붙이세요.']
356
+ ], { currency: 'KRW', consentRequired: true, consented: yes }),
357
+ send: {
358
+ method: 'POST',
359
+ url,
360
+ body,
361
+ spinner: '미결제 요금을 결제하고 있습니다.',
362
+ failed: PAY_FAILED,
363
+ notFound: NO_UNPAID,
364
+ failures: { unavailable: CHANGE_UNAVAILABLE, charge_pending: CHARGE_PENDING, no_unpaid: NO_UNPAID, payment_unavailable: SUBSCRIBE_FAILURES.payment_unavailable },
365
+ intercept: payAnswer(command, rest, pretty, depth),
366
+ succeeded,
367
+ done: (result, siteUrl) => paid(command, pretty, depth, result, siteUrl)
368
+ }
369
+ };
370
+ });
371
+ }