11import { HTTPException } from 'hono/http-exception'
22import z from 'zod'
33import { zValidator } from '@hono/zod-validator'
4- import { ConfigStorageService } from '@shared/config-storage-service'
4+ import {
5+ ConfigStorageService ,
6+ ConfigStorageServiceError ,
7+ } from '@shared/config-storage-service'
58import { AWS_PREFIX } from '@shared/defines'
6- import { PROFILE_IDS , TOOLS } from '@shared/types'
9+ import {
10+ numberToBannerFontSize ,
11+ numberToWidgetFontSize ,
12+ PROFILE_IDS ,
13+ TOOLS ,
14+ } from '@shared/types'
715import type {
8- BannerConfig ,
16+ BaseToolProfile ,
917 ConfigVersions ,
1018 ElementConfigType ,
1119 Tool ,
1220 ToolProfile ,
13- WidgetConfig ,
1421} from '@shared/types'
1522import { app } from '../app.js'
1623import { createHTTPException } from '../utils/utils.js'
@@ -43,12 +50,17 @@ app.get(
4350 return json < ToolProfile < typeof tool > > ( profile )
4451 } catch ( error ) {
4552 if ( error instanceof HTTPException ) throw error
46- if ( error instanceof Error ) {
47- if ( error . message . includes ( '404' ) ) {
53+ if ( error instanceof ConfigStorageServiceError ) {
54+ if ( error . code === 'not-found' ) {
4855 const msg = 'No saved profile found for given wallet address'
4956 throw createHTTPException ( 404 , msg , {
50- message : 'Not found' , // can include the S3 key here perhaps
57+ message : 'Not found' ,
5158 code : '404' ,
59+ cause : {
60+ statusCode : error . statusCode ,
61+ code : error . code ,
62+ message : error . message ,
63+ } ,
5264 } )
5365 }
5466 }
@@ -62,6 +74,10 @@ function convertToProfile<T extends Tool>(
6274 config : ElementConfigType ,
6375 tool : T ,
6476) : ToolProfile < T > {
77+ if ( tool === 'offerwall' ) {
78+ return config . offerwall as ToolProfile < T >
79+ }
80+
6581 return {
6682 $version : '0.0.1' ,
6783 $name : config . versionName ,
@@ -70,30 +86,68 @@ function convertToProfile<T extends Tool>(
7086 } as ToolProfile < T >
7187}
7288
89+ /** @legacy */
7390function getToolProfile ( profile : ElementConfigType , tool : Tool ) {
74- switch ( tool ) {
75- case 'widget' :
76- return extract < WidgetConfig > (
77- profile ,
78- ( key ) => key . startsWith ( 'widget' ) || key . includes ( 'Widget' ) ,
79- )
80- case 'banner' :
81- return extract < BannerConfig > (
82- profile ,
83- ( key ) => key . startsWith ( 'banner' ) || key . includes ( 'Banner' ) ,
84- )
91+ if ( tool === 'banner' ) {
92+ return {
93+ title : {
94+ text : profile . bannerTitleText ,
95+ } ,
96+ description : {
97+ text : profile . bannerDescriptionText ,
98+ isVisible : profile . bannerDescriptionVisible ,
99+ } ,
100+ font : {
101+ name : profile . bannerFontName ,
102+ size : numberToBannerFontSize ( profile . bannerFontSize ) ,
103+ } ,
104+ animation : {
105+ type : profile . bannerSlideAnimation ,
106+ } ,
107+ position : profile . bannerPosition ,
108+ border : {
109+ type : profile . bannerBorder ,
110+ } ,
111+ color : {
112+ text : profile . bannerTextColor ,
113+ background : profile . bannerBackgroundColor ,
114+ } ,
115+ thumbnail : {
116+ value : profile . bannerThumbnail ,
117+ } ,
118+ } satisfies Omit < ToolProfile < 'banner' > , keyof BaseToolProfile >
85119 }
86- }
87-
88- function extract < R , T = ElementConfigType , K = keyof T > (
89- obj : T ,
90- filter : ( key : K ) => boolean ,
91- ) : R {
92- const entries = Object . entries ( obj as Record < string , unknown > ) . filter (
93- ( [ key ] ) => filter ( key as K ) ,
94- )
95- if ( ! entries . length ) {
96- throw new Error ( 'No matching profile found' )
120+ if ( tool === 'widget' ) {
121+ return {
122+ title : {
123+ text : profile . widgetTitleText ,
124+ } ,
125+ description : {
126+ text : profile . widgetDescriptionText ,
127+ isVisible : profile . widgetDescriptionVisible ,
128+ } ,
129+ font : {
130+ name : profile . widgetFontName ,
131+ size : numberToWidgetFontSize ( profile . widgetFontSize ) ,
132+ } ,
133+ position : profile . widgetPosition ,
134+ border : {
135+ type : profile . widgetButtonBorder ,
136+ } ,
137+ color : {
138+ text : profile . widgetTextColor ,
139+ background : profile . widgetBackgroundColor ,
140+ theme : profile . widgetButtonBackgroundColor ,
141+ } ,
142+ ctaPayButton : {
143+ text : profile . widgetButtonText ,
144+ } ,
145+ icon : {
146+ value : '' ,
147+ color : profile . widgetTriggerBackgroundColor ,
148+ } ,
149+ } satisfies Omit < ToolProfile < 'widget' > , keyof BaseToolProfile >
97150 }
98- return Object . fromEntries ( entries ) as R
151+
152+ throw new Error ( `Unsupported tool type: ${ tool } ` )
99153}
0 commit comments