@asgardeo/javascript 0.2.17 → 0.4.0
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/api/v2/executeEmbeddedUserOnboardingFlowV2.d.ts +88 -0
- package/dist/cjs/index.js +54 -6
- package/dist/cjs/index.js.map +3 -3
- package/dist/index.d.ts +1 -0
- package/dist/index.js +53 -6
- package/dist/index.js.map +3 -3
- package/dist/models/embedded-flow.d.ts +2 -1
- package/dist/utils/extractUserClaimsFromIdToken.d.ts +7 -5
- package/package.json +1 -1
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
|
|
3
|
+
*
|
|
4
|
+
* WSO2 LLC. licenses this file to you under the Apache License,
|
|
5
|
+
* Version 2.0 (the "License"); you may not use this file except
|
|
6
|
+
* in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing,
|
|
12
|
+
* software distributed under the License is distributed on an
|
|
13
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
+
* KIND, either express or implied. See the License for the
|
|
15
|
+
* specific language governing permissions and limitations
|
|
16
|
+
* under the License.
|
|
17
|
+
*/
|
|
18
|
+
import { EmbeddedFlowExecuteRequestConfig as EmbeddedFlowExecuteRequestConfigV2 } from '../../models/v2/embedded-flow-v2';
|
|
19
|
+
/**
|
|
20
|
+
* Response from the user onboarding flow execution.
|
|
21
|
+
*/
|
|
22
|
+
export interface EmbeddedUserOnboardingFlowResponse {
|
|
23
|
+
/**
|
|
24
|
+
* Unique identifier for the flow execution.
|
|
25
|
+
*/
|
|
26
|
+
flowId: string;
|
|
27
|
+
/**
|
|
28
|
+
* Current status of the flow.
|
|
29
|
+
*/
|
|
30
|
+
flowStatus: 'INCOMPLETE' | 'COMPLETE' | 'ERROR';
|
|
31
|
+
/**
|
|
32
|
+
* Type of the current step in the flow.
|
|
33
|
+
*/
|
|
34
|
+
type?: 'VIEW' | 'REDIRECTION';
|
|
35
|
+
/**
|
|
36
|
+
* Data for the current step including components and additional data.
|
|
37
|
+
*/
|
|
38
|
+
data?: {
|
|
39
|
+
/**
|
|
40
|
+
* UI components to render for the current step.
|
|
41
|
+
*/
|
|
42
|
+
components?: any[];
|
|
43
|
+
/**
|
|
44
|
+
* Additional data from the flow step (e.g., inviteLink).
|
|
45
|
+
*/
|
|
46
|
+
additionalData?: Record<string, string>;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Reason for failure if flowStatus is ERROR.
|
|
50
|
+
*/
|
|
51
|
+
failureReason?: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Executes an embedded user onboarding flow by sending a request to the flow execution endpoint.
|
|
55
|
+
*
|
|
56
|
+
* This function handles both:
|
|
57
|
+
* - Admin flow: Initiates onboarding, collects user details, generates invite link
|
|
58
|
+
* - End-user flow: Validates invite token and allows password setting
|
|
59
|
+
*
|
|
60
|
+
* @param requestConfig - Request configuration object containing URL, payload, and optional auth token.
|
|
61
|
+
* @returns A promise that resolves with the flow execution response.
|
|
62
|
+
* @throws AsgardeoAPIError when the request fails or URL is invalid.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* // Admin initiating user onboarding (requires auth token)
|
|
67
|
+
* const response = await executeEmbeddedUserOnboardingFlowV2({
|
|
68
|
+
* baseUrl: "https://api.thunder.io",
|
|
69
|
+
* payload: {
|
|
70
|
+
* flowType: "USER_ONBOARDING"
|
|
71
|
+
* },
|
|
72
|
+
* headers: {
|
|
73
|
+
* Authorization: `Bearer ${accessToken}`
|
|
74
|
+
* }
|
|
75
|
+
* });
|
|
76
|
+
*
|
|
77
|
+
* // End-user accepting invite (no auth required)
|
|
78
|
+
* const response = await executeEmbeddedUserOnboardingFlowV2({
|
|
79
|
+
* baseUrl: "https://api.thunder.io",
|
|
80
|
+
* payload: {
|
|
81
|
+
* flowId: "flow-id-from-url",
|
|
82
|
+
* inputs: { inviteToken: "token-from-url" }
|
|
83
|
+
* }
|
|
84
|
+
* });
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
declare const executeEmbeddedUserOnboardingFlowV2: ({ url, baseUrl, payload, ...requestConfig }: EmbeddedFlowExecuteRequestConfigV2) => Promise<EmbeddedUserOnboardingFlowResponse>;
|
|
88
|
+
export default executeEmbeddedUserOnboardingFlowV2;
|
package/dist/cjs/index.js
CHANGED
|
@@ -75,6 +75,7 @@ __export(index_exports, {
|
|
|
75
75
|
executeEmbeddedSignInFlowV2: () => executeEmbeddedSignInFlowV2_default,
|
|
76
76
|
executeEmbeddedSignUpFlow: () => executeEmbeddedSignUpFlow_default,
|
|
77
77
|
executeEmbeddedSignUpFlowV2: () => executeEmbeddedSignUpFlowV2_default,
|
|
78
|
+
executeEmbeddedUserOnboardingFlowV2: () => executeEmbeddedUserOnboardingFlowV2_default,
|
|
78
79
|
extractPkceStorageKeyFromState: () => extractPkceStorageKeyFromState_default,
|
|
79
80
|
extractUserClaimsFromIdToken: () => extractUserClaimsFromIdToken_default,
|
|
80
81
|
flattenUserSchema: () => flattenUserSchema_default,
|
|
@@ -709,12 +710,7 @@ var extractUserClaimsFromIdToken = (payload) => {
|
|
|
709
710
|
protocolClaims.forEach((claim) => {
|
|
710
711
|
delete filteredPayload[claim];
|
|
711
712
|
});
|
|
712
|
-
|
|
713
|
-
Object.entries(filteredPayload).forEach(([key, value]) => {
|
|
714
|
-
const camelCasedKey = key.split("_").map((part, i) => i === 0 ? part : part[0].toUpperCase() + part.slice(1)).join("");
|
|
715
|
-
userClaims[camelCasedKey] = value;
|
|
716
|
-
});
|
|
717
|
-
return userClaims;
|
|
713
|
+
return filteredPayload;
|
|
718
714
|
};
|
|
719
715
|
var extractUserClaimsFromIdToken_default = extractUserClaimsFromIdToken;
|
|
720
716
|
|
|
@@ -2171,6 +2167,7 @@ var executeEmbeddedSignInFlow_default = executeEmbeddedSignInFlow;
|
|
|
2171
2167
|
var EmbeddedFlowType = /* @__PURE__ */ ((EmbeddedFlowType2) => {
|
|
2172
2168
|
EmbeddedFlowType2["Authentication"] = "AUTHENTICATION";
|
|
2173
2169
|
EmbeddedFlowType2["Registration"] = "REGISTRATION";
|
|
2170
|
+
EmbeddedFlowType2["UserOnboarding"] = "USER_ONBOARDING";
|
|
2174
2171
|
return EmbeddedFlowType2;
|
|
2175
2172
|
})(EmbeddedFlowType || {});
|
|
2176
2173
|
var EmbeddedFlowStatus = /* @__PURE__ */ ((EmbeddedFlowStatus2) => {
|
|
@@ -3176,6 +3173,56 @@ var executeEmbeddedSignUpFlowV2 = async ({
|
|
|
3176
3173
|
};
|
|
3177
3174
|
var executeEmbeddedSignUpFlowV2_default = executeEmbeddedSignUpFlowV2;
|
|
3178
3175
|
|
|
3176
|
+
// src/api/v2/executeEmbeddedUserOnboardingFlowV2.ts
|
|
3177
|
+
var executeEmbeddedUserOnboardingFlowV2 = async ({
|
|
3178
|
+
url,
|
|
3179
|
+
baseUrl,
|
|
3180
|
+
payload,
|
|
3181
|
+
...requestConfig
|
|
3182
|
+
}) => {
|
|
3183
|
+
if (!payload) {
|
|
3184
|
+
throw new AsgardeoAPIError(
|
|
3185
|
+
"User onboarding payload is required",
|
|
3186
|
+
"executeEmbeddedUserOnboardingFlow-ValidationError-002",
|
|
3187
|
+
"javascript",
|
|
3188
|
+
400,
|
|
3189
|
+
"If a user onboarding payload is not provided, the request cannot be constructed correctly."
|
|
3190
|
+
);
|
|
3191
|
+
}
|
|
3192
|
+
const endpoint = url ?? `${baseUrl}/flow/execute`;
|
|
3193
|
+
const cleanPayload = typeof payload === "object" && payload !== null ? Object.fromEntries(Object.entries(payload).filter(([key]) => key !== "verbose")) : payload;
|
|
3194
|
+
const hasOnlyFlowType = typeof cleanPayload === "object" && cleanPayload !== null && "flowType" in cleanPayload && Object.keys(cleanPayload).length === 1;
|
|
3195
|
+
const hasOnlyFlowId = typeof cleanPayload === "object" && cleanPayload !== null && "flowId" in cleanPayload && Object.keys(cleanPayload).length === 1;
|
|
3196
|
+
const hasFlowIdWithInputs = typeof cleanPayload === "object" && cleanPayload !== null && "flowId" in cleanPayload && "inputs" in cleanPayload;
|
|
3197
|
+
const requestPayload = hasOnlyFlowType || hasOnlyFlowId || hasFlowIdWithInputs ? { ...cleanPayload, verbose: true } : cleanPayload;
|
|
3198
|
+
if ("flowType" in requestPayload && requestPayload["flowType"] !== "USER_ONBOARDING" /* UserOnboarding */) {
|
|
3199
|
+
requestPayload["flowType"] = "USER_ONBOARDING" /* UserOnboarding */;
|
|
3200
|
+
}
|
|
3201
|
+
const response = await fetch(endpoint, {
|
|
3202
|
+
...requestConfig,
|
|
3203
|
+
method: requestConfig.method || "POST",
|
|
3204
|
+
headers: {
|
|
3205
|
+
"Content-Type": "application/json",
|
|
3206
|
+
Accept: "application/json",
|
|
3207
|
+
...requestConfig.headers
|
|
3208
|
+
},
|
|
3209
|
+
body: JSON.stringify(requestPayload)
|
|
3210
|
+
});
|
|
3211
|
+
if (!response.ok) {
|
|
3212
|
+
const errorText = await response.text();
|
|
3213
|
+
throw new AsgardeoAPIError(
|
|
3214
|
+
`User onboarding request failed: ${errorText}`,
|
|
3215
|
+
"executeEmbeddedUserOnboardingFlow-ResponseError-001",
|
|
3216
|
+
"javascript",
|
|
3217
|
+
response.status,
|
|
3218
|
+
response.statusText
|
|
3219
|
+
);
|
|
3220
|
+
}
|
|
3221
|
+
const flowResponse = await response.json();
|
|
3222
|
+
return flowResponse;
|
|
3223
|
+
};
|
|
3224
|
+
var executeEmbeddedUserOnboardingFlowV2_default = executeEmbeddedUserOnboardingFlowV2;
|
|
3225
|
+
|
|
3179
3226
|
// src/constants/ApplicationNativeAuthenticationConstants.ts
|
|
3180
3227
|
var ApplicationNativeAuthenticationConstants = {
|
|
3181
3228
|
SupportedAuthenticators: {
|
|
@@ -4833,6 +4880,7 @@ var transformBrandingPreferenceToTheme_default = transformBrandingPreferenceToTh
|
|
|
4833
4880
|
executeEmbeddedSignInFlowV2,
|
|
4834
4881
|
executeEmbeddedSignUpFlow,
|
|
4835
4882
|
executeEmbeddedSignUpFlowV2,
|
|
4883
|
+
executeEmbeddedUserOnboardingFlowV2,
|
|
4836
4884
|
extractPkceStorageKeyFromState,
|
|
4837
4885
|
extractUserClaimsFromIdToken,
|
|
4838
4886
|
flattenUserSchema,
|