@drax/identity-front 0.4.0 → 0.5.2

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/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.4.0",
6
+ "version": "0.5.2",
7
7
  "type": "module",
8
8
  "main": "./src/index.ts",
9
9
  "module": "./src/index.ts",
@@ -24,9 +24,9 @@
24
24
  "format": "prettier --write src/"
25
25
  },
26
26
  "dependencies": {
27
- "@drax/common-front": "^0.4.0",
28
- "@drax/common-share": "^0.4.0",
29
- "@drax/identity-share": "^0.4.0"
27
+ "@drax/common-front": "^0.5.1",
28
+ "@drax/crud-share": "^0.5.2",
29
+ "@drax/identity-share": "^0.5.1"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@rushstack/eslint-patch": "^1.8.0",
@@ -48,5 +48,5 @@
48
48
  "vite-plugin-dts": "^3.9.1",
49
49
  "vitest": "^1.4.0"
50
50
  },
51
- "gitHead": "481b302fe72f403abf092806ceca540dd2765dfa"
51
+ "gitHead": "6f854dbeb2af7bca32ed35bcec2f8e48790a73b9"
52
52
  }
@@ -0,0 +1,32 @@
1
+ import TenantSystem from "../system/TenantSystem.js";
2
+ import TenantGqlProvider from "../providers/gql/TenantGqlProvider.js";
3
+ import TenantRestClientProvider from "../providers/rest/TenantRestProvider.js";
4
+ import {HttpGqlClientFactory, HttpRestClientFactory} from "@drax/common-front"
5
+ const HTTP_TRANSPORT = import.meta.env.VITE_HTTP_TRANSPORT || 'REST';
6
+
7
+ class TenantSystemFactory{
8
+
9
+ static singleton: TenantSystem
10
+
11
+ static getInstance(httpTransport: string = HTTP_TRANSPORT): TenantSystem {
12
+ if(!TenantSystemFactory.singleton){
13
+ if(httpTransport === 'GRAPHQL') {
14
+ const httpGqlClient = HttpGqlClientFactory.getInstance()
15
+ const provider = new TenantGqlProvider(httpGqlClient)
16
+ TenantSystemFactory.singleton = new TenantSystem(provider)
17
+ } else if(httpTransport === 'REST') {
18
+ const httpRestClient = HttpRestClientFactory.getInstance()
19
+ const provider = new TenantRestClientProvider(httpRestClient)
20
+ TenantSystemFactory.singleton = new TenantSystem(provider)
21
+ }else{
22
+ throw new Error('TenantSystemFactory ERROR: Invalid HTTP_TRANSPORT environment variable')
23
+ }
24
+ }
25
+ return TenantSystemFactory.singleton
26
+ }
27
+
28
+ }
29
+
30
+
31
+ export default TenantSystemFactory
32
+ export {TenantSystemFactory}
@@ -8,6 +8,10 @@ const messages = {
8
8
  creating: "Creating Tenant",
9
9
  deleting: "Deleting Tenant",
10
10
  managing: 'Managing Tenant',
11
+ fields:{
12
+ id: 'ID',
13
+ name: 'Name'
14
+ }
11
15
  }
12
16
  },
13
17
  es: {
@@ -19,6 +23,10 @@ const messages = {
19
23
  creating: "Creando Tenant",
20
24
  deleting: "Eliminando Tenant",
21
25
  managing: 'Gestionando Tenant',
26
+ fields:{
27
+ id: 'ID',
28
+ name: 'Nombre'
29
+ }
22
30
  }
23
31
  }
24
32
  }
package/src/index.ts CHANGED
@@ -24,6 +24,7 @@ import RoleSystem from "./system/RoleSystem.js"
24
24
  import TenantRestProvider from "./providers/rest/TenantRestProvider.js";
25
25
  import TenantGqlProvider from "./providers/gql/TenantGqlProvider.js";
26
26
  import TenantSystem from "./system/TenantSystem.js"
27
+ import TenantSystemFactory from "./factory/TenantSystemFactory.js"
27
28
 
28
29
 
29
30
  import {IdentityI18nMessages} from "./i18n/index.js"
