@habit.analytics/habit-smartlink-reactcomponent
Version:
A React component for Habit SmartLink integration.
35 lines (34 loc) • 1.54 kB
JavaScript
;
/**
* @file types.ts
* @description Shared type system for iframe ↔ parent postMessage communication.
*
* Direction is documented per message type as: child → parent | parent → child | both
*/
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createSmartlinkMessage = exports.createRequestId = void 0;
/*==================================== REQUEST ID HELPER ===================================*/
/**
* Generates a unique requestId for correlating request/response message pairs.
* Used internally by useSmartlinkMessaging — not typically called directly.
*/
var createRequestId = function () {
return "req-".concat(Date.now(), "-").concat(Math.random().toString(36).substring(2, 9));
};
exports.createRequestId = createRequestId;
/*===================================== FACTORY HELPER =====================================*/
function createSmartlinkMessage(type, payload, requestId) {
return __assign(__assign({ type: type }, (payload !== undefined ? { payload: payload } : {})), (requestId !== undefined ? { requestId: requestId } : {}));
}
exports.createSmartlinkMessage = createSmartlinkMessage;