@activepieces/piece-metabase 0.0.3 → 0.1.0
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/package.json +5 -5
- package/src/index.d.ts +2 -6
- package/src/index.js +10 -14
- package/src/index.js.map +1 -1
- package/src/lib/actions/get-question.d.ts +1 -3
- package/src/lib/actions/get-question.js +4 -4
- package/src/lib/actions/get-question.js.map +1 -1
- package/src/lib/common.d.ts +3 -4
- package/src/lib/common.js +7 -78
- package/src/lib/common.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@activepieces/piece-metabase",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"@sinclair/typebox": "0.26.8",
|
|
6
|
-
"axios": "
|
|
6
|
+
"axios": "1.6.7",
|
|
7
7
|
"dayjs": "1.11.9",
|
|
8
8
|
"is-base64": "1.1.0",
|
|
9
9
|
"lodash": "4.17.21",
|
|
10
10
|
"nanoid": "3.3.6",
|
|
11
11
|
"semver": "7.6.0",
|
|
12
|
-
"@activepieces/pieces-common": "0.2.
|
|
13
|
-
"@activepieces/pieces-framework": "0.7.
|
|
14
|
-
"@activepieces/shared": "0.10.
|
|
12
|
+
"@activepieces/pieces-common": "0.2.12",
|
|
13
|
+
"@activepieces/pieces-framework": "0.7.30",
|
|
14
|
+
"@activepieces/shared": "0.10.104",
|
|
15
15
|
"tslib": "1.14.1"
|
|
16
16
|
},
|
|
17
17
|
"main": "./src/index.js",
|
package/src/index.d.ts
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
export declare const metabaseAuth: import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
2
|
-
username: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
3
|
-
password: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
4
2
|
baseUrl: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
5
|
-
|
|
3
|
+
apiKey: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
6
4
|
}>;
|
|
7
5
|
export declare const metabase: import("@activepieces/pieces-framework").Piece<import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
8
|
-
username: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
9
|
-
password: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
10
6
|
baseUrl: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
11
|
-
|
|
7
|
+
apiKey: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
12
8
|
}>>;
|
package/src/index.js
CHANGED
|
@@ -5,31 +5,27 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const pieces_framework_1 = require("@activepieces/pieces-framework");
|
|
6
6
|
const get_question_1 = require("./lib/actions/get-question");
|
|
7
7
|
const common_1 = require("./lib/common");
|
|
8
|
+
const pieces_common_1 = require("@activepieces/pieces-common");
|
|
8
9
|
exports.metabaseAuth = pieces_framework_1.PieceAuth.CustomAuth({
|
|
9
10
|
description: 'Metabase authentication requires a username and password.',
|
|
10
11
|
required: true,
|
|
11
12
|
props: {
|
|
12
|
-
username: pieces_framework_1.Property.ShortText({
|
|
13
|
-
displayName: 'User email',
|
|
14
|
-
required: true,
|
|
15
|
-
}),
|
|
16
|
-
password: pieces_framework_1.PieceAuth.SecretText({
|
|
17
|
-
displayName: 'Password',
|
|
18
|
-
required: true,
|
|
19
|
-
}),
|
|
20
13
|
baseUrl: pieces_framework_1.Property.ShortText({
|
|
21
14
|
displayName: 'Metabase API base URL',
|
|
22
15
|
required: true,
|
|
23
16
|
}),
|
|
24
|
-
|
|
25
|
-
displayName: '
|
|
26
|
-
description: 'Generate one
|
|
17
|
+
apiKey: pieces_framework_1.PieceAuth.SecretText({
|
|
18
|
+
displayName: 'API key',
|
|
19
|
+
description: 'Generate one on your Metabase instance (settings -> authentication -> API keys)',
|
|
27
20
|
required: true,
|
|
28
21
|
}),
|
|
29
22
|
},
|
|
30
23
|
validate: ({ auth }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
31
24
|
try {
|
|
32
|
-
yield (0, common_1.
|
|
25
|
+
yield (0, common_1.queryMetabaseApi)({
|
|
26
|
+
endpoint: 'login-history/current',
|
|
27
|
+
method: pieces_common_1.HttpMethod.GET,
|
|
28
|
+
}, auth);
|
|
33
29
|
return {
|
|
34
30
|
valid: true,
|
|
35
31
|
};
|
|
@@ -37,7 +33,7 @@ exports.metabaseAuth = pieces_framework_1.PieceAuth.CustomAuth({
|
|
|
37
33
|
catch (e) {
|
|
38
34
|
return {
|
|
39
35
|
valid: false,
|
|
40
|
-
error: 'Invalid API Key or
|
|
36
|
+
error: 'Invalid API Key or base URL',
|
|
41
37
|
};
|
|
42
38
|
}
|
|
43
39
|
}),
|
|
@@ -48,7 +44,7 @@ exports.metabase = (0, pieces_framework_1.createPiece)({
|
|
|
48
44
|
auth: exports.metabaseAuth,
|
|
49
45
|
minimumSupportedRelease: '0.9.0',
|
|
50
46
|
logoUrl: 'https://cdn.activepieces.com/pieces/metabase.png',
|
|
51
|
-
authors: [
|
|
47
|
+
authors: ['AdamSelene', 'abuaboud'],
|
|
52
48
|
actions: [get_question_1.getQuestion],
|
|
53
49
|
triggers: [],
|
|
54
50
|
});
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/pieces/community/metabase/src/index.ts"],"names":[],"mappings":";;;;AAAA,qEAIwC;AACxC,6DAAyD;AACzD,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/pieces/community/metabase/src/index.ts"],"names":[],"mappings":";;;;AAAA,qEAIwC;AACxC,6DAAyD;AACzD,yCAAgD;AAChD,+DAAyD;AAE5C,QAAA,YAAY,GAAG,4BAAS,CAAC,UAAU,CAAC;IAC/C,WAAW,EAAE,2DAA2D;IACxE,QAAQ,EAAE,IAAI;IACd,KAAK,EAAE;QACL,OAAO,EAAE,2BAAQ,CAAC,SAAS,CAAC;YAC1B,WAAW,EAAE,uBAAuB;YACpC,QAAQ,EAAE,IAAI;SACf,CAAC;QACF,MAAM,EAAE,4BAAS,CAAC,UAAU,CAAC;YAC3B,WAAW,EAAE,SAAS;YACtB,WAAW,EACT,iFAAiF;YACnF,QAAQ,EAAE,IAAI;SACf,CAAC;KACH;IAED,QAAQ,EAAE,CAAO,EAAE,IAAI,EAAE,EAAE,EAAE;QAC3B,IAAI,CAAC;YACH,MAAM,IAAA,yBAAgB,EACpB;gBACE,QAAQ,EAAE,uBAAuB;gBACjC,MAAM,EAAE,0BAAU,CAAC,GAAG;aACvB,EACD,IAAI,CACL,CAAC;YACF,OAAO;gBACL,KAAK,EAAE,IAAI;aACZ,CAAC;QACJ,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,OAAO;gBACL,KAAK,EAAE,KAAK;gBACZ,KAAK,EAAE,6BAA6B;aACrC,CAAC;QACJ,CAAC;IACH,CAAC,CAAA;CACF,CAAC,CAAC;AACU,QAAA,QAAQ,GAAG,IAAA,8BAAW,EAAC;IAClC,WAAW,EAAE,UAAU;IACvB,WAAW,EAAE,uDAAuD;IAEpE,IAAI,EAAE,oBAAY;IAClB,uBAAuB,EAAE,OAAO;IAChC,OAAO,EAAE,kDAAkD;IAC3D,OAAO,EAAE,CAAC,YAAY,EAAE,UAAU,CAAC;IACnC,OAAO,EAAE,CAAC,0BAAW,CAAC;IACtB,QAAQ,EAAE,EAAE;CACb,CAAC,CAAC"}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
export declare const getQuestion: import("@activepieces/pieces-framework").IAction<import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
2
|
-
username: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
3
|
-
password: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
4
2
|
baseUrl: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
5
|
-
|
|
3
|
+
apiKey: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
6
4
|
}>, {
|
|
7
5
|
questionId: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
8
6
|
parameters: import("@activepieces/pieces-framework").ObjectProperty<false>;
|
|
@@ -22,11 +22,11 @@ exports.getQuestion = (0, pieces_framework_1.createAction)({
|
|
|
22
22
|
required: false,
|
|
23
23
|
}),
|
|
24
24
|
},
|
|
25
|
-
run({ auth,
|
|
25
|
+
run({ auth, propsValue }) {
|
|
26
26
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
27
|
-
const card = yield (0, common_1.
|
|
27
|
+
const card = yield (0, common_1.queryMetabaseApi)({ endpoint: `card/${propsValue.questionId}`, method: pieces_common_1.HttpMethod.GET }, auth);
|
|
28
28
|
const parameters = card['parameters'];
|
|
29
|
-
return (0, common_1.
|
|
29
|
+
return (0, common_1.queryMetabaseApi)({
|
|
30
30
|
endpoint: `card/${propsValue.questionId}/query`,
|
|
31
31
|
method: pieces_common_1.HttpMethod.POST,
|
|
32
32
|
body: {
|
|
@@ -44,7 +44,7 @@ exports.getQuestion = (0, pieces_framework_1.createAction)({
|
|
|
44
44
|
};
|
|
45
45
|
}),
|
|
46
46
|
},
|
|
47
|
-
}, auth
|
|
47
|
+
}, auth);
|
|
48
48
|
});
|
|
49
49
|
},
|
|
50
50
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-question.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/metabase/src/lib/actions/get-question.ts"],"names":[],"mappings":";;;;AAAA,qEAAwE;AACxE,
|
|
1
|
+
{"version":3,"file":"get-question.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/metabase/src/lib/actions/get-question.ts"],"names":[],"mappings":";;;;AAAA,qEAAwE;AACxE,sCAA6C;AAC7C,6BAAqC;AACrC,+DAAyD;AAS5C,QAAA,WAAW,G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,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC;yBAC7D,CAAC;oBACJ,CAAC,CAAC;iBACL;aACF,EACD,IAAI,CACL,CAAC;QACJ,CAAC;KAAA;CACF,CAAC,CAAC"}
|
package/src/lib/common.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { HttpHeaders, HttpMethod, QueryParams } from '@activepieces/pieces-common';
|
|
2
|
-
import { CustomAuthProps, StaticPropsValue
|
|
3
|
-
export declare function
|
|
4
|
-
export declare function queryApiAndHandleRefresh(params: {
|
|
2
|
+
import { CustomAuthProps, StaticPropsValue } from '@activepieces/pieces-framework';
|
|
3
|
+
export declare function queryMetabaseApi(params: {
|
|
5
4
|
endpoint: string;
|
|
6
5
|
method: HttpMethod;
|
|
7
6
|
queryParams?: QueryParams;
|
|
8
7
|
headers?: HttpHeaders;
|
|
9
8
|
body?: object;
|
|
10
|
-
}, auth: StaticPropsValue<CustomAuthProps
|
|
9
|
+
}, auth: StaticPropsValue<CustomAuthProps>): Promise<any>;
|
package/src/lib/common.js
CHANGED
|
@@ -1,91 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.queryMetabaseApi = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const crypto_1 = tslib_1.__importDefault(require("crypto"));
|
|
6
5
|
const pieces_common_1 = require("@activepieces/pieces-common");
|
|
7
|
-
|
|
8
|
-
const shared_1 = require("@activepieces/shared");
|
|
9
|
-
const algorithm = 'aes-256-cbc';
|
|
10
|
-
const ivLength = 16;
|
|
11
|
-
const SESSION_TOKEN_KEY = '_session_token';
|
|
12
|
-
function encryptString(inputString, key) {
|
|
13
|
-
const iv = crypto_1.default.randomBytes(ivLength); // Generate a random initialization vector
|
|
14
|
-
const cipher = crypto_1.default.createCipheriv(algorithm, Buffer.from(key, 'binary'), iv); // Create a cipher with the key and initialization vector
|
|
15
|
-
let encrypted = cipher.update(inputString, 'utf8', 'hex');
|
|
16
|
-
encrypted += cipher.final('hex');
|
|
17
|
-
return {
|
|
18
|
-
iv: iv.toString('hex'),
|
|
19
|
-
data: encrypted,
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
function decryptString(encryptedObject, key) {
|
|
23
|
-
const iv = Buffer.from(encryptedObject.iv, 'hex');
|
|
24
|
-
const decipher = crypto_1.default.createDecipheriv(algorithm, Buffer.from(key, 'binary'), iv);
|
|
25
|
-
let decrypted = decipher.update(encryptedObject.data, 'hex', 'utf8');
|
|
26
|
-
decrypted += decipher.final('utf8');
|
|
27
|
-
return decrypted;
|
|
28
|
-
}
|
|
29
|
-
function refreshSessionToken(auth) {
|
|
30
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
31
|
-
const { username, password, baseUrl } = auth;
|
|
32
|
-
const request = {
|
|
33
|
-
method: pieces_common_1.HttpMethod.POST,
|
|
34
|
-
url: `${baseUrl}/api/session`,
|
|
35
|
-
headers: {
|
|
36
|
-
'Content-Type': 'application/json',
|
|
37
|
-
},
|
|
38
|
-
body: JSON.stringify({ username, password }),
|
|
39
|
-
};
|
|
40
|
-
const tokenResponse = yield pieces_common_1.httpClient.sendRequest(request);
|
|
41
|
-
return tokenResponse.body['id'];
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
exports.refreshSessionToken = refreshSessionToken;
|
|
45
|
-
function storeSessionToken(sessionToken, encryptionKey, store) {
|
|
46
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
47
|
-
return store.put(SESSION_TOKEN_KEY, encryptString(sessionToken, encryptionKey), pieces_framework_1.StoreScope.FLOW);
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
function queryApiAndHandleRefresh(params, auth, store) {
|
|
6
|
+
function queryMetabaseApi(params, auth) {
|
|
51
7
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
52
|
-
const { baseUrl, encryptionKey } = auth;
|
|
53
|
-
let sessionToken;
|
|
54
|
-
const encryptedToken = yield store.get(SESSION_TOKEN_KEY, pieces_framework_1.StoreScope.FLOW);
|
|
55
|
-
if ((0, shared_1.isNil)(encryptedToken)) {
|
|
56
|
-
sessionToken = yield refreshSessionToken(auth);
|
|
57
|
-
yield storeSessionToken(sessionToken, encryptionKey, store);
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
try {
|
|
61
|
-
sessionToken = decryptString(encryptedToken, encryptionKey);
|
|
62
|
-
}
|
|
63
|
-
catch (e) {
|
|
64
|
-
// This can happen when e.g. the connection / encryption key has changed
|
|
65
|
-
sessionToken = yield refreshSessionToken(auth);
|
|
66
|
-
yield storeSessionToken(sessionToken, encryptionKey, store);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
8
|
const request = {
|
|
70
9
|
method: params.method,
|
|
71
|
-
url: `${baseUrl}/api/${params.endpoint}`,
|
|
10
|
+
url: `${auth.baseUrl}/api/${params.endpoint}`,
|
|
72
11
|
queryParams: params.queryParams,
|
|
73
|
-
headers: Object.assign(Object.assign({}, params.headers), { 'Content-Type': 'application/json', 'X-
|
|
12
|
+
headers: Object.assign(Object.assign({}, params.headers), { 'Content-Type': 'application/json', 'X-API-KEY': auth.apiKey }),
|
|
74
13
|
body: JSON.stringify(params.body),
|
|
75
14
|
};
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
catch (error) {
|
|
80
|
-
const httpError = error;
|
|
81
|
-
if (httpError.response.status === 401) {
|
|
82
|
-
const sessionToken = yield refreshSessionToken(auth);
|
|
83
|
-
yield storeSessionToken(sessionToken, encryptionKey, store);
|
|
84
|
-
return (yield pieces_common_1.httpClient.sendRequest(request)).body;
|
|
85
|
-
}
|
|
86
|
-
throw error;
|
|
87
|
-
}
|
|
15
|
+
const response = yield pieces_common_1.httpClient.sendRequest(request);
|
|
16
|
+
return response.body;
|
|
88
17
|
});
|
|
89
18
|
}
|
|
90
|
-
exports.
|
|
19
|
+
exports.queryMetabaseApi = queryMetabaseApi;
|
|
91
20
|
//# sourceMappingURL=common.js.map
|
package/src/lib/common.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../../../../../packages/pieces/community/metabase/src/lib/common.ts"],"names":[],"mappings":";;;;AAAA
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../../../../../packages/pieces/community/metabase/src/lib/common.ts"],"names":[],"mappings":";;;;AAAA,+DAMqC;AAMrC,SAAsB,gBAAgB,CACpC,MAMC,EACD,IAAuC;;QAEvC,MAAM,OAAO,GAAgB;YAC3B,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,GAAG,EAAE,GAAG,IAAI,CAAC,OAAO,QAAQ,MAAM,CAAC,QAAQ,EAAE;YAC7C,WAAW,EAAE,MAAM,CAAC,WAAW;YAC/B,OAAO,kCACF,MAAM,CAAC,OAAO,KACjB,cAAc,EAAE,kBAAkB,EAClC,WAAW,EAAE,IAAI,CAAC,MAAgB,GACnC;YACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC;SAClC,CAAC;QACF,MAAM,QAAQ,GAAG,MAAM,0BAAU,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QACvD,OAAO,QAAQ,CAAC,IAAI,CAAC;IACvB,CAAC;CAAA;AAvBD,4CAuBC"}
|