@kedaruma/revlm-client 1.0.44 → 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 +38 -4
- package/dist/index.mjs +38 -4
- 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);
|
|
@@ -264,8 +270,17 @@ var Revlm = class {
|
|
|
264
270
|
}
|
|
265
271
|
if (allowAuthRetry && !retrying && res.status === 401 && !this.shouldSkipAuthRetry(path)) {
|
|
266
272
|
const refreshRes = await this.refreshToken();
|
|
267
|
-
if (
|
|
268
|
-
|
|
273
|
+
if (!refreshRes.ok) {
|
|
274
|
+
console.warn("### refresh failed:", {
|
|
275
|
+
reason: refreshRes.reason,
|
|
276
|
+
status: refreshRes.status,
|
|
277
|
+
error: refreshRes.error
|
|
278
|
+
});
|
|
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
|
+
}
|
|
269
284
|
}
|
|
270
285
|
if (refreshRes && refreshRes.ok && refreshRes.token) {
|
|
271
286
|
return this.requestWithRetry(path, method, body, { allowAuthRetry: false, retrying: true });
|
|
@@ -273,6 +288,9 @@ var Revlm = class {
|
|
|
273
288
|
}
|
|
274
289
|
return out;
|
|
275
290
|
} catch (err) {
|
|
291
|
+
if (err && err.revlmReason === "no_refresh_secret") {
|
|
292
|
+
throw err;
|
|
293
|
+
}
|
|
276
294
|
return { ok: false, error: err?.message || String(err) };
|
|
277
295
|
}
|
|
278
296
|
}
|
|
@@ -288,6 +306,7 @@ var Revlm = class {
|
|
|
288
306
|
if (!this.provisionalEnabled) {
|
|
289
307
|
throw new Error("provisional login is disabled by client configuration");
|
|
290
308
|
}
|
|
309
|
+
await this.ensureCookieSupport();
|
|
291
310
|
if (!authId) throw new Error("authId is required");
|
|
292
311
|
const provisionalClient = new import_revlm_shared.AuthClient({ secretMaster: this.provisionalAuthSecretMaster, authDomain: this.provisionalAuthDomain });
|
|
293
312
|
const provisionalPassword = await provisionalClient.producePassword(String(Date.now() * 1e3));
|
|
@@ -314,6 +333,21 @@ var Revlm = class {
|
|
|
314
333
|
db(dbName) {
|
|
315
334
|
return new RevlmDBDatabase(dbName, this);
|
|
316
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
|
+
}
|
|
317
351
|
};
|
|
318
352
|
var MongoDBService = class {
|
|
319
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);
|
|
@@ -221,8 +227,17 @@ var Revlm = class {
|
|
|
221
227
|
}
|
|
222
228
|
if (allowAuthRetry && !retrying && res.status === 401 && !this.shouldSkipAuthRetry(path)) {
|
|
223
229
|
const refreshRes = await this.refreshToken();
|
|
224
|
-
if (
|
|
225
|
-
|
|
230
|
+
if (!refreshRes.ok) {
|
|
231
|
+
console.warn("### refresh failed:", {
|
|
232
|
+
reason: refreshRes.reason,
|
|
233
|
+
status: refreshRes.status,
|
|
234
|
+
error: refreshRes.error
|
|
235
|
+
});
|
|
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
|
+
}
|
|
226
241
|
}
|
|
227
242
|
if (refreshRes && refreshRes.ok && refreshRes.token) {
|
|
228
243
|
return this.requestWithRetry(path, method, body, { allowAuthRetry: false, retrying: true });
|
|
@@ -230,6 +245,9 @@ var Revlm = class {
|
|
|
230
245
|
}
|
|
231
246
|
return out;
|
|
232
247
|
} catch (err) {
|
|
248
|
+
if (err && err.revlmReason === "no_refresh_secret") {
|
|
249
|
+
throw err;
|
|
250
|
+
}
|
|
233
251
|
return { ok: false, error: err?.message || String(err) };
|
|
234
252
|
}
|
|
235
253
|
}
|
|
@@ -245,6 +263,7 @@ var Revlm = class {
|
|
|
245
263
|
if (!this.provisionalEnabled) {
|
|
246
264
|
throw new Error("provisional login is disabled by client configuration");
|
|
247
265
|
}
|
|
266
|
+
await this.ensureCookieSupport();
|
|
248
267
|
if (!authId) throw new Error("authId is required");
|
|
249
268
|
const provisionalClient = new AuthClient({ secretMaster: this.provisionalAuthSecretMaster, authDomain: this.provisionalAuthDomain });
|
|
250
269
|
const provisionalPassword = await provisionalClient.producePassword(String(Date.now() * 1e3));
|
|
@@ -271,6 +290,21 @@ var Revlm = class {
|
|
|
271
290
|
db(dbName) {
|
|
272
291
|
return new RevlmDBDatabase(dbName, this);
|
|
273
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
|
+
}
|
|
274
308
|
};
|
|
275
309
|
var MongoDBService = class {
|
|
276
310
|
_revlm;
|