@shophost/rest-api 2.0.33 → 2.0.35

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 (148) hide show
  1. package/package.json +1 -1
  2. package/scripts/minify-dist.mjs +45 -0
  3. package/src/app.js +1 -53
  4. package/src/core/auth/auth.schema.js +1 -41
  5. package/src/core/auth/auth.util.js +1 -44
  6. package/src/core/auth/better-auth.lib.js +1 -100
  7. package/src/core/auth/generate-password-hash.util.js +1 -30
  8. package/src/core/auth/headers.schema.js +1 -22
  9. package/src/core/auth/user.schema.js +1 -30
  10. package/src/core/db/__generated__/client/browser.js +1 -18
  11. package/src/core/db/__generated__/client/client.js +1 -35
  12. package/src/core/db/__generated__/client/commonInputTypes.js +1 -11
  13. package/src/core/db/__generated__/client/enums.js +1 -200
  14. package/src/core/db/__generated__/client/internal/class.js +769 -55
  15. package/src/core/db/__generated__/client/internal/prismaNamespace.js +1 -541
  16. package/src/core/db/__generated__/client/internal/prismaNamespaceBrowser.js +1 -512
  17. package/src/core/db/__generated__/client/models/Account.js +1 -2
  18. package/src/core/db/__generated__/client/models/Address.js +1 -2
  19. package/src/core/db/__generated__/client/models/Campaign.js +1 -2
  20. package/src/core/db/__generated__/client/models/ClosingTimes.js +1 -2
  21. package/src/core/db/__generated__/client/models/File.js +1 -2
  22. package/src/core/db/__generated__/client/models/Invitation.js +1 -2
  23. package/src/core/db/__generated__/client/models/LegalEntity.js +1 -2
  24. package/src/core/db/__generated__/client/models/Manufacturer.js +1 -2
  25. package/src/core/db/__generated__/client/models/ManufacturerTranslation.js +1 -2
  26. package/src/core/db/__generated__/client/models/Member.js +1 -2
  27. package/src/core/db/__generated__/client/models/Modifier.js +1 -2
  28. package/src/core/db/__generated__/client/models/ModifierGroup.js +1 -2
  29. package/src/core/db/__generated__/client/models/ModifierGroupTranslation.js +1 -2
  30. package/src/core/db/__generated__/client/models/OpeningTimes.js +1 -2
  31. package/src/core/db/__generated__/client/models/Order.js +1 -2
  32. package/src/core/db/__generated__/client/models/OrderItem.js +1 -2
  33. package/src/core/db/__generated__/client/models/OrderItemTranslation.js +1 -2
  34. package/src/core/db/__generated__/client/models/Organization.js +1 -2
  35. package/src/core/db/__generated__/client/models/OrganizationConfiguration.js +1 -2
  36. package/src/core/db/__generated__/client/models/Payment.js +1 -2
  37. package/src/core/db/__generated__/client/models/PaymentSession.js +1 -2
  38. package/src/core/db/__generated__/client/models/Product.js +1 -2
  39. package/src/core/db/__generated__/client/models/ProductCategory.js +1 -2
  40. package/src/core/db/__generated__/client/models/ProductCategoryTranslation.js +1 -2
  41. package/src/core/db/__generated__/client/models/ProductSnapshot.js +1 -2
  42. package/src/core/db/__generated__/client/models/ProductTranslation.js +1 -2
  43. package/src/core/db/__generated__/client/models/Reservation.js +1 -2
  44. package/src/core/db/__generated__/client/models/Session.js +1 -2
  45. package/src/core/db/__generated__/client/models/ShippingMethod.js +1 -2
  46. package/src/core/db/__generated__/client/models/ShippingZone.js +1 -2
  47. package/src/core/db/__generated__/client/models/User.js +1 -2
  48. package/src/core/db/__generated__/client/models/Verification.js +1 -2
  49. package/src/core/db/__generated__/client/models.js +1 -2
  50. package/src/core/db/index.js +1 -2
  51. package/src/core/exceptions/http-exception.js +1 -9
  52. package/src/core/hono/hono.js +1 -123
  53. package/src/core/lib/prisma.js +1 -11
  54. package/src/core/logging/pino.js +1 -5
  55. package/src/core/notifications/email.service.js +1 -116
  56. package/src/core/openapi/openapi.lib.js +1 -26
  57. package/src/core/types/google-maps.types.js +1 -2
  58. package/src/core/utils/currency.util.js +1 -11
  59. package/src/core/utils/env.util.js +1 -8
  60. package/src/core/utils/object.util.js +1 -39
  61. package/src/core/utils/translations.util.js +0 -1
  62. package/src/core/utils/zod.util.js +1 -85
  63. package/src/db.js +1 -3
  64. package/src/features/access/access.handler.js +1 -91
  65. package/src/features/access/access.route.js +1 -220
  66. package/src/features/access/access.schema.js +1 -108
  67. package/src/features/access/access.service.js +1 -294
  68. package/src/features/cart/cart.handler.js +1 -17
  69. package/src/features/cart/cart.route.js +1 -32
  70. package/src/features/cart/cart.schema.js +1 -39
  71. package/src/features/cart/cart.service.js +1 -97
  72. package/src/features/cart/cart.util.js +1 -76
  73. package/src/features/file/file.handler.js +1 -23
  74. package/src/features/file/file.route.js +1 -34
  75. package/src/features/file/file.schema.js +1 -77
  76. package/src/features/file/file.service.js +1 -66
  77. package/src/features/health/health.handler.js +1 -10
  78. package/src/features/health/health.route.js +1 -25
  79. package/src/features/index.js +1 -16
  80. package/src/features/location/location.handler.js +1 -25
  81. package/src/features/location/location.route.js +1 -56
  82. package/src/features/location/location.schema.js +1 -50
  83. package/src/features/location/location.service.js +1 -141
  84. package/src/features/manufacturer/manufacturer.handler.js +1 -53
  85. package/src/features/manufacturer/manufacturer.route.js +1 -97
  86. package/src/features/manufacturer/manufacturer.schema.js +1 -125
  87. package/src/features/manufacturer/manufacturer.service.js +1 -190
  88. package/src/features/order/emails/order-confirmation.email.js +1 -229
  89. package/src/features/order/emails/order-notification.email.js +1 -229
  90. package/src/features/order/fulfilment.schema.js +1 -3
  91. package/src/features/order/order.handler.js +1 -54
  92. package/src/features/order/order.route.js +1 -111
  93. package/src/features/order/order.schema.js +1 -158
  94. package/src/features/order/order.service.js +1 -306
  95. package/src/features/order/recipient.schema.js +1 -38
  96. package/src/features/organization/legal-entity.schema.js +1 -83
  97. package/src/features/organization/organization-configuration.schema.js +1 -115
  98. package/src/features/organization/organization.handler.js +1 -48
  99. package/src/features/organization/organization.route.js +1 -84
  100. package/src/features/organization/organization.schema.js +1 -64
  101. package/src/features/organization/organization.service.js +1 -334
  102. package/src/features/payment/payment.handler.js +1 -16
  103. package/src/features/payment/payment.route.js +1 -22
  104. package/src/features/payment/payment.schema.js +1 -46
  105. package/src/features/payment/payment.service.js +1 -100
  106. package/src/features/payment/stripe.service.js +1 -164
  107. package/src/features/product/product-modifier.schema.js +1 -84
  108. package/src/features/product/product.handler.js +1 -87
  109. package/src/features/product/product.route.js +1 -179
  110. package/src/features/product/product.schema.js +1 -143
  111. package/src/features/product/product.service.js +1 -440
  112. package/src/features/product-category/product-category.handler.js +1 -59
  113. package/src/features/product-category/product-category.route.js +1 -139
  114. package/src/features/product-category/product-category.schema.js +1 -86
  115. package/src/features/product-category/product-category.service.js +1 -220
  116. package/src/features/reservation/emails/reservation-cancellation.email.js +1 -82
  117. package/src/features/reservation/emails/reservation-confirmation.email.js +1 -82
  118. package/src/features/reservation/emails/reservation-notification.email.js +1 -93
  119. package/src/features/reservation/reservation.handler.js +1 -65
  120. package/src/features/reservation/reservation.route.js +1 -167
  121. package/src/features/reservation/reservation.schema.js +1 -51
  122. package/src/features/reservation/reservation.service.js +1 -231
  123. package/src/features/shipping/shipping.handler.js +1 -32
  124. package/src/features/shipping/shipping.route.js +1 -51
  125. package/src/features/shipping/shipping.service.js +1 -96
  126. package/src/features/shipping-method/shipping-method.handler.js +1 -60
  127. package/src/features/shipping-method/shipping-method.route.js +1 -144
  128. package/src/features/shipping-method/shipping-method.schema.js +1 -48
  129. package/src/features/shipping-method/shipping-method.service.js +1 -229
  130. package/src/features/shipping-method/shipping-zone.schema.js +1 -31
  131. package/src/features/webhook/webhook.handler.js +1 -50
  132. package/src/features/webhook/webhook.route.js +1 -33
  133. package/src/index.js +1 -6
  134. package/src/integrations/next.js +1 -82
  135. package/src/schemas/address.schema.js +1 -112
  136. package/src/schemas/currency.schema.js +1 -118
  137. package/src/schemas/error.schema.js +1 -12
  138. package/src/schemas/index.js +1 -29
  139. package/src/schemas/locales.schema.js +1 -238
  140. package/src/schemas/number.schema.js +1 -29
  141. package/src/schemas/pagination.schema.js +1 -54
  142. package/src/schemas/params.schema.js +1 -20
  143. package/src/schemas/queries.schema.js +1 -6
  144. package/src/test/global-setup.js +1 -37
  145. package/src/test/integration/api-fixtures.js +1 -160
  146. package/src/test/integration/seed.js +1 -368
  147. package/src/test/integration/test-helpers.js +1 -154
  148. package/src/test/setup-test-env.js +1 -7
