@open-mercato/shared 0.9.1-develop.7574.1.837288eec1 → 0.10.1-develop.7576.1.21d5b50435

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 (125) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/AGENTS.md +4 -4
  3. package/dist/lib/auth/server.js +1 -1
  4. package/dist/lib/auth/server.js.map +2 -2
  5. package/dist/lib/bootstrap/dynamicLoader.js +6 -46
  6. package/dist/lib/bootstrap/dynamicLoader.js.map +2 -2
  7. package/dist/lib/bootstrap/factory.js +3 -4
  8. package/dist/lib/bootstrap/factory.js.map +2 -2
  9. package/dist/lib/catalog-visibility/index.js +0 -4
  10. package/dist/lib/catalog-visibility/index.js.map +2 -2
  11. package/dist/lib/commands/command-bus.js +13 -45
  12. package/dist/lib/commands/command-bus.js.map +2 -2
  13. package/dist/lib/commands/types.js.map +2 -2
  14. package/dist/lib/crud/exporters.js +1 -1
  15. package/dist/lib/crud/exporters.js.map +2 -2
  16. package/dist/lib/crud/ids.js +1 -13
  17. package/dist/lib/crud/ids.js.map +2 -2
  18. package/dist/lib/db/pg-errors.js +0 -14
  19. package/dist/lib/db/pg-errors.js.map +2 -2
  20. package/dist/lib/localization/index.js +1 -9
  21. package/dist/lib/localization/index.js.map +2 -2
  22. package/dist/lib/localization/translatable-fields.js +0 -26
  23. package/dist/lib/localization/translatable-fields.js.map +2 -2
  24. package/dist/lib/number.js +0 -6
  25. package/dist/lib/number.js.map +2 -2
  26. package/dist/lib/openapi/generator.js +67 -84
  27. package/dist/lib/openapi/generator.js.map +2 -2
  28. package/dist/lib/query/engine.js +10 -45
  29. package/dist/lib/query/engine.js.map +2 -2
  30. package/dist/lib/query/join-utils.js +1 -1
  31. package/dist/lib/query/join-utils.js.map +2 -2
  32. package/dist/lib/query/types.js.map +2 -2
  33. package/dist/lib/url.js +0 -24
  34. package/dist/lib/url.js.map +2 -2
  35. package/dist/lib/version.js +1 -1
  36. package/dist/lib/version.js.map +1 -1
  37. package/dist/lib/webhooks/body.js +3 -7
  38. package/dist/lib/webhooks/body.js.map +2 -2
  39. package/dist/lib/webhooks/index.js +0 -2
  40. package/dist/lib/webhooks/index.js.map +2 -2
  41. package/dist/modules/integrations/types.js.map +2 -2
  42. package/dist/modules/notifications/types.js +0 -4
  43. package/dist/modules/notifications/types.js.map +3 -3
  44. package/dist/modules/payment_gateways/types.js +1 -14
  45. package/dist/modules/payment_gateways/types.js.map +2 -2
  46. package/dist/modules/registry.js.map +2 -2
  47. package/dist/modules/search.js.map +2 -2
  48. package/dist/modules/widgets/injection-loader.js +3 -14
  49. package/dist/modules/widgets/injection-loader.js.map +2 -2
  50. package/package.json +3 -10
  51. package/src/lib/__tests__/number.test.ts +1 -24
  52. package/src/lib/auth/__tests__/server.test.ts +0 -14
  53. package/src/lib/auth/server.ts +1 -1
  54. package/src/lib/bootstrap/__tests__/dynamicLoader.appDi.test.ts +2 -2
  55. package/src/lib/bootstrap/__tests__/dynamicLoader.appModuleOverrides.test.ts +2 -2
  56. package/src/lib/bootstrap/__tests__/dynamicLoader.cacheRecovery.test.ts +2 -2
  57. package/src/lib/bootstrap/__tests__/dynamicLoader.commandInterceptors.test.ts +2 -2
  58. package/src/lib/bootstrap/__tests__/dynamicLoader.tsconfig.test.ts +2 -2
  59. package/src/lib/bootstrap/__tests__/factory.test.ts +6 -18
  60. package/src/lib/bootstrap/dynamicLoader.ts +5 -63
  61. package/src/lib/bootstrap/factory.ts +3 -8
  62. package/src/lib/bootstrap/types.ts +1 -5
  63. package/src/lib/catalog-visibility/index.ts +0 -2
  64. package/src/lib/commands/__tests__/command-bus.test.ts +1 -100
  65. package/src/lib/commands/command-bus.ts +10 -42
  66. package/src/lib/commands/command-interceptor.ts +0 -4
  67. package/src/lib/commands/types.ts +0 -14
  68. package/src/lib/crud/__tests__/exporters.test.ts +0 -18
  69. package/src/lib/crud/__tests__/ids.test.ts +1 -34
  70. package/src/lib/crud/exporters.ts +1 -1
  71. package/src/lib/crud/ids.ts +0 -24
  72. package/src/lib/db/__tests__/pg-errors.test.ts +1 -68
  73. package/src/lib/db/pg-errors.ts +0 -35
  74. package/src/lib/encryption/__tests__/tenantDataEncryptionService.test.ts +0 -23
  75. package/src/lib/localization/__tests__/translatable-fields.test.ts +0 -17
  76. package/src/lib/localization/index.ts +1 -8
  77. package/src/lib/localization/translatable-fields.ts +0 -46
  78. package/src/lib/number.ts +0 -13
  79. package/src/lib/openapi/generator.ts +77 -106
  80. package/src/lib/query/engine.ts +8 -58
  81. package/src/lib/query/join-utils.ts +1 -1
  82. package/src/lib/query/types.ts +1 -13
  83. package/src/lib/url.ts +0 -30
  84. package/src/lib/webhooks/__tests__/body.test.ts +0 -48
  85. package/src/lib/webhooks/body.ts +4 -11
  86. package/src/lib/webhooks/index.ts +0 -1
  87. package/src/modules/integrations/types.ts +0 -6
  88. package/src/modules/notifications/types.ts +0 -7
  89. package/src/modules/payment_gateways/__tests__/types.test.ts +0 -44
  90. package/src/modules/payment_gateways/types.ts +6 -52
  91. package/src/modules/registry.ts +0 -5
  92. package/src/modules/search.ts +0 -39
  93. package/src/modules/widgets/injection-loader.ts +3 -33
  94. package/dist/lib/bootstrap/next-subpath-resolve-hook-worker.js +0 -6
  95. package/dist/lib/bootstrap/next-subpath-resolve-hook-worker.js.map +0 -7
  96. package/dist/lib/bootstrap/next-subpath-resolve-hook.js +0 -62
  97. package/dist/lib/bootstrap/next-subpath-resolve-hook.js.map +0 -7
  98. package/dist/lib/catalog-visibility/canonicalizeEffectiveScope.js +0 -33
  99. package/dist/lib/catalog-visibility/canonicalizeEffectiveScope.js.map +0 -7
  100. package/dist/lib/catalog-visibility/hashEffectiveScope.js +0 -9
  101. package/dist/lib/catalog-visibility/hashEffectiveScope.js.map +0 -7
  102. package/dist/lib/db/advisoryLock.js +0 -172
  103. package/dist/lib/db/advisoryLock.js.map +0 -7
  104. package/dist/lib/query/overlap.js +0 -58
  105. package/dist/lib/query/overlap.js.map +0 -7
  106. package/dist/modules/notifications/safeHref.js +0 -20
  107. package/dist/modules/notifications/safeHref.js.map +0 -7
  108. package/src/lib/__tests__/url.cross-site.test.ts +0 -140
  109. package/src/lib/bootstrap/__tests__/dynamicLoader.externalSubpath.test.ts +0 -141
  110. package/src/lib/bootstrap/__tests__/next-subpath-resolve-hook.test.ts +0 -174
  111. package/src/lib/bootstrap/next-subpath-resolve-hook-worker.ts +0 -3
  112. package/src/lib/bootstrap/next-subpath-resolve-hook.ts +0 -130
  113. package/src/lib/catalog-visibility/__tests__/hashEffectiveScope.test.ts +0 -121
  114. package/src/lib/catalog-visibility/canonicalizeEffectiveScope.ts +0 -41
  115. package/src/lib/catalog-visibility/hashEffectiveScope.ts +0 -8
  116. package/src/lib/db/__tests__/advisoryLock.integration.test.ts +0 -343
  117. package/src/lib/db/__tests__/advisoryLock.test.ts +0 -564
  118. package/src/lib/db/advisoryLock.ts +0 -271
  119. package/src/lib/openapi/__tests__/optional-path-params.test.ts +0 -102
  120. package/src/lib/query/__tests__/empty-ids-filter.pg.test.ts +0 -89
  121. package/src/lib/query/__tests__/engine.empty-in-filter.test.ts +0 -79
  122. package/src/lib/query/__tests__/overlap.test.ts +0 -219
  123. package/src/lib/query/overlap.ts +0 -106
  124. package/src/modules/notifications/safeHref.ts +0 -19
  125. package/src/modules/widgets/__tests__/injection-loader.partitioned-registration.test.ts +0 -78
