@cabin-id/nextjs 1.0.0 → 1.0.2

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 (301) hide show
  1. package/dist/cjs/api/endpoints/AbstractApi.js +38 -0
  2. package/dist/cjs/api/endpoints/AbstractApi.js.map +1 -0
  3. package/dist/cjs/api/endpoints/UserApi.js +40 -0
  4. package/dist/cjs/api/endpoints/UserApi.js.map +1 -0
  5. package/dist/cjs/api/endpoints/index.js +32 -0
  6. package/dist/cjs/api/endpoints/index.js.map +1 -0
  7. package/dist/cjs/api/factory.js +60 -0
  8. package/dist/cjs/api/factory.js.map +1 -0
  9. package/dist/cjs/api/request.js +97 -0
  10. package/dist/cjs/api/request.js.map +1 -0
  11. package/dist/cjs/component.client.js +32 -0
  12. package/dist/cjs/component.client.js.map +1 -0
  13. package/dist/cjs/component.server.js +32 -0
  14. package/dist/cjs/component.server.js.map +1 -0
  15. package/dist/cjs/components/SignInButton.js +67 -0
  16. package/dist/cjs/components/SignInButton.js.map +1 -0
  17. package/dist/cjs/components/index.js +29 -0
  18. package/dist/cjs/components/index.js.map +1 -0
  19. package/dist/cjs/constants.js +122 -0
  20. package/dist/cjs/constants.js.map +1 -0
  21. package/dist/cjs/hooks/createContextAndHook.js +62 -0
  22. package/dist/cjs/hooks/createContextAndHook.js.map +1 -0
  23. package/dist/cjs/hooks/index.js +29 -0
  24. package/dist/cjs/hooks/index.js.map +1 -0
  25. package/dist/cjs/hooks/useSafeLayoutEffect.js +40 -0
  26. package/dist/cjs/hooks/useSafeLayoutEffect.js.map +1 -0
  27. package/dist/cjs/hooks/useUser.js +70 -0
  28. package/dist/cjs/hooks/useUser.js.map +1 -0
  29. package/dist/cjs/icons/logo.js +98 -0
  30. package/dist/cjs/icons/logo.js.map +1 -0
  31. package/dist/cjs/index.js +45 -0
  32. package/dist/cjs/index.js.map +1 -0
  33. package/dist/cjs/package.json +9 -0
  34. package/dist/cjs/provider/context.js +62 -0
  35. package/dist/cjs/provider/context.js.map +1 -0
  36. package/dist/cjs/provider/core.provider.js +49 -0
  37. package/dist/cjs/provider/core.provider.js.map +1 -0
  38. package/dist/cjs/provider/main.provider.js +45 -0
  39. package/dist/cjs/provider/main.provider.js.map +1 -0
  40. package/dist/cjs/server/auth.js +61 -0
  41. package/dist/cjs/server/auth.js.map +1 -0
  42. package/dist/cjs/server/client.js +35 -0
  43. package/dist/cjs/server/client.js.map +1 -0
  44. package/dist/cjs/server/createGetAuth.js +45 -0
  45. package/dist/cjs/server/createGetAuth.js.map +1 -0
  46. package/dist/cjs/server/createRedirect.js +90 -0
  47. package/dist/cjs/server/createRedirect.js.map +1 -0
  48. package/dist/cjs/server/errors.js +110 -0
  49. package/dist/cjs/server/errors.js.map +1 -0
  50. package/dist/cjs/server/getCurrentUser.js +36 -0
  51. package/dist/cjs/server/getCurrentUser.js.map +1 -0
  52. package/dist/cjs/server/index.js +32 -0
  53. package/dist/cjs/server/index.js.map +1 -0
  54. package/dist/cjs/server/middleware.js +193 -0
  55. package/dist/cjs/server/middleware.js.map +1 -0
  56. package/dist/cjs/server/protect.js +69 -0
  57. package/dist/cjs/server/protect.js.map +1 -0
  58. package/dist/cjs/server/routeMatcher.js +42 -0
  59. package/dist/cjs/server/routeMatcher.js.map +1 -0
  60. package/dist/cjs/server/serverRedirectWithAuth.js +39 -0
  61. package/dist/cjs/server/serverRedirectWithAuth.js.map +1 -0
  62. package/dist/cjs/server/type.js +17 -0
  63. package/dist/cjs/server/type.js.map +1 -0
  64. package/dist/cjs/server/utils.js +165 -0
  65. package/dist/cjs/server/utils.js.map +1 -0
  66. package/dist/cjs/styles/global.css +420 -0
  67. package/dist/cjs/styles/global.css.map +1 -0
  68. package/dist/cjs/tokens/authObjects.js +45 -0
  69. package/dist/cjs/tokens/authObjects.js.map +1 -0
  70. package/dist/cjs/tokens/authStatus.js +86 -0
  71. package/dist/cjs/tokens/authStatus.js.map +1 -0
  72. package/dist/cjs/tokens/authenticateContext.js +69 -0
  73. package/dist/cjs/tokens/authenticateContext.js.map +1 -0
  74. package/dist/cjs/tokens/cabinIdRequest.js +79 -0
  75. package/dist/cjs/tokens/cabinIdRequest.js.map +1 -0
  76. package/dist/cjs/tokens/cabinIdUrl.js +36 -0
  77. package/dist/cjs/tokens/cabinIdUrl.js.map +1 -0
  78. package/dist/cjs/tokens/request.js +58 -0
  79. package/dist/cjs/tokens/request.js.map +1 -0
  80. package/dist/cjs/types.js +17 -0
  81. package/dist/cjs/types.js.map +1 -0
  82. package/dist/cjs/utils/assertValidSecretKey.js +35 -0
  83. package/dist/cjs/utils/assertValidSecretKey.js.map +1 -0
  84. package/dist/cjs/utils/createCabinIdClient.js +38 -0
  85. package/dist/cjs/utils/createCabinIdClient.js.map +1 -0
  86. package/dist/cjs/utils/http.js +31 -0
  87. package/dist/cjs/utils/http.js.map +1 -0
  88. package/dist/cjs/utils/initial.js +45 -0
  89. package/dist/cjs/utils/initial.js.map +1 -0
  90. package/dist/cjs/utils/isomorphicAtob.js +36 -0
  91. package/dist/cjs/utils/isomorphicAtob.js.map +1 -0
  92. package/dist/cjs/utils/isomorphicBtoa.js +36 -0
  93. package/dist/cjs/utils/isomorphicBtoa.js.map +1 -0
  94. package/dist/cjs/utils/key.js +49 -0
  95. package/dist/cjs/utils/key.js.map +1 -0
  96. package/dist/cjs/utils/path.js +33 -0
  97. package/dist/cjs/utils/path.js.map +1 -0
  98. package/dist/cjs/utils/response.js +76 -0
  99. package/dist/cjs/utils/response.js.map +1 -0
  100. package/dist/cjs/utils.js +52 -0
  101. package/dist/cjs/utils.js.map +1 -0
  102. package/dist/esm/api/endpoints/AbstractApi.js +14 -0
  103. package/dist/esm/api/endpoints/AbstractApi.js.map +1 -0
  104. package/dist/esm/api/endpoints/UserApi.js +16 -0
  105. package/dist/esm/api/endpoints/UserApi.js.map +1 -0
  106. package/dist/esm/api/endpoints/index.js +7 -0
  107. package/dist/esm/api/endpoints/index.js.map +1 -0
  108. package/dist/esm/api/factory.js +35 -0
  109. package/dist/esm/api/factory.js.map +1 -0
  110. package/dist/esm/api/request.js +63 -0
  111. package/dist/esm/api/request.js.map +1 -0
  112. package/dist/esm/component.client.js +7 -0
  113. package/dist/esm/component.client.js.map +1 -0
  114. package/dist/esm/component.server.js +7 -0
  115. package/dist/esm/component.server.js.map +1 -0
  116. package/dist/esm/components/SignInButton.js +33 -0
  117. package/dist/esm/components/SignInButton.js.map +1 -0
  118. package/dist/esm/components/index.js +5 -0
  119. package/dist/esm/components/index.js.map +1 -0
  120. package/dist/esm/constants.js +88 -0
  121. package/dist/esm/constants.js.map +1 -0
  122. package/dist/esm/hooks/createContextAndHook.js +27 -0
  123. package/dist/esm/hooks/createContextAndHook.js.map +1 -0
  124. package/dist/esm/hooks/index.js +5 -0
  125. package/dist/esm/hooks/index.js.map +1 -0
  126. package/dist/esm/hooks/useSafeLayoutEffect.js +6 -0
  127. package/dist/esm/hooks/useSafeLayoutEffect.js.map +1 -0
  128. package/dist/esm/hooks/useUser.js +54 -0
  129. package/dist/esm/hooks/useUser.js.map +1 -0
  130. package/dist/esm/icons/logo.js +64 -0
  131. package/dist/esm/icons/logo.js.map +1 -0
  132. package/dist/esm/index.js +16 -0
  133. package/dist/esm/index.js.map +1 -0
  134. package/dist/esm/package.json +9 -0
  135. package/dist/esm/provider/context.js +24 -0
  136. package/dist/esm/provider/context.js.map +1 -0
  137. package/dist/esm/provider/core.provider.js +15 -0
  138. package/dist/esm/provider/core.provider.js.map +1 -0
  139. package/dist/esm/provider/main.provider.js +11 -0
  140. package/dist/esm/provider/main.provider.js.map +1 -0
  141. package/dist/esm/server/auth.js +37 -0
  142. package/dist/esm/server/auth.js.map +1 -0
  143. package/dist/esm/server/client.js +11 -0
  144. package/dist/esm/server/client.js.map +1 -0
  145. package/dist/esm/server/createGetAuth.js +23 -0
  146. package/dist/esm/server/createGetAuth.js.map +1 -0
  147. package/dist/esm/server/createRedirect.js +66 -0
  148. package/dist/esm/server/createRedirect.js.map +1 -0
  149. package/dist/esm/server/errors.js +78 -0
  150. package/dist/esm/server/errors.js.map +1 -0
  151. package/dist/esm/server/getCurrentUser.js +12 -0
  152. package/dist/esm/server/getCurrentUser.js.map +1 -0
  153. package/dist/esm/server/index.js +7 -0
  154. package/dist/esm/server/index.js.map +1 -0
  155. package/dist/esm/server/middleware.js +175 -0
  156. package/dist/esm/server/middleware.js.map +1 -0
  157. package/dist/esm/server/protect.js +45 -0
  158. package/dist/esm/server/protect.js.map +1 -0
  159. package/dist/esm/server/routeMatcher.js +18 -0
  160. package/dist/esm/server/routeMatcher.js.map +1 -0
  161. package/dist/esm/server/serverRedirectWithAuth.js +15 -0
  162. package/dist/esm/server/serverRedirectWithAuth.js.map +1 -0
  163. package/dist/esm/server/type.js +1 -0
  164. package/dist/esm/server/type.js.map +1 -0
  165. package/dist/esm/server/utils.js +132 -0
  166. package/dist/esm/server/utils.js.map +1 -0
  167. package/dist/esm/styles/global.css +420 -0
  168. package/dist/esm/styles/global.css.map +1 -0
  169. package/dist/esm/tokens/authObjects.js +20 -0
  170. package/dist/esm/tokens/authObjects.js.map +1 -0
  171. package/dist/esm/tokens/authStatus.js +59 -0
  172. package/dist/esm/tokens/authStatus.js.map +1 -0
  173. package/dist/esm/tokens/authenticateContext.js +45 -0
  174. package/dist/esm/tokens/authenticateContext.js.map +1 -0
  175. package/dist/esm/tokens/cabinIdRequest.js +55 -0
  176. package/dist/esm/tokens/cabinIdRequest.js.map +1 -0
  177. package/dist/esm/tokens/cabinIdUrl.js +12 -0
  178. package/dist/esm/tokens/cabinIdUrl.js.map +1 -0
  179. package/dist/esm/tokens/request.js +34 -0
  180. package/dist/esm/tokens/request.js.map +1 -0
  181. package/dist/esm/types.js +1 -0
  182. package/dist/esm/types.js.map +1 -0
  183. package/dist/esm/utils/assertValidSecretKey.js +11 -0
  184. package/dist/esm/utils/assertValidSecretKey.js.map +1 -0
  185. package/dist/esm/utils/createCabinIdClient.js +17 -0
  186. package/dist/esm/utils/createCabinIdClient.js.map +1 -0
  187. package/dist/esm/utils/http.js +7 -0
  188. package/dist/esm/utils/http.js.map +1 -0
  189. package/dist/esm/utils/initial.js +21 -0
  190. package/dist/esm/utils/initial.js.map +1 -0
  191. package/dist/esm/utils/isomorphicAtob.js +12 -0
  192. package/dist/esm/utils/isomorphicAtob.js.map +1 -0
  193. package/dist/esm/utils/isomorphicBtoa.js +12 -0
  194. package/dist/esm/utils/isomorphicBtoa.js.map +1 -0
  195. package/dist/esm/utils/key.js +24 -0
  196. package/dist/esm/utils/key.js.map +1 -0
  197. package/dist/esm/utils/path.js +9 -0
  198. package/dist/esm/utils/path.js.map +1 -0
  199. package/dist/esm/utils/response.js +49 -0
  200. package/dist/esm/utils/response.js.map +1 -0
  201. package/dist/esm/utils.js +27 -0
  202. package/dist/esm/utils.js.map +1 -0
  203. package/dist/types/api/endpoints/AbstractApi.d.ts +7 -0
  204. package/dist/types/api/endpoints/AbstractApi.d.ts.map +1 -0
  205. package/dist/types/api/endpoints/UserApi.d.ts +6 -0
  206. package/dist/types/api/endpoints/UserApi.d.ts.map +1 -0
  207. package/dist/types/api/endpoints/index.d.ts +3 -0
  208. package/dist/types/api/endpoints/index.d.ts.map +1 -0
  209. package/dist/types/api/factory.d.ts +35 -0
  210. package/dist/types/api/factory.d.ts.map +1 -0
  211. package/dist/types/api/request.d.ts +33 -0
  212. package/dist/types/api/request.d.ts.map +1 -0
  213. package/dist/types/component.client.d.ts +3 -0
  214. package/dist/types/component.client.d.ts.map +1 -0
  215. package/dist/types/component.server.d.ts +3 -0
  216. package/dist/types/component.server.d.ts.map +1 -0
  217. package/dist/types/components/SignInButton.d.ts +3 -0
  218. package/dist/types/components/SignInButton.d.ts.map +1 -0
  219. package/dist/types/components/index.d.ts +2 -0
  220. package/dist/types/components/index.d.ts.map +1 -0
  221. package/dist/types/constants.d.ts +69 -0
  222. package/dist/types/constants.d.ts.map +1 -0
  223. package/dist/types/hooks/createContextAndHook.d.ts +18 -0
  224. package/dist/types/hooks/createContextAndHook.d.ts.map +1 -0
  225. package/dist/types/hooks/index.d.ts +2 -0
  226. package/dist/types/hooks/index.d.ts.map +1 -0
  227. package/dist/types/hooks/useSafeLayoutEffect.d.ts +3 -0
  228. package/dist/types/hooks/useSafeLayoutEffect.d.ts.map +1 -0
  229. package/dist/types/hooks/useUser.d.ts +36 -0
  230. package/dist/types/hooks/useUser.d.ts.map +1 -0
  231. package/dist/types/icons/logo.d.ts +3 -0
  232. package/dist/types/icons/logo.d.ts.map +1 -0
  233. package/dist/types/index.d.ts +8 -0
  234. package/dist/types/index.d.ts.map +1 -0
  235. package/dist/types/provider/context.d.ts +15 -0
  236. package/dist/types/provider/context.d.ts.map +1 -0
  237. package/dist/types/provider/core.provider.d.ts +6 -0
  238. package/dist/types/provider/core.provider.d.ts.map +1 -0
  239. package/dist/types/provider/main.provider.d.ts +5 -0
  240. package/dist/types/provider/main.provider.d.ts.map +1 -0
  241. package/dist/types/server/auth.d.ts +11 -0
  242. package/dist/types/server/auth.d.ts.map +1 -0
  243. package/dist/types/server/client.d.ts +3 -0
  244. package/dist/types/server/client.d.ts.map +1 -0
  245. package/dist/types/server/createGetAuth.d.ts +5 -0
  246. package/dist/types/server/createGetAuth.d.ts.map +1 -0
  247. package/dist/types/server/createRedirect.d.ts +21 -0
  248. package/dist/types/server/createRedirect.d.ts.map +1 -0
  249. package/dist/types/server/errors.d.ts +10 -0
  250. package/dist/types/server/errors.d.ts.map +1 -0
  251. package/dist/types/server/getCurrentUser.d.ts +3 -0
  252. package/dist/types/server/getCurrentUser.d.ts.map +1 -0
  253. package/dist/types/server/index.d.ts +3 -0
  254. package/dist/types/server/index.d.ts.map +1 -0
  255. package/dist/types/server/middleware.d.ts +33 -0
  256. package/dist/types/server/middleware.d.ts.map +1 -0
  257. package/dist/types/server/protect.d.ts +34 -0
  258. package/dist/types/server/protect.d.ts.map +1 -0
  259. package/dist/types/server/routeMatcher.d.ts +10 -0
  260. package/dist/types/server/routeMatcher.d.ts.map +1 -0
  261. package/dist/types/server/serverRedirectWithAuth.d.ts +3 -0
  262. package/dist/types/server/serverRedirectWithAuth.d.ts.map +1 -0
  263. package/dist/types/server/type.d.ts +14 -0
  264. package/dist/types/server/type.d.ts.map +1 -0
  265. package/dist/types/server/utils.d.ts +17 -0
  266. package/dist/types/server/utils.d.ts.map +1 -0
  267. package/dist/types/tokens/authObjects.d.ts +37 -0
  268. package/dist/types/tokens/authObjects.d.ts.map +1 -0
  269. package/dist/types/tokens/authStatus.d.ts +51 -0
  270. package/dist/types/tokens/authStatus.d.ts.map +1 -0
  271. package/dist/types/tokens/authenticateContext.d.ts +40 -0
  272. package/dist/types/tokens/authenticateContext.d.ts.map +1 -0
  273. package/dist/types/tokens/cabinIdRequest.d.ts +24 -0
  274. package/dist/types/tokens/cabinIdRequest.d.ts.map +1 -0
  275. package/dist/types/tokens/cabinIdUrl.d.ts +18 -0
  276. package/dist/types/tokens/cabinIdUrl.d.ts.map +1 -0
  277. package/dist/types/tokens/request.d.ts +4 -0
  278. package/dist/types/tokens/request.d.ts.map +1 -0
  279. package/dist/types/types.d.ts +34 -0
  280. package/dist/types/types.d.ts.map +1 -0
  281. package/dist/types/utils/assertValidSecretKey.d.ts +2 -0
  282. package/dist/types/utils/assertValidSecretKey.d.ts.map +1 -0
  283. package/dist/types/utils/createCabinIdClient.d.ts +5 -0
  284. package/dist/types/utils/createCabinIdClient.d.ts.map +1 -0
  285. package/dist/types/utils/http.d.ts +4 -0
  286. package/dist/types/utils/http.d.ts.map +1 -0
  287. package/dist/types/utils/initial.d.ts +5 -0
  288. package/dist/types/utils/initial.d.ts.map +1 -0
  289. package/dist/types/utils/isomorphicAtob.d.ts +6 -0
  290. package/dist/types/utils/isomorphicAtob.d.ts.map +1 -0
  291. package/dist/types/utils/isomorphicBtoa.d.ts +2 -0
  292. package/dist/types/utils/isomorphicBtoa.d.ts.map +1 -0
  293. package/dist/types/utils/key.d.ts +5 -0
  294. package/dist/types/utils/key.d.ts.map +1 -0
  295. package/dist/types/utils/path.d.ts +4 -0
  296. package/dist/types/utils/path.d.ts.map +1 -0
  297. package/dist/types/utils/response.d.ts +13 -0
  298. package/dist/types/utils/response.d.ts.map +1 -0
  299. package/dist/types/utils.d.ts +5 -0
  300. package/dist/types/utils.d.ts.map +1 -0
  301. package/package.json +1 -1
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var client_exports = {};
20
+ __export(client_exports, {
21
+ cabinIdClient: () => cabinIdClient
22
+ });
23
+ module.exports = __toCommonJS(client_exports);
24
+ var import_constants = require("../constants");
25
+ var import_createCabinIdClient = require("../utils/createCabinIdClient");
26
+ const cabinIdClient = (0, import_createCabinIdClient.createCabinIdClient)({
27
+ apiUrl: import_constants.API_URL,
28
+ apiVersion: import_constants.API_VERSION,
29
+ secretKey: import_constants.SECRET_KEY
30
+ });
31
+ // Annotate the CommonJS export names for ESM import in node:
32
+ 0 && (module.exports = {
33
+ cabinIdClient
34
+ });
35
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/server/client.ts"],"sourcesContent":["import { API_URL, API_VERSION, SECRET_KEY } from '../constants';\nimport { createCabinIdClient } from '../utils/createCabinIdClient';\n\nconst cabinIdClient = createCabinIdClient({\n apiUrl: API_URL,\n apiVersion: API_VERSION,\n secretKey: SECRET_KEY,\n});\n\nexport { cabinIdClient };\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAiD;AACjD,iCAAoC;AAEpC,MAAM,oBAAgB,gDAAoB;AAAA,EACxC,QAAQ;AAAA,EACR,YAAY;AAAA,EACZ,WAAW;AACb,CAAC;","names":[]}
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var createGetAuth_exports = {};
20
+ __export(createGetAuth_exports, {
21
+ createGetAuth: () => createGetAuth,
22
+ getAuth: () => getAuth
23
+ });
24
+ module.exports = __toCommonJS(createGetAuth_exports);
25
+ var import_authObjects = require("../tokens/authObjects");
26
+ var import_constants = require("../constants");
27
+ var import_utils = require("./utils");
28
+ const createGetAuth = () => (req) => {
29
+ const authToken = (0, import_utils.getCookie)(req, import_constants.constants.Cookies.Client);
30
+ const userId = (0, import_utils.getCookie)(req, import_constants.constants.Cookies.User);
31
+ if (authToken && userId) {
32
+ return (0, import_authObjects.signedInAuthObject)({
33
+ sessionToken: authToken || "",
34
+ userId: userId || ""
35
+ });
36
+ }
37
+ return (0, import_authObjects.signedOutAuthObject)();
38
+ };
39
+ const getAuth = createGetAuth();
40
+ // Annotate the CommonJS export names for ESM import in node:
41
+ 0 && (module.exports = {
42
+ createGetAuth,
43
+ getAuth
44
+ });
45
+ //# sourceMappingURL=createGetAuth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/server/createGetAuth.ts"],"sourcesContent":["import {\n AuthObject,\n signedInAuthObject,\n signedOutAuthObject,\n} from '../tokens/authObjects';\nimport { constants } from '../constants';\nimport { getCookie } from './utils';\nimport { RequestLike } from './type';\n\nexport const createGetAuth =\n () =>\n (req: RequestLike): AuthObject => {\n const authToken = getCookie(req, constants.Cookies.Client);\n const userId = getCookie(req, constants.Cookies.User);\n if (authToken && userId) {\n return signedInAuthObject({\n sessionToken: authToken || '',\n userId: userId || '',\n });\n }\n\n return signedOutAuthObject();\n };\n\nexport const getAuth = createGetAuth();\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAIO;AACP,uBAA0B;AAC1B,mBAA0B;AAGnB,MAAM,gBACX,MACA,CAAC,QAAiC;AAChC,QAAM,gBAAY,wBAAU,KAAK,2BAAU,QAAQ,MAAM;AACzD,QAAM,aAAS,wBAAU,KAAK,2BAAU,QAAQ,IAAI;AACpD,MAAI,aAAa,QAAQ;AACvB,eAAO,uCAAmB;AAAA,MACxB,cAAc,aAAa;AAAA,MAC3B,QAAQ,UAAU;AAAA,IACpB,CAAC;AAAA,EACH;AAEA,aAAO,wCAAoB;AAC7B;AAEK,MAAM,UAAU,cAAc;","names":[]}
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var createRedirect_exports = {};
20
+ __export(createRedirect_exports, {
21
+ createRedirect: () => createRedirect
22
+ });
23
+ module.exports = __toCommonJS(createRedirect_exports);
24
+ var import_key = require("../utils/key");
25
+ const buildUrl = (_baseUrl, _targetUrl, _returnBackUrl) => {
26
+ if (!!_baseUrl) {
27
+ const baseUrl = new URL(_baseUrl);
28
+ const returnBackUrl = _returnBackUrl ? new URL(_returnBackUrl, baseUrl) : void 0;
29
+ const res = new URL(_targetUrl, baseUrl);
30
+ if (returnBackUrl) {
31
+ res.searchParams.set("redirect_url", returnBackUrl.toString());
32
+ }
33
+ return res.toString();
34
+ } else {
35
+ const returnBackUrl = _returnBackUrl ? new URL(_returnBackUrl) : void 0;
36
+ const res = new URL(_targetUrl);
37
+ if (returnBackUrl) {
38
+ res.searchParams.set("redirect_url", returnBackUrl.toString());
39
+ }
40
+ return res.toString();
41
+ }
42
+ };
43
+ const buildAccountsBaseUrl = (frontendApi) => {
44
+ if (!frontendApi) {
45
+ return "";
46
+ }
47
+ const accountsBaseUrl = frontendApi;
48
+ return `https://${accountsBaseUrl}`;
49
+ };
50
+ const createRedirect = (params) => {
51
+ const { publishableKey, redirectAdapter, signInUrl, signUpUrl, baseUrl } = params;
52
+ const frontendApi = (0, import_key.parsePublishableKey)(publishableKey);
53
+ const accountsBaseUrl = buildAccountsBaseUrl(frontendApi);
54
+ const redirectToSignUp = ({ returnBackUrl } = {}) => {
55
+ if (!signUpUrl && !accountsBaseUrl) {
56
+ throw new Error("Publish Key is not exist");
57
+ }
58
+ const accountsSignUpUrl = `${accountsBaseUrl}/sign-up`;
59
+ let redirect = null;
60
+ if (signUpUrl) {
61
+ redirect = redirectAdapter(buildUrl(baseUrl, signUpUrl));
62
+ } else {
63
+ redirect = redirectAdapter(
64
+ buildUrl(null, accountsSignUpUrl, returnBackUrl)
65
+ );
66
+ }
67
+ return redirect;
68
+ };
69
+ const redirectToSignIn = ({ returnBackUrl } = {}) => {
70
+ if (!signInUrl && !accountsBaseUrl) {
71
+ throw new Error("Publish Key is not exist");
72
+ }
73
+ const accountsSignInUrl = `${accountsBaseUrl}/sign-in`;
74
+ let redirect = null;
75
+ if (signInUrl) {
76
+ redirect = redirectAdapter(buildUrl(baseUrl, signInUrl));
77
+ } else {
78
+ redirect = redirectAdapter(
79
+ buildUrl(null, accountsSignInUrl, returnBackUrl)
80
+ );
81
+ }
82
+ return redirect;
83
+ };
84
+ return { redirectToSignUp, redirectToSignIn };
85
+ };
86
+ // Annotate the CommonJS export names for ESM import in node:
87
+ 0 && (module.exports = {
88
+ createRedirect
89
+ });
90
+ //# sourceMappingURL=createRedirect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/server/createRedirect.ts"],"sourcesContent":["import { parsePublishableKey } from '../utils/key';\n\ntype RedirectAdapter<RedirectReturn> = (url: string) => RedirectReturn;\ntype RedirectToParams = { returnBackUrl?: string | URL | null };\nexport type RedirectFun<ReturnType> = (params?: RedirectToParams) => ReturnType;\n\nconst buildUrl = (\n _baseUrl: string | URL | null,\n _targetUrl: string | URL,\n _returnBackUrl?: string | URL | null\n) => {\n if (!!_baseUrl) {\n const baseUrl = new URL(_baseUrl);\n const returnBackUrl = _returnBackUrl\n ? new URL(_returnBackUrl, baseUrl)\n : undefined;\n const res = new URL(_targetUrl, baseUrl);\n\n if (returnBackUrl) {\n res.searchParams.set('redirect_url', returnBackUrl.toString());\n }\n return res.toString();\n } else {\n const returnBackUrl = _returnBackUrl ? new URL(_returnBackUrl) : undefined;\n const res = new URL(_targetUrl);\n\n if (returnBackUrl) {\n res.searchParams.set('redirect_url', returnBackUrl.toString());\n }\n return res.toString();\n }\n};\n\nconst buildAccountsBaseUrl = (frontendApi: string | null) => {\n if (!frontendApi) {\n return '';\n }\n\n // convert url from FAPI to accounts for Kima and legacy (prod & dev) instances\n const accountsBaseUrl = frontendApi;\n return `https://${accountsBaseUrl}`;\n};\n\n/**\n * @internal\n */\ntype CreateRedirect = <ReturnType>(params: {\n publishableKey: string;\n redirectAdapter: RedirectAdapter<ReturnType>;\n baseUrl: URL | string;\n signInUrl?: URL | string;\n signUpUrl?: URL | string;\n}) => {\n redirectToSignIn: RedirectFun<ReturnType>;\n redirectToSignUp: RedirectFun<ReturnType>;\n};\n\nexport const createRedirect: CreateRedirect = (params) => {\n const { publishableKey, redirectAdapter, signInUrl, signUpUrl, baseUrl } =\n params;\n const frontendApi = parsePublishableKey(publishableKey);\n const accountsBaseUrl = buildAccountsBaseUrl(frontendApi);\n\n const redirectToSignUp = ({ returnBackUrl }: RedirectToParams = {}) => {\n if (!signUpUrl && !accountsBaseUrl) {\n throw new Error('Publish Key is not exist');\n }\n const accountsSignUpUrl = `${accountsBaseUrl}/sign-up`;\n let redirect = null;\n\n if (signUpUrl) {\n redirect = redirectAdapter(buildUrl(baseUrl, signUpUrl));\n } else {\n redirect = redirectAdapter(\n buildUrl(null, accountsSignUpUrl, returnBackUrl)\n );\n }\n return redirect;\n };\n\n const redirectToSignIn = ({ returnBackUrl }: RedirectToParams = {}) => {\n if (!signInUrl && !accountsBaseUrl) {\n throw new Error('Publish Key is not exist');\n }\n const accountsSignInUrl = `${accountsBaseUrl}/sign-in`;\n\n let redirect = null;\n if (signInUrl) {\n redirect = redirectAdapter(buildUrl(baseUrl, signInUrl));\n } else {\n redirect = redirectAdapter(\n buildUrl(null, accountsSignInUrl, returnBackUrl)\n );\n }\n\n return redirect;\n };\n\n return { redirectToSignUp, redirectToSignIn };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAA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;AAEA,QAAM,mBAAmB,CAAC,EAAE,cAAc,IAAsB,CAAC,MAAM;AACrE,QAAI,CAAC,aAAa,CAAC,iBAAiB;AAClC,YAAM,IAAI,MAAM,0BAA0B;AAAA,IAC5C;AACA,UAAM,oBAAoB,GAAG,eAAe;AAE5C,QAAI,WAAW;AACf,QAAI,WAAW;AACb,iBAAW,gBAAgB,SAAS,SAAS,SAAS,CAAC;AAAA,IACzD,OAAO;AACL,iBAAW;AAAA,QACT,SAAS,MAAM,mBAAmB,aAAa;AAAA,MACjD;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAEA,SAAO,EAAE,kBAAkB,iBAAiB;AAC9C;","names":[]}
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var errors_exports = {};
20
+ __export(errors_exports, {
21
+ authAuthHeaderMissing: () => authAuthHeaderMissing,
22
+ authSignatureInvalid: () => authSignatureInvalid,
23
+ clockSkewDetected: () => clockSkewDetected,
24
+ getAuthAuthHeaderMissing: () => getAuthAuthHeaderMissing,
25
+ infiniteRedirectLoopDetected: () => infiniteRedirectLoopDetected,
26
+ informAboutProtectedRouteInfo: () => informAboutProtectedRouteInfo,
27
+ missingDomainAndProxy: () => missingDomainAndProxy,
28
+ missingSignInUrlInDev: () => missingSignInUrlInDev,
29
+ receivedRequestForIgnoredRoute: () => receivedRequestForIgnoredRoute
30
+ });
31
+ module.exports = __toCommonJS(errors_exports);
32
+ const missingDomainAndProxy = `
33
+ Missing domain and proxyUrl. A satellite application needs to specify a domain or a proxyUrl.
34
+
35
+ 1) With middleware
36
+ e.g. export default clerkMiddleware({domain:'YOUR_DOMAIN',isSatellite:true}); // or the deprecated authMiddleware()
37
+ 2) With environment variables e.g.
38
+ NEXT_PUBLIC_CLERK_DOMAIN='YOUR_DOMAIN'
39
+ NEXT_PUBLIC_CLERK_IS_SATELLITE='true'
40
+ `;
41
+ const missingSignInUrlInDev = `
42
+ Invalid signInUrl. A satellite application requires a signInUrl for development instances.
43
+ Check if signInUrl is missing from your configuration or if it is not an absolute URL
44
+
45
+ 1) With middleware
46
+ e.g. export default clerkMiddleware({signInUrl:'SOME_URL', isSatellite:true}); // or the deprecated authMiddleware()
47
+ 2) With environment variables e.g.
48
+ NEXT_PUBLIC_CLERK_SIGN_IN_URL='SOME_URL'
49
+ NEXT_PUBLIC_CLERK_IS_SATELLITE='true'`;
50
+ const receivedRequestForIgnoredRoute = (url, matcher) => `Clerk: The middleware was skipped for this request URL: ${url}. For performance reasons, it's recommended to your middleware matcher to:
51
+ export const config = {
52
+ matcher: ${matcher},
53
+ };
54
+
55
+ Alternatively, you can set your own ignoredRoutes. See https://clerk.com/docs/nextjs/middleware
56
+ (This log only appears in development mode)
57
+ `;
58
+ const getAuthAuthHeaderMissing = () => authAuthHeaderMissing("getAuth");
59
+ const authAuthHeaderMissing = (helperName = "auth") => `CabinID: ${helperName}() was called but CabinID can't detect usage of authMiddleware(). Please ensure the following:
60
+ - clerkMiddleware() authMiddleware is used in your Next.js Middleware.
61
+ - Your Middleware matcher is configured to match this route or page.
62
+ - If you are using the src directory, make sure the Middleware file is inside of it.
63
+ `;
64
+ const clockSkewDetected = (verifyMessage) => `Clerk: Clock skew detected. This usually means that your system clock is inaccurate. Clerk will continuously try to issue new tokens, as the existing ones will be treated as "expired" due to clock skew.
65
+
66
+ To resolve this issue, make sure your system's clock is set to the correct time (e.g. turn off and on automatic time synchronization).
67
+
68
+ ---
69
+
70
+ ${verifyMessage}`;
71
+ const infiniteRedirectLoopDetected = () => `Clerk: Infinite redirect loop detected. That usually means that we were not able to determine the auth state for this request. A list of common causes and solutions follows.
72
+
73
+ Reason 1:
74
+ Your Clerk instance keys are incorrect, or you recently changed keys (Publishable Key, Secret Key).
75
+ How to resolve:
76
+ -> Make sure you're using the correct keys from the Clerk Dashboard. If you changed keys recently, make sure to clear your browser application data and cookies.
77
+
78
+ Reason 2:
79
+ A bug that may have already been fixed in the latest version of Clerk NextJS package.
80
+ How to resolve:
81
+ -> Make sure you are using the latest version of '@clerk/nextjs' and 'next'.
82
+ `;
83
+ const informAboutProtectedRouteInfo = (path, hasPublicRoutes, hasIgnoredRoutes, isApiRoute, defaultIgnoredRoutes) => {
84
+ const infoText = isApiRoute ? `INFO: Clerk: The request to ${path} is being protected (401) because there is no signed-in user, and the path is included in \`apiRoutes\`. To prevent this behavior, choose one of:` : `INFO: Clerk: The request to ${path} is being redirected because there is no signed-in user, and the path is not included in \`ignoredRoutes\` or \`publicRoutes\`. To prevent this behavior, choose one of:`;
85
+ const apiRoutesText = isApiRoute ? `To prevent Clerk authentication from protecting (401) the api route, remove the rule matching "${path}" from the \`apiRoutes\` array passed to authMiddleware` : void 0;
86
+ const publicRoutesText = hasPublicRoutes ? `To make the route accessible to both signed in and signed out users, add "${path}" to the \`publicRoutes\` array passed to authMiddleware` : `To make the route accessible to both signed in and signed out users, pass \`publicRoutes: ["${path}"]\` to authMiddleware`;
87
+ const ignoredRoutes = [...defaultIgnoredRoutes, path].map((r) => `"${r}"`).join(", ");
88
+ const ignoredRoutesText = hasIgnoredRoutes ? `To prevent Clerk authentication from running at all, add "${path}" to the \`ignoredRoutes\` array passed to authMiddleware` : `To prevent Clerk authentication from running at all, pass \`ignoredRoutes: [${ignoredRoutes}]\` to authMiddleware`;
89
+ const afterAuthText = "Pass a custom `afterAuth` to authMiddleware, and replace Clerk's default behavior of redirecting unless a route is included in publicRoutes";
90
+ return `${infoText}
91
+
92
+ ${[apiRoutesText, publicRoutesText, ignoredRoutesText, afterAuthText].filter(Boolean).map((text, index) => `${index + 1}. ${text}`).join("\n")}
93
+
94
+ For additional information about middleware, please visit https://clerk.com/docs/nextjs/middleware
95
+ (This log only appears in development mode, or if \`debug: true\` is passed to authMiddleware)`;
96
+ };
97
+ const authSignatureInvalid = `Clerk: Unable to verify request, this usually means the Clerk middleware did not run. Ensure Clerk's middleware is properly integrated and matches the current route. For more information, see: https://clerk.com/docs/nextjs/middleware. (code=auth_signature_invalid)`;
98
+ // Annotate the CommonJS export names for ESM import in node:
99
+ 0 && (module.exports = {
100
+ authAuthHeaderMissing,
101
+ authSignatureInvalid,
102
+ clockSkewDetected,
103
+ getAuthAuthHeaderMissing,
104
+ infiniteRedirectLoopDetected,
105
+ informAboutProtectedRouteInfo,
106
+ missingDomainAndProxy,
107
+ missingSignInUrlInDev,
108
+ receivedRequestForIgnoredRoute
109
+ });
110
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/server/errors.ts"],"sourcesContent":["export const missingDomainAndProxy = `\nMissing domain and proxyUrl. A satellite application needs to specify a domain or a proxyUrl.\n\n1) With middleware\n e.g. export default clerkMiddleware({domain:'YOUR_DOMAIN',isSatellite:true}); // or the deprecated authMiddleware()\n2) With environment variables e.g.\n NEXT_PUBLIC_CLERK_DOMAIN='YOUR_DOMAIN'\n NEXT_PUBLIC_CLERK_IS_SATELLITE='true'\n `;\n\nexport const missingSignInUrlInDev = `\nInvalid signInUrl. A satellite application requires a signInUrl for development instances.\nCheck if signInUrl is missing from your configuration or if it is not an absolute URL\n\n1) With middleware\n e.g. export default clerkMiddleware({signInUrl:'SOME_URL', isSatellite:true}); // or the deprecated authMiddleware()\n2) With environment variables e.g.\n NEXT_PUBLIC_CLERK_SIGN_IN_URL='SOME_URL'\n NEXT_PUBLIC_CLERK_IS_SATELLITE='true'`;\n\nexport const receivedRequestForIgnoredRoute = (url: string, matcher: string) =>\n `Clerk: The middleware was skipped for this request URL: ${url}. For performance reasons, it's recommended to your middleware matcher to:\nexport const config = {\n matcher: ${matcher},\n};\n\nAlternatively, you can set your own ignoredRoutes. See https://clerk.com/docs/nextjs/middleware\n(This log only appears in development mode)\n`;\n\nexport const getAuthAuthHeaderMissing = () => authAuthHeaderMissing('getAuth');\n\nexport const authAuthHeaderMissing = (helperName = 'auth') =>\n `CabinID: ${helperName}() was called but CabinID can't detect usage of authMiddleware(). Please ensure the following:\n- clerkMiddleware() authMiddleware is used in your Next.js Middleware.\n- Your Middleware matcher is configured to match this route or page.\n- If you are using the src directory, make sure the Middleware file is inside of it.\n`;\n\nexport const clockSkewDetected = (verifyMessage: string) =>\n `Clerk: Clock skew detected. This usually means that your system clock is inaccurate. Clerk will continuously try to issue new tokens, as the existing ones will be treated as \"expired\" due to clock skew.\n\nTo resolve this issue, make sure your system's clock is set to the correct time (e.g. turn off and on automatic time synchronization).\n\n---\n\n${verifyMessage}`;\n\nexport const infiniteRedirectLoopDetected = () =>\n `Clerk: Infinite redirect loop detected. That usually means that we were not able to determine the auth state for this request. A list of common causes and solutions follows.\n\nReason 1:\nYour Clerk instance keys are incorrect, or you recently changed keys (Publishable Key, Secret Key).\nHow to resolve:\n-> Make sure you're using the correct keys from the Clerk Dashboard. If you changed keys recently, make sure to clear your browser application data and cookies.\n\nReason 2:\nA bug that may have already been fixed in the latest version of Clerk NextJS package.\nHow to resolve:\n-> Make sure you are using the latest version of '@clerk/nextjs' and 'next'.\n`;\n\nexport const informAboutProtectedRouteInfo = (\n path: string,\n hasPublicRoutes: boolean,\n hasIgnoredRoutes: boolean,\n isApiRoute: boolean,\n defaultIgnoredRoutes: string[]\n) => {\n const infoText = isApiRoute\n ? `INFO: Clerk: The request to ${path} is being protected (401) because there is no signed-in user, and the path is included in \\`apiRoutes\\`. To prevent this behavior, choose one of:`\n : `INFO: Clerk: The request to ${path} is being redirected because there is no signed-in user, and the path is not included in \\`ignoredRoutes\\` or \\`publicRoutes\\`. To prevent this behavior, choose one of:`;\n const apiRoutesText = isApiRoute\n ? `To prevent Clerk authentication from protecting (401) the api route, remove the rule matching \"${path}\" from the \\`apiRoutes\\` array passed to authMiddleware`\n : undefined;\n const publicRoutesText = hasPublicRoutes\n ? `To make the route accessible to both signed in and signed out users, add \"${path}\" to the \\`publicRoutes\\` array passed to authMiddleware`\n : `To make the route accessible to both signed in and signed out users, pass \\`publicRoutes: [\"${path}\"]\\` to authMiddleware`;\n const ignoredRoutes = [...defaultIgnoredRoutes, path]\n .map((r) => `\"${r}\"`)\n .join(', ');\n const ignoredRoutesText = hasIgnoredRoutes\n ? `To prevent Clerk authentication from running at all, add \"${path}\" to the \\`ignoredRoutes\\` array passed to authMiddleware`\n : `To prevent Clerk authentication from running at all, pass \\`ignoredRoutes: [${ignoredRoutes}]\\` to authMiddleware`;\n const afterAuthText =\n \"Pass a custom `afterAuth` to authMiddleware, and replace Clerk's default behavior of redirecting unless a route is included in publicRoutes\";\n\n return `${infoText}\n\n${[apiRoutesText, publicRoutesText, ignoredRoutesText, afterAuthText]\n .filter(Boolean)\n .map((text, index) => `${index + 1}. ${text}`)\n .join('\\n')}\n\nFor additional information about middleware, please visit https://clerk.com/docs/nextjs/middleware\n(This log only appears in development mode, or if \\`debug: true\\` is passed to authMiddleware)`;\n};\n\nexport const authSignatureInvalid = `Clerk: Unable to verify request, this usually means the Clerk middleware did not run. Ensure Clerk's middleware is properly integrated and matches the current route. For more information, see: https://clerk.com/docs/nextjs/middleware. (code=auth_signature_invalid)`;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,MAAM,wBAAwB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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ptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var getCurrentUser_exports = {};
20
+ __export(getCurrentUser_exports, {
21
+ currentUser: () => currentUser
22
+ });
23
+ module.exports = __toCommonJS(getCurrentUser_exports);
24
+ var import_auth = require("./auth");
25
+ var import_http = require("../utils/http");
26
+ async function currentUser() {
27
+ const { userId } = (0, import_auth.auth)();
28
+ if (!userId)
29
+ return null;
30
+ return import_http.client.users.getUser(userId);
31
+ }
32
+ // Annotate the CommonJS export names for ESM import in node:
33
+ 0 && (module.exports = {
34
+ currentUser
35
+ });
36
+ //# sourceMappingURL=getCurrentUser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/server/getCurrentUser.ts"],"sourcesContent":["import { User } from '../types';\nimport { auth } from './auth';\nimport { client } from '../utils/http';\n\nexport async function currentUser(): Promise<User | null> {\n const { userId } = auth();\n if (!userId) return null;\n return client.users.getUser(userId);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,kBAAqB;AACrB,kBAAuB;AAEvB,eAAsB,cAAoC;AACxD,QAAM,EAAE,OAAO,QAAI,kBAAK;AACxB,MAAI,CAAC;AAAQ,WAAO;AACpB,SAAO,mBAAO,MAAM,QAAQ,MAAM;AACpC;","names":[]}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var server_exports = {};
20
+ __export(server_exports, {
21
+ auth: () => import_auth.auth,
22
+ createRouteMatcher: () => import_routeMatcher.createRouteMatcher
23
+ });
24
+ module.exports = __toCommonJS(server_exports);
25
+ var import_auth = require("./auth");
26
+ var import_routeMatcher = require("./routeMatcher");
27
+ // Annotate the CommonJS export names for ESM import in node:
28
+ 0 && (module.exports = {
29
+ auth,
30
+ createRouteMatcher
31
+ });
32
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/server/index.ts"],"sourcesContent":["export { auth } from './auth';\nexport { createRouteMatcher } from './routeMatcher';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAqB;AACrB,0BAAmC;","names":[]}
@@ -0,0 +1,193 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var middleware_exports = {};
20
+ __export(middleware_exports, {
21
+ authMiddleware: () => authMiddleware
22
+ });
23
+ module.exports = __toCommonJS(middleware_exports);
24
+ var import_server = require("next/server");
25
+ var import_constants = require("../constants");
26
+ var import_utils = require("./utils");
27
+ var import_client = require("./client");
28
+ var import_cabinIdRequest = require("../tokens/cabinIdRequest");
29
+ var import_protect = require("./protect");
30
+ var import_createRedirect = require("./createRedirect");
31
+ var import_response = require("../utils/response");
32
+ var import_serverRedirectWithAuth = require("./serverRedirectWithAuth");
33
+ const CONTROL_FLOW_ERROR = {
34
+ FORCE_NOT_FOUND: "CABIN_ID_PROTECT_REWRITE",
35
+ REDIRECT_TO_URL: "CABIN_ID_PROTECT_REDIRECT_TO_URL",
36
+ REDIRECT_TO_SIGN_IN: "CABIN_ID_PROTECT_REDIRECT_TO_SIGN_IN"
37
+ };
38
+ const setCookieWithDefaults = (response, name, value, options = {}) => {
39
+ response.cookies.set(name, value, {
40
+ maxAge: options.maxAge || 60 * 60 * 24 * 30,
41
+ // 30 days mặc định
42
+ sameSite: "lax",
43
+ secure: true
44
+ });
45
+ };
46
+ const parseRequestAndEvent = (args) => {
47
+ return [
48
+ args[0] instanceof Request ? args[0] : void 0,
49
+ args[0] instanceof Request ? args[1] : void 0
50
+ ];
51
+ };
52
+ const parseHandlerAndOptions = (args) => {
53
+ return [
54
+ typeof args[0] === "function" ? args[0] : void 0,
55
+ (args.length === 2 ? args[1] : typeof args[0] === "function" ? {} : args[0]) || {}
56
+ ];
57
+ };
58
+ const authMiddleware = (...args) => {
59
+ const [request, event] = parseRequestAndEvent(args);
60
+ const [handler, params] = parseHandlerAndOptions(args);
61
+ const publishableKey = (0, import_utils.assertKey)(
62
+ params.publishableKey || import_constants.PUBLISHABLE_KEY,
63
+ () => {
64
+ throw new Error("Publish Key is not exist");
65
+ }
66
+ );
67
+ const secretKey = (0, import_utils.assertKey)(params.secretKey || import_constants.SECRET_KEY, () => {
68
+ throw new Error("Secret Key is not valid");
69
+ });
70
+ const signInUrl = params.signInUrl || import_constants.SIGN_IN_URL;
71
+ const signUpUrl = params.signUpUrl || import_constants.SIGN_UP_URL;
72
+ const options = {
73
+ ...params,
74
+ publishableKey,
75
+ secretKey,
76
+ signInUrl,
77
+ signUpUrl
78
+ };
79
+ const nextMiddleware = async (_request, _event) => {
80
+ const accessToken = _request.nextUrl.searchParams.get(
81
+ import_constants.constants.QueryParams.Token
82
+ );
83
+ const userId = _request.nextUrl.searchParams.get(
84
+ import_constants.constants.QueryParams.UserId
85
+ );
86
+ if (accessToken && userId) {
87
+ const url = _request.nextUrl;
88
+ const path = url.pathname;
89
+ const response = import_server.NextResponse.redirect(
90
+ new URL(path || "/", _request.url)
91
+ );
92
+ setCookieWithDefaults(response, import_constants.constants.Cookies.Client, accessToken);
93
+ setCookieWithDefaults(response, import_constants.constants.Cookies.User, userId);
94
+ return response;
95
+ }
96
+ const cabinIdRequest = (0, import_cabinIdRequest.createCabinIdRequest)(_request);
97
+ const requestState = await import_client.cabinIdClient.authenticateRequest(
98
+ cabinIdRequest,
99
+ options
100
+ );
101
+ const authObject = requestState.toAuth();
102
+ const redirectToSignIn = createMiddlewareRedirectToSignIn(cabinIdRequest);
103
+ const protect = createMiddlewareProtect(
104
+ cabinIdRequest,
105
+ authObject,
106
+ redirectToSignIn
107
+ );
108
+ const authObjWithMethods = Object.assign(
109
+ authObject,
110
+ { protect, redirectToSignIn }
111
+ );
112
+ let handlerResult = import_server.NextResponse.next();
113
+ try {
114
+ handlerResult = await (handler == null ? void 0 : handler(() => authObjWithMethods, _request, _event)) || handlerResult;
115
+ } catch (e) {
116
+ handlerResult = handleControlFlowErrors(e, cabinIdRequest, requestState);
117
+ }
118
+ if ((0, import_response.isRedirect)(handlerResult)) {
119
+ return (0, import_serverRedirectWithAuth.serverRedirectWithAuth)(cabinIdRequest, handlerResult);
120
+ }
121
+ (0, import_utils.decorateRequest)(
122
+ cabinIdRequest,
123
+ handlerResult,
124
+ requestState,
125
+ options.secretKey
126
+ );
127
+ if (requestState.headers) {
128
+ requestState.headers.forEach((value, key) => {
129
+ handlerResult.headers.append(key, value);
130
+ });
131
+ }
132
+ return handlerResult;
133
+ };
134
+ if (request && event) {
135
+ return nextMiddleware(request, event);
136
+ }
137
+ return nextMiddleware;
138
+ };
139
+ const createMiddlewareRedirectToSignIn = (cabinIdRequest) => {
140
+ return (opts = {}) => {
141
+ const err = new Error(CONTROL_FLOW_ERROR.REDIRECT_TO_SIGN_IN);
142
+ err.returnBackUrl = opts.returnBackUrl === null ? "" : opts.returnBackUrl || cabinIdRequest.cabinIdUrl.toString();
143
+ throw err;
144
+ };
145
+ };
146
+ const createMiddlewareProtect = (cabinIdRequest, authObject, redirectToSignIn) => {
147
+ return (_, options) => {
148
+ const notFound = () => {
149
+ throw new Error(CONTROL_FLOW_ERROR.FORCE_NOT_FOUND);
150
+ };
151
+ const redirect = (url) => {
152
+ const err = new Error(CONTROL_FLOW_ERROR.REDIRECT_TO_URL);
153
+ err.redirectUrl = url;
154
+ throw err;
155
+ };
156
+ return (0, import_protect.createProtect)({
157
+ request: cabinIdRequest,
158
+ redirect,
159
+ notFound,
160
+ authObject,
161
+ redirectToSignIn
162
+ })(options);
163
+ };
164
+ };
165
+ const handleControlFlowErrors = (e, cabinIdRequest, requestState) => {
166
+ switch (e.message) {
167
+ case CONTROL_FLOW_ERROR.FORCE_NOT_FOUND:
168
+ return (0, import_response.setHeader)(
169
+ import_server.NextResponse.rewrite(
170
+ `${cabinIdRequest.cabinIdUrl.origin}/cabin_${Date.now()}`
171
+ ),
172
+ import_constants.constants.Headers.AuthReason,
173
+ "protect-rewrite"
174
+ );
175
+ case CONTROL_FLOW_ERROR.REDIRECT_TO_URL:
176
+ return (0, import_utils.redirectAdapter)(e.redirectUrl);
177
+ case CONTROL_FLOW_ERROR.REDIRECT_TO_SIGN_IN:
178
+ return (0, import_createRedirect.createRedirect)({
179
+ redirectAdapter: import_utils.redirectAdapter,
180
+ baseUrl: cabinIdRequest.cabinIdUrl,
181
+ signInUrl: requestState.signInUrl,
182
+ signUpUrl: requestState.signUpUrl,
183
+ publishableKey: requestState.publishableKey
184
+ }).redirectToSignIn({ returnBackUrl: e.returnBackUrl });
185
+ default:
186
+ throw e;
187
+ }
188
+ };
189
+ // Annotate the CommonJS export names for ESM import in node:
190
+ 0 && (module.exports = {
191
+ authMiddleware
192
+ });
193
+ //# sourceMappingURL=middleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/server/middleware.ts"],"sourcesContent":["import { NextMiddleware, NextResponse } from \"next/server\";\nimport {\n constants,\n PUBLISHABLE_KEY,\n SECRET_KEY,\n SIGN_IN_URL,\n SIGN_UP_URL,\n} from \"../constants\";\nimport { assertKey, decorateRequest, redirectAdapter } from \"./utils\";\nimport {\n NextMiddlewareEvtParam,\n NextMiddlewareRequestParam,\n NextMiddlewareReturn,\n} from \"./type\";\nimport { cabinIdClient } from \"./client\";\nimport { CabinIdRequest, createCabinIdRequest } from \"../tokens/cabinIdRequest\";\nimport { AuthProtect, createProtect } from \"./protect\";\nimport { createRedirect, RedirectFun } from \"./createRedirect\";\nimport { isRedirect, setHeader } from \"../utils/response\";\nimport { RequestState } from \"../tokens/authStatus\";\nimport { AuthObject } from \"../tokens/authObjects\";\nimport { serverRedirectWithAuth } from \"./serverRedirectWithAuth\";\nimport { AuthenticateRequestOptions } from \"../api/factory\";\n\nconst CONTROL_FLOW_ERROR = {\n FORCE_NOT_FOUND: \"CABIN_ID_PROTECT_REWRITE\",\n REDIRECT_TO_URL: \"CABIN_ID_PROTECT_REDIRECT_TO_URL\",\n REDIRECT_TO_SIGN_IN: \"CABIN_ID_PROTECT_REDIRECT_TO_SIGN_IN\",\n};\n\nexport type CabinIdMiddlewareAuthObject = AuthObject & {\n protect: AuthProtect;\n redirectToSignIn: RedirectFun<Response>;\n};\n\nexport type CabinIdMiddlewareAuth = () => CabinIdMiddlewareAuthObject;\n\nexport interface AuthMiddleware {\n /**\n * @example\n * export default clerkMiddleware((auth, request, event) => { ... }, options);\n */\n (\n handler: CabinIdMiddlewareHandler,\n options?: CabinIdMiddlewareOptions\n ): NextMiddleware;\n /**\n * @example\n * export default clerkMiddleware(options);\n */\n (options?: CabinIdMiddlewareOptions): NextMiddleware;\n /**\n * @example\n * export default clerkMiddleware;\n */\n (\n request: NextMiddlewareRequestParam,\n event: NextMiddlewareEvtParam\n ): NextMiddlewareReturn;\n}\n\ntype CabinIdMiddlewareHandler = (\n auth: CabinIdMiddlewareAuth,\n request: NextMiddlewareRequestParam,\n event: NextMiddlewareEvtParam\n) => NextMiddlewareReturn;\n\nexport type CabinIdMiddlewareOptions = AuthenticateRequestOptions;\n\n// Hàm tiện ích để thiết lập cookie với cấu hình mặc định\nconst setCookieWithDefaults = (\n response: NextResponse,\n name: string,\n value: string,\n options: { maxAge?: number } = {}\n) => {\n response.cookies.set(name, value, {\n maxAge: options.maxAge || 60 * 60 * 24 * 30, // 30 days mặc định\n sameSite: \"lax\",\n secure: true,\n });\n};\n\nconst parseRequestAndEvent = (args: unknown[]) => {\n return [\n args[0] instanceof Request ? args[0] : undefined,\n args[0] instanceof Request ? args[1] : undefined,\n ] as [\n NextMiddlewareRequestParam | undefined,\n NextMiddlewareEvtParam | undefined,\n ];\n};\n\nconst parseHandlerAndOptions = (args: unknown[]) => {\n return [\n typeof args[0] === \"function\" ? args[0] : undefined,\n (args.length === 2\n ? args[1]\n : typeof args[0] === \"function\"\n ? {}\n : args[0]) || {},\n ] as [CabinIdMiddlewareHandler | undefined, CabinIdMiddlewareOptions];\n};\n\nconst authMiddleware: AuthMiddleware = (...args: unknown[]): any => {\n const [request, event] = parseRequestAndEvent(args);\n const [handler, params] = parseHandlerAndOptions(args);\n\n const publishableKey = assertKey(\n params.publishableKey || PUBLISHABLE_KEY,\n () => {\n throw new Error(\"Publish Key is not exist\");\n }\n );\n const secretKey = assertKey(params.secretKey || SECRET_KEY, () => {\n throw new Error(\"Secret Key is not valid\");\n });\n\n const signInUrl = params.signInUrl || SIGN_IN_URL;\n const signUpUrl = params.signUpUrl || SIGN_UP_URL;\n\n const options = {\n ...params,\n publishableKey,\n secretKey,\n signInUrl,\n signUpUrl,\n };\n\n const nextMiddleware: NextMiddleware = async (_request, _event) => {\n const accessToken = _request.nextUrl.searchParams.get(\n constants.QueryParams.Token\n );\n const userId = _request.nextUrl.searchParams.get(\n constants.QueryParams.UserId\n );\n\n if (accessToken && userId) {\n const url = _request.nextUrl;\n const path = url.pathname;\n const response = NextResponse.redirect(\n new URL(path || \"/\", _request.url)\n );\n \n // Sử dụng hàm tiện ích để thiết lập cookie với sameSite=\"lax\" và secure=true\n setCookieWithDefaults(response, constants.Cookies.Client, accessToken);\n setCookieWithDefaults(response, constants.Cookies.User, userId);\n\n return response;\n }\n\n const cabinIdRequest = createCabinIdRequest(_request);\n\n const requestState = await cabinIdClient.authenticateRequest(\n cabinIdRequest,\n options\n );\n\n const authObject = requestState.toAuth();\n\n const redirectToSignIn = createMiddlewareRedirectToSignIn(cabinIdRequest);\n\n const protect = createMiddlewareProtect(\n cabinIdRequest,\n authObject,\n redirectToSignIn\n );\n\n const authObjWithMethods: CabinIdMiddlewareAuthObject = Object.assign(\n authObject,\n { protect, redirectToSignIn }\n );\n\n let handlerResult: Response = NextResponse.next();\n\n try {\n handlerResult =\n (await handler?.(() => authObjWithMethods, _request, _event)) ||\n handlerResult;\n } catch (e: any) {\n handlerResult = handleControlFlowErrors(e, cabinIdRequest, requestState);\n }\n\n if (isRedirect(handlerResult)) {\n return serverRedirectWithAuth(cabinIdRequest, handlerResult);\n }\n\n decorateRequest(\n cabinIdRequest,\n handlerResult,\n requestState,\n options.secretKey\n );\n\n if (requestState.headers) {\n requestState.headers.forEach((value, key) => {\n handlerResult.headers.append(key, value);\n });\n }\n\n return handlerResult;\n };\n\n if (request && event) {\n return nextMiddleware(request, event);\n }\n\n return nextMiddleware;\n};\n\nexport { authMiddleware };\n\nconst createMiddlewareRedirectToSignIn = (\n cabinIdRequest: CabinIdRequest\n): CabinIdMiddlewareAuthObject[\"redirectToSignIn\"] => {\n return (opts = {}) => {\n const err = new Error(CONTROL_FLOW_ERROR.REDIRECT_TO_SIGN_IN) as any;\n err.returnBackUrl =\n opts.returnBackUrl === null\n ? \"\"\n : opts.returnBackUrl || cabinIdRequest.cabinIdUrl.toString();\n throw err;\n };\n};\n\nconst createMiddlewareProtect = (\n cabinIdRequest: CabinIdRequest,\n authObject: AuthObject,\n redirectToSignIn: RedirectFun<Response>\n): CabinIdMiddlewareAuthObject[\"protect\"] => {\n return ((_: any, options: any) => {\n const notFound = () => {\n throw new Error(CONTROL_FLOW_ERROR.FORCE_NOT_FOUND) as any;\n };\n\n const redirect = (url: string) => {\n const err = new Error(CONTROL_FLOW_ERROR.REDIRECT_TO_URL) as any;\n err.redirectUrl = url;\n throw err;\n };\n\n return createProtect({\n request: cabinIdRequest,\n redirect,\n notFound,\n authObject,\n redirectToSignIn,\n })(options);\n }) as AuthProtect;\n};\n\nconst handleControlFlowErrors = (\n e: any,\n cabinIdRequest: CabinIdRequest,\n requestState: RequestState\n): Response => {\n switch (e.message) {\n case CONTROL_FLOW_ERROR.FORCE_NOT_FOUND:\n return setHeader(\n NextResponse.rewrite(\n `${cabinIdRequest.cabinIdUrl.origin}/cabin_${Date.now()}`\n ),\n constants.Headers.AuthReason,\n \"protect-rewrite\"\n );\n case CONTROL_FLOW_ERROR.REDIRECT_TO_URL:\n return redirectAdapter(e.redirectUrl);\n case CONTROL_FLOW_ERROR.REDIRECT_TO_SIGN_IN:\n return createRedirect({\n redirectAdapter,\n baseUrl: cabinIdRequest.cabinIdUrl,\n signInUrl: requestState.signInUrl,\n signUpUrl: requestState.signUpUrl,\n publishableKey: requestState.publishableKey,\n }).redirectToSignIn({ returnBackUrl: e.returnBackUrl });\n default:\n throw e;\n }\n};"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA6C;AAC7C,uBAMO;AACP,mBAA4D;AAM5D,oBAA8B;AAC9B,4BAAqD;AACrD,qBAA2C;AAC3C,4BAA4C;AAC5C,sBAAsC;AAGtC,oCAAuC;AAGvC,MAAM,qBAAqB;AAAA,EACzB,iBAAiB;AAAA,EACjB,iBAAiB;AAAA,EACjB,qBAAqB;AACvB;AA0CA,MAAM,wBAAwB,CAC5B,UACA,MACA,OACA,UAA+B,CAAC,MAC7B;AACH,WAAS,QAAQ,IAAI,MAAM,OAAO;AAAA,IAChC,QAAQ,QAAQ,UAAU,KAAK,KAAK,KAAK;AAAA;AAAA,IACzC,UAAU;AAAA,IACV,QAAQ;AAAA,EACV,CAAC;AACH;AAEA,MAAM,uBAAuB,CAAC,SAAoB;AAChD,SAAO;AAAA,IACL,KAAK,CAAC,aAAa,UAAU,KAAK,CAAC,IAAI;AAAA,IACvC,KAAK,CAAC,aAAa,UAAU,KAAK,CAAC,IAAI;AAAA,EACzC;AAIF;AAEA,MAAM,yBAAyB,CAAC,SAAoB;AAClD,SAAO;AAAA,IACL,OAAO,KAAK,CAAC,MAAM,aAAa,KAAK,CAAC,IAAI;AAAA,KACzC,KAAK,WAAW,IACb,KAAK,CAAC,IACN,OAAO,KAAK,CAAC,MAAM,aACnB,CAAC,IACD,KAAK,CAAC,MAAM,CAAC;AAAA,EACnB;AACF;AAEA,MAAM,iBAAiC,IAAI,SAAyB;AAClE,QAAM,CAAC,SAAS,KAAK,IAAI,qBAAqB,IAAI;AAClD,QAAM,CAAC,SAAS,MAAM,IAAI,uBAAuB,IAAI;AAErD,QAAM,qBAAiB;AAAA,IACrB,OAAO,kBAAkB;AA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