@getstrata/core 0.5.52 → 0.5.54

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 (32) hide show
  1. package/README.md +6 -3
  2. package/dist/core/queue/failedJobRepository.d.ts +1 -1
  3. package/dist/core/queue/failedJobTable.d.ts +1 -1
  4. package/dist/entries/auth/accessControl.js +60 -1
  5. package/dist/entries/auth/membershipMiddleware.js +21 -0
  6. package/dist/entries/auth/membershipScope.js +336 -1
  7. package/dist/entries/auth/membershipService.js +304 -1
  8. package/dist/entries/auth/policy.js +81 -1
  9. package/dist/entries/auth/sessionGuard.js +8 -7
  10. package/dist/entries/database/repositoryQuery.js +655 -0
  11. package/dist/entries/database/whereBuilder.js +32 -0
  12. package/dist/entries/http/formRequest.js +102 -0
  13. package/dist/entries/http/pagination.js +102 -0
  14. package/dist/entries/http/routeModelBinding.js +102 -0
  15. package/dist/entries/http/securedRouteModelBinding.js +102 -0
  16. package/dist/entries/http/validation.js +145 -0
  17. package/dist/entries/http/webErrorResponse.js +8 -7
  18. package/dist/entries/http/webFormRequest.js +102 -0
  19. package/dist/entries/queue/createAppQueue.js +2 -2
  20. package/dist/entries/queue/failedJobRepository.js +2 -2
  21. package/dist/entries/queue/publicQueue.js +2 -2
  22. package/dist/entries/queue/queueMetrics.js +2 -2
  23. package/dist/entries/view.js +8 -7
  24. package/dist/index.js +2215 -2213
  25. package/dist/modules/user/apiTokenRepository.d.ts +1 -1
  26. package/dist/modules/user/apiTokenTable.d.ts +1 -1
  27. package/dist/modules/user/notificationRepository.d.ts +1 -1
  28. package/dist/modules/user/notificationTable.d.ts +1 -1
  29. package/dist/modules/user/oauthIdentityRepository.d.ts +2 -2
  30. package/dist/modules/user/repository.d.ts +1 -1
  31. package/dist/modules/user/table.d.ts +1 -1
  32. package/package.json +17 -2
