@tuturuuu/utils 0.0.3 → 0.6.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.
Files changed (186) hide show
  1. package/CHANGELOG.md +305 -0
  2. package/biome.json +5 -0
  3. package/jsr.json +8 -8
  4. package/package.json +63 -32
  5. package/src/__tests__/ai-temp-auth.test.ts +309 -0
  6. package/src/__tests__/api-proxy-guard.test.ts +1451 -0
  7. package/src/__tests__/app-url.test.ts +270 -0
  8. package/src/__tests__/avatar-url.test.ts +97 -0
  9. package/src/__tests__/color-helper.test.ts +179 -0
  10. package/src/__tests__/constants.test.ts +351 -0
  11. package/src/__tests__/crypto.test.ts +107 -0
  12. package/src/__tests__/date-helper.test.ts +408 -0
  13. package/src/__tests__/fixtures/task-description-full-featured.json +456 -0
  14. package/src/__tests__/format.test.ts +317 -0
  15. package/src/__tests__/html-sanitizer.test.ts +360 -0
  16. package/src/__tests__/interest-calculator.test.ts +336 -0
  17. package/src/__tests__/interest-detector.test.ts +222 -0
  18. package/src/__tests__/label-colors.test.ts +241 -0
  19. package/src/__tests__/name-helper.test.ts +158 -0
  20. package/src/__tests__/node-diff.test.ts +576 -0
  21. package/src/__tests__/notification-service.test.ts +210 -0
  22. package/src/__tests__/onboarding-helper.test.ts +331 -0
  23. package/src/__tests__/path-helper.test.ts +152 -0
  24. package/src/__tests__/permissions.test.tsx +81 -0
  25. package/src/__tests__/request-emoji-limit.test.ts +172 -0
  26. package/src/__tests__/search-helper.test.ts +51 -0
  27. package/src/__tests__/storage-display-name.test.ts +37 -0
  28. package/src/__tests__/storage-path.test.ts +238 -0
  29. package/src/__tests__/tag-utils.test.ts +205 -0
  30. package/src/__tests__/task-description-yjs-state.test.ts +581 -0
  31. package/src/__tests__/task-helper-board-api-routing.test.ts +94 -0
  32. package/src/__tests__/task-helper-create-task.test.ts +129 -0
  33. package/src/__tests__/task-helpers.test.ts +464 -0
  34. package/src/__tests__/task-overrides.test.ts +305 -0
  35. package/src/__tests__/task-reorder-cache.test.ts +74 -0
  36. package/src/__tests__/task-sort-keys.test.ts +36 -0
  37. package/src/__tests__/task-transformers.test.ts +62 -0
  38. package/src/__tests__/text-helper.test.ts +776 -0
  39. package/src/__tests__/time-helper.test.ts +70 -0
  40. package/src/__tests__/time-tracker-period.test.ts +55 -0
  41. package/src/__tests__/timezone.test.ts +117 -0
  42. package/src/__tests__/upstash-rest.test.ts +77 -0
  43. package/src/__tests__/uuid-helper.test.ts +133 -0
  44. package/src/__tests__/workspace-helper.test.ts +859 -0
  45. package/src/__tests__/workspace-limits.test.ts +255 -0
  46. package/src/__tests__/yjs-helper.test.ts +581 -0
  47. package/src/abuse-protection/__tests__/backend-rate-limit.test.ts +113 -0
  48. package/src/abuse-protection/__tests__/edge.test.ts +136 -0
  49. package/src/abuse-protection/__tests__/index.test.ts +562 -0
  50. package/src/abuse-protection/__tests__/reputation.test.ts +192 -0
  51. package/src/abuse-protection/backend-rate-limit.ts +44 -0
  52. package/src/abuse-protection/constants.ts +117 -0
  53. package/src/abuse-protection/edge.ts +223 -0
  54. package/src/abuse-protection/index.ts +1545 -0
  55. package/src/abuse-protection/reputation.ts +587 -0
  56. package/src/abuse-protection/types.ts +97 -0
  57. package/src/abuse-protection/user-agent.ts +124 -0
  58. package/src/abuse-protection/user-suspension.ts +231 -0
  59. package/src/ai-temp-auth.ts +315 -0
  60. package/src/api-proxy-guard.ts +965 -0
  61. package/src/app-url.ts +96 -0
  62. package/src/avatar-url.ts +64 -0
  63. package/src/break-duration.ts +84 -0
  64. package/src/calendar-auth-token.test.ts +37 -0
  65. package/src/calendar-auth-token.ts +19 -0
  66. package/src/calendar-sync-coordination.md +197 -0
  67. package/src/calendar-utils.test.ts +169 -0
  68. package/src/calendar-utils.ts +91 -0
  69. package/src/color-helper.ts +110 -0
  70. package/src/common/nextjs.tsx +99 -0
  71. package/src/common/scan.tsx +15 -0
  72. package/src/configs/reports.ts +160 -0
  73. package/src/constants.ts +85 -0
  74. package/src/crypto.ts +21 -0
  75. package/src/currencies.ts +97 -0
  76. package/src/date-helper.ts +313 -0
  77. package/src/editor/convert-to-task.ts +264 -0
  78. package/src/editor/index.ts +5 -0
  79. package/src/email/__tests__/client.test.ts +141 -0
  80. package/src/email/__tests__/validation.test.ts +46 -0
  81. package/src/email/client.ts +92 -0
  82. package/src/email/server.ts +128 -0
  83. package/src/email/validation.ts +11 -0
  84. package/src/encryption/__tests__/calendar-events.test.ts +411 -0
  85. package/src/encryption/__tests__/configuration.test.ts +114 -0
  86. package/src/encryption/__tests__/field-encryption.test.ts +232 -0
  87. package/src/encryption/__tests__/key-generation.test.ts +30 -0
  88. package/src/encryption/__tests__/performance-edge-cases.test.ts +187 -0
  89. package/src/encryption/__tests__/test-helpers.ts +22 -0
  90. package/src/encryption/__tests__/workspace-key-encryption.test.ts +129 -0
  91. package/src/encryption/encryption-service.ts +343 -0
  92. package/src/encryption/index.ts +25 -0
  93. package/src/encryption/types.ts +57 -0
  94. package/src/exchange-rates.ts +49 -0
  95. package/src/feature-flags/__tests__/feature-flags.test.ts +302 -0
  96. package/src/feature-flags/core.ts +322 -0
  97. package/src/feature-flags/data.ts +16 -0
  98. package/src/feature-flags/default.ts +18 -0
  99. package/src/feature-flags/index.ts +7 -0
  100. package/src/feature-flags/requestable-features.ts +79 -0
  101. package/src/feature-flags/types.ts +4 -0
  102. package/src/fetcher.ts +2 -0
  103. package/src/finance/index.ts +4 -0
  104. package/src/finance/interest-calculator.ts +456 -0
  105. package/src/finance/interest-detector.ts +141 -0
  106. package/src/finance/transform-invoice-results.ts +219 -0
  107. package/src/finance/wallet-permissions.test.ts +169 -0
  108. package/src/finance/wallet-permissions.ts +82 -0
  109. package/src/format.ts +120 -1
  110. package/src/generated/platform-build-metadata.ts +11 -0
  111. package/src/hooks/use-platform.ts +64 -0
  112. package/src/html-sanitizer.ts +155 -0
  113. package/src/internal-domains.ts +497 -0
  114. package/src/keyboard-preset.ts +109 -0
  115. package/src/label-colors.ts +213 -0
  116. package/src/launchable-apps.test.ts +126 -0
  117. package/src/launchable-apps.ts +490 -0
  118. package/src/name-helper.ts +269 -0
  119. package/src/next-config.test.ts +234 -0
  120. package/src/next-config.ts +203 -0
  121. package/src/node-diff.ts +375 -0
  122. package/src/notification-service.ts +379 -0
  123. package/src/nova/scores/__tests__/calculate.test.ts +254 -0
  124. package/src/nova/scores/calculate.ts +132 -0
  125. package/src/nova/submissions/check-permission.ts +132 -0
  126. package/src/onboarding-helper.ts +213 -0
  127. package/src/path-helper.ts +93 -0
  128. package/src/permissions.tsx +1170 -0
  129. package/src/plan-helpers.test.ts +188 -0
  130. package/src/plan-helpers.ts +80 -0
  131. package/src/platform-release.test.ts +74 -0
  132. package/src/platform-release.ts +155 -0
  133. package/src/portless.ts +124 -0
  134. package/src/priority-styles.ts +42 -0
  135. package/src/request-emoji-limit.ts +335 -0
  136. package/src/search-helper.ts +18 -0
  137. package/src/search.test.ts +89 -0
  138. package/src/search.ts +355 -0
  139. package/src/storage-display-name.ts +30 -0
  140. package/src/storage-path.ts +147 -0
  141. package/src/tag-utils.ts +159 -0
  142. package/src/task/reorder.ts +245 -0
  143. package/src/task/transformers.ts +149 -0
  144. package/src/task-date-timezone.ts +133 -0
  145. package/src/task-description-content.ts +240 -0
  146. package/src/task-helper/board.ts +193 -0
  147. package/src/task-helper/bulk-actions.ts +564 -0
  148. package/src/task-helper/personal-external-staging.ts +21 -0
  149. package/src/task-helper/recycle-bin.ts +202 -0
  150. package/src/task-helper/relationships.ts +346 -0
  151. package/src/task-helper/shared.ts +109 -0
  152. package/src/task-helper/sort-keys.ts +337 -0
  153. package/src/task-helper/task-hooks-basic.ts +342 -0
  154. package/src/task-helper/task-hooks-move.ts +264 -0
  155. package/src/task-helper/task-operations.ts +278 -0
  156. package/src/task-helper.ts +12 -0
  157. package/src/task-helpers.ts +241 -0
  158. package/src/task-list-status.ts +62 -0
  159. package/src/task-overrides.ts +82 -0
  160. package/src/task-snapshot.ts +374 -0
  161. package/src/text-diff.ts +81 -0
  162. package/src/text-helper.ts +537 -0
  163. package/src/time-helper.ts +63 -0
  164. package/src/time-tracker-period.ts +73 -0
  165. package/src/timeblock-helper.ts +418 -0
  166. package/src/timezone.ts +190 -0
  167. package/src/timezones.json +1271 -0
  168. package/src/upstash-rest.ts +56 -0
  169. package/src/user-helper.ts +296 -0
  170. package/src/uuid-helper.ts +11 -0
  171. package/src/workspace-handle.ts +10 -0
  172. package/src/workspace-helper.ts +1408 -0
  173. package/src/workspace-limits.ts +68 -0
  174. package/src/yjs-helper.ts +217 -0
  175. package/src/yjs-task-description.ts +81 -0
  176. package/tsconfig.json +3 -5
  177. package/tsconfig.typecheck.json +33 -0
  178. package/vitest.config.ts +36 -0
  179. package/dist/index.d.ts +0 -8
  180. package/dist/index.js +0 -2
  181. package/dist/index.js.map +0 -1
  182. package/dist/index.mjs +0 -2
  183. package/dist/index.mjs.map +0 -1
  184. package/eslint.config.mjs +0 -20
  185. package/rollup.config.js +0 -41
  186. package/src/index.ts +0 -1
