@casfa/client 0.0.1 → 0.3.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.
Files changed (64) hide show
  1. package/dist/api/claim.d.ts +21 -0
  2. package/dist/api/claim.d.ts.map +1 -0
  3. package/dist/api/delegates.d.ts +39 -0
  4. package/dist/api/delegates.d.ts.map +1 -0
  5. package/dist/api/depots.d.ts +68 -0
  6. package/dist/api/depots.d.ts.map +1 -0
  7. package/dist/api/filesystem.d.ts +55 -0
  8. package/dist/api/filesystem.d.ts.map +1 -0
  9. package/dist/api/index.d.ts +13 -3
  10. package/dist/api/index.d.ts.map +1 -0
  11. package/dist/api/index.js +355 -207
  12. package/dist/api/index.js.map +19 -1
  13. package/dist/api/info.d.ts +16 -0
  14. package/dist/api/info.d.ts.map +1 -0
  15. package/dist/api/nodes.d.ts +42 -0
  16. package/dist/api/nodes.d.ts.map +1 -0
  17. package/dist/api/oauth.d.ts +54 -0
  18. package/dist/api/oauth.d.ts.map +1 -0
  19. package/dist/api/requests.d.ts +33 -0
  20. package/dist/api/requests.d.ts.map +1 -0
  21. package/dist/api/tokens.d.ts +19 -0
  22. package/dist/api/tokens.d.ts.map +1 -0
  23. package/dist/client/delegates.d.ts +26 -0
  24. package/dist/client/delegates.d.ts.map +1 -0
  25. package/dist/client/depots.d.ts +28 -0
  26. package/dist/client/depots.d.ts.map +1 -0
  27. package/dist/client/filesystem.d.ts +39 -0
  28. package/dist/client/filesystem.d.ts.map +1 -0
  29. package/dist/client/helpers.d.ts +27 -0
  30. package/dist/client/helpers.d.ts.map +1 -0
  31. package/dist/client/index.d.ts +49 -0
  32. package/dist/client/index.d.ts.map +1 -0
  33. package/dist/client/nodes.d.ts +30 -0
  34. package/dist/client/nodes.d.ts.map +1 -0
  35. package/dist/client/oauth.d.ts +24 -0
  36. package/dist/client/oauth.d.ts.map +1 -0
  37. package/dist/client/tokens.d.ts +23 -0
  38. package/dist/client/tokens.d.ts.map +1 -0
  39. package/dist/index.d.ts +14 -294
  40. package/dist/index.d.ts.map +1 -0
  41. package/dist/index.js +414 -515
  42. package/dist/index.js.map +32 -1
  43. package/dist/store/index.d.ts +8 -0
  44. package/dist/store/index.d.ts.map +1 -0
  45. package/dist/store/jwt-refresh.d.ts +31 -0
  46. package/dist/store/jwt-refresh.d.ts.map +1 -0
  47. package/dist/store/token-checks.d.ts +33 -0
  48. package/dist/store/token-checks.d.ts.map +1 -0
  49. package/dist/store/token-selector.d.ts +29 -0
  50. package/dist/store/token-selector.d.ts.map +1 -0
  51. package/dist/store/token-store.d.ts +30 -0
  52. package/dist/store/token-store.d.ts.map +1 -0
  53. package/dist/types/client.d.ts +64 -0
  54. package/dist/types/client.d.ts.map +1 -0
  55. package/dist/types/index.d.ts +5 -142
  56. package/dist/types/index.d.ts.map +1 -0
  57. package/dist/types/index.js +14 -3
  58. package/dist/types/index.js.map +10 -1
  59. package/dist/types/tokens.d.ts +86 -0
  60. package/dist/types/tokens.d.ts.map +1 -0
  61. package/dist/utils/http.d.ts +32 -0
  62. package/dist/utils/http.d.ts.map +1 -0
  63. package/package.json +7 -3
  64. package/dist/index-cPO-6GxE.d.ts +0 -338
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Stateful CASFA Client
3
+ *
4
+ * A closure-based client that manages JWT auth.
5
+ * Root delegate is auto-created by the server on first JWT request.
6
+ */
7
+ import type { ServiceInfo } from "@casfa/protocol";
8
+ import type { ClientConfig, OnAuthRequiredCallback, OnTokenChangeCallback, TokenStorageProvider } from "../types/client.ts";
9
+ import type { StoredAccessToken, StoredRootDelegate, TokenState } from "../types/tokens.ts";
10
+ import { type DelegateMethods } from "./delegates.ts";
11
+ import { type DepotMethods } from "./depots.ts";
12
+ import { type FsMethods } from "./filesystem.ts";
13
+ import { type NodeMethods } from "./nodes.ts";
14
+ import { type OAuthMethods } from "./oauth.ts";
15
+ import { type TokenMethods } from "./tokens.ts";
16
+ export type { DelegateMethods, DepotMethods, FsMethods, NodeMethods, OAuthMethods, TokenMethods };
17
+ export type { ClientConfig, OnAuthRequiredCallback, OnTokenChangeCallback, TokenStorageProvider };
18
+ /**
19
+ * The stateful CASFA client.
20
+ */
21
+ export type CasfaClient = {
22
+ /** Get current token state */
23
+ getState: () => TokenState;
24
+ /** Get server info */
25
+ getServerInfo: () => ServiceInfo | null;
26
+ /** Set root delegate metadata (e.g., from external source) */
27
+ setRootDelegate: (delegate: StoredRootDelegate) => void;
28
+ /** Get current auth token (JWT — server auto-creates root delegate) */
29
+ getAccessToken: () => Promise<StoredAccessToken | null>;
30
+ /** Clear all tokens and logout */
31
+ logout: () => void;
32
+ /** OAuth methods */
33
+ oauth: OAuthMethods;
34
+ /** Token management methods */
35
+ tokens: TokenMethods;
36
+ /** Delegate management methods */
37
+ delegates: DelegateMethods;
38
+ /** Depot methods */
39
+ depots: DepotMethods;
40
+ /** Filesystem methods */
41
+ fs: FsMethods;
42
+ /** Node methods */
43
+ nodes: NodeMethods;
44
+ };
45
+ /**
46
+ * Create a stateful CASFA client.
47
+ */
48
+ export declare const createClient: (config: ClientConfig) => Promise<CasfaClient>;
49
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAKnD,OAAO,KAAK,EACV,YAAY,EACZ,sBAAsB,EACtB,qBAAqB,EACrB,oBAAoB,EACrB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC5F,OAAO,EAAyB,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAC7E,OAAO,EAAsB,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AACpE,OAAO,EAAmB,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,EAAqB,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AACjE,OAAO,EAAsB,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AACnE,OAAO,EAAsB,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AAMpE,YAAY,EAAE,eAAe,EAAE,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,EAAE,CAAC;AAElG,YAAY,EAAE,YAAY,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,CAAC;AAMlG;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,8BAA8B;IAC9B,QAAQ,EAAE,MAAM,UAAU,CAAC;IAC3B,sBAAsB;IACtB,aAAa,EAAE,MAAM,WAAW,GAAG,IAAI,CAAC;IAExC,8DAA8D;IAC9D,eAAe,EAAE,CAAC,QAAQ,EAAE,kBAAkB,KAAK,IAAI,CAAC;IACxD,uEAAuE;IACvE,cAAc,EAAE,MAAM,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC,CAAC;IACxD,kCAAkC;IAClC,MAAM,EAAE,MAAM,IAAI,CAAC;IAEnB,oBAAoB;IACpB,KAAK,EAAE,YAAY,CAAC;IACpB,+BAA+B;IAC/B,MAAM,EAAE,YAAY,CAAC;IACrB,kCAAkC;IAClC,SAAS,EAAE,eAAe,CAAC;IAC3B,oBAAoB;IACpB,MAAM,EAAE,YAAY,CAAC;IACrB,yBAAyB;IACzB,EAAE,EAAE,SAAS,CAAC;IACd,mBAAmB;IACnB,KAAK,EAAE,WAAW,CAAC;CACpB,CAAC;AAMF;;GAEG;AACH,eAAO,MAAM,YAAY,GAAU,QAAQ,YAAY,KAAG,OAAO,CAAC,WAAW,CAuD5E,CAAC"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Node methods for the stateful client.
3
+ */
4
+ import type { BatchClaimRequest, BatchClaimResponse, CheckNodes, CheckNodesResponse, ClaimNodeResponse, NodeMetadata } from "@casfa/protocol";
5
+ import * as api from "../api/index.ts";
6
+ import type { TokenSelector } from "../store/token-selector.ts";
7
+ import type { FetchResult } from "../types/client.ts";
8
+ export type NodeMethods = {
9
+ /** Get node content */
10
+ get: (nodeKey: string) => Promise<FetchResult<Uint8Array>>;
11
+ /** Get node content via navigation path (~0/~1/...) */
12
+ getNavigated: (nodeKey: string, indexPath: string) => Promise<FetchResult<Uint8Array>>;
13
+ /** Get node metadata */
14
+ getMetadata: (nodeKey: string) => Promise<FetchResult<NodeMetadata>>;
15
+ /** Check nodes status on the server */
16
+ check: (params: CheckNodes) => Promise<FetchResult<CheckNodesResponse>>;
17
+ /** Upload a node */
18
+ put: (nodeKey: string, content: Uint8Array) => Promise<FetchResult<api.NodeUploadResult>>;
19
+ /** Claim ownership of a node via PoP (legacy single claim) */
20
+ claim: (nodeKey: string, pop: string) => Promise<FetchResult<ClaimNodeResponse>>;
21
+ /** Batch claim ownership of nodes (PoP + path-based) */
22
+ batchClaim: (params: BatchClaimRequest) => Promise<FetchResult<BatchClaimResponse>>;
23
+ };
24
+ export type NodeDeps = {
25
+ baseUrl: string;
26
+ realm: string;
27
+ tokenSelector: TokenSelector;
28
+ };
29
+ export declare const createNodeMethods: ({ baseUrl, realm, tokenSelector }: NodeDeps) => NodeMethods;
30
+ //# sourceMappingURL=nodes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nodes.d.ts","sourceRoot":"","sources":["../../src/client/nodes.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACV,iBAAiB,EACjB,kBAAkB,EAClB,UAAU,EACV,kBAAkB,EAClB,iBAAiB,EACjB,YAAY,EACb,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,GAAG,MAAM,iBAAiB,CAAC;AACvC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAOtD,MAAM,MAAM,WAAW,GAAG;IACxB,uBAAuB;IACvB,GAAG,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC,CAAC;IAC3D,uDAAuD;IACvD,YAAY,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC,CAAC;IACvF,wBAAwB;IACxB,WAAW,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC,CAAC;IACrE,uCAAuC;IACvC,KAAK,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,OAAO,CAAC,WAAW,CAAC,kBAAkB,CAAC,CAAC,CAAC;IACxE,oBAAoB;IACpB,GAAG,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,KAAK,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC,CAAC;IAC1F,8DAA8D;IAC9D,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,WAAW,CAAC,iBAAiB,CAAC,CAAC,CAAC;IACjF,wDAAwD;IACxD,UAAU,EAAE,CAAC,MAAM,EAAE,iBAAiB,KAAK,OAAO,CAAC,WAAW,CAAC,kBAAkB,CAAC,CAAC,CAAC;CACrF,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,aAAa,CAAC;CAC9B,CAAC;AAMF,eAAO,MAAM,iBAAiB,GAAI,mCAAmC,QAAQ,KAAG,WAuB/E,CAAC"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * OAuth methods for the stateful client.
3
+ */
4
+ import * as api from "../api/index.ts";
5
+ import type { RefreshManager } from "../store/jwt-refresh.ts";
6
+ import type { TokenStore } from "../store/token-store.ts";
7
+ import type { FetchResult } from "../types/client.ts";
8
+ export type OAuthMethods = {
9
+ /** Get Cognito configuration */
10
+ getConfig: () => Promise<FetchResult<api.CognitoConfig>>;
11
+ /** Login with email and password */
12
+ login: (email: string, password: string) => Promise<FetchResult<api.UserInfo>>;
13
+ /** Exchange authorization code for tokens */
14
+ exchangeCode: (code: string, redirectUri: string, codeVerifier?: string) => Promise<FetchResult<api.UserInfo>>;
15
+ /** Get current user info */
16
+ getMe: () => Promise<FetchResult<api.UserInfo>>;
17
+ };
18
+ export type OAuthDeps = {
19
+ baseUrl: string;
20
+ store: TokenStore;
21
+ refreshManager: RefreshManager;
22
+ };
23
+ export declare const createOAuthMethods: ({ baseUrl, store, refreshManager, }: OAuthDeps) => OAuthMethods;
24
+ //# sourceMappingURL=oauth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauth.d.ts","sourceRoot":"","sources":["../../src/client/oauth.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,GAAG,MAAM,iBAAiB,CAAC;AACvC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAOtD,MAAM,MAAM,YAAY,GAAG;IACzB,gCAAgC;IAChC,SAAS,EAAE,MAAM,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC;IACzD,oCAAoC;IACpC,KAAK,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC/E,6CAA6C;IAC7C,YAAY,EAAE,CACZ,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,EACnB,YAAY,CAAC,EAAE,MAAM,KAClB,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC;IACxC,4BAA4B;IAC5B,KAAK,EAAE,MAAM,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC;CACjD,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,UAAU,CAAC;IAClB,cAAc,EAAE,cAAc,CAAC;CAChC,CAAC;AAMF,eAAO,MAAM,kBAAkB,GAAI,qCAIhC,SAAS,KAAG,YAsCb,CAAC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Token management methods for the stateful client.
3
+ *
4
+ * Root delegates are auto-created by the server's auth middleware on
5
+ * first JWT request. This module provides token refresh operations.
6
+ */
7
+ import type { RefreshManager } from "../store/jwt-refresh.ts";
8
+ import type { TokenSelector } from "../store/token-selector.ts";
9
+ import type { TokenStore } from "../store/token-store.ts";
10
+ import type { FetchResult } from "../types/client.ts";
11
+ export type TokenMethods = {
12
+ /** Refresh the user's JWT (OAuth token refresh). */
13
+ refresh: () => Promise<FetchResult<void>>;
14
+ };
15
+ export type TokenDeps = {
16
+ baseUrl: string;
17
+ realm: string;
18
+ store: TokenStore;
19
+ refreshManager: RefreshManager;
20
+ tokenSelector: TokenSelector;
21
+ };
22
+ export declare const createTokenMethods: ({ refreshManager }: TokenDeps) => TokenMethods;
23
+ //# sourceMappingURL=tokens.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../../src/client/tokens.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAMtD,MAAM,MAAM,YAAY,GAAG;IACzB,oDAAoD;IACpD,OAAO,EAAE,MAAM,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC;CAC3C,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,UAAU,CAAC;IAClB,cAAc,EAAE,cAAc,CAAC;IAC/B,aAAa,EAAE,aAAa,CAAC;CAC9B,CAAC;AAMF,eAAO,MAAM,kBAAkB,GAAI,oBAAoB,SAAS,KAAG,YAkBlE,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,298 +1,18 @@
1
- import { ServiceInfo, CreateDepot, CreateDepotResponse, ListDepotsQuery, DepotDetail, UpdateDepot, DepotCommit, NodeMetadata, PrepareNodes, PrepareNodesResponse, CreateTicket, CreateTicketResponse, ListTicketsQuery, TicketDetail, TicketSubmit, CreateToken } from '@casfa/protocol';
2
- import { TokenState, StoredUserToken, StoredDelegateToken, StoredAccessToken, TokenStorageProvider, OnTokenChangeCallback, OnAuthRequiredCallback, FetchResult, ClientConfig } from './types/index.js';
3
- export { ClientError, emptyTokenState } from './types/index.js';
4
- import { L as ListDepotsResponse, C as CommitDepotResponse, N as NodeUploadResult, a as CognitoConfig, U as UserInfo, b as ListTicketsResponse, S as SubmitTicketResponse, c as ListTokensParams, d as ListTokensResponse, D as DelegateTokenParams } from './index-cPO-6GxE.js';
5
- export { i as api } from './index-cPO-6GxE.js';
6
-
7
1
  /**
8
- * Token store - manages the three-tier token state.
2
+ * @casfa/client - CASFA client library
9
3
  *
10
- * Provides a closure-based store for token state management with
11
- * automatic persistence and change notifications.
12
- */
13
-
14
- type TokenStore = {
15
- /** Get current token state (immutable snapshot) */
16
- getState: () => TokenState;
17
- /** Set user JWT token */
18
- setUser: (token: StoredUserToken | null) => void;
19
- /** Set delegate token */
20
- setDelegate: (token: StoredDelegateToken | null) => void;
21
- /** Set access token */
22
- setAccess: (token: StoredAccessToken | null) => void;
23
- /** Clear all tokens */
24
- clear: () => void;
25
- /** Initialize from storage provider */
26
- initialize: () => Promise<void>;
27
- };
28
- type TokenStoreConfig = {
29
- storage?: TokenStorageProvider;
30
- onTokenChange?: OnTokenChangeCallback;
31
- onAuthRequired?: OnAuthRequiredCallback;
32
- };
33
- /**
34
- * Create a token store instance.
35
- */
36
- declare const createTokenStore: (config?: TokenStoreConfig) => TokenStore;
37
-
38
- /**
39
- * Token selector and auto-issuer.
4
+ * A stateful client that manages two-tier token hierarchy:
5
+ * - User JWT: OAuth login token, highest authority, used for root operations
6
+ * - Root Delegate: metadata-only entity (no RT/AT), anchor of delegate tree
40
7
  *
41
- * Implements the "maximum authority" principle:
42
- * - When issuing tokens, prefer User JWT (depth=0) over Delegate Token
43
- * - Check issuer consistency before using existing tokens
44
- * - Re-issue tokens when issuer is not maximized
45
- */
46
-
47
- type TokenSelectorConfig = {
48
- store: TokenStore;
49
- baseUrl: string;
50
- realm: string;
51
- serverInfo: ServiceInfo | null;
52
- defaultTokenTtl?: number;
53
- };
54
- type TokenSelector = {
55
- /**
56
- * Get or issue an Access Token.
57
- * - If valid Access Token exists and is from max issuer, return it
58
- * - Otherwise, issue a new one using User JWT or Delegate Token
59
- */
60
- ensureAccessToken: () => Promise<StoredAccessToken | null>;
61
- /**
62
- * Get or issue a Delegate Token.
63
- * - If valid Delegate Token exists, return it
64
- * - If User JWT exists, issue a new one
65
- */
66
- ensureDelegateToken: () => Promise<StoredDelegateToken | null>;
67
- };
68
- /**
69
- * Create a token selector instance.
70
- */
71
- declare const createTokenSelector: (config: TokenSelectorConfig) => TokenSelector;
72
-
73
- /**
74
- * Depot methods for the stateful client.
75
- */
76
-
77
- type DepotMethods = {
78
- /** Create a new depot */
79
- create: (params: CreateDepot) => Promise<FetchResult<CreateDepotResponse>>;
80
- /** List depots */
81
- list: (params?: ListDepotsQuery) => Promise<FetchResult<ListDepotsResponse>>;
82
- /** Get depot details */
83
- get: (depotId: string) => Promise<FetchResult<DepotDetail>>;
84
- /** Update depot */
85
- update: (depotId: string, params: UpdateDepot) => Promise<FetchResult<DepotDetail>>;
86
- /** Delete depot */
87
- delete: (depotId: string) => Promise<FetchResult<void>>;
88
- /** Commit new root */
89
- commit: (depotId: string, params: DepotCommit) => Promise<FetchResult<CommitDepotResponse>>;
90
- };
91
-
92
- /**
93
- * Node methods for the stateful client.
94
- */
95
-
96
- type NodeMethods = {
97
- /** Get node content */
98
- get: (nodeKey: string, indexPath: string) => Promise<FetchResult<Uint8Array>>;
99
- /** Get node metadata */
100
- getMetadata: (nodeKey: string, indexPath: string) => Promise<FetchResult<NodeMetadata>>;
101
- /** Prepare nodes for upload */
102
- prepare: (params: PrepareNodes) => Promise<FetchResult<PrepareNodesResponse>>;
103
- /** Upload a node */
104
- put: (nodeKey: string, content: Uint8Array) => Promise<FetchResult<NodeUploadResult>>;
105
- };
106
-
107
- /**
108
- * JWT refresh management with promise deduplication.
109
- */
110
-
111
- type RefreshManager = {
112
- /**
113
- * Ensure user token is valid, refreshing if needed.
114
- * Returns the valid user token or null if refresh failed.
115
- */
116
- ensureValidUserToken: () => Promise<StoredUserToken | null>;
117
- /**
118
- * Schedule proactive refresh before expiration.
119
- */
120
- scheduleProactiveRefresh: () => void;
121
- /**
122
- * Cancel any scheduled refresh.
123
- */
124
- cancelScheduledRefresh: () => void;
125
- };
126
- type RefreshManagerConfig = {
127
- store: TokenStore;
128
- baseUrl: string;
129
- onAuthRequired?: OnAuthRequiredCallback;
130
- };
131
- /**
132
- * Create a refresh manager for JWT token refresh.
133
- */
134
- declare const createRefreshManager: (config: RefreshManagerConfig) => RefreshManager;
135
-
136
- /**
137
- * OAuth methods for the stateful client.
138
- */
139
-
140
- type OAuthMethods = {
141
- /** Get Cognito configuration */
142
- getConfig: () => Promise<FetchResult<CognitoConfig>>;
143
- /** Login with email and password */
144
- login: (email: string, password: string) => Promise<FetchResult<UserInfo>>;
145
- /** Exchange authorization code for tokens */
146
- exchangeCode: (code: string, redirectUri: string, codeVerifier?: string) => Promise<FetchResult<UserInfo>>;
147
- /** Get current user info */
148
- getMe: () => Promise<FetchResult<UserInfo>>;
149
- };
150
-
151
- /**
152
- * Ticket methods for the stateful client.
8
+ * Root operations use JWT directly via the server's unified auth middleware.
153
9
  *
154
- * Design Principle: All Realm data operations use Access Token.
155
- * Delegate Token is only for issuing tokens.
156
- *
157
- * Two-step Ticket creation flow:
158
- * 1. Issue Access Token using tokens.delegate() (requires Delegate Token)
159
- * 2. Create Ticket using tickets.create() (requires Access Token)
160
- */
161
-
162
- type TicketMethods = {
163
- /**
164
- * Create a new ticket and bind a pre-issued Access Token.
165
- * Requires Access Token.
166
- *
167
- * Note: The Access Token to bind must be issued first using tokens.delegate().
168
- *
169
- * @param params.accessTokenId - Pre-issued Access Token ID to bind (for Tool use)
170
- */
171
- create: (params: CreateTicket) => Promise<FetchResult<CreateTicketResponse>>;
172
- /** List tickets */
173
- list: (params?: ListTicketsQuery) => Promise<FetchResult<ListTicketsResponse>>;
174
- /** Get ticket details */
175
- get: (ticketId: string) => Promise<FetchResult<TicketDetail>>;
176
- /** Submit ticket */
177
- submit: (ticketId: string, params: TicketSubmit) => Promise<FetchResult<SubmitTicketResponse>>;
178
- };
179
-
180
- /**
181
- * Token management methods for the stateful client.
182
- */
183
-
184
- type TokenMethods = {
185
- /** Create a new token (User JWT required) */
186
- create: (params: CreateToken) => Promise<FetchResult<StoredDelegateToken | StoredAccessToken>>;
187
- /** List tokens (User JWT required) */
188
- list: (params?: ListTokensParams) => Promise<FetchResult<ListTokensResponse>>;
189
- /** Revoke a token (User JWT required) */
190
- revoke: (tokenId: string) => Promise<FetchResult<void>>;
191
- /** Delegate a token using current Delegate Token */
192
- delegate: (params: DelegateTokenParams) => Promise<FetchResult<StoredDelegateToken | StoredAccessToken>>;
193
- };
194
-
195
- /**
196
- * Stateful CASFA Client
197
- *
198
- * A closure-based client that manages three-tier token hierarchy:
199
- * - User JWT: OAuth login token, highest authority
200
- * - Delegate Token: Re-delegation token, can issue child tokens
201
- * - Access Token: Data access token, used for CAS operations
202
- */
203
-
204
- /**
205
- * The stateful CASFA client.
206
- */
207
- type CasfaClient = {
208
- /** Get current token state */
209
- getState: () => TokenState;
210
- /** Get server info */
211
- getServerInfo: () => ServiceInfo | null;
212
- /** Set delegate token (e.g., from external source) */
213
- setDelegateToken: (token: StoredDelegateToken) => void;
214
- /** Set access token (e.g., from external source) */
215
- setAccessToken: (token: StoredAccessToken) => void;
216
- /** Clear all tokens and logout */
217
- logout: () => void;
218
- /** OAuth methods */
219
- oauth: OAuthMethods;
220
- /** Token management methods */
221
- tokens: TokenMethods;
222
- /** Ticket methods */
223
- tickets: TicketMethods;
224
- /** Depot methods */
225
- depots: DepotMethods;
226
- /** Node methods */
227
- nodes: NodeMethods;
228
- };
229
- /**
230
- * Create a stateful CASFA client.
231
- */
232
- declare const createClient: (config: ClientConfig) => Promise<CasfaClient>;
233
-
234
- /**
235
- * Token validity and issuer consistency checks.
236
- */
237
-
238
- /**
239
- * Default buffer time before expiration (60 seconds).
240
- */
241
- declare const DEFAULT_EXPIRY_BUFFER_MS = 60000;
242
- /**
243
- * Check if a token is valid (not expired with buffer).
244
- */
245
- declare const isTokenValid: (token: {
246
- expiresAt: number;
247
- } | null, bufferMs?: number) => boolean;
248
- /**
249
- * Check if token is expiring soon and should be refreshed proactively.
250
- * Used for JWT refresh scheduling.
251
- */
252
- declare const isTokenExpiringSoon: (token: {
253
- expiresAt: number;
254
- } | null, windowMs?: number) => boolean;
255
- /**
256
- * Check if user JWT is valid.
257
- */
258
- declare const isUserTokenValid: (userToken: StoredUserToken | null, bufferMs?: number) => boolean;
259
- /**
260
- * Check if delegate token is valid.
261
- */
262
- declare const isDelegateTokenValid: (delegateToken: StoredDelegateToken | null, bufferMs?: number) => boolean;
263
- /**
264
- * Check if access token is valid.
265
- */
266
- declare const isAccessTokenValid: (accessToken: StoredAccessToken | null, bufferMs?: number) => boolean;
267
- /**
268
- * Get the current max issuer ID.
269
- * Priority: User JWT (userId) > Delegate Token (tokenId)
270
- */
271
- declare const getMaxIssuerId: (state: TokenState) => string | null;
272
- /**
273
- * Check if access token is issued by the current max issuer.
274
- * If not, the access token should be re-issued.
275
- */
276
- declare const isAccessTokenFromMaxIssuer: (state: TokenState) => boolean;
277
- /**
278
- * Check if delegate token is issued by current user.
279
- * If user JWT exists but delegate token is from a different user,
280
- * we may want to re-issue the delegate token.
281
- */
282
- declare const isDelegateTokenFromCurrentUser: (state: TokenState) => boolean;
283
- /**
284
- * Determine if access token needs re-issue.
285
- * Returns true if:
286
- * - Access token is invalid/expired
287
- * - Access token's issuer is not the current max issuer
288
- */
289
- declare const shouldReissueAccessToken: (state: TokenState) => boolean;
290
- /**
291
- * Determine if delegate token needs re-issue.
292
- * Returns true if:
293
- * - Delegate token is invalid/expired
294
- * - User token exists but delegate token is not from current user
295
- */
296
- declare const shouldReissueDelegateToken: (state: TokenState) => boolean;
297
-
298
- export { type CasfaClient, ClientConfig, DEFAULT_EXPIRY_BUFFER_MS, type DepotMethods, FetchResult, type NodeMethods, type OAuthMethods, OnAuthRequiredCallback, OnTokenChangeCallback, type RefreshManager, StoredAccessToken, StoredDelegateToken, StoredUserToken, type TicketMethods, type TokenMethods, type TokenSelector, TokenState, TokenStorageProvider, type TokenStore, createClient, createRefreshManager, createTokenSelector, createTokenStore, getMaxIssuerId, isAccessTokenFromMaxIssuer, isAccessTokenValid, isDelegateTokenFromCurrentUser, isDelegateTokenValid, isTokenExpiringSoon, isTokenValid, isUserTokenValid, shouldReissueAccessToken, shouldReissueDelegateToken };
10
+ * @packageDocumentation
11
+ */
12
+ export { type CasfaClient, type ClientConfig, createClient, type DelegateMethods, type DepotMethods, type FsMethods, type NodeMethods, type OAuthMethods, type OnAuthRequiredCallback, type OnTokenChangeCallback, type TokenMethods, type TokenStorageProvider, } from "./client/index.ts";
13
+ export { createRefreshManager, createTokenSelector, createTokenStore, DEFAULT_EXPIRY_BUFFER_MS, isStoredAccessTokenValid, isTokenExpiringSoon, isTokenValid, isUserTokenValid, type RefreshManager, type TokenSelector, type TokenStore, } from "./store/index.ts";
14
+ export type { ClientError, FetchResult } from "./types/client.ts";
15
+ export type { StoredAccessToken, StoredRootDelegate, StoredUserToken, TokenState, } from "./types/tokens.ts";
16
+ export { emptyTokenState } from "./types/tokens.ts";
17
+ export * as api from "./api/index.ts";
18
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAMH,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,YAAY,EACZ,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,KAAK,YAAY,EACjB,KAAK,oBAAoB,GAC1B,MAAM,mBAAmB,CAAC;AAM3B,OAAO,EACL,oBAAoB,EACpB,mBAAmB,EACnB,gBAAgB,EAChB,wBAAwB,EACxB,wBAAwB,EACxB,mBAAmB,EACnB,YAAY,EACZ,gBAAgB,EAChB,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,UAAU,GAChB,MAAM,kBAAkB,CAAC;AAM1B,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAElE,YAAY,EACV,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EACf,UAAU,GACX,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAMpD,OAAO,KAAK,GAAG,MAAM,gBAAgB,CAAC"}