@unchainedshop/api 4.8.3 → 5.0.0-alpha.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.
Files changed (109) hide show
  1. package/lib/acl.js +30 -3
  2. package/lib/api-index.d.ts +3 -1
  3. package/lib/chat/generateImageHandler.js +6 -5
  4. package/lib/context.d.ts +4 -1
  5. package/lib/context.js +9 -3
  6. package/lib/events.d.ts +2 -0
  7. package/lib/events.js +2 -0
  8. package/lib/express/createMCPMiddleware.js +1 -1
  9. package/lib/express/index.d.ts +6 -9
  10. package/lib/express/index.js +52 -125
  11. package/lib/fastify/index.d.ts +6 -9
  12. package/lib/fastify/index.js +51 -117
  13. package/lib/fastify/mcpHandler.js +1 -1
  14. package/lib/loaders/buildTextMap.js +15 -13
  15. package/lib/locale-context.d.ts +4 -2
  16. package/lib/locale-context.js +2 -6
  17. package/lib/mcp/tools/assortment/assortmentManagement.d.ts +2 -2
  18. package/lib/mcp/tools/assortment/assortmentManagement.js +2 -2
  19. package/lib/mcp/tools/assortment/handlers/getAssortment.js +1 -1
  20. package/lib/mcp/tools/assortment/schemas.d.ts +322 -141
  21. package/lib/mcp/tools/assortment/schemas.js +179 -96
  22. package/lib/mcp/tools/filter/filterManagement.d.ts +2 -2
  23. package/lib/mcp/tools/filter/filterManagement.js +2 -2
  24. package/lib/mcp/tools/filter/schemas.d.ts +184 -75
  25. package/lib/mcp/tools/filter/schemas.js +87 -51
  26. package/lib/mcp/tools/localization/getLocalizationsConfig.d.ts +1 -1
  27. package/lib/mcp/tools/localization/localizationManagement.d.ts +2 -2
  28. package/lib/mcp/tools/localization/localizationManagement.js +2 -2
  29. package/lib/mcp/tools/localization/schemas.d.ts +144 -47
  30. package/lib/mcp/tools/localization/schemas.js +51 -36
  31. package/lib/mcp/tools/order/handlers/getTopCustomers.d.ts +2 -0
  32. package/lib/mcp/tools/order/orderManagement.d.ts +2 -2
  33. package/lib/mcp/tools/order/orderManagement.js +2 -2
  34. package/lib/mcp/tools/order/schemas.d.ts +184 -75
  35. package/lib/mcp/tools/order/schemas.js +113 -51
  36. package/lib/mcp/tools/product/handlers/getProduct.js +1 -1
  37. package/lib/mcp/tools/product/productManagement.d.ts +2 -2
  38. package/lib/mcp/tools/product/productManagement.js +2 -2
  39. package/lib/mcp/tools/product/schemas.d.ts +642 -317
  40. package/lib/mcp/tools/product/schemas.js +287 -191
  41. package/lib/mcp/tools/provider/providerManagement.d.ts +2 -2
  42. package/lib/mcp/tools/provider/providerManagement.js +2 -2
  43. package/lib/mcp/tools/provider/schemas.d.ts +142 -47
  44. package/lib/mcp/tools/provider/schemas.js +67 -32
  45. package/lib/mcp/tools/quotation/handlers/getQuotation.d.ts +2 -0
  46. package/lib/mcp/tools/quotation/handlers/listQuotations.d.ts +2 -0
  47. package/lib/mcp/tools/quotation/handlers/makeQuotationProposal.d.ts +2 -0
  48. package/lib/mcp/tools/quotation/handlers/rejectQuotation.d.ts +2 -0
  49. package/lib/mcp/tools/quotation/handlers/verifyQuotation.d.ts +2 -0
  50. package/lib/mcp/tools/quotation/quotationManagement.d.ts +2 -2
  51. package/lib/mcp/tools/quotation/quotationManagement.js +2 -2
  52. package/lib/mcp/tools/quotation/schemas.d.ts +111 -40
  53. package/lib/mcp/tools/quotation/schemas.js +54 -29
  54. package/lib/mcp/tools/system/handlers/countEvents.d.ts +8 -1
  55. package/lib/mcp/tools/system/handlers/countWork.d.ts +10 -1
  56. package/lib/mcp/tools/system/handlers/countWork.js +1 -0
  57. package/lib/mcp/tools/system/handlers/index.d.ts +4 -4
  58. package/lib/mcp/tools/system/handlers/listEvents.d.ts +12 -1
  59. package/lib/mcp/tools/system/handlers/listWork.d.ts +14 -1
  60. package/lib/mcp/tools/system/handlers/listWork.js +1 -0
  61. package/lib/mcp/tools/system/schemas.d.ts +179 -84
  62. package/lib/mcp/tools/system/schemas.js +188 -67
  63. package/lib/mcp/tools/system/systemManagement.d.ts +1 -1
  64. package/lib/mcp/tools/system/systemManagement.js +1 -1
  65. package/lib/mcp/tools/users/handlers/addUserEmail.d.ts +2 -0
  66. package/lib/mcp/tools/users/handlers/createUser.d.ts +2 -0
  67. package/lib/mcp/tools/users/handlers/enrollUser.d.ts +2 -0
  68. package/lib/mcp/tools/users/handlers/getCurrentUser.d.ts +2 -0
  69. package/lib/mcp/tools/users/handlers/getUser.d.ts +2 -0
  70. package/lib/mcp/tools/users/handlers/listUsers.d.ts +2 -0
  71. package/lib/mcp/tools/users/handlers/setUserTags.d.ts +2 -0
  72. package/lib/mcp/tools/users/handlers/setUserUsername.d.ts +2 -0
  73. package/lib/mcp/tools/users/handlers/updateUser.d.ts +2 -0
  74. package/lib/mcp/tools/users/schemas.d.ts +296 -163
  75. package/lib/mcp/tools/users/schemas.js +152 -71
  76. package/lib/mcp/tools/users/usersManagement.d.ts +2 -2
  77. package/lib/mcp/tools/users/usersManagement.js +2 -2
  78. package/lib/mcp/utils/getNormalizedQuotationDetails.d.ts +2 -0
  79. package/lib/mcp/utils/getNormalizedUserDetails.d.ts +2 -0
  80. package/lib/mcp/utils/normalizeMediaUrl.js +1 -1
  81. package/lib/mcp/utils/sanitizeLocalizationEntityData.d.ts +1 -1
  82. package/lib/mcp/utils/sharedSchemas.d.ts +28 -39
  83. package/lib/mcp/utils/sharedSchemas.js +28 -47
  84. package/lib/mcp/utils/validateIsoCode.d.ts +1 -1
  85. package/lib/resolvers/mutations/accounts/changePassword.js +1 -2
  86. package/lib/resolvers/mutations/index.d.ts +1 -6
  87. package/lib/resolvers/mutations/index.js +2 -12
  88. package/lib/resolvers/mutations/orders/updateCart.js +7 -1
  89. package/lib/resolvers/mutations/users/setRoles.d.ts +1 -1
  90. package/lib/resolvers/mutations/users/setRoles.js +8 -1
  91. package/lib/resolvers/queries/events/registeredEventTypes.d.ts +1 -1
  92. package/lib/resolvers/queries/events/registeredEventTypes.js +1 -1
  93. package/lib/resolvers/queries/index.d.ts +1 -1
  94. package/lib/resolvers/queries/index.js +1 -1
  95. package/lib/resolvers/type/index.d.ts +0 -1
  96. package/lib/resolvers/type/login-method-response-types.js +2 -1
  97. package/lib/resolvers/type/order/order-delivery-pickup-types.d.ts +0 -1
  98. package/lib/resolvers/type/order/order-delivery-pickup-types.js +0 -7
  99. package/lib/resolvers/type/shop-types.js +1 -1
  100. package/lib/resolvers/type/user-types.js +3 -3
  101. package/lib/roles/all.js +5 -3
  102. package/lib/roles/index.d.ts +4 -11
  103. package/lib/roles/index.js +16 -11
  104. package/lib/roles/loggedIn.js +2 -0
  105. package/lib/schema/mutation.js +6 -44
  106. package/lib/schema/query.js +5 -5
  107. package/lib/schema/types/index.js +2 -2
  108. package/lib/schema/types/order/delivery.js +0 -2
  109. package/package.json +13 -23
