@contractspec/example.openbanking-powens 3.7.6 → 3.7.10
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/.turbo/turbo-build.log +22 -18
- package/AGENTS.md +40 -17
- package/CHANGELOG.md +22 -0
- package/README.md +61 -20
- package/dist/contracts.test.d.ts +1 -0
- package/dist/handlers/oauth-callback.d.ts +6 -0
- package/dist/handlers/webhook-handler.d.ts +6 -0
- package/dist/handlers/webhook-handler.js +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +43 -1
- package/dist/jobs/index.d.ts +1 -0
- package/dist/jobs/index.js +45 -0
- package/dist/jobs/powens-sync-dispatch.job.d.ts +1 -0
- package/dist/jobs/powens-sync-dispatch.job.js +45 -0
- package/dist/node/handlers/webhook-handler.js +1 -1
- package/dist/node/index.js +43 -1
- package/dist/node/jobs/index.js +44 -0
- package/dist/node/jobs/powens-sync-dispatch.job.js +44 -0
- package/package.json +31 -7
- package/src/contracts.test.ts +12 -0
- package/src/docs/openbanking-powens.docblock.ts +21 -21
- package/src/example.ts +26 -26
- package/src/handlers/oauth-callback.ts +79 -78
- package/src/handlers/webhook-handler.ts +101 -100
- package/src/index.ts +2 -1
- package/src/jobs/index.ts +1 -0
- package/src/jobs/powens-sync-dispatch.job.ts +44 -0
- package/src/openbanking-powens.feature.ts +18 -18
- package/tsconfig.json +7 -9
- package/tsdown.config.js +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contractspec/example.openbanking-powens",
|
|
3
|
-
"version": "3.7.
|
|
3
|
+
"version": "3.7.10",
|
|
4
4
|
"description": "OpenBanking Powens example: OAuth callback + webhook handler patterns (provider + workflows).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -41,6 +41,18 @@
|
|
|
41
41
|
"node": "./dist/node/handlers/webhook-handler.js",
|
|
42
42
|
"default": "./dist/handlers/webhook-handler.js"
|
|
43
43
|
},
|
|
44
|
+
"./jobs": {
|
|
45
|
+
"types": "./dist/jobs/index.d.ts",
|
|
46
|
+
"bun": "./dist/jobs/index.js",
|
|
47
|
+
"node": "./dist/node/jobs/index.js",
|
|
48
|
+
"default": "./dist/jobs/index.js"
|
|
49
|
+
},
|
|
50
|
+
"./jobs/powens-sync-dispatch.job": {
|
|
51
|
+
"types": "./dist/jobs/powens-sync-dispatch.job.d.ts",
|
|
52
|
+
"bun": "./dist/jobs/powens-sync-dispatch.job.js",
|
|
53
|
+
"node": "./dist/node/jobs/powens-sync-dispatch.job.js",
|
|
54
|
+
"default": "./dist/jobs/powens-sync-dispatch.job.js"
|
|
55
|
+
},
|
|
44
56
|
"./openbanking-powens.feature": {
|
|
45
57
|
"types": "./dist/openbanking-powens.feature.d.ts",
|
|
46
58
|
"bun": "./dist/openbanking-powens.feature.js",
|
|
@@ -57,20 +69,20 @@
|
|
|
57
69
|
"dev": "contractspec-bun-build dev",
|
|
58
70
|
"clean": "rimraf dist .turbo",
|
|
59
71
|
"lint": "bun lint:fix",
|
|
60
|
-
"lint:fix": "
|
|
61
|
-
"lint:check": "
|
|
72
|
+
"lint:fix": "biome check --write --unsafe --only=nursery/useSortedClasses . && biome check --write .",
|
|
73
|
+
"lint:check": "biome check .",
|
|
62
74
|
"test": "bun test --pass-with-no-tests",
|
|
63
75
|
"prebuild": "contractspec-bun-build prebuild",
|
|
64
76
|
"typecheck": "tsc --noEmit"
|
|
65
77
|
},
|
|
66
78
|
"dependencies": {
|
|
67
|
-
"@contractspec/integration.providers-impls": "3.
|
|
68
|
-
"@contractspec/lib.contracts-spec": "
|
|
79
|
+
"@contractspec/integration.providers-impls": "3.8.2",
|
|
80
|
+
"@contractspec/lib.contracts-spec": "4.1.2"
|
|
69
81
|
},
|
|
70
82
|
"devDependencies": {
|
|
71
|
-
"@contractspec/tool.typescript": "3.7.
|
|
83
|
+
"@contractspec/tool.typescript": "3.7.8",
|
|
72
84
|
"typescript": "^5.9.3",
|
|
73
|
-
"@contractspec/tool.bun": "3.7.
|
|
85
|
+
"@contractspec/tool.bun": "3.7.8"
|
|
74
86
|
},
|
|
75
87
|
"publishConfig": {
|
|
76
88
|
"access": "public",
|
|
@@ -111,6 +123,18 @@
|
|
|
111
123
|
"node": "./dist/node/handlers/webhook-handler.js",
|
|
112
124
|
"default": "./dist/handlers/webhook-handler.js"
|
|
113
125
|
},
|
|
126
|
+
"./jobs": {
|
|
127
|
+
"types": "./dist/jobs/index.d.ts",
|
|
128
|
+
"bun": "./dist/jobs/index.js",
|
|
129
|
+
"node": "./dist/node/jobs/index.js",
|
|
130
|
+
"default": "./dist/jobs/index.js"
|
|
131
|
+
},
|
|
132
|
+
"./jobs/powens-sync-dispatch.job": {
|
|
133
|
+
"types": "./dist/jobs/powens-sync-dispatch.job.d.ts",
|
|
134
|
+
"bun": "./dist/jobs/powens-sync-dispatch.job.js",
|
|
135
|
+
"node": "./dist/node/jobs/powens-sync-dispatch.job.js",
|
|
136
|
+
"default": "./dist/jobs/powens-sync-dispatch.job.js"
|
|
137
|
+
},
|
|
114
138
|
"./openbanking-powens.feature": {
|
|
115
139
|
"types": "./dist/openbanking-powens.feature.d.ts",
|
|
116
140
|
"bun": "./dist/openbanking-powens.feature.js",
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test';
|
|
2
|
+
import { OpenbankingPowensFeature, PowensSyncDispatchJob } from './index';
|
|
3
|
+
|
|
4
|
+
describe('@contractspec/example.openbanking-powens', () => {
|
|
5
|
+
test('exports the canonical job spec', () => {
|
|
6
|
+
expect(PowensSyncDispatchJob.meta.key).toBe(
|
|
7
|
+
'openbanking-powens.job.sync-dispatch'
|
|
8
|
+
);
|
|
9
|
+
expect(PowensSyncDispatchJob.timeoutMs).toBe(60_000);
|
|
10
|
+
expect(OpenbankingPowensFeature.meta.key).toBe('openbanking-powens');
|
|
11
|
+
});
|
|
12
|
+
});
|
|
@@ -2,27 +2,27 @@ import type { DocBlock } from '@contractspec/lib.contracts-spec/docs';
|
|
|
2
2
|
import { registerDocBlocks } from '@contractspec/lib.contracts-spec/docs';
|
|
3
3
|
|
|
4
4
|
const blocks: DocBlock[] = [
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
5
|
+
{
|
|
6
|
+
id: 'docs.examples.openbanking-powens',
|
|
7
|
+
title: 'Open Banking — Powens (example)',
|
|
8
|
+
summary:
|
|
9
|
+
'Framework-neutral OAuth callback + webhook handler patterns for Powens, orchestrating canonical sync workflows.',
|
|
10
|
+
kind: 'reference',
|
|
11
|
+
visibility: 'public',
|
|
12
|
+
route: '/docs/examples/openbanking-powens',
|
|
13
|
+
tags: ['openbanking', 'powens', 'integration', 'example'],
|
|
14
|
+
body: `## What this example shows\n- OAuth callback handler: exchange auth code, map powens user, enqueue sync workflow.\n- Webhook handler: verify signature, route event → workflow, optionally refresh balances.\n\n## Guardrails\n- Secrets via secret providers/env only.\n- Verify webhook signatures.\n- Keep side effects explicit: enqueue workflows instead of mutating canonical stores inline.`,
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
id: 'docs.examples.openbanking-powens.usage',
|
|
18
|
+
title: 'Open Banking — Powens — Usage',
|
|
19
|
+
summary: 'How to integrate the handlers in a fetch-compatible runtime.',
|
|
20
|
+
kind: 'usage',
|
|
21
|
+
visibility: 'public',
|
|
22
|
+
route: '/docs/examples/openbanking-powens/usage',
|
|
23
|
+
tags: ['openbanking', 'usage'],
|
|
24
|
+
body: `## Usage\n- Wire \`powensOAuthCallbackHandler(req)\` at your OAuth redirect route.\n- Wire \`powensWebhookHandler(req)\` at your webhook route.\n\n## Notes\n- Replace the fake stores with your app-layer persistence.\n- Enqueue ContractSpec workflows for canonical upserts and telemetry.`,
|
|
25
|
+
},
|
|
26
26
|
];
|
|
27
27
|
|
|
28
28
|
registerDocBlocks(blocks);
|
package/src/example.ts
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
import { defineExample } from '@contractspec/lib.contracts-spec';
|
|
2
2
|
|
|
3
3
|
const example = defineExample({
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
4
|
+
meta: {
|
|
5
|
+
key: 'openbanking-powens',
|
|
6
|
+
version: '1.0.0',
|
|
7
|
+
title: 'Open Banking — Powens',
|
|
8
|
+
description:
|
|
9
|
+
'OAuth callback + webhook handler patterns for Powens open banking integration (provider + workflow orchestration).',
|
|
10
|
+
kind: 'integration',
|
|
11
|
+
visibility: 'public',
|
|
12
|
+
stability: 'experimental',
|
|
13
|
+
owners: ['@platform.core'],
|
|
14
|
+
tags: ['openbanking', 'powens', 'oauth', 'webhooks', 'integrations'],
|
|
15
|
+
},
|
|
16
|
+
docs: {
|
|
17
|
+
rootDocId: 'docs.examples.openbanking-powens',
|
|
18
|
+
usageDocId: 'docs.examples.openbanking-powens.usage',
|
|
19
|
+
},
|
|
20
|
+
entrypoints: {
|
|
21
|
+
packageName: '@contractspec/example.openbanking-powens',
|
|
22
|
+
docs: './docs',
|
|
23
|
+
},
|
|
24
|
+
surfaces: {
|
|
25
|
+
templates: true,
|
|
26
|
+
sandbox: { enabled: true, modes: ['markdown', 'specs'] },
|
|
27
|
+
studio: { enabled: true, installable: true },
|
|
28
|
+
mcp: { enabled: true },
|
|
29
|
+
},
|
|
30
30
|
});
|
|
31
31
|
|
|
32
32
|
export default example;
|
|
@@ -4,110 +4,111 @@
|
|
|
4
4
|
* This example stays framework-neutral: it operates on the standard `Request`
|
|
5
5
|
* type so it can be used in Next.js, Elysia, or any fetch-compatible runtime.
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
|
|
8
8
|
import type { PowensEnvironment } from '@contractspec/integration.providers-impls/impls/powens-client';
|
|
9
|
+
import { PowensOpenBankingProvider } from '@contractspec/integration.providers-impls/impls/powens-openbanking';
|
|
9
10
|
|
|
10
11
|
export async function powensOAuthCallbackHandler(req: Request) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
12
|
+
const url = new URL(req.url);
|
|
13
|
+
const code = url.searchParams.get('code');
|
|
14
|
+
const state = url.searchParams.get('state');
|
|
15
|
+
const userUuid = url.searchParams.get('user_uuid');
|
|
16
|
+
|
|
17
|
+
if (!code || !state || !userUuid) {
|
|
18
|
+
return new Response('Missing Powens OAuth params', { status: 400 });
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const connection = await getConnectionByState(state);
|
|
22
|
+
if (!connection) {
|
|
23
|
+
return new Response('Unknown Powens OAuth state', { status: 404 });
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const secrets = await getPowensSecretsForConnection(connection.meta.id);
|
|
27
|
+
|
|
28
|
+
const provider = new PowensOpenBankingProvider({
|
|
29
|
+
clientId: secrets.clientId,
|
|
30
|
+
clientSecret: secrets.clientSecret,
|
|
31
|
+
apiKey: secrets.apiKey,
|
|
32
|
+
environment: connection.config.environment as PowensEnvironment,
|
|
33
|
+
baseUrl: connection.config.baseUrl as string | undefined,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const preview = await provider.listAccounts({
|
|
37
|
+
tenantId: connection.meta.tenantId,
|
|
38
|
+
connectionId: connection.meta.id,
|
|
39
|
+
userId: userUuid,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
await connection.storePowensUser({
|
|
43
|
+
tenantUserId: connection.meta.tenantUserId,
|
|
44
|
+
powensUserUuid: userUuid,
|
|
45
|
+
authCode: code,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
await enqueueWorkflow('pfo.workflow.sync-openbanking-accounts', {
|
|
49
|
+
tenantId: connection.meta.tenantId,
|
|
50
|
+
userUuid,
|
|
51
|
+
connectionId: connection.meta.id,
|
|
52
|
+
previewAccounts: preview.accounts,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const redirectBase = process.env.APP_DASHBOARD_URL ?? '';
|
|
56
|
+
return Response.redirect(
|
|
57
|
+
`${redirectBase}/banking/linked?tenant=${connection.meta.tenantId}`,
|
|
58
|
+
302
|
|
59
|
+
);
|
|
59
60
|
}
|
|
60
61
|
|
|
61
62
|
interface ExamplePowensSecrets {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
clientId: string;
|
|
64
|
+
clientSecret: string;
|
|
65
|
+
apiKey?: string;
|
|
65
66
|
}
|
|
66
67
|
|
|
67
68
|
interface ExampleIntegrationConnection {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
69
|
+
meta: {
|
|
70
|
+
id: string;
|
|
71
|
+
tenantId: string;
|
|
72
|
+
tenantUserId: string;
|
|
73
|
+
};
|
|
74
|
+
config: {
|
|
75
|
+
environment: PowensEnvironment;
|
|
76
|
+
baseUrl?: string;
|
|
77
|
+
};
|
|
78
|
+
storePowensUser(input: {
|
|
79
|
+
tenantUserId: string;
|
|
80
|
+
powensUserUuid: string;
|
|
81
|
+
authCode: string;
|
|
82
|
+
}): Promise<void>;
|
|
82
83
|
}
|
|
83
84
|
|
|
84
85
|
async function getConnectionByState(
|
|
85
|
-
|
|
86
|
+
state: string
|
|
86
87
|
): Promise<ExampleIntegrationConnection | null> {
|
|
87
|
-
|
|
88
|
-
|
|
88
|
+
const record = fakeDatabase.connections.find((conn) => conn.state === state);
|
|
89
|
+
return record ?? null;
|
|
89
90
|
}
|
|
90
91
|
|
|
91
92
|
async function getPowensSecretsForConnection(
|
|
92
|
-
|
|
93
|
+
connectionId: string
|
|
93
94
|
): Promise<ExamplePowensSecrets> {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
const secret = fakeSecretStore[connectionId];
|
|
96
|
+
if (!secret) throw new Error(`Missing Powens secrets for ${connectionId}`);
|
|
97
|
+
return secret;
|
|
97
98
|
}
|
|
98
99
|
|
|
99
100
|
async function enqueueWorkflow(name: string, input: Record<string, unknown>) {
|
|
100
|
-
|
|
101
|
+
await fakeWorkflowQueue.enqueue({ name, input });
|
|
101
102
|
}
|
|
102
103
|
|
|
103
104
|
const fakeDatabase = {
|
|
104
|
-
|
|
105
|
+
connections: [] as (ExampleIntegrationConnection & { state: string })[],
|
|
105
106
|
};
|
|
106
107
|
|
|
107
108
|
const fakeSecretStore: Record<string, ExamplePowensSecrets> = {};
|
|
108
109
|
|
|
109
110
|
const fakeWorkflowQueue = {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
111
|
+
enqueue: async (_payload: Record<string, unknown>) => {
|
|
112
|
+
/* no-op */
|
|
113
|
+
},
|
|
113
114
|
};
|
|
@@ -4,144 +4,145 @@
|
|
|
4
4
|
* Verifies signature, then enqueues the canonical workflows to keep the ledger
|
|
5
5
|
* in sync. Unknown events are ignored (or can be recorded by the app layer).
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
|
-
import { PowensOpenBankingProvider } from '@contractspec/integration.providers-impls/impls/powens-openbanking';
|
|
7
|
+
|
|
9
8
|
import type { PowensEnvironment } from '@contractspec/integration.providers-impls/impls/powens-client';
|
|
9
|
+
import { PowensOpenBankingProvider } from '@contractspec/integration.providers-impls/impls/powens-openbanking';
|
|
10
|
+
import { createHmac, timingSafeEqual } from 'crypto';
|
|
10
11
|
|
|
11
12
|
export async function powensWebhookHandler(req: Request) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
13
|
+
const signature = req.headers.get('x-powens-signature');
|
|
14
|
+
const stateHeader = req.headers.get('x-powens-state');
|
|
15
|
+
const payload = await req.text();
|
|
16
|
+
|
|
17
|
+
if (!signature || !stateHeader) {
|
|
18
|
+
return new Response('Missing Powens signature headers', { status: 400 });
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const connection = await getConnectionByState(stateHeader);
|
|
22
|
+
if (!connection) {
|
|
23
|
+
return new Response('Unknown Powens state header', { status: 404 });
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const secrets = await getPowensSecretsForConnection(connection.meta.id);
|
|
27
|
+
if (!verifySignature(payload, signature, secrets.webhookSecret)) {
|
|
28
|
+
return new Response('Invalid Powens webhook signature', { status: 401 });
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const event = JSON.parse(payload) as PowensWebhookEvent;
|
|
32
|
+
const provider = new PowensOpenBankingProvider({
|
|
33
|
+
clientId: secrets.clientId,
|
|
34
|
+
clientSecret: secrets.clientSecret,
|
|
35
|
+
apiKey: secrets.apiKey,
|
|
36
|
+
environment: connection.config.environment as PowensEnvironment,
|
|
37
|
+
baseUrl: connection.config.baseUrl as string | undefined,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
switch (event.type) {
|
|
41
|
+
case 'connection.updated':
|
|
42
|
+
case 'user.sync.completed': {
|
|
43
|
+
await enqueueWorkflow('pfo.workflow.sync-openbanking-accounts', {
|
|
44
|
+
tenantId: connection.meta.tenantId,
|
|
45
|
+
connectionId: connection.meta.id,
|
|
46
|
+
userUuid: event.user_uuid,
|
|
47
|
+
});
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
case 'transactions.created':
|
|
51
|
+
case 'transactions.updated': {
|
|
52
|
+
await enqueueWorkflow('pfo.workflow.sync-openbanking-transactions', {
|
|
53
|
+
tenantId: connection.meta.tenantId,
|
|
54
|
+
connectionId: connection.meta.id,
|
|
55
|
+
userUuid: event.user_uuid,
|
|
56
|
+
accountId: event.account_uuid,
|
|
57
|
+
});
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
default:
|
|
61
|
+
await logUnmappedEvent(event);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (event.account_uuid) {
|
|
65
|
+
await provider.getBalances({
|
|
66
|
+
tenantId: connection.meta.tenantId,
|
|
67
|
+
connectionId: connection.meta.id,
|
|
68
|
+
accountId: event.account_uuid,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return new Response('OK', { status: 200 });
|
|
72
73
|
}
|
|
73
74
|
|
|
74
75
|
interface PowensWebhookEvent {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
type: string;
|
|
77
|
+
user_uuid: string;
|
|
78
|
+
connection_uuid: string;
|
|
79
|
+
account_uuid?: string;
|
|
79
80
|
}
|
|
80
81
|
|
|
81
82
|
interface ExamplePowensSecrets {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
83
|
+
clientId: string;
|
|
84
|
+
clientSecret: string;
|
|
85
|
+
apiKey?: string;
|
|
86
|
+
webhookSecret: string;
|
|
86
87
|
}
|
|
87
88
|
|
|
88
89
|
interface ExampleIntegrationConnection {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
90
|
+
meta: {
|
|
91
|
+
id: string;
|
|
92
|
+
tenantId: string;
|
|
93
|
+
};
|
|
94
|
+
config: {
|
|
95
|
+
environment: PowensEnvironment;
|
|
96
|
+
baseUrl?: string;
|
|
97
|
+
};
|
|
97
98
|
}
|
|
98
99
|
|
|
99
100
|
function verifySignature(payload: string, signature: string, secret: string) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
101
|
+
const digest = createHmac('sha256', secret).update(payload).digest('hex');
|
|
102
|
+
const a = Buffer.from(digest, 'hex');
|
|
103
|
+
const b = Buffer.from(signature, 'hex');
|
|
104
|
+
return a.length === b.length && timingSafeEqual(a, b);
|
|
104
105
|
}
|
|
105
106
|
|
|
106
107
|
async function getConnectionByState(
|
|
107
|
-
|
|
108
|
+
state: string
|
|
108
109
|
): Promise<ExampleIntegrationConnection | null> {
|
|
109
|
-
|
|
110
|
+
return fakeDatabase.connections.find((conn) => conn.state === state) ?? null;
|
|
110
111
|
}
|
|
111
112
|
|
|
112
113
|
async function getPowensSecretsForConnection(
|
|
113
|
-
|
|
114
|
+
connectionId: string
|
|
114
115
|
): Promise<ExamplePowensSecrets> {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
const secret = fakeSecretStore[connectionId];
|
|
117
|
+
if (!secret) throw new Error(`Missing Powens secrets for ${connectionId}`);
|
|
118
|
+
return secret;
|
|
118
119
|
}
|
|
119
120
|
|
|
120
121
|
async function enqueueWorkflow(name: string, input: Record<string, unknown>) {
|
|
121
|
-
|
|
122
|
+
await fakeWorkflowQueue.enqueue({ name, input });
|
|
122
123
|
}
|
|
123
124
|
|
|
124
125
|
async function logUnmappedEvent(_event: PowensWebhookEvent) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
126
|
+
await fakeTelemetryLogger.record({
|
|
127
|
+
event: 'openbanking.webhook.unmapped',
|
|
128
|
+
payload: 'redacted',
|
|
129
|
+
});
|
|
129
130
|
}
|
|
130
131
|
|
|
131
132
|
const fakeDatabase = {
|
|
132
|
-
|
|
133
|
+
connections: [] as (ExampleIntegrationConnection & { state: string })[],
|
|
133
134
|
};
|
|
134
135
|
|
|
135
136
|
const fakeSecretStore: Record<string, ExamplePowensSecrets> = {};
|
|
136
137
|
|
|
137
138
|
const fakeWorkflowQueue = {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
139
|
+
enqueue: async (_payload: Record<string, unknown>) => {
|
|
140
|
+
/* no-op */
|
|
141
|
+
},
|
|
141
142
|
};
|
|
142
143
|
|
|
143
144
|
const fakeTelemetryLogger = {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
145
|
+
record: async (_payload: Record<string, unknown>) => {
|
|
146
|
+
/* no-op */
|
|
147
|
+
},
|
|
147
148
|
};
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
export { default as example } from './example';
|
|
1
2
|
export * from './handlers/oauth-callback';
|
|
2
3
|
export * from './handlers/webhook-handler';
|
|
4
|
+
export * from './jobs';
|
|
3
5
|
export * from './openbanking-powens.feature';
|
|
4
|
-
export { default as example } from './example';
|
|
5
6
|
import './docs';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './powens-sync-dispatch.job';
|