go-mokapi 0.30.0 → 0.30.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
package/types/http.d.ts
CHANGED
|
@@ -86,11 +86,83 @@ export function del(url: string, body?: JSONValue, args?: Args): Response;
|
|
|
86
86
|
*/
|
|
87
87
|
export function options(url: string, body?: JSONValue, args?: Args): Response;
|
|
88
88
|
|
|
89
|
-
|
|
89
|
+
/**
|
|
90
|
+
* Sends an HTTP request and returns a Promise resolving to the response.
|
|
91
|
+
*
|
|
92
|
+
* @param {string} url - The URL to request.
|
|
93
|
+
* @param {FetchOptions} opts - Optional fetch configuration.
|
|
94
|
+
* @returns {Promise<Response>} A Promise that resolves with the response.
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* // Simple GET request
|
|
98
|
+
* const res = await fetch('https://foo.bar/api');
|
|
99
|
+
* const data = await res.json();
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* // POST request with JSON body
|
|
103
|
+
* const res = await fetch('https://foo.bar/api', {
|
|
104
|
+
* method: 'POST',
|
|
105
|
+
* headers: { 'Content-Type': 'application/json' },
|
|
106
|
+
* body: { name: 'Alice' }
|
|
107
|
+
* });
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* // Request with timeout and redirect settings
|
|
111
|
+
* const res = await fetch('https://foo.bar/api', {
|
|
112
|
+
* timeout: '5s',
|
|
113
|
+
* maxRedirects: 2
|
|
114
|
+
* });
|
|
115
|
+
*/
|
|
116
|
+
export function fetch(url: string, opts?: FetchOptions): Promise<Response>
|
|
90
117
|
|
|
118
|
+
/**
|
|
119
|
+
* Options for the {@link fetch} function.
|
|
120
|
+
*/
|
|
91
121
|
export interface FetchOptions {
|
|
92
|
-
|
|
93
|
-
|
|
122
|
+
/**
|
|
123
|
+
* HTTP method to use for the request.
|
|
124
|
+
* @default "GET"
|
|
125
|
+
* @example
|
|
126
|
+
* const res = await fetch(url, { method: 'POST' });
|
|
127
|
+
*/
|
|
128
|
+
method?: string;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* The body of the request, such as a string or object.
|
|
132
|
+
* @example
|
|
133
|
+
* const res = await fetch(url, { body: JSON.stringify({ name: 'Alice' }) });
|
|
134
|
+
*/
|
|
135
|
+
body?: any;
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Request headers.
|
|
139
|
+
* @example
|
|
140
|
+
* const res = await fetch(url, {
|
|
141
|
+
* headers: { 'Authorization': 'Bearer token123' }
|
|
142
|
+
* });
|
|
143
|
+
*/
|
|
144
|
+
headers?: { [name: string]: string };
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* The number of redirects to follow for this request.
|
|
148
|
+
* @default 5
|
|
149
|
+
* @example
|
|
150
|
+
* const res = await fetch(url, { maxRedirects: 1 });
|
|
151
|
+
*/
|
|
152
|
+
maxRedirects?: number;
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Maximum time to wait for the request to complete. Default
|
|
156
|
+
* timeout is 60 seconds ("60s"). The type can also be a number, in which
|
|
157
|
+
* case Mokapi interprets it as milliseconds
|
|
158
|
+
* @default "60s"
|
|
159
|
+
* @example
|
|
160
|
+
* const res = get(url, { timeout: '5m' })
|
|
161
|
+
* @example
|
|
162
|
+
* // Timeout as milliseconds
|
|
163
|
+
* const res = await fetch(url, { timeout: 3000 });
|
|
164
|
+
*/
|
|
165
|
+
timeout?: number | string;
|
|
94
166
|
}
|
|
95
167
|
|
|
96
168
|
/**
|
|
@@ -103,8 +175,8 @@ export interface Args {
|
|
|
103
175
|
/**
|
|
104
176
|
* The number of redirects to follow for this request.
|
|
105
177
|
* @default 5
|
|
106
|
-
|
|
107
|
-
maxRedirects?: number
|
|
178
|
+
*/
|
|
179
|
+
maxRedirects?: number;
|
|
108
180
|
/**
|
|
109
181
|
* Maximum time to wait for the request to complete. Default
|
|
110
182
|
* timeout is 60 seconds ("60s"). The type can also be a number, in which
|
|
@@ -112,7 +184,7 @@ export interface Args {
|
|
|
112
184
|
* @example
|
|
113
185
|
* const res = get(url, { timeout: '5m' })
|
|
114
186
|
*/
|
|
115
|
-
timeout?: number | string
|
|
187
|
+
timeout?: number | string;
|
|
116
188
|
}
|
|
117
189
|
|
|
118
190
|
/**
|
package/types/index.d.ts
CHANGED
|
@@ -29,7 +29,7 @@ import "./mail";
|
|
|
29
29
|
* })
|
|
30
30
|
* }
|
|
31
31
|
*/
|
|
32
|
-
export function on<T extends keyof EventHandler>(event: T, handler: EventHandler[T], args?: EventArgs): void
|
|
32
|
+
export function on<T extends keyof EventHandler>(event: T, handler: EventHandler[T], args?: EventArgs): void;
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
35
|
* Schedules a new periodic job with interval.
|
|
@@ -122,7 +122,7 @@ export interface EventHandler {
|
|
|
122
122
|
* })
|
|
123
123
|
* }
|
|
124
124
|
*/
|
|
125
|
-
export type HttpEventHandler = (request: HttpRequest, response: HttpResponse) => void
|
|
125
|
+
export type HttpEventHandler = (request: HttpRequest, response: HttpResponse) => void | Promise<void>;
|
|
126
126
|
|
|
127
127
|
/**
|
|
128
128
|
* HttpRequest is an object used by HttpEventHandler that contains request-specific
|
|
@@ -133,7 +133,7 @@ export interface HttpRequest {
|
|
|
133
133
|
/**
|
|
134
134
|
* Request method.
|
|
135
135
|
* @example GET
|
|
136
|
-
|
|
136
|
+
*/
|
|
137
137
|
readonly method: string;
|
|
138
138
|
|
|
139
139
|
/** Represents a parsed URL. */
|
|
@@ -157,15 +157,13 @@ export interface HttpRequest {
|
|
|
157
157
|
/** Object contains querystring parameters specified by OpenAPI querystring parameters. */
|
|
158
158
|
readonly querystring: any;
|
|
159
159
|
|
|
160
|
-
/** API name where this request is specified */
|
|
161
|
-
readonly api: string;
|
|
162
|
-
|
|
163
160
|
/** Path value specified by the OpenAPI path */
|
|
164
161
|
readonly key: string;
|
|
165
162
|
|
|
166
163
|
/** OperationId defined in OpenAPI */
|
|
167
164
|
readonly operationId: string;
|
|
168
165
|
|
|
166
|
+
/** Returns a string representing this HttpRequest object. */
|
|
169
167
|
toString(): string
|
|
170
168
|
}
|
|
171
169
|
|
|
@@ -206,7 +204,8 @@ export interface Url {
|
|
|
206
204
|
/** URL query string. */
|
|
207
205
|
readonly query: string;
|
|
208
206
|
|
|
209
|
-
|
|
207
|
+
/** Returns a string representing this Url object. */
|
|
208
|
+
toString(): string;
|
|
210
209
|
}
|
|
211
210
|
|
|
212
211
|
/**
|
|
@@ -427,12 +426,6 @@ export type DateLayout =
|
|
|
427
426
|
*
|
|
428
427
|
* Use this to customize how the event appears in the dashboard or to control tracking.
|
|
429
428
|
*
|
|
430
|
-
* @property tags Optional key-value pairs used to label the event in the dashboard.
|
|
431
|
-
*
|
|
432
|
-
* @property track Set to `true` to enable tracking of this event handler in the dashboard.
|
|
433
|
-
* If omitted, Mokapi automatically checks whether the response object has
|
|
434
|
-
* been modified and tracks the handler only if a change is detected.
|
|
435
|
-
*
|
|
436
429
|
* @example
|
|
437
430
|
* export default function() {
|
|
438
431
|
* on('http', function(req, res) {
|
|
@@ -445,7 +438,7 @@ export type DateLayout =
|
|
|
445
438
|
*/
|
|
446
439
|
export interface EventArgs {
|
|
447
440
|
/**
|
|
448
|
-
* Adds or overrides existing tags used in dashboard
|
|
441
|
+
* Adds or overrides existing tags used to label the event in dashboard
|
|
449
442
|
*/
|
|
450
443
|
tags?: { [key: string]: string };
|
|
451
444
|
|
|
@@ -458,7 +451,7 @@ export interface EventArgs {
|
|
|
458
451
|
}
|
|
459
452
|
|
|
460
453
|
/**
|
|
461
|
-
*
|
|
454
|
+
* ScheduledEventHandler is an object used by every and cron function.
|
|
462
455
|
* https://mokapi.io/docs/javascript-api/mokapi/eventhandler/scheduledeventargs
|
|
463
456
|
* @example
|
|
464
457
|
* export default function() {
|
|
@@ -559,7 +552,7 @@ export interface SharedMemory {
|
|
|
559
552
|
* @param key The key to retrieve.
|
|
560
553
|
* @returns The stored value, or `undefined` if not found.
|
|
561
554
|
*/
|
|
562
|
-
get
|
|
555
|
+
get(key: string): any;
|
|
563
556
|
|
|
564
557
|
/**
|
|
565
558
|
* Sets a value for the given key.
|
|
@@ -567,7 +560,7 @@ export interface SharedMemory {
|
|
|
567
560
|
* @param key The key to store the value under.
|
|
568
561
|
* @param value The value to store.
|
|
569
562
|
*/
|
|
570
|
-
set
|
|
563
|
+
set(key: string, value: any): void;
|
|
571
564
|
|
|
572
565
|
/**
|
|
573
566
|
* Updates a value atomically using an updater function.
|
|
@@ -583,32 +576,32 @@ export interface SharedMemory {
|
|
|
583
576
|
* @param updater Function that receives the current value and returns the new value.
|
|
584
577
|
* @returns The new value after update.
|
|
585
578
|
*/
|
|
586
|
-
update<T = any>(key: string, updater: (value: T | undefined) => T): T
|
|
579
|
+
update<T = any>(key: string, updater: (value: T | undefined) => T): T;
|
|
587
580
|
|
|
588
581
|
/**
|
|
589
582
|
* Checks if the given key exists in shared memory.
|
|
590
583
|
* @param key The key to check.
|
|
591
584
|
* @returns `true` if the key exists, otherwise `false`.
|
|
592
585
|
*/
|
|
593
|
-
has(key: string): boolean
|
|
586
|
+
has(key: string): boolean;
|
|
594
587
|
|
|
595
588
|
/**
|
|
596
589
|
* Removes the specified key and its value from shared memory.
|
|
597
590
|
* @param key The key to remove.
|
|
598
591
|
*/
|
|
599
|
-
delete(key: string): void
|
|
592
|
+
delete(key: string): void;
|
|
600
593
|
|
|
601
594
|
/**
|
|
602
595
|
* Removes all stored entries from shared memory.
|
|
603
596
|
* Use with caution — this clears all shared state.
|
|
604
597
|
*/
|
|
605
|
-
clear(): void
|
|
598
|
+
clear(): void;
|
|
606
599
|
|
|
607
600
|
/**
|
|
608
601
|
* Returns a list of all stored keys.
|
|
609
602
|
* @returns An array of key names.
|
|
610
603
|
*/
|
|
611
|
-
keys(): string[]
|
|
604
|
+
keys(): string[];
|
|
612
605
|
|
|
613
606
|
/**
|
|
614
607
|
* Creates or returns a namespaced shared memory store.
|
|
@@ -623,7 +616,7 @@ export interface SharedMemory {
|
|
|
623
616
|
* @param name The namespace identifier.
|
|
624
617
|
* @returns A `SharedMemory` object scoped to the given namespace.
|
|
625
618
|
*/
|
|
626
|
-
namespace(name: string): SharedMemory
|
|
619
|
+
namespace(name: string): SharedMemory;
|
|
627
620
|
}
|
|
628
621
|
|
|
629
622
|
/**
|
|
@@ -647,4 +640,4 @@ export interface SharedMemory {
|
|
|
647
640
|
* mokapi.log(`Current counter: ${count}`)
|
|
648
641
|
* ```
|
|
649
642
|
*/
|
|
650
|
-
export const shared: SharedMemory
|
|
643
|
+
export const shared: SharedMemory;
|