@@ -1,154 +1 @@
1
- import { __awaiter } from "tslib";
2
- import { randomUUID } from "node:crypto";
3
- import { PrismaPg } from "@prisma/adapter-pg";
4
- import { buildApiApp } from "../../app";
5
- import { HttpException } from "../../core/exceptions/http-exception";
6
- import { createPrismaClient, } from "../../core/lib/prisma";
7
- import { SEED, resetToSeed as resetToSeedImpl } from "./seed";
8
- export { SEED } from "./seed";
9
- const TEST_DATABASE_URL = "postgresql://shophost:shophost@localhost:5555/shophost_test";
10
- const GOOGLE_MAPS_TEST_KEY = "test-google-maps-key";
11
- // ── Prisma (internal, never exposed to test files) ──
12
- let _prisma = null;
13
- const getTestPrisma = () => {
14
- if (!_prisma) {
15
- _prisma = createPrismaClient({
16
- adapter: new PrismaPg({ connectionString: TEST_DATABASE_URL }),
17
- log: ["warn", "error"],
18
- });
19
- }
20
- return _prisma;
21
- };
22
- // ── Reset ──
23
- export const resetToSeed = () => resetToSeedImpl(getTestPrisma());
24
- // ── Auth app ──
25
- const getOrganizationIdFromPath = (path) => {
26
- var _a, _b;
27
- const segments = path.split("/").filter(Boolean);
28
- if (segments[0] === "organizations") {
29
- return (_a = segments[1]) !== null && _a !== void 0 ? _a : "";
30
- }
31
- return (_b = segments[0]) !== null && _b !== void 0 ? _b : "";
32
- };
33
- const toUser = (seed) => ({
34
- id: seed.id,
35
- email: seed.email,
36
- firstname: seed.firstname,
37
- lastname: seed.lastname,
38
- name: seed.name,
39
- image: seed.image,
40
- });
41
- export const createTestApp = (user = SEED.users.owner, options = {}) => {
42
- const prisma = getTestPrisma();
43
- const authUser = toUser(user);
44
- return buildApiApp(Object.assign(Object.assign({}, options), { maps: Object.assign({ google: { key: GOOGLE_MAPS_TEST_KEY } }, options.maps), prisma, resolveAuth: (_request, path) => ({
45
- getCurrentUser: () => __awaiter(void 0, void 0, void 0, function* () { return authUser; }),
46
- isGranted: () => __awaiter(void 0, void 0, void 0, function* () {
47
- const organizationId = getOrganizationIdFromPath(path);
48
- if (!organizationId) {
49
- return authUser;
50
- }
51
- const membership = yield prisma.member.findFirst({
52
- where: { organizationId, userId: authUser.id },
53
- });
54
- if (!membership) {
55
- throw new HttpException(403, "Forbidden");
56
- }
57
- return authUser;
58
- }),
59
- }) }));
60
- };
61
- // ── Context factories ──
62
- export const primaryContext = (options) => ({
63
- app: createTestApp(SEED.users.owner, options),
64
- user: SEED.users.owner,
65
- org: SEED.organizations.primary,
66
- catalog: SEED.catalog.primary,
67
- shipping: SEED.shipping.primary,
68
- });
69
- export const secondaryContext = (options) => ({
70
- app: createTestApp(SEED.users.owner, options),
71
- user: SEED.users.owner,
72
- org: SEED.organizations.secondary,
73
- catalog: SEED.catalog.secondary,
74
- shipping: SEED.shipping.secondary,
75
- });
76
- export const outsiderContext = (options) => ({
77
- app: createTestApp(SEED.users.outsider, options),
78
- user: SEED.users.outsider,
79
- });
80
- // ── Additional users (for access tests) ──
81
- export const createAdditionalUser = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (overrides = {}) {
82
- var _a, _b, _c, _d;
83
- const prisma = getTestPrisma();
84
- const id = randomUUID();
85
- const firstname = (_a = overrides.firstname) !== null && _a !== void 0 ? _a : "Extra";
86
- const lastname = (_b = overrides.lastname) !== null && _b !== void 0 ? _b : "User";
87
- const name = (_c = overrides.name) !== null && _c !== void 0 ? _c : `${firstname} ${lastname}`;
88
- const email = (_d = overrides.email) !== null && _d !== void 0 ? _d : `extra-${id}@shophost.test`;
89
- const dbUser = yield prisma.user.create({
90
- data: {
91
- id,
92
- email,
93
- emailVerified: false,
94
- firstname,
95
- image: null,
96
- lastname,
97
- name,
98
- createdAt: new Date(),
99
- updatedAt: new Date(),
100
- },
101
- });
102
- const user = {
103
- id: dbUser.id,
104
- email: dbUser.email,
105
- firstname: dbUser.firstname,
106
- lastname: dbUser.lastname,
107
- name: dbUser.name,
108
- image: dbUser.image,
109
- };
110
- return {
111
- app: createTestApp(user),
112
- user,
113
- dbUser,
114
- };
115
- });
116
- // ── Seed helpers (for access tests that need members/invitations) ──
117
- export const seedMember = (input) => __awaiter(void 0, void 0, void 0, function* () {
118
- var _a;
119
- const prisma = getTestPrisma();
120
- return prisma.member.create({
121
- data: {
122
- organizationId: input.organizationId,
123
- role: (_a = input.role) !== null && _a !== void 0 ? _a : "member",
124
- userId: input.userId,
125
- },
126
- include: {
127
- user: {
128
- select: {
129
- id: true,
130
- firstname: true,
131
- lastname: true,
132
- email: true,
133
- image: true,
134
- },
135
- },
136
- },
137
- });
138
- });
139
- export const seedInvitation = (input) => __awaiter(void 0, void 0, void 0, function* () {
140
- var _a, _b, _c;
141
- const prisma = getTestPrisma();
142
- return prisma.invitation.create({
143
- data: {
144
- id: randomUUID(),
145
- organizationId: input.organizationId,
146
- email: input.email,
147
- role: (_a = input.role) !== null && _a !== void 0 ? _a : "member",
148
- status: (_b = input.status) !== null && _b !== void 0 ? _b : "pending",
149
- expiresAt: (_c = input.expiresAt) !== null && _c !== void 0 ? _c : new Date(Date.now() + 7 * 24 * 60 * 60 * 1000),
150
- inviterId: SEED.users.owner.id,
151
- },
152
- });
153
- });
154
- //# sourceMappingURL=test-helpers.js.map
1
+ import{__awaiter as m}from"tslib";import{randomUUID as f}from"node:crypto";import{PrismaPg as x}from"@prisma/adapter-pg";import{buildApiApp as b}from"../../app";import{HttpException as w}from"../../core/exceptions/http-exception";import{createPrismaClient as A}from"../../core/lib/prisma";import{SEED as a,resetToSeed as I}from"./seed";export{SEED}from"./seed";const y="postgresql://shophost:shophost@localhost:5555/shophost_test",E="test-google-maps-key";let c=null;const d=()=>(c||(c=A({adapter:new x({connectionString:y}),log:["warn","error"]})),c);export const resetToSeed=()=>I(d());const S=e=>{var t,o;const r=e.split("/").filter(Boolean);return r[0]==="organizations"?(t=r[1])!==null&&t!==void 0?t:"":(o=r[0])!==null&&o!==void 0?o:""},T=e=>({id:e.id,email:e.email,firstname:e.firstname,lastname:e.lastname,name:e.name,image:e.image});export const createTestApp=(e=a.users.owner,t={})=>{const o=d(),r=T(e);return b(Object.assign(Object.assign({},t),{maps:Object.assign({google:{key:E}},t.maps),prisma:o,resolveAuth:(n,s)=>({getCurrentUser:()=>m(void 0,void 0,void 0,function*(){return r}),isGranted:()=>m(void 0,void 0,void 0,function*(){const l=S(s);if(!l)return r;if(!(yield o.member.findFirst({where:{organizationId:l,userId:r.id}})))throw new w(403,"Forbidden");return r})})}))},primaryContext=e=>({app:createTestApp(a.users.owner,e),user:a.users.owner,org:a.organizations.primary,catalog:a.catalog.primary,shipping:a.shipping.primary}),secondaryContext=e=>({app:createTestApp(a.users.owner,e),user:a.users.owner,org:a.organizations.secondary,catalog:a.catalog.secondary,shipping:a.shipping.secondary}),outsiderContext=e=>({app:createTestApp(a.users.outsider,e),user:a.users.outsider}),createAdditionalUser=(...e)=>m(void 0,[...e],void 0,function*(t={}){var o,r,n,s;const l=d(),p=f(),u=(o=t.firstname)!==null&&o!==void 0?o:"Extra",g=(r=t.lastname)!==null&&r!==void 0?r:"User",h=(n=t.name)!==null&&n!==void 0?n:`${u} ${g}`,_=(s=t.email)!==null&&s!==void 0?s:`extra-${p}@shophost.test`,i=yield l.user.create({data:{id:p,email:_,emailVerified:!1,firstname:u,image:null,lastname:g,name:h,createdAt:new Date,updatedAt:new Date}}),v={id:i.id,email:i.email,firstname:i.firstname,lastname:i.lastname,name:i.name,image:i.image};return{app:createTestApp(v),user:v,dbUser:i}}),seedMember=e=>m(void 0,void 0,void 0,function*(){var t;return d().member.create({data:{organizationId:e.organizationId,role:(t=e.role)!==null&&t!==void 0?t:"member",userId:e.userId},include:{user:{select:{id:!0,firstname:!0,lastname:!0,email:!0,image:!0}}}})}),seedInvitation=e=>m(void 0,void 0,void 0,function*(){var t,o,r;return d().invitation.create({data:{id:f(),organizationId:e.organizationId,email:e.email,role:(t=e.role)!==null&&t!==void 0?t:"member",status:(o=e.status)!==null&&o!==void 0?o:"pending",expiresAt:(r=e.expiresAt)!==null&&r!==void 0?r:new Date(Date.now()+10080*60*1e3),inviterId:a.users.owner.id}})});
@@ -1,7 +1 @@
1
- "use strict";
2
- var _a, _b;
3
- var _c, _d;
4
- const TEST_DATABASE_URL = "postgresql://shophost:shophost@localhost:5555/shophost_test";
5
- (_a = (_c = process.env).DATABASE_URL) !== null && _a !== void 0 ? _a : (_c.DATABASE_URL = TEST_DATABASE_URL);
6
- (_b = (_d = process.env).NODE_ENV) !== null && _b !== void 0 ? _b : (_d.NODE_ENV = "test");
7
- //# sourceMappingURL=setup-test-env.js.map
1
+ "use strict";var _a,_b,_c,_d;const TEST_DATABASE_URL="postgresql://shophost:shophost@localhost:5555/shophost_test";(_a=(_c=process.env).DATABASE_URL)!==null&&_a!==void 0||(_c.DATABASE_URL=TEST_DATABASE_URL),(_b=(_d=process.env).NODE_ENV)!==null&&_b!==void 0||(_d.NODE_ENV="test");