@nlabs/metropolisjs 0.1.1 → 0.2.0

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 (326) hide show
  1. package/.github/copilot-instructions.md +167 -0
  2. package/AGENTS.md +13 -0
  3. package/CHANGELOG.md +112 -0
  4. package/GRAPHQL_VALIDATION_RESULTS.md +158 -0
  5. package/PERMISSION_GRAPHQL_INTEGRATION.md +293 -0
  6. package/PERMISSION_IMPLEMENTATION_SUMMARY.md +243 -0
  7. package/README.md +1343 -0
  8. package/SIGNIN_GRAPHQL_VALIDATION.md +125 -0
  9. package/VAULT_GRAPHQL_API_FINDINGS.md +312 -0
  10. package/docs/ACTIONS.md +63 -0
  11. package/docs/COLLECTIONS.md +1038 -0
  12. package/docs/CONNECTIONS.md +1367 -0
  13. package/docs/CRUD_INTEGRATION.md +702 -0
  14. package/examples/connections-usage.tsx +909 -0
  15. package/examples/content-actions-usage.ts +144 -0
  16. package/examples/crud-usage.tsx +847 -0
  17. package/examples/extensibility-usage.tsx +889 -0
  18. package/examples/factory-pattern-usage.ts +283 -0
  19. package/examples/i18n-import-examples.ts +86 -0
  20. package/examples/i18n-namespace-usage.ts +118 -0
  21. package/examples/i18next-singleton-demo.ts +187 -0
  22. package/examples/permission-system-usage.tsx +415 -0
  23. package/examples/project-details.tsx +397 -0
  24. package/examples/shared-i18n-usage.tsx +203 -0
  25. package/examples/signup-error-handling.ts +100 -0
  26. package/examples/translation-types.ts +86 -0
  27. package/examples/translation-usage.tsx +336 -0
  28. package/factoryPatternGuide.md +244 -0
  29. package/index.js +1 -0
  30. package/jest.config.mjs +28 -0
  31. package/lex.config.mjs +26 -0
  32. package/lib/__tests__/e2e/helpers/testGraphQLServer.d.ts +22 -0
  33. package/lib/__tests__/e2e/helpers/testGraphQLServer.d.ts.map +1 -0
  34. package/lib/__tests__/e2e/helpers/testGraphQLServer.js +197 -0
  35. package/lib/__tests__/e2e/helpers/testGraphQLServerSimple.d.ts +3 -0
  36. package/lib/__tests__/e2e/helpers/testGraphQLServerSimple.d.ts.map +1 -0
  37. package/lib/__tests__/e2e/helpers/testGraphQLServerSimple.js +52 -0
  38. package/lib/actions/appActions/appActions.d.ts +29 -0
  39. package/lib/actions/appActions/appActions.d.ts.map +1 -0
  40. package/lib/actions/appActions/appActions.js +159 -0
  41. package/lib/actions/connectionActions/connectionActions.d.ts +19 -0
  42. package/lib/actions/connectionActions/connectionActions.d.ts.map +1 -0
  43. package/lib/actions/connectionActions/connectionActions.js +131 -0
  44. package/lib/actions/contentActions/contentActions.d.ts +34 -0
  45. package/lib/actions/contentActions/contentActions.d.ts.map +1 -0
  46. package/lib/actions/contentActions/contentActions.js +314 -0
  47. package/lib/actions/conversationActions/conversationActions.d.ts +30 -0
  48. package/lib/actions/conversationActions/conversationActions.d.ts.map +1 -0
  49. package/lib/actions/conversationActions/conversationActions.js +225 -0
  50. package/lib/actions/eventActions/eventActions.d.ts +65 -0
  51. package/lib/actions/eventActions/eventActions.d.ts.map +1 -0
  52. package/lib/actions/eventActions/eventActions.js +436 -0
  53. package/lib/actions/groupActions/groupActions.d.ts +30 -0
  54. package/lib/actions/groupActions/groupActions.d.ts.map +1 -0
  55. package/lib/actions/groupActions/groupActions.js +229 -0
  56. package/lib/actions/imageActions/imageActions.d.ts +62 -0
  57. package/lib/actions/imageActions/imageActions.d.ts.map +1 -0
  58. package/lib/actions/imageActions/imageActions.js +593 -0
  59. package/lib/actions/index.d.ts +21 -0
  60. package/lib/actions/index.d.ts.map +1 -0
  61. package/lib/actions/index.js +22 -0
  62. package/lib/actions/locationActions/locationActions.d.ts +60 -0
  63. package/lib/actions/locationActions/locationActions.d.ts.map +1 -0
  64. package/lib/actions/locationActions/locationActions.js +388 -0
  65. package/lib/actions/messageActions/messageActions.d.ts +38 -0
  66. package/lib/actions/messageActions/messageActions.d.ts.map +1 -0
  67. package/lib/actions/messageActions/messageActions.js +235 -0
  68. package/lib/actions/permissionActions/permissionActions.d.ts +34 -0
  69. package/lib/actions/permissionActions/permissionActions.d.ts.map +1 -0
  70. package/lib/actions/permissionActions/permissionActions.js +330 -0
  71. package/lib/actions/personaActions/personaActions.d.ts +65 -0
  72. package/lib/actions/personaActions/personaActions.d.ts.map +1 -0
  73. package/lib/actions/personaActions/personaActions.js +572 -0
  74. package/lib/actions/postActions/postActions.d.ts +36 -0
  75. package/lib/actions/postActions/postActions.d.ts.map +1 -0
  76. package/lib/actions/postActions/postActions.js +447 -0
  77. package/lib/actions/reactionActions/reactionActions.d.ts +38 -0
  78. package/lib/actions/reactionActions/reactionActions.d.ts.map +1 -0
  79. package/lib/actions/reactionActions/reactionActions.js +413 -0
  80. package/lib/actions/sseActions/sseActions.d.ts +38 -0
  81. package/lib/actions/sseActions/sseActions.d.ts.map +1 -0
  82. package/lib/actions/sseActions/sseActions.js +148 -0
  83. package/lib/actions/subscriptionActions/subscriptionActions.d.ts +24 -0
  84. package/lib/actions/subscriptionActions/subscriptionActions.d.ts.map +1 -0
  85. package/lib/actions/subscriptionActions/subscriptionActions.js +329 -0
  86. package/lib/actions/tagActions/tagActions.d.ts +37 -0
  87. package/lib/actions/tagActions/tagActions.d.ts.map +1 -0
  88. package/lib/actions/tagActions/tagActions.js +347 -0
  89. package/lib/actions/translationActions/translationActions.d.ts +38 -0
  90. package/lib/actions/translationActions/translationActions.d.ts.map +1 -0
  91. package/lib/actions/translationActions/translationActions.js +189 -0
  92. package/lib/actions/userActions/userActions.d.ts +78 -0
  93. package/lib/actions/userActions/userActions.d.ts.map +1 -0
  94. package/lib/actions/userActions/userActions.js +844 -0
  95. package/lib/actions/videoActions/videoActions.d.ts +41 -0
  96. package/lib/actions/videoActions/videoActions.d.ts.map +1 -0
  97. package/lib/actions/videoActions/videoActions.js +532 -0
  98. package/lib/actions/websocketActions/websocketActions.d.ts +30 -0
  99. package/lib/actions/websocketActions/websocketActions.d.ts.map +1 -0
  100. package/lib/actions/websocketActions/websocketActions.js +377 -0
  101. package/lib/adapters/appAdapter/appAdapter.d.ts +8 -0
  102. package/lib/adapters/appAdapter/appAdapter.d.ts.map +1 -0
  103. package/lib/adapters/appAdapter/appAdapter.js +90 -0
  104. package/lib/adapters/arangoAdapter/arangoAdapter.d.ts +21 -0
  105. package/lib/adapters/arangoAdapter/arangoAdapter.d.ts.map +1 -0
  106. package/lib/adapters/arangoAdapter/arangoAdapter.js +75 -0
  107. package/lib/adapters/contentAdapter/contentAdapter.d.ts +32 -0
  108. package/lib/adapters/contentAdapter/contentAdapter.d.ts.map +1 -0
  109. package/lib/adapters/contentAdapter/contentAdapter.js +107 -0
  110. package/lib/adapters/conversationAdapter/conversationAdapter.d.ts +24 -0
  111. package/lib/adapters/conversationAdapter/conversationAdapter.d.ts.map +1 -0
  112. package/lib/adapters/conversationAdapter/conversationAdapter.js +75 -0
  113. package/lib/adapters/eventAdapter/eventAdapter.d.ts +46 -0
  114. package/lib/adapters/eventAdapter/eventAdapter.d.ts.map +1 -0
  115. package/lib/adapters/eventAdapter/eventAdapter.js +162 -0
  116. package/lib/adapters/fileAdapter/fileAdapter.d.ts +30 -0
  117. package/lib/adapters/fileAdapter/fileAdapter.d.ts.map +1 -0
  118. package/lib/adapters/fileAdapter/fileAdapter.js +118 -0
  119. package/lib/adapters/groupAdapter/groupAdapter.d.ts +28 -0
  120. package/lib/adapters/groupAdapter/groupAdapter.d.ts.map +1 -0
  121. package/lib/adapters/groupAdapter/groupAdapter.js +66 -0
  122. package/lib/adapters/imageAdapter/imageAdapter.d.ts +38 -0
  123. package/lib/adapters/imageAdapter/imageAdapter.d.ts.map +1 -0
  124. package/lib/adapters/imageAdapter/imageAdapter.js +134 -0
  125. package/lib/adapters/index.d.ts +34 -0
  126. package/lib/adapters/index.d.ts.map +1 -0
  127. package/lib/adapters/index.js +19 -0
  128. package/lib/adapters/locationAdapter/locationAdapter.d.ts +28 -0
  129. package/lib/adapters/locationAdapter/locationAdapter.d.ts.map +1 -0
  130. package/lib/adapters/locationAdapter/locationAdapter.js +95 -0
  131. package/lib/adapters/messageAdapter/messageAdapter.d.ts +31 -0
  132. package/lib/adapters/messageAdapter/messageAdapter.d.ts.map +1 -0
  133. package/lib/adapters/messageAdapter/messageAdapter.js +82 -0
  134. package/lib/adapters/permissionAdapter/permissionAdapter.d.ts +41 -0
  135. package/lib/adapters/permissionAdapter/permissionAdapter.d.ts.map +1 -0
  136. package/lib/adapters/permissionAdapter/permissionAdapter.js +120 -0
  137. package/lib/adapters/personaAdapter/personaAdapter.d.ts +44 -0
  138. package/lib/adapters/personaAdapter/personaAdapter.d.ts.map +1 -0
  139. package/lib/adapters/personaAdapter/personaAdapter.js +161 -0
  140. package/lib/adapters/postAdapter/postAdapter.d.ts +33 -0
  141. package/lib/adapters/postAdapter/postAdapter.d.ts.map +1 -0
  142. package/lib/adapters/postAdapter/postAdapter.js +115 -0
  143. package/lib/adapters/reactionAdapter/reactionAdapter.d.ts +23 -0
  144. package/lib/adapters/reactionAdapter/reactionAdapter.d.ts.map +1 -0
  145. package/lib/adapters/reactionAdapter/reactionAdapter.js +81 -0
  146. package/lib/adapters/reaktorAdapter/reaktorAdapter.d.ts +17 -0
  147. package/lib/adapters/reaktorAdapter/reaktorAdapter.d.ts.map +1 -0
  148. package/lib/adapters/reaktorAdapter/reaktorAdapter.js +58 -0
  149. package/lib/adapters/sessionAdapter/sessionAdapter.d.ts +24 -0
  150. package/lib/adapters/sessionAdapter/sessionAdapter.d.ts.map +1 -0
  151. package/lib/adapters/sessionAdapter/sessionAdapter.js +80 -0
  152. package/lib/adapters/tagAdapter/tagAdapter.d.ts +21 -0
  153. package/lib/adapters/tagAdapter/tagAdapter.d.ts.map +1 -0
  154. package/lib/adapters/tagAdapter/tagAdapter.js +98 -0
  155. package/lib/adapters/translationAdapter/translationAdapter.d.ts +21 -0
  156. package/lib/adapters/translationAdapter/translationAdapter.d.ts.map +1 -0
  157. package/lib/adapters/translationAdapter/translationAdapter.js +55 -0
  158. package/lib/adapters/userAdapter/userAdapter.d.ts +67 -0
  159. package/lib/adapters/userAdapter/userAdapter.d.ts.map +1 -0
  160. package/lib/adapters/userAdapter/userAdapter.js +302 -0
  161. package/lib/adapters/videoAdapter/videoAdapter.d.ts +8 -0
  162. package/lib/adapters/videoAdapter/videoAdapter.d.ts.map +1 -0
  163. package/lib/adapters/videoAdapter/videoAdapter.js +194 -0
  164. package/lib/config/index.d.ts +44 -0
  165. package/lib/config/index.d.ts.map +1 -0
  166. package/lib/config/index.js +97 -0
  167. package/lib/constants/Collections.d.ts +44 -0
  168. package/lib/constants/Collections.d.ts.map +1 -0
  169. package/lib/constants/Collections.js +40 -0
  170. package/lib/constants/MetropolisConstants.d.ts +15 -0
  171. package/lib/constants/MetropolisConstants.d.ts.map +1 -0
  172. package/lib/constants/MetropolisConstants.js +15 -0
  173. package/lib/graphql/message.d.ts +3 -0
  174. package/lib/graphql/message.d.ts.map +1 -0
  175. package/lib/graphql/message.js +20 -0
  176. package/lib/graphql/notification.d.ts +3 -0
  177. package/lib/graphql/notification.d.ts.map +1 -0
  178. package/lib/graphql/notification.js +20 -0
  179. package/lib/graphql/session.d.ts +2 -0
  180. package/lib/graphql/session.d.ts.map +1 -0
  181. package/lib/graphql/session.js +17 -0
  182. package/lib/index.d.ts +52 -0
  183. package/lib/index.d.ts.map +1 -0
  184. package/lib/index.js +248 -0
  185. package/lib/stores/appStore.d.ts +23 -0
  186. package/lib/stores/appStore.d.ts.map +1 -0
  187. package/lib/stores/appStore.js +23 -0
  188. package/lib/stores/contentStore.d.ts +36 -0
  189. package/lib/stores/contentStore.d.ts.map +1 -0
  190. package/lib/stores/contentStore.js +139 -0
  191. package/lib/stores/conversationStore.d.ts +38 -0
  192. package/lib/stores/conversationStore.d.ts.map +1 -0
  193. package/lib/stores/conversationStore.js +117 -0
  194. package/lib/stores/eventStore.d.ts +37 -0
  195. package/lib/stores/eventStore.d.ts.map +1 -0
  196. package/lib/stores/eventStore.js +47 -0
  197. package/lib/stores/groupStore.d.ts +37 -0
  198. package/lib/stores/groupStore.d.ts.map +1 -0
  199. package/lib/stores/groupStore.js +68 -0
  200. package/lib/stores/imageStore.d.ts +40 -0
  201. package/lib/stores/imageStore.d.ts.map +1 -0
  202. package/lib/stores/imageStore.js +53 -0
  203. package/lib/stores/index.d.ts +24 -0
  204. package/lib/stores/index.d.ts.map +1 -0
  205. package/lib/stores/index.js +24 -0
  206. package/lib/stores/locationStore.d.ts +34 -0
  207. package/lib/stores/locationStore.d.ts.map +1 -0
  208. package/lib/stores/locationStore.js +42 -0
  209. package/lib/stores/messageStore.d.ts +51 -0
  210. package/lib/stores/messageStore.d.ts.map +1 -0
  211. package/lib/stores/messageStore.js +137 -0
  212. package/lib/stores/notificationStore.d.ts +33 -0
  213. package/lib/stores/notificationStore.d.ts.map +1 -0
  214. package/lib/stores/notificationStore.js +55 -0
  215. package/lib/stores/permissionStore.d.ts +37 -0
  216. package/lib/stores/permissionStore.d.ts.map +1 -0
  217. package/lib/stores/permissionStore.js +117 -0
  218. package/lib/stores/personaStore.d.ts +26 -0
  219. package/lib/stores/personaStore.d.ts.map +1 -0
  220. package/lib/stores/personaStore.js +118 -0
  221. package/lib/stores/postStore.d.ts +34 -0
  222. package/lib/stores/postStore.d.ts.map +1 -0
  223. package/lib/stores/postStore.js +53 -0
  224. package/lib/stores/reactionStore.d.ts +25 -0
  225. package/lib/stores/reactionStore.d.ts.map +1 -0
  226. package/lib/stores/reactionStore.js +28 -0
  227. package/lib/stores/subscriptionStore.d.ts +41 -0
  228. package/lib/stores/subscriptionStore.d.ts.map +1 -0
  229. package/lib/stores/subscriptionStore.js +85 -0
  230. package/lib/stores/tagStore.d.ts +34 -0
  231. package/lib/stores/tagStore.d.ts.map +1 -0
  232. package/lib/stores/tagStore.js +87 -0
  233. package/lib/stores/translationStore.d.ts +42 -0
  234. package/lib/stores/translationStore.d.ts.map +1 -0
  235. package/lib/stores/translationStore.js +122 -0
  236. package/lib/stores/userStore.d.ts +74 -0
  237. package/lib/stores/userStore.d.ts.map +1 -0
  238. package/lib/stores/userStore.js +319 -0
  239. package/lib/stores/videoStore.d.ts +39 -0
  240. package/lib/stores/videoStore.d.ts.map +1 -0
  241. package/lib/stores/videoStore.js +132 -0
  242. package/lib/stores/websocketStore.d.ts +24 -0
  243. package/lib/stores/websocketStore.d.ts.map +1 -0
  244. package/lib/stores/websocketStore.js +51 -0
  245. package/lib/types/apps.types.d.ts +17 -0
  246. package/lib/types/apps.types.d.ts.map +1 -0
  247. package/lib/types/apps.types.js +6 -0
  248. package/lib/types/common.types.d.ts +31 -0
  249. package/lib/types/common.types.d.ts.map +1 -0
  250. package/lib/types/common.types.js +6 -0
  251. package/lib/types/conversations.types.d.ts +17 -0
  252. package/lib/types/conversations.types.d.ts.map +1 -0
  253. package/lib/types/conversations.types.js +6 -0
  254. package/lib/types/edges.types.d.ts +38 -0
  255. package/lib/types/edges.types.d.ts.map +1 -0
  256. package/lib/types/edges.types.js +6 -0
  257. package/lib/types/groups.types.d.ts +19 -0
  258. package/lib/types/groups.types.d.ts.map +1 -0
  259. package/lib/types/groups.types.js +6 -0
  260. package/lib/types/index.d.ts +12 -0
  261. package/lib/types/index.d.ts.map +1 -0
  262. package/lib/types/index.js +12 -0
  263. package/lib/types/subscriptions.types.d.ts +32 -0
  264. package/lib/types/subscriptions.types.d.ts.map +1 -0
  265. package/lib/types/subscriptions.types.js +6 -0
  266. package/lib/types/videos.types.d.ts +61 -0
  267. package/lib/types/videos.types.d.ts.map +1 -0
  268. package/lib/types/videos.types.js +6 -0
  269. package/lib/utils/MetropolisProvider.d.ts +58 -0
  270. package/lib/utils/MetropolisProvider.d.ts.map +1 -0
  271. package/lib/utils/MetropolisProvider.js +31 -0
  272. package/lib/utils/actionFactory.d.ts +24 -0
  273. package/lib/utils/actionFactory.d.ts.map +1 -0
  274. package/lib/utils/actionFactory.js +95 -0
  275. package/lib/utils/api.d.ts +44 -0
  276. package/lib/utils/api.d.ts.map +1 -0
  277. package/lib/utils/api.js +253 -0
  278. package/lib/utils/app.d.ts +7 -0
  279. package/lib/utils/app.d.ts.map +1 -0
  280. package/lib/utils/app.js +15 -0
  281. package/lib/utils/baseActionFactory.d.ts +16 -0
  282. package/lib/utils/baseActionFactory.d.ts.map +1 -0
  283. package/lib/utils/baseActionFactory.js +72 -0
  284. package/lib/utils/configUtils.d.ts +11 -0
  285. package/lib/utils/configUtils.d.ts.map +1 -0
  286. package/lib/utils/configUtils.js +20 -0
  287. package/lib/utils/dateUtils.d.ts +3 -0
  288. package/lib/utils/dateUtils.d.ts.map +1 -0
  289. package/lib/utils/dateUtils.js +11 -0
  290. package/lib/utils/file.d.ts +3 -0
  291. package/lib/utils/file.d.ts.map +1 -0
  292. package/lib/utils/file.js +156 -0
  293. package/lib/utils/i18n.d.ts +7 -0
  294. package/lib/utils/i18n.d.ts.map +1 -0
  295. package/lib/utils/i18n.js +96 -0
  296. package/lib/utils/index.d.ts +20 -0
  297. package/lib/utils/index.d.ts.map +1 -0
  298. package/lib/utils/index.js +26 -0
  299. package/lib/utils/location.d.ts +10 -0
  300. package/lib/utils/location.d.ts.map +1 -0
  301. package/lib/utils/location.js +82 -0
  302. package/lib/utils/permissionUtils.d.ts +22 -0
  303. package/lib/utils/permissionUtils.d.ts.map +1 -0
  304. package/lib/utils/permissionUtils.js +72 -0
  305. package/lib/utils/requestCache.d.ts +8 -0
  306. package/lib/utils/requestCache.d.ts.map +1 -0
  307. package/lib/utils/requestCache.js +53 -0
  308. package/lib/utils/session.d.ts +14 -0
  309. package/lib/utils/session.d.ts.map +1 -0
  310. package/lib/utils/session.js +107 -0
  311. package/lib/utils/useConversationTyping.d.ts +26 -0
  312. package/lib/utils/useConversationTyping.d.ts.map +1 -0
  313. package/lib/utils/useConversationTyping.js +117 -0
  314. package/lib/utils/useMetropolis.d.ts +67 -0
  315. package/lib/utils/useMetropolis.d.ts.map +1 -0
  316. package/lib/utils/useMetropolis.js +311 -0
  317. package/lib/utils/useTranslations.d.ts +16 -0
  318. package/lib/utils/useTranslations.d.ts.map +1 -0
  319. package/lib/utils/useTranslations.js +105 -0
  320. package/lib/utils/validatorFactory.d.ts +49 -0
  321. package/lib/utils/validatorFactory.d.ts.map +1 -0
  322. package/lib/utils/validatorFactory.js +95 -0
  323. package/package.json +75 -28
  324. package/temp_signin.ts +73 -0
  325. package/tsconfig.lint.json +25 -0
  326. package/tsconfig.test.json +14 -0
