@shophost/rest-api 2.0.30 → 2.0.32
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 +18 -13
- package/scripts/minify.mjs +123 -0
- package/src/app.js +1 -53
- package/src/core/auth/auth.schema.js +1 -41
- package/src/core/auth/auth.util.js +1 -44
- package/src/core/auth/better-auth.lib.js +1 -100
- package/src/core/auth/generate-password-hash.util.d.ts +0 -3
- package/src/core/auth/generate-password-hash.util.js +1 -30
- package/src/core/auth/headers.schema.js +1 -22
- package/src/core/auth/user.schema.js +1 -30
- package/src/core/db/__generated__/client/browser.d.ts +0 -128
- package/src/core/db/__generated__/client/browser.js +1 -18
- package/src/core/db/__generated__/client/client.d.ts +0 -143
- package/src/core/db/__generated__/client/client.js +1 -35
- package/src/core/db/__generated__/client/commonInputTypes.js +1 -11
- package/src/core/db/__generated__/client/enums.js +1 -200
- package/src/core/db/__generated__/client/internal/class.d.ts +0 -343
- package/src/core/db/__generated__/client/internal/class.js +1 -55
- package/src/core/db/__generated__/client/internal/prismaNamespace.d.ts +0 -234
- package/src/core/db/__generated__/client/internal/prismaNamespace.js +1 -541
- package/src/core/db/__generated__/client/internal/prismaNamespaceBrowser.d.ts +0 -15
- package/src/core/db/__generated__/client/internal/prismaNamespaceBrowser.js +1 -512
- package/src/core/db/__generated__/client/models/Account.d.ts +0 -628
- package/src/core/db/__generated__/client/models/Account.js +1 -2
- package/src/core/db/__generated__/client/models/Address.d.ts +0 -701
- package/src/core/db/__generated__/client/models/Address.js +1 -2
- package/src/core/db/__generated__/client/models/Campaign.d.ts +0 -638
- package/src/core/db/__generated__/client/models/Campaign.js +1 -2
- package/src/core/db/__generated__/client/models/ClosingTimes.d.ts +0 -634
- package/src/core/db/__generated__/client/models/ClosingTimes.js +1 -2
- package/src/core/db/__generated__/client/models/File.d.ts +0 -752
- package/src/core/db/__generated__/client/models/File.js +1 -2
- package/src/core/db/__generated__/client/models/Invitation.d.ts +0 -628
- package/src/core/db/__generated__/client/models/Invitation.js +1 -2
- package/src/core/db/__generated__/client/models/LegalEntity.d.ts +0 -652
- package/src/core/db/__generated__/client/models/LegalEntity.js +1 -2
- package/src/core/db/__generated__/client/models/Manufacturer.d.ts +0 -679
- package/src/core/db/__generated__/client/models/Manufacturer.js +1 -2
- package/src/core/db/__generated__/client/models/ManufacturerTranslation.d.ts +0 -628
- package/src/core/db/__generated__/client/models/ManufacturerTranslation.js +1 -2
- package/src/core/db/__generated__/client/models/Member.d.ts +0 -628
- package/src/core/db/__generated__/client/models/Member.js +1 -2
- package/src/core/db/__generated__/client/models/Modifier.d.ts +0 -662
- package/src/core/db/__generated__/client/models/Modifier.js +1 -2
- package/src/core/db/__generated__/client/models/ModifierGroup.d.ts +0 -686
- package/src/core/db/__generated__/client/models/ModifierGroup.js +1 -2
- package/src/core/db/__generated__/client/models/ModifierGroupTranslation.d.ts +0 -628
- package/src/core/db/__generated__/client/models/ModifierGroupTranslation.js +1 -2
- package/src/core/db/__generated__/client/models/OpeningTimes.d.ts +0 -634
- package/src/core/db/__generated__/client/models/OpeningTimes.js +1 -2
- package/src/core/db/__generated__/client/models/Order.d.ts +0 -700
- package/src/core/db/__generated__/client/models/Order.js +1 -2
- package/src/core/db/__generated__/client/models/OrderItem.d.ts +0 -686
- package/src/core/db/__generated__/client/models/OrderItem.js +1 -2
- package/src/core/db/__generated__/client/models/OrderItemTranslation.d.ts +0 -628
- package/src/core/db/__generated__/client/models/OrderItemTranslation.js +1 -2
- package/src/core/db/__generated__/client/models/Organization.d.ts +0 -811
- package/src/core/db/__generated__/client/models/Organization.js +1 -2
- package/src/core/db/__generated__/client/models/OrganizationConfiguration.d.ts +0 -676
- package/src/core/db/__generated__/client/models/OrganizationConfiguration.js +1 -2
- package/src/core/db/__generated__/client/models/Payment.d.ts +0 -668
- package/src/core/db/__generated__/client/models/Payment.js +1 -2
- package/src/core/db/__generated__/client/models/PaymentSession.d.ts +0 -638
- package/src/core/db/__generated__/client/models/PaymentSession.js +1 -2
- package/src/core/db/__generated__/client/models/Product.d.ts +0 -746
- package/src/core/db/__generated__/client/models/Product.js +1 -2
- package/src/core/db/__generated__/client/models/ProductCategory.d.ts +0 -689
- package/src/core/db/__generated__/client/models/ProductCategory.js +1 -2
- package/src/core/db/__generated__/client/models/ProductCategoryTranslation.d.ts +0 -628
- package/src/core/db/__generated__/client/models/ProductCategoryTranslation.js +1 -2
- package/src/core/db/__generated__/client/models/ProductSnapshot.d.ts +0 -664
- package/src/core/db/__generated__/client/models/ProductSnapshot.js +1 -2
- package/src/core/db/__generated__/client/models/ProductTranslation.d.ts +0 -628
- package/src/core/db/__generated__/client/models/ProductTranslation.js +1 -2
- package/src/core/db/__generated__/client/models/Reservation.d.ts +0 -650
- package/src/core/db/__generated__/client/models/Reservation.js +1 -2
- package/src/core/db/__generated__/client/models/Session.d.ts +0 -628
- package/src/core/db/__generated__/client/models/Session.js +1 -2
- package/src/core/db/__generated__/client/models/ShippingMethod.d.ts +0 -679
- package/src/core/db/__generated__/client/models/ShippingMethod.js +1 -2
- package/src/core/db/__generated__/client/models/ShippingZone.d.ts +0 -638
- package/src/core/db/__generated__/client/models/ShippingZone.js +1 -2
- package/src/core/db/__generated__/client/models/User.d.ts +0 -736
- package/src/core/db/__generated__/client/models/User.js +1 -2
- package/src/core/db/__generated__/client/models/Verification.d.ts +0 -592
- package/src/core/db/__generated__/client/models/Verification.js +1 -2
- package/src/core/db/__generated__/client/models.js +1 -2
- package/src/core/db/index.js +1 -2
- package/src/core/exceptions/http-exception.js +1 -9
- package/src/core/hono/hono.js +1 -123
- package/src/core/lib/prisma.d.ts +9 -1
- package/src/core/lib/prisma.js +1 -11
- package/src/core/logging/pino.js +1 -5
- package/src/core/notifications/email.service.d.ts +0 -15
- package/src/core/notifications/email.service.js +1 -116
- package/src/core/openapi/openapi.lib.js +1 -26
- package/src/core/types/google-maps.types.js +1 -2
- package/src/core/utils/currency.util.js +1 -11
- package/src/core/utils/env.util.js +1 -8
- package/src/core/utils/object.util.d.ts +0 -10
- package/src/core/utils/object.util.js +1 -39
- package/src/core/utils/translations.util.js +0 -2
- package/src/core/utils/zod.util.d.ts +0 -12
- package/src/core/utils/zod.util.js +1 -85
- package/src/db.js +1 -3
- package/src/features/access/access.handler.js +1 -91
- package/src/features/access/access.route.js +1 -220
- package/src/features/access/access.schema.js +1 -108
- package/src/features/access/access.service.js +1 -294
- package/src/features/cart/cart.handler.js +1 -17
- package/src/features/cart/cart.route.js +1 -32
- package/src/features/cart/cart.schema.js +1 -39
- package/src/features/cart/cart.service.d.ts +0 -7
- package/src/features/cart/cart.service.js +1 -97
- package/src/features/cart/cart.util.js +1 -76
- package/src/features/file/file.handler.js +1 -23
- package/src/features/file/file.route.js +1 -34
- package/src/features/file/file.schema.js +1 -77
- package/src/features/file/file.service.d.ts +0 -6
- package/src/features/file/file.service.js +1 -66
- package/src/features/health/health.handler.js +1 -10
- package/src/features/health/health.route.js +1 -25
- package/src/features/index.js +1 -16
- package/src/features/location/location.handler.js +1 -25
- package/src/features/location/location.route.js +1 -56
- package/src/features/location/location.schema.js +1 -50
- package/src/features/location/location.service.d.ts +0 -3
- package/src/features/location/location.service.js +1 -141
- package/src/features/manufacturer/manufacturer.handler.js +1 -53
- package/src/features/manufacturer/manufacturer.route.js +1 -97
- package/src/features/manufacturer/manufacturer.schema.js +1 -125
- package/src/features/manufacturer/manufacturer.service.d.ts +0 -19
- package/src/features/manufacturer/manufacturer.service.js +1 -190
- package/src/features/order/emails/order-confirmation.email.js +1 -229
- package/src/features/order/emails/order-notification.email.js +1 -229
- package/src/features/order/fulfilment.schema.js +1 -3
- package/src/features/order/order.handler.js +1 -54
- package/src/features/order/order.route.js +1 -111
- package/src/features/order/order.schema.js +1 -158
- package/src/features/order/order.service.d.ts +0 -15
- package/src/features/order/order.service.js +1 -306
- package/src/features/order/recipient.schema.js +1 -38
- package/src/features/organization/legal-entity.schema.js +1 -83
- package/src/features/organization/organization-configuration.schema.js +1 -115
- package/src/features/organization/organization.handler.js +1 -48
- package/src/features/organization/organization.route.js +1 -84
- package/src/features/organization/organization.schema.js +1 -64
- package/src/features/organization/organization.service.d.ts +0 -15
- package/src/features/organization/organization.service.js +1 -334
- package/src/features/payment/payment.handler.js +1 -16
- package/src/features/payment/payment.route.js +1 -22
- package/src/features/payment/payment.schema.js +1 -46
- package/src/features/payment/payment.service.js +1 -100
- package/src/features/payment/stripe.service.js +1 -164
- package/src/features/product/product-modifier.schema.js +1 -84
- package/src/features/product/product.handler.js +1 -87
- package/src/features/product/product.route.js +1 -179
- package/src/features/product/product.schema.js +1 -143
- package/src/features/product/product.service.d.ts +0 -25
- package/src/features/product/product.service.js +1 -440
- package/src/features/product-category/product-category.handler.js +1 -59
- package/src/features/product-category/product-category.route.js +1 -139
- package/src/features/product-category/product-category.schema.js +1 -86
- package/src/features/product-category/product-category.service.d.ts +0 -22
- package/src/features/product-category/product-category.service.js +1 -220
- package/src/features/reservation/emails/reservation-cancellation.email.js +1 -82
- package/src/features/reservation/emails/reservation-confirmation.email.js +1 -82
- package/src/features/reservation/emails/reservation-notification.email.js +1 -93
- package/src/features/reservation/reservation.handler.js +1 -65
- package/src/features/reservation/reservation.route.js +1 -167
- package/src/features/reservation/reservation.schema.js +1 -51
- package/src/features/reservation/reservation.service.d.ts +0 -18
- package/src/features/reservation/reservation.service.js +1 -231
- package/src/features/shipping/shipping.handler.js +1 -32
- package/src/features/shipping/shipping.route.js +1 -51
- package/src/features/shipping/shipping.service.d.ts +0 -7
- package/src/features/shipping/shipping.service.js +1 -96
- package/src/features/shipping-method/shipping-method.handler.js +1 -60
- package/src/features/shipping-method/shipping-method.route.js +1 -144
- package/src/features/shipping-method/shipping-method.schema.js +1 -48
- package/src/features/shipping-method/shipping-method.service.d.ts +0 -25
- package/src/features/shipping-method/shipping-method.service.js +1 -229
- package/src/features/shipping-method/shipping-zone.schema.js +1 -31
- package/src/features/webhook/webhook.handler.js +1 -50
- package/src/features/webhook/webhook.route.js +1 -33
- package/src/index.js +1 -6
- package/src/integrations/next.js +1 -82
- package/src/schemas/address.schema.d.ts +0 -8
- package/src/schemas/address.schema.js +1 -112
- package/src/schemas/currency.schema.d.ts +0 -42
- package/src/schemas/currency.schema.js +1 -118
- package/src/schemas/error.schema.js +1 -12
- package/src/schemas/index.js +1 -29
- package/src/schemas/locales.schema.js +1 -238
- package/src/schemas/number.schema.js +1 -29
- package/src/schemas/pagination.schema.js +1 -54
- package/src/schemas/params.schema.js +1 -20
- package/src/schemas/queries.schema.js +1 -6
- package/src/test/global-setup.d.ts +1 -0
- package/src/test/global-setup.js +1 -0
- package/src/test/integration/api-fixtures.d.ts +4 -16
- package/src/test/integration/api-fixtures.js +1 -225
- package/src/test/integration/seed.d.ts +81 -0
- package/src/test/integration/seed.js +1 -0
- package/src/test/integration/test-helpers.d.ts +107 -924
- package/src/test/integration/test-helpers.js +1 -1100
- package/src/test/setup-test-env.d.ts +1 -1
- package/src/test/setup-test-env.js +1 -29
- package/src/app.js.map +0 -1
- package/src/core/auth/auth.schema.js.map +0 -1
- package/src/core/auth/auth.util.js.map +0 -1
- package/src/core/auth/better-auth.lib.js.map +0 -1
- package/src/core/auth/generate-password-hash.util.js.map +0 -1
- package/src/core/auth/headers.schema.js.map +0 -1
- package/src/core/auth/user.schema.js.map +0 -1
- package/src/core/db/__generated__/client/browser.js.map +0 -1
- package/src/core/db/__generated__/client/client.js.map +0 -1
- package/src/core/db/__generated__/client/commonInputTypes.js.map +0 -1
- package/src/core/db/__generated__/client/enums.js.map +0 -1
- package/src/core/db/__generated__/client/internal/class.js.map +0 -1
- package/src/core/db/__generated__/client/internal/prismaNamespace.js.map +0 -1
- package/src/core/db/__generated__/client/internal/prismaNamespaceBrowser.js.map +0 -1
- package/src/core/db/__generated__/client/models/Account.js.map +0 -1
- package/src/core/db/__generated__/client/models/Address.js.map +0 -1
- package/src/core/db/__generated__/client/models/Campaign.js.map +0 -1
- package/src/core/db/__generated__/client/models/ClosingTimes.js.map +0 -1
- package/src/core/db/__generated__/client/models/File.js.map +0 -1
- package/src/core/db/__generated__/client/models/Invitation.js.map +0 -1
- package/src/core/db/__generated__/client/models/LegalEntity.js.map +0 -1
- package/src/core/db/__generated__/client/models/Manufacturer.js.map +0 -1
- package/src/core/db/__generated__/client/models/ManufacturerTranslation.js.map +0 -1
- package/src/core/db/__generated__/client/models/Member.js.map +0 -1
- package/src/core/db/__generated__/client/models/Modifier.js.map +0 -1
- package/src/core/db/__generated__/client/models/ModifierGroup.js.map +0 -1
- package/src/core/db/__generated__/client/models/ModifierGroupTranslation.js.map +0 -1
- package/src/core/db/__generated__/client/models/OpeningTimes.js.map +0 -1
- package/src/core/db/__generated__/client/models/Order.js.map +0 -1
- package/src/core/db/__generated__/client/models/OrderItem.js.map +0 -1
- package/src/core/db/__generated__/client/models/OrderItemTranslation.js.map +0 -1
- package/src/core/db/__generated__/client/models/Organization.js.map +0 -1
- package/src/core/db/__generated__/client/models/OrganizationConfiguration.js.map +0 -1
- package/src/core/db/__generated__/client/models/Payment.js.map +0 -1
- package/src/core/db/__generated__/client/models/PaymentSession.js.map +0 -1
- package/src/core/db/__generated__/client/models/Product.js.map +0 -1
- package/src/core/db/__generated__/client/models/ProductCategory.js.map +0 -1
- package/src/core/db/__generated__/client/models/ProductCategoryTranslation.js.map +0 -1
- package/src/core/db/__generated__/client/models/ProductSnapshot.js.map +0 -1
- package/src/core/db/__generated__/client/models/ProductTranslation.js.map +0 -1
- package/src/core/db/__generated__/client/models/Reservation.js.map +0 -1
- package/src/core/db/__generated__/client/models/Session.js.map +0 -1
- package/src/core/db/__generated__/client/models/ShippingMethod.js.map +0 -1
- package/src/core/db/__generated__/client/models/ShippingZone.js.map +0 -1
- package/src/core/db/__generated__/client/models/User.js.map +0 -1
- package/src/core/db/__generated__/client/models/Verification.js.map +0 -1
- package/src/core/db/__generated__/client/models.js.map +0 -1
- package/src/core/db/index.js.map +0 -1
- package/src/core/exceptions/http-exception.js.map +0 -1
- package/src/core/hono/hono.js.map +0 -1
- package/src/core/lib/prisma.js.map +0 -1
- package/src/core/logging/pino.js.map +0 -1
- package/src/core/notifications/email.service.js.map +0 -1
- package/src/core/openapi/openapi.lib.js.map +0 -1
- package/src/core/types/google-maps.types.js.map +0 -1
- package/src/core/utils/currency.util.js.map +0 -1
- package/src/core/utils/env.util.js.map +0 -1
- package/src/core/utils/object.util.js.map +0 -1
- package/src/core/utils/translations.util.js.map +0 -1
- package/src/core/utils/zod.util.js.map +0 -1
- package/src/db.js.map +0 -1
- package/src/features/access/access.handler.js.map +0 -1
- package/src/features/access/access.route.js.map +0 -1
- package/src/features/access/access.schema.js.map +0 -1
- package/src/features/access/access.service.js.map +0 -1
- package/src/features/cart/cart.handler.js.map +0 -1
- package/src/features/cart/cart.route.js.map +0 -1
- package/src/features/cart/cart.schema.js.map +0 -1
- package/src/features/cart/cart.service.js.map +0 -1
- package/src/features/cart/cart.util.js.map +0 -1
- package/src/features/file/file.handler.js.map +0 -1
- package/src/features/file/file.route.js.map +0 -1
- package/src/features/file/file.schema.js.map +0 -1
- package/src/features/file/file.service.js.map +0 -1
- package/src/features/health/health.handler.js.map +0 -1
- package/src/features/health/health.route.js.map +0 -1
- package/src/features/index.js.map +0 -1
- package/src/features/location/location.handler.js.map +0 -1
- package/src/features/location/location.route.js.map +0 -1
- package/src/features/location/location.schema.js.map +0 -1
- package/src/features/location/location.service.js.map +0 -1
- package/src/features/manufacturer/manufacturer.handler.js.map +0 -1
- package/src/features/manufacturer/manufacturer.route.js.map +0 -1
- package/src/features/manufacturer/manufacturer.schema.js.map +0 -1
- package/src/features/manufacturer/manufacturer.service.js.map +0 -1
- package/src/features/order/emails/order-confirmation.email.js.map +0 -1
- package/src/features/order/emails/order-notification.email.js.map +0 -1
- package/src/features/order/fulfilment.schema.js.map +0 -1
- package/src/features/order/order.handler.js.map +0 -1
- package/src/features/order/order.route.js.map +0 -1
- package/src/features/order/order.schema.js.map +0 -1
- package/src/features/order/order.service.js.map +0 -1
- package/src/features/order/recipient.schema.js.map +0 -1
- package/src/features/organization/legal-entity.schema.js.map +0 -1
- package/src/features/organization/organization-configuration.schema.js.map +0 -1
- package/src/features/organization/organization.handler.js.map +0 -1
- package/src/features/organization/organization.route.js.map +0 -1
- package/src/features/organization/organization.schema.js.map +0 -1
- package/src/features/organization/organization.service.js.map +0 -1
- package/src/features/payment/payment.handler.js.map +0 -1
- package/src/features/payment/payment.route.js.map +0 -1
- package/src/features/payment/payment.schema.js.map +0 -1
- package/src/features/payment/payment.service.js.map +0 -1
- package/src/features/payment/stripe.service.js.map +0 -1
- package/src/features/product/product-modifier.schema.js.map +0 -1
- package/src/features/product/product.handler.js.map +0 -1
- package/src/features/product/product.route.js.map +0 -1
- package/src/features/product/product.schema.js.map +0 -1
- package/src/features/product/product.service.js.map +0 -1
- package/src/features/product-category/product-category.handler.js.map +0 -1
- package/src/features/product-category/product-category.route.js.map +0 -1
- package/src/features/product-category/product-category.schema.js.map +0 -1
- package/src/features/product-category/product-category.service.js.map +0 -1
- package/src/features/reservation/emails/reservation-cancellation.email.js.map +0 -1
- package/src/features/reservation/emails/reservation-confirmation.email.js.map +0 -1
- package/src/features/reservation/emails/reservation-notification.email.js.map +0 -1
- package/src/features/reservation/reservation.handler.js.map +0 -1
- package/src/features/reservation/reservation.route.js.map +0 -1
- package/src/features/reservation/reservation.schema.js.map +0 -1
- package/src/features/reservation/reservation.service.js.map +0 -1
- package/src/features/shipping/shipping.handler.js.map +0 -1
- package/src/features/shipping/shipping.route.js.map +0 -1
- package/src/features/shipping/shipping.service.js.map +0 -1
- package/src/features/shipping-method/shipping-method.handler.js.map +0 -1
- package/src/features/shipping-method/shipping-method.route.js.map +0 -1
- package/src/features/shipping-method/shipping-method.schema.js.map +0 -1
- package/src/features/shipping-method/shipping-method.service.js.map +0 -1
- package/src/features/shipping-method/shipping-zone.schema.js.map +0 -1
- package/src/features/webhook/webhook.handler.js.map +0 -1
- package/src/features/webhook/webhook.route.js.map +0 -1
- package/src/index.js.map +0 -1
- package/src/integrations/next.js.map +0 -1
- package/src/schemas/address.schema.js.map +0 -1
- package/src/schemas/currency.schema.js.map +0 -1
- package/src/schemas/error.schema.js.map +0 -1
- package/src/schemas/index.js.map +0 -1
- package/src/schemas/locales.schema.js.map +0 -1
- package/src/schemas/number.schema.js.map +0 -1
- package/src/schemas/pagination.schema.js.map +0 -1
- package/src/schemas/params.schema.js.map +0 -1
- package/src/schemas/queries.schema.js.map +0 -1
- package/src/test/integration/api-fixtures.js.map +0 -1
- package/src/test/integration/test-helpers.js.map +0 -1
- package/src/test/setup-test-env.js.map +0 -1
|
@@ -1,77 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
const GenerateClientTokenEventSchema = z.object({
|
|
3
|
-
type: z.literal("blob.generate-client-token"),
|
|
4
|
-
payload: z.object({
|
|
5
|
-
pathname: z.string(),
|
|
6
|
-
callbackUrl: z.string(),
|
|
7
|
-
multipart: z.boolean(),
|
|
8
|
-
clientPayload: z.string().nullable(),
|
|
9
|
-
}),
|
|
10
|
-
});
|
|
11
|
-
// Schema for UploadCompletedEvent
|
|
12
|
-
const UploadCompletedEventSchema = z.object({
|
|
13
|
-
type: z.literal("blob.upload-completed"),
|
|
14
|
-
payload: z.object({
|
|
15
|
-
// Replace z.any() with an appropriate schema for PutBlobResult if available
|
|
16
|
-
blob: z.any(),
|
|
17
|
-
tokenPayload: z.string().nullable().optional(),
|
|
18
|
-
}),
|
|
19
|
-
});
|
|
20
|
-
// Discriminated union schema for HandleUploadBody
|
|
21
|
-
export const GetVercelTokenBody = z.discriminatedUnion("type", [
|
|
22
|
-
GenerateClientTokenEventSchema,
|
|
23
|
-
UploadCompletedEventSchema,
|
|
24
|
-
]);
|
|
25
|
-
export const GetVercelTokenResponse = z.discriminatedUnion("type", [
|
|
26
|
-
z.object({
|
|
27
|
-
type: z.literal("blob.generate-client-token"),
|
|
28
|
-
clientToken: z.string(),
|
|
29
|
-
}),
|
|
30
|
-
z.object({
|
|
31
|
-
type: z.literal("blob.upload-completed"),
|
|
32
|
-
response: z.literal("ok"),
|
|
33
|
-
}),
|
|
34
|
-
]);
|
|
35
|
-
export const CreateTemporaryFileSchema = z.object({
|
|
36
|
-
mimeType: z.string().min(1, "MIME type is required").openapi({
|
|
37
|
-
example: "image/png",
|
|
38
|
-
description: "MIME type of the file",
|
|
39
|
-
}),
|
|
40
|
-
size: z.number().min(1, "Size is required").openapi({
|
|
41
|
-
example: 1024,
|
|
42
|
-
description: "Size of the file in bytes",
|
|
43
|
-
}),
|
|
44
|
-
filename: z.string().min(1, "Filename is required").openapi({
|
|
45
|
-
example: "example.png",
|
|
46
|
-
description: "Name of the file",
|
|
47
|
-
}),
|
|
48
|
-
organizationId: z.string().optional().openapi({
|
|
49
|
-
example: "clm1234567890abcdef",
|
|
50
|
-
description: "ID of the organization",
|
|
51
|
-
}),
|
|
52
|
-
});
|
|
53
|
-
export const FileSchema = z
|
|
54
|
-
.object({
|
|
55
|
-
id: z.string().min(1, "ID is required").openapi({
|
|
56
|
-
example: "clf9876543210abcdef",
|
|
57
|
-
description: "ID of the file",
|
|
58
|
-
}),
|
|
59
|
-
url: z.string().min(1, "Path is required").openapi({
|
|
60
|
-
example: "/path/to/file",
|
|
61
|
-
description: "Path of the file",
|
|
62
|
-
}),
|
|
63
|
-
mimeType: z.string().min(1, "MIME type is required").openapi({
|
|
64
|
-
example: "image/png",
|
|
65
|
-
description: "MIME type of the file",
|
|
66
|
-
}),
|
|
67
|
-
size: z.number().min(1, "Size is required").openapi({
|
|
68
|
-
example: 1024,
|
|
69
|
-
description: "Size of the file in bytes",
|
|
70
|
-
}),
|
|
71
|
-
filename: z.string().min(1, "Filename is required").openapi({
|
|
72
|
-
example: "example.png",
|
|
73
|
-
description: "Name of the file",
|
|
74
|
-
}),
|
|
75
|
-
})
|
|
76
|
-
.openapi("UploadedFile");
|
|
77
|
-
//# sourceMappingURL=file.schema.js.map
|
|
1
|
+
import{z as e}from"@hono/zod-openapi";const i=e.object({type:e.literal("blob.generate-client-token"),payload:e.object({pathname:e.string(),callbackUrl:e.string(),multipart:e.boolean(),clientPayload:e.string().nullable()})}),t=e.object({type:e.literal("blob.upload-completed"),payload:e.object({blob:e.any(),tokenPayload:e.string().nullable().optional()})});export const GetVercelTokenBody=e.discriminatedUnion("type",[i,t]);export const GetVercelTokenResponse=e.discriminatedUnion("type",[e.object({type:e.literal("blob.generate-client-token"),clientToken:e.string()}),e.object({type:e.literal("blob.upload-completed"),response:e.literal("ok")})]);export const CreateTemporaryFileSchema=e.object({mimeType:e.string().min(1,"MIME type is required").openapi({example:"image/png",description:"MIME type of the file"}),size:e.number().min(1,"Size is required").openapi({example:1024,description:"Size of the file in bytes"}),filename:e.string().min(1,"Filename is required").openapi({example:"example.png",description:"Name of the file"}),organizationId:e.string().optional().openapi({example:"clm1234567890abcdef",description:"ID of the organization"})});export const FileSchema=e.object({id:e.string().min(1,"ID is required").openapi({example:"clf9876543210abcdef",description:"ID of the file"}),url:e.string().min(1,"Path is required").openapi({example:"/path/to/file",description:"Path of the file"}),mimeType:e.string().min(1,"MIME type is required").openapi({example:"image/png",description:"MIME type of the file"}),size:e.number().min(1,"Size is required").openapi({example:1024,description:"Size of the file in bytes"}),filename:e.string().min(1,"Filename is required").openapi({example:"example.png",description:"Name of the file"})}).openapi("UploadedFile");
|
|
@@ -4,9 +4,6 @@ import { CreateTemporaryFileSchema, GetVercelTokenBody } from "../../schemas";
|
|
|
4
4
|
declare class FileService {
|
|
5
5
|
private readonly prisma;
|
|
6
6
|
constructor(prisma: PrismaClientType);
|
|
7
|
-
/**
|
|
8
|
-
* Get Vercel token for file upload
|
|
9
|
-
*/
|
|
10
7
|
getVercelToken(body: z.infer<typeof GetVercelTokenBody>, request: any): Promise<{
|
|
11
8
|
type: "blob.generate-client-token";
|
|
12
9
|
clientToken: string;
|
|
@@ -14,9 +11,6 @@ declare class FileService {
|
|
|
14
11
|
type: "blob.upload-completed";
|
|
15
12
|
response: "ok";
|
|
16
13
|
}>;
|
|
17
|
-
/**
|
|
18
|
-
* Create a temporary file record
|
|
19
|
-
*/
|
|
20
14
|
createTemporaryFile(userId: string, body: z.infer<typeof CreateTemporaryFileSchema>): Promise<{
|
|
21
15
|
id: string;
|
|
22
16
|
url: string;
|
|
@@ -1,66 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { handleUpload } from "@vercel/blob/client";
|
|
3
|
-
import { logger } from "../../core/logging/pino";
|
|
4
|
-
import { FileSchema, GetVercelTokenResponse, } from "../../schemas";
|
|
5
|
-
class FileService {
|
|
6
|
-
constructor(prisma) {
|
|
7
|
-
this.prisma = prisma;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Get Vercel token for file upload
|
|
11
|
-
*/
|
|
12
|
-
getVercelToken(body, request) {
|
|
13
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
14
|
-
const jsonResponse = yield handleUpload({
|
|
15
|
-
body: body,
|
|
16
|
-
request,
|
|
17
|
-
onBeforeGenerateToken: () => __awaiter(this, void 0, void 0, function* () {
|
|
18
|
-
if (body.type !== "blob.generate-client-token") {
|
|
19
|
-
throw new Error("Invalid type");
|
|
20
|
-
}
|
|
21
|
-
if (!body.payload.clientPayload) {
|
|
22
|
-
throw new Error("clientPayload is required");
|
|
23
|
-
}
|
|
24
|
-
yield request.auth.getCurrentUser();
|
|
25
|
-
return {
|
|
26
|
-
addRandomSuffix: true,
|
|
27
|
-
allowedContentTypes: ["image/jpeg", "image/png", "image/gif"],
|
|
28
|
-
tokenPayload: body.payload.clientPayload,
|
|
29
|
-
};
|
|
30
|
-
}),
|
|
31
|
-
onUploadCompleted: (_a) => __awaiter(this, [_a], void 0, function* ({ blob, tokenPayload }) {
|
|
32
|
-
logger.info({ blob, tokenPayload }, "blob upload completed");
|
|
33
|
-
if (!tokenPayload) {
|
|
34
|
-
throw new Error("tokenPayload is required");
|
|
35
|
-
}
|
|
36
|
-
const { fileId } = JSON.parse(tokenPayload);
|
|
37
|
-
yield this.prisma.file.update({
|
|
38
|
-
where: {
|
|
39
|
-
id: fileId,
|
|
40
|
-
},
|
|
41
|
-
data: {
|
|
42
|
-
filename: blob.pathname,
|
|
43
|
-
url: blob.url,
|
|
44
|
-
mimeType: blob.contentType,
|
|
45
|
-
status: "completed",
|
|
46
|
-
},
|
|
47
|
-
});
|
|
48
|
-
}),
|
|
49
|
-
});
|
|
50
|
-
return GetVercelTokenResponse.parse(jsonResponse);
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Create a temporary file record
|
|
55
|
-
*/
|
|
56
|
-
createTemporaryFile(userId, body) {
|
|
57
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
-
const file = yield this.prisma.file.create({
|
|
59
|
-
data: Object.assign(Object.assign({}, body), { url: "-", createdBy: userId }),
|
|
60
|
-
});
|
|
61
|
-
return FileSchema.parse(file);
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
export { FileService };
|
|
66
|
-
//# sourceMappingURL=file.service.js.map
|
|
1
|
+
import{__awaiter as e}from"tslib";import{handleUpload as o}from"@vercel/blob/client";import{logger as t}from"../../core/logging/pino";import{FileSchema as r,GetVercelTokenResponse as i}from"../../schemas";class a{constructor(e){this.prisma=e}getVercelToken(r,a){return e(this,void 0,void 0,function*(){const n=yield o({body:r,request:a,onBeforeGenerateToken:()=>e(this,void 0,void 0,function*(){if("blob.generate-client-token"!==r.type)throw new Error("Invalid type");if(!r.payload.clientPayload)throw new Error("clientPayload is required");return yield a.auth.getCurrentUser(),{addRandomSuffix:!0,allowedContentTypes:["image/jpeg","image/png","image/gif"],tokenPayload:r.payload.clientPayload}}),onUploadCompleted:o=>e(this,[o],void 0,function*({blob:e,tokenPayload:o}){if(t.info({blob:e,tokenPayload:o},"blob upload completed"),!o)throw new Error("tokenPayload is required");const{fileId:r}=JSON.parse(o);yield this.prisma.file.update({where:{id:r},data:{filename:e.pathname,url:e.url,mimeType:e.contentType,status:"completed"}})})});return i.parse(n)})}createTemporaryFile(o,t){return e(this,void 0,void 0,function*(){const e=yield this.prisma.file.create({data:Object.assign(Object.assign({},t),{url:"-",createdBy:o})});return r.parse(e)})}}export{a as FileService};
|
|
@@ -1,10 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { healthRoute } from "./health.route";
|
|
3
|
-
export const buildHealthHandler = () => {
|
|
4
|
-
const app = createApiRouter();
|
|
5
|
-
app.openapi(healthRoute.ping, (c) => {
|
|
6
|
-
return c.json({ ok: true }, 200);
|
|
7
|
-
});
|
|
8
|
-
return app;
|
|
9
|
-
};
|
|
10
|
-
//# sourceMappingURL=health.handler.js.map
|
|
1
|
+
import{createApiRouter as o}from"../../core/hono/hono";import{healthRoute as r}from"./health.route";export const buildHealthHandler=()=>{const n=o();return n.openapi(r.ping,o=>o.json({ok:!0},200)),n};
|
|
@@ -1,25 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { createApiRoute } from "../../core/hono/hono";
|
|
3
|
-
import { ErrorSchema, HeaderSchema } from "../../schemas";
|
|
4
|
-
const pingRoute = createApiRoute({
|
|
5
|
-
description: "Pings the relevancy score service to check its availability",
|
|
6
|
-
headers: HeaderSchema,
|
|
7
|
-
method: "GET",
|
|
8
|
-
operationId: "ping",
|
|
9
|
-
path: "/ping",
|
|
10
|
-
responses: {
|
|
11
|
-
200: z.object({
|
|
12
|
-
ok: z.boolean().openapi({
|
|
13
|
-
description: "Indicates if the service is available",
|
|
14
|
-
example: true,
|
|
15
|
-
}),
|
|
16
|
-
}),
|
|
17
|
-
500: ErrorSchema,
|
|
18
|
-
},
|
|
19
|
-
summary: "Ping",
|
|
20
|
-
tags: ["Health"],
|
|
21
|
-
});
|
|
22
|
-
export const healthRoute = {
|
|
23
|
-
ping: pingRoute,
|
|
24
|
-
};
|
|
25
|
-
//# sourceMappingURL=health.route.js.map
|
|
1
|
+
import{z as e}from"@hono/zod-openapi";import{createApiRoute as o}from"../../core/hono/hono";import{ErrorSchema as i,HeaderSchema as t}from"../../schemas";const a=o({description:"Pings the relevancy score service to check its availability",headers:t,method:"GET",operationId:"ping",path:"/ping",responses:{200:e.object({ok:e.boolean().openapi({description:"Indicates if the service is available",example:!0})}),500:i},summary:"Ping",tags:["Health"]});export const healthRoute={ping:a};
|
package/src/features/index.js
CHANGED
|
@@ -1,16 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
export { buildCartHandler } from "./cart/cart.handler";
|
|
3
|
-
export { buildFileHandler } from "./file/file.handler";
|
|
4
|
-
export { buildHealthHandler } from "./health/health.handler";
|
|
5
|
-
export { buildLocationHandler } from "./location/location.handler";
|
|
6
|
-
export { buildManufacturerHandler } from "./manufacturer/manufacturer.handler";
|
|
7
|
-
export { buildOrderHandler } from "./order/order.handler";
|
|
8
|
-
export { buildOrganizationHandler } from "./organization/organization.handler";
|
|
9
|
-
export { buildPaymentHandler } from "./payment/payment.handler";
|
|
10
|
-
export { buildProductCategoryHandler } from "./product-category/product-category.handler";
|
|
11
|
-
export { buildProductHandler } from "./product/product.handler";
|
|
12
|
-
export { buildReservationHandler } from "./reservation/reservation.handler";
|
|
13
|
-
export { buildShippingHandler } from "./shipping/shipping.handler";
|
|
14
|
-
export { buildShippingMethodHandler } from "./shipping-method/shipping-method.handler";
|
|
15
|
-
export { buildWebhookHandler } from "./webhook/webhook.handler";
|
|
16
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export{buildAccessHandler}from"./access/access.handler";export{buildCartHandler}from"./cart/cart.handler";export{buildFileHandler}from"./file/file.handler";export{buildHealthHandler}from"./health/health.handler";export{buildLocationHandler}from"./location/location.handler";export{buildManufacturerHandler}from"./manufacturer/manufacturer.handler";export{buildOrderHandler}from"./order/order.handler";export{buildOrganizationHandler}from"./organization/organization.handler";export{buildPaymentHandler}from"./payment/payment.handler";export{buildProductCategoryHandler}from"./product-category/product-category.handler";export{buildProductHandler}from"./product/product.handler";export{buildReservationHandler}from"./reservation/reservation.handler";export{buildShippingHandler}from"./shipping/shipping.handler";export{buildShippingMethodHandler}from"./shipping-method/shipping-method.handler";export{buildWebhookHandler}from"./webhook/webhook.handler";
|
|
@@ -1,25 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createApiRouter } from "../../core/hono/hono";
|
|
3
|
-
import { locationRoute } from "./location.route";
|
|
4
|
-
import { LocationService } from "./location.service";
|
|
5
|
-
export const buildLocationHandler = (options) => {
|
|
6
|
-
const app = createApiRouter();
|
|
7
|
-
app.openapi(locationRoute.getPredictions, (c) => __awaiter(void 0, void 0, void 0, function* () {
|
|
8
|
-
const auth = c.get("auth");
|
|
9
|
-
const query = c.req.valid("query");
|
|
10
|
-
yield auth.getCurrentUser();
|
|
11
|
-
const service = new LocationService(options.google.key);
|
|
12
|
-
const predictions = yield service.getPredictions(query.query, query.radius);
|
|
13
|
-
return c.json(predictions, 200);
|
|
14
|
-
}));
|
|
15
|
-
app.openapi(locationRoute.getPlaceDetails, (c) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
-
const auth = c.get("auth");
|
|
17
|
-
const params = c.req.valid("param");
|
|
18
|
-
yield auth.getCurrentUser();
|
|
19
|
-
const service = new LocationService(options.google.key);
|
|
20
|
-
const placeDetails = yield service.getPlaceDetails(params.placeId);
|
|
21
|
-
return c.json(placeDetails, 200);
|
|
22
|
-
}));
|
|
23
|
-
return app;
|
|
24
|
-
};
|
|
25
|
-
//# sourceMappingURL=location.handler.js.map
|
|
1
|
+
import{__awaiter as o}from"tslib";import{createApiRouter as e}from"../../core/hono/hono";import{locationRoute as t}from"./location.route";import{LocationService as i}from"./location.service";export const buildLocationHandler=r=>{const n=e();return n.openapi(t.getPredictions,e=>o(void 0,void 0,void 0,function*(){const o=e.get("auth"),t=e.req.valid("query");yield o.getCurrentUser();const n=new i(r.google.key),a=yield n.getPredictions(t.query,t.radius);return e.json(a,200)})),n.openapi(t.getPlaceDetails,e=>o(void 0,void 0,void 0,function*(){const o=e.get("auth"),t=e.req.valid("param");yield o.getCurrentUser();const n=new i(r.google.key),a=yield n.getPlaceDetails(t.placeId);return e.json(a,200)})),n};
|
|
@@ -1,56 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { createApiRoute } from "../../core/hono/hono";
|
|
3
|
-
import { ErrorSchema, HeaderSchema, PlaceDetailsSchema, PlaceSchema, } from "../../schemas";
|
|
4
|
-
const getPredictionsRoute = createApiRoute({
|
|
5
|
-
description: "Returns a list of places for autocompletion based on a search query",
|
|
6
|
-
headers: HeaderSchema,
|
|
7
|
-
method: "GET",
|
|
8
|
-
operationId: "getPredictions",
|
|
9
|
-
path: "/places/prediction",
|
|
10
|
-
query: z.object({
|
|
11
|
-
query: z.string().openapi({
|
|
12
|
-
description: "Search query",
|
|
13
|
-
example: "123 Main St",
|
|
14
|
-
}),
|
|
15
|
-
radius: z.coerce.number().default(10000).openapi({
|
|
16
|
-
description: "Search radius in meters",
|
|
17
|
-
example: 10000,
|
|
18
|
-
}),
|
|
19
|
-
}),
|
|
20
|
-
responses: {
|
|
21
|
-
200: z.array(PlaceSchema),
|
|
22
|
-
400: ErrorSchema,
|
|
23
|
-
401: ErrorSchema,
|
|
24
|
-
},
|
|
25
|
-
summary: "Get Places Predictions",
|
|
26
|
-
tags: ["Location"],
|
|
27
|
-
});
|
|
28
|
-
const getPlaceDetailsRoute = createApiRoute({
|
|
29
|
-
description: "Returns details for a specific place based on its placeId",
|
|
30
|
-
headers: HeaderSchema,
|
|
31
|
-
method: "GET",
|
|
32
|
-
operationId: "getPlaceDetails",
|
|
33
|
-
path: "/places/:placeId",
|
|
34
|
-
pathParams: z.object({
|
|
35
|
-
placeId: z.string().openapi({
|
|
36
|
-
description: "The Google Place ID for the address",
|
|
37
|
-
example: "ChIJN1t_tKlj4AR4GeTYWZ7frY",
|
|
38
|
-
param: {
|
|
39
|
-
in: "path",
|
|
40
|
-
name: "placeId",
|
|
41
|
-
},
|
|
42
|
-
}),
|
|
43
|
-
}),
|
|
44
|
-
responses: {
|
|
45
|
-
200: PlaceDetailsSchema,
|
|
46
|
-
400: ErrorSchema,
|
|
47
|
-
401: ErrorSchema,
|
|
48
|
-
},
|
|
49
|
-
summary: "Get Place Details",
|
|
50
|
-
tags: ["Location"],
|
|
51
|
-
});
|
|
52
|
-
export const locationRoute = {
|
|
53
|
-
getPredictions: getPredictionsRoute,
|
|
54
|
-
getPlaceDetails: getPlaceDetailsRoute,
|
|
55
|
-
};
|
|
56
|
-
//# sourceMappingURL=location.route.js.map
|
|
1
|
+
import{z as e}from"@hono/zod-openapi";import{createApiRoute as a}from"../../core/hono/hono";import{ErrorSchema as o,HeaderSchema as t,PlaceDetailsSchema as r,PlaceSchema as s}from"../../schemas";const i=a({description:"Returns a list of places for autocompletion based on a search query",headers:t,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(s),400:o,401:o},summary:"Get Places Predictions",tags:["Location"]}),p=a({description:"Returns details for a specific place based on its placeId",headers:t,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:o,401:o},summary:"Get Place Details",tags:["Location"]});export const locationRoute={getPredictions:i,getPlaceDetails:p};
|
|
@@ -1,50 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
export const PlaceSchema = z
|
|
3
|
-
.object({
|
|
4
|
-
placeId: z.string().openapi({
|
|
5
|
-
example: "ChIJN1t_tKlj4AR4GeTYWZ7frY",
|
|
6
|
-
description: "The Google Place ID for the address",
|
|
7
|
-
}),
|
|
8
|
-
text: z.string().openapi({
|
|
9
|
-
example: "123 Main Street, New York, USA",
|
|
10
|
-
description: "The description of the place",
|
|
11
|
-
}),
|
|
12
|
-
addressLineOne: z.string().openapi({
|
|
13
|
-
example: "123 Main Street",
|
|
14
|
-
description: "The first line of the address",
|
|
15
|
-
}),
|
|
16
|
-
addressLineTwo: z.string().optional().openapi({
|
|
17
|
-
example: "Suite 100",
|
|
18
|
-
description: "The second line of the address",
|
|
19
|
-
}),
|
|
20
|
-
latitude: z.number().optional().openapi({
|
|
21
|
-
example: 40.712776,
|
|
22
|
-
description: "The latitude of the coordinate",
|
|
23
|
-
}),
|
|
24
|
-
longitude: z.number().optional().openapi({
|
|
25
|
-
example: -74.005974,
|
|
26
|
-
description: "The longitude of the coordinate",
|
|
27
|
-
}),
|
|
28
|
-
})
|
|
29
|
-
.openapi("Place");
|
|
30
|
-
export const PlaceDetailsSchema = z
|
|
31
|
-
.object({
|
|
32
|
-
addressLineOne: z.string().openapi({
|
|
33
|
-
example: "123 Main Street",
|
|
34
|
-
description: "The first line of the address",
|
|
35
|
-
}),
|
|
36
|
-
zipCode: z.string().optional().openapi({
|
|
37
|
-
example: "12345",
|
|
38
|
-
description: "The postal code of the address",
|
|
39
|
-
}),
|
|
40
|
-
city: z.string().openapi({
|
|
41
|
-
example: "New York",
|
|
42
|
-
description: "The city of the address",
|
|
43
|
-
}),
|
|
44
|
-
country: z.string().openapi({
|
|
45
|
-
example: "USA",
|
|
46
|
-
description: "The ISO 3166-1 alpha-2 country code",
|
|
47
|
-
}),
|
|
48
|
-
})
|
|
49
|
-
.openapi("PlaceDetails");
|
|
50
|
-
//# sourceMappingURL=location.schema.js.map
|
|
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");export const 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");
|
|
@@ -6,9 +6,6 @@ declare class LocationService {
|
|
|
6
6
|
readonly apiKey: string;
|
|
7
7
|
private client;
|
|
8
8
|
constructor(apiKey: string);
|
|
9
|
-
/**
|
|
10
|
-
* Get a list of places for autocompletion based on a search query
|
|
11
|
-
*/
|
|
12
9
|
getPredictions(query: string, radius: number): Promise<{
|
|
13
10
|
placeId: string;
|
|
14
11
|
text: string;
|
|
@@ -1,141 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import axios, { isAxiosError } from "axios";
|
|
3
|
-
import { logger } from "../../core/logging/pino";
|
|
4
|
-
class LocationService {
|
|
5
|
-
constructor(apiKey) {
|
|
6
|
-
this.apiKey = apiKey;
|
|
7
|
-
this.client = axios.create({
|
|
8
|
-
baseURL: "https://places.googleapis.com/v1",
|
|
9
|
-
headers: {
|
|
10
|
-
"Content-Type": "application/json",
|
|
11
|
-
"X-Goog-Api-Key": apiKey,
|
|
12
|
-
},
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Get a list of places for autocompletion based on a search query
|
|
17
|
-
*/
|
|
18
|
-
getPredictions(query, radius) {
|
|
19
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
-
var _a, _b, _c;
|
|
21
|
-
if (!query || query.trim() === "" || query.length < 3) {
|
|
22
|
-
return [];
|
|
23
|
-
}
|
|
24
|
-
try {
|
|
25
|
-
const { data } = yield this.client.post("/places:autocomplete", {
|
|
26
|
-
input: query,
|
|
27
|
-
locationBias: {
|
|
28
|
-
circle: {
|
|
29
|
-
center: {
|
|
30
|
-
latitude: 37.7937,
|
|
31
|
-
longitude: -122.3965,
|
|
32
|
-
},
|
|
33
|
-
radius: radius || 100000,
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
return data.suggestions.map(({ placePrediction }) => ({
|
|
38
|
-
placeId: placePrediction.placeId,
|
|
39
|
-
text: placePrediction.text.text,
|
|
40
|
-
addressLineOne: placePrediction.structuredFormat.mainText.text,
|
|
41
|
-
addressLineTwo: placePrediction.structuredFormat.secondaryText.text,
|
|
42
|
-
}));
|
|
43
|
-
}
|
|
44
|
-
catch (error) {
|
|
45
|
-
if (isAxiosError(error)) {
|
|
46
|
-
logger.error({
|
|
47
|
-
status: (_a = error.response) === null || _a === void 0 ? void 0 : _a.status,
|
|
48
|
-
statusText: (_b = error.response) === null || _b === void 0 ? void 0 : _b.statusText,
|
|
49
|
-
data: (_c = error.response) === null || _c === void 0 ? void 0 : _c.data,
|
|
50
|
-
query,
|
|
51
|
-
}, "Google Places Autocomplete request failed");
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
logger.error({ err: error, query }, "Unexpected error during Places Autocomplete");
|
|
55
|
-
}
|
|
56
|
-
throw error;
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
findDistanceBetweenCoordinates(from, to) {
|
|
61
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
62
|
-
// Helper function to convert degrees to radians
|
|
63
|
-
const toRadians = (degrees) => degrees * (Math.PI / 180);
|
|
64
|
-
// Earth's radius in kilometers
|
|
65
|
-
const earthRadiusKm = 6371;
|
|
66
|
-
// Convert latitude and longitude differences to radians
|
|
67
|
-
const dLat = toRadians(to.latitude - from.latitude);
|
|
68
|
-
const dLon = toRadians(to.longitude - from.longitude);
|
|
69
|
-
// Convert starting coordinates to radians
|
|
70
|
-
const lat1 = toRadians(from.latitude);
|
|
71
|
-
const lat2 = toRadians(to.latitude);
|
|
72
|
-
// Haversine formula
|
|
73
|
-
const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
|
|
74
|
-
Math.cos(lat1) * Math.cos(lat2) * Math.sin(dLon / 2) * Math.sin(dLon / 2);
|
|
75
|
-
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
|
76
|
-
// Calculate the distance
|
|
77
|
-
const distance = earthRadiusKm * c;
|
|
78
|
-
return distance;
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
getPlaceDetails(placeId) {
|
|
82
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
-
var _a, _b, _c;
|
|
84
|
-
let data;
|
|
85
|
-
try {
|
|
86
|
-
const response = yield this.client.get(`/places/${placeId}`, {
|
|
87
|
-
headers: {
|
|
88
|
-
"X-Goog-FieldMask": "addressComponents,adrFormatAddress,formattedAddress,location,plusCode,postalAddress,shortFormattedAddress,types",
|
|
89
|
-
},
|
|
90
|
-
});
|
|
91
|
-
data = response.data;
|
|
92
|
-
}
|
|
93
|
-
catch (error) {
|
|
94
|
-
if (isAxiosError(error)) {
|
|
95
|
-
logger.error({
|
|
96
|
-
status: (_a = error.response) === null || _a === void 0 ? void 0 : _a.status,
|
|
97
|
-
statusText: (_b = error.response) === null || _b === void 0 ? void 0 : _b.statusText,
|
|
98
|
-
data: (_c = error.response) === null || _c === void 0 ? void 0 : _c.data,
|
|
99
|
-
placeId,
|
|
100
|
-
}, "Google Place Details request failed");
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
logger.error({ err: error, placeId }, "Unexpected error during Place Details");
|
|
104
|
-
}
|
|
105
|
-
throw error;
|
|
106
|
-
}
|
|
107
|
-
const result = {
|
|
108
|
-
addressLineOne: "",
|
|
109
|
-
zipCode: "",
|
|
110
|
-
country: "",
|
|
111
|
-
city: "",
|
|
112
|
-
latitude: data.location.latitude,
|
|
113
|
-
longitude: data.location.longitude,
|
|
114
|
-
};
|
|
115
|
-
if (!data.addressComponents) {
|
|
116
|
-
return result;
|
|
117
|
-
}
|
|
118
|
-
for (const component of data.addressComponents) {
|
|
119
|
-
if (component.types.includes("street_number")) {
|
|
120
|
-
result.addressLineOne = component.shortText;
|
|
121
|
-
}
|
|
122
|
-
if (component.types.includes("route")) {
|
|
123
|
-
result.addressLineOne =
|
|
124
|
-
component.shortText + " " + result.addressLineOne;
|
|
125
|
-
}
|
|
126
|
-
if (component.types.includes("postal_code")) {
|
|
127
|
-
result.zipCode = component.shortText;
|
|
128
|
-
}
|
|
129
|
-
if (component.types.includes("country")) {
|
|
130
|
-
result.country = component.shortText;
|
|
131
|
-
}
|
|
132
|
-
if (component.types.includes("locality")) {
|
|
133
|
-
result.city = component.longText;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
return result;
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
export { LocationService };
|
|
141
|
-
//# sourceMappingURL=location.service.js.map
|
|
1
|
+
import{__awaiter as t}from"tslib";import e,{isAxiosError as s}from"axios";import{logger as o}from"../../core/logging/pino";class r{constructor(t){this.apiKey=t,this.client=e.create({baseURL:"https://places.googleapis.com/v1",headers:{"Content-Type":"application/json","X-Goog-Api-Key":t}})}getPredictions(e,r){return t(this,void 0,void 0,function*(){var t,i,a;if(!e||""===e.trim()||e.length<3)return[];try{const{data:t}=yield this.client.post("/places:autocomplete",{input:e,locationBias:{circle:{center:{latitude:37.7937,longitude:-122.3965},radius:r||1e5}}});return t.suggestions.map(({placePrediction:t})=>({placeId:t.placeId,text:t.text.text,addressLineOne:t.structuredFormat.mainText.text,addressLineTwo:t.structuredFormat.secondaryText.text}))}catch(r){throw s(r)?o.error({status:null===(t=r.response)||void 0===t?void 0:t.status,statusText:null===(i=r.response)||void 0===i?void 0:i.statusText,data:null===(a=r.response)||void 0===a?void 0:a.data,query:e},"Google Places Autocomplete request failed"):o.error({err:r,query:e},"Unexpected error during Places Autocomplete"),r}})}findDistanceBetweenCoordinates(e,s){return t(this,void 0,void 0,function*(){const t=t=>t*(Math.PI/180),o=t(s.latitude-e.latitude),r=t(s.longitude-e.longitude),i=t(e.latitude),a=t(s.latitude),d=Math.sin(o/2)*Math.sin(o/2)+Math.cos(i)*Math.cos(a)*Math.sin(r/2)*Math.sin(r/2);return 2*Math.atan2(Math.sqrt(d),Math.sqrt(1-d))*6371})}getPlaceDetails(e){return t(this,void 0,void 0,function*(){var t,r,i;let a;try{a=(yield this.client.get(`/places/${e}`,{headers:{"X-Goog-FieldMask":"addressComponents,adrFormatAddress,formattedAddress,location,plusCode,postalAddress,shortFormattedAddress,types"}})).data}catch(a){throw s(a)?o.error({status:null===(t=a.response)||void 0===t?void 0:t.status,statusText:null===(r=a.response)||void 0===r?void 0:r.statusText,data:null===(i=a.response)||void 0===i?void 0:i.data,placeId:e},"Google Place Details request failed"):o.error({err:a,placeId:e},"Unexpected error during Place Details"),a}const d={addressLineOne:"",zipCode:"",country:"",city:"",latitude:a.location.latitude,longitude:a.location.longitude};if(!a.addressComponents)return d;for(const t of a.addressComponents)t.types.includes("street_number")&&(d.addressLineOne=t.shortText),t.types.includes("route")&&(d.addressLineOne=t.shortText+" "+d.addressLineOne),t.types.includes("postal_code")&&(d.zipCode=t.shortText),t.types.includes("country")&&(d.country=t.shortText),t.types.includes("locality")&&(d.city=t.longText);return d})}}export{r as LocationService};
|
|
@@ -1,53 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createApiRouter } from "../../core/hono/hono";
|
|
3
|
-
import { manufacturerRoute } from "./manufacturer.route";
|
|
4
|
-
import { ManufacturerService } from "./manufacturer.service";
|
|
5
|
-
export const buildManufacturerHandler = (prisma) => {
|
|
6
|
-
const app = createApiRouter();
|
|
7
|
-
app.openapi(manufacturerRoute.createManufacturer, (c) => __awaiter(void 0, void 0, void 0, function* () {
|
|
8
|
-
const auth = c.get("auth");
|
|
9
|
-
const params = c.req.valid("param");
|
|
10
|
-
const body = c.req.valid("json");
|
|
11
|
-
const user = yield auth.isGranted("create");
|
|
12
|
-
const service = new ManufacturerService(prisma);
|
|
13
|
-
const manufacturer = yield service.createManufacturer(params.organizationId, user.id, body);
|
|
14
|
-
return c.json(manufacturer, 201);
|
|
15
|
-
}));
|
|
16
|
-
app.openapi(manufacturerRoute.getManufacturer, (c) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
-
const auth = c.get("auth");
|
|
18
|
-
const params = c.req.valid("param");
|
|
19
|
-
const query = c.req.valid("query");
|
|
20
|
-
yield auth.isGranted("read");
|
|
21
|
-
const service = new ManufacturerService(prisma);
|
|
22
|
-
const manufacturer = yield service.getManufacturer(params.organizationId, params.id, { locale: query.locale || null });
|
|
23
|
-
return c.json(manufacturer, 200);
|
|
24
|
-
}));
|
|
25
|
-
app.openapi(manufacturerRoute.getManufacturers, (c) => __awaiter(void 0, void 0, void 0, function* () {
|
|
26
|
-
const auth = c.get("auth");
|
|
27
|
-
const params = c.req.valid("param");
|
|
28
|
-
const query = c.req.valid("query");
|
|
29
|
-
yield auth.isGranted("read");
|
|
30
|
-
const service = new ManufacturerService(prisma);
|
|
31
|
-
const result = yield service.getManufacturers(params.organizationId, Object.assign(Object.assign({}, query), { locale: query.locale || null }));
|
|
32
|
-
return c.json(result, 200);
|
|
33
|
-
}));
|
|
34
|
-
app.openapi(manufacturerRoute.updateManufacturer, (c) => __awaiter(void 0, void 0, void 0, function* () {
|
|
35
|
-
const auth = c.get("auth");
|
|
36
|
-
const params = c.req.valid("param");
|
|
37
|
-
const body = c.req.valid("json");
|
|
38
|
-
const user = yield auth.isGranted("update");
|
|
39
|
-
const service = new ManufacturerService(prisma);
|
|
40
|
-
const updatedManufacturer = yield service.updateManufacturer(params.organizationId, params.id, user.id, body);
|
|
41
|
-
return c.json(updatedManufacturer, 200);
|
|
42
|
-
}));
|
|
43
|
-
app.openapi(manufacturerRoute.deleteManufacturer, (c) => __awaiter(void 0, void 0, void 0, function* () {
|
|
44
|
-
const auth = c.get("auth");
|
|
45
|
-
const params = c.req.valid("param");
|
|
46
|
-
const user = yield auth.isGranted("delete");
|
|
47
|
-
const service = new ManufacturerService(prisma);
|
|
48
|
-
yield service.deleteManufacturer(params.organizationId, params.id, user.id);
|
|
49
|
-
return c.body(null, 204);
|
|
50
|
-
}));
|
|
51
|
-
return app;
|
|
52
|
-
};
|
|
53
|
-
//# sourceMappingURL=manufacturer.handler.js.map
|
|
1
|
+
import{__awaiter as e}from"tslib";import{createApiRouter as a}from"../../core/hono/hono";import{manufacturerRoute as r}from"./manufacturer.route";import{ManufacturerService as n}from"./manufacturer.service";export const buildManufacturerHandler=t=>{const i=a();return i.openapi(r.createManufacturer,a=>e(void 0,void 0,void 0,function*(){const e=a.get("auth"),r=a.req.valid("param"),i=a.req.valid("json"),o=yield e.isGranted("create"),d=new n(t),u=yield d.createManufacturer(r.organizationId,o.id,i);return a.json(u,201)})),i.openapi(r.getManufacturer,a=>e(void 0,void 0,void 0,function*(){const e=a.get("auth"),r=a.req.valid("param"),i=a.req.valid("query");yield e.isGranted("read");const o=new n(t),d=yield o.getManufacturer(r.organizationId,r.id,{locale:i.locale||null});return a.json(d,200)})),i.openapi(r.getManufacturers,a=>e(void 0,void 0,void 0,function*(){const e=a.get("auth"),r=a.req.valid("param"),i=a.req.valid("query");yield e.isGranted("read");const o=new n(t),d=yield o.getManufacturers(r.organizationId,Object.assign(Object.assign({},i),{locale:i.locale||null}));return a.json(d,200)})),i.openapi(r.updateManufacturer,a=>e(void 0,void 0,void 0,function*(){const e=a.get("auth"),r=a.req.valid("param"),i=a.req.valid("json"),o=yield e.isGranted("update"),d=new n(t),u=yield d.updateManufacturer(r.organizationId,r.id,o.id,i);return a.json(u,200)})),i.openapi(r.deleteManufacturer,a=>e(void 0,void 0,void 0,function*(){const e=a.get("auth"),r=a.req.valid("param"),i=yield e.isGranted("delete"),o=new n(t);return yield o.deleteManufacturer(r.organizationId,r.id,i.id),a.body(null,204)})),i};
|