@hypercerts-org/sdk-core 0.9.0-beta.0 → 0.10.0-beta.1
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/CHANGELOG.md +273 -0
- package/README.md +132 -105
- package/dist/index.cjs +1756 -664
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1341 -276
- package/dist/index.mjs +1700 -647
- package/dist/index.mjs.map +1 -1
- package/dist/lexicons.cjs +103 -374
- package/dist/lexicons.cjs.map +1 -1
- package/dist/lexicons.d.ts +90 -188
- package/dist/lexicons.mjs +103 -367
- package/dist/lexicons.mjs.map +1 -1
- package/dist/testing.d.ts +26 -1
- package/dist/types.cjs +33 -2
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.ts +113 -42
- package/dist/types.mjs +29 -2
- package/dist/types.mjs.map +1 -1
- package/package.json +10 -9
package/dist/index.d.ts
CHANGED
|
@@ -1,231 +1,11 @@
|
|
|
1
|
-
import { Agent } from '@atproto/api';
|
|
2
|
-
import { LexiconDoc } from '@atproto/lexicon';
|
|
3
1
|
import { NodeSavedSession, NodeSavedState, OAuthSession } from '@atproto/oauth-client-node';
|
|
4
2
|
import { z } from 'zod';
|
|
5
3
|
import { EventEmitter } from 'eventemitter3';
|
|
6
|
-
import {
|
|
7
|
-
export { AppCertifiedDefs, AppCertifiedLocation, ComAtprotoRepoStrongRef,
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
*/
|
|
12
|
-
interface ValidationResult {
|
|
13
|
-
/**
|
|
14
|
-
* Whether the record is valid according to the lexicon schema.
|
|
15
|
-
*/
|
|
16
|
-
valid: boolean;
|
|
17
|
-
/**
|
|
18
|
-
* Error message if validation failed.
|
|
19
|
-
*
|
|
20
|
-
* Only present when `valid` is `false`.
|
|
21
|
-
*/
|
|
22
|
-
error?: string;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Registry for managing and validating AT Protocol lexicon schemas.
|
|
26
|
-
*
|
|
27
|
-
* Lexicons are schema definitions that describe the structure of records
|
|
28
|
-
* in the AT Protocol. This registry allows you to:
|
|
29
|
-
*
|
|
30
|
-
* - Register custom lexicons for your application's record types
|
|
31
|
-
* - Validate records against their lexicon schemas
|
|
32
|
-
* - Extend the AT Protocol Agent with custom lexicon support
|
|
33
|
-
*
|
|
34
|
-
* @remarks
|
|
35
|
-
* The SDK automatically registers hypercert lexicons when creating a Repository.
|
|
36
|
-
* You only need to use this class directly if you're working with custom
|
|
37
|
-
* record types.
|
|
38
|
-
*
|
|
39
|
-
* **Lexicon IDs** follow the NSID (Namespaced Identifier) format:
|
|
40
|
-
* `{authority}.{name}` (e.g., `org.hypercerts.hypercert`)
|
|
41
|
-
*
|
|
42
|
-
* @example Registering custom lexicons
|
|
43
|
-
* ```typescript
|
|
44
|
-
* const registry = sdk.getLexiconRegistry();
|
|
45
|
-
*
|
|
46
|
-
* // Register a single lexicon
|
|
47
|
-
* registry.register({
|
|
48
|
-
* lexicon: 1,
|
|
49
|
-
* id: "org.example.myRecord",
|
|
50
|
-
* defs: {
|
|
51
|
-
* main: {
|
|
52
|
-
* type: "record",
|
|
53
|
-
* key: "tid",
|
|
54
|
-
* record: {
|
|
55
|
-
* type: "object",
|
|
56
|
-
* required: ["title", "createdAt"],
|
|
57
|
-
* properties: {
|
|
58
|
-
* title: { type: "string" },
|
|
59
|
-
* description: { type: "string" },
|
|
60
|
-
* createdAt: { type: "string", format: "datetime" },
|
|
61
|
-
* },
|
|
62
|
-
* },
|
|
63
|
-
* },
|
|
64
|
-
* },
|
|
65
|
-
* });
|
|
66
|
-
*
|
|
67
|
-
* // Register multiple lexicons at once
|
|
68
|
-
* registry.registerMany([lexicon1, lexicon2, lexicon3]);
|
|
69
|
-
* ```
|
|
70
|
-
*
|
|
71
|
-
* @example Validating records
|
|
72
|
-
* ```typescript
|
|
73
|
-
* const result = registry.validate("org.example.myRecord", {
|
|
74
|
-
* title: "Test",
|
|
75
|
-
* createdAt: new Date().toISOString(),
|
|
76
|
-
* });
|
|
77
|
-
*
|
|
78
|
-
* if (!result.valid) {
|
|
79
|
-
* console.error(`Validation failed: ${result.error}`);
|
|
80
|
-
* }
|
|
81
|
-
* ```
|
|
82
|
-
*
|
|
83
|
-
* @see https://atproto.com/specs/lexicon for the Lexicon specification
|
|
84
|
-
*/
|
|
85
|
-
declare class LexiconRegistry {
|
|
86
|
-
/** Map of lexicon ID to lexicon document */
|
|
87
|
-
private lexicons;
|
|
88
|
-
/** Lexicons collection for validation */
|
|
89
|
-
private lexiconsCollection;
|
|
90
|
-
/**
|
|
91
|
-
* Creates a new LexiconRegistry.
|
|
92
|
-
*
|
|
93
|
-
* The registry starts empty. Use {@link register} or {@link registerMany}
|
|
94
|
-
* to add lexicons.
|
|
95
|
-
*/
|
|
96
|
-
constructor();
|
|
97
|
-
/**
|
|
98
|
-
* Registers a single lexicon schema.
|
|
99
|
-
*
|
|
100
|
-
* @param lexicon - The lexicon document to register
|
|
101
|
-
* @throws {@link ValidationError} if the lexicon doesn't have an `id` field
|
|
102
|
-
*
|
|
103
|
-
* @remarks
|
|
104
|
-
* If a lexicon with the same ID is already registered, it will be
|
|
105
|
-
* replaced with the new definition. This is useful for testing but
|
|
106
|
-
* should generally be avoided in production.
|
|
107
|
-
*
|
|
108
|
-
* @example
|
|
109
|
-
* ```typescript
|
|
110
|
-
* registry.register({
|
|
111
|
-
* lexicon: 1,
|
|
112
|
-
* id: "org.example.post",
|
|
113
|
-
* defs: {
|
|
114
|
-
* main: {
|
|
115
|
-
* type: "record",
|
|
116
|
-
* key: "tid",
|
|
117
|
-
* record: {
|
|
118
|
-
* type: "object",
|
|
119
|
-
* required: ["text", "createdAt"],
|
|
120
|
-
* properties: {
|
|
121
|
-
* text: { type: "string", maxLength: 300 },
|
|
122
|
-
* createdAt: { type: "string", format: "datetime" },
|
|
123
|
-
* },
|
|
124
|
-
* },
|
|
125
|
-
* },
|
|
126
|
-
* },
|
|
127
|
-
* });
|
|
128
|
-
* ```
|
|
129
|
-
*/
|
|
130
|
-
register(lexicon: LexiconDoc): void;
|
|
131
|
-
/**
|
|
132
|
-
* Registers multiple lexicons at once.
|
|
133
|
-
*
|
|
134
|
-
* @param lexicons - Array of lexicon documents to register
|
|
135
|
-
*
|
|
136
|
-
* @example
|
|
137
|
-
* ```typescript
|
|
138
|
-
* import { HYPERCERT_LEXICONS } from "@hypercerts-org/sdk/lexicons";
|
|
139
|
-
*
|
|
140
|
-
* registry.registerMany(HYPERCERT_LEXICONS);
|
|
141
|
-
* ```
|
|
142
|
-
*/
|
|
143
|
-
registerMany(lexicons: LexiconDoc[]): void;
|
|
144
|
-
/**
|
|
145
|
-
* Gets a lexicon document by ID.
|
|
146
|
-
*
|
|
147
|
-
* @param id - The lexicon NSID (e.g., "org.hypercerts.hypercert")
|
|
148
|
-
* @returns The lexicon document, or `undefined` if not registered
|
|
149
|
-
*
|
|
150
|
-
* @example
|
|
151
|
-
* ```typescript
|
|
152
|
-
* const lexicon = registry.get("org.hypercerts.hypercert");
|
|
153
|
-
* if (lexicon) {
|
|
154
|
-
* console.log(`Found lexicon: ${lexicon.id}`);
|
|
155
|
-
* }
|
|
156
|
-
* ```
|
|
157
|
-
*/
|
|
158
|
-
get(id: string): LexiconDoc | undefined;
|
|
159
|
-
/**
|
|
160
|
-
* Validates a record against a collection's lexicon schema.
|
|
161
|
-
*
|
|
162
|
-
* @param collection - The collection NSID (same as lexicon ID)
|
|
163
|
-
* @param record - The record data to validate
|
|
164
|
-
* @returns Validation result with `valid` boolean and optional `error` message
|
|
165
|
-
*
|
|
166
|
-
* @remarks
|
|
167
|
-
* - If no lexicon is registered for the collection, validation passes
|
|
168
|
-
* (we can't validate against unknown schemas)
|
|
169
|
-
* - Validation checks required fields and type constraints defined
|
|
170
|
-
* in the lexicon schema
|
|
171
|
-
*
|
|
172
|
-
* @example
|
|
173
|
-
* ```typescript
|
|
174
|
-
* const result = registry.validate("org.hypercerts.hypercert", {
|
|
175
|
-
* title: "My Hypercert",
|
|
176
|
-
* description: "Description...",
|
|
177
|
-
* // ... other fields
|
|
178
|
-
* });
|
|
179
|
-
*
|
|
180
|
-
* if (!result.valid) {
|
|
181
|
-
* throw new Error(`Invalid record: ${result.error}`);
|
|
182
|
-
* }
|
|
183
|
-
* ```
|
|
184
|
-
*/
|
|
185
|
-
validate(collection: string, record: unknown): ValidationResult;
|
|
186
|
-
/**
|
|
187
|
-
* Adds all registered lexicons to an AT Protocol Agent instance.
|
|
188
|
-
*
|
|
189
|
-
* This allows the Agent to understand custom lexicon types when making
|
|
190
|
-
* API requests.
|
|
191
|
-
*
|
|
192
|
-
* @param agent - The Agent instance to extend
|
|
193
|
-
*
|
|
194
|
-
* @remarks
|
|
195
|
-
* This is called automatically when creating a Repository. You typically
|
|
196
|
-
* don't need to call this directly unless you're using the Agent
|
|
197
|
-
* independently.
|
|
198
|
-
*
|
|
199
|
-
* @internal
|
|
200
|
-
*/
|
|
201
|
-
addToAgent(agent: Agent): void;
|
|
202
|
-
/**
|
|
203
|
-
* Gets all registered lexicon IDs.
|
|
204
|
-
*
|
|
205
|
-
* @returns Array of lexicon NSIDs
|
|
206
|
-
*
|
|
207
|
-
* @example
|
|
208
|
-
* ```typescript
|
|
209
|
-
* const ids = registry.getRegisteredIds();
|
|
210
|
-
* console.log(`Registered lexicons: ${ids.join(", ")}`);
|
|
211
|
-
* ```
|
|
212
|
-
*/
|
|
213
|
-
getRegisteredIds(): string[];
|
|
214
|
-
/**
|
|
215
|
-
* Checks if a lexicon is registered.
|
|
216
|
-
*
|
|
217
|
-
* @param id - The lexicon NSID to check
|
|
218
|
-
* @returns `true` if the lexicon is registered
|
|
219
|
-
*
|
|
220
|
-
* @example
|
|
221
|
-
* ```typescript
|
|
222
|
-
* if (registry.has("org.hypercerts.hypercert")) {
|
|
223
|
-
* // Hypercert lexicon is available
|
|
224
|
-
* }
|
|
225
|
-
* ```
|
|
226
|
-
*/
|
|
227
|
-
has(id: string): boolean;
|
|
228
|
-
}
|
|
4
|
+
import { OrgHypercertsClaimEvidence, OrgHypercertsClaimActivity, OrgHypercertsClaimCollection, ComAtprotoRepoStrongRef, OrgHypercertsClaimRights, OrgHypercertsClaimContribution, OrgHypercertsClaimMeasurement, OrgHypercertsClaimEvaluation, OrgHypercertsClaimProject, AppCertifiedLocation, AppCertifiedBadgeAward, AppCertifiedBadgeDefinition, AppCertifiedBadgeResponse, OrgHypercertsFundingReceipt, OrgHypercertsDefs } from '@hypercerts-org/lexicon';
|
|
5
|
+
export { AppCertifiedBadgeAward, AppCertifiedBadgeDefinition, AppCertifiedBadgeResponse, AppCertifiedDefs, AppCertifiedLocation, ComAtprotoRepoStrongRef, HYPERCERTS_LEXICON_DOC, HYPERCERTS_LEXICON_JSON, HYPERCERTS_NSIDS, HYPERCERTS_NSIDS_BY_TYPE, HYPERCERTS_SCHEMAS, HYPERCERTS_SCHEMA_DICT, OrgHypercertsClaimActivity, OrgHypercertsClaimCollection, OrgHypercertsClaimContribution, OrgHypercertsClaimEvaluation, OrgHypercertsClaimEvidence, OrgHypercertsClaimMeasurement, OrgHypercertsClaimProject, OrgHypercertsClaimRights, OrgHypercertsDefs, OrgHypercertsFundingReceipt, lexicons, validate } from '@hypercerts-org/lexicon';
|
|
6
|
+
import { Agent } from '@atproto/api';
|
|
7
|
+
import { LexiconDoc } from '@atproto/lexicon';
|
|
8
|
+
export { BlobRef, JsonBlobRef } from '@atproto/lexicon';
|
|
229
9
|
|
|
230
10
|
/**
|
|
231
11
|
* Storage interface for persisting OAuth sessions.
|
|
@@ -1043,6 +823,132 @@ interface ProgressStep {
|
|
|
1043
823
|
error?: Error;
|
|
1044
824
|
}
|
|
1045
825
|
|
|
826
|
+
/**
|
|
827
|
+
* Lexicons entrypoint - Lexicon definitions and registry.
|
|
828
|
+
*
|
|
829
|
+
* This sub-entrypoint exports the lexicon registry and hypercert
|
|
830
|
+
* lexicon constants for working with AT Protocol record schemas.
|
|
831
|
+
*
|
|
832
|
+
* @remarks
|
|
833
|
+
* Import from `@hypercerts-org/sdk/lexicons`:
|
|
834
|
+
*
|
|
835
|
+
* ```typescript
|
|
836
|
+
* import {
|
|
837
|
+
* LexiconRegistry,
|
|
838
|
+
* HYPERCERT_LEXICONS,
|
|
839
|
+
* HYPERCERT_COLLECTIONS,
|
|
840
|
+
* } from "@hypercerts-org/sdk/lexicons";
|
|
841
|
+
* ```
|
|
842
|
+
*
|
|
843
|
+
* **Exports**:
|
|
844
|
+
* - {@link LexiconRegistry} - Registry for managing and validating lexicons
|
|
845
|
+
* - {@link HYPERCERT_LEXICONS} - Array of all hypercert lexicon documents
|
|
846
|
+
* - {@link HYPERCERT_COLLECTIONS} - Constants for collection NSIDs
|
|
847
|
+
*
|
|
848
|
+
* @example Using collection constants
|
|
849
|
+
* ```typescript
|
|
850
|
+
* import { HYPERCERT_COLLECTIONS } from "@hypercerts-org/sdk/lexicons";
|
|
851
|
+
*
|
|
852
|
+
* // List hypercerts using the correct collection name
|
|
853
|
+
* const records = await repo.records.list({
|
|
854
|
+
* collection: HYPERCERT_COLLECTIONS.RECORD,
|
|
855
|
+
* });
|
|
856
|
+
*
|
|
857
|
+
* // List contributions
|
|
858
|
+
* const contributions = await repo.records.list({
|
|
859
|
+
* collection: HYPERCERT_COLLECTIONS.CONTRIBUTION,
|
|
860
|
+
* });
|
|
861
|
+
* ```
|
|
862
|
+
*
|
|
863
|
+
* @example Custom lexicon registration
|
|
864
|
+
* ```typescript
|
|
865
|
+
* import { LexiconRegistry } from "@hypercerts-org/sdk/lexicons";
|
|
866
|
+
*
|
|
867
|
+
* const registry = sdk.getLexiconRegistry();
|
|
868
|
+
*
|
|
869
|
+
* // Register custom lexicon
|
|
870
|
+
* registry.register({
|
|
871
|
+
* lexicon: 1,
|
|
872
|
+
* id: "org.myapp.customRecord",
|
|
873
|
+
* defs: { ... },
|
|
874
|
+
* });
|
|
875
|
+
*
|
|
876
|
+
* // Validate a record
|
|
877
|
+
* const result = registry.validate("org.myapp.customRecord", record);
|
|
878
|
+
* if (!result.valid) {
|
|
879
|
+
* console.error(result.error);
|
|
880
|
+
* }
|
|
881
|
+
* ```
|
|
882
|
+
*
|
|
883
|
+
* @packageDocumentation
|
|
884
|
+
*/
|
|
885
|
+
|
|
886
|
+
/**
|
|
887
|
+
* All hypercert-related lexicons for registration with AT Protocol Agent.
|
|
888
|
+
* This array contains all lexicon documents from the published package.
|
|
889
|
+
*/
|
|
890
|
+
declare const HYPERCERT_LEXICONS: LexiconDoc[];
|
|
891
|
+
/**
|
|
892
|
+
* Collection NSIDs (Namespaced Identifiers) for hypercert records.
|
|
893
|
+
*
|
|
894
|
+
* Use these constants when performing record operations to ensure
|
|
895
|
+
* correct collection names.
|
|
896
|
+
*/
|
|
897
|
+
declare const HYPERCERT_COLLECTIONS: {
|
|
898
|
+
/**
|
|
899
|
+
* Main hypercert claim record collection.
|
|
900
|
+
*/
|
|
901
|
+
readonly CLAIM: "org.hypercerts.claim.activity";
|
|
902
|
+
/**
|
|
903
|
+
* Rights record collection.
|
|
904
|
+
*/
|
|
905
|
+
readonly RIGHTS: "org.hypercerts.claim.rights";
|
|
906
|
+
/**
|
|
907
|
+
* Location record collection (shared certified lexicon).
|
|
908
|
+
*/
|
|
909
|
+
readonly LOCATION: "app.certified.location";
|
|
910
|
+
/**
|
|
911
|
+
* Contribution record collection.
|
|
912
|
+
*/
|
|
913
|
+
readonly CONTRIBUTION: "org.hypercerts.claim.contribution";
|
|
914
|
+
/**
|
|
915
|
+
* Measurement record collection.
|
|
916
|
+
*/
|
|
917
|
+
readonly MEASUREMENT: "org.hypercerts.claim.measurement";
|
|
918
|
+
/**
|
|
919
|
+
* Evaluation record collection.
|
|
920
|
+
*/
|
|
921
|
+
readonly EVALUATION: "org.hypercerts.claim.evaluation";
|
|
922
|
+
/**
|
|
923
|
+
* Evidence record collection.
|
|
924
|
+
*/
|
|
925
|
+
readonly EVIDENCE: "org.hypercerts.claim.evidence";
|
|
926
|
+
/**
|
|
927
|
+
* Collection record collection (groups of hypercerts).
|
|
928
|
+
*/
|
|
929
|
+
readonly COLLECTION: "org.hypercerts.claim.collection";
|
|
930
|
+
/**
|
|
931
|
+
* Project record collection.
|
|
932
|
+
*/
|
|
933
|
+
readonly PROJECT: "org.hypercerts.claim.project";
|
|
934
|
+
/**
|
|
935
|
+
* Badge award record collection.
|
|
936
|
+
*/
|
|
937
|
+
readonly BADGE_AWARD: "app.certified.badge.award";
|
|
938
|
+
/**
|
|
939
|
+
* Badge definition record collection.
|
|
940
|
+
*/
|
|
941
|
+
readonly BADGE_DEFINITION: "app.certified.badge.definition";
|
|
942
|
+
/**
|
|
943
|
+
* Badge response record collection.
|
|
944
|
+
*/
|
|
945
|
+
readonly BADGE_RESPONSE: "app.certified.badge.response";
|
|
946
|
+
/**
|
|
947
|
+
* Funding receipt record collection.
|
|
948
|
+
*/
|
|
949
|
+
readonly FUNDING_RECEIPT: "org.hypercerts.funding.receipt";
|
|
950
|
+
};
|
|
951
|
+
|
|
1046
952
|
/**
|
|
1047
953
|
* TypeScript types for hypercert lexicon schemas.
|
|
1048
954
|
*
|
|
@@ -1052,30 +958,32 @@ interface ProgressStep {
|
|
|
1052
958
|
*/
|
|
1053
959
|
|
|
1054
960
|
type StrongRef = ComAtprotoRepoStrongRef.Main;
|
|
1055
|
-
type HypercertClaim =
|
|
961
|
+
type HypercertClaim = OrgHypercertsClaimActivity.Main;
|
|
1056
962
|
type HypercertRights = OrgHypercertsClaimRights.Main;
|
|
1057
963
|
type HypercertContribution = OrgHypercertsClaimContribution.Main;
|
|
1058
964
|
type HypercertMeasurement = OrgHypercertsClaimMeasurement.Main;
|
|
1059
965
|
type HypercertEvaluation = OrgHypercertsClaimEvaluation.Main;
|
|
1060
|
-
type
|
|
1061
|
-
type
|
|
966
|
+
type HypercertEvidence = OrgHypercertsClaimEvidence.Main;
|
|
967
|
+
type HypercertCollection = OrgHypercertsClaimCollection.Main;
|
|
968
|
+
type HypercertCollectionClaimItem = OrgHypercertsClaimActivity.ActivityWeight;
|
|
969
|
+
type HypercertProject = OrgHypercertsClaimProject.Main;
|
|
1062
970
|
type HypercertLocation = AppCertifiedLocation.Main;
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
971
|
+
type BadgeAward = AppCertifiedBadgeAward.Main;
|
|
972
|
+
type BadgeDefinition = AppCertifiedBadgeDefinition.Main;
|
|
973
|
+
type BadgeResponse = AppCertifiedBadgeResponse.Main;
|
|
974
|
+
type FundingReceipt = OrgHypercertsFundingReceipt.Main;
|
|
975
|
+
/**
|
|
976
|
+
* Image input for SDK operations.
|
|
977
|
+
*
|
|
978
|
+
* Can be either:
|
|
979
|
+
* - A URI reference (for external images)
|
|
980
|
+
* - A Blob to be uploaded
|
|
981
|
+
*
|
|
982
|
+
* The SDK will convert these to the appropriate lexicon types:
|
|
983
|
+
* - OrgHypercertsDefs.Uri
|
|
984
|
+
* - OrgHypercertsDefs.SmallImage
|
|
985
|
+
* - OrgHypercertsDefs.LargeImage
|
|
986
|
+
*/
|
|
1079
987
|
type HypercertImage = {
|
|
1080
988
|
type: "uri";
|
|
1081
989
|
uri: string;
|
|
@@ -1083,6 +991,11 @@ type HypercertImage = {
|
|
|
1083
991
|
type: "blob";
|
|
1084
992
|
blob: Blob;
|
|
1085
993
|
};
|
|
994
|
+
/**
|
|
995
|
+
* Lexicon-defined image types (union of Uri and image blob types).
|
|
996
|
+
* Use this when working with stored records.
|
|
997
|
+
*/
|
|
998
|
+
type HypercertImageRecord = OrgHypercertsDefs.Uri | OrgHypercertsDefs.SmallImage | OrgHypercertsDefs.LargeImage;
|
|
1086
999
|
/** Hypercert with AT Protocol metadata */
|
|
1087
1000
|
interface HypercertWithMetadata {
|
|
1088
1001
|
uri: string;
|
|
@@ -2071,7 +1984,6 @@ declare class Repository {
|
|
|
2071
1984
|
private session;
|
|
2072
1985
|
private serverUrl;
|
|
2073
1986
|
private repoDid;
|
|
2074
|
-
private lexiconRegistry;
|
|
2075
1987
|
private logger?;
|
|
2076
1988
|
private agent;
|
|
2077
1989
|
private _isSDS;
|
|
@@ -2087,7 +1999,6 @@ declare class Repository {
|
|
|
2087
1999
|
* @param session - Authenticated OAuth session
|
|
2088
2000
|
* @param serverUrl - Base URL of the AT Protocol server
|
|
2089
2001
|
* @param repoDid - DID of the repository to operate on
|
|
2090
|
-
* @param lexiconRegistry - Registry for lexicon validation
|
|
2091
2002
|
* @param isSDS - Whether this is a Shared Data Server
|
|
2092
2003
|
* @param logger - Optional logger for debugging
|
|
2093
2004
|
*
|
|
@@ -2097,7 +2008,7 @@ declare class Repository {
|
|
|
2097
2008
|
*
|
|
2098
2009
|
* @internal
|
|
2099
2010
|
*/
|
|
2100
|
-
constructor(session: Session, serverUrl: string, repoDid: string,
|
|
2011
|
+
constructor(session: Session, serverUrl: string, repoDid: string, isSDS: boolean, logger?: LoggerInterface);
|
|
2101
2012
|
/**
|
|
2102
2013
|
* The DID (Decentralized Identifier) of this repository.
|
|
2103
2014
|
*
|
|
@@ -2355,7 +2266,32 @@ declare const OAuthConfigSchema: z.ZodObject<{
|
|
|
2355
2266
|
redirectUri: z.ZodString;
|
|
2356
2267
|
/**
|
|
2357
2268
|
* OAuth scopes to request, space-separated.
|
|
2358
|
-
*
|
|
2269
|
+
*
|
|
2270
|
+
* Can be a string of space-separated permissions or use the permission system:
|
|
2271
|
+
*
|
|
2272
|
+
* @example Using presets
|
|
2273
|
+
* ```typescript
|
|
2274
|
+
* import { ScopePresets } from '@hypercerts-org/sdk-core';
|
|
2275
|
+
* scope: ScopePresets.EMAIL_AND_PROFILE
|
|
2276
|
+
* ```
|
|
2277
|
+
*
|
|
2278
|
+
* @example Building custom scopes
|
|
2279
|
+
* ```typescript
|
|
2280
|
+
* import { PermissionBuilder, buildScope } from '@hypercerts-org/sdk-core';
|
|
2281
|
+
* scope: buildScope(
|
|
2282
|
+
* new PermissionBuilder()
|
|
2283
|
+
* .accountEmail('read')
|
|
2284
|
+
* .repoWrite('app.bsky.feed.post')
|
|
2285
|
+
* .build()
|
|
2286
|
+
* )
|
|
2287
|
+
* ```
|
|
2288
|
+
*
|
|
2289
|
+
* @example Legacy scopes
|
|
2290
|
+
* ```typescript
|
|
2291
|
+
* scope: "atproto transition:generic"
|
|
2292
|
+
* ```
|
|
2293
|
+
*
|
|
2294
|
+
* @see https://atproto.com/specs/permission for permission details
|
|
2359
2295
|
*/
|
|
2360
2296
|
scope: z.ZodString;
|
|
2361
2297
|
/**
|
|
@@ -2461,7 +2397,32 @@ declare const ATProtoSDKConfigSchema: z.ZodObject<{
|
|
|
2461
2397
|
redirectUri: z.ZodString;
|
|
2462
2398
|
/**
|
|
2463
2399
|
* OAuth scopes to request, space-separated.
|
|
2464
|
-
*
|
|
2400
|
+
*
|
|
2401
|
+
* Can be a string of space-separated permissions or use the permission system:
|
|
2402
|
+
*
|
|
2403
|
+
* @example Using presets
|
|
2404
|
+
* ```typescript
|
|
2405
|
+
* import { ScopePresets } from '@hypercerts-org/sdk-core';
|
|
2406
|
+
* scope: ScopePresets.EMAIL_AND_PROFILE
|
|
2407
|
+
* ```
|
|
2408
|
+
*
|
|
2409
|
+
* @example Building custom scopes
|
|
2410
|
+
* ```typescript
|
|
2411
|
+
* import { PermissionBuilder, buildScope } from '@hypercerts-org/sdk-core';
|
|
2412
|
+
* scope: buildScope(
|
|
2413
|
+
* new PermissionBuilder()
|
|
2414
|
+
* .accountEmail('read')
|
|
2415
|
+
* .repoWrite('app.bsky.feed.post')
|
|
2416
|
+
* .build()
|
|
2417
|
+
* )
|
|
2418
|
+
* ```
|
|
2419
|
+
*
|
|
2420
|
+
* @example Legacy scopes
|
|
2421
|
+
* ```typescript
|
|
2422
|
+
* scope: "atproto transition:generic"
|
|
2423
|
+
* ```
|
|
2424
|
+
*
|
|
2425
|
+
* @see https://atproto.com/specs/permission for permission details
|
|
2465
2426
|
*/
|
|
2466
2427
|
scope: z.ZodString;
|
|
2467
2428
|
/**
|
|
@@ -2703,13 +2664,47 @@ interface AuthorizeOptions {
|
|
|
2703
2664
|
* OAuth scope string to request specific permissions.
|
|
2704
2665
|
* Overrides the default scope configured in {@link ATProtoSDKConfig.oauth.scope}.
|
|
2705
2666
|
*
|
|
2706
|
-
*
|
|
2667
|
+
* Can use the permission system for type-safe scope building.
|
|
2668
|
+
*
|
|
2669
|
+
* @example Using presets
|
|
2670
|
+
* ```typescript
|
|
2671
|
+
* import { ScopePresets } from '@hypercerts-org/sdk-core';
|
|
2672
|
+
*
|
|
2673
|
+
* // Request email and profile access
|
|
2674
|
+
* await sdk.authorize("user.bsky.social", {
|
|
2675
|
+
* scope: ScopePresets.EMAIL_AND_PROFILE
|
|
2676
|
+
* });
|
|
2677
|
+
*
|
|
2678
|
+
* // Request full posting capabilities
|
|
2679
|
+
* await sdk.authorize("user.bsky.social", {
|
|
2680
|
+
* scope: ScopePresets.POSTING_APP
|
|
2681
|
+
* });
|
|
2682
|
+
* ```
|
|
2683
|
+
*
|
|
2684
|
+
* @example Building custom scopes
|
|
2685
|
+
* ```typescript
|
|
2686
|
+
* import { PermissionBuilder, buildScope } from '@hypercerts-org/sdk-core';
|
|
2687
|
+
*
|
|
2688
|
+
* const scope = buildScope(
|
|
2689
|
+
* new PermissionBuilder()
|
|
2690
|
+
* .accountEmail('read')
|
|
2691
|
+
* .repoWrite('app.bsky.feed.post')
|
|
2692
|
+
* .blob(['image/*'])
|
|
2693
|
+
* .build()
|
|
2694
|
+
* );
|
|
2695
|
+
*
|
|
2696
|
+
* await sdk.authorize("user.bsky.social", { scope });
|
|
2697
|
+
* ```
|
|
2698
|
+
*
|
|
2699
|
+
* @example Legacy scopes
|
|
2707
2700
|
* ```typescript
|
|
2708
2701
|
* // Request read-only access
|
|
2709
2702
|
* await sdk.authorize("user.bsky.social", { scope: "atproto" });
|
|
2710
2703
|
*
|
|
2711
|
-
* // Request full access (
|
|
2712
|
-
* await sdk.authorize("user.bsky.social", {
|
|
2704
|
+
* // Request full access (legacy)
|
|
2705
|
+
* await sdk.authorize("user.bsky.social", {
|
|
2706
|
+
* scope: "atproto transition:generic"
|
|
2707
|
+
* });
|
|
2713
2708
|
* ```
|
|
2714
2709
|
*/
|
|
2715
2710
|
scope?: string;
|
|
@@ -2768,7 +2763,6 @@ declare class ATProtoSDK {
|
|
|
2768
2763
|
private oauthClient;
|
|
2769
2764
|
private config;
|
|
2770
2765
|
private logger?;
|
|
2771
|
-
private lexiconRegistry;
|
|
2772
2766
|
/**
|
|
2773
2767
|
* Creates a new ATProto SDK instance.
|
|
2774
2768
|
*
|
|
@@ -2902,6 +2896,56 @@ declare class ATProtoSDK {
|
|
|
2902
2896
|
* ```
|
|
2903
2897
|
*/
|
|
2904
2898
|
revokeSession(did: string): Promise<void>;
|
|
2899
|
+
/**
|
|
2900
|
+
* Gets the account email address from the authenticated session.
|
|
2901
|
+
*
|
|
2902
|
+
* This method retrieves the email address associated with the user's account
|
|
2903
|
+
* by calling the `com.atproto.server.getSession` endpoint. The email will only
|
|
2904
|
+
* be returned if the appropriate OAuth scope was granted during authorization.
|
|
2905
|
+
*
|
|
2906
|
+
* Required OAuth scopes:
|
|
2907
|
+
* - **Granular permissions**: `account:email?action=read` or `account:email`
|
|
2908
|
+
* - **Transitional permissions**: `transition:email`
|
|
2909
|
+
*
|
|
2910
|
+
* @param session - An authenticated OAuth session
|
|
2911
|
+
* @returns A Promise resolving to email info, or `null` if permission not granted
|
|
2912
|
+
* @throws {@link ValidationError} if the session is invalid
|
|
2913
|
+
* @throws {@link NetworkError} if the API request fails
|
|
2914
|
+
*
|
|
2915
|
+
* @example Using granular permissions
|
|
2916
|
+
* ```typescript
|
|
2917
|
+
* import { ScopePresets } from '@hypercerts-org/sdk-core';
|
|
2918
|
+
*
|
|
2919
|
+
* // Authorize with email scope
|
|
2920
|
+
* const authUrl = await sdk.authorize("user.bsky.social", {
|
|
2921
|
+
* scope: ScopePresets.EMAIL_READ
|
|
2922
|
+
* });
|
|
2923
|
+
*
|
|
2924
|
+
* // After callback...
|
|
2925
|
+
* const emailInfo = await sdk.getAccountEmail(session);
|
|
2926
|
+
* if (emailInfo) {
|
|
2927
|
+
* console.log(`Email: ${emailInfo.email}`);
|
|
2928
|
+
* console.log(`Confirmed: ${emailInfo.emailConfirmed}`);
|
|
2929
|
+
* } else {
|
|
2930
|
+
* console.log("Email permission not granted");
|
|
2931
|
+
* }
|
|
2932
|
+
* ```
|
|
2933
|
+
*
|
|
2934
|
+
* @example Using transitional permissions (legacy)
|
|
2935
|
+
* ```typescript
|
|
2936
|
+
* // Authorize with transition:email scope
|
|
2937
|
+
* const authUrl = await sdk.authorize("user.bsky.social", {
|
|
2938
|
+
* scope: "atproto transition:email"
|
|
2939
|
+
* });
|
|
2940
|
+
*
|
|
2941
|
+
* // After callback...
|
|
2942
|
+
* const emailInfo = await sdk.getAccountEmail(session);
|
|
2943
|
+
* ```
|
|
2944
|
+
*/
|
|
2945
|
+
getAccountEmail(session: Session): Promise<{
|
|
2946
|
+
email: string;
|
|
2947
|
+
emailConfirmed: boolean;
|
|
2948
|
+
} | null>;
|
|
2905
2949
|
/**
|
|
2906
2950
|
* Creates a repository instance for data operations.
|
|
2907
2951
|
*
|
|
@@ -2938,27 +2982,6 @@ declare class ATProtoSDK {
|
|
|
2938
2982
|
* ```
|
|
2939
2983
|
*/
|
|
2940
2984
|
repository(session: Session, options?: RepositoryOptions): Repository;
|
|
2941
|
-
/**
|
|
2942
|
-
* Gets the lexicon registry for schema validation.
|
|
2943
|
-
*
|
|
2944
|
-
* The lexicon registry manages AT Protocol lexicon schemas used for
|
|
2945
|
-
* validating record data. You can register custom lexicons to extend
|
|
2946
|
-
* the SDK's capabilities.
|
|
2947
|
-
*
|
|
2948
|
-
* @returns The {@link LexiconRegistry} instance
|
|
2949
|
-
*
|
|
2950
|
-
* @example
|
|
2951
|
-
* ```typescript
|
|
2952
|
-
* const registry = sdk.getLexiconRegistry();
|
|
2953
|
-
*
|
|
2954
|
-
* // Register custom lexicons
|
|
2955
|
-
* registry.register(myCustomLexicons);
|
|
2956
|
-
*
|
|
2957
|
-
* // Check if a lexicon is registered
|
|
2958
|
-
* const hasLexicon = registry.has("org.example.myRecord");
|
|
2959
|
-
* ```
|
|
2960
|
-
*/
|
|
2961
|
-
getLexiconRegistry(): LexiconRegistry;
|
|
2962
2985
|
/**
|
|
2963
2986
|
* The configured PDS (Personal Data Server) URL.
|
|
2964
2987
|
*
|
|
@@ -3532,5 +3555,1047 @@ declare class InMemoryStateStore implements StateStore {
|
|
|
3532
3555
|
clear(): void;
|
|
3533
3556
|
}
|
|
3534
3557
|
|
|
3535
|
-
|
|
3536
|
-
|
|
3558
|
+
/**
|
|
3559
|
+
* OAuth Scopes and Granular Permissions
|
|
3560
|
+
*
|
|
3561
|
+
* This module provides type-safe, Zod-validated OAuth scope and permission management
|
|
3562
|
+
* for the ATProto SDK. It supports both legacy transitional scopes and the new
|
|
3563
|
+
* granular permissions model.
|
|
3564
|
+
*
|
|
3565
|
+
* @see https://atproto.com/specs/oauth
|
|
3566
|
+
* @see https://atproto.com/specs/permission
|
|
3567
|
+
*
|
|
3568
|
+
* @module auth/permissions
|
|
3569
|
+
*/
|
|
3570
|
+
|
|
3571
|
+
/**
|
|
3572
|
+
* Base OAuth scope - required for all sessions
|
|
3573
|
+
*
|
|
3574
|
+
* @constant
|
|
3575
|
+
*/
|
|
3576
|
+
declare const ATPROTO_SCOPE: "atproto";
|
|
3577
|
+
/**
|
|
3578
|
+
* Transitional OAuth scopes for legacy compatibility.
|
|
3579
|
+
*
|
|
3580
|
+
* These scopes provide broad access and are maintained for backwards compatibility.
|
|
3581
|
+
* New applications should use granular permissions instead.
|
|
3582
|
+
*
|
|
3583
|
+
* @deprecated Use granular permissions (account:*, repo:*, etc.) for better control
|
|
3584
|
+
* @constant
|
|
3585
|
+
*/
|
|
3586
|
+
declare const TRANSITION_SCOPES: {
|
|
3587
|
+
/** Broad PDS permissions including record creation, blob uploads, and preferences */
|
|
3588
|
+
readonly GENERIC: "transition:generic";
|
|
3589
|
+
/** Direct messages access (requires transition:generic) */
|
|
3590
|
+
readonly CHAT: "transition:chat.bsky";
|
|
3591
|
+
/** Email address and confirmation status */
|
|
3592
|
+
readonly EMAIL: "transition:email";
|
|
3593
|
+
};
|
|
3594
|
+
/**
|
|
3595
|
+
* Zod schema for transitional scopes.
|
|
3596
|
+
*
|
|
3597
|
+
* Validates that a scope string is one of the known transitional scopes.
|
|
3598
|
+
*
|
|
3599
|
+
* @example
|
|
3600
|
+
* ```typescript
|
|
3601
|
+
* TransitionScopeSchema.parse('transition:email'); // Valid
|
|
3602
|
+
* TransitionScopeSchema.parse('invalid'); // Throws ZodError
|
|
3603
|
+
* ```
|
|
3604
|
+
*/
|
|
3605
|
+
declare const TransitionScopeSchema: z.ZodEnum<["transition:generic", "transition:chat.bsky", "transition:email"]>;
|
|
3606
|
+
/**
|
|
3607
|
+
* Type for transitional scopes inferred from schema.
|
|
3608
|
+
*/
|
|
3609
|
+
type TransitionScope = z.infer<typeof TransitionScopeSchema>;
|
|
3610
|
+
/**
|
|
3611
|
+
* Zod schema for account permission attributes.
|
|
3612
|
+
*
|
|
3613
|
+
* Account attributes specify what aspect of the account is being accessed.
|
|
3614
|
+
*/
|
|
3615
|
+
declare const AccountAttrSchema: z.ZodEnum<["email", "repo"]>;
|
|
3616
|
+
/**
|
|
3617
|
+
* Type for account attributes inferred from schema.
|
|
3618
|
+
*/
|
|
3619
|
+
type AccountAttr = z.infer<typeof AccountAttrSchema>;
|
|
3620
|
+
/**
|
|
3621
|
+
* Zod schema for account actions.
|
|
3622
|
+
*
|
|
3623
|
+
* Account actions specify the level of access (read-only or management).
|
|
3624
|
+
*/
|
|
3625
|
+
declare const AccountActionSchema: z.ZodEnum<["read", "manage"]>;
|
|
3626
|
+
/**
|
|
3627
|
+
* Type for account actions inferred from schema.
|
|
3628
|
+
*/
|
|
3629
|
+
type AccountAction = z.infer<typeof AccountActionSchema>;
|
|
3630
|
+
/**
|
|
3631
|
+
* Zod schema for repository actions.
|
|
3632
|
+
*
|
|
3633
|
+
* Repository actions specify what operations can be performed on records.
|
|
3634
|
+
*/
|
|
3635
|
+
declare const RepoActionSchema: z.ZodEnum<["create", "update", "delete"]>;
|
|
3636
|
+
/**
|
|
3637
|
+
* Type for repository actions inferred from schema.
|
|
3638
|
+
*/
|
|
3639
|
+
type RepoAction = z.infer<typeof RepoActionSchema>;
|
|
3640
|
+
/**
|
|
3641
|
+
* Zod schema for identity permission attributes.
|
|
3642
|
+
*
|
|
3643
|
+
* Identity attributes specify what identity information can be managed.
|
|
3644
|
+
*/
|
|
3645
|
+
declare const IdentityAttrSchema: z.ZodEnum<["handle", "*"]>;
|
|
3646
|
+
/**
|
|
3647
|
+
* Type for identity attributes inferred from schema.
|
|
3648
|
+
*/
|
|
3649
|
+
type IdentityAttr = z.infer<typeof IdentityAttrSchema>;
|
|
3650
|
+
/**
|
|
3651
|
+
* Zod schema for MIME type patterns.
|
|
3652
|
+
*
|
|
3653
|
+
* Validates MIME type strings like "image/*" or "video/mp4".
|
|
3654
|
+
*
|
|
3655
|
+
* @example
|
|
3656
|
+
* ```typescript
|
|
3657
|
+
* MimeTypeSchema.parse('image/*'); // Valid
|
|
3658
|
+
* MimeTypeSchema.parse('video/mp4'); // Valid
|
|
3659
|
+
* MimeTypeSchema.parse('invalid'); // Throws ZodError
|
|
3660
|
+
* ```
|
|
3661
|
+
*/
|
|
3662
|
+
declare const MimeTypeSchema: z.ZodString;
|
|
3663
|
+
/**
|
|
3664
|
+
* Zod schema for NSID (Namespaced Identifier).
|
|
3665
|
+
*
|
|
3666
|
+
* NSIDs are reverse-DNS style identifiers used throughout ATProto
|
|
3667
|
+
* (e.g., "app.bsky.feed.post" or "com.example.myrecord").
|
|
3668
|
+
*
|
|
3669
|
+
* @see https://atproto.com/specs/nsid
|
|
3670
|
+
*
|
|
3671
|
+
* @example
|
|
3672
|
+
* ```typescript
|
|
3673
|
+
* NsidSchema.parse('app.bsky.feed.post'); // Valid
|
|
3674
|
+
* NsidSchema.parse('com.example.myrecord'); // Valid
|
|
3675
|
+
* NsidSchema.parse('InvalidNSID'); // Throws ZodError
|
|
3676
|
+
* ```
|
|
3677
|
+
*/
|
|
3678
|
+
declare const NsidSchema: z.ZodString;
|
|
3679
|
+
/**
|
|
3680
|
+
* Zod schema for account permission.
|
|
3681
|
+
*
|
|
3682
|
+
* Account permissions control access to account-level information like email
|
|
3683
|
+
* and repository management.
|
|
3684
|
+
*
|
|
3685
|
+
* @example Without action (read-only)
|
|
3686
|
+
* ```typescript
|
|
3687
|
+
* const input = { type: 'account', attr: 'email' };
|
|
3688
|
+
* AccountPermissionSchema.parse(input); // Returns: "account:email"
|
|
3689
|
+
* ```
|
|
3690
|
+
*
|
|
3691
|
+
* @example With action
|
|
3692
|
+
* ```typescript
|
|
3693
|
+
* const input = { type: 'account', attr: 'email', action: 'manage' };
|
|
3694
|
+
* AccountPermissionSchema.parse(input); // Returns: "account:email?action=manage"
|
|
3695
|
+
* ```
|
|
3696
|
+
*/
|
|
3697
|
+
declare const AccountPermissionSchema: z.ZodEffects<z.ZodObject<{
|
|
3698
|
+
type: z.ZodLiteral<"account">;
|
|
3699
|
+
attr: z.ZodEnum<["email", "repo"]>;
|
|
3700
|
+
action: z.ZodOptional<z.ZodEnum<["read", "manage"]>>;
|
|
3701
|
+
}, "strip", z.ZodTypeAny, {
|
|
3702
|
+
type: "account";
|
|
3703
|
+
attr: "email" | "repo";
|
|
3704
|
+
action?: "read" | "manage" | undefined;
|
|
3705
|
+
}, {
|
|
3706
|
+
type: "account";
|
|
3707
|
+
attr: "email" | "repo";
|
|
3708
|
+
action?: "read" | "manage" | undefined;
|
|
3709
|
+
}>, string, {
|
|
3710
|
+
type: "account";
|
|
3711
|
+
attr: "email" | "repo";
|
|
3712
|
+
action?: "read" | "manage" | undefined;
|
|
3713
|
+
}>;
|
|
3714
|
+
/**
|
|
3715
|
+
* Input type for account permission (before transform).
|
|
3716
|
+
*/
|
|
3717
|
+
type AccountPermissionInput = z.input<typeof AccountPermissionSchema>;
|
|
3718
|
+
/**
|
|
3719
|
+
* Zod schema for repository permission.
|
|
3720
|
+
*
|
|
3721
|
+
* Repository permissions control write access to records by collection type.
|
|
3722
|
+
* The collection must be a valid NSID or wildcard (*).
|
|
3723
|
+
*
|
|
3724
|
+
* @example Without actions (all actions allowed)
|
|
3725
|
+
* ```typescript
|
|
3726
|
+
* const input = { type: 'repo', collection: 'app.bsky.feed.post' };
|
|
3727
|
+
* RepoPermissionSchema.parse(input); // Returns: "repo:app.bsky.feed.post"
|
|
3728
|
+
* ```
|
|
3729
|
+
*
|
|
3730
|
+
* @example With specific actions
|
|
3731
|
+
* ```typescript
|
|
3732
|
+
* const input = {
|
|
3733
|
+
* type: 'repo',
|
|
3734
|
+
* collection: 'app.bsky.feed.post',
|
|
3735
|
+
* actions: ['create', 'update']
|
|
3736
|
+
* };
|
|
3737
|
+
* RepoPermissionSchema.parse(input); // Returns: "repo:app.bsky.feed.post?action=create&action=update"
|
|
3738
|
+
* ```
|
|
3739
|
+
*
|
|
3740
|
+
* @example With wildcard collection
|
|
3741
|
+
* ```typescript
|
|
3742
|
+
* const input = { type: 'repo', collection: '*', actions: ['delete'] };
|
|
3743
|
+
* RepoPermissionSchema.parse(input); // Returns: "repo:*?action=delete"
|
|
3744
|
+
* ```
|
|
3745
|
+
*/
|
|
3746
|
+
declare const RepoPermissionSchema: z.ZodEffects<z.ZodObject<{
|
|
3747
|
+
type: z.ZodLiteral<"repo">;
|
|
3748
|
+
collection: z.ZodUnion<[z.ZodString, z.ZodLiteral<"*">]>;
|
|
3749
|
+
actions: z.ZodOptional<z.ZodArray<z.ZodEnum<["create", "update", "delete"]>, "many">>;
|
|
3750
|
+
}, "strip", z.ZodTypeAny, {
|
|
3751
|
+
type: "repo";
|
|
3752
|
+
collection: string;
|
|
3753
|
+
actions?: ("create" | "update" | "delete")[] | undefined;
|
|
3754
|
+
}, {
|
|
3755
|
+
type: "repo";
|
|
3756
|
+
collection: string;
|
|
3757
|
+
actions?: ("create" | "update" | "delete")[] | undefined;
|
|
3758
|
+
}>, string, {
|
|
3759
|
+
type: "repo";
|
|
3760
|
+
collection: string;
|
|
3761
|
+
actions?: ("create" | "update" | "delete")[] | undefined;
|
|
3762
|
+
}>;
|
|
3763
|
+
/**
|
|
3764
|
+
* Input type for repository permission (before transform).
|
|
3765
|
+
*/
|
|
3766
|
+
type RepoPermissionInput = z.input<typeof RepoPermissionSchema>;
|
|
3767
|
+
/**
|
|
3768
|
+
* Zod schema for blob permission.
|
|
3769
|
+
*
|
|
3770
|
+
* Blob permissions control media file uploads constrained by MIME type patterns.
|
|
3771
|
+
*
|
|
3772
|
+
* @example Single MIME type
|
|
3773
|
+
* ```typescript
|
|
3774
|
+
* const input = { type: 'blob', mimeTypes: ['image/*'] };
|
|
3775
|
+
* BlobPermissionSchema.parse(input); // Returns: "blob:image/*"
|
|
3776
|
+
* ```
|
|
3777
|
+
*
|
|
3778
|
+
* @example Multiple MIME types
|
|
3779
|
+
* ```typescript
|
|
3780
|
+
* const input = { type: 'blob', mimeTypes: ['image/*', 'video/*'] };
|
|
3781
|
+
* BlobPermissionSchema.parse(input); // Returns: "blob?accept=image/*&accept=video/*"
|
|
3782
|
+
* ```
|
|
3783
|
+
*/
|
|
3784
|
+
declare const BlobPermissionSchema: z.ZodEffects<z.ZodObject<{
|
|
3785
|
+
type: z.ZodLiteral<"blob">;
|
|
3786
|
+
mimeTypes: z.ZodArray<z.ZodString, "many">;
|
|
3787
|
+
}, "strip", z.ZodTypeAny, {
|
|
3788
|
+
type: "blob";
|
|
3789
|
+
mimeTypes: string[];
|
|
3790
|
+
}, {
|
|
3791
|
+
type: "blob";
|
|
3792
|
+
mimeTypes: string[];
|
|
3793
|
+
}>, string, {
|
|
3794
|
+
type: "blob";
|
|
3795
|
+
mimeTypes: string[];
|
|
3796
|
+
}>;
|
|
3797
|
+
/**
|
|
3798
|
+
* Input type for blob permission (before transform).
|
|
3799
|
+
*/
|
|
3800
|
+
type BlobPermissionInput = z.input<typeof BlobPermissionSchema>;
|
|
3801
|
+
/**
|
|
3802
|
+
* Zod schema for RPC permission.
|
|
3803
|
+
*
|
|
3804
|
+
* RPC permissions control authenticated API calls to remote services.
|
|
3805
|
+
* At least one of lexicon or aud must be restricted (both cannot be wildcards).
|
|
3806
|
+
*
|
|
3807
|
+
* @example Specific lexicon with wildcard audience
|
|
3808
|
+
* ```typescript
|
|
3809
|
+
* const input = {
|
|
3810
|
+
* type: 'rpc',
|
|
3811
|
+
* lexicon: 'com.atproto.repo.createRecord',
|
|
3812
|
+
* aud: '*'
|
|
3813
|
+
* };
|
|
3814
|
+
* RpcPermissionSchema.parse(input);
|
|
3815
|
+
* // Returns: "rpc:com.atproto.repo.createRecord?aud=*"
|
|
3816
|
+
* ```
|
|
3817
|
+
*
|
|
3818
|
+
* @example With specific audience
|
|
3819
|
+
* ```typescript
|
|
3820
|
+
* const input = {
|
|
3821
|
+
* type: 'rpc',
|
|
3822
|
+
* lexicon: 'com.atproto.repo.createRecord',
|
|
3823
|
+
* aud: 'did:web:api.example.com',
|
|
3824
|
+
* inheritAud: true
|
|
3825
|
+
* };
|
|
3826
|
+
* RpcPermissionSchema.parse(input);
|
|
3827
|
+
* // Returns: "rpc:com.atproto.repo.createRecord?aud=did%3Aweb%3Aapi.example.com&inheritAud=true"
|
|
3828
|
+
* ```
|
|
3829
|
+
*/
|
|
3830
|
+
declare const RpcPermissionSchema: z.ZodEffects<z.ZodEffects<z.ZodObject<{
|
|
3831
|
+
type: z.ZodLiteral<"rpc">;
|
|
3832
|
+
lexicon: z.ZodUnion<[z.ZodString, z.ZodLiteral<"*">]>;
|
|
3833
|
+
aud: z.ZodString;
|
|
3834
|
+
inheritAud: z.ZodOptional<z.ZodBoolean>;
|
|
3835
|
+
}, "strip", z.ZodTypeAny, {
|
|
3836
|
+
type: "rpc";
|
|
3837
|
+
lexicon: string;
|
|
3838
|
+
aud: string;
|
|
3839
|
+
inheritAud?: boolean | undefined;
|
|
3840
|
+
}, {
|
|
3841
|
+
type: "rpc";
|
|
3842
|
+
lexicon: string;
|
|
3843
|
+
aud: string;
|
|
3844
|
+
inheritAud?: boolean | undefined;
|
|
3845
|
+
}>, {
|
|
3846
|
+
type: "rpc";
|
|
3847
|
+
lexicon: string;
|
|
3848
|
+
aud: string;
|
|
3849
|
+
inheritAud?: boolean | undefined;
|
|
3850
|
+
}, {
|
|
3851
|
+
type: "rpc";
|
|
3852
|
+
lexicon: string;
|
|
3853
|
+
aud: string;
|
|
3854
|
+
inheritAud?: boolean | undefined;
|
|
3855
|
+
}>, string, {
|
|
3856
|
+
type: "rpc";
|
|
3857
|
+
lexicon: string;
|
|
3858
|
+
aud: string;
|
|
3859
|
+
inheritAud?: boolean | undefined;
|
|
3860
|
+
}>;
|
|
3861
|
+
/**
|
|
3862
|
+
* Input type for RPC permission (before transform).
|
|
3863
|
+
*/
|
|
3864
|
+
type RpcPermissionInput = z.input<typeof RpcPermissionSchema>;
|
|
3865
|
+
/**
|
|
3866
|
+
* Zod schema for identity permission.
|
|
3867
|
+
*
|
|
3868
|
+
* Identity permissions control access to DID documents and handles.
|
|
3869
|
+
*
|
|
3870
|
+
* @example Handle management
|
|
3871
|
+
* ```typescript
|
|
3872
|
+
* const input = { type: 'identity', attr: 'handle' };
|
|
3873
|
+
* IdentityPermissionSchema.parse(input); // Returns: "identity:handle"
|
|
3874
|
+
* ```
|
|
3875
|
+
*
|
|
3876
|
+
* @example All identity attributes
|
|
3877
|
+
* ```typescript
|
|
3878
|
+
* const input = { type: 'identity', attr: '*' };
|
|
3879
|
+
* IdentityPermissionSchema.parse(input); // Returns: "identity:*"
|
|
3880
|
+
* ```
|
|
3881
|
+
*/
|
|
3882
|
+
declare const IdentityPermissionSchema: z.ZodEffects<z.ZodObject<{
|
|
3883
|
+
type: z.ZodLiteral<"identity">;
|
|
3884
|
+
attr: z.ZodEnum<["handle", "*"]>;
|
|
3885
|
+
}, "strip", z.ZodTypeAny, {
|
|
3886
|
+
type: "identity";
|
|
3887
|
+
attr: "handle" | "*";
|
|
3888
|
+
}, {
|
|
3889
|
+
type: "identity";
|
|
3890
|
+
attr: "handle" | "*";
|
|
3891
|
+
}>, string, {
|
|
3892
|
+
type: "identity";
|
|
3893
|
+
attr: "handle" | "*";
|
|
3894
|
+
}>;
|
|
3895
|
+
/**
|
|
3896
|
+
* Input type for identity permission (before transform).
|
|
3897
|
+
*/
|
|
3898
|
+
type IdentityPermissionInput = z.input<typeof IdentityPermissionSchema>;
|
|
3899
|
+
/**
|
|
3900
|
+
* Zod schema for permission set inclusion.
|
|
3901
|
+
*
|
|
3902
|
+
* Include permissions reference permission sets bundled under a single NSID.
|
|
3903
|
+
*
|
|
3904
|
+
* @example Without audience
|
|
3905
|
+
* ```typescript
|
|
3906
|
+
* const input = { type: 'include', nsid: 'com.example.authBasicFeatures' };
|
|
3907
|
+
* IncludePermissionSchema.parse(input);
|
|
3908
|
+
* // Returns: "include:com.example.authBasicFeatures"
|
|
3909
|
+
* ```
|
|
3910
|
+
*
|
|
3911
|
+
* @example With audience
|
|
3912
|
+
* ```typescript
|
|
3913
|
+
* const input = {
|
|
3914
|
+
* type: 'include',
|
|
3915
|
+
* nsid: 'com.example.authBasicFeatures',
|
|
3916
|
+
* aud: 'did:web:api.example.com'
|
|
3917
|
+
* };
|
|
3918
|
+
* IncludePermissionSchema.parse(input);
|
|
3919
|
+
* // Returns: "include:com.example.authBasicFeatures?aud=did%3Aweb%3Aapi.example.com"
|
|
3920
|
+
* ```
|
|
3921
|
+
*/
|
|
3922
|
+
declare const IncludePermissionSchema: z.ZodEffects<z.ZodObject<{
|
|
3923
|
+
type: z.ZodLiteral<"include">;
|
|
3924
|
+
nsid: z.ZodString;
|
|
3925
|
+
aud: z.ZodOptional<z.ZodString>;
|
|
3926
|
+
}, "strip", z.ZodTypeAny, {
|
|
3927
|
+
type: "include";
|
|
3928
|
+
nsid: string;
|
|
3929
|
+
aud?: string | undefined;
|
|
3930
|
+
}, {
|
|
3931
|
+
type: "include";
|
|
3932
|
+
nsid: string;
|
|
3933
|
+
aud?: string | undefined;
|
|
3934
|
+
}>, string, {
|
|
3935
|
+
type: "include";
|
|
3936
|
+
nsid: string;
|
|
3937
|
+
aud?: string | undefined;
|
|
3938
|
+
}>;
|
|
3939
|
+
/**
|
|
3940
|
+
* Input type for include permission (before transform).
|
|
3941
|
+
*/
|
|
3942
|
+
type IncludePermissionInput = z.input<typeof IncludePermissionSchema>;
|
|
3943
|
+
/**
|
|
3944
|
+
* Union schema for all permission types.
|
|
3945
|
+
*
|
|
3946
|
+
* This schema accepts any of the supported permission types and validates
|
|
3947
|
+
* them according to their specific rules.
|
|
3948
|
+
*/
|
|
3949
|
+
declare const PermissionSchema: z.ZodUnion<[z.ZodEffects<z.ZodObject<{
|
|
3950
|
+
type: z.ZodLiteral<"account">;
|
|
3951
|
+
attr: z.ZodEnum<["email", "repo"]>;
|
|
3952
|
+
action: z.ZodOptional<z.ZodEnum<["read", "manage"]>>;
|
|
3953
|
+
}, "strip", z.ZodTypeAny, {
|
|
3954
|
+
type: "account";
|
|
3955
|
+
attr: "email" | "repo";
|
|
3956
|
+
action?: "read" | "manage" | undefined;
|
|
3957
|
+
}, {
|
|
3958
|
+
type: "account";
|
|
3959
|
+
attr: "email" | "repo";
|
|
3960
|
+
action?: "read" | "manage" | undefined;
|
|
3961
|
+
}>, string, {
|
|
3962
|
+
type: "account";
|
|
3963
|
+
attr: "email" | "repo";
|
|
3964
|
+
action?: "read" | "manage" | undefined;
|
|
3965
|
+
}>, z.ZodEffects<z.ZodObject<{
|
|
3966
|
+
type: z.ZodLiteral<"repo">;
|
|
3967
|
+
collection: z.ZodUnion<[z.ZodString, z.ZodLiteral<"*">]>;
|
|
3968
|
+
actions: z.ZodOptional<z.ZodArray<z.ZodEnum<["create", "update", "delete"]>, "many">>;
|
|
3969
|
+
}, "strip", z.ZodTypeAny, {
|
|
3970
|
+
type: "repo";
|
|
3971
|
+
collection: string;
|
|
3972
|
+
actions?: ("create" | "update" | "delete")[] | undefined;
|
|
3973
|
+
}, {
|
|
3974
|
+
type: "repo";
|
|
3975
|
+
collection: string;
|
|
3976
|
+
actions?: ("create" | "update" | "delete")[] | undefined;
|
|
3977
|
+
}>, string, {
|
|
3978
|
+
type: "repo";
|
|
3979
|
+
collection: string;
|
|
3980
|
+
actions?: ("create" | "update" | "delete")[] | undefined;
|
|
3981
|
+
}>, z.ZodEffects<z.ZodObject<{
|
|
3982
|
+
type: z.ZodLiteral<"blob">;
|
|
3983
|
+
mimeTypes: z.ZodArray<z.ZodString, "many">;
|
|
3984
|
+
}, "strip", z.ZodTypeAny, {
|
|
3985
|
+
type: "blob";
|
|
3986
|
+
mimeTypes: string[];
|
|
3987
|
+
}, {
|
|
3988
|
+
type: "blob";
|
|
3989
|
+
mimeTypes: string[];
|
|
3990
|
+
}>, string, {
|
|
3991
|
+
type: "blob";
|
|
3992
|
+
mimeTypes: string[];
|
|
3993
|
+
}>, z.ZodEffects<z.ZodEffects<z.ZodObject<{
|
|
3994
|
+
type: z.ZodLiteral<"rpc">;
|
|
3995
|
+
lexicon: z.ZodUnion<[z.ZodString, z.ZodLiteral<"*">]>;
|
|
3996
|
+
aud: z.ZodString;
|
|
3997
|
+
inheritAud: z.ZodOptional<z.ZodBoolean>;
|
|
3998
|
+
}, "strip", z.ZodTypeAny, {
|
|
3999
|
+
type: "rpc";
|
|
4000
|
+
lexicon: string;
|
|
4001
|
+
aud: string;
|
|
4002
|
+
inheritAud?: boolean | undefined;
|
|
4003
|
+
}, {
|
|
4004
|
+
type: "rpc";
|
|
4005
|
+
lexicon: string;
|
|
4006
|
+
aud: string;
|
|
4007
|
+
inheritAud?: boolean | undefined;
|
|
4008
|
+
}>, {
|
|
4009
|
+
type: "rpc";
|
|
4010
|
+
lexicon: string;
|
|
4011
|
+
aud: string;
|
|
4012
|
+
inheritAud?: boolean | undefined;
|
|
4013
|
+
}, {
|
|
4014
|
+
type: "rpc";
|
|
4015
|
+
lexicon: string;
|
|
4016
|
+
aud: string;
|
|
4017
|
+
inheritAud?: boolean | undefined;
|
|
4018
|
+
}>, string, {
|
|
4019
|
+
type: "rpc";
|
|
4020
|
+
lexicon: string;
|
|
4021
|
+
aud: string;
|
|
4022
|
+
inheritAud?: boolean | undefined;
|
|
4023
|
+
}>, z.ZodEffects<z.ZodObject<{
|
|
4024
|
+
type: z.ZodLiteral<"identity">;
|
|
4025
|
+
attr: z.ZodEnum<["handle", "*"]>;
|
|
4026
|
+
}, "strip", z.ZodTypeAny, {
|
|
4027
|
+
type: "identity";
|
|
4028
|
+
attr: "handle" | "*";
|
|
4029
|
+
}, {
|
|
4030
|
+
type: "identity";
|
|
4031
|
+
attr: "handle" | "*";
|
|
4032
|
+
}>, string, {
|
|
4033
|
+
type: "identity";
|
|
4034
|
+
attr: "handle" | "*";
|
|
4035
|
+
}>, z.ZodEffects<z.ZodObject<{
|
|
4036
|
+
type: z.ZodLiteral<"include">;
|
|
4037
|
+
nsid: z.ZodString;
|
|
4038
|
+
aud: z.ZodOptional<z.ZodString>;
|
|
4039
|
+
}, "strip", z.ZodTypeAny, {
|
|
4040
|
+
type: "include";
|
|
4041
|
+
nsid: string;
|
|
4042
|
+
aud?: string | undefined;
|
|
4043
|
+
}, {
|
|
4044
|
+
type: "include";
|
|
4045
|
+
nsid: string;
|
|
4046
|
+
aud?: string | undefined;
|
|
4047
|
+
}>, string, {
|
|
4048
|
+
type: "include";
|
|
4049
|
+
nsid: string;
|
|
4050
|
+
aud?: string | undefined;
|
|
4051
|
+
}>]>;
|
|
4052
|
+
/**
|
|
4053
|
+
* Input type for any permission (before transform).
|
|
4054
|
+
*/
|
|
4055
|
+
type PermissionInput = z.input<typeof PermissionSchema>;
|
|
4056
|
+
/**
|
|
4057
|
+
* Output type for any permission (after transform).
|
|
4058
|
+
*/
|
|
4059
|
+
type Permission = z.output<typeof PermissionSchema>;
|
|
4060
|
+
/**
|
|
4061
|
+
* Fluent builder for constructing OAuth permission arrays.
|
|
4062
|
+
*
|
|
4063
|
+
* This class provides a convenient, type-safe way to build arrays of permissions
|
|
4064
|
+
* using method chaining.
|
|
4065
|
+
*
|
|
4066
|
+
* @example Basic usage
|
|
4067
|
+
* ```typescript
|
|
4068
|
+
* const builder = new PermissionBuilder()
|
|
4069
|
+
* .accountEmail('read')
|
|
4070
|
+
* .repoWrite('app.bsky.feed.post')
|
|
4071
|
+
* .blob(['image/*', 'video/*']);
|
|
4072
|
+
*
|
|
4073
|
+
* const permissions = builder.build();
|
|
4074
|
+
* // Returns: ['account:email?action=read', 'repo:app.bsky.feed.post?action=create&action=update', 'blob:image/*,video/*']
|
|
4075
|
+
* ```
|
|
4076
|
+
*
|
|
4077
|
+
* @example With transitional scopes
|
|
4078
|
+
* ```typescript
|
|
4079
|
+
* const builder = new PermissionBuilder()
|
|
4080
|
+
* .transition('email')
|
|
4081
|
+
* .transition('generic');
|
|
4082
|
+
*
|
|
4083
|
+
* const scopes = builder.build();
|
|
4084
|
+
* // Returns: ['transition:email', 'transition:generic']
|
|
4085
|
+
* ```
|
|
4086
|
+
*/
|
|
4087
|
+
declare class PermissionBuilder {
|
|
4088
|
+
private permissions;
|
|
4089
|
+
/**
|
|
4090
|
+
* Add a transitional scope.
|
|
4091
|
+
*
|
|
4092
|
+
* @param scope - The transitional scope name ('email', 'generic', or 'chat.bsky')
|
|
4093
|
+
* @returns This builder for chaining
|
|
4094
|
+
*
|
|
4095
|
+
* @example
|
|
4096
|
+
* ```typescript
|
|
4097
|
+
* builder.transition('email').transition('generic');
|
|
4098
|
+
* ```
|
|
4099
|
+
*/
|
|
4100
|
+
transition(scope: "email" | "generic" | "chat.bsky"): this;
|
|
4101
|
+
/**
|
|
4102
|
+
* Add an account permission.
|
|
4103
|
+
*
|
|
4104
|
+
* @param attr - The account attribute ('email' or 'repo')
|
|
4105
|
+
* @param action - Optional action ('read' or 'manage')
|
|
4106
|
+
* @returns This builder for chaining
|
|
4107
|
+
*
|
|
4108
|
+
* @example
|
|
4109
|
+
* ```typescript
|
|
4110
|
+
* builder.accountEmail('read').accountRepo('manage');
|
|
4111
|
+
* ```
|
|
4112
|
+
*/
|
|
4113
|
+
account(attr: z.infer<typeof AccountAttrSchema>, action?: z.infer<typeof AccountActionSchema>): this;
|
|
4114
|
+
/**
|
|
4115
|
+
* Convenience method for account:email permission.
|
|
4116
|
+
*
|
|
4117
|
+
* @param action - Optional action ('read' or 'manage')
|
|
4118
|
+
* @returns This builder for chaining
|
|
4119
|
+
*
|
|
4120
|
+
* @example
|
|
4121
|
+
* ```typescript
|
|
4122
|
+
* builder.accountEmail('read');
|
|
4123
|
+
* ```
|
|
4124
|
+
*/
|
|
4125
|
+
accountEmail(action?: z.infer<typeof AccountActionSchema>): this;
|
|
4126
|
+
/**
|
|
4127
|
+
* Convenience method for account:repo permission.
|
|
4128
|
+
*
|
|
4129
|
+
* @param action - Optional action ('read' or 'manage')
|
|
4130
|
+
* @returns This builder for chaining
|
|
4131
|
+
*
|
|
4132
|
+
* @example
|
|
4133
|
+
* ```typescript
|
|
4134
|
+
* builder.accountRepo('manage');
|
|
4135
|
+
* ```
|
|
4136
|
+
*/
|
|
4137
|
+
accountRepo(action?: z.infer<typeof AccountActionSchema>): this;
|
|
4138
|
+
/**
|
|
4139
|
+
* Add a repository permission.
|
|
4140
|
+
*
|
|
4141
|
+
* @param collection - The NSID of the collection or '*' for all
|
|
4142
|
+
* @param actions - Optional array of actions ('create', 'update', 'delete')
|
|
4143
|
+
* @returns This builder for chaining
|
|
4144
|
+
*
|
|
4145
|
+
* @example
|
|
4146
|
+
* ```typescript
|
|
4147
|
+
* builder.repo('app.bsky.feed.post', ['create', 'update']);
|
|
4148
|
+
* ```
|
|
4149
|
+
*/
|
|
4150
|
+
repo(collection: string, actions?: z.infer<typeof RepoActionSchema>[]): this;
|
|
4151
|
+
/**
|
|
4152
|
+
* Convenience method for repository write permissions (create + update).
|
|
4153
|
+
*
|
|
4154
|
+
* @param collection - The NSID of the collection or '*' for all
|
|
4155
|
+
* @returns This builder for chaining
|
|
4156
|
+
*
|
|
4157
|
+
* @example
|
|
4158
|
+
* ```typescript
|
|
4159
|
+
* builder.repoWrite('app.bsky.feed.post');
|
|
4160
|
+
* ```
|
|
4161
|
+
*/
|
|
4162
|
+
repoWrite(collection: string): this;
|
|
4163
|
+
/**
|
|
4164
|
+
* Convenience method for repository read permission (no actions).
|
|
4165
|
+
*
|
|
4166
|
+
* @param collection - The NSID of the collection or '*' for all
|
|
4167
|
+
* @returns This builder for chaining
|
|
4168
|
+
*
|
|
4169
|
+
* @example
|
|
4170
|
+
* ```typescript
|
|
4171
|
+
* builder.repoRead('app.bsky.feed.post');
|
|
4172
|
+
* ```
|
|
4173
|
+
*/
|
|
4174
|
+
repoRead(collection: string): this;
|
|
4175
|
+
/**
|
|
4176
|
+
* Convenience method for full repository permissions (create + update + delete).
|
|
4177
|
+
*
|
|
4178
|
+
* @param collection - The NSID of the collection or '*' for all
|
|
4179
|
+
* @returns This builder for chaining
|
|
4180
|
+
*
|
|
4181
|
+
* @example
|
|
4182
|
+
* ```typescript
|
|
4183
|
+
* builder.repoFull('app.bsky.feed.post');
|
|
4184
|
+
* ```
|
|
4185
|
+
*/
|
|
4186
|
+
repoFull(collection: string): this;
|
|
4187
|
+
/**
|
|
4188
|
+
* Add a blob permission.
|
|
4189
|
+
*
|
|
4190
|
+
* @param mimeTypes - Array of MIME types or a single MIME type
|
|
4191
|
+
* @returns This builder for chaining
|
|
4192
|
+
*
|
|
4193
|
+
* @example
|
|
4194
|
+
* ```typescript
|
|
4195
|
+
* builder.blob(['image/*', 'video/*']);
|
|
4196
|
+
* builder.blob('image/*');
|
|
4197
|
+
* ```
|
|
4198
|
+
*/
|
|
4199
|
+
blob(mimeTypes: string | string[]): this;
|
|
4200
|
+
/**
|
|
4201
|
+
* Add an RPC permission.
|
|
4202
|
+
*
|
|
4203
|
+
* @param lexicon - The NSID of the lexicon or '*' for all
|
|
4204
|
+
* @param aud - The audience (DID or URL)
|
|
4205
|
+
* @param inheritAud - Whether to inherit audience
|
|
4206
|
+
* @returns This builder for chaining
|
|
4207
|
+
*
|
|
4208
|
+
* @example
|
|
4209
|
+
* ```typescript
|
|
4210
|
+
* builder.rpc('com.atproto.repo.createRecord', 'did:web:api.example.com');
|
|
4211
|
+
* ```
|
|
4212
|
+
*/
|
|
4213
|
+
rpc(lexicon: string, aud: string, inheritAud?: boolean): this;
|
|
4214
|
+
/**
|
|
4215
|
+
* Add an identity permission.
|
|
4216
|
+
*
|
|
4217
|
+
* @param attr - The identity attribute ('handle' or '*')
|
|
4218
|
+
* @returns This builder for chaining
|
|
4219
|
+
*
|
|
4220
|
+
* @example
|
|
4221
|
+
* ```typescript
|
|
4222
|
+
* builder.identity('handle');
|
|
4223
|
+
* ```
|
|
4224
|
+
*/
|
|
4225
|
+
identity(attr: z.infer<typeof IdentityAttrSchema>): this;
|
|
4226
|
+
/**
|
|
4227
|
+
* Add an include permission.
|
|
4228
|
+
*
|
|
4229
|
+
* @param nsid - The NSID of the scope set to include
|
|
4230
|
+
* @param aud - Optional audience restriction
|
|
4231
|
+
* @returns This builder for chaining
|
|
4232
|
+
*
|
|
4233
|
+
* @example
|
|
4234
|
+
* ```typescript
|
|
4235
|
+
* builder.include('com.example.authBasicFeatures');
|
|
4236
|
+
* ```
|
|
4237
|
+
*/
|
|
4238
|
+
include(nsid: string, aud?: string): this;
|
|
4239
|
+
/**
|
|
4240
|
+
* Add a custom permission string directly (bypasses validation).
|
|
4241
|
+
*
|
|
4242
|
+
* Use this for testing or special cases where you need to add
|
|
4243
|
+
* a permission that doesn't fit the standard types.
|
|
4244
|
+
*
|
|
4245
|
+
* @param permission - The permission string
|
|
4246
|
+
* @returns This builder for chaining
|
|
4247
|
+
*
|
|
4248
|
+
* @example
|
|
4249
|
+
* ```typescript
|
|
4250
|
+
* builder.custom('atproto');
|
|
4251
|
+
* ```
|
|
4252
|
+
*/
|
|
4253
|
+
custom(permission: string): this;
|
|
4254
|
+
/**
|
|
4255
|
+
* Add the base atproto scope.
|
|
4256
|
+
*
|
|
4257
|
+
* @returns This builder for chaining
|
|
4258
|
+
*
|
|
4259
|
+
* @example
|
|
4260
|
+
* ```typescript
|
|
4261
|
+
* builder.atproto();
|
|
4262
|
+
* ```
|
|
4263
|
+
*/
|
|
4264
|
+
atproto(): this;
|
|
4265
|
+
/**
|
|
4266
|
+
* Build and return the array of permission strings.
|
|
4267
|
+
*
|
|
4268
|
+
* @returns Array of permission strings
|
|
4269
|
+
*
|
|
4270
|
+
* @example
|
|
4271
|
+
* ```typescript
|
|
4272
|
+
* const permissions = builder.build();
|
|
4273
|
+
* ```
|
|
4274
|
+
*/
|
|
4275
|
+
build(): string[];
|
|
4276
|
+
/**
|
|
4277
|
+
* Clear all permissions from the builder.
|
|
4278
|
+
*
|
|
4279
|
+
* @returns This builder for chaining
|
|
4280
|
+
*
|
|
4281
|
+
* @example
|
|
4282
|
+
* ```typescript
|
|
4283
|
+
* builder.clear().accountEmail('read');
|
|
4284
|
+
* ```
|
|
4285
|
+
*/
|
|
4286
|
+
clear(): this;
|
|
4287
|
+
/**
|
|
4288
|
+
* Get the current number of permissions.
|
|
4289
|
+
*
|
|
4290
|
+
* @returns The number of permissions
|
|
4291
|
+
*
|
|
4292
|
+
* @example
|
|
4293
|
+
* ```typescript
|
|
4294
|
+
* const count = builder.count();
|
|
4295
|
+
* ```
|
|
4296
|
+
*/
|
|
4297
|
+
count(): number;
|
|
4298
|
+
}
|
|
4299
|
+
/**
|
|
4300
|
+
* Build a scope string from an array of permissions.
|
|
4301
|
+
*
|
|
4302
|
+
* This is a convenience function that joins permission strings with spaces,
|
|
4303
|
+
* which is the standard format for OAuth scope parameters.
|
|
4304
|
+
*
|
|
4305
|
+
* @param permissions - Array of permission strings
|
|
4306
|
+
* @returns Space-separated scope string
|
|
4307
|
+
*
|
|
4308
|
+
* @example
|
|
4309
|
+
* ```typescript
|
|
4310
|
+
* const permissions = ['account:email?action=read', 'repo:app.bsky.feed.post'];
|
|
4311
|
+
* const scope = buildScope(permissions);
|
|
4312
|
+
* // Returns: "account:email?action=read repo:app.bsky.feed.post"
|
|
4313
|
+
* ```
|
|
4314
|
+
*/
|
|
4315
|
+
declare function buildScope(permissions: string[]): string;
|
|
4316
|
+
/**
|
|
4317
|
+
* Pre-built scope presets for common use cases.
|
|
4318
|
+
*
|
|
4319
|
+
* These presets provide ready-to-use permission sets for typical application scenarios.
|
|
4320
|
+
*/
|
|
4321
|
+
declare const ScopePresets: {
|
|
4322
|
+
/**
|
|
4323
|
+
* Email access scope - allows reading user's email address.
|
|
4324
|
+
*
|
|
4325
|
+
* Includes:
|
|
4326
|
+
* - account:email?action=read
|
|
4327
|
+
*
|
|
4328
|
+
* @example
|
|
4329
|
+
* ```typescript
|
|
4330
|
+
* const scope = ScopePresets.EMAIL_READ;
|
|
4331
|
+
* // Use in OAuth flow to request email access
|
|
4332
|
+
* ```
|
|
4333
|
+
*/
|
|
4334
|
+
readonly EMAIL_READ: string;
|
|
4335
|
+
/**
|
|
4336
|
+
* Profile read scope - allows reading user's profile.
|
|
4337
|
+
*
|
|
4338
|
+
* Includes:
|
|
4339
|
+
* - repo:app.bsky.actor.profile (read-only)
|
|
4340
|
+
*
|
|
4341
|
+
* @example
|
|
4342
|
+
* ```typescript
|
|
4343
|
+
* const scope = ScopePresets.PROFILE_READ;
|
|
4344
|
+
* ```
|
|
4345
|
+
*/
|
|
4346
|
+
readonly PROFILE_READ: string;
|
|
4347
|
+
/**
|
|
4348
|
+
* Profile write scope - allows updating user's profile.
|
|
4349
|
+
*
|
|
4350
|
+
* Includes:
|
|
4351
|
+
* - repo:app.bsky.actor.profile (create + update)
|
|
4352
|
+
*
|
|
4353
|
+
* @example
|
|
4354
|
+
* ```typescript
|
|
4355
|
+
* const scope = ScopePresets.PROFILE_WRITE;
|
|
4356
|
+
* ```
|
|
4357
|
+
*/
|
|
4358
|
+
readonly PROFILE_WRITE: string;
|
|
4359
|
+
/**
|
|
4360
|
+
* Post creation scope - allows creating and updating posts.
|
|
4361
|
+
*
|
|
4362
|
+
* Includes:
|
|
4363
|
+
* - repo:app.bsky.feed.post (create + update)
|
|
4364
|
+
*
|
|
4365
|
+
* @example
|
|
4366
|
+
* ```typescript
|
|
4367
|
+
* const scope = ScopePresets.POST_WRITE;
|
|
4368
|
+
* ```
|
|
4369
|
+
*/
|
|
4370
|
+
readonly POST_WRITE: string;
|
|
4371
|
+
/**
|
|
4372
|
+
* Social interactions scope - allows liking, reposting, and following.
|
|
4373
|
+
*
|
|
4374
|
+
* Includes:
|
|
4375
|
+
* - repo:app.bsky.feed.like (create + update)
|
|
4376
|
+
* - repo:app.bsky.feed.repost (create + update)
|
|
4377
|
+
* - repo:app.bsky.graph.follow (create + update)
|
|
4378
|
+
*
|
|
4379
|
+
* @example
|
|
4380
|
+
* ```typescript
|
|
4381
|
+
* const scope = ScopePresets.SOCIAL_WRITE;
|
|
4382
|
+
* ```
|
|
4383
|
+
*/
|
|
4384
|
+
readonly SOCIAL_WRITE: string;
|
|
4385
|
+
/**
|
|
4386
|
+
* Media upload scope - allows uploading images and videos.
|
|
4387
|
+
*
|
|
4388
|
+
* Includes:
|
|
4389
|
+
* - blob permissions for image/* and video/*
|
|
4390
|
+
*
|
|
4391
|
+
* @example
|
|
4392
|
+
* ```typescript
|
|
4393
|
+
* const scope = ScopePresets.MEDIA_UPLOAD;
|
|
4394
|
+
* ```
|
|
4395
|
+
*/
|
|
4396
|
+
readonly MEDIA_UPLOAD: string;
|
|
4397
|
+
/**
|
|
4398
|
+
* Image upload only scope - allows uploading images.
|
|
4399
|
+
*
|
|
4400
|
+
* Includes:
|
|
4401
|
+
* - blob:image/*
|
|
4402
|
+
*
|
|
4403
|
+
* @example
|
|
4404
|
+
* ```typescript
|
|
4405
|
+
* const scope = ScopePresets.IMAGE_UPLOAD;
|
|
4406
|
+
* ```
|
|
4407
|
+
*/
|
|
4408
|
+
readonly IMAGE_UPLOAD: string;
|
|
4409
|
+
/**
|
|
4410
|
+
* Posting app scope - full posting capabilities including media.
|
|
4411
|
+
*
|
|
4412
|
+
* Includes:
|
|
4413
|
+
* - repo:app.bsky.feed.post (create + update)
|
|
4414
|
+
* - repo:app.bsky.feed.like (create + update)
|
|
4415
|
+
* - repo:app.bsky.feed.repost (create + update)
|
|
4416
|
+
* - blob permissions for image/* and video/*
|
|
4417
|
+
*
|
|
4418
|
+
* @example
|
|
4419
|
+
* ```typescript
|
|
4420
|
+
* const scope = ScopePresets.POSTING_APP;
|
|
4421
|
+
* ```
|
|
4422
|
+
*/
|
|
4423
|
+
readonly POSTING_APP: string;
|
|
4424
|
+
/**
|
|
4425
|
+
* Read-only app scope - allows reading all repository data.
|
|
4426
|
+
*
|
|
4427
|
+
* Includes:
|
|
4428
|
+
* - repo:* (read-only, no actions)
|
|
4429
|
+
*
|
|
4430
|
+
* @example
|
|
4431
|
+
* ```typescript
|
|
4432
|
+
* const scope = ScopePresets.READ_ONLY;
|
|
4433
|
+
* ```
|
|
4434
|
+
*/
|
|
4435
|
+
readonly READ_ONLY: string;
|
|
4436
|
+
/**
|
|
4437
|
+
* Full access scope - allows all repository operations.
|
|
4438
|
+
*
|
|
4439
|
+
* Includes:
|
|
4440
|
+
* - repo:* (create + update + delete)
|
|
4441
|
+
*
|
|
4442
|
+
* @example
|
|
4443
|
+
* ```typescript
|
|
4444
|
+
* const scope = ScopePresets.FULL_ACCESS;
|
|
4445
|
+
* ```
|
|
4446
|
+
*/
|
|
4447
|
+
readonly FULL_ACCESS: string;
|
|
4448
|
+
/**
|
|
4449
|
+
* Email + Profile scope - common combination for user identification.
|
|
4450
|
+
*
|
|
4451
|
+
* Includes:
|
|
4452
|
+
* - account:email?action=read
|
|
4453
|
+
* - repo:app.bsky.actor.profile (read-only)
|
|
4454
|
+
*
|
|
4455
|
+
* @example
|
|
4456
|
+
* ```typescript
|
|
4457
|
+
* const scope = ScopePresets.EMAIL_AND_PROFILE;
|
|
4458
|
+
* ```
|
|
4459
|
+
*/
|
|
4460
|
+
readonly EMAIL_AND_PROFILE: string;
|
|
4461
|
+
/**
|
|
4462
|
+
* Transitional email scope (legacy).
|
|
4463
|
+
*
|
|
4464
|
+
* Uses the transitional scope format for backward compatibility.
|
|
4465
|
+
*
|
|
4466
|
+
* @example
|
|
4467
|
+
* ```typescript
|
|
4468
|
+
* const scope = ScopePresets.TRANSITION_EMAIL;
|
|
4469
|
+
* ```
|
|
4470
|
+
*/
|
|
4471
|
+
readonly TRANSITION_EMAIL: string;
|
|
4472
|
+
/**
|
|
4473
|
+
* Transitional generic scope (legacy).
|
|
4474
|
+
*
|
|
4475
|
+
* Uses the transitional scope format for backward compatibility.
|
|
4476
|
+
*
|
|
4477
|
+
* @example
|
|
4478
|
+
* ```typescript
|
|
4479
|
+
* const scope = ScopePresets.TRANSITION_GENERIC;
|
|
4480
|
+
* ```
|
|
4481
|
+
*/
|
|
4482
|
+
readonly TRANSITION_GENERIC: string;
|
|
4483
|
+
};
|
|
4484
|
+
/**
|
|
4485
|
+
* Parse a scope string into an array of individual permissions.
|
|
4486
|
+
*
|
|
4487
|
+
* This splits a space-separated scope string into individual permission strings.
|
|
4488
|
+
*
|
|
4489
|
+
* @param scope - Space-separated scope string
|
|
4490
|
+
* @returns Array of permission strings
|
|
4491
|
+
*
|
|
4492
|
+
* @example
|
|
4493
|
+
* ```typescript
|
|
4494
|
+
* const scope = "account:email?action=read repo:app.bsky.feed.post";
|
|
4495
|
+
* const permissions = parseScope(scope);
|
|
4496
|
+
* // Returns: ['account:email?action=read', 'repo:app.bsky.feed.post']
|
|
4497
|
+
* ```
|
|
4498
|
+
*/
|
|
4499
|
+
declare function parseScope(scope: string): string[];
|
|
4500
|
+
/**
|
|
4501
|
+
* Check if a scope string contains a specific permission.
|
|
4502
|
+
*
|
|
4503
|
+
* This function performs exact string matching. For more advanced
|
|
4504
|
+
* permission checking (e.g., wildcard matching), you'll need to
|
|
4505
|
+
* implement custom logic.
|
|
4506
|
+
*
|
|
4507
|
+
* @param scope - Space-separated scope string
|
|
4508
|
+
* @param permission - The permission to check for
|
|
4509
|
+
* @returns True if the scope contains the permission
|
|
4510
|
+
*
|
|
4511
|
+
* @example
|
|
4512
|
+
* ```typescript
|
|
4513
|
+
* const scope = "account:email?action=read repo:app.bsky.feed.post";
|
|
4514
|
+
* hasPermission(scope, "account:email?action=read"); // true
|
|
4515
|
+
* hasPermission(scope, "account:repo"); // false
|
|
4516
|
+
* ```
|
|
4517
|
+
*/
|
|
4518
|
+
declare function hasPermission(scope: string, permission: string): boolean;
|
|
4519
|
+
/**
|
|
4520
|
+
* Check if a scope string contains all of the specified permissions.
|
|
4521
|
+
*
|
|
4522
|
+
* @param scope - Space-separated scope string
|
|
4523
|
+
* @param requiredPermissions - Array of permissions to check for
|
|
4524
|
+
* @returns True if the scope contains all required permissions
|
|
4525
|
+
*
|
|
4526
|
+
* @example
|
|
4527
|
+
* ```typescript
|
|
4528
|
+
* const scope = "account:email?action=read repo:app.bsky.feed.post blob:image/*";
|
|
4529
|
+
* hasAllPermissions(scope, ["account:email?action=read", "blob:image/*"]); // true
|
|
4530
|
+
* hasAllPermissions(scope, ["account:email?action=read", "account:repo"]); // false
|
|
4531
|
+
* ```
|
|
4532
|
+
*/
|
|
4533
|
+
declare function hasAllPermissions(scope: string, requiredPermissions: string[]): boolean;
|
|
4534
|
+
/**
|
|
4535
|
+
* Check if a scope string contains any of the specified permissions.
|
|
4536
|
+
*
|
|
4537
|
+
* @param scope - Space-separated scope string
|
|
4538
|
+
* @param checkPermissions - Array of permissions to check for
|
|
4539
|
+
* @returns True if the scope contains at least one of the permissions
|
|
4540
|
+
*
|
|
4541
|
+
* @example
|
|
4542
|
+
* ```typescript
|
|
4543
|
+
* const scope = "account:email?action=read repo:app.bsky.feed.post";
|
|
4544
|
+
* hasAnyPermission(scope, ["account:email?action=read", "account:repo"]); // true
|
|
4545
|
+
* hasAnyPermission(scope, ["account:repo", "identity:handle"]); // false
|
|
4546
|
+
* ```
|
|
4547
|
+
*/
|
|
4548
|
+
declare function hasAnyPermission(scope: string, checkPermissions: string[]): boolean;
|
|
4549
|
+
/**
|
|
4550
|
+
* Merge multiple scope strings into a single scope string with deduplicated permissions.
|
|
4551
|
+
*
|
|
4552
|
+
* @param scopes - Array of scope strings to merge
|
|
4553
|
+
* @returns Merged scope string with unique permissions
|
|
4554
|
+
*
|
|
4555
|
+
* @example
|
|
4556
|
+
* ```typescript
|
|
4557
|
+
* const scope1 = "account:email?action=read repo:app.bsky.feed.post";
|
|
4558
|
+
* const scope2 = "repo:app.bsky.feed.post blob:image/*";
|
|
4559
|
+
* const merged = mergeScopes([scope1, scope2]);
|
|
4560
|
+
* // Returns: "account:email?action=read repo:app.bsky.feed.post blob:image/*"
|
|
4561
|
+
* ```
|
|
4562
|
+
*/
|
|
4563
|
+
declare function mergeScopes(scopes: string[]): string;
|
|
4564
|
+
/**
|
|
4565
|
+
* Remove specific permissions from a scope string.
|
|
4566
|
+
*
|
|
4567
|
+
* @param scope - Space-separated scope string
|
|
4568
|
+
* @param permissionsToRemove - Array of permissions to remove
|
|
4569
|
+
* @returns New scope string without the specified permissions
|
|
4570
|
+
*
|
|
4571
|
+
* @example
|
|
4572
|
+
* ```typescript
|
|
4573
|
+
* const scope = "account:email?action=read repo:app.bsky.feed.post blob:image/*";
|
|
4574
|
+
* const filtered = removePermissions(scope, ["blob:image/*"]);
|
|
4575
|
+
* // Returns: "account:email?action=read repo:app.bsky.feed.post"
|
|
4576
|
+
* ```
|
|
4577
|
+
*/
|
|
4578
|
+
declare function removePermissions(scope: string, permissionsToRemove: string[]): string;
|
|
4579
|
+
/**
|
|
4580
|
+
* Validate that all permissions in a scope string are well-formed.
|
|
4581
|
+
*
|
|
4582
|
+
* This checks that each permission matches expected patterns for transitional
|
|
4583
|
+
* or granular permissions. It does NOT validate against the full Zod schemas.
|
|
4584
|
+
*
|
|
4585
|
+
* @param scope - Space-separated scope string
|
|
4586
|
+
* @returns Object with isValid flag and array of invalid permissions
|
|
4587
|
+
*
|
|
4588
|
+
* @example
|
|
4589
|
+
* ```typescript
|
|
4590
|
+
* const scope = "account:email?action=read invalid:permission";
|
|
4591
|
+
* const result = validateScope(scope);
|
|
4592
|
+
* // Returns: { isValid: false, invalidPermissions: ['invalid:permission'] }
|
|
4593
|
+
* ```
|
|
4594
|
+
*/
|
|
4595
|
+
declare function validateScope(scope: string): {
|
|
4596
|
+
isValid: boolean;
|
|
4597
|
+
invalidPermissions: string[];
|
|
4598
|
+
};
|
|
4599
|
+
|
|
4600
|
+
export { ATPROTO_SCOPE, ATProtoSDK, ATProtoSDKConfigSchema, ATProtoSDKError, AccountActionSchema, AccountAttrSchema, AccountPermissionSchema, AuthenticationError, BlobPermissionSchema, CollaboratorPermissionsSchema, CollaboratorSchema, ConfigurableAgent, HYPERCERT_COLLECTIONS, HYPERCERT_LEXICONS, IdentityAttrSchema, IdentityPermissionSchema, InMemorySessionStore, InMemoryStateStore, IncludePermissionSchema, MimeTypeSchema, NetworkError, NsidSchema, OAuthConfigSchema, OrganizationSchema, PermissionBuilder, PermissionSchema, RepoActionSchema, RepoPermissionSchema, Repository, RpcPermissionSchema, SDSRequiredError, ScopePresets, ServerConfigSchema, SessionExpiredError, TRANSITION_SCOPES, TimeoutConfigSchema, TransitionScopeSchema, ValidationError, buildScope, createATProtoSDK, hasAllPermissions, hasAnyPermission, hasPermission, mergeScopes, parseScope, removePermissions, validateScope };
|
|
4601
|
+
export type { ATProtoSDKConfig, AccountAction, AccountAttr, AccountPermissionInput, AuthorizeOptions, BadgeAward, BadgeDefinition, BadgeResponse, BlobOperations, BlobPermissionInput, CacheInterface, Collaborator, CollaboratorOperations, CollaboratorPermissions, CreateHypercertParams, CreateHypercertResult, CreateResult, DID, FundingReceipt, HypercertClaim, HypercertCollection, HypercertCollectionClaimItem, HypercertContribution, HypercertEvaluation, HypercertEvents, HypercertEvidence, HypercertImage, HypercertImageRecord, HypercertLocation, HypercertMeasurement, HypercertOperations, HypercertProject, HypercertRights, HypercertWithMetadata, IdentityAttr, IdentityPermissionInput, IncludePermissionInput, ListParams, LoggerInterface, Organization, OrganizationInfo, OrganizationOperations, PaginatedList, Permission, PermissionInput, ProfileOperations, ProgressStep, RecordOperations, RepoAction, RepoPermissionInput, RepositoryAccessGrant, RepositoryOptions, RepositoryRole, RpcPermissionInput, Session, SessionStore, StateStore, StrongRef, TransitionScope, UpdateResult };
|