@stamprally/server 0.18.0 → 0.19.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.
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # @stamprally/server v0.18.0
1
+ # @stamprally/server v0.19.0
2
2
 
3
3
  Web Standard `Request` / `Response` handlers for server-authoritative check-ins and reward claims.
4
4
 
package/dist/index.cjs CHANGED
@@ -4,9 +4,13 @@ var core = require('@stamprally/core');
4
4
 
5
5
  // src/examples/transaction.ts
6
6
  async function executeClaimRewardTransaction(database, store, params2, mutation2) {
7
+ if (params2.secondaryStockKey !== void 0 && store.writeSecondaryStock === void 0)
8
+ return { success: false, error: "SECONDARY_STOCK_UNSUPPORTED" };
7
9
  try {
8
10
  return await database.transaction(async (transaction) => {
9
11
  const current = await store.readContext(transaction, params2);
12
+ if (params2.secondaryStockKey !== void 0 && current.secondaryStock === void 0)
13
+ return { success: false, error: "SECONDARY_STOCK_UNSUPPORTED" };
10
14
  const secondaryStock = current.secondaryStock ?? null;
11
15
  const rewardStock2 = params2.stockKey === "__shared__" ? secondaryStock : current.stock;
12
16
  const next = mutation2({
@@ -598,6 +602,40 @@ function validateSyncRequest(value) {
598
602
  return errors({ path: "$", message: "Expected an object.", code: "INVALID_TYPE" });
599
603
  if (value.userId !== void 0 && !nonEmpty(value.userId))
600
604
  return errors({ path: "userId", message: "userId must be non-empty.", code: "INVALID_TYPE" });
605
+ if (value.operations !== void 0) {
606
+ if (!Array.isArray(value.operations))
607
+ return errors({
608
+ path: "operations",
609
+ message: "operations must be an array.",
610
+ code: "INVALID_TYPE"
611
+ });
612
+ const operationErrors = [];
613
+ value.operations.forEach((operation, index) => {
614
+ const path = `operations[${index}]`;
615
+ if (!record(operation)) {
616
+ operationErrors.push({
617
+ path,
618
+ message: "Expected an operation object.",
619
+ code: "INVALID_TYPE"
620
+ });
621
+ return;
622
+ }
623
+ if (operation.kind !== "checkIn" && operation.kind !== "claimReward") {
624
+ operationErrors.push({
625
+ path: `${path}.kind`,
626
+ message: "Unknown sync operation.",
627
+ code: "INVALID_ENUM"
628
+ });
629
+ return;
630
+ }
631
+ const result = operation.kind === "checkIn" ? validateCheckInRequest(operation.request) : validateClaimRewardRequest(operation.request);
632
+ if (!result.success)
633
+ operationErrors.push(
634
+ ...result.errors.map((error) => ({ ...error, path: `${path}.request.${error.path}` }))
635
+ );
636
+ });
637
+ if (operationErrors.length > 0) return errors(...operationErrors);
638
+ }
601
639
  return {
602
640
  success: true,
603
641
  data: value
@@ -849,6 +887,7 @@ var StampRallyServer = class {
849
887
  state: await this.syncProgress(
850
888
  {
851
889
  rallyId: body.data.rallyId,
890
+ ...body.data.operations === void 0 ? {} : { operations: body.data.operations },
852
891
  ...sessionId === null ? {} : { anonymousSessionId: sessionId }
853
892
  },
854
893
  authContext
@@ -1189,6 +1228,10 @@ var StampRallyServer = class {
1189
1228
  async syncProgress(request, authContext) {
1190
1229
  const directRequest = withDirectIdentity(request, authContext);
1191
1230
  assertValidSyncParams(directRequest, this.#config);
1231
+ for (const operation of request.operations ?? []) {
1232
+ if (operation.kind === "checkIn") await this.checkIn(operation.request, authContext);
1233
+ else await this.claimReward(operation.request, authContext);
1234
+ }
1192
1235
  return this.sync(directRequest.rallyId, authContext);
1193
1236
  }
1194
1237
  async #attachInventory(state2) {