@kedaruma/revlm-client 1.0.45 → 1.0.46
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 +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +32 -5
- package/dist/index.mjs +32 -5
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -181,7 +181,6 @@ type RevlmOptions = {
|
|
|
181
181
|
provisionalAuthDomain?: string;
|
|
182
182
|
autoSetToken?: boolean;
|
|
183
183
|
autoRefreshOn401?: boolean;
|
|
184
|
-
strictRefreshCookie?: boolean;
|
|
185
184
|
};
|
|
186
185
|
type RevlmResponse<T = any> = {
|
|
187
186
|
ok: boolean;
|
|
@@ -201,7 +200,7 @@ declare class Revlm {
|
|
|
201
200
|
private provisionalAuthDomain;
|
|
202
201
|
private autoSetToken;
|
|
203
202
|
private autoRefreshOn401;
|
|
204
|
-
private
|
|
203
|
+
private cookieCheckPromise?;
|
|
205
204
|
constructor(baseUrl: string, opts?: RevlmOptions);
|
|
206
205
|
setToken(token: string): void;
|
|
207
206
|
getToken(): string | undefined;
|
|
@@ -213,6 +212,7 @@ declare class Revlm {
|
|
|
213
212
|
private parseResponse;
|
|
214
213
|
private request;
|
|
215
214
|
private shouldSkipAuthRetry;
|
|
215
|
+
private shouldSkipCookieCheck;
|
|
216
216
|
private signIfNeeded;
|
|
217
217
|
private requestWithRetry;
|
|
218
218
|
login(authId: string, password: string): Promise<LoginResponse>;
|
|
@@ -224,6 +224,7 @@ declare class Revlm {
|
|
|
224
224
|
}): Promise<RevlmResponse<any>>;
|
|
225
225
|
revlmGate(payload: any): Promise<RevlmResponse<any>>;
|
|
226
226
|
db(dbName: string): RevlmDBDatabase;
|
|
227
|
+
private ensureCookieSupport;
|
|
227
228
|
}
|
|
228
229
|
|
|
229
230
|
declare class MongoDBService {
|
package/dist/index.d.ts
CHANGED
|
@@ -181,7 +181,6 @@ type RevlmOptions = {
|
|
|
181
181
|
provisionalAuthDomain?: string;
|
|
182
182
|
autoSetToken?: boolean;
|
|
183
183
|
autoRefreshOn401?: boolean;
|
|
184
|
-
strictRefreshCookie?: boolean;
|
|
185
184
|
};
|
|
186
185
|
type RevlmResponse<T = any> = {
|
|
187
186
|
ok: boolean;
|
|
@@ -201,7 +200,7 @@ declare class Revlm {
|
|
|
201
200
|
private provisionalAuthDomain;
|
|
202
201
|
private autoSetToken;
|
|
203
202
|
private autoRefreshOn401;
|
|
204
|
-
private
|
|
203
|
+
private cookieCheckPromise?;
|
|
205
204
|
constructor(baseUrl: string, opts?: RevlmOptions);
|
|
206
205
|
setToken(token: string): void;
|
|
207
206
|
getToken(): string | undefined;
|
|
@@ -213,6 +212,7 @@ declare class Revlm {
|
|
|
213
212
|
private parseResponse;
|
|
214
213
|
private request;
|
|
215
214
|
private shouldSkipAuthRetry;
|
|
215
|
+
private shouldSkipCookieCheck;
|
|
216
216
|
private signIfNeeded;
|
|
217
217
|
private requestWithRetry;
|
|
218
218
|
login(authId: string, password: string): Promise<LoginResponse>;
|
|
@@ -224,6 +224,7 @@ declare class Revlm {
|
|
|
224
224
|
}): Promise<RevlmResponse<any>>;
|
|
225
225
|
revlmGate(payload: any): Promise<RevlmResponse<any>>;
|
|
226
226
|
db(dbName: string): RevlmDBDatabase;
|
|
227
|
+
private ensureCookieSupport;
|
|
227
228
|
}
|
|
228
229
|
|
|
229
230
|
declare class MongoDBService {
|
package/dist/index.js
CHANGED
|
@@ -156,7 +156,7 @@ var Revlm = class {
|
|
|
156
156
|
provisionalAuthDomain;
|
|
157
157
|
autoSetToken;
|
|
158
158
|
autoRefreshOn401;
|
|
159
|
-
|
|
159
|
+
cookieCheckPromise;
|
|
160
160
|
constructor(baseUrl, opts = {}) {
|
|
161
161
|
if (!baseUrl) throw new Error("baseUrl is required");
|
|
162
162
|
this.baseUrl = baseUrl.replace(/\/$/, "");
|
|
@@ -167,7 +167,6 @@ var Revlm = class {
|
|
|
167
167
|
this.provisionalAuthDomain = opts.provisionalAuthDomain || "";
|
|
168
168
|
this.autoSetToken = opts.autoSetToken ?? true;
|
|
169
169
|
this.autoRefreshOn401 = opts.autoRefreshOn401 || false;
|
|
170
|
-
this.strictRefreshCookie = opts.strictRefreshCookie || false;
|
|
171
170
|
if (!this.fetchImpl) {
|
|
172
171
|
throw new Error("No fetch implementation available. Provide fetchImpl in options or run in Node 18+ with global fetch.");
|
|
173
172
|
}
|
|
@@ -237,11 +236,18 @@ var Revlm = class {
|
|
|
237
236
|
const pathname = path.startsWith("http") ? new URL(path).pathname : path;
|
|
238
237
|
return pathname.includes("/login") || pathname.includes("/provisional-login") || pathname.includes("/refresh-token") || pathname.includes("/verify-token");
|
|
239
238
|
}
|
|
239
|
+
shouldSkipCookieCheck(path) {
|
|
240
|
+
const pathname = path.startsWith("http") ? new URL(path).pathname : path;
|
|
241
|
+
return pathname.includes("/cookie-check");
|
|
242
|
+
}
|
|
240
243
|
async signIfNeeded(_url, _method, headers, _body) {
|
|
241
244
|
return { signedUrl: _url, signedHeaders: headers };
|
|
242
245
|
}
|
|
243
246
|
async requestWithRetry(path, method = "POST", body, opts = { allowAuthRetry: false, retrying: false }) {
|
|
244
247
|
const { allowAuthRetry, retrying } = opts;
|
|
248
|
+
if (!this.shouldSkipCookieCheck(path)) {
|
|
249
|
+
await this.ensureCookieSupport();
|
|
250
|
+
}
|
|
245
251
|
const url = path.startsWith("http") ? path : `${this.baseUrl}${path.startsWith("/") ? "" : "/"}${path}`;
|
|
246
252
|
const hasBody = body !== void 0;
|
|
247
253
|
const headers = this.makeHeaders(hasBody);
|
|
@@ -270,9 +276,11 @@ var Revlm = class {
|
|
|
270
276
|
status: refreshRes.status,
|
|
271
277
|
error: refreshRes.error
|
|
272
278
|
});
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
279
|
+
if (refreshRes.reason === "no_refresh_secret") {
|
|
280
|
+
const missingError = new Error("Refresh cookie missing. Provide a cookie-aware fetch implementation for Node/RN.");
|
|
281
|
+
missingError.revlmReason = "no_refresh_secret";
|
|
282
|
+
throw missingError;
|
|
283
|
+
}
|
|
276
284
|
}
|
|
277
285
|
if (refreshRes && refreshRes.ok && refreshRes.token) {
|
|
278
286
|
return this.requestWithRetry(path, method, body, { allowAuthRetry: false, retrying: true });
|
|
@@ -280,6 +288,9 @@ var Revlm = class {
|
|
|
280
288
|
}
|
|
281
289
|
return out;
|
|
282
290
|
} catch (err) {
|
|
291
|
+
if (err && err.revlmReason === "no_refresh_secret") {
|
|
292
|
+
throw err;
|
|
293
|
+
}
|
|
283
294
|
return { ok: false, error: err?.message || String(err) };
|
|
284
295
|
}
|
|
285
296
|
}
|
|
@@ -295,6 +306,7 @@ var Revlm = class {
|
|
|
295
306
|
if (!this.provisionalEnabled) {
|
|
296
307
|
throw new Error("provisional login is disabled by client configuration");
|
|
297
308
|
}
|
|
309
|
+
await this.ensureCookieSupport();
|
|
298
310
|
if (!authId) throw new Error("authId is required");
|
|
299
311
|
const provisionalClient = new import_revlm_shared.AuthClient({ secretMaster: this.provisionalAuthSecretMaster, authDomain: this.provisionalAuthDomain });
|
|
300
312
|
const provisionalPassword = await provisionalClient.producePassword(String(Date.now() * 1e3));
|
|
@@ -321,6 +333,21 @@ var Revlm = class {
|
|
|
321
333
|
db(dbName) {
|
|
322
334
|
return new RevlmDBDatabase(dbName, this);
|
|
323
335
|
}
|
|
336
|
+
async ensureCookieSupport() {
|
|
337
|
+
if (this.cookieCheckPromise) return this.cookieCheckPromise;
|
|
338
|
+
this.cookieCheckPromise = (async () => {
|
|
339
|
+
const first = await this.requestWithRetry("/cookie-check", "POST", void 0, { allowAuthRetry: false, retrying: false });
|
|
340
|
+
if (first.ok) return;
|
|
341
|
+
if (first.reason !== "cookie_missing") {
|
|
342
|
+
throw new Error(`Cookie check failed: ${first.reason || first.error || "unknown_error"}`);
|
|
343
|
+
}
|
|
344
|
+
const second = await this.requestWithRetry("/cookie-check", "POST", void 0, { allowAuthRetry: false, retrying: false });
|
|
345
|
+
if (!second.ok) {
|
|
346
|
+
throw new Error("Cookie support missing. Provide a cookie-aware fetch implementation for Node/RN.");
|
|
347
|
+
}
|
|
348
|
+
})();
|
|
349
|
+
return this.cookieCheckPromise;
|
|
350
|
+
}
|
|
324
351
|
};
|
|
325
352
|
var MongoDBService = class {
|
|
326
353
|
_revlm;
|
package/dist/index.mjs
CHANGED
|
@@ -113,7 +113,7 @@ var Revlm = class {
|
|
|
113
113
|
provisionalAuthDomain;
|
|
114
114
|
autoSetToken;
|
|
115
115
|
autoRefreshOn401;
|
|
116
|
-
|
|
116
|
+
cookieCheckPromise;
|
|
117
117
|
constructor(baseUrl, opts = {}) {
|
|
118
118
|
if (!baseUrl) throw new Error("baseUrl is required");
|
|
119
119
|
this.baseUrl = baseUrl.replace(/\/$/, "");
|
|
@@ -124,7 +124,6 @@ var Revlm = class {
|
|
|
124
124
|
this.provisionalAuthDomain = opts.provisionalAuthDomain || "";
|
|
125
125
|
this.autoSetToken = opts.autoSetToken ?? true;
|
|
126
126
|
this.autoRefreshOn401 = opts.autoRefreshOn401 || false;
|
|
127
|
-
this.strictRefreshCookie = opts.strictRefreshCookie || false;
|
|
128
127
|
if (!this.fetchImpl) {
|
|
129
128
|
throw new Error("No fetch implementation available. Provide fetchImpl in options or run in Node 18+ with global fetch.");
|
|
130
129
|
}
|
|
@@ -194,11 +193,18 @@ var Revlm = class {
|
|
|
194
193
|
const pathname = path.startsWith("http") ? new URL(path).pathname : path;
|
|
195
194
|
return pathname.includes("/login") || pathname.includes("/provisional-login") || pathname.includes("/refresh-token") || pathname.includes("/verify-token");
|
|
196
195
|
}
|
|
196
|
+
shouldSkipCookieCheck(path) {
|
|
197
|
+
const pathname = path.startsWith("http") ? new URL(path).pathname : path;
|
|
198
|
+
return pathname.includes("/cookie-check");
|
|
199
|
+
}
|
|
197
200
|
async signIfNeeded(_url, _method, headers, _body) {
|
|
198
201
|
return { signedUrl: _url, signedHeaders: headers };
|
|
199
202
|
}
|
|
200
203
|
async requestWithRetry(path, method = "POST", body, opts = { allowAuthRetry: false, retrying: false }) {
|
|
201
204
|
const { allowAuthRetry, retrying } = opts;
|
|
205
|
+
if (!this.shouldSkipCookieCheck(path)) {
|
|
206
|
+
await this.ensureCookieSupport();
|
|
207
|
+
}
|
|
202
208
|
const url = path.startsWith("http") ? path : `${this.baseUrl}${path.startsWith("/") ? "" : "/"}${path}`;
|
|
203
209
|
const hasBody = body !== void 0;
|
|
204
210
|
const headers = this.makeHeaders(hasBody);
|
|
@@ -227,9 +233,11 @@ var Revlm = class {
|
|
|
227
233
|
status: refreshRes.status,
|
|
228
234
|
error: refreshRes.error
|
|
229
235
|
});
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
236
|
+
if (refreshRes.reason === "no_refresh_secret") {
|
|
237
|
+
const missingError = new Error("Refresh cookie missing. Provide a cookie-aware fetch implementation for Node/RN.");
|
|
238
|
+
missingError.revlmReason = "no_refresh_secret";
|
|
239
|
+
throw missingError;
|
|
240
|
+
}
|
|
233
241
|
}
|
|
234
242
|
if (refreshRes && refreshRes.ok && refreshRes.token) {
|
|
235
243
|
return this.requestWithRetry(path, method, body, { allowAuthRetry: false, retrying: true });
|
|
@@ -237,6 +245,9 @@ var Revlm = class {
|
|
|
237
245
|
}
|
|
238
246
|
return out;
|
|
239
247
|
} catch (err) {
|
|
248
|
+
if (err && err.revlmReason === "no_refresh_secret") {
|
|
249
|
+
throw err;
|
|
250
|
+
}
|
|
240
251
|
return { ok: false, error: err?.message || String(err) };
|
|
241
252
|
}
|
|
242
253
|
}
|
|
@@ -252,6 +263,7 @@ var Revlm = class {
|
|
|
252
263
|
if (!this.provisionalEnabled) {
|
|
253
264
|
throw new Error("provisional login is disabled by client configuration");
|
|
254
265
|
}
|
|
266
|
+
await this.ensureCookieSupport();
|
|
255
267
|
if (!authId) throw new Error("authId is required");
|
|
256
268
|
const provisionalClient = new AuthClient({ secretMaster: this.provisionalAuthSecretMaster, authDomain: this.provisionalAuthDomain });
|
|
257
269
|
const provisionalPassword = await provisionalClient.producePassword(String(Date.now() * 1e3));
|
|
@@ -278,6 +290,21 @@ var Revlm = class {
|
|
|
278
290
|
db(dbName) {
|
|
279
291
|
return new RevlmDBDatabase(dbName, this);
|
|
280
292
|
}
|
|
293
|
+
async ensureCookieSupport() {
|
|
294
|
+
if (this.cookieCheckPromise) return this.cookieCheckPromise;
|
|
295
|
+
this.cookieCheckPromise = (async () => {
|
|
296
|
+
const first = await this.requestWithRetry("/cookie-check", "POST", void 0, { allowAuthRetry: false, retrying: false });
|
|
297
|
+
if (first.ok) return;
|
|
298
|
+
if (first.reason !== "cookie_missing") {
|
|
299
|
+
throw new Error(`Cookie check failed: ${first.reason || first.error || "unknown_error"}`);
|
|
300
|
+
}
|
|
301
|
+
const second = await this.requestWithRetry("/cookie-check", "POST", void 0, { allowAuthRetry: false, retrying: false });
|
|
302
|
+
if (!second.ok) {
|
|
303
|
+
throw new Error("Cookie support missing. Provide a cookie-aware fetch implementation for Node/RN.");
|
|
304
|
+
}
|
|
305
|
+
})();
|
|
306
|
+
return this.cookieCheckPromise;
|
|
307
|
+
}
|
|
281
308
|
};
|
|
282
309
|
var MongoDBService = class {
|
|
283
310
|
_revlm;
|