@baukit/suite-client 0.10.0 → 0.10.3
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 +13 -1
- package/dist/connected.d.ts +4 -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 +6 -4
- package/src/client.test.ts +50 -0
- package/src/connected.ts +11 -1
package/README.md
CHANGED
|
@@ -26,9 +26,21 @@ 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.completed) {
|
|
31
|
+
if (navigation.claimSuiteConnectionAnnouncement(result.completed.requestId)) {
|
|
32
|
+
announceConnected(result.completed.peerApp);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
30
35
|
```
|
|
31
36
|
|
|
37
|
+
A successful `connect()` refreshes the lists and returns a ready state with
|
|
38
|
+
`completed: { peerApp, requestId }`. This additive field keeps the completed
|
|
39
|
+
request id with the list state. A later `load()` clears it. Share one
|
|
40
|
+
`SuiteNavigationStore` between this caller and `SuiteLinkedMachine`; its
|
|
41
|
+
announcement guard deduplicates the native auth-session result and redirect
|
|
42
|
+
notice by request id. The session redeems the code once even if both paths fire.
|
|
43
|
+
|
|
32
44
|
## Pages and native intents
|
|
33
45
|
|
|
34
46
|
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;
|
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,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;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AACvD,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,SAAS,GAAG,SAAS,GAC1B,eAAe,GAAG,WAAW,GAAG,iBAAiB,GAAG,UAAU,CAMhE;AACD,qBAAa,aAAa;;IAGtB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,OAAO;gBADP,MAAM,EAAE,WAAW,EACnB,OAAO,EAAE,YAAY;IAExC,IAAW,KAAK,IAAI,kBAAkB,CAErC;IACY,IAAI,IAAI,OAAO,CAAC,kBAAkB,CAAC;IAUhD,oFAAoF;IACvE,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,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') {
|
|
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;AAY5C,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;QACnB,YAAO,GAAP,OAAO,CAAc;IACrC,CAAC;IACJ,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IACM,KAAK,CAAC,IAAI;QACf,IAAI,CAAC,MAAM,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;QAClC,IAAI,CAAC;YACH,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;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ACD,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.3",
|
|
4
4
|
"description": "Headless suite linking, authorization state and connected app clients.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Patrick Koss",
|
|
@@ -52,12 +52,14 @@
|
|
|
52
52
|
"format:check": "prettier --check src scripts package.json turbo.json tsconfig.json tsconfig.test.json tsconfig.cjs.json"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
+
"@baukit/integrations-client": "workspace:*",
|
|
56
|
+
"@baukit/localization-core": "workspace:*",
|
|
55
57
|
"@types/node": "26.6.4",
|
|
56
58
|
"typescript": "6.0.3",
|
|
57
59
|
"vitest": "5.0.3"
|
|
58
60
|
},
|
|
59
|
-
"
|
|
60
|
-
"@baukit/integrations-client": "
|
|
61
|
-
"@baukit/localization-core": "
|
|
61
|
+
"peerDependencies": {
|
|
62
|
+
"@baukit/integrations-client": "^0.10.3",
|
|
63
|
+
"@baukit/localization-core": "^0.10.3"
|
|
62
64
|
}
|
|
63
65
|
}
|
package/src/client.test.ts
CHANGED
|
@@ -459,6 +459,56 @@ describe('authorize state', () => {
|
|
|
459
459
|
});
|
|
460
460
|
});
|
|
461
461
|
describe('connected apps and linked page', () => {
|
|
462
|
+
it.each(['native_first', 'redirect_first'] as const)(
|
|
463
|
+
'returns the completed request and announces once when %s',
|
|
464
|
+
async (order) => {
|
|
465
|
+
const f = sessionFixture();
|
|
466
|
+
const connected = new ConnectedApps(f.client, f.session);
|
|
467
|
+
const navigation = createSuiteNavigationStore(() => 'notice');
|
|
468
|
+
const linked = new SuiteLinkedMachine({
|
|
469
|
+
originalUrl: f.callback,
|
|
470
|
+
session: f.session,
|
|
471
|
+
navigation,
|
|
472
|
+
refresh: async () => {
|
|
473
|
+
await connected.load();
|
|
474
|
+
},
|
|
475
|
+
scrubHistory: () => undefined,
|
|
476
|
+
});
|
|
477
|
+
const native = connected.connect('beta');
|
|
478
|
+
const redirect = linked.restore(false, true);
|
|
479
|
+
const claims: boolean[] = [];
|
|
480
|
+
const claimNative = async () => {
|
|
481
|
+
const state = await native;
|
|
482
|
+
expect(state).toEqual({
|
|
483
|
+
type: 'ready',
|
|
484
|
+
peers: [],
|
|
485
|
+
links: [],
|
|
486
|
+
completed: { peerApp: 'beta', requestId: 'request' },
|
|
487
|
+
});
|
|
488
|
+
if (state.type === 'ready' && state.completed) {
|
|
489
|
+
claims.push(navigation.claimSuiteConnectionAnnouncement(state.completed.requestId));
|
|
490
|
+
}
|
|
491
|
+
};
|
|
492
|
+
const claimRedirect = async () => {
|
|
493
|
+
const state = await redirect;
|
|
494
|
+
expect(state).toEqual({ type: 'connected_apps', noticeToken: 'notice' });
|
|
495
|
+
if (state.type === 'connected_apps') {
|
|
496
|
+
claims.push(navigation.consumeSuiteNotice(state.noticeToken)?.announce ?? false);
|
|
497
|
+
}
|
|
498
|
+
};
|
|
499
|
+
if (order === 'native_first') {
|
|
500
|
+
await claimNative();
|
|
501
|
+
await claimRedirect();
|
|
502
|
+
} else {
|
|
503
|
+
await claimRedirect();
|
|
504
|
+
await claimNative();
|
|
505
|
+
}
|
|
506
|
+
expect(claims).toEqual([true, false]);
|
|
507
|
+
expect(f.request.mock.calls.filter(([, path]) => path.endsWith('/complete'))).toHaveLength(1);
|
|
508
|
+
expect(await connected.load()).toEqual({ type: 'ready', peers: [], links: [] });
|
|
509
|
+
},
|
|
510
|
+
);
|
|
511
|
+
|
|
462
512
|
it('waits for restoration, scrubs history, completes and refetches before navigating', async () => {
|
|
463
513
|
const f = sessionFixture('web');
|
|
464
514
|
await f.storage.save({
|
package/src/connected.ts
CHANGED
|
@@ -6,6 +6,7 @@ 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' }
|
|
@@ -44,7 +45,16 @@ export class ConnectedApps {
|
|
|
44
45
|
this.#state = { type: 'connecting', peerApp };
|
|
45
46
|
try {
|
|
46
47
|
const result = await this.session.connect(peerApp);
|
|
47
|
-
if (result.type === 'connected')
|
|
48
|
+
if (result.type === 'connected') {
|
|
49
|
+
const loaded = await this.load();
|
|
50
|
+
if (loaded.type === 'ready') {
|
|
51
|
+
this.#state = {
|
|
52
|
+
...loaded,
|
|
53
|
+
completed: { peerApp, requestId: result.requestId },
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
return this.#state;
|
|
57
|
+
}
|
|
48
58
|
this.#state = { type: result.type };
|
|
49
59
|
} catch (error) {
|
|
50
60
|
this.#state = { type: 'failed', code: suiteErrorCode(error) };
|