opensoma 0.5.1 → 0.7.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 (149) hide show
  1. package/dist/package.json +5 -1
  2. package/dist/src/agent-browser-launcher.d.ts +43 -0
  3. package/dist/src/agent-browser-launcher.d.ts.map +1 -0
  4. package/dist/src/agent-browser-launcher.js +97 -0
  5. package/dist/src/agent-browser-launcher.js.map +1 -0
  6. package/dist/src/cli.d.ts.map +1 -1
  7. package/dist/src/cli.js +8 -5
  8. package/dist/src/cli.js.map +1 -1
  9. package/dist/src/client.d.ts +34 -7
  10. package/dist/src/client.d.ts.map +1 -1
  11. package/dist/src/client.js +224 -52
  12. package/dist/src/client.js.map +1 -1
  13. package/dist/src/commands/agent-browser.d.ts +3 -0
  14. package/dist/src/commands/agent-browser.d.ts.map +1 -0
  15. package/dist/src/commands/agent-browser.js +27 -0
  16. package/dist/src/commands/agent-browser.js.map +1 -0
  17. package/dist/src/commands/auth.d.ts +1 -1
  18. package/dist/src/commands/auth.d.ts.map +1 -1
  19. package/dist/src/commands/auth.js +4 -2
  20. package/dist/src/commands/auth.js.map +1 -1
  21. package/dist/src/commands/dashboard.d.ts +13 -0
  22. package/dist/src/commands/dashboard.d.ts.map +1 -1
  23. package/dist/src/commands/dashboard.js +10 -18
  24. package/dist/src/commands/dashboard.js.map +1 -1
  25. package/dist/src/commands/helpers.d.ts +1 -1
  26. package/dist/src/commands/helpers.d.ts.map +1 -1
  27. package/dist/src/commands/helpers.js +2 -2
  28. package/dist/src/commands/helpers.js.map +1 -1
  29. package/dist/src/commands/index.d.ts +3 -1
  30. package/dist/src/commands/index.d.ts.map +1 -1
  31. package/dist/src/commands/index.js +3 -1
  32. package/dist/src/commands/index.js.map +1 -1
  33. package/dist/src/commands/mentoring.d.ts.map +1 -1
  34. package/dist/src/commands/mentoring.js +54 -29
  35. package/dist/src/commands/mentoring.js.map +1 -1
  36. package/dist/src/commands/notice.d.ts.map +1 -1
  37. package/dist/src/commands/notice.js +2 -1
  38. package/dist/src/commands/notice.js.map +1 -1
  39. package/dist/src/commands/report.d.ts.map +1 -1
  40. package/dist/src/commands/report.js +4 -2
  41. package/dist/src/commands/report.js.map +1 -1
  42. package/dist/src/commands/room.d.ts.map +1 -1
  43. package/dist/src/commands/room.js +125 -2
  44. package/dist/src/commands/room.js.map +1 -1
  45. package/dist/src/commands/schedule.d.ts +3 -0
  46. package/dist/src/commands/schedule.d.ts.map +1 -0
  47. package/dist/src/commands/schedule.js +27 -0
  48. package/dist/src/commands/schedule.js.map +1 -0
  49. package/dist/src/commands/team.d.ts.map +1 -1
  50. package/dist/src/commands/team.js +55 -4
  51. package/dist/src/commands/team.js.map +1 -1
  52. package/dist/src/commands/toz.d.ts +16 -0
  53. package/dist/src/commands/toz.d.ts.map +1 -0
  54. package/dist/src/commands/toz.js +488 -0
  55. package/dist/src/commands/toz.js.map +1 -0
  56. package/dist/src/constants.d.ts +5 -5
  57. package/dist/src/constants.d.ts.map +1 -1
  58. package/dist/src/constants.js +20 -8
  59. package/dist/src/constants.js.map +1 -1
  60. package/dist/src/credential-manager.d.ts +15 -0
  61. package/dist/src/credential-manager.d.ts.map +1 -1
  62. package/dist/src/credential-manager.js +46 -0
  63. package/dist/src/credential-manager.js.map +1 -1
  64. package/dist/src/formatters.d.ts +11 -3
  65. package/dist/src/formatters.d.ts.map +1 -1
  66. package/dist/src/formatters.js +281 -52
  67. package/dist/src/formatters.js.map +1 -1
  68. package/dist/src/http.d.ts +8 -0
  69. package/dist/src/http.d.ts.map +1 -1
  70. package/dist/src/http.js +29 -1
  71. package/dist/src/http.js.map +1 -1
  72. package/dist/src/index.d.ts +8 -1
  73. package/dist/src/index.d.ts.map +1 -1
  74. package/dist/src/index.js +4 -1
  75. package/dist/src/index.js.map +1 -1
  76. package/dist/src/session-recovery.js +2 -0
  77. package/dist/src/session-recovery.js.map +1 -1
  78. package/dist/src/shared/utils/swmaestro.d.ts +34 -1
  79. package/dist/src/shared/utils/swmaestro.d.ts.map +1 -1
  80. package/dist/src/shared/utils/swmaestro.js +102 -39
  81. package/dist/src/shared/utils/swmaestro.js.map +1 -1
  82. package/dist/src/shared/utils/team-action-params.d.ts +3 -0
  83. package/dist/src/shared/utils/team-action-params.d.ts.map +1 -0
  84. package/dist/src/shared/utils/team-action-params.js +10 -0
  85. package/dist/src/shared/utils/team-action-params.js.map +1 -0
  86. package/dist/src/shared/utils/team-params.d.ts +12 -0
  87. package/dist/src/shared/utils/team-params.d.ts.map +1 -0
  88. package/dist/src/shared/utils/team-params.js +38 -0
  89. package/dist/src/shared/utils/team-params.js.map +1 -0
  90. package/dist/src/toz-client.d.ts +89 -0
  91. package/dist/src/toz-client.d.ts.map +1 -0
  92. package/dist/src/toz-client.js +204 -0
  93. package/dist/src/toz-client.js.map +1 -0
  94. package/dist/src/toz-pending-store.d.ts +30 -0
  95. package/dist/src/toz-pending-store.d.ts.map +1 -0
  96. package/dist/src/toz-pending-store.js +36 -0
  97. package/dist/src/toz-pending-store.js.map +1 -0
  98. package/dist/src/types.d.ts +147 -10
  99. package/dist/src/types.d.ts.map +1 -1
  100. package/dist/src/types.js +74 -6
  101. package/dist/src/types.js.map +1 -1
  102. package/package.json +5 -1
  103. package/src/agent-browser-launcher.test.ts +263 -0
  104. package/src/agent-browser-launcher.ts +159 -0
  105. package/src/cli.ts +10 -5
  106. package/src/client.test.ts +673 -30
  107. package/src/client.ts +287 -67
  108. package/src/commands/agent-browser.ts +33 -0
  109. package/src/commands/auth.test.ts +77 -26
  110. package/src/commands/auth.ts +5 -3
  111. package/src/commands/dashboard.test.ts +57 -0
  112. package/src/commands/dashboard.ts +22 -19
  113. package/src/commands/helpers.test.ts +76 -25
  114. package/src/commands/helpers.ts +3 -3
  115. package/src/commands/index.ts +3 -1
  116. package/src/commands/mentoring.ts +60 -29
  117. package/src/commands/notice.ts +2 -1
  118. package/src/commands/report.ts +4 -2
  119. package/src/commands/room.ts +160 -1
  120. package/src/commands/schedule.ts +32 -0
  121. package/src/commands/team.ts +73 -5
  122. package/src/commands/toz.test.ts +51 -0
  123. package/src/commands/toz.ts +607 -0
  124. package/src/constants.ts +20 -8
  125. package/src/credential-manager.test.ts +98 -0
  126. package/src/credential-manager.ts +50 -0
  127. package/src/formatters.test.ts +528 -33
  128. package/src/formatters.ts +309 -55
  129. package/src/http.test.ts +71 -2
  130. package/src/http.ts +41 -2
  131. package/src/index.ts +23 -1
  132. package/src/session-recovery.ts +2 -0
  133. package/src/shared/utils/swmaestro.test.ts +245 -9
  134. package/src/shared/utils/swmaestro.ts +150 -47
  135. package/src/shared/utils/team-action-params.test.ts +32 -0
  136. package/src/shared/utils/team-action-params.ts +10 -0
  137. package/src/shared/utils/team-params.test.ts +141 -0
  138. package/src/shared/utils/team-params.ts +53 -0
  139. package/src/toz-client.test.ts +243 -0
  140. package/src/toz-client.ts +311 -0
  141. package/src/toz-pending-store.test.ts +91 -0
  142. package/src/toz-pending-store.ts +62 -0
  143. package/src/types.test.ts +26 -13
  144. package/src/types.ts +87 -7
  145. package/dist/src/commands/event.d.ts +0 -3
  146. package/dist/src/commands/event.d.ts.map +0 -1
  147. package/dist/src/commands/event.js +0 -58
  148. package/dist/src/commands/event.js.map +0 -1
  149. package/src/commands/event.ts +0 -73
