@open-dpp/dto 5.2.0 → 5.3.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/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/policy/policy.dto.d.ts +44 -0
- package/dist/policy/policy.dto.d.ts.map +1 -0
- package/dist/policy/policy.dto.js +39 -0
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/policy/policy.dto.ts +50 -0
- package/src/policy/set-policy-limits.dto.spec.ts +60 -0
package/dist/index.d.ts
CHANGED
|
@@ -95,4 +95,5 @@ export * from "./unique-product-identifiers/unique-product-identifier-list-item.
|
|
|
95
95
|
export * from "./unique-product-identifiers/create-unique-product-identifier.dto";
|
|
96
96
|
export * from "./unique-product-identifiers/create-internal-unique-product-identifier.dto";
|
|
97
97
|
export * from "./unique-product-identifiers/update-unique-product-identifier.dto";
|
|
98
|
+
export * from "./policy/policy.dto";
|
|
98
99
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,8CAA8C,CAAC;AAC7D,cAAc,oCAAoC,CAAC;AACnD,cAAc,8CAA8C,CAAC;AAC7D,cAAc,qCAAqC,CAAC;AACpD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,wCAAwC,CAAC;AAEvD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,yDAAyD,CAAC;AAExE,cAAc,mBAAmB,CAAC;AAClC,cAAc,gCAAgC,CAAC;AAE/C,cAAc,2CAA2C,CAAC;AAC1D,cAAc,oCAAoC,CAAC;AACnD,cAAc,oCAAoC,CAAC;AACnD,cAAc,uCAAuC,CAAC;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exportStar(require("./unique-product-identifiers/unique-product-identifier-lis
|
|
|
111
111
|
__exportStar(require("./unique-product-identifiers/create-unique-product-identifier.dto"), exports);
|
|
112
112
|
__exportStar(require("./unique-product-identifiers/create-internal-unique-product-identifier.dto"), exports);
|
|
113
113
|
__exportStar(require("./unique-product-identifiers/update-unique-product-identifier.dto"), exports);
|
|
114
|
+
__exportStar(require("./policy/policy.dto"), exports);
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const PolicyKeyList: {
|
|
3
|
+
readonly AI_TOKEN_QUOTA: "AI_TOKEN_QUOTA";
|
|
4
|
+
readonly MEDIA_STORAGE_LIMIT: "MEDIA_STORAGE_LIMIT";
|
|
5
|
+
readonly PASSPORT_CREATE_LIMIT: "PASSPORT_CREATE_LIMIT";
|
|
6
|
+
readonly ORGANIZATION_MEMBER_LIMIT: "ORGANIZATION_MEMBER_LIMIT";
|
|
7
|
+
};
|
|
8
|
+
export declare const PolicyKeyEnum: z.ZodEnum<{
|
|
9
|
+
readonly AI_TOKEN_QUOTA: "AI_TOKEN_QUOTA";
|
|
10
|
+
readonly MEDIA_STORAGE_LIMIT: "MEDIA_STORAGE_LIMIT";
|
|
11
|
+
readonly PASSPORT_CREATE_LIMIT: "PASSPORT_CREATE_LIMIT";
|
|
12
|
+
readonly ORGANIZATION_MEMBER_LIMIT: "ORGANIZATION_MEMBER_LIMIT";
|
|
13
|
+
}>;
|
|
14
|
+
export type PolicyKey = z.infer<typeof PolicyKeyEnum>;
|
|
15
|
+
export declare const PolicyUtilizationDtoSchema: z.ZodObject<{
|
|
16
|
+
limit: z.ZodNumber;
|
|
17
|
+
used: z.ZodNumber;
|
|
18
|
+
reset: z.ZodOptional<z.ZodISODateTime>;
|
|
19
|
+
}, z.core.$strip>;
|
|
20
|
+
export type PolicyUtilizationDto = z.infer<typeof PolicyUtilizationDtoSchema>;
|
|
21
|
+
export declare const PolicyUtilizationsDtoSchema: z.ZodRecord<z.ZodEnum<{
|
|
22
|
+
readonly AI_TOKEN_QUOTA: "AI_TOKEN_QUOTA";
|
|
23
|
+
readonly MEDIA_STORAGE_LIMIT: "MEDIA_STORAGE_LIMIT";
|
|
24
|
+
readonly PASSPORT_CREATE_LIMIT: "PASSPORT_CREATE_LIMIT";
|
|
25
|
+
readonly ORGANIZATION_MEMBER_LIMIT: "ORGANIZATION_MEMBER_LIMIT";
|
|
26
|
+
}>, z.ZodObject<{
|
|
27
|
+
limit: z.ZodNumber;
|
|
28
|
+
used: z.ZodNumber;
|
|
29
|
+
reset: z.ZodOptional<z.ZodISODateTime>;
|
|
30
|
+
}, z.core.$strip>>;
|
|
31
|
+
export type PolicyUtilizationDtoType = z.infer<typeof PolicyUtilizationsDtoSchema>;
|
|
32
|
+
export declare const PolicyLimitDtoSchema: z.ZodNumber;
|
|
33
|
+
/**
|
|
34
|
+
* New limits keyed by policy key. Omitted keys keep the limit they already
|
|
35
|
+
* have, so a caller only sends what it wants to change.
|
|
36
|
+
*/
|
|
37
|
+
export declare const SetPolicyLimitsDtoSchema: z.ZodRecord<z.ZodEnum<{
|
|
38
|
+
readonly AI_TOKEN_QUOTA: "AI_TOKEN_QUOTA";
|
|
39
|
+
readonly MEDIA_STORAGE_LIMIT: "MEDIA_STORAGE_LIMIT";
|
|
40
|
+
readonly PASSPORT_CREATE_LIMIT: "PASSPORT_CREATE_LIMIT";
|
|
41
|
+
readonly ORGANIZATION_MEMBER_LIMIT: "ORGANIZATION_MEMBER_LIMIT";
|
|
42
|
+
}> & z.core.$partial, z.ZodNumber>;
|
|
43
|
+
export type SetPolicyLimitsDto = z.infer<typeof SetPolicyLimitsDtoSchema>;
|
|
44
|
+
//# sourceMappingURL=policy.dto.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy.dto.d.ts","sourceRoot":"","sources":["../../src/policy/policy.dto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,aAAa;;;;;CAKhB,CAAC;AAEX,eAAO,MAAM,aAAa;;;;;EAAwB,CAAC;AACnD,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;AAEtD,eAAO,MAAM,0BAA0B;;;;iBASrC,CAAC;AAEH,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,0BAA0B,CAAC,CAAC;AAE9E,eAAO,MAAM,2BAA2B;;;;;;;;;kBAAsD,CAAC;AAE/F,MAAM,MAAM,wBAAwB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAEnF,eAAO,MAAM,oBAAoB,aAI4D,CAAC;AAE9F;;;GAGG;AACH,eAAO,MAAM,wBAAwB;;;;;kCAQjC,CAAC;AAEL,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SetPolicyLimitsDtoSchema = exports.PolicyLimitDtoSchema = exports.PolicyUtilizationsDtoSchema = exports.PolicyUtilizationDtoSchema = exports.PolicyKeyEnum = exports.PolicyKeyList = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
exports.PolicyKeyList = {
|
|
6
|
+
AI_TOKEN_QUOTA: "AI_TOKEN_QUOTA",
|
|
7
|
+
MEDIA_STORAGE_LIMIT: "MEDIA_STORAGE_LIMIT",
|
|
8
|
+
PASSPORT_CREATE_LIMIT: "PASSPORT_CREATE_LIMIT",
|
|
9
|
+
ORGANIZATION_MEMBER_LIMIT: "ORGANIZATION_MEMBER_LIMIT",
|
|
10
|
+
};
|
|
11
|
+
exports.PolicyKeyEnum = zod_1.z.enum(exports.PolicyKeyList);
|
|
12
|
+
exports.PolicyUtilizationDtoSchema = zod_1.z.object({
|
|
13
|
+
limit: zod_1.z
|
|
14
|
+
.number()
|
|
15
|
+
.meta({ description: "The cap for this policy. 0 means unlimited.", example: 50 }),
|
|
16
|
+
used: zod_1.z.number().meta({ description: "How much of the cap is currently used.", example: 12 }),
|
|
17
|
+
reset: zod_1.z.iso
|
|
18
|
+
.datetime()
|
|
19
|
+
.optional()
|
|
20
|
+
.meta({ description: "When the counter resets. Absent for limits, which never reset." }),
|
|
21
|
+
});
|
|
22
|
+
exports.PolicyUtilizationsDtoSchema = zod_1.z.record(exports.PolicyKeyEnum, exports.PolicyUtilizationDtoSchema);
|
|
23
|
+
exports.PolicyLimitDtoSchema = zod_1.z
|
|
24
|
+
.number()
|
|
25
|
+
.int()
|
|
26
|
+
.min(0)
|
|
27
|
+
.meta({ description: "The new cap for this policy key. 0 means unlimited.", example: 100 });
|
|
28
|
+
/**
|
|
29
|
+
* New limits keyed by policy key. Omitted keys keep the limit they already
|
|
30
|
+
* have, so a caller only sends what it wants to change.
|
|
31
|
+
*/
|
|
32
|
+
exports.SetPolicyLimitsDtoSchema = zod_1.z
|
|
33
|
+
.partialRecord(exports.PolicyKeyEnum, exports.PolicyLimitDtoSchema)
|
|
34
|
+
.refine((limits) => Object.keys(limits).length > 0, {
|
|
35
|
+
message: "At least one policy key must be provided",
|
|
36
|
+
})
|
|
37
|
+
.meta({
|
|
38
|
+
description: "New limits keyed by policy key. Keys that are omitted keep their current limit. At least one key is required.",
|
|
39
|
+
});
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -102,3 +102,4 @@ export * from "./unique-product-identifiers/unique-product-identifier-list-item.
|
|
|
102
102
|
export * from "./unique-product-identifiers/create-unique-product-identifier.dto";
|
|
103
103
|
export * from "./unique-product-identifiers/create-internal-unique-product-identifier.dto";
|
|
104
104
|
export * from "./unique-product-identifiers/update-unique-product-identifier.dto";
|
|
105
|
+
export * from "./policy/policy.dto";
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
export const PolicyKeyList = {
|
|
4
|
+
AI_TOKEN_QUOTA: "AI_TOKEN_QUOTA",
|
|
5
|
+
MEDIA_STORAGE_LIMIT: "MEDIA_STORAGE_LIMIT",
|
|
6
|
+
PASSPORT_CREATE_LIMIT: "PASSPORT_CREATE_LIMIT",
|
|
7
|
+
ORGANIZATION_MEMBER_LIMIT: "ORGANIZATION_MEMBER_LIMIT",
|
|
8
|
+
} as const;
|
|
9
|
+
|
|
10
|
+
export const PolicyKeyEnum = z.enum(PolicyKeyList);
|
|
11
|
+
export type PolicyKey = z.infer<typeof PolicyKeyEnum>;
|
|
12
|
+
|
|
13
|
+
export const PolicyUtilizationDtoSchema = z.object({
|
|
14
|
+
limit: z
|
|
15
|
+
.number()
|
|
16
|
+
.meta({ description: "The cap for this policy. 0 means unlimited.", example: 50 }),
|
|
17
|
+
used: z.number().meta({ description: "How much of the cap is currently used.", example: 12 }),
|
|
18
|
+
reset: z.iso
|
|
19
|
+
.datetime()
|
|
20
|
+
.optional()
|
|
21
|
+
.meta({ description: "When the counter resets. Absent for limits, which never reset." }),
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export type PolicyUtilizationDto = z.infer<typeof PolicyUtilizationDtoSchema>;
|
|
25
|
+
|
|
26
|
+
export const PolicyUtilizationsDtoSchema = z.record(PolicyKeyEnum, PolicyUtilizationDtoSchema);
|
|
27
|
+
|
|
28
|
+
export type PolicyUtilizationDtoType = z.infer<typeof PolicyUtilizationsDtoSchema>;
|
|
29
|
+
|
|
30
|
+
export const PolicyLimitDtoSchema = z
|
|
31
|
+
.number()
|
|
32
|
+
.int()
|
|
33
|
+
.min(0)
|
|
34
|
+
.meta({ description: "The new cap for this policy key. 0 means unlimited.", example: 100 });
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* New limits keyed by policy key. Omitted keys keep the limit they already
|
|
38
|
+
* have, so a caller only sends what it wants to change.
|
|
39
|
+
*/
|
|
40
|
+
export const SetPolicyLimitsDtoSchema = z
|
|
41
|
+
.partialRecord(PolicyKeyEnum, PolicyLimitDtoSchema)
|
|
42
|
+
.refine((limits) => Object.keys(limits).length > 0, {
|
|
43
|
+
message: "At least one policy key must be provided",
|
|
44
|
+
})
|
|
45
|
+
.meta({
|
|
46
|
+
description:
|
|
47
|
+
"New limits keyed by policy key. Keys that are omitted keep their current limit. At least one key is required.",
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
export type SetPolicyLimitsDto = z.infer<typeof SetPolicyLimitsDtoSchema>;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { PolicyKeyList, SetPolicyLimitsDtoSchema } from "./policy.dto";
|
|
2
|
+
|
|
3
|
+
describe("setPolicyLimitsDtoSchema", () => {
|
|
4
|
+
it("accepts a single policy key", () => {
|
|
5
|
+
const result = SetPolicyLimitsDtoSchema.safeParse({
|
|
6
|
+
[PolicyKeyList.AI_TOKEN_QUOTA]: 1000,
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
expect(result.success).toBe(true);
|
|
10
|
+
expect(result.data).toEqual({ [PolicyKeyList.AI_TOKEN_QUOTA]: 1000 });
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("accepts several policy keys at once", () => {
|
|
14
|
+
const result = SetPolicyLimitsDtoSchema.safeParse({
|
|
15
|
+
[PolicyKeyList.AI_TOKEN_QUOTA]: 1000,
|
|
16
|
+
[PolicyKeyList.MEDIA_STORAGE_LIMIT]: 500,
|
|
17
|
+
[PolicyKeyList.PASSPORT_CREATE_LIMIT]: 0,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
expect(result.success).toBe(true);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("leaves unspecified keys out instead of demanding every key", () => {
|
|
24
|
+
const result = SetPolicyLimitsDtoSchema.safeParse({
|
|
25
|
+
[PolicyKeyList.MEDIA_STORAGE_LIMIT]: 500,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
expect(result.success).toBe(true);
|
|
29
|
+
expect(Object.keys(result.data!)).toEqual([PolicyKeyList.MEDIA_STORAGE_LIMIT]);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("rejects an empty record", () => {
|
|
33
|
+
const result = SetPolicyLimitsDtoSchema.safeParse({});
|
|
34
|
+
|
|
35
|
+
expect(result.success).toBe(false);
|
|
36
|
+
expect(result.error!.issues[0].message).toBe("At least one policy key must be provided");
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("rejects an unknown policy key", () => {
|
|
40
|
+
const result = SetPolicyLimitsDtoSchema.safeParse({ NOT_A_POLICY: 10 });
|
|
41
|
+
|
|
42
|
+
expect(result.success).toBe(false);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("rejects a negative limit", () => {
|
|
46
|
+
const result = SetPolicyLimitsDtoSchema.safeParse({
|
|
47
|
+
[PolicyKeyList.AI_TOKEN_QUOTA]: -1,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
expect(result.success).toBe(false);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("rejects a fractional limit", () => {
|
|
54
|
+
const result = SetPolicyLimitsDtoSchema.safeParse({
|
|
55
|
+
[PolicyKeyList.AI_TOKEN_QUOTA]: 1.5,
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
expect(result.success).toBe(false);
|
|
59
|
+
});
|
|
60
|
+
});
|