@kedaruma/revlm-client 1.0.1 → 1.0.4
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/dist/index.d.mts +61 -5
- package/dist/index.d.ts +61 -5
- package/dist/index.js +102 -5
- package/dist/index.mjs +97 -4
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
import { Timestamp, Long } from 'bson';
|
|
2
|
+
import { User as User$1 } from '@kedaruma/revlm-shared/models/user-types';
|
|
2
3
|
|
|
4
|
+
type RevlmErrorResponse = {
|
|
5
|
+
ok: false;
|
|
6
|
+
error: string;
|
|
7
|
+
};
|
|
8
|
+
type LoginSuccess = {
|
|
9
|
+
ok: true;
|
|
10
|
+
token: string;
|
|
11
|
+
user: User$1;
|
|
12
|
+
};
|
|
13
|
+
type LoginResponse = LoginSuccess | RevlmErrorResponse;
|
|
14
|
+
type ProvisionalLoginSuccess = {
|
|
15
|
+
ok: true;
|
|
16
|
+
token: string;
|
|
17
|
+
user: Record<string, never>;
|
|
18
|
+
};
|
|
19
|
+
type ProvisionalLoginResponse = ProvisionalLoginSuccess | RevlmErrorResponse;
|
|
3
20
|
type FindOneOptions = {
|
|
4
21
|
readonly projection?: Record<string, unknown>;
|
|
5
22
|
readonly sort?: Record<string, unknown>;
|
|
@@ -100,7 +117,7 @@ type WatchOptionsFilter = {
|
|
|
100
117
|
filter: Filter;
|
|
101
118
|
};
|
|
102
119
|
|
|
103
|
-
declare class
|
|
120
|
+
declare class MdbCollection<T extends Document = Document> {
|
|
104
121
|
private _revlm;
|
|
105
122
|
private _dbName;
|
|
106
123
|
private _collection;
|
|
@@ -127,9 +144,14 @@ declare class RevlmDBDatabase {
|
|
|
127
144
|
private _revlm;
|
|
128
145
|
private _dbName;
|
|
129
146
|
constructor(dbName: string, revlm: Revlm);
|
|
130
|
-
collection<T extends Document = Document>(collection: string):
|
|
147
|
+
collection<T extends Document = Document>(collection: string): MdbCollection<T>;
|
|
131
148
|
}
|
|
132
149
|
|
|
150
|
+
type EmailPasswordCredential = {
|
|
151
|
+
type: 'emailPassword';
|
|
152
|
+
email: string;
|
|
153
|
+
password: string;
|
|
154
|
+
};
|
|
133
155
|
type RevlmOptions = {
|
|
134
156
|
fetchImpl?: typeof fetch;
|
|
135
157
|
defaultHeaders?: Record<string, string>;
|
|
@@ -165,8 +187,8 @@ declare class Revlm {
|
|
|
165
187
|
private makeHeaders;
|
|
166
188
|
private parseResponse;
|
|
167
189
|
private request;
|
|
168
|
-
login(authId: string, password: string): Promise<
|
|
169
|
-
provisionalLogin(authId: string): Promise<
|
|
190
|
+
login(authId: string, password: string): Promise<LoginResponse>;
|
|
191
|
+
provisionalLogin(authId: string): Promise<ProvisionalLoginResponse>;
|
|
170
192
|
registerUser(user: any, password: string): Promise<RevlmResponse<any>>;
|
|
171
193
|
deleteUser(params: {
|
|
172
194
|
_id?: any;
|
|
@@ -176,4 +198,38 @@ declare class Revlm {
|
|
|
176
198
|
db(dbName: string): RevlmDBDatabase;
|
|
177
199
|
}
|
|
178
200
|
|
|
179
|
-
|
|
201
|
+
declare class MongoDBService {
|
|
202
|
+
private _revlm;
|
|
203
|
+
constructor(revlm: Revlm);
|
|
204
|
+
db(dbName: string): RevlmDBDatabase;
|
|
205
|
+
}
|
|
206
|
+
declare class Credentials {
|
|
207
|
+
static emailPassword(email: string, password: string): EmailPasswordCredential;
|
|
208
|
+
}
|
|
209
|
+
declare class User {
|
|
210
|
+
private _app;
|
|
211
|
+
private _token;
|
|
212
|
+
private _profile;
|
|
213
|
+
constructor(app: App, token: string, profile: any);
|
|
214
|
+
get id(): string;
|
|
215
|
+
get accessToken(): string;
|
|
216
|
+
get profile(): any;
|
|
217
|
+
mongoClient(_serviceName?: string): MongoDBService;
|
|
218
|
+
logOut(): Promise<void>;
|
|
219
|
+
}
|
|
220
|
+
declare class App {
|
|
221
|
+
private _currentUser;
|
|
222
|
+
private _users;
|
|
223
|
+
__revlm: Revlm;
|
|
224
|
+
constructor(baseUrl: string, opts?: RevlmOptions & {
|
|
225
|
+
id?: string;
|
|
226
|
+
});
|
|
227
|
+
get currentUser(): User | null;
|
|
228
|
+
get allUsers(): Record<string, User>;
|
|
229
|
+
logIn(cred: EmailPasswordCredential): Promise<User>;
|
|
230
|
+
switchUser(user: User): User;
|
|
231
|
+
removeUser(user: User): Promise<void>;
|
|
232
|
+
logOut(): Promise<void>;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export { App, Credentials, MongoDBService, Revlm, type RevlmOptions, type RevlmResponse, User };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
import { Timestamp, Long } from 'bson';
|
|
2
|
+
import { User as User$1 } from '@kedaruma/revlm-shared/models/user-types';
|
|
2
3
|
|
|
4
|
+
type RevlmErrorResponse = {
|
|
5
|
+
ok: false;
|
|
6
|
+
error: string;
|
|
7
|
+
};
|
|
8
|
+
type LoginSuccess = {
|
|
9
|
+
ok: true;
|
|
10
|
+
token: string;
|
|
11
|
+
user: User$1;
|
|
12
|
+
};
|
|
13
|
+
type LoginResponse = LoginSuccess | RevlmErrorResponse;
|
|
14
|
+
type ProvisionalLoginSuccess = {
|
|
15
|
+
ok: true;
|
|
16
|
+
token: string;
|
|
17
|
+
user: Record<string, never>;
|
|
18
|
+
};
|
|
19
|
+
type ProvisionalLoginResponse = ProvisionalLoginSuccess | RevlmErrorResponse;
|
|
3
20
|
type FindOneOptions = {
|
|
4
21
|
readonly projection?: Record<string, unknown>;
|
|
5
22
|
readonly sort?: Record<string, unknown>;
|
|
@@ -100,7 +117,7 @@ type WatchOptionsFilter = {
|
|
|
100
117
|
filter: Filter;
|
|
101
118
|
};
|
|
102
119
|
|
|
103
|
-
declare class
|
|
120
|
+
declare class MdbCollection<T extends Document = Document> {
|
|
104
121
|
private _revlm;
|
|
105
122
|
private _dbName;
|
|
106
123
|
private _collection;
|
|
@@ -127,9 +144,14 @@ declare class RevlmDBDatabase {
|
|
|
127
144
|
private _revlm;
|
|
128
145
|
private _dbName;
|
|
129
146
|
constructor(dbName: string, revlm: Revlm);
|
|
130
|
-
collection<T extends Document = Document>(collection: string):
|
|
147
|
+
collection<T extends Document = Document>(collection: string): MdbCollection<T>;
|
|
131
148
|
}
|
|
132
149
|
|
|
150
|
+
type EmailPasswordCredential = {
|
|
151
|
+
type: 'emailPassword';
|
|
152
|
+
email: string;
|
|
153
|
+
password: string;
|
|
154
|
+
};
|
|
133
155
|
type RevlmOptions = {
|
|
134
156
|
fetchImpl?: typeof fetch;
|
|
135
157
|
defaultHeaders?: Record<string, string>;
|
|
@@ -165,8 +187,8 @@ declare class Revlm {
|
|
|
165
187
|
private makeHeaders;
|
|
166
188
|
private parseResponse;
|
|
167
189
|
private request;
|
|
168
|
-
login(authId: string, password: string): Promise<
|
|
169
|
-
provisionalLogin(authId: string): Promise<
|
|
190
|
+
login(authId: string, password: string): Promise<LoginResponse>;
|
|
191
|
+
provisionalLogin(authId: string): Promise<ProvisionalLoginResponse>;
|
|
170
192
|
registerUser(user: any, password: string): Promise<RevlmResponse<any>>;
|
|
171
193
|
deleteUser(params: {
|
|
172
194
|
_id?: any;
|
|
@@ -176,4 +198,38 @@ declare class Revlm {
|
|
|
176
198
|
db(dbName: string): RevlmDBDatabase;
|
|
177
199
|
}
|
|
178
200
|
|
|
179
|
-
|
|
201
|
+
declare class MongoDBService {
|
|
202
|
+
private _revlm;
|
|
203
|
+
constructor(revlm: Revlm);
|
|
204
|
+
db(dbName: string): RevlmDBDatabase;
|
|
205
|
+
}
|
|
206
|
+
declare class Credentials {
|
|
207
|
+
static emailPassword(email: string, password: string): EmailPasswordCredential;
|
|
208
|
+
}
|
|
209
|
+
declare class User {
|
|
210
|
+
private _app;
|
|
211
|
+
private _token;
|
|
212
|
+
private _profile;
|
|
213
|
+
constructor(app: App, token: string, profile: any);
|
|
214
|
+
get id(): string;
|
|
215
|
+
get accessToken(): string;
|
|
216
|
+
get profile(): any;
|
|
217
|
+
mongoClient(_serviceName?: string): MongoDBService;
|
|
218
|
+
logOut(): Promise<void>;
|
|
219
|
+
}
|
|
220
|
+
declare class App {
|
|
221
|
+
private _currentUser;
|
|
222
|
+
private _users;
|
|
223
|
+
__revlm: Revlm;
|
|
224
|
+
constructor(baseUrl: string, opts?: RevlmOptions & {
|
|
225
|
+
id?: string;
|
|
226
|
+
});
|
|
227
|
+
get currentUser(): User | null;
|
|
228
|
+
get allUsers(): Record<string, User>;
|
|
229
|
+
logIn(cred: EmailPasswordCredential): Promise<User>;
|
|
230
|
+
switchUser(user: User): User;
|
|
231
|
+
removeUser(user: User): Promise<void>;
|
|
232
|
+
logOut(): Promise<void>;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export { App, Credentials, MongoDBService, Revlm, type RevlmOptions, type RevlmResponse, User };
|
package/dist/index.js
CHANGED
|
@@ -20,7 +20,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
-
|
|
23
|
+
App: () => App,
|
|
24
|
+
Credentials: () => Credentials,
|
|
25
|
+
MongoDBService: () => MongoDBService,
|
|
26
|
+
Revlm: () => Revlm,
|
|
27
|
+
User: () => User
|
|
24
28
|
});
|
|
25
29
|
module.exports = __toCommonJS(index_exports);
|
|
26
30
|
|
|
@@ -28,8 +32,8 @@ module.exports = __toCommonJS(index_exports);
|
|
|
28
32
|
var import_bson = require("bson");
|
|
29
33
|
var import_revlm_shared = require("@kedaruma/revlm-shared");
|
|
30
34
|
|
|
31
|
-
// src/
|
|
32
|
-
var
|
|
35
|
+
// src/MdbCollection.ts
|
|
36
|
+
var MdbCollection = class {
|
|
33
37
|
_revlm;
|
|
34
38
|
_dbName;
|
|
35
39
|
_collection;
|
|
@@ -122,7 +126,7 @@ var RevlmDBDatabase = class {
|
|
|
122
126
|
this._revlm = revlm;
|
|
123
127
|
}
|
|
124
128
|
collection(collection) {
|
|
125
|
-
return new
|
|
129
|
+
return new MdbCollection(collection, this._dbName, this._revlm);
|
|
126
130
|
}
|
|
127
131
|
};
|
|
128
132
|
|
|
@@ -270,7 +274,100 @@ var Revlm = class {
|
|
|
270
274
|
return new RevlmDBDatabase(dbName, this);
|
|
271
275
|
}
|
|
272
276
|
};
|
|
277
|
+
var MongoDBService = class {
|
|
278
|
+
_revlm;
|
|
279
|
+
constructor(revlm) {
|
|
280
|
+
this._revlm = revlm;
|
|
281
|
+
}
|
|
282
|
+
db(dbName) {
|
|
283
|
+
return new RevlmDBDatabase(dbName, this._revlm);
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
var Credentials = class {
|
|
287
|
+
static emailPassword(email, password) {
|
|
288
|
+
if (!email || !password) throw new Error("email and password are required");
|
|
289
|
+
return { type: "emailPassword", email, password };
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
var User = class {
|
|
293
|
+
_app;
|
|
294
|
+
_token;
|
|
295
|
+
_profile;
|
|
296
|
+
constructor(app, token, profile) {
|
|
297
|
+
this._app = app;
|
|
298
|
+
this._token = token;
|
|
299
|
+
this._profile = profile || {};
|
|
300
|
+
}
|
|
301
|
+
get id() {
|
|
302
|
+
return String(this._profile && this._profile._id ? this._profile._id : "");
|
|
303
|
+
}
|
|
304
|
+
get accessToken() {
|
|
305
|
+
return this._token;
|
|
306
|
+
}
|
|
307
|
+
get profile() {
|
|
308
|
+
return this._profile;
|
|
309
|
+
}
|
|
310
|
+
mongoClient(_serviceName = "mongodb-atlas") {
|
|
311
|
+
return new MongoDBService(this._app.__revlm);
|
|
312
|
+
}
|
|
313
|
+
async logOut() {
|
|
314
|
+
await this._app.logOut();
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
var App = class {
|
|
318
|
+
_currentUser = null;
|
|
319
|
+
_users = {};
|
|
320
|
+
// Expose for internal use by emulated classes
|
|
321
|
+
__revlm;
|
|
322
|
+
constructor(baseUrl, opts = {}) {
|
|
323
|
+
this.__revlm = new Revlm(baseUrl, opts);
|
|
324
|
+
}
|
|
325
|
+
get currentUser() {
|
|
326
|
+
return this._currentUser;
|
|
327
|
+
}
|
|
328
|
+
get allUsers() {
|
|
329
|
+
return { ...this._users };
|
|
330
|
+
}
|
|
331
|
+
async logIn(cred) {
|
|
332
|
+
if (!cred || cred.type !== "emailPassword") {
|
|
333
|
+
throw new Error("Unsupported credentials type");
|
|
334
|
+
}
|
|
335
|
+
const res = await this.__revlm.login(cred.email, cred.password);
|
|
336
|
+
if (!res || !res.ok || !res.token) {
|
|
337
|
+
const errMsg = res && !res.ok ? res.error : "login failed";
|
|
338
|
+
throw new Error(errMsg);
|
|
339
|
+
}
|
|
340
|
+
this.__revlm.setToken(res.token);
|
|
341
|
+
const user = new User(this, res.token, res.user);
|
|
342
|
+
const userId = user.id || "current";
|
|
343
|
+
this._users[userId] = user;
|
|
344
|
+
this._currentUser = user;
|
|
345
|
+
return user;
|
|
346
|
+
}
|
|
347
|
+
switchUser(user) {
|
|
348
|
+
if (!user) throw new Error("user is required");
|
|
349
|
+
this._currentUser = user;
|
|
350
|
+
this.__revlm.setToken(user.accessToken);
|
|
351
|
+
return user;
|
|
352
|
+
}
|
|
353
|
+
async removeUser(user) {
|
|
354
|
+
if (!user) return;
|
|
355
|
+
const id = user.id || "current";
|
|
356
|
+
delete this._users[id];
|
|
357
|
+
if (this._currentUser === user) {
|
|
358
|
+
await this.logOut();
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
async logOut() {
|
|
362
|
+
this.__revlm.logout();
|
|
363
|
+
this._currentUser = null;
|
|
364
|
+
}
|
|
365
|
+
};
|
|
273
366
|
// Annotate the CommonJS export names for ESM import in node:
|
|
274
367
|
0 && (module.exports = {
|
|
275
|
-
|
|
368
|
+
App,
|
|
369
|
+
Credentials,
|
|
370
|
+
MongoDBService,
|
|
371
|
+
Revlm,
|
|
372
|
+
User
|
|
276
373
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
import { EJSON } from "bson";
|
|
3
3
|
import { AuthClient } from "@kedaruma/revlm-shared";
|
|
4
4
|
|
|
5
|
-
// src/
|
|
6
|
-
var
|
|
5
|
+
// src/MdbCollection.ts
|
|
6
|
+
var MdbCollection = class {
|
|
7
7
|
_revlm;
|
|
8
8
|
_dbName;
|
|
9
9
|
_collection;
|
|
@@ -96,7 +96,7 @@ var RevlmDBDatabase = class {
|
|
|
96
96
|
this._revlm = revlm;
|
|
97
97
|
}
|
|
98
98
|
collection(collection) {
|
|
99
|
-
return new
|
|
99
|
+
return new MdbCollection(collection, this._dbName, this._revlm);
|
|
100
100
|
}
|
|
101
101
|
};
|
|
102
102
|
|
|
@@ -244,6 +244,99 @@ var Revlm = class {
|
|
|
244
244
|
return new RevlmDBDatabase(dbName, this);
|
|
245
245
|
}
|
|
246
246
|
};
|
|
247
|
+
var MongoDBService = class {
|
|
248
|
+
_revlm;
|
|
249
|
+
constructor(revlm) {
|
|
250
|
+
this._revlm = revlm;
|
|
251
|
+
}
|
|
252
|
+
db(dbName) {
|
|
253
|
+
return new RevlmDBDatabase(dbName, this._revlm);
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
var Credentials = class {
|
|
257
|
+
static emailPassword(email, password) {
|
|
258
|
+
if (!email || !password) throw new Error("email and password are required");
|
|
259
|
+
return { type: "emailPassword", email, password };
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
var User = class {
|
|
263
|
+
_app;
|
|
264
|
+
_token;
|
|
265
|
+
_profile;
|
|
266
|
+
constructor(app, token, profile) {
|
|
267
|
+
this._app = app;
|
|
268
|
+
this._token = token;
|
|
269
|
+
this._profile = profile || {};
|
|
270
|
+
}
|
|
271
|
+
get id() {
|
|
272
|
+
return String(this._profile && this._profile._id ? this._profile._id : "");
|
|
273
|
+
}
|
|
274
|
+
get accessToken() {
|
|
275
|
+
return this._token;
|
|
276
|
+
}
|
|
277
|
+
get profile() {
|
|
278
|
+
return this._profile;
|
|
279
|
+
}
|
|
280
|
+
mongoClient(_serviceName = "mongodb-atlas") {
|
|
281
|
+
return new MongoDBService(this._app.__revlm);
|
|
282
|
+
}
|
|
283
|
+
async logOut() {
|
|
284
|
+
await this._app.logOut();
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
var App = class {
|
|
288
|
+
_currentUser = null;
|
|
289
|
+
_users = {};
|
|
290
|
+
// Expose for internal use by emulated classes
|
|
291
|
+
__revlm;
|
|
292
|
+
constructor(baseUrl, opts = {}) {
|
|
293
|
+
this.__revlm = new Revlm(baseUrl, opts);
|
|
294
|
+
}
|
|
295
|
+
get currentUser() {
|
|
296
|
+
return this._currentUser;
|
|
297
|
+
}
|
|
298
|
+
get allUsers() {
|
|
299
|
+
return { ...this._users };
|
|
300
|
+
}
|
|
301
|
+
async logIn(cred) {
|
|
302
|
+
if (!cred || cred.type !== "emailPassword") {
|
|
303
|
+
throw new Error("Unsupported credentials type");
|
|
304
|
+
}
|
|
305
|
+
const res = await this.__revlm.login(cred.email, cred.password);
|
|
306
|
+
if (!res || !res.ok || !res.token) {
|
|
307
|
+
const errMsg = res && !res.ok ? res.error : "login failed";
|
|
308
|
+
throw new Error(errMsg);
|
|
309
|
+
}
|
|
310
|
+
this.__revlm.setToken(res.token);
|
|
311
|
+
const user = new User(this, res.token, res.user);
|
|
312
|
+
const userId = user.id || "current";
|
|
313
|
+
this._users[userId] = user;
|
|
314
|
+
this._currentUser = user;
|
|
315
|
+
return user;
|
|
316
|
+
}
|
|
317
|
+
switchUser(user) {
|
|
318
|
+
if (!user) throw new Error("user is required");
|
|
319
|
+
this._currentUser = user;
|
|
320
|
+
this.__revlm.setToken(user.accessToken);
|
|
321
|
+
return user;
|
|
322
|
+
}
|
|
323
|
+
async removeUser(user) {
|
|
324
|
+
if (!user) return;
|
|
325
|
+
const id = user.id || "current";
|
|
326
|
+
delete this._users[id];
|
|
327
|
+
if (this._currentUser === user) {
|
|
328
|
+
await this.logOut();
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
async logOut() {
|
|
332
|
+
this.__revlm.logout();
|
|
333
|
+
this._currentUser = null;
|
|
334
|
+
}
|
|
335
|
+
};
|
|
247
336
|
export {
|
|
248
|
-
|
|
337
|
+
App,
|
|
338
|
+
Credentials,
|
|
339
|
+
MongoDBService,
|
|
340
|
+
Revlm,
|
|
341
|
+
User
|
|
249
342
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kedaruma/revlm-client",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "TypeScript client SDK for talking to the Revlm server replacement for MongoDB Realm.",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"bson": "^6.10.4",
|
|
31
31
|
"dotenv": "^17.2.3",
|
|
32
|
-
"@kedaruma/revlm-shared": "1.0.
|
|
32
|
+
"@kedaruma/revlm-shared": "1.0.2"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"tsup": "^8.5.1"
|