@kedaruma/revlm-client 1.0.9 → 1.0.11
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 +12 -4
- package/dist/index.d.ts +12 -4
- package/dist/index.js +24 -6
- package/dist/index.mjs +24 -6
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { User as User$1 } from '@kedaruma/revlm-shared/models/user-types';
|
|
2
|
-
import { Timestamp, Long } from 'bson';
|
|
3
2
|
import * as bson from 'bson';
|
|
4
|
-
|
|
5
|
-
export { ObjectId as ObjectID, ObjectId } from 'bson';
|
|
3
|
+
import { Timestamp, Long } from 'bson';
|
|
6
4
|
|
|
7
5
|
type RevlmErrorResponse = {
|
|
8
6
|
ok: false;
|
|
@@ -175,6 +173,7 @@ type RevlmOptions = {
|
|
|
175
173
|
provisionalAuthSecretMaster?: string;
|
|
176
174
|
provisionalAuthDomain?: string;
|
|
177
175
|
autoSetToken?: boolean;
|
|
176
|
+
autoRefreshOn401?: boolean;
|
|
178
177
|
};
|
|
179
178
|
type RevlmResponse<T = any> = {
|
|
180
179
|
ok: boolean;
|
|
@@ -193,6 +192,7 @@ declare class Revlm {
|
|
|
193
192
|
private provisionalAuthSecretMaster;
|
|
194
193
|
private provisionalAuthDomain;
|
|
195
194
|
private autoSetToken;
|
|
195
|
+
private autoRefreshOn401;
|
|
196
196
|
constructor(baseUrl: string, opts?: RevlmOptions);
|
|
197
197
|
setToken(token: string): void;
|
|
198
198
|
getToken(): string | undefined;
|
|
@@ -203,6 +203,8 @@ declare class Revlm {
|
|
|
203
203
|
private makeHeaders;
|
|
204
204
|
private parseResponse;
|
|
205
205
|
private request;
|
|
206
|
+
private shouldSkipAuthRetry;
|
|
207
|
+
private requestWithRetry;
|
|
206
208
|
login(authId: string, password: string): Promise<LoginResponse>;
|
|
207
209
|
provisionalLogin(authId: string): Promise<ProvisionalLoginResponse>;
|
|
208
210
|
registerUser(user: UserInput, password: string): Promise<RevlmResponse<any>>;
|
|
@@ -256,4 +258,10 @@ declare class App {
|
|
|
256
258
|
deleteUser(user: User): Promise<void>;
|
|
257
259
|
}
|
|
258
260
|
|
|
259
|
-
|
|
261
|
+
declare const ObjectId: typeof bson.ObjectId;
|
|
262
|
+
declare const ObjectID: typeof bson.ObjectId;
|
|
263
|
+
declare const BSON: typeof bson & {
|
|
264
|
+
ObjectID: typeof bson.ObjectId;
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
export { type AggregatePipelineStage, App, BSON, type BaseChangeEvent, type ChangeEvent, type ChangeEventId, type CountOptions, Credentials, type DeleteEvent, type DeleteResult, type DeleteUserResponse, type DeleteUserSuccess, type Document, type DocumentKey, type DocumentNamespace, type DropDatabaseEvent, type DropEvent, type Filter, type FindOneAndModifyOptions, type FindOneOptions, type FindOptions, type InsertEvent, type InsertManyResult, type InsertOneResult, type InvalidateEvent, type LoginResponse, type LoginSuccess, MdbCollection, MongoDBService, type NewDocument, ObjectID, ObjectId, type OperationType, type ProvisionalLoginResponse, type ProvisionalLoginSuccess, type RegisterUserResponse, type RegisterUserSuccess, type RenameEvent, type ReplaceEvent, Revlm, RevlmDBDatabase, type RevlmErrorResponse, type RevlmOptions, type RevlmResponse, type Update, type UpdateDescription, type UpdateEvent, type UpdateOptions, type UpdateResult, User, type WatchOptionsFilter, type WatchOptionsIds };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { User as User$1 } from '@kedaruma/revlm-shared/models/user-types';
|
|
2
|
-
import { Timestamp, Long } from 'bson';
|
|
3
2
|
import * as bson from 'bson';
|
|
4
|
-
|
|
5
|
-
export { ObjectId as ObjectID, ObjectId } from 'bson';
|
|
3
|
+
import { Timestamp, Long } from 'bson';
|
|
6
4
|
|
|
7
5
|
type RevlmErrorResponse = {
|
|
8
6
|
ok: false;
|
|
@@ -175,6 +173,7 @@ type RevlmOptions = {
|
|
|
175
173
|
provisionalAuthSecretMaster?: string;
|
|
176
174
|
provisionalAuthDomain?: string;
|
|
177
175
|
autoSetToken?: boolean;
|
|
176
|
+
autoRefreshOn401?: boolean;
|
|
178
177
|
};
|
|
179
178
|
type RevlmResponse<T = any> = {
|
|
180
179
|
ok: boolean;
|
|
@@ -193,6 +192,7 @@ declare class Revlm {
|
|
|
193
192
|
private provisionalAuthSecretMaster;
|
|
194
193
|
private provisionalAuthDomain;
|
|
195
194
|
private autoSetToken;
|
|
195
|
+
private autoRefreshOn401;
|
|
196
196
|
constructor(baseUrl: string, opts?: RevlmOptions);
|
|
197
197
|
setToken(token: string): void;
|
|
198
198
|
getToken(): string | undefined;
|
|
@@ -203,6 +203,8 @@ declare class Revlm {
|
|
|
203
203
|
private makeHeaders;
|
|
204
204
|
private parseResponse;
|
|
205
205
|
private request;
|
|
206
|
+
private shouldSkipAuthRetry;
|
|
207
|
+
private requestWithRetry;
|
|
206
208
|
login(authId: string, password: string): Promise<LoginResponse>;
|
|
207
209
|
provisionalLogin(authId: string): Promise<ProvisionalLoginResponse>;
|
|
208
210
|
registerUser(user: UserInput, password: string): Promise<RevlmResponse<any>>;
|
|
@@ -256,4 +258,10 @@ declare class App {
|
|
|
256
258
|
deleteUser(user: User): Promise<void>;
|
|
257
259
|
}
|
|
258
260
|
|
|
259
|
-
|
|
261
|
+
declare const ObjectId: typeof bson.ObjectId;
|
|
262
|
+
declare const ObjectID: typeof bson.ObjectId;
|
|
263
|
+
declare const BSON: typeof bson & {
|
|
264
|
+
ObjectID: typeof bson.ObjectId;
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
export { type AggregatePipelineStage, App, BSON, type BaseChangeEvent, type ChangeEvent, type ChangeEventId, type CountOptions, Credentials, type DeleteEvent, type DeleteResult, type DeleteUserResponse, type DeleteUserSuccess, type Document, type DocumentKey, type DocumentNamespace, type DropDatabaseEvent, type DropEvent, type Filter, type FindOneAndModifyOptions, type FindOneOptions, type FindOptions, type InsertEvent, type InsertManyResult, type InsertOneResult, type InvalidateEvent, type LoginResponse, type LoginSuccess, MdbCollection, MongoDBService, type NewDocument, ObjectID, ObjectId, type OperationType, type ProvisionalLoginResponse, type ProvisionalLoginSuccess, type RegisterUserResponse, type RegisterUserSuccess, type RenameEvent, type ReplaceEvent, Revlm, RevlmDBDatabase, type RevlmErrorResponse, type RevlmOptions, type RevlmResponse, type Update, type UpdateDescription, type UpdateEvent, type UpdateOptions, type UpdateResult, User, type WatchOptionsFilter, type WatchOptionsIds };
|
package/dist/index.js
CHANGED
|
@@ -35,8 +35,8 @@ __export(index_exports, {
|
|
|
35
35
|
Credentials: () => Credentials,
|
|
36
36
|
MdbCollection: () => MdbCollection,
|
|
37
37
|
MongoDBService: () => MongoDBService,
|
|
38
|
-
ObjectID: () =>
|
|
39
|
-
ObjectId: () =>
|
|
38
|
+
ObjectID: () => ObjectID,
|
|
39
|
+
ObjectId: () => ObjectId2,
|
|
40
40
|
Revlm: () => Revlm,
|
|
41
41
|
RevlmDBDatabase: () => RevlmDBDatabase,
|
|
42
42
|
User: () => User
|
|
@@ -155,6 +155,7 @@ var Revlm = class {
|
|
|
155
155
|
provisionalAuthSecretMaster;
|
|
156
156
|
provisionalAuthDomain;
|
|
157
157
|
autoSetToken;
|
|
158
|
+
autoRefreshOn401;
|
|
158
159
|
constructor(baseUrl, opts = {}) {
|
|
159
160
|
if (!baseUrl) throw new Error("baseUrl is required");
|
|
160
161
|
this.baseUrl = baseUrl.replace(/\/$/, "");
|
|
@@ -164,6 +165,7 @@ var Revlm = class {
|
|
|
164
165
|
this.provisionalAuthSecretMaster = opts.provisionalAuthSecretMaster || "";
|
|
165
166
|
this.provisionalAuthDomain = opts.provisionalAuthDomain || "";
|
|
166
167
|
this.autoSetToken = opts.autoSetToken ?? true;
|
|
168
|
+
this.autoRefreshOn401 = opts.autoRefreshOn401 || false;
|
|
167
169
|
if (!this.fetchImpl) {
|
|
168
170
|
throw new Error("No fetch implementation available. Provide fetchImpl in options or run in Node 18+ with global fetch.");
|
|
169
171
|
}
|
|
@@ -185,7 +187,7 @@ var Revlm = class {
|
|
|
185
187
|
// On success, if autoSetToken is true and res.token is set, update the client token.
|
|
186
188
|
async refreshToken() {
|
|
187
189
|
if (!this._token) return { ok: false, error: "No token set" };
|
|
188
|
-
const res = await this.
|
|
190
|
+
const res = await this.requestWithRetry("/refresh-token", "POST", void 0, { allowAuthRetry: false, retrying: false });
|
|
189
191
|
if (this.autoSetToken && res && res.ok && res.token) {
|
|
190
192
|
this.setToken(res.token);
|
|
191
193
|
}
|
|
@@ -230,6 +232,14 @@ var Revlm = class {
|
|
|
230
232
|
}
|
|
231
233
|
}
|
|
232
234
|
async request(path, method = "POST", body) {
|
|
235
|
+
return this.requestWithRetry(path, method, body, { allowAuthRetry: this.autoRefreshOn401, retrying: false });
|
|
236
|
+
}
|
|
237
|
+
shouldSkipAuthRetry(path) {
|
|
238
|
+
const pathname = path.startsWith("http") ? new URL(path).pathname : path;
|
|
239
|
+
return pathname.includes("/login") || pathname.includes("/provisional-login") || pathname.includes("/refresh-token") || pathname.includes("/verify-token");
|
|
240
|
+
}
|
|
241
|
+
async requestWithRetry(path, method = "POST", body, opts = { allowAuthRetry: false, retrying: false }) {
|
|
242
|
+
const { allowAuthRetry, retrying } = opts;
|
|
233
243
|
const url = path.startsWith("http") ? path : `${this.baseUrl}${path.startsWith("/") ? "" : "/"}${path}`;
|
|
234
244
|
const hasBody = body !== void 0;
|
|
235
245
|
const headers = this.makeHeaders(hasBody);
|
|
@@ -249,6 +259,12 @@ var Revlm = class {
|
|
|
249
259
|
if (out && out.ok === false && !out.error) {
|
|
250
260
|
out.error = parsed?.reason || parsed?.message || "Unknown error";
|
|
251
261
|
}
|
|
262
|
+
if (allowAuthRetry && !retrying && res.status === 401 && !this.shouldSkipAuthRetry(path)) {
|
|
263
|
+
const refreshRes = await this.refreshToken();
|
|
264
|
+
if (refreshRes && refreshRes.ok && refreshRes.token) {
|
|
265
|
+
return this.requestWithRetry(path, method, body, { allowAuthRetry: false, retrying: true });
|
|
266
|
+
}
|
|
267
|
+
}
|
|
252
268
|
return out;
|
|
253
269
|
} catch (err) {
|
|
254
270
|
return { ok: false, error: err?.message || String(err) };
|
|
@@ -404,9 +420,11 @@ var App = class {
|
|
|
404
420
|
}
|
|
405
421
|
};
|
|
406
422
|
|
|
407
|
-
// src/
|
|
408
|
-
var
|
|
409
|
-
var
|
|
423
|
+
// src/bsonCompat.ts
|
|
424
|
+
var bson = __toESM(require("bson"));
|
|
425
|
+
var ObjectId2 = bson.ObjectId;
|
|
426
|
+
var ObjectID = bson.ObjectId;
|
|
427
|
+
var BSON = Object.assign({}, bson, { ObjectID: bson.ObjectId });
|
|
410
428
|
// Annotate the CommonJS export names for ESM import in node:
|
|
411
429
|
0 && (module.exports = {
|
|
412
430
|
App,
|
package/dist/index.mjs
CHANGED
|
@@ -110,6 +110,7 @@ var Revlm = class {
|
|
|
110
110
|
provisionalAuthSecretMaster;
|
|
111
111
|
provisionalAuthDomain;
|
|
112
112
|
autoSetToken;
|
|
113
|
+
autoRefreshOn401;
|
|
113
114
|
constructor(baseUrl, opts = {}) {
|
|
114
115
|
if (!baseUrl) throw new Error("baseUrl is required");
|
|
115
116
|
this.baseUrl = baseUrl.replace(/\/$/, "");
|
|
@@ -119,6 +120,7 @@ var Revlm = class {
|
|
|
119
120
|
this.provisionalAuthSecretMaster = opts.provisionalAuthSecretMaster || "";
|
|
120
121
|
this.provisionalAuthDomain = opts.provisionalAuthDomain || "";
|
|
121
122
|
this.autoSetToken = opts.autoSetToken ?? true;
|
|
123
|
+
this.autoRefreshOn401 = opts.autoRefreshOn401 || false;
|
|
122
124
|
if (!this.fetchImpl) {
|
|
123
125
|
throw new Error("No fetch implementation available. Provide fetchImpl in options or run in Node 18+ with global fetch.");
|
|
124
126
|
}
|
|
@@ -140,7 +142,7 @@ var Revlm = class {
|
|
|
140
142
|
// On success, if autoSetToken is true and res.token is set, update the client token.
|
|
141
143
|
async refreshToken() {
|
|
142
144
|
if (!this._token) return { ok: false, error: "No token set" };
|
|
143
|
-
const res = await this.
|
|
145
|
+
const res = await this.requestWithRetry("/refresh-token", "POST", void 0, { allowAuthRetry: false, retrying: false });
|
|
144
146
|
if (this.autoSetToken && res && res.ok && res.token) {
|
|
145
147
|
this.setToken(res.token);
|
|
146
148
|
}
|
|
@@ -185,6 +187,14 @@ var Revlm = class {
|
|
|
185
187
|
}
|
|
186
188
|
}
|
|
187
189
|
async request(path, method = "POST", body) {
|
|
190
|
+
return this.requestWithRetry(path, method, body, { allowAuthRetry: this.autoRefreshOn401, retrying: false });
|
|
191
|
+
}
|
|
192
|
+
shouldSkipAuthRetry(path) {
|
|
193
|
+
const pathname = path.startsWith("http") ? new URL(path).pathname : path;
|
|
194
|
+
return pathname.includes("/login") || pathname.includes("/provisional-login") || pathname.includes("/refresh-token") || pathname.includes("/verify-token");
|
|
195
|
+
}
|
|
196
|
+
async requestWithRetry(path, method = "POST", body, opts = { allowAuthRetry: false, retrying: false }) {
|
|
197
|
+
const { allowAuthRetry, retrying } = opts;
|
|
188
198
|
const url = path.startsWith("http") ? path : `${this.baseUrl}${path.startsWith("/") ? "" : "/"}${path}`;
|
|
189
199
|
const hasBody = body !== void 0;
|
|
190
200
|
const headers = this.makeHeaders(hasBody);
|
|
@@ -204,6 +214,12 @@ var Revlm = class {
|
|
|
204
214
|
if (out && out.ok === false && !out.error) {
|
|
205
215
|
out.error = parsed?.reason || parsed?.message || "Unknown error";
|
|
206
216
|
}
|
|
217
|
+
if (allowAuthRetry && !retrying && res.status === 401 && !this.shouldSkipAuthRetry(path)) {
|
|
218
|
+
const refreshRes = await this.refreshToken();
|
|
219
|
+
if (refreshRes && refreshRes.ok && refreshRes.token) {
|
|
220
|
+
return this.requestWithRetry(path, method, body, { allowAuthRetry: false, retrying: true });
|
|
221
|
+
}
|
|
222
|
+
}
|
|
207
223
|
return out;
|
|
208
224
|
} catch (err) {
|
|
209
225
|
return { ok: false, error: err?.message || String(err) };
|
|
@@ -359,17 +375,19 @@ var App = class {
|
|
|
359
375
|
}
|
|
360
376
|
};
|
|
361
377
|
|
|
362
|
-
// src/
|
|
363
|
-
import
|
|
364
|
-
|
|
378
|
+
// src/bsonCompat.ts
|
|
379
|
+
import * as bson from "bson";
|
|
380
|
+
var ObjectId2 = bson.ObjectId;
|
|
381
|
+
var ObjectID = bson.ObjectId;
|
|
382
|
+
var BSON = Object.assign({}, bson, { ObjectID: bson.ObjectId });
|
|
365
383
|
export {
|
|
366
384
|
App,
|
|
367
385
|
BSON,
|
|
368
386
|
Credentials,
|
|
369
387
|
MdbCollection,
|
|
370
388
|
MongoDBService,
|
|
371
|
-
|
|
372
|
-
ObjectId,
|
|
389
|
+
ObjectID,
|
|
390
|
+
ObjectId2 as ObjectId,
|
|
373
391
|
Revlm,
|
|
374
392
|
RevlmDBDatabase,
|
|
375
393
|
User
|