@syncmatters/connector-sdk 1.0.39 → 1.0.40

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.
@@ -91,6 +91,8 @@ platform warns the user at deselect time, naming the syncs that would break.
91
91
  matchRules: ["id", "field_value_equals[ci]"], // match rules the object supports
92
92
  canUpsertClean: true, // you implement upsertClean()
93
93
  canUpsertFieldOptions: true, // you implement upsertFieldOptions()
94
+ upsertFieldsMeta: { /* the create-field form - you implement upsertFields(), see below */ },
95
+ canDeleteFields: true, // you implement deleteFields(), see below
94
96
  queryFields: [ /* ObjectField[] returned by query */ ],
95
97
  upsertFields: [ /* ObjectField[] accepted by upsert */ ],
96
98
  deleteFields: [ /* ObjectField[] needed to identify rows to delete */ ],
@@ -222,6 +224,9 @@ show its **Type** as "declared by connector". "Detected from the name" marks an
222
224
  | `objectFields` | child fields when `type: "object"` |
223
225
  | `arrayType` / `arrayObjectFields` | element type / element fields when `type: "array"` |
224
226
  | `constraints` | validation: `mandatory` (`"always"` · `"add"` · `"update"`; array children only when parent array is non-empty), `max/min/maxLen/minLen`, `regex`, `email`, `integer`, `decimals`, `trim`, `dt: { format: "iso8601", "unix", ..., tz?, dateOnly? }` (see [Date fields](#date-fields-dt)) |
227
+ | `isName: true` | the field holds the record's display text (a company's name, a deal's name). A display hint, not a key; at most one field per object. Optional |
228
+ | `portableId` | set only on a field whose `id` differs per account: a string that names the same field in every account. See below |
229
+ | `portableType` | set on custom fields: what kind of field it is where `type` cannot say. See below |
225
230
  | `isCustom` | the field, and everything below it, is account-specific: a field the account created, or a vendor field with no meaning of its own that only holds an attribute each account defines (a user-defined-value slot, a generic custom-field array, `Custom1..N`). Put it on the container, not only on its leaves. A tenant-defined picklist or a notes field is not custom: the vendor defines what it holds. See below |
226
231
  | `data` | connector-private payload, echoed back in metadata |
227
232
 
@@ -270,6 +275,23 @@ Set the flag on the container (the object or array field), so tools that walk th
270
275
  everything below it. The field-type corpus extractor leaves custom fields out of the training
271
276
  data, and the fields table badges them; auto-map does not read the flag today (2026-11-15).
272
277
 
278
+ ### `portableId` and `portableType`: finding a field in another account
279
+
280
+ When a sync is cloned or a template applied to another account, each mapped field has to be found
281
+ again in that account. The platform compares both attributes as opaque strings; choose values that
282
+ are stable and the same in every account.
283
+
284
+ - **`portableId`**: set it when the field's `id` is assigned per account, so the same field has a
285
+ different id elsewhere. A custom field under a container keyed by a numeric id
286
+ (`customFieldsById.27`) is the case it exists for; its `portableId` is something every account
287
+ shares, such as the field's name. Leave it out when the `id` is already the same in every
288
+ account (an absent `portableId` means the `id` is portable), which covers standard fields and
289
+ custom fields whose id the account chooses (a HubSpot property name).
290
+ - **`portableType`**: set it on custom fields, to say what kind of field it is where `type` cannot
291
+ (HubSpot dates, numbers and booleans all read as `"string"`). Build it from the system's own
292
+ field type, such as HubSpot's `<type>:<fieldType>` (`datetime:date`). An absent `portableType`
293
+ means compare `type`.
294
+
273
295
  ### Match rules
274
296
 
275
297
  `matchRules` values: `"id"`, `"name[ci]"`, `"email[ci]"`, `"domain[ci]"`,
@@ -322,6 +344,141 @@ can build the related filter). Declaring relationships enables `relatedFilter` q
322
344
  Declaring it on the wrong object doesn't fail here — it fails later, when
323
345
  `relatedFilter` hands your `query()` keys of the wrong object. Decide direction at `meta()` time.
324
346
 
347
+ ## Creating and deleting fields: `upsertFields()` and `deleteFields()`
348
+
349
+ An object may describe a form for creating a field on it in the connected system
350
+ (`upsertFieldsMeta`). Users reach it from the mapping screen ("Create field"), and templates and
351
+ installs use it to create the fields they map to. The form's presence on an object is the
352
+ capability. An object may also allow its fields to be deleted (`canDeleteFields: true`); scripts and
353
+ the connector test harness use that, the UI does not.
354
+
355
+ Scripts call them per object, like the data operations:
356
+
357
+ ```js
358
+ const { rows } = await conn.upsertFields.contacts({ rows: [row, ...] }); // one result per row, in order
359
+ await conn.deleteFields.contacts({ rows: [{ id: "sf_id" }] });
360
+ ```
361
+
362
+ `conn.upsertFields.<object>` is there when your connector implements `upsertFields()` and the
363
+ object's metadata has `upsertFieldsMeta`; `conn.deleteFields.<object>` when it implements
364
+ `deleteFields()` and the object has `canDeleteFields`.
365
+
366
+ Two methods touch field definitions and they do different jobs:
367
+
368
+ | | `upsertFieldOptions()` | `upsertFields()` |
369
+ | ------- | ------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------- |
370
+ | Called | during a sync run, driven by row values | at design time, by a person, a template apply or an install |
371
+ | Does | merges option values into an existing picklist field; options already there are fine | creates a field from the form's values, or updates its definition where `update` is listed; an add of an existing field is an error |
372
+ | Returns | the resolved id of each option, which the run needs to write the row | the field's id, and its path when it is not a top-level field |
373
+
374
+ `options` in an update row is the field's whole option list, not a merge. You may share one
375
+ internal routine between the two methods.
376
+
377
+ ### The form
378
+
379
+ ```js
380
+ upsertFieldsMeta: {
381
+ operations: ["add"], // what upsertFields() accepts; default ["add"]. Listing "update" is deliberate
382
+ fields: { // form inputs, keyed by input id; a row uses the same ids
383
+ name: { name: "Internal name", type: "string", isUserKey: true, mandatory: true, constraints: { regex: "^[a-z][a-z0-9_]*$" } },
384
+ label: { name: "Label", type: "string", isName: true, mandatory: true },
385
+ fieldType: { name: "Field type", type: "string", control: "select", mandatory: true,
386
+ options: [{ id: "text", name: "Single-line text" }, { id: "select", name: "Dropdown select" }] },
387
+ options: { name: "Options", type: "option_array", userOptionIds: true,
388
+ displayIf: "other_setting_has_value", displayIfSetting: "fieldType", displayIfValues: ["select"] },
389
+ },
390
+ presets: [{ id: "external_id", name: "Id of the other system's record", values: { fieldType: "text" } }],
391
+ }
392
+ ```
393
+
394
+ - **Inputs are form inputs** (the same type as object settings: `name`, `description`,
395
+ `mandatory`, `control`, `options`, `default`, `constraints`, `displayIf`), keyed by the
396
+ system's own attribute names, with the system's own values (HubSpot's `fieldType` list). Add an
397
+ input of your own only where the system has none, such as naming a new group. Every input needs a
398
+ `type`.
399
+ - **Three flags are all the platform understands about a form:**
400
+ - `isUserKey`: holds the new field's key, chosen by the user. A row gives it as
401
+ `{ operation: "add" | "update", value }`, and the input's `constraints` are checked against
402
+ `value`.
403
+ - `isKey`: holds the field's key, assigned by the system. A row without it is an add, a row with
404
+ it an update; it is not shown when adding and its `mandatory` applies to updates only.
405
+ - `isName`: holds the field's display text.
406
+
407
+ A form has at most one key input (`isUserKey` or `isKey`, never both), at most one name input,
408
+ and at least one of the two. The platform drops a form that breaks this rule, or has an input
409
+ without a `type`, and logs why; the connector test harness flags it.
410
+
411
+ - **`option_array`** holds a picklist's options as `[{ id?, name }]`, in option order. An omitted
412
+ `id` means the name: apply that when you create the options. Set `userOptionIds: true` only where
413
+ the system lets the creator choose option ids; without it a row that sends an `id` is refused.
414
+ - **`displayIf`** hides inputs that do not apply (options for a text field). A hidden input is not
415
+ sent, and a hidden mandatory input does not block.
416
+ - **Presets** are prefilled rows. `external_id` is the well-known one: the UI offers it as "Id of
417
+ the <other system> record".
418
+ - **Advertise the form only where the connection may use it.** Set `upsertFieldsMeta` (and
419
+ `canDeleteFields`) on an object only when your connector implements `upsertFields()` (and
420
+ `deleteFields()`) and the connection's grant lets it change that object's fields, as you would hide
421
+ an object the grant does not cover. The platform strips them when the method is missing.
422
+
423
+ ### Rows and `upsertFields()`
424
+
425
+ A row is shaped like a data upsert row: its keys are input ids.
426
+
427
+ ```js
428
+ { name: { operation: "add", value: "sf_id" }, label: "Salesforce ID", fieldType: "text" }
429
+ { name: { operation: "add", value: "rating" }, label: "Rating", fieldType: "select",
430
+ options: [{ id: "HOT", name: "Hot lead" }, { name: "Cold" }] }
431
+ ```
432
+
433
+ Before your method runs the platform refuses a row whose operation the form does not list, that
434
+ has an unknown input, a missing mandatory input or a malformed option list, and removes inputs
435
+ `displayIf` hides. It also refuses a row that repeats an earlier row's key (or, without a user key
436
+ input, its name), so you receive each field once. Where the system assigns keys and may accept two
437
+ fields with the same name, the platform refreshes the object and refuses an add whose name is
438
+ already there.
439
+
440
+ **Do not check for an existing field yourself.** The platform checks cached metadata before the
441
+ call. An add the system still rejects as a duplicate comes back as a row error with code
442
+ `"already_exists"`, and the platform refreshes the object.
443
+
444
+ ```js
445
+ async upsertFields({ log, id, meta, objectMeta, rows }) {
446
+ const results = [];
447
+ for (const row of rows) {
448
+ try {
449
+ const created = await this.#createProperty(id, row);
450
+ results.push({ id: created.name }); // path: [...] when not a top-level field
451
+ } catch (err) {
452
+ results.push({ error: { code: isDuplicate(err) ? "already_exists" : undefined, message: err.message } });
453
+ }
454
+ }
455
+ return { rows: results }; // one result per row, in request order
456
+ }
457
+ ```
458
+
459
+ - Return a row error rather than throwing for a row that fails; a throw fails every row of the call.
460
+ - `path` says where the new field can be mapped when it is not the top-level field `id`, such as a
461
+ custom field inside a `customFieldsById` container.
462
+ - To save a metadata refresh, return `metaUpdate: { objects: [...] }` with the changed objects, as
463
+ `upsertFieldOptions()` can. Each object replaces the cached object's name, flags and
464
+ `upsertFieldsMeta`, and any field list it carries replaces all of the cached field lists, so send
465
+ the whole object. Without it the platform refreshes the object after any row succeeds, once per
466
+ call however many rows it had. A returned object that leaves out `upsertFieldsMeta` keeps the
467
+ cached form.
468
+ - The refreshes are part of the change: a run allowed to change fields can make them.
469
+
470
+ ### `deleteFields()`
471
+
472
+ ```js
473
+ async deleteFields({ log, id, meta, objectMeta, rows }) { // rows: [{ id }], the field ids in meta
474
+ return { rows: await Promise.all(rows.map((row) => this.#deleteProperty(id, row.id))) };
475
+ }
476
+ ```
477
+
478
+ The platform refuses a row without an `id` and a repeated id before your method runs. Return one
479
+ `{ id?, error? }` per row in request order, and `metaUpdate` as for `upsertFields()`; without it the
480
+ object is refreshed once when any row succeeded.
481
+
325
482
  ## The query capability bar
326
483
 
327
484
  Syncs are built from these capabilities — an object missing one is an object syncs can only
@@ -1,4 +1,4 @@
1
- import { EventTypeMeta, Logger, ObjectField, UpsertIssue, ObjectIndex, ObjectMeta, ObjectMetaUpsert, Row, TestResult, ScriptType, UpsertFieldOptionMeta, QueryMatchFilter, QueryCheckpointFilter, JsonValuePathPart, SyncSession, ObjectFieldOption, RowMatchRuleType, SyncOptimalBatchSizeOperation, SyncOptimalBatchSizeBatchType, DiscoverResult } from "@syncmatters/script-api";
1
+ import { EventTypeMeta, Logger, ObjectField, UpsertIssue, ObjectIndex, ObjectMeta, ObjectMetaUpsert, Row, TestResult, ScriptType, UpsertFieldOptionMeta, QueryMatchFilter, QueryCheckpointFilter, JsonValuePathPart, SyncSession, ObjectFieldOption, RowMatchRuleType, SyncOptimalBatchSizeOperation, SyncOptimalBatchSizeBatchType, DiscoverResult, UpsertFieldRow, UpsertFieldResult, DeleteFieldRow, DeleteFieldResult } from "@syncmatters/script-api";
2
2
  import SDK from "../index.js";
3
3
  /**
4
4
  * InitArgs are passed as the only argument to the connector init() function.
@@ -61,8 +61,12 @@ export interface Connector {
61
61
  upsertClean?(options: UpsertCleanOptions): Promise<UpsertCleanResponse>;
62
62
  /** upsertFieldOptions adds/updates field option values to picklist style fields. */
63
63
  upsertFieldOptions?(options: UpsertOptionsOptions): Promise<UpsertOptionsResponse>;
64
+ /** upsertFields creates/updates fields on an object. */
65
+ upsertFields?(options: UpsertFieldsOptions): Promise<UpsertFieldsResponse>;
64
66
  /** delete records from the target system, returning the key's of deleted rows. */
65
67
  delete?(options: DeleteOptions): Promise<Row[]>;
68
+ /** deleteFields deletes fields from an object. */
69
+ deleteFields?(options: DeleteFieldsOptions): Promise<DeleteFieldsResponse>;
66
70
  /** the endpoint can recommend batch sizes to used when querying/updating/deleting data */
67
71
  optimalBatchSize?(options: OptimalBatchSizeOptions): Promise<OptimalBatchSizeResponse>;
68
72
  /** parseEvents receives raw event payloads from webhooks and transforms it to ParsedEvent format. */
@@ -407,6 +411,56 @@ export interface UpsertOptionsResponse {
407
411
  objects?: ObjectMetaUpsert[];
408
412
  };
409
413
  }
