@datalayer/core 0.0.14 → 0.0.16
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/components/checkout/StripeCheckout.js +19 -23
- package/lib/components/context/OrganizationSelect.js +12 -15
- package/lib/components/context/SpaceSelect.js +24 -25
- package/lib/hooks/useAuthorization.js +4 -2
- package/lib/hooks/useCache.d.ts +932 -285
- package/lib/hooks/useCache.js +5735 -2761
- package/lib/hooks/useCache0.d.ts +312 -0
- package/lib/hooks/useCache0.js +3189 -0
- package/lib/hooks/useIAM.js +18 -17
- package/lib/models/Runtime.d.ts +49 -49
- package/package.json +1 -1
- package/lib/sdk/index.d.ts +0 -27
- package/lib/sdk/index.js +0 -33
|
@@ -7,34 +7,26 @@ import { createElement, useCallback, useEffect, useState } from 'react';
|
|
|
7
7
|
import { Button, Flash, FormControl, Spinner, Text } from '@primer/react';
|
|
8
8
|
import { Box } from '@datalayer/primer-addons';
|
|
9
9
|
import { useCache } from '../../hooks';
|
|
10
|
-
import { useIAMStore } from '../../state';
|
|
11
10
|
/**
|
|
12
11
|
* Stripe checkout.
|
|
13
12
|
*/
|
|
14
13
|
export function StripeCheckout({ checkoutPortal, }) {
|
|
15
|
-
const {
|
|
16
|
-
const { createCheckoutSession, refreshStripePrices } = useCache();
|
|
14
|
+
const { useCreateCheckoutSession, useStripePrices } = useCache();
|
|
17
15
|
const [stripe, setStripe] = useState(null);
|
|
18
16
|
const [components, setComponents] = useState(null);
|
|
19
17
|
const [items, setItems] = useState(null);
|
|
20
18
|
const [product, setProduct] = useState(null);
|
|
21
19
|
const [checkout, setCheckout] = useState(false);
|
|
22
|
-
//
|
|
20
|
+
// Get Stripe prices using TanStack Query hook
|
|
21
|
+
const { data: pricesData } = useStripePrices();
|
|
22
|
+
// Update items when prices data changes
|
|
23
23
|
useEffect(() => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
setItems([]);
|
|
31
|
-
}
|
|
32
|
-
})
|
|
33
|
-
.catch(error => {
|
|
34
|
-
console.error('Failed to fetch product items.', error);
|
|
35
|
-
setItems([]);
|
|
36
|
-
});
|
|
37
|
-
}, []);
|
|
24
|
+
if (pricesData) {
|
|
25
|
+
setItems(pricesData);
|
|
26
|
+
}
|
|
27
|
+
}, [pricesData]);
|
|
28
|
+
// Get checkout session mutation
|
|
29
|
+
const checkoutSessionMutation = useCreateCheckoutSession();
|
|
38
30
|
// Load stripe components.
|
|
39
31
|
useEffect(() => {
|
|
40
32
|
import('@stripe/react-stripe-js').then(module => {
|
|
@@ -45,15 +37,19 @@ export function StripeCheckout({ checkoutPortal, }) {
|
|
|
45
37
|
useEffect(() => {
|
|
46
38
|
if (checkoutPortal?.metadata?.stripe_key) {
|
|
47
39
|
import('@stripe/stripe-js').then(module => {
|
|
48
|
-
setStripe(module.loadStripe(checkoutPortal.metadata
|
|
40
|
+
setStripe(module.loadStripe(checkoutPortal.metadata?.stripe_key ?? ''));
|
|
49
41
|
});
|
|
50
42
|
}
|
|
51
43
|
}, [checkoutPortal?.metadata?.stripe_key]);
|
|
52
|
-
const fetchClientSecret = useCallback(() => {
|
|
44
|
+
const fetchClientSecret = useCallback(async () => {
|
|
53
45
|
const location = document.location;
|
|
54
|
-
// Create a Checkout Session
|
|
55
|
-
|
|
56
|
-
|
|
46
|
+
// Create a Checkout Session using TanStack Query mutation
|
|
47
|
+
const result = await checkoutSessionMutation.mutateAsync({
|
|
48
|
+
product,
|
|
49
|
+
location,
|
|
50
|
+
});
|
|
51
|
+
return result;
|
|
52
|
+
}, [checkoutSessionMutation, product]);
|
|
57
53
|
const options = { fetchClientSecret };
|
|
58
54
|
let view = (_jsx(Box, { sx: { minHeight: '40px' }, children: _jsx(Spinner, {}) }));
|
|
59
55
|
if (checkout) {
|
|
@@ -3,7 +3,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
3
3
|
* Copyright (c) 2023-2025 Datalayer, Inc.
|
|
4
4
|
* Distributed under the terms of the Modified BSD License.
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
6
|
+
import { useCallback, useEffect } from 'react';
|
|
7
7
|
import { Select } from '@primer/react';
|
|
8
8
|
import { useCache, useUser } from './../../hooks';
|
|
9
9
|
import { useLayoutStore } from '../../state';
|
|
@@ -11,25 +11,22 @@ const NO_ORGANIZATION_SELECTED_VALUE = 'NO_ORGANIZATION_SELECTED_VALUE';
|
|
|
11
11
|
export const OrganizationSelect = () => {
|
|
12
12
|
const user = useUser();
|
|
13
13
|
const { organization, updateLayoutOrganization, updateLayoutSpace } = useLayoutStore();
|
|
14
|
-
const {
|
|
15
|
-
const
|
|
16
|
-
const [
|
|
14
|
+
const { useRefreshUserOrganizations, useUserOrganizations } = useCache();
|
|
15
|
+
const { mutate: refreshUserOrganizationsMutate } = useRefreshUserOrganizations();
|
|
16
|
+
const { data: organizations = [] } = useUserOrganizations();
|
|
17
17
|
useEffect(() => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const onSelectionChange = useCallback((e) => {
|
|
25
|
-
const selectedOrganization = e.target.value;
|
|
18
|
+
if (user) {
|
|
19
|
+
refreshUserOrganizationsMutate();
|
|
20
|
+
}
|
|
21
|
+
}, [user, refreshUserOrganizationsMutate]);
|
|
22
|
+
const onSelectionChange = useCallback((event) => {
|
|
23
|
+
const selectedOrganization = event.target.value;
|
|
26
24
|
const org = selectedOrganization === NO_ORGANIZATION_SELECTED_VALUE
|
|
27
25
|
? undefined
|
|
28
26
|
: organizations[parseInt(selectedOrganization, 10)];
|
|
29
|
-
setSelection(org);
|
|
30
27
|
updateLayoutOrganization(org);
|
|
31
28
|
updateLayoutSpace(undefined);
|
|
32
|
-
}, [
|
|
33
|
-
return (_jsx(_Fragment, { children: _jsxs(Select, { block: true, width: "medium", onChange: onSelectionChange, children: [_jsx(Select.Option, { value: NO_ORGANIZATION_SELECTED_VALUE, selected: organization === undefined, children: "Please select an organization..." }), organizations.map((org, index) => (_jsx(Select.Option, { value: `${index}`, selected: org.id === organization?.id, children: org.name })))] }) }));
|
|
29
|
+
}, [organizations, updateLayoutOrganization, updateLayoutSpace]);
|
|
30
|
+
return (_jsx(_Fragment, { children: _jsxs(Select, { block: true, width: "medium", onChange: onSelectionChange, children: [_jsx(Select.Option, { value: NO_ORGANIZATION_SELECTED_VALUE, selected: organization === undefined, children: "Please select an organization..." }), organizations.map((org, index) => (_jsx(Select.Option, { value: `${index}`, selected: org.id === organization?.id, children: org.name }, org.id)))] }) }));
|
|
34
31
|
};
|
|
35
32
|
export default OrganizationSelect;
|
|
@@ -3,7 +3,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
3
3
|
* Copyright (c) 2023-2025 Datalayer, Inc.
|
|
4
4
|
* Distributed under the terms of the Modified BSD License.
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
6
|
+
import { useCallback, useEffect } from 'react';
|
|
7
7
|
import { FormControl, Select } from '@primer/react';
|
|
8
8
|
import { Box } from '@datalayer/primer-addons';
|
|
9
9
|
import { useCache, useUser } from './../../hooks';
|
|
@@ -11,33 +11,32 @@ import { useLayoutStore } from '../../state';
|
|
|
11
11
|
export const SpaceSelect = () => {
|
|
12
12
|
const user = useUser();
|
|
13
13
|
const { organization, space, updateLayoutSpace } = useLayoutStore();
|
|
14
|
-
const {
|
|
15
|
-
const
|
|
16
|
-
const
|
|
14
|
+
const { useRefreshUserSpaces, useUserSpaces, useRefreshOrganizationSpaces, useOrganizationSpaces, } = useCache();
|
|
15
|
+
const { mutate: refreshUserSpacesMutate } = useRefreshUserSpaces();
|
|
16
|
+
const { mutate: refreshOrganizationSpacesMutate } = useRefreshOrganizationSpaces();
|
|
17
|
+
const { data: organizationSpaces = [] } = useOrganizationSpaces(organization?.id ?? '');
|
|
18
|
+
const { data: userSpaces = [] } = useUserSpaces();
|
|
19
|
+
const spaces = organization ? organizationSpaces : userSpaces;
|
|
17
20
|
useEffect(() => {
|
|
18
|
-
if (organization) {
|
|
19
|
-
|
|
20
|
-
if (resp.success) {
|
|
21
|
-
setSpaces(getOrganizationSpaces(organization.id));
|
|
22
|
-
}
|
|
23
|
-
});
|
|
21
|
+
if (organization?.id) {
|
|
22
|
+
refreshOrganizationSpacesMutate(organization.id);
|
|
24
23
|
}
|
|
25
|
-
else {
|
|
26
|
-
|
|
27
|
-
if (resp.success) {
|
|
28
|
-
setSpaces(getUserSpaces());
|
|
29
|
-
}
|
|
30
|
-
});
|
|
24
|
+
else if (user) {
|
|
25
|
+
refreshUserSpacesMutate();
|
|
31
26
|
}
|
|
32
|
-
}, [
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
27
|
+
}, [
|
|
28
|
+
organization?.id,
|
|
29
|
+
refreshOrganizationSpacesMutate,
|
|
30
|
+
refreshUserSpacesMutate,
|
|
31
|
+
user,
|
|
32
|
+
]);
|
|
33
|
+
const onSelectionChange = useCallback((event) => {
|
|
34
|
+
const selectedSpaceIndex = Number.parseInt(event.target.value, 10);
|
|
35
|
+
const selectedSpace = Number.isNaN(selectedSpaceIndex) || selectedSpaceIndex < 0
|
|
36
36
|
? undefined
|
|
37
|
-
: spaces[
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
return (_jsx(_Fragment, { children: _jsx(Box, { as: "form", children: _jsxs(FormControl, { children: [_jsx(FormControl.Label, { children: "Select a space" }), _jsx(FormControl.Caption, { children: "This will go with you while you navigate" }), _jsx(Select, { block: true, width: "medium", onChange: onSelectionChange, placeholder: "Please select an space...", children: spaces.map((sp, index) => (_jsx(Select.Option, { value: `${index}`, selected: sp.id === space?.id, children: sp.name }))) })] }) }) }));
|
|
37
|
+
: spaces[selectedSpaceIndex];
|
|
38
|
+
updateLayoutSpace(selectedSpace);
|
|
39
|
+
}, [spaces, updateLayoutSpace]);
|
|
40
|
+
return (_jsx(_Fragment, { children: _jsx(Box, { as: "form", children: _jsxs(FormControl, { children: [_jsx(FormControl.Label, { children: "Select a space" }), _jsx(FormControl.Caption, { children: "This will go with you while you navigate" }), _jsx(Select, { block: true, width: "medium", onChange: onSelectionChange, placeholder: "Please select an space...", children: spaces.map((sp, index) => (_jsx(Select.Option, { value: `${index}`, selected: sp.id === space?.id, children: sp.name }, sp.id))) })] }) }) }));
|
|
42
41
|
};
|
|
43
42
|
export default SpaceSelect;
|
|
@@ -16,8 +16,10 @@ export const useAuthorization = () => {
|
|
|
16
16
|
};
|
|
17
17
|
// Account -------------------------------------------------------------------
|
|
18
18
|
const checkUserAccountPermissions = (user, accountHandle) => {
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
// Note: user object from API has handle_s property, not handle
|
|
20
|
+
const userHandle = user.handle_s || user.handle;
|
|
21
|
+
if (userHandle !== accountHandle) {
|
|
22
|
+
goToApplicationStateError(`Permissions check failed for account handle: ${accountHandle} and user handle: ${userHandle}`);
|
|
21
23
|
}
|
|
22
24
|
};
|
|
23
25
|
// Platform -------------------------------------------------------------------
|