@@ -66,6 +66,104 @@ describe('CredentialManager', () => {
66
66
  await expect(manager.getCredentials()).resolves.toBeNull()
67
67
  })
68
68
 
69
+ it('clearSessionState preserves username and password but wipes session fields', async () => {
70
+ const dir = await makeTempDir()
71
+ const manager = new CredentialManager(dir)
72
+
73
+ await manager.setCredentials({
74
+ sessionCookie: 'session-value',
75
+ csrfToken: 'csrf-value',
76
+ username: 'mentor@example.com',
77
+ password: 'secret-password',
78
+ tozName: 'Mentor One',
79
+ tozPhone: '010-1234-5678',
80
+ loggedInAt: '2026-04-09T00:00:00.000Z',
81
+ })
82
+
83
+ await manager.clearSessionState()
84
+
85
+ await expect(manager.getCredentials()).resolves.toEqual({
86
+ sessionCookie: '',
87
+ csrfToken: '',
88
+ username: 'mentor@example.com',
89
+ password: 'secret-password',
90
+ tozName: 'Mentor One',
91
+ tozPhone: '010-1234-5678',
92
+ })
93
+ })
94
+
95
+ it('clearSessionState removes the file when no recovery material is stored', async () => {
96
+ const dir = await makeTempDir()
97
+ const manager = new CredentialManager(dir)
98
+
99
+ await manager.setCredentials({
100
+ sessionCookie: 'session-value',
101
+ csrfToken: 'csrf-value',
102
+ })
103
+
104
+ await manager.clearSessionState()
105
+
106
+ await expect(manager.getCredentials()).resolves.toBeNull()
107
+ })
108
+
109
+ it('clearSessionState is a no-op when no credentials file exists', async () => {
110
+ const dir = await makeTempDir()
111
+ const manager = new CredentialManager(dir)
112
+
113
+ await expect(manager.clearSessionState()).resolves.toBeUndefined()
114
+ await expect(manager.getCredentials()).resolves.toBeNull()
115
+ })
116
+
117
+ it('setTozIdentity merges into existing credentials', async () => {
118
+ const dir = await makeTempDir()
119
+ const manager = new CredentialManager(dir)
120
+
121
+ await manager.setCredentials({
122
+ sessionCookie: 'session-value',
123
+ csrfToken: 'csrf-value',
124
+ })
125
+
126
+ await manager.setTozIdentity('Mentor One', '010-1234-5678')
127
+
128
+ await expect(manager.getCredentials()).resolves.toMatchObject({
129
+ sessionCookie: 'session-value',
130
+ csrfToken: 'csrf-value',
131
+ tozName: 'Mentor One',
132
+ tozPhone: '010-1234-5678',
133
+ })
134
+ await expect(manager.getTozIdentity()).resolves.toEqual({
135
+ name: 'Mentor One',
136
+ phone: '010-1234-5678',
137
+ })
138
+ })
139
+
140
+ it('setTozIdentity throws without SWMaestro credentials', async () => {
141
+ const dir = await makeTempDir()
142
+ const manager = new CredentialManager(dir)
143
+
144
+ await expect(manager.setTozIdentity('Mentor One', '010-1234-5678')).rejects.toThrow(/auth login/)
145
+ })
146
+
147
+ it('clearTozIdentity removes only toz fields', async () => {
148
+ const dir = await makeTempDir()
149
+ const manager = new CredentialManager(dir)
150
+
151
+ await manager.setCredentials({
152
+ sessionCookie: 'session-value',
153
+ csrfToken: 'csrf-value',
154
+ tozName: 'Mentor One',
155
+ tozPhone: '010-1234-5678',
156
+ })
157
+ await manager.clearTozIdentity()
158
+
159
+ const creds = await manager.getCredentials()
160
+ expect(creds?.tozName).toBeUndefined()
161
+ expect(creds?.tozPhone).toBeUndefined()
162
+ expect(creds?.sessionCookie).toBe('session-value')
163
+ expect(creds?.csrfToken).toBe('csrf-value')
164
+ await expect(manager.getTozIdentity()).resolves.toBeNull()
165
+ })
166
+
69
167
  it('preserves session credentials but drops the password when the encryption key is missing', async () => {
70
168
  const dir = await makeTempDir()
71
169
  const manager = new CredentialManager(dir)
@@ -76,6 +76,56 @@ export class CredentialManager {
76
76
  await rm(this.encryptionKeyPath, { force: true })
77
77
  }
78
78
 
79
+ /**
80
+ * Wipe ephemeral session fields (sessionCookie, csrfToken, loggedInAt) while
81
+ * preserving long-term material (username, password, TOZ identity). Used when
82
+ * the server-side session expired but we still want automatic recovery on the
83
+ * next run via `recoverSession()`.
84
+ *
85
+ * No-op when no credentials file exists or no recovery material is stored.
86
+ */
87
+ async clearSessionState(): Promise<void> {
88
+ const current = await this.getCredentials()
89
+ if (!current) {
90
+ return
91
+ }
92
+
93
+ if (!current.username && !current.password && !current.tozName && !current.tozPhone) {
94
+ await this.remove()
95
+ return
96
+ }
97
+
98
+ await this.setCredentials({
99
+ sessionCookie: '',
100
+ csrfToken: '',
101
+ username: current.username,
102
+ password: current.password,
103
+ tozName: current.tozName,
104
+ tozPhone: current.tozPhone,
105
+ })
106
+ }
107
+
108
+ async setTozIdentity(name: string, phone: string): Promise<void> {
109
+ const existing = await this.getCredentials()
110
+ if (!existing) {
111
+ throw new Error('SWMaestro credentials not found. Run: opensoma auth login first.')
112
+ }
113
+ await this.setCredentials({ ...existing, tozName: name, tozPhone: phone })
114
+ }
115
+
116
+ async clearTozIdentity(): Promise<void> {
117
+ const existing = await this.getCredentials()
118
+ if (!existing) return
119
+ const { tozName: _name, tozPhone: _phone, ...rest } = existing
120
+ await this.setCredentials(rest)
121
+ }
122
+
123
+ async getTozIdentity(): Promise<{ name: string; phone: string } | null> {
124
+ const creds = await this.getCredentials()
125
+ if (!creds?.tozName || !creds?.tozPhone) return null
126
+ return { name: creds.tozName, phone: creds.tozPhone }
127
+ }
128
+
79
129
  private async hydrateCredentials(credentials: StoredCredentials): Promise<Credentials> {
80
130
  if (!credentials.encryptedPassword) {
81
131
  return credentials