Skip to content

Commit

Permalink
Changed Env to SAIL_DIRECTORY_URL
Browse files Browse the repository at this point in the history
  • Loading branch information
robmoffat committed Oct 28, 2022
1 parent b0c3a8d commit 3cb6f65
Show file tree
Hide file tree
Showing 8 changed files with 825 additions and 449 deletions.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,16 @@ The local appD will run at `localhost:8080` by default.

By default, the Desktop Agent points to the local directory in development and to the `https://appd.kolbito.com` directory in production. You can change the local settings in `scripts/watch.js` by modifying the entries for `VITE_DEV_DIRECTORY_URL` and change the production setting by modifying the value for `productionDirectory` in `packages/main/src/utils.ts`.

## Getting Started
## Getting Started (Using the FINOS App Directory)

~~~
npm install
npm start
~~~

This will use the FINOS app directory at https://directory.fdc3.finos.org/v2/apps

## Getting Started With Your Own App Directory

Install dependencies:

Expand All @@ -99,6 +108,12 @@ npm run start:directory

This will run a local App Directory on port 8080.

Set the environment variable to use this directory:

~~~
export SAIL_DIRECTORY_URL=https://localhost:8080
~~~

Start the FDC3 application:

~~~
Expand Down
1,217 changes: 792 additions & 425 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions packages/main/src/directory/directory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,10 @@ export class Directory {
retrieveByName(name: string): DirectoryApp[] {
return this.retrieve((app) => app.name == name);
}

retrieveByQuery(query: string): DirectoryApp[] {
// tbd
console.log('Directory Query: ' + query);
return this.apps;
}
}
2 changes: 1 addition & 1 deletion packages/main/src/directory/fdc3-2_0-loaders.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { readFile } from 'fs/promises';
import { DirectoryApp } from './directory';
import fetch from 'electron-fetch';

const convertToDirectoryList = (data: unknown) => data as DirectoryApp[];
const convertSingleApp = (data: unknown) => [data] as DirectoryApp[];
Expand All @@ -10,7 +11,6 @@ const convertSingleApp = (data: unknown) => [data] as DirectoryApp[];
*/
export function fdc3AppDirectoryLoader(u: string): Promise<DirectoryApp[]> {
let converter;
console.log('IN: ' + process.cwd());

if (u.endsWith('/v2/apps') || u.endsWith('/v2/apps/')) {
// whole directory
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import { getRuntime } from '../../index';
import { RuntimeMessage } from '../runtimeMessage';
import { WebContents } from 'electron';
import utils from '../../utils';
import fetch from 'electron-fetch';
import { RUNTIME_TOPICS } from './topics';
import { Runtime } from '/@/runtime';

export function initFetchFromDirectory(
runtime: Runtime = getRuntime(),
): (message: RuntimeMessage) => Promise<void> {
return async (message: RuntimeMessage) => {
const directoryUrl = await utils.getDirectoryUrl();
const directory = runtime.getDirectory();

const response = await fetch(`${directoryUrl}${message.data.query}`);
const result = await response.json();
const result = directory.retrieveByQuery(message.data.query);

//request can come frome 2 types of (priviledged) sources: the workspace UI and views
//if the sourceType is View. We need to check that the view is a 'system' view and can access the directory
Expand Down
2 changes: 1 addition & 1 deletion packages/main/src/handlers/runtime/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { openToolsMenu } from './toolbar';
import { pickChannel, joinChannel } from './channelPicker';
import { loadSearchResults } from './search';
import { resolveIntent } from '../fdc3/resolveIntent';
import { initFetchFromDirectory } from './directory';
import { initFetchFromDirectory } from './directory-fetch';

export const register = (runtime: Runtime) => {
runtime.addHandler(RUNTIME_TOPICS.TAB_SELECTED, tabSelected);
Expand Down
20 changes: 7 additions & 13 deletions packages/main/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,16 @@
import { channels } from './system-channels';
import { ChannelData } from './types/FDC3Data';
import { FDC3EventDetail } from './types/FDC3Event';
import { DirectoryPort } from '../../../directory/src/config';

const productionDirectory = 'https://appd.kolbito.com';
const DEFAULT_DIRECTORY = 'https://directory.fdc3.finos.org/v2/apps';

const getDirectoryUrl = (): Promise<string> => {
return new Promise((resolve) => {
const url: string =
import.meta.env.DEV && import.meta.env.VITE_DEV_DIRECTORY_URL
? `${import.meta.env.VITE_DEV_DIRECTORY_URL}`
: productionDirectory;

if (url === 'local') {
resolve(`http://localhost:${DirectoryPort}`);
} else {
resolve(url);
}
return new Promise(() => {
const url: string = import.meta.env.SAIL_DIRECTORY_URL
? `${import.meta.env.SAIL_DIRECTORY_URL}`
: DEFAULT_DIRECTORY;

return url;
});
};

Expand Down
3 changes: 0 additions & 3 deletions scripts/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ const setupMainPackageWatcher = ({ config: { server } }) => {
process.env.VITE_DEV_SERVER_CHANNEL_URL = `${protocol}//${host}:${port}${path}channelPicker.html`;
process.env.VITE_DEV_SERVER_SEARCH_URL = `${protocol}//${host}:${port}${path}searchResults.html`;
process.env.VITE_DEV_SERVER_INTENTS_URL = `${protocol}//${host}:${port}${path}intentResolver.html`;

//set directory address. 'local' will be resolved to the local directory in the project
process.env.VITE_DEV_DIRECTORY_URL = 'local';
}

const logger = createLogger(LOG_LEVEL, {
Expand Down

0 comments on commit 3cb6f65

Please sign in to comment.