fiber-firebase-functions 1.0.5 → 1.0.7
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/lib/auth/is_user_disabled.d.ts +18 -0
- package/lib/auth/is_user_exists.d.ts +16 -0
- package/lib/auth/otp.d.ts +16 -0
- package/lib/auth/reset_password.d.ts +93 -0
- package/lib/auth/user.d.ts +23 -0
- package/lib/common/config.d.ts +17 -0
- package/lib/common/locale.d.ts +46 -0
- package/lib/common/realtime_database.d.ts +6 -0
- package/lib/email/email.d.ts +11 -0
- package/lib/email/templates/new_user.d.ts +5 -0
- package/lib/email/templates.d.ts +3 -0
- package/lib/geospatial/convert.d.ts +3 -0
- package/lib/geospatial/convert.js +82 -0
- package/lib/geospatial/convert.js.map +1 -0
- package/lib/index.d.ts +10 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/middleware/rate_limiter.d.ts +31 -0
- package/package.json +9 -3
- package/lib/auth/update_password.js +0 -232
- package/lib/auth/update_password.js.map +0 -1
- package/lib/email/send_email.js +0 -81
- package/lib/email/send_email.js.map +0 -1
- package/src/auth/is_user_disabled.ts +0 -94
- package/src/auth/is_user_exists.ts +0 -86
- package/src/auth/otp.ts +0 -135
- package/src/auth/reset_password.ts +0 -359
- package/src/auth/user.ts +0 -93
- package/src/common/config.ts +0 -84
- package/src/common/locale.ts +0 -121
- package/src/common/realtime_database.ts +0 -60
- package/src/email/email.ts +0 -70
- package/src/email/templates/new_user.ts +0 -493
- package/src/email/templates.ts +0 -34
- package/src/index.ts +0 -41
- package/src/middleware/rate_limiter.ts +0 -153
- package/tsconfig.json +0 -32
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright (C) 2025 Fiber
|
|
4
|
-
*
|
|
5
|
-
* All rights reserved. This script, including its code and logic, is the
|
|
6
|
-
* exclusive property of Fiber. Redistribution, reproduction,
|
|
7
|
-
* or modification of any part of this script is strictly prohibited
|
|
8
|
-
* without prior written permission from Fiber.
|
|
9
|
-
*
|
|
10
|
-
* Conditions of use:
|
|
11
|
-
* - The code may not be copied, duplicated, or used, in whole or in part,
|
|
12
|
-
* for any purpose without explicit authorization.
|
|
13
|
-
* - Redistribution of this code, with or without modification, is not
|
|
14
|
-
* permitted unless expressly agreed upon by Fiber.
|
|
15
|
-
* - The name "Fiber" and any associated branding, logos, or
|
|
16
|
-
* trademarks may not be used to endorse or promote derived products
|
|
17
|
-
* or services without prior written approval.
|
|
18
|
-
*
|
|
19
|
-
* Disclaimer:
|
|
20
|
-
* THIS SCRIPT AND ITS CODE ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
|
|
21
|
-
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY,
|
|
22
|
-
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL
|
|
23
|
-
* FIBER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
24
|
-
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING BUT NOT LIMITED TO LOSS OF USE,
|
|
25
|
-
* DATA, PROFITS, OR BUSINESS INTERRUPTION) ARISING OUT OF OR RELATED TO THE USE
|
|
26
|
-
* OR INABILITY TO USE THIS SCRIPT, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
27
|
-
*
|
|
28
|
-
* Unauthorized copying or reproduction of this script, in whole or in part,
|
|
29
|
-
* is a violation of applicable intellectual property laws and will result
|
|
30
|
-
* in legal action.
|
|
31
|
-
*/
|
|
32
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
33
|
-
if (k2 === undefined) k2 = k;
|
|
34
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
35
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
36
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
37
|
-
}
|
|
38
|
-
Object.defineProperty(o, k2, desc);
|
|
39
|
-
}) : (function(o, m, k, k2) {
|
|
40
|
-
if (k2 === undefined) k2 = k;
|
|
41
|
-
o[k2] = m[k];
|
|
42
|
-
}));
|
|
43
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
44
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
45
|
-
}) : function(o, v) {
|
|
46
|
-
o["default"] = v;
|
|
47
|
-
});
|
|
48
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
49
|
-
var ownKeys = function(o) {
|
|
50
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
51
|
-
var ar = [];
|
|
52
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
53
|
-
return ar;
|
|
54
|
-
};
|
|
55
|
-
return ownKeys(o);
|
|
56
|
-
};
|
|
57
|
-
return function (mod) {
|
|
58
|
-
if (mod && mod.__esModule) return mod;
|
|
59
|
-
var result = {};
|
|
60
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
61
|
-
__setModuleDefault(result, mod);
|
|
62
|
-
return result;
|
|
63
|
-
};
|
|
64
|
-
})();
|
|
65
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
66
|
-
exports.ResetPasswordByIdStatus = exports.ResetPasswordByEmailStatus = void 0;
|
|
67
|
-
exports.resetPasswordByEmail = resetPasswordByEmail;
|
|
68
|
-
exports.resetPasswordById = resetPasswordById;
|
|
69
|
-
const admin = __importStar(require("firebase-admin"));
|
|
70
|
-
const config_1 = require("../common/config");
|
|
71
|
-
const rate_limiter_1 = require("../middleware/rate_limiter");
|
|
72
|
-
const is_user_disabled_1 = require("./is_user_disabled");
|
|
73
|
-
const is_user_exists_1 = require("./is_user_exists");
|
|
74
|
-
const user_1 = require("./user");
|
|
75
|
-
if (admin.apps.length === 0) {
|
|
76
|
-
admin.initializeApp();
|
|
77
|
-
}
|
|
78
|
-
var ResetPasswordByEmailStatus;
|
|
79
|
-
(function (ResetPasswordByEmailStatus) {
|
|
80
|
-
ResetPasswordByEmailStatus["MISSING_DATABASE_CONFIG"] = "MISSING_DATABASE_CONFIG";
|
|
81
|
-
ResetPasswordByEmailStatus["MISSING_USER_EMAIL"] = "MISSING_USER_EMAIL";
|
|
82
|
-
ResetPasswordByEmailStatus["MISSING_NEW_PASSWORD"] = "MISSING_NEW_PASSWORD";
|
|
83
|
-
ResetPasswordByEmailStatus["MISSING_CONFIRM_NEW_PASSWORD"] = "MISSING_CONFIRM_NEW_PASSWORD";
|
|
84
|
-
ResetPasswordByEmailStatus["MISSING_PASSWORD_POLICY"] = "MISSING_PASSWORD_POLICY";
|
|
85
|
-
ResetPasswordByEmailStatus["NOT_IDENTICAL_CONFIRM_PASSWORD"] = "NOT_IDENTICAL_CONFIRM_PASSWORD";
|
|
86
|
-
ResetPasswordByEmailStatus["USER_NOT_FOUND"] = "USER_NOT_FOUND";
|
|
87
|
-
ResetPasswordByEmailStatus["USER_DISABLED"] = "USER_DISABLED";
|
|
88
|
-
ResetPasswordByEmailStatus["WEAK_NEW_PASSWORD"] = "WEAK_NEW_PASSWORD";
|
|
89
|
-
ResetPasswordByEmailStatus["MISSING_PASSWORD_UPPERCASE"] = "MISSING_PASSWORD_UPPERCASE";
|
|
90
|
-
ResetPasswordByEmailStatus["MISSING_PASSWORD_LOWERCASE"] = "MISSING_PASSWORD_LOWERCASE";
|
|
91
|
-
ResetPasswordByEmailStatus["MISSING_PASSWORD_DIGIT"] = "MISSING_PASSWORD_DIGIT";
|
|
92
|
-
ResetPasswordByEmailStatus["MISSING_PASSWORD_SPECIAL_CHAR"] = "MISSING_PASSWORD_SPECIAL_CHAR";
|
|
93
|
-
ResetPasswordByEmailStatus["TOO_MANY_REQUEST"] = "TOO_MANY_REQUEST";
|
|
94
|
-
ResetPasswordByEmailStatus["SUCCESS"] = "SUCCESS";
|
|
95
|
-
ResetPasswordByEmailStatus["INTERNAL_ERROR"] = "INTERNAL_ERROR";
|
|
96
|
-
})(ResetPasswordByEmailStatus || (exports.ResetPasswordByEmailStatus = ResetPasswordByEmailStatus = {}));
|
|
97
|
-
var ResetPasswordByIdStatus;
|
|
98
|
-
(function (ResetPasswordByIdStatus) {
|
|
99
|
-
ResetPasswordByIdStatus["MISSING_DATABASE_CONFIG"] = "MISSING_DATABASE_CONFIG";
|
|
100
|
-
ResetPasswordByIdStatus["MISSING_USER_ID"] = "MISSING_USER_ID";
|
|
101
|
-
ResetPasswordByIdStatus["MISSING_NEW_PASSWORD"] = "MISSING_NEW_PASSWORD";
|
|
102
|
-
ResetPasswordByIdStatus["MISSING_CONFIRM_NEW_PASSWORD"] = "MISSING_CONFIRM_NEW_PASSWORD";
|
|
103
|
-
ResetPasswordByIdStatus["MISSING_PASSWORD_POLICY"] = "MISSING_PASSWORD_POLICY";
|
|
104
|
-
ResetPasswordByIdStatus["NOT_IDENTICAL_CONFIRM_PASSWORD"] = "NOT_IDENTICAL_CONFIRM_PASSWORD";
|
|
105
|
-
ResetPasswordByIdStatus["USER_NOT_FOUND"] = "USER_NOT_FOUND";
|
|
106
|
-
ResetPasswordByIdStatus["USER_DISABLED"] = "USER_DISABLED";
|
|
107
|
-
ResetPasswordByIdStatus["WEAK_NEW_PASSWORD"] = "WEAK_NEW_PASSWORD";
|
|
108
|
-
ResetPasswordByIdStatus["MISSING_PASSWORD_UPPERCASE"] = "MISSING_PASSWORD_UPPERCASE";
|
|
109
|
-
ResetPasswordByIdStatus["MISSING_PASSWORD_LOWERCASE"] = "MISSING_PASSWORD_LOWERCASE";
|
|
110
|
-
ResetPasswordByIdStatus["MISSING_PASSWORD_DIGIT"] = "MISSING_PASSWORD_DIGIT";
|
|
111
|
-
ResetPasswordByIdStatus["MISSING_PASSWORD_SPECIAL_CHAR"] = "MISSING_PASSWORD_SPECIAL_CHAR";
|
|
112
|
-
ResetPasswordByIdStatus["TOO_MANY_REQUEST"] = "TOO_MANY_REQUEST";
|
|
113
|
-
ResetPasswordByIdStatus["SUCCESS"] = "SUCCESS";
|
|
114
|
-
ResetPasswordByIdStatus["INTERNAL_ERROR"] = "INTERNAL_ERROR";
|
|
115
|
-
})(ResetPasswordByIdStatus || (exports.ResetPasswordByIdStatus = ResetPasswordByIdStatus = {}));
|
|
116
|
-
async function resetPasswordByEmail(email, password) {
|
|
117
|
-
const config = (0, config_1.appInitialize)();
|
|
118
|
-
const middleware = config.middleware;
|
|
119
|
-
if (!middleware)
|
|
120
|
-
return ResetPasswordByEmailStatus.MISSING_DATABASE_CONFIG;
|
|
121
|
-
email = email.trim();
|
|
122
|
-
if (!email)
|
|
123
|
-
return ResetPasswordByEmailStatus.MISSING_USER_EMAIL;
|
|
124
|
-
const newPassword = password.newPassword.trim();
|
|
125
|
-
const confirmNewPassword = password.confirmNewPassword.trim();
|
|
126
|
-
if (!newPassword || newPassword === "")
|
|
127
|
-
return ResetPasswordByEmailStatus.MISSING_NEW_PASSWORD;
|
|
128
|
-
if (!confirmNewPassword || confirmNewPassword === "")
|
|
129
|
-
return ResetPasswordByEmailStatus.MISSING_CONFIRM_NEW_PASSWORD;
|
|
130
|
-
const passwordPolicy = password.passwordPolicy;
|
|
131
|
-
if (!passwordPolicy)
|
|
132
|
-
return ResetPasswordByEmailStatus.MISSING_PASSWORD_POLICY;
|
|
133
|
-
const userResult = await (0, user_1.getUserByEmail)(email);
|
|
134
|
-
const user = userResult.user;
|
|
135
|
-
if (userResult.status !== user_1.UserByEmailStatus.FOUND || user === undefined)
|
|
136
|
-
return ResetPasswordByEmailStatus.USER_NOT_FOUND;
|
|
137
|
-
const identifier = {
|
|
138
|
-
id: user.uid,
|
|
139
|
-
target: "reset_password"
|
|
140
|
-
};
|
|
141
|
-
const rule = {
|
|
142
|
-
ttl: 2 * 60 * 1000,
|
|
143
|
-
windowMs: 3 * 60 * 1000,
|
|
144
|
-
maxHits: 5,
|
|
145
|
-
};
|
|
146
|
-
if (await (0, rate_limiter_1.isRateLimited)(identifier, rule) !== rate_limiter_1.RateLimitCheckStatus.LIMIT_NOT_FOUND) {
|
|
147
|
-
return ResetPasswordByEmailStatus.TOO_MANY_REQUEST;
|
|
148
|
-
}
|
|
149
|
-
await (0, rate_limiter_1.recordRateLimitHit)(identifier, rule);
|
|
150
|
-
if (await (0, is_user_disabled_1.isUserDisabledById)(user.uid))
|
|
151
|
-
return ResetPasswordByEmailStatus.USER_DISABLED;
|
|
152
|
-
if (newPassword !== confirmNewPassword)
|
|
153
|
-
return ResetPasswordByEmailStatus.NOT_IDENTICAL_CONFIRM_PASSWORD;
|
|
154
|
-
const requiredMin = Math.max(6, passwordPolicy.minLength);
|
|
155
|
-
if (newPassword.length < requiredMin)
|
|
156
|
-
return ResetPasswordByEmailStatus.WEAK_NEW_PASSWORD;
|
|
157
|
-
const rules = [
|
|
158
|
-
{ enabled: passwordPolicy.requireUppercase, regex: /[A-Z]/, error: ResetPasswordByEmailStatus.MISSING_PASSWORD_UPPERCASE },
|
|
159
|
-
{ enabled: passwordPolicy.requireLowercase, regex: /[a-z]/, error: ResetPasswordByEmailStatus.MISSING_PASSWORD_LOWERCASE },
|
|
160
|
-
{ enabled: passwordPolicy.requireDigit, regex: /[0-9]/, error: ResetPasswordByEmailStatus.MISSING_PASSWORD_DIGIT },
|
|
161
|
-
{ enabled: passwordPolicy.requireSpecial, regex: /[^A-Za-z0-9]/, error: ResetPasswordByEmailStatus.MISSING_PASSWORD_SPECIAL_CHAR },
|
|
162
|
-
];
|
|
163
|
-
for (const rule of rules) {
|
|
164
|
-
if (rule.enabled && !rule.regex.test(newPassword))
|
|
165
|
-
return rule.error;
|
|
166
|
-
}
|
|
167
|
-
try {
|
|
168
|
-
await admin.auth().updateUser(user.uid, { password: newPassword });
|
|
169
|
-
return ResetPasswordByEmailStatus.SUCCESS;
|
|
170
|
-
}
|
|
171
|
-
catch (error) {
|
|
172
|
-
return ResetPasswordByEmailStatus.INTERNAL_ERROR;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
async function resetPasswordById(userId, password, databaseConfig) {
|
|
176
|
-
const config = (0, config_1.appInitialize)();
|
|
177
|
-
const middleware = config.middleware;
|
|
178
|
-
if (!middleware)
|
|
179
|
-
return ResetPasswordByIdStatus.MISSING_DATABASE_CONFIG;
|
|
180
|
-
userId = userId.trim();
|
|
181
|
-
if (!userId)
|
|
182
|
-
return ResetPasswordByIdStatus.MISSING_USER_ID;
|
|
183
|
-
const newPassword = password.newPassword.trim();
|
|
184
|
-
const confirmNewPassword = password.confirmNewPassword.trim();
|
|
185
|
-
if (!newPassword || newPassword === "")
|
|
186
|
-
return ResetPasswordByIdStatus.MISSING_NEW_PASSWORD;
|
|
187
|
-
if (!confirmNewPassword || confirmNewPassword === "")
|
|
188
|
-
return ResetPasswordByIdStatus.MISSING_CONFIRM_NEW_PASSWORD;
|
|
189
|
-
const passwordPolicy = password.passwordPolicy;
|
|
190
|
-
if (!passwordPolicy)
|
|
191
|
-
return ResetPasswordByIdStatus.MISSING_PASSWORD_POLICY;
|
|
192
|
-
const identifier = {
|
|
193
|
-
id: userId,
|
|
194
|
-
target: "reset_password"
|
|
195
|
-
};
|
|
196
|
-
const rule = {
|
|
197
|
-
ttl: 2 * 60 * 1000,
|
|
198
|
-
windowMs: 3 * 60 * 1000,
|
|
199
|
-
maxHits: 5,
|
|
200
|
-
};
|
|
201
|
-
if (await (0, rate_limiter_1.isRateLimited)(identifier, rule) !== rate_limiter_1.RateLimitCheckStatus.LIMIT_NOT_FOUND) {
|
|
202
|
-
return ResetPasswordByIdStatus.TOO_MANY_REQUEST;
|
|
203
|
-
}
|
|
204
|
-
await (0, rate_limiter_1.recordRateLimitHit)(identifier, rule);
|
|
205
|
-
if (await (0, is_user_exists_1.isUserExistsById)(userId))
|
|
206
|
-
return ResetPasswordByIdStatus.USER_NOT_FOUND;
|
|
207
|
-
if (await (0, is_user_disabled_1.isUserDisabledById)(userId))
|
|
208
|
-
return ResetPasswordByIdStatus.USER_DISABLED;
|
|
209
|
-
if (newPassword !== confirmNewPassword)
|
|
210
|
-
return ResetPasswordByIdStatus.NOT_IDENTICAL_CONFIRM_PASSWORD;
|
|
211
|
-
const requiredMin = Math.max(6, passwordPolicy.minLength);
|
|
212
|
-
if (newPassword.length < requiredMin)
|
|
213
|
-
return ResetPasswordByIdStatus.WEAK_NEW_PASSWORD;
|
|
214
|
-
const rules = [
|
|
215
|
-
{ enabled: passwordPolicy.requireUppercase, regex: /[A-Z]/, error: ResetPasswordByIdStatus.MISSING_PASSWORD_UPPERCASE },
|
|
216
|
-
{ enabled: passwordPolicy.requireLowercase, regex: /[a-z]/, error: ResetPasswordByIdStatus.MISSING_PASSWORD_LOWERCASE },
|
|
217
|
-
{ enabled: passwordPolicy.requireDigit, regex: /[0-9]/, error: ResetPasswordByIdStatus.MISSING_PASSWORD_DIGIT },
|
|
218
|
-
{ enabled: passwordPolicy.requireSpecial, regex: /[^A-Za-z0-9]/, error: ResetPasswordByIdStatus.MISSING_PASSWORD_SPECIAL_CHAR },
|
|
219
|
-
];
|
|
220
|
-
for (const rule of rules) {
|
|
221
|
-
if (rule.enabled && !rule.regex.test(newPassword))
|
|
222
|
-
return rule.error;
|
|
223
|
-
}
|
|
224
|
-
try {
|
|
225
|
-
await admin.auth().updateUser(userId, { password: newPassword });
|
|
226
|
-
return ResetPasswordByIdStatus.SUCCESS;
|
|
227
|
-
}
|
|
228
|
-
catch (error) {
|
|
229
|
-
return ResetPasswordByIdStatus.INTERNAL_ERROR;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
//# sourceMappingURL=update_password.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"update_password.js","sourceRoot":"","sources":["../../src/auth/update_password.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;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AAI,CAAC,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC;YAAE,OAAO,IAAI,CAAC,KAAK,CAAC;IACzE,CAAC;IAED,IAAI,CAAC;QACD,MAAM,KAAK,CAAC,IAAI,EAAE,CAAC,UAAU,CAAC,MAAM,EAAE,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC,CAAC;QACjE,OAAO,uBAAuB,CAAC,OAAO,CAAC;IAC3C,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QAClB,OAAO,uBAAuB,CAAC,cAAc,CAAC;IAClD,CAAC;AACL,CAAC"}
|
package/lib/email/send_email.js
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright (C) 2025 Fiber
|
|
4
|
-
*
|
|
5
|
-
* All rights reserved. This script, including its code and logic, is the
|
|
6
|
-
* exclusive property of Fiber. Redistribution, reproduction,
|
|
7
|
-
* or modification of any part of this script is strictly prohibited
|
|
8
|
-
* without prior written permission from Fiber.
|
|
9
|
-
*
|
|
10
|
-
* Conditions of use:
|
|
11
|
-
* - The code may not be copied, duplicated, or used, in whole or in part,
|
|
12
|
-
* for any purpose without explicit authorization.
|
|
13
|
-
* - Redistribution of this code, with or without modification, is not
|
|
14
|
-
* permitted unless expressly agreed upon by Fiber.
|
|
15
|
-
* - The name "Fiber" and any associated branding, logos, or
|
|
16
|
-
* trademarks may not be used to endorse or promote derived products
|
|
17
|
-
* or services without prior written approval.
|
|
18
|
-
*
|
|
19
|
-
* Disclaimer:
|
|
20
|
-
* THIS SCRIPT AND ITS CODE ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
|
|
21
|
-
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY,
|
|
22
|
-
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL
|
|
23
|
-
* FIBER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
24
|
-
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING BUT NOT LIMITED TO LOSS OF USE,
|
|
25
|
-
* DATA, PROFITS, OR BUSINESS INTERRUPTION) ARISING OUT OF OR RELATED TO THE USE
|
|
26
|
-
* OR INABILITY TO USE THIS SCRIPT, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
27
|
-
*
|
|
28
|
-
* Unauthorized copying or reproduction of this script, in whole or in part,
|
|
29
|
-
* is a violation of applicable intellectual property laws and will result
|
|
30
|
-
* in legal action.
|
|
31
|
-
*/
|
|
32
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
33
|
-
if (k2 === undefined) k2 = k;
|
|
34
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
35
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
36
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
37
|
-
}
|
|
38
|
-
Object.defineProperty(o, k2, desc);
|
|
39
|
-
}) : (function(o, m, k, k2) {
|
|
40
|
-
if (k2 === undefined) k2 = k;
|
|
41
|
-
o[k2] = m[k];
|
|
42
|
-
}));
|
|
43
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
44
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
45
|
-
}) : function(o, v) {
|
|
46
|
-
o["default"] = v;
|
|
47
|
-
});
|
|
48
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
49
|
-
var ownKeys = function(o) {
|
|
50
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
51
|
-
var ar = [];
|
|
52
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
53
|
-
return ar;
|
|
54
|
-
};
|
|
55
|
-
return ownKeys(o);
|
|
56
|
-
};
|
|
57
|
-
return function (mod) {
|
|
58
|
-
if (mod && mod.__esModule) return mod;
|
|
59
|
-
var result = {};
|
|
60
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
61
|
-
__setModuleDefault(result, mod);
|
|
62
|
-
return result;
|
|
63
|
-
};
|
|
64
|
-
})();
|
|
65
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
66
|
-
exports.sendEmail = sendEmail;
|
|
67
|
-
const admin = __importStar(require("firebase-admin"));
|
|
68
|
-
if (admin.apps.length === 0) {
|
|
69
|
-
admin.initializeApp();
|
|
70
|
-
}
|
|
71
|
-
async function sendEmail(collection, to, subject, message) {
|
|
72
|
-
const firestore = admin.firestore();
|
|
73
|
-
await firestore.collection(collection).add({
|
|
74
|
-
to: [to],
|
|
75
|
-
message: {
|
|
76
|
-
subject: subject,
|
|
77
|
-
text: message,
|
|
78
|
-
},
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
//# sourceMappingURL=send_email.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"send_email.js","sourceRoot":"","sources":["../../src/email/send_email.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQH,8BAUC;AAhBD,sDAAwC;AAExC,IAAI,KAAK,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;IAC1B,KAAK,CAAC,aAAa,EAAE,CAAC;AAC1B,CAAC;AAEM,KAAK,UAAU,SAAS,CAAC,UAAkB,EAAE,EAAU,EAAE,OAAe,EAAE,OAAe;IAC5F,MAAM,SAAS,GAAG,KAAK,CAAC,SAAS,EAAE,CAAC;IAEpC,MAAM,SAAS,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC;QACvC,EAAE,EAAE,CAAC,EAAE,CAAC;QACR,OAAO,EAAE;YACL,OAAO,EAAE,OAAO;YAChB,IAAI,EAAE,OAAO;SAChB;KACJ,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (C) 2025 Fiber
|
|
3
|
-
*
|
|
4
|
-
* All rights reserved. This script, including its code and logic, is the
|
|
5
|
-
* exclusive property of Fiber. Redistribution, reproduction,
|
|
6
|
-
* or modification of any part of this script is strictly prohibited
|
|
7
|
-
* without prior written permission from Fiber.
|
|
8
|
-
*
|
|
9
|
-
* Conditions of use:
|
|
10
|
-
* - The code may not be copied, duplicated, or used, in whole or in part,
|
|
11
|
-
* for any purpose without explicit authorization.
|
|
12
|
-
* - Redistribution of this code, with or without modification, is not
|
|
13
|
-
* permitted unless expressly agreed upon by Fiber.
|
|
14
|
-
* - The name "Fiber" and any associated branding, logos, or
|
|
15
|
-
* trademarks may not be used to endorse or promote derived products
|
|
16
|
-
* or services without prior written approval.
|
|
17
|
-
*
|
|
18
|
-
* Disclaimer:
|
|
19
|
-
* THIS SCRIPT AND ITS CODE ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
|
|
20
|
-
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY,
|
|
21
|
-
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL
|
|
22
|
-
* FIBER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
23
|
-
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING BUT NOT LIMITED TO LOSS OF USE,
|
|
24
|
-
* DATA, PROFITS, OR BUSINESS INTERRUPTION) ARISING OUT OF OR RELATED TO THE USE
|
|
25
|
-
* OR INABILITY TO USE THIS SCRIPT, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
26
|
-
*
|
|
27
|
-
* Unauthorized copying or reproduction of this script, in whole or in part,
|
|
28
|
-
* is a violation of applicable intellectual property laws and will result
|
|
29
|
-
* in legal action.
|
|
30
|
-
*/
|
|
31
|
-
|
|
32
|
-
import * as admin from "firebase-admin";
|
|
33
|
-
|
|
34
|
-
if (admin.apps.length === 0) {
|
|
35
|
-
admin.initializeApp();
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export enum UserDisabledByIdStatus {
|
|
39
|
-
MISSING_USER_ID = "MISSING_USER_ID",
|
|
40
|
-
ENABLED = "ENABLED",
|
|
41
|
-
DISABLED = "DISABLED",
|
|
42
|
-
USER_NOT_FOUND = "USER_NOT_FOUND",
|
|
43
|
-
INTERNAL_ERROR = "INTERNAL_ERROR",
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export enum UserDisabledByEmailStatus {
|
|
47
|
-
MISSING_USER_ID = "MISSING_USER_ID",
|
|
48
|
-
ENABLED = "ENABLED",
|
|
49
|
-
DISABLED = "DISABLED",
|
|
50
|
-
USER_NOT_FOUND = "USER_NOT_FOUND",
|
|
51
|
-
INTERNAL_ERROR = "INTERNAL_ERROR",
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export class IsUserDisabled {
|
|
55
|
-
static async withId(userId: string): Promise<UserDisabledByIdStatus> {
|
|
56
|
-
userId = userId.trim();
|
|
57
|
-
|
|
58
|
-
if (!userId || userId === "") return UserDisabledByIdStatus.MISSING_USER_ID;
|
|
59
|
-
|
|
60
|
-
try {
|
|
61
|
-
const user = await admin.auth().getUser(userId);
|
|
62
|
-
const isUserDisabled = user.disabled;
|
|
63
|
-
|
|
64
|
-
return isUserDisabled
|
|
65
|
-
? UserDisabledByIdStatus.DISABLED
|
|
66
|
-
: UserDisabledByIdStatus.ENABLED;
|
|
67
|
-
} catch (error: any) {
|
|
68
|
-
if (error.code === "auth/user-not-found") {
|
|
69
|
-
return UserDisabledByIdStatus.USER_NOT_FOUND;
|
|
70
|
-
}
|
|
71
|
-
return UserDisabledByIdStatus.INTERNAL_ERROR;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
static async withEmail(email: string): Promise<UserDisabledByEmailStatus> {
|
|
76
|
-
email = email.trim();
|
|
77
|
-
|
|
78
|
-
if (!email || email === "") return UserDisabledByEmailStatus.MISSING_USER_ID;
|
|
79
|
-
|
|
80
|
-
try {
|
|
81
|
-
const user = await admin.auth().getUserByEmail(email);
|
|
82
|
-
const isUserDisabled = user.disabled;
|
|
83
|
-
|
|
84
|
-
return isUserDisabled
|
|
85
|
-
? UserDisabledByEmailStatus.DISABLED
|
|
86
|
-
: UserDisabledByEmailStatus.ENABLED;
|
|
87
|
-
} catch (error: any) {
|
|
88
|
-
if (error.code === "auth/user-not-found") {
|
|
89
|
-
return UserDisabledByEmailStatus.USER_NOT_FOUND;
|
|
90
|
-
}
|
|
91
|
-
return UserDisabledByEmailStatus.INTERNAL_ERROR;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (C) 2025 Fiber
|
|
3
|
-
*
|
|
4
|
-
* All rights reserved. This script, including its code and logic, is the
|
|
5
|
-
* exclusive property of Fiber. Redistribution, reproduction,
|
|
6
|
-
* or modification of any part of this script is strictly prohibited
|
|
7
|
-
* without prior written permission from Fiber.
|
|
8
|
-
*
|
|
9
|
-
* Conditions of use:
|
|
10
|
-
* - The code may not be copied, duplicated, or used, in whole or in part,
|
|
11
|
-
* for any purpose without explicit authorization.
|
|
12
|
-
* - Redistribution of this code, with or without modification, is not
|
|
13
|
-
* permitted unless expressly agreed upon by Fiber.
|
|
14
|
-
* - The name "Fiber" and any associated branding, logos, or
|
|
15
|
-
* trademarks may not be used to endorse or promote derived products
|
|
16
|
-
* or services without prior written approval.
|
|
17
|
-
*
|
|
18
|
-
* Disclaimer:
|
|
19
|
-
* THIS SCRIPT AND ITS CODE ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
|
|
20
|
-
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY,
|
|
21
|
-
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL
|
|
22
|
-
* FIBER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
23
|
-
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING BUT NOT LIMITED TO LOSS OF USE,
|
|
24
|
-
* DATA, PROFITS, OR BUSINESS INTERRUPTION) ARISING OUT OF OR RELATED TO THE USE
|
|
25
|
-
* OR INABILITY TO USE THIS SCRIPT, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
26
|
-
*
|
|
27
|
-
* Unauthorized copying or reproduction of this script, in whole or in part,
|
|
28
|
-
* is a violation of applicable intellectual property laws and will result
|
|
29
|
-
* in legal action.
|
|
30
|
-
*/
|
|
31
|
-
|
|
32
|
-
import * as admin from "firebase-admin";
|
|
33
|
-
|
|
34
|
-
if (admin.apps.length === 0) {
|
|
35
|
-
admin.initializeApp();
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export enum UserExistsByIdStatus {
|
|
39
|
-
MISSING_USER_ID = "MISSING_USER_ID",
|
|
40
|
-
EXISTS = "EXISTS",
|
|
41
|
-
USER_NOT_FOUND = "USER_NOT_FOUND",
|
|
42
|
-
INTERNAL_ERROR = "INTERNAL_ERROR",
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export enum UserExistsByEmailStatus {
|
|
46
|
-
MISSING_USER_EMAIL = "MISSING_USER_EMAIL",
|
|
47
|
-
EXISTS = "EXISTS",
|
|
48
|
-
USER_NOT_FOUND = "USER_NOT_FOUND",
|
|
49
|
-
INTERNAL_ERROR = "INTERNAL_ERROR",
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export class IsUserExists {
|
|
53
|
-
static async withId(userId: string): Promise<UserExistsByIdStatus> {
|
|
54
|
-
userId = userId.trim();
|
|
55
|
-
|
|
56
|
-
if (!userId || userId === "") return UserExistsByIdStatus.MISSING_USER_ID;
|
|
57
|
-
|
|
58
|
-
try {
|
|
59
|
-
await admin.auth().getUser(userId);
|
|
60
|
-
|
|
61
|
-
return UserExistsByIdStatus.EXISTS;
|
|
62
|
-
} catch (error: any) {
|
|
63
|
-
if (error.code === "auth/user-not-found") {
|
|
64
|
-
return UserExistsByIdStatus.USER_NOT_FOUND;
|
|
65
|
-
}
|
|
66
|
-
return UserExistsByIdStatus.INTERNAL_ERROR;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
static async withEmail(email: string): Promise<UserExistsByEmailStatus> {
|
|
71
|
-
email = email.trim();
|
|
72
|
-
|
|
73
|
-
if (!email || email === "") return UserExistsByEmailStatus.MISSING_USER_EMAIL;
|
|
74
|
-
|
|
75
|
-
try {
|
|
76
|
-
await admin.auth().getUserByEmail(email);
|
|
77
|
-
|
|
78
|
-
return UserExistsByEmailStatus.EXISTS;
|
|
79
|
-
} catch (error: any) {
|
|
80
|
-
if (error.code === "auth/user-not-found") {
|
|
81
|
-
return UserExistsByEmailStatus.USER_NOT_FOUND;
|
|
82
|
-
}
|
|
83
|
-
return UserExistsByEmailStatus.INTERNAL_ERROR;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
package/src/auth/otp.ts
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (C) 2025 Fiber
|
|
3
|
-
*
|
|
4
|
-
* All rights reserved. This script, including its code and logic, is the
|
|
5
|
-
* exclusive property of Fiber. Redistribution, reproduction,
|
|
6
|
-
* or modification of any part of this script is strictly prohibited
|
|
7
|
-
* without prior written permission from Fiber.
|
|
8
|
-
*
|
|
9
|
-
* Conditions of use:
|
|
10
|
-
* - The code may not be copied, duplicated, or used, in whole or in part,
|
|
11
|
-
* for any purpose without explicit authorization.
|
|
12
|
-
* - Redistribution of this code, with or without modification, is not
|
|
13
|
-
* permitted unless expressly agreed upon by Fiber.
|
|
14
|
-
* - The name "Fiber" and any associated branding, logos, or
|
|
15
|
-
* trademarks may not be used to endorse or promote derived products
|
|
16
|
-
* or services without prior written approval.
|
|
17
|
-
*
|
|
18
|
-
* Disclaimer:
|
|
19
|
-
* THIS SCRIPT AND ITS CODE ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
|
|
20
|
-
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY,
|
|
21
|
-
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL
|
|
22
|
-
* FIBER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
23
|
-
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING BUT NOT LIMITED TO LOSS OF USE,
|
|
24
|
-
* DATA, PROFITS, OR BUSINESS INTERRUPTION) ARISING OUT OF OR RELATED TO THE USE
|
|
25
|
-
* OR INABILITY TO USE THIS SCRIPT, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
26
|
-
*
|
|
27
|
-
* Unauthorized copying or reproduction of this script, in whole or in part,
|
|
28
|
-
* is a violation of applicable intellectual property laws and will result
|
|
29
|
-
* in legal action.
|
|
30
|
-
*/
|
|
31
|
-
|
|
32
|
-
import crypto from 'crypto';
|
|
33
|
-
import * as admin from "firebase-admin";
|
|
34
|
-
import { appInitialize } from "../common/config";
|
|
35
|
-
|
|
36
|
-
if (admin.apps.length === 0) {
|
|
37
|
-
admin.initializeApp();
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export enum GenerateStatus {
|
|
41
|
-
MISSING_OTP_CONFIG = "MISSING_OTP_CONFIG",
|
|
42
|
-
SUCCESS = "SUCCESS",
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export enum GetOTPStatus {
|
|
46
|
-
MISSING_OTP_CONFIG = "MISSING_OTP_CONFIG",
|
|
47
|
-
OTP_NOT_FOUND = "OTP_NOT_FOUND",
|
|
48
|
-
OTP_FOUND = "OTP_FOUND",
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export class Otp {
|
|
52
|
-
static async generate(userId: string, type: string): Promise<GenerateStatus> {
|
|
53
|
-
const config = appInitialize();
|
|
54
|
-
const otp = config.otp;
|
|
55
|
-
|
|
56
|
-
if (otp.collection === undefined) return GenerateStatus.MISSING_OTP_CONFIG;
|
|
57
|
-
|
|
58
|
-
const now = Date.now();
|
|
59
|
-
const otpCode = OTPUtils.generate();
|
|
60
|
-
const hashOtp = OTPUtils.hash(otpCode);
|
|
61
|
-
|
|
62
|
-
await admin.firestore().collection(otp.collection).add({
|
|
63
|
-
__fbs__user_id: userId,
|
|
64
|
-
__fbs__created_at: now,
|
|
65
|
-
__fbs__otp_type: type,
|
|
66
|
-
__fbs__otp: hashOtp,
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
return GenerateStatus.SUCCESS;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
static async get(userId: string, type: string): Promise<{ status: GetOTPStatus; otp?: string; }> {
|
|
73
|
-
const config = appInitialize();
|
|
74
|
-
const otp = config.otp;
|
|
75
|
-
|
|
76
|
-
if (otp.collection === undefined) return { status: GetOTPStatus.MISSING_OTP_CONFIG };
|
|
77
|
-
|
|
78
|
-
const snapshot = await admin.firestore()
|
|
79
|
-
.collection(otp.collection)
|
|
80
|
-
.where("__fbs__user_id", "==", userId)
|
|
81
|
-
.where("__fbs__otp_type", "==", type)
|
|
82
|
-
.orderBy("__fbs__created_at", "desc")
|
|
83
|
-
.limit(1)
|
|
84
|
-
.get();
|
|
85
|
-
|
|
86
|
-
if (snapshot.docs.length === 0) return { status: GetOTPStatus.OTP_NOT_FOUND };
|
|
87
|
-
|
|
88
|
-
const doc = snapshot.docs[0];
|
|
89
|
-
const data = doc?.data();
|
|
90
|
-
const otpCode = data?.__fbs__otp as string;
|
|
91
|
-
|
|
92
|
-
return { status: GetOTPStatus.MISSING_OTP_CONFIG, otp: otpCode };
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
class OTPUtils {
|
|
97
|
-
static generate(): string {
|
|
98
|
-
while (true) {
|
|
99
|
-
const buffer = crypto.randomBytes(4);
|
|
100
|
-
const number = buffer.readUInt32BE();
|
|
101
|
-
const otp = (number % 1000000).toString().padStart(6, '0');
|
|
102
|
-
|
|
103
|
-
if (this.hasAllIdenticalDigits(otp)) continue;
|
|
104
|
-
if (this.hasRepeatingPattern(otp)) continue;
|
|
105
|
-
if (this.hasMoreThanThreeConsecutiveIdenticalDigits(otp)) continue;
|
|
106
|
-
|
|
107
|
-
return otp;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
static hash(otp: string): string {
|
|
112
|
-
return crypto.createHash('sha256').update(otp).digest('hex');
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
private static hasAllIdenticalDigits(str: string): boolean {
|
|
116
|
-
return /^(\d)\1{5}$/.test(str);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
private static hasMoreThanThreeConsecutiveIdenticalDigits(str: string): boolean {
|
|
120
|
-
return /(\d)\1{3,}/.test(str);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
private static hasRepeatingPattern(str: string): boolean {
|
|
124
|
-
const half = str.slice(0, 3);
|
|
125
|
-
if (half.repeat(2) === str) return true;
|
|
126
|
-
|
|
127
|
-
const pairs = str.match(/(..)/g);
|
|
128
|
-
if (pairs && pairs.length === 3 && new Set(pairs).size === 1) return true;
|
|
129
|
-
|
|
130
|
-
const mirror = half + half.split('').reverse().join('');
|
|
131
|
-
if (str === mirror) return true;
|
|
132
|
-
|
|
133
|
-
return false;
|
|
134
|
-
}
|
|
135
|
-
}
|