@shophost/rest-api 2.0.34 → 2.0.36

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 (220) hide show
  1. package/LICENSE +17 -13
  2. package/README.md +76 -66
  3. package/package.json +2 -2
  4. package/scripts/minify-dist.mjs +45 -0
  5. package/src/app.js +1 -53
  6. package/src/app.js.map +1 -1
  7. package/src/core/auth/auth.schema.js +1 -41
  8. package/src/core/auth/auth.util.js +1 -44
  9. package/src/core/auth/better-auth.lib.js +1 -100
  10. package/src/core/auth/generate-password-hash.util.js +1 -30
  11. package/src/core/auth/headers.schema.js +1 -22
  12. package/src/core/auth/user.schema.js +1 -30
  13. package/src/core/db/__generated__/client/browser.js +1 -18
  14. package/src/core/db/__generated__/client/client.js +1 -35
  15. package/src/core/db/__generated__/client/commonInputTypes.js +1 -11
  16. package/src/core/db/__generated__/client/enums.js +1 -200
  17. package/src/core/db/__generated__/client/internal/class.js +769 -55
  18. package/src/core/db/__generated__/client/internal/prismaNamespace.d.ts +2 -2
  19. package/src/core/db/__generated__/client/internal/prismaNamespace.js +1 -541
  20. package/src/core/db/__generated__/client/internal/prismaNamespaceBrowser.js +1 -512
  21. package/src/core/db/__generated__/client/models/Account.d.ts +0 -5
  22. package/src/core/db/__generated__/client/models/Account.js +1 -2
  23. package/src/core/db/__generated__/client/models/Address.d.ts +0 -5
  24. package/src/core/db/__generated__/client/models/Address.js +1 -2
  25. package/src/core/db/__generated__/client/models/Campaign.d.ts +0 -5
  26. package/src/core/db/__generated__/client/models/Campaign.js +1 -2
  27. package/src/core/db/__generated__/client/models/ClosingTimes.d.ts +0 -5
  28. package/src/core/db/__generated__/client/models/ClosingTimes.js +1 -2
  29. package/src/core/db/__generated__/client/models/File.d.ts +0 -5
  30. package/src/core/db/__generated__/client/models/File.js +1 -2
  31. package/src/core/db/__generated__/client/models/Invitation.d.ts +0 -5
  32. package/src/core/db/__generated__/client/models/Invitation.js +1 -2
  33. package/src/core/db/__generated__/client/models/LegalEntity.d.ts +0 -5
  34. package/src/core/db/__generated__/client/models/LegalEntity.js +1 -2
  35. package/src/core/db/__generated__/client/models/Manufacturer.d.ts +0 -5
  36. package/src/core/db/__generated__/client/models/Manufacturer.js +1 -2
  37. package/src/core/db/__generated__/client/models/ManufacturerTranslation.d.ts +0 -5
  38. package/src/core/db/__generated__/client/models/ManufacturerTranslation.js +1 -2
  39. package/src/core/db/__generated__/client/models/Member.d.ts +0 -5
  40. package/src/core/db/__generated__/client/models/Member.js +1 -2
  41. package/src/core/db/__generated__/client/models/Modifier.d.ts +0 -5
  42. package/src/core/db/__generated__/client/models/Modifier.js +1 -2
  43. package/src/core/db/__generated__/client/models/ModifierGroup.d.ts +0 -5
  44. package/src/core/db/__generated__/client/models/ModifierGroup.js +1 -2
  45. package/src/core/db/__generated__/client/models/ModifierGroupTranslation.d.ts +0 -5
  46. package/src/core/db/__generated__/client/models/ModifierGroupTranslation.js +1 -2
  47. package/src/core/db/__generated__/client/models/OpeningTimes.d.ts +0 -5
  48. package/src/core/db/__generated__/client/models/OpeningTimes.js +1 -2
  49. package/src/core/db/__generated__/client/models/Order.d.ts +0 -5
  50. package/src/core/db/__generated__/client/models/Order.js +1 -2
  51. package/src/core/db/__generated__/client/models/OrderItem.d.ts +0 -5
  52. package/src/core/db/__generated__/client/models/OrderItem.js +1 -2
  53. package/src/core/db/__generated__/client/models/OrderItemTranslation.d.ts +0 -5
  54. package/src/core/db/__generated__/client/models/OrderItemTranslation.js +1 -2
  55. package/src/core/db/__generated__/client/models/Organization.d.ts +0 -5
  56. package/src/core/db/__generated__/client/models/Organization.js +1 -2
  57. package/src/core/db/__generated__/client/models/OrganizationConfiguration.d.ts +0 -5
  58. package/src/core/db/__generated__/client/models/OrganizationConfiguration.js +1 -2
  59. package/src/core/db/__generated__/client/models/Payment.d.ts +0 -5
  60. package/src/core/db/__generated__/client/models/Payment.js +1 -2
  61. package/src/core/db/__generated__/client/models/PaymentSession.d.ts +0 -5
  62. package/src/core/db/__generated__/client/models/PaymentSession.js +1 -2
  63. package/src/core/db/__generated__/client/models/Product.d.ts +0 -5
  64. package/src/core/db/__generated__/client/models/Product.js +1 -2
  65. package/src/core/db/__generated__/client/models/ProductCategory.d.ts +0 -5
  66. package/src/core/db/__generated__/client/models/ProductCategory.js +1 -2
  67. package/src/core/db/__generated__/client/models/ProductCategoryTranslation.d.ts +0 -5
  68. package/src/core/db/__generated__/client/models/ProductCategoryTranslation.js +1 -2
  69. package/src/core/db/__generated__/client/models/ProductSnapshot.d.ts +0 -5
  70. package/src/core/db/__generated__/client/models/ProductSnapshot.js +1 -2
  71. package/src/core/db/__generated__/client/models/ProductTranslation.d.ts +0 -5
  72. package/src/core/db/__generated__/client/models/ProductTranslation.js +1 -2
  73. package/src/core/db/__generated__/client/models/Reservation.d.ts +0 -5
  74. package/src/core/db/__generated__/client/models/Reservation.js +1 -2
  75. package/src/core/db/__generated__/client/models/Session.d.ts +0 -5
  76. package/src/core/db/__generated__/client/models/Session.js +1 -2
  77. package/src/core/db/__generated__/client/models/ShippingMethod.d.ts +0 -5
  78. package/src/core/db/__generated__/client/models/ShippingMethod.js +1 -2
  79. package/src/core/db/__generated__/client/models/ShippingZone.d.ts +0 -5
  80. package/src/core/db/__generated__/client/models/ShippingZone.js +1 -2
  81. package/src/core/db/__generated__/client/models/User.d.ts +0 -5
  82. package/src/core/db/__generated__/client/models/User.js +1 -2
  83. package/src/core/db/__generated__/client/models/Verification.d.ts +0 -5
  84. package/src/core/db/__generated__/client/models/Verification.js +1 -2
  85. package/src/core/db/__generated__/client/models.js +1 -2
  86. package/src/core/db/index.js +1 -2
  87. package/src/core/email/components.d.ts +16 -0
  88. package/src/core/email/components.js +1 -0
  89. package/src/core/email/components.js.map +1 -0
  90. package/src/core/exceptions/http-exception.js +1 -9
  91. package/src/core/hono/hono.js +1 -123
  92. package/src/core/lib/prisma.d.ts +8 -8
  93. package/src/core/lib/prisma.js +1 -11
  94. package/src/core/logging/pino.js +1 -5
  95. package/src/core/notifications/email.service.js +1 -116
  96. package/src/core/openapi/openapi.lib.js +1 -26
  97. package/src/core/types/google-maps.types.js +1 -2
  98. package/src/core/utils/currency.util.js +1 -11
  99. package/src/core/utils/env.util.js +1 -8
  100. package/src/core/utils/object.util.js +1 -39
  101. package/src/core/utils/translations.util.js +0 -1
  102. package/src/core/utils/zod.util.js +1 -85
  103. package/src/db.js +1 -3
  104. package/src/features/access/access.handler.js +1 -91
  105. package/src/features/access/access.route.js +1 -220
  106. package/src/features/access/access.schema.js +1 -108
  107. package/src/features/access/access.service.js +1 -294
  108. package/src/features/analytics/analytics.handler.d.ts +2 -0
  109. package/src/features/analytics/analytics.handler.js +1 -0
  110. package/src/features/analytics/analytics.handler.js.map +1 -0
  111. package/src/features/analytics/analytics.route.d.ts +3 -0
  112. package/src/features/analytics/analytics.route.js +1 -0
  113. package/src/features/analytics/analytics.route.js.map +1 -0
  114. package/src/features/analytics/analytics.schema.d.ts +86 -0
  115. package/src/features/analytics/analytics.schema.js +1 -0
  116. package/src/features/analytics/analytics.schema.js.map +1 -0
  117. package/src/features/analytics/analytics.service.d.ts +45 -0
  118. package/src/features/analytics/analytics.service.js +1 -0
  119. package/src/features/analytics/analytics.service.js.map +1 -0
  120. package/src/features/cart/cart.handler.js +1 -17
  121. package/src/features/cart/cart.route.js +1 -32
  122. package/src/features/cart/cart.schema.d.ts +1 -1
  123. package/src/features/cart/cart.schema.js +1 -39
  124. package/src/features/cart/cart.service.d.ts +1 -1
  125. package/src/features/cart/cart.service.js +1 -97
  126. package/src/features/cart/cart.util.js +1 -76
  127. package/src/features/file/file.handler.js +1 -23
  128. package/src/features/file/file.route.js +1 -34
  129. package/src/features/file/file.schema.js +1 -77
  130. package/src/features/file/file.service.js +1 -66
  131. package/src/features/health/health.handler.js +1 -10
  132. package/src/features/health/health.route.js +1 -25
  133. package/src/features/index.d.ts +1 -0
  134. package/src/features/index.js +1 -16
  135. package/src/features/index.js.map +1 -1
  136. package/src/features/location/location.handler.js +1 -25
  137. package/src/features/location/location.route.js +1 -56
  138. package/src/features/location/location.schema.js +1 -50
  139. package/src/features/location/location.service.js +1 -141
  140. package/src/features/manufacturer/manufacturer.handler.js +1 -53
  141. package/src/features/manufacturer/manufacturer.route.js +1 -97
  142. package/src/features/manufacturer/manufacturer.schema.js +1 -125
  143. package/src/features/manufacturer/manufacturer.service.js +1 -190
  144. package/src/features/order/emails/order-confirmation.email.js +1 -229
  145. package/src/features/order/emails/order-confirmation.email.js.map +1 -1
  146. package/src/features/order/emails/order-notification.email.js +1 -229
  147. package/src/features/order/emails/order-notification.email.js.map +1 -1
  148. package/src/features/order/fulfilment.schema.js +1 -3
  149. package/src/features/order/order.handler.js +1 -54
  150. package/src/features/order/order.route.js +1 -111
  151. package/src/features/order/order.schema.d.ts +4 -4
  152. package/src/features/order/order.schema.js +1 -158
  153. package/src/features/order/order.service.d.ts +4 -4
  154. package/src/features/order/order.service.js +1 -306
  155. package/src/features/order/recipient.schema.js +1 -38
  156. package/src/features/organization/legal-entity.schema.js +1 -83
  157. package/src/features/organization/organization-configuration.schema.js +1 -115
  158. package/src/features/organization/organization.handler.js +1 -48
  159. package/src/features/organization/organization.route.js +1 -84
  160. package/src/features/organization/organization.schema.js +1 -64
  161. package/src/features/organization/organization.service.js +1 -334
  162. package/src/features/payment/payment.handler.js +1 -16
  163. package/src/features/payment/payment.route.js +1 -22
  164. package/src/features/payment/payment.schema.d.ts +3 -3
  165. package/src/features/payment/payment.schema.js +1 -46
  166. package/src/features/payment/payment.service.d.ts +1 -1
  167. package/src/features/payment/payment.service.js +1 -100
  168. package/src/features/payment/stripe.service.js +1 -164
  169. package/src/features/product/product-modifier.schema.js +1 -84
  170. package/src/features/product/product.handler.js +1 -87
  171. package/src/features/product/product.route.js +1 -179
  172. package/src/features/product/product.schema.d.ts +3 -3
  173. package/src/features/product/product.schema.js +1 -143
  174. package/src/features/product/product.service.d.ts +2 -2
  175. package/src/features/product/product.service.js +1 -440
  176. package/src/features/product-category/product-category.handler.js +1 -59
  177. package/src/features/product-category/product-category.route.js +1 -139
  178. package/src/features/product-category/product-category.schema.js +1 -86
  179. package/src/features/product-category/product-category.service.js +1 -220
  180. package/src/features/reservation/emails/reservation-cancellation.email.js +1 -82
  181. package/src/features/reservation/emails/reservation-cancellation.email.js.map +1 -1
  182. package/src/features/reservation/emails/reservation-confirmation.email.js +1 -82
  183. package/src/features/reservation/emails/reservation-confirmation.email.js.map +1 -1
  184. package/src/features/reservation/emails/reservation-notification.email.js +1 -93
  185. package/src/features/reservation/emails/reservation-notification.email.js.map +1 -1
  186. package/src/features/reservation/reservation.handler.js +1 -65
  187. package/src/features/reservation/reservation.route.js +1 -167
  188. package/src/features/reservation/reservation.schema.d.ts +1 -1
  189. package/src/features/reservation/reservation.schema.js +1 -51
  190. package/src/features/reservation/reservation.service.js +1 -231
  191. package/src/features/shipping/shipping.handler.js +1 -32
  192. package/src/features/shipping/shipping.route.js +1 -51
  193. package/src/features/shipping/shipping.service.js +1 -96
  194. package/src/features/shipping-method/shipping-method.handler.js +1 -60
  195. package/src/features/shipping-method/shipping-method.route.js +1 -144
  196. package/src/features/shipping-method/shipping-method.schema.js +1 -48
  197. package/src/features/shipping-method/shipping-method.service.js +1 -229
  198. package/src/features/shipping-method/shipping-zone.schema.js +1 -31
  199. package/src/features/webhook/webhook.handler.js +1 -50
  200. package/src/features/webhook/webhook.route.js +1 -33
  201. package/src/index.js +1 -6
  202. package/src/integrations/next.js +1 -82
  203. package/src/schemas/address.schema.js +1 -112
  204. package/src/schemas/currency.schema.js +1 -118
  205. package/src/schemas/error.schema.js +1 -12
  206. package/src/schemas/index.d.ts +1 -0
  207. package/src/schemas/index.js +1 -29
  208. package/src/schemas/index.js.map +1 -1
  209. package/src/schemas/locales.schema.js +1 -238
  210. package/src/schemas/number.schema.js +1 -29
  211. package/src/schemas/pagination.schema.js +1 -54
  212. package/src/schemas/params.schema.js +1 -20
  213. package/src/schemas/queries.schema.js +1 -6
  214. package/src/test/global-setup.js +1 -37
  215. package/src/test/integration/api-fixtures.js +1 -160
  216. package/src/test/integration/seed.js +1 -368
  217. package/src/test/integration/test-helpers.d.ts +2 -0
  218. package/src/test/integration/test-helpers.js +1 -154
  219. package/src/test/integration/test-helpers.js.map +1 -1
  220. package/src/test/setup-test-env.js +1 -7
