@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
 
| 
         @@ -1,5 +1,5 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            import express from  
     | 
| 
       2 
     | 
    
         
            -
            import PromClient from  
     | 
| 
      
 1 
     | 
    
         
            +
            import express from 'express';
         
     | 
| 
      
 2 
     | 
    
         
            +
            import PromClient from 'prom-client';
         
     | 
| 
       3 
3 
     | 
    
         
             
            export const makeMetrics = async ({ id, name, version }) => {
         
     | 
| 
       4 
4 
     | 
    
         
             
                const newMetrics = () => {
         
     | 
| 
       5 
5 
     | 
    
         
             
                    const metrics = PromClient;
         
     | 
| 
         @@ -7,7 +7,7 @@ export const makeMetrics = async ({ id, name, version }) => { 
     | 
|
| 
       7 
7 
     | 
    
         
             
                        service: name,
         
     | 
| 
       8 
8 
     | 
    
         
             
                        connectorId: id,
         
     | 
| 
       9 
9 
     | 
    
         
             
                        connectorVersion: version,
         
     | 
| 
       10 
     | 
    
         
            -
                        node: process.env.HOSTNAME ||  
     | 
| 
      
 10 
     | 
    
         
            +
                        node: process.env.HOSTNAME || 'test',
         
     | 
| 
       11 
11 
     | 
    
         
             
                    };
         
     | 
| 
       12 
12 
     | 
    
         
             
                    metrics.register.setDefaultLabels(defaultLabels);
         
     | 
| 
       13 
13 
     | 
    
         
             
                    metrics.collectDefaultMetrics();
         
     | 
| 
         @@ -15,13 +15,13 @@ export const makeMetrics = async ({ id, name, version }) => { 
     | 
|
| 
       15 
15 
     | 
    
         
             
                };
         
     | 
| 
       16 
16 
     | 
    
         
             
                const makeMetricsServer = (metrics) => {
         
     | 
| 
       17 
17 
     | 
    
         
             
                    const app = express();
         
     | 
| 
       18 
     | 
    
         
            -
                    app.get( 
     | 
| 
      
 18 
     | 
    
         
            +
                    app.get('/metrics', async (request, response, next) => {
         
     | 
| 
       19 
19 
     | 
    
         
             
                        response.status(200);
         
     | 
| 
       20 
     | 
    
         
            -
                        response.set( 
     | 
| 
      
 20 
     | 
    
         
            +
                        response.set('Content-type', metrics.contentType);
         
     | 
| 
       21 
21 
     | 
    
         
             
                        response.send(await metrics.register.metrics());
         
     | 
| 
       22 
22 
     | 
    
         
             
                        response.end();
         
     | 
| 
       23 
23 
     | 
    
         
             
                    });
         
     | 
| 
       24 
24 
     | 
    
         
             
                    return app;
         
     | 
| 
       25 
25 
     | 
    
         
             
                };
         
     | 
| 
       26 
     | 
    
         
            -
                makeMetricsServer(newMetrics()).listen(4050,  
     | 
| 
      
 26 
     | 
    
         
            +
                makeMetricsServer(newMetrics()).listen(4050, '0.0.0.0');
         
     | 
| 
       27 
27 
     | 
    
         
             
            };
         
     | 
| 
         @@ -1,6 +1,6 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            import Dispatcher from  
     | 
| 
       2 
     | 
    
         
            -
            import { Config } from  
     | 
| 
       3 
     | 
    
         
            -
            import { WebsocketConnector } from  
     | 
| 
      
 1 
     | 
    
         
            +
            import Dispatcher from '../../dispatcher/index.mjs';
         
     | 
| 
      
 2 
     | 
    
         
            +
            import { Config } from '../../websocket/config.mjs';
         
     | 
| 
      
 3 
     | 
    
         
            +
            import { WebsocketConnector } from '../../websocket/index.mjs';
         
     | 
| 
       4 
4 
     | 
    
         
             
            export declare const makeServer: ({ config, configSchema, start, processPacket, dispatcher, }: {
         
     | 
| 
       5 
5 
     | 
    
         
             
                config: Config;
         
     | 
| 
       6 
6 
     | 
    
         
             
                configSchema: any;
         
     | 
| 
         @@ -1,6 +1,6 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            import { WebsocketConnector } from  
     | 
| 
       2 
     | 
    
         
            -
            import { onConnect } from  
     | 
| 
       3 
     | 
    
         
            -
            import { onMessage } from  
     | 
| 
      
 1 
     | 
    
         
            +
            import { WebsocketConnector } from '../../websocket/index.mjs';
         
     | 
| 
      
 2 
     | 
    
         
            +
            import { onConnect } from './on-connect/index.mjs';
         
     | 
| 
      
 3 
     | 
    
         
            +
            import { onMessage } from './on-message.mjs';
         
     | 
| 
       4 
4 
     | 
    
         
             
            export const makeServer = async ({ config, configSchema, start, processPacket, dispatcher, }) => {
         
     | 
| 
       5 
5 
     | 
    
         
             
                const server = new WebsocketConnector({
         
     | 
| 
       6 
6 
     | 
    
         
             
                    config,
         
     | 
| 
         @@ -17,13 +17,13 @@ export const makeServer = async ({ config, configSchema, start, processPacket, d 
     | 
|
| 
       17 
17 
     | 
    
         
             
                    });
         
     | 
| 
       18 
18 
     | 
    
         
             
                    process.exit(0);
         
     | 
| 
       19 
19 
     | 
    
         
             
                };
         
     | 
| 
       20 
     | 
    
         
            -
                process.on( 
     | 
| 
      
 20 
     | 
    
         
            +
                process.on('uncaughtException', (e) => {
         
     | 
| 
       21 
21 
     | 
    
         
             
                    console.log(e);
         
     | 
| 
       22 
22 
     | 
    
         
             
                });
         
     | 
| 
       23 
     | 
    
         
            -
                process.on( 
     | 
| 
      
 23 
     | 
    
         
            +
                process.on('unhandledRejection', (e) => {
         
     | 
| 
       24 
24 
     | 
    
         
             
                    console.log(e);
         
     | 
| 
       25 
25 
     | 
    
         
             
                });
         
     | 
| 
       26 
     | 
    
         
            -
                process.on( 
     | 
| 
       27 
     | 
    
         
            -
                process.on( 
     | 
| 
      
 26 
     | 
    
         
            +
                process.on('SIGTERM', term);
         
     | 
| 
      
 27 
     | 
    
         
            +
                process.on('SIGINT', term);
         
     | 
| 
       28 
28 
     | 
    
         
             
                return server;
         
     | 
| 
       29 
29 
     | 
    
         
             
            };
         
     | 
| 
         @@ -2,13 +2,13 @@ export const decryptConfig = async ({ configSchema, config, secrets }) => { 
     | 
|
| 
       2 
2 
     | 
    
         
             
                const decrypted = {};
         
     | 
| 
       3 
3 
     | 
    
         
             
                const fields = configSchema().fields;
         
     | 
| 
       4 
4 
     | 
    
         
             
                const keys = Object.keys(secrets);
         
     | 
| 
       5 
     | 
    
         
            -
                const jwe = await config.validateKeys( 
     | 
| 
      
 5 
     | 
    
         
            +
                const jwe = await config.validateKeys('RSA-OAEP-256');
         
     | 
| 
       6 
6 
     | 
    
         
             
                for (var i = 0; i < keys.length; ++i) {
         
     | 
| 
       7 
7 
     | 
    
         
             
                    const key = keys[i];
         
     | 
| 
       8 
8 
     | 
    
         
             
                    const value = secrets[key];
         
     | 
| 
       9 
9 
     | 
    
         
             
                    if (!value)
         
     | 
| 
       10 
10 
     | 
    
         
             
                        continue;
         
     | 
| 
       11 
     | 
    
         
            -
                    if (fields[key]?.plain || [ 
     | 
| 
      
 11 
     | 
    
         
            +
                    if (fields[key]?.plain || ['endpointUrl'].includes(key)) {
         
     | 
| 
       12 
12 
     | 
    
         
             
                        decrypted[key] = value;
         
     | 
| 
       13 
13 
     | 
    
         
             
                    }
         
     | 
| 
       14 
14 
     | 
    
         
             
                    else {
         
     | 
| 
         @@ -16,7 +16,7 @@ export const decryptConfig = async ({ configSchema, config, secrets }) => { 
     | 
|
| 
       16 
16 
     | 
    
         
             
                            decrypted[key] = await jwe.decrypt(value, config.id());
         
     | 
| 
       17 
17 
     | 
    
         
             
                        }
         
     | 
| 
       18 
18 
     | 
    
         
             
                        catch (e) {
         
     | 
| 
       19 
     | 
    
         
            -
                            console.log( 
     | 
| 
      
 19 
     | 
    
         
            +
                            console.log('failed to decrypt key', key, config.id(), e);
         
     | 
| 
       20 
20 
     | 
    
         
             
                        }
         
     | 
| 
       21 
21 
     | 
    
         
             
                    }
         
     | 
| 
       22 
22 
     | 
    
         
             
                }
         
     | 
| 
         @@ -1,6 +1,6 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            import Dispatcher from  
     | 
| 
       2 
     | 
    
         
            -
            import { Config } from  
     | 
| 
       3 
     | 
    
         
            -
            import { WebsocketConnector } from  
     | 
| 
      
 1 
     | 
    
         
            +
            import Dispatcher from '../../../dispatcher/index.mjs';
         
     | 
| 
      
 2 
     | 
    
         
            +
            import { Config } from '../../../websocket/config.mjs';
         
     | 
| 
      
 3 
     | 
    
         
            +
            import { WebsocketConnector } from '../../../websocket/index.mjs';
         
     | 
| 
       4 
4 
     | 
    
         
             
            export declare const patchFinishOAuth: ({ dispatcher, decrypted, config, transport, }: {
         
     | 
| 
       5 
5 
     | 
    
         
             
                dispatcher: Dispatcher;
         
     | 
| 
       6 
6 
     | 
    
         
             
                decrypted: any;
         
     | 
| 
         @@ -1,31 +1,25 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            export const patchFinishOAuth = async ({ dispatcher, decrypted, config, transport, }) => {
         
     | 
| 
       2 
2 
     | 
    
         
             
                dispatcher.finishOAuth = async function (arg) {
         
     | 
| 
       3 
     | 
    
         
            -
                    const tokenURL = process.env.OAUTH_TOKEN_URL ||
         
     | 
| 
       4 
     | 
    
         
            -
                        decrypted.tokenURL ||
         
     | 
| 
       5 
     | 
    
         
            -
                        dispatcher._oauth.tokenURL;
         
     | 
| 
      
 3 
     | 
    
         
            +
                    const tokenURL = process.env.OAUTH_TOKEN_URL || decrypted.tokenURL || dispatcher._oauth.tokenURL;
         
     | 
| 
       6 
4 
     | 
    
         
             
                    if (!dispatcher._oauth)
         
     | 
| 
       7 
     | 
    
         
            -
                        throw new Error( 
     | 
| 
      
 5 
     | 
    
         
            +
                        throw new Error('oauth not configured');
         
     | 
| 
       8 
6 
     | 
    
         
             
                    if (!tokenURL && !dispatcher._oauth.finishOAuth)
         
     | 
| 
       9 
     | 
    
         
            -
                        throw new Error( 
     | 
| 
      
 7 
     | 
    
         
            +
                        throw new Error('need tokenURL or finishOAuth(arg)');
         
     | 
| 
       10 
8 
     | 
    
         
             
                    var data = null;
         
     | 
| 
       11 
9 
     | 
    
         
             
                    const doFinish = async () => {
         
     | 
| 
       12 
10 
     | 
    
         
             
                        if (!arg.code || !arg.redirectURI)
         
     | 
| 
       13 
     | 
    
         
            -
                            throw new Error( 
     | 
| 
       14 
     | 
    
         
            -
                        const clientId = decrypted.clientId ||
         
     | 
| 
       15 
     | 
    
         
            -
                            process.env.OAUTH_CLIENT_ID ||
         
     | 
| 
       16 
     | 
    
         
            -
                            dispatcher._oauth.clientId;
         
     | 
| 
      
 11 
     | 
    
         
            +
                            throw new Error('need code and redirectUri');
         
     | 
| 
      
 12 
     | 
    
         
            +
                        const clientId = decrypted.clientId || process.env.OAUTH_CLIENT_ID || dispatcher._oauth.clientId;
         
     | 
| 
       17 
13 
     | 
    
         
             
                        if (!clientId)
         
     | 
| 
       18 
     | 
    
         
            -
                            throw new Error( 
     | 
| 
       19 
     | 
    
         
            -
                        const clientSecret = decrypted.clientSecret ||
         
     | 
| 
       20 
     | 
    
         
            -
                            process.env.OAUTH_CLIENT_SECRET ||
         
     | 
| 
       21 
     | 
    
         
            -
                            dispatcher._oauth.clientSecret;
         
     | 
| 
      
 14 
     | 
    
         
            +
                            throw new Error('clientId not configured');
         
     | 
| 
      
 15 
     | 
    
         
            +
                        const clientSecret = decrypted.clientSecret || process.env.OAUTH_CLIENT_SECRET || dispatcher._oauth.clientSecret;
         
     | 
| 
       22 
16 
     | 
    
         
             
                        if (!clientSecret)
         
     | 
| 
       23 
     | 
    
         
            -
                            throw new Error( 
     | 
| 
      
 17 
     | 
    
         
            +
                            throw new Error('clientSecret not configured');
         
     | 
| 
       24 
18 
     | 
    
         
             
                        const additionalTokenArgs = dispatcher._oauth.additionalTokenArgs || {};
         
     | 
| 
       25 
19 
     | 
    
         
             
                        const useAuthHeader = !!dispatcher._oauth.useAuthHeader;
         
     | 
| 
       26 
20 
     | 
    
         
             
                        const useCodeChallenge = !!dispatcher._oauth.useCodeChallenge;
         
     | 
| 
       27 
21 
     | 
    
         
             
                        let body = {
         
     | 
| 
       28 
     | 
    
         
            -
                            grant_type:  
     | 
| 
      
 22 
     | 
    
         
            +
                            grant_type: 'authorization_code',
         
     | 
| 
       29 
23 
     | 
    
         
             
                            ...additionalTokenArgs,
         
     | 
| 
       30 
24 
     | 
    
         
             
                            code: arg.code,
         
     | 
| 
       31 
25 
     | 
    
         
             
                            redirect_uri: arg.redirectURI,
         
     | 
| 
         @@ -34,8 +28,8 @@ export const patchFinishOAuth = async ({ dispatcher, decrypted, config, transpor 
     | 
|
| 
       34 
28 
     | 
    
         
             
                            body.code_verifier = arg.codeVerifier;
         
     | 
| 
       35 
29 
     | 
    
         
             
                        }
         
     | 
| 
       36 
30 
     | 
    
         
             
                        let headers = {
         
     | 
| 
       37 
     | 
    
         
            -
                             
     | 
| 
       38 
     | 
    
         
            -
                            Accept:  
     | 
| 
      
 31 
     | 
    
         
            +
                            'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
         
     | 
| 
      
 32 
     | 
    
         
            +
                            Accept: 'application/json',
         
     | 
| 
       39 
33 
     | 
    
         
             
                        };
         
     | 
| 
       40 
34 
     | 
    
         
             
                        if (useAuthHeader) {
         
     | 
| 
       41 
35 
     | 
    
         
             
                            headers = {
         
     | 
| 
         @@ -51,7 +45,7 @@ export const patchFinishOAuth = async ({ dispatcher, decrypted, config, transpor 
     | 
|
| 
       51 
45 
     | 
    
         
             
                            };
         
     | 
| 
       52 
46 
     | 
    
         
             
                        }
         
     | 
| 
       53 
47 
     | 
    
         
             
                        const response = await fetch(tokenURL, {
         
     | 
| 
       54 
     | 
    
         
            -
                            method:  
     | 
| 
      
 48 
     | 
    
         
            +
                            method: 'POST',
         
     | 
| 
       55 
49 
     | 
    
         
             
                            body: new URLSearchParams(body),
         
     | 
| 
       56 
50 
     | 
    
         
             
                            headers,
         
     | 
| 
       57 
51 
     | 
    
         
             
                            signal: AbortSignal.timeout(60 * 1000),
         
     | 
| 
         @@ -61,17 +55,17 @@ export const patchFinishOAuth = async ({ dispatcher, decrypted, config, transpor 
     | 
|
| 
       61 
55 
     | 
    
         
             
                        if (status === 200) {
         
     | 
| 
       62 
56 
     | 
    
         
             
                            const ret = JSON.parse(text);
         
     | 
| 
       63 
57 
     | 
    
         
             
                            if (ret.error) {
         
     | 
| 
       64 
     | 
    
         
            -
                                throw new Error(`${status} ${ret.error} ${ret.error_description ||  
     | 
| 
      
 58 
     | 
    
         
            +
                                throw new Error(`${status} ${ret.error} ${ret.error_description || ''}`);
         
     | 
| 
       65 
59 
     | 
    
         
             
                            }
         
     | 
| 
       66 
60 
     | 
    
         
             
                            else if (ret.access_token) {
         
     | 
| 
       67 
61 
     | 
    
         
             
                                return { ...ret };
         
     | 
| 
       68 
62 
     | 
    
         
             
                            }
         
     | 
| 
       69 
63 
     | 
    
         
             
                            else {
         
     | 
| 
       70 
     | 
    
         
            -
                                throw new Error(status +  
     | 
| 
      
 64 
     | 
    
         
            +
                                throw new Error(status + ' response has no access_token - ' + text);
         
     | 
| 
       71 
65 
     | 
    
         
             
                            }
         
     | 
| 
       72 
66 
     | 
    
         
             
                        }
         
     | 
| 
       73 
67 
     | 
    
         
             
                        else {
         
     | 
| 
       74 
     | 
    
         
            -
                            throw new Error(status +  
     | 
| 
      
 68 
     | 
    
         
            +
                            throw new Error(status + ' ' + text);
         
     | 
| 
       75 
69 
     | 
    
         
             
                        }
         
     | 
| 
       76 
70 
     | 
    
         
             
                    };
         
     | 
| 
       77 
71 
     | 
    
         
             
                    if (dispatcher._oauth.finishOAuth) {
         
     | 
| 
         @@ -84,7 +78,7 @@ export const patchFinishOAuth = async ({ dispatcher, decrypted, config, transpor 
     | 
|
| 
       84 
78 
     | 
    
         
             
                    else {
         
     | 
| 
       85 
79 
     | 
    
         
             
                        data = await doFinish();
         
     | 
| 
       86 
80 
     | 
    
         
             
                    }
         
     | 
| 
       87 
     | 
    
         
            -
                    const jwe = await config.validateKeys( 
     | 
| 
       88 
     | 
    
         
            -
                    return { value: await jwe.encrypt(data,  
     | 
| 
      
 81 
     | 
    
         
            +
                    const jwe = await config.validateKeys('RSA-OAEP-256');
         
     | 
| 
      
 82 
     | 
    
         
            +
                    return { value: await jwe.encrypt(data, 'none', config.id()) };
         
     | 
| 
       89 
83 
     | 
    
         
             
                };
         
     | 
| 
       90 
84 
     | 
    
         
             
            };
         
     | 
| 
         @@ -1,5 +1,5 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            import Dispatcher from  
     | 
| 
       2 
     | 
    
         
            -
            import { Config } from  
     | 
| 
      
 1 
     | 
    
         
            +
            import Dispatcher from '../../../dispatcher/index.mjs';
         
     | 
| 
      
 2 
     | 
    
         
            +
            import { Config } from '../../../websocket/config.mjs';
         
     | 
| 
       3 
3 
     | 
    
         
             
            export declare const onConnect: ({ dispatcher, configSchema, config, start, }: {
         
     | 
| 
       4 
4 
     | 
    
         
             
                config: Config;
         
     | 
| 
       5 
5 
     | 
    
         
             
                configSchema: any;
         
     | 
| 
         @@ -1,9 +1,9 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            import { init } from  
     | 
| 
       2 
     | 
    
         
            -
            import Fetcher from  
     | 
| 
       3 
     | 
    
         
            -
            import { decryptConfig } from  
     | 
| 
       4 
     | 
    
         
            -
            import { patchFinishOAuth } from  
     | 
| 
       5 
     | 
    
         
            -
            import { makeOAuth } from  
     | 
| 
       6 
     | 
    
         
            -
            import { patchStartOAuth } from  
     | 
| 
      
 1 
     | 
    
         
            +
            import { init } from '@paralleldrive/cuid2';
         
     | 
| 
      
 2 
     | 
    
         
            +
            import Fetcher from '../../../fetcher/fetcher.mjs';
         
     | 
| 
      
 3 
     | 
    
         
            +
            import { decryptConfig } from './decrypt-config.mjs';
         
     | 
| 
      
 4 
     | 
    
         
            +
            import { patchFinishOAuth } from './finish-oauth.mjs';
         
     | 
| 
      
 5 
     | 
    
         
            +
            import { makeOAuth } from './make-oauth.mjs';
         
     | 
| 
      
 6 
     | 
    
         
            +
            import { patchStartOAuth } from './start-oauth.mjs';
         
     | 
| 
       7 
7 
     | 
    
         
             
            const cuid = init({ length: 32 });
         
     | 
| 
       8 
8 
     | 
    
         
             
            export const onConnect = ({ dispatcher, configSchema, config, start, }) => {
         
     | 
| 
       9 
9 
     | 
    
         
             
                return async (transport) => {
         
     | 
| 
         @@ -24,7 +24,7 @@ export const onConnect = ({ dispatcher, configSchema, config, start, }) => { 
     | 
|
| 
       24 
24 
     | 
    
         
             
                        const getBlob = (id) => {
         
     | 
| 
       25 
25 
     | 
    
         
             
                            return new Promise((resolve, reject) => {
         
     | 
| 
       26 
26 
     | 
    
         
             
                                const packet = transport.newPacket({}, (ret) => (ret?.error ? reject(ret.error) : resolve(ret)), `_req-${cuid()}`);
         
     | 
| 
       27 
     | 
    
         
            -
                                packet.method( 
     | 
| 
      
 27 
     | 
    
         
            +
                                packet.method('connector.blob.get');
         
     | 
| 
       28 
28 
     | 
    
         
             
                                packet.args({
         
     | 
| 
       29 
29 
     | 
    
         
             
                                    id,
         
     | 
| 
       30 
30 
     | 
    
         
             
                                });
         
     | 
| 
         @@ -34,7 +34,7 @@ export const onConnect = ({ dispatcher, configSchema, config, start, }) => { 
     | 
|
| 
       34 
34 
     | 
    
         
             
                        const getBlobContent = (id) => {
         
     | 
| 
       35 
35 
     | 
    
         
             
                            return new Promise((resolve, reject) => {
         
     | 
| 
       36 
36 
     | 
    
         
             
                                const packet = transport.newPacket({}, (ret) => (ret?.error ? reject(ret.error) : resolve(ret?.content)), `_req-${cuid()}`);
         
     | 
| 
       37 
     | 
    
         
            -
                                packet.method( 
     | 
| 
      
 37 
     | 
    
         
            +
                                packet.method('connector.blob.get-content');
         
     | 
| 
       38 
38 
     | 
    
         
             
                                packet.args({
         
     | 
| 
       39 
39 
     | 
    
         
             
                                    id,
         
     | 
| 
       40 
40 
     | 
    
         
             
                                });
         
     | 
| 
         @@ -44,7 +44,7 @@ export const onConnect = ({ dispatcher, configSchema, config, start, }) => { 
     | 
|
| 
       44 
44 
     | 
    
         
             
                        const createBlob = (args = {}) => {
         
     | 
| 
       45 
45 
     | 
    
         
             
                            return new Promise((resolve, reject) => {
         
     | 
| 
       46 
46 
     | 
    
         
             
                                const packet = transport.newPacket({}, (ret) => (ret?.error ? reject(ret.error) : resolve(ret?.id)), `_req-${cuid()}`);
         
     | 
| 
       47 
     | 
    
         
            -
                                packet.method( 
     | 
| 
      
 47 
     | 
    
         
            +
                                packet.method('connector.blob.create');
         
     | 
| 
       48 
48 
     | 
    
         
             
                                packet.args(args);
         
     | 
| 
       49 
49 
     | 
    
         
             
                                transport.send(packet);
         
     | 
| 
       50 
50 
     | 
    
         
             
                            });
         
     | 
| 
         @@ -69,15 +69,15 @@ export const onConnect = ({ dispatcher, configSchema, config, start, }) => { 
     | 
|
| 
       69 
69 
     | 
    
         
             
                                    result.error = e.message;
         
     | 
| 
       70 
70 
     | 
    
         
             
                                }
         
     | 
| 
       71 
71 
     | 
    
         
             
                                const packet = transport.newPacket({});
         
     | 
| 
       72 
     | 
    
         
            -
                                packet.method( 
     | 
| 
      
 72 
     | 
    
         
            +
                                packet.method('connector.health.check');
         
     | 
| 
       73 
73 
     | 
    
         
             
                                packet.args(result);
         
     | 
| 
       74 
74 
     | 
    
         
             
                                transport.send(packet);
         
     | 
| 
       75 
75 
     | 
    
         
             
                            },
         
     | 
| 
       76 
     | 
    
         
            -
                            getClient: (arg) => theOAuth ? (oauthClient = theOAuth.getClient(arg)) : new Fetcher(arg),
         
     | 
| 
      
 76 
     | 
    
         
            +
                            getClient: (arg) => (theOAuth ? (oauthClient = theOAuth.getClient(arg)) : new Fetcher(arg)),
         
     | 
| 
       77 
77 
     | 
    
         
             
                            newTask: (name, data) => {
         
     | 
| 
       78 
78 
     | 
    
         
             
                                return new Promise((resolve, reject) => {
         
     | 
| 
       79 
79 
     | 
    
         
             
                                    const packet = transport.newPacket({}, (ret) => (ret?.error ? reject(ret.error) : resolve(ret)), `_req-${cuid()}`);
         
     | 
| 
       80 
     | 
    
         
            -
                                    packet.method( 
     | 
| 
      
 80 
     | 
    
         
            +
                                    packet.method('connector.task.new');
         
     | 
| 
       81 
81 
     | 
    
         
             
                                    packet.args({
         
     | 
| 
       82 
82 
     | 
    
         
             
                                        name,
         
     | 
| 
       83 
83 
     | 
    
         
             
                                        a: data,
         
     | 
| 
         @@ -88,7 +88,7 @@ export const onConnect = ({ dispatcher, configSchema, config, start, }) => { 
     | 
|
| 
       88 
88 
     | 
    
         
             
                            updateTask: (id, data) => {
         
     | 
| 
       89 
89 
     | 
    
         
             
                                return new Promise((resolve, reject) => {
         
     | 
| 
       90 
90 
     | 
    
         
             
                                    const packet = transport.newPacket({}, (ret) => (ret?.error ? reject(ret.error) : resolve(ret)), `_req-${cuid()}`);
         
     | 
| 
       91 
     | 
    
         
            -
                                    packet.method( 
     | 
| 
      
 91 
     | 
    
         
            +
                                    packet.method('connector.task.update');
         
     | 
| 
       92 
92 
     | 
    
         
             
                                    packet.args({
         
     | 
| 
       93 
93 
     | 
    
         
             
                                        id,
         
     | 
| 
       94 
94 
     | 
    
         
             
                                        a: data,
         
     | 
| 
         @@ -1,6 +1,6 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            import Dispatcher from  
     | 
| 
       2 
     | 
    
         
            -
            import { OAuth } from  
     | 
| 
       3 
     | 
    
         
            -
            import { Config } from  
     | 
| 
      
 1 
     | 
    
         
            +
            import Dispatcher from '../../../dispatcher/index.mjs';
         
     | 
| 
      
 2 
     | 
    
         
            +
            import { OAuth } from '../../../fetcher/oauth-fetcher.mjs';
         
     | 
| 
      
 3 
     | 
    
         
            +
            import { Config } from '../../../websocket/config.mjs';
         
     | 
| 
       4 
4 
     | 
    
         
             
            export declare const makeOAuth: ({ config, transport, decrypted, dispatcher, }: {
         
     | 
| 
       5 
5 
     | 
    
         
             
                config: Config;
         
     | 
| 
       6 
6 
     | 
    
         
             
                transport: any;
         
     | 
| 
         @@ -1,29 +1,23 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            import { OAuth } from  
     | 
| 
      
 1 
     | 
    
         
            +
            import { OAuth } from '../../../fetcher/oauth-fetcher.mjs';
         
     | 
| 
       2 
2 
     | 
    
         
             
            export const makeOAuth = async ({ config, transport, decrypted, dispatcher, }) => {
         
     | 
| 
       3 
3 
     | 
    
         
             
                const saveOAuthResult = async (what) => {
         
     | 
| 
       4 
     | 
    
         
            -
                    const jwe = await config.validateKeys( 
     | 
| 
       5 
     | 
    
         
            -
                    const value = await jwe.encrypt(what,  
     | 
| 
      
 4 
     | 
    
         
            +
                    const jwe = await config.validateKeys('RSA-OAEP-256');
         
     | 
| 
      
 5 
     | 
    
         
            +
                    const value = await jwe.encrypt(what, 'none', config.id());
         
     | 
| 
       6 
6 
     | 
    
         
             
                    const packet = transport.newPacket({});
         
     | 
| 
       7 
     | 
    
         
            -
                    packet.method( 
     | 
| 
      
 7 
     | 
    
         
            +
                    packet.method('connector.config-update');
         
     | 
| 
       8 
8 
     | 
    
         
             
                    packet.args({
         
     | 
| 
       9 
9 
     | 
    
         
             
                        value,
         
     | 
| 
       10 
10 
     | 
    
         
             
                    });
         
     | 
| 
       11 
11 
     | 
    
         
             
                    transport.send(packet);
         
     | 
| 
       12 
12 
     | 
    
         
             
                };
         
     | 
| 
       13 
13 
     | 
    
         
             
                const getRefreshToken = async (refreshToken) => {
         
     | 
| 
       14 
     | 
    
         
            -
                    const tokenURL = process.env.OAUTH_TOKEN_URL ||
         
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
                        dispatcher._oauth.tokenURL;
         
     | 
| 
       17 
     | 
    
         
            -
                    const clientId = decrypted.clientId ||
         
     | 
| 
       18 
     | 
    
         
            -
                        process.env.OAUTH_CLIENT_ID ||
         
     | 
| 
       19 
     | 
    
         
            -
                        dispatcher._oauth.clientId;
         
     | 
| 
      
 14 
     | 
    
         
            +
                    const tokenURL = process.env.OAUTH_TOKEN_URL || decrypted.tokenURL || dispatcher._oauth.tokenURL;
         
     | 
| 
      
 15 
     | 
    
         
            +
                    const clientId = decrypted.clientId || process.env.OAUTH_CLIENT_ID || dispatcher._oauth.clientId;
         
     | 
| 
       20 
16 
     | 
    
         
             
                    if (!clientId)
         
     | 
| 
       21 
     | 
    
         
            -
                        throw new Error( 
     | 
| 
       22 
     | 
    
         
            -
                    const clientSecret = decrypted.clientSecret ||
         
     | 
| 
       23 
     | 
    
         
            -
                        process.env.OAUTH_CLIENT_SECRET ||
         
     | 
| 
       24 
     | 
    
         
            -
                        dispatcher._oauth.clientSecret;
         
     | 
| 
      
 17 
     | 
    
         
            +
                        throw new Error('clientId not configured');
         
     | 
| 
      
 18 
     | 
    
         
            +
                    const clientSecret = decrypted.clientSecret || process.env.OAUTH_CLIENT_SECRET || dispatcher._oauth.clientSecret;
         
     | 
| 
       25 
19 
     | 
    
         
             
                    if (!clientSecret)
         
     | 
| 
       26 
     | 
    
         
            -
                        throw new Error( 
     | 
| 
      
 20 
     | 
    
         
            +
                        throw new Error('clientSecret not configured');
         
     | 
| 
       27 
21 
     | 
    
         
             
                    const useAuthHeader = !!dispatcher._oauth.useAuthHeader;
         
     | 
| 
       28 
22 
     | 
    
         
             
                    let headers = {};
         
     | 
| 
       29 
23 
     | 
    
         
             
                    if (useAuthHeader) {
         
     | 
| 
         @@ -33,16 +27,16 @@ export const makeOAuth = async ({ config, transport, decrypted, dispatcher, }) = 
     | 
|
| 
       33 
27 
     | 
    
         
             
                        };
         
     | 
| 
       34 
28 
     | 
    
         
             
                    }
         
     | 
| 
       35 
29 
     | 
    
         
             
                    const response = await fetch(tokenURL, {
         
     | 
| 
       36 
     | 
    
         
            -
                        method:  
     | 
| 
      
 30 
     | 
    
         
            +
                        method: 'POST',
         
     | 
| 
       37 
31 
     | 
    
         
             
                        body: new URLSearchParams({
         
     | 
| 
       38 
     | 
    
         
            -
                            grant_type:  
     | 
| 
      
 32 
     | 
    
         
            +
                            grant_type: 'refresh_token',
         
     | 
| 
       39 
33 
     | 
    
         
             
                            refresh_token: refreshToken,
         
     | 
| 
       40 
34 
     | 
    
         
             
                            client_id: clientId,
         
     | 
| 
       41 
35 
     | 
    
         
             
                            client_secret: clientSecret,
         
     | 
| 
       42 
36 
     | 
    
         
             
                        }),
         
     | 
| 
       43 
37 
     | 
    
         
             
                        headers: {
         
     | 
| 
       44 
     | 
    
         
            -
                             
     | 
| 
       45 
     | 
    
         
            -
                            Accept:  
     | 
| 
      
 38 
     | 
    
         
            +
                            'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
         
     | 
| 
      
 39 
     | 
    
         
            +
                            Accept: 'application/json',
         
     | 
| 
       46 
40 
     | 
    
         
             
                            ...headers,
         
     | 
| 
       47 
41 
     | 
    
         
             
                        },
         
     | 
| 
       48 
42 
     | 
    
         
             
                        signal: AbortSignal.timeout(60 * 1000),
         
     | 
| 
         @@ -53,22 +47,20 @@ export const makeOAuth = async ({ config, transport, decrypted, dispatcher, }) = 
     | 
|
| 
       53 
47 
     | 
    
         
             
                        return JSON.parse(text);
         
     | 
| 
       54 
48 
     | 
    
         
             
                    }
         
     | 
| 
       55 
49 
     | 
    
         
             
                    else {
         
     | 
| 
       56 
     | 
    
         
            -
                        throw new Error( 
     | 
| 
      
 50 
     | 
    
         
            +
                        throw new Error('could not get refresh token ' + status + ' ' + text);
         
     | 
| 
       57 
51 
     | 
    
         
             
                    }
         
     | 
| 
       58 
52 
     | 
    
         
             
                };
         
     | 
| 
       59 
     | 
    
         
            -
                const theOAuth = dispatcher._oauth
         
     | 
| 
       60 
     | 
    
         
            -
                    ? new OAuth(decrypted.oauthResult, saveOAuthResult, getRefreshToken)
         
     | 
| 
       61 
     | 
    
         
            -
                    : null;
         
     | 
| 
      
 53 
     | 
    
         
            +
                const theOAuth = dispatcher._oauth ? new OAuth(decrypted.oauthResult, saveOAuthResult, getRefreshToken) : null;
         
     | 
| 
       62 
54 
     | 
    
         
             
                if (theOAuth) {
         
     | 
| 
       63 
55 
     | 
    
         
             
                    clearInterval(dispatcher._refreshOAuthToken);
         
     | 
| 
       64 
56 
     | 
    
         
             
                    if (!(dispatcher._oauth.noPeriodicTokenRefresh === false)) {
         
     | 
| 
       65 
57 
     | 
    
         
             
                        dispatcher._refreshOAuthToken = setInterval(async () => {
         
     | 
| 
       66 
58 
     | 
    
         
             
                            try {
         
     | 
| 
       67 
     | 
    
         
            -
                                console.log( 
     | 
| 
      
 59 
     | 
    
         
            +
                                console.log('refreshing oauth token');
         
     | 
| 
       68 
60 
     | 
    
         
             
                                await theOAuth.periodicRefresh();
         
     | 
| 
       69 
61 
     | 
    
         
             
                            }
         
     | 
| 
       70 
62 
     | 
    
         
             
                            catch (e) {
         
     | 
| 
       71 
     | 
    
         
            -
                                console.log( 
     | 
| 
      
 63 
     | 
    
         
            +
                                console.log('periodic refresh', e);
         
     | 
| 
       72 
64 
     | 
    
         
             
                            }
         
     | 
| 
       73 
65 
     | 
    
         
             
                        }, dispatcher._oauth.tokenRefreshPeriod || 4 * 60 * 60 * 15000);
         
     | 
| 
       74 
66 
     | 
    
         
             
                    }
         
     | 
| 
         @@ -1,21 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            export const patchStartOAuth = async ({ dispatcher, decrypted }) => {
         
     | 
| 
       2 
2 
     | 
    
         
             
                dispatcher.startOAuth = async function () {
         
     | 
| 
       3 
3 
     | 
    
         
             
                    if (!dispatcher._oauth)
         
     | 
| 
       4 
     | 
    
         
            -
                        throw new Error( 
     | 
| 
       5 
     | 
    
         
            -
                    const authorizationURL = process.env.OAUTH_AUTHORIZATION_URL ||
         
     | 
| 
       6 
     | 
    
         
            -
                        decrypted.authorizationURL ||
         
     | 
| 
       7 
     | 
    
         
            -
                        dispatcher._oauth.authorizationURL;
         
     | 
| 
      
 4 
     | 
    
         
            +
                        throw new Error('oauth not configured');
         
     | 
| 
      
 5 
     | 
    
         
            +
                    const authorizationURL = process.env.OAUTH_AUTHORIZATION_URL || decrypted.authorizationURL || dispatcher._oauth.authorizationURL;
         
     | 
| 
       8 
6 
     | 
    
         
             
                    if (!authorizationURL)
         
     | 
| 
       9 
     | 
    
         
            -
                        throw new Error( 
     | 
| 
       10 
     | 
    
         
            -
                    const clientId = decrypted.clientId ||
         
     | 
| 
       11 
     | 
    
         
            -
                        process.env.OAUTH_CLIENT_ID ||
         
     | 
| 
       12 
     | 
    
         
            -
                        dispatcher._oauth.clientId;
         
     | 
| 
      
 7 
     | 
    
         
            +
                        throw new Error('authorizationURL not configured');
         
     | 
| 
      
 8 
     | 
    
         
            +
                    const clientId = decrypted.clientId || process.env.OAUTH_CLIENT_ID || dispatcher._oauth.clientId;
         
     | 
| 
       13 
9 
     | 
    
         
             
                    if (!clientId)
         
     | 
| 
       14 
     | 
    
         
            -
                        throw new Error( 
     | 
| 
       15 
     | 
    
         
            -
                    const scopes = process.env.OAUTH_SCOPE ||
         
     | 
| 
       16 
     | 
    
         
            -
                        decrypted.scope ||
         
     | 
| 
       17 
     | 
    
         
            -
                        dispatcher._oauth.scope ||
         
     | 
| 
       18 
     | 
    
         
            -
                        "";
         
     | 
| 
      
 10 
     | 
    
         
            +
                        throw new Error('clientId not configured');
         
     | 
| 
      
 11 
     | 
    
         
            +
                    const scopes = process.env.OAUTH_SCOPE || decrypted.scope || dispatcher._oauth.scope || '';
         
     | 
| 
       19 
12 
     | 
    
         
             
                    const useCodeChallenge = !!dispatcher._oauth.useCodeChallenge;
         
     | 
| 
       20 
13 
     | 
    
         
             
                    return {
         
     | 
| 
       21 
14 
     | 
    
         
             
                        url: authorizationURL
         
     | 
| 
         @@ -18,26 +18,26 @@ export default class Dispatcher { 
     | 
|
| 
       18 
18 
     | 
    
         
             
                            oauth: true,
         
     | 
| 
       19 
19 
     | 
    
         
             
                            fields: {
         
     | 
| 
       20 
20 
     | 
    
         
             
                                oauthResult: {
         
     | 
| 
       21 
     | 
    
         
            -
                                    name:  
     | 
| 
       22 
     | 
    
         
            -
                                    placeholder:  
     | 
| 
       23 
     | 
    
         
            -
                                    type:  
     | 
| 
      
 21 
     | 
    
         
            +
                                    name: 'OAuth Result',
         
     | 
| 
      
 22 
     | 
    
         
            +
                                    placeholder: 'will be set by finishing the oauth flow',
         
     | 
| 
      
 23 
     | 
    
         
            +
                                    type: 'managed',
         
     | 
| 
       24 
24 
     | 
    
         
             
                                },
         
     | 
| 
       25 
25 
     | 
    
         
             
                            },
         
     | 
| 
       26 
26 
     | 
    
         
             
                        });
         
     | 
| 
       27 
27 
     | 
    
         
             
                        return this;
         
     | 
| 
       28 
28 
     | 
    
         
             
                    }
         
     | 
| 
       29 
29 
     | 
    
         
             
                    if (!arg.authorizationURL)
         
     | 
| 
       30 
     | 
    
         
            -
                        throw new Error( 
     | 
| 
      
 30 
     | 
    
         
            +
                        throw new Error('need a authorizationURL');
         
     | 
| 
       31 
31 
     | 
    
         
             
                    if (!arg.tokenURL && !arg.finishOAuth)
         
     | 
| 
       32 
     | 
    
         
            -
                        throw new Error( 
     | 
| 
      
 32 
     | 
    
         
            +
                        throw new Error('need a tokenURL or finishOAuth()');
         
     | 
| 
       33 
33 
     | 
    
         
             
                    this._oauth = { ...arg };
         
     | 
| 
       34 
34 
     | 
    
         
             
                    this.config({
         
     | 
| 
       35 
35 
     | 
    
         
             
                        oauth: true,
         
     | 
| 
       36 
36 
     | 
    
         
             
                        fields: {
         
     | 
| 
       37 
37 
     | 
    
         
             
                            oauthResult: {
         
     | 
| 
       38 
     | 
    
         
            -
                                name:  
     | 
| 
       39 
     | 
    
         
            -
                                placeholder:  
     | 
| 
       40 
     | 
    
         
            -
                                type:  
     | 
| 
      
 38 
     | 
    
         
            +
                                name: 'OAuth Result',
         
     | 
| 
      
 39 
     | 
    
         
            +
                                placeholder: 'will be set by finishing the oauth flow',
         
     | 
| 
      
 40 
     | 
    
         
            +
                                type: 'managed',
         
     | 
| 
       41 
41 
     | 
    
         
             
                                optional: !!arg.connectionOptional,
         
     | 
| 
       42 
42 
     | 
    
         
             
                            },
         
     | 
| 
       43 
43 
     | 
    
         
             
                        },
         
     | 
| 
         @@ -46,17 +46,17 @@ export default class Dispatcher { 
     | 
|
| 
       46 
46 
     | 
    
         
             
                        this.config({
         
     | 
| 
       47 
47 
     | 
    
         
             
                            fields: {
         
     | 
| 
       48 
48 
     | 
    
         
             
                                clientId: {
         
     | 
| 
       49 
     | 
    
         
            -
                                    name:  
     | 
| 
       50 
     | 
    
         
            -
                                    placeholder:  
     | 
| 
       51 
     | 
    
         
            -
                                    type:  
     | 
| 
      
 49 
     | 
    
         
            +
                                    name: 'OAuth Client ID',
         
     | 
| 
      
 50 
     | 
    
         
            +
                                    placeholder: 'e.g. 1234',
         
     | 
| 
      
 51 
     | 
    
         
            +
                                    type: 'line',
         
     | 
| 
       52 
52 
     | 
    
         
             
                                    optional: !!arg.configurableClientOptional,
         
     | 
| 
       53 
53 
     | 
    
         
             
                                    plain: true,
         
     | 
| 
       54 
54 
     | 
    
         
             
                                },
         
     | 
| 
       55 
55 
     | 
    
         
             
                                clientSecret: {
         
     | 
| 
       56 
     | 
    
         
            -
                                    name:  
     | 
| 
       57 
     | 
    
         
            -
                                    placeholder:  
     | 
| 
      
 56 
     | 
    
         
            +
                                    name: 'OAuth Client Secret',
         
     | 
| 
      
 57 
     | 
    
         
            +
                                    placeholder: 'e.g. axd5xde',
         
     | 
| 
       58 
58 
     | 
    
         
             
                                    optional: !!arg.configurableClientOptional,
         
     | 
| 
       59 
     | 
    
         
            -
                                    type:  
     | 
| 
      
 59 
     | 
    
         
            +
                                    type: 'line',
         
     | 
| 
       60 
60 
     | 
    
         
             
                                },
         
     | 
| 
       61 
61 
     | 
    
         
             
                            },
         
     | 
| 
       62 
62 
     | 
    
         
             
                        });
         
     | 
| 
         @@ -65,9 +65,9 @@ export default class Dispatcher { 
     | 
|
| 
       65 
65 
     | 
    
         
             
                        this.config({
         
     | 
| 
       66 
66 
     | 
    
         
             
                            fields: {
         
     | 
| 
       67 
67 
     | 
    
         
             
                                scope: {
         
     | 
| 
       68 
     | 
    
         
            -
                                    name:  
     | 
| 
       69 
     | 
    
         
            -
                                    placeholder:  
     | 
| 
       70 
     | 
    
         
            -
                                    type:  
     | 
| 
      
 68 
     | 
    
         
            +
                                    name: 'OAuth Scope',
         
     | 
| 
      
 69 
     | 
    
         
            +
                                    placeholder: 'e.g. x y z',
         
     | 
| 
      
 70 
     | 
    
         
            +
                                    type: 'line',
         
     | 
| 
       71 
71 
     | 
    
         
             
                                    description: `Default Scope:
         
     | 
| 
       72 
72 
     | 
    
         | 
| 
       73 
73 
     | 
    
         
             
            ${arg.configurableClientScope}
         
     | 
| 
         @@ -99,9 +99,9 @@ ${arg.configurableClientScope} 
     | 
|
| 
       99 
99 
     | 
    
         
             
                    this.config({
         
     | 
| 
       100 
100 
     | 
    
         
             
                        fields: {
         
     | 
| 
       101 
101 
     | 
    
         
             
                            _endpointToken: {
         
     | 
| 
       102 
     | 
    
         
            -
                                name:  
     | 
| 
       103 
     | 
    
         
            -
                                placeholder:  
     | 
| 
       104 
     | 
    
         
            -
                                type: !!notOptional ?  
     | 
| 
      
 102 
     | 
    
         
            +
                                name: 'Endpoint Token',
         
     | 
| 
      
 103 
     | 
    
         
            +
                                placeholder: 'e.g. 1234',
         
     | 
| 
      
 104 
     | 
    
         
            +
                                type: !!notOptional ? 'managed' : 'line',
         
     | 
| 
       105 
105 
     | 
    
         
             
                                plain: true,
         
     | 
| 
       106 
106 
     | 
    
         
             
                                optional: !notOptional,
         
     | 
| 
       107 
107 
     | 
    
         
             
                            },
         
     | 
| 
         @@ -111,19 +111,19 @@ ${arg.configurableClientScope} 
     | 
|
| 
       111 
111 
     | 
    
         
             
                    return this;
         
     | 
| 
       112 
112 
     | 
    
         
             
                }
         
     | 
| 
       113 
113 
     | 
    
         
             
                async startOAuth() {
         
     | 
| 
       114 
     | 
    
         
            -
                    throw new Error( 
     | 
| 
      
 114 
     | 
    
         
            +
                    throw new Error('oauth not configured');
         
     | 
| 
       115 
115 
     | 
    
         
             
                }
         
     | 
| 
       116 
116 
     | 
    
         
             
                async finishOAuth(arg) {
         
     | 
| 
       117 
     | 
    
         
            -
                    throw new Error( 
     | 
| 
      
 117 
     | 
    
         
            +
                    throw new Error('oauth not configured');
         
     | 
| 
       118 
118 
     | 
    
         
             
                }
         
     | 
| 
       119 
119 
     | 
    
         
             
                build() {
         
     | 
| 
       120 
120 
     | 
    
         
             
                    if (!this._types || !this._resolvers)
         
     | 
| 
       121 
     | 
    
         
            -
                        throw new Error( 
     | 
| 
      
 121 
     | 
    
         
            +
                        throw new Error('missing types or resolvers');
         
     | 
| 
       122 
122 
     | 
    
         
             
                    var local = this;
         
     | 
| 
       123 
123 
     | 
    
         
             
                    const _resolvers = { ...this._resolvers };
         
     | 
| 
       124 
124 
     | 
    
         
             
                    const main = this._main || (() => { });
         
     | 
| 
       125 
125 
     | 
    
         
             
                    const start = async (arg) => {
         
     | 
| 
       126 
     | 
    
         
            -
                        console.log( 
     | 
| 
      
 126 
     | 
    
         
            +
                        console.log('starting ...');
         
     | 
| 
       127 
127 
     | 
    
         
             
                        await main(arg);
         
     | 
| 
       128 
128 
     | 
    
         
             
                    };
         
     | 
| 
       129 
129 
     | 
    
         
             
                    const resolveMethod = (query) => {
         
     | 
| 
         @@ -137,47 +137,36 @@ ${arg.configurableClientScope} 
     | 
|
| 
       137 
137 
     | 
    
         
             
                        if (!Array.isArray(query))
         
     | 
| 
       138 
138 
     | 
    
         
             
                            query = [query];
         
     | 
| 
       139 
139 
     | 
    
         
             
                        query = query
         
     | 
| 
       140 
     | 
    
         
            -
                            .filter((what) => !!what?.trim() &&
         
     | 
| 
       141 
     | 
    
         
            -
                            ![
         
     | 
| 
       142 
     | 
    
         
            -
                                "constructor",
         
     | 
| 
       143 
     | 
    
         
            -
                                "__proto__",
         
     | 
| 
       144 
     | 
    
         
            -
                                "toString",
         
     | 
| 
       145 
     | 
    
         
            -
                                "toSource",
         
     | 
| 
       146 
     | 
    
         
            -
                                "prototype",
         
     | 
| 
       147 
     | 
    
         
            -
                            ].includes(what))
         
     | 
| 
      
 140 
     | 
    
         
            +
                            .filter((what) => !!what?.trim() && !['constructor', '__proto__', 'toString', 'toSource', 'prototype'].includes(what))
         
     | 
| 
       148 
141 
     | 
    
         
             
                            .slice(0, 20);
         
     | 
| 
       149 
142 
     | 
    
         
             
                        const method = resolveMethod(query);
         
     | 
| 
       150 
143 
     | 
    
         
             
                        if (!method && !_resolvers.__default)
         
     | 
| 
       151 
144 
     | 
    
         
             
                            throw new Error(`${query} not found`);
         
     | 
| 
       152 
     | 
    
         
            -
                        return method
         
     | 
| 
       153 
     | 
    
         
            -
                            ? method(variables)
         
     | 
| 
       154 
     | 
    
         
            -
                            : _resolvers.__default(variables ? { ...variables, __method: query } : variables);
         
     | 
| 
      
 145 
     | 
    
         
            +
                        return method ? method(variables) : _resolvers.__default(variables ? { ...variables, __method: query } : variables);
         
     | 
| 
       155 
146 
     | 
    
         
             
                    };
         
     | 
| 
       156 
147 
     | 
    
         
             
                    const introspect = () => local._types;
         
     | 
| 
       157 
148 
     | 
    
         
             
                    const configSchema = () => local._config;
         
     | 
| 
       158 
149 
     | 
    
         
             
                    const processPacket = async (packet) => {
         
     | 
| 
       159 
150 
     | 
    
         
             
                        switch (packet.method()) {
         
     | 
| 
       160 
     | 
    
         
            -
                            case  
     | 
| 
      
 151 
     | 
    
         
            +
                            case 'connector.introspect':
         
     | 
| 
       161 
152 
     | 
    
         
             
                                // @ts-ignore
         
     | 
| 
       162 
153 
     | 
    
         
             
                                const intro = await introspect({});
         
     | 
| 
       163 
154 
     | 
    
         
             
                                return { configSchema: local._config, introspect: intro };
         
     | 
| 
       164 
     | 
    
         
            -
                            case  
     | 
| 
      
 155 
     | 
    
         
            +
                            case 'connector.start-oauth':
         
     | 
| 
       165 
156 
     | 
    
         
             
                                // @ts-ignore
         
     | 
| 
       166 
157 
     | 
    
         
             
                                return await local.startOAuth(packet.args());
         
     | 
| 
       167 
     | 
    
         
            -
                            case  
     | 
| 
      
 158 
     | 
    
         
            +
                            case 'connector.finish-oauth':
         
     | 
| 
       168 
159 
     | 
    
         
             
                                // @ts-ignore
         
     | 
| 
       169 
160 
     | 
    
         
             
                                return await local.finishOAuth(packet.args());
         
     | 
| 
       170 
     | 
    
         
            -
                            case  
     | 
| 
      
 161 
     | 
    
         
            +
                            case 'connector.query':
         
     | 
| 
       171 
162 
     | 
    
         
             
                                const ret = await execute(packet.args());
         
     | 
| 
       172 
     | 
    
         
            -
                                return typeof ret ===  
     | 
| 
       173 
     | 
    
         
            -
             
     | 
| 
       174 
     | 
    
         
            -
                                    : { [packet.args().query]: ret };
         
     | 
| 
       175 
     | 
    
         
            -
                            case "connector.set-config":
         
     | 
| 
      
 163 
     | 
    
         
            +
                                return typeof ret === 'object' && !Array.isArray(ret) ? ret : { [packet.args().query]: ret };
         
     | 
| 
      
 164 
     | 
    
         
            +
                            case 'connector.set-config':
         
     | 
| 
       176 
165 
     | 
    
         
             
                                await local.onConfig({ ...packet.args().secrets });
         
     | 
| 
       177 
166 
     | 
    
         
             
                                return;
         
     | 
| 
       178 
167 
     | 
    
         
             
                        }
         
     | 
| 
       179 
168 
     | 
    
         
             
                        console.dir(packet, { depth: null });
         
     | 
| 
       180 
     | 
    
         
            -
                        throw new Error( 
     | 
| 
      
 169 
     | 
    
         
            +
                        throw new Error('cannot handle packet');
         
     | 
| 
       181 
170 
     | 
    
         
             
                    };
         
     | 
| 
       182 
171 
     | 
    
         
             
                    return {
         
     | 
| 
       183 
172 
     | 
    
         
             
                        introspect,
         
     | 
| 
         @@ -188,7 +177,7 @@ ${arg.configurableClientScope} 
     | 
|
| 
       188 
177 
     | 
    
         
             
                    };
         
     | 
| 
       189 
178 
     | 
    
         
             
                }
         
     | 
| 
       190 
179 
     | 
    
         
             
                onConfig(arg0) {
         
     | 
| 
       191 
     | 
    
         
            -
                    throw new Error( 
     | 
| 
      
 180 
     | 
    
         
            +
                    throw new Error('Method not implemented.');
         
     | 
| 
       192 
181 
     | 
    
         
             
                }
         
     | 
| 
       193 
182 
     | 
    
         
             
            }
         
     | 
| 
       194 
183 
     | 
    
         
             
            export { Dispatcher };
         
     | 
| 
         @@ -7,7 +7,7 @@ export default class Fetcher { 
     | 
|
| 
       7 
7 
     | 
    
         
             
                protected baseUrl: any;
         
     | 
| 
       8 
8 
     | 
    
         
             
                protected onResponse: any;
         
     | 
| 
       9 
9 
     | 
    
         
             
                protected customize0: any;
         
     | 
| 
       10 
     | 
    
         
            -
                constructor({ retry, baseUrl, onResponse, customize }?: {
         
     | 
| 
      
 10 
     | 
    
         
            +
                constructor({ retry, baseUrl, onResponse, customize, }?: {
         
     | 
| 
       11 
11 
     | 
    
         
             
                    retry?: number;
         
     | 
| 
       12 
12 
     | 
    
         
             
                    baseUrl?: string;
         
     | 
| 
       13 
13 
     | 
    
         
             
                    onResponse?: (response: Response) => void;
         
     |