react-native-efilli-sdk
Version:
Efilli SDK for React Native - Consent Management Solution
62 lines (61 loc) • 2.13 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConsentResult = void 0;
const Categories_1 = require("./Categories");
const ConsentAction_1 = require("../enums/ConsentAction");
/**
* ConsentResult model representing the outcome of a consent decision
*/
class ConsentResult {
/**
* Create a ConsentResult instance
* @param action - The action taken (from ConsentAction enum)
* @param data - The consent categories selections
*/
constructor(action, data = null) {
this.action = action;
this.data = data;
}
/**
* Create a ConsentResult instance from a plain object or JSON string
* @param data - Plain object or JSON string
* @returns New ConsentResult instance or null if invalid
*/
static fromJSON(data) {
var _a, _b;
if (typeof data === 'string') {
try {
data = JSON.parse(data);
}
catch (e) {
console.error('Failed to parse ConsentResult JSON:', e);
return null;
}
}
if (!data || typeof data !== 'object')
return null;
const typedData = data;
const actionValue = (_a = typedData.action) !== null && _a !== void 0 ? _a : typedData['type']; // fallback
if (!actionValue)
return null;
const action = (0, ConsentAction_1.fromConsentActionValue)(actionValue);
if (!action)
return null;
const categoriesData = (_b = typedData.data) !== null && _b !== void 0 ? _b : typedData; // fallback if only category fields exist
const categories = categoriesData && typeof categoriesData === 'object'
? Categories_1.Categories.fromJSON(categoriesData)
: null;
return new ConsentResult(action, categories);
}
/**
* Convert to a plain object
* @returns Plain object representation
*/
toJSON() {
return {
action: this.action,
data: this.data ? this.data.toJSON() : null
};
}
}
exports.ConsentResult = ConsentResult;
;