Skip to content

Commit 840e5c5

Browse files
authored
Merge pull request #356 from rikoe/release/1.1
fix: add reject/throw if fdc3 is not available to package
2 parents d9a1a44 + c3d83b7 commit 840e5c5

File tree

4 files changed

+237
-136
lines changed

4 files changed

+237
-136
lines changed

.github/workflows/package.yml

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ on:
88
push:
99
branches:
1010
- master
11+
- release/**
1112
paths-ignore:
1213
- '.github/workflows/docusaurus.yml'
1314
- 'docs/**'
1415
- 'website/**'
1516
pull_request:
1617
branches:
1718
- master
19+
- release/*
1820
paths-ignore:
1921
- '.github/workflows/docusaurus.yml'
2022
- 'docs/**'
@@ -26,8 +28,8 @@ jobs:
2628
runs-on: ${{ matrix.os }}
2729
strategy:
2830
matrix:
29-
node: ['10.x', '12.x', '14.x']
30-
os: [ubuntu-latest, windows-latest, macOS-latest]
31+
node: ['14.x']
32+
os: [ubuntu-latest, windows-latest]
3133

3234
steps:
3335
- name: Checkout repo
@@ -48,4 +50,22 @@ jobs:
4850
run: yarn test --ci --coverage --maxWorkers=2
4951

5052
- name: Build
51-
run: yarn build
53+
run: yarn build
54+
55+
- name: Publish to NPM
56+
- uses: JS-DevTools/npm-publish@v1
57+
with:
58+
registry: https://registry.npmjs.org/
59+
access: public
60+
dry-run: true
61+
check-version: true
62+
token: ${{ secrets.NPM_TOKEN }}
63+
64+
- name: Publish to GitHub
65+
- uses: JS-DevTools/npm-publish@v1
66+
with:
67+
registry: https://npm.pkg.github.com
68+
access: public
69+
dry-run: true
70+
check-version: true
71+
token: ${{ secrets.GITHUB_TOKEN }}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@finos/fdc3",
3-
"version": "1.1.0-alpha.2",
3+
"version": "1.1.0-alpha.3",
44
"author": "Fintech Open Source Foundation (FINOS)",
55
"homepage": "https://fdc3.finos.org",
66
"repository": {

src/api/methods.ts

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,70 +7,85 @@ import {
77
Listener,
88
} from '..';
99

10+
const unavailableError = new Error(
11+
'FDC3 DesktopAgent not available at `window.fdc3`.'
12+
);
13+
14+
const rejectIfNoGlobal = (f: () => Promise<any>) => {
15+
return window.fdc3 ? f() : Promise.reject(unavailableError);
16+
};
17+
18+
const throwIfNoGlobal = (f: () => any) => {
19+
if (!window.fdc3) {
20+
throw unavailableError;
21+
}
22+
return f();
23+
};
24+
1025
export const open: (name: string, context?: Context) => Promise<void> = (
1126
name,
1227
context
1328
) => {
14-
return window.fdc3.open(name, context);
29+
return rejectIfNoGlobal(() => window.fdc3.open(name, context));
1530
};
1631

1732
export const findIntent: (
1833
intent: string,
1934
context?: Context
2035
) => Promise<AppIntent> = (intent, context) => {
21-
return window.fdc3.findIntent(intent, context);
36+
return rejectIfNoGlobal(() => window.fdc3.findIntent(intent, context));
2237
};
2338

2439
export const findIntentsByContext: (
2540
context: Context
2641
) => Promise<Array<AppIntent>> = context => {
27-
return window.fdc3.findIntentsByContext(context);
42+
return rejectIfNoGlobal(() => window.fdc3.findIntentsByContext(context));
2843
};
2944

3045
export const broadcast: (context: Context) => void = context => {
31-
window.fdc3.broadcast(context);
46+
throwIfNoGlobal(() => window.fdc3.broadcast(context));
3247
};
3348

3449
export const raiseIntent: (
3550
intent: string,
3651
context: Context,
3752
target?: string
3853
) => Promise<IntentResolution> = (intent, context, target) => {
39-
return window.fdc3.raiseIntent(intent, context, target);
54+
return rejectIfNoGlobal(() => window.fdc3.raiseIntent(intent, context, target));
4055
};
4156

4257
export const addIntentListener: (
4358
intent: string,
4459
handler: ContextHandler
4560
) => Listener = (intent, handler) => {
46-
return window.fdc3.addIntentListener(intent, handler);
61+
return throwIfNoGlobal(() => window.fdc3.addIntentListener(intent, handler));
4762
};
4863

4964
export const addContextListener: (
5065
contextTypeOrHandler: string | ContextHandler,
5166
handler?: ContextHandler
5267
) => Listener = (a, b) => {
5368
if (typeof a !== 'function') {
54-
return window.fdc3.addContextListener(a as string, b as ContextHandler);
69+
return throwIfNoGlobal(() =>
70+
window.fdc3.addContextListener(a as string, b as ContextHandler)
71+
);
5572
} else {
56-
return window.fdc3.addContextListener(a as ContextHandler);
73+
return throwIfNoGlobal(() =>
74+
window.fdc3.addContextListener(a as ContextHandler)
75+
);
5776
}
5877
};
5978

6079
export const getSystemChannels: () => Promise<Array<Channel>> = () => {
61-
return window.fdc3.getSystemChannels();
80+
return rejectIfNoGlobal(() => window.fdc3.getSystemChannels());
6281
};
6382

6483
export const joinChannel: (channelId: string) => Promise<void> = channelId => {
65-
return window.fdc3.joinChannel(channelId);
84+
return rejectIfNoGlobal(() => window.fdc3.joinChannel(channelId));
6685
};
6786

6887
export const getOrCreateChannel: (
6988
channelId: string
7089
) => Promise<Channel> = channelId => {
71-
return window.fdc3.getOrCreateChannel(channelId);
72-
};
73-
74-
export const getCurrentChannel: () => Promise<Channel> = () => {
75-
return window.fdc3.getCurrentChannel();
76-
};
90+
return rejectIfNoGlobal(() => window.fdc3.getOrCreateChannel(channelId));
91+
};

0 commit comments

Comments
 (0)