@amityco/ts-sdk
Version:
Amity Social Cloud Typescript SDK
55 lines • 2.29 kB
TypeScript
/**
* Session-scoped singleton engine that manages TTL-based fetching and caching
* of blocked users. Provides a lazy `ensureFetched()` gate for the
* `getAllBlockedUsers()` API.
*
* Key behaviours:
* - `establish()` is a no-op — fetch is lazy, triggered only by consumer call
* - `destroy()` resets `lastFetchedAt` to null (ensures fresh fetch on next session)
* - `ensureFetched()` fetches from server only when cache is expired or never fetched
* - `lastFetchedAt` is only updated on successful fetch
* - `blockedUserIds` is kept in sync with each successful fetch
*
* @internal
*/
declare class BlockedUserSyncEngine {
/** Epoch ms of last successful fetch. null = never fetched in this session. */
private lastFetchedAt;
/** Ordered list of userId strings from the most recent successful fetch. */
private blockedUserIds;
/** No-op — fetch is lazy, triggered by consumer calling getAllBlockedUsers(). */
onSessionEstablished(): void;
/** Resets state so the next session starts with a cold cache. */
onSessionDestroyed(): void;
/** No-op for this engine. */
onTokenExpired(): void;
private isCacheExpired;
/**
* Ensures the local store is populated with fresh blocked-user data.
*
* - If the cache is still within the 5-minute TTL window: resolves immediately
* (no server call).
* - If the cache is expired (or never fetched): fetches from the server,
* persists the payload to the cache, and updates `lastFetchedAt`.
*
* On failure the error propagates to the caller and `lastFetchedAt` is NOT
* updated, so the next call will retry.
*/
ensureFetched(): Promise<void>;
/**
* Returns blocked {@link Amity.InternalUser} objects from the in-memory cache.
*
* Applies the spec-mandated filter:
* - Only users whose `isDeleted` is false or null
* - Hard limit of 100 results
*
* This always reads the latest local state, so changes made by `blockUser()`
* and `unblockUser()` are reflected even within the TTL window.
*/
getCachedUsers(): Amity.InternalUser[];
}
declare const _default: {
getInstance: () => BlockedUserSyncEngine;
};
export default _default;
//# sourceMappingURL=blockedUserSyncEngine.d.ts.map