@@ -4,6 +4,7 @@ import loginWithPassword from "./accounts/loginWithPassword.js";
4
4
  import loginWithWebAuthn from "./accounts/loginWithWebAuthn.js";
5
5
  import loginAsGuest from "./accounts/loginAsGuest.js";
6
6
  import logout from "./accounts/logout.js";
7
+ import logoutAllSessions from "./accounts/logoutAllSessions.js";
7
8
  import impersonate from "./accounts/impersonate.js";
8
9
  import stopImpersonation from "./accounts/stopImpersonation.js";
9
10
  import changePassword from "./accounts/changePassword.js";
@@ -69,8 +70,6 @@ import updateCartItem from "./orders/updateCartItem.js";
69
70
  import removeCartItem from "./orders/removeCartItem.js";
70
71
  import removeCartDiscount from "./orders/removeCartDiscount.js";
71
72
  import removeOrder from "./orders/removeOrder.js";
72
- import setOrderPaymentProvider from "./orders/setOrderPaymentProvider.js";
73
- import setOrderDeliveryProvider from "./orders/setOrderDeliveryProvider.js";
74
73
  import confirmOrder from "./orders/confirmOrder.js";
75
74
  import payOrder from "./orders/payOrder.js";
76
75
  import deliverOrder from "./orders/deliverOrder.js";
