@dereekb/firebase 13.32.0 → 13.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/eslint/package.json +3 -3
- package/index.cjs.js +1077 -551
- package/index.esm.js +1048 -552
- package/package.json +5 -5
- package/src/lib/common/firestore/snapshot/snapshot.field.d.ts +59 -4
- package/src/lib/model/index.d.ts +1 -0
- package/src/lib/model/system/system.d.ts +61 -3
- package/src/lib/model/userexternalconnection/index.d.ts +6 -0
- package/src/lib/model/userexternalconnection/userexternalconnection.action.d.ts +21 -0
- package/src/lib/model/userexternalconnection/userexternalconnection.api.d.ts +120 -0
- package/src/lib/model/userexternalconnection/userexternalconnection.d.ts +191 -0
- package/src/lib/model/userexternalconnection/userexternalconnection.id.d.ts +51 -0
- package/src/lib/model/userexternalconnection/userexternalconnection.query.d.ts +19 -0
- package/src/lib/model/userexternalconnection/userexternalconnection.util.d.ts +149 -0
- package/test/index.cjs.js +371 -50
- package/test/index.esm.js +362 -51
- package/test/package.json +6 -6
- package/test/src/lib/client/firebase.rules.d.ts +114 -0
- package/test/src/lib/client/index.d.ts +1 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { type Maybe } from '@dereekb/util';
|
|
2
|
+
import { type FirebaseAuthUserId } from '../../common';
|
|
3
|
+
import { type UserExternalConnection, type UserExternalConnectionEntry, type UserExternalConnectionEntryMap, type UserExternalConnectionEntryStatus, type UserExternalConnectionErrorCode } from './userexternalconnection';
|
|
4
|
+
import { type UserExternalConnectionCapability, type UserExternalConnectionExternalAccountId, type UserExternalConnectionProviderType } from './userexternalconnection.id';
|
|
5
|
+
/**
|
|
6
|
+
* The facts about a granted third-party authorization that a {@link UserExternalConnectionEntry} is
|
|
7
|
+
* allowed to summarize.
|
|
8
|
+
*
|
|
9
|
+
* This is projected from the stored credentials by the server (see
|
|
10
|
+
* `userExternalConnectionGrantSummaryFromCredentials` in `@dereekb/firebase-server/model`), never
|
|
11
|
+
* assembled by a caller. That is what makes it impossible for the client-readable summary to claim
|
|
12
|
+
* scopes, an account, or an expiration the credentials do not actually have.
|
|
13
|
+
*/
|
|
14
|
+
export interface UserExternalConnectionGrantSummary {
|
|
15
|
+
readonly scopes?: Maybe<UserExternalConnectionCapability[]>;
|
|
16
|
+
readonly externalAccountId?: Maybe<UserExternalConnectionExternalAccountId>;
|
|
17
|
+
readonly label?: Maybe<string>;
|
|
18
|
+
readonly connectedAt?: Maybe<Date>;
|
|
19
|
+
readonly expiresAt?: Maybe<Date>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The SOLE producer of a {@link UserExternalConnection}'s `c` array.
|
|
23
|
+
*
|
|
24
|
+
* Membership is exactly the provider types whose entry status is `connected`. `disconnected` and
|
|
25
|
+
* `error` entries are excluded — the array backs a "which users can I actually call X for?" query,
|
|
26
|
+
* and `array-contains` has no way to filter by status afterwards.
|
|
27
|
+
*
|
|
28
|
+
* @param entries - The per-provider entry map to derive from.
|
|
29
|
+
* @returns The connected provider types, sorted for a stable stored value.
|
|
30
|
+
*/
|
|
31
|
+
export declare function userExternalConnectionConnectedProviderTypes(entries: Maybe<UserExternalConnectionEntryMap>): UserExternalConnectionProviderType[];
|
|
32
|
+
/**
|
|
33
|
+
* Input for {@link userExternalConnectionEntryForOutcome}.
|
|
34
|
+
*
|
|
35
|
+
* NOTE the shape: there is no parameter for any entry field. `ca`/`ea`/`l`/`exa` are copied off the
|
|
36
|
+
* `grant` (which is itself projected from the credentials), and `st`/`coa`/`uat` are computed. A
|
|
37
|
+
* caller has no way to describe a connection the credentials do not support.
|
|
38
|
+
*/
|
|
39
|
+
export interface UserExternalConnectionEntryForOutcomeInput {
|
|
40
|
+
/**
|
|
41
|
+
* The outcome of the operation that produced (or removed) the credentials.
|
|
42
|
+
*/
|
|
43
|
+
readonly outcome: UserExternalConnectionEntryStatus;
|
|
44
|
+
/**
|
|
45
|
+
* Summary of the grant the credentials carry. Required in practice for a `connected` outcome.
|
|
46
|
+
*/
|
|
47
|
+
readonly grant?: Maybe<UserExternalConnectionGrantSummary>;
|
|
48
|
+
/**
|
|
49
|
+
* Reason for an `error` outcome. Defaults to `unknown`.
|
|
50
|
+
*/
|
|
51
|
+
readonly error?: Maybe<UserExternalConnectionErrorCode>;
|
|
52
|
+
/**
|
|
53
|
+
* The entry currently stored for this provider, when there is one.
|
|
54
|
+
*/
|
|
55
|
+
readonly previous?: Maybe<UserExternalConnectionEntry>;
|
|
56
|
+
/**
|
|
57
|
+
* Whether a `disconnected` outcome should retain a history entry rather than removing the key.
|
|
58
|
+
*
|
|
59
|
+
* Defaults to false.
|
|
60
|
+
*/
|
|
61
|
+
readonly retainEntry?: Maybe<boolean>;
|
|
62
|
+
/**
|
|
63
|
+
* The instant the operation is being applied at.
|
|
64
|
+
*/
|
|
65
|
+
readonly now: Date;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Derives the {@link UserExternalConnectionEntry} for an operation's outcome.
|
|
69
|
+
*
|
|
70
|
+
* @param input - The outcome plus the grant it derives from.
|
|
71
|
+
* @returns The next entry, or null when the provider's entry should be REMOVED from the map.
|
|
72
|
+
*/
|
|
73
|
+
export declare function userExternalConnectionEntryForOutcome(input: UserExternalConnectionEntryForOutcomeInput): Maybe<UserExternalConnectionEntry>;
|
|
74
|
+
/**
|
|
75
|
+
* Input for {@link applyUserExternalConnectionEntry}.
|
|
76
|
+
*/
|
|
77
|
+
export interface ApplyUserExternalConnectionEntryInput {
|
|
78
|
+
/**
|
|
79
|
+
* The currently stored document, when one exists.
|
|
80
|
+
*/
|
|
81
|
+
readonly current?: Maybe<UserExternalConnection>;
|
|
82
|
+
readonly uid: FirebaseAuthUserId;
|
|
83
|
+
readonly providerType: UserExternalConnectionProviderType;
|
|
84
|
+
/**
|
|
85
|
+
* The next entry for this provider, or null to remove the provider's key entirely.
|
|
86
|
+
*/
|
|
87
|
+
readonly entry: Maybe<UserExternalConnectionEntry>;
|
|
88
|
+
readonly now: Date;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Applies a single provider's entry and returns the COMPLETE next document.
|
|
92
|
+
*
|
|
93
|
+
* Returning the whole value (rather than a patch) is what keeps `c` honest: this is the only
|
|
94
|
+
* exported way to change `e`, and it always recomputes `c` from the resulting map. There is no
|
|
95
|
+
* exported path that touches one without the other.
|
|
96
|
+
*
|
|
97
|
+
* @param input - The current document plus the provider entry to apply.
|
|
98
|
+
* @returns The next UserExternalConnection value to write.
|
|
99
|
+
*/
|
|
100
|
+
export declare function applyUserExternalConnectionEntry(input: ApplyUserExternalConnectionEntryInput): UserExternalConnection;
|
|
101
|
+
/**
|
|
102
|
+
* Input for {@link emptyUserExternalConnection}.
|
|
103
|
+
*/
|
|
104
|
+
export interface EmptyUserExternalConnectionInput {
|
|
105
|
+
readonly uid: FirebaseAuthUserId;
|
|
106
|
+
readonly now: Date;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Returns the value of a connection document that has no providers on it yet.
|
|
110
|
+
*
|
|
111
|
+
* Creating the document is its own operation, so the "no connections" value lives here beside
|
|
112
|
+
* {@link applyUserExternalConnectionEntry} rather than as a literal at the call site — both write
|
|
113
|
+
* the complete document, and `c` is empty here for the same reason it is derived there.
|
|
114
|
+
*
|
|
115
|
+
* @param input - The user the document belongs to and the instant to stamp it with.
|
|
116
|
+
* @returns The UserExternalConnection value for a user with no provider entries.
|
|
117
|
+
*/
|
|
118
|
+
export declare function emptyUserExternalConnection(input: EmptyUserExternalConnectionInput): UserExternalConnection;
|
|
119
|
+
/**
|
|
120
|
+
* Returns the entry for the given provider, if any.
|
|
121
|
+
*
|
|
122
|
+
* @param connection - The loaded connection document.
|
|
123
|
+
* @param providerType - The provider to read.
|
|
124
|
+
* @returns The provider's entry, or null when the user has no entry for it.
|
|
125
|
+
*/
|
|
126
|
+
export declare function userExternalConnectionEntryForProvider(connection: Maybe<UserExternalConnection>, providerType: UserExternalConnectionProviderType): Maybe<UserExternalConnectionEntry>;
|
|
127
|
+
/**
|
|
128
|
+
* Returns true if the entry is in the `connected` status.
|
|
129
|
+
*
|
|
130
|
+
* @param entry - The entry to check.
|
|
131
|
+
* @returns True when the entry is connected.
|
|
132
|
+
*/
|
|
133
|
+
export declare function userExternalConnectionEntryIsConnected(entry: Maybe<UserExternalConnectionEntry>): boolean;
|
|
134
|
+
/**
|
|
135
|
+
* Returns true if the entry declares an expiration that has already passed.
|
|
136
|
+
*
|
|
137
|
+
* @param entry - The entry to check.
|
|
138
|
+
* @param now - The instant to compare against. Defaults to the current time.
|
|
139
|
+
* @returns True when the entry's credentials are known to have expired.
|
|
140
|
+
*/
|
|
141
|
+
export declare function userExternalConnectionEntryIsExpired(entry: Maybe<UserExternalConnectionEntry>, now?: Date): boolean;
|
|
142
|
+
/**
|
|
143
|
+
* Returns true if the user is currently connected to the given provider.
|
|
144
|
+
*
|
|
145
|
+
* @param connection - The loaded connection document.
|
|
146
|
+
* @param providerType - The provider to check.
|
|
147
|
+
* @returns True when the provider's entry is connected.
|
|
148
|
+
*/
|
|
149
|
+
export declare function userExternalConnectionIsConnectedToProvider(connection: Maybe<UserExternalConnection>, providerType: UserExternalConnectionProviderType): boolean;
|