@hypercerts-org/sdk-core 0.4.0-beta.0 → 0.6.0-beta.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/README.md +459 -79
- package/dist/index.cjs +128 -47
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +28 -9
- package/dist/index.mjs +128 -47
- package/dist/index.mjs.map +1 -1
- package/dist/types.cjs +3 -2
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.ts +28 -9
- package/dist/types.mjs +3 -2
- package/dist/types.mjs.map +1 -1
- package/package.json +9 -5
- package/.turbo/turbo-build.log +0 -328
- package/.turbo/turbo-test.log +0 -118
- package/CHANGELOG.md +0 -22
- package/eslint.config.mjs +0 -22
- package/rollup.config.js +0 -75
- package/src/auth/OAuthClient.ts +0 -497
- package/src/core/SDK.ts +0 -410
- package/src/core/config.ts +0 -243
- package/src/core/errors.ts +0 -257
- package/src/core/interfaces.ts +0 -324
- package/src/core/types.ts +0 -281
- package/src/errors.ts +0 -57
- package/src/index.ts +0 -107
- package/src/lexicons.ts +0 -64
- package/src/repository/BlobOperationsImpl.ts +0 -199
- package/src/repository/CollaboratorOperationsImpl.ts +0 -396
- package/src/repository/HypercertOperationsImpl.ts +0 -1146
- package/src/repository/LexiconRegistry.ts +0 -332
- package/src/repository/OrganizationOperationsImpl.ts +0 -234
- package/src/repository/ProfileOperationsImpl.ts +0 -281
- package/src/repository/RecordOperationsImpl.ts +0 -340
- package/src/repository/Repository.ts +0 -482
- package/src/repository/interfaces.ts +0 -897
- package/src/repository/types.ts +0 -111
- package/src/services/hypercerts/types.ts +0 -87
- package/src/storage/InMemorySessionStore.ts +0 -127
- package/src/storage/InMemoryStateStore.ts +0 -146
- package/src/storage.ts +0 -63
- package/src/testing/index.ts +0 -67
- package/src/testing/mocks.ts +0 -142
- package/src/testing/stores.ts +0 -285
- package/src/testing.ts +0 -64
- package/src/types.ts +0 -86
- package/tests/auth/OAuthClient.test.ts +0 -164
- package/tests/core/SDK.test.ts +0 -176
- package/tests/core/errors.test.ts +0 -81
- package/tests/repository/BlobOperationsImpl.test.ts +0 -154
- package/tests/repository/CollaboratorOperationsImpl.test.ts +0 -438
- package/tests/repository/HypercertOperationsImpl.test.ts +0 -652
- package/tests/repository/LexiconRegistry.test.ts +0 -192
- package/tests/repository/OrganizationOperationsImpl.test.ts +0 -242
- package/tests/repository/ProfileOperationsImpl.test.ts +0 -254
- package/tests/repository/RecordOperationsImpl.test.ts +0 -375
- package/tests/repository/Repository.test.ts +0 -149
- package/tests/utils/fixtures.ts +0 -117
- package/tests/utils/mocks.ts +0 -109
- package/tests/utils/repository-fixtures.ts +0 -78
- package/tsconfig.json +0 -11
- package/tsconfig.tsbuildinfo +0 -1
- package/vitest.config.ts +0 -30
package/src/repository/types.ts
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Repository types - Shared types for repository operations
|
|
3
|
-
* @packageDocumentation
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import type { CollaboratorPermissions } from "../core/types.js";
|
|
7
|
-
|
|
8
|
-
// ============================================================================
|
|
9
|
-
// Basic Types
|
|
10
|
-
// ============================================================================
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Options for creating a repository instance
|
|
14
|
-
*/
|
|
15
|
-
export interface RepositoryOptions {
|
|
16
|
-
/** Use "sds" for configured SDS server, or provide a custom URL */
|
|
17
|
-
server?: "pds" | "sds" | string;
|
|
18
|
-
/** Custom server URL (overrides server option) */
|
|
19
|
-
serverUrl?: string;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Result of a create operation
|
|
24
|
-
*/
|
|
25
|
-
export interface CreateResult {
|
|
26
|
-
uri: string;
|
|
27
|
-
cid: string;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Result of an update operation
|
|
32
|
-
*/
|
|
33
|
-
export interface UpdateResult {
|
|
34
|
-
uri: string;
|
|
35
|
-
cid: string;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Paginated list result
|
|
40
|
-
*/
|
|
41
|
-
export interface PaginatedList<T> {
|
|
42
|
-
records: T[];
|
|
43
|
-
cursor?: string;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* List parameters
|
|
48
|
-
*/
|
|
49
|
-
export interface ListParams {
|
|
50
|
-
limit?: number;
|
|
51
|
-
cursor?: string;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// ============================================================================
|
|
55
|
-
// Collaborator Types
|
|
56
|
-
// ============================================================================
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Role for repository access
|
|
60
|
-
*/
|
|
61
|
-
export type RepositoryRole = "viewer" | "editor" | "admin" | "owner";
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Repository access grant
|
|
65
|
-
*/
|
|
66
|
-
export interface RepositoryAccessGrant {
|
|
67
|
-
userDid: string;
|
|
68
|
-
role: RepositoryRole;
|
|
69
|
-
permissions: CollaboratorPermissions;
|
|
70
|
-
grantedBy: string;
|
|
71
|
-
grantedAt: string;
|
|
72
|
-
revokedAt?: string;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// ============================================================================
|
|
76
|
-
// Organization Types
|
|
77
|
-
// ============================================================================
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Organization info
|
|
81
|
-
*/
|
|
82
|
-
export interface OrganizationInfo {
|
|
83
|
-
did: string;
|
|
84
|
-
handle: string;
|
|
85
|
-
name: string;
|
|
86
|
-
description?: string;
|
|
87
|
-
createdAt: string;
|
|
88
|
-
accessType: "owner" | "collaborator";
|
|
89
|
-
permissions: CollaboratorPermissions;
|
|
90
|
-
collaboratorCount?: number;
|
|
91
|
-
profile?: {
|
|
92
|
-
displayName?: string;
|
|
93
|
-
avatar?: string;
|
|
94
|
-
banner?: string;
|
|
95
|
-
website?: string;
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// ============================================================================
|
|
100
|
-
// Progress Types
|
|
101
|
-
// ============================================================================
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Progress step for long-running operations
|
|
105
|
-
*/
|
|
106
|
-
export interface ProgressStep {
|
|
107
|
-
name: string;
|
|
108
|
-
status: "start" | "success" | "error";
|
|
109
|
-
data?: unknown;
|
|
110
|
-
error?: Error;
|
|
111
|
-
}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* TypeScript types for hypercert lexicon schemas.
|
|
3
|
-
*
|
|
4
|
-
* Re-exports generated types and validation from `@hypercerts-org/lexicon`.
|
|
5
|
-
*
|
|
6
|
-
* @packageDocumentation
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
// Re-export everything from lexicon package
|
|
10
|
-
export {
|
|
11
|
-
// Namespaced types with validation (isRecord, validateRecord)
|
|
12
|
-
OrgHypercertsClaim,
|
|
13
|
-
OrgHypercertsClaimRights,
|
|
14
|
-
OrgHypercertsClaimContribution,
|
|
15
|
-
OrgHypercertsClaimMeasurement,
|
|
16
|
-
OrgHypercertsClaimEvaluation,
|
|
17
|
-
OrgHypercertsClaimEvidence,
|
|
18
|
-
OrgHypercertsCollection,
|
|
19
|
-
AppCertifiedLocation,
|
|
20
|
-
ComAtprotoRepoStrongRef,
|
|
21
|
-
// Validation utilities
|
|
22
|
-
validate,
|
|
23
|
-
schemas,
|
|
24
|
-
schemaDict,
|
|
25
|
-
lexicons,
|
|
26
|
-
ids,
|
|
27
|
-
// Lexicon constants
|
|
28
|
-
HYPERCERT_LEXICONS,
|
|
29
|
-
HYPERCERT_COLLECTIONS,
|
|
30
|
-
} from "@hypercerts-org/lexicon";
|
|
31
|
-
|
|
32
|
-
export type { AppCertifiedDefs } from "@hypercerts-org/lexicon";
|
|
33
|
-
|
|
34
|
-
import type {
|
|
35
|
-
OrgHypercertsClaim,
|
|
36
|
-
OrgHypercertsClaimRights,
|
|
37
|
-
OrgHypercertsClaimContribution,
|
|
38
|
-
OrgHypercertsClaimMeasurement,
|
|
39
|
-
OrgHypercertsClaimEvaluation,
|
|
40
|
-
OrgHypercertsCollection,
|
|
41
|
-
AppCertifiedLocation,
|
|
42
|
-
ComAtprotoRepoStrongRef,
|
|
43
|
-
} from "@hypercerts-org/lexicon";
|
|
44
|
-
|
|
45
|
-
// ============================================================================
|
|
46
|
-
// Type Aliases
|
|
47
|
-
// ============================================================================
|
|
48
|
-
|
|
49
|
-
export type StrongRef = ComAtprotoRepoStrongRef.Main;
|
|
50
|
-
export type HypercertClaim = OrgHypercertsClaim.Main;
|
|
51
|
-
export type HypercertRights = OrgHypercertsClaimRights.Main;
|
|
52
|
-
export type HypercertContribution = OrgHypercertsClaimContribution.Main;
|
|
53
|
-
export type HypercertMeasurement = OrgHypercertsClaimMeasurement.Main;
|
|
54
|
-
export type HypercertEvaluation = OrgHypercertsClaimEvaluation.Main;
|
|
55
|
-
export type HypercertCollection = OrgHypercertsCollection.Main;
|
|
56
|
-
export type HypercertCollectionClaimItem = OrgHypercertsCollection.ClaimItem;
|
|
57
|
-
export type HypercertLocation = AppCertifiedLocation.Main;
|
|
58
|
-
|
|
59
|
-
// ============================================================================
|
|
60
|
-
// SDK Input Helper Types
|
|
61
|
-
// ATProto API infers $type from the collection
|
|
62
|
-
// ============================================================================
|
|
63
|
-
|
|
64
|
-
/** Blob reference for uploaded files (images, GeoJSON, etc.) */
|
|
65
|
-
export interface BlobRef {
|
|
66
|
-
$type: "blob";
|
|
67
|
-
ref: { $link: string };
|
|
68
|
-
mimeType: string;
|
|
69
|
-
size: number;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/** Evidence item for operations */
|
|
73
|
-
export interface HypercertEvidence {
|
|
74
|
-
uri: string;
|
|
75
|
-
title?: string;
|
|
76
|
-
description?: string;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/** Image input for operations */
|
|
80
|
-
export type HypercertImage = { type: "uri"; uri: string } | { type: "blob"; blob: Blob };
|
|
81
|
-
|
|
82
|
-
/** Hypercert with AT Protocol metadata */
|
|
83
|
-
export interface HypercertWithMetadata {
|
|
84
|
-
uri: string;
|
|
85
|
-
cid: string;
|
|
86
|
-
record: HypercertClaim;
|
|
87
|
-
}
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import type { SessionStore } from "../core/interfaces.js";
|
|
2
|
-
import type { NodeSavedSession } from "@atproto/oauth-client-node";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* In-memory implementation of the SessionStore interface.
|
|
6
|
-
*
|
|
7
|
-
* This store keeps OAuth sessions in memory using a Map. It's intended
|
|
8
|
-
* for development, testing, and simple use cases where session persistence
|
|
9
|
-
* across restarts is not required.
|
|
10
|
-
*
|
|
11
|
-
* @remarks
|
|
12
|
-
* **Warning**: This implementation is **not suitable for production** because:
|
|
13
|
-
* - Sessions are lost when the process restarts
|
|
14
|
-
* - Sessions cannot be shared across multiple server instances
|
|
15
|
-
* - No automatic cleanup of expired sessions
|
|
16
|
-
*
|
|
17
|
-
* For production, implement {@link SessionStore} with a persistent backend:
|
|
18
|
-
* - **Redis**: Good for distributed systems, supports TTL
|
|
19
|
-
* - **PostgreSQL/MySQL**: Good for existing database infrastructure
|
|
20
|
-
* - **MongoDB**: Good for document-based storage
|
|
21
|
-
*
|
|
22
|
-
* @example Basic usage
|
|
23
|
-
* ```typescript
|
|
24
|
-
* import { InMemorySessionStore } from "@hypercerts-org/sdk/storage";
|
|
25
|
-
*
|
|
26
|
-
* const sessionStore = new InMemorySessionStore();
|
|
27
|
-
*
|
|
28
|
-
* const sdk = new ATProtoSDK({
|
|
29
|
-
* oauth: { ... },
|
|
30
|
-
* storage: {
|
|
31
|
-
* sessionStore, // Will warn in logs for production
|
|
32
|
-
* },
|
|
33
|
-
* });
|
|
34
|
-
* ```
|
|
35
|
-
*
|
|
36
|
-
* @example Testing usage
|
|
37
|
-
* ```typescript
|
|
38
|
-
* const sessionStore = new InMemorySessionStore();
|
|
39
|
-
*
|
|
40
|
-
* // After tests, clean up
|
|
41
|
-
* sessionStore.clear();
|
|
42
|
-
* ```
|
|
43
|
-
*
|
|
44
|
-
* @see {@link SessionStore} for the interface definition
|
|
45
|
-
* @see {@link InMemoryStateStore} for the corresponding state store
|
|
46
|
-
*/
|
|
47
|
-
export class InMemorySessionStore implements SessionStore {
|
|
48
|
-
/**
|
|
49
|
-
* Internal storage for sessions, keyed by DID.
|
|
50
|
-
* @internal
|
|
51
|
-
*/
|
|
52
|
-
private sessions = new Map<string, NodeSavedSession>();
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Retrieves a session by DID.
|
|
56
|
-
*
|
|
57
|
-
* @param did - The user's Decentralized Identifier
|
|
58
|
-
* @returns Promise resolving to the session, or `undefined` if not found
|
|
59
|
-
*
|
|
60
|
-
* @example
|
|
61
|
-
* ```typescript
|
|
62
|
-
* const session = await sessionStore.get("did:plc:abc123");
|
|
63
|
-
* if (session) {
|
|
64
|
-
* console.log("Session found");
|
|
65
|
-
* }
|
|
66
|
-
* ```
|
|
67
|
-
*/
|
|
68
|
-
async get(did: string): Promise<NodeSavedSession | undefined> {
|
|
69
|
-
return this.sessions.get(did);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Stores or updates a session.
|
|
74
|
-
*
|
|
75
|
-
* @param did - The user's DID to use as the key
|
|
76
|
-
* @param session - The session data to store
|
|
77
|
-
*
|
|
78
|
-
* @remarks
|
|
79
|
-
* If a session already exists for the DID, it is overwritten.
|
|
80
|
-
*
|
|
81
|
-
* @example
|
|
82
|
-
* ```typescript
|
|
83
|
-
* await sessionStore.set("did:plc:abc123", sessionData);
|
|
84
|
-
* ```
|
|
85
|
-
*/
|
|
86
|
-
async set(did: string, session: NodeSavedSession): Promise<void> {
|
|
87
|
-
this.sessions.set(did, session);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Deletes a session by DID.
|
|
92
|
-
*
|
|
93
|
-
* @param did - The DID of the session to delete
|
|
94
|
-
*
|
|
95
|
-
* @remarks
|
|
96
|
-
* If no session exists for the DID, this is a no-op.
|
|
97
|
-
*
|
|
98
|
-
* @example
|
|
99
|
-
* ```typescript
|
|
100
|
-
* await sessionStore.del("did:plc:abc123");
|
|
101
|
-
* ```
|
|
102
|
-
*/
|
|
103
|
-
async del(did: string): Promise<void> {
|
|
104
|
-
this.sessions.delete(did);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Clears all stored sessions.
|
|
109
|
-
*
|
|
110
|
-
* This is primarily useful for testing to ensure a clean state
|
|
111
|
-
* between test runs.
|
|
112
|
-
*
|
|
113
|
-
* @remarks
|
|
114
|
-
* This method is synchronous (not async) for convenience in test cleanup.
|
|
115
|
-
*
|
|
116
|
-
* @example
|
|
117
|
-
* ```typescript
|
|
118
|
-
* // In test teardown
|
|
119
|
-
* afterEach(() => {
|
|
120
|
-
* sessionStore.clear();
|
|
121
|
-
* });
|
|
122
|
-
* ```
|
|
123
|
-
*/
|
|
124
|
-
clear(): void {
|
|
125
|
-
this.sessions.clear();
|
|
126
|
-
}
|
|
127
|
-
}
|
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import type { StateStore } from "../core/interfaces.js";
|
|
2
|
-
import type { NodeSavedState } from "@atproto/oauth-client-node";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* In-memory implementation of the StateStore interface.
|
|
6
|
-
*
|
|
7
|
-
* This store keeps OAuth state parameters in memory using a Map. State is
|
|
8
|
-
* used during the OAuth authorization flow for CSRF protection and PKCE.
|
|
9
|
-
*
|
|
10
|
-
* @remarks
|
|
11
|
-
* **Warning**: This implementation is **not suitable for production** because:
|
|
12
|
-
* - State is lost when the process restarts (breaking in-progress OAuth flows)
|
|
13
|
-
* - State cannot be shared across multiple server instances
|
|
14
|
-
* - No automatic cleanup of expired state (memory leak potential)
|
|
15
|
-
*
|
|
16
|
-
* For production, implement {@link StateStore} with a persistent backend
|
|
17
|
-
* that supports TTL (time-to-live):
|
|
18
|
-
* - **Redis**: Ideal choice with built-in TTL support
|
|
19
|
-
* - **Database with cleanup job**: PostgreSQL/MySQL with periodic cleanup
|
|
20
|
-
*
|
|
21
|
-
* **State Lifecycle**:
|
|
22
|
-
* 1. Created when user starts OAuth flow (`authorize()`)
|
|
23
|
-
* 2. Retrieved and validated during callback
|
|
24
|
-
* 3. Deleted after successful or failed callback
|
|
25
|
-
* 4. Should expire after ~15 minutes if callback never happens
|
|
26
|
-
*
|
|
27
|
-
* @example Basic usage
|
|
28
|
-
* ```typescript
|
|
29
|
-
* import { InMemoryStateStore } from "@hypercerts-org/sdk/storage";
|
|
30
|
-
*
|
|
31
|
-
* const stateStore = new InMemoryStateStore();
|
|
32
|
-
*
|
|
33
|
-
* const sdk = new ATProtoSDK({
|
|
34
|
-
* oauth: { ... },
|
|
35
|
-
* storage: {
|
|
36
|
-
* stateStore, // Will warn in logs for production
|
|
37
|
-
* },
|
|
38
|
-
* });
|
|
39
|
-
* ```
|
|
40
|
-
*
|
|
41
|
-
* @example Testing usage
|
|
42
|
-
* ```typescript
|
|
43
|
-
* const stateStore = new InMemoryStateStore();
|
|
44
|
-
*
|
|
45
|
-
* // After tests, clean up
|
|
46
|
-
* stateStore.clear();
|
|
47
|
-
* ```
|
|
48
|
-
*
|
|
49
|
-
* @see {@link StateStore} for the interface definition
|
|
50
|
-
* @see {@link InMemorySessionStore} for the corresponding session store
|
|
51
|
-
*/
|
|
52
|
-
export class InMemoryStateStore implements StateStore {
|
|
53
|
-
/**
|
|
54
|
-
* Internal storage for OAuth state, keyed by state string.
|
|
55
|
-
* @internal
|
|
56
|
-
*/
|
|
57
|
-
private states = new Map<string, NodeSavedState>();
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Retrieves OAuth state by key.
|
|
61
|
-
*
|
|
62
|
-
* @param key - The state key (random string from authorization URL)
|
|
63
|
-
* @returns Promise resolving to the state, or `undefined` if not found
|
|
64
|
-
*
|
|
65
|
-
* @remarks
|
|
66
|
-
* The key is a cryptographically random string generated during
|
|
67
|
-
* the authorization request. It's included in the callback URL
|
|
68
|
-
* and used to retrieve the associated PKCE verifier and other data.
|
|
69
|
-
*
|
|
70
|
-
* @example
|
|
71
|
-
* ```typescript
|
|
72
|
-
* // During OAuth callback
|
|
73
|
-
* const state = await stateStore.get(params.get("state")!);
|
|
74
|
-
* if (!state) {
|
|
75
|
-
* throw new Error("Invalid or expired state");
|
|
76
|
-
* }
|
|
77
|
-
* ```
|
|
78
|
-
*/
|
|
79
|
-
async get(key: string): Promise<NodeSavedState | undefined> {
|
|
80
|
-
return this.states.get(key);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Stores OAuth state temporarily.
|
|
85
|
-
*
|
|
86
|
-
* @param key - The state key to use for storage
|
|
87
|
-
* @param state - The OAuth state data (includes PKCE verifier, etc.)
|
|
88
|
-
*
|
|
89
|
-
* @remarks
|
|
90
|
-
* In production implementations, state should be stored with a TTL
|
|
91
|
-
* of approximately 10-15 minutes to prevent stale state accumulation.
|
|
92
|
-
*
|
|
93
|
-
* @example
|
|
94
|
-
* ```typescript
|
|
95
|
-
* // Called internally by OAuthClient during authorize()
|
|
96
|
-
* await stateStore.set(stateKey, {
|
|
97
|
-
* // PKCE code verifier, redirect URI, etc.
|
|
98
|
-
* });
|
|
99
|
-
* ```
|
|
100
|
-
*/
|
|
101
|
-
async set(key: string, state: NodeSavedState): Promise<void> {
|
|
102
|
-
this.states.set(key, state);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Deletes OAuth state by key.
|
|
107
|
-
*
|
|
108
|
-
* @param key - The state key to delete
|
|
109
|
-
*
|
|
110
|
-
* @remarks
|
|
111
|
-
* Called after the OAuth callback is processed (whether successful or not)
|
|
112
|
-
* to clean up the temporary state.
|
|
113
|
-
*
|
|
114
|
-
* @example
|
|
115
|
-
* ```typescript
|
|
116
|
-
* // After processing callback
|
|
117
|
-
* await stateStore.del(stateKey);
|
|
118
|
-
* ```
|
|
119
|
-
*/
|
|
120
|
-
async del(key: string): Promise<void> {
|
|
121
|
-
this.states.delete(key);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Clears all stored state.
|
|
126
|
-
*
|
|
127
|
-
* This is primarily useful for testing to ensure a clean state
|
|
128
|
-
* between test runs.
|
|
129
|
-
*
|
|
130
|
-
* @remarks
|
|
131
|
-
* This method is synchronous (not async) for convenience in test cleanup.
|
|
132
|
-
* In production, be careful using this as it will invalidate all
|
|
133
|
-
* in-progress OAuth flows.
|
|
134
|
-
*
|
|
135
|
-
* @example
|
|
136
|
-
* ```typescript
|
|
137
|
-
* // In test teardown
|
|
138
|
-
* afterEach(() => {
|
|
139
|
-
* stateStore.clear();
|
|
140
|
-
* });
|
|
141
|
-
* ```
|
|
142
|
-
*/
|
|
143
|
-
clear(): void {
|
|
144
|
-
this.states.clear();
|
|
145
|
-
}
|
|
146
|
-
}
|
package/src/storage.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Storage entrypoint - Storage implementations and interfaces
|
|
3
|
-
*
|
|
4
|
-
* This module provides storage adapters for persisting OAuth sessions and state.
|
|
5
|
-
* Includes in-memory implementations for development and testing, plus interfaces
|
|
6
|
-
* for implementing custom storage backends (Redis, database, etc.).
|
|
7
|
-
*
|
|
8
|
-
* @remarks
|
|
9
|
-
* The in-memory implementations are suitable for:
|
|
10
|
-
* - Development and testing environments
|
|
11
|
-
* - Single-server deployments with acceptable session loss on restart
|
|
12
|
-
* - Prototyping and demos
|
|
13
|
-
*
|
|
14
|
-
* For production multi-server deployments, implement the interfaces with
|
|
15
|
-
* a distributed storage backend like Redis, PostgreSQL, or a managed
|
|
16
|
-
* key-value store.
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```typescript
|
|
20
|
-
* // Using built-in in-memory stores (development)
|
|
21
|
-
* import { InMemorySessionStore, InMemoryStateStore } from "@hypercerts-org/sdk";
|
|
22
|
-
*
|
|
23
|
-
* const sessionStore = new InMemorySessionStore();
|
|
24
|
-
* const stateStore = new InMemoryStateStore();
|
|
25
|
-
*
|
|
26
|
-
* const sdk = new HypercertsSDK({
|
|
27
|
-
* sessionStore,
|
|
28
|
-
* stateStore,
|
|
29
|
-
* // ... other config
|
|
30
|
-
* });
|
|
31
|
-
* ```
|
|
32
|
-
*
|
|
33
|
-
* @example
|
|
34
|
-
* ```typescript
|
|
35
|
-
* // Implementing custom storage (production)
|
|
36
|
-
* import type { SessionStore, StateStore } from "@hypercerts-org/sdk";
|
|
37
|
-
* import Redis from "ioredis";
|
|
38
|
-
*
|
|
39
|
-
* class RedisSessionStore implements SessionStore {
|
|
40
|
-
* constructor(private redis: Redis) {}
|
|
41
|
-
*
|
|
42
|
-
* async get(did: string) {
|
|
43
|
-
* const data = await this.redis.get(`session:${did}`);
|
|
44
|
-
* return data ? JSON.parse(data) : undefined;
|
|
45
|
-
* }
|
|
46
|
-
*
|
|
47
|
-
* async set(did: string, session: Session) {
|
|
48
|
-
* await this.redis.set(`session:${did}`, JSON.stringify(session));
|
|
49
|
-
* }
|
|
50
|
-
*
|
|
51
|
-
* async delete(did: string) {
|
|
52
|
-
* await this.redis.del(`session:${did}`);
|
|
53
|
-
* }
|
|
54
|
-
* }
|
|
55
|
-
* ```
|
|
56
|
-
*
|
|
57
|
-
* @packageDocumentation
|
|
58
|
-
*/
|
|
59
|
-
|
|
60
|
-
export { InMemorySessionStore } from "./storage/InMemorySessionStore.js";
|
|
61
|
-
export { InMemoryStateStore } from "./storage/InMemoryStateStore.js";
|
|
62
|
-
|
|
63
|
-
export type { SessionStore, StateStore, CacheInterface } from "./core/interfaces.js";
|
package/src/testing/index.ts
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Testing utilities for the Hypercerts SDK.
|
|
3
|
-
*
|
|
4
|
-
* This module exports mock implementations and factory functions
|
|
5
|
-
* for testing applications that use the SDK.
|
|
6
|
-
*
|
|
7
|
-
* @remarks
|
|
8
|
-
* Import from `@hypercerts-org/sdk/testing` to access these utilities:
|
|
9
|
-
*
|
|
10
|
-
* ```typescript
|
|
11
|
-
* import {
|
|
12
|
-
* createMockSession,
|
|
13
|
-
* createTestConfig,
|
|
14
|
-
* MockSessionStore,
|
|
15
|
-
* MockStateStore,
|
|
16
|
-
* } from "@hypercerts-org/sdk/testing";
|
|
17
|
-
* ```
|
|
18
|
-
*
|
|
19
|
-
* **Available Utilities**:
|
|
20
|
-
*
|
|
21
|
-
* - {@link createMockSession} - Factory for mock OAuth sessions
|
|
22
|
-
* - {@link createTestConfig} - Factory for test SDK configurations
|
|
23
|
-
* - {@link MockSessionStore} - Mock session store with call tracking
|
|
24
|
-
* - {@link MockStateStore} - Mock state store with call tracking
|
|
25
|
-
*
|
|
26
|
-
* @example Setting up tests
|
|
27
|
-
* ```typescript
|
|
28
|
-
* import { ATProtoSDK } from "@hypercerts-org/sdk";
|
|
29
|
-
* import {
|
|
30
|
-
* createTestConfig,
|
|
31
|
-
* createMockSession,
|
|
32
|
-
* MockSessionStore,
|
|
33
|
-
* MockStateStore,
|
|
34
|
-
* } from "@hypercerts-org/sdk/testing";
|
|
35
|
-
*
|
|
36
|
-
* describe("MyApp", () => {
|
|
37
|
-
* let sdk: ATProtoSDK;
|
|
38
|
-
* let sessionStore: MockSessionStore;
|
|
39
|
-
* let stateStore: MockStateStore;
|
|
40
|
-
*
|
|
41
|
-
* beforeEach(() => {
|
|
42
|
-
* sessionStore = new MockSessionStore();
|
|
43
|
-
* stateStore = new MockStateStore();
|
|
44
|
-
*
|
|
45
|
-
* sdk = new ATProtoSDK(createTestConfig({
|
|
46
|
-
* storage: { sessionStore, stateStore },
|
|
47
|
-
* }));
|
|
48
|
-
* });
|
|
49
|
-
*
|
|
50
|
-
* afterEach(() => {
|
|
51
|
-
* sessionStore.reset();
|
|
52
|
-
* stateStore.reset();
|
|
53
|
-
* });
|
|
54
|
-
*
|
|
55
|
-
* it("should work with mock session", () => {
|
|
56
|
-
* const session = createMockSession();
|
|
57
|
-
* const repo = sdk.repository(session);
|
|
58
|
-
* // ... test repository operations
|
|
59
|
-
* });
|
|
60
|
-
* });
|
|
61
|
-
* ```
|
|
62
|
-
*
|
|
63
|
-
* @packageDocumentation
|
|
64
|
-
*/
|
|
65
|
-
|
|
66
|
-
export { createMockSession, createTestConfig } from "./mocks.js";
|
|
67
|
-
export { MockSessionStore, MockStateStore } from "./stores.js";
|