@@ -0,0 +1,167 @@
1
+ # MetropolisJS AI Coding Assistant Instructions
2
+
3
+ ## Project Overview
4
+ MetropolisJS is a React library that provides seamless frontend-backend integration for applications using Reaktor backend services and ArkhamJS state management. It handles authentication, real-time messaging, content management, and social features through a unified API.
5
+
6
+ ## Architecture Patterns
7
+
8
+ ### Core Components
9
+ - **Stores**: ArkhamJS-based state management with domain-specific stores (`users`, `posts`, `messages`, etc.)
10
+ - **Actions**: Factory function pattern using `createUserActions(flux)`, `createPostActions(flux)`, etc.
11
+ - **Adapters**: Zod-validated data parsers for API responses (`parseUser`, `parsePost`, etc.)
12
+ - **Configuration**: Environment-specific config objects with API endpoints, WebSocket URLs, and session settings
13
+
14
+ ### Key Conventions
15
+
16
+ #### 1. Action Creation Pattern
17
+ ```typescript
18
+ // Correct: Use factory functions
19
+ import {createUserActions} from '@nlabs/metropolisjs';
20
+ const userActions = createUserActions(flux);
21
+
22
+ // Avoid: Direct instantiation
23
+ const userActions = new UserActions(flux);
24
+ ```
25
+
26
+ #### 2. GraphQL Mutation Structure
27
+ All GraphQL mutations are wrapped in domain fields:
28
+ ```graphql
29
+ mutation UsersSignIn($user: UserInput!, $expires: Int) {
30
+ users {
31
+ signIn(user: $user, expires: $expires) {
32
+ token
33
+ expires
34
+ }
35
+ }
36
+ }
37
+ ```
38
+
39
+ #### 3. Store Constants Pattern
40
+ Each store defines action type constants:
41
+ ```typescript
42
+ export const USER_CONSTANTS = {
43
+ SIGN_IN_SUCCESS: 'USER_SIGN_IN_SUCCESS',
44
+ SIGN_IN_ERROR: 'USER_SIGN_IN_ERROR',
45
+ // ... etc
46
+ };
47
+ ```
48
+
49
+ #### 4. Adapter Validation
50
+ Use Zod schemas for data validation in adapters:
51
+ ```typescript
52
+ import {z} from 'zod';
53
+ const userSchema = z.object({
54
+ id: z.string(),
55
+ email: z.string().email(),
56
+ // ...
57
+ });
58
+ ```
59
+
60
+ ## Development Workflow
61
+
62
+ ### Build Commands
63
+ - `npm run build` - Compile TypeScript to `lib/` using @nlabs/lex
64
+ - `npm run dev` - Development build with watch mode
65
+ - `npm run test` - Run Jest tests with @nlabs/lex configuration
66
+ - `npm run lint` - ESLint with auto-fix using @nlabs/lex
67
+
68
+ ### Testing Setup
69
+ - Uses Jest with jsdom environment
70
+ - Tests located in `__tests__/` directories alongside source
71
+ - Mock setup in `__mocks__/` for external dependencies
72
+
73
+ ### TypeScript Configuration
74
+ - Strict mode disabled (`"strict": false`)
75
+ - ESNext modules with bundler resolution
76
+ - Declaration files emitted to `lib/` directory
77
+
78
+ ## Coding Conventions
79
+
80
+ ### Comments
81
+ - Do not write comments in code except for TODOs, copyrights, and lint disables
82
+ - Variables and code should be self-explanatory with clear, descriptive names
83
+ - Use meaningful variable names that explain their purpose
84
+ - Structure code to be readable without additional comments
85
+
86
+ ## Integration Points
87
+
88
+ ### External Dependencies
89
+ - **@nlabs/arkhamjs**: State management framework
90
+ - **@nlabs/arkhamjs-utils-react**: React hooks for ArkhamJS
91
+ - **i18next**: Internationalization
92
+ - **sockette**: WebSocket client
93
+ - **zod**: Schema validation
94
+
95
+ ### Real-time Features
96
+ - WebSocket connections via `websocketStore`
97
+ - Server-Sent Events (SSE) for notifications
98
+ - Automatic reconnection and state synchronization
99
+
100
+ ### Authentication Flow
101
+ - Session management through `user.session` state
102
+ - Token refresh via `refreshSession()` API calls
103
+ - Environment-specific auth checks via config
104
+
105
+ ## Code Organization
106
+
107
+ ### Directory Structure
108
+ ```
109
+ src/
110
+ ├── actions/ # Factory-based action creators
111
+ ├── adapters/ # Data parsing and validation
112
+ ├── stores/ # ArkhamJS store definitions
113
+ ├── config/ # Environment configuration
114
+ ├── utils/ # Shared utilities (API, i18n, etc.)
115
+ └── constants/ # Application constants
116
+ ```
117
+
118
+ ### File Naming
119
+ - Actions: `userActions.ts`, `postActions.ts`
120
+ - Stores: `userStore.ts`, `postStore.ts`
121
+ - Adapters: `userAdapter.ts`, `postAdapter.ts`
122
+ - Tests: `userActions.test.ts` alongside implementation
123
+
124
+ ## Common Patterns
125
+
126
+ ### Error Handling
127
+ ```typescript
128
+ try {
129
+ const result = await userActions.signIn({username, password});
130
+ // Handle success
131
+ } catch (error) {
132
+ // Error dispatched to store with *_ERROR constant
133
+ console.error('Sign in failed:', error);
134
+ }
135
+ ```
136
+
137
+ ### State Access
138
+ ```typescript
139
+ import {useFlux} from '@nlabs/arkhamjs-utils-react';
140
+
141
+ const MyComponent = () => {
142
+ const flux = useFlux();
143
+ const user = flux.getState('user.item', {});
144
+ // ...
145
+ };
146
+ ```
147
+
148
+ ### Custom Adapters
149
+ ```typescript
150
+ const customUserAdapter = (input: unknown) => {
151
+ const user = parseUser(input); // Use default parser first
152
+ // Add custom business logic
153
+ return {...user, computedField: 'value'};
154
+ };
155
+
156
+ const userActions = createUserActions(flux, {
157
+ userAdapter: customUserAdapter
158
+ });
159
+ ```
160
+
161
+ ## Key Files to Reference
162
+ - `src/index.tsx` - Main library exports and Metropolis component
163
+ - `src/stores/index.ts` - All store exports
164
+ - `src/actions/index.ts` - All action exports
165
+ - `src/adapters/index.ts` - All adapter exports
166
+ - `src/utils/api.ts` - GraphQL API utilities
167
+ - `factoryPatternGuide.md` - Detailed factory pattern documentation
package/AGENTS.md ADDED
@@ -0,0 +1,13 @@
1
+ # AGENTS.md
2
+
3
+ ## Core Rule
4
+ - Treat shared data contracts as strict and canonical.
5
+ - Do not add legacy aliases, compatibility shims, fallback field names, or dual-write behavior.
6
+
7
+ ## Required Patterns
8
+ - When a shared contract changes, update MetropolisJS to the canonical field names and update callers instead of supporting both shapes.
9
+ - Keep API payloads aligned with the current Reaktor schema.
10
+
11
+ ## Prohibited Patterns
12
+ - No temporary backward-compatibility layers for field renames.
13
+ - No adapters that emit both old and new field names for the same value.
package/CHANGELOG.md ADDED
@@ -0,0 +1,112 @@
1
+ # Changelog
2
+
3
+ ## Architecture Modernization (2025)
4
+
5
+ MetropolisJS has undergone a comprehensive three-phase refactoring to align with React best practices, improve type safety, and enhance developer experience.
6
+
7
+ ### Phase 1: Context-Based Configuration ✅
8
+
9
+ **Status:** Complete (Backward Compatible)
10
+
11
+ - Added `resolveEnvironmentConfig()` utility for environment-specific config resolution
12
+ - Enhanced `MetropolisContext` with `config` and `flux` properties
13
+ - Created `useMetropolisConfig()` and `useMetropolisFlux()` hooks
14
+ - Configuration now available through React Context
15
+ - Global `Config` class still works for backward compatibility
16
+
17
+ **New Features:**
18
+ - `useMetropolisConfig()` - Access config from React context
19
+ - `useMetropolisFlux()` - Access flux instance from context
20
+ - `resolveEnvironmentConfig()` - Resolve environment-specific configuration
21
+
22
+ ### Phase 2: Selective Action Creation & Specialized Hooks ✅
23
+
24
+ **Status:** Complete (Backward Compatible)
25
+
26
+ - Added selective action creation: `useMetropolis(['user', 'post'])`
27
+ - Created 12 specialized hooks for individual action types
28
+ - Improved type safety by removing `as any` casts
29
+ - Better performance through selective action creation
30
+
31
+ **New Features:**
32
+ - `useUserActions()` - User management actions only
33
+ - `usePostActions()` - Post management actions only
34
+ - `useMessageActions()` - Messaging actions only
35
+ - `useEventActions()` - Event management actions only
36
+ - `useImageActions()` - Image handling actions only
37
+ - `useLocationActions()` - Location services actions only
38
+ - `useReactionActions()` - Reaction actions only
39
+ - `useTagActions()` - Tag management actions only
40
+ - `useContentActions()` - Content management actions only
41
+ - `usePersonaActions()` - Persona management actions only
42
+ - `useTranslationActions()` - Translation actions only
43
+ - `useWebsocketActions()` - WebSocket actions only
44
+ - Selective creation: `useMetropolis(['user', 'post'])`
45
+
46
+ **Performance Improvements:**
47
+ - Only creates actions you need
48
+ - Better tree-shaking opportunities
49
+ - More efficient memoization
50
+
51
+ ### Phase 3: Remove Global Config Singleton ✅
52
+
53
+ **Status:** Complete (Breaking Changes)
54
+
55
+ - Removed global `Config.set()` from Metropolis component
56
+ - Config now stored in flux state (`app.config`)
57
+ - Created `getConfigFromFlux()` utility for non-React code
58
+ - Deprecated `Config.get()` and `Config.set()` with warnings
59
+ - `useMetropolisConfig()` now requires Metropolis context
60
+
61
+ **Breaking Changes:**
62
+ - `useMetropolisConfig()` throws error if used outside Metropolis component
63
+ - `Config.get()` and `Config.set()` are deprecated (show warnings)
64
+ - Configuration must be passed to `<Metropolis>` component
65
+
66
+ **Migration Required:**
67
+ - React components: Use `useMetropolisConfig()` instead of `Config.get()`
68
+ - Non-React code: Use `getConfigFromFlux(flux)` instead of `Config.get()`
69
+ - Ensure components are wrapped with `<Metropolis>` provider
70
+
71
+ ## Summary of Changes
72
+
73
+ ### New Hooks
74
+
75
+ 1. **Configuration Hooks:**
76
+ - `useMetropolisConfig()` - Get configuration from context
77
+ - `useMetropolisFlux()` - Get flux instance from context
78
+
79
+ 2. **Specialized Action Hooks:**
80
+ - `useUserActions()`
81
+ - `usePostActions()`
82
+ - `useMessageActions()`
83
+ - `useEventActions()`
84
+ - `useImageActions()`
85
+ - `useLocationActions()`
86
+ - `useReactionActions()`
87
+ - `useTagActions()`
88
+ - `useContentActions()`
89
+ - `usePersonaActions()`
90
+ - `useTranslationActions()`
91
+ - `useWebsocketActions()`
92
+
93
+ ### Enhanced Features
94
+
95
+ - **Selective Action Creation:** `useMetropolis(['user', 'post'])`
96
+ - **Context-Based Configuration:** No global state
97
+ - **Type Safety:** Removed `as any` casts
98
+ - **Better Performance:** Only create needed actions
99
+
100
+ ### Deprecated APIs
101
+
102
+ - `Config.get()` - Use `useMetropolisConfig()` or `getConfigFromFlux(flux)`
103
+ - `Config.set()` - Pass config to `<Metropolis>` component
104
+
105
+ ### New Utilities
106
+
107
+ - `getConfigFromFlux(flux)` - Get config from flux state (for non-React code)
108
+ - `resolveEnvironmentConfig(config)` - Resolve environment-specific config
109
+
110
+ ## Migration Guide
111
+
112
+ See the [README.md](./README.md) for detailed migration examples and usage patterns.
@@ -0,0 +1,158 @@
1
+ # GraphQL SignIn Validation - Complete Analysis
2
+
3
+ ## Summary
4
+
5
+ ✅ **Client Code Status:** CORRECT
6
+ ✅ **Unit Tests Created:** 10 tests, all PASSING
7
+ 🔴 **Server Issue:** GraphQL schema missing `users` field on `Mutation` type
8
+
9
+ ## Test Results
10
+
11
+ When running `npm test src/utils/api.signin.test.ts`, all tests pass:
12
+
13
+ ```
14
+ PASS @nlabs/lex src/utils/api.signin.test.ts
15
+
16
+ SignIn GraphQL Mutation Generation
17
+ createMutation with signIn
18
+ ✓ should generate correct mutation shape with users wrapper (18 ms)
19
+ ✓ should generate mutation with correct GraphQL syntax structure
20
+ ✓ should handle signIn with only required parameters (1 ms)
21
+ ✓ should create complete signin mutation payload
22
+ refreshSession mutation
23
+ ✓ should generate correct refreshSession mutation (1 ms)
24
+ signUp mutation
25
+ ✓ should generate correct signUp mutation with users wrapper (1 ms)
26
+ API Response Handler
27
+ ✓ should correctly extract signIn session from users wrapper
28
+ ✓ should handle missing users wrapper gracefully
29
+ ✓ should handle nested data extraction for other mutations
30
+ Expected Server GraphQL Schema
31
+ ✓ should document the expected Mutation type structure for server implementation
32
+
33
+ Test Suites: 1 passed, 1 total
34
+ Tests: 10 passed, 10 total
35
+ ```
36
+
37
+ ## Test Coverage
38
+
39
+ ### 1. Mutation Generation Tests ✅
40
+
41
+ Tests verify that the `createMutation()` function generates the correct GraphQL structure:
42
+
43
+ **Generated SignIn Mutation:**
44
+ ```graphql
45
+ mutation UsersSignIn($expires: Int, $password: String!, $username: String!) {
46
+ users {
47
+ signIn(expires: $expires, password: $password, username: $username) {
48
+ expires
49
+ issued
50
+ token
51
+ userId
52
+ username
53
+ }
54
+ }
55
+ }
56
+ ```
57
+
58
+ **Generated RefreshSession Mutation:**
59
+ ```graphql
60
+ mutation UsersRefreshSession($expires: Int, $token: String!) {
61
+ users {
62
+ refreshSession(expires: $expires, token: $token) {
63
+ expires
64
+ issued
65
+ token
66
+ }
67
+ }
68
+ }
69
+ ```
70
+
71
+ **Generated SignUp Mutation:**
72
+ ```graphql
73
+ mutation UsersSignUp($user: UserInput!) {
74
+ users {
75
+ signUp(user: $user) {
76
+ userId
77
+ username
78
+ }
79
+ }
80
+ }
81
+ ```
82
+
83
+ ### 2. Response Handler Tests ✅
84
+
85
+ Tests verify correct data extraction from nested response structure:
86
+
87
+ - ✅ `data.users.signIn` is correctly extracted
88
+ - ✅ Missing wrapper is handled gracefully
89
+ - ✅ Other mutations follow the same pattern: `data.{collection}.{method}`
90
+
91
+ ### 3. Schema Documentation ✅
92
+
93
+ Tests document the expected server GraphQL schema structure needed to support these mutations.
94
+
95
+ ## What Needs to be Fixed on Server
96
+
97
+ The server at `/Users/nitrog7/Development/vault` must have this schema structure:
98
+
99
+ ```graphql
100
+ type Mutation {
101
+ users: UsersMutation!
102
+ }
103
+
104
+ type UsersMutation {
105
+ signIn(username: String!, password: String!, expires: Int): Session
106
+ signUp(user: UserInput!): User
107
+ update(user: UserUpdateInput!): User
108
+ updateProfile(profile: ProfileUpdateInput!): Profile
109
+ refreshSession(token: String!, expires: Int): Session
110
+ confirmCode(code: Int!, type: String!, value: String!): Boolean
111
+ remove(userId: String!): User
112
+ session(user: UserInput!): User
113
+ itemById(userId: String!): User
114
+ }
115
+
116
+ type Session {
117
+ token: String!
118
+ expires: Int
119
+ issued: Int
120
+ userId: String
121
+ username: String
122
+ }
123
+ ```
124
+
125
+ ## Client-Side Architecture
126
+
127
+ The metropolisjs library uses a **collection-type wrapper pattern** for all GraphQL mutations:
128
+
129
+ | Collection | Mutations | Response |
130
+ |-----------|-----------|----------|
131
+ | `users` | signIn, signUp, update, refreshSession, ... | `data.users.{method}` |
132
+ | `posts` | add, delete, update, ... | `data.posts.{method}` |
133
+ | `contents` | add, delete, update, ... | `data.contents.{method}` |
134
+ | `reactions` | addReaction, deleteReaction | `data.reactions.{method}` |
135
+
136
+ This is intentional and consistent across the codebase.
137
+
138
+ ## Files
139
+
140
+ - **Test File:** [src/utils/api.signin.test.ts](../src/utils/api.signin.test.ts)
141
+ - **API Implementation:** [src/utils/api.ts](../src/utils/api.ts)
142
+ - **User Actions:** [src/actions/userActions/userActions.ts](../src/actions/userActions/userActions.ts)
143
+
144
+ ## Next Steps
145
+
146
+ 1. ✅ Client-side validation complete
147
+ 2. ⏳ Update server GraphQL schema at `/Users/nitrog7/Development/vault`
148
+ 3. ⏳ Verify signin mutation works with updated schema
149
+ 4. ⏳ Run full integration tests
150
+
151
+ ## How to Run Tests
152
+
153
+ ```bash
154
+ cd /Users/nitrog7/Development/metropolisjs
155
+ npm test -- src/utils/api.signin.test.ts
156
+ ```
157
+
158
+ All tests pass with the Lex test runner configured in `lex.config.mjs`.