Skip to content
Open
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
Binary file added packages/backend/dump.rdb
Binary file not shown.
3 changes: 3 additions & 0 deletions packages/backend/src/apps/usda-food-data/actions/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import searchFood from './search-food/index.js';

export default [searchFood];
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import defineAction from '../../../../helpers/define-action.js';

export default defineAction({
name: 'Search Food',
key: 'searchFood',
description: 'Search for foods using keywords',
arguments: [
{
label: 'Food item',
key: 'query',
type: 'string',
required: true,
variables: true,
description: '',
},
],

async run($) {
const query = $.step.parameters.query;
const params = { query: query, pageNumber: 2, pageSize: 25 };
const { data } = await $.http.get('/v1/foods/search', { params });
$.setActionItem({ raw: data });
},
});
12 changes: 12 additions & 0 deletions packages/backend/src/apps/usda-food-data/assets/favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions packages/backend/src/apps/usda-food-data/auth/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import verifyCredentials from './verify-credentials.js';
import isStillVerified from './is-still-verified.js';

export default {
fields: [
{
key: 'screenName',
label: 'Screen Name',
type: 'string',
required: true,
readOnly: false,
value: null,
placeholder: null,
description:
'Screen name of your connection to be used on Automatisch UI.',
clickToCopy: false,
},
{
key: 'apiKey',
label: 'API Key',
type: 'string',
required: true,
readOnly: false,
value: null,
placeholder: null,
description: 'Food Data Central API key of your account.',
clickToCopy: false,
},
],

verifyCredentials,
isStillVerified,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import verifyCredentials from './verify-credentials.js';

const isStillVerified = async ($) => {
await verifyCredentials($);
return true;
};

export default isStillVerified;
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const verifyCredentials = async ($) => {
await $.http.get('/v1/foods/list');

await $.auth.set({
screenName: $.auth.data.screenName,
apiKey: $.auth.data.apiKey,
});
};

export default verifyCredentials;
12 changes: 12 additions & 0 deletions packages/backend/src/apps/usda-food-data/common/add-auth-header.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const addAuthHeader = ($, requestConfig) => {
if ($.auth.data?.apiKey) {
requestConfig.params = {
...requestConfig.params,
api_key: $.auth.data.apiKey,
};
}

return requestConfig;
};

export default addAuthHeader;
18 changes: 18 additions & 0 deletions packages/backend/src/apps/usda-food-data/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import defineApp from '../../helpers/define-app.js';
import addAuthHeader from './common/add-auth-header.js';
import auth from './auth/index.js';
import actions from './actions/index.js';

export default defineApp({
name: 'USDA Food Data',
key: 'usda-food-data',
iconUrl: '{BASE_URL}/apps/usda-food-data/assets/favicon.svg',
authDocUrl: '',
supportsConnections: true,
baseUrl: 'https://api.nal.usda.gov/fdc',
apiBaseUrl: 'https://api.nal.usda.gov/fdc',
primaryColor: '#6f42c1',
beforeRequest: [addAuthHeader],
auth,
actions,
});