Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | INFRASTRUCTURE & AUTOMATION4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : MacLustr SMS Gateway8 * File : ios/Scripts/dev-stack.ts9 * Description : Pile locale jetable pour la mise au point et les tests10 * d'interface : vrai serveur, vraie base, téléphone SIMULÉ11 * (aucun SMS réel). Lancé par dev-stack.sh depuis la racine12 * du dépôt. Écrit le jeton de session d'administration dans13 * ios/build/dev-session.txt.14 * Module : ios15 * Repository : https://git.spboucher.ai/maclustr-sms16 * Project Website : https://sms.spboucher.ai17 * Created : 2026-11-3018 * Last Modified : 2026-12-0119 *20 * Author : Simon-Pierre Boucher21 * Position : Professor of Finance22 * Institution : Université du Québec en Outaouais (UQO)23 * Organization : SP Boucher24 * Website : https://spboucher.ai25 * Git : https://git.spboucher.ai26 *27 * Preferred Contact: admin@spboucher.ai28 * Technical Contact: dev@spboucher.ai29 * Security/Admin : admin@spboucher.ai30 *31 * Copyright (c) 202632 * Simon-Pierre Boucher33 * All rights reserved where applicable. This file is governed by the34 * applicable project license, copyright notices and relevant law.35 * Existing third-party rights and notices remain unaffected.36 *37 * License : None specified (no license file in this repository)38 *39 * Do not embed credentials, private keys, access tokens,40 * certificates or confidential personal information.41 *42 * =============================================================================43 * END OF SP BOUCHER SOURCE HEADER44 * =============================================================================45 */4647import crypto from "node:crypto"48import { mkdirSync, writeFileSync } from "node:fs"49import { FakeDevice, ORIGIN, resetDatabase, sql, startServer, stopServer, until } from "../../backend/tests/harness.ts"5051const sha = (s: string) => crypto.createHash("sha256").update(s).digest("hex")52await resetDatabase()53await startServer()54const token = crypto.randomBytes(32).toString("base64url")55await sql`insert into users(id, handle, display_name) values ('usr_ios', 'essai', 'Essai iOS')`56await sql`insert into admin_sessions(id, user_id, expires_at) values (${sha(token)}, 'usr_ios', now() + interval '1 day')`57const code = "IOSTESTCODE2"58await sql`insert into pairing_codes(code_hash, name_hint, expires_at) values (${sha(code)}, 'Téléphone simulé', now() + interval '10 minutes')`59const dev = new FakeDevice()60dev.sims = [{ ...dev.sims[0], carrier_name: "Opérateur Essai", number: "+14185550124" }]61const r = await dev.pair(code, "Téléphone simulé")62if (r.status !== 201) throw new Error("association refusée : " + JSON.stringify(r.body))63await dev.connect()64await until(() => dev.outbox.length === 0, "inventaire SIM")65await sql`update sim_profiles set enabled = true`66await sql`insert into allowed_recipients(number, label) values ('+14185550123', 'Essai'), ('+14185550155', 'Opérateur sans accusé')`67// Un destinataire dont l'opérateur ne renvoie jamais d'accusé de livraison (cas réel de la ligne du propriétaire) : le message reste « remis au réseau ».68const process0 = dev.process.bind(dev)69dev.process = (c: any) => { dev.deliver = !String(c.to).endsWith("0155"); process0(c) }70await dev.close(); await dev.connect() // la reconnexion pousse la configuration (SIM activée)71mkdirSync("ios/build", { recursive: true })72writeFileSync("ios/build/dev-session.txt", token)73console.log(`pile prête : ${ORIGIN} · jeton écrit dans ios/build/dev-session.txt · téléphone simulé ${dev.deviceId}`)74// Commandes de pilotage sur l'entrée standard (pour les essais manuels) : « receive <numéro> <texte> », « mode ok|fail|unknown », « quit ».75process.stdin.setEncoding("utf8")76process.stdin.on("data", async (line: string) => {77 const [cmd, a, ...rest] = line.trim().split(" ")78 if (cmd === "receive") dev.receive(a, rest.join(" "))79 if (cmd === "mode") dev.mode = a as any80 if (cmd === "quit") { await dev.close(); await stopServer(); await sql.end(); process.exit(0) }81})82for (const s of ["SIGINT", "SIGTERM"] as const) process.once(s, async () => { await dev.close(); await stopServer(); process.exit(0) })83