@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 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
- res = await plugin?.afterFetch?.(res) ?? res;
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;
@@ -4,7 +4,9 @@
4
4
  */
5
5
  export const delayPlugin = (ms) => ({
6
6
  name: 'delay',
7
- afterFetch: () => new Promise(r => setTimeout(r,ms))
7
+ afterFetch: async () => {
8
+ await new Promise(r => setTimeout(r,ms))
9
+ }
8
10
  });
9
11
 
10
12
  export const delay = delayPlugin(1000);
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
@@ -15,7 +15,7 @@ export interface OpenDialogOptions {
15
15
  }
16
16
 
17
17
  export interface Context {
18
- dialog: DialogNode,
18
+ dialog: DialogNode | undefined,
19
19
  id: string,
20
20
  parameters: Record<string, any>
21
21
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thepassle/app-tools",
3
- "version": "0.8.1",
3
+ "version": "0.8.3",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",