tru-402 0.5.1 → 0.7.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/dist/bin/tru.d.ts +3 -0
- package/dist/bin/tru.d.ts.map +1 -0
- package/dist/bin/tru.js +38 -0
- package/dist/bin/tru.js.map +1 -0
- package/dist/src/challenge.d.ts +2 -3
- package/dist/src/challenge.d.ts.map +1 -1
- package/dist/src/challenge.js +12 -11
- package/dist/src/challenge.js.map +1 -1
- package/dist/src/identity.d.ts +13 -8
- package/dist/src/identity.d.ts.map +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/middleware.d.ts +12 -11
- package/dist/src/middleware.d.ts.map +1 -1
- package/dist/src/middleware.js +118 -44
- package/dist/src/middleware.js.map +1 -1
- package/dist/src/session.d.ts +11 -24
- package/dist/src/session.d.ts.map +1 -1
- package/dist/src/session.js +10 -30
- package/dist/src/session.js.map +1 -1
- package/package.json +3 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tru.d.ts","sourceRoot":"","sources":["../../bin/tru.ts"],"names":[],"mappings":""}
|
package/dist/bin/tru.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { runInit } from '../src/init/index.js';
|
|
3
|
+
const args = process.argv.slice(2);
|
|
4
|
+
const command = args[0];
|
|
5
|
+
if (!command || command === 'init') {
|
|
6
|
+
runInit().catch((err) => {
|
|
7
|
+
console.error('Error:', err.message);
|
|
8
|
+
process.exit(1);
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
else if (command === '--help' || command === '-h') {
|
|
12
|
+
console.log(`
|
|
13
|
+
tru-402 — One-line middleware for agent commerce
|
|
14
|
+
|
|
15
|
+
Usage:
|
|
16
|
+
npx tru-402 init Install tru-402 + MCP server, then set up via your AI assistant
|
|
17
|
+
|
|
18
|
+
Options:
|
|
19
|
+
--help, -h Show this help message
|
|
20
|
+
--version, -v Show version
|
|
21
|
+
|
|
22
|
+
Learn more: https://tru.so/docs
|
|
23
|
+
`);
|
|
24
|
+
}
|
|
25
|
+
else if (command === '--version' || command === '-v') {
|
|
26
|
+
const { readFileSync } = await import('fs');
|
|
27
|
+
const { resolve, dirname } = await import('path');
|
|
28
|
+
const { fileURLToPath } = await import('url');
|
|
29
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
30
|
+
const pkg = JSON.parse(readFileSync(resolve(__dirname, '../../package.json'), 'utf-8'));
|
|
31
|
+
console.log(pkg.version);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
console.error(`Unknown command: ${command}`);
|
|
35
|
+
console.error('Run `npx tru-402 --help` for usage.');
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=tru.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tru.js","sourceRoot":"","sources":["../../bin/tru.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACnC,MAAM,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;AAExB,IAAI,CAAC,OAAO,IAAI,OAAO,KAAK,MAAM,EAAE,CAAC;IACnC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;QACtB,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;QACrC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;AACL,CAAC;KAAM,IAAI,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;IACpD,OAAO,CAAC,GAAG,CAAC;;;;;;;;;;;CAWb,CAAC,CAAC;AACH,CAAC;KAAM,IAAI,OAAO,KAAK,WAAW,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;IACvD,MAAM,EAAE,YAAY,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,CAAC;IAC5C,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,CAAC;IAClD,MAAM,EAAE,aAAa,EAAE,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC,CAAC;IAC9C,MAAM,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAC1D,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC,SAAS,EAAE,oBAAoB,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;IACxF,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AAC3B,CAAC;KAAM,CAAC;IACN,OAAO,CAAC,KAAK,CAAC,oBAAoB,OAAO,EAAE,CAAC,CAAC;IAC7C,OAAO,CAAC,KAAK,CAAC,qCAAqC,CAAC,CAAC;IACrD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC"}
|
package/dist/src/challenge.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TruConfig } from './identity.js';
|
|
2
2
|
export interface ChallengeParams {
|
|
3
3
|
options: {
|
|
4
4
|
amount: number;
|
|
5
5
|
currency?: string;
|
|
6
6
|
description?: string;
|
|
7
|
-
dailyCap?: number;
|
|
8
7
|
};
|
|
9
|
-
config:
|
|
8
|
+
config: TruConfig;
|
|
10
9
|
requestUrl: string;
|
|
11
10
|
}
|
|
12
11
|
export interface ChallengeResponse {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"challenge.d.ts","sourceRoot":"","sources":["../../src/challenge.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"challenge.d.ts","sourceRoot":"","sources":["../../src/challenge.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAa/C,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACrE,MAAM,EAAE,SAAS,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,iBAAiB;IAChC,oCAAoC;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,qCAAqC;IACrC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,eAAe,GAAG,iBAAiB,CAuE5E"}
|
package/dist/src/challenge.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import crypto from 'crypto';
|
|
2
2
|
/**
|
|
3
|
-
* Encode a JSON object to base64url (
|
|
3
|
+
* Encode a JSON object to base64url (base64url-encoded encoding).
|
|
4
4
|
*/
|
|
5
5
|
function toBase64Url(obj) {
|
|
6
6
|
return Buffer.from(JSON.stringify(obj))
|
|
@@ -19,19 +19,19 @@ export function generateChallenge(params) {
|
|
|
19
19
|
const amountDollars = options.amount;
|
|
20
20
|
const currency = options.currency || 'usd';
|
|
21
21
|
const expires = new Date(Date.now() + 5 * 60 * 1000).toISOString(); // 5 min
|
|
22
|
-
//
|
|
22
|
+
// base64url-encoded encoding
|
|
23
23
|
const request = toBase64Url({
|
|
24
24
|
amount: String(amountDollars),
|
|
25
25
|
currency,
|
|
26
26
|
url: requestUrl,
|
|
27
27
|
});
|
|
28
|
-
const realm = config.serviceName || config.appId;
|
|
28
|
+
const realm = config.serviceName || config.appId || 'tru';
|
|
29
29
|
// WWW-Authenticate header
|
|
30
30
|
const header = `Payment id="${challengeId}", realm="${realm}", method="tru", intent="charge", request="${request}", expires="${expires}"`;
|
|
31
31
|
// Self-documenting body
|
|
32
32
|
const body = {
|
|
33
33
|
error: 'payment_required',
|
|
34
|
-
message: `This API costs $${amountDollars.toFixed(2)} per request.
|
|
34
|
+
message: `This API costs $${amountDollars.toFixed(2)} per request. Calls draw from your prepaid tru balance — top up once, call many times. When the balance runs low, this endpoint returns a 402 with a top_up_url so the agent can prompt the user to add more funds.`,
|
|
35
35
|
amount: amountDollars,
|
|
36
36
|
currency,
|
|
37
37
|
description: options.description || undefined,
|
|
@@ -41,7 +41,7 @@ export function generateChallenge(params) {
|
|
|
41
41
|
step_1_note: 'Creates a login session. Response: { code, login_url }',
|
|
42
42
|
step_2: 'Open login_url in the user\'s browser so they can sign in or create an account (Stripe Link — about 10 seconds).',
|
|
43
43
|
step_3: `Poll GET ${config.apiUrl}/api/auth/session/{code} every 2s until status is "complete". Response: { status: "complete", token: "<jwt>", user: { email: "..." } }`,
|
|
44
|
-
step_4: `POST ${config.apiUrl}/api/
|
|
44
|
+
step_4: `POST ${config.apiUrl}/api/tru-402/resolve-challenge with Authorization: Bearer <token> header`,
|
|
45
45
|
step_4_body: {
|
|
46
46
|
challenge: {
|
|
47
47
|
id: challengeId,
|
|
@@ -66,13 +66,14 @@ export function generateChallenge(params) {
|
|
|
66
66
|
expires,
|
|
67
67
|
},
|
|
68
68
|
};
|
|
69
|
-
//
|
|
70
|
-
|
|
69
|
+
// Prepaid balance billing info. Users top up a per-(user, app)
|
|
70
|
+
// balance in their tru wallet and every request atomically deducts
|
|
71
|
+
// from it. When empty, the next request gets another 402 with a
|
|
72
|
+
// top_up_url so the agent can prompt for more funds.
|
|
71
73
|
body.billing = {
|
|
72
|
-
model: '
|
|
73
|
-
message:
|
|
74
|
-
|
|
75
|
-
subsequent_requests: 'After your first payment, the response includes an X-Tru-Token header. Send it on subsequent requests — no re-auth needed.',
|
|
74
|
+
model: 'prepaid_balance',
|
|
75
|
+
message: 'Calls are debited from your prepaid tru balance. When the balance runs low, this endpoint returns another 402 with a top_up_url — the agent walks the user through adding more funds, then retries.',
|
|
76
|
+
subsequent_requests: 'After your first payment, the response includes an X-Tru-Token header. Send it on subsequent requests — no re-auth needed for 24 hours.',
|
|
76
77
|
};
|
|
77
78
|
return { header, body };
|
|
78
79
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"challenge.js","sourceRoot":"","sources":["../../src/challenge.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAG5B;;GAEG;AACH,SAAS,WAAW,CAAC,GAA4B;IAC/C,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;SACpC,QAAQ,CAAC,QAAQ,CAAC;SAClB,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;SACnB,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;SACnB,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AACxB,CAAC;AAeD;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAAuB;IACvD,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC;IAC/C,MAAM,WAAW,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC;IACxC,MAAM,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC;IACrC,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,KAAK,CAAC;IAC3C,MAAM,OAAO,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,QAAQ;IAE5E,
|
|
1
|
+
{"version":3,"file":"challenge.js","sourceRoot":"","sources":["../../src/challenge.ts"],"names":[],"mappings":"AAAA,OAAO,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,qNAAqN;QACzQ,MAAM,EAAE,aAAa;QACrB,QAAQ;QACR,WAAW,EAAE,OAAO,CAAC,WAAW,IAAI,SAAS;QAE7C,UAAU,EAAE;YACV,MAAM,EAAE,QAAQ,MAAM,CAAC,MAAM,mBAAmB;YAChD,WAAW,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE;YAC3B,WAAW,EAAE,wDAAwD;YACrE,MAAM,EAAE,kHAAkH;YAC1H,MAAM,EAAE,YAAY,MAAM,CAAC,MAAM,wIAAwI;YACzK,MAAM,EAAE,QAAQ,MAAM,CAAC,MAAM,0EAA0E;YACvG,WAAW,EAAE;gBACX,SAAS,EAAE;oBACT,EAAE,EAAE,WAAW;oBACf,KAAK;oBACL,MAAM,EAAE,KAAK;oBACb,MAAM,EAAE,QAAQ;oBAChB,OAAO;oBACP,OAAO;iBACR;gBACD,KAAK,EAAE,0BAA0B;aAClC;YACD,WAAW,EAAE,kEAAkE;YAC/E,MAAM,EAAE,yEAAyE;YACjF,WAAW,EAAE,mFAAmF;SACjG;QAED,SAAS,EAAE;YACT,EAAE,EAAE,WAAW;YACf,KAAK;YACL,MAAM,EAAE,KAAK;YACb,MAAM,EAAE,QAAQ;YAChB,OAAO;YACP,OAAO;SACR;KACF,CAAC;IAEF,+DAA+D;IAC/D,mEAAmE;IACnE,gEAAgE;IAChE,qDAAqD;IACrD,IAAI,CAAC,OAAO,GAAG;QACb,KAAK,EAAE,iBAAiB;QACxB,OAAO,EAAE,qMAAqM;QAC9M,mBAAmB,EAAE,yIAAyI;KAC/J,CAAC;IAEF,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;AAC1B,CAAC"}
|
package/dist/src/identity.d.ts
CHANGED
|
@@ -15,23 +15,28 @@ export interface TruIdentity {
|
|
|
15
15
|
* Amount can be a fixed number or a function that calculates price from the request.
|
|
16
16
|
*
|
|
17
17
|
* Examples:
|
|
18
|
-
*
|
|
19
|
-
*
|
|
18
|
+
* tru({ amount: 0.002 })
|
|
19
|
+
* tru({ amount: (req) => req.body.model === 'premium' ? 0.01 : 0.002 })
|
|
20
20
|
*/
|
|
21
|
-
export type
|
|
22
|
-
export interface
|
|
23
|
-
amount:
|
|
21
|
+
export type TruAmount = number | ((req: any) => number | Promise<number>);
|
|
22
|
+
export interface TruOptions {
|
|
23
|
+
amount: TruAmount;
|
|
24
24
|
currency?: string;
|
|
25
25
|
description?: string;
|
|
26
|
-
dailyCap?: number;
|
|
27
26
|
passthrough?: (req: any) => boolean;
|
|
28
27
|
}
|
|
29
28
|
/**
|
|
30
29
|
* Internal config resolved from env vars.
|
|
30
|
+
*
|
|
31
|
+
* As of tru-402 0.7.0, TRU_APP_ID is OPTIONAL. The server derives
|
|
32
|
+
* the app from TRU_API_KEY, and this middleware binds its HMAC
|
|
33
|
+
* tokens to a stable key derived from the apiKey itself when
|
|
34
|
+
* appId isn't set. Providing appId is still supported for
|
|
35
|
+
* backward compatibility.
|
|
31
36
|
*/
|
|
32
|
-
export interface
|
|
33
|
-
appId: string;
|
|
37
|
+
export interface TruConfig {
|
|
34
38
|
apiKey: string;
|
|
39
|
+
appId?: string;
|
|
35
40
|
apiUrl: string;
|
|
36
41
|
appSecret?: string;
|
|
37
42
|
serviceName?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../../src/identity.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;GAMG;AACH,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../../src/identity.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;GAMG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,KAAK,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;AAE1E,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,SAAS,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,OAAO,CAAC;CACrC;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAGD,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,OAAO,CAAC;QAChB,UAAU,OAAO;YACf,GAAG,CAAC,EAAE,WAAW,CAAC;SACnB;KACF;CACF"}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { createMiddleware as tru } from './middleware.js';
|
|
2
|
-
export type { TruIdentity,
|
|
2
|
+
export type { TruIdentity, TruOptions, TruConfig } from './identity.js';
|
|
3
3
|
export { generateChallenge } from './challenge.js';
|
|
4
4
|
export { recordUsage } from './session.js';
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,IAAI,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAC1D,YAAY,EAAE,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,IAAI,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAC1D,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/src/middleware.d.ts
CHANGED
|
@@ -1,30 +1,31 @@
|
|
|
1
1
|
import type { Request, Response, NextFunction } from 'express';
|
|
2
|
-
import type {
|
|
2
|
+
import type { TruOptions } from './identity.js';
|
|
3
3
|
/**
|
|
4
|
-
* Create the
|
|
4
|
+
* Create the tru Express middleware.
|
|
5
5
|
*
|
|
6
|
-
* Flow (identity-first):
|
|
6
|
+
* Flow (identity-first, debit-then-refund):
|
|
7
7
|
* 1. Existing auth (API keys, sessions) → pass through
|
|
8
|
-
* 2. Identify user: X-Tru-Token
|
|
8
|
+
* 2. Identify user: X-Tru-Token verification
|
|
9
9
|
* 3. No identity → 402 with self-documenting payment instructions
|
|
10
10
|
* 4. Identity found → resolve amount (can be async, has access to req.tru)
|
|
11
|
-
* 5. Amount = 0 → free request, identity verified, no charge
|
|
12
|
-
* 6. Amount > 0 →
|
|
11
|
+
* 5. Amount = 0 → free request, identity verified, no charge, no refund hook
|
|
12
|
+
* 6. Amount > 0 → pre-handler debit via recordUsage; on handler error (4xx/5xx)
|
|
13
|
+
* res.on('finish') fires a refund so the deduction is reversed.
|
|
13
14
|
*
|
|
14
15
|
* Usage:
|
|
15
16
|
* ```
|
|
16
17
|
* // Fixed price
|
|
17
|
-
* app.post('/api/generate',
|
|
18
|
+
* app.post('/api/generate', tru({ amount: 0.002 }), handler);
|
|
18
19
|
*
|
|
19
20
|
* // Free credits then pay (identity-first)
|
|
20
|
-
* app.post('/api/generate',
|
|
21
|
+
* app.post('/api/generate', tru({
|
|
21
22
|
* amount: async (req) => {
|
|
22
|
-
* if (!req.tru) return 0.
|
|
23
|
+
* if (!req.tru) return 0.002; // price shown in 402 challenge
|
|
23
24
|
* const user = await db.getUser(req.tru.email);
|
|
24
|
-
* return user?.credits > 0 ? 0 : 0.
|
|
25
|
+
* return user?.credits > 0 ? 0 : 0.002;
|
|
25
26
|
* }
|
|
26
27
|
* }), handler);
|
|
27
28
|
* ```
|
|
28
29
|
*/
|
|
29
|
-
export declare function createMiddleware(options:
|
|
30
|
+
export declare function createMiddleware(options: TruOptions): (req: Request, res: Response, next: NextFunction) => Promise<void | Response<any, Record<string, any>>>;
|
|
30
31
|
//# sourceMappingURL=middleware.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/middleware.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/middleware.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,KAAK,EAAE,UAAU,EAAa,MAAM,eAAe,CAAC;AAuI3D;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,UAAU,IACpC,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,wDAyH9D"}
|
package/dist/src/middleware.js
CHANGED
|
@@ -2,22 +2,40 @@ import crypto from 'crypto';
|
|
|
2
2
|
import { generateChallenge } from './challenge.js';
|
|
3
3
|
import { recordUsage } from './session.js';
|
|
4
4
|
/**
|
|
5
|
-
* Resolve
|
|
5
|
+
* Resolve tru config from environment variables.
|
|
6
|
+
*
|
|
7
|
+
* As of 0.7.0, only TRU_API_KEY is required. TRU_APP_ID is optional —
|
|
8
|
+
* the server derives the app from the API key, and this middleware
|
|
9
|
+
* binds its HMAC tokens to a stable key derived from the apiKey
|
|
10
|
+
* itself when appId isn't set. TRU_APP_SECRET is also optional but
|
|
11
|
+
* recommended (better key rotation story).
|
|
6
12
|
*/
|
|
7
13
|
function resolveConfig() {
|
|
8
|
-
const appId = process.env.TRU_APP_ID;
|
|
9
14
|
const apiKey = process.env.TRU_API_KEY;
|
|
10
|
-
if (!
|
|
11
|
-
throw new Error('tru-402:
|
|
15
|
+
if (!apiKey) {
|
|
16
|
+
throw new Error('tru-402: TRU_API_KEY environment variable is required. Run `npx tru-402 init` to set it up.');
|
|
12
17
|
}
|
|
13
18
|
return {
|
|
14
|
-
appId,
|
|
15
19
|
apiKey,
|
|
20
|
+
appId: process.env.TRU_APP_ID, // optional
|
|
16
21
|
apiUrl: process.env.TRU_API_URL || 'https://tru.so',
|
|
17
22
|
appSecret: process.env.TRU_APP_SECRET,
|
|
18
23
|
serviceName: process.env.TRU_SERVICE_NAME,
|
|
19
24
|
};
|
|
20
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Derive a stable binding identifier for HMAC token payloads. Prefers
|
|
28
|
+
* the explicit appId when set (backward compatibility with 0.6.x), but
|
|
29
|
+
* falls back to a deterministic slice of the apiKey so every token
|
|
30
|
+
* stays tied to this specific app even without TRU_APP_ID.
|
|
31
|
+
*/
|
|
32
|
+
function getTokenBindingId(config) {
|
|
33
|
+
if (config.appId)
|
|
34
|
+
return config.appId;
|
|
35
|
+
// API keys look like tru_ak_<hex>. The prefix is the first 15 chars
|
|
36
|
+
// (`tru_ak_` + 8 hex), which is unique per app and stable.
|
|
37
|
+
return config.apiKey.slice(0, 15);
|
|
38
|
+
}
|
|
21
39
|
// Lazy-loaded config singleton
|
|
22
40
|
let _config = null;
|
|
23
41
|
function getConfig() {
|
|
@@ -33,7 +51,7 @@ function getConfig() {
|
|
|
33
51
|
function generateTruToken(email, config) {
|
|
34
52
|
const secret = config.appSecret || config.apiKey;
|
|
35
53
|
const date = new Date().toISOString().slice(0, 10); // YYYY-MM-DD
|
|
36
|
-
const payload = `${email}:${date}:${config
|
|
54
|
+
const payload = `${email}:${date}:${getTokenBindingId(config)}`;
|
|
37
55
|
const hmac = crypto.createHmac('sha256', secret).update(payload).digest('hex').slice(0, 32);
|
|
38
56
|
return `${email}:${date}:${hmac}`;
|
|
39
57
|
}
|
|
@@ -56,9 +74,11 @@ function verifyTruToken(token, config) {
|
|
|
56
74
|
const ageMs = now.getTime() - tokenDate.getTime();
|
|
57
75
|
if (ageMs < 0 || ageMs > 25 * 60 * 60 * 1000)
|
|
58
76
|
return null; // >25h (24h + 1h timezone grace)
|
|
59
|
-
// Verify HMAC (uses appSecret, falls back to apiKey for backward compat)
|
|
77
|
+
// Verify HMAC (uses appSecret, falls back to apiKey for backward compat).
|
|
78
|
+
// The binding id matches whatever `generateTruToken` used at mint time:
|
|
79
|
+
// TRU_APP_ID if set, otherwise a stable slice of the apiKey.
|
|
60
80
|
const secret = config.appSecret || config.apiKey;
|
|
61
|
-
const payload = `${email}:${date}:${config
|
|
81
|
+
const payload = `${email}:${date}:${getTokenBindingId(config)}`;
|
|
62
82
|
const expected = crypto.createHmac('sha256', secret).update(payload).digest('hex').slice(0, 32);
|
|
63
83
|
if (!crypto.timingSafeEqual(Buffer.from(hmac), Buffer.from(expected)))
|
|
64
84
|
return null;
|
|
@@ -81,27 +101,49 @@ function hasExistingAuth(req, options) {
|
|
|
81
101
|
return false;
|
|
82
102
|
}
|
|
83
103
|
/**
|
|
84
|
-
*
|
|
104
|
+
* Fire-and-forget refund call. The usage row was debited pre-handler; if the
|
|
105
|
+
* developer's handler returned a 4xx/5xx we reverse the deduction so errored
|
|
106
|
+
* responses don't charge the user.
|
|
85
107
|
*
|
|
86
|
-
*
|
|
108
|
+
* Intentionally does NOT await / does NOT throw — the response has already been
|
|
109
|
+
* flushed by the time this runs, so any failure just gets logged.
|
|
110
|
+
*/
|
|
111
|
+
function refundUsage(usageId, config) {
|
|
112
|
+
fetch(`${config.apiUrl}/api/tru-402/refund-usage`, {
|
|
113
|
+
method: 'POST',
|
|
114
|
+
headers: {
|
|
115
|
+
'Content-Type': 'application/json',
|
|
116
|
+
'X-API-Key': config.apiKey,
|
|
117
|
+
},
|
|
118
|
+
body: JSON.stringify({ usage_id: usageId }),
|
|
119
|
+
}).catch((err) => {
|
|
120
|
+
// eslint-disable-next-line no-console
|
|
121
|
+
console.error('tru-402: refundUsage failed', { usageId, err: err?.message || err });
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Create the tru Express middleware.
|
|
126
|
+
*
|
|
127
|
+
* Flow (identity-first, debit-then-refund):
|
|
87
128
|
* 1. Existing auth (API keys, sessions) → pass through
|
|
88
|
-
* 2. Identify user: X-Tru-Token
|
|
129
|
+
* 2. Identify user: X-Tru-Token verification
|
|
89
130
|
* 3. No identity → 402 with self-documenting payment instructions
|
|
90
131
|
* 4. Identity found → resolve amount (can be async, has access to req.tru)
|
|
91
|
-
* 5. Amount = 0 → free request, identity verified, no charge
|
|
92
|
-
* 6. Amount > 0 →
|
|
132
|
+
* 5. Amount = 0 → free request, identity verified, no charge, no refund hook
|
|
133
|
+
* 6. Amount > 0 → pre-handler debit via recordUsage; on handler error (4xx/5xx)
|
|
134
|
+
* res.on('finish') fires a refund so the deduction is reversed.
|
|
93
135
|
*
|
|
94
136
|
* Usage:
|
|
95
137
|
* ```
|
|
96
138
|
* // Fixed price
|
|
97
|
-
* app.post('/api/generate',
|
|
139
|
+
* app.post('/api/generate', tru({ amount: 0.002 }), handler);
|
|
98
140
|
*
|
|
99
141
|
* // Free credits then pay (identity-first)
|
|
100
|
-
* app.post('/api/generate',
|
|
142
|
+
* app.post('/api/generate', tru({
|
|
101
143
|
* amount: async (req) => {
|
|
102
|
-
* if (!req.tru) return 0.
|
|
144
|
+
* if (!req.tru) return 0.002; // price shown in 402 challenge
|
|
103
145
|
* const user = await db.getUser(req.tru.email);
|
|
104
|
-
* return user?.credits > 0 ? 0 : 0.
|
|
146
|
+
* return user?.credits > 0 ? 0 : 0.002;
|
|
105
147
|
* }
|
|
106
148
|
* }), handler);
|
|
107
149
|
* ```
|
|
@@ -145,40 +187,72 @@ export function createMiddleware(options) {
|
|
|
145
187
|
throw new Error(`tru-402: invalid amount ${amountDollars} — must be a number from 0 to 9999.99`);
|
|
146
188
|
}
|
|
147
189
|
const amountCents = Math.round(amountDollars * 100);
|
|
148
|
-
|
|
149
|
-
|
|
190
|
+
// 5a. Free request — no debit, no refund hook, just let the handler run.
|
|
191
|
+
if (amountCents === 0) {
|
|
192
|
+
return next();
|
|
193
|
+
}
|
|
194
|
+
// 6. Pre-handler debit. Deduct balance + write usage ledger row atomically.
|
|
195
|
+
// On ok:false (balance_required / insufficient_balance / etc.) return a 402.
|
|
150
196
|
const result = await recordUsage(truUserEmail, amountCents, config, {
|
|
151
197
|
description: options.description,
|
|
152
198
|
agentName,
|
|
153
199
|
endpoint,
|
|
154
|
-
dailyCapCents,
|
|
155
200
|
});
|
|
156
|
-
if (result.ok
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
201
|
+
if (!result.ok || !result.identity) {
|
|
202
|
+
// Usage recording failed — return 402 with a fresh challenge.
|
|
203
|
+
const fallbackAmount = typeof options.amount === 'function'
|
|
204
|
+
? await options.amount(req) : options.amount;
|
|
205
|
+
const requestUrl = `${req.protocol}://${req.get('host')}${req.originalUrl}`;
|
|
206
|
+
const challenge = generateChallenge({
|
|
207
|
+
options: { ...options, amount: Math.max(0, fallbackAmount) },
|
|
208
|
+
config,
|
|
209
|
+
requestUrl,
|
|
210
|
+
});
|
|
211
|
+
// Preserve any extra error context from the server (balance_required,
|
|
212
|
+
// insufficient_balance, top_up_url, balance_cents, needed_cents, etc.)
|
|
213
|
+
const body = { ...challenge.body };
|
|
214
|
+
if (result.error)
|
|
215
|
+
body.error = result.error;
|
|
216
|
+
const extras = result;
|
|
217
|
+
for (const key of ['top_up_url', 'balance_cents', 'needed_cents', 'balance_remaining_cents']) {
|
|
218
|
+
if (extras[key] !== undefined)
|
|
219
|
+
body[key] = extras[key];
|
|
167
220
|
}
|
|
168
|
-
return
|
|
221
|
+
return res.status(402)
|
|
222
|
+
.set('WWW-Authenticate', challenge.header)
|
|
223
|
+
.json(body);
|
|
169
224
|
}
|
|
170
|
-
//
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
225
|
+
// Debit succeeded. Populate identity and surface headers BEFORE calling
|
|
226
|
+
// next() so the developer's handler can proxy them if it wants.
|
|
227
|
+
req.tru = result.identity;
|
|
228
|
+
if (result.limit_warning) {
|
|
229
|
+
res.setHeader('X-Tru-Limit-Warning', JSON.stringify(result.limit_warning));
|
|
230
|
+
}
|
|
231
|
+
if (result.trial_status) {
|
|
232
|
+
res.setHeader('X-Tru-Trial', JSON.stringify(result.trial_status));
|
|
233
|
+
}
|
|
234
|
+
// 7. Wire up the post-handler refund hook. If the response flushes with
|
|
235
|
+
// a 4xx/5xx, reverse the deduction. Covers:
|
|
236
|
+
// - handler calls res.status(500).json(...)
|
|
237
|
+
// - handler throws → Express error handler emits 5xx → finish fires
|
|
238
|
+
// - handler calls next(err) → same as above
|
|
239
|
+
// We listen to both 'finish' and 'close' behind a one-shot flag so we
|
|
240
|
+
// don't double-refund if the socket drops mid-flush.
|
|
241
|
+
const usageId = result.usage_id;
|
|
242
|
+
if (usageId) {
|
|
243
|
+
let refundHandled = false;
|
|
244
|
+
const maybeRefund = () => {
|
|
245
|
+
if (refundHandled)
|
|
246
|
+
return;
|
|
247
|
+
refundHandled = true;
|
|
248
|
+
if (res.statusCode >= 400) {
|
|
249
|
+
refundUsage(usageId, config);
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
res.on('finish', maybeRefund);
|
|
253
|
+
res.on('close', maybeRefund);
|
|
254
|
+
}
|
|
255
|
+
return next();
|
|
182
256
|
}
|
|
183
257
|
catch (err) {
|
|
184
258
|
next(err);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../src/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAG5B,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C
|
|
1
|
+
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../src/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAG5B,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C;;;;;;;;GAQG;AACH,SAAS,aAAa;IACpB,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC;IAEvC,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CACb,6FAA6F,CAC9F,CAAC;IACJ,CAAC;IAED,OAAO;QACL,MAAM;QACN,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,UAAU,EAAG,WAAW;QAC3C,MAAM,EAAE,OAAO,CAAC,GAAG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AC;QACZ,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/src/session.d.ts
CHANGED
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
import type { TruIdentity,
|
|
2
|
-
export interface PlanUpsell {
|
|
3
|
-
name: string;
|
|
4
|
-
price_cents: number;
|
|
5
|
-
interval: string;
|
|
6
|
-
monthly_spend_cents: number;
|
|
7
|
-
credit_cents: number;
|
|
8
|
-
message: string;
|
|
9
|
-
}
|
|
1
|
+
import type { TruIdentity, TruConfig } from './identity.js';
|
|
10
2
|
export interface LimitWarning {
|
|
11
3
|
limit_cents: number;
|
|
12
4
|
spent_cents: number;
|
|
@@ -28,20 +20,22 @@ interface RecordUsageResult {
|
|
|
28
20
|
usage_id?: string;
|
|
29
21
|
identity?: TruIdentity;
|
|
30
22
|
error?: string;
|
|
31
|
-
has_subscription?: boolean;
|
|
32
|
-
plan_upsell?: PlanUpsell;
|
|
33
23
|
limit_warning?: LimitWarning;
|
|
34
24
|
trial_status?: TrialStatus;
|
|
35
25
|
}
|
|
36
26
|
/**
|
|
37
|
-
* Record usage
|
|
38
|
-
*
|
|
27
|
+
* Record usage against the user's prepaid tru balance.
|
|
28
|
+
*
|
|
29
|
+
* No Stripe charge happens here — the user funded their balance
|
|
30
|
+
* earlier via an explicit top-up, and this call atomically deducts
|
|
31
|
+
* from it. When the balance is insufficient, the response carries
|
|
32
|
+
* ok:false with a top_up_url so the caller can return a 402 that
|
|
33
|
+
* prompts the user (or agent) to add more funds.
|
|
39
34
|
*/
|
|
40
|
-
export declare function recordUsage(userEmail: string, amountCents: number, config:
|
|
35
|
+
export declare function recordUsage(userEmail: string, amountCents: number, config: TruConfig, opts?: {
|
|
41
36
|
description?: string;
|
|
42
37
|
agentName?: string;
|
|
43
38
|
endpoint?: string;
|
|
44
|
-
dailyCapCents?: number;
|
|
45
39
|
}): Promise<RecordUsageResult>;
|
|
46
40
|
interface SessionDebitResult {
|
|
47
41
|
ok: boolean;
|
|
@@ -50,15 +44,8 @@ interface SessionDebitResult {
|
|
|
50
44
|
error?: string;
|
|
51
45
|
}
|
|
52
46
|
/**
|
|
53
|
-
* Debit from an existing
|
|
54
|
-
*/
|
|
55
|
-
export declare function debitSession(sessionId: string, amountCents: number, config: TruxConfig): Promise<SessionDebitResult>;
|
|
56
|
-
/**
|
|
57
|
-
* Create a new trux session after initial 402 resolution.
|
|
47
|
+
* Debit from an existing tru session.
|
|
58
48
|
*/
|
|
59
|
-
export declare function
|
|
60
|
-
sessionId: string;
|
|
61
|
-
expiresAt: string;
|
|
62
|
-
} | null>;
|
|
49
|
+
export declare function debitSession(sessionId: string, amountCents: number, config: TruConfig): Promise<SessionDebitResult>;
|
|
63
50
|
export {};
|
|
64
51
|
//# sourceMappingURL=session.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/session.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/session.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAI5D,MAAM,WAAW,YAAY;IAC3B,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;IACxB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,SAAS,EAAE,OAAO,CAAC;CACpB;AAED,UAAU,iBAAiB;IACzB,EAAE,EAAE,OAAO,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,WAAW,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,aAAa,CAAC,EAAE,YAAY,CAAC;IAC7B,YAAY,CAAC,EAAE,WAAW,CAAC;CAC5B;AAED;;;;;;;;GAQG;AACH,wBAAsB,WAAW,CAC/B,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,SAAS,EACjB,IAAI,CAAC,EAAE;IAAE,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,GACrE,OAAO,CAAC,iBAAiB,CAAC,CAqC5B;AAID,UAAU,kBAAkB;IAC1B,EAAE,EAAE,OAAO,CAAC;IACZ,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,EAAE,WAAW,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,wBAAsB,YAAY,CAChC,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,SAAS,GAChB,OAAO,CAAC,kBAAkB,CAAC,CAiC7B"}
|
package/dist/src/session.js
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Record usage
|
|
3
|
-
*
|
|
2
|
+
* Record usage against the user's prepaid tru balance.
|
|
3
|
+
*
|
|
4
|
+
* No Stripe charge happens here — the user funded their balance
|
|
5
|
+
* earlier via an explicit top-up, and this call atomically deducts
|
|
6
|
+
* from it. When the balance is insufficient, the response carries
|
|
7
|
+
* ok:false with a top_up_url so the caller can return a 402 that
|
|
8
|
+
* prompts the user (or agent) to add more funds.
|
|
4
9
|
*/
|
|
5
10
|
export async function recordUsage(userEmail, amountCents, config, opts) {
|
|
6
|
-
const res = await fetch(`${config.apiUrl}/api/
|
|
11
|
+
const res = await fetch(`${config.apiUrl}/api/tru-402/usage`, {
|
|
7
12
|
method: 'POST',
|
|
8
13
|
headers: {
|
|
9
14
|
'Content-Type': 'application/json',
|
|
@@ -15,7 +20,6 @@ export async function recordUsage(userEmail, amountCents, config, opts) {
|
|
|
15
20
|
description: opts?.description,
|
|
16
21
|
agent_name: opts?.agentName,
|
|
17
22
|
endpoint: opts?.endpoint,
|
|
18
|
-
daily_cap_cents: opts?.dailyCapCents,
|
|
19
23
|
}),
|
|
20
24
|
});
|
|
21
25
|
const data = await res.json();
|
|
@@ -25,8 +29,6 @@ export async function recordUsage(userEmail, amountCents, config, opts) {
|
|
|
25
29
|
return {
|
|
26
30
|
ok: true,
|
|
27
31
|
usage_id: data.usage_id,
|
|
28
|
-
has_subscription: data.has_subscription || false,
|
|
29
|
-
plan_upsell: data.plan_upsell || undefined,
|
|
30
32
|
limit_warning: data.limit_warning || undefined,
|
|
31
33
|
trial_status: data.trial_status || undefined,
|
|
32
34
|
identity: data.identity ? {
|
|
@@ -41,10 +43,10 @@ export async function recordUsage(userEmail, amountCents, config, opts) {
|
|
|
41
43
|
};
|
|
42
44
|
}
|
|
43
45
|
/**
|
|
44
|
-
* Debit from an existing
|
|
46
|
+
* Debit from an existing tru session.
|
|
45
47
|
*/
|
|
46
48
|
export async function debitSession(sessionId, amountCents, config) {
|
|
47
|
-
const res = await fetch(`${config.apiUrl}/api/
|
|
49
|
+
const res = await fetch(`${config.apiUrl}/api/tru-402/session-debit`, {
|
|
48
50
|
method: 'POST',
|
|
49
51
|
headers: {
|
|
50
52
|
'Content-Type': 'application/json',
|
|
@@ -74,26 +76,4 @@ export async function debitSession(sessionId, amountCents, config) {
|
|
|
74
76
|
} : undefined,
|
|
75
77
|
};
|
|
76
78
|
}
|
|
77
|
-
/**
|
|
78
|
-
* Create a new trux session after initial 402 resolution.
|
|
79
|
-
*/
|
|
80
|
-
export async function createSession(userEmail, budgetCents, chargeRequestId, stripeSptId, agentName, config) {
|
|
81
|
-
const res = await fetch(`${config.apiUrl}/api/mpp/sessions`, {
|
|
82
|
-
method: 'POST',
|
|
83
|
-
headers: {
|
|
84
|
-
'Content-Type': 'application/json',
|
|
85
|
-
'X-API-Key': config.apiKey,
|
|
86
|
-
},
|
|
87
|
-
body: JSON.stringify({
|
|
88
|
-
user_email: userEmail,
|
|
89
|
-
budget_cents: budgetCents,
|
|
90
|
-
charge_request_id: chargeRequestId,
|
|
91
|
-
stripe_spt_id: stripeSptId,
|
|
92
|
-
agent_name: agentName,
|
|
93
|
-
}),
|
|
94
|
-
});
|
|
95
|
-
if (!res.ok)
|
|
96
|
-
return null;
|
|
97
|
-
return res.json();
|
|
98
|
-
}
|
|
99
79
|
//# sourceMappingURL=session.js.map
|
package/dist/src/session.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/session.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/session.ts"],"names":[],"mappings":"AA+BA;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,SAAiB,EACjB,WAAmB,EACnB,MAAiB,EACjB,IAAsE;IAEtE,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,MAAM,CAAC,MAAM,oBAAoB,EAAE;QAC5D,MAAM,EAAE,MAAM;QACd,OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;YAClC,WAAW,EAAE,MAAM,CAAC,MAAM;SAC3B;QACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;YACnB,UAAU,EAAE,SAAS;YACrB,YAAY,EAAE,WAAW;YACzB,WAAW,EAAE,IAAI,EAAE,WAAW;YAC9B,UAAU,EAAE,IAAI,EAAE,SAAS;YAC3B,QAAQ,EAAE,IAAI,EAAE,QAAQ;SACzB,CAAC;KACH,CAAC,CAAC;IAEH,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,IAAI,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AC;KACH,CAAC,CAAC;IAEH,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;IAE9B,IAAI,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC;QACxB,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,QAAQ,GAAG,CAAC,MAAM,EAAE,EAAE,CAAC;IAClE,CAAC;IAED,OAAO;QACL,EAAE,EAAE,IAAI;QACR,eAAe,EAAE,IAAI,CAAC,eAAe;QACrC,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;YACxB,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,KAAK;YAC1B,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI;YACxB,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,MAAM;YAC5B,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,SAAS;YAClC,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,SAAS;YAClC,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,SAAS;YAClC,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,QAAQ;YAChC,SAAS;SACV,CAAC,CAAC,CAAC,SAAS;KACd,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tru-402",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "One-line middleware for agent commerce.
|
|
3
|
+
"version": "0.7.0",
|
|
4
|
+
"description": "One-line Express middleware for agent commerce. Wrap paid endpoints; unauthenticated requests get a self-documenting 402 that tells agents how to authenticate and pay.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
|
-
"tru-402": "dist/bin/
|
|
7
|
+
"tru-402": "dist/bin/tru.js"
|
|
8
8
|
},
|
|
9
9
|
"exports": {
|
|
10
10
|
".": "./dist/src/index.js"
|
|
@@ -34,7 +34,6 @@
|
|
|
34
34
|
"402",
|
|
35
35
|
"payment",
|
|
36
36
|
"tru",
|
|
37
|
-
"mpp",
|
|
38
37
|
"stripe",
|
|
39
38
|
"express"
|
|
40
39
|
],
|