@iglo.tech/iglo.base 0.0.0-stage → 1.0.1-rc.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/CHANGELOG.md +22 -0
- package/LICENSE +18 -0
- package/README.md +778 -2
- package/dist/iglo-base.es.mjs +4 -0
- package/dist/iglo-base.es.mjs.map +34 -0
- package/dist/ssr-astro.es.mjs +4 -0
- package/dist/ssr-astro.es.mjs.map +12 -0
- package/dist/ssr-browser-client.es.mjs +4 -0
- package/dist/ssr-browser-client.es.mjs.map +13 -0
- package/dist/ssr-browser.es.mjs +4 -0
- package/dist/ssr-browser.es.mjs.map +10 -0
- package/dist/ssr-next.es.mjs +4 -0
- package/dist/ssr-next.es.mjs.map +12 -0
- package/dist/ssr-nuxt.es.mjs +4 -0
- package/dist/ssr-nuxt.es.mjs.map +12 -0
- package/dist/ssr-react-router.es.mjs +4 -0
- package/dist/ssr-react-router.es.mjs.map +12 -0
- package/dist/ssr-sveltekit.es.mjs +4 -0
- package/dist/ssr-sveltekit.es.mjs.map +12 -0
- package/dist/ssr.es.mjs +4 -0
- package/dist/ssr.es.mjs.map +22 -0
- package/dist/types/src/Client.d.ts +233 -0
- package/dist/types/src/ClientResponseError.d.ts +22 -0
- package/dist/types/src/index.d.ts +18 -0
- package/dist/types/src/services/BackupService.d.ts +59 -0
- package/dist/types/src/services/BaseService.d.ts +8 -0
- package/dist/types/src/services/BatchService.d.ts +56 -0
- package/dist/types/src/services/CollectionService.d.ts +47 -0
- package/dist/types/src/services/CronService.d.ts +20 -0
- package/dist/types/src/services/CrudService.d.ts +85 -0
- package/dist/types/src/services/FileService.d.ts +19 -0
- package/dist/types/src/services/HealthService.d.ts +16 -0
- package/dist/types/src/services/LogService.d.ts +35 -0
- package/dist/types/src/services/RealtimeService.d.ts +124 -0
- package/dist/types/src/services/RecordService.d.ts +374 -0
- package/dist/types/src/services/SQLService.d.ts +21 -0
- package/dist/types/src/services/SettingsService.d.ts +46 -0
- package/dist/types/src/ssr/adapter.d.ts +133 -0
- package/dist/types/src/ssr/astro.d.ts +27 -0
- package/dist/types/src/ssr/browser-client.d.ts +100 -0
- package/dist/types/src/ssr/browser-token.d.ts +29 -0
- package/dist/types/src/ssr/browser.d.ts +1 -0
- package/dist/types/src/ssr/cache.d.ts +9 -0
- package/dist/types/src/ssr/cookies.d.ts +68 -0
- package/dist/types/src/ssr/csrf.d.ts +38 -0
- package/dist/types/src/ssr/index.d.ts +12 -0
- package/dist/types/src/ssr/next.d.ts +53 -0
- package/dist/types/src/ssr/no-store-fetch.d.ts +7 -0
- package/dist/types/src/ssr/nuxt.d.ts +41 -0
- package/dist/types/src/ssr/oauth2.d.ts +56 -0
- package/dist/types/src/ssr/popup.d.ts +14 -0
- package/dist/types/src/ssr/react-router.d.ts +53 -0
- package/dist/types/src/ssr/renew.d.ts +25 -0
- package/dist/types/src/ssr/server-client.d.ts +83 -0
- package/dist/types/src/ssr/superuser-client.d.ts +24 -0
- package/dist/types/src/ssr/sveltekit.d.ts +44 -0
- package/dist/types/src/ssr/types.d.ts +118 -0
- package/dist/types/src/stores/AsyncAuthStore.d.ts +52 -0
- package/dist/types/src/stores/BaseAuthStore.d.ts +104 -0
- package/dist/types/src/stores/LocalAuthStore.d.ts +48 -0
- package/dist/types/src/tools/cookie.d.ts +31 -0
- package/dist/types/src/tools/dtos.d.ts +122 -0
- package/dist/types/src/tools/formdata.d.ts +30 -0
- package/dist/types/src/tools/jwt.d.ts +14 -0
- package/dist/types/src/tools/legacy.d.ts +2 -0
- package/dist/types/src/tools/loose.d.ts +5 -0
- package/dist/types/src/tools/options.d.ts +91 -0
- package/dist/types/src/tools/refresh.d.ts +3 -0
- package/package.json +73 -4
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import type { Loose } from "../tools/loose.js";
|
|
2
|
+
import { BaseService } from "./BaseService.js";
|
|
3
|
+
import { type SendOptions } from "../tools/options.js";
|
|
4
|
+
export type UnsubscribeFunc = () => Promise<void>;
|
|
5
|
+
export declare class RealtimeService extends BaseService {
|
|
6
|
+
clientId: string;
|
|
7
|
+
private eventSource;
|
|
8
|
+
private subscriptions;
|
|
9
|
+
private lastSentSubscriptions;
|
|
10
|
+
private connectTimeoutId?;
|
|
11
|
+
private maxConnectTimeout;
|
|
12
|
+
private reconnectTimeoutId?;
|
|
13
|
+
private reconnectAttempts;
|
|
14
|
+
private maxReconnectAttempts;
|
|
15
|
+
private predefinedReconnectIntervals;
|
|
16
|
+
private pendingConnects;
|
|
17
|
+
private pendingSubmits;
|
|
18
|
+
private isProcessingPendingSubmits;
|
|
19
|
+
private connectionGeneration;
|
|
20
|
+
/**
|
|
21
|
+
* Returns whether the realtime connection has been established.
|
|
22
|
+
*/
|
|
23
|
+
get isConnected(): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* An optional hook that is invoked when the realtime client disconnects
|
|
26
|
+
* either when unsubscribing from all subscriptions or when the
|
|
27
|
+
* connection was interrupted or closed by the server.
|
|
28
|
+
*
|
|
29
|
+
* The received argument could be used to determine whether the disconnect
|
|
30
|
+
* is a result from unsubscribing (`activeSubscriptions.length == 0`)
|
|
31
|
+
* or because of network/server error (`activeSubscriptions.length > 0`).
|
|
32
|
+
*
|
|
33
|
+
* If you want to listen for the opposite, aka. when the client connection is established,
|
|
34
|
+
* subscribe to the `PB_CONNECT` event.
|
|
35
|
+
*/
|
|
36
|
+
onDisconnect?: (activeSubscriptions: Array<string>) => void;
|
|
37
|
+
/**
|
|
38
|
+
* Register the subscription listener.
|
|
39
|
+
*
|
|
40
|
+
* You can subscribe multiple times to the same topic.
|
|
41
|
+
*
|
|
42
|
+
* If the SSE connection is not started yet,
|
|
43
|
+
* this method will also initialize it.
|
|
44
|
+
*/
|
|
45
|
+
subscribe(topic: string, callback: (data: Loose) => void, options?: SendOptions): Promise<UnsubscribeFunc>;
|
|
46
|
+
/**
|
|
47
|
+
* Sends the current subscriptions again, with the client's current authorization. Upstream
|
|
48
|
+
* keeps a subscription's auth state on the server, so a new token for the same record is
|
|
49
|
+
* accepted and replaces it (docs/design/13-ssr.md, "Browser client and realtime"). A no-op
|
|
50
|
+
* when the connection is not established or there are no subscriptions.
|
|
51
|
+
*/
|
|
52
|
+
resubmit(): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Closes the SSE connection and opens a new one with the same subscriptions, after an intended
|
|
55
|
+
* change of authorization. The new connection gets its own client ID, and the subscriptions are
|
|
56
|
+
* sent on it with the client's current authorization. Upstream keeps a connection's
|
|
57
|
+
* authorization on the server and only accepts a change to the same record (a guest may then
|
|
58
|
+
* sign in), so a different user or a sign-out needs a new connection
|
|
59
|
+
* (docs/design/13-ssr.md, "Browser client and realtime").
|
|
60
|
+
*
|
|
61
|
+
* The new connection is opened the way a dropped one is reopened: its first attempt waits the
|
|
62
|
+
* first backoff step, and a failed attempt retries in the background with the usual backoff
|
|
63
|
+
* (`connectErrorHandler`). Unlike a dropped connection, it does not call `onDisconnect`, since
|
|
64
|
+
* nothing went wrong on the network or the server. The returned promise resolves when the
|
|
65
|
+
* reconnect is scheduled, not when the new connection is up. A no-op without subscriptions.
|
|
66
|
+
*/
|
|
67
|
+
reconnect(): Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* Unsubscribe from all subscription listeners with the specified topic.
|
|
70
|
+
*
|
|
71
|
+
* If `topic` is not provided, then this method will unsubscribe
|
|
72
|
+
* from all active subscriptions.
|
|
73
|
+
*
|
|
74
|
+
* This method is no-op if there are no active subscriptions.
|
|
75
|
+
*
|
|
76
|
+
* The related sse connection will be autoclosed if after the
|
|
77
|
+
* unsubscribe operation there are no active subscriptions left.
|
|
78
|
+
*/
|
|
79
|
+
unsubscribe(topic?: string): Promise<void>;
|
|
80
|
+
/**
|
|
81
|
+
* Unsubscribe from all subscription listeners starting with the specified topic prefix.
|
|
82
|
+
*
|
|
83
|
+
* This method is no-op if there are no active subscriptions with the specified topic prefix.
|
|
84
|
+
*
|
|
85
|
+
* The related sse connection will be autoclosed if after the
|
|
86
|
+
* unsubscribe operation there are no active subscriptions left.
|
|
87
|
+
*/
|
|
88
|
+
unsubscribeByPrefix(keyPrefix: string): Promise<void>;
|
|
89
|
+
/**
|
|
90
|
+
* Unsubscribe from all subscriptions matching the specified topic and listener function.
|
|
91
|
+
*
|
|
92
|
+
* This method is no-op if there are no active subscription with
|
|
93
|
+
* the specified topic and listener.
|
|
94
|
+
*
|
|
95
|
+
* The related sse connection will be autoclosed if after the
|
|
96
|
+
* unsubscribe operation there are no active subscriptions left.
|
|
97
|
+
*/
|
|
98
|
+
unsubscribeByTopicAndListener(topic: string, listener: EventListener): Promise<void>;
|
|
99
|
+
private hasSubscriptionListeners;
|
|
100
|
+
private submitSubscriptions;
|
|
101
|
+
private finalizePendingSubscriptions;
|
|
102
|
+
private getSubscriptionsCancelKey;
|
|
103
|
+
private getSubscriptionsByTopic;
|
|
104
|
+
private getNonEmptySubscriptionKeys;
|
|
105
|
+
private hasUnsentSubscriptions;
|
|
106
|
+
private sendSubscriptions;
|
|
107
|
+
private addAllSubscriptionListeners;
|
|
108
|
+
private removeAllSubscriptionListeners;
|
|
109
|
+
private connect;
|
|
110
|
+
private initConnect;
|
|
111
|
+
private connectErrorHandler;
|
|
112
|
+
/**
|
|
113
|
+
* Schedules the next connection attempt after the backoff step for the current attempt count,
|
|
114
|
+
* and counts the attempt. Shared by a dropped connection and by `reconnect()`, so both retry
|
|
115
|
+
* the same way.
|
|
116
|
+
*/
|
|
117
|
+
private scheduleReconnect;
|
|
118
|
+
/**
|
|
119
|
+
* Closes the connection. `fromReconnect` keeps the reconnect attempts and the pending connects,
|
|
120
|
+
* for a retry. `notify` is false when the close is intended (a `reconnect()`), so the
|
|
121
|
+
* `onDisconnect` hook, which means a network or server error, is not called.
|
|
122
|
+
*/
|
|
123
|
+
private disconnect;
|
|
124
|
+
}
|
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
import type { Loose, LooseObject } from "../tools/loose.js";
|
|
2
|
+
import Client from "../Client.js";
|
|
3
|
+
import { type UnsubscribeFunc } from "./RealtimeService.js";
|
|
4
|
+
import { CrudService } from "./CrudService.js";
|
|
5
|
+
import { type ListResult, type RecordModel } from "../tools/dtos.js";
|
|
6
|
+
import { type CommonOptions, type RecordFullListOptions, type RecordListOptions, type RecordOptions, type SendOptions, type RecordSubscribeOptions } from "../tools/options.js";
|
|
7
|
+
export interface RecordAuthResponse<T = RecordModel> {
|
|
8
|
+
/**
|
|
9
|
+
* The signed PocketBase auth record.
|
|
10
|
+
*/
|
|
11
|
+
record: T;
|
|
12
|
+
/**
|
|
13
|
+
* The PocketBase record auth token.
|
|
14
|
+
*
|
|
15
|
+
* If you are looking for the OAuth2 access and refresh tokens
|
|
16
|
+
* they are available under the `meta.accessToken` and `meta.refreshToken` props.
|
|
17
|
+
*/
|
|
18
|
+
token: string;
|
|
19
|
+
/**
|
|
20
|
+
* Auth meta data usually filled when OAuth2 is used.
|
|
21
|
+
*/
|
|
22
|
+
meta?: LooseObject;
|
|
23
|
+
}
|
|
24
|
+
export interface AuthProviderInfo {
|
|
25
|
+
name: string;
|
|
26
|
+
displayName: string;
|
|
27
|
+
state: string;
|
|
28
|
+
authURL: string;
|
|
29
|
+
codeVerifier: string;
|
|
30
|
+
codeChallenge: string;
|
|
31
|
+
codeChallengeMethod: string;
|
|
32
|
+
}
|
|
33
|
+
export interface AuthMethodsList {
|
|
34
|
+
mfa: {
|
|
35
|
+
enabled: boolean;
|
|
36
|
+
duration: number;
|
|
37
|
+
};
|
|
38
|
+
otp: {
|
|
39
|
+
enabled: boolean;
|
|
40
|
+
duration: number;
|
|
41
|
+
};
|
|
42
|
+
password: {
|
|
43
|
+
enabled: boolean;
|
|
44
|
+
identityFields: Array<string>;
|
|
45
|
+
};
|
|
46
|
+
oauth2: {
|
|
47
|
+
enabled: boolean;
|
|
48
|
+
providers: Array<AuthProviderInfo>;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export interface RecordSubscription<T = RecordModel> {
|
|
52
|
+
action: string;
|
|
53
|
+
record: T;
|
|
54
|
+
}
|
|
55
|
+
export type OAuth2UrlCallback = (url: string) => void | Promise<void>;
|
|
56
|
+
export interface OAuth2AuthConfig extends SendOptions {
|
|
57
|
+
provider: string;
|
|
58
|
+
scopes?: Array<string>;
|
|
59
|
+
createData?: LooseObject;
|
|
60
|
+
urlCallback?: OAuth2UrlCallback;
|
|
61
|
+
query?: RecordOptions;
|
|
62
|
+
}
|
|
63
|
+
export interface OTPResponse {
|
|
64
|
+
otpId: string;
|
|
65
|
+
}
|
|
66
|
+
export declare class RecordService<M = RecordModel> extends CrudService<M> {
|
|
67
|
+
readonly collectionIdOrName: string;
|
|
68
|
+
constructor(client: Client, collectionIdOrName: string);
|
|
69
|
+
/**
|
|
70
|
+
* @inheritdoc
|
|
71
|
+
*/
|
|
72
|
+
get baseCrudPath(): string;
|
|
73
|
+
/**
|
|
74
|
+
* Returns the current collection service base path.
|
|
75
|
+
*/
|
|
76
|
+
get baseCollectionPath(): string;
|
|
77
|
+
/**
|
|
78
|
+
* Returns whether the current service collection is superusers.
|
|
79
|
+
*/
|
|
80
|
+
get isSuperusers(): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Subscribe to realtime changes to the specified topic ("*" or record id).
|
|
83
|
+
*
|
|
84
|
+
* If `topic` is the wildcard "*", then this method will subscribe to
|
|
85
|
+
* any record changes in the collection.
|
|
86
|
+
*
|
|
87
|
+
* If `topic` is a record id, then this method will subscribe only
|
|
88
|
+
* to changes of the specified record id.
|
|
89
|
+
*
|
|
90
|
+
* It's OK to subscribe multiple times to the same topic.
|
|
91
|
+
* You can use the returned `UnsubscribeFunc` to remove only a single subscription.
|
|
92
|
+
* Or use `unsubscribe(topic)` if you want to remove all subscriptions attached to the topic.
|
|
93
|
+
*/
|
|
94
|
+
subscribe<T = M>(topic: string, callback: (data: RecordSubscription<T>) => void, options?: RecordSubscribeOptions): Promise<UnsubscribeFunc>;
|
|
95
|
+
/**
|
|
96
|
+
* Unsubscribe from all subscriptions of the specified topic
|
|
97
|
+
* ("*" or record id).
|
|
98
|
+
*
|
|
99
|
+
* If `topic` is not set, then this method will unsubscribe from
|
|
100
|
+
* all subscriptions associated to the current collection.
|
|
101
|
+
*/
|
|
102
|
+
unsubscribe(topic?: string): Promise<void>;
|
|
103
|
+
/**
|
|
104
|
+
* @inheritdoc
|
|
105
|
+
*/
|
|
106
|
+
getFullList<T = M>(options?: RecordFullListOptions): Promise<Array<T>>;
|
|
107
|
+
/**
|
|
108
|
+
* @inheritdoc
|
|
109
|
+
*/
|
|
110
|
+
getFullList<T = M>(batch?: number, options?: RecordListOptions): Promise<Array<T>>;
|
|
111
|
+
/**
|
|
112
|
+
* @inheritdoc
|
|
113
|
+
*/
|
|
114
|
+
getList<T = M>(page?: number, perPage?: number, options?: RecordListOptions): Promise<ListResult<T>>;
|
|
115
|
+
/**
|
|
116
|
+
* @inheritdoc
|
|
117
|
+
*/
|
|
118
|
+
getFirstListItem<T = M>(filter: string, options?: RecordListOptions): Promise<T>;
|
|
119
|
+
/**
|
|
120
|
+
* @inheritdoc
|
|
121
|
+
*/
|
|
122
|
+
getOne<T = M>(id: string, options?: RecordOptions): Promise<T>;
|
|
123
|
+
/**
|
|
124
|
+
* @inheritdoc
|
|
125
|
+
*/
|
|
126
|
+
create<T = M>(bodyParams?: LooseObject | FormData, options?: RecordOptions): Promise<T>;
|
|
127
|
+
/**
|
|
128
|
+
* @inheritdoc
|
|
129
|
+
*
|
|
130
|
+
* If the current `client.authStore.record` matches with the updated id, then
|
|
131
|
+
* on success the `client.authStore.record` will be updated with the new response record fields.
|
|
132
|
+
*/
|
|
133
|
+
update<T = M>(id: string, bodyParams?: LooseObject | FormData, options?: RecordOptions): Promise<T>;
|
|
134
|
+
/**
|
|
135
|
+
* @inheritdoc
|
|
136
|
+
*
|
|
137
|
+
* If the current `client.authStore.record` matches with the deleted id,
|
|
138
|
+
* then on success the `client.authStore` will be cleared.
|
|
139
|
+
*/
|
|
140
|
+
delete(id: string, options?: CommonOptions): Promise<boolean>;
|
|
141
|
+
/**
|
|
142
|
+
* Prepare successful collection authorization response.
|
|
143
|
+
*/
|
|
144
|
+
protected authResponse<T = M>(responseData: LooseObject): RecordAuthResponse<T>;
|
|
145
|
+
/**
|
|
146
|
+
* Returns all available collection auth methods.
|
|
147
|
+
*
|
|
148
|
+
* @throws {ClientResponseError}
|
|
149
|
+
*/
|
|
150
|
+
listAuthMethods(options?: CommonOptions): Promise<AuthMethodsList>;
|
|
151
|
+
/**
|
|
152
|
+
* Authenticate a single auth collection record via its username/email and password.
|
|
153
|
+
*
|
|
154
|
+
* On success, this method also automatically updates
|
|
155
|
+
* the client's AuthStore data and returns:
|
|
156
|
+
* - the authentication token
|
|
157
|
+
* - the authenticated record model
|
|
158
|
+
*
|
|
159
|
+
* @throws {ClientResponseError}
|
|
160
|
+
*/
|
|
161
|
+
authWithPassword<T = M>(usernameOrEmail: string, password: string, options?: RecordOptions): Promise<RecordAuthResponse<T>>;
|
|
162
|
+
/**
|
|
163
|
+
* Authenticate a single auth collection record with OAuth2 code.
|
|
164
|
+
*
|
|
165
|
+
* If you don't have an OAuth2 code you may also want to check `authWithOAuth2` method.
|
|
166
|
+
*
|
|
167
|
+
* On success, this method also automatically updates
|
|
168
|
+
* the client's AuthStore data and returns:
|
|
169
|
+
* - the authentication token
|
|
170
|
+
* - the authenticated record model
|
|
171
|
+
* - the OAuth2 account data (eg. name, email, avatar, etc.)
|
|
172
|
+
*
|
|
173
|
+
* @throws {ClientResponseError}
|
|
174
|
+
*/
|
|
175
|
+
authWithOAuth2Code<T = M>(provider: string, code: string, codeVerifier: string, redirectURL: string, createData?: LooseObject, options?: RecordOptions): Promise<RecordAuthResponse<T>>;
|
|
176
|
+
/**
|
|
177
|
+
* @deprecated
|
|
178
|
+
* Consider using authWithOAuth2Code(provider, code, codeVerifier, redirectURL, createdData, options?).
|
|
179
|
+
*/
|
|
180
|
+
authWithOAuth2Code<T = M>(provider: string, code: string, codeVerifier: string, redirectURL: string, createData?: LooseObject, body?: Loose, query?: Loose): Promise<RecordAuthResponse<T>>;
|
|
181
|
+
/**
|
|
182
|
+
* @deprecated This form of authWithOAuth2 is deprecated.
|
|
183
|
+
*
|
|
184
|
+
* Please use `authWithOAuth2Code()` OR its simplified realtime version
|
|
185
|
+
* as shown in https://pocketbase.io/docs/authentication/#oauth2-integration.
|
|
186
|
+
*/
|
|
187
|
+
authWithOAuth2<T = M>(provider: string, code: string, codeVerifier: string, redirectURL: string, createData?: LooseObject, bodyParams?: LooseObject, queryParams?: RecordOptions): Promise<RecordAuthResponse<T>>;
|
|
188
|
+
/**
|
|
189
|
+
* Authenticate a single auth collection record with OAuth2
|
|
190
|
+
* **without custom redirects, deeplinks or even page reload**.
|
|
191
|
+
*
|
|
192
|
+
* This method initializes a one-off realtime subscription and will
|
|
193
|
+
* open a popup window with the OAuth2 vendor page to authenticate.
|
|
194
|
+
* Once the external OAuth2 sign-in/sign-up flow is completed, the popup
|
|
195
|
+
* window will be automatically closed and the OAuth2 data sent back
|
|
196
|
+
* to the user through the previously established realtime connection.
|
|
197
|
+
*
|
|
198
|
+
* You can specify an optional `urlCallback` prop to customize
|
|
199
|
+
* the default url `window.open` behavior.
|
|
200
|
+
*
|
|
201
|
+
* On success, this method also automatically updates
|
|
202
|
+
* the client's AuthStore data and returns:
|
|
203
|
+
* - the authentication token
|
|
204
|
+
* - the authenticated record model
|
|
205
|
+
* - the OAuth2 account data (eg. name, email, avatar, etc.)
|
|
206
|
+
*
|
|
207
|
+
* Example:
|
|
208
|
+
*
|
|
209
|
+
* ```js
|
|
210
|
+
* const authData = await pb.collection("users").authWithOAuth2({
|
|
211
|
+
* provider: "google",
|
|
212
|
+
* })
|
|
213
|
+
* ```
|
|
214
|
+
*
|
|
215
|
+
* Note1: When creating the OAuth2 app in the provider dashboard
|
|
216
|
+
* you have to configure `https://yourdomain.com/api/oauth2-redirect`
|
|
217
|
+
* as redirect URL.
|
|
218
|
+
*
|
|
219
|
+
* Note2: Safari may block the default `urlCallback` popup because
|
|
220
|
+
* it doesn't allow `window.open` calls as part of an `async` click functions.
|
|
221
|
+
* To workaround this you can either change your click handler to not be marked as `async`
|
|
222
|
+
* OR manually call `window.open` before your `async` function and use the
|
|
223
|
+
* window reference in your own custom `urlCallback` (see https://github.com/pocketbase/pocketbase/discussions/2429#discussioncomment-5943061).
|
|
224
|
+
* For example:
|
|
225
|
+
* ```js
|
|
226
|
+
* <button id="btn">Login with Gitlab</button>
|
|
227
|
+
* ...
|
|
228
|
+
* document.getElementById("btn").addEventListener("click", () => {
|
|
229
|
+
* pb.collection("users").authWithOAuth2({
|
|
230
|
+
* provider: "gitlab",
|
|
231
|
+
* }).then((authData) => {
|
|
232
|
+
* console.log(authData)
|
|
233
|
+
* }).catch((err) => {
|
|
234
|
+
* console.log(err, err.originalError);
|
|
235
|
+
* });
|
|
236
|
+
* })
|
|
237
|
+
* ```
|
|
238
|
+
*
|
|
239
|
+
* @throws {ClientResponseError}
|
|
240
|
+
*/
|
|
241
|
+
authWithOAuth2<T = M>(options: OAuth2AuthConfig): Promise<RecordAuthResponse<T>>;
|
|
242
|
+
/**
|
|
243
|
+
* Refreshes the current authenticated record instance and
|
|
244
|
+
* returns a new token and record data.
|
|
245
|
+
*
|
|
246
|
+
* On success this method also automatically updates the client's AuthStore.
|
|
247
|
+
*
|
|
248
|
+
* @throws {ClientResponseError}
|
|
249
|
+
*/
|
|
250
|
+
authRefresh<T = M>(options?: RecordOptions): Promise<RecordAuthResponse<T>>;
|
|
251
|
+
/**
|
|
252
|
+
* @deprecated
|
|
253
|
+
* Consider using authRefresh(options?).
|
|
254
|
+
*/
|
|
255
|
+
authRefresh<T = M>(body?: Loose, query?: Loose): Promise<RecordAuthResponse<T>>;
|
|
256
|
+
/**
|
|
257
|
+
* Sends auth record password reset request.
|
|
258
|
+
*
|
|
259
|
+
* @throws {ClientResponseError}
|
|
260
|
+
*/
|
|
261
|
+
requestPasswordReset(email: string, options?: CommonOptions): Promise<boolean>;
|
|
262
|
+
/**
|
|
263
|
+
* @deprecated
|
|
264
|
+
* Consider using requestPasswordReset(email, options?).
|
|
265
|
+
*/
|
|
266
|
+
requestPasswordReset(email: string, body?: Loose, query?: Loose): Promise<boolean>;
|
|
267
|
+
/**
|
|
268
|
+
* Confirms auth record password reset request.
|
|
269
|
+
*
|
|
270
|
+
* @throws {ClientResponseError}
|
|
271
|
+
*/
|
|
272
|
+
confirmPasswordReset(passwordResetToken: string, password: string, passwordConfirm: string, options?: CommonOptions): Promise<boolean>;
|
|
273
|
+
/**
|
|
274
|
+
* @deprecated
|
|
275
|
+
* Consider using confirmPasswordReset(passwordResetToken, password, passwordConfirm, options?).
|
|
276
|
+
*/
|
|
277
|
+
confirmPasswordReset(passwordResetToken: string, password: string, passwordConfirm: string, body?: Loose, query?: Loose): Promise<boolean>;
|
|
278
|
+
/**
|
|
279
|
+
* Sends auth record verification email request.
|
|
280
|
+
*
|
|
281
|
+
* @throws {ClientResponseError}
|
|
282
|
+
*/
|
|
283
|
+
requestVerification(email: string, options?: CommonOptions): Promise<boolean>;
|
|
284
|
+
/**
|
|
285
|
+
* @deprecated
|
|
286
|
+
* Consider using requestVerification(email, options?).
|
|
287
|
+
*/
|
|
288
|
+
requestVerification(email: string, body?: Loose, query?: Loose): Promise<boolean>;
|
|
289
|
+
/**
|
|
290
|
+
* Confirms auth record email verification request.
|
|
291
|
+
*
|
|
292
|
+
* If the current `client.authStore.record` matches with the auth record from the token,
|
|
293
|
+
* then on success the `client.authStore.record.verified` will be updated to `true`.
|
|
294
|
+
*
|
|
295
|
+
* @throws {ClientResponseError}
|
|
296
|
+
*/
|
|
297
|
+
confirmVerification(verificationToken: string, options?: CommonOptions): Promise<boolean>;
|
|
298
|
+
/**
|
|
299
|
+
* @deprecated
|
|
300
|
+
* Consider using confirmVerification(verificationToken, options?).
|
|
301
|
+
*/
|
|
302
|
+
confirmVerification(verificationToken: string, body?: Loose, query?: Loose): Promise<boolean>;
|
|
303
|
+
/**
|
|
304
|
+
* Sends an email change request to the authenticated record model.
|
|
305
|
+
*
|
|
306
|
+
* @throws {ClientResponseError}
|
|
307
|
+
*/
|
|
308
|
+
requestEmailChange(newEmail: string, options?: CommonOptions): Promise<boolean>;
|
|
309
|
+
/**
|
|
310
|
+
* @deprecated
|
|
311
|
+
* Consider using requestEmailChange(newEmail, options?).
|
|
312
|
+
*/
|
|
313
|
+
requestEmailChange(newEmail: string, body?: Loose, query?: Loose): Promise<boolean>;
|
|
314
|
+
/**
|
|
315
|
+
* Confirms auth record's new email address.
|
|
316
|
+
*
|
|
317
|
+
* If the current `client.authStore.record` matches with the auth record from the token,
|
|
318
|
+
* then on success the `client.authStore` will be cleared.
|
|
319
|
+
*
|
|
320
|
+
* @throws {ClientResponseError}
|
|
321
|
+
*/
|
|
322
|
+
confirmEmailChange(emailChangeToken: string, password: string, options?: CommonOptions): Promise<boolean>;
|
|
323
|
+
/**
|
|
324
|
+
* @deprecated
|
|
325
|
+
* Consider using confirmEmailChange(emailChangeToken, password, options?).
|
|
326
|
+
*/
|
|
327
|
+
confirmEmailChange(emailChangeToken: string, password: string, body?: Loose, query?: Loose): Promise<boolean>;
|
|
328
|
+
/**
|
|
329
|
+
* @deprecated use collection("_externalAuths").*
|
|
330
|
+
*
|
|
331
|
+
* Lists all linked external auth providers for the specified auth record.
|
|
332
|
+
*
|
|
333
|
+
* @throws {ClientResponseError}
|
|
334
|
+
*/
|
|
335
|
+
listExternalAuths(recordId: string, options?: CommonOptions): Promise<Array<RecordModel>>;
|
|
336
|
+
/**
|
|
337
|
+
* @deprecated use collection("_externalAuths").*
|
|
338
|
+
*
|
|
339
|
+
* Unlink a single external auth provider from the specified auth record.
|
|
340
|
+
*
|
|
341
|
+
* @throws {ClientResponseError}
|
|
342
|
+
*/
|
|
343
|
+
unlinkExternalAuth(recordId: string, provider: string, options?: CommonOptions): Promise<boolean>;
|
|
344
|
+
/**
|
|
345
|
+
* Sends auth record OTP to the provided email.
|
|
346
|
+
*
|
|
347
|
+
* @throws {ClientResponseError}
|
|
348
|
+
*/
|
|
349
|
+
requestOTP(email: string, options?: CommonOptions): Promise<OTPResponse>;
|
|
350
|
+
/**
|
|
351
|
+
* Authenticate a single auth collection record via OTP.
|
|
352
|
+
*
|
|
353
|
+
* On success, this method also automatically updates
|
|
354
|
+
* the client's AuthStore data and returns:
|
|
355
|
+
* - the authentication token
|
|
356
|
+
* - the authenticated record model
|
|
357
|
+
*
|
|
358
|
+
* @throws {ClientResponseError}
|
|
359
|
+
*/
|
|
360
|
+
authWithOTP<T = M>(otpId: string, password: string, options?: CommonOptions): Promise<RecordAuthResponse<T>>;
|
|
361
|
+
/**
|
|
362
|
+
* Impersonate authenticates with the specified recordId and
|
|
363
|
+
* returns a new client with the received auth token in a memory store.
|
|
364
|
+
*
|
|
365
|
+
* If `duration` is 0 the generated auth token will fallback
|
|
366
|
+
* to the default collection auth token duration.
|
|
367
|
+
*
|
|
368
|
+
* This action currently requires superusers privileges.
|
|
369
|
+
*
|
|
370
|
+
* @throws {ClientResponseError}
|
|
371
|
+
*/
|
|
372
|
+
impersonate(recordId: string, duration: number, options?: CommonOptions): Promise<Client>;
|
|
373
|
+
private _replaceQueryParams;
|
|
374
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { BaseService } from "./BaseService.js";
|
|
2
|
+
import { type CommonOptions } from "../tools/options.js";
|
|
3
|
+
export interface SQLResult {
|
|
4
|
+
execTime: number;
|
|
5
|
+
affectedRows: number;
|
|
6
|
+
columns: Array<{
|
|
7
|
+
name: string;
|
|
8
|
+
type: string;
|
|
9
|
+
nullable: boolean;
|
|
10
|
+
}>;
|
|
11
|
+
rows: Array<Array<string | null>>;
|
|
12
|
+
}
|
|
13
|
+
export declare class SQLService extends BaseService {
|
|
14
|
+
/**
|
|
15
|
+
* Executes the specified raw SQL query.
|
|
16
|
+
* This operation is allowed only for superusers.
|
|
17
|
+
*
|
|
18
|
+
* @throws {ClientResponseError}
|
|
19
|
+
*/
|
|
20
|
+
run(query: string, options?: CommonOptions): Promise<SQLResult>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { LooseObject } from "../tools/loose.js";
|
|
2
|
+
import { BaseService } from "./BaseService.js";
|
|
3
|
+
import { type CommonOptions } from "../tools/options.js";
|
|
4
|
+
interface appleClientSecret {
|
|
5
|
+
secret: string;
|
|
6
|
+
}
|
|
7
|
+
export declare class SettingsService extends BaseService {
|
|
8
|
+
/**
|
|
9
|
+
* Fetch all available app settings.
|
|
10
|
+
*
|
|
11
|
+
* @throws {ClientResponseError}
|
|
12
|
+
*/
|
|
13
|
+
getAll(options?: CommonOptions): Promise<LooseObject>;
|
|
14
|
+
/**
|
|
15
|
+
* Bulk updates app settings.
|
|
16
|
+
*
|
|
17
|
+
* @throws {ClientResponseError}
|
|
18
|
+
*/
|
|
19
|
+
update(bodyParams?: LooseObject | FormData, options?: CommonOptions): Promise<LooseObject>;
|
|
20
|
+
/**
|
|
21
|
+
* Performs a S3 filesystem connection test.
|
|
22
|
+
*
|
|
23
|
+
* The currently supported `filesystem` are "storage" and "backups".
|
|
24
|
+
*
|
|
25
|
+
* @throws {ClientResponseError}
|
|
26
|
+
*/
|
|
27
|
+
testS3(filesystem?: string, options?: CommonOptions): Promise<boolean>;
|
|
28
|
+
/**
|
|
29
|
+
* Sends a test email.
|
|
30
|
+
*
|
|
31
|
+
* The possible `emailTemplate` values are:
|
|
32
|
+
* - verification
|
|
33
|
+
* - password-reset
|
|
34
|
+
* - email-change
|
|
35
|
+
*
|
|
36
|
+
* @throws {ClientResponseError}
|
|
37
|
+
*/
|
|
38
|
+
testEmail(collectionIdOrName: string, toEmail: string, emailTemplate: string, options?: CommonOptions): Promise<boolean>;
|
|
39
|
+
/**
|
|
40
|
+
* Generates a new Apple OAuth2 client secret.
|
|
41
|
+
*
|
|
42
|
+
* @throws {ClientResponseError}
|
|
43
|
+
*/
|
|
44
|
+
generateAppleClientSecret(clientId: string, teamId: string, keyId: string, privateKey: string, duration: number, options?: CommonOptions): Promise<appleClientSecret>;
|
|
45
|
+
}
|
|
46
|
+
export {};
|