414
+ /** UpsertFieldsOptions is passed to the upsertFields function. */
415
+ export interface UpsertFieldsOptions {
416
+ /** log can record to the platform event store */
417
+ log: Logger;
418
+ /** id of the object whose fields are created or changed */
419
+ id: string;
420
+ /** metadata of the object, holding its upsertFieldsMeta */
421
+ meta: ObjectMeta;
422
+ /** request cached metadata from any object on the connection */
423
+ objectMeta(id: string): Promise<ObjectMeta>;
424
+ /**
425
+ * the rows, already checked against meta.upsertFieldsMeta: every input id is known, mandatory inputs are present,
426
+ * inputs hidden by displayIf are removed, and the operation is one the form lists
427
+ */
428
+ rows: UpsertFieldRow[];
429
+ }
430
+ /** UpsertFieldsResponse is returned from the upsertFields function. */
431
+ export interface UpsertFieldsResponse {
432
+ /** one result per row, in request order; a failed row carries `error` (code "already_exists" when the system says so) */
433
+ rows: UpsertFieldResult[];
434
+ /**
435
+ * optionally return the changed objects to avoid a metadata refresh. Each object replaces the cached object's
436
+ * name, flags and upsertFieldsMeta, and any field list it carries replaces all of the cached field lists.
437
+ */
438
+ metaUpdate?: {
439
+ objects?: ObjectMetaUpsert[];
440
+ };
441
+ }
442
+ /** DeleteFieldsOptions is passed to the deleteFields function. */
443
+ export interface DeleteFieldsOptions {
444
+ /** log can record to the platform event store */
445
+ log: Logger;
446
+ /** id of the object whose fields are deleted */
447
+ id: string;
448
+ /** metadata of the object */
449
+ meta: ObjectMeta;
450
+ /** request cached metadata from any object on the connection */
451
+ objectMeta(id: string): Promise<ObjectMeta>;
452
+ /** the fields to delete, each named by its id in the object's metadata; no id repeats */
453
+ rows: DeleteFieldRow[];
454
+ }
455
+ /** DeleteFieldsResponse is returned from the deleteFields function. */
456
+ export interface DeleteFieldsResponse {
457
+ /** one result per row, in request order; a failed row carries `error` */
458
+ rows: DeleteFieldResult[];
459
+ /** optionally return the changed objects to avoid a metadata refresh (as for upsertFields) */
460
+ metaUpdate?: {
461
+ objects?: ObjectMetaUpsert[];
462
+ };
463
+ }
410
464
  /** DeleteOptions is passed to the delete function. */
