@unchainedshop/api 4.6.1 → 4.7.2

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 (75) hide show
  1. package/lib/acl.js +29 -1
  2. package/lib/api-index.d.ts +1 -0
  3. package/lib/auth.d.ts +44 -0
  4. package/lib/auth.js +187 -0
  5. package/lib/context.d.ts +1 -0
  6. package/lib/context.js +8 -3
  7. package/lib/events.d.ts +2 -0
  8. package/lib/events.js +2 -0
  9. package/lib/express/index.d.ts +6 -9
  10. package/lib/express/index.js +52 -125
  11. package/lib/express/mountPluginRoutes.d.ts +3 -0
  12. package/lib/express/mountPluginRoutes.js +59 -0
  13. package/lib/express/mountRoutes.d.ts +3 -0
  14. package/lib/express/mountRoutes.js +57 -0
  15. package/lib/fastify/index.d.ts +6 -9
  16. package/lib/fastify/index.js +51 -113
  17. package/lib/fastify/mountPluginRoutes.d.ts +3 -0
  18. package/lib/fastify/mountPluginRoutes.js +62 -0
  19. package/lib/fastify/mountRoutes.d.ts +3 -0
  20. package/lib/fastify/mountRoutes.js +60 -0
  21. package/lib/handlers/createBackchannelLogoutHandler.d.ts +4 -0
  22. package/lib/handlers/createBackchannelLogoutHandler.js +170 -0
  23. package/lib/mcp/tools/localization/getLocalizationsConfig.d.ts +1 -1
  24. package/lib/mcp/tools/localization/schemas.d.ts +34 -0
  25. package/lib/mcp/tools/order/handlers/getTopCustomers.d.ts +2 -0
  26. package/lib/mcp/tools/quotation/handlers/getQuotation.d.ts +2 -0
  27. package/lib/mcp/tools/quotation/handlers/listQuotations.d.ts +2 -0
  28. package/lib/mcp/tools/quotation/handlers/makeQuotationProposal.d.ts +2 -0
  29. package/lib/mcp/tools/quotation/handlers/rejectQuotation.d.ts +2 -0
  30. package/lib/mcp/tools/quotation/handlers/verifyQuotation.d.ts +2 -0
  31. package/lib/mcp/tools/system/handlers/countEvents.d.ts +8 -1
  32. package/lib/mcp/tools/system/handlers/countWork.d.ts +10 -1
  33. package/lib/mcp/tools/system/handlers/countWork.js +1 -0
  34. package/lib/mcp/tools/system/handlers/index.d.ts +4 -4
  35. package/lib/mcp/tools/system/handlers/listEvents.d.ts +12 -1
  36. package/lib/mcp/tools/system/handlers/listWork.d.ts +14 -1
  37. package/lib/mcp/tools/system/handlers/listWork.js +1 -0
  38. package/lib/mcp/tools/users/handlers/addUserEmail.d.ts +2 -0
  39. package/lib/mcp/tools/users/handlers/createUser.d.ts +2 -0
  40. package/lib/mcp/tools/users/handlers/enrollUser.d.ts +2 -0
  41. package/lib/mcp/tools/users/handlers/getCurrentUser.d.ts +2 -0
  42. package/lib/mcp/tools/users/handlers/getUser.d.ts +2 -0
  43. package/lib/mcp/tools/users/handlers/listUsers.d.ts +2 -0
  44. package/lib/mcp/tools/users/handlers/setUserTags.d.ts +2 -0
  45. package/lib/mcp/tools/users/handlers/setUserUsername.d.ts +2 -0
  46. package/lib/mcp/tools/users/handlers/updateUser.d.ts +2 -0
  47. package/lib/mcp/utils/getNormalizedQuotationDetails.d.ts +2 -0
  48. package/lib/mcp/utils/getNormalizedUserDetails.d.ts +2 -0
  49. package/lib/mcp/utils/normalizeMediaUrl.js +1 -1
  50. package/lib/mcp/utils/sanitizeLocalizationEntityData.d.ts +1 -1
  51. package/lib/mcp/utils/validateIsoCode.d.ts +1 -1
  52. package/lib/middleware/createAuthMiddleware.d.ts +29 -0
  53. package/lib/middleware/createAuthMiddleware.js +128 -0
  54. package/lib/resolvers/mutations/accounts/logoutAllSessions.d.ts +4 -0
  55. package/lib/resolvers/mutations/accounts/logoutAllSessions.js +11 -0
  56. package/lib/resolvers/mutations/index.d.ts +1 -6
  57. package/lib/resolvers/mutations/index.js +2 -12
  58. package/lib/resolvers/mutations/orders/updateCart.js +7 -1
  59. package/lib/resolvers/type/index.d.ts +0 -1
  60. package/lib/resolvers/type/order/order-delivery-pickup-types.d.ts +0 -1
  61. package/lib/resolvers/type/order/order-delivery-pickup-types.js +0 -7
  62. package/lib/resolvers/type/order/order-payment-base.d.ts +7 -0
  63. package/lib/resolvers/type/order/order-payment-base.js +14 -0
  64. package/lib/roles/index.js +1 -0
  65. package/lib/roles/loggedIn.js +1 -0
  66. package/lib/schema/mutation.js +6 -44
  67. package/lib/schema/types/common.d.ts +2 -0
  68. package/lib/schema/types/common.js +12 -0
  69. package/lib/schema/types/index.js +2 -2
  70. package/lib/schema/types/order/delivery.js +0 -2
  71. package/lib/utils/mapServiceError.d.ts +1 -0
  72. package/lib/utils/mapServiceError.js +59 -0
  73. package/lib/utils/maskError.d.ts +1 -0
  74. package/lib/utils/maskError.js +22 -0
  75. package/package.json +8 -17
