@friggframework/core 2.0.0--canary.700.80ec1cc.0 → 2.0.0--canary.702.047d3c4.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 (130) hide show
  1. package/database/documentdb-utils.js +1 -6
  2. package/errors/index.js +0 -4
  3. package/generated/prisma-mongodb/edge.js +4 -52
  4. package/generated/prisma-mongodb/index-browser.js +1 -49
  5. package/generated/prisma-mongodb/index.d.ts +60 -3506
  6. package/generated/prisma-mongodb/index.js +4 -52
  7. package/generated/prisma-mongodb/package.json +1 -1
  8. package/generated/prisma-mongodb/schema.prisma +0 -65
  9. package/generated/prisma-mongodb/wasm.js +4 -52
  10. package/generated/prisma-postgresql/edge.js +4 -52
  11. package/generated/prisma-postgresql/index-browser.js +1 -49
  12. package/generated/prisma-postgresql/index.d.ts +94 -3824
  13. package/generated/prisma-postgresql/index.js +4 -52
  14. package/generated/prisma-postgresql/package.json +1 -1
  15. package/generated/prisma-postgresql/schema.prisma +0 -63
  16. package/generated/prisma-postgresql/wasm.js +4 -52
  17. package/handlers/WEBHOOKS.md +0 -29
  18. package/handlers/app-definition-loader.js +9 -2
  19. package/handlers/app-handler-helpers.js +2 -5
  20. package/handlers/integration-event-dispatcher.js +3 -7
  21. package/handlers/routers/integration-webhook-routers.js +38 -26
  22. package/index.js +0 -2
  23. package/integrations/integration-base.js +1 -162
  24. package/integrations/integration-router.js +1 -6
  25. package/integrations/repositories/integration-mapping-repository-documentdb.js +0 -50
  26. package/integrations/repositories/integration-mapping-repository-interface.js +0 -15
  27. package/integrations/repositories/integration-mapping-repository-mongo.js +0 -29
  28. package/integrations/repositories/integration-mapping-repository-postgres.js +0 -30
  29. package/integrations/repositories/integration-mapping-repository.js +0 -29
  30. package/integrations/repositories/integration-repository-documentdb.js +2 -6
  31. package/integrations/repositories/integration-repository-interface.js +0 -3
  32. package/integrations/repositories/integration-repository-mongo.js +5 -20
  33. package/integrations/repositories/integration-repository-postgres.js +1 -5
  34. package/integrations/repositories/process-repository-mongo.js +1 -1
  35. package/integrations/use-cases/create-integration.js +4 -14
  36. package/integrations/use-cases/delete-integration-for-user.js +4 -4
  37. package/integrations/use-cases/get-integration-for-user.js +2 -4
  38. package/integrations/use-cases/get-integration-instance.js +4 -4
  39. package/integrations/use-cases/get-integrations-for-user.js +4 -4
  40. package/integrations/use-cases/get-possible-integrations.js +2 -7
  41. package/integrations/use-cases/update-integration.js +4 -4
  42. package/package.json +6 -6
  43. package/prisma-mongodb/schema.prisma +0 -65
  44. package/prisma-postgresql/schema.prisma +0 -63
  45. package/queues/queuer-util.js +2 -9
  46. package/errors/mapping-already-exists-error.js +0 -14
  47. package/handlers/workers/integration-triggers.js +0 -25
  48. package/infrastructure/scheduler/recurrence.js +0 -204
  49. package/integrations/definitions/README.md +0 -278
  50. package/integrations/definitions/canonical.js +0 -11
  51. package/integrations/definitions/capabilities/AUDIT.md +0 -480
  52. package/integrations/definitions/capabilities/acmeerp.capabilities.json +0 -633
  53. package/integrations/definitions/capabilities/asana.capabilities.json +0 -279
  54. package/integrations/definitions/capabilities/calendly.capabilities.json +0 -385
  55. package/integrations/definitions/capabilities/docusign.capabilities.json +0 -314
  56. package/integrations/definitions/capabilities/fathom.capabilities.json +0 -238
  57. package/integrations/definitions/capabilities/github.capabilities.json +0 -585
  58. package/integrations/definitions/capabilities/hubspot.capabilities.json +0 -822
  59. package/integrations/definitions/capabilities/jira.capabilities.json +0 -391
  60. package/integrations/definitions/capabilities/klaviyo.capabilities.json +0 -503
  61. package/integrations/definitions/capabilities/linear.capabilities.json +0 -378
  62. package/integrations/definitions/capabilities/netsuite.capabilities.json +0 -535
  63. package/integrations/definitions/capabilities/notion.capabilities.json +0 -208
  64. package/integrations/definitions/capabilities/phone.capabilities.json +0 -511
  65. package/integrations/definitions/capabilities/pipedrive.capabilities.json +0 -430
  66. package/integrations/definitions/capabilities/quickbooks.capabilities.json +0 -635
  67. package/integrations/definitions/capabilities/salesforce.capabilities.json +0 -568
  68. package/integrations/definitions/capabilities/shopify.capabilities.json +0 -1128
  69. package/integrations/definitions/capabilities/slack.capabilities.json +0 -373
  70. package/integrations/definitions/capabilities/stripe.capabilities.json +0 -630
  71. package/integrations/definitions/capabilities/webflow.capabilities.json +0 -196
  72. package/integrations/definitions/capabilities/zendesk.capabilities.json +0 -422
  73. package/integrations/definitions/compile.js +0 -80
  74. package/integrations/definitions/config-form.js +0 -137
  75. package/integrations/definitions/examples/acme-erp-quickbooks.definition.json +0 -467
  76. package/integrations/definitions/examples/asana-slack.definition.json +0 -219
  77. package/integrations/definitions/examples/calendly-salesforce.definition.json +0 -459
  78. package/integrations/definitions/examples/docusign-salesforce.definition.json +0 -305
  79. package/integrations/definitions/examples/fathom-hubspot-notion.definition.json +0 -575
  80. package/integrations/definitions/examples/github-linear.definition.json +0 -322
  81. package/integrations/definitions/examples/hubspot-slack.definition.json +0 -427
  82. package/integrations/definitions/examples/klaviyo-hubspot.definition.json +0 -336
  83. package/integrations/definitions/examples/phone-hubspot.definition.json +0 -633
  84. package/integrations/definitions/examples/pipedrive-hubspot.definition.json +0 -136
  85. package/integrations/definitions/examples/pipedrive-phone.definition.json +0 -340
  86. package/integrations/definitions/examples/records/phone-hubspot.definition-version.json +0 -652
  87. package/integrations/definitions/examples/records/phone-hubspot.integration.json +0 -86
  88. package/integrations/definitions/examples/records/phone-hubspot.mappings.json +0 -39
  89. package/integrations/definitions/examples/records/phone-hubspot.workflow-run.json +0 -62
  90. package/integrations/definitions/examples/shopify-klaviyo.definition.json +0 -488
  91. package/integrations/definitions/examples/shopify-netsuite.definition.json +0 -622
  92. package/integrations/definitions/examples/stripe-quickbooks.definition.json +0 -476
  93. package/integrations/definitions/examples/webflow-hubspot-slack.definition.json +0 -262
  94. package/integrations/definitions/examples/zendesk-jira.definition.json +0 -604
  95. package/integrations/definitions/expressions.js +0 -229
  96. package/integrations/definitions/index.js +0 -45
  97. package/integrations/definitions/integration-runtime.js +0 -763
  98. package/integrations/definitions/interpreter.js +0 -104
  99. package/integrations/definitions/manifests.js +0 -177
  100. package/integrations/definitions/renderers/common.js +0 -67
  101. package/integrations/definitions/renderers/html.js +0 -129
  102. package/integrations/definitions/renderers/hubspot.js +0 -59
  103. package/integrations/definitions/renderers/preview.js +0 -154
  104. package/integrations/definitions/renderers/slack.js +0 -146
  105. package/integrations/definitions/repositories/definition-version-repository.js +0 -67
  106. package/integrations/definitions/repositories/workflow-run-repository.js +0 -80
  107. package/integrations/definitions/router.js +0 -170
  108. package/integrations/definitions/runtime.js +0 -268
  109. package/integrations/definitions/schema/capability-manifest.v0.1.schema.json +0 -549
  110. package/integrations/definitions/schema/installation.v0.1.schema.json +0 -130
  111. package/integrations/definitions/schema/integration-definition.v0.1.schema.json +0 -909
  112. package/integrations/definitions/schema/records.md +0 -105
  113. package/integrations/definitions/schema-check.js +0 -58
  114. package/integrations/definitions/scripts/check-manifests.js +0 -220
  115. package/integrations/definitions/scripts/validate.js +0 -66
  116. package/integrations/definitions/steps.js +0 -123
  117. package/integrations/definitions/sync-engine.js +0 -297
  118. package/integrations/definitions/tests/helpers-fake-crm.js +0 -49
  119. package/integrations/definitions/transforms.js +0 -91
  120. package/integrations/definitions/use-cases/definition-use-cases.js +0 -245
  121. package/integrations/definitions/validate.js +0 -436
  122. package/integrations/definitions/versioning.js +0 -176
  123. package/integrations/definitions/webhooks.js +0 -119
  124. package/integrations/integration-types.js +0 -64
  125. package/integrations/triggers.js +0 -244
  126. package/integrations/use-cases/run-trigger-tick.js +0 -155
  127. package/integrations/use-cases/run-trigger.js +0 -77
  128. package/prisma-postgresql/migrations/20261018000000_add_data_defined_integrations/migration.sql +0 -66
  129. package/prisma-postgresql/migrations/20261019000000_workflow_run_waits/migration.sql +0 -7
  130. package/prisma-postgresql/migrations/20261019120000_definition_workspace/migration.sql +0 -5
