Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .betterleaks.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Betterleaks' default rules, plus the fixture values the tests use on purpose.
[extend]
useDefault = true

[[allowlists]]
description = "The PDF password the submission tests pass through (test/creates/generate_pdf.test.js)"
targetRules = ["generic-password"]
regexTarget = "match"
regexes = ['''password: 's3cret'''']
17 changes: 17 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: 2
updates:
- package-ecosystem: npm
directory: /
schedule:
interval: weekly
cooldown:
default-days: 7
groups:
dev-dependencies:
dependency-type: development
- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
cooldown:
default-days: 7
35 changes: 35 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Runs every check (scripts/ci.sh) on pull requests and on main. `npm run push` runs the same
# checks before it pushes a version to Zapier.
name: CI

on:
pull_request:
push:
branches: [main]

permissions:
contents: read

concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
ci:
name: Checks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0 # Betterleaks scans the whole history
persist-credentials: false

- uses: jdx/mise-action@924e7c586e33d7d4bae9c14e26c5d22e2beb6e78 # v5.3.0
with:
cache: true

- name: Install dependencies
run: npm ci

- name: Checks
run: mise run ci
4 changes: 4 additions & 0 deletions .github/zizmor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
rules:
# It asks for the `$/` form of a local reusable workflow, which actionlint 1.7.12 rejects. `./` is the same file.
self-repository:
disable: true
17 changes: 17 additions & 0 deletions .jscpd.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"path": [
"authentication.js",
"index.js",
"creates",
"lib",
"searches",
"triggers",
"scripts",
"test"
],
"minLines": 8,
"threshold": 0,
"reporters": ["console"],
"silent": true,
"gitignore": true
}
8 changes: 8 additions & 0 deletions .oxfmtrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "./node_modules/oxfmt/configuration_schema.json",
"semi": false,
"singleQuote": true,
"printWidth": 100,
"experimentalSortPackageJson": false,
"ignorePatterns": ["package-lock.json", "build"]
}
35 changes: 35 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# DocSpring's Zapier integration

The integration's design and naming rules are in `DESIGN.md`; read it before changing an action, search or trigger.

## Checks

`mise run ci` (`scripts/ci.sh`) runs what CI runs, and the pre-push hook runs it too. Set up a checkout with
`mise install`, `npm ci` and `lefthook install`. CI (`.github/workflows/ci.yml`) runs on pull requests and on main.
A new version reaches Zapier only through `npm run push`, which runs the same checks first and stops if one fails
(it needs the Zapier CLI, `zapier-platform`, installed and signed in).

