@hawk.so/types 0.6.1 → 0.6.2

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.
@@ -1,4 +1,90 @@
1
1
  import type { ObjectId } from 'bson';
2
+ /**
3
+ * Defines what a promo code grants to the user or workspace
4
+ */
5
+ export type PromoCodeBenefitType = 'grant_plan' | 'percent_discount' | 'amount_discount' | 'fixed_price';
6
+ /**
7
+ * Grant plan benefit — assigns a tariff to workspace immediately
8
+ */
9
+ export interface GrantPlanPromoCodeBenefit {
10
+ /**
11
+ * Benefit type
12
+ */
13
+ type: 'grant_plan';
14
+ /**
15
+ * Tariff plan to grant to workspace
16
+ */
17
+ planId: ObjectId;
18
+ }
19
+ /**
20
+ * Reduces plan price by a percentage when purchasing a tariff
21
+ */
22
+ export interface PercentDiscountPromoCodeBenefit {
23
+ /**
24
+ * Benefit type
25
+ */
26
+ type: 'percent_discount';
27
+ /**
28
+ * Discount size in percent. Greater than 0, maximum 100
29
+ * @example 20
30
+ */
31
+ percent: number;
32
+ /**
33
+ * Plan ids this promo can be applied to.
34
+ * If not set or empty — applicable to any available plan
35
+ */
36
+ applicablePlanIds?: ObjectId[];
37
+ /**
38
+ * Minimum final price after discount.
39
+ * If not set — defaults to 1
40
+ */
41
+ minFinalPrice?: number;
42
+ }
43
+ /**
44
+ * Fixed amount discount benefit
45
+ */
46
+ export interface AmountDiscountPromoCodeBenefit {
47
+ /**
48
+ * Benefit type
49
+ */
50
+ type: 'amount_discount';
51
+ /**
52
+ * Discount size in money. Must be greater than 0
53
+ */
54
+ amount: number;
55
+ /**
56
+ * Plan ids this promo can be applied to.
57
+ * If not set or empty — applicable to any available plan
58
+ */
59
+ applicablePlanIds?: ObjectId[];
60
+ /**
61
+ * Minimum final price after discount.
62
+ * If not set — defaults to 1
63
+ */
64
+ minFinalPrice?: number;
65
+ }
66
+ /**
67
+ * Sets a fixed final price for selected plans when purchasing a tariff
68
+ */
69
+ export interface FixedPricePromoCodeBenefit {
70
+ /**
71
+ * Benefit type
72
+ */
73
+ type: 'fixed_price';
74
+ /**
75
+ * Final tariff price after promo is applied
76
+ */
77
+ amount: number;
78
+ /**
79
+ * Plan ids this promo can be applied to.
80
+ * If not set or empty — applicable to any available plan
81
+ */
82
+ applicablePlanIds?: ObjectId[];
83
+ }
84
+ /**
85
+ * Promo code benefit union
86
+ */
87
+ export type PromoCodeBenefit = GrantPlanPromoCodeBenefit | PercentDiscountPromoCodeBenefit | AmountDiscountPromoCodeBenefit | FixedPricePromoCodeBenefit;
2
88
  /**
3
89
  * Promo code representation in DataBase
4
90
  */
