@shophost/rest-api 2.0.67 → 2.0.68
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/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 +788 -1
- package/src/core/db/__generated__/client/internal/prismaNamespace.js +1 -1
- package/src/core/db/__generated__/client/internal/prismaNamespaceBrowser.js +1 -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.js +1 -1
- package/src/features/organization/organization.handler.js +1 -1
- package/src/features/organization/organization.route.js +1 -1
- package/src/features/organization/organization.schema.js +1 -1
- 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-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.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/features/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export{registerAnalyticsHandlers}from"./analytics/analytics.handler";export{registerAccessHandlers}from"./access/access.handler";export{registerCartHandlers}from"./cart/cart.handler";export{registerCustomerHandlers}from"./customer/customer.handler";export{registerFileHandlers}from"./file/file.handler";export{registerHealthHandlers}from"./health/health.handler";export{registerIntegrationHandlers}from"./integration/integration.handler";export{registerLocationHandlers}from"./location/location.handler";export{registerManufacturerHandlers}from"./manufacturer/manufacturer.handler";export{registerOrderHandlers}from"./order/order.handler";export{registerOrganizationHandlers}from"./organization/organization.handler";export{registerPaymentHandlers}from"./payment/payment.handler";export{registerProductCategoryHandlers}from"./product-category/product-category.handler";export{registerProductHandlers}from"./product/product.handler";export{registerReservationHandlers}from"./reservation/reservation.handler";export{registerShippingHandlers}from"./shipping/shipping.handler";export{registerShippingMethodHandlers}from"./shipping-method/shipping-method.handler";export{registerWebhookHandlers}from"./webhook/webhook.handler";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{ResendIntegrationStoredConfigSchema as o,StripeIntegrationStoredConfigSchema as r}from"./integration.schema";export const normalizeSecret=e=>{const t=e?.trim();return t||void 0},normalizeEmail=e=>{const t=e?.trim();return t||void 0},normalizeStripePaymentMethods=e=>Array.from(new Set(e.filter(t=>t==="card"||t==="blik"))),parseStripeStoredConfig=e=>{const t=r.safeParse(e);if(t.success)return{paymentMethods:t.data.paymentMethods?normalizeStripePaymentMethods(t.data.paymentMethods):void 0,secretKey:normalizeSecret(t.data.secretKey),webhookSecret:normalizeSecret(t.data.webhookSecret)}},parseResendStoredConfig=e=>{const t=o.safeParse(e);if(t.success)return{apiKey:normalizeSecret(t.data.apiKey),fromEmail:normalizeEmail(t.data.fromEmail)}},getStoredStripeConfig=e=>parseStripeStoredConfig(e?.config),getStoredResendConfig=e=>parseResendStoredConfig(e?.config);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{__awaiter as o}from"tslib";const e=(s,t)=>`${s}:${t}`;class a{constructor(t){this.prisma=t,this.entries=new Map,this.initialLoadPromise=this.loadAll()}loadAll(){return o(this,void 0,void 0,function*(){var t,i;if(!(!((i=(t=this.prisma)===null||t===void 0?void 0:t.integration)===null||i===void 0)&&i.findMany))return;const r=yield this.prisma.integration.findMany();this.entries.clear();for(const n of r)this.entries.set(e(n.organizationId,n.type),n)})}ready(){return o(this,void 0,void 0,function*(){yield this.initialLoadPromise})}get(t,i){if(t)return this.entries.get(e(t,i))}list(t){return[...this.entries.values()].filter(i=>i.organizationId===t).sort((i,r)=>i.type.localeCompare(r.type))}upsert(t){return this.entries.set(e(t.organizationId,t.type),t),t}delete(t,i){this.entries.delete(e(t,i))}}export{a as IntegrationRegistry};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{__awaiter as d}from"tslib";import{createApiRouter as u}from"../../core/hono/hono";import{integrationRoutes as s}from"./integration.route";export const registerIntegrationHandlers=i=>{const a=u();return a.openapi(s.getIntegrations,t=>d(void 0,void 0,void 0,function*(){const o=t.get("auth"),n=t.req.valid("param");yield o.isGranted("read");const e=yield i.getIntegrations(n.organizationId);return t.json(e,200)})),a.openapi(s.upsertIntegration,t=>d(void 0,void 0,void 0,function*(){const o=t.get("auth"),n=t.req.valid("param"),e=t.req.valid("json"),r=yield o.isGranted("update"),p=yield i.upsertIntegration(n.organizationId,n.type,r.id,e);return t.json(p,200)})),a.openapi(s.deleteIntegration,t=>d(void 0,void 0,void 0,function*(){const o=t.get("auth"),n=t.req.valid("param");return yield o.isGranted("update"),yield i.deleteIntegration(n.organizationId,n.type),t.body(null,204)})),a.openapi(s.sendTestEmail,t=>d(void 0,void 0,void 0,function*(){const o=t.get("auth"),n=t.req.valid("param"),e=t.req.valid("json");yield o.isGranted("update");const r=yield i.sendTestEmail(n.organizationId,e.to);return t.json(r,200)})),a.openapi(s.createStripeTestCheckout,t=>d(void 0,void 0,void 0,function*(){const o=t.get("auth"),n=t.req.valid("param"),e=t.req.valid("json"),r=yield o.isGranted("update"),p=yield i.createStripeTestCheckout(n.organizationId,r.email,e.returnUrl);return t.json(p,200)})),a};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{z as i}from"@hono/zod-openapi";import{createApiRoute as t}from"../../core/hono/hono";import{ErrorSchema as e,HeaderSchema as a,OrganizationParams as n}from"../../schemas";import{CreateStripeTestCheckoutResponseSchema as s,CreateStripeTestCheckoutSchema as p,IntegrationSchema as o,IntegrationTypeSchema as g,SendTestEmailResponseSchema as m,SendTestEmailSchema as d,UpsertIntegrationSchema as h}from"./integration.schema";const r=n.extend({type:g.openapi({param:{in:"path",name:"type"}})}),c=t({description:"Fetches integrations configured for an organization",headers:a,method:"GET",operationId:"getIntegrations",path:"/:organizationId/integrations",pathParams:n,responses:{200:i.array(o),400:e,401:e,404:e},summary:"Get Integrations",tags:["Integration"]}),u=t({body:h,description:"Creates or updates an integration configuration",headers:a,method:"PUT",operationId:"upsertIntegration",path:"/:organizationId/integrations/:type",pathParams:r,responses:{200:o,400:e,401:e,404:e},summary:"Upsert Integration",tags:["Integration"]}),I=t({description:"Deletes an integration configuration",headers:a,method:"DELETE",operationId:"deleteIntegration",path:"/:organizationId/integrations/:type",pathParams:r,responses:{204:null,400:e,401:e,404:e},summary:"Delete Integration",tags:["Integration"]}),S=t({body:d,description:"Sends a test email using the configured Resend integration",headers:a,method:"POST",operationId:"sendTestEmail",path:"/:organizationId/integrations/resend/test",pathParams:n,responses:{200:m,400:e,401:e,404:e,500:e},summary:"Send Test Email",tags:["Integration"]}),T=t({body:p,description:"Creates a Stripe Checkout session with mock products to test the configured Stripe integration",headers:a,method:"POST",operationId:"createStripeTestCheckout",path:"/:organizationId/integrations/stripe/test",pathParams:n,responses:{200:s,400:e,401:e,404:e,500:e},summary:"Create Stripe Test Checkout",tags:["Integration"]});export const integrationRoutes={getIntegrations:c,upsertIntegration:u,deleteIntegration:I,sendTestEmail:S,createStripeTestCheckout:T};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function _0x5a46(_0x24e087,_0x231eed){_0x24e087=_0x24e087-0x1b6;const _0x1e377f=_0x1e37();let _0x5a4625=_0x1e377f[_0x24e087];if(_0x5a46['GrgFGD']===undefined){var _0x1fe204=function(_0x49c151){const _0x4234e9='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x256bca='',_0x44f70b='';for(let _0x58d0ed=0x0,_0x327ae4,_0x1560c9,_0x1f9e09=0x0;_0x1560c9=_0x49c151['charAt'](_0x1f9e09++);~_0x1560c9&&(_0x327ae4=_0x58d0ed%0x4?_0x327ae4*0x40+_0x1560c9:_0x1560c9,_0x58d0ed++%0x4)?_0x256bca+=String['fromCharCode'](0xff&_0x327ae4>>(-0x2*_0x58d0ed&0x6)):0x0){_0x1560c9=_0x4234e9['indexOf'](_0x1560c9);}for(let _0x26e069=0x0,_0x4be85b=_0x256bca['length'];_0x26e069<_0x4be85b;_0x26e069++){_0x44f70b+='%'+('00'+_0x256bca['charCodeAt'](_0x26e069)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x44f70b);};_0x5a46['hUFRpu']=_0x1fe204,_0x5a46['UZqLyo']={},_0x5a46['GrgFGD']=!![];}const _0x5089da=_0x1e377f[0x0],_0x18ee43=_0x24e087+_0x5089da,_0x3f3433=_0x5a46['UZqLyo'][_0x18ee43];return!_0x3f3433?(_0x5a4625=_0x5a46['hUFRpu'](_0x5a4625),_0x5a46['UZqLyo'][_0x18ee43]=_0x5a4625):_0x5a4625=_0x3f3433,_0x5a4625;}const _0x4782f2=_0x5a46,_0x3cf677=_0x5a46;(function(_0x1674bc,_0x40446f){const _0xda5f7a=_0x5a46,_0x14e0df=_0x5a46,_0x131be0=_0x1674bc();while(!![]){try{const _0xa8e0f3=parseInt(_0xda5f7a(0x21c))/0x1+parseInt(_0xda5f7a(0x1e7))/0x2+-parseInt(_0x14e0df(0x21f))/0x3*(parseInt(_0xda5f7a(0x20a))/0x4)+parseInt(_0x14e0df(0x241))/0x5*(-parseInt(_0x14e0df(0x1cc))/0x6)+parseInt(_0xda5f7a(0x1cb))/0x7*(-parseInt(_0xda5f7a(0x1cd))/0x8)+parseInt(_0x14e0df(0x23f))/0x9+parseInt(_0xda5f7a(0x1d0))/0xa*(parseInt(_0xda5f7a(0x1ed))/0xb);if(_0xa8e0f3===_0x40446f)break;else _0x131be0['push'](_0x131be0['shift']());}catch(_0x2065e3){_0x131be0['push'](_0x131be0['shift']());}}}(_0x1e37,0xb74db));import{z as _0x256bca}from'@hono/zod-openapi';export const IntegrationTypeSchema=_0x256bca[_0x4782f2(0x1bb)]()['min'](0x1)[_0x3cf677(0x214)]({'example':'stripe','description':_0x3cf677(0x1ba)+'ion\x20type'+_0x4782f2(0x203)}),StripePaymentMethodSchema=_0x256bca['enum']([_0x3cf677(0x222),_0x4782f2(0x231)])['openapi']({'example':_0x3cf677(0x222),'description':_0x4782f2(0x1d2)+_0x4782f2(0x21b)+_0x3cf677(0x1f5)}),StripeIntegrationStoredConfigSchema=_0x256bca[_0x3cf677(0x217)]({'paymentMethods':_0x256bca[_0x4782f2(0x244)](StripePaymentMethodSchema)['max'](0x2)['optional'](),'secretKey':_0x256bca['string']()['trim']()[_0x4782f2(0x20e)](0x1)[_0x3cf677(0x20b)](),'webhookSecret':_0x256bca[_0x3cf677(0x1bb)]()[_0x4782f2(0x1d9)]()['min'](0x1)[_0x4782f2(0x20b)]()})['strict'](),ResendIntegrationStoredConfigSchema=_0x256bca['object']({'apiKey':_0x256bca['string']()['trim']()[_0x3cf677(0x20e)](0x1)['optional'](),'fromEmail':_0x256bca[_0x4782f2(0x1bb)]()['trim']()[_0x4782f2(0x1de)]()[_0x4782f2(0x20b)]()})['strict'](),StripeIntegrationConfigSchema=_0x256bca[_0x4782f2(0x217)]({'paymentMethods':_0x256bca[_0x3cf677(0x244)](StripePaymentMethodSchema)[_0x4782f2(0x229)](0x2)[_0x3cf677(0x214)]({'example':[_0x4782f2(0x222),_0x3cf677(0x231)],'description':'Enabled\x20'+_0x4782f2(0x1d2)+'ayment\x20m'+_0x4782f2(0x250)+'or\x20the\x20o'+'rganizat'+'ion'}),'hasSecretKey':_0x256bca[_0x3cf677(0x1dd)]()['openapi']({'example':!0x0,'description':_0x3cf677(0x1d5)+_0x3cf677(0x24e)+_0x4782f2(0x1d3)+_0x4782f2(0x242)+_0x3cf677(0x23c)+_0x3cf677(0x1d8)}),'hasWebhookSecret':_0x256bca[_0x3cf677(0x1dd)]()['openapi']({'example':!0x0,'description':_0x4782f2(0x1d5)+'the\x20Stri'+_0x3cf677(0x1fc)+'ok\x20signi'+_0x4782f2(0x1c3)+'t\x20has\x20be'+_0x4782f2(0x200)+_0x4782f2(0x1c9)})})[_0x3cf677(0x24b)]()[_0x4782f2(0x214)](_0x4782f2(0x208)+_0x4782f2(0x221)+'nConfig'),UpsertStripeIntegrationConfigSchema=_0x256bca[_0x3cf677(0x217)]({'paymentMethods':_0x256bca['array'](StripePaymentMethodSchema)['max'](0x2)[_0x4782f2(0x214)]({'example':[_0x3cf677(0x222),_0x4782f2(0x231)],'description':_0x3cf677(0x1ef)+'Stripe\x20p'+_0x4782f2(0x21b)+'ethods\x20f'+_0x3cf677(0x1e5)+_0x3cf677(0x24f)+_0x4782f2(0x207)}),'secretKey':_0x256bca[_0x4782f2(0x1bb)]()['trim']()['min'](0x1)[_0x4782f2(0x20b)]()['openapi']({'example':_0x3cf677(0x215)+_0x3cf677(0x205)+'9','description':_0x3cf677(0x1e1)+_0x4782f2(0x247)+_0x3cf677(0x213)+_0x4782f2(0x1e3)+_0x4782f2(0x22c)+'on'}),'webhookSecret':_0x256bca[_0x3cf677(0x1bb)]()[_0x4782f2(0x1d9)]()[_0x3cf677(0x20e)](0x1)[_0x3cf677(0x20b)]()['openapi']({'example':_0x3cf677(0x216)+_0x4782f2(0x1fd),'description':_0x4782f2(0x1c8)+_0x4782f2(0x1f2)+_0x3cf677(0x253)+_0x3cf677(0x1d1)+_0x4782f2(0x1e3)+'ganizati'+'on'})})[_0x4782f2(0x24b)]()[_0x3cf677(0x214)](_0x3cf677(0x1fa)+_0x4782f2(0x226)+_0x4782f2(0x235)+_0x4782f2(0x20f)),ResendIntegrationConfigSchema=_0x256bca[_0x4782f2(0x217)]({'hasApiKey':_0x256bca[_0x3cf677(0x1dd)]()[_0x4782f2(0x214)]({'example':!0x0,'description':'Whether\x20'+_0x3cf677(0x1fe)+_0x3cf677(0x1f7)+'ey\x20has\x20b'+_0x4782f2(0x23c)+_0x3cf677(0x1d8)}),'fromEmail':_0x256bca[_0x4782f2(0x1bb)]()[_0x4782f2(0x1d9)]()['email']()[_0x3cf677(0x20b)]()[_0x4782f2(0x214)]({'example':_0x4782f2(0x228)+'xample.c'+'om','description':_0x4782f2(0x246)+_0x3cf677(0x24a)+_0x4782f2(0x22f)+'ed\x20for\x20t'+_0x4782f2(0x206)+'onal\x20mes'+_0x4782f2(0x23a)})})[_0x4782f2(0x24b)]()[_0x3cf677(0x214)]('ResendIn'+'tegratio'+_0x3cf677(0x22b)),UpsertResendIntegrationConfigSchema=_0x256bca[_0x3cf677(0x217)]({'apiKey':_0x256bca[_0x3cf677(0x1bb)]()[_0x4782f2(0x1d9)]()[_0x4782f2(0x20e)](0x1)[_0x3cf677(0x20b)]()[_0x3cf677(0x214)]({'example':_0x3cf677(0x20d)+_0x3cf677(0x1df),'description':_0x3cf677(0x1cf)+_0x3cf677(0x1e9)+_0x3cf677(0x1e5)+_0x3cf677(0x24f)+'ion'}),'fromEmail':_0x256bca[_0x3cf677(0x1bb)]()[_0x3cf677(0x1d9)]()[_0x4782f2(0x1de)]()[_0x3cf677(0x20b)]()[_0x4782f2(0x214)]({'example':_0x4782f2(0x228)+'xample.c'+'om','description':_0x3cf677(0x246)+_0x4782f2(0x24a)+_0x4782f2(0x22f)+_0x4782f2(0x219)+_0x4782f2(0x206)+_0x4782f2(0x23b)+_0x3cf677(0x23a)})})['strict']()['openapi']('UpsertRe'+_0x4782f2(0x23d)+_0x3cf677(0x235)+'onfig'),IntegrationConfigSchema=_0x256bca[_0x3cf677(0x251)](_0x256bca[_0x3cf677(0x1bb)](),_0x256bca[_0x3cf677(0x1c5)]())[_0x3cf677(0x214)](_0x3cf677(0x1ba)+_0x3cf677(0x249)+'g'),IntegrationSchema=_0x256bca[_0x4782f2(0x217)]({'organizationId':_0x256bca[_0x4782f2(0x1bb)]()[_0x4782f2(0x214)]({'example':_0x3cf677(0x1c2)+'67890abc'+_0x3cf677(0x238),'description':_0x3cf677(0x1d7)+_0x3cf677(0x1f8)}),'type':IntegrationTypeSchema,'config':IntegrationConfigSchema[_0x3cf677(0x214)]({'description':_0x3cf677(0x1c6)+_0x3cf677(0x1eb)+_0x4782f2(0x1b6)+_0x3cf677(0x1da)+_0x3cf677(0x21e)}),'createdAt':_0x256bca[_0x3cf677(0x1ce)]()[_0x3cf677(0x214)]({'description':_0x4782f2(0x1c1)+_0x4782f2(0x218)+_0x4782f2(0x1dc)+_0x3cf677(0x204)+_0x4782f2(0x234)+'ed'}),'updatedAt':_0x256bca[_0x4782f2(0x1ce)]()[_0x3cf677(0x214)]({'description':_0x3cf677(0x1c1)+_0x3cf677(0x218)+_0x4782f2(0x1dc)+_0x4782f2(0x204)+_0x3cf677(0x1e8)+'updated'})})[_0x4782f2(0x214)](_0x4782f2(0x1ba)+_0x4782f2(0x207)),UpsertIntegrationSchema=_0x256bca['object']({'config':_0x256bca[_0x3cf677(0x1c5)]()[_0x4782f2(0x214)]({'example':{'paymentMethods':[_0x3cf677(0x222),_0x3cf677(0x231)],'secretKey':_0x4782f2(0x215)+'12345678'+'9','webhookSecret':_0x3cf677(0x216)+_0x4782f2(0x1fd)},'description':_0x3cf677(0x1ba)+_0x4782f2(0x220)+_0x4782f2(0x1db)+_0x4782f2(0x1d4)+_0x4782f2(0x1c4)+_0x4782f2(0x1c7)+'pends\x20on'+_0x3cf677(0x21a)+_0x3cf677(0x240)+_0x4782f2(0x1f4)})})[_0x4782f2(0x214)](_0x3cf677(0x21d)+_0x3cf677(0x221)+'n'),SendTestEmailSchema=_0x256bca[_0x4782f2(0x217)]({'to':_0x256bca[_0x3cf677(0x1bb)]()['trim']()[_0x3cf677(0x1de)](_0x3cf677(0x243)+_0x3cf677(0x255)+_0x4782f2(0x210)+_0x3cf677(0x1b8))[_0x4782f2(0x214)]({'example':_0x3cf677(0x20c)+_0x3cf677(0x1fb),'description':_0x4782f2(0x233)+_0x3cf677(0x248)+_0x3cf677(0x236)+_0x4782f2(0x212)+_0x4782f2(0x1e4)})})[_0x4782f2(0x24b)]()[_0x4782f2(0x214)](_0x3cf677(0x239)+_0x3cf677(0x1f0)),SendTestEmailResponseSchema=_0x256bca[_0x3cf677(0x217)]({'success':_0x256bca[_0x4782f2(0x1dd)]()['openapi']({'example':!0x0,'description':_0x4782f2(0x1d5)+_0x4782f2(0x1e6)+_0x3cf677(0x232)+_0x3cf677(0x1b7)+_0x4782f2(0x1d6)+_0x4782f2(0x1ea)}),'message':_0x256bca[_0x3cf677(0x1bb)]()[_0x3cf677(0x214)]({'example':_0x4782f2(0x201)+_0x4782f2(0x1ca)+_0x4782f2(0x22d)+'example.'+_0x4782f2(0x22e),'description':_0x3cf677(0x1ec)+_0x4782f2(0x1f1)})})[_0x4782f2(0x214)](_0x4782f2(0x239)+_0x4782f2(0x209)+_0x3cf677(0x1be)),CreateStripeTestCheckoutSchema=_0x256bca[_0x4782f2(0x217)]({'returnUrl':_0x256bca[_0x3cf677(0x1bb)]()[_0x3cf677(0x1f6)]()[_0x4782f2(0x214)]({'example':'https://'+_0x4782f2(0x24c)+_0x4782f2(0x252)+_0x4782f2(0x1f9)+'settings'+_0x4782f2(0x1f3)+'tions/st'+_0x3cf677(0x1bf),'description':'URL\x20to\x20r'+_0x4782f2(0x22a)+_0x4782f2(0x1bc)+_0x3cf677(0x1b9)+_0x4782f2(0x1bd)+_0x3cf677(0x1c0)+_0x4782f2(0x1e2)+_0x3cf677(0x202)+_0x3cf677(0x225)+'d'})})[_0x3cf677(0x24b)]()[_0x4782f2(0x214)](_0x4782f2(0x223)+_0x3cf677(0x237)+_0x3cf677(0x1ee)),CreateStripeTestCheckoutResponseSchema=_0x256bca[_0x3cf677(0x217)]({'redirectUrl':_0x256bca[_0x3cf677(0x1bb)]()[_0x4782f2(0x1f6)]()[_0x4782f2(0x214)]({'example':_0x3cf677(0x211)+'checkout'+_0x4782f2(0x254)+_0x4782f2(0x230)+_0x4782f2(0x245)+_0x4782f2(0x1ff),'description':_0x3cf677(0x23e)+_0x3cf677(0x1c0)+_0x4782f2(0x24d)+'the\x20mock'+_0x4782f2(0x1e0)+_0x3cf677(0x227)})})['openapi'](_0x3cf677(0x223)+_0x4782f2(0x237)+_0x3cf677(0x1ee)+_0x3cf677(0x224));function _0x1e37(){const _0x58cb06=['AxmGy29TCgW','CIb0AguGB3i','C2fNzq','B3iGDgHLig8','DgHLihrLC3q','mtC1odm4uxLNDK1q','yxmGBgfZDca','ueKGA2v5igy','DwXSEq','BNrLz3jHDgK','uMvZDwX0ig0','mJyZodLZAfHjyM0','q2HLy2TVDxq','rw5HyMXLzca','rw1HAwW','zxnZywDL','zwjOB29Rihm','l2LUDgvNCMe','ihr5CguU','zxrOB2q','DxjS','BMqGqvbjigS','DgLVBIbjra','Dc9Hzg1PBI8','vxbZzxj0u3q','BxbSzs5JB20','CguGD2vIAg8','mZq1nJC4oq','DgHLifjLC2u','Df8XmJm','zw4Gy29UzMK','vgvZDcbLBwe','zxrLzcbVCIa','igTLEq','CMf0Aw9UihC','mtiZndu2nZG','CMfUC2fJDgK','Aw9U','u3rYAxbLsw4','rw1HAwXszxm','nde0mZe2s0jfvhnW','B3b0Aw9UywW','DgvZDebLEge','CMvFmtiZndu','BwLU','B25MAwC','y2LWAwvUDca','Ahr0Chm6lY8','DgvZDcbTzxm','ssbRzxKGzM8','B3bLBMfWAq','C2TFBgL2zv8','D2HZzwnFmti','B2jQzwn0','Ccb3AgvUihq','zwqGzM9Yihq','ihrOzsbPBNq','yxLTzw50ig0','mti5nti5mNfQExr5yq','vxbZzxj0sw4','iePtt04','mJrMALDHyue','Aw9UignVBMy','DgvNCMf0Aw8','y2fYza','q3jLyxrLu3q','uMvZCg9UC2u','y2fUy2vSBgu','CMLWzuLUDgu','C3nPB24','B3jKzxjZqgu','Bwf4','zxr1CM4GDg8','BKnVBMzPzW','z2fUAxPHDgK','Dg8GDgvZDea','y29T','zw1HAwWGDxm','y29Tl2mVCge','yMXPAW','igvTywLSihC','uMvJAxbPzw4','yxmGy3jLyxq','z3jHDgLVBKm','zM9YihrOzsa','CMLWzvrLC3q','zgvM','u2vUzfrLC3q','C2fNzxm','B25HBcbTzxm','zwvUignVBMy','C2vUzeLUDgu','u3rYAxbLiem','nZK5odCYm0jSAgLJsW','zwDYyxrPB24','mtuXmgHgtgj6Ca','zxKGAgfZigi','rw50zxiGysa','yxjYyxK','Es9JC190zxm','vMvYAwzPzwq','zwnYzxqGqva','DcbLBwfPBca','Aw9Uq29UzMK','ihnLBMrLCIa','C3rYAwn0','yxbWlNnOB3a','vvjmigzVCIa','DgHLifn0CMK','CMDHBML6yxq','zxrOB2rZigy','CMvJB3jK','Ag9ZDc50zxm','AwDUAw5Nihm','lNn0CMLWzs4','DMfSAwqGCMu','B24Gy29UzMK','yxmGC2vUDca','zw1HAwWU','AguGu3rYAxa','sw50zwDYyxq','C3rYAw5N','igfMDgvYihq','zsb0zxn0igm','Cg9UC2u','CMLWzq','AgvJA291Dca','vgLTzxn0yw0','y2XTmtiZndu','BMCGC2vJCMu','zc4GvMfSAwq','Dw5RBM93BG','u3rVCMvKigK','yxrPB24Gzgu','u3rYAxbLihC','z3vYzwq','AwWGC2vUDca','n2P3s1PMBa','mtaWntzesff5DvG','mJiYmdiWmhDltw91CG','zgf0zq','uMvZzw5Kiee','mZGWrMTHq0HZ','zwnYzxqGzM8','u3rYAxbLiha','CguGqvbjigS','BIbWyxLSB2e','v2HLDgHLCIa','C3vJy2vZC2y','t3jNyw5PEMe','AwD1CMvK','DhjPBq','z3vYyxrPB24','AwD1CMf0Aw8','AguGAw50zwC','yM9VBgvHBG','zw1HAwW','nJC4oq','ihrLC3qGC2u','u3rYAxbLihm'];_0x1e37=function(){return _0x58cb06;};return _0x1e37();}
|
|
1
|
+
import{z as e}from"@hono/zod-openapi";export const IntegrationTypeSchema=e.string().min(1).openapi({example:"stripe",description:"Integration type key"}),StripePaymentMethodSchema=e.enum(["card","blik"]).openapi({example:"card",description:"Stripe payment method"}),StripeIntegrationStoredConfigSchema=e.object({paymentMethods:e.array(StripePaymentMethodSchema).max(2).optional(),secretKey:e.string().trim().min(1).optional(),webhookSecret:e.string().trim().min(1).optional()}).strict(),ResendIntegrationStoredConfigSchema=e.object({apiKey:e.string().trim().min(1).optional(),fromEmail:e.string().trim().email().optional()}).strict(),StripeIntegrationConfigSchema=e.object({paymentMethods:e.array(StripePaymentMethodSchema).max(2).openapi({example:["card","blik"],description:"Enabled Stripe payment methods for the organization"}),hasSecretKey:e.boolean().openapi({example:!0,description:"Whether the Stripe API key has been configured"}),hasWebhookSecret:e.boolean().openapi({example:!0,description:"Whether the Stripe webhook signing secret has been configured"})}).strict().openapi("StripeIntegrationConfig"),UpsertStripeIntegrationConfigSchema=e.object({paymentMethods:e.array(StripePaymentMethodSchema).max(2).openapi({example:["card","blik"],description:"Enabled Stripe payment methods for the organization"}),secretKey:e.string().trim().min(1).optional().openapi({example:"sk_live_123456789",description:"Stripe secret API key for the organization"}),webhookSecret:e.string().trim().min(1).optional().openapi({example:"whsec_123456789",description:"Stripe webhook signing secret for the organization"})}).strict().openapi("UpsertStripeIntegrationConfig"),ResendIntegrationConfigSchema=e.object({hasApiKey:e.boolean().openapi({example:!0,description:"Whether the Resend API key has been configured"}),fromEmail:e.string().trim().email().optional().openapi({example:"orders@example.com",description:"Verified sender email used for transactional messages"})}).strict().openapi("ResendIntegrationConfig"),UpsertResendIntegrationConfigSchema=e.object({apiKey:e.string().trim().min(1).optional().openapi({example:"re_123456789",description:"Resend API key for the organization"}),fromEmail:e.string().trim().email().optional().openapi({example:"orders@example.com",description:"Verified sender email used for transactional messages"})}).strict().openapi("UpsertResendIntegrationConfig"),IntegrationConfigSchema=e.record(e.string(),e.unknown()).openapi("IntegrationConfig"),IntegrationSchema=e.object({organizationId:e.string().openapi({example:"clm1234567890abcdef",description:"Organization ID"}),type:IntegrationTypeSchema,config:IntegrationConfigSchema.openapi({description:"Stored integration configuration JSON"}),createdAt:e.date().openapi({description:"Timestamp when the integration was created"}),updatedAt:e.date().openapi({description:"Timestamp when the integration was last updated"})}).openapi("Integration"),UpsertIntegrationSchema=e.object({config:e.unknown().openapi({example:{paymentMethods:["card","blik"],secretKey:"sk_live_123456789",webhookSecret:"whsec_123456789"},description:"Integration configuration payload. Validation depends on the integration type."})}).openapi("UpsertIntegration"),SendTestEmailSchema=e.object({to:e.string().trim().email("Enter a valid recipient email.").openapi({example:"test@example.com",description:"Recipient email for the test message"})}).strict().openapi("SendTestEmail"),SendTestEmailResponseSchema=e.object({success:e.boolean().openapi({example:!0,description:"Whether the test email was sent successfully"}),message:e.string().openapi({example:"Test email sent to test@example.com",description:"Result message"})}).openapi("SendTestEmailResponse"),CreateStripeTestCheckoutSchema=e.object({returnUrl:e.string().url().openapi({example:"https://app.shophost.test/admin/settings/integrations/stripe",description:"URL to return to after the Stripe test checkout is completed or cancelled"})}).strict().openapi("CreateStripeTestCheckout"),CreateStripeTestCheckoutResponseSchema=e.object({redirectUrl:e.string().url().openapi({example:"https://checkout.stripe.com/c/pay/cs_test_123",description:"Stripe Checkout URL for the mock test session"})}).openapi("CreateStripeTestCheckoutResponse");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const _0x2077b2=_0x1f23,_0x5a279a=_0x1f23;(function(_0x404b2b,_0xcec321){const _0x13a0cd=_0x1f23,_0xbd2c79=_0x1f23,_0x39e7b3=_0x404b2b();while(!![]){try{const _0x28fca0=-parseInt(_0x13a0cd(0x1be))/0x1+parseInt(_0x13a0cd(0x1bb))/0x2+-parseInt(_0xbd2c79(0x18b))/0x3*(-parseInt(_0xbd2c79(0x233))/0x4)+-parseInt(_0xbd2c79(0x205))/0x5*(parseInt(_0x13a0cd(0x1ce))/0x6)+parseInt(_0xbd2c79(0x1df))/0x7+-parseInt(_0xbd2c79(0x21d))/0x8+parseInt(_0xbd2c79(0x207))/0x9*(parseInt(_0xbd2c79(0x223))/0xa);if(_0x28fca0===_0xcec321)break;else _0x39e7b3['push'](_0x39e7b3['shift']());}catch(_0x2e8a34){_0x39e7b3['push'](_0x39e7b3['shift']());}}}(_0x4b7d,0x536bb));import{__awaiter as _0x5583d6}from'tslib';import{HttpException as _0x2e9fac}from'../../core/exceptions/http-exception';import{getStoredResendConfig as _0x424423,normalizeEmail as _0x47c099,normalizeSecret as _0x106957,normalizeStripePaymentMethods as _0x9ebcf0,parseResendStoredConfig as _0x49bb6c,parseStripeStoredConfig as _0x114a97}from'./integration-config';import{IntegrationSchema as _0x433663,ResendIntegrationConfigSchema as _0x51fbf3,StripeIntegrationConfigSchema as _0x5ad53a,UpsertResendIntegrationConfigSchema as _0x446d20,UpsertStripeIntegrationConfigSchema as _0x4e5e67}from'./integration.schema';function _0x1f23(_0x4f8ee0,_0x2f30b2){_0x4f8ee0=_0x4f8ee0-0x17c;const _0x4b7d39=_0x4b7d();let _0x1f23a4=_0x4b7d39[_0x4f8ee0];if(_0x1f23['caeMjs']===undefined){var _0x4f6538=function(_0x32f101){const _0x1b4110='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x7abde9='',_0x5b8279='';for(let _0x296026=0x0,_0x170da2,_0x2ba740,_0x458020=0x0;_0x2ba740=_0x32f101['charAt'](_0x458020++);~_0x2ba740&&(_0x170da2=_0x296026%0x4?_0x170da2*0x40+_0x2ba740:_0x2ba740,_0x296026++%0x4)?_0x7abde9+=String['fromCharCode'](0xff&_0x170da2>>(-0x2*_0x296026&0x6)):0x0){_0x2ba740=_0x1b4110['indexOf'](_0x2ba740);}for(let _0xb87fa=0x0,_0x2ff1ad=_0x7abde9['length'];_0xb87fa<_0x2ff1ad;_0xb87fa++){_0x5b8279+='%'+('00'+_0x7abde9['charCodeAt'](_0xb87fa)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x5b8279);};_0x1f23['fSMwaU']=_0x4f6538,_0x1f23['hiymMD']={},_0x1f23['caeMjs']=!![];}const _0x19cb27=_0x4b7d39[0x0],_0x8a5a05=_0x4f8ee0+_0x19cb27,_0x50372a=_0x1f23['hiymMD'][_0x8a5a05];return!_0x50372a?(_0x1f23a4=_0x1f23['fSMwaU'](_0x1f23a4),_0x1f23['hiymMD'][_0x8a5a05]=_0x1f23a4):_0x1f23a4=_0x50372a,_0x1f23a4;}class U{constructor(_0x189307,_0x378d93,_0x5af0c1,_0x587eff){const _0x285a5b=_0x1f23,_0x1b5ab5=_0x1f23;this[_0x285a5b(0x234)]=_0x189307,this['integrat'+_0x285a5b(0x1ea)+_0x1b5ab5(0x187)]=_0x378d93,this[_0x1b5ab5(0x1ff)+'vice']=_0x5af0c1,this[_0x285a5b(0x1af)+_0x285a5b(0x211)]=_0x587eff;}[_0x2077b2(0x1b6)+'Config'](_0x316a8e,_0x3ca2e2){const _0x5699af=_0x2077b2,_0x22c1ff=_0x2077b2;var _0x1f2dd8;switch(_0x316a8e){case'stripe':{const _0x3ca230=_0x114a97(_0x3ca2e2);return _0x5ad53a[_0x5699af(0x199)]({'paymentMethods':(_0x1f2dd8=_0x3ca230?.[_0x22c1ff(0x201)+_0x22c1ff(0x1d8)])!==null&&_0x1f2dd8!==void 0x0?_0x1f2dd8:[],'hasSecretKey':!!_0x3ca230?.[_0x22c1ff(0x217)+'y'],'hasWebhookSecret':!!_0x3ca230?.[_0x22c1ff(0x231)+'ecret']});}case _0x22c1ff(0x1b9):{const _0x40713f=_0x49bb6c(_0x3ca2e2);return _0x51fbf3[_0x5699af(0x199)]({'hasApiKey':!!_0x40713f?.['apiKey'],'fromEmail':_0x40713f?.['fromEmai'+'l']});}default:return _0x3ca2e2&&typeof _0x3ca2e2==_0x22c1ff(0x22c)&&!Array[_0x22c1ff(0x21c)](_0x3ca2e2)?_0x3ca2e2:{};}}[_0x5a279a(0x1b6)+'Integrat'+_0x5a279a(0x1c9)](_0x254459){const _0x29327e=_0x2077b2,_0x43c7ef=_0x2077b2;return _0x433663[_0x29327e(0x199)](Object[_0x29327e(0x21a)](Object[_0x29327e(0x21a)]({},_0x254459),{'config':this[_0x43c7ef(0x1b6)+_0x29327e(0x17c)](_0x254459[_0x43c7ef(0x1c1)],_0x254459[_0x29327e(0x1a5)])}));}[_0x5a279a(0x222)+_0x5a279a(0x1da)+_0x5a279a(0x1c8)](_0x223876){return _0x5583d6(this,void 0x0,void 0x0,function*(){const _0x568ce0=_0x1f23,_0xd0c6c1=_0x1f23;if(!(yield this[_0x568ce0(0x234)]['organiza'+_0xd0c6c1(0x22d)][_0xd0c6c1(0x1dd)+'ue']({'where':{'id':_0x223876,'deletedAt':null},'select':{'id':!0x0}})))throw new _0x2e9fac(0x194,_0x568ce0(0x1a3)+_0xd0c6c1(0x1b5)+_0x568ce0(0x1d2));});}[_0x2077b2(0x1e0)+_0x2077b2(0x17c)](_0x18ff68,_0x11877e,_0x339167){const _0x162520=_0x2077b2,_0x2094fc=_0x2077b2,_0x39d66a={'kxCCl':function(_0x4bdac8,_0x51f822){return _0x4bdac8===_0x51f822;}};var _0x7d619b,_0x31fac4,_0x458b86,_0x5406f4,_0x415c8c,_0x5bf965,_0x2bb901,_0x2fa545;switch(_0x18ff68){case _0x162520(0x1cb):{const _0x55f762=_0x4e5e67[_0x162520(0x1ae)+'e'](_0x11877e);if(!_0x55f762['success'])throw new _0x2e9fac(0x190,(_0x31fac4=(_0x7d619b=_0x55f762[_0x2094fc(0x230)][_0x162520(0x1fd)][0x0])===null||_0x7d619b===void 0x0?void 0x0:_0x7d619b['message'])!==null&&_0x31fac4!==void 0x0?_0x31fac4:_0x2094fc(0x1b8)+_0x2094fc(0x237)+_0x162520(0x1e5)+_0x162520(0x22d));const _0x35e253=_0x114a97(_0x339167),_0x4760cc=(_0x458b86=_0x106957(_0x55f762['data'][_0x162520(0x217)+'y']))!==null&&_0x458b86!==void 0x0?_0x458b86:_0x35e253?.[_0x162520(0x217)+'y'],_0x564cf4=(_0x5406f4=_0x106957(_0x55f762['data'][_0x2094fc(0x231)+_0x162520(0x200)]))!==null&&_0x5406f4!==void 0x0?_0x5406f4:_0x35e253?.['webhookS'+_0x2094fc(0x200)];if(!_0x4760cc)throw new _0x2e9fac(0x190,'Stripe\x20A'+_0x162520(0x1a8)+_0x162520(0x17f)+'ed');if(!_0x564cf4)throw new _0x2e9fac(0x190,'Stripe\x20w'+'ebhook\x20s'+_0x162520(0x21e)+_0x2094fc(0x1c4)+'d');return{'paymentMethods':_0x9ebcf0(_0x55f762[_0x2094fc(0x228)][_0x2094fc(0x201)+_0x2094fc(0x1d8)]),'secretKey':_0x4760cc,'webhookSecret':_0x564cf4};}case'resend':{const _0x287072=_0x446d20[_0x162520(0x1ae)+'e'](_0x11877e);if(!_0x287072['success'])throw new _0x2e9fac(0x190,(_0x5bf965=_0x39d66a[_0x2094fc(0x1ec)](_0x415c8c=_0x287072[_0x162520(0x230)]['issues'][0x0],null)||_0x415c8c===void 0x0?void 0x0:_0x415c8c[_0x2094fc(0x20a)])!==null&&_0x5bf965!==void 0x0?_0x5bf965:_0x2094fc(0x1b8)+_0x162520(0x1e4)+_0x162520(0x1e5)+_0x2094fc(0x22d));const _0x59ad48=_0x49bb6c(_0x339167),_0x372ecc=(_0x2bb901=_0x106957(_0x287072[_0x2094fc(0x228)][_0x162520(0x1ab)]))!==null&&_0x2bb901!==void 0x0?_0x2bb901:_0x59ad48?.[_0x2094fc(0x1ab)],_0x4dca84=(_0x2fa545=_0x47c099(_0x287072[_0x162520(0x228)]['fromEmai'+'l']))!==null&&_0x2fa545!==void 0x0?_0x2fa545:_0x59ad48?.[_0x162520(0x215)+'l'];if(!_0x372ecc)throw new _0x2e9fac(0x190,_0x162520(0x220)+_0x2094fc(0x1a8)+'s\x20requir'+'ed');if(!_0x4dca84)throw new _0x2e9fac(0x190,_0x2094fc(0x1b3)+'ender\x20em'+_0x162520(0x1ee)+_0x2094fc(0x1b4));return{'apiKey':_0x372ecc,'fromEmail':_0x4dca84};}default:throw new _0x2e9fac(0x190,_0x162520(0x1b2)+_0x162520(0x1f7)+_0x162520(0x1f6)+_0x162520(0x1a7)+_0x18ff68);}}['getInteg'+_0x2077b2(0x229)](_0x5ebe42){const _0xcdcd0f=_0x5a279a,_0x38f5dc={'bCwNc':function(_0x17afca,_0x1172c8,_0x3fd574,_0x986bc4,_0x4f4c75){return _0x17afca(_0x1172c8,_0x3fd574,_0x986bc4,_0x4f4c75);}};return _0x38f5dc[_0xcdcd0f(0x226)](_0x5583d6,this,void 0x0,void 0x0,function*(){const _0x54ceff=_0xcdcd0f,_0x30fb64=_0xcdcd0f;return yield this['ensureOr'+_0x54ceff(0x1da)+_0x30fb64(0x1c8)](_0x5ebe42),this[_0x30fb64(0x20c)+_0x30fb64(0x1ea)+_0x54ceff(0x187)][_0x30fb64(0x21b)](_0x5ebe42)['map'](_0x1b2282=>this[_0x30fb64(0x1b6)+'Integrat'+_0x54ceff(0x1c9)](_0x1b2282));});}[_0x5a279a(0x203)+_0x2077b2(0x192)+'n'](_0x336850,_0x438f51,_0x4eac27,_0x45437f){return _0x5583d6(this,void 0x0,void 0x0,function*(){const _0x48b4f2=_0x1f23,_0x1438ee=_0x1f23;yield this[_0x48b4f2(0x222)+'ganizati'+'onExists'](_0x336850);const _0xe27007=this[_0x1438ee(0x20c)+_0x48b4f2(0x1ea)+_0x1438ee(0x187)][_0x1438ee(0x1eb)](_0x336850,_0x438f51),_0x4c42c8=this[_0x1438ee(0x1e0)+'Config'](_0x438f51,_0x45437f[_0x48b4f2(0x1a5)],_0xe27007?.[_0x1438ee(0x1a5)]),_0x354903=yield this[_0x1438ee(0x234)][_0x1438ee(0x20c)+_0x1438ee(0x1c9)][_0x48b4f2(0x1e7)]({'where':{'organizationId_type':{'organizationId':_0x336850,'type':_0x438f51}},'update':{'config':_0x4c42c8,'updatedBy':_0x4eac27},'create':{'organization':{'connect':{'id':_0x336850}},'type':_0x438f51,'config':_0x4c42c8,'createdBy':_0x4eac27,'updatedBy':_0x4eac27}});return this['integrat'+_0x48b4f2(0x1ea)+_0x48b4f2(0x187)][_0x48b4f2(0x1e7)](_0x354903),this[_0x1438ee(0x1b6)+'Integrat'+_0x48b4f2(0x1c9)](_0x354903);});}[_0x2077b2(0x22e)+_0x2077b2(0x192)+'n'](_0x4c0eed,_0x4598c4){const _0x386c5f={'dnlGX':function(_0x5935b6,_0x4c831b){return _0x5935b6===_0x4c831b;}};return _0x5583d6(this,void 0x0,void 0x0,function*(){const _0x363d8d=_0x1f23,_0x47eab5=_0x1f23;if(yield this[_0x363d8d(0x222)+_0x47eab5(0x1da)+_0x47eab5(0x1c8)](_0x4c0eed),_0x386c5f[_0x47eab5(0x1cf)]((yield this['prisma']['integrat'+_0x363d8d(0x1c9)][_0x47eab5(0x208)+'ny']({'where':{'organizationId':_0x4c0eed,'type':_0x4598c4}}))[_0x47eab5(0x194)],0x0))throw new _0x2e9fac(0x194,_0x363d8d(0x1f8)+_0x47eab5(0x1f4)+_0x363d8d(0x1a6));this[_0x363d8d(0x20c)+_0x47eab5(0x1ea)+_0x47eab5(0x187)][_0x47eab5(0x1c7)](_0x4c0eed,_0x4598c4);});}[_0x2077b2(0x17d)+_0x5a279a(0x20d)](_0xbee430,_0x24972f){const _0xa533fb=_0x5a279a,_0x4e11bf=_0x5a279a,_0x165026={'EtMKp':'</p>','yVYmM':_0xa533fb(0x185)+_0xa533fb(0x230)};return _0x5583d6(this,void 0x0,void 0x0,function*(){const _0x223e05=_0x4e11bf,_0x1a4d2a=_0x4e11bf,_0x56db85=yield this[_0x223e05(0x234)][_0x223e05(0x190)+_0x223e05(0x22d)][_0x1a4d2a(0x1dd)+'ue']({'where':{'id':_0xbee430,'deletedAt':null},'select':{'id':!0x0,'name':!0x0,'email':!0x0}});if(!_0x56db85)throw new _0x2e9fac(0x194,'Organiza'+_0x223e05(0x1b5)+_0x1a4d2a(0x1d2));const _0x19f0ec=this[_0x1a4d2a(0x20c)+_0x1a4d2a(0x1ea)+_0x1a4d2a(0x187)]['get'](_0xbee430,'resend'),_0x233000=_0x424423(_0x19f0ec);if(!_0x233000?.[_0x1a4d2a(0x1ab)])throw new _0x2e9fac(0x190,_0x223e05(0x220)+'PI\x20key\x20i'+_0x1a4d2a(0x18a)+'nfigured'+_0x1a4d2a(0x1e9)+_0x223e05(0x236)+_0x223e05(0x202)+_0x1a4d2a(0x232));if(!_0x233000[_0x223e05(0x215)+'l'])throw new _0x2e9fac(0x190,'Sender\x20e'+_0x223e05(0x1e1)+_0x223e05(0x1e8)+'igured.\x20'+_0x223e05(0x1c6)+_0x223e05(0x1f9)+_0x223e05(0x213)+'st.');try{return yield this[_0x1a4d2a(0x1ff)+_0x1a4d2a(0x1a0)][_0x223e05(0x20b)+'l'](_0xbee430,{'from':_0x56db85[_0x223e05(0x1d9)]+'\x20<'+_0x233000[_0x223e05(0x215)+'l']+'>','to':[_0x24972f],'subject':_0x223e05(0x1bc)+_0x223e05(0x206)+_0x56db85[_0x223e05(0x1d9)],'html':[_0x223e05(0x18e)+_0x1a4d2a(0x1b7)+_0x223e05(0x1de)+_0x223e05(0x1f2)+_0x1a4d2a(0x188)+'BlinkMac'+_0x1a4d2a(0x1a1)+_0x223e05(0x1d5)+_0x223e05(0x1a9)+'Roboto,\x20'+_0x223e05(0x210)+_0x223e05(0x1fe)+'width:\x205'+'60px;\x20ma'+_0x1a4d2a(0x191)+_0x223e05(0x1dc)+_0x223e05(0x189)+_0x223e05(0x1ad)+_0x223e05(0x181),_0x223e05(0x219)+'e=\x22font-'+_0x1a4d2a(0x1ed)+_0x1a4d2a(0x1d0)+'-weight:'+'\x20600;\x20co'+_0x223e05(0x1ac)+_0x1a4d2a(0x239)+'rgin:\x200\x20'+_0x223e05(0x182)+_0x1a4d2a(0x227)+_0x1a4d2a(0x204)+_0x1a4d2a(0x1d3)+_0x223e05(0x1e2)+'1>','<p\x20style'+_0x223e05(0x1bf)+'ize:\x2014p'+_0x1a4d2a(0x224)+_0x223e05(0x22f)+'1.6;\x20col'+'or:\x20#6b7'+'280;\x20mar'+_0x223e05(0x183)+_0x1a4d2a(0x1c3),_0x223e05(0x19c)+_0x223e05(0x221)+'mail\x20sen'+_0x1a4d2a(0x18f)+_0x223e05(0x23a)+_0x1a4d2a(0x1cd)+'lor:\x20#11'+_0x223e05(0x19d)+_0x56db85[_0x1a4d2a(0x1d9)]+(_0x1a4d2a(0x19b)+_0x1a4d2a(0x1c2)+_0x1a4d2a(0x193)+_0x1a4d2a(0x1fb)+_0x223e05(0x1bd)+_0x223e05(0x1a2)+_0x223e05(0x195)+_0x223e05(0x1ba)+_0x1a4d2a(0x18d)+'.'),_0x1a4d2a(0x1cc),'<hr\x20styl'+_0x1a4d2a(0x22b)+'r:\x20none;'+_0x223e05(0x18c)+_0x1a4d2a(0x1f3)+_0x223e05(0x1ca)+_0x223e05(0x196)+_0x223e05(0x1ef)+_0x223e05(0x1f0)+_0x223e05(0x1f1),_0x1a4d2a(0x19e)+_0x223e05(0x1bf)+_0x1a4d2a(0x19f)+'x;\x20color'+_0x223e05(0x1c0)+_0x1a4d2a(0x1a4)+_0x223e05(0x214),_0x1a4d2a(0x1e3)+_0x1a4d2a(0x218)+_0x1a4d2a(0x197)+_0x223e05(0x184)+_0x1a4d2a(0x180)+_0x233000[_0x223e05(0x215)+'l'],_0x165026[_0x223e05(0x235)],'</div>'][_0x1a4d2a(0x225)]('')}),{'success':!0x0,'message':_0x223e05(0x1d6)+_0x223e05(0x1d7)+_0x223e05(0x1c5)+_0x24972f};}catch(_0x590afe){const _0x814edc=_0x590afe instanceof Error?_0x590afe['message']:_0x165026[_0x1a4d2a(0x19a)];throw new _0x2e9fac(0x1f4,_0x223e05(0x1e6)+_0x1a4d2a(0x209)+_0x1a4d2a(0x1fa)+_0x223e05(0x238)+_0x814edc);}});}[_0x2077b2(0x1db)+_0x5a279a(0x20e)+_0x5a279a(0x1f5)](_0xee4fa3,_0x392456,_0x2db58e){return _0x5583d6(this,void 0x0,void 0x0,function*(){const _0xb09bff=_0x1f23,_0x5755c7=_0x1f23,_0x3e0065=yield this[_0xb09bff(0x234)][_0xb09bff(0x190)+_0xb09bff(0x22d)][_0x5755c7(0x1dd)+'ue']({'where':{'id':_0xee4fa3,'deletedAt':null},'select':{'id':!0x0,'name':!0x0,'configuration':{'select':{'defaultCurrency':!0x0}}}});if(!_0x3e0065)throw new _0x2e9fac(0x194,_0xb09bff(0x1a3)+'tion\x20not'+_0x5755c7(0x1d2));try{const _0x1cd57b=yield this[_0x5755c7(0x1af)+_0xb09bff(0x211)][_0x5755c7(0x1b1)+_0x5755c7(0x20f)+_0x5755c7(0x212)+'n'](_0xee4fa3,{'cancelUrl':_0x2db58e,'customerEmail':_0x392456,'defaultCurrency':_0x3e0065[_0xb09bff(0x22a)+'ation'][_0x5755c7(0x1b0)+'urrency'],'organizationName':_0x3e0065[_0x5755c7(0x1d9)],'successUrl':_0x2db58e});if(!_0x1cd57b[_0x5755c7(0x1fc)])throw new _0x2e9fac(0x1f4,_0xb09bff(0x17e)+'id\x20not\x20r'+_0xb09bff(0x198)+_0xb09bff(0x1aa)+_0x5755c7(0x21f)+'\x20the\x20tes'+'t\x20sessio'+'n.');return{'redirectUrl':_0x1cd57b[_0xb09bff(0x1fc)]};}catch(_0x43d02c){if(_0x43d02c instanceof _0x2e9fac)throw _0x43d02c;const _0x4f558d=_0x43d02c instanceof Error?_0x43d02c['message']:_0x5755c7(0x185)+_0xb09bff(0x230);throw new _0x2e9fac(0x1f4,_0x5755c7(0x1e6)+_0xb09bff(0x186)+_0xb09bff(0x216)+_0x5755c7(0x1d4)+_0xb09bff(0x1d1)+_0x4f558d);}});}}function _0x4b7d(){const _0x18ced3=['EvzzBu0','pc9ZDhjVBMC','vgHPCYbPCYa','mtGYnZSIpG','phaGC3r5Bgu','AxPLoIaXmNa','DMLJzq','u3LZDgvTrM8','zwDYyxrPB24','t3jNyw5PEMe','zJSGBwfYz2K','y29UzMLN','zM91BMq','DhLWztOG','ueKGA2v5igK','B2uGvuKNlca','y2HLy2TVDxq','yxbPs2v5','Bg9YoIaJmte','mhb4idiWChG','C2fMzvbHCNm','C3rYAxbLu2u','zgvMyxvSDem','y3jLyxrLvgu','vw5ZDxbWB3i','uMvZzw5Kihm','zxf1AxjLza','DgLVBIbUB3q','C2fUAxrPEMu','Bgu9iMzVBNq','sw52ywXPzca','CMvZzw5K','AwD1CMvKigm','nZq0mdqYt2vbwgPY','vgvZDcbfBwe','C2vUzcbPBNq','nJeZodK0svvvsNfv','psjMB250lxm','oIaJownHm2e','DhLWzq','pIb0BYb2zxi','idi0ChG7iJ4','ihjLCxvPCMu','Dg8G','u2f2zsb0Agu','zgvSzxrL','B25fEgLZDhm','Aw9U','ihnVBgLKicm','C3rYAxbL','pc9WpG','DhLSzt0Iy28','mtC4otmZmLHzDMDKuG','zg5Sr1G','ChG7igzVBNq','y2TVDxq6ia','igzVDw5K','B24GAxmGD28','DgvZDcbJAgu','BNqSicDtzwC','vgvZDcbLBwe','AwWGC2vUDca','zxrOB2rZ','BMfTzq','z2fUAxPHDgK','y3jLyxrLu3q','yxv0BZSGCge','zMLUzfvUAxe','lwzHBwLSEtO','mJyXmdKZn0HWBNbRyW','DMfSAwrHDgu','BwfPBcbPCYa','CMTPBMC8l2G','u2vUDcb2Awe','uMvZzw5Kigm','B25MAwD1CMe','rMfPBgvKihq','DxbZzxj0','BM90ignVBMy','lIbtyxzLihq','Aw9UuMvNAxm','z2v0','A3Hdq2W','C2L6ztOGmJa','ywLSigLZihi','BwfYz2LUoIa','mJrWEcaWoYi','ic8+','ic1HChbSzs0','Dg9WoIaXChG','Aw9Uig5VDca','q2HLy2TVDxq','z3jHDgLVBIa','DgvKigLUDgu','sw50zwDYyxq','igLUDgvNCMe','zxn0igvTywK','ihLVDxiGuMu','DxjS','AxnZDwvZ','Awy7ig1HEc0','zw1HAwXtzxi','zwnYzxq','Cgf5BwvUDe0','CMf0Aw9Uigy','DxbZzxj0sw4','BNrLz3jHDgK','nw96EwLuta','AwWGzNjVBsa','ou5fEgTqvW','zgvSzxrLtwe','BYbZzw5Kihq','BwvZC2fNzq','C2vUzevTywK','Aw50zwDYyxq','rw1HAwW','CMLWzvrLC3q','C3rdAgvJA28','C2fUCY1Zzxi','CNzPy2u','DxrtzxnZAw8','DgLVBIbMAxi','BJOGmdSIpG','zNjVBuvTywK','ifn0CMLWzsa','C2vJCMv0s2u','ifnOB3bOB3m','pgGXihn0EwW','yxnZAwDU','BgLZDa','AxnbCNjHEq','mJuZoduZnLbJvvn4BW','zwnYzxqGAxm','ifvstcbMB3i','uMvZzw5Kiee','ysb0zxn0igu','zw5ZDxjLt3i','ndyXodGYmhn4D2fWDG','EdSGBgLUzs0','AM9PBG','yKn3tMm','pKvTywLSigK','zgf0yq','CMf0Aw9UCW','y29UzMLNDxi','zt0IyM9Yzgu','B2jQzwn0','DgLVBG','zgvSzxrLsw4','AgvPz2H0oIa','zxjYB3i','D2vIAg9VA1m','AxjZDc4','ndi2mgTUvw1HzW','ChjPC21H','rxrns3a','AguGAw50zwC','u3rYAxbLigm','BdOG','mtGYnZSGBwe','C3rYB25Nihm','q29UzMLN','C2vUzfrLC3q','u3rYAxbLigq','CYbYzxf1Axi','CJOG','oYi+','mcaXnNb4oYi','z2LUoIaWida','DdSGu2vUzgu','vw5RBM93BIa','BYbJCMvHDgu','Dhj5','C3LZDgvTlca','zgrPBMC6idq','CYbUB3qGy28','mtaYnKPZBLreqW','igjVCMrLCI0','B3jYzwn0BhK','pgrPDIbZDhK','DcbMCM9TidW','B3jNyw5PEMe','CMDPBJOGmca','DgvNCMf0Aw8','Awz5ihrOyxq','y291BNq','igLZignVBMy','ztvLn2vIoYa','DcaMBwLKzg8','zxr1CM4Gysa','CgfYC2u'];_0x4b7d=function(){return _0x18ced3;};return _0x4b7d();}export{U as IntegrationService};
|
|
1
|
+
import{__awaiter as c}from"tslib";import{HttpException as o}from"../../core/exceptions/http-exception";import{getStoredResendConfig as S,normalizeEmail as E,normalizeSecret as v,normalizeStripePaymentMethods as x,parseResendStoredConfig as y,parseStripeStoredConfig as w}from"./integration-config";import{IntegrationSchema as z,ResendIntegrationConfigSchema as k,StripeIntegrationConfigSchema as R,UpsertResendIntegrationConfigSchema as b,UpsertStripeIntegrationConfigSchema as C}from"./integration.schema";class U{constructor(e,i,n,t){this.prisma=e,this.integrationRegistry=i,this.emailService=n,this.stripeService=t}sanitizeConfig(e,i){var n;switch(e){case"stripe":{const t=w(i);return R.parse({paymentMethods:(n=t?.paymentMethods)!==null&&n!==void 0?n:[],hasSecretKey:!!t?.secretKey,hasWebhookSecret:!!t?.webhookSecret})}case"resend":{const t=y(i);return k.parse({hasApiKey:!!t?.apiKey,fromEmail:t?.fromEmail})}default:return i&&typeof i=="object"&&!Array.isArray(i)?i:{}}}sanitizeIntegration(e){return z.parse(Object.assign(Object.assign({},e),{config:this.sanitizeConfig(e.type,e.config)}))}ensureOrganizationExists(e){return c(this,void 0,void 0,function*(){if(!(yield this.prisma.organization.findUnique({where:{id:e,deletedAt:null},select:{id:!0}})))throw new o(404,"Organization not found")})}validateConfig(e,i,n){var t,r,a,l,g,f,m,p;switch(e){case"stripe":{const d=C.safeParse(i);if(!d.success)throw new o(400,(r=(t=d.error.issues[0])===null||t===void 0?void 0:t.message)!==null&&r!==void 0?r:"Invalid Stripe configuration");const s=w(n),u=(a=v(d.data.secretKey))!==null&&a!==void 0?a:s?.secretKey,h=(l=v(d.data.webhookSecret))!==null&&l!==void 0?l:s?.webhookSecret;if(!u)throw new o(400,"Stripe API key is required");if(!h)throw new o(400,"Stripe webhook secret is required");return{paymentMethods:x(d.data.paymentMethods),secretKey:u,webhookSecret:h}}case"resend":{const d=b.safeParse(i);if(!d.success)throw new o(400,(f=(g=d.error.issues[0])===null||g===void 0?void 0:g.message)!==null&&f!==void 0?f:"Invalid Resend configuration");const s=y(n),u=(m=v(d.data.apiKey))!==null&&m!==void 0?m:s?.apiKey,h=(p=E(d.data.fromEmail))!==null&&p!==void 0?p:s?.fromEmail;if(!u)throw new o(400,"Resend API key is required");if(!h)throw new o(400,"Resend sender email is required");return{apiKey:u,fromEmail:h}}default:throw new o(400,`Unsupported integration type: ${e}`)}}getIntegrations(e){return c(this,void 0,void 0,function*(){return yield this.ensureOrganizationExists(e),this.integrationRegistry.list(e).map(n=>this.sanitizeIntegration(n))})}upsertIntegration(e,i,n,t){return c(this,void 0,void 0,function*(){yield this.ensureOrganizationExists(e);const r=this.integrationRegistry.get(e,i),a=this.validateConfig(i,t.config,r?.config),l=yield this.prisma.integration.upsert({where:{organizationId_type:{organizationId:e,type:i}},update:{config:a,updatedBy:n},create:{organization:{connect:{id:e}},type:i,config:a,createdBy:n,updatedBy:n}});return this.integrationRegistry.upsert(l),this.sanitizeIntegration(l)})}deleteIntegration(e,i){return c(this,void 0,void 0,function*(){if(yield this.ensureOrganizationExists(e),(yield this.prisma.integration.deleteMany({where:{organizationId:e,type:i}})).count===0)throw new o(404,"Integration not found");this.integrationRegistry.delete(e,i)})}sendTestEmail(e,i){return c(this,void 0,void 0,function*(){const n=yield this.prisma.organization.findUnique({where:{id:e,deletedAt:null},select:{id:!0,name:!0,email:!0}});if(!n)throw new o(404,"Organization not found");const t=this.integrationRegistry.get(e,"resend"),r=S(t);if(!r?.apiKey)throw new o(400,"Resend API key is not configured. Save the integration first.");if(!r.fromEmail)throw new o(400,"Sender email is not configured. Save the integration first.");try{return yield this.emailService.sendEmail(e,{from:`${n.name} <${r.fromEmail}>`,to:[i],subject:`Test Email from ${n.name}`,html:[`<div style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; max-width: 560px; margin: 0 auto; padding: 40px 20px;">`,'<h1 style="font-size: 20px; font-weight: 600; color: #111827; margin: 0 0 16px;">Email integration is working</h1>','<p style="font-size: 14px; line-height: 1.6; color: #6b7280; margin: 0 0 24px;">',`This is a test email sent from <strong style="color: #111827;">${n.name}</strong> to verify that your Resend integration is configured correctly.`,"</p>",'<hr style="border: none; border-top: 1px solid #e5e7eb; margin: 24px 0;" />','<p style="font-size: 12px; color: #9ca3af; margin: 0;">',`Sent via Shophost · Sender: ${r.fromEmail}`,"</p>","</div>"].join("")}),{success:!0,message:`Test email sent to ${i}`}}catch(a){const l=a instanceof Error?a.message:"Unknown error";throw new o(500,`Failed to send test email: ${l}`)}})}createStripeTestCheckout(e,i,n){return c(this,void 0,void 0,function*(){const t=yield this.prisma.organization.findUnique({where:{id:e,deletedAt:null},select:{id:!0,name:!0,configuration:{select:{defaultCurrency:!0}}}});if(!t)throw new o(404,"Organization not found");try{const r=yield this.stripeService.createTestCheckoutSession(e,{cancelUrl:n,customerEmail:i,defaultCurrency:t.configuration.defaultCurrency,organizationName:t.name,successUrl:n});if(!r.url)throw new o(500,"Stripe did not return a checkout URL for the test session.");return{redirectUrl:r.url}}catch(r){if(r instanceof o)throw r;const a=r instanceof Error?r.message:"Unknown error";throw new o(500,`Failed to create Stripe test checkout: ${a}`)}})}}export{U as IntegrationService};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const _0xdfc160=_0x2122,_0x3098e2=_0x2122;(function(_0x547dad,_0x4a7c48){const _0x33ab56=_0x2122,_0xa1ff5d=_0x2122,_0x141c1b=_0x547dad();while(!![]){try{const _0x180d2a=-parseInt(_0x33ab56(0xb3))/0x1*(parseInt(_0xa1ff5d(0xee))/0x2)+-parseInt(_0x33ab56(0xbf))/0x3*(parseInt(_0x33ab56(0xd7))/0x4)+-parseInt(_0x33ab56(0xde))/0x5+-parseInt(_0x33ab56(0xd1))/0x6*(-parseInt(_0x33ab56(0xc1))/0x7)+parseInt(_0xa1ff5d(0xeb))/0x8*(-parseInt(_0x33ab56(0xc3))/0x9)+parseInt(_0xa1ff5d(0xaf))/0xa+parseInt(_0xa1ff5d(0xe5))/0xb*(parseInt(_0x33ab56(0xd3))/0xc);if(_0x180d2a===_0x4a7c48)break;else _0x141c1b['push'](_0x141c1b['shift']());}catch(_0x53cc88){_0x141c1b['push'](_0x141c1b['shift']());}}}(_0x50c1,0x5f49f));import{__awaiter as _0x43dec3}from'tslib';function _0x2122(_0x3c6397,_0x181ce8){_0x3c6397=_0x3c6397-0xa1;const _0x50c1d0=_0x50c1();let _0x21225c=_0x50c1d0[_0x3c6397];if(_0x2122['ZPSnto']===undefined){var _0x1d6b50=function(_0x499280){const _0x49e457='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x294c98='',_0x49f615='';for(let _0x20979f=0x0,_0x8b8076,_0x1f3282,_0x4ef56e=0x0;_0x1f3282=_0x499280['charAt'](_0x4ef56e++);~_0x1f3282&&(_0x8b8076=_0x20979f%0x4?_0x8b8076*0x40+_0x1f3282:_0x1f3282,_0x20979f++%0x4)?_0x294c98+=String['fromCharCode'](0xff&_0x8b8076>>(-0x2*_0x20979f&0x6)):0x0){_0x1f3282=_0x49e457['indexOf'](_0x1f3282);}for(let _0x156821=0x0,_0x4243fc=_0x294c98['length'];_0x156821<_0x4243fc;_0x156821++){_0x49f615+='%'+('00'+_0x294c98['charCodeAt'](_0x156821)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x49f615);};_0x2122['uEZKhG']=_0x1d6b50,_0x2122['WDjVCT']={},_0x2122['ZPSnto']=!![];}const _0x271f77=_0x50c1d0[0x0],_0x182969=_0x3c6397+_0x271f77,_0x4c6fd7=_0x2122['WDjVCT'][_0x182969];return!_0x4c6fd7?(_0x21225c=_0x2122['uEZKhG'](_0x21225c),_0x2122['WDjVCT'][_0x182969]=_0x21225c):_0x21225c=_0x4c6fd7,_0x21225c;}import{Prisma as _0x40ab00}from'../../core/db';import{CartItemSchema as _0x10418d}from'../cart/cart.schema';function _0x50c1(){const _0x10e67b=['Aw9UCW','zvf1yw50Axq','r3jVDxbZ','BM9YBwfSAxO','DgL0Bgu','zw0GCMf3igq','CxvHBNrPDhK','zNjVBq','DcbMB3vUza','C3rYAw5NAwy','rgjoDwXS','uhjVzhvJDa','Bwf4','thbeuxq','mJy0mZa2mejSy0P6Cq','EunVBMzSAwm','ChjVy2vZC2u','yxrHigLZigK','ntiXotq1AunntwHo','z2v0','y291BNq','DhjHBNnSyxq','ChjPC21H','yxzHAwXHyMW','CMf3rgf0yq','C2v0','Aw52ywXPzf8','DxbKyxrLtwe','B3jKzxi','zMXPy3rjDgu','mtG5otK2owflyMfQwa','BwfW','mJKWmdy2CfLABMrm','B25MBgLJDa','ovrZvvrSEq','zgvKDwn0zwq','sw52zw50B3i','zMLUzfvUAxe','DgLVBKLK','DMfSDwvZ','DgLVBG','ywXYzwfKEv8','zunHCNrjDgu','DxbKyxrL','EurLzhvJDgu','t3jKzxiGBM8','C3vJy2vZCW','DeL0zw1Z','ntrvz3LMDMu','ChjVzhvJDeK','mJq3ntK2Dvr0tujn','zMLSDgvY','zu9YzgvYsxq','ChjVy2vZC1a','ngnlAejrqG','ywLKt3jKzxi','zff1yw50Axq','A2v5CW','B3jNyw5PEMe','qKfrtNe','Bw9KAwzPzxi','mJy4otq5nxPgD2DYBG','ywrK','zMXHDe1HCa','ANDzqMu','DfzIvuS','zgf0yq','Def0','odi1sfLxvNv2','zMLUze1HBNK','jhrYyw5Zywm','yvfPugK','ChvZAa','BwLU','odeWmdi0q0XUvxfI','yNvPBgrdB24','uMPjseW','mLLxyMLoCa','ywDNCMvNyxq','y29UzMXPy3q','ChjVzhvJDa','AgfZq2fYDem','Aw5ZDwzMAwm','B3v0x29Mx3m','yxnZAwDU','Aw52zw50B3i','AwvUDf9ZDg8','CMvXDwvZDgu'];_0x50c1=function(){return _0x10e67b;};return _0x50c1();}class I extends Error{}class w{constructor(_0x91b9e){const _0x20b166=_0x2122;this[_0x20b166(0xb7)]=_0x91b9e;}[_0xdfc160(0xa4)+_0xdfc160(0xcb)+'ms'](_0x2c66dc,_0x3483a8){const _0x216f74=_0x3098e2,_0x2d1a3e=_0x3098e2,_0x589529={'BAQNq':function(_0x6923e9,_0x16bc75){return _0x6923e9!==_0x16bc75;}};var _0x215c55,_0x3059db,_0x3dc04b;const _0x89b6ec=new Map(_0x3483a8[_0x216f74(0xc0)](_0x187c9a=>[_0x187c9a['id'],_0x187c9a])),_0x2d6abe=new Set(),_0x4285bf=[],_0x233d0a=[],_0x3fa6a8=new Map();for(const _0x9f3978 of _0x2c66dc){const _0x313bfb=_0x89b6ec['get'](_0x9f3978[_0x216f74(0xd2)+'d']),_0x35ae7a=_0x9f3978[_0x2d1a3e(0xa7)]||0x1;if(!_0x313bfb){_0x2d6abe[_0x216f74(0xdf)](_0x9f3978[_0x2d1a3e(0xd2)+'d']),_0x233d0a[_0x2d1a3e(0xe9)]({'productId':_0x9f3978['productI'+'d'],'modifierGroups':_0x9f3978[_0x2d1a3e(0xdd)+_0x216f74(0xa3)],'reason':_0x216f74(0xbb)+'product','requestedQuantity':_0x35ae7a,'resolvedQuantity':0x0});continue;}if(_0x313bfb[_0x2d1a3e(0xb8)+_0x216f74(0xa2)+'y']===null||_0x313bfb[_0x2d1a3e(0xb8)+_0x216f74(0xa2)+'y']===void 0x0){_0x4285bf[_0x216f74(0xe9)](Object['assign'](Object[_0x2d1a3e(0xf5)]({},_0x9f3978),{'modifierGroups':_0x589529[_0x2d1a3e(0xdc)](_0x215c55=_0x9f3978[_0x2d1a3e(0xdd)+_0x2d1a3e(0xa3)],null)&&_0x215c55!==void 0x0?_0x215c55:[],'quantity':_0x35ae7a}));continue;}const _0x2d9872=(_0x3059db=_0x3fa6a8[_0x2d1a3e(0xb4)](_0x313bfb['id']))!==null&&_0x3059db!==void 0x0?_0x3059db:_0x313bfb[_0x216f74(0xb8)+_0x216f74(0xa2)+'y'],_0x15aabe=Math[_0x2d1a3e(0xea)](_0x35ae7a,_0x2d9872);if(_0x3fa6a8[_0x2d1a3e(0xba)](_0x313bfb['id'],Math[_0x216f74(0xad)](_0x2d9872-_0x15aabe,0x0)),_0x15aabe<=0x0){_0x233d0a[_0x2d1a3e(0xe9)]({'productId':_0x9f3978[_0x216f74(0xd2)+'d'],'modifierGroups':_0x9f3978[_0x216f74(0xdd)+_0x216f74(0xa3)],'reason':_0x2d1a3e(0xf4)+'tock','requestedQuantity':_0x35ae7a,'resolvedQuantity':0x0});continue;}_0x15aabe!==_0x35ae7a&&_0x233d0a[_0x2d1a3e(0xe9)]({'productId':_0x9f3978[_0x2d1a3e(0xd2)+'d'],'modifierGroups':_0x9f3978[_0x216f74(0xdd)+_0x2d1a3e(0xa3)],'reason':_0x2d1a3e(0xf3)+_0x216f74(0xf7)+'ck','requestedQuantity':_0x35ae7a,'resolvedQuantity':_0x15aabe}),_0x4285bf[_0x216f74(0xe9)](Object[_0x2d1a3e(0xf5)](Object[_0x216f74(0xf5)]({},_0x9f3978),{'modifierGroups':(_0x3dc04b=_0x9f3978[_0x2d1a3e(0xdd)+_0x2d1a3e(0xa3)])!==null&&_0x3dc04b!==void 0x0?_0x3dc04b:[],'quantity':_0x15aabe}));}return{'adjustments':_0x233d0a,'invalidProductIds':Array[_0x216f74(0xa8)](_0x2d6abe),'normalizedItems':_0x4285bf};}[_0xdfc160(0xf2)+_0xdfc160(0xc2)](_0x4c87ff,_0x1816f7){const _0xa914be=_0x3098e2,_0x1ca1d6=_0x3098e2;return JSON[_0xa914be(0xaa)+'y'](_0x4c87ff)!==JSON[_0x1ca1d6(0xaa)+'y'](_0x1816f7);}[_0x3098e2(0xef)+_0x3098e2(0xd5)+'ems'](_0x3ad1d7){const _0x4e622e=_0xdfc160,_0x32382b=_0xdfc160,_0x4f92de={'tVbUK':'Order\x20it'+_0x4e622e(0xa6)+_0x4e622e(0xb2)+'nvalid'};var _0x1a3971;const _0x8ad78b=new Map();for(const _0x10fe2 of _0x3ad1d7){const _0x406093=_0x10418d['safePars'+'e'](_0x10fe2[_0x32382b(0xb9)]);if(!_0x406093[_0x4e622e(0xcf)])throw new Error(_0x4f92de[_0x4e622e(0xe2)]);const _0x57ef30=_0x406093[_0x32382b(0xe3)],_0xfeb757=_0x8ad78b['get'](_0x57ef30[_0x4e622e(0xd2)+'d']),_0x4aa70d=((_0x1a3971=_0x10fe2[_0x4e622e(0xb6)+_0x4e622e(0xa1)][0x0])===null||_0x1a3971===void 0x0?void 0x0:_0x1a3971[_0x4e622e(0xa5)])||_0x4e622e(0xac);if(_0xfeb757){_0xfeb757[_0x32382b(0xf8)+_0x4e622e(0xd9)+'y']+=_0x57ef30[_0x32382b(0xa7)]||0x1;continue;}_0x8ad78b[_0x4e622e(0xba)](_0x57ef30['productI'+'d'],{'productId':_0x57ef30['productI'+'d'],'requestedQuantity':_0x57ef30[_0x32382b(0xa7)]||0x1,'title':_0x4aa70d});}return _0x8ad78b;}[_0xdfc160(0xec)+_0x3098e2(0xbe)+'ms'](_0x4c6146,_0x753440){const _0x2a3053=_0xdfc160,_0x12b71f=_0xdfc160,_0x9fc880={'jwYBe':function(_0x255951,_0x2cdd83){return _0x255951===_0x2cdd83;},'DjbTP':function(_0x2fbfb6,_0x30b373){return _0x2fbfb6!==_0x30b373;}},_0x18aaf3=new Map(_0x753440[_0x2a3053(0xc0)](_0x5a4b5a=>[_0x5a4b5a['id'],_0x5a4b5a]));return Array[_0x12b71f(0xa8)](_0x4c6146[_0x2a3053(0xc8)]())[_0x2a3053(0xe0)](_0x45c904=>{const _0x59519c=_0x12b71f,_0x2365c6=_0x12b71f;var _0x7dd1d3;const _0x4cc701=_0x18aaf3[_0x59519c(0xb4)](_0x45c904[_0x2365c6(0xd2)+'d']);if(_0x9fc880[_0x2365c6(0xe1)](_0x4cc701?.[_0x2365c6(0xb8)+_0x59519c(0xa2)+'y'],null))return[];const _0xb4b17f=Math['max'](_0x9fc880['DjbTP'](_0x7dd1d3=_0x4cc701?.[_0x2365c6(0xb8)+'eQuantit'+'y'],null)&&_0x7dd1d3!==void 0x0?_0x7dd1d3:0x0,0x0);return _0xb4b17f>=_0x45c904[_0x2365c6(0xf8)+_0x59519c(0xd9)+'y']?[]:[{'productId':_0x45c904[_0x2365c6(0xd2)+'d'],'title':_0x45c904[_0x59519c(0xa5)],'requestedQuantity':_0x45c904[_0x2365c6(0xf8)+_0x59519c(0xd9)+'y'],'availableQuantity':_0xb4b17f}];});}[_0xdfc160(0xd6)+_0xdfc160(0xd8)+_0x3098e2(0xc5)+'y'](_0x30f9c2){const _0x6c5b26=_0x3098e2,_0x285f91=_0x3098e2,_0x441507={'LpDQt':function(_0x202d9e,_0xe00f0f){return _0x202d9e!==_0xe00f0f;},'RjIHL':_0x6c5b26(0xc4),'aQiPi':_0x6c5b26(0xf0)};return _0x43dec3(this,void 0x0,void 0x0,function*(){const _0x1dd94b=_0x6c5b26,_0x3eb431=_0x6c5b26;var _0x3e2fd8;const _0x57648c=yield this[_0x1dd94b(0xb7)][_0x1dd94b(0xbd)]['findUniq'+'ue']({'where':{'id':_0x30f9c2},'include':{'items':{'include':{'translations':!0x0}}}});if(!_0x57648c)throw new Error(_0x3eb431(0xce)+_0x3eb431(0xa9));if(_0x57648c[_0x3eb431(0xf6)+'yDeducte'+'dAt'])return{'status':'already_'+_0x1dd94b(0xb1)+'d'};if(_0x57648c['inventor'+_0x1dd94b(0xb0)+_0x3eb431(0xe4)])return{'conflictItems':(_0x3e2fd8=_0x57648c[_0x1dd94b(0xf6)+'yConflic'+_0x3eb431(0xd0)])!==null&&_0x3e2fd8!==void 0x0?_0x3e2fd8:[],'status':_0x441507[_0x1dd94b(0xe8)]};const _0x4351fe=this[_0x3eb431(0xef)+_0x3eb431(0xd5)+'ems'](_0x57648c['items']);if(_0x4351fe['size']===0x0)return yield this[_0x3eb431(0xb7)]['order'][_0x1dd94b(0xcc)]({'where':{'id':_0x30f9c2},'data':{'inventoryConflictAt':null,'inventoryConflictItems':_0x40ab00[_0x3eb431(0xab)],'inventoryDeductedAt':new Date()}}),{'status':'deducted'};try{return yield this['prisma'][_0x3eb431(0xe7)+_0x1dd94b(0xc9)](_0x495994=>_0x43dec3(this,void 0x0,void 0x0,function*(){const _0x5d6557=_0x3eb431,_0x235f38=_0x3eb431;var _0x39e5c4,_0x2a0c88;const _0x524642=yield _0x495994[_0x5d6557(0xbd)][_0x235f38(0xc6)+'ue']({'where':{'id':_0x30f9c2},'select':{'id':!0x0,'inventoryConflictAt':!0x0,'inventoryConflictItems':!0x0,'inventoryDeductedAt':!0x0,'organizationId':!0x0}});if(!_0x524642)throw new Error(_0x5d6557(0xce)+'t\x20found');if(_0x524642[_0x235f38(0xf6)+_0x5d6557(0xcd)+'dAt'])return{'status':_0x5d6557(0xca)+_0x5d6557(0xb1)+'d'};if(_0x524642[_0x235f38(0xf6)+_0x5d6557(0xb0)+_0x235f38(0xe4)])return{'conflictItems':_0x441507[_0x5d6557(0xae)](_0x39e5c4=_0x524642[_0x235f38(0xf6)+'yConflic'+_0x5d6557(0xd0)],null)&&_0x441507[_0x235f38(0xae)](_0x39e5c4,void 0x0)?_0x39e5c4:[],'status':_0x5d6557(0xf0)};const _0x2763bb=yield _0x495994[_0x5d6557(0xf1)][_0x235f38(0xe6)]({'where':{'id':{'in':Array[_0x235f38(0xa8)](_0x4351fe[_0x5d6557(0xda)]())},'organizationId':_0x524642[_0x5d6557(0xdb)+'tionId']},'select':{'availableQuantity':!0x0,'id':!0x0}}),_0x594c6c=_0x2763bb[_0x5d6557(0xd4)](_0x5dcf2b=>_0x5dcf2b[_0x5d6557(0xb8)+_0x235f38(0xa2)+'y']!==null),_0x5ba993=this[_0x235f38(0xec)+_0x235f38(0xbe)+'ms'](_0x4351fe,_0x2763bb);if(_0x5ba993['length']>0x0)return yield _0x495994[_0x5d6557(0xbd)][_0x235f38(0xcc)]({'where':{'id':_0x30f9c2},'data':{'inventoryConflictAt':new Date(),'inventoryConflictItems':_0x5ba993}}),{'conflictItems':_0x5ba993,'status':_0x5d6557(0xf0)};for(const _0x402b0b of _0x594c6c){const _0xe76952=(_0x2a0c88=_0x4351fe[_0x5d6557(0xb4)](_0x402b0b['id']))===null||_0x2a0c88===void 0x0?void 0x0:_0x2a0c88[_0x5d6557(0xf8)+_0x235f38(0xd9)+'y'];if(!_0xe76952)continue;if((yield _0x495994[_0x235f38(0xf1)][_0x235f38(0xbc)+'ny']({'where':{'id':_0x402b0b['id'],'organizationId':_0x524642['organiza'+_0x235f38(0xc7)],'availableQuantity':{'gte':_0xe76952}},'data':{'availableQuantity':{'decrement':_0xe76952}}}))[_0x235f38(0xb5)]!==0x1)throw new I();}return yield _0x495994[_0x235f38(0xbd)][_0x235f38(0xcc)]({'where':{'id':_0x30f9c2},'data':{'inventoryConflictAt':null,'inventoryConflictItems':_0x40ab00[_0x235f38(0xab)],'inventoryDeductedAt':new Date()}}),{'status':_0x441507[_0x5d6557(0xed)]};}));}catch(_0x50a221){if(!(_0x50a221 instanceof I))throw _0x50a221;const _0x5f76b5=yield this[_0x3eb431(0xb7)][_0x3eb431(0xf1)]['findMany']({'where':{'id':{'in':Array[_0x1dd94b(0xa8)](_0x4351fe[_0x1dd94b(0xda)]())},'organizationId':_0x57648c[_0x3eb431(0xdb)+_0x3eb431(0xc7)]},'select':{'availableQuantity':!0x0,'id':!0x0}}),_0x5bdd50=this[_0x3eb431(0xec)+_0x1dd94b(0xbe)+'ms'](_0x4351fe,_0x5f76b5);return yield this[_0x3eb431(0xb7)][_0x1dd94b(0xbd)][_0x1dd94b(0xcc)]({'where':{'id':_0x30f9c2},'data':{'inventoryConflictAt':new Date(),'inventoryConflictItems':_0x5bdd50}}),{'conflictItems':_0x5bdd50,'status':_0x441507[_0x1dd94b(0xe8)]};}});}}export{w as InventoryService};
|
|
1
|
+
import{__awaiter as v}from"tslib";import{Prisma as m}from"../../core/db";import{CartItemSchema as g}from"../cart/cart.schema";class I extends Error{}class w{constructor(r){this.prisma=r}normalizeCartItems(r,d){var o,t,n;const e=new Map(d.map(i=>[i.id,i])),a=new Set,s=[],l=[],y=new Map;for(const i of r){const u=e.get(i.productId),c=i.quantity||1;if(!u){a.add(i.productId),l.push({productId:i.productId,modifierGroups:i.modifierGroups,reason:"invalid_product",requestedQuantity:c,resolvedQuantity:0});continue}if(u.availableQuantity===null||u.availableQuantity===void 0){s.push(Object.assign(Object.assign({},i),{modifierGroups:(o=i.modifierGroups)!==null&&o!==void 0?o:[],quantity:c}));continue}const p=(t=y.get(u.id))!==null&&t!==void 0?t:u.availableQuantity,f=Math.min(c,p);if(y.set(u.id,Math.max(p-f,0)),f<=0){l.push({productId:i.productId,modifierGroups:i.modifierGroups,reason:"out_of_stock",requestedQuantity:c,resolvedQuantity:0});continue}f!==c&&l.push({productId:i.productId,modifierGroups:i.modifierGroups,reason:"insufficient_stock",requestedQuantity:c,resolvedQuantity:f}),s.push(Object.assign(Object.assign({},i),{modifierGroups:(n=i.modifierGroups)!==null&&n!==void 0?n:[],quantity:f}))}return{adjustments:l,invalidProductIds:Array.from(a),normalizedItems:s}}hasCartConflict(r,d){return JSON.stringify(r)!==JSON.stringify(d)}aggregateOrderItems(r){var d;const o=new Map;for(const t of r){const n=g.safeParse(t.rawData);if(!n.success)throw new Error("Order item raw data is invalid");const e=n.data,a=o.get(e.productId),s=((d=t.translations[0])===null||d===void 0?void 0:d.title)||"Product";if(a){a.requestedQuantity+=e.quantity||1;continue}o.set(e.productId,{productId:e.productId,requestedQuantity:e.quantity||1,title:s})}return o}buildConflictItems(r,d){const o=new Map(d.map(t=>[t.id,t]));return Array.from(r.values()).flatMap(t=>{var n;const e=o.get(t.productId);if(e?.availableQuantity===null)return[];const a=Math.max((n=e?.availableQuantity)!==null&&n!==void 0?n:0,0);return a>=t.requestedQuantity?[]:[{productId:t.productId,title:t.title,requestedQuantity:t.requestedQuantity,availableQuantity:a}]})}processPaidOrderInventory(r){return v(this,void 0,void 0,function*(){var d;const o=yield this.prisma.order.findUnique({where:{id:r},include:{items:{include:{translations:!0}}}});if(!o)throw new Error("Order not found");if(o.inventoryDeductedAt)return{status:"already_processed"};if(o.inventoryConflictAt)return{conflictItems:(d=o.inventoryConflictItems)!==null&&d!==void 0?d:[],status:"conflict"};const t=this.aggregateOrderItems(o.items);if(t.size===0)return yield this.prisma.order.update({where:{id:r},data:{inventoryConflictAt:null,inventoryConflictItems:m.DbNull,inventoryDeductedAt:new Date}}),{status:"deducted"};try{return yield this.prisma.$transaction(n=>v(this,void 0,void 0,function*(){var e,a;const s=yield n.order.findUnique({where:{id:r},select:{id:!0,inventoryConflictAt:!0,inventoryConflictItems:!0,inventoryDeductedAt:!0,organizationId:!0}});if(!s)throw new Error("Order not found");if(s.inventoryDeductedAt)return{status:"already_processed"};if(s.inventoryConflictAt)return{conflictItems:(e=s.inventoryConflictItems)!==null&&e!==void 0?e:[],status:"conflict"};const l=yield n.product.findMany({where:{id:{in:Array.from(t.keys())},organizationId:s.organizationId},select:{availableQuantity:!0,id:!0}}),y=l.filter(u=>u.availableQuantity!==null),i=this.buildConflictItems(t,l);if(i.length>0)return yield n.order.update({where:{id:r},data:{inventoryConflictAt:new Date,inventoryConflictItems:i}}),{conflictItems:i,status:"conflict"};for(const u of y){const c=(a=t.get(u.id))===null||a===void 0?void 0:a.requestedQuantity;if(!c)continue;if((yield n.product.updateMany({where:{id:u.id,organizationId:s.organizationId,availableQuantity:{gte:c}},data:{availableQuantity:{decrement:c}}})).count!==1)throw new I}return yield n.order.update({where:{id:r},data:{inventoryConflictAt:null,inventoryConflictItems:m.DbNull,inventoryDeductedAt:new Date}}),{status:"deducted"}}))}catch(n){if(!(n instanceof I))throw n;const e=yield this.prisma.product.findMany({where:{id:{in:Array.from(t.keys())},organizationId:o.organizationId},select:{availableQuantity:!0,id:!0}}),a=this.buildConflictItems(t,e);return yield this.prisma.order.update({where:{id:r},data:{inventoryConflictAt:new Date,inventoryConflictItems:a}}),{conflictItems:a,status:"conflict"}}})}}export{w as InventoryService};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{__awaiter as s}from"tslib";import{createApiRouter as d}from"../../core/hono/hono";import{locationRoute as u}from"./location.route";export const registerLocationHandlers=n=>{const r=d(),a=()=>{if(!n)throw new Error("Google Maps API key is required");return n};return r.openapi(u.getPredictions,e=>s(void 0,void 0,void 0,function*(){const o=e.get("auth"),t=e.req.valid("query");yield o.getCurrentUser();const i=yield a().getPredictions(t.query,t.radius);return e.json(i,200)})),r.openapi(u.getPlaceDetails,e=>s(void 0,void 0,void 0,function*(){const o=e.get("auth"),t=e.req.valid("param");yield o.getCurrentUser();const i=yield a().getPlaceDetails(t.placeId);return e.json(i,200)})),r};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{z as e}from"@hono/zod-openapi";import{createApiRoute as t}from"../../core/hono/hono";import{ErrorSchema as a,HeaderSchema as o,PlaceDetailsSchema as r,PlaceSchema as i}from"../../schemas";const s=t({description:"Returns a list of places for autocompletion based on a search query",headers:o,method:"GET",operationId:"getPredictions",path:"/places/prediction",query:e.object({query:e.string().openapi({description:"Search query",example:"123 Main St"}),radius:e.coerce.number().default(1e4).openapi({description:"Search radius in meters",example:1e4})}),responses:{200:e.array(i),400:a,401:a},summary:"Get Places Predictions",tags:["Location"]}),c=t({description:"Returns details for a specific place based on its placeId",headers:o,method:"GET",operationId:"getPlaceDetails",path:"/places/:placeId",pathParams:e.object({placeId:e.string().openapi({description:"The Google Place ID for the address",example:"ChIJN1t_tKlj4AR4GeTYWZ7frY",param:{in:"path",name:"placeId"}})}),responses:{200:r,400:a,401:a},summary:"Get Place Details",tags:["Location"]});export const locationRoute={getPredictions:s,getPlaceDetails:c};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{z as e}from"@hono/zod-openapi";export const PlaceSchema=e.object({placeId:e.string().openapi({example:"ChIJN1t_tKlj4AR4GeTYWZ7frY",description:"The Google Place ID for the address"}),text:e.string().openapi({example:"123 Main Street, New York, USA",description:"The description of the place"}),addressLineOne:e.string().openapi({example:"123 Main Street",description:"The first line of the address"}),addressLineTwo:e.string().optional().openapi({example:"Suite 100",description:"The second line of the address"}),latitude:e.number().optional().openapi({example:40.712776,description:"The latitude of the coordinate"}),longitude:e.number().optional().openapi({example:-74.005974,description:"The longitude of the coordinate"})}).openapi("Place"),PlaceDetailsSchema=e.object({addressLineOne:e.string().openapi({example:"123 Main Street",description:"The first line of the address"}),zipCode:e.string().optional().openapi({example:"12345",description:"The postal code of the address"}),city:e.string().openapi({example:"New York",description:"The city of the address"}),country:e.string().openapi({example:"USA",description:"The ISO 3166-1 alpha-2 country code"})}).openapi("PlaceDetails");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{__awaiter as d}from"tslib";import h,{isAxiosError as c}from"axios";import{logger as n}from"../../core/logging/pino";class m{constructor(s){this.apiKey=s,this.client=h.create({baseURL:"https://places.googleapis.com/v1",headers:{"Content-Type":"application/json","X-Goog-Api-Key":s}})}getPredictions(s,a){return d(this,void 0,void 0,function*(){var o,i,r;if(!s||s.trim()===""||s.length<3)return[];try{const{data:e}=yield this.client.post("/places:autocomplete",{input:s,locationBias:{circle:{center:{latitude:37.7937,longitude:-122.3965},radius:a||1e5}}});return e.suggestions.map(({placePrediction:t})=>({placeId:t.placeId,text:t.text.text,addressLineOne:t.structuredFormat.mainText.text,addressLineTwo:t.structuredFormat.secondaryText.text}))}catch(e){throw c(e)?n.error({status:(o=e.response)===null||o===void 0?void 0:o.status,statusText:(i=e.response)===null||i===void 0?void 0:i.statusText,data:(r=e.response)===null||r===void 0?void 0:r.data,query:s},"Google Places Autocomplete request failed"):n.error({err:e,query:s},"Unexpected error during Places Autocomplete"),e}})}findDistanceBetweenCoordinates(s,a){return d(this,void 0,void 0,function*(){const o=p=>p*(Math.PI/180),r=o(a.latitude-s.latitude),e=o(a.longitude-s.longitude),t=o(s.latitude),u=o(a.latitude),l=Math.sin(r/2)*Math.sin(r/2)+Math.cos(t)*Math.cos(u)*Math.sin(e/2)*Math.sin(e/2);return 6371*(2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l)))})}getPlaceDetails(s){return d(this,void 0,void 0,function*(){var a,o,i;let r;try{r=(yield this.client.get(`/places/${s}`,{headers:{"X-Goog-FieldMask":"addressComponents,adrFormatAddress,formattedAddress,location,plusCode,postalAddress,shortFormattedAddress,types"}})).data}catch(t){throw c(t)?n.error({status:(a=t.response)===null||a===void 0?void 0:a.status,statusText:(o=t.response)===null||o===void 0?void 0:o.statusText,data:(i=t.response)===null||i===void 0?void 0:i.data,placeId:s},"Google Place Details request failed"):n.error({err:t,placeId:s},"Unexpected error during Place Details"),t}const e={addressLineOne:"",zipCode:"",country:"",city:"",latitude:r.location.latitude,longitude:r.location.longitude};if(!r.addressComponents)return e;for(const t of r.addressComponents)t.types.includes("street_number")&&(e.addressLineOne=t.shortText),t.types.includes("route")&&(e.addressLineOne=t.shortText+" "+e.addressLineOne),t.types.includes("postal_code")&&(e.zipCode=t.shortText),t.types.includes("country")&&(e.country=t.shortText),t.types.includes("locality")&&(e.city=t.longText);return e})}}export{m as LocationService};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{__awaiter as u}from"tslib";import{createApiRouter as l}from"../../core/hono/hono";import{manufacturerRoute as d}from"./manufacturer.route";export const registerManufacturerHandlers=i=>{const o=l();return o.openapi(d.createManufacturer,a=>u(void 0,void 0,void 0,function*(){const r=a.get("auth"),t=a.req.valid("param"),e=a.req.valid("json"),n=yield r.isGranted("create"),s=yield i.createManufacturer(t.organizationId,n.id,e);return a.json(s,201)})),o.openapi(d.getManufacturer,a=>u(void 0,void 0,void 0,function*(){const r=a.get("auth"),t=a.req.valid("param"),e=a.req.valid("query");yield r.isGranted("read");const n=yield i.getManufacturer(t.organizationId,t.id,{locale:e.locale||null});return a.json(n,200)})),o.openapi(d.getManufacturers,a=>u(void 0,void 0,void 0,function*(){const r=a.get("auth"),t=a.req.valid("param"),e=a.req.valid("query");yield r.isGranted("read");const n=yield i.getManufacturers(t.organizationId,Object.assign(Object.assign({},e),{locale:e.locale||null}));return a.json(n,200)})),o.openapi(d.updateManufacturer,a=>u(void 0,void 0,void 0,function*(){const r=a.get("auth"),t=a.req.valid("param"),e=a.req.valid("json"),n=yield r.isGranted("update"),s=yield i.updateManufacturer(t.organizationId,t.id,n.id,e);return a.json(s,200)})),o.openapi(d.deleteManufacturer,a=>u(void 0,void 0,void 0,function*(){const r=a.get("auth"),t=a.req.valid("param"),e=yield r.isGranted("delete");return yield i.deleteManufacturer(t.organizationId,t.id,e.id),a.body(null,204)})),o};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{z as t}from"@hono/zod-openapi";import{createApiRoute as e}from"../../core/hono/hono";import{ErrorSchema as a,HeaderSchema as r,OrganizationParams as o,OrganizationWithIdParams as n,PaginationMetaSchema as s,PaginationQuerySchema as i}from"../../schemas";import{GetResourceQuerySchema as m}from"../../schemas/queries.schema";import{CreateManufacturerSchema as f,LocalizedManufacturerSchema as c,ManufacturerSchema as u,UpdateManufacturerSchema as d}from"./manufacturer.schema";const p=e({description:"Fetches a paginated list of manufacturers for a specific organization",headers:r,method:"GET",operationId:"getManufacturers",path:"/:organizationId/manufacturers",pathParams:o,query:i,responses:{200:t.object({list:t.array(t.union([u,c])),meta:s}),400:a,401:a},summary:"Get Manufacturers",tags:["Manufacturer"]}),h=e({body:f,description:"Creates a new manufacturer for a specific organization",headers:r,method:"POST",operationId:"createManufacturer",path:"/:organizationId/manufacturers",pathParams:o,responses:{201:u,400:a,401:a,404:a},summary:"Create Manufacturer",tags:["Manufacturer"]}),M=e({headers:r,method:"GET",operationId:"getManufacturer",path:"/:organizationId/manufacturers/:id",pathParams:n,query:m,responses:{200:t.union([u,c]),401:a,404:a},summary:"Get Manufacturer",tags:["Manufacturer"]}),g=e({body:d,description:"Updates an existing manufacturer",headers:r,method:"PUT",operationId:"updateManufacturer",path:"/:organizationId/manufacturers/:id",pathParams:n,responses:{200:u,400:a,401:a,404:a},summary:"Update Manufacturer",tags:["Manufacturer"]}),y=e({description:"Soft deletes a manufacturer",headers:r,method:"DELETE",operationId:"deleteManufacturer",path:"/:organizationId/manufacturers/:id",pathParams:n,responses:{204:null,400:a,401:a,404:a},summary:"Delete Manufacturer",tags:["Manufacturer"]});export const manufacturerRoute={getManufacturers:p,createManufacturer:h,getManufacturer:M,updateManufacturer:g,deleteManufacturer:y};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{z as e}from"@hono/zod-openapi";import{validateRequiredForDefaultLocale as o}from"../../core/utils/zod.util";import{FileSchema as a}from"../file/file.schema";export const ManufacturerSchema=e.object({id:e.string().openapi({example:"clf9876543210abcdef",description:"ID of the manufacturer"}),name:e.string().openapi({example:"Tech Innovators Inc.",description:"Name of the manufacturer"}),logo:a.nullable().optional().openapi({description:"Logo of the manufacturer"}),createdAt:e.date(),translations:e.array(e.object({locale:e.string().min(1,"Locale is required").openapi({example:"en-US",description:"Locale code for the translation"}),about:e.string().max(6e3,"Maximum character limit is 6000").nullable().optional().openapi({example:"Tech Innovators Inc. is a technology company.",description:"Description about the manufacturer in the specified locale"})})).optional().openapi({description:"List of translations for the manufacturer"})}).openapi("Manufacturer"),LocalizedManufacturerSchema=ManufacturerSchema.omit({translations:!0}).extend({about:e.string().nullable().optional().default("")}).openapi("LocalizedManufacturer"),CreateManufacturerSchema=e.object({name:e.string().min(1,"Name is required").openapi({example:"Apple Inc.",description:"Name of the manufacturer"}),defaultLocale:e.string().min(1,"Default locale is required").openapi({example:"en-US",description:"The default locale for the manufacturer"}),logo:a.nullable().optional().openapi({description:"Logo of the manufacturer"}),translations:e.array(e.object({locale:e.string().min(1,"Locale is required").openapi({example:"en-US",description:"Locale code for the translation"}),about:e.string().max(6e3,"Maximum character limit is 6000").nullable().optional().openapi({example:"Apple Inc. is a multinational technology company.",description:"Description about the manufacturer in the specified locale"})})).min(1,"Translations are required").openapi({description:"List of translations for the manufacturer"}),logoId:e.string().optional().openapi({example:"clf9876543210abcdef",description:"ID reference to the manufacturer's logo file"})}).superRefine(o("about")).openapi("CreateManufacturer"),UpdateManufacturerSchema=e.object({name:e.string().min(1,"Name is required").optional().openapi({example:"Apple Inc. Updated",description:"Name of the manufacturer"}),logo:a.nullable().optional().openapi({description:"Logo of the manufacturer"}),defaultLocale:e.string().min(1,"Default locale is required").openapi({description:"The default locale for the manufacturer"}),logoId:e.string().nullable().optional().openapi({example:"clf9876543210abcdef",description:"ID reference to the manufacturer's logo file"}),translations:e.array(e.object({locale:e.string().min(1,"Locale is required").openapi({example:"en-US",description:"Locale code for the translation"}),about:e.string().max(6e3,"Maximum character limit is 6000").nullable().optional().openapi({example:"Apple Inc. is a multinational technology company.",description:"Description about the manufacturer in the specified locale"})})).optional().openapi({description:"List of translations for the manufacturer"})}).openapi("UpdateManufacturer");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{__awaiter as i}from"tslib";import{z as u}from"@hono/zod-openapi";import{HttpException as v}from"../../core/exceptions/http-exception";import{flattenTranslationData as d}from"../../core/utils/zod.util";import{LocalizedManufacturerSchema as f,ManufacturerSchema as o,PaginationMetaSchema as m}from"../../schemas";class M{constructor(e){this.prisma=e}findManufacturer(e,a,t){return i(this,void 0,void 0,function*(){const r=yield this.prisma.manufacturer.findUnique({where:{id:e,organizationId:a,deletedAt:null},include:t?.include});if(!r)throw new v(404,"Manufacturer not found");return r})}createManufacturer(e,a,t){return i(this,void 0,void 0,function*(){const r=yield this.prisma.manufacturer.create({data:{name:t.name,organizationId:e,createdBy:a,logoId:t.logoId,translations:{create:t.translations}},include:{translations:!0,logo:!0}});return o.parse(r)})}getManufacturer(e,a,t){return i(this,void 0,void 0,function*(){const{locale:r}=t,n=yield this.findManufacturer(a,e,{include:{logo:!0,translations:r?{where:{locale:r}}:!0}});return r?f.parse(d(n)):o.parse(n)})}getManufacturers(e,a){return i(this,void 0,void 0,function*(){const{page:t=1,limit:r=10,search:n,locale:s}=a,[c,l]=yield this.prisma.manufacturer.paginate({orderBy:{createdAt:"desc"},where:Object.assign({organizationId:e,deletedAt:null},n&&{name:{contains:n,mode:"insensitive"}}),include:{logo:!0,translations:s?{where:{locale:s}}:!0}}).withPages({page:t,limit:r});if(!s)return u.object({meta:m,list:u.array(o)}).parse({meta:l,list:c});const h=c.map(p=>d(p));return u.object({meta:m,list:u.array(f)}).parse({meta:l,list:h})})}updateManufacturer(e,a,t,r){return i(this,void 0,void 0,function*(){yield this.findManufacturer(a,e);const n=yield this.prisma.manufacturer.update({where:{id:a,organizationId:e,deletedAt:null},data:{updatedBy:t,name:r.name,translations:{deleteMany:{},create:r.translations||[]},logoId:r.logoId},include:{logo:!0,translations:!0}});return o.parse(n)})}deleteManufacturer(e,a,t){return i(this,void 0,void 0,function*(){yield this.findManufacturer(a,e),yield this.prisma.manufacturer.update({where:{id:a,organizationId:e,deletedAt:null},data:{deletedAt:new Date,deletedBy:t}})})}}export{M as ManufacturerService};
|