@dappermountain/payload-plugin-achievements 1.0.0-beta.1 → 1.0.0-beta.3
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/README.md +22 -7
- package/dist/catalog.d.ts +12 -0
- package/dist/catalog.d.ts.map +1 -1
- package/dist/catalog.js +12 -0
- package/dist/collections/Achievements/index.d.ts.map +1 -1
- package/dist/collections/Achievements/index.js +9 -2
- package/dist/collections/TierRequests/hooks/prepareTierRequest.d.ts +1 -1
- package/dist/collections/TierRequests/hooks/prepareTierRequest.d.ts.map +1 -1
- package/dist/collections/TierRequests/hooks/prepareTierRequest.js +114 -7
- package/dist/collections/TierRequests/index.js +1 -1
- package/dist/collections/Tiers/index.js +1 -1
- package/dist/collections/applyOverrides.d.ts +1 -0
- package/dist/collections/applyOverrides.d.ts.map +1 -1
- package/dist/collections/applyOverrides.js +8 -0
- package/dist/collections/fields/index.d.ts +1 -1
- package/dist/collections/fields/index.d.ts.map +1 -1
- package/dist/collections/fields/index.js +1 -1
- package/dist/collections/fields/ruleFields.d.ts +25 -2
- package/dist/collections/fields/ruleFields.d.ts.map +1 -1
- package/dist/collections/fields/ruleFields.js +39 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/seed/index.d.ts +5 -0
- package/dist/seed/index.d.ts.map +1 -1
- package/dist/seed/index.js +1 -0
- package/dist/services/achievement/grantSideEffects.d.ts.map +1 -1
- package/dist/services/achievement/grantSideEffects.js +5 -2
- package/dist/services/achievement/index.d.ts +3 -0
- package/dist/services/achievement/index.d.ts.map +1 -1
- package/dist/services/achievement/index.js +2 -0
- package/dist/services/achievement/logData.d.ts +3 -0
- package/dist/services/achievement/logData.d.ts.map +1 -1
- package/dist/services/achievement/reviewTierRequest.d.ts +28 -0
- package/dist/services/achievement/reviewTierRequest.d.ts.map +1 -0
- package/dist/services/achievement/reviewTierRequest.js +77 -0
- package/dist/services/achievement/submitTierRequest.d.ts +16 -0
- package/dist/services/achievement/submitTierRequest.d.ts.map +1 -0
- package/dist/services/achievement/submitTierRequest.js +84 -0
- package/dist/types.d.ts +6 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ You describe what people can earn and what has to happen first. Your app records
|
|
|
18
18
|
|
|
19
19
|
| Plugin line | Payload | Notes |
|
|
20
20
|
| ----------- | ------- | ----- |
|
|
21
|
-
| **`1.x`** (this package — e.g. `1.0.0-beta.
|
|
21
|
+
| **`1.x`** (this package — e.g. `1.0.0-beta.3`) | **4** (`^4.0.0-beta.1` / `^4.0.0`) | Current line. Opt out of P4 default versions/authorship on high-churn collections. |
|
|
22
22
|
| **`0.6.x`** | **3** (`^3.89`) | Last Payload 3 line. Same product features (reactions, composites, etc.). Stay on `0.6.x` until you upgrade the host to Payload 4. |
|
|
23
23
|
|
|
24
24
|
One published version cannot peer both Payload majors (Admin field types and collection defaults diverge). Pick the line that matches your host.
|
|
@@ -37,7 +37,7 @@ Plugin collections opt out of Payload 4’s default versions and authorship (app
|
|
|
37
37
|
|
|
38
38
|
```bash
|
|
39
39
|
# Payload 4 hosts
|
|
40
|
-
bun add @dappermountain/payload-plugin-achievements@^1.0.0-beta.
|
|
40
|
+
bun add @dappermountain/payload-plugin-achievements@^1.0.0-beta.3
|
|
41
41
|
|
|
42
42
|
# Payload 3 hosts (stay on the 0.6 line)
|
|
43
43
|
bun add @dappermountain/payload-plugin-achievements@0.6
|
|
@@ -68,7 +68,7 @@ Then:
|
|
|
68
68
|
|
|
69
69
|
1. `payload generate:importmap` — Admin fields for logs, subjects, and Lucide icons.
|
|
70
70
|
2. Migrate (or push) schema. The plugin adds collections; your app still owns the migrate runner.
|
|
71
|
-
3. Restart so Payload can seed the system catalog on `onInit` (`points`, `metric.delta`, `achievement.granted
|
|
71
|
+
3. Restart so Payload can seed the system catalog on `onInit` (`points`, `metric.delta`, `achievement.granted` / `revoked`, `tier.changed`, `tier.request.submitted` / `approved` / `rejected`). Set `seedSystemCatalog: false` if you want to call `seedAchievementCatalog` yourself.
|
|
72
72
|
|
|
73
73
|
Your product catalog — extra event types, metrics, tiers, achievements — is `seedAchievements`.
|
|
74
74
|
|
|
@@ -93,14 +93,14 @@ Slugs use the prefix `achievement-` so they sit beside your own collections. Ove
|
|
|
93
93
|
| `metricBalances` | `achievement-metric-balances` | Running totals for stored metrics, per user (+ scope). Leaderboards read this. |
|
|
94
94
|
| `eventTypes` | `achievement-event-types` | Kinds of log entries you can count or require. |
|
|
95
95
|
| `tiers` | `achievement-tiers` | Ladder steps with unlock rules. |
|
|
96
|
-
| `achievements` | `achievement-definitions` | Earnable items with eligibility and completion rules. |
|
|
96
|
+
| `achievements` | `achievement-definitions` | Earnable items with eligibility and completion rules, plus optional JSON `metadata` for host/product structure. |
|
|
97
97
|
| `grants` | `achievement-grants` | One earned achievement per user (+ scope). |
|
|
98
98
|
| `achievementRequests` | `achievement-requests` | Request → pending / approved / rejected. |
|
|
99
99
|
| `tierRequests` | `achievement-tier-requests` | Tier unlock waiting on review (`requiresReview` on the tier). |
|
|
100
100
|
| `logs` | `achievement-logs` | Activity history. |
|
|
101
101
|
| `reactions` | `achievement-reactions` | Side effects when something is logged or granted. |
|
|
102
102
|
|
|
103
|
-
System rows (`points` and the
|
|
103
|
+
System rows (`points` and the engine event types) are protected. The plugin locks their slugs and blocks deletes.
|
|
104
104
|
|
|
105
105
|
## Event types
|
|
106
106
|
|
|
@@ -163,6 +163,8 @@ Put host document links on `subject`. Engine grant/revoke/tier rows use a small
|
|
|
163
163
|
| `achievement.granted` | `null` | achievement |
|
|
164
164
|
| `achievement.revoked` | achievement | `null` |
|
|
165
165
|
|
|
166
|
+
Tier-request lifecycle logs (`tier.request.submitted` / `approved` / `rejected`) store `{ requestId, status, fromStatus, tier }` so hosts and reactions can listen without forking ladder derivation.
|
|
167
|
+
|
|
166
168
|
## Rules
|
|
167
169
|
|
|
168
170
|
Unlock (tiers), eligibility, and completion (achievements) share one tree:
|
|
@@ -176,7 +178,9 @@ Unlock (tiers), eligibility, and completion (achievements) share one tree:
|
|
|
176
178
|
|
|
177
179
|
**Eligibility** gates who may request an achievement. **Completion** describes what a composed achievement is made of. When `requiresReview` is off and completion passes, the parent grants itself. Nested achievement graphs skip cycles.
|
|
178
180
|
|
|
179
|
-
**
|
|
181
|
+
**Definition `metadata`** is an optional JSON field on achievement definitions for host/product structure (filters, effects, completion shape, and so on). The plugin does not interpret it. Keep member-facing copy in localized `name` / `description` and host i18n keyed by slug — not inside `metadata`. Seed with `seedAchievements({ achievements: [{ metadata, … }] })`. For typed Admin fields on hot paths, use `collections.overrides.achievements.fields`.
|
|
182
|
+
|
|
183
|
+
**Current tier** walks the ladder in `rank` order (`resolveCurrentTier`). A tier with `requiresReview` becomes current after an **approved** tier request. Members open requests with `submitTierRequest` (unlock rules must pass); staff use `reviewTierRequest` / `findTierRequestsForReview`. Turning `requiresReview` off approves pending requests for that row and writes missing `tier.changed` logs for people who already meet the unlock rules.
|
|
180
184
|
|
|
181
185
|
**Next-tier fill** (`resolveTierProgress` / `evaluateRuleProgress`):
|
|
182
186
|
|
|
@@ -355,7 +359,7 @@ achievementPlugin({
|
|
|
355
359
|
| `prefix` | `'achievement'` | Default slugs, REST paths, and table names. |
|
|
356
360
|
| `adminGroup` | `'Achievements'` | Sidebar group. `false` leaves collections ungrouped. |
|
|
357
361
|
| `slugs` | derived | Absolute slug per key (ignores `prefix` for that key). |
|
|
358
|
-
| `overrides` | unset | `access`, `admin`, `hooks`, `labels`. Access keys replace; hook arrays append after plugin hooks; `admin` / `labels` merge shallowly. |
|
|
362
|
+
| `overrides` | unset | `access`, `admin`, `hooks`, `labels`, `fields`. Access keys replace; hook arrays append after plugin hooks; `admin` / `labels` merge shallowly; `fields` replaces the list (use `({ defaultFields }) => …` to wrap). |
|
|
359
363
|
|
|
360
364
|
```ts
|
|
361
365
|
achievementPlugin({
|
|
@@ -373,6 +377,12 @@ achievementPlugin({
|
|
|
373
377
|
],
|
|
374
378
|
},
|
|
375
379
|
},
|
|
380
|
+
achievements: {
|
|
381
|
+
fields: ({ defaultFields }) => [
|
|
382
|
+
...defaultFields,
|
|
383
|
+
// optional typed Admin fields for hot paths; prefer definition `metadata` for product JSON
|
|
384
|
+
],
|
|
385
|
+
},
|
|
376
386
|
},
|
|
377
387
|
},
|
|
378
388
|
})
|
|
@@ -420,6 +430,9 @@ import {
|
|
|
420
430
|
buildUnlockRequirementLeaves,
|
|
421
431
|
submitAchievementRequest,
|
|
422
432
|
reviewAchievementRequest,
|
|
433
|
+
submitTierRequest,
|
|
434
|
+
reviewTierRequest,
|
|
435
|
+
findTierRequestsForReview,
|
|
423
436
|
logSubject,
|
|
424
437
|
} from '@dappermountain/payload-plugin-achievements'
|
|
425
438
|
|
|
@@ -512,6 +525,8 @@ await seedAchievements(payload, {
|
|
|
512
525
|
slug: 'first-steps',
|
|
513
526
|
requiresReview: false,
|
|
514
527
|
completionRules: [{ type: 'metric-minimum', metricSlug: 'points', minimum: 10 }],
|
|
528
|
+
// Optional host JSON — structure only; validate in the host (Zod, etc.)
|
|
529
|
+
metadata: { kind: 'action', effort: 'immediate' },
|
|
515
530
|
},
|
|
516
531
|
],
|
|
517
532
|
removeAchievementSlugs: ['old-slug'],
|
package/dist/catalog.d.ts
CHANGED
|
@@ -11,6 +11,15 @@ export declare const ENGINE_EVENT_TYPES: readonly [{
|
|
|
11
11
|
}, {
|
|
12
12
|
readonly slug: "tier.changed";
|
|
13
13
|
readonly name: "Tier changed";
|
|
14
|
+
}, {
|
|
15
|
+
readonly slug: "tier.request.submitted";
|
|
16
|
+
readonly name: "Tier request submitted";
|
|
17
|
+
}, {
|
|
18
|
+
readonly slug: "tier.request.approved";
|
|
19
|
+
readonly name: "Tier request approved";
|
|
20
|
+
}, {
|
|
21
|
+
readonly slug: "tier.request.rejected";
|
|
22
|
+
readonly name: "Tier request rejected";
|
|
14
23
|
}];
|
|
15
24
|
export declare const ENGINE_METRICS: readonly [{
|
|
16
25
|
readonly slug: "points";
|
|
@@ -24,5 +33,8 @@ export declare const DEFAULT_ACHIEVEMENT_METRIC_SLUG: EngineMetricSlug;
|
|
|
24
33
|
export declare const DEFAULT_ACHIEVEMENT_METRIC: "points";
|
|
25
34
|
/** Grant/revoke audit logs — progression already runs from Grants hooks. */
|
|
26
35
|
export declare const GRANT_AUDIT_EVENT_SLUGS: ReadonlySet<string>;
|
|
36
|
+
/** Tier-request lifecycle logs — TierRequests afterChange already syncs the ladder. */
|
|
37
|
+
export declare const TIER_REQUEST_AUDIT_EVENT_SLUGS: ReadonlySet<string>;
|
|
27
38
|
export declare function isGrantAuditEventSlug(slug: string | null | undefined): boolean;
|
|
39
|
+
export declare function isTierRequestAuditEventSlug(slug: string | null | undefined): boolean;
|
|
28
40
|
//# sourceMappingURL=catalog.d.ts.map
|
package/dist/catalog.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../src/catalog.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kBAAkB
|
|
1
|
+
{"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../src/catalog.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;EAQrB,CAAA;AAEV,eAAO,MAAM,cAAc;;;;EAAyE,CAAA;AAEpG,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAA;AAC7E,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAA;AAEtE,eAAO,MAAM,+BAA+B,EAAE,gBAA2B,CAAA;AAEzE,+DAA+D;AAC/D,eAAO,MAAM,0BAA0B,UAAkC,CAAA;AAEzE,4EAA4E;AAC5E,eAAO,MAAM,uBAAuB,EAAE,WAAW,CAAC,MAAM,CAGtD,CAAA;AAEF,uFAAuF;AACvF,eAAO,MAAM,8BAA8B,EAAE,WAAW,CAAC,MAAM,CAI7D,CAAA;AAEF,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAE9E;AAED,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAEpF"}
|
package/dist/catalog.js
CHANGED
|
@@ -3,6 +3,9 @@ export const ENGINE_EVENT_TYPES = [
|
|
|
3
3
|
{ slug: 'achievement.revoked', name: 'Achievement revoked' },
|
|
4
4
|
{ slug: 'metric.delta', name: 'Metric delta', requiresMetric: true },
|
|
5
5
|
{ slug: 'tier.changed', name: 'Tier changed' },
|
|
6
|
+
{ slug: 'tier.request.submitted', name: 'Tier request submitted' },
|
|
7
|
+
{ slug: 'tier.request.approved', name: 'Tier request approved' },
|
|
8
|
+
{ slug: 'tier.request.rejected', name: 'Tier request rejected' },
|
|
6
9
|
];
|
|
7
10
|
export const ENGINE_METRICS = [{ slug: 'points', name: 'Points', kind: 'stored' }];
|
|
8
11
|
export const DEFAULT_ACHIEVEMENT_METRIC_SLUG = 'points';
|
|
@@ -13,6 +16,15 @@ export const GRANT_AUDIT_EVENT_SLUGS = new Set([
|
|
|
13
16
|
'achievement.granted',
|
|
14
17
|
'achievement.revoked',
|
|
15
18
|
]);
|
|
19
|
+
/** Tier-request lifecycle logs — TierRequests afterChange already syncs the ladder. */
|
|
20
|
+
export const TIER_REQUEST_AUDIT_EVENT_SLUGS = new Set([
|
|
21
|
+
'tier.request.submitted',
|
|
22
|
+
'tier.request.approved',
|
|
23
|
+
'tier.request.rejected',
|
|
24
|
+
]);
|
|
16
25
|
export function isGrantAuditEventSlug(slug) {
|
|
17
26
|
return typeof slug === 'string' && GRANT_AUDIT_EVENT_SLUGS.has(slug);
|
|
18
27
|
}
|
|
28
|
+
export function isTierRequestAuditEventSlug(slug) {
|
|
29
|
+
return typeof slug === 'string' && TIER_REQUEST_AUDIT_EVENT_SLUGS.has(slug);
|
|
30
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/collections/Achievements/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAO/C,wBAAgB,2BAA2B,IAAI,gBAAgB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/collections/Achievements/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAO/C,wBAAgB,2BAA2B,IAAI,gBAAgB,CAsE9D"}
|
|
@@ -33,6 +33,13 @@ export function buildAchievementsCollection() {
|
|
|
33
33
|
],
|
|
34
34
|
},
|
|
35
35
|
localizedDescriptionField(),
|
|
36
|
+
{
|
|
37
|
+
name: 'metadata',
|
|
38
|
+
type: 'json',
|
|
39
|
+
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.',
|
|
41
|
+
},
|
|
42
|
+
},
|
|
36
43
|
{
|
|
37
44
|
name: 'requiresReview',
|
|
38
45
|
type: 'checkbox',
|
|
@@ -49,7 +56,7 @@ export function buildAchievementsCollection() {
|
|
|
49
56
|
admin: {
|
|
50
57
|
description: 'Who may request this achievement. Composed parents that auto-grant should leave this empty.',
|
|
51
58
|
},
|
|
52
|
-
fields: buildRuleTreeFields(),
|
|
59
|
+
fields: buildRuleTreeFields({ dbName: 'ach_elig_r' }),
|
|
53
60
|
},
|
|
54
61
|
{
|
|
55
62
|
name: 'completionRules',
|
|
@@ -58,7 +65,7 @@ export function buildAchievementsCollection() {
|
|
|
58
65
|
admin: {
|
|
59
66
|
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.',
|
|
60
67
|
},
|
|
61
|
-
fields: buildRuleTreeFields(),
|
|
68
|
+
fields: buildRuleTreeFields({ dbName: 'ach_comp_r' }),
|
|
62
69
|
},
|
|
63
70
|
],
|
|
64
71
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { CollectionAfterChangeHook, CollectionBeforeValidateHook } from 'payload';
|
|
2
2
|
/**
|
|
3
3
|
* System-created requests (reconcile / progression sync) may set user freely.
|
|
4
|
-
* Member creates
|
|
4
|
+
* Member creates bind `req.user`, require unlock rules, and requireReview on the tier.
|
|
5
5
|
*/
|
|
6
6
|
export declare const prepareTierRequest: CollectionBeforeValidateHook;
|
|
7
7
|
export declare const afterTierRequestChange: CollectionAfterChangeHook;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prepareTierRequest.d.ts","sourceRoot":"","sources":["../../../../src/collections/TierRequests/hooks/prepareTierRequest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,yBAAyB,EACzB,4BAA4B,EAE7B,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"prepareTierRequest.d.ts","sourceRoot":"","sources":["../../../../src/collections/TierRequests/hooks/prepareTierRequest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,yBAAyB,EACzB,4BAA4B,EAE7B,MAAM,SAAS,CAAA;AA2BhB;;;GAGG;AACH,eAAO,MAAM,kBAAkB,EAAE,4BAiGhC,CAAA;AA8CD,eAAO,MAAM,sBAAsB,EAAE,yBAkCpC,CAAA"}
|
|
@@ -1,56 +1,163 @@
|
|
|
1
1
|
import { APIError } from 'payload';
|
|
2
2
|
import { collectionOf } from '../../../collections/helpers.js';
|
|
3
3
|
import { CTX_SYSTEM_REQUEST } from '../../../services/achievement/contextFlags.js';
|
|
4
|
-
import {
|
|
4
|
+
import { evaluateRules } from '../../../services/achievement/evaluateRules.js';
|
|
5
|
+
import { catalogRef } from '../../../services/achievement/logData.js';
|
|
6
|
+
import { recordLog, syncTierChangedLog } from '../../../services/achievement/recordEvent.js';
|
|
5
7
|
import { relationId } from '../../../services/achievement/relationId.js';
|
|
6
8
|
function scopeIdOf(data) {
|
|
7
9
|
return relationId(data?.scope);
|
|
8
10
|
}
|
|
11
|
+
const TIER_REQUEST_STATUS_EVENT = {
|
|
12
|
+
pending: 'tier.request.submitted',
|
|
13
|
+
approved: 'tier.request.approved',
|
|
14
|
+
rejected: 'tier.request.rejected',
|
|
15
|
+
};
|
|
9
16
|
/**
|
|
10
17
|
* System-created requests (reconcile / progression sync) may set user freely.
|
|
11
|
-
* Member creates
|
|
18
|
+
* Member creates bind `req.user`, require unlock rules, and requireReview on the tier.
|
|
12
19
|
*/
|
|
13
20
|
export const prepareTierRequest = async ({ data, operation, req, originalDoc, }) => {
|
|
14
21
|
if (!data)
|
|
15
22
|
return data;
|
|
16
23
|
if (operation === 'create') {
|
|
17
|
-
|
|
24
|
+
const system = Boolean(req.context?.[CTX_SYSTEM_REQUEST]);
|
|
25
|
+
if (!system) {
|
|
18
26
|
const userId = req.user?.id;
|
|
19
27
|
if (typeof userId !== 'string')
|
|
20
28
|
throw new APIError('Unauthorized', 401);
|
|
21
29
|
data.user = userId;
|
|
22
30
|
}
|
|
31
|
+
else {
|
|
32
|
+
const bound = relationId(data.user);
|
|
33
|
+
if (!bound)
|
|
34
|
+
throw new APIError('user required', 400);
|
|
35
|
+
data.user = bound;
|
|
36
|
+
}
|
|
37
|
+
const userId = relationId(data.user);
|
|
38
|
+
if (!userId)
|
|
39
|
+
throw new APIError('user required', 400);
|
|
23
40
|
const tierId = relationId(data.tier);
|
|
24
41
|
if (!tierId)
|
|
25
42
|
throw new APIError('tier required', 400);
|
|
26
|
-
const tier = await req.payload.findByID({
|
|
43
|
+
const tier = (await req.payload.findByID({
|
|
27
44
|
collection: collectionOf('tiers'),
|
|
28
45
|
id: tierId,
|
|
29
46
|
depth: 0,
|
|
30
47
|
overrideAccess: true,
|
|
31
48
|
req,
|
|
32
|
-
});
|
|
49
|
+
}));
|
|
33
50
|
if (!tier)
|
|
34
51
|
throw new APIError(`Unknown tier: ${tierId}`, 400);
|
|
35
52
|
if (tier.requiresReview !== true) {
|
|
36
53
|
throw new APIError('This tier does not require review.', 400);
|
|
37
54
|
}
|
|
38
55
|
data.tier = tierId;
|
|
39
|
-
if (!
|
|
56
|
+
if (!system) {
|
|
57
|
+
const scopeId = scopeIdOf(data);
|
|
58
|
+
const unlocked = await evaluateRules({
|
|
59
|
+
payload: req.payload,
|
|
60
|
+
req,
|
|
61
|
+
rules: tier.unlockRules,
|
|
62
|
+
userId,
|
|
63
|
+
scopeId,
|
|
64
|
+
});
|
|
65
|
+
if (!unlocked) {
|
|
66
|
+
throw new APIError('Unlock rules not met for this tier.', 400);
|
|
67
|
+
}
|
|
68
|
+
// Members cannot self-approve; only reviewers / system may set approved|rejected.
|
|
69
|
+
data.status = 'pending';
|
|
70
|
+
}
|
|
71
|
+
else if (!data.status) {
|
|
40
72
|
data.status = 'pending';
|
|
73
|
+
}
|
|
41
74
|
return data;
|
|
42
75
|
}
|
|
43
76
|
if (operation === 'update' && originalDoc) {
|
|
44
77
|
data.user = originalDoc.user;
|
|
45
78
|
data.tier = originalDoc.tier;
|
|
79
|
+
const nextStatus = typeof data.status === 'string' ? data.status : undefined;
|
|
80
|
+
const prevStatus = originalDoc.status;
|
|
81
|
+
if (nextStatus === 'pending' && prevStatus && prevStatus !== 'pending') {
|
|
82
|
+
const userId = relationId(originalDoc.user);
|
|
83
|
+
const tierId = relationId(originalDoc.tier);
|
|
84
|
+
if (userId && tierId) {
|
|
85
|
+
const tier = (await req.payload.findByID({
|
|
86
|
+
collection: collectionOf('tiers'),
|
|
87
|
+
id: tierId,
|
|
88
|
+
depth: 0,
|
|
89
|
+
overrideAccess: true,
|
|
90
|
+
req,
|
|
91
|
+
}));
|
|
92
|
+
const scopeId = scopeIdOf({
|
|
93
|
+
scope: data.scope ?? originalDoc.scope,
|
|
94
|
+
});
|
|
95
|
+
const unlocked = await evaluateRules({
|
|
96
|
+
payload: req.payload,
|
|
97
|
+
req,
|
|
98
|
+
rules: (tier?.unlockRules ?? []),
|
|
99
|
+
userId,
|
|
100
|
+
scopeId,
|
|
101
|
+
});
|
|
102
|
+
if (!unlocked) {
|
|
103
|
+
throw new APIError('Unlock rules not met for this tier.', 400);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
46
107
|
}
|
|
47
108
|
return data;
|
|
48
109
|
};
|
|
49
|
-
|
|
110
|
+
async function recordTierRequestStatusLog(args) {
|
|
111
|
+
const eventType = TIER_REQUEST_STATUS_EVENT[args.status];
|
|
112
|
+
if (!eventType)
|
|
113
|
+
return;
|
|
114
|
+
// Only log real transitions (and create-as-pending / create-as-approved).
|
|
115
|
+
if (args.previousStatus === args.status)
|
|
116
|
+
return;
|
|
117
|
+
const userId = relationId(args.doc.user);
|
|
118
|
+
const tierId = relationId(args.doc.tier);
|
|
119
|
+
if (!userId || !tierId)
|
|
120
|
+
return;
|
|
121
|
+
const tier = (await args.req.payload.findByID({
|
|
122
|
+
collection: collectionOf('tiers'),
|
|
123
|
+
id: tierId,
|
|
124
|
+
depth: 0,
|
|
125
|
+
overrideAccess: true,
|
|
126
|
+
req: args.req,
|
|
127
|
+
select: { slug: true },
|
|
128
|
+
}));
|
|
129
|
+
const scopeId = scopeIdOf(args.doc);
|
|
130
|
+
const requestId = typeof args.doc.id === 'string' ? args.doc.id : String(args.doc.id ?? '');
|
|
131
|
+
await recordLog({
|
|
132
|
+
payload: args.req.payload,
|
|
133
|
+
req: args.req,
|
|
134
|
+
userId,
|
|
135
|
+
scopeId,
|
|
136
|
+
type: eventType,
|
|
137
|
+
actorId: typeof args.req.user?.id === 'string' ? args.req.user.id : undefined,
|
|
138
|
+
data: {
|
|
139
|
+
requestId,
|
|
140
|
+
status: args.status,
|
|
141
|
+
fromStatus: args.previousStatus,
|
|
142
|
+
tier: catalogRef(tierId, tier?.slug),
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
export const afterTierRequestChange = async ({ doc, operation, previousDoc, req, }) => {
|
|
50
147
|
const userId = relationId(doc.user);
|
|
51
148
|
if (!userId)
|
|
52
149
|
return doc;
|
|
53
150
|
const scopeId = scopeIdOf(doc);
|
|
151
|
+
const status = typeof doc.status === 'string' ? doc.status : '';
|
|
152
|
+
const previousStatus = operation === 'update' && previousDoc && typeof previousDoc.status === 'string'
|
|
153
|
+
? previousDoc.status
|
|
154
|
+
: null;
|
|
155
|
+
await recordTierRequestStatusLog({
|
|
156
|
+
req: req,
|
|
157
|
+
doc: doc,
|
|
158
|
+
previousStatus,
|
|
159
|
+
status,
|
|
160
|
+
});
|
|
54
161
|
// Any status transition (or create as pending/rejected/approved) can change the
|
|
55
162
|
// live ladder — including demotions when approved → pending/rejected. Sync is
|
|
56
163
|
// idempotent when the latest audit already matches resolveCurrentTier.
|
|
@@ -85,7 +85,7 @@ export function buildTiersCollection() {
|
|
|
85
85
|
admin: {
|
|
86
86
|
description: 'Rules that must pass to unlock this tier (all-of or any-of). Empty rules mean this step is open. Current tier is derived by walking ranks; optional tier.changed logs record moves.',
|
|
87
87
|
},
|
|
88
|
-
fields: buildRuleTreeFields(),
|
|
88
|
+
fields: buildRuleTreeFields({ dbName: 'ach_unlk_r' }),
|
|
89
89
|
},
|
|
90
90
|
],
|
|
91
91
|
};
|
|
@@ -4,6 +4,7 @@ import type { AchievementCollectionOverride } from '../types.js';
|
|
|
4
4
|
* Layer host overrides on a plugin collection:
|
|
5
5
|
* - `access` / `admin` / `labels`: shallow merge (host wins per key)
|
|
6
6
|
* - `hooks`: append host hook arrays after the plugin’s (plugin runs first)
|
|
7
|
+
* - `fields`: replace — function receives `{ defaultFields }` (Form Builder–style)
|
|
7
8
|
*/
|
|
8
9
|
export declare function applyCollectionOverrides(collection: CollectionConfig, override?: AchievementCollectionOverride): CollectionConfig;
|
|
9
10
|
//# sourceMappingURL=applyOverrides.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"applyOverrides.d.ts","sourceRoot":"","sources":["../../src/collections/applyOverrides.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,
|
|
1
|
+
{"version":3,"file":"applyOverrides.d.ts","sourceRoot":"","sources":["../../src/collections/applyOverrides.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAS,MAAM,SAAS,CAAA;AAEtD,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,aAAa,CAAA;AAEhE;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,UAAU,EAAE,gBAAgB,EAC5B,QAAQ,CAAC,EAAE,6BAA6B,GACvC,gBAAgB,CAsClB"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Layer host overrides on a plugin collection:
|
|
3
3
|
* - `access` / `admin` / `labels`: shallow merge (host wins per key)
|
|
4
4
|
* - `hooks`: append host hook arrays after the plugin’s (plugin runs first)
|
|
5
|
+
* - `fields`: replace — function receives `{ defaultFields }` (Form Builder–style)
|
|
5
6
|
*/
|
|
6
7
|
export function applyCollectionOverrides(collection, override) {
|
|
7
8
|
if (!override)
|
|
@@ -18,6 +19,12 @@ export function applyCollectionOverrides(collection, override) {
|
|
|
18
19
|
hooks[key] = [...base, ...extra];
|
|
19
20
|
}
|
|
20
21
|
}
|
|
22
|
+
const defaultFields = (collection.fields ?? []);
|
|
23
|
+
const fields = override.fields == null
|
|
24
|
+
? undefined
|
|
25
|
+
: typeof override.fields === 'function'
|
|
26
|
+
? override.fields({ defaultFields })
|
|
27
|
+
: override.fields;
|
|
21
28
|
return {
|
|
22
29
|
...collection,
|
|
23
30
|
access: {
|
|
@@ -29,6 +36,7 @@ export function applyCollectionOverrides(collection, override) {
|
|
|
29
36
|
...override.admin,
|
|
30
37
|
},
|
|
31
38
|
...(override.labels ? { labels: override.labels } : {}),
|
|
39
|
+
...(fields ? { fields } : {}),
|
|
32
40
|
hooks,
|
|
33
41
|
};
|
|
34
42
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { scopeField } from './scopeField.js';
|
|
2
2
|
export { userField } from './userField.js';
|
|
3
|
-
export { buildRuleRowFields, buildRuleTreeFields } from './ruleFields.js';
|
|
3
|
+
export { assertSafeRuleArrayDbName, buildRuleRowFields, buildRuleTreeFields, POSTGRES_IDENTIFIER_MAX, ruleArrayIdentifierLength, type BuildRuleTreeFieldsArgs, } from './ruleFields.js';
|
|
4
4
|
export { usersAchievementsGroup } from './usersAchievementsGroup.js';
|
|
5
5
|
export { localizedDescriptionField, localizedNameField } from './localizedText.js';
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/collections/fields/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/collections/fields/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EACL,yBAAyB,EACzB,kBAAkB,EAClB,mBAAmB,EACnB,uBAAuB,EACvB,yBAAyB,EACzB,KAAK,uBAAuB,GAC7B,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAA;AACpE,OAAO,EAAE,yBAAyB,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { scopeField } from './scopeField.js';
|
|
2
2
|
export { userField } from './userField.js';
|
|
3
|
-
export { buildRuleRowFields, buildRuleTreeFields } from './ruleFields.js';
|
|
3
|
+
export { assertSafeRuleArrayDbName, buildRuleRowFields, buildRuleTreeFields, POSTGRES_IDENTIFIER_MAX, ruleArrayIdentifierLength, } from './ruleFields.js';
|
|
4
4
|
export { usersAchievementsGroup } from './usersAchievementsGroup.js';
|
|
5
5
|
export { localizedDescriptionField, localizedNameField } from './localizedText.js';
|
|
@@ -1,8 +1,31 @@
|
|
|
1
1
|
import type { Field } from 'payload';
|
|
2
|
+
/**
|
|
3
|
+
* Postgres truncates identifiers over 63 chars. Nested `rules` arrays under
|
|
4
|
+
* `eligibilityRules` / `completionRules` / `unlockRules` exceed that when
|
|
5
|
+
* Payload auto-names tables — set explicit short `dbName` values instead.
|
|
6
|
+
*
|
|
7
|
+
* Call sites must pass a **unique** `dbName` (plugin-wide). Nested group rules
|
|
8
|
+
* use `${dbName}_g` so one prefix yields two unique table names.
|
|
9
|
+
*/
|
|
10
|
+
export declare const POSTGRES_IDENTIFIER_MAX = 63;
|
|
11
|
+
export type BuildRuleTreeFieldsArgs = {
|
|
12
|
+
/**
|
|
13
|
+
* Short, unique Postgres table name for the outer `rules` array.
|
|
14
|
+
* Nested group `rules` become `${dbName}_g`. Must stay unique across the plugin.
|
|
15
|
+
*/
|
|
16
|
+
dbName: string;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Worst-case identifier length when Payload prefixes `dbName` with the parent
|
|
20
|
+
* collection table and appends `_parent_id_idx` / `_parent_id_fk`.
|
|
21
|
+
*/
|
|
22
|
+
export declare function ruleArrayIdentifierLength(dbName: string, parentTable?: string): number;
|
|
23
|
+
export declare function assertSafeRuleArrayDbName(dbName: string): void;
|
|
2
24
|
/**
|
|
3
25
|
* Top-level rule group: combinator + rules, with one nested group level.
|
|
26
|
+
* Pass a unique short {@link BuildRuleTreeFieldsArgs.dbName} per embed site.
|
|
4
27
|
*/
|
|
5
|
-
export declare function buildRuleTreeFields(): Field[];
|
|
28
|
+
export declare function buildRuleTreeFields(args: BuildRuleTreeFieldsArgs): Field[];
|
|
6
29
|
/** @deprecated Use {@link buildRuleTreeFields}. */
|
|
7
|
-
export declare function buildRuleRowFields(): Field[];
|
|
30
|
+
export declare function buildRuleRowFields(args: BuildRuleTreeFieldsArgs): Field[];
|
|
8
31
|
//# sourceMappingURL=ruleFields.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ruleFields.d.ts","sourceRoot":"","sources":["../../../src/collections/fields/ruleFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAU,MAAM,SAAS,CAAA;AAqI5C
|
|
1
|
+
{"version":3,"file":"ruleFields.d.ts","sourceRoot":"","sources":["../../../src/collections/fields/ruleFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAU,MAAM,SAAS,CAAA;AAqI5C;;;;;;;GAOG;AACH,eAAO,MAAM,uBAAuB,KAAK,CAAA;AAUzC,MAAM,MAAM,uBAAuB,GAAG;IACpC;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAA;CACf,CAAA;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,SAA+B,GAAG,MAAM,CAE5G;AAED,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAY9D;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,uBAAuB,GAAG,KAAK,EAAE,CA2B1E;AAED,mDAAmD;AACnD,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,uBAAuB,GAAG,KAAK,EAAE,CAEzE"}
|
|
@@ -121,15 +121,50 @@ function ruleParamFields() {
|
|
|
121
121
|
function buildRuleLeafFields() {
|
|
122
122
|
return [ruleTypeSelect(false), ...ruleParamFields()];
|
|
123
123
|
}
|
|
124
|
+
/**
|
|
125
|
+
* Postgres truncates identifiers over 63 chars. Nested `rules` arrays under
|
|
126
|
+
* `eligibilityRules` / `completionRules` / `unlockRules` exceed that when
|
|
127
|
+
* Payload auto-names tables — set explicit short `dbName` values instead.
|
|
128
|
+
*
|
|
129
|
+
* Call sites must pass a **unique** `dbName` (plugin-wide). Nested group rules
|
|
130
|
+
* use `${dbName}_g` so one prefix yields two unique table names.
|
|
131
|
+
*/
|
|
132
|
+
export const POSTGRES_IDENTIFIER_MAX = 63;
|
|
133
|
+
/** Longest default plugin table (`achievement-definitions` → snake_case). */
|
|
134
|
+
const LONGEST_DEFAULT_PARENT_TABLE = 'achievement_definitions';
|
|
135
|
+
const PARENT_ID_INDEX_SUFFIX = '_parent_id_idx';
|
|
136
|
+
/** Nested group-rules array suffix; keep short and stable. */
|
|
137
|
+
const NESTED_RULES_DB_SUFFIX = '_g';
|
|
138
|
+
/**
|
|
139
|
+
* Worst-case identifier length when Payload prefixes `dbName` with the parent
|
|
140
|
+
* collection table and appends `_parent_id_idx` / `_parent_id_fk`.
|
|
141
|
+
*/
|
|
142
|
+
export function ruleArrayIdentifierLength(dbName, parentTable = LONGEST_DEFAULT_PARENT_TABLE) {
|
|
143
|
+
return parentTable.length + 1 + dbName.length + PARENT_ID_INDEX_SUFFIX.length;
|
|
144
|
+
}
|
|
145
|
+
export function assertSafeRuleArrayDbName(dbName) {
|
|
146
|
+
if (!/^[a-z][a-z0-9_]*$/.test(dbName)) {
|
|
147
|
+
throw new Error(`Rule array dbName "${dbName}" must be a lowercase snake_case Postgres identifier starting with a letter.`);
|
|
148
|
+
}
|
|
149
|
+
const length = ruleArrayIdentifierLength(dbName);
|
|
150
|
+
if (length > POSTGRES_IDENTIFIER_MAX) {
|
|
151
|
+
throw new Error(`Rule array dbName "${dbName}" is too long (${length} > ${POSTGRES_IDENTIFIER_MAX} with parent index suffix).`);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
124
154
|
/**
|
|
125
155
|
* Top-level rule group: combinator + rules, with one nested group level.
|
|
156
|
+
* Pass a unique short {@link BuildRuleTreeFieldsArgs.dbName} per embed site.
|
|
126
157
|
*/
|
|
127
|
-
export function buildRuleTreeFields() {
|
|
158
|
+
export function buildRuleTreeFields(args) {
|
|
159
|
+
assertSafeRuleArrayDbName(args.dbName);
|
|
160
|
+
const nestedDbName = `${args.dbName}${NESTED_RULES_DB_SUFFIX}`;
|
|
161
|
+
assertSafeRuleArrayDbName(nestedDbName);
|
|
128
162
|
return [
|
|
129
163
|
combinatorField(),
|
|
130
164
|
{
|
|
131
165
|
name: 'rules',
|
|
132
166
|
type: 'array',
|
|
167
|
+
dbName: args.dbName,
|
|
133
168
|
labels: { singular: 'Rule', plural: 'Rules' },
|
|
134
169
|
fields: [
|
|
135
170
|
ruleTypeSelect(true),
|
|
@@ -138,6 +173,7 @@ export function buildRuleTreeFields() {
|
|
|
138
173
|
{
|
|
139
174
|
name: 'rules',
|
|
140
175
|
type: 'array',
|
|
176
|
+
dbName: nestedDbName,
|
|
141
177
|
labels: { singular: 'Rule', plural: 'Rules' },
|
|
142
178
|
admin: { condition: (_, sibling) => sibling?.type === 'group' },
|
|
143
179
|
fields: buildRuleLeafFields(),
|
|
@@ -147,6 +183,6 @@ export function buildRuleTreeFields() {
|
|
|
147
183
|
];
|
|
148
184
|
}
|
|
149
185
|
/** @deprecated Use {@link buildRuleTreeFields}. */
|
|
150
|
-
export function buildRuleRowFields() {
|
|
151
|
-
return buildRuleTreeFields();
|
|
186
|
+
export function buildRuleRowFields(args) {
|
|
187
|
+
return buildRuleTreeFields(args);
|
|
152
188
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export { DEFAULT_ACHIEVEMENT_METRIC, DEFAULT_ACHIEVEMENT_METRIC_SLUG, ENGINE_EVENT_TYPES, ENGINE_METRICS, GRANT_AUDIT_EVENT_SLUGS, isGrantAuditEventSlug, } from './catalog.js';
|
|
1
|
+
export { DEFAULT_ACHIEVEMENT_METRIC, DEFAULT_ACHIEVEMENT_METRIC_SLUG, ENGINE_EVENT_TYPES, ENGINE_METRICS, GRANT_AUDIT_EVENT_SLUGS, TIER_REQUEST_AUDIT_EVENT_SLUGS, isGrantAuditEventSlug, isTierRequestAuditEventSlug, } from './catalog.js';
|
|
2
2
|
export type { EngineEventTypeSlug, EngineMetricSlug } from './catalog.js';
|
|
3
3
|
export { achievementPlugin } from './plugin.js';
|
|
4
4
|
export { seedAchievementCatalog, seedAchievements } from './seed/index.js';
|
|
5
5
|
export type { AchievementSeedAchievement, AchievementSeedCatalogRow, AchievementSeedInput, AchievementSeedLocalizedText, AchievementSeedTier, } from './seed/index.js';
|
|
6
|
-
export { evaluateRules, evaluateRuleProgress, collectAchievementCompleteRefs, buildCatalogProgressGroups, buildUnlockRequirementLeaves, getUserProgress, loadUserProgressReviews, getMetricLeaderboard, grantAchievement, loadMetricDoc, recordEvent, recordLog, recordMetricChange, rebuildMetricBalance, rebuildMetricBalancesForUser, reconcileProgression, reconcileUserProgression, releasePendingAchievementReviews, releasePendingTierReviews, resolveCurrentTier, resolveElapsedAnchor, resolveMetricValue, resolveTierProgress, reviewAchievementRequest, submitAchievementRequest, syncTierChangedLog, syncTierProgression, syncCompositeProgression, syncProgressionFromLog, runReactions, catalogRef, transitionLogData, transitionToId, logSubject, readLogSubject, validateRuleGroup, validateRuleNode, } from './services/achievement/index.js';
|
|
7
|
-
export type { ResolvedTier, RuleGroup, TierLadderProgress, CatalogProgressGroup, CatalogProgressItem, UnlockRequirementLeaf, UnlockRequirementRelation, GetUserProgressInclude, UserProgressMeResponse, UserProgressReviews, UserProgressTierRequest, CatalogRef, TransitionLogData, LogSubjectRef, MetricLeaderboardResult, MetricLeaderboardRow, ReconcileProgressionArgs, ReconcileProgressionResult, ReleaseReviewGateResult, } from './services/achievement/index.js';
|
|
6
|
+
export { evaluateRules, evaluateRuleProgress, collectAchievementCompleteRefs, buildCatalogProgressGroups, buildUnlockRequirementLeaves, getUserProgress, loadUserProgressReviews, getMetricLeaderboard, grantAchievement, loadMetricDoc, recordEvent, recordLog, recordMetricChange, rebuildMetricBalance, rebuildMetricBalancesForUser, reconcileProgression, reconcileUserProgression, releasePendingAchievementReviews, releasePendingTierReviews, resolveCurrentTier, resolveElapsedAnchor, resolveMetricValue, resolveTierProgress, findTierRequestsForReview, reviewAchievementRequest, reviewTierRequest, submitAchievementRequest, submitTierRequest, syncTierChangedLog, syncTierProgression, syncCompositeProgression, syncProgressionFromLog, runReactions, catalogRef, transitionLogData, transitionToId, logSubject, readLogSubject, validateRuleGroup, validateRuleNode, } from './services/achievement/index.js';
|
|
7
|
+
export type { ResolvedTier, RuleGroup, TierLadderProgress, CatalogProgressGroup, CatalogProgressItem, UnlockRequirementLeaf, UnlockRequirementRelation, GetUserProgressInclude, UserProgressMeResponse, UserProgressReviews, UserProgressTierRequest, CatalogRef, TransitionLogData, LogSubjectRef, MetricLeaderboardResult, MetricLeaderboardRow, FindTierRequestsForReviewArgs, ReconcileProgressionArgs, ReconcileProgressionResult, ReleaseReviewGateResult, } from './services/achievement/index.js';
|
|
8
8
|
export type { BuiltInEventType, BuiltInRuleType, AchievementCollectionKey, AchievementCollectionOverride, AchievementCollectionsOptions, AchievementEndpointsOptions, AchievementMetricAnchor, AchievementMetricAnchorConfig, AchievementMetricAnchorEntry, AchievementPluginOptions, AchievementRuleType, AchievementAction, AchievementActionRunArgs, AchievementReactionTrigger, AchievementScopeConfig, AchievementSubjectsOptions, AchievementUsersOptions, } from './types.js';
|
|
9
9
|
export { DEFAULT_COLLECTION_BASE_SLUGS, DEFAULT_COLLECTION_PREFIX, DEFAULT_ADMIN_GROUP } from './collections/slugs.js';
|
|
10
10
|
export { DEFAULT_ME_ENDPOINT_PATH, DEFAULT_LEADERBOARD_ENDPOINT_PATH, DEFAULT_RECONCILE_ENDPOINT_PATH, resolveSubjectCollections, resolveSubjectCollectionsFromConfig, } from './defaults.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0BAA0B,EAC1B,+BAA+B,EAC/B,kBAAkB,EAClB,cAAc,EACd,uBAAuB,EACvB,qBAAqB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0BAA0B,EAC1B,+BAA+B,EAC/B,kBAAkB,EAClB,cAAc,EACd,uBAAuB,EACvB,8BAA8B,EAC9B,qBAAqB,EACrB,2BAA2B,GAC5B,MAAM,cAAc,CAAA;AACrB,YAAY,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AACzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAC1E,YAAY,EACV,0BAA0B,EAC1B,yBAAyB,EACzB,oBAAoB,EACpB,4BAA4B,EAC5B,mBAAmB,GACpB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EACL,aAAa,EACb,oBAAoB,EACpB,8BAA8B,EAC9B,0BAA0B,EAC1B,4BAA4B,EAC5B,eAAe,EACf,uBAAuB,EACvB,oBAAoB,EACpB,gBAAgB,EAChB,aAAa,EACb,WAAW,EACX,SAAS,EACT,kBAAkB,EAClB,oBAAoB,EACpB,4BAA4B,EAC5B,oBAAoB,EACpB,wBAAwB,EACxB,gCAAgC,EAChC,yBAAyB,EACzB,kBAAkB,EAClB,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,EACnB,yBAAyB,EACzB,wBAAwB,EACxB,iBAAiB,EACjB,wBAAwB,EACxB,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,EACnB,wBAAwB,EACxB,sBAAsB,EACtB,YAAY,EACZ,UAAU,EACV,iBAAiB,EACjB,cAAc,EACd,UAAU,EACV,cAAc,EACd,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,iCAAiC,CAAA;AACxC,YAAY,EACV,YAAY,EACZ,SAAS,EACT,kBAAkB,EAClB,oBAAoB,EACpB,mBAAmB,EACnB,qBAAqB,EACrB,yBAAyB,EACzB,sBAAsB,EACtB,sBAAsB,EACtB,mBAAmB,EACnB,uBAAuB,EACvB,UAAU,EACV,iBAAiB,EACjB,aAAa,EACb,uBAAuB,EACvB,oBAAoB,EACpB,6BAA6B,EAC7B,wBAAwB,EACxB,0BAA0B,EAC1B,uBAAuB,GACxB,MAAM,iCAAiC,CAAA;AACxC,YAAY,EACV,gBAAgB,EAChB,eAAe,EACf,wBAAwB,EACxB,6BAA6B,EAC7B,6BAA6B,EAC7B,2BAA2B,EAC3B,uBAAuB,EACvB,6BAA6B,EAC7B,4BAA4B,EAC5B,wBAAwB,EACxB,mBAAmB,EACnB,iBAAiB,EACjB,wBAAwB,EACxB,0BAA0B,EAC1B,sBAAsB,EACtB,0BAA0B,EAC1B,uBAAuB,GACxB,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,6BAA6B,EAAE,yBAAyB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAA;AACtH,OAAO,EACL,wBAAwB,EACxB,iCAAiC,EACjC,+BAA+B,EAC/B,yBAAyB,EACzB,mCAAmC,GACpC,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAA;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAA;AAClE,OAAO,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAA;AACzD,OAAO,EAAE,sBAAsB,EAAE,MAAM,kCAAkC,CAAA;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { DEFAULT_ACHIEVEMENT_METRIC, DEFAULT_ACHIEVEMENT_METRIC_SLUG, ENGINE_EVENT_TYPES, ENGINE_METRICS, GRANT_AUDIT_EVENT_SLUGS, isGrantAuditEventSlug, } from './catalog.js';
|
|
1
|
+
export { DEFAULT_ACHIEVEMENT_METRIC, DEFAULT_ACHIEVEMENT_METRIC_SLUG, ENGINE_EVENT_TYPES, ENGINE_METRICS, GRANT_AUDIT_EVENT_SLUGS, TIER_REQUEST_AUDIT_EVENT_SLUGS, isGrantAuditEventSlug, isTierRequestAuditEventSlug, } from './catalog.js';
|
|
2
2
|
export { achievementPlugin } from './plugin.js';
|
|
3
3
|
export { seedAchievementCatalog, seedAchievements } from './seed/index.js';
|
|
4
|
-
export { evaluateRules, evaluateRuleProgress, collectAchievementCompleteRefs, buildCatalogProgressGroups, buildUnlockRequirementLeaves, getUserProgress, loadUserProgressReviews, getMetricLeaderboard, grantAchievement, loadMetricDoc, recordEvent, recordLog, recordMetricChange, rebuildMetricBalance, rebuildMetricBalancesForUser, reconcileProgression, reconcileUserProgression, releasePendingAchievementReviews, releasePendingTierReviews, resolveCurrentTier, resolveElapsedAnchor, resolveMetricValue, resolveTierProgress, reviewAchievementRequest, submitAchievementRequest, syncTierChangedLog, syncTierProgression, syncCompositeProgression, syncProgressionFromLog, runReactions, catalogRef, transitionLogData, transitionToId, logSubject, readLogSubject, validateRuleGroup, validateRuleNode, } from './services/achievement/index.js';
|
|
4
|
+
export { evaluateRules, evaluateRuleProgress, collectAchievementCompleteRefs, buildCatalogProgressGroups, buildUnlockRequirementLeaves, getUserProgress, loadUserProgressReviews, getMetricLeaderboard, grantAchievement, loadMetricDoc, recordEvent, recordLog, recordMetricChange, rebuildMetricBalance, rebuildMetricBalancesForUser, reconcileProgression, reconcileUserProgression, releasePendingAchievementReviews, releasePendingTierReviews, resolveCurrentTier, resolveElapsedAnchor, resolveMetricValue, resolveTierProgress, findTierRequestsForReview, reviewAchievementRequest, reviewTierRequest, submitAchievementRequest, submitTierRequest, syncTierChangedLog, syncTierProgression, syncCompositeProgression, syncProgressionFromLog, runReactions, catalogRef, transitionLogData, transitionToId, logSubject, readLogSubject, validateRuleGroup, validateRuleNode, } from './services/achievement/index.js';
|
|
5
5
|
export { DEFAULT_COLLECTION_BASE_SLUGS, DEFAULT_COLLECTION_PREFIX, DEFAULT_ADMIN_GROUP } from './collections/slugs.js';
|
|
6
6
|
export { DEFAULT_ME_ENDPOINT_PATH, DEFAULT_LEADERBOARD_ENDPOINT_PATH, DEFAULT_RECONCILE_ENDPOINT_PATH, resolveSubjectCollections, resolveSubjectCollectionsFromConfig, } from './defaults.js';
|
|
7
7
|
export { collectionOf, slugOf } from './collections/helpers.js';
|