/************************************************************************* * Copyright 2022 Adobe * All Rights Reserved. * * NOTICE: Adobe permits you to use, modify, and distribute this file in * accordance with the terms of the Adobe license agreement accompanying * it. If you have received this file from a source other than Adobe, * then your use, modification, or distribution of it requires the prior * written permission of Adobe. **************************************************************************/ import { CacheExpiry, CacheScope } from '../cache'; import { FetchScope, GraphQLQuery } from '../network'; /** * @packageDocumentation * @module network */ export declare const FRESH_MS: number; export declare enum StandardVariables { ACP_FD = "acpFulfillableData", APP_ID = "appId", CACHED_TS = "cached.createdAt", DEDUP_SF = "dedup.sortField" } /** * Defines the conditions when certain data can be fetched. * When conditions are not met, default data will be returned but not cached. */ export interface FetchCondition { /** * Service Codes that needs to be present (For the current org) in order to execute the query. * This is useful when a query only makes sense if a certain product is provisioned for the current user. */ serviceCodes?: string | string[]; } /** * Defines a GraphQL query that will be executed to fetch the data exposed by this contract. */ export interface QueryDefinition extends GraphQLQuery { /** * When provided, the data at the certain path will be returned. * If not provided, the entire GraphQL response will be returned. */ dataPath?: string; /** * Fetch scope. Controls which headers are sent with the query. * See fetch documentation for more info. */ fetchScope: FetchScope; /** * Do not fail (throw) when encountering errors while processing the query if the errors * happened on certain paths. */ ignoreErrorsOnPaths?: string[]; } export interface DataDedupConfig { /** * An array of elements that needs to be merged and deduped across fresh and cached data. */ arrayElement: string; /** * To avoid overflow when data is refreshed, limit the number of items in the array. * 0 = unlimited. */ arrayLimit: number; /** * A key that will be used to deduplicate the array element. */ keyField: string; /** * Sort direction - True for ascending, false for descending. */ sortAscending: boolean; /** * Field to sort the array by - Used to decide which items are old and can be chopped off. */ sortField: string; } /** * Defines a data contract which will be executed by Unified Shell on behalf ot the requesting application. */ export default interface DataPrefetchContract { /** * Default value to return if the data execution is skipped. */ defaultValue: T; /** * Cache expiry. Can be one of the set values defined by the Cache API, or a numeric cache ttl (in seconds). */ expiry: CacheExpiry; /** * Defines the conditions when certain data can be fetched. * When conditions are not met, the default value above will be returned (But not cached). */ fetchWhen?: FetchCondition; /** * GraphQL used to fulfill this data contract. * Note: Currently GraphQL is the only supported method for data contracts. */ gql?: QueryDefinition; /** * Is the data sensitive? (PII or other sensitive data). * Sensitive data can only be cached in the browser's session storage * Non-sensitive data can be cached in the standard Cache storage. */ isSensitive: boolean; /** * Unique key associated with this contract. * Will be used by the calling application to get access to the data. */ key: string; /** * Defines specific behavior for refresh. * This is optional, by default refreshing data and fetching new will yield the same results. */ refreshData?: { /** * Cached & Fresh Data deduplication and merge configuration. */ dedup?: DataDedupConfig; /** * GraphQL query to use for refresh. */ gql?: QueryDefinition; /** * An optional array of root level elements that need to be retained from the cached data. */ keepOriginal?: string[]; }; /** * When true, data will be fetched even when a cache is available. * In this case, the query will return the cached data and at the same time fetch fresh data from the network. * (stale-while-revalidate strategy) */ revalidate: { /** * When true, data will be fetched even when a cache is available. * In this case, the query will return the cached data and at the same time fetch fresh data from the network. * (stale-while-revalidate strategy) */ enabled: boolean; /** * If true, revalidation will be done right away * If false, revalidation will be done when the browser is idle * (On browsers where requestIdleCallback is supported, otherwise right away) * Optional - Defaults to false */ immediate?: boolean; /** * Used in conjunction with revalidate = true. Threshold for revalidating data from the network. * When set the query will return the cached data and if the cache is older than the set threshold, * fetch fresh data from the network. Optional - Defaults to 0 (immediate) */ revalidateAfterSec?: number; }; /** * Cache scope as defined by the Cache API. */ scope: CacheScope; /** * If true, this data will be accessible to all experience cloud applications. * Otherwise, data will be cached against the requesting application. */ shared: boolean; }