@unchainedshop/api 3.1.1 → 3.1.3

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 (83) hide show
  1. package/lib/loaders/index.d.ts.map +1 -1
  2. package/lib/loaders/index.js +56 -44
  3. package/lib/loaders/index.js.map +1 -1
  4. package/package.json +5 -6
  5. package/src/loaders/index.ts +63 -54
  6. package/tests/api-index.test.ts +18 -11
  7. package/jest.config.js +0 -17
  8. package/lib/express/createApolloMiddleware.d.ts +0 -4
  9. package/lib/express/createApolloMiddleware.d.ts.map +0 -1
  10. package/lib/express/createApolloMiddleware.js +0 -36
  11. package/lib/express/createApolloMiddleware.js.map +0 -1
  12. package/lib/express/createSingleSignOnMiddleware.d.ts +0 -5
  13. package/lib/express/createSingleSignOnMiddleware.d.ts.map +0 -1
  14. package/lib/express/createSingleSignOnMiddleware.js +0 -71
  15. package/lib/express/createSingleSignOnMiddleware.js.map +0 -1
  16. package/lib/hashPassword.d.ts +0 -2
  17. package/lib/hashPassword.d.ts.map +0 -1
  18. package/lib/hashPassword.js +0 -5
  19. package/lib/hashPassword.js.map +0 -1
  20. package/lib/resolvers/mutations/accounts/buildSecretTOTPAuthURL.d.ts +0 -3
  21. package/lib/resolvers/mutations/accounts/buildSecretTOTPAuthURL.d.ts.map +0 -1
  22. package/lib/resolvers/mutations/accounts/buildSecretTOTPAuthURL.js +0 -6
  23. package/lib/resolvers/mutations/accounts/buildSecretTOTPAuthURL.js.map +0 -1
  24. package/lib/resolvers/mutations/accounts/disableTOTP.d.ts +0 -6
  25. package/lib/resolvers/mutations/accounts/disableTOTP.d.ts.map +0 -1
  26. package/lib/resolvers/mutations/accounts/disableTOTP.js +0 -27
  27. package/lib/resolvers/mutations/accounts/disableTOTP.js.map +0 -1
  28. package/lib/resolvers/mutations/accounts/enableTOTP.d.ts +0 -6
  29. package/lib/resolvers/mutations/accounts/enableTOTP.d.ts.map +0 -1
  30. package/lib/resolvers/mutations/accounts/enableTOTP.js +0 -20
  31. package/lib/resolvers/mutations/accounts/enableTOTP.js.map +0 -1
  32. package/lib/resolvers/mutations/accounts/linkOAuthAccount.d.ts +0 -7
  33. package/lib/resolvers/mutations/accounts/linkOAuthAccount.d.ts.map +0 -1
  34. package/lib/resolvers/mutations/accounts/linkOAuthAccount.js +0 -30
  35. package/lib/resolvers/mutations/accounts/linkOAuthAccount.js.map +0 -1
  36. package/lib/resolvers/mutations/accounts/loginWithOAuth.d.ts +0 -8
  37. package/lib/resolvers/mutations/accounts/loginWithOAuth.d.ts.map +0 -1
  38. package/lib/resolvers/mutations/accounts/loginWithOAuth.js +0 -25
  39. package/lib/resolvers/mutations/accounts/loginWithOAuth.js.map +0 -1
  40. package/lib/resolvers/mutations/accounts/logoutAllSessions.d.ts +0 -5
  41. package/lib/resolvers/mutations/accounts/logoutAllSessions.d.ts.map +0 -1
  42. package/lib/resolvers/mutations/accounts/logoutAllSessions.js +0 -20
  43. package/lib/resolvers/mutations/accounts/logoutAllSessions.js.map +0 -1
  44. package/lib/resolvers/mutations/accounts/unlinkOAuthAccount.d.ts +0 -6
  45. package/lib/resolvers/mutations/accounts/unlinkOAuthAccount.d.ts.map +0 -1
  46. package/lib/resolvers/mutations/accounts/unlinkOAuthAccount.js +0 -13
  47. package/lib/resolvers/mutations/accounts/unlinkOAuthAccount.js.map +0 -1
  48. package/lib/resolvers/mutations/assortments/addAssortmentMedia.d.ts +0 -6
  49. package/lib/resolvers/mutations/assortments/addAssortmentMedia.d.ts.map +0 -1
  50. package/lib/resolvers/mutations/assortments/addAssortmentMedia.js +0 -18
  51. package/lib/resolvers/mutations/assortments/addAssortmentMedia.js.map +0 -1
  52. package/lib/resolvers/mutations/products/addProductMedia.d.ts +0 -6
  53. package/lib/resolvers/mutations/products/addProductMedia.d.ts.map +0 -1
  54. package/lib/resolvers/mutations/products/addProductMedia.js +0 -18
  55. package/lib/resolvers/mutations/products/addProductMedia.js.map +0 -1
  56. package/lib/resolvers/mutations/users/updateUserAvatar.d.ts +0 -6
  57. package/lib/resolvers/mutations/users/updateUserAvatar.d.ts.map +0 -1
  58. package/lib/resolvers/mutations/users/updateUserAvatar.js +0 -22
  59. package/lib/resolvers/mutations/users/updateUserAvatar.js.map +0 -1
  60. package/lib/resolvers/mutations/utils/getOrderCart.d.ts +0 -7
  61. package/lib/resolvers/mutations/utils/getOrderCart.d.ts.map +0 -1
  62. package/lib/resolvers/mutations/utils/getOrderCart.js +0 -13
  63. package/lib/resolvers/mutations/utils/getOrderCart.js.map +0 -1
  64. package/lib/resolvers/type/dispatch-types.d.ts +0 -15
  65. package/lib/resolvers/type/dispatch-types.d.ts.map +0 -1
  66. package/lib/resolvers/type/dispatch-types.js +0 -16
  67. package/lib/resolvers/type/dispatch-types.js.map +0 -1
  68. package/lib/resolvers/type/oauth-account.d.ts +0 -6
  69. package/lib/resolvers/type/oauth-account.d.ts.map +0 -1
  70. package/lib/resolvers/type/oauth-account.js +0 -7
  71. package/lib/resolvers/type/oauth-account.js.map +0 -1
  72. package/lib/resolvers/type/oauth-provider.d.ts +0 -6
  73. package/lib/resolvers/type/oauth-provider.d.ts.map +0 -1
  74. package/lib/resolvers/type/oauth-provider.js +0 -6
  75. package/lib/resolvers/type/oauth-provider.js.map +0 -1
  76. package/lib/resolvers/type/stock-types.d.ts +0 -14
  77. package/lib/resolvers/type/stock-types.d.ts.map +0 -1
  78. package/lib/resolvers/type/stock-types.js +0 -15
  79. package/lib/resolvers/type/stock-types.js.map +0 -1
  80. package/lib/user-context.d.ts +0 -7
  81. package/lib/user-context.d.ts.map +0 -1
  82. package/lib/user-context.js +0 -76
  83. package/lib/user-context.js.map +0 -1
