@winche-technologies/admin 0.0.0-stage → 3.0.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.
@@ -0,0 +1,631 @@
1
+ /**
2
+ * @winche/admin — a Winche project's data: documents, files, the app's users, assets, and calling functions.
3
+ *
4
+ * import { documents, files, FieldValue } from "@winche/admin";
5
+ *
6
+ * await documents.doc("patients/p1").update({ visits: FieldValue.increment(1) });
7
+ * const report = await files.child("reports/a.pdf").getData();
8
+ *
9
+ * The same API wherever it runs; only who it acts as differs:
10
+ *
11
+ * - in functions: the server (full rights, access rules don't apply);
12
+ * - in a console page: the person who opened it, limited by their role in the project (viewer reads, member writes
13
+ * data, admin does everything);
14
+ * - anywhere else: `initializeAdmin({ server, project, token })`, limited by the token's role.
15
+ *
16
+ * `as(user)` gives the same API acting as one of the app's users: every documents and files call is checked against
17
+ * the project's access rules for them, as if the app had made it.
18
+ *
19
+ * References (`doc`, `collection`, `child`, `user`) and the snapshots their reads return read like the Dart SDKs.
20
+ */
21
+ export type Json = null | boolean | number | string | Json[] | {
22
+ [key: string]: Json;
23
+ };
24
+ /** A latitude / longitude pair (geoPointValue). */
25
+ export declare class GeoPoint {
26
+ readonly latitude: number;
27
+ readonly longitude: number;
28
+ constructor(latitude: number, longitude: number);
29
+ isEqual(other: GeoPoint): boolean;
30
+ }
31
+ export type LinkKind = "document" | "file" | "user";
32
+ /**
33
+ * A typed reference stored in a document: to a document, a file or a user. Reads give every stored reference back as a
34
+ * Link; `data()` is what it points to when the read expanded it (`expand(["patient"])`), else null. Write one with
35
+ * `Link.document(path)`, `Link.file(path)`, `Link.user(uid)`, or a reference (`documents.doc(...)`, …).
36
+ */
37
+ export declare class Link<T = unknown> {
38
+ readonly kind: LinkKind;
39
+ readonly target: string;
40
+ private readonly resolved;
41
+ /** @internal */ constructor(kind: LinkKind, target: string, resolved?: (() => T | null) | null);
42
+ static document(path: string): Link<DocumentData>;
43
+ static file(path: string): Link<FileData>;
44
+ static user(uid: string): Link<UserData>;
45
+ /** What it points to, when the read expanded it and the target exists; null otherwise. */
46
+ data(): T | null;
47
+ isEqual(other: unknown): boolean;
48
+ toString(): string;
49
+ }
50
+ type FieldValueKind = "delete" | "serverTimestamp" | "increment" | "maximum" | "minimum" | "arrayUnion" | "arrayRemove";
51
+ /** Sentinels for set / update: server-side transforms, and removing a field. */
52
+ export declare class FieldValue {
53
+ readonly kind: FieldValueKind;
54
+ readonly operand?: unknown;
55
+ private constructor();
56
+ /** Removes the field (update, or set with merge / mergeFields). */
57
+ static delete(): FieldValue;
58
+ /** The write's commit time. */
59
+ static serverTimestamp(): FieldValue;
60
+ /** Adds n (integers stay integers; a double makes a double). A missing or non-number field becomes n. */
61
+ static increment(n: number | bigint): FieldValue;
62
+ /** Keeps the larger of the field and n. */
63
+ static maximum(n: number | bigint): FieldValue;
64
+ /** Keeps the smaller of the field and n. */
65
+ static minimum(n: number | bigint): FieldValue;
66
+ /** Appends the elements not already in the array. */
67
+ static arrayUnion(...elements: unknown[]): FieldValue;
68
+ /** Removes every element equal to one of these. */
69
+ static arrayRemove(...elements: unknown[]): FieldValue;
70
+ }
71
+ /** A document's fields, decoded: numbers, strings, booleans, null, Date (timestamps), Uint8Array (bytes), GeoPoint, Link, arrays and maps. */
72
+ export type DocumentData = {
73
+ [field: string]: any;
74
+ };
75
+ type Tagged = {
76
+ [tag: string]: any;
77
+ };
78
+ /** Where links read from a document find what they point to (the read's included documents and resolved files/users). */
79
+ interface Expansion {
80
+ included: {
81
+ [path: string]: any;
82
+ };
83
+ resolved: {
84
+ [key: string]: any;
85
+ };
86
+ }
87
+ /** @internal JS value → tagged wire value. */
88
+ export declare function encodeValue(v: unknown): Tagged;
89
+ /** @internal */
90
+ export declare function encodeFields(fields: {
91
+ [k: string]: unknown;
92
+ }): {
93
+ [k: string]: Tagged;
94
+ };
95
+ /** @internal Tagged wire value → JS value. */
96
+ export declare function decodeValue(t: Tagged | null | undefined, x?: Expansion): any;
97
+ /** @internal */
98
+ export declare function decodeFields(fields: {
99
+ [k: string]: Tagged;
100
+ } | null | undefined, x?: Expansion): DocumentData;
101
+ /**
102
+ * The protocol this SDK speaks with Winche (its operations and how it finds the server where it runs). A server says
103
+ * which it speaks; one that doesn't speak this one refuses the SDK's calls, saying which version to use.
104
+ */
105
+ export declare const PROTOCOL = 1;
106
+ /** @internal A call into the server: the runtime's bridge in functions, the console's channel in pages, HTTP elsewhere. */
107
+ export type Call = (op: string, args: {
108
+ [k: string]: unknown;
109
+ }) => Promise<any>;
110
+ /** An error from the server: its code (e.g. "permission-denied", "not-found") and message. */
111
+ export declare class WincheError extends Error {
112
+ code: string;
113
+ constructor(code: string, message: string);
114
+ }
115
+ /** A write condition: the document exists (or not), or is unchanged since a read (`snapshot.updateTimeRaw`). */
116
+ export interface Precondition {
117
+ exists?: boolean;
118
+ updateTime?: string;
119
+ }
120
+ export interface SetOptions {
121
+ /** Merge into the existing document (deep, maps into maps) instead of replacing it. */
122
+ merge?: boolean;
123
+ /** Write only these field paths (others are left as they are); a listed path missing from data is removed. */
124
+ mergeFields?: string[];
125
+ precondition?: Precondition;
126
+ }
127
+ export type WhereOp = "==" | "!=" | "<" | "<=" | ">" | ">=" | "in" | "not-in" | "array-contains" | "array-contains-any" | "array-contains-all" | "contains" | "starts-with" | "ends-with" | "matches";
128
+ /** Filters to combine: `query.where(Filter.or(Filter.where("a", "==", 1), Filter.where("b", "==", 2)))`. */
129
+ export declare class Filter {
130
+ readonly wire: Tagged;
131
+ private constructor();
132
+ static where(field: string, op: WhereOp, value: unknown): Filter;
133
+ static and(...filters: Filter[]): Filter;
134
+ static or(...filters: Filter[]): Filter;
135
+ static not(filter: Filter): Filter;
136
+ /** The field is null. */
137
+ static isNull(field: string): Filter;
138
+ /** The field is NaN. */
139
+ static isNan(field: string): Filter;
140
+ /** The field is there (any value, null included). */
141
+ static exists(field: string): Filter;
142
+ }
143
+ export type Aggregate = {
144
+ kind: "count";
145
+ } | {
146
+ kind: "sum";
147
+ field: string;
148
+ } | {
149
+ kind: "average";
150
+ field: string;
151
+ };
152
+ export declare const Aggregate: {
153
+ count: () => Aggregate;
154
+ sum: (field: string) => Aggregate;
155
+ average: (field: string) => Aggregate;
156
+ };
157
+ interface QueryState {
158
+ collection: string;
159
+ group: boolean;
160
+ filters: Tagged[];
161
+ orderBy: {
162
+ field: string;
163
+ direction: "asc" | "desc";
164
+ }[];
165
+ limit?: number;
166
+ limitToLast?: number;
167
+ offset?: number;
168
+ start?: {
169
+ values: unknown[] | DocumentSnapshot;
170
+ before: boolean;
171
+ };
172
+ end?: {
173
+ values: unknown[] | DocumentSnapshot;
174
+ before: boolean;
175
+ };
176
+ select?: string[];
177
+ expand?: string[];
178
+ }
179
+ /** A read of a collection (or a collection group): chain filters and order, then get(), count(), sum(), … */
180
+ export declare class Query<T = DocumentData> {
181
+ protected readonly call: Call;
182
+ protected readonly state: QueryState;
183
+ /** @internal */ constructor(call: Call, /** @internal */ state: QueryState);
184
+ private with;
185
+ /** `where("age", ">=", 18)`, or a combined `Filter`. */
186
+ where(field: string, op: WhereOp, value: unknown): Query<T>;
187
+ where(filter: Filter): Query<T>;
188
+ orderBy(field: string, direction?: "asc" | "desc"): Query<T>;
189
+ limit(n: number): Query<T>;
190
+ /** The last n of an ordered query (in order). */
191
+ limitToLast(n: number): Query<T>;
192
+ offset(n: number): Query<T>;
193
+ /** Cursors: the orderBy fields' values, or a snapshot (its values for them, and its path). */
194
+ startAt(...at: unknown[]): Query<T>;
195
+ startAfter(...at: unknown[]): Query<T>;
196
+ endAt(...at: unknown[]): Query<T>;
197
+ endBefore(...at: unknown[]): Query<T>;
198
+ /** Only these fields in the results (the server leaves the rest out). */
199
+ select(...fields: string[]): Query<T>;
200
+ /** Follow these reference fields: their Links' data() is what they point to. */
201
+ expand(paths: string[]): Query<T>;
202
+ /** @internal The query in the wire format. */
203
+ toWire(): Tagged;
204
+ get(): Promise<QuerySnapshot<T>>;
205
+ /** How many documents match (no limit). */
206
+ count(): Promise<number>;
207
+ /** The sum of a numeric field over the matches. */
208
+ sum(field: string): Promise<number>;
209
+ /** The average of a numeric field over the matches (null when none). */
210
+ average(field: string): Promise<number | null>;
211
+ /** Several at once: `aggregate({ n: Aggregate.count(), total: Aggregate.sum("amount") })`. */
212
+ aggregate<K extends string>(aggregates: {
213
+ [alias in K]: Aggregate;
214
+ }): Promise<{
215
+ [alias in K]: number | null;
216
+ }>;
217
+ }
218
+ /** A collection: a query over its documents, and where new ones go. */
219
+ export declare class CollectionReference<T = DocumentData> extends Query<T> {
220
+ readonly path: string;
221
+ /** @internal */ constructor(call: Call, path: string);
222
+ get id(): string;
223
+ /** The document this collection is under (null at the top). */
224
+ get parent(): DocumentReference | null;
225
+ /** A document in it; without an id, a new random one. */
226
+ doc(id?: string): DocumentReference<T>;
227
+ /** Adds a document with a new id. */
228
+ add(data: T & DocumentData): Promise<DocumentReference<T>>;
229
+ }
230
+ /** A document: read it, write it, reach its sub-collections. */
231
+ export declare class DocumentReference<T = DocumentData> {
232
+ private readonly call;
233
+ readonly path: string;
234
+ private readonly expandPaths?;
235
+ /** @internal */ constructor(call: Call, path: string, /** @internal */ expandPaths?: string[]);
236
+ get id(): string;
237
+ get parent(): CollectionReference<T>;
238
+ collection(path: string): CollectionReference;
239
+ /** Follow these reference fields on get(): their Links' data() is what they point to. */
240
+ expand(paths: string[]): DocumentReference<T>;
241
+ get(): Promise<DocumentSnapshot<T>>;
242
+ /** Replaces the document (or merges into it, or writes the mergeFields only). */
243
+ set(data: T & DocumentData, options?: SetOptions): Promise<void>;
244
+ /** Changes these fields (dotted paths reach into maps) of an existing document. */
245
+ update(data: {
246
+ [fieldPath: string]: unknown;
247
+ }, options?: {
248
+ precondition?: Precondition;
249
+ }): Promise<void>;
250
+ /** Deletes it; with cascade, everything under it too (in one write: for big trees, use documents.recursiveDelete). */
251
+ delete(options?: {
252
+ cascade?: boolean;
253
+ precondition?: Precondition;
254
+ }): Promise<void>;
255
+ isEqual(other: unknown): boolean;
256
+ }
257
+ /** A document as read: `exists`, `data()`, and its metadata. */
258
+ export declare class DocumentSnapshot<T = DocumentData> {
259
+ readonly reference: DocumentReference<T>;
260
+ readonly exists: boolean;
261
+ private readonly fields;
262
+ private readonly meta;
263
+ /** @internal */ constructor(reference: DocumentReference<T>, exists: boolean, fields: DocumentData | null, meta: {
264
+ createTime: string;
265
+ updateTime: string;
266
+ version: number;
267
+ } | null);
268
+ /** @internal From the wire (with the read's expansion for its links). */
269
+ static of<T>(call: Call, d: Tagged, x?: Expansion): DocumentSnapshot<T>;
270
+ get id(): string;
271
+ /** The fields (undefined when it doesn't exist). */
272
+ data(): T | undefined;
273
+ /** One field, by dotted path ("address.city"); undefined when it isn't there. */
274
+ get(fieldPath: string): any;
275
+ get createTime(): Date | null;
276
+ get updateTime(): Date | null;
277
+ /** The update time exactly as the server has it (microseconds), for `precondition: { updateTime }`. */
278
+ get updateTimeRaw(): string | null;
279
+ get version(): number | null;
280
+ }
281
+ export declare class QuerySnapshot<T = DocumentData> {
282
+ readonly docs: DocumentSnapshot<T>[];
283
+ readonly hasMore: boolean;
284
+ /** @internal */ constructor(docs: DocumentSnapshot<T>[], /** True when more matched past the limit. */ hasMore: boolean);
285
+ get size(): number;
286
+ get empty(): boolean;
287
+ forEach(fn: (doc: DocumentSnapshot<T>) => void): void;
288
+ }
289
+ /** Up to 500 writes, all or none. */
290
+ export declare class WriteBatch {
291
+ private readonly call;
292
+ private readonly writes;
293
+ /** @internal */ constructor(call: Call);
294
+ set<T>(ref: DocumentReference<T>, data: T & DocumentData, options?: SetOptions): this;
295
+ update(ref: DocumentReference<any>, data: {
296
+ [fieldPath: string]: unknown;
297
+ }, options?: {
298
+ precondition?: Precondition;
299
+ }): this;
300
+ delete(ref: DocumentReference<any>, options?: {
301
+ cascade?: boolean;
302
+ precondition?: Precondition;
303
+ }): this;
304
+ get size(): number;
305
+ commit(): Promise<void>;
306
+ }
307
+ /**
308
+ * A transaction's reads and writes. Optimistic: each document it read and then writes must be unchanged when it
309
+ * commits (else the whole function runs again, up to maxAttempts). Reads must come before writes.
310
+ */
311
+ export declare class Transaction {
312
+ private readonly call;
313
+ private readonly writes;
314
+ /** @internal path → updateTimeRaw (null: it didn't exist) */ readonly seen: Map<string, string>;
315
+ /** @internal */ constructor(call: Call);
316
+ get<T>(ref: DocumentReference<T>): Promise<DocumentSnapshot<T>>;
317
+ private guard;
318
+ set<T>(ref: DocumentReference<T>, data: T & DocumentData, options?: SetOptions): this;
319
+ update(ref: DocumentReference<any>, data: {
320
+ [fieldPath: string]: unknown;
321
+ }, options?: {
322
+ precondition?: Precondition;
323
+ }): this;
324
+ delete(ref: DocumentReference<any>, options?: {
325
+ precondition?: Precondition;
326
+ }): this;
327
+ /** @internal */ commit(): Promise<void>;
328
+ }
329
+ export declare class Documents {
330
+ private readonly call;
331
+ /** @internal */ constructor(call: Call);
332
+ /** A collection by path ("patients", "patients/p1/visits"). */
333
+ collection(path: string): CollectionReference;
334
+ /** A document by path ("patients/p1"). */
335
+ doc(path: string): DocumentReference;
336
+ /** Every collection with this id, under any parent ("sessionHistory"). */
337
+ collectionGroup(id: string): Query;
338
+ /** Several documents in one call, in order. */
339
+ getAll(refs: DocumentReference<any>[]): Promise<DocumentSnapshot[]>;
340
+ batch(): WriteBatch;
341
+ /** Deletes a document and everything under it, in batches (any size); how many documents went. */
342
+ recursiveDelete(ref: DocumentReference<any>): Promise<number>;
343
+ /** Runs `fn` with a transaction and commits it; runs it again when something it read changed meanwhile. */
344
+ runTransaction<R>(fn: (tx: Transaction) => Promise<R>, options?: {
345
+ maxAttempts?: number;
346
+ }): Promise<R>;
347
+ }
348
+ /** A file's record: what it is, not its bytes. */
349
+ export interface FileData {
350
+ id: string;
351
+ path: string;
352
+ directory: string;
353
+ mimeType: string;
354
+ sizeBytes: number;
355
+ uploadStatus: "pending" | "complete";
356
+ contentDisposition: string | null;
357
+ cacheControl: string | null;
358
+ contentHash: string | null;
359
+ metadata: {
360
+ [key: string]: Json;
361
+ };
362
+ version: number;
363
+ createdAt: Date;
364
+ updatedAt: Date;
365
+ }
366
+ /** @internal */
367
+ export declare function fileData(r: any): FileData;
368
+ export interface PutOptions {
369
+ /** Default: text/plain for text, application/octet-stream for bytes. */
370
+ mimeType?: string;
371
+ metadata?: {
372
+ [key: string]: Json;
373
+ };
374
+ /** What browsers do with it when downloaded, e.g. 'attachment; filename="report.pdf"'. */
375
+ contentDisposition?: string;
376
+ cacheControl?: string;
377
+ }
378
+ /** A file (or a folder) by path. */
379
+ export declare class ChildReference {
380
+ private readonly call;
381
+ readonly path: string;
382
+ /** @internal */ constructor(call: Call, path: string);
383
+ /** The last part of the path. */
384
+ get name(): string;
385
+ get parent(): ChildReference | null;
386
+ child(path: string): ChildReference;
387
+ /** The file's record; `exists` is false when there's none. */
388
+ getSnapshot(): Promise<FileSnapshot>;
389
+ /** The bytes (up to 32 MB), or null when there's no file. */
390
+ getData(): Promise<Uint8Array | null>;
391
+ /** The contents as UTF-8 text, or null. */
392
+ getText(): Promise<string | null>;
393
+ /** Writes the file (new or replacing one), up to 32 MB; its triggers and hooks run as for an upload. */
394
+ putData(data: Uint8Array | ArrayBuffer | string, options?: PutOptions): Promise<FileSnapshot>;
395
+ /**
396
+ * Writes the file from a URL (a GET with these headers), up to 5 GB: the bytes go from the URL to storage on the
397
+ * server, never through the function. The type is the one given, else the response's.
398
+ */
399
+ putFromUrl(url: string, options?: PutOptions & {
400
+ headers?: {
401
+ [name: string]: string;
402
+ };
403
+ }): Promise<FileSnapshot>;
404
+ /** One page of the folder: files and sub-folders in name order. */
405
+ list(options?: {
406
+ maxResults?: number;
407
+ pageToken?: string;
408
+ mimeType?: string;
409
+ }): Promise<DirectorySnapshot>;
410
+ /** Every file and sub-folder of the folder (all pages). */
411
+ listChildren(options?: {
412
+ mimeType?: string;
413
+ }): Promise<DirectorySnapshot>;
414
+ /** Merges metadata (null removes a key); optionally changes the download headers ("" clears one), only at ifVersion. */
415
+ updateMetadata(metadata: {
416
+ [key: string]: Json;
417
+ }, options?: {
418
+ contentDisposition?: string;
419
+ cacheControl?: string;
420
+ ifVersion?: number;
421
+ }): Promise<FileSnapshot>;
422
+ /** Deletes the file, or everything under the folder. False when nothing was there. */
423
+ delete(): Promise<boolean>;
424
+ /** A link anyone holding it can download the file with, until expiresAt. */
425
+ downloadUrl(): Promise<{
426
+ url: string;
427
+ expiresAt: Date;
428
+ }>;
429
+ isEqual(other: unknown): boolean;
430
+ }
431
+ export declare class FileSnapshot {
432
+ readonly reference: ChildReference;
433
+ readonly data: FileData | null;
434
+ /** @internal */ constructor(reference: ChildReference, data: FileData | null);
435
+ get exists(): boolean;
436
+ }
437
+ export declare class DirectorySnapshot {
438
+ readonly reference: ChildReference;
439
+ readonly files: FileSnapshot[];
440
+ readonly folders: ChildReference[];
441
+ readonly nextPageToken: string | null;
442
+ /** @internal */ constructor(reference: ChildReference, files: FileSnapshot[], folders: ChildReference[], nextPageToken: string | null);
443
+ }
444
+ export declare class Files {
445
+ private readonly call;
446
+ /** @internal */ constructor(call: Call);
447
+ /** A file or folder by path; "" is the top. */
448
+ child(path: string): ChildReference;
449
+ }
450
+ /** A user's account. */
451
+ export interface UserData {
452
+ uid: string;
453
+ email: string | null;
454
+ emailVerified: boolean;
455
+ displayName: string | null;
456
+ photoUrl: string | null;
457
+ isAnonymous: boolean;
458
+ disabled: boolean;
459
+ mfaEnabled: boolean;
460
+ /** How they sign in: password, anonymous, google, … */
461
+ providers: string[];
462
+ customClaims: {
463
+ [claim: string]: Json;
464
+ };
465
+ createdAt: Date | null;
466
+ lastSignInAt: Date | null;
467
+ }
468
+ /** @internal */
469
+ export declare function userData(u: any): UserData;
470
+ /** A user, by uid. */
471
+ export declare class UserReference {
472
+ private readonly call;
473
+ readonly uid: string;
474
+ /** @internal */ constructor(call: Call, uid: string);
475
+ /** Their account; `exists` is false when there's no such user. */
476
+ get(): Promise<UserSnapshot>;
477
+ /** Their custom claims ({} when none). Throws not-found when there's no such user. */
478
+ getCustomClaims(): Promise<{
479
+ [claim: string]: Json;
480
+ }>;
481
+ /** Replaces their custom claims (null clears them); they're in the user's next token. */
482
+ setCustomClaims(claims: {
483
+ [claim: string]: Json;
484
+ } | null): Promise<void>;
485
+ isEqual(other: unknown): boolean;
486
+ }
487
+ export declare class UserSnapshot {
488
+ readonly reference: UserReference;
489
+ readonly data: UserData | null;
490
+ /** @internal */ constructor(reference: UserReference, data: UserData | null);
491
+ get uid(): string;
492
+ get exists(): boolean;
493
+ /** Their custom claims ({} when none, or no user). */
494
+ get customClaims(): {
495
+ [claim: string]: Json;
496
+ };
497
+ }
498
+ export declare class Auth {
499
+ private readonly call;
500
+ /** @internal */ constructor(call: Call);
501
+ user(uid: string): UserReference;
502
+ }
503
+ /** A file of a release: its path, its content's SHA-256, size and type. */
504
+ export interface AssetEntry {
505
+ path: string;
506
+ hash: string;
507
+ size: number;
508
+ mimeType: string;
509
+ }
510
+ /** A file of a release, to read. */
511
+ export declare class AssetFileReference {
512
+ private readonly call;
513
+ readonly release: number;
514
+ readonly path: string;
515
+ /** @internal */ constructor(call: Call, release: number, path: string);
516
+ /** Its bytes (up to 32 MB: larger ones through downloadUrl). */
517
+ bytes(): Promise<Uint8Array>;
518
+ /** Its contents as UTF-8 text. */
519
+ text(): Promise<string>;
520
+ /** Its contents decoded from JSON. */
521
+ json<T = Json>(): Promise<T>;
522
+ /** A short-lived link to its bytes (to hand to someone, or to fetch a large one). */
523
+ downloadUrl(): Promise<{
524
+ url: string;
525
+ expiresAt: Date;
526
+ }>;
527
+ }
528
+ /** A published release: numbered, never changed. */
529
+ export declare class AssetRelease {
530
+ private readonly call;
531
+ readonly number: number;
532
+ readonly note: string | null;
533
+ readonly by: string | null;
534
+ readonly at: Date;
535
+ readonly files: AssetEntry[];
536
+ /** @internal */ constructor(call: Call, number: number, note: string | null, by: string | null, at: Date, files: AssetEntry[]);
537
+ /** @internal */ static of(call: Call, r: any): AssetRelease;
538
+ /** Whether it has a file at path. */
539
+ has(path: string): boolean;
540
+ /** The paths under a folder ("translations"), or all of them. */
541
+ paths(folder?: string): string[];
542
+ /** A file of this release (reading one it hasn't throws not-found). */
543
+ file(path: string): AssetFileReference;
544
+ }
545
+ /** A channel: a name pointing at a release. */
546
+ export declare class AssetChannelReference {
547
+ private readonly call;
548
+ readonly name: string;
549
+ /** @internal */ constructor(call: Call, name: string);
550
+ /** The release it points at now, or null when there's no such channel. */
551
+ get(): Promise<AssetRelease | null>;
552
+ }
553
+ export declare class Assets {
554
+ private readonly call;
555
+ /** @internal */ constructor(call: Call);
556
+ /** A channel by name ("production"). */
557
+ channel(name: string): AssetChannelReference;
558
+ /** A release by number, or null. */
559
+ release(number: number): Promise<AssetRelease | null>;
560
+ /** The channels and the release each points at. */
561
+ channels(): Promise<{
562
+ name: string;
563
+ release: number;
564
+ updatedAt: Date;
565
+ by: string | null;
566
+ }[]>;
567
+ /** The releases, newest first, without their files. */
568
+ releases(limit?: number): Promise<{
569
+ number: number;
570
+ note: string | null;
571
+ by: string | null;
572
+ at: Date;
573
+ files: number;
574
+ size: number;
575
+ }[]>;
576
+ }
577
+ export declare class Functions {
578
+ private readonly send;
579
+ /** @internal */ constructor(send: Call);
580
+ /** Runs the callable `name` with `data` and returns what it returns (its HttpsError as a WincheError with its code). */
581
+ call<R = Json>(name: string, data?: Json): Promise<R>;
582
+ }
583
+ /** One of the app's users, to act as with `as(user)`: their uid and token claims (custom claims among them). */
584
+ export interface AppUser {
585
+ uid: string;
586
+ token?: {
587
+ [claim: string]: Json;
588
+ };
589
+ }
590
+ /** A project's data, acting as someone: `documents`, `files`, `auth`, `assets`, `functions`. */
591
+ export declare class Admin {
592
+ private readonly transport;
593
+ readonly documents: Documents;
594
+ readonly files: Files;
595
+ readonly auth: Auth;
596
+ readonly assets: Assets;
597
+ readonly functions: Functions;
598
+ /** @internal */ constructor(transport: Call);
599
+ /**
600
+ * The same API acting as one of the app's users (`ctx.caller` in a callable): every documents and files call is
601
+ * checked against the project's access rules for them, and refused with permission-denied as an app would be.
602
+ * Auth, assets and functions calls are refused (rules don't cover them).
603
+ */
604
+ as(user: AppUser): Admin;
605
+ }
606
+ /** How `initializeAdmin` reaches a Winche server. */
607
+ export interface AdminOptions {
608
+ /** The server's address, e.g. "https://winche.example.com". */
609
+ server: string;
610
+ /** The project's id. */
611
+ project: string;
612
+ /** A token for the project (or a function that returns the current one): its role limits what the SDK may do. */
613
+ token: string | (() => string | Promise<string>);
614
+ /** The fetch to use (default: the global one). */
615
+ fetch?: typeof fetch;
616
+ }
617
+ /** The SDK for a project on a server, from anywhere (another server, a script): calls go over HTTPS with the token. */
618
+ export declare function initializeAdmin(options: AdminOptions): Admin;
619
+ /** Documents (in functions: with the server's rights; in a page: the person's role). */
620
+ export declare const documents: Documents;
621
+ /** Files. */
622
+ export declare const files: Files;
623
+ /** The app's users. */
624
+ export declare const auth: Auth;
625
+ /** The app's assets (releases and channels). */
626
+ export declare const assets: Assets;
627
+ /** Calling callables. */
628
+ export declare const functions: Functions;
629
+ /** The same API acting as one of the app's users: their access rules apply. */
630
+ export declare const as: (user: AppUser) => Admin;
631
+ export {};