@go-mondo/identity-sdk 0.0.2-beta.3 → 0.0.2-beta.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.
Files changed (33) hide show
  1. package/.release-please-manifest.json +1 -1
  2. package/.tsbuildinfo/cjs.json +1 -1
  3. package/.tsbuildinfo/esm.json +1 -1
  4. package/CHANGELOG.md +7 -0
  5. package/dist/cjs/association/schema/association.d.ts +3 -3
  6. package/dist/cjs/authorization/permissions/schema.d.ts +4 -4
  7. package/dist/cjs/authorization/permissions/schema.d.ts.map +1 -1
  8. package/dist/cjs/authorization/permissions/schema.js +4 -2
  9. package/dist/cjs/common/schema/schema.d.ts +4 -0
  10. package/dist/cjs/common/schema/schema.d.ts.map +1 -1
  11. package/dist/cjs/common/schema/schema.js +10 -0
  12. package/dist/cjs/common/schema/sets.d.ts +1 -1
  13. package/dist/cjs/common/schema/sets.d.ts.map +1 -1
  14. package/dist/cjs/common/schema/sets.js +2 -2
  15. package/dist/cjs/customer/users/schema.d.ts +7 -8
  16. package/dist/cjs/customer/users/schema.d.ts.map +1 -1
  17. package/dist/cjs/customer/users/schema.js +25 -24
  18. package/dist/cjs/customer/users/schema.test.js +49 -0
  19. package/dist/esm/association/schema/association.d.ts +3 -3
  20. package/dist/esm/authorization/permissions/schema.d.ts +4 -4
  21. package/dist/esm/authorization/permissions/schema.d.ts.map +1 -1
  22. package/dist/esm/authorization/permissions/schema.js +4 -2
  23. package/dist/esm/common/schema/schema.d.ts +4 -0
  24. package/dist/esm/common/schema/schema.d.ts.map +1 -1
  25. package/dist/esm/common/schema/schema.js +6 -0
  26. package/dist/esm/common/schema/sets.d.ts +1 -1
  27. package/dist/esm/common/schema/sets.d.ts.map +1 -1
  28. package/dist/esm/common/schema/sets.js +1 -1
  29. package/dist/esm/customer/users/schema.d.ts +7 -8
  30. package/dist/esm/customer/users/schema.d.ts.map +1 -1
  31. package/dist/esm/customer/users/schema.js +24 -23
  32. package/dist/esm/customer/users/schema.test.js +49 -0
  33. package/package.json +1 -1
@@ -2,6 +2,7 @@ import { type } from 'arktype';
2
2
  import { AggregateSchema } from '../../common/schema/aggregate.js';
3
3
  import { OptionalDatePayloadSchema, OptionalDateSchema, RequiredDatePayloadSchema, RequiredDateSchema, } from '../../common/schema/dates.js';
4
4
  import { MetadataMapPropertySchema, MetadataPayloadPropertySchema, UpsertMetadataPayloadPropertySchema, } from '../../common/schema/metadata.js';
5
+ import { optionallyNullish, optionallyNullishToUndefined, optionallyUndefined, } from '../../common/schema/schema.js';
5
6
  import { generateUserId } from '../schema/utils.js';
