@looker/run-it 0.9.23 → 0.9.27
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +82 -1
- package/lib/RunIt.d.ts +2 -2
- package/lib/RunIt.js +18 -30
- package/lib/RunIt.js.map +1 -1
- package/lib/RunItProvider.d.ts +0 -4
- package/lib/RunItProvider.js +2 -7
- package/lib/RunItProvider.js.map +1 -1
- package/lib/components/ConfigForm/ConfigForm.d.ts +1 -6
- package/lib/components/ConfigForm/ConfigForm.js +39 -48
- package/lib/components/ConfigForm/ConfigForm.js.map +1 -1
- package/lib/components/ConfigForm/index.d.ts +1 -1
- package/lib/components/ConfigForm/index.js +4 -4
- package/lib/components/ConfigForm/index.js.map +1 -1
- package/lib/components/ConfigForm/utils.d.ts +11 -0
- package/lib/components/ConfigForm/utils.js +81 -0
- package/lib/components/ConfigForm/utils.js.map +1 -0
- package/lib/components/LoginForm/LoginForm.d.ts +3 -8
- package/lib/components/LoginForm/LoginForm.js +9 -8
- package/lib/components/LoginForm/LoginForm.js.map +1 -1
- package/lib/components/PerfTracker/PerfTracker.d.ts +0 -2
- package/lib/components/PerfTracker/PerfTracker.js +7 -8
- package/lib/components/PerfTracker/PerfTracker.js.map +1 -1
- package/lib/components/RequestForm/RequestForm.d.ts +0 -6
- package/lib/components/RequestForm/RequestForm.js +0 -7
- package/lib/components/RequestForm/RequestForm.js.map +1 -1
- package/lib/components/common/index.d.ts +0 -1
- package/lib/components/common/index.js +0 -18
- package/lib/components/common/index.js.map +1 -1
- package/lib/esm/RunIt.js +19 -32
- package/lib/esm/RunIt.js.map +1 -1
- package/lib/esm/RunItProvider.js +2 -7
- package/lib/esm/RunItProvider.js.map +1 -1
- package/lib/esm/components/ConfigForm/ConfigForm.js +36 -46
- package/lib/esm/components/ConfigForm/ConfigForm.js.map +1 -1
- package/lib/esm/components/ConfigForm/index.js +1 -1
- package/lib/esm/components/ConfigForm/index.js.map +1 -1
- package/lib/esm/components/ConfigForm/utils.js +61 -0
- package/lib/esm/components/ConfigForm/utils.js.map +1 -0
- package/lib/esm/components/LoginForm/LoginForm.js +7 -7
- package/lib/esm/components/LoginForm/LoginForm.js.map +1 -1
- package/lib/esm/components/PerfTracker/PerfTracker.js +7 -8
- package/lib/esm/components/PerfTracker/PerfTracker.js.map +1 -1
- package/lib/esm/components/RequestForm/RequestForm.js +0 -7
- package/lib/esm/components/RequestForm/RequestForm.js.map +1 -1
- package/lib/esm/components/common/index.js +0 -1
- package/lib/esm/components/common/index.js.map +1 -1
- package/lib/esm/index.js +0 -1
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/utils/RunItSDK.js +8 -78
- package/lib/esm/utils/RunItSDK.js.map +1 -1
- package/lib/esm/utils/requestUtils.js +21 -14
- package/lib/esm/utils/requestUtils.js.map +1 -1
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -13
- package/lib/index.js.map +1 -1
- package/lib/test-data/responses.js +9 -0
- package/lib/test-data/responses.js.map +1 -1
- package/lib/utils/RunItSDK.d.ts +1 -17
- package/lib/utils/RunItSDK.js +10 -88
- package/lib/utils/RunItSDK.js.map +1 -1
- package/lib/utils/requestUtils.d.ts +2 -3
- package/lib/utils/requestUtils.js +22 -15
- package/lib/utils/requestUtils.js.map +1 -1
- package/package.json +8 -7
- package/lib/components/ConfigForm/configUtils.d.ts +0 -39
- package/lib/components/ConfigForm/configUtils.js +0 -232
- package/lib/components/ConfigForm/configUtils.js.map +0 -1
- package/lib/components/common/StandaloneConfigurator.d.ts +0 -7
- package/lib/components/common/StandaloneConfigurator.js +0 -61
- package/lib/components/common/StandaloneConfigurator.js.map +0 -1
- package/lib/esm/components/ConfigForm/configUtils.js +0 -196
- package/lib/esm/components/ConfigForm/configUtils.js.map +0 -1
- package/lib/esm/components/common/StandaloneConfigurator.js +0 -51
- package/lib/esm/components/common/StandaloneConfigurator.js.map +0 -1
- package/lib/esm/scenes/OAuthScene/OAuthScene.js +0 -64
- package/lib/esm/scenes/OAuthScene/OAuthScene.js.map +0 -1
- package/lib/esm/scenes/OAuthScene/index.js +0 -2
- package/lib/esm/scenes/OAuthScene/index.js.map +0 -1
- package/lib/esm/scenes/index.js +0 -2
- package/lib/esm/scenes/index.js.map +0 -1
- package/lib/scenes/OAuthScene/OAuthScene.d.ts +0 -2
- package/lib/scenes/OAuthScene/OAuthScene.js +0 -81
- package/lib/scenes/OAuthScene/OAuthScene.js.map +0 -1
- package/lib/scenes/OAuthScene/index.d.ts +0 -1
- package/lib/scenes/OAuthScene/index.js +0 -14
- package/lib/scenes/OAuthScene/index.js.map +0 -1
- package/lib/scenes/index.d.ts +0 -1
- package/lib/scenes/index.js +0 -14
- package/lib/scenes/index.js.map +0 -1
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.testBogusJsonResponse = exports.testErrorResponse = exports.testUnknownResponse = exports.testImageResponse = exports.testSqlResponse = exports.testHtmlResponse = exports.testTextResponse = exports.testOneRowComplexJson = exports.testJsonResponse = void 0;
|
7
7
|
var testJsonResponse = {
|
8
|
+
method: 'GET',
|
8
9
|
url: 'https://some/json/data',
|
9
10
|
headers: {
|
10
11
|
'content-type': 'application/json'
|
@@ -17,6 +18,7 @@ var testJsonResponse = {
|
|
17
18
|
};
|
18
19
|
exports.testJsonResponse = testJsonResponse;
|
19
20
|
var testOneRowComplexJson = {
|
21
|
+
method: 'GET',
|
20
22
|
url: 'https://some/json/data',
|
21
23
|
headers: {
|
22
24
|
'content-type': 'application/json'
|
@@ -29,6 +31,7 @@ var testOneRowComplexJson = {
|
|
29
31
|
};
|
30
32
|
exports.testOneRowComplexJson = testOneRowComplexJson;
|
31
33
|
var testTextResponse = {
|
34
|
+
method: 'GET',
|
32
35
|
url: 'https://some/text/data',
|
33
36
|
headers: {
|
34
37
|
'content-type': 'text/plain;charset=utf-8'
|
@@ -41,6 +44,7 @@ var testTextResponse = {
|
|
41
44
|
};
|
42
45
|
exports.testTextResponse = testTextResponse;
|
43
46
|
var testHtmlResponse = {
|
47
|
+
method: 'GET',
|
44
48
|
url: "https://some/html",
|
45
49
|
headers: {
|
46
50
|
'content-type': 'text/html;charset=utf-8'
|
@@ -53,6 +57,7 @@ var testHtmlResponse = {
|
|
53
57
|
};
|
54
58
|
exports.testHtmlResponse = testHtmlResponse;
|
55
59
|
var testSqlResponse = {
|
60
|
+
method: 'GET',
|
56
61
|
url: "https://some/sql",
|
57
62
|
headers: {
|
58
63
|
'content-type': 'application/sql'
|
@@ -68,6 +73,7 @@ exports.testSqlResponse = testSqlResponse;
|
|
68
73
|
var testImageResponse = function testImageResponse() {
|
69
74
|
var contentType = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'image/png';
|
70
75
|
return {
|
76
|
+
method: 'GET',
|
71
77
|
url: "http://".concat(contentType),
|
72
78
|
headers: {
|
73
79
|
'content-type': contentType
|
@@ -82,6 +88,7 @@ var testImageResponse = function testImageResponse() {
|
|
82
88
|
|
83
89
|
exports.testImageResponse = testImageResponse;
|
84
90
|
var testUnknownResponse = {
|
91
|
+
method: 'GET',
|
85
92
|
url: 'http://bogus',
|
86
93
|
headers: {},
|
87
94
|
contentType: 'bogus',
|
@@ -92,6 +99,7 @@ var testUnknownResponse = {
|
|
92
99
|
};
|
93
100
|
exports.testUnknownResponse = testUnknownResponse;
|
94
101
|
var testErrorResponse = {
|
102
|
+
method: 'GET',
|
95
103
|
url: 'http://error',
|
96
104
|
headers: {},
|
97
105
|
body: Buffer.from('{"message": "Not found", "documentation_url": "http://docs.looker.com"}'),
|
@@ -102,6 +110,7 @@ var testErrorResponse = {
|
|
102
110
|
};
|
103
111
|
exports.testErrorResponse = testErrorResponse;
|
104
112
|
var testBogusJsonResponse = {
|
113
|
+
method: 'GET',
|
105
114
|
url: 'https://some/json/data',
|
106
115
|
headers: {},
|
107
116
|
contentType: 'application/json',
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/test-data/responses.ts"],"names":["testJsonResponse","url","headers","contentType","ok","statusCode","statusMessage","body","Buffer","from","testOneRowComplexJson","testTextResponse","testHtmlResponse","testSqlResponse","testImageResponse","testUnknownResponse","testErrorResponse","testBogusJsonResponse"],"mappings":";;;;;;AA4BO,IAAMA,gBAA8B,GAAG;AAC5CC,EAAAA,
|
1
|
+
{"version":3,"sources":["../../src/test-data/responses.ts"],"names":["testJsonResponse","method","url","headers","contentType","ok","statusCode","statusMessage","body","Buffer","from","testOneRowComplexJson","testTextResponse","testHtmlResponse","testSqlResponse","testImageResponse","testUnknownResponse","testErrorResponse","testBogusJsonResponse"],"mappings":";;;;;;AA4BO,IAAMA,gBAA8B,GAAG;AAC5CC,EAAAA,MAAM,EAAE,KADoC;AAE5CC,EAAAA,GAAG,EAAE,wBAFuC;AAG5CC,EAAAA,OAAO,EAAE;AAAE,oBAAgB;AAAlB,GAHmC;AAI5CC,EAAAA,WAAW,EAAE,kBAJ+B;AAK5CC,EAAAA,EAAE,EAAE,IALwC;AAM5CC,EAAAA,UAAU,EAAE,GANgC;AAO5CC,EAAAA,aAAa,EAAE,IAP6B;AAQ5CC,EAAAA,IAAI,EAAEC,MAAM,CAACC,IAAP,CAAY,uBAAZ;AARsC,CAAvC;;AAWA,IAAMC,qBAAmC,GAAG;AACjDV,EAAAA,MAAM,EAAE,KADyC;AAEjDC,EAAAA,GAAG,EAAE,wBAF4C;AAGjDC,EAAAA,OAAO,EAAE;AAAE,oBAAgB;AAAlB,GAHwC;AAIjDC,EAAAA,WAAW,EAAE,kBAJoC;AAKjDC,EAAAA,EAAE,EAAE,IAL6C;AAMjDC,EAAAA,UAAU,EAAE,GANqC;AAOjDC,EAAAA,aAAa,EAAE,IAPkC;AAQjDC,EAAAA,IAAI,EAAEC,MAAM,CAACC,IAAP;AAR2C,CAA5C;;AA8DA,IAAME,gBAA8B,GAAG;AAC5CX,EAAAA,MAAM,EAAE,KADoC;AAE5CC,EAAAA,GAAG,EAAE,wBAFuC;AAG5CC,EAAAA,OAAO,EAAE;AAAE,oBAAgB;AAAlB,GAHmC;AAI5CC,EAAAA,WA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021 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\n\nimport type { IRawResponse } from '@looker/sdk-rtl'\n\nexport const testJsonResponse: IRawResponse = {\n method: 'GET',\n url: 'https://some/json/data',\n headers: { 'content-type': 'application/json' },\n contentType: 'application/json',\n ok: true,\n statusCode: 200,\n statusMessage: 'OK',\n body: Buffer.from('[{\"key1\": \"value1\" }]'),\n}\n\nexport const testOneRowComplexJson: IRawResponse = {\n method: 'GET',\n url: 'https://some/json/data',\n headers: { 'content-type': 'application/json' },\n contentType: 'application/json',\n ok: true,\n statusCode: 200,\n statusMessage: 'OK',\n body: Buffer.from(`{\n \"id\": 520,\n \"view\": \"orders\",\n \"fields\": [\n \"orders.id\",\n \"users.age\",\n \"users.city\"\n ],\n \"pivots\": [],\n \"fill_fields\": [],\n \"filters\": null,\n \"filter_expression\": \"\",\n \"sorts\": [],\n \"limit\": \"\",\n \"column_limit\": \"\",\n \"total\": null,\n \"row_total\": \"\",\n \"subtotals\": [],\n \"vis_config\": null,\n \"filter_config\": null,\n \"visible_ui_sections\": \"\",\n \"slug\": \"64zJjJw\",\n \"client_id\": \"zfn3SwIaaHbJTbsXSJ0JO7\",\n \"share_url\": \"https://localhost:9999/x/zfn3SwIaaHbJTbsXSJ0JO7\",\n \"expanded_share_url\": \"https://localhost:9999/explore/thelook/orders?fields=orders.id,users.age,users.city&origin=share-expanded\",\n \"url\": \"/explore/thelook/orders?fields=orders.id,users.age,users.city\",\n \"has_table_calculations\": false,\n \"model\": \"thelook\",\n \"dynamic_fields\": \"\",\n \"query_timezone\": \"\",\n \"quick_calcs\": null,\n \"analysis_config\": null,\n \"can\": {\n \"run\": true,\n \"see_results\": true,\n \"explore\": true,\n \"create\": true,\n \"show\": true,\n \"cost_estimate\": true,\n \"index\": true,\n \"see_lookml\": true,\n \"see_aggregate_table_lookml\": true,\n \"see_derived_table_lookml\": true,\n \"see_sql\": true,\n \"save\": true,\n \"generate_drill_links\": true,\n \"download\": true,\n \"download_unlimited\": true,\n \"use_custom_fields\": true,\n \"schedule\": true\n }\n}`),\n}\n\nexport const testTextResponse: IRawResponse = {\n method: 'GET',\n url: 'https://some/text/data',\n headers: { 'content-type': 'text/plain;charset=utf-8' },\n contentType: 'text/plain;charset=utf-8',\n ok: true,\n statusCode: 200,\n statusMessage: 'OK',\n body: Buffer.from('some text data'),\n}\n\nexport const testHtmlResponse: IRawResponse = {\n method: 'GET',\n url: `https://some/html`,\n headers: { 'content-type': 'text/html;charset=utf-8' },\n contentType: 'text/html;charset=utf-8',\n ok: true,\n statusCode: 200,\n statusMessage: 'OK',\n body: Buffer.from(\n '<table>\\n' +\n '<tr><th>Orders Created Date</th><th>Orders Count</th></tr>\\n' +\n '<tr><td>2019-12-22</td><td>39</td></tr>\\n' +\n '</table>'\n ),\n}\n\nexport const testSqlResponse: IRawResponse = {\n method: 'GET',\n url: `https://some/sql`,\n headers: { 'content-type': 'application/sql' },\n contentType: 'application/sql',\n ok: true,\n statusCode: 200,\n statusMessage: 'OK',\n body: Buffer.from(`SELECT\n COUNT(DISTINCT products.id ) AS \\`products.count\\`\nFROM demo_db.inventory_items AS inventory_items\nLEFT JOIN demo_db.products AS products ON inventory_items.product_id = products.id\nLIMIT 500`),\n}\n\nexport const testImageResponse = (contentType = 'image/png'): IRawResponse => ({\n method: 'GET',\n url: `http://${contentType}`,\n headers: { 'content-type': contentType },\n contentType,\n ok: true,\n statusCode: 200,\n statusMessage: 'OK',\n body: Buffer.from('some image data'),\n})\n\nexport const testUnknownResponse: IRawResponse = {\n method: 'GET',\n url: 'http://bogus',\n headers: {},\n contentType: 'bogus',\n ok: true,\n statusCode: 200,\n statusMessage: 'OK',\n body: Buffer.from('some data'),\n}\n\nexport const testErrorResponse: IRawResponse = {\n method: 'GET',\n url: 'http://error',\n headers: {},\n body: Buffer.from(\n '{\"message\": \"Not found\", \"documentation_url\": \"http://docs.looker.com\"}'\n ),\n contentType: 'text',\n ok: false,\n statusCode: 404,\n statusMessage: 'some status message',\n}\n\nexport const testBogusJsonResponse: IRawResponse = {\n method: 'GET',\n url: 'https://some/json/data',\n headers: {},\n contentType: 'application/json',\n ok: true,\n statusCode: 200,\n statusMessage: 'OK',\n body: Buffer.from('<html><body>I AM A LYING JSON RESPONSE</body></html>'),\n}\n"],"file":"responses.js"}
|
package/lib/utils/RunItSDK.d.ts
CHANGED
@@ -1,20 +1,4 @@
|
|
1
|
-
|
2
|
-
import { ApiSettings } from '@looker/sdk-rtl';
|
3
|
-
import type { RunItConfigurator } from '../components';
|
4
|
-
export declare class RunItSettings extends ApiSettings {
|
5
|
-
configurator: RunItConfigurator;
|
6
|
-
constructor(settings: Partial<IApiSettings>, configurator: RunItConfigurator);
|
7
|
-
getStoredConfig(): {
|
8
|
-
base_url: string;
|
9
|
-
looker_url: string;
|
10
|
-
};
|
11
|
-
authIsConfigured(): boolean;
|
12
|
-
readConfig(_section?: string): IApiSection;
|
13
|
-
}
|
14
|
-
export declare let runItSDK: IAPIMethods;
|
15
|
-
export declare const initRunItSdk: (configurator: RunItConfigurator) => IAPIMethods;
|
16
|
-
export declare const sdkNeedsConfig: (sdk: IAPIMethods | undefined) => boolean;
|
17
|
-
export declare const sdkNeedsAuth: (sdk: IAPIMethods | undefined) => boolean;
|
1
|
+
export declare const initRunItSdk: () => import("@looker/sdk-rtl").APIMethods;
|
18
2
|
export declare enum StoreConstants {
|
19
3
|
LOCALSTORAGE_SETTINGS_KEY = "settings"
|
20
4
|
}
|
package/lib/utils/RunItSDK.js
CHANGED
@@ -3,11 +3,13 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.StoreConstants = exports.
|
6
|
+
exports.StoreConstants = exports.initRunItSdk = void 0;
|
7
|
+
|
8
|
+
var _sdkRtl = require("@looker/sdk-rtl");
|
7
9
|
|
8
10
|
var _sdk = require("@looker/sdk");
|
9
11
|
|
10
|
-
var
|
12
|
+
var _extensionUtils = require("@looker/extension-utils");
|
11
13
|
|
12
14
|
var _components = require("../components");
|
13
15
|
|
@@ -17,70 +19,13 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
17
19
|
|
18
20
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
19
21
|
|
20
|
-
var
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
class RunItSettings extends _sdkRtl.ApiSettings {
|
26
|
-
constructor(settings, configurator) {
|
27
|
-
super(settings);
|
28
|
-
|
29
|
-
_defineProperty(this, "configurator", void 0);
|
30
|
-
|
31
|
-
this.configurator = configurator;
|
32
|
-
}
|
33
|
-
|
34
|
-
getStoredConfig() {
|
35
|
-
var storage = this.configurator.getStorage(_components.RunItConfigKey);
|
36
|
-
var config = {
|
37
|
-
base_url: '',
|
38
|
-
looker_url: ''
|
39
|
-
};
|
40
|
-
|
41
|
-
if (storage.value) {
|
42
|
-
config = JSON.parse(storage.value);
|
43
|
-
}
|
44
|
-
|
45
|
-
return config;
|
46
|
-
}
|
47
|
-
|
48
|
-
authIsConfigured() {
|
49
|
-
var config = this.getStoredConfig();
|
50
|
-
return config.base_url !== '' && config.looker_url !== '';
|
51
|
-
}
|
52
|
-
|
53
|
-
readConfig(_section) {
|
54
|
-
var config = this.getStoredConfig();
|
55
|
-
|
56
|
-
if (!this.authIsConfigured()) {
|
57
|
-
var url = new URL(this.base_url);
|
58
|
-
var authServer = "".concat(url.protocol, "//").concat(url.hostname);
|
59
|
-
config = {
|
60
|
-
base_url: this.base_url,
|
61
|
-
looker_url: "".concat(authServer, ":9999")
|
62
|
-
};
|
63
|
-
}
|
22
|
+
var initRunItSdk = () => {
|
23
|
+
var settings = _objectSpread(_objectSpread({}, (0, _sdkRtl.DefaultSettings)()), {}, {
|
24
|
+
base_url: 'https://self-signed.looker.com:19999',
|
25
|
+
agentTag: 'RunIt 0.8'
|
26
|
+
});
|
64
27
|
|
65
|
-
|
66
|
-
base_url,
|
67
|
-
looker_url
|
68
|
-
} = config;
|
69
|
-
this.base_url = base_url;
|
70
|
-
return _objectSpread(_objectSpread({}, super.readConfig(_section)), {
|
71
|
-
base_url,
|
72
|
-
looker_url,
|
73
|
-
client_id: 'looker.api-explorer',
|
74
|
-
redirect_uri: "".concat(window.location.origin, "/oauth")
|
75
|
-
});
|
76
|
-
}
|
77
|
-
|
78
|
-
}
|
79
|
-
|
80
|
-
exports.RunItSettings = RunItSettings;
|
81
|
-
|
82
|
-
var perfSDK = (settings, configurator) => {
|
83
|
-
var options = new RunItSettings(settings, configurator);
|
28
|
+
var options = new _extensionUtils.OAuthConfigProvider(settings, _components.RunItConfigKey);
|
84
29
|
var transport = new _sdkRtl.BrowserTransport(options);
|
85
30
|
var session = new _sdkRtl.BrowserSession(options, transport);
|
86
31
|
var sdk = (0, _sdk.functionalSdk40)(session);
|
@@ -88,30 +33,7 @@ var perfSDK = (settings, configurator) => {
|
|
88
33
|
return sdk;
|
89
34
|
};
|
90
35
|
|
91
|
-
var runItSDK;
|
92
|
-
exports.runItSDK = runItSDK;
|
93
|
-
|
94
|
-
var initRunItSdk = configurator => {
|
95
|
-
if (!runItSDK) {
|
96
|
-
exports.runItSDK = runItSDK = perfSDK(settings, configurator);
|
97
|
-
}
|
98
|
-
|
99
|
-
return runItSDK;
|
100
|
-
};
|
101
|
-
|
102
36
|
exports.initRunItSdk = initRunItSdk;
|
103
|
-
|
104
|
-
var sdkNeedsConfig = sdk => (sdk === null || sdk === void 0 ? void 0 : sdk.authSession.settings) instanceof RunItSettings;
|
105
|
-
|
106
|
-
exports.sdkNeedsConfig = sdkNeedsConfig;
|
107
|
-
|
108
|
-
var sdkNeedsAuth = sdk => {
|
109
|
-
if (!sdk) return false;
|
110
|
-
var configIsNeeded = sdkNeedsConfig(sdk);
|
111
|
-
return configIsNeeded && !sdk.authSession.isAuthenticated();
|
112
|
-
};
|
113
|
-
|
114
|
-
exports.sdkNeedsAuth = sdkNeedsAuth;
|
115
37
|
var StoreConstants;
|
116
38
|
exports.StoreConstants = StoreConstants;
|
117
39
|
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/utils/RunItSDK.ts"],"names":["settings","base_url","agentTag","
|
1
|
+
{"version":3,"sources":["../../src/utils/RunItSDK.ts"],"names":["initRunItSdk","settings","base_url","agentTag","options","OAuthConfigProvider","RunItConfigKey","transport","BrowserTransport","session","BrowserSession","sdk","trackPerformance","StoreConstants"],"mappings":";;;;;;;AA2BA;;AAKA;;AACA;;AAEA;;;;;;;;AAEO,IAAMA,YAAY,GAAG,MAAM;AAChC,MAAMC,QAAQ,mCACT,8BADS;AAEZC,IAAAA,QAAQ,EAAE,sCAFE;AAGZC,IAAAA,QAAQ,EAAE;AAHE,IAAd;;AAMA,MAAMC,OAAO,GAAG,IAAIC,mCAAJ,CAAwBJ,QAAxB,EAAkCK,0BAAlC,CAAhB;AACA,MAAMC,SAAS,GAAG,IAAIC,wBAAJ,CAAqBJ,OAArB,CAAlB;AACA,MAAMK,OAAO,GAAG,IAAIC,sBAAJ,CAAmBN,OAAnB,EAA4BG,SAA5B,CAAhB;AACA,MAAMI,GAAG,GAAG,0BAAgBF,OAAhB,CAAZ;AACAD,2BAAiBI,gBAAjB,GAAoC,IAApC;AACA,SAAOD,GAAP;AACD,CAbM;;;IAeKE,c;;;WAAAA,c;AAAAA,EAAAA,c;GAAAA,c,8BAAAA,c","sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2021 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\n\nimport type { IApiSettings } from '@looker/sdk-rtl'\nimport {\n BrowserSession,\n BrowserTransport,\n DefaultSettings,\n} from '@looker/sdk-rtl'\nimport { functionalSdk40 } from '@looker/sdk'\nimport { OAuthConfigProvider } from '@looker/extension-utils'\n\nimport { RunItConfigKey } from '../components'\n\nexport const initRunItSdk = () => {\n const settings = {\n ...DefaultSettings(),\n base_url: 'https://self-signed.looker.com:19999',\n agentTag: 'RunIt 0.8',\n } as IApiSettings\n\n const options = new OAuthConfigProvider(settings, RunItConfigKey)\n const transport = new BrowserTransport(options)\n const session = new BrowserSession(options, transport)\n const sdk = functionalSdk40(session)\n BrowserTransport.trackPerformance = true\n return sdk\n}\n\nexport enum StoreConstants {\n LOCALSTORAGE_SETTINGS_KEY = 'settings',\n}\n"],"file":"RunItSDK.js"}
|
@@ -1,13 +1,12 @@
|
|
1
1
|
import type { IAPIMethods, IRawResponse } from '@looker/sdk-rtl';
|
2
2
|
import type { IApiModel, IMethod } from '@looker/sdk-codegen';
|
3
3
|
import type { RunItHttpMethod, RunItInput, RunItValues } from '../RunIt';
|
4
|
-
import type { RunItConfigurator } from '../components';
|
5
4
|
export declare type RunItSetter = (value: any) => any;
|
6
5
|
export declare const runItNoSet: RunItSetter;
|
7
6
|
export declare const pathify: (path: string, pathParams?: RunItValues | undefined) => string;
|
8
7
|
export declare const prepareInputs: (inputs: RunItInput[], requestContent: RunItValues) => RunItValues;
|
9
|
-
export declare const formValues: (
|
10
|
-
export declare const initRequestContent: (
|
8
|
+
export declare const formValues: () => Promise<any>;
|
9
|
+
export declare const initRequestContent: (inputs: RunItInput[], requestContent?: {}) => {};
|
11
10
|
export declare const createRequestParams: (inputs: RunItInput[], requestContent: RunItValues) => any[];
|
12
11
|
export declare const runRequest: (sdk: IAPIMethods, basePath: string, httpMethod: RunItHttpMethod, endpoint: string, pathParams: RunItValues, queryParams: RunItValues, body: any) => Promise<IRawResponse>;
|
13
12
|
export declare const createInputs: (spec: IApiModel, method: IMethod) => RunItInput[];
|
@@ -11,9 +11,9 @@ var _lodash = require("lodash");
|
|
11
11
|
|
12
12
|
var _sdkCodegen = require("@looker/sdk-codegen");
|
13
13
|
|
14
|
-
var
|
14
|
+
var _extensionUtils = require("@looker/extension-utils");
|
15
15
|
|
16
|
-
var
|
16
|
+
var _components = require("../components");
|
17
17
|
|
18
18
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
19
19
|
|
@@ -68,18 +68,25 @@ var prepareInputs = (inputs, requestContent) => {
|
|
68
68
|
|
69
69
|
exports.prepareInputs = prepareInputs;
|
70
70
|
|
71
|
-
var formValues =
|
72
|
-
var
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
71
|
+
var formValues = function () {
|
72
|
+
var _ref = _asyncToGenerator(function* () {
|
73
|
+
var adaptor = (0, _extensionUtils.getEnvAdaptor)();
|
74
|
+
var formValue = yield adaptor.localStorageGetItem(_components.RunItFormKey);
|
75
|
+
var result = formValue ? JSON.parse(formValue) : {};
|
76
|
+
adaptor.localStorageRemoveItem(_components.RunItFormKey);
|
77
|
+
return result;
|
78
|
+
});
|
79
|
+
|
80
|
+
return function formValues() {
|
81
|
+
return _ref.apply(this, arguments);
|
82
|
+
};
|
83
|
+
}();
|
77
84
|
|
78
85
|
exports.formValues = formValues;
|
79
86
|
|
80
|
-
var initRequestContent = function initRequestContent(
|
81
|
-
var requestContent = arguments.length >
|
82
|
-
var content =
|
87
|
+
var initRequestContent = function initRequestContent(inputs) {
|
88
|
+
var requestContent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
89
|
+
var content = {};
|
83
90
|
|
84
91
|
if ((0, _lodash.isEmpty)(content)) {
|
85
92
|
content = prepareInputs(inputs, requestContent);
|
@@ -124,18 +131,18 @@ var createRequestParams = (inputs, requestContent) => {
|
|
124
131
|
exports.createRequestParams = createRequestParams;
|
125
132
|
|
126
133
|
var runRequest = function () {
|
127
|
-
var
|
134
|
+
var _ref2 = _asyncToGenerator(function* (sdk, basePath, httpMethod, endpoint, pathParams, queryParams, body) {
|
128
135
|
if (!sdk.authSession.isAuthenticated()) {
|
129
|
-
yield sdk.ok(
|
136
|
+
yield sdk.ok(sdk.authSession.login());
|
130
137
|
}
|
131
138
|
|
132
139
|
var url = "".concat(basePath).concat(pathify(endpoint, pathParams));
|
133
|
-
var raw = yield sdk.authSession.transport.rawRequest(httpMethod, url, queryParams, body, props =>
|
140
|
+
var raw = yield sdk.authSession.transport.rawRequest(httpMethod, url, queryParams, body, props => sdk.authSession.authenticate(props));
|
134
141
|
return raw;
|
135
142
|
});
|
136
143
|
|
137
144
|
return function runRequest(_x, _x2, _x3, _x4, _x5, _x6, _x7) {
|
138
|
-
return
|
145
|
+
return _ref2.apply(this, arguments);
|
139
146
|
};
|
140
147
|
}();
|
141
148
|
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/utils/requestUtils.ts"],"names":["runItNoSet","value","macro","path","vars","replace","_","b","pathify","pathParams","result","includes","prepareInputs","inputs","requestContent","input","name","location","parsed","JSON","parse","type","e","formValues","configurator","storage","getStorage","RunItFormKey","removeStorage","initRequestContent","content","createRequestParams","queryParams","prepped","trimmed","body","Error","runRequest","sdk","basePath","httpMethod","endpoint","authSession","isAuthenticated","ok","runItSDK","login","url","raw","transport","rawRequest","props","authenticate","getTypeDefault","createSampleBody","spec","getSampleValue","IntrinsicType","DelimArrayType","elementType","EnumType","ArrayType","customType","recurse","types","HashType","sampleBody","prop","writeable","sampleValue","undefined","editType","createInputs","method","allParams","map","param","required","description"],"mappings":";;;;;;;AA2BA;;AACA;;AAEA;;AAWA;;AACA;;;;;;;;AASO,IAAMA,UAAuB,GAAIC,KAAD,IAAgBA,KAAhD;;;;AAQP,IAAMC,KAAK,GAAG,CAACC,IAAD,EAAeC,IAAf,KACZD,IAAI,CAACE,OAAL,CAAa,UAAb,EAAyB,CAACC,CAAD,EAAIC,CAAJ,KAAUH,IAAI,CAACG,CAAD,CAAvC,CADF;;AASO,IAAMC,OAAO,GAAG,CAACL,IAAD,EAAeM,UAAf,KAAoD;AACzE,MAAIC,MAAM,GAAGP,IAAb;;AACA,MAAIM,UAAU,IAAIN,IAAI,CAACQ,QAAL,CAAc,GAAd,CAAlB,EAAsC;AACpCD,IAAAA,MAAM,GAAGR,KAAK,CAACC,IAAD,EAAOM,UAAP,CAAd;AACD;;AACD,SAAOC,MAAP;AACD,CANM;;;;AAaA,IAAME,aAAa,GAAG,CAC3BC,MAD2B,EA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K,CAAC5D,IADmB;AAE/BC,EAAAA,QAAQ,EAAE2D,KAAK,CAAC3D,QAFe;AAG/BI,EAAAA,IAAI,EAAEkD,QAAQ,CAAChB,IAAD,EAAOqB,KAAK,CAACvD,IAAb,CAHiB;AAI/BwD,EAAAA,QAAQ,EAAED,KAAK,CAACC,QAJe;AAK/BC,EAAAA,WAAW,EAAEF,KAAK,CAACE;AALY,CAAZ,CAArB,CADK","sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2021 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\n\nimport type { IAPIMethods, IRawResponse } from '@looker/sdk-rtl'\nimport cloneDeep from 'lodash/cloneDeep'\nimport { isEmpty } from 'lodash'\nimport type { IApiModel, IMethod, IType } from '@looker/sdk-codegen'\nimport {\n ArrayType,\n DelimArrayType,\n EnumType,\n HashType,\n IntrinsicType,\n trimInputs,\n} from '@looker/sdk-codegen'\n\nimport type { RunItHttpMethod, RunItInput, RunItValues } from '../RunIt'\nimport type { RunItConfigurator } from '../components'\nimport { RunItFormKey } from '../components'\nimport { runItSDK } from './RunItSDK'\n\n/** Hook to set a URL somewhere else in APIX */\nexport type RunItSetter = (value: any) => any\n\n/**\n * A \"no-op\" function\n * @param value passed through\n */\nexport const runItNoSet: RunItSetter = (value: any) => value\n\n/**\n * Replaces {foo} with vars[foo] in provided path\n * @param path with templatized param names\n * @param vars Collection of path params\n * @returns Path with param names replaced with values\n */\nconst macro = (path: string, vars: RunItValues) =>\n path.replace(/{(\\w+)}/g, (_, b) => vars[b])\n\n/**\n * Construct a full request path including path params\n * @param path A request path with path params in curly braces e.g. /queries/{query_id}/run/{result_format}\n * @param pathParams Collection of path params\n * @returns a full request path\n */\nexport const pathify = (path: string, pathParams?: RunItValues): string => {\n let result = path\n if (pathParams && path.includes('{')) {\n result = macro(path, pathParams)\n }\n return result\n}\n\n/**\n * Prepares the inputs for use with the SDK and other RunIt components\n * @param inputs An array describing RunIt form inputs\n * @param requestContent Current request parameters\n */\nexport const prepareInputs = (\n inputs: RunItInput[],\n requestContent: RunItValues\n) => {\n const result = cloneDeep(requestContent)\n for (const input of inputs) {\n const name = input.name\n if (input.location === 'body') {\n try {\n let parsed\n if (name in requestContent) {\n const value = requestContent[name]\n /** The value is not a string when the user has not interacted with this param and prepareInputs has been\n * called (e.g. if user navigates to the Code tab).\n */\n parsed = typeof value === 'string' ? JSON.parse(value) : value\n } else {\n /** This scenario occurs when RunIt is about to be mounted for a new method */\n parsed = input.type\n }\n result[name] = parsed\n } catch (e) {\n /** Treat as x-www-form-urlencoded */\n result[name] = requestContent[name]\n }\n }\n }\n return result\n}\n\n/**\n * Load and clear any saved form values from the session\n * @param configurator storage service\n */\nexport const formValues = (configurator: RunItConfigurator) => {\n const storage = configurator.getStorage(RunItFormKey)\n const result = storage.value ? JSON.parse(storage.value) : {}\n configurator.removeStorage(RunItFormKey)\n return result\n}\n\n/**\n * Initializes the request content object from local storage or input definitions, in that order\n * @param configurator storage service\n * @param inputs\n * @param requestContent the current request content\n */\nexport const initRequestContent = (\n configurator: RunItConfigurator,\n inputs: RunItInput[],\n requestContent = {}\n) => {\n let content = formValues(configurator)\n if (isEmpty(content)) {\n content = prepareInputs(inputs, requestContent)\n }\n return content\n}\n\n/**\n * Takes all form input values and categorizes them based on their request location\n * @param inputs RunIt form inputs\n * @param requestContent Form input values\n * @returns path, query and body param objects\n */\nexport const createRequestParams = (\n inputs: RunItInput[],\n requestContent: RunItValues\n) => {\n const pathParams = {}\n const queryParams = {}\n const prepped = prepareInputs(inputs, requestContent)\n const trimmed = trimInputs(prepped)\n let body\n for (const input of inputs) {\n const name = input.name\n switch (input.location) {\n case 'path':\n pathParams[name] = trimmed[name]\n break\n case 'query':\n queryParams[name] = trimmed[name]\n break\n case 'body':\n body = trimmed[name]\n break\n default:\n throw new Error(`Invalid input location: '${input.location}'`)\n }\n }\n return [pathParams, queryParams, body]\n}\n\n/**\n * Makes an http request using the SDK browser transport rawRequest method\n * @param sdk functional SDK that supports rawRequest via its transport\n * @param basePath base path for the URL. For standalone this includes the specKey. Empty for extension.\n * @param httpMethod Request operation\n * @param endpoint Request path with path params in curly braces e.g. /queries/{query_id}/run/{result_format}\n * @param pathParams Collection of path params\n * @param queryParams Collection of query params\n * @param body Collection of body params\n */\nexport const runRequest = async (\n sdk: IAPIMethods,\n basePath: string,\n httpMethod: RunItHttpMethod,\n endpoint: string,\n pathParams: RunItValues,\n queryParams: RunItValues,\n body: any\n): Promise<IRawResponse> => {\n if (!sdk.authSession.isAuthenticated()) {\n await sdk.ok(runItSDK.authSession.login())\n }\n const url = `${basePath}${pathify(endpoint, pathParams)}`\n const raw = await sdk.authSession.transport.rawRequest(\n httpMethod,\n url,\n queryParams,\n body,\n (props) => runItSDK.authSession.authenticate(props)\n )\n return raw\n}\n\n/**\n * Return a default value for a given type name\n * @param type A type name\n */\nconst getTypeDefault = (type: string) => {\n // TODO: use potential equivalent from sdk-codegen, confirm formats\n switch (type) {\n case 'boolean':\n return false\n case 'int64':\n case 'integer':\n return 0\n case 'float':\n case 'double':\n return 0.0\n case 'hostname':\n case 'ipv4':\n case 'ipv6':\n case 'uuid':\n case 'uri':\n case 'string':\n case 'email':\n return ''\n case 'string[]':\n return []\n case 'object':\n return {}\n case 'datetime':\n return ''\n default:\n return ''\n }\n}\n\n/**\n * Given a type object reduce it to its writeable intrinsic and/or custom type properties and their default values\n * @param spec Api spec\n * @param type A type object\n */\nconst createSampleBody = (spec: IApiModel, type: IType) => {\n /* eslint-disable @typescript-eslint/no-use-before-define */\n const getSampleValue = (type: IType) => {\n if (type instanceof IntrinsicType) return getTypeDefault(type.name)\n if (type instanceof DelimArrayType)\n return getTypeDefault(type.elementType.name)\n if (type instanceof EnumType) return ''\n if (type instanceof ArrayType)\n return type.customType\n ? [recurse(spec.types[type.customType])]\n : getTypeDefault(type.name)\n if (type instanceof HashType)\n return type.customType ? recurse(spec.types[type.customType]) : {}\n\n return recurse(type)\n }\n /* eslint-enable @typescript-eslint/no-use-before-define */\n\n const recurse = (type: IType) => {\n const sampleBody: RunItValues = {}\n for (const prop of type.writeable) {\n const sampleValue = getSampleValue(prop.type)\n if (sampleValue !== undefined) {\n sampleBody[prop.name] = sampleValue\n }\n }\n return sampleBody\n }\n return recurse(type)\n}\n\n/**\n * Convert model type to an editable type\n * @param spec API model for building input editor\n * @param type to convert\n */\nconst editType = (spec: IApiModel, type: IType) => {\n if (type instanceof IntrinsicType) return type.name\n // TODO create a DelimArray editing component as part of the complex type editor\n if (type instanceof DelimArrayType) return 'string'\n return createSampleBody(spec, type)\n}\n\n/**\n * Given an SDK method create and return an array of inputs for the run-it form\n * @param spec Api spec\n * @param method A method object\n */\nexport const createInputs = (spec: IApiModel, method: IMethod): RunItInput[] =>\n method.allParams.map((param) => ({\n name: param.name,\n location: param.location,\n type: editType(spec, param.type),\n required: param.required,\n description: param.description,\n }))\n"],"file":"requestUtils.js"}
|
1
|
+
{"version":3,"sources":["../../src/utils/requestUtils.ts"],"names":["runItNoSet","value","macro","path","vars","replace","_","b","pathify","pathParams","result","includes","prepareInputs","inputs","requestContent","input","name","location","parsed","JSON","parse","type","e","formValues","adaptor","formValue","localStorageGetItem","RunItFormKey","localStorageRemoveItem","initRequestContent","content","createRequestParams","queryParams","prepped","trimmed","body","Error","runRequest","sdk","basePath","httpMethod","endpoint","authSession","isAuthenticated","ok","login","url","raw","transport","rawRequest","props","authenticate","getTypeDefault","createSampleBody","spec","getSampleValue","IntrinsicType","DelimArrayType","elementType","EnumType","ArrayType","customType","recurse","types","HashType","sampleBody","prop","writeable","sampleValue","undefined","editType","createInputs","method","allParams","map","param","required","description"],"mappings":";;;;;;;AA2BA;;AACA;;AAEA;;AAQA;;AAGA;;;;;;;;AASO,IAAMA,UAAuB,GAAIC,KAAD,IAAgBA,KAAhD;;;;AAQP,IAAMC,KAAK,GAAG,CAACC,IAAD,EAAeC,IAAf,KACZD,IAAI,CAACE,OAAL,CAAa,UAAb,EAAyB,CAACC,CAAD,EAAIC,CAAJ,KAAUH,IAAI,CAACG,CAAD,CAAvC,CADF;;AASO,IAAMC,OAAO,GAAG,CAACL,IAAD,EAAeM,UAAf,KAAoD;AACzE,MAAIC,MAAM,GAAGP,IAAb;;AACA,MAAIM,UAAU,IAAIN,IAAI,CAACQ,QAAL,CAAc,GAAd,CAAlB,EAAsC;AACpCD,IAAAA,MAAM,GAAGR,KAAK,CAACC,IAAD,EAAOM,UAAP,CAAd;AACD;;AACD,SAAOC,MAAP;AACD,CANM;;;;AAaA,IAAME,aAAa,GAAG,CAC3BC,MAD2B,EAE3BC,cAF2B,KAGxB;AACH,MAAMJ,MAAM,GAAG,wBAAUI,cAAV,CAAf;;AACA,OAAK,IAAMC,KAAX,IAAoBF,MAApB,EAA4B;AAC1B,QAAMG,IAAI,GAAGD,KAAK,CAACC,IAAnB;;AACA,QAAID,KAAK,CAACE,QAAN,KAAmB,MAAvB,EAA+B;AAC7B,UAAI;AACF,YAAIC,MAAM,SAAV;;AACA,YAAIF,IAAI,IAAIF,cAAZ,EAA4B;AAC1B,c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["/*\n\n MIT License\n\n Copyright (c) 2021 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\n\nimport type { IAPIMethods, IRawResponse } from '@looker/sdk-rtl'\nimport cloneDeep from 'lodash/cloneDeep'\nimport { isEmpty } from 'lodash'\nimport type { IApiModel, IMethod, IType } from '@looker/sdk-codegen'\nimport {\n ArrayType,\n DelimArrayType,\n EnumType,\n HashType,\n IntrinsicType,\n trimInputs,\n} from '@looker/sdk-codegen'\nimport { getEnvAdaptor } from '@looker/extension-utils'\n\nimport type { RunItHttpMethod, RunItInput, RunItValues } from '../RunIt'\nimport { RunItFormKey } from '../components'\n\n/** Hook to set a URL somewhere else in APIX */\nexport type RunItSetter = (value: any) => any\n\n/**\n * A \"no-op\" function\n * @param value passed through\n */\nexport const runItNoSet: RunItSetter = (value: any) => value\n\n/**\n * Replaces {foo} with vars[foo] in provided path\n * @param path with templatized param names\n * @param vars Collection of path params\n * @returns Path with param names replaced with values\n */\nconst macro = (path: string, vars: RunItValues) =>\n path.replace(/{(\\w+)}/g, (_, b) => vars[b])\n\n/**\n * Construct a full request path including path params\n * @param path A request path with path params in curly braces e.g. /queries/{query_id}/run/{result_format}\n * @param pathParams Collection of path params\n * @returns a full request path\n */\nexport const pathify = (path: string, pathParams?: RunItValues): string => {\n let result = path\n if (pathParams && path.includes('{')) {\n result = macro(path, pathParams)\n }\n return result\n}\n\n/**\n * Prepares the inputs for use with the SDK and other RunIt components\n * @param inputs An array describing RunIt form inputs\n * @param requestContent Current request parameters\n */\nexport const prepareInputs = (\n inputs: RunItInput[],\n requestContent: RunItValues\n) => {\n const result = cloneDeep(requestContent)\n for (const input of inputs) {\n const name = input.name\n if (input.location === 'body') {\n try {\n let parsed\n if (name in requestContent) {\n const value = requestContent[name]\n /** The value is not a string when the user has not interacted with this param and prepareInputs has been\n * called (e.g. if user navigates to the Code tab).\n */\n parsed = typeof value === 'string' ? JSON.parse(value) : value\n } else {\n /** This scenario occurs when RunIt is about to be mounted for a new method */\n parsed = input.type\n }\n result[name] = parsed\n } catch (e) {\n /** Treat as x-www-form-urlencoded */\n result[name] = requestContent[name]\n }\n }\n }\n return result\n}\n\n/**\n * Load and clear any saved form values from the session\n * @param configurator storage service\n */\nexport const formValues = async () => {\n const adaptor = getEnvAdaptor()\n const formValue = await adaptor.localStorageGetItem(RunItFormKey)\n const result = formValue ? JSON.parse(formValue) : {}\n adaptor.localStorageRemoveItem(RunItFormKey)\n return result\n}\n\n/**\n * Initializes the request content object from local storage or input definitions, in that order\n * @param configurator storage service\n * @param inputs\n * @param requestContent the current request content\n */\nexport const initRequestContent = (\n inputs: RunItInput[],\n requestContent = {}\n) => {\n // TODO: Temporarily disabling request form state persistence until RunIt is using redux\n // let content = await formValues()\n let content = {}\n if (isEmpty(content)) {\n content = prepareInputs(inputs, requestContent)\n }\n return content\n}\n\n/**\n * Takes all form input values and categorizes them based on their request location\n * @param inputs RunIt form inputs\n * @param requestContent Form input values\n * @returns path, query and body param objects\n */\nexport const createRequestParams = (\n inputs: RunItInput[],\n requestContent: RunItValues\n) => {\n const pathParams = {}\n const queryParams = {}\n const prepped = prepareInputs(inputs, requestContent)\n const trimmed = trimInputs(prepped)\n let body\n for (const input of inputs) {\n const name = input.name\n switch (input.location) {\n case 'path':\n pathParams[name] = trimmed[name]\n break\n case 'query':\n queryParams[name] = trimmed[name]\n break\n case 'body':\n body = trimmed[name]\n break\n default:\n throw new Error(`Invalid input location: '${input.location}'`)\n }\n }\n return [pathParams, queryParams, body]\n}\n\n/**\n * Makes an http request using the SDK browser transport rawRequest method\n * @param sdk functional SDK that supports rawRequest via its transport\n * @param basePath base path for the URL. For standalone this includes the specKey. Empty for extension.\n * @param httpMethod Request operation\n * @param endpoint Request path with path params in curly braces e.g. /queries/{query_id}/run/{result_format}\n * @param pathParams Collection of path params\n * @param queryParams Collection of query params\n * @param body Collection of body params\n */\nexport const runRequest = async (\n sdk: IAPIMethods,\n basePath: string,\n httpMethod: RunItHttpMethod,\n endpoint: string,\n pathParams: RunItValues,\n queryParams: RunItValues,\n body: any\n): Promise<IRawResponse> => {\n if (!sdk.authSession.isAuthenticated()) {\n await sdk.ok(sdk.authSession.login())\n }\n const url = `${basePath}${pathify(endpoint, pathParams)}`\n const raw = await sdk.authSession.transport.rawRequest(\n httpMethod,\n url,\n queryParams,\n body,\n (props) => sdk.authSession.authenticate(props)\n )\n return raw\n}\n\n/**\n * Return a default value for a given type name\n * @param type A type name\n */\nconst getTypeDefault = (type: string) => {\n // TODO: use potential equivalent from sdk-codegen, confirm formats\n switch (type) {\n case 'boolean':\n return false\n case 'int64':\n case 'integer':\n return 0\n case 'float':\n case 'double':\n return 0.0\n case 'hostname':\n case 'ipv4':\n case 'ipv6':\n case 'uuid':\n case 'uri':\n case 'string':\n case 'email':\n return ''\n case 'string[]':\n return []\n case 'object':\n return {}\n case 'datetime':\n return ''\n default:\n return ''\n }\n}\n\n/**\n * Given a type object reduce it to its writeable intrinsic and/or custom type properties and their default values\n * @param spec Api spec\n * @param type A type object\n */\nconst createSampleBody = (spec: IApiModel, type: IType) => {\n /* eslint-disable @typescript-eslint/no-use-before-define */\n const getSampleValue = (type: IType) => {\n if (type instanceof IntrinsicType) return getTypeDefault(type.name)\n if (type instanceof DelimArrayType)\n return getTypeDefault(type.elementType.name)\n if (type instanceof EnumType) return ''\n if (type instanceof ArrayType)\n return type.customType\n ? [recurse(spec.types[type.customType])]\n : getTypeDefault(type.name)\n if (type instanceof HashType)\n return type.customType ? recurse(spec.types[type.customType]) : {}\n\n return recurse(type)\n }\n /* eslint-enable @typescript-eslint/no-use-before-define */\n\n const recurse = (type: IType) => {\n const sampleBody: RunItValues = {}\n for (const prop of type.writeable) {\n const sampleValue = getSampleValue(prop.type)\n if (sampleValue !== undefined) {\n sampleBody[prop.name] = sampleValue\n }\n }\n return sampleBody\n }\n return recurse(type)\n}\n\n/**\n * Convert model type to an editable type\n * @param spec API model for building input editor\n * @param type to convert\n */\nconst editType = (spec: IApiModel, type: IType) => {\n if (type instanceof IntrinsicType) return type.name\n // TODO create a DelimArray editing component as part of the complex type editor\n if (type instanceof DelimArrayType) return 'string'\n return createSampleBody(spec, type)\n}\n\n/**\n * Given an SDK method create and return an array of inputs for the run-it form\n * @param spec Api spec\n * @param method A method object\n */\nexport const createInputs = (spec: IApiModel, method: IMethod): RunItInput[] =>\n method.allParams.map((param) => ({\n name: param.name,\n location: param.location,\n type: editType(spec, param.type),\n required: param.required,\n description: param.description,\n }))\n"],"file":"requestUtils.js"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@looker/run-it",
|
3
|
-
"version": "0.9.
|
3
|
+
"version": "0.9.27",
|
4
4
|
"description": "A dynamic REST request input form and response visualizer",
|
5
5
|
"main": "lib/index.js",
|
6
6
|
"module": "lib/esm/index.js",
|
@@ -18,7 +18,7 @@
|
|
18
18
|
"repository": {
|
19
19
|
"type": "git",
|
20
20
|
"url": "git+https://github.com/looker-open-source/sdk-codegen.git",
|
21
|
-
"directory": "packages/
|
21
|
+
"directory": "packages/run-it"
|
22
22
|
},
|
23
23
|
"homepage": "https://github.com/looker-open-source/sdk-codegen/tree/main/packages/run-it",
|
24
24
|
"bugs": {
|
@@ -51,15 +51,16 @@
|
|
51
51
|
"webpack-dev-server": "^3.11.2"
|
52
52
|
},
|
53
53
|
"dependencies": {
|
54
|
-
"@looker/code-editor": "^0.1.
|
54
|
+
"@looker/code-editor": "^0.1.18",
|
55
55
|
"@looker/components": "^2.8.1",
|
56
56
|
"@looker/components-date": "^2.4.1",
|
57
57
|
"@looker/design-tokens": "^2.7.1",
|
58
|
+
"@looker/extension-utils": "^0.1.4",
|
58
59
|
"@looker/icons": "^1.5.3",
|
59
|
-
"@looker/sdk": "^
|
60
|
-
"@looker/sdk-codegen": "^21.
|
60
|
+
"@looker/sdk": "^22.0.0",
|
61
|
+
"@looker/sdk-codegen": "^21.4.0",
|
61
62
|
"@looker/sdk-codegen-utils": "^21.0.11",
|
62
|
-
"@looker/sdk-rtl": "^21.2
|
63
|
+
"@looker/sdk-rtl": "^21.3.2",
|
63
64
|
"@styled-icons/material": "^10.28.0",
|
64
65
|
"@styled-icons/material-outlined": "^10.28.0",
|
65
66
|
"@styled-icons/material-rounded": "^10.28.0",
|
@@ -72,5 +73,5 @@
|
|
72
73
|
"react-is": "^16.13.1",
|
73
74
|
"styled-components": "^5.2.1"
|
74
75
|
},
|
75
|
-
"gitHead": "
|
76
|
+
"gitHead": "f8867339965baf85c26b3beaee8e4621e3cff3a8"
|
76
77
|
}
|
@@ -1,39 +0,0 @@
|
|
1
|
-
import type { ILookerVersions, SpecItem, SpecList } from '@looker/sdk-codegen';
|
2
|
-
import { ApiModel } from '@looker/sdk-codegen';
|
3
|
-
import type { RunItValues } from '../..';
|
4
|
-
export declare type StorageLocation = 'session' | 'local';
|
5
|
-
export declare const RunItConfigKey = "RunItConfig";
|
6
|
-
export declare const RunItFormKey = "RunItForm";
|
7
|
-
export declare const RunItNoConfig: {
|
8
|
-
base_url: string;
|
9
|
-
looker_url: string;
|
10
|
-
};
|
11
|
-
export interface IStorageValue {
|
12
|
-
location: StorageLocation;
|
13
|
-
value: string;
|
14
|
-
}
|
15
|
-
export declare type ApiSpecFetcher = (version: string, name: string) => Promise<string | RunItValues>;
|
16
|
-
export declare type ParsedSpec = ApiModel | undefined;
|
17
|
-
export interface RunItConfigurator {
|
18
|
-
getStorage: (key: string, defaultValue?: string) => IStorageValue;
|
19
|
-
setStorage(key: string, value: string, location: 'local' | 'session'): string;
|
20
|
-
removeStorage(key: string): void;
|
21
|
-
}
|
22
|
-
export interface ILoadedSpecs {
|
23
|
-
baseUrl: string;
|
24
|
-
webUrl: string;
|
25
|
-
headless: boolean;
|
26
|
-
specs: SpecList;
|
27
|
-
fetchResult: string;
|
28
|
-
}
|
29
|
-
export interface IAPIXConfig extends ILookerVersions {
|
30
|
-
headless?: boolean;
|
31
|
-
}
|
32
|
-
export declare const validateUrl: (url: string) => string;
|
33
|
-
export declare const getUrl: (url: string) => Promise<string | RunItValues>;
|
34
|
-
export declare const fullify: (uri: string, baseUrl: string) => string;
|
35
|
-
export declare const funFetch: (version: string, name: string) => Promise<string>;
|
36
|
-
export declare const specUrlFetch: (url: string) => Promise<ParsedSpec>;
|
37
|
-
export declare const loadSpecsFromVersions: (url: string, content?: string | Record<string, unknown>, defer?: boolean) => Promise<ILoadedSpecs>;
|
38
|
-
export declare const sdkSpecFetch: (spec: SpecItem, fetcher: ApiSpecFetcher) => Promise<ParsedSpec>;
|
39
|
-
export declare const fallbackFetch: (spec: SpecItem, fetcher: ApiSpecFetcher) => Promise<ParsedSpec>;
|