@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.
- package/lib/loaders/index.d.ts.map +1 -1
- package/lib/loaders/index.js +56 -44
- package/lib/loaders/index.js.map +1 -1
- package/package.json +5 -6
- package/src/loaders/index.ts +63 -54
- package/tests/api-index.test.ts +18 -11
- package/jest.config.js +0 -17
- package/lib/express/createApolloMiddleware.d.ts +0 -4
- package/lib/express/createApolloMiddleware.d.ts.map +0 -1
- package/lib/express/createApolloMiddleware.js +0 -36
- package/lib/express/createApolloMiddleware.js.map +0 -1
- package/lib/express/createSingleSignOnMiddleware.d.ts +0 -5
- package/lib/express/createSingleSignOnMiddleware.d.ts.map +0 -1
- package/lib/express/createSingleSignOnMiddleware.js +0 -71
- package/lib/express/createSingleSignOnMiddleware.js.map +0 -1
- package/lib/hashPassword.d.ts +0 -2
- package/lib/hashPassword.d.ts.map +0 -1
- package/lib/hashPassword.js +0 -5
- package/lib/hashPassword.js.map +0 -1
- package/lib/resolvers/mutations/accounts/buildSecretTOTPAuthURL.d.ts +0 -3
- package/lib/resolvers/mutations/accounts/buildSecretTOTPAuthURL.d.ts.map +0 -1
- package/lib/resolvers/mutations/accounts/buildSecretTOTPAuthURL.js +0 -6
- package/lib/resolvers/mutations/accounts/buildSecretTOTPAuthURL.js.map +0 -1
- package/lib/resolvers/mutations/accounts/disableTOTP.d.ts +0 -6
- package/lib/resolvers/mutations/accounts/disableTOTP.d.ts.map +0 -1
- package/lib/resolvers/mutations/accounts/disableTOTP.js +0 -27
- package/lib/resolvers/mutations/accounts/disableTOTP.js.map +0 -1
- package/lib/resolvers/mutations/accounts/enableTOTP.d.ts +0 -6
- package/lib/resolvers/mutations/accounts/enableTOTP.d.ts.map +0 -1
- package/lib/resolvers/mutations/accounts/enableTOTP.js +0 -20
- package/lib/resolvers/mutations/accounts/enableTOTP.js.map +0 -1
- package/lib/resolvers/mutations/accounts/linkOAuthAccount.d.ts +0 -7
- package/lib/resolvers/mutations/accounts/linkOAuthAccount.d.ts.map +0 -1
- package/lib/resolvers/mutations/accounts/linkOAuthAccount.js +0 -30
- package/lib/resolvers/mutations/accounts/linkOAuthAccount.js.map +0 -1
- package/lib/resolvers/mutations/accounts/loginWithOAuth.d.ts +0 -8
- package/lib/resolvers/mutations/accounts/loginWithOAuth.d.ts.map +0 -1
- package/lib/resolvers/mutations/accounts/loginWithOAuth.js +0 -25
- package/lib/resolvers/mutations/accounts/loginWithOAuth.js.map +0 -1
- package/lib/resolvers/mutations/accounts/logoutAllSessions.d.ts +0 -5
- package/lib/resolvers/mutations/accounts/logoutAllSessions.d.ts.map +0 -1
- package/lib/resolvers/mutations/accounts/logoutAllSessions.js +0 -20
- package/lib/resolvers/mutations/accounts/logoutAllSessions.js.map +0 -1
- package/lib/resolvers/mutations/accounts/unlinkOAuthAccount.d.ts +0 -6
- package/lib/resolvers/mutations/accounts/unlinkOAuthAccount.d.ts.map +0 -1
- package/lib/resolvers/mutations/accounts/unlinkOAuthAccount.js +0 -13
- package/lib/resolvers/mutations/accounts/unlinkOAuthAccount.js.map +0 -1
- package/lib/resolvers/mutations/assortments/addAssortmentMedia.d.ts +0 -6
- package/lib/resolvers/mutations/assortments/addAssortmentMedia.d.ts.map +0 -1
- package/lib/resolvers/mutations/assortments/addAssortmentMedia.js +0 -18
- package/lib/resolvers/mutations/assortments/addAssortmentMedia.js.map +0 -1
- package/lib/resolvers/mutations/products/addProductMedia.d.ts +0 -6
- package/lib/resolvers/mutations/products/addProductMedia.d.ts.map +0 -1
- package/lib/resolvers/mutations/products/addProductMedia.js +0 -18
- package/lib/resolvers/mutations/products/addProductMedia.js.map +0 -1
- package/lib/resolvers/mutations/users/updateUserAvatar.d.ts +0 -6
- package/lib/resolvers/mutations/users/updateUserAvatar.d.ts.map +0 -1
- package/lib/resolvers/mutations/users/updateUserAvatar.js +0 -22
- package/lib/resolvers/mutations/users/updateUserAvatar.js.map +0 -1
- package/lib/resolvers/mutations/utils/getOrderCart.d.ts +0 -7
- package/lib/resolvers/mutations/utils/getOrderCart.d.ts.map +0 -1
- package/lib/resolvers/mutations/utils/getOrderCart.js +0 -13
- package/lib/resolvers/mutations/utils/getOrderCart.js.map +0 -1
- package/lib/resolvers/type/dispatch-types.d.ts +0 -15
- package/lib/resolvers/type/dispatch-types.d.ts.map +0 -1
- package/lib/resolvers/type/dispatch-types.js +0 -16
- package/lib/resolvers/type/dispatch-types.js.map +0 -1
- package/lib/resolvers/type/oauth-account.d.ts +0 -6
- package/lib/resolvers/type/oauth-account.d.ts.map +0 -1
- package/lib/resolvers/type/oauth-account.js +0 -7
- package/lib/resolvers/type/oauth-account.js.map +0 -1
- package/lib/resolvers/type/oauth-provider.d.ts +0 -6
- package/lib/resolvers/type/oauth-provider.d.ts.map +0 -1
- package/lib/resolvers/type/oauth-provider.js +0 -6
- package/lib/resolvers/type/oauth-provider.js.map +0 -1
- package/lib/resolvers/type/stock-types.d.ts +0 -14
- package/lib/resolvers/type/stock-types.d.ts.map +0 -1
- package/lib/resolvers/type/stock-types.js +0 -15
- package/lib/resolvers/type/stock-types.js.map +0 -1
- package/lib/user-context.d.ts +0 -7
- package/lib/user-context.d.ts.map +0 -1
- package/lib/user-context.js +0 -76
- package/lib/user-context.js.map +0 -1
|
@@ -1,14 +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 Stock: {
|
|
5
|
-
_id: (params: {
|
|
6
|
-
product: Product;
|
|
7
|
-
deliveryProvider: DeliveryProvider;
|
|
8
|
-
warehousingProvider: WarehousingProvider;
|
|
9
|
-
referenceDate: Date;
|
|
10
|
-
country: string;
|
|
11
|
-
userId?: string;
|
|
12
|
-
}) => string;
|
|
13
|
-
};
|
|
14
|
-
//# sourceMappingURL=stock-types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stock-types.d.ts","sourceRoot":"","sources":["../../../src/resolvers/type/stock-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,KAAK;kBACF;QACZ,OAAO,EAAE,OAAO,CAAC;QACjB,gBAAgB,EAAE,gBAAgB,CAAC;QACnC,mBAAmB,EAAE,mBAAmB,CAAC;QACzC,aAAa,EAAE,IAAI,CAAC;QACpB,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB;CAcF,CAAC"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import crypto from 'crypto';
|
|
2
|
-
export const Stock = {
|
|
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.country,
|
|
11
|
-
params.userId || 'ANONYMOUS',
|
|
12
|
-
].join(''))
|
|
13
|
-
.digest('hex'),
|
|
14
|
-
};
|
|
15
|
-
//# sourceMappingURL=stock-types.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stock-types.js","sourceRoot":"","sources":["../../../src/resolvers/type/stock-types.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAK5B,MAAM,CAAC,MAAM,KAAK,GAAG;IACnB,GAAG,EAAE,CAAC,MAOL,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,OAAO;QACd,MAAM,CAAC,MAAM,IAAI,WAAW;KAC7B,CAAC,IAAI,CAAC,EAAE,CAAC,CACX;SACA,MAAM,CAAC,KAAK,CAAC;CACnB,CAAC"}
|
package/lib/user-context.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { IncomingMessage, OutgoingMessage } from 'http';
|
|
2
|
-
import { UnchainedUserContext } from '@unchainedshop/types/api.js';
|
|
3
|
-
import { UnchainedCore } from '@unchainedshop/types/core.js';
|
|
4
|
-
export declare const getUserContext: (req: IncomingMessage & {
|
|
5
|
-
cookies?: any;
|
|
6
|
-
}, res: OutgoingMessage, unchainedAPI: UnchainedCore) => Promise<UnchainedUserContext>;
|
|
7
|
-
//# sourceMappingURL=user-context.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"user-context.d.ts","sourceRoot":"","sources":["../src/user-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AA0C7D,eAAO,MAAM,cAAc,QACpB,eAAe,GAAG;IAAE,OAAO,CAAC,EAAE,GAAG,CAAA;CAAE,OACnC,eAAe,gBACN,aAAa,KAC1B,OAAO,CAAC,oBAAoB,CAsD9B,CAAC"}
|
package/lib/user-context.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import cookie from 'cookie';
|
|
2
|
-
function isString(input) {
|
|
3
|
-
return typeof input === 'string' && Object.prototype.toString.call(input) === '[object String]';
|
|
4
|
-
}
|
|
5
|
-
const { UNCHAINED_COOKIE_NAME = 'unchained_token', UNCHAINED_COOKIE_PATH = '/', UNCHAINED_COOKIE_DOMAIN, UNCHAINED_COOKIE_SAMESITE, UNCHAINED_COOKIE_INSECURE, } = process.env;
|
|
6
|
-
function setLoginToken(res, token, expires) {
|
|
7
|
-
const cookieName = UNCHAINED_COOKIE_NAME;
|
|
8
|
-
const domain = UNCHAINED_COOKIE_DOMAIN;
|
|
9
|
-
const path = UNCHAINED_COOKIE_PATH;
|
|
10
|
-
const secure = UNCHAINED_COOKIE_INSECURE ? false : true;
|
|
11
|
-
const sameSite = ({
|
|
12
|
-
none: 'none',
|
|
13
|
-
lax: 'lax',
|
|
14
|
-
strict: 'strict',
|
|
15
|
-
'1': true,
|
|
16
|
-
'0': false,
|
|
17
|
-
}[UNCHAINED_COOKIE_SAMESITE?.trim()?.toLowerCase()] || false);
|
|
18
|
-
if (!cookieName)
|
|
19
|
-
return;
|
|
20
|
-
const authCookie = cookie.serialize(cookieName, token || null, {
|
|
21
|
-
domain,
|
|
22
|
-
httpOnly: true,
|
|
23
|
-
path,
|
|
24
|
-
expires: token && expires ? expires : undefined,
|
|
25
|
-
maxAge: token ? undefined : -1,
|
|
26
|
-
sameSite,
|
|
27
|
-
secure,
|
|
28
|
-
});
|
|
29
|
-
res.setHeader('Set-Cookie', authCookie);
|
|
30
|
-
}
|
|
31
|
-
export const getUserContext = async (req, res, unchainedAPI) => {
|
|
32
|
-
// there is a possible current user connected!
|
|
33
|
-
const cookieName = UNCHAINED_COOKIE_NAME;
|
|
34
|
-
let loginToken = req.cookies?.[cookieName];
|
|
35
|
-
if (req.headers.authorization) {
|
|
36
|
-
const [type, token] = req.headers.authorization.split(' ');
|
|
37
|
-
if (type === 'Bearer') {
|
|
38
|
-
loginToken = token;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
if (loginToken) {
|
|
42
|
-
// throw an error if the token is not a string
|
|
43
|
-
if (!isString(loginToken))
|
|
44
|
-
throw new Error('Access Token is not a string');
|
|
45
|
-
// the hashed token is the key to find the possible current user in the db
|
|
46
|
-
const hashedToken = unchainedAPI.modules.accounts.createHashLoginToken(loginToken);
|
|
47
|
-
const currentUser = await unchainedAPI.modules.users.findUserByToken({
|
|
48
|
-
hashedToken,
|
|
49
|
-
});
|
|
50
|
-
// the current user exists
|
|
51
|
-
if (currentUser) {
|
|
52
|
-
// find the right login token corresponding, the current user may have
|
|
53
|
-
// several sessions logged on different browsers / computers
|
|
54
|
-
const tokenInformation = currentUser.services.resume.loginTokens.find((tokenInfo) => tokenInfo.hashedToken === hashedToken); // eslint-disable-line
|
|
55
|
-
// true if the token is expired
|
|
56
|
-
const isExpired = new Date(tokenInformation.when) < new Date();
|
|
57
|
-
// if the token is still valid, give access to the current user
|
|
58
|
-
// information in the resolvers context
|
|
59
|
-
if (!isExpired) {
|
|
60
|
-
// return a new context object with the current user & her id
|
|
61
|
-
return {
|
|
62
|
-
user: currentUser,
|
|
63
|
-
userId: currentUser._id,
|
|
64
|
-
loginToken: loginToken,
|
|
65
|
-
setLoginToken,
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
// If there is no user with this token or the token is expires/invalid,
|
|
70
|
-
// we should remove that cookie from the client
|
|
71
|
-
setLoginToken(res, null);
|
|
72
|
-
return { loginToken: loginToken, setLoginToken };
|
|
73
|
-
}
|
|
74
|
-
return { setLoginToken };
|
|
75
|
-
};
|
|
76
|
-
//# sourceMappingURL=user-context.js.map
|
package/lib/user-context.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"user-context.js","sourceRoot":"","sources":["../src/user-context.ts"],"names":[],"mappings":"AAGA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,SAAS,QAAQ,CAAC,KAAK;IACrB,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,iBAAiB,CAAC;AAClG,CAAC;AAED,MAAM,EACJ,qBAAqB,GAAG,iB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