@contember/engine-actions 2.2.0-alpha.15 → 2.2.0-alpha.17
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/CLAUDE.md +18 -2
- package/dist/development/index.cjs +1 -1
- package/dist/development/index.cjs.map +1 -1
- package/dist/development/index.js +1 -1
- package/dist/development/index.js.map +1 -1
- package/dist/development/src/dispatch/EventDispatcher.cjs +30 -2
- package/dist/development/src/dispatch/EventDispatcher.cjs.map +1 -1
- package/dist/development/src/dispatch/EventDispatcher.js +30 -2
- package/dist/development/src/dispatch/EventDispatcher.js.map +1 -1
- package/dist/development/src/dispatch/EventsRepository.cjs +38 -2
- package/dist/development/src/dispatch/EventsRepository.cjs.map +1 -1
- package/dist/development/src/dispatch/EventsRepository.js +38 -2
- package/dist/development/src/dispatch/EventsRepository.js.map +1 -1
- package/dist/development/src/dispatch/WebhookTargetHandler.cjs +45 -22
- package/dist/development/src/dispatch/WebhookTargetHandler.cjs.map +1 -1
- package/dist/development/src/dispatch/WebhookTargetHandler.js +45 -22
- package/dist/development/src/dispatch/WebhookTargetHandler.js.map +1 -1
- package/dist/development/src/dispatch/redactRequestError.cjs +24 -0
- package/dist/development/src/dispatch/redactRequestError.cjs.map +1 -0
- package/dist/development/src/dispatch/redactRequestError.js +24 -0
- package/dist/development/src/dispatch/redactRequestError.js.map +1 -0
- package/dist/development/src/graphql/resolvers/mutation/SetVariablesMutationResolver.cjs +6 -1
- package/dist/development/src/graphql/resolvers/mutation/SetVariablesMutationResolver.cjs.map +1 -1
- package/dist/development/src/graphql/resolvers/mutation/SetVariablesMutationResolver.js +6 -1
- package/dist/development/src/graphql/resolvers/mutation/SetVariablesMutationResolver.js.map +1 -1
- package/dist/development/src/model/VariablesManager.cjs +5 -0
- package/dist/development/src/model/VariablesManager.cjs.map +1 -1
- package/dist/development/src/model/VariablesManager.js +6 -1
- package/dist/development/src/model/VariablesManager.js.map +1 -1
- package/dist/production/index.cjs +1 -1
- package/dist/production/index.cjs.map +1 -1
- package/dist/production/index.js +1 -1
- package/dist/production/index.js.map +1 -1
- package/dist/production/src/dispatch/EventDispatcher.cjs +30 -2
- package/dist/production/src/dispatch/EventDispatcher.cjs.map +1 -1
- package/dist/production/src/dispatch/EventDispatcher.js +30 -2
- package/dist/production/src/dispatch/EventDispatcher.js.map +1 -1
- package/dist/production/src/dispatch/EventsRepository.cjs +38 -2
- package/dist/production/src/dispatch/EventsRepository.cjs.map +1 -1
- package/dist/production/src/dispatch/EventsRepository.js +38 -2
- package/dist/production/src/dispatch/EventsRepository.js.map +1 -1
- package/dist/production/src/dispatch/WebhookTargetHandler.cjs +45 -22
- package/dist/production/src/dispatch/WebhookTargetHandler.cjs.map +1 -1
- package/dist/production/src/dispatch/WebhookTargetHandler.js +45 -22
- package/dist/production/src/dispatch/WebhookTargetHandler.js.map +1 -1
- package/dist/production/src/dispatch/redactRequestError.cjs +24 -0
- package/dist/production/src/dispatch/redactRequestError.cjs.map +1 -0
- package/dist/production/src/dispatch/redactRequestError.js +24 -0
- package/dist/production/src/dispatch/redactRequestError.js.map +1 -0
- package/dist/production/src/graphql/resolvers/mutation/SetVariablesMutationResolver.cjs +6 -1
- package/dist/production/src/graphql/resolvers/mutation/SetVariablesMutationResolver.cjs.map +1 -1
- package/dist/production/src/graphql/resolvers/mutation/SetVariablesMutationResolver.js +6 -1
- package/dist/production/src/graphql/resolvers/mutation/SetVariablesMutationResolver.js.map +1 -1
- package/dist/production/src/model/VariablesManager.cjs +5 -0
- package/dist/production/src/model/VariablesManager.cjs.map +1 -1
- package/dist/production/src/model/VariablesManager.js +6 -1
- package/dist/production/src/model/VariablesManager.js.map +1 -1
- package/dist/tests/cases/unit/redactRequestError.test.d.ts +2 -0
- package/dist/tests/cases/unit/redactRequestError.test.d.ts.map +1 -0
- package/dist/tests/tsconfig.tsbuildinfo +1 -1
- package/dist/types/dispatch/EventDispatcher.d.ts.map +1 -1
- package/dist/types/dispatch/EventsRepository.d.ts +20 -1
- package/dist/types/dispatch/EventsRepository.d.ts.map +1 -1
- package/dist/types/dispatch/WebhookTargetHandler.d.ts +6 -0
- package/dist/types/dispatch/WebhookTargetHandler.d.ts.map +1 -1
- package/dist/types/dispatch/redactRequestError.d.ts +7 -0
- package/dist/types/dispatch/redactRequestError.d.ts.map +1 -0
- package/dist/types/graphql/resolvers/mutation/SetVariablesMutationResolver.d.ts +3 -1
- package/dist/types/graphql/resolvers/mutation/SetVariablesMutationResolver.d.ts.map +1 -1
- package/dist/types/model/VariablesManager.d.ts +2 -0
- package/dist/types/model/VariablesManager.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +17 -17
- package/src/dispatch/EventDispatcher.ts +32 -3
- package/src/dispatch/EventsRepository.ts +77 -2
- package/src/dispatch/WebhookTargetHandler.ts +58 -27
- package/src/dispatch/redactRequestError.ts +32 -0
- package/src/graphql/resolvers/mutation/SetVariablesMutationResolver.ts +7 -0
- package/src/index.ts +1 -1
- package/src/model/VariablesManager.ts +6 -0
- package/tests/cases/unit/dispatchTracing.test.ts +79 -6
- package/tests/cases/unit/redactRequestError.test.ts +45 -0
- package/tests/cases/unit/webhookHandler.test.ts +104 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, test } from 'bun:test'
|
|
2
|
-
import { WebhookTargetHandler } from '../../../src/dispatch/WebhookTargetHandler.js'
|
|
2
|
+
import { UndefinedVariableError, WebhookTargetHandler } from '../../../src/dispatch/WebhookTargetHandler.js'
|
|
3
3
|
import { FetcherResponse, WebhookFetcher } from '../../../src/dispatch/WebhookFetcher.js'
|
|
4
4
|
import { noopTracer } from '@contember/telemetry'
|
|
5
5
|
import { createLogger, Logger, TestLoggerHandler } from '@contember/logger'
|
|
@@ -140,6 +140,109 @@ describe('webhook request', () => {
|
|
|
140
140
|
assert.equal(fetchCalled, true)
|
|
141
141
|
})
|
|
142
142
|
})
|
|
143
|
+
describe('webhook variables', () => {
|
|
144
|
+
const target: Actions.WebhookTarget = {
|
|
145
|
+
name: 'test_target',
|
|
146
|
+
type: 'webhook',
|
|
147
|
+
url: 'http://{{HOST}}/{{PATH}}',
|
|
148
|
+
headers: { Authorization: 'Bearer {{TOKEN}}', 'X-Path': '{{PATH}}' },
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
test('interpolates variables into the URL and headers', async () => {
|
|
152
|
+
const requests: { url: string; headers: Headers }[] = []
|
|
153
|
+
const webhookHandler = createHandler({
|
|
154
|
+
fetch(url: string, init: RequestInit): Promise<FetcherResponse> {
|
|
155
|
+
requests.push({ url, headers: new Headers(init.headers) })
|
|
156
|
+
return okResponse
|
|
157
|
+
},
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
await webhookHandler.handle({
|
|
161
|
+
logger: createLogger(new TestLoggerHandler()),
|
|
162
|
+
target,
|
|
163
|
+
events: [createTestEvent(0)],
|
|
164
|
+
variables: { HOST: 'example.com', PATH: 'hook', TOKEN: 'secret' },
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
assert.equal(requests.length, 1)
|
|
168
|
+
assert.equal(requests[0].url, 'http://example.com/hook')
|
|
169
|
+
assert.equal(requests[0].headers.get('Authorization'), 'Bearer secret')
|
|
170
|
+
assert.equal(requests[0].headers.get('X-Path'), 'hook')
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
test('throws a typed error naming every undefined variable before any request', async () => {
|
|
174
|
+
const testLoggerHandler = new TestLoggerHandler()
|
|
175
|
+
let fetchCalled = false
|
|
176
|
+
const webhookHandler = createHandler({
|
|
177
|
+
fetch(): Promise<FetcherResponse> {
|
|
178
|
+
fetchCalled = true
|
|
179
|
+
return okResponse
|
|
180
|
+
},
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
const error = await webhookHandler.handle({
|
|
184
|
+
logger: createLogger(testLoggerHandler),
|
|
185
|
+
target: { ...target, url: 'http://{{HOST}}/{{constructor}}/{{PATH}}' },
|
|
186
|
+
events: [createTestEvent(0)],
|
|
187
|
+
// an empty value counts as undefined, and so does a name an object inherits
|
|
188
|
+
variables: { HOST: 'example.com', PATH: '' },
|
|
189
|
+
}).then(() => null, (e: unknown) => e)
|
|
190
|
+
|
|
191
|
+
expect(error).toBeInstanceOf(UndefinedVariableError)
|
|
192
|
+
expect(error instanceof UndefinedVariableError ? error.variables : null).toStrictEqual(['constructor', 'PATH', 'TOKEN'])
|
|
193
|
+
assert.equal(fetchCalled, false)
|
|
194
|
+
// the dispatcher reports it once for the whole target, the handler stays quiet
|
|
195
|
+
assert.deepStrictEqual(testLoggerHandler.messages, [])
|
|
196
|
+
})
|
|
197
|
+
|
|
198
|
+
test('a failed request is logged and stored without the credentials its URL and headers carry', async () => {
|
|
199
|
+
const testLoggerHandler = new TestLoggerHandler()
|
|
200
|
+
const webhookHandler = createHandler({
|
|
201
|
+
async fetch(url: string, init: RequestInit): Promise<FetcherResponse> {
|
|
202
|
+
// messages as Node's fetch words them: the URL quoted raw, an invalid header value quoted trimmed
|
|
203
|
+
const authorization = new Headers(init.headers).get('Authorization')?.trim()
|
|
204
|
+
throw Object.assign(new TypeError(`Request cannot be constructed from a URL that includes credentials: ${url}`), {
|
|
205
|
+
cause: Object.assign(new TypeError(`Headers.append: "${authorization}" is an invalid header value.`), {
|
|
206
|
+
cause: Object.assign(new Error('connect ECONNREFUSED 127.0.0.1:443 after sending token-3 to https://example.com:8443/hooks?key=static-key'), {
|
|
207
|
+
code: 'ECONNREFUSED',
|
|
208
|
+
url,
|
|
209
|
+
}),
|
|
210
|
+
}),
|
|
211
|
+
})
|
|
212
|
+
},
|
|
213
|
+
})
|
|
214
|
+
|
|
215
|
+
const result = await webhookHandler.handle({
|
|
216
|
+
logger: createLogger(testLoggerHandler),
|
|
217
|
+
target: {
|
|
218
|
+
...target,
|
|
219
|
+
url: 'https://deliveries:{{PASSWORD}}@example.com:8443/hooks/{{PATH}}?key=static-key#fragment',
|
|
220
|
+
headers: { Authorization: 'Bearer {{TOKEN}}', 'X-Api-Key': 'static-header-key' },
|
|
221
|
+
},
|
|
222
|
+
events: [createTestEvent(0)],
|
|
223
|
+
// a password with @ and / ends the URL authority early, a value with an edge newline is quoted trimmed
|
|
224
|
+
variables: { PASSWORD: 'p@ss/1', PATH: 'path-2', TOKEN: 'token-3\n' },
|
|
225
|
+
})
|
|
226
|
+
|
|
227
|
+
const reason = 'Request cannot be constructed from a URL that includes credentials: [redacted]; '
|
|
228
|
+
+ 'Headers.append: "[redacted]" is an invalid header value.; '
|
|
229
|
+
+ 'connect ECONNREFUSED 127.0.0.1:443 after sending [redacted] to https://example.com:8443/[redacted]'
|
|
230
|
+
assert.deepStrictEqual(result.map(it => it.result.errorMessage), [reason])
|
|
231
|
+
assert.deepStrictEqual(testLoggerHandler.messages.map(it => [it.level.name, it.message, it.ownAttributes]), [
|
|
232
|
+
['warn', `Webhook request failed: ${reason}`, { target: 'test_target' }],
|
|
233
|
+
])
|
|
234
|
+
const error = testLoggerHandler.messages[0].error
|
|
235
|
+
expect(error).toBeInstanceOf(Error)
|
|
236
|
+
expect(error).toHaveProperty('name', 'TypeError')
|
|
237
|
+
expect(error).toHaveProperty('code', 'ECONNREFUSED')
|
|
238
|
+
expect(error).not.toHaveProperty('cause')
|
|
239
|
+
const logged = JSON.stringify([error, error instanceof Error ? error.stack : null])
|
|
240
|
+
for (const secret of ['deliveries', 'ss/1', 'hooks', 'path-2', 'static-key', 'fragment', 'token-3', 'static-header-key']) {
|
|
241
|
+
expect(logged).not.toContain(secret)
|
|
242
|
+
}
|
|
243
|
+
})
|
|
244
|
+
})
|
|
245
|
+
|
|
143
246
|
describe('webhook response', () => {
|
|
144
247
|
test('successful response', async () => {
|
|
145
248
|
const testLoggerHandler = new TestLoggerHandler()
|