@drax/identity-front 0.5.1 → 0.5.3
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.5.
|
|
6
|
+
"version": "0.5.3",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "./src/index.ts",
|
|
9
9
|
"module": "./src/index.ts",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@drax/common-front": "^0.5.1",
|
|
28
|
-
"@drax/crud-share": "^0.5.
|
|
28
|
+
"@drax/crud-share": "^0.5.3",
|
|
29
29
|
"@drax/identity-share": "^0.5.1"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"vite-plugin-dts": "^3.9.1",
|
|
49
49
|
"vitest": "^1.4.0"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "56ea5a743bce196d6322ae6c26ea5b041450d7a3"
|
|
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,7 +1,7 @@
|
|
|
1
1
|
import type {ITenant, ITenantBase} from "@drax/identity-share";
|
|
2
|
-
import type {
|
|
2
|
+
import type {IDraxCrudProvider} from "@drax/crud-share";
|
|
3
3
|
|
|
4
|
-
interface ITenantProvider extends
|
|
4
|
+
interface ITenantProvider extends IDraxCrudProvider<ITenant, ITenantBase, ITenantBase> {
|
|
5
5
|
fetchTenant(): Promise<ITenant[]>
|
|
6
6
|
}
|
|
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 {
|
|
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,9 +1,14 @@
|
|
|
1
1
|
import type {ITenantProvider} from "../interfaces/ITenantProvider";
|
|
2
2
|
import type {ITenant, ITenantBase} from "@drax/identity-share";
|
|
3
|
-
import type {
|
|
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({
|
|
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
|