Class: VerifyTokenFetchStrategy
@headstartwp/core.VerifyTokenFetchStrategy
The Verify Token strategy is used to verify tokens issued by the headless wp plugin
Hierarchy
AbstractFetchStrategy
<AppEntity
,EndpointParams
,AppEntity
>↳
VerifyTokenFetchStrategy
Constructors
constructor
• new VerifyTokenFetchStrategy(baseURL?
, defaultParams?
)
The strategy constructor
Parameters
Name | Type | Description |
---|---|---|
baseURL? | string | The base URL of the API |
defaultParams? | Partial <EndpointParams > | (optional) list of default params |
Inherited from
AbstractFetchStrategy.constructor
Defined in
packages/core/src/data/strategies/AbstractFetchStrategy.ts:145
Properties
baseURL
• baseURL: string
= ''
The base URL where the API is located
Inherited from
Defined in
packages/core/src/data/strategies/AbstractFetchStrategy.ts:131
defaultParams
• defaultParams: Partial
<EndpointParams
> = {}
The Default Params
Inherited from
AbstractFetchStrategy.defaultParams
Defined in
packages/core/src/data/strategies/AbstractFetchStrategy.ts:121
endpoint
• endpoint: string
= ''
Holds the current endpoint for the strategy
Inherited from
AbstractFetchStrategy.endpoint
Defined in
packages/core/src/data/strategies/AbstractFetchStrategy.ts:126
Methods
buildEndpointURL
▸ buildEndpointURL(params
): string
Builds the final endpoint URL based on the passed parameters
Parameters
Name | Type | Description |
---|---|---|
params | Partial <VerifyTokenParams > | The params to add to the request |
Returns
string
The endpoint URL.
Overrides
AbstractFetchStrategy.buildEndpointURL
Defined in
packages/core/src/data/strategies/VerifyTokenFetchStrategy.ts:32
fetcher
▸ fetcher(url
, params
, options?
): Promise
<FetchResponse
<AppEntity
>>
The default fetcher function
The default fetcher function handles authentication headers and errors from the API.
A custom strategy can override this function to run additional logic before or after the fetch call
Parameters
Name | Type | Description |
---|---|---|
url | string | The URL to fetch |
params | VerifyTokenParams | The request params |
options | Partial <FetchOptions > | The fetcher options |
Returns
Promise
<FetchResponse
<AppEntity
>>
Overrides
Defined in
packages/core/src/data/strategies/VerifyTokenFetchStrategy.ts:39
filterData
▸ filterData(data
, filterOptions?
): FetchResponse
<AppEntity
>
Filters the data returned from the API by excluding fields that are not needed in order to reduce payload size.
Parameters
Name | Type | Description |
---|---|---|
data | FetchResponse <AppEntity > | The data to filter |
filterOptions? | FilterDataOptions <AppEntity > | Filter options |
Returns
The filtered data
Inherited from
AbstractFetchStrategy.filterData
Defined in
packages/core/src/data/strategies/AbstractFetchStrategy.ts:379
get
▸ get(params?
): Promise
<FetchResponse
<AppEntity
>>
This is a simple wrapper to quickly fetch data from the API given a set of params
Usage
import { PostsArchiveFetchStrategy } from '@headstartwp/core';
new PostsArchiveFetchStrategy('http://my-wp-url.com').get({perPage: 10});
Parameters
Name | Type | Description |
---|---|---|
params | Partial <EndpointParams > | The endpoint params |
Returns
Promise
<FetchResponse
<AppEntity
>>
Inherited from
Defined in
packages/core/src/data/strategies/AbstractFetchStrategy.ts:444
getAuthHeader
▸ getAuthHeader(options?
): string
Parameters
Name | Type |
---|---|
options | Partial <FetchOptions > |
Returns
string
Inherited from
AbstractFetchStrategy.getAuthHeader
Defined in
packages/core/src/data/strategies/AbstractFetchStrategy.ts:258
getCacheKey
▸ getCacheKey(params
): Object
Returns the cache key with both the endpoint and the sourceUrl to distinguish between multiple sites
Parameters
Name | Type | Description |
---|---|---|
params | Partial <EndpointParams > | The request params |
Returns
Object
The cache key object
Name | Type |
---|---|
args | Partial <EndpointParams > & { sourceUrl : string } |
url | string |
Inherited from
AbstractFetchStrategy.getCacheKey
Defined in
packages/core/src/data/strategies/AbstractFetchStrategy.ts:409
getDefaultEndpoint
▸ getDefaultEndpoint(): string
A method that must be implemented by concrete implementations which returns the default endpoint for the strategy
Returns
string
Overrides
AbstractFetchStrategy.getDefaultEndpoint
Defined in
packages/core/src/data/strategies/VerifyTokenFetchStrategy.ts:23
getDefaultParams
▸ getDefaultParams(): Partial
<EndpointParams
>
Returns
Partial
<EndpointParams
>
Inherited from
AbstractFetchStrategy.getDefaultParams
Defined in
packages/core/src/data/strategies/AbstractFetchStrategy.ts:184
getEndpoint
▸ getEndpoint(): string
Returns the endpoint of the strategy. If no endpoint has been set at runtime, returns the default endpoint
Returns
string
The current endpoint for the strategy
Inherited from
AbstractFetchStrategy.getEndpoint
Defined in
packages/core/src/data/strategies/AbstractFetchStrategy.ts:176
getParamsFromURL
▸ getParamsFromURL(path
, params?
): Partial
<EndpointParams
>
Returns the supported params from the URL if present.
These params are passed to buildEndpointURL
. If the strategy does not support
mapping url params to endpoint params, it should return an empty object.
Parameters
Name | Type | Description |
---|---|---|
path | string | The Path name |
params | Partial <EndpointParams > | The non-url params |
Returns
Partial
<EndpointParams
>
params extracted from the URL
Overrides
AbstractFetchStrategy.getParamsFromURL
Defined in
packages/core/src/data/strategies/VerifyTokenFetchStrategy.ts:28
getPreviewAuthHeader
▸ getPreviewAuthHeader(options?
): string
Parameters
Name | Type |
---|---|
options | Partial <FetchOptions > |
Returns
string
Inherited from
AbstractFetchStrategy.getPreviewAuthHeader
Defined in
packages/core/src/data/strategies/AbstractFetchStrategy.ts:249
getPreviewHeaderName
▸ getPreviewHeaderName(options?
): "X-HeadstartWP-Authorization"
| "Authorization"
Parameters
Name | Type |
---|---|
options | Partial <FetchOptions > |
Returns
"X-HeadstartWP-Authorization"
| "Authorization"
Inherited from
AbstractFetchStrategy.getPreviewHeaderName
Defined in
packages/core/src/data/strategies/AbstractFetchStrategy.ts:243
getQueriedObject
▸ getQueriedObject(response
, params
): Object
Parameters
Name | Type |
---|---|
response | FetchResponse <AppEntity > |
params | Partial <EndpointParams > |
Returns
Object
Inherited from
AbstractFetchStrategy.getQueriedObject
Defined in
packages/core/src/data/strategies/AbstractFetchStrategy.ts:367
isMainQuery
▸ isMainQuery(path
, nonUrlParams
): boolean
Checks if this is the main query for a page
Parameters
Name | Type | Description |
---|---|---|
path | string | The page name |
nonUrlParams | Partial <EndpointParams > | The non-url params |
Returns
boolean
Inherited from
AbstractFetchStrategy.isMainQuery
Defined in
packages/core/src/data/strategies/AbstractFetchStrategy.ts:207
normalizeForCache
▸ normalizeForCache(data
, params
): NormalizedDataForCache
<AppEntity
, EndpointParams
>
Normalize data for cache.
Parameters
Name | Type | Description |
---|---|---|
data | FetchResponse <AppEntity > | The fetch response data |
params | Partial <EndpointParams > | The request params |
Returns
NormalizedDataForCache
<AppEntity
, EndpointParams
>
Inherited from
AbstractFetchStrategy.normalizeForCache
Defined in
packages/core/src/data/strategies/AbstractFetchStrategy.ts:419
prepareResponse
▸ prepareResponse(response
, params
): FetchResponse
<AppEntity
>
Parameters
Name | Type |
---|---|
response | FetchResponse <AppEntity > |
params | Partial <EndpointParams > |
Returns
Inherited from
AbstractFetchStrategy.prepareResponse
Defined in
packages/core/src/data/strategies/AbstractFetchStrategy.ts:235
setBaseURL
▸ setBaseURL(url?
): void
Parameters
Name | Type | Default value |
---|---|---|
url | undefined | string | '' |
Returns
void
Inherited from
AbstractFetchStrategy.setBaseURL
Defined in
packages/core/src/data/strategies/AbstractFetchStrategy.ts:166
setEndpoint
▸ setEndpoint(endpoint
): void
The strategy can switch endpoints at runtime if needed.
E.g: The actual endpoint for a post depends on its post_type
Parameters
Name | Type | Description |
---|---|---|
endpoint | string | The endpoint to fetch |
Returns
void
Inherited from
AbstractFetchStrategy.setEndpoint
Defined in
packages/core/src/data/strategies/AbstractFetchStrategy.ts:162