@fiado/type-kit 3.665.0 → 3.667.0
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/_test_/unit/platformRbac/customerAccountDtos.test.ts +23 -4
- package/bin/platformRbac/dtos/EnsureCustomerAccountRequest.d.ts +4 -2
- package/bin/platformRbac/dtos/EnsureCustomerAccountRequest.js +9 -6
- package/package.json +1 -1
- package/src/platformRbac/dtos/EnsureCustomerAccountRequest.ts +10 -3
|
@@ -9,8 +9,6 @@ import type { UserProfileResponse } from '../../../src/platformRbac/dtos/UserPro
|
|
|
9
9
|
|
|
10
10
|
const BODY = {
|
|
11
11
|
phone: '+525512345678',
|
|
12
|
-
retailCustomerId: 'customer-1',
|
|
13
|
-
directoryId: 'directory-1',
|
|
14
12
|
displayName: 'Ana Pérez',
|
|
15
13
|
createdBy: 'wizard',
|
|
16
14
|
};
|
|
@@ -21,11 +19,32 @@ const propertiesWithError = async (body: object): Promise<string[]> => {
|
|
|
21
19
|
};
|
|
22
20
|
|
|
23
21
|
describe('EnsureCustomerAccountRequest', () => {
|
|
24
|
-
it('valida el body
|
|
22
|
+
it('valida el body mínimo', async () => {
|
|
25
23
|
expect(await propertiesWithError(BODY)).toEqual([]);
|
|
26
24
|
});
|
|
27
25
|
|
|
28
|
-
it
|
|
26
|
+
it('valida el body con customFields y roleId', async () => {
|
|
27
|
+
const full = { ...BODY, customFields: { store: 'luga-01' }, roleId: 'role-1' };
|
|
28
|
+
expect(await propertiesWithError(full)).toEqual([]);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it.each([{ store: 42 }, { store: null }, ['luga-01'], 'luga-01'])('rechaza customFields %p', async (customFields) => {
|
|
32
|
+
expect(await propertiesWithError({ ...BODY, customFields })).toEqual(['customFields']);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('rechaza roleId vacío cuando viene', async () => {
|
|
36
|
+
expect(await propertiesWithError({ ...BODY, roleId: '' })).toEqual(['roleId']);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('ya no expone los campos de SureKeep', () => {
|
|
40
|
+
const extra = { ...BODY, retailCustomerId: 'c', directoryId: 'd', externalId: 'e' };
|
|
41
|
+
const request = plainToInstance(EnsureCustomerAccountRequest, extra, { excludeExtraneousValues: true });
|
|
42
|
+
expect(request).not.toHaveProperty('retailCustomerId');
|
|
43
|
+
expect(request).not.toHaveProperty('directoryId');
|
|
44
|
+
expect(request).not.toHaveProperty('externalId');
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it.each(['displayName', 'createdBy'])('exige %s', async (field) => {
|
|
29
48
|
expect(await propertiesWithError({ ...BODY, [field]: '' })).toEqual([field]);
|
|
30
49
|
});
|
|
31
50
|
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/** Body de POST /internal/tenants/{tenantId}/customer-accounts. */
|
|
2
2
|
export declare class EnsureCustomerAccountRequest {
|
|
3
3
|
phone: string;
|
|
4
|
-
retailCustomerId: string;
|
|
5
|
-
directoryId: string;
|
|
6
4
|
displayName: string;
|
|
5
|
+
/** Campos declarados por la aplicación; RBAC los valida contra su catálogo. */
|
|
6
|
+
customFields?: Record<string, string>;
|
|
7
|
+
/** Si falta, RBAC asigna el rol con el permiso del portal. */
|
|
8
|
+
roleId?: string;
|
|
7
9
|
createdBy: string;
|
|
8
10
|
}
|
|
@@ -13,6 +13,7 @@ exports.EnsureCustomerAccountRequest = void 0;
|
|
|
13
13
|
const class_transformer_1 = require("class-transformer");
|
|
14
14
|
const class_validator_1 = require("class-validator");
|
|
15
15
|
const InputPatterns_1 = require("../../common/constants/InputPatterns");
|
|
16
|
+
const IsStringValueRecord_1 = require("../../common/validators/IsStringValueRecord");
|
|
16
17
|
/** Body de POST /internal/tenants/{tenantId}/customer-accounts. */
|
|
17
18
|
class EnsureCustomerAccountRequest {
|
|
18
19
|
}
|
|
@@ -28,19 +29,21 @@ __decorate([
|
|
|
28
29
|
(0, class_validator_1.IsString)(),
|
|
29
30
|
(0, class_validator_1.IsNotEmpty)(),
|
|
30
31
|
__metadata("design:type", String)
|
|
31
|
-
], EnsureCustomerAccountRequest.prototype, "
|
|
32
|
+
], EnsureCustomerAccountRequest.prototype, "displayName", void 0);
|
|
32
33
|
__decorate([
|
|
33
34
|
(0, class_transformer_1.Expose)(),
|
|
34
|
-
(0, class_validator_1.
|
|
35
|
-
(0, class_validator_1.
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
(0, class_validator_1.IsOptional)(),
|
|
36
|
+
(0, class_validator_1.IsObject)(),
|
|
37
|
+
(0, class_validator_1.Validate)(IsStringValueRecord_1.IsStringValueRecord, { message: 'customFields: todos los valores deben ser string' }),
|
|
38
|
+
__metadata("design:type", Object)
|
|
39
|
+
], EnsureCustomerAccountRequest.prototype, "customFields", void 0);
|
|
38
40
|
__decorate([
|
|
39
41
|
(0, class_transformer_1.Expose)(),
|
|
42
|
+
(0, class_validator_1.IsOptional)(),
|
|
40
43
|
(0, class_validator_1.IsString)(),
|
|
41
44
|
(0, class_validator_1.IsNotEmpty)(),
|
|
42
45
|
__metadata("design:type", String)
|
|
43
|
-
], EnsureCustomerAccountRequest.prototype, "
|
|
46
|
+
], EnsureCustomerAccountRequest.prototype, "roleId", void 0);
|
|
44
47
|
__decorate([
|
|
45
48
|
(0, class_transformer_1.Expose)(),
|
|
46
49
|
(0, class_validator_1.IsString)(),
|
package/package.json
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import { Expose } from 'class-transformer';
|
|
2
|
-
import { IsNotEmpty, IsString, Matches } from 'class-validator';
|
|
2
|
+
import { IsNotEmpty, IsObject, IsOptional, IsString, Matches, Validate } from 'class-validator';
|
|
3
3
|
import { PHONE_E164_PATTERN } from '../../common/constants/InputPatterns';
|
|
4
|
+
import { IsStringValueRecord } from '../../common/validators/IsStringValueRecord';
|
|
4
5
|
|
|
5
6
|
/** Body de POST /internal/tenants/{tenantId}/customer-accounts. */
|
|
6
7
|
export class EnsureCustomerAccountRequest {
|
|
7
8
|
@Expose() @IsString() @Matches(PHONE_E164_PATTERN) phone!: string;
|
|
8
|
-
@Expose() @IsString() @IsNotEmpty() retailCustomerId!: string;
|
|
9
|
-
@Expose() @IsString() @IsNotEmpty() directoryId!: string;
|
|
10
9
|
@Expose() @IsString() @IsNotEmpty() displayName!: string;
|
|
10
|
+
/** Campos declarados por la aplicación; RBAC los valida contra su catálogo. */
|
|
11
|
+
@Expose()
|
|
12
|
+
@IsOptional()
|
|
13
|
+
@IsObject()
|
|
14
|
+
@Validate(IsStringValueRecord, { message: 'customFields: todos los valores deben ser string' })
|
|
15
|
+
customFields?: Record<string, string>;
|
|
16
|
+
/** Si falta, RBAC asigna el rol con el permiso del portal. */
|
|
17
|
+
@Expose() @IsOptional() @IsString() @IsNotEmpty() roleId?: string;
|
|
11
18
|
@Expose() @IsString() @IsNotEmpty() createdBy!: string;
|
|
12
19
|
}
|