@aamp/protocol 1.1.2 → 1.1.4
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/agent.d.ts +7 -2
- package/dist/agent.js +15 -1
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +4 -1
- package/dist/express.d.ts +3 -1
- package/dist/express.js +28 -36
- package/dist/nextjs.d.ts +3 -1
- package/dist/nextjs.js +15 -30
- package/dist/publisher.d.ts +19 -20
- package/dist/publisher.js +210 -41
- package/dist/types.d.ts +30 -17
- package/package.json +23 -23
- package/src/agent.ts +87 -71
- package/src/constants.ts +38 -34
- package/src/crypto.ts +68 -68
- package/src/express.ts +94 -103
- package/src/index.ts +12 -12
- package/src/nextjs.ts +91 -108
- package/src/publisher.ts +306 -106
- package/src/types.ts +112 -97
- package/test/handshake.spec.ts +62 -66
- package/tsconfig.json +14 -14
package/test/handshake.spec.ts
CHANGED
|
@@ -1,67 +1,63 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Integration Test: Protocol Handshake
|
|
3
|
-
* Run using: npm test
|
|
4
|
-
* Location: sdk/typescript/test/handshake.spec.ts
|
|
5
|
-
*/
|
|
6
|
-
import { AAMPAgent } from '../src/agent';
|
|
7
|
-
import { AAMPPublisher } from '../src/publisher';
|
|
8
|
-
import { AccessPurpose } from '../src/types';
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
console.log("
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
console.log("\n--- ALL TESTS PASSED ---");
|
|
65
|
-
}
|
|
66
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Integration Test: Protocol Handshake
|
|
3
|
+
* Run using: npm test
|
|
4
|
+
* Location: sdk/typescript/test/handshake.spec.ts
|
|
5
|
+
*/
|
|
6
|
+
import { AAMPAgent } from '../src/agent';
|
|
7
|
+
import { AAMPPublisher } from '../src/publisher';
|
|
8
|
+
import { AccessPurpose } from '../src/types';
|
|
9
|
+
import { HEADERS } from '../src/constants';
|
|
10
|
+
|
|
11
|
+
async function runTest() {
|
|
12
|
+
console.log("--- STARTING AAMP HANDSHAKE TEST ---");
|
|
13
|
+
|
|
14
|
+
// 1. Setup Publisher with Economic Policy
|
|
15
|
+
const publisher = new AAMPPublisher({
|
|
16
|
+
version: '1.1',
|
|
17
|
+
allowTraining: false,
|
|
18
|
+
allowRAG: true,
|
|
19
|
+
attributionRequired: true,
|
|
20
|
+
requiresPayment: true, // Publisher wants money...
|
|
21
|
+
allowAdSupportedAccess: true, // ...OR ads
|
|
22
|
+
paymentPointer: '$wallet.example.com/publisher'
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// 2. Initialize Agent
|
|
26
|
+
const agent = new AAMPAgent();
|
|
27
|
+
await agent.initialize();
|
|
28
|
+
|
|
29
|
+
// TEST CASE A: Requesting RAG without Ads (Should FAIL due to Payment Requirement)
|
|
30
|
+
console.log("\n[TEST A] Requesting RAG (No Ads)...");
|
|
31
|
+
const reqA = await agent.createAccessRequest('/doc/1', AccessPurpose.RAG_RETRIEVAL, { adsDisplayed: false });
|
|
32
|
+
|
|
33
|
+
const payloadA = JSON.stringify(reqA.header);
|
|
34
|
+
const headersA = {
|
|
35
|
+
[HEADERS.PAYLOAD]: btoa(payloadA),
|
|
36
|
+
[HEADERS.SIGNATURE]: reqA.signature,
|
|
37
|
+
[HEADERS.PUBLIC_KEY]: reqA.publicKey!
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const resA = await publisher.evaluateVisitor(headersA, payloadA);
|
|
41
|
+
console.log("Result A (Expect Deny):", resA);
|
|
42
|
+
if (resA.allowed) throw new Error("Test A Failed (Should require payment)");
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
// TEST CASE B: Requesting RAG WITH Ads (Should SUCCEED via Exemption)
|
|
46
|
+
console.log("\n[TEST B] Requesting RAG (With Ads)...");
|
|
47
|
+
const reqB = await agent.createAccessRequest('/doc/1', AccessPurpose.RAG_RETRIEVAL, { adsDisplayed: true });
|
|
48
|
+
|
|
49
|
+
const payloadB = JSON.stringify(reqB.header);
|
|
50
|
+
const headersB = {
|
|
51
|
+
[HEADERS.PAYLOAD]: btoa(payloadB),
|
|
52
|
+
[HEADERS.SIGNATURE]: reqB.signature,
|
|
53
|
+
[HEADERS.PUBLIC_KEY]: reqB.publicKey!
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const resB = await publisher.evaluateVisitor(headersB, payloadB);
|
|
57
|
+
console.log("Result B (Expect Allow):", resB);
|
|
58
|
+
if (!resB.allowed) throw new Error("Test B Failed (Should allow via Ad exemption)");
|
|
59
|
+
|
|
60
|
+
console.log("\n--- ALL TESTS PASSED ---");
|
|
61
|
+
}
|
|
62
|
+
|
|
67
63
|
runTest().catch(console.error);
|
package/tsconfig.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2020",
|
|
4
|
-
"module": "CommonJS",
|
|
5
|
-
"lib": ["ES2020", "DOM"],
|
|
6
|
-
"declaration": true,
|
|
7
|
-
"outDir": "./dist",
|
|
8
|
-
"rootDir": "./src",
|
|
9
|
-
"strict": true,
|
|
10
|
-
"esModuleInterop": true,
|
|
11
|
-
"skipLibCheck": true,
|
|
12
|
-
"forceConsistentCasingInFileNames": true
|
|
13
|
-
},
|
|
14
|
-
"include": ["src/**/*"]
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"module": "CommonJS",
|
|
5
|
+
"lib": ["ES2020", "DOM"],
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"outDir": "./dist",
|
|
8
|
+
"rootDir": "./src",
|
|
9
|
+
"strict": true,
|
|
10
|
+
"esModuleInterop": true,
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"forceConsistentCasingInFileNames": true
|
|
13
|
+
},
|
|
14
|
+
"include": ["src/**/*"]
|
|
15
15
|
}
|