How to use getAccessToken method in devicefarmer-stf

Best JavaScript code snippet using devicefarmer-stf

api.ts

Source:api.ts Github

copy

Full Screen

...57export const getRefreshToken = (): string | null => {58 const tokens = getAuthTokens();59 return (tokens && tokens.renew_token) || null;60};61export const me = async (token = getAccessToken()): Promise<User> => {62 if (!token) {63 throw new Error('Invalid token!');64 }65 return request66 .get(`/api/me`)67 .set('Authorization', token)68 .then((res) => res.body.data);69};70export const login = async ({email, password}: LoginParams) => {71 return request72 .post(`/api/session`)73 .send({user: {email, password}})74 .then((res) => res.body.data);75};76export const logout = async () => {77 return request.delete(`/api/session`).then((res) => res.body);78};79export const register = async ({80 companyName,81 inviteToken,82 email,83 password,84 passwordConfirmation,85}: RegisterParams) => {86 return request87 .post(`/api/registration`)88 .send({89 user: {90 company_name: companyName,91 invite_token: inviteToken,92 email,93 password,94 password_confirmation: passwordConfirmation,95 },96 })97 .then((res) => res.body.data);98};99export const renew = async (token = getRefreshToken()) => {100 if (!token) {101 throw new Error('Invalid token!');102 }103 return request104 .post(`/api/session/renew`)105 .set('Authorization', token)106 .then((res) => res.body.data);107};108export const verifyUserEmail = async (verificationToken: string) => {109 return request110 .post(`/api/verify_email`)111 .send({token: verificationToken})112 .then((res) => res.body.data);113};114export const sendPasswordResetEmail = async (email: string) => {115 return request116 .post(`/api/reset_password`)117 .send({email})118 .then((res) => res.body.data);119};120export const attemptPasswordReset = async (121 passwordResetToken: string,122 {password, passwordConfirmation}: ResetPasswordParams123) => {124 return request125 .put(`/api/reset_password`)126 .send({127 password,128 password_confirmation: passwordConfirmation,129 token: passwordResetToken,130 })131 .then((res) => res.body.data);132};133export const createNewCustomer = async (134 accountId: string,135 params: Partial<Customer>136) => {137 return request138 .post(`/api/customers`)139 .send({140 customer: {141 first_seen: now(),142 last_seen_at: now(),143 ...params,144 account_id: accountId,145 },146 })147 .then((res) => res.body.data);148};149export const fetchCustomers = async (150 filters = {},151 token = getAccessToken()152) => {153 if (!token) {154 throw new Error('Invalid token!');155 }156 return request157 .get(`/api/customers`)158 .query(qs.stringify(filters, {arrayFormat: 'bracket'}))159 .set('Authorization', token)160 .then((res) => res.body);161};162export const fetchCustomer = async (163 id: string,164 query: {expand?: Array<string>} = {},165 token = getAccessToken()166) => {167 if (!token) {168 throw new Error('Invalid token!');169 }170 const {expand = []} = query;171 return request172 .get(`/api/customers/${id}`)173 .query(qs.stringify({expand}, {arrayFormat: 'bracket'}))174 .set('Authorization', token)175 .then((res) => res.body.data);176};177export const updateCustomer = async (178 id: string,179 updates: Record<string, any>,180 token = getAccessToken()181) => {182 if (!token) {183 throw new Error('Invalid token!');184 }185 return request186 .put(`/api/customers/${id}`)187 .set('Authorization', token)188 .send({189 customer: updates,190 })191 .then((res) => res.body.data);192};193export const deleteCustomer = async (id: string, token = getAccessToken()) => {194 if (!token) {195 throw new Error('Invalid token!');196 }197 return request198 .delete(`/api/customers/${id}`)199 .set('Authorization', token)200 .then((res) => res.body);201};202export const createNewCompany = async (203 params: Record<string, any>,204 token = getAccessToken()205) => {206 if (!token) {207 throw new Error('Invalid token!');208 }209 return request210 .post(`/api/companies`)211 .send({company: params})212 .set('Authorization', token)213 .then((res) => res.body.data);214};215export const fetchCompanies = async (token = getAccessToken()) => {216 if (!token) {217 throw new Error('Invalid token!');218 }219 return request220 .get(`/api/companies`)221 .set('Authorization', token)222 .then((res) => res.body.data);223};224export const fetchCompany = async (id: string, token = getAccessToken()) => {225 if (!token) {226 throw new Error('Invalid token!');227 }228 return request229 .get(`/api/companies/${id}`)230 .set('Authorization', token)231 .then((res) => res.body.data);232};233export const updateCompany = async (234 id: string,235 updates: Record<string, any>,236 token = getAccessToken()237) => {238 if (!token) {239 throw new Error('Invalid token!');240 }241 return request242 .put(`/api/companies/${id}`)243 .set('Authorization', token)244 .send({company: updates})245 .then((res) => res.body.data);246};247export const deleteCompany = async (id: string, token = getAccessToken()) => {248 if (!token) {249 throw new Error('Invalid token!');250 }251 return request.delete(`/api/companies/${id}`).set('Authorization', token);252};253export const createNewConversation = async (254 customerId: string,255 params?: Record<any, any>,256 token = getAccessToken()257) => {258 if (!token) {259 throw new Error('Invalid token!');260 }261 return request262 .post(`/api/conversations`)263 .set('Authorization', token)264 .send({265 conversation: {266 customer_id: customerId,267 ...params,268 },269 })270 .then((res) => res.body.data);271};272export const fetchAccountInfo = async (273 token = getAccessToken()274): Promise<Account> => {275 if (!token) {276 throw new Error('Invalid token!');277 }278 return request279 .get(`/api/accounts/me`)280 .set('Authorization', token)281 .then((res) => res.body.data);282};283export const updateAccountInfo = async (284 updates: Record<string, any>,285 token = getAccessToken()286) => {287 if (!token) {288 throw new Error('Invalid token!');289 }290 return request291 .put(`/api/accounts/me`)292 .set('Authorization', token)293 .send({294 account: updates,295 })296 .then((res) => res.body.data);297};298export const deleteMyAccount = async (token = getAccessToken()) => {299 if (!token) {300 throw new Error('Invalid token!');301 }302 return request303 .delete(`/api/accounts/me`)304 .set('Authorization', token)305 .then((res) => res.body);306};307export const fetchUserProfile = async (token = getAccessToken()) => {308 if (!token) {309 throw new Error('Invalid token!');310 }311 return request312 .get(`/api/profile`)313 .set('Authorization', token)314 .then((res) => res.body.data);315};316export const updateUserProfile = async (317 updates: Record<string, any>,318 token = getAccessToken()319) => {320 if (!token) {321 throw new Error('Invalid token!');322 }323 return request324 .put(`/api/profile`)325 .set('Authorization', token)326 .send({327 user_profile: updates,328 })329 .then((res) => res.body.data);330};331export const fetchUserSettings = async (332 token = getAccessToken()333): Promise<UserSettings> => {334 if (!token) {335 throw new Error('Invalid token!');336 }337 return request338 .get('/api/user_settings')339 .set('Authorization', token)340 .then((res) => res.body.data);341};342export const updateUserSettings = async (343 updates: Record<string, any>,344 token = getAccessToken()345) => {346 if (!token) {347 throw new Error('Invalid token!');348 }349 return request350 .put('/api/user_settings')351 .set('Authorization', token)352 .send({353 user_settings: updates,354 })355 .then((res) => res.body.data);356};357export type PaginationOptions = {358 limit?: number;359 next?: string | null;360 previous?: string | null;361 total?: number;362};363export type ConversationsListResponse = {364 data: Array<Conversation>;365 next: string | null;366 previous: string | null;367};368export const countUnreadConversations = async (369 token = getAccessToken()370): Promise<any> => {371 if (!token) {372 throw new Error('Invalid token!');373 }374 return request375 .get(`/api/conversations/unread`)376 .set('Authorization', token)377 .then((res) => res.body.data);378};379export const fetchConversations = async (380 query = {},381 token = getAccessToken()382): Promise<ConversationsListResponse> => {383 if (!token) {384 throw new Error('Invalid token!');385 }386 return request387 .get(`/api/conversations`)388 .query(query)389 .set('Authorization', token)390 .then((res) => res.body);391};392export const fetchConversationsByInbox = async (393 inboxId: string,394 query = {},395 token = getAccessToken()396): Promise<ConversationsListResponse> => {397 return fetchConversations({...query, inbox_id: inboxId}, token);398};399export const fetchAllConversations = async (400 query = {},401 token = getAccessToken()402) => {403 return fetchConversations({...query, status: 'open'}, token);404};405export const fetchMyConversations = async (406 userId?: number,407 query = {},408 token = getAccessToken()409) => {410 return fetchConversations(411 {412 ...query,413 assignee_id: userId || 'me',414 status: 'open',415 },416 token417 );418};419export const fetchMentionedConversations = async (420 userId?: number,421 query = {},422 token = getAccessToken()423) => {424 return fetchConversations(425 {426 ...query,427 mentioning: userId || 'me',428 status: 'open',429 },430 token431 );432};433export const fetchPriorityConversations = async (434 query = {},435 token = getAccessToken()436) => {437 return fetchConversations(438 {439 ...query,440 priority: 'priority',441 status: 'open',442 },443 token444 );445};446export const fetchClosedConversations = async (447 query = {},448 token = getAccessToken()449) => {450 return fetchConversations({...query, status: 'closed'}, token);451};452export const fetchUnreadConversations = async (453 query = {},454 token = getAccessToken()455) => {456 return fetchConversations({...query, status: 'open', read: false}, token);457};458export const fetchUnassignedConversations = async (459 query = {},460 token = getAccessToken()461) => {462 return fetchConversations(463 {464 ...query,465 status: 'open',466 assignee_id: null,467 },468 token469 );470};471export const fetchConversation = async (472 id: string,473 token = getAccessToken()474): Promise<Conversation> => {475 if (!token) {476 throw new Error('Invalid token!');477 }478 return request479 .get(`/api/conversations/${id}`)480 .set('Authorization', token)481 .then((res) => res.body.data);482};483export const fetchPreviousConversation = async (484 id: string,485 token = getAccessToken()486): Promise<Conversation> => {487 if (!token) {488 throw new Error('Invalid token!');489 }490 return request491 .get(`/api/conversations/${id}/previous`)492 .set('Authorization', token)493 .then((res) => res.body.data);494};495export const fetchRelatedConversations = async (496 id: string,497 token = getAccessToken()498): Promise<Array<Conversation>> => {499 if (!token) {500 throw new Error('Invalid token!');501 }502 return request503 .get(`/api/conversations/${id}/related`)504 .set('Authorization', token)505 .then((res) => res.body.data);506};507export const fetchSlackConversationThreads = async (508 conversationId: string,509 token = getAccessToken()510): Promise<Array<Conversation>> => {511 if (!token) {512 throw new Error('Invalid token!');513 }514 return request515 .get(`/api/slack_conversation_threads`)516 .query({conversation_id: conversationId})517 .set('Authorization', token)518 .then((res) => res.body.data);519};520export const generateShareConversationToken = async (521 conversationId: string,522 token = getAccessToken()523) => {524 if (!token) {525 throw new Error('Invalid token!');526 }527 return request528 .post(`/api/conversations/${conversationId}/share`)529 .set('Authorization', token)530 .then((res) => res.body.data);531};532export const fetchSharedConversation = async (533 id: string,534 token: string535): Promise<Conversation> => {536 if (!token) {537 throw new Error('Access denied!');538 }539 return request540 .get(`/api/conversations/shared`)541 .query({token, conversation_id: id})542 .then((res) => res.body.data);543};544export const updateConversation = async (545 conversationId: string,546 updates: Record<string, any>,547 token = getAccessToken()548) => {549 if (!token) {550 throw new Error('Invalid token!');551 }552 return request553 .put(`/api/conversations/${conversationId}`)554 .set('Authorization', token)555 .send(updates)556 .then((res) => res.body.data);557};558export const deleteConversation = async (559 conversationId: string,560 token = getAccessToken()561) => {562 if (!token) {563 throw new Error('Invalid token!');564 }565 return request566 .delete(`/api/conversations/${conversationId}`)567 .set('Authorization', token)568 .then((res) => res.body);569};570export const archiveConversation = async (571 conversationId: string,572 token = getAccessToken()573) => {574 if (!token) {575 throw new Error('Invalid token!');576 }577 return request578 .post(`/api/conversations/${conversationId}/archive`)579 .set('Authorization', token)580 .then((res) => res.body);581};582export const createNewMessage = async (583 message: Partial<Message>,584 token = getAccessToken()585) => {586 if (!token) {587 throw new Error('Invalid token!');588 }589 return request590 .post(`/api/messages`)591 .set('Authorization', token)592 .send({593 message: {594 sent_at: new Date().toISOString(),595 ...message,596 },597 })598 .then((res) => res.body.data);599};600export const countMessages = async (token = getAccessToken()) => {601 if (!token) {602 throw new Error('Invalid token!');603 }604 return request605 .get(`/api/messages/count`)606 .set('Authorization', token)607 .then((res) => res.body.data);608};609export const countAllConversations = async (610 query = {},611 token = getAccessToken()612) => {613 if (!token) {614 throw new Error('Invalid token!');615 }616 return request617 .get(`/api/conversations/count`)618 .query(query)619 .set('Authorization', token)620 .then((res) => res.body.data);621};622export const fetchCustomerConversations = async (623 customerId: string,624 accountId: string625) => {626 return request627 .get(`/api/conversations/customer`)628 .query({customer_id: customerId, account_id: accountId})629 .then((res) => res.body.data);630};631export const generateUserInvitation = async (token = getAccessToken()) => {632 if (!token) {633 throw new Error('Invalid token!');634 }635 return request636 .post(`/api/user_invitations`)637 .send({user_invitation: {}})638 .set('Authorization', token)639 .then((res) => res.body.data);640};641export const sendUserInvitationEmail = async (642 to_address: string,643 token = getAccessToken()644) => {645 if (!token) {646 throw new Error('Invalid token!');647 }648 return request649 .post(`/api/user_invitation_emails`)650 .send({to_address})651 .set('Authorization', token)652 .then((res) => res.body.data);653};654export const sendSlackNotification = async (655 params: {656 text: string;657 type?: 'reply' | 'support';658 channel?: string;659 },660 token = getAccessToken()661) => {662 if (!token) {663 throw new Error('Invalid token!');664 }665 return request666 .post(`/api/slack/notify`)667 .send(params)668 .set('Authorization', token)669 .then((res) => res.body.data);670};671export const fetchSlackAuthorization = async (672 type = 'reply',673 query = {},674 token = getAccessToken()675): Promise<SlackAuthorization> => {676 if (!token) {677 throw new Error('Invalid token!');678 }679 return request680 .get(`/api/slack/authorization`)681 .query({type, ...query})682 .set('Authorization', token)683 .then((res) => res.body.data);684};685export const listSlackAuthorizations = async (686 type = 'support',687 query = {},688 token = getAccessToken()689): Promise<Array<SlackAuthorization>> => {690 if (!token) {691 throw new Error('Invalid token!');692 }693 return request694 .get(`/api/slack/authorizations`)695 .query({type, ...query})696 .set('Authorization', token)697 .then((res) => res.body.data);698};699export const updateSlackAuthorizationSettings = async (700 authorizationId: string,701 settings: Record<string, any>,702 token = getAccessToken()703) => {704 if (!token) {705 throw new Error('Invalid token!');706 }707 return request708 .post(`/api/slack/authorizations/${authorizationId}/settings`)709 .send({settings})710 .set('Authorization', token)711 .then((res) => res.body.data);712};713export const deleteSlackAuthorization = async (714 authorizationId: string,715 token = getAccessToken()716) => {717 if (!token) {718 throw new Error('Invalid token!');719 }720 return request721 .delete(`/api/slack/authorizations/${authorizationId}`)722 .set('Authorization', token);723};724export const fetchSlackChannels = async (725 query = {},726 token = getAccessToken()727) => {728 if (!token) {729 throw new Error('Invalid token!');730 }731 return request732 .get(`/api/slack/channels`)733 .query(query)734 .set('Authorization', token)735 .then((res) => res.body.data);736};737export const fetchMattermostChannels = async (738 query = {},739 token = getAccessToken()740) => {741 if (!token) {742 throw new Error('Invalid token!');743 }744 return request745 .get(`/api/mattermost/channels`)746 .query(query)747 .set('Authorization', token)748 .then((res) => res.body.data);749};750export const createMattermostAuthorization = async (751 authorization = {},752 token = getAccessToken()753) => {754 if (!token) {755 throw new Error('Invalid token!');756 }757 return request758 .post(`/api/mattermost/auth`)759 .send({authorization})760 .set('Authorization', token)761 .then((res) => res.body.data);762};763export const fetchMattermostAuthorization = async (764 query = {},765 token = getAccessToken()766) => {767 if (!token) {768 throw new Error('Invalid token!');769 }770 return request771 .get(`/api/mattermost/authorization`)772 .query(query)773 .set('Authorization', token)774 .then((res) => res.body.data);775};776export const deleteMattermostAuthorization = async (777 authorizationId: string,778 token = getAccessToken()779) => {780 if (!token) {781 throw new Error('Invalid token!');782 }783 return request784 .delete(`/api/mattermost/authorizations/${authorizationId}`)785 .set('Authorization', token);786};787export const createTwilioAuthorization = async (788 authorization = {},789 token = getAccessToken()790) => {791 if (!token) {792 throw new Error('Invalid token!');793 }794 return request795 .post(`/api/twilio/auth`)796 .send({authorization})797 .set('Authorization', token)798 .then((res) => res.body.data);799};800export const fetchTwilioAuthorization = async (801 query = {},802 token = getAccessToken()803) => {804 if (!token) {805 throw new Error('Invalid token!');806 }807 return request808 .get(`/api/twilio/authorization`)809 .query(query)810 .set('Authorization', token)811 .then((res) => res.body.data);812};813export const deleteTwilioAuthorization = async (814 authorizationId: string,815 token = getAccessToken()816) => {817 if (!token) {818 throw new Error('Invalid token!');819 }820 return request821 .delete(`/api/twilio/authorizations/${authorizationId}`)822 .set('Authorization', token);823};824export const sendTwilioSms = async (825 params: {to: string; body: string},826 token = getAccessToken()827) => {828 if (!token) {829 throw new Error('Invalid token!');830 }831 return request832 .post(`/api/twilio/send`)833 .send(params)834 .set('Authorization', token)835 .then((res) => res.body.data);836};837export const fetchGoogleAuthorization = async (838 query: GoogleIntegrationParams,839 token = getAccessToken()840) => {841 if (!token) {842 throw new Error('Invalid token!');843 }844 return request845 .get(`/api/google/authorization`)846 .query(query)847 .set('Authorization', token)848 .then((res) => res.body.data);849};850export const deleteGoogleAuthorization = async (851 authorizationId: string,852 token = getAccessToken()853) => {854 if (!token) {855 throw new Error('Invalid token!');856 }857 return request858 .delete(`/api/google/authorizations/${authorizationId}`)859 .set('Authorization', token);860};861export const fetchGithubAuthorization = async (token = getAccessToken()) => {862 if (!token) {863 throw new Error('Invalid token!');864 }865 return request866 .get(`/api/github/authorization`)867 .set('Authorization', token)868 .then((res) => res.body.data);869};870export const deleteGithubAuthorization = async (871 authorizationId: string,872 token = getAccessToken()873) => {874 if (!token) {875 throw new Error('Invalid token!');876 }877 return request878 .delete(`/api/github/authorizations/${authorizationId}`)879 .set('Authorization', token);880};881export const fetchGithubRepos = async (token = getAccessToken()) => {882 if (!token) {883 throw new Error('Invalid token!');884 }885 return request886 .get(`/api/github/repos`)887 .set('Authorization', token)888 .then((res) => res.body.data);889};890export const findGithubIssues = async (891 query: {892 url?: string;893 owner?: string;894 repo?: string;895 },896 token = getAccessToken()897) => {898 if (!token) {899 throw new Error('Invalid token!');900 }901 return request902 .get(`/api/github/issues`)903 .query(query)904 .set('Authorization', token)905 .then((res) => res.body.data);906};907export const fetchGmailProfile = async (908 query = {},909 token = getAccessToken()910) => {911 if (!token) {912 throw new Error('Invalid token!');913 }914 return request915 .get(`/api/gmail/profile`)916 .query(query)917 .set('Authorization', token)918 .then((res) => res.body.data);919};920export type EmailParams = {921 recipient: string;922 subject: string;923 message: string;924};925export const sendGmailNotification = async (926 {recipient, subject, message}: EmailParams,927 token = getAccessToken()928) => {929 if (!token) {930 throw new Error('Invalid token!');931 }932 return request933 .post(`/api/gmail/send`)934 .send({recipient, subject, message})935 .set('Authorization', token)936 .then((res) => res.body.data);937};938export const fetchHubspotAuthorization = async (token = getAccessToken()) => {939 if (!token) {940 throw new Error('Invalid token!');941 }942 return request943 .get(`/api/hubspot/authorization`)944 .set('Authorization', token)945 .then((res) => res.body.data);946};947export const createHubspotContact = async (948 params = {},949 token = getAccessToken()950) => {951 if (!token) {952 throw new Error('Invalid token!');953 }954 return request955 .post(`/api/hubspot/contacts`)956 .send(params)957 .set('Authorization', token)958 .then((res) => res.body.data);959};960export const fetchHubspotContacts = async (961 query = {},962 token = getAccessToken()963) => {964 if (!token) {965 throw new Error('Invalid token!');966 }967 return request968 .get(`/api/hubspot/contacts`)969 .query(query)970 .set('Authorization', token)971 .then((res) => res.body.data);972};973export const fetchHubspotContactByEmail = async (974 email: string,975 token = getAccessToken()976) => {977 return fetchHubspotContacts({email}, token).then(978 ([result]) => result || null979 );980};981export const deleteHubspotAuthorization = async (982 authorizationId: string,983 token = getAccessToken()984) => {985 if (!token) {986 throw new Error('Invalid token!');987 }988 return request989 .delete(`/api/hubspot/authorizations/${authorizationId}`)990 .set('Authorization', token);991};992export const fetchIntercomAuthorization = async (token = getAccessToken()) => {993 if (!token) {994 throw new Error('Invalid token!');995 }996 return request997 .get(`/api/intercom/authorization`)998 .set('Authorization', token)999 .then((res) => res.body.data);1000};1001export const createIntercomContact = async (1002 params = {},1003 token = getAccessToken()1004) => {1005 if (!token) {1006 throw new Error('Invalid token!');1007 }1008 return request1009 .post(`/api/intercom/contacts`)1010 .send(params)1011 .set('Authorization', token)1012 .then((res) => res.body.data);1013};1014export const fetchIntercomContacts = async (1015 query = {},1016 token = getAccessToken()1017) => {1018 if (!token) {1019 throw new Error('Invalid token!');1020 }1021 return request1022 .get(`/api/intercom/contacts`)1023 .query(query)1024 .set('Authorization', token)1025 .then((res) => res.body.data);1026};1027export const fetchIntercomContactByEmail = async (1028 email: string,1029 token = getAccessToken()1030) => {1031 return fetchIntercomContacts({email}, token).then(1032 ([result]) => result || null1033 );1034};1035export const deleteIntercomAuthorization = async (1036 authorizationId: string,1037 token = getAccessToken()1038) => {1039 if (!token) {1040 throw new Error('Invalid token!');1041 }1042 return request1043 .delete(`/api/intercom/authorizations/${authorizationId}`)1044 .set('Authorization', token);1045};1046export const fetchEventSubscriptions = async (token = getAccessToken()) => {1047 if (!token) {1048 throw new Error('Invalid token!');1049 }1050 return request1051 .get(`/api/event_subscriptions`)1052 .set('Authorization', token)1053 .then((res) => res.body.data);1054};1055export const verifyWebhookUrl = async (1056 url: string,1057 token = getAccessToken()1058) => {1059 if (!token) {1060 throw new Error('Invalid token!');1061 }1062 return request1063 .post(`/api/event_subscriptions/verify`)1064 .set('Authorization', token)1065 .send({url})1066 .then((res) => res.body.data);1067};1068export const createEventSubscription = async (1069 params: EventSubscriptionParams,1070 token = getAccessToken()1071) => {1072 if (!token) {1073 throw new Error('Invalid token!');1074 }1075 return request1076 .post(`/api/event_subscriptions`)1077 .set('Authorization', token)1078 .send({1079 event_subscription: params,1080 })1081 .then((res) => res.body.data);1082};1083export const updateEventSubscription = async (1084 id: string,1085 updates: EventSubscriptionParams,1086 token = getAccessToken()1087) => {1088 if (!token) {1089 throw new Error('Invalid token!');1090 }1091 return request1092 .put(`/api/event_subscriptions/${id}`)1093 .set('Authorization', token)1094 .send({1095 event_subscription: updates,1096 })1097 .then((res) => res.body.data);1098};1099export const deleteEventSubscription = async (1100 id: string,1101 token = getAccessToken()1102) => {1103 if (!token) {1104 throw new Error('Invalid token!');1105 }1106 return request1107 .delete(`/api/event_subscriptions/${id}`)1108 .set('Authorization', token);1109};1110export const fetchForwardingAddresses = async (1111 query = {},1112 token = getAccessToken()1113) => {1114 if (!token) {1115 throw new Error('Invalid token!');1116 }1117 return request1118 .get(`/api/forwarding_addresses`)1119 .query(query)1120 .set('Authorization', token)1121 .then((res) => res.body.data);1122};1123export const createForwardingAddress = async (1124 params: Partial<ForwardingAddress>,1125 token = getAccessToken()1126) => {1127 if (!token) {1128 throw new Error('Invalid token!');1129 }1130 return request1131 .post(`/api/forwarding_addresses`)1132 .set('Authorization', token)1133 .send({1134 forwarding_address: params,1135 })1136 .then((res) => res.body.data);1137};1138export const updateForwardingAddress = async (1139 id: string,1140 updates: Partial<ForwardingAddress>,1141 token = getAccessToken()1142) => {1143 if (!token) {1144 throw new Error('Invalid token!');1145 }1146 return request1147 .put(`/api/forwarding_addresses/${id}`)1148 .set('Authorization', token)1149 .send({1150 forwarding_address: updates,1151 })1152 .then((res) => res.body.data);1153};1154export const deleteForwardingAddress = async (1155 id: string,1156 token = getAccessToken()1157) => {1158 if (!token) {1159 throw new Error('Invalid token!');1160 }1161 return request1162 .delete(`/api/forwarding_addresses/${id}`)1163 .set('Authorization', token);1164};1165type SlackAuthorizationParams = {1166 code: string;1167 type: string;1168 inbox_id?: string;1169 redirect_url?: string;1170};1171export const authorizeSlackIntegration = async (1172 params: SlackAuthorizationParams,1173 token = getAccessToken()1174) => {1175 if (!token) {1176 throw new Error('Invalid token!');1177 }1178 return request1179 .get(`/api/slack/oauth`)1180 .query(params)1181 .set('Authorization', token)1182 .then((res) => res.body.data);1183};1184export const authorizeGmailIntegration = async (1185 code: string,1186 token = getAccessToken()1187) => {1188 if (!token) {1189 throw new Error('Invalid token!');1190 }1191 return request1192 .get(`/api/gmail/oauth`)1193 .query({code})1194 .set('Authorization', token)1195 .then((res) => res.body.data);1196};1197export const authorizeGoogleIntegration = async (1198 query: GoogleAuthParams,1199 token = getAccessToken()1200) => {1201 if (!token) {1202 throw new Error('Invalid token!');1203 }1204 return request1205 .get(`/api/google/oauth`)1206 .query(query)1207 .set('Authorization', token)1208 .then((res) => res.body.data);1209};1210export const authorizeGithubIntegration = async (1211 query: Record<string, any>,1212 token = getAccessToken()1213) => {1214 if (!token) {1215 throw new Error('Invalid token!');1216 }1217 return request1218 .get(`/api/github/oauth`)1219 .query(query)1220 .set('Authorization', token)1221 .then((res) => res.body);1222};1223export const authorizeHubspotIntegration = async (1224 query: Record<string, any>,1225 token = getAccessToken()1226) => {1227 if (!token) {1228 throw new Error('Invalid token!');1229 }1230 return request1231 .get(`/api/hubspot/oauth`)1232 .query(query)1233 .set('Authorization', token)1234 .then((res) => res.body);1235};1236export const authorizeIntercomIntegration = async (1237 query: {code: string},1238 token = getAccessToken()1239) => {1240 if (!token) {1241 throw new Error('Invalid token!');1242 }1243 return request1244 .get(`/api/intercom/callback`)1245 .query(query)1246 .set('Authorization', token)1247 .then((res) => res.body);1248};1249export const fetchWidgetSettings = async (1250 query: {1251 account_id?: string;1252 inbox_id?: string;1253 } = {},1254 token = getAccessToken()1255) => {1256 if (!token) {1257 throw new Error('Invalid token!');1258 }1259 return request1260 .get(`/api/widget_settings`)1261 .query(query)1262 .set('Authorization', token)1263 .then((res) => res.body.data);1264};1265export const updateWidgetSettings = async (1266 widgetSettingsParams: Partial<WidgetSettings>,1267 token = getAccessToken()1268) => {1269 if (!token) {1270 throw new Error('Invalid token!');1271 }1272 return request1273 .put(`/api/widget_settings`)1274 .send({widget_settings: widgetSettingsParams})1275 .set('Authorization', token)1276 .then((res) => res.body.data);1277};1278export const fetchDefaultPaymentMethod = async (token = getAccessToken()) => {1279 if (!token) {1280 throw new Error('Invalid token!');1281 }1282 return request1283 .get(`/api/payment_methods`)1284 .set('Authorization', token)1285 .then((res) => res.body.data);1286};1287export const fetchBillingInfo = async (token = getAccessToken()) => {1288 if (!token) {1289 throw new Error('Invalid token!');1290 }1291 return request1292 .get(`/api/billing`)1293 .set('Authorization', token)1294 .then((res) => res.body.data);1295};1296export const createSubscriptionPlan = async (1297 plan: string,1298 token = getAccessToken()1299) => {1300 if (!token) {1301 throw new Error('Invalid token!');1302 }1303 return request1304 .post(`/api/billing`)1305 .send({plan})1306 .set('Authorization', token)1307 .then((res) => res.body.data);1308};1309export const updateSubscriptionPlan = async (1310 plan: string,1311 token = getAccessToken()1312) => {1313 if (!token) {1314 throw new Error('Invalid token!');1315 }1316 return request1317 .put(`/api/billing`)1318 .send({plan})1319 .set('Authorization', token)1320 .then((res) => res.body.data);1321};1322export const createPaymentMethod = async (1323 paymentMethod: any,1324 token = getAccessToken()1325) => {1326 if (!token) {1327 throw new Error('Invalid token!');1328 }1329 return request1330 .post(`/api/payment_methods`)1331 .send({payment_method: paymentMethod})1332 .set('Authorization', token)1333 .then((res) => res.body.data);1334};1335export const fetchAccountUsers = async (token = getAccessToken()) => {1336 if (!token) {1337 throw new Error('Invalid token!');1338 }1339 return request1340 .get(`/api/users`)1341 .set('Authorization', token)1342 .then((res) => res.body.data);1343};1344export const fetchAccountUser = async (1345 id: number,1346 token = getAccessToken()1347) => {1348 if (!token) {1349 throw new Error('Invalid token!');1350 }1351 return request1352 .get(`/api/users/${id}`)1353 .set('Authorization', token)1354 .then((res) => res.body.data);1355};1356export const disableAccountUser = async (1357 userId: number | string,1358 token = getAccessToken()1359) => {1360 if (!token) {1361 throw new Error('Invalid token!');1362 }1363 return request1364 .post(`/api/users/${userId}/disable`)1365 .set('Authorization', token)1366 .then((res) => res.body.data);1367};1368export const setAccountUserRole = async (1369 userId: number | string,1370 role: string,1371 token = getAccessToken()1372) => {1373 if (!token) {1374 throw new Error('Invalid token!');1375 }1376 return request1377 .put(`/api/users/${userId}/role`)1378 .set('Authorization', token)1379 .send({role})1380 .then((res) => res.body.data);1381};1382export const enableAccountUser = async (1383 userId: number | string,1384 token = getAccessToken()1385) => {1386 if (!token) {1387 throw new Error('Invalid token!');1388 }1389 return request1390 .post(`/api/users/${userId}/enable`)1391 .set('Authorization', token)1392 .then((res) => res.body.data);1393};1394export const archiveAccountUser = async (1395 userId: number | string,1396 token = getAccessToken()1397) => {1398 if (!token) {1399 throw new Error('Invalid token!');1400 }1401 return request1402 .post(`/api/users/${userId}/archive`)1403 .set('Authorization', token)1404 .then((res) => res.body.data);1405};1406export const fetchNotes = async (1407 query = {},1408 token = getAccessToken()1409): Promise<CustomerNote[]> => {1410 if (!token) {1411 throw new Error('Invalid token!');1412 }1413 return request1414 .get('/api/notes')1415 .query(query)1416 .set('Authorization', token)1417 .then((res) => res.body.data);1418};1419export type CustomerNotesListResponse = {1420 data: Array<CustomerNote>;1421};1422export const fetchCustomerNotes = async (1423 customerId: string,1424 query = {},1425 token = getAccessToken()1426): Promise<CustomerNote[]> => {1427 return fetchNotes({...query, customer_id: customerId}, token);1428};1429export const createCustomerNote = async (1430 customerId: string,1431 body: string,1432 token = getAccessToken()1433) => {1434 if (!token) {1435 throw new Error('Invalid token!');1436 }1437 return request1438 .post(`/api/notes`)1439 .set('Authorization', token)1440 .send({1441 note: {1442 body,1443 customer_id: customerId,1444 },1445 })1446 .then((res) => res.body.data);1447};1448export const deleteCustomerNote = async (1449 noteId: string,1450 token = getAccessToken()1451) => {1452 if (!token) {1453 throw new Error('Invalid token!');1454 }1455 return request.delete(`/api/notes/${noteId}`).set('Authorization', token);1456};1457export const fetchAllTags = async (token = getAccessToken()) => {1458 if (!token) {1459 throw new Error('Invalid token!');1460 }1461 return request1462 .get(`/api/tags`)1463 .set('Authorization', token)1464 .then((res) => res.body.data);1465};1466export const fetchTagById = async (id: string, token = getAccessToken()) => {1467 if (!token) {1468 throw new Error('Invalid token!');1469 }1470 return request1471 .get(`/api/tags/${id}`)1472 .set('Authorization', token)1473 .then((res) => res.body.data);1474};1475export const createTag = async (1476 tag: Partial<Tag>,1477 token = getAccessToken()1478) => {1479 if (!token) {1480 throw new Error('Invalid token!');1481 }1482 return request1483 .post(`/api/tags`)1484 .send({tag})1485 .set('Authorization', token)1486 .then((res) => res.body.data);1487};1488export const updateTag = async (1489 id: string,1490 tag: Partial<Tag>,1491 token = getAccessToken()1492) => {1493 if (!token) {1494 throw new Error('Invalid token!');1495 }1496 return request1497 .put(`/api/tags/${id}`)1498 .send({tag})1499 .set('Authorization', token)1500 .then((res) => res.body.data);1501};1502export const deleteTag = async (id: string, token = getAccessToken()) => {1503 if (!token) {1504 throw new Error('Invalid token!');1505 }1506 return request1507 .delete(`/api/tags/${id}`)1508 .set('Authorization', token)1509 .then((res) => res.body);1510};1511export const addConversationTag = async (1512 conversationId: string,1513 tagId: string,1514 token = getAccessToken()1515) => {1516 if (!token) {1517 throw new Error('Invalid token!');1518 }1519 return request1520 .post(`/api/conversations/${conversationId}/tags`)1521 .send({tag_id: tagId})1522 .set('Authorization', token)1523 .then((res) => res.body.data);1524};1525export const removeConversationTag = async (1526 conversationId: string,1527 tagId: string,1528 token = getAccessToken()1529) => {1530 if (!token) {1531 throw new Error('Invalid token!');1532 }1533 return request1534 .delete(`/api/conversations/${conversationId}/tags/${tagId}`)1535 .set('Authorization', token)1536 .then((res) => res.body.data);1537};1538export const addCustomerTag = async (1539 customerId: string,1540 tagId: string,1541 token = getAccessToken()1542) => {1543 if (!token) {1544 throw new Error('Invalid token!');1545 }1546 return request1547 .post(`/api/customers/${customerId}/tags`)1548 .send({tag_id: tagId})1549 .set('Authorization', token)1550 .then((res) => res.body.data);1551};1552export const removeCustomerTag = async (1553 customerId: string,1554 tagId: string,1555 token = getAccessToken()1556) => {1557 if (!token) {1558 throw new Error('Invalid token!');1559 }1560 return request1561 .delete(`/api/customers/${customerId}/tags/${tagId}`)1562 .set('Authorization', token)1563 .then((res) => res.body.data);1564};1565export const fetchAllIssues = async (1566 query = {},1567 token = getAccessToken()1568): Promise<Array<Issue>> => {1569 if (!token) {1570 throw new Error('Invalid token!');1571 }1572 return request1573 .get(`/api/issues`)1574 .set('Authorization', token)1575 .query(query)1576 .then((res) => res.body.data);1577};1578export const fetchIssueById = async (id: string, token = getAccessToken()) => {1579 if (!token) {1580 throw new Error('Invalid token!');1581 }1582 return request1583 .get(`/api/issues/${id}`)1584 .set('Authorization', token)1585 .then((res) => res.body.data);1586};1587export const createIssue = async (1588 issue: Partial<Issue>,1589 token = getAccessToken()1590) => {1591 if (!token) {1592 throw new Error('Invalid token!');1593 }1594 return request1595 .post(`/api/issues`)1596 .send({issue})1597 .set('Authorization', token)1598 .then((res) => res.body.data);1599};1600export const updateIssue = async (1601 id: string,1602 issue: Partial<Issue>,1603 token = getAccessToken()1604) => {1605 if (!token) {1606 throw new Error('Invalid token!');1607 }1608 return request1609 .put(`/api/issues/${id}`)1610 .send({issue})1611 .set('Authorization', token)1612 .then((res) => res.body.data);1613};1614export const deleteIssue = async (id: string, token = getAccessToken()) => {1615 if (!token) {1616 throw new Error('Invalid token!');1617 }1618 return request1619 .delete(`/api/issues/${id}`)1620 .set('Authorization', token)1621 .then((res) => res.body);1622};1623export const addCustomerIssue = async (1624 customerId: string,1625 issueId: string,1626 token = getAccessToken()1627) => {1628 if (!token) {1629 throw new Error('Invalid token!');1630 }1631 return request1632 .post(`/api/customers/${customerId}/issues`)1633 .send({issue_id: issueId})1634 .set('Authorization', token)1635 .then((res) => res.body.data);1636};1637export const removeCustomerIssue = async (1638 customerId: string,1639 issueId: string,1640 token = getAccessToken()1641) => {1642 if (!token) {1643 throw new Error('Invalid token!');1644 }1645 return request1646 .delete(`/api/customers/${customerId}/issues/${issueId}`)1647 .set('Authorization', token)1648 .then((res) => res.body.data);1649};1650type BrowserSessionFilters = {1651 sessionIds?: Array<string>;1652 customerId?: string;1653 isActive?: boolean;1654 limit?: number;1655};1656export const fetchBrowserSessions = async (1657 {customerId, isActive, limit = 100, sessionIds = []}: BrowserSessionFilters,1658 token = getAccessToken()1659): Promise<Array<BrowserSession>> => {1660 if (!token) {1661 throw new Error('Invalid token!');1662 }1663 return request1664 .get(`/api/browser_sessions`)1665 .query(1666 qs.stringify(1667 {1668 ids: sessionIds,1669 customer_id: customerId,1670 active: isActive,1671 limit,1672 },1673 {arrayFormat: 'bracket'}1674 )1675 )1676 .set('Authorization', token)1677 .then((res) => res.body.data);1678};1679export const countBrowserSessions = async (1680 {customerId, isActive}: BrowserSessionFilters,1681 token = getAccessToken()1682) => {1683 if (!token) {1684 throw new Error('Invalid token!');1685 }1686 return request1687 .get(`/api/browser_sessions/count`)1688 .query(1689 qs.stringify(1690 {1691 customer_id: customerId,1692 active: isActive,1693 },1694 {arrayFormat: 'bracket'}1695 )1696 )1697 .set('Authorization', token)1698 .then((res) => res.body.data);1699};1700export const fetchBrowserSession = async (1701 id: string,1702 token = getAccessToken()1703) => {1704 if (!token) {1705 throw new Error('Invalid token!');1706 }1707 return request1708 .get(`/api/browser_sessions/${id}`)1709 .set('Authorization', token)1710 .then((res) => res.body.data);1711};1712type ReportingFilters = {1713 from_date?: string | null;1714 to_date?: string | null;1715};1716export const fetchReportingData = async (1717 filters = {} as ReportingFilters,1718 token = getAccessToken()1719) => {1720 if (!token) {1721 throw new Error('Invalid token!');1722 }1723 return request1724 .get(`/api/reporting`)1725 .query(filters)1726 .set('Authorization', token)1727 .then((res) => res.body.data);1728};1729export const fetchPersonalApiKeys = async (token = getAccessToken()) => {1730 if (!token) {1731 throw new Error('Invalid token!');1732 }1733 return request1734 .get(`/api/personal_api_keys`)1735 .set('Authorization', token)1736 .then((res) => res.body.data);1737};1738export const createPersonalApiKey = async (1739 label: string,1740 token = getAccessToken()1741) => {1742 if (!token) {1743 throw new Error('Invalid token!');1744 }1745 return request1746 .post(`/api/personal_api_keys`)1747 .send({label})1748 .set('Authorization', token)1749 .then((res) => res.body.data);1750};1751export const deletePersonalApiKey = async (1752 id: string,1753 token = getAccessToken()1754) => {1755 if (!token) {1756 throw new Error('Invalid token!');1757 }1758 return request1759 .delete(`/api/personal_api_keys/${id}`)1760 .set('Authorization', token)1761 .then((res) => res.body);1762};1763export const getOnboardingStatus = async (1764 token = getAccessToken()1765): Promise<OnboardingStatus> => {1766 if (!token) {1767 throw new Error('Invalid token!');1768 }1769 return request1770 .get(`/api/onboarding_status`)1771 .set('Authorization', token)1772 .then((res) => res.body);1773};1774export const fetchCannedResponses = async (token = getAccessToken()) => {1775 if (!token) {1776 throw new Error('Invalid token!');1777 }1778 return request1779 .get(`/api/canned_responses`)1780 .set('Authorization', token)1781 .then((res) => res.body.data);1782};1783export const createCannedResponse = async (1784 params: Partial<CannedResponse>,1785 token = getAccessToken()1786) => {1787 if (!token) {1788 throw new Error('Invalid token!');1789 }1790 return request1791 .post(`/api/canned_responses`)1792 .send({canned_response: params})1793 .set('Authorization', token)1794 .then((res) => res.body.data);1795};1796export const updateCannedResponse = async (1797 id: string,1798 updates: Partial<CannedResponse>,1799 token = getAccessToken()1800) => {1801 if (!token) {1802 throw new Error('Invalid token!');1803 }1804 return request1805 .put(`/api/canned_responses/${id}`)1806 .send({canned_response: updates})1807 .set('Authorization', token)1808 .then((res) => res.body.data);1809};1810export const deleteCannedResponse = async (1811 id: string,1812 token = getAccessToken()1813) => {1814 if (!token) {1815 throw new Error('Invalid token!');1816 }1817 return request1818 .delete(`/api/canned_responses/${id}`)1819 .set('Authorization', token)1820 .then((res) => res.body);1821};1822export const fetchLambdas = async (token = getAccessToken()) => {1823 if (!token) {1824 throw new Error('Invalid token!');1825 }1826 return request1827 .get(`/api/lambdas`)1828 .set('Authorization', token)1829 .then((res) => res.body.data);1830};1831export const fetchLambda = async (id: string, token = getAccessToken()) => {1832 if (!token) {1833 throw new Error('Invalid token!');1834 }1835 return request1836 .get(`/api/lambdas/${id}`)1837 .set('Authorization', token)1838 .then((res) => res.body.data);1839};1840export const createNewLambda = async (1841 params: Partial<Lambda>,1842 token = getAccessToken()1843) => {1844 if (!token) {1845 throw new Error('Invalid token!');1846 }1847 return request1848 .post(`/api/lambdas`)1849 .send({lambda: params})1850 .set('Authorization', token)1851 .then((res) => res.body.data);1852};1853export const updateLambda = async (1854 id: string,1855 updates: Partial<Lambda>,1856 token = getAccessToken()1857) => {1858 if (!token) {1859 throw new Error('Invalid token!');1860 }1861 return request1862 .put(`/api/lambdas/${id}`)1863 .send({lambda: updates})1864 .set('Authorization', token)1865 .then((res) => res.body.data);1866};1867export const deleteLambda = async (id: string, token = getAccessToken()) => {1868 if (!token) {1869 throw new Error('Invalid token!');1870 }1871 return request1872 .delete(`/api/lambdas/${id}`)1873 .set('Authorization', token)1874 .then((res) => res.body);1875};1876export const deployLambda = async (1877 id: string,1878 params = {},1879 token = getAccessToken()1880) => {1881 if (!token) {1882 throw new Error('Invalid token!');1883 }1884 return request1885 .post(`/api/lambdas/${id}/deploy`)1886 .send(params)1887 .set('Authorization', token)1888 .then((res) => res.body.data);1889};1890export const invokeLambda = async (1891 id: string,1892 params = {},1893 token = getAccessToken()1894) => {1895 if (!token) {1896 throw new Error('Invalid token!');1897 }1898 return request1899 .post(`/api/lambdas/${id}/invoke`)1900 .send(params)1901 .set('Authorization', token)1902 .then((res) => res.body.data);1903};1904export const sendAdminNotification = async (1905 params = {},1906 token = getAccessToken()1907) => {1908 if (!token) {1909 throw new Error('Invalid token!');1910 }1911 return request1912 .post(`/api/admin/notifications`)1913 .send(params)1914 .set('Authorization', token)1915 .then((res) => res.body.data);1916};1917export const fetchInboxes = async (1918 token = getAccessToken()1919): Promise<Array<Inbox>> => {1920 if (!token) {1921 throw new Error('Invalid token!');1922 }1923 return request1924 .get(`/api/inboxes`)1925 .set('Authorization', token)1926 .then((res) => res.body.data);1927};1928export const fetchPrimaryInbox = async (1929 token = getAccessToken()1930): Promise<Inbox> => {1931 if (!token) {1932 throw new Error('Invalid token!');1933 }1934 return request1935 .get(`/api/inboxes/primary`)1936 .set('Authorization', token)1937 .then((res) => res.body.data);1938};1939export const fetchInbox = async (1940 id: string,1941 token = getAccessToken()1942): Promise<Inbox> => {1943 if (!token) {1944 throw new Error('Invalid token!');1945 }1946 return request1947 .get(`/api/inboxes/${id}`)1948 .set('Authorization', token)1949 .then((res) => res.body.data);1950};1951export const createInbox = async (1952 params: Partial<Inbox>,1953 token = getAccessToken()1954) => {1955 if (!token) {1956 throw new Error('Invalid token!');1957 }1958 return request1959 .post(`/api/inboxes`)1960 .send({inbox: params})1961 .set('Authorization', token)1962 .then((res) => res.body.data);1963};1964export const updateInbox = async (1965 id: string,1966 updates: Partial<Inbox>,1967 token = getAccessToken()1968) => {1969 if (!token) {1970 throw new Error('Invalid token!');1971 }1972 return request1973 .put(`/api/inboxes/${id}`)1974 .send({inbox: updates})1975 .set('Authorization', token)1976 .then((res) => res.body.data);1977};1978export const deleteInbox = async (id: string, token = getAccessToken()) => {1979 if (!token) {1980 throw new Error('Invalid token!');1981 }1982 return request1983 .delete(`/api/inboxes/${id}`)1984 .set('Authorization', token)1985 .then((res) => res.body);...

Full Screen

Full Screen

CardApi.ts

Source:CardApi.ts Github

copy

Full Screen

...14 * @param accessToken15 */16 public static async create(jsonStr: string, accessToken?: AccessToken) {17 if (!accessToken) {18 accessToken = await AccessTokenApi.getAccessToken()19 }20 let url = util.format(this.cardCreateUrl, accessToken.getAccessToken)21 return HttpKit.getHttpDelegate.httpPost(url, jsonStr)22 }23 private static setPayCellUrl: string = 'https://api.weixin.qq.com/card/paycell/set?access_token=%s'24 /**25 * 设置买单接口26 * @param cardId27 * @param isOpen28 * @param accessToken29 */30 public static async setPayCell(cardId: string, isOpen: boolean, accessToken?: AccessToken) {31 if (!accessToken) {32 accessToken = await AccessTokenApi.getAccessToken()33 }34 let url = util.format(this.setPayCellUrl, accessToken.getAccessToken)35 return HttpKit.getHttpDelegate.httpPost(36 url,37 JSON.stringify({38 card_id: cardId,39 is_open: isOpen40 })41 )42 }43 private static setSelfConsumeCellUrl: string = 'https://api.weixin.qq.com/card/selfconsumecell/set?access_token=%s'44 /**45 * 设置自助核销接口46 * @param cardId 卡券ID47 * @param isOpen 是否开启自助核销功能,填true/false,默认为false48 * @param needVerifyCod 用户核销时是否需要输入验证码, 填true/false, 默认为false49 * @param needRemarkAmount 用户核销时是否需要备注核销金额, 填true/false, 默认为false50 * @param accessToken51 */52 public static async setSelfConsumeCell(cardId: string, isOpen: boolean = false, needVerifyCod: boolean = false, needRemarkAmount: boolean = false, accessToken?: AccessToken) {53 if (!accessToken) {54 accessToken = await AccessTokenApi.getAccessToken()55 }56 let url = util.format(this.setSelfConsumeCellUrl, accessToken.getAccessToken)57 return HttpKit.getHttpDelegate.httpPost(58 url,59 JSON.stringify({60 card_id: cardId,61 is_open: isOpen,62 need_verify_cod: needVerifyCod,63 need_remark_amount: needRemarkAmount64 })65 )66 }67 private static createQrcodeCardUrl: string = 'https://api.weixin.qq.com/card/qrcode/create?access_token=%s'68 /**69 * 创建二维码接口70 * @param jsonStr71 * @param accessToken72 */73 public static async createQrcodeCard(jsonStr: string, accessToken?: AccessToken) {74 if (!accessToken) {75 accessToken = await AccessTokenApi.getAccessToken()76 }77 let url = util.format(this.createQrcodeCardUrl, accessToken.getAccessToken)78 return HttpKit.getHttpDelegate.httpPost(url, jsonStr)79 }80 private static createLandingPageCardUrl: string = 'https://api.weixin.qq.com/card/landingpage/create?access_token=%s'81 /**82 * 创建货架接口83 * @param jsonStr84 * @param accessToken85 */86 public static async createLandingPageCard(jsonStr: string, accessToken?: AccessToken) {87 if (!accessToken) {88 accessToken = await AccessTokenApi.getAccessToken()89 }90 let url = util.format(this.createLandingPageCardUrl, accessToken.getAccessToken)91 return HttpKit.getHttpDelegate.httpPost(url, jsonStr)92 }93 private static getHtmlMpNewsUrl: string = 'https://api.weixin.qq.com/card/mpnews/gethtml?access_token=%s'94 /**95 * 图文消息群发卡券96 * @param cardId97 * @param accessToken98 */99 public static async getHtmlMpNews(cardId: string, accessToken?: AccessToken) {100 if (!accessToken) {101 accessToken = await AccessTokenApi.getAccessToken()102 }103 let url = util.format(this.getHtmlMpNewsUrl, accessToken.getAccessToken)104 return HttpKit.getHttpDelegate.httpPost(105 url,106 JSON.stringify({107 card_id: cardId108 })109 )110 }111 private static setTestWhiteListUrl: string = 'https://api.weixin.qq.com/card/testwhitelist/set?access_token=%s'112 /**113 * 设置测试白名单114 * @param jsonStr115 * @param accessToken116 */117 public static async setTestWhiteList(jsonStr: string, accessToken?: AccessToken) {118 if (!accessToken) {119 accessToken = await AccessTokenApi.getAccessToken()120 }121 let url = util.format(this.setTestWhiteListUrl, accessToken.getAccessToken)122 return HttpKit.getHttpDelegate.httpPost(url, jsonStr)123 }124 private static getCodeUrl: string = 'https://api.weixin.qq.com/card/code/get?access_token=%s'125 /**126 * 查询Code接口127 * @param code 单张卡券的唯一标准128 * @param cardId 卡券ID代表一类卡券。自定义code卡券必填。129 * @param checkConsume 是否校验code核销状态130 * @param accessToken131 */132 public static async getCode(code: string, cardId?: string, checkConsume?: boolean, accessToken?: AccessToken) {133 let map = new Map()134 map.set('code', code)135 if (cardId) {136 map.set('card_id', cardId)137 }138 if (checkConsume) {139 map.set('check_consume', checkConsume)140 }141 if (!accessToken) {142 accessToken = await AccessTokenApi.getAccessToken()143 }144 let url = util.format(this.getCodeUrl, accessToken.getAccessToken)145 return HttpKit.getHttpDelegate.httpPost(url, JSON.stringify(map))146 }147 private static consumeCodeUrl: string = 'https://api.weixin.qq.com/card/code/consume?access_token=%s'148 /**149 * 核销Code接口150 * @param code 需核销的Code码151 * @param cardId 卡券ID。创建卡券时use_custom_code填写true时必填。非自定义Code不必填写。152 * @param accessToken153 */154 public static async consume(code: string, cardId?: string, accessToken?: AccessToken) {155 let map = new Map()156 map.set('code', code)157 if (cardId) {158 map.set('card_id', cardId)159 }160 if (!accessToken) {161 accessToken = await AccessTokenApi.getAccessToken()162 }163 let url = util.format(this.consumeCodeUrl, accessToken.getAccessToken)164 return HttpKit.getHttpDelegate.httpPost(url, JSON.stringify(map))165 }166 /**167 * 线上核销Code接口168 * @param code 需核销的Code码169 * @param openid 当前卡券使用者的openid,通常通过网页授权登录或自定义url跳转参数获得。170 * @param accessToken171 */172 public static async consumeOnline(code: string, openid: string, accessToken?: AccessToken) {173 if (!accessToken) {174 accessToken = await AccessTokenApi.getAccessToken()175 }176 let url = util.format(this.consumeCodeUrl, accessToken.getAccessToken)177 return HttpKit.getHttpDelegate.httpPost(178 url,179 JSON.stringify({180 code: code,181 openid: openid182 })183 )184 }185 private static decryptCodeUrl: string = 'https://api.weixin.qq.com/card/code/decrypt?access_token=%s'186 /**187 * Code解码接口188 * @param encryptCode 经过加密的Code码189 * @param accessToken190 */191 public static async decryptCode(encryptCode: string, accessToken?: AccessToken) {192 if (!accessToken) {193 accessToken = await AccessTokenApi.getAccessToken()194 }195 let url = util.format(this.decryptCodeUrl, accessToken.getAccessToken)196 return HttpKit.getHttpDelegate.httpPost(197 url,198 JSON.stringify({199 encrypt_code: encryptCode200 })201 )202 }203 private static setDepositUrl: string = 'http://api.weixin.qq.com/card/code/deposit?access_token=%s'204 /**205 * 导入自定义code206 * @param cardId 需要进行导入code的卡券ID207 * @param codeList 需导入微信卡券后台的自定义code,上限为100个。208 * @param accessToken209 */210 public static async setDeposit(cardId: string, codeList: [], accessToken?: AccessToken) {211 if (!accessToken) {212 accessToken = await AccessTokenApi.getAccessToken()213 }214 let url = util.format(this.setDepositUrl, accessToken.getAccessToken)215 return HttpKit.getHttpDelegate.httpPost(216 url,217 JSON.stringify({218 card_id: cardId,219 code: codeList220 })221 )222 }223 private static getDepositCountUrl: string = 'http://api.weixin.qq.com/card/code/getdepositcount?access_token=%s'224 /**225 * 查询导入code数目接口226 * @param cardId227 * @param accessToken228 */229 public static async getDepositCount(cardId: string, accessToken?: AccessToken) {230 if (!accessToken) {231 accessToken = await AccessTokenApi.getAccessToken()232 }233 let url = util.format(this.getDepositCountUrl, accessToken.getAccessToken)234 return HttpKit.getHttpDelegate.httpPost(235 url,236 JSON.stringify({237 card_id: cardId238 })239 )240 }241 private static checkCodeUrl: string = 'http://api.weixin.qq.com/card/code/checkcode?access_token=%s'242 /**243 * 核查code接口244 * @param cardId 进行导入code的卡券ID245 * @param codeList 已经微信卡券后台的自定义code,上限为100个246 * @param accessToken247 */248 public static async checkCode(cardId: string, codeList: [], accessToken?: AccessToken) {249 if (!accessToken) {250 accessToken = await AccessTokenApi.getAccessToken()251 }252 let url = util.format(this.checkCodeUrl, accessToken.getAccessToken)253 return HttpKit.getHttpDelegate.httpPost(254 url,255 JSON.stringify({256 card_id: cardId,257 code: codeList258 })259 )260 }261 private static getUserCardListUrl: string = 'https://api.weixin.qq.com/card/user/getcardlist?access_token=%s'262 /**263 * 获取用户已领取卡券接口264 * @param openid 需要查询的用户openid265 * @param cardId 卡券ID 不填写时默认查询当前appid下的卡券266 * @param accessToken267 */268 public static async getUserCardList(openid: string, cardId?: string, accessToken?: AccessToken) {269 let map = new Map()270 map.set('openid', openid)271 if (cardId) {272 map.set('card_id', cardId)273 }274 if (!accessToken) {275 accessToken = await AccessTokenApi.getAccessToken()276 }277 let url = util.format(this.getUserCardListUrl, accessToken.getAccessToken)278 return HttpKit.getHttpDelegate.httpPost(url, JSON.stringify(map))279 }280 private static getCardUrl: string = 'https://api.weixin.qq.com/card/get?access_token=%s'281 /**282 * 查看卡券详情283 * @param cardId 卡券ID284 * @param accessToken285 */286 public static async getCard(cardId: string, accessToken?: AccessToken) {287 if (!accessToken) {288 accessToken = await AccessTokenApi.getAccessToken()289 }290 let url = util.format(this.getCardUrl, accessToken.getAccessToken)291 return HttpKit.getHttpDelegate.httpPost(292 url,293 JSON.stringify({294 card_id: cardId295 })296 )297 }298 private static getBatchUrl: string = 'https://api.weixin.qq.com/card/batchget?access_token=%s'299 /**300 * 批量查询卡券列表301 * @param offset 查询卡列表的起始偏移量,从0开始,即offset: 5是指从从列表里的第六个开始读取302 * @param count 需要查询的卡片的数量(数量最大50)303 * @param statusList 支持开发者拉出指定状态的卡券列表304 * @param accessToken305 *306 * “CARD_STATUS_NOT_VERIFY”, 待审核 ;307 * “CARD_STATUS_VERIFY_FAIL”, 审核失败;308 * “CARD_STATUS_VERIFY_OK”, 通过审核;309 * “CARD_STATUS_DELETE”, 卡券被商户删除;310 * “CARD_STATUS_DISPATCH”,在公众平台投放过的卡券311 */312 public static async getBatch(offset: number, count: number, statusList?: [], accessToken?: AccessToken) {313 let map = new Map()314 map.set('offset', offset)315 map.set('count', count)316 if (statusList) {317 map.set('status_list', statusList)318 }319 if (!accessToken) {320 accessToken = await AccessTokenApi.getAccessToken()321 }322 let url = util.format(this.getBatchUrl, accessToken.getAccessToken)323 return HttpKit.getHttpDelegate.httpPost(url, JSON.stringify(map))324 }325 private static updateUrl: string = 'https://api.weixin.qq.com/card/update?access_token=%s'326 /**327 * 更改卡券信息接口328 * @param jsonStr329 * @param accessToken330 */331 public static async update(jsonStr: string, accessToken?: AccessToken) {332 if (!accessToken) {333 accessToken = await AccessTokenApi.getAccessToken()334 }335 let url = util.format(this.updateUrl, accessToken.getAccessToken)336 return HttpKit.getHttpDelegate.httpPost(url, jsonStr)337 }338 private static modifyStockUrl: string = 'https://api.weixin.qq.com/card/modifystock?access_token=%s'339 /**340 * 修改库存接口341 * @param cardId 卡券ID342 * @param increase 增加多少库存,支持不填或填0343 * @param reduce 减少多少库存,可以不填或填0344 * @param accessToken345 */346 public static async modifyStock(cardId: string, increase: number = 0, reduce: number = 0, accessToken?: AccessToken) {347 if (!accessToken) {348 accessToken = await AccessTokenApi.getAccessToken()349 }350 let url = util.format(this.modifyStockUrl, accessToken.getAccessToken)351 return HttpKit.getHttpDelegate.httpPost(352 url,353 JSON.stringify({354 card_id: cardId,355 increase_stock_value: increase,356 reduce_stock_value: reduce357 })358 )359 }360 private static updateCodeUrl: string = 'https://api.weixin.qq.com/card/code/update?access_token='361 /**362 * 更改Code接口363 * @param code 需变更的Code码364 * @param newCode 变更后的有效Code码365 * @param cardId 卡券ID。自定义Code码卡券为必填366 * @param accessToken367 */368 public static async updateCode(code: string, newCode: string, cardId?: string, accessToken?: AccessToken) {369 let map = new Map()370 map.set('code', code)371 map.set('new_code', newCode)372 if (cardId) {373 map.set('card_id', cardId)374 }375 if (!accessToken) {376 accessToken = await AccessTokenApi.getAccessToken()377 }378 let url = util.format(this.updateCodeUrl, accessToken.getAccessToken)379 return HttpKit.getHttpDelegate.httpPost(url, JSON.stringify(map))380 }381 private static deleteUrl: string = 'https://api.weixin.qq.com/card/delete?access_token=%s'382 /**383 * 删除卡券接口384 * @param cardId 卡券ID385 * @param accessToken386 */387 public static async delete(cardId: string, accessToken?: AccessToken) {388 if (!accessToken) {389 accessToken = await AccessTokenApi.getAccessToken()390 }391 let url = util.format(this.deleteUrl, accessToken.getAccessToken)392 return HttpKit.getHttpDelegate.httpPost(393 url,394 JSON.stringify({395 card_id: cardId396 })397 )398 }399 private static unavailableUrl: string = 'https://api.weixin.qq.com/card/code/unavailable?access_token=%s'400 /**401 * 设置卡券失效接口402 * @param cardId 卡券ID403 * @param code 设置失效的Code码404 * @param reason 失效理由405 * @param accessToken406 */407 public static async unavailable(cardId?: string, code?: string, reason?: string, accessToken?: AccessToken) {408 if (!code && !cardId) {409 throw new Error('code 与 card_id 不能同时为空')410 }411 let map = new Map()412 if (code) map.set('code', code)413 if (cardId) map.set('card_id', cardId)414 if (reason) map.set('reason', reason)415 if (!accessToken) {416 accessToken = await AccessTokenApi.getAccessToken()417 }418 let url = util.format(this.unavailableUrl, accessToken.getAccessToken)419 return HttpKit.getHttpDelegate.httpPost(url, JSON.stringify(map))420 }421 private static getCardBizUinInfoUrl: string = 'https://api.weixin.qq.com/datacube/getcardbizuininfo?access_token=%s'422 /**423 * 拉取卡券概况数据接口424 * @param beginDate 查询数据的起始时间425 * @param endDate 查询数据的截至时间426 * @param condSource 卡券来源,0为公众平台创建的卡券数据 、1是API创建的卡券数据427 * @param accessToken428 */429 public static async getCardBizUinInfo(beginDate: string, endDate: string, condSource: number = 0, accessToken?: AccessToken) {430 if (!accessToken) {431 accessToken = await AccessTokenApi.getAccessToken()432 }433 let url = util.format(this.getCardBizUinInfoUrl, accessToken.getAccessToken)434 return HttpKit.getHttpDelegate.httpPost(435 url,436 JSON.stringify({437 begin_date: beginDate,438 end_date: endDate,439 cond_source: condSource440 })441 )442 }443 private static getFreeCardInfoUrl: string = 'https://api.weixin.qq.com/datacube/getcardcardinfo?access_token=%s'444 /**445 * 获取免费券数据接口446 * @param beginDate 查询数据的起始时间447 * @param endDate 查询数据的截至时间448 * @param condSource 卡券来源,0为公众平台创建的卡券数据、1是API创建的卡券数据449 * @param cardId 卡券ID 填写后,指定拉出该卡券的相关数据450 * @param accessToken451 */452 public static async getFreeCardInfo(beginDate: string, endDate: string, condSource: number = 0, cardId?: string, accessToken?: AccessToken) {453 let map = new Map()454 map.set('begin_date', beginDate)455 map.set('end_date', endDate)456 map.set('cond_source', condSource)457 if (cardId) map.set('card_id', cardId)458 if (!accessToken) {459 accessToken = await AccessTokenApi.getAccessToken()460 }461 let url = util.format(this.getFreeCardInfoUrl, accessToken.getAccessToken)462 return HttpKit.getHttpDelegate.httpPost(url, JSON.stringify(map))463 }464 private static subMerchantSubmitUrl: string = 'https://api.weixin.qq.com/card/submerchant/submit?access_token=%s'465 /**466 * 创建子商户接口467 * @param data468 * @param accessToken469 */470 public static async subMerchantSubmit(data: string, accessToken?: AccessToken) {471 if (!accessToken) {472 accessToken = await AccessTokenApi.getAccessToken()473 }474 let url = util.format(this.subMerchantSubmitUrl, accessToken.getAccessToken)475 return HttpKit.getHttpDelegate.httpPost(url, data)476 }477 private static subMerchantUpdateUrl: string = 'https://api.weixin.qq.com/card/submerchant/update?access_token=%s'478 /**479 * 更新子商户接口480 * @param data481 * @param accessToken482 */483 public static async subMerchantUpdate(data: string, accessToken?: AccessToken) {484 if (!accessToken) {485 accessToken = await AccessTokenApi.getAccessToken()486 }487 let url = util.format(this.subMerchantUpdateUrl, accessToken.getAccessToken)488 return HttpKit.getHttpDelegate.httpPost(url, data)489 }490 private static getSubMerchantUrl: string = 'https://api.weixin.qq.com/card/submerchant/get?access_token=%s'491 /**492 * 拉取单个子商户信息接口493 * @param merchantId494 * @param accessToken495 */496 public static async getSubMerchant(merchantId: string, accessToken?: AccessToken) {497 if (!accessToken) {498 accessToken = await AccessTokenApi.getAccessToken()499 }500 let url = util.format(this.getSubMerchantUrl, accessToken.getAccessToken)501 return HttpKit.getHttpDelegate.httpPost(502 url,503 JSON.stringify({504 merchant_id: merchantId505 })506 )507 }508 private static batchGetSubMerchantUrl: string = 'https://api.weixin.qq.com/card/submerchant/batchget?access_token=%s'509 /**510 * 批量拉取子商户信息接口511 * @param beginId 起始的子商户id512 * @param limit 拉取的子商户的个数,最大值为100513 * @param status 子商户审核状态,填入后,只会拉出当前状态的子商户514 * @param accessToken accessToken515 */516 public static async batchGetSubMerchant(beginId: string, limit: number, status: string, accessToken?: AccessToken) {517 if (!accessToken) {518 accessToken = await AccessTokenApi.getAccessToken()519 }520 let url = util.format(this.batchGetSubMerchantUrl, accessToken.getAccessToken)521 return HttpKit.getHttpDelegate.httpPost(522 url,523 JSON.stringify({524 begin_id: beginId,525 limit: limit > 100 ? 100 : limit,526 status: status527 })528 )529 }530 private static getApplyProtocolUrl: string = 'https://api.weixin.qq.com/card/getapplyprotocol?access_token=%s'531 /**532 * 卡券开放类目查询接口533 * @param accessToken534 */535 public static async getApplyProtocol(accessToken?: AccessToken) {536 if (!accessToken) {537 accessToken = await AccessTokenApi.getAccessToken()538 }539 let url = util.format(this.getApplyProtocolUrl, accessToken.getAccessToken)540 return HttpKit.getHttpDelegate.httpGet(url)541 }...

Full Screen

Full Screen

hara-work.js

Source:hara-work.js Github

copy

Full Screen

1/**2 * @author Tran Dinh Hoang3 */4'use strict';5const getAccessToken = require('./hr-token-manager').get;6let callAPI = {};7module.exports = callAPI;8const BASE_HR_URL = global.config.hr_api;9const BASE_ACCOUNT_HR = global.config.hr_account_api;10// --------------------------- departments -------------------------11callAPI.HR_LIST_DEPARTMENT = {12 baseURL : BASE_HR_URL,13 url : '/departments',14 method : 'get',15 pre_send : getAccessToken,16 default_params : {17 page : 1,18 page_size : 20,19 isCount : true,20 },21 params : {22 page : 1,23 page_size : 20,24 query : '',25 parentId : 1031,26 unitId : 0,27 isGetAll : false,28 isCount : false,29 }30};31callAPI.HR_DEPARTMENT_DETAIL = {32 baseURL : BASE_HR_URL,33 url : '/department/{id}',34 method : 'get',35 pre_send : getAccessToken,36 url_args : {37 id : 19238 }39};40callAPI.HR_LIST_CONTRACT_TYPE = {41 baseURL : BASE_HR_URL,42 url : '/contracttypes',43 method : 'get',44 pre_send : getAccessToken45};46// --------------------------- departments unit -------------------------47callAPI.HR_LIST_DEPARTMENT_UNIT = {48 baseURL : BASE_HR_URL,49 url : '/departmentUnits',50 method : 'get',51 pre_send : getAccessToken52};53callAPI.HR_DEPARTMENT_UNIT_DETAIL = {54 baseURL : BASE_HR_URL,55 url : '/departmentUnit/{id}',56 method : 'get',57 pre_send : getAccessToken58};59//----------------------------- Employees --------------------------60callAPI.HR_LIST_EMPLOYEES = {61 baseURL : BASE_HR_URL,62 url : '/employees',63 method : 'get',64 pre_send : getAccessToken,65 params : {66 departmentId : 0,67 page : 1,68 page_size : 20,69 dateFilter : 0,70 fromDate : '',71 toDate : '',72 jobtitleId : 0,73 contractTypeId : 0,74 query : '',75 statusTimeKeeping : 0,76 statusactive : 1,77 isBasic: true,78 contractDay: 0,79 contractDayQueryType: 080 }81};82callAPI.HR_LIST_EMPLOYEES_ALL = {83 baseURL : BASE_HR_URL,84 url : '/employees/getall',85 method : 'get',86 pre_send : getAccessToken,87 params : {88 departmentId : 0,89 page : 1,90 page_size : 20,91 dateFilter : 0,92 fromDate : '',93 toDate : '',94 jobtitleId : 0,95 contractTypeId : 0,96 query : '',97 statusTimeKeeping : 0,98 statusactive : 0,99 }100};101callAPI.GET_EMPLOYEES_DETAIL = {102 baseURL : BASE_HR_URL,103 url : '/employees/{id}',104 method : 'get',105 pre_send : getAccessToken106};107callAPI.GET_EMPLOYEE_BY_HR_ID = {108 baseURL : BASE_HR_URL,109 url : '/employees/getbyharaid',110 method : 'get',111 params : {112 haraId : 200000008811113 },114 pre_send : getAccessToken,115};116//------------------------------ salary elements ---------------------117callAPI.HR_LIST_SALARY_ELEMENTS = {118 baseURL : BASE_HR_URL,119 url : '/salaryElements',120 method : 'get',121 pre_send : getAccessToken,122 default_params : {123 page : 1,124 page_size : 20,125 },126 params : {127 page : 1,128 page_size : 20,129 query : '',130 }131};132callAPI.HR_LIST_ALL_SALARY_ELEMENTS = {133 baseURL : BASE_HR_URL,134 url : '/salaryElements/getall',135 method : 'get',136 pre_send : getAccessToken,137};138callAPI.HR_GET_SALARY_ELEMENT = {139 baseURL : BASE_HR_URL,140 url : '/salaryElement/{id}',141 method : 'get',142 pre_send : getAccessToken,143 url_args : {144 id : 68145 }146};147callAPI.HR_ADD_SALARY_DATA = {148 baseURL : BASE_HR_URL,149 url : '/salaryData?elementCode={elementCode}&authenticateCode={authenticateCode}',150 method : 'post',151 pre_send : getAccessToken,152 data : {153 'haraId' : 0,154 'employeeId' : 0,155 'salaryDay' : '2018-11-29T10:24:52.658Z',156 'total' : 0,157 'note' : 'string'158 },159 url_args : {160 elementCode : 0,161 authenticateCode : 0,162 }163};164callAPI.HR_ADD_LIST_SALARY_DATA = {165 baseURL : BASE_HR_URL,166 url : '/salaryData/addlist',167 method : 'post',168 pre_send : getAccessToken,169 data : [{170 'userId' : 'string',171 'salaryDay' : '2018-11-30T04:56:04.275Z',172 'total' : 0,173 'note' : 'string',174 'elementCode' : 'string',175 'salaryPeriodCode' : 'string'176 }]177};178callAPI.HR_SALARY_DATA_RESET_POINT = {179 baseURL : BASE_HR_URL,180 url : '/salaryData/deactive',181 method : 'put',182 pre_send : getAccessToken,183 params : {184 employeeId : 0,185 haraId : 0,186 day : '',187 elementCode : '',188 authenticationCode : ''189 }190}191//------------------------------ Jobtitle ---------------------192callAPI.HR_LIST_JOB_TITLE = {193 baseURL : BASE_HR_URL,194 url : '/jobtitles', 195 method : 'get',196 pre_send : getAccessToken,197 params : {198 page:0,199 page_size:0,200 query:'',201 parentId:0,202 levelId:0,203 departmentId:0,204 isGetAll:false,205 isCount:false,206 getDeptManager:false207 }208}209//---------------------------------- USER -----------------------------------210callAPI.GET_USER = {211 baseURL : BASE_ACCOUNT_HR,212 url : '/users/{id}',213 method : 'get',214 pre_send : getAccessToken,215};216callAPI.HR_ME = {217 baseURL : BASE_ACCOUNT_HR,218 url : '/me',219 method : 'get',220 pre_send : getAccessToken,221};222//------------------------------- SUPERVISOR ----------------------------------223callAPI.HR_SUPERVISOR_DEPARTMENTS = {224 baseURL : BASE_HR_URL,225 url : '/supervisor/departments',226 method : 'get',227 pre_send : getAccessToken,...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var stf = require('devicefarmer-stf-client');2var options = {3};4var client = new stf(options);5client.getAccessToken(function (err, result) {6 if (err) {7 console.log(err);8 } else {9 console.log(result);10 }11});12var stf = require('devicefarmer-stf-client');13var options = {14};15var client = new stf(options);16client.getDevices(function (err, result) {17 if (err) {18 console.log(err);19 } else {20 console.log(result);21 }22});23var stf = require('devicefarmer-stf-client');24var options = {25};26var client = new stf(options);27client.getDevice('device_id', function (err, result) {28 if (err) {29 console.log(err);30 } else {31 console.log(result);32 }33});34var stf = require('devicefarmer-stf-client');35var options = {36};37var client = new stf(options);38client.getDevice('device_id', function (err, result) {39 if (err) {40 console.log(err);41 } else {42 console.log(result);43 }44});45var stf = require('devicefarmer-stf-client');46var options = {47};48var client = new stf(options);49client.getDevice('device_id', function (err, result) {50 if (err) {51 console.log(err);52 } else

Full Screen

Using AI Code Generation

copy

Full Screen

1var stf = require('devicefarmer-stf');2var device = client.getDevice('serialNumber');3var accessToken = device.getAccessToken();4console.log(accessToken);5var stf = require('devicefarmer-stf');6var device = client.getDevice('serialNumber');7var accessToken = device.getAccessToken();8console.log(accessToken);9var stf = require('devicefarmer-stf');10var device = client.getDevice('serialNumber');11var accessToken = device.getAccessToken();12console.log(accessToken);13var stf = require('devicefarmer-stf');14var device = client.getDevice('serialNumber');15var accessToken = device.getAccessToken();16console.log(accessToken);17var stf = require('devicefarmer-stf');18var device = client.getDevice('serialNumber');19var accessToken = device.getAccessToken();20console.log(accessToken);21var stf = require('devicefarmer-stf');22var device = client.getDevice('serialNumber');23var accessToken = device.getAccessToken();24console.log(accessToken);25var stf = require('devicefarmer-stf');26var device = client.getDevice('serialNumber');27var accessToken = device.getAccessToken();28console.log(accessToken);29var stf = require('devicefarmer-stf');

Full Screen

Using AI Code Generation

copy

Full Screen

1var stf = require('devicefarmer-stf-client');2var client = new stf.Client();3client.getAccessToken("device_id", function(err, token) {4 if (err) {5 console.log("Error: " + err);6 } else {7 console.log("Token: " + token);8 }9});

Full Screen

Using AI Code Generation

copy

Full Screen

1var stf = require('devicefarmer-stf-client');2client.getAccessToken('7d2e3be3').then(function(token) {3 console.log(token);4}).catch(function(err) {5 console.log(err);6});7{

Full Screen

Using AI Code Generation

copy

Full Screen

1var client = require('devicefarmer-stf-client');2stf.getAccessToken('admin', 'admin').then(function(token){3 console.log(token);4 stf.getDevices(token).then(function(devices){5 console.log(devices);6 })7})8var client = require('devicefarmer-stf-client');9stf.getAccessToken('admin', 'admin').then(function(token){10 console.log(token);11 stf.getDevices(token).then(function(devices){12 console.log(devices);13 })14})15var client = require('devicefarmer-stf-client');16stf.getAccessToken('admin', 'admin').then(function(token){17 console.log(token);18 stf.getDevices(token).then(function(devices){19 console.log(devices);20 })21})22var client = require('devicefarmer-stf-client');23stf.getAccessToken('admin', 'admin').then(function(token){24 console.log(token);25 stf.getDevices(token).then(function(devices){26 console.log(devices);27 })28})29var client = require('devicefarmer-stf-client');

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run devicefarmer-stf automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful