@fonoster/identity 0.18.1 → 0.19.1

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.
@@ -36,11 +36,11 @@ exports.Prisma = Prisma
36
36
  exports.$Enums = {}
37
37
 
38
38
  /**
39
- * Prisma Client JS version: 6.19.1
39
+ * Prisma Client JS version: 6.19.2
40
40
  * Query Engine version: c2990dca591cba766e3b7ef5d9e8a84796e47ab7
41
41
  */
42
42
  Prisma.prismaVersion = {
43
- client: "6.19.1",
43
+ client: "6.19.2",
44
44
  engine: "c2990dca591cba766e3b7ef5d9e8a84796e47ab7"
45
45
  }
46
46
 
@@ -228,7 +228,7 @@ const config = {
228
228
  "rootEnvPath": null
229
229
  },
230
230
  "relativePath": "../../../..",
231
- "clientVersion": "6.19.1",
231
+ "clientVersion": "6.19.2",
232
232
  "engineVersion": "c2990dca591cba766e3b7ef5d9e8a84796e47ab7",
233
233
  "datasourceNames": [
234
234
  "db"
package/dist/index.d.ts CHANGED
@@ -16,6 +16,7 @@
16
16
  * See the License for the specific language governing permissions and
17
17
  * limitations under the License.
18
18
  */
19
+ export * from "./allowList";
19
20
  export * from "./apikeys";
20
21
  export * from "./exchanges";
21
22
  export * from "./invites";
package/dist/index.js CHANGED
@@ -32,6 +32,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
32
32
  * See the License for the specific language governing permissions and
33
33
  * limitations under the License.
34
34
  */
35
+ __exportStar(require("./allowList"), exports);
35
36
  __exportStar(require("./apikeys"), exports);
36
37
  __exportStar(require("./exchanges"), exports);
37
38
  __exportStar(require("./invites"), exports);
@@ -0,0 +1,276 @@
1
+ import { z } from "zod";
2
+ import { IdentityConfig } from "../exchanges/types";
3
+ declare const identityServiceConfigSchema: z.ZodObject<{
4
+ server: z.ZodDefault<z.ZodObject<{
5
+ bindAddr: z.ZodDefault<z.ZodString>;
6
+ httpBridgePort: z.ZodDefault<z.ZodNumber>;
7
+ }, "strip", z.ZodTypeAny, {
8
+ bindAddr?: string;
9
+ httpBridgePort?: number;
10
+ }, {
11
+ bindAddr?: string;
12
+ httpBridgePort?: number;
13
+ }>>;
14
+ database: z.ZodObject<{
15
+ url: z.ZodString;
16
+ }, "strip", z.ZodTypeAny, {
17
+ url?: string;
18
+ }, {
19
+ url?: string;
20
+ }>;
21
+ encryptionKey: z.ZodString;
22
+ issuer: z.ZodString;
23
+ audience: z.ZodString;
24
+ keys: z.ZodEffects<z.ZodObject<{
25
+ privateKey: z.ZodOptional<z.ZodString>;
26
+ publicKey: z.ZodOptional<z.ZodString>;
27
+ privateKeyPath: z.ZodOptional<z.ZodString>;
28
+ publicKeyPath: z.ZodOptional<z.ZodString>;
29
+ }, "strip", z.ZodTypeAny, {
30
+ privateKey?: string;
31
+ publicKey?: string;
32
+ privateKeyPath?: string;
33
+ publicKeyPath?: string;
34
+ }, {
35
+ privateKey?: string;
36
+ publicKey?: string;
37
+ privateKeyPath?: string;
38
+ publicKeyPath?: string;
39
+ }>, {
40
+ privateKey?: string;
41
+ publicKey?: string;
42
+ privateKeyPath?: string;
43
+ publicKeyPath?: string;
44
+ }, {
45
+ privateKey?: string;
46
+ publicKey?: string;
47
+ privateKeyPath?: string;
48
+ publicKeyPath?: string;
49
+ }>;
50
+ tokens: z.ZodDefault<z.ZodObject<{
51
+ accessTokenExpiresIn: z.ZodDefault<z.ZodString>;
52
+ refreshTokenExpiresIn: z.ZodDefault<z.ZodString>;
53
+ idTokenExpiresIn: z.ZodDefault<z.ZodString>;
54
+ }, "strip", z.ZodTypeAny, {
55
+ idTokenExpiresIn?: string;
56
+ accessTokenExpiresIn?: string;
57
+ refreshTokenExpiresIn?: string;
58
+ }, {
59
+ idTokenExpiresIn?: string;
60
+ accessTokenExpiresIn?: string;
61
+ refreshTokenExpiresIn?: string;
62
+ }>>;
63
+ security: z.ZodDefault<z.ZodObject<{
64
+ contactVerificationRequired: z.ZodDefault<z.ZodBoolean>;
65
+ twoFactorAuthenticationRequired: z.ZodDefault<z.ZodBoolean>;
66
+ }, "strip", z.ZodTypeAny, {
67
+ contactVerificationRequired?: boolean;
68
+ twoFactorAuthenticationRequired?: boolean;
69
+ }, {
70
+ contactVerificationRequired?: boolean;
71
+ twoFactorAuthenticationRequired?: boolean;
72
+ }>>;
73
+ invite: z.ZodDefault<z.ZodObject<{
74
+ url: z.ZodDefault<z.ZodString>;
75
+ failUrl: z.ZodDefault<z.ZodString>;
76
+ expiration: z.ZodDefault<z.ZodString>;
77
+ }, "strip", z.ZodTypeAny, {
78
+ url?: string;
79
+ failUrl?: string;
80
+ expiration?: string;
81
+ }, {
82
+ url?: string;
83
+ failUrl?: string;
84
+ expiration?: string;
85
+ }>>;
86
+ appUrl: z.ZodDefault<z.ZodString>;
87
+ smtp: z.ZodOptional<z.ZodObject<{
88
+ host: z.ZodString;
89
+ port: z.ZodNumber;
90
+ secure: z.ZodDefault<z.ZodBoolean>;
91
+ sender: z.ZodString;
92
+ auth: z.ZodDefault<z.ZodObject<{
93
+ user: z.ZodDefault<z.ZodString>;
94
+ pass: z.ZodDefault<z.ZodString>;
95
+ }, "strip", z.ZodTypeAny, {
96
+ user?: string;
97
+ pass?: string;
98
+ }, {
99
+ user?: string;
100
+ pass?: string;
101
+ }>>;
102
+ }, "strip", z.ZodTypeAny, {
103
+ host?: string;
104
+ port?: number;
105
+ secure?: boolean;
106
+ sender?: string;
107
+ auth?: {
108
+ user?: string;
109
+ pass?: string;
110
+ };
111
+ }, {
112
+ host?: string;
113
+ port?: number;
114
+ secure?: boolean;
115
+ sender?: string;
116
+ auth?: {
117
+ user?: string;
118
+ pass?: string;
119
+ };
120
+ }>>;
121
+ oauth2: z.ZodOptional<z.ZodObject<{
122
+ github: z.ZodObject<{
123
+ clientId: z.ZodString;
124
+ clientSecret: z.ZodString;
125
+ }, "strip", z.ZodTypeAny, {
126
+ clientId?: string;
127
+ clientSecret?: string;
128
+ }, {
129
+ clientId?: string;
130
+ clientSecret?: string;
131
+ }>;
132
+ }, "strip", z.ZodTypeAny, {
133
+ github?: {
134
+ clientId?: string;
135
+ clientSecret?: string;
136
+ };
137
+ }, {
138
+ github?: {
139
+ clientId?: string;
140
+ clientSecret?: string;
141
+ };
142
+ }>>;
143
+ defaultUser: z.ZodOptional<z.ZodObject<{
144
+ name: z.ZodString;
145
+ email: z.ZodString;
146
+ password: z.ZodString;
147
+ }, "strip", z.ZodTypeAny, {
148
+ name?: string;
149
+ email?: string;
150
+ password?: string;
151
+ }, {
152
+ name?: string;
153
+ email?: string;
154
+ password?: string;
155
+ }>>;
156
+ }, "strip", z.ZodTypeAny, {
157
+ keys?: {
158
+ privateKey?: string;
159
+ publicKey?: string;
160
+ privateKeyPath?: string;
161
+ publicKeyPath?: string;
162
+ };
163
+ issuer?: string;
164
+ audience?: string;
165
+ server?: {
166
+ bindAddr?: string;
167
+ httpBridgePort?: number;
168
+ };
169
+ database?: {
170
+ url?: string;
171
+ };
172
+ encryptionKey?: string;
173
+ tokens?: {
174
+ idTokenExpiresIn?: string;
175
+ accessTokenExpiresIn?: string;
176
+ refreshTokenExpiresIn?: string;
177
+ };
178
+ security?: {
179
+ contactVerificationRequired?: boolean;
180
+ twoFactorAuthenticationRequired?: boolean;
181
+ };
182
+ invite?: {
183
+ url?: string;
184
+ failUrl?: string;
185
+ expiration?: string;
186
+ };
187
+ appUrl?: string;
188
+ smtp?: {
189
+ host?: string;
190
+ port?: number;
191
+ secure?: boolean;
192
+ sender?: string;
193
+ auth?: {
194
+ user?: string;
195
+ pass?: string;
196
+ };
197
+ };
198
+ oauth2?: {
199
+ github?: {
200
+ clientId?: string;
201
+ clientSecret?: string;
202
+ };
203
+ };
204
+ defaultUser?: {
205
+ name?: string;
206
+ email?: string;
207
+ password?: string;
208
+ };
209
+ }, {
210
+ keys?: {
211
+ privateKey?: string;
212
+ publicKey?: string;
213
+ privateKeyPath?: string;
214
+ publicKeyPath?: string;
215
+ };
216
+ issuer?: string;
217
+ audience?: string;
218
+ server?: {
219
+ bindAddr?: string;
220
+ httpBridgePort?: number;
221
+ };
222
+ database?: {
223
+ url?: string;
224
+ };
225
+ encryptionKey?: string;
226
+ tokens?: {
227
+ idTokenExpiresIn?: string;
228
+ accessTokenExpiresIn?: string;
229
+ refreshTokenExpiresIn?: string;
230
+ };
231
+ security?: {
232
+ contactVerificationRequired?: boolean;
233
+ twoFactorAuthenticationRequired?: boolean;
234
+ };
235
+ invite?: {
236
+ url?: string;
237
+ failUrl?: string;
238
+ expiration?: string;
239
+ };
240
+ appUrl?: string;
241
+ smtp?: {
242
+ host?: string;
243
+ port?: number;
244
+ secure?: boolean;
245
+ sender?: string;
246
+ auth?: {
247
+ user?: string;
248
+ pass?: string;
249
+ };
250
+ };
251
+ oauth2?: {
252
+ github?: {
253
+ clientId?: string;
254
+ clientSecret?: string;
255
+ };
256
+ };
257
+ defaultUser?: {
258
+ name?: string;
259
+ email?: string;
260
+ password?: string;
261
+ };
262
+ }>;
263
+ type IdentityServiceConfig = z.infer<typeof identityServiceConfigSchema>;
264
+ /** Loads and validates the service configuration from the file, failing fast. */
265
+ declare function loadConfig(argv?: string[]): {
266
+ bindAddr: string;
267
+ httpBridgePort: number;
268
+ appUrl: string;
269
+ defaultUser: {
270
+ name?: string;
271
+ email?: string;
272
+ password?: string;
273
+ };
274
+ identityConfig: IdentityConfig;
275
+ };
276
+ export { identityServiceConfigSchema, IdentityServiceConfig, loadConfig };
@@ -0,0 +1,154 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.identityServiceConfigSchema = void 0;
4
+ exports.loadConfig = loadConfig;
5
+ /**
6
+ * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
7
+ * http://github.com/fonoster/fonoster
8
+ *
9
+ * This file is part of Fonoster
10
+ *
11
+ * Licensed under the MIT License (the "License");
12
+ * you may not use this file except in compliance with
13
+ * the License. You may obtain a copy of the License at
14
+ *
15
+ * https://opensource.org/licenses/MIT
16
+ *
17
+ * Unless required by applicable law or agreed to in writing, software
18
+ * distributed under the License is distributed on an "AS IS" BASIS,
19
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
+ * See the License for the specific language governing permissions and
21
+ * limitations under the License.
22
+ */
23
+ const fs_1 = require("fs");
24
+ const path_1 = require("path");
25
+ const zod_1 = require("zod");
26
+ const zod_validation_error_1 = require("zod-validation-error");
27
+ /**
28
+ * Configuration for the standalone Identity service.
29
+ *
30
+ * The service is configured exclusively from a JSON configuration file — no
31
+ * environment variables. The file path is taken from a `--config <path>` CLI
32
+ * flag, defaulting to `./config/identity.json` relative to the working
33
+ * directory.
34
+ */
35
+ const keysSchema = zod_1.z
36
+ .object({
37
+ privateKey: zod_1.z.string().optional(),
38
+ publicKey: zod_1.z.string().optional(),
39
+ privateKeyPath: zod_1.z.string().optional(),
40
+ publicKeyPath: zod_1.z.string().optional()
41
+ })
42
+ .refine((k) => (k.privateKey || k.privateKeyPath) && (k.publicKey || k.publicKeyPath), {
43
+ message: "keys must provide a private and public key, inline or by path"
44
+ });
45
+ const smtpSchema = zod_1.z.object({
46
+ host: zod_1.z.string(),
47
+ port: zod_1.z.number(),
48
+ secure: zod_1.z.boolean().default(false),
49
+ sender: zod_1.z.string(),
50
+ auth: zod_1.z
51
+ .object({ user: zod_1.z.string().default(""), pass: zod_1.z.string().default("") })
52
+ .default({})
53
+ });
54
+ const identityServiceConfigSchema = zod_1.z.object({
55
+ server: zod_1.z
56
+ .object({
57
+ bindAddr: zod_1.z.string().default("0.0.0.0:50051"),
58
+ httpBridgePort: zod_1.z.number().default(9000)
59
+ })
60
+ .default({}),
61
+ database: zod_1.z.object({ url: zod_1.z.string().min(1) }),
62
+ encryptionKey: zod_1.z.string().min(1),
63
+ issuer: zod_1.z.string().min(1),
64
+ audience: zod_1.z.string().min(1),
65
+ keys: keysSchema,
66
+ tokens: zod_1.z
67
+ .object({
68
+ accessTokenExpiresIn: zod_1.z.string().default("15m"),
69
+ refreshTokenExpiresIn: zod_1.z.string().default("30d"),
70
+ idTokenExpiresIn: zod_1.z.string().default("15m")
71
+ })
72
+ .default({}),
73
+ security: zod_1.z
74
+ .object({
75
+ contactVerificationRequired: zod_1.z.boolean().default(false),
76
+ twoFactorAuthenticationRequired: zod_1.z.boolean().default(false)
77
+ })
78
+ .default({}),
79
+ invite: zod_1.z
80
+ .object({
81
+ url: zod_1.z.string().default(""),
82
+ failUrl: zod_1.z.string().default(""),
83
+ expiration: zod_1.z.string().default("2d")
84
+ })
85
+ .default({}),
86
+ appUrl: zod_1.z.string().default(""),
87
+ smtp: smtpSchema.optional(),
88
+ oauth2: zod_1.z
89
+ .object({
90
+ github: zod_1.z.object({ clientId: zod_1.z.string(), clientSecret: zod_1.z.string() })
91
+ })
92
+ .optional(),
93
+ defaultUser: zod_1.z
94
+ .object({
95
+ name: zod_1.z.string(),
96
+ email: zod_1.z.string().email(),
97
+ password: zod_1.z.string()
98
+ })
99
+ .optional()
100
+ });
101
+ exports.identityServiceConfigSchema = identityServiceConfigSchema;
102
+ function configPathFromArgv(argv) {
103
+ const i = argv.indexOf("--config");
104
+ const fromFlag = i >= 0 ? argv[i + 1] : undefined;
105
+ return (0, path_1.resolve)(process.cwd(), fromFlag !== null && fromFlag !== void 0 ? fromFlag : "./config/identity.json");
106
+ }
107
+ function readKey(inline, path) {
108
+ return inline !== null && inline !== void 0 ? inline : (0, fs_1.readFileSync)((0, path_1.resolve)(process.cwd(), path), "utf8");
109
+ }
110
+ /** Maps the file config into the `IdentityConfig` shape `buildIdentityService` expects. */
111
+ function toIdentityConfig(c) {
112
+ var _a;
113
+ return {
114
+ dbUrl: c.database.url,
115
+ issuer: c.issuer,
116
+ audience: c.audience,
117
+ privateKey: readKey(c.keys.privateKey, c.keys.privateKeyPath),
118
+ publicKey: readKey(c.keys.publicKey, c.keys.publicKeyPath),
119
+ encryptionKey: c.encryptionKey,
120
+ accessTokenExpiresIn: c.tokens.accessTokenExpiresIn,
121
+ refreshTokenExpiresIn: c.tokens.refreshTokenExpiresIn,
122
+ idTokenExpiresIn: c.tokens.idTokenExpiresIn,
123
+ workspaceInviteExpiration: c.invite.expiration,
124
+ workspaceInviteUrl: c.invite.url,
125
+ workspaceInviteFailUrl: c.invite.failUrl,
126
+ contactVerificationRequired: c.security.contactVerificationRequired,
127
+ twoFactorAuthenticationRequired: c.security.twoFactorAuthenticationRequired,
128
+ smtpConfig: c.smtp,
129
+ githubOauth2Config: (_a = c.oauth2) === null || _a === void 0 ? void 0 : _a.github
130
+ };
131
+ }
132
+ /** Loads and validates the service configuration from the file, failing fast. */
133
+ function loadConfig(argv = process.argv) {
134
+ const path = configPathFromArgv(argv);
135
+ let raw;
136
+ try {
137
+ raw = JSON.parse((0, fs_1.readFileSync)(path, "utf8"));
138
+ }
139
+ catch (e) {
140
+ throw new Error(`unable to read Identity config at ${path}: ${e.message}`);
141
+ }
142
+ const result = identityServiceConfigSchema.safeParse(raw);
143
+ if (!result.success) {
144
+ throw new Error(`invalid Identity config at ${path}: ${(0, zod_validation_error_1.fromError)(result.error).toString()}`);
145
+ }
146
+ const config = result.data;
147
+ return {
148
+ bindAddr: config.server.bindAddr,
149
+ httpBridgePort: config.server.httpBridgePort,
150
+ appUrl: config.appUrl,
151
+ defaultUser: config.defaultUser,
152
+ identityConfig: toIdentityConfig(config)
153
+ };
154
+ }
@@ -0,0 +1,10 @@
1
+ import { IdentityConfig } from "../exchanges/types";
2
+ /**
3
+ * Minimal HTTP bridge for the standalone Identity service. It serves only the
4
+ * accept-invite endpoint (the apiserver's bridge also serves telephony routes).
5
+ */
6
+ declare function startHttpBridge(identityConfig: IdentityConfig, params: {
7
+ port: number;
8
+ appUrl: string;
9
+ }): import("express-serve-static-core").Express;
10
+ export { startHttpBridge };
@@ -0,0 +1,59 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.startHttpBridge = startHttpBridge;
16
+ /**
17
+ * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
18
+ * http://github.com/fonoster/fonoster
19
+ *
20
+ * This file is part of Fonoster
21
+ *
22
+ * Licensed under the MIT License (the "License");
23
+ * you may not use this file except in compliance with
24
+ * the License. You may obtain a copy of the License at
25
+ *
26
+ * https://opensource.org/licenses/MIT
27
+ *
28
+ * Unless required by applicable law or agreed to in writing, software
29
+ * distributed under the License is distributed on an "AS IS" BASIS,
30
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31
+ * See the License for the specific language governing permissions and
32
+ * limitations under the License.
33
+ */
34
+ const logger_1 = require("@fonoster/logger");
35
+ const express_1 = __importDefault(require("express"));
36
+ const utils_1 = require("../utils");
37
+ const logger = (0, logger_1.getLogger)({ service: "identity", filePath: __filename });
38
+ /**
39
+ * Minimal HTTP bridge for the standalone Identity service. It serves only the
40
+ * accept-invite endpoint (the apiserver's bridge also serves telephony routes).
41
+ */
42
+ function startHttpBridge(identityConfig, params) {
43
+ const { port, appUrl } = params;
44
+ const app = (0, express_1.default)();
45
+ app.get("/api/identity/accept-invite", (req, res) => __awaiter(this, void 0, void 0, function* () {
46
+ try {
47
+ yield (0, utils_1.createUpdateMembershipStatus)(identityConfig)(req.query.token);
48
+ res.redirect(appUrl);
49
+ }
50
+ catch (error) {
51
+ logger.verbose("error updating membership status", error);
52
+ res.redirect(identityConfig.workspaceInviteFailUrl);
53
+ }
54
+ }));
55
+ app.listen(port, () => {
56
+ logger.info(`Identity HTTP bridge running on port ${port}`);
57
+ });
58
+ return app;
59
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
+ return new (P || (P = Promise))(function (resolve, reject) {
38
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
42
+ });
43
+ };
44
+ Object.defineProperty(exports, "__esModule", { value: true });
45
+ /**
46
+ * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
47
+ * http://github.com/fonoster/fonoster
48
+ *
49
+ * This file is part of Fonoster
50
+ *
51
+ * Licensed under the MIT License (the "License");
52
+ * you may not use this file except in compliance with
53
+ * the License. You may obtain a copy of the License at
54
+ *
55
+ * https://opensource.org/licenses/MIT
56
+ *
57
+ * Unless required by applicable law or agreed to in writing, software
58
+ * distributed under the License is distributed on an "AS IS" BASIS,
59
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
60
+ * See the License for the specific language governing permissions and
61
+ * limitations under the License.
62
+ */
63
+ const common_1 = require("@fonoster/common");
64
+ const logger_1 = require("@fonoster/logger");
65
+ const grpc = __importStar(require("@grpc/grpc-js"));
66
+ const grpc_health_check_1 = require("grpc-health-check");
67
+ const __1 = require("..");
68
+ const config_1 = require("./config");
69
+ const httpBridge_1 = require("./httpBridge");
70
+ const logger = (0, logger_1.getLogger)({ service: "identity", filePath: __filename });
71
+ /**
72
+ * Standalone Identity gRPC service. Wraps `buildIdentityService` with the auth
73
+ * interceptor, the identity allow-list, a health service, and the accept-invite
74
+ * HTTP bridge — without any telephony subsystem. Configured entirely from a
75
+ * file (see `./config`); no environment variables.
76
+ */
77
+ function main() {
78
+ return __awaiter(this, void 0, void 0, function* () {
79
+ const { bindAddr, httpBridgePort, appUrl, defaultUser, identityConfig } = (0, config_1.loadConfig)();
80
+ const { definition, handlers } = (0, __1.buildIdentityService)(identityConfig);
81
+ const authorization = (0, common_1.createAuthInterceptor)(identityConfig.publicKey, __1.identityAllowList);
82
+ const credentials = yield (0, common_1.getServerCredentials)({});
83
+ const healthImpl = new grpc_health_check_1.HealthImplementation(common_1.statusMap);
84
+ const server = new grpc.Server({ interceptors: [authorization] });
85
+ healthImpl.addToServer(server);
86
+ server.addService((0, common_1.createServiceDefinition)(definition), handlers);
87
+ if (defaultUser) {
88
+ yield (0, __1.upsertDefaultUser)(identityConfig, defaultUser);
89
+ }
90
+ (0, httpBridge_1.startHttpBridge)(identityConfig, { port: httpBridgePort, appUrl });
91
+ server.bindAsync(bindAddr, credentials, (error) => {
92
+ if (error) {
93
+ logger.error("failed to start Identity service", error);
94
+ process.exit(1);
95
+ }
96
+ healthImpl.setStatus("", common_1.GRPC_SERVING_STATUS);
97
+ logger.info(`Identity service running at ${bindAddr}`);
98
+ });
99
+ });
100
+ }
101
+ main().catch((error) => {
102
+ logger.error(error);
103
+ process.exit(1);
104
+ });