| Check | Tool |
| ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Type check | `tsc` on the JavaScript (`checkJs`, `tsconfig.json`), with Zapier's and Jest's types |
| Lint | oxlint, warnings fail |
| Tests, with a coverage floor | Jest (`jest.config.js`): statements 96%, branches 85%, functions 98%, lines 97%. Raise the floor as coverage rises; never lower it |
| Smoke test | `scripts/smoke_test.js`: Zapier's own validation of the app (what `zapier-platform validate` runs), a `CHANGELOG.md` entry for `package.json`'s version, and `.env` ignored by git, so `zapier-platform push` never uploads it |
| Dead code, unused dependencies | Knip (`knip.json`) |
| Copy-paste | jscpd (`.jscpd.json`): any clone of 8 lines or more fails. A false positive (the same `require` lines in two files) gets `// jscpd:ignore-start` and `// jscpd:ignore-end` with a comment saying what it repeats |
| File length | `scripts/check_file_length.sh`: 500 lines for code, 1000 for tests. Split the file |
| Lint suppressions | `scripts/check_lint_suppressions.sh`: no `eslint-disable`, `oxlint-disable` or `@ts-` comments |
| Spelling | typos (`_typos.toml`) |
| Workflows | actionlint, zizmor (`.github/zizmor.yml`). Actions are pinned to commit SHAs: `pinact run` |
| Secrets | Betterleaks over the whole history (`.betterleaks.toml` allows the tests' fixture password only) |
| Dependency advisories | `scripts/check_audit.mjs`: `npm audit`, minus `audit-ignores.json`. Each ignore has a reason and an expiry at most six months away, and the check fails once an ignore expires or no longer matches an advisory |
| Licences | `scripts/check_licences.mjs`: the runtime dependencies, which go into the bundle Zapier runs, must be permissive. Zapier's own SDK and three of its dependencies are named exceptions, each with its reason |

There's no format check. The pre-commit hook (`lefthook.yml`) formats staged files with oxfmt (`.oxfmtrc.json`), fixes
spelling and what oxlint can fix, and stages the result. `npm run format` formats everything.

`zapier-platform-cli` isn't a dev dependency: it brings several hundred packages, many with advisories, into the
audit. The smoke test runs the validation it would run through `zapier-platform-core`.

Tool versions are pinned in `mise.toml` and `package.json`, each at least 7 days old when pinned. Dependabot
(`.github/dependabot.yml`) waits 7 days before it proposes a new version.
2 changes: 1 addition & 1 deletion DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Architecture and rationale for the CLI integration. Companion to `README.md`.
- `lib/middleware.js` `beforeRequest` prepends the standard host to root-relative paths
and, **only for requests to this connection's DocSpring hosts**, adds
`Authorization: Basic base64(token_id:token_secret)`, `User-Agent:
docspring-zapier/<version>` (so `api_logs.user_agent` counts users by version),
docspring-zapier/<version>` (so `api_logs.user_agent` counts users by version),
`Accept` and `Content-Type: application/json`. Requests anywhere else (downloading a
file a user mapped into Create Template) never carry the credentials.
- `afterResponse` turns DocSpring error responses into readable errors (below). There
Expand Down
3 changes: 3 additions & 0 deletions _typos.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[default]
# A test checks that a misspelt variable, [[ signer.nmae ]], is passed through unchanged.
extend-ignore-re = ['signer\.nmae']
53 changes: 53 additions & 0 deletions audit-ignores.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"_comment": "npm audit advisories scripts/check_audit.mjs lets through. Each needs a reason and an expiry at most six months away; the check fails once an entry expires or no longer matches anything.",
"ignores": [
{
"id": "GHSA-ghv9-86vm-4v8m",
"package": "cross-spawn",
"reason": "Jest's dependency (through execa), dev only, and the bug is on Windows. The fixed 7.1.1 came out on 28 Nov 2026: run npm update cross-spawn once it's 7 days old.",
"expires": "2026-12-13"
},
{
"id": "GHSA-m6qr-m48x-3xhh",
"package": "cross-spawn",
"reason": "As GHSA-ghv9-86vm-4v8m.",
"expires": "2026-12-13"
},
{
"id": "GHSA-w3gc-668g-rf8f",
"package": "cross-spawn",
"reason": "As GHSA-ghv9-86vm-4v8m.",
"expires": "2026-12-13"
},
{
"id": "GHSA-3g3m-2fjr-6pw4",
"package": "glob",
"reason": "Jest 30's own dependency (its reporters and coverage), dev only: Jest's version ranges don't take a fixed release yet. Check again with the next Jest release.",
"expires": "2027-03-05"
},
{
"id": "GHSA-qxr8-q827-836c",
"package": "glob",
"reason": "Jest 30's own dependency (its reporters and coverage), dev only: Jest's version ranges don't take a fixed release yet. Check again with the next Jest release.",
"expires": "2027-03-05"
},
{
"id": "GHSA-c6wh-w8c3-cv3g",
"package": "glob",
"reason": "Jest 30's own dependency (its reporters and coverage), dev only: Jest's version ranges don't take a fixed release yet. Check again with the next Jest release.",
"expires": "2027-03-05"
},
{
"id": "GHSA-g3hv-75wg-m249",
"package": "minimatch",
"reason": "Jest 30's own dependency (its reporters and coverage), dev only: Jest's version ranges don't take a fixed release yet. Check again with the next Jest release.",
"expires": "2027-03-05"
},
{
"id": "GHSA-c859-jr93-m5j4",
"package": "minimatch",
"reason": "Jest 30's own dependency (its reporters and coverage), dev only: Jest's version ranges don't take a fixed release yet. Check again with the next Jest release.",
"expires": "2027-03-05"
}
]
}
5 changes: 1 addition & 4 deletions authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ const test = async (z, bundle) => {
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()
const region = ((bundle.authData && bundle.authData.region) || 'us').toUpperCase()
return `DocSpring ${env} · ${region}${tokenId ? ` · ${tokenId}` : ''}`
}

Expand Down
24 changes: 5 additions & 19 deletions creates/check_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,33 +45,19 @@ function withDefaultAuthType(request) {
if (!request || typeof request !== 'object' || Array.isArray(request)) {
return request
}
return request.auth_type === undefined
? { ...request, auth_type: 'email_link' }
: request
return request.auth_type === undefined ? { ...request, auth_type: 'email_link' } : request
}

const perform = async (z, bundle) => {
const input = bundle.inputData || {}
const parsed = parseJson(
z,
input.signature_requests,
'Signature Requests',
'array'
)
const parsed = parseJson(z, input.signature_requests, 'Signature Requests', 'array')
// An empty list is no signature requests: the email settings go only with
// signers. Each one's authentication defaults to an email link, as in
// Create Signature Request.
const signatureRequests =
parsed && parsed.length > 0
? parsed.map(withoutBlankText).map(withDefaultAuthType)
: undefined
parsed && parsed.length > 0 ? parsed.map(withoutBlankText).map(withDefaultAuthType) : undefined
const response = await apiRequest(z, {
url: apiPath(
'templates',
seg(input.template_id),
'submissions',
'validate'
),
url: apiPath('templates', seg(input.template_id), 'submissions', 'validate'),
method: 'POST',
params: compact({ version: text(input.version) }),
body: compact({
Expand All @@ -91,7 +77,7 @@ async function dynamicFields(z, bundle) {
let mode = 'docspring'
try {
mode = emailMode(z, input)
} catch (_e) {
} catch {
// An invalid choice is reported by perform; show DocSpring's options meanwhile.
}
const fields = await templateSchemaFields({ optional: true })(z, bundle)
Expand Down
47 changes: 10 additions & 37 deletions creates/combine_pdfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,8 @@

const { apiPath } = require('../lib/api')
const { COMBINED_PDF, createAndWait } = require('../lib/records')
const {
compact,
isBlank,
parseJson,
text,
toBoolean,
toInteger,
} = require('../lib/util')
const {
metadataInput,
pdfPassphraseInput,
expiresInInput,
waitInput,
} = require('../lib/templates')
const { compact, isBlank, parseJson, text, toBoolean, toInteger } = require('../lib/util')
const { metadataInput, pdfPassphraseInput, expiresInInput, waitInput } = require('../lib/templates')
const { shouldWait } = require('../lib/submissionInputs')
const combinedPdf = require('../lib/resources/combinedPdf')

Expand All @@ -35,28 +23,18 @@ function sourcePdf(z, row, number) {
const type = text(row.type) || 'submission'
if (type === 'url') {
const url = text(row.url)
if (!url)
throw new z.errors.Error(
`Source PDF ${number} needs a URL.`,
'InvalidInput',
400
)
if (!url) throw new z.errors.Error(`Source PDF ${number} needs a URL.`, 'InvalidInput', 400)
return { type, url }
}
if (!ID_TYPES.includes(type)) {
throw new z.errors.Error(
`Source PDF ${number} has an unknown type "${type}".`,
'InvalidInput',
400
400,
)
}
const id = text(row.id)
if (!id)
throw new z.errors.Error(
`Source PDF ${number} needs an ID.`,
'InvalidInput',
400
)
if (!id) throw new z.errors.Error(`Source PDF ${number} needs an ID.`, 'InvalidInput', 400)
if (type !== 'template') return { type, id }
return compact({
type,
Expand All @@ -69,15 +47,11 @@ function sourcePdf(z, row, number) {
const perform = async (z, bundle) => {
const input = bundle.inputData || {}
// Skip wholly blank line items; a row with a type but no ID or URL is an error.
const rows = (
Array.isArray(input.source_pdfs) ? input.source_pdfs : []
).filter((row) => row && !Object.values(row).every(isBlank))
const rows = (Array.isArray(input.source_pdfs) ? input.source_pdfs : []).filter(
(row) => row && !Object.values(row).every(isBlank),
)
if (rows.length === 0) {
throw new z.errors.Error(
'Add at least one source PDF.',
'InvalidInput',
400
)
throw new z.errors.Error('Add at least one source PDF.', 'InvalidInput', 400)
}
return createAndWait(z, bundle, {
kind: COMBINED_PDF,
Expand Down Expand Up @@ -150,8 +124,7 @@ module.exports = {
},
{
...metadataInput,
helpText:
'Your own data about the combined PDF, such as an ID from your app.',
helpText: 'Your own data about the combined PDF, such as an ID from your app.',
},
pdfPassphraseInput,
{
Expand Down
12 changes: 5 additions & 7 deletions creates/copy_template.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
'use strict'

// jscpd:ignore-start: the same requires as move_template.js, which jscpd counts as a copy.
const { apiPath, apiRequest } = require('../lib/api')
const { isRoot } = require('../lib/documents')
const { compact, seg, text } = require('../lib/util')
const { templateInput, folderInput } = require('../lib/templates')
const template = require('../lib/resources/template')
// jscpd:ignore-end

const perform = async (z, bundle) => {
const input = bundle.inputData || {}
// Blank: the copy goes in the template's own folder (left out). `root`:
// the top level (null).
const folder = isRoot(input.parent_folder_id)
? null
: text(input.parent_folder_id)
const folder = isRoot(input.parent_folder_id) ? null : text(input.parent_folder_id)
const response = await apiRequest(z, {
url: apiPath('templates', seg(input.template_id), 'copy'),
method: 'POST',
Expand All @@ -30,8 +30,7 @@ module.exports = {
noun: 'Template',
display: {
label: 'Copy Template',
description:
'Copies a template, or one of its published versions, to a new template.',
description: 'Copies a template, or one of its published versions, to a new template.',
},
operation: {
inputFields: [
Expand All @@ -41,8 +40,7 @@ module.exports = {
label: 'Name',
type: 'string',
required: false,
helpText:
'Default: the template\'s name and a number, such as "Contract (2)".',
helpText: 'Default: the template\'s name and a number, such as "Contract (2)".',
},
folderInput({
helpText:
Expand Down
Loading