@proveanything/smartlinks 2.2.1 → 3.0.0-alpha.0

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.
Files changed (330) hide show
  1. package/README.md +741 -754
  2. package/dist/README.md +573 -573
  3. package/dist/adminCardsView.js +55 -55
  4. package/dist/api/adminCards.d.ts +8 -0
  5. package/dist/api/adminCards.js +9 -1
  6. package/dist/api/ai.d.ts +22 -11
  7. package/dist/api/ai.js +18 -14
  8. package/dist/api/analytics.d.ts +13 -0
  9. package/dist/api/analytics.js +13 -0
  10. package/dist/api/appConfiguration.d.ts +17 -14
  11. package/dist/api/appConfiguration.js +14 -12
  12. package/dist/api/appObjects.d.ts +80 -16
  13. package/dist/api/appObjects.js +74 -11
  14. package/dist/api/asset.d.ts +55 -19
  15. package/dist/api/asset.js +52 -32
  16. package/dist/api/attestation.d.ts +3 -2
  17. package/dist/api/attestation.js +1 -1
  18. package/dist/api/attestations.d.ts +22 -7
  19. package/dist/api/attestations.js +22 -7
  20. package/dist/api/authKit.d.ts +22 -5
  21. package/dist/api/authKit.js +21 -4
  22. package/dist/api/batch.d.ts +23 -16
  23. package/dist/api/batch.js +19 -13
  24. package/dist/api/bookings.d.ts +45 -9
  25. package/dist/api/bookings.js +39 -3
  26. package/dist/api/broadcasts.d.ts +26 -6
  27. package/dist/api/broadcasts.js +22 -2
  28. package/dist/api/claimSet.d.ts +48 -13
  29. package/dist/api/claimSet.js +43 -7
  30. package/dist/api/collection.d.ts +20 -6
  31. package/dist/api/collection.js +19 -8
  32. package/dist/api/comms.d.ts +43 -12
  33. package/dist/api/comms.js +43 -13
  34. package/dist/api/conditions.d.ts +12 -2
  35. package/dist/api/conditions.js +10 -1
  36. package/dist/api/config.d.ts +15 -2
  37. package/dist/api/config.js +12 -0
  38. package/dist/api/contact.d.ts +34 -13
  39. package/dist/api/contact.js +35 -10
  40. package/dist/api/containers.d.ts +41 -23
  41. package/dist/api/containers.js +37 -21
  42. package/dist/api/crate.d.ts +9 -8
  43. package/dist/api/crate.js +8 -8
  44. package/dist/api/dpp.d.ts +58 -10
  45. package/dist/api/dpp.js +57 -15
  46. package/dist/api/facets.d.ts +71 -0
  47. package/dist/api/facets.js +71 -0
  48. package/dist/api/files.d.ts +11 -5
  49. package/dist/api/files.js +9 -1
  50. package/dist/api/form.d.ts +9 -2
  51. package/dist/api/form.js +7 -1
  52. package/dist/api/index.d.ts +0 -1
  53. package/dist/api/index.js +0 -1
  54. package/dist/api/integrations.d.ts +82 -27
  55. package/dist/api/integrations.js +63 -7
  56. package/dist/api/interactions.d.ts +42 -6
  57. package/dist/api/interactions.js +41 -5
  58. package/dist/api/jobs.d.ts +9 -2
  59. package/dist/api/jobs.js +6 -0
  60. package/dist/api/journeys.d.ts +13 -2
  61. package/dist/api/journeys.js +10 -1
  62. package/dist/api/journeysAnalytics.d.ts +12 -3
  63. package/dist/api/journeysAnalytics.js +9 -1
  64. package/dist/api/knowledge.d.ts +43 -10
  65. package/dist/api/knowledge.js +37 -5
  66. package/dist/api/location.d.ts +10 -3
  67. package/dist/api/location.js +7 -1
  68. package/dist/api/lots.d.ts +40 -13
  69. package/dist/api/lots.js +38 -8
  70. package/dist/api/loyalty.d.ts +70 -12
  71. package/dist/api/loyalty.js +60 -3
  72. package/dist/api/nfc.d.ts +8 -2
  73. package/dist/api/nfc.js +6 -1
  74. package/dist/api/order.d.ts +51 -160
  75. package/dist/api/order.js +46 -208
  76. package/dist/api/partner.d.ts +41 -8
  77. package/dist/api/partner.js +36 -4
  78. package/dist/api/products.d.ts +41 -8
  79. package/dist/api/products.js +33 -4
  80. package/dist/api/proof.d.ts +50 -13
  81. package/dist/api/proof.js +43 -7
  82. package/dist/api/realtime.d.ts +1 -11
  83. package/dist/api/realtime.js +1 -22
  84. package/dist/api/secrets.d.ts +25 -5
  85. package/dist/api/secrets.js +21 -2
  86. package/dist/api/segments.d.ts +26 -6
  87. package/dist/api/segments.js +22 -2
  88. package/dist/api/serviceAccounts.d.ts +8 -1
  89. package/dist/api/serviceAccounts.js +8 -1
  90. package/dist/api/shop.d.ts +41 -13
  91. package/dist/api/shop.js +35 -4
  92. package/dist/api/subscriptions.d.ts +47 -12
  93. package/dist/api/subscriptions.js +40 -4
  94. package/dist/api/tags.d.ts +40 -19
  95. package/dist/api/tags.js +38 -18
  96. package/dist/api/template.d.ts +31 -3
  97. package/dist/api/template.js +27 -0
  98. package/dist/api/translations.d.ts +17 -2
  99. package/dist/api/translations.js +14 -0
  100. package/dist/api/userGroups.d.ts +35 -9
  101. package/dist/api/userGroups.js +30 -5
  102. package/dist/api/variant.d.ts +11 -3
  103. package/dist/api/variant.js +9 -2
  104. package/dist/api/wallet.d.ts +23 -10
  105. package/dist/api/wallet.js +20 -2
  106. package/dist/apiVersion.d.ts +1 -1
  107. package/dist/apiVersion.js +1 -1
  108. package/dist/baseline.css +194 -194
  109. package/dist/docs/API_SUMMARY.md +1389 -2298
  110. package/dist/docs/PRODUCT_FACETS_SDK.md +10 -15
  111. package/dist/docs/admin-cards.md +189 -189
  112. package/dist/docs/admin-lists-and-pickers.md +1 -1
  113. package/dist/docs/agent-tools.md +156 -156
  114. package/dist/docs/ai-tools-and-skills.md +180 -180
  115. package/dist/docs/ai.md +1721 -1721
  116. package/dist/docs/analytics.md +3 -2
  117. package/dist/docs/api-versions.md +85 -76
  118. package/dist/docs/app-data-storage.md +277 -277
  119. package/dist/docs/app-docs.md +73 -73
  120. package/dist/docs/app-manifest.md +852 -852
  121. package/dist/docs/app-objects.md +38 -50
  122. package/dist/docs/app-records-pattern.md +388 -388
  123. package/dist/docs/appConfig.md +550 -550
  124. package/dist/docs/assets.md +17 -3
  125. package/dist/docs/assistant-apps.md +172 -172
  126. package/dist/docs/assistant-context.md +119 -119
  127. package/dist/docs/attestations.md +5 -4
  128. package/dist/docs/auth-kit.md +1 -1
  129. package/dist/docs/bookings.md +442 -442
  130. package/dist/docs/comms.md +689 -686
  131. package/dist/docs/connectors.md +340 -340
  132. package/dist/docs/contact-search.md +4 -3
  133. package/dist/docs/container-tracking.md +7 -7
  134. package/dist/docs/css-baseline.md +133 -133
  135. package/dist/docs/customer-guide.md +70 -70
  136. package/dist/docs/deploying-apps.md +340 -340
  137. package/dist/docs/dpp.md +115 -115
  138. package/dist/docs/entitlements.md +90 -90
  139. package/dist/docs/executor.md +1 -1
  140. package/dist/docs/files.md +69 -69
  141. package/dist/docs/forms.md +1 -1
  142. package/dist/docs/headless-providers.md +3 -3
  143. package/dist/docs/host-dependency-contract.md +252 -210
  144. package/dist/docs/i18n.md +292 -46
  145. package/dist/docs/integrations.md +322 -322
  146. package/dist/docs/interactions.md +544 -545
  147. package/dist/docs/item-context.md +181 -181
  148. package/dist/docs/knowledge.md +105 -102
  149. package/dist/docs/lists.md +114 -0
  150. package/dist/docs/lots.md +112 -111
  151. package/dist/docs/loyalty.md +348 -352
  152. package/dist/docs/members.md +183 -183
  153. package/dist/docs/memberships.md +150 -149
  154. package/dist/docs/mobile-admin-container.md +693 -693
  155. package/dist/docs/operations.md +281 -281
  156. package/dist/docs/overview.md +485 -485
  157. package/dist/docs/proof-claiming-methods.md +6 -6
  158. package/dist/docs/proof-comms-triggers.md +142 -142
  159. package/dist/docs/proof-ownership-transfer.md +155 -155
  160. package/dist/docs/proof-product-data-scoping.md +462 -462
  161. package/dist/docs/proof-share-grants.md +305 -305
  162. package/dist/docs/realtime.md +139 -138
  163. package/dist/docs/records-admin-pattern.md +304 -304
  164. package/dist/docs/server-functions.md +2 -2
  165. package/dist/docs/service-accounts.md +64 -64
  166. package/dist/docs/shop.md +4 -2
  167. package/dist/docs/site-seo.md +2 -1
  168. package/dist/docs/standard-query.md +187 -187
  169. package/dist/docs/tag-codes.md +97 -97
  170. package/dist/docs/tag-ranges.md +106 -106
  171. package/dist/docs/theme-tokens.md +252 -252
  172. package/dist/docs/translations.md +6 -1
  173. package/dist/docs/upgrading-to-3.md +430 -0
  174. package/dist/docs/user-groups.md +4 -4
  175. package/dist/docs/utils.md +1 -1
  176. package/dist/docs/wallet-passes.md +107 -107
  177. package/dist/docs/websites.md +123 -123
  178. package/dist/headless.d.ts +1 -1
  179. package/dist/headless.js +2 -2
  180. package/dist/http.d.ts +15 -2
  181. package/dist/http.js +60 -2
  182. package/dist/i18n.d.ts +2 -14
  183. package/dist/i18n.js +6 -23
  184. package/dist/index.d.ts +7 -8
  185. package/dist/index.js +2 -0
  186. package/dist/list.d.ts +24 -0
  187. package/dist/list.js +80 -0
  188. package/dist/mobile-admin/types.d.ts +0 -16
  189. package/dist/openapi.yaml +290 -2723
  190. package/dist/shared-dependencies.d.ts +3 -3
  191. package/dist/shared-dependencies.js +13 -5
  192. package/dist/site.d.ts +1 -7
  193. package/dist/site.js +1 -14
  194. package/dist/theme-boot.js +82 -82
  195. package/dist/theme.css +75 -75
  196. package/dist/types/adminCards.d.ts +6 -3
  197. package/dist/types/ai.d.ts +0 -6
  198. package/dist/types/analytics.d.ts +5 -8
  199. package/dist/types/appManifest.d.ts +4 -5
  200. package/dist/types/appObjects.d.ts +14 -18
  201. package/dist/types/appObjects.js +0 -1
  202. package/dist/types/appOptions.d.ts +18 -0
  203. package/dist/types/asset.d.ts +3 -22
  204. package/dist/types/attestations.d.ts +7 -10
  205. package/dist/types/batch.d.ts +6 -14
  206. package/dist/types/bookings.d.ts +22 -4
  207. package/dist/types/broadcasts.d.ts +5 -13
  208. package/dist/types/broadcasts.js +0 -1
  209. package/dist/types/claimSet.d.ts +0 -5
  210. package/dist/types/comms.d.ts +11 -9
  211. package/dist/types/contact.d.ts +5 -29
  212. package/dist/types/contact.js +0 -13
  213. package/dist/types/containers.d.ts +15 -26
  214. package/dist/types/crate.d.ts +4 -12
  215. package/dist/types/dpp.d.ts +3 -3
  216. package/dist/types/dpp.js +0 -1
  217. package/dist/types/error.d.ts +8 -5
  218. package/dist/types/error.js +12 -5
  219. package/dist/types/facets.d.ts +15 -15
  220. package/dist/types/index.d.ts +1 -0
  221. package/dist/types/index.js +1 -0
  222. package/dist/types/integrations.d.ts +3 -28
  223. package/dist/types/interaction.d.ts +3 -9
  224. package/dist/types/jobs.d.ts +3 -8
  225. package/dist/types/jobs.js +0 -1
  226. package/dist/types/journeys.d.ts +3 -8
  227. package/dist/types/journeys.js +0 -1
  228. package/dist/types/journeysAnalytics.d.ts +0 -1
  229. package/dist/types/list.d.ts +24 -0
  230. package/dist/types/list.js +2 -0
  231. package/dist/types/location.d.ts +0 -4
  232. package/dist/types/lots.d.ts +0 -9
  233. package/dist/types/loyalty.d.ts +0 -9
  234. package/dist/types/order.d.ts +7 -134
  235. package/dist/types/product.d.ts +11 -24
  236. package/dist/types/proof.d.ts +16 -0
  237. package/dist/types/realtime.d.ts +0 -29
  238. package/dist/types/segments.d.ts +5 -13
  239. package/dist/types/segments.js +0 -1
  240. package/dist/types/serviceAccounts.d.ts +3 -2
  241. package/dist/types/serviceAccounts.js +0 -1
  242. package/dist/types/shop.d.ts +5 -12
  243. package/dist/types/shop.js +0 -4
  244. package/dist/types/subscriptions.d.ts +18 -0
  245. package/dist/types/subscriptions.js +0 -8
  246. package/dist/types/tags.d.ts +6 -16
  247. package/dist/types/tags.js +0 -7
  248. package/dist/types/translations.d.ts +3 -9
  249. package/dist/types/variant.d.ts +0 -2
  250. package/dist/version.d.ts +1 -1
  251. package/dist/version.js +1 -1
  252. package/docs/API_SUMMARY.md +1389 -2298
  253. package/docs/PRODUCT_FACETS_SDK.md +10 -15
  254. package/docs/admin-cards.md +189 -189
  255. package/docs/admin-lists-and-pickers.md +1 -1
  256. package/docs/agent-tools.md +156 -156
  257. package/docs/ai-tools-and-skills.md +180 -180
  258. package/docs/ai.md +1721 -1721
  259. package/docs/analytics.md +3 -2
  260. package/docs/api-versions.md +85 -76
  261. package/docs/app-data-storage.md +277 -277
  262. package/docs/app-docs.md +73 -73
  263. package/docs/app-manifest.md +852 -852
  264. package/docs/app-objects.md +38 -50
  265. package/docs/app-records-pattern.md +388 -388
  266. package/docs/appConfig.md +550 -550
  267. package/docs/assets.md +17 -3
  268. package/docs/assistant-apps.md +172 -172
  269. package/docs/assistant-context.md +119 -119
  270. package/docs/attestations.md +5 -4
  271. package/docs/auth-kit.md +1 -1
  272. package/docs/bookings.md +442 -442
  273. package/docs/comms.md +689 -686
  274. package/docs/connectors.md +340 -340
  275. package/docs/contact-search.md +4 -3
  276. package/docs/container-tracking.md +7 -7
  277. package/docs/css-baseline.md +133 -133
  278. package/docs/customer-guide.md +70 -70
  279. package/docs/deploying-apps.md +340 -340
  280. package/docs/dpp.md +115 -115
  281. package/docs/entitlements.md +90 -90
  282. package/docs/executor.md +1 -1
  283. package/docs/files.md +69 -69
  284. package/docs/forms.md +1 -1
  285. package/docs/headless-providers.md +3 -3
  286. package/docs/host-dependency-contract.md +252 -210
  287. package/docs/i18n.md +292 -46
  288. package/docs/integrations.md +322 -322
  289. package/docs/interactions.md +544 -545
  290. package/docs/item-context.md +181 -181
  291. package/docs/knowledge.md +105 -102
  292. package/docs/lists.md +114 -0
  293. package/docs/lots.md +112 -111
  294. package/docs/loyalty.md +348 -352
  295. package/docs/members.md +183 -183
  296. package/docs/memberships.md +150 -149
  297. package/docs/mobile-admin-container.md +693 -693
  298. package/docs/operations.md +281 -281
  299. package/docs/overview.md +485 -485
  300. package/docs/proof-claiming-methods.md +6 -6
  301. package/docs/proof-comms-triggers.md +142 -142
  302. package/docs/proof-ownership-transfer.md +155 -155
  303. package/docs/proof-product-data-scoping.md +462 -462
  304. package/docs/proof-share-grants.md +305 -305
  305. package/docs/realtime.md +139 -138
  306. package/docs/server-functions.md +2 -2
  307. package/docs/service-accounts.md +64 -64
  308. package/docs/shop.md +4 -2
  309. package/docs/site-seo.md +2 -1
  310. package/docs/standard-query.md +187 -187
  311. package/docs/tag-codes.md +97 -97
  312. package/docs/tag-ranges.md +106 -106
  313. package/docs/theme-lookbook.v1.json +120 -120
  314. package/docs/theme-tokens.md +252 -252
  315. package/docs/translations.md +6 -1
  316. package/docs/upgrading-to-3.md +430 -0
  317. package/docs/user-groups.md +4 -4
  318. package/docs/utils.md +1 -1
  319. package/docs/wallet-passes.md +107 -107
  320. package/docs/websites.md +123 -123
  321. package/openapi.yaml +290 -2723
  322. package/package.json +91 -87
  323. package/scripts/headless-check.mjs +87 -87
  324. package/scripts/lib/bare-imports.mjs +57 -57
  325. package/scripts/lib/keyed-app-data.mjs +21 -21
  326. package/scripts/lib/upgrade.mjs +512 -0
  327. package/scripts/publish.mjs +272 -272
  328. package/scripts/register-release.mjs +91 -91
  329. package/scripts/upgrade.mjs +56 -0
  330. package/upgrade/3.json +2213 -0
