getCustomerInfo method
Refreshes customer information from the backend that owns the session.
Implementation
@override
Future<InappifySdkResult<CustomerInfo>> getCustomerInfo(
InappifyRefreshRequest request,
) async {
final cancellation = request.cancellation;
if (cancellation?.isCancelled ?? false) {
return _cancelled<CustomerInfo>('getCustomerInfo');
}
return _run<CustomerInfo>(
'getCustomerInfo',
action: () async {
final identityRevision = _identityRevision;
final mirrorRevision = _customerMirrorRevision;
final policy =
request.fetchPolicy ??
(request.force
? InappifyCacheFetchPolicy.fetchCurrent
: InappifyCacheFetchPolicy.cachedOrFetched);
final readRevision = policy == InappifyCacheFetchPolicy.cacheOnly
? _customerReadRevision
: ++_customerReadRevision;
try {
final raw = await _bridge.call(
'getCustomerInfo',
positionalArguments: <Object?>[
_customerFetchPolicy(policy),
const <String, Object?>{},
],
cancellation: cancellation,
injectAbortSignal: cancellation != null,
);
final customer = InappifyWebPayloadCodec.customerInfo(raw);
if (identityRevision != _identityRevision ||
(policy != InappifyCacheFetchPolicy.cacheOnly &&
readRevision != _customerReadRevision)) {
throw const InappifyWebBridgeException(
code: 'CUSTOMER_INFO_REQUEST_SUPERSEDED',
kind: 'configuration',
);
}
// An event may have published a newer background result before the
// cached Promise crossed the bridge. Keep that newer mirror.
if (mirrorRevision == _customerMirrorRevision) {
_customerInfo = customer;
_customerMirrorRevision += 1;
}
_failedToLoadCustomerInfo = false;
return customer;
} catch (_) {
if (identityRevision == _identityRevision &&
readRevision == _customerReadRevision) {
_failedToLoadCustomerInfo = true;
}
rethrow;
}
},
cancellation: cancellation,
);
}