@unchainedshop/api 2.8.17 → 2.9.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 (82) hide show
  1. package/jest.config.js +2 -2
  2. package/lib/errors.d.ts +1 -0
  3. package/lib/errors.js +1 -0
  4. package/lib/errors.js.map +1 -1
  5. package/lib/resolvers/mutations/index.d.ts +1 -0
  6. package/lib/resolvers/mutations/index.js +2 -0
  7. package/lib/resolvers/mutations/index.js.map +1 -1
  8. package/lib/resolvers/mutations/warehousing/invalidateToken.d.ts +4 -0
  9. package/lib/resolvers/mutations/warehousing/invalidateToken.js +26 -0
  10. package/lib/resolvers/mutations/warehousing/invalidateToken.js.map +1 -0
  11. package/lib/resolvers/queries/index.d.ts +1 -0
  12. package/lib/resolvers/queries/index.js +2 -0
  13. package/lib/resolvers/queries/index.js.map +1 -1
  14. package/lib/resolvers/queries/warehousing/tokens.d.ts +5 -0
  15. package/lib/resolvers/queries/warehousing/tokens.js +6 -0
  16. package/lib/resolvers/queries/warehousing/tokens.js.map +1 -0
  17. package/lib/resolvers/type/index.d.ts +367 -9
  18. package/lib/resolvers/type/order/order-item-types.d.ts +15 -17
  19. package/lib/resolvers/type/order/order-item-types.js +28 -23
  20. package/lib/resolvers/type/order/order-item-types.js.map +1 -1
  21. package/lib/resolvers/type/order/order-types.d.ts +15 -19
  22. package/lib/resolvers/type/order/order-types.js +48 -28
  23. package/lib/resolvers/type/order/order-types.js.map +1 -1
  24. package/lib/resolvers/type/product/product-bundle-types.d.ts +34 -2
  25. package/lib/resolvers/type/product/product-bundle-types.js.map +1 -1
  26. package/lib/resolvers/type/product/product-configurable-types.d.ts +62 -2
  27. package/lib/resolvers/type/product/product-configurable-types.js +10 -10
  28. package/lib/resolvers/type/product/product-configurable-types.js.map +1 -1
  29. package/lib/resolvers/type/product/product-plan-types.d.ts +53 -2
  30. package/lib/resolvers/type/product/product-plan-types.js +9 -9
  31. package/lib/resolvers/type/product/product-plan-types.js.map +1 -1
  32. package/lib/resolvers/type/product/product-simple-types.d.ts +85 -2
  33. package/lib/resolvers/type/product/product-simple-types.js +7 -7
  34. package/lib/resolvers/type/product/product-simple-types.js.map +1 -1
  35. package/lib/resolvers/type/product/product-tokenized-types.d.ts +67 -2
  36. package/lib/resolvers/type/product/product-tokenized-types.js +19 -10
  37. package/lib/resolvers/type/product/product-tokenized-types.js.map +1 -1
  38. package/lib/resolvers/type/product/product-types.d.ts +38 -2
  39. package/lib/resolvers/type/product/product-types.js +15 -15
  40. package/lib/resolvers/type/product/product-types.js.map +1 -1
  41. package/lib/resolvers/type/token-types.d.ts +9 -12
  42. package/lib/resolvers/type/token-types.js +22 -3
  43. package/lib/resolvers/type/token-types.js.map +1 -1
  44. package/lib/roles/all.js +38 -17
  45. package/lib/roles/all.js.map +1 -1
  46. package/lib/roles/index.js +1 -0
  47. package/lib/roles/index.js.map +1 -1
  48. package/lib/roles/loggedIn.js +9 -14
  49. package/lib/roles/loggedIn.js.map +1 -1
  50. package/lib/schema/mutation.js +5 -1
  51. package/lib/schema/mutation.js.map +1 -1
  52. package/lib/schema/query.js +5 -0
  53. package/lib/schema/query.js.map +1 -1
  54. package/lib/schema/types/order/item.js +1 -0
  55. package/lib/schema/types/order/item.js.map +1 -1
  56. package/lib/schema/types/product/tokenized-product.js +2 -0
  57. package/lib/schema/types/product/tokenized-product.js.map +1 -1
  58. package/lib/schema/types/warehousing.js +9 -2
  59. package/lib/schema/types/warehousing.js.map +1 -1
  60. package/package.json +8 -8
  61. package/src/errors.ts +2 -0
  62. package/src/resolvers/mutations/index.ts +2 -0
  63. package/src/resolvers/mutations/warehousing/invalidateToken.ts +42 -0
  64. package/src/resolvers/queries/index.ts +2 -1
  65. package/src/resolvers/queries/warehousing/tokens.ts +18 -0
  66. package/src/resolvers/type/order/order-item-types.ts +59 -49
  67. package/src/resolvers/type/order/order-types.ts +58 -54
  68. package/src/resolvers/type/product/product-bundle-types.ts +3 -3
  69. package/src/resolvers/type/product/product-configurable-types.ts +79 -19
  70. package/src/resolvers/type/product/product-plan-types.ts +34 -15
  71. package/src/resolvers/type/product/product-simple-types.ts +41 -10
  72. package/src/resolvers/type/product/product-tokenized-types.ts +43 -13
  73. package/src/resolvers/type/product/product-types.ts +77 -18
  74. package/src/resolvers/type/token-types.ts +35 -20
  75. package/src/roles/all.ts +46 -17
  76. package/src/roles/index.ts +1 -0
  77. package/src/roles/loggedIn.ts +10 -24
  78. package/src/schema/mutation.ts +5 -1
  79. package/src/schema/query.ts +5 -0
  80. package/src/schema/types/order/item.ts +1 -0
  81. package/src/schema/types/product/tokenized-product.ts +2 -0
  82. package/src/schema/types/warehousing.ts +9 -2
