-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
82 lines (73 loc) · 1.67 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/* eslint-disable max-classes-per-file */
import type { CXExperience, Logger } from '@atamaco/cx-core';
export class AtamaFetcherError extends Error {
constructor(private readonly statusCode: number) {
super(
[
{
status: 401,
message: 'unauthorized',
},
{
status: 404,
message: 'not_found',
},
].find((config) => config.status === statusCode)?.message ||
'internal_server_error',
);
Object.setPrototypeOf(this, AtamaFetcherError.prototype);
}
get status() {
return this.statusCode;
}
}
/**
* Abstract class for a fetcher to implement fetching channel experiences
*/
export abstract class Fetcher<C> {
/**
* The configuration for the Fetcher
*/
config: C;
/**
* The logger to use for logging
*/
logger?: Logger;
/**
* Initialize the fetcher
* @param config The configuration for the Fetcher
*/
constructor(config: C, logger?: Logger) {
this.config = config;
this.logger = logger;
}
/**
* Gets the data from a remote location and returns it
* @param identifier The identifier to use for fetching data
*/
abstract getData<T>(identifier: string): Promise<CXExperience<T>>;
/**
* Get all paths that can be loaded as a page
*/
abstract getAllPaths({
excludedPaths,
includedDirectories,
excludedDirectories,
}: {
excludedPaths?: string[];
includedDirectories?: string[];
excludedDirectories?: string[];
}): Promise<string[]>;
/**
* Run an action
*/
abstract action<T, R>({
actionId,
slug,
input,
}: {
actionId: string;
slug: string;
input: T;
}): Promise<R>;
}