@unchainedshop/api 2.8.18 → 2.9.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.
- package/jest.config.js +2 -2
- package/lib/errors.d.ts +1 -0
- package/lib/errors.js +1 -0
- package/lib/errors.js.map +1 -1
- package/lib/resolvers/mutations/index.d.ts +1 -0
- package/lib/resolvers/mutations/index.js +2 -0
- package/lib/resolvers/mutations/index.js.map +1 -1
- package/lib/resolvers/mutations/warehousing/invalidateToken.d.ts +4 -0
- package/lib/resolvers/mutations/warehousing/invalidateToken.js +26 -0
- package/lib/resolvers/mutations/warehousing/invalidateToken.js.map +1 -0
- package/lib/resolvers/queries/index.d.ts +1 -0
- package/lib/resolvers/queries/index.js +2 -0
- package/lib/resolvers/queries/index.js.map +1 -1
- package/lib/resolvers/queries/warehousing/tokens.d.ts +5 -0
- package/lib/resolvers/queries/warehousing/tokens.js +6 -0
- package/lib/resolvers/queries/warehousing/tokens.js.map +1 -0
- package/lib/resolvers/type/index.d.ts +367 -9
- package/lib/resolvers/type/order/order-item-types.d.ts +15 -17
- package/lib/resolvers/type/order/order-item-types.js +28 -23
- package/lib/resolvers/type/order/order-item-types.js.map +1 -1
- package/lib/resolvers/type/order/order-types.d.ts +15 -19
- package/lib/resolvers/type/order/order-types.js +48 -28
- package/lib/resolvers/type/order/order-types.js.map +1 -1
- package/lib/resolvers/type/product/product-bundle-types.d.ts +34 -2
- package/lib/resolvers/type/product/product-bundle-types.js.map +1 -1
- package/lib/resolvers/type/product/product-configurable-types.d.ts +62 -2
- package/lib/resolvers/type/product/product-configurable-types.js +10 -10
- package/lib/resolvers/type/product/product-configurable-types.js.map +1 -1
- package/lib/resolvers/type/product/product-plan-types.d.ts +53 -2
- package/lib/resolvers/type/product/product-plan-types.js +9 -9
- package/lib/resolvers/type/product/product-plan-types.js.map +1 -1
- package/lib/resolvers/type/product/product-simple-types.d.ts +85 -2
- package/lib/resolvers/type/product/product-simple-types.js +7 -7
- package/lib/resolvers/type/product/product-simple-types.js.map +1 -1
- package/lib/resolvers/type/product/product-tokenized-types.d.ts +67 -2
- package/lib/resolvers/type/product/product-tokenized-types.js +19 -10
- package/lib/resolvers/type/product/product-tokenized-types.js.map +1 -1
- package/lib/resolvers/type/product/product-types.d.ts +38 -2
- package/lib/resolvers/type/product/product-types.js +15 -15
- package/lib/resolvers/type/product/product-types.js.map +1 -1
- package/lib/resolvers/type/token-types.d.ts +9 -12
- package/lib/resolvers/type/token-types.js +22 -3
- package/lib/resolvers/type/token-types.js.map +1 -1
- package/lib/roles/all.js +38 -17
- package/lib/roles/all.js.map +1 -1
- package/lib/roles/index.js +1 -0
- package/lib/roles/index.js.map +1 -1
- package/lib/roles/loggedIn.js +9 -14
- package/lib/roles/loggedIn.js.map +1 -1
- package/lib/schema/mutation.js +5 -1
- package/lib/schema/mutation.js.map +1 -1
- package/lib/schema/query.js +5 -0
- package/lib/schema/query.js.map +1 -1
- package/lib/schema/types/order/item.js +1 -0
- package/lib/schema/types/order/item.js.map +1 -1
- package/lib/schema/types/product/tokenized-product.js +2 -0
- package/lib/schema/types/product/tokenized-product.js.map +1 -1
- package/lib/schema/types/warehousing.js +9 -2
- package/lib/schema/types/warehousing.js.map +1 -1
- package/package.json +8 -8
- package/src/errors.ts +2 -0
- package/src/resolvers/mutations/index.ts +2 -0
- package/src/resolvers/mutations/warehousing/invalidateToken.ts +42 -0
- package/src/resolvers/queries/index.ts +2 -1
- package/src/resolvers/queries/warehousing/tokens.ts +18 -0
- package/src/resolvers/type/order/order-item-types.ts +59 -49
- package/src/resolvers/type/order/order-types.ts +58 -54
- package/src/resolvers/type/product/product-bundle-types.ts +3 -3
- package/src/resolvers/type/product/product-configurable-types.ts +79 -19
- package/src/resolvers/type/product/product-plan-types.ts +34 -15
- package/src/resolvers/type/product/product-simple-types.ts +41 -10
- package/src/resolvers/type/product/product-tokenized-types.ts +43 -13
- package/src/resolvers/type/product/product-types.ts +77 -18
- package/src/resolvers/type/token-types.ts +35 -20
- package/src/roles/all.ts +46 -17
- package/src/roles/index.ts +1 -0
- package/src/roles/loggedIn.ts +10 -24
- package/src/schema/mutation.ts +5 -1
- package/src/schema/query.ts +5 -0
- package/src/schema/types/order/item.ts +1 -0
- package/src/schema/types/product/tokenized-product.ts +2 -0
- 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);
|
package/src/roles/index.ts
CHANGED
package/src/roles/loggedIn.ts
CHANGED
|
@@ -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
|
|
7
|
-
|
|
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
|
-
|
|
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);
|
package/src/schema/mutation.ts
CHANGED
|
@@ -896,7 +896,10 @@ export default [
|
|
|
896
896
|
"""
|
|
897
897
|
Sign a generic payment provider for registration
|
|
898
898
|
"""
|
|
899
|
-
signPaymentProviderForCredentialRegistration(
|
|
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
|
"""
|
package/src/schema/query.ts
CHANGED
|
@@ -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
|
"""
|
|
@@ -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
|