@hackfed/toolbox 0.1.4 → 0.2.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.
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@hackfed/toolbox",
3
3
  "description": "Tools for Hackfed Registry",
4
- "version": "0.1.4",
4
+ "version": "0.2.1",
5
5
  "bin": {
6
6
  "hackfed-toolbox": "src/index.ts"
7
7
  },
8
8
  "dependencies": {
9
- "@hackfed/schemas": "^0.7.0",
9
+ "@hackfed/schemas": "^0.8.0",
10
10
  "commander": "^14.0.2",
11
11
  "ipaddr.js": "^2.3.0",
12
12
  "tslog": "^4.10.2",
@@ -36,6 +36,6 @@
36
36
  },
37
37
  "type": "module",
38
38
  "scripts": {
39
- "lint": "tsc --noEmit && eslint ."
39
+ "check": "tsc --noEmit && eslint ."
40
40
  }
41
41
  }
@@ -167,7 +167,6 @@ async function checkTelephonyService (context: CheckServiceContext): Promise<voi
167
167
  }
168
168
 
169
169
  const orgExchanges = new Set<string>()
170
- const orgPrefixes = new Set<string>()
171
170
 
172
171
  if (org.spec.services.telephony.exchanges) {
173
172
  for (const exchange of org.spec.services.telephony.exchanges) {
@@ -189,32 +188,14 @@ async function checkTelephonyService (context: CheckServiceContext): Promise<voi
189
188
  process.exit(1)
190
189
  }
191
190
 
192
- orgExchanges.add(exchange.id)
193
- }
194
- }
195
-
196
- if (org.spec.services.telephony.prefixes) {
197
- for (const prefix of org.spec.services.telephony.prefixes) {
198
191
  // Check for duplicate prefixes across organizations
199
- if (prefixes.has(prefix.prefix)) {
200
- context.logger.error('(%s) duplicate Telephony prefix found: %s', org.spec.id, prefix.prefix)
192
+ if (prefixes.has(exchange.prefix)) {
193
+ context.logger.error('(%s) duplicate Telephony prefix found: %s', org.spec.id, exchange.prefix)
201
194
  process.exit(1)
202
195
  }
203
196
 
204
- // Check for duplicate prefixes within organization
205
- if (orgPrefixes.has(prefix.prefix)) {
206
- context.logger.error('(%s) duplicate Telephony prefix found within organization: %s', org.spec.id, prefix.prefix)
207
- process.exit(1)
208
- }
209
-
210
- // Verify that referenced exchange exists
211
- if (!orgExchanges.has(prefix.exchange)) {
212
- context.logger.error('(%s) Telephony prefix references unknown exchange: %s', org.spec.id, prefix.exchange)
213
- process.exit(1)
214
- }
215
-
216
- prefixes.add(prefix.prefix)
217
- orgPrefixes.add(prefix.prefix)
197
+ prefixes.add(exchange.prefix)
198
+ orgExchanges.add(exchange.id)
218
199
  }
219
200
  }
220
201
  }
@@ -1,6 +1,12 @@
1
1
  import type { Command } from 'commander'
2
2
 
3
- import { OrganizationSchema, type TelephonyDirectory, type TelephonyDirectoryExchange, type TelephonyDirectoryOrg } from '@hackfed/schemas/v1'
3
+ import {
4
+ OrganizationSchema,
5
+ type TelephonyDirectory,
6
+ type TelephonyDirectoryExchange,
7
+ type TelephonyDirectoryOrg,
8
+ TelephonyDirectorySchema,
9
+ } from '@hackfed/schemas/v1'
4
10
  import { Glob, YAML } from 'bun'
5
11
  import path from 'node:path'
6
12
  import { type Logger } from 'tslog'
@@ -44,14 +50,6 @@ async function generateTelephonyDirectory (
44
50
  continue
45
51
  }
46
52
 
47
- // Map prefixes to exchanges
48
- const exchangePrefixes = new Map<string, Set<string>>()
49
- for (const prefix of org.spec.services.telephony.prefixes ?? []) {
50
- const prefixes = exchangePrefixes.get(prefix.exchange) ?? new Set<string>()
51
- prefixes.add(prefix.prefix)
52
- exchangePrefixes.set(prefix.exchange, prefixes)
53
- }
54
-
55
53
  // Map exchanges
56
54
  const exchanges = new Map<string, TelephonyDirectoryExchange>()
57
55
  for (const exchange of org.spec.services.telephony.exchanges ?? []) {
@@ -59,7 +57,7 @@ async function generateTelephonyDirectory (
59
57
  codecs: exchange.codecs,
60
58
  endpoint: exchange.address,
61
59
  id: exchange.id,
62
- prefixes: [...exchangePrefixes.get(exchange.id) ?? []],
60
+ prefix: exchange.prefix,
63
61
  protocol: exchange.protocol
64
62
  })
65
63
  }
@@ -68,15 +66,15 @@ async function generateTelephonyDirectory (
68
66
  exchanges: [...exchanges.values()],
69
67
  name: org.spec.name,
70
68
  orgId: org.spec.id,
71
- phonebooks: org.spec.services.telephony.phonebook ?? []
69
+ phonebook: org.spec.services.telephony.phonebook,
72
70
  })
73
71
 
74
72
  logger.debug('Added organization: %s (%s)', org.spec.name, org.spec.id)
75
73
  }
76
74
 
77
- const directory: TelephonyDirectory = {
75
+ const directory = TelephonyDirectorySchema.parse({
78
76
  orgs,
79
- }
77
+ } satisfies TelephonyDirectory)
80
78
 
81
79
  const file = Bun.file(path.resolve(options.output))
82
80
  await Bun.write(file, JSON.stringify(directory))