@shophost/rest-api 2.0.67 → 2.0.69
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/schema.prisma +1 -0
- package/scripts/shophost-rest-api.mjs +198 -1
- package/src/bootstrap.js +1 -1
- package/src/container.js +1 -1
- package/src/core/auth/auth.schema.js +1 -1
- package/src/core/auth/auth.util.js +1 -1
- package/src/core/auth/better-auth.lib.js +1 -1
- package/src/core/auth/generate-password-hash.util.js +1 -1
- package/src/core/auth/headers.schema.js +1 -1
- package/src/core/auth/user.schema.js +1 -1
- package/src/core/db/__generated__/client/browser.js +1 -1
- package/src/core/db/__generated__/client/client.js +1 -1
- package/src/core/db/__generated__/client/enums.js +1 -1
- package/src/core/db/__generated__/client/internal/class.js +789 -1
- package/src/core/db/__generated__/client/internal/prismaNamespace.d.ts +1 -0
- package/src/core/db/__generated__/client/internal/prismaNamespace.js +1 -1
- package/src/core/db/__generated__/client/internal/prismaNamespaceBrowser.d.ts +1 -0
- package/src/core/db/__generated__/client/internal/prismaNamespaceBrowser.js +1 -1
- package/src/core/db/__generated__/client/models/OrganizationConfiguration.d.ts +41 -1
- package/src/core/db/index.js +1 -1
- package/src/core/email/components.js +1 -1
- package/src/core/exceptions/http-exception.js +1 -1
- package/src/core/hono/hono.js +1 -1
- package/src/core/lib/prisma.js +1 -1
- package/src/core/logging/pino.js +1 -1
- package/src/core/notifications/email.service.js +1 -1
- package/src/core/openapi/openapi.lib.js +1 -1
- package/src/core/utils/currency.util.js +1 -1
- package/src/core/utils/env.util.js +1 -1
- package/src/core/utils/object.util.js +1 -1
- package/src/core/utils/translations.util.js +1 -1
- package/src/core/utils/zod.util.js +1 -1
- package/src/db.js +1 -1
- package/src/features/access/access.handler.js +1 -1
- package/src/features/access/access.route.js +1 -1
- package/src/features/access/access.schema.js +1 -1
- package/src/features/access/access.service.js +1 -1
- package/src/features/analytics/analytics.handler.js +1 -1
- package/src/features/analytics/analytics.route.js +1 -1
- package/src/features/analytics/analytics.schema.js +1 -1
- package/src/features/analytics/analytics.service.js +1 -1
- package/src/features/cart/cart.handler.js +1 -1
- package/src/features/cart/cart.route.js +1 -1
- package/src/features/cart/cart.schema.js +1 -1
- package/src/features/cart/cart.service.js +1 -1
- package/src/features/cart/cart.util.js +1 -1
- package/src/features/customer/customer.handler.js +1 -1
- package/src/features/customer/customer.route.js +1 -1
- package/src/features/customer/customer.schema.js +1 -1
- package/src/features/customer/customer.service.js +1 -1
- package/src/features/file/file.handler.js +1 -1
- package/src/features/file/file.route.js +1 -1
- package/src/features/file/file.schema.js +1 -1
- package/src/features/file/file.service.js +1 -1
- package/src/features/health/health.handler.js +1 -1
- package/src/features/health/health.route.js +1 -1
- package/src/features/index.js +1 -1
- package/src/features/integration/integration-config.js +1 -1
- package/src/features/integration/integration-registry.js +1 -1
- package/src/features/integration/integration.handler.js +1 -1
- package/src/features/integration/integration.route.js +1 -1
- package/src/features/integration/integration.schema.js +1 -1
- package/src/features/integration/integration.service.js +1 -1
- package/src/features/inventory/inventory.service.js +1 -1
- package/src/features/location/location.handler.js +1 -1
- package/src/features/location/location.route.js +1 -1
- package/src/features/location/location.schema.js +1 -1
- package/src/features/location/location.service.js +1 -1
- package/src/features/manufacturer/manufacturer.handler.js +1 -1
- package/src/features/manufacturer/manufacturer.route.js +1 -1
- package/src/features/manufacturer/manufacturer.schema.js +1 -1
- package/src/features/manufacturer/manufacturer.service.js +1 -1
- package/src/features/order/emails/order-confirmation.email.js +1 -1
- package/src/features/order/emails/order-notification.email.js +1 -1
- package/src/features/order/fulfilment.schema.js +1 -1
- package/src/features/order/order-fulfillment.service.js +1 -1
- package/src/features/order/order.handler.js +1 -1
- package/src/features/order/order.route.js +1 -1
- package/src/features/order/order.schema.js +1 -1
- package/src/features/order/order.service.js +1 -1
- package/src/features/order/recipient.schema.js +1 -1
- package/src/features/organization/legal-entity.schema.js +1 -1
- package/src/features/organization/organization-configuration.schema.d.ts +2 -0
- package/src/features/organization/organization-configuration.schema.js +1 -1
- package/src/features/organization/organization.handler.js +1 -1
- package/src/features/organization/organization.route.d.ts +5 -0
- package/src/features/organization/organization.route.js +1 -1
- package/src/features/organization/organization.schema.d.ts +2 -0
- package/src/features/organization/organization.schema.js +1 -1
- package/src/features/organization/organization.service.d.ts +4 -0
- package/src/features/organization/organization.service.js +1 -1
- package/src/features/payment/payment-webhook.service.js +1 -1
- package/src/features/payment/payment.handler.js +1 -1
- package/src/features/payment/payment.route.js +1 -1
- package/src/features/payment/payment.schema.js +1 -1
- package/src/features/payment/payment.service.js +1 -1
- package/src/features/payment/stripe.service.js +1 -1
- package/src/features/product/product-modifier.schema.js +1 -1
- package/src/features/product/product.handler.js +1 -1
- package/src/features/product/product.route.js +1 -1
- package/src/features/product/product.schema.js +1 -1
- package/src/features/product/product.service.js +1 -1
- package/src/features/product-category/product-category.handler.js +1 -1
- package/src/features/product-category/product-category.route.js +1 -1
- package/src/features/product-category/product-category.schema.js +1 -1
- package/src/features/product-category/product-category.service.js +1 -1
- package/src/features/reservation/emails/reservation-cancellation.email.js +1 -1
- package/src/features/reservation/emails/reservation-confirmation.email.js +1 -1
- package/src/features/reservation/emails/reservation-email-date.d.ts +2 -0
- package/src/features/reservation/emails/reservation-email-date.js +1 -0
- package/src/features/reservation/emails/reservation-notification.email.js +1 -1
- package/src/features/reservation/emails/reservation-updated.email.js +1 -1
- package/src/features/reservation/reservation.handler.js +1 -1
- package/src/features/reservation/reservation.route.js +1 -1
- package/src/features/reservation/reservation.schema.js +1 -1
- package/src/features/reservation/reservation.service.js +1 -1
- package/src/features/shipping/shipping.handler.js +1 -1
- package/src/features/shipping/shipping.route.js +1 -1
- package/src/features/shipping/shipping.service.js +1 -1
- package/src/features/shipping-method/shipping-method.handler.js +1 -1
- package/src/features/shipping-method/shipping-method.route.js +1 -1
- package/src/features/shipping-method/shipping-method.schema.js +1 -1
- package/src/features/shipping-method/shipping-method.service.js +1 -1
- package/src/features/shipping-method/shipping-zone.schema.js +1 -1
- package/src/features/webhook/webhook.handler.js +1 -1
- package/src/features/webhook/webhook.route.js +1 -1
- package/src/index.js +1 -1
- package/src/integrations/next.js +1 -1
- package/src/schemas/address.schema.js +1 -1
- package/src/schemas/currency.schema.js +1 -1
- package/src/schemas/error.schema.js +1 -1
- package/src/schemas/index.d.ts +1 -0
- package/src/schemas/index.js +1 -1
- package/src/schemas/locales.schema.js +1 -1
- package/src/schemas/number.schema.js +1 -1
- package/src/schemas/pagination.schema.js +1 -1
- package/src/schemas/params.schema.js +1 -1
- package/src/schemas/queries.schema.js +1 -1
- package/src/schemas/time-zone.schema.d.ts +9 -0
- package/src/schemas/time-zone.schema.js +1 -0
package/src/core/lib/prisma.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
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}}));
|
package/src/core/logging/pino.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import o from"pino";export const logger=o({timestamp:o.stdTimeFunctions.isoTime});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const _0x422d2b=_0x9ad8,_0x515720=_0x9ad8;(function(_0x5d4b98,_0x44bb4e){const _0x37c547=_0x9ad8,_0x13b145=_0x9ad8,_0x352526=_0x5d4b98();while(!![]){try{const _0x22389e=-parseInt(_0x37c547(0xc9))/0x1*(parseInt(_0x13b145(0xf8))/0x2)+parseInt(_0x13b145(0x10a))/0x3*(-parseInt(_0x37c547(0xeb))/0x4)+-parseInt(_0x13b145(0xd5))/0x5+parseInt(_0x13b145(0x116))/0x6+parseInt(_0x37c547(0x110))/0x7+-parseInt(_0x37c547(0xed))/0x8*(parseInt(_0x13b145(0xf0))/0x9)+parseInt(_0x13b145(0x10d))/0xa;if(_0x22389e===_0x44bb4e)break;else _0x352526['push'](_0x352526['shift']());}catch(_0x5c1b44){_0x352526['push'](_0x352526['shift']());}}}(_0x4bde,0xeb2c9));import{__awaiter as _0x3e802b}from'tslib';import{Resend as _0xabd830}from'resend';import{getStoredResendConfig as _0x420520}from'../../features/integration/integration-config';import{OrderConfirmationEmail as _0x15df56}from'../../features/order/emails/order-confirmation.email';import _0x2e04ed from'../../features/order/emails/order-notification.email';import{ReservationCancellationEmail as _0x5714e1}from'../../features/reservation/emails/reservation-cancellation.email';import{ReservationConfirmationEmail as _0x10042c}from'../../features/reservation/emails/reservation-confirmation.email';function _0x9ad8(_0x45a4e6,_0x1bf7ca){_0x45a4e6=_0x45a4e6-0xc4;const _0x4bde64=_0x4bde();let _0x9ad84c=_0x4bde64[_0x45a4e6];if(_0x9ad8['NFcjUd']===undefined){var _0x45e22=function(_0x3b6fea){const _0x5bed22='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x521495='',_0x401632='';for(let _0x46fdee=0x0,_0x45ae67,_0x41395c,_0x37db8a=0x0;_0x41395c=_0x3b6fea['charAt'](_0x37db8a++);~_0x41395c&&(_0x45ae67=_0x46fdee%0x4?_0x45ae67*0x40+_0x41395c:_0x41395c,_0x46fdee++%0x4)?_0x521495+=String['fromCharCode'](0xff&_0x45ae67>>(-0x2*_0x46fdee&0x6)):0x0){_0x41395c=_0x5bed22['indexOf'](_0x41395c);}for(let _0xa14832=0x0,_0x5a1669=_0x521495['length'];_0xa14832<_0x5a1669;_0xa14832++){_0x401632+='%'+('00'+_0x521495['charCodeAt'](_0xa14832)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x401632);};_0x9ad8['syTLAP']=_0x45e22,_0x9ad8['SSWPGv']={},_0x9ad8['NFcjUd']=!![];}const _0x3fa3d3=_0x4bde64[0x0],_0x455b1c=_0x45a4e6+_0x3fa3d3,_0x33455c=_0x9ad8['SSWPGv'][_0x455b1c];return!_0x33455c?(_0x9ad84c=_0x9ad8['syTLAP'](_0x9ad84c),_0x9ad8['SSWPGv'][_0x455b1c]=_0x9ad84c):_0x9ad84c=_0x33455c,_0x9ad84c;}import _0x41112e from'../../features/reservation/emails/reservation-notification.email';import{ReservationUpdatedEmail as _0xac48c4}from'../../features/reservation/emails/reservation-updated.email';import{logger as _0x8e2122}from'../logging/pino';class g{constructor(_0x37fb4a){const _0x30fbfd=_0x9ad8,_0x3dc759=_0x9ad8;this[_0x30fbfd(0xea)+_0x3dc759(0xe6)+_0x30fbfd(0xde)]=_0x37fb4a,this[_0x30fbfd(0xe8)]=new Map();}[_0x422d2b(0xfa)+'me'](_0x279f1d){return _0x3e802b(this,void 0x0,void 0x0,function*(){const _0x2daf16=_0x9ad8,_0x5988d4=_0x9ad8,_0x4d419d=_0x420520(this[_0x2daf16(0xea)+'ionRegis'+'try'][_0x2daf16(0xc6)](_0x279f1d,_0x5988d4(0xf1))),_0x3a9a35=JSON[_0x2daf16(0xee)+'y'](_0x4d419d??null),_0xae8cc=this['runtimes'][_0x5988d4(0xc6)](_0x279f1d);if(_0xae8cc?.[_0x2daf16(0xe7)+'e']===_0x3a9a35)return _0xae8cc;const _0x283500={'fromEmail':_0x4d419d?.[_0x5988d4(0x118)+'l'],'resend':_0x4d419d?.[_0x2daf16(0xcc)]?new _0xabd830(_0x4d419d[_0x2daf16(0xcc)]):void 0x0,'signature':_0x3a9a35};return this[_0x5988d4(0xe8)][_0x2daf16(0x112)](_0x279f1d,_0x283500),_0x283500;});}[_0x422d2b(0xd1)+'ddress'](_0x224941,_0x555ebc){return _0x3e802b(this,void 0x0,void 0x0,function*(){const _0x275f4c=_0x9ad8,_0x1edd2e=_0x9ad8;var _0x27d9fa,_0x5ae69e;const _0x17aad3=(_0x5ae69e=(_0x27d9fa=(yield this[_0x275f4c(0xfa)+'me'](_0x224941))[_0x1edd2e(0x118)+'l'])!==null&&_0x27d9fa!==void 0x0?_0x27d9fa:_0x555ebc[_0x1edd2e(0x11b)])!==null&&_0x5ae69e!==void 0x0?_0x5ae69e:_0x275f4c(0xf4)+_0x275f4c(0x104);return _0x555ebc[_0x1edd2e(0xff)]+'\x20<'+_0x17aad3+'>';});}[_0x515720(0xe3)+'l'](_0x7ae635,_0x5ac4bb,_0x257e0d){return _0x3e802b(this,void 0x0,void 0x0,function*(){const _0x34aa9b=_0x9ad8,_0x16a0c6=_0x9ad8,_0x594d5b=yield this[_0x34aa9b(0xfa)+'me'](_0x7ae635);if(!_0x594d5b['resend'])return;const {data:_0x9bfad4,error:_0x3d5d2}=yield _0x594d5b[_0x16a0c6(0xf1)]['emails'][_0x16a0c6(0xe5)](_0x5ac4bb,_0x257e0d);if(_0x3d5d2)throw _0x8e2122[_0x16a0c6(0x103)]({'resendError':_0x3d5d2,'from':_0x5ac4bb[_0x34aa9b(0x10c)],'subject':_0x5ac4bb[_0x16a0c6(0xcf)],'to':_0x5ac4bb['to']},_0x34aa9b(0xdf)+_0x16a0c6(0xc5)+_0x34aa9b(0xcd)+_0x16a0c6(0xfb)),new Error(_0x34aa9b(0xec)+_0x16a0c6(0xe9)+_0x34aa9b(0xf6)+_0x3d5d2['name']+':\x20'+_0x3d5d2[_0x34aa9b(0x10f)]);return _0x8e2122['info']({'emailId':_0x9bfad4?.['id'],'subject':_0x5ac4bb['subject'],'to':_0x5ac4bb['to']},_0x34aa9b(0x119)+_0x34aa9b(0xc4)+'Resend'),_0x9bfad4;});}[_0x515720(0x113)+_0x515720(0xfd)+_0x515720(0xcb)+'il'](_0x1a128d,_0x3d14cd,_0x1008c6,_0x631464){const _0x40f22d={'dfXlP':function(_0x4e1653,_0x184301){return _0x4e1653(_0x184301);}};return _0x3e802b(this,void 0x0,void 0x0,function*(){const _0x202d51=_0x9ad8,_0x36aeaa=_0x9ad8;console[_0x202d51(0x108)](_0x202d51(0x107)+_0x36aeaa(0xd9)+_0x202d51(0xd2)+'on\x20email'+'\x20to\x20'+_0x3d14cd[_0x202d51(0x11b)]),yield this['sendEmai'+'l'](_0x1a128d,{'from':yield this[_0x202d51(0xd1)+_0x36aeaa(0xe2)](_0x1a128d,_0x1008c6),'to':[_0x3d14cd[_0x202d51(0x11b)]],'subject':'Order\x20Co'+_0x202d51(0xd2)+'on\x20-\x20Ord'+_0x36aeaa(0xce)+_0x631464[_0x202d51(0x100)+_0x36aeaa(0xfe)]+'\x20|\x20'+_0x1008c6[_0x202d51(0xff)],'react':_0x40f22d['dfXlP'](_0x15df56,{'user':_0x3d14cd,'organization':_0x1008c6,'order':_0x631464})});});}[_0x515720(0x113)+_0x515720(0x10e)+_0x422d2b(0xcb)+'il'](_0x3c3c28,_0x5445f0,_0x35a584,_0x214245,_0x21e1d4){return _0x3e802b(this,void 0x0,void 0x0,function*(){const _0x1c64b6=_0x9ad8,_0x1aca97=_0x9ad8;console[_0x1c64b6(0x108)](_0x1aca97(0x107)+_0x1aca97(0xf2)+_0x1aca97(0xdc)+_0x1c64b6(0xdd)+'\x20to\x20'+_0x35a584[_0x1aca97(0x11b)]),yield this[_0x1aca97(0xe3)+'l'](_0x3c3c28,{'from':yield this['getFromA'+'ddress'](_0x3c3c28,_0x214245),'to':[_0x35a584[_0x1aca97(0x11b)]],'subject':'You\x20have'+'\x20receive'+_0x1c64b6(0xd8)+_0x1aca97(0x114)+_0x214245[_0x1c64b6(0xff)],'react':_0x2e04ed({'user':_0x5445f0,'organization':_0x214245,'order':_0x21e1d4})});});}[_0x422d2b(0xe0)+_0x422d2b(0x106)+'onfirmat'+_0x515720(0x105)](_0x31caf7,_0x1a13a5){return _0x3e802b(this,void 0x0,void 0x0,function*(){const _0x1e0edf=_0x9ad8,_0xd5a35d=_0x9ad8,_0x2d53f8=_0x1a13a5['user'],_0x4f6c7a=_0x1a13a5[_0x1e0edf(0xc7)+_0x1e0edf(0x102)];_0x2d53f8?.[_0xd5a35d(0x11b)]&&(console[_0xd5a35d(0x108)](_0xd5a35d(0x107)+_0x1e0edf(0xd0)+_0xd5a35d(0x109)+_0x1e0edf(0x115)+_0xd5a35d(0xd6)+'o\x20'+_0x2d53f8[_0x1e0edf(0x11b)]),yield this[_0x1e0edf(0xe3)+'l'](_0x31caf7,{'from':yield this[_0x1e0edf(0xd1)+_0xd5a35d(0xe2)](_0x31caf7,_0x4f6c7a),'to':[_0x2d53f8[_0xd5a35d(0x11b)]],'subject':_0x1e0edf(0xf3)+_0xd5a35d(0xef)+_0x1e0edf(0x115)+_0xd5a35d(0xe4)+_0x4f6c7a[_0xd5a35d(0xff)],'react':_0x10042c({'user':_0x2d53f8,'organization':_0x4f6c7a,'reservation':_0x1a13a5})}));});}[_0x422d2b(0xe0)+'rvationC'+_0x422d2b(0xd7)+_0x515720(0x105)](_0x9adfb7,_0x34f12c){return _0x3e802b(this,void 0x0,void 0x0,function*(){const _0x4e9364=_0x9ad8,_0x23a011=_0x9ad8,_0x2847c1=_0x34f12c[_0x4e9364(0xc8)],_0x111aad=_0x34f12c['organiza'+_0x23a011(0x102)];_0x2847c1?.['email']&&(console[_0x23a011(0x108)](_0x4e9364(0x107)+_0x4e9364(0xd0)+'ion\x20canc'+_0x4e9364(0x11a)+_0x23a011(0xd6)+'o\x20'+_0x2847c1[_0x4e9364(0x11b)]),yield this[_0x4e9364(0xe3)+'l'](_0x9adfb7,{'from':yield this[_0x23a011(0xd1)+_0x23a011(0xe2)](_0x9adfb7,_0x111aad),'to':[_0x2847c1['email']],'subject':_0x23a011(0xf3)+_0x23a011(0xf7)+_0x4e9364(0xd4)+_0x111aad[_0x23a011(0xff)],'react':_0x5714e1({'user':_0x2847c1,'organization':_0x111aad,'reservation':_0x34f12c})}));});}[_0x515720(0xe0)+_0x422d2b(0x10b)+_0x515720(0xda)+_0x422d2b(0x105)](_0xd88216,_0x884dc2,_0x5d5179){return _0x3e802b(this,void 0x0,void 0x0,function*(){const _0x2c054e=_0x9ad8,_0x327b92=_0x9ad8,_0x495e85=_0x5d5179[_0x2c054e(0xc8)],_0x14c93d=_0x5d5179[_0x2c054e(0xc7)+_0x2c054e(0x102)];_0x495e85&&(console[_0x327b92(0x108)](_0x327b92(0x107)+_0x2c054e(0xd0)+_0x2c054e(0xf9)+'fication'+_0x2c054e(0xd6)+'o\x20'+_0x884dc2[_0x2c054e(0x11b)]),yield this[_0x327b92(0xe3)+'l'](_0xd88216,{'from':yield this[_0x327b92(0xd1)+_0x2c054e(0xe2)](_0xd88216,_0x14c93d),'to':[_0x884dc2[_0x327b92(0x11b)]],'subject':'New\x20Rese'+_0x2c054e(0x111)+_0x2c054e(0x117)+'|\x20'+_0x14c93d[_0x327b92(0xff)],'react':_0x41112e({'user':_0x495e85,'member':_0x884dc2,'organization':_0x14c93d,'reservation':_0x5d5179})}));});}[_0x515720(0xe0)+_0x422d2b(0xe1)+_0x515720(0xdb)+_0x422d2b(0xf5)](_0x30d8fe,_0x321cd6){return _0x3e802b(this,void 0x0,void 0x0,function*(){const _0x352251=_0x9ad8,_0x2e64c8=_0x9ad8,_0x4dbe0b=_0x321cd6[_0x352251(0xc8)],_0x297835=_0x321cd6[_0x352251(0xc7)+_0x2e64c8(0x102)];_0x4dbe0b?.[_0x2e64c8(0x11b)]&&(console[_0x352251(0x108)](_0x352251(0x107)+_0x2e64c8(0xd0)+_0x2e64c8(0xca)+'ted\x20emai'+_0x352251(0x101)+_0x4dbe0b['email']),yield this[_0x352251(0xe3)+'l'](_0x30d8fe,{'from':yield this[_0x352251(0xd1)+'ddress'](_0x30d8fe,_0x297835),'to':[_0x4dbe0b[_0x352251(0x11b)]],'subject':_0x352251(0xf3)+_0x2e64c8(0xfc)+_0x352251(0xd3)+_0x297835[_0x352251(0xff)],'react':_0xac48c4({'user':_0x4dbe0b,'organization':_0x297835,'reservation':_0x321cd6})}));});}}export{g as EmailService};function _0x4bde(){const _0x517366=['BwvZC2fNzq','ndmZmda4muzjuu1lAa','CNzHDgLVBIa','C2v0','C2vUze9Yzgu','B3jKzxiGFca','AxjTyxrPB24','ndK4mde1nNH3rNrVrW','uMvXDwvZDca','zNjVBuvTywK','rw1HAwWGC2u','zwXSyxrPB24','zw1HAwW','BNqGD2L0Aca','BYbZzw5Kigu','z2v0','B3jNyw5PEMe','DxnLCG','mu9bB2ziDa','Aw9UihvWzge','yxrPB25fBwe','yxbPs2v5','BwfPBcb3Axq','zxiGiW','C3vIAMvJDa','CMvZzxj2yxq','z2v0rNjVBue','BMzPCM1HDgK','DgvKic0G','zwXSzwqGlsa','odq1mZy0nxfZqMPlBG','igvTywLSihq','yw5JzwXSyxq','zcbHig5LDYa','B3jKzxiGy28','B3rPzMLJyxq','CgrHDgvKrw0','DgLMAwnHDgK','B24Gzw1HAwW','Dhj5','rMfPBgvKihq','C2vUzfjLC2u','CNzHDgLVBLu','zgrYzxnZ','C2vUzevTywK','ic0G','C2vUza','Aw9UuMvNAxm','C2LNBMf0Dxi','CNvUDgLTzxm','zw5KigzHAwW','Aw50zwDYyxq','mte4otq2meroEfDpBa','uMvZzw5Kihm','mJKYntG0mgnTveTWBG','C3rYAw5NAwy','Aw9UienVBMy','mJDZAhLNrKC','CMvZzw5K','B3jKzxiGBM8','uMvZzxj2yxq','Aw5MB0bZAg8','ywLS','zwq6ia','Aw9UienHBMm','mZCXntq1ngjeBfrbAG','Aw9Uig5VDgK','z2v0uNvUDgK','AcbszxnLBMq','Aw9UifvWzge','CKnVBMzPCM0','zuLK','BMfTzq','CMvMzxjLBMm','Bcb0BYa','DgLVBG','zxjYB3i','CgHVC3qUAw8','Aw9Urw1HAwW','CNzHDgLVBKm','u2vUzgLUzYa','Bg9N','Aw9UignVBMy','m3vOwgXdvq','CNzHDgLVBK4','zNjVBq','ndq1nZy3ntbxzM5kDwG','CK5VDgLMAwm'];_0x4bde=function(){return _0x517366;};return _0x4bde();}
|
|
1
|
+
import{__awaiter as r}from"tslib";import{Resend as m}from"resend";import{getStoredResendConfig as l}from"../../features/integration/integration-config";import{OrderConfirmationEmail as a}from"../../features/order/emails/order-confirmation.email";import u from"../../features/order/emails/order-notification.email";import{ReservationCancellationEmail as c}from"../../features/reservation/emails/reservation-cancellation.email";import{ReservationConfirmationEmail as f}from"../../features/reservation/emails/reservation-confirmation.email";import v from"../../features/reservation/emails/reservation-notification.email";import{ReservationUpdatedEmail as h}from"../../features/reservation/emails/reservation-updated.email";import{logger as d}from"../logging/pino";class g{constructor(o){this.integrationRegistry=o,this.runtimes=new Map}getRuntime(o){return r(this,void 0,void 0,function*(){const e=l(this.integrationRegistry.get(o,"resend")),i=JSON.stringify(e??null),t=this.runtimes.get(o);if(t?.signature===i)return t;const n={fromEmail:e?.fromEmail,resend:e?.apiKey?new m(e.apiKey):void 0,signature:i};return this.runtimes.set(o,n),n})}getFromAddress(o,e){return r(this,void 0,void 0,function*(){var i,t;const s=(t=(i=(yield this.getRuntime(o)).fromEmail)!==null&&i!==void 0?i:e.email)!==null&&t!==void 0?t:"info@shophost.io";return`${e.name} <${s}>`})}sendEmail(o,e,i){return r(this,void 0,void 0,function*(){const t=yield this.getRuntime(o);if(!t.resend)return;const{data:n,error:s}=yield t.resend.emails.send(e,i);if(s)throw d.error({resendError:s,from:e.from,subject:e.subject,to:e.to},"Failed to send email with Resend"),new Error(`Resend send failed: ${s.name}: ${s.message}`);return d.info({emailId:n?.id,subject:e.subject,to:e.to},"Email sent with Resend"),n})}sendOrderConfirmationEmail(o,e,i,t){return r(this,void 0,void 0,function*(){console.log(`Sending order confirmation email to ${e.email}`),yield this.sendEmail(o,{from:yield this.getFromAddress(o,i),to:[e.email],subject:`Order Confirmation - Order #${t.referenceId} | ${i.name}`,react:a({user:e,organization:i,order:t})})})}sendOrderNotificationEmail(o,e,i,t,n){return r(this,void 0,void 0,function*(){console.log(`Sending order notification email to ${i.email}`),yield this.sendEmail(o,{from:yield this.getFromAddress(o,t),to:[i.email],subject:`You have received a new order | ${t.name}`,react:u({user:e,organization:t,order:n})})})}sendReservationConfirmationEmail(o,e){return r(this,void 0,void 0,function*(){const i=e.user,t=e.organization;i?.email&&(console.log(`Sending reservation confirmation email to ${i.email}`),yield this.sendEmail(o,{from:yield this.getFromAddress(o,t),to:[i.email],subject:`Reservation Confirmation - ${t.name}`,react:f({user:i,organization:t,reservation:e})}))})}sendReservationCancellationEmail(o,e){return r(this,void 0,void 0,function*(){const i=e.user,t=e.organization;i?.email&&(console.log(`Sending reservation cancellation email to ${i.email}`),yield this.sendEmail(o,{from:yield this.getFromAddress(o,t),to:[i.email],subject:`Reservation Cancelled - ${t.name}`,react:c({user:i,organization:t,reservation:e})}))})}sendReservationNotificationEmail(o,e,i){return r(this,void 0,void 0,function*(){const t=i.user,n=i.organization;t&&(console.log(`Sending reservation notification email to ${e.email}`),yield this.sendEmail(o,{from:yield this.getFromAddress(o,n),to:[e.email],subject:`New Reservation Request | ${n.name}`,react:v({user:t,member:e,organization:n,reservation:i})}))})}sendReservationUpdatedEmail(o,e){return r(this,void 0,void 0,function*(){const i=e.user,t=e.organization;i?.email&&(console.log(`Sending reservation updated email to ${i.email}`),yield this.sendEmail(o,{from:yield this.getFromAddress(o,t),to:[i.email],subject:`Reservation Updated - ${t.name}`,react:h({user:i,organization:t,reservation:e})}))})}}export{g as EmailService};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{bootstrap as p}from"../../bootstrap";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,t={})=>p(t).getOpenAPI31Document(o,{unionPreferredType:"oneOf"});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
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 +1 @@
|
|
|
1
|
-
|
|
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 +1 @@
|
|
|
1
|
-
|
|
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 +1 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{z as i}from"@hono/zod-openapi";export const validateRequiredForDefaultLocale=(...t)=>(n,s)=>{const{translations:e,defaultLocale:o}=n;if(e===void 0&&o===void 0)return;if(!Array.isArray(e)||e.length===0){s.addIssue({code:i.ZodIssueCode.custom,message:"Missing translation for the default locale",path:["translations"]});return}if(typeof o!="string"||!o.trim()){s.addIssue({code:i.ZodIssueCode.custom,message:"Default locale is required when translations are provided",path:["defaultLocale"]});return}const r=e.findIndex(a=>a.locale===o);if(r===-1){s.addIssue({code:i.ZodIssueCode.custom,message:"Missing translation for the default locale",path:["translations"]});return}t.forEach(a=>{const l=e[r][a];(typeof l!="string"||!l.trim())&&s.addIssue({code:i.ZodIssueCode.custom,message:"This field is required",path:["translations",r,a]})})},flattenTranslationData=t=>{if(t==null||typeof t!="object"||t instanceof Date)return t;if(Array.isArray(t))return t.map(s=>flattenTranslationData(s));const n={};for(const[s,e]of Object.entries(t))if(s==="translations"&&Array.isArray(e)&&e.length>0){const o=e[0];if(o&&typeof o=="object")for(const[r,a]of Object.entries(o))r!=="id"&&(n[r]=a)}else typeof e=="object"&&e!==null&&!(e instanceof Date)?n[s]=flattenTranslationData(e):n[s]=e;return n};
|
package/src/db.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export*from"./core/db";export{createPrismaClient}from"./core/lib/prisma";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{__awaiter as r}from"tslib";import{createApiRouter as l}from"../../core/hono/hono";import{accessRoute as d}from"./access.route";export const registerAccessHandlers=a=>{const o=l();return o.openapi(d.getMembers,t=>r(void 0,void 0,void 0,function*(){const n=t.get("auth"),e=t.req.valid("param"),i=t.req.valid("query");yield n.isGranted("read");const s=yield a.getMembers(e.organizationId,Object.assign({},i));return t.json(s,200)})),o.openapi(d.getMember,t=>r(void 0,void 0,void 0,function*(){const n=t.get("auth"),e=t.req.valid("param");yield n.isGranted("read");const i=yield a.getMember(e.organizationId,e.memberId);return t.json(i,200)})),o.openapi(d.updateMemberRole,t=>r(void 0,void 0,void 0,function*(){const n=t.get("auth"),e=t.req.valid("param"),i=t.req.valid("json"),s=yield n.isGranted("update"),u=yield a.updateMemberRole(e.organizationId,e.memberId,s.id,i);return t.json(u,200)})),o.openapi(d.deleteMember,t=>r(void 0,void 0,void 0,function*(){const n=t.get("auth"),e=t.req.valid("param"),i=yield n.isGranted("delete");return yield a.deleteMember(e.organizationId,e.memberId,i.id),t.body(null,204)})),o.openapi(d.createInvitation,t=>r(void 0,void 0,void 0,function*(){const n=t.get("auth"),e=t.req.valid("param"),i=t.req.valid("json"),s=yield n.isGranted("create"),u=yield a.createInvitation(e.organizationId,s.id,i);return t.json(u,201)})),o.openapi(d.getInvitations,t=>r(void 0,void 0,void 0,function*(){const n=t.get("auth"),e=t.req.valid("param");yield n.isGranted("read");const i=yield a.getInvitations(e.organizationId);return t.json(i,200)})),o.openapi(d.deleteInvitation,t=>r(void 0,void 0,void 0,function*(){const n=t.get("auth"),e=t.req.valid("param");return yield n.isGranted("delete"),yield a.deleteInvitation(e.organizationId,e.invitationId),t.body(null,204)})),o.openapi(d.getUserInvitations,t=>r(void 0,void 0,void 0,function*(){const e=yield t.get("auth").getCurrentUser(),i=yield a.getUserInvitations(e.email);return t.json(i,200)})),o.openapi(d.acceptInvitation,t=>r(void 0,void 0,void 0,function*(){const n=t.get("auth"),e=t.req.valid("param"),i=yield n.getCurrentUser(),s=yield a.acceptInvitation(e.invitationId,i.id);return t.json(s,200)})),o.openapi(d.leaveOrganization,t=>r(void 0,void 0,void 0,function*(){const n=t.get("auth"),e=t.req.valid("param"),i=yield n.getCurrentUser();return yield a.leaveOrganization(e.organizationId,i.id),t.body(null,204)})),o};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{z as t}from"@hono/zod-openapi";import{createApiRoute as a}from"../../core/hono/hono";import{ErrorSchema as e,HeaderSchema as n,OrganizationParams as i,PaginationMetaSchema as m,PaginationQuerySchema as c}from"../../schemas";import{CreateInvitationSchema as p,InvitationSchema as r,MemberSchema as o,UpdateMemberRoleSchema as d,UserInvitationSchema as h}from"./access.schema";const s=t.object({memberId:t.string().openapi({description:"ID of the member",example:"clf9876543210abcdef",param:{in:"path",name:"memberId"}}),organizationId:t.string().openapi({description:"ID of the organization",example:"cju0z9k4z0000l1qg5z1z1z1z",param:{in:"path",name:"organizationId"}})}),g=a({description:"Fetches a paginated list of members for an organization",headers:n,method:"GET",operationId:"getMembers",path:"/:organizationId/access/members",pathParams:i,query:c,responses:{200:t.object({list:t.array(o),meta:m}),400:e,401:e},summary:"Get Members",tags:["Access"]}),I=a({headers:n,method:"GET",operationId:"getMember",path:"/:organizationId/access/members/:memberId",pathParams:s,responses:{200:o,401:e,404:e},summary:"Get Member",tags:["Access"]}),v=a({body:d,description:"Updates a member's role in the organization",headers:n,method:"PUT",operationId:"updateMemberRole",path:"/:organizationId/access/members/:memberId",pathParams:s,responses:{200:o,400:e,401:e,404:e},summary:"Update Member Role",tags:["Access"]}),b=a({description:"Removes a member from the organization",headers:n,method:"DELETE",operationId:"deleteMember",path:"/:organizationId/access/members/:memberId",pathParams:s,responses:{204:null,400:e,401:e,404:e},summary:"Delete Member",tags:["Access"]}),z=a({body:p,description:"Creates a new invitation for the organization",headers:n,method:"POST",operationId:"createInvitation",path:"/:organizationId/access/invitations",pathParams:i,responses:{201:r,400:e,401:e},summary:"Create Invitation",tags:["Access"]}),l=a({description:"Fetches a list of pending invitations for an organization",headers:n,method:"GET",operationId:"getInvitations",path:"/:organizationId/access/invitations",pathParams:i,responses:{200:t.array(r),401:e},summary:"Get Invitations",tags:["Access"]}),u=t.object({invitationId:t.string().openapi({description:"ID of the invitation",example:"inv_123",param:{in:"path",name:"invitationId"}})}),P=a({description:"Fetches pending invitations for the currently authenticated user",headers:n,method:"GET",operationId:"getUserInvitations",path:"/access/invitations/me",responses:{200:t.array(h),401:e},summary:"Get User Invitations",tags:["Access"]}),y=a({description:"Accepts a pending invitation and adds the user as a member",headers:n,method:"POST",operationId:"acceptInvitation",path:"/access/invitations/:invitationId/accept",pathParams:u,responses:{200:o,400:e,401:e,404:e},summary:"Accept Invitation",tags:["Access"]}),M=t.object({invitationId:t.string().openapi({description:"ID of the invitation",example:"inv_123",param:{in:"path",name:"invitationId"}}),organizationId:t.string().openapi({description:"ID of the organization",example:"cju0z9k4z0000l1qg5z1z1z1z",param:{in:"path",name:"organizationId"}})}),R=a({description:"Revokes a pending invitation",headers:n,method:"DELETE",operationId:"deleteInvitation",path:"/:organizationId/access/invitations/:invitationId",pathParams:M,responses:{204:null,400:e,401:e,404:e},summary:"Delete Invitation",tags:["Access"]}),f=a({description:"Leave an organization by revoking your own membership",headers:n,method:"POST",operationId:"leaveOrganization",path:"/:organizationId/access/leave",pathParams:i,responses:{204:null,400:e,401:e,404:e},summary:"Leave Organization",tags:["Access"]});export const accessRoute={getMembers:g,getMember:I,updateMemberRole:v,deleteMember:b,createInvitation:z,deleteInvitation:R,getInvitations:l,getUserInvitations:P,acceptInvitation:y,leaveOrganization:f};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{z as e}from"@hono/zod-openapi";export const MemberSchema=e.object({id:e.string().openapi({example:"clf9876543210abcdef",description:"ID of the member"}),organizationId:e.string().openapi({example:"cju0z9k4z0000l1qg5z1z1z1z",description:"ID of the organization"}),userId:e.string().openapi({example:"usr_123",description:"ID of the user"}),role:e.string().openapi({example:"owner",description:"Role of the member in the organization"}),createdAt:e.date(),user:e.object({id:e.string(),firstname:e.string(),lastname:e.string(),email:e.string(),image:e.string().nullable().optional()}).openapi({description:"User details"})}).openapi("Member"),InvitationSchema=e.object({id:e.string().openapi({example:"inv_123",description:"ID of the invitation"}),organizationId:e.string().openapi({example:"cju0z9k4z0000l1qg5z1z1z1z",description:"ID of the organization"}),email:e.string().email().openapi({example:"user@example.com",description:"Email of the invited user"}),role:e.string().nullable().optional().openapi({example:"member",description:"Role assigned to the invitation"}),status:e.string().openapi({example:"pending",description:"Status of the invitation"}),expiresAt:e.date().openapi({description:"Expiration date of the invitation"}),inviterId:e.string().openapi({description:"ID of the user who created the invitation"}),createdAt:e.date().optional()}).openapi("Invitation"),CreateInvitationSchema=e.object({email:e.string().email("A valid email is required").openapi({example:"user@example.com",description:"Email of the user to invite"}),role:e.string().min(1,"Role is required").openapi({example:"member",description:"Role to assign to the invited user"})}).openapi("CreateInvitation"),UpdateMemberRoleSchema=e.object({role:e.string().min(1,"Role is required").openapi({example:"admin",description:"New role for the member"})}).openapi("UpdateMemberRole"),UserInvitationSchema=e.object({id:e.string().openapi({example:"inv_123",description:"ID of the invitation"}),organizationId:e.string().openapi({example:"cju0z9k4z0000l1qg5z1z1z1z",description:"ID of the organization"}),role:e.string().nullable().optional().openapi({example:"member",description:"Role assigned to the invitation"}),expiresAt:e.date().openapi({description:"Expiration date of the invitation"}),organization:e.object({id:e.string(),name:e.string()}).openapi({description:"Organization details"})}).openapi("UserInvitation");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function _0x5668(_0x504e7f,_0x25d9fc){_0x504e7f=_0x504e7f-0x156;const _0x2f3790=_0x2f37();let _0x566806=_0x2f3790[_0x504e7f];if(_0x5668['QiiVFV']===undefined){var _0xfe4e1c=function(_0x246c7b){const _0x3ce523='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0xa606ab='',_0x1ca931='';for(let _0x2f0ab9=0x0,_0x3fcce8,_0x20ea85,_0xb42430=0x0;_0x20ea85=_0x246c7b['charAt'](_0xb42430++);~_0x20ea85&&(_0x3fcce8=_0x2f0ab9%0x4?_0x3fcce8*0x40+_0x20ea85:_0x20ea85,_0x2f0ab9++%0x4)?_0xa606ab+=String['fromCharCode'](0xff&_0x3fcce8>>(-0x2*_0x2f0ab9&0x6)):0x0){_0x20ea85=_0x3ce523['indexOf'](_0x20ea85);}for(let _0x3f581d=0x0,_0x296123=_0xa606ab['length'];_0x3f581d<_0x296123;_0x3f581d++){_0x1ca931+='%'+('00'+_0xa606ab['charCodeAt'](_0x3f581d)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x1ca931);};_0x5668['myiUlt']=_0xfe4e1c,_0x5668['SNcNsi']={},_0x5668['QiiVFV']=!![];}const _0xb8ff4c=_0x2f3790[0x0],_0x549aa8=_0x504e7f+_0xb8ff4c,_0x114a65=_0x5668['SNcNsi'][_0x549aa8];return!_0x114a65?(_0x566806=_0x5668['myiUlt'](_0x566806),_0x5668['SNcNsi'][_0x549aa8]=_0x566806):_0x566806=_0x114a65,_0x566806;}const _0x437e36=_0x5668,_0x447e45=_0x5668;(function(_0x437270,_0x5d7012){const _0x41660a=_0x5668,_0x521e5a=_0x5668,_0x5550b6=_0x437270();while(!![]){try{const _0x2d027a=parseInt(_0x41660a(0x199))/0x1*(parseInt(_0x41660a(0x156))/0x2)+parseInt(_0x41660a(0x166))/0x3+-parseInt(_0x521e5a(0x19e))/0x4*(-parseInt(_0x41660a(0x161))/0x5)+parseInt(_0x521e5a(0x18e))/0x6*(-parseInt(_0x521e5a(0x16c))/0x7)+-parseInt(_0x41660a(0x16d))/0x8*(parseInt(_0x521e5a(0x1bc))/0x9)+-parseInt(_0x41660a(0x185))/0xa+parseInt(_0x41660a(0x170))/0xb;if(_0x2d027a===_0x5d7012)break;else _0x5550b6['push'](_0x5550b6['shift']());}catch(_0x126233){_0x5550b6['push'](_0x5550b6['shift']());}}}(_0x2f37,0x87a45));import{__awaiter as _0x231a97}from'tslib';function _0x2f37(){const _0x4a04d=['D2L0AfbHz2u','zgLUzYbPBNy','mJmYmJm1m21Jsg15zW','zMLUzfvUAxe','y3jLyxrLsw4','AxzL','B2jQzwn0','zsbHBM90Agu','BMCGDg8GDgG','BwjLCIbVzIa','igzPCNn0lG','zgvZyW','Aw5Zzw5ZAxq','ihrOzsbVCMC','CIbTzw1Izxi','CgfYC2u','DgHLigXHC3q','yxjYyxK','yxrPB25Z','ig93BMvYlIa','sw52AxrHDgK','AxaGzMLYC3q','BwjLCG','mJK1nZeXmfDHBuDpAq','ywXYzwfKEsa','ywnJzxb0zwq','BwjLCLjVBgu','igXVBMDLCIa','zwfKEsbLEgK','zgvSzxrLtwu','D25LCNnOAxa','v01KwvG','ndi1mtm4nhHwBLfLvG','zsbSyxn0ig8','B3DUzxi','lIbqCM9TB3q','CIbPCYbHBhi','C3qGB3DUzxi','C3rHDhvZ','BM90igeGBwu','B3jNyw5PEMe','DgHLig9Yz2e','twvTyMvYig4','mZi2nxzjEgj2yG','jhrYyw5Zywm','t2HcsuC','ww91igfYzsa','z2v0sw52Axq','mtKZmZm5nNfpDxPpqq','BgyGzNjVBsa','DgHPCYbVCMC','zMLUzezPCNm','B3qGzM91BMq','CIbMAxjZDc4','zMLUze1HBNK','DgLVBG','DxnLCG','ww91ignHBM4','vgHPCYb1C2u','ig9MihrOAxm','DML0yxrPB24','B3vUza','z2v0twvTyMu','y3jLyxrL','C3rZigzVCIa','Aw52AxrHDgK','D25LCI4Gvhi','BgvHDMvpCMC','AxmGDxnLCG','yxrPB24','t25SEsbWzw4','ignHBIbIzsa','B24GAgfZigu','ig93BMvYC2G','CM9Szq','B24GBM90igy','BNzPDgf0Aw8','zw1IzxiGB2y','ovvsufjvsW','DgLVBIbHBhi','DgLVBKLK','zgvSzxrL','CgvUzgLUzW','q2fUBM90igW','yw5ZzMvYig8','zw1HAwW','BML6yxrPB24','BwvTyMvY','BM90igjLBg8','ChjPC21H','B24Gzg9LCYa','mJu4tuTMywfM','zsbPBNzPDge','zsb5B3vYC2u','zIb0AguGBge','qw4Gywn0Axy','AwWGywrKCMu','AMznDhu','zw1VDMuGDgG','DxbKyxrL','yw5PEMf0Aw8','EhbPCMvK','nuPHsvPfuW','q2fUBM90ihi','C0PjCuq','B3LorKG','ywnJzxb0sw4','mtu5mZmZnLHXDMzIDG','ihrVig93BMu','y291BNq','DgHPCYbLBwe','zxHWAxjLC0e','ig9Yz2fUAxO','n0TXyLvLDq','nJK1mJqWu3jMAunV'];_0x2f37=function(){return _0x4a04d;};return _0x2f37();}import{z as _0x343a7c}from'@hono/zod-openapi';import{HttpException as _0x14615f}from'../../core/exceptions/http-exception';import{PaginationMetaSchema as _0x152122}from'../../schemas';import{InvitationSchema as _0x2a6586,MemberSchema as _0x2e8890,UserInvitationSchema as _0x15d923}from'./access.schema';class c{constructor(_0xeb6597){const _0x2533bf=_0x5668;this[_0x2533bf(0x1c7)]=_0xeb6597;}[_0x437e36(0x1ac)+'rs'](_0x5c6d62,_0xb8bb82){return _0x231a97(this,void 0x0,void 0x0,function*(){const _0x459439=_0x5668,_0x16cf2a=_0x5668,{page:_0x15f74a=0x1,limit:_0x3987ae=0xa,search:_0x2e4634}=_0xb8bb82,[_0x43986a,_0x1c310c]=yield this[_0x459439(0x1c7)][_0x16cf2a(0x1c5)]['paginate']({'orderBy':{'createdAt':'desc'},'where':Object['assign']({'organizationId':_0x5c6d62},_0x2e4634&&{'user':{'OR':[{'firstname':{'contains':_0x2e4634,'mode':_0x16cf2a(0x17a)+_0x459439(0x173)}},{'lastname':{'contains':_0x2e4634,'mode':_0x459439(0x17a)+_0x16cf2a(0x173)}},{'email':{'contains':_0x2e4634,'mode':_0x16cf2a(0x17a)+_0x16cf2a(0x173)}}]}}),'include':{'user':{'select':{'id':!0x0,'firstname':!0x0,'lastname':!0x0,'email':!0x0,'image':!0x0}}}})[_0x16cf2a(0x16e)+'s']({'page':_0x15f74a,'limit':_0x3987ae});return _0x343a7c[_0x16cf2a(0x174)]({'meta':_0x152122,'list':_0x343a7c['array'](_0x2e8890)})[_0x16cf2a(0x17d)]({'meta':_0x1c310c,'list':_0x43986a});});}['getMembe'+'r'](_0x1aabb8,_0x5cfcf4){const _0x5c56bd=_0x437e36,_0x96d0e8={'oyNFH':function(_0x39a9b4,_0x2d1643,_0x5d9720,_0x27e709,_0x4ae94e){return _0x39a9b4(_0x2d1643,_0x5d9720,_0x27e709,_0x4ae94e);}};return _0x96d0e8[_0x5c56bd(0x164)](_0x231a97,this,void 0x0,void 0x0,function*(){const _0x3e47f4=_0x5c56bd,_0x1498fe=_0x5c56bd,_0xeb2d7f=yield this[_0x3e47f4(0x1c7)]['member'][_0x1498fe(0x171)+'ue']({'where':{'id':_0x5cfcf4,'organizationId':_0x1aabb8},'include':{'user':{'select':{'id':!0x0,'firstname':!0x0,'lastname':!0x0,'email':!0x0,'image':!0x0}}}});if(!_0xeb2d7f)throw new _0x14615f(0x194,_0x3e47f4(0x198)+_0x1498fe(0x1a2));return _0x2e8890['parse'](_0xeb2d7f);});}['updateMe'+_0x447e45(0x188)](_0xd3ffa8,_0x29fead,_0x139c2d,_0x54c062){return _0x231a97(this,void 0x0,void 0x0,function*(){const _0x6b6681=_0x5668,_0x436670=_0x5668,_0x46aa53=yield this[_0x6b6681(0x1c7)][_0x436670(0x1c5)][_0x6b6681(0x171)+'ue']({'where':{'id':_0x29fead,'organizationId':_0xd3ffa8},'include':{'user':{'select':{'id':!0x0,'firstname':!0x0,'lastname':!0x0,'email':!0x0,'image':!0x0}}}});if(!_0x46aa53)throw new _0x14615f(0x194,_0x6b6681(0x198)+'ot\x20found');if(_0x46aa53[_0x6b6681(0x1b8)]===_0x436670(0x190)&&_0x54c062['role']!==_0x6b6681(0x190)&&(yield this[_0x436670(0x1c7)][_0x436670(0x1c5)]['count']({'where':{'organizationId':_0xd3ffa8,'role':'owner'}}))<=0x1)throw new _0x14615f(0x190,'Cannot\x20c'+'hange\x20th'+'e\x20role\x20o'+_0x6b6681(0x159)+_0x436670(0x193)+_0x6b6681(0x191)+_0x436670(0x175)+_0x436670(0x17c)+_0x6b6681(0x167)+_0x436670(0x1a3));const _0x5df4b7=yield this[_0x436670(0x1c7)][_0x436670(0x1c5)][_0x436670(0x15e)]({'where':{'id':_0x29fead,'organizationId':_0xd3ffa8},'data':{'role':_0x54c062[_0x436670(0x1b8)]},'include':{'user':{'select':{'id':!0x0,'firstname':!0x0,'lastname':!0x0,'email':!0x0,'image':!0x0}}}});return _0x2e8890[_0x436670(0x17d)](_0x5df4b7);});}[_0x447e45(0x18b)+_0x437e36(0x184)](_0x512bed,_0xe4142a,_0x54de8f){const _0x44ccee=_0x437e36,_0x1592f7=_0x437e36,_0x474de3={'WMdYX':_0x44ccee(0x162)+_0x44ccee(0x15d)+_0x44ccee(0x18f)+_0x1592f7(0x1b0)+_0x44ccee(0x1c2)+_0x1592f7(0x18c)+_0x44ccee(0x178)};return _0x231a97(this,void 0x0,void 0x0,function*(){const _0x17269e=_0x44ccee,_0x1fbb58=_0x44ccee,_0x311a85=yield this[_0x17269e(0x1c7)][_0x1fbb58(0x1c5)][_0x1fbb58(0x171)+'ue']({'where':{'id':_0xe4142a,'organizationId':_0x512bed}});if(!_0x311a85)throw new _0x14615f(0x194,_0x17269e(0x198)+_0x17269e(0x1a2));if(_0x311a85['userId']===_0x54de8f)throw new _0x14615f(0x190,_0x17269e(0x1a7)+'ot\x20remov'+_0x17269e(0x158)+_0x1fbb58(0x19f)+_0x1fbb58(0x197)+_0x1fbb58(0x1c4));if(_0x311a85[_0x1fbb58(0x1b8)]===_0x1fbb58(0x190)&&(yield this[_0x1fbb58(0x1c7)]['member'][_0x17269e(0x168)]({'where':{'organizationId':_0x512bed,'role':_0x17269e(0x190)}}))<=0x1)throw new _0x14615f(0x190,_0x474de3[_0x17269e(0x18d)]);yield this[_0x17269e(0x1c7)]['member'][_0x1fbb58(0x1bf)]({'where':{'id':_0xe4142a,'organizationId':_0x512bed}});});}[_0x447e45(0x1b1)+_0x447e45(0x15f)+'n'](_0x4f2328,_0xf94900){return _0x231a97(this,void 0x0,void 0x0,function*(){const _0x25177e=_0x5668,_0x1b5213=_0x5668,_0x10e7f0=yield this['prisma'][_0x25177e(0x1c5)][_0x25177e(0x1a1)+'t']({'where':{'organizationId':_0x4f2328,'userId':_0xf94900}});if(!_0x10e7f0)throw new _0x14615f(0x194,_0x25177e(0x19c)+_0x25177e(0x195)+_0x25177e(0x177)+_0x1b5213(0x1a0)+_0x1b5213(0x15f)+'n');if(_0x10e7f0[_0x25177e(0x1b8)]===_0x25177e(0x190)&&(yield this[_0x25177e(0x1c7)]['member'][_0x25177e(0x168)]({'where':{'organizationId':_0x4f2328,'role':_0x1b5213(0x190)}}))<=0x1)throw new _0x14615f(0x190,_0x25177e(0x1c1)+'eave\x20as\x20'+_0x1b5213(0x17e)+_0x1b5213(0x181)+'Transfer'+_0x1b5213(0x1b7)+_0x1b5213(0x183)+'.');yield this[_0x1b5213(0x1c7)][_0x1b5213(0x1c5)]['delete']({'where':{'id':_0x10e7f0['id'],'organizationId':_0x4f2328}});});}[_0x437e36(0x172)+'vitation'](_0x23c1f8,_0x3f3ce7,_0x3bdce5){return _0x231a97(this,void 0x0,void 0x0,function*(){const _0x58222d=_0x5668,_0x33f520=_0x5668;if(yield this['prisma'][_0x58222d(0x1af)+'on'][_0x33f520(0x1a1)+'t']({'where':{'organizationId':_0x23c1f8,'email':_0x3bdce5['email'],'status':_0x58222d(0x1c0),'expiresAt':{'gt':new Date()}}}))throw new _0x14615f(0x190,_0x33f520(0x15a)+_0x58222d(0x157)+_0x33f520(0x1bd)+_0x58222d(0x18a)+_0x33f520(0x1ae)+_0x58222d(0x169)+_0x33f520(0x15b)+'ss');if(yield this[_0x58222d(0x1c7)][_0x33f520(0x1c5)][_0x58222d(0x1a1)+'t']({'where':{'organizationId':_0x23c1f8,'user':{'email':_0x3bdce5[_0x33f520(0x1c3)]}}}))throw new _0x14615f(0x190,_0x58222d(0x1a8)+_0x33f520(0x192)+'eady\x20a\x20m'+_0x33f520(0x1bb)+_0x33f520(0x17b)+_0x58222d(0x15f)+'n');const _0x4c994f=yield this[_0x33f520(0x1c7)][_0x33f520(0x1af)+'on'][_0x33f520(0x1ad)]({'data':{'id':crypto['randomUU'+'ID'](),'organizationId':_0x23c1f8,'email':_0x3bdce5[_0x33f520(0x1c3)],'role':_0x3bdce5[_0x58222d(0x1b8)],'status':'pending','inviterId':_0x3f3ce7,'expiresAt':new Date(Date['now']()+0x2760*0x3c*0x3e8)}});return _0x2a6586[_0x33f520(0x17d)](_0x4c994f);});}[_0x437e36(0x19d)+_0x447e45(0x180)](_0x16fa6b){return _0x231a97(this,void 0x0,void 0x0,function*(){const _0x278d81=_0x5668,_0x3039e1=_0x5668,_0x5703e0=yield this[_0x278d81(0x1c7)]['invitati'+'on'][_0x3039e1(0x1a4)]({'where':{'organizationId':_0x16fa6b,'status':_0x278d81(0x1c0)},'orderBy':{'expiresAt':_0x278d81(0x179)}});return _0x343a7c[_0x3039e1(0x17f)](_0x2a6586)['parse'](_0x5703e0);});}['deleteIn'+_0x437e36(0x1aa)](_0x2a60d1,_0x4c17b9){const _0x45a6d0={'OhBIG':function(_0x42f4aa,_0x56fb46){return _0x42f4aa!==_0x56fb46;}};return _0x231a97(this,void 0x0,void 0x0,function*(){const _0x4c460c=_0x5668,_0x4913e1=_0x5668,_0x5c94ec=yield this[_0x4c460c(0x1c7)]['invitati'+'on']['findUniq'+'ue']({'where':{'id':_0x4c17b9,'organizationId':_0x2a60d1}});if(!_0x5c94ec)throw new _0x14615f(0x194,_0x4c460c(0x182)+_0x4913e1(0x1b9)+'ound');if(_0x45a6d0[_0x4c460c(0x19b)](_0x5c94ec[_0x4c460c(0x194)],_0x4913e1(0x1c0)))throw new _0x14615f(0x190,_0x4913e1(0x1b4)+_0x4913e1(0x16f)+'itations'+_0x4913e1(0x1b5)+'revoked');yield this[_0x4913e1(0x1c7)][_0x4913e1(0x1af)+'on'][_0x4c460c(0x1bf)]({'where':{'id':_0x4c17b9}});});}['getUserI'+_0x437e36(0x1ba)+'ns'](_0x23b5fe){return _0x231a97(this,void 0x0,void 0x0,function*(){const _0x3f1fd0=_0x5668,_0x56e46f=_0x5668,_0x4403d6=yield this['prisma'][_0x3f1fd0(0x1af)+'on']['findMany']({'where':{'email':_0x23b5fe,'status':_0x3f1fd0(0x1c0),'expiresAt':{'gt':new Date()}},'include':{'organization':{'select':{'id':!0x0,'name':!0x0}}},'orderBy':{'expiresAt':_0x3f1fd0(0x179)}});return _0x343a7c[_0x3f1fd0(0x17f)](_0x15d923)[_0x3f1fd0(0x17d)](_0x4403d6);});}[_0x447e45(0x165)+_0x447e45(0x1aa)](_0x10da49,_0x482b3b){const _0x379654=_0x447e45,_0x115134=_0x447e45,_0xb60460={'kTyuH':_0x379654(0x182)+'on\x20is\x20no'+_0x379654(0x189)+'pending','jfMtu':_0x379654(0x182)+_0x379654(0x1b6)+_0x379654(0x160),'sJIqD':_0x115134(0x182)+_0x379654(0x1c8)+_0x379654(0x1c6)+_0x115134(0x176)+_0x115134(0x1b2)};return _0x231a97(this,void 0x0,void 0x0,function*(){const _0x538df7=_0x115134,_0x14106f=_0x115134;var _0x5f58cc;const _0xc05bfa=yield this['prisma'][_0x538df7(0x1af)+'on'][_0x538df7(0x171)+'ue']({'where':{'id':_0x10da49}});if(!_0xc05bfa)throw new _0x14615f(0x194,_0x14106f(0x182)+_0x14106f(0x1b9)+_0x538df7(0x1ab));if(_0xc05bfa[_0x538df7(0x194)]!==_0x14106f(0x1c0))throw new _0x14615f(0x190,_0xb60460['kTyuH']);if(_0xc05bfa[_0x538df7(0x16a)+'t']<new Date())throw new _0x14615f(0x190,_0xb60460[_0x14106f(0x15c)]);const _0x366212=yield this[_0x538df7(0x1c7)][_0x14106f(0x1a6)][_0x538df7(0x171)+'ue']({'where':{'id':_0x482b3b}});if(!_0x366212||_0x366212['email']!==_0xc05bfa[_0x14106f(0x1c3)])throw new _0x14615f(0x190,_0xb60460[_0x538df7(0x163)]);if(yield this[_0x14106f(0x1c7)][_0x538df7(0x1c5)]['findFirs'+'t']({'where':{'organizationId':_0xc05bfa[_0x538df7(0x196)+_0x14106f(0x1be)],'userId':_0x482b3b}}))throw new _0x14615f(0x190,_0x14106f(0x19c)+_0x538df7(0x186)+'a\x20member'+_0x538df7(0x1a9)+_0x538df7(0x16b)+_0x538df7(0x1b3));const [_0x2b4ab0]=yield this[_0x14106f(0x1c7)][_0x538df7(0x19a)+_0x538df7(0x1a5)]([this['prisma'][_0x538df7(0x1c5)][_0x538df7(0x1ad)]({'data':{'organizationId':_0xc05bfa[_0x14106f(0x196)+_0x538df7(0x1be)],'userId':_0x482b3b,'role':(_0x5f58cc=_0xc05bfa[_0x538df7(0x1b8)])!==null&&_0x5f58cc!==void 0x0?_0x5f58cc:_0x538df7(0x1c5)},'include':{'user':{'select':{'id':!0x0,'firstname':!0x0,'lastname':!0x0,'email':!0x0,'image':!0x0}}}}),this[_0x538df7(0x1c7)]['invitati'+'on'][_0x14106f(0x15e)]({'where':{'id':_0x10da49},'data':{'status':_0x538df7(0x187)}})]);return _0x2e8890['parse'](_0x2b4ab0);});}}export{c as AccessService};
|
|
1
|
+
import{__awaiter as o}from"tslib";import{z as d}from"@hono/zod-openapi";import{HttpException as n}from"../../core/exceptions/http-exception";import{PaginationMetaSchema as l}from"../../schemas";import{InvitationSchema as h,MemberSchema as u,UserInvitationSchema as w}from"./access.schema";class c{constructor(e){this.prisma=e}getMembers(e,i){return o(this,void 0,void 0,function*(){const{page:t=1,limit:r=10,search:s}=i,[a,m]=yield this.prisma.member.paginate({orderBy:{createdAt:"desc"},where:Object.assign({organizationId:e},s&&{user:{OR:[{firstname:{contains:s,mode:"insensitive"}},{lastname:{contains:s,mode:"insensitive"}},{email:{contains:s,mode:"insensitive"}}]}}),include:{user:{select:{id:!0,firstname:!0,lastname:!0,email:!0,image:!0}}}}).withPages({page:t,limit:r});return d.object({meta:l,list:d.array(u)}).parse({meta:m,list:a})})}getMember(e,i){return o(this,void 0,void 0,function*(){const t=yield this.prisma.member.findUnique({where:{id:i,organizationId:e},include:{user:{select:{id:!0,firstname:!0,lastname:!0,email:!0,image:!0}}}});if(!t)throw new n(404,"Member not found");return u.parse(t)})}updateMemberRole(e,i,t,r){return o(this,void 0,void 0,function*(){const s=yield this.prisma.member.findUnique({where:{id:i,organizationId:e},include:{user:{select:{id:!0,firstname:!0,lastname:!0,email:!0,image:!0}}}});if(!s)throw new n(404,"Member not found");if(s.role==="owner"&&r.role!=="owner"&&(yield this.prisma.member.count({where:{organizationId:e,role:"owner"}}))<=1)throw new n(400,"Cannot change the role of the last owner. Promote another member to owner first.");const a=yield this.prisma.member.update({where:{id:i,organizationId:e},data:{role:r.role},include:{user:{select:{id:!0,firstname:!0,lastname:!0,email:!0,image:!0}}}});return u.parse(a)})}deleteMember(e,i,t){return o(this,void 0,void 0,function*(){const r=yield this.prisma.member.findUnique({where:{id:i,organizationId:e}});if(!r)throw new n(404,"Member not found");if(r.userId===t)throw new n(400,"You cannot remove yourself from the organization");if(r.role==="owner"&&(yield this.prisma.member.count({where:{organizationId:e,role:"owner"}}))<=1)throw new n(400,"Cannot remove the last owner. Transfer ownership first.");yield this.prisma.member.delete({where:{id:i,organizationId:e}})})}leaveOrganization(e,i){return o(this,void 0,void 0,function*(){const t=yield this.prisma.member.findFirst({where:{organizationId:e,userId:i}});if(!t)throw new n(404,"You are not a member of this organization");if(t.role==="owner"&&(yield this.prisma.member.count({where:{organizationId:e,role:"owner"}}))<=1)throw new n(400,"Cannot leave as the last owner. Transfer ownership first.");yield this.prisma.member.delete({where:{id:t.id,organizationId:e}})})}createInvitation(e,i,t){return o(this,void 0,void 0,function*(){if(yield this.prisma.invitation.findFirst({where:{organizationId:e,email:t.email,status:"pending",expiresAt:{gt:new Date}}}))throw new n(400,"An active invitation already exists for this email address");if(yield this.prisma.member.findFirst({where:{organizationId:e,user:{email:t.email}}}))throw new n(400,"This user is already a member of the organization");const a=yield this.prisma.invitation.create({data:{id:crypto.randomUUID(),organizationId:e,email:t.email,role:t.role,status:"pending",inviterId:i,expiresAt:new Date(Date.now()+10080*60*1e3)}});return h.parse(a)})}getInvitations(e){return o(this,void 0,void 0,function*(){const i=yield this.prisma.invitation.findMany({where:{organizationId:e,status:"pending"},orderBy:{expiresAt:"desc"}});return d.array(h).parse(i)})}deleteInvitation(e,i){return o(this,void 0,void 0,function*(){const t=yield this.prisma.invitation.findUnique({where:{id:i,organizationId:e}});if(!t)throw new n(404,"Invitation not found");if(t.status!=="pending")throw new n(400,"Only pending invitations can be revoked");yield this.prisma.invitation.delete({where:{id:i}})})}getUserInvitations(e){return o(this,void 0,void 0,function*(){const i=yield this.prisma.invitation.findMany({where:{email:e,status:"pending",expiresAt:{gt:new Date}},include:{organization:{select:{id:!0,name:!0}}},orderBy:{expiresAt:"desc"}});return d.array(w).parse(i)})}acceptInvitation(e,i){return o(this,void 0,void 0,function*(){var t;const r=yield this.prisma.invitation.findUnique({where:{id:e}});if(!r)throw new n(404,"Invitation not found");if(r.status!=="pending")throw new n(400,"Invitation is no longer pending");if(r.expiresAt<new Date)throw new n(400,"Invitation has expired");const s=yield this.prisma.user.findUnique({where:{id:i}});if(!s||s.email!==r.email)throw new n(400,"Invitation does not belong to this user");if(yield this.prisma.member.findFirst({where:{organizationId:r.organizationId,userId:i}}))throw new n(400,"You are already a member of this organization");const[m]=yield this.prisma.$transaction([this.prisma.member.create({data:{organizationId:r.organizationId,userId:i,role:(t=r.role)!==null&&t!==void 0?t:"member"},include:{user:{select:{id:!0,firstname:!0,lastname:!0,email:!0,image:!0}}}}),this.prisma.invitation.update({where:{id:e},data:{status:"accepted"}})]);return u.parse(m)})}}export{c as AccessService};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{__awaiter as s}from"tslib";import{createApiRouter as d}from"../../core/hono/hono";import{analyticsRoute as p}from"./analytics.route";export const registerAnalyticsHandlers=t=>{const e=d();return e.openapi(p.getOverview,r=>s(void 0,void 0,void 0,function*(){const o=r.get("auth"),i=r.req.valid("param"),a=r.req.valid("query");yield o.isGranted("read");const n=yield t.getOverview(i.organizationId,a);return r.json(n,200)})),e};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{createApiRoute as a}from"../../core/hono/hono";import{ErrorSchema as e,HeaderSchema as r,OrganizationParams as t}from"../../schemas";import{AnalyticsOverviewQuerySchema as i,AnalyticsOverviewSchema as o}from"./analytics.schema";const n=a({description:"Returns dashboard analytics for an organization within a date range.",headers:r,method:"GET",operationId:"getAnalyticsOverview",path:"/:organizationId/analytics/overview",pathParams:t,query:i,responses:{200:o,400:e,401:e,404:e},summary:"Get Analytics Overview",tags:["Analytics"]});export const analyticsRoute={getOverview:n};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{z as e}from"@hono/zod-openapi";import{currency as t}from"../../schemas/currency.schema";import{fulfilmentMethod as n}from"../order/fulfilment.schema";const a=e.enum(["card","blik","paypal","bank_transfer","cash_on_delivery"]).openapi({description:"The payment method used for the order",example:"card"});export const AnalyticsOverviewQuerySchema=e.object({from:e.coerce.date().openapi({description:"Start of the reporting range",example:"2026-01-01T00:00:00.000Z"}),to:e.coerce.date().openapi({description:"End of the reporting range",example:"2026-01-30T23:59:59.999Z"})});const r=e.object({from:e.date(),to:e.date()}).openapi("AnalyticsRange"),o=e.object({currency:t,totalSales:e.number().min(0),paidOrders:e.number().int().min(0),averageOrderValue:e.number().min(0),reservations:e.number().int().min(0),guests:e.number().int().min(0)}).openapi("AnalyticsSummary"),i=e.object({date:e.date(),label:e.string(),totalSales:e.number().min(0),paidOrders:e.number().int().min(0)}).openapi("SalesByDayPoint"),m=e.object({date:e.date(),label:e.string(),reservations:e.number().int().min(0),guests:e.number().int().min(0)}).openapi("ReservationsByDayPoint"),s=e.object({method:a,count:e.number().int().min(0),totalSales:e.number().min(0)}).openapi("PaymentMethodBreakdownItem"),c=e.object({method:n,count:e.number().int().min(0),totalSales:e.number().min(0)}).openapi("FulfilmentBreakdownItem");export const AnalyticsOverviewSchema=e.object({range:r,summary:o,salesByDay:e.array(i),reservationsByDay:e.array(m),paymentMethods:e.array(s),fulfilmentMethods:e.array(c)}).openapi("AnalyticsOverview");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{__awaiter as B}from"tslib";import{eachDayOfInterval as k,endOfDay as E,format as l,startOfDay as I}from"date-fns";import{HttpException as _}from"../../core/exceptions/http-exception";import{AnalyticsOverviewSchema as K}from"./analytics.schema";class P{constructor(o){this.prisma=o}getOverview(o,h){return B(this,void 0,void 0,function*(){var c,u,y,m;const n=I(h.from),r=E(h.to);if(n>r)throw new _(400,"`from` must be before or equal to `to`");const g=yield this.prisma.organization.findFirst({where:{id:o},include:{configuration:!0}});if(!g)throw new _(404,"Organization not found");const[b,x]=yield Promise.all([this.prisma.order.findMany({where:{organizationId:o,deletedAt:null,createdAt:{gte:n,lte:r}},select:{createdAt:!0,cancelledAt:!0,fulfilmentMethod:!0,payment:{select:{method:!0,status:!0,total:!0}}}}),this.prisma.reservation.findMany({where:{organizationId:o,date:{gte:n,lte:r}},select:{date:!0,guests:!0,cancelledAt:!0}})]),S=k({start:n,end:r}),d=S.map(t=>({date:t,label:l(t,"MMM d"),totalSales:0,paidOrders:0})),f=S.map(t=>({date:t,label:l(t,"MMM d"),reservations:0,guests:0})),w=new Map(d.map((t,e)=>[l(t.date,"yyyy-MM-dd"),e])),p=new Map,A=new Map(["delivery","pickup"].map(t=>[t,{method:t,count:0,totalSales:0}]));let v=0,i=0;for(const t of b){const e=t.cancelledAt===null&&((c=t.payment)===null||c===void 0?void 0:c.status)==="succeeded",s=l(t.createdAt,"yyyy-MM-dd"),M=w.get(s);if(e&&t.payment&&M!==void 0){d[M].totalSales+=t.payment.total,d[M].paidOrders+=1,v+=t.payment.total,i+=1;const a=(u=p.get(t.payment.method))!==null&&u!==void 0?u:{method:t.payment.method,count:0,totalSales:0};a.count+=1,a.totalSales+=t.payment.total,p.set(t.payment.method,a)}if(t.cancelledAt===null&&t.fulfilmentMethod){const a=A.get(t.fulfilmentMethod);a&&(a.count+=1,a.totalSales+=(m=(y=t.payment)===null||y===void 0?void 0:y.total)!==null&&m!==void 0?m:0)}}let O=0,D=0;for(const t of x){if(t.cancelledAt)continue;const e=l(t.date,"yyyy-MM-dd"),s=w.get(e);s!==void 0&&(f[s].reservations+=1,f[s].guests+=t.guests,O+=1,D+=t.guests)}return K.parse({range:{from:n,to:r},summary:{currency:g.configuration.defaultCurrency,totalSales:v,paidOrders:i,averageOrderValue:i>0?v/i:0,reservations:O,guests:D},salesByDay:d,reservationsByDay:f,paymentMethods:Array.from(p.values()).sort((t,e)=>e.totalSales-t.totalSales),fulfilmentMethods:Array.from(A.values()).sort((t,e)=>e.totalSales-t.totalSales)})})}}export{P as AnalyticsService};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{__awaiter as p}from"tslib";import{createApiRouter as d}from"../../core/hono/hono";import{cartRoute as s}from"./cart.route";export const registerCartHandlers=o=>{const t=d();return t.openapi(s.getCartData,r=>p(void 0,void 0,void 0,function*(){const a=r.req.valid("param"),e=r.req.valid("json"),i=r.req.valid("query"),n=yield o.getCartData(a.organizationId,e,i);return r.json(n,200)})),t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{z as t}from"@hono/zod-openapi";import{createApiRoute as r}from"../../core/hono/hono";import{CartDataSchema as e,CartSchema as o,ErrorSchema as a,HeaderSchema as m,locale as c,OrganizationParams as s}from"../../schemas";const d=r({body:o,description:"Fetches formatted cart data",headers:m,method:"POST",operationId:"getCartData",path:"/:organizationId/cart",pathParams:s,query:t.object({locale:c.default("en")}),responses:{200:e,400:a,401:a},summary:"Get Formatted Cart",tags:["Cart"]});export const cartRoute={getCartData:d};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{z as t}from"@hono/zod-openapi";import{LocalizedProductSchema as e}from"../product/product.schema";export const CartProductsMappingSchema=t.record(t.string().openapi({example:"clf9876543210abcdef",description:"ID of the product in the cart"}),e),CartItemSchema=t.object({productId:t.string().cuid().openapi({example:"clf9876543210abcdef",description:"ID of the product in the cart"}),quantity:t.number().default(1).optional().openapi({example:2,description:"Quantity of this item in the cart"}),modifierGroups:t.array(t.object({id:t.string().cuid().openapi({example:"clg1234567890abcdef",description:"ID of the modifier group"}),modifiers:t.array(t.object({id:t.string().cuid().openapi({example:"clh9876543210abcdef",description:"ID of the selected modifier"}),quantity:t.number().default(1).openapi({example:1,description:"Quantity of this modifier"})}))}))}).openapi("CartItem"),CartSchema=t.object({items:t.array(CartItemSchema),shippingMethodId:t.string().cuid().optional()}),CartAdjustmentReasonSchema=t.enum(["invalid_product","out_of_stock","insufficient_stock"]).openapi("CartAdjustmentReason"),CartAdjustmentSchema=t.object({productId:t.string().cuid().openapi({example:"clf9876543210abcdef",description:"ID of the affected product"}),modifierGroups:CartItemSchema.shape.modifierGroups.optional(),reason:CartAdjustmentReasonSchema,requestedQuantity:t.number().int().min(0).openapi({example:3,description:"Quantity requested by the customer"}),resolvedQuantity:t.number().int().min(0).openapi({example:1,description:"Quantity accepted after stock normalization"})}).openapi("CartAdjustment"),CartDataSchema=t.object({invalidProductIds:t.array(t.string()),normalizedItems:t.array(CartItemSchema),adjustments:t.array(CartAdjustmentSchema),products:CartProductsMappingSchema,shipping:t.number().optional(),subtotal:t.number(),total:t.number()}),CartConflictSchema=CartDataSchema.extend({message:t.string()}).openapi("CartConflict");
|