@@ -1,340 +1,340 @@
1
- # Integration connectors
2
-
3
- A **connector** is an app that knows one external provider (a PIM, a content network, a shop
4
- platform, a loyalty or CRM system…). It is installed on a collection like any app, versioned and released like any app, and
5
- it adds a manifest `connector` block plus a handful of [server functions](server-functions.md) the
6
- integration engine and the integrations console call by convention.
7
-
8
- Three layers, each with one job:
9
-
10
- | Layer | Holds |
11
- |---|---|
12
- | **Engine** (the API) | [Integration flows](integrations.md), runs and their logs, triggers (events, schedule, Run now), the secret store, **the mapping** (each customer's field mappings and rules), generic transports (HTTP, Event Hub). No provider code. |
13
- | **Integrations console** (a core app) | The one admin screen: installed connectors, connect forms, settings, the mapper with AI assist, flows, runs. |
14
- | **Connector apps** | One per provider: an **adapter**. Talks to the provider and converts between its format and a clean, provider-neutral document. |
15
-
16
- **A connector adapts; core maps.** A connector never holds a customer's mapping. It turns the
17
- provider's records into provider-neutral documents (`shape`), or provider-ready payloads out of
18
- documents core has already mapped (`serialize`). Every customer's mapping, routing and rules live in
19
- core, so they work the same for every provider and can be replayed and traced. This is the line
20
- SnapLogic (endpoint Snaps vs the Mapper), MuleSoft and Airbyte all draw.
21
-
22
- A flow that only posts JSON to a webhook or an Event Hub needs no connector; it uses the engine's
23
- generic transports (see [integrations.md](integrations.md)).
24
-
25
- **No AI at run time.** The AI helps an admin *author* a mapping in the console (from the connector's
26
- target schema plus real sample records); a person approves it, and it is saved as data and runs
27
- deterministically. A connector's `shape` and `serialize` must be deterministic too.
28
-
29
- ---
30
-
31
- ## The manifest block
32
-
33
- ```jsonc
34
- // app.manifest.json
35
- "connector": {
36
- "provider": "oneworldsync",
37
- "title": "1WorldSync",
38
- "directions": ["inbound"],
39
- "entities": ["product"],
40
- "connection": {
41
- "fields": [
42
- // Optional: SmartLinks' own credentials are the default; a customer may enter theirs.
43
- { "name": "appId", "label": "App ID", "secret": "oneworldsync-app-id" },
44
- { "name": "secretKey", "label": "Secret key", "secret": "oneworldsync-secret-key" },
45
- { "name": "gln", "label": "GLN", "required": true },
46
- { "name": "environment", "label": "Environment", "type": "select",
47
- "options": [ { "value": "preprod", "label": "Pre-production" }, { "value": "production", "label": "Production" } ] }
48
- ]
49
- },
50
- "settings": { // JSON Schema → a form in the console
51
- "type": "object",
52
- "properties": { "targetMarket": { "type": "string", "default": "GB" } }
53
- },
54
- "presets": [
55
- { "id": "import-products", "title": "Import products", "direction": "inbound", "entity": "product",
56
- "flow": { "config": { "fieldMappings": [ /* a suggested mapping the customer can edit */ ] } } }
57
- ],
58
- "functions": { // names of this app's server functions
59
- "testConnection": "testConnection",
60
- "describeTarget": "describeTarget",
61
- "sample": "sample",
62
- "shape": "shape",
63
- "fetch": "fetch"
64
- },
65
- "panels": [ { "id": "explorer", "title": "Explorer", "component": "Explorer" } ],
66
- "aiGuide": "connector-ai-guide.md"
67
- },
68
- "functions": {
69
- "files": { "js": { "umd": "functions.umd.js" } },
70
- "definitions": [
71
- { "name": "testConnection", "trigger": { "type": "http", "method": "POST" },
72
- "visibility": "admin", "authority": "collection",
73
- "capabilities": ["network:content1-api.1worldsync.com", "secrets:oneworldsync-app-id", "secrets:oneworldsync-secret-key"] }
74
- // …one definition per function named above
75
- ]
76
- }
77
- ```
78
-
79
- Types: `AppConnectorDeclaration` and friends in `@proveanything/smartlinks` (`src/types/appManifest.ts`).
80
-
81
- | Field | Meaning |
82
- |---|---|
83
- | `provider` | Stable provider key (`syndigo`, `oneworldsync`). |
84
- | `title` | Provider display name; defaults to the app name. |
85
- | `directions` | `inbound` (provider → SmartLinks), `outbound` (SmartLinks → provider), or both. |
86
- | `entities` | SmartLinks entities it maps: `product`, and for people-shaped providers `interaction`, `contact`, `event` (see [Loyalty and CRM connectors](#loyalty-and-crm-connectors)). |
87
- | `connection.fields[]` | The console's **Connect** form. A field with `secret` is stored as this app's secret of that name on the collection (write-only; never returned to the browser). Other fields are saved in the installation's connection settings. |
88
- | `settings` | JSON Schema for installation settings; the console renders it as a form. |
89
- | `presets[]` | Ready-made flows ("Products → provider"). A preset's `flow.config.fieldMappings` is a **suggested** mapping: the connector's knowledge of the provider, which the customer accepts or edits in core. |
90
- | `functions` | Which of this app's server functions implement each step (below). Fill in only what applies. |
91
- | `panels[]` | Provider-specific screens the console mounts (an API explorer, a status page). |
92
- | `aiGuide` | A guide the mapping assistant reads: the provider's quirks, required fields, good defaults. |
93
- | `recordId` | Path of the provider's own id in a fetched record (e.g. `gtin`). Inbound records are landed and matched by it, so a re-import updates the same product instead of creating another. Default `id`; a flow can override it (`config.upsert.externalIdPath`). |
94
- | `limits` | `{ requestsPerSecond }` toward the provider, enforced across every SmartLinks worker; `{ maxEvents, maxAttributes }` when the provider caps registered events — a flow's `eventMapping` is checked against them when saved. |
95
- | `actions[]` | Provider operations invoked on demand (redeem, enrol, issue…): name, title, function, `visibility`, input schema. See [Actions](#actions-provider-operations-on-demand). |
96
-
97
- ---
98
-
99
- ## The functions
100
-
101
- Each step names one of the app's server functions. Declare them as **http POST, `visibility:
102
- "admin"`, `authority: "collection"`**: the engine calls them with no signed-in user (a product edit, a
103
- schedule), and the console calls the same functions while an admin configures the flow. The input
104
- arrives as `event.body`; return the result as JSON. Capabilities still cap what each one can do:
105
- declare the provider's hosts (`network:<host>`) and the secrets it reads (`secrets:<name>`).
106
-
107
- | Step | Called by | Input (`event.body`) | Returns |
108
- |---|---|---|---|
109
- | `testConnection` | Connect form, **Test** | `{ installation }` | `ConnectorTestResult` `{ ok, message }` |
110
- | `describeTarget` | Mapper opens | `{ installation }` | `ConnectorTargetSchema` `{ fields: [{ path, label, type, required, enum }] }`: the provider's fields *for this customer*. Outbound mappings target these paths. |
111
- | `sample` | Mapper, AI assist, dry run | `{ installation, limit }` | `ConnectorRecords` `{ records }`: real provider records |
112
- | `fetch` | Every inbound run | `ConnectorFetchInput` `{ installation, cursor, limit }` | `ConnectorRecords` `{ records, nextCursor }`: one page per call |
113
- | `shape` | Every inbound run (and sample dry runs) | `ConnectorShapeInput` `{ installation, records }` | `ConnectorShapeResult` `{ documents, skipped }`: one provider-neutral document per record, same order; `null` skips one |
114
- | `serialize` | Every outbound run | `ConnectorSerializeInput` `{ installation, documents, entities, targetOptions, eventType? }`: documents core mapped to `describeTarget` paths; `entities` = the SmartLinks record each came from (id, name); `targetOptions` = per-field options the mapping carries (e.g. locale, unit); a deletion arrives as `{ id, _deleted: true }` | `ConnectorSerializeResult` `{ payloads, skipped }`: one provider payload per document, same order; `null` skips one |
115
- | `send` | Every outbound run | `ConnectorSendInput` `{ installation, payloads, eventType? }` | `ConnectorSendResult` `{ results: [{ index, ok, status, error, externalId, retryable?, retryAfterSeconds? }] }` — `retryable: false` for a provider validation error (dead at once), `true` / a 5xx or 429 status for anything worth retrying |
116
- | `describeEvents` | Mapper opens; a flow with an `eventMapping` is saved | `{ installation }` | `ConnectorEventsSchema` `{ events: [{ name, title, attributes: [{ name, type, required }] }], limits: { maxEvents, maxAttributes } }`: the event names the provider has registered for this customer |
117
- | `lookup` | An entitlement check (`docs/entitlements.md`) | `ConnectorLookupInput` `{ installation, identity: { externalId, email, phone } \| { externalId, emailHash, phoneHash }, want }` | `ConnectorLookupResult` `{ found, memberId, tier, points, status, attributes, asOf }`. Throw for an outage — never `found: false` |
118
-
119
- **How a run flows:**
120
- - **Inbound:** `fetch` (paged; every record is landed as received) → `shape` → core maps the documents
121
- with the flow's mapping → upsert, matched by `recordId`. Unchanged records aren't processed again; a
122
- changed flow configuration replays the landed records without fetching.
123
- - **Outbound:** gather the SmartLinks records → core maps them to the provider's fields → `serialize`
124
- → `send` (or a generic transport). A record identical to its last successful delivery isn't sent again.
125
- - Large runs are processed in short slices that resume after an interruption; there's no record cap.
126
-
127
- **What happens when a step is left out:**
128
- - **No `shape`:** core maps the provider records as they come.
129
- - **No `serialize`:** the mapped documents are sent as they are.
130
- - **No `send`:** the flow's own transport is used: HTTP (`config.connection`), or Azure Event Hub with
131
- `config.transport: 'eventhub'` and `config.eventHub`.
132
- - **No `describeTarget`:** the mapper offers free-text target paths.
133
-
134
- **What `shape` should produce:** plain, predictable JSON a person can map without reading the
135
- provider's documentation. Flatten the provider's envelopes, name things plainly, keep codes alongside
136
- their meanings, and put repeated sections (ingredients, allergens, nutrients, images) in arrays. The
137
- same provider record always gives the same document.
138
-
139
- ### `installation`
140
-
141
- Every step receives the installation it serves:
142
-
143
- ```ts
144
- interface ConnectorInstallation {
145
- collectionId: string
146
- appId: string // the connector app
147
- flowId?: string | null // when called for a flow
148
- connection: Record<string, unknown> // non-secret Connect-form fields
149
- settings: Record<string, unknown> // installation settings, with the flow's overrides on top
150
- }
151
- ```
152
-
153
- Secrets are never in it. Read them in the function with `ctx.secrets.get('<name>')`, which needs the
154
- matching `secrets:<name>` capability. A secret the customer set on their collection wins; otherwise the
155
- connector's own app-level secret of that name (set in Forge) is used, so a connector can ship with
156
- SmartLinks' credentials as the default.
157
-
158
- ### Example: `fetch` and `shape`
159
-
160
- ```ts
161
- // src/functions/index.ts (the app's functions bundle)
162
- import type { ConnectorFetchInput, ConnectorRecords, ConnectorShapeInput, ConnectorShapeResult } from '@proveanything/smartlinks'
163
-
164
- export async function fetch(ctx: any, event: any): Promise<ConnectorRecords> {
165
- const { installation, cursor, limit = 50 } = event.body as ConnectorFetchInput
166
- const appId = await ctx.secrets.get('provider-app-id')
167
- const key = await ctx.secrets.get('provider-secret-key')
168
- const res = await ctx.fetch(buildSignedUrl(installation, { cursor, limit }, appId, key))
169
- const page = await res.json()
170
- return { records: page.items, nextCursor: page.next ?? null }
171
- }
172
-
173
- export async function shape(_ctx: any, event: any): Promise<ConnectorShapeResult> {
174
- const { records } = event.body as ConnectorShapeInput
175
- return {
176
- documents: records.map((r: any) => ({
177
- gtin: r.item?.gtin,
178
- name: r.item?.tradeItemDescription?.[0]?.value,
179
- brand: r.item?.brandName,
180
- ingredients: (r.item?.ingredients ?? []).map((i: any) => ({ name: i.name, percent: i.percentage })),
181
- })),
182
- }
183
- }
184
- ```
185
-
186
- ---
187
-
188
- ## Loyalty and CRM connectors
189
-
190
- A provider that is about **people** rather than products uses the same contract with three more
191
- pieces; nothing provider-specific lives in core. Full contract: `loyalty-connector-authoring.md` in the
192
- platform's design docs; the shapes are in [integrations.md](integrations.md#event-sourced-flows-and-the-envelope).
193
-
194
- | Flow | What core does | What the connector does |
195
- |---|---|---|
196
- | **Earn** (us → them) | an outbound flow with `sourceEntity: 'interaction' \| 'contact' \| 'event'` sends one **envelope** per event, through the flow's identity policy and `eventMapping`, signed, with retries and a run log | `describeEvents` (what the provider has registered), `serialize` (envelope → the provider's event payload), `send` if the generic HTTP destination can't make the call |
197
- | **Profile** (them → us) | `ctx.sl.members.apply(document)` matches the contact and writes member id, tier, points, tags, external ids; or an inbound flow with `targetEntity: 'contact'` | an **HTTP-trigger function** receiving the provider's member webhook (verify their signature, then apply); or `fetch` + `shape` for a poll |
198
- | **Gate / display** (on demand) | `entitlements.check` — claims → cached `lookup` → the contact's own loyalty fields → fallback; Valkey cache keyed on an identity hash, brand-set TTL | `lookup`: one identity → tier / points / status |
199
-
200
- ```ts
201
- // A member webhook: the provider tells us about a person; we land it on the contact.
202
- export default async function memberWebhook(event: any, ctx: any) {
203
- verifyProviderSignature(event, await ctx.secrets.get('webhookSecret'))
204
- const m = event.body
205
- return ctx.sl.members.apply({
206
- identity: { externalId: m.memberId, email: m.email },
207
- contact: { firstName: m.firstName, lastName: m.lastName }, // fills empty fields only
208
- loyalty: { memberId: m.memberId, tier: m.tier, points: m.points, status: m.status, asOf: m.updatedAt },
209
- tags: { add: [`tier:${m.tier}`] },
210
- }, { provider: 'acme-loyalty' }) // → { contactId, op: 'created' | 'updated' | 'unchanged' }
211
- }
212
- ```
213
-
214
- Declare it `{ "trigger": { "type": "http" }, "capabilities": ["sl:members:write", "secrets:webhookSecret"] }`;
215
- `sl:members:write` is approved by the admin on install. The envelope's `identity.externalIds[<provider>]`
216
- is the member id this wrote back, so **Earn** can address the member by the provider's own id.
217
-
218
- A connector should ship an `eventMapping` **preset** with the provider's standard event names and an
219
- `aiGuide` paragraph, so the console's assistant proposes a customer's mapping in the provider's terms.
220
-
221
- ---
222
-
223
- ## Actions: provider operations on demand
224
-
225
- Steps are called by the engine. **Actions** are called when someone asks: redeem a reward, enrol a
226
- member, issue a coupon, raise a ticket, send a receipt, check a balance. A connector declares them in
227
- the manifest and implements each as a server function; the platform decides who may call them and
228
- runs them with the connector's credentials, telling the function who asked.
229
-
230
- ```jsonc
231
- "connector": {
232
- "actions": [
233
- { "name": "redeem", "title": "Redeem a reward", "function": "redeemReward", "visibility": "member",
234
- "input": { "type": "object", "required": ["rewardId"], "properties": { "rewardId": { "type": "string" } } } },
235
- { "name": "enrol", "title": "Join the programme", "function": "enrolMember", "visibility": "member" },
236
- { "name": "coupon-status", "title": "Coupon status", "function": "couponStatus", "visibility": "public" },
237
- { "name": "adjust-points", "title": "Adjust points", "function": "adjustPoints" } // admin only (the default)
238
- ]
239
- }
240
- ```
241
-
242
- | `visibility` | Who may invoke it |
243
- |---|---|
244
- | `admin` (default) | the console and admin API; any app function |
245
- | `member` | also a signed-in person through the Hub / a site |
246
- | `public` | also anyone |
247
-
248
- The function receives `event.body = { input, installation, caller: { userId, contactId, role, surface } }`
249
- and returns JSON (or a `Response`). `input.required` fields from the declared schema are checked before
250
- the function runs (400 with `missing[]`); fuller validation is the connector's job.
251
-
252
- ```ts
253
- export async function redeemReward(ctx: any, event: any) {
254
- const { input, caller } = event.body
255
- if (!caller.contactId) return new Response(JSON.stringify({ error: 'no_contact' }), { status: 400 })
256
- const memberId = (await ctx.sl.contacts.forCaller())?.customFields?.loyaltyMemberId // written by Profile
257
- const res = await ctx.fetch(`${api}/members/${memberId}/redemptions`, { method: 'POST', headers: auth(await ctx.secrets.get('apiKey')), body: JSON.stringify({ reward: input.rewardId }) })
258
- return res.json()
259
- }
260
- ```
261
-
262
- Calling an action:
263
-
264
- ```ts
265
- // From the Hub or a site (visibility public / member):
266
- const { actions } = await integrations.listConnectorActions(collectionId, 'acme-loyalty')
267
- const out = await integrations.callConnectorAction(collectionId, 'acme-loyalty', 'redeem', { rewardId: 'R-5' })
268
-
269
- // From another app's server function (any visibility; needs sl:connectors:write):
270
- const out = await ctx.sl.connectors.call('acme-loyalty', 'redeem', { rewardId: 'R-5' })
271
-
272
- // From the console (any visibility):
273
- await integrations.runConnectorAction(collectionId, 'acme-loyalty', 'adjust-points', { memberId, delta: 100 })
274
- ```
275
-
276
- ---
277
-
278
- ## Where configuration lives
279
-
280
- | What | Where |
281
- |---|---|
282
- | Connect-form values (non-secret), installation settings | The connector app's config on the collection, in its admin-only zone (`admin.connector.connection`, `admin.connector.settings`). |
283
- | Credentials | The connector app's secrets, by the names its fields declare (the customer's on their collection, else the connector's default). |
284
- | One flow's use of the connector | The flow: `config.connector = { appId, preset?, settings? }` (per-flow settings override the installation's), plus `config.fieldMappings`, which core runs. |
285
-
286
- ```ts
287
- await integrations.createFlow(collectionId, {
288
- appId: 'core-integrations',
289
- direction: 'inbound',
290
- name: 'Import products from 1WorldSync',
291
- status: 'active',
292
- schedule: '0 * * * *',
293
- targetEntity: 'product',
294
- config: {
295
- connector: { appId: 'oneworldsync', preset: 'import-products' },
296
- // Maps the connector's shaped documents (not the raw provider records) onto the product.
297
- fieldMappings: [ { targetPath: 'name', sourcePath: 'name', transformType: 'direct' } ],
298
- },
299
- })
300
- ```
301
-
302
- ---
303
-
304
- ## From the console
305
-
306
- ```ts
307
- import { integrations, secrets } from '@proveanything/smartlinks'
308
-
309
- const { connectors } = await integrations.listConnectors(collectionId)
310
- // → [{ appId, name, version, connector, installation: { connection, settings }, secrets: { 'provider-key': { set, hint } } }]
311
-
312
- await secrets.put(collectionId, 'provider-key', value, { appId }) // a secret field
313
- await integrations.saveConnectorInstallation(collectionId, appId, { connection: { environment: 'production' } })
314
- const test = await integrations.runConnectorStep(collectionId, appId, 'testConnection')
315
- const target = await integrations.runConnectorStep(collectionId, appId, 'describeTarget')
316
- const events = await integrations.runConnectorStep(collectionId, appId, 'describeEvents') // loyalty / engagement providers
317
- const { records } = await integrations.runConnectorStep(collectionId, appId, 'sample', { limit: 5 })
318
- const shaped = await integrations.runConnectorStep(collectionId, appId, 'shape', { records }) // dry run
319
- const wire = await integrations.runConnectorStep(collectionId, appId, 'serialize', { documents }) // dry run
320
- ```
321
-
322
- `send` and `fetch` only run inside a flow. A flow run's summary carries `sent` (outbound) or
323
- `created` / `updated` / `skipped` (inbound), and every run, inbound or outbound, is in the run history.
324
-
325
- ---
326
-
327
- ## Panels
328
-
329
- A connector can contribute screens to the integrations console (an API explorer, say). Each
330
- `panels[]` entry names a component exported from the app's widgets bundle; the console mounts it
331
- host-side and passes it the collection and the installation. Panels are admin-only and call the
332
- connector's own functions.
333
-
334
- ---
335
-
336
- ## Who can build connectors
337
-
338
- First-party connectors run in-process, like any app server function. Third-party connectors will run
339
- in the isolated runner (see [server-functions.md](server-functions.md)) once that opens up; the contract
340
- does not change.
1
+ # Integration connectors
2
+
3
+ A **connector** is an app that knows one external provider (a PIM, a content network, a shop
4
+ platform, a loyalty or CRM system…). It is installed on a collection like any app, versioned and released like any app, and
5
+ it adds a manifest `connector` block plus a handful of [server functions](server-functions.md) the
6
+ integration engine and the integrations console call by convention.
7
+
8
+ Three layers, each with one job:
9
+
10
+ | Layer | Holds |
11
+ |---|---|
12
+ | **Engine** (the API) | [Integration flows](integrations.md), runs and their logs, triggers (events, schedule, Run now), the secret store, **the mapping** (each customer's field mappings and rules), generic transports (HTTP, Event Hub). No provider code. |
13
+ | **Integrations console** (a core app) | The one admin screen: installed connectors, connect forms, settings, the mapper with AI assist, flows, runs. |
14
+ | **Connector apps** | One per provider: an **adapter**. Talks to the provider and converts between its format and a clean, provider-neutral document. |
15
+
16
+ **A connector adapts; core maps.** A connector never holds a customer's mapping. It turns the
17
+ provider's records into provider-neutral documents (`shape`), or provider-ready payloads out of
18
+ documents core has already mapped (`serialize`). Every customer's mapping, routing and rules live in
19
+ core, so they work the same for every provider and can be replayed and traced. This is the line
20
+ SnapLogic (endpoint Snaps vs the Mapper), MuleSoft and Airbyte all draw.
21
+
22
+ A flow that only posts JSON to a webhook or an Event Hub needs no connector; it uses the engine's
23
+ generic transports (see [integrations.md](integrations.md)).
24
+
25
+ **No AI at run time.** The AI helps an admin *author* a mapping in the console (from the connector's
26
+ target schema plus real sample records); a person approves it, and it is saved as data and runs
27
+ deterministically. A connector's `shape` and `serialize` must be deterministic too.
28
+
29
+ ---
30
+
31
+ ## The manifest block
32
+
33
+ ```jsonc
34
+ // app.manifest.json
35
+ "connector": {
36
+ "provider": "oneworldsync",
37
+ "title": "1WorldSync",
38
+ "directions": ["inbound"],
39
+ "entities": ["product"],
40
+ "connection": {
41
+ "fields": [
42
+ // Optional: SmartLinks' own credentials are the default; a customer may enter theirs.
43
+ { "name": "appId", "label": "App ID", "secret": "oneworldsync-app-id" },
44
+ { "name": "secretKey", "label": "Secret key", "secret": "oneworldsync-secret-key" },
45
+ { "name": "gln", "label": "GLN", "required": true },
46
+ { "name": "environment", "label": "Environment", "type": "select",
47
+ "options": [ { "value": "preprod", "label": "Pre-production" }, { "value": "production", "label": "Production" } ] }
48
+ ]
49
+ },
50
+ "settings": { // JSON Schema → a form in the console
51
+ "type": "object",
52
+ "properties": { "targetMarket": { "type": "string", "default": "GB" } }
53
+ },
54
+ "presets": [
55
+ { "id": "import-products", "title": "Import products", "direction": "inbound", "entity": "product",
56
+ "flow": { "config": { "fieldMappings": [ /* a suggested mapping the customer can edit */ ] } } }
57
+ ],
58
+ "functions": { // names of this app's server functions
59
+ "testConnection": "testConnection",
60
+ "describeTarget": "describeTarget",
61
+ "sample": "sample",
62
+ "shape": "shape",
63
+ "fetch": "fetch"
64
+ },
65
+ "panels": [ { "id": "explorer", "title": "Explorer", "component": "Explorer" } ],
66
+ "aiGuide": "connector-ai-guide.md"
67
+ },
68
+ "functions": {
69
+ "files": { "js": { "umd": "functions.umd.js" } },
70
+ "definitions": [
71
+ { "name": "testConnection", "trigger": { "type": "http", "method": "POST" },
72
+ "visibility": "admin", "authority": "collection",
73
+ "capabilities": ["network:content1-api.1worldsync.com", "secrets:oneworldsync-app-id", "secrets:oneworldsync-secret-key"] }
74
+ // …one definition per function named above
75
+ ]
76
+ }
77
+ ```
78
+
79
+ Types: `AppConnectorDeclaration` and friends in `@proveanything/smartlinks` (`src/types/appManifest.ts`).
80
+
81
+ | Field | Meaning |
82
+ |---|---|
83
+ | `provider` | Stable provider key (`syndigo`, `oneworldsync`). |
84
+ | `title` | Provider display name; defaults to the app name. |
85
+ | `directions` | `inbound` (provider → SmartLinks), `outbound` (SmartLinks → provider), or both. |
86
+ | `entities` | SmartLinks entities it maps: `product`, and for people-shaped providers `interaction`, `contact`, `event` (see [Loyalty and CRM connectors](#loyalty-and-crm-connectors)). |
87
+ | `connection.fields[]` | The console's **Connect** form. A field with `secret` is stored as this app's secret of that name on the collection (write-only; never returned to the browser). Other fields are saved in the installation's connection settings. |
88
+ | `settings` | JSON Schema for installation settings; the console renders it as a form. |
89
+ | `presets[]` | Ready-made flows ("Products → provider"). A preset's `flow.config.fieldMappings` is a **suggested** mapping: the connector's knowledge of the provider, which the customer accepts or edits in core. |
90
+ | `functions` | Which of this app's server functions implement each step (below). Fill in only what applies. |
91
+ | `panels[]` | Provider-specific screens the console mounts (an API explorer, a status page). |
92
+ | `aiGuide` | A guide the mapping assistant reads: the provider's quirks, required fields, good defaults. |
93
+ | `recordId` | Path of the provider's own id in a fetched record (e.g. `gtin`). Inbound records are landed and matched by it, so a re-import updates the same product instead of creating another. Default `id`; a flow can override it (`config.upsert.externalIdPath`). |
94
+ | `limits` | `{ requestsPerSecond }` toward the provider, enforced across every SmartLinks worker; `{ maxEvents, maxAttributes }` when the provider caps registered events — a flow's `eventMapping` is checked against them when saved. |
95
+ | `actions[]` | Provider operations invoked on demand (redeem, enrol, issue…): name, title, function, `visibility`, input schema. See [Actions](#actions-provider-operations-on-demand). |
96
+
97
+ ---
98
+
99
+ ## The functions
100
+
101
+ Each step names one of the app's server functions. Declare them as **http POST, `visibility:
102
+ "admin"`, `authority: "collection"`**: the engine calls them with no signed-in user (a product edit, a
103
+ schedule), and the console calls the same functions while an admin configures the flow. The input
104
+ arrives as `event.body`; return the result as JSON. Capabilities still cap what each one can do:
105
+ declare the provider's hosts (`network:<host>`) and the secrets it reads (`secrets:<name>`).
106
+
107
+ | Step | Called by | Input (`event.body`) | Returns |
108
+ |---|---|---|---|
109
+ | `testConnection` | Connect form, **Test** | `{ installation }` | `ConnectorTestResult` `{ ok, message }` |
110
+ | `describeTarget` | Mapper opens | `{ installation }` | `ConnectorTargetSchema` `{ fields: [{ path, label, type, required, enum }] }`: the provider's fields *for this customer*. Outbound mappings target these paths. |
111
+ | `sample` | Mapper, AI assist, dry run | `{ installation, limit }` | `ConnectorRecords` `{ records }`: real provider records |
112
+ | `fetch` | Every inbound run | `ConnectorFetchInput` `{ installation, cursor, limit }` | `ConnectorRecords` `{ records, nextCursor }`: one page per call |
113
+ | `shape` | Every inbound run (and sample dry runs) | `ConnectorShapeInput` `{ installation, records }` | `ConnectorShapeResult` `{ documents, skipped }`: one provider-neutral document per record, same order; `null` skips one |
114
+ | `serialize` | Every outbound run | `ConnectorSerializeInput` `{ installation, documents, entities, targetOptions, eventType? }`: documents core mapped to `describeTarget` paths; `entities` = the SmartLinks record each came from (id, name); `targetOptions` = per-field options the mapping carries (e.g. locale, unit); a deletion arrives as `{ id, _deleted: true }` | `ConnectorSerializeResult` `{ payloads, skipped }`: one provider payload per document, same order; `null` skips one |
115
+ | `send` | Every outbound run | `ConnectorSendInput` `{ installation, payloads, eventType? }` | `ConnectorSendResult` `{ results: [{ index, ok, status, error, externalId, retryable?, retryAfterSeconds? }] }` — `retryable: false` for a provider validation error (dead at once), `true` / a 5xx or 429 status for anything worth retrying |
116
+ | `describeEvents` | Mapper opens; a flow with an `eventMapping` is saved | `{ installation }` | `ConnectorEventsSchema` `{ events: [{ name, title, attributes: [{ name, type, required }] }], limits: { maxEvents, maxAttributes } }`: the event names the provider has registered for this customer |
117
+ | `lookup` | An entitlement check (`docs/entitlements.md`) | `ConnectorLookupInput` `{ installation, identity: { externalId, email, phone } \| { externalId, emailHash, phoneHash }, want }` | `ConnectorLookupResult` `{ found, memberId, tier, points, status, attributes, asOf }`. Throw for an outage — never `found: false` |
118
+
119
+ **How a run flows:**
120
+ - **Inbound:** `fetch` (paged; every record is landed as received) → `shape` → core maps the documents
121
+ with the flow's mapping → upsert, matched by `recordId`. Unchanged records aren't processed again; a
122
+ changed flow configuration replays the landed records without fetching.
123
+ - **Outbound:** gather the SmartLinks records → core maps them to the provider's fields → `serialize`
124
+ → `send` (or a generic transport). A record identical to its last successful delivery isn't sent again.
125
+ - Large runs are processed in short slices that resume after an interruption; there's no record cap.
126
+
127
+ **What happens when a step is left out:**
128
+ - **No `shape`:** core maps the provider records as they come.
129
+ - **No `serialize`:** the mapped documents are sent as they are.
130
+ - **No `send`:** the flow's own transport is used: HTTP (`config.connection`), or Azure Event Hub with
131
+ `config.transport: 'eventhub'` and `config.eventHub`.
132
+ - **No `describeTarget`:** the mapper offers free-text target paths.
133
+
134
+ **What `shape` should produce:** plain, predictable JSON a person can map without reading the
135
+ provider's documentation. Flatten the provider's envelopes, name things plainly, keep codes alongside
136
+ their meanings, and put repeated sections (ingredients, allergens, nutrients, images) in arrays. The
137
+ same provider record always gives the same document.
138
+
139
+ ### `installation`
140
+
141
+ Every step receives the installation it serves:
142
+
143
+ ```ts
144
+ interface ConnectorInstallation {
145
+ collectionId: string
146
+ appId: string // the connector app
147
+ flowId?: string | null // when called for a flow
148
+ connection: Record<string, unknown> // non-secret Connect-form fields
149
+ settings: Record<string, unknown> // installation settings, with the flow's overrides on top
150
+ }
151
+ ```
152
+
153
+ Secrets are never in it. Read them in the function with `ctx.secrets.get('<name>')`, which needs the
154
+ matching `secrets:<name>` capability. A secret the customer set on their collection wins; otherwise the
155
+ connector's own app-level secret of that name (set in Forge) is used, so a connector can ship with
156
+ SmartLinks' credentials as the default.
157
+
158
+ ### Example: `fetch` and `shape`
159
+
160
+ ```ts
161
+ // src/functions/index.ts (the app's functions bundle)
162
+ import type { ConnectorFetchInput, ConnectorRecords, ConnectorShapeInput, ConnectorShapeResult } from '@proveanything/smartlinks'
163
+
164
+ export async function fetch(ctx: any, event: any): Promise<ConnectorRecords> {
165
+ const { installation, cursor, limit = 50 } = event.body as ConnectorFetchInput
166
+ const appId = await ctx.secrets.get('provider-app-id')
167
+ const key = await ctx.secrets.get('provider-secret-key')
168
+ const res = await ctx.fetch(buildSignedUrl(installation, { cursor, limit }, appId, key))
169
+ const page = await res.json()
170
+ return { records: page.items, nextCursor: page.next ?? null }
171
+ }
172
+
173
+ export async function shape(_ctx: any, event: any): Promise<ConnectorShapeResult> {
174
+ const { records } = event.body as ConnectorShapeInput
175
+ return {
176
+ documents: records.map((r: any) => ({
177
+ gtin: r.item?.gtin,
178
+ name: r.item?.tradeItemDescription?.[0]?.value,
179
+ brand: r.item?.brandName,
180
+ ingredients: (r.item?.ingredients ?? []).map((i: any) => ({ name: i.name, percent: i.percentage })),
181
+ })),
182
+ }
183
+ }
184
+ ```
185
+
186
+ ---
187
+
188
+ ## Loyalty and CRM connectors
189
+
190
+ A provider that is about **people** rather than products uses the same contract with three more
191
+ pieces; nothing provider-specific lives in core. Full contract: `loyalty-connector-authoring.md` in the
192
+ platform's design docs; the shapes are in [integrations.md](integrations.md#event-sourced-flows-and-the-envelope).
193
+
194
+ | Flow | What core does | What the connector does |
195
+ |---|---|---|
196
+ | **Earn** (us → them) | an outbound flow with `sourceEntity: 'interaction' \| 'contact' \| 'event'` sends one **envelope** per event, through the flow's identity policy and `eventMapping`, signed, with retries and a run log | `describeEvents` (what the provider has registered), `serialize` (envelope → the provider's event payload), `send` if the generic HTTP destination can't make the call |
197
+ | **Profile** (them → us) | `ctx.sl.members.apply(document)` matches the contact and writes member id, tier, points, tags, external ids; or an inbound flow with `targetEntity: 'contact'` | an **HTTP-trigger function** receiving the provider's member webhook (verify their signature, then apply); or `fetch` + `shape` for a poll |
198
+ | **Gate / display** (on demand) | `entitlements.check` — claims → cached `lookup` → the contact's own loyalty fields → fallback; Valkey cache keyed on an identity hash, brand-set TTL | `lookup`: one identity → tier / points / status |
199
+
200
+ ```ts
201
+ // A member webhook: the provider tells us about a person; we land it on the contact.
202
+ export default async function memberWebhook(event: any, ctx: any) {
203
+ verifyProviderSignature(event, await ctx.secrets.get('webhookSecret'))
204
+ const m = event.body
205
+ return ctx.sl.members.apply({
206
+ identity: { externalId: m.memberId, email: m.email },
207
+ contact: { firstName: m.firstName, lastName: m.lastName }, // fills empty fields only
208
+ loyalty: { memberId: m.memberId, tier: m.tier, points: m.points, status: m.status, asOf: m.updatedAt },
209
+ tags: { add: [`tier:${m.tier}`] },
210
+ }, { provider: 'acme-loyalty' }) // → { contactId, op: 'created' | 'updated' | 'unchanged' }
211
+ }
212
+ ```
213
+
214
+ Declare it `{ "trigger": { "type": "http" }, "capabilities": ["sl:members:write", "secrets:webhookSecret"] }`;
215
+ `sl:members:write` is approved by the admin on install. The envelope's `identity.externalIds[<provider>]`
216
+ is the member id this wrote back, so **Earn** can address the member by the provider's own id.
217
+
218
+ A connector should ship an `eventMapping` **preset** with the provider's standard event names and an
219
+ `aiGuide` paragraph, so the console's assistant proposes a customer's mapping in the provider's terms.
220
+
221
+ ---
222
+
223
+ ## Actions: provider operations on demand
224
+
225
+ Steps are called by the engine. **Actions** are called when someone asks: redeem a reward, enrol a
226
+ member, issue a coupon, raise a ticket, send a receipt, check a balance. A connector declares them in
227
+ the manifest and implements each as a server function; the platform decides who may call them and
228
+ runs them with the connector's credentials, telling the function who asked.
229
+
230
+ ```jsonc
231
+ "connector": {
232
+ "actions": [
233
+ { "name": "redeem", "title": "Redeem a reward", "function": "redeemReward", "visibility": "member",
234
+ "input": { "type": "object", "required": ["rewardId"], "properties": { "rewardId": { "type": "string" } } } },
235
+ { "name": "enrol", "title": "Join the programme", "function": "enrolMember", "visibility": "member" },
236
+ { "name": "coupon-status", "title": "Coupon status", "function": "couponStatus", "visibility": "public" },
237
+ { "name": "adjust-points", "title": "Adjust points", "function": "adjustPoints" } // admin only (the default)
238
+ ]
239
+ }
240
+ ```
241
+
242
+ | `visibility` | Who may invoke it |
243
+ |---|---|
244
+ | `admin` (default) | the console and admin API; any app function |
245
+ | `member` | also a signed-in person through the Hub / a site |
246
+ | `public` | also anyone |
247
+
248
+ The function receives `event.body = { input, installation, caller: { userId, contactId, role, surface } }`
249
+ and returns JSON (or a `Response`). `input.required` fields from the declared schema are checked before
250
+ the function runs (400 with `missing[]`); fuller validation is the connector's job.
251
+
252
+ ```ts
253
+ export async function redeemReward(ctx: any, event: any) {
254
+ const { input, caller } = event.body
255
+ if (!caller.contactId) return new Response(JSON.stringify({ error: 'no_contact' }), { status: 400 })
256
+ const memberId = (await ctx.sl.contacts.forCaller())?.customFields?.loyaltyMemberId // written by Profile
257
+ const res = await ctx.fetch(`${api}/members/${memberId}/redemptions`, { method: 'POST', headers: auth(await ctx.secrets.get('apiKey')), body: JSON.stringify({ reward: input.rewardId }) })
258
+ return res.json()
259
+ }
260
+ ```
261
+
262
+ Calling an action:
263
+
264
+ ```ts
265
+ // From the Hub or a site (visibility public / member):
266
+ const { items: actions } = await integrations.listConnectorActions(collectionId, 'acme-loyalty')
267
+ const out = await integrations.callConnectorAction(collectionId, 'acme-loyalty', 'redeem', { rewardId: 'R-5' })
268
+
269
+ // From another app's server function (any visibility; needs sl:connectors:write):
270
+ const out = await ctx.sl.connectors.call('acme-loyalty', 'redeem', { rewardId: 'R-5' })
271
+
272
+ // From the console (any visibility):
273
+ await integrations.runConnectorAction(collectionId, 'acme-loyalty', 'adjust-points', { memberId, delta: 100 })
274
+ ```
275
+
276
+ ---
277
+
278
+ ## Where configuration lives
279
+
280
+ | What | Where |
281
+ |---|---|
282
+ | Connect-form values (non-secret), installation settings | The connector app's config on the collection, in its admin-only zone (`admin.connector.connection`, `admin.connector.settings`). |
283
+ | Credentials | The connector app's secrets, by the names its fields declare (the customer's on their collection, else the connector's default). |
284
+ | One flow's use of the connector | The flow: `config.connector = { appId, preset?, settings? }` (per-flow settings override the installation's), plus `config.fieldMappings`, which core runs. |
285
+
286
+ ```ts
287
+ await integrations.createFlow(collectionId, {
288
+ appId: 'core-integrations',
289
+ direction: 'inbound',
290
+ name: 'Import products from 1WorldSync',
291
+ status: 'active',
292
+ schedule: '0 * * * *',
293
+ targetEntity: 'product',
294
+ config: {
295
+ connector: { appId: 'oneworldsync', preset: 'import-products' },
296
+ // Maps the connector's shaped documents (not the raw provider records) onto the product.
297
+ fieldMappings: [ { targetPath: 'name', sourcePath: 'name', transformType: 'direct' } ],
298
+ },
299
+ })
300
+ ```
301
+
302
+ ---
303
+
304
+ ## From the console
305
+
306
+ ```ts
307
+ import { integrations, secrets } from '@proveanything/smartlinks'
308
+
309
+ const { items: connectors } = await integrations.listConnectors(collectionId)
310
+ // → [{ appId, name, version, connector, installation: { connection, settings }, secrets: { 'provider-key': { set, hint } } }]
311
+
312
+ await secrets.put(collectionId, 'provider-key', value, { appId }) // a secret field
313
+ await integrations.saveConnectorInstallation(collectionId, appId, { connection: { environment: 'production' } })
314
+ const test = await integrations.runConnectorStep(collectionId, appId, 'testConnection')
315
+ const target = await integrations.runConnectorStep(collectionId, appId, 'describeTarget')
316
+ const events = await integrations.runConnectorStep(collectionId, appId, 'describeEvents') // loyalty / engagement providers
317
+ const { records } = await integrations.runConnectorStep(collectionId, appId, 'sample', { limit: 5 })
318
+ const shaped = await integrations.runConnectorStep(collectionId, appId, 'shape', { records }) // dry run
319
+ const wire = await integrations.runConnectorStep(collectionId, appId, 'serialize', { documents }) // dry run
320
+ ```
321
+
322
+ `send` and `fetch` only run inside a flow. A flow run's summary carries `sent` (outbound) or
323
+ `created` / `updated` / `skipped` (inbound), and every run, inbound or outbound, is in the run history.
324
+
325
+ ---
326
+
327
+ ## Panels
328
+
329
+ A connector can contribute screens to the integrations console (an API explorer, say). Each
330
+ `panels[]` entry names a component exported from the app's widgets bundle; the console mounts it
331
+ host-side and passes it the collection and the installation. Panels are admin-only and call the
332
+ connector's own functions.
333
+
334
+ ---
335
+
336
+ ## Who can build connectors
337
+
338
+ First-party connectors run in-process, like any app server function. Third-party connectors will run
339
+ in the isolated runner (see [server-functions.md](server-functions.md)) once that opens up; the contract
340
+ does not change.