@vicacha-devs/medusa-plugin-b2b 0.0.0-stage → 0.1.0
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 +126 -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,25 @@
|
|
|
1
|
+
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
|
2
|
+
import { ICompanyModuleService, ModuleUpdateCompany } from "@b2b/types"
|
|
3
|
+
import { COMPANY_MODULE } from "@b2b/modules/company"
|
|
4
|
+
|
|
5
|
+
export const updateCompaniesStep = createStep(
|
|
6
|
+
"update-companies",
|
|
7
|
+
async (input: ModuleUpdateCompany, { container }) => {
|
|
8
|
+
const companyModule =
|
|
9
|
+
container.resolve<ICompanyModuleService>(COMPANY_MODULE)
|
|
10
|
+
|
|
11
|
+
const [previousData] = await companyModule.listCompanies({
|
|
12
|
+
id: input.id,
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
const updatedCompanies = await companyModule.updateCompanies(input)
|
|
16
|
+
|
|
17
|
+
return new StepResponse(updatedCompanies, previousData)
|
|
18
|
+
},
|
|
19
|
+
async (previousData: ModuleUpdateCompany, { container }) => {
|
|
20
|
+
const companyModule =
|
|
21
|
+
container.resolve<ICompanyModuleService>(COMPANY_MODULE)
|
|
22
|
+
|
|
23
|
+
await companyModule.updateCompanies(previousData)
|
|
24
|
+
}
|
|
25
|
+
)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createWorkflow,
|
|
3
|
+
WorkflowResponse,
|
|
4
|
+
} from "@medusajs/framework/workflows-sdk"
|
|
5
|
+
import { createRemoteLinkStep } from "@medusajs/core-flows"
|
|
6
|
+
import { COMPANY_MODULE } from "@b2b/modules/company"
|
|
7
|
+
import { Modules } from "@medusajs/framework/utils"
|
|
8
|
+
import { addCompanyEmployeesToCustomerGroupStep } from "../steps/add-company-employees-to-customer-group"
|
|
9
|
+
import { dismissCompanyCustomerGroupLinkStep } from "../steps/dismiss-company-customer-group-link"
|
|
10
|
+
|
|
11
|
+
export const addCompanyToCustomerGroupWorkflow = createWorkflow(
|
|
12
|
+
"add-company-to-customer-group",
|
|
13
|
+
function (input: { company_id: string; group_id: string }) {
|
|
14
|
+
// Dismiss any existing link first — createRemoteLinkStep fails on duplicates
|
|
15
|
+
dismissCompanyCustomerGroupLinkStep({ company_id: input.company_id })
|
|
16
|
+
|
|
17
|
+
createRemoteLinkStep([
|
|
18
|
+
{
|
|
19
|
+
[COMPANY_MODULE]: {
|
|
20
|
+
company_id: input.company_id,
|
|
21
|
+
},
|
|
22
|
+
[Modules.CUSTOMER]: {
|
|
23
|
+
customer_group_id: input.group_id,
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
])
|
|
27
|
+
|
|
28
|
+
addCompanyEmployeesToCustomerGroupStep({
|
|
29
|
+
company_id: input.company_id,
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
return new WorkflowResponse(input)
|
|
33
|
+
}
|
|
34
|
+
)
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { createRemoteLinkStep } from "@medusajs/medusa/core-flows"
|
|
2
|
+
import {
|
|
3
|
+
createWorkflow,
|
|
4
|
+
transform,
|
|
5
|
+
WorkflowResponse,
|
|
6
|
+
} from "@medusajs/framework/workflows-sdk"
|
|
7
|
+
import { APPROVAL_MODULE } from "@b2b/modules/approval"
|
|
8
|
+
import { COMPANY_MODULE } from "@b2b/modules/company"
|
|
9
|
+
import { ModuleCreateCompany } from "@b2b/types"
|
|
10
|
+
import { createApprovalSettingsStep } from "@b2b/workflows/approval/steps/create-approval-settings"
|
|
11
|
+
import { createCompaniesStep } from "../steps"
|
|
12
|
+
|
|
13
|
+
export const createCompaniesWorkflow = createWorkflow(
|
|
14
|
+
"create-companies",
|
|
15
|
+
function (input: ModuleCreateCompany[]) {
|
|
16
|
+
const companies = createCompaniesStep(input)
|
|
17
|
+
|
|
18
|
+
const approvalSettings = createApprovalSettingsStep(companies)
|
|
19
|
+
|
|
20
|
+
const linkData = transform(approvalSettings, (settings) =>
|
|
21
|
+
settings.map((setting) => ({
|
|
22
|
+
[COMPANY_MODULE]: {
|
|
23
|
+
company_id: setting.company_id,
|
|
24
|
+
},
|
|
25
|
+
[APPROVAL_MODULE]: {
|
|
26
|
+
approval_settings_id: setting.id,
|
|
27
|
+
},
|
|
28
|
+
}))
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
createRemoteLinkStep(linkData)
|
|
32
|
+
|
|
33
|
+
return new WorkflowResponse(companies)
|
|
34
|
+
}
|
|
35
|
+
)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { WorkflowResponse } from "@medusajs/framework/workflows-sdk"
|
|
2
|
+
import { createWorkflow } from "@medusajs/framework/workflows-sdk"
|
|
3
|
+
import { ModuleDeleteCompany } from "@b2b/types"
|
|
4
|
+
import { deleteApprovalSettingsStep } from "@b2b/workflows/approval/steps/delete-approval-settings"
|
|
5
|
+
import { deleteCompaniesStep } from "../steps"
|
|
6
|
+
|
|
7
|
+
export const deleteCompaniesWorkflow = createWorkflow(
|
|
8
|
+
"delete-companies",
|
|
9
|
+
function (input: ModuleDeleteCompany) {
|
|
10
|
+
deleteCompaniesStep([input.id])
|
|
11
|
+
|
|
12
|
+
deleteApprovalSettingsStep({
|
|
13
|
+
companyIds: [input.id],
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
return new WorkflowResponse(undefined)
|
|
17
|
+
}
|
|
18
|
+
)
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Modules } from "@medusajs/framework/utils"
|
|
2
|
+
import { removeRemoteLinkStep } from "@medusajs/medusa/core-flows"
|
|
3
|
+
import {
|
|
4
|
+
createWorkflow,
|
|
5
|
+
WorkflowResponse,
|
|
6
|
+
} from "@medusajs/framework/workflows-sdk"
|
|
7
|
+
import { COMPANY_MODULE } from "@b2b/modules/company"
|
|
8
|
+
import { removeCompanyEmployeesFromCustomerGroupStep } from "../steps/remove-company-employees-from-customer-group"
|
|
9
|
+
|
|
10
|
+
export const removeCompanyFromCustomerGroupWorkflow = createWorkflow(
|
|
11
|
+
"remove-company-from-customer-group",
|
|
12
|
+
function (input: { company_id: string; group_id: string }) {
|
|
13
|
+
removeCompanyEmployeesFromCustomerGroupStep({
|
|
14
|
+
company_id: input.company_id,
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
removeRemoteLinkStep([
|
|
18
|
+
{
|
|
19
|
+
[COMPANY_MODULE]: {
|
|
20
|
+
company_id: input.company_id,
|
|
21
|
+
},
|
|
22
|
+
[Modules.CUSTOMER]: {
|
|
23
|
+
customer_group_id: input.group_id,
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
])
|
|
27
|
+
|
|
28
|
+
return new WorkflowResponse(input)
|
|
29
|
+
}
|
|
30
|
+
)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createWorkflow,
|
|
3
|
+
WorkflowResponse,
|
|
4
|
+
} from "@medusajs/framework/workflows-sdk"
|
|
5
|
+
import { ModuleUpdateCompany } from "@b2b/types"
|
|
6
|
+
import { updateCompaniesStep } from "../steps"
|
|
7
|
+
|
|
8
|
+
export const updateCompaniesWorkflow = createWorkflow(
|
|
9
|
+
"update-companies",
|
|
10
|
+
function (input: ModuleUpdateCompany) {
|
|
11
|
+
return new WorkflowResponse(updateCompaniesStep(input))
|
|
12
|
+
}
|
|
13
|
+
)
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { ICustomerModuleService } from "@medusajs/framework/types"
|
|
2
|
+
import { ContainerRegistrationKeys, Modules } from "@medusajs/framework/utils"
|
|
3
|
+
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
|
4
|
+
|
|
5
|
+
type AddEmployeeInput = { employee_id: string }
|
|
6
|
+
type AddEmployeeCompensate = {
|
|
7
|
+
customer_id: string | undefined
|
|
8
|
+
group_id: string | undefined
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const addEmployeeToCustomerGroupStep = createStep<
|
|
12
|
+
AddEmployeeInput,
|
|
13
|
+
unknown,
|
|
14
|
+
AddEmployeeCompensate
|
|
15
|
+
>(
|
|
16
|
+
"add-employee-to-customer-group",
|
|
17
|
+
async (input: AddEmployeeInput, { container }) => {
|
|
18
|
+
const query = container.resolve(ContainerRegistrationKeys.QUERY)
|
|
19
|
+
|
|
20
|
+
const {
|
|
21
|
+
data: [employee],
|
|
22
|
+
} = await query.graph(
|
|
23
|
+
{
|
|
24
|
+
entity: "employee",
|
|
25
|
+
filters: { id: input.employee_id },
|
|
26
|
+
fields: ["id", "customer.id", "company.id"],
|
|
27
|
+
},
|
|
28
|
+
{ throwIfKeyNotFound: true }
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
const {
|
|
32
|
+
data: [company],
|
|
33
|
+
} = await query.graph(
|
|
34
|
+
{
|
|
35
|
+
entity: "company",
|
|
36
|
+
filters: { id: employee.company.id },
|
|
37
|
+
fields: ["id", "customer_group.*"],
|
|
38
|
+
},
|
|
39
|
+
{ throwIfKeyNotFound: true }
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
const customerModuleService = container.resolve<ICustomerModuleService>(
|
|
43
|
+
Modules.CUSTOMER
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
if (!employee.customer?.id || !company.customer_group?.id) {
|
|
47
|
+
return new StepResponse(null, {
|
|
48
|
+
customer_id: employee.customer?.id,
|
|
49
|
+
group_id: company.customer_group?.id,
|
|
50
|
+
})
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
await customerModuleService.addCustomerToGroup({
|
|
54
|
+
customer_id: employee.customer.id,
|
|
55
|
+
customer_group_id: company.customer_group.id,
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
const customerGroup = await customerModuleService.retrieveCustomerGroup(
|
|
59
|
+
company.customer_group.id
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
return new StepResponse(customerGroup, {
|
|
63
|
+
customer_id: employee.customer.id,
|
|
64
|
+
group_id: company.customer_group.id,
|
|
65
|
+
})
|
|
66
|
+
},
|
|
67
|
+
async (input: AddEmployeeCompensate | undefined, { container }) => {
|
|
68
|
+
if (!input?.customer_id || !input?.group_id) {
|
|
69
|
+
return
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const customerModuleService = container.resolve<ICustomerModuleService>(
|
|
73
|
+
Modules.CUSTOMER
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
await customerModuleService.removeCustomerFromGroup({
|
|
77
|
+
customer_id: input.customer_id,
|
|
78
|
+
customer_group_id: input.group_id,
|
|
79
|
+
})
|
|
80
|
+
}
|
|
81
|
+
)
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ContainerRegistrationKeys } from "@medusajs/framework/utils"
|
|
2
|
+
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
|
3
|
+
import { COMPANY_MODULE } from "@b2b/modules/company"
|
|
4
|
+
import {
|
|
5
|
+
ICompanyModuleService,
|
|
6
|
+
ModuleCreateEmployee,
|
|
7
|
+
ModuleEmployee,
|
|
8
|
+
} from "@b2b/types"
|
|
9
|
+
|
|
10
|
+
export const createEmployeesStep = createStep<
|
|
11
|
+
ModuleCreateEmployee,
|
|
12
|
+
ModuleEmployee,
|
|
13
|
+
string
|
|
14
|
+
>(
|
|
15
|
+
"create-employees",
|
|
16
|
+
async (
|
|
17
|
+
input: ModuleCreateEmployee,
|
|
18
|
+
{ container }
|
|
19
|
+
): Promise<StepResponse<ModuleEmployee, string>> => {
|
|
20
|
+
const companyModuleService =
|
|
21
|
+
container.resolve<ICompanyModuleService>(COMPANY_MODULE)
|
|
22
|
+
|
|
23
|
+
const createdEmployee = await companyModuleService.createEmployees(input)
|
|
24
|
+
|
|
25
|
+
const query = container.resolve(ContainerRegistrationKeys.QUERY)
|
|
26
|
+
|
|
27
|
+
const {
|
|
28
|
+
data: [employee],
|
|
29
|
+
} = await query.graph(
|
|
30
|
+
{
|
|
31
|
+
entity: "employee",
|
|
32
|
+
filters: { id: createdEmployee.id },
|
|
33
|
+
fields: ["id", "company.*"],
|
|
34
|
+
},
|
|
35
|
+
{ throwIfKeyNotFound: true }
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
return new StepResponse(employee as unknown as ModuleEmployee, employee.id)
|
|
39
|
+
},
|
|
40
|
+
async (employeeId: string | undefined, { container }) => {
|
|
41
|
+
if (!employeeId) return
|
|
42
|
+
const companyModuleService =
|
|
43
|
+
container.resolve<ICompanyModuleService>(COMPANY_MODULE)
|
|
44
|
+
await companyModuleService.deleteEmployees([employeeId])
|
|
45
|
+
}
|
|
46
|
+
)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
|
2
|
+
import { COMPANY_MODULE } from "@b2b/modules/company"
|
|
3
|
+
import { ICompanyModuleService } from "@b2b/types"
|
|
4
|
+
|
|
5
|
+
export const deleteEmployeesStep = createStep(
|
|
6
|
+
"delete-employees",
|
|
7
|
+
async (
|
|
8
|
+
id: string | string[],
|
|
9
|
+
{ container }
|
|
10
|
+
): Promise<StepResponse<string[], string[]>> => {
|
|
11
|
+
const ids = Array.isArray(id) ? id : [id]
|
|
12
|
+
|
|
13
|
+
const companyModuleService =
|
|
14
|
+
container.resolve<ICompanyModuleService>(COMPANY_MODULE)
|
|
15
|
+
await companyModuleService.softDeleteEmployees(ids)
|
|
16
|
+
|
|
17
|
+
return new StepResponse(ids)
|
|
18
|
+
},
|
|
19
|
+
async (ids: string[] | undefined, { container }) => {
|
|
20
|
+
if (!ids) return
|
|
21
|
+
const companyModuleService =
|
|
22
|
+
container.resolve<ICompanyModuleService>(COMPANY_MODULE)
|
|
23
|
+
await companyModuleService.restoreEmployees(ids)
|
|
24
|
+
}
|
|
25
|
+
)
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from "./create-employees"
|
|
2
|
+
export * from "./delete-employees"
|
|
3
|
+
export * from "./link-employee-to-customer"
|
|
4
|
+
export * from "./remove-admin-role"
|
|
5
|
+
export * from "./set-admin-role"
|
|
6
|
+
export * from "./sync-customer-company-name"
|
|
7
|
+
export * from "./update-employees"
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ContainerRegistrationKeys, Modules } from "@medusajs/framework/utils"
|
|
2
|
+
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
|
3
|
+
import { COMPANY_MODULE } from "@b2b/modules/company"
|
|
4
|
+
|
|
5
|
+
export const linkEmployeeToCustomerStep = createStep(
|
|
6
|
+
"link-employee-to-customer",
|
|
7
|
+
async (
|
|
8
|
+
input: { employeeId: string; customerId: string },
|
|
9
|
+
{ container }
|
|
10
|
+
): Promise<
|
|
11
|
+
StepResponse<undefined, { employeeId: string; customerId: string }>
|
|
12
|
+
> => {
|
|
13
|
+
const remoteLink = container.resolve(ContainerRegistrationKeys.LINK)
|
|
14
|
+
|
|
15
|
+
const link = {
|
|
16
|
+
[COMPANY_MODULE]: {
|
|
17
|
+
employee_id: input.employeeId,
|
|
18
|
+
},
|
|
19
|
+
[Modules.CUSTOMER]: {
|
|
20
|
+
customer_id: input.customerId,
|
|
21
|
+
},
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
await remoteLink.create(link)
|
|
25
|
+
|
|
26
|
+
return new StepResponse(undefined, input)
|
|
27
|
+
},
|
|
28
|
+
async (
|
|
29
|
+
input: { employeeId: string; customerId: string },
|
|
30
|
+
{ container }
|
|
31
|
+
): Promise<
|
|
32
|
+
StepResponse<undefined, { employeeId: string; customerId: string }>
|
|
33
|
+
> => {
|
|
34
|
+
const remoteLink = container.resolve(ContainerRegistrationKeys.LINK)
|
|
35
|
+
|
|
36
|
+
const link = {
|
|
37
|
+
[COMPANY_MODULE]: {
|
|
38
|
+
employee_id: input.employeeId,
|
|
39
|
+
},
|
|
40
|
+
[Modules.CUSTOMER]: {
|
|
41
|
+
customer_id: input.customerId,
|
|
42
|
+
},
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
await remoteLink.dismiss(link)
|
|
46
|
+
|
|
47
|
+
return new StepResponse(undefined, input)
|
|
48
|
+
}
|
|
49
|
+
)
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { IAuthModuleService } from "@medusajs/framework/types"
|
|
2
|
+
import { Modules } from "@medusajs/framework/utils"
|
|
3
|
+
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
|
4
|
+
import { ContainerRegistrationKeys } from "@medusajs/framework/utils"
|
|
5
|
+
|
|
6
|
+
export const removeAdminRoleStep = createStep<
|
|
7
|
+
{ email: string },
|
|
8
|
+
undefined,
|
|
9
|
+
string
|
|
10
|
+
>(
|
|
11
|
+
"remove-admin-role",
|
|
12
|
+
async (
|
|
13
|
+
input: { email: string },
|
|
14
|
+
{ container }
|
|
15
|
+
): Promise<StepResponse<undefined, string>> => {
|
|
16
|
+
const authModuleService = container.resolve<IAuthModuleService>(
|
|
17
|
+
Modules.AUTH
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
const query = container.resolve(ContainerRegistrationKeys.QUERY)
|
|
21
|
+
|
|
22
|
+
const {
|
|
23
|
+
data: [providerIdentity],
|
|
24
|
+
} = await query.graph({
|
|
25
|
+
entity: "provider_identity",
|
|
26
|
+
fields: ["id"],
|
|
27
|
+
filters: {
|
|
28
|
+
provider: "emailpass",
|
|
29
|
+
entity_id: input.email,
|
|
30
|
+
},
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
await authModuleService.updateProviderIdentities([
|
|
34
|
+
{
|
|
35
|
+
id: providerIdentity.id,
|
|
36
|
+
user_metadata: {
|
|
37
|
+
role: null,
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
])
|
|
41
|
+
|
|
42
|
+
return new StepResponse(undefined, providerIdentity.id)
|
|
43
|
+
},
|
|
44
|
+
async (providerIdentityId: string | undefined, { container }) => {
|
|
45
|
+
if (!providerIdentityId) return
|
|
46
|
+
const authModuleService = container.resolve<IAuthModuleService>(
|
|
47
|
+
Modules.AUTH
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
await authModuleService.updateProviderIdentities([
|
|
51
|
+
{
|
|
52
|
+
id: providerIdentityId,
|
|
53
|
+
user_metadata: {
|
|
54
|
+
role: "company_admin",
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
])
|
|
58
|
+
}
|
|
59
|
+
)
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { IAuthModuleService } from "@medusajs/framework/types"
|
|
2
|
+
import { ContainerRegistrationKeys, Modules } from "@medusajs/framework/utils"
|
|
3
|
+
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
|
4
|
+
|
|
5
|
+
export const setAdminRoleStep = createStep(
|
|
6
|
+
"set-admin-role",
|
|
7
|
+
async (
|
|
8
|
+
input: { employeeId: string; customerId: string },
|
|
9
|
+
{ container }
|
|
10
|
+
): Promise<any> => {
|
|
11
|
+
const query = container.resolve(ContainerRegistrationKeys.QUERY)
|
|
12
|
+
|
|
13
|
+
const {
|
|
14
|
+
data: [employee],
|
|
15
|
+
} = await query.graph(
|
|
16
|
+
{
|
|
17
|
+
entity: "employee",
|
|
18
|
+
fields: ["id", "is_admin", "customer.has_account"],
|
|
19
|
+
filters: {
|
|
20
|
+
id: input.employeeId,
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
{ throwIfKeyNotFound: true }
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
if (employee.customer?.has_account === false) {
|
|
27
|
+
return new StepResponse(undefined, input)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const {
|
|
31
|
+
data: [customer],
|
|
32
|
+
} = await query.graph(
|
|
33
|
+
{
|
|
34
|
+
entity: "customer",
|
|
35
|
+
fields: ["email"],
|
|
36
|
+
filters: {
|
|
37
|
+
id: input.customerId,
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
{ throwIfKeyNotFound: true }
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
if (!customer.email) {
|
|
44
|
+
return new StepResponse(undefined, input)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const {
|
|
48
|
+
data: [providerIdentity],
|
|
49
|
+
} = await query.graph({
|
|
50
|
+
entity: "provider_identity",
|
|
51
|
+
fields: ["*"],
|
|
52
|
+
filters: {
|
|
53
|
+
provider: "emailpass",
|
|
54
|
+
entity_id: customer.email,
|
|
55
|
+
},
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
const authModuleService = container.resolve<IAuthModuleService>(
|
|
59
|
+
Modules.AUTH
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
if (providerIdentity) {
|
|
63
|
+
await authModuleService.updateProviderIdentities([
|
|
64
|
+
{
|
|
65
|
+
id: providerIdentity.id,
|
|
66
|
+
user_metadata: {
|
|
67
|
+
role: "company_admin",
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
])
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return new StepResponse(undefined, input)
|
|
74
|
+
},
|
|
75
|
+
async (input: { providerIdentityId: string }, { container }) => {
|
|
76
|
+
const authModuleService = container.resolve<IAuthModuleService>(
|
|
77
|
+
Modules.AUTH
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
await authModuleService.updateProviderIdentities([
|
|
81
|
+
{
|
|
82
|
+
id: input.providerIdentityId,
|
|
83
|
+
user_metadata: {
|
|
84
|
+
role: null,
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
])
|
|
88
|
+
}
|
|
89
|
+
)
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { ICustomerModuleService } from "@medusajs/framework/types"
|
|
2
|
+
import { ContainerRegistrationKeys, Modules } from "@medusajs/framework/utils"
|
|
3
|
+
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
|
4
|
+
|
|
5
|
+
type Input = { customerId: string; companyName: string | null }
|
|
6
|
+
|
|
7
|
+
export const syncCustomerCompanyNameStep = createStep(
|
|
8
|
+
"sync-customer-company-name",
|
|
9
|
+
async ({ customerId, companyName }: Input, { container }) => {
|
|
10
|
+
const customerModule = container.resolve<ICustomerModuleService>(
|
|
11
|
+
Modules.CUSTOMER
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
const [previous] = await customerModule.listCustomers(
|
|
15
|
+
{ id: customerId },
|
|
16
|
+
{ select: ["id", "company_name"] }
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
await customerModule.updateCustomers(customerId, {
|
|
20
|
+
company_name: companyName ?? "",
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
return new StepResponse(
|
|
24
|
+
{ customerId, companyName },
|
|
25
|
+
{ customerId, companyName: previous?.company_name ?? null }
|
|
26
|
+
)
|
|
27
|
+
},
|
|
28
|
+
async (previous: Input | undefined, { container }) => {
|
|
29
|
+
if (!previous) return
|
|
30
|
+
const customerModule = container.resolve<ICustomerModuleService>(
|
|
31
|
+
Modules.CUSTOMER
|
|
32
|
+
)
|
|
33
|
+
await customerModule.updateCustomers(previous.customerId, {
|
|
34
|
+
company_name: previous.companyName ?? "",
|
|
35
|
+
})
|
|
36
|
+
}
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
type ClearInput = { employeeId: string }
|
|
40
|
+
|
|
41
|
+
export const clearCustomerCompanyNameStep = createStep(
|
|
42
|
+
"clear-customer-company-name",
|
|
43
|
+
async ({ employeeId }: ClearInput, { container }) => {
|
|
44
|
+
const query = container.resolve(ContainerRegistrationKeys.QUERY)
|
|
45
|
+
const customerModule = container.resolve<ICustomerModuleService>(
|
|
46
|
+
Modules.CUSTOMER
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
const {
|
|
50
|
+
data: [employee],
|
|
51
|
+
} = await query.graph({
|
|
52
|
+
entity: "employee",
|
|
53
|
+
fields: ["id", "customer.id", "customer.company_name"],
|
|
54
|
+
filters: { id: employeeId },
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
const customerId = (employee as any)?.customer?.id
|
|
58
|
+
if (!customerId) {
|
|
59
|
+
return new StepResponse(null, null)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const previousName = (employee as any)?.customer?.company_name ?? null
|
|
63
|
+
|
|
64
|
+
await customerModule.updateCustomers(customerId, { company_name: "" })
|
|
65
|
+
|
|
66
|
+
return new StepResponse({ customerId }, { customerId, previousName })
|
|
67
|
+
},
|
|
68
|
+
async (
|
|
69
|
+
previous:
|
|
70
|
+
| { customerId: string; previousName: string | null }
|
|
71
|
+
| null
|
|
72
|
+
| undefined,
|
|
73
|
+
{ container }
|
|
74
|
+
) => {
|
|
75
|
+
if (!previous?.customerId) return
|
|
76
|
+
const customerModule = container.resolve<ICustomerModuleService>(
|
|
77
|
+
Modules.CUSTOMER
|
|
78
|
+
)
|
|
79
|
+
await customerModule.updateCustomers(previous.customerId, {
|
|
80
|
+
company_name: previous.previousName ?? "",
|
|
81
|
+
})
|
|
82
|
+
}
|
|
83
|
+
)
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { ContainerRegistrationKeys } from "@medusajs/framework/utils"
|
|
2
|
+
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
|
3
|
+
import { COMPANY_MODULE } from "@b2b/modules/company"
|
|
4
|
+
import {
|
|
5
|
+
ICompanyModuleService,
|
|
6
|
+
ModuleUpdateEmployee,
|
|
7
|
+
QueryEmployee,
|
|
8
|
+
} from "@b2b/types"
|
|
9
|
+
|
|
10
|
+
export const updateEmployeesStep = createStep<
|
|
11
|
+
ModuleUpdateEmployee,
|
|
12
|
+
QueryEmployee,
|
|
13
|
+
QueryEmployee
|
|
14
|
+
>(
|
|
15
|
+
"update-employees",
|
|
16
|
+
async (
|
|
17
|
+
input: ModuleUpdateEmployee,
|
|
18
|
+
{ container }
|
|
19
|
+
): Promise<StepResponse<QueryEmployee, QueryEmployee>> => {
|
|
20
|
+
const companyModuleService =
|
|
21
|
+
container.resolve<ICompanyModuleService>(COMPANY_MODULE)
|
|
22
|
+
|
|
23
|
+
const query = container.resolve(ContainerRegistrationKeys.QUERY)
|
|
24
|
+
|
|
25
|
+
const {
|
|
26
|
+
data: [currentData],
|
|
27
|
+
} = await query.graph({
|
|
28
|
+
entity: "employee",
|
|
29
|
+
fields: ["*"],
|
|
30
|
+
filters: {
|
|
31
|
+
id: input.id,
|
|
32
|
+
},
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
const updatedEmployee = await companyModuleService.updateEmployees(input)
|
|
36
|
+
|
|
37
|
+
const {
|
|
38
|
+
data: [employee],
|
|
39
|
+
} = await query.graph({
|
|
40
|
+
entity: "employee",
|
|
41
|
+
fields: ["*", "customer.*", "company.*"],
|
|
42
|
+
filters: {
|
|
43
|
+
id: updatedEmployee.id,
|
|
44
|
+
},
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
return new StepResponse(
|
|
48
|
+
employee as unknown as QueryEmployee,
|
|
49
|
+
currentData as unknown as QueryEmployee
|
|
50
|
+
)
|
|
51
|
+
},
|
|
52
|
+
async (currentData: QueryEmployee | undefined, { container }) => {
|
|
53
|
+
if (!currentData) return
|
|
54
|
+
const companyModuleService =
|
|
55
|
+
container.resolve<ICompanyModuleService>(COMPANY_MODULE)
|
|
56
|
+
|
|
57
|
+
await companyModuleService.updateEmployees(
|
|
58
|
+
currentData as unknown as ModuleUpdateEmployee
|
|
59
|
+
)
|
|
60
|
+
}
|
|
61
|
+
)
|