@airsoko/auth 0.0.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.
Files changed (91) hide show
  1. package/dist/__generated__/globalTypes.d.ts +590 -0
  2. package/dist/__generated__/globalTypes.d.ts.map +1 -0
  3. package/dist/__generated__/globalTypes.js +607 -0
  4. package/dist/src/constants/endpoints.d.ts +5 -0
  5. package/dist/src/constants/endpoints.d.ts.map +1 -0
  6. package/dist/src/constants/endpoints.js +7 -0
  7. package/dist/src/constants/index.d.ts +6 -0
  8. package/dist/src/constants/index.d.ts.map +1 -0
  9. package/dist/src/constants/index.js +8 -0
  10. package/dist/src/core/AuthContext.d.ts +5 -0
  11. package/dist/src/core/AuthContext.d.ts.map +1 -0
  12. package/dist/src/core/AuthContext.js +10 -0
  13. package/dist/src/core/client.d.ts +108 -0
  14. package/dist/src/core/client.d.ts.map +1 -0
  15. package/dist/src/core/client.js +256 -0
  16. package/dist/src/core/old/SampleAuthProvider.d.ts +37 -0
  17. package/dist/src/core/old/SampleAuthProvider.d.ts.map +1 -0
  18. package/dist/src/core/old/SampleAuthProvider.js +123 -0
  19. package/dist/src/core/user/context.d.ts +56 -0
  20. package/dist/src/core/user/context.d.ts.map +1 -0
  21. package/dist/src/core/user/context.js +46 -0
  22. package/dist/src/core/user/hooks.d.ts +2 -0
  23. package/dist/src/core/user/hooks.d.ts.map +1 -0
  24. package/dist/src/core/user/hooks.js +5 -0
  25. package/dist/src/core/user/index.d.ts +4 -0
  26. package/dist/src/core/user/index.d.ts.map +1 -0
  27. package/dist/src/core/user/index.js +9 -0
  28. package/dist/src/core/user/provider.d.ts +19 -0
  29. package/dist/src/core/user/provider.d.ts.map +1 -0
  30. package/dist/src/core/user/provider.js +71 -0
  31. package/dist/src/data/checkDeviceSatus.d.ts +5 -0
  32. package/dist/src/data/checkDeviceSatus.d.ts.map +1 -0
  33. package/dist/src/data/checkDeviceSatus.js +58 -0
  34. package/dist/src/data/getMerchantUser.d.ts +3 -0
  35. package/dist/src/data/getMerchantUser.d.ts.map +1 -0
  36. package/dist/src/data/getMerchantUser.js +20 -0
  37. package/dist/src/data/getRegularUser.d.ts +3 -0
  38. package/dist/src/data/getRegularUser.d.ts.map +1 -0
  39. package/dist/src/data/getRegularUser.js +20 -0
  40. package/dist/src/graphql/__generated__/Logout.d.ts +4 -0
  41. package/dist/src/graphql/__generated__/Logout.d.ts.map +1 -0
  42. package/dist/src/graphql/__generated__/Logout.js +6 -0
  43. package/dist/src/graphql/__generated__/onboarding.d.ts +29 -0
  44. package/dist/src/graphql/__generated__/onboarding.d.ts.map +1 -0
  45. package/dist/src/graphql/__generated__/onboarding.js +6 -0
  46. package/dist/src/graphql/__generated__/onboardingShop.d.ts +66 -0
  47. package/dist/src/graphql/__generated__/onboardingShop.d.ts.map +1 -0
  48. package/dist/src/graphql/__generated__/onboardingShop.js +6 -0
  49. package/dist/src/graphql/queries.d.ts +10 -0
  50. package/dist/src/graphql/queries.d.ts.map +1 -0
  51. package/dist/src/graphql/queries.js +68 -0
  52. package/dist/src/graphql/typings.d.ts +66 -0
  53. package/dist/src/graphql/typings.d.ts.map +1 -0
  54. package/dist/src/graphql/typings.js +2 -0
  55. package/dist/src/index.d.ts +5 -0
  56. package/dist/src/index.d.ts.map +1 -0
  57. package/dist/src/index.js +25 -0
  58. package/dist/src/utils/currentPageHasParam.d.ts +13 -0
  59. package/dist/src/utils/currentPageHasParam.d.ts.map +1 -0
  60. package/dist/src/utils/currentPageHasParam.js +23 -0
  61. package/dist/src/utils/getCookie.d.ts +7 -0
  62. package/dist/src/utils/getCookie.d.ts.map +1 -0
  63. package/dist/src/utils/getCookie.js +19 -0
  64. package/dist/src/utils/getMainDomain.d.ts +45 -0
  65. package/dist/src/utils/getMainDomain.d.ts.map +1 -0
  66. package/dist/src/utils/getMainDomain.js +73 -0
  67. package/dist/src/utils/getProtocol.d.ts +8 -0
  68. package/dist/src/utils/getProtocol.d.ts.map +1 -0
  69. package/dist/src/utils/getProtocol.js +13 -0
  70. package/dist/src/utils/getURL.d.ts +26 -0
  71. package/dist/src/utils/getURL.d.ts.map +1 -0
  72. package/dist/src/utils/getURL.js +56 -0
  73. package/dist/src/utils/index.d.ts +8 -0
  74. package/dist/src/utils/index.d.ts.map +1 -0
  75. package/dist/src/utils/index.js +17 -0
  76. package/dist/src/utils/jwt/decode.d.ts +3 -0
  77. package/dist/src/utils/jwt/decode.d.ts.map +1 -0
  78. package/dist/src/utils/jwt/decode.js +32 -0
  79. package/dist/src/utils/jwt/encode.d.ts +3 -0
  80. package/dist/src/utils/jwt/encode.d.ts.map +1 -0
  81. package/dist/src/utils/jwt/encode.js +25 -0
  82. package/dist/src/utils/jwt/index.d.ts +3 -0
  83. package/dist/src/utils/jwt/index.d.ts.map +1 -0
  84. package/dist/src/utils/jwt/index.js +7 -0
  85. package/dist/src/utils/redirectToPathWithParams.d.ts +9 -0
  86. package/dist/src/utils/redirectToPathWithParams.d.ts.map +1 -0
  87. package/dist/src/utils/redirectToPathWithParams.js +22 -0
  88. package/dist/src/utils/setSharedCookie.d.ts +8 -0
  89. package/dist/src/utils/setSharedCookie.d.ts.map +1 -0
  90. package/dist/src/utils/setSharedCookie.js +21 -0
  91. package/package.json +35 -0
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCookie = void 0;
4
+ /**
5
+ * Utility function to get the value of a cookie by name
6
+ * @param name The name of the cookie
7
+ * @returns The value of the cookie, or undefined if the cookie does not exist
8
+ */
9
+ function getCookie(name) {
10
+ const cookies = document.cookie.split(';');
11
+ for (const cookie of cookies) {
12
+ const [cookieName, cookieValue] = cookie.trim().split('=');
13
+ if (cookieName === name) {
14
+ return decodeURIComponent(cookieValue);
15
+ }
16
+ }
17
+ return undefined;
18
+ }
19
+ exports.getCookie = getCookie;
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Returns the main domain name of a given URL or domain name.
3
+ * If the input is a valid URL, the function extracts the hostname from the URL and returns its main domain.
4
+ * If the input is not a valid URL, the function assumes it is a domain name and returns its main domain.
5
+ * If the input hostname starts with `localhost`, `127.`, or `0.0.0.0`, the function returns the string `localhost`.
6
+ * @param urlOrDomain The input URL or domain name.
7
+ * @returns The main domain name.
8
+ * @example
9
+ * // Example 1: Extract main domain from a valid URL
10
+ * const url = 'https://www.example.co.uk';
11
+ * const mainDomain = getMainDomain(url);
12
+ * // mainDomain === 'example.co.uk'
13
+ *
14
+ * @example
15
+ * // Example 2: Extract main domain from an invalid URL by assuming it's a domain name
16
+ * const url = 'example.com';
17
+ * const mainDomain = getMainDomain(url);
18
+ * // mainDomain === 'example.com'
19
+ *
20
+ * @example
21
+ * // Example 3: Extract main domain from a domain name
22
+ * const domain = 'www.example.co.uk';
23
+ * const mainDomain = getMainDomain(domain);
24
+ * // mainDomain === 'example.co.uk'
25
+ *
26
+ * @example
27
+ * // Example 4: Return 'localhost' for input hostname starting with 'localhost'
28
+ * const hostname = 'localhost:3000';
29
+ * const mainDomain = getMainDomain(hostname);
30
+ * // mainDomain === 'localhost'
31
+ *
32
+ * @example
33
+ * // Example 5: Return 'localhost' for input hostname starting with '127.'
34
+ * const hostname = '127.0.0.1';
35
+ * const mainDomain = getMainDomain(hostname);
36
+ * // mainDomain === 'localhost'
37
+ *
38
+ * @example
39
+ * // Example 6: Return 'localhost' for input hostname starting with '0.0.0.0'
40
+ * const hostname = '0.0.0.0';
41
+ * const mainDomain = getMainDomain(hostname);
42
+ * // mainDomain === 'localhost'
43
+ */
44
+ export declare function getMainDomain(url: string): string;
45
+ //# sourceMappingURL=getMainDomain.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getMainDomain.d.ts","sourceRoot":"","sources":["../../../src/utils/getMainDomain.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AAEH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CA8BjD"}
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ /**
3
+ * Returns the main domain name of a given URL or domain name.
4
+ * If the input is a valid URL, the function extracts the hostname from the URL and returns its main domain.
5
+ * If the input is not a valid URL, the function assumes it is a domain name and returns its main domain.
6
+ * If the input hostname starts with `localhost`, `127.`, or `0.0.0.0`, the function returns the string `localhost`.
7
+ * @param urlOrDomain The input URL or domain name.
8
+ * @returns The main domain name.
9
+ * @example
10
+ * // Example 1: Extract main domain from a valid URL
11
+ * const url = 'https://www.example.co.uk';
12
+ * const mainDomain = getMainDomain(url);
13
+ * // mainDomain === 'example.co.uk'
14
+ *
15
+ * @example
16
+ * // Example 2: Extract main domain from an invalid URL by assuming it's a domain name
17
+ * const url = 'example.com';
18
+ * const mainDomain = getMainDomain(url);
19
+ * // mainDomain === 'example.com'
20
+ *
21
+ * @example
22
+ * // Example 3: Extract main domain from a domain name
23
+ * const domain = 'www.example.co.uk';
24
+ * const mainDomain = getMainDomain(domain);
25
+ * // mainDomain === 'example.co.uk'
26
+ *
27
+ * @example
28
+ * // Example 4: Return 'localhost' for input hostname starting with 'localhost'
29
+ * const hostname = 'localhost:3000';
30
+ * const mainDomain = getMainDomain(hostname);
31
+ * // mainDomain === 'localhost'
32
+ *
33
+ * @example
34
+ * // Example 5: Return 'localhost' for input hostname starting with '127.'
35
+ * const hostname = '127.0.0.1';
36
+ * const mainDomain = getMainDomain(hostname);
37
+ * // mainDomain === 'localhost'
38
+ *
39
+ * @example
40
+ * // Example 6: Return 'localhost' for input hostname starting with '0.0.0.0'
41
+ * const hostname = '0.0.0.0';
42
+ * const mainDomain = getMainDomain(hostname);
43
+ * // mainDomain === 'localhost'
44
+ */
45
+ Object.defineProperty(exports, "__esModule", { value: true });
46
+ exports.getMainDomain = void 0;
47
+ function getMainDomain(url) {
48
+ let hostname;
49
+ try {
50
+ // Attempt to extract the hostname from the input URL.
51
+ hostname = new URL(url).hostname;
52
+ }
53
+ catch (e) {
54
+ // If the URL is invalid, assume it is a domain name and prepend with `http://`.
55
+ hostname = new URL(`http://${url}`).hostname;
56
+ }
57
+ // Test if the hostname starts with `localhost`, `127.`, or `0.0.0.0`.
58
+ if (/^(localhost|127\.|0\.0\.0\.0)/.test(hostname)) {
59
+ // Return `localhost` as the main domain if any of the above strings are present.
60
+ return 'localhost';
61
+ }
62
+ // Split the hostname into parts and reverse the order.
63
+ const parts = hostname.split('.').reverse();
64
+ // Extract the main domain name from the reversed parts.
65
+ const domain = `${parts[1]}.${parts[0]}`;
66
+ // If the last part is a two-letter TLD (`co`), include the third-to-last part in the domain name.
67
+ if (parts[0].length === 2 && parts[1] === 'co') {
68
+ return `${parts[2]}.${domain}`;
69
+ }
70
+ // Otherwise, return the main domain name.
71
+ return domain;
72
+ }
73
+ exports.getMainDomain = getMainDomain;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Returns the protocol (http or https) based on the domain name
3
+ *
4
+ * @param domain The domain name to check
5
+ * @returns The protocol (http or https)
6
+ */
7
+ export declare function getProtocol(domain: string): 'http' | 'https';
8
+ //# sourceMappingURL=getProtocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getProtocol.d.ts","sourceRoot":"","sources":["../../../src/utils/getProtocol.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAE5D"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getProtocol = void 0;
4
+ /**
5
+ * Returns the protocol (http or https) based on the domain name
6
+ *
7
+ * @param domain The domain name to check
8
+ * @returns The protocol (http or https)
9
+ */
10
+ function getProtocol(domain) {
11
+ return domain.includes('127.0.0.1') || domain.includes('localhost') ? 'http' : 'https';
12
+ }
13
+ exports.getProtocol = getProtocol;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Constructs a URL from a domain and endpoint, with optional query parameters.
3
+ *
4
+ * @param domain - The domain of the URL.
5
+ * @param endpoint - The endpoint of the URL.
6
+ * @param queryParams - Optional key-value pairs of query parameters.
7
+ * @returns The constructed URL.
8
+ * @throws An error if the URL is invalid.
9
+ *
10
+ * @example
11
+ * // Basic usage with domain and endpoint
12
+ * const url1 = getURL('example.com', '/api/data');
13
+ * // Returns: 'https://example.com/api/data'
14
+ *
15
+ * @example
16
+ * // Using localhost domain and query parameters
17
+ * const url2 = getURL('localhost:3000', '/api/data', { page: 1, size: 10 });
18
+ * // Returns: 'http://localhost:3000/api/data?page=1&size=10'
19
+ *
20
+ * @example
21
+ * // Using an IP address domain and endpoint with special characters
22
+ * const url3 = getURL('http://127.0.0.1', '/api/data?query=test#hash');
23
+ * // Returns: 'http://127.0.0.1/api/data?query=test#hash'
24
+ */
25
+ export declare function getURL(domain: string, endpoint: string, queryParams?: Record<string, any>): string;
26
+ //# sourceMappingURL=getURL.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getURL.d.ts","sourceRoot":"","sources":["../../../src/utils/getURL.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,MAAM,CACpB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAChC,MAAM,CAmCR"}
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getURL = void 0;
4
+ /**
5
+ * Constructs a URL from a domain and endpoint, with optional query parameters.
6
+ *
7
+ * @param domain - The domain of the URL.
8
+ * @param endpoint - The endpoint of the URL.
9
+ * @param queryParams - Optional key-value pairs of query parameters.
10
+ * @returns The constructed URL.
11
+ * @throws An error if the URL is invalid.
12
+ *
13
+ * @example
14
+ * // Basic usage with domain and endpoint
15
+ * const url1 = getURL('example.com', '/api/data');
16
+ * // Returns: 'https://example.com/api/data'
17
+ *
18
+ * @example
19
+ * // Using localhost domain and query parameters
20
+ * const url2 = getURL('localhost:3000', '/api/data', { page: 1, size: 10 });
21
+ * // Returns: 'http://localhost:3000/api/data?page=1&size=10'
22
+ *
23
+ * @example
24
+ * // Using an IP address domain and endpoint with special characters
25
+ * const url3 = getURL('http://127.0.0.1', '/api/data?query=test#hash');
26
+ * // Returns: 'http://127.0.0.1/api/data?query=test#hash'
27
+ */
28
+ function getURL(domain, endpoint, queryParams) {
29
+ let protocol = 'https';
30
+ let url = domain.trim() + endpoint.trim();
31
+ if (domain.match(/^(https?|ftp):\/\//)) {
32
+ // If domain includes a protocol, use that instead of https
33
+ protocol = domain.split('://')[0];
34
+ url = domain.substring(domain.indexOf('://') + 3).trim() + endpoint.trim();
35
+ }
36
+ else if (domain.includes('localhost') || domain.includes('127.0.0.1')) {
37
+ // If domain is localhost or 127.0.0.1, use http instead of https
38
+ protocol = 'http';
39
+ }
40
+ if (queryParams) {
41
+ // If query parameters are provided, append them to the URL
42
+ //@ts-ignore
43
+ const query = encode(queryParams);
44
+ url += `?${query}`;
45
+ }
46
+ // URL encoding
47
+ url = encodeURI(url);
48
+ url = `${protocol}://${url}`;
49
+ // URL validation
50
+ const isValidUrl = /^(https?|ftp):\/\/((\w+[\.\-\+]*){2,}[a-zA-Z]{2,}|(\d{1,3}\.){3}\d{1,3})(:\d+)?(\/.*)?$/i.test(url);
51
+ if (!isValidUrl) {
52
+ throw new Error('Invalid URL');
53
+ }
54
+ return url;
55
+ }
56
+ exports.getURL = getURL;
@@ -0,0 +1,8 @@
1
+ export { currentPageHasParam } from './currentPageHasParam';
2
+ export { getCookie } from './getCookie';
3
+ export { getMainDomain } from './getMainDomain';
4
+ export { getProtocol } from './getProtocol';
5
+ export { getURL } from './getURL';
6
+ export { redirectToPathWithParams } from './redirectToPathWithParams';
7
+ export { setSharedCookie } from './setSharedCookie';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAA;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setSharedCookie = exports.redirectToPathWithParams = exports.getURL = exports.getProtocol = exports.getMainDomain = exports.getCookie = exports.currentPageHasParam = void 0;
4
+ var currentPageHasParam_1 = require("./currentPageHasParam");
5
+ Object.defineProperty(exports, "currentPageHasParam", { enumerable: true, get: function () { return currentPageHasParam_1.currentPageHasParam; } });
6
+ var getCookie_1 = require("./getCookie");
7
+ Object.defineProperty(exports, "getCookie", { enumerable: true, get: function () { return getCookie_1.getCookie; } });
8
+ var getMainDomain_1 = require("./getMainDomain");
9
+ Object.defineProperty(exports, "getMainDomain", { enumerable: true, get: function () { return getMainDomain_1.getMainDomain; } });
10
+ var getProtocol_1 = require("./getProtocol");
11
+ Object.defineProperty(exports, "getProtocol", { enumerable: true, get: function () { return getProtocol_1.getProtocol; } });
12
+ var getURL_1 = require("./getURL");
13
+ Object.defineProperty(exports, "getURL", { enumerable: true, get: function () { return getURL_1.getURL; } });
14
+ var redirectToPathWithParams_1 = require("./redirectToPathWithParams");
15
+ Object.defineProperty(exports, "redirectToPathWithParams", { enumerable: true, get: function () { return redirectToPathWithParams_1.redirectToPathWithParams; } });
16
+ var setSharedCookie_1 = require("./setSharedCookie");
17
+ Object.defineProperty(exports, "setSharedCookie", { enumerable: true, get: function () { return setSharedCookie_1.setSharedCookie; } });
@@ -0,0 +1,3 @@
1
+ export declare function base64urlDecodeV1(data: string): string;
2
+ export declare function decodeJWtV1(token: string): object | null;
3
+ //# sourceMappingURL=decode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["../../../../src/utils/jwt/decode.ts"],"names":[],"mappings":"AACA,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAUtD;AAGD,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAexD"}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.decodeJWtV1 = exports.base64urlDecodeV1 = void 0;
4
+ // Function to base64 URL decode data
5
+ function base64urlDecodeV1(data) {
6
+ const base64 = data.replace(/-/g, "+").replace(/_/g, "/");
7
+ const decoded = atob(base64);
8
+ return decodeURIComponent(Array.prototype.map
9
+ .call(decoded, (c) => {
10
+ return "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2);
11
+ })
12
+ .join(""));
13
+ }
14
+ exports.base64urlDecodeV1 = base64urlDecodeV1;
15
+ // Function to decode a JWT token
16
+ function decodeJWtV1(token) {
17
+ const [encodedHeader, encodedPayload] = token.split(".");
18
+ if (!encodedHeader || !encodedPayload) {
19
+ console.error("Invalid JWT format");
20
+ return null;
21
+ }
22
+ const decodedPayload = base64urlDecodeV1(encodedPayload);
23
+ try {
24
+ const parsedPayload = JSON.parse(decodedPayload);
25
+ return parsedPayload;
26
+ }
27
+ catch (error) {
28
+ console.error("Error parsing JWT payload:", error);
29
+ return null;
30
+ }
31
+ }
32
+ exports.decodeJWtV1 = decodeJWtV1;
@@ -0,0 +1,3 @@
1
+ export declare function base64urlEncode(data: any): string;
2
+ export declare function createJWT(userId: string, email: string, name: string, secretKey: string, expiresIn: number): string;
3
+ //# sourceMappingURL=encode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../../../../src/utils/jwt/encode.ts"],"names":[],"mappings":"AAGA,wBAAgB,eAAe,CAAC,IAAI,EAAE,GAAG,GAAG,MAAM,CAGjD;AAGD,wBAAgB,SAAS,CACvB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,GAChB,MAAM,CAiBR"}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ // jwtUtils.ts
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.createJWT = exports.base64urlEncode = void 0;
5
+ // Function to encode payload to base64
6
+ function base64urlEncode(data) {
7
+ const base64 = btoa(JSON.stringify(data));
8
+ return base64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
9
+ }
10
+ exports.base64urlEncode = base64urlEncode;
11
+ // Function to create a JWT token with a secret key and expiration
12
+ function createJWT(userId, email, name, secretKey, expiresIn) {
13
+ const now = Math.floor(Date.now() / 1000); // Current time in seconds
14
+ const expirationTime = now + expiresIn; // Expiration time in seconds
15
+ const header = { alg: "HS256", typ: "JWT" }; // Using HS256 algorithm for demonstration
16
+ const payload = { userId, email, name, exp: expirationTime }; // Include 'exp' in payload
17
+ const encodedHeader = base64urlEncode(header);
18
+ const encodedPayload = base64urlEncode(payload);
19
+ const token = `${encodedHeader}.${encodedPayload}`;
20
+ // Create a signature using the secret key and sign the token
21
+ const signature = btoa(JSON.stringify(token + secretKey));
22
+ const signedToken = `${token}.${signature}`;
23
+ return signedToken;
24
+ }
25
+ exports.createJWT = createJWT;
@@ -0,0 +1,3 @@
1
+ export { decodeJWtV1 } from "./decode";
2
+ export { createJWT } from "./encode";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/utils/jwt/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC"}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createJWT = exports.decodeJWtV1 = void 0;
4
+ var decode_1 = require("./decode");
5
+ Object.defineProperty(exports, "decodeJWtV1", { enumerable: true, get: function () { return decode_1.decodeJWtV1; } });
6
+ var encode_1 = require("./encode");
7
+ Object.defineProperty(exports, "createJWT", { enumerable: true, get: function () { return encode_1.createJWT; } });
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Redirects the user to the specified destination path or absolute URL while appending all current URL query parameters.
3
+ * @example
4
+ * Redirect to "/custom-path" or http://example.com/red with current query parameters
5
+ * redirectToPathWithParams('/custom-path');
6
+ * @param destinationPath - The destination path or absolute URL.
7
+ */
8
+ export declare function redirectToPathWithParams(destinationPath: string): void;
9
+ //# sourceMappingURL=redirectToPathWithParams.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redirectToPathWithParams.d.ts","sourceRoot":"","sources":["../../../src/utils/redirectToPathWithParams.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CAAC,eAAe,EAAE,MAAM,GAAG,IAAI,CAatE"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.redirectToPathWithParams = void 0;
4
+ /**
5
+ * Redirects the user to the specified destination path or absolute URL while appending all current URL query parameters.
6
+ * @example
7
+ * Redirect to "/custom-path" or http://example.com/red with current query parameters
8
+ * redirectToPathWithParams('/custom-path');
9
+ * @param destinationPath - The destination path or absolute URL.
10
+ */
11
+ function redirectToPathWithParams(destinationPath) {
12
+ const currentURL = new URL(window.location.href);
13
+ const searchParams = currentURL.searchParams;
14
+ // Add query parameter for redirect
15
+ destinationPath += destinationPath.includes('?') ? '&ac=redirect' : '?ac=redirect';
16
+ // Add current query parameters to the destination path
17
+ searchParams.forEach((value, key) => {
18
+ destinationPath += `&${key}=${encodeURIComponent(value)}`;
19
+ });
20
+ window.location.href = destinationPath;
21
+ }
22
+ exports.redirectToPathWithParams = redirectToPathWithParams;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Sets a cookie with the specified name and value that can be shared across subdomains.
3
+ * @param name The name of the cookie.
4
+ * @param value The value of the cookie.
5
+ * @param expires The expiration date of the cookie. Defaults to 1 day from now.
6
+ */
7
+ export declare function setSharedCookie(name: string, value: string, expires?: number): void;
8
+ //# sourceMappingURL=setSharedCookie.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setSharedCookie.d.ts","sourceRoot":"","sources":["../../../src/utils/setSharedCookie.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,SAAM,QAKzE"}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.setSharedCookie = void 0;
7
+ const js_cookie_1 = __importDefault(require("js-cookie"));
8
+ const getMainDomain_1 = require("./getMainDomain");
9
+ /**
10
+ * Sets a cookie with the specified name and value that can be shared across subdomains.
11
+ * @param name The name of the cookie.
12
+ * @param value The value of the cookie.
13
+ * @param expires The expiration date of the cookie. Defaults to 1 day from now.
14
+ */
15
+ function setSharedCookie(name, value, expires = 180) {
16
+ // Get the main domain name of the current URL.
17
+ const domain = (0, getMainDomain_1.getMainDomain)(window.location.hostname);
18
+ // Set the cookie with the specified name, value, and domain.
19
+ js_cookie_1.default.set(name, value, { expires /** domain: domain == 'localhost' ? `localhost` : `.${domain}` */ });
20
+ }
21
+ exports.setSharedCookie = setSharedCookie;
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@airsoko/auth",
3
+ "version": "0.0.1",
4
+ "description": "",
5
+ "author": "",
6
+ "private": false,
7
+ "license": "UNLICENSED",
8
+ "main": "./dist/src/index.js",
9
+ "types": "./dist/src/index.d.ts",
10
+ "files": [
11
+ "dist/**"
12
+ ],
13
+ "scripts": {
14
+ "prebuild": "yarn clean",
15
+ "build": "tsc --build",
16
+ "format": "prettier --write \"src/**/*.ts\"",
17
+ "dev": "tsc --watch",
18
+ "clean": "rimraf dist && rimraf .turbo && rimraf node_modules",
19
+ "preLaunch": "tsc --build",
20
+ "test": "jest",
21
+ "test:watch": "jest --watch"
22
+ },
23
+ "dependencies": {
24
+ "@airsoko/api": "*",
25
+ "@airsoko/graphql": "*",
26
+ "js-cookie": "^3.0.5"
27
+ },
28
+ "devDependencies": {
29
+ "@airsoko/tsconfig": "*",
30
+ "@types/js-cookie": "^3.0.6"
31
+ },
32
+ "publishConfig": {
33
+ "access": "public"
34
+ }
35
+ }