@@ -0,0 +1,205 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import {
3
+ DEFAULT_TAG_COLOR,
4
+ getAvailableTagColors,
5
+ getTagColor,
6
+ getTagColorClass,
7
+ getTagColorStyling,
8
+ } from '../tag-utils';
9
+
10
+ describe('Tag Utils', () => {
11
+ describe('getTagColor', () => {
12
+ it('returns default colors for empty string', () => {
13
+ const result = getTagColor('');
14
+ expect(result['--tag-bg-color']).toBe('rgb(75 85 99 / 0.2)');
15
+ expect(result['--tag-text-color']).toBe('rgb(209 213 219)');
16
+ expect(result['--tag-border-color']).toBe('rgb(75 85 99 / 0.4)');
17
+ });
18
+
19
+ it('returns default colors for null input', () => {
20
+ const result = getTagColor(null as any);
21
+ expect(result['--tag-bg-color']).toBe('rgb(75 85 99 / 0.2)');
22
+ });
23
+
24
+ it('returns default colors for undefined input', () => {
25
+ const result = getTagColor(undefined as any);
26
+ expect(result['--tag-bg-color']).toBe('rgb(75 85 99 / 0.2)');
27
+ });
28
+
29
+ it('returns consistent colors for the same tag', () => {
30
+ const result1 = getTagColor('urgent');
31
+ const result2 = getTagColor('urgent');
32
+ expect(result1).toEqual(result2);
33
+ });
34
+
35
+ it('returns different colors for different tags', () => {
36
+ const result1 = getTagColor('urgent');
37
+ const result2 = getTagColor('feature');
38
+ // At least one color should differ
39
+ expect(
40
+ result1['--tag-bg-color'] !== result2['--tag-bg-color'] ||
41
+ result1['--tag-text-color'] !== result2['--tag-text-color']
42
+ ).toBe(true);
43
+ });
44
+
45
+ it('returns HSL-formatted colors', () => {
46
+ const result = getTagColor('test');
47
+ expect(result['--tag-bg-color']).toMatch(
48
+ /^hsl\(\d+ \d+% \d+% \/ [\d.]+\)$/
49
+ );
50
+ expect(result['--tag-text-color']).toMatch(/^hsl\(\d+ \d+% \d+%\)$/);
51
+ expect(result['--tag-border-color']).toMatch(
52
+ /^hsl\(\d+ \d+% \d+% \/ [\d.]+\)$/
53
+ );
54
+ });
55
+
56
+ it('handles tags with special characters', () => {
57
+ const result = getTagColor('tag-with-dash');
58
+ expect(result['--tag-bg-color']).toBeDefined();
59
+ });
60
+
61
+ it('handles tags with numbers', () => {
62
+ const result = getTagColor('tag123');
63
+ expect(result['--tag-bg-color']).toBeDefined();
64
+ });
65
+
66
+ it('handles tags with spaces', () => {
67
+ const result = getTagColor('tag with spaces');
68
+ expect(result['--tag-bg-color']).toBeDefined();
69
+ });
70
+
71
+ it('is case insensitive for color generation', () => {
72
+ const result1 = getTagColor('Urgent');
73
+ const result2 = getTagColor('urgent');
74
+ expect(result1).toEqual(result2);
75
+ });
76
+
77
+ it('trims whitespace for consistent hashing', () => {
78
+ const result1 = getTagColor(' test ');
79
+ const result2 = getTagColor('test');
80
+ expect(result1).toEqual(result2);
81
+ });
82
+
83
+ it('returns all three CSS variables', () => {
84
+ const result = getTagColor('test');
85
+ expect(result).toHaveProperty('--tag-bg-color');
86
+ expect(result).toHaveProperty('--tag-text-color');
87
+ expect(result).toHaveProperty('--tag-border-color');
88
+ });
89
+ });
90
+
91
+ describe('getTagColorClass', () => {
92
+ it('returns Tailwind classes using CSS variables', () => {
93
+ const result = getTagColorClass();
94
+ expect(result).toContain('bg-[var(--tag-bg-color)]');
95
+ expect(result).toContain('text-[var(--tag-text-color)]');
96
+ expect(result).toContain('border-[var(--tag-border-color)]');
97
+ });
98
+
99
+ it('returns the same class on multiple calls', () => {
100
+ const result1 = getTagColorClass();
101
+ const result2 = getTagColorClass();
102
+ expect(result1).toBe(result2);
103
+ });
104
+ });
105
+
106
+ describe('getTagColorStyling', () => {
107
+ it('returns both style and className', () => {
108
+ const result = getTagColorStyling('test');
109
+ expect(result).toHaveProperty('style');
110
+ expect(result).toHaveProperty('className');
111
+ });
112
+
113
+ it('style contains CSS variables', () => {
114
+ const result = getTagColorStyling('test');
115
+ expect(result.style).toHaveProperty('--tag-bg-color');
116
+ expect(result.style).toHaveProperty('--tag-text-color');
117
+ expect(result.style).toHaveProperty('--tag-border-color');
118
+ });
119
+
120
+ it('className matches getTagColorClass output', () => {
121
+ const result = getTagColorStyling('test');
122
+ expect(result.className).toBe(getTagColorClass());
123
+ });
124
+
125
+ it('style matches getTagColor output', () => {
126
+ const result = getTagColorStyling('test');
127
+ const colors = getTagColor('test');
128
+ expect((result.style as Record<string, string>)['--tag-bg-color']).toBe(
129
+ colors['--tag-bg-color']
130
+ );
131
+ });
132
+ });
133
+
134
+ describe('getAvailableTagColors', () => {
135
+ it('returns an array of color classes', () => {
136
+ const colors = getAvailableTagColors();
137
+ expect(Array.isArray(colors)).toBe(true);
138
+ expect(colors.length).toBeGreaterThan(0);
139
+ });
140
+
141
+ it('returns 12 predefined colors', () => {
142
+ const colors = getAvailableTagColors();
143
+ expect(colors).toHaveLength(12);
144
+ });
145
+
146
+ it('all colors follow the expected pattern', () => {
147
+ const colors = getAvailableTagColors();
148
+ colors.forEach((color) => {
149
+ expect(color).toMatch(
150
+ /^bg-\w+-\d+\/\d+ text-\w+-\d+ border-\w+-\d+\/\d+$/
151
+ );
152
+ });
153
+ });
154
+
155
+ it('includes common color names', () => {
156
+ const colors = getAvailableTagColors();
157
+ const colorString = colors.join(' ');
158
+ expect(colorString).toContain('blue');
159
+ expect(colorString).toContain('green');
160
+ expect(colorString).toContain('red');
161
+ expect(colorString).toContain('purple');
162
+ });
163
+
164
+ it('returns readonly array', () => {
165
+ const colors = getAvailableTagColors();
166
+ // TypeScript prevents modification, but we test the content
167
+ expect(colors[0]).toBe('bg-blue-600/20 text-blue-300 border-blue-600/40');
168
+ });
169
+ });
170
+
171
+ describe('DEFAULT_TAG_COLOR', () => {
172
+ it('is a valid Tailwind class string', () => {
173
+ expect(DEFAULT_TAG_COLOR).toBe(
174
+ 'bg-gray-500/20 text-gray-300 border-gray-500/30'
175
+ );
176
+ });
177
+
178
+ it('uses gray color scheme', () => {
179
+ expect(DEFAULT_TAG_COLOR).toContain('gray');
180
+ });
181
+ });
182
+
183
+ describe('color distribution', () => {
184
+ it('distributes colors reasonably for common tags', () => {
185
+ const commonTags = [
186
+ 'bug',
187
+ 'feature',
188
+ 'urgent',
189
+ 'documentation',
190
+ 'enhancement',
191
+ 'refactor',
192
+ 'test',
193
+ 'design',
194
+ ];
195
+
196
+ const colors = commonTags.map(
197
+ (tag) => getTagColor(tag)['--tag-bg-color']
198
+ );
199
+ const uniqueColors = new Set(colors);
200
+
201
+ // Should have reasonable variety (at least half should be unique)
202
+ expect(uniqueColors.size).toBeGreaterThan(commonTags.length / 2);
203
+ });
204
+ });
205
+ });