@frontera-sdk/functions 1.49.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.
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Everything an author reads when the platform turns their code away.
3
+ *
4
+ * They live in the SDK, not in the runner, because three surfaces have to say
5
+ * exactly the same sentence: the runner refusing a call before it makes it, the
6
+ * service refusing it after, and `createTestContext` refusing it on the author's
7
+ * own machine. Three copies of a message drift, and a test that fails with
8
+ * different words than production is a test that teaches the wrong lesson.
9
+ */
10
+
11
+ /**
12
+ * A `ctx` call the manifest does not permit.
13
+ *
14
+ * Names the fix, not the verdict: the author is looking at CLI output, and
15
+ * "missing grant" without the remedy costs them a round trip through the docs.
16
+ */
17
+ export function missingGrantMessage(grant: string): string {
18
+ return `Automation is missing the "${grant}" grant. Add it to the manifest and redeploy.`
19
+ }
20
+
21
+ /**
22
+ * One step name used twice in a run.
23
+ *
24
+ * The platform memoizes by name, so the second call would return the FIRST
25
+ * step's result — no error, no warning, a wrong value flowing on. The remedy
26
+ * names THIS step rather than a placeholder, because a hint that reads as code
27
+ * to paste gets pasted.
28
+ */
29
+ export function duplicateStepMessage(name: string): string {
30
+ return (
31
+ `Duplicate automation step name "${name}". Step names must be unique within a run — ` +
32
+ "the platform memoizes by name, so this call would return the first step's result " +
33
+ 'instead of running again. If this is a loop, add the index: ' +
34
+ `ctx.step.run(\`${name}:\${i}\`, ...)`
35
+ )
36
+ }
37
+
38
+ /**
39
+ * A submit inside a step whose own row never recorded.
40
+ *
41
+ * Recording a step is contractually non-fatal — telemetry must not fail a run —
42
+ * so the id comes back empty and everything else carries on. A submission
43
+ * cannot: the row is what the idempotency key is derived from, and improvising
44
+ * one is how the same effect happens twice. Named here rather than left to the
45
+ * service's generic invalid-submission, which would blame the payload.
46
+ */
47
+ export function lostStepRowMessage(stepName: string): string {
48
+ return (
49
+ `ctx.action.submit cannot run in step "${stepName}": the step's own record failed to write, ` +
50
+ 'so there is nothing stable to key the submission on and it is refused rather than sent ' +
51
+ 'twice. This is a transient service failure — retry the run.'
52
+ )
53
+ }
54
+
55
+ /**
56
+ * The same Action submitted twice from one step with no way to tell them apart.
57
+ *
58
+ * Refused HERE, locally, rather than left to the write plane, because the plane
59
+ * cannot refuse it: two identical submissions derive one idempotency key AND
60
+ * one semantic fingerprint, so it replays the first request and answers both
61
+ * calls with the same request id. Nothing errors, one effect happens, and the
62
+ * run reports success — the failure mode a batch loop hits on its second row
63
+ * and not on a one-row fixture.
64
+ *
65
+ * Naming the remedy matters more than usual: `submissionKey` is the one field
66
+ * an author has to reach for to fix this, and it is not guessable from a 409.
67
+ */
68
+ export function duplicateSubmissionMessage(apiName: string): string {
69
+ return (
70
+ `Step already submitted "${apiName}" with the same submissionKey. Two submissions the ` +
71
+ 'platform cannot tell apart become ONE request — the plane replays the first and the second ' +
72
+ 'effect never happens. If this is a batch, give each submission a distinct submissionKey ' +
73
+ "keyed on what it acts on: ctx.action.submit({ action: '" + apiName + "', submissionKey: " +
74
+ 'row.id, ... }). If it is a retry, it is already idempotent — drop the loop.'
75
+ )
76
+ }
77
+
78
+ /**
79
+ * An empty `submissionKey`.
80
+ *
81
+ * Refused rather than treated as absent, and refused in both layers: the
82
+ * service rejects it by name, so folding it into the no-key identity here
83
+ * would make the SDK and the service disagree about what the author asked for.
84
+ */
85
+ export function emptySubmissionKeyMessage(apiName: string): string {
86
+ return (
87
+ `ctx.action.submit("${apiName}") was given an empty submissionKey. Omit it entirely to mean ` +
88
+ '"this step submits once", or pass a value identifying what this submission acts on.'
89
+ )
90
+ }
91
+
92
+ /**
93
+ * `ctx.action.submit` called outside a step.
94
+ *
95
+ * States the consequence rather than the rule, because the rule on its own
96
+ * reads as ceremony: code outside a step runs again after EVERY step the
97
+ * handler completes, so a submit there is not one submission with a retry
98
+ * risk — it is one submission per step boundary, every time the run resumes.
99
+ * The step row is also what the idempotency key is derived from, so there is
100
+ * nothing to derive one from out here.
101
+ */
102
+ export function submitOutsideStepMessage(apiName: string): string {
103
+ return (
104
+ `ctx.action.submit("${apiName}") must be called inside ctx.step.run. Code outside a step ` +
105
+ 're-executes every time the run resumes, so this would submit once per step boundary. ' +
106
+ `Wrap it: ctx.step.run('submit-${apiName}', () => ctx.action.submit({ ... }))`
107
+ )
108
+ }