@carlonicora/nextjs-jsonapi 0.0.1 → 1.0.4
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/dist/BlockNoteEditor-VFWG6LXI.js.map +1 -1
- package/dist/JsonApiRequest-ZZLSP26T.js.map +1 -1
- package/dist/atoms/index.js.map +1 -1
- package/dist/chunk-2K3Q24UF.js.map +1 -1
- package/dist/chunk-3FBCC4G3.js.map +1 -1
- package/dist/chunk-4HCRAOS5.js.map +1 -1
- package/dist/chunk-6GKHCVF6.js.map +1 -1
- package/dist/chunk-7QVYU63E.js.map +1 -1
- package/dist/chunk-A5DDIABK.js.map +1 -1
- package/dist/chunk-AWONBQQP.js.map +1 -1
- package/dist/chunk-CXQOWQSY.js.map +1 -1
- package/dist/chunk-DO2HLAZO.js.map +1 -1
- package/dist/chunk-EFJEWLRL.js.map +1 -1
- package/dist/chunk-FY4SXJGU.js.map +1 -1
- package/dist/chunk-H6FMOA6B.js.map +1 -1
- package/dist/chunk-I2REI7OA.js.map +1 -1
- package/dist/chunk-IBS6NI7D.js.map +1 -1
- package/dist/chunk-J4Q36PMP.js.map +1 -1
- package/dist/chunk-JC3WJK65.js.map +1 -1
- package/dist/chunk-LXKSUWAV.js.map +1 -1
- package/dist/chunk-RAF7PNLG.js.map +1 -1
- package/dist/chunk-RUR22SVM.js.map +1 -1
- package/dist/chunk-TEGF6ZWG.js.map +1 -1
- package/dist/chunk-TMVHSY3Y.js.map +1 -1
- package/dist/chunk-V2JJPI7N.js.map +1 -1
- package/dist/client/index.js.map +1 -1
- package/dist/components/index.js.map +1 -1
- package/dist/contexts/index.js.map +1 -1
- package/dist/core/index.js.map +1 -1
- package/dist/features/index.js.map +1 -1
- package/dist/hooks/index.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/interfaces/index.js.map +1 -1
- package/dist/permissions/index.js.map +1 -1
- package/dist/request-QFS7NEIE.js.map +1 -1
- package/dist/request-ZYY6RI5X.js.map +1 -1
- package/dist/roles/index.js.map +1 -1
- package/dist/server/index.js.map +1 -1
- package/dist/shadcnui/index.js.map +1 -1
- package/dist/token-MJMC26ON.js.map +1 -1
- package/dist/token-UYE7CV6X.js.map +1 -1
- package/dist/utils/index.js.map +1 -1
- package/package.json +6 -1
- package/src/atoms/index.ts +1 -0
- package/src/atoms/recentPagesAtom.ts +10 -0
- package/src/client/context/JsonApiContext.ts +61 -0
- package/src/client/context/JsonApiProvider.tsx +27 -0
- package/src/client/context/index.ts +2 -0
- package/src/client/hooks/index.ts +3 -0
- package/src/client/hooks/useJsonApiGet.ts +188 -0
- package/src/client/hooks/useJsonApiMutation.ts +193 -0
- package/src/client/hooks/useRehydration.ts +47 -0
- package/src/client/index.ts +11 -0
- package/src/client/request.ts +97 -0
- package/src/client/token.ts +10 -0
- package/src/components/containers/PageContainer.tsx +15 -0
- package/src/components/containers/ReactMarkdownContainer.tsx +119 -0
- package/src/components/containers/TabsContainer.tsx +93 -0
- package/src/components/containers/index.ts +3 -0
- package/src/components/contents/AttributeElement.tsx +20 -0
- package/src/components/contents/index.ts +1 -0
- package/src/components/details/AllowedUsersDetails.tsx +23 -0
- package/src/components/details/index.ts +1 -0
- package/src/components/editors/BlockNoteDiffInlineContent.tsx +152 -0
- package/src/components/editors/BlockNoteEditor.tsx +404 -0
- package/src/components/editors/BlockNoteEditorContainer.tsx +13 -0
- package/src/components/editors/BlockNoteEditorFormattingToolbar.tsx +38 -0
- package/src/components/editors/index.ts +1 -0
- package/src/components/errors/ErrorDetails.tsx +41 -0
- package/src/components/errors/errorToast.ts +9 -0
- package/src/components/errors/index.ts +2 -0
- package/src/components/forms/CommonAssociationForm.tsx +162 -0
- package/src/components/forms/CommonDeleter.tsx +94 -0
- package/src/components/forms/CommonEditorButtons.tsx +30 -0
- package/src/components/forms/CommonEditorHeader.tsx +35 -0
- package/src/components/forms/CommonEditorTrigger.tsx +26 -0
- package/src/components/forms/DatePickerPopover.tsx +219 -0
- package/src/components/forms/DateRangeSelector.tsx +110 -0
- package/src/components/forms/FileUploader.tsx +324 -0
- package/src/components/forms/FormCheckbox.tsx +66 -0
- package/src/components/forms/FormContainerGeneric.tsx +39 -0
- package/src/components/forms/FormDate.tsx +247 -0
- package/src/components/forms/FormDateTime.tsx +231 -0
- package/src/components/forms/FormInput.tsx +110 -0
- package/src/components/forms/FormPassword.tsx +54 -0
- package/src/components/forms/FormPlaceAutocomplete.tsx +286 -0
- package/src/components/forms/FormSelect.tsx +72 -0
- package/src/components/forms/FormSlider.tsx +51 -0
- package/src/components/forms/FormSwitch.tsx +25 -0
- package/src/components/forms/FormTextarea.tsx +44 -0
- package/src/components/forms/MultiFileUploader.tsx +107 -0
- package/src/components/forms/PasswordInput.tsx +47 -0
- package/src/components/forms/index.ts +21 -0
- package/src/components/index.ts +11 -0
- package/src/components/navigations/Breadcrumb.tsx +83 -0
- package/src/components/navigations/ContentTitle.tsx +39 -0
- package/src/components/navigations/Header.tsx +27 -0
- package/src/components/navigations/ModeToggleSwitch.tsx +25 -0
- package/src/components/navigations/PageSection.tsx +64 -0
- package/src/components/navigations/RecentPagesNavigator.tsx +52 -0
- package/src/components/navigations/index.ts +6 -0
- package/src/components/pages/PageContainerContentDetails.tsx +76 -0
- package/src/components/pages/PageContentContainer.tsx +31 -0
- package/src/components/pages/index.ts +2 -0
- package/src/components/tables/ContentListTable.tsx +165 -0
- package/src/components/tables/ContentTableSearch.tsx +105 -0
- package/src/components/tables/cells/cell.component.tsx +18 -0
- package/src/components/tables/cells/cell.date.tsx +16 -0
- package/src/components/tables/cells/cell.id.tsx +27 -0
- package/src/components/tables/cells/cell.link.tsx +18 -0
- package/src/components/tables/cells/cell.text.tsx +12 -0
- package/src/components/tables/cells/cell.url.tsx +13 -0
- package/src/components/tables/cells/index.ts +5 -0
- package/src/components/tables/index.ts +3 -0
- package/src/contexts/SharedContext.tsx +35 -0
- package/src/contexts/index.ts +2 -0
- package/src/core/abstracts/AbstractApiData.ts +138 -0
- package/src/core/abstracts/AbstractService.ts +263 -0
- package/src/core/abstracts/index.ts +2 -0
- package/src/core/endpoint/EndpointCreator.ts +97 -0
- package/src/core/endpoint/index.ts +1 -0
- package/src/core/factories/JsonApiDataFactory.ts +12 -0
- package/src/core/factories/RehydrationFactory.ts +30 -0
- package/src/core/factories/index.ts +2 -0
- package/src/core/fields/FieldSelector.ts +15 -0
- package/src/core/fields/index.ts +1 -0
- package/src/core/index.ts +20 -0
- package/src/core/interfaces/ApiData.ts +8 -0
- package/src/core/interfaces/ApiDataInterface.ts +15 -0
- package/src/core/interfaces/ApiRequestDataTypeInterface.ts +14 -0
- package/src/core/interfaces/ApiResponseInterface.ts +17 -0
- package/src/core/interfaces/JsonApiHydratedDataInterface.ts +5 -0
- package/src/core/interfaces/index.ts +5 -0
- package/src/core/registry/DataClassRegistry.ts +51 -0
- package/src/core/registry/ModuleRegistrar.ts +43 -0
- package/src/core/registry/ModuleRegistry.ts +64 -0
- package/src/core/registry/index.ts +3 -0
- package/src/core/utils/index.ts +2 -0
- package/src/core/utils/rehydrate.ts +24 -0
- package/src/core/utils/translateResponse.ts +125 -0
- package/src/features/auth/auth.module.ts +9 -0
- package/src/features/auth/config.ts +57 -0
- package/src/features/auth/data/auth.interface.ts +31 -0
- package/src/features/auth/data/auth.service.ts +159 -0
- package/src/features/auth/data/auth.ts +54 -0
- package/src/features/auth/data/index.ts +3 -0
- package/src/features/auth/index.ts +3 -0
- package/src/features/company/company.module.ts +10 -0
- package/src/features/company/data/company.fields.ts +6 -0
- package/src/features/company/data/company.interface.ts +28 -0
- package/src/features/company/data/company.service.ts +73 -0
- package/src/features/company/data/company.ts +104 -0
- package/src/features/company/data/index.ts +4 -0
- package/src/features/company/index.ts +2 -0
- package/src/features/content/content.module.ts +20 -0
- package/src/features/content/data/content.fields.ts +13 -0
- package/src/features/content/data/content.interface.ts +23 -0
- package/src/features/content/data/content.service.ts +75 -0
- package/src/features/content/data/content.ts +85 -0
- package/src/features/content/data/index.ts +4 -0
- package/src/features/content/index.ts +2 -0
- package/src/features/feature/components/forms/FormFeatures.tsx +149 -0
- package/src/features/feature/components/index.ts +1 -0
- package/src/features/feature/data/feature.interface.ts +9 -0
- package/src/features/feature/data/feature.service.ts +19 -0
- package/src/features/feature/data/feature.ts +33 -0
- package/src/features/feature/data/index.ts +3 -0
- package/src/features/feature/feature.module.ts +10 -0
- package/src/features/feature/index.ts +3 -0
- package/src/features/index.ts +12 -0
- package/src/features/module/data/index.ts +2 -0
- package/src/features/module/data/module.interface.ts +12 -0
- package/src/features/module/data/module.ts +42 -0
- package/src/features/module/index.ts +2 -0
- package/src/features/module/module.module.ts +10 -0
- package/src/features/notification/data/index.ts +4 -0
- package/src/features/notification/data/notification.fields.ts +8 -0
- package/src/features/notification/data/notification.interface.ts +14 -0
- package/src/features/notification/data/notification.service.ts +34 -0
- package/src/features/notification/data/notification.ts +51 -0
- package/src/features/notification/index.ts +2 -0
- package/src/features/notification/notification.module.ts +10 -0
- package/src/features/push/data/index.ts +3 -0
- package/src/features/push/data/push.interface.ts +8 -0
- package/src/features/push/data/push.service.ts +17 -0
- package/src/features/push/data/push.ts +18 -0
- package/src/features/push/index.ts +2 -0
- package/src/features/push/push.module.ts +10 -0
- package/src/features/role/data/index.ts +4 -0
- package/src/features/role/data/role.fields.ts +8 -0
- package/src/features/role/data/role.interface.ts +16 -0
- package/src/features/role/data/role.service.ts +117 -0
- package/src/features/role/data/role.ts +62 -0
- package/src/features/role/index.ts +2 -0
- package/src/features/role/role.module.ts +10 -0
- package/src/features/s3/data/index.ts +3 -0
- package/src/features/s3/data/s3.interface.ts +11 -0
- package/src/features/s3/data/s3.service.ts +30 -0
- package/src/features/s3/data/s3.ts +60 -0
- package/src/features/s3/index.ts +2 -0
- package/src/features/s3/s3.module.ts +10 -0
- package/src/features/search/index.ts +1 -0
- package/src/features/search/interfaces/index.ts +1 -0
- package/src/features/search/interfaces/search.result.interface.ts +3 -0
- package/src/features/user/author.module.ts +10 -0
- package/src/features/user/components/index.ts +2 -0
- package/src/features/user/components/lists/ContributorsList.tsx +41 -0
- package/src/features/user/components/lists/index.ts +1 -0
- package/src/features/user/components/widgets/UserAvatar.tsx +86 -0
- package/src/features/user/components/widgets/index.ts +1 -0
- package/src/features/user/contexts/CurrentUserContext.tsx +156 -0
- package/src/features/user/contexts/index.ts +1 -0
- package/src/features/user/data/index.ts +4 -0
- package/src/features/user/data/user.fields.ts +8 -0
- package/src/features/user/data/user.interface.ts +41 -0
- package/src/features/user/data/user.service.ts +246 -0
- package/src/features/user/data/user.ts +162 -0
- package/src/features/user/index.ts +4 -0
- package/src/features/user/user.module.ts +21 -0
- package/src/hooks/TableGeneratorRegistry.ts +53 -0
- package/src/hooks/index.ts +33 -0
- package/src/hooks/types.ts +35 -0
- package/src/hooks/url.rewriter.ts +22 -0
- package/src/hooks/useCustomD3Graph.tsx +705 -0
- package/src/hooks/useDataListRetriever.ts +349 -0
- package/src/hooks/useDebounce.ts +33 -0
- package/src/hooks/usePageUrlGenerator.ts +50 -0
- package/src/hooks/useTableGenerator.ts +16 -0
- package/src/i18n/config.ts +73 -0
- package/src/i18n/index.ts +18 -0
- package/src/index.ts +16 -0
- package/src/interfaces/breadcrumb.item.data.interface.ts +4 -0
- package/src/interfaces/d3.link.interface.ts +7 -0
- package/src/interfaces/d3.node.interface.ts +12 -0
- package/src/interfaces/index.ts +3 -0
- package/src/permissions/check.ts +127 -0
- package/src/permissions/index.ts +2 -0
- package/src/permissions/types.ts +109 -0
- package/src/roles/config.ts +46 -0
- package/src/roles/index.ts +1 -0
- package/src/server/cache.ts +28 -0
- package/src/server/index.ts +3 -0
- package/src/server/request.ts +113 -0
- package/src/server/token.ts +10 -0
- package/src/shadcnui/custom/kanban.tsx +1001 -0
- package/src/shadcnui/custom/link.tsx +18 -0
- package/src/shadcnui/custom/multi-select.tsx +382 -0
- package/src/shadcnui/index.ts +49 -0
- package/src/shadcnui/ui/accordion.tsx +52 -0
- package/src/shadcnui/ui/alert-dialog.tsx +141 -0
- package/src/shadcnui/ui/alert.tsx +43 -0
- package/src/shadcnui/ui/avatar.tsx +50 -0
- package/src/shadcnui/ui/badge.tsx +40 -0
- package/src/shadcnui/ui/breadcrumb.tsx +115 -0
- package/src/shadcnui/ui/button.tsx +51 -0
- package/src/shadcnui/ui/calendar.tsx +73 -0
- package/src/shadcnui/ui/card.tsx +43 -0
- package/src/shadcnui/ui/carousel.tsx +225 -0
- package/src/shadcnui/ui/chart.tsx +320 -0
- package/src/shadcnui/ui/checkbox.tsx +29 -0
- package/src/shadcnui/ui/collapsible.tsx +11 -0
- package/src/shadcnui/ui/command.tsx +155 -0
- package/src/shadcnui/ui/context-menu.tsx +179 -0
- package/src/shadcnui/ui/dialog.tsx +96 -0
- package/src/shadcnui/ui/drawer.tsx +89 -0
- package/src/shadcnui/ui/dropdown-menu.tsx +205 -0
- package/src/shadcnui/ui/form.tsx +138 -0
- package/src/shadcnui/ui/hover-card.tsx +29 -0
- package/src/shadcnui/ui/input.tsx +21 -0
- package/src/shadcnui/ui/label.tsx +26 -0
- package/src/shadcnui/ui/navigation-menu.tsx +168 -0
- package/src/shadcnui/ui/popover.tsx +33 -0
- package/src/shadcnui/ui/progress.tsx +25 -0
- package/src/shadcnui/ui/radio-group.tsx +37 -0
- package/src/shadcnui/ui/resizable.tsx +47 -0
- package/src/shadcnui/ui/scroll-area.tsx +40 -0
- package/src/shadcnui/ui/select.tsx +164 -0
- package/src/shadcnui/ui/separator.tsx +28 -0
- package/src/shadcnui/ui/sheet.tsx +139 -0
- package/src/shadcnui/ui/sidebar.tsx +677 -0
- package/src/shadcnui/ui/skeleton.tsx +13 -0
- package/src/shadcnui/ui/slider.tsx +25 -0
- package/src/shadcnui/ui/sonner.tsx +25 -0
- package/src/shadcnui/ui/switch.tsx +31 -0
- package/src/shadcnui/ui/table.tsx +120 -0
- package/src/shadcnui/ui/tabs.tsx +55 -0
- package/src/shadcnui/ui/textarea.tsx +24 -0
- package/src/shadcnui/ui/toggle.tsx +39 -0
- package/src/shadcnui/ui/tooltip.tsx +61 -0
- package/src/unified/JsonApiRequest.ts +325 -0
- package/src/unified/index.ts +1 -0
- package/src/utils/blocknote-diff.util.ts +815 -0
- package/src/utils/blocknote-word-diff-renderer.util.ts +413 -0
- package/src/utils/cn.ts +6 -0
- package/src/utils/compose-refs.ts +61 -0
- package/src/utils/date-formatter.ts +53 -0
- package/src/utils/exists.ts +7 -0
- package/src/utils/index.ts +15 -0
- package/src/utils/schemas/entity.object.schema.ts +8 -0
- package/src/utils/schemas/index.ts +2 -0
- package/src/utils/schemas/user.object.schema.ts +9 -0
- package/src/utils/table-options.ts +67 -0
- package/src/utils/use-mobile.tsx +21 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { ApiDataInterface } from "../interfaces/ApiDataInterface";
|
|
2
|
+
import { ApiRequestDataTypeInterface } from "../interfaces/ApiRequestDataTypeInterface";
|
|
3
|
+
|
|
4
|
+
export class DataClassRegistry {
|
|
5
|
+
private static _map = new Map<string, { new (): ApiDataInterface }>();
|
|
6
|
+
|
|
7
|
+
public static registerObjectClass(
|
|
8
|
+
key: ApiRequestDataTypeInterface,
|
|
9
|
+
classConstructor: { new (): ApiDataInterface },
|
|
10
|
+
): void {
|
|
11
|
+
const classKey = key.name;
|
|
12
|
+
if (!this._map.has(classKey)) {
|
|
13
|
+
this._map.set(classKey, classConstructor);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public static get(classKey: ApiRequestDataTypeInterface): {
|
|
18
|
+
new (): ApiDataInterface;
|
|
19
|
+
} {
|
|
20
|
+
const response = this._map.get(classKey.name);
|
|
21
|
+
if (!response) {
|
|
22
|
+
throw new Error(`Class not registered for key: ${typeof classKey === "string" ? classKey : classKey.name}`);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return response;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Bootstrap the registry with all modules.
|
|
30
|
+
* This is a convenience method for apps to register all their modules at once.
|
|
31
|
+
*
|
|
32
|
+
* @param modules - An object with module definitions (like the app's Modules class)
|
|
33
|
+
*/
|
|
34
|
+
public static bootstrap(modules: Record<string, ApiRequestDataTypeInterface>): void {
|
|
35
|
+
Object.values(modules).forEach((module) => {
|
|
36
|
+
if (module && module.model) {
|
|
37
|
+
this.registerObjectClass(module, module.model);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Clear all registered classes. Useful for testing.
|
|
44
|
+
*/
|
|
45
|
+
public static clear(): void {
|
|
46
|
+
this._map.clear();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Export alias for backward compatibility
|
|
51
|
+
export { DataClassRegistry as DataClass };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { ApiRequestDataTypeInterface } from "../interfaces/ApiRequestDataTypeInterface";
|
|
2
|
+
import { DataClassRegistry } from "./DataClassRegistry";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Helper class to bootstrap the registry from a Modules-style class.
|
|
6
|
+
* This supports the pattern where modules are defined as static getters.
|
|
7
|
+
*/
|
|
8
|
+
export class ModuleRegistrar {
|
|
9
|
+
private static _isBootstrapped = false;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Bootstrap the registry from a Modules class.
|
|
13
|
+
* Automatically detects static getters and registers their models.
|
|
14
|
+
*
|
|
15
|
+
* @param modulesClass - The Modules class with static getters
|
|
16
|
+
*/
|
|
17
|
+
static bootstrap<T extends object>(modulesClass: T): void {
|
|
18
|
+
if (this._isBootstrapped) return;
|
|
19
|
+
|
|
20
|
+
const data = Object.getOwnPropertyNames(modulesClass)
|
|
21
|
+
.filter((key) => {
|
|
22
|
+
const descriptor = Object.getOwnPropertyDescriptor(modulesClass, key);
|
|
23
|
+
return descriptor && typeof descriptor.get === "function";
|
|
24
|
+
})
|
|
25
|
+
.map((key) => (modulesClass as any)[key] as ApiRequestDataTypeInterface);
|
|
26
|
+
|
|
27
|
+
data.forEach((item) => {
|
|
28
|
+
if (item && item.model) {
|
|
29
|
+
DataClassRegistry.registerObjectClass(item, item.model);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
this._isBootstrapped = true;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Reset the bootstrapped state. Useful for testing.
|
|
38
|
+
*/
|
|
39
|
+
static reset(): void {
|
|
40
|
+
this._isBootstrapped = false;
|
|
41
|
+
DataClassRegistry.clear();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { ApiRequestDataTypeInterface } from "../interfaces/ApiRequestDataTypeInterface";
|
|
2
|
+
import { ModuleWithPermissions } from "../../permissions/types";
|
|
3
|
+
|
|
4
|
+
// Foundation module types - defined by LIBRARY
|
|
5
|
+
export interface FoundationModuleDefinitions {
|
|
6
|
+
S3: ModuleWithPermissions;
|
|
7
|
+
Auth: ModuleWithPermissions;
|
|
8
|
+
User: ModuleWithPermissions;
|
|
9
|
+
Author: ModuleWithPermissions;
|
|
10
|
+
Company: ModuleWithPermissions;
|
|
11
|
+
Role: ModuleWithPermissions;
|
|
12
|
+
Notification: ModuleWithPermissions;
|
|
13
|
+
Push: ModuleWithPermissions;
|
|
14
|
+
Feature: ModuleWithPermissions;
|
|
15
|
+
Module: ModuleWithPermissions;
|
|
16
|
+
Content: ModuleWithPermissions;
|
|
17
|
+
UserTopic: ModuleWithPermissions;
|
|
18
|
+
UserExpertise: ModuleWithPermissions;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// App-specific modules - apps will augment this interface ONLY
|
|
22
|
+
|
|
23
|
+
export interface AppModuleDefinitions {}
|
|
24
|
+
|
|
25
|
+
// Combined type for full autocompletion
|
|
26
|
+
export type ModuleDefinitions = FoundationModuleDefinitions & AppModuleDefinitions;
|
|
27
|
+
|
|
28
|
+
class ModuleRegistryClass {
|
|
29
|
+
private _modules: Map<string, ApiRequestDataTypeInterface> = new Map();
|
|
30
|
+
|
|
31
|
+
register<K extends string>(name: K, module: ApiRequestDataTypeInterface): void {
|
|
32
|
+
this._modules.set(name, module);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
get<K extends keyof ModuleDefinitions>(name: K): ModuleDefinitions[K] {
|
|
36
|
+
const module = this._modules.get(name as string);
|
|
37
|
+
if (!module) {
|
|
38
|
+
throw new Error(`Module "${String(name)}" not registered. Call bootstrap() first.`);
|
|
39
|
+
}
|
|
40
|
+
return module as ModuleDefinitions[K];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
findByName(moduleName: string): ModuleWithPermissions {
|
|
44
|
+
// Search by module's name property (e.g., "topics", "articles")
|
|
45
|
+
for (const module of this._modules.values()) {
|
|
46
|
+
if ((module as ModuleWithPermissions).name === moduleName) {
|
|
47
|
+
return module as ModuleWithPermissions;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
throw new Error(`Module not found: ${moduleName}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export const ModuleRegistry = new ModuleRegistryClass();
|
|
55
|
+
|
|
56
|
+
// Proxy object for Modules.X syntax with autocompletion
|
|
57
|
+
export const Modules = new Proxy({} as ModuleDefinitions, {
|
|
58
|
+
get(_, prop: string) {
|
|
59
|
+
if (prop === "findByName") {
|
|
60
|
+
return (name: string) => ModuleRegistry.findByName(name);
|
|
61
|
+
}
|
|
62
|
+
return ModuleRegistry.get(prop as keyof ModuleDefinitions);
|
|
63
|
+
},
|
|
64
|
+
}) as ModuleDefinitions & { findByName: (name: string) => ModuleWithPermissions };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ApiDataInterface } from "../interfaces/ApiDataInterface";
|
|
2
|
+
import { ApiRequestDataTypeInterface } from "../interfaces/ApiRequestDataTypeInterface";
|
|
3
|
+
import { JsonApiHydratedDataInterface } from "../interfaces/JsonApiHydratedDataInterface";
|
|
4
|
+
import { RehydrationFactory } from "../factories/RehydrationFactory";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Rehydrate a single dehydrated object back into its typed class instance.
|
|
8
|
+
*/
|
|
9
|
+
export function rehydrate<T extends ApiDataInterface>(
|
|
10
|
+
classKey: ApiRequestDataTypeInterface,
|
|
11
|
+
data: JsonApiHydratedDataInterface,
|
|
12
|
+
): T {
|
|
13
|
+
return RehydrationFactory.rehydrate(classKey, data) as T;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Rehydrate a list of dehydrated objects back into typed class instances.
|
|
18
|
+
*/
|
|
19
|
+
export function rehydrateList<T extends ApiDataInterface>(
|
|
20
|
+
classKey: ApiRequestDataTypeInterface,
|
|
21
|
+
data: JsonApiHydratedDataInterface[],
|
|
22
|
+
): T[] {
|
|
23
|
+
return RehydrationFactory.rehydrateList(classKey, data) as T[];
|
|
24
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { ApiData } from "../interfaces/ApiData";
|
|
2
|
+
import { ApiDataInterface } from "../interfaces/ApiDataInterface";
|
|
3
|
+
import { ApiRequestDataTypeInterface } from "../interfaces/ApiRequestDataTypeInterface";
|
|
4
|
+
import { ApiResponseInterface } from "../interfaces/ApiResponseInterface";
|
|
5
|
+
import { DataClassRegistry } from "../registry/DataClassRegistry";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Translates raw JSON:API data into typed objects.
|
|
9
|
+
* Does not require API response metadata.
|
|
10
|
+
*/
|
|
11
|
+
export function translateData<T extends ApiDataInterface>(params: {
|
|
12
|
+
classKey: ApiRequestDataTypeInterface;
|
|
13
|
+
data: any;
|
|
14
|
+
}): T | T[] {
|
|
15
|
+
const factoryClass = DataClassRegistry.get(params.classKey);
|
|
16
|
+
|
|
17
|
+
if (!factoryClass) {
|
|
18
|
+
throw new Error(
|
|
19
|
+
`Class not registered for key: ${typeof params.classKey === "string" ? params.classKey : params.classKey.name}`,
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const included: any = params.data.included ?? [];
|
|
24
|
+
|
|
25
|
+
if (Array.isArray(params.data.data)) {
|
|
26
|
+
const responseData: T[] = [];
|
|
27
|
+
|
|
28
|
+
for (const data of params.data.data) {
|
|
29
|
+
const object = new factoryClass();
|
|
30
|
+
object.rehydrate({ jsonApi: data, included: included, allData: params.data.data });
|
|
31
|
+
responseData.push(object as T);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return responseData as T[];
|
|
35
|
+
} else {
|
|
36
|
+
const responseData = new factoryClass();
|
|
37
|
+
responseData.rehydrate({
|
|
38
|
+
jsonApi: params.data.data,
|
|
39
|
+
included: included,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
return responseData as T;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Translates a full API response into a typed ApiResponseInterface.
|
|
48
|
+
* Includes pagination support.
|
|
49
|
+
*/
|
|
50
|
+
export async function translateResponse<T extends ApiDataInterface>(params: {
|
|
51
|
+
classKey: ApiRequestDataTypeInterface;
|
|
52
|
+
apiResponse: ApiData;
|
|
53
|
+
companyId?: string;
|
|
54
|
+
language: string;
|
|
55
|
+
paginationHandler?: (endpoint: string) => Promise<ApiResponseInterface>;
|
|
56
|
+
}): Promise<ApiResponseInterface> {
|
|
57
|
+
const response: ApiResponseInterface = {
|
|
58
|
+
ok: true,
|
|
59
|
+
response: 0,
|
|
60
|
+
data: [],
|
|
61
|
+
error: "",
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const factoryClass = DataClassRegistry.get(params.classKey);
|
|
65
|
+
|
|
66
|
+
if (!factoryClass) {
|
|
67
|
+
throw new Error(
|
|
68
|
+
`Class not registered for key: ${typeof params.classKey === "string" ? params.classKey : params.classKey.name}`,
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
response.ok = params.apiResponse.ok;
|
|
73
|
+
response.response = params.apiResponse.status;
|
|
74
|
+
|
|
75
|
+
if (!params.apiResponse.ok) {
|
|
76
|
+
response.error = params.apiResponse?.data?.message ?? params.apiResponse.statusText;
|
|
77
|
+
return response;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (params.apiResponse.status === 204) return response;
|
|
81
|
+
|
|
82
|
+
response.raw = params.apiResponse.data;
|
|
83
|
+
|
|
84
|
+
try {
|
|
85
|
+
const included: any = params.apiResponse.data.included ?? [];
|
|
86
|
+
|
|
87
|
+
if (params.apiResponse.data.links) {
|
|
88
|
+
response.self = params.apiResponse.data.links.self;
|
|
89
|
+
|
|
90
|
+
if (params.apiResponse.data.links.next && params.paginationHandler) {
|
|
91
|
+
response.next = params.apiResponse.data.links.next;
|
|
92
|
+
response.nextPage = async () => params.paginationHandler!(params.apiResponse.data.links.next);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (params.apiResponse.data.links.prev && params.paginationHandler) {
|
|
96
|
+
response.prev = params.apiResponse.data.links.prev;
|
|
97
|
+
response.prevPage = async () => params.paginationHandler!(params.apiResponse.data.links.prev);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (Array.isArray(params.apiResponse.data.data)) {
|
|
102
|
+
const responseData: T[] = [];
|
|
103
|
+
|
|
104
|
+
for (const data of params.apiResponse.data.data) {
|
|
105
|
+
const object = new factoryClass();
|
|
106
|
+
object.rehydrate({ jsonApi: data, included: included, allData: params.apiResponse.data.data });
|
|
107
|
+
responseData.push(object as T);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
response.data = responseData;
|
|
111
|
+
} else {
|
|
112
|
+
const responseData = new factoryClass();
|
|
113
|
+
responseData.rehydrate({
|
|
114
|
+
jsonApi: params.apiResponse.data.data,
|
|
115
|
+
included: included,
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
response.data = responseData;
|
|
119
|
+
}
|
|
120
|
+
} catch (e) {
|
|
121
|
+
console.error(e);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return response;
|
|
125
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Token parameters for authentication cookie management
|
|
3
|
+
*/
|
|
4
|
+
export interface TokenParams {
|
|
5
|
+
token?: string;
|
|
6
|
+
refreshToken?: string;
|
|
7
|
+
userId?: string;
|
|
8
|
+
companyId?: string;
|
|
9
|
+
licenseExpirationDate?: Date;
|
|
10
|
+
roles?: string[];
|
|
11
|
+
features?: string[];
|
|
12
|
+
modules?: {
|
|
13
|
+
id: string;
|
|
14
|
+
permissions: {
|
|
15
|
+
create: boolean | string;
|
|
16
|
+
read: boolean | string;
|
|
17
|
+
update: boolean | string;
|
|
18
|
+
delete: boolean | string;
|
|
19
|
+
};
|
|
20
|
+
}[];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Token handler interface for dependency injection
|
|
25
|
+
* Apps must provide implementations of these functions via configureAuth()
|
|
26
|
+
*/
|
|
27
|
+
export interface TokenHandler {
|
|
28
|
+
updateToken: (params: TokenParams) => Promise<void>;
|
|
29
|
+
removeToken: () => Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Private storage for the injected token handler
|
|
33
|
+
let _tokenHandler: TokenHandler | null = null;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Configure authentication token handling
|
|
37
|
+
* Call this at app startup to provide Server Actions for cookie management
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* import { configureAuth } from "@carlonicora/nextjs-jsonapi/features";
|
|
42
|
+
* import { updateToken, removeToken } from "@/features/auth/utils/AuthCookies";
|
|
43
|
+
*
|
|
44
|
+
* configureAuth({ updateToken, removeToken });
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export function configureAuth(handler: TokenHandler): void {
|
|
48
|
+
_tokenHandler = handler;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Internal getter for AuthService to access the token handler
|
|
53
|
+
* @internal
|
|
54
|
+
*/
|
|
55
|
+
export function getTokenHandler(): TokenHandler | null {
|
|
56
|
+
return _tokenHandler;
|
|
57
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ApiDataInterface } from "../../../core";
|
|
2
|
+
import { UserInterface } from "../../user";
|
|
3
|
+
|
|
4
|
+
export type AuthInput = {
|
|
5
|
+
id?: string;
|
|
6
|
+
email?: string | undefined | null;
|
|
7
|
+
password?: string | undefined;
|
|
8
|
+
name?: string;
|
|
9
|
+
companyName?: string;
|
|
10
|
+
partitaIva?: string;
|
|
11
|
+
codiceFiscale?: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type AuthQuery = {
|
|
15
|
+
userId?: string;
|
|
16
|
+
|
|
17
|
+
tokenCode?: string;
|
|
18
|
+
refreshToken?: string;
|
|
19
|
+
|
|
20
|
+
login?: boolean;
|
|
21
|
+
forgot?: boolean;
|
|
22
|
+
code?: string;
|
|
23
|
+
activationCode?: string;
|
|
24
|
+
checkUsername?: string;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export interface AuthInterface extends ApiDataInterface {
|
|
28
|
+
get token(): string;
|
|
29
|
+
get refreshToken(): string;
|
|
30
|
+
get user(): UserInterface;
|
|
31
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { AuthInput, AuthInterface } from ".";
|
|
2
|
+
import { JsonApiDelete, JsonApiGet, JsonApiPost } from "../../../";
|
|
3
|
+
import {
|
|
4
|
+
AbstractService,
|
|
5
|
+
ApiResponseInterface,
|
|
6
|
+
EndpointCreator,
|
|
7
|
+
HttpMethod,
|
|
8
|
+
JsonApiHydratedDataInterface,
|
|
9
|
+
Modules,
|
|
10
|
+
rehydrate,
|
|
11
|
+
} from "../../../core";
|
|
12
|
+
import { UserInterface } from "../../user";
|
|
13
|
+
import { getTokenHandler } from "../config";
|
|
14
|
+
|
|
15
|
+
export class AuthService extends AbstractService {
|
|
16
|
+
static async login(params: { email: string; password: string; language?: string }): Promise<UserInterface> {
|
|
17
|
+
const language = params.language || "en-US";
|
|
18
|
+
|
|
19
|
+
const apiResponse: ApiResponseInterface = await JsonApiPost({
|
|
20
|
+
classKey: Modules.Auth,
|
|
21
|
+
endpoint: new EndpointCreator({ endpoint: Modules.Auth, id: "login" }).generate(),
|
|
22
|
+
body: { email: params.email, password: params.password } as AuthInput,
|
|
23
|
+
language: language,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
if (!apiResponse.ok) throw new Error(apiResponse.error);
|
|
27
|
+
|
|
28
|
+
const auth = apiResponse.data as AuthInterface;
|
|
29
|
+
|
|
30
|
+
// Use injected token handler if configured
|
|
31
|
+
const handler = getTokenHandler();
|
|
32
|
+
if (handler) {
|
|
33
|
+
await handler.updateToken({
|
|
34
|
+
token: auth.token,
|
|
35
|
+
refreshToken: auth.refreshToken,
|
|
36
|
+
userId: auth.user.id,
|
|
37
|
+
companyId: auth.user.company?.id,
|
|
38
|
+
licenseExpirationDate: auth.user.company?.licenseExpirationDate,
|
|
39
|
+
roles: auth.user.roles.map((role) => role.id),
|
|
40
|
+
features: auth.user.company?.features?.map((feature) => feature.id) ?? [],
|
|
41
|
+
modules: auth.user.modules.map((module) => ({
|
|
42
|
+
id: module.id,
|
|
43
|
+
permissions: module.permissions,
|
|
44
|
+
})),
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return auth.user;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
static async logout(params?: { language?: string }): Promise<void> {
|
|
52
|
+
const language = params?.language || "en-US";
|
|
53
|
+
|
|
54
|
+
await JsonApiDelete({
|
|
55
|
+
classKey: Modules.Auth,
|
|
56
|
+
endpoint: new EndpointCreator({ endpoint: Modules.Auth }).generate(),
|
|
57
|
+
language: language,
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// Use injected token handler if configured
|
|
61
|
+
const handler = getTokenHandler();
|
|
62
|
+
if (handler) {
|
|
63
|
+
await handler.removeToken();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
static async initialiseForgotPassword(params: { email: string; language?: string }): Promise<void> {
|
|
68
|
+
const language = params.language || "en-US";
|
|
69
|
+
|
|
70
|
+
const response: ApiResponseInterface = await JsonApiPost({
|
|
71
|
+
classKey: Modules.Auth,
|
|
72
|
+
endpoint: new EndpointCreator({ endpoint: Modules.Auth, id: "forgot" }).generate(),
|
|
73
|
+
body: { email: params.email } as AuthInput,
|
|
74
|
+
language: language,
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
if (!response.ok) {
|
|
78
|
+
throw new Error(response.error);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
static async register(params: AuthInput): Promise<void> {
|
|
83
|
+
const endpoint = new EndpointCreator({ endpoint: Modules.Auth, id: "register" });
|
|
84
|
+
|
|
85
|
+
await this.callApi({
|
|
86
|
+
type: Modules.Auth,
|
|
87
|
+
method: HttpMethod.POST,
|
|
88
|
+
endpoint: endpoint.generate(),
|
|
89
|
+
input: params,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
static async activate(params: { activationCode: string }): Promise<void> {
|
|
94
|
+
const endpoint = new EndpointCreator({
|
|
95
|
+
endpoint: Modules.Auth,
|
|
96
|
+
id: "activate",
|
|
97
|
+
childEndpoint: params.activationCode,
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
await this.callApi({ type: Modules.Auth, method: HttpMethod.POST, endpoint: endpoint.generate() });
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
static async validateCode(params: { code: string; language?: string }): Promise<void> {
|
|
104
|
+
const language = params.language || "en-US";
|
|
105
|
+
|
|
106
|
+
const apiResponse: ApiResponseInterface = await JsonApiGet({
|
|
107
|
+
classKey: Modules.Auth,
|
|
108
|
+
endpoint: new EndpointCreator({ endpoint: Modules.Auth, id: "validate", childEndpoint: params.code }).generate(),
|
|
109
|
+
language: language,
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
if (!apiResponse.ok) throw new Error(apiResponse.error);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
static async resetPassword(params: { code: string; password: string }): Promise<void> {
|
|
116
|
+
const endpoint = new EndpointCreator({ endpoint: Modules.Auth, id: "reset", childEndpoint: params.code });
|
|
117
|
+
|
|
118
|
+
const input: AuthInput = { password: params.password };
|
|
119
|
+
|
|
120
|
+
await this.callApi({ type: Modules.Auth, method: HttpMethod.POST, endpoint: endpoint.generate(), input: input });
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
static async acceptInvitation(params: { code: string; password: string }): Promise<void> {
|
|
124
|
+
const endpoint = new EndpointCreator({ endpoint: Modules.Auth, id: "invitation", childEndpoint: params.code });
|
|
125
|
+
|
|
126
|
+
const input: AuthInput = { password: params.password };
|
|
127
|
+
|
|
128
|
+
await this.callApi({ type: Modules.Auth, method: HttpMethod.POST, endpoint: endpoint.generate(), input: input });
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
static async findToken(params: { tokenCode: string }): Promise<AuthInterface> {
|
|
132
|
+
return await this.callApi<AuthInterface>({
|
|
133
|
+
type: Modules.Auth,
|
|
134
|
+
method: HttpMethod.POST,
|
|
135
|
+
endpoint: new EndpointCreator({ endpoint: Modules.Auth }).addAdditionalParam("code", params.tokenCode).generate(),
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
static async saveToken(params: { dehydratedAuth: JsonApiHydratedDataInterface }): Promise<void> {
|
|
140
|
+
const auth: AuthInterface = rehydrate(Modules.Auth, params.dehydratedAuth) as AuthInterface;
|
|
141
|
+
|
|
142
|
+
const handler = getTokenHandler();
|
|
143
|
+
if (handler) {
|
|
144
|
+
await handler.updateToken({
|
|
145
|
+
token: auth.token,
|
|
146
|
+
refreshToken: auth.refreshToken,
|
|
147
|
+
userId: auth.user.id,
|
|
148
|
+
companyId: auth.user.company?.id,
|
|
149
|
+
licenseExpirationDate: auth.user.company?.licenseExpirationDate,
|
|
150
|
+
roles: auth.user.roles.map((role) => role.id),
|
|
151
|
+
features: auth.user.company?.features?.map((feature) => feature.id) ?? [],
|
|
152
|
+
modules: auth.user.modules.map((module) => ({
|
|
153
|
+
id: module.id,
|
|
154
|
+
permissions: module.permissions,
|
|
155
|
+
})),
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { AbstractApiData, JsonApiHydratedDataInterface, Modules } from "../../../core";
|
|
2
|
+
import { UserInterface } from "../../user/data/user.interface";
|
|
3
|
+
import { AuthInput, AuthInterface } from "./auth.interface";
|
|
4
|
+
|
|
5
|
+
export class Auth extends AbstractApiData implements AuthInterface {
|
|
6
|
+
private _token?: string;
|
|
7
|
+
private _refreshToken?: string;
|
|
8
|
+
private _user?: UserInterface;
|
|
9
|
+
|
|
10
|
+
get token(): string {
|
|
11
|
+
if (!this._token) throw new Error("Token is not defined");
|
|
12
|
+
return this._token;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
get refreshToken(): string {
|
|
16
|
+
if (!this._refreshToken) throw new Error("Refresh token is not defined");
|
|
17
|
+
return this._refreshToken;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
get user(): UserInterface {
|
|
21
|
+
if (!this._user) throw new Error("User is not defined");
|
|
22
|
+
return this._user;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
rehydrate(data: JsonApiHydratedDataInterface): this {
|
|
26
|
+
super.rehydrate(data);
|
|
27
|
+
|
|
28
|
+
this._token = data.jsonApi.attributes.token ?? undefined;
|
|
29
|
+
this._refreshToken = data.jsonApi.attributes.refreshToken ?? undefined;
|
|
30
|
+
|
|
31
|
+
this._user = this._readIncluded(data, "user", Modules.User) as UserInterface;
|
|
32
|
+
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
createJsonApi(data: AuthInput) {
|
|
37
|
+
const response: any = {
|
|
38
|
+
data: {
|
|
39
|
+
type: Modules.Auth.name,
|
|
40
|
+
attributes: {},
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
if (data.id) response.data.id = data.id;
|
|
45
|
+
if (data.email !== undefined) response.data.attributes.email = data.email;
|
|
46
|
+
if (data.name !== undefined) response.data.attributes.name = data.name;
|
|
47
|
+
if (data.companyName !== undefined) response.data.attributes.companyName = data.companyName;
|
|
48
|
+
if (data.password !== undefined) response.data.attributes.password = data.password;
|
|
49
|
+
if (data.partitaIva !== undefined) response.data.attributes.partitaIva = data.partitaIva;
|
|
50
|
+
if (data.codiceFiscale !== undefined) response.data.attributes.codiceFiscale = data.codiceFiscale;
|
|
51
|
+
|
|
52
|
+
return response;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ModuleFactory } from "../../permissions";
|
|
2
|
+
import { Company } from ".";
|
|
3
|
+
|
|
4
|
+
export const CompanyModule = (factory: ModuleFactory) =>
|
|
5
|
+
factory({
|
|
6
|
+
pageUrl: "/companies",
|
|
7
|
+
name: "companies",
|
|
8
|
+
model: Company,
|
|
9
|
+
moduleId: "f9e77c8f-bfd1-4fd4-80b0-e1d891ab7113",
|
|
10
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ApiDataInterface } from "../../../core";
|
|
2
|
+
import { FeatureInterface } from "../../feature/data/feature.interface";
|
|
3
|
+
import { ModuleInterface } from "../../module/data/module.interface";
|
|
4
|
+
|
|
5
|
+
export type CompanyInput = {
|
|
6
|
+
id: string;
|
|
7
|
+
name?: string;
|
|
8
|
+
logo?: string;
|
|
9
|
+
configurations?: any;
|
|
10
|
+
|
|
11
|
+
license?: string;
|
|
12
|
+
privateKey?: string;
|
|
13
|
+
|
|
14
|
+
featureIds?: string[];
|
|
15
|
+
moduleIds?: string[];
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export interface CompanyInterface extends ApiDataInterface {
|
|
19
|
+
get name(): string;
|
|
20
|
+
get configurations(): any;
|
|
21
|
+
get logo(): string | undefined;
|
|
22
|
+
get logoUrl(): string | undefined;
|
|
23
|
+
|
|
24
|
+
get licenseExpirationDate(): Date | undefined;
|
|
25
|
+
|
|
26
|
+
get features(): FeatureInterface[];
|
|
27
|
+
get modules(): ModuleInterface[];
|
|
28
|
+
}
|