@aloma.io/integration-sdk 3.8.10 → 3.8.12
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/.prettierrc.cjs +8 -0
 - package/build/builder/index.d.mts +7 -11
 - package/build/builder/index.mjs +14 -15
 - package/build/builder/runtime-context.d.mts +1 -1
 - package/build/builder/runtime-context.mjs +11 -16
 - package/build/cli.mjs +38 -38
 - package/build/controller/index.d.mts +58 -2
 - package/build/controller/index.mjs +68 -11
 - package/build/index.d.mts +2 -2
 - package/build/index.mjs +2 -2
 - package/build/internal/connector/config.d.mts +2 -2
 - package/build/internal/connector/config.mjs +10 -10
 - package/build/internal/connector/index.d.mts +2 -2
 - package/build/internal/connector/index.mjs +4 -4
 - package/build/internal/connector/metrics.mjs +6 -6
 - package/build/internal/connector/server/index.d.mts +3 -3
 - package/build/internal/connector/server/index.mjs +7 -7
 - package/build/internal/connector/server/on-connect/decrypt-config.mjs +3 -3
 - package/build/internal/connector/server/on-connect/finish-oauth.d.mts +3 -3
 - package/build/internal/connector/server/on-connect/finish-oauth.mjs +17 -23
 - package/build/internal/connector/server/on-connect/index.d.mts +2 -2
 - package/build/internal/connector/server/on-connect/index.mjs +13 -13
 - package/build/internal/connector/server/on-connect/make-oauth.d.mts +3 -3
 - package/build/internal/connector/server/on-connect/make-oauth.mjs +17 -25
 - package/build/internal/connector/server/on-connect/start-oauth.mjs +6 -13
 - package/build/internal/connector/server/on-message.mjs +1 -1
 - package/build/internal/dispatcher/index.mjs +34 -45
 - package/build/internal/fetcher/fetcher.d.mts +1 -1
 - package/build/internal/fetcher/fetcher.mjs +11 -15
 - package/build/internal/fetcher/oauth-fetcher.d.mts +1 -1
 - package/build/internal/fetcher/oauth-fetcher.mjs +7 -7
 - package/build/internal/index.d.mts +1 -1
 - package/build/internal/index.mjs +1 -1
 - package/build/internal/util/index.mjs +5 -5
 - package/build/internal/util/jwe/cli.mjs +3 -3
 - package/build/internal/util/jwe/index.d.mts +1 -1
 - package/build/internal/util/jwe/index.mjs +10 -10
 - package/build/internal/websocket/config.d.mts +1 -1
 - package/build/internal/websocket/config.mjs +7 -7
 - package/build/internal/websocket/connection/constants.mjs +3 -3
 - package/build/internal/websocket/connection/index.mjs +8 -8
 - package/build/internal/websocket/connection/registration.mjs +6 -6
 - package/build/internal/websocket/index.d.mts +2 -2
 - package/build/internal/websocket/index.mjs +3 -3
 - package/build/internal/websocket/transport/durable.mjs +6 -6
 - package/build/internal/websocket/transport/index.d.mts +2 -2
 - package/build/internal/websocket/transport/index.mjs +19 -19
 - package/build/internal/websocket/transport/packet.mjs +1 -1
 - package/build/internal/websocket/transport/processor.mjs +5 -5
 - package/build/transform/index.mjs +26 -26
 - package/package.json +1 -1
 - package/src/builder/index.mts +66 -66
 - package/src/builder/runtime-context.mts +17 -43
 - package/src/cli.mts +48 -53
 - package/src/controller/index.mts +72 -12
 - package/src/index.mts +2 -2
 - package/src/internal/connector/config.mts +11 -19
 - package/src/internal/connector/index.mts +8 -9
 - package/src/internal/connector/metrics.mts +7 -7
 - package/src/internal/connector/server/index.mts +10 -10
 - package/src/internal/connector/server/on-connect/decrypt-config.mts +4 -4
 - package/src/internal/connector/server/on-connect/finish-oauth.mts +22 -35
 - package/src/internal/connector/server/on-connect/index.mts +27 -27
 - package/src/internal/connector/server/on-connect/make-oauth.mts +22 -33
 - package/src/internal/connector/server/on-connect/start-oauth.mts +7 -16
 - package/src/internal/connector/server/on-message.mts +1 -1
 - package/src/internal/dispatcher/index.mts +49 -70
 - package/src/internal/fetcher/fetcher.mts +44 -49
 - package/src/internal/fetcher/oauth-fetcher.mts +12 -13
 - package/src/internal/index.mts +2 -2
 - package/src/internal/util/index.mts +8 -11
 - package/src/internal/util/jwe/cli.mts +3 -3
 - package/src/internal/util/jwe/index.mts +17 -21
 - package/src/internal/websocket/config.mjs +8 -12
 - package/src/internal/websocket/connection/constants.mjs +3 -3
 - package/src/internal/websocket/connection/index.mjs +14 -14
 - package/src/internal/websocket/connection/registration.mjs +10 -10
 - package/src/internal/websocket/index.mjs +6 -6
 - package/src/internal/websocket/transport/durable.mjs +9 -9
 - package/src/internal/websocket/transport/index.mjs +28 -32
 - package/src/internal/websocket/transport/packet.mjs +4 -4
 - package/src/internal/websocket/transport/processor.mjs +9 -12
 - package/src/transform/index.mts +28 -41
 
    
        package/.prettierrc.cjs
    ADDED
    
    
| 
         @@ -1,5 +1,5 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            import  
     | 
| 
       2 
     | 
    
         
            -
            import RuntimeContext from  
     | 
| 
      
 1 
     | 
    
         
            +
            import 'dotenv/config';
         
     | 
| 
      
 2 
     | 
    
         
            +
            import RuntimeContext from './runtime-context.mjs';
         
     | 
| 
       3 
3 
     | 
    
         
             
            export declare const TARGET_DIR: string;
         
     | 
| 
       4 
4 
     | 
    
         
             
            /**
         
     | 
| 
       5 
5 
     | 
    
         
             
             * a configuration field
         
     | 
| 
         @@ -22,23 +22,19 @@ export type ConfigField = { 
     | 
|
| 
       22 
22 
     | 
    
         
             
                /**
         
     | 
| 
       23 
23 
     | 
    
         
             
                 * the type of the field
         
     | 
| 
       24 
24 
     | 
    
         
             
                 */
         
     | 
| 
       25 
     | 
    
         
            -
                type: 
         
     | 
| 
       26 
     | 
    
         
            -
                /**
         
     | 
| 
       27 
     | 
    
         
            -
                 * a multiline text field
         
     | 
| 
       28 
     | 
    
         
            -
                 */
         
     | 
| 
       29 
     | 
    
         
            -
                "multiline"
         
     | 
| 
      
 25 
     | 
    
         
            +
                type: 'multiline'
         
     | 
| 
       30 
26 
     | 
    
         
             
                /**
         
     | 
| 
       31 
27 
     | 
    
         
             
                 * a single line text field
         
     | 
| 
       32 
28 
     | 
    
         
             
                 */
         
     | 
| 
       33 
     | 
    
         
            -
                 |  
     | 
| 
      
 29 
     | 
    
         
            +
                 | 'line'
         
     | 
| 
       34 
30 
     | 
    
         
             
                /**
         
     | 
| 
       35 
31 
     | 
    
         
             
                 * a number field
         
     | 
| 
       36 
32 
     | 
    
         
             
                 */
         
     | 
| 
       37 
     | 
    
         
            -
                 |  
     | 
| 
      
 33 
     | 
    
         
            +
                 | 'number'
         
     | 
| 
       38 
34 
     | 
    
         
             
                /**
         
     | 
| 
       39 
35 
     | 
    
         
             
                 * a boolean text field
         
     | 
| 
       40 
36 
     | 
    
         
             
                 */
         
     | 
