@kedaruma/revlm-client 1.0.39 → 1.0.42

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 CHANGED
@@ -1,3 +1,4 @@
1
+ import { DefaultId } from '@kedaruma/revlm-shared/models/mongo-doc-base-types';
1
2
  import * as bson from 'bson';
2
3
  import { Timestamp, Long } from 'bson';
3
4
  import { User as User$1, UserBase as UserBase$1 } from '@kedaruma/revlm-shared/models/user-types';
@@ -239,7 +240,7 @@ declare class RevlmUser {
239
240
  callFunction: (_name: string, _args?: any[]) => Promise<any>;
240
241
  };
241
242
  constructor(app: App, token: string, profile: User);
242
- get id(): string;
243
+ get id(): DefaultId;
243
244
  get accessToken(): string;
244
245
  get profile(): User;
245
246
  mongoClient(_serviceName?: string): MongoDBService;
@@ -256,6 +257,7 @@ declare class App {
256
257
  constructor(baseUrl: string, opts?: RevlmOptions & {
257
258
  id?: string;
258
259
  });
260
+ private getUserKey;
259
261
  get currentUser(): RevlmUser | null;
260
262
  get allUsers(): Record<string, RevlmUser>;
261
263
  logIn(cred: EmailPasswordCredential): Promise<RevlmUser>;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { DefaultId } from '@kedaruma/revlm-shared/models/mongo-doc-base-types';
1
2
  import * as bson from 'bson';
2
3
  import { Timestamp, Long } from 'bson';
3
4
  import { User as User$1, UserBase as UserBase$1 } from '@kedaruma/revlm-shared/models/user-types';
@@ -239,7 +240,7 @@ declare class RevlmUser {
239
240
  callFunction: (_name: string, _args?: any[]) => Promise<any>;
240
241
  };
241
242
  constructor(app: App, token: string, profile: User);
242
- get id(): string;
243
+ get id(): DefaultId;
243
244
  get accessToken(): string;
244
245
  get profile(): User;
245
246
  mongoClient(_serviceName?: string): MongoDBService;
@@ -256,6 +257,7 @@ declare class App {
256
257
  constructor(baseUrl: string, opts?: RevlmOptions & {
257
258
  id?: string;
258
259
  });
260
+ private getUserKey;
259
261
  get currentUser(): RevlmUser | null;
260
262
  get allUsers(): Record<string, RevlmUser>;
261
263
  logIn(cred: EmailPasswordCredential): Promise<RevlmUser>;
package/dist/index.js CHANGED
@@ -224,11 +224,8 @@ var Revlm = class {
224
224
  try {
225
225
  return import_bson.EJSON.parse(text);
226
226
  } catch (e) {
227
- }
228
- try {
229
- return JSON.parse(text);
230
- } catch (e) {
231
- return text;
227
+ const preview = text.length > 200 ? `${text.slice(0, 200)}...` : text;
228
+ throw new Error(`Invalid EJSON response: ${preview}`);
232
229
  }
233
230
  }
234
231
  async request(path, method = "POST", body) {
@@ -344,7 +341,7 @@ var RevlmUser = class {
344
341
  };
345
342
  }
346
343
  get id() {
347
- return String(this._profile && this._profile._id ? this._profile._id : "");
344
+ return this._profile && this._profile._id ? this._profile._id : "";
348
345
  }
349
346
  get accessToken() {
350
347
  return this._token;
@@ -375,6 +372,9 @@ var App = class {
375
372
  }
376
373
  };
377
374
  }
375
+ getUserKey(user) {
376
+ return user && user.id ? String(user.id) : "current";
377
+ }
378
378
  get currentUser() {
379
379
  return this._currentUser;
380
380
  }
@@ -401,8 +401,8 @@ var App = class {
401
401
  }
402
402
  this.revlm.setToken(res.token);
403
403
  const user = new RevlmUser(this, res.token, res.user);
404
- const userId = user.id || "current";
405
- this._users[userId] = user;
404
+ const userKey = this.getUserKey(user);
405
+ this._users[userKey] = user;
406
406
  this._currentUser = user;
407
407
  return user;
408
408
  }
@@ -414,8 +414,8 @@ var App = class {
414
414
  }
415
415
  async removeUser(user) {
416
416
  if (!user) return;
417
- const id = user.id || "current";
418
- delete this._users[id];
417
+ const userKey = this.getUserKey(user);
418
+ delete this._users[userKey];
419
419
  if (this._currentUser === user) {
420
420
  await this.logOut();
421
421
  }
package/dist/index.mjs CHANGED
@@ -181,11 +181,8 @@ var Revlm = class {
181
181
  try {
182
182
  return EJSON.parse(text);
183
183
  } catch (e) {
184
- }
185
- try {
186
- return JSON.parse(text);
187
- } catch (e) {
188
- return text;
184
+ const preview = text.length > 200 ? `${text.slice(0, 200)}...` : text;
185
+ throw new Error(`Invalid EJSON response: ${preview}`);
189
186
  }
190
187
  }
191
188
  async request(path, method = "POST", body) {
@@ -301,7 +298,7 @@ var RevlmUser = class {
301
298
  };
302
299
  }
303
300
  get id() {
304
- return String(this._profile && this._profile._id ? this._profile._id : "");
301
+ return this._profile && this._profile._id ? this._profile._id : "";
305
302
  }
306
303
  get accessToken() {
307
304
  return this._token;
@@ -332,6 +329,9 @@ var App = class {
332
329
  }
333
330
  };
334
331
  }
332
+ getUserKey(user) {
333
+ return user && user.id ? String(user.id) : "current";
334
+ }
335
335
  get currentUser() {
336
336
  return this._currentUser;
337
337
  }
@@ -358,8 +358,8 @@ var App = class {
358
358
  }
359
359
  this.revlm.setToken(res.token);
360
360
  const user = new RevlmUser(this, res.token, res.user);
361
- const userId = user.id || "current";
362
- this._users[userId] = user;
361
+ const userKey = this.getUserKey(user);
362
+ this._users[userKey] = user;
363
363
  this._currentUser = user;
364
364
  return user;
365
365
  }
@@ -371,8 +371,8 @@ var App = class {
371
371
  }
372
372
  async removeUser(user) {
373
373
  if (!user) return;
374
- const id = user.id || "current";
375
- delete this._users[id];
374
+ const userKey = this.getUserKey(user);
375
+ delete this._users[userKey];
376
376
  if (this._currentUser === user) {
377
377
  await this.logOut();
378
378
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kedaruma/revlm-client",
3
- "version": "1.0.39",
3
+ "version": "1.0.42",
4
4
  "private": false,
5
5
  "description": "TypeScript client SDK for talking to the Revlm server replacement for MongoDB Realm.",
6
6
  "keywords": [