@@ -73,6 +74,9 @@ export {
73
74
  TenantSystem,
74
75
  UserApiKeySystem,
75
76
 
77
+ //Factory
78
+ TenantSystemFactory,
79
+
76
80
  //Helpers
77
81
  AuthHelper,
78
82
  jwtDecodeHelper,
@@ -1,5 +1,5 @@
1
1
  import type {IRole, IRoleBase} from "@drax/identity-share";
2
- import type {IDraxCrud} from "@drax/common-share";
2
+ import type {IDraxCrud} from "@drax/crud-share";
3
3
 
4
4
  interface IRoleProvider extends IDraxCrud<IRole, IRoleBase, IRoleBase>{
5
5
  fetchRole(): Promise<IRole[]>
@@ -1,7 +1,7 @@
1
1
  import type {ITenant, ITenantBase} from "@drax/identity-share";
2
- import type {IDraxCrud} from "@drax/common-share";
2
+ import type {IDraxCrudProvider} from "@drax/crud-share";
3
3
 
4
- interface ITenantProvider extends IDraxCrud<ITenant, ITenantBase, ITenantBase> {
4
+ interface ITenantProvider extends IDraxCrudProvider<ITenant, ITenantBase, ITenantBase> {
5
5
  fetchTenant(): Promise<ITenant[]>
6
6
  }
7
7
 
@@ -1,5 +1,5 @@
1
1
  import type {IUserApiKey, IUserApiKeyBase} from "@drax/identity-share";
2
- import type {IDraxCrud} from "@drax/common-share";
2
+ import type {IDraxCrud} from "@drax/crud-share";
3
3
 
4
4
  interface IUserApiKeyProvider extends IDraxCrud<IUserApiKey, IUserApiKeyBase, IUserApiKeyBase> {
5
5
  //findBySecret(): Promise<IUserApiKey[]>
@@ -1,5 +1,5 @@
1
1
  import type {IUser, IUserCreate, IUserUpdate} from "@drax/identity-share";
2
- import type {IDraxCrud} from "@drax/common-share";
2
+ import type {IDraxCrud} from "@drax/crud-share";
3
3
 
4
4
 
5
5
  interface IUserProvider extends IDraxCrud<IUser, IUserCreate, IUserUpdate>{
@@ -1,7 +1,7 @@
1
1
  import type {IGqlClient} from '@drax/common-front'
2
2
  import type {IRoleProvider} from "../../interfaces/IRoleProvider";
3
3
  import type {IRole, IRoleBase} from "@drax/identity-share";
4
- import type {IDraxPaginateOptions, IDraxPaginateResult} from "@drax/common-share";
4
+ import type {IDraxPaginateOptions, IDraxPaginateResult} from "@drax/crud-share";
5
5
 
6
6
 
7
7
  class RoleGqlProvider implements IRoleProvider {
@@ -1,7 +1,7 @@
1
1
  import type {IGqlClient} from '@drax/common-front'
2
2
  import type {ITenantProvider} from "../../interfaces/ITenantProvider";
3
3
  import type {ITenant, ITenantBase} from "@drax/identity-share";
4
- import type {IDraxPaginateOptions, IDraxPaginateResult} from "@drax/common-share";
4
+ import type {IDraxPaginateOptions, IDraxPaginateResult} from "@drax/crud-share";
5
5
 
6
6
 
7
7
  class TenantGqlProvider implements ITenantProvider {
@@ -1,7 +1,7 @@
1
1
  import type {IGqlClient} from '@drax/common-front'
2
2
  import type {IUserApiKeyProvider} from "../../interfaces/IUserApiKeyProvider";
3
3
  import type {IUserApiKey, IUserApiKeyBase} from "@drax/identity-share";
4
- import type {IDraxPaginateOptions, IDraxPaginateResult} from "@drax/common-share";
4
+ import type {IDraxPaginateOptions, IDraxPaginateResult} from "@drax/crud-share";
5
5
 
6
6
  class UserApiKeyGqlProvider implements IUserApiKeyProvider {
7
7
 
@@ -1,7 +1,7 @@
1
1
  import type {IGqlClient} from '@drax/common-front'
2
2
  import type {IUserProvider} from "../../interfaces/IUserProvider";
3
3
  import type {IUser, IUserCreate, IUserUpdate} from "@drax/identity-share";
4
- import type {IDraxPaginateOptions, IDraxPaginateResult} from "@drax/common-share";
4
+ import type {IDraxPaginateOptions, IDraxPaginateResult} from "@drax/crud-share";
5
5
 
6
6
  class UserGqlProvider implements IUserProvider {
7
7
 
@@ -1,7 +1,7 @@
1
1
  import type {IHttpClient} from '@drax/common-front'
2
2
  import type {IRoleProvider} from "../../interfaces/IRoleProvider.ts";
3
3
  import type {IRole, IRoleBase} from "@drax/identity-share";
4
- import type {IDraxPaginateOptions, IDraxPaginateResult} from "@drax/common-share";
4
+ import type {IDraxPaginateOptions, IDraxPaginateResult} from "@drax/crud-share";
5
5
 
6
6
  class RoleRestProvider implements IRoleProvider {
7
7
 
@@ -1,7 +1,12 @@
1
1
  import type {IHttpClient} from '@drax/common-front'
2
2
  import type {ITenantProvider} from "../../interfaces/ITenantProvider.ts";
3
3
  import type {ITenant, ITenantBase} from "@drax/identity-share";
4
- import type {IDraxPaginateOptions, IDraxPaginateResult} from "@drax/common-share";
4
+ import type {
5
+ IDraxCrudProviderExportResult,
6
+ IDraxExportOptions, IDraxFieldFilter,
7
+ IDraxPaginateOptions,
8
+ IDraxPaginateResult
9
+ } from "@drax/crud-share";
5
10
 
6
11
  class TenantRestProvider implements ITenantProvider {
7
12
 
@@ -44,6 +49,23 @@ class TenantRestProvider implements ITenantProvider {
44
49
 
45
50
  }
46
51
 
52
+ async export({
53
+ format = 'JSON',
54
+ headers = [],
55
+ separator = ';',
56
+ limit = 0,
57
+ orderBy = "",
58
+ order = false,
59
+ search = "",
60
+ filters = []
61
+ }: IDraxExportOptions): Promise<IDraxCrudProviderExportResult> {
62
+ const url = '/api/tenants/export'
63
+ const sFilters: string = filters.map((filter : IDraxFieldFilter ) => `${filter.field},${filter.operator},${filter.value}`).join('|')
64
+ const params: any = {format, headers, separator, limit, orderBy, order, search, filters: sFilters}
65
+ return await this.httpClient.get(url, {params}) as IDraxCrudProviderExportResult
66
+
67
+ }
68
+
47
69
 
48
70
  }
49
71
 
@@ -1,7 +1,7 @@
1
1
  import type {IHttpClient} from '@drax/common-front'
2
2
  import type {IUserApiKeyProvider} from "../../interfaces/IUserApiKeyProvider";
3
3
  import type {IUserApiKey, IUserApiKeyBase} from "@drax/identity-share";
4
- import type {IDraxPaginateOptions, IDraxPaginateResult} from "@drax/common-share";
4
+ import type {IDraxPaginateOptions, IDraxPaginateResult} from "@drax/crud-share";
5
5
 
6
6
 
7
7
  class UserApiKeyRestProvider implements IUserApiKeyProvider {
@@ -1,7 +1,7 @@
1
1
  import type {IHttpClient} from '@drax/common-front'
2
2
  import type {IUserProvider} from "../../interfaces/IUserProvider.ts";
3
3
  import type {IUser, IUserCreate, IUserUpdate} from "@drax/identity-share";
4
- import type {IDraxPaginateOptions, IDraxPaginateResult} from "@drax/common-share";
4
+ import type {IDraxPaginateOptions, IDraxPaginateResult} from "@drax/crud-share";
5
5
 
6
6
 
7
7
  class UserRestProvider implements IUserProvider {
@@ -1,6 +1,6 @@
1
1
  import type {IRoleProvider} from "../interfaces/IRoleProvider";
2
2
  import type {IRole, IRoleBase} from "@drax/identity-share";
3
- import type {IDraxPaginateResult} from "@drax/common-share";
3
+ import type {IDraxPaginateOptions, IDraxPaginateResult} from "@drax/crud-share";
4
4
 
5
5
 
6
6
  class RoleSystem implements IRoleProvider {
@@ -21,7 +21,7 @@ class RoleSystem implements IRoleProvider {
21
21
  return this._provider.fetchPermissions()
22
22
  }
23
23
 
24
- async paginate({page= 1, limit= 5, orderBy="", order=false, search = ""}): Promise<IDraxPaginateResult<IRole>> {
24
+ async paginate({page= 1, limit= 5, orderBy="", order=false, search = ""}: IDraxPaginateOptions): Promise<IDraxPaginateResult<IRole>> {
25
25
  return this._provider.paginate({page, limit, orderBy, order, search})
26
26
  }
27
27
 
@@ -1,9 +1,14 @@
1
1
  import type {ITenantProvider} from "../interfaces/ITenantProvider";
2
2
  import type {ITenant, ITenantBase} from "@drax/identity-share";
3
- import type {IDraxPaginateResult} from "@drax/common-share";
3
+ import type {
4
+ IDraxCrudProvider,
5
+ IDraxCrudProviderExportResult,
6
+ IDraxExportOptions,
7
+ IDraxPaginateOptions,
8
+ IDraxPaginateResult
9
+ } from "@drax/crud-share";
4
10
 
5
-
6
- class TenantSystem {
11
+ class TenantSystem implements IDraxCrudProvider<ITenant, ITenantBase, ITenantBase> {
7
12
 
8
13
  _provider: ITenantProvider
9
14
  prototype: string;
@@ -13,26 +18,60 @@ class TenantSystem {
13
18
  this.prototype = 'TenantSystem'
14
19
  }
15
20
 
16
- fetchTenant():Promise<any> {
21
+ fetchTenant(): Promise<any> {
17
22
  return this._provider.fetchTenant()
18
23
  }
19
24
 
20
- async paginate({page= 1, limit= 5, orderBy="", order=false, search = ""}):Promise<IDraxPaginateResult<ITenant>> {
25
+ async paginate({
26
+ page = 1,
27
+ limit = 5,
28
+ orderBy = "",
29
+ order = false,
30
+ search = ""
31
+ }: IDraxPaginateOptions): Promise<IDraxPaginateResult<ITenant>> {
21
32
  return this._provider.paginate({page, limit, orderBy, order, search})
22
33
  }
23
34
 
24
- async create(userPayload: ITenantBase):Promise<ITenant> {
35
+ async create(userPayload: ITenantBase): Promise<ITenant> {
25
36
  return this._provider.create(userPayload)
26
37
  }
27
38
 
28
- async update(id:string, userPayload: ITenantBase):Promise<ITenant> {
39
+ async update(id: string, userPayload: ITenantBase): Promise<ITenant> {
29
40
  return this._provider.update(id, userPayload)
30
41
  }
31
42
 
32
- async delete(id: string):Promise<any> {
43
+ async delete(id: string): Promise<any> {
33
44
  return this._provider.delete(id)
34
45
  }
35
46
 
47
+ async export({
48
+ format = 'JSON',
49
+ headers = [],
50
+ separator = ';',
51
+ limit = 0,
52
+ orderBy = "",
53
+ order = false,
54
+ search = "",
55
+ filters = []
56
+ }: IDraxExportOptions): Promise<IDraxCrudProviderExportResult> {
57
+
58
+ if(!this._provider.export){
59
+ throw new Error(`TenantSystem.provider does not support export`) // assuming we have a custom error for this case // replace with actual error handling as needed // see: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-1.html#error-handling-changes for more details on custom error classes in TypeScript 3.1+ // or use a library like 'ts-error' for a more robust and flexible error handling solution // or use a custom error type if you want to have a specific error type for this operation // or use a custom interface or class for the export result if you want to have a specific structure for the result // or use a custom function that returns the result if you want to have a specific function for the result // or use a custom interface or class if you want to have a specific structure for the result // or use a custom function that returns the result
60
+ }
61
+
62
+ return this._provider.export({
63
+ format,
64
+ headers,
65
+ separator,
66
+ limit,
67
+ orderBy,
68
+ order,
69
+ search,
70
+ filters
71
+ })
72
+ }
73
+
74
+
36
75
  }
37
76
 
38
77
  export default TenantSystem
@@ -1,6 +1,6 @@
1
1
  import type {IUserApiKeyProvider} from "../interfaces/IUserApiKeyProvider";
2
2
  import type {IUserApiKey, IUserApiKeyBase} from "@drax/identity-share";
3
- import type {IDraxPaginateResult} from "@drax/common-share";
3
+ import type {IDraxPaginateResult} from "@drax/crud-share";
4
4
 
5
5
 
6
6
  class UserApiKeySystem {
@@ -1,6 +1,6 @@
1
1
  import type {IUserProvider} from "../interfaces/IUserProvider";
2
2
  import type {IUser, IUserCreate, IUserUpdate} from "@drax/identity-share";
3
- import type {IDraxPaginateResult} from "@drax/common-share";
3
+ import type {IDraxPaginateResult} from "@drax/crud-share";
4
4
 
5
5
 
6
6
  class UserSystem {