@flowerforce/flowerbase 1.4.2-beta.6 → 1.5.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,27 @@
1
+ ## 1.5.0 (2026-01-26)
2
+
3
+
4
+ ### 🚀 Features
5
+
6
+ - add trigger auth LOGOUT ([970f2c7](https://github.com/flowerforce/flowerbase/commit/970f2c7))
7
+
8
+
9
+ ### 🩹 Fixes
10
+
11
+ - response error in functions ([557941e](https://github.com/flowerforce/flowerbase/commit/557941e))
12
+
13
+ - add error AccountNameInUse ([e0162c1](https://github.com/flowerforce/flowerbase/commit/e0162c1))
14
+
15
+ - update aws lib ([6fa5144](https://github.com/flowerforce/flowerbase/commit/6fa5144))
16
+
17
+ - add unique email auth and schema email password ([d650d0b](https://github.com/flowerforce/flowerbase/commit/d650d0b))
18
+
19
+ - add options mongod methods ([1f4bbcd](https://github.com/flowerforce/flowerbase/commit/1f4bbcd))
20
+
21
+ - change status code FunctionExecutionError ([6ae17c8](https://github.com/flowerforce/flowerbase/commit/6ae17c8))
22
+
23
+ - add delete auth user method ([353c030](https://github.com/flowerforce/flowerbase/commit/353c030))
24
+
1
25
  ## 1.4.1 (2026-01-16)
2
26
 
3
27
 
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/auth/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAEzC,QAAA,MAAM,IAAI,EAAE,eAMX,CAAA;AAED,eAAe,IAAI,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/auth/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAEzC,QAAA,MAAM,IAAI,EAAE,eAOX,CAAA;AAED,eAAe,IAAI,CAAA"}
@@ -3,11 +3,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ const handleUserDeletion_1 = __importDefault(require("../../shared/handleUserDeletion"));
6
7
  const handleUserRegistration_1 = __importDefault(require("../../shared/handleUserRegistration"));
7
8
  const Auth = (app, opt) => {
8
9
  return {
9
10
  emailPasswordAuth: {
10
- registerUser: (0, handleUserRegistration_1.default)(app, opt)
11
+ registerUser: (0, handleUserRegistration_1.default)(app, opt),
12
+ deleteUser: (0, handleUserDeletion_1.default)(app, opt)
11
13
  }
12
14
  };
13
15
  };
@@ -1,8 +1,10 @@
1
1
  import { FastifyInstance } from "fastify/types/instance";
2
+ import handleUserDeletion from "../../../src/shared/handleUserDeletion";
2
3
  import handleUserRegistration from "../../../src/shared/handleUserRegistration";
3
4
  import { Options } from "../../shared/models/handleUserRegistration.model";
4
5
  type EmailPasswordAuth = {
5
6
  registerUser: ReturnType<typeof handleUserRegistration>;
7
+ deleteUser: ReturnType<typeof handleUserDeletion>;
6
8
  };
7
9
  type AuthMethods = {
8
10
  emailPasswordAuth: EmailPasswordAuth;
@@ -1 +1 @@
1
- {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../../src/services/auth/model.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,sBAAsB,MAAM,4CAA4C,CAAA;AAC/E,OAAO,EAAE,OAAO,EAAE,MAAM,kDAAkD,CAAA;AAE1E,KAAK,iBAAiB,GAAG;IACrB,YAAY,EAAE,UAAU,CAAC,OAAO,sBAAsB,CAAC,CAAA;CAC1D,CAAA;AAED,KAAK,WAAW,GAAG;IACf,iBAAiB,EAAE,iBAAiB,CAAA;CACvC,CAAA;AAED,MAAM,MAAM,eAAe,GAAG,CAAC,GAAG,EAAE,eAAe,EAAE,OAAO,EAAE,OAAO,KAAK,WAAW,CAAA"}
1
+ {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../../src/services/auth/model.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,kBAAkB,MAAM,wCAAwC,CAAA;AACvE,OAAO,sBAAsB,MAAM,4CAA4C,CAAA;AAC/E,OAAO,EAAE,OAAO,EAAE,MAAM,kDAAkD,CAAA;AAE1E,KAAK,iBAAiB,GAAG;IACrB,YAAY,EAAE,UAAU,CAAC,OAAO,sBAAsB,CAAC,CAAA;IACvD,UAAU,EAAE,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAA;CACpD,CAAA;AAED,KAAK,WAAW,GAAG;IACf,iBAAiB,EAAE,iBAAiB,CAAA;CACvC,CAAA;AAED,MAAM,MAAM,eAAe,GAAG,CAAC,GAAG,EAAE,eAAe,EAAE,OAAO,EAAE,OAAO,KAAK,WAAW,CAAA"}
@@ -0,0 +1,11 @@
1
+ import { HandleUserDeletion } from "./models/handleUserDeletion.model";
2
+ /**
3
+ * Delete user
4
+ *
5
+ * @param {FastifyInstance} app The Fastify instance.
6
+ * @param {Object} [opt] The options from the context
7
+ * @returns {Promise<DeleteResult>} A promise resolving to the result of the delete operation.
8
+ */
9
+ declare const handleUserDeletion: HandleUserDeletion;
10
+ export default handleUserDeletion;
11
+ //# sourceMappingURL=handleUserDeletion.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handleUserDeletion.d.ts","sourceRoot":"","sources":["../../src/shared/handleUserDeletion.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAA;AAEtE;;;;;;GAMG;AACH,QAAA,MAAM,kBAAkB,EAAE,kBA8BzB,CAAA;AAED,eAAe,kBAAkB,CAAA"}
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const bson_1 = require("bson");
13
+ const constants_1 = require("../constants");
14
+ /**
15
+ * Delete user
16
+ *
17
+ * @param {FastifyInstance} app The Fastify instance.
18
+ * @param {Object} [opt] The options from the context
19
+ * @returns {Promise<DeleteResult>} A promise resolving to the result of the delete operation.
20
+ */
21
+ const handleUserDeletion = (app, opt) => (_a) => __awaiter(void 0, [_a], void 0, function* ({ id, email }) {
22
+ const { run_as_system } = opt !== null && opt !== void 0 ? opt : {};
23
+ if (!run_as_system) {
24
+ throw new Error('only run_as_system');
25
+ }
26
+ if (!id && !email) {
27
+ throw new Error('Missing user identifier');
28
+ }
29
+ const { authCollection } = constants_1.AUTH_CONFIG;
30
+ const mongo = app === null || app === void 0 ? void 0 : app.mongo;
31
+ const db = mongo.client.db(constants_1.DB_NAME);
32
+ const collection = db.collection(authCollection);
33
+ let query;
34
+ if (id) {
35
+ let parsedId = id;
36
+ try {
37
+ parsedId = new bson_1.ObjectId(id);
38
+ }
39
+ catch (_b) {
40
+ parsedId = id;
41
+ }
42
+ query = { _id: parsedId };
43
+ }
44
+ else {
45
+ query = { email };
46
+ }
47
+ return collection.deleteOne(query);
48
+ });
49
+ exports.default = handleUserDeletion;
@@ -0,0 +1,10 @@
1
+ import { FastifyInstance } from "fastify/types/instance";
2
+ import { DeleteResult } from "mongodb";
3
+ import { Options } from "./handleUserRegistration.model";
4
+ type DeleteUserParams = {
5
+ id?: string;
6
+ email?: string;
7
+ };
8
+ export type HandleUserDeletion = (app: FastifyInstance, opt: Options) => (params: DeleteUserParams) => Promise<DeleteResult>;
9
+ export {};
10
+ //# sourceMappingURL=handleUserDeletion.model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handleUserDeletion.model.d.ts","sourceRoot":"","sources":["../../../src/shared/models/handleUserDeletion.model.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAA;AAExD,KAAK,gBAAgB,GAAG;IACtB,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAED,MAAM,MAAM,kBAAkB,GAAG,CAC/B,GAAG,EAAE,eAAe,EACpB,GAAG,EAAE,OAAO,KACT,CAAC,MAAM,EAAE,gBAAgB,KAAK,OAAO,CAAC,YAAY,CAAC,CAAA"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -24,10 +24,10 @@ export declare const generateContextData: ({ user, services, app, rules, current
24
24
  method?: string | undefined;
25
25
  url?: string | undefined;
26
26
  host?: string | undefined;
27
+ id?: string | undefined;
27
28
  ips?: string[];
28
29
  hostname?: string | undefined;
29
30
  ip?: string | undefined;
30
- id?: string | undefined;
31
31
  };
32
32
  user: unknown;
33
33
  environment: {
@@ -167,6 +167,7 @@ export declare const generateContextData: ({ user, services, app, rules, current
167
167
  } | {
168
168
  emailPasswordAuth: {
169
169
  registerUser: ReturnType<import("../../shared/models/handleUserRegistration.model").HandleUserRegistration>;
170
+ deleteUser: ReturnType<import("../../shared/models/handleUserDeletion.model").HandleUserDeletion>;
170
171
  };
171
172
  } | undefined;
172
173
  };
@@ -300,6 +301,7 @@ export declare const generateContextData: ({ user, services, app, rules, current
300
301
  } | {
301
302
  emailPasswordAuth: {
302
303
  registerUser: ReturnType<import("../../shared/models/handleUserRegistration.model").HandleUserRegistration>;
304
+ deleteUser: ReturnType<import("../../shared/models/handleUserDeletion.model").HandleUserDeletion>;
303
305
  };
304
306
  } | undefined;
305
307
  https: {
@@ -432,6 +434,7 @@ export declare const generateContextData: ({ user, services, app, rules, current
432
434
  } | {
433
435
  emailPasswordAuth: {
434
436
  registerUser: ReturnType<import("../../shared/models/handleUserRegistration.model").HandleUserRegistration>;
437
+ deleteUser: ReturnType<import("../../shared/models/handleUserDeletion.model").HandleUserDeletion>;
435
438
  };
436
439
  } | undefined;
437
440
  functions: {
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/utils/context/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAE3C,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAA;AAEvD;;;;;;;;;GASG;AACH,eAAO,MAAM,mBAAmB,GAAI,0FASjC,yBAAyB;;;;uBAqBP,SAAS;yBAGP,SAAS;;;;;;;;;;;;;;;;;;uBAcb,MAAM;;;+BArCU,MAAM,OAAO,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4BA6ChC,MAAM,OAAO,aAAa,WAAW,SAAS;;;CAerE,CAAA"}
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/utils/context/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAE3C,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAA;AAEvD;;;;;;;;;GASG;AACH,eAAO,MAAM,mBAAmB,GAAI,0FASjC,yBAAyB;;;;uBAqBP,SAAS;yBAGP,SAAS;;;;;;;;;;;;;;;;;;uBAcb,MAAM;;;+BArCU,MAAM,OAAO,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4BA6ChC,MAAM,OAAO,aAAa,WAAW,SAAS;;;CAerE,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowerforce/flowerbase",
3
- "version": "1.4.2-beta.6",
3
+ "version": "1.5.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,12 +1,14 @@
1
+ import handleUserDeletion from "../../shared/handleUserDeletion"
1
2
  import handleUserRegistration from "../../shared/handleUserRegistration"
2
3
  import { AuthServiceType } from "./model"
3
4
 
4
5
  const Auth: AuthServiceType = (app, opt) => {
5
6
  return {
6
7
  emailPasswordAuth: {
7
- registerUser: handleUserRegistration(app, opt)
8
+ registerUser: handleUserRegistration(app, opt),
9
+ deleteUser: handleUserDeletion(app, opt)
8
10
  }
9
11
  }
10
12
  }
11
13
 
12
- export default Auth
14
+ export default Auth
@@ -1,13 +1,15 @@
1
1
  import { FastifyInstance } from "fastify/types/instance"
2
+ import handleUserDeletion from "../../../src/shared/handleUserDeletion"
2
3
  import handleUserRegistration from "../../../src/shared/handleUserRegistration"
3
4
  import { Options } from "../../shared/models/handleUserRegistration.model"
4
5
 
5
6
  type EmailPasswordAuth = {
6
7
  registerUser: ReturnType<typeof handleUserRegistration>
8
+ deleteUser: ReturnType<typeof handleUserDeletion>
7
9
  }
8
10
 
9
11
  type AuthMethods = {
10
12
  emailPasswordAuth: EmailPasswordAuth
11
13
  }
12
14
 
13
- export type AuthServiceType = (app: FastifyInstance, options: Options) => AuthMethods
15
+ export type AuthServiceType = (app: FastifyInstance, options: Options) => AuthMethods
@@ -0,0 +1,44 @@
1
+ import { ObjectId } from "bson"
2
+ import { AUTH_CONFIG, DB_NAME } from "../constants"
3
+ import { HandleUserDeletion } from "./models/handleUserDeletion.model"
4
+
5
+ /**
6
+ * Delete user
7
+ *
8
+ * @param {FastifyInstance} app The Fastify instance.
9
+ * @param {Object} [opt] The options from the context
10
+ * @returns {Promise<DeleteResult>} A promise resolving to the result of the delete operation.
11
+ */
12
+ const handleUserDeletion: HandleUserDeletion = (app, opt) => async ({ id, email }) => {
13
+ const { run_as_system } = opt ?? {}
14
+
15
+ if (!run_as_system) {
16
+ throw new Error('only run_as_system')
17
+ }
18
+
19
+ if (!id && !email) {
20
+ throw new Error('Missing user identifier')
21
+ }
22
+
23
+ const { authCollection } = AUTH_CONFIG
24
+ const mongo = app?.mongo
25
+ const db = mongo.client.db(DB_NAME)
26
+ const collection = db.collection<Record<string, unknown>>(authCollection!)
27
+ let query: Record<string, unknown>
28
+
29
+ if (id) {
30
+ let parsedId: ObjectId | string = id
31
+ try {
32
+ parsedId = new ObjectId(id)
33
+ } catch {
34
+ parsedId = id
35
+ }
36
+ query = { _id: parsedId }
37
+ } else {
38
+ query = { email }
39
+ }
40
+
41
+ return collection.deleteOne(query)
42
+ }
43
+
44
+ export default handleUserDeletion
@@ -0,0 +1,13 @@
1
+ import { FastifyInstance } from "fastify/types/instance"
2
+ import { DeleteResult } from "mongodb"
3
+ import { Options } from "./handleUserRegistration.model"
4
+
5
+ type DeleteUserParams = {
6
+ id?: string
7
+ email?: string
8
+ }
9
+
10
+ export type HandleUserDeletion = (
11
+ app: FastifyInstance,
12
+ opt: Options
13
+ ) => (params: DeleteUserParams) => Promise<DeleteResult>