@velion-la/onboarding-sdk-react-native 1.4.0-beta.5 → 1.4.0-beta.6
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/CHANGELOG.md +10 -0
- package/README.md +2 -2
- package/lib/commonjs/core/VelionOnboarding.js +41 -1
- package/lib/commonjs/core/VelionOnboarding.js.map +1 -1
- package/lib/commonjs/transport/api.js +30 -2
- package/lib/commonjs/transport/api.js.map +1 -1
- package/lib/commonjs/types/index.js +3 -2
- package/lib/commonjs/types/index.js.map +1 -1
- package/lib/commonjs/utils/sdkVersion.js +1 -1
- package/lib/module/core/VelionOnboarding.js +41 -1
- package/lib/module/core/VelionOnboarding.js.map +1 -1
- package/lib/module/transport/api.js +30 -2
- package/lib/module/transport/api.js.map +1 -1
- package/lib/module/types/index.js +3 -2
- package/lib/module/types/index.js.map +1 -1
- package/lib/module/utils/sdkVersion.js +1 -1
- package/lib/typescript/core/VelionOnboarding.d.ts +11 -0
- package/lib/typescript/core/VelionOnboarding.d.ts.map +1 -1
- package/lib/typescript/transport/api.d.ts +10 -1
- package/lib/typescript/transport/api.d.ts.map +1 -1
- package/lib/typescript/types/index.d.ts +6 -3
- package/lib/typescript/types/index.d.ts.map +1 -1
- package/lib/typescript/utils/sdkVersion.d.ts +1 -1
- package/package.json +1 -1
- package/src/core/VelionOnboarding.ts +40 -0
- package/src/transport/api.ts +40 -0
- package/src/types/index.ts +6 -3
- package/src/utils/sdkVersion.ts +1 -1
|
@@ -17,6 +17,8 @@
|
|
|
17
17
|
* - SESSION_CANCELLED rides the same channel as SESSION_DECLINED (it can land
|
|
18
18
|
* mid-step too) but never triggers a GET: the backend revokes the session
|
|
19
19
|
* token with the cancellation, so the SDK closes SSE and stops calling out
|
|
20
|
+
* - A request rejected with the 401 `VOB-40103` (token revoked by that same
|
|
21
|
+
* cancellation, SSE event missed) ends the flow exactly like SESSION_CANCELLED
|
|
20
22
|
*/
|
|
21
23
|
|
|
22
24
|
import { TypedEventEmitter } from '../utils/EventEmitter';
|
|
@@ -174,6 +176,18 @@ function cancelledEventFromDto(): OnboardingSessionEvent {
|
|
|
174
176
|
return { event_type: 'SESSION_CANCELLED', session_status: 'CANCELLED' };
|
|
175
177
|
}
|
|
176
178
|
|
|
179
|
+
/**
|
|
180
|
+
* A request got the 401 `VOB-40103`: the same cancellation SSE would have
|
|
181
|
+
* announced, rebuilt with the reason the 401 body carries.
|
|
182
|
+
*/
|
|
183
|
+
function cancelledEventFromRevokedToken(reason: string | undefined): OnboardingSessionEvent {
|
|
184
|
+
return {
|
|
185
|
+
event_type: 'SESSION_CANCELLED',
|
|
186
|
+
session_status: 'CANCELLED',
|
|
187
|
+
...(reason !== undefined && { reason }),
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
|
|
177
191
|
function isSessionTokenAuthSdkError(err: unknown): err is SdkError {
|
|
178
192
|
return (
|
|
179
193
|
err != null &&
|
|
@@ -254,11 +268,16 @@ export class VelionOnboarding {
|
|
|
254
268
|
if (this.config.debug === true) setDebugEnabled(true);
|
|
255
269
|
let api: ApiCaller;
|
|
256
270
|
let constructionError: SdkError | null = null;
|
|
271
|
+
const hooks = {
|
|
272
|
+
onSessionCancelled: (reason: string | undefined) =>
|
|
273
|
+
this.endFlowWithRevokedToken(reason),
|
|
274
|
+
};
|
|
257
275
|
try {
|
|
258
276
|
api = createApiCaller(
|
|
259
277
|
apiUrl,
|
|
260
278
|
config.sessionToken,
|
|
261
279
|
config.expiresAt,
|
|
280
|
+
hooks,
|
|
262
281
|
);
|
|
263
282
|
} catch (err) {
|
|
264
283
|
constructionError = err as SdkError;
|
|
@@ -338,6 +357,9 @@ export class VelionOnboarding {
|
|
|
338
357
|
try {
|
|
339
358
|
await this.initialize();
|
|
340
359
|
} catch (err) {
|
|
360
|
+
// The flow already reported how it ended (e.g. a request that found the
|
|
361
|
+
// session cancelled); the rejection that unwinds here is not news.
|
|
362
|
+
if (this.sessionEnded) return;
|
|
341
363
|
this.emitError(err as SdkError);
|
|
342
364
|
}
|
|
343
365
|
}
|
|
@@ -941,6 +963,24 @@ export class VelionOnboarding {
|
|
|
941
963
|
this.emitError(err);
|
|
942
964
|
}
|
|
943
965
|
|
|
966
|
+
/**
|
|
967
|
+
* A request was rejected with the 401 `VOB-40103`: the backend cancelled the
|
|
968
|
+
* session and revoked its token, and the SSE event either never arrived or
|
|
969
|
+
* SSE was not open. Reported to the host exactly as SESSION_CANCELLED over
|
|
970
|
+
* SSE: `onSessionEvent` with the event, then `onError(SESSION_CANCELLED)` and
|
|
971
|
+
* the cancelled screen. Never `SESSION_EXPIRED`, so the host does not try to
|
|
972
|
+
* refresh a token that belongs to a closed session.
|
|
973
|
+
*/
|
|
974
|
+
private endFlowWithRevokedToken(reason: string | undefined): void {
|
|
975
|
+
if (this.sessionEnded || this.status === 'DESTROYED') return;
|
|
976
|
+
const event = cancelledEventFromRevokedToken(reason);
|
|
977
|
+
this.showLoading(null);
|
|
978
|
+
this.config.onSessionEvent?.(event);
|
|
979
|
+
this.endFlowWithSessionCancelled(event);
|
|
980
|
+
// Unwind a step that swallowed the rejection instead of leaving it pending.
|
|
981
|
+
this.sessionDeclineHandler?.(event);
|
|
982
|
+
}
|
|
983
|
+
|
|
944
984
|
/** Closes SSE and the API caller, and tears down the active step. */
|
|
945
985
|
private stopTalkingToBackend(): void {
|
|
946
986
|
this.api.close();
|
package/src/transport/api.ts
CHANGED
|
@@ -29,12 +29,32 @@ const SESSION_EXPIRED_CODE = SdkErrorCode.SESSION_EXPIRED;
|
|
|
29
29
|
/** Backend code for an app outside the organization's enforced allowed apps. */
|
|
30
30
|
const APP_ID_NOT_ALLOWED_BACKEND_CODE = 'VOB-40302';
|
|
31
31
|
|
|
32
|
+
/**
|
|
33
|
+
* Backend code of the 401 for a session token revoked because the backend
|
|
34
|
+
* cancelled the session (e.g. `WORKFLOW_VERSION_RETIRED`). Unlike an expired
|
|
35
|
+
* token, a new token does not help: the session itself is closed.
|
|
36
|
+
*/
|
|
37
|
+
const SESSION_CANCELLED_BACKEND_CODE = 'VOB-40103';
|
|
38
|
+
|
|
39
|
+
/** Error body: the legacy `{message, code}` shape or RFC 7807 problem+json. */
|
|
32
40
|
interface BackendErrorBody {
|
|
33
41
|
message?: string;
|
|
42
|
+
detail?: string;
|
|
34
43
|
code?: string;
|
|
44
|
+
reason?: string;
|
|
35
45
|
details?: unknown;
|
|
36
46
|
}
|
|
37
47
|
|
|
48
|
+
/** Hooks the orchestrator gives the API caller. */
|
|
49
|
+
export interface ApiCallerHooks {
|
|
50
|
+
/**
|
|
51
|
+
* Called once when a request is rejected with the 401 `VOB-40103`: the
|
|
52
|
+
* backend cancelled the session and revoked its token. The caller is already
|
|
53
|
+
* closed when it runs, and the request still rejects with `SESSION_CANCELLED`.
|
|
54
|
+
*/
|
|
55
|
+
onSessionCancelled?: (reason: string | undefined) => void;
|
|
56
|
+
}
|
|
57
|
+
|
|
38
58
|
function buildApiError(
|
|
39
59
|
message: string,
|
|
40
60
|
httpStatus?: number,
|
|
@@ -75,6 +95,7 @@ export function createApiCaller(
|
|
|
75
95
|
rawBaseUrl: string,
|
|
76
96
|
sessionToken: string,
|
|
77
97
|
expiresAt?: string,
|
|
98
|
+
hooks: ApiCallerHooks = {},
|
|
78
99
|
) {
|
|
79
100
|
if (!isSecureHttpUrl(rawBaseUrl)) {
|
|
80
101
|
throw {
|
|
@@ -188,6 +209,24 @@ export function createApiCaller(
|
|
|
188
209
|
// Body may not be JSON (e.g., a 502 from a proxy). That's fine.
|
|
189
210
|
}
|
|
190
211
|
|
|
212
|
+
if (
|
|
213
|
+
response.status === 401 &&
|
|
214
|
+
errorBody.code === SESSION_CANCELLED_BACKEND_CODE
|
|
215
|
+
) {
|
|
216
|
+
// Not an expired token: refreshing would only earn another 401, so
|
|
217
|
+
// close the caller and report the cancellation instead.
|
|
218
|
+
const alreadyClosed = closed;
|
|
219
|
+
closed = true;
|
|
220
|
+
if (!alreadyClosed) hooks.onSessionCancelled?.(errorBody.reason);
|
|
221
|
+
throw {
|
|
222
|
+
code: SdkErrorCode.SESSION_CANCELLED,
|
|
223
|
+
message: errorBody.detail ?? 'The onboarding session was cancelled.',
|
|
224
|
+
...(errorBody.reason !== undefined && { cancelReason: errorBody.reason }),
|
|
225
|
+
cause: errorBody,
|
|
226
|
+
httpStatus: response.status,
|
|
227
|
+
} satisfies SdkError;
|
|
228
|
+
}
|
|
229
|
+
|
|
191
230
|
if (errorBody.code === APP_ID_NOT_ALLOWED_BACKEND_CODE) {
|
|
192
231
|
throw {
|
|
193
232
|
code: SdkErrorCode.APP_NOT_ALLOWED,
|
|
@@ -201,6 +240,7 @@ export function createApiCaller(
|
|
|
201
240
|
|
|
202
241
|
throw buildApiError(
|
|
203
242
|
errorBody.message ??
|
|
243
|
+
errorBody.detail ??
|
|
204
244
|
`Backend returned ${response.status} on ${endpoint}.`,
|
|
205
245
|
response.status,
|
|
206
246
|
errorBody,
|
package/src/types/index.ts
CHANGED
|
@@ -300,8 +300,9 @@ export enum SdkErrorCode {
|
|
|
300
300
|
/** Backend sent SESSION_DECLINED over SSE; session ended before completion. */
|
|
301
301
|
SESSION_DECLINED = 'SESSION_DECLINED',
|
|
302
302
|
/**
|
|
303
|
-
* The backend cancelled the session (`SESSION_CANCELLED` over SSE,
|
|
304
|
-
* `status: CANCELLED` on `GET /sessions/:id
|
|
303
|
+
* The backend cancelled the session (`SESSION_CANCELLED` over SSE,
|
|
304
|
+
* `status: CANCELLED` on `GET /sessions/:id`, or a request rejected with the
|
|
305
|
+
* 401 `VOB-40103` for the token it revoked). Not a verdict on the person:
|
|
305
306
|
* the session was closed on Velion's side (e.g. `WORKFLOW_VERSION_RETIRED`
|
|
306
307
|
* when a new workflow version is published forcing it). The session token
|
|
307
308
|
* is revoked and the SDK sends no further requests; create a new session
|
|
@@ -700,7 +701,9 @@ export interface VelionConfig extends VelionCallbacks {
|
|
|
700
701
|
/**
|
|
701
702
|
* ISO-8601 expiry timestamp of the sessionToken. If provided, the SDK may
|
|
702
703
|
* check expiration before requests and emit SESSION_EXPIRED without a round-trip.
|
|
703
|
-
* When the backend returns 401/403, the SDK emits SESSION_EXPIRED anyway
|
|
704
|
+
* When the backend returns 401/403, the SDK emits SESSION_EXPIRED anyway,
|
|
705
|
+
* except for the 401 `VOB-40103` (session cancelled, token revoked), which
|
|
706
|
+
* ends the flow with SESSION_CANCELLED: a new token would not help.
|
|
704
707
|
*/
|
|
705
708
|
expiresAt?: string;
|
|
706
709
|
|
package/src/utils/sdkVersion.ts
CHANGED