UNPKG

weverse

Version:
289 lines (288 loc) 8.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.NotifKeys = exports.NotifContent = exports.CommentArray = exports.MediaArray = exports.Media = exports.isComment = exports.isPost = exports.PhotoArray = exports.PostArray = exports.Post = exports.Comment = exports.artistInfo = exports.Video = exports.Photo = exports.isNotification = exports.NotificationArray = exports.Notification = exports.ExtraInfo = exports.NotificationType = exports.ArtistArray = exports.Artist = exports.CommunityArray = exports.Community = exports.isWeverseLogin = void 0; const isWeverseLogin = (res) => { return res.access_token && typeof res.access_token === 'string' && res.token_type && res.token_type === 'bearer' && typeof res.expires_in === 'number' && res.refresh_token && typeof res.refresh_token === 'string' && res.weMemberId && typeof res.weMemberId === 'number'; }; exports.isWeverseLogin = isWeverseLogin; const optToNum = (val) => { if (val === undefined || typeof val === 'undefined') return val; if (typeof val !== 'string') throw new Error(); return Number(val); }; const optNotif = (val) => { if (val === undefined || typeof val === 'undefined') return val; if (typeof val !== 'string') throw new Error(); if (isNotif(val)) return val; throw new Error(); }; const string = (val) => { if (typeof val !== 'string') throw new Error(); return val; }; const mediaType = (val) => { if (typeof val !== 'string') throw new Error(); if (val === 'VIDEO' || val === 'PHOTO') return val; throw new Error(); }; const boolean = (val) => { if (typeof val !== 'boolean') throw new Error(); return val; }; const number = (val) => { if (typeof val !== 'number') throw new Error(); return val; }; const url = (val) => { if (val === undefined) return new URL('https://PLACEHOLDER.weverse.com'); if (typeof val !== 'string') throw new Error(); const url = new URL(val); return url; }; const toNum = (val) => { if (typeof val !== 'string') throw new Error(); return Number(val); }; const date = (val) => { if (typeof val !== 'string') throw new Error(); return new Date(val); }; const optionalUrl = (val) => { if (typeof val === 'undefined') return undefined; if (typeof val === 'string') return new URL(val); throw new Error(); }; const optionalDate = (val) => { if (typeof val === 'string') return date(val); return undefined; }; const array = (inner) => (val) => { if (!Array.isArray(val)) throw new Error(); return val.map(inner); }; const notif = (val) => { if (typeof val !== 'string') throw new Error(); if (isNotif(val)) return val; throw new Error(); }; const isNotif = (val) => { for (const [k, v] of Object.entries(NotificationType)) { if (v === val) return true; } return false; }; const optional = (inner) => (val) => { if (val === undefined) return undefined; return inner(val); }; const object = (inner) => { return (val) => { if (val === null || typeof val !== 'object') throw new Error(); const out = {}; for (const k in inner) { out[k] = inner[k](val[k]); } return out; }; }; exports.Community = object({ id: number, name: string, description: string, memberCount: number, homeBannerImgPath: url, iconImgPath: url, bannerImgPath: url, fullname: array(string), fcMember: boolean, membershipName: optional(string), }); exports.CommunityArray = array(exports.Community); exports.Artist = object({ id: number, communityUserId: number, name: string, listName: array(string), profileNickName: string, profileImgPath: url, profileUploadImgPath: url, isBirthday: boolean, groupName: string, communityId: number, hasNewToFans: boolean, hasNewPrivateToFans: boolean, toFanLastId: optional(number), toFanLastCreatedAt: optionalDate, birthdayImgUrl: url, }); exports.ArtistArray = array(exports.Artist); var NotificationType; (function (NotificationType) { NotificationType["MEDIA"] = "MEDIA"; NotificationType["SERVICE"] = "SERVICE_NOTICE"; NotificationType["FANS"] = "TO_FANS"; NotificationType["POST"] = "ARTIST_POST"; NotificationType["FAN_REPLY"] = "COMMENT_DETAIL"; NotificationType["NOTICE"] = "NOTICE"; NotificationType["O_POST"] = "POST"; })(NotificationType = exports.NotificationType || (exports.NotificationType = {})); exports.ExtraInfo = object({ replyCommentId: toNum, originContentId: toNum, originContentType: notif, }); // const isInfo = (val: unknown): val is Info => { // try { // ExtraInfo(val) // return true // } catch { // return false // } // } exports.Notification = object({ id: number, message: string, boldElement: string, communityId: number, communityName: string, contentsExtraInfo: object({ replyCommentId: optToNum, originContentId: optToNum, originContentType: optNotif }), contentsType: notif, contentsId: number, notifiedAt: date, iconImageUrl: url, artistId: optional(number), isMembershipContent: boolean, isWebOnly: boolean, platform: string, }); exports.NotificationArray = array(exports.Notification); const isNotification = (n) => { return !!n; }; exports.isNotification = isNotification; exports.Photo = object({ mediaId: optional(number), postId: number, imgUrl: url, imgWidth: number, imgHeight: number, id: number, contentIndex: number, thumbnailImgUrl: url, thumbnailImgWidth: number, thumbnailImgHeight: number, orgImgUrl: url, orgImgWidth: number, orgImgHeight: number, downloadImgFilename: string, isGif: boolean }); exports.Video = object({ id: optional(number), videoUrl: url, thumbnailUrl: url, thumbnailWidth: number, thumbnailHeight: number, playTime: number }); exports.artistInfo = object({ artistId: number, communityId: number, }); exports.Comment = object({ id: number, body: string, commentCount: number, likeCount: number, postId: number, createdAt: date, updatedAt: date, communityUser: exports.artistInfo }); exports.Post = object({ id: number, communityUser: exports.artistInfo, communityTabId: number, body: optional(string), artistComments: optional(array(exports.Comment)), commentCount: number, likeCount: number, createdAt: date, updatedAt: date, photos: optional(array(exports.Photo)), attachedVideos: optional(array(exports.Video)), }); exports.PostArray = array(exports.Post); exports.PhotoArray = array(exports.Photo); const isPost = (n) => { return !!n; }; exports.isPost = isPost; const isComment = (c) => { return !!c; }; exports.isComment = isComment; exports.Media = object({ id: number, communityId: number, body: string, type: mediaType, thumbnailPath: url, title: string, extVideoPath: optionalUrl, youtubeId: optional(string), likeCount: number, playCount: number, commentCount: number, createdAt: date, updatedAt: date, photos: array(exports.Photo) }); exports.MediaArray = array(exports.Media); exports.CommentArray = array(exports.Comment); exports.NotifContent = { COMMENT: ["commented on", "replied to", "포스트에 댓글을 작성했습니다", "답글을 작성했습니다."], POST: [ "님이 포스트를 작성했습니다", "created a new post!", "shared a moment with you", "모먼트가 도착했습니다" ], MEDIA: ["Check out the new media", "새로운 미디어"], ANNOUNCEMENT: ["New announcement", "NOTICE:", "(광고)", "(AD)"] }; var NotifKeys; (function (NotifKeys) { NotifKeys["COMMENT"] = "COMMENT"; NotifKeys["POST"] = "POST"; NotifKeys["MEDIA"] = "MEDIA"; NotifKeys["ANNOUNCEMENT"] = "ANNOUNCEMENT"; })(NotifKeys = exports.NotifKeys || (exports.NotifKeys = {}));