@go-mondo/identity-sdk 0.0.2-beta.73 → 0.0.2-beta.75
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/.release-please-manifest.json +1 -1
- package/.tsbuildinfo/cjs.json +1 -1
- package/.tsbuildinfo/esm.json +1 -1
- package/CHANGELOG.md +14 -0
- package/dist/cjs/app/authorization/schema.d.ts +0 -9
- package/dist/cjs/app/authorization/schema.d.ts.map +1 -1
- package/dist/cjs/common/schema/jwt.d.ts +0 -6
- package/dist/cjs/common/schema/jwt.d.ts.map +1 -1
- package/dist/cjs/common/schema/jwt.js +0 -3
- package/dist/cjs/common/schema/jwt.test.js +0 -8
- package/dist/cjs/customer/users/schema.d.ts +4 -4
- package/dist/cjs/customer/users/schema.d.ts.map +1 -1
- package/dist/cjs/customer/users/schema.js +8 -4
- package/dist/cjs/customer/users/schema.test.js +4 -4
- package/dist/cjs/workspace/authorization/schema.d.ts +0 -9
- package/dist/cjs/workspace/authorization/schema.d.ts.map +1 -1
- package/dist/esm/app/authorization/schema.d.ts +0 -9
- package/dist/esm/app/authorization/schema.d.ts.map +1 -1
- package/dist/esm/common/schema/jwt.d.ts +0 -6
- package/dist/esm/common/schema/jwt.d.ts.map +1 -1
- package/dist/esm/common/schema/jwt.js +0 -3
- package/dist/esm/common/schema/jwt.test.js +0 -8
- package/dist/esm/customer/users/schema.d.ts +4 -4
- package/dist/esm/customer/users/schema.d.ts.map +1 -1
- package/dist/esm/customer/users/schema.js +8 -4
- package/dist/esm/customer/users/schema.test.js +4 -4
- package/dist/esm/workspace/authorization/schema.d.ts +0 -9
- package/dist/esm/workspace/authorization/schema.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/action/schema/operations/sign-up-verification.test.ts.bak +0 -163
- package/src/action/schema/operations/sign-up.test.ts.bak +0 -203
- package/src/action/schema/operations/user-attribute-verification.test.ts.bak +0 -148
- package/src/activity/schema/base.test.ts.bak +0 -291
- package/src/activity/schema/schema.test.ts.bak +0 -392
- package/src/activity/schema/types/authentication.test.ts.bak +0 -337
- package/src/activity/schema/types/authorization.test.ts.bak +0 -379
- package/src/activity/schema/types/note.test.ts.bak +0 -367
- package/src/activity/schema/types/operation.test.ts.bak +0 -379
- package/src/activity/schema/types/unknown.test.ts.bak +0 -304
- package/src/app/authorization/schema.test.ts.bak +0 -412
- package/src/app/oidc/schema.test.ts.bak +0 -117
- package/src/app/registration/schema.test.ts.bak +0 -308
- package/src/app/schema.test.ts.bak +0 -221
- package/src/association/schema.test.ts.bak +0 -148
- package/src/authentication/factors/schema.test.ts.bak +0 -174
- package/src/authentication/settings/schema.test.ts.bak +0 -91
- package/src/authorization/permissions/schema.test.ts.bak +0 -267
- package/src/authorization/roles/schema.test.ts.bak +0 -283
- package/src/common/schema/aggregate.test.ts.bak +0 -89
- package/src/common/schema/collection.test.ts.bak +0 -116
- package/src/common/schema/dates.test.ts.bak +0 -49
- package/src/common/schema/id.test.ts.bak +0 -149
- package/src/common/schema/jwt.test.ts.bak +0 -61
- package/src/common/schema/metadata.test.ts.bak +0 -141
- package/src/common/schema/pagination.test.ts.bak +0 -80
- package/src/common/schema/schema.test.ts.bak +0 -41
- package/src/customer/users/schema.test.ts.bak +0 -138
- package/src/identity/schema.test.ts.bak +0 -48
- package/src/oauth/token/schema/schema.test.ts.bak +0 -142
- package/src/workspace/settings/schema.test.ts.bak +0 -88
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { type } from 'arktype';
|
|
2
|
-
import { describe, expect, test } from 'vitest';
|
|
3
|
-
import { Algorithm, AlgorithmSchema } from './jwt.js';
|
|
4
|
-
|
|
5
|
-
describe('Common Schema - JWT', () => {
|
|
6
|
-
describe('Algorithm constants', () => {
|
|
7
|
-
test('should have correct algorithm values', () => {
|
|
8
|
-
expect(Algorithm.DEFAULT).toBe('RS256');
|
|
9
|
-
expect(Algorithm.HS256).toBe('HS256');
|
|
10
|
-
expect(Algorithm.HS384).toBe('HS384');
|
|
11
|
-
expect(Algorithm.HS512).toBe('HS512');
|
|
12
|
-
expect(Algorithm.RS256).toBe('RS256');
|
|
13
|
-
expect(Algorithm.RS384).toBe('RS384');
|
|
14
|
-
expect(Algorithm.RS512).toBe('RS512');
|
|
15
|
-
expect(Algorithm.ES256).toBe('ES256');
|
|
16
|
-
expect(Algorithm.ES384).toBe('ES384');
|
|
17
|
-
expect(Algorithm.ES512).toBe('ES512');
|
|
18
|
-
expect(Algorithm.PS256).toBe('PS256');
|
|
19
|
-
expect(Algorithm.PS384).toBe('PS384');
|
|
20
|
-
expect(Algorithm.PS512).toBe('PS512');
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
describe('AlgorithmSchema', () => {
|
|
25
|
-
test('should accept valid HMAC algorithms', () => {
|
|
26
|
-
expect(AlgorithmSchema('HS256')).not.toBeInstanceOf(type.errors);
|
|
27
|
-
expect(AlgorithmSchema('HS384')).not.toBeInstanceOf(type.errors);
|
|
28
|
-
expect(AlgorithmSchema('HS512')).not.toBeInstanceOf(type.errors);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
test('should accept valid RSA algorithms', () => {
|
|
32
|
-
expect(AlgorithmSchema('RS256')).not.toBeInstanceOf(type.errors);
|
|
33
|
-
expect(AlgorithmSchema('RS384')).not.toBeInstanceOf(type.errors);
|
|
34
|
-
expect(AlgorithmSchema('RS512')).not.toBeInstanceOf(type.errors);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
test('should accept valid ECDSA algorithms', () => {
|
|
38
|
-
expect(AlgorithmSchema('ES256')).not.toBeInstanceOf(type.errors);
|
|
39
|
-
expect(AlgorithmSchema('ES384')).not.toBeInstanceOf(type.errors);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
test('should accept valid PSS algorithms', () => {
|
|
43
|
-
expect(AlgorithmSchema('PS256')).not.toBeInstanceOf(type.errors);
|
|
44
|
-
expect(AlgorithmSchema('PS384')).not.toBeInstanceOf(type.errors);
|
|
45
|
-
expect(AlgorithmSchema('PS512')).not.toBeInstanceOf(type.errors);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
test('should reject invalid algorithms', () => {
|
|
49
|
-
expect(AlgorithmSchema('INVALID')).toBeInstanceOf(type.errors);
|
|
50
|
-
expect(AlgorithmSchema('HS128')).toBeInstanceOf(type.errors);
|
|
51
|
-
expect(AlgorithmSchema('RS128')).toBeInstanceOf(type.errors);
|
|
52
|
-
expect(AlgorithmSchema('')).toBeInstanceOf(type.errors);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
test('should reject non-string values', () => {
|
|
56
|
-
expect(AlgorithmSchema(123)).toBeInstanceOf(type.errors);
|
|
57
|
-
expect(AlgorithmSchema(null)).toBeInstanceOf(type.errors);
|
|
58
|
-
expect(AlgorithmSchema(undefined)).toBeInstanceOf(type.errors);
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
});
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import { type } from 'arktype';
|
|
2
|
-
import { describe, expect, test } from 'vitest';
|
|
3
|
-
import {
|
|
4
|
-
MetadataMapPropertySchema,
|
|
5
|
-
MetadataPayloadPropertySchema,
|
|
6
|
-
UpsertMetadataPayloadSchema,
|
|
7
|
-
} from './metadata.js';
|
|
8
|
-
|
|
9
|
-
describe('Common - Metadata', () => {
|
|
10
|
-
describe('Map Property Schema', () => {
|
|
11
|
-
test('should parse a record to a map', async () => {
|
|
12
|
-
const result = MetadataMapPropertySchema({
|
|
13
|
-
metadata: { foo: 'bar' },
|
|
14
|
-
}) as typeof MetadataMapPropertySchema.inferOut;
|
|
15
|
-
|
|
16
|
-
expect(result).not.toBeInstanceOf(type.errors);
|
|
17
|
-
expect(result?.metadata).toBeInstanceOf(Map);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
test('should parse undefined property to a map', async () => {
|
|
21
|
-
const result = MetadataMapPropertySchema({
|
|
22
|
-
metadata: undefined,
|
|
23
|
-
}) as typeof MetadataMapPropertySchema.inferOut;
|
|
24
|
-
|
|
25
|
-
expect(result).not.toBeInstanceOf(type.errors);
|
|
26
|
-
expect(result?.metadata).toBeInstanceOf(Map);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
test('should parse undefined to a map', async () => {
|
|
30
|
-
const result = MetadataMapPropertySchema(
|
|
31
|
-
{}
|
|
32
|
-
) as typeof MetadataMapPropertySchema.inferOut;
|
|
33
|
-
|
|
34
|
-
expect(result).not.toBeInstanceOf(type.errors);
|
|
35
|
-
expect(result?.metadata).toBeInstanceOf(Map);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
test('should parse map to a map', async () => {
|
|
39
|
-
const result = MetadataMapPropertySchema({
|
|
40
|
-
metadata: new Map([['foo', 'bar']]),
|
|
41
|
-
}) as typeof MetadataMapPropertySchema.inferOut;
|
|
42
|
-
|
|
43
|
-
expect(result).not.toBeInstanceOf(type.errors);
|
|
44
|
-
expect(result?.metadata).toBeInstanceOf(Map);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
test('should parse null to a map', async () => {
|
|
48
|
-
const result = MetadataMapPropertySchema({
|
|
49
|
-
metadata: null,
|
|
50
|
-
}) as typeof MetadataMapPropertySchema.inferOut;
|
|
51
|
-
|
|
52
|
-
expect(result).not.toBeInstanceOf(type.errors);
|
|
53
|
-
expect(result?.metadata).toBeInstanceOf(Map);
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
describe('Payload', () => {
|
|
58
|
-
test('should parse map to record', async () => {
|
|
59
|
-
const result = MetadataPayloadPropertySchema({
|
|
60
|
-
metadata: new Map<string, string | number>([
|
|
61
|
-
['foo', 'bar'],
|
|
62
|
-
['baz', 0],
|
|
63
|
-
]),
|
|
64
|
-
}) as typeof MetadataPayloadPropertySchema.inferOut;
|
|
65
|
-
|
|
66
|
-
expect(result).not.toBeInstanceOf(type.errors);
|
|
67
|
-
expect(result?.metadata?.foo).to.equal('bar');
|
|
68
|
-
expect(result?.metadata?.baz).to.equal(0);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
test('should return undefined if map is empty', async () => {
|
|
72
|
-
const result = MetadataPayloadPropertySchema({
|
|
73
|
-
metadata: new Map(),
|
|
74
|
-
}) as typeof MetadataPayloadPropertySchema.inferOut;
|
|
75
|
-
|
|
76
|
-
expect(result).not.toBeInstanceOf(type.errors);
|
|
77
|
-
expect(result?.metadata).is.undefined;
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
describe('Upsert Metadata Payload Schema', () => {
|
|
82
|
-
test('should handle incoming record', async () => {
|
|
83
|
-
const result = UpsertMetadataPayloadSchema({
|
|
84
|
-
foo: 'bar',
|
|
85
|
-
bar: 'baz',
|
|
86
|
-
}) as typeof UpsertMetadataPayloadSchema.inferOut;
|
|
87
|
-
|
|
88
|
-
expect(result).not.toBeInstanceOf(type.errors);
|
|
89
|
-
expect(result?.foo).to.equal('bar');
|
|
90
|
-
expect(result?.bar).to.equal('baz');
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
test('should handle incoming map', async () => {
|
|
94
|
-
const result = UpsertMetadataPayloadSchema(
|
|
95
|
-
new Map([
|
|
96
|
-
['foo', 'bar'],
|
|
97
|
-
['bar', 'baz'],
|
|
98
|
-
])
|
|
99
|
-
) as typeof UpsertMetadataPayloadSchema.inferOut;
|
|
100
|
-
|
|
101
|
-
expect(result).not.toBeInstanceOf(type.errors);
|
|
102
|
-
expect(result?.foo).to.equal('bar');
|
|
103
|
-
expect(result?.bar).to.equal('baz');
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
test('should only allow 10 items', async () => {
|
|
107
|
-
const result = UpsertMetadataPayloadSchema(
|
|
108
|
-
new Map([
|
|
109
|
-
['1', '1'],
|
|
110
|
-
['2', '2'],
|
|
111
|
-
['3', '3'],
|
|
112
|
-
['4', '4'],
|
|
113
|
-
['5', '5'],
|
|
114
|
-
['6', '6'],
|
|
115
|
-
['7', '7'],
|
|
116
|
-
['8', '8'],
|
|
117
|
-
['9', '9'],
|
|
118
|
-
['10', '10'],
|
|
119
|
-
['11', '11'],
|
|
120
|
-
])
|
|
121
|
-
) as typeof UpsertMetadataPayloadSchema.inferOut;
|
|
122
|
-
|
|
123
|
-
expect(result).toBeInstanceOf(type.errors);
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
describe('Map Property Schema', () => {
|
|
128
|
-
test('should parse map to record', async () => {
|
|
129
|
-
const result = MetadataMapPropertySchema({
|
|
130
|
-
metadata: {
|
|
131
|
-
foo: 'bar',
|
|
132
|
-
bar: 'baz',
|
|
133
|
-
},
|
|
134
|
-
}) as typeof MetadataMapPropertySchema.inferOut;
|
|
135
|
-
|
|
136
|
-
expect(result).not.toBeInstanceOf(type.errors);
|
|
137
|
-
expect(result?.metadata?.get('foo')).to.equal('bar');
|
|
138
|
-
expect(result?.metadata?.get('bar')).to.equal('baz');
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
});
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { type } from 'arktype';
|
|
2
|
-
import { describe, expect, test } from 'vitest';
|
|
3
|
-
import { PaginationSchema } from './pagination.js';
|
|
4
|
-
|
|
5
|
-
describe('Common Schema - Pagination', () => {
|
|
6
|
-
describe('PaginationSchema', () => {
|
|
7
|
-
test('should accept valid pagination with pageSize as string', () => {
|
|
8
|
-
const result = PaginationSchema({
|
|
9
|
-
pageSize: '10',
|
|
10
|
-
nextToken: 'token123',
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
expect(result).not.toBeInstanceOf(type.errors);
|
|
14
|
-
expect(result).toEqual({
|
|
15
|
-
pageSize: '10',
|
|
16
|
-
nextToken: 'token123',
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
test('should accept valid pagination with pageSize as number', () => {
|
|
21
|
-
const result = PaginationSchema({
|
|
22
|
-
pageSize: 20,
|
|
23
|
-
nextToken: 'token456',
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
expect(result).not.toBeInstanceOf(type.errors);
|
|
27
|
-
expect(result).toEqual({
|
|
28
|
-
pageSize: 20,
|
|
29
|
-
nextToken: 'token456',
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
test('should accept pagination with only pageSize', () => {
|
|
34
|
-
const result = PaginationSchema({
|
|
35
|
-
pageSize: '15',
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
expect(result).not.toBeInstanceOf(type.errors);
|
|
39
|
-
expect(result).toEqual({
|
|
40
|
-
pageSize: '15',
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
test('should accept pagination with only nextToken', () => {
|
|
45
|
-
const result = PaginationSchema({
|
|
46
|
-
nextToken: 'token789',
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
expect(result).not.toBeInstanceOf(type.errors);
|
|
50
|
-
expect(result).toEqual({
|
|
51
|
-
nextToken: 'token789',
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
test('should accept empty pagination object', () => {
|
|
56
|
-
const result = PaginationSchema({});
|
|
57
|
-
|
|
58
|
-
expect(result).not.toBeInstanceOf(type.errors);
|
|
59
|
-
expect(result).toEqual({});
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
test('should reject invalid pageSize type', () => {
|
|
63
|
-
const result = PaginationSchema({
|
|
64
|
-
pageSize: true,
|
|
65
|
-
nextToken: 'token123',
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
expect(result).toBeInstanceOf(type.errors);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
test('should reject invalid nextToken type', () => {
|
|
72
|
-
const result = PaginationSchema({
|
|
73
|
-
pageSize: '10',
|
|
74
|
-
nextToken: 123,
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
expect(result).toBeInstanceOf(type.errors);
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
});
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { type } from 'arktype';
|
|
2
|
-
import { describe, expect, test } from 'vitest';
|
|
3
|
-
import { optionallyNullishToUndefined } from './schema.js';
|
|
4
|
-
|
|
5
|
-
describe('Common Schema', () => {
|
|
6
|
-
describe('optionallyNullishToUndefined', () => {
|
|
7
|
-
test('should parse null string successfully', async () => {
|
|
8
|
-
const Schema = type({
|
|
9
|
-
foo: optionallyNullishToUndefined(type('string')),
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
const result = Schema.assert({
|
|
13
|
-
foo: null,
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
if (result instanceof type.errors) {
|
|
17
|
-
console.log(result.summary);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
expect(result).not.toBeInstanceOf(type.errors);
|
|
21
|
-
expect(result.foo).toBeUndefined();
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
test('should parse undefined string successfully', async () => {
|
|
25
|
-
const Schema = type({
|
|
26
|
-
foo: optionallyNullishToUndefined(type('string')),
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
const result = Schema.assert({
|
|
30
|
-
foo: undefined,
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
if (result instanceof type.errors) {
|
|
34
|
-
console.log(result.summary);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
expect(result).not.toBeInstanceOf(type.errors);
|
|
38
|
-
expect(result.foo).toBeUndefined();
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
});
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import { type } from 'arktype';
|
|
2
|
-
import { describe, expect, test } from 'vitest';
|
|
3
|
-
import { generateUserId } from '../schema.js';
|
|
4
|
-
import {
|
|
5
|
-
InsertUserPayloadSchema,
|
|
6
|
-
UserPayloadSchema,
|
|
7
|
-
UserStatus,
|
|
8
|
-
} from './schema.js';
|
|
9
|
-
|
|
10
|
-
describe('Customer - User', () => {
|
|
11
|
-
describe('User Payload', () => {
|
|
12
|
-
test('should parse attributes successfully', async () => {
|
|
13
|
-
const item = {
|
|
14
|
-
foo: 'bar',
|
|
15
|
-
id: generateUserId(),
|
|
16
|
-
phoneNumber: '123',
|
|
17
|
-
status: UserStatus.ACTIVE,
|
|
18
|
-
createdAt: new Date(),
|
|
19
|
-
updatedAt: new Date(),
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const result = UserPayloadSchema(
|
|
23
|
-
item
|
|
24
|
-
) as typeof UserPayloadSchema.inferOut;
|
|
25
|
-
|
|
26
|
-
if (result instanceof type.errors) {
|
|
27
|
-
console.log(result.summary);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
expect(result).not.toBeInstanceOf(type.errors);
|
|
31
|
-
expect(result?.metadata).to.undefined;
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
describe('Insert User Payload', () => {
|
|
36
|
-
test('should parse attributes successfully', async () => {
|
|
37
|
-
const item = {
|
|
38
|
-
foo: 'bar',
|
|
39
|
-
id: generateUserId(),
|
|
40
|
-
familyName: 'Foo',
|
|
41
|
-
phoneNumber: '123',
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const result = InsertUserPayloadSchema(
|
|
45
|
-
item
|
|
46
|
-
) as typeof InsertUserPayloadSchema.inferOut;
|
|
47
|
-
|
|
48
|
-
if (result instanceof type.errors) {
|
|
49
|
-
console.log(result.summary);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
expect(result).not.toBeInstanceOf(type.errors);
|
|
53
|
-
expect(result?.metadata).to.undefined;
|
|
54
|
-
expect(result?.familyName).to.equal(item.familyName);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
test('should serialize successfully', async () => {
|
|
58
|
-
const item = {
|
|
59
|
-
foo: 'bar',
|
|
60
|
-
id: generateUserId(),
|
|
61
|
-
phoneNumber: '123',
|
|
62
|
-
metadata: new Map(),
|
|
63
|
-
// status: UserStatus.ACTIVE,
|
|
64
|
-
// createdAt: new Date(),
|
|
65
|
-
// updatedAt: new Date(),
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
const result = InsertUserPayloadSchema(
|
|
69
|
-
item
|
|
70
|
-
) as typeof InsertUserPayloadSchema.inferOut;
|
|
71
|
-
|
|
72
|
-
if (result instanceof type.errors) {
|
|
73
|
-
console.log(result.summary);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
expect(result).not.toBeInstanceOf(type.errors);
|
|
77
|
-
expect(result?.metadata).to.null;
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
test('should serialize nulls successfully', async () => {
|
|
81
|
-
const payload = {
|
|
82
|
-
id: generateUserId(),
|
|
83
|
-
status: 'unverified',
|
|
84
|
-
givenName: null,
|
|
85
|
-
middleName: null,
|
|
86
|
-
familyName: null,
|
|
87
|
-
honorificPrefix: null,
|
|
88
|
-
honorificSuffix: null,
|
|
89
|
-
email: null,
|
|
90
|
-
verifiedEmail: null,
|
|
91
|
-
phoneNumber: null,
|
|
92
|
-
verifiedPhoneNumber: null,
|
|
93
|
-
createdAt: '2025-04-02T03:50:40.812Z',
|
|
94
|
-
updatedAt: '2025-04-02T03:50:40.812Z',
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
const result = UserPayloadSchema(payload);
|
|
98
|
-
|
|
99
|
-
if (result instanceof type.errors) {
|
|
100
|
-
console.log(result.summary);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
expect(result).not.toBeInstanceOf(type.errors);
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
test('should serialize nulls successfully', async () => {
|
|
107
|
-
const payload = {
|
|
108
|
-
id: generateUserId(),
|
|
109
|
-
status: 'unverified',
|
|
110
|
-
givenName: null,
|
|
111
|
-
middleName: null,
|
|
112
|
-
familyName: null,
|
|
113
|
-
honorificPrefix: null,
|
|
114
|
-
honorificSuffix: null,
|
|
115
|
-
email: null,
|
|
116
|
-
verifiedEmail: null,
|
|
117
|
-
phoneNumber: null,
|
|
118
|
-
verifiedPhoneNumber: null,
|
|
119
|
-
createdAt: '2025-04-02T03:50:40.812Z',
|
|
120
|
-
updatedAt: '2025-04-02T03:50:40.812Z',
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
const test = type({
|
|
124
|
-
foo: 'string.numeric.parse',
|
|
125
|
-
bar: 'number',
|
|
126
|
-
baz: 'string.date.iso.parse',
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
const result = UserPayloadSchema(payload);
|
|
130
|
-
|
|
131
|
-
if (result instanceof type.errors) {
|
|
132
|
-
console.log(result.summary);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
expect(result).not.toBeInstanceOf(type.errors);
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
});
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { type } from 'arktype';
|
|
2
|
-
import { describe, expect, test } from 'vitest';
|
|
3
|
-
import { IdentityIdentifier, IdentityIdentifierSchema } from './schema.js';
|
|
4
|
-
|
|
5
|
-
describe('Identity - Schema', () => {
|
|
6
|
-
describe('IdentityIdentifier constants', () => {
|
|
7
|
-
test('should have correct identifier values', () => {
|
|
8
|
-
expect(IdentityIdentifier.EMAIL).toBe('email');
|
|
9
|
-
expect(IdentityIdentifier.PHONE_NUMBER).toBe('phoneNumber');
|
|
10
|
-
});
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
describe('IdentityIdentifierSchema', () => {
|
|
14
|
-
test('should accept valid email identifier', () => {
|
|
15
|
-
const result = IdentityIdentifierSchema('email');
|
|
16
|
-
expect(result).not.toBeInstanceOf(type.errors);
|
|
17
|
-
expect(result).toBe('email');
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
test('should accept valid phone number identifier', () => {
|
|
21
|
-
const result = IdentityIdentifierSchema('phoneNumber');
|
|
22
|
-
expect(result).not.toBeInstanceOf(type.errors);
|
|
23
|
-
expect(result).toBe('phoneNumber');
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
test('should reject invalid identifiers', () => {
|
|
27
|
-
expect(IdentityIdentifierSchema('username')).toBeInstanceOf(type.errors);
|
|
28
|
-
expect(IdentityIdentifierSchema('invalid')).toBeInstanceOf(type.errors);
|
|
29
|
-
expect(IdentityIdentifierSchema('')).toBeInstanceOf(type.errors);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
test('should reject non-string values', () => {
|
|
33
|
-
expect(IdentityIdentifierSchema(123)).toBeInstanceOf(type.errors);
|
|
34
|
-
expect(IdentityIdentifierSchema(null)).toBeInstanceOf(type.errors);
|
|
35
|
-
expect(IdentityIdentifierSchema(undefined)).toBeInstanceOf(type.errors);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
test('should be case sensitive', () => {
|
|
39
|
-
expect(IdentityIdentifierSchema('Email')).toBeInstanceOf(type.errors);
|
|
40
|
-
expect(IdentityIdentifierSchema('PHONE_NUMBER')).toBeInstanceOf(
|
|
41
|
-
type.errors
|
|
42
|
-
);
|
|
43
|
-
expect(IdentityIdentifierSchema('phonenumber')).toBeInstanceOf(
|
|
44
|
-
type.errors
|
|
45
|
-
);
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
});
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import { type } from 'arktype';
|
|
2
|
-
import { describe, expect, test } from 'vitest';
|
|
3
|
-
import { generateAppId } from '../../../app/utils.js';
|
|
4
|
-
import { Schema } from './schema.js';
|
|
5
|
-
|
|
6
|
-
describe('OAuth Token - Schema', () => {
|
|
7
|
-
describe('Schema union', () => {
|
|
8
|
-
test('should accept authorization code grant', () => {
|
|
9
|
-
const payload = {
|
|
10
|
-
grant_type: 'authorization_code',
|
|
11
|
-
code: 'auth_code_123',
|
|
12
|
-
client_id: generateAppId(),
|
|
13
|
-
redirect_uri: 'https://example.com/callback',
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const result = Schema(payload);
|
|
17
|
-
expect(result).not.toBeInstanceOf(type.errors);
|
|
18
|
-
expect(result).toEqual(payload);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
test('should accept authorization code with PKCE', () => {
|
|
22
|
-
const payload = {
|
|
23
|
-
grant_type: 'authorization_code',
|
|
24
|
-
code: 'auth_code_123',
|
|
25
|
-
client_id: generateAppId(),
|
|
26
|
-
redirect_uri: 'https://example.com/callback',
|
|
27
|
-
code_verifier: 'pkce_verifier_123',
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const result = Schema(payload);
|
|
31
|
-
expect(result).not.toBeInstanceOf(type.errors);
|
|
32
|
-
expect(result).toEqual(payload);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
test('should accept authorization code with client secret', () => {
|
|
36
|
-
const payload = {
|
|
37
|
-
grant_type: 'authorization_code',
|
|
38
|
-
code: 'auth_code_123',
|
|
39
|
-
client_id: generateAppId(),
|
|
40
|
-
client_secret: 'secret_123',
|
|
41
|
-
redirect_uri: 'https://example.com/callback',
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const result = Schema(payload);
|
|
45
|
-
expect(result).not.toBeInstanceOf(type.errors);
|
|
46
|
-
expect(result).toEqual(payload);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
test('should accept client credentials grant', () => {
|
|
50
|
-
const payload = {
|
|
51
|
-
grant_type: 'client_credentials',
|
|
52
|
-
client_id: generateAppId(),
|
|
53
|
-
client_secret: 'secret_123',
|
|
54
|
-
scope: 'read write',
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
const result = Schema(payload);
|
|
58
|
-
expect(result).not.toBeInstanceOf(type.errors);
|
|
59
|
-
expect(result).toEqual(payload);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
test('should accept refresh token grant', () => {
|
|
63
|
-
const payload = {
|
|
64
|
-
grant_type: 'refresh_token',
|
|
65
|
-
refresh_token: 'refresh_token_123',
|
|
66
|
-
client_id: generateAppId(),
|
|
67
|
-
client_secret: 'secret_123',
|
|
68
|
-
scope: 'read',
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
const result = Schema(payload);
|
|
72
|
-
expect(result).not.toBeInstanceOf(type.errors);
|
|
73
|
-
expect(result).toEqual(payload);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
test('should reject invalid grant type', () => {
|
|
77
|
-
const payload = {
|
|
78
|
-
grant_type: 'invalid_grant',
|
|
79
|
-
code: 'auth_code_123',
|
|
80
|
-
client_id: generateAppId(),
|
|
81
|
-
redirect_uri: 'https://example.com/callback',
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
const result = Schema(payload);
|
|
85
|
-
expect(result).toBeInstanceOf(type.errors);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
test('should reject authorization code without required fields', () => {
|
|
89
|
-
const payload = {
|
|
90
|
-
grant_type: 'authorization_code',
|
|
91
|
-
client_id: generateAppId(),
|
|
92
|
-
// missing code and redirect_uri
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
const result = Schema(payload);
|
|
96
|
-
expect(result).toBeInstanceOf(type.errors);
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
test('should reject invalid redirect URI', () => {
|
|
100
|
-
const payload = {
|
|
101
|
-
grant_type: 'authorization_code',
|
|
102
|
-
code: 'auth_code_123',
|
|
103
|
-
client_id: generateAppId(),
|
|
104
|
-
redirect_uri: 'not-a-valid-url',
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
const result = Schema(payload);
|
|
108
|
-
expect(result).toBeInstanceOf(type.errors);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
test('should reject client credentials without required fields', () => {
|
|
112
|
-
const payload = {
|
|
113
|
-
grant_type: 'client_credentials',
|
|
114
|
-
client_id: generateAppId(),
|
|
115
|
-
// missing client_secret
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
const result = Schema(payload);
|
|
119
|
-
expect(result).toBeInstanceOf(type.errors);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
test('should reject refresh token without required fields', () => {
|
|
123
|
-
const payload = {
|
|
124
|
-
grant_type: 'refresh_token',
|
|
125
|
-
client_id: 'app_123',
|
|
126
|
-
// missing refresh_token and client_secret
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
const result = Schema(payload);
|
|
130
|
-
expect(result).toBeInstanceOf(type.errors);
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
test('should reject completely invalid payload', () => {
|
|
134
|
-
const payload = {
|
|
135
|
-
invalid: 'data',
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
const result = Schema(payload);
|
|
139
|
-
expect(result).toBeInstanceOf(type.errors);
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
});
|