-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauthentication.js
More file actions
84 lines (79 loc) · 3.1 KB
/
Copy pathauthentication.js
File metadata and controls
84 lines (79 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
'use strict'
const { REGION_CHOICES } = require('./lib/regions')
const { API_PREFIX } = require('./lib/constants')
// Verify the connection. The middleware injects the region host + Basic auth,
// so this only needs the path. A 200 `{status:'success'}` passes; a 401 is
// turned into a friendly error by the afterResponse middleware.
const test = {
url: `${API_PREFIX}/authentication`,
method: 'GET',
}
// Human-readable label for the connected account, derived entirely from the
// token (no extra API call): the token-id prefix tells us Test vs Live.
const connectionLabel = (z, bundle) => {
const tokenId = (bundle.authData && bundle.authData.token_id) || ''
const env = tokenId.startsWith('api_test_') ? 'Test' : 'Live'
const region = (
(bundle.authData && bundle.authData.region) ||
'us'
).toUpperCase()
return `DocSpring ${env} · ${region}${tokenId ? ` · ${tokenId}` : ''}`
}
// Where users find their credentials. Zapier check D002 wants every auth
// field's help text to link directly to the relevant page.
const API_TOKENS_URL = 'https://app.docspring.com/api_tokens'
const AUTH_DOCS_URL = 'https://docspring.com/docs/api-guide/authentication/'
module.exports = {
// Custom (not basic) so we can collect a Region dropdown + self-hosted host
// alongside the token. The Basic Authorization header is built in middleware.
type: 'custom',
test,
connectionLabel,
fields: [
{
key: 'region',
label: 'Region',
type: 'string',
required: true,
default: 'us',
choices: REGION_CHOICES,
helpText:
'The DocSpring region your account is in — it matches the dashboard you sign in to: ' +
'[app.docspring.com](https://app.docspring.com) (United States), ' +
'[app-eu.docspring.com](https://app-eu.docspring.com) (Europe) or ' +
'[app-au.docspring.com](https://app-au.docspring.com) (Australia). ' +
'Choose **Self-hosted / Enterprise** to enter a custom domain.',
},
{
key: 'custom_host',
label: 'Self-hosted Host',
type: 'string',
required: false,
helpText:
'Only for the **Self-hosted / Enterprise** region. Just the domain of your DocSpring install, ' +
'e.g. `docspring.example.com` (or `http://localhost:3000` for a local install). ' +
'No path or query string.',
},
{
key: 'token_id',
label: 'API Token ID',
type: 'string',
required: true,
helpText:
'Your DocSpring API Token ID. Starts with `api_` (live) or `api_test_` (test). ' +
`Create one on the [API Tokens page](${API_TOKENS_URL}) of your DocSpring dashboard ` +
'(Settings → API Tokens; use the EU/AU dashboard for those regions). ' +
`See the [authentication docs](${AUTH_DOCS_URL}).`,
},
{
key: 'token_secret',
label: 'API Token Secret',
type: 'password',
required: true,
helpText:
'The API Token Secret shown when you created the token on the ' +
`[API Tokens page](${API_TOKENS_URL}). It is only displayed once — ` +
'if you no longer have it, create a new token.',
},
],
}