@open-mercato/webhooks 0.10.1-develop.8196.1.f76558d655 → 0.10.1-develop.8209.1.811137ebc0
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.
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { createIntegrationStateService } from "@open-mercato/core/modules/integrations/lib/state-service";
|
|
2
|
-
import {
|
|
2
|
+
import { getEntityIds } from "@open-mercato/shared/lib/encryption/entityIds";
|
|
3
|
+
import { integration, webhookCustomIntegrationId } from "../integration.js";
|
|
3
4
|
const WEBHOOK_INTEGRATION_DISABLED_MESSAGE = "Custom Webhooks integration is disabled";
|
|
5
|
+
function isIntegrationsModuleEnabled() {
|
|
6
|
+
return Boolean(getEntityIds(false).integrations?.integration_state);
|
|
7
|
+
}
|
|
4
8
|
async function isWebhookIntegrationEnabled(em, scope) {
|
|
9
|
+
if (!isIntegrationsModuleEnabled()) return integration.defaultState?.isEnabled ?? true;
|
|
5
10
|
const stateService = createIntegrationStateService(em);
|
|
6
11
|
return stateService.isEnabled(webhookCustomIntegrationId, scope);
|
|
7
12
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/modules/webhooks/lib/integration-state.ts"],
|
|
4
|
-
"sourcesContent": ["import type { EntityManager } from '@mikro-orm/postgresql'\nimport { createIntegrationStateService } from '@open-mercato/core/modules/integrations/lib/state-service'\nimport type { IntegrationScope } from '@open-mercato/shared/modules/integrations/types'\nimport { webhookCustomIntegrationId } from '../integration'\n\nexport const WEBHOOK_INTEGRATION_DISABLED_MESSAGE = 'Custom Webhooks integration is disabled'\n\nexport async function isWebhookIntegrationEnabled(\n em: EntityManager,\n scope: IntegrationScope,\n): Promise<boolean> {\n const stateService = createIntegrationStateService(em)\n return stateService.isEnabled(webhookCustomIntegrationId, scope)\n}\n"],
|
|
5
|
-
"mappings": "AACA,SAAS,qCAAqC;
|
|
4
|
+
"sourcesContent": ["import type { EntityManager } from '@mikro-orm/postgresql'\nimport { createIntegrationStateService } from '@open-mercato/core/modules/integrations/lib/state-service'\nimport { getEntityIds } from '@open-mercato/shared/lib/encryption/entityIds'\nimport type { IntegrationScope } from '@open-mercato/shared/modules/integrations/types'\nimport { integration, webhookCustomIntegrationId } from '../integration'\n\nexport const WEBHOOK_INTEGRATION_DISABLED_MESSAGE = 'Custom Webhooks integration is disabled'\n\n/**\n * `integrations` is an optional peer of `webhooks`: when it is disabled the\n * `IntegrationState` entity is not registered with the ORM, so the marketplace\n * on/off switch cannot be read and the definition default applies instead.\n */\nfunction isIntegrationsModuleEnabled(): boolean {\n return Boolean(getEntityIds(false).integrations?.integration_state)\n}\n\nexport async function isWebhookIntegrationEnabled(\n em: EntityManager,\n scope: IntegrationScope,\n): Promise<boolean> {\n if (!isIntegrationsModuleEnabled()) return integration.defaultState?.isEnabled ?? true\n const stateService = createIntegrationStateService(em)\n return stateService.isEnabled(webhookCustomIntegrationId, scope)\n}\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,qCAAqC;AAC9C,SAAS,oBAAoB;AAE7B,SAAS,aAAa,kCAAkC;AAEjD,MAAM,uCAAuC;AAOpD,SAAS,8BAAuC;AAC9C,SAAO,QAAQ,aAAa,KAAK,EAAE,cAAc,iBAAiB;AACpE;AAEA,eAAsB,4BACpB,IACA,OACkB;AAClB,MAAI,CAAC,4BAA4B,EAAG,QAAO,YAAY,cAAc,aAAa;AAClF,QAAM,eAAe,8BAA8B,EAAE;AACrD,SAAO,aAAa,UAAU,4BAA4B,KAAK;AACjE;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-mercato/webhooks",
|
|
3
|
-
"version": "0.10.1-develop.
|
|
3
|
+
"version": "0.10.1-develop.8209.1.811137ebc0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Webhooks module for Open Mercato — Standard Webhooks compliant outbound/inbound delivery",
|
|
6
6
|
"type": "module",
|
|
@@ -71,29 +71,29 @@
|
|
|
71
71
|
}
|
|
72
72
|
},
|
|
73
73
|
"dependencies": {
|
|
74
|
-
"@open-mercato/cache": "0.10.1-develop.
|
|
75
|
-
"@open-mercato/core": "0.10.1-develop.
|
|
76
|
-
"@open-mercato/queue": "0.10.1-develop.
|
|
77
|
-
"@open-mercato/ui": "0.10.1-develop.
|
|
74
|
+
"@open-mercato/cache": "0.10.1-develop.8209.1.811137ebc0",
|
|
75
|
+
"@open-mercato/core": "0.10.1-develop.8209.1.811137ebc0",
|
|
76
|
+
"@open-mercato/queue": "0.10.1-develop.8209.1.811137ebc0",
|
|
77
|
+
"@open-mercato/ui": "0.10.1-develop.8209.1.811137ebc0",
|
|
78
78
|
"svix": "^1.99.1"
|
|
79
79
|
},
|
|
80
80
|
"peerDependencies": {
|
|
81
81
|
"@mikro-orm/postgresql": "^7.0.14",
|
|
82
|
-
"@open-mercato/ai-assistant": "0.10.1-develop.
|
|
83
|
-
"@open-mercato/shared": "0.10.1-develop.
|
|
82
|
+
"@open-mercato/ai-assistant": "0.10.1-develop.8209.1.811137ebc0",
|
|
83
|
+
"@open-mercato/shared": "0.10.1-develop.8209.1.811137ebc0",
|
|
84
84
|
"react": "^19.0.0",
|
|
85
85
|
"react-dom": "^19.0.0",
|
|
86
86
|
"react-is": ">=18.0.0"
|
|
87
87
|
},
|
|
88
88
|
"devDependencies": {
|
|
89
|
-
"@open-mercato/ai-assistant": "0.10.1-develop.
|
|
90
|
-
"@open-mercato/shared": "0.10.1-develop.
|
|
89
|
+
"@open-mercato/ai-assistant": "0.10.1-develop.8209.1.811137ebc0",
|
|
90
|
+
"@open-mercato/shared": "0.10.1-develop.8209.1.811137ebc0",
|
|
91
91
|
"@types/jest": "^30.0.0",
|
|
92
92
|
"@types/react": "^19.2.18",
|
|
93
93
|
"@types/react-dom": "^19.2.5",
|
|
94
94
|
"cross-env": "^10.1.0",
|
|
95
95
|
"esbuild": "^0.28.2",
|
|
96
|
-
"glob": "^14.0.
|
|
96
|
+
"glob": "^14.0.6",
|
|
97
97
|
"jest": "^30.4.2",
|
|
98
98
|
"react": "19.2.8",
|
|
99
99
|
"react-dom": "19.2.8",
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
const mockIsEnabled = jest.fn()
|
|
2
|
+
const mockCreateIntegrationStateService = jest.fn((_em: unknown) => ({ isEnabled: mockIsEnabled }))
|
|
3
|
+
|
|
4
|
+
jest.mock('@open-mercato/core/modules/integrations/lib/state-service', () => ({
|
|
5
|
+
createIntegrationStateService: (em: unknown) => mockCreateIntegrationStateService(em),
|
|
6
|
+
}))
|
|
7
|
+
|
|
8
|
+
import type { EntityManager } from '@mikro-orm/postgresql'
|
|
9
|
+
import { getEntityIds, registerEntityIds, type EntityIds } from '@open-mercato/shared/lib/encryption/entityIds'
|
|
10
|
+
import { isWebhookIntegrationEnabled } from '../integration-state'
|
|
11
|
+
import { webhookCustomIntegrationId } from '../../integration'
|
|
12
|
+
|
|
13
|
+
const scope = { tenantId: 'tenant-1', organizationId: 'org-1' }
|
|
14
|
+
|
|
15
|
+
function createUntouchableEm(): EntityManager {
|
|
16
|
+
return new Proxy({}, {
|
|
17
|
+
get: (_target, property) => {
|
|
18
|
+
throw new Error(`[internal] em.${String(property)} must not be used`)
|
|
19
|
+
},
|
|
20
|
+
}) as EntityManager
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
describe('isWebhookIntegrationEnabled', () => {
|
|
24
|
+
let previousEntityIds: EntityIds | null = null
|
|
25
|
+
|
|
26
|
+
beforeEach(() => {
|
|
27
|
+
previousEntityIds = getEntityIds(false)
|
|
28
|
+
mockIsEnabled.mockReset()
|
|
29
|
+
mockCreateIntegrationStateService.mockClear()
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
afterEach(() => {
|
|
33
|
+
registerEntityIds(previousEntityIds ?? ({} as EntityIds))
|
|
34
|
+
previousEntityIds = null
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
it('returns the definition default without touching em when the integrations module is disabled', async () => {
|
|
38
|
+
registerEntityIds({ webhooks: { webhook_entity: 'webhooks:webhook_entity' } })
|
|
39
|
+
|
|
40
|
+
await expect(isWebhookIntegrationEnabled(createUntouchableEm(), scope)).resolves.toBe(true)
|
|
41
|
+
expect(mockCreateIntegrationStateService).not.toHaveBeenCalled()
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
it('delegates to the integration state service when the integrations module is enabled', async () => {
|
|
45
|
+
registerEntityIds({ integrations: { integration_state: 'integrations:integration_state' } })
|
|
46
|
+
mockIsEnabled.mockResolvedValue(true)
|
|
47
|
+
const em = {} as EntityManager
|
|
48
|
+
|
|
49
|
+
await expect(isWebhookIntegrationEnabled(em, scope)).resolves.toBe(true)
|
|
50
|
+
expect(mockCreateIntegrationStateService).toHaveBeenCalledWith(em)
|
|
51
|
+
expect(mockIsEnabled).toHaveBeenCalledWith(webhookCustomIntegrationId, scope)
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
it('returns false when the integrations module is enabled and the webhook integration is disabled', async () => {
|
|
55
|
+
registerEntityIds({ integrations: { integration_state: 'integrations:integration_state' } })
|
|
56
|
+
mockIsEnabled.mockResolvedValue(false)
|
|
57
|
+
|
|
58
|
+
await expect(isWebhookIntegrationEnabled({} as EntityManager, scope)).resolves.toBe(false)
|
|
59
|
+
expect(mockIsEnabled).toHaveBeenCalledTimes(1)
|
|
60
|
+
})
|
|
61
|
+
})
|
|
@@ -1,14 +1,25 @@
|
|
|
1
1
|
import type { EntityManager } from '@mikro-orm/postgresql'
|
|
2
2
|
import { createIntegrationStateService } from '@open-mercato/core/modules/integrations/lib/state-service'
|
|
3
|
+
import { getEntityIds } from '@open-mercato/shared/lib/encryption/entityIds'
|
|
3
4
|
import type { IntegrationScope } from '@open-mercato/shared/modules/integrations/types'
|
|
4
|
-
import { webhookCustomIntegrationId } from '../integration'
|
|
5
|
+
import { integration, webhookCustomIntegrationId } from '../integration'
|
|
5
6
|
|
|
6
7
|
export const WEBHOOK_INTEGRATION_DISABLED_MESSAGE = 'Custom Webhooks integration is disabled'
|
|
7
8
|
|
|
9
|
+
/**
|
|
10
|
+
* `integrations` is an optional peer of `webhooks`: when it is disabled the
|
|
11
|
+
* `IntegrationState` entity is not registered with the ORM, so the marketplace
|
|
12
|
+
* on/off switch cannot be read and the definition default applies instead.
|
|
13
|
+
*/
|
|
14
|
+
function isIntegrationsModuleEnabled(): boolean {
|
|
15
|
+
return Boolean(getEntityIds(false).integrations?.integration_state)
|
|
16
|
+
}
|
|
17
|
+
|
|
8
18
|
export async function isWebhookIntegrationEnabled(
|
|
9
19
|
em: EntityManager,
|
|
10
20
|
scope: IntegrationScope,
|
|
11
21
|
): Promise<boolean> {
|
|
22
|
+
if (!isIntegrationsModuleEnabled()) return integration.defaultState?.isEnabled ?? true
|
|
12
23
|
const stateService = createIntegrationStateService(em)
|
|
13
24
|
return stateService.isEnabled(webhookCustomIntegrationId, scope)
|
|
14
25
|
}
|