@hypercerts-org/sdk-core 0.2.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/.turbo/turbo-build.log +328 -0
- package/.turbo/turbo-test.log +118 -0
- package/CHANGELOG.md +16 -0
- package/LICENSE +21 -0
- package/README.md +100 -0
- package/dist/errors.cjs +260 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.ts +233 -0
- package/dist/errors.mjs +253 -0
- package/dist/errors.mjs.map +1 -0
- package/dist/index.cjs +4531 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +3430 -0
- package/dist/index.mjs +4448 -0
- package/dist/index.mjs.map +1 -0
- package/dist/lexicons.cjs +420 -0
- package/dist/lexicons.cjs.map +1 -0
- package/dist/lexicons.d.ts +227 -0
- package/dist/lexicons.mjs +410 -0
- package/dist/lexicons.mjs.map +1 -0
- package/dist/storage.cjs +270 -0
- package/dist/storage.cjs.map +1 -0
- package/dist/storage.d.ts +474 -0
- package/dist/storage.mjs +267 -0
- package/dist/storage.mjs.map +1 -0
- package/dist/testing.cjs +415 -0
- package/dist/testing.cjs.map +1 -0
- package/dist/testing.d.ts +928 -0
- package/dist/testing.mjs +410 -0
- package/dist/testing.mjs.map +1 -0
- package/dist/types.cjs +220 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.ts +2118 -0
- package/dist/types.mjs +212 -0
- package/dist/types.mjs.map +1 -0
- package/eslint.config.mjs +22 -0
- package/package.json +90 -0
- package/rollup.config.js +75 -0
- package/src/auth/OAuthClient.ts +497 -0
- package/src/core/SDK.ts +410 -0
- package/src/core/config.ts +243 -0
- package/src/core/errors.ts +257 -0
- package/src/core/interfaces.ts +324 -0
- package/src/core/types.ts +281 -0
- package/src/errors.ts +57 -0
- package/src/index.ts +107 -0
- package/src/lexicons.ts +64 -0
- package/src/repository/BlobOperationsImpl.ts +199 -0
- package/src/repository/CollaboratorOperationsImpl.ts +288 -0
- package/src/repository/HypercertOperationsImpl.ts +1146 -0
- package/src/repository/LexiconRegistry.ts +332 -0
- package/src/repository/OrganizationOperationsImpl.ts +234 -0
- package/src/repository/ProfileOperationsImpl.ts +281 -0
- package/src/repository/RecordOperationsImpl.ts +340 -0
- package/src/repository/Repository.ts +482 -0
- package/src/repository/interfaces.ts +868 -0
- package/src/repository/types.ts +111 -0
- package/src/services/hypercerts/types.ts +87 -0
- package/src/storage/InMemorySessionStore.ts +127 -0
- package/src/storage/InMemoryStateStore.ts +146 -0
- package/src/storage.ts +63 -0
- package/src/testing/index.ts +67 -0
- package/src/testing/mocks.ts +142 -0
- package/src/testing/stores.ts +285 -0
- package/src/testing.ts +64 -0
- package/src/types.ts +86 -0
- package/tests/auth/OAuthClient.test.ts +164 -0
- package/tests/core/SDK.test.ts +176 -0
- package/tests/core/errors.test.ts +81 -0
- package/tests/repository/BlobOperationsImpl.test.ts +154 -0
- package/tests/repository/CollaboratorOperationsImpl.test.ts +323 -0
- package/tests/repository/HypercertOperationsImpl.test.ts +652 -0
- package/tests/repository/LexiconRegistry.test.ts +192 -0
- package/tests/repository/OrganizationOperationsImpl.test.ts +242 -0
- package/tests/repository/ProfileOperationsImpl.test.ts +254 -0
- package/tests/repository/RecordOperationsImpl.test.ts +375 -0
- package/tests/repository/Repository.test.ts +149 -0
- package/tests/utils/fixtures.ts +117 -0
- package/tests/utils/mocks.ts +109 -0
- package/tests/utils/repository-fixtures.ts +78 -0
- package/tsconfig.json +11 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/vitest.config.ts +30 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import type { SessionStore, StateStore, CacheInterface, LoggerInterface } from "../../src/core/interfaces.js";
|
|
2
|
+
import type { NodeSavedSession, NodeSavedState } from "@atproto/oauth-client-node";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* In-memory session store for testing
|
|
6
|
+
*/
|
|
7
|
+
export class InMemorySessionStore implements SessionStore {
|
|
8
|
+
private sessions = new Map<string, NodeSavedSession>();
|
|
9
|
+
|
|
10
|
+
async get(did: string): Promise<NodeSavedSession | undefined> {
|
|
11
|
+
return this.sessions.get(did);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async set(did: string, session: NodeSavedSession): Promise<void> {
|
|
15
|
+
this.sessions.set(did, session);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async del(did: string): Promise<void> {
|
|
19
|
+
this.sessions.delete(did);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
clear(): void {
|
|
23
|
+
this.sessions.clear();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* In-memory state store for testing
|
|
29
|
+
*/
|
|
30
|
+
export class InMemoryStateStore implements StateStore {
|
|
31
|
+
private states = new Map<string, NodeSavedState>();
|
|
32
|
+
|
|
33
|
+
async get(key: string): Promise<NodeSavedState | undefined> {
|
|
34
|
+
return this.states.get(key);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async set(key: string, state: NodeSavedState): Promise<void> {
|
|
38
|
+
this.states.set(key, state);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async del(key: string): Promise<void> {
|
|
42
|
+
this.states.delete(key);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
clear(): void {
|
|
46
|
+
this.states.clear();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* In-memory cache for testing
|
|
52
|
+
*/
|
|
53
|
+
export class InMemoryCache implements CacheInterface {
|
|
54
|
+
private cache = new Map<string, { value: unknown; expiresAt?: number }>();
|
|
55
|
+
|
|
56
|
+
async get<T>(key: string): Promise<T | undefined> {
|
|
57
|
+
const entry = this.cache.get(key);
|
|
58
|
+
if (!entry) {
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (entry.expiresAt && Date.now() > entry.expiresAt) {
|
|
63
|
+
this.cache.delete(key);
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return entry.value as T;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async set<T>(key: string, value: T, ttlSeconds?: number): Promise<void> {
|
|
71
|
+
const expiresAt = ttlSeconds ? Date.now() + ttlSeconds * 1000 : undefined;
|
|
72
|
+
this.cache.set(key, { value, expiresAt });
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async del(key: string): Promise<void> {
|
|
76
|
+
this.cache.delete(key);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async clear(): Promise<void> {
|
|
80
|
+
this.cache.clear();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Mock logger for testing
|
|
86
|
+
*/
|
|
87
|
+
export class MockLogger implements LoggerInterface {
|
|
88
|
+
public logs: Array<{ level: string; message: string; args: unknown[] }> = [];
|
|
89
|
+
|
|
90
|
+
debug(message: string, ...args: unknown[]): void {
|
|
91
|
+
this.logs.push({ level: "debug", message, args });
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
info(message: string, ...args: unknown[]): void {
|
|
95
|
+
this.logs.push({ level: "info", message, args });
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
warn(message: string, ...args: unknown[]): void {
|
|
99
|
+
this.logs.push({ level: "warn", message, args });
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
error(message: string, ...args: unknown[]): void {
|
|
103
|
+
this.logs.push({ level: "error", message, args });
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
clear(): void {
|
|
107
|
+
this.logs = [];
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { LexiconDoc } from "@atproto/lexicon";
|
|
2
|
+
import type { Session } from "../../src/core/types.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Create a mock OAuth session for testing
|
|
6
|
+
*/
|
|
7
|
+
export function createMockSession(overrides?: Partial<Session>): Session {
|
|
8
|
+
const defaultServerMetadata = {
|
|
9
|
+
issuer: "https://pds.example.com",
|
|
10
|
+
authorization_endpoint: "https://pds.example.com/oauth/authorize",
|
|
11
|
+
token_endpoint: "https://pds.example.com/oauth/token",
|
|
12
|
+
token_endpoint_auth_methods_supported: ["private_key_jwt"],
|
|
13
|
+
code_challenge_methods_supported: ["S256"],
|
|
14
|
+
dpop_signing_alg_values_supported: ["ES256"],
|
|
15
|
+
} as const;
|
|
16
|
+
|
|
17
|
+
const defaultFetchHandler = async (_url: string, _options?: RequestInit): Promise<Response> => {
|
|
18
|
+
// Mock fetch handler - tests will override this
|
|
19
|
+
return new Response(JSON.stringify({}), { status: 200 });
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const mockSession: Session = {
|
|
23
|
+
sub: "did:plc:testdid123456789012345678901234567890",
|
|
24
|
+
did: "did:plc:testdid123456789012345678901234567890",
|
|
25
|
+
serverMetadata: defaultServerMetadata,
|
|
26
|
+
fetchHandler: overrides?.fetchHandler ?? defaultFetchHandler,
|
|
27
|
+
getTokenInfo: async () => ({
|
|
28
|
+
expiresAt: new Date(Date.now() + 3600 * 1000),
|
|
29
|
+
expired: false,
|
|
30
|
+
scope: "atproto",
|
|
31
|
+
iss: "https://pds.example.com",
|
|
32
|
+
aud: "https://example.com/atproto-client-metadata.json",
|
|
33
|
+
sub: "did:plc:testdid123456789012345678901234567890",
|
|
34
|
+
}),
|
|
35
|
+
signOut: async () => {},
|
|
36
|
+
...overrides,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
return mockSession;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Create a mock lexicon document for testing
|
|
44
|
+
*/
|
|
45
|
+
export function createMockLexicon(id: string): LexiconDoc {
|
|
46
|
+
return {
|
|
47
|
+
lexicon: 1,
|
|
48
|
+
id,
|
|
49
|
+
defs: {
|
|
50
|
+
record: {
|
|
51
|
+
type: "record" as const,
|
|
52
|
+
record: {
|
|
53
|
+
type: "object" as const,
|
|
54
|
+
properties: {
|
|
55
|
+
text: { type: "string" as const },
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
} as LexiconDoc;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Create a mock blob reference
|
|
65
|
+
*/
|
|
66
|
+
export function createMockBlobRef(): {
|
|
67
|
+
$type: string;
|
|
68
|
+
ref: { $link: string };
|
|
69
|
+
mimeType: string;
|
|
70
|
+
size: number;
|
|
71
|
+
} {
|
|
72
|
+
return {
|
|
73
|
+
$type: "blob",
|
|
74
|
+
ref: { $link: "bafyrei..." },
|
|
75
|
+
mimeType: "image/png",
|
|
76
|
+
size: 1024,
|
|
77
|
+
};
|
|
78
|
+
}
|
package/tsconfig.json
ADDED