@teleporthq/teleport-plugin-next-workflows 0.43.46 → 0.43.47
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.
- package/__tests__/auth-env-secret-preservation.test.ts +35 -0
- package/__tests__/auth-nextauth-url.test.ts +28 -0
- package/__tests__/auth-session-cost.test.ts +614 -0
- package/__tests__/custom-js-params-env-invariance.test.ts +134 -0
- package/__tests__/data-node-not-awaited.test.ts +644 -0
- package/__tests__/element-trigger-static-attr-replace.test.ts +99 -0
- package/__tests__/element-visible-trigger-scoping.test.ts +296 -0
- package/__tests__/payment-charge-user-handler-serialization.test.ts +7 -5
- package/__tests__/payment-redirect-and-order-notification.test.ts +6 -4
- package/__tests__/raw-sql-param-binding.test.ts +82 -0
- package/__tests__/reserved-word-state-binding.test.ts +112 -0
- package/__tests__/strip-event-handler-attrs.test.ts +59 -0
- package/__tests__/workflow-auth-guard.test.ts +277 -0
- package/dist/cjs/api-route-generator.d.ts +3 -3
- package/dist/cjs/api-route-generator.d.ts.map +1 -1
- package/dist/cjs/api-route-generator.js +136 -11
- package/dist/cjs/api-route-generator.js.map +1 -1
- package/dist/cjs/auth-generator.d.ts +67 -1
- package/dist/cjs/auth-generator.d.ts.map +1 -1
- package/dist/cjs/auth-generator.js +458 -20
- package/dist/cjs/auth-generator.js.map +1 -1
- package/dist/cjs/await-result.d.ts +31 -0
- package/dist/cjs/await-result.d.ts.map +1 -0
- package/dist/cjs/await-result.js +50 -0
- package/dist/cjs/await-result.js.map +1 -0
- package/dist/cjs/executor-generator.d.ts.map +1 -1
- package/dist/cjs/executor-generator.js +150 -1
- package/dist/cjs/executor-generator.js.map +1 -1
- package/dist/cjs/nodes/account/account-get-current.d.ts.map +1 -1
- package/dist/cjs/nodes/account/account-get-current.js +44 -11
- package/dist/cjs/nodes/account/account-get-current.js.map +1 -1
- package/dist/cjs/nodes/account/account-login.d.ts.map +1 -1
- package/dist/cjs/nodes/account/account-login.js +10 -1
- package/dist/cjs/nodes/account/account-login.js.map +1 -1
- package/dist/cjs/raw-sql-param-binding.d.ts.map +1 -1
- package/dist/cjs/raw-sql-param-binding.js +32 -0
- package/dist/cjs/raw-sql-param-binding.js.map +1 -1
- package/dist/cjs/segment-splitter.d.ts.map +1 -1
- package/dist/cjs/segment-splitter.js +15 -7
- package/dist/cjs/segment-splitter.js.map +1 -1
- package/dist/cjs/tsconfig.tsbuildinfo +1 -1
- package/dist/cjs/workflow-auth-generator.d.ts +26 -0
- package/dist/cjs/workflow-auth-generator.d.ts.map +1 -0
- package/dist/cjs/workflow-auth-generator.js +166 -0
- package/dist/cjs/workflow-auth-generator.js.map +1 -0
- package/dist/cjs/workflow-component-plugin.d.ts.map +1 -1
- package/dist/cjs/workflow-component-plugin.js +107 -16
- package/dist/cjs/workflow-component-plugin.js.map +1 -1
- package/dist/cjs/workflow-project-plugin.d.ts +2 -1
- package/dist/cjs/workflow-project-plugin.d.ts.map +1 -1
- package/dist/cjs/workflow-project-plugin.js +170 -20
- package/dist/cjs/workflow-project-plugin.js.map +1 -1
- package/dist/esm/api-route-generator.d.ts +3 -3
- package/dist/esm/api-route-generator.d.ts.map +1 -1
- package/dist/esm/api-route-generator.js +136 -11
- package/dist/esm/api-route-generator.js.map +1 -1
- package/dist/esm/auth-generator.d.ts +67 -1
- package/dist/esm/auth-generator.d.ts.map +1 -1
- package/dist/esm/auth-generator.js +453 -19
- package/dist/esm/auth-generator.js.map +1 -1
- package/dist/esm/await-result.d.ts +31 -0
- package/dist/esm/await-result.d.ts.map +1 -0
- package/dist/esm/await-result.js +45 -0
- package/dist/esm/await-result.js.map +1 -0
- package/dist/esm/executor-generator.d.ts.map +1 -1
- package/dist/esm/executor-generator.js +150 -1
- package/dist/esm/executor-generator.js.map +1 -1
- package/dist/esm/nodes/account/account-get-current.d.ts.map +1 -1
- package/dist/esm/nodes/account/account-get-current.js +44 -11
- package/dist/esm/nodes/account/account-get-current.js.map +1 -1
- package/dist/esm/nodes/account/account-login.d.ts.map +1 -1
- package/dist/esm/nodes/account/account-login.js +10 -1
- package/dist/esm/nodes/account/account-login.js.map +1 -1
- package/dist/esm/raw-sql-param-binding.d.ts.map +1 -1
- package/dist/esm/raw-sql-param-binding.js +32 -0
- package/dist/esm/raw-sql-param-binding.js.map +1 -1
- package/dist/esm/segment-splitter.d.ts.map +1 -1
- package/dist/esm/segment-splitter.js +15 -7
- package/dist/esm/segment-splitter.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/workflow-auth-generator.d.ts +26 -0
- package/dist/esm/workflow-auth-generator.d.ts.map +1 -0
- package/dist/esm/workflow-auth-generator.js +161 -0
- package/dist/esm/workflow-auth-generator.js.map +1 -0
- package/dist/esm/workflow-component-plugin.d.ts.map +1 -1
- package/dist/esm/workflow-component-plugin.js +108 -17
- package/dist/esm/workflow-component-plugin.js.map +1 -1
- package/dist/esm/workflow-project-plugin.d.ts +2 -1
- package/dist/esm/workflow-project-plugin.d.ts.map +1 -1
- package/dist/esm/workflow-project-plugin.js +169 -20
- package/dist/esm/workflow-project-plugin.js.map +1 -1
- package/package.json +4 -4
- package/src/api-route-generator.ts +139 -11
- package/src/auth-generator.ts +471 -19
- package/src/await-result.ts +52 -0
- package/src/executor-generator.ts +150 -1
- package/src/nodes/account/account-get-current.ts +44 -9
- package/src/nodes/account/account-login.ts +12 -1
- package/src/raw-sql-param-binding.ts +33 -0
- package/src/segment-splitter.ts +15 -7
- package/src/workflow-auth-generator.ts +187 -0
- package/src/workflow-component-plugin.ts +129 -20
- package/src/workflow-project-plugin.ts +186 -19
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { loadHandler, HandlerFn } from './_helpers/load-handler'
|
|
2
|
+
|
|
3
|
+
// Moving a top-level `general-custom-js` between `context: 'server'` and
|
|
4
|
+
// `context: 'client'` MUST NOT shift its positional `params[N]` indices.
|
|
5
|
+
//
|
|
6
|
+
// This is what makes the e-commerce placement sweep safe: checkout's
|
|
7
|
+
// "Assemble Order Data" reads params[2]/[5]/[6]/[7]/[9]/[10] and
|
|
8
|
+
// "Build Order Number" reads params[14] — hard-coded positions into the live
|
|
9
|
+
// context. If the environment switch renumbered them the workflow would write
|
|
10
|
+
// the wrong columns on a real order.
|
|
11
|
+
//
|
|
12
|
+
// Two mechanisms could renumber them, and both are pinned here:
|
|
13
|
+
// 1. The SERVER executor injects `__nodeId` into the resolved config, which
|
|
14
|
+
// makes the handler EXCLUDE the executing node from `params`; the client
|
|
15
|
+
// executor does not. That only matters if the executing node ALREADY has a
|
|
16
|
+
// context entry — never true at top level, only inside a loop body (which
|
|
17
|
+
// is filtered out of `params` anyway).
|
|
18
|
+
// 2. Context key ORDER. Keys are inserted as nodes complete, i.e. in graph
|
|
19
|
+
// order — the same order regardless of which side each node ran on.
|
|
20
|
+
|
|
21
|
+
describe('general-custom-js — params are identical on client and server', () => {
|
|
22
|
+
const handler: HandlerFn = loadHandler('general-custom-js')
|
|
23
|
+
|
|
24
|
+
// Echoes back whatever positional slots the caller asks about.
|
|
25
|
+
const PROBE = [
|
|
26
|
+
'function customHandler(params) {',
|
|
27
|
+
' return { seen: params.map(function (p) { return p && p.tag ? p.tag : null; }) };',
|
|
28
|
+
'}',
|
|
29
|
+
].join('\n')
|
|
30
|
+
|
|
31
|
+
const context = () => ({
|
|
32
|
+
trigger: { tag: 'trigger' },
|
|
33
|
+
formNode: { tag: 'form' },
|
|
34
|
+
cartTotal: { tag: 'cart' },
|
|
35
|
+
createOrder: { tag: 'order' },
|
|
36
|
+
// Reserved scaffolding — must never occupy a positional slot.
|
|
37
|
+
__stateValues: { x: 1 },
|
|
38
|
+
__baseUrl: 'https://example.com',
|
|
39
|
+
__skippedNodes: {},
|
|
40
|
+
triggerElement: { nodeType: 1 },
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
it('injecting __nodeId (the server marker) does not change the params array', async () => {
|
|
44
|
+
const asClient = (await handler({ code: PROBE }, context())) as { seen: string[] }
|
|
45
|
+
const asServer = (await handler({ code: PROBE, __nodeId: 'thisNode' }, context())) as {
|
|
46
|
+
seen: string[]
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
expect(asClient.seen).toEqual(['trigger', 'form', 'cart', 'order'])
|
|
50
|
+
expect(asServer.seen).toEqual(asClient.seen)
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it('reserved __ keys and triggerElement never consume a positional slot', async () => {
|
|
54
|
+
const result = (await handler({ code: PROBE }, context())) as { seen: string[] }
|
|
55
|
+
expect(result.seen).toHaveLength(4)
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
it('a hard-coded index resolves to the same node either way', async () => {
|
|
59
|
+
const READ_INDEX_3 = [
|
|
60
|
+
'function customHandler(params) {',
|
|
61
|
+
' return { picked: params[3] && params[3].tag };',
|
|
62
|
+
'}',
|
|
63
|
+
].join('\n')
|
|
64
|
+
|
|
65
|
+
const asClient = await handler({ code: READ_INDEX_3 }, context())
|
|
66
|
+
const asServer = await handler({ code: READ_INDEX_3, __nodeId: 'thisNode' }, context())
|
|
67
|
+
expect(asClient).toEqual({ picked: 'order' })
|
|
68
|
+
expect(asServer).toEqual({ picked: 'order' })
|
|
69
|
+
})
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
describe('context key ORDER survives a client→server→client round trip', () => {
|
|
73
|
+
// The runtime inserts a key when a node completes, so the order tracks the
|
|
74
|
+
// GRAPH, not the execution environment. A server segment rebuilds its context
|
|
75
|
+
// from the serialized client context and appends its own nodes; merging the
|
|
76
|
+
// response back preserves existing positions. This simulates that round trip
|
|
77
|
+
// with the real merge helper and asserts the ordering is env-independent.
|
|
78
|
+
// `mergeServerResults` lives in the client runtime, which needs a DOM to load.
|
|
79
|
+
// Its rule for plain values is a straight assign in the response's key order —
|
|
80
|
+
// reproduced here so the ordering claim can be tested in isolation.
|
|
81
|
+
const mergeServerResults = (
|
|
82
|
+
context: Record<string, unknown>,
|
|
83
|
+
results: Record<string, unknown>
|
|
84
|
+
) => {
|
|
85
|
+
for (const key of Object.keys(results)) {
|
|
86
|
+
context[key] = results[key]
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const runSplit = (envOf: (id: string) => 'client' | 'server') => {
|
|
91
|
+
const graphOrder = ['a', 'b', 'c', 'd', 'e']
|
|
92
|
+
let context: Record<string, unknown> = {}
|
|
93
|
+
let i = 0
|
|
94
|
+
while (i < graphOrder.length) {
|
|
95
|
+
const env = envOf(graphOrder[i])
|
|
96
|
+
const run: string[] = []
|
|
97
|
+
while (i < graphOrder.length && envOf(graphOrder[i]) === env) {
|
|
98
|
+
run.push(graphOrder[i])
|
|
99
|
+
i++
|
|
100
|
+
}
|
|
101
|
+
if (env === 'client') {
|
|
102
|
+
for (const id of run) {
|
|
103
|
+
context[id] = { tag: id }
|
|
104
|
+
}
|
|
105
|
+
} else {
|
|
106
|
+
// Server segment: the pruned client context crosses the wire, the route
|
|
107
|
+
// appends its own nodes, and the whole context comes back.
|
|
108
|
+
const serverContext: Record<string, unknown> = JSON.parse(JSON.stringify(context))
|
|
109
|
+
for (const id of run) {
|
|
110
|
+
serverContext[id] = { tag: id }
|
|
111
|
+
}
|
|
112
|
+
mergeServerResults(context, serverContext)
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
context = { ...context }
|
|
116
|
+
return Object.keys(context)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
it('is the same whether c runs on the client or the server', () => {
|
|
120
|
+
const cOnServer = runSplit((id) => (id === 'b' || id === 'c' ? 'server' : 'client'))
|
|
121
|
+
const cOnClient = runSplit((id) => (id === 'b' ? 'server' : 'client'))
|
|
122
|
+
expect(cOnServer).toEqual(['a', 'b', 'c', 'd', 'e'])
|
|
123
|
+
expect(cOnClient).toEqual(cOnServer)
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
it('is the same when a whole run moves to the client', () => {
|
|
127
|
+
const allServerMiddle = runSplit((id) =>
|
|
128
|
+
id === 'b' || id === 'c' || id === 'd' ? 'server' : 'client'
|
|
129
|
+
)
|
|
130
|
+
const allClient = runSplit(() => 'client')
|
|
131
|
+
expect(allServerMiddle).toEqual(['a', 'b', 'c', 'd', 'e'])
|
|
132
|
+
expect(allClient).toEqual(allServerMiddle)
|
|
133
|
+
})
|
|
134
|
+
})
|