@curless/agentbank-core 0.0.2 → 0.1.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/encoding.d.ts +4 -0
- package/dist/encoding.d.ts.map +1 -0
- package/dist/encoding.js +30 -0
- package/dist/encoding.js.map +1 -0
- package/dist/errors.d.ts +1 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +12 -0
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +8 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encoding.d.ts","sourceRoot":"","sources":["../src/encoding.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,QAAQ,GAAI,GAAG,MAAM,KAAG,MAMpC,CAAC;AAGF,eAAO,MAAM,WAAW,GAAI,GAAG,MAAM,KAAG,MACgC,CAAC;AAKzE,eAAO,MAAM,UAAU,GAAI,KAAK,MAAM,KAAG,MAMxC,CAAC"}
|
package/dist/encoding.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Portable base64 / base64url for every runtime the SDKs target: Node has
|
|
2
|
+
// Buffer; Workers / Deno / edge have atob + btoa + TextEncoder/Decoder. One
|
|
3
|
+
// implementation here so the buyer / merchant / protocol packages encode
|
|
4
|
+
// identically instead of each shipping its own guarded copy (which is how
|
|
5
|
+
// protocols-sdk ended up with an unguarded Buffer that crashed on Workers).
|
|
6
|
+
const hasBuffer = typeof Buffer !== 'undefined';
|
|
7
|
+
// utf8 string → standard base64.
|
|
8
|
+
export const toBase64 = (s) => {
|
|
9
|
+
if (hasBuffer)
|
|
10
|
+
return Buffer.from(s, 'utf8').toString('base64');
|
|
11
|
+
const bytes = new TextEncoder().encode(s);
|
|
12
|
+
let bin = '';
|
|
13
|
+
for (const b of bytes)
|
|
14
|
+
bin += String.fromCharCode(b);
|
|
15
|
+
return btoa(bin);
|
|
16
|
+
};
|
|
17
|
+
// utf8 string → base64url, unpadded — for tokens and wire credentials.
|
|
18
|
+
export const toBase64Url = (s) => toBase64(s).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
|
|
19
|
+
// base64 (standard OR url-safe) → utf8 string. Throws on malformed input on
|
|
20
|
+
// edge runtimes (atob); Node's Buffer is lenient, matching the prior per-
|
|
21
|
+
// package behaviour. Accepting url-safe input too means one decoder for both.
|
|
22
|
+
export const fromBase64 = (b64) => {
|
|
23
|
+
const std = b64.replace(/-/g, '+').replace(/_/g, '/');
|
|
24
|
+
if (hasBuffer)
|
|
25
|
+
return Buffer.from(std, 'base64').toString('utf8');
|
|
26
|
+
const bin = atob(std);
|
|
27
|
+
const bytes = Uint8Array.from(bin, (ch) => ch.charCodeAt(0));
|
|
28
|
+
return new TextDecoder().decode(bytes);
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=encoding.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encoding.js","sourceRoot":"","sources":["../src/encoding.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,4EAA4E;AAC5E,yEAAyE;AACzE,0EAA0E;AAC1E,4EAA4E;AAC5E,MAAM,SAAS,GAAG,OAAO,MAAM,KAAK,WAAW,CAAC;AAEhD,iCAAiC;AACjC,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,CAAS,EAAU,EAAE;IAC5C,IAAI,SAAS;QAAE,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAChE,MAAM,KAAK,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC1C,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,KAAK,MAAM,CAAC,IAAI,KAAK;QAAE,GAAG,IAAI,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IACrD,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;AACnB,CAAC,CAAC;AAEF,uEAAuE;AACvE,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAS,EAAU,EAAE,CAC/C,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AAEzE,4EAA4E;AAC5E,0EAA0E;AAC1E,8EAA8E;AAC9E,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,GAAW,EAAU,EAAE;IAChD,MAAM,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IACtD,IAAI,SAAS;QAAE,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAClE,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;IACtB,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7D,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACzC,CAAC,CAAC"}
|
package/dist/errors.d.ts
CHANGED
|
@@ -3,5 +3,6 @@ export declare class AgentbankError extends Error {
|
|
|
3
3
|
readonly code: string;
|
|
4
4
|
readonly details?: unknown;
|
|
5
5
|
constructor(status: number, code: string, message: string, details?: unknown);
|
|
6
|
+
static is(err: unknown): err is AgentbankError;
|
|
6
7
|
}
|
|
7
8
|
//# sourceMappingURL=errors.d.ts.map
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAOA,qBAAa,cAAe,SAAQ,KAAK;IACvC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;gBAEf,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO;
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAOA,qBAAa,cAAe,SAAQ,KAAK;IACvC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;gBAEf,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO;IAc5E,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,cAAc;CAQ/C"}
|
package/dist/errors.js
CHANGED
|
@@ -16,5 +16,17 @@ export class AgentbankError extends Error {
|
|
|
16
16
|
this.code = code;
|
|
17
17
|
this.details = details;
|
|
18
18
|
}
|
|
19
|
+
// Cross-version-safe type guard. `instanceof` silently fails when two copies
|
|
20
|
+
// of @curless/agentbank-core coexist in one node_modules (e.g. a consumer on
|
|
21
|
+
// core@0.1.0 and an SDK that pinned core@0.0.x) — they're different class
|
|
22
|
+
// objects. This checks the shape instead, so an error from ANY core version
|
|
23
|
+
// is recognized. Prefer `AgentbankError.is(err)` over `err instanceof` at
|
|
24
|
+
// package boundaries.
|
|
25
|
+
static is(err) {
|
|
26
|
+
return (err instanceof Error &&
|
|
27
|
+
err.name === 'AgentbankError' &&
|
|
28
|
+
typeof err.code === 'string' &&
|
|
29
|
+
typeof err.status === 'number');
|
|
30
|
+
}
|
|
19
31
|
}
|
|
20
32
|
//# sourceMappingURL=errors.js.map
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,qEAAqE;AACrE,sDAAsD;AACtD,EAAE;AACF,wEAAwE;AACxE,wEAAwE;AACxE,qDAAqD;AACrD,MAAM,OAAO,cAAe,SAAQ,KAAK;IAC9B,MAAM,CAAS;IACf,IAAI,CAAS;IACb,OAAO,CAAW;IAE3B,YAAY,MAAc,EAAE,IAAY,EAAE,OAAe,EAAE,OAAiB;QAC1E,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;QAC7B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;CACF"}
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,qEAAqE;AACrE,sDAAsD;AACtD,EAAE;AACF,wEAAwE;AACxE,wEAAwE;AACxE,qDAAqD;AACrD,MAAM,OAAO,cAAe,SAAQ,KAAK;IAC9B,MAAM,CAAS;IACf,IAAI,CAAS;IACb,OAAO,CAAW;IAE3B,YAAY,MAAc,EAAE,IAAY,EAAE,OAAe,EAAE,OAAiB;QAC1E,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;QAC7B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,6EAA6E;IAC7E,6EAA6E;IAC7E,0EAA0E;IAC1E,4EAA4E;IAC5E,0EAA0E;IAC1E,sBAAsB;IACtB,MAAM,CAAC,EAAE,CAAC,GAAY;QACpB,OAAO,CACL,GAAG,YAAY,KAAK;YACpB,GAAG,CAAC,IAAI,KAAK,gBAAgB;YAC7B,OAAQ,GAA+B,CAAC,IAAI,KAAK,QAAQ;YACzD,OAAQ,GAA+B,CAAC,MAAM,KAAK,QAAQ,CAC5D,CAAC;IACJ,CAAC;CACF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { hmacSha256Hex, randomHex, timingSafeEqualHex } from './crypto.js';
|
|
2
|
+
export { fromBase64, toBase64, toBase64Url } from './encoding.js';
|
|
2
3
|
export { AgentbankError } from './errors.js';
|
|
3
4
|
export { type FetchLike, type RequestOptions, buildUrl, sendJson, toError } from './http.js';
|
|
4
5
|
export type { BalanceTransaction, Customer, CustomerStatus, LedgerEntryView, Paginated, PaymentIntent, PaymentIntentLedger, PaymentIntentStatus, PaymentLink, PaymentLinkItem, PaymentLinkStatus, PaymentProtocol, } from './types.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,cAAc,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7F,YAAY,EACV,kBAAkB,EAClB,QAAQ,EACR,cAAc,EACd,eAAe,EACf,SAAS,EACT,aAAa,EACb,mBAAmB,EACnB,mBAAmB,EACnB,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,eAAe,GAChB,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAC3E,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,cAAc,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7F,YAAY,EACV,kBAAkB,EAClB,QAAQ,EACR,cAAc,EACd,eAAe,EACf,SAAS,EACT,aAAa,EACb,mBAAmB,EACnB,mBAAmB,EACnB,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,eAAe,GAChB,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// there's one implementation: one crypto path, one error class, one HTTP +
|
|
4
4
|
// type surface.
|
|
5
5
|
export { hmacSha256Hex, randomHex, timingSafeEqualHex } from './crypto.js';
|
|
6
|
+
export { fromBase64, toBase64, toBase64Url } from './encoding.js';
|
|
6
7
|
export { AgentbankError } from './errors.js';
|
|
7
8
|
export { buildUrl, sendJson, toError } from './http.js';
|
|
8
9
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,4EAA4E;AAC5E,2EAA2E;AAC3E,gBAAgB;AAChB,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAuC,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,4EAA4E;AAC5E,2EAA2E;AAC3E,gBAAgB;AAChB,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAC3E,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAuC,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@curless/agentbank-core",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Shared runtime primitives for the agentbank SDKs. Edge-safe crypto (Web Crypto API, no node:crypto) so the buyer / merchant / protocol SDKs run unchanged on Node 18+, Vercel Edge, Cloudflare Workers and Deno.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/node": "^22.10.1",
|
|
26
26
|
"typescript": "^5.6.3",
|
|
27
|
-
"vitest": "^2.
|
|
27
|
+
"vitest": "^3.2.6"
|
|
28
28
|
},
|
|
29
29
|
"engines": {
|
|
30
30
|
"node": ">=18"
|
|
@@ -36,6 +36,12 @@
|
|
|
36
36
|
"edge-runtime",
|
|
37
37
|
"hmac"
|
|
38
38
|
],
|
|
39
|
+
"repository": {
|
|
40
|
+
"type": "git",
|
|
41
|
+
"url": "git+https://gitlab.com/robin-ruan/agentbank.git",
|
|
42
|
+
"directory": "packages/core"
|
|
43
|
+
},
|
|
44
|
+
"author": "robin",
|
|
39
45
|
"scripts": {
|
|
40
46
|
"build": "tsc",
|
|
41
47
|
"typecheck": "tsc --noEmit",
|