@queelabs/connectors-mpp 0.0.1

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/http.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ import type { MppPaymentAdapter } from "@queelabs/core";
2
+ export type HttpMppConnectorOptions = {
3
+ /** Base URL of your MPP gateway (no trailing slash). */
4
+ baseUrl: string;
5
+ apiKey?: string;
6
+ fetchImpl?: typeof fetch;
7
+ };
8
+ /**
9
+ * Forwards challenge creation and verification to an external HTTP service.
10
+ * Contract: see `docs/connectors-http.md`.
11
+ */
12
+ export declare function createHttpMppConnector(opts: HttpMppConnectorOptions): MppPaymentAdapter;
13
+ //# sourceMappingURL=http.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,iBAAiB,EAGlB,MAAM,gBAAgB,CAAC;AAExB,MAAM,MAAM,uBAAuB,GAAG;IACpC,wDAAwD;IACxD,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;CAC1B,CAAC;AAQF;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,uBAAuB,GAC5B,iBAAiB,CA4EnB"}
package/dist/http.js ADDED
@@ -0,0 +1,67 @@
1
+ function headers(apiKey) {
2
+ const h = { "Content-Type": "application/json" };
3
+ if (apiKey)
4
+ h.Authorization = `Bearer ${apiKey}`;
5
+ return h;
6
+ }
7
+ /**
8
+ * Forwards challenge creation and verification to an external HTTP service.
9
+ * Contract: see `docs/connectors-http.md`.
10
+ */
11
+ export function createHttpMppConnector(opts) {
12
+ const base = opts.baseUrl.replace(/\/$/, "");
13
+ const f = opts.fetchImpl ?? fetch;
14
+ return {
15
+ async createPurchaseChallenge(input) {
16
+ const res = await f(`${base}/v1/challenges`, {
17
+ method: "POST",
18
+ headers: headers(opts.apiKey),
19
+ body: JSON.stringify(input),
20
+ });
21
+ const text = await res.text();
22
+ if (!res.ok) {
23
+ throw new Error(`MPP HTTP challenge failed (${res.status}): ${text.slice(0, 500)}`);
24
+ }
25
+ const json = JSON.parse(text);
26
+ if (typeof json.challengeId !== "string" ||
27
+ typeof json.rail !== "string" ||
28
+ typeof json.payload !== "object" ||
29
+ json.payload === null) {
30
+ throw new Error("MPP HTTP: invalid challenge response shape");
31
+ }
32
+ const expiresAt = json.expiresAt instanceof Date
33
+ ? json.expiresAt
34
+ : typeof json.expiresAt === "string"
35
+ ? new Date(json.expiresAt)
36
+ : undefined;
37
+ return {
38
+ challengeId: json.challengeId,
39
+ rail: json.rail,
40
+ payload: json.payload,
41
+ expiresAt,
42
+ };
43
+ },
44
+ async verifyPurchase(input) {
45
+ const res = await f(`${base}/v1/verify`, {
46
+ method: "POST",
47
+ headers: headers(opts.apiKey),
48
+ body: JSON.stringify(input),
49
+ });
50
+ const text = await res.text();
51
+ if (!res.ok) {
52
+ throw new Error(`MPP HTTP verify failed (${res.status}): ${text.slice(0, 500)}`);
53
+ }
54
+ const json = JSON.parse(text);
55
+ if (!json?.receiptPayload || typeof json.receiptPayload !== "object") {
56
+ throw new Error("MPP HTTP: invalid verify response (need receiptPayload)");
57
+ }
58
+ return {
59
+ receiptPayload: json.receiptPayload,
60
+ verifiedAt: json.verifiedAt
61
+ ? new Date(json.verifiedAt)
62
+ : new Date(),
63
+ };
64
+ },
65
+ };
66
+ }
67
+ //# sourceMappingURL=http.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.js","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAeA,SAAS,OAAO,CAAC,MAAe;IAC9B,MAAM,CAAC,GAA2B,EAAE,cAAc,EAAE,kBAAkB,EAAE,CAAC;IACzE,IAAI,MAAM;QAAE,CAAC,CAAC,aAAa,GAAG,UAAU,MAAM,EAAE,CAAC;IACjD,OAAO,CA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ymentAdapter } from "@queelabs/core";
2
+ export { createHttpMppConnector, type HttpMppConnectorOptions, } from "./http.js";
3
+ /**
4
+ * Dev-friendly MPP-shaped connector: returns a structured challenge payload.
5
+ * Agents complete payment by POSTing proof; verification accepts mock proof for local demos.
6
+ */
7
+ export declare function createMockMppConnector(): MppPaymentAdapter;
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,iBAAiB,EAGlB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EACL,sBAAsB,EACtB,KAAK,uBAAuB,GAC7B,MAAM,WAAW,CAAC;AAEnB;;;GAGG;AACH,wBAAgB,sBAAsB,IAAI,iBAAiB,CA+C1D"}
package/dist/index.js ADDED
@@ -0,0 +1,52 @@
1
+ import { nanoid } from "nanoid";
2
+ export { createHttpMppConnector, } from "./http.js";
3
+ /**
4
+ * Dev-friendly MPP-shaped connector: returns a structured challenge payload.
5
+ * Agents complete payment by POSTing proof; verification accepts mock proof for local demos.
6
+ */
7
+ export function createMockMppConnector() {
8
+ return {
9
+ async createPurchaseChallenge(input) {
10
+ const challengeId = `ch_${nanoid(12)}`;
11
+ const expiresAt = new Date(Date.now() + 15 * 60 * 1000);
12
+ return {
13
+ challengeId,
14
+ rail: "mpp",
15
+ payload: {
16
+ type: "payment_challenge",
17
+ version: "0.1",
18
+ orderId: input.orderId,
19
+ marketplaceId: input.marketplaceId,
20
+ amountMinor: input.amountMinor,
21
+ currency: input.currency,
22
+ /** Example: HTTP 402 body would echo this for machine clients */
23
+ mpp: {
24
+ accepts: ["mock", "tempo"],
25
+ resource: `quee://orders/${input.orderId}/pay`,
26
+ },
27
+ expiresAt: expiresAt.toISOString(),
28
+ },
29
+ expiresAt,
30
+ };
31
+ },
32
+ async verifyPurchase(input) {
33
+ const paid = input.proof.mockPaid === true ||
34
+ input.proof.receipt === "ok" ||
35
+ input.proof.signature === "demo";
36
+ if (!paid) {
37
+ throw new Error("payment verification failed: missing proof");
38
+ }
39
+ return {
40
+ receiptPayload: {
41
+ verified: true,
42
+ challengeId: input.challengeId,
43
+ orderId: input.orderId,
44
+ settledVia: input.rail,
45
+ proof: input.proof,
46
+ },
47
+ verifiedAt: new Date(),
48
+ };
49
+ },
50
+ };
51
+ }
52
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EACL,sBAAsB,GAEvB,MAAM,WAAW,CAAC;AAEnB;;;GAGG;AACH,MAAM,UAAU,sBAAsB;IACpC,OAAO;QACL,KAAK,CAAC,uBAAuB,CAC3B,KAA2B;YAE3B,MAAM,WAAW,GAAG,MAAM,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC;YACvC,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;YACxD,OAAO;gBACL,WAAW;gBACX,IAAI,EAAE,KAAK;gBACX,OAAO,EAAE;oBACP,IAAI,EAAE,mBAAmB;oBACzB,OAAO,EAAE,KAAK;oBACd,OAAO,EAAE,KAAK,CAAC,OAAO;oBACtB,aAAa,EAAE,KAAK,CAAC,aAAa;oBAClC,WAAW,EAAE,KAAK,CAAC,WAAW;oBAC9B,QAAQ,EAAE,KAAK,CAAC,QAAQ;oBACxB,iEAAiE;oBACjE,GAAG,EAAE;wBACH,OAAO,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC;wBAC1B,QAAQ,EAAE,iBAAiB,KAAK,CAAC,OAAO,MAAM;qBAC/C;oBACD,SAAS,EAAE,SAAS,CAAC,WAAW,EAAE;iBACnC;gBACD,SAAS;aACV,CAAC;QACJ,CAAC;QACD,KAAK,CAAC,cAAc,CAAC,KAAyB;YAC5C,MAAM,IAAI,GACR,KAAK,CAAC,KAAK,CAAC,QAAQ,KAAK,IAAI;gBAC7B,KAAK,CAAC,KAAK,CAAC,OAAO,KAAK,IAAI;gBAC5B,KAAK,CAAC,KAAK,CAAC,SAAS,KAAK,MAAM,CAAC;YACnC,IAAI,CAAC,IAAI,EAAE,CAAC;gBACV,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;YAChE,CAAC;YACD,OAAO;gBACL,cAAc,EAAE;oBACd,QAAQ,EAAE,IAAI;oBACd,WAAW,EAAE,KAAK,CAAC,WAAW;oBAC9B,OAAO,EAAE,KAAK,CAAC,OAAO;oBACtB,UAAU,EAAE,KAAK,CAAC,IAAI;oBACtB,KAAK,EAAE,KAAK,CAAC,KAAK;iBACnB;gBACD,UAAU,EAAE,IAAI,IAAI,EAAE;aACvB,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@queelabs/connectors-mpp",
3
+ "version": "0.0.1",
4
+ "license": "UNLICENSED",
5
+ "description": "MPP challenge and verify connector for Quee",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "files": [
10
+ "dist"
11
+ ],
12
+ "publishConfig": {
13
+ "access": "public"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/quee-protocol/quee.git",
18
+ "directory": "connectors/mpp"
19
+ },
20
+ "exports": {
21
+ ".": {
22
+ "types": "./dist/index.d.ts",
23
+ "import": "./dist/index.js"
24
+ }
25
+ },
26
+ "dependencies": {
27
+ "nanoid": "^5.0.9",
28
+ "@queelabs/core": "0.0.1"
29
+ },
30
+ "devDependencies": {
31
+ "@types/node": "^22.10.2",
32
+ "typescript": "^5.7.2",
33
+ "vitest": "^2.1.8"
34
+ },
35
+ "scripts": {
36
+ "build": "tsc",
37
+ "lint": "echo ok",
38
+ "test": "vitest run --passWithNoTests"
39
+ }
40
+ }