@deepdynamic/cli 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -43,6 +43,12 @@ function queuedResult({ status, body }) {
43
43
  return status === 202 && sent?.ok === true && (sent.queued === true || sent.held === true);
44
44
  }
45
45
  export const holdReasonText = (reasons) => (reasons ?? []).map((reason) => HOLD_REASON_NAMES[reason] ?? reason).join(', ');
46
+ function domainRequiredFailure(body) {
47
+ const domains = body?.domains;
48
+ const names = Array.isArray(domains) ? domains.filter((name) => typeof name === 'string') : [];
49
+ const message = `More than one account domain can send email${names.length > 0 ? ` (${names.join(', ')})` : ''}. Choose one with --domain.`;
50
+ return { code: 'domain_required', message, display: message };
51
+ }
46
52
  function signupWaitFailure(body) {
47
53
  const availableAt = body?.availableAt;
48
54
  const message = `New free accounts can send email 72 hours after sign-up.${typeof availableAt === 'string' ? ` Try again after ${availableAt}.` : ''}`;
@@ -75,13 +81,15 @@ export async function runEmailSend(args, pretty, depth, deps = defaultAuthDeps(p
75
81
  ? { code: 'spam_rejected', message: 'The server rejected the email as advertising or spam. The account may be blocked if this continues.', display: 'The server rejected the email as advertising or spam. The account may be blocked if this continues.' }
76
82
  : result.status === 400 && typeof code === 'string' && DOMAIN_FAILURES[code]
77
83
  ? { code, message: DOMAIN_FAILURES[code], display: DOMAIN_FAILURES[code] }
78
- : result.status === 403 && code === 'signup_wait'
79
- ? signupWaitFailure(result.body)
80
- : result.status === 429
81
- ? { code: 'rate_limited', message: 'Too many emails. Try again later.', display: 'Too many emails. Try again later.' }
82
- : result.status === 400
83
- ? { code: 'rejected', message: 'The server rejected the email. Check the recipient, title and body.', display: 'The server rejected the email. Check the recipient, title and body.' }
84
- : httpFailure(result.status);
84
+ : result.status === 400 && code === 'domain_required'
85
+ ? domainRequiredFailure(result.body)
86
+ : result.status === 403 && code === 'signup_wait'
87
+ ? signupWaitFailure(result.body)
88
+ : result.status === 429
89
+ ? { code: 'rate_limited', message: 'Too many emails. Try again later.', display: 'Too many emails. Try again later.' }
90
+ : result.status === 400
91
+ ? { code: 'rejected', message: 'The server rejected the email. Check the recipient, title and body.', display: 'The server rejected the email. Check the recipient, title and body.' }
92
+ : httpFailure(result.status);
85
93
  }
86
94
  if (failure) {
87
95
  return pretty
@@ -10,7 +10,6 @@ import { rehearsed } from "./dns.js";
10
10
  export const KEYS_PATH = '/api/v1/keys';
11
11
  const KINDS = {
12
12
  dns: { name: 'DNS Control API key', prefix: 'dd_dns_' },
13
- s3: { name: 'S3 Control API key', prefix: 'dd_s3_' },
14
13
  pay: { name: 'Pay Control API key', prefix: 'dd_pay_' }
15
14
  };
16
15
  const EXPIRIES = {
@@ -21,9 +20,12 @@ const EXPIRIES = {
21
20
  };
22
21
  const DEFAULT_EXPIRY = '10m';
23
22
  const SCOPES = { 'dns:read': 'DNS read', 'dns:write': 'DNS write', 's3:read': 'Storage read', 's3:write': 'Storage write', 'pay:write': 'Consolidated billing' };
23
+ const CREATE_SCOPES = ['dns:read', 'dns:write'];
24
24
  const CUSTOM_PREFIX = 'dd_key_';
25
25
  const KIND_LABELS = { dns: 'DNS Control', s3: 'S3 Control', pay: 'Pay Control', custom: 'Custom' };
26
26
  const PAY_SCOPE = /^pay(:|$)/i;
27
+ const STORAGE_SCOPE = /^s3(:|$)/i;
28
+ const NO_STORAGE = 'no storage API accepts them yet';
27
29
  const KEY_VALUE = /^dd_/i;
28
30
  const KEY_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
29
31
  const CONTROL = /[\u0000-\u001f\u007f-\u009f]/;
@@ -32,6 +34,7 @@ const ONCE = 'The key value is shown only now. Store it somewhere safe. deepdyna
32
34
  const failure = (code, message) => ({ code, message, display: message });
33
35
  const KEY_NOT_FOUND = failure('key_not_found', 'No key with that ID is among your keys. Check them with deepdynamic keys.');
34
36
  const KEY_EXISTS = failure('key_exists', 'That key is already issued. Revoke it with deepdynamic keys revoke <key-id> --yes before issuing it again.');
37
+ const WEB_ONLY = failure('web_only', 'Pay Control keys are issued only on the web, signed in with a recent re-authentication, so the CLI cannot issue them. Ask the user to issue one in the API keys tab of /projects on the website.');
35
38
  const ISSUE_STEPS = [
36
39
  { stage: 'validate_kind', message: 'Checking the key kind.' },
37
40
  { stage: 'resolve_prefix', message: 'Resolving the key prefix.' },
@@ -63,9 +66,11 @@ function parseIssue(args) {
63
66
  const consented = args.includes('--yes');
64
67
  const [kind, ...rest] = args.filter((arg) => arg !== '--yes');
65
68
  if (kind === undefined || kind.startsWith('-'))
66
- return { error: 'Specify the key kind: dns, s3 or pay.' };
69
+ return { error: 'Specify the key kind: dns or pay.' };
70
+ if (kind === 's3')
71
+ return { error: `S3 Control keys are not issued for now because ${NO_STORAGE}. Use dns or pay.` };
67
72
  if (!Object.hasOwn(KINDS, kind))
68
- return { error: `Unknown key kind: ${kind}. Use dns, s3 or pay.` };
73
+ return { error: `Unknown key kind: ${kind}. Use dns or pay.` };
69
74
  const parsed = parseFlags(rest, ['--expires']);
70
75
  if ('error' in parsed)
71
76
  return parsed;
@@ -100,11 +105,14 @@ function parseCreate(args) {
100
105
  return { error: 'At least one --scope is required.' };
101
106
  const pay = given.find((scope) => PAY_SCOPE.test(scope));
102
107
  if (pay)
103
- return { error: `Payment scopes such as ${pay} are issued only with a temporary Pay Control key. Use deepdynamic keys issue pay.` };
104
- const unknown = given.find((scope) => !Object.hasOwn(SCOPES, scope));
108
+ return { error: `Payment scopes such as ${pay} come only with a temporary Pay Control key, which is issued on the web.` };
109
+ const storage = given.find((scope) => STORAGE_SCOPE.test(scope));
110
+ if (storage)
111
+ return { error: `Storage scopes such as ${storage} are not issued for now because ${NO_STORAGE}. Use dns:read or dns:write.` };
112
+ const unknown = given.find((scope) => !CREATE_SCOPES.includes(scope));
105
113
  if (unknown)
106
- return { error: `Unknown scope: ${unknown}. Use dns:read, dns:write, s3:read or s3:write.` };
107
- return { name, scopes: Object.keys(SCOPES).filter((scope) => scope !== 'pay:write' && given.includes(scope)) };
114
+ return { error: `Unknown scope: ${unknown}. Use dns:read or dns:write.` };
115
+ return { name, scopes: CREATE_SCOPES.filter((scope) => given.includes(scope)) };
108
116
  }
109
117
  function parseRevoke(args) {
110
118
  const option = args.find((arg) => arg.startsWith('-'));
@@ -203,6 +211,7 @@ export async function runKeysIssue(args, pretty, depth, deps = defaultAuthDeps(p
203
211
  failed: 'Could not issue the key.',
204
212
  notFound: httpFailure(404),
205
213
  conflict: KEY_EXISTS,
214
+ failures: { web_only: WEB_ONLY },
206
215
  done: (result, siteUrl) => issued(command, pretty, depth, `Issued the ${name}.`, result, siteUrl)
207
216
  }
208
217
  };
@@ -114,7 +114,7 @@ const KEYS_SECRET_NOTE = 'The key value is shown only once when it is actually i
114
114
  const MAIL_NOT_EMAILS = 'This is the Mail settings tab of captain mode on the My Projects page: the SPF, DKIM and DMARC records that let a domain send and receive mail. It never sends an email; use deepdynamic emails send for that.';
115
115
  const KEY_RESULT = '{ id, kind: dns|s3|pay|custom, name, prefix, scopes, createdAt, expiresAt, lastUsedAt }. prefix is the key prefix plus the first 8 characters (dd_dns_, dd_s3_, dd_pay_, dd_key_). scopes are among dns:read, dns:write, s3:read, s3:write and pay:write. Dates are ISO 8601 and lastUsedAt is null until the key is used.';
116
116
  const SESSION_RESULT = '{ id, kind: web|cli, current, name, device, userAgent, ip, lastIp, lastSeen, createdAt, expiresAt }. id is 64 hex characters for a browser session or a UUID for a deepdynamic login token. name is the token name for cli and null for web. device is { browser, os } for web and null for cli. ip is the sign-in IP (web) or the issue IP (cli); lastIp is the IP the token was last used from (cli only) and null for web. Dates are ISO 8601 and lastSeen is null until the session is used.';
117
- const KEYS_SOURCE_NOTE = 'Keys are told apart from deepdynamic login tokens by their prefix. A key authenticates the same Bearer header as a login token but only for its scopes: dns keys for deepdynamic dns and deepdynamic mail, s3 keys for storage, pay keys for consolidated billing.';
117
+ const KEYS_SOURCE_NOTE = 'Keys are told apart from deepdynamic login tokens by their prefix. A key authenticates the same Bearer header as a login token but only for its scopes: dns keys for deepdynamic dns and deepdynamic mail, pay keys for consolidated billing. s3 keys issued earlier have no API that accepts them yet.';
118
118
  const MAIL_SOURCE_NOTE = 'The settings are read from the TXT records of the domain: SPF at @ (v=spf1), DMARC at _dmarc and the first <selector>._domainkey record with a p= tag as the managed DKIM key. deepdynamic dns records <domain> shows the same records, and only those three managed records are replaced when settings change.';
119
119
  const MAIL_ZONE_RESULT = '{ domain, status: pending|ready, configured, custom, config: { policy, rua, spfInclude, selector, publicKey } }. configured is true once the SPF or DMARC record exists; before that config shows the automatic setup that deepdynamic mail reset or the first deepdynamic mail set would write. custom is true when the records differ from the automatic setup (policy quarantine, rua rua@<domain>, no SPF include, no DKIM key). spfInclude, selector and publicKey are "" when unset.';
120
120
  export const details = {
@@ -393,14 +393,14 @@ export const details = {
393
393
  { flag: '--title', description: 'Subject line, up to 200 characters, no line breaks.', required: true },
394
394
  { flag: '--body', description: 'Plain-text body, up to 10000 characters. \\n becomes a line break, \\t a tab and \\\\ a backslash, so write \\\\n for a literal \\n. Give this or --body-file.' },
395
395
  { flag: '--body-file', description: `Path of a UTF-8 file holding the plain-text body, instead of --body. Escapes such as \\n are not converted. ${BODY_FILE_NOTE}` },
396
- { flag: '--domain', description: 'Send from noreply@<domain> instead of the deepdynamic-usercontent.com address. The domain must belong to the account, use name servers on DeepDynamic, keep the automatic email setup, and have finished getting ready (deepdynamic mail show <domain> shows sending.state ready).' },
397
- { flag: '--dry-run', description: 'The server runs every check (account, rate limit, recipient, title, body, spam and --domain readiness) and returns the sender it would use without sending. The call is logged but does not count toward the hourly limit.' }
396
+ { flag: '--domain', description: 'Send from noreply@<domain> instead of the deepdynamic-usercontent.com address. The domain must belong to the account, use name servers on DeepDynamic, keep the automatic email setup, and have finished getting ready (deepdynamic mail show <domain> shows sending.state ready). Without --domain the server picks the domain itself when exactly one account domain is ready, fails with domain_required when more than one is, and uses the deepdynamic-usercontent.com address when none is.' },
397
+ { flag: '--dry-run', description: 'The server runs every check (account, rate limit, recipient, title, body, spam and sending domain readiness) and returns the sender it would use without sending. The call is logged but does not count toward the hourly limit.' }
398
398
  ],
399
399
  notes: [
400
400
  SIGN_IN_NOTE,
401
- 'The server builds the sender from the account email: me@example.com sends as "me <me-example.com@deepdynamic-usercontent.com>", and replies go to me@example.com. The sender and reply-to cannot be changed.',
402
- 'With --domain the sender is "me-example-com <noreply@<domain>>" and replies still go to the account email.',
403
- 'With --domain the email may be queued when the sending provider is busy: exit 0 with queued: true and delivered: false means it will be sent within an hour or, if it cannot, the account gets a notification. Do not resend a queued email.',
401
+ 'The server builds the sender from the account email: without a domain ready to send, me@example.com sends as "me <me-example.com@deepdynamic-usercontent.com>", and replies go to me@example.com. The sender and reply-to cannot be changed.',
402
+ 'When the email goes out from a domain (--domain, or the only account domain ready to send) the sender is "me-example-com <noreply@<domain>>" and replies still go to the account email.',
403
+ 'An email sent from a domain may be queued when the sending provider is busy: exit 0 with queued: true and delivered: false means it will be sent within an hour or, if it cannot, the account gets a notification. Do not resend a queued email.',
404
404
  'A free-plan email with a shortened URL (bit.ly and similar), an executable or archive file name or link, or a login link outside the account sites is not sent right away: exit 0 with held: true, code held_for_review and reasons means an administrator will send it or turn it down within 72 hours, and the account gets a notification either way. Do not resend a held email.',
405
405
  'A free-plan account can send email 72 hours after sign-up. Paid plans can send right away.',
406
406
  'The server keeps a record of every call with its full content.',
@@ -410,7 +410,7 @@ export const details = {
410
410
  limits: ['Calls per account are limited per hour.'],
411
411
  result: {
412
412
  dryRun: DRY_RUN_RESULT,
413
- queued: 'true when --domain was used and the email waits in a queue to be sent within an hour.',
413
+ queued: 'true when the email was sent from a domain and waits in a queue to be sent within an hour.',
414
414
  held: 'true when the email waits for an administrator review instead of being sent. With dryRun it means the email would be held.',
415
415
  code: 'held_for_review when held is true.',
416
416
  reasons: 'Why it was held: short_url, executable or login_page.',
@@ -430,6 +430,7 @@ export const details = {
430
430
  domain_not_found: 'The --domain is not one of the account domains that use DeepDynamic name servers. Check the domain name.',
431
431
  domain_mail_pending: 'The --domain is still getting ready to send. Retry later or send without --domain.',
432
432
  domain_mail_unavailable: 'The --domain email settings were edited manually or never set up automatically. Reset them with deepdynamic mail reset <domain> --yes or send without --domain.',
433
+ domain_required: 'More than one account domain is ready to send and --domain was not given. The message lists them. Ask the user which domain to send from and retry with --domain.',
433
434
  signup_wait: 'The free-plan account was created less than 72 hours ago. The message says when sending opens. Tell the user and retry after that time; --dry-run still works.',
434
435
  http_error: SUPPORT_HELP,
435
436
  ...CONNECTION_ERRORS
@@ -444,7 +445,7 @@ export const details = {
444
445
  ['--title', 'Subject, up to 200 characters, no line breaks (required)'],
445
446
  ['--body', 'Body, up to 10000 characters, \\n for a line break (or --body-file)'],
446
447
  ['--body-file', 'UTF-8 file with the body (instead of --body)'],
447
- ['--domain', 'Send from noreply@<domain> of an account domain'],
448
+ ['--domain', 'Send from noreply@<domain> of an account domain (needed when several are ready)'],
448
449
  SEND_DRY_RUN_PRETTY
449
450
  ]
450
451
  },
@@ -1859,7 +1860,7 @@ export const details = {
1859
1860
  },
1860
1861
  'keys issue': {
1861
1862
  options: [
1862
- { flag: '<dns|s3|pay>', description: 'Key kind. dns gets dns:read and dns:write, s3 gets s3:read and s3:write, both for 90 days. pay gets pay:write for the chosen expiry.', required: true },
1863
+ { flag: '<dns|pay>', description: 'Key kind. dns gets dns:read and dns:write for 90 days. pay gets pay:write for the chosen expiry and is issued only on the web.', required: true },
1863
1864
  { flag: '--expires', description: 'Expiry of a pay key: 10m, 1h, 6h or 1d. Only for pay.', default: '10m' },
1864
1865
  { flag: '--yes', description: 'Confirms the paid-service and consolidated-billing consent for a pay key. Only for pay; required to issue one without --dry-run.' },
1865
1866
  DNS_CHANGE_DRY_RUN
@@ -1868,7 +1869,8 @@ export const details = {
1868
1869
  SIGN_IN_NOTE,
1869
1870
  'Only one key of each kind can exist. If it is already issued the server answers 409 (key_exists); revoke it with deepdynamic keys revoke <key-id> first.',
1870
1871
  'The key value (key.token) is returned only by this command, once. Show it to the user and tell them to store it safely; deepdynamic keys shows only the prefix afterwards.',
1871
- 'A pay key can charge the account. Tell the user the expiry and the billing warning and get their consent before adding --yes. Pay keys can be issued only from the web with a recent sign-in; with the CLI login token the server answers 403, so send the user to the API 발급 tab for a pay key.',
1872
+ 'A pay key can charge the account and is issued only on the web, signed in with a recent re-authentication. With the CLI login token the server refuses it with web_only, so send the user to the API keys tab of /projects instead of retrying or logging in again.',
1873
+ 'S3 Control keys are not issued for now because no storage API accepts them yet. s3 keys issued earlier still appear in deepdynamic keys and can be revoked.',
1872
1874
  KEYS_SOURCE_NOTE,
1873
1875
  DNS_DRY_RUN_NOTE
1874
1876
  ],
@@ -1883,22 +1885,23 @@ export const details = {
1883
1885
  ...DNS_CHANGE_ERRORS,
1884
1886
  confirmation_required: 'Exit code 3. A pay key was requested without --yes, so nothing was sent. Get the user\'s consent, then run error.next.',
1885
1887
  key_exists: 'A key of that kind is already issued. Revoke it with deepdynamic keys revoke <key-id> --yes first.',
1886
- login_required: 'The login is missing or expired, or the token cannot issue that key (a pay key needs the web). Run deepdynamic login again or use the web.'
1888
+ web_only: 'A pay key was requested with the CLI login token. Pay keys are issued only on the web; send the user to the API keys tab of /projects. Logging in again does not help.',
1889
+ login_required: 'The login is missing or expired, or the token lacks the scope. Run deepdynamic login again.'
1887
1890
  },
1888
- examples: ['deepdynamic keys issue dns', 'deepdynamic keys issue s3 --dry-run', 'deepdynamic keys issue pay --expires 1h --yes'],
1889
- prettyOptions: [['<dns|s3|pay>', 'Kind of key to issue (required)'], ['--expires', 'Pay key expiry: 10m, 1h, 6h or 1d (default 10m)'], ['--yes', 'Consent to paid services and consolidated billing for a pay key'], DNS_CHANGE_DRY_RUN_PRETTY]
1891
+ examples: ['deepdynamic keys issue dns', 'deepdynamic keys issue dns --dry-run'],
1892
+ prettyOptions: [['<dns|pay>', 'Kind of key to issue (required, pay is web only)'], ['--expires', 'Pay key expiry: 10m, 1h, 6h or 1d (default 10m)'], ['--yes', 'Consent to paid services and consolidated billing for a pay key'], DNS_CHANGE_DRY_RUN_PRETTY]
1890
1893
  },
1891
1894
  'keys create': {
1892
1895
  options: [
1893
1896
  { flag: '--label', description: 'Key name, 1-60 characters without control characters. Surrounding spaces are removed.', required: true },
1894
- { flag: '--scope', description: 'A scope to grant: dns:read, dns:write, s3:read or s3:write. Repeat it for several scopes. Payment scopes are refused; use deepdynamic keys issue pay.', required: true },
1897
+ { flag: '--scope', description: 'A scope to grant: dns:read or dns:write. Repeat it for both. Storage scopes (s3:read, s3:write) are not issued for now, and payment scopes come only with a Pay Control key on the web.', required: true },
1895
1898
  DNS_CHANGE_DRY_RUN
1896
1899
  ],
1897
1900
  notes: [
1898
1901
  SIGN_IN_NOTE,
1899
1902
  'The key value (key.token) is returned only by this command, once. Show it to the user and tell them to store it safely.',
1900
1903
  'Keys and access tokens together are limited to 10 per account; beyond that the server answers 409.',
1901
- 'With the CLI login token you can create keys for scopes that token has (dns and s3 scopes are included in projects:read and projects:write).',
1904
+ 'With the CLI login token you can create keys for scopes that token has (dns scopes are included in projects:read and projects:write).',
1902
1905
  KEYS_SOURCE_NOTE,
1903
1906
  DNS_DRY_RUN_NOTE
1904
1907
  ],
@@ -1910,8 +1913,8 @@ export const details = {
1910
1913
  request: 'With --dry-run only: the POST request it would send, { method, url, body: { kind: "custom", name, scopes } }.'
1911
1914
  },
1912
1915
  errors: { ...DNS_CHANGE_ERRORS, key_exists: 'Keys and access tokens are limited to 10 per account. Revoke one first.' },
1913
- examples: ['deepdynamic keys create --label "Deploy automation" --scope dns:read --scope dns:write', 'deepdynamic keys create --label uploads --scope s3:write --dry-run'],
1914
- prettyOptions: [['--label', 'Key name, 1-60 characters (required)'], ['--scope', 'Scope dns:read, dns:write, s3:read or s3:write, repeatable (required)'], DNS_CHANGE_DRY_RUN_PRETTY]
1916
+ examples: ['deepdynamic keys create --label "Deploy automation" --scope dns:read --scope dns:write', 'deepdynamic keys create --label "DNS reader" --scope dns:read --dry-run'],
1917
+ prettyOptions: [['--label', 'Key name, 1-60 characters (required)'], ['--scope', 'Scope dns:read or dns:write, repeatable (required)'], DNS_CHANGE_DRY_RUN_PRETTY]
1915
1918
  },
1916
1919
  'keys revoke': {
1917
1920
  options: [
package/dist/registry.js CHANGED
@@ -157,7 +157,7 @@ export const commands = [
157
157
  name: 'emails send',
158
158
  usage: 'deepdynamic emails send --to <email> --title <text> (--body <text> | --body-file <path>) [--domain <domain>] [--dry-run]',
159
159
  summary: 'Send an email as the account',
160
- description: 'Send a plain-text email on behalf of the logged-in account. With --domain, send from noreply@<domain>.',
160
+ description: 'Send a plain-text email on behalf of the logged-in account, from noreply@<domain> when a domain is ready to send.',
161
161
  effect: 'write',
162
162
  requiresLogin: true,
163
163
  dryRun: 'server'
@@ -585,9 +585,9 @@ export const commands = [
585
585
  },
586
586
  {
587
587
  name: 'keys issue',
588
- usage: 'deepdynamic keys issue <dns|s3|pay> [--expires 10m|1h|6h|1d] [--yes] [--dry-run]',
588
+ usage: 'deepdynamic keys issue <dns|pay> [--expires 10m|1h|6h|1d] [--yes] [--dry-run]',
589
589
  summary: 'Issue a service API key',
590
- description: 'Issue a DNS Control, S3 Control or temporary Pay Control API key and print its value once.',
590
+ description: 'Issue a DNS Control API key and print its value once. Temporary Pay Control keys are issued only on the web.',
591
591
  effect: 'billing',
592
592
  requiresLogin: true,
593
593
  dryRun: 'local',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deepdynamic/cli",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Command-line tool for deploying and managing sites on DeepDynamic Cloud.",
5
5
  "keywords": [
6
6
  "deepdynamic",