@vida-global/apps-tools 1.0.7 → 1.0.9
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.
|
@@ -18,13 +18,13 @@ class AbstractAppManager {
|
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
get attachedToAppServer() {
|
|
21
|
-
return this.constructor.name
|
|
21
|
+
return this.constructor.name === 'AppServerAppManager';
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
get providerManager() {
|
|
26
26
|
if (!this.#providerManager) {
|
|
27
|
-
this.#providerManager = new ProviderManager(this.redisClient, this.attachedToAppServer);
|
|
27
|
+
this.#providerManager = new ProviderManager(this, this.redisClient, this.attachedToAppServer);
|
|
28
28
|
}
|
|
29
29
|
return this.#providerManager;
|
|
30
30
|
}
|
|
@@ -52,19 +52,20 @@ class VaderApiClient extends HttpClient {
|
|
|
52
52
|
|
|
53
53
|
|
|
54
54
|
async #invokeAction(actionType, responseCls, app, actionName, actionArgs, userContext) {
|
|
55
|
-
const endpoint
|
|
55
|
+
const endpoint = `/invoke/app/${actionType}/${app.id()}/${app.version()}/${actionName}`
|
|
56
|
+
const argsParamName = `${actionType}Args`;
|
|
56
57
|
const body = {
|
|
57
|
-
userContext:
|
|
58
|
-
appManifest:
|
|
59
|
-
actionArgs,
|
|
58
|
+
userContext: userContext?.toDict() || null,
|
|
59
|
+
appManifest: await app.getCompositeManifest(),
|
|
60
|
+
[argsParamName]: actionArgs,
|
|
60
61
|
};
|
|
61
62
|
|
|
62
63
|
try {
|
|
63
64
|
const { data } = await this.post(endpoint, userContext, body);
|
|
64
|
-
if (data.
|
|
65
|
-
return data.data;
|
|
66
|
-
} else {
|
|
65
|
+
if (data.functionName) {
|
|
67
66
|
return data;
|
|
67
|
+
} else {
|
|
68
|
+
return data.data;
|
|
68
69
|
}
|
|
69
70
|
} catch(err) {
|
|
70
71
|
const appResponse = new responseCls();
|
|
@@ -4,7 +4,7 @@ const { logger } = require('@vida-global/core');
|
|
|
4
4
|
|
|
5
5
|
class BaseProviderConfigurator {
|
|
6
6
|
constructor(userContext, redisClient, type, name,
|
|
7
|
-
globalProviderConfig, appId, appVersion) {
|
|
7
|
+
globalProviderConfig, appId, appVersion, appManager = null) {
|
|
8
8
|
this.userContext = userContext;
|
|
9
9
|
this.redis = redisClient;
|
|
10
10
|
this.type = type;
|
|
@@ -13,6 +13,7 @@ class BaseProviderConfigurator {
|
|
|
13
13
|
this.appId = appId;
|
|
14
14
|
this.appVersion = appVersion;
|
|
15
15
|
this.hasBuiltRoutes = false;
|
|
16
|
+
this.appManager = appManager;
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
async _initialize() {
|
|
@@ -41,7 +42,7 @@ class BaseProvider {
|
|
|
41
42
|
constructor(
|
|
42
43
|
userContext, redisClient, vanillaConfig = null,
|
|
43
44
|
appId = null, appVersion = null,
|
|
44
|
-
isServer = false
|
|
45
|
+
isServer = false, appManager = null
|
|
45
46
|
) {
|
|
46
47
|
this.userContext = userContext;
|
|
47
48
|
this.redis = redisClient;
|
|
@@ -50,17 +51,18 @@ class BaseProvider {
|
|
|
50
51
|
this.appId = appId;
|
|
51
52
|
this.appVersion = appVersion;
|
|
52
53
|
this.globalConfig = {};
|
|
54
|
+
this.appManager = appManager;
|
|
53
55
|
}
|
|
54
56
|
|
|
55
57
|
static async get(providerCls, {
|
|
56
58
|
userContext, redisClient, vanillaConfig,
|
|
57
59
|
appId, appVersion,
|
|
58
|
-
isServer = false
|
|
60
|
+
isServer = false, appManager
|
|
59
61
|
}) {
|
|
60
62
|
const provider = new providerCls(
|
|
61
63
|
userContext, redisClient, vanillaConfig,
|
|
62
64
|
appId, appVersion,
|
|
63
|
-
isServer
|
|
65
|
+
isServer, appManager
|
|
64
66
|
);
|
|
65
67
|
await provider._initialize();
|
|
66
68
|
return provider
|
|
@@ -70,7 +72,7 @@ class BaseProvider {
|
|
|
70
72
|
const configurator = new this.configurator(
|
|
71
73
|
this.userContext, this.redis, this.type, this.name,
|
|
72
74
|
this.globalConfig,
|
|
73
|
-
this.appId, this.appVersion,
|
|
75
|
+
this.appId, this.appVersion, this.appManager
|
|
74
76
|
)
|
|
75
77
|
await configurator._initialize()
|
|
76
78
|
return configurator
|
|
@@ -4,9 +4,11 @@ const { logger } = require('@vida-global/core')
|
|
|
4
4
|
class ProviderManager {
|
|
5
5
|
#isServer;
|
|
6
6
|
#redisClient;
|
|
7
|
+
#appManager;
|
|
7
8
|
|
|
8
9
|
|
|
9
|
-
constructor(redisClient, isServer) {
|
|
10
|
+
constructor(appManager, redisClient, isServer) {
|
|
11
|
+
this.#appManager = appManager;
|
|
10
12
|
this.#isServer = isServer;
|
|
11
13
|
this.#redisClient = redisClient;
|
|
12
14
|
}
|
|
@@ -41,6 +43,7 @@ class ProviderManager {
|
|
|
41
43
|
vanillaConfig: vanillaConfig,
|
|
42
44
|
appId, appVersion,
|
|
43
45
|
isServer: this.#isServer,
|
|
46
|
+
appManager: this.#appManager
|
|
44
47
|
}
|
|
45
48
|
)
|
|
46
49
|
}
|
|
@@ -36,7 +36,7 @@ class HubspotOAuthConfigurator extends BaseProviderConfigurator {
|
|
|
36
36
|
let ctx = this.userContext
|
|
37
37
|
if (!ctx) {
|
|
38
38
|
// Build a new user context using our own
|
|
39
|
-
ctx = new VaderUserContext(this)
|
|
39
|
+
ctx = new VaderUserContext(this.appManager)
|
|
40
40
|
await ctx.load({ user })
|
|
41
41
|
}
|
|
42
42
|
let providerConfig = await ctx.getProviderConfig(
|
|
@@ -66,6 +66,7 @@ class HubspotOAuthConfigurator extends BaseProviderConfigurator {
|
|
|
66
66
|
logger.warn('OAuth routes already built');
|
|
67
67
|
return
|
|
68
68
|
}
|
|
69
|
+
logger.info('Building OAuth routes')
|
|
69
70
|
|
|
70
71
|
app.get(oAuthConfig.initiateOAuthUrl, async (req, res) => {
|
|
71
72
|
let {redirectUri, finalUri, userId, appId, appVersion} = req.query;
|