@@ -101,6 +101,7 @@ const actions = [
101
101
  'managePaymentCredentials',
102
102
  'bulkImport',
103
103
  'logout',
104
+ 'logoutAllSessions',
104
105
  'loginAsGuest',
105
106
  'loginWithPassword',
106
107
  'loginWithWebAuthn',
@@ -172,4 +172,5 @@ 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.logoutAllSessions, () => true);
175
176
  };
@@ -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
  """
@@ -0,0 +1,2 @@
1
+ declare const _default: string[];
2
+ export default _default;
@@ -0,0 +1,12 @@
1
+ export default [
2
+ `
3
+ type SuccessResponse @cacheControl(maxAge: 0, scope: PRIVATE) {
4
+ success: Boolean
5
+ }
6
+
7
+ enum SortDirection {
8
+ ASC
9
+ DESC
10
+ }
11
+ `,
12
+ ];
@@ -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
 
@@ -0,0 +1 @@
1
+ export declare function mapServiceError(error: unknown): never;
@@ -0,0 +1,59 @@
1
+ import { GraphQLError } from 'graphql';
2
+ import * as errors from "../errors.js";
3
+ const errorMap = {
4
+ ProductNotFoundError: errors.ProductNotFoundError,
5
+ ProductWrongStatusError: errors.ProductWrongStatusError,
6
+ ProductWrongTypeError: errors.ProductWrongTypeError,
7
+ CyclicProductBundlingNotSupportedError: errors.CyclicProductBundlingNotSupportedError,
8
+ ProductVariationInfinityLoop: errors.ProductVariationInfinityLoop,
9
+ ProductVariationVectorInvalid: errors.ProductVariationVectorInvalid,
10
+ ProductVariationVectorAlreadySet: errors.ProductVariationVectorAlreadySet,
11
+ ProductLinkedToActiveBundleError: errors.ProductLinkedToActiveBundleError,
12
+ ProductLinkedToActiveVariationError: errors.ProductLinkedToActiveVariationError,
13
+ ProductLinkedToQuotationError: errors.ProductLinkedToQuotationError,
14
+ ProductLinkedToEnrollmentError: errors.ProductLinkedToEnrollmentError,
15
+ EnrollmentNotFoundError: errors.EnrollmentNotFoundError,
16
+ EnrollmentWrongStatusError: errors.EnrollmentWrongStatusError,
17
+ EnrollmentPlanUpdateNotAllowedError: errors.EnrollmentWrongStatusError,
18
+ OrderNotFoundError: errors.OrderNotFoundError,
19
+ OrderWrongStatusError: errors.OrderWrongStatusError,
20
+ OrderItemNotFoundError: errors.OrderItemNotFoundError,
21
+ OrderQuantityTooLowError: errors.OrderQuantityTooLowError,
22
+ OrderPaymentNotFoundError: errors.OrderPaymentNotFoundError,
23
+ OrderWrongPaymentStatusError: errors.OrderWrongPaymentStatusError,
24
+ OrderDeliveryNotFoundError: errors.OrderDeliveryNotFoundError,
25
+ OrderWrongDeliveryStatusError: errors.OrderWrongDeliveryStatusError,
26
+ QuotationNotFoundError: errors.QuotationNotFoundError,
27
+ QuotationWrongStatusError: errors.QuotationWrongStatusError,
28
+ QuotationItemConfigurationError: errors.QuotationItemConfigurationError,
29
+ BookmarkNotFoundError: errors.BookmarkNotFoundError,
30
+ MultipleBookmarksFound: errors.MultipleBookmarksFound,
31
+ BookmarkAlreadyExistsError: errors.BookmarkAlreadyExistsError,
32
+ OrderDiscountCodeAlreadyPresentError: errors.OrderDiscountCodeAlreadyPresentError,
33
+ OrderDiscountCodeNotValidError: errors.OrderDiscountCodeNotValidError,
34
+ UserNotFoundError: errors.UserNotFoundError,
35
+ ImpersonatingAdminUserError: errors.ImpersonatingAdminUserError,
36
+ InvalidEmailVerificationTokenError: errors.InvalidEmailVerificationTokenError,
37
+ UsernameOrEmailRequiredError: errors.UsernameOrEmailRequiredError,
38
+ PasswordOrWebAuthnPublicKeyRequiredError: errors.PasswordOrWebAuthnPublicKeyRequiredError,
39
+ EmailAlreadyExistsError: errors.EmailAlreadyExistsError,
40
+ UsernameAlreadyExistsError: errors.UsernameAlreadyExistsError,
41
+ PasswordInvalidError: errors.PasswordInvalidError,
42
+ WebAuthnVerificationFailedError: errors.WebAuthnVerificationFailedError,
43
+ AuthOperationFailedError: errors.AuthOperationFailedError,
44
+ InvalidCredentialsError: errors.InvalidCredentialsError,
45
+ InvalidResetTokenError: errors.InvalidResetTokenError,
46
+ InvalidIdError: errors.InvalidIdError,
47
+ ProviderConfigurationInvalid: errors.ProviderConfigurationInvalid,
48
+ };
49
+ export function mapServiceError(error) {
50
+ if (error instanceof GraphQLError) {
51
+ throw error;
52
+ }
53
+ const serviceError = error;
54
+ const ErrorClass = serviceError.code ? errorMap[serviceError.code] : undefined;
55
+ if (ErrorClass) {
56
+ throw new ErrorClass(serviceError.data);
57
+ }
58
+ throw error;
59
+ }
@@ -0,0 +1 @@
1
+ export declare function createMaskError(isDev: boolean): (error: unknown, message: string) => Error;
@@ -0,0 +1,22 @@
1
+ import { GraphQLError } from 'graphql';
2
+ import { maskError as yogaMaskError } from 'graphql-yoga';
3
+ function isKnownError(error) {
4
+ return error instanceof Error && 'code' in error && typeof error.code === 'string';
5
+ }
6
+ export function createMaskError(isDev) {
7
+ return function maskError(error, message) {
8
+ const originalError = error instanceof GraphQLError ? error.originalError || error : error;
9
+ if (error instanceof GraphQLError && error.extensions?.code) {
10
+ return error;
11
+ }
12
+ if (isKnownError(originalError)) {
13
+ return new GraphQLError(originalError.message, {
14
+ extensions: {
15
+ code: originalError.code,
16
+ ...(originalError.data || {}),
17
+ },
18
+ });
19
+ }
20
+ return yogaMaskError(error, message, isDev);
21
+ };
22
+ }
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.6.1",
4
+ "version": "4.7.2",
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,9 +105,6 @@
110
105
  },
111
106
  "multer": {
112
107
  "optional": true
113
- },
114
- "passport": {
115
- "optional": true
116
108
  }
117
109
  },
118
110
  "dependencies": {
@@ -121,9 +113,10 @@
121
113
  "@unchainedshop/logger": "^4.6.0",
122
114
  "@unchainedshop/roles": "^4.6.0",
123
115
  "@unchainedshop/utils": "^4.6.0",
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
121
  "p-memoize": "^8.0.0",
129
122
  "zod": "^3.25.76 || ^4"
@@ -132,18 +125,16 @@
132
125
  "@ai-sdk/mcp": "^1.0.5",
133
126
  "@fastify/cookie": "^11.0.2",
134
127
  "@fastify/multipart": "^9.0.3",
135
- "@fastify/session": "^11.1.0",
136
128
  "@fastify/static": "^9.0.0",
137
129
  "@modelcontextprotocol/sdk": "^1.15.1",
130
+ "@types/cookie-parser": "^1.4.8",
138
131
  "@types/express": "^5.0.3",
139
- "@types/express-session": "^1.18.2",
140
132
  "@types/node": "^25.0.0",
141
133
  "ai": "^6.0.14",
134
+ "cookie-parser": "^1.4.7",
142
135
  "express": "^5.1.0",
143
- "express-session": "^1.18.1",
144
136
  "fastify": "^5.4.0",
145
137
  "multer": "^2.0.1",
146
- "passport": "^0.7.0",
147
138
  "typescript": "^5.8.3"
148
139
  }
149
140
  }