6
7
  export const VerifiableAttribute = {
7
8
  EMAIL: 'email',
@@ -14,36 +15,36 @@ export const UserStatus = {
14
15
  };
15
16
  const UserStatusSchema = type.enumerated(UserStatus.ACTIVE, UserStatus.SUSPENDED, UserStatus.UNVERIFIED);
16
17
  export const UserNamePropertiesSchema = type({
17
- givenName: type('string | undefined').or('undefined').optional(),
18
- middleName: type('string | undefined').optional(),
19
- familyName: type('string | undefined').optional(),
20
- honorificPrefix: type('string | undefined').optional(),
21
- honorificSuffix: type('string | undefined').optional(),
18
+ givenName: optionallyNullishToUndefined(type('string')),
19
+ middleName: optionallyNullishToUndefined(type('string')),
20
+ familyName: optionallyNullishToUndefined(type('string')),
21
+ honorificPrefix: optionallyNullishToUndefined(type('string')),
22
+ honorificSuffix: optionallyNullishToUndefined(type('string')),
22
23
  });
23
- export const UpsertUserNamePropertiesSchema = type({
24
- givenName: type('string | undefined | null').optional(),
25
- middleName: type('string | undefined | null').optional(),
26
- familyName: type('string | undefined | null').optional(),
27
- honorificPrefix: type('string | undefined | null').optional(),
28
- honorificSuffix: type('string | undefined | null').optional(),
24
+ // export type UserNameProperties = typeof UserNamePropertiesSchema.inferOut;
25
+ export const UpdateUserNamePropertiesSchema = type({
26
+ givenName: optionallyNullish(type('string')),
27
+ middleName: optionallyNullish(type('string')),
28
+ familyName: optionallyNullish(type('string')),
29
+ honorificPrefix: optionallyNullish(type('string')),
30
+ honorificSuffix: optionallyNullish(type('string')),
29
31
  });
32
+ // type UpsertUserNameProperties = typeof UpdateUserNamePropertiesSchema.inferOut;
30
33
  export const UserIdSchema = type.string;
31
34
  export const UserIdPropertySchema = type({
32
35
  id: UserIdSchema,
33
36
  });
34
37
  export const RequiredEmailSchema = type('string.email');
35
38
  export const RequiredPhoneNumberSchema = type('string');
36
- const EmailSchema = RequiredEmailSchema.or('undefined').pipe((v) => v != null ? v : undefined);
37
- const PhoneNumberSchema = RequiredPhoneNumberSchema.or('undefined');
38
39
  export const VerifiedEmailOrPhonePropertiesSchema = type({
39
- email: EmailSchema.optional(),
40
- verifiedEmail: type('boolean').or('undefined').optional(),
41
- phoneNumber: PhoneNumberSchema.optional(),
42
- verifiedPhoneNumber: type('boolean').or('undefined').optional(),
40
+ email: optionallyNullishToUndefined(RequiredEmailSchema),
41
+ verifiedEmail: optionallyNullishToUndefined(type('boolean')),
42
+ phoneNumber: optionallyNullishToUndefined(RequiredPhoneNumberSchema),
43
+ verifiedPhoneNumber: optionallyNullishToUndefined(type('boolean')),
43
44
  });
44
45
  export const EmailOrPhonePropertiesSchema = type({
45
- email: EmailSchema.optional(),
46
- phoneNumber: PhoneNumberSchema.optional(),
46
+ email: optionallyNullishToUndefined(RequiredEmailSchema),
47
+ phoneNumber: optionallyNullishToUndefined(RequiredPhoneNumberSchema),
47
48
  });
48
49
  const UserRoleAssociationSchema = type('string[] | undefined');
49
50
  export const UserAssociationsSchema = type({
@@ -53,14 +54,14 @@ const BaseSchema = UserIdPropertySchema.and(UserNamePropertiesSchema)
53
54
  .and(VerifiedEmailOrPhonePropertiesSchema)
54
55
  .and({
55
56
  status: UserStatusSchema,
56
- roles: AggregateSchema.or(type.undefined).optional(),
57
+ roles: optionallyUndefined(AggregateSchema),
57
58
  });
58
59
  export const UserSchema = BaseSchema.and({
59
60
  lastLogin: OptionalDateSchema.optional(),
60
61
  createdAt: RequiredDateSchema,
61
62
  updatedAt: RequiredDateSchema,
62
- 'deletedAt?': OptionalDateSchema,
63
- 'deactivatedAt?': OptionalDateSchema,
63
+ deletedAt: OptionalDateSchema.optional(),
64
+ deactivatedAt: OptionalDateSchema.optional(),
64
65
  }).and(MetadataMapPropertySchema);
65
66
  export const UserPayloadSchema = BaseSchema.and({
66
67
  lastLogin: OptionalDatePayloadSchema.optional(),
@@ -80,7 +81,7 @@ export const InsertUserPayloadSchema = type({
80
81
  export const UpdateUserPayloadSchema = type({
81
82
  suspended: type.boolean.optional(),
82
83
  })
83
- .and(UpsertUserNamePropertiesSchema)
84
+ .and(UpdateUserNamePropertiesSchema)
84
85
  .and(UpsertMetadataPayloadPropertySchema);
85
86
  export const UserAssociationReferenceSchema = UserIdPropertySchema.and(UserNamePropertiesSchema).and(EmailOrPhonePropertiesSchema.and(type({
86
87
  status: UserStatusSchema,
@@ -51,5 +51,54 @@ describe('Customer - User', () => {
51
51
  expect(result).not.toBeInstanceOf(type.errors);
52
52
  expect(result?.metadata).to.null;
53
53
  });
54
+ test('should serialize nulls successfully', async () => {
55
+ const payload = {
56
+ id: '123',
57
+ status: 'unverified',
58
+ givenName: null,
59
+ middleName: null,
60
+ familyName: null,
61
+ honorificPrefix: null,
62
+ honorificSuffix: null,
63
+ email: null,
64
+ verifiedEmail: null,
65
+ phoneNumber: null,
66
+ verifiedPhoneNumber: null,
67
+ createdAt: '2025-04-02T03:50:40.812Z',
68
+ updatedAt: '2025-04-02T03:50:40.812Z',
69
+ };
70
+ const result = UserPayloadSchema(payload);
71
+ if (result instanceof type.errors) {
72
+ console.log(result.summary);
73
+ }
74
+ expect(result).not.toBeInstanceOf(type.errors);
75
+ });
76
+ test('should serialize nulls successfully', async () => {
77
+ const payload = {
78
+ id: '123',
79
+ status: 'unverified',
80
+ givenName: null,
81
+ middleName: null,
82
+ familyName: null,
83
+ honorificPrefix: null,
84
+ honorificSuffix: null,
85
+ email: null,
86
+ verifiedEmail: null,
87
+ phoneNumber: null,
88
+ verifiedPhoneNumber: null,
89
+ createdAt: '2025-04-02T03:50:40.812Z',
90
+ updatedAt: '2025-04-02T03:50:40.812Z',
91
+ };
92
+ const test = type({
93
+ foo: 'string.numeric.parse',
94
+ bar: 'number',
95
+ baz: 'string.date.iso.parse',
96
+ });
97
+ const result = UserPayloadSchema(payload);
98
+ if (result instanceof type.errors) {
99
+ console.log(result.summary);
100
+ }
101
+ expect(result).not.toBeInstanceOf(type.errors);
102
+ });
54
103
  });
55
104
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go-mondo/identity-sdk",
3
- "version": "0.0.2-beta.3",
3
+ "version": "0.0.2-beta.4",
4
4
  "type": "module",
5
5
  "description": "A node SDK for Mondo Identity",
6
6
  "license": "MIT",