@@ -1,71 +0,0 @@
1
- import { createLogger } from '@unchainedshop/logger';
2
- import cookie from 'cookie';
3
- import { getCurrentContextResolver } from '../context.js';
4
- const { NODE_ENV, UNCHAINED_CLOUD_ENDPOINT, UNCHAINED_COOKIE_NAME = 'unchained_token', UNCHAINED_COOKIE_DOMAIN, } = process.env;
5
- const logger = createLogger('unchained:unchained-cloud-sso');
6
- const loginWithSingleSignOn = async (remoteToken, context) => {
7
- const domain = UNCHAINED_COOKIE_DOMAIN;
8
- const result = await fetch(UNCHAINED_CLOUD_ENDPOINT, {
9
- method: 'POST',
10
- headers: {
11
- 'content-type': 'application/json',
12
- },
13
- duplex: 'half',
14
- body: JSON.stringify({
15
- operationName: 'consume',
16
- variables: {
17
- token: remoteToken,
18
- },
19
- query: 'mutation consume($token: ID!) { controlConsumeSingleSignOnToken(token: $token) { domain } }',
20
- }),
21
- });
22
- const json = await result.json();
23
- if (json?.errors?.length > 0) {
24
- throw new Error(json.errors[0].message);
25
- }
26
- if (domain === 'localhost' || domain === json?.data?.controlConsumeSingleSignOnToken?.domain) {
27
- // create sso user if not exist and login
28
- const ssoUserId = (await context.modules.users.findUser({ username: 'sso' }))?._id ||
29
- (await context.modules.accounts.createUser({
30
- username: 'sso',
31
- roles: ['admin'],
32
- email: 'sso@unchained.local',
33
- password: null,
34
- guest: false,
35
- }, { skipMessaging: true }));
36
- const { tokenExpires, token } = await context.modules.accounts.createLoginToken(ssoUserId, context);
37
- const expires = new Date(tokenExpires || new Date().getTime() + 100000);
38
- const authCookie = cookie.serialize(UNCHAINED_COOKIE_NAME, token, {
39
- domain,
40
- httpOnly: true,
41
- expires,
42
- path: '/',
43
- sameSite: 'strict',
44
- secure: NODE_ENV === 'production',
45
- });
46
- return authCookie;
47
- }
48
- throw new Error('Invalid token/domain pair');
49
- };
50
- export default async function singleSignOnMiddleware(req, res, next) {
51
- try {
52
- if (req.query?.token && UNCHAINED_CLOUD_ENDPOINT) {
53
- const contextResolver = getCurrentContextResolver();
54
- const context = await contextResolver({ req, res });
55
- const authCookie = await loginWithSingleSignOn(req.query.token, context);
56
- if (authCookie) {
57
- res.writeHead(303, {
58
- 'Set-Cookie': authCookie,
59
- Location: '/',
60
- });
61
- res.end();
62
- return;
63
- }
64
- }
65
- }
66
- catch (e) {
67
- logger.error(e.message);
68
- }
69
- next();
70
- }
71
- //# sourceMappingURL=createSingleSignOnMiddleware.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createSingleSignOnMiddleware.js","sourceRoot":"","sources":["../../src/express/createSingleSignOnMiddleware.ts"],"names":[],"mappings":"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"}
@@ -1,2 +0,0 @@
1
- export declare const hashPassword: (password: string) => string;
2
- //# sourceMappingURL=hashPassword.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hashPassword.d.ts","sourceRoot":"","sources":["../src/hashPassword.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,YAAY,aAAc,MAAM,KAAG,MAE/C,CAAC"}
@@ -1,5 +0,0 @@
1
- import crypto from 'crypto';
2
- export const hashPassword = (password) => {
3
- return crypto.createHash('sha256').update(password).digest('hex');
4
- };
5
- //# sourceMappingURL=hashPassword.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hashPassword.js","sourceRoot":"","sources":["../src/hashPassword.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,QAAgB,EAAU,EAAE;IACvD,OAAO,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACpE,CAAC,CAAC"}
@@ -1,3 +0,0 @@
1
- import { Context, Root } from '@unchainedshop/types/api.js';
2
- export default function buildTOTPSecret(root: Root, _: any, { modules, userId }: Context): Promise<string>;
3
- //# sourceMappingURL=buildSecretTOTPAuthURL.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"buildSecretTOTPAuthURL.d.ts","sourceRoot":"","sources":["../../../../src/resolvers/mutations/accounts/buildSecretTOTPAuthURL.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AAE5D,wBAA8B,eAAe,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,OAAO,mBAI7F"}
@@ -1,6 +0,0 @@
1
- import { log } from '@unchainedshop/logger';
2
- export default async function buildTOTPSecret(root, _, { modules, userId }) {
3
- log('mutation buildTOTPSecret', { userId });
4
- return modules.accounts.buildTOTPSecret();
5
- }
6
- //# sourceMappingURL=buildSecretTOTPAuthURL.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"buildSecretTOTPAuthURL.js","sourceRoot":"","sources":["../../../../src/resolvers/mutations/accounts/buildSecretTOTPAuthURL.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAC;AAG5C,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,eAAe,CAAC,IAAU,EAAE,CAAM,EAAE,EAAE,OAAO,EAAE,MAAM,EAAW;IAC5F,GAAG,CAAC,0BAA0B,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IAE5C,OAAO,OAAO,CAAC,QAAQ,CAAC,eAAe,EAAE,CAAC;AAC5C,CAAC"}
@@ -1,6 +0,0 @@
1
- import { Context, Root } from '@unchainedshop/types/api.js';
2
- export default function disableTOTP(root: Root, params: {
3
- code: string;
4
- userId: string;
5
- }, { modules, userId }: Context): Promise<import("@unchainedshop/types/user.js").User>;
6
- //# sourceMappingURL=disableTOTP.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"disableTOTP.d.ts","sourceRoot":"","sources":["../../../../src/resolvers/mutations/accounts/disableTOTP.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AAO5D,wBAA8B,WAAW,CACvC,IAAI,EAAE,IAAI,EACV,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,EACxC,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,OAAO,wDAwB7B"}
@@ -1,27 +0,0 @@
1
- import { log } from '@unchainedshop/logger';
2
- import { TwoFactorCodeDidNotMatchError, TwoFactorNotSetError, UserNotFoundError, } from '../../../errors.js';
3
- export default async function disableTOTP(root, params, { modules, userId }) {
4
- const normalizedUserId = params.userId || userId;
5
- log(`mutation disableTOTP ${params.code} ${normalizedUserId}`, {
6
- userId,
7
- });
8
- const user = await modules.users.findUserById(normalizedUserId);
9
- if (!user)
10
- throw new UserNotFoundError({ userId: normalizedUserId });
11
- try {
12
- await modules.accounts.disableTOTP(normalizedUserId, params.code);
13
- }
14
- catch (e) {
15
- if (e?.message?.includes("2FA code didn't match"))
16
- throw new TwoFactorCodeDidNotMatchError({
17
- submittedCode: params.code,
18
- userId: params?.userId || userId,
19
- });
20
- else if (e?.message?.includes('2FA not set'))
21
- throw new TwoFactorNotSetError({ userId: params?.userId || userId });
22
- else
23
- throw e;
24
- }
25
- return user;
26
- }
27
- //# sourceMappingURL=disableTOTP.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"disableTOTP.js","sourceRoot":"","sources":["../../../../src/resolvers/mutations/accounts/disableTOTP.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAC;AAE5C,OAAO,EACL,6BAA6B,EAC7B,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,oBAAoB,CAAC;AAE5B,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,WAAW,CACvC,IAAU,EACV,MAAwC,EACxC,EAAE,OAAO,EAAE,MAAM,EAAW;IAE5B,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC;IAEjD,GAAG,CAAC,wBAAwB,MAAM,CAAC,IAAI,IAAI,gBAAgB,EAAE,EAAE;QAC7D,MAAM;KACP,CAAC,CAAC;IAEH,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,gBAAgB,CAAC,CAAC;IAChE,IAAI,CAAC,IAAI;QAAE,MAAM,IAAI,iBAAiB,CAAC,EAAE,MAAM,EAAE,gBAAgB,EAAE,CAAC,CAAC;IACrE,IAAI,CAAC;QACH,MAAM,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,gBAAgB,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;IACpE,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,IAAI,CAAC,EAAE,OAAO,EAAE,QAAQ,CAAC,uBAAuB,CAAC;YAC/C,MAAM,IAAI,6BAA6B,CAAC;gBACtC,aAAa,EAAE,MAAM,CAAC,IAAI;gBAC1B,MAAM,EAAE,MAAM,EAAE,MAAM,IAAI,MAAM;aACjC,CAAC,CAAC;aACA,IAAI,CAAC,EAAE,OAAO,EAAE,QAAQ,CAAC,aAAa,CAAC;YAC1C,MAAM,IAAI,oBAAoB,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,IAAI,MAAM,EAAE,CAAC,CAAC;;YAClE,MAAM,CAAC,CAAC;IACf,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -1,6 +0,0 @@
1
- import { Context, Root } from '@unchainedshop/types/api.js';
2
- export default function enableTOTP(root: Root, params: {
3
- code: string;
4
- secretBase32: string;
5
- }, { modules, userId }: Context): Promise<import("@unchainedshop/types/user.js").User>;
6
- //# sourceMappingURL=enableTOTP.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"enableTOTP.d.ts","sourceRoot":"","sources":["../../../../src/resolvers/mutations/accounts/enableTOTP.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AAG5D,wBAA8B,UAAU,CACtC,IAAI,EAAE,IAAI,EACV,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,EAC9C,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,OAAO,wDAe7B"}
@@ -1,20 +0,0 @@
1
- import { log } from '@unchainedshop/logger';
2
- import { TwoFactorAlreadySetError, TwoFactorCodeDidNotMatchError } from '../../../errors.js';
3
- export default async function enableTOTP(root, params, { modules, userId }) {
4
- log(`mutation enableTOTP ${params.code}`, {
5
- userId,
6
- });
7
- try {
8
- await modules.accounts.enableTOTP(userId, params.secretBase32, params.code);
9
- }
10
- catch (e) {
11
- if (e?.message?.includes("2FA code didn't match"))
12
- throw new TwoFactorCodeDidNotMatchError({ submittedCode: params.code, userId });
13
- else if (e?.message?.includes('2FA already set'))
14
- throw new TwoFactorAlreadySetError({ userId });
15
- else
16
- throw e;
17
- }
18
- return modules.users.findUserById(userId);
19
- }
20
- //# sourceMappingURL=enableTOTP.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"enableTOTP.js","sourceRoot":"","sources":["../../../../src/resolvers/mutations/accounts/enableTOTP.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAC;AAE5C,OAAO,EAAE,wBAAwB,EAAE,6BAA6B,EAAE,MAAM,oBAAoB,CAAC;AAE7F,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,UAAU,CACtC,IAAU,EACV,MAA8C,EAC9C,EAAE,OAAO,EAAE,MAAM,EAAW;IAE5B,GAAG,CAAC,uBAAuB,MAAM,CAAC,IAAI,EAAE,EAAE;QACxC,MAAM;KACP,CAAC,CAAC;IACH,IAAI,CAAC;QACH,MAAM,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;IAC9E,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,IAAI,CAAC,EAAE,OAAO,EAAE,QAAQ,CAAC,uBAAuB,CAAC;YAC/C,MAAM,IAAI,6BAA6B,CAAC,EAAE,aAAa,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;aAC7E,IAAI,CAAC,EAAE,OAAO,EAAE,QAAQ,CAAC,iBAAiB,CAAC;YAAE,MAAM,IAAI,wBAAwB,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;;YAC5F,MAAM,CAAC,CAAC;IACf,CAAC;IAED,OAAO,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;AAC5C,CAAC"}
@@ -1,7 +0,0 @@
1
- import { Context, Root } from '@unchainedshop/types/api.js';
2
- export default function linkOAuthAccount(root: Root, { provider, redirectUrl, authorizationCode, }: {
3
- provider: string;
4
- redirectUrl: string;
5
- authorizationCode: string;
6
- }, context: Context): Promise<boolean>;
7
- //# sourceMappingURL=linkOAuthAccount.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"linkOAuthAccount.d.ts","sourceRoot":"","sources":["../../../../src/resolvers/mutations/accounts/linkOAuthAccount.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AAG5D,wBAA8B,gBAAgB,CAC5C,IAAI,EAAE,IAAI,EACV,EACE,QAAQ,EACR,WAAW,EACX,iBAAiB,GAClB,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,iBAAiB,EAAE,MAAM,CAAA;CAAE,EACvE,OAAO,EAAE,OAAO,oBAuCjB"}
@@ -1,30 +0,0 @@
1
- import { log } from '@unchainedshop/logger';
2
- import { AuthOperationFailedError } from '../../../errors.js';
3
- export default async function linkOAuthAccount(root, { provider, redirectUrl, authorizationCode, }, context) {
4
- const { userId, user } = context;
5
- log(`mutation linkOAuthAccount ${user.username}`, {
6
- userId,
7
- });
8
- try {
9
- const { modules } = context;
10
- const authorizationToken = await modules.accounts.oAuth2.getAuthorizationToken(provider, authorizationCode, redirectUrl);
11
- if (!authorizationToken)
12
- throw new Error('Unable to authorize user');
13
- const { id, ...data } = await modules.accounts.oAuth2.getAccountData(provider, authorizationToken);
14
- await modules.users.updateUser({ _id: userId }, {
15
- $push: {
16
- [`services.oauth.${provider}`]: {
17
- id,
18
- authorizationToken,
19
- authorizationCode,
20
- data,
21
- },
22
- },
23
- }, { upsert: true });
24
- return true;
25
- }
26
- catch {
27
- throw new AuthOperationFailedError({});
28
- }
29
- }
30
- //# sourceMappingURL=linkOAuthAccount.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"linkOAuthAccount.js","sourceRoot":"","sources":["../../../../src/resolvers/mutations/accounts/linkOAuthAccount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAC;AAE5C,OAAO,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAE9D,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,gBAAgB,CAC5C,IAAU,EACV,EACE,QAAQ,EACR,WAAW,EACX,iBAAiB,GACoD,EACvE,OAAgB;IAEhB,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC;IAEjC,GAAG,CAAC,6BAA6B,IAAI,CAAC,QAAQ,EAAE,EAAE;QAChD,MAAM;KACP,CAAC,CAAC;IACH,IAAI,CAAC;QACH,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;QAE5B,MAAM,kBAAkB,GAAG,MAAM,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,qBAAqB,CAC5E,QAAQ,EACR,iBAAiB,EACjB,WAAW,CACZ,CAAC;QAEF,IAAI,CAAC,kBAAkB;YAAE,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;QAErE,MAAM,EAAE,EAAE,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,cAAc,CAAC,QAAQ,EAAE,kBAAkB,CAAC,CAAC;QAEnG,MAAM,OAAO,CAAC,KAAK,CAAC,UAAU,CAC5B,EAAE,GAAG,EAAE,MAAM,EAAE,EACf;YACE,KAAK,EAAE;gBACL,CAAC,kBAAkB,QAAQ,EAAE,CAAC,EAAE;oBAC9B,EAAE;oBACF,kBAAkB;oBAClB,iBAAiB;oBACjB,IAAI;iBACL;aACF;SACF,EACD,EAAE,MAAM,EAAE,IAAI,EAAE,CACjB,CAAC;QAEF,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,wBAAwB,CAAC,EAAE,CAAC,CAAC;IACzC,CAAC;AACH,CAAC"}
@@ -1,8 +0,0 @@
1
- import { Context } from '@unchainedshop/types/api.js';
2
- declare const loginWithOAuth: (_: any, { provider, authorizationCode, redirectUrl, }: {
3
- provider: string;
4
- authorizationCode: string;
5
- redirectUrl: string;
6
- }, context: Context) => Promise<any | null>;
7
- export default loginWithOAuth;
8
- //# sourceMappingURL=loginWithOAuth.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"loginWithOAuth.d.ts","sourceRoot":"","sources":["../../../../src/resolvers/mutations/accounts/loginWithOAuth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAStD,QAAA,MAAM,cAAc,0DAMf;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,iBAAiB,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,WAC9D,OAAO,KACf,OAAO,CAAC,GAAG,GAAG,IAAI,CAkBpB,CAAC;AAEF,eAAe,cAAc,CAAC"}
@@ -1,25 +0,0 @@
1
- import { log } from '@unchainedshop/logger';
2
- import { AuthOperationFailedError, EmailAlreadyExistsError, UsernameAlreadyExistsError, UsernameOrEmailRequiredError, } from '../../../errors.js';
3
- const loginWithOAuth = async (_, { provider, authorizationCode, redirectUrl, }, context) => {
4
- log(`mutation loginWithOAuth ${provider} ${authorizationCode}`);
5
- try {
6
- return context.modules.accounts.loginWithService({
7
- service: 'oauth2',
8
- authorizationCode,
9
- provider,
10
- redirectUrl,
11
- }, context);
12
- }
13
- catch (e) {
14
- if (e.code === 'EmailAlreadyExists')
15
- throw new EmailAlreadyExistsError({});
16
- else if (e.code === 'UsernameAlreadyExists')
17
- throw new UsernameAlreadyExistsError({});
18
- else if (e.code === 'UsernameOrEmailRequired')
19
- throw new UsernameOrEmailRequiredError({});
20
- else
21
- throw new AuthOperationFailedError({});
22
- }
23
- };
24
- export default loginWithOAuth;
25
- //# sourceMappingURL=loginWithOAuth.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"loginWithOAuth.js","sourceRoot":"","sources":["../../../../src/resolvers/mutations/accounts/loginWithOAuth.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAC;AAC5C,OAAO,EACL,wBAAwB,EACxB,uBAAuB,EACvB,0BAA0B,EAC1B,4BAA4B,GAC7B,MAAM,oBAAoB,CAAC;AAE5B,MAAM,cAAc,GAAG,KAAK,EAC1B,CAAC,EACD,EACE,QAAQ,EACR,iBAAiB,EACjB,WAAW,GAC0D,EACvE,OAAgB,EACK,EAAE;IACvB,GAAG,CAAC,2BAA2B,QAAQ,IAAI,iBAAiB,EAAE,CAAC,CAAC;IAChE,IAAI,CAAC;QACH,OAAO,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAC9C;YACE,OAAO,EAAE,QAAQ;YACjB,iBAAiB;YACjB,QAAQ;YACR,WAAW;SACZ,EACD,OAAO,CACR,CAAC;IACJ,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,IAAI,CAAC,CAAC,IAAI,KAAK,oBAAoB;YAAE,MAAM,IAAI,uBAAuB,CAAC,EAAE,CAAC,CAAC;aACtE,IAAI,CAAC,CAAC,IAAI,KAAK,uBAAuB;YAAE,MAAM,IAAI,0BAA0B,CAAC,EAAE,CAAC,CAAC;aACjF,IAAI,CAAC,CAAC,IAAI,KAAK,yBAAyB;YAAE,MAAM,IAAI,4BAA4B,CAAC,EAAE,CAAC,CAAC;;YACrF,MAAM,IAAI,wBAAwB,CAAC,EAAE,CAAC,CAAC;IAC9C,CAAC;AACH,CAAC,CAAC;AAEF,eAAe,cAAc,CAAC"}
@@ -1,5 +0,0 @@
1
- import { Context, Root } from '@unchainedshop/types/api.js';
2
- export default function logoutAllSessions(root: Root, _: any, context: Context): Promise<{
3
- success: boolean;
4
- }>;
5
- //# sourceMappingURL=logoutAllSessions.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"logoutAllSessions.d.ts","sourceRoot":"","sources":["../../../../src/resolvers/mutations/accounts/logoutAllSessions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AAG5D,wBAA8B,iBAAiB,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO;;GAuBnF"}
@@ -1,20 +0,0 @@
1
- import { log, LogLevel } from '@unchainedshop/logger';
2
- export default async function logoutAllSessions(root, _, context) {
3
- const { modules, userId, setLoginToken } = context;
4
- log('mutation logoutAllSessions', { userId });
5
- const loggedOut = await modules.accounts.logout({
6
- loginToken: context.loginToken,
7
- userId: context.userId,
8
- }, context);
9
- if (loggedOut.error) {
10
- log('Error while logging out', {
11
- logLevel: LogLevel.Error,
12
- ...loggedOut.error,
13
- });
14
- }
15
- else {
16
- setLoginToken(context.res, null);
17
- }
18
- return { success: loggedOut.success };
19
- }
20
- //# sourceMappingURL=logoutAllSessions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"logoutAllSessions.js","sourceRoot":"","sources":["../../../../src/resolvers/mutations/accounts/logoutAllSessions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEtD,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,iBAAiB,CAAC,IAAU,EAAE,CAAM,EAAE,OAAgB;IAClF,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC;IAEnD,GAAG,CAAC,4BAA4B,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IAE9C,MAAM,SAAS,GAAG,MAAM,OAAO,CAAC,QAAQ,CAAC,MAAM,CAC7C;QACE,UAAU,EAAE,OAAO,CAAC,UAAU;QAC9B,MAAM,EAAE,OAAO,CAAC,MAAM;KACvB,EACD,OAAO,CACR,CAAC;IAEF,IAAI,SAAS,CAAC,KAAK,EAAE,CAAC;QACpB,GAAG,CAAC,yBAAyB,EAAE;YAC7B,QAAQ,EAAE,QAAQ,CAAC,KAAK;YACxB,GAAG,SAAS,CAAC,KAAK;SACnB,CAAC,CAAC;IACL,CAAC;SAAM,CAAC;QACN,aAAa,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IACnC,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,SAAS,CAAC,OAAO,EAAE,CAAC;AACxC,CAAC"}
@@ -1,6 +0,0 @@
1
- import { Context, Root } from '@unchainedshop/types/api.js';
2
- export default function unlinkOAuthAccount(root: Root, { provider, oAuthAccountId }: {
3
- provider: string;
4
- oAuthAccountId: string;
5
- }, context: Context): Promise<import("@unchainedshop/types/user.js").User>;
6
- //# sourceMappingURL=unlinkOAuthAccount.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"unlinkOAuthAccount.d.ts","sourceRoot":"","sources":["../../../../src/resolvers/mutations/accounts/unlinkOAuthAccount.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AAE5D,wBAA8B,kBAAkB,CAC9C,IAAI,EAAE,IAAI,EACV,EAAE,QAAQ,EAAE,cAAc,EAAE,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,MAAM,CAAA;CAAE,EAC1E,OAAO,EAAE,OAAO,wDAiBjB"}
@@ -1,13 +0,0 @@
1
- import { log } from '@unchainedshop/logger';
2
- export default async function unlinkOAuthAccount(root, { provider, oAuthAccountId }, context) {
3
- const { modules, userId } = context;
4
- log(`mutation unlinkOAuthAccount ${provider} ${oAuthAccountId}`, {
5
- userId,
6
- });
7
- return modules.users.updateUser({ _id: userId }, {
8
- $pull: {
9
- [`services.oauth.${provider}`]: { id: oAuthAccountId },
10
- },
11
- }, { upsert: true });
12
- }
13
- //# sourceMappingURL=unlinkOAuthAccount.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"unlinkOAuthAccount.js","sourceRoot":"","sources":["../../../../src/resolvers/mutations/accounts/unlinkOAuthAccount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAC;AAG5C,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,kBAAkB,CAC9C,IAAU,EACV,EAAE,QAAQ,EAAE,cAAc,EAAgD,EAC1E,OAAgB;IAEhB,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAEpC,GAAG,CAAC,+BAA+B,QAAQ,IAAI,cAAc,EAAE,EAAE;QAC/D,MAAM;KACP,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC,KAAK,CAAC,UAAU,CAC7B,EAAE,GAAG,EAAE,MAAM,EAAE,EACf;QACE,KAAK,EAAE;YACL,CAAC,kBAAkB,QAAQ,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,cAAc,EAAE;SACvD;KACF,EACD,EAAE,MAAM,EAAE,IAAI,EAAE,CACjB,CAAC;AACJ,CAAC"}
@@ -1,6 +0,0 @@
1
- import { Context, Root } from '@unchainedshop/types/api.js';
2
- export default function addAssortmentMedia(root: Root, { media, assortmentId }: {
3
- media: any;
4
- assortmentId: any;
5
- }, context: Context): Promise<import("@unchainedshop/types/assortments.media.js").AssortmentMedia>;
6
- //# sourceMappingURL=addAssortmentMedia.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"addAssortmentMedia.d.ts","sourceRoot":"","sources":["../../../../src/resolvers/mutations/assortments/addAssortmentMedia.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AAG5D,wBAA8B,kBAAkB,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,YAAY,EAAE;;;CAAA,EAAE,OAAO,EAAE,OAAO,gFAqBrG"}
@@ -1,18 +0,0 @@
1
- import { log } from '@unchainedshop/logger';
2
- import { AssortmentNotFoundError, InvalidIdError } from '../../../errors.js';
3
- export default async function addAssortmentMedia(root, { media, assortmentId }, context) {
4
- const { modules, services, userId } = context;
5
- log(`mutation addAssortmentMedia ${assortmentId}`, { userId });
6
- if (!assortmentId)
7
- throw new InvalidIdError({ assortmentId });
8
- if (!(await modules.assortments.assortmentExists({ assortmentId })))
9
- throw new AssortmentNotFoundError({ assortmentId });
10
- const file = await services.files.uploadFileFromStream({
11
- directoryName: 'assortment-media',
12
- rawFile: media,
13
- meta: {},
14
- }, context);
15
- const assortmentMedia = await modules.assortments.media.create({ assortmentId, mediaId: file._id });
16
- return assortmentMedia;
17
- }
18
- //# sourceMappingURL=addAssortmentMedia.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"addAssortmentMedia.js","sourceRoot":"","sources":["../../../../src/resolvers/mutations/assortments/addAssortmentMedia.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAC;AAE5C,OAAO,EAAE,uBAAuB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAE7E,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,kBAAkB,CAAC,IAAU,EAAE,EAAE,KAAK,EAAE,YAAY,EAAE,EAAE,OAAgB;IACpG,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAC9C,GAAG,CAAC,+BAA+B,YAAY,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IAE/D,IAAI,CAAC,YAAY;QAAE,MAAM,IAAI,cAAc,CAAC,EAAE,YAAY,EAAE,CAAC,CAAC;IAE9D,IAAI,CAAC,CAAC,MAAM,OAAO,CAAC,WAAW,CAAC,gBAAgB,CAAC,EAAE,YAAY,EAAE,CAAC,CAAC;QACjE,MAAM,IAAI,uBAAuB,CAAC,EAAE,YAAY,EAAE,CAAC,CAAC;IAEtD,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,KAAK,CAAC,oBAAoB,CACpD;QACE,aAAa,EAAE,kBAAkB;QACjC,OAAO,EAAE,KAAK;QACd,IAAI,EAAE,EAAE;KACT,EACD,OAAO,CACR,CAAC;IAEF,MAAM,eAAe,GAAG,MAAM,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,YAAY,EAAE,OAAO,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;IAEpG,OAAO,eAAe,CAAC;AACzB,CAAC"}
@@ -1,6 +0,0 @@
1
- import { Context, Root } from '@unchainedshop/types/api.js';
2
- export default function addProductMedia(root: Root, { media, productId }: {
3
- media: any;
4
- productId: any;
5
- }, context: Context): Promise<import("@unchainedshop/types/products.media.js").ProductMedia>;
6
- //# sourceMappingURL=addProductMedia.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"addProductMedia.d.ts","sourceRoot":"","sources":["../../../../src/resolvers/mutations/products/addProductMedia.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AAG5D,wBAA8B,eAAe,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE;;;CAAA,EAAE,OAAO,EAAE,OAAO,0EAmB/F"}
@@ -1,18 +0,0 @@
1
- import { log } from '@unchainedshop/logger';
2
- import { ProductNotFoundError, InvalidIdError } from '../../../errors.js';
3
- export default async function addProductMedia(root, { media, productId }, context) {
4
- const { modules, services, userId } = context;
5
- log(`mutation addProductMedia ${productId}`, { userId });
6
- if (!productId)
7
- throw new InvalidIdError({ productId });
8
- const product = await modules.products.findProduct({ productId });
9
- if (!product)
10
- throw new ProductNotFoundError({ productId });
11
- const file = await services.files.uploadFileFromStream({
12
- directoryName: 'product-media',
13
- rawFile: media,
14
- meta: { productId },
15
- }, context);
16
- return modules.products.media.create({ productId, mediaId: file._id });
17
- }
18
- //# sourceMappingURL=addProductMedia.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"addProductMedia.js","sourceRoot":"","sources":["../../../../src/resolvers/mutations/products/addProductMedia.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAC;AAE5C,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAE1E,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,eAAe,CAAC,IAAU,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE,OAAgB;IAC9F,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAC9C,GAAG,CAAC,4BAA4B,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IAEzD,IAAI,CAAC,SAAS;QAAE,MAAM,IAAI,cAAc,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC;IAExD,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC;IAClE,IAAI,CAAC,OAAO;QAAE,MAAM,IAAI,oBAAoB,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC;IAE5D,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,KAAK,CAAC,oBAAoB,CACpD;QACE,aAAa,EAAE,eAAe;QAC9B,OAAO,EAAE,KAAK;QACd,IAAI,EAAE,EAAE,SAAS,EAAE;KACpB,EACD,OAAO,CACR,CAAC;IAEF,OAAO,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;AACzE,CAAC"}
@@ -1,6 +0,0 @@
1
- import { Context, Root } from '@unchainedshop/types/api.js';
2
- export default function updateUserAvatar(root: Root, params: {
3
- avatar: any;
4
- userId: string;
5
- }, context: Context): Promise<import("@unchainedshop/types/user.js").User>;
6
- //# sourceMappingURL=updateUserAvatar.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"updateUserAvatar.d.ts","sourceRoot":"","sources":["../../../../src/resolvers/mutations/users/updateUserAvatar.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AAG5D,wBAA8B,gBAAgB,CAC5C,IAAI,EAAE,IAAI,EACV,MAAM,EAAE;IAAE,MAAM,EAAE,GAAG,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,EACvC,OAAO,EAAE,OAAO,wDA+BjB"}
@@ -1,22 +0,0 @@
1
- import { log } from '@unchainedshop/logger';
2
- import { UserNotFoundError } from '../../../errors.js';
3
- export default async function updateUserAvatar(root, params, context) {
4
- const { modules, services, userId } = context;
5
- const normalizedUserId = params.userId || userId;
6
- log(`mutation updateUserAvatar ${normalizedUserId}`, { userId });
7
- if (!(await modules.users.userExists({ userId: normalizedUserId })))
8
- throw new UserNotFoundError({ userId: normalizedUserId });
9
- const user = await modules.users.findUserById(normalizedUserId);
10
- const file = await services.files.uploadFileFromStream({
11
- directoryName: 'user-avatars',
12
- rawFile: params.avatar,
13
- meta: { userId: normalizedUserId },
14
- }, context);
15
- if (user?.avatarId) {
16
- await services.files.removeFiles({
17
- fileIds: [user.avatarId],
18
- }, context);
19
- }
20
- return modules.users.updateAvatar(normalizedUserId, file._id);
21
- }
22
- //# sourceMappingURL=updateUserAvatar.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"updateUserAvatar.js","sourceRoot":"","sources":["../../../../src/resolvers/mutations/users/updateUserAvatar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAC;AAE5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAEvD,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,gBAAgB,CAC5C,IAAU,EACV,MAAuC,EACvC,OAAgB;IAEhB,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAC9C,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC;IAEjD,GAAG,CAAC,6BAA6B,gBAAgB,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IAEjE,IAAI,CAAC,CAAC,MAAM,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,MAAM,EAAE,gBAAgB,EAAE,CAAC,CAAC;QACjE,MAAM,IAAI,iBAAiB,CAAC,EAAE,MAAM,EAAE,gBAAgB,EAAE,CAAC,CAAC;IAE5D,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,gBAAgB,CAAC,CAAC;IAEhE,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,KAAK,CAAC,oBAAoB,CACpD;QACE,aAAa,EAAE,cAAc;QAC7B,OAAO,EAAE,MAAM,CAAC,MAAM;QACtB,IAAI,EAAE,EAAE,MAAM,EAAE,gBAAgB,EAAE;KACnC,EACD,OAAO,CACR,CAAC;IAEF,IAAI,IAAI,EAAE,QAAQ,EAAE,CAAC;QACnB,MAAM,QAAQ,CAAC,KAAK,CAAC,WAAW,CAC9B;YACE,OAAO,EAAE,CAAC,IAAI,CAAC,QAAkB,CAAC;SACnC,EACD,OAAO,CACR,CAAC;IACJ,CAAC;IAED,OAAO,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,gBAAgB,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;AAChE,CAAC"}
@@ -1,7 +0,0 @@
1
- import { Context } from '@unchainedshop/types/api.js';
2
- import { User } from '@unchainedshop/types/user.js';
3
- export declare const getOrderCart: (params: {
4
- orderId?: string;
5
- user: User;
6
- }, context: Context) => Promise<import("@unchainedshop/types/orders.js").Order>;
7
- //# sourceMappingURL=getOrderCart.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getOrderCart.d.ts","sourceRoot":"","sources":["../../../../src/resolvers/mutations/utils/getOrderCart.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AACtD,OAAO,EAAE,IAAI,EAAE,MAAM,8BAA8B,CAAC;AAGpD,eAAO,MAAM,YAAY,WAAkB;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,IAAI,CAAA;CAAE,WAAW,OAAO,4DAc5F,CAAC"}
@@ -1,13 +0,0 @@
1
- import { OrderNotFoundError } from '../../../errors.js';
2
- export const getOrderCart = async (params, context) => {
3
- const { modules, services } = context;
4
- const { orderId, user } = params;
5
- if (orderId) {
6
- const order = await modules.orders.findOrder({ orderId });
7
- if (!order)
8
- throw new OrderNotFoundError({ orderId });
9
- return order;
10
- }
11
- return services.orders.nextUserCart({ user, countryCode: context.countryContext, forceCartCreation: true }, context);
12
- };
13
- //# sourceMappingURL=getOrderCart.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getOrderCart.js","sourceRoot":"","sources":["../../../../src/resolvers/mutations/utils/getOrderCart.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAExD,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,EAAE,MAAwC,EAAE,OAAgB,EAAE,EAAE;IAC/F,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IACtC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC;IAEjC,IAAI,OAAO,EAAE,CAAC;QACZ,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;QAC1D,IAAI,CAAC,KAAK;YAAE,MAAM,IAAI,kBAAkB,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;QACtD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,QAAQ,CAAC,MAAM,CAAC,YAAY,CACjC,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,CAAC,cAAc,EAAE,iBAAiB,EAAE,IAAI,EAAE,EACtE,OAAO,CACR,CAAC;AACJ,CAAC,CAAC"}
@@ -1,15 +0,0 @@
1
- import { DeliveryProvider } from '@unchainedshop/types/delivery.js';
2
- import { Product } from '@unchainedshop/types/products.js';
3
- import { WarehousingProvider } from '@unchainedshop/types/warehousing.js';
4
- export declare const Dispatch: {
5
- _id: (params: {
6
- product: Product;
7
- deliveryProvider: DeliveryProvider;
8
- warehousingProvider: WarehousingProvider;
9
- referenceDate: Date;
10
- quantity: number;
11
- country: string;
12
- userId?: string;
13
- }) => string;
14
- };
15
- //# sourceMappingURL=dispatch-types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dispatch-types.d.ts","sourceRoot":"","sources":["../../../src/resolvers/type/dispatch-types.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAE1E,eAAO,MAAM,QAAQ;kBACL;QACZ,OAAO,EAAE,OAAO,CAAC;QACjB,gBAAgB,EAAE,gBAAgB,CAAC;QACnC,mBAAmB,EAAE,mBAAmB,CAAC;QACzC,aAAa,EAAE,IAAI,CAAC;QACpB,QAAQ,EAAE,MAAM,CAAC;QACjB,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB;CAeF,CAAC"}
@@ -1,16 +0,0 @@
1
- import crypto from 'crypto';
2
- export const Dispatch = {
3
- _id: (params) => crypto
4
- .createHash('sha256')
5
- .update([
6
- params.product._id,
7
- params.deliveryProvider._id,
8
- params.warehousingProvider._id,
9
- params.referenceDate,
10
- params.quantity,
11
- params.country,
12
- params.userId || 'ANONYMOUS',
13
- ].join(''))
14
- .digest('hex'),
15
- };
16
- //# sourceMappingURL=dispatch-types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dispatch-types.js","sourceRoot":"","sources":["../../../src/resolvers/type/dispatch-types.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAK5B,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,GAAG,EAAE,CAAC,MAQL,EAAE,EAAE,CACH,MAAM;SACH,UAAU,CAAC,QAAQ,CAAC;SACpB,MAAM,CACL;QACE,MAAM,CAAC,OAAO,CAAC,GAAG;QAClB,MAAM,CAAC,gBAAgB,CAAC,GAAG;QAC3B,MAAM,CAAC,mBAAmB,CAAC,GAAG;QAC9B,MAAM,CAAC,aAAa;QACpB,MAAM,CAAC,QAAQ;QACf,MAAM,CAAC,OAAO;QACd,MAAM,CAAC,MAAM,IAAI,WAAW;KAC7B,CAAC,IAAI,CAAC,EAAE,CAAC,CACX;SACA,MAAM,CAAC,KAAK,CAAC;CACnB,CAAC"}
@@ -1,6 +0,0 @@
1
- import { Context } from '@unchainedshop/types/api.js';
2
- export declare const OAuthAccount: {
3
- _id: (account: any) => any;
4
- provider: (account: any, _: never, { modules }: Context) => Promise<import("@unchainedshop/types/accounts.js").IOAuth2Adapter>;
5
- };
6
- //# sourceMappingURL=oauth-account.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"oauth-account.d.ts","sourceRoot":"","sources":["../../../src/resolvers/type/oauth-account.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAEtD,eAAO,MAAM,YAAY;;gCAEM,KAAK,eAAe,OAAO;CAGzD,CAAC"}
@@ -1,7 +0,0 @@
1
- export const OAuthAccount = {
2
- _id: (account) => account.id,
3
- provider: async (account, _, { modules }) => {
4
- return modules.accounts.oAuth2.getProvider(account.provider);
5
- },
6
- };
7
- //# sourceMappingURL=oauth-account.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"oauth-account.js","sourceRoot":"","sources":["../../../src/resolvers/type/oauth-account.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,GAAG,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE;IAC5B,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,CAAQ,EAAE,EAAE,OAAO,EAAW,EAAE,EAAE;QAC1D,OAAO,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC/D,CAAC;CACF,CAAC"}
@@ -1,6 +0,0 @@
1
- export declare const OAuthProvider: {
2
- _id: (adapter: any) => any;
3
- clientId: (adapter: any) => any;
4
- scopes: (adapter: any) => any;
5
- };
6
- //# sourceMappingURL=oauth-provider.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"oauth-provider.d.ts","sourceRoot":"","sources":["../../../src/resolvers/type/oauth-provider.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa;;;;CAIzB,CAAC"}
@@ -1,6 +0,0 @@
1
- export const OAuthProvider = {
2
- _id: (adapter) => adapter.provider,
3
- clientId: (adapter) => adapter.config?.clientId,
4
- scopes: (adapter) => adapter.config?.scopes || [],
5
- };
6
- //# sourceMappingURL=oauth-provider.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"oauth-provider.js","sourceRoot":"","sources":["../../../src/resolvers/type/oauth-provider.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,GAAG,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ;IAClC,QAAQ,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ;IAC/C,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,IAAI,EAAE;CAClD,CAAC"}