@zoreal/oauth2-js 0.1.18 → 0.1.19
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.cjs +26 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -6
- package/dist/index.d.ts +1 -6
- package/dist/index.js +26 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -310,7 +310,7 @@ declare function mountPairingModal(state: PairingState, options: PairingModalOpt
|
|
|
310
310
|
* auth-code mode leaves it to the RP backend.
|
|
311
311
|
*/
|
|
312
312
|
declare const WIRE_VERSION = 1;
|
|
313
|
-
declare const SDK_VERSION = "0.1.
|
|
313
|
+
declare const SDK_VERSION = "0.1.19";
|
|
314
314
|
declare const SDK_NAME = "@zoreal/oauth2-js";
|
|
315
315
|
declare const DEFAULT_ISSUER = "https://id.zoreal.com";
|
|
316
316
|
/** Pending TTL is short. Poll gently; over-polling cancels the request. */
|
|
@@ -413,11 +413,6 @@ interface StartPairingParams {
|
|
|
413
413
|
display?: PairDisplay;
|
|
414
414
|
}
|
|
415
415
|
declare function startPairing(issuer: string, params: StartPairingParams, signal?: AbortSignal): Promise<PairStartResponse>;
|
|
416
|
-
/**
|
|
417
|
-
* Polls until the request resolves. Returns the authorization code.
|
|
418
|
-
* Throws FlowAbandonedError for the human outcomes (denied, expired,
|
|
419
|
-
* enrolment abandoned) and OAuthFlowError for protocol ones.
|
|
420
|
-
*/
|
|
421
416
|
declare function pollUntilApproved(issuer: string, requestId: string, onState?: (state: PairingState) => void, signal?: AbortSignal, options?: {
|
|
422
417
|
/**
|
|
423
418
|
* Same-device navigation only. The page starts polling while the
|
package/dist/index.d.ts
CHANGED
|
@@ -310,7 +310,7 @@ declare function mountPairingModal(state: PairingState, options: PairingModalOpt
|
|
|
310
310
|
* auth-code mode leaves it to the RP backend.
|
|
311
311
|
*/
|
|
312
312
|
declare const WIRE_VERSION = 1;
|
|
313
|
-
declare const SDK_VERSION = "0.1.
|
|
313
|
+
declare const SDK_VERSION = "0.1.19";
|
|
314
314
|
declare const SDK_NAME = "@zoreal/oauth2-js";
|
|
315
315
|
declare const DEFAULT_ISSUER = "https://id.zoreal.com";
|
|
316
316
|
/** Pending TTL is short. Poll gently; over-polling cancels the request. */
|
|
@@ -413,11 +413,6 @@ interface StartPairingParams {
|
|
|
413
413
|
display?: PairDisplay;
|
|
414
414
|
}
|
|
415
415
|
declare function startPairing(issuer: string, params: StartPairingParams, signal?: AbortSignal): Promise<PairStartResponse>;
|
|
416
|
-
/**
|
|
417
|
-
* Polls until the request resolves. Returns the authorization code.
|
|
418
|
-
* Throws FlowAbandonedError for the human outcomes (denied, expired,
|
|
419
|
-
* enrolment abandoned) and OAuthFlowError for protocol ones.
|
|
420
|
-
*/
|
|
421
416
|
declare function pollUntilApproved(issuer: string, requestId: string, onState?: (state: PairingState) => void, signal?: AbortSignal, options?: {
|
|
422
417
|
/**
|
|
423
418
|
* Same-device navigation only. The page starts polling while the
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ function unsafeClaims(idToken) {
|
|
|
14
14
|
|
|
15
15
|
// src/wire.ts
|
|
16
16
|
var WIRE_VERSION = 1;
|
|
17
|
-
var SDK_VERSION = "0.1.
|
|
17
|
+
var SDK_VERSION = "0.1.19";
|
|
18
18
|
var SDK_NAME = "@zoreal/oauth2-js";
|
|
19
19
|
var DEFAULT_ISSUER = "https://id.zoreal.com";
|
|
20
20
|
var POLL_INTERVAL_MS = 2e3;
|
|
@@ -92,11 +92,30 @@ var sleep = (ms, signal) => new Promise((resolve, reject) => {
|
|
|
92
92
|
}, ms);
|
|
93
93
|
signal?.addEventListener("abort", onAbort, { once: true });
|
|
94
94
|
});
|
|
95
|
+
var SETTLE_MS = 1500;
|
|
96
|
+
var NETWORK_FAILURES_TOLERATED = 4;
|
|
95
97
|
async function pollUntilApproved(issuer, requestId, onState, signal, options = {}) {
|
|
98
|
+
const settlingUntil = options.tolerateUnknownUntil ?? 0;
|
|
99
|
+
let networkFailures = 0;
|
|
100
|
+
let last = { status: "pending" };
|
|
101
|
+
if (settlingUntil > Date.now()) await sleep(SETTLE_MS, signal);
|
|
96
102
|
for (; ; ) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
103
|
+
let response;
|
|
104
|
+
try {
|
|
105
|
+
response = await fetch(`${issuer}/pair/${encodeURIComponent(requestId)}/status`, {
|
|
106
|
+
signal
|
|
107
|
+
});
|
|
108
|
+
networkFailures = 0;
|
|
109
|
+
} catch (e) {
|
|
110
|
+
if (e instanceof DOMException && e.name === "AbortError") throw e;
|
|
111
|
+
networkFailures += 1;
|
|
112
|
+
if (settlingUntil > Date.now() || networkFailures <= NETWORK_FAILURES_TOLERATED) {
|
|
113
|
+
onState?.(last);
|
|
114
|
+
await sleep(POLL_INTERVAL_MS, signal);
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
throw e;
|
|
118
|
+
}
|
|
100
119
|
const body = await parseJson(response);
|
|
101
120
|
if (response.status === 404 && (options.tolerateUnknownUntil ?? 0) > Date.now()) {
|
|
102
121
|
onState?.({ status: "pending" });
|
|
@@ -109,11 +128,12 @@ async function pollUntilApproved(issuer, requestId, onState, signal, options = {
|
|
|
109
128
|
body.error_description ?? `Pairing status failed (${response.status})`
|
|
110
129
|
);
|
|
111
130
|
}
|
|
112
|
-
|
|
131
|
+
last = {
|
|
113
132
|
status: body.status,
|
|
114
133
|
expiresIn: body.expires_in,
|
|
115
134
|
enrolmentDeadline: body.enrolment_deadline
|
|
116
|
-
}
|
|
135
|
+
};
|
|
136
|
+
onState?.(last);
|
|
117
137
|
switch (body.status) {
|
|
118
138
|
case "approved":
|
|
119
139
|
if (!body.code) {
|