@vicacha-devs/medusa-plugin-b2b 0.0.0-stage → 0.0.1
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/.medusa/server/src/admin/index.cjs +8706 -0
- package/.medusa/server/src/admin/index.js +8683 -0
- package/.medusa/server/src/api/admin/b2b/approvals/[id]/route.js +24 -0
- package/.medusa/server/src/api/admin/b2b/approvals/middlewares.js +23 -0
- package/.medusa/server/src/api/admin/b2b/approvals/query-config.js +13 -0
- package/.medusa/server/src/api/admin/b2b/approvals/route.js +45 -0
- package/.medusa/server/src/api/admin/b2b/approvals/validators.js +15 -0
- package/.medusa/server/src/api/admin/b2b/companies/[id]/approval-settings/route.js +36 -0
- package/.medusa/server/src/api/admin/b2b/companies/[id]/customer-group/[customerGroupId]/route.js +10 -0
- package/.medusa/server/src/api/admin/b2b/companies/[id]/customer-group/route.js +35 -0
- package/.medusa/server/src/api/admin/b2b/companies/[id]/employees/[employeeId]/route.js +48 -0
- package/.medusa/server/src/api/admin/b2b/companies/[id]/employees/route.js +64 -0
- package/.medusa/server/src/api/admin/b2b/companies/[id]/route.js +48 -0
- package/.medusa/server/src/api/admin/b2b/companies/middlewares.js +77 -0
- package/.medusa/server/src/api/admin/b2b/companies/query-config.js +91 -0
- package/.medusa/server/src/api/admin/b2b/companies/route.js +68 -0
- package/.medusa/server/src/api/admin/b2b/companies/validators.js +113 -0
- package/.medusa/server/src/api/admin/b2b/customers/[id]/employee/route.js +20 -0
- package/.medusa/server/src/api/admin/b2b/quotes/[id]/messages/route.js +20 -0
- package/.medusa/server/src/api/admin/b2b/quotes/[id]/reject/route.js +19 -0
- package/.medusa/server/src/api/admin/b2b/quotes/[id]/route.js +30 -0
- package/.medusa/server/src/api/admin/b2b/quotes/[id]/send/route.js +19 -0
- package/.medusa/server/src/api/admin/b2b/quotes/middlewares.js +44 -0
- package/.medusa/server/src/api/admin/b2b/quotes/query-config.js +43 -0
- package/.medusa/server/src/api/admin/b2b/quotes/route.js +54 -0
- package/.medusa/server/src/api/admin/b2b/quotes/validators.js +37 -0
- package/.medusa/server/src/api/admin/companies/route.js +32 -0
- package/.medusa/server/src/api/admin/middlewares.js +9 -0
- package/.medusa/server/src/api/admin/validators.js +4 -0
- package/.medusa/server/src/api/admin/views/b2b-approvals/columns/route.js +119 -0
- package/.medusa/server/src/api/admin/views/b2b-companies/columns/route.js +144 -0
- package/.medusa/server/src/api/admin/views/b2b-company-employees/columns/route.js +73 -0
- package/.medusa/server/src/api/admin/views/b2b-quotes/columns/route.js +108 -0
- package/.medusa/server/src/api/middlewares/ensure-role.js +88 -0
- package/.medusa/server/src/api/middlewares.js +20 -0
- package/.medusa/server/src/api/store/b2b/approvals/[id]/route.js +24 -0
- package/.medusa/server/src/api/store/b2b/approvals/middlewares.js +71 -0
- package/.medusa/server/src/api/store/b2b/approvals/query-config.js +13 -0
- package/.medusa/server/src/api/store/b2b/approvals/route.js +76 -0
- package/.medusa/server/src/api/store/b2b/approvals/validators.js +22 -0
- package/.medusa/server/src/api/store/b2b/carts/[id]/approvals/route.js +24 -0
- package/.medusa/server/src/api/store/b2b/carts/[id]/line-items/bulk/route.js +26 -0
- package/.medusa/server/src/api/store/b2b/carts/middlewares.js +19 -0
- package/.medusa/server/src/api/store/b2b/carts/query-config.js +13 -0
- package/.medusa/server/src/api/store/b2b/carts/validators.js +12 -0
- package/.medusa/server/src/api/store/b2b/companies/[id]/approval-settings/route.js +21 -0
- package/.medusa/server/src/api/store/b2b/companies/[id]/employees/[employeeId]/route.js +53 -0
- package/.medusa/server/src/api/store/b2b/companies/[id]/employees/route.js +44 -0
- package/.medusa/server/src/api/store/b2b/companies/[id]/route.js +39 -0
- package/.medusa/server/src/api/store/b2b/companies/middlewares.js +94 -0
- package/.medusa/server/src/api/store/b2b/companies/query-config.js +62 -0
- package/.medusa/server/src/api/store/b2b/companies/route.js +18 -0
- package/.medusa/server/src/api/store/b2b/companies/validators.js +66 -0
- package/.medusa/server/src/api/store/b2b/free-shipping/middlewares.js +15 -0
- package/.medusa/server/src/api/store/b2b/free-shipping/prices/route.js +41 -0
- package/.medusa/server/src/api/store/b2b/free-shipping/utils.js +51 -0
- package/.medusa/server/src/api/store/b2b/free-shipping/validators.js +11 -0
- package/.medusa/server/src/api/store/b2b/quotes/[id]/accept/route.js +20 -0
- package/.medusa/server/src/api/store/b2b/quotes/[id]/messages/route.js +20 -0
- package/.medusa/server/src/api/store/b2b/quotes/[id]/preview/route.js +19 -0
- package/.medusa/server/src/api/store/b2b/quotes/[id]/reject/route.js +19 -0
- package/.medusa/server/src/api/store/b2b/quotes/[id]/route.js +15 -0
- package/.medusa/server/src/api/store/b2b/quotes/middlewares.js +64 -0
- package/.medusa/server/src/api/store/b2b/quotes/query-config.js +58 -0
- package/.medusa/server/src/api/store/b2b/quotes/route.js +39 -0
- package/.medusa/server/src/api/store/b2b/quotes/validators.js +35 -0
- package/.medusa/server/src/api/store/middlewares.js +13 -0
- package/.medusa/server/src/api/store/validators.js +6 -0
- package/.medusa/server/src/api/validators.js +3 -0
- package/.medusa/server/src/jobs/expire-quotes.js +22 -0
- package/.medusa/server/src/links/cart-approval-status.js +12 -0
- package/.medusa/server/src/links/cart-approvals.js +13 -0
- package/.medusa/server/src/links/company-approval-setting.js +5 -0
- package/.medusa/server/src/links/company-carts.js +12 -0
- package/.medusa/server/src/links/company-customer-group.js +11 -0
- package/.medusa/server/src/links/employee-customer.js +9 -0
- package/.medusa/server/src/links/order-company.js +9 -0
- package/.medusa/server/src/links/quote-links.js +77 -0
- package/.medusa/server/src/modules/approval/index.js +7 -0
- package/.medusa/server/src/modules/approval/migrations/Migration20260912010000.js +22 -0
- package/.medusa/server/src/modules/approval/models/approval-settings.js +21 -0
- package/.medusa/server/src/modules/approval/models/approval-status.js +21 -0
- package/.medusa/server/src/modules/approval/models/approval.js +36 -0
- package/.medusa/server/src/modules/approval/models/index.js +4 -0
- package/.medusa/server/src/modules/approval/service.js +18 -0
- package/.medusa/server/src/modules/company/index.js +7 -0
- package/.medusa/server/src/modules/company/migrations/Migration20260912010000.js +24 -0
- package/.medusa/server/src/modules/company/models/company.js +44 -0
- package/.medusa/server/src/modules/company/models/employee.js +30 -0
- package/.medusa/server/src/modules/company/models/index.js +3 -0
- package/.medusa/server/src/modules/company/service.js +9 -0
- package/.medusa/server/src/modules/company/types/common.js +2 -0
- package/.medusa/server/src/modules/company/types/mutations.js +2 -0
- package/.medusa/server/src/modules/quote/index.js +5 -0
- package/.medusa/server/src/modules/quote/migrations/Migration20260912010000.js +29 -0
- package/.medusa/server/src/modules/quote/models/index.js +3 -0
- package/.medusa/server/src/modules/quote/models/message.js +34 -0
- package/.medusa/server/src/modules/quote/models/quote.js +57 -0
- package/.medusa/server/src/modules/quote/service.js +6 -0
- package/.medusa/server/src/rbac.js +122 -0
- package/.medusa/server/src/scripts/seed-b2b-data.js +99 -0
- package/.medusa/server/src/scripts/seed-b2b-test-data.js +813 -0
- package/.medusa/server/src/types/approval/http.js +2 -0
- package/.medusa/server/src/types/approval/index.js +5 -0
- package/.medusa/server/src/types/approval/module.js +14 -0
- package/.medusa/server/src/types/approval/query.js +2 -0
- package/.medusa/server/src/types/approval/service.js +2 -0
- package/.medusa/server/src/types/company/http.js +2 -0
- package/.medusa/server/src/types/company/index.js +5 -0
- package/.medusa/server/src/types/company/module.js +3 -0
- package/.medusa/server/src/types/company/query.js +2 -0
- package/.medusa/server/src/types/company/service.js +2 -0
- package/.medusa/server/src/types/constants.js +16 -0
- package/.medusa/server/src/types/enums.js +18 -0
- package/.medusa/server/src/types/index.js +6 -0
- package/.medusa/server/src/types/quote/http.js +2 -0
- package/.medusa/server/src/types/quote/index.js +5 -0
- package/.medusa/server/src/types/quote/module.js +3 -0
- package/.medusa/server/src/types/quote/query.js +2 -0
- package/.medusa/server/src/types/quote/service.js +2 -0
- package/.medusa/server/src/types/shipping-options/http.js +2 -0
- package/.medusa/server/src/types/shipping-options/index.js +2 -0
- package/.medusa/server/src/types/types.js +2 -0
- package/.medusa/server/src/utils/check-spending-limit.js +51 -0
- package/.medusa/server/src/utils/get-cart-approval-status.js +22 -0
- package/.medusa/server/src/workflows/approval/steps/create-approval-settings.js +18 -0
- package/.medusa/server/src/workflows/approval/steps/create-approval-status.js +37 -0
- package/.medusa/server/src/workflows/approval/steps/create-approvals.js +55 -0
- package/.medusa/server/src/workflows/approval/steps/delete-approval-settings.js +23 -0
- package/.medusa/server/src/workflows/approval/steps/delete-approvals.js +11 -0
- package/.medusa/server/src/workflows/approval/steps/index.js +9 -0
- package/.medusa/server/src/workflows/approval/steps/update-approval-settings.js +12 -0
- package/.medusa/server/src/workflows/approval/steps/update-approval-statuses.js +49 -0
- package/.medusa/server/src/workflows/approval/steps/update-approval.js +60 -0
- package/.medusa/server/src/workflows/approval/workflows/create-approval-settings.js +20 -0
- package/.medusa/server/src/workflows/approval/workflows/create-approvals.js +43 -0
- package/.medusa/server/src/workflows/approval/workflows/index.js +5 -0
- package/.medusa/server/src/workflows/approval/workflows/update-approval-settings.js +6 -0
- package/.medusa/server/src/workflows/approval/workflows/update-approval.js +8 -0
- package/.medusa/server/src/workflows/company/steps/add-company-employees-to-customer-group.js +41 -0
- package/.medusa/server/src/workflows/company/steps/create-companies.js +14 -0
- package/.medusa/server/src/workflows/company/steps/delete-companies.js +11 -0
- package/.medusa/server/src/workflows/company/steps/dismiss-company-customer-group-link.js +40 -0
- package/.medusa/server/src/workflows/company/steps/index.js +7 -0
- package/.medusa/server/src/workflows/company/steps/remove-company-employees-from-customer-group.js +39 -0
- package/.medusa/server/src/workflows/company/steps/update-companies.js +14 -0
- package/.medusa/server/src/workflows/company/workflows/add-company-to-customer-group.js +25 -0
- package/.medusa/server/src/workflows/company/workflows/create-companies.js +21 -0
- package/.medusa/server/src/workflows/company/workflows/delete-companies.js +12 -0
- package/.medusa/server/src/workflows/company/workflows/index.js +6 -0
- package/.medusa/server/src/workflows/company/workflows/remove-company-from-customer-group.js +22 -0
- package/.medusa/server/src/workflows/company/workflows/update-companies.js +6 -0
- package/.medusa/server/src/workflows/employee/steps/add-employee-to-customer-group.js +41 -0
- package/.medusa/server/src/workflows/employee/steps/create-employees.js +20 -0
- package/.medusa/server/src/workflows/employee/steps/delete-employees.js +14 -0
- package/.medusa/server/src/workflows/employee/steps/index.js +8 -0
- package/.medusa/server/src/workflows/employee/steps/link-employee-to-customer.js +29 -0
- package/.medusa/server/src/workflows/employee/steps/remove-admin-role.js +37 -0
- package/.medusa/server/src/workflows/employee/steps/set-admin-role.js +56 -0
- package/.medusa/server/src/workflows/employee/steps/sync-customer-company-name.js +41 -0
- package/.medusa/server/src/workflows/employee/steps/update-employees.js +29 -0
- package/.medusa/server/src/workflows/employee/workflows/create-employees.js +34 -0
- package/.medusa/server/src/workflows/employee/workflows/delete-employees.js +15 -0
- package/.medusa/server/src/workflows/employee/workflows/index.js +4 -0
- package/.medusa/server/src/workflows/employee/workflows/update-employees.js +14 -0
- package/.medusa/server/src/workflows/hooks/cart-created.js +37 -0
- package/.medusa/server/src/workflows/hooks/order-created.js +30 -0
- package/.medusa/server/src/workflows/hooks/validate-add-to-cart.js +20 -0
- package/.medusa/server/src/workflows/hooks/validate-cart-completion.js +38 -0
- package/.medusa/server/src/workflows/hooks/validate-update-cart.js +20 -0
- package/.medusa/server/src/workflows/index.js +6 -0
- package/.medusa/server/src/workflows/order/steps/update-order.js +28 -0
- package/.medusa/server/src/workflows/order/workflows/update-order.js +21 -0
- package/.medusa/server/src/workflows/quote/steps/create-quote-message.js +18 -0
- package/.medusa/server/src/workflows/quote/steps/create-quotes.js +18 -0
- package/.medusa/server/src/workflows/quote/steps/update-quotes.js +28 -0
- package/.medusa/server/src/workflows/quote/steps/validate-quote-acceptance.js +11 -0
- package/.medusa/server/src/workflows/quote/steps/validate-quote-rejection.js +10 -0
- package/.medusa/server/src/workflows/quote/workflows/create-quote-message.js +11 -0
- package/.medusa/server/src/workflows/quote/workflows/create-quote.js +9 -0
- package/.medusa/server/src/workflows/quote/workflows/create-request-for-quote.js +84 -0
- package/.medusa/server/src/workflows/quote/workflows/customer-accept-quote.js +39 -0
- package/.medusa/server/src/workflows/quote/workflows/customer-reject-quote.js +27 -0
- package/.medusa/server/src/workflows/quote/workflows/index.js +9 -0
- package/.medusa/server/src/workflows/quote/workflows/merchant-reject-quote.js +28 -0
- package/.medusa/server/src/workflows/quote/workflows/merchant-send-quote.js +29 -0
- package/.medusa/server/src/workflows/quote/workflows/update-quote.js +9 -0
- package/LICENSE +21 -0
- package/README.md +587 -2
- package/package.json +121 -3
- package/src/__tests__/b2b-contract.spec.ts +41 -0
- package/src/admin/README.md +73 -0
- package/src/admin/constants.ts +1 -0
- package/src/admin/hooks/api/approvals.tsx +106 -0
- package/src/admin/hooks/api/companies.tsx +288 -0
- package/src/admin/hooks/api/customers.tsx +44 -0
- package/src/admin/hooks/api/employees.tsx +170 -0
- package/src/admin/hooks/api/index.ts +5 -0
- package/src/admin/hooks/api/quotes.tsx +329 -0
- package/src/admin/i18n/README.md +78 -0
- package/src/admin/i18n/index.ts +23 -0
- package/src/admin/i18n/json/ar.json +388 -0
- package/src/admin/i18n/json/de.json +388 -0
- package/src/admin/i18n/json/en.json +388 -0
- package/src/admin/i18n/json/es.json +388 -0
- package/src/admin/i18n/json/fr.json +388 -0
- package/src/admin/i18n/json/it.json +388 -0
- package/src/admin/i18n/json/nl.json +388 -0
- package/src/admin/i18n/json/pl.json +388 -0
- package/src/admin/i18n/json/pt.json +388 -0
- package/src/admin/i18n/json/tr.json +388 -0
- package/src/admin/routes/b2b/approvals/components/approval-actions.tsx +129 -0
- package/src/admin/routes/b2b/approvals/components/approval-status-badge.tsx +24 -0
- package/src/admin/routes/b2b/approvals/components/approvals-items-popover.tsx +69 -0
- package/src/admin/routes/b2b/approvals/components/approvals-table-adapter.tsx +45 -0
- package/src/admin/routes/b2b/approvals/components/approvals-table-renderers.tsx +74 -0
- package/src/admin/routes/b2b/approvals/components/approvals-table.tsx +66 -0
- package/src/admin/routes/b2b/approvals/components/table/columns.tsx +113 -0
- package/src/admin/routes/b2b/approvals/components/table/filters.tsx +30 -0
- package/src/admin/routes/b2b/approvals/components/table/query.tsx +25 -0
- package/src/admin/routes/b2b/approvals/page.tsx +66 -0
- package/src/admin/routes/b2b/companies/@create/page.tsx +70 -0
- package/src/admin/routes/b2b/companies/[id]/@approval-settings/page.tsx +106 -0
- package/src/admin/routes/b2b/companies/[id]/@customer-group/page.tsx +152 -0
- package/src/admin/routes/b2b/companies/[id]/@edit/page.tsx +93 -0
- package/src/admin/routes/b2b/companies/[id]/@employee/[employeeId]/page.tsx +82 -0
- package/src/admin/routes/b2b/companies/[id]/@employee/components/employees-actions-menu.tsx +61 -0
- package/src/admin/routes/b2b/companies/[id]/@employee/components/employees-create-form.tsx +190 -0
- package/src/admin/routes/b2b/companies/[id]/@employee/components/employees-update-form.tsx +160 -0
- package/src/admin/routes/b2b/companies/[id]/@employee/components/index.ts +3 -0
- package/src/admin/routes/b2b/companies/[id]/@employee/components/validators.ts +25 -0
- package/src/admin/routes/b2b/companies/[id]/@employee/create/page.tsx +91 -0
- package/src/admin/routes/b2b/companies/[id]/components/company-approval-settings-section.tsx +67 -0
- package/src/admin/routes/b2b/companies/[id]/components/company-customer-group-section.tsx +55 -0
- package/src/admin/routes/b2b/companies/[id]/components/company-employees-section.tsx +70 -0
- package/src/admin/routes/b2b/companies/[id]/components/company-employees-table-renderers.tsx +53 -0
- package/src/admin/routes/b2b/companies/[id]/components/company-general-section.tsx +59 -0
- package/src/admin/routes/b2b/companies/[id]/page.tsx +85 -0
- package/src/admin/routes/b2b/companies/components/companies-table-adapter.tsx +46 -0
- package/src/admin/routes/b2b/companies/components/companies-table-renderers.tsx +53 -0
- package/src/admin/routes/b2b/companies/components/companies-table.tsx +83 -0
- package/src/admin/routes/b2b/companies/components/company-actions-menu.tsx +46 -0
- package/src/admin/routes/b2b/companies/components/company-create-admin-tab.tsx +185 -0
- package/src/admin/routes/b2b/companies/components/company-create-details-tab.tsx +169 -0
- package/src/admin/routes/b2b/companies/components/company-create-form.tsx +201 -0
- package/src/admin/routes/b2b/companies/components/company-form-admin-tab.tsx +99 -0
- package/src/admin/routes/b2b/companies/components/company-form-details-tab.tsx +159 -0
- package/src/admin/routes/b2b/companies/components/company-form.tsx +159 -0
- package/src/admin/routes/b2b/companies/components/index.ts +9 -0
- package/src/admin/routes/b2b/companies/components/table/columns.tsx +81 -0
- package/src/admin/routes/b2b/companies/components/table/filters.tsx +23 -0
- package/src/admin/routes/b2b/companies/components/table/query.tsx +27 -0
- package/src/admin/routes/b2b/companies/components/use-delete-company-list-action.tsx +37 -0
- package/src/admin/routes/b2b/companies/components/validators.ts +49 -0
- package/src/admin/routes/b2b/companies/page.tsx +66 -0
- package/src/admin/routes/b2b/components/index.ts +6 -0
- package/src/admin/routes/b2b/components/navigation-card.tsx +51 -0
- package/src/admin/routes/b2b/components/stat-card.tsx +48 -0
- package/src/admin/routes/b2b/page.tsx +173 -0
- package/src/admin/routes/b2b/quotes/[id]/components/index.ts +8 -0
- package/src/admin/routes/b2b/quotes/[id]/components/quote-company-section.tsx +54 -0
- package/src/admin/routes/b2b/quotes/[id]/components/quote-customer-section.tsx +75 -0
- package/src/admin/routes/b2b/quotes/[id]/components/quote-detail-actions.tsx +57 -0
- package/src/admin/routes/b2b/quotes/[id]/components/quote-general-section.tsx +66 -0
- package/src/admin/routes/b2b/quotes/[id]/components/quote-message-bubble.tsx +132 -0
- package/src/admin/routes/b2b/quotes/[id]/components/quote-message-composer.tsx +135 -0
- package/src/admin/routes/b2b/quotes/[id]/components/quote-messages-section.tsx +100 -0
- package/src/admin/routes/b2b/quotes/[id]/components/quote-order-section.tsx +115 -0
- package/src/admin/routes/b2b/quotes/[id]/components/validators.ts +8 -0
- package/src/admin/routes/b2b/quotes/[id]/manage/components/index.ts +7 -0
- package/src/admin/routes/b2b/quotes/[id]/manage/components/manage-item-info.tsx +63 -0
- package/src/admin/routes/b2b/quotes/[id]/manage/components/manage-item-price-form.tsx +60 -0
- package/src/admin/routes/b2b/quotes/[id]/manage/components/manage-item.tsx +227 -0
- package/src/admin/routes/b2b/quotes/[id]/manage/components/manage-items-section.tsx +145 -0
- package/src/admin/routes/b2b/quotes/[id]/manage/components/manage-items-table.tsx +117 -0
- package/src/admin/routes/b2b/quotes/[id]/manage/components/manage-quote-form.tsx +187 -0
- package/src/admin/routes/b2b/quotes/[id]/manage/components/table/columns.tsx +29 -0
- package/src/admin/routes/b2b/quotes/[id]/manage/components/table/filters.tsx +8 -0
- package/src/admin/routes/b2b/quotes/[id]/manage/components/table/index.ts +3 -0
- package/src/admin/routes/b2b/quotes/[id]/manage/components/table/query.tsx +25 -0
- package/src/admin/routes/b2b/quotes/[id]/manage/components/validators.ts +5 -0
- package/src/admin/routes/b2b/quotes/[id]/manage/page.tsx +60 -0
- package/src/admin/routes/b2b/quotes/[id]/page.tsx +213 -0
- package/src/admin/routes/b2b/quotes/components/index.ts +4 -0
- package/src/admin/routes/b2b/quotes/components/quote-actions-menu.tsx +119 -0
- package/src/admin/routes/b2b/quotes/components/quote-status-badge.tsx +30 -0
- package/src/admin/routes/b2b/quotes/components/quotes-table-adapter.tsx +43 -0
- package/src/admin/routes/b2b/quotes/components/quotes-table-renderers.tsx +87 -0
- package/src/admin/routes/b2b/quotes/components/quotes-table.tsx +70 -0
- package/src/admin/routes/b2b/quotes/components/send-quote-drawer.tsx +69 -0
- package/src/admin/routes/b2b/quotes/components/table/columns.tsx +75 -0
- package/src/admin/routes/b2b/quotes/components/table/filters.tsx +44 -0
- package/src/admin/routes/b2b/quotes/components/table/query.tsx +27 -0
- package/src/admin/routes/b2b/quotes/page.tsx +65 -0
- package/src/admin/tsconfig.json +23 -0
- package/src/admin/validators.ts +4 -0
- package/src/admin/vite-env.d.ts +1 -0
- package/src/admin/widgets/customer-company-widget.tsx +63 -0
- package/src/admin/widgets/customer-employee-widget.tsx +48 -0
- package/src/admin/widgets/customer-group-companies-widget.tsx +68 -0
- package/src/api/README.md +64 -0
- package/src/api/admin/b2b/approvals/[id]/route.ts +34 -0
- package/src/api/admin/b2b/approvals/middlewares.ts +31 -0
- package/src/api/admin/b2b/approvals/query-config.ts +13 -0
- package/src/api/admin/b2b/approvals/route.ts +56 -0
- package/src/api/admin/b2b/approvals/validators.ts +23 -0
- package/src/api/admin/b2b/companies/[id]/approval-settings/route.ts +57 -0
- package/src/api/admin/b2b/companies/[id]/customer-group/[customerGroupId]/route.ts +17 -0
- package/src/api/admin/b2b/companies/[id]/customer-group/route.ts +56 -0
- package/src/api/admin/b2b/companies/[id]/employees/[employeeId]/route.ts +84 -0
- package/src/api/admin/b2b/companies/[id]/employees/route.ts +90 -0
- package/src/api/admin/b2b/companies/[id]/route.ts +88 -0
- package/src/api/admin/b2b/companies/middlewares.ts +123 -0
- package/src/api/admin/b2b/companies/query-config.ts +99 -0
- package/src/api/admin/b2b/companies/route.ts +101 -0
- package/src/api/admin/b2b/companies/validators.ts +165 -0
- package/src/api/admin/b2b/customers/[id]/employee/route.ts +31 -0
- package/src/api/admin/b2b/quotes/[id]/messages/route.ts +36 -0
- package/src/api/admin/b2b/quotes/[id]/reject/route.ts +35 -0
- package/src/api/admin/b2b/quotes/[id]/route.ts +48 -0
- package/src/api/admin/b2b/quotes/[id]/send/route.ts +35 -0
- package/src/api/admin/b2b/quotes/middlewares.ts +71 -0
- package/src/api/admin/b2b/quotes/query-config.ts +45 -0
- package/src/api/admin/b2b/quotes/route.ts +72 -0
- package/src/api/admin/b2b/quotes/validators.ts +49 -0
- package/src/api/admin/companies/route.ts +43 -0
- package/src/api/admin/middlewares.ts +10 -0
- package/src/api/admin/validators.ts +3 -0
- package/src/api/admin/views/b2b-approvals/columns/route.ts +121 -0
- package/src/api/admin/views/b2b-companies/columns/route.ts +146 -0
- package/src/api/admin/views/b2b-company-employees/columns/route.ts +74 -0
- package/src/api/admin/views/b2b-quotes/columns/route.ts +110 -0
- package/src/api/middlewares/ensure-role.ts +138 -0
- package/src/api/middlewares.ts +26 -0
- package/src/api/store/b2b/approvals/[id]/route.ts +34 -0
- package/src/api/store/b2b/approvals/middlewares.ts +103 -0
- package/src/api/store/b2b/approvals/query-config.ts +13 -0
- package/src/api/store/b2b/approvals/route.ts +105 -0
- package/src/api/store/b2b/approvals/validators.ts +30 -0
- package/src/api/store/b2b/carts/[id]/approvals/route.ts +33 -0
- package/src/api/store/b2b/carts/[id]/line-items/bulk/route.ts +46 -0
- package/src/api/store/b2b/carts/middlewares.ts +27 -0
- package/src/api/store/b2b/carts/query-config.ts +13 -0
- package/src/api/store/b2b/carts/validators.ts +19 -0
- package/src/api/store/b2b/companies/[id]/approval-settings/route.ts +33 -0
- package/src/api/store/b2b/companies/[id]/employees/[employeeId]/route.ts +86 -0
- package/src/api/store/b2b/companies/[id]/employees/route.ts +72 -0
- package/src/api/store/b2b/companies/[id]/route.ts +70 -0
- package/src/api/store/b2b/companies/middlewares.ts +137 -0
- package/src/api/store/b2b/companies/query-config.ts +76 -0
- package/src/api/store/b2b/companies/route.ts +34 -0
- package/src/api/store/b2b/companies/validators.ts +88 -0
- package/src/api/store/b2b/free-shipping/middlewares.ts +16 -0
- package/src/api/store/b2b/free-shipping/prices/route.ts +71 -0
- package/src/api/store/b2b/free-shipping/utils.ts +60 -0
- package/src/api/store/b2b/free-shipping/validators.ts +16 -0
- package/src/api/store/b2b/quotes/[id]/accept/route.ts +36 -0
- package/src/api/store/b2b/quotes/[id]/messages/route.ts +36 -0
- package/src/api/store/b2b/quotes/[id]/preview/route.ts +45 -0
- package/src/api/store/b2b/quotes/[id]/reject/route.ts +35 -0
- package/src/api/store/b2b/quotes/[id]/route.ts +30 -0
- package/src/api/store/b2b/quotes/middlewares.ts +96 -0
- package/src/api/store/b2b/quotes/query-config.ts +59 -0
- package/src/api/store/b2b/quotes/route.ts +65 -0
- package/src/api/store/b2b/quotes/validators.ts +51 -0
- package/src/api/store/middlewares.ts +14 -0
- package/src/api/store/validators.ts +5 -0
- package/src/api/validators.ts +2 -0
- package/src/jobs/expire-quotes.ts +31 -0
- package/src/links/README.md +62 -0
- package/src/links/cart-approval-status.ts +14 -0
- package/src/links/cart-approvals.ts +15 -0
- package/src/links/company-approval-setting.ts +8 -0
- package/src/links/company-carts.ts +14 -0
- package/src/links/company-customer-group.ts +16 -0
- package/src/links/employee-customer.ts +14 -0
- package/src/links/order-company.ts +14 -0
- package/src/links/quote-links.ts +77 -0
- package/src/modules/README.md +75 -0
- package/src/modules/approval/index.ts +8 -0
- package/src/modules/approval/migrations/Migration20260912010000.ts +47 -0
- package/src/modules/approval/models/approval-settings.ts +21 -0
- package/src/modules/approval/models/approval-status.ts +21 -0
- package/src/modules/approval/models/approval.ts +36 -0
- package/src/modules/approval/models/index.ts +3 -0
- package/src/modules/approval/service.ts +20 -0
- package/src/modules/company/index.ts +8 -0
- package/src/modules/company/migrations/Migration20260912010000.ts +50 -0
- package/src/modules/company/models/company.ts +44 -0
- package/src/modules/company/models/employee.ts +30 -0
- package/src/modules/company/models/index.ts +2 -0
- package/src/modules/company/service.ts +9 -0
- package/src/modules/company/types/common.ts +30 -0
- package/src/modules/company/types/mutations.ts +30 -0
- package/src/modules/quote/index.ts +6 -0
- package/src/modules/quote/migrations/Migration20260912010000.ts +65 -0
- package/src/modules/quote/models/index.ts +2 -0
- package/src/modules/quote/models/message.ts +35 -0
- package/src/modules/quote/models/quote.ts +58 -0
- package/src/modules/quote/service.ts +6 -0
- package/src/rbac.ts +136 -0
- package/src/scripts/README.md +40 -0
- package/src/scripts/seed-b2b-data.ts +177 -0
- package/src/scripts/seed-b2b-test-data.ts +986 -0
- package/src/types/README.md +52 -0
- package/src/types/approval/http.ts +56 -0
- package/src/types/approval/index.ts +4 -0
- package/src/types/approval/module.ts +77 -0
- package/src/types/approval/query.ts +11 -0
- package/src/types/approval/service.ts +126 -0
- package/src/types/company/http.ts +126 -0
- package/src/types/company/index.ts +4 -0
- package/src/types/company/module.ts +78 -0
- package/src/types/company/query.ts +15 -0
- package/src/types/company/service.ts +109 -0
- package/src/types/constants.ts +16 -0
- package/src/types/enums.ts +16 -0
- package/src/types/index.ts +5 -0
- package/src/types/quote/http.ts +50 -0
- package/src/types/quote/index.ts +4 -0
- package/src/types/quote/module.ts +45 -0
- package/src/types/quote/query.ts +22 -0
- package/src/types/quote/service.ts +65 -0
- package/src/types/shipping-options/http.ts +7 -0
- package/src/types/shipping-options/index.ts +1 -0
- package/src/types/types.ts +5 -0
- package/src/utils/README.md +37 -0
- package/src/utils/check-spending-limit.ts +81 -0
- package/src/utils/get-cart-approval-status.ts +35 -0
- package/src/workflows/README.md +85 -0
- package/src/workflows/approval/steps/create-approval-settings.ts +34 -0
- package/src/workflows/approval/steps/create-approval-status.ts +56 -0
- package/src/workflows/approval/steps/create-approvals.ts +114 -0
- package/src/workflows/approval/steps/delete-approval-settings.ts +52 -0
- package/src/workflows/approval/steps/delete-approvals.ts +21 -0
- package/src/workflows/approval/steps/index.ts +8 -0
- package/src/workflows/approval/steps/update-approval-settings.ts +27 -0
- package/src/workflows/approval/steps/update-approval-statuses.ts +77 -0
- package/src/workflows/approval/steps/update-approval.ts +87 -0
- package/src/workflows/approval/workflows/create-approval-settings.ts +32 -0
- package/src/workflows/approval/workflows/create-approvals.ts +60 -0
- package/src/workflows/approval/workflows/index.ts +4 -0
- package/src/workflows/approval/workflows/update-approval-settings.ts +13 -0
- package/src/workflows/approval/workflows/update-approval.ts +17 -0
- package/src/workflows/company/steps/add-company-employees-to-customer-group.ts +74 -0
- package/src/workflows/company/steps/create-companies.ts +28 -0
- package/src/workflows/company/steps/delete-companies.ts +21 -0
- package/src/workflows/company/steps/dismiss-company-customer-group-link.ts +53 -0
- package/src/workflows/company/steps/index.ts +6 -0
- package/src/workflows/company/steps/remove-company-employees-from-customer-group.ts +76 -0
- package/src/workflows/company/steps/update-companies.ts +25 -0
- package/src/workflows/company/workflows/add-company-to-customer-group.ts +34 -0
- package/src/workflows/company/workflows/create-companies.ts +35 -0
- package/src/workflows/company/workflows/delete-companies.ts +18 -0
- package/src/workflows/company/workflows/index.ts +5 -0
- package/src/workflows/company/workflows/remove-company-from-customer-group.ts +30 -0
- package/src/workflows/company/workflows/update-companies.ts +13 -0
- package/src/workflows/employee/steps/add-employee-to-customer-group.ts +81 -0
- package/src/workflows/employee/steps/create-employees.ts +46 -0
- package/src/workflows/employee/steps/delete-employees.ts +25 -0
- package/src/workflows/employee/steps/index.ts +7 -0
- package/src/workflows/employee/steps/link-employee-to-customer.ts +49 -0
- package/src/workflows/employee/steps/remove-admin-role.ts +59 -0
- package/src/workflows/employee/steps/set-admin-role.ts +89 -0
- package/src/workflows/employee/steps/sync-customer-company-name.ts +83 -0
- package/src/workflows/employee/steps/update-employees.ts +61 -0
- package/src/workflows/employee/workflows/create-employees.ts +61 -0
- package/src/workflows/employee/workflows/delete-employees.ts +26 -0
- package/src/workflows/employee/workflows/index.ts +3 -0
- package/src/workflows/employee/workflows/update-employees.ts +31 -0
- package/src/workflows/hooks/cart-created.ts +56 -0
- package/src/workflows/hooks/order-created.ts +38 -0
- package/src/workflows/hooks/validate-add-to-cart.ts +32 -0
- package/src/workflows/hooks/validate-cart-completion.ts +61 -0
- package/src/workflows/hooks/validate-update-cart.ts +32 -0
- package/src/workflows/index.ts +5 -0
- package/src/workflows/order/steps/update-order.ts +53 -0
- package/src/workflows/order/workflows/update-order.ts +28 -0
- package/src/workflows/quote/steps/create-quote-message.ts +33 -0
- package/src/workflows/quote/steps/create-quotes.ts +32 -0
- package/src/workflows/quote/steps/update-quotes.ts +48 -0
- package/src/workflows/quote/steps/validate-quote-acceptance.ts +22 -0
- package/src/workflows/quote/steps/validate-quote-rejection.ts +17 -0
- package/src/workflows/quote/workflows/create-quote-message.ts +20 -0
- package/src/workflows/quote/workflows/create-quote.ts +16 -0
- package/src/workflows/quote/workflows/create-request-for-quote.ts +102 -0
- package/src/workflows/quote/workflows/customer-accept-quote.ts +49 -0
- package/src/workflows/quote/workflows/customer-reject-quote.ts +31 -0
- package/src/workflows/quote/workflows/index.ts +8 -0
- package/src/workflows/quote/workflows/merchant-reject-quote.ts +34 -0
- package/src/workflows/quote/workflows/merchant-send-quote.ts +33 -0
- package/src/workflows/quote/workflows/update-quote.ts +16 -0
- package/tsconfig.json +40 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { CustomerDTO, CustomerGroupDTO } from "@medusajs/framework/types"
|
|
2
|
+
|
|
3
|
+
export interface CompanyDTO {
|
|
4
|
+
id: string
|
|
5
|
+
name: string
|
|
6
|
+
phone: string
|
|
7
|
+
email: string
|
|
8
|
+
address: string | null
|
|
9
|
+
city: string | null
|
|
10
|
+
state: string | null
|
|
11
|
+
zip: string | null
|
|
12
|
+
country: string | null
|
|
13
|
+
logo_url: string | null
|
|
14
|
+
employees?: EmployeeDTO[]
|
|
15
|
+
currency_code: string | null
|
|
16
|
+
customer_group?: CustomerGroupDTO
|
|
17
|
+
created_at: Date
|
|
18
|
+
updated_at: Date
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface EmployeeDTO extends CustomerDTO {
|
|
22
|
+
id: string
|
|
23
|
+
spending_limit: number
|
|
24
|
+
is_admin: boolean
|
|
25
|
+
company_id: string
|
|
26
|
+
company?: CompanyDTO
|
|
27
|
+
customer?: CustomerDTO
|
|
28
|
+
created_at: Date
|
|
29
|
+
updated_at: Date
|
|
30
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { CompanyDTO } from "./common"
|
|
2
|
+
import { EmployeeDTO } from "./common"
|
|
3
|
+
|
|
4
|
+
export interface CreateCompanyDTO extends Omit<
|
|
5
|
+
Partial<CompanyDTO>,
|
|
6
|
+
"id" | "createdAt" | "updatedAt"
|
|
7
|
+
> {}
|
|
8
|
+
|
|
9
|
+
export interface UpdateCompanyDTO extends Partial<CompanyDTO> {
|
|
10
|
+
id: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface DeleteCompanyDTO {
|
|
14
|
+
id: string
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface CreateEmployeeDTO extends Omit<
|
|
18
|
+
Partial<EmployeeDTO>,
|
|
19
|
+
"id" | "createdAt" | "updatedAt"
|
|
20
|
+
> {
|
|
21
|
+
customer_id: string
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface UpdateEmployeeDTO extends Partial<EmployeeDTO> {
|
|
25
|
+
id: string
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface DeleteEmployeeDTO {
|
|
29
|
+
id: string
|
|
30
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Migration } from "@medusajs/framework/mikro-orm/migrations"
|
|
2
|
+
|
|
3
|
+
export class Migration20260912010000 extends Migration {
|
|
4
|
+
async up(): Promise<void> {
|
|
5
|
+
// quote
|
|
6
|
+
this.addSql(
|
|
7
|
+
'create table if not exists "quote" ("id" text not null, "status" text check ("status" in (\'pending_merchant\', \'pending_customer\', \'accepted\', \'customer_rejected\', \'merchant_rejected\', \'expired\')) not null default \'pending_merchant\', "customer_id" text not null, "draft_order_id" text not null, "order_change_id" text null, "cart_id" text not null, "expires_at" timestamptz null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "quote_pkey" primary key ("id"));'
|
|
8
|
+
)
|
|
9
|
+
this.addSql(
|
|
10
|
+
'CREATE INDEX IF NOT EXISTS "IDX_quote_deleted_at" ON "quote" (deleted_at) WHERE deleted_at IS NULL;'
|
|
11
|
+
)
|
|
12
|
+
this.addSql(
|
|
13
|
+
'CREATE INDEX IF NOT EXISTS "IDX_quote_customer_id" ON "quote" (customer_id) WHERE deleted_at IS NULL;'
|
|
14
|
+
)
|
|
15
|
+
this.addSql(
|
|
16
|
+
'CREATE INDEX IF NOT EXISTS "IDX_quote_status" ON "quote" (status) WHERE deleted_at IS NULL;'
|
|
17
|
+
)
|
|
18
|
+
this.addSql(
|
|
19
|
+
'CREATE INDEX IF NOT EXISTS "IDX_quote_customer_status" ON "quote" (customer_id, status) WHERE deleted_at IS NULL;'
|
|
20
|
+
)
|
|
21
|
+
this.addSql(
|
|
22
|
+
'CREATE UNIQUE INDEX IF NOT EXISTS "IDX_quote_draft_order_id" ON "quote" (draft_order_id) WHERE deleted_at IS NULL;'
|
|
23
|
+
)
|
|
24
|
+
this.addSql(
|
|
25
|
+
'CREATE UNIQUE INDEX IF NOT EXISTS "IDX_quote_cart_id" ON "quote" (cart_id) WHERE deleted_at IS NULL;'
|
|
26
|
+
)
|
|
27
|
+
this.addSql(
|
|
28
|
+
'CREATE INDEX IF NOT EXISTS "IDX_quote_created_at" ON "quote" (created_at) WHERE deleted_at IS NULL;'
|
|
29
|
+
)
|
|
30
|
+
this.addSql(
|
|
31
|
+
'CREATE INDEX IF NOT EXISTS "IDX_quote_expires_at" ON "quote" (expires_at) WHERE deleted_at IS NULL AND expires_at IS NOT NULL;'
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
// message
|
|
35
|
+
this.addSql(
|
|
36
|
+
'create table if not exists "message" ("id" text not null, "text" text not null, "item_id" text null, "admin_id" text null, "customer_id" text null, "quote_id" text not null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "message_pkey" primary key ("id"));'
|
|
37
|
+
)
|
|
38
|
+
this.addSql(
|
|
39
|
+
'CREATE INDEX IF NOT EXISTS "IDX_message_deleted_at" ON "message" (deleted_at) WHERE deleted_at IS NULL;'
|
|
40
|
+
)
|
|
41
|
+
this.addSql(
|
|
42
|
+
'CREATE INDEX IF NOT EXISTS "IDX_message_quote_id_created_at" ON "message" (quote_id, created_at) WHERE deleted_at IS NULL;'
|
|
43
|
+
)
|
|
44
|
+
this.addSql(
|
|
45
|
+
'CREATE INDEX IF NOT EXISTS "IDX_message_customer_id" ON "message" (customer_id) WHERE deleted_at IS NULL AND customer_id IS NOT NULL;'
|
|
46
|
+
)
|
|
47
|
+
this.addSql(
|
|
48
|
+
'CREATE INDEX IF NOT EXISTS "IDX_message_admin_id" ON "message" (admin_id) WHERE deleted_at IS NULL AND admin_id IS NOT NULL;'
|
|
49
|
+
)
|
|
50
|
+
this.addSql(
|
|
51
|
+
'CREATE INDEX IF NOT EXISTS "IDX_message_item_id" ON "message" (item_id) WHERE deleted_at IS NULL AND item_id IS NOT NULL;'
|
|
52
|
+
)
|
|
53
|
+
this.addSql(
|
|
54
|
+
'alter table if exists "message" add constraint "message_quote_id_foreign" foreign key ("quote_id") references "quote" ("id") on update cascade;'
|
|
55
|
+
)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async down(): Promise<void> {
|
|
59
|
+
this.addSql(
|
|
60
|
+
'alter table if exists "message" drop constraint if exists "message_quote_id_foreign";'
|
|
61
|
+
)
|
|
62
|
+
this.addSql('drop table if exists "message" cascade;')
|
|
63
|
+
this.addSql('drop table if exists "quote" cascade;')
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { model } from "@medusajs/framework/utils"
|
|
2
|
+
|
|
3
|
+
import { Quote } from "./quote"
|
|
4
|
+
|
|
5
|
+
export const Message = model
|
|
6
|
+
.define("message", {
|
|
7
|
+
id: model.id({ prefix: "mess" }).primaryKey(),
|
|
8
|
+
text: model.text().searchable(),
|
|
9
|
+
item_id: model.text().nullable(),
|
|
10
|
+
admin_id: model.text().nullable(),
|
|
11
|
+
customer_id: model.text().nullable(),
|
|
12
|
+
quote: model.belongsTo(() => Quote, { mappedBy: "messages" }),
|
|
13
|
+
})
|
|
14
|
+
.indexes([
|
|
15
|
+
{
|
|
16
|
+
name: "IDX_message_quote_id_created_at",
|
|
17
|
+
on: ["quote_id", "created_at"],
|
|
18
|
+
where: "deleted_at IS NULL",
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
name: "IDX_message_customer_id",
|
|
22
|
+
on: ["customer_id"],
|
|
23
|
+
where: "deleted_at IS NULL AND customer_id IS NOT NULL",
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
name: "IDX_message_admin_id",
|
|
27
|
+
on: ["admin_id"],
|
|
28
|
+
where: "deleted_at IS NULL AND admin_id IS NOT NULL",
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: "IDX_message_item_id",
|
|
32
|
+
on: ["item_id"],
|
|
33
|
+
where: "deleted_at IS NULL AND item_id IS NOT NULL",
|
|
34
|
+
},
|
|
35
|
+
])
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { model } from "@medusajs/framework/utils"
|
|
2
|
+
import { EQuoteStatus } from "@b2b/types"
|
|
3
|
+
|
|
4
|
+
import { Message } from "./message"
|
|
5
|
+
|
|
6
|
+
export const Quote = model
|
|
7
|
+
.define("quote", {
|
|
8
|
+
id: model.id({ prefix: "quo" }).primaryKey(),
|
|
9
|
+
status: model.enum(EQuoteStatus).default(EQuoteStatus.PendingMerchant),
|
|
10
|
+
customer_id: model.text(),
|
|
11
|
+
draft_order_id: model.text(),
|
|
12
|
+
order_change_id: model.text().nullable(),
|
|
13
|
+
cart_id: model.text(),
|
|
14
|
+
expires_at: model.dateTime().nullable(),
|
|
15
|
+
messages: model.hasMany(() => Message, { mappedBy: "quote" }),
|
|
16
|
+
})
|
|
17
|
+
.cascades({
|
|
18
|
+
delete: ["messages"],
|
|
19
|
+
})
|
|
20
|
+
.indexes([
|
|
21
|
+
{
|
|
22
|
+
name: "IDX_quote_customer_id",
|
|
23
|
+
on: ["customer_id"],
|
|
24
|
+
where: "deleted_at IS NULL",
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
name: "IDX_quote_status",
|
|
28
|
+
on: ["status"],
|
|
29
|
+
where: "deleted_at IS NULL",
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
name: "IDX_quote_customer_status",
|
|
33
|
+
on: ["customer_id", "status"],
|
|
34
|
+
where: "deleted_at IS NULL",
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
name: "IDX_quote_draft_order_id",
|
|
38
|
+
on: ["draft_order_id"],
|
|
39
|
+
unique: true,
|
|
40
|
+
where: "deleted_at IS NULL",
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: "IDX_quote_cart_id",
|
|
44
|
+
on: ["cart_id"],
|
|
45
|
+
unique: true,
|
|
46
|
+
where: "deleted_at IS NULL",
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
name: "IDX_quote_created_at",
|
|
50
|
+
on: ["created_at"],
|
|
51
|
+
where: "deleted_at IS NULL",
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
name: "IDX_quote_expires_at",
|
|
55
|
+
on: ["expires_at"],
|
|
56
|
+
where: "deleted_at IS NULL AND expires_at IS NOT NULL",
|
|
57
|
+
},
|
|
58
|
+
])
|
package/src/rbac.ts
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
// Auto-generated RBAC descriptors compatible with @abhi1693/medusa-rbac AccessControlOptions.
|
|
2
|
+
export type RbacPermissionTuple = readonly [
|
|
3
|
+
id: string,
|
|
4
|
+
label: string,
|
|
5
|
+
group: string,
|
|
6
|
+
]
|
|
7
|
+
export type RbacRoutePolicy = {
|
|
8
|
+
method: string
|
|
9
|
+
path: string
|
|
10
|
+
permissions: string[]
|
|
11
|
+
superuser?: boolean
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const RBAC_PERMISSIONS: readonly RbacPermissionTuple[] = [
|
|
15
|
+
["b2b.read", "Read B2B companies, employees, quotes & approvals", "B2B"],
|
|
16
|
+
["b2b.write", "Manage B2B companies, employees, quotes & approvals", "B2B"],
|
|
17
|
+
] as const
|
|
18
|
+
|
|
19
|
+
export const RBAC_ROUTES: RbacRoutePolicy[] = [
|
|
20
|
+
{
|
|
21
|
+
method: "POST",
|
|
22
|
+
path: "/admin/b2b/approvals/:id",
|
|
23
|
+
permissions: ["b2b.write"],
|
|
24
|
+
},
|
|
25
|
+
{ method: "GET", path: "/admin/b2b/approvals", permissions: ["b2b.read"] },
|
|
26
|
+
{
|
|
27
|
+
method: "GET",
|
|
28
|
+
path: "/admin/b2b/companies/:id/approval-settings",
|
|
29
|
+
permissions: ["b2b.read"],
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
method: "POST",
|
|
33
|
+
path: "/admin/b2b/companies/:id/approval-settings",
|
|
34
|
+
permissions: ["b2b.write"],
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
method: "DELETE",
|
|
38
|
+
path: "/admin/b2b/companies/:id/customer-group/:customerGroupId",
|
|
39
|
+
permissions: ["b2b.write"],
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
method: "POST",
|
|
43
|
+
path: "/admin/b2b/companies/:id/customer-group",
|
|
44
|
+
permissions: ["b2b.write"],
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
method: "GET",
|
|
48
|
+
path: "/admin/b2b/companies/:id/employees/:employeeId",
|
|
49
|
+
permissions: ["b2b.read"],
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
method: "POST",
|
|
53
|
+
path: "/admin/b2b/companies/:id/employees/:employeeId",
|
|
54
|
+
permissions: ["b2b.write"],
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
method: "DELETE",
|
|
58
|
+
path: "/admin/b2b/companies/:id/employees/:employeeId",
|
|
59
|
+
permissions: ["b2b.write"],
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
method: "GET",
|
|
63
|
+
path: "/admin/b2b/companies/:id/employees",
|
|
64
|
+
permissions: ["b2b.read"],
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
method: "POST",
|
|
68
|
+
path: "/admin/b2b/companies/:id/employees",
|
|
69
|
+
permissions: ["b2b.write"],
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
method: "GET",
|
|
73
|
+
path: "/admin/b2b/companies/:id",
|
|
74
|
+
permissions: ["b2b.read"],
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
method: "POST",
|
|
78
|
+
path: "/admin/b2b/companies/:id",
|
|
79
|
+
permissions: ["b2b.write"],
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
method: "DELETE",
|
|
83
|
+
path: "/admin/b2b/companies/:id",
|
|
84
|
+
permissions: ["b2b.write"],
|
|
85
|
+
},
|
|
86
|
+
{ method: "GET", path: "/admin/b2b/companies", permissions: ["b2b.read"] },
|
|
87
|
+
{ method: "POST", path: "/admin/b2b/companies", permissions: ["b2b.write"] },
|
|
88
|
+
{
|
|
89
|
+
method: "GET",
|
|
90
|
+
path: "/admin/b2b/customers/:id/employee",
|
|
91
|
+
permissions: ["b2b.read"],
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
method: "POST",
|
|
95
|
+
path: "/admin/b2b/quotes/:id/messages",
|
|
96
|
+
permissions: ["b2b.write"],
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
method: "POST",
|
|
100
|
+
path: "/admin/b2b/quotes/:id/reject",
|
|
101
|
+
permissions: ["b2b.write"],
|
|
102
|
+
},
|
|
103
|
+
{ method: "GET", path: "/admin/b2b/quotes/:id", permissions: ["b2b.read"] },
|
|
104
|
+
{
|
|
105
|
+
method: "POST",
|
|
106
|
+
path: "/admin/b2b/quotes/:id/send",
|
|
107
|
+
permissions: ["b2b.write"],
|
|
108
|
+
},
|
|
109
|
+
{ method: "GET", path: "/admin/b2b/quotes", permissions: ["b2b.read"] },
|
|
110
|
+
{ method: "GET", path: "/admin/companies", permissions: ["b2b.read"] },
|
|
111
|
+
{
|
|
112
|
+
method: "GET",
|
|
113
|
+
path: "/admin/views/b2b-approvals/columns",
|
|
114
|
+
permissions: ["b2b.read"],
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
method: "GET",
|
|
118
|
+
path: "/admin/views/b2b-companies/columns",
|
|
119
|
+
permissions: ["b2b.read"],
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
method: "GET",
|
|
123
|
+
path: "/admin/views/b2b-company-employees/columns",
|
|
124
|
+
permissions: ["b2b.read"],
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
method: "GET",
|
|
128
|
+
path: "/admin/views/b2b-quotes/columns",
|
|
129
|
+
permissions: ["b2b.read"],
|
|
130
|
+
},
|
|
131
|
+
]
|
|
132
|
+
|
|
133
|
+
export const rbacAccess = {
|
|
134
|
+
permissions: [...RBAC_PERMISSIONS],
|
|
135
|
+
routes: RBAC_ROUTES,
|
|
136
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Scripts
|
|
2
|
+
|
|
3
|
+
Medusa exec scripts for data seeding and one-off operations.
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
scripts/
|
|
7
|
+
└── seed-b2b-data.ts creates baseline B2B data in a fresh database
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## `seed-b2b-data.ts`
|
|
13
|
+
|
|
14
|
+
Seeds the minimum data needed for a working B2B setup:
|
|
15
|
+
|
|
16
|
+
| Resource | What it creates | Guard |
|
|
17
|
+
| --------------- | ------------------------------------- | ---------------------------------------------- |
|
|
18
|
+
| Customer groups | `B2B` and `B2C` groups | Skips if a group with that name already exists |
|
|
19
|
+
| Sales channel | `B2B` sales channel | Skips if one already exists |
|
|
20
|
+
| Region | Default region with a shipping option | Skips if any region exists |
|
|
21
|
+
|
|
22
|
+
Run from the host application's root:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
medusa exec ./node_modules/@vicacha-devs/medusa-plugin-b2b/src/scripts/seed-b2b-data.ts
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Or, during development, from the plugin's root:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
medusa exec ./src/scripts/seed-b2b-data.ts
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Adding a script
|
|
35
|
+
|
|
36
|
+
1. Create a `.ts` file in this directory.
|
|
37
|
+
2. Export a default `async` function that accepts `{ container }` (the Medusa DI container).
|
|
38
|
+
3. Run it with `medusa exec ./src/scripts/<name>.ts`.
|
|
39
|
+
|
|
40
|
+
Scripts must be idempotent — check before creating so that re-running does not produce duplicate data.
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { MedusaContainer } from "@medusajs/framework"
|
|
2
|
+
import { linkSalesChannelsToStockLocationWorkflow } from "@medusajs/medusa/core-flows"
|
|
3
|
+
import {
|
|
4
|
+
ContainerRegistrationKeys,
|
|
5
|
+
MedusaError,
|
|
6
|
+
ModuleRegistrationName,
|
|
7
|
+
Modules,
|
|
8
|
+
} from "@medusajs/framework/utils"
|
|
9
|
+
|
|
10
|
+
export default async function seed_b2b_data({
|
|
11
|
+
container,
|
|
12
|
+
}: {
|
|
13
|
+
container: MedusaContainer
|
|
14
|
+
}) {
|
|
15
|
+
const logger = container.resolve(ContainerRegistrationKeys.LOGGER)
|
|
16
|
+
|
|
17
|
+
const customerModuleService = container.resolve(
|
|
18
|
+
ModuleRegistrationName.CUSTOMER
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
const salesChannelModuleService = container.resolve(
|
|
22
|
+
ModuleRegistrationName.SALES_CHANNEL
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
// ---------------------------------------------------------------------------
|
|
26
|
+
// Customer Groups
|
|
27
|
+
// ---------------------------------------------------------------------------
|
|
28
|
+
|
|
29
|
+
logger.info("Ensuring B2B/B2C customer groups exist...")
|
|
30
|
+
|
|
31
|
+
const existingCustomerGroups = await customerModuleService.listCustomerGroups(
|
|
32
|
+
{
|
|
33
|
+
name: {
|
|
34
|
+
$in: ["B2C", "B2B"],
|
|
35
|
+
},
|
|
36
|
+
}
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
const existingB2C = existingCustomerGroups.find(
|
|
40
|
+
(group) => group.name === "B2C"
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
const existingB2B = existingCustomerGroups.find(
|
|
44
|
+
(group) => group.name === "B2B"
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
const customerGroupsToCreate: { name: string }[] = []
|
|
48
|
+
|
|
49
|
+
if (!existingB2C) {
|
|
50
|
+
customerGroupsToCreate.push({
|
|
51
|
+
name: "B2C",
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (!existingB2B) {
|
|
56
|
+
customerGroupsToCreate.push({
|
|
57
|
+
name: "B2B",
|
|
58
|
+
})
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (customerGroupsToCreate.length) {
|
|
62
|
+
await customerModuleService.createCustomerGroups(customerGroupsToCreate)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const customerGroups = await customerModuleService.listCustomerGroups({
|
|
66
|
+
name: {
|
|
67
|
+
$in: ["B2C", "B2B"],
|
|
68
|
+
},
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
const b2cCustomerGroup = customerGroups.find((group) => group.name === "B2C")
|
|
72
|
+
|
|
73
|
+
const b2bCustomerGroup = customerGroups.find((group) => group.name === "B2B")
|
|
74
|
+
|
|
75
|
+
if (!b2cCustomerGroup || !b2bCustomerGroup) {
|
|
76
|
+
throw new MedusaError(
|
|
77
|
+
MedusaError.Types.CONFLICT,
|
|
78
|
+
"Failed to create/find B2B/B2C customer groups."
|
|
79
|
+
)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
logger.info(`B2C customer group: ${b2cCustomerGroup.id}`)
|
|
83
|
+
|
|
84
|
+
logger.info(`B2B customer group: ${b2bCustomerGroup.id}`)
|
|
85
|
+
|
|
86
|
+
// ---------------------------------------------------------------------------
|
|
87
|
+
// Sales Channels
|
|
88
|
+
// ---------------------------------------------------------------------------
|
|
89
|
+
|
|
90
|
+
logger.info("Ensuring B2B/B2C sales channels exist...")
|
|
91
|
+
|
|
92
|
+
const existingSalesChannels =
|
|
93
|
+
await salesChannelModuleService.listSalesChannels({
|
|
94
|
+
name: ["B2C", "B2B"],
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
const existingB2CSalesChannel = existingSalesChannels.find(
|
|
98
|
+
(channel) => channel.name === "B2C"
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
const existingB2BSalesChannel = existingSalesChannels.find(
|
|
102
|
+
(channel) => channel.name === "B2B"
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
const salesChannelsToCreate: { name: string; description: string }[] = []
|
|
106
|
+
|
|
107
|
+
if (!existingB2CSalesChannel) {
|
|
108
|
+
salesChannelsToCreate.push({
|
|
109
|
+
name: "B2C",
|
|
110
|
+
description: "Sales channel for B2C customers.",
|
|
111
|
+
})
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (!existingB2BSalesChannel) {
|
|
115
|
+
salesChannelsToCreate.push({
|
|
116
|
+
name: "B2B",
|
|
117
|
+
description: "Sales channel for B2B customers.",
|
|
118
|
+
})
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (salesChannelsToCreate.length) {
|
|
122
|
+
await salesChannelModuleService.createSalesChannels(salesChannelsToCreate)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const salesChannels = await salesChannelModuleService.listSalesChannels({
|
|
126
|
+
name: ["B2C", "B2B"],
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
const b2cSalesChannel = salesChannels.find(
|
|
130
|
+
(channel) => channel.name === "B2C"
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
const b2bSalesChannel = salesChannels.find(
|
|
134
|
+
(channel) => channel.name === "B2B"
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
if (!b2cSalesChannel || !b2bSalesChannel) {
|
|
138
|
+
throw new MedusaError(
|
|
139
|
+
MedusaError.Types.CONFLICT,
|
|
140
|
+
"Failed to create/find B2B/B2C sales channels."
|
|
141
|
+
)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
logger.info(`B2C sales channel: ${b2cSalesChannel.id}`)
|
|
145
|
+
|
|
146
|
+
logger.info(`B2B sales channel: ${b2bSalesChannel.id}`)
|
|
147
|
+
|
|
148
|
+
// ---------------------------------------------------------------------------
|
|
149
|
+
// Link sales channels to stock location
|
|
150
|
+
// ---------------------------------------------------------------------------
|
|
151
|
+
|
|
152
|
+
logger.info("Linking B2B/B2C sales channels to stock location...")
|
|
153
|
+
|
|
154
|
+
const stockLocationService = container.resolve(Modules.STOCK_LOCATION) as any
|
|
155
|
+
const [stockLocation] = await stockLocationService.listStockLocations(
|
|
156
|
+
{},
|
|
157
|
+
{ take: 1 }
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
if (stockLocation) {
|
|
161
|
+
await linkSalesChannelsToStockLocationWorkflow(container).run({
|
|
162
|
+
input: {
|
|
163
|
+
id: stockLocation.id,
|
|
164
|
+
add: [b2bSalesChannel.id, b2cSalesChannel.id],
|
|
165
|
+
},
|
|
166
|
+
})
|
|
167
|
+
logger.info(
|
|
168
|
+
`Linked B2B and B2C channels to stock location ${stockLocation.id} (${stockLocation.name})`
|
|
169
|
+
)
|
|
170
|
+
} else {
|
|
171
|
+
logger.warn(
|
|
172
|
+
"No stock location found — skipping sales channel linkage. Create a stock location first."
|
|
173
|
+
)
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
logger.info("Finished creating B2B/B2C data.")
|
|
177
|
+
}
|