@syncmatters/connector-sdk 1.0.44 → 1.0.46
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/docs/04-meta-objects-fields.md +19 -10
- package/docs/09-testing.md +89 -0
- package/package.json +3 -3
|
@@ -350,8 +350,10 @@ An object may describe a form for creating a field on it in the connected system
|
|
|
350
350
|
(`upsertFieldsMeta`). Users reach it from the mapping screen ("Create field" for one field,
|
|
351
351
|
"Create fields from source fields" for several), and scripts call it. The form's presence on an
|
|
352
352
|
object is the capability. An object may also allow its fields to be deleted (`canDeleteFields: true`); only
|
|
353
|
-
scripts call `deleteFields
|
|
354
|
-
`canDeleteFields`
|
|
353
|
+
scripts call `deleteFields`, the UI does not. The connector test harness checks the form and
|
|
354
|
+
`canDeleteFields` against the test spec. It creates, repeats and deletes a real field, reported as
|
|
355
|
+
the object's `upsertFields` and `deleteFields` features, only for an object whose test module opts
|
|
356
|
+
in with `upsertFields.test`, because that changes the test account's schema ([09-testing.md](./09-testing.md#creating-and-deleting-fields-upsertfieldstest)).
|
|
355
357
|
|
|
356
358
|
Scripts call them per object, like the data operations:
|
|
357
359
|
|
|
@@ -479,14 +481,21 @@ A row is shaped like a data upsert row: its keys are input ids.
|
|
|
479
481
|
Before your method runs the platform refuses a row whose operation the form does not list, that
|
|
480
482
|
has an unknown input, a missing mandatory input or a malformed option list, and removes inputs
|
|
481
483
|
`displayIf` hides. It also refuses a row that repeats an earlier row's key (or, without a user key
|
|
482
|
-
input, its name), so you receive each field once.
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
**
|
|
487
|
-
in cached metadata
|
|
488
|
-
duplicate key reaches your method and the system rejects it. Report
|
|
489
|
-
|
|
484
|
+
input, its name), so you receive each field once. The platform does not look for an existing field
|
|
485
|
+
before calling you: an add of a field that is already there is yours to report, as a row error with
|
|
486
|
+
code `"already_exists"`. The platform then refreshes the object.
|
|
487
|
+
|
|
488
|
+
- **The user chooses the key** (`isUserKey`): do not check yourself. The mapping screen refuses a
|
|
489
|
+
key that is already in cached metadata, but a script's call is not checked against the cache, so
|
|
490
|
+
a duplicate key reaches your method and the system rejects it. Report that rejection as
|
|
491
|
+
`"already_exists"`.
|
|
492
|
+
- **The system assigns keys and accepts two fields with the same name**: check for the name
|
|
493
|
+
yourself, in the cheapest way your API allows (a lookup by name, or the field list you already
|
|
494
|
+
hold), and return `"already_exists"` for a name that is there rather than creating a second
|
|
495
|
+
field.
|
|
496
|
+
|
|
497
|
+
The connector test round trip (`upsertFields.test`, [09-testing.md](./09-testing.md#creating-and-deleting-fields-upsertfieldstest))
|
|
498
|
+
verifies this by sending the same row twice.
|
|
490
499
|
|
|
491
500
|
```js
|
|
492
501
|
async upsertFields({ log, id, meta, objectMeta, rows }) {
|
package/docs/09-testing.md
CHANGED
|
@@ -87,6 +87,20 @@ Established conventions:
|
|
|
87
87
|
- **Test-data hygiene**: prefix every created record (`const testRecordPrefix = "sm_test";`)
|
|
88
88
|
and have `before()` sweep and delete `sm_test*` leftovers, so crashed runs never pollute the
|
|
89
89
|
sandbox account.
|
|
90
|
+
- **Clean up only what the run uses**: `before()` receives `selection` — what the run was
|
|
91
|
+
narrowed to: `objects` (`"all"`, `"selected"` or `"none"`), `objectIds` (the `--object` ids
|
|
92
|
+
when selected), `features` (`["all"]` unless restricted, e.g. `--only query`) and `checkIds`
|
|
93
|
+
(the `--check` ids). A suite whose sweep is slow or touches many objects limits it to the
|
|
94
|
+
objects the run tests **plus the objects those depend on** (a Contacts run that associates
|
|
95
|
+
companies still needs Companies swept), and skips write cleanup when nothing selected writes.
|
|
96
|
+
`selection` is absent on an older runner: treat absent as a full run.
|
|
97
|
+
|
|
98
|
+
```js
|
|
99
|
+
async before({ connection, selection }) {
|
|
100
|
+
const wanted = !selection || selection.objects === "all" ? undefined : new Set(selection.objectIds);
|
|
101
|
+
if (!wanted || wanted.has("contacts") || wanted.has("companies")) await this.#sweepCrm();
|
|
102
|
+
}
|
|
103
|
+
```
|
|
90
104
|
- **Scoping out an object**: set `features.cannotTestReason = "<why>"` on an object's features
|
|
91
105
|
instead of deleting it from the generated file.
|
|
92
106
|
- `expectedIdentity` pins the account: if the sandbox credentials get re-pointed, the suite
|
|
@@ -302,6 +316,81 @@ This catches a connector that keys its rows on one column and tags another, whic
|
|
|
302
316
|
only a sync finds. A spec without `query.key` (anything generated before it existed) skips
|
|
303
317
|
these checks.
|
|
304
318
|
|
|
319
|
+
## Creating and deleting fields: `upsertFields.test`
|
|
320
|
+
|
|
321
|
+
The generated `upsertFields` and `deleteFields` sections are metadata checks (the form's inputs,
|
|
322
|
+
its key and name inputs, `canDeleteFields`), run by the **fieldMetadata** feature. To exercise
|
|
323
|
+
`upsertFields()` and `deleteFields()` against the test account, opt the object in from
|
|
324
|
+
`mod Test.mjs`. The round trip creates a real field in the connected account, so the generator
|
|
325
|
+
never turns it on:
|
|
326
|
+
|
|
327
|
+
```js
|
|
328
|
+
// HubSpot contacts: the user chooses the key (name); groupName is mandatory, so the row names it
|
|
329
|
+
// even though the form has a default
|
|
330
|
+
objectFeatures.Contacts.upsertFields = {
|
|
331
|
+
...objectFeatures.Contacts.upsertFields,
|
|
332
|
+
test: { row: { label: "sm_test field", name: { operation: "add", value: "sm_test_field" }, fieldType: "text", groupName: "contactinformation" } },
|
|
333
|
+
};
|
|
334
|
+
// ConnectWise PSA companies: the system assigns the field id (the form has no key input), so the row needs
|
|
335
|
+
// the name input (caption, maxLen 25). podId is one of the form's podId options on the test account
|
|
336
|
+
objectFeatures.Companies.upsertFields.test = {
|
|
337
|
+
row: { caption: "sm_test field", podId: "12", fieldTypeIdentifier: "Text", entryTypeIdentifier: "EntryField" },
|
|
338
|
+
};
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
`row` is an `upsertFields` row keyed by the form's input ids. A user key can be given as
|
|
342
|
+
`{ operation: "add", value }` or as a plain string. Mandatory inputs must be in the row even when
|
|
343
|
+
they have a `default`. The harness appends a per-run suffix to the key value and to the name, so
|
|
344
|
+
each run creates a new field. The suffix is lower-case letters and digits. It tries `_<suffix>`,
|
|
345
|
+
then `<suffix>`, then `-<suffix>` (a space instead of `_` for the name), shortens the value to fit
|
|
346
|
+
the input's byte `maxLen`, and uses the first value that passes the input's `regex`. If none does,
|
|
347
|
+
the create fails before anything is sent.
|
|
348
|
+
|
|
349
|
+
The round trip runs on a run that tests every feature, or that selects `upsertFields` or
|
|
350
|
+
`deleteFields`. Either value runs the whole round trip, because the delete needs the field the
|
|
351
|
+
create made. A run of `fieldMetadata` alone does not run it. It runs after the object's other
|
|
352
|
+
tests, and the harness:
|
|
353
|
+
|
|
354
|
+
1. calls `connection.upsertFields.<object>` with the row and expects one result, no error and a
|
|
355
|
+
string `id` (a numeric id is dropped by the platform). Then it reads the object's cached
|
|
356
|
+
metadata and expects the field at `path` (or `id`) in `queryFields` or `upsertFields`.
|
|
357
|
+
2. sends the same row again and expects a row error with code `"already_exists"`. Your connector
|
|
358
|
+
produces it: from the system's rejection of a duplicate user key, or from its own check of the
|
|
359
|
+
name where the system assigns keys
|
|
360
|
+
([04](./04-meta-objects-fields.md#rows-and-upsertfields)).
|
|
361
|
+
3. calls `connection.deleteFields.<object>` with every id the add calls created, expects no row
|
|
362
|
+
error, and checks the fields are gone from the cached metadata. The delete runs whatever
|
|
363
|
+
happened in steps 1 and 2.
|
|
364
|
+
|
|
365
|
+
The calls go through the connection, so the platform's row checks and metadata refresh (or your
|
|
366
|
+
`metaUpdate`) are part of what is tested.
|
|
367
|
+
|
|
368
|
+
The delete needs `deleteFields.canDeleteFields: true` in the spec and a `deleteFields` for the
|
|
369
|
+
object on the connection. The generator writes `canDeleteFields` from cached metadata, so a
|
|
370
|
+
features module generated before the object declared it needs regenerating first. Without both,
|
|
371
|
+
the round trip creates nothing and both features read `Not tested`, unless the spec sets
|
|
372
|
+
`upsertFields.test.leaveFieldBehind: true`. With that flag each run creates a field and leaves it
|
|
373
|
+
in the account, and `deleteFields` reads `Not tested` with a reason naming it.
|
|
374
|
+
|
|
375
|
+
The results are two object features, each with a status, a `NotTestedReason`, a `FatalError` and
|
|
376
|
+
details under its own key:
|
|
377
|
+
|
|
378
|
+
- **upsertFields** covers steps 1 and 2. The first step that fails decides the status: `Failed:
|
|
379
|
+
upsertFields not available on the connection`, `Failed: Test row invalid`, `Failed: Create
|
|
380
|
+
returned an error`, `Failed: No id returned for the created field`, `Failed: Field not in cached
|
|
381
|
+
metadata after create`, then for the repeated add `Failed: Repeated add threw an error`,
|
|
382
|
+
`Failed: Repeated add was not refused` or `Failed: Repeated add was not refused with
|
|
383
|
+
already_exists`. A thrown error or a failed metadata read is `Failed: Fatal error during
|
|
384
|
+
testing`. The message behind a failure is in `upsertFieldsFatalError`.
|
|
385
|
+
- **deleteFields** covers step 3: `Passed`, `Failed: Delete returned an error`, `Failed: Field
|
|
386
|
+
still in cached metadata after delete`, `Failed: Fatal error during testing`, or `Not tested`
|
|
387
|
+
when no field was created or it was left behind.
|
|
388
|
+
|
|
389
|
+
An object whose spec does not set `upsertFields.test`, or a run that does not select the round
|
|
390
|
+
trip, has neither feature on its result, and its summary is unchanged. For an object that opts
|
|
391
|
+
in, a failure of either feature fails the object and the run. A `Not tested` (such as an object
|
|
392
|
+
that cannot delete fields) makes an object that would pass Partial.
|
|
393
|
+
|
|
305
394
|
## Custom checks: `customChecks()`
|
|
306
395
|
|
|
307
396
|
Some tests are not shaped like an object feature: a free statement with typed parameters,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@syncmatters/connector-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.46",
|
|
4
4
|
"description": "TypeScript type definitions for the SyncMatters connector SDK (types only - connectors execute on the SyncMatters platform)",
|
|
5
5
|
"types": "./index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
"license": "MIT",
|
|
13
13
|
"author": "SyncMatters",
|
|
14
14
|
"homepage": "https://syncmatters.com",
|
|
15
|
-
"typesContentHash": "
|
|
15
|
+
"typesContentHash": "68b1eba052b8a26ee11cdecc81796e2f921819c36e808a2a091bf7d6e9def32b",
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@types/node": "*",
|
|
18
|
-
"@syncmatters/script-api": "^1.0.
|
|
18
|
+
"@syncmatters/script-api": "^1.0.48"
|
|
19
19
|
}
|
|
20
20
|
}
|