@@ -59,19 +59,6 @@ function normalizePath(path) {
59
59
  }).join("/");
60
60
  return { path: "/" + normalized, params };
61
61
  }
62
- function expandOptionalPathParams(normalized) {
63
- const required = normalized.params.filter((param) => !param.optional);
64
- const optionalParam = normalized.params.find((param) => param.optional);
65
- const fullVariant = {
66
- path: normalized.path,
67
- params: normalized.params.map((param) => ({ ...param, optional: false }))
68
- };
69
- if (!optionalParam) return [fullVariant];
70
- const placeholder = `/{${optionalParam.name}}`;
71
- if (!normalized.path.endsWith(placeholder)) return [fullVariant];
72
- const basePath = normalized.path.slice(0, -placeholder.length) || "/";
73
- return [fullVariant, { path: basePath, params: required, omittedParam: optionalParam.name }];
74
- }
75
62
  function unwrap(schema) {
76
63
  if (!schema) {
77
64
  return { schema: void 0, optional: true, nullable: false };
@@ -577,14 +564,14 @@ function buildParameters(schema, location, pathParamNames) {
577
564
  const params = [];
578
565
  if (location === "path" && pathParamNames && pathParamNames.length) {
579
566
  const merged = mergePathParamSchemas(schema, pathParamNames);
580
- for (const { name, schema: paramSchema } of merged) {
567
+ for (const { name, schema: paramSchema, optional } of merged) {
581
568
  const jsonSchema = zodToJsonSchema(paramSchema);
582
569
  const example = generateExample(paramSchema);
583
570
  const description = extractZodDescription(paramSchema);
584
571
  params.push({
585
572
  name,
586
573
  in: "path",
587
- required: true,
574
+ required: !optional,
588
575
  schema: jsonSchema ?? { type: "string" },
589
576
  example,
590
577
  ...description ? { description } : {}
@@ -644,7 +631,8 @@ function mergePathParamSchemas(schema, params) {
644
631
  for (const param of params) {
645
632
  merged.push({
646
633
  name: param.name,
647
- schema: map[param.name]
634
+ schema: map[param.name],
635
+ optional: !!param.optional
648
636
  });
649
637
  }
650
638
  return merged;
@@ -895,7 +883,6 @@ function buildOpenApiDocument(modules, options = {}) {
895
883
  ensureSecurityComponents(doc);
896
884
  const includeAccessControlMetadata = options.includeAccessControlMetadata !== false;
897
885
  const tags = /* @__PURE__ */ new Map();
898
- const derivedOperations = /* @__PURE__ */ new Set();
899
886
  for (const moduleEntry of modules) {
900
887
  const defaultTag = moduleEntry.info?.title ?? toTitle(moduleEntry.id);
901
888
  if (defaultTag) tags.set(defaultTag, moduleEntry.info?.description);
@@ -903,75 +890,71 @@ function buildOpenApiDocument(modules, options = {}) {
903
890
  for (const api of apis) {
904
891
  const routeDoc = collectRouteDoc(api, moduleEntry.id);
905
892
  const moduleTag = routeDoc?.tag ?? defaultTag;
893
+ const normalized = normalizePath(api.path ?? api.path ?? "");
894
+ const pathKey = normalized.path;
895
+ if (!doc.paths[pathKey]) doc.paths[pathKey] = {};
906
896
  const availableMethods = "handlers" in api ? HTTP_METHODS.filter((method) => typeof api.handlers?.[method] === "function") : [api.method];
907
- for (const normalized of expandOptionalPathParams(normalizePath(api.path ?? ""))) {
908
- const pathKey = normalized.path;
909
- if (!doc.paths[pathKey]) doc.paths[pathKey] = {};
910
- for (const method of availableMethods) {
911
- const methodLower = method.toLowerCase();
912
- const operationKey = `${methodLower} ${pathKey}`;
913
- const existing = doc.paths[pathKey][methodLower];
914
- if (existing && (normalized.omittedParam || !derivedOperations.has(operationKey))) continue;
915
- if (normalized.omittedParam) derivedOperations.add(operationKey);
916
- else derivedOperations.delete(operationKey);
917
- const metadata = "handlers" in api ? api.metadata?.[method] : void 0;
918
- const methodDoc = routeDoc?.methods?.[method];
919
- const summary = methodDoc?.summary ?? routeDoc?.summary ?? `${method} ${pathKey}`;
920
- const baseDescription = methodDoc?.description ?? routeDoc?.description;
921
- const meta = metadata && typeof metadata === "object" ? metadata : void 0;
922
- const requireFeatures = Array.isArray(meta?.["requireFeatures"]) ? meta["requireFeatures"] : void 0;
923
- const requireRoles = Array.isArray(meta?.["requireRoles"]) ? meta["requireRoles"] : void 0;
924
- const requireAuth = meta?.["requireAuth"] === true;
925
- const descriptionParts = [];
926
- if (baseDescription) descriptionParts.push(baseDescription);
927
- if (includeAccessControlMetadata && Array.isArray(requireFeatures) && requireFeatures.length) {
928
- descriptionParts.push(`Requires features: ${requireFeatures.join(", ")}`);
929
- }
930
- if (includeAccessControlMetadata && Array.isArray(requireRoles) && requireRoles.length) {
931
- descriptionParts.push(`Requires roles: ${requireRoles.join(", ")}`);
932
- }
933
- const querySchema = methodDoc?.query;
934
- const pathSchema = methodDoc?.pathParams ?? routeDoc?.pathParams;
935
- const headerSchema = methodDoc?.headers;
936
- const requestBody = methodDoc?.requestBody;
937
- const examples = collectExamples(querySchema, requestBody?.schema, pathSchema, headerSchema, metadata);
938
- const curlSample = buildCurlSample(
939
- method,
940
- pathKey,
941
- normalized.params,
942
- examples,
943
- options.baseUrlForExamples ?? "https://api.open-mercato.local",
944
- metadata,
945
- requestBody
946
- );
947
- doc.paths[pathKey][methodLower] = {
948
- operationId: methodDoc?.operationId ? normalized.omittedParam ? `${methodDoc.operationId}_without_${normalizeOperationIdSegment(normalized.omittedParam)}` : methodDoc.operationId : resolveOperationId(moduleEntry.id, pathKey, method),
949
- summary,
950
- description: descriptionParts.length ? descriptionParts.join("\n\n") : void 0,
951
- tags: methodDoc?.tags ?? (moduleTag ? [moduleTag] : void 0),
952
- deprecated: methodDoc?.deprecated,
953
- externalDocs: methodDoc?.externalDocs,
954
- parameters: [
955
- ...buildParameters(pathSchema, "path", normalized.params),
956
- ...buildParameters(querySchema, "query"),
957
- ...buildParameters(headerSchema, "header")
958
- ].filter(Boolean),
959
- requestBody: buildRequestBody(requestBody),
960
- responses: buildResponses(method, methodDoc?.responses, methodDoc?.errors, metadata),
961
- security: buildSecurity(metadata, methodDoc, options.defaultSecurity),
962
- "x-codeSamples": methodDoc?.codeSamples ?? [
963
- {
964
- lang: "curl",
965
- label: "cURL",
966
- source: curlSample
967
- }
968
- ],
969
- ...includeAccessControlMetadata && Array.isArray(requireFeatures) && requireFeatures.length ? { "x-require-features": requireFeatures } : {},
970
- ...includeAccessControlMetadata && Array.isArray(requireRoles) && requireRoles.length ? { "x-require-roles": requireRoles } : {},
971
- ...requireAuth ? { "x-require-auth": true } : {},
972
- ...methodDoc?.extensions ?? {}
973
- };
897
+ for (const method of availableMethods) {
898
+ const methodLower = method.toLowerCase();
899
+ const existing = doc.paths[pathKey][methodLower];
900
+ if (existing) continue;
901
+ const metadata = "handlers" in api ? api.metadata?.[method] : void 0;
902
+ const methodDoc = routeDoc?.methods?.[method];
903
+ const summary = methodDoc?.summary ?? routeDoc?.summary ?? `${method} ${pathKey}`;
904
+ const baseDescription = methodDoc?.description ?? routeDoc?.description;
905
+ const meta = metadata && typeof metadata === "object" ? metadata : void 0;
906
+ const requireFeatures = Array.isArray(meta?.["requireFeatures"]) ? meta["requireFeatures"] : void 0;
907
+ const requireRoles = Array.isArray(meta?.["requireRoles"]) ? meta["requireRoles"] : void 0;
908
+ const requireAuth = meta?.["requireAuth"] === true;
909
+ const descriptionParts = [];
910
+ if (baseDescription) descriptionParts.push(baseDescription);
911
+ if (includeAccessControlMetadata && Array.isArray(requireFeatures) && requireFeatures.length) {
912
+ descriptionParts.push(`Requires features: ${requireFeatures.join(", ")}`);
913
+ }
914
+ if (includeAccessControlMetadata && Array.isArray(requireRoles) && requireRoles.length) {
915
+ descriptionParts.push(`Requires roles: ${requireRoles.join(", ")}`);
974
916
  }
917
+ const querySchema = methodDoc?.query;
918
+ const pathSchema = methodDoc?.pathParams ?? routeDoc?.pathParams;
919
+ const headerSchema = methodDoc?.headers;
920
+ const requestBody = methodDoc?.requestBody;
921
+ const examples = collectExamples(querySchema, requestBody?.schema, pathSchema, headerSchema, metadata);
922
+ const curlSample = buildCurlSample(
923
+ method,
924
+ pathKey,
925
+ normalized.params,
926
+ examples,
927
+ options.baseUrlForExamples ?? "https://api.open-mercato.local",
928
+ metadata,
929
+ requestBody
930
+ );
931
+ doc.paths[pathKey][methodLower] = {
932
+ operationId: methodDoc?.operationId ?? resolveOperationId(moduleEntry.id, pathKey, method),
933
+ summary,
934
+ description: descriptionParts.length ? descriptionParts.join("\n\n") : void 0,
935
+ tags: methodDoc?.tags ?? (moduleTag ? [moduleTag] : void 0),
936
+ deprecated: methodDoc?.deprecated,
937
+ externalDocs: methodDoc?.externalDocs,
938
+ parameters: [
939
+ ...buildParameters(pathSchema, "path", normalized.params),
940
+ ...buildParameters(querySchema, "query"),
941
+ ...buildParameters(headerSchema, "header")
942
+ ].filter(Boolean),
943
+ requestBody: buildRequestBody(requestBody),
944
+ responses: buildResponses(method, methodDoc?.responses, methodDoc?.errors, metadata),
945
+ security: buildSecurity(metadata, methodDoc, options.defaultSecurity),
946
+ "x-codeSamples": methodDoc?.codeSamples ?? [
947
+ {
948
+ lang: "curl",
949
+ label: "cURL",
950
+ source: curlSample
951
+ }
952
+ ],
953
+ ...includeAccessControlMetadata && Array.isArray(requireFeatures) && requireFeatures.length ? { "x-require-features": requireFeatures } : {},
954
+ ...includeAccessControlMetadata && Array.isArray(requireRoles) && requireRoles.length ? { "x-require-roles": requireRoles } : {},
955
+ ...requireAuth ? { "x-require-auth": true } : {},
956
+ ...methodDoc?.extensions ?? {}
957
+ };
975
958
  }
976
959
  }
977
960
  }