@asgardeo/javascript
Version:
Framework agnostic JavaScript SDK for Asgardeo.
54 lines (53 loc) • 2.29 kB
TypeScript
/**
* Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { User } from '../models/user';
/**
* Generates a flattened user profile from a response object and schema definitions.
*
* This function processes user data according to schema specifications, creating
* a flat object with dot notation keys instead of nested objects. Multi-valued
* properties and type-specific defaults are handled appropriately.
*
* Additionally, any fields present in the response but not defined in the schema
* will be included to ensure no user data is lost during flattening.
*
* @param meResponse - The response object containing user data
* @param processedSchemas - Array of schema objects defining field properties
* @param processedSchemas[].name - The field name/path for the property
* @param processedSchemas[].type - The data type of the field (e.g., 'STRING')
* @param processedSchemas[].multiValued - Whether the field can contain multiple values
*
* @returns A flattened user profile object with dot notation keys
*
* @example
* ```typescript
* const schemas = [
* { name: 'name.givenName', type: 'STRING', multiValued: false },
* { name: 'emails', type: 'STRING', multiValued: true }
* ];
* const response = {
* name: { givenName: 'John' },
* emails: 'john@example.com',
* country: 'US' // This will be included even if not in schema
* };
* const profile = generateFlattenedUserProfile(response, schemas);
* // Result: { "name.givenName": 'John', emails: ['john@example.com'], country: 'US' }
* ```
*/
declare const generateFlattenedUserProfile: (meResponse: any, processedSchemas: any[]) => User;
export default generateFlattenedUserProfile;