@@ -8,21 +94,24 @@ export interface PromoCodeDBScheme {
8
94
  */
9
95
  _id: ObjectId;
10
96
  /**
11
- * Normalized promo code value
97
+ * Promo code value entered by user.
98
+ * Normalized: trim + uppercase. Allowed: A-Z, 0-9, "-", "_". Must be unique
12
99
  * @example HAWK-2026
13
100
  */
14
- code: string;
101
+ value: string;
15
102
  /**
16
- * Tariff plan assigned by this promo code
103
+ * What this promo code grants
17
104
  */
18
- planId: ObjectId;
105
+ benefit: PromoCodeBenefit;
19
106
  /**
20
- * Maximum total usages count
107
+ * Maximum total successful usages count.
108
+ * If not set — no global limit
21
109
  * @example 100
22
110
  */
23
111
  limit?: number;
24
112
  /**
25
- * Date after which promo code cannot be used
113
+ * Date after which promo code cannot be used.
114
+ * If not set — no expiration
26
115
  * @example 2026-12-31T23:59:59.000Z
27
116
  */
28
117
  expiresAt?: Date;
@@ -1,4 +1,5 @@
1
1
  import type { ObjectId } from 'bson';
2
+ import type { PromoCodeBenefitType } from './promoCode.ts';
2
3
  /**
3
4
  * Promo code usage representation in DataBase
4
5
  */
@@ -20,10 +21,25 @@ export interface PromoCodeUsageDBScheme {
20
21
  */
21
22
  workspaceId: ObjectId;
22
23
  /**
23
- * Date when promo code was applied
24
- * @example 2026-06-10T12:30:00.000Z
24
+ * Plan to which promo was applied or which was granted
25
25
  */
26
- appliedAt: Date;
26
+ planId?: ObjectId;
27
+ /**
28
+ * Benefit type at the moment of application
29
+ */
30
+ benefitType: PromoCodeBenefitType;
31
+ /**
32
+ * Plan price before promo, for discount promos
33
+ */
34
+ originalAmount?: number;
35
+ /**
36
+ * Final price after promo, for discount promos
37
+ */
38
+ finalAmount?: number;
39
+ /**
40
+ * Actual discount amount in money, for discount promos
41
+ */
42
+ discountAmount?: number;
27
43
  /**
28
44
  * UTM parameters captured when promo code was applied. Used for analytics purposes
29
45
  */
@@ -49,4 +65,9 @@ export interface PromoCodeUsageDBScheme {
49
65
  */
50
66
  term?: string;
51
67
  };
68
+ /**
69
+ * Date when promo code was successfully applied
70
+ * @example 2026-06-10T12:30:00.000Z
71
+ */
72
+ appliedAt: Date;
52
73
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hawk.so/types",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "description": "TypeScript definitions for Hawk",
5
5
  "types": "build/index.d.ts",
6
6
  "main": "build/index.js",
@@ -1,5 +1,114 @@
1
1
  import type { ObjectId } from 'bson';
2
2
 
3
+ /**
4
+ * Defines what a promo code grants to the user or workspace
5
+ */
6
+ export type PromoCodeBenefitType =
7
+ | 'grant_plan'
8
+ | 'percent_discount'
9
+ | 'amount_discount'
10
+ | 'fixed_price';
11
+
12
+ /**
13
+ * Grant plan benefit — assigns a tariff to workspace immediately
14
+ */
15
+ export interface GrantPlanPromoCodeBenefit {
16
+ /**
17
+ * Benefit type
18
+ */
19
+ type: 'grant_plan';
20
+
21
+ /**
22
+ * Tariff plan to grant to workspace
23
+ */
24
+ planId: ObjectId;
25
+ }
26
+
27
+ /**
28
+ * Reduces plan price by a percentage when purchasing a tariff
29
+ */
30
+ export interface PercentDiscountPromoCodeBenefit {
31
+ /**
32
+ * Benefit type
33
+ */
34
+ type: 'percent_discount';
35
+
36
+ /**
37
+ * Discount size in percent. Greater than 0, maximum 100
38
+ * @example 20
39
+ */
40
+ percent: number;
41
+
42
+ /**
43
+ * Plan ids this promo can be applied to.
44
+ * If not set or empty — applicable to any available plan
45
+ */
46
+ applicablePlanIds?: ObjectId[];
47
+
48
+ /**
49
+ * Minimum final price after discount.
50
+ * If not set — defaults to 1
51
+ */
52
+ minFinalPrice?: number;
53
+ }
54
+
55
+ /**
56
+ * Fixed amount discount benefit
57
+ */
58
+ export interface AmountDiscountPromoCodeBenefit {
59
+ /**
60
+ * Benefit type
61
+ */
62
+ type: 'amount_discount';
63
+
64
+ /**
65
+ * Discount size in money. Must be greater than 0
66
+ */
67
+ amount: number;
68
+
69
+ /**
70
+ * Plan ids this promo can be applied to.
71
+ * If not set or empty — applicable to any available plan
72
+ */
73
+ applicablePlanIds?: ObjectId[];
74
+
75
+ /**
76
+ * Minimum final price after discount.
77
+ * If not set — defaults to 1
78
+ */
79
+ minFinalPrice?: number;
80
+ }
81
+
82
+ /**
83
+ * Sets a fixed final price for selected plans when purchasing a tariff
84
+ */
85
+ export interface FixedPricePromoCodeBenefit {
86
+ /**
87
+ * Benefit type
88
+ */
89
+ type: 'fixed_price';
90
+
91
+ /**
92
+ * Final tariff price after promo is applied
93
+ */
94
+ amount: number;
95
+
96
+ /**
97
+ * Plan ids this promo can be applied to.
98
+ * If not set or empty — applicable to any available plan
99
+ */
100
+ applicablePlanIds?: ObjectId[];
101
+ }
102
+
103
+ /**
104
+ * Promo code benefit union
105
+ */
106
+ export type PromoCodeBenefit =
107
+ | GrantPlanPromoCodeBenefit
108
+ | PercentDiscountPromoCodeBenefit
109
+ | AmountDiscountPromoCodeBenefit
110
+ | FixedPricePromoCodeBenefit;
111
+
3
112
  /**
4
113
  * Promo code representation in DataBase
5
114
  */
@@ -10,24 +119,27 @@ export interface PromoCodeDBScheme {
10
119
  _id: ObjectId;
11
120
 
12
121
  /**
13
- * Normalized promo code value
122
+ * Promo code value entered by user.
123
+ * Normalized: trim + uppercase. Allowed: A-Z, 0-9, "-", "_". Must be unique
14
124
  * @example HAWK-2026
15
125
  */
16
- code: string;
126
+ value: string;
17
127
 
18
128
  /**
19
- * Tariff plan assigned by this promo code
129
+ * What this promo code grants
20
130
  */
21
- planId: ObjectId;
131
+ benefit: PromoCodeBenefit;
22
132
 
23
133
  /**
24
- * Maximum total usages count
134
+ * Maximum total successful usages count.
135
+ * If not set — no global limit
25
136
  * @example 100
26
137
  */
27
138
  limit?: number;
28
139
 
29
140
  /**
30
- * Date after which promo code cannot be used
141
+ * Date after which promo code cannot be used.
142
+ * If not set — no expiration
31
143
  * @example 2026-12-31T23:59:59.000Z
32
144
  */
33
145
  expiresAt?: Date;
@@ -1,4 +1,5 @@
1
1
  import type { ObjectId } from 'bson';
2
+ import type { PromoCodeBenefitType } from './promoCode.ts';
2
3
 
3
4
  /**
4
5
  * Promo code usage representation in DataBase
@@ -25,10 +26,29 @@ export interface PromoCodeUsageDBScheme {
25
26
  workspaceId: ObjectId;
26
27
 
27
28
  /**
28
- * Date when promo code was applied
29
- * @example 2026-06-10T12:30:00.000Z
29
+ * Plan to which promo was applied or which was granted
30
30
  */
31
- appliedAt: Date;
31
+ planId?: ObjectId;
32
+
33
+ /**
34
+ * Benefit type at the moment of application
35
+ */
36
+ benefitType: PromoCodeBenefitType;
37
+
38
+ /**
39
+ * Plan price before promo, for discount promos
40
+ */
41
+ originalAmount?: number;
42
+
43
+ /**
44
+ * Final price after promo, for discount promos
45
+ */
46
+ finalAmount?: number;
47
+
48
+ /**
49
+ * Actual discount amount in money, for discount promos
50
+ */
51
+ discountAmount?: number;
32
52
 
33
53
  /**
34
54
  * UTM parameters captured when promo code was applied. Used for analytics purposes
@@ -59,4 +79,10 @@ export interface PromoCodeUsageDBScheme {
59
79
  */
60
80
  term?: string;
61
81
  };
82
+
83
+ /**
84
+ * Date when promo code was successfully applied
85
+ * @example 2026-06-10T12:30:00.000Z
86
+ */
87
+ appliedAt: Date;
62
88
  }