@@ -26,7 +26,7 @@ export declare const createPrismaClient: (options: CreatePrismaClientOptions) =>
26
26
  }) => Promise<[import("@prisma/client/runtime/client").Result<T, A, "findMany">, import("prisma-extension-pagination").CursorPaginationMeta]>;
27
27
  };
28
28
  };
29
- user: {
29
+ file: {
30
30
  paginate: () => <T, A>(this: T, args?: import("@prisma/client/runtime/client").Exact<A, Omit<import("@prisma/client/runtime/client").Args<T, "findMany">, "cursor" | "take" | "skip">> | undefined) => {
31
31
  withPages: <TOptions extends Omit<P, "limit">, P extends import("prisma-extension-pagination").PageNumberPaginationOptions>(options?: (TOptions & {
32
32
  limit?: P["limit"] | undefined;
@@ -38,7 +38,7 @@ export declare const createPrismaClient: (options: CreatePrismaClientOptions) =>
38
38
  }) => Promise<[import("@prisma/client/runtime/client").Result<T, A, "findMany">, import("prisma-extension-pagination").CursorPaginationMeta]>;
39
39
  };
40
40
  };
41
- member: {
41
+ user: {
42
42
  paginate: () => <T, A>(this: T, args?: import("@prisma/client/runtime/client").Exact<A, Omit<import("@prisma/client/runtime/client").Args<T, "findMany">, "cursor" | "take" | "skip">> | undefined) => {
43
43
  withPages: <TOptions extends Omit<P, "limit">, P extends import("prisma-extension-pagination").PageNumberPaginationOptions>(options?: (TOptions & {
44
44
  limit?: P["limit"] | undefined;
@@ -50,7 +50,7 @@ export declare const createPrismaClient: (options: CreatePrismaClientOptions) =>
50
50
  }) => Promise<[import("@prisma/client/runtime/client").Result<T, A, "findMany">, import("prisma-extension-pagination").CursorPaginationMeta]>;
51
51
  };
52
52
  };
53
- organization: {
53
+ member: {
54
54
  paginate: () => <T, A>(this: T, args?: import("@prisma/client/runtime/client").Exact<A, Omit<import("@prisma/client/runtime/client").Args<T, "findMany">, "cursor" | "take" | "skip">> | undefined) => {
55
55
  withPages: <TOptions extends Omit<P, "limit">, P extends import("prisma-extension-pagination").PageNumberPaginationOptions>(options?: (TOptions & {
56
56
  limit?: P["limit"] | undefined;
@@ -62,7 +62,7 @@ export declare const createPrismaClient: (options: CreatePrismaClientOptions) =>
62
62
  }) => Promise<[import("@prisma/client/runtime/client").Result<T, A, "findMany">, import("prisma-extension-pagination").CursorPaginationMeta]>;
63
63
  };
64
64
  };
65
- file: {
65
+ organization: {
66
66
  paginate: () => <T, A>(this: T, args?: import("@prisma/client/runtime/client").Exact<A, Omit<import("@prisma/client/runtime/client").Args<T, "findMany">, "cursor" | "take" | "skip">> | undefined) => {
67
67
  withPages: <TOptions extends Omit<P, "limit">, P extends import("prisma-extension-pagination").PageNumberPaginationOptions>(options?: (TOptions & {
68
68
  limit?: P["limit"] | undefined;
@@ -428,7 +428,7 @@ export declare const createPrismaClient: (options: CreatePrismaClientOptions) =>
428
428
  }) => Promise<[import("@prisma/client/runtime/client").Result<T, A, "findMany">, import("prisma-extension-pagination").CursorPaginationMeta]>;
429
429
  };
430
430
  };
431
- user: {
431
+ file: {
432
432
  paginate: () => <T, A>(this: T, args?: import("@prisma/client/runtime/client").Exact<A, Omit<import("@prisma/client/runtime/client").Args<T, "findMany">, "cursor" | "take" | "skip">> | undefined) => {
433
433
  withPages: <TOptions extends Omit<P, "limit">, P extends import("prisma-extension-pagination").PageNumberPaginationOptions>(options?: (TOptions & {
434
434
  limit?: P["limit"] | undefined;
@@ -440,7 +440,7 @@ export declare const createPrismaClient: (options: CreatePrismaClientOptions) =>
440
440
  }) => Promise<[import("@prisma/client/runtime/client").Result<T, A, "findMany">, import("prisma-extension-pagination").CursorPaginationMeta]>;
441
441
  };
442
442
  };
443
- member: {
443
+ user: {
444
444
  paginate: () => <T, A>(this: T, args?: import("@prisma/client/runtime/client").Exact<A, Omit<import("@prisma/client/runtime/client").Args<T, "findMany">, "cursor" | "take" | "skip">> | undefined) => {
445
445
  withPages: <TOptions extends Omit<P, "limit">, P extends import("prisma-extension-pagination").PageNumberPaginationOptions>(options?: (TOptions & {
446
446
  limit?: P["limit"] | undefined;
@@ -452,7 +452,7 @@ export declare const createPrismaClient: (options: CreatePrismaClientOptions) =>
452
452
  }) => Promise<[import("@prisma/client/runtime/client").Result<T, A, "findMany">, import("prisma-extension-pagination").CursorPaginationMeta]>;
453
453
  };
454
454
  };
455
- organization: {
455
+ member: {
456
456
  paginate: () => <T, A>(this: T, args?: import("@prisma/client/runtime/client").Exact<A, Omit<import("@prisma/client/runtime/client").Args<T, "findMany">, "cursor" | "take" | "skip">> | undefined) => {
457
457
  withPages: <TOptions extends Omit<P, "limit">, P extends import("prisma-extension-pagination").PageNumberPaginationOptions>(options?: (TOptions & {
458
458
  limit?: P["limit"] | undefined;
@@ -464,7 +464,7 @@ export declare const createPrismaClient: (options: CreatePrismaClientOptions) =>
464
464
  }) => Promise<[import("@prisma/client/runtime/client").Result<T, A, "findMany">, import("prisma-extension-pagination").CursorPaginationMeta]>;
465
465
  };
466
466
  };
467
- file: {
467
+ organization: {
468
468
  paginate: () => <T, A>(this: T, args?: import("@prisma/client/runtime/client").Exact<A, Omit<import("@prisma/client/runtime/client").Args<T, "findMany">, "cursor" | "take" | "skip">> | undefined) => {
469
469
  withPages: <TOptions extends Omit<P, "limit">, P extends import("prisma-extension-pagination").PageNumberPaginationOptions>(options?: (TOptions & {
470
470
  limit?: P["limit"] | undefined;
@@ -1,11 +1 @@
1
- import { pagination } from "prisma-extension-pagination";
2
- import { PrismaClient } from "../db";
3
- export const createPrismaClient = (options) => {
4
- return new PrismaClient(options).$extends(pagination({
5
- pages: {
6
- limit: 15,
7
- includePageCount: true,
8
- },
9
- }));
10
- };
11
- //# sourceMappingURL=prisma.js.map
1
+ import{pagination as t}from"prisma-extension-pagination";import{PrismaClient as i}from"../db";export const createPrismaClient=e=>new i(e).$extends(t({pages:{limit:15,includePageCount:!0}}));
@@ -1,5 +1 @@
1
- import pino from "pino";
2
- export const logger = pino({
3
- timestamp: pino.stdTimeFunctions.isoTime,
4
- });
5
- //# sourceMappingURL=pino.js.map
1
+ import o from"pino";export const logger=o({timestamp:o.stdTimeFunctions.isoTime});
@@ -1,116 +1 @@
1
- import { __awaiter } from "tslib";
2
- import { Resend } from "resend";
3
- import { OrderConfirmationEmail } from "../../features/order/emails/order-confirmation.email";
4
- import OrderNotificationEmail from "../../features/order/emails/order-notification.email";
5
- import { ReservationCancellationEmail } from "../../features/reservation/emails/reservation-cancellation.email";
6
- import { ReservationConfirmationEmail } from "../../features/reservation/emails/reservation-confirmation.email";
7
- import ReservationNotificationEmail from "../../features/reservation/emails/reservation-notification.email";
8
- class EmailService {
9
- constructor(apiKey) {
10
- this.resend = new Resend(apiKey);
11
- }
12
- /**
13
- * Sends an email
14
- */
15
- sendEmail(payload, options) {
16
- return __awaiter(this, void 0, void 0, function* () {
17
- const { data, error } = yield this.resend.emails.send(payload);
18
- });
19
- }
20
- /**
21
- * Sends an order confirmation email
22
- */
23
- sendOrderConfirmationEmail(user, organization, order) {
24
- return __awaiter(this, void 0, void 0, function* () {
25
- console.log(`Sending order confirmation email to ${user.email}`);
26
- yield this.sendEmail({
27
- from: `${organization.name} <info@shophost.io>`,
28
- to: [user.email],
29
- subject: `Order Confirmation - Order #${order.referenceId} | ${organization.name}`,
30
- react: OrderConfirmationEmail({
31
- user,
32
- organization,
33
- order,
34
- }),
35
- });
36
- });
37
- }
38
- /**
39
- * Sends an order confirmation email
40
- */
41
- sendOrderNotificationEmail(user, member, organization, order) {
42
- return __awaiter(this, void 0, void 0, function* () {
43
- console.log(`Sending order notification email to ${member.email}`);
44
- yield this.sendEmail({
45
- from: `${organization.name} <info@shophost.io>`,
46
- to: [member.email],
47
- subject: `You have received a new order | ${organization.name}`,
48
- react: OrderNotificationEmail({
49
- user,
50
- organization,
51
- order,
52
- }),
53
- });
54
- });
55
- }
56
- sendReservationConfirmationEmail(reservation) {
57
- return __awaiter(this, void 0, void 0, function* () {
58
- const user = reservation.user;
59
- const organization = reservation.organization;
60
- console.log(`Sending reservation confirmation email to ${user.email}`);
61
- yield this.sendEmail({
62
- from: `${organization.name} <info@shophost.io>`,
63
- to: [user.email],
64
- subject: `Reservation Confirmation - ${organization.name}`,
65
- react: ReservationConfirmationEmail({
66
- user,
67
- organization,
68
- reservation,
69
- }),
70
- });
71
- });
72
- }
73
- /**
74
- * Sends a reservation cancellation email
75
- */
76
- sendReservationCancellationEmail(reservation) {
77
- return __awaiter(this, void 0, void 0, function* () {
78
- const user = reservation.user;
79
- const organization = reservation.organization;
80
- console.log(`Sending reservation cancellation email to ${user.email}`);
81
- yield this.sendEmail({
82
- from: `${organization.name} <info@shophost.io>`,
83
- to: [user.email],
84
- subject: `Reservation Cancelled - ${organization.name}`,
85
- react: ReservationCancellationEmail({
86
- user,
87
- organization,
88
- reservation,
89
- }),
90
- });
91
- });
92
- }
93
- /**
94
- * Sends a reservation notification email to an organization member
95
- */
96
- sendReservationNotificationEmail(member, reservation) {
97
- return __awaiter(this, void 0, void 0, function* () {
98
- const user = reservation.user;
99
- const organization = reservation.organization;
100
- console.log(`Sending reservation notification email to ${member.email}`);
101
- yield this.sendEmail({
102
- from: `${organization.name} <info@shophost.io>`,
103
- to: [member.email],
104
- subject: `New Reservation Request | ${organization.name}`,
105
- react: ReservationNotificationEmail({
106
- user,
107
- member,
108
- organization,
109
- reservation,
110
- }),
111
- });
112
- });
113
- }
114
- }
115
- export { EmailService };
116
- //# sourceMappingURL=email.service.js.map
1
+ import{__awaiter as t}from"tslib";import{Resend as a}from"resend";import{OrderConfirmationEmail as r}from"../../features/order/emails/order-confirmation.email";import s from"../../features/order/emails/order-notification.email";import{ReservationCancellationEmail as m}from"../../features/reservation/emails/reservation-cancellation.email";import{ReservationConfirmationEmail as l}from"../../features/reservation/emails/reservation-confirmation.email";import d from"../../features/reservation/emails/reservation-notification.email";class c{constructor(i){this.resend=new a(i)}sendEmail(i,o){return t(this,void 0,void 0,function*(){const{data:e,error:n}=yield this.resend.emails.send(i)})}sendOrderConfirmationEmail(i,o,e){return t(this,void 0,void 0,function*(){console.log(`Sending order confirmation email to ${i.email}`),yield this.sendEmail({from:`${o.name} <info@shophost.io>`,to:[i.email],subject:`Order Confirmation - Order #${e.referenceId} | ${o.name}`,react:r({user:i,organization:o,order:e})})})}sendOrderNotificationEmail(i,o,e,n){return t(this,void 0,void 0,function*(){console.log(`Sending order notification email to ${o.email}`),yield this.sendEmail({from:`${e.name} <info@shophost.io>`,to:[o.email],subject:`You have received a new order | ${e.name}`,react:s({user:i,organization:e,order:n})})})}sendReservationConfirmationEmail(i){return t(this,void 0,void 0,function*(){const o=i.user,e=i.organization;console.log(`Sending reservation confirmation email to ${o.email}`),yield this.sendEmail({from:`${e.name} <info@shophost.io>`,to:[o.email],subject:`Reservation Confirmation - ${e.name}`,react:l({user:o,organization:e,reservation:i})})})}sendReservationCancellationEmail(i){return t(this,void 0,void 0,function*(){const o=i.user,e=i.organization;console.log(`Sending reservation cancellation email to ${o.email}`),yield this.sendEmail({from:`${e.name} <info@shophost.io>`,to:[o.email],subject:`Reservation Cancelled - ${e.name}`,react:m({user:o,organization:e,reservation:i})})})}sendReservationNotificationEmail(i,o){return t(this,void 0,void 0,function*(){const e=o.user,n=o.organization;console.log(`Sending reservation notification email to ${i.email}`),yield this.sendEmail({from:`${n.name} <info@shophost.io>`,to:[i.email],subject:`New Reservation Request | ${n.name}`,react:d({user:e,member:i,organization:n,reservation:o})})})}}export{c as EmailService};
@@ -1,26 +1 @@
1
- import { buildApiApp } from "../../app";
2
- export const defaultOpenApiDocument = {
3
- info: {
4
- description: "API for Shophost Organization API",
5
- title: "Shophost API",
6
- version: "1.0",
7
- },
8
- openapi: "3.1.0",
9
- servers: [
10
- {
11
- description: "Local",
12
- url: "http://localhost:3001/api",
13
- },
14
- {
15
- description: "Production",
16
- url: "https://api.shophost.io/api",
17
- },
18
- ],
19
- };
20
- export const generateOpenApiSpec = (apiDoc = defaultOpenApiDocument, buildApiAppOptions = {}) => {
21
- const app = buildApiApp(buildApiAppOptions);
22
- return app.getOpenAPI31Document(apiDoc, {
23
- unionPreferredType: "oneOf",
24
- });
25
- };
26
- //# sourceMappingURL=openapi.lib.js.map
1
+ import{buildApiApp as e}from"../../app";export const defaultOpenApiDocument={info:{description:"API for Shophost Organization API",title:"Shophost API",version:"1.0"},openapi:"3.1.0",servers:[{description:"Local",url:"http://localhost:3001/api"},{description:"Production",url:"https://api.shophost.io/api"}]},generateOpenApiSpec=(o=defaultOpenApiDocument,p={})=>e(p).getOpenAPI31Document(o,{unionPreferredType:"oneOf"});
@@ -1,2 +1 @@
1
- export {};
2
- //# sourceMappingURL=google-maps.types.js.map
1
+ export{};
@@ -1,11 +1 @@
1
- export const formatCurrencyAmount = (amount, currency = "USD", locale = "en-US") => {
2
- // Stripe amounts are in the smallest currency unit (e.g., cents for USD)
3
- const amountInMainUnit = amount / 100;
4
- return new Intl.NumberFormat(locale, {
5
- style: "currency",
6
- currency: currency,
7
- minimumFractionDigits: 2,
8
- maximumFractionDigits: 2,
9
- }).format(amountInMainUnit);
10
- };
11
- //# sourceMappingURL=currency.util.js.map
1
+ export const formatCurrencyAmount=(n,t="USD",r="en-US")=>{const m=n/100;return new Intl.NumberFormat(r,{style:"currency",currency:t,minimumFractionDigits:2,maximumFractionDigits:2}).format(m)};
@@ -1,8 +1 @@
1
- import { z } from "@hono/zod-openapi";
2
- export function requireEnv(type, key) {
3
- if (type === "string") {
4
- return z.string().min(1, `${key} is required`).parse(process.env[key]);
5
- }
6
- return z.coerce.number().min(1, `${key} is required`).parse(process.env[key]);
7
- }
8
- //# sourceMappingURL=env.util.js.map
1
+ import{z as e}from"@hono/zod-openapi";export function requireEnv(i,r){return i==="string"?e.string().min(1,`${r} is required`).parse(process.env[r]):e.coerce.number().min(1,`${r} is required`).parse(process.env[r])}
@@ -1,39 +1 @@
1
- /**
2
- * A standalone implementation of Lodash's `_.get` in TypeScript.
3
- *
4
- * @param object The object to query.
5
- * @param path The path to get. Can be:
6
- * - a string in dot/bracket notation, e.g. "a.b[0].c"
7
- * - an array of string/number keys, e.g. ["a", "b", 0, "c"].
8
- * @param defaultValue The value returned if the resolved value is undefined.
9
- * @returns The resolved value, or defaultValue if it's undefined.
10
- */
11
- export const get = (object, path, defaultValue) => {
12
- // If the object is null or undefined, return the defaultValue right away.
13
- if (object == null) {
14
- return defaultValue;
15
- }
16
- // Convert path into an array if it's not already.
17
- // This regex handles bracket-notation -> dot-notation, e.g. "a[0].b" -> "a.0.b".
18
- // Then we split on '.' to create an array of keys.
19
- const pathArray = Array.isArray(path)
20
- ? path
21
- : path
22
- .replace(/\[(\d+)\]/g, ".$1")
23
- .split(".")
24
- // filter out empty strings (e.g., if path had a leading or trailing dot)
25
- .filter(Boolean);
26
- // Start traversing
27
- let result = object;
28
- for (let i = 0; i < pathArray.length; i++) {
29
- const key = pathArray[i];
30
- // If the current value is null/undefined or doesn't have the key, return defaultValue.
31
- if (result == null || !(key in result)) {
32
- return defaultValue;
33
- }
34
- result = result[key];
35
- }
36
- // If we finally get `undefined`, return defaultValue, else the resolved value
37
- return result === undefined ? defaultValue : result;
38
- };
39
- //# sourceMappingURL=object.util.js.map
1
+ export const get=(i,n,e)=>{if(i==null)return e;const l=Array.isArray(n)?n:n.replace(/\[(\d+)\]/g,".$1").split(".").filter(Boolean);let r=i;for(let t=0;t<l.length;t++){const o=l[t];if(r==null||!(o in r))return e;r=r[o]}return r===void 0?e:r};
@@ -1,2 +1 @@
1
1
  "use strict";
2
- //# sourceMappingURL=translations.util.js.map
@@ -1,85 +1 @@
1
- import { z } from "@hono/zod-openapi";
2
- /**
3
- * A helper function that, given an array of field names,
4
- * ensures that each of these fields is present and non-empty
5
- * in the translation that matches the `defaultLocale`.
6
- */
7
- export const validateRequiredForDefaultLocale = (...requiredFields) => (data, ctx) => {
8
- const { translations, defaultLocale } = data;
9
- // Find the index of the translation that matches the defaultLocale
10
- const defaultTranslationIndex = translations.findIndex((t) => t.locale === defaultLocale);
11
- // If there's no translation for the default locale, add an error
12
- if (defaultTranslationIndex === -1) {
13
- ctx.addIssue({
14
- code: z.ZodIssueCode.custom,
15
- message: "Missing translation for the default locale",
16
- path: ["translations"],
17
- });
18
- return;
19
- }
20
- // For each required field, check if it's present and non-empty
21
- requiredFields.forEach((fieldName) => {
22
- const fieldValue = translations[defaultTranslationIndex][fieldName];
23
- // Depending on your exact needs, this could be a more nuanced check,
24
- // e.g., for non-empty arrays, numeric values, etc.
25
- // Here, we assume "non-empty string" is the requirement.
26
- if (typeof fieldValue !== "string" || !fieldValue.trim()) {
27
- ctx.addIssue({
28
- code: z.ZodIssueCode.custom,
29
- message: `This field is required`,
30
- path: ["translations", defaultTranslationIndex, fieldName],
31
- });
32
- }
33
- });
34
- };
35
- /**
36
- * Recursively processes an object and extracts values from 'translations' arrays.
37
- * If a field called 'translations' is found and it's an array with at least one object,
38
- * the values from that object are added to the parent object.
39
- * @param data The object to process
40
- * @returns A new object with translations extracted
41
- */
42
- export const flattenTranslationData = (data) => {
43
- // If data is null, undefined, or not an object, return it as is
44
- if (data === null ||
45
- data === undefined ||
46
- typeof data !== "object" ||
47
- data instanceof Date) {
48
- return data;
49
- }
50
- // If data is an array, process each item recursively
51
- if (Array.isArray(data)) {
52
- return data.map((item) => flattenTranslationData(item));
53
- }
54
- // Create a new object to hold the result
55
- const result = {};
56
- // Process each property in the object
57
- for (const [key, value] of Object.entries(data)) {
58
- if (key === "translations" && Array.isArray(value) && value.length > 0) {
59
- // If we found a translations array with at least one object,
60
- // merge its properties into the result object
61
- const translationObj = value[0];
62
- if (translationObj && typeof translationObj === "object") {
63
- // Copy all properties from the first translation object to the result
64
- // except for the 'id' field
65
- for (const [translationKey, translationValue] of Object.entries(translationObj)) {
66
- if (translationKey !== "id") {
67
- result[translationKey] = translationValue;
68
- }
69
- }
70
- }
71
- }
72
- else if (typeof value === "object" &&
73
- value !== null &&
74
- !(value instanceof Date)) {
75
- // Recursively process nested objects
76
- result[key] = flattenTranslationData(value);
77
- }
78
- else {
79
- // Copy primitive values and dates as is
80
- result[key] = value;
81
- }
82
- }
83
- return result;
84
- };
85
- //# sourceMappingURL=zod.util.js.map
1
+ import{z as l}from"@hono/zod-openapi";export const validateRequiredForDefaultLocale=(...t)=>(s,o)=>{const{translations:e,defaultLocale:i}=s,n=e.findIndex(r=>r.locale===i);if(n===-1){o.addIssue({code:l.ZodIssueCode.custom,message:"Missing translation for the default locale",path:["translations"]});return}t.forEach(r=>{const a=e[n][r];(typeof a!="string"||!a.trim())&&o.addIssue({code:l.ZodIssueCode.custom,message:"This field is required",path:["translations",n,r]})})},flattenTranslationData=t=>{if(t==null||typeof t!="object"||t instanceof Date)return t;if(Array.isArray(t))return t.map(o=>flattenTranslationData(o));const s={};for(const[o,e]of Object.entries(t))if(o==="translations"&&Array.isArray(e)&&e.length>0){const i=e[0];if(i&&typeof i=="object")for(const[n,r]of Object.entries(i))n!=="id"&&(s[n]=r)}else typeof e=="object"&&e!==null&&!(e instanceof Date)?s[o]=flattenTranslationData(e):s[o]=e;return s};
package/src/db.js CHANGED
@@ -1,3 +1 @@
1
- export * from "./core/db";
2
- export { createPrismaClient, } from "./core/lib/prisma";
3
- //# sourceMappingURL=db.js.map
1
+ export*from"./core/db";export{createPrismaClient}from"./core/lib/prisma";
@@ -1,91 +1 @@
1
- import { __awaiter } from "tslib";
2
- import { createApiRouter } from "../../core/hono/hono";
3
- import { accessRoute } from "./access.route";
4
- import { AccessService } from "./access.service";
5
- export const buildAccessHandler = (prisma) => {
6
- const app = createApiRouter();
7
- app.openapi(accessRoute.getMembers, (c) => __awaiter(void 0, void 0, void 0, function* () {
8
- const auth = c.get("auth");
9
- const params = c.req.valid("param");
10
- const query = c.req.valid("query");
11
- yield auth.isGranted("read");
12
- const service = new AccessService(prisma);
13
- const result = yield service.getMembers(params.organizationId, Object.assign({}, query));
14
- return c.json(result, 200);
15
- }));
16
- app.openapi(accessRoute.getMember, (c) => __awaiter(void 0, void 0, void 0, function* () {
17
- const auth = c.get("auth");
18
- const params = c.req.valid("param");
19
- yield auth.isGranted("read");
20
- const service = new AccessService(prisma);
21
- const member = yield service.getMember(params.organizationId, params.memberId);
22
- return c.json(member, 200);
23
- }));
24
- app.openapi(accessRoute.updateMemberRole, (c) => __awaiter(void 0, void 0, void 0, function* () {
25
- const auth = c.get("auth");
26
- const params = c.req.valid("param");
27
- const body = c.req.valid("json");
28
- const user = yield auth.isGranted("update");
29
- const service = new AccessService(prisma);
30
- const updated = yield service.updateMemberRole(params.organizationId, params.memberId, user.id, body);
31
- return c.json(updated, 200);
32
- }));
33
- app.openapi(accessRoute.deleteMember, (c) => __awaiter(void 0, void 0, void 0, function* () {
34
- const auth = c.get("auth");
35
- const params = c.req.valid("param");
36
- const user = yield auth.isGranted("delete");
37
- const service = new AccessService(prisma);
38
- yield service.deleteMember(params.organizationId, params.memberId, user.id);
39
- return c.body(null, 204);
40
- }));
41
- app.openapi(accessRoute.createInvitation, (c) => __awaiter(void 0, void 0, void 0, function* () {
42
- const auth = c.get("auth");
43
- const params = c.req.valid("param");
44
- const body = c.req.valid("json");
45
- const user = yield auth.isGranted("create");
46
- const service = new AccessService(prisma);
47
- const invitation = yield service.createInvitation(params.organizationId, user.id, body);
48
- return c.json(invitation, 201);
49
- }));
50
- app.openapi(accessRoute.getInvitations, (c) => __awaiter(void 0, void 0, void 0, function* () {
51
- const auth = c.get("auth");
52
- const params = c.req.valid("param");
53
- yield auth.isGranted("read");
54
- const service = new AccessService(prisma);
55
- const invitations = yield service.getInvitations(params.organizationId);
56
- return c.json(invitations, 200);
57
- }));
58
- app.openapi(accessRoute.deleteInvitation, (c) => __awaiter(void 0, void 0, void 0, function* () {
59
- const auth = c.get("auth");
60
- const params = c.req.valid("param");
61
- yield auth.isGranted("delete");
62
- const service = new AccessService(prisma);
63
- yield service.deleteInvitation(params.organizationId, params.invitationId);
64
- return c.body(null, 204);
65
- }));
66
- app.openapi(accessRoute.getUserInvitations, (c) => __awaiter(void 0, void 0, void 0, function* () {
67
- const auth = c.get("auth");
68
- const user = yield auth.getCurrentUser();
69
- const service = new AccessService(prisma);
70
- const invitations = yield service.getUserInvitations(user.email);
71
- return c.json(invitations, 200);
72
- }));
73
- app.openapi(accessRoute.acceptInvitation, (c) => __awaiter(void 0, void 0, void 0, function* () {
74
- const auth = c.get("auth");
75
- const params = c.req.valid("param");
76
- const user = yield auth.getCurrentUser();
77
- const service = new AccessService(prisma);
78
- const member = yield service.acceptInvitation(params.invitationId, user.id);
79
- return c.json(member, 200);
80
- }));
81
- app.openapi(accessRoute.leaveOrganization, (c) => __awaiter(void 0, void 0, void 0, function* () {
82
- const auth = c.get("auth");
83
- const params = c.req.valid("param");
84
- const user = yield auth.getCurrentUser();
85
- const service = new AccessService(prisma);
86
- yield service.leaveOrganization(params.organizationId, user.id);
87
- return c.body(null, 204);
88
- }));
89
- return app;
90
- };
91
- //# sourceMappingURL=access.handler.js.map
1
+ import{__awaiter as s}from"tslib";import{createApiRouter as l}from"../../core/hono/hono";import{accessRoute as d}from"./access.route";import{AccessService as v}from"./access.service";export const buildAccessHandler=r=>{const a=l();return a.openapi(d.getMembers,e=>s(void 0,void 0,void 0,function*(){const n=e.get("auth"),t=e.req.valid("param"),i=e.req.valid("query");yield n.isGranted("read");const c=yield new v(r).getMembers(t.organizationId,Object.assign({},i));return e.json(c,200)})),a.openapi(d.getMember,e=>s(void 0,void 0,void 0,function*(){const n=e.get("auth"),t=e.req.valid("param");yield n.isGranted("read");const o=yield new v(r).getMember(t.organizationId,t.memberId);return e.json(o,200)})),a.openapi(d.updateMemberRole,e=>s(void 0,void 0,void 0,function*(){const n=e.get("auth"),t=e.req.valid("param"),i=e.req.valid("json"),o=yield n.isGranted("update"),u=yield new v(r).updateMemberRole(t.organizationId,t.memberId,o.id,i);return e.json(u,200)})),a.openapi(d.deleteMember,e=>s(void 0,void 0,void 0,function*(){const n=e.get("auth"),t=e.req.valid("param"),i=yield n.isGranted("delete");return yield new v(r).deleteMember(t.organizationId,t.memberId,i.id),e.body(null,204)})),a.openapi(d.createInvitation,e=>s(void 0,void 0,void 0,function*(){const n=e.get("auth"),t=e.req.valid("param"),i=e.req.valid("json"),o=yield n.isGranted("create"),u=yield new v(r).createInvitation(t.organizationId,o.id,i);return e.json(u,201)})),a.openapi(d.getInvitations,e=>s(void 0,void 0,void 0,function*(){const n=e.get("auth"),t=e.req.valid("param");yield n.isGranted("read");const o=yield new v(r).getInvitations(t.organizationId);return e.json(o,200)})),a.openapi(d.deleteInvitation,e=>s(void 0,void 0,void 0,function*(){const n=e.get("auth"),t=e.req.valid("param");return yield n.isGranted("delete"),yield new v(r).deleteInvitation(t.organizationId,t.invitationId),e.body(null,204)})),a.openapi(d.getUserInvitations,e=>s(void 0,void 0,void 0,function*(){const t=yield e.get("auth").getCurrentUser(),o=yield new v(r).getUserInvitations(t.email);return e.json(o,200)})),a.openapi(d.acceptInvitation,e=>s(void 0,void 0,void 0,function*(){const n=e.get("auth"),t=e.req.valid("param"),i=yield n.getCurrentUser(),c=yield new v(r).acceptInvitation(t.invitationId,i.id);return e.json(c,200)})),a.openapi(d.leaveOrganization,e=>s(void 0,void 0,void 0,function*(){const n=e.get("auth"),t=e.req.valid("param"),i=yield n.getCurrentUser();return yield new v(r).leaveOrganization(t.organizationId,i.id),e.body(null,204)})),a};