create-mercato-app 0.6.6-develop.6409.1.4bfed821c0 → 0.6.6-develop.6410.1.2ad881013e
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/dist/agentic/guides/module-facts.json +9 -9
- package/dist/agentic/guides/modules/auth.md +1 -1
- package/dist/agentic/guides/modules/catalog.md +1 -1
- package/dist/agentic/guides/modules/currencies.md +1 -1
- package/dist/agentic/guides/modules/customer_accounts.md +1 -1
- package/dist/agentic/guides/modules/customers.md +1 -1
- package/dist/agentic/guides/modules/data_sync.md +1 -1
- package/dist/agentic/guides/modules/integrations.md +1 -1
- package/dist/agentic/guides/modules/sales.md +1 -1
- package/dist/agentic/guides/modules/workflows.md +1 -1
- package/package.json +3 -3
- package/template/src/modules/example/lib/__tests__/mock-webhook-endpoint-adapter.test.ts +157 -0
- package/template/src/modules/example/lib/mock-webhook-endpoint-adapter.ts +68 -2
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"auth": {
|
|
3
3
|
"title": "Authentication & Accounts",
|
|
4
4
|
"description": "User accounts, sessions, roles and password resets.",
|
|
5
|
-
"coreVersion": "0.6.6-develop.
|
|
5
|
+
"coreVersion": "0.6.6-develop.6410.1.2ad881013e",
|
|
6
6
|
"entities": [
|
|
7
7
|
{
|
|
8
8
|
"id": "auth:user",
|
|
@@ -191,7 +191,7 @@
|
|
|
191
191
|
"catalog": {
|
|
192
192
|
"title": "Product Catalog",
|
|
193
193
|
"description": "Configurable catalog for products, variants, and pricing used by the sales module.",
|
|
194
|
-
"coreVersion": "0.6.6-develop.
|
|
194
|
+
"coreVersion": "0.6.6-develop.6410.1.2ad881013e",
|
|
195
195
|
"entities": [
|
|
196
196
|
{
|
|
197
197
|
"id": "catalog:catalog_option_schema_template",
|
|
@@ -405,7 +405,7 @@
|
|
|
405
405
|
"currencies": {
|
|
406
406
|
"title": "Currencies",
|
|
407
407
|
"description": "Currencies and Exchange rate management",
|
|
408
|
-
"coreVersion": "0.6.6-develop.
|
|
408
|
+
"coreVersion": "0.6.6-develop.6410.1.2ad881013e",
|
|
409
409
|
"entities": [
|
|
410
410
|
{
|
|
411
411
|
"id": "currencies:currency",
|
|
@@ -489,7 +489,7 @@
|
|
|
489
489
|
"customer_accounts": {
|
|
490
490
|
"title": "Customer Identity & Portal Authentication",
|
|
491
491
|
"description": "Customer-facing authentication with two-tier identity model and full RBAC.",
|
|
492
|
-
"coreVersion": "0.6.6-develop.
|
|
492
|
+
"coreVersion": "0.6.6-develop.6410.1.2ad881013e",
|
|
493
493
|
"entities": [
|
|
494
494
|
{
|
|
495
495
|
"id": "customer_accounts:customer_user",
|
|
@@ -729,7 +729,7 @@
|
|
|
729
729
|
"customers": {
|
|
730
730
|
"title": "Customer Relationship Management",
|
|
731
731
|
"description": "Core CRM capabilities for people, companies, deals, and activities.",
|
|
732
|
-
"coreVersion": "0.6.6-develop.
|
|
732
|
+
"coreVersion": "0.6.6-develop.6410.1.2ad881013e",
|
|
733
733
|
"entities": [
|
|
734
734
|
{
|
|
735
735
|
"id": "customers:customer_entity",
|
|
@@ -1211,7 +1211,7 @@
|
|
|
1211
1211
|
"data_sync": {
|
|
1212
1212
|
"title": "Data Sync",
|
|
1213
1213
|
"description": "Streaming data sync hub for import/export integrations.",
|
|
1214
|
-
"coreVersion": "0.6.6-develop.
|
|
1214
|
+
"coreVersion": "0.6.6-develop.6410.1.2ad881013e",
|
|
1215
1215
|
"entities": [
|
|
1216
1216
|
{
|
|
1217
1217
|
"id": "data_sync:sync_run",
|
|
@@ -1289,7 +1289,7 @@
|
|
|
1289
1289
|
"integrations": {
|
|
1290
1290
|
"title": "Integrations",
|
|
1291
1291
|
"description": "Core integration framework — external ID mapping, status badges, and integration registry.",
|
|
1292
|
-
"coreVersion": "0.6.6-develop.
|
|
1292
|
+
"coreVersion": "0.6.6-develop.6410.1.2ad881013e",
|
|
1293
1293
|
"entities": [
|
|
1294
1294
|
{
|
|
1295
1295
|
"id": "integrations:sync_external_id_mapping",
|
|
@@ -1365,7 +1365,7 @@
|
|
|
1365
1365
|
"sales": {
|
|
1366
1366
|
"title": "Sales Management",
|
|
1367
1367
|
"description": "Quoting, ordering, fulfillment, and billing capabilities built on modular pricing and tax pipelines.",
|
|
1368
|
-
"coreVersion": "0.6.6-develop.
|
|
1368
|
+
"coreVersion": "0.6.6-develop.6410.1.2ad881013e",
|
|
1369
1369
|
"entities": [
|
|
1370
1370
|
{
|
|
1371
1371
|
"id": "sales:sales_channel",
|
|
@@ -1839,7 +1839,7 @@
|
|
|
1839
1839
|
"workflows": {
|
|
1840
1840
|
"title": "Workflow Engine",
|
|
1841
1841
|
"description": "Orchestrate business processes with state machines, transitions, and activities",
|
|
1842
|
-
"coreVersion": "0.6.6-develop.
|
|
1842
|
+
"coreVersion": "0.6.6-develop.6410.1.2ad881013e",
|
|
1843
1843
|
"entities": [
|
|
1844
1844
|
{
|
|
1845
1845
|
"id": "workflows:workflow_definition",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# customer_accounts — module facts (generated, do not edit)
|
|
2
|
-
<!-- generated from @open-mercato/core 0.6.6-develop.
|
|
2
|
+
<!-- generated from @open-mercato/core 0.6.6-develop.6410.1.2ad881013e — R1 staleness stamp -->
|
|
3
3
|
|
|
4
4
|
## Entities
|
|
5
5
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-mercato-app",
|
|
3
|
-
"version": "0.6.6-develop.
|
|
3
|
+
"version": "0.6.6-develop.6410.1.2ad881013e",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Create a new Open Mercato application",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"ts-morph": "^28.0.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@open-mercato/cli": "0.6.6-develop.
|
|
26
|
-
"@open-mercato/shared": "0.6.6-develop.
|
|
25
|
+
"@open-mercato/cli": "0.6.6-develop.6410.1.2ad881013e",
|
|
26
|
+
"@open-mercato/shared": "0.6.6-develop.6410.1.2ad881013e",
|
|
27
27
|
"@types/node": "^26.0.0",
|
|
28
28
|
"esbuild": "^0.28.1",
|
|
29
29
|
"tsx": "^4.22.4",
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { createHmac } from 'node:crypto'
|
|
2
|
+
import {
|
|
3
|
+
MOCK_INBOUND_DEV_WEBHOOK_SECRET,
|
|
4
|
+
MOCK_INBOUND_SIGNATURE_HEADER,
|
|
5
|
+
MOCK_INBOUND_TOKEN_HEADER,
|
|
6
|
+
computeMockInboundWebhookSignature,
|
|
7
|
+
mockWebhookEndpointAdapter,
|
|
8
|
+
} from '../mock-webhook-endpoint-adapter'
|
|
9
|
+
|
|
10
|
+
const ORIGINAL_SECRET_ENV = process.env.MOCK_INBOUND_WEBHOOK_SECRET
|
|
11
|
+
const ORIGINAL_NODE_ENV = process.env.NODE_ENV
|
|
12
|
+
|
|
13
|
+
function resetEnv() {
|
|
14
|
+
if (ORIGINAL_SECRET_ENV === undefined) delete process.env.MOCK_INBOUND_WEBHOOK_SECRET
|
|
15
|
+
else process.env.MOCK_INBOUND_WEBHOOK_SECRET = ORIGINAL_SECRET_ENV
|
|
16
|
+
if (ORIGINAL_NODE_ENV === undefined) delete process.env.NODE_ENV
|
|
17
|
+
else process.env.NODE_ENV = ORIGINAL_NODE_ENV
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
describe('mockWebhookEndpointAdapter.verifyWebhook', () => {
|
|
21
|
+
afterEach(() => {
|
|
22
|
+
resetEnv()
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
it('throws when the signature header is missing', async () => {
|
|
26
|
+
const body = JSON.stringify({ type: 'mock.inbound.received', data: {} })
|
|
27
|
+
await expect(
|
|
28
|
+
mockWebhookEndpointAdapter.verifyWebhook({
|
|
29
|
+
headers: {},
|
|
30
|
+
body,
|
|
31
|
+
method: 'POST',
|
|
32
|
+
}),
|
|
33
|
+
).rejects.toThrow(/Missing .* header/)
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
it('rejects the legacy hardcoded literal signature', async () => {
|
|
37
|
+
const body = JSON.stringify({ type: 'mock.inbound.received', data: {} })
|
|
38
|
+
await expect(
|
|
39
|
+
mockWebhookEndpointAdapter.verifyWebhook({
|
|
40
|
+
headers: { [MOCK_INBOUND_SIGNATURE_HEADER]: 'valid' },
|
|
41
|
+
body,
|
|
42
|
+
method: 'POST',
|
|
43
|
+
}),
|
|
44
|
+
).rejects.toThrow(/Invalid mock webhook signature/)
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
it('throws when the signature does not match the dev secret', async () => {
|
|
48
|
+
const body = JSON.stringify({ type: 'mock.inbound.received', data: { id: 'evt_1' } })
|
|
49
|
+
const bogus = createHmac('sha256', 'wrong-secret').update(body, 'utf-8').digest('hex')
|
|
50
|
+
await expect(
|
|
51
|
+
mockWebhookEndpointAdapter.verifyWebhook({
|
|
52
|
+
headers: { [MOCK_INBOUND_SIGNATURE_HEADER]: bogus },
|
|
53
|
+
body,
|
|
54
|
+
method: 'POST',
|
|
55
|
+
}),
|
|
56
|
+
).rejects.toThrow(/Invalid mock webhook signature/)
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
it('rejects signatures that were valid for a different body (tamper detection)', async () => {
|
|
60
|
+
const originalBody = JSON.stringify({ type: 'mock.inbound.received', data: { id: 'good' } })
|
|
61
|
+
const tamperedBody = JSON.stringify({ type: 'mock.inbound.received', data: { id: 'evil' } })
|
|
62
|
+
const goodSignature = computeMockInboundWebhookSignature(originalBody, MOCK_INBOUND_DEV_WEBHOOK_SECRET)
|
|
63
|
+
await expect(
|
|
64
|
+
mockWebhookEndpointAdapter.verifyWebhook({
|
|
65
|
+
headers: { [MOCK_INBOUND_SIGNATURE_HEADER]: goodSignature },
|
|
66
|
+
body: tamperedBody,
|
|
67
|
+
method: 'POST',
|
|
68
|
+
}),
|
|
69
|
+
).rejects.toThrow(/Invalid mock webhook signature/)
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
it('accepts a payload signed with the dev fallback secret', async () => {
|
|
73
|
+
const body = JSON.stringify({ type: 'order.created', data: { id: 'order_1' } })
|
|
74
|
+
const signature = computeMockInboundWebhookSignature(body, MOCK_INBOUND_DEV_WEBHOOK_SECRET)
|
|
75
|
+
const event = await mockWebhookEndpointAdapter.verifyWebhook({
|
|
76
|
+
headers: { [MOCK_INBOUND_SIGNATURE_HEADER]: signature },
|
|
77
|
+
body,
|
|
78
|
+
method: 'POST',
|
|
79
|
+
})
|
|
80
|
+
expect(event.eventType).toBe('order.created')
|
|
81
|
+
expect(event.payload).toMatchObject({ data: { id: 'order_1' } })
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
it('falls back to mock.inbound.received when the body omits a type', async () => {
|
|
85
|
+
const body = JSON.stringify({ data: { id: 'order_2' } })
|
|
86
|
+
const signature = computeMockInboundWebhookSignature(body, MOCK_INBOUND_DEV_WEBHOOK_SECRET)
|
|
87
|
+
const event = await mockWebhookEndpointAdapter.verifyWebhook({
|
|
88
|
+
headers: { [MOCK_INBOUND_SIGNATURE_HEADER]: signature },
|
|
89
|
+
body,
|
|
90
|
+
method: 'POST',
|
|
91
|
+
})
|
|
92
|
+
expect(event.eventType).toBe('mock.inbound.received')
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
it('verifies signatures computed with MOCK_INBOUND_WEBHOOK_SECRET', async () => {
|
|
96
|
+
process.env.MOCK_INBOUND_WEBHOOK_SECRET = 'env-only-secret'
|
|
97
|
+
const body = JSON.stringify({ type: 'mock.inbound.received', data: {} })
|
|
98
|
+
const signature = computeMockInboundWebhookSignature(body, 'env-only-secret')
|
|
99
|
+
await expect(
|
|
100
|
+
mockWebhookEndpointAdapter.verifyWebhook({
|
|
101
|
+
headers: { [MOCK_INBOUND_SIGNATURE_HEADER]: signature },
|
|
102
|
+
body,
|
|
103
|
+
method: 'POST',
|
|
104
|
+
}),
|
|
105
|
+
).resolves.toMatchObject({ eventType: 'mock.inbound.received' })
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
it('accepts a request authenticated with the static token header', async () => {
|
|
109
|
+
const body = JSON.stringify({ type: 'mock.inbound.received', data: { externalId: 'ext-token' } })
|
|
110
|
+
await expect(
|
|
111
|
+
mockWebhookEndpointAdapter.verifyWebhook({
|
|
112
|
+
headers: { [MOCK_INBOUND_TOKEN_HEADER]: MOCK_INBOUND_DEV_WEBHOOK_SECRET },
|
|
113
|
+
body,
|
|
114
|
+
method: 'POST',
|
|
115
|
+
}),
|
|
116
|
+
).resolves.toMatchObject({ eventType: 'mock.inbound.received' })
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
it('rejects a static token that does not equal the secret', async () => {
|
|
120
|
+
const body = JSON.stringify({ type: 'mock.inbound.received', data: {} })
|
|
121
|
+
await expect(
|
|
122
|
+
mockWebhookEndpointAdapter.verifyWebhook({
|
|
123
|
+
headers: { [MOCK_INBOUND_TOKEN_HEADER]: 'valid' },
|
|
124
|
+
body,
|
|
125
|
+
method: 'POST',
|
|
126
|
+
}),
|
|
127
|
+
).rejects.toThrow(/Invalid mock webhook token/)
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
it('verifies the signature, not the token, when both headers are present', async () => {
|
|
131
|
+
const body = JSON.stringify({ type: 'mock.inbound.received', data: {} })
|
|
132
|
+
await expect(
|
|
133
|
+
mockWebhookEndpointAdapter.verifyWebhook({
|
|
134
|
+
headers: {
|
|
135
|
+
[MOCK_INBOUND_SIGNATURE_HEADER]: 'valid',
|
|
136
|
+
[MOCK_INBOUND_TOKEN_HEADER]: MOCK_INBOUND_DEV_WEBHOOK_SECRET,
|
|
137
|
+
},
|
|
138
|
+
body,
|
|
139
|
+
method: 'POST',
|
|
140
|
+
}),
|
|
141
|
+
).rejects.toThrow(/Invalid mock webhook signature/)
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
it('refuses to fall back to the dev secret in production', async () => {
|
|
145
|
+
process.env.NODE_ENV = 'production'
|
|
146
|
+
delete process.env.MOCK_INBOUND_WEBHOOK_SECRET
|
|
147
|
+
const body = JSON.stringify({ type: 'mock.inbound.received', data: {} })
|
|
148
|
+
const signature = computeMockInboundWebhookSignature(body, MOCK_INBOUND_DEV_WEBHOOK_SECRET)
|
|
149
|
+
await expect(
|
|
150
|
+
mockWebhookEndpointAdapter.verifyWebhook({
|
|
151
|
+
headers: { [MOCK_INBOUND_SIGNATURE_HEADER]: signature },
|
|
152
|
+
body,
|
|
153
|
+
method: 'POST',
|
|
154
|
+
}),
|
|
155
|
+
).rejects.toThrow(/Mock inbound webhook secret is not configured/)
|
|
156
|
+
})
|
|
157
|
+
})
|
|
@@ -1,5 +1,26 @@
|
|
|
1
|
+
import { createHmac, timingSafeEqual } from 'node:crypto'
|
|
1
2
|
import type { WebhookEndpointAdapter } from '@open-mercato/webhooks/modules/webhooks/lib/adapter-registry'
|
|
2
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Deterministic dev-only secret used when `MOCK_INBOUND_WEBHOOK_SECRET` is not set.
|
|
6
|
+
* Exported so integration tests can sign mock inbound webhook payloads. MUST NOT be
|
|
7
|
+
* used in production: the mock adapter refuses to fall back to this constant when
|
|
8
|
+
* `NODE_ENV === 'production'`.
|
|
9
|
+
*/
|
|
10
|
+
export const MOCK_INBOUND_DEV_WEBHOOK_SECRET = 'open-mercato-mock-dev-inbound-webhook-secret'
|
|
11
|
+
|
|
12
|
+
export const MOCK_INBOUND_SIGNATURE_HEADER = 'x-mock-webhook-signature'
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Static-token alternative to the HMAC signature, for senders that can only attach
|
|
16
|
+
* fixed headers (e.g. the outbound webhook delivery worker, whose per-delivery body
|
|
17
|
+
* is generated server-side and cannot be pre-signed). The header value must equal the
|
|
18
|
+
* resolved webhook secret (timing-safe compare), so authentication still requires
|
|
19
|
+
* knowledge of the shared secret. Prefer the HMAC signature whenever the sender can
|
|
20
|
+
* compute it — the token does not bind the request body.
|
|
21
|
+
*/
|
|
22
|
+
export const MOCK_INBOUND_TOKEN_HEADER = 'x-mock-webhook-token'
|
|
23
|
+
|
|
3
24
|
function parseJsonBody(body: string): Record<string, unknown> {
|
|
4
25
|
const parsed = JSON.parse(body) as unknown
|
|
5
26
|
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
@@ -8,12 +29,57 @@ function parseJsonBody(body: string): Record<string, unknown> {
|
|
|
8
29
|
return parsed as Record<string, unknown>
|
|
9
30
|
}
|
|
10
31
|
|
|
32
|
+
function resolveMockInboundWebhookSecret(): string {
|
|
33
|
+
const fromEnv = (process.env.MOCK_INBOUND_WEBHOOK_SECRET ?? '').trim()
|
|
34
|
+
if (fromEnv) return fromEnv
|
|
35
|
+
|
|
36
|
+
if (process.env.NODE_ENV === 'production') {
|
|
37
|
+
throw new Error(
|
|
38
|
+
'Mock inbound webhook secret is not configured. Set MOCK_INBOUND_WEBHOOK_SECRET.',
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return MOCK_INBOUND_DEV_WEBHOOK_SECRET
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function computeMockInboundWebhookSignature(rawBody: string, secret: string): string {
|
|
46
|
+
return createHmac('sha256', secret).update(rawBody, 'utf-8').digest('hex')
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function readHeader(headers: Record<string, string>, name: string): string {
|
|
50
|
+
const direct = headers[name]
|
|
51
|
+
?? headers[name.toUpperCase()]
|
|
52
|
+
?? headers[name.replace(/-/g, '_')]
|
|
53
|
+
return typeof direct === 'string' ? direct : ''
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function timingSafeEqualStrings(provided: string, expected: string): boolean {
|
|
57
|
+
const providedBuffer = Buffer.from(provided, 'utf-8')
|
|
58
|
+
const expectedBuffer = Buffer.from(expected, 'utf-8')
|
|
59
|
+
return providedBuffer.length === expectedBuffer.length
|
|
60
|
+
&& timingSafeEqual(providedBuffer, expectedBuffer)
|
|
61
|
+
}
|
|
62
|
+
|
|
11
63
|
export const mockWebhookEndpointAdapter: WebhookEndpointAdapter = {
|
|
12
64
|
providerKey: 'mock_inbound',
|
|
13
65
|
subscribedEvents: ['*'],
|
|
14
66
|
async verifyWebhook(input) {
|
|
15
|
-
|
|
16
|
-
|
|
67
|
+
const providedSignature = readHeader(input.headers, MOCK_INBOUND_SIGNATURE_HEADER)
|
|
68
|
+
const providedToken = readHeader(input.headers, MOCK_INBOUND_TOKEN_HEADER)
|
|
69
|
+
if (!providedSignature && !providedToken) {
|
|
70
|
+
throw new Error(
|
|
71
|
+
`Missing ${MOCK_INBOUND_SIGNATURE_HEADER} or ${MOCK_INBOUND_TOKEN_HEADER} header`,
|
|
72
|
+
)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const secret = resolveMockInboundWebhookSecret()
|
|
76
|
+
if (providedSignature) {
|
|
77
|
+
const expectedSignature = computeMockInboundWebhookSignature(input.body, secret)
|
|
78
|
+
if (!timingSafeEqualStrings(providedSignature, expectedSignature)) {
|
|
79
|
+
throw new Error('Invalid mock webhook signature')
|
|
80
|
+
}
|
|
81
|
+
} else if (!timingSafeEqualStrings(providedToken, secret)) {
|
|
82
|
+
throw new Error('Invalid mock webhook token')
|
|
17
83
|
}
|
|
18
84
|
|
|
19
85
|
const payload = parseJsonBody(input.body)
|