Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 8
refactor(profile-editor): rebuild backend on web3-adapter for 2-way sync#985
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "watch": ["src"], | ||
| "ext": "ts,json", | ||
| "ignore": ["src/**/*.spec.ts"], | ||
| "exec": "ts-node src/index.ts" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import axios from "axios"; | ||
| import { env } from "./env"; | ||
| const USER_ONTOLOGY = "550e8400-e29b-41d4-a716-446655440000"; | ||
| const PROFESSIONAL_PROFILE_ONTOLOGY = "550e8400-e29b-41d4-a716-446655440009"; | ||
| /** | ||
| * Registers our `/api/webhook` as an AaaS subscription for the user and | ||
| * professional-profile ontologies (idempotent — skips if one already targets | ||
| * us). Logs and continues on failure so a down AaaS never blocks startup. | ||
| */ | ||
| export async function registerSubscriptionOnStartup(): Promise<void> { | ||
| if (!env.awarenessApiKey) { | ||
| console.warn( | ||
| "[aaas] AWARENESS_API_KEY not set — skipping subscription registration", | ||
| ); | ||
| return; | ||
| } | ||
| const targetUrl = | ||
| env.awarenessWebhookUrl || | ||
| `${env.baseUrl.replace(/\/$/, "")}/api/webhook`; | ||
| const headers = { Authorization: `Bearer ${env.awarenessApiKey}` }; | ||
| const base = env.awarenessServiceUrl.replace(/\/$/, ""); | ||
| try { | ||
| const { data } = await axios.get<{ | ||
| subscriptions: Array<{ targetUrl: string }>; | ||
| }>(`${base}/api/subscriptions`, { headers, timeout: 10000 }); | ||
| if (data.subscriptions?.some((s) => s.targetUrl === targetUrl)) { | ||
| console.log("[aaas] subscription already registered"); | ||
| return; | ||
| } | ||
| await axios.post( | ||
| `${base}/api/subscriptions`, | ||
| { | ||
| targetUrl, | ||
| ontologyFilter: [USER_ONTOLOGY, PROFESSIONAL_PROFILE_ONTOLOGY], | ||
| evaultFilter: [], | ||
| }, | ||
| { headers, timeout: 10000 }, | ||
| ); | ||
| console.log(`[aaas] subscription registered -> ${targetUrl}`); | ||
| } catch (error) { | ||
| const message = axios.isAxiosError(error) | ||
| ? (error.response?.data?.error ?? error.message) | ||
| : (error as Error).message; | ||
| console.error( | ||
| "[aaas] subscription registration failed (continuing):", | ||
| message, | ||
| ); | ||
| } | ||
| } | ||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing null check for
env.awarenessServiceUrlmay cause runtime TypeError.The function checks
env.awarenessApiKeyon line 13, but proceeds to useenv.awarenessServiceUrl.replace()on line 24 without verifying it's defined. If the API key is set but the service URL is not, this will throw aTypeError: Cannot read properties of undefined (reading 'replace'), bypassing the graceful error handling.Similarly,
env.baseUrlis used on line 22 without a guard whenenv.awarenessWebhookUrlis not set.🛡️ Proposed fix to validate required config
export async function registerSubscriptionOnStartup(): Promise<void> { - if (!env.awarenessApiKey) {+ if (!env.awarenessApiKey || !env.awarenessServiceUrl) { console.warn( - "[aaas] AWARENESS_API_KEY not set — skipping subscription registration",+ "[aaas] AWARENESS_API_KEY or AWARENESS_SERVICE_URL not set — skipping subscription registration", ); return; } + if (!env.awarenessWebhookUrl && !env.baseUrl) {+ console.warn(+ "[aaas] Neither AWARENESS_WEBHOOK_URL nor BASE_URL set — skipping subscription registration",+ );+ return;+ }+ const targetUrl = env.awarenessWebhookUrl || `${env.baseUrl.replace(/\/$/, "")}/api/webhook`;🤖 Prompt for AI Agents