@dappermountain/payload-plugin-achievements 1.0.0 → 1.1.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 (217) hide show
  1. package/README.md +6 -5
  2. package/dist/admin/LucideIconField.d.ts +1 -0
  3. package/dist/admin/LucideIconField.d.ts.map +1 -1
  4. package/dist/admin/LucideIconField.js +54 -101
  5. package/dist/admin/ReconcileProgressionButton.d.ts +1 -1
  6. package/dist/admin/ReconcileProgressionButton.d.ts.map +1 -1
  7. package/dist/admin/ReconcileProgressionButton.js +21 -7
  8. package/dist/admin/useEventTypeFlags.d.ts.map +1 -1
  9. package/dist/admin/useEventTypeFlags.js +7 -4
  10. package/dist/admin/usePluginT.d.ts +6 -0
  11. package/dist/admin/usePluginT.d.ts.map +1 -0
  12. package/dist/admin/usePluginT.js +10 -0
  13. package/dist/adminLabel.d.ts +17 -0
  14. package/dist/adminLabel.d.ts.map +1 -0
  15. package/dist/adminLabel.js +28 -0
  16. package/dist/collections/AchievementRequests/hooks/prepareAchievementRequest.d.ts.map +1 -1
  17. package/dist/collections/AchievementRequests/hooks/prepareAchievementRequest.js +8 -7
  18. package/dist/collections/AchievementRequests/index.d.ts.map +1 -1
  19. package/dist/collections/AchievementRequests/index.js +19 -5
  20. package/dist/collections/Achievements/index.d.ts.map +1 -1
  21. package/dist/collections/Achievements/index.js +17 -13
  22. package/dist/collections/EventTypes/index.d.ts.map +1 -1
  23. package/dist/collections/EventTypes/index.js +26 -12
  24. package/dist/collections/Grants/hooks/ensureUniqueGrant.js +2 -2
  25. package/dist/collections/Grants/index.d.ts.map +1 -1
  26. package/dist/collections/Grants/index.js +25 -16
  27. package/dist/collections/Logs/fields/validators.d.ts.map +1 -1
  28. package/dist/collections/Logs/fields/validators.js +8 -7
  29. package/dist/collections/Logs/hooks/ensureTypeRequirements.d.ts.map +1 -1
  30. package/dist/collections/Logs/hooks/ensureTypeRequirements.js +9 -7
  31. package/dist/collections/Logs/index.d.ts.map +1 -1
  32. package/dist/collections/Logs/index.js +33 -15
  33. package/dist/collections/MetricBalances/index.d.ts.map +1 -1
  34. package/dist/collections/MetricBalances/index.js +9 -3
  35. package/dist/collections/Metrics/index.d.ts.map +1 -1
  36. package/dist/collections/Metrics/index.js +35 -16
  37. package/dist/collections/Reactions/index.d.ts.map +1 -1
  38. package/dist/collections/Reactions/index.js +25 -13
  39. package/dist/collections/TierRequests/hooks/prepareTierRequest.d.ts.map +1 -1
  40. package/dist/collections/TierRequests/hooks/prepareTierRequest.js +8 -7
  41. package/dist/collections/TierRequests/index.d.ts.map +1 -1
  42. package/dist/collections/TierRequests/index.js +13 -7
  43. package/dist/collections/Tiers/index.d.ts.map +1 -1
  44. package/dist/collections/Tiers/index.js +17 -7
  45. package/dist/collections/fields/localizedText.d.ts.map +1 -1
  46. package/dist/collections/fields/localizedText.js +3 -0
  47. package/dist/collections/fields/ruleFields.d.ts.map +1 -1
  48. package/dist/collections/fields/ruleFields.js +25 -16
  49. package/dist/collections/fields/scopeField.d.ts.map +1 -1
  50. package/dist/collections/fields/scopeField.js +3 -1
  51. package/dist/collections/fields/userField.d.ts.map +1 -1
  52. package/dist/collections/fields/userField.js +2 -0
  53. package/dist/collections/fields/usersAchievementsGroup.d.ts.map +1 -1
  54. package/dist/collections/fields/usersAchievementsGroup.js +2 -1
  55. package/dist/collections/helpers.d.ts.map +1 -1
  56. package/dist/collections/helpers.js +2 -1
  57. package/dist/collections/hooks/preventCatalogDelete.d.ts.map +1 -1
  58. package/dist/collections/hooks/preventCatalogDelete.js +6 -3
  59. package/dist/collections/slugs.d.ts +5 -2
  60. package/dist/collections/slugs.d.ts.map +1 -1
  61. package/dist/collections/slugs.js +7 -5
  62. package/dist/defaults.d.ts +1 -1
  63. package/dist/defaults.d.ts.map +1 -1
  64. package/dist/extensions/actions.d.ts.map +1 -1
  65. package/dist/extensions/actions.js +2 -1
  66. package/dist/extensions/elapsedSinceOptions.d.ts +1 -1
  67. package/dist/extensions/elapsedSinceOptions.d.ts.map +1 -1
  68. package/dist/extensions/elapsedSinceOptions.js +4 -3
  69. package/dist/index.d.ts +3 -0
  70. package/dist/index.d.ts.map +1 -1
  71. package/dist/index.js +3 -0
  72. package/dist/plugin.d.ts.map +1 -1
  73. package/dist/plugin.js +20 -0
  74. package/dist/translations/index.d.ts +8723 -0
  75. package/dist/translations/index.d.ts.map +1 -0
  76. package/dist/translations/index.js +96 -0
  77. package/dist/translations/keys.d.ts +4 -0
  78. package/dist/translations/keys.d.ts.map +1 -0
  79. package/dist/translations/keys.js +5 -0
  80. package/dist/translations/languages/ar.d.ts +199 -0
  81. package/dist/translations/languages/ar.d.ts.map +1 -0
  82. package/dist/translations/languages/ar.js +198 -0
  83. package/dist/translations/languages/az.d.ts +199 -0
  84. package/dist/translations/languages/az.d.ts.map +1 -0
  85. package/dist/translations/languages/az.js +198 -0
  86. package/dist/translations/languages/bg.d.ts +199 -0
  87. package/dist/translations/languages/bg.d.ts.map +1 -0
  88. package/dist/translations/languages/bg.js +198 -0
  89. package/dist/translations/languages/bnBd.d.ts +199 -0
  90. package/dist/translations/languages/bnBd.d.ts.map +1 -0
  91. package/dist/translations/languages/bnBd.js +198 -0
  92. package/dist/translations/languages/bnIn.d.ts +199 -0
  93. package/dist/translations/languages/bnIn.d.ts.map +1 -0
  94. package/dist/translations/languages/bnIn.js +198 -0
  95. package/dist/translations/languages/ca.d.ts +199 -0
  96. package/dist/translations/languages/ca.d.ts.map +1 -0
  97. package/dist/translations/languages/ca.js +198 -0
  98. package/dist/translations/languages/cs.d.ts +199 -0
  99. package/dist/translations/languages/cs.d.ts.map +1 -0
  100. package/dist/translations/languages/cs.js +198 -0
  101. package/dist/translations/languages/da.d.ts +199 -0
  102. package/dist/translations/languages/da.d.ts.map +1 -0
  103. package/dist/translations/languages/da.js +198 -0
  104. package/dist/translations/languages/de.d.ts +199 -0
  105. package/dist/translations/languages/de.d.ts.map +1 -0
  106. package/dist/translations/languages/de.js +198 -0
  107. package/dist/translations/languages/en.d.ts +199 -0
  108. package/dist/translations/languages/en.d.ts.map +1 -0
  109. package/dist/translations/languages/en.js +198 -0
  110. package/dist/translations/languages/es.d.ts +199 -0
  111. package/dist/translations/languages/es.d.ts.map +1 -0
  112. package/dist/translations/languages/es.js +198 -0
  113. package/dist/translations/languages/et.d.ts +199 -0
  114. package/dist/translations/languages/et.d.ts.map +1 -0
  115. package/dist/translations/languages/et.js +198 -0
  116. package/dist/translations/languages/fa.d.ts +199 -0
  117. package/dist/translations/languages/fa.d.ts.map +1 -0
  118. package/dist/translations/languages/fa.js +198 -0
  119. package/dist/translations/languages/fr.d.ts +199 -0
  120. package/dist/translations/languages/fr.d.ts.map +1 -0
  121. package/dist/translations/languages/fr.js +198 -0
  122. package/dist/translations/languages/he.d.ts +199 -0
  123. package/dist/translations/languages/he.d.ts.map +1 -0
  124. package/dist/translations/languages/he.js +198 -0
  125. package/dist/translations/languages/hr.d.ts +199 -0
  126. package/dist/translations/languages/hr.d.ts.map +1 -0
  127. package/dist/translations/languages/hr.js +198 -0
  128. package/dist/translations/languages/hu.d.ts +199 -0
  129. package/dist/translations/languages/hu.d.ts.map +1 -0
  130. package/dist/translations/languages/hu.js +198 -0
  131. package/dist/translations/languages/hy.d.ts +199 -0
  132. package/dist/translations/languages/hy.d.ts.map +1 -0
  133. package/dist/translations/languages/hy.js +198 -0
  134. package/dist/translations/languages/id.d.ts +199 -0
  135. package/dist/translations/languages/id.d.ts.map +1 -0
  136. package/dist/translations/languages/id.js +198 -0
  137. package/dist/translations/languages/is.d.ts +199 -0
  138. package/dist/translations/languages/is.d.ts.map +1 -0
  139. package/dist/translations/languages/is.js +198 -0
  140. package/dist/translations/languages/it.d.ts +199 -0
  141. package/dist/translations/languages/it.d.ts.map +1 -0
  142. package/dist/translations/languages/it.js +198 -0
  143. package/dist/translations/languages/ja.d.ts +199 -0
  144. package/dist/translations/languages/ja.d.ts.map +1 -0
  145. package/dist/translations/languages/ja.js +198 -0
  146. package/dist/translations/languages/ko.d.ts +199 -0
  147. package/dist/translations/languages/ko.d.ts.map +1 -0
  148. package/dist/translations/languages/ko.js +198 -0
  149. package/dist/translations/languages/lt.d.ts +199 -0
  150. package/dist/translations/languages/lt.d.ts.map +1 -0
  151. package/dist/translations/languages/lt.js +198 -0
  152. package/dist/translations/languages/lv.d.ts +199 -0
  153. package/dist/translations/languages/lv.d.ts.map +1 -0
  154. package/dist/translations/languages/lv.js +198 -0
  155. package/dist/translations/languages/my.d.ts +199 -0
  156. package/dist/translations/languages/my.d.ts.map +1 -0
  157. package/dist/translations/languages/my.js +198 -0
  158. package/dist/translations/languages/nb.d.ts +199 -0
  159. package/dist/translations/languages/nb.d.ts.map +1 -0
  160. package/dist/translations/languages/nb.js +198 -0
  161. package/dist/translations/languages/nl.d.ts +199 -0
  162. package/dist/translations/languages/nl.d.ts.map +1 -0
  163. package/dist/translations/languages/nl.js +198 -0
  164. package/dist/translations/languages/pl.d.ts +199 -0
  165. package/dist/translations/languages/pl.d.ts.map +1 -0
  166. package/dist/translations/languages/pl.js +198 -0
  167. package/dist/translations/languages/pt.d.ts +199 -0
  168. package/dist/translations/languages/pt.d.ts.map +1 -0
  169. package/dist/translations/languages/pt.js +198 -0
  170. package/dist/translations/languages/ro.d.ts +199 -0
  171. package/dist/translations/languages/ro.d.ts.map +1 -0
  172. package/dist/translations/languages/ro.js +198 -0
  173. package/dist/translations/languages/rs.d.ts +199 -0
  174. package/dist/translations/languages/rs.d.ts.map +1 -0
  175. package/dist/translations/languages/rs.js +198 -0
  176. package/dist/translations/languages/rsLatin.d.ts +199 -0
  177. package/dist/translations/languages/rsLatin.d.ts.map +1 -0
  178. package/dist/translations/languages/rsLatin.js +198 -0
  179. package/dist/translations/languages/ru.d.ts +199 -0
  180. package/dist/translations/languages/ru.d.ts.map +1 -0
  181. package/dist/translations/languages/ru.js +198 -0
  182. package/dist/translations/languages/sk.d.ts +199 -0
  183. package/dist/translations/languages/sk.d.ts.map +1 -0
  184. package/dist/translations/languages/sk.js +198 -0
  185. package/dist/translations/languages/sl.d.ts +199 -0
  186. package/dist/translations/languages/sl.d.ts.map +1 -0
  187. package/dist/translations/languages/sl.js +198 -0
  188. package/dist/translations/languages/sv.d.ts +199 -0
  189. package/dist/translations/languages/sv.d.ts.map +1 -0
  190. package/dist/translations/languages/sv.js +198 -0
  191. package/dist/translations/languages/ta.d.ts +199 -0
  192. package/dist/translations/languages/ta.d.ts.map +1 -0
  193. package/dist/translations/languages/ta.js +198 -0
  194. package/dist/translations/languages/th.d.ts +199 -0
  195. package/dist/translations/languages/th.d.ts.map +1 -0
  196. package/dist/translations/languages/th.js +198 -0
  197. package/dist/translations/languages/tr.d.ts +199 -0
  198. package/dist/translations/languages/tr.d.ts.map +1 -0
  199. package/dist/translations/languages/tr.js +198 -0
  200. package/dist/translations/languages/uk.d.ts +199 -0
  201. package/dist/translations/languages/uk.d.ts.map +1 -0
  202. package/dist/translations/languages/uk.js +198 -0
  203. package/dist/translations/languages/vi.d.ts +199 -0
  204. package/dist/translations/languages/vi.d.ts.map +1 -0
  205. package/dist/translations/languages/vi.js +198 -0
  206. package/dist/translations/languages/zh.d.ts +199 -0
  207. package/dist/translations/languages/zh.d.ts.map +1 -0
  208. package/dist/translations/languages/zh.js +198 -0
  209. package/dist/translations/languages/zhTw.d.ts +199 -0
  210. package/dist/translations/languages/zhTw.d.ts.map +1 -0
  211. package/dist/translations/languages/zhTw.js +198 -0
  212. package/dist/translations/reqT.d.ts +14 -0
  213. package/dist/translations/reqT.d.ts.map +1 -0
  214. package/dist/translations/reqT.js +26 -0
  215. package/dist/types.d.ts +5 -2
  216. package/dist/types.d.ts.map +1 -1
  217. package/package.json +3 -1
