@baukit/suite-client 0.10.3 → 0.10.5
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 +9 -6
- package/dist/connected.d.ts +4 -0
- package/dist/connected.d.ts.map +1 -1
- package/dist/connected.js +1 -1
- package/dist/connected.js.map +1 -1
- package/package.json +3 -3
- package/src/client.test.ts +15 -7
- package/src/connected.ts +6 -2
package/README.md
CHANGED
|
@@ -27,18 +27,21 @@ const client = new SuiteClient(transport);
|
|
|
27
27
|
const connectedApps = new ConnectedApps(client, session);
|
|
28
28
|
await connectedApps.load();
|
|
29
29
|
const result = await connectedApps.connect('beta');
|
|
30
|
-
if (result.type === 'ready' && result.completed) {
|
|
30
|
+
if ((result.type === 'ready' || result.type === 'failed') && result.completed) {
|
|
31
31
|
if (navigation.claimSuiteConnectionAnnouncement(result.completed.requestId)) {
|
|
32
32
|
announceConnected(result.completed.peerApp);
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
-
A successful
|
|
38
|
-
`completed: { peerApp, requestId }
|
|
39
|
-
|
|
40
|
-
`
|
|
41
|
-
|
|
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
|
|
42
45
|
notice by request id. The session redeems the code once even if both paths fire.
|
|
43
46
|
|
|
44
47
|
## Pages and native intents
|
package/dist/connected.d.ts
CHANGED
|
@@ -18,6 +18,10 @@ export type ConnectedAppsState = {
|
|
|
18
18
|
} | {
|
|
19
19
|
readonly type: 'failed';
|
|
20
20
|
readonly code: string;
|
|
21
|
+
readonly completed?: {
|
|
22
|
+
readonly peerApp: string;
|
|
23
|
+
readonly requestId: string;
|
|
24
|
+
};
|
|
21
25
|
};
|
|
22
26
|
export declare function suiteConnectionState(link: SuiteLink | undefined): 'not_connected' | 'connected' | 'needs_attention' | 'disabled';
|
|
23
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;IACrC,QAAQ,CAAC,SAAS,CAAC,EAAE;QAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;CAC/E,GACD;IAAE,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACzD;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,GAAG,WAAW,CAAA;CAAE,GACzC;
|
|
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,M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CAAC;CAqBnE"}
|
package/dist/connected.js
CHANGED
|
@@ -40,7 +40,7 @@ export class ConnectedApps {
|
|
|
40
40
|
const result = await this.session.connect(peerApp);
|
|
41
41
|
if (result.type === 'connected') {
|
|
42
42
|
const loaded = await this.load();
|
|
43
|
-
if (loaded.type === 'ready') {
|
|
43
|
+
if (loaded.type === 'ready' || loaded.type === 'failed') {
|
|
44
44
|
this.#state = {
|
|
45
45
|
...loaded,
|
|
46
46
|
completed: { peerApp, requestId: result.requestId },
|
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;IAC7B,OAAO,WAAW,CAAC;AACrB,CAAC;AACD,MAAM,OAAO,aAAa;IAGL;IACA;IAHnB,MAAM,GAAuB,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;IACjD,YACmB,MAAmB,EACnB,OAAqB;QADrB,WAAM,GAAN,MAAM,CAAa;QAC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,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.5",
|
|
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.5",
|
|
63
|
+
"@baukit/localization-core": "^0.10.5"
|
|
64
64
|
}
|
|
65
65
|
}
|
package/src/client.test.ts
CHANGED
|
@@ -459,10 +459,17 @@ describe('authorize state', () => {
|
|
|
459
459
|
});
|
|
460
460
|
});
|
|
461
461
|
describe('connected apps and linked page', () => {
|
|
462
|
-
it.each([
|
|
463
|
-
|
|
464
|
-
|
|
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 }) => {
|
|
465
470
|
const f = sessionFixture();
|
|
471
|
+
const list = vi.spyOn(f.client, 'list');
|
|
472
|
+
if (refreshFails) list.mockRejectedValue(new SuiteFlowError('suite_peer_unreachable'));
|
|
466
473
|
const connected = new ConnectedApps(f.client, f.session);
|
|
467
474
|
const navigation = createSuiteNavigationStore(() => 'notice');
|
|
468
475
|
const linked = new SuiteLinkedMachine({
|
|
@@ -480,12 +487,12 @@ describe('connected apps and linked page', () => {
|
|
|
480
487
|
const claimNative = async () => {
|
|
481
488
|
const state = await native;
|
|
482
489
|
expect(state).toEqual({
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
490
|
+
...(refreshFails
|
|
491
|
+
? { type: 'failed', code: 'suite_peer_unreachable' }
|
|
492
|
+
: { type: 'ready', peers: [], links: [] }),
|
|
486
493
|
completed: { peerApp: 'beta', requestId: 'request' },
|
|
487
494
|
});
|
|
488
|
-
if (state.type === 'ready' && state.completed) {
|
|
495
|
+
if ((state.type === 'ready' || state.type === 'failed') && state.completed) {
|
|
489
496
|
claims.push(navigation.claimSuiteConnectionAnnouncement(state.completed.requestId));
|
|
490
497
|
}
|
|
491
498
|
};
|
|
@@ -505,6 +512,7 @@ describe('connected apps and linked page', () => {
|
|
|
505
512
|
}
|
|
506
513
|
expect(claims).toEqual([true, false]);
|
|
507
514
|
expect(f.request.mock.calls.filter(([, path]) => path.endsWith('/complete'))).toHaveLength(1);
|
|
515
|
+
list.mockRestore();
|
|
508
516
|
expect(await connected.load()).toEqual({ type: 'ready', peers: [], links: [] });
|
|
509
517
|
},
|
|
510
518
|
);
|
package/src/connected.ts
CHANGED
|
@@ -10,7 +10,11 @@ export type ConnectedAppsState =
|
|
|
10
10
|
}
|
|
11
11
|
| { readonly type: 'connecting'; readonly peerApp: string }
|
|
12
12
|
| { readonly type: 'denied' | 'cancelled' }
|
|
13
|
-
| {
|
|
13
|
+
| {
|
|
14
|
+
readonly type: 'failed';
|
|
15
|
+
readonly code: string;
|
|
16
|
+
readonly completed?: { readonly peerApp: string; readonly requestId: string };
|
|
17
|
+
};
|
|
14
18
|
export function suiteConnectionState(
|
|
15
19
|
link: SuiteLink | undefined,
|
|
16
20
|
): 'not_connected' | 'connected' | 'needs_attention' | 'disabled' {
|
|
@@ -47,7 +51,7 @@ export class ConnectedApps {
|
|
|
47
51
|
const result = await this.session.connect(peerApp);
|
|
48
52
|
if (result.type === 'connected') {
|
|
49
53
|
const loaded = await this.load();
|
|
50
|
-
if (loaded.type === 'ready') {
|
|
54
|
+
if (loaded.type === 'ready' || loaded.type === 'failed') {
|
|
51
55
|
this.#state = {
|
|
52
56
|
...loaded,
|
|
53
57
|
completed: { peerApp, requestId: result.requestId },
|