@@ -134,10 +133,6 @@ import updateEnrollment from "./enrollments/updateEnrollment.js";
134
133
  import registerPaymentCredentials from "./payment/registerPaymentCredentials.js";
135
134
  import markPaymentCredentialsPreferred from "./payment/markPaymentCredentialsPreferred.js";
136
135
  import removePaymentCredentials from "./payment/removePaymentCredentials.js";
137
- import updateOrderDeliveryShipping from "./orders/updateOrderDeliveryShipping.js";
138
- import updateOrderDeliveryPickUp from "./orders/updateOrderDeliveryPickUp.js";
139
- import updateOrderPaymentGeneric from "./orders/updateOrderPaymentGeneric.js";
140
- import updateOrderPaymentInvoice from "./orders/updateOrderPaymentInvoice.js";
141
136
  import signPaymentProviderForCredentialRegistration from "./payment/signPaymentProviderForCredentialRegistration.js";
142
137
  import signPaymentProviderForCheckout from "./orders/signPaymentProviderForCheckout.js";
143
138
  import pageView from "./pageView.js";
@@ -157,6 +152,7 @@ import updateCartPaymentGeneric from "./orders/updateCartPaymentGeneric.js";
157
152
  import updateCartPaymentInvoice from "./orders/updateCartPaymentInvoice.js";
