@haneinfo/integration-contracts 0.4.0
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/LICENSE +14 -0
- package/dist/canonical.d.ts +6 -0
- package/dist/canonical.d.ts.map +1 -0
- package/dist/canonical.js +49 -0
- package/dist/canonical.js.map +1 -0
- package/dist/compatibility.d.ts +10 -0
- package/dist/compatibility.d.ts.map +1 -0
- package/dist/compatibility.js +137 -0
- package/dist/compatibility.js.map +1 -0
- package/dist/delivery.d.ts +19 -0
- package/dist/delivery.d.ts.map +1 -0
- package/dist/delivery.js +67 -0
- package/dist/delivery.js.map +1 -0
- package/dist/destination-policy.d.ts +13 -0
- package/dist/destination-policy.d.ts.map +1 -0
- package/dist/destination-policy.js +133 -0
- package/dist/destination-policy.js.map +1 -0
- package/dist/envelope.d.ts +10 -0
- package/dist/envelope.d.ts.map +1 -0
- package/dist/envelope.js +45 -0
- package/dist/envelope.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/manifest.d.ts +9 -0
- package/dist/manifest.d.ts.map +1 -0
- package/dist/manifest.js +36 -0
- package/dist/manifest.js.map +1 -0
- package/dist/schema.d.ts +11 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +362 -0
- package/dist/schema.js.map +1 -0
- package/dist/types.d.ts +184 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +37 -0
- package/dist/types.js.map +1 -0
- package/dist/webhook.d.ts +52 -0
- package/dist/webhook.d.ts.map +1 -0
- package/dist/webhook.js +143 -0
- package/dist/webhook.js.map +1 -0
- package/docs/webhook-v2.md +30 -0
- package/fixtures/consumer-compile.ts +32 -0
- package/fixtures/tsconfig.json +8 -0
- package/package.json +35 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Copyright (c) 2026 Haneinfo. All Rights Reserved.
|
|
2
|
+
|
|
3
|
+
This software and associated documentation files (the "Software") are the proprietary and
|
|
4
|
+
confidential property of Haneinfo. No part of the Software may be copied, modified, merged,
|
|
5
|
+
published, distributed, sublicensed, or sold without the prior written permission of Haneinfo.
|
|
6
|
+
|
|
7
|
+
The Software is provided for internal use by Haneinfo and its authorized personnel only, and is
|
|
8
|
+
NOT licensed for external distribution or open-source use.
|
|
9
|
+
|
|
10
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
|
11
|
+
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
12
|
+
NONINFRINGEMENT. IN NO EVENT SHALL HANEINFO BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
13
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
|
|
14
|
+
THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { JsonValue } from './types';
|
|
2
|
+
export declare function canonicalJson(value: unknown): string;
|
|
3
|
+
export declare function sha256Hex(value: string | Uint8Array): string;
|
|
4
|
+
export declare function sha256Digest(value: unknown): string;
|
|
5
|
+
export declare function canonicalJsonValue(value: unknown): JsonValue;
|
|
6
|
+
//# sourceMappingURL=canonical.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canonical.d.ts","sourceRoot":"","sources":["../src/canonical.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAEpD;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,GAAG,MAAM,CAE5D;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAEnD;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS,CAE5D"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.canonicalJson = canonicalJson;
|
|
4
|
+
exports.sha256Hex = sha256Hex;
|
|
5
|
+
exports.sha256Digest = sha256Digest;
|
|
6
|
+
exports.canonicalJsonValue = canonicalJsonValue;
|
|
7
|
+
const node_crypto_1 = require("node:crypto");
|
|
8
|
+
function canonicalJson(value) {
|
|
9
|
+
return canonicalize(value, '$');
|
|
10
|
+
}
|
|
11
|
+
function sha256Hex(value) {
|
|
12
|
+
return (0, node_crypto_1.createHash)('sha256').update(value).digest('hex');
|
|
13
|
+
}
|
|
14
|
+
function sha256Digest(value) {
|
|
15
|
+
return `sha256:${sha256Hex(canonicalJson(value))}`;
|
|
16
|
+
}
|
|
17
|
+
function canonicalJsonValue(value) {
|
|
18
|
+
return JSON.parse(canonicalJson(value));
|
|
19
|
+
}
|
|
20
|
+
function canonicalize(value, path) {
|
|
21
|
+
if (value === null)
|
|
22
|
+
return 'null';
|
|
23
|
+
if (typeof value === 'string')
|
|
24
|
+
return JSON.stringify(value);
|
|
25
|
+
if (typeof value === 'boolean')
|
|
26
|
+
return value ? 'true' : 'false';
|
|
27
|
+
if (typeof value === 'number') {
|
|
28
|
+
if (!Number.isFinite(value))
|
|
29
|
+
throw new TypeError(`Non-finite number at ${path}`);
|
|
30
|
+
return JSON.stringify(Object.is(value, -0) ? 0 : value);
|
|
31
|
+
}
|
|
32
|
+
if (typeof value === 'bigint')
|
|
33
|
+
throw new TypeError(`BigInt is not JSON data at ${path}`);
|
|
34
|
+
if (typeof value === 'undefined')
|
|
35
|
+
throw new TypeError(`Undefined is not JSON data at ${path}`);
|
|
36
|
+
if (typeof value !== 'object')
|
|
37
|
+
throw new TypeError(`Unsupported JSON value at ${path}`);
|
|
38
|
+
if (Array.isArray(value)) {
|
|
39
|
+
return `[${value.map((item, index) => canonicalize(item, `${path}[${index}]`)).join(',')}]`;
|
|
40
|
+
}
|
|
41
|
+
const prototype = Object.getPrototypeOf(value);
|
|
42
|
+
if (prototype !== Object.prototype && prototype !== null)
|
|
43
|
+
throw new TypeError(`Non-plain object is not JSON data at ${path}`);
|
|
44
|
+
const entries = Object.entries(value).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));
|
|
45
|
+
return `{${entries
|
|
46
|
+
.map(([key, item]) => `${JSON.stringify(key)}:${canonicalize(item, `${path}.${key}`)}`)
|
|
47
|
+
.join(',')}}`;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=canonical.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canonical.js","sourceRoot":"","sources":["../src/canonical.ts"],"names":[],"mappings":";;AAIA,sCAEC;AAED,8BAEC;AAED,oCAEC;AAED,gDAEC;AAlBD,6CAAyC;AAIzC,SAAgB,aAAa,CAAC,KAAc;IAC1C,OAAO,YAAY,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AAClC,CAAC;AAED,SAAgB,SAAS,CAAC,KAA0B;IAClD,OAAO,IAAA,wBAAU,EAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC1D,CAAC;AAED,SAAgB,YAAY,CAAC,KAAc;IACzC,OAAO,UAAU,SAAS,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;AACrD,CAAC;AAED,SAAgB,kBAAkB,CAAC,KAAc;IAC/C,OAAO,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,CAAc,CAAC;AACvD,CAAC;AAED,SAAS,YAAY,CAAC,KAAc,EAAE,IAAY;IAChD,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,MAAM,CAAC;IAClC,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AM,IAAI,SAAS,CAAC,wCAAwC,IAAI,EAAE,CAAC,CAAC;IAEtE,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACvF,OAAO,IAAI,OAAO;SACf,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,YAAY,CAAC,IAAI,EAAE,GAAG,IAAI,IAAI,GAAG,EAAE,CAAC,EAAE,CAAC;SACtF,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { JsonSchema } from './types';
|
|
2
|
+
export type CompatibilityProfile = 'strict' | 'tolerant-reader' | 'provider-compatible';
|
|
3
|
+
export type CompatibilityFinding = {
|
|
4
|
+
path: string;
|
|
5
|
+
rule: string;
|
|
6
|
+
breaking: boolean;
|
|
7
|
+
severity: 'info' | 'warning' | 'error';
|
|
8
|
+
};
|
|
9
|
+
export declare function checkSchemaCompatibility(previous: JsonSchema, next: JsonSchema, profile?: CompatibilityProfile): CompatibilityFinding[];
|
|
10
|
+
//# sourceMappingURL=compatibility.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compatibility.d.ts","sourceRoot":"","sources":["../src/compatibility.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C,MAAM,MAAM,oBAAoB,GAAG,QAAQ,GAAG,iBAAiB,GAAG,qBAAqB,CAAC;AAExF,MAAM,MAAM,oBAAoB,GAAG;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,OAAO,CAAC;IAClB,QAAQ,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC;CACxC,CAAC;AAEF,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,UAAU,EACpB,IAAI,EAAE,UAAU,EAChB,OAAO,GAAE,oBAA4C,GACpD,oBAAoB,EAAE,CAIxB"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checkSchemaCompatibility = checkSchemaCompatibility;
|
|
4
|
+
function checkSchemaCompatibility(previous, next, profile = 'provider-compatible') {
|
|
5
|
+
const findings = [];
|
|
6
|
+
compareSchema(previous, next, '$', profile, findings, new Set());
|
|
7
|
+
return findings;
|
|
8
|
+
}
|
|
9
|
+
function compareSchema(previous, next, path, profile, findings, seen) {
|
|
10
|
+
const pair = `${JSON.stringify(previous)}\n${JSON.stringify(next)}\n${path}`;
|
|
11
|
+
if (seen.has(pair))
|
|
12
|
+
return;
|
|
13
|
+
seen.add(pair);
|
|
14
|
+
if (previous.type && next.type && JSON.stringify(previous.type) !== JSON.stringify(next.type)) {
|
|
15
|
+
findings.push({ path, rule: 'type changed', breaking: true, severity: 'error' });
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (previous.enum && next.enum) {
|
|
19
|
+
for (const value of previous.enum)
|
|
20
|
+
if (!next.enum.some((candidate) => sameJson(candidate, value)))
|
|
21
|
+
findings.push({ path, rule: 'enum value removed', breaking: true, severity: 'error' });
|
|
22
|
+
if (next.enum.some((value) => !previous.enum?.some((candidate) => sameJson(candidate, value))))
|
|
23
|
+
findings.push({
|
|
24
|
+
path,
|
|
25
|
+
rule: 'enum value added',
|
|
26
|
+
breaking: profile === 'strict',
|
|
27
|
+
severity: profile === 'strict' ? 'error' : 'warning',
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
if (previous.pattern !== next.pattern &&
|
|
31
|
+
previous.pattern !== undefined &&
|
|
32
|
+
next.pattern !== undefined)
|
|
33
|
+
findings.push({ path, rule: 'pattern changed', breaking: true, severity: 'error' });
|
|
34
|
+
if (previous.format !== next.format && previous.format !== undefined && next.format !== undefined)
|
|
35
|
+
findings.push({ path, rule: 'format changed', breaking: true, severity: 'error' });
|
|
36
|
+
compareUpperBound(previous.minLength, next.minLength, path, 'minLength increased', findings);
|
|
37
|
+
compareLowerBound(previous.maxLength, next.maxLength, path, 'maxLength decreased', findings);
|
|
38
|
+
compareUpperBound(previous.minimum, next.minimum, path, 'minimum increased', findings);
|
|
39
|
+
compareLowerBound(previous.maximum, next.maximum, path, 'maximum decreased', findings);
|
|
40
|
+
compareUpperBound(previous.minItems, next.minItems, path, 'minItems increased', findings);
|
|
41
|
+
compareLowerBound(previous.maxItems, next.maxItems, path, 'maxItems decreased', findings);
|
|
42
|
+
if (previous.uniqueItems === false && next.uniqueItems === true)
|
|
43
|
+
findings.push({ path, rule: 'uniqueItems became stricter', breaking: true, severity: 'error' });
|
|
44
|
+
const previousProperties = previous.properties ?? {};
|
|
45
|
+
const nextProperties = next.properties ?? {};
|
|
46
|
+
const previousRequired = new Set(previous.required ?? []);
|
|
47
|
+
const nextRequired = new Set(next.required ?? []);
|
|
48
|
+
for (const key of Object.keys(previousProperties)) {
|
|
49
|
+
if (!(key in nextProperties)) {
|
|
50
|
+
const breaking = profile !== 'tolerant-reader' || previousRequired.has(key);
|
|
51
|
+
findings.push({
|
|
52
|
+
path: `${path}.${key}`,
|
|
53
|
+
rule: 'property removed',
|
|
54
|
+
breaking,
|
|
55
|
+
severity: breaking ? 'error' : 'warning',
|
|
56
|
+
});
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
compareSchema(previousProperties[key], nextProperties[key], `${path}.${key}`, profile, findings, seen);
|
|
60
|
+
}
|
|
61
|
+
for (const key of Object.keys(nextProperties)) {
|
|
62
|
+
if (key in previousProperties)
|
|
63
|
+
continue;
|
|
64
|
+
if (!nextRequired.has(key) && profile === 'tolerant-reader')
|
|
65
|
+
continue;
|
|
66
|
+
const required = nextRequired.has(key);
|
|
67
|
+
const breaking = required || profile === 'strict';
|
|
68
|
+
findings.push({
|
|
69
|
+
path: `${path}.${key}`,
|
|
70
|
+
rule: required ? 'required property added' : 'optional property added',
|
|
71
|
+
breaking,
|
|
72
|
+
severity: breaking ? 'error' : 'info',
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
for (const key of previousRequired)
|
|
76
|
+
if (!nextRequired.has(key))
|
|
77
|
+
findings.push({
|
|
78
|
+
path: `${path}.${key}`,
|
|
79
|
+
rule: 'requiredness relaxed',
|
|
80
|
+
breaking: false,
|
|
81
|
+
severity: 'info',
|
|
82
|
+
});
|
|
83
|
+
for (const key of nextRequired)
|
|
84
|
+
if (!previousRequired.has(key) && key in previousProperties)
|
|
85
|
+
findings.push({
|
|
86
|
+
path: `${path}.${key}`,
|
|
87
|
+
rule: 'requiredness tightened',
|
|
88
|
+
breaking: true,
|
|
89
|
+
severity: 'error',
|
|
90
|
+
});
|
|
91
|
+
if (previous.additionalProperties === false && next.additionalProperties !== false)
|
|
92
|
+
findings.push({
|
|
93
|
+
path,
|
|
94
|
+
rule: 'additional properties relaxed',
|
|
95
|
+
breaking: false,
|
|
96
|
+
severity: 'info',
|
|
97
|
+
});
|
|
98
|
+
if (previous.additionalProperties !== false && next.additionalProperties === false)
|
|
99
|
+
findings.push({
|
|
100
|
+
path,
|
|
101
|
+
rule: 'additional properties restricted',
|
|
102
|
+
breaking: profile !== 'tolerant-reader',
|
|
103
|
+
severity: profile === 'tolerant-reader' ? 'warning' : 'error',
|
|
104
|
+
});
|
|
105
|
+
if (previous.items && next.items)
|
|
106
|
+
compareSchema(previous.items, next.items, `${path}[]`, profile, findings, seen);
|
|
107
|
+
for (const keyword of ['allOf', 'anyOf', 'oneOf']) {
|
|
108
|
+
const oldChildren = previous[keyword];
|
|
109
|
+
const newChildren = next[keyword];
|
|
110
|
+
if (oldChildren && newChildren && oldChildren.length === newChildren.length)
|
|
111
|
+
oldChildren.forEach((child, index) => {
|
|
112
|
+
compareSchema(child, newChildren[index], `${path}.${keyword}[${index}]`, profile, findings, seen);
|
|
113
|
+
});
|
|
114
|
+
else if (oldChildren &&
|
|
115
|
+
newChildren &&
|
|
116
|
+
JSON.stringify(oldChildren) !== JSON.stringify(newChildren))
|
|
117
|
+
findings.push({
|
|
118
|
+
path,
|
|
119
|
+
rule: `${keyword} composition changed`,
|
|
120
|
+
breaking: true,
|
|
121
|
+
severity: 'error',
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
function compareUpperBound(previous, next, path, rule, findings) {
|
|
126
|
+
if (next !== undefined && (previous === undefined || next > previous))
|
|
127
|
+
findings.push({ path, rule, breaking: true, severity: 'error' });
|
|
128
|
+
}
|
|
129
|
+
function compareLowerBound(previous, next, path, rule, findings) {
|
|
130
|
+
if (next !== undefined && (previous === undefined || next < previous))
|
|
131
|
+
findings.push({ path, rule, breaking: true, severity: 'error' });
|
|
132
|
+
}
|
|
133
|
+
function sameJson(left, right) {
|
|
134
|
+
return (JSON.stringify(left, Object.keys(left ?? {}).sort()) ===
|
|
135
|
+
JSON.stringify(right, Object.keys(right ?? {}).sort()));
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=compatibility.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compatibility.js","sourceRoot":"","sources":["../src/compatibility.ts"],"names":[],"mappings":";;AAWA,4DAQC;AARD,SAAgB,wBAAwB,CACtC,QAAoB,EACpB,IAAgB,EAChB,UAAgC,qBAAqB;IAErD,MAAM,QAAQ,GAA2B,EAAE,CAAC;IAC5C,aAAa,CAAC,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,QAAQ,EAA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AM,CAAC,IAAI,CAAE,IAAe,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QAChE,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC,IAAI,CAAE,KAAgB,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CACnE,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { DeliveryOutcome } from './types';
|
|
2
|
+
export declare class DomainEventTerminalError extends Error {
|
|
3
|
+
readonly status?: number;
|
|
4
|
+
constructor(message: string, status?: number);
|
|
5
|
+
}
|
|
6
|
+
export declare class DomainEventRetryableError extends Error {
|
|
7
|
+
readonly retryAfterMs?: number;
|
|
8
|
+
readonly status?: number;
|
|
9
|
+
constructor(message: string, options?: {
|
|
10
|
+
retryAfterMs?: number;
|
|
11
|
+
status?: number;
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
export declare class DomainEventIgnoredError extends Error {
|
|
15
|
+
constructor(message: string);
|
|
16
|
+
}
|
|
17
|
+
export declare function classifyHttpOutcome(status: number, headers?: Record<string, string | undefined>, body?: unknown, expectedEventId?: string): DeliveryOutcome;
|
|
18
|
+
export declare function boundedRetryAfter(value: string | undefined, maxMs?: number, nowMs?: number): number | undefined;
|
|
19
|
+
//# sourceMappingURL=delivery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delivery.d.ts","sourceRoot":"","sources":["../src/delivery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C,qBAAa,wBAAyB,SAAQ,KAAK;IACjD,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;gBACb,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;CAK7C;AAED,qBAAa,yBAA0B,SAAQ,KAAK;IAClD,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;gBACb,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE;QAAE,YAAY,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAO;CAMtF;AAED,qBAAa,uBAAwB,SAAQ,KAAK;gBACpC,OAAO,EAAE,MAAM;CAI5B;AAED,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAM,EAChD,IAAI,CAAC,EAAE,OAAO,EACd,eAAe,CAAC,EAAE,MAAM,GACvB,eAAe,CAejB;AAED,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,KAAK,SAAa,EAClB,KAAK,SAAa,GACjB,MAAM,GAAG,SAAS,CAOpB"}
|
package/dist/delivery.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DomainEventIgnoredError = exports.DomainEventRetryableError = exports.DomainEventTerminalError = void 0;
|
|
4
|
+
exports.classifyHttpOutcome = classifyHttpOutcome;
|
|
5
|
+
exports.boundedRetryAfter = boundedRetryAfter;
|
|
6
|
+
class DomainEventTerminalError extends Error {
|
|
7
|
+
constructor(message, status) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.name = 'DomainEventTerminalError';
|
|
10
|
+
this.status = status;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.DomainEventTerminalError = DomainEventTerminalError;
|
|
14
|
+
class DomainEventRetryableError extends Error {
|
|
15
|
+
constructor(message, options = {}) {
|
|
16
|
+
super(message);
|
|
17
|
+
this.name = 'DomainEventRetryableError';
|
|
18
|
+
this.retryAfterMs = options.retryAfterMs;
|
|
19
|
+
this.status = options.status;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.DomainEventRetryableError = DomainEventRetryableError;
|
|
23
|
+
class DomainEventIgnoredError extends Error {
|
|
24
|
+
constructor(message) {
|
|
25
|
+
super(message);
|
|
26
|
+
this.name = 'DomainEventIgnoredError';
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.DomainEventIgnoredError = DomainEventIgnoredError;
|
|
30
|
+
function classifyHttpOutcome(status, headers = {}, body, expectedEventId) {
|
|
31
|
+
if (status >= 200 && status < 300)
|
|
32
|
+
return { kind: 'processed', status };
|
|
33
|
+
if (status === 409 && isAlreadyProcessed(body, expectedEventId))
|
|
34
|
+
return {
|
|
35
|
+
kind: 'processed',
|
|
36
|
+
status,
|
|
37
|
+
eventId: typeof body === 'object' && body !== null && 'eventId' in body
|
|
38
|
+
? String(body.eventId)
|
|
39
|
+
: undefined,
|
|
40
|
+
reason: 'already_processed',
|
|
41
|
+
};
|
|
42
|
+
if (status === 408 || status === 425 || status === 429 || status >= 500)
|
|
43
|
+
return { kind: 'retryable', status, retryAfterMs: boundedRetryAfter(headers['retry-after']) };
|
|
44
|
+
return { kind: 'terminal', status };
|
|
45
|
+
}
|
|
46
|
+
function boundedRetryAfter(value, maxMs = 86_400_000, nowMs = Date.now()) {
|
|
47
|
+
if (!value)
|
|
48
|
+
return undefined;
|
|
49
|
+
const seconds = Number(value);
|
|
50
|
+
if (Number.isFinite(seconds) && seconds >= 0)
|
|
51
|
+
return Math.min(Math.round(seconds * 1000), maxMs);
|
|
52
|
+
const timestamp = Date.parse(value);
|
|
53
|
+
if (Number.isNaN(timestamp))
|
|
54
|
+
return undefined;
|
|
55
|
+
return Math.min(Math.max(timestamp - nowMs, 0), maxMs);
|
|
56
|
+
}
|
|
57
|
+
function isAlreadyProcessed(value, expectedEventId) {
|
|
58
|
+
const eventId = typeof value === 'object' && value !== null && 'eventId' in value
|
|
59
|
+
? value.eventId
|
|
60
|
+
: undefined;
|
|
61
|
+
return (typeof value === 'object' &&
|
|
62
|
+
value !== null &&
|
|
63
|
+
value.status === 'already_processed' &&
|
|
64
|
+
typeof eventId === 'string' &&
|
|
65
|
+
(expectedEventId === undefined || eventId === expectedEventId));
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=delivery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delivery.js","sourceRoot":"","sources":["../src/delivery.ts"],"names":[],"mappings":";;;AA6BA,kDAoBC;AAED,8CAWC;AA5DD,MAAa,wBAAyB,SAAQ,KAAK;IAEjD,YAAY,OAAe,EAAE,MAAe;QAC1C,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;QACvC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AAPD,4DAOC;AAED,MAAa,yBAA0B,SAAQ,KAAK;IAGlD,YAAY,OAAe,EAAE,UAAsD,EAAE;QACnF,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAC;QACxC,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;QACzC,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAC/B,CAAC;CACF;AATD,8DASC;AAED,MAAa,uBAAwB,SAAQ,KAAK;IAChD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;IACxC,CAAC;CACF;AALD,0DAKC;AAED,SAAgB,mBAAmB,CACjC,MAAc,EACd,UAA8C,EAAE,EAChD,IAAc,EACd,eAAwB;IAExB,IAAI,MAAM,IAAI,GAAG,IAAI,MAAM,GAAG,GAAG;QAAE,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC;IACxE,IAAI,MAAM,KAAK,GAAG,IAAI,kBAAkB,CAAC,IAAI,EAAE,eAAe,CAAC;QAC7D,OAAO;YACL,IAAI,EAAE,WAAW;YACjB,MAAM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ACX,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,SAAS,IAAI,KAAK;QAC/D,CAAC,CAAE,KAA+B,CAAC,OAAO;QAC1C,CAAC,CAAC,SAAS,CAAC;IAChB,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACb,KAA8B,CAAC,MAAM,KAAK,mBAAmB;QAC9D,OAAO,OAAO,KAAK,QAAQ;QAC3B,CAAC,eAAe,KAAK,SAAS,IAAI,OAAO,KAAK,eAAe,CAAC,CAC/D,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type DestinationPolicyOptions = {
|
|
2
|
+
production?: boolean;
|
|
3
|
+
allowedHosts?: string[];
|
|
4
|
+
resolve?: (hostname: string) => Promise<string[]>;
|
|
5
|
+
};
|
|
6
|
+
export type SafeDestination = {
|
|
7
|
+
url: URL;
|
|
8
|
+
addresses: string[];
|
|
9
|
+
};
|
|
10
|
+
export declare function assertSafeDestination(urlValue: string, options?: DestinationPolicyOptions): Promise<URL>;
|
|
11
|
+
export declare function resolveSafeDestination(urlValue: string, options?: DestinationPolicyOptions): Promise<SafeDestination>;
|
|
12
|
+
export declare function parseDestinationUrl(value: string): URL;
|
|
13
|
+
//# sourceMappingURL=destination-policy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"destination-policy.d.ts","sourceRoot":"","sources":["../src/destination-policy.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,wBAAwB,GAAG;IACrC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;CACnD,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,GAAG,EAAE,GAAG,CAAC;IACT,SAAS,EAAE,MAAM,EAAE,CAAC;CACrB,CAAC;AAEF,wBAAsB,qBAAqB,CACzC,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,wBAA6B,GACrC,OAAO,CAAC,GAAG,CAAC,CAEd;AAED,wBAAsB,sBAAsB,CAC1C,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,wBAA6B,GACrC,OAAO,CAAC,eAAe,CAAC,CAyB1B;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,CAMtD"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertSafeDestination = assertSafeDestination;
|
|
4
|
+
exports.resolveSafeDestination = resolveSafeDestination;
|
|
5
|
+
exports.parseDestinationUrl = parseDestinationUrl;
|
|
6
|
+
const node_dns_1 = require("node:dns");
|
|
7
|
+
const node_net_1 = require("node:net");
|
|
8
|
+
async function assertSafeDestination(urlValue, options = {}) {
|
|
9
|
+
return (await resolveSafeDestination(urlValue, options)).url;
|
|
10
|
+
}
|
|
11
|
+
async function resolveSafeDestination(urlValue, options = {}) {
|
|
12
|
+
const url = parseDestinationUrl(urlValue);
|
|
13
|
+
const host = url.hostname.toLowerCase().replace(/\.$/u, '');
|
|
14
|
+
if (options.production && (!options.allowedHosts || options.allowedHosts.length === 0))
|
|
15
|
+
throw new Error('Production webhook destinations require an explicit host allowlist');
|
|
16
|
+
if (options.allowedHosts &&
|
|
17
|
+
!options.allowedHosts.some((allowed) => normalizeHost(allowed) === host))
|
|
18
|
+
throw new Error(`Destination host is not allowlisted: ${host}`);
|
|
19
|
+
if (options.production && url.protocol !== 'https:')
|
|
20
|
+
throw new Error('Production webhook destinations must use HTTPS');
|
|
21
|
+
if (url.username || url.password)
|
|
22
|
+
throw new Error('Destination URL must not contain credentials');
|
|
23
|
+
const addresses = (0, node_net_1.isIP)(host)
|
|
24
|
+
? [host]
|
|
25
|
+
: await (options.resolve ??
|
|
26
|
+
(async (hostname) => (await node_dns_1.promises.lookup(hostname, { all: true })).map((entry) => entry.address)))(host);
|
|
27
|
+
if (addresses.length === 0)
|
|
28
|
+
throw new Error(`Destination host did not resolve: ${host}`);
|
|
29
|
+
for (const address of addresses)
|
|
30
|
+
if (isBlockedAddress(address))
|
|
31
|
+
throw new Error(`Destination resolves to a blocked address: ${address}`);
|
|
32
|
+
return { url, addresses };
|
|
33
|
+
}
|
|
34
|
+
function parseDestinationUrl(value) {
|
|
35
|
+
const url = new URL(value);
|
|
36
|
+
if (!['http:', 'https:'].includes(url.protocol))
|
|
37
|
+
throw new Error('Destination URL must use HTTP or HTTPS');
|
|
38
|
+
if (!url.hostname)
|
|
39
|
+
throw new Error('Destination URL must include a hostname');
|
|
40
|
+
return url;
|
|
41
|
+
}
|
|
42
|
+
function normalizeHost(value) {
|
|
43
|
+
return value
|
|
44
|
+
.toLowerCase()
|
|
45
|
+
.replace(/^\[|\]$/gu, '')
|
|
46
|
+
.replace(/\.$/u, '');
|
|
47
|
+
}
|
|
48
|
+
function isBlockedAddress(address) {
|
|
49
|
+
const normalized = address.toLowerCase().replace(/^\[|\]$/gu, '');
|
|
50
|
+
if ((0, node_net_1.isIP)(normalized) === 4) {
|
|
51
|
+
const [a, b, c, d] = normalized.split('.').map(Number);
|
|
52
|
+
return isBlockedIpv4Value(((a * 256 + b) * 256 + c) * 256 + d);
|
|
53
|
+
}
|
|
54
|
+
if ((0, node_net_1.isIP)(normalized) === 6) {
|
|
55
|
+
// Expand to the full 8-group form first. Matching on the *textual* form let a caller
|
|
56
|
+
// spell loopback as `0:0:0:0:0:0:0:1` (or ULA as `fc00:0:0:0:0:0:0:1` written with
|
|
57
|
+
// leading zeroes) and slip past a `=== '::1'` / `startsWith('fc')` check entirely.
|
|
58
|
+
const groups = expandIpv6(normalized);
|
|
59
|
+
if (!groups)
|
|
60
|
+
return true;
|
|
61
|
+
// IPv4-mapped (::ffff:a.b.c.d) and IPv4-compatible — classify by the embedded IPv4.
|
|
62
|
+
const first5AllZero = groups.slice(0, 5).every((group) => group === 0);
|
|
63
|
+
if (first5AllZero && groups[5] === 0xffff)
|
|
64
|
+
return isBlockedIpv4Value(embeddedIpv4(groups));
|
|
65
|
+
if (first5AllZero && groups[5] === 0) {
|
|
66
|
+
const value = embeddedIpv4(groups);
|
|
67
|
+
// `::` (unspecified) and `::1` (loopback) both land here.
|
|
68
|
+
return value <= 1 || isBlockedIpv4Value(value);
|
|
69
|
+
}
|
|
70
|
+
// NAT64 well-known prefix 64:ff9b::/96 and 64:ff9b:1::/48 tunnel to an embedded IPv4.
|
|
71
|
+
if (groups[0] === 0x0064 && groups[1] === 0xff9b)
|
|
72
|
+
return true;
|
|
73
|
+
const [head, second] = groups;
|
|
74
|
+
return ((head & 0xfe00) === 0xfc00 || // fc00::/7 unique-local
|
|
75
|
+
(head & 0xffc0) === 0xfe80 || // fe80::/10 link-local (incl. the IPv6 metadata address)
|
|
76
|
+
(head & 0xff00) === 0xff00 || // ff00::/8 multicast
|
|
77
|
+
head === 0x2002 || // 2002::/16 6to4 — tunnels to an arbitrary embedded IPv4
|
|
78
|
+
(head === 0x2001 && second === 0x0000) || // 2001::/32 Teredo — same tunnelling problem
|
|
79
|
+
(head === 0x2001 && second === 0x0db8) // 2001:db8::/32 documentation
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
/** Splits an already-`isIP`-validated IPv6 literal into its 8 numeric groups. */
|
|
85
|
+
function expandIpv6(value) {
|
|
86
|
+
let text = value;
|
|
87
|
+
// Trailing dotted-quad form (::ffff:127.0.0.1) — fold the IPv4 tail into two groups.
|
|
88
|
+
const dotted = /^(.*:)(\d+\.\d+\.\d+\.\d+)$/u.exec(text);
|
|
89
|
+
if (dotted) {
|
|
90
|
+
const octets = dotted[2].split('.').map(Number);
|
|
91
|
+
if (octets.some((octet) => !Number.isInteger(octet) || octet < 0 || octet > 255))
|
|
92
|
+
return undefined;
|
|
93
|
+
const high = (octets[0] << 8) | octets[1];
|
|
94
|
+
const low = (octets[2] << 8) | octets[3];
|
|
95
|
+
text = `${dotted[1]}${high.toString(16)}:${low.toString(16)}`;
|
|
96
|
+
}
|
|
97
|
+
// Drop a zone id (fe80::1%eth0) before parsing.
|
|
98
|
+
text = text.split('%')[0];
|
|
99
|
+
const [left, right, ...rest] = text.split('::');
|
|
100
|
+
if (rest.length > 0)
|
|
101
|
+
return undefined;
|
|
102
|
+
const parse = (part) => (part === '' ? [] : part.split(':').map((g) => parseInt(g, 16)));
|
|
103
|
+
const head = parse(left);
|
|
104
|
+
const groups = right === undefined
|
|
105
|
+
? head
|
|
106
|
+
: [...head, ...Array(8 - head.length - parse(right).length).fill(0), ...parse(right)];
|
|
107
|
+
if (groups.length !== 8 || groups.some((g) => !Number.isInteger(g) || g < 0 || g > 0xffff))
|
|
108
|
+
return undefined;
|
|
109
|
+
return groups;
|
|
110
|
+
}
|
|
111
|
+
function embeddedIpv4(groups) {
|
|
112
|
+
return groups[6] * 65536 + groups[7];
|
|
113
|
+
}
|
|
114
|
+
function isBlockedIpv4Value(value) {
|
|
115
|
+
const a = (value >>> 24) & 0xff;
|
|
116
|
+
const b = (value >>> 16) & 0xff;
|
|
117
|
+
const inRange = (start, end) => value >= start && value <= end;
|
|
118
|
+
return (a === 0 ||
|
|
119
|
+
a === 10 ||
|
|
120
|
+
a === 127 ||
|
|
121
|
+
(a === 169 && b === 254) ||
|
|
122
|
+
(a === 100 && b >= 64 && b <= 127) ||
|
|
123
|
+
(a === 172 && b >= 16 && b <= 31) ||
|
|
124
|
+
(a === 192 && b === 168) ||
|
|
125
|
+
inRange(0xc0000000, 0xc00000ff) ||
|
|
126
|
+
inRange(0xc0000200, 0xc00002ff) ||
|
|
127
|
+
inRange(0xc0586300, 0xc05863ff) ||
|
|
128
|
+
inRange(0xc6120000, 0xc613ffff) ||
|
|
129
|
+
inRange(0xc6336400, 0xc63364ff) ||
|
|
130
|
+
inRange(0xcb007100, 0xcb0071ff) ||
|
|
131
|
+
a >= 224);
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=destination-policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"destination-policy.js","sourceRoot":"","sources":["../src/destination-policy.ts"],"names":[],"mappings":";;AAcA,sDAKC;AAED,wDA4BC;AAED,kDAMC;AAzDD,uCAA2C;AAC3C,uCAAgC;AAazB,KAAK,UAAU,qBAAqB,CACzC,QAAgB,EAChB,UAAoC,EAAE;IAEtC,OAAO,CAAC,MAAM,sBAAsB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC;AAC/D,CAAC;AAEM,KAAK,UAAU,sBAAsB,CAC1C,QAAgB,EAChB,UAAoC,EAAE;IAEtC,MAAM,GAAG,GAAG,mBAAmB,CAAC,QAAQ,CAAC,CAAC;IAC1C,MAAM,IAAI,GAAG,GAAG,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAC5D,IAAI,OAAO,CAAC,UAAU,IAAI,CAAC,CAAC,OAAO,CAAC,YAAY,IAAI,OAAO,CAAC,YAAY,CAAC,MAAM,KAAK,CAAC,CAAC;QACpF,MAAM,IAAI,KAAK,CAAC,oEAAoE,CAAC,CAAC;IACxF,IACE,OAAO,CAAC,YAAY;QACpB,CAAC,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,aAAa,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC;QAExE,MAAM,IAAI,KAAK,CAAC,wCAAwC,IAAI,EAAE,CAAC,CAAC;IAClE,IAAI,OAAO,CAAC,UAAU,IAAI,GAAG,CAAC,QAAQ,KAAK,QAAQ;QACjD,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;IACpE,IAAI,GAAG,CAAC,QAAQ,IAAI,GAAG,CAAC,QAAQ;QAAE,MAAM,IAA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AAC,IAAI,GAAG,CACT,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ExternalEventEnvelope, IntegrationEventMetadata, JsonValue } from './types';
|
|
2
|
+
export declare function freezeJsonValue<T extends JsonValue>(value: T): T;
|
|
3
|
+
export declare function freezeIntegrationMetadata(input: IntegrationEventMetadata): IntegrationEventMetadata;
|
|
4
|
+
export type ExternalEventEnvelopeInput = Omit<ExternalEventEnvelope, 'payloadDigest' | 'payload' | 'envelopeVersion'> & {
|
|
5
|
+
envelopeVersion?: string;
|
|
6
|
+
payload: JsonValue;
|
|
7
|
+
payloadDigest?: string;
|
|
8
|
+
};
|
|
9
|
+
export declare function buildExternalEventEnvelope(input: ExternalEventEnvelopeInput): ExternalEventEnvelope;
|
|
10
|
+
//# sourceMappingURL=envelope.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"envelope.d.ts","sourceRoot":"","sources":["../src/envelope.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAE1F,wBAAgB,eAAe,CAAC,CAAC,SAAS,SAAS,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAGhE;AAED,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,wBAAwB,GAC9B,wBAAwB,CAc1B;AAED,MAAM,MAAM,0BAA0B,GAAG,IAAI,CAC3C,qBAAqB,EACrB,eAAe,GAAG,SAAS,GAAG,iBAAiB,CAChD,GAAG;IACF,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,OAAO,EAAE,SAAS,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,0BAA0B,GAChC,qBAAqB,CAcvB"}
|
package/dist/envelope.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.freezeJsonValue = freezeJsonValue;
|
|
4
|
+
exports.freezeIntegrationMetadata = freezeIntegrationMetadata;
|
|
5
|
+
exports.buildExternalEventEnvelope = buildExternalEventEnvelope;
|
|
6
|
+
const canonical_1 = require("./canonical");
|
|
7
|
+
function freezeJsonValue(value) {
|
|
8
|
+
const clone = (0, canonical_1.canonicalJsonValue)(value);
|
|
9
|
+
return deepFreeze(clone);
|
|
10
|
+
}
|
|
11
|
+
function freezeIntegrationMetadata(input) {
|
|
12
|
+
const payload = freezeJsonValue(input.payload);
|
|
13
|
+
const payloadDigest = (0, canonical_1.sha256Digest)(payload);
|
|
14
|
+
if (input.payloadDigest && input.payloadDigest !== payloadDigest) {
|
|
15
|
+
throw new Error(`Integration payload digest mismatch: expected ${input.payloadDigest}, got ${payloadDigest}`);
|
|
16
|
+
}
|
|
17
|
+
return deepFreeze({
|
|
18
|
+
...input,
|
|
19
|
+
envelopeVersion: input.envelopeVersion ?? '2',
|
|
20
|
+
payload,
|
|
21
|
+
payloadDigest,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
function buildExternalEventEnvelope(input) {
|
|
25
|
+
const payload = freezeJsonValue(input.payload);
|
|
26
|
+
const payloadDigest = (0, canonical_1.sha256Digest)(payload);
|
|
27
|
+
if (input.payloadDigest && input.payloadDigest !== payloadDigest) {
|
|
28
|
+
throw new Error(`External event payload digest mismatch: expected ${input.payloadDigest}, got ${payloadDigest}`);
|
|
29
|
+
}
|
|
30
|
+
return deepFreeze({
|
|
31
|
+
...input,
|
|
32
|
+
envelopeVersion: input.envelopeVersion ?? '2',
|
|
33
|
+
payload,
|
|
34
|
+
payloadDigest,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
function deepFreeze(value) {
|
|
38
|
+
if (value && typeof value === 'object' && !Object.isFrozen(value)) {
|
|
39
|
+
Object.freeze(value);
|
|
40
|
+
for (const child of Object.values(value))
|
|
41
|
+
deepFreeze(child);
|
|
42
|
+
}
|
|
43
|
+
return value;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=envelope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"envelope.js","sourceRoot":"","sources":["../src/envelope.ts"],"names":[],"mappings":";;AAGA,0CAGC;AAED,8DAgBC;AAWD,gEAgBC;AAnDD,2CAA+D;AAG/D,SAAgB,eAAe,CAAsB,KAAQ;IAC3D,MAAM,KAAK,GAAG,IAAA,8BAAkB,EAAC,KAAK,CAAM,CAAC;IAC7C,OAAO,UAAU,CAAC,KAAK,CAAC,CAAC;AAC3B,CAAC;AAED,SAAgB,yBAAyB,CACvC,KAA+B;IAE/B,MAAM,OAAO,GAAG,eAAe,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC/C,MAAM,aAAa,GAAG,IAAA,wBAAY,EAAC,OAAO,CAAC,CAAC;IAC5C,IAAI,KAAK,CAAC,aAAa,IAAI,KAAK,CAAC,aAAa,KAAK,aAAa,EAAE,CAAC;QACjE,MAAM,IAAI,KAAK,CACb,iDAAiD,KAAK,CAAC,aAAa,SAAS,aAAa,EAAE,CAC7F,CAAC;IACJ,CAAC;IACD,OAAO,UAAU,CAAC;QAChB,GAAG,KAAK;QACR,eAAe,EAAE,KAAK,CAAC,eAAe,IAAI,GAAG;QAC7C,OAAO;QACP,aAAa;KACd,CAAC,CAAC;AACL,CAAC;AAWD,SAAgB,0BAA0B,CACxC,KAAiC;IAEjC,MAAM,OAAO,GAAG,eAAe,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC/C,MAAM,aAAa,GAAG,IAAA,wBAAY,EAAC,OAAO,CAAC,CAAC;IAC5C,IAAI,KAAK,CAAC,aAAa,IAAI,KAAK,CAAC,aAAa,KAAK,aAAa,EAAE,CAAC;QACjE,MAAM,IAAI,KAAK,CACb,oDAAoD,KAAK,CAAC,aAAa,SAAS,aAAa,EAAE,CAChG,CAAC;IACJ,CAAC;IACD,OAAO,UAAU,CAAC;QAChB,GAAG,KAAK;QACR,eAAe,EAAE,KAAK,CAAC,eAAe,IAAI,GAAG;QAC7C,OAAO;QACP,aAAa;KACd,CAAC,CAAC;AACL,CAAC;AAED,SAAS,UAAU,CAAI,KAAQ;IAC7B,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QAClE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACrB,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,CAAC,KAAgC,CAAC;YAAE,UAAU,CAAC,KAAK,CAAC,CAAC;IACzF,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './canonical';
|
|
2
|
+
export * from './compatibility';
|
|
3
|
+
export * from './delivery';
|
|
4
|
+
export * from './destination-policy';
|
|
5
|
+
export * from './envelope';
|
|
6
|
+
export * from './manifest';
|
|
7
|
+
export * from './schema';
|
|
8
|
+
export * from './types';
|
|
9
|
+
export * from './webhook';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,sBAAsB,CAAC;AACrC,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./canonical"), exports);
|
|
18
|
+
__exportStar(require("./compatibility"), exports);
|
|
19
|
+
__exportStar(require("./delivery"), exports);
|
|
20
|
+
__exportStar(require("./destination-policy"), exports);
|
|
21
|
+
__exportStar(require("./envelope"), exports);
|
|
22
|
+
__exportStar(require("./manifest"), exports);
|
|
23
|
+
__exportStar(require("./schema"), exports);
|
|
24
|
+
__exportStar(require("./types"), exports);
|
|
25
|
+
__exportStar(require("./webhook"), exports);
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,kDAAgC;AAChC,6CAA2B;AAC3B,uDAAqC;AACrC,6CAA2B;AAC3B,6CAA2B;AAC3B,2CAAyB;AACzB,0CAAwB;AACxB,4CAA0B"}
|