-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathtypes.d.ts
175 lines (167 loc) · 6.25 KB
/
types.d.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/**
* AdobeStateCredentials
* @property namespace - the state store namespace
* @property apikey - the state store api key
* @property region - the region for the Adobe State Store. defaults to 'amer'
*/
export type AdobeStateCredentials = {
namespace: string;
apikey: string;
region: 'amer' | 'apac' | 'emea';
};
/**
* AdobeState put options
* @property ttl - Time-To-Live for key-value pair in seconds. When not
* defined or set to 0, defaults to 24 hours (86400s). Max TTL is one year
* (31536000s), `require('@adobe/aio-lib-state').MAX_TTL`. A TTL of 0 defaults
* to 24 hours.
*/
export type AdobeStatePutOptions = {
ttl: number;
};
/**
* AdobeState get return object
* @property expiration - the ISO-8601 date string of the expiration time for the key-value pair
* @property value - the value set by put
*/
export type AdobeStateGetReturnValue = {
expiration: string;
value: string;
};
/**
* Cloud State Management
*/
export class AdobeState {
/**
* Gets the regional endpoint for an endpoint.
* @param endpoint - the endpoint to test
* @param region - the region to set
* @returns the endpoint, with the correct region
*/
getRegionalEndpoint(endpoint: string, region: string): string;
/**
* Retrieves the state value for given key.
* If the key doesn't exist returns undefined.
* @param key - state key identifier
* @returns get response holding value and additional info
*/
get(key: string): Promise<AdobeStateGetReturnValue>;
/**
* Creates or updates a state key-value pair
* @param key - state key identifier
* @param value - state value
* @param [options] - put options
* @returns key
*/
put(key: string, value: string, options?: AdobeStatePutOptions): Promise<string>;
/**
* Deletes a state key-value pair
* @param key - state key identifier
* @returns key of deleted state or `null` if state does not exist
*/
delete(key: string): Promise<string | null>;
/**
* Deletes multiple key-values. The match option is required as a safeguard.
* CAUTION: use `{ match: '*' }` to delete all key-values.
* @example
* await state.deleteAll({ match: 'abc*' })
* @param options - deleteAll options.
* @param options.match - REQUIRED, a glob pattern to specify which keys to delete.
* @returns returns an object with the number of deleted keys.
*/
deleteAll(options: {
match: string;
}): Promise<{ keys: number; }>;
/**
* There exists key-values in the region.
* @returns true if exists, false if not
*/
any(): Promise<boolean>;
/**
* Get stats.
* @returns State container stats.
*/
stats(): Promise<{ bytesKeys: number; bytesValues: number; keys: number; }>;
/**
* List keys, returns an iterator. Every iteration returns a batch of
* approximately `countHint` keys.
* @example
* for await (const { keys } of state.list({ match: 'abc*' })) {
* console.log(keys)
* }
* @param options - list options
* @param options.match - a glob pattern that supports '*' to filter
* keys.
* @param options.countHint - an approximate number on how many items
* to return per iteration. Default: 100, min: 10, max: 1000.
* @returns an async generator which yields a
* { keys } object at every iteration.
*/
list(options: {
match: string;
countHint: number;
}): AsyncGenerator<{ keys: string[]; }>;
}
/**
* @property message - The message for the Error
* @property code - The code for the Error
* @property sdk - The SDK associated with the Error
* @property sdkDetails - The SDK details associated with the Error
*/
export type AdobeStateLibError = {
message: string;
code: string;
sdk: string;
sdkDetails: any;
};
/**
* Adobe State lib custom errors.
* `e.sdkDetails` provides additional context for each error (e.g. function parameter)
* @property ERROR_BAD_ARGUMENT - this error is thrown when an argument is missing, has invalid type, or includes invalid characters.
* @property ERROR_BAD_REQUEST - this error is thrown when an argument has an illegal value.
* @property ERROR_PAYLOAD_TOO_LARGE - this error is thrown when the state key, state value or underlying request payload size
* exceeds the specified limitations.
* @property ERROR_BAD_CREDENTIALS - this error is thrown when the supplied init credentials are invalid.
* @property ERROR_UNAUTHORIZED - this error is thrown when the credentials are unauthorized to access the resource
* @property ERROR_INTERNAL - this error is thrown when an unknown error is thrown by the underlying
* DB provider or TVM server for credential exchange. More details can be found in `e.sdkDetails._internal`.
* @property ERROR_REQUEST_RATE_TOO_HIGH - this error is thrown when the request rate for accessing state is too high.
*/
export type AdobeStateLibErrors = {
ERROR_BAD_ARGUMENT: AdobeStateLibError;
ERROR_BAD_REQUEST: AdobeStateLibError;
ERROR_PAYLOAD_TOO_LARGE: AdobeStateLibError;
ERROR_BAD_CREDENTIALS: AdobeStateLibError;
ERROR_UNAUTHORIZED: AdobeStateLibError;
ERROR_INTERNAL: AdobeStateLibError;
ERROR_REQUEST_RATE_TOO_HIGH: AdobeStateLibError;
};
/**
* An object holding the OpenWhisk credentials
* @property namespace - user namespace
* @property auth - auth key
*/
export type OpenWhiskCredentials = {
namespace: string;
auth: string;
};
/**
* Initializes and returns the key-value-store SDK.
*
* To use the SDK you must either provide your
* [OpenWhisk credentials]{@link OpenWhiskCredentials} in
* `config.ow` or your own
*
* OpenWhisk credentials can also be read from environment variables `__OW_NAMESPACE` and `__OW_API_KEY`.
* @param [config] - used to init the sdk
* @param [config.ow] - {@link OpenWhiskCredentials}. Set those if you want
* to use ootb credentials to access the state management service. OpenWhisk
* namespace and auth can also be passed through environment variables:
* `__OW_NAMESPACE` and `__OW_API_KEY`
* @param [config.region] - optional region to use, accepted values: `amer` (default), `emea`
* @returns An AdobeState instance
*/
export function init(config?: {
ow?: OpenWhiskCredentials;
region?: string;
}): Promise<AdobeState>;