Skip to content

Commit a37e205

Browse files
Merge branch 'main' into feat/progress-hosting
2 parents cc57e6e + 0f33fcc commit a37e205

File tree

8 files changed

+65
-54
lines changed

8 files changed

+65
-54
lines changed

src/frontend/src/lib/components/auth/AuthConfig.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
import type { AuthenticationConfig, Rule } from '$declarations/satellite/satellite.did';
66
import SkeletonText from '$lib/components/ui/SkeletonText.svelte';
77
import Value from '$lib/components/ui/Value.svelte';
8+
import { getAuthConfig } from '$lib/services/auth.config.services';
89
import { getRuleUser } from '$lib/services/collection.services';
9-
import { getAuthConfig, listCustomDomains } from '$lib/services/hosting.services';
10+
import { listCustomDomains } from '$lib/services/custom-domain.services';
1011
import { authStore } from '$lib/stores/auth.store';
1112
import { busy } from '$lib/stores/busy.store';
1213
import { i18n } from '$lib/stores/i18n.store';

src/frontend/src/lib/components/hosting/CustomDomainActions.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import Checkbox from '$lib/components/ui/Checkbox.svelte';
1313
import Html from '$lib/components/ui/Html.svelte';
1414
import Popover from '$lib/components/ui/Popover.svelte';
15-
import { deleteCustomDomain as deleteCustomDomainService } from '$lib/services/hosting.services';
15+
import { deleteCustomDomain as deleteCustomDomainService } from '$lib/services/custom-domain.services';
1616
import { authStore } from '$lib/stores/auth.store';
1717
import { busy, isBusy } from '$lib/stores/busy.store';
1818
import { i18n } from '$lib/stores/i18n.store';

src/frontend/src/lib/components/hosting/Hosting.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
import CustomDomainInfo from '$lib/components/hosting/CustomDomainInfo.svelte';
1212
import HostingCount from '$lib/components/hosting/HostingCount.svelte';
1313
import { sortedSatelliteCustomDomains } from '$lib/derived/satellite-custom-domains.derived';
14-
import { listCustomDomains, getAuthConfig } from '$lib/services/hosting.services';
14+
import { getAuthConfig } from '$lib/services/auth.config.services';
15+
import { listCustomDomains } from '$lib/services/custom-domain.services';
1516
import { authStore } from '$lib/stores/auth.store';
1617
import { i18n } from '$lib/stores/i18n.store';
1718
import type { CustomDomainRegistrationState } from '$lib/types/custom-domain';

src/frontend/src/lib/components/modals/CustomDomainModal.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import IconVerified from '$lib/components/icons/IconVerified.svelte';
1010
import Modal from '$lib/components/ui/Modal.svelte';
1111
import SpinnerModal from '$lib/components/ui/SpinnerModal.svelte';
12-
import { setCustomDomain } from '$lib/services/hosting.services';
12+
import { setCustomDomain } from '$lib/services/custom-domain.services';
1313
import { authStore } from '$lib/stores/auth.store';
1414
import { wizardBusy } from '$lib/stores/busy.store';
1515
import { i18n } from '$lib/stores/i18n.store';

src/frontend/src/lib/components/satellites/SatelliteActions.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import SegmentDetach from '$lib/components/canister/SegmentDetach.svelte';
1010
import TopUp from '$lib/components/canister/TopUp.svelte';
1111
import SegmentActions from '$lib/components/segments/SegmentActions.svelte';
12-
import { listCustomDomains } from '$lib/services/hosting.services';
12+
import { listCustomDomains } from '$lib/services/custom-domain.services';
1313
import { busy } from '$lib/stores/busy.store';
1414
import { i18n } from '$lib/stores/i18n.store';
1515
import { toasts } from '$lib/stores/toasts.store';

src/frontend/src/lib/components/satellites/SatelliteOverviewCustomDomain.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
satelliteCustomDomain,
99
satelliteCustomDomainsLoaded
1010
} from '$lib/derived/satellite-custom-domains.derived';
11-
import { listCustomDomains } from '$lib/services/hosting.services';
11+
import { listCustomDomains } from '$lib/services/custom-domain.services';
1212
import { i18n } from '$lib/stores/i18n.store';
1313
import { satelliteUrl } from '$lib/utils/satellite.utils';
1414

