@baukit/suite-client 0.10.2 → 0.10.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -1
- package/dist/connected.d.ts +8 -0
- package/dist/connected.d.ts.map +1 -1
- package/dist/connected.js +10 -2
- package/dist/connected.js.map +1 -1
- package/package.json +3 -3
- package/src/client.test.ts +58 -0
- package/src/connected.ts +16 -2
package/README.md
CHANGED
|
@@ -26,9 +26,24 @@ import { SuiteClient, ConnectedApps } from '@baukit/suite-client';
|
|
|
26
26
|
const client = new SuiteClient(transport);
|
|
27
27
|
const connectedApps = new ConnectedApps(client, session);
|
|
28
28
|
await connectedApps.load();
|
|
29
|
-
await connectedApps.connect('beta');
|
|
29
|
+
const result = await connectedApps.connect('beta');
|
|
30
|
+
if ((result.type === 'ready' || result.type === 'failed') && result.completed) {
|
|
31
|
+
if (navigation.claimSuiteConnectionAnnouncement(result.completed.requestId)) {
|
|
32
|
+
announceConnected(result.completed.peerApp);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
30
35
|
```
|
|
31
36
|
|
|
37
|
+
A successful connection refreshes the lists. `connect()` returns
|
|
38
|
+
`completed: { peerApp, requestId }` on the `ready` state, or on the `failed` state
|
|
39
|
+
if that refresh fails. A failed state with `completed` means the server connected
|
|
40
|
+
the apps; its `code` describes the refresh error. Handle that error separately
|
|
41
|
+
from the connection announcement. A later `load()` clears `completed`.
|
|
42
|
+
|
|
43
|
+
Share one `SuiteNavigationStore` between this caller and `SuiteLinkedMachine`.
|
|
44
|
+
Its announcement guard deduplicates the native auth-session result and redirect
|
|
45
|
+
notice by request id. The session redeems the code once even if both paths fire.
|
|
46
|
+
|
|
32
47
|
## Pages and native intents
|
|
33
48
|
|
|
34
49
|
Use `parseSuiteAuthorizeQuery` before constructing `SuiteAuthorizeMachine`.
|
package/dist/connected.d.ts
CHANGED
|
@@ -6,6 +6,10 @@ export type ConnectedAppsState = {
|
|
|
6
6
|
readonly type: 'ready';
|
|
7
7
|
readonly peers: readonly SuitePeer[];
|
|
8
8
|
readonly links: readonly SuiteLink[];
|
|
9
|
+
readonly completed?: {
|
|
10
|
+
readonly peerApp: string;
|
|
11
|
+
readonly requestId: string;
|
|
12
|
+
};
|
|
9
13
|
} | {
|
|
10
14
|
readonly type: 'connecting';
|
|
11
15
|
readonly peerApp: string;
|
|
@@ -14,6 +18,10 @@ export type ConnectedAppsState = {
|
|
|
14
18
|
} | {
|
|
15
19
|
readonly type: 'failed';
|
|
16
20
|
readonly code: string;
|
|
21
|
+
readonly completed?: {
|
|
22
|
+
readonly peerApp: string;
|
|
23
|
+
readonly requestId: string;
|
|
24
|
+
};
|
|
17
25
|
};
|
|
18
26
|
export declare function suiteConnectionState(link: SuiteLink | undefined): 'not_connected' | 'connected' | 'needs_attention' | 'disabled';
|
|
19
27
|
export declare class ConnectedApps {
|
package/dist/connected.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connected.d.ts","sourceRoot":"","sources":["../src/connected.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAkB,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,UAAU,CAAC;AACvF,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,MAAM,MAAM,kBAAkB,GAC1B;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;CAAE,GAC5B;IACE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,SAAS,SAAS,EAAE,CAAC;IACrC,QAAQ,CAAC,KAAK,EAAE,SAAS,SAAS,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"connected.d.ts","sourceRoot":"","sources":["../src/connected.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAkB,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,UAAU,CAAC;AACvF,OAAO,EAAE,YAAY,EAA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kB,CAAC;CAqBnE"}
|
package/dist/connected.js
CHANGED
|
@@ -38,8 +38,16 @@ export class ConnectedApps {
|
|
|
38
38
|
this.#state = { type: 'connecting', peerApp };
|
|
39
39
|
try {
|
|
40
40
|
const result = await this.session.connect(peerApp);
|
|
41
|
-
if (result.type === 'connected')
|
|
42
|
-
|
|
41
|
+
if (result.type === 'connected') {
|
|
42
|
+
const loaded = await this.load();
|
|
43
|
+
if (loaded.type === 'ready' || loaded.type === 'failed') {
|
|
44
|
+
this.#state = {
|
|
45
|
+
...loaded,
|
|
46
|
+
completed: { peerApp, requestId: result.requestId },
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
return this.#state;
|
|
50
|
+
}
|
|
43
51
|
this.#state = { type: result.type };
|
|
44
52
|
}
|
|
45
53
|
catch (error) {
|
package/dist/connected.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connected.js","sourceRoot":"","sources":["../src/connected.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAkC,MAAM,UAAU,CAAC;AACvF,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"connected.js","sourceRoot":"","sources":["../src/connected.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAkC,MAAM,UAAU,CAAC;AACvF,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAgB5C,MAAM,UAAU,oBAAoB,CAClC,IAA2B;IAE3B,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS;QAAE,OAAO,eAAe,CAAC;IAC5E,IAAI,IAAI,CAAC,MAAM,KAAK,iBAAiB;QAAE,OAAO,iBAAiB,CAAC;IAChE,IAAI,IAAI,CAAC,cAAc,KAAK,iBAAiB,IAAI,IAAI,CAAC,cAAc,KAAK,UAAU;QACjF,OAAO,IAAI,CAAC,cAAc,CAAC;IA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KAAK,WAAW,EAAE,CAAC;gBAChC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;gBACjC,IAAI,MAAM,CAAC,IAAI,KAAK,OAAO,IAAI,MAAM,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;oBACxD,IAAI,CAAC,MAAM,GAAG;wBACZ,GAAG,MAAM;wBACT,SAAS,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,SAAS,EAAE;qBACpD,CAAC;gBACJ,CAAC;gBACD,OAAO,IAAI,CAAC,MAAM,CAAC;YACrB,CAAC;YACD,IAAI,CAAC,MAAM,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;QACtC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,MAAM,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,cAAc,CAAC,KAAK,CAAC,EAAE,CAAC;QAChE,CAAC;QACD,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@baukit/suite-client",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.4",
|
|
4
4
|
"description": "Headless suite linking, authorization state and connected app clients.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Patrick Koss",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"vitest": "5.0.3"
|
|
60
60
|
},
|
|
61
61
|
"peerDependencies": {
|
|
62
|
-
"@baukit/integrations-client": "^0.10.
|
|
63
|
-
"@baukit/localization-core": "^0.10.
|
|
62
|
+
"@baukit/integrations-client": "^0.10.4",
|
|
63
|
+
"@baukit/localization-core": "^0.10.4"
|
|
64
64
|
}
|
|
65
65
|
}
|
package/src/client.test.ts
CHANGED
|
@@ -459,6 +459,64 @@ describe('authorize state', () => {
|
|
|
459
459
|
});
|
|
460
460
|
});
|
|
461
461
|
describe('connected apps and linked page', () => {
|
|
462
|
+
it.each([
|
|
463
|
+
{ order: 'native_first', refreshFails: false },
|
|
464
|
+
{ order: 'redirect_first', refreshFails: false },
|
|
465
|
+
{ order: 'native_first', refreshFails: true },
|
|
466
|
+
{ order: 'redirect_first', refreshFails: true },
|
|
467
|
+
] as const)(
|
|
468
|
+
'returns the completed request and announces once when $order and refreshFails=$refreshFails',
|
|
469
|
+
async ({ order, refreshFails }) => {
|
|
470
|
+
const f = sessionFixture();
|
|
471
|
+
const list = vi.spyOn(f.client, 'list');
|
|
472
|
+
if (refreshFails) list.mockRejectedValue(new SuiteFlowError('suite_peer_unreachable'));
|
|
473
|
+
const connected = new ConnectedApps(f.client, f.session);
|
|
474
|
+
const navigation = createSuiteNavigationStore(() => 'notice');
|
|
475
|
+
const linked = new SuiteLinkedMachine({
|
|
476
|
+
originalUrl: f.callback,
|
|
477
|
+
session: f.session,
|
|
478
|
+
navigation,
|
|
479
|
+
refresh: async () => {
|
|
480
|
+
await connected.load();
|
|
481
|
+
},
|
|
482
|
+
scrubHistory: () => undefined,
|
|
483
|
+
});
|
|
484
|
+
const native = connected.connect('beta');
|
|
485
|
+
const redirect = linked.restore(false, true);
|
|
486
|
+
const claims: boolean[] = [];
|
|
487
|
+
const claimNative = async () => {
|
|
488
|
+
const state = await native;
|
|
489
|
+
expect(state).toEqual({
|
|
490
|
+
...(refreshFails
|
|
491
|
+
? { type: 'failed', code: 'suite_peer_unreachable' }
|
|
492
|
+
: { type: 'ready', peers: [], links: [] }),
|
|
493
|
+
completed: { peerApp: 'beta', requestId: 'request' },
|
|
494
|
+
});
|
|
495
|
+
if ((state.type === 'ready' || state.type === 'failed') && state.completed) {
|
|
496
|
+
claims.push(navigation.claimSuiteConnectionAnnouncement(state.completed.requestId));
|
|
497
|
+
}
|
|
498
|
+
};
|
|
499
|
+
const claimRedirect = async () => {
|
|
500
|
+
const state = await redirect;
|
|
501
|
+
expect(state).toEqual({ type: 'connected_apps', noticeToken: 'notice' });
|
|
502
|
+
if (state.type === 'connected_apps') {
|
|
503
|
+
claims.push(navigation.consumeSuiteNotice(state.noticeToken)?.announce ?? false);
|
|
504
|
+
}
|
|
505
|
+
};
|
|
506
|
+
if (order === 'native_first') {
|
|
507
|
+
await claimNative();
|
|
508
|
+
await claimRedirect();
|
|
509
|
+
} else {
|
|
510
|
+
await claimRedirect();
|
|
511
|
+
await claimNative();
|
|
512
|
+
}
|
|
513
|
+
expect(claims).toEqual([true, false]);
|
|
514
|
+
expect(f.request.mock.calls.filter(([, path]) => path.endsWith('/complete'))).toHaveLength(1);
|
|
515
|
+
list.mockRestore();
|
|
516
|
+
expect(await connected.load()).toEqual({ type: 'ready', peers: [], links: [] });
|
|
517
|
+
},
|
|
518
|
+
);
|
|
519
|
+
|
|
462
520
|
it('waits for restoration, scrubs history, completes and refetches before navigating', async () => {
|
|
463
521
|
const f = sessionFixture('web');
|
|
464
522
|
await f.storage.save({
|
package/src/connected.ts
CHANGED
|
@@ -6,10 +6,15 @@ export type ConnectedAppsState =
|
|
|
6
6
|
readonly type: 'ready';
|
|
7
7
|
readonly peers: readonly SuitePeer[];
|
|
8
8
|
readonly links: readonly SuiteLink[];
|
|
9
|
+
readonly completed?: { readonly peerApp: string; readonly requestId: string };
|
|
9
10
|
}
|
|
10
11
|
| { readonly type: 'connecting'; readonly peerApp: string }
|
|
11
12
|
| { readonly type: 'denied' | 'cancelled' }
|
|
12
|
-
| {
|
|
13
|
+
| {
|
|
14
|
+
readonly type: 'failed';
|
|
15
|
+
readonly code: string;
|
|
16
|
+
readonly completed?: { readonly peerApp: string; readonly requestId: string };
|
|
17
|
+
};
|
|
13
18
|
export function suiteConnectionState(
|
|
14
19
|
link: SuiteLink | undefined,
|
|
15
20
|
): 'not_connected' | 'connected' | 'needs_attention' | 'disabled' {
|
|
@@ -44,7 +49,16 @@ export class ConnectedApps {
|
|
|
44
49
|
this.#state = { type: 'connecting', peerApp };
|
|
45
50
|
try {
|
|
46
51
|
const result = await this.session.connect(peerApp);
|
|
47
|
-
if (result.type === 'connected')
|
|
52
|
+
if (result.type === 'connected') {
|
|
53
|
+
const loaded = await this.load();
|
|
54
|
+
if (loaded.type === 'ready' || loaded.type === 'failed') {
|
|
55
|
+
this.#state = {
|
|
56
|
+
...loaded,
|
|
57
|
+
completed: { peerApp, requestId: result.requestId },
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
return this.#state;
|
|
61
|
+
}
|
|
48
62
|
this.#state = { type: result.type };
|
|
49
63
|
} catch (error) {
|
|
50
64
|
this.#state = { type: 'failed', code: suiteErrorCode(error) };
|