@oxy.so/services 13.15.5 → 14.0.0
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/lib/commonjs/ui/components/OxyAuthChooser.js +2 -1
- package/lib/commonjs/ui/components/OxyAuthChooser.js.map +1 -1
- package/lib/commonjs/ui/components/ProfileButton.js +4 -2
- package/lib/commonjs/ui/components/ProfileButton.js.map +1 -1
- package/lib/commonjs/ui/components/organizations/OrganizationDirectorySearch.js +135 -17
- package/lib/commonjs/ui/components/organizations/OrganizationDirectorySearch.js.map +1 -1
- package/lib/commonjs/ui/navigation/accountDialogManager.js.map +1 -1
- package/lib/commonjs/ui/screens/CreateAccountScreen.js +1 -1
- package/lib/commonjs/ui/screens/CreateAccountScreen.js.map +1 -1
- package/lib/module/ui/components/OxyAuthChooser.js +2 -1
- package/lib/module/ui/components/OxyAuthChooser.js.map +1 -1
- package/lib/module/ui/components/ProfileButton.js +4 -2
- package/lib/module/ui/components/ProfileButton.js.map +1 -1
- package/lib/module/ui/components/organizations/OrganizationDirectorySearch.js +136 -18
- package/lib/module/ui/components/organizations/OrganizationDirectorySearch.js.map +1 -1
- package/lib/module/ui/navigation/accountDialogManager.js.map +1 -1
- package/lib/module/ui/screens/CreateAccountScreen.js +1 -1
- package/lib/module/ui/screens/CreateAccountScreen.js.map +1 -1
- package/lib/typescript/commonjs/ui/components/OxyAuthChooser.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/components/ProfileButton.d.ts +2 -0
- package/lib/typescript/commonjs/ui/components/ProfileButton.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/components/organizations/OrganizationDirectorySearch.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/navigation/accountDialogManager.d.ts +2 -0
- package/lib/typescript/commonjs/ui/navigation/accountDialogManager.d.ts.map +1 -1
- package/lib/typescript/module/ui/components/OxyAuthChooser.d.ts.map +1 -1
- package/lib/typescript/module/ui/components/ProfileButton.d.ts +2 -0
- package/lib/typescript/module/ui/components/ProfileButton.d.ts.map +1 -1
- package/lib/typescript/module/ui/components/organizations/OrganizationDirectorySearch.d.ts.map +1 -1
- package/lib/typescript/module/ui/navigation/accountDialogManager.d.ts +2 -0
- package/lib/typescript/module/ui/navigation/accountDialogManager.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/ui/components/OxyAuthChooser.tsx +2 -1
- package/src/ui/components/ProfileButton.tsx +12 -2
- package/src/ui/components/organizations/OrganizationDirectorySearch.tsx +188 -16
- package/src/ui/navigation/accountDialogManager.ts +2 -0
- package/src/ui/screens/CreateAccountScreen.tsx +1 -1
|
@@ -47,6 +47,8 @@ export interface AccountDialogControls {
|
|
|
47
47
|
*/
|
|
48
48
|
export interface AccountDialogConsumerHooks {
|
|
49
49
|
onAddAccount?: () => void;
|
|
50
|
+
/** Called synchronously before the shared add-account view; ignored when onAddAccount overrides it. */
|
|
51
|
+
onBeforeAddAccount?: () => void;
|
|
50
52
|
onNavigateProfile?: () => void;
|
|
51
53
|
menuItems?: readonly AccountDialogMenuItem[];
|
|
52
54
|
menuSections?: readonly AccountDialogMenuSection[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accountDialogManager.d.ts","sourceRoot":"","sources":["../../../../../src/ui/navigation/accountDialogManager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAE9D,mEAAmE;AACnE,MAAM,WAAW,qBAAqB;IACpC,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,iDAAiD;IACjD,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,iEAAiE;IACjE,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAED,yEAAyE;AACzE,MAAM,WAAW,wBAAwB;IACvC,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,SAAS,qBAAqB,EAAE,CAAC;CACzC;AAED;;;;GAIG;AACH,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,CAAC,IAAI,CAAC,EAAE,iBAAiB,KAAK,IAAI,CAAC;IACzC,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED;;;;;GAKG;AACH,MAAM,WAAW,0BAA0B;IACzC,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;IAC1B,iBAAiB,CAAC,EAAE,MAAM,IAAI,CAAC;IAC/B,SAAS,CAAC,EAAE,SAAS,qBAAqB,EAAE,CAAC;IAC7C,YAAY,CAAC,EAAE,SAAS,wBAAwB,EAAE,CAAC;CACpD;AAaD,wBAAgB,6BAA6B,CAAC,IAAI,EAAE,qBAAqB,GAAG,MAAM,IAAI,CAOrF;AAED,uFAAuF;AACvF,wBAAgB,kCAAkC,CAChD,IAAI,EAAE,0BAA0B,GAAG,IAAI,GACtC,MAAM,IAAI,CASZ;AAED,wBAAgB,6BAA6B,IAAI,0BAA0B,GAAG,IAAI,CAEjF;AAED,2FAA2F;AAC3F,wBAAgB,qCAAqC,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAKtF;AAED,kFAAkF;AAClF,wBAAgB,iBAAiB,CAAC,IAAI,CAAC,EAAE,iBAAiB,GAAG,IAAI,CAEhE;AAED,oDAAoD;AACpD,wBAAgB,kBAAkB,IAAI,IAAI,CAEzC;AAED,sFAAsF;AACtF,wBAAgB,6BAA6B,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAIpE;AAED,sDAAsD;AACtD,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,GAAG,MAAM,IAAI,CAKzF"}
|
|
1
|
+
{"version":3,"file":"accountDialogManager.d.ts","sourceRoot":"","sources":["../../../../../src/ui/navigation/accountDialogManager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAE9D,mEAAmE;AACnE,MAAM,WAAW,qBAAqB;IACpC,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,iDAAiD;IACjD,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,iEAAiE;IACjE,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAED,yEAAyE;AACzE,MAAM,WAAW,wBAAwB;IACvC,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,SAAS,qBAAqB,EAAE,CAAC;CACzC;AAED;;;;GAIG;AACH,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,CAAC,IAAI,CAAC,EAAE,iBAAiB,KAAK,IAAI,CAAC;IACzC,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED;;;;;GAKG;AACH,MAAM,WAAW,0BAA0B;IACzC,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;IAC1B,uGAAuG;IACvG,kBAAkB,CAAC,EAAE,MAAM,IAAI,CAAC;IAChC,iBAAiB,CAAC,EAAE,MAAM,IAAI,CAAC;IAC/B,SAAS,CAAC,EAAE,SAAS,qBAAqB,EAAE,CAAC;IAC7C,YAAY,CAAC,EAAE,SAAS,wBAAwB,EAAE,CAAC;CACpD;AAaD,wBAAgB,6BAA6B,CAAC,IAAI,EAAE,qBAAqB,GAAG,MAAM,IAAI,CAOrF;AAED,uFAAuF;AACvF,wBAAgB,kCAAkC,CAChD,IAAI,EAAE,0BAA0B,GAAG,IAAI,GACtC,MAAM,IAAI,CASZ;AAED,wBAAgB,6BAA6B,IAAI,0BAA0B,GAAG,IAAI,CAEjF;AAED,2FAA2F;AAC3F,wBAAgB,qCAAqC,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAKtF;AAED,kFAAkF;AAClF,wBAAgB,iBAAiB,CAAC,IAAI,CAAC,EAAE,iBAAiB,GAAG,IAAI,CAEhE;AAED,oDAAoD;AACpD,wBAAgB,kBAAkB,IAAI,IAAI,CAEzC;AAED,sFAAsF;AACtF,wBAAgB,6BAA6B,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAIpE;AAED,sDAAsD;AACtD,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,GAAG,MAAM,IAAI,CAKzF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oxy.so/services",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "14.0.0",
|
|
4
4
|
"description": "OxyHQ Expo/React Native SDK — UI components, screens, and native features",
|
|
5
5
|
"main": "lib/commonjs/index.js",
|
|
6
6
|
"module": "lib/module/index.js",
|
|
@@ -185,7 +185,7 @@
|
|
|
185
185
|
"@commitlint/config-conventional": "^21.2.0",
|
|
186
186
|
"@expo/app-integrity": "~58.0.2",
|
|
187
187
|
"@expo/vector-icons": "^15.0.3",
|
|
188
|
-
"@oxy.so/core": "7.10.
|
|
188
|
+
"@oxy.so/core": "7.10.6",
|
|
189
189
|
"@react-native-async-storage/async-storage": "^2.0.0",
|
|
190
190
|
"@react-native-community/netinfo": "^12.0.1",
|
|
191
191
|
"@react-native/babel-preset": "^0.88.0",
|
|
@@ -235,13 +235,13 @@
|
|
|
235
235
|
"expo-video": "~58.0.12"
|
|
236
236
|
},
|
|
237
237
|
"//@oxy.so/bloom": "Bloom 11.1.0 adds the shared grouped sections, usage card, subscription plans, frame appearance and overlay navigation APIs used by this SDK. First-party Bloom peers remain open above this tested minimum.",
|
|
238
|
-
"//@oxy.so/core": "Core 7.9.0 supplies `deviceComparisonCode`, the short code `OxyDeviceSignIn` prints; 7.8.0 supplies the device sign-in request's `approvalUrl` and the `signin.device.*` strings `OxyDeviceSignIn` shows; 7.7.0 supplies the bounded native asset file adapter and phase progress installed by OxyProvider; 7.6.0 forwards guest locale and first-touch campaign metadata through signup; 7.3.0 supplies `users.lookupMany`, with which the account members screen fails (and retries) a profile read whose chunk failed instead of caching those members as handle-less; 7.2.0 supplies `assets.cachedUrl`, with which `useFileDownloadUrl` answers an already-resolved URL in its first render; 6.16.0 supplies `requireServerVerdict` and `onHolderRejected`, with which the cold boot checks a session it painted from the cache; 6.13.0 supplies the `accounts.settings.*` strings (picture, categories) the account settings speak in every language; 6.12.0 supplies `fileManagement.contentLost` and the `lost` file status a lost file is listed with; 6.11.0 supplies the `follow.errors.*` strings the follow error codes are worded with; 6.4.0 the `follow.*` strings the follow buttons read for every verb and language; 6.1.0 the `oxy.auth.email.{startChange,change,remove}` and `oxy.auth.password.remove` the sign-in & security panels call. Keep one Core instance per app; raise this floor with the root catalogue when new runtime APIs are required.",
|
|
238
|
+
"//@oxy.so/core": "Core 7.9.1 fences ordinary authenticated HTTP requests across session changes during auth preflight, which organization claim and creation require; 7.9.0 supplies `deviceComparisonCode`, the short code `OxyDeviceSignIn` prints; 7.8.0 supplies the device sign-in request's `approvalUrl` and the `signin.device.*` strings `OxyDeviceSignIn` shows; 7.7.0 supplies the bounded native asset file adapter and phase progress installed by OxyProvider; 7.6.0 forwards guest locale and first-touch campaign metadata through signup; 7.3.0 supplies `users.lookupMany`, with which the account members screen fails (and retries) a profile read whose chunk failed instead of caching those members as handle-less; 7.2.0 supplies `assets.cachedUrl`, with which `useFileDownloadUrl` answers an already-resolved URL in its first render; 6.16.0 supplies `requireServerVerdict` and `onHolderRejected`, with which the cold boot checks a session it painted from the cache; 6.13.0 supplies the `accounts.settings.*` strings (picture, categories) the account settings speak in every language; 6.12.0 supplies `fileManagement.contentLost` and the `lost` file status a lost file is listed with; 6.11.0 supplies the `follow.errors.*` strings the follow error codes are worded with; 6.4.0 the `follow.*` strings the follow buttons read for every verb and language; 6.1.0 the `oxy.auth.email.{startChange,change,remove}` and `oxy.auth.password.remove` the sign-in & security panels call. Keep one Core instance per app; raise this floor with the root catalogue when new runtime APIs are required.",
|
|
239
239
|
"//react-native": "React Native 0.81 to 0.88, React 19.1+ and Expo SDK 54 to 58. The floors are the Expo SDK 54 stack (react-native 0.81.6, react 19.1.4, react-native-web 0.21.4, expo 54.0.38 and the module versions its bundledNativeModules.json pins), which compat/expo-54 installs as an external consumer and checks on every CI run (`bun check.mjs`): every peer here admits that stack, services' published src typechecks against its types, and <OxyProvider> mounts and settles its cold boot on iOS (React Native 0.81), web (react-native-web 0.21) and react-native-macos 0.81 with the native modules macOS lacks absent. Astro, Oxy's browser, runs react-native-macos 0.81 (0.83 is its latest release), which is why the floor is not 0.85. The SDK 56 floors these replaced were the versions current when the ranges were first written, not measurements.",
|
|
240
240
|
"peerDependencies": {
|
|
241
241
|
"@expo/app-integrity": ">=0.1.10 <59.0.0",
|
|
242
242
|
"@expo/vector-icons": "^15.0.3",
|
|
243
243
|
"@oxy.so/bloom": ">=11.1.0",
|
|
244
|
-
"@oxy.so/core": "^7.9.
|
|
244
|
+
"@oxy.so/core": "^7.9.1",
|
|
245
245
|
"@react-native-async-storage/async-storage": "^2.0.0",
|
|
246
246
|
"@react-native-community/netinfo": ">=11.4.1 <13.0.0",
|
|
247
247
|
"@tanstack/query-async-storage-persister": "^5.101",
|
|
@@ -301,7 +301,8 @@ const OxyAuthChooser: React.FC<OxyAuthChooserProps> = ({ onComplete }) => {
|
|
|
301
301
|
consumerHooks.onAddAccount();
|
|
302
302
|
return;
|
|
303
303
|
}
|
|
304
|
-
// No consumer override:
|
|
304
|
+
// No consumer override: let the host close its drawer before the shared view.
|
|
305
|
+
consumerHooks?.onBeforeAddAccount?.();
|
|
305
306
|
controller?.add();
|
|
306
307
|
}, [consumerHooks, controller, onComplete]);
|
|
307
308
|
|
|
@@ -35,6 +35,8 @@ export interface ProfileButtonProps {
|
|
|
35
35
|
avatarSize?: number;
|
|
36
36
|
/** Start the add-account / sign-in flow for an additional account. */
|
|
37
37
|
onAddAccount?: () => void;
|
|
38
|
+
/** Called synchronously before the shared add-account view, unless onAddAccount overrides it. */
|
|
39
|
+
onBeforeAddAccount?: () => void;
|
|
38
40
|
/** Optional: navigate to the signed-in user's own profile. */
|
|
39
41
|
onNavigateProfile?: () => void;
|
|
40
42
|
/** App-owned actions rendered in the shared account menu. */
|
|
@@ -62,6 +64,7 @@ const ProfileButton: React.FC<ProfileButtonProps> = ({
|
|
|
62
64
|
expanded = true,
|
|
63
65
|
avatarSize,
|
|
64
66
|
onAddAccount,
|
|
67
|
+
onBeforeAddAccount,
|
|
65
68
|
onNavigateProfile,
|
|
66
69
|
menuItems,
|
|
67
70
|
menuSections,
|
|
@@ -80,16 +83,23 @@ const ProfileButton: React.FC<ProfileButtonProps> = ({
|
|
|
80
83
|
}, [openAccountDialog]);
|
|
81
84
|
|
|
82
85
|
useEffect(() => {
|
|
83
|
-
if (
|
|
86
|
+
if (
|
|
87
|
+
!onAddAccount &&
|
|
88
|
+
!onBeforeAddAccount &&
|
|
89
|
+
!onNavigateProfile &&
|
|
90
|
+
!menuItems?.length &&
|
|
91
|
+
!menuSections?.length
|
|
92
|
+
) {
|
|
84
93
|
return undefined;
|
|
85
94
|
}
|
|
86
95
|
return registerAccountDialogConsumerHooks({
|
|
87
96
|
onAddAccount,
|
|
97
|
+
onBeforeAddAccount,
|
|
88
98
|
onNavigateProfile,
|
|
89
99
|
menuItems,
|
|
90
100
|
menuSections,
|
|
91
101
|
});
|
|
92
|
-
}, [onAddAccount, onNavigateProfile, menuItems, menuSections]);
|
|
102
|
+
}, [onAddAccount, onBeforeAddAccount, onNavigateProfile, menuItems, menuSections]);
|
|
93
103
|
|
|
94
104
|
const avatarUrl = useMemo(
|
|
95
105
|
() => (user?.avatar ? oxyServices.assets.publicUrl(user.avatar, 'thumb') : undefined),
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
useCallback,
|
|
3
|
+
useEffect,
|
|
4
|
+
useLayoutEffect,
|
|
5
|
+
useRef,
|
|
6
|
+
useState,
|
|
7
|
+
useSyncExternalStore,
|
|
8
|
+
} from 'react';
|
|
2
9
|
import { ActivityIndicator, View } from 'react-native';
|
|
3
10
|
import { useInfiniteQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
|
4
11
|
import type { Organization, OrganizationType } from '@oxy.so/contracts';
|
|
@@ -15,6 +22,7 @@ import { TextField, TextFieldInput } from '@oxy.so/bloom/text-field';
|
|
|
15
22
|
import { Text } from '@oxy.so/bloom/typography';
|
|
16
23
|
import { useOxy } from '../../context/oxyRuntimeContext';
|
|
17
24
|
import { useI18n } from '../../hooks/useI18n';
|
|
25
|
+
import { useOxyRuntime } from '../../runtime/runtimeContext';
|
|
18
26
|
import { OrganizationTypePicker } from './OrganizationTypePicker';
|
|
19
27
|
|
|
20
28
|
/** Finding an existing identity never grants ownership or silently creates an account. */
|
|
@@ -23,7 +31,48 @@ export function OrganizationDirectorySearch({
|
|
|
23
31
|
}: {
|
|
24
32
|
onCreateAccount: (name: string, type: OrganizationType) => void;
|
|
25
33
|
}) {
|
|
26
|
-
const
|
|
34
|
+
const runtime = useOxyRuntime();
|
|
35
|
+
const { oxyServices } = useOxy();
|
|
36
|
+
// Revisions are local to each instance, so equal counters do not identify a
|
|
37
|
+
// replacement provider. React retries this render before committing it.
|
|
38
|
+
const [instance, setInstance] = useState(() => ({ runtime, oxyServices, generation: 0 }));
|
|
39
|
+
let instanceGeneration = instance.generation;
|
|
40
|
+
if (instance.runtime !== runtime || instance.oxyServices !== oxyServices) {
|
|
41
|
+
instanceGeneration += 1;
|
|
42
|
+
setInstance({ runtime, oxyServices, generation: instanceGeneration });
|
|
43
|
+
}
|
|
44
|
+
const revision = useSyncExternalStore(
|
|
45
|
+
runtime.subscribe,
|
|
46
|
+
runtime.getAccountSessionRevision,
|
|
47
|
+
runtime.getAccountSessionRevision,
|
|
48
|
+
);
|
|
49
|
+
const subscribeBearer = useCallback(
|
|
50
|
+
(notify: () => void) => oxyServices.session.onChange(notify),
|
|
51
|
+
[oxyServices],
|
|
52
|
+
);
|
|
53
|
+
const getBearerEpoch = useCallback(() => oxyServices.http.getSessionEpoch(), [oxyServices]);
|
|
54
|
+
const bearerEpoch = useSyncExternalStore(subscribeBearer, getBearerEpoch, getBearerEpoch);
|
|
55
|
+
return (
|
|
56
|
+
<OrganizationDirectorySearchContent
|
|
57
|
+
key={`${instanceGeneration}:${revision}:${bearerEpoch}`}
|
|
58
|
+
revision={revision}
|
|
59
|
+
bearerEpoch={bearerEpoch}
|
|
60
|
+
onCreateAccount={onCreateAccount}
|
|
61
|
+
/>
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function OrganizationDirectorySearchContent({
|
|
66
|
+
onCreateAccount,
|
|
67
|
+
revision,
|
|
68
|
+
bearerEpoch,
|
|
69
|
+
}: {
|
|
70
|
+
onCreateAccount: (name: string, type: OrganizationType) => void;
|
|
71
|
+
revision: number;
|
|
72
|
+
bearerEpoch: number;
|
|
73
|
+
}) {
|
|
74
|
+
const runtime = useOxyRuntime();
|
|
75
|
+
const { oxyServices, user, activeSessionId, canUsePrivateApi } = useOxy();
|
|
27
76
|
const { t } = useI18n();
|
|
28
77
|
const queryClient = useQueryClient();
|
|
29
78
|
const [search, setSearch] = useState('');
|
|
@@ -34,6 +83,72 @@ export function OrganizationDirectorySearch({
|
|
|
34
83
|
const [evidence, setEvidence] = useState('');
|
|
35
84
|
const [validationError, setValidationError] = useState(false);
|
|
36
85
|
const personalReady = canUsePrivateApi && user?.kind === 'personal';
|
|
86
|
+
const lifecycle = useRef({ active: false });
|
|
87
|
+
const pending = useRef<{ claim: object | null; create: object | null }>({
|
|
88
|
+
claim: null,
|
|
89
|
+
create: null,
|
|
90
|
+
});
|
|
91
|
+
const operations = useRef(
|
|
92
|
+
new WeakMap<
|
|
93
|
+
object,
|
|
94
|
+
{
|
|
95
|
+
identity: ReturnType<typeof runtime.getAccountSessionIdentity>;
|
|
96
|
+
bearerEpoch: number;
|
|
97
|
+
accountId?: string;
|
|
98
|
+
evidence?: string;
|
|
99
|
+
name?: string;
|
|
100
|
+
type?: OrganizationType;
|
|
101
|
+
}
|
|
102
|
+
>(),
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
useLayoutEffect(() => {
|
|
106
|
+
lifecycle.current.active = true;
|
|
107
|
+
return () => {
|
|
108
|
+
lifecycle.current.active = false;
|
|
109
|
+
};
|
|
110
|
+
}, []);
|
|
111
|
+
|
|
112
|
+
function currentOwner(
|
|
113
|
+
operation: NonNullable<ReturnType<typeof operations.current.get>>,
|
|
114
|
+
): boolean {
|
|
115
|
+
const current = runtime.getAccountSessionIdentity();
|
|
116
|
+
const subject = oxyServices.session.userId;
|
|
117
|
+
return (
|
|
118
|
+
lifecycle.current.active &&
|
|
119
|
+
oxyServices.http.getSessionEpoch() === operation.bearerEpoch &&
|
|
120
|
+
current.revision === operation.identity.revision &&
|
|
121
|
+
current.accountId === operation.identity.accountId &&
|
|
122
|
+
current.sessionId === operation.identity.sessionId &&
|
|
123
|
+
!!oxyServices.session.accessToken &&
|
|
124
|
+
(subject === null || subject === current.accountId)
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function capture(input: {
|
|
129
|
+
accountId?: string;
|
|
130
|
+
evidence?: string;
|
|
131
|
+
name?: string;
|
|
132
|
+
type?: OrganizationType;
|
|
133
|
+
}): object {
|
|
134
|
+
const key = {};
|
|
135
|
+
const identity = runtime.getAccountSessionIdentity();
|
|
136
|
+
if (
|
|
137
|
+
lifecycle.current.active &&
|
|
138
|
+
personalReady &&
|
|
139
|
+
identity.revision === revision &&
|
|
140
|
+
oxyServices.http.getSessionEpoch() === bearerEpoch &&
|
|
141
|
+
identity.accountId === user?.id &&
|
|
142
|
+
identity.sessionId === activeSessionId
|
|
143
|
+
) {
|
|
144
|
+
operations.current.set(key, {
|
|
145
|
+
identity,
|
|
146
|
+
bearerEpoch,
|
|
147
|
+
...input,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
return key;
|
|
151
|
+
}
|
|
37
152
|
useEffect(() => {
|
|
38
153
|
const timer = setTimeout(() => setQuery(search.trim()), 300);
|
|
39
154
|
return () => clearTimeout(timer);
|
|
@@ -52,28 +167,53 @@ export function OrganizationDirectorySearch({
|
|
|
52
167
|
retry: false,
|
|
53
168
|
});
|
|
54
169
|
const claim = useMutation({
|
|
55
|
-
|
|
56
|
-
|
|
170
|
+
// A lost response does not prove this non-idempotent claim was not sent.
|
|
171
|
+
retry: false,
|
|
172
|
+
mutationFn: (key: object) => {
|
|
173
|
+
const operation = operations.current.get(key);
|
|
174
|
+
if (!operation || !currentOwner(operation) || !operation.accountId || !operation.evidence)
|
|
57
175
|
throw new Error('An active organization and personal session are required');
|
|
58
176
|
return oxyServices.organizations.claim(
|
|
59
|
-
|
|
60
|
-
parseContract(organizationClaimInputCheck, { evidenceReference: evidence }),
|
|
177
|
+
operation.accountId,
|
|
178
|
+
parseContract(organizationClaimInputCheck, { evidenceReference: operation.evidence }),
|
|
61
179
|
);
|
|
62
180
|
},
|
|
63
|
-
onSuccess: () =>
|
|
181
|
+
onSuccess: (_result, key) => {
|
|
182
|
+
const operation = operations.current.get(key);
|
|
183
|
+
if (operation && currentOwner(operation))
|
|
184
|
+
return queryClient.invalidateQueries({ queryKey: ['oxy', 'organizations'] });
|
|
185
|
+
},
|
|
186
|
+
onSettled: (_result, _error, key) => {
|
|
187
|
+
operations.current.delete(key);
|
|
188
|
+
if (pending.current.claim === key) pending.current.claim = null;
|
|
189
|
+
},
|
|
64
190
|
});
|
|
65
191
|
const create = useMutation({
|
|
66
|
-
|
|
67
|
-
|
|
192
|
+
// The directory creation endpoint does not carry an idempotency key.
|
|
193
|
+
retry: false,
|
|
194
|
+
mutationFn: (key: object) => {
|
|
195
|
+
const operation = operations.current.get(key);
|
|
196
|
+
if (!operation || !currentOwner(operation)) throw new Error('A personal session is required');
|
|
68
197
|
return oxyServices.organizations.create(
|
|
69
|
-
parseContract(createOrganizationCheck, {
|
|
198
|
+
parseContract(createOrganizationCheck, {
|
|
199
|
+
name: operation.name,
|
|
200
|
+
organizationType: operation.type,
|
|
201
|
+
}),
|
|
70
202
|
);
|
|
71
203
|
},
|
|
72
|
-
onSuccess: (organization) => {
|
|
73
|
-
|
|
74
|
-
|
|
204
|
+
onSuccess: (organization, key) => {
|
|
205
|
+
const operation = operations.current.get(key);
|
|
206
|
+
if (!operation || !currentOwner(operation)) return;
|
|
207
|
+
if (lifecycle.current.active) {
|
|
208
|
+
setSelected(organization);
|
|
209
|
+
setAdding(false);
|
|
210
|
+
}
|
|
75
211
|
void queryClient.invalidateQueries({ queryKey: ['oxy', 'organizations'] });
|
|
76
212
|
},
|
|
213
|
+
onSettled: (_result, _error, key) => {
|
|
214
|
+
operations.current.delete(key);
|
|
215
|
+
if (pending.current.create === key) pending.current.create = null;
|
|
216
|
+
},
|
|
77
217
|
});
|
|
78
218
|
const reset = () => {
|
|
79
219
|
setSelected(null);
|
|
@@ -107,7 +247,21 @@ export function OrganizationDirectorySearch({
|
|
|
107
247
|
<Text accessibilityRole="alert">{t('organizationDirectory.claimSent')}</Text>
|
|
108
248
|
) : (
|
|
109
249
|
<Button
|
|
110
|
-
onPress={() =>
|
|
250
|
+
onPress={() => {
|
|
251
|
+
if (pending.current.claim) return;
|
|
252
|
+
const key =
|
|
253
|
+
selected.status === 'active'
|
|
254
|
+
? capture({ accountId: selected.accountId, evidence })
|
|
255
|
+
: {};
|
|
256
|
+
pending.current.claim = key;
|
|
257
|
+
try {
|
|
258
|
+
claim.mutate(key);
|
|
259
|
+
} catch (error) {
|
|
260
|
+
pending.current.claim = null;
|
|
261
|
+
operations.current.delete(key);
|
|
262
|
+
throw error;
|
|
263
|
+
}
|
|
264
|
+
}}
|
|
111
265
|
disabled={
|
|
112
266
|
!personalReady ||
|
|
113
267
|
selected.status !== 'active' ||
|
|
@@ -184,7 +338,16 @@ export function OrganizationDirectorySearch({
|
|
|
184
338
|
{results.isSuccess && query === search.trim() ? (
|
|
185
339
|
<>
|
|
186
340
|
<Text>{t('organizationDirectory.newAccountHint')}</Text>
|
|
187
|
-
<Button
|
|
341
|
+
<Button
|
|
342
|
+
onPress={() => {
|
|
343
|
+
if (
|
|
344
|
+
lifecycle.current.active &&
|
|
345
|
+
runtime.getAccountSessionRevision() === revision &&
|
|
346
|
+
oxyServices.http.getSessionEpoch() === bearerEpoch
|
|
347
|
+
)
|
|
348
|
+
onCreateAccount(search.trim(), type);
|
|
349
|
+
}}
|
|
350
|
+
>
|
|
188
351
|
{t('organizationDirectory.newAccount')}
|
|
189
352
|
</Button>
|
|
190
353
|
{personalReady && !adding ? (
|
|
@@ -219,7 +382,16 @@ export function OrganizationDirectorySearch({
|
|
|
219
382
|
setValidationError(true);
|
|
220
383
|
return;
|
|
221
384
|
}
|
|
222
|
-
create
|
|
385
|
+
if (pending.current.create) return;
|
|
386
|
+
const key = capture({ name: search.trim(), type });
|
|
387
|
+
pending.current.create = key;
|
|
388
|
+
try {
|
|
389
|
+
create.mutate(key);
|
|
390
|
+
} catch (error) {
|
|
391
|
+
pending.current.create = null;
|
|
392
|
+
operations.current.delete(key);
|
|
393
|
+
throw error;
|
|
394
|
+
}
|
|
223
395
|
}}
|
|
224
396
|
>
|
|
225
397
|
{t('organizationDirectory.addDirectory')}
|
|
@@ -52,6 +52,8 @@ export interface AccountDialogControls {
|
|
|
52
52
|
*/
|
|
53
53
|
export interface AccountDialogConsumerHooks {
|
|
54
54
|
onAddAccount?: () => void;
|
|
55
|
+
/** Called synchronously before the shared add-account view; ignored when onAddAccount overrides it. */
|
|
56
|
+
onBeforeAddAccount?: () => void;
|
|
55
57
|
onNavigateProfile?: () => void;
|
|
56
58
|
menuItems?: readonly AccountDialogMenuItem[];
|
|
57
59
|
menuSections?: readonly AccountDialogMenuSection[];
|
|
@@ -167,6 +167,7 @@ const CreateAccountScreen: React.FC<BaseScreenProps> = ({
|
|
|
167
167
|
if (debounceTimerRef.current) {
|
|
168
168
|
clearTimeout(debounceTimerRef.current);
|
|
169
169
|
}
|
|
170
|
+
const seq = ++usernameCheckSeqRef.current;
|
|
170
171
|
|
|
171
172
|
if (!value || value.length < USERNAME_MIN_LENGTH) {
|
|
172
173
|
setUsernameStatus(value.length > 0 ? 'invalid' : 'idle');
|
|
@@ -203,7 +204,6 @@ const CreateAccountScreen: React.FC<BaseScreenProps> = ({
|
|
|
203
204
|
setUsernameStatus('checking');
|
|
204
205
|
setUsernameMessage('');
|
|
205
206
|
|
|
206
|
-
const seq = ++usernameCheckSeqRef.current;
|
|
207
207
|
debounceTimerRef.current = setTimeout(async () => {
|
|
208
208
|
try {
|
|
209
209
|
const result = await oxyServices.auth.checkUsername(value);
|