@ref247/affiliate-sdk
Version:
Ref247.io Affiliate SDK - integrate with us from you backend or build your custom UI
3 lines (2 loc) • 16.9 kB
JavaScript
var ref247AffiliateSDK=function(a,t){"use strict";var i,e,n,r,s,o,c,p,g,u,d,m;a.ApplicationEvent=void 0,(i=a.ApplicationEvent||(a.ApplicationEvent={})).CREATE_CAMPAIGN="create_campaign",i.CREATE_COMMISSION_STRUCTURE="create_commission_structure",i.CREATE_TRACKING="create_tracking",i.MAIL_SEND="mail_send",i.DELETE_AFFILIATE="delete_affiliate",i.ACTIVATE_AFFILIATE="activate_affiliate",i.INCREMENT_AFFILIATELINK_CLICK="increment_affiliatelink_click",i.PAYMENT_EVENT="payment_event",a.ApplicationQueue=void 0,(e=a.ApplicationQueue||(a.ApplicationQueue={})).AFFILIATION_QUEUE="affiliation_queue",e.COMMISSION_QUEUE="commission_queue",e.TRACKING_QUEUE="tracking_queue",e.MAIL_QUEUE="mail_queue",e.PAYMENT_QUEUE="payment_queue",a.ApplicationEventService=void 0,(n=a.ApplicationEventService||(a.ApplicationEventService={})).AFFILIATION_SERVICE="affiliation_service",n.COMMISSION_SERVICE="commission_service",n.TRACKING_SERVICE="tracking_service",n.MAIL_SERVICE="mail_service",n.PAYMENT_SERVICE="payment_service",a.OrganizationPlanEnum=void 0,(r=a.OrganizationPlanEnum||(a.OrganizationPlanEnum={})).Free="Free",r.Starter="Starter",r.Growth="Growth",r.Enterprise="Enterprise",a.CommissionStatusEnum=void 0,(s=a.CommissionStatusEnum||(a.CommissionStatusEnum={})).PENDING="pending",s.PAID="paid",s.REJECTED="rejected",a.ConditionOperatorEnum=void 0,(o=a.ConditionOperatorEnum||(a.ConditionOperatorEnum={})).GREATER_THAN=">",o.GREATER_THAN_OR_EQUAL=">=",o.LESS_THAN="<",o.LESS_THAN_OR_EQUAL="<=",o.EQUALS="=",o.NOT_EQUALS="!=",o.NONE="NONE",a.OrderEnum=void 0,(c=a.OrderEnum||(a.OrderEnum={})).ASC="ASC",c.DESC="DESC",a.FileTypeEnum=void 0,(p=a.FileTypeEnum||(a.FileTypeEnum={})).PROFILE_PICTURE="PROFILE_PICTURE",p.ORGANIZATION_LOGO="ORGANIZATION_LOGO",p.ORGANIZATION_AFFILIATE_FILES="ORGANIZATION_AFFILIATE_FILES",a.OrgCurrencyEnum=void 0,(g=a.OrgCurrencyEnum||(a.OrgCurrencyEnum={})).USD="USD",g.EUR="EUR",a.OrgEventTypeEnum=void 0,(u=a.OrgEventTypeEnum||(a.OrgEventTypeEnum={})).click="click",u.deposit="deposit",a.PaymentStatusEnum=void 0,(d=a.PaymentStatusEnum||(a.PaymentStatusEnum={})).PENDING="pending",d.COMPLETED="completed",d.FAILED="failed",d.REFUNDED="refunded",a.RoleEnum=void 0,(m=a.RoleEnum||(a.RoleEnum={})).Admin="admin",m.Manager="manager",m.Viewer="viewer",m.Affiliate="affiliate",a.IntegrationTypeEnum=void 0,(a.IntegrationTypeEnum||(a.IntegrationTypeEnum={})).Gemini="gemini";class l{apiUrl;apiKey;apiSecret;api;constructor(a,i,e){this.apiKey=i,this.apiSecret=e,this.apiUrl=a||"https://ref247.io/api",this.api=t.create({baseURL:this.apiUrl,headers:{"Content-Type":"application/json"}}),this.api.interceptors.request.use((a=>(this.apiKey&&this.apiSecret&&(a.headers["X-API-KEY"]=this.apiKey,a.headers["x-api-secret"]=this.apiSecret),a)))}static init(a,t,i){return new l(a,t,i)}getApiInstance(){return this.api}setBearer(a){this.api.interceptors.request.use((t=>(a&&(t.headers.Authorization=`Bearer ${a}`),t)))}async validateMagicToken(a){const{data:t}=await this.api.get(`/auth/magic-login?token=${a}`);return t}async loginByMagicLink(a,t){const{data:i}=await this.api.post("/auth/login/magic-link",{email:a,turnstileToken:t});return i}async register(a,t,i,e){const{data:n}=await this.api.post("/auth/register",{firstName:a,lastName:t,email:i,turnstileToken:e});return n}async getRoles(){const{data:a}=await this.api.get("/role");return a}async getMe(){const{data:a}=await this.api.get("/user/me");return a}async getUserAffiliationsByOrg(a){const{data:t}=await this.api.get(`/affiliate/${a}/organization/me`);return t}async updateUser(a,t){const{data:i}=await this.api.patch(`/user/${a}`,t);return i}async addUserToOrganization(a,t){const{data:i}=await this.api.post(`/organizations/${a}/users`,t);return i}async updateUserRole(a,t,i){const{data:e}=await this.api.patch(`/organizations/${a}/users/${t}/role`,{roleId:i});return e}async enterpriseRequest(a){await this.api.put(`/organizations/${a}/enterpriseRequest`)}async deleteUserFromOrganization(a,t){const{data:i}=await this.api.delete(`/organizations/${a}/users/${t}`);return i}async getUsersFromOrganization(a,t=1,i=10,e="",n="createdAt",r="DESC",s=!1){const{data:o}=await this.api.get(`/organizations/${a}/users?page=${t}&take=${i}&searchTerm=${e}&orderBy=${n}&order=${r}&withDeleted=${s}`);return o}async getOrganizations(){const{data:a}=await this.api.get("/organizations");return a}async createOrganization(a,t){const{data:i}=await this.api.post("/organizations",{name:a,userId:t});return i}async updateOrganization(a,t){const{data:i}=await this.api.patch(`/organizations/${a}`,t);return i}async getOrganizationTheme(a){const{data:t}=await this.api.get(`/organizations/${a}/theme`);return t}async getOrganizationCurrency(a){const{data:t}=await this.api.get(`/organizations/${a}/currency`);return t}async addOrganizationCurrency(a,t){const{data:i}=await this.api.post(`/organizations/${a}/currency`,{name:t});return i}async updateOrganizationCurrency(a,t,i){const{data:e}=await this.api.patch(`/organizations/${a}/currency/${t}`,{name:i});return e}async removeOrganizationCurrency(a,t){const{data:i}=await this.api.delete(`/organizations/${a}/currency/${t}`);return i}async getOrganizationPlan(a){const{data:t}=await this.api.get(`/organizations/${a}/plan`);return t}async getPricingPlans(){const{data:a}=await this.api.get("/plan");return a}async getPricingPlan(a){const{data:t}=await this.api.get(`/plan/${a}`);return t}async getOrganizationEventTypes(a){const{data:t}=await this.api.get(`/organizations/${a}/eventTypes`);return t}async addOrganizationEventType(a,t){const{data:i}=await this.api.post(`/organizations/${a}/eventTypes`,{name:t});return i}async updateOrganizationEventType(a,t,i){const{data:e}=await this.api.patch(`/organizations/${a}/eventTypes/${t}`,{name:i});return e}async removeOrganizationEventType(a,t){const{data:i}=await this.api.delete(`/organizations/${a}/eventTypes/${t}`);return i}async getOrganizationEnabledIntegrations(a){const{data:t}=await this.api.get(`/organizations/${a}/integrations/enabled`);return t}async getOrganizationIntegrations(a){const{data:t}=await this.api.get(`/organizations/${a}/integrations`);return t}async addOrganizationIntegration(a,t){const{data:i}=await this.api.post(`/organizations/${a}/integrations`,t);return i}async removeOrganizationIntegration(a,t){const{data:i}=await this.api.delete(`/organizations/${a}/integrations/${t}`);return i}async getAffiliates(a,t=1,i=10,e="",n="createdAt",r="DESC",s=!1){const{data:o}=await this.api.get(`/affiliate/${a}/organization?page=${t}&take=${i}&searchTerm=${e}&orderBy=${n}&order=${r}&withDeleted=${s}`);return o}async getAffiliatesByIds(a,t){const{data:i}=await this.api.get(`/affiliate/${a}/organization/basic?affiliateIds=${t.join(",")}`);return i}async createAffiliate(a){const{data:t}=await this.api.post("/affiliate",a);return t}async addCampaignToAffiliate(a,t){const{data:i}=await this.api.patch(`/affiliate/${a}/campaign/${t}`);return i}async removeCampaignToAffiliate(a,t){const{data:i}=await this.api.delete(`/affiliate/${a}/campaign/${t}`);return i}async getAffiliate(a){const{data:t}=await this.api.get(`/affiliate/${a}`);return t}async getAffiliateReferrals(a,t=1,i=10,e="",n="createdAt",r="DESC",s=!1){const{data:o}=await this.api.get(`/affiliate/${a}/referrals?page=${t}&take=${i}&searchTerm=${e}&orderBy=${n}&order=${r}&withDeleted=${s}`);return o}async getAffiliateCommissionsGenerated(a,t=1,i=10,e="",n="createdAt",r="DESC"){const{data:s}=await this.api.get(`/commission/${a}/generated?page=${t}&take=${i}&searchTerm=${e}&orderBy=${n}&order=${r}`);return s}async getAffiliateCommissionsGained(a,t=1,i=10,e="",n="createdAt",r="DESC"){const{data:s}=await this.api.get(`/commission/${a}/gained?page=${t}&take=${i}&searchTerm=${e}&orderBy=${n}&order=${r}`);return s}async getAffiliatesByAffiliateId(a,t=1,i=10,e="",n="createdAt",r="DESC",s=!1){const{data:o}=await this.api.get(`/affiliate/${a}/referralsList?page=${t}&take=${i}&searchTerm=${e}&orderBy=${n}&order=${r}&withDeleted=${s}`);return o}async updateAffiliate(a,t){const{data:i}=await this.api.patch(`/affiliate/${a}`,t);return i}async getAffiliateLinkById(a){const{data:t}=await this.api.get(`/marketing/affiliate-link/${a}`);return t}async getAffiliateLinkByUri(a){const{data:t}=await this.api.get(`/marketing/affiliate-link/uri/${a}`);return t}async createAffiliateLink(a){const{data:t}=await this.api.post("/marketing/affiliate-link",a);return t}async deleteAffiliateLink(a){const{data:t}=await this.api.delete(`/marketing/affiliate-link/${a}`);return t}async getAllAffiliateLinksOfAffiliate(a,t=!1,i=1,e=10,n="",r="createdAt",s="DESC"){const{data:o}=await this.api.get(`/marketing/affiliate-link/affiliation/${a}?page=${i}&take=${e}&searchTerm=${n}&orderBy=${r}&order=${s}&withDeleted=${t}`);return o}async getAllAffiliateLinksOfOrganization(a,t=!1,i=1,e=10,n="",r="createdAt",s="DESC"){const{data:o}=await this.api.get(`/marketing/affiliate-link/organization/${a}?page=${i}&take=${e}&searchTerm=${n}&orderBy=${r}&order=${s}&withDeleted=${t}`);return o}async createCampaign(a){const{data:t}=await this.api.post("/marketing/campaign",a);return t}async getAllCampaignsOfOrganization(a,t=!1){const{data:i}=await this.api.get(`/marketing/${a}/campaign?withDeleted=${t}`);return i}async getCampaignsByIds(a,t){const{data:i}=await this.api.get(`/marketing/${a}/campaign?withDeleted=true&campaignIds=${t.join(",")}`);return i}async updateCampaign(a,t){const{data:i}=await this.api.patch(`/marketing/campaign/${a}`,t);return i}async updateCampaignAssets(a,t){const{data:i}=await this.api.patch(`/marketing/campaign/${a}/assets`,t);return i}async deleteCampaign(a){const{data:t}=await this.api.delete(`/marketing/campaign/${a}`);return t}async getCommissionStructuresOfOrganization(a,t=!1){const{data:i}=await this.api.get(`/commission/${a}/structure?withDeleted=${t}`);return i}async getCommissionStructure(a){const{data:t}=await this.api.get(`/commission/structure/${a}`);return t}async addCommissionStructureToCampaign(a,t){const{data:i}=await this.api.put(`/commission/structure/${a}/campaign/${t}`);return i}async removeCommissionStructureToCampaign(a,t){const{data:i}=await this.api.delete(`/commission/structure/${a}/campaign/${t}`);return i}async addCommissionStructure(a){const{data:t}=await this.api.post("/commission/structure",a);return t}async deleteCommissionStructure(a){const{data:t}=await this.api.delete(`/commission/structure/${a}`);return t}async updateCommissionStructure(a,t){const{data:i}=await this.api.patch(`/commission/structure/${a}`,t);return i}async getCommissionRule(a){const{data:t}=await this.api.get(`/commission/rule/${a}`);return t}async deleteCommissionRule(a){const{data:t}=await this.api.delete(`/commission/rule/${a}`);return t}async getCommissionRulesOfcommissionStructure(a,t=!1){const{data:i}=await this.api.get(`/commission/structure/${a}/rule?withDeleted=${t}`);return i}async addCommissionRule(a){a.fixedAmount&&(a.fixedAmount=Number(a.fixedAmount)),a.percentage&&(a.percentage=Number(a.percentage)),a.value&&(a.value=Number(a.value));const{data:t}=await this.api.post("/commission/rule",a);return t}async updateCommissionRule(a,t){t.fixedAmount&&(t.fixedAmount=Number(t.fixedAmount)),t.percentage&&(t.percentage=Number(t.percentage)),t.value&&(t.value=Number(t.value));const{data:i}=await this.api.patch(`/commission/rule/${a}`,t);return i}async getAffiliateCommissionsChartData(a,t,i){const e=new URLSearchParams;t&&e.append("startDate",t.toISOString()),i&&e.append("endDate",i.toISOString());const{data:n}=await this.api.get(`/commission/${a}/chart/commissions?${e.toString()}`);return n}async getAffiliateReferralsChartData(a,t,i){const e=new URLSearchParams;t&&e.append("startDate",t.toISOString()),i&&e.append("endDate",i.toISOString());const{data:n}=await this.api.get(`/affiliate/${a}/chart/referrals?${e.toString()}`);return n}async getOrgReferralsChartData(a,t,i){const e=new URLSearchParams;t&&e.append("startDate",t.toISOString()),i&&e.append("endDate",i.toISOString());const{data:n}=await this.api.get(`/affiliate/organization/${a}/chart/referrals?${e.toString()}`);return n}async getAffiliateStats(a){const{data:t}=await this.api.get(`/affiliate/${a}/stats`);return t}async getOrganizationAffiliationStats(a){const{data:t}=await this.api.get(`/affiliate/${a}/organization/stats`);return t}async getOrganizationCommissionStats(a){const{data:t}=await this.api.get(`/commission/organization/${a}/summary`);return t}async getOrganizationGenericStats(a){const{data:t}=await this.api.get(`/organizations/${a}/genericStats`);return t}async getOrganizationPrivateStats(a){const{data:t}=await this.api.get(`/organizations/${a}/privateStats`);return t}async getOrgCommissionsChartData(a,t,i){const e=new URLSearchParams;t&&e.append("startDate",t.toISOString()),i&&e.append("endDate",i.toISOString());const{data:n}=await this.api.get(`/commission/organization/${a}/chart/commissions?${e.toString()}`);return n}async createApiKey(a,t){const{data:i}=await this.api.post(`/organizations/${a}/api-keys`,t);return i}async listApiKeysOfOrganization(a){const{data:t}=await this.api.get(`/organizations/${a}/api-keys`);return t}async listApiKeysOfUserAndOrganizationId(a,t){const{data:i}=await this.api.get(`/organizations/${t}/api-keys/users/${a}`);return i}async revokeApiKey(a,t){const{data:i}=await this.api.delete(`/organizations/${a}/api-keys/${t}`);return i}async getOrganizationSignedUrl(a){const{data:t}=await this.api.get(`/file/organization/${a}`);return t}async getPublicSignedUrl(a){const{data:t}=await this.api.get(`/file/organization/${a}/public`);return t}async getUploadUrlOrganization(a){const{data:t}=await this.api.post("/file/upload/organization",a);return t}async getUploadUrlUser(a){const{data:t}=await this.api.post("/file/upload/user",a);return t}async createCheckoutSession(a){const{data:t}=await this.api.post("/payments/checkout",a);return t}async createBillingSession(a){const{data:t}=await this.api.post("/payments/portal",a);return t}async changeSubscription(a){const{data:t}=await this.api.post("/payments/change-subscription",a);return t}async getPaymentsByOrganization(a){const{data:t}=await this.api.get(`/payments/organization/${a}`);return t}async getPaymentsPendingByOrganization(a){const{data:t}=await this.api.get(`/payments/organization/${a}/pending`);return t}async getAuditLogsByOrganizationId(a,t=1,i=10,e="",n="createdAt",r="DESC",s,o){const c=new URLSearchParams;c.append("page",t.toString()),c.append("take",i.toString()),e&&c.append("searchTerm",e),c.append("orderBy",n),c.append("order",r),s&&c.append("startDate",s.toISOString()),o&&c.append("endDate",o.toISOString());const{data:p}=await this.api.get(`/audit/organization/${a}?${c.toString()}`);return p}async getOrganizationCommissions(a,t=1,i=10,e="",n="createdAt",r="DESC",s){const o=new URLSearchParams({page:t.toString(),take:i.toString(),searchTerm:e,orderBy:n,order:r});s&&o.append("status",s);const{data:c}=await this.api.get(`/commission/organization/${a}/commissions?${o.toString()}`);return c}async getOrganizationCommissionsByAffiliate(a,t=1,i=10,e="",n="createdAt",r="DESC",s){const o=new URLSearchParams({page:t.toString(),take:i.toString(),searchTerm:e,orderBy:n,order:r});s&&o.append("status",s);const{data:c}=await this.api.get(`/commission/organization/${a}/commissions/affiliate?${o.toString()}`);return c}async updateCommissionsStatus(a,t,i){const{data:e}=await this.api.patch(`/commission/organization/${a}/commissions/status`,{commissionIds:t,status:i});return e}async updatePendingCommissionsStatusOfAffiliate(a,t,i){const{data:e}=await this.api.patch(`/commission/affiliation/${a}/commissions/status`,{status:t,currencyId:i});return e}async getOrganizationReferralActions(a,t=1,i=10,e="",n="createdAt",r="DESC",s){const o=new URLSearchParams({page:t.toString(),take:i.toString(),searchTerm:e,orderBy:n,order:r});s&&o.append("isProcessed",`${s}`);const{data:c}=await this.api.get(`/referralaction/organization/${a}?${o.toString()}`);return c}async deleteReferralAction(a){const{data:t}=await this.api.delete(`/referralaction/${a}?`);return t}async createReferralAction(a){const{data:t}=await this.api.post("/tracking/referral-actions",a);return t}async chat(a){const{data:t}=await this.api.post("/ai/chat",a);return t}async getAiHistory(a){const{data:t}=await this.api.get(`/ai/${a}/history`);return t}async clearAiHistory(a){await this.api.delete(`/ai/${a}/history`)}}return a.Ref247AffiliateSDK=l,a.roleToRoleEnum=t=>{switch(t.name){case a.RoleEnum.Admin:return a.RoleEnum.Admin;case a.RoleEnum.Manager:return a.RoleEnum.Manager;case a.RoleEnum.Viewer:return a.RoleEnum.Viewer;case a.RoleEnum.Affiliate:return a.RoleEnum.Affiliate;default:throw new Error(`Invalid role name: ${t.name}`)}},a.validateConditionOperator=t=>Object.values(a.ConditionOperatorEnum).includes(t),a}({},axios);
//# sourceMappingURL=ref247-affiliate-sdk.min.js.map