@@ -1,137 +0,0 @@
1
- /**
2
- * The configure form for an installation, generated from its definition: what GET_CONFIG_OPTIONS and
3
- * REFRESH_CONFIG_OPTIONS return on Frigg's existing, authenticated /api/integrations/:id/config/options routes.
4
- *
5
- * The form's data has exactly the shape of Integration.config, so what the management UI PATCHes back is the config:
6
- * { settings: { … }, syncs: { <id>: { enabled } }, workflows: { <id>: { enabled, settings: { … } } }, ui: { <id>: { enabled } } }
7
- *
8
- * Option settings become enums filled by `options(path, values)` (resolveOptions underneath). A list whose inputs are
9
- * not chosen yet comes back empty with a help line saying what to choose first; REFRESH_CONFIG_OPTIONS, called with
10
- * the form's current values, fills it.
11
- */
12
- const SETTING_SCHEMA = {
13
- string: () => ({ type: 'string' }),
14
- text: () => ({ type: 'string' }),
15
- number: () => ({ type: 'number' }),
16
- boolean: () => ({ type: 'boolean' }),
17
- duration: () => ({ type: 'string', pattern: '^\\d+(m|h|d)$' }),
18
- enum: (s) => ({ type: 'string', enum: s.enum }),
19
- };
20
-
21
- const dependsOn = (s) => (s && typeof s.options === 'object' ? Object.values(s.options.with || {}).map((v) => String(v).replace(/^\$\.(settings|install)\./, '')) : []);
22
-
23
- async function settingsSchema(settings, pathPrefix, values, options, integrationSettings) {
24
- const properties = {}, ui = {}, required = [];
25
- for (const [key, s] of Object.entries(settings || {})) {
26
- let schema;
27
- if (s.type === 'option') {
28
- const choices = await options(`${pathPrefix}.${key}`, values, integrationSettings);
29
- schema = choices.length
30
- ? { type: 'string', oneOf: choices.map((c) => ({ const: String(c.value), title: c.label })) }
31
- : { type: 'string', enum: [] };
32
- if (!choices.length && dependsOn(s).length) ui[key] = { 'ui:help': `Choose ${dependsOn(s).join(' and ')} first.` };
33
- } else schema = (SETTING_SCHEMA[s.type] || SETTING_SCHEMA.string)(s);
34
- properties[key] = { ...schema, title: s.label, ...(s.default !== undefined ? { default: s.default } : {}) };
35
- if (s.help) ui[key] = { ...(ui[key] || {}), 'ui:help': s.help };
36
- if (s.required && s.default === undefined) required.push(key);
37
- }
38
- return { schema: { type: 'object', properties, ...(required.length ? { required } : {}) }, ui };
39
- }
40
-
41
- /**
42
- * The timing field of a schedule the definition marks configurable: an interval when its default is an interval,
43
- * a cron (with time zone) when its default is a cron. The floor is said in the help text and enforced on save.
44
- */
45
- function scheduleField(recurrence, configurable) {
46
- if (!configurable || !recurrence) return null;
47
- const min = configurable.min ? ` No more often than every ${configurable.min}.` : '';
48
- if (recurrence.every !== undefined) {
49
- return { schema: { type: 'object', title: 'Schedule', properties: { every: { type: 'string', title: 'Runs every', pattern: '^\\d+\\s*(m|h|d)$', default: recurrence.every } } }, ui: { every: { 'ui:help': `Minutes, hours or days: 15m, 2h, 1d.${min}` } } };
50
- }
51
- return { schema: { type: 'object', title: 'Schedule', properties: { cron: { type: 'string', title: 'Cron', default: recurrence.cron }, timezone: { type: 'string', title: 'Time zone', default: recurrence.timezone || 'UTC' } } }, ui: { cron: { 'ui:help': `minute hour day-of-month month day-of-week.${min}` } } };
52
- }
53
- const configurableOf = (c) => (c ? (c === true ? {} : c) : false);
54
-
55
- const toggle = (title, description, enabledByDefault) => ({ type: 'boolean', title, ...(description ? { description } : {}), default: enabledByDefault });
56
- const isOn = (item, chosen) => (typeof chosen?.enabled === 'boolean' ? chosen.enabled : (item.default || 'on') === 'on');
57
-
58
- /**
59
- * @param {object} def
60
- * @param {object} config the installation's current config (or the form's current values on refresh)
61
- * @param {(path: string, values: object, integrationSettings: object) => Promise<Array<{label,value}>>} options
62
- * @returns {Promise<{ jsonSchema: object, uiSchema: object, data: object }>}
63
- */
64
- async function buildConfigForm(def, config = {}, options = async () => []) {
65
- const jsonSchema = { type: 'object', title: def.display?.label, properties: {} };
66
- const uiSchema = {};
67
- const data = { settings: { ...(config.settings || {}) }, syncs: {}, workflows: {}, ui: {} };
68
-
69
- if (Object.keys(def.settings || {}).length) {
70
- const s = await settingsSchema(def.settings, 'settings', config.settings || {}, options, config.settings || {});
71
- jsonSchema.properties.settings = { title: 'Settings', ...s.schema };
72
- uiSchema.settings = s.ui;
73
- }
74
-
75
- if ((def.syncs || []).length) {
76
- jsonSchema.properties.syncs = { type: 'object', title: 'Syncs', properties: {} };
77
- for (const s of def.syncs) {
78
- jsonSchema.properties.syncs.properties[s.id] = { type: 'object', title: s.label, properties: { enabled: toggle('On', s.description, (s.default || 'on') === 'on') } };
79
- data.syncs[s.id] = { enabled: isOn(s, config.syncs?.[s.id]) };
80
- const field = s.ongoing?.mode === 'poll' && scheduleField({ every: s.ongoing.every || '15m' }, configurableOf(s.ongoing.configurable));
81
- if (field) {
82
- jsonSchema.properties.syncs.properties[s.id].properties.schedule = field.schema;
83
- ((uiSchema.syncs ||= {})[s.id] ||= {}).schedule = field.ui;
84
- if (config.syncs?.[s.id]?.schedule) data.syncs[s.id].schedule = { ...config.syncs[s.id].schedule };
85
- }
86
- }
87
- }
88
-
89
- if ((def.workflows || []).length) {
90
- jsonSchema.properties.workflows = { type: 'object', title: 'Workflows', properties: {} };
91
- uiSchema.workflows = {};
92
- for (const w of def.workflows) {
93
- const chosen = config.workflows?.[w.id] || {};
94
- const node = { type: 'object', title: w.label, properties: { enabled: toggle('On', w.description, (w.default || 'on') === 'on') } };
95
- data.workflows[w.id] = { enabled: isOn(w, chosen), settings: { ...(chosen.settings || {}) } };
96
- if (Object.keys(w.settings || {}).length) {
97
- // A workflow setting's option inputs may read integration settings, which it sees as $.install.
98
- const s = await settingsSchema(w.settings, `workflows.${w.id}.settings`, chosen.settings || {}, options, config.settings || {});
99
- node.properties.settings = { title: 'Settings', ...s.schema };
100
- uiSchema.workflows[w.id] = { settings: s.ui };
101
- // Settings only matter while the workflow is on: required only then.
102
- node.dependencies = { enabled: { oneOf: [{ properties: { enabled: { const: false } } }, { properties: { enabled: { const: true } }, required: ['settings'] }] } };
103
- }
104
- const t = w.trigger || {};
105
- const field = t.type === 'schedule' && scheduleField(t.every !== undefined ? { every: t.every } : { cron: t.cron, timezone: t.timezone }, configurableOf(t.configurable));
106
- if (field) {
107
- node.properties.schedule = field.schema;
108
- (uiSchema.workflows[w.id] ||= {}).schedule = field.ui;
109
- if (chosen.schedule) data.workflows[w.id].schedule = { ...chosen.schedule };
110
- }
111
- jsonSchema.properties.workflows.properties[w.id] = node;
112
- }
113
- }
114
-
115
- if ((def.ui || []).length) {
116
- jsonSchema.properties.ui = { type: 'object', title: 'Cards and panels', properties: {} };
117
- for (const u of def.ui) {
118
- jsonSchema.properties.ui.properties[u.id] = { type: 'object', title: u.label || u.id, properties: { enabled: toggle('Show', `${u.host} · ${u.placement}`, (u.default || 'on') === 'on') } };
119
- data.ui[u.id] = { enabled: isOn(u, config.ui?.[u.id]) };
120
- }
121
- }
122
-
123
- return { jsonSchema, uiSchema, data };
124
- }
125
-
126
- /** Is anything required still missing? (NEEDS_CONFIG) */
127
- function missingRequired(def, config = {}) {
128
- const missing = [];
129
- for (const [k, s] of Object.entries(def.settings || {})) if (s.required && s.default === undefined && (config.settings?.[k] == null || config.settings[k] === '')) missing.push(`settings.${k}`);
130
- for (const w of def.workflows || []) {
131
- if (!isOn(w, config.workflows?.[w.id])) continue;
132
- for (const [k, s] of Object.entries(w.settings || {})) if (s.required && s.default === undefined && (config.workflows?.[w.id]?.settings?.[k] == null || config.workflows[w.id].settings[k] === '')) missing.push(`workflows.${w.id}.settings.${k}`);
133
- }
134
- return missing;
135
- }
136
-
137
- module.exports = { buildConfigForm, missingRequired };
@@ -1,467 +0,0 @@
1
- {
2
- "$schema": "https://friggframework.org/schemas/integration-definition/v0.1.json",
3
- "schemaVersion": "0.1",
4
- "id": "acme-erp-quickbooks",
5
- "version": "1.3.0",
6
- "display": {
7
- "label": "Acme ERP \u2194 QuickBooks Online",
8
- "description": "Finished jobs become QuickBooks invoices with every line item, customers stay matched both ways, and payments recorded in QuickBooks mark the job paid in Acme ERP.",
9
- "category": "Accounting",
10
- "tags": [
11
- "field-service",
12
- "invoicing",
13
- "accounting"
14
- ]
15
- },
16
- "modules": {
17
- "acmeerp": {
18
- "module": "acmeerp",
19
- "version": "^0.9"
20
- },
21
- "quickbooks": {
22
- "module": "quickbooks",
23
- "version": "^2.0"
24
- }
25
- },
26
- "settings": {
27
- "fallbackItem": {
28
- "type": "option",
29
- "options": "quickbooks.item",
30
- "label": "Product/service for line items with no matching QuickBooks item",
31
- "required": true
32
- },
33
- "terms": {
34
- "type": "enum",
35
- "label": "Invoice terms",
36
- "enum": [
37
- "Due on receipt",
38
- "Net 15",
39
- "Net 30"
40
- ],
41
- "default": "Due on receipt"
42
- }
43
- },
44
- "syncs": [
45
- {
46
- "id": "customers",
47
- "label": "Customers",
48
- "description": "One customer in both systems. Contact details follow whichever side changed last; QuickBooks owns the billing name.",
49
- "source": "acmeerp.customer",
50
- "target": "quickbooks.customer",
51
- "direction": "two_way",
52
- "identity": {
53
- "match": [
54
- {
55
- "source": "email",
56
- "target": "PrimaryEmailAddr.Address",
57
- "transform": "lowercase",
58
- "key": "email"
59
- },
60
- {
61
- "source": "mobile_number",
62
- "target": "Mobile.FreeFormNumber",
63
- "transform": "to_e164_phone",
64
- "key": "phone"
65
- }
66
- ],
67
- "onAmbiguous": "skip"
68
- },
69
- "mapping": [
70
- {
71
- "source": "display_name",
72
- "target": "DisplayName",
73
- "master": "target"
74
- },
75
- {
76
- "source": "first_name",
77
- "target": "GivenName",
78
- "master": "newest"
79
- },
80
- {
81
- "source": "last_name",
82
- "target": "FamilyName",
83
- "master": "newest"
84
- },
85
- {
86
- "source": "company_name",
87
- "target": "CompanyName",
88
- "master": "newest"
89
- },
90
- {
91
- "source": "email",
92
- "target": "PrimaryEmailAddr.Address",
93
- "transform": "lowercase",
94
- "master": "newest"
95
- },
96
- {
97
- "source": "mobile_number",
98
- "target": "Mobile.FreeFormNumber",
99
- "transform": "to_e164_phone",
100
- "master": "newest"
101
- },
102
- {
103
- "source": "address.street",
104
- "target": "BillAddr.Line1",
105
- "master": "source"
106
- },
107
- {
108
- "source": "address.city",
109
- "target": "BillAddr.City",
110
- "master": "source"
111
- },
112
- {
113
- "source": "address.state",
114
- "target": "BillAddr.CountrySubDivisionCode",
115
- "master": "source"
116
- },
117
- {
118
- "source": "address.zip",
119
- "target": "BillAddr.PostalCode",
120
- "master": "source"
121
- }
122
- ],
123
- "backfill": {
124
- "trigger": "userAction",
125
- "pageSize": 100
126
- },
127
- "ongoing": {
128
- "mode": "webhook"
129
- },
130
- "default": "on"
131
- }
132
- ],
133
- "workflows": [
134
- {
135
- "id": "job-invoice",
136
- "label": "Invoice finished jobs",
137
- "purpose": "write",
138
- "default": "on",
139
- "settings": {
140
- "emailInvoice": {
141
- "type": "boolean",
142
- "label": "Email the invoice from QuickBooks",
143
- "default": false
144
- }
145
- },
146
- "trigger": {
147
- "type": "webhook",
148
- "module": "acmeerp",
149
- "topic": "job.finished",
150
- "filter": "$.record.total_amount > 0 && $.record.external_invoice_id == null"
151
- },
152
- "steps": [
153
- {
154
- "id": "customer",
155
- "use": "links.find",
156
- "with": {
157
- "sync": "customers",
158
- "from": "acmeerp",
159
- "id": "$.record.customer_id"
160
- }
161
- },
162
- {
163
- "use": "stop",
164
- "when": "$.steps.customer == null",
165
- "with": {
166
- "reason": "Customer is not in QuickBooks yet; the queue will retry after the customer sync"
167
- }
168
- },
169
- {
170
- "id": "lineItems",
171
- "use": "acmeerp.job.lineItems",
172
- "with": {
173
- "jobId": "$.record.id"
174
- }
175
- },
176
- {
177
- "id": "lines",
178
- "use": "code",
179
- "with": {
180
- "ref": "@acme/frigg-steps#quickbooksInvoiceLines@1.0.0",
181
- "with": {
182
- "lineItems": "$.steps.lineItems",
183
- "fallbackItemId": "$.install.fallbackItem",
184
- "taxAmount": "$.record.tax_amount"
185
- }
186
- }
187
- },
188
- {
189
- "id": "memo",
190
- "use": "template",
191
- "with": {
192
- "id": "invoice-memo"
193
- }
194
- },
195
- {
196
- "id": "invoice",
197
- "use": "quickbooks.invoice.create",
198
- "with": {
199
- "invoice": {
200
- "CustomerRef": {
201
- "value": "$.steps.customer.quickbooks"
202
- },
203
- "DocNumber": "TW-{{record.job_number}}",
204
- "TxnDate": "$.record.finished_at",
205
- "SalesTermRef": {
206
- "name": "$.install.terms"
207
- },
208
- "CustomerMemo": {
209
- "value": "$.steps.memo"
210
- },
211
- "PrivateNote": "Acme ERP job {{record.id}}",
212
- "Line": "$.steps.lines.lines"
213
- }
214
- }
215
- },
216
- {
217
- "use": "acmeerp.job.update",
218
- "with": {
219
- "id": "$.record.id",
220
- "job": {
221
- "status": "invoiced",
222
- "external_invoice_id": "$.steps.invoice.Id"
223
- }
224
- }
225
- },
226
- {
227
- "use": "quickbooks.invoice.send",
228
- "when": "$.settings.emailInvoice == true",
229
- "with": {
230
- "id": "$.steps.invoice.Id"
231
- },
232
- "onError": "continue"
233
- }
234
- ],
235
- "retry": {
236
- "max": 5,
237
- "backoff": "exponential"
238
- }
239
- },
240
- {
241
- "id": "invoice-paid",
242
- "label": "Mark jobs paid when QuickBooks records a payment",
243
- "purpose": "write",
244
- "default": "on",
245
- "trigger": {
246
- "type": "webhook",
247
- "module": "quickbooks",
248
- "topic": "payment.created"
249
- },
250
- "steps": [
251
- {
252
- "id": "payment",
253
- "use": "quickbooks.payment.get",
254
- "with": {
255
- "id": "$.record.id"
256
- }
257
- },
258
- {
259
- "id": "apply",
260
- "use": "foreach",
261
- "with": {
262
- "over": "$.steps.payment.Line",
263
- "max": 20
264
- },
265
- "do": [
266
- {
267
- "id": "jobs",
268
- "use": "acmeerp.job.search",
269
- "when": "$.item.LinkedTxn[0].TxnType == 'Invoice'",
270
- "with": {
271
- "external_invoice_id": "$.item.LinkedTxn[0].TxnId"
272
- }
273
- },
274
- {
275
- "use": "acmeerp.job.markPaid",
276
- "when": "$.steps.jobs[0] exists",
277
- "with": {
278
- "id": "$.steps.jobs[0].id",
279
- "amount": "{{item.Amount | to_cents}}",
280
- "paid_at": "$.steps.payment.TxnDate",
281
- "method": "quickbooks",
282
- "reference": "QBO payment {{steps.payment.Id}}"
283
- }
284
- }
285
- ]
286
- }
287
- ]
288
- },
289
- {
290
- "id": "invoice-note",
291
- "label": "Note the invoice on the job",
292
- "purpose": "write",
293
- "default": "off",
294
- "trigger": {
295
- "type": "syncRecord",
296
- "sync": "customers",
297
- "on": [
298
- "linked"
299
- ]
300
- },
301
- "steps": [
302
- {
303
- "id": "open",
304
- "use": "acmeerp.job.search",
305
- "with": {
306
- "customer_id": "$.record.id"
307
- }
308
- },
309
- {
310
- "id": "notes",
311
- "use": "foreach",
312
- "with": {
313
- "over": "$.steps.open",
314
- "max": 25
315
- },
316
- "do": [
317
- {
318
- "use": "acmeerp.job.addNote",
319
- "when": "$.item.status == 'finished'",
320
- "with": {
321
- "jobId": "$.item.id",
322
- "body": "Customer is now linked to QuickBooks; finished jobs will be invoiced automatically."
323
- }
324
- }
325
- ]
326
- }
327
- ]
328
- }
329
- ],
330
- "queries": [
331
- {
332
- "id": "job-invoice-status",
333
- "description": "The QuickBooks invoice for this job.",
334
- "steps": [
335
- {
336
- "use": "stop",
337
- "when": "$.record.external_invoice_id == null",
338
- "with": {
339
- "reason": "Not invoiced"
340
- }
341
- },
342
- {
343
- "id": "invoice",
344
- "use": "quickbooks.invoice.get",
345
- "with": {
346
- "id": "$.record.external_invoice_id"
347
- }
348
- }
349
- ],
350
- "returns": {
351
- "invoice": "$.steps.invoice",
352
- "realmId": "$.install.accounts.quickbooks.realmId"
353
- }
354
- }
355
- ],
356
- "ui": [
357
- {
358
- "id": "invoice-panel",
359
- "label": "QuickBooks invoice",
360
- "host": "acmeerp",
361
- "placement": "job.sidebar",
362
- "objects": [
363
- "job"
364
- ],
365
- "data": {
366
- "query": "job-invoice-status"
367
- },
368
- "view": {
369
- "component": "Stack",
370
- "children": [
371
- {
372
- "component": "Heading",
373
- "props": {
374
- "text": "QuickBooks"
375
- }
376
- },
377
- {
378
- "component": "Empty",
379
- "when": "!($.data.invoice exists)",
380
- "props": {
381
- "text": "Invoiced automatically when the job is finished."
382
- }
383
- },
384
- {
385
- "component": "KeyValue",
386
- "when": "$.data.invoice exists",
387
- "props": {
388
- "items": [
389
- {
390
- "label": "Invoice",
391
- "value": "{{data.invoice.DocNumber}}"
392
- },
393
- {
394
- "label": "Total",
395
- "value": "${{data.invoice.TotalAmt}}"
396
- },
397
- {
398
- "label": "Balance",
399
- "value": "${{data.invoice.Balance}}"
400
- },
401
- {
402
- "label": "Due",
403
- "value": "{{data.invoice.DueDate | date}}"
404
- }
405
- ]
406
- }
407
- },
408
- {
409
- "component": "Badge",
410
- "when": "$.data.invoice.Balance == 0",
411
- "props": {
412
- "text": "Paid",
413
- "tone": "success"
414
- }
415
- },
416
- {
417
- "component": "Badge",
418
- "when": "$.data.invoice.Balance > 0",
419
- "props": {
420
- "text": "Open",
421
- "tone": "warning"
422
- }
423
- },
424
- {
425
- "component": "Button",
426
- "when": "$.data.invoice exists",
427
- "props": {
428
- "label": "Open in QuickBooks",
429
- "action": {
430
- "type": "open_url",
431
- "url": "https://app.qbo.intuit.com/app/invoice?txnId={{data.invoice.Id}}"
432
- }
433
- }
434
- }
435
- ]
436
- }
437
- }
438
- ],
439
- "templates": {
440
- "invoice-memo": "Thanks for choosing Acme! Job #{{record.job_number}}: {{record.description | truncate: 200}}"
441
- },
442
- "lifecycle": {
443
- "onInstall": [
444
- {
445
- "id": "hook",
446
- "use": "acmeerp.webhook.create",
447
- "with": {
448
- "url": "$.install.webhookUrls.acmeerp",
449
- "events": [
450
- "job.finished",
451
- "job.scheduled",
452
- "customer.created",
453
- "customer.updated"
454
- ]
455
- }
456
- }
457
- ],
458
- "onUninstall": [
459
- {
460
- "use": "acmeerp.webhook.delete",
461
- "with": {
462
- "id": "$.install.runtime.installed.hook.id"
463
- }
464
- }
465
- ]
466
- }
467
- }