twenty-app-intake 0.2.1 → 0.4.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 (52) hide show
  1. package/README.md +293 -8
  2. package/manifest.json +419 -667
  3. package/package.json +6 -9
  4. package/public/cover.generated.png +0 -0
  5. package/src/front-components/dashboard.mjs +19 -21947
  6. package/src/front-components/dashboard.mjs.map +4 -4
  7. package/src/front-components/dashboard.tsx +118 -0
  8. package/src/front-components/settings-panel.mjs +19 -22103
  9. package/src/front-components/settings-panel.mjs.map +4 -4
  10. package/src/front-components/settings-panel.tsx +304 -0
  11. package/src/front-components/source-panel.mjs +20 -21962
  12. package/src/front-components/source-panel.mjs.map +4 -4
  13. package/src/front-components/source-panel.tsx +113 -0
  14. package/src/logic-functions/check-silence.mjs +263 -0
  15. package/src/logic-functions/check-silence.mjs.map +7 -0
  16. package/src/logic-functions/check-silence.ts +52 -0
  17. package/src/logic-functions/contract.mjs +507 -0
  18. package/src/logic-functions/contract.mjs.map +7 -0
  19. package/src/logic-functions/contract.ts +172 -0
  20. package/src/logic-functions/health.mjs +125 -5
  21. package/src/logic-functions/health.mjs.map +3 -3
  22. package/src/logic-functions/health.ts +62 -0
  23. package/src/logic-functions/quarantine-discard.mjs +380 -0
  24. package/src/logic-functions/quarantine-discard.mjs.map +7 -0
  25. package/src/logic-functions/quarantine-discard.ts +65 -0
  26. package/src/logic-functions/quarantine-list.mjs +211 -0
  27. package/src/logic-functions/quarantine-list.mjs.map +7 -0
  28. package/src/logic-functions/quarantine-list.ts +93 -0
  29. package/src/logic-functions/quarantine-release.mjs +1974 -0
  30. package/src/logic-functions/quarantine-release.mjs.map +7 -0
  31. package/src/logic-functions/quarantine-release.ts +94 -0
  32. package/src/logic-functions/register.mjs +34 -1
  33. package/src/logic-functions/register.mjs.map +2 -2
  34. package/src/logic-functions/register.ts +105 -0
  35. package/src/logic-functions/replay-bulk.mjs +2040 -0
  36. package/src/logic-functions/replay-bulk.mjs.map +7 -0
  37. package/src/logic-functions/replay-bulk.ts +83 -0
  38. package/src/logic-functions/replay-log.mjs +1987 -0
  39. package/src/logic-functions/replay-log.mjs.map +7 -0
  40. package/src/logic-functions/replay-log.ts +54 -0
  41. package/src/logic-functions/retry.mjs +1004 -248
  42. package/src/logic-functions/retry.mjs.map +4 -4
  43. package/src/logic-functions/retry.ts +101 -0
  44. package/src/logic-functions/test-ingest.mjs +616 -28
  45. package/src/logic-functions/test-ingest.mjs.map +4 -4
  46. package/src/logic-functions/test-ingest.ts +179 -0
  47. package/src/logic-functions/webhook.mjs +968 -209
  48. package/src/logic-functions/webhook.mjs.map +4 -4
  49. package/src/logic-functions/webhook.ts +58 -0
  50. package/src/post-install.mjs +34 -1
  51. package/src/post-install.mjs.map +2 -2
  52. package/src/post-install.ts +81 -0
@@ -0,0 +1,101 @@
1
+ import { defineLogicFunction, type RoutePayload } from 'twenty-sdk/define';
2
+ import { IDS } from '../constants/universal-identifiers';
3
+ import { loadLog, slugForSource } from '../lib/replay';
4
+ import { runIngestion, successBody } from '../lib/ingest';
5
+
6
+ /**
7
+ * Re-run a failed ingestion.
8
+ *
9
+ * Deliberately narrower than replay: this refuses a log that already succeeded,
10
+ * so an operator clicking Retry on a working record cannot create a second one.
11
+ * Use `/replay` for a log that succeeded but needs re-mapping.
12
+ */
13
+ const handler = async (params: RoutePayload) => {
14
+ const startedAt = Date.now();
15
+
16
+ const logId = params.pathParameters?.['logId'];
17
+ if (!logId) return { statusCode: 400, body: { error: 'Missing logId in URL' } };
18
+
19
+ const log = await loadLog(logId);
20
+ if (!log) return { statusCode: 404, body: { error: `IntakeLog ${logId} not found` } };
21
+
22
+ if (log.status === 'SUCCESS') {
23
+ return {
24
+ statusCode: 400,
25
+ body: {
26
+ error: 'This ingestion already succeeded — no retry needed. Use POST /s/intake/logs/:logId/replay to re-run it through the current rules.',
27
+ status: log.status,
28
+ },
29
+ };
30
+ }
31
+
32
+ if (log.status === 'QUARANTINED') {
33
+ return {
34
+ statusCode: 400,
35
+ body: {
36
+ error: 'This payload is quarantined. Use POST /s/intake/quarantine/:logId/release to let it through.',
37
+ status: log.status,
38
+ },
39
+ };
40
+ }
41
+
42
+ if (!log.rawPayload) {
43
+ return {
44
+ statusCode: 400,
45
+ body: {
46
+ error: 'No raw payload stored on this log — retry needs one. Check INTAKE_RAW_PAYLOAD_RETENTION and INTAKE_RAW_PAYLOAD_MAX_BYTES.',
47
+ code: 'NO_STORED_PAYLOAD',
48
+ },
49
+ };
50
+ }
51
+
52
+ let rawPayload: Record<string, unknown>;
53
+ try {
54
+ rawPayload = JSON.parse(log.rawPayload) as Record<string, unknown>;
55
+ } catch {
56
+ return { statusCode: 400, body: { error: 'rawPayload is not valid JSON' } };
57
+ }
58
+
59
+ const sourceSlug = await slugForSource(log.intakeSourceId);
60
+ if (!sourceSlug) {
61
+ return { statusCode: 400, body: { error: 'The source for this log no longer exists' } };
62
+ }
63
+
64
+ const outcome = await runIngestion({
65
+ sourceSlug,
66
+ rawPayload,
67
+ // The signature was verified when the payload first arrived and there is no
68
+ // body to re-verify against; the caller here is already authenticated.
69
+ skipDedup: true,
70
+ replayOfLogId: log.id,
71
+ });
72
+
73
+ if (!outcome.ok) {
74
+ return {
75
+ statusCode: 500,
76
+ body: {
77
+ error: `Retry failed: ${outcome.error.message}`,
78
+ code: outcome.error.code,
79
+ originalLogId: logId,
80
+ },
81
+ };
82
+ }
83
+
84
+ return {
85
+ statusCode: 200,
86
+ body: { originalLogId: logId, ...successBody(outcome.ctx, startedAt) },
87
+ };
88
+ };
89
+
90
+ export default defineLogicFunction({
91
+ universalIdentifier: IDS.RETRY_LOGIC_FUNCTION,
92
+ name: 'intake-retry',
93
+ description: 'Retry a failed ingestion using the stored raw payload from an IntakeLog record.',
94
+ timeoutSeconds: 30,
95
+ handler,
96
+ httpRouteTriggerSettings: {
97
+ path: '/intake/logs/:logId/retry',
98
+ httpMethod: 'POST',
99
+ isAuthRequired: true,
100
+ },
101
+ });