411
465
  export interface DeleteOptions {
412
466
  /** log can record to the platform event store */
package/module.d.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  * SDK specific elements that would be of no interest to users of the API.
4
4
  */
5
5
  export { EventScriptComplete, defaultRedactKeys } from "@syncmatters/script-api";
6
- export type { Cache, FileProvider, HttpRequest, HttpClientOptions, Redactor, RedactorOptions, KvCollection, KvIterator, Logger, EventContext, TestResult, Row, ObjectMeta, ObjectField, ObjectFieldOption, RateLimiterOptions, ScriptType, JsonValuePath, JsonValuePathPart, QueryMatchFilter, QueryCheckpointFilter, EventTypeMeta, ObjectIndex, ObjectMetaUpsert, ObjectRowFilter, ObjectRelationship, ObjectFieldConstraints, FormInput, FormInputOption, ObjectSettingMeta, ObjectUnavailableReason, DiscoverResult, DiscoveredObject, MetaState, MetaStateObject, UpsertIssue, UpsertFieldOptionMeta, RowMatchRuleType, ObjectSemanticType, RowMatchData, RowMatchRuleOrder, SyncSession, SyncOptimalBatchSizeOperation, SyncOptimalBatchSizeBatchType, } from "@syncmatters/script-api";
6
+ export type { Cache, FileProvider, HttpRequest, HttpClientOptions, Redactor, RedactorOptions, KvCollection, KvIterator, Logger, EventContext, TestResult, Row, ObjectMeta, ObjectField, ObjectFieldOption, RateLimiterOptions, ScriptType, JsonValuePath, JsonValuePathPart, QueryMatchFilter, QueryCheckpointFilter, EventTypeMeta, ObjectIndex, ObjectMetaUpsert, ObjectRowFilter, ObjectRelationship, ObjectFieldConstraints, FormInput, FormInputOption, ObjectSettingMeta, UpsertFieldsMeta, UpsertFieldInputMeta, UpsertFieldOperation, UpsertFieldPreset, UpsertFieldRow, UpsertFieldOption, UpsertFieldResult, DeleteFieldRow, DeleteFieldResult, ObjectUnavailableReason, DiscoverResult, DiscoveredObject, MetaState, MetaStateObject, UpsertIssue, UpsertFieldOptionMeta, RowMatchRuleType, ObjectSemanticType, RowMatchData, RowMatchRuleOrder, SyncSession, SyncOptimalBatchSizeOperation, SyncOptimalBatchSizeBatchType, } from "@syncmatters/script-api";
7
7
  export * from "./lib/connector.js";
8
8
  export * from "./lib/connector-error.js";
9
9
  export { envSet } from "./lib/environment.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@syncmatters/connector-sdk",
3
- "version": "1.0.39",
3
+ "version": "1.0.40",
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": "e0307551d7ae002230cd7275876066de343c4d286e81127bf27d08d84d876506",
15
+ "typesContentHash": "047a3bc412ec7fd9f3397234350f75efb2ce44768c7520f713801e35bac80cd3",
16
16
  "dependencies": {
17
17
  "@types/node": "*",
18
- "@syncmatters/script-api": "^1.0.43"
18
+ "@syncmatters/script-api": "^1.0.44"
19
19
  }
20
20
  }