@devrev/airsync-sdk 2.0.0-beta.1 → 2.0.0-beta.10
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/README.md +7 -21
- package/dist/attachments-streaming/attachments-streaming-pool.d.ts +6 -7
- package/dist/attachments-streaming/attachments-streaming-pool.d.ts.map +1 -1
- package/dist/attachments-streaming/attachments-streaming-pool.interfaces.d.ts +4 -3
- package/dist/attachments-streaming/attachments-streaming-pool.interfaces.d.ts.map +1 -1
- package/dist/attachments-streaming/attachments-streaming-pool.js +69 -61
- package/dist/common/constants.d.ts +15 -12
- package/dist/common/constants.d.ts.map +1 -1
- package/dist/common/constants.js +20 -34
- package/dist/common/helpers.d.ts +3 -27
- package/dist/common/helpers.d.ts.map +1 -1
- package/dist/common/helpers.js +6 -36
- package/dist/http/{axios-client-internal.d.ts → client.d.ts} +1 -1
- package/dist/http/client.d.ts.map +1 -0
- package/dist/http/{axios-client-internal.js → client.js} +7 -4
- package/dist/http/errors.d.ts +8 -0
- package/dist/http/errors.d.ts.map +1 -0
- package/dist/http/errors.js +31 -0
- package/dist/index.d.ts +30 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +47 -28
- package/dist/logger/logger.d.ts +13 -70
- package/dist/logger/logger.d.ts.map +1 -1
- package/dist/logger/logger.interfaces.d.ts +4 -7
- package/dist/logger/logger.interfaces.d.ts.map +1 -1
- package/dist/logger/logger.js +67 -92
- package/dist/mappers/mappers.d.ts +10 -43
- package/dist/mappers/mappers.d.ts.map +1 -1
- package/dist/mappers/mappers.interfaces.d.ts +173 -0
- package/dist/mappers/mappers.interfaces.d.ts.map +1 -0
- package/dist/mappers/{mappers.interface.js → mappers.interfaces.js} +1 -10
- package/dist/mappers/mappers.js +32 -46
- package/dist/multithreading/adapters/base-adapter.d.ts +39 -0
- package/dist/multithreading/adapters/base-adapter.d.ts.map +1 -0
- package/dist/multithreading/adapters/base-adapter.js +212 -0
- package/dist/multithreading/adapters/extraction-adapter.d.ts +49 -0
- package/dist/multithreading/adapters/extraction-adapter.d.ts.map +1 -0
- package/dist/multithreading/adapters/extraction-adapter.js +375 -0
- package/dist/multithreading/adapters/loading-adapter.d.ts +26 -0
- package/dist/multithreading/adapters/loading-adapter.d.ts.map +1 -0
- package/dist/multithreading/adapters/loading-adapter.helpers.d.ts +12 -0
- package/dist/multithreading/adapters/loading-adapter.helpers.d.ts.map +1 -0
- package/dist/multithreading/{worker-adapter/worker-adapter.helpers.js → adapters/loading-adapter.helpers.js} +2 -12
- package/dist/multithreading/adapters/loading-adapter.js +279 -0
- package/dist/multithreading/emit.d.ts +11 -0
- package/dist/multithreading/emit.d.ts.map +1 -0
- package/dist/multithreading/emit.js +25 -0
- package/dist/multithreading/process-task.d.ts +6 -1
- package/dist/multithreading/process-task.d.ts.map +1 -1
- package/dist/multithreading/process-task.js +120 -82
- package/dist/multithreading/spawn/spawn.d.ts +10 -11
- package/dist/multithreading/spawn/spawn.d.ts.map +1 -1
- package/dist/multithreading/spawn/spawn.helpers.d.ts +12 -11
- package/dist/multithreading/spawn/spawn.helpers.d.ts.map +1 -1
- package/dist/multithreading/spawn/spawn.helpers.js +142 -77
- package/dist/multithreading/spawn/spawn.js +59 -75
- package/dist/multithreading/worker.js +16 -5
- package/dist/repo/repo.d.ts +14 -5
- package/dist/repo/repo.d.ts.map +1 -1
- package/dist/repo/repo.helpers.d.ts +6 -0
- package/dist/repo/repo.helpers.d.ts.map +1 -0
- package/dist/repo/repo.helpers.js +16 -0
- package/dist/repo/repo.interfaces.d.ts +11 -20
- package/dist/repo/repo.interfaces.d.ts.map +1 -1
- package/dist/repo/repo.js +36 -22
- package/dist/state/base-state.d.ts +58 -0
- package/dist/state/base-state.d.ts.map +1 -0
- package/dist/state/base-state.js +242 -0
- package/dist/state/extraction-state.d.ts +14 -0
- package/dist/state/extraction-state.d.ts.map +1 -0
- package/dist/state/extraction-state.js +140 -0
- package/dist/state/install-initial-domain-mapping.d.ts +4 -0
- package/dist/state/install-initial-domain-mapping.d.ts.map +1 -0
- package/dist/{common → state}/install-initial-domain-mapping.js +5 -7
- package/dist/state/loading-state.d.ts +8 -0
- package/dist/state/loading-state.d.ts.map +1 -0
- package/dist/state/loading-state.js +29 -0
- package/dist/state/state.d.ts +3 -29
- package/dist/state/state.d.ts.map +1 -1
- package/dist/state/state.interfaces.d.ts +31 -12
- package/dist/state/state.interfaces.d.ts.map +1 -1
- package/dist/state/state.interfaces.js +17 -1
- package/dist/state/state.js +9 -164
- package/dist/state/time-value-resolver.d.ts +17 -0
- package/dist/state/time-value-resolver.d.ts.map +1 -0
- package/dist/state/time-value-resolver.js +110 -0
- package/dist/testing/mock-event.d.ts +10 -0
- package/dist/testing/mock-event.d.ts.map +1 -0
- package/dist/testing/mock-event.js +96 -0
- package/dist/testing/mock-server.d.ts +31 -0
- package/dist/testing/mock-server.d.ts.map +1 -0
- package/dist/testing/mock-server.interfaces.d.ts +54 -0
- package/dist/testing/mock-server.interfaces.d.ts.map +1 -0
- package/dist/testing/mock-server.interfaces.js +4 -0
- package/dist/testing/mock-server.js +297 -0
- package/dist/testing/test-adapters.d.ts +22 -0
- package/dist/testing/test-adapters.d.ts.map +1 -0
- package/dist/testing/test-adapters.js +32 -0
- package/dist/types/common.d.ts +4 -37
- package/dist/types/common.d.ts.map +1 -1
- package/dist/types/common.js +2 -17
- package/dist/types/errors.d.ts +15 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/errors.js +28 -0
- package/dist/types/external-domain-metadata.d.ts +40 -162
- package/dist/types/external-domain-metadata.d.ts.map +1 -1
- package/dist/types/extraction.d.ts +135 -278
- package/dist/types/extraction.d.ts.map +1 -1
- package/dist/types/extraction.js +46 -133
- package/dist/types/loading.d.ts +15 -55
- package/dist/types/loading.d.ts.map +1 -1
- package/dist/types/loading.js +1 -23
- package/dist/types/workers.d.ts +70 -103
- package/dist/types/workers.d.ts.map +1 -1
- package/dist/types/workers.js +1 -6
- package/dist/uploader/uploader.d.ts +10 -61
- package/dist/uploader/uploader.d.ts.map +1 -1
- package/dist/uploader/uploader.helpers.d.ts +7 -27
- package/dist/uploader/uploader.helpers.d.ts.map +1 -1
- package/dist/uploader/uploader.helpers.js +80 -30
- package/dist/uploader/uploader.interfaces.d.ts +19 -54
- package/dist/uploader/uploader.interfaces.d.ts.map +1 -1
- package/dist/uploader/uploader.interfaces.js +8 -0
- package/dist/uploader/uploader.js +72 -124
- package/docs/MIGRATION.md +696 -0
- package/package.json +35 -22
- package/dist/attachments-streaming/attachments-streaming-pool.test.d.ts +0 -2
- package/dist/attachments-streaming/attachments-streaming-pool.test.d.ts.map +0 -1
- package/dist/attachments-streaming/attachments-streaming-pool.test.js +0 -321
- package/dist/common/control-protocol.d.ts +0 -10
- package/dist/common/control-protocol.d.ts.map +0 -1
- package/dist/common/control-protocol.js +0 -31
- package/dist/common/errors.d.ts +0 -6
- package/dist/common/errors.d.ts.map +0 -1
- package/dist/common/errors.js +0 -4
- package/dist/common/event-type-translation.d.ts +0 -24
- package/dist/common/event-type-translation.d.ts.map +0 -1
- package/dist/common/event-type-translation.js +0 -117
- package/dist/common/install-initial-domain-mapping.d.ts +0 -4
- package/dist/common/install-initial-domain-mapping.d.ts.map +0 -1
- package/dist/common/install-initial-domain-mapping.test.d.ts +0 -2
- package/dist/common/install-initial-domain-mapping.test.d.ts.map +0 -1
- package/dist/common/install-initial-domain-mapping.test.js +0 -208
- package/dist/deprecated/adapter/index.d.ts +0 -62
- package/dist/deprecated/adapter/index.d.ts.map +0 -1
- package/dist/deprecated/adapter/index.js +0 -151
- package/dist/deprecated/common/helpers.d.ts +0 -7
- package/dist/deprecated/common/helpers.d.ts.map +0 -1
- package/dist/deprecated/common/helpers.js +0 -47
- package/dist/deprecated/demo-extractor/external_domain_metadata.json +0 -38
- package/dist/deprecated/demo-extractor/index.d.ts +0 -18
- package/dist/deprecated/demo-extractor/index.d.ts.map +0 -1
- package/dist/deprecated/demo-extractor/index.js +0 -161
- package/dist/deprecated/http/client.d.ts +0 -22
- package/dist/deprecated/http/client.d.ts.map +0 -1
- package/dist/deprecated/http/client.js +0 -161
- package/dist/deprecated/uploader/index.d.ts +0 -35
- package/dist/deprecated/uploader/index.d.ts.map +0 -1
- package/dist/deprecated/uploader/index.js +0 -161
- package/dist/http/axios-client-internal.d.ts.map +0 -1
- package/dist/http/axios-client-internal.test.d.ts +0 -2
- package/dist/http/axios-client-internal.test.d.ts.map +0 -1
- package/dist/http/axios-client-internal.test.js +0 -154
- package/dist/http/axios-client.d.ts +0 -27
- package/dist/http/axios-client.d.ts.map +0 -1
- package/dist/http/axios-client.js +0 -57
- package/dist/http/constants.d.ts +0 -4
- package/dist/http/constants.d.ts.map +0 -1
- package/dist/http/constants.js +0 -6
- package/dist/http/index.d.ts +0 -3
- package/dist/http/index.d.ts.map +0 -1
- package/dist/http/index.js +0 -18
- package/dist/http/types.d.ts +0 -17
- package/dist/http/types.d.ts.map +0 -1
- package/dist/http/types.js +0 -2
- package/dist/logger/logger.constants.d.ts +0 -6
- package/dist/logger/logger.constants.d.ts.map +0 -1
- package/dist/logger/logger.constants.js +0 -13
- package/dist/logger/logger.context.d.ts +0 -58
- package/dist/logger/logger.context.d.ts.map +0 -1
- package/dist/logger/logger.context.js +0 -86
- package/dist/logger/logger.test.d.ts +0 -2
- package/dist/logger/logger.test.d.ts.map +0 -1
- package/dist/logger/logger.test.js +0 -490
- package/dist/mappers/mappers.interface.d.ts +0 -294
- package/dist/mappers/mappers.interface.d.ts.map +0 -1
- package/dist/mappers/mappers.test.d.ts +0 -2
- package/dist/mappers/mappers.test.d.ts.map +0 -1
- package/dist/mappers/mappers.test.js +0 -107
- package/dist/multithreading/create-worker.test.d.ts +0 -2
- package/dist/multithreading/create-worker.test.d.ts.map +0 -1
- package/dist/multithreading/create-worker.test.js +0 -89
- package/dist/multithreading/spawn/spawn.helpers.test.d.ts +0 -2
- package/dist/multithreading/spawn/spawn.helpers.test.d.ts.map +0 -1
- package/dist/multithreading/spawn/spawn.helpers.test.js +0 -293
- package/dist/multithreading/worker-adapter/worker-adapter.artifacts.test.d.ts +0 -2
- package/dist/multithreading/worker-adapter/worker-adapter.artifacts.test.d.ts.map +0 -1
- package/dist/multithreading/worker-adapter/worker-adapter.artifacts.test.js +0 -127
- package/dist/multithreading/worker-adapter/worker-adapter.d.ts +0 -91
- package/dist/multithreading/worker-adapter/worker-adapter.d.ts.map +0 -1
- package/dist/multithreading/worker-adapter/worker-adapter.helpers.d.ts +0 -22
- package/dist/multithreading/worker-adapter/worker-adapter.helpers.d.ts.map +0 -1
- package/dist/multithreading/worker-adapter/worker-adapter.helpers.test.d.ts +0 -2
- package/dist/multithreading/worker-adapter/worker-adapter.helpers.test.d.ts.map +0 -1
- package/dist/multithreading/worker-adapter/worker-adapter.helpers.test.js +0 -514
- package/dist/multithreading/worker-adapter/worker-adapter.js +0 -745
- package/dist/multithreading/worker-adapter/worker-adapter.test.d.ts +0 -2
- package/dist/multithreading/worker-adapter/worker-adapter.test.d.ts.map +0 -1
- package/dist/multithreading/worker-adapter/worker-adapter.test.js +0 -483
- package/dist/repo/repo.test.d.ts +0 -2
- package/dist/repo/repo.test.d.ts.map +0 -1
- package/dist/repo/repo.test.js +0 -131
- package/dist/state/state.test.d.ts +0 -2
- package/dist/state/state.test.d.ts.map +0 -1
- package/dist/state/state.test.js +0 -224
- package/dist/types/extraction.test.d.ts +0 -2
- package/dist/types/extraction.test.d.ts.map +0 -1
- package/dist/types/extraction.test.js +0 -70
- package/dist/types/index.d.ts +0 -10
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -18
- package/dist/uploader/uploader.helpers.test.d.ts +0 -2
- package/dist/uploader/uploader.helpers.test.d.ts.map +0 -1
- package/dist/uploader/uploader.helpers.test.js +0 -267
- package/dist/uploader/uploader.test.d.ts +0 -2
- package/dist/uploader/uploader.test.d.ts.map +0 -1
- package/dist/uploader/uploader.test.js +0 -589
|
@@ -0,0 +1,696 @@
|
|
|
1
|
+
# Migrating connectors from v1 (`@devrev/ts-adaas`) to v2 (`@devrev/airsync-sdk`)
|
|
2
|
+
|
|
3
|
+
This is the complete list of connector-facing changes from `@devrev/ts-adaas`
|
|
4
|
+
1.x to `@devrev/airsync-sdk` 2.x, written so an AI agent can apply it on its
|
|
5
|
+
own:
|
|
6
|
+
|
|
7
|
+
> Read `MIGRATION.md` from `@devrev/airsync-sdk` and migrate this connector.
|
|
8
|
+
|
|
9
|
+
It ships in the package at `node_modules/@devrev/airsync-sdk/docs/MIGRATION.md`
|
|
10
|
+
(read it from disk; the `exports` map only blocks `import`/`require`). Before
|
|
11
|
+
v2 is installed, use
|
|
12
|
+
`https://raw.githubusercontent.com/devrev/adaas-sdk/v2/docs/MIGRATION.md`.
|
|
13
|
+
|
|
14
|
+
**The wire protocol is unchanged.** Event payloads, routes, headers, the
|
|
15
|
+
artifact flow and every event-type and `ERROR_CODE=…` string are identical to
|
|
16
|
+
v1. Only the TypeScript API changed, all at once, with no compatibility shims.
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## Runbook
|
|
21
|
+
|
|
22
|
+
**Rules.** Work autonomously; when a rewrite is ambiguous, pick the option
|
|
23
|
+
that preserves runtime behavior and note it in `MIGRATION_REVIEW.md`. Migrate
|
|
24
|
+
source **and** tests. Never change a runtime string value. Don't add comments
|
|
25
|
+
about the migration; the `// v1` / `// v2` labels here are reading aids. Leave
|
|
26
|
+
no compile errors or orphaned imports. A section with no hits is a no-op.
|
|
27
|
+
Existing comments and commented-out code that describe v1 behavior (`emit`,
|
|
28
|
+
`{ id }` / `{ error }` returns, `.data.sync_mapper_record`) are rewritten to
|
|
29
|
+
v2; templates are copied into new connectors, so stale comments spread.
|
|
30
|
+
|
|
31
|
+
1. **Locate the package.** Find the `package.json` that depends on
|
|
32
|
+
`@devrev/ts-adaas` (generated connectors keep it in `code/`). Run everything
|
|
33
|
+
from there. If it already depends on `@devrev/airsync-sdk` only, report
|
|
34
|
+
"already on v2" and stop.
|
|
35
|
+
2. **Start from green latest v1.** If behind the latest stable 1.x, upgrade and
|
|
36
|
+
apply the release notes of every release in between that mentions a
|
|
37
|
+
migration (the last ones were 1.16.0–1.18.0), then get tsc/lint/build/test
|
|
38
|
+
green on v1. Record failures that remain as **Pre-existing**.
|
|
39
|
+
3. **Install v2.**
|
|
40
|
+
```bash
|
|
41
|
+
npm uninstall @devrev/ts-adaas
|
|
42
|
+
npm install @devrev/airsync-sdk@beta # @latest after GA
|
|
43
|
+
```
|
|
44
|
+
Rename or remove `overrides` / `resolutions` entries keyed on
|
|
45
|
+
`@devrev/ts-adaas`; `npm uninstall` leaves them behind. If the installed
|
|
46
|
+
`docs/MIGRATION.md` differs from this copy, switch to it.
|
|
47
|
+
4. **Apply §1–§14 in order** across source and tests. After §1, search by
|
|
48
|
+
symbol (`\.emit\(`, `WorkerAdapter`, `sync_mapper_record`, …), not by the old
|
|
49
|
+
package name; test files that import nothing from the SDK still need
|
|
50
|
+
changes.
|
|
51
|
+
5. **Verify**: `npm install && npx tsc --noEmit && npm run lint && npm run build && npm test`.
|
|
52
|
+
If tsconfig excludes folders the connector still runs (`test/`, a local
|
|
53
|
+
runner), type-check them too: use the repo's `tsconfig.test.json` if it has
|
|
54
|
+
one, otherwise a temporary tsconfig that extends `tsconfig.json` with
|
|
55
|
+
`"include": ["src", "test"]` and `npx tsc --noEmit -p` it. Fix and rerun,
|
|
56
|
+
at most 4 attempts; the migration must add no new failures compared to
|
|
57
|
+
step 2.
|
|
58
|
+
6. **Sweep.** This must return nothing except legitimate hits (an
|
|
59
|
+
`EventEmitter.emit`, the connector's own `axiosClient` from §9,
|
|
60
|
+
`@devrev/typescript-sdk` in `package.json` from §1, `git config --local`):
|
|
61
|
+
```bash
|
|
62
|
+
grep -rnE "@devrev/ts-adaas|airsync-sdk/dist|\bprocessTask\b|WorkerAdapter|\.emit\(|hasWorkerEmitted|Airdrop(Event|Message)|axiosClient|(format|serialize)AxiosError|workerPath:|overridenOptions|skipConfirmation|isLocalDevelopment|--local|-- local\b|@devrev/typescript-sdk|(Extractor|Loader)EventType|ExtractionCommonError|ERROR_CODE=|sdkState|onUpload|uploadedArtifacts|currentEventDataLength|EXTRACTION_(DATA|METADATA|ATTACHMENTS|EXTERNAL_SYNC_UNITS)_" \
|
|
63
|
+
--include='*.ts' --include='*.js' --include='*.json' --include='*.yml' --include='*.yaml' --include='*.md' --include='*.mdc' --include='*.sh' . \
|
|
64
|
+
| grep -vE 'node_modules|/dist/|/coverage/|package-lock.json|MIGRATION_REVIEW.md'
|
|
65
|
+
```
|
|
66
|
+
The sweep covers `test/` and other folders that tsc, lint and jest often
|
|
67
|
+
exclude. A hit there is real: `@devrev/typescript-sdk` must be in
|
|
68
|
+
`package.json` (§1), and a `local` argv must become the env var (§3).
|
|
69
|
+
Also check `package.json` scripts and shell scripts for a bare `local`
|
|
70
|
+
argument (`npm run test:server -- local`, `main.ts local`).
|
|
71
|
+
Also grep `getByExternalId|getByTargetId` and check each call against §10:
|
|
72
|
+
existence checks there compile but silently invert.
|
|
73
|
+
Then rewrite any connector docs (`README`, `AGENTS.md`, `CLAUDE.md`, `docs/`)
|
|
74
|
+
that describe v1 behavior, including text that paraphrases DevRev docs with
|
|
75
|
+
legacy event names.
|
|
76
|
+
7. **Write `MIGRATION_REVIEW.md`** at the repo root: one line per section that
|
|
77
|
+
changed code with `high` / `medium` / `low confidence`, a sentence on what
|
|
78
|
+
to verify for medium/low, and the final check results with an
|
|
79
|
+
**Unresolved** list. Use medium/low for anything judged: emits bubbled out of
|
|
80
|
+
helpers (§4), paths that emitted nothing (§4), `onTimeout` bodies kept (§4),
|
|
81
|
+
delay values that look like milliseconds or headers (§4), the cursor decision
|
|
82
|
+
(§8), ESU repo rewrites (§7), mapper error handling (§10), and a v1 baseline
|
|
83
|
+
upgrade.
|
|
84
|
+
```markdown
|
|
85
|
+
# v2 Migration Review
|
|
86
|
+
Migrated `@devrev/ts-adaas` 1.20.2 → `@devrev/airsync-sdk` 2.0.0.
|
|
87
|
+
- §4 emit→return — high confidence
|
|
88
|
+
- §8 state / cursor — low confidence: repointed `lastSuccessfulSyncStarted`
|
|
89
|
+
to `extract_from`; confirm the connector didn't own this cursor.
|
|
90
|
+
## Verification
|
|
91
|
+
tsc ✓ · lint ✓ · build ✓ · test ✓ (48 passed)
|
|
92
|
+
```
|
|
93
|
+
8. **Report** the start and end versions, which sections fired, the check
|
|
94
|
+
results and how many review entries need a second look.
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
## 1. Package, imports and runtime
|
|
99
|
+
|
|
100
|
+
- Replace `@devrev/ts-adaas` with `@devrev/airsync-sdk` **everywhere the
|
|
101
|
+
string appears**: imports, `jest.mock` / `jest.requireActual` arguments and
|
|
102
|
+
`moduleNameMapper`.
|
|
103
|
+
- **Import only from the root.** `exports` exposes nothing else, so every
|
|
104
|
+
`@devrev/airsync-sdk/dist/**` import fails with
|
|
105
|
+
`ERR_PACKAGE_PATH_NOT_EXPORTED`. Everything public is on the root, including
|
|
106
|
+
`Mappers`, `Item`, `ItemTypeToLoad`, `InitialSyncScope`, the mapper
|
|
107
|
+
`*Params` / `*Response` types and `SyncMapperRecord*`. Deep imports with no
|
|
108
|
+
root equivalent are listed in §11. Never import the SDK's internal HTTP client
|
|
109
|
+
(`dist/http/axios-client-internal`): use the connector's own client (§9).
|
|
110
|
+
- **Node.js ≥ 20.** Bump the connector's `engines`, CI image and `.nvmrc` if
|
|
111
|
+
they pin older. `@types/node` can stay as it is. Dependabot / CI configs that name `@devrev/ts-adaas` switch to
|
|
112
|
+
`@devrev/airsync-sdk`.
|
|
113
|
+
- `ts-node` and `@devrev/typescript-sdk` are no longer SDK dependencies. A
|
|
114
|
+
connector that runs `.ts` workers directly needs `ts-node` in its own
|
|
115
|
+
`devDependencies`. A connector that uses `@devrev/typescript-sdk` must list
|
|
116
|
+
it. The template's local test server (`code/test/runner.ts`, and the copy
|
|
117
|
+
`airsync start-worker` writes to `code/.snapin-test/`) imports
|
|
118
|
+
`@devrev/typescript-sdk/dist/snap-ins`, so template connectors add it to
|
|
119
|
+
`devDependencies` (`1.1.78`, the version the template pins). Most connectors exclude `test/` from tsc, lint and jest,
|
|
120
|
+
so the gates pass and the local worker then fails with
|
|
121
|
+
`Cannot find module '@devrev/typescript-sdk/dist/snap-ins'`.
|
|
122
|
+
`InputData` (the type of `event.input_data`) is now exported from the
|
|
123
|
+
root.
|
|
124
|
+
|
|
125
|
+
## 2. Event types
|
|
126
|
+
|
|
127
|
+
| v1 | v2 |
|
|
128
|
+
|----|----|
|
|
129
|
+
| `AirdropEvent` | `AirSyncEvent` |
|
|
130
|
+
| `AirdropMessage` | `AirSyncMessage` |
|
|
131
|
+
|
|
132
|
+
The shapes are unchanged. `AirSyncEvent.context` now also declares `user_id`,
|
|
133
|
+
`dev_oid`, `source_id` and `service_account_id` (on `event.context`, not on
|
|
134
|
+
`payload.event_context`). Delete a hand-rolled context type that added these
|
|
135
|
+
(e.g. `interface CustomAirdropEvent extends AirdropEvent { context: CustomContext }`):
|
|
136
|
+
a narrower `context` no longer satisfies `AirSyncEvent`. Keep only the fields
|
|
137
|
+
the SDK type lacks.
|
|
138
|
+
|
|
139
|
+
Deprecated `EventContext` aliases are removed. Use the current names:
|
|
140
|
+
|
|
141
|
+
| Removed | Use |
|
|
142
|
+
|---------|-----|
|
|
143
|
+
| `dev_org` | `dev_oid` |
|
|
144
|
+
| `dev_user`, `dev_user_id` | `dev_uid` |
|
|
145
|
+
| `external_sync_unit` | `external_sync_unit_id` |
|
|
146
|
+
| `external_system` | `external_system_id` |
|
|
147
|
+
| `sync_run`, `sync_run_id` | `run_id` |
|
|
148
|
+
| `uuid` | `request_id_adaas` |
|
|
149
|
+
|
|
150
|
+
Rename these keys in fixture and test `event_context` objects too. Untyped
|
|
151
|
+
JSON still compiles, but the SDK reads only the current names (e.g. state
|
|
152
|
+
requests carry `request_id_adaas`).
|
|
153
|
+
|
|
154
|
+
`reset_extraction` and `reset_extract_from` remain (the SDK never read them);
|
|
155
|
+
leave connector logic that uses them alone.
|
|
156
|
+
|
|
157
|
+
## 3. `spawn`
|
|
158
|
+
|
|
159
|
+
| v1 | v2 |
|
|
160
|
+
|----|----|
|
|
161
|
+
| `workerPath` | removed; use `baseWorkerPath` |
|
|
162
|
+
| `baseWorkerPath?` | **required**, the directory containing `workers/` (usually `__dirname`) |
|
|
163
|
+
| `options.workerPathOverrides` | top-level `workerPathOverrides` |
|
|
164
|
+
| `options: WorkerAdapterOptions` | `options?: SpawnOptions` (`{ timeout?, batchSize? }`) |
|
|
165
|
+
| `options.isLocalDevelopment`, `local` / `--local` argv | removed; set `AIRSYNC_LOCAL_DEVELOPMENT=1` |
|
|
166
|
+
|
|
167
|
+
```ts
|
|
168
|
+
// v1
|
|
169
|
+
spawn({
|
|
170
|
+
event,
|
|
171
|
+
initialState,
|
|
172
|
+
workerPath: __dirname + '/workers/data-extraction',
|
|
173
|
+
options: { isLocalDevelopment: true, workerPathOverrides: { [EventType.StartExtractingData]: '/workers/custom' } },
|
|
174
|
+
});
|
|
175
|
+
// v2
|
|
176
|
+
spawn({
|
|
177
|
+
event,
|
|
178
|
+
initialState,
|
|
179
|
+
baseWorkerPath: __dirname,
|
|
180
|
+
workerPathOverrides: { [EventType.StartExtractingData]: '/workers/custom' },
|
|
181
|
+
});
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
- If `workerPath` came from a dispatcher helper (e.g.
|
|
185
|
+
`getWorkerPerLoadingPhase(event)`), delete the helper and its now-unused
|
|
186
|
+
imports.
|
|
187
|
+
- **Fixture and test events** must use the modern event-type strings; v1
|
|
188
|
+
translated legacy ones and v2 doesn't. Replace `EXTRACTION_EXTERNAL_SYNC_UNITS_START`,
|
|
189
|
+
`EXTRACTION_METADATA_START`, `EXTRACTION_DATA_START` / `_CONTINUE` / `_DELETE`
|
|
190
|
+
and `EXTRACTION_ATTACHMENTS_START` / `_CONTINUE` / `_DELETE` with
|
|
191
|
+
`START_EXTRACTING_EXTERNAL_SYNC_UNITS`, `START_EXTRACTING_METADATA`,
|
|
192
|
+
`START_EXTRACTING_DATA` / `CONTINUE_EXTRACTING_DATA` /
|
|
193
|
+
`START_DELETING_EXTRACTOR_STATE` and `START_EXTRACTING_ATTACHMENTS` /
|
|
194
|
+
`CONTINUE_EXTRACTING_ATTACHMENTS` / `START_DELETING_EXTRACTOR_ATTACHMENTS_STATE`.
|
|
195
|
+
- **Local mode** comes only from the `AIRSYNC_LOCAL_DEVELOPMENT=1` environment
|
|
196
|
+
variable, and is ignored on Lambda. v1 also enabled it from a bare `local`
|
|
197
|
+
argument, which the template test server receives (`main.ts local --port …`,
|
|
198
|
+
also used by `airsync start-worker`). v2 ignores both `local` and `--local`
|
|
199
|
+
without an error: logs come out as production JSON and no copies land in
|
|
200
|
+
`extracted_files/`. A local runner that did `process.argv.push('--local')`
|
|
201
|
+
or relied on the `local` argument sets
|
|
202
|
+
`process.env.AIRSYNC_LOCAL_DEVELOPMENT = '1'` before calling `spawn` instead,
|
|
203
|
+
or documents running the worker with `AIRSYNC_LOCAL_DEVELOPMENT=1`.
|
|
204
|
+
|
|
205
|
+
## 4. Workers return a `TaskResult` instead of emitting
|
|
206
|
+
|
|
207
|
+
`adapter.emit` is gone (a compile error). A task reports how the phase ended by
|
|
208
|
+
returning a result; the SDK picks the platform event and emits it exactly once.
|
|
209
|
+
|
|
210
|
+
```ts
|
|
211
|
+
export type TaskResult =
|
|
212
|
+
| { status: 'success' }
|
|
213
|
+
| { status: 'progress' }
|
|
214
|
+
| { status: 'delay'; delaySeconds: number }
|
|
215
|
+
| { status: 'error'; error: ErrorRecord }; // { message: string; code?: AirSyncErrorCode }
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
Replace `processTask` with `processExtractionTask` or `processLoadingTask`,
|
|
219
|
+
depending on the worker (extraction workers use repos or `streamAttachments`;
|
|
220
|
+
loading workers use `loadItemTypes` or `loadAttachments`). Their
|
|
221
|
+
generic stays the connector state: `processTask<State>` →
|
|
222
|
+
`processExtractionTask<State>`.
|
|
223
|
+
|
|
224
|
+
```ts
|
|
225
|
+
// v1
|
|
226
|
+
processTask({
|
|
227
|
+
task: async ({ adapter }) => {
|
|
228
|
+
// ...
|
|
229
|
+
await adapter.emit(ExtractorEventType.DataExtractionDone);
|
|
230
|
+
},
|
|
231
|
+
onTimeout: async ({ adapter }) => {
|
|
232
|
+
await adapter.postState();
|
|
233
|
+
await adapter.emit(ExtractorEventType.DataExtractionProgress);
|
|
234
|
+
},
|
|
235
|
+
});
|
|
236
|
+
// v2
|
|
237
|
+
processExtractionTask({
|
|
238
|
+
task: async ({ adapter }) => {
|
|
239
|
+
// ...
|
|
240
|
+
return { status: 'success' };
|
|
241
|
+
},
|
|
242
|
+
});
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
| v1 | v2 |
|
|
246
|
+
|----|----|
|
|
247
|
+
| `emit(XxxDone)` | `return { status: 'success' }` |
|
|
248
|
+
| `emit(XxxProgress, { progress })` | `return { status: 'progress' }` |
|
|
249
|
+
| `emit(XxxDelayed, { delay })` | `return { status: 'delay', delaySeconds: delay }` — keep the same number; the platform always read it as seconds. If it is clearly milliseconds or a raw `Retry-After` header, keep the behavior (`Number(header)`) and flag it in the review |
|
|
250
|
+
| `emit(XxxDelayed)` with no `delay` | `delaySeconds` is required; use the connector's existing default retry constant, else `0` (what v1 effectively sent), and flag it |
|
|
251
|
+
| `emit(XxxError, { error })` | `return { status: 'error', error }` — `error` is required; fall back to `{ message: '<phase> failed' }` |
|
|
252
|
+
| `emit(XxxDone, { error })` (finished with warnings) | `return { status: 'success' }` and log the error. Returning `error` would fail the phase |
|
|
253
|
+
| `emit(ExternalSyncUnitExtractionDone, { external_sync_units })` | push to a repo, then `success` (§7) |
|
|
254
|
+
| `emit(MetadataExtractionDone, { pre_extraction_item_counts })` | `adapter.preExtractionItemCounts = counts`, then `success` |
|
|
255
|
+
| a path that **emitted nothing** (a `catch` that only logs, a branch that falls through) | `{ status: 'error', error: { message } }`, or rethrow. In v1 the SDK reported these as a phase error ("Worker exited without emitting"); never turn them into `success` or `progress` |
|
|
256
|
+
| any `emit(XxxDone)` after `loadItemTypes` / `loadAttachments` / `streamAttachments`, guarded (`!adapter.hasWorkerEmitted && !adapter.isTimeout`) or not | `return adapter.loadItemTypes(...)` (or the other call). Never discard their result and return `success`: v1 emitted their `delay` / `error` itself. Drop the guard and any module-level "already emitted" flags |
|
|
257
|
+
|
|
258
|
+
In non-resumable phases (external sync units, state deletion), `progress` and
|
|
259
|
+
`delay` become `*Error`.
|
|
260
|
+
|
|
261
|
+
**Emits inside helpers.** Only the task's return value reaches the SDK, so a
|
|
262
|
+
helper that emitted must hand its result back up. Either return
|
|
263
|
+
`TaskResult | null` up the call chain (`null` = keep going), or record it and
|
|
264
|
+
return it once the loop ends:
|
|
265
|
+
|
|
266
|
+
```ts
|
|
267
|
+
private result: TaskResult | undefined;
|
|
268
|
+
private onPermissionDenied() {
|
|
269
|
+
this.result = { status: 'error', error: { message: '...' } };
|
|
270
|
+
}
|
|
271
|
+
// at the end of the task: a recorded result, else continue only on timeout
|
|
272
|
+
return this.result ?? (adapter.isTimeout
|
|
273
|
+
? { status: 'progress' }
|
|
274
|
+
: { status: 'error', error: { message: 'Extraction ended without a result' } });
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
If a shared `handleError` emitted from many `catch` blocks that rethrow, v1
|
|
278
|
+
kept only the first emit. Record the first result (`firstError ??= …`) and
|
|
279
|
+
return it from the task's outermost `catch`.
|
|
280
|
+
|
|
281
|
+
If a helper **emitted and then kept going** (no throw), the caller often
|
|
282
|
+
emitted again later, e.g. `DataExtractionDone` after the loop, and v1 dropped
|
|
283
|
+
every emit after the first. Record the first result the same way, stop the
|
|
284
|
+
work that followed it (return out of the loop or extractor), and return it
|
|
285
|
+
from the task. Unawaited emits inside loops count too.
|
|
286
|
+
|
|
287
|
+
If a helper (often the HTTP client's 429 handler) **emitted and then threw a
|
|
288
|
+
sentinel error** that call sites rethrow, keep the throw, drop the emit, and map
|
|
289
|
+
it in the task's outermost `catch`:
|
|
290
|
+
`if (e instanceof RateLimitDelayedError) return { status: 'delay', delaySeconds: e.retryAfterSeconds };`.
|
|
291
|
+
Don't let it reach a generic error branch, or every rate limit fails the sync.
|
|
292
|
+
In external sync units (non-resumable) the SDK still sends `delay` as an
|
|
293
|
+
error; that matches nothing better, so keep it and flag it in the review.
|
|
294
|
+
|
|
295
|
+
Tests of helpers that now record a result read it back
|
|
296
|
+
(`expect(extractor['result']).toEqual(…)`) or, for `TaskResult | null`
|
|
297
|
+
helpers, assert on the return value.
|
|
298
|
+
|
|
299
|
+
**Timeouts.**
|
|
300
|
+
|
|
301
|
+
- In the **task body**, `if (adapter.isTimeout) return;` becomes
|
|
302
|
+
`return { status: 'progress' };`. The same applies to a `return;` in a
|
|
303
|
+
`catch` that handles a timeout (`if (adapter.isTimeout || e instanceof
|
|
304
|
+
MyTimeout) return;`). Early `return`s inside `Promise<void>` helpers stay as
|
|
305
|
+
they are, as long as the task checks `isTimeout` after calling them.
|
|
306
|
+
- After the soft timeout, a returned `progress` is replaced by the
|
|
307
|
+
`onTimeout` result, and so is a returned `success` in resumable phases
|
|
308
|
+
(metadata, data, attachments, loading). A returned `error` or `delay`, and
|
|
309
|
+
a `success` in external sync units or state deletion, are emitted as is.
|
|
310
|
+
- `onTimeout` is optional and defaults to `progress` (or a timeout error in
|
|
311
|
+
external sync units and state deletion). v1 ran `onTimeout` only when the
|
|
312
|
+
task finished **without emitting**; v2 also runs it when a resumable task
|
|
313
|
+
returns `success` after the timeout, which costs one extra `PROGRESS` →
|
|
314
|
+
`CONTINUE` round instead of `DONE`. So:
|
|
315
|
+
- **Delete** it when it only emitted the usual event or computed a
|
|
316
|
+
`progress` number, when the v1 task emitted on every path, or when the task
|
|
317
|
+
only returns `loadItemTypes` / `loadAttachments` / `streamAttachments`
|
|
318
|
+
(they handled the timeout themselves).
|
|
319
|
+
- **Keep** it, returning a `TaskResult`, only when it could actually run in
|
|
320
|
+
v1 (the task had a path that didn't emit) **and** it did real work or set a
|
|
321
|
+
custom error. Make its body safe to run after a completed task. A custom
|
|
322
|
+
"Lambda timeout" `onTimeout` on a task that emits on every path is
|
|
323
|
+
deleted; v1 never ran it.
|
|
324
|
+
- Don't call `process.exit()` or `postState()` in `onTimeout`; the SDK saves
|
|
325
|
+
state and exits.
|
|
326
|
+
|
|
327
|
+
**Throws.** A task that throws emits the phase's `*Error` with the message,
|
|
328
|
+
along with the artifacts already uploaded. `repo.push()` and `repo.upload()`
|
|
329
|
+
resolve `void` and throw if an upload fails. **Any use of `push()`'s value is
|
|
330
|
+
now wrong**, and `Boolean(await repo.push(x))` or `if (!(await …push(x)))`
|
|
331
|
+
compiles but is always falsy. Make wrappers `await repo.push(x)` and return
|
|
332
|
+
`true` (or `void`). Keep a top-level `try/catch` that maps an error to `delay`
|
|
333
|
+
(e.g. a thrown 429); otherwise it's only needed for a custom message.
|
|
334
|
+
`loadItemTypes` and `loadAttachments` don't throw: a `create` / `update` that
|
|
335
|
+
throws becomes their `error` result, so a 429 must be returned as
|
|
336
|
+
`{ status: 'delay', delaySeconds }` from the callback (§6). A `catch` around
|
|
337
|
+
them that checks `isAxiosError(e) && status === 429` is dead; delete it.
|
|
338
|
+
|
|
339
|
+
`ProcessTaskInterface<T>` and `TaskAdapterInterface<T>` now take the
|
|
340
|
+
**adapter** type: `ProcessTaskInterface<ExtractionAdapter<State>>`, not
|
|
341
|
+
`<State>`.
|
|
342
|
+
|
|
343
|
+
## 5. Adapters
|
|
344
|
+
|
|
345
|
+
The `WorkerAdapter` class is gone. Annotate with the phase's adapter:
|
|
346
|
+
|
|
347
|
+
```ts
|
|
348
|
+
async function extractList(adapter: ExtractionAdapter<State>) { ... }
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
| Members | On |
|
|
352
|
+
|---------|----|
|
|
353
|
+
| `initializeRepos`, `getRepo`, `streamAttachments`, `processAttachment`, `shouldExtract`, `artifacts`, `preExtractionItemCounts` | `ExtractionAdapter` |
|
|
354
|
+
| `loadItemTypes`, `loadAttachments`, `reports`, `processedFiles` | `LoadingAdapter` |
|
|
355
|
+
| `event`, `state`, `mappers`, `postState`, `uploadArtifact`, `downloadArtifact`, `isTimeout`, `extractionScope` | both |
|
|
356
|
+
|
|
357
|
+
- The adapters and `Repo` are **type-only**: `new ExtractionAdapter(...)` and
|
|
358
|
+
`class X extends LoadingAdapter<S>` don't compile; `interface X extends …`
|
|
359
|
+
does. SDK internals (`emit`, `sdkState`, `options`, constructors, …) aren't
|
|
360
|
+
public. `isTimeout` and `artifacts` are read-only.
|
|
361
|
+
- `adapter.mappers` works in extraction as in v1; keep those calls and only
|
|
362
|
+
apply the §10 return-shape changes.
|
|
363
|
+
- **Integration tests** that built an adapter by hand use the root factories:
|
|
364
|
+
|
|
365
|
+
```ts
|
|
366
|
+
// v1
|
|
367
|
+
const adapter = new WorkerAdapter({ event, adapterState: new State({ event, initialState }) });
|
|
368
|
+
adapterState.state.fromDevRev = { filesToLoad };
|
|
369
|
+
// v2
|
|
370
|
+
const adapter = createTestExtractionAdapter({ event, initialState });
|
|
371
|
+
const loader = createTestLoadingAdapter({ event, initialState, filesToLoad });
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
Platform calls still go to the event's URLs. Build the event with
|
|
375
|
+
`createMockEvent(mockServer.baseUrl, …)` and serve the URLs with
|
|
376
|
+
`MockServer`. Artifact downloads need two routes: `GET
|
|
377
|
+
/internal/airdrop.artifacts.download-url` returning `{ download_url }`, and
|
|
378
|
+
that URL serving the gzipped JSONL. Assert on the returned `TaskResult`,
|
|
379
|
+
`adapter.reports` and `adapter.processedFiles`, not on `emit` or SDK state;
|
|
380
|
+
to test a resume, build a second adapter with `filesToLoad` at the cursor you
|
|
381
|
+
expect. To simulate a timeout, use a plain mock object, not a real adapter.
|
|
382
|
+
Test repos are plain objects (`{ itemType, push: jest.fn() }`).
|
|
383
|
+
- `adapter.postState()` takes no argument and **throws** on failure (v1 exited
|
|
384
|
+
the process). State is saved on every emit, so keep a call only to save
|
|
385
|
+
state before an external write that must not be repeated. v1
|
|
386
|
+
`postState(next)` becomes `adapter.state = next; await adapter.postState();`.
|
|
387
|
+
|
|
388
|
+
## 6. Loading, attachments and callback results
|
|
389
|
+
|
|
390
|
+
`loadItemTypes`, `loadAttachments` and `streamAttachments` return a
|
|
391
|
+
`TaskResult`. Return it directly:
|
|
392
|
+
|
|
393
|
+
```ts
|
|
394
|
+
processLoadingTask({ task: async ({ adapter }) => adapter.loadItemTypes({ itemTypesToLoad }) });
|
|
395
|
+
processExtractionTask({ task: async ({ adapter }) => adapter.streamAttachments({ stream }) });
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
The result has no `reports` / `processed_files`. To add a report, push it to
|
|
399
|
+
`adapter.reports` before returning. Tests assert on `adapter.reports`.
|
|
400
|
+
|
|
401
|
+
**Connector callbacks** return a `status` union, like `TaskResult`:
|
|
402
|
+
|
|
403
|
+
| Callback | v1 | v2 |
|
|
404
|
+
|----------|----|----|
|
|
405
|
+
| attachment `stream` | `{ httpStream }` / `{ delay }` / `{ error: { message, statusCode? } }` | `{ status: 'success', httpStream }` / `{ status: 'delay', delaySeconds }` / `{ status: 'error', error: { message } }` |
|
|
406
|
+
| loader `create` / `update` | `{ id, modifiedDate? }` / `{ delay }` / `{ error: 'msg' \| { message } }` / neither (counted as failed) | `{ status: 'success', id, modifiedDate? }` / `{ status: 'delay', delaySeconds }` / `{ status: 'error', error: { message } }` |
|
|
407
|
+
| `adapter.processAttachment`, custom `iterator` | `{ delay? , error? } \| undefined` | `{ status: 'success' }` / `{ status: 'delay', delaySeconds }` / `{ status: 'error', error }` |
|
|
408
|
+
|
|
409
|
+
```ts
|
|
410
|
+
// custom iterator, v2
|
|
411
|
+
const response = await adapter.processAttachment(attachment, stream);
|
|
412
|
+
if (response.status === 'delay') return response;
|
|
413
|
+
if (response.status === 'error') console.warn(response.error.message);
|
|
414
|
+
// ...
|
|
415
|
+
return { status: 'success' }; // was a bare `return;`
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
- Loader `error` results still count as failed and loading continues. A v1
|
|
419
|
+
result with **both** `delay` and `error` becomes `delay` (v1 honored the delay).
|
|
420
|
+
- `success` needs a real `id`: a v1 `{ id }` whose value may be `undefined`
|
|
421
|
+
(from an untyped response) was counted as failed, so guard it:
|
|
422
|
+
`if (!id) return { status: 'error', error: { message } }`. Extra fields such
|
|
423
|
+
as `skip` are dropped; every `success` creates or updates a mapper record.
|
|
424
|
+
- Shared helpers typed as these responses change too. Callers that read
|
|
425
|
+
`result.delay` or interpolate `${result.error}` (now an object) switch on
|
|
426
|
+
`result.status`.
|
|
427
|
+
- An error `code` returned from the stream callback is only logged; the pool
|
|
428
|
+
skips that attachment.
|
|
429
|
+
- `httpStream` is typed `HttpStreamResponse` (`{ data, headers }`); an axios
|
|
430
|
+
response still satisfies it. Types derived by indexing the old interface
|
|
431
|
+
(`ExternalSystemAttachmentStreamingResponse['httpStream']`) use the root
|
|
432
|
+
`HttpStreamResponse` instead.
|
|
433
|
+
- `statusCode` on stream errors is gone; put it in the message if you need it.
|
|
434
|
+
|
|
435
|
+
**`processAttachment` works in any extraction phase.** SSOR artifacts created
|
|
436
|
+
outside the attachments phase are held by the SDK and reported with
|
|
437
|
+
`ATTACHMENT_EXTRACTION_DONE`. **Delete any workaround** for this, along with
|
|
438
|
+
its state fields and tests. Workarounds typically override the
|
|
439
|
+
`ssor_attachment` repo's `onUpload`, splice `uploadedArtifacts`, adjust
|
|
440
|
+
`currentEventDataLength`, or stash artifact refs in state.
|
|
441
|
+
|
|
442
|
+
## 7. External sync units go through a repo
|
|
443
|
+
|
|
444
|
+
`EventData.external_sync_units` is removed. Push them to a repo:
|
|
445
|
+
|
|
446
|
+
```ts
|
|
447
|
+
adapter.initializeRepos([
|
|
448
|
+
// matches the batching v1 used for the inline path
|
|
449
|
+
{ itemType: AirSyncDefaultItemTypes.EXTERNAL_SYNC_UNITS, overriddenOptions: { batchSize: 25000 } },
|
|
450
|
+
]);
|
|
451
|
+
await adapter.getRepo(AirSyncDefaultItemTypes.EXTERNAL_SYNC_UNITS)?.push(externalSyncUnits);
|
|
452
|
+
return { status: 'success' };
|
|
453
|
+
```
|
|
454
|
+
|
|
455
|
+
If the connector already pushed ESUs to a repo, keep its options as they are
|
|
456
|
+
(apart from the §14 rename and removing `skipConfirmation`) and only convert
|
|
457
|
+
the emit.
|
|
458
|
+
|
|
459
|
+
## 8. State: connector state only
|
|
460
|
+
|
|
461
|
+
- `adapter.state` is the connector's own state (the `initialState` shape);
|
|
462
|
+
reads and writes work as before. SDK bookkeeping (`toDevRev`, `fromDevRev`,
|
|
463
|
+
`workers*`, `pendingWorkers*`, `lastSyncStarted`,
|
|
464
|
+
`lastSuccessfulSyncStarted`, `snapInVersionId`) is internal. The
|
|
465
|
+
`AdapterState<S>` alias is removed; use your own `State` type.
|
|
466
|
+
- **Persisted state** becomes `{ stateVersion: 2, connectorState, sdkState }`.
|
|
467
|
+
A v1 blob is migrated automatically on first read: known SDK keys move to
|
|
468
|
+
`sdkState` and everything else becomes connector state. **Rolling back to v1
|
|
469
|
+
after a v2 worker has run is not supported**; drain or reset syncs first. A
|
|
470
|
+
v1 state with a top-level key named `connectorState` or `sdkState` is
|
|
471
|
+
misread; rename it before upgrading.
|
|
472
|
+
- **Sync window**: read
|
|
473
|
+
`adapter.event.payload.event_context.extract_from` / `extract_to`. The SDK
|
|
474
|
+
resolves them from the platform's time values, or from the last successful
|
|
475
|
+
sync on platforms that don't send them.
|
|
476
|
+
- Remove SDK fields (`toDevRev`, `fromDevRev`, …) from the connector's own
|
|
477
|
+
`State` interface, `getInitialState` and fixtures.
|
|
478
|
+
|
|
479
|
+
**`lastSyncStarted` / `lastSuccessfulSyncStarted`: rename or repoint.**
|
|
480
|
+
Getting this wrong compiles but silently breaks incremental sync.
|
|
481
|
+
|
|
482
|
+
- **Not in the connector's `State` interface** (it came from the SDK): delete
|
|
483
|
+
writes, and repoint reads to `extract_from`.
|
|
484
|
+
- **Declared and used as the connector's own cursor** (derived from data, or
|
|
485
|
+
read alongside `extract_from`): **rename** it (e.g. →
|
|
486
|
+
`lastSuccessfulWindowStart`) everywhere, including fixtures. Otherwise the v1
|
|
487
|
+
auto-migration moves it into SDK state and the connector loses it.
|
|
488
|
+
- **Declared but only mirrors the SDK**: its only writes are "now" when data
|
|
489
|
+
extraction starts and a copy on finish. Treat it as not declared, **even if
|
|
490
|
+
it is read next to `extract_from`**. Renaming would leave it empty after the
|
|
491
|
+
upgrade, because the v1 value moves into SDK state.
|
|
492
|
+
|
|
493
|
+
`extract_from` equals the last successful sync start only when the platform
|
|
494
|
+
sends no time window. If a repointed read feeds logic beyond "skip items older
|
|
495
|
+
than this" (e.g. distinguishing first syncs), flag it as low confidence; there
|
|
496
|
+
is no public "last successful sync" value. Fixtures move from
|
|
497
|
+
`adapter.state.lastSuccessfulSyncStarted = X` to
|
|
498
|
+
`event.payload.event_context.extract_from = X`.
|
|
499
|
+
|
|
500
|
+
## 9. HTTP: bring your own axios client
|
|
501
|
+
|
|
502
|
+
`axios`, `axiosClient`, `formatAxiosError`, `serializeAxiosError` and
|
|
503
|
+
`HTTPResponse` are no longer exported. Add `axios` (and `axios-retry` for a
|
|
504
|
+
retrying client) to the connector's dependencies.
|
|
505
|
+
|
|
506
|
+
- **`axios`** (v1 re-exported plain axios, without retries) →
|
|
507
|
+
`import axios from 'axios'`. Calls stay as they are; don't route them through
|
|
508
|
+
a retrying client.
|
|
509
|
+
- **`axiosClient`** → the connector's own client, in its own module (e.g.
|
|
510
|
+
`src/http/axios-client.ts`), so tests can mock that module:
|
|
511
|
+
|
|
512
|
+
```ts
|
|
513
|
+
import axios from 'axios';
|
|
514
|
+
import axiosRetry from 'axios-retry';
|
|
515
|
+
|
|
516
|
+
export const axiosClient = axios.create();
|
|
517
|
+
axiosRetry(axiosClient, {
|
|
518
|
+
retries: 5,
|
|
519
|
+
retryDelay: (retryCount, error) => axiosRetry.exponentialDelay(retryCount, error, 1000),
|
|
520
|
+
retryCondition: (error) =>
|
|
521
|
+
(axiosRetry.isNetworkOrIdempotentRequestError(error) && error.response?.status !== 429) ||
|
|
522
|
+
(error.response?.status ?? 0) >= 500,
|
|
523
|
+
onMaxRetryTimesExceeded: (error) => {
|
|
524
|
+
delete error.config?.headers?.authorization;
|
|
525
|
+
delete error.config?.headers?.Authorization;
|
|
526
|
+
delete error.request?._header;
|
|
527
|
+
},
|
|
528
|
+
});
|
|
529
|
+
```
|
|
530
|
+
|
|
531
|
+
A deep import of the SDK's internal client (`dist/http/axios-client-internal`)
|
|
532
|
+
relied on more: a 30 s timeout, retries of 429s that send `Retry-After` (waiting
|
|
533
|
+
that long) and of `ECONNABORTED`. Reproduce what the connector depends on with
|
|
534
|
+
`axios.create({ timeout: 30_000 })`, `shouldResetTimeout: true`, and a
|
|
535
|
+
`retryCondition` / `retryDelay` that honor `Retry-After`.
|
|
536
|
+
|
|
537
|
+
For logging, use the root `serializeError(error)`, which returns a string.
|
|
538
|
+
For an axios error it is JSON of the request method, URL and params plus the
|
|
539
|
+
response status and body, without headers. Interpolating `serializeAxiosError`
|
|
540
|
+
printed `[object Object]` in v1, so such messages now carry these details.
|
|
541
|
+
Where `serializeAxiosError(e)` was used as an object (spread, or `.response`),
|
|
542
|
+
build the fields you need from the axios error yourself, leaving out headers.
|
|
543
|
+
|
|
544
|
+
## 10. Mappers
|
|
545
|
+
|
|
546
|
+
| Method | v1 | v2 |
|
|
547
|
+
|--------|----|----|
|
|
548
|
+
| `getByTargetId`, `getByExternalId` | `AxiosResponse<T>`; rejects with 404 when missing | `T \| null`; `null` when no record exists |
|
|
549
|
+
| `create`, `update` | `AxiosResponse<T>` | `T` |
|
|
550
|
+
| any other failure | axios error | `AirSyncHttpError` (`message`, `status?`), exported from the root |
|
|
551
|
+
|
|
552
|
+
```ts
|
|
553
|
+
// v1
|
|
554
|
+
try {
|
|
555
|
+
const res = await mappers.getByTargetId({ sync_unit, target });
|
|
556
|
+
return res.data.sync_mapper_record.external_ids[0];
|
|
557
|
+
} catch (e) {
|
|
558
|
+
if (axios.isAxiosError(e) && e.response?.status === 404) return undefined;
|
|
559
|
+
throw e;
|
|
560
|
+
}
|
|
561
|
+
// v2
|
|
562
|
+
const record = await mappers.getByTargetId({ sync_unit, target });
|
|
563
|
+
return record?.sync_mapper_record.external_ids[0];
|
|
564
|
+
```
|
|
565
|
+
|
|
566
|
+
- Drop `.data`; loosely typed code would otherwise read `undefined`.
|
|
567
|
+
- **Existence checks invert silently.** `try { await mappers.getByExternalId(…); return true; } catch { return false; }`
|
|
568
|
+
now always returns `true`, because a missing record resolves `null`. Rewrite
|
|
569
|
+
the `try` body as `return (await mappers.getByExternalId(…)) !== null;` and
|
|
570
|
+
**keep the `catch`** if v1 had one, so other failures still mean what they
|
|
571
|
+
meant before. Find these with
|
|
572
|
+
`grep -n "getByExternalId\|getByTargetId"`, not by searching for 404.
|
|
573
|
+
- Hand-written structural types (`{ getByTargetId(): Promise<{ data?: … }> }`)
|
|
574
|
+
keep `.data` compiling. Replace them with `Pick<Mappers, 'getByTargetId'>`.
|
|
575
|
+
- Replace 404 `catch` branches with a `null` check.
|
|
576
|
+
- A **generic `catch`** around a lookup (no 404 test) also handled "not
|
|
577
|
+
found": it reported an item error, logged a warning or tried the next ID.
|
|
578
|
+
With `null` that path no longer runs, so add a `null` branch that does what
|
|
579
|
+
the `catch` did, and keep the `catch` for other failures.
|
|
580
|
+
- Replace `isAxiosError` checks on mapper calls with
|
|
581
|
+
`e instanceof AirSyncHttpError` / `e.status`. Checks on the connector's own
|
|
582
|
+
HTTP calls stay.
|
|
583
|
+
- Test doubles: `mockResolvedValue({ data: { sync_mapper_record } })` →
|
|
584
|
+
`mockResolvedValue({ sync_mapper_record })`; a 404 `mockRejectedValue(...)`
|
|
585
|
+
or a "not found" `mockResolvedValue({ data: {} })` → `mockResolvedValue(null)`.
|
|
586
|
+
Find them with `grep sync_mapper_record`.
|
|
587
|
+
|
|
588
|
+
## 11. Removed symbols
|
|
589
|
+
|
|
590
|
+
| Removed | Replacement |
|
|
591
|
+
|---------|-------------|
|
|
592
|
+
| `ExtractorEventType`, `LoaderEventType` | none; return a `TaskResult` (§4), and in tests assert on it. Compare against the raw wire string if really needed |
|
|
593
|
+
| `ExtractionCommonError` | `AirSyncErrorCode` on `error.code` (§12) |
|
|
594
|
+
| `WorkerAdapterOptions` | `SpawnOptions` (spawn), `RepoOptions` (`overriddenOptions`) |
|
|
595
|
+
| `WorkerAdapterInterface`, `SpawnInterface`, `StreamResponse`, `StreamAttachmentsResponse` | none; drop the import |
|
|
596
|
+
| `ArtifactsPrepareResponse` | none; if the connector uses it as its own type, declare it locally (`{ url: string; id: string; form_data: { key: string; value: string }[] }`) |
|
|
597
|
+
| worker IPC types (`WorkerEvent`, `WorkerMessage*`, `WorkerData`, `GetWorkerPathInterface`) | none; assert on the returned `TaskResult` |
|
|
598
|
+
| `State`, `createAdapterState`, `ToDevRev`, `AdapterState` | `createTest*Adapter` (§5); drop SDK state types (§8) |
|
|
599
|
+
| `Uploader` (deep import of `dist/uploader/uploader`, used to store and read back the connector's own artifacts) | `adapter.uploadArtifact(itemType, data)` → `{ id }` and `adapter.downloadArtifact<T>(id)` → `T[]`; both throw instead of returning `{ error }` |
|
|
600
|
+
| `Adapter`, `createAdapter`, `DemoExtractor`, `HTTPClient`, `defaultResponse`, deprecated `Uploader` | the v2 worker contract, your own axios client, repos |
|
|
601
|
+
| `ExtractionMode` | `SyncMode` |
|
|
602
|
+
| `EventContextIn`, `EventContextOut` | `EventContext` |
|
|
603
|
+
| `DomainObjectState`, `ErrorLevel`, `LogRecord`, `AdapterUpdateParams` | none |
|
|
604
|
+
| `translate*EventType` helpers | none; the platform sends modern strings |
|
|
605
|
+
| `EventType.UnknownEventType` | the string `'UNKNOWN_EVENT_TYPE'` |
|
|
606
|
+
| `adapter.hasWorkerEmitted`, `adapter.emit` spies | none; return / assert on the `TaskResult` (§4, §13) |
|
|
607
|
+
| `EventData.progress`, `EventData.external_sync_units` | none (§4, §7) |
|
|
608
|
+
|
|
609
|
+
Deprecated `EventType` members are removed. They had **different** string
|
|
610
|
+
values from their replacements:
|
|
611
|
+
|
|
612
|
+
| Removed | Use |
|
|
613
|
+
|---------|-----|
|
|
614
|
+
| `ExtractionExternalSyncUnitsStart` | `StartExtractingExternalSyncUnits` |
|
|
615
|
+
| `ExtractionMetadataStart` | `StartExtractingMetadata` |
|
|
616
|
+
| `ExtractionDataStart` / `ExtractionDataContinue` | `StartExtractingData` / `ContinueExtractingData` |
|
|
617
|
+
| `ExtractionDataDelete` | `StartDeletingExtractorState` |
|
|
618
|
+
| `ExtractionAttachmentsStart` / `ExtractionAttachmentsContinue` | `StartExtractingAttachments` / `ContinueExtractingAttachments` |
|
|
619
|
+
| `ExtractionAttachmentsDelete` | `StartDeletingExtractorAttachmentsState` |
|
|
620
|
+
|
|
621
|
+
This also applies to `workerPathOverrides` keys. `EventType` can gain members
|
|
622
|
+
in minor versions, so give `switch` statements over it a `default`.
|
|
623
|
+
|
|
624
|
+
## 12. Error codes
|
|
625
|
+
|
|
626
|
+
`ExtractionCommonError` is now `AirSyncErrorCode`. Its values are bare codes,
|
|
627
|
+
and you set them on `error.code`:
|
|
628
|
+
|
|
629
|
+
```ts
|
|
630
|
+
// v1
|
|
631
|
+
return { status: 'error', error: { message: ExtractionCommonError.EXTERNAL_SYNC_UNIT_DELETED } };
|
|
632
|
+
// v2
|
|
633
|
+
return {
|
|
634
|
+
status: 'error',
|
|
635
|
+
error: { message: `Project ${id} was deleted.`, code: AirSyncErrorCode.EXTERNAL_SYNC_UNIT_DELETED },
|
|
636
|
+
};
|
|
637
|
+
```
|
|
638
|
+
|
|
639
|
+
The platform only recognizes a code when the message is exactly
|
|
640
|
+
`ERROR_CODE=<code>`, so the SDK sends just that and logs your `message`. Write
|
|
641
|
+
a useful `message`. Raw `'ERROR_CODE=…'` strings and connector helpers that
|
|
642
|
+
return them (`HISTORICAL_DONE`, `authErrorCode(e)`) still work at runtime but
|
|
643
|
+
are migrated too: make the helper return `AirSyncErrorCode | undefined`, set it
|
|
644
|
+
as `code`, and update tests that pin the literal. The wire string doesn't
|
|
645
|
+
change.
|
|
646
|
+
|
|
647
|
+
## 13. Tests
|
|
648
|
+
|
|
649
|
+
- Mock factories: `processTask` → `processExtractionTask` /
|
|
650
|
+
`processLoadingTask`. Drop the `WorkerAdapter`, `axios`, `axiosClient` and
|
|
651
|
+
`emit: jest.fn()` keys; if nothing is left, or the file under test never
|
|
652
|
+
imports the SDK, delete the `jest.mock` entirely. Keep `jest.requireActual`
|
|
653
|
+
only for enums that still exist (`EventType`, `SyncMode`, `AirSyncErrorCode`).
|
|
654
|
+
- HTTP mocks: a test that mocked the SDK's `axiosClient` mocks the connector's
|
|
655
|
+
client module instead (`jest.mock('../http/axios-client', () => ({ axiosClient: { get: jest.fn(), post: jest.fn() } }))`).
|
|
656
|
+
Don't automock `axios` when the source calls `axios.create()`, because the
|
|
657
|
+
client becomes `undefined`. For plain `axios` use
|
|
658
|
+
`jest.mock('axios', () => ({ __esModule: true, default: { get: jest.fn(), isAxiosError: jest.fn() }, AxiosError: jest.requireActual('axios').AxiosError }))`.
|
|
659
|
+
Patching a client's `defaults.adapter` now affects only connector traffic.
|
|
660
|
+
- ESU tests assert on the repo: give the mock adapter
|
|
661
|
+
`initializeRepos: jest.fn()` and `getRepo: () => ({ push: mockPush })`, then
|
|
662
|
+
check `mockPush.mock.calls[0][0]`.
|
|
663
|
+
- Replace emit assertions with assertions on the returned result. This applies
|
|
664
|
+
to helpers you call directly too.
|
|
665
|
+
```ts
|
|
666
|
+
const result = await mockProcessTask.mock.calls[0][0].task({ adapter });
|
|
667
|
+
expect(result).toEqual({ status: 'success' });
|
|
668
|
+
```
|
|
669
|
+
- Casts like `as unknown as WorkerAdapter<S>` become `ExtractionAdapter<S>` /
|
|
670
|
+
`LoadingAdapter<S>`.
|
|
671
|
+
- Update doubles and fixtures to the v2 shapes: `delaySeconds`, callback
|
|
672
|
+
`status` unions (§6), mapper `null` / unwrapped bodies (§10), `code` on
|
|
673
|
+
errors (§12), renamed state fields and the removed SDK fields (§8).
|
|
674
|
+
- For a deleted `onTimeout`, drop the tests of its body and assert it's
|
|
675
|
+
`undefined`. A factory like `processExtractionTask: (_config) => jest.fn()`
|
|
676
|
+
discards the config; use `processExtractionTask: jest.fn()` and read
|
|
677
|
+
`mocked.mock.calls[0][0].onTimeout`. Tests of a deleted SSOR workaround go with it.
|
|
678
|
+
|
|
679
|
+
## 14. Smaller changes
|
|
680
|
+
|
|
681
|
+
- `RepoInterface.overridenOptions` → `overriddenOptions`.
|
|
682
|
+
- `skipConfirmation` is removed; the SDK handles the ESU repo itself.
|
|
683
|
+
- `NormalizedAttachment.grand_parent_id` is `string`; use `String(id)`.
|
|
684
|
+
|
|
685
|
+
---
|
|
686
|
+
|
|
687
|
+
## Rare cases
|
|
688
|
+
|
|
689
|
+
- **Attachment syncs started on SDK < 1.15.2 and still in flight** re-upload
|
|
690
|
+
their already-processed attachments once. Drain them before upgrading if
|
|
691
|
+
that matters.
|
|
692
|
+
- **`is_sdk_log`** is no longer on log lines; update dashboards that filter on
|
|
693
|
+
it.
|
|
694
|
+
- **Connectors migrated against a beta (≤ `2.0.0-beta.6`)** must re-apply
|
|
695
|
+
§3–§14 against GA, because most of the API above changed after those betas.
|
|
696
|
+
State they wrote is still read.
|