@molecule/api-resource-user 1.4.3 → 1.4.4
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.
- package/README.md +2 -2
- package/dist/handlers/del.d.ts +10 -3
- package/dist/handlers/del.d.ts.map +1 -1
- package/dist/handlers/del.js +28 -13
- package/dist/handlers/del.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@ AUTO-GENERATED — DO NOT EDIT THIS FILE.
|
|
|
3
3
|
Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
|
|
4
4
|
Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
|
|
5
5
|
To change this document, edit the module-level JSDoc in src/index.ts.
|
|
6
|
-
Generated: 2026-
|
|
6
|
+
Generated: 2026-10-04T04:10:08.619Z
|
|
7
7
|
-->
|
|
8
8
|
|
|
9
9
|
# @molecule/api-resource-user
|
|
@@ -537,7 +537,7 @@ Members:
|
|
|
537
537
|
- `handlers.verifyPayment` — function: Generic payment verification handler that works with any bonded PaymentProvider. Reads the
|
|
538
538
|
- `handlers.CreateRequest` — interface: Request body for user creation, including password and optional device name.
|
|
539
539
|
- `handlers.create` — function: Creates a user with username and password. Validates username uniqueness and email format,
|
|
540
|
-
- `handlers.del` — function: Deletes a user and their associated data.
|
|
540
|
+
- `handlers.del` — function: Deletes a user and their associated data. Deletes the user row FIRST, then
|
|
541
541
|
- `handlers.ForgotPasswordRequest` — interface: Request body for password reset initiation.
|
|
542
542
|
- `handlers.forgotPassword` — function: Generates a UUID password reset token, stores it in the secrets table, and sends a reset
|
|
543
543
|
- `handlers.LogInRequest` — interface: Request body for user login, supporting password, reset token, and 2FA flows.
|
package/dist/handlers/del.d.ts
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import type { MoleculeRequest } from '@molecule/api-resource';
|
|
2
2
|
import type * as types from '../types.js';
|
|
3
3
|
/**
|
|
4
|
-
* Deletes a user and their associated data.
|
|
5
|
-
* devices via the bonded DeviceService
|
|
6
|
-
*
|
|
4
|
+
* Deletes a user and their associated data. Deletes the user row FIRST, then
|
|
5
|
+
* the secrets, the devices (via the bonded DeviceService) and the payment
|
|
6
|
+
* records (via the bonded PaymentRecordService).
|
|
7
|
+
*
|
|
8
|
+
* The row goes first so that a failed delete changes nothing: deleting the
|
|
9
|
+
* secrets first meant a row delete that then failed left an account with no
|
|
10
|
+
* password hash — no password sign-in, and a retried delete that no longer
|
|
11
|
+
* asks for one. When the row delete fails nothing else has been touched; when
|
|
12
|
+
* it succeeds, a failure in the clean-up after it leaves records that belong
|
|
13
|
+
* to no account (logged), never an account without its password.
|
|
7
14
|
* @param resource - The user resource configuration (name, tableName, schema).
|
|
8
15
|
* @param resource.name - The resource name.
|
|
9
16
|
* @param resource.tableName - The database table name for users.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"del.d.ts","sourceRoot":"","sources":["../../src/handlers/del.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAG7D,OAAO,KAAK,KAAK,KAAK,MAAM,aAAa,CAAA;AAKzC
|
|
1
|
+
{"version":3,"file":"del.d.ts","sourceRoot":"","sources":["../../src/handlers/del.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAG7D,OAAO,KAAK,KAAK,KAAK,MAAM,aAAa,CAAA;AAKzC;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,GAAG,GAAI,6CAA6C,KAAK,CAAC,QAAQ,MAC/D,KAAK,eAAe;;;;;;;;;;;;;;;;EAmDnC,CAAA"}
|
package/dist/handlers/del.js
CHANGED
|
@@ -5,9 +5,16 @@ import { invalidateAllDeviceExistsCache } from '../authorization.js';
|
|
|
5
5
|
const analytics = getAnalytics();
|
|
6
6
|
const logger = getLogger();
|
|
7
7
|
/**
|
|
8
|
-
* Deletes a user and their associated data.
|
|
9
|
-
* devices via the bonded DeviceService
|
|
10
|
-
*
|
|
8
|
+
* Deletes a user and their associated data. Deletes the user row FIRST, then
|
|
9
|
+
* the secrets, the devices (via the bonded DeviceService) and the payment
|
|
10
|
+
* records (via the bonded PaymentRecordService).
|
|
11
|
+
*
|
|
12
|
+
* The row goes first so that a failed delete changes nothing: deleting the
|
|
13
|
+
* secrets first meant a row delete that then failed left an account with no
|
|
14
|
+
* password hash — no password sign-in, and a retried delete that no longer
|
|
15
|
+
* asks for one. When the row delete fails nothing else has been touched; when
|
|
16
|
+
* it succeeds, a failure in the clean-up after it leaves records that belong
|
|
17
|
+
* to no account (logged), never an account without its password.
|
|
11
18
|
* @param resource - The user resource configuration (name, tableName, schema).
|
|
12
19
|
* @param resource.name - The resource name.
|
|
13
20
|
* @param resource.tableName - The database table name for users.
|
|
@@ -18,6 +25,14 @@ export const del = ({ name: _name, tableName, schema: _schema }) => {
|
|
|
18
25
|
return async (req) => {
|
|
19
26
|
try {
|
|
20
27
|
const id = req.params.id;
|
|
28
|
+
// Delete the user row first — see the note above.
|
|
29
|
+
const result = await deleteById(tableName, id);
|
|
30
|
+
if (!result?.affected) {
|
|
31
|
+
return {
|
|
32
|
+
statusCode: 404,
|
|
33
|
+
body: { error: t('user.error.notFound'), errorKey: 'user.error.notFound' },
|
|
34
|
+
};
|
|
35
|
+
}
|
|
21
36
|
// Delete secrets.
|
|
22
37
|
await deleteById(`${tableName}Secrets`, id).catch((err) => {
|
|
23
38
|
logger.warn('Failed to delete user secrets', { userId: id, error: err });
|
|
@@ -25,18 +40,18 @@ export const del = ({ name: _name, tableName, schema: _schema }) => {
|
|
|
25
40
|
// Delete devices via bond, then evict this process's positive
|
|
26
41
|
// device-exists cache so any in-flight token for a just-deleted device is
|
|
27
42
|
// rejected on its very next request (immediate in-process revocation).
|
|
28
|
-
|
|
43
|
+
// Evicted even if the bond call fails: the user row is already gone.
|
|
44
|
+
try {
|
|
45
|
+
await get('device')?.deleteByUserId(id);
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
logger.warn('Failed to delete user devices', { userId: id, error: err });
|
|
49
|
+
}
|
|
29
50
|
invalidateAllDeviceExistsCache();
|
|
30
51
|
// Delete payments via bond.
|
|
31
|
-
await get('paymentRecords')?.deleteByUserId(id)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if (!result?.affected) {
|
|
35
|
-
return {
|
|
36
|
-
statusCode: 404,
|
|
37
|
-
body: { error: t('user.error.notFound'), errorKey: 'user.error.notFound' },
|
|
38
|
-
};
|
|
39
|
-
}
|
|
52
|
+
await Promise.resolve(get('paymentRecords')?.deleteByUserId(id)).catch((err) => {
|
|
53
|
+
logger.warn('Failed to delete user payment records', { userId: id, error: err });
|
|
54
|
+
});
|
|
40
55
|
analytics.track({ name: 'user.deleted', userId: id }).catch(() => { });
|
|
41
56
|
return { statusCode: 200, body: { props: { id } } };
|
|
42
57
|
}
|
package/dist/handlers/del.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"del.js","sourceRoot":"","sources":["../../src/handlers/del.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AACjE,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACnD,OAAO,EAAE,CAAC,EAAE,MAAM,oBAAoB,CAAA;AAItC,OAAO,EAAE,8BAA8B,EAAE,MAAM,qBAAqB,CAAA;AAGpE,MAAM,SAAS,GAAG,YAAY,EAAE,CAAA;AAChC,MAAM,MAAM,GAAG,SAAS,EAAE,CAAA;AAE1B
|
|
1
|
+
{"version":3,"file":"del.js","sourceRoot":"","sources":["../../src/handlers/del.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AACjE,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA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