@@ -1,3 +1,4 @@
1
+ import { tEntityDescription, tLabel } from '../../adminLabel.js';
1
2
  import { buildRuleTreeFields, localizedDescriptionField, localizedNameField, scopeField } from '../fields/index.js';
2
3
  import { collectionAdmin, columnsWithOptionalScope, optionalFields, slugOf } from '../helpers.js';
3
4
  import { access } from './access/index.js';
@@ -6,15 +7,15 @@ export function buildAchievementsCollection() {
6
7
  return {
7
8
  slug: slugOf('achievements'),
8
9
  labels: {
9
- singular: 'Achievement Definition',
10
- plural: 'Achievement Definitions',
10
+ singular: tLabel('achievementDefinition'),
11
+ plural: tLabel('achievementDefinitions'),
11
12
  },
12
13
  access: { ...access },
13
14
  hooks,
14
15
  admin: collectionAdmin({
15
16
  useAsTitle: 'name',
16
17
  defaultColumns: columnsWithOptionalScope(['name', 'slug', 'lifecycle', 'requiresReview', 'scope']),
17
- description: 'What someone can earn. Set who’s eligible and whether a person on your team needs to approve it.',
18
+ description: tEntityDescription('whatSomeoneCanEarnSetWhoSEligible'),
18
19
  }),
19
20
  fields: [
20
21
  ...optionalFields(scopeField()),
@@ -28,6 +29,7 @@ export function buildAchievementsCollection() {
28
29
  required: true,
29
30
  unique: true,
30
31
  index: true,
32
+ label: tLabel('slug'),
31
33
  admin: { width: '50%' },
32
34
  },
33
35
  ],
@@ -36,8 +38,9 @@ export function buildAchievementsCollection() {
36
38
  {
37
39
  name: 'metadata',
38
40
  type: 'json',
41
+ label: tLabel('metadata'),
39
42
  admin: {
40
- description: 'Optional host/product payload (structure only). Shape is owned by the host — validate with Zod or similar at read/seed time. Do not store localized copy here; use name, description, and host i18n.',
43
+ description: tLabel('optionalHostProductPayloadStructureOnlyShapeIs'),
41
44
  },
42
45
  },
43
46
  {
@@ -45,38 +48,39 @@ export function buildAchievementsCollection() {
45
48
  type: 'select',
46
49
  required: true,
47
50
  defaultValue: 'once',
51
+ label: tLabel('lifecycle'),
48
52
  options: [
49
- { label: 'Once', value: 'once' },
50
- { label: 'Ongoing', value: 'ongoing' },
53
+ { label: tLabel('once'), value: 'once' },
54
+ { label: tLabel('ongoing'), value: 'ongoing' },
51
55
  ],
52
56
  admin: {
53
- description: 'Once: binary grant (create/delete). Ongoing: one grant row whose status can be active, expired, or superseded.',
57
+ description: tLabel('onceBinaryGrantCreateDeleteOngoingOneGrant'),
54
58
  },
55
59
  },
56
60
  {
57
61
  name: 'requiresReview',
58
62
  type: 'checkbox',
59
63
  defaultValue: true,
60
- label: 'Requires review',
64
+ label: tLabel('requiresReview'),
61
65
  admin: {
62
- description: 'When turned off, any pending requests for this achievement are approved automatically (one user at a time via existing grant hooks).',
66
+ description: tLabel('whenTurnedOffAnyPendingRequestsForThis'),
63
67
  },
64
68
  },
65
69
  {
66
70
  name: 'eligibilityRules',
67
71
  type: 'group',
68
- label: 'Eligibility rules',
72
+ label: tLabel('eligibilityRules'),
69
73
  admin: {
70
- description: 'Who may request this achievement. Composed parents that auto-grant should leave this empty.',
74
+ description: tLabel('whoMayRequestThisAchievementComposedParentsThat'),
71
75
  },
72
76
  fields: buildRuleTreeFields({ site: 'eligibility' }),
73
77
  },
74
78
  {
75
79
  name: 'completionRules',
76
80
  type: 'group',
77
- label: 'Completion rules',
81
+ label: tLabel('completionRules'),
78
82
  admin: {
79
- description: 'What this achievement is made of. When every rule passes, it is granted automatically (do not require review on composed parents). Nested achievements appear in this order in your app UI.',
83
+ description: tLabel('whatThisAchievementIsMadeOfWhenEvery'),
80
84
  },
81
85
  fields: buildRuleTreeFields({ site: 'completion' }),
82
86
  },
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/collections/EventTypes/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAS,MAAM,SAAS,CAAA;AAqCtD,wBAAgB,yBAAyB,IAAI,gBAAgB,CA+E5D"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/collections/EventTypes/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAS,MAAM,SAAS,CAAA;AAoCtD,wBAAgB,yBAAyB,IAAI,gBAAgB,CAyF5D"}
@@ -1,3 +1,4 @@
1
+ import { tEntityDescription, tLabel } from '../../adminLabel.js';
1
2
  import { getAchievementOptions } from '../../options-store.js';
2
3
  import { collectionAdmin, collectionOf, columnsWithOptionalScope, optionalFields, slugOf } from '../helpers.js';
3
4
  import { localizedNameField, scopeField } from '../fields/index.js';
@@ -12,9 +13,9 @@ function subjectCatalogFields() {
12
13
  name: 'requiresSubject',
13
14
  type: 'checkbox',
14
15
  defaultValue: false,
15
- label: 'Requires a subject',
16
+ label: tLabel('requiresASubject'),
16
17
  admin: {
17
- description: 'Turn this on when the log points at a host document (for example a post or comment). We’ll ask for that document when it’s logged.',
18
+ description: tLabel('turnThisOnWhenTheLogPointsAt'),
18
19
  },
19
20
  },
20
21
  {
@@ -24,7 +25,7 @@ function subjectCatalogFields() {
24
25
  options: collections.map((slug) => ({ label: slug, value: slug })),
25
26
  admin: {
26
27
  condition: (_, siblingData) => Boolean(siblingData?.requiresSubject),
27
- description: 'Which host collections this type may reference. Leave empty to allow any collection from the plugin subjects allowlist.',
28
+ description: tLabel('whichHostCollectionsThisTypeMayReferenceLeave'),
28
29
  },
29
30
  },
30
31
  ];
@@ -33,6 +34,10 @@ export function buildEventTypesCollection() {
33
34
  const subjectFields = subjectCatalogFields();
34
35
  return {
35
36
  slug: slugOf('eventTypes'),
37
+ labels: {
38
+ singular: tLabel('eventType2'),
39
+ plural: tLabel('eventTypes'),
40
+ },
36
41
  access: { ...access },
37
42
  hooks,
38
43
  admin: collectionAdmin({
@@ -47,7 +52,7 @@ export function buildEventTypesCollection() {
47
52
  'system',
48
53
  'scope',
49
54
  ]),
50
- description: 'Names for things that can happen and show up in the achievement logs.',
55
+ description: tEntityDescription('namesForThingsThatCanHappenAndShow'),
51
56
  }),
52
57
  fields: [
53
58
  ...optionalFields(scopeField()),
@@ -55,34 +60,42 @@ export function buildEventTypesCollection() {
55
60
  type: 'row',
56
61
  fields: [
57
62
  localizedNameField({ width: '50%' }),
58
- { name: 'slug', type: 'text', required: true, unique: true, index: true, admin: { width: '50%' } },
63
+ {
64
+ name: 'slug',
65
+ type: 'text',
66
+ required: true,
67
+ unique: true,
68
+ index: true,
69
+ label: tLabel('slug'),
70
+ admin: { width: '50%' },
71
+ },
59
72
  ],
60
73
  },
61
74
  {
62
75
  name: 'requiresActor',
63
76
  type: 'checkbox',
64
77
  defaultValue: false,
65
- label: 'Requires an actor',
78
+ label: tLabel('requiresAnActor'),
66
79
  admin: {
67
- description: 'Turn this on when someone else caused the entry (for example a peer nomination). We’ll ask for that person when it’s logged.',
80
+ description: tLabel('turnThisOnWhenSomeoneElseCausedThe'),
68
81
  },
69
82
  },
70
83
  {
71
84
  name: 'snapshotActorTiers',
72
85
  type: 'checkbox',
73
86
  defaultValue: false,
74
- label: 'Snapshot actor tiers',
87
+ label: tLabel('snapshotActorTiers'),
75
88
  admin: {
76
- description: 'When this entry is logged, store the actor’s derived ladder rank at write time. Unscoped logs stamp every ladder; scoped logs stamp that tenant plus unscoped ranks. Event count can then require “actor was at least this tier” in the rule’s scope. Does not grant or open requests.',
89
+ description: tLabel('whenThisEntryIsLoggedStoreTheActor'),
77
90
  },
78
91
  },
79
92
  {
80
93
  name: 'requiresMetric',
81
94
  type: 'checkbox',
82
95
  defaultValue: false,
83
- label: 'Adjusts a metric',
96
+ label: tLabel('adjustsAMetric'),
84
97
  admin: {
85
- description: 'Turn this on when the entry changes a score (like points). We’ll ask which metric and by how much.',
98
+ description: tLabel('turnThisOnWhenTheEntryChangesA'),
86
99
  },
87
100
  },
88
101
  ...subjectFields,
@@ -90,9 +103,10 @@ export function buildEventTypesCollection() {
90
103
  name: 'system',
91
104
  type: 'checkbox',
92
105
  defaultValue: false,
106
+ label: tLabel('system'),
93
107
  admin: {
94
108
  readOnly: true,
95
- description: 'Built-in type. It can’t be deleted.',
109
+ description: tLabel('builtInTypeItCanTBeDeleted'),
96
110
  },
97
111
  },
98
112
  {
@@ -1,6 +1,6 @@
1
- import { APIError } from 'payload';
2
1
  import { collectionOf } from '../../helpers.js';
3
2
  import { relationId } from '../../../services/achievement/relationId.js';
3
+ import { throwApiError } from '../../../translations/reqT.js';
4
4
  /** Reject a second grant of the same achievement for the same user (+ scope). */
5
5
  export const ensureUniqueGrant = async ({ data, originalDoc, operation, req, }) => {
6
6
  if (!req?.payload || !data)
@@ -28,7 +28,7 @@ export const ensureUniqueGrant = async ({ data, originalDoc, operation, req, })
28
28
  });
29
29
  const other = existing.docs[0];
30
30
  if (other && (operation === 'create' || relationId(other.id) !== relationId(originalDoc?.id))) {
31
- throw new APIError('This achievement is already granted to that user for this scope.', 400);
31
+ throwApiError(req, 'errorAlreadyGranted', 400);
32
32
  }
33
33
  return data;
34
34
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/collections/Grants/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAS,MAAM,SAAS,CAAA;AAQtD,wBAAgB,qBAAqB,IAAI,gBAAgB,CA4GxD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/collections/Grants/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAS,MAAM,SAAS,CAAA;AAStD,wBAAgB,qBAAqB,IAAI,gBAAgB,CAkHxD"}
@@ -1,18 +1,21 @@
1
+ import { tEntityDescription, tLabel } from '../../adminLabel.js';
1
2
  import { collectionAdmin, collectionOf, columnsWithOptionalScope, optionalFields, slugOf } from '../helpers.js';
2
3
  import { scopeField, userField } from '../fields/index.js';
3
4
  import { getAchievementOptions } from '../../options-store.js';
4
5
  import { access } from './access/index.js';
5
6
  import { hooks } from './hooks/index.js';
6
7
  export function buildGrantsCollection() {
7
- const reconcilePath = getAchievementOptions().endpoints?.reconcile;
8
- const apiPath = typeof reconcilePath === 'string' && reconcilePath.length > 0
9
- ? `/api${reconcilePath.startsWith('/') ? reconcilePath : `/${reconcilePath}`}`
8
+ const reconcileEndpoint = getAchievementOptions().endpoints?.reconcile;
9
+ const reconcilePath = typeof reconcileEndpoint === 'string' && reconcileEndpoint.length > 0
10
+ ? reconcileEndpoint.startsWith('/')
11
+ ? reconcileEndpoint
12
+ : `/${reconcileEndpoint}`
10
13
  : null;
11
14
  return {
12
15
  slug: slugOf('grants'),
13
16
  labels: {
14
- singular: 'Achievement Grant',
15
- plural: 'Achievement Grants',
17
+ singular: tLabel('achievementGrant'),
18
+ plural: tLabel('achievementGrants'),
16
19
  },
17
20
  access: { ...access },
18
21
  hooks,
@@ -20,14 +23,14 @@ export function buildGrantsCollection() {
20
23
  useAsTitle: 'title',
21
24
  defaultColumns: columnsWithOptionalScope(['title', 'user', 'status', 'completedAt', 'scope']),
22
25
  listSearchableFields: ['title'],
23
- description: 'What someone has earned — one row per user and achievement (+ scope). Creating or deleting a grant updates logs and composed progression. Ongoing definitions keep the row and change status instead of deleting.',
24
- ...(apiPath
26
+ description: tEntityDescription('whatSomeoneHasEarnedOneRowPerUser'),
27
+ ...(reconcilePath
25
28
  ? {
26
29
  components: {
27
30
  beforeListTable: [
28
31
  {
29
32
  path: '@dappermountain/payload-plugin-achievements/client#ReconcileProgressionButton',
30
- clientProps: { reconcilePath: apiPath },
33
+ clientProps: { reconcilePath },
31
34
  },
32
35
  ],
33
36
  },
@@ -39,9 +42,10 @@ export function buildGrantsCollection() {
39
42
  name: 'title',
40
43
  type: 'text',
41
44
  index: true,
45
+ label: tLabel('title'),
42
46
  admin: {
43
47
  readOnly: true,
44
- description: 'Copied from the achievement name for lists and search.',
48
+ description: tLabel('copiedFromTheAchievementNameForListsAnd'),
45
49
  },
46
50
  },
47
51
  ...optionalFields(scopeField()),
@@ -55,6 +59,7 @@ export function buildGrantsCollection() {
55
59
  relationTo: collectionOf('achievements'),
56
60
  required: true,
57
61
  index: true,
62
+ label: tLabel('achievement'),
58
63
  admin: { width: '60%' },
59
64
  },
60
65
  {
@@ -75,13 +80,14 @@ export function buildGrantsCollection() {
75
80
  required: true,
76
81
  defaultValue: 'active',
77
82
  index: true,
83
+ label: tLabel('status'),
78
84
  options: [
79
- { label: 'Active', value: 'active' },
80
- { label: 'Expired', value: 'expired' },
81
- { label: 'Superseded', value: 'superseded' },
85
+ { label: tLabel('active'), value: 'active' },
86
+ { label: tLabel('expired'), value: 'expired' },
87
+ { label: tLabel('superseded'), value: 'superseded' },
82
88
  ],
83
89
  admin: {
84
- description: 'Standing for ongoing achievements. Once achievements stay active until the grant is deleted. Prefer renew / expire / supersede helpers over editing this by hand.',
90
+ description: tLabel('standingForOngoingAchievementsOnceAchievementsStayActive'),
85
91
  },
86
92
  },
87
93
  {
@@ -89,7 +95,7 @@ export function buildGrantsCollection() {
89
95
  type: 'date',
90
96
  admin: {
91
97
  date: { pickerAppearance: 'dayAndTime' },
92
- description: 'Last renew time for an ongoing grant.',
98
+ description: tLabel('lastRenewTimeForAnOngoingGrant'),
93
99
  },
94
100
  },
95
101
  {
@@ -97,13 +103,16 @@ export function buildGrantsCollection() {
97
103
  type: 'relationship',
98
104
  relationTo: collectionOf('grants'),
99
105
  admin: {
100
- description: 'Grant that replaced this one when status is superseded.',
106
+ description: tLabel('grantThatReplacedThisOneWhenStatusIs'),
101
107
  },
102
108
  },
103
109
  {
104
110
  name: 'note',
105
111
  type: 'textarea',
106
- admin: { description: 'Optional note about why this was granted.' },
112
+ label: tLabel('note'),
113
+ admin: {
114
+ description: tLabel('optionalNoteAboutWhyThisWasGranted'),
115
+ },
107
116
  },
108
117
  ],
109
118
  };
@@ -1 +1 @@
1
- {"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../../../src/collections/Logs/fields/validators.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAavC,eAAO,MAAM,aAAa,EAAE,QAW3B,CAAA;AAED,eAAO,MAAM,cAAc,EAAE,QA0B5B,CAAA;AAED,eAAO,MAAM,cAAc,EAAE,QAW5B,CAAA;AAED,eAAO,MAAM,eAAe,EAAE,QAqC7B,CAAA"}
1
+ {"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../../../src/collections/Logs/fields/validators.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAcvC,eAAO,MAAM,aAAa,EAAE,QAW3B,CAAA;AAED,eAAO,MAAM,cAAc,EAAE,QA0B5B,CAAA;AAED,eAAO,MAAM,cAAc,EAAE,QAW5B,CAAA;AAED,eAAO,MAAM,eAAe,EAAE,QAqC7B,CAAA"}
@@ -3,6 +3,7 @@ import { collectionOf } from '../../../collections/helpers.js';
3
3
  import { eventTypeRequiresActor, eventTypeRequiresMetric, eventTypeSubjectRelationTo, getEventTypeFlags, } from '../../../services/achievement/eventTypeRequiresActor.js';
4
4
  import { readLogSubject } from '../../../services/achievement/logSubject.js';
5
5
  import { relationId } from '../../../services/achievement/relationId.js';
6
+ import { reqT } from '../../../translations/reqT.js';
6
7
  export const validateActor = async (value, { data, req }) => {
7
8
  if (!req?.payload)
8
9
  return true;
@@ -13,7 +14,7 @@ export const validateActor = async (value, { data, req }) => {
13
14
  return true;
14
15
  }
15
16
  if (!relationId(value)) {
16
- return 'This log type needs an actor (who caused it).';
17
+ return reqT(req, 'validationNeedsActor');
17
18
  }
18
19
  return true;
19
20
  };
@@ -28,7 +29,7 @@ export const validateMetric = async (value, { data, req }) => {
28
29
  }
29
30
  const metricId = relationId(value);
30
31
  if (!metricId) {
31
- return 'This log type needs a metric.';
32
+ return reqT(req, 'validationNeedsMetric');
32
33
  }
33
34
  const metric = (await req.payload.findByID({
34
35
  collection: collectionOf('metrics'),
@@ -39,7 +40,7 @@ export const validateMetric = async (value, { data, req }) => {
39
40
  select: { kind: true, name: true, slug: true },
40
41
  }));
41
42
  if (metric && (metric.kind ?? 'stored') === 'computed') {
42
- return 'Computed metrics (for example Days) cannot be changed with a metric delta. Use a stored metric such as Points.';
43
+ return reqT(req, 'validationComputedMetricDelta');
43
44
  }
44
45
  return true;
45
46
  };
@@ -53,7 +54,7 @@ export const validateChange = async (value, { data, req }) => {
53
54
  return true;
54
55
  }
55
56
  if (typeof value !== 'number' || Number.isNaN(value)) {
56
- return 'This log type needs a change amount.';
57
+ return reqT(req, 'validationNeedsChange');
57
58
  }
58
59
  return true;
59
60
  };
@@ -76,10 +77,10 @@ export const validateSubject = async (value, { data, req }) => {
76
77
  return true;
77
78
  }
78
79
  if (!subject) {
79
- return 'This log type needs a subject (the host document it is about).';
80
+ return reqT(req, 'validationNeedsSubject');
80
81
  }
81
82
  if (!allowlist.includes(subject.relationTo)) {
82
- return `Subject collection "${subject.relationTo}" is not in the plugin subjects allowlist.`;
83
+ return reqT(req, 'validationSubjectNotAllowlisted', { collection: subject.relationTo });
83
84
  }
84
85
  const allowed = await eventTypeSubjectRelationTo({
85
86
  payload: req.payload,
@@ -87,7 +88,7 @@ export const validateSubject = async (value, { data, req }) => {
87
88
  typeIdOrDoc: typeId,
88
89
  });
89
90
  if (allowed.length > 0 && !allowed.includes(subject.relationTo)) {
90
- return `This log type only allows subjects from: ${allowed.join(', ')}.`;
91
+ return reqT(req, 'validationSubjectNotAllowed', { collections: allowed.join(', ') });
91
92
  }
92
93
  return true;
93
94
  };
@@ -1 +1 @@
1
- {"version":3,"file":"ensureTypeRequirements.d.ts","sourceRoot":"","sources":["../../../../src/collections/Logs/hooks/ensureTypeRequirements.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,SAAS,CAAA;AAc3D,eAAO,MAAM,sBAAsB,EAAE,4BA+DpC,CAAA"}
1
+ {"version":3,"file":"ensureTypeRequirements.d.ts","sourceRoot":"","sources":["../../../../src/collections/Logs/hooks/ensureTypeRequirements.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,SAAS,CAAA;AAY3D,eAAO,MAAM,sBAAsB,EAAE,4BA2DpC,CAAA"}
@@ -1,9 +1,9 @@
1
- import { APIError } from 'payload';
2
1
  import { getAchievementOptions } from '../../../options-store.js';
3
2
  import { collectionOf } from '../../../collections/helpers.js';
4
3
  import { eventTypeSubjectRelationTo, getEventTypeFlags, } from '../../../services/achievement/eventTypeRequiresActor.js';
5
4
  import { readLogSubject } from '../../../services/achievement/logSubject.js';
6
5
  import { relationId } from '../../../services/achievement/relationId.js';
6
+ import { throwApiError } from '../../../translations/reqT.js';
7
7
  export const ensureTypeRequirements = async ({ data, req }) => {
8
8
  if (!data)
9
9
  return data;
@@ -16,16 +16,16 @@ export const ensureTypeRequirements = async ({ data, req }) => {
16
16
  typeIdOrDoc: typeId,
17
17
  });
18
18
  if (flags.requiresActor && !relationId(data.actor)) {
19
- throw new APIError('This log type needs an actor (who caused it).', 400);
19
+ throwApiError(req, 'validationNeedsActor', 400);
20
20
  }
21
21
  if (flags.requiresMetric) {
22
22
  const metricId = relationId(data.metric);
23
23
  if (!metricId) {
24
- throw new APIError('This log type needs a metric.', 400);
24
+ throwApiError(req, 'validationNeedsMetric', 400);
25
25
  }
26
26
  const change = data.change;
27
27
  if (typeof change !== 'number' || Number.isNaN(change)) {
28
- throw new APIError('This log type needs a change amount.', 400);
28
+ throwApiError(req, 'validationNeedsChange', 400);
29
29
  }
30
30
  const metric = (await req.payload.findByID({
31
31
  collection: collectionOf('metrics'),
@@ -36,13 +36,13 @@ export const ensureTypeRequirements = async ({ data, req }) => {
36
36
  select: { kind: true },
37
37
  }));
38
38
  if (metric && (metric.kind ?? 'stored') === 'computed') {
39
- throw new APIError('Computed metrics cannot be changed with a metric delta. Use a stored metric such as Points.', 400);
39
+ throwApiError(req, 'validationComputedMetricDelta', 400);
40
40
  }
41
41
  }
42
42
  if (flags.requiresSubject && getAchievementOptions().subjectCollections.length > 0) {
43
43
  const subject = readLogSubject(data.subject);
44
44
  if (!subject) {
45
- throw new APIError('This log type needs a subject (the host document it is about).', 400);
45
+ throwApiError(req, 'validationNeedsSubject', 400);
46
46
  }
47
47
  const allowed = await eventTypeSubjectRelationTo({
48
48
  payload: req.payload,
@@ -50,7 +50,9 @@ export const ensureTypeRequirements = async ({ data, req }) => {
50
50
  typeIdOrDoc: typeId,
51
51
  });
52
52
  if (allowed.length > 0 && !allowed.includes(subject.relationTo)) {
53
- throw new APIError(`This log type only allows subjects from: ${allowed.join(', ')}.`, 400);
53
+ throwApiError(req, 'validationSubjectNotAllowed', 400, {
54
+ collections: allowed.join(', '),
55
+ });
54
56
  }
55
57
  }
56
58
  return data;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/collections/Logs/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAS,MAAM,SAAS,CAAA;AAqCtD,+EAA+E;AAC/E,wBAAgB,mBAAmB,IAAI,gBAAgB,CAgJtD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/collections/Logs/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAS,MAAM,SAAS,CAAA;AAuCtD,+EAA+E;AAC/E,wBAAgB,mBAAmB,IAAI,gBAAgB,CA6JtD"}
@@ -1,3 +1,4 @@
1
+ import { tEntityDescription, tLabel } from '../../adminLabel.js';
1
2
  import { catalogFilterOptions, metricLogFilterOptions } from '../fields/catalogFilter.js';
2
3
  import { collectionAdmin, collectionOf, optionalFields, slugOf } from '../helpers.js';
3
4
  import { getAchievementOptions } from '../../options-store.js';
@@ -15,8 +16,9 @@ function subjectLogField(eventTypesSlug) {
15
16
  relationTo: collections,
16
17
  index: true,
17
18
  validate: validateSubject,
19
+ label: tLabel('subject'),
18
20
  admin: {
19
- description: 'Host document this entry is about (post, comment, …).',
21
+ description: tLabel('hostDocumentThisEntryIsAboutPostComment'),
20
22
  components: {
21
23
  Field: {
22
24
  path: '@dappermountain/payload-plugin-achievements/client#SubjectField',
@@ -34,8 +36,8 @@ export function buildLogsCollection() {
34
36
  return {
35
37
  slug: slugOf('logs'),
36
38
  labels: {
37
- singular: 'Achievement Log',
38
- plural: 'Achievement Logs',
39
+ singular: tLabel('achievementLog'),
40
+ plural: tLabel('achievementLogs'),
39
41
  },
40
42
  access: { ...access },
41
43
  hooks,
@@ -50,7 +52,7 @@ export function buildLogsCollection() {
50
52
  'change',
51
53
  'createdAt',
52
54
  ],
53
- description: 'Member activity history — grants, revokes, score changes, tier moves, and host custom events. Creating or deleting a host (or metric) log re-evaluates composed achievements and derived tiers.',
55
+ description: tEntityDescription('memberActivityHistoryGrantsRevokesScoreChangesTier'),
54
56
  }),
55
57
  fields: [
56
58
  ...optionalFields(scopeField()),
@@ -65,7 +67,11 @@ export function buildLogsCollection() {
65
67
  required: true,
66
68
  index: true,
67
69
  filterOptions: catalogFilterOptions,
68
- admin: { width: '50%', description: 'What kind of thing happened.' },
70
+ label: tLabel('eventType'),
71
+ admin: {
72
+ width: '50%',
73
+ description: tLabel('whatKindOfThingHappened'),
74
+ },
69
75
  },
70
76
  {
71
77
  name: 'actor',
@@ -73,9 +79,10 @@ export function buildLogsCollection() {
73
79
  relationTo: users,
74
80
  index: true,
75
81
  validate: validateActor,
82
+ label: tLabel('actor'),
76
83
  admin: {
77
84
  width: '50%',
78
- description: 'Who caused it.',
85
+ description: tLabel('whoCausedIt'),
79
86
  components: {
80
87
  Field: {
81
88
  path: '@dappermountain/payload-plugin-achievements/client#ActorField',
@@ -90,9 +97,10 @@ export function buildLogsCollection() {
90
97
  relationTo: collectionOf('metrics'),
91
98
  filterOptions: metricLogFilterOptions,
92
99
  validate: validateMetric,
100
+ label: tLabel('metric'),
93
101
  admin: {
94
102
  width: '50%',
95
- description: 'Which stored score moved (computed metrics like Days cannot be chosen here).',
103
+ description: tLabel('whichStoredScoreMovedComputedMetricsLikeDays'),
96
104
  components: {
97
105
  Field: {
98
106
  path: '@dappermountain/payload-plugin-achievements/client#MetricField',
@@ -105,9 +113,10 @@ export function buildLogsCollection() {
105
113
  name: 'change',
106
114
  type: 'number',
107
115
  validate: validateChange,
116
+ label: tLabel('change'),
108
117
  admin: {
109
118
  width: '50%',
110
- description: 'How much it changed (for example 10 or −3).',
119
+ description: tLabel('howMuchItChangedForExample10Or'),
111
120
  components: {
112
121
  Field: {
113
122
  path: '@dappermountain/payload-plugin-achievements/client#MetricChangeField',
@@ -124,7 +133,7 @@ export function buildLogsCollection() {
124
133
  type: 'array',
125
134
  admin: {
126
135
  readOnly: true,
127
- description: 'Derived ladder rank of the actor when this entry was written. Filled only when the event type snapshots actor tiers.',
136
+ description: tLabel('derivedLadderRankOfTheActorWhenThis'),
128
137
  },
129
138
  fields: [
130
139
  ...optionalFields(scopeField()),
@@ -133,34 +142,43 @@ export function buildLogsCollection() {
133
142
  type: 'relationship',
134
143
  relationTo: collectionOf('tiers'),
135
144
  required: true,
136
- admin: { description: 'Which ladder step they held.' },
145
+ label: tLabel('tier'),
146
+ admin: {
147
+ description: tLabel('whichLadderStepTheyHeld'),
148
+ },
137
149
  },
138
150
  {
139
151
  name: 'rank',
140
152
  type: 'number',
141
153
  required: true,
142
- admin: { description: 'Ladder rank at write time (higher is further along).' },
154
+ label: tLabel('rank'),
155
+ admin: {
156
+ description: tLabel('ladderRankAtWriteTimeHigherIsFurther'),
157
+ },
143
158
  },
144
159
  ],
145
160
  },
146
161
  {
147
162
  type: 'collapsible',
148
- label: 'Details',
163
+ label: tLabel('details'),
149
164
  admin: {
150
165
  initCollapsed: true,
151
- description: 'Extra detail if you need it.',
166
+ description: tLabel('extraDetailIfYouNeedIt'),
152
167
  },
153
168
  fields: [
154
169
  {
155
170
  name: 'reason',
156
171
  type: 'text',
157
- admin: { description: 'A short note about why this was recorded.' },
172
+ admin: {
173
+ description: tLabel('aShortNoteAboutWhyThisWasRecorded'),
174
+ },
158
175
  },
159
176
  {
160
177
  name: 'data',
161
178
  type: 'json',
179
+ label: tLabel('data'),
162
180
  admin: {
163
- description: 'Engine transition envelope: `{ from, to }` each `{ id, slug? }` or null (tier.changed, achievement.granted/revoked). Prefer `subject` for host document links.',
181
+ description: tLabel('engineTransitionEnvelopeFromToEachIdSlug'),
164
182
  },
165
183
  },
166
184
  ],
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/collections/MetricBalances/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAa/C,wBAAgB,6BAA6B,IAAI,gBAAgB,CA4ChE"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/collections/MetricBalances/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAc/C,wBAAgB,6BAA6B,IAAI,gBAAgB,CAgDhE"}