| 
       41 
     | 
    
         
            -
                 |  
     | 
| 
      
 37 
     | 
    
         
            +
                 | 'boolean';
         
     | 
| 
       42 
38 
     | 
    
         
             
                /**
         
     | 
| 
       43 
39 
     | 
    
         
             
                 * if true, the field is optional, otherwise a value is required
         
     | 
| 
       44 
40 
     | 
    
         
             
                 */
         
     | 
| 
         @@ -127,7 +123,7 @@ declare type OAuth = { 
     | 
|
| 
       127 
123 
     | 
    
         
             
                /**
         
     | 
| 
       128 
124 
     | 
    
         
             
                 * milliseconds to automatically refresh the token, if a refresh_token is available
         
     | 
| 
       129 
125 
     | 
    
         
             
                 *
         
     | 
| 
       130 
     | 
    
         
            -
             
     | 
| 
      
 126 
     | 
    
         
            +
                 * @default 4 * 60 * 60 * 1000 // 4 hours
         
     | 
| 
       131 
127 
     | 
    
         
             
                 */
         
     | 
| 
       132 
128 
     | 
    
         
             
                tokenRefreshPeriod?: number;
         
     | 
| 
       133 
129 
     | 
    
         
             
                /**
         
     | 
    
        package/build/builder/index.mjs
    CHANGED
    
    | 
         @@ -1,10 +1,10 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            import  
     | 
| 
       2 
     | 
    
         
            -
            import fs from  
     | 
| 
       3 
     | 
    
         
            -
            import path from  
     | 
| 
       4 
     | 
    
         
            -
            import { fileURLToPath } from  
     | 
| 
       5 
     | 
    
         
            -
            import { notEmpty } from  
     | 
| 
       6 
     | 
    
         
            -
            import RuntimeContext from  
     | 
| 
       7 
     | 
    
         
            -
            const DIR_OFFSET =  
     | 
| 
      
 1 
     | 
    
         
            +
            import 'dotenv/config';
         
     | 
| 
      
 2 
     | 
    
         
            +
            import fs from 'node:fs';
         
     | 
| 
      
 3 
     | 
    
         
            +
            import path from 'node:path';
         
     | 
| 
      
 4 
     | 
    
         
            +
            import { fileURLToPath } from 'node:url';
         
     | 
| 
      
 5 
     | 
    
         
            +
            import { notEmpty } from '../internal/util/index.mjs';
         
     | 
| 
      
 6 
     | 
    
         
            +
            import RuntimeContext from './runtime-context.mjs';
         
     | 
| 
      
 7 
     | 
    
         
            +
            const DIR_OFFSET = '/../../../../../';
         
     | 
| 
       8 
8 
     | 
    
         
             
            const __dirname = path.dirname(fileURLToPath(import.meta.url));
         
     | 
| 
       9 
9 
     | 
    
         
             
            export const TARGET_DIR = `${__dirname}${DIR_OFFSET}`;
         
     | 
| 
       10 
10 
     | 
    
         
             
            /**
         
     | 
| 
         @@ -12,7 +12,7 @@ export const TARGET_DIR = `${__dirname}${DIR_OFFSET}`; 
     | 
|
| 
       12 
12 
     | 
    
         
             
             */
         
     | 
| 
       13 
13 
     | 
    
         
             
            export class Builder {
         
     | 
| 
       14 
14 
     | 
    
         
             
                data = {
         
     | 
| 
       15 
     | 
    
         
            -
                    controller:  
     | 
| 
      
 15 
     | 
    
         
            +
                    controller: './build/.controller.json',
         
     | 
| 
       16 
16 
     | 
    
         
             
                };
         
     | 
| 
       17 
17 
     | 
    
         
             
                /**
         
     | 
| 
       18 
18 
     | 
    
         
             
                 * configure properties of the connector
         
     | 
| 
         @@ -49,23 +49,22 @@ export class Builder { 
     | 
|
| 
       49 
49 
     | 
    
         
             
                    await this.loadDescriptor();
         
     | 
| 
       50 
50 
     | 
    
         
             
                    await this.checkIcon();
         
     | 
| 
       51 
51 
     | 
    
         
             
                    // @ts-ignore
         
     | 
| 
       52 
     | 
    
         
            -
                    const Controller = (await import(TARGET_DIR +  
     | 
| 
       53 
     | 
    
         
            -
                        .default;
         
     | 
| 
      
 52 
     | 
    
         
            +
                    const Controller = (await import(TARGET_DIR + 'build/controller/index.mjs')).default;
         
     | 
| 
       54 
53 
     | 
    
         
             
                    return new RuntimeContext(new Controller(), this.data);
         
     | 
| 
       55 
54 
     | 
    
         
             
                }
         
     | 
| 
       56 
55 
     | 
    
         
             
                async checkIcon() {
         
     | 
| 
       57 
56 
     | 
    
         
             
                    const data = this.data;
         
     | 
| 
       58 
     | 
    
         
            -
                    data.icon = TARGET_DIR +  
     | 
| 
      
 57 
     | 
    
         
            +
                    data.icon = TARGET_DIR + 'build/logo.png';
         
     | 
| 
       59 
58 
     | 
    
         
             
                }
         
     | 
| 
       60 
59 
     | 
    
         
             
                async loadDescriptor() {
         
     | 
| 
       61 
     | 
    
         
            -
                    notEmpty(this.data.controller,  
     | 
| 
      
 60 
     | 
    
         
            +
                    notEmpty(this.data.controller, 'controller');
         
     | 
| 
       62 
61 
     | 
    
         
             
                    const content = fs.readFileSync(this.data.controller, {
         
     | 
| 
       63 
     | 
    
         
            -
                        encoding:  
     | 
| 
      
 62 
     | 
    
         
            +
                        encoding: 'utf-8',
         
     | 
| 
       64 
63 
     | 
    
         
             
                    });
         
     | 
| 
       65 
64 
     | 
    
         
             
                    const { text, methods, connectorId, version } = JSON.parse(content);
         
     | 
| 
       66 
65 
     | 
    
         
             
                    this.data.types = text;
         
     | 
| 
       67 
66 
     | 
    
         
             
                    this.data.methods = methods;
         
     | 
| 
       68 
     | 
    
         
            -
                    notEmpty((this.data.id = connectorId),  
     | 
| 
       69 
     | 
    
         
            -
                    notEmpty((this.data.version = version),  
     | 
| 
      
 67 
     | 
    
         
            +
                    notEmpty((this.data.id = connectorId), 'id');
         
     | 
| 
      
 68 
     | 
    
         
            +
                    notEmpty((this.data.version = version), 'version');
         
     | 
| 
       70 
69 
     | 
    
         
             
                }
         
     | 
| 
       71 
70 
     | 
    
         
             
            }
         
     | 
| 
         @@ -1,6 +1,6 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            import fs from  
     | 
| 
       2 
     | 
    
         
            -
            import { AbstractController } from  
     | 
| 
       3 
     | 
    
         
            -
            import { Connector } from  
     | 
| 
      
 1 
     | 
    
         
            +
            import fs from 'node:fs';
         
     | 
| 
      
 2 
     | 
    
         
            +
            import { AbstractController } from '../controller/index.mjs';
         
     | 
| 
      
 3 
     | 
    
         
            +
            import { Connector } from '../internal/index.mjs';
         
     | 
| 
       4 
4 
     | 
    
         
             
            export default class RuntimeContext {
         
     | 
| 
       5 
5 
     | 
    
         
             
                controller;
         
     | 
| 
       6 
6 
     | 
    
         
             
                data;
         
     | 
| 
         @@ -11,13 +11,13 @@ export default class RuntimeContext { 
     | 
|
| 
       11 
11 
     | 
    
         
             
                async start() {
         
     | 
| 
       12 
12 
     | 
    
         
             
                    const controller = this.controller;
         
     | 
| 
       13 
13 
     | 
    
         
             
                    if (!(controller instanceof AbstractController)) {
         
     | 
| 
       14 
     | 
    
         
            -
                        throw new Error( 
     | 
| 
      
 14 
     | 
    
         
            +
                        throw new Error('the controller needs to extend AbstractController');
         
     | 
| 
       15 
15 
     | 
    
         
             
                    }
         
     | 
| 
       16 
16 
     | 
    
         
             
                    const data = this.data;
         
     | 
| 
       17 
17 
     | 
    
         
             
                    let icon;
         
     | 
| 
       18 
18 
     | 
    
         
             
                    try {
         
     | 
| 
       19 
19 
     | 
    
         
             
                        if (data.icon) {
         
     | 
| 
       20 
     | 
    
         
            -
                            icon = fs.readFileSync(data.icon).toString( 
     | 
| 
      
 20 
     | 
    
         
            +
                            icon = fs.readFileSync(data.icon).toString('base64');
         
     | 
| 
       21 
21 
     | 
    
         
             
                        }
         
     | 
| 
       22 
22 
     | 
    
         
             
                    }
         
     | 
| 
       23 
23 
     | 
    
         
             
                    catch (e) {
         
     | 
| 
         @@ -31,13 +31,7 @@ export default class RuntimeContext { 
     | 
|
| 
       31 
31 
     | 
    
         
             
                    });
         
     | 
| 
       32 
32 
     | 
    
         
             
                    const configuration = connector.configure().config(data.config || {});
         
     | 
| 
       33 
33 
     | 
    
         
             
                    const resolvers = {};
         
     | 
| 
       34 
     | 
    
         
            -
                    const methods = [
         
     | 
| 
       35 
     | 
    
         
            -
                        ...data.methods,
         
     | 
| 
       36 
     | 
    
         
            -
                        "__autocomplete",
         
     | 
| 
       37 
     | 
    
         
            -
                        "__endpoint",
         
     | 
| 
       38 
     | 
    
         
            -
                        "__configQuery",
         
     | 
| 
       39 
     | 
    
         
            -
                        "__default",
         
     | 
| 
       40 
     | 
    
         
            -
                    ];
         
     | 
| 
      
 34 
     | 
    
         
            +
                    const methods = [...data.methods, '__autocomplete', '__endpoint', '__configQuery', '__default'];
         
     | 
| 
       41 
35 
     | 
    
         
             
                    methods.forEach((method) => {
         
     | 
| 
       42 
36 
     | 
    
         
             
                        resolvers[method] = async (args) => {
         
     | 
| 
       43 
37 
     | 
    
         
             
                            if (!methods.includes(method))
         
     | 
| 
         @@ -53,12 +47,13 @@ export default class RuntimeContext { 
     | 
|
| 
       53 
47 
     | 
    
         
             
                        configuration.oauth(data.auth?.oauth);
         
     | 
| 
       54 
48 
     | 
    
         
             
                    }
         
     | 
| 
       55 
49 
     | 
    
         
             
                    let healthInterval;
         
     | 
| 
       56 
     | 
    
         
            -
                    configuration.main(async ({ newTask, updateTask, config, oauth, getClient, getBlob, getBlobContent, createBlob, healthCheck 
     | 
| 
      
 50 
     | 
    
         
            +
                    configuration.main(async ({ newTask, updateTask, config, oauth, getClient, getBlob, getBlobContent, createBlob, healthCheck }) => {
         
     | 
| 
       57 
51 
     | 
    
         
             
                        try {
         
     | 
| 
       58 
52 
     | 
    
         
             
                            clearInterval(healthInterval);
         
     | 
| 
       59 
53 
     | 
    
         
             
                            await controller._doStop();
         
     | 
| 
       60 
54 
     | 
    
         
             
                            await controller._doStart(config, oauth, newTask, updateTask, getClient, getBlob, getBlobContent, createBlob);
         
     | 
| 
       61 
     | 
    
         
            -
                            healthInterval = setInterval(() => healthCheck(controller), 30000);
         
     | 
| 
      
 55 
     | 
    
         
            +
                            healthInterval = setInterval(() => healthCheck(controller), 30000).unref();
         
     | 
| 
      
 56 
     | 
    
         
            +
                            await healthCheck(controller);
         
     | 
| 
       62 
57 
     | 
    
         
             
                        }
         
     | 
| 
       63 
58 
     | 
    
         
             
                        catch (e) {
         
     | 
| 
       64 
59 
     | 
    
         
             
                            console.log(e);
         
     | 
| 
         @@ -70,7 +65,7 @@ export default class RuntimeContext { 
     | 
|
| 
       70 
65 
     | 
    
         
             
                        await controller._doStop(true);
         
     | 
| 
       71 
66 
     | 
    
         
             
                        process.exit(0);
         
     | 
| 
       72 
67 
     | 
    
         
             
                    };
         
     | 
| 
       73 
     | 
    
         
            -
                    process.on( 
     | 
| 
       74 
     | 
    
         
            -
                    process.on( 
     | 
| 
      
 68 
     | 
    
         
            +
                    process.on('SIGTERM', term);
         
     | 
| 
      
 69 
     | 
    
         
            +
                    process.on('SIGINT', term);
         
     | 
| 
       75 
70 
     | 
    
         
             
                }
         
     | 
| 
       76 
71 
     | 
    
         
             
            }
         
     | 
    
        package/build/cli.mjs
    CHANGED
    
    | 
         @@ -1,23 +1,23 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            #!/usr/bin/env node
         
     | 
| 
       2 
     | 
    
         
            -
            import { Command } from  
     | 
| 
       3 
     | 
    
         
            -
            import ChildProcess from  
     | 
| 
       4 
     | 
    
         
            -
            import fs from  
     | 
| 
       5 
     | 
    
         
            -
            import path from  
     | 
| 
       6 
     | 
    
         
            -
            import { fileURLToPath } from  
     | 
| 
       7 
     | 
    
         
            -
            import util from  
     | 
| 
       8 
     | 
    
         
            -
            import { TARGET_DIR } from  
     | 
| 
       9 
     | 
    
         
            -
            import { notEmpty } from  
     | 
| 
       10 
     | 
    
         
            -
            import JWE from  
     | 
| 
       11 
     | 
    
         
            -
            import parseTypes from  
     | 
| 
      
 2 
     | 
    
         
            +
            import { Command } from 'commander';
         
     | 
| 
      
 3 
     | 
    
         
            +
            import ChildProcess from 'node:child_process';
         
     | 
| 
      
 4 
     | 
    
         
            +
            import fs from 'node:fs';
         
     | 
| 
      
 5 
     | 
    
         
            +
            import path from 'node:path';
         
     | 
| 
      
 6 
     | 
    
         
            +
            import { fileURLToPath } from 'node:url';
         
     | 
| 
      
 7 
     | 
    
         
            +
            import util from 'node:util';
         
     | 
| 
      
 8 
     | 
    
         
            +
            import { TARGET_DIR } from './builder/index.mjs';
         
     | 
| 
      
 9 
     | 
    
         
            +
            import { notEmpty } from './internal/util/index.mjs';
         
     | 
| 
      
 10 
     | 
    
         
            +
            import JWE from './internal/util/jwe/index.mjs';
         
     | 
| 
      
 11 
     | 
    
         
            +
            import parseTypes from './transform/index.mjs';
         
     | 
| 
       12 
12 
     | 
    
         
             
            const exec = util.promisify(ChildProcess.exec);
         
     | 
| 
       13 
13 
     | 
    
         
             
            const __dirname = path.dirname(fileURLToPath(import.meta.url));
         
     | 
| 
       14 
14 
     | 
    
         
             
            const files = [
         
     | 
| 
       15 
     | 
    
         
            -
                { name:  
     | 
| 
       16 
     | 
    
         
            -
                { name:  
     | 
| 
       17 
     | 
    
         
            -
                { name:  
     | 
| 
       18 
     | 
    
         
            -
                { name:  
     | 
| 
       19 
     | 
    
         
            -
                { name:  
     | 
| 
       20 
     | 
    
         
            -
                { name:  
     | 
| 
      
 15 
     | 
    
         
            +
                { name: 'index.mts', dir: 'src/controller' },
         
     | 
| 
      
 16 
     | 
    
         
            +
                { name: 'index.mts', dir: 'src' },
         
     | 
| 
      
 17 
     | 
    
         
            +
                { name: 'package.json', dir: '' },
         
     | 
| 
      
 18 
     | 
    
         
            +
                { name: 'Containerfile', dir: '' },
         
     | 
| 
      
 19 
     | 
    
         
            +
                { name: 'entrypoint.sh', dir: '' },
         
     | 
| 
      
 20 
     | 
    
         
            +
                { name: 'tsconfig.json', dir: '' },
         
     | 
| 
       21 
21 
     | 
    
         
             
            ];
         
     | 
| 
       22 
22 
     | 
    
         
             
            const extract = ({ target, name, connectorId }) => {
         
     | 
| 
       23 
23 
     | 
    
         
             
                const source = `${__dirname}/../template/connector/`;
         
     | 
| 
         @@ -29,11 +29,11 @@ const extract = ({ target, name, connectorId }) => { 
     | 
|
| 
       29 
29 
     | 
    
         
             
                        fs.mkdirSync(`${target}/${dir}`, { recursive: true });
         
     | 
| 
       30 
30 
     | 
    
         
             
                    }
         
     | 
| 
       31 
31 
     | 
    
         
             
                    const content = fs.readFileSync(`${source}/${dir}/${name}`, {
         
     | 
| 
       32 
     | 
    
         
            -
                        encoding:  
     | 
| 
      
 32 
     | 
    
         
            +
                        encoding: 'utf-8',
         
     | 
| 
       33 
33 
     | 
    
         
             
                    });
         
     | 
| 
       34 
34 
     | 
    
         
             
                    fs.writeFileSync(`${target}/${dir}/${name}`, content);
         
     | 
| 
       35 
35 
     | 
    
         
             
                });
         
     | 
| 
       36 
     | 
    
         
            -
                const content = JSON.parse(fs.readFileSync(`${target}/package.json`, { encoding:  
     | 
| 
      
 36 
     | 
    
         
            +
                const content = JSON.parse(fs.readFileSync(`${target}/package.json`, { encoding: 'utf-8' }));
         
     | 
| 
       37 
37 
     | 
    
         
             
                content.name = name;
         
     | 
| 
       38 
38 
     | 
    
         
             
                content.connectorId = connectorId;
         
     | 
| 
       39 
39 
     | 
    
         
             
                fs.writeFileSync(`${target}/package.json`, JSON.stringify(content, null, 2));
         
     | 
| 
         @@ -56,28 +56,28 @@ PUBLIC_KEY=${pub} 
     | 
|
| 
       56 
56 
     | 
    
         
             
            };
         
     | 
| 
       57 
57 
     | 
    
         
             
            const program = new Command();
         
     | 
| 
       58 
58 
     | 
    
         
             
            program
         
     | 
| 
       59 
     | 
    
         
            -
                .name( 
     | 
| 
       60 
     | 
    
         
            -
                .description( 
     | 
| 
       61 
     | 
    
         
            -
                .version( 
     | 
| 
      
 59 
     | 
    
         
            +
                .name('npx @aloma.io/integration-sdk')
         
     | 
| 
      
 60 
     | 
    
         
            +
                .description('aloma.io integration sdk')
         
     | 
| 
      
 61 
     | 
    
         
            +
                .version('0.8.0')
         
     | 
| 
       62 
62 
     | 
    
         
             
                .showHelpAfterError();
         
     | 
| 
       63 
63 
     | 
    
         
             
            program
         
     | 
| 
       64 
     | 
    
         
            -
                .command( 
     | 
| 
       65 
     | 
    
         
            -
                .description( 
     | 
| 
       66 
     | 
    
         
            -
                .argument( 
     | 
| 
       67 
     | 
    
         
            -
                .requiredOption( 
     | 
| 
      
 64 
     | 
    
         
            +
                .command('create')
         
     | 
| 
      
 65 
     | 
    
         
            +
                .description('Create a new connector project')
         
     | 
| 
      
 66 
     | 
    
         
            +
                .argument('<name>', 'name of the project')
         
     | 
| 
      
 67 
     | 
    
         
            +
                .requiredOption('--connector-id <id>', 'id of the connector')
         
     | 
| 
       68 
68 
     | 
    
         
             
                .action(async (name, options) => {
         
     | 
| 
       69 
     | 
    
         
            -
                name = name.replace(/[\/\.]/gi,  
     | 
| 
      
 69 
     | 
    
         
            +
                name = name.replace(/[\/\.]/gi, '');
         
     | 
| 
       70 
70 
     | 
    
         
             
                if (!name)
         
     | 
| 
       71 
     | 
    
         
            -
                    throw new Error( 
     | 
| 
      
 71 
     | 
    
         
            +
                    throw new Error('name is empty');
         
     | 
| 
       72 
72 
     | 
    
         
             
                const target = `${process.cwd()}/${name}`;
         
     | 
| 
       73 
73 
     | 
    
         
             
                fs.mkdirSync(target);
         
     | 
| 
       74 
     | 
    
         
            -
                console.log( 
     | 
| 
      
 74 
     | 
    
         
            +
                console.log('Creating connector ...');
         
     | 
| 
       75 
75 
     | 
    
         
             
                extract({ ...options, target, name });
         
     | 
| 
       76 
     | 
    
         
            -
                console.log( 
     | 
| 
      
 76 
     | 
    
         
            +
                console.log('Generating keys ...');
         
     | 
| 
       77 
77 
     | 
    
         
             
                await generateKeys({ target });
         
     | 
| 
       78 
     | 
    
         
            -
                console.log( 
     | 
| 
      
 78 
     | 
    
         
            +
                console.log('Installing dependencies ...');
         
     | 
| 
       79 
79 
     | 
    
         
             
                await exec(`cd ${target}; yarn`);
         
     | 
| 
       80 
     | 
    
         
            -
                console.log( 
     | 
| 
      
 80 
     | 
    
         
            +
                console.log('Building ...');
         
     | 
| 
       81 
81 
     | 
    
         
             
                await exec(`cd ${target}; yarn build`);
         
     | 
| 
       82 
82 
     | 
    
         
             
                console.log(`
         
     | 
| 
       83 
83 
     | 
    
         
             
            Success!
         
     | 
| 
         @@ -87,8 +87,8 @@ Success! 
     | 
|
| 
       87 
87 
     | 
    
         
             
            3.) Start the connector with cd ./${name}/; yarn start`);
         
     | 
| 
       88 
88 
     | 
    
         
             
            });
         
     | 
| 
       89 
89 
     | 
    
         
             
            program
         
     | 
| 
       90 
     | 
    
         
            -
                .command( 
     | 
| 
       91 
     | 
    
         
            -
                .description( 
     | 
| 
      
 90 
     | 
    
         
            +
                .command('build')
         
     | 
| 
      
 91 
     | 
    
         
            +
                .description('Build the current connector project')
         
     | 
| 
       92 
92 
     | 
    
         
             
                .action(async (str, options) => {
         
     | 
| 
       93 
93 
     | 
    
         
             
                const { stdout, stderr } = await exec(`rm -rf build; mkdir -p build; `);
         
     | 
| 
       94 
94 
     | 
    
         
             
                try {
         
     | 
| 
         @@ -99,22 +99,22 @@ program 
     | 
|
| 
       99 
99 
     | 
    
         
             
                }
         
     | 
| 
       100 
100 
     | 
    
         
             
                if (stdout)
         
     | 
| 
       101 
101 
     | 
    
         
             
                    console.log(stdout);
         
     | 
| 
       102 
     | 
    
         
            -
                new Extractor().extract( 
     | 
| 
      
 102 
     | 
    
         
            +
                new Extractor().extract('./src/controller/index.mts', './build/.controller.json');
         
     | 
| 
       103 
103 
     | 
    
         
             
            });
         
     | 
| 
       104 
104 
     | 
    
         
             
            class Extractor {
         
     | 
| 
       105 
105 
     | 
    
         
             
                async extract(source, target) {
         
     | 
| 
       106 
     | 
    
         
            -
                    notEmpty(source,  
     | 
| 
      
 106 
     | 
    
         
            +
                    notEmpty(source, 'source');
         
     | 
| 
       107 
107 
     | 
    
         
             
                    fs.readFileSync(source);
         
     | 
| 
       108 
108 
     | 
    
         
             
                    const { text, methods } = await parseTypes(source);
         
     | 
| 
       109 
     | 
    
         
            -
                    const packageJson = JSON.parse(fs.readFileSync(TARGET_DIR +  
     | 
| 
       110 
     | 
    
         
            -
                        encoding:  
     | 
| 
      
 109 
     | 
    
         
            +
                    const packageJson = JSON.parse(fs.readFileSync(TARGET_DIR + 'package.json', {
         
     | 
| 
      
 110 
     | 
    
         
            +
                        encoding: 'utf-8',
         
     | 
| 
       111 
111 
     | 
    
         
             
                    }));
         
     | 
| 
       112 
112 
     | 
    
         
             
                    fs.writeFileSync(target, JSON.stringify({
         
     | 
| 
       113 
113 
     | 
    
         
             
                        text,
         
     | 
| 
       114 
114 
     | 
    
         
             
                        methods,
         
     | 
| 
       115 
115 
     | 
    
         
             
                        connectorId: packageJson.connectorId,
         
     | 
| 
       116 
116 
     | 
    
         
             
                        version: packageJson.version,
         
     | 
| 
       117 
     | 
    
         
            -
                    }), { encoding:  
     | 
| 
      
 117 
     | 
    
         
            +
                    }), { encoding: 'utf-8' });
         
     | 
| 
       118 
118 
     | 
    
         
             
                }
         
     | 
| 
       119 
119 
     | 
    
         
             
            }
         
     | 
| 
       120 
120 
     | 
    
         
             
            program.parse();
         
     | 
| 
         @@ -1,21 +1,65 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            import Fetcher from  
     | 
| 
      
 1 
     | 
    
         
            +
            import Fetcher from '../internal/fetcher/fetcher.mjs';
         
     | 
| 
      
 2 
     | 
    
         
            +
            import { OAuth } from '../internal/fetcher/oauth-fetcher.mjs';
         
     | 
| 
       2 
3 
     | 
    
         
             
            export declare abstract class AbstractController {
         
     | 
| 
      
 4 
     | 
    
         
            +
                /**
         
     | 
| 
      
 5 
     | 
    
         
            +
                 * connector configuration
         
     | 
| 
      
 6 
     | 
    
         
            +
                 */
         
     | 
| 
       3 
7 
     | 
    
         
             
                protected config: {
         
     | 
| 
       4 
8 
     | 
    
         
             
                    [key: string]: any;
         
     | 
| 
       5 
9 
     | 
    
         
             
                };
         
     | 
| 
      
 10 
     | 
    
         
            +
                /**
         
     | 
| 
      
 11 
     | 
    
         
            +
                 * @deprecated
         
     | 
| 
      
 12 
     | 
    
         
            +
                 */
         
     | 
| 
       6 
13 
     | 
    
         
             
                protected client: any;
         
     | 
| 
      
 14 
     | 
    
         
            +
                /**
         
     | 
| 
      
 15 
     | 
    
         
            +
                 * oauth data, if the connector is using oauth
         
     | 
| 
      
 16 
     | 
    
         
            +
                 */
         
     | 
| 
      
 17 
     | 
    
         
            +
                protected oauth?: OAuth;
         
     | 
| 
      
 18 
     | 
    
         
            +
                /**
         
     | 
| 
      
 19 
     | 
    
         
            +
                 * invoked, when the controller is started
         
     | 
| 
      
 20 
     | 
    
         
            +
                 */
         
     | 
| 
       7 
21 
     | 
    
         
             
                protected start(): Promise<void>;
         
     | 
| 
      
 22 
     | 
    
         
            +
                /**
         
     | 
| 
      
 23 
     | 
    
         
            +
                 * invoked, when the controller is stopped
         
     | 
| 
      
 24 
     | 
    
         
            +
                 * @param isShutdown true if the controller is stopped due to shutdown
         
     | 
| 
      
 25 
     | 
    
         
            +
                 */
         
     | 
| 
       8 
26 
     | 
    
         
             
                protected stop(isShutdown?: boolean): Promise<void>;
         
     | 
| 
       9 
27 
     | 
    
         
             
                protected configQuery(arg: any): Promise<any>;
         
     | 
| 
      
 28 
     | 
    
         
            +
                /**
         
     | 
| 
      
 29 
     | 
    
         
            +
                 * autocomplete configuration options
         
     | 
| 
      
 30 
     | 
    
         
            +
                 *
         
     | 
| 
      
 31 
     | 
    
         
            +
                 * e.g. if this connector is connected to a system which has multiple entities with dynamic attributes, like deals, ...
         
     | 
| 
      
 32 
     | 
    
         
            +
                 * then this method should return the possible attributes of the entity when invoked like
         
     | 
| 
      
 33 
     | 
    
         
            +
                 * ```javascript
         
     | 
| 
      
 34 
     | 
    
         
            +
                 * autocomplete({entity: 'deal'})
         
     | 
| 
      
 35 
     | 
    
         
            +
                 * ```
         
     | 
| 
      
 36 
     | 
    
         
            +
                 * @param arg
         
     | 
| 
      
 37 
     | 
    
         
            +
                 * @returns
         
     | 
| 
      
 38 
     | 
    
         
            +
                 */
         
     | 
| 
       10 
39 
     | 
    
         
             
                protected autocomplete(arg: any): Promise<any>;
         
     | 
| 
      
 40 
     | 
    
         
            +
                /**
         
     | 
| 
      
 41 
     | 
    
         
            +
                 * called, when the remote public method is not found on the controller
         
     | 
| 
      
 42 
     | 
    
         
            +
                 * @param arg
         
     | 
| 
      
 43 
     | 
    
         
            +
                 */
         
     | 
| 
       11 
44 
     | 
    
         
             
                protected fallback(arg: any): Promise<any>;
         
     | 
| 
       12 
45 
     | 
    
         
             
                protected endpoint(arg: any): Promise<any>;
         
     | 
| 
      
 46 
     | 
    
         
            +
                /**
         
     | 
| 
      
 47 
     | 
    
         
            +
                 * create a new task
         
     | 
| 
      
 48 
     | 
    
         
            +
                 * @param name name of the task
         
     | 
| 
      
 49 
     | 
    
         
            +
                 * @param data data of the task
         
     | 
| 
      
 50 
     | 
    
         
            +
                 */
         
     | 
| 
       13 
51 
     | 
    
         
             
                protected newTask(name: string, data: any): Promise<string>;
         
     | 
| 
       14 
52 
     | 
    
         
             
                protected getClient({ baseUrl, onResponse, customize, }: {
         
     | 
| 
       15 
53 
     | 
    
         
             
                    baseUrl?: string;
         
     | 
| 
       16 
54 
     | 
    
         
             
                    onResponse?: (response: any) => void;
         
     | 
| 
       17 
55 
     | 
    
         
             
                    customize?: (request: any) => void;
         
     | 
| 
       18 
56 
     | 
    
         
             
                }): Fetcher;
         
     | 
| 
      
 57 
     | 
    
         
            +
                /**
         
     | 
| 
      
 58 
     | 
    
         
            +
                 * update a task
         
     | 
| 
      
 59 
     | 
    
         
            +
                 * @param name name of the task
         
     | 
| 
      
 60 
     | 
    
         
            +
                 * @param data partial data of the task to update
         
     | 
| 
      
 61 
     | 
    
         
            +
                 * @returns taskId
         
     | 
| 
      
 62 
     | 
    
         
            +
                 */
         
     | 
| 
       19 
63 
     | 
    
         
             
                protected updateTask(name: string, data: any): Promise<string>;
         
     | 
| 
       20 
64 
     | 
    
         
             
                protected createBlob({ content, name, size, mimetype, meta, taskId, }: {
         
     | 
| 
       21 
65 
     | 
    
         
             
                    content: string;
         
     | 
| 
         @@ -25,6 +69,10 @@ export declare abstract class AbstractController { 
     | 
|
| 
       25 
69 
     | 
    
         
             
                    meta?: any;
         
     | 
| 
       26 
70 
     | 
    
         
             
                    taskId?: string;
         
     | 
| 
       27 
71 
     | 
    
         
             
                }): Promise<string>;
         
     | 
| 
      
 72 
     | 
    
         
            +
                /**
         
     | 
| 
      
 73 
     | 
    
         
            +
                 * get the metadata of a blob by id
         
     | 
| 
      
 74 
     | 
    
         
            +
                 * @param id blob id
         
     | 
| 
      
 75 
     | 
    
         
            +
                 */
         
     | 
| 
       28 
76 
     | 
    
         
             
                protected getBlob(id: string): Promise<{
         
     | 
| 
       29 
77 
     | 
    
         
             
                    name?: string;
         
     | 
| 
       30 
78 
     | 
    
         
             
                    id: any;
         
     | 
| 
         @@ -32,13 +80,21 @@ export declare abstract class AbstractController { 
     | 
|
| 
       32 
80 
     | 
    
         
             
                    mimetype?: string;
         
     | 
| 
       33 
81 
     | 
    
         
             
                    meta?: any;
         
     | 
| 
       34 
82 
     | 
    
         
             
                }>;
         
     | 
| 
      
 83 
     | 
    
         
            +
                /**
         
     | 
| 
      
 84 
     | 
    
         
            +
                 * get the content of a blob by id as base64
         
     | 
| 
      
 85 
     | 
    
         
            +
                 * @param id blob id
         
     | 
| 
      
 86 
     | 
    
         
            +
                 */
         
     | 
| 
       35 
87 
     | 
    
         
             
                protected getBlobContent(id: string): Promise<string>;
         
     | 
| 
      
 88 
     | 
    
         
            +
                /**
         
     | 
| 
      
 89 
     | 
    
         
            +
                 * health check, will be called periodically
         
     | 
| 
      
 90 
     | 
    
         
            +
                 * throw an error if unhealthy with a message describing what needs to be fixed
         
     | 
| 
      
 91 
     | 
    
         
            +
                 */
         
     | 
| 
       36 
92 
     | 
    
         
             
                protected healthCheck(): Promise<any>;
         
     | 
| 
       37 
93 
     | 
    
         
             
                __endpoint(arg: any): Promise<any | null>;
         
     | 
| 
       38 
94 
     | 
    
         
             
                __configQuery(arg: any): Promise<any | null>;
         
     | 
| 
       39 
95 
     | 
    
         
             
                __autocomplete(arg: any): Promise<any | null>;
         
     | 
| 
       40 
96 
     | 
    
         
             
                __default(arg: any): Promise<any | null>;
         
     | 
| 
       41 
97 
     | 
    
         
             
                __healthCheck(): Promise<any>;
         
     | 
| 
       42 
     | 
    
         
            -
                _doStart(config: any,  
     | 
| 
      
 98 
     | 
    
         
            +
                _doStart(config: any, oauth: any, newTask: any, updateTask: any, getClient: any, getBlob: any, getBlobContent: any, createBlob: any): Promise<void>;
         
     | 
| 
       43 
99 
     | 
    
         
             
                _doStop(isShutdown?: boolean): Promise<void>;
         
     | 
| 
       44 
100 
     | 
    
         
             
            }
         
     | 
| 
         @@ -1,38 +1,93 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            export class AbstractController {
         
     | 
| 
      
 2 
     | 
    
         
            +
                /**
         
     | 
| 
      
 3 
     | 
    
         
            +
                 * connector configuration
         
     | 
| 
      
 4 
     | 
    
         
            +
                 */
         
     | 
| 
       2 
5 
     | 
    
         
             
                config = {};
         
     | 
| 
      
 6 
     | 
    
         
            +
                /**
         
     | 
| 
      
 7 
     | 
    
         
            +
                 * @deprecated
         
     | 
| 
      
 8 
     | 
    
         
            +
                 */
         
     | 
| 
       3 
9 
     | 
    
         
             
                client;
         
     | 
| 
      
 10 
     | 
    
         
            +
                /**
         
     | 
| 
      
 11 
     | 
    
         
            +
                 * oauth data, if the connector is using oauth
         
     | 
| 
      
 12 
     | 
    
         
            +
                 */
         
     | 
| 
      
 13 
     | 
    
         
            +
                oauth;
         
     | 
| 
      
 14 
     | 
    
         
            +
                /**
         
     | 
| 
      
 15 
     | 
    
         
            +
                 * invoked, when the controller is started
         
     | 
| 
      
 16 
     | 
    
         
            +
                 */
         
     | 
| 
       4 
17 
     | 
    
         
             
                async start() { }
         
     | 
| 
      
 18 
     | 
    
         
            +
                /**
         
     | 
| 
      
 19 
     | 
    
         
            +
                 * invoked, when the controller is stopped
         
     | 
| 
      
 20 
     | 
    
         
            +
                 * @param isShutdown true if the controller is stopped due to shutdown
         
     | 
| 
      
 21 
     | 
    
         
            +
                 */
         
     | 
| 
       5 
22 
     | 
    
         
             
                async stop(isShutdown = false) { }
         
     | 
| 
       6 
23 
     | 
    
         
             
                configQuery(arg) {
         
     | 
| 
       7 
24 
     | 
    
         
             
                    return Promise.resolve({});
         
     | 
| 
       8 
25 
     | 
    
         
             
                }
         
     | 
| 
      
 26 
     | 
    
         
            +
                /**
         
     | 
| 
      
 27 
     | 
    
         
            +
                 * autocomplete configuration options
         
     | 
| 
      
 28 
     | 
    
         
            +
                 *
         
     | 
| 
      
 29 
     | 
    
         
            +
                 * e.g. if this connector is connected to a system which has multiple entities with dynamic attributes, like deals, ...
         
     | 
| 
      
 30 
     | 
    
         
            +
                 * then this method should return the possible attributes of the entity when invoked like
         
     | 
| 
      
 31 
     | 
    
         
            +
                 * ```javascript
         
     | 
| 
      
 32 
     | 
    
         
            +
                 * autocomplete({entity: 'deal'})
         
     | 
| 
      
 33 
     | 
    
         
            +
                 * ```
         
     | 
| 
      
 34 
     | 
    
         
            +
                 * @param arg
         
     | 
| 
      
 35 
     | 
    
         
            +
                 * @returns
         
     | 
| 
      
 36 
     | 
    
         
            +
                 */
         
     | 
| 
       9 
37 
     | 
    
         
             
                autocomplete(arg) {
         
     | 
| 
       10 
38 
     | 
    
         
             
                    return Promise.resolve({});
         
     | 
| 
       11 
39 
     | 
    
         
             
                }
         
     | 
| 
      
 40 
     | 
    
         
            +
                /**
         
     | 
| 
      
 41 
     | 
    
         
            +
                 * called, when the remote public method is not found on the controller
         
     | 
| 
      
 42 
     | 
    
         
            +
                 * @param arg
         
     | 
| 
      
 43 
     | 
    
         
            +
                 */
         
     | 
| 
       12 
44 
     | 
    
         
             
                fallback(arg) {
         
     | 
| 
       13 
     | 
    
         
            -
                    throw new Error( 
     | 
| 
      
 45 
     | 
    
         
            +
                    throw new Error('method not found');
         
     | 
| 
       14 
46 
     | 
    
         
             
                }
         
     | 
| 
       15 
47 
     | 
    
         
             
                async endpoint(arg) {
         
     | 
| 
       16 
     | 
    
         
            -
                    throw new Error( 
     | 
| 
      
 48 
     | 
    
         
            +
                    throw new Error('method not found');
         
     | 
| 
       17 
49 
     | 
    
         
             
                }
         
     | 
| 
      
 50 
     | 
    
         
            +
                /**
         
     | 
| 
      
 51 
     | 
    
         
            +
                 * create a new task
         
     | 
| 
      
 52 
     | 
    
         
            +
                 * @param name name of the task
         
     | 
| 
      
 53 
     | 
    
         
            +
                 * @param data data of the task
         
     | 
| 
      
 54 
     | 
    
         
            +
                 */
         
     | 
| 
       18 
55 
     | 
    
         
             
                async newTask(name, data) {
         
     | 
| 
       19 
     | 
    
         
            -
                    throw new Error( 
     | 
| 
      
 56 
     | 
    
         
            +
                    throw new Error('not implemented');
         
     | 
| 
       20 
57 
     | 
    
         
             
                }
         
     | 
| 
       21 
58 
     | 
    
         
             
                getClient({ baseUrl, onResponse, customize, }) {
         
     | 
| 
       22 
     | 
    
         
            -
                    throw new Error( 
     | 
| 
       23 
     | 
    
         
            -
                }
         
     | 
| 
      
 59 
     | 
    
         
            +
                    throw new Error('not implemented');
         
     | 
| 
      
 60 
     | 
    
         
            +
                }
         
     | 
| 
      
 61 
     | 
    
         
            +
                /**
         
     | 
| 
      
 62 
     | 
    
         
            +
                 * update a task
         
     | 
| 
      
 63 
     | 
    
         
            +
                 * @param name name of the task
         
     | 
| 
      
 64 
     | 
    
         
            +
                 * @param data partial data of the task to update
         
     | 
| 
      
 65 
     | 
    
         
            +
                 * @returns taskId
         
     | 
| 
      
 66 
     | 
    
         
            +
                 */
         
     | 
| 
       24 
67 
     | 
    
         
             
                async updateTask(name, data) {
         
     | 
| 
       25 
     | 
    
         
            -
                    throw new Error( 
     | 
| 
      
 68 
     | 
    
         
            +
                    throw new Error('not implemented');
         
     | 
| 
       26 
69 
     | 
    
         
             
                }
         
     | 
| 
       27 
70 
     | 
    
         
             
                async createBlob({ content, name, size, mimetype, meta, taskId, }) {
         
     | 
| 
       28 
     | 
    
         
            -
                    throw new Error( 
     | 
| 
      
 71 
     | 
    
         
            +
                    throw new Error('not implemented');
         
     | 
| 
       29 
72 
     | 
    
         
             
                }
         
     | 
| 
      
 73 
     | 
    
         
            +
                /**
         
     | 
| 
      
 74 
     | 
    
         
            +
                 * get the metadata of a blob by id
         
     | 
| 
      
 75 
     | 
    
         
            +
                 * @param id blob id
         
     | 
| 
      
 76 
     | 
    
         
            +
                 */
         
     | 
| 
       30 
77 
     | 
    
         
             
                async getBlob(id) {
         
     | 
| 
       31 
     | 
    
         
            -
                    throw new Error( 
     | 
| 
      
 78 
     | 
    
         
            +
                    throw new Error('not implemented');
         
     | 
| 
       32 
79 
     | 
    
         
             
                }
         
     | 
| 
      
 80 
     | 
    
         
            +
                /**
         
     | 
| 
      
 81 
     | 
    
         
            +
                 * get the content of a blob by id as base64
         
     | 
| 
      
 82 
     | 
    
         
            +
                 * @param id blob id
         
     | 
| 
      
 83 
     | 
    
         
            +
                 */
         
     | 
| 
       33 
84 
     | 
    
         
             
                async getBlobContent(id) {
         
     | 
| 
       34 
     | 
    
         
            -
                    throw new Error( 
     | 
| 
      
 85 
     | 
    
         
            +
                    throw new Error('not implemented');
         
     | 
| 
       35 
86 
     | 
    
         
             
                }
         
     | 
| 
      
 87 
     | 
    
         
            +
                /**
         
     | 
| 
      
 88 
     | 
    
         
            +
                 * health check, will be called periodically
         
     | 
| 
      
 89 
     | 
    
         
            +
                 * throw an error if unhealthy with a message describing what needs to be fixed
         
     | 
| 
      
 90 
     | 
    
         
            +
                 */
         
     | 
| 
       36 
91 
     | 
    
         
             
                async healthCheck() {
         
     | 
| 
       37 
92 
     | 
    
         
             
                    // blank, throw an error if unhealthy
         
     | 
| 
       38 
93 
     | 
    
         
             
                }
         
     | 
| 
         @@ -51,9 +106,11 @@ export class AbstractController { 
     | 
|
| 
       51 
106 
     | 
    
         
             
                async __healthCheck() {
         
     | 
| 
       52 
107 
     | 
    
         
             
                    return this.healthCheck();
         
     | 
| 
       53 
108 
     | 
    
         
             
                }
         
     | 
| 
       54 
     | 
    
         
            -
                async _doStart(config,  
     | 
| 
      
 109 
     | 
    
         
            +
                async _doStart(config, oauth, newTask, updateTask, getClient, getBlob, getBlobContent, createBlob) {
         
     | 
| 
      
 110 
     | 
    
         
            +
                    console.dir(config, { depth: null });
         
     | 
| 
       55 
111 
     | 
    
         
             
                    this.config = config;
         
     | 
| 
       56 
     | 
    
         
            -
                    this.client =  
     | 
| 
      
 112 
     | 
    
         
            +
                    this.client = oauth;
         
     | 
| 
      
 113 
     | 
    
         
            +
                    this.oauth = oauth;
         
     | 
| 
       57 
114 
     | 
    
         
             
                    this.newTask = newTask;
         
     | 
| 
       58 
115 
     | 
    
         
             
                    this.updateTask = updateTask;
         
     | 
| 
       59 
116 
     | 
    
         
             
                    this.getClient = getClient;
         
     | 
    
        package/build/index.d.mts
    CHANGED
    
    | 
         @@ -1,2 +1,2 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            export * from  
     | 
| 
       2 
     | 
    
         
            -
            export * from  
     | 
| 
      
 1 
     | 
    
         
            +
            export * from './builder/index.mjs';
         
     | 
| 
      
 2 
     | 
    
         
            +
            export * from './controller/index.mjs';
         
     | 
    
        package/build/index.mjs
    CHANGED
    
    | 
         @@ -1,2 +1,2 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            export * from  
     | 
| 
       2 
     | 
    
         
            -
            export * from  
     | 
| 
      
 1 
     | 
    
         
            +
            export * from './builder/index.mjs';
         
     | 
| 
      
 2 
     | 
    
         
            +
            export * from './controller/index.mjs';
         
     | 
| 
         @@ -1,5 +1,5 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            import { Config } from  
     | 
| 
       2 
     | 
    
         
            -
            export declare const makeConfig: ({ id, version, name, introspect, configSchema, icon 
     | 
| 
      
 1 
     | 
    
         
            +
            import { Config } from '../websocket/config.mjs';
         
     | 
| 
      
 2 
     | 
    
         
            +
            export declare const makeConfig: ({ id, version, name, introspect, configSchema, icon }: {
         
     | 
| 
       3 
3 
     | 
    
         
             
                id: any;
         
     | 
| 
       4 
4 
     | 
    
         
             
                version: any;
         
     | 
| 
       5 
5 
     | 
    
         
             
                name: any;
         
     | 
| 
         @@ -1,13 +1,13 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            import JWE from  
     | 
| 
       2 
     | 
    
         
            -
            import { Config } from  
     | 
| 
       3 
     | 
    
         
            -
            export const makeConfig = async ({ id, version, name, introspect, configSchema, icon 
     | 
| 
      
 1 
     | 
    
         
            +
            import JWE from '../util/jwe/index.mjs';
         
     | 
| 
      
 2 
     | 
    
         
            +
            import { Config } from '../websocket/config.mjs';
         
     | 
| 
      
 3 
     | 
    
         
            +
            export const makeConfig = async ({ id, version, name, introspect, configSchema, icon }) => {
         
     | 
| 
       4 
4 
     | 
    
         
             
                const config = new Config({
         
     | 
| 
       5 
5 
     | 
    
         
             
                    id: id,
         
     | 
| 
       6 
6 
     | 
    
         
             
                    version: version,
         
     | 
| 
       7 
7 
     | 
    
         
             
                    name: process.env.HOSTNAME || name,
         
     | 
| 
       8 
8 
     | 
    
         
             
                    registrationToken: process.env.REGISTRATION_TOKEN,
         
     | 
| 
       9 
     | 
    
         
            -
                    endpoint: process.env.DEVICE_ENDPOINT ||  
     | 
| 
       10 
     | 
    
         
            -
                    wsEndpoint: process.env.WEBSOCKET_ENDPOINT ||  
     | 
| 
      
 9 
     | 
    
         
            +
                    endpoint: process.env.DEVICE_ENDPOINT || 'https://connect.aloma.io/',
         
     | 
| 
      
 10 
     | 
    
         
            +
                    wsEndpoint: process.env.WEBSOCKET_ENDPOINT || 'wss://connect.aloma.io/transport/',
         
     | 
| 
       11 
11 
     | 
    
         
             
                    privateKey: process.env.PRIVATE_KEY,
         
     | 
| 
       12 
12 
     | 
    
         
             
                    publicKey: process.env.PUBLIC_KEY,
         
     | 
| 
       13 
13 
     | 
    
         
             
                    introspect,
         
     | 
| 
         @@ -21,15 +21,15 @@ export const makeConfig = async ({ id, version, name, introspect, configSchema, 
     | 
|
| 
       21 
21 
     | 
    
         
             
                    catch (e) {
         
     | 
| 
       22 
22 
     | 
    
         
             
                        const haveKey = !!process.env.PRIVATE_KEY;
         
     | 
| 
       23 
23 
     | 
    
         
             
                        const jwe = new JWE({});
         
     | 
| 
       24 
     | 
    
         
            -
                        var text =  
     | 
| 
      
 24 
     | 
    
         
            +
                        var text = 'Please double check the env variables';
         
     | 
| 
       25 
25 
     | 
    
         
             
                        if (!haveKey) {
         
     | 
| 
       26 
26 
     | 
    
         
             
                            await jwe.newPair();
         
     | 
| 
       27 
27 
     | 
    
         
             
                            text =
         
     | 
| 
       28 
     | 
    
         
            -
                                 
     | 
| 
      
 28 
     | 
    
         
            +
                                'fresh keys generated, set environment variables: \n\nPRIVATE_KEY: ' +
         
     | 
| 
       29 
29 
     | 
    
         
             
                                    (await jwe.exportPrivateAsBase64()) +
         
     | 
| 
       30 
     | 
    
         
            -
                                     
     | 
| 
      
 30 
     | 
    
         
            +
                                    '\n\nPUBLIC_KEY: ' +
         
     | 
| 
       31 
31 
     | 
    
         
             
                                    (await jwe.exportPublicAsBase64()) +
         
     | 
| 
       32 
     | 
    
         
            -
                                     
     | 
| 
      
 32 
     | 
    
         
            +
                                    '\n';
         
     | 
| 
       33 
33 
     | 
    
         
             
                        }
         
     | 
| 
       34 
34 
     | 
    
         
             
                        console.log(`
         
     | 
| 
       35 
35 
     | 
    
         
             
            Error:
         
     | 
| 
         @@ -43,7 +43,7 @@ ${text} 
     | 
|
| 
       43 
43 
     | 
    
         
             
                                resolve(null);
         
     | 
| 
       44 
44 
     | 
    
         
             
                            }, 2 * 60 * 1000);
         
     | 
| 
       45 
45 
     | 
    
         
             
                        });
         
     | 
| 
       46 
     | 
    
         
            -
                        throw new Error( 
     | 
| 
      
 46 
     | 
    
         
            +
                        throw new Error('could not start');
         
     | 
| 
       47 
47 
     | 
    
         
             
                    }
         
     | 
| 
       48 
48 
     | 
    
         
             
                }
         
     | 
| 
       49 
49 
     | 
    
         
             
                return config;
         
     | 
| 
         @@ -1,10 +1,10 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            import { Dispatcher } from  
     | 
| 
      
 1 
     | 
    
         
            +
            import { Dispatcher } from '../dispatcher/index.mjs';
         
     | 
| 
       2 
2 
     | 
    
         
             
            export declare class Connector {
         
     | 
| 
       3 
3 
     | 
    
         
             
                id: any;
         
     | 
| 
       4 
4 
     | 
    
         
             
                version: any;
         
     | 
| 
       5 
5 
     | 
    
         
             
                name: any;
         
     | 
| 
       6 
6 
     | 
    
         
             
                icon: any;
         
     | 
| 
       7 
     | 
    
         
            -
                dispatcher 
     | 
| 
      
 7 
     | 
    
         
            +
                dispatcher: Dispatcher;
         
     | 
| 
       8 
8 
     | 
    
         
             
                constructor({ version, id, name, icon }: {
         
     | 
| 
       9 
9 
     | 
    
         
             
                    version: any;
         
     | 
| 
       10 
10 
     | 
    
         
             
                    id: any;
         
     | 
| 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            import { Dispatcher } from  
     | 
| 
       2 
     | 
    
         
            -
            import { makeConfig } from  
     | 
| 
       3 
     | 
    
         
            -
            import { makeMetrics } from  
     | 
| 
       4 
     | 
    
         
            -
            import { makeServer } from  
     | 
| 
      
 1 
     | 
    
         
            +
            import { Dispatcher } from '../dispatcher/index.mjs';
         
     | 
| 
      
 2 
     | 
    
         
            +
            import { makeConfig } from './config.mjs';
         
     | 
| 
      
 3 
     | 
    
         
            +
            import { makeMetrics } from './metrics.mjs';
         
     | 
| 
      
 4 
     | 
    
         
            +
            import { makeServer } from './server/index.mjs';
         
     | 
| 
       5 
5 
     | 
    
         
             
            export class Connector {
         
     | 
| 
       6 
6 
     | 
    
         
             
                id;
         
     | 
| 
       7 
7 
     | 
    
         
             
                version;
         
     |