35 lines
1.4 KiB
JavaScript
35 lines
1.4 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.syncEntitlement = void 0;
|
|
const https_1 = require("firebase-functions/v2/https");
|
|
const entitlementLogic_1 = require("./entitlementLogic");
|
|
const log_1 = require("../log");
|
|
/**
|
|
* Callable function that forces a re-sync of entitlements for the
|
|
* authenticated caller.
|
|
*
|
|
* Request body: { } (auth context supplies uid)
|
|
* Response: EntitlementState
|
|
*
|
|
* The client can invoke this after a purchase/restore or when local
|
|
* entitlement state appears stale. In production this should fetch the
|
|
* latest entitlement state from RevenueCat; for now it computes the
|
|
* state from the existing Firestore document and rewrites it, ensuring
|
|
* consistent field shapes.
|
|
*/
|
|
exports.syncEntitlement = (0, https_1.onCall)(async (request) => {
|
|
var _a;
|
|
if (!((_a = request.auth) === null || _a === void 0 ? void 0 : _a.uid)) {
|
|
throw new https_1.HttpsError('unauthenticated', 'Caller must be authenticated.');
|
|
}
|
|
const userId = request.auth.uid;
|
|
try {
|
|
const state = await (0, entitlementLogic_1.applyEntitlementSync)(userId);
|
|
return state;
|
|
}
|
|
catch (err) {
|
|
log_1.logger.error('[syncEntitlement] failed', { error: String(err) });
|
|
throw new https_1.HttpsError('internal', 'Entitlement sync failed.');
|
|
}
|
|
});
|
|
//# sourceMappingURL=syncEntitlement.js.map
|