package/src/roles/all.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { Context } from '@unchainedshop/types/api.js';
2
+
1
3
  export const all = (role, actions) => {
2
4
  const isInLoginMutationResponse = (root) => {
3
5
  // eslint-disable-next-line
@@ -7,6 +9,27 @@ export const all = (role, actions) => {
7
9
  return false;
8
10
  };
9
11
 
12
+ const isOwnedToken = async (_: never, { tokenId }: { tokenId: string }, context: Context) => {
13
+ const { modules, userId, user } = context;
14
+
15
+ const token = await modules.warehousing.findToken({ tokenId });
16
+ if (!token) return true;
17
+
18
+ const isOwnedByUser =
19
+ token.userId === userId ||
20
+ user?.services?.web3?.some((service) => {
21
+ return service.address === token.walletAddress && service.verified;
22
+ });
23
+
24
+ if (isOwnedByUser) return true;
25
+
26
+ const accessKeyHeader = context.req.headers['x-token-accesskey'];
27
+ const accessKey = await context.modules.warehousing.buildAccessKeyForToken(tokenId);
28
+ if (accessKeyHeader === accessKey) return true;
29
+
30
+ return false;
31
+ };
32
+
10
33
  role.allow(actions.viewEvent, () => false);
11
34
  role.allow(actions.viewEvents, () => false);
12
35
  role.allow(actions.viewUser, () => false);
@@ -31,8 +54,6 @@ export const all = (role, actions) => {
31
54
  role.allow(actions.managePaymentProviders, () => false);
32
55
  role.allow(actions.manageDeliveryProviders, () => false);
33
56
  role.allow(actions.manageWarehousingProviders, () => false);
34
- role.allow(actions.updateToken, () => false);
35
- role.allow(actions.viewToken, () => false);
36
57
  role.allow(actions.manageAssortments, () => false);
37
58
  role.allow(actions.manageFilters, () => false);
38
59
  role.allow(actions.manageUsers, () => false);
@@ -49,14 +70,6 @@ export const all = (role, actions) => {
49
70
  role.allow(actions.markOrderRejected, () => false);
50
71
  role.allow(actions.markOrderPaid, () => false);
51
72
  role.allow(actions.markOrderDelivered, () => false);
52
- role.allow(actions.viewLogs, isInLoginMutationResponse);
53
- role.allow(actions.viewUserRoles, isInLoginMutationResponse);
54
- role.allow(actions.viewUserOrders, isInLoginMutationResponse);
55
- role.allow(actions.viewUserTokens, isInLoginMutationResponse);
56
- role.allow(actions.viewUserQuotations, isInLoginMutationResponse);
57
- role.allow(actions.viewUserPrivateInfos, isInLoginMutationResponse);
58
- role.allow(actions.viewUserEnrollments, isInLoginMutationResponse);
59
- role.allow(actions.viewUserProductReviews, isInLoginMutationResponse);
60
73
  role.allow(actions.reviewProduct, () => false);
61
74
  role.allow(actions.updateProductReview, () => false);
62
75
  role.allow(actions.manageProductReviews, () => false);
@@ -82,26 +95,42 @@ export const all = (role, actions) => {
82
95
  role.allow(actions.manageTwoFactor, () => false);
83
96
  role.allow(actions.impersonate, () => false);
84
97
  role.allow(actions.stopImpersonation, () => false);
98
+ role.allow(actions.viewTokens, () => false);
99
+
100
+ // special case: when doing a login mutation, the user is not logged in technically yet,
101
+ // but should be able to see user data of the user that is about to be logged in
102
+ role.allow(actions.viewLogs, isInLoginMutationResponse);
103
+ role.allow(actions.viewUserRoles, isInLoginMutationResponse);
104
+ role.allow(actions.viewUserOrders, isInLoginMutationResponse);
105
+ role.allow(actions.viewUserTokens, isInLoginMutationResponse);
106
+ role.allow(actions.viewUserQuotations, isInLoginMutationResponse);
107
+ role.allow(actions.viewUserPrivateInfos, isInLoginMutationResponse);
108
+ role.allow(actions.viewUserEnrollments, isInLoginMutationResponse);
109
+ role.allow(actions.viewUserProductReviews, isInLoginMutationResponse);
110
+
111
+ // special case: access to token sometimes works via a X-Token-AccessKey Header and thus should also be allowed for anonymous users
112
+ role.allow(actions.updateToken, isOwnedToken);
113
+ role.allow(actions.viewToken, isOwnedToken);
85
114
 
86
- // only allow if query is not demanding for drafts
115
+ // only allow if query is not demanding for drafts or inactive item lists
87
116
  role.allow(actions.viewProducts, (root, { includeDrafts }) => !includeDrafts);
117
+ role.allow(actions.viewAssortments, (root, { includeInactive }) => !includeInactive);
118
+ role.allow(actions.viewCountries, (root, { includeInactive }) => !includeInactive);
119
+ role.allow(actions.viewCurrencies, (root, { includeInactive }) => !includeInactive);
120
+ role.allow(actions.viewFilters, (root, { includeInactive }) => !includeInactive);
121
+ role.allow(actions.viewLanguages, (root, { includeInactive }) => !includeInactive);
122
+ role.allow(actions.search, (root, { includeInactive }) => !includeInactive);
88
123
 
89
124
  // public
90
125
  role.allow(actions.viewUserPublicInfos, () => true);
91
126
  role.allow(actions.viewProduct, () => true);
92
- role.allow(actions.viewLanguages, () => true);
93
127
  role.allow(actions.viewLanguage, () => true);
94
- role.allow(actions.viewCountries, () => true);
95
128
  role.allow(actions.viewCountry, () => true);
96
- role.allow(actions.viewCurrencies, () => true);
97
129
  role.allow(actions.viewCurrency, () => true);
98
130
  role.allow(actions.viewShopInfo, () => true);
99
- role.allow(actions.viewAssortments, () => true);
100
131
  role.allow(actions.viewAssortment, () => true);
101
132
  role.allow(actions.viewFilter, () => true);
102
- role.allow(actions.viewFilters, () => true);
103
133
  role.allow(actions.viewTranslations, () => true);
104
- role.allow(actions.search, () => true);
105
134
  role.allow(actions.logout, () => true);
106
135
  role.allow(actions.logoutAllSessions, () => true);
107
136
  role.allow(actions.loginAsGuest, () => true);
@@ -59,6 +59,7 @@ const actions: Record<string, string> = [
59
59
  'manageWarehousingProviders',
60
60
  'updateToken',
61
61
  'viewToken',
62
+ 'viewTokens',
62
63
  'manageAssortments',
63
64
  'manageFilters',
64
65
  'createCart',
@@ -2,15 +2,18 @@ import { Context } from '@unchainedshop/types/api.js';
2
2
  import { User } from '@unchainedshop/types/user.js';
3
3
 
4
4
  export const loggedIn = (role: any, actions: Record<string, string>) => {
5
- const isMyself = (
6
- user: User,
7
- foreignUser: { userId?: string } = {},
8
- ownUser: { userId?: string } = {},
9
- ) => {
10
- if (user && user.username && user.services && user.emails && !foreignUser.userId) {
5
+ const isMyself = (user: User, params: { userId?: string } = {}, ownUser: { userId?: string } = {}) => {
6
+ // user wants to access a field of a user
7
+ if (user && !params.userId) {
11
8
  return user._id === ownUser.userId;
12
9
  }
13
- return foreignUser.userId === ownUser.userId || !foreignUser.userId;
10
+ if (params.userId) {
11
+ // user wants to access a user object by userId
12
+ return params.userId === ownUser.userId;
13
+ }
14
+
15
+ // user wants to access himself
16
+ return true;
14
17
  };
15
18
 
16
19
  const isOwnedEmailAddress = (obj: any, params: { email?: string }, { user }: Context) => {
@@ -190,21 +193,6 @@ export const loggedIn = (role: any, actions: Record<string, string>) => {
190
193
  return credentials.userId === userId;
191
194
  };
192
195
 
193
- const isOwnedToken = async (
194
- obj: any,
195
- { tokenId }: { tokenId: string },
196
- { modules, userId, user }: Context,
197
- ) => {
198
- const token = await modules.warehousing.findToken({ tokenId });
199
- if (!token) return true;
200
- return (
201
- token.userId === userId ||
202
- user?.services?.web3?.some((service) => {
203
- return service.address === token.walletAddress && service.verified;
204
- })
205
- );
206
- };
207
-
208
196
  role.allow(actions.viewEvent, false);
209
197
  role.allow(actions.viewEvents, false);
210
198
  role.allow(actions.viewUser, isMyself);
@@ -240,8 +228,6 @@ export const loggedIn = (role: any, actions: Record<string, string>) => {
240
228
  role.allow(actions.voteProductReview, () => true);
241
229
  role.allow(actions.registerPaymentCredentials, () => true);
242
230
  role.allow(actions.managePaymentCredentials, isOwnedPaymentCredential);
243
- role.allow(actions.updateToken, isOwnedToken);
244
- role.allow(actions.viewToken, isOwnedToken);
245
231
  role.allow(actions.stopImpersonation, () => true);
246
232
  role.allow(actions.impersonate, () => false);
247
233
  role.allow(actions.confirmMediaUpload, () => true);
@@ -896,7 +896,10 @@ export default [
896
896
  """
897
897
  Sign a generic payment provider for registration
898
898
  """
899
- signPaymentProviderForCredentialRegistration(paymentProviderId: ID!): String
899
+ signPaymentProviderForCredentialRegistration(
900
+ paymentProviderId: ID!
901
+ transactionContext: JSON
902
+ ): String
900
903
 
901
904
  """
902
905
  Sign a generic order payment
@@ -911,6 +914,7 @@ export default [
911
914
  """
912
915
  Tokenize
913
916
  """
917
+ invalidateToken(tokenId: ID!): Token!
914
918
  exportToken(tokenId: ID!, quantity: Int! = 1, recipientWalletAddress: String!): Token!
915
919
 
916
920
  """
@@ -205,6 +205,11 @@ export default [
205
205
  """
206
206
  token(tokenId: ID!): Token
207
207
 
208
+ """
209
+ Get all tokens
210
+ """
211
+ tokens(limit: Int = 10, offset: Int = 0): [Token!]!
212
+
208
213
  """
209
214
  Returns total number of payment providers, optionally filtered by type
210
215
  """
@@ -29,6 +29,7 @@ export default [
29
29
  discounts: [OrderItemDiscount!]
30
30
  dispatches: [Dispatch!]
31
31
  configuration: [ProductConfigurationParameter!]
32
+ tokens: [Token!]!
32
33
  }
33
34
  `,
34
35
  ];
@@ -54,6 +54,8 @@ export default [
54
54
  contractAddress: String
55
55
  contractStandard: SmartContractStandard
56
56
  contractConfiguration: ContractConfiguration
57
+ tokens: [Token!]!
58
+ tokensCount: Int!
57
59
  }
58
60
  `,
59
61
  ];
@@ -44,12 +44,19 @@ export default [
44
44
 
45
45
  type Token @cacheControl(maxAge: 0, scope: PRIVATE) {
46
46
  _id: ID!
47
- user: User
48
- walletAddress: String
49
47
  product: TokenizedProduct!
50
48
  status: TokenExportStatus!
51
49
  quantity: Int!
50
+ isInvalidateable: Boolean!
51
+ """
52
+ Get an access key that you can pass along the HTTP Header "x-token-accesskey" to access the token anonymously.
53
+ """
54
+ accessKey: String!
55
+ invalidatedDate: DateTime
56
+ user: User
57
+ expiryDate: DateTime
52
58
  contractAddress: String
59
+ walletAddress: String
53
60
  chainId: String
54
61
  chainTokenId: String
55
62
  ercMetadata(forceLocale: String): JSON