@aithos/sdk 0.1.0-alpha.4 → 0.1.0-alpha.40

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.
Files changed (62) hide show
  1. package/README.md +211 -7
  2. package/dist/src/assets.d.ts +207 -0
  3. package/dist/src/assets.js +533 -0
  4. package/dist/src/auth-api.d.ts +138 -0
  5. package/dist/src/auth-api.js +168 -0
  6. package/dist/src/auth.d.ts +536 -119
  7. package/dist/src/auth.js +1207 -152
  8. package/dist/src/compute.d.ts +221 -9
  9. package/dist/src/compute.js +293 -16
  10. package/dist/src/data-schema-contacts-v1.d.ts +14 -0
  11. package/dist/src/data-schema-contacts-v1.js +28 -0
  12. package/dist/src/data.d.ts +153 -0
  13. package/dist/src/data.js +670 -0
  14. package/dist/src/endpoints.d.ts +9 -0
  15. package/dist/src/endpoints.js +5 -0
  16. package/dist/src/ethos.d.ts +202 -1
  17. package/dist/src/ethos.js +821 -16
  18. package/dist/src/index.d.ts +16 -6
  19. package/dist/src/index.js +33 -6
  20. package/dist/src/internal/delegate-bundle.d.ts +18 -0
  21. package/dist/src/internal/delegate-bundle.js +94 -0
  22. package/dist/src/internal/delegate-state.d.ts +45 -0
  23. package/dist/src/internal/delegate-state.js +120 -0
  24. package/dist/src/internal/envelope.d.ts +77 -0
  25. package/dist/src/internal/envelope.js +154 -0
  26. package/dist/src/internal/owner-signers.d.ts +78 -0
  27. package/dist/src/internal/owner-signers.js +179 -0
  28. package/dist/src/internal/protocol-client-bridge.d.ts +8 -0
  29. package/dist/src/internal/protocol-client-bridge.js +20 -0
  30. package/dist/src/internal/recovery-file.d.ts +29 -0
  31. package/dist/src/internal/recovery-file.js +98 -0
  32. package/dist/src/internal/signer.d.ts +59 -0
  33. package/dist/src/internal/signer.js +86 -0
  34. package/dist/src/key-store.d.ts +128 -0
  35. package/dist/src/key-store.js +244 -0
  36. package/dist/src/mandates.d.ts +163 -1
  37. package/dist/src/mandates.js +286 -8
  38. package/dist/src/react/AithosAsset.d.ts +66 -0
  39. package/dist/src/react/AithosAsset.js +67 -0
  40. package/dist/src/react/context.d.ts +29 -0
  41. package/dist/src/react/context.js +31 -0
  42. package/dist/src/react/index.d.ts +28 -0
  43. package/dist/src/react/index.js +30 -0
  44. package/dist/src/react/use-aithos-asset.d.ts +39 -0
  45. package/dist/src/react/use-aithos-asset.js +118 -0
  46. package/dist/src/sdk.d.ts +39 -3
  47. package/dist/src/sdk.js +36 -23
  48. package/dist/src/wallet.d.ts +4 -6
  49. package/dist/src/wallet.js +18 -8
  50. package/dist/src/web.d.ts +279 -0
  51. package/dist/src/web.js +186 -0
  52. package/package.json +18 -3
  53. package/dist/test/auth.test.d.ts +0 -2
  54. package/dist/test/auth.test.js +0 -175
  55. package/dist/test/compute.test.d.ts +0 -2
  56. package/dist/test/compute.test.js +0 -179
  57. package/dist/test/endpoints.test.d.ts +0 -2
  58. package/dist/test/endpoints.test.js +0 -43
  59. package/dist/test/sdk.test.d.ts +0 -2
  60. package/dist/test/sdk.test.js +0 -86
  61. package/dist/test/wallet.test.d.ts +0 -2
  62. package/dist/test/wallet.test.js +0 -110
@@ -1,86 +0,0 @@
1
- // SPDX-License-Identifier: Apache-2.0
2
- // Copyright 2026 Mathieu Colla
3
- // Smoke tests for the AithosSDK construction surface.
4
- //
5
- // Runtime tests of `compute.invokeBedrock` and `wallet.createTopupSession`
6
- // require either a running compute proxy or a more elaborate fetch mock
7
- // pattern; we land them in a follow-up commit alongside the rest of Phase 4
8
- // (mock-fetch unit tests for both namespaces).
9
- import { strict as assert } from "node:assert";
10
- import { describe, it } from "node:test";
11
- import { AithosSDK, AithosSDKError, DEFAULT_SDK_ENDPOINTS, VERSION, } from "../src/index.js";
12
- // We can't easily mint a real BrowserIdentity in a synchronous unit test
13
- // without crypto setup; the constructor only reads `.did` from it, so a
14
- // minimal stub is enough for the construction-surface tests below.
15
- function fakeIdentity(did) {
16
- return { did };
17
- }
18
- describe("VERSION", () => {
19
- it("is a non-empty semver-ish string", () => {
20
- assert.equal(typeof VERSION, "string");
21
- assert.match(VERSION, /^\d+\.\d+\.\d+/);
22
- });
23
- });
24
- describe("DEFAULT_SDK_ENDPOINTS", () => {
25
- it("points at the production Aithos hosts", () => {
26
- assert.equal(DEFAULT_SDK_ENDPOINTS.compute, "https://compute.aithos.be");
27
- assert.equal(DEFAULT_SDK_ENDPOINTS.wallet, "https://wallet.aithos.be");
28
- });
29
- });
30
- describe("AithosSDK constructor", () => {
31
- const id = fakeIdentity("did:aithos:smoke");
32
- const appDid = "did:aithos:app:smoke";
33
- it("requires an identity", () => {
34
- assert.throws(() =>
35
- // @ts-expect-error: deliberately passing an invalid config
36
- new AithosSDK({ appDid }), /identity/);
37
- });
38
- it("requires an appDid", () => {
39
- assert.throws(() =>
40
- // @ts-expect-error: deliberately passing an invalid config
41
- new AithosSDK({ identity: id }), /appDid/);
42
- });
43
- it("exposes endpoints, appDid, userDid", () => {
44
- const sdk = new AithosSDK({ identity: id, appDid });
45
- assert.equal(sdk.appDid, appDid);
46
- assert.equal(sdk.userDid, "did:aithos:smoke");
47
- assert.equal(sdk.endpoints.compute, DEFAULT_SDK_ENDPOINTS.compute);
48
- assert.equal(sdk.endpoints.wallet, DEFAULT_SDK_ENDPOINTS.wallet);
49
- });
50
- it("merges endpoint overrides on top of defaults", () => {
51
- const sdk = new AithosSDK({
52
- identity: id,
53
- appDid,
54
- endpoints: { wallet: "https://staging-wallet.aithos.be" },
55
- });
56
- assert.equal(sdk.endpoints.compute, DEFAULT_SDK_ENDPOINTS.compute);
57
- assert.equal(sdk.endpoints.wallet, "https://staging-wallet.aithos.be");
58
- });
59
- it("trims trailing slashes on endpoint URLs at compose time", async () => {
60
- // Inject a fetch that captures the URL the SDK chose.
61
- let capturedUrl;
62
- const fakeFetch = async (input) => {
63
- capturedUrl = typeof input === "string" ? input : input.toString();
64
- // Reject so we don't have to construct a full happy-path response.
65
- throw new Error("captured");
66
- };
67
- const sdk = new AithosSDK({
68
- identity: id,
69
- appDid,
70
- endpoints: { wallet: "https://wallet.example.com/" }, // trailing slash
71
- fetch: fakeFetch,
72
- });
73
- await assert.rejects(sdk.wallet.createTopupSession({
74
- packId: "credits-100k",
75
- successUrl: "https://app.example.com/?ok",
76
- cancelUrl: "https://app.example.com/?ko",
77
- }), AithosSDKError);
78
- assert.equal(capturedUrl, "https://wallet.example.com/v1/wallet/topup/checkout");
79
- });
80
- it("exposes namespaces compute, wallet", () => {
81
- const sdk = new AithosSDK({ identity: id, appDid });
82
- assert.equal(typeof sdk.compute.invokeBedrock, "function");
83
- assert.equal(typeof sdk.wallet.createTopupSession, "function");
84
- });
85
- });
86
- //# sourceMappingURL=sdk.test.js.map
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=wallet.test.d.ts.map
@@ -1,110 +0,0 @@
1
- // SPDX-License-Identifier: Apache-2.0
2
- // Copyright 2026 Mathieu Colla
3
- // Unit tests for sdk.wallet.createTopupSession with a mock fetch.
4
- import { strict as assert } from "node:assert";
5
- import { describe, it } from "node:test";
6
- import { createBrowserIdentity } from "@aithos/protocol-client";
7
- import { AithosSDK, AithosSDKError } from "../src/index.js";
8
- const APP_DID = "did:aithos:app:test";
9
- function makeSdk(fetchImpl) {
10
- const identity = createBrowserIdentity("test-handle", "Test User");
11
- return new AithosSDK({
12
- identity,
13
- appDid: APP_DID,
14
- endpoints: { wallet: "https://wallet.example.test" },
15
- fetch: fetchImpl,
16
- });
17
- }
18
- describe("wallet.createTopupSession — happy path", () => {
19
- it("posts user_did + pack_id + urls and returns the hosted URL", async () => {
20
- let capturedUrl;
21
- let capturedBody;
22
- const fakeFetch = async (input, init) => {
23
- capturedUrl = typeof input === "string" ? input : input.toString();
24
- capturedBody = JSON.parse(init?.body);
25
- return new Response(JSON.stringify({
26
- checkout_url: "https://checkout.stripe.com/c/pay/cs_test_xyz",
27
- session_id: "cs_test_xyz",
28
- }), { status: 200, headers: { "content-type": "application/json" } });
29
- };
30
- const sdk = makeSdk(fakeFetch);
31
- const out = await sdk.wallet.createTopupSession({
32
- packId: "credits-1m",
33
- successUrl: "https://app.example.com/?topup=success",
34
- cancelUrl: "https://app.example.com/?topup=cancel",
35
- });
36
- assert.equal(out.checkoutUrl, "https://checkout.stripe.com/c/pay/cs_test_xyz");
37
- assert.equal(out.sessionId, "cs_test_xyz");
38
- assert.equal(capturedUrl, "https://wallet.example.test/v1/wallet/topup/checkout");
39
- assert.equal(capturedBody?.user_did, sdk.userDid);
40
- assert.equal(capturedBody?.pack_id, "credits-1m");
41
- assert.equal(capturedBody?.success_url, "https://app.example.com/?topup=success");
42
- assert.equal(capturedBody?.cancel_url, "https://app.example.com/?topup=cancel");
43
- });
44
- });
45
- describe("wallet.createTopupSession — errors", () => {
46
- it("wraps a network failure as AithosSDKError(code='network')", async () => {
47
- const fakeFetch = async () => {
48
- throw new TypeError("Failed to fetch");
49
- };
50
- const sdk = makeSdk(fakeFetch);
51
- await assert.rejects(sdk.wallet.createTopupSession({
52
- packId: "credits-100k",
53
- successUrl: "https://app.example.com/?ok",
54
- cancelUrl: "https://app.example.com/?ko",
55
- }), (err) => {
56
- assert.ok(err instanceof AithosSDKError);
57
- assert.equal(err.code, "network");
58
- return true;
59
- });
60
- });
61
- it("surfaces the proxy's structured error (error/detail) on a 4xx", async () => {
62
- const fakeFetch = async () => new Response(JSON.stringify({ error: "unknown_pack", pack_id: "credits-9999" }), { status: 400, headers: { "content-type": "application/json" } });
63
- const sdk = makeSdk(fakeFetch);
64
- await assert.rejects(sdk.wallet.createTopupSession({
65
- // @ts-expect-error: deliberately invalid pack id
66
- packId: "credits-9999",
67
- successUrl: "https://app.example.com/?ok",
68
- cancelUrl: "https://app.example.com/?ko",
69
- }), (err) => {
70
- assert.ok(err instanceof AithosSDKError);
71
- assert.equal(err.code, "unknown_pack");
72
- assert.equal(err.status, 400);
73
- return true;
74
- });
75
- });
76
- it("rejects a non-JSON response as AithosSDKError(code='http')", async () => {
77
- const fakeFetch = async () => new Response("<html>500</html>", {
78
- status: 500,
79
- headers: { "content-type": "text/html" },
80
- });
81
- const sdk = makeSdk(fakeFetch);
82
- await assert.rejects(sdk.wallet.createTopupSession({
83
- packId: "credits-100k",
84
- successUrl: "https://app.example.com/?ok",
85
- cancelUrl: "https://app.example.com/?ko",
86
- }), (err) => {
87
- assert.ok(err instanceof AithosSDKError);
88
- assert.equal(err.code, "http");
89
- assert.equal(err.status, 500);
90
- return true;
91
- });
92
- });
93
- it("rejects a 200 with missing fields as AithosSDKError(code='empty')", async () => {
94
- const fakeFetch = async () => new Response(JSON.stringify({}), {
95
- status: 200,
96
- headers: { "content-type": "application/json" },
97
- });
98
- const sdk = makeSdk(fakeFetch);
99
- await assert.rejects(sdk.wallet.createTopupSession({
100
- packId: "credits-100k",
101
- successUrl: "https://app.example.com/?ok",
102
- cancelUrl: "https://app.example.com/?ko",
103
- }), (err) => {
104
- assert.ok(err instanceof AithosSDKError);
105
- assert.equal(err.code, "empty");
106
- return true;
107
- });
108
- });
109
- });
110
- //# sourceMappingURL=wallet.test.js.map