@unchainedshop/api 3.0.0-rc9 → 3.0.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.
Files changed (172) hide show
  1. package/lib/api-index.d.ts +3 -2
  2. package/lib/api-index.d.ts.map +1 -1
  3. package/lib/api-index.js +3 -2
  4. package/lib/api-index.js.map +1 -1
  5. package/lib/context.d.ts +16 -21
  6. package/lib/context.d.ts.map +1 -1
  7. package/lib/context.js +2 -2
  8. package/lib/context.js.map +1 -1
  9. package/lib/errors.d.ts +1 -0
  10. package/lib/errors.d.ts.map +1 -1
  11. package/lib/errors.js +1 -0
  12. package/lib/errors.js.map +1 -1
  13. package/lib/express/createBulkImportMiddleware.d.ts.map +1 -1
  14. package/lib/express/createBulkImportMiddleware.js +3 -3
  15. package/lib/express/createBulkImportMiddleware.js.map +1 -1
  16. package/lib/express/createERCMetadataMiddleware.d.ts.map +1 -1
  17. package/lib/express/createERCMetadataMiddleware.js +9 -8
  18. package/lib/express/createERCMetadataMiddleware.js.map +1 -1
  19. package/lib/express/index.d.ts +2 -0
  20. package/lib/express/index.d.ts.map +1 -1
  21. package/lib/express/index.js +11 -2
  22. package/lib/express/index.js.map +1 -1
  23. package/lib/fastify/ercMetadataHandler.d.ts.map +1 -1
  24. package/lib/fastify/ercMetadataHandler.js +2 -1
  25. package/lib/fastify/ercMetadataHandler.js.map +1 -1
  26. package/lib/fastify/index.d.ts +4 -1
  27. package/lib/fastify/index.d.ts.map +1 -1
  28. package/lib/fastify/index.js +47 -15
  29. package/lib/fastify/index.js.map +1 -1
  30. package/lib/loaders/index.d.ts +103 -59
  31. package/lib/loaders/index.d.ts.map +1 -1
  32. package/lib/loaders/index.js +173 -111
  33. package/lib/loaders/index.js.map +1 -1
  34. package/lib/locale-context.d.ts +1 -6
  35. package/lib/locale-context.d.ts.map +1 -1
  36. package/lib/locale-context.js +2 -4
  37. package/lib/locale-context.js.map +1 -1
  38. package/lib/resolvers/mutations/accounts/createUser.js +1 -1
  39. package/lib/resolvers/mutations/accounts/createUser.js.map +1 -1
  40. package/lib/resolvers/mutations/accounts/impersonate.d.ts +9 -0
  41. package/lib/resolvers/mutations/accounts/impersonate.d.ts.map +1 -0
  42. package/lib/resolvers/mutations/accounts/impersonate.js +17 -0
  43. package/lib/resolvers/mutations/accounts/impersonate.js.map +1 -0
  44. package/lib/resolvers/mutations/accounts/loginAsGuest.js +1 -1
  45. package/lib/resolvers/mutations/accounts/loginAsGuest.js.map +1 -1
  46. package/lib/resolvers/mutations/accounts/loginWithPassword.js +1 -1
  47. package/lib/resolvers/mutations/accounts/loginWithPassword.js.map +1 -1
  48. package/lib/resolvers/mutations/accounts/loginWithWebAuthn.js +1 -1
  49. package/lib/resolvers/mutations/accounts/loginWithWebAuthn.js.map +1 -1
  50. package/lib/resolvers/mutations/accounts/resetPassword.js +1 -1
  51. package/lib/resolvers/mutations/accounts/resetPassword.js.map +1 -1
  52. package/lib/resolvers/mutations/accounts/stopImpersonation.d.ts +6 -0
  53. package/lib/resolvers/mutations/accounts/stopImpersonation.d.ts.map +1 -0
  54. package/lib/resolvers/mutations/accounts/stopImpersonation.js +14 -0
  55. package/lib/resolvers/mutations/accounts/stopImpersonation.js.map +1 -0
  56. package/lib/resolvers/mutations/accounts/verifyEmail.js +1 -1
  57. package/lib/resolvers/mutations/accounts/verifyEmail.js.map +1 -1
  58. package/lib/resolvers/mutations/assortments/removeAssortmentProduct.js +1 -1
  59. package/lib/resolvers/mutations/assortments/removeAssortmentProduct.js.map +1 -1
  60. package/lib/resolvers/mutations/index.d.ts +2 -0
  61. package/lib/resolvers/mutations/index.d.ts.map +1 -1
  62. package/lib/resolvers/mutations/index.js +5 -1
  63. package/lib/resolvers/mutations/index.js.map +1 -1
  64. package/lib/resolvers/mutations/products/removeProductReviewVote.d.ts +1 -1
  65. package/lib/resolvers/mutations/products/removeProductReviewVote.d.ts.map +1 -1
  66. package/lib/resolvers/mutations/users/addPushSubscription.d.ts.map +1 -1
  67. package/lib/resolvers/mutations/users/addPushSubscription.js +2 -1
  68. package/lib/resolvers/mutations/users/addPushSubscription.js.map +1 -1
  69. package/lib/resolvers/mutations/users/heartbeat.d.ts +1 -1
  70. package/lib/resolvers/mutations/users/heartbeat.d.ts.map +1 -1
  71. package/lib/resolvers/mutations/users/heartbeat.js +2 -2
  72. package/lib/resolvers/mutations/users/heartbeat.js.map +1 -1
  73. package/lib/resolvers/mutations/users/removePushSubscription.d.ts.map +1 -1
  74. package/lib/resolvers/mutations/users/removePushSubscription.js +2 -1
  75. package/lib/resolvers/mutations/users/removePushSubscription.js.map +1 -1
  76. package/lib/resolvers/queries/index.d.ts +3 -0
  77. package/lib/resolvers/queries/index.d.ts.map +1 -1
  78. package/lib/resolvers/queries/index.js +4 -0
  79. package/lib/resolvers/queries/index.js.map +1 -1
  80. package/lib/resolvers/queries/users/impersonator.d.ts +3 -0
  81. package/lib/resolvers/queries/users/impersonator.d.ts.map +1 -0
  82. package/lib/resolvers/queries/users/impersonator.js +8 -0
  83. package/lib/resolvers/queries/users/impersonator.js.map +1 -0
  84. package/lib/resolvers/queries/warehousing/tokens.d.ts +2 -1
  85. package/lib/resolvers/queries/warehousing/tokens.d.ts.map +1 -1
  86. package/lib/resolvers/queries/warehousing/tokens.js +2 -2
  87. package/lib/resolvers/queries/warehousing/tokens.js.map +1 -1
  88. package/lib/resolvers/queries/warehousing/tokensCount.d.ts +5 -0
  89. package/lib/resolvers/queries/warehousing/tokensCount.d.ts.map +1 -0
  90. package/lib/resolvers/queries/warehousing/tokensCount.js +6 -0
  91. package/lib/resolvers/queries/warehousing/tokensCount.js.map +1 -0
  92. package/lib/resolvers/type/assortment/assortment-path-link-types.d.ts +7 -9
  93. package/lib/resolvers/type/assortment/assortment-path-link-types.d.ts.map +1 -1
  94. package/lib/resolvers/type/assortment/assortment-path-link-types.js +9 -7
  95. package/lib/resolvers/type/assortment/assortment-path-link-types.js.map +1 -1
  96. package/lib/resolvers/type/assortment/assortment-types.d.ts +1 -1
  97. package/lib/resolvers/type/assortment/assortment-types.d.ts.map +1 -1
  98. package/lib/resolvers/type/assortment/assortment-types.js +9 -2
  99. package/lib/resolvers/type/assortment/assortment-types.js.map +1 -1
  100. package/lib/resolvers/type/index.d.ts +14 -8
  101. package/lib/resolvers/type/index.d.ts.map +1 -1
  102. package/lib/resolvers/type/product/product-bundle-types.d.ts +1 -1
  103. package/lib/resolvers/type/product/product-bundle-types.d.ts.map +1 -1
  104. package/lib/resolvers/type/product/product-configurable-types.d.ts +1 -1
  105. package/lib/resolvers/type/product/product-configurable-types.d.ts.map +1 -1
  106. package/lib/resolvers/type/product/product-plan-types.d.ts +1 -1
  107. package/lib/resolvers/type/product/product-plan-types.d.ts.map +1 -1
  108. package/lib/resolvers/type/product/product-simple-types.d.ts +1 -1
  109. package/lib/resolvers/type/product/product-simple-types.d.ts.map +1 -1
  110. package/lib/resolvers/type/product/product-tokenized-types.d.ts +1 -1
  111. package/lib/resolvers/type/product/product-tokenized-types.d.ts.map +1 -1
  112. package/lib/resolvers/type/product/product-types.d.ts +1 -1
  113. package/lib/resolvers/type/product/product-types.d.ts.map +1 -1
  114. package/lib/resolvers/type/product/product-types.js +9 -2
  115. package/lib/resolvers/type/product/product-types.js.map +1 -1
  116. package/lib/resolvers/type/product/product-variation-assignment-vector.d.ts.map +1 -1
  117. package/lib/resolvers/type/product/product-variation-assignment-vector.js +4 -1
  118. package/lib/resolvers/type/product/product-variation-assignment-vector.js.map +1 -1
  119. package/lib/resolvers/type/product/product-variation-types.d.ts.map +1 -1
  120. package/lib/resolvers/type/product/product-variation-types.js +5 -2
  121. package/lib/resolvers/type/product/product-variation-types.js.map +1 -1
  122. package/lib/roles/all.d.ts.map +1 -1
  123. package/lib/roles/all.js +2 -0
  124. package/lib/roles/all.js.map +1 -1
  125. package/lib/roles/index.d.ts.map +1 -1
  126. package/lib/roles/index.js +2 -0
  127. package/lib/roles/index.js.map +1 -1
  128. package/lib/schema/mutation.d.ts.map +1 -1
  129. package/lib/schema/mutation.js +10 -0
  130. package/lib/schema/mutation.js.map +1 -1
  131. package/lib/schema/query.d.ts.map +1 -1
  132. package/lib/schema/query.js +11 -1
  133. package/lib/schema/query.js.map +1 -1
  134. package/lib/schema/types/user.js +1 -1
  135. package/package.json +20 -20
  136. package/src/api-index.ts +5 -4
  137. package/src/context.ts +31 -17
  138. package/src/errors.ts +5 -0
  139. package/src/express/createBulkImportMiddleware.ts +3 -3
  140. package/src/express/createERCMetadataMiddleware.ts +10 -8
  141. package/src/express/index.ts +29 -13
  142. package/src/fastify/ercMetadataHandler.ts +3 -1
  143. package/src/fastify/index.ts +67 -23
  144. package/src/loaders/index.ts +273 -228
  145. package/src/locale-context.ts +1 -10
  146. package/src/resolvers/mutations/accounts/createUser.ts +1 -1
  147. package/src/resolvers/mutations/accounts/impersonate.ts +23 -0
  148. package/src/resolvers/mutations/accounts/loginAsGuest.ts +1 -1
  149. package/src/resolvers/mutations/accounts/loginWithPassword.ts +1 -1
  150. package/src/resolvers/mutations/accounts/loginWithWebAuthn.ts +1 -1
  151. package/src/resolvers/mutations/accounts/resetPassword.ts +1 -1
  152. package/src/resolvers/mutations/accounts/stopImpersonation.ts +19 -0
  153. package/src/resolvers/mutations/accounts/verifyEmail.ts +1 -1
  154. package/src/resolvers/mutations/assortments/removeAssortmentProduct.ts +1 -1
  155. package/src/resolvers/mutations/index.ts +6 -1
  156. package/src/resolvers/mutations/users/addPushSubscription.ts +2 -1
  157. package/src/resolvers/mutations/users/heartbeat.ts +2 -2
  158. package/src/resolvers/mutations/users/removePushSubscription.ts +3 -1
  159. package/src/resolvers/queries/index.ts +4 -0
  160. package/src/resolvers/queries/users/impersonator.ts +13 -0
  161. package/src/resolvers/queries/warehousing/tokens.ts +3 -1
  162. package/src/resolvers/queries/warehousing/tokensCount.ts +12 -0
  163. package/src/resolvers/type/assortment/assortment-path-link-types.ts +14 -19
  164. package/src/resolvers/type/assortment/assortment-types.ts +17 -5
  165. package/src/resolvers/type/product/product-types.ts +17 -5
  166. package/src/resolvers/type/product/product-variation-assignment-vector.ts +4 -1
  167. package/src/resolvers/type/product/product-variation-types.ts +5 -2
  168. package/src/roles/all.ts +2 -0
  169. package/src/roles/index.ts +2 -0
  170. package/src/schema/mutation.ts +10 -0
  171. package/src/schema/query.ts +11 -1
  172. package/src/schema/types/user.ts +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/roles/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,MAAM,KAAK,GAAG;IACZ,KAAK,EAAE,KAAK,CAAC,SAAS;IACtB,QAAQ,EAAE,KAAK,CAAC,YAAY;IAC5B,GAAG,EAAE,KAAK,CAAC,OAAO;CACnB,CAAC;AAEF,MAAM,QAAQ,GAAG,KAAK,CAAC;AAEvB,MAAM,OAAO,GAA2B;IACtC,WAAW;IACX,YAAY;IACZ,eAAe;IACf,gBAAgB;IAChB,oBAAoB;IACpB,qBAAqB;IACrB,sBAAsB;IACtB,qBAAqB;IACrB,gBAAgB;IAChB,UAAU;IACV,UAAU;IACV,WAAW;IACX,aAAa;IACb,cAAc;IACd,eAAe;IACf,cAAc;IACd,eAAe;IACf,aAAa;IACb,gBAAgB;IAChB,cAAc;IACd,sBAAsB;IACtB,qBAAqB;IACrB,uBAAuB;IACvB,uBAAuB;IACvB,sBAAsB;IACtB,wBAAwB;IACxB,0BAA0B;IAC1B,yBAAyB;IACzB,2BAA2B;IAC3B,kBAAkB;IAClB,YAAY;IACZ,WAAW;IACX,cAAc;IACd,YAAY;IACZ,gBAAgB;IAChB,WAAW;IACX,aAAa;IACb,aAAa;IACb,iBAAiB;IACjB,iBAAiB;IACjB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IACZ,cAAc;IACd,kBAAkB;CACnB,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,WAAW,EAAE,EAAE;IACjC,MAAM,QAAQ,GAAG,QAAQ,CAAC;IAC1B,QAAQ,CAAC,WAAW,CAAC,GAAG,WAAW,CAAC;IACpC,OAAO,QAAQ,CAAC;AAClB,CAAC,EAAE,EAAE,CAAC,CAAC;AAEP,MAAM,cAAc,GAAG,CAAC,EAAE,eAAe,GAAG,EAAE,EAAE,iBAAiB,GAAG,EAAE,EAAE,EAAE,EAAE;IAC1E,iBAAiB,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;QACnC,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;IAC3B,CAAC,CAAC,CAAC;IACH,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,GAAG,CAAgB,EAAE,EAAE;QACpE,QAAQ,CAAC,GAAG,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC;QAC9B,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,CAAC;IAC9B,CAAC,CAAC,CAAC;IAEH,GAAG,CAAC,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAC3B,QAAQ,CAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACrC,KAAK,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAE/B,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC;AAEF,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"mutation.d.ts","sourceRoot":"","sources":["../../src/schema/mutation.ts"],"names":[],"mappings":";AAAA,wBA42BE"}