158
153
  export default {
159
154
  logout: acl(actions.logout)(logout),
155
+ logoutAllSessions: acl(actions.logoutAllSessions)(logoutAllSessions),
160
156
  loginAsGuest: acl(actions.loginAsGuest)(loginAsGuest),
161
157
  impersonate: acl(actions.impersonate)(impersonate),
162
158
  stopImpersonation: acl(actions.stopImpersonation)(stopImpersonation),
@@ -242,12 +238,6 @@ export default {
242
238
  updateCartDeliveryShipping: acl(actions.updateCart)(updateCartDeliveryShipping),
243
239
  updateCartPaymentGeneric: acl(actions.updateCart)(updateCartPaymentGeneric),
244
240
  updateCartPaymentInvoice: acl(actions.updateCart)(updateCartPaymentInvoice),
245
- setOrderPaymentProvider: acl(actions.updateOrder)(setOrderPaymentProvider),
246
- setOrderDeliveryProvider: acl(actions.updateOrder)(setOrderDeliveryProvider),
247
- updateOrderDeliveryShipping: acl(actions.updateOrderDelivery)(updateOrderDeliveryShipping),
248
- updateOrderDeliveryPickUp: acl(actions.updateOrderDelivery)(updateOrderDeliveryPickUp),
249
- updateOrderPaymentGeneric: acl(actions.updateOrderPayment)(updateOrderPaymentGeneric),
250
- updateOrderPaymentInvoice: acl(actions.updateOrderPayment)(updateOrderPaymentInvoice),
251
241
  removeOrder: acl(actions.updateOrder)(removeOrder),
252
242
  confirmOrder: acl(actions.markOrderConfirmed)(confirmOrder),
253
243
  rejectOrder: acl(actions.markOrderRejected)(rejectOrder),
@@ -1,9 +1,15 @@
1
1
  import { log } from '@unchainedshop/logger';
2
- import { OrderNotFoundError, OrderWrongStatusError } from "../../../errors.js";
2
+ import { InvalidIdError, OrderNotFoundError, OrderWrongStatusError } from "../../../errors.js";
3
3
  export default async function updateCart(root, params, context) {
4
4
  const { orderId, billingAddress, contact, paymentProviderId, deliveryProviderId, meta } = params;
5
5
  const { modules, services, userId, user } = context;
6
6
  log('mutation updateCart', { userId });
7
+ if (orderId === '')
8
+ throw new InvalidIdError({ orderId });
9
+ if (paymentProviderId === '')
10
+ throw new InvalidIdError({ paymentProviderId });
11
+ if (deliveryProviderId === '')
12
+ throw new InvalidIdError({ deliveryProviderId });
7
13
  const order = await services.orders.findOrInitCart({
8
14
  orderId,
9
15
  user: user,
@@ -2,4 +2,4 @@ import type { Context } from '../../../context.ts';
2
2
  export default function setRoles(root: never, params: {
3
3
  roles: string[];
4
4
  userId: string;
5
- }, { modules, userId }: Context): Promise<import("mongodb").WithId<import("@unchainedshop/core-users").User> | null>;
5
+ }, context: Context): Promise<import("mongodb").WithId<import("@unchainedshop/core-users").User> | null>;
@@ -1,11 +1,18 @@
1
1
  import { log } from '@unchainedshop/logger';
2
2
  import { InvalidIdError, UserNotFoundError } from "../../../errors.js";
3
- export default async function setRoles(root, params, { modules, userId }) {
3
+ import { getPublicRoles } from "../../../roles/index.js";
4
+ export default async function setRoles(root, params, context) {
5
+ const { modules, userId } = context;
4
6
  const foreignUserId = params.userId;
5
7
  log(`mutation setRoles ${foreignUserId}`, { userId });
6
8
  if (!foreignUserId)
7
9
  throw new InvalidIdError({ foreignUserId });
8
10
  if (!(await modules.users.userExists({ userId: foreignUserId })))
9
11
  throw new UserNotFoundError({ userId: foreignUserId });
12
+ const publicRoles = getPublicRoles(context.roles);
13
+ const invalidRoles = params.roles.filter((r) => !publicRoles.includes(r));
14
+ if (invalidRoles.length) {
15
+ throw new Error(`Invalid role names: ${invalidRoles.join(', ')}`);
16
+ }
10
17
  return modules.users.updateRoles(foreignUserId, params.roles);
11
18
  }
@@ -1 +1 @@
1
- export default function registeredEventTypes(): string[];
1
+ export default function registeredEventTypes(): Promise<string[]>;
@@ -1,4 +1,4 @@
1
1
  import { getRegisteredEvents } from '@unchainedshop/events';
2
- export default function registeredEventTypes() {
2
+ export default async function registeredEventTypes() {
3
3
  return getRegisteredEvents();
4
4
  }
@@ -68,10 +68,10 @@ declare const _default: {
68
68
  event: (root: any, params: any, context: any, ...other: any[]) => Promise<any>;
69
69
  events: (root: any, params: any, context: any, ...other: any[]) => Promise<any>;
70
70
  eventsCount: (root: any, params: any, context: any, ...other: any[]) => Promise<any>;
71
- registeredEventTypes: (root: any, params: any, context: any, ...other: any[]) => Promise<any>;
72
71
  validateResetPasswordToken: (root: any, params: any, context: any, ...other: any[]) => Promise<any>;
73
72
  validateVerifyEmailToken: (root: any, params: any, context: any, ...other: any[]) => Promise<any>;
74
73
  workStatistics: (root: any, params: any, context: any, ...other: any[]) => Promise<any>;
74
+ registeredEventTypes: (root: any, params: any, context: any, ...other: any[]) => Promise<any>;
75
75
  eventStatistics: (root: any, params: any, context: any, ...other: any[]) => Promise<any>;
76
76
  orderStatistics: (root: any, params: any, context: any, ...other: any[]) => Promise<any>;
77
77
  };
@@ -141,10 +141,10 @@ export default {
141
141
  event: acl(actions.viewEvent)(event),
142
142
  events: acl(actions.viewEvents)(events),
143
143
  eventsCount: acl(actions.viewEvents)(eventsCount),
144
- registeredEventTypes: acl(actions.viewEvents)(registeredEventTypes),
145
144
  validateResetPasswordToken: acl(actions.resetPassword)(validateResetPasswordToken),
146
145
  validateVerifyEmailToken: acl(actions.verifyEmail)(validateVerifyEmailToken),
147
146
  workStatistics: acl(actions.viewStatistics)(workStatistics),
147
+ registeredEventTypes: acl(actions.viewEvents)(registeredEventTypes),
148
148
  eventStatistics: acl(actions.viewStatistics)(eventStatistics),
149
149
  orderStatistics: acl(actions.viewStatistics)(orderStatistics),
150
150
  };
@@ -330,7 +330,6 @@ declare const types: {
330
330
  };
331
331
  OrderDeliveryPickUp: {
332
332
  activePickUpLocation(orderDelivery: import("@unchainedshop/core-orders").OrderDelivery, _: never, requestContext: import("../../context.ts").Context): Promise<import("@unchainedshop/core-delivery").DeliveryLocation | null>;
333
- pickUpLocations(obj: import("@unchainedshop/core-orders").OrderDelivery, _: never, context: import("../../context.ts").Context): Promise<import("@unchainedshop/core-delivery").DeliveryLocation[]>;
334
333
  provider(obj: import("@unchainedshop/core-orders").OrderDelivery, _: never, { loaders }: import("../../context.ts").Context): Promise<import("@unchainedshop/core-delivery").DeliveryProvider>;
335
334
  status(obj: import("@unchainedshop/core-orders").OrderDelivery, _: never, { modules }: import("../../context.ts").Context): import("@unchainedshop/core-orders").OrderDeliveryStatus;
336
335
  discounts(obj: import("@unchainedshop/core-orders").OrderDelivery, _: never, { loaders }: import("../../context.ts").Context): Promise<{
@@ -1,6 +1,7 @@
1
+ import { IN_LOGIN_RESPONSE } from "../../context.js";
1
2
  export const LoginMethodResponse = {
2
3
  user({ user }) {
3
- user._inLoginMethodResponse = true;
4
+ user[IN_LOGIN_RESPONSE] = true;
4
5
  return user;
5
6
  },
6
7
  };
@@ -2,7 +2,6 @@ import type { Context } from '../../../context.ts';
2
2
  import type { OrderDelivery } from '@unchainedshop/core-orders';
3
3
  export declare const OrderDeliveryPickUp: {
4
4
  activePickUpLocation(orderDelivery: OrderDelivery, _: never, requestContext: Context): Promise<import("@unchainedshop/core-delivery").DeliveryLocation | null>;
5
- pickUpLocations(obj: OrderDelivery, _: never, context: Context): Promise<import("@unchainedshop/core-delivery").DeliveryLocation[]>;
6
5
  provider(obj: OrderDelivery, _: never, { loaders }: Context): Promise<import("@unchainedshop/core-delivery").DeliveryProvider>;
7
6
  status(obj: OrderDelivery, _: never, { modules }: Context): import("@unchainedshop/core-orders").OrderDeliveryStatus;
8
7
  discounts(obj: OrderDelivery, _: never, { loaders }: Context): Promise<{
@@ -8,13 +8,6 @@ export const OrderDeliveryPickUp = {
8
8
  const director = await DeliveryDirector.actions(provider, { orderDelivery: orderDelivery }, requestContext);
9
9
  return director.pickUpLocationById(orderPickUpLocationId);
10
10
  },
11
- async pickUpLocations(obj, _, context) {
12
- const provider = await context.loaders.deliveryProviderLoader.load({
13
- deliveryProviderId: obj.deliveryProviderId,
14
- });
15
- const director = await DeliveryDirector.actions(provider, { orderDelivery: obj }, context);
16
- return director.pickUpLocations();
17
- },
18
11
  async provider(obj, _, { loaders }) {
19
12
  return loaders.deliveryProviderLoader.load({
20
13
  deliveryProviderId: obj.deliveryProviderId,
@@ -12,6 +12,6 @@ export const Shop = {
12
12
  },
13
13
  userRoles: async (_root, _params, context) => {
14
14
  await checkAction(context, actions.manageUsers);
15
- return getPublicRoles();
15
+ return getPublicRoles(context.roles);
16
16
  },
17
17
  };
@@ -1,4 +1,4 @@
1
- import { Roles, permissions } from '@unchainedshop/roles';
1
+ import { permissions } from '@unchainedshop/roles';
2
2
  import { checkAction, checkTypeResolver } from "../../acl.js";
3
3
  import { actions } from "../../roles/index.js";
4
4
  const { viewUserPrivateInfos, viewUserPublicInfos, viewUserOrders, viewUserEnrollments, viewUserQuotations, viewUserProductReviews, } = actions;
@@ -90,8 +90,8 @@ export const User = {
90
90
  },
91
91
  allowedActions: async (user, params, context) => {
92
92
  await checkAction(context, viewUserPrivateInfos, [user, params]);
93
- const userRoles = Roles.getUserRoles(user?._id, user.roles, true);
94
- return permissions(userRoles, context.roles);
93
+ const userRoles = context.roles.getUserRoles(user?._id, user.roles, true);
94
+ return permissions(userRoles, context.roles.roles);
95
95
  },
96
96
  orders: async (user, params, context) => {
97
97
  await checkAction(context, viewUserOrders, [user, params]);
package/lib/roles/all.js CHANGED
@@ -1,6 +1,8 @@
1
+ import { timingSafeStringEqual } from '@unchainedshop/utils';
2
+ import { IN_LOGIN_RESPONSE } from "../context.js";
1
3
  export const all = (role, actions) => {
2
4
  const isInLoginMutationResponse = (root) => {
3
- if (root && root._inLoginMethodResponse) {
5
+ if (root && root[IN_LOGIN_RESPONSE]) {
4
6
  return true;
5
7
  }
6
8
  return false;
@@ -19,7 +21,7 @@ export const all = (role, actions) => {
19
21
  return true;
20
22
  const accessKeyHeader = context.getHeader('x-token-accesskey');
21
23
  const accessKey = await context.modules.warehousing.buildAccessKeyForToken(tokenId);
22
- if (accessKeyHeader && accessKeyHeader === accessKey)
24
+ if (accessKeyHeader && accessKey && (await timingSafeStringEqual(accessKeyHeader, accessKey)))
23
25
  return true;
24
26
  return false;
25
27
  };
@@ -145,6 +147,6 @@ export const all = (role, actions) => {
145
147
  role.allow(actions.createUser, () => true);
146
148
  role.allow(actions.forgotPassword, () => true);
147
149
  role.allow(actions.resetPassword, () => true);
148
- role.allow(actions.changePassword, () => true);
150
+ role.allow(actions.changePassword, () => false);
149
151
  role.allow(actions.heartbeat, () => true);
150
152
  };
@@ -1,16 +1,9 @@
1
- declare const allRoles: {
2
- ADMIN: import("@unchainedshop/roles").RoleInterface | undefined;
3
- LOGGEDIN: import("@unchainedshop/roles").RoleInterface | undefined;
4
- ALL: import("@unchainedshop/roles").RoleInterface | undefined;
5
- };
1
+ import { type RolesInterface } from '@unchainedshop/roles';
6
2
  declare const actions: Record<string, string>;
3
+ declare let allRoles: Record<string, any>;
7
4
  declare const configureRoles: ({ additionalRoles, additionalActions, }: {
8
5
  additionalRoles?: Record<string, any>;
9
6
  additionalActions?: string[];
10
- }) => {
11
- ADMIN: import("@unchainedshop/roles").RoleInterface | undefined;
12
- LOGGEDIN: import("@unchainedshop/roles").RoleInterface | undefined;
13
- ALL: import("@unchainedshop/roles").RoleInterface | undefined;
14
- };
15
- declare const getPublicRoles: () => string[];
7
+ }) => RolesInterface;
8
+ declare const getPublicRoles: (roles: RolesInterface) => string[];
16
9
  export { allRoles, actions, configureRoles, getPublicRoles };
@@ -1,13 +1,7 @@
1
- import { Roles, Role } from '@unchainedshop/roles';
1
+ import { createRoles, Role } from '@unchainedshop/roles';
2
2
  import { all } from "./all.js";
3
3
  import { loggedIn } from "./loggedIn.js";
4
4
  import { admin } from "./admin.js";
5
- const roles = {
6
- ADMIN: Roles.adminRole,
7
- LOGGEDIN: Roles.loggedInRole,
8
- ALL: Roles.allRole,
9
- };
10
- const allRoles = roles;
11
5
  const actions = [
12
6
  'impersonate',
13
7
  'stopImpersonation',
@@ -101,6 +95,7 @@ const actions = [
101
95
  'managePaymentCredentials',
102
96
  'bulkImport',
103
97
  'logout',
98
+ 'logoutAllSessions',
104
99
  'loginAsGuest',
105
100
  'loginWithPassword',
106
101
  'loginWithWebAuthn',
@@ -124,21 +119,31 @@ const actions = [
124
119
  newValue[actionValue] = actionValue;
125
120
  return newValue;
126
121
  }, {});
122
+ let allRoles = {};
127
123
  const configureRoles = ({ additionalRoles, additionalActions, }) => {
124
+ const roles = createRoles();
125
+ roles.adminRole = roles.addRole(new Role('admin'));
126
+ roles.loggedInRole = roles.addRole(new Role('__loggedIn__'));
127
+ roles.allRole = roles.addRole(new Role('__all__'));
128
128
  additionalActions?.forEach((action) => {
129
129
  actions[action] = action;
130
130
  });
131
+ allRoles = {
132
+ ADMIN: roles.adminRole,
133
+ LOGGEDIN: roles.loggedInRole,
134
+ ALL: roles.allRole,
135
+ };
131
136
  Object.entries(additionalRoles || {}).forEach(([key, val]) => {
132
- allRoles[key] = new Role(key);
137
+ allRoles[key] = roles.addRole(new Role(key));
133
138
  val(allRoles[key], actions);
134
139
  });
135
140
  all(allRoles.ALL, actions);
136
141
  loggedIn(allRoles.LOGGEDIN, actions);
137
142
  admin(allRoles.ADMIN, actions);
138
- return allRoles;
143
+ return roles;
139
144
  };
140
- const getPublicRoles = () => {
141
- return Object.values(allRoles)
145
+ const getPublicRoles = (roles) => {
146
+ return Object.values(roles.roles)
142
147
  .map((role) => role?.name)
143
148
  .filter(Boolean)
144
149
  .filter((name) => !name.startsWith('__'));
@@ -172,4 +172,6 @@ export const loggedIn = (role, actions) => {
172
172
  role.allow(actions.downloadFile, isFileAccessible);
173
173
  role.allow(actions.uploadUserAvatar, canUpdateAvatar);
174
174
  role.allow(actions.uploadTempFile, canUpdateAvatar);
175
+ role.allow(actions.changePassword, () => true);
176
+ role.allow(actions.logoutAllSessions, () => true);
175
177
  };
@@ -57,6 +57,12 @@ export default [
57
57
  """
58
58
  logout: SuccessResponse
59
59
 
60
+ """
61
+ Log the user out of all sessions by invalidating all JWT tokens.
62
+ This increments the token version, making all existing tokens invalid.
63
+ """
64
+ logoutAllSessions: SuccessResponse
65
+
60
66
  """
61
67
  Impersonate a user
62
68
  """
@@ -221,20 +227,6 @@ export default [
221
227
  """
222
228
  terminateEnrollment(enrollmentId: ID!): Enrollment!
223
229
 
224
- """
225
- Change the delivery method/provider to an order. If the delivery provider
226
- doesn’t exists new delivery provider will be created with the provided ID.
227
- """
228
- setOrderDeliveryProvider(orderId: ID!, deliveryProviderId: ID!): Order!
229
- @deprecated(reason: "Use updateCart or updateCartDelivery* mutations instead")
230
-
231
- """
232
- Change the payment method/provider to an order. If the payment provider
233
- doesn’t exists new payment provider will be created with the provided ID.
234
- """
235
- setOrderPaymentProvider(orderId: ID!, paymentProviderId: ID!): Order!
236
- @deprecated(reason: "Use updateCart or updateCartPayment* mutations instead")
237
-
238
230
  """
239
231
  Update the cart by changing the delivery provider and using a shipping specific configuration
240
232
  """
@@ -265,36 +257,6 @@ export default [
265
257
  """
266
258
  updateCartPaymentGeneric(orderId: ID, paymentProviderId: ID!, meta: JSON): Order!
267
259
 
268
- """
269
- Update a Shipping Delivery Provider's specific configuration
270
- """
271
- updateOrderDeliveryShipping(
272
- orderDeliveryId: ID!
273
- address: AddressInput
274
- meta: JSON
275
- ): OrderDeliveryShipping! @deprecated(reason: "Use updateCartDeliveryShipping instead")
276
-
277
- """
278
- Update a Pick Up Delivery Provider's specific configuration
279
- """
280
- updateOrderDeliveryPickUp(
281
- orderDeliveryId: ID!
282
- orderPickUpLocationId: ID!
283
- meta: JSON
284
- ): OrderDeliveryPickUp! @deprecated(reason: "Use updateCartDeliveryPickUp instead")
285
-
286
- """
287
- Update an Invoice Payment Provider's specific configuration
288
- """
289
- updateOrderPaymentInvoice(orderPaymentId: ID!, meta: JSON): OrderPaymentInvoice!
290
- @deprecated(reason: "Use updateCartPaymentInvoice instead")
291
-
292
- """
293
- Update a Generic Payment Provider's specific configuration
294
- """
295
- updateOrderPaymentGeneric(orderPaymentId: ID!, meta: JSON): OrderPaymentGeneric!
296
- @deprecated(reason: "Use updateCartPaymentGeneric instead")
297
-
298
260
  """
299
261
  Remove an order while it's still open
300
262
  """
@@ -491,11 +491,6 @@ export default [
491
491
  """
492
492
  eventsCount(types: [String!], queryString: String, created: DateFilterInput): Int!
493
493
 
494
- """
495
- Get all registered event types
496
- """
497
- registeredEventTypes: [String!]!
498
-
499
494
  """
500
495
  Determines if a token is valid/active for reset password
501
496
  """
@@ -506,6 +501,11 @@ export default [
506
501
  """
507
502
  validateVerifyEmailToken(token: String!): Boolean!
508
503
 
504
+ """
505
+ Get all registered event types
506
+ """
507
+ registeredEventTypes: [String!]!
508
+
509
509
  """
510
510
  Returns aggregated report of all the events that occurred in the system
511
511
  """
@@ -15,7 +15,7 @@ import price from "./price.js";
15
15
  import payment from "./payment.js";
16
16
  import shop from "./shop.js";
17
17
  import stock from "./stock.js";
18
- import types from "./types.js";
18
+ import common from "./common.js";
19
19
  import user from "./user.js";
20
20
  import warehousing from "./warehousing.js";
21
21
  import order from "./order/index.js";
@@ -46,7 +46,7 @@ export default [
46
46
  ...payment,
47
47
  ...shop,
48
48
  ...stock,
49
- ...types,
49
+ ...common,
50
50
  ...user,
51
51
  ...warehousing,
52
52
  ...product,
@@ -33,8 +33,6 @@ export default [
33
33
  delivered: DateTime
34
34
  fee: Price
35
35
  discounts: [OrderDeliveryDiscount!]
36
- pickUpLocations: [PickUpLocation!]!
37
- @deprecated(reason: "Use DeliveryProvider.pickupLocations instead")
38
36
  activePickUpLocation: PickUpLocation
39
37
  }
40
38
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@unchainedshop/api",
3
3
  "description": "GraphQL API layer for the Unchained Engine with Express/Fastify adapters and MCP server",
4
- "version": "4.8.3",
4
+ "version": "5.0.0-alpha.1",
5
5
  "main": "lib/api-index.js",
6
6
  "types": "lib/api-index.d.ts",
7
7
  "type": "module",
@@ -63,22 +63,20 @@
63
63
  "@ai-sdk/mcp": "^1",
64
64
  "@fastify/cookie": ">= 11 < 12",
65
65
  "@fastify/multipart": ">= 9 < 10",
66
- "@fastify/session": ">= 11 < 12",
67
66
  "@fastify/static": ">= 9 < 10",
68
67
  "@modelcontextprotocol/sdk": ">= 1 < 2",
69
68
  "ai": ">= 6 < 7",
69
+ "cookie-parser": ">= 1.4 < 2",
70
70
  "express": ">= 5 < 6",
71
- "express-session": ">= 1.18 < 2",
72
71
  "fastify": ">= 5.2 < 6",
73
72
  "graphql-yoga": ">= 5.9 < 6",
74
- "multer": ">= 2 < 3",
75
- "passport": ">= 0.7 < 1"
73
+ "multer": ">= 2 < 3"
76
74
  },
77
75
  "peerDependenciesMeta": {
78
76
  "graphql-yoga": {
79
77
  "optional": false
80
78
  },
81
- "express-session": {
79
+ "cookie-parser": {
82
80
  "optional": false
83
81
  },
84
82
  "@modelcontextprotocol/sdk": {
@@ -99,9 +97,6 @@
99
97
  "@fastify/multipart": {
100
98
  "optional": true
101
99
  },
102
- "@fastify/session": {
103
- "optional": true
104
- },
105
100
  "@fastify/static": {
106
101
  "optional": true
107
102
  },
@@ -110,40 +105,35 @@
110
105
  },
111
106
  "multer": {
112
107
  "optional": true
113
- },
114
- "passport": {
115
- "optional": true
116
108
  }
117
109
  },
118
110
  "dependencies": {
119
- "@unchainedshop/core": "^4.6.0",
120
- "@unchainedshop/events": "^4.6.0",
121
- "@unchainedshop/logger": "^4.6.0",
122
- "@unchainedshop/roles": "^4.6.0",
123
- "@unchainedshop/utils": "^4.6.0",
111
+ "@unchainedshop/core": "^5.0.0-alpha.1",
112
+ "@unchainedshop/events": "^5.0.0-alpha.1",
113
+ "@unchainedshop/logger": "^5.0.0-alpha.1",
114
+ "@unchainedshop/roles": "^5.0.0-alpha.1",
115
+ "@unchainedshop/utils": "^5.0.0-alpha.1",
116
+ "@whatwg-node/server": "^0.10.18",
124
117
  "dataloader": "^2.2.3",
125
- "expiry-map": "^2.0.0",
126
118
  "graphql-scalars": "^1.24.2",
119
+ "jose": "^6.0.10",
127
120
  "mime": ">= 4 < 5",
128
- "p-memoize": "^8.0.0",
129
121
  "zod": "^3.25.76 || ^4"
130
122
  },
131
123
  "devDependencies": {
132
124
  "@ai-sdk/mcp": "^1.0.5",
133
125
  "@fastify/cookie": "^11.0.2",
134
126
  "@fastify/multipart": "^9.0.3",
135
- "@fastify/session": "^11.1.0",
136
127
  "@fastify/static": "^9.0.0",
137
128
  "@modelcontextprotocol/sdk": "^1.15.1",
129
+ "@types/cookie-parser": "^1.4.8",
138
130
  "@types/express": "^5.0.3",
139
- "@types/express-session": "^1.18.2",
140
131
  "@types/node": "^25.0.0",
141
132
  "ai": "^6.0.14",
133
+ "cookie-parser": "^1.4.7",
142
134
  "express": "^5.1.0",
143
- "express-session": "^1.18.1",
144
135
  "fastify": "^5.4.0",
145
136
  "multer": "^2.0.1",
146
- "passport": "^0.7.0",
147
137
  "typescript": "^5.8.3"
148
138
  }
149
139
  }