@jskit-ai/rewarded-core 0.2.15 → 0.2.16
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/CHANGELOG.md +6 -0
- package/README.md +3 -2
- package/package.json +14 -13
- package/src/server/RewardedResources.js +13 -17
- package/src/server/service.js +38 -78
- package/src/server/types.js +3 -2
- package/src/shared/index.js +4 -12
- package/src/shared/rewardedProviderConfigResource.js +55 -72
- package/src/shared/rewardedRuleResource.js +80 -113
- package/src/shared/rewardedUnlockReceiptResource.js +70 -90
- package/src/shared/rewardedWatchSessionResource.js +85 -116
- package/test/featureRuntime.test.js +27 -15
- package/test/service.integration.test.js +69 -90
- package/test/service.test.js +37 -61
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
- `@jskit-ai/database-runtime` and `@jskit-ai/resource-runtime` are peer dependencies, required and at the same versions, where they were dependencies: its rules, provider settings, watch sessions and unlock receipts are table resources, and the app holds one copy of the table runtime that every package shares, as it does the kernel. npm installs a required peer as it installed the dependency, so an app installs the same packages and versions; a release whose versions disagree now fails the install with ERESOLVE instead of nesting a second copy.
|
|
6
|
+
- `@jskit-ai/database-runtime` is a dependency again: the foreign-key migration (`migrations/constraints/rewarded_foreign_keys.cjs`) imports its `server/foreignKeyMigrations` in `up` and `down`, which resolved only through hoisting since the CRUD features moved to the resource runtime.
|
|
7
|
+
- The rewarded table resources no longer declare their own `id` search entry: their handles' `id` filter takes one id or a list.
|
|
8
|
+
- The package requires `crud.contracts`, the registry of served CRUD contracts its CRUD features register with, so an application that installs it also loads crud-core's `CrudContractsProvider`.
|
|
9
|
+
- The rewarded CRUD contracts name every field they show and accept, since a contract now shows only the fields it names; what each one shows and accepts is unchanged.
|
|
10
|
+
- **Breaking (data-access redesign).** Each rewarded table is one table resource with a CRUD contract on it: `rewardedRuleTableResource`/`rewardedRuleCrud`, `rewardedProviderConfigTableResource`/`rewardedProviderConfigCrud`, `rewardedWatchSessionTableResource`/`rewardedWatchSessionCrud` and `rewardedUnlockReceiptTableResource`/`rewardedUnlockReceiptCrud`, exported from `./shared`, which replace `rewardedRuleResource`, `rewardedProviderConfigResource`, `rewardedWatchSessionResource` and `rewardedUnlockReceiptResource`. The HTTP routes, namespaces and fields are unchanged.
|
|
5
11
|
- The rewarded resources' save, delete and validation feedback names catalog keys under `jskit.rewarded.feedback.*` instead of plain English; JSKIT's forms render them with `text()`, so the English shown is unchanged.
|
|
6
12
|
|
|
7
13
|
### New message keys (5)
|
package/README.md
CHANGED
|
@@ -85,12 +85,13 @@ That page shows the service and feature wiring pattern.
|
|
|
85
85
|
## Grant authorization
|
|
86
86
|
|
|
87
87
|
The application must supply capability `rewarded.grant-policy` with an
|
|
88
|
-
`authorizeGrant({ session, context,
|
|
88
|
+
`authorizeGrant({ session, context, options })` function. Missing policy fails at setup;
|
|
89
89
|
only the literal result `true` permits a grant. False, absent or other results
|
|
90
90
|
reject it before any watch-session update or receipt creation.
|
|
91
91
|
|
|
92
92
|
The workflow loads the session through its owned repository, then passes that
|
|
93
|
-
stored session, the server request context and the
|
|
93
|
+
stored session, the server request context and the grant's call options (inside its
|
|
94
|
+
transaction) to policy; pass `options` on to any read the decision makes.
|
|
94
95
|
It never accepts a client approval flag or replacement gate identity. The policy
|
|
95
96
|
runs for repeated grant requests too. Keep policy local and bounded within the
|
|
96
97
|
transaction; use the application's trusted eligibility or verification records.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jskit-ai/rewarded-core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.16",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "jskit test"
|
|
@@ -24,11 +24,11 @@
|
|
|
24
24
|
"rewarded.core"
|
|
25
25
|
],
|
|
26
26
|
"requires": [
|
|
27
|
+
"crud.contracts",
|
|
27
28
|
"runtime.actions",
|
|
28
|
-
"runtime.database",
|
|
29
29
|
"runtime.http",
|
|
30
|
-
"
|
|
31
|
-
"
|
|
30
|
+
"rewarded.grant-policy",
|
|
31
|
+
"runtime.resources"
|
|
32
32
|
],
|
|
33
33
|
"applicationRequires": [
|
|
34
34
|
"rewarded.grant-policy"
|
|
@@ -125,17 +125,18 @@
|
|
|
125
125
|
}
|
|
126
126
|
},
|
|
127
127
|
"dependencies": {
|
|
128
|
-
"@jskit-ai/crud-core": "0.2.
|
|
129
|
-
"@jskit-ai/
|
|
130
|
-
"@jskit-ai/
|
|
131
|
-
"@jskit-ai/
|
|
132
|
-
"@jskit-ai/
|
|
133
|
-
"@jskit-ai/workspaces-core": "0.2.15",
|
|
128
|
+
"@jskit-ai/crud-core": "0.2.15",
|
|
129
|
+
"@jskit-ai/resource-core": "0.1.205",
|
|
130
|
+
"@jskit-ai/resource-crud-core": "0.1.205",
|
|
131
|
+
"@jskit-ai/users-core": "0.2.16",
|
|
132
|
+
"@jskit-ai/workspaces-core": "0.2.16",
|
|
134
133
|
"json-rest-schema": "^1.0.17"
|
|
135
134
|
},
|
|
136
135
|
"peerDependencies": {
|
|
137
|
-
"@jskit-ai/auth-core": "0.2.
|
|
138
|
-
"@jskit-ai/
|
|
139
|
-
"@jskit-ai/
|
|
136
|
+
"@jskit-ai/auth-core": "0.2.14",
|
|
137
|
+
"@jskit-ai/database-runtime": "0.1.263",
|
|
138
|
+
"@jskit-ai/http-runtime": "0.2.14",
|
|
139
|
+
"@jskit-ai/kernel": "0.2.14",
|
|
140
|
+
"@jskit-ai/resource-runtime": "0.2.12"
|
|
140
141
|
}
|
|
141
142
|
}
|
|
@@ -1,49 +1,45 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defineCrudFeature } from "@jskit-ai/crud-core/server/defineCrudFeature";
|
|
2
2
|
import { WORKSPACE_CRUD_SCOPE } from "@jskit-ai/workspaces-core/server/support/workspaceCrud";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
3
|
+
import { rewardedProviderConfigCrud } from "../shared/rewardedProviderConfigResource.js";
|
|
4
|
+
import { rewardedRuleCrud } from "../shared/rewardedRuleResource.js";
|
|
5
|
+
import { rewardedUnlockReceiptCrud } from "../shared/rewardedUnlockReceiptResource.js";
|
|
6
|
+
import { rewardedWatchSessionCrud } from "../shared/rewardedWatchSessionResource.js";
|
|
7
7
|
|
|
8
|
-
const RewardedRulesFeature =
|
|
8
|
+
const RewardedRulesFeature = defineCrudFeature({
|
|
9
9
|
id: "rewarded.rules",
|
|
10
10
|
capability: "rewarded.rules",
|
|
11
|
-
|
|
11
|
+
crud: rewardedRuleCrud,
|
|
12
12
|
surface: "admin",
|
|
13
|
-
ownershipFilter: "workspace",
|
|
14
13
|
relativePath: "/rewarded-rules",
|
|
15
14
|
internal: true,
|
|
16
15
|
scope: WORKSPACE_CRUD_SCOPE
|
|
17
16
|
});
|
|
18
17
|
|
|
19
|
-
const RewardedProviderConfigsFeature =
|
|
18
|
+
const RewardedProviderConfigsFeature = defineCrudFeature({
|
|
20
19
|
id: "rewarded.provider-configs",
|
|
21
20
|
capability: "rewarded.provider-configs",
|
|
22
|
-
|
|
21
|
+
crud: rewardedProviderConfigCrud,
|
|
23
22
|
surface: "admin",
|
|
24
|
-
ownershipFilter: "workspace",
|
|
25
23
|
relativePath: "/rewarded-provider-configs",
|
|
26
24
|
internal: true,
|
|
27
25
|
scope: WORKSPACE_CRUD_SCOPE
|
|
28
26
|
});
|
|
29
27
|
|
|
30
|
-
const RewardedWatchSessionsFeature =
|
|
28
|
+
const RewardedWatchSessionsFeature = defineCrudFeature({
|
|
31
29
|
id: "rewarded.watch-sessions",
|
|
32
30
|
capability: "rewarded.watch-sessions",
|
|
33
|
-
|
|
31
|
+
crud: rewardedWatchSessionCrud,
|
|
34
32
|
surface: "admin",
|
|
35
|
-
ownershipFilter: "workspace_user",
|
|
36
33
|
relativePath: "/rewarded-watch-sessions",
|
|
37
34
|
internal: true,
|
|
38
35
|
scope: WORKSPACE_CRUD_SCOPE
|
|
39
36
|
});
|
|
40
37
|
|
|
41
|
-
const RewardedUnlockReceiptsFeature =
|
|
38
|
+
const RewardedUnlockReceiptsFeature = defineCrudFeature({
|
|
42
39
|
id: "rewarded.unlock-receipts",
|
|
43
40
|
capability: "rewarded.unlock-receipts",
|
|
44
|
-
|
|
41
|
+
crud: rewardedUnlockReceiptCrud,
|
|
45
42
|
surface: "admin",
|
|
46
|
-
ownershipFilter: "workspace_user",
|
|
47
43
|
relativePath: "/rewarded-unlock-receipts",
|
|
48
44
|
internal: true,
|
|
49
45
|
scope: WORKSPACE_CRUD_SCOPE
|
package/src/server/service.js
CHANGED
|
@@ -1,21 +1,8 @@
|
|
|
1
1
|
import { AppError } from "@jskit-ai/kernel/server/runtime/errors";
|
|
2
2
|
import { normalizeText } from "@jskit-ai/kernel/shared/support/normalize";
|
|
3
|
-
import { jsonApiNextCursor, simplifyJsonApiDocument } from "@jskit-ai/http-runtime/shared";
|
|
4
3
|
import { resolveActionUser } from "@jskit-ai/users-core/server/resolveActionUser";
|
|
5
4
|
|
|
6
5
|
const REWARDED_SURFACE = "app";
|
|
7
|
-
// json-rest-api's largest page.
|
|
8
|
-
const RECEIPT_PAGE_SIZE = 100;
|
|
9
|
-
|
|
10
|
-
function normalizeRecordList(document) {
|
|
11
|
-
const simplified = simplifyJsonApiDocument(document);
|
|
12
|
-
return Array.isArray(simplified) ? simplified.filter(Boolean) : [];
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function normalizeRecord(document) {
|
|
16
|
-
const simplified = simplifyJsonApiDocument(document);
|
|
17
|
-
return simplified && typeof simplified === "object" && !Array.isArray(simplified) ? simplified : null;
|
|
18
|
-
}
|
|
19
6
|
|
|
20
7
|
/**
|
|
21
8
|
* Lower-case text, or the fallback when there is none.
|
|
@@ -142,7 +129,7 @@ function isFutureDate(value, now) {
|
|
|
142
129
|
}
|
|
143
130
|
|
|
144
131
|
/** @typedef {import("@jskit-ai/crud-core/server/types").CrudRepository} CrudRepository */
|
|
145
|
-
/** @typedef {
|
|
132
|
+
/** @typedef {import("@jskit-ai/resource-runtime/server/types").ResourceCallOptions} RewardedRepositoryOptions */
|
|
146
133
|
|
|
147
134
|
/**
|
|
148
135
|
* The Rewarded gate workflow over its four resources' repositories and the
|
|
@@ -163,71 +150,48 @@ function createService({
|
|
|
163
150
|
rewardedUnlockReceiptsRepository
|
|
164
151
|
}) {
|
|
165
152
|
/**
|
|
153
|
+
* The newest record the filters match, or null.
|
|
166
154
|
* @param {CrudRepository} repository
|
|
155
|
+
* @param {Record<string, unknown>} filters
|
|
156
|
+
* @param {string} newestFirst The sort that puts the newest record first.
|
|
167
157
|
* @param {RewardedRepositoryOptions} repositoryOptions
|
|
168
158
|
*/
|
|
169
|
-
async function
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* @param {CrudRepository} repository
|
|
175
|
-
* @param {RewardedRepositoryOptions} repositoryOptions
|
|
176
|
-
*/
|
|
177
|
-
async function queryFirst(repository, query, repositoryOptions) {
|
|
178
|
-
return (await listRecords(repository, query, repositoryOptions))[0] || null;
|
|
159
|
+
async function queryFirst(repository, filters, newestFirst, repositoryOptions) {
|
|
160
|
+
const { records } = await repository.query({ filters, sort: [newestFirst], page: { size: 1 } }, repositoryOptions);
|
|
161
|
+
return records[0] || null;
|
|
179
162
|
}
|
|
180
163
|
|
|
181
164
|
/** @param {RewardedRepositoryOptions} repositoryOptions */
|
|
182
165
|
async function resolveRule(gateKey, repositoryOptions) {
|
|
183
|
-
return queryFirst(rewardedRulesRepository, {
|
|
184
|
-
gateKey,
|
|
185
|
-
enabled: "true",
|
|
186
|
-
surface: REWARDED_SURFACE,
|
|
187
|
-
sort: ["-updatedAt"],
|
|
188
|
-
limit: 1
|
|
189
|
-
}, repositoryOptions);
|
|
166
|
+
return queryFirst(rewardedRulesRepository, { gateKey, enabled: true, surface: REWARDED_SURFACE }, "-updatedAt", repositoryOptions);
|
|
190
167
|
}
|
|
191
168
|
|
|
192
169
|
/** @param {RewardedRepositoryOptions} repositoryOptions */
|
|
193
170
|
async function resolveProviderConfig(repositoryOptions) {
|
|
194
|
-
return queryFirst(rewardedProviderConfigsRepository, {
|
|
195
|
-
surface: REWARDED_SURFACE,
|
|
196
|
-
enabled: "true",
|
|
197
|
-
sort: ["-updatedAt"],
|
|
198
|
-
limit: 1
|
|
199
|
-
}, repositoryOptions);
|
|
171
|
+
return queryFirst(rewardedProviderConfigsRepository, { surface: REWARDED_SURFACE, enabled: true }, "-updatedAt", repositoryOptions);
|
|
200
172
|
}
|
|
201
173
|
|
|
202
174
|
/** @param {RewardedRepositoryOptions} repositoryOptions */
|
|
203
175
|
async function resolveUnlockReceipts(gateKey, repositoryOptions) {
|
|
204
|
-
|
|
205
|
-
gateKey,
|
|
176
|
+
const { records } = await rewardedUnlockReceiptsRepository.query({
|
|
177
|
+
filters: { gateKey },
|
|
206
178
|
sort: ["-grantedAt"],
|
|
207
|
-
|
|
179
|
+
page: { size: 25 }
|
|
208
180
|
}, repositoryOptions);
|
|
181
|
+
return records;
|
|
209
182
|
}
|
|
210
183
|
|
|
211
184
|
/**
|
|
212
|
-
* How many of the gate's receipts were granted since `since`,
|
|
213
|
-
*
|
|
214
|
-
* count is exact for any daily limit.
|
|
185
|
+
* How many of the gate's receipts were granted since `since`, counted in one
|
|
186
|
+
* query, so the count is exact for any daily limit.
|
|
215
187
|
* @param {RewardedRepositoryOptions} repositoryOptions
|
|
216
188
|
*/
|
|
217
|
-
async function countReceiptsGrantedSince(gateKey, since,
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
grantedSince: since.toISOString(),
|
|
224
|
-
limit: RECEIPT_PAGE_SIZE,
|
|
225
|
-
...(cursor ? { cursor } : {})
|
|
226
|
-
}, repositoryOptions);
|
|
227
|
-
count += normalizeRecordList(document).length;
|
|
228
|
-
cursor = jsonApiNextCursor(document);
|
|
229
|
-
} while (cursor && count < dailyLimit);
|
|
230
|
-
return count;
|
|
189
|
+
async function countReceiptsGrantedSince(gateKey, since, repositoryOptions) {
|
|
190
|
+
const [totals] = await rewardedUnlockReceiptsRepository.aggregate({
|
|
191
|
+
measures: { granted: { count: "*" } },
|
|
192
|
+
filters: { gateKey, grantedSince: since.toISOString() }
|
|
193
|
+
}, repositoryOptions);
|
|
194
|
+
return Number(totals?.granted || 0);
|
|
231
195
|
}
|
|
232
196
|
|
|
233
197
|
async function evaluateGate(input, context) {
|
|
@@ -320,7 +284,7 @@ function createService({
|
|
|
320
284
|
}
|
|
321
285
|
|
|
322
286
|
if (rule.dailyLimit != null) {
|
|
323
|
-
const todaysCount = await countReceiptsGrantedSince(gateKey, startOfUtcDay(now),
|
|
287
|
+
const todaysCount = await countReceiptsGrantedSince(gateKey, startOfUtcDay(now), { context });
|
|
324
288
|
const remaining = Math.max(0, Number(rule.dailyLimit) - todaysCount);
|
|
325
289
|
if (remaining < 1) {
|
|
326
290
|
return {
|
|
@@ -384,7 +348,7 @@ function createService({
|
|
|
384
348
|
};
|
|
385
349
|
}
|
|
386
350
|
|
|
387
|
-
const createdSession =
|
|
351
|
+
const createdSession = await rewardedWatchSessionsRepository.create(
|
|
388
352
|
{
|
|
389
353
|
gateKey: state.gateKey,
|
|
390
354
|
providerConfigId: state.providerConfig?.id || null,
|
|
@@ -392,7 +356,7 @@ function createService({
|
|
|
392
356
|
startedAt: new Date().toISOString()
|
|
393
357
|
},
|
|
394
358
|
{ context }
|
|
395
|
-
)
|
|
359
|
+
);
|
|
396
360
|
|
|
397
361
|
return {
|
|
398
362
|
...state,
|
|
@@ -408,8 +372,8 @@ function createService({
|
|
|
408
372
|
throw new AppError(400, "sessionId is required.", { code: "rewarded.request.sessionIdRequired" });
|
|
409
373
|
}
|
|
410
374
|
|
|
411
|
-
return rewardedWatchSessionsRepository.withTransaction(async (
|
|
412
|
-
const sessionRecord =
|
|
375
|
+
return rewardedWatchSessionsRepository.withTransaction({ context }, async (txOptions) => {
|
|
376
|
+
const sessionRecord = await rewardedWatchSessionsRepository.get(sessionId, {}, { ...txOptions, missing: "skip" });
|
|
413
377
|
if (!sessionRecord) {
|
|
414
378
|
throw new AppError(404, "Watch session not found.", { code: "rewarded.session.notFound" });
|
|
415
379
|
}
|
|
@@ -417,7 +381,7 @@ function createService({
|
|
|
417
381
|
const authorized = await grantPolicy.authorizeGrant({
|
|
418
382
|
session: formatWatchSession(sessionRecord),
|
|
419
383
|
context,
|
|
420
|
-
|
|
384
|
+
options: txOptions
|
|
421
385
|
});
|
|
422
386
|
if (authorized !== true) {
|
|
423
387
|
throw new AppError(403, "Reward grant is not authorized.", { code: "rewarded.session.grantNotAuthorized" });
|
|
@@ -427,11 +391,7 @@ function createService({
|
|
|
427
391
|
throw new AppError(409, "Watch session is already closed.", { code: "rewarded.session.closed" });
|
|
428
392
|
}
|
|
429
393
|
if (sessionRecord.rewardedAt || normalizeText(sessionRecord.status).toLowerCase() === "rewarded") {
|
|
430
|
-
const receiptRecord = await queryFirst(rewardedUnlockReceiptsRepository, {
|
|
431
|
-
watchSessionId: sessionId,
|
|
432
|
-
sort: ["-grantedAt"],
|
|
433
|
-
limit: 1
|
|
434
|
-
}, { context, trx });
|
|
394
|
+
const receiptRecord = await queryFirst(rewardedUnlockReceiptsRepository, { watchSessionId: sessionId }, "-grantedAt", txOptions);
|
|
435
395
|
return {
|
|
436
396
|
unlocked: true,
|
|
437
397
|
workspaceSlug,
|
|
@@ -441,7 +401,7 @@ function createService({
|
|
|
441
401
|
};
|
|
442
402
|
}
|
|
443
403
|
|
|
444
|
-
const ruleRecord = await resolveRule(normalizeText(sessionRecord.gateKey),
|
|
404
|
+
const ruleRecord = await resolveRule(normalizeText(sessionRecord.gateKey), txOptions);
|
|
445
405
|
if (!ruleRecord) {
|
|
446
406
|
throw new AppError(409, "No rewarded rule is configured for this session.", {
|
|
447
407
|
code: "rewarded.session.ruleMissing"
|
|
@@ -452,17 +412,17 @@ function createService({
|
|
|
452
412
|
const nowIso = now.toISOString();
|
|
453
413
|
const unlockedUntil = addMinutes(now, Number(ruleRecord.unlockMinutes || 0));
|
|
454
414
|
|
|
455
|
-
const updatedSession =
|
|
415
|
+
const updatedSession = await rewardedWatchSessionsRepository.patch(
|
|
456
416
|
sessionId,
|
|
457
417
|
{
|
|
458
418
|
status: "rewarded",
|
|
459
419
|
rewardedAt: nowIso,
|
|
460
420
|
completedAt: nowIso
|
|
461
421
|
},
|
|
462
|
-
|
|
463
|
-
)
|
|
422
|
+
txOptions
|
|
423
|
+
);
|
|
464
424
|
|
|
465
|
-
const createdReceipt =
|
|
425
|
+
const createdReceipt = await rewardedUnlockReceiptsRepository.create(
|
|
466
426
|
{
|
|
467
427
|
gateKey: normalizeText(sessionRecord.gateKey),
|
|
468
428
|
providerConfigId: sessionRecord.providerConfigId || null,
|
|
@@ -470,8 +430,8 @@ function createService({
|
|
|
470
430
|
grantedAt: nowIso,
|
|
471
431
|
unlockedUntil: unlockedUntil.toISOString()
|
|
472
432
|
},
|
|
473
|
-
|
|
474
|
-
)
|
|
433
|
+
txOptions
|
|
434
|
+
);
|
|
475
435
|
|
|
476
436
|
return {
|
|
477
437
|
unlocked: true,
|
|
@@ -491,7 +451,7 @@ function createService({
|
|
|
491
451
|
throw new AppError(400, "sessionId is required.", { code: "rewarded.request.sessionIdRequired" });
|
|
492
452
|
}
|
|
493
453
|
|
|
494
|
-
const sessionRecord =
|
|
454
|
+
const sessionRecord = await rewardedWatchSessionsRepository.get(sessionId, {}, { context, missing: "skip" });
|
|
495
455
|
if (!sessionRecord) {
|
|
496
456
|
throw new AppError(404, "Watch session not found.", { code: "rewarded.session.notFound" });
|
|
497
457
|
}
|
|
@@ -506,14 +466,14 @@ function createService({
|
|
|
506
466
|
};
|
|
507
467
|
}
|
|
508
468
|
|
|
509
|
-
const closedSession =
|
|
469
|
+
const closedSession = await rewardedWatchSessionsRepository.patch(
|
|
510
470
|
sessionId,
|
|
511
471
|
{
|
|
512
472
|
status: "closed",
|
|
513
473
|
closedAt: new Date().toISOString()
|
|
514
474
|
},
|
|
515
475
|
{ context }
|
|
516
|
-
)
|
|
476
|
+
);
|
|
517
477
|
|
|
518
478
|
return {
|
|
519
479
|
closed: true,
|
package/src/server/types.js
CHANGED
|
@@ -10,8 +10,9 @@
|
|
|
10
10
|
* The `rewarded.grant-policy` capability the application provides: it decides
|
|
11
11
|
* whether a watch session earns its reward.
|
|
12
12
|
* @typedef {object} RewardedGrantPolicy
|
|
13
|
-
* @property {(input: { session: object, context: object,
|
|
14
|
-
* Answers true when the session's reward may be granted.
|
|
13
|
+
* @property {(input: { session: object, context: object, options: import("@jskit-ai/resource-runtime/server/types").ResourceCallOptions }) => boolean | Promise<boolean>} authorizeGrant
|
|
14
|
+
* Answers true when the session's reward may be granted. `options` are the grant's call options, inside its
|
|
15
|
+
* transaction: pass them on to any read the decision needs.
|
|
15
16
|
*/
|
|
16
17
|
|
|
17
18
|
export {};
|
package/src/shared/index.js
CHANGED
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
export {
|
|
2
|
-
|
|
3
|
-
} from "./
|
|
4
|
-
export {
|
|
5
|
-
resource as rewardedProviderConfigResource
|
|
6
|
-
} from "./rewardedProviderConfigResource.js";
|
|
7
|
-
export {
|
|
8
|
-
resource as rewardedWatchSessionResource
|
|
9
|
-
} from "./rewardedWatchSessionResource.js";
|
|
10
|
-
export {
|
|
11
|
-
resource as rewardedUnlockReceiptResource
|
|
12
|
-
} from "./rewardedUnlockReceiptResource.js";
|
|
1
|
+
export { rewardedRuleCrud, rewardedRuleTableResource } from "./rewardedRuleResource.js";
|
|
2
|
+
export { rewardedProviderConfigCrud, rewardedProviderConfigTableResource } from "./rewardedProviderConfigResource.js";
|
|
3
|
+
export { rewardedWatchSessionCrud, rewardedWatchSessionTableResource } from "./rewardedWatchSessionResource.js";
|
|
4
|
+
export { rewardedUnlockReceiptCrud, rewardedUnlockReceiptTableResource } from "./rewardedUnlockReceiptResource.js";
|
|
@@ -1,81 +1,64 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defineTableResource } from "@jskit-ai/resource-core/shared/tableResource";
|
|
2
|
+
import { defineCrudContract } from "@jskit-ai/resource-crud-core/shared/crudContract";
|
|
2
3
|
|
|
3
|
-
const
|
|
4
|
-
|
|
4
|
+
const rewardedProviderConfigTableResource = defineTableResource({
|
|
5
|
+
name: "rewardedProviderConfigs",
|
|
5
6
|
tableName: "rewarded_provider_configs",
|
|
7
|
+
ownership: "workspace",
|
|
6
8
|
schema: {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
9
|
+
workspaceId: {
|
|
10
|
+
type: "id",
|
|
11
|
+
required: true,
|
|
12
|
+
search: true,
|
|
13
|
+
hidden: true
|
|
14
|
+
},
|
|
15
|
+
surface: {
|
|
16
|
+
type: "string",
|
|
17
|
+
maxLength: 64,
|
|
18
|
+
required: true,
|
|
19
|
+
search: true
|
|
20
|
+
},
|
|
21
|
+
enabled: {
|
|
22
|
+
type: "boolean",
|
|
23
|
+
search: true
|
|
24
|
+
},
|
|
25
|
+
placement: {
|
|
26
|
+
type: "string",
|
|
27
|
+
maxLength: 255,
|
|
28
|
+
required: true,
|
|
29
|
+
search: true
|
|
30
|
+
},
|
|
31
|
+
provider: {
|
|
32
|
+
type: "string",
|
|
33
|
+
maxLength: 64,
|
|
34
|
+
required: true,
|
|
35
|
+
search: true
|
|
36
|
+
},
|
|
37
|
+
createdAt: {
|
|
38
|
+
type: "dateTime",
|
|
39
|
+
storage: { writeSerializer: "datetime-utc" }
|
|
40
|
+
},
|
|
41
|
+
updatedAt: {
|
|
42
|
+
type: "dateTime",
|
|
43
|
+
storage: { writeSerializer: "datetime-utc" }
|
|
23
44
|
}
|
|
24
45
|
},
|
|
25
|
-
enabled: {
|
|
26
|
-
type: "boolean",
|
|
27
|
-
search: true,
|
|
28
|
-
operations: {
|
|
29
|
-
output: { required: true },
|
|
30
|
-
create: { required: false },
|
|
31
|
-
patch: { required: false }
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
placement: {
|
|
35
|
-
type: "string",
|
|
36
|
-
maxLength: 255,
|
|
37
|
-
required: true,
|
|
38
|
-
search: true,
|
|
39
|
-
operations: {
|
|
40
|
-
output: { required: true },
|
|
41
|
-
create: { required: true },
|
|
42
|
-
patch: { required: false }
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
provider: {
|
|
46
|
-
type: "string",
|
|
47
|
-
maxLength: 64,
|
|
48
|
-
required: true,
|
|
49
|
-
search: true,
|
|
50
|
-
operations: {
|
|
51
|
-
output: { required: true },
|
|
52
|
-
create: { required: true },
|
|
53
|
-
patch: { required: false }
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
createdAt: {
|
|
57
|
-
type: "dateTime",
|
|
58
|
-
default: "now()",
|
|
59
|
-
storage: { writeSerializer: "datetime-utc" },
|
|
60
|
-
operations: {
|
|
61
|
-
output: { required: true }
|
|
62
|
-
}
|
|
63
|
-
},
|
|
64
|
-
updatedAt: {
|
|
65
|
-
type: "dateTime",
|
|
66
|
-
default: "now()",
|
|
67
|
-
storage: { writeSerializer: "datetime-utc" },
|
|
68
|
-
operations: {
|
|
69
|
-
output: { required: true }
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
},
|
|
73
46
|
searchSchema: {
|
|
74
|
-
|
|
75
|
-
|
|
47
|
+
q: { type: "string", oneOf: ["surface", "placement", "provider"], filterOperator: "like", splitBy: " ", matchAll: true }
|
|
48
|
+
},
|
|
49
|
+
defaultSort: ["-createdAt"]
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const rewardedProviderConfigCrud = defineCrudContract(rewardedProviderConfigTableResource, {
|
|
53
|
+
namespace: "rewarded_provider_configs",
|
|
54
|
+
fields: {
|
|
55
|
+
surface: { output: "required", create: "required", patch: "optional" },
|
|
56
|
+
enabled: { output: "required", create: "optional", patch: "optional" },
|
|
57
|
+
placement: { output: "required", create: "required", patch: "optional" },
|
|
58
|
+
provider: { output: "required", create: "required", patch: "optional" },
|
|
59
|
+
createdAt: { output: "required" },
|
|
60
|
+
updatedAt: { output: "required" }
|
|
76
61
|
},
|
|
77
|
-
defaultSort: ["-createdAt"],
|
|
78
|
-
autofilter: "workspace",
|
|
79
62
|
messages: {
|
|
80
63
|
validation: "jskit.rewarded.feedback.fixInvalidValues",
|
|
81
64
|
saveSuccess: "jskit.rewarded.feedback.recordSaved",
|
|
@@ -92,4 +75,4 @@ const resource = defineCrudResource({
|
|
|
92
75
|
}
|
|
93
76
|
});
|
|
94
77
|
|
|
95
|
-
export {
|
|
78
|
+
export { rewardedProviderConfigCrud, rewardedProviderConfigTableResource };
|