@mspkapps/auth-client 0.1.5 → 0.1.6

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/AuthClient.js +54 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mspkapps/auth-client",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "Lightweight client for Your Auth Service",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
package/src/AuthClient.js CHANGED
@@ -34,8 +34,8 @@ export class AuthClient {
34
34
 
35
35
  // ---------- storage helpers ----------
36
36
  _load(key) { if (!this.storage) return null; try { return this.storage.getItem(key); } catch { return null; } }
37
- _save(key, val) { if (!this.storage) return; try { this.storage.setItem(key, val); } catch {} }
38
- _clear(key) { if (!this.storage) return; try { this.storage.removeItem(key); } catch {} }
37
+ _save(key, val) { if (!this.storage) return; try { this.storage.setItem(key, val); } catch { } }
38
+ _clear(key) { if (!this.storage) return; try { this.storage.removeItem(key); } catch { } }
39
39
 
40
40
  // ---------- internal builders ----------
41
41
  _buildUrl(path) {
@@ -92,16 +92,63 @@ export class AuthClient {
92
92
  return json;
93
93
  }
94
94
 
95
- async getProfile() {
96
- const resp = await this.fetch(this._buildUrl('auth/user/profile'), {
97
- method: 'GET',
98
- headers: this._headers()
95
+ async requestPasswordReset({ email }) {
96
+ const resp = await this.fetch(this._buildUrl('auth/request-password-reset'), {
97
+ method: 'POST',
98
+ headers: this._headers(),
99
+ body: JSON.stringify({ email })
100
+ });
101
+ const json = await safeJson(resp);
102
+ if (!resp.ok || json?.success === false) throw toError(resp, json, 'Password reset request failed');
103
+ return json;
104
+ }
105
+
106
+ async changePassword({ currentPassword, newPassword }) {
107
+ const resp = await this.fetch(this._buildUrl('auth/change-password'), {
108
+ method: 'POST',
109
+ headers: this._headers(),
110
+ body: JSON.stringify({ current_password: currentPassword, new_password: newPassword })
111
+ });
112
+ const json = await safeJson(resp);
113
+ if (!resp.ok || json?.success === false) throw toError(resp, json, 'Change password failed');
114
+ return json;
115
+ }
116
+
117
+ async resendVerificationEmail({ email, purpose }) {
118
+ // purpose: 'New Account' | 'Password change' | 'Profile Edit'
119
+ const resp = await this.fetch(this._buildUrl('auth/resend-verification'), {
120
+ method: 'POST',
121
+ headers: this._headers(),
122
+ body: JSON.stringify({ email, purpose })
99
123
  });
100
124
  const json = await safeJson(resp);
101
- if (!resp.ok || json?.success === false) throw toError(resp, json, 'Profile failed');
125
+ if (!resp.ok || json?.success === false) throw toError(resp, json, 'Resend verification failed');
102
126
  return json;
103
127
  }
104
128
 
129
+ async deleteAccount({ email, password }) {
130
+ const resp = await this.fetch(this._buildUrl('auth/delete-account'), {
131
+ method: 'POST',
132
+ headers: this._headers(),
133
+ body: JSON.stringify({ email, password })
134
+ });
135
+ const json = await safeJson(resp);
136
+ if (!resp.ok || json?.success === false) throw toError(resp, json, 'Delete account failed');
137
+ return json;
138
+ }
139
+
140
+
141
+
142
+ // async getProfile() {
143
+ // const resp = await this.fetch(this._buildUrl('user/profile'), {
144
+ // method: 'GET',
145
+ // headers: this._headers()
146
+ // });
147
+ // const json = await safeJson(resp);
148
+ // if (!resp.ok || json?.success === false) throw toError(resp, json, 'Profile failed');
149
+ // return json;
150
+ // }
151
+
105
152
  // Generic authorized call for extra endpoints
106
153
  async authed(path, { method = 'GET', body, headers } = {}) {
107
154
  const resp = await this.fetch(this._buildUrl(path), {