MCPcopy Create free account
hub / github.com/dailydotdev/apps / toPatchyConfig

Function toPatchyConfig

packages/shared/src/features/patchy/patchyConfig.ts:206–265  ·  view source on GitHub ↗
(
  response: Partial<PatchyConfigResponse> | null | undefined,
)

Source from the content-addressed store, hash-verified

204// Layers the API config over the defaults one field at a time, so a missing,
205// malformed or unknown value can only ever fall back, never break Patchy.
206export const toPatchyConfig = (
207 response: Partial<PatchyConfigResponse> | null | undefined,
208): PatchyConfig => {
209 const fallback = defaultPatchyConfig;
210 if (!response || typeof response !== 'object') {
211 return fallback;
212 }
213
214 const faceImage = { ...fallback.faceImage };
215 response.faces?.forEach(({ face, image }) => {
216 if (isOneOf(patchyFaces, face) && isText(image)) {
217 faceImage[face] = image;
218 }
219 });
220
221 const reactions = { ...fallback.reactions };
222 response.reactions?.forEach((reaction) => {
223 if (!isOneOf(patchyTriggers, reaction?.trigger)) {
224 return;
225 }
226 const base = fallback.reactions[reaction.trigger];
227 reactions[reaction.trigger] = {
228 enabled:
229 typeof reaction.enabled === 'boolean' ? reaction.enabled : base.enabled,
230 emote: isOneOf(patchyEmotes, reaction.emote)
231 ? reaction.emote
232 : base.emote,
233 face: isOneOf(patchyFaces, reaction.face) ? reaction.face : base.face,
234 };
235 });
236
237 const moods = { ...fallback.moods };
238 response.moods?.forEach((mood) => {
239 if (!isOneOf(patchyMoods, mood?.mood)) {
240 return;
241 }
242 const base = fallback.moods[mood.mood];
243 moods[mood.mood] = {
244 face: isOneOf(patchyFaces, mood.face) ? mood.face : base.face,
245 copy: isText(mood.copy) ? mood.copy : base.copy,
246 label: isText(mood.label) ? mood.label : base.label,
247 };
248 });
249
250 const fridayTags = response.fridayDeploy?.tags?.filter(isText);
251
252 return {
253 awayMs: isCount(response.awayHours)
254 ? response.awayHours * HOUR
255 : fallback.awayMs,
256 lateNight: toWindow(response.lateNight, fallback.lateNight),
257 fridayDeploy: {
258 ...toWindow(response.fridayDeploy, fallback.fridayDeploy),
259 tags: fridayTags?.length ? fridayTags : fallback.fridayDeploy.tags,
260 },
261 faceImage,
262 reactions,
263 moods,

Callers 2

getPatchyConfigFunction · 0.85

Calls 4

toWindowFunction · 0.85
isOneOfFunction · 0.70
isTextFunction · 0.70
isCountFunction · 0.70

Tested by

no test coverage detected