monime-package 1.1.3 → 1.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +227 -235
- package/dist/index.d.mts +207 -166
- package/dist/index.d.ts +207 -166
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +6 -7
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{randomBytes as sr}from"crypto";import y from"axios";import{z as f}from"zod";var K=f.object({name:f.string().min(1,"Name is required"),amount:f.number().gt(0,"Amount must be greater than zero"),quantity:f.number().int().gt(0,"Quantity must be greater than zero"),successUrl:f.url("Invalid success URL"),cancelUrl:f.url("Invalid cancel URL"),description:f.string().optional(),financialAccountId:f.string().optional(),primaryColor:f.string().optional(),images:f.array(f.string()).optional()});var or=sr(20).toString("hex"),x="https://api.monime.io/v1/checkout-sessions";async function q(r,e,t,o,n,s,c,m,p,l){let R=K.safeParse({name:e,amount:t,quantity:o,successUrl:n,cancelUrl:s,description:c,financialAccountId:m,primaryColor:p,images:l});if(!R.success)return{success:!1,error:new Error(R.error.message)};let{monimeSpaceId:B,accessToken:b,monimeVersion:V}=r,tr={name:e,description:c,cancelUrl:s,successUrl:n,callbackState:null,reference:null,financialAccountId:m,lineItems:[{type:"custom",name:e,price:{currency:"SLE",value:t},quantity:o,reference:null,description:c,images:l}],paymentOptions:{card:{disable:!1},bank:{disable:!1,enabledProviders:["slb001","slb004","slb007"]},momo:{disable:!1,enabledProviders:["m17","m18"]},wallet:{disable:!1,enabledProviders:["dw001"]}},brandingOptions:{primaryColor:p},metadata:{}};try{return{success:!0,data:(await y.post(x,tr,{headers:{"Monime-Space-Id":B,Authorization:`Bearer ${b}`,"Content-Type":"application/json","Idempotency-Key":or,...V?{"Monime-Version":V}:{}}})).data}}catch(U){return y.isAxiosError(U)?{error:U,success:!1}:{error:new Error("unknown error"),success:!1}}}async function N(r){let{accessToken:e,monimeSpaceId:t,monimeVersion:o}=r;try{return{success:!0,data:(await y.get(x,{headers:{"Monime-Space-Id":t,Authorization:`Bearer ${e}`,...o?{"Monime-Version":o}:{}}})).data}}catch(n){return y.isAxiosError(n)?{error:n,success:!1}:{error:new Error("unknown error"),success:!1}}}async function j(r,e){let{accessToken:t,monimeSpaceId:o,monimeVersion:n}=r;try{return{success:!0,data:(await y.get(`${x}/${e}`,{headers:{"Monime-Space-Id":o,Authorization:`Bearer ${t}`,...n?{"Monime-Version":n}:{}}})).data}}catch(s){return y.isAxiosError(s)?{error:s,success:!1}:{error:new Error("unknown error"),success:!1}}}async function H(r,e){let{accessToken:t,monimeSpaceId:o,monimeVersion:n}=r;try{return await y.delete(`${x}/${e}`,{headers:{"Monime-Space-Id":o,Authorization:`Bearer ${t}`,...n?{"Monime-Version":n}:{}}}),{success:!0}}catch(s){return y.isAxiosError(s)?{error:s,success:!1}:{error:new Error("unknown error"),success:!1}}}function Q(r){return{create:(e,t,o,n,s,c,m,p,l)=>q(r,e,t,o,n,s,c,m,p,l),get:()=>N(r),getOne:e=>j(r,e),delete:e=>H(r,e)}}import{randomBytes as ir}from"crypto";import w from"axios";import{z as W}from"zod";var J=W.object({accountName:W.string().min(1,"Account name is required"),currency:W.enum(["USD","SLE"],{message:"Currency must be either USD or SLE"})});var z="https://api.monime.io/v1/financial-accounts",ar=ir(20).toString("hex");async function X(r,e,t){let o=J.safeParse({accountName:r,currency:e});if(!o.success)return{success:!1,error:new Error(o.error.message)};let n={name:r,currency:e,description:"",metadata:{}},{accessToken:s,monimeSpaceId:c,monimeVersion:m}=t;try{return{success:!0,data:(await w.post(z,n,{headers:{"Idempotency-Key":`${ar}`,"Monime-Space-Id":`${c}`,Authorization:`Bearer ${s}`,"Content-Type":"application/json",...m?{"Monime-Version":m}:{}}})).data.result}}catch(p){return w.isAxiosError(p)?{error:p,success:!1}:{error:new Error("unknown error"),success:!1}}}async function Y(r,e){if(r.trim()==="")return{success:!1,error:new Error("financialAccountId is required")};let{monimeSpaceId:t,accessToken:o,monimeVersion:n}=e;try{return{success:!0,data:(await w.get(`${z}/${r}`,{headers:{"Monime-Space-Id":`${t}`,Authorization:`Bearer ${o}`,...n?{"Monime-Version":n}:{}}})).data.result}}catch(s){return w.isAxiosError(s)?{error:s,success:!1}:{error:new Error("unknown error"),success:!1}}}async function Z(r){let{monimeSpaceId:e,accessToken:t,monimeVersion:o}=r;try{return{success:!0,data:(await w.get(z,{headers:{"Monime-Space-Id":`${e}`,Authorization:`Bearer ${t}`,...o?{"Monime-Version":o}:{}}})).data}}catch(n){return w.isAxiosError(n)?{error:n,success:!1}:{error:new Error("unknown error"),success:!1}}}function _(r){return{create:(e,t)=>X(e,t,r),get:e=>Y(e,r),getAll:()=>Z(r)}}import I from"axios";var ee="https://api.monime.io/v1/banks";async function re(r,e){let{monimeSpaceId:t,accessToken:o,monimeVersion:n}=e;try{return{success:!0,data:(await I.get(`${ee}/${r}`,{headers:{"Monime-Space-Id":t,Authorization:`Bearer ${o}`,...n?{"Monime-Version":n}:{}}})).data.result}}catch(s){return I.isAxiosError(s)?{success:!1,error:s}:{success:!1,error:new Error("Unknown error")}}}async function ne(r,e){let{monimeSpaceId:t,accessToken:o,monimeVersion:n}=r;try{return{success:!0,data:(await I.get(ee,{headers:{"Monime-Space-Id":t,Authorization:`Bearer ${o}`,...n?{"Monime-Version":n}:{}},params:e})).data}}catch(s){return I.isAxiosError(s)?{success:!1,error:s}:{success:!1,error:new Error("Unknown error")}}}function te(r){return{get:e=>re(e,r),getAll:e=>ne(r,e)}}import S from"axios";var se="https://api.monime.io/v1/momos";async function oe(r,e){let{monimeSpaceId:t,accessToken:o,monimeVersion:n}=e;try{return{success:!0,data:(await S.get(`${se}/${r}`,{headers:{"Monime-Space-Id":t,Authorization:`Bearer ${o}`,...n?{"Monime-Version":n}:{}}})).data.result}}catch(s){return S.isAxiosError(s)?{success:!1,error:s}:{success:!1,error:new Error("Unknown error")}}}async function ie(r,e){let{monimeSpaceId:t,accessToken:o,monimeVersion:n}=r;try{return{success:!0,data:(await S.get(se,{headers:{"Monime-Space-Id":t,Authorization:`Bearer ${o}`,...n?{"Monime-Version":n}:{}},params:e})).data}}catch(s){return S.isAxiosError(s)?{success:!1,error:s}:{success:!1,error:new Error("Unknown error")}}}function ae(r){return{get:e=>oe(e,r),getAll:e=>ie(r,e)}}import O from"axios";var ce="https://api.monime.io/v1/financial-transactions";async function ue(r){let{monimeSpaceId:e,accessToken:t,monimeVersion:o}=r;try{return{success:!0,data:(await O.get(ce,{headers:{Authorization:`Bearer ${t}`,"Monime-Space-Id":`${e}`,...o?{"Monime-Version":o}:{}}})).data}}catch(n){return O.isAxiosError(n)?{error:n,success:!1}:{error:new Error("unknown error"),success:!1}}}async function me(r,e){let{accessToken:t,monimeSpaceId:o,monimeVersion:n}=r;if(e.trim()==="")return{error:new Error("transactionId must not be empty"),success:!1};try{return{success:!0,data:(await O.get(`${ce}/${e}`,{headers:{Authorization:`Bearer ${t}`,"Monime-Space-Id":`${o}`,...n?{"Monime-Version":n}:{}}})).data.result}}catch(s){return O.isAxiosError(s)?{error:s,success:!1}:{error:new Error("unknown error"),success:!1}}}function pe(r){return{get:e=>me(r,e),getAll:()=>ue(r)}}import{randomBytes as cr}from"crypto";import h from"axios";import{z as v}from"zod";var le=v.object({sourceAccount:v.string().min(1,"Source account is required"),destinationAccount:v.string().min(1,"Destination account is required"),amount:v.number().gt(0,"Amount must be greater than zero")});var G="https://api.monime.io/v1/internal-transfers",ur=cr(20).toString("hex");async function ge(r,e,t,o){let n=le.safeParse({sourceAccount:r,destinationAccount:e,amount:o});if(!n.success)return{success:!1,error:new Error(n.error.message)};let s={amount:{currency:"SLE",value:o},sourceFinancialAccount:{id:r},destinationFinancialAccount:{id:e},metadata:{}},{accessToken:c,monimeSpaceId:m,monimeVersion:p}=t;try{return{success:!0,data:(await h.post(G,s,{headers:{"Idempotency-Key":`${ur}`,"Monime-Space-Id":`${m}`,Authorization:`Bearer ${c}`,"Content-Type":"application/json",...p?{"Monime-Version":p}:{}}})).data.result}}catch(l){return h.isAxiosError(l)?{error:l,success:!1}:{error:new Error("unkknown error"),success:!1}}}async function fe(r){let{monimeSpaceId:e,accessToken:t,monimeVersion:o}=r;try{return{success:!0,data:(await h.get(G,{headers:{"Monime-Space-Id":`${e}`,Authorization:`Bearer ${t}`,...o?{"Monime-Version":o}:{}}})).data}}catch(n){return h.isAxiosError(n)?{success:!1,error:n}:{error:new Error("unkknown error"),success:!1}}}async function de(r,e){let{accessToken:t,monimeSpaceId:o,monimeVersion:n}=r;try{return{success:!0,data:(await h.get(`${G}/${e}`,{headers:{"Monime-Space-Id":`${o}`,Authorization:`Bearer ${t}`,...n?{"Monime-Version":n}:{}}})).data.result}}catch(s){return h.isAxiosError(s)?{success:!1,error:s}:{error:new Error("unkknown error"),success:!1}}}async function ye(r,e){let{monimeSpaceId:t,accessToken:o,monimeVersion:n}=r;try{return await h.delete(`${G}/${e}`,{headers:{"Monime-Space-Id":`${t}`,Authorization:`Bearer ${o}`,...n?{"Monime-Version":n}:{}}}),{success:!0}}catch(s){return h.isAxiosError(s)?{success:!1,error:s}:{success:!1,error:new Error("unknown error")}}}function he(r){return{create:(e,t,o)=>ge(e,t,r,o),get:e=>de(r,e),getAll:()=>fe(r),delete:e=>ye(r,e)}}import{randomBytes as mr}from"crypto";import A from"axios";import{z as D}from"zod";var Ce=D.record(D.string(),D.unknown());var L="https://api.monime.io/v1/payments";async function Pe(r,e){if(!r)return{success:!1,error:new Error("paymentId is required")};let{monimeSpaceId:t,accessToken:o,monimeVersion:n}=e;try{return{success:!0,data:(await A.get(`${L}/${r}`,{headers:{"Monime-Space-Id":t,Authorization:`Bearer ${o}`,...n?{"Monime-Version":n}:{}}})).data.result}}catch(s){return A.isAxiosError(s)?{success:!1,error:s}:{success:!1,error:new Error("Unknown error")}}}async function Re(r,e){let{monimeSpaceId:t,accessToken:o,monimeVersion:n}=r;try{return{success:!0,data:(await A.get(L,{headers:{"Monime-Space-Id":t,Authorization:`Bearer ${o}`,...n?{"Monime-Version":n}:{}},params:e})).data}}catch(s){return A.isAxiosError(s)?{success:!1,error:s}:{success:!1,error:new Error("Unknown error")}}}async function we(r,e,t){if(!r)return{success:!1,error:new Error("paymentId is required")};let o=Ce.safeParse(e);if(!o.success)return{success:!1,error:new Error(o.error.message)};let{monimeSpaceId:n,accessToken:s,monimeVersion:c}=t,m=mr(20).toString("hex");try{return{success:!0,data:(await A.patch(`${L}/${r}`,e,{headers:{"Idempotency-Key":m,"Monime-Space-Id":n,Authorization:`Bearer ${s}`,"Content-Type":"application/json",...c?{"Monime-Version":c}:{}}})).data.result}}catch(p){return A.isAxiosError(p)?{success:!1,error:p}:{success:!1,error:new Error("Unknown error")}}}function Ae(r){return{get:e=>Pe(e,r),getAll:e=>Re(r,e),patch:(e,t)=>we(e,t,r)}}import{randomBytes as pr}from"crypto";import C from"axios";import{z as k}from"zod";var ke=k.object({paymentName:k.string().min(1,"Payment name is required"),amount:k.number().gt(0,"Amount must be greater than zero"),financialAccountId:k.string().optional().nullable(),name:k.string().min(1,"Name is required"),phoneNumber:k.string().min(1,"Phone number is required")});var be=pr(20).toString("hex"),M="https://api.monime.io/v1/payment-codes";async function Te(r,e,t,o,n,s){let c=null;t!==""&&(c=t);let m=ke.safeParse({paymentName:r,amount:e,financialAccountId:t,name:o,phoneNumber:n});if(!m.success)return{success:!1,error:new Error(m.error.message)};let{accessToken:p,monimeSpaceId:l,monimeVersion:R}=s,B={name:`${r}`,mode:"recurrent",enable:!0,amount:{currency:"SLE",value:e*100},duration:"1h30m",customer:{name:`${o}`},reference:"",authorizedPhoneNumber:n,recurrentPaymentTarget:{expectedPaymentCount:1,expectedPaymentTotal:{currency:"SLE",value:e*100}},financialAccountId:c,metadata:{}};try{return{success:!0,data:(await C.post(M,B,{headers:{"Idempotency-Key":`${be}`,"Monime-Space-Id":`${l}`,Authorization:`Bearer ${p}`,"Content-Type":"application/json",...R?{"Monime-Version":R}:{}}})).data.result}}catch(b){return C.isAxiosError(b)?{error:b.response?.data,success:!1}:{error:new Error("unknown error"),success:!1}}}async function xe(r,e){let{accessToken:t,monimeSpaceId:o,monimeVersion:n}=e;if(r.trim()==="")return{success:!1,error:new Error("paymentCodeId is required")};try{return await C.delete(`${M}/${r}`,{headers:{"Idempotency-Key":`${be}`,"Monime-Space-Id":`${o}`,Authorization:`Bearer ${t}`,"Content-Type":"application/json",...n?{"Monime-Version":n}:{}}}),{success:!0}}catch(s){return C.isAxiosError(s)?{error:s,success:!1}:{error:new Error("unknown error"),success:!1}}}async function Ie(r){let{monimeSpaceId:e,accessToken:t,monimeVersion:o}=r;try{return{success:!0,data:(await C.get(M,{headers:{"Monime-Space-Id":`${e}`,Authorization:`Bearer ${t}`,...o?{"Monime-Version":o}:{}}})).data}}catch(n){return C.isAxiosError(n)?{error:n,success:!1}:{error:new Error("unknown error"),success:!1}}}async function Se(r,e){let{monimeSpaceId:t,accessToken:o,monimeVersion:n}=e;try{return{success:!0,data:(await C.get(`${M}/${r}`,{headers:{"Monime-Space-Id":`${t}`,Authorization:`Bearer ${o}`,...n?{"Monime-Version":n}:{}}})).data.result}}catch(s){return C.isAxiosError(s)?{error:s,success:!1}:{error:new Error("unknown error"),success:!1}}}function Oe(r){return{create:(e,t,o,n,s)=>Te(e,t,o,n,s,r),delete:e=>xe(e,r),getAll:()=>Ie(r),get:e=>Se(e,r)}}import{randomBytes as lr}from"crypto";import P from"axios";import{z as g}from"zod";var ve=g.object({amount:g.number().gt(0,"Amount must be greater than 0"),sourceAccount:g.string().min(1,"Source account cannot be empty"),destination:g.discriminatedUnion("type",[g.object({type:g.literal("momo"),providerId:g.enum(["m17","m18"]),phoneNumber:g.string()}),g.object({type:g.literal("bank"),providerId:g.enum(["b01","b02","b03"]),accountNumber:g.string()}),g.object({type:g.literal("wallet"),providerId:g.enum(["w01","w02"]),walletId:g.string()})])});var E="https://api.monime.io/v1/payouts",gr=lr(20).toString("hex");async function Ge(r,e,t,o){let n=ve.safeParse({amount:r,sourceAccount:e,destination:t});if(!n.success)return{success:!1,error:new Error(n.error.message)};let{accessToken:s,monimeSpaceId:c,monimeVersion:m}=o,p={amount:{currency:"SLE",value:r},source:{financialAccountId:e},destination:t,metadata:{}};try{return{success:!0,data:(await P.post(E,p,{headers:{"Idempotency-Key":`${gr}`,"Monime-Space-Id":`${c}`,Authorization:`Bearer ${s}`,"Content-Type":"application/json",...m?{"Monime-Version":m}:{}}})).data.result}}catch(l){return P.isAxiosError(l)?{success:!1,error:l}:{success:!1,error:new Error("unknown error")}}}async function Me(r){let{accessToken:e,monimeSpaceId:t,monimeVersion:o}=r;try{return{success:!0,data:(await P.get(E,{headers:{"Monime-Space-Id":`${t}`,Authorization:`Bearer ${e}`,...o?{"Monime-Version":o}:{}}})).data}}catch(n){return P.isAxiosError(n)?{success:!1,error:n}:{success:!1,error:new Error("unknown error")}}}async function Ee(r,e){let{accessToken:t,monimeSpaceId:o,monimeVersion:n}=e;try{return{success:!0,data:(await P.get(`${E}/${r}`,{headers:{"Monime-Space-Id":`${o}`,Authorization:`Bearer ${t}`,...n?{"Monime-Version":n}:{}}})).data.result}}catch(s){return P.isAxiosError(s)?{success:!1,error:s}:{success:!1,error:new Error("unknown error")}}}async function $e(r,e){let{accessToken:t,monimeSpaceId:o,monimeVersion:n}=e;try{return await P.delete(`${E}/${r}`,{headers:{"Monime-Space-Id":`${o}`,Authorization:`Bearer ${t}`,...n?{"Monime-Version":n}:{}}}),{success:!0}}catch(s){return P.isAxiosError(s)?{success:!1,error:s}:{success:!1,error:new Error("unknown error")}}}function Fe(r){return{create:(e,t,o)=>Ge(e,o,t,r),get:()=>Me(r),getOne:e=>Ee(e,r),delete:e=>$e(e,r)}}import Be from"axios";var fr="https://api.monime.io/v1/provider-kyc";async function Ve(r,e){let{monimeSpaceId:t,accessToken:o,monimeVersion:n}=e;try{return{success:!0,data:(await Be.get(`${fr}/${r}`,{headers:{"Monime-Space-Id":t,Authorization:`Bearer ${o}`,...n?{"Monime-Version":n}:{}}})).data.result}}catch(s){return Be.isAxiosError(s)?{success:!1,error:s}:{success:!1,error:new Error("Unknown error")}}}function Ue(r){return{get:e=>Ve(e,r)}}import{randomBytes as dr}from"crypto";import $ from"axios";var We="https://api.monime.io/v1/receipts";async function ze(r,e){let{monimeSpaceId:t,accessToken:o,monimeVersion:n}=e;try{return{success:!0,data:(await $.get(`${We}/${r}`,{headers:{"Monime-Space-Id":t,Authorization:`Bearer ${o}`,...n?{"Monime-Version":n}:{}}})).data.result}}catch(s){return $.isAxiosError(s)?{success:!1,error:s}:{success:!1,error:new Error("Unknown error")}}}async function De(r,e,t){let{monimeSpaceId:o,accessToken:n,monimeVersion:s}=t,c=dr(20).toString("hex");try{return{success:!0,data:(await $.post(`${We}/${r}/redeem`,e,{headers:{"Idempotency-Key":c,"Monime-Space-Id":o,Authorization:`Bearer ${n}`,"Content-Type":"application/json",...s?{"Monime-Version":s}:{}}})).data.result}}catch(m){return $.isAxiosError(m)?{success:!1,error:m}:{success:!1,error:new Error("Unknown error")}}}function Le(r){return{get:e=>ze(e,r),redeem:(e,t={})=>De(e,t,r)}}import{randomBytes as yr}from"crypto";import Ne from"axios";import{z as Ke}from"zod";var qe=Ke.object({phoneNumber:Ke.string().min(1,"Phone number is required")});var hr="https://api.monime.io/v1/ussd-otps";async function je(r,e){let t=qe.safeParse(r);if(!t.success)return{success:!1,error:new Error(t.error.message)};let{monimeSpaceId:o,accessToken:n,monimeVersion:s}=e,c=yr(20).toString("hex");try{return{success:!0,data:(await Ne.post(hr,r,{headers:{"Idempotency-Key":c,"Monime-Space-Id":o,Authorization:`Bearer ${n}`,"Content-Type":"application/json",...s?{"Monime-Version":s}:{}}})).data.result}}catch(m){return Ne.isAxiosError(m)?{success:!1,error:m}:{success:!1,error:new Error("Unknown error")}}}function He(r){return{create:e=>je(e,r)}}import{randomBytes as Xe}from"crypto";import d from"axios";import{z as u}from"zod";var Qe=u.object({name:u.string().min(1,"Name is required"),url:u.string().url("Invalid URL"),events:u.array(u.string()).min(1,"At least one event is required"),enabled:u.boolean().optional(),apiRelease:u.string().optional(),headers:u.record(u.string(),u.string()).optional(),alertEmails:u.array(u.string().email()).optional(),verificationMethod:u.object({type:u.enum(["HS256","ES256"]),secret:u.string()}).optional(),metadata:u.record(u.string(),u.unknown()).optional()}),Je=u.object({name:u.string().min(1).optional(),url:u.string().url().optional(),events:u.array(u.string()).min(1).optional(),enabled:u.boolean().optional(),headers:u.record(u.string(),u.string()).optional(),alertEmails:u.array(u.email()).optional(),verificationMethod:u.object({type:u.enum(["HS256","ES256"]),secret:u.string()}).optional(),metadata:u.record(u.string(),u.unknown()).optional()});var T="https://api.monime.io/v1/webhooks";async function Ye(r,e){let t=Qe.safeParse(r);if(!t.success)return{success:!1,error:new Error(t.error.message)};let{monimeSpaceId:o,accessToken:n,monimeVersion:s}=e,c=Xe(20).toString("hex");try{return{success:!0,data:(await d.post(T,r,{headers:{"Idempotency-Key":c,"Monime-Space-Id":o,Authorization:`Bearer ${n}`,"Content-Type":"application/json",...s?{"Monime-Version":s}:{}}})).data.result}}catch(m){return d.isAxiosError(m)?{success:!1,error:m}:{success:!1,error:new Error("Unknown error")}}}async function Ze(r,e){let{monimeSpaceId:t,accessToken:o,monimeVersion:n}=e;try{return{success:!0,data:(await d.get(`${T}/${r}`,{headers:{"Monime-Space-Id":t,Authorization:`Bearer ${o}`,...n?{"Monime-Version":n}:{}}})).data.result}}catch(s){return d.isAxiosError(s)?{success:!1,error:s}:{success:!1,error:new Error("Unknown error")}}}async function _e(r){let{monimeSpaceId:e,accessToken:t,monimeVersion:o}=r;try{return{success:!0,data:(await d.get(T,{headers:{"Monime-Space-Id":e,Authorization:`Bearer ${t}`,...o?{"Monime-Version":o}:{}}})).data}}catch(n){return d.isAxiosError(n)?{success:!1,error:n}:{success:!1,error:new Error("Unknown error")}}}async function er(r,e,t){let o=Je.safeParse(e);if(!o.success)return{success:!1,error:new Error(o.error.message)};let{monimeSpaceId:n,accessToken:s,monimeVersion:c}=t,m=Xe(20).toString("hex");try{return{success:!0,data:(await d.patch(`${T}/${r}`,e,{headers:{"Idempotency-Key":m,"Monime-Space-Id":n,Authorization:`Bearer ${s}`,"Content-Type":"application/json",...c?{"Monime-Version":c}:{}}})).data.result}}catch(p){return d.isAxiosError(p)?{success:!1,error:p}:{success:!1,error:new Error("Unknown error")}}}async function rr(r,e){let{monimeSpaceId:t,accessToken:o,monimeVersion:n}=e;try{return await d.delete(`${T}/${r}`,{headers:{"Monime-Space-Id":t,Authorization:`Bearer ${o}`,...n?{"Monime-Version":n}:{}}}),{success:!0}}catch(s){return d.isAxiosError(s)?{success:!1,error:s}:{success:!1,error:new Error("Unknown error")}}}function nr(r){return{create:e=>Ye(e,r),get:e=>Ze(e,r),getAll:()=>_e(r),update:(e,t)=>er(e,t,r),delete:e=>rr(e,r)}}var F=class{monimeSpaceId;accessToken;monimeVersion;financialAccount;internalTransfer;paymentCode;payment;payout;providerKyc;receipt;ussdOtp;webhook;financialTransaction;checkoutSession;financialProvider;constructor(e){this.accessToken=e.accessToken,this.monimeSpaceId=e.monimeSpaceId,this.monimeVersion=e.monimeVersion;let t={monimeSpaceId:this.monimeSpaceId,accessToken:this.accessToken,monimeVersion:this.monimeVersion};this.financialAccount=_(t),this.internalTransfer=he(t),this.paymentCode=Oe(t),this.payment=Ae(t),this.payout=Fe(t),this.providerKyc=Ue(t),this.receipt=Le(t),this.ussdOtp=He(t),this.webhook=nr(t),this.financialTransaction=pe(t),this.checkoutSession=Q(t),this.financialProvider={bank:te(t),momo:ae(t)}}};function Rs(r){return new F(r)}export{F as MonimeClient,Rs as createClient};
|
|
1
|
+
var h=class p extends Error{status;requestId;details;constructor(e,t,s,c){super(e),this.name="MonimeError",t!==void 0&&(this.status=t),s!==void 0&&(this.requestId=s),this.details=c,Error.captureStackTrace&&Error.captureStackTrace(this,p)}},w=class extends h{constructor(e="Invalid or missing access token"){super(e,401),this.name="MonimeAuthenticationError"}},U=class extends h{constructor(e,t){super(e,400,void 0,t),this.name="MonimeValidationError"}};var a=class{baseUrl="https://api.monime.io/v1";config;constructor(e){this.config=e}async getHeaders(e){let t=new Headers({"Content-Type":"application/json",Authorization:`Bearer ${this.config.accessToken}`,"Monime-Space-Id":this.config.monimeSpaceId});return this.config.monimeVersion&&t.set("Monime-Version",this.config.monimeVersion),e&&t.set("Idempotency-Key",e),t}async request(e){let{path:t,method:s,body:c,idempotencyKey:o}=e,d=`${this.baseUrl}${t}`;try{let m=await fetch(d,{method:s,headers:await this.getHeaders(o),body:c?JSON.stringify(c):null}),f=m.headers?.get("x-request-id")||void 0;if(!m.ok){let l=`Request failed with status ${m.status}`,b;try{let P=await m.json();l=P.message||l,b=P}catch{}throw m.status===401?new w(l):new h(l,m.status,f,b)}if(m.status===204)return{success:!0};let y=await m.json();return{success:!0,data:y.result!==void 0?y.result:y}}catch(m){return m instanceof h?{success:!1,error:m}:{success:!1,error:m instanceof Error?m:new Error("Unknown error occurred")}}}};import{z as g}from"zod";var W=g.object({name:g.string().min(1,"Name is required"),amount:g.number().gt(0,"Amount must be greater than zero"),quantity:g.number().int().gt(0,"Quantity must be greater than zero"),successUrl:g.string().url("Invalid success URL"),cancelUrl:g.string().url("Invalid cancel URL"),description:g.string().optional(),financialAccountId:g.string().optional(),primaryColor:g.string().optional(),images:g.array(g.string()).optional()});import{randomBytes as Y}from"crypto";var v=class extends a{path="/checkout-sessions";async create(e,t,s,c,o,d={}){let{description:m,financialAccountId:f,primaryColor:y,images:B}=d,l=W.safeParse({name:e,amount:t,quantity:s,successUrl:c,cancelUrl:o,description:m,financialAccountId:f,primaryColor:y,images:B});if(!l.success)return{success:!1,error:new Error(l.error.message)};let b={name:e,description:m,cancelUrl:o,successUrl:c,callbackState:null,reference:null,financialAccountId:f,lineItems:[{type:"custom",name:e,price:{currency:"SLE",value:t},quantity:s,reference:null,description:m,images:B}],paymentOptions:{card:{disable:!1},bank:{disable:!1,enabledProviders:["slb001","slb004","slb007"]},momo:{disable:!1,enabledProviders:["m17","m18"]},wallet:{disable:!1,enabledProviders:["dw001"]}},brandingOptions:{primaryColor:y},metadata:{}},P=Y(20).toString("hex");return this.request({method:"POST",path:this.path,body:b,idempotencyKey:P})}async list(){return this.request({method:"GET",path:this.path})}async retrieve(e){return this.request({method:"GET",path:`${this.path}/${e}`})}async delete(e){return this.request({method:"DELETE",path:`${this.path}/${e}`})}};import{z as M}from"zod";var N=M.object({accountName:M.string().min(1,"Account name is required"),currency:M.enum(["USD","SLE"],{message:"Currency must be either USD or SLE"})});import{randomBytes as Z}from"crypto";var T=class extends a{path="/financial-accounts";async create(e,t){let s=N.safeParse({accountName:e,currency:t});if(!s.success)return{success:!1,error:new Error(s.error.message)};let c={name:e,currency:t,description:"",metadata:{}},o=Z(20).toString("hex");return this.request({method:"POST",path:this.path,body:c,idempotencyKey:o})}async retrieve(e){return!e||e.trim()===""?{success:!1,error:new Error("financialAccountId is required")}:this.request({method:"GET",path:`${this.path}/${e}`})}async list(){return this.request({method:"GET",path:this.path})}};var x=class extends a{path="/banks";async retrieve(e){return this.request({method:"GET",path:`${this.path}/${e}`})}async list(){return this.request({method:"GET",path:this.path})}};var O=class extends a{path="/momos";async retrieve(e){return this.request({method:"GET",path:`${this.path}/${e}`})}async list(){return this.request({method:"GET",path:this.path})}};var C=class extends a{path="/financial-transactions";async list(){return this.request({method:"GET",path:this.path})}async retrieve(e){return!e||e.trim()===""?{error:new Error("transactionId is required"),success:!1}:this.request({method:"GET",path:`${this.path}/${e}`})}};import{z as k}from"zod";var K=k.object({sourceAccount:k.string().min(1,"Source account is required"),destinationAccount:k.string().min(1,"Destination account is required"),amount:k.number().gt(0,"Amount must be greater than zero")});import{randomBytes as ee}from"crypto";var A=class extends a{path="/internal-transfers";async create(e,t,s){let c=K.safeParse({sourceAccount:e,destinationAccount:t,amount:s});if(!c.success)return{success:!1,error:new Error(c.error.message)};let o={amount:{currency:"SLE",value:s},sourceFinancialAccount:{id:e},destinationFinancialAccount:{id:t},metadata:{}},d=ee(20).toString("hex");return this.request({method:"POST",path:this.path,body:o,idempotencyKey:d})}async list(){return this.request({method:"GET",path:this.path})}async retrieve(e){return this.request({method:"GET",path:`${this.path}/${e}`})}async delete(e){return this.request({method:"DELETE",path:`${this.path}/${e}`})}};import{z as $}from"zod";var H=$.record($.string(),$.unknown());import{randomBytes as te}from"crypto";var I=class extends a{path="/payments";async retrieve(e){return e?this.request({method:"GET",path:`${this.path}/${e}`}):{success:!1,error:new Error("paymentId is required")}}async list(){return this.request({method:"GET",path:this.path})}async update(e,t){if(!e)return{success:!1,error:new Error("paymentId is required")};let s=H.safeParse(t);if(!s.success)return{success:!1,error:new Error(s.error.message)};let c=te(20).toString("hex");return this.request({method:"PATCH",path:`${this.path}/${e}`,body:t,idempotencyKey:c})}};import{z as R}from"zod";var z=R.object({paymentName:R.string().min(1,"Payment name is required"),amount:R.number().gt(0,"Amount must be greater than zero"),financialAccountId:R.string().optional().nullable(),name:R.string().min(1,"Name is required"),phoneNumber:R.string().min(1,"Phone number is required")});import{randomBytes as re}from"crypto";var S=class extends a{path="/payment-codes";async create(e,t,s,c,o){let d=z.safeParse({paymentName:e,amount:t,financialAccountId:s,name:c,phoneNumber:o});if(!d.success)return{success:!1,error:new Error(d.error.message)};let m={name:e,mode:"recurrent",enable:!0,amount:{currency:"SLE",value:t*100},duration:"1h30m",customer:{name:c},reference:"",authorizedPhoneNumber:o,recurrentPaymentTarget:{expectedPaymentCount:1,expectedPaymentTotal:{currency:"SLE",value:t*100}},financialAccountId:s||void 0,metadata:{}},f=re(20).toString("hex");return this.request({method:"POST",path:this.path,body:m,idempotencyKey:f})}async retrieve(e){return this.request({method:"GET",path:`${this.path}/${e}`})}async list(){return this.request({method:"GET",path:this.path})}async delete(e){return!e||e.trim()===""?{success:!1,error:new Error("paymentCodeId is required")}:this.request({method:"DELETE",path:`${this.path}/${e}`})}};import{z as u}from"zod";var V=u.object({amount:u.number().gt(0,"Amount must be greater than 0"),sourceAccount:u.string().min(1,"Source account cannot be empty"),destination:u.discriminatedUnion("type",[u.object({type:u.literal("momo"),providerId:u.enum(["m17","m18"]),phoneNumber:u.string()}),u.object({type:u.literal("bank"),providerId:u.enum(["b01","b02","b03"]),accountNumber:u.string()}),u.object({type:u.literal("wallet"),providerId:u.enum(["w01","w02"]),walletId:u.string()})])});import{randomBytes as ne}from"crypto";var E=class extends a{path="/payouts";async create(e,t,s){let c=V.safeParse({amount:e,sourceAccount:t,destination:s});if(!c.success)return{success:!1,error:new Error(c.error.message)};let o={amount:{currency:"SLE",value:e},source:{financialAccountId:t},destination:s,metadata:{}},d=ne(20).toString("hex");return this.request({method:"POST",path:this.path,body:o,idempotencyKey:d})}async list(){return this.request({method:"GET",path:this.path})}async retrieve(e){return this.request({method:"GET",path:`${this.path}/${e}`})}async delete(e){return this.request({method:"DELETE",path:`${this.path}/${e}`})}};var G=class extends a{path="/provider-kyc";async retrieve(e){return this.request({method:"GET",path:`${this.path}/${e}`})}};import{randomBytes as ie}from"crypto";var F=class extends a{path="/receipts";async retrieve(e){return this.request({method:"GET",path:`${this.path}/${e}`})}async redeem(e,t){let s=ie(20).toString("hex");return this.request({method:"POST",path:`${this.path}/${e}/redeem`,body:t,idempotencyKey:s})}};import{z as j}from"zod";var _=j.object({phoneNumber:j.string().min(1,"Phone number is required")});import{randomBytes as se}from"crypto";var q=class extends a{path="/ussd-otps";async create(e){let t=_.safeParse(e);if(!t.success)return{success:!1,error:new Error(t.error.message)};let s=se(20).toString("hex");return this.request({method:"POST",path:this.path,body:e,idempotencyKey:s})}};import{z as i}from"zod";var J=i.object({name:i.string().min(1,"Name is required"),url:i.string().url("Invalid URL"),events:i.array(i.string()).min(1,"At least one event is required"),enabled:i.boolean().optional(),apiRelease:i.string().optional(),headers:i.record(i.string(),i.string()).optional(),alertEmails:i.array(i.string().email()).optional(),verificationMethod:i.object({type:i.enum(["HS256","ES256"]),secret:i.string()}).optional(),metadata:i.record(i.string(),i.unknown()).optional()}),Q=i.object({name:i.string().min(1).optional(),url:i.string().url().optional(),events:i.array(i.string()).min(1).optional(),enabled:i.boolean().optional(),headers:i.record(i.string(),i.string()).optional(),alertEmails:i.array(i.string().email()).optional(),verificationMethod:i.object({type:i.enum(["HS256","ES256"]),secret:i.string()}).optional(),metadata:i.record(i.string(),i.unknown()).optional()});import{randomBytes as X}from"crypto";var D=class extends a{path="/webhooks";async create(e){let t=J.safeParse(e);if(!t.success)return{success:!1,error:new Error(t.error.message)};let s=X(20).toString("hex");return this.request({method:"POST",path:this.path,body:e,idempotencyKey:s})}async retrieve(e){return this.request({method:"GET",path:`${this.path}/${e}`})}async list(){return this.request({method:"GET",path:this.path})}async update(e,t){let s=Q.safeParse(t);if(!s.success)return{success:!1,error:new Error(s.error.message)};let c=X(20).toString("hex");return this.request({method:"PATCH",path:`${this.path}/${e}`,body:t,idempotencyKey:c})}async delete(e){return this.request({method:"DELETE",path:`${this.path}/${e}`})}};var L=class{financialAccount;internalTransfer;paymentCode;payment;payout;providerKyc;receipt;ussdOtp;webhook;financialTransaction;checkoutSession;financialProvider;constructor(e={}){let t=e.monimeSpaceId||process.env.MONIME_SPACE_ID,s=e.accessToken||process.env.MONIME_ACCESS_TOKEN,c=e.monimeVersion||process.env.MONIME_VERSION;if(!t)throw new Error("monimeSpaceId is required. Pass it in options or set MONIME_SPACE_ID env var.");if(!s)throw new Error("accessToken is required. Pass it in options or set MONIME_ACCESS_TOKEN env var.");let o={monimeSpaceId:t,accessToken:s,monimeVersion:c};this.financialAccount=new T(o),this.internalTransfer=new A(o),this.paymentCode=new S(o),this.payment=new I(o),this.payout=new E(o),this.providerKyc=new G(o),this.receipt=new F(o),this.ussdOtp=new q(o),this.webhook=new D(o),this.financialTransaction=new C(o),this.checkoutSession=new v(o),this.financialProvider={bank:new x(o),momo:new O(o)}}};function Ar(p){return new L(p)}export{w as MonimeAuthenticationError,L as MonimeClient,h as MonimeError,U as MonimeValidationError,Ar as createClient};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "monime-package",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.4",
|
|
4
4
|
"description": "A focused TypeScript helper library for interacting with Monime's common endpoints. It provides small, typed helpers that handle request composition, headers, and basic response/error plumbing so your application code stays clean.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -26,17 +26,16 @@
|
|
|
26
26
|
"packageManager": "pnpm@10.17.1",
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@biomejs/biome": "2.2.5",
|
|
29
|
-
"@types/node": "^
|
|
29
|
+
"@types/node": "^25.2.0",
|
|
30
30
|
"tsup": "^8.5.0",
|
|
31
|
-
"typescript": "^5.
|
|
32
|
-
"vitest": "^3.
|
|
31
|
+
"typescript": "^5.0.0",
|
|
32
|
+
"vitest": "^3.0.0"
|
|
33
33
|
},
|
|
34
34
|
"repository": {
|
|
35
35
|
"type": "git",
|
|
36
36
|
"url": "git+https://github.com/Walon-Foundation/monime-package.git"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"
|
|
40
|
-
"zod": "^4.3.6"
|
|
39
|
+
"zod": "^3.24.0"
|
|
41
40
|
}
|
|
42
|
-
}
|
|
41
|
+
}
|