1
+ {"version":3,"file":"mutation.d.ts","sourceRoot":"","sources":["../../src/schema/mutation.ts"],"names":[],"mappings":";AAAA,wBAs3BE"}
@@ -57,6 +57,16 @@ export default [
57
57
  """
58
58
  logout: SuccessResponse
59
59
 
60
+ """
61
+ Impersonate a user
62
+ """
63
+ impersonate(userId: ID!): LoginMethodResponse!
64
+
65
+ """
66
+ End customer impersonated user session and resume the impersonator session
67
+ """
68
+ stopImpersonation: LoginMethodResponse
69
+
60
70
  """
61
71
  Marks the user's email address as verified. Logs the user in afterwards.
62
72
  """
@@ -1 +1 @@
1
- {"version":3,"file":"mutation.js","sourceRoot":"","sources":["../../src/schema/mutation.ts"],"names":[],"mappings":"AAAA,eAAe;IACb,aAAa,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAo3Bb;CACF,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../src/schema/query.ts"],"names":[],"mappings":";AAAA,wBA+eE"}
1
+ {"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../src/schema/query.ts"],"names":[],"mappings":";AAAA,wBAyfE"}
@@ -6,6 +6,11 @@ export default [
6
6
  """
7
7
  me: User
8
8
 
9
+ """
10
+ User impersonating currently logged in user
11
+ """
12
+ impersonator: User
13
+
9
14
  """
10
15
  Get list of users, by default sorted by creation date (ascending) unless a queryString is set
11
16
  """
@@ -211,7 +216,12 @@ export default [
211
216
  """
212
217
  Get all tokens
213
218
  """
214
- tokens(limit: Int = 10, offset: Int = 0): [Token!]!
219
+ tokens(queryString: String, limit: Int = 10, offset: Int = 0): [Token!]!
220
+
221
+ """
222
+ Returns total tokens
223
+ """
224
+ tokensCount(queryString: String): Int!
215
225
 
216
226
  """
217
227
  Returns total number of payment providers, optionally filtered by type
@@ -1 +1 @@
1
- {"version":3,"file":"query.js","sourceRoot":"","sources":["../../src/schema/query.ts"],"names":[],"mappings":"AAAA,eAAe;IACb,aAAa,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6eb;CACF,CAAC"}
1
+ {"version":3,"file":"query.js","sourceRoot":"","sources":["../../src/schema/query.ts"],"names":[],"mappings":"AAAA,eAAe;IACb,aAAa,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAufb;CACF,CAAC"}
@@ -45,7 +45,7 @@ export default [
45
45
  type UserLoginTracker {
46
46
  timestamp: Timestamp!
47
47
  remoteAddress: String
48
- remotePort: String
48
+ remotePort: Int
49
49
  userAgent: String
50
50
  locale: Locale
51
51
  countryCode: String
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unchainedshop/api",
3
- "version": "3.0.0-rc9",
3
+ "version": "3.0.0",
4
4
  "main": "lib/api-index.js",
5
5
  "types": "lib/api-index.d.ts",
6
6
  "type": "module",
@@ -31,15 +31,15 @@
31
31
  },
32
32
  "homepage": "https://github.com/unchainedshop/unchained#readme",
33
33
  "peerDependencies": {
34
- "@fastify/cookie": "^11.0.1",
35
- "@fastify/session": "^11.0.2",
36
- "@metamask/eth-sig-util": "^8.1.2",
37
- "connect-mongo": "^5.1.0",
38
- "express": "^5.0.1",
39
- "express-session": "^1.18.1",
40
- "fastify": "^5.2.0",
41
- "graphql-yoga": "^5.10.6",
42
- "passport": "^0.7.0"
34
+ "@fastify/cookie": ">= 11.0 < 12",
35
+ "@fastify/session": ">= 11.0 < 12",
36
+ "@metamask/eth-sig-util": ">= 8.1 < 9",
37
+ "connect-mongo": ">= 5.1.0 < 6",
38
+ "express": ">= 5.0 < 6",
39
+ "express-session": ">= 1.18 < 2",
40
+ "graphql-yoga": ">= 5.9 < 6.0",
41
+ "fastify": ">= 5.2 < 6",
42
+ "passport": ">= 0.7 < 1"
43
43
  },
44
44
  "peerDependenciesMeta": {
45
45
  "graphql-yoga": {
@@ -71,11 +71,11 @@
71
71
  }
72
72
  },
73
73
  "dependencies": {
74
- "@unchainedshop/core": "^3.0.0-rc9",
75
- "@unchainedshop/events": "^3.0.0-rc9",
76
- "@unchainedshop/logger": "^3.0.0-rc9",
77
- "@unchainedshop/roles": "^3.0.0-rc9",
78
- "@unchainedshop/utils": "^3.0.0-rc9",
74
+ "@unchainedshop/core": "^3.0.0",
75
+ "@unchainedshop/events": "^3.0.0",
76
+ "@unchainedshop/logger": "^3.0.0",
77
+ "@unchainedshop/roles": "^3.0.0",
78
+ "@unchainedshop/utils": "^3.0.0",
79
79
  "accounting": "0.4.1",
80
80
  "dataloader": "^2.2.3",
81
81
  "expiry-map": "^2.0.0",
@@ -84,17 +84,17 @@
84
84
  "p-memoize": "^7.1.1"
85
85
  },
86
86
  "devDependencies": {
87
- "@fastify/cookie": "^11.0.1",
88
- "@fastify/session": "^11.0.2",
87
+ "@fastify/cookie": "^11.0.2",
88
+ "@fastify/session": "^11.1.0",
89
89
  "@metamask/eth-sig-util": "^8.1.2",
90
90
  "@types/express": "^5.0.0",
91
- "@types/node": "^22.10.2",
91
+ "@types/node": "^22.10.5",
92
92
  "express": "^5.0.1",
93
93
  "express-session": "^1.18.1",
94
- "fastify": "^5.2.0",
94
+ "fastify": "^5.2.1",
95
95
  "jest": "^29.7.0",
96
96
  "passport": "^0.7.0",
97
97
  "ts-jest": "^29.2.5",
98
- "typescript": "^5.7.2"
98
+ "typescript": "^5.7.3"
99
99
  }
100
100
  }
package/src/api-index.ts CHANGED
@@ -4,9 +4,10 @@ import {
4
4
  setCurrentContextResolver,
5
5
  getCurrentContextResolver,
6
6
  AdminUiConfig,
7
+ UnchainedContextResolver,
7
8
  } from './context.js';
8
9
  import { UnchainedCore } from '@unchainedshop/core';
9
-
10
+ export * from './events.js';
10
11
  export * from './context.js';
11
12
  export * from './locale-context.js';
12
13
  export * from './loaders/index.js';
@@ -23,7 +24,7 @@ export type UnchainedServerOptions = {
23
24
  roles?: any;
24
25
  adminUiConfig?: AdminUiConfig;
25
26
  unchainedAPI: UnchainedCore;
26
- context?: any;
27
+ context?: (defaultResolver: UnchainedContextResolver) => UnchainedContextResolver;
27
28
  events: Array<string>;
28
29
  workTypes: Array<string>;
29
30
  } & GraphQLServerOptions;
@@ -45,8 +46,8 @@ export const startAPIServer = async (options: UnchainedServerOptions) => {
45
46
 
46
47
  setCurrentContextResolver(
47
48
  customContext
48
- ? (props) => {
49
- return customContext(props, contextResolver);
49
+ ? (props, ...rest) => {
50
+ return customContext(contextResolver)(props, ...rest);
50
51
  }
51
52
  : contextResolver,
52
53
  );
package/src/context.ts CHANGED
@@ -4,14 +4,21 @@ import { getLocaleContext, UnchainedLocaleContext } from './locale-context.js';
4
4
  import { UnchainedServerOptions } from './api-index.js';
5
5
  import { User } from '@unchainedshop/core-users';
6
6
 
7
+ export type LoginFn = (
8
+ user: User,
9
+ options?: {
10
+ impersonator?: User;
11
+ },
12
+ ) => Promise<{ _id: string; tokenExpires: Date }>;
13
+
14
+ export type LogoutFn = (sessionId?: string) => Promise<boolean>;
7
15
  export interface UnchainedUserContext {
8
- login: (user: User) => Promise<{ _id: string; tokenExpires: Date }>;
9
- logout: () => Promise<boolean>;
16
+ login: LoginFn;
17
+ logout: LogoutFn;
10
18
  userId?: string;
19
+ impersonatorId?: string;
20
+ accessToken?: string;
11
21
  user?: User;
12
- remoteAddress?: string;
13
- remotePort?: string;
14
- userAgent?: string;
15
22
  }
16
23
 
17
24
  export interface CustomAdminUiProperties {
@@ -26,15 +33,17 @@ export interface AdminUiConfig {
26
33
  export type UnchainedHTTPServerContext = {
27
34
  setHeader: (key: string, value: string) => void;
28
35
  getHeader: (key: string) => string;
36
+ remoteAddress?: string;
37
+ remotePort?: number;
29
38
  };
30
39
 
31
40
  export type Context = UnchainedCore & {
32
41
  version?: string;
33
42
  roles?: any;
34
43
  adminUiConfig?: AdminUiConfig;
44
+ loaders: UnchainedLoaders;
35
45
  } & UnchainedUserContext &
36
46
  UnchainedLocaleContext &
37
- UnchainedLoaders &
38
47
  UnchainedHTTPServerContext;
39
48
 
40
49
  let context;
@@ -45,15 +54,10 @@ export const setCurrentContextResolver = (newContext: UnchainedContextResolver)
45
54
  context = newContext;
46
55
  };
47
56
 
48
- export type UnchainedContextResolver = (
49
- params: UnchainedHTTPServerContext & {
50
- remoteAddress?: string;
51
- remotePort?: number;
52
- userId?: string;
53
- login: (user: any) => Promise<{ _id: string; user: any; tokenExpires: Date }>;
54
- accessToken?: string;
55
- logout: () => Promise<boolean>;
56
- },
57
+ export type UnchainedContextResolver<Request = any, Response = any> = (
58
+ params: UnchainedHTTPServerContext & Omit<UnchainedUserContext, 'user'>,
59
+ req?: Request,
60
+ res?: Response,
57
61
  ) => Promise<Context>;
58
62
 
59
63
  const { default: packageJson } = await import(`${import.meta.dirname}/../package.json`, {
@@ -66,11 +70,21 @@ export const createContextResolver =
66
70
  unchainedAPI: UnchainedCore,
67
71
  unchainedConfig: Pick<UnchainedServerOptions, 'roles' | 'adminUiConfig'>,
68
72
  ): UnchainedContextResolver =>
69
- async ({ getHeader, setHeader, remoteAddress, remotePort, userId, accessToken, login, logout }) => {
73
+ async ({
74
+ getHeader,
75
+ setHeader,
76
+ remoteAddress,
77
+ remotePort,
78
+ userId,
79
+ impersonatorId,
80
+ accessToken,
81
+ login,
82
+ logout,
83
+ }) => {
70
84
  const abstractHttpServerContext = { remoteAddress, remotePort, getHeader, setHeader };
71
85
  const loaders = await instantiateLoaders(unchainedAPI);
72
86
  const localeContext = await getLocaleContext(abstractHttpServerContext, unchainedAPI);
73
- const userContext: UnchainedUserContext = { login, logout };
87
+ const userContext: UnchainedUserContext = { login, logout, impersonatorId };
74
88
 
75
89
  if (accessToken) {
76
90
  const accessTokenUser = await unchainedAPI.modules.users.findUserByToken(accessToken);
package/src/errors.ts CHANGED
@@ -308,3 +308,8 @@ export const ProductLinkedToQuotationError = createError(
308
308
  export const FileNotFoundError = createError('FileNotFoundError', 'File not found');
309
309
 
310
310
  export const FileUploadExpiredError = createError('FileUploadExpired', 'File upload has expired');
311
+
312
+ export const ImpersonatingAdminUserError = createError(
313
+ 'ImpersonatingAdminUserError',
314
+ 'Can not impersonate a admin user account',
315
+ );
@@ -11,10 +11,11 @@ const errorHandler = (res) => (e) => {
11
11
  res.end(JSON.stringify({ name: e.name, code: e.code, message: e.message }));
12
12
  };
13
13
 
14
- const methodWrongHandler = (res) => () => {
14
+ const methodWrongHandler = (res) => {
15
15
  logger.error('Method not supported, return 404');
16
16
  res.writeHead(404);
17
17
  res.end();
18
+ return;
18
19
  };
19
20
 
20
21
  export default async function bulkImportMiddleware(
@@ -25,8 +26,7 @@ export default async function bulkImportMiddleware(
25
26
  const context = req.unchainedContext;
26
27
 
27
28
  if (req.method !== 'POST') {
28
- methodWrongHandler(res)();
29
- return;
29
+ return methodWrongHandler(res);
30
30
  }
31
31
 
32
32
  await checkAction(context, (actions as any).bulkImport);
@@ -5,16 +5,20 @@ import { Request, RequestHandler } from 'express';
5
5
 
6
6
  const logger = createLogger('unchained:erc-metadata');
7
7
 
8
- const errorHandler = (res) => (e) => {
8
+ const { ROOT_URL = 'http://localhost:4010' } = process.env;
9
+
10
+ const errorHandler = (res, e) => {
9
11
  logger.error(e.message);
10
12
  res.writeHead(503);
11
13
  res.end(JSON.stringify({ name: e.name, code: e.code, message: e.message }));
14
+ return;
12
15
  };
13
16
 
14
- const methodWrongHandler = (res) => () => {
17
+ const methodWrongHandler = (res) => {
15
18
  logger.error('Method not supported, return 404');
16
19
  res.writeHead(404);
17
20
  res.end();
21
+ return;
18
22
  };
19
23
 
20
24
  const ercMetadataMiddleware: RequestHandler = async (
@@ -23,12 +27,11 @@ const ercMetadataMiddleware: RequestHandler = async (
23
27
  ) => {
24
28
  try {
25
29
  if (req.method !== 'GET') {
26
- methodWrongHandler(res)();
27
- return;
30
+ return methodWrongHandler(res);
28
31
  }
29
32
 
30
33
  const { services, localeContext } = req.unchainedContext;
31
- const url = new URL(req.url, process.env.ROOT_URL);
34
+ const url = new URL(req.url, ROOT_URL);
32
35
  const parsedPath = path.parse(url.pathname);
33
36
 
34
37
  if (parsedPath.ext !== '.json') throw new Error('Invalid ERC Metadata URI');
@@ -43,8 +46,7 @@ const ercMetadataMiddleware: RequestHandler = async (
43
46
  });
44
47
 
45
48
  if (!ercMetadata) {
46
- methodWrongHandler(res);
47
- return;
49
+ return methodWrongHandler(res);
48
50
  }
49
51
 
50
52
  const body = JSON.stringify(ercMetadata);
@@ -54,7 +56,7 @@ const ercMetadataMiddleware: RequestHandler = async (
54
56
  });
55
57
  res.end(body);
56
58
  } catch (e) {
57
- errorHandler(res)(e);
59
+ return errorHandler(res, e);
58
60
  }
59
61
  };
60
62
 
@@ -1,5 +1,5 @@
1
1
  import e from 'express';
2
- import { getCurrentContextResolver } from '../context.js';
2
+ import { getCurrentContextResolver, LoginFn, LogoutFn } from '../context.js';
3
3
  import createBulkImportMiddleware from './createBulkImportMiddleware.js';
4
4
  import createERCMetadataMiddleware from './createERCMetadataMiddleware.js';
5
5
  import session from 'express-session';
@@ -46,7 +46,7 @@ const addContext = async function middlewareWithContext(
46
46
 
47
47
  const context = getCurrentContextResolver();
48
48
 
49
- const login = async (user: User) => {
49
+ const login: LoginFn = async (user: User) => {
50
50
  await new Promise((resolve, reject) => {
51
51
  (req as any).login(user, (error, result) => {
52
52
  if (error) {
@@ -70,7 +70,7 @@ const addContext = async function middlewareWithContext(
70
70
  return { user, ...tokenObject };
71
71
  };
72
72
 
73
- const logout = async (sessionId?: string) => { /* eslint-disable-line */
73
+ const logout: LogoutFn = async (sessionId) => { /* eslint-disable-line */
74
74
  // TODO: this should only logout an explicitly provided session if sessionID
75
75
  // has been provided
76
76
  // express-session destroy
@@ -97,16 +97,20 @@ const addContext = async function middlewareWithContext(
97
97
 
98
98
  const [, accessToken] = req.headers.authorization?.split(' ') || [];
99
99
 
100
- (req as any).unchainedContext = await context({
101
- setHeader,
102
- getHeader,
103
- remoteAddress,
104
- remotePort,
105
- login,
106
- logout,
107
- accessToken,
108
- userId: (req as any).user?._id,
109
- });
100
+ (req as any).unchainedContext = await context(
101
+ {
102
+ setHeader,
103
+ getHeader,
104
+ remoteAddress,
105
+ remotePort,
106
+ login,
107
+ logout,
108
+ accessToken,
109
+ userId: (req as any).user?._id,
110
+ },
111
+ req,
112
+ res,
113
+ );
110
114
  next();
111
115
  } catch (error) {
112
116
  next(error);
@@ -119,7 +123,19 @@ export const connect = (
119
123
  graphqlHandler,
120
124
  db,
121
125
  }: { graphqlHandler: YogaServerInstance<any, any>; db: mongodb.Db; unchainedAPI: UnchainedCore },
126
+ {
127
+ allowRemoteToLocalhostSecureCookies = false,
128
+ }: { allowRemoteToLocalhostSecureCookies?: boolean } = {},
122
129
  ) => {
130
+ if (allowRemoteToLocalhostSecureCookies) {
131
+ // Workaround: Allow to use sandbox with localhost
132
+ expressApp.set('trust proxy', 1);
133
+ expressApp.use((req, res, next) => {
134
+ req.headers['x-forwarded-proto'] = 'https';
135
+ res.setHeader('Access-Control-Allow-Private-Network', 'true');
136
+ next();
137
+ });
138
+ }
123
139
  const passport = new Passport();
124
140
 
125
141
  passport.serializeUser(function serialize(user, done) {
@@ -4,6 +4,8 @@ import { FastifyRequest, RouteHandlerMethod } from 'fastify';
4
4
 
5
5
  const logger = createLogger('unchained:erc-metadata');
6
6
 
7
+ const { ROOT_URL = 'http://localhost:4010' } = process.env;
8
+
7
9
  const errorHandler = (res) => (e) => {
8
10
  logger.error(e.message);
9
11
  res.status(503);
@@ -22,7 +24,7 @@ const ercMetadataHandler: RouteHandlerMethod = async (
22
24
  ) => {
23
25
  try {
24
26
  const { services, localeContext } = req.unchainedContext;
25
- const url = new URL(req.url, process.env.ROOT_URL);
27
+ const url = new URL(req.url, ROOT_URL);
26
28
 
27
29
  if (!url.pathname.toLowerCase().endsWith('.json')) throw new Error('Invalid ERC Metadata URI');
28
30
 
@@ -1,4 +1,4 @@
1
- import { getCurrentContextResolver } from '../context.js';
1
+ import { getCurrentContextResolver, LoginFn, LogoutFn } from '../context.js';
2
2
  import bulkImportHandler from './bulkImportHandler.js';
3
3
  import ercMetadataHandler from './ercMetadataHandler.js';
4
4
  import MongoStore from 'connect-mongo';
@@ -10,7 +10,8 @@ import { API_EVENTS } from '../events.js';
10
10
  import { User } from '@unchainedshop/core-users';
11
11
  import fastifySession from '@fastify/session';
12
12
  import fastifyCookie from '@fastify/cookie';
13
- import { FastifyInstance, FastifyRequest } from 'fastify';
13
+ import { FastifyBaseLogger, FastifyInstance, FastifyRequest } from 'fastify';
14
+ import { createLogger } from '@unchainedshop/logger';
14
15
 
15
16
  const resolveUserRemoteAddress = (req: FastifyRequest) => {
16
17
  const remoteAddress =
@@ -41,44 +42,69 @@ const middlewareHook = async function middlewareHook(req: any, reply: any) {
41
42
 
42
43
  const context = getCurrentContextResolver();
43
44
 
44
- async function login(user: User) {
45
- req.session.user = user;
45
+ const login: LoginFn = async function (user: User, options = {}) {
46
+ const { impersonator } = options;
47
+
48
+ req.session.userId = user._id;
49
+ req.session.impersonatorId = impersonator?._id;
50
+
46
51
  const tokenObject = {
47
52
  _id: req.session.sessionId,
48
53
  userId: user._id,
49
- /* eslint-disable-next-line */
50
- tokenExpires: new Date((req as any).session?.cookie._expires),
54
+ // eslint-disable-next-line
55
+ tokenExpires: new Date((req as any).session.cookie._expires),
51
56
  };
52
57
  await emit(API_EVENTS.API_LOGIN_TOKEN_CREATED, tokenObject);
53
58
  /* eslint-disable-next-line */
54
59
  (user as any)._inLoginMethodResponse = true;
55
60
  return { user, ...tokenObject };
56
- }
61
+ };
57
62
 
58
- async function logout() {
63
+ const logout: LogoutFn = async function logout() {
59
64
  /* eslint-disable-line */
60
- if (!req.session?.user?._id) return false;
61
65
  const tokenObject = {
62
66
  _id: (req as any).session.sessionId,
63
- userId: req.session?.user?._id,
67
+ userId: req.session?.userId,
64
68
  };
65
- req.session.user = null;
69
+ req.session.userId = null;
66
70
  await emit(API_EVENTS.API_LOGOUT, tokenObject);
67
71
  return true;
68
- }
72
+ };
69
73
 
70
74
  const [, accessToken] = req.headers.authorization?.split(' ') || [];
71
75
 
72
- (req as any).unchainedContext = await context({
73
- setHeader,
74
- getHeader,
75
- remoteAddress,
76
- remotePort,
77
- login,
78
- logout,
79
- accessToken,
80
- userId: req.session.user?._id,
81
- });
76
+ (req as any).unchainedContext = await context(
77
+ {
78
+ setHeader,
79
+ getHeader,
80
+ remoteAddress,
81
+ remotePort,
82
+ login,
83
+ logout,
84
+ accessToken,
85
+ userId: req.session.userId,
86
+ impersonatorId: req.session.impersonatorId,
87
+ },
88
+ req,
89
+ reply,
90
+ );
91
+ };
92
+
93
+ export const unchainedLogger = (prefix: string): FastifyBaseLogger => {
94
+ const logger = createLogger(prefix);
95
+ function Logger(...args) {
96
+ this.args = args;
97
+ }
98
+ Logger.prototype.info = logger.info;
99
+ Logger.prototype.error = logger.error;
100
+ Logger.prototype.debug = logger.debug;
101
+ Logger.prototype.fatal = logger.error;
102
+ Logger.prototype.warn = logger.warn;
103
+ Logger.prototype.trace = logger.trace;
104
+ Logger.prototype.child = function () {
105
+ return new Logger();
106
+ };
107
+ return new Logger();
82
108
  };
83
109
 
84
110
  export const connect = (
@@ -87,7 +113,23 @@ export const connect = (
87
113
  graphqlHandler,
88
114
  db,
89
115
  }: { graphqlHandler: YogaServerInstance<any, any>; db: mongodb.Db; unchainedAPI: UnchainedCore },
116
+ {
117
+ allowRemoteToLocalhostSecureCookies = false,
118
+ }: { allowRemoteToLocalhostSecureCookies?: boolean } = {},
90
119
  ) => {
120
+ if (allowRemoteToLocalhostSecureCookies) {
121
+ // Workaround: Allow to use sandbox with localhost
122
+ // https://github.com/fastify/fastify-cookie/issues/308
123
+ fastify.addHook('preHandler', async function (request) {
124
+ request.headers['x-forwarded-proto'] = 'https';
125
+ });
126
+ fastify.addHook('onSend', async function (_, reply) {
127
+ reply.headers({
128
+ 'Access-Control-Allow-Private-Network': 'true',
129
+ });
130
+ });
131
+ }
132
+
91
133
  const cookieName = UNCHAINED_COOKIE_NAME;
92
134
  const domain = UNCHAINED_COOKIE_DOMAIN;
93
135
  const path = UNCHAINED_COOKIE_PATH;
@@ -100,7 +142,9 @@ export const connect = (
100
142
  '0': false,
101
143
  }[UNCHAINED_COOKIE_SAMESITE?.trim()?.toLowerCase()] || false) as boolean | 'none' | 'lax' | 'strict';
102
144
 
103
- fastify.register(fastifyCookie);
145
+ if (!fastify.hasPlugin('@fastify/cookie')) {
146
+ fastify.register(fastifyCookie);
147
+ }
104
148
  fastify.register(fastifySession, {
105
149
  secret: process.env.UNCHAINED_TOKEN_SECRET,
106
150
  cookieName,