@thepassle/app-tools 0.8.1 → 0.8.3
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.
- package/api/index.js +4 -6
- package/api/plugins/delay.js +3 -1
- package/api/types.d.ts +1 -1
- package/dialog/types.d.ts +1 -1
- package/package.json +1 -1
package/api/index.js
CHANGED
|
@@ -39,11 +39,6 @@ export class Api {
|
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
/** @param {Plugin} plugin */
|
|
43
|
-
addPlugin(plugin) {
|
|
44
|
-
this.config.plugins.push(plugin);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
42
|
/**
|
|
48
43
|
* @param {string} url
|
|
49
44
|
* @param {Method} method
|
|
@@ -111,7 +106,10 @@ export class Api {
|
|
|
111
106
|
.then(async res => {
|
|
112
107
|
for(const plugin of plugins) {
|
|
113
108
|
try {
|
|
114
|
-
|
|
109
|
+
const afterFetchResult = await plugin?.afterFetch?.(res) ?? res;
|
|
110
|
+
if(afterFetchResult) {
|
|
111
|
+
res = afterFetchResult;
|
|
112
|
+
}
|
|
115
113
|
} catch(e) {
|
|
116
114
|
log(`Plugin "${plugin.name}" error on afterFetch hook`)
|
|
117
115
|
throw e;
|
package/api/plugins/delay.js
CHANGED
package/api/types.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export type Method = 'GET'|'DELETE'|'HEAD'|'OPTIONS'|'POST'|'PUT'|'PATCH';
|
|
|
13
13
|
|
|
14
14
|
export interface Plugin {
|
|
15
15
|
beforeFetch?: (meta: MetaParams) => MetaParams | Promise<MetaParams> | void;
|
|
16
|
-
afterFetch?: (res: Response) => Response | Promise<Response>;
|
|
16
|
+
afterFetch?: (res: Response) => void | Promise<void> | Response | Promise<Response>;
|
|
17
17
|
transform?: (data: any) => any;
|
|
18
18
|
name: string;
|
|
19
19
|
handleError?: (e: Error) => boolean;
|
package/dialog/types.d.ts
CHANGED