@selfhelp/shared 1.2.5 → 1.3.1
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/CHANGELOG.md +341 -326
- package/LICENSE +381 -381
- package/README.md +57 -57
- package/dist/index.d.mts +25 -1
- package/dist/index.d.ts +25 -1
- package/dist/index.js +2 -0
- package/dist/index.mjs +2 -0
- package/package.json +102 -102
- package/src/api/__tests__/endpoints.test.ts +45 -0
- package/src/api/endpoints.ts +2 -0
- package/src/api/index.ts +5 -5
- package/src/assets/__tests__/resolveAssetUrl.test.ts +61 -61
- package/src/assets/index.ts +5 -5
- package/src/assets/resolveAssetUrl.ts +44 -44
- package/src/cms-classes/__tests__/classify.test.ts +63 -63
- package/src/cms-classes/allow-list.ts +158 -158
- package/src/cms-classes/classify.ts +90 -90
- package/src/cms-classes/index.ts +7 -7
- package/src/cms-classes/remap.ts +44 -44
- package/src/condition/__tests__/evaluate.test.ts +54 -54
- package/src/condition/evaluate.ts +121 -121
- package/src/condition/index.ts +5 -5
- package/src/index.ts +25 -25
- package/src/interpolation/__tests__/replaceCalcedValues.test.ts +41 -41
- package/src/interpolation/index.ts +5 -5
- package/src/interpolation/replaceCalcedValues.ts +27 -27
- package/src/plugin-sdk/define.ts +89 -89
- package/src/plugin-sdk/index.ts +103 -103
- package/src/plugin-sdk/lock.ts +124 -124
- package/src/plugin-sdk/manifest.ts +307 -307
- package/src/plugin-sdk/realtime.ts +277 -277
- package/src/plugin-sdk/registry.ts +105 -105
- package/src/plugin-sdk/runtime-shim.ts +140 -140
- package/src/plugin-sdk/types.ts +315 -315
- package/src/plugin-sdk/version.ts +209 -209
- package/src/registry/__tests__/registry.test.ts +135 -135
- package/src/registry/index.ts +94 -94
- package/src/registry/styles.registry.ts +295 -295
- package/src/testing/__tests__/testing-kit.test.ts +228 -228
- package/src/testing/index.ts +483 -483
- package/src/theme/index.ts +6 -6
- package/src/theme/tailwind.ts +73 -73
- package/src/theme/tokens.ts +177 -177
- package/src/types/api/auth.ts +22 -0
- package/src/types/api/envelope.ts +34 -34
- package/src/types/api/forms.ts +76 -76
- package/src/types/api/index.ts +9 -9
- package/src/types/api/language.ts +12 -12
- package/src/types/api/page.ts +9 -9
- package/src/types/index.ts +17 -17
- package/src/types/mantine/common.ts +142 -142
- package/src/types/pages.ts +107 -107
- package/src/types/styles/auth.ts +184 -184
- package/src/types/styles/base.ts +72 -72
- package/src/types/styles/composite.ts +131 -131
- package/src/types/styles/forms.ts +439 -439
- package/src/types/styles/interactive.ts +165 -165
- package/src/types/styles/layout.ts +184 -184
- package/src/types/styles/media.ts +68 -68
- package/src/types/styles/typography.ts +118 -118
- package/src/types/styles/unknown.ts +220 -220
- package/src/utils/__tests__/transformPageData.test.ts +69 -69
- package/src/utils/spacing.ts +64 -64
- package/src/utils/transformPageData.ts +99 -99
package/README.md
CHANGED
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
<!--
|
|
2
|
-
SPDX-FileCopyrightText: 2026 Humdek, University of Bern
|
|
3
|
-
SPDX-License-Identifier: MPL-2.0
|
|
4
|
-
-->
|
|
5
|
-
|
|
6
|
-
# @selfhelp/shared
|
|
7
|
-
|
|
8
|
-
The shared TypeScript foundation for the SelfHelp ecosystem. It is the single source of truth that keeps the web frontend (`sh-selfhelp_frontend`) and mobile app (`sh-selfhelp_mobile`) aligned on:
|
|
9
|
-
|
|
10
|
-
- CMS page and style types
|
|
11
|
-
- API request/response contracts
|
|
12
|
-
- shared theme tokens and a Tailwind preset
|
|
13
|
-
- condition and interpolation helpers that mirror backend behavior
|
|
14
|
-
- CMS class allow-listing and asset URL utilities
|
|
15
|
-
|
|
16
|
-
## Install
|
|
17
|
-
|
|
18
|
-
```bash
|
|
19
|
-
npm install @selfhelp/shared
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
For local development against sibling repositories you can use a file dependency:
|
|
23
|
-
|
|
24
|
-
```json
|
|
25
|
-
{ "dependencies": { "@selfhelp/shared": "file:../sh-selfhelp_shared" } }
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
## Quick usage
|
|
29
|
-
|
|
30
|
-
```ts
|
|
31
|
-
import { ENDPOINTS, replaceCalcedValues, resolveAssetUrl } from '@selfhelp/shared';
|
|
32
|
-
import type { IPageContent, IUserDataResponse } from '@selfhelp/shared';
|
|
33
|
-
|
|
34
|
-
import { STYLE_REGISTRY } from '@selfhelp/shared/registry';
|
|
35
|
-
import { THEME_TOKENS } from '@selfhelp/shared/theme';
|
|
36
|
-
import tailwindPreset from '@selfhelp/shared/tailwind';
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
The package exposes a root export plus the `registry`, `theme`, `tailwind`, `plugin-sdk`, and `testing` subpaths.
|
|
40
|
-
|
|
41
|
-
## Build
|
|
42
|
-
|
|
43
|
-
```bash
|
|
44
|
-
npm install
|
|
45
|
-
npm run build
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
## Documentation
|
|
49
|
-
|
|
50
|
-
Full documentation lives in [docs/](docs/README.md):
|
|
51
|
-
|
|
52
|
-
- Public exports, types, and contracts: [docs/reference/exports.md](docs/reference/exports.md)
|
|
53
|
-
- Release and versioning: [docs/developer/release-and-versioning.md](docs/developer/release-and-versioning.md)
|
|
54
|
-
- Testing and the coverage gate: [docs/developer/testing.md](docs/developer/testing.md)
|
|
55
|
-
- Extending the package: [docs/developer/extending.md](docs/developer/extending.md)
|
|
56
|
-
|
|
57
|
-
Release notes are in [CHANGELOG.md](CHANGELOG.md). Licensed under [MPL-2.0](LICENSE).
|
|
1
|
+
<!--
|
|
2
|
+
SPDX-FileCopyrightText: 2026 Humdek, University of Bern
|
|
3
|
+
SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
-->
|
|
5
|
+
|
|
6
|
+
# @selfhelp/shared
|
|
7
|
+
|
|
8
|
+
The shared TypeScript foundation for the SelfHelp ecosystem. It is the single source of truth that keeps the web frontend (`sh-selfhelp_frontend`) and mobile app (`sh-selfhelp_mobile`) aligned on:
|
|
9
|
+
|
|
10
|
+
- CMS page and style types
|
|
11
|
+
- API request/response contracts
|
|
12
|
+
- shared theme tokens and a Tailwind preset
|
|
13
|
+
- condition and interpolation helpers that mirror backend behavior
|
|
14
|
+
- CMS class allow-listing and asset URL utilities
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install @selfhelp/shared
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
For local development against sibling repositories you can use a file dependency:
|
|
23
|
+
|
|
24
|
+
```json
|
|
25
|
+
{ "dependencies": { "@selfhelp/shared": "file:../sh-selfhelp_shared" } }
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Quick usage
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import { ENDPOINTS, replaceCalcedValues, resolveAssetUrl } from '@selfhelp/shared';
|
|
32
|
+
import type { IPageContent, IUserDataResponse } from '@selfhelp/shared';
|
|
33
|
+
|
|
34
|
+
import { STYLE_REGISTRY } from '@selfhelp/shared/registry';
|
|
35
|
+
import { THEME_TOKENS } from '@selfhelp/shared/theme';
|
|
36
|
+
import tailwindPreset from '@selfhelp/shared/tailwind';
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
The package exposes a root export plus the `registry`, `theme`, `tailwind`, `plugin-sdk`, and `testing` subpaths.
|
|
40
|
+
|
|
41
|
+
## Build
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
npm install
|
|
45
|
+
npm run build
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Documentation
|
|
49
|
+
|
|
50
|
+
Full documentation lives in [docs/](docs/README.md):
|
|
51
|
+
|
|
52
|
+
- Public exports, types, and contracts: [docs/reference/exports.md](docs/reference/exports.md)
|
|
53
|
+
- Release and versioning: [docs/developer/release-and-versioning.md](docs/developer/release-and-versioning.md)
|
|
54
|
+
- Testing and the coverage gate: [docs/developer/testing.md](docs/developer/testing.md)
|
|
55
|
+
- Extending the package: [docs/developer/extending.md](docs/developer/extending.md)
|
|
56
|
+
|
|
57
|
+
Release notes are in [CHANGELOG.md](CHANGELOG.md). Licensed under [MPL-2.0](LICENSE).
|
package/dist/index.d.mts
CHANGED
|
@@ -244,6 +244,16 @@ interface ITwoFactorVerifyRequest {
|
|
|
244
244
|
interface IRefreshRequest {
|
|
245
245
|
refresh_token: string;
|
|
246
246
|
}
|
|
247
|
+
/** POST /auth/forgot-password — request a recovery email. */
|
|
248
|
+
interface IForgotPasswordRequest {
|
|
249
|
+
email: string;
|
|
250
|
+
}
|
|
251
|
+
/** POST /auth/reset-password — set a new password from the one-time token. */
|
|
252
|
+
interface IResetPasswordRequest {
|
|
253
|
+
id_users: number;
|
|
254
|
+
token: string;
|
|
255
|
+
password: string;
|
|
256
|
+
}
|
|
247
257
|
interface ILoginSuccessData {
|
|
248
258
|
access_token: string;
|
|
249
259
|
refresh_token: string;
|
|
@@ -268,6 +278,18 @@ type ILanguagePreferenceUpdateResponse = IBaseApiResponse<{
|
|
|
268
278
|
access_token?: string;
|
|
269
279
|
language_id: number;
|
|
270
280
|
}>;
|
|
281
|
+
/**
|
|
282
|
+
* Generic success for the forgot-password request. The backend always returns
|
|
283
|
+
* `requested: true` regardless of whether the email matched an account, so the
|
|
284
|
+
* endpoint cannot be used to enumerate registered users.
|
|
285
|
+
*/
|
|
286
|
+
type IForgotPasswordResponse = IBaseApiResponse<{
|
|
287
|
+
requested: boolean;
|
|
288
|
+
}>;
|
|
289
|
+
/** Success when the recovery token was valid and the password was changed. */
|
|
290
|
+
type IResetPasswordResponse = IBaseApiResponse<{
|
|
291
|
+
reset: boolean;
|
|
292
|
+
}>;
|
|
271
293
|
|
|
272
294
|
interface IFormSubmitRequest {
|
|
273
295
|
section_id: number;
|
|
@@ -358,6 +380,8 @@ declare const ENDPOINTS: {
|
|
|
358
380
|
readonly TWO_FACTOR_VERIFY: "/cms-api/v1/auth/two-factor-verify";
|
|
359
381
|
readonly LOGOUT: "/cms-api/v1/auth/logout";
|
|
360
382
|
readonly REFRESH: "/cms-api/v1/auth/refresh-token";
|
|
383
|
+
readonly FORGOT_PASSWORD: "/cms-api/v1/auth/forgot-password";
|
|
384
|
+
readonly RESET_PASSWORD: "/cms-api/v1/auth/reset-password";
|
|
361
385
|
readonly SET_LANGUAGE: "/cms-api/v1/auth/set-language";
|
|
362
386
|
readonly USER_DATA: "/cms-api/v1/auth/user-data";
|
|
363
387
|
readonly EVENTS: "/cms-api/v1/auth/events";
|
|
@@ -640,4 +664,4 @@ declare function transformPageData(apiPage: IRawPage): IPageItem;
|
|
|
640
664
|
*/
|
|
641
665
|
declare function transformPagesData(pages: IRawPage[] | null | undefined): IPageItem[];
|
|
642
666
|
|
|
643
|
-
export { API_VERSION_PREFIX, CLASS_PATTERNS, CLASS_REMAP, CLIENT_TYPE_MOBILE, CLIENT_TYPE_MOBILE_AND_WEB, CLIENT_TYPE_WEB, COLOR_NAMES, ENDPOINTS, HEADER_CLIENT_TYPE, type IApiError, type IApiMeta, type IAssetSource, type IBaseApiResponse, type IBasePageInfo, type IBasePageSection, type IClassPattern, type IClassRemap, type IConditionContext, IContentField, type IEvaluatedCondition, type IFormDeleteRequest, type IFormDeleteResponse, type IFormResultLegacyFields, type IFormSubmitData, type IFormSubmitRequest, type IFormSubmitResponse, type IFormUpdateData, type IFormUpdateRequest, type IFormUpdateResponse, type IGetPageResponse, type IGetPagesResponse, type IJwtPayload, type ILanguage, type ILanguageItem, type ILanguagePreference, type ILanguagePreferenceUpdateResponse, type ILanguagesResponse, type ILoginRequest, type ILoginSuccessData, type ILoginSuccessResponse, type ILogoutSuccessResponse, type IMeta, type IPageAccessTypeInfo, type IPageContent, type IPageField, type IPageFieldTranslation, type IPageFieldsData, type IPageItem, type IPageSectionWithFields, type IPageSectionsData, type IRefreshRequest, type IRefreshSuccessResponse, type ISpacingValue, type ITwoFactorRequiredData, type ITwoFactorRequiredResponse, type ITwoFactorVerifyRequest, type ITwoFactorVerifySuccessResponse, type IUserData, type IUserDataResponse, LITERAL_CLASSES, PERMISSIONS, SIZE_VALUES, SPACING_VALUES, type TCalcedValues, type TClassDecision, type TClientType, type TPermission, type TPlatform, TStyleName, buildConditionContext, classifyClass, classifyClassString, evaluateCondition, findRemap, parseSpacing, replaceCalcedValues, resolveAssetSources, resolveAssetUrl, spacingToClasses, transformPageData, transformPagesData };
|
|
667
|
+
export { API_VERSION_PREFIX, CLASS_PATTERNS, CLASS_REMAP, CLIENT_TYPE_MOBILE, CLIENT_TYPE_MOBILE_AND_WEB, CLIENT_TYPE_WEB, COLOR_NAMES, ENDPOINTS, HEADER_CLIENT_TYPE, type IApiError, type IApiMeta, type IAssetSource, type IBaseApiResponse, type IBasePageInfo, type IBasePageSection, type IClassPattern, type IClassRemap, type IConditionContext, IContentField, type IEvaluatedCondition, type IForgotPasswordRequest, type IForgotPasswordResponse, type IFormDeleteRequest, type IFormDeleteResponse, type IFormResultLegacyFields, type IFormSubmitData, type IFormSubmitRequest, type IFormSubmitResponse, type IFormUpdateData, type IFormUpdateRequest, type IFormUpdateResponse, type IGetPageResponse, type IGetPagesResponse, type IJwtPayload, type ILanguage, type ILanguageItem, type ILanguagePreference, type ILanguagePreferenceUpdateResponse, type ILanguagesResponse, type ILoginRequest, type ILoginSuccessData, type ILoginSuccessResponse, type ILogoutSuccessResponse, type IMeta, type IPageAccessTypeInfo, type IPageContent, type IPageField, type IPageFieldTranslation, type IPageFieldsData, type IPageItem, type IPageSectionWithFields, type IPageSectionsData, type IRefreshRequest, type IRefreshSuccessResponse, type IResetPasswordRequest, type IResetPasswordResponse, type ISpacingValue, type ITwoFactorRequiredData, type ITwoFactorRequiredResponse, type ITwoFactorVerifyRequest, type ITwoFactorVerifySuccessResponse, type IUserData, type IUserDataResponse, LITERAL_CLASSES, PERMISSIONS, SIZE_VALUES, SPACING_VALUES, type TCalcedValues, type TClassDecision, type TClientType, type TPermission, type TPlatform, TStyleName, buildConditionContext, classifyClass, classifyClassString, evaluateCondition, findRemap, parseSpacing, replaceCalcedValues, resolveAssetSources, resolveAssetUrl, spacingToClasses, transformPageData, transformPagesData };
|
package/dist/index.d.ts
CHANGED
|
@@ -244,6 +244,16 @@ interface ITwoFactorVerifyRequest {
|
|
|
244
244
|
interface IRefreshRequest {
|
|
245
245
|
refresh_token: string;
|
|
246
246
|
}
|
|
247
|
+
/** POST /auth/forgot-password — request a recovery email. */
|
|
248
|
+
interface IForgotPasswordRequest {
|
|
249
|
+
email: string;
|
|
250
|
+
}
|
|
251
|
+
/** POST /auth/reset-password — set a new password from the one-time token. */
|
|
252
|
+
interface IResetPasswordRequest {
|
|
253
|
+
id_users: number;
|
|
254
|
+
token: string;
|
|
255
|
+
password: string;
|
|
256
|
+
}
|
|
247
257
|
interface ILoginSuccessData {
|
|
248
258
|
access_token: string;
|
|
249
259
|
refresh_token: string;
|
|
@@ -268,6 +278,18 @@ type ILanguagePreferenceUpdateResponse = IBaseApiResponse<{
|
|
|
268
278
|
access_token?: string;
|
|
269
279
|
language_id: number;
|
|
270
280
|
}>;
|
|
281
|
+
/**
|
|
282
|
+
* Generic success for the forgot-password request. The backend always returns
|
|
283
|
+
* `requested: true` regardless of whether the email matched an account, so the
|
|
284
|
+
* endpoint cannot be used to enumerate registered users.
|
|
285
|
+
*/
|
|
286
|
+
type IForgotPasswordResponse = IBaseApiResponse<{
|
|
287
|
+
requested: boolean;
|
|
288
|
+
}>;
|
|
289
|
+
/** Success when the recovery token was valid and the password was changed. */
|
|
290
|
+
type IResetPasswordResponse = IBaseApiResponse<{
|
|
291
|
+
reset: boolean;
|
|
292
|
+
}>;
|
|
271
293
|
|
|
272
294
|
interface IFormSubmitRequest {
|
|
273
295
|
section_id: number;
|
|
@@ -358,6 +380,8 @@ declare const ENDPOINTS: {
|
|
|
358
380
|
readonly TWO_FACTOR_VERIFY: "/cms-api/v1/auth/two-factor-verify";
|
|
359
381
|
readonly LOGOUT: "/cms-api/v1/auth/logout";
|
|
360
382
|
readonly REFRESH: "/cms-api/v1/auth/refresh-token";
|
|
383
|
+
readonly FORGOT_PASSWORD: "/cms-api/v1/auth/forgot-password";
|
|
384
|
+
readonly RESET_PASSWORD: "/cms-api/v1/auth/reset-password";
|
|
361
385
|
readonly SET_LANGUAGE: "/cms-api/v1/auth/set-language";
|
|
362
386
|
readonly USER_DATA: "/cms-api/v1/auth/user-data";
|
|
363
387
|
readonly EVENTS: "/cms-api/v1/auth/events";
|
|
@@ -640,4 +664,4 @@ declare function transformPageData(apiPage: IRawPage): IPageItem;
|
|
|
640
664
|
*/
|
|
641
665
|
declare function transformPagesData(pages: IRawPage[] | null | undefined): IPageItem[];
|
|
642
666
|
|
|
643
|
-
export { API_VERSION_PREFIX, CLASS_PATTERNS, CLASS_REMAP, CLIENT_TYPE_MOBILE, CLIENT_TYPE_MOBILE_AND_WEB, CLIENT_TYPE_WEB, COLOR_NAMES, ENDPOINTS, HEADER_CLIENT_TYPE, type IApiError, type IApiMeta, type IAssetSource, type IBaseApiResponse, type IBasePageInfo, type IBasePageSection, type IClassPattern, type IClassRemap, type IConditionContext, IContentField, type IEvaluatedCondition, type IFormDeleteRequest, type IFormDeleteResponse, type IFormResultLegacyFields, type IFormSubmitData, type IFormSubmitRequest, type IFormSubmitResponse, type IFormUpdateData, type IFormUpdateRequest, type IFormUpdateResponse, type IGetPageResponse, type IGetPagesResponse, type IJwtPayload, type ILanguage, type ILanguageItem, type ILanguagePreference, type ILanguagePreferenceUpdateResponse, type ILanguagesResponse, type ILoginRequest, type ILoginSuccessData, type ILoginSuccessResponse, type ILogoutSuccessResponse, type IMeta, type IPageAccessTypeInfo, type IPageContent, type IPageField, type IPageFieldTranslation, type IPageFieldsData, type IPageItem, type IPageSectionWithFields, type IPageSectionsData, type IRefreshRequest, type IRefreshSuccessResponse, type ISpacingValue, type ITwoFactorRequiredData, type ITwoFactorRequiredResponse, type ITwoFactorVerifyRequest, type ITwoFactorVerifySuccessResponse, type IUserData, type IUserDataResponse, LITERAL_CLASSES, PERMISSIONS, SIZE_VALUES, SPACING_VALUES, type TCalcedValues, type TClassDecision, type TClientType, type TPermission, type TPlatform, TStyleName, buildConditionContext, classifyClass, classifyClassString, evaluateCondition, findRemap, parseSpacing, replaceCalcedValues, resolveAssetSources, resolveAssetUrl, spacingToClasses, transformPageData, transformPagesData };
|
|
667
|
+
export { API_VERSION_PREFIX, CLASS_PATTERNS, CLASS_REMAP, CLIENT_TYPE_MOBILE, CLIENT_TYPE_MOBILE_AND_WEB, CLIENT_TYPE_WEB, COLOR_NAMES, ENDPOINTS, HEADER_CLIENT_TYPE, type IApiError, type IApiMeta, type IAssetSource, type IBaseApiResponse, type IBasePageInfo, type IBasePageSection, type IClassPattern, type IClassRemap, type IConditionContext, IContentField, type IEvaluatedCondition, type IForgotPasswordRequest, type IForgotPasswordResponse, type IFormDeleteRequest, type IFormDeleteResponse, type IFormResultLegacyFields, type IFormSubmitData, type IFormSubmitRequest, type IFormSubmitResponse, type IFormUpdateData, type IFormUpdateRequest, type IFormUpdateResponse, type IGetPageResponse, type IGetPagesResponse, type IJwtPayload, type ILanguage, type ILanguageItem, type ILanguagePreference, type ILanguagePreferenceUpdateResponse, type ILanguagesResponse, type ILoginRequest, type ILoginSuccessData, type ILoginSuccessResponse, type ILogoutSuccessResponse, type IMeta, type IPageAccessTypeInfo, type IPageContent, type IPageField, type IPageFieldTranslation, type IPageFieldsData, type IPageItem, type IPageSectionWithFields, type IPageSectionsData, type IRefreshRequest, type IRefreshSuccessResponse, type IResetPasswordRequest, type IResetPasswordResponse, type ISpacingValue, type ITwoFactorRequiredData, type ITwoFactorRequiredResponse, type ITwoFactorVerifyRequest, type ITwoFactorVerifySuccessResponse, type IUserData, type IUserDataResponse, LITERAL_CLASSES, PERMISSIONS, SIZE_VALUES, SPACING_VALUES, type TCalcedValues, type TClassDecision, type TClientType, type TPermission, type TPlatform, TStyleName, buildConditionContext, classifyClass, classifyClassString, evaluateCondition, findRemap, parseSpacing, replaceCalcedValues, resolveAssetSources, resolveAssetUrl, spacingToClasses, transformPageData, transformPagesData };
|
package/dist/index.js
CHANGED
|
@@ -317,6 +317,8 @@ var ENDPOINTS = {
|
|
|
317
317
|
TWO_FACTOR_VERIFY: `${API_VERSION_PREFIX}/auth/two-factor-verify`,
|
|
318
318
|
LOGOUT: `${API_VERSION_PREFIX}/auth/logout`,
|
|
319
319
|
REFRESH: `${API_VERSION_PREFIX}/auth/refresh-token`,
|
|
320
|
+
FORGOT_PASSWORD: `${API_VERSION_PREFIX}/auth/forgot-password`,
|
|
321
|
+
RESET_PASSWORD: `${API_VERSION_PREFIX}/auth/reset-password`,
|
|
320
322
|
SET_LANGUAGE: `${API_VERSION_PREFIX}/auth/set-language`,
|
|
321
323
|
USER_DATA: `${API_VERSION_PREFIX}/auth/user-data`,
|
|
322
324
|
EVENTS: `${API_VERSION_PREFIX}/auth/events`
|
package/dist/index.mjs
CHANGED
|
@@ -232,6 +232,8 @@ var ENDPOINTS = {
|
|
|
232
232
|
TWO_FACTOR_VERIFY: `${API_VERSION_PREFIX}/auth/two-factor-verify`,
|
|
233
233
|
LOGOUT: `${API_VERSION_PREFIX}/auth/logout`,
|
|
234
234
|
REFRESH: `${API_VERSION_PREFIX}/auth/refresh-token`,
|
|
235
|
+
FORGOT_PASSWORD: `${API_VERSION_PREFIX}/auth/forgot-password`,
|
|
236
|
+
RESET_PASSWORD: `${API_VERSION_PREFIX}/auth/reset-password`,
|
|
235
237
|
SET_LANGUAGE: `${API_VERSION_PREFIX}/auth/set-language`,
|
|
236
238
|
USER_DATA: `${API_VERSION_PREFIX}/auth/user-data`,
|
|
237
239
|
EVENTS: `${API_VERSION_PREFIX}/auth/events`
|
package/package.json
CHANGED
|
@@ -1,102 +1,102 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@selfhelp/shared",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Shared TypeScript package for SelfHelp web frontend and mobile app: style registry, types, API contracts, Mantine theme tokens, condition + interpolation engines, CMS class allow-list.",
|
|
5
|
-
"repository": {
|
|
6
|
-
"type": "git",
|
|
7
|
-
"url": "git+https://github.com/humdek-unibe-ch/sh-selfhelp_shared.git"
|
|
8
|
-
},
|
|
9
|
-
"homepage": "https://github.com/humdek-unibe-ch/sh-selfhelp_shared#readme",
|
|
10
|
-
"bugs": {
|
|
11
|
-
"url": "https://github.com/humdek-unibe-ch/sh-selfhelp_shared/issues"
|
|
12
|
-
},
|
|
13
|
-
"main": "dist/index.js",
|
|
14
|
-
"module": "dist/index.mjs",
|
|
15
|
-
"types": "dist/index.d.ts",
|
|
16
|
-
"exports": {
|
|
17
|
-
".": {
|
|
18
|
-
"types": "./dist/index.d.ts",
|
|
19
|
-
"import": "./dist/index.mjs",
|
|
20
|
-
"require": "./dist/index.js"
|
|
21
|
-
},
|
|
22
|
-
"./registry": {
|
|
23
|
-
"types": "./dist/registry/index.d.ts",
|
|
24
|
-
"import": "./dist/registry/index.mjs",
|
|
25
|
-
"require": "./dist/registry/index.js"
|
|
26
|
-
},
|
|
27
|
-
"./theme": {
|
|
28
|
-
"types": "./dist/theme/index.d.ts",
|
|
29
|
-
"import": "./dist/theme/index.mjs",
|
|
30
|
-
"require": "./dist/theme/index.js"
|
|
31
|
-
},
|
|
32
|
-
"./tailwind": {
|
|
33
|
-
"types": "./dist/theme/tailwind.d.ts",
|
|
34
|
-
"import": "./dist/theme/tailwind.mjs",
|
|
35
|
-
"require": "./dist/theme/tailwind.js"
|
|
36
|
-
},
|
|
37
|
-
"./plugin-sdk": {
|
|
38
|
-
"types": "./dist/plugin-sdk/index.d.ts",
|
|
39
|
-
"import": "./dist/plugin-sdk/index.mjs",
|
|
40
|
-
"require": "./dist/plugin-sdk/index.js"
|
|
41
|
-
},
|
|
42
|
-
"./testing": {
|
|
43
|
-
"types": "./dist/testing/index.d.ts",
|
|
44
|
-
"import": "./dist/testing/index.mjs",
|
|
45
|
-
"require": "./dist/testing/index.js"
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
"files": [
|
|
49
|
-
"dist",
|
|
50
|
-
"src",
|
|
51
|
-
"README.md",
|
|
52
|
-
"CHANGELOG.md"
|
|
53
|
-
],
|
|
54
|
-
"scripts": {
|
|
55
|
-
"build": "tsup src/index.ts src/registry/index.ts src/theme/index.ts src/theme/tailwind.ts src/plugin-sdk/index.ts src/testing/index.ts --format cjs,esm --dts --clean --no-splitting",
|
|
56
|
-
"dev": "tsup src/index.ts src/registry/index.ts src/theme/index.ts src/theme/tailwind.ts src/plugin-sdk/index.ts src/testing/index.ts --format cjs,esm --dts --watch --no-splitting",
|
|
57
|
-
"lint": "eslint . --ext .ts",
|
|
58
|
-
"typecheck": "tsc --noEmit",
|
|
59
|
-
"test": "vitest run --passWithNoTests",
|
|
60
|
-
"test:coverage": "vitest run --coverage",
|
|
61
|
-
"test:changed": "vitest run --changed --passWithNoTests",
|
|
62
|
-
"test:release": "npm run headers:check && npm run typecheck && npm run check:schemas && npm run test:coverage && npm run build",
|
|
63
|
-
"check:schemas": "node scripts/check-schema-parity.mjs",
|
|
64
|
-
"prepublishOnly": "npm run build",
|
|
65
|
-
"headers:check": "license-check-and-add check -f license-check-and-add-config.json",
|
|
66
|
-
"headers:add": "license-check-and-add add -f license-check-and-add-config.json",
|
|
67
|
-
"headers:remove": "license-check-and-add remove -f license-check-and-add-config.json"
|
|
68
|
-
},
|
|
69
|
-
"dependencies": {
|
|
70
|
-
"json-logic-js": "^2.0.5"
|
|
71
|
-
},
|
|
72
|
-
"peerDependencies": {
|
|
73
|
-
"react": "^18.0.0 || ^19.0.0"
|
|
74
|
-
},
|
|
75
|
-
"peerDependenciesMeta": {
|
|
76
|
-
"react": {
|
|
77
|
-
"optional": true
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
|
-
"devDependencies": {
|
|
81
|
-
"@types/json-logic-js": "^2.0.8",
|
|
82
|
-
"@types/node": "^22.10.0",
|
|
83
|
-
"@types/react": "^19.2.15",
|
|
84
|
-
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
|
85
|
-
"@typescript-eslint/parser": "^8.0.0",
|
|
86
|
-
"@vitest/coverage-istanbul": "^2.1.9",
|
|
87
|
-
"eslint": "^9.18.0",
|
|
88
|
-
"license-check-and-add": "^4.0.5",
|
|
89
|
-
"react": "^19.2.6",
|
|
90
|
-
"tsup": "^8.3.5",
|
|
91
|
-
"typescript": "^5.6.0",
|
|
92
|
-
"vitest": "^2.1.0"
|
|
93
|
-
},
|
|
94
|
-
"publishConfig": {
|
|
95
|
-
"access": "public"
|
|
96
|
-
},
|
|
97
|
-
"engines": {
|
|
98
|
-
"node": ">=18"
|
|
99
|
-
},
|
|
100
|
-
"sideEffects": false,
|
|
101
|
-
"license": "MPL-2.0"
|
|
102
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@selfhelp/shared",
|
|
3
|
+
"version": "1.3.1",
|
|
4
|
+
"description": "Shared TypeScript package for SelfHelp web frontend and mobile app: style registry, types, API contracts, Mantine theme tokens, condition + interpolation engines, CMS class allow-list.",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/humdek-unibe-ch/sh-selfhelp_shared.git"
|
|
8
|
+
},
|
|
9
|
+
"homepage": "https://github.com/humdek-unibe-ch/sh-selfhelp_shared#readme",
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/humdek-unibe-ch/sh-selfhelp_shared/issues"
|
|
12
|
+
},
|
|
13
|
+
"main": "dist/index.js",
|
|
14
|
+
"module": "dist/index.mjs",
|
|
15
|
+
"types": "dist/index.d.ts",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"import": "./dist/index.mjs",
|
|
20
|
+
"require": "./dist/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./registry": {
|
|
23
|
+
"types": "./dist/registry/index.d.ts",
|
|
24
|
+
"import": "./dist/registry/index.mjs",
|
|
25
|
+
"require": "./dist/registry/index.js"
|
|
26
|
+
},
|
|
27
|
+
"./theme": {
|
|
28
|
+
"types": "./dist/theme/index.d.ts",
|
|
29
|
+
"import": "./dist/theme/index.mjs",
|
|
30
|
+
"require": "./dist/theme/index.js"
|
|
31
|
+
},
|
|
32
|
+
"./tailwind": {
|
|
33
|
+
"types": "./dist/theme/tailwind.d.ts",
|
|
34
|
+
"import": "./dist/theme/tailwind.mjs",
|
|
35
|
+
"require": "./dist/theme/tailwind.js"
|
|
36
|
+
},
|
|
37
|
+
"./plugin-sdk": {
|
|
38
|
+
"types": "./dist/plugin-sdk/index.d.ts",
|
|
39
|
+
"import": "./dist/plugin-sdk/index.mjs",
|
|
40
|
+
"require": "./dist/plugin-sdk/index.js"
|
|
41
|
+
},
|
|
42
|
+
"./testing": {
|
|
43
|
+
"types": "./dist/testing/index.d.ts",
|
|
44
|
+
"import": "./dist/testing/index.mjs",
|
|
45
|
+
"require": "./dist/testing/index.js"
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"files": [
|
|
49
|
+
"dist",
|
|
50
|
+
"src",
|
|
51
|
+
"README.md",
|
|
52
|
+
"CHANGELOG.md"
|
|
53
|
+
],
|
|
54
|
+
"scripts": {
|
|
55
|
+
"build": "tsup src/index.ts src/registry/index.ts src/theme/index.ts src/theme/tailwind.ts src/plugin-sdk/index.ts src/testing/index.ts --format cjs,esm --dts --clean --no-splitting",
|
|
56
|
+
"dev": "tsup src/index.ts src/registry/index.ts src/theme/index.ts src/theme/tailwind.ts src/plugin-sdk/index.ts src/testing/index.ts --format cjs,esm --dts --watch --no-splitting",
|
|
57
|
+
"lint": "eslint . --ext .ts",
|
|
58
|
+
"typecheck": "tsc --noEmit",
|
|
59
|
+
"test": "vitest run --passWithNoTests",
|
|
60
|
+
"test:coverage": "vitest run --coverage",
|
|
61
|
+
"test:changed": "vitest run --changed --passWithNoTests",
|
|
62
|
+
"test:release": "npm run headers:check && npm run typecheck && npm run check:schemas && npm run test:coverage && npm run build",
|
|
63
|
+
"check:schemas": "node scripts/check-schema-parity.mjs",
|
|
64
|
+
"prepublishOnly": "npm run build",
|
|
65
|
+
"headers:check": "license-check-and-add check -f license-check-and-add-config.json",
|
|
66
|
+
"headers:add": "license-check-and-add add -f license-check-and-add-config.json",
|
|
67
|
+
"headers:remove": "license-check-and-add remove -f license-check-and-add-config.json"
|
|
68
|
+
},
|
|
69
|
+
"dependencies": {
|
|
70
|
+
"json-logic-js": "^2.0.5"
|
|
71
|
+
},
|
|
72
|
+
"peerDependencies": {
|
|
73
|
+
"react": "^18.0.0 || ^19.0.0"
|
|
74
|
+
},
|
|
75
|
+
"peerDependenciesMeta": {
|
|
76
|
+
"react": {
|
|
77
|
+
"optional": true
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
"devDependencies": {
|
|
81
|
+
"@types/json-logic-js": "^2.0.8",
|
|
82
|
+
"@types/node": "^22.10.0",
|
|
83
|
+
"@types/react": "^19.2.15",
|
|
84
|
+
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
|
85
|
+
"@typescript-eslint/parser": "^8.0.0",
|
|
86
|
+
"@vitest/coverage-istanbul": "^2.1.9",
|
|
87
|
+
"eslint": "^9.18.0",
|
|
88
|
+
"license-check-and-add": "^4.0.5",
|
|
89
|
+
"react": "^19.2.6",
|
|
90
|
+
"tsup": "^8.3.5",
|
|
91
|
+
"typescript": "^5.6.0",
|
|
92
|
+
"vitest": "^2.1.0"
|
|
93
|
+
},
|
|
94
|
+
"publishConfig": {
|
|
95
|
+
"access": "public"
|
|
96
|
+
},
|
|
97
|
+
"engines": {
|
|
98
|
+
"node": ">=18"
|
|
99
|
+
},
|
|
100
|
+
"sideEffects": false,
|
|
101
|
+
"license": "MPL-2.0"
|
|
102
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* SPDX-FileCopyrightText: 2026 Humdek, University of Bern
|
|
3
|
+
* SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { describe, expect, it } from 'vitest';
|
|
7
|
+
import { API_VERSION_PREFIX, ENDPOINTS } from '../endpoints';
|
|
8
|
+
import type {
|
|
9
|
+
IForgotPasswordRequest,
|
|
10
|
+
IResetPasswordRequest,
|
|
11
|
+
} from '../../types/api/auth';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Contract coverage for the public auth endpoint catalog. The frontend and the
|
|
15
|
+
* mobile app both build their password-recovery requests from these constants,
|
|
16
|
+
* so a wrong/missing path silently breaks the cross-repo flow (issue #31). The
|
|
17
|
+
* backend serves these under `/cms-api/v1/auth/...`.
|
|
18
|
+
*/
|
|
19
|
+
describe('ENDPOINTS.AUTH password recovery', () => {
|
|
20
|
+
it('exposes the forgot-password endpoint at the backend path', () => {
|
|
21
|
+
expect(ENDPOINTS.AUTH.FORGOT_PASSWORD).toBe(
|
|
22
|
+
`${API_VERSION_PREFIX}/auth/forgot-password`,
|
|
23
|
+
);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('exposes the reset-password endpoint at the backend path', () => {
|
|
27
|
+
expect(ENDPOINTS.AUTH.RESET_PASSWORD).toBe(
|
|
28
|
+
`${API_VERSION_PREFIX}/auth/reset-password`,
|
|
29
|
+
);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('models the request DTOs with the backend-required fields', () => {
|
|
33
|
+
const forgot: IForgotPasswordRequest = { email: 'qa.user@selfhelp.test' };
|
|
34
|
+
const reset: IResetPasswordRequest = {
|
|
35
|
+
id_users: 1,
|
|
36
|
+
token: 'qa-token',
|
|
37
|
+
password: 'qa-password-123',
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
expect(Object.keys(forgot)).toEqual(['email']);
|
|
41
|
+
expect(Object.keys(reset).sort()).toEqual(
|
|
42
|
+
['id_users', 'password', 'token'],
|
|
43
|
+
);
|
|
44
|
+
});
|
|
45
|
+
});
|
package/src/api/endpoints.ts
CHANGED
|
@@ -15,6 +15,8 @@ export const ENDPOINTS = {
|
|
|
15
15
|
TWO_FACTOR_VERIFY: `${API_VERSION_PREFIX}/auth/two-factor-verify`,
|
|
16
16
|
LOGOUT: `${API_VERSION_PREFIX}/auth/logout`,
|
|
17
17
|
REFRESH: `${API_VERSION_PREFIX}/auth/refresh-token`,
|
|
18
|
+
FORGOT_PASSWORD: `${API_VERSION_PREFIX}/auth/forgot-password`,
|
|
19
|
+
RESET_PASSWORD: `${API_VERSION_PREFIX}/auth/reset-password`,
|
|
18
20
|
SET_LANGUAGE: `${API_VERSION_PREFIX}/auth/set-language`,
|
|
19
21
|
USER_DATA: `${API_VERSION_PREFIX}/auth/user-data`,
|
|
20
22
|
EVENTS: `${API_VERSION_PREFIX}/auth/events`,
|
package/src/api/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/*
|
|
2
|
-
SPDX-FileCopyrightText: 2026 Humdek, University of Bern
|
|
3
|
-
SPDX-License-Identifier: MPL-2.0
|
|
4
|
-
*/
|
|
5
|
-
export * from './endpoints';
|
|
1
|
+
/*
|
|
2
|
+
SPDX-FileCopyrightText: 2026 Humdek, University of Bern
|
|
3
|
+
SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
*/
|
|
5
|
+
export * from './endpoints';
|
|
@@ -1,61 +1,61 @@
|
|
|
1
|
-
/*
|
|
2
|
-
SPDX-FileCopyrightText: 2026 Humdek, University of Bern
|
|
3
|
-
SPDX-License-Identifier: MPL-2.0
|
|
4
|
-
*/
|
|
5
|
-
import { describe, it, expect } from 'vitest';
|
|
6
|
-
import { resolveAssetUrl, resolveAssetSources } from '../resolveAssetUrl';
|
|
7
|
-
|
|
8
|
-
describe('resolveAssetUrl', () => {
|
|
9
|
-
const base = 'https://api.example.com';
|
|
10
|
-
|
|
11
|
-
it('prefixes a root-relative path with the base url', () => {
|
|
12
|
-
expect(resolveAssetUrl('/assets/img/foo.png', base)).toBe('https://api.example.com/assets/img/foo.png');
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('adds a leading slash for paths that lack one', () => {
|
|
16
|
-
expect(resolveAssetUrl('assets/foo.png', base)).toBe('https://api.example.com/assets/foo.png');
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('strips trailing slashes from the base url', () => {
|
|
20
|
-
expect(resolveAssetUrl('/foo.png', 'https://api.example.com/')).toBe('https://api.example.com/foo.png');
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('passes absolute http(s) urls through unchanged', () => {
|
|
24
|
-
expect(resolveAssetUrl('https://cdn.example.com/foo.png', base)).toBe('https://cdn.example.com/foo.png');
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('passes protocol-relative urls through unchanged', () => {
|
|
28
|
-
expect(resolveAssetUrl('//cdn.example.com/foo.png', base)).toBe('//cdn.example.com/foo.png');
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('passes data/blob/file uris through unchanged', () => {
|
|
32
|
-
expect(resolveAssetUrl('data:image/png;base64,AAAA', base)).toBe('data:image/png;base64,AAAA');
|
|
33
|
-
expect(resolveAssetUrl('blob:abc', base)).toBe('blob:abc');
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('returns an empty string for null/undefined/empty input', () => {
|
|
37
|
-
expect(resolveAssetUrl(null, base)).toBe('');
|
|
38
|
-
expect(resolveAssetUrl(undefined, base)).toBe('');
|
|
39
|
-
expect(resolveAssetUrl('', base)).toBe('');
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
describe('resolveAssetSources', () => {
|
|
44
|
-
it('resolves the src of each source and keeps other fields', () => {
|
|
45
|
-
const resolved = resolveAssetSources(
|
|
46
|
-
[
|
|
47
|
-
{ src: '/a.mp4', type: 'video/mp4' },
|
|
48
|
-
{ src: 'https://cdn/b.webm', type: 'video/webm' },
|
|
49
|
-
],
|
|
50
|
-
'https://api.example.com',
|
|
51
|
-
);
|
|
52
|
-
expect(resolved).toEqual([
|
|
53
|
-
{ src: 'https://api.example.com/a.mp4', type: 'video/mp4' },
|
|
54
|
-
{ src: 'https://cdn/b.webm', type: 'video/webm' },
|
|
55
|
-
]);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('returns an empty array for undefined sources', () => {
|
|
59
|
-
expect(resolveAssetSources(undefined, 'https://api.example.com')).toEqual([]);
|
|
60
|
-
});
|
|
61
|
-
});
|
|
1
|
+
/*
|
|
2
|
+
SPDX-FileCopyrightText: 2026 Humdek, University of Bern
|
|
3
|
+
SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { describe, it, expect } from 'vitest';
|
|
6
|
+
import { resolveAssetUrl, resolveAssetSources } from '../resolveAssetUrl';
|
|
7
|
+
|
|
8
|
+
describe('resolveAssetUrl', () => {
|
|
9
|
+
const base = 'https://api.example.com';
|
|
10
|
+
|
|
11
|
+
it('prefixes a root-relative path with the base url', () => {
|
|
12
|
+
expect(resolveAssetUrl('/assets/img/foo.png', base)).toBe('https://api.example.com/assets/img/foo.png');
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('adds a leading slash for paths that lack one', () => {
|
|
16
|
+
expect(resolveAssetUrl('assets/foo.png', base)).toBe('https://api.example.com/assets/foo.png');
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('strips trailing slashes from the base url', () => {
|
|
20
|
+
expect(resolveAssetUrl('/foo.png', 'https://api.example.com/')).toBe('https://api.example.com/foo.png');
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('passes absolute http(s) urls through unchanged', () => {
|
|
24
|
+
expect(resolveAssetUrl('https://cdn.example.com/foo.png', base)).toBe('https://cdn.example.com/foo.png');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('passes protocol-relative urls through unchanged', () => {
|
|
28
|
+
expect(resolveAssetUrl('//cdn.example.com/foo.png', base)).toBe('//cdn.example.com/foo.png');
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('passes data/blob/file uris through unchanged', () => {
|
|
32
|
+
expect(resolveAssetUrl('data:image/png;base64,AAAA', base)).toBe('data:image/png;base64,AAAA');
|
|
33
|
+
expect(resolveAssetUrl('blob:abc', base)).toBe('blob:abc');
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('returns an empty string for null/undefined/empty input', () => {
|
|
37
|
+
expect(resolveAssetUrl(null, base)).toBe('');
|
|
38
|
+
expect(resolveAssetUrl(undefined, base)).toBe('');
|
|
39
|
+
expect(resolveAssetUrl('', base)).toBe('');
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
describe('resolveAssetSources', () => {
|
|
44
|
+
it('resolves the src of each source and keeps other fields', () => {
|
|
45
|
+
const resolved = resolveAssetSources(
|
|
46
|
+
[
|
|
47
|
+
{ src: '/a.mp4', type: 'video/mp4' },
|
|
48
|
+
{ src: 'https://cdn/b.webm', type: 'video/webm' },
|
|
49
|
+
],
|
|
50
|
+
'https://api.example.com',
|
|
51
|
+
);
|
|
52
|
+
expect(resolved).toEqual([
|
|
53
|
+
{ src: 'https://api.example.com/a.mp4', type: 'video/mp4' },
|
|
54
|
+
{ src: 'https://cdn/b.webm', type: 'video/webm' },
|
|
55
|
+
]);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('returns an empty array for undefined sources', () => {
|
|
59
|
+
expect(resolveAssetSources(undefined, 'https://api.example.com')).toEqual([]);
|
|
60
|
+
});
|
|
61
|
+
});
|