@@ -48,12 +48,65 @@ function formDataToRecord(formData) {
48
48
  import { currentAuthUser } from "@getstrata/core/auth/authContext";
49
49
  import { BadRequestError as BadRequestError2 } from "@getstrata/core/errors/http";
50
50
  import { currentTenantId } from "@getstrata/core/tenant/tenantContext";
51
+ function buildRequestCacheKey(fallbackPath, request) {
52
+ if (!request) {
53
+ return fallbackPath;
54
+ }
55
+ const url = new URL(request.url);
56
+ const user = currentAuthUser();
57
+ const authScope = user ? `u:${user.id}` : "guest";
58
+ const tenantScope = `t:${currentTenantId()}`;
59
+ return `${authScope}|${tenantScope}|${url.pathname}${url.search}`;
60
+ }
51
61
  function getQueryParams(request) {
52
62
  if (!request) {
53
63
  return new URLSearchParams;
54
64
  }
55
65
  return new URL(request.url).searchParams;
56
66
  }
67
+ function parseOptionalPositiveIntQueryParam(params, name) {
68
+ const value = params.get(name);
69
+ if (value === null || value.trim() === "") {
70
+ return;
71
+ }
72
+ const parsed = Number.parseInt(value, 10);
73
+ if (!Number.isInteger(parsed) || parsed <= 0) {
74
+ throw new BadRequestError2(`Invalid query parameter "${name}". Expected a positive integer.`);
75
+ }
76
+ return parsed;
77
+ }
78
+ function parseOptionalBooleanQueryParam(params, name) {
79
+ const value = params.get(name);
80
+ if (value === null || value.trim() === "") {
81
+ return;
82
+ }
83
+ switch (value.toLowerCase()) {
84
+ case "true":
85
+ case "1":
86
+ return true;
87
+ case "false":
88
+ case "0":
89
+ return false;
90
+ default:
91
+ throw new BadRequestError2(`Invalid query parameter "${name}". Expected a boolean.`);
92
+ }
93
+ }
94
+ function parseOptionalEnumQueryParam(params, name, allowedValues) {
95
+ const value = params.get(name);
96
+ if (value === null || value.trim() === "") {
97
+ return;
98
+ }
99
+ if (!allowedValues.includes(value)) {
100
+ throw new BadRequestError2(`Invalid query parameter "${name}". Expected one of: ${allowedValues.join(", ")}.`);
101
+ }
102
+ return value;
103
+ }
104
+ function expectObject(value, label = "request body") {
105
+ if (value === null || typeof value !== "object" || Array.isArray(value)) {
106
+ throw new BadRequestError2(`${label} must be a JSON object.`);
107
+ }
108
+ return value;
109
+ }
57
110
  async function parseJsonBody(request, validator) {
58
111
  let payload;
59
112
  try {
@@ -63,6 +116,55 @@ async function parseJsonBody(request, validator) {
63
116
  }
64
117
  return validator(payload);
65
118
  }
119
+ function readRequiredString(payload, field, options = {}) {
120
+ const value = payload[field];
121
+ if (typeof value !== "string" || value.trim() === "") {
122
+ throw new BadRequestError2(`"${field}" is required and must be a string.`);
123
+ }
124
+ const trimmed = value.trim();
125
+ if (options.minLength !== undefined && trimmed.length < options.minLength) {
126
+ throw new BadRequestError2(`"${field}" must be at least ${options.minLength} characters.`);
127
+ }
128
+ if (options.maxLength !== undefined && trimmed.length > options.maxLength) {
129
+ throw new BadRequestError2(`"${field}" must be at most ${options.maxLength} characters.`);
130
+ }
131
+ if (options.pattern && !options.pattern.test(trimmed)) {
132
+ throw new BadRequestError2(`"${field}" has an invalid format.`);
133
+ }
134
+ return trimmed;
135
+ }
136
+ function readOptionalString(payload, field, options = {}) {
137
+ if (!(field in payload) || payload[field] === undefined) {
138
+ return;
139
+ }
140
+ return readRequiredString(payload, field, options);
141
+ }
142
+ function readRequiredEnum(payload, field, allowedValues) {
143
+ const value = readRequiredString(payload, field);
144
+ if (!allowedValues.includes(value)) {
145
+ throw new BadRequestError2(`"${field}" must be one of: ${allowedValues.join(", ")}.`);
146
+ }
147
+ return value;
148
+ }
149
+ function readOptionalEnum(payload, field, allowedValues) {
150
+ if (!(field in payload) || payload[field] === undefined) {
151
+ return;
152
+ }
153
+ return readRequiredEnum(payload, field, allowedValues);
154
+ }
155
+ function readRequiredPositiveInt(payload, field) {
156
+ const value = payload[field];
157
+ if (typeof value !== "number" || !Number.isInteger(value) || value <= 0) {
158
+ throw new BadRequestError2(`"${field}" is required and must be a positive integer.`);
159
+ }
160
+ return value;
161
+ }
162
+ function readOptionalPositiveInt(payload, field) {
163
+ if (!(field in payload) || payload[field] === undefined) {
164
+ return;
165
+ }
166
+ return readRequiredPositiveInt(payload, field);
167
+ }
66
168
  function parsePositiveIntParam(value, name = "id") {
67
169
  const parsed = Number.parseInt(value, 10);
68
170
  if (!Number.isInteger(parsed) || parsed <= 0) {
@@ -1,9 +1,9 @@
1
1
  // @bun
2
2
  // ../../src/core/queue/failedJobRepository.ts
3
- import { BaseRepository } from "@getstrata/core/database";
3
+ import { BaseRepository } from "@getstrata/core/database/baseRepository";
4
4
 
5
5
  // ../../src/core/queue/failedJobTable.ts
6
- import { defineTable } from "@getstrata/core/database";
6
+ import { defineTable } from "@getstrata/core/database/table";
7
7
  var failedJobTable = defineTable({
8
8
  name: "failed_job",
9
9
  primaryKey: "id",
@@ -1,9 +1,9 @@
1
1
  // @bun
2
2
  // ../../src/core/queue/failedJobRepository.ts
3
- import { BaseRepository } from "@getstrata/core/database";
3
+ import { BaseRepository } from "@getstrata/core/database/baseRepository";
4
4
 
5
5
  // ../../src/core/queue/failedJobTable.ts
6
- import { defineTable } from "@getstrata/core/database";
6
+ import { defineTable } from "@getstrata/core/database/table";
7
7
  var failedJobTable = defineTable({
8
8
  name: "failed_job",
9
9
  primaryKey: "id",
@@ -1,9 +1,9 @@
1
1
  // @bun
2
2
  // ../../src/core/queue/failedJobRepository.ts
3
- import { BaseRepository } from "@getstrata/core/database";
3
+ import { BaseRepository } from "@getstrata/core/database/baseRepository";
4
4
 
5
5
  // ../../src/core/queue/failedJobTable.ts
6
- import { defineTable } from "@getstrata/core/database";
6
+ import { defineTable } from "@getstrata/core/database/table";
7
7
  var failedJobTable = defineTable({
8
8
  name: "failed_job",
9
9
  primaryKey: "id",
@@ -22,10 +22,10 @@ var queueConfig = {
22
22
  };
23
23
 
24
24
  // ../../src/core/queue/failedJobRepository.ts
25
- import { BaseRepository } from "@getstrata/core/database";
25
+ import { BaseRepository } from "@getstrata/core/database/baseRepository";
26
26
 
27
27
  // ../../src/core/queue/failedJobTable.ts
28
- import { defineTable } from "@getstrata/core/database";
28
+ import { defineTable } from "@getstrata/core/database/table";
29
29
  var failedJobTable = defineTable({
30
30
  name: "failed_job",
31
31
  primaryKey: "id",
@@ -87,7 +87,7 @@ function isFeatureEnabled(feature) {
87
87
  }
88
88
 
89
89
  // ../../src/modules/user/apiTokenRepository.ts
90
- import { BaseRepository } from "@getstrata/core/database";
90
+ import { BaseRepository } from "@getstrata/core/database/baseRepository";
91
91
 
92
92
  // ../../src/config/database.ts
93
93
  function readInteger(name, fallback) {
@@ -213,7 +213,7 @@ var db = new Proxy(function database() {}, {
213
213
  var connection_default = db;
214
214
 
215
215
  // ../../src/modules/user/apiTokenTable.ts
216
- import { defineTable } from "@getstrata/core/database";
216
+ import { defineTable } from "@getstrata/core/database/table";
217
217
  var apiTokenTable = defineTable({
218
218
  name: "api_token",
219
219
  primaryKey: "id",
@@ -371,10 +371,10 @@ class AuthService {
371
371
  }
372
372
 
373
373
  // ../../src/modules/user/notificationRepository.ts
374
- import { BaseRepository as BaseRepository2 } from "@getstrata/core/database";
374
+ import { BaseRepository as BaseRepository2 } from "@getstrata/core/database/baseRepository";
375
375
 
376
376
  // ../../src/modules/user/notificationTable.ts
377
- import { defineTable as defineTable2 } from "@getstrata/core/database";
377
+ import { defineTable as defineTable2 } from "@getstrata/core/database/table";
378
378
  var notificationTable = defineTable2({
379
379
  name: "notification",
380
380
  primaryKey: "id",
@@ -386,7 +386,8 @@ var notificationTable = defineTable2({
386
386
  import { NotFoundError } from "@getstrata/core/errors/http";
387
387
 
388
388
  // ../../src/modules/user/oauthIdentityRepository.ts
389
- import { BaseRepository as BaseRepository3, defineTable as defineTable3 } from "@getstrata/core/database";
389
+ import { BaseRepository as BaseRepository3 } from "@getstrata/core/database/baseRepository";
390
+ import { defineTable as defineTable3 } from "@getstrata/core/database/table";
390
391
  var oauthIdentityTable = defineTable3({
391
392
  name: "oauth_identity",
392
393
  primaryKey: "id",
@@ -400,11 +401,11 @@ import {
400
401
  revealEmail
401
402
  } from "@getstrata/core/crypto/fieldEncryption";
402
403
  import { revealMfaSecret as revealMfaSecret2 } from "@getstrata/core/crypto/mfaSecret";
403
- import { BaseRepository as BaseRepository4 } from "@getstrata/core/database";
404
+ import { BaseRepository as BaseRepository4 } from "@getstrata/core/database/baseRepository";
404
405
  import { currentTenantId as currentTenantId2 } from "@getstrata/core/tenant/tenantContext";
405
406
 
406
407
  // ../../src/modules/user/table.ts
407
- import { defineTable as defineTable4 } from "@getstrata/core/database";
408
+ import { defineTable as defineTable4 } from "@getstrata/core/database/table";
408
409
  var userTable = defineTable4({
409
410
  name: "users",
410
411
  primaryKey: "id",