UNPKG

@haelp/teto

Version:

A typescript-based controllable TETR.IO client.

1 lines 2.73 kB
{"version":3,"sources":["../../../src/utils/api/relationship.ts"],"sourcesContent":["import { type APIDefaults } from \".\";\nimport type { Social } from \"../../types\";\nimport type { Get, Post } from \"./basic\";\n\nexport const relationship = (get: Get, post: Post, __: APIDefaults) => {\n const removeRelationship = async (id: string) => {\n const res = await post<{ success: boolean }>({\n uri: \"relationships/remove\",\n body: { user: id }\n });\n\n if (res.success === false) throw new Error(\"Failed to remove relationship\");\n return true;\n };\n\n return {\n /** Block a user */\n block: async (id: string) => {\n const res = await post<{}>({\n uri: \"relationships/block\",\n body: { user: id }\n });\n\n if (res.success === false) throw new Error(res.error.msg);\n return res.success;\n },\n\n /** Unblock a user. Note: unblocking a user will unfriend them if they are friended. */\n unblock: removeRelationship,\n\n /** Friend a user */\n friend: async (id: string) => {\n const res = await post<{}>({\n uri: \"relationships/friend\",\n body: { user: id }\n });\n\n if (res.success === false) throw new Error(res.error.msg);\n return res.success;\n },\n\n /** Unfriend a user. Note: unfriending a user will unblock them if they are blocked. */\n unfriend: removeRelationship,\n\n dms: async (id: string) => {\n const res = await get<{\n dms: Social.DM[];\n }>({\n uri: `dms/${id}`\n });\n if (res.success === false) throw new Error(res.error.msg);\n return res.dms;\n }\n };\n};\n"],"names":["relationship","get","post","__","removeRelationship","id","res","uri","body","user","success","Error","block","error","msg","unblock","friend","unfriend","dms"],"mappings":"AAIA,OAAO,MAAMA,eAAe,CAACC,KAAUC,MAAYC;IACjD,MAAMC,qBAAqB,OAAOC;QAChC,MAAMC,MAAM,MAAMJ,KAA2B;YAC3CK,KAAK;YACLC,MAAM;gBAAEC,MAAMJ;YAAG;QACnB;QAEA,IAAIC,IAAII,OAAO,KAAK,OAAO,MAAM,IAAIC,MAAM;QAC3C,OAAO;IACT;IAEA,OAAO;QACL,iBAAiB,GACjBC,OAAO,OAAOP;YACZ,MAAMC,MAAM,MAAMJ,KAAS;gBACzBK,KAAK;gBACLC,MAAM;oBAAEC,MAAMJ;gBAAG;YACnB;YAEA,IAAIC,IAAII,OAAO,KAAK,OAAO,MAAM,IAAIC,MAAML,IAAIO,KAAK,CAACC,GAAG;YACxD,OAAOR,IAAII,OAAO;QACpB;QAEA,qFAAqF,GACrFK,SAASX;QAET,kBAAkB,GAClBY,QAAQ,OAAOX;YACb,MAAMC,MAAM,MAAMJ,KAAS;gBACzBK,KAAK;gBACLC,MAAM;oBAAEC,MAAMJ;gBAAG;YACnB;YAEA,IAAIC,IAAII,OAAO,KAAK,OAAO,MAAM,IAAIC,MAAML,IAAIO,KAAK,CAACC,GAAG;YACxD,OAAOR,IAAII,OAAO;QACpB;QAEA,qFAAqF,GACrFO,UAAUb;QAEVc,KAAK,OAAOb;YACV,MAAMC,MAAM,MAAML,IAEf;gBACDM,KAAK,CAAC,IAAI,EAAEF,IAAI;YAClB;YACA,IAAIC,IAAII,OAAO,KAAK,OAAO,MAAM,IAAIC,MAAML,IAAIO,KAAK,CAACC,GAAG;YACxD,OAAOR,IAAIY,GAAG;QAChB;IACF;AACF,EAAE"}