@402flow/sdk 0.1.0-alpha.1 → 0.1.0-alpha.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/LICENSE +201 -0
- package/README.md +58 -23
- package/dist/challenge-detection.d.ts +7 -5
- package/dist/challenge-detection.js +54 -102
- package/dist/challenge-detection.js.map +1 -1
- package/dist/contracts.d.ts +484 -328
- package/dist/contracts.js +46 -13
- package/dist/contracts.js.map +1 -1
- package/dist/index.d.ts +43 -8
- package/dist/index.js +166 -22
- package/dist/index.js.map +1 -1
- package/dist/version.d.ts +2 -0
- package/dist/version.js +4 -0
- package/dist/version.js.map +1 -0
- package/package.json +19 -7
- package/dist/challenge-types.d.ts +0 -57
- package/dist/challenge-types.js +0 -111
- package/dist/challenge-types.js.map +0 -1
- package/dist/x402-v1.d.ts +0 -4
- package/dist/x402-v1.js +0 -53
- package/dist/x402-v1.js.map +0 -1
- package/dist/x402-v2.d.ts +0 -4
- package/dist/x402-v2.js +0 -52
- package/dist/x402-v2.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@402flow/sdk",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.10",
|
|
4
4
|
"description": "Node.js SDK for making paid requests through the 402flow control plane.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
8
|
"types": "dist/index.d.ts",
|
|
9
|
+
"engines": {
|
|
10
|
+
"node": ">=22.0.0"
|
|
11
|
+
},
|
|
9
12
|
"license": "Apache-2.0",
|
|
10
13
|
"author": "402flow",
|
|
11
14
|
"homepage": "https://github.com/402flow/sdk#readme",
|
|
@@ -14,8 +17,7 @@
|
|
|
14
17
|
},
|
|
15
18
|
"repository": {
|
|
16
19
|
"type": "git",
|
|
17
|
-
"url": "git+https://github.com/402flow/sdk.git"
|
|
18
|
-
"directory": "packages/sdk"
|
|
20
|
+
"url": "git+https://github.com/402flow/sdk.git"
|
|
19
21
|
},
|
|
20
22
|
"keywords": [
|
|
21
23
|
"402flow",
|
|
@@ -24,7 +26,6 @@
|
|
|
24
26
|
"AI",
|
|
25
27
|
"agents",
|
|
26
28
|
"payments"
|
|
27
|
-
|
|
28
29
|
],
|
|
29
30
|
"files": [
|
|
30
31
|
"dist"
|
|
@@ -41,15 +42,26 @@
|
|
|
41
42
|
},
|
|
42
43
|
"scripts": {
|
|
43
44
|
"build": "tsc -p tsconfig.json",
|
|
45
|
+
"check": "npm run lint && npm test",
|
|
44
46
|
"clean": "node -e \"const fs = require('node:fs'); for (const path of ['dist', 'tsconfig.tsbuildinfo', 'tsconfig.typecheck.tsbuildinfo']) { fs.rmSync(path, { recursive: true, force: true }); }\"",
|
|
45
|
-
"lint": "eslint src",
|
|
46
|
-
"
|
|
47
|
-
"
|
|
47
|
+
"lint": "eslint src vitest.config.ts && npm run typecheck",
|
|
48
|
+
"pack:check": "npm run clean && npm run build && npm pack --dry-run",
|
|
49
|
+
"prepack": "npm run clean && npm run build",
|
|
48
50
|
"test": "vitest run",
|
|
49
51
|
"test:coverage": "vitest run --coverage",
|
|
50
52
|
"typecheck": "tsc -p tsconfig.typecheck.json --noEmit"
|
|
51
53
|
},
|
|
52
54
|
"dependencies": {
|
|
53
55
|
"zod": "^3.24.2"
|
|
56
|
+
},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"@eslint/js": "^9.22.0",
|
|
59
|
+
"@types/node": "^22.13.10",
|
|
60
|
+
"@vitest/coverage-v8": "^3.0.8",
|
|
61
|
+
"eslint": "^9.22.0",
|
|
62
|
+
"globals": "^15.15.0",
|
|
63
|
+
"typescript": "^5.8.2",
|
|
64
|
+
"typescript-eslint": "^8.26.1",
|
|
65
|
+
"vitest": "^3.0.8"
|
|
54
66
|
}
|
|
55
67
|
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { type NormalizedMoney, type PaidRequestProtocol } from './contracts.js';
|
|
2
|
-
export type SupportedProtocol = PaidRequestProtocol;
|
|
3
|
-
export declare const defaultX402MoneyPrecision = 6;
|
|
4
|
-
export type X402PaymentRequirement = {
|
|
5
|
-
scheme: string;
|
|
6
|
-
network: string;
|
|
7
|
-
amount?: string;
|
|
8
|
-
maxAmountRequired?: string;
|
|
9
|
-
asset?: string;
|
|
10
|
-
payTo?: string;
|
|
11
|
-
maxTimeoutSeconds?: number;
|
|
12
|
-
extra?: Record<string, unknown>;
|
|
13
|
-
};
|
|
14
|
-
export type X402PaymentRequired = {
|
|
15
|
-
x402Version: number;
|
|
16
|
-
error?: string;
|
|
17
|
-
resource?: {
|
|
18
|
-
url: string;
|
|
19
|
-
description?: string;
|
|
20
|
-
mimeType?: string;
|
|
21
|
-
} & Record<string, unknown>;
|
|
22
|
-
accepts: X402PaymentRequirement[];
|
|
23
|
-
};
|
|
24
|
-
export type X402PaymentResponse = Record<string, unknown>;
|
|
25
|
-
export type ParsedChallenge = {
|
|
26
|
-
protocol: SupportedProtocol;
|
|
27
|
-
money: NormalizedMoney;
|
|
28
|
-
payee?: string;
|
|
29
|
-
raw: Record<string, unknown>;
|
|
30
|
-
};
|
|
31
|
-
export declare function readX402RequirementAmount(requirement: X402PaymentRequirement): string | undefined;
|
|
32
|
-
export declare function createParsedChallenge(input: {
|
|
33
|
-
protocol: SupportedProtocol;
|
|
34
|
-
money: NormalizedMoney;
|
|
35
|
-
payee: string | undefined;
|
|
36
|
-
raw: Record<string, unknown>;
|
|
37
|
-
}): ParsedChallenge;
|
|
38
|
-
export declare function minorUnitsToMonetaryAmount(amountMinor: string, precision: number): string;
|
|
39
|
-
export declare function decodeBase64JsonObject(value: string): unknown;
|
|
40
|
-
export declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
41
|
-
export declare function isX402PaymentRequirement(value: unknown): value is X402PaymentRequirement;
|
|
42
|
-
export declare function isX402PaymentRequired(value: unknown): value is X402PaymentRequired;
|
|
43
|
-
export declare function inferX402Precision(requirement: X402PaymentRequirement): number;
|
|
44
|
-
export declare function createParsedChallengeFromPaymentRequired(input: {
|
|
45
|
-
protocol: SupportedProtocol;
|
|
46
|
-
paymentRequired: X402PaymentRequired;
|
|
47
|
-
raw: Record<string, unknown>;
|
|
48
|
-
}): ParsedChallenge | undefined;
|
|
49
|
-
export declare function createParsedChallengeFromExplicitHeaders(input: {
|
|
50
|
-
protocol: SupportedProtocol;
|
|
51
|
-
amount: string;
|
|
52
|
-
asset: string;
|
|
53
|
-
precision: number;
|
|
54
|
-
payee?: string;
|
|
55
|
-
raw: Record<string, unknown>;
|
|
56
|
-
}): ParsedChallenge;
|
|
57
|
-
export declare function getX402PaymentRequired(challenge: ParsedChallenge): X402PaymentRequired | undefined;
|
package/dist/challenge-types.js
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { monetaryAmountToMinorUnits, normalizedMoneySchema, } from './contracts.js';
|
|
2
|
-
export const defaultX402MoneyPrecision = 6;
|
|
3
|
-
export function readX402RequirementAmount(requirement) {
|
|
4
|
-
return requirement.amount ?? requirement.maxAmountRequired;
|
|
5
|
-
}
|
|
6
|
-
export function createParsedChallenge(input) {
|
|
7
|
-
return {
|
|
8
|
-
protocol: input.protocol,
|
|
9
|
-
money: input.money,
|
|
10
|
-
raw: input.raw,
|
|
11
|
-
...(input.payee ? { payee: input.payee } : {}),
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
export function minorUnitsToMonetaryAmount(amountMinor, precision) {
|
|
15
|
-
if (!/^\d+$/.test(amountMinor)) {
|
|
16
|
-
throw new Error('Invalid minor-unit amount format.');
|
|
17
|
-
}
|
|
18
|
-
if (precision === 0) {
|
|
19
|
-
return amountMinor;
|
|
20
|
-
}
|
|
21
|
-
const normalizedMinorUnits = amountMinor.padStart(precision + 1, '0');
|
|
22
|
-
const wholePart = normalizedMinorUnits.slice(0, -precision) || '0';
|
|
23
|
-
const fractionalPart = normalizedMinorUnits.slice(-precision);
|
|
24
|
-
return `${wholePart}.${fractionalPart}`;
|
|
25
|
-
}
|
|
26
|
-
export function decodeBase64JsonObject(value) {
|
|
27
|
-
const normalized = value.replace(/-/g, '+').replace(/_/g, '/');
|
|
28
|
-
const padded = normalized.padEnd(Math.ceil(normalized.length / 4) * 4, '=');
|
|
29
|
-
const decodeBase64 = typeof globalThis.atob === 'function'
|
|
30
|
-
? globalThis.atob.bind(globalThis)
|
|
31
|
-
: (input) => Buffer.from(input, 'base64').toString('binary');
|
|
32
|
-
const binary = decodeBase64(padded);
|
|
33
|
-
const bytes = Uint8Array.from(binary, (character) => character.charCodeAt(0));
|
|
34
|
-
const decoded = new TextDecoder().decode(bytes);
|
|
35
|
-
return JSON.parse(decoded);
|
|
36
|
-
}
|
|
37
|
-
export function isRecord(value) {
|
|
38
|
-
return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
|
|
39
|
-
}
|
|
40
|
-
export function isX402PaymentRequirement(value) {
|
|
41
|
-
return (isRecord(value) &&
|
|
42
|
-
typeof value.scheme === 'string' &&
|
|
43
|
-
typeof value.network === 'string' &&
|
|
44
|
-
(typeof value.amount === 'string' || typeof value.maxAmountRequired === 'string'));
|
|
45
|
-
}
|
|
46
|
-
export function isX402PaymentRequired(value) {
|
|
47
|
-
return (isRecord(value) &&
|
|
48
|
-
typeof value.x402Version === 'number' &&
|
|
49
|
-
Array.isArray(value.accepts) &&
|
|
50
|
-
value.accepts.every((accept) => isX402PaymentRequirement(accept)));
|
|
51
|
-
}
|
|
52
|
-
export function inferX402Precision(requirement) {
|
|
53
|
-
const extra = requirement.extra;
|
|
54
|
-
if (!isRecord(extra)) {
|
|
55
|
-
return defaultX402MoneyPrecision;
|
|
56
|
-
}
|
|
57
|
-
const precisionCandidate = extra.precision ?? extra.decimals;
|
|
58
|
-
const precision = Number(precisionCandidate);
|
|
59
|
-
if (!Number.isFinite(precision) || precision < 0) {
|
|
60
|
-
return defaultX402MoneyPrecision;
|
|
61
|
-
}
|
|
62
|
-
return precision;
|
|
63
|
-
}
|
|
64
|
-
export function createParsedChallengeFromPaymentRequired(input) {
|
|
65
|
-
const firstRequirement = input.paymentRequired.accepts[0];
|
|
66
|
-
if (!firstRequirement) {
|
|
67
|
-
return undefined;
|
|
68
|
-
}
|
|
69
|
-
const requirementAmount = readX402RequirementAmount(firstRequirement);
|
|
70
|
-
if (!requirementAmount) {
|
|
71
|
-
return undefined;
|
|
72
|
-
}
|
|
73
|
-
const precision = inferX402Precision(firstRequirement);
|
|
74
|
-
const amount = minorUnitsToMonetaryAmount(requirementAmount, precision);
|
|
75
|
-
const asset = firstRequirement.asset ?? 'UNKNOWN';
|
|
76
|
-
const payee = firstRequirement.payTo;
|
|
77
|
-
return createParsedChallenge({
|
|
78
|
-
protocol: input.protocol,
|
|
79
|
-
money: normalizedMoneySchema.parse({
|
|
80
|
-
asset,
|
|
81
|
-
amount,
|
|
82
|
-
amountMinor: requirementAmount,
|
|
83
|
-
precision,
|
|
84
|
-
unit: 'minor',
|
|
85
|
-
}),
|
|
86
|
-
payee,
|
|
87
|
-
raw: input.raw,
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
export function createParsedChallengeFromExplicitHeaders(input) {
|
|
91
|
-
return createParsedChallenge({
|
|
92
|
-
protocol: input.protocol,
|
|
93
|
-
money: normalizedMoneySchema.parse({
|
|
94
|
-
asset: input.asset,
|
|
95
|
-
amount: input.amount,
|
|
96
|
-
amountMinor: monetaryAmountToMinorUnits(input.amount, input.precision),
|
|
97
|
-
precision: input.precision,
|
|
98
|
-
unit: 'minor',
|
|
99
|
-
}),
|
|
100
|
-
payee: input.payee,
|
|
101
|
-
raw: input.raw,
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
export function getX402PaymentRequired(challenge) {
|
|
105
|
-
const paymentRequired = challenge.raw.paymentRequired;
|
|
106
|
-
if (!isX402PaymentRequired(paymentRequired)) {
|
|
107
|
-
return undefined;
|
|
108
|
-
}
|
|
109
|
-
return paymentRequired;
|
|
110
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,SAAS,CAAC;IACnB,CAAC;IAED,OAAO,eAAe,CAAC;AACzB,CAAC"}
|
package/dist/x402-v1.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { type X402PaymentResponse } from './challenge-types.js';
|
|
2
|
-
export declare function parseX402V1HeaderChallenge(response: Response): import("./challenge-types.js").ParsedChallenge | undefined;
|
|
3
|
-
export declare function parseX402V1BodyChallenge(candidate: unknown): import("./challenge-types.js").ParsedChallenge | undefined;
|
|
4
|
-
export declare function parseX402V1PaymentResponseHeader(headerValue: string | null): X402PaymentResponse | undefined;
|
package/dist/x402-v1.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { createParsedChallengeFromExplicitHeaders, createParsedChallengeFromPaymentRequired, decodeBase64JsonObject, isRecord, isX402PaymentRequired, } from './challenge-types.js';
|
|
2
|
-
export function parseX402V1HeaderChallenge(response) {
|
|
3
|
-
const protocolHeader = response.headers.get('x-payment-protocol');
|
|
4
|
-
const amountHeader = response.headers.get('x-payment-amount');
|
|
5
|
-
const assetHeader = response.headers.get('x-payment-asset');
|
|
6
|
-
if (!protocolHeader || !amountHeader || !assetHeader) {
|
|
7
|
-
return undefined;
|
|
8
|
-
}
|
|
9
|
-
return createParsedChallengeFromExplicitHeaders({
|
|
10
|
-
protocol: protocolHeader.toLowerCase(),
|
|
11
|
-
amount: amountHeader,
|
|
12
|
-
asset: assetHeader,
|
|
13
|
-
precision: Number(response.headers.get('x-payment-precision') ?? '6'),
|
|
14
|
-
...(response.headers.get('x-payment-payee')
|
|
15
|
-
? { payee: response.headers.get('x-payment-payee') }
|
|
16
|
-
: {}),
|
|
17
|
-
raw: {
|
|
18
|
-
headers: {
|
|
19
|
-
'x-payment-protocol': protocolHeader,
|
|
20
|
-
'x-payment-amount': amountHeader,
|
|
21
|
-
'x-payment-asset': assetHeader,
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
export function parseX402V1BodyChallenge(candidate) {
|
|
27
|
-
if (!isX402PaymentRequired(candidate) || candidate.x402Version !== 1) {
|
|
28
|
-
return undefined;
|
|
29
|
-
}
|
|
30
|
-
return createParsedChallengeFromPaymentRequired({
|
|
31
|
-
protocol: 'x402',
|
|
32
|
-
paymentRequired: candidate,
|
|
33
|
-
raw: {
|
|
34
|
-
paymentRequired: candidate,
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
export function parseX402V1PaymentResponseHeader(headerValue) {
|
|
39
|
-
if (!headerValue) {
|
|
40
|
-
return undefined;
|
|
41
|
-
}
|
|
42
|
-
try {
|
|
43
|
-
const decodedHeader = decodeBase64JsonObject(headerValue);
|
|
44
|
-
if (!isRecord(decodedHeader)) {
|
|
45
|
-
return undefined;
|
|
46
|
-
}
|
|
47
|
-
return decodedHeader;
|
|
48
|
-
}
|
|
49
|
-
catch {
|
|
50
|
-
return undefined;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
//# sourceMappingURL=x402-v1.js.map
|
package/dist/x402-v1.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"x402-v1.js","sourceRoot":"","sources":["../src/x402-v1.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wCAAwC,EACxC,wCAAwC,EACxC,sBAAsB,EACtB,QAAQ,EACR,qBAAqB,GAEtB,MAAM,sBAAsB,CAAC;AAE9B,MAAM,UAAU,0BAA0B,CAAC,QAAkB;IAC3D,MAAM,cAAc,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;IAClE,MAAM,YAAY,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;IAC9D,MAAM,WAAW,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;IAE5D,IAAI,CAAC,cAAc,IAAI,CAAC,YAAY,IAAI,CAAC,WAAW,EAAE,C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AC9C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC"}
|
package/dist/x402-v2.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { type X402PaymentResponse } from './challenge-types.js';
|
|
2
|
-
export declare function parseX402V2HeaderChallenge(response: Response): import("./challenge-types.js").ParsedChallenge | undefined;
|
|
3
|
-
export declare function parseX402V2BodyChallenge(candidate: unknown): import("./challenge-types.js").ParsedChallenge | undefined;
|
|
4
|
-
export declare function parseX402V2PaymentResponseHeader(headerValue: string | null): X402PaymentResponse | undefined;
|
package/dist/x402-v2.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { createParsedChallengeFromPaymentRequired, decodeBase64JsonObject, isRecord, isX402PaymentRequired, } from './challenge-types.js';
|
|
2
|
-
export function parseX402V2HeaderChallenge(response) {
|
|
3
|
-
const paymentRequiredHeader = response.headers.get('payment-required');
|
|
4
|
-
if (!paymentRequiredHeader) {
|
|
5
|
-
return undefined;
|
|
6
|
-
}
|
|
7
|
-
try {
|
|
8
|
-
const decodedHeader = decodeBase64JsonObject(paymentRequiredHeader);
|
|
9
|
-
if (!isX402PaymentRequired(decodedHeader) || decodedHeader.x402Version !== 2) {
|
|
10
|
-
return undefined;
|
|
11
|
-
}
|
|
12
|
-
return createParsedChallengeFromPaymentRequired({
|
|
13
|
-
protocol: 'x402',
|
|
14
|
-
paymentRequired: decodedHeader,
|
|
15
|
-
raw: {
|
|
16
|
-
paymentRequiredHeader,
|
|
17
|
-
paymentRequired: decodedHeader,
|
|
18
|
-
},
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
catch {
|
|
22
|
-
return undefined;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
export function parseX402V2BodyChallenge(candidate) {
|
|
26
|
-
if (!isX402PaymentRequired(candidate) || candidate.x402Version !== 2) {
|
|
27
|
-
return undefined;
|
|
28
|
-
}
|
|
29
|
-
return createParsedChallengeFromPaymentRequired({
|
|
30
|
-
protocol: 'x402',
|
|
31
|
-
paymentRequired: candidate,
|
|
32
|
-
raw: {
|
|
33
|
-
paymentRequired: candidate,
|
|
34
|
-
},
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
export function parseX402V2PaymentResponseHeader(headerValue) {
|
|
38
|
-
if (!headerValue) {
|
|
39
|
-
return undefined;
|
|
40
|
-
}
|
|
41
|
-
try {
|
|
42
|
-
const decodedHeader = decodeBase64JsonObject(headerValue);
|
|
43
|
-
if (!isRecord(decodedHeader)) {
|
|
44
|
-
return undefined;
|
|
45
|
-
}
|
|
46
|
-
return decodedHeader;
|
|
47
|
-
}
|
|
48
|
-
catch {
|
|
49
|
-
return undefined;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
//# sourceMappingURL=x402-v2.js.map
|
package/dist/x402-v2.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"x402-v2.js","sourceRoot":"","sources":["../src/x402-v2.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wCAAwC,EACxC,sBAAsB,EACtB,QAAQ,EACR,qBAAqB,GAEtB,MAAM,sBAAsB,CAAC;AAE9B,MAAM,UAAU,0BAA0B,CAAC,QAAkB;IAC3D,MAAM,qBAAqB,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;IAEvE,IAAI,CAAC,qBAAqB,EAAE,CAAC;QAC3B,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,CAAC;QACH,MAAM,aAAa,GAAG,sBAAsB,CAAC,qBAAqB,CAAC,CAAC;QAEpE,IAAI,CAAC,qBAAqB,CAAC,aAAa,CAAC,IAAI,aAAa,CAAC,WAAW,KAAK,CAAC,EAAE,CAAC;YAC7E,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,OAAO,wCAAwC,CAAC;YAC9C,QAAQ,EAAE,MAAM;YAChB,eAAe,EAAE,aAAa;Y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