Skip to content
This repository was archived by the owner on Feb 25, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 117 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@
},
"homepage": "https://github.com/adobe/helix-data-embed#readme",
"dependencies": {
"@adobe/helix-fetch": "1.6.0",
"@adobe/helix-epsagon": "1.3.1",
"@adobe/helix-onedrive-support": "2.3.0",
"@adobe/helix-shared": "7.3.0",
"@adobe/helix-status": "7.1.3",
"@adobe/openwhisk-action-logger": "2.2.0",
"@adobe/openwhisk-action-utils": "4.2.2",
Expand Down
4 changes: 3 additions & 1 deletion src/embed.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
const feed = require('./matchers/feed');
const excel = require('./matchers/excel');
const google = require('./matchers/google');
// eslint-disable-next-line camelcase
const runQuery = require('./matchers/run-query');

const matchers = [
feed, excel, google,
feed, excel, google, runQuery,
];

function hasParams(list, params) {
Expand Down
58 changes: 58 additions & 0 deletions src/matchers/run-query.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright 2020 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
/* eslint-disable camelcase */
const { fetch } = require('@adobe/helix-fetch');
const { utils } = require('@adobe/helix-shared');

async function extract(url, params, log = console) {
const host = 'https://adobeioruntime.net';
const path = '/api/v1/web/helix/helix-services/run-query@v2/';
const query = url.split('/').pop();
const resource = `${host}${path}${query}`;
const DEFAULT_CACHE = 'max-age=600';

const results = await fetch(url.startsWith(host) ? url : resource);
const statusCode = utils.propagateStatusCode(results.status);
const logLevel = utils.logLevelForStatusCode(results.status);
const cacheControl = results.headers.get('cache-control');

try {
if (!results.ok) {
throw new Error(await results.text());
}
return {
statusCode,
headers: {
'Content-Type': 'application/json',
'Cache-Control': cacheControl || DEFAULT_CACHE,
},
body: (await results.json()).results,
};
} catch (e) {
log[logLevel](`data request to ${resource} failed ${e.message}`);
return {
statusCode,
headers: {
'Content-Type': 'application/json',
'Cache-Control': 'max-age=60',
},
body: [],
};
}
}

module.exports = {
required: [],
pattern: (url) => /(^https:\/\/adobeioruntime\.net\/api\/v1\/web\/helix\/helix-services\/run-query@.*)/.test(url)
|| /^\/?_query\/run-query\/.*$/.test(new URL(url).pathname),
extract,
};
Loading