src/frontend/src/lib/services/auth.config.services.ts

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import type { Satellite } from '$declarations/mission_control/mission_control.did';
22
import type { AuthenticationConfig, Rule } from '$declarations/satellite/satellite.did';
3-
import { setAuthConfig, setRule } from '$lib/api/satellites.api';
3+
import {
4+
getAuthConfig as getAuthConfigApi,
5+
satelliteVersion,
6+
setAuthConfig,
7+
setRule
8+
} from '$lib/api/satellites.api';
49
import { DEFAULT_RATE_CONFIG_TIME_PER_TOKEN_NS } from '$lib/constants/data.constants';
10+
import { SATELLITE_v0_0_17 } from '$lib/constants/version.constants';
511
import { i18n } from '$lib/stores/i18n.store';
612
import { toasts } from '$lib/stores/toasts.store';
713
import type { OptionIdentity } from '$lib/types/itentity';
@@ -10,7 +16,15 @@ import {
1016
buildDeleteAuthenticationConfig,
1117
buildSetAuthenticationConfig
1218
} from '$lib/utils/auth.config.utils';
13-
import { fromNullishNullable, isNullish, nonNullish, toNullable } from '@dfinity/utils';
19+
import type { Principal } from '@dfinity/principal';
20+
import {
21+
fromNullable,
22+
fromNullishNullable,
23+
isNullish,
24+
nonNullish,
25+
toNullable
26+
} from '@dfinity/utils';
27+
import { compare } from 'semver';
1428
import { get } from 'svelte/store';
1529

1630
interface UpdateAuthConfigParams {
@@ -161,3 +175,43 @@ const updateRule = async ({
161175

162176
return { result: 'success' };
163177
};
178+
179+
export const getAuthConfig = async ({
180+
satelliteId,
181+
identity
182+
}: {
183+
satelliteId: Principal;
184+
identity: OptionIdentity;
185+
}): Promise<{
186+
result: 'success' | 'error' | 'skip';
187+
config?: AuthenticationConfig | undefined;
188+
}> => {
189+
try {
190+
// TODO: load versions globally and use store value instead of fetching version again
191+
const version = await satelliteVersion({ satelliteId, identity });
192+
193+
// TODO: keep a list of those version checks and remove them incrementally
194+
// Also would be cleaner than to have 0.0.17 hardcoded there and there...
195+
const authConfigSupported = compare(version, SATELLITE_v0_0_17) >= 0;
196+
197+
if (!authConfigSupported) {
198+
return { result: 'skip' };
199+
}
200+
201+
const config = await getAuthConfigApi({
202+
satelliteId,
203+
identity
204+
});
205+
206+
return { result: 'success', config: fromNullable(config) };
207+
} catch (err: unknown) {
208+
const labels = get(i18n);
209+
210+
toasts.error({
211+
text: labels.errors.authentication_config_loading,
212+
detail: err
213+
});
214+
215+
return { result: 'error' };
216+
}
217+
};

src/frontend/src/lib/services/hosting.services.ts renamed to src/frontend/src/lib/services/custom-domain.services.ts

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
1-
import type { AuthenticationConfig, CustomDomain } from '$declarations/satellite/satellite.did';
1+
import type { CustomDomain } from '$declarations/satellite/satellite.did';
22
import {
33
deleteCustomDomain as deleteCustomDomainApi,
4-
getAuthConfig as getAuthConfigApi,
54
listCustomDomains as listCustomDomainsApi,
6-
satelliteVersion,
75
setCustomDomain as setCustomDomainApi
86
} from '$lib/api/satellites.api';
9-
import { SATELLITE_v0_0_17 } from '$lib/constants/version.constants';
107
import { deleteDomain, registerDomain } from '$lib/rest/bn.rest';
118
import { authStore } from '$lib/stores/auth.store';
129
import { customDomainsStore } from '$lib/stores/custom-domains.store';
1310
import { i18n } from '$lib/stores/i18n.store';
1411
import { toasts } from '$lib/stores/toasts.store';
15-
import type { OptionIdentity } from '$lib/types/itentity';
1612
import type { Principal } from '@dfinity/principal';
1713
import { fromNullable, nonNullish } from '@dfinity/utils';
18-
import { compare } from 'semver';
1914
import { get } from 'svelte/store';
2015

2116
/**
@@ -110,43 +105,3 @@ export const listCustomDomains = async ({
110105
return { success: false };
111106
}
112107
};
113-
114-
export const getAuthConfig = async ({
115-
satelliteId,
116-
identity
117-
}: {
118-
satelliteId: Principal;
119-
identity: OptionIdentity;
120-
}): Promise<{
121-
result: 'success' | 'error' | 'skip';
122-
config?: AuthenticationConfig | undefined;
123-
}> => {
124-
try {
125-
// TODO: load versions globally and use store value instead of fetching version again
126-
const version = await satelliteVersion({ satelliteId, identity });
127-
128-
// TODO: keep a list of those version checks and remove them incrementally
129-
// Also would be cleaner than to have 0.0.17 hardcoded there and there...
130-
const authConfigSupported = compare(version, SATELLITE_v0_0_17) >= 0;
131-
132-
if (!authConfigSupported) {
133-
return { result: 'skip' };
134-
}
135-
136-
const config = await getAuthConfigApi({
137-
satelliteId,
138-
identity
139-
});
140-
141-
return { result: 'success', config: fromNullable(config) };
142-
} catch (err: unknown) {
143-
const labels = get(i18n);
144-
145-
toasts.error({
146-
text: labels.errors.authentication_config_loading,
147-
detail: err
148-
});
149-
150-
return { result: 'error' };
151-
}
152-
};

0 commit comments

Comments
 (0)