@qonto/embed-sdk 0.11.0 → 0.12.0

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/dist/index.umd.js CHANGED
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).QontoEmbed={})}(this,(function(e){"use strict";class t{constructor(){this.accessToken=null,this.stagingToken=null}static getInstance(){return t.instance||(t.instance=new t),t.instance}setAccessToken(e){this.accessToken=e}getAccessToken(){return this.accessToken}hasAccessToken(){return null!==this.accessToken&&""!==this.accessToken}clearAccessToken(){this.accessToken=null}setStagingToken(e){this.stagingToken=e}getStagingToken(){return this.stagingToken}hasStagingToken(){return null!==this.stagingToken&&""!==this.stagingToken}clearStagingToken(){this.stagingToken=null}}const n=t.getInstance();class i extends Error{constructor(){super(),this.stack=""}toString(){return`${this.name}: ${this.message}`}}class a extends i{constructor(){super(),this.name="AuthenticationError",this.message="Authentication failed due to missing or invalid access token.\nEnsure you have called the initialize function with a valid access token."}}function s(){if(!n.hasAccessToken())throw new a;return n.getAccessToken()}class r extends i{constructor(e){super(),this.name="InvalidParametersError",this.invalidParameters=Array.isArray(e)?e:[e],this.message=`Invalid parameters were passed to the function:\n${this.invalidParameters.map((e=>e)).join("\n")}`}}class o{constructor(){this.uiParentElementId=null,this.mfaPreference=null,this.debugMode=!1}static getInstance(){return o.instance||(o.instance=new o),o.instance}setSettings(e){e.uiParentElementId&&(this.uiParentElementId=e.uiParentElementId),e.mfaPreference&&(this.mfaPreference=e.mfaPreference),e.debugMode&&(this.debugMode=e.debugMode)}getUIParentElementId(){return this.uiParentElementId}getMFAPreference(){return this.mfaPreference}getDebugMode(){return this.debugMode}clearSettings(){this.uiParentElementId=null,this.mfaPreference=null}}const c=o.getInstance();function d(e){const t=e?.uiParentElementId||c.getUIParentElementId();if(!t)throw new r("operationSettings parameter must have a uiParentElementId for the called function.\nYou can pass it either to the initialize function or in a per function basis.");const n=e?.mfaPreference||c.getMFAPreference();if(n&&!["passkey","paired-device","sms-otp"].includes(n))throw new r("operationSettings.mfaPreference must be one of passkey, paired-device or sms-otp.");const i=e?.debugMode||c.getDebugMode();if(void 0!==i&&"boolean"!=typeof i)throw new r("operationSettings.debugMode must be a boolean.");return{uiParentElementId:t,mfaPreference:n,debugMode:i}}const m={READY:"qonto.ready"},l={CARD_SEE:"card.see",CARD_SEE_DETAILS:"card.see-details",CARD_ORDER:"card.order",CARD_UNLOCK:"card.unlock",CARD_SHOW_PIN:"card.show.pin",CARD_SET_PIN:"card.set.pin",TRANSFERS_CREATE:"transfers.create"},u={PRODUCTION:"production",STAGING:"staging",LOCAL:"local"},p={MASTER:"master",SANDBOX:"sandbox",QA:"qa"},g={EN:"en",FR:"fr",DE:"de",ES:"es",IT:"it",PT:"pt"};var h=Object.freeze({__proto__:null,ACTIONS:l,ACTIVITY_TAGS:{ATM:"atm",FALLBACK:"fallback",FEES:"fees",FINANCE:"finance",FOOD_AND_GROCERY:"food_and_grocery",GAS_STATION:"gas_station",HARDWARE_AND_EQUIPMENT:"hardware_and_equipment",HOTEL_AND_LODGING:"hotel_and_lodging",INSURANCE:"insurance",IT_AND_ELECTRONICS:"it_and_electronics",LEGAL_AND_ACCOUNTING:"legal_and_accounting",LOGISTICS:"logistics",MANUFACTURING:"manufacturing",MARKETING:"marketing",OFFICE_RENTAL:"office_rental",OFFICE_SUPPLY:"office_supply",ONLINE_SERVICE:"online_service",OTHER_EXPENSE:"other_expense",OTHER_INCOME:"other_income",OTHER_SERVICE:"other_service",PENDING:"pending",REFUND:"refund",RESTAURANT_AND_BAR:"restaurant_and_bar",SALES:"sales",SALARY:"salary",SUBSCRIPTION:"subscription",TAX:"tax",TRANSPORT:"transport",TREASURY_AND_INTERCO:"treasury_and_interco",UTILITY:"utility",VOUCHER:"voucher"},BENEFICIARY_STATUSES:{PENDING:"pending",VALIDATED:"validated",DECLINED:"declined"},BRANCHES:p,ENVIRONMENTS:u,IFRAME_EVENTS:m,LOCALES:g,SEPA_TRANSFER_DECLINE_REASONS:{BENEFICIARY_BIC_INVALID:"beneficiary_bic_invalid",BENEFICIARY_IBAN_INVALID:"beneficiary_iban_invalid",BENEFICIARY_STATUS:"beneficiary_status",BENEFICIARY_NETWORK_RULES_ERROR:"beneficiary_network_rules_error",ORGANISATION_COMPLIANCE_REASONS:"organisation_compliance_reasons",DEBIT_ACCOUNT_INSUFFICIENT_FUNDS:"debit_account_insufficient_funds",QONTO_PROCESSING_FAILED:"qonto_processing_failed"},SEPA_TRANSFER_STATUSES:{PENDING:"pending",PROCESSING:"processing",CANCELED:"canceled",DECLINED:"declined",SETTLED:"settled"}});const f=Object.values(g);function _(e){if(!function(e){return f.includes(e)}(e))throw new r(`Unsupported locale: ${e}. The locale must be one of: ${f.join(", ")}.`);return e}function y(e){if(!e?.accessToken)throw new r("Access token is required when calling initialize()");return e?.operationSettings&&d(e.operationSettings),function(e){if(e.environment){if(!["production","staging","local"].includes(e.environment))throw new r('If provided, environment must be either "production" or "staging"\nYou can "import constants from @qonto/embed-sdk/common" and then use "constants.environment.PRODUCTION" or "constants.environment.STAGING"');if(e.branch&&!["master","sandbox","qa"].includes(e.branch))throw new r('If provided, branch must be either "master", "sandbox" or "qa"\nYou can "import constants from @qonto/embed-sdk/common" and then use "constants.branch.MASTER" or "constants.environment.SANDBOX" and so on')}}(e),e.locale&&_(e.locale),e}const T="https://embed.qonto.com",I="https://embed-js{branch}.staging.qonto.co",E="https://embed.dev.qonto.co",A={[u.PRODUCTION]:{IFRAME_BASE_URL:T,IFRAME_URL:`${T}/connect`,THIRD_PARTY_API_URL:"https://thirdparty.qonto.com"},[u.STAGING]:{IFRAME_BASE_URL:I,IFRAME_URL:`${I}/connect`,THIRD_PARTY_API_URL:"https://thirdparty{branch}.staging.qonto.co"},[u.LOCAL]:{IFRAME_BASE_URL:E,IFRAME_URL:`${E}/connect`,THIRD_PARTY_API_URL:"https://thirdparty{branch}.staging.qonto.co"}};class w{constructor(){this.environment=u.PRODUCTION,this.branch=p.SANDBOX;const e=process.env.QONTO_EMBED_ENVIRONMENT,t=process.env.QONTO_EMBED_BRANCH;this.environment=Object.values(u).includes(e)?e:u.PRODUCTION,this.branch=Object.values(p).includes(t)?t:p.SANDBOX}static getInstance(){return w.instance||(w.instance=new w),w.instance}setEnvironment(e){this.environment=e}getEnvironment(){return this.environment}setBranch(e){this.branch=e}getBranch(){return this.branch}clear(){this.environment=u.PRODUCTION,this.branch=p.MASTER}getEnvironmentUrls(){if(this.environment===u.PRODUCTION)return A.production;{const e=A[this.environment];return Object.entries(e).reduce(((e,[t,n])=>({...e,[t]:n.replace("{branch}",`-${this.branch}`)})),{})}}}const b=w.getInstance();class L{constructor(){this.currentLocale="en"}static getInstance(){return L.instance||(L.instance=new L),L.instance}setLocale(e){this.currentLocale=e}getLocale(){return this.currentLocale}setDefaultLocale(){this.currentLocale="en"}}const R=L.getInstance();const D={initialize:function(e){const{accessToken:t,stagingToken:i,operationSettings:a,environment:s,branch:r,locale:o}=y(e);n.setAccessToken(t),i&&n.setStagingToken(i),o&&R.setLocale(o),a&&c.setSettings(a),s&&(b.setEnvironment(s),r&&b.setBranch(r))},logout:function(){n.clearAccessToken(),n.clearStagingToken(),R.setDefaultLocale()},constants:h},{initialize:S,logout:v,constants:k}=D;class P extends i{constructor(e){super();const t=Array.isArray(e)?e.join("\n"):e;this.name="EmbedApiError",this.message=`The call to the Embed API failed with the following errors:\n${t}`}}function O({accessToken:e,stagingToken:t,idempotencyKey:i}){const a=new Headers;a.append("Authorization",`Bearer ${e}`);const s=t||n.getStagingToken();return s&&a.append("X-Qonto-Staging-Token",s),i&&a.append("X-Qonto-Idempotency-Key",i),a.append("Content-Type","application/json"),a.append("Accept-Language",R.getLocale()),a}async function N(e,t,n){const i={method:"GET",headers:O({accessToken:t,stagingToken:n})},a=b.getEnvironmentUrls().THIRD_PARTY_API_URL,s=await fetch(`${a}/v2/cards/${e.cardId}/data_view`,i),r=await s.json();if(r.errors)throw new P(r.errors.map((e=>`${e.code}: ${e.detail}`)));return function(e,t){const n=new URL(e);return"boolean"==typeof t.allowPinReveal&&n.searchParams.set("canSeePin",t.allowPinReveal?"true":"false"),"boolean"==typeof t.allowBlocking&&n.searchParams.set("canBlock",t.allowBlocking?"true":"false"),n.toString()}(r.iframe_url,e)}var U;!function(e){e.PENDING="pending",e.ONHOLD="onhold",e.ORDER_CANCELED="order_canceled",e.LIVE="live",e.PAUSED="paused",e.STOLEN="stolen",e.LOST="lost",e.PIN_BLOCKED="pin_blocked",e.DELETED="deleted",e.PRE_EXPIRED="pre_expired",e.EXPIRED="expired",e.DISCARDED="discarded",e.SHIPPED_LOST="shipped_lost",e.ABUSIVE="abusive"}(U||(U={}));const C={TRANSPORT:"transport",RESTAURANT_AND_BAR:"restaurant_and_bar",FOOD_AND_GROCERY:"food_and_grocery",IT_AND_ELECTRONICS:"it_and_electronics",UTILITY:"utility",TAX:"tax",LEGAL_AND_ACCOUNTING:"legal_and_accounting",ATM:"atm",OFFICE_SUPPLY:"office_supply",HARDWARE_AND_EQUIPMENT:"hardware_and_equipment",FINANCE:"finance"};var M,$;function B(e,t){const n=t.filter((t=>t.requiredIfPresent?!e[t.name]&&e[t.requiredIfPresent]:void 0===e[t.name])).map((e=>e.name));if(n.length>0)throw new r(n.map((e=>`Missing required parameter: ${e}`)))}function F(e){return Object.entries(e).filter((([,e])=>void 0!==e)).filter((([,e])=>"string"!=typeof e)).map((([e])=>`${e} must be a string`))}function j(e){return Object.entries(e).filter((([,e])=>void 0!==e&&!1!==e&&!0!==e)).map((([e])=>`${e} must be a boolean`))}function G(e){return Object.entries(e).filter((([,e])=>void 0!==e)).filter((([,e])=>"number"!=typeof e)).map((([e])=>`${e} must be a number`))}!function(e){e.VIRTUAL="virtual"}(M||(M={})),function(e){e.METAL="metal",e.PLUS="plus",e.STANDARD="standard"}($||($={}));const Y=[{name:"organizationId"},{name:"membershipId"},{name:"bankAccountId"},{name:"monthlyLimit"},{name:"cardLevel"}],q=[...Y,{name:"atmDailyLimit",requiredIfPresent:"hasAtmDailyLimit"},{name:"hasAtmDailyLimit",requiredIfPresent:"hasAtmOption"},{name:"atmMonthlyLimit",requiredIfPresent:"hasAtmOption"},{name:"shipToBusiness"},{name:"cardLevel"}];function x(e){if(!e)throw new r("cardSettings parameter is required for the called function");return"virtual"===e.cardLevel?function(e){return B(e,Y),function(e){const{membershipId:t,organizationId:n,bankAccountId:i,hasDailyLimit:a,hasTransactionLimit:s,monthlyLimit:o,dailyLimit:c,transactionLimit:d,activeDays:m,categories:l,cardLevel:u}=e,p=function(e){return"virtual"!==e?['cardLevel must be "virtual"']:[]}(u),g=F({membershipId:t,organizationId:n,bankAccountId:i}),h=j({hasDailyLimit:a,hasTransactionLimit:s}),f=G({monthlyLimit:o,dailyLimit:c,transactionLimit:d}),_=z(m),y=H(l),T=[...p,...g,...h,...f,..._,...y];if(T.length>0)throw new r(T)}(e),e}(e):function(e){B(e,q),function(e){const{membershipId:t,organizationId:n,bankAccountId:i,hasDailyLimit:a,hasTransactionLimit:s,monthlyLimit:o,dailyLimit:c,transactionLimit:d,activeDays:m,categories:l,cardLevel:u,hasNfcOption:p,hasForeignPaymentOption:g,hasOnlinePaymentOption:h,shipToBusiness:f,hasAtmOption:_,hasAtmDailyLimit:y,atmDailyLimit:T,atmMonthlyLimit:I,address:E,cardDesign:A,typeOfPrint:w}=e,b=function(e){return Object.values($).includes(e)?[]:['cardLevel must be one of "standard", "plus", "metal"']}(u),L=function(e){const t=null!=e&&"string"!=typeof e,n=!["print","embossed",void 0,null].includes(e);return t||n?['typeOfPrint must be one of "print", "embossed" or null']:[]}(w),R=F({membershipId:t,organizationId:n,bankAccountId:i}),D=j({hasDailyLimit:a,hasTransactionLimit:s,hasAtmOption:_,hasNfcOption:p,hasForeignPaymentOption:g,hasOnlinePaymentOption:h,hasAtmDailyLimit:y,shipToBusiness:f}),S=G({monthlyLimit:o,dailyLimit:c,transactionLimit:d,atmDailyLimit:T,atmMonthlyLimit:I}),v=z(m),k=H(l),P=function(e){return["undefined","string"].includes(typeof e)?[]:["cardDesign must be a string"]}(A),O=function(e,t){if(t)return[];return!e||e.contactName&&e.firstLine&&e.zipCode&&e.city&&e.country?[]:["address must contain at least contactName, firstLine, zipCode, city and country properties"]}(E,f),N=[...b,...R,...D,...S,...v,...k,...L,...P,...O];if(N.length>0)throw new r(N)}(e)}(e)}function z(e){const t=!Array.isArray(e)||!e.every((e=>Number.isInteger(e)&&e>0&&e<8));return void 0!==e&&t?["activeDays must be an array of integers between 1 and 7"]:[]}function H(e){const t=!Array.isArray(e)||e.some((e=>"string"!=typeof e));return void 0!==e&&t?["categories must be an array of strings"]:[]}class V extends i{constructor(e){super(),this.name="EmbedOperationError",this.message=e}}class K{constructor(e){this.options=e,this.iframe=null,this.parentElement=null,this.messageListeners=new Map,this.defaultTimeout=3e4;const t=new URL(e.iframeUrl);this.targetOrigin=`${t.protocol}//${t.host}`}async initialize(){if(this.iframe)return this;if(this.parentElement=document.getElementById(this.options.parentElementId),!this.parentElement)throw new V(`Could not install the authentication UI because the parent element with id ${this.options.parentElementId} was not found.\nPlease make sure to pass a valid parentElementId when calling the method.`);return new Promise(((e,t)=>{this.iframe=document.createElement("iframe"),this.iframe.src=this.options.iframeUrl,this.iframe.style.width="100%",this.iframe.style.height="100%",this.iframe.style.border="none";const n=this.options.timeout||this.defaultTimeout,i=setTimeout((()=>{window.removeEventListener("message",a),t(new V(`Could not install the authentication UI because the timeout of ${n}ms was reached.\nPlease make sure the application can reach the Internet.`))}),n),a=t=>{t.data.eventId===m.READY&&(clearTimeout(i),window.removeEventListener("message",a),e(this))};window.addEventListener("message",a),this.parentElement?.appendChild(this.iframe)}))}postMessage(e){return this.iframe&&this.iframe.contentWindow?new Promise(((t,n)=>{const i=a=>{if(a.data?.actionId===e.actionId){if("error"===a.data.status)return this.removeMessageListener(e.actionId,i),n(new V(`An error occurred when performing the action ${e.actionId}.\n${JSON.stringify(a.data.payload)}`));this.removeMessageListener(e.actionId,i),t(a.data.payload)}};this.addMessageListener(e.actionId,i),this.iframe?.contentWindow?.postMessage(e,this.targetOrigin)})):Promise.reject(new V("Attempted to perform an Embed operation without having the authentication UI initialized."))}addMessageListener(e,t){this.messageListeners.has(e)||this.messageListeners.set(e,[]);this.messageListeners.get(e).push(t),window.addEventListener("message",t)}removeMessageListener(e,t){const n=this.messageListeners.get(e);if(n){const e=n.indexOf(t);-1!==e&&(n.splice(e,1),window.removeEventListener("message",t))}}destroy(){this.messageListeners.forEach((e=>{e.forEach((e=>{window.removeEventListener("message",e)}))})),this.messageListeners.clear(),this.iframe&&this.parentElement&&(this.parentElement.removeChild(this.iframe),this.iframe=null)}}function X({accessToken:e,stagingToken:t,locale:n,debugMode:i}){const a=i||!1,s=n||R.getLocale(),r=b.getEnvironmentUrls().IFRAME_URL,o=t?`&staging_token=${encodeURIComponent(t)}`:"";return`${r}?debug=${a}&lang=${encodeURIComponent(s)}#access_token=${encodeURIComponent(e)}${o}`}function Q({parentElementId:e,iframeUrl:t}){return new K({parentElementId:e,iframeUrl:t}).initialize()}const W=[];for(let e=0;e<256;++e)W.push((e+256).toString(16).slice(1));let J;const Z=new Uint8Array(16);var ee={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function te(e,t,n){if(ee.randomUUID&&!e)return ee.randomUUID();const i=(e=e||{}).random??e.rng?.()??function(){if(!J){if("undefined"==typeof crypto||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");J=crypto.getRandomValues.bind(crypto)}return J(Z)}();if(i.length<16)throw new Error("Random bytes length must be >= 16");return i[6]=15&i[6]|64,i[8]=63&i[8]|128,function(e,t=0){return(W[e[t+0]]+W[e[t+1]]+W[e[t+2]]+W[e[t+3]]+"-"+W[e[t+4]]+W[e[t+5]]+"-"+W[e[t+6]]+W[e[t+7]]+"-"+W[e[t+8]]+W[e[t+9]]+"-"+W[e[t+10]]+W[e[t+11]]+W[e[t+12]]+W[e[t+13]]+W[e[t+14]]+W[e[t+15]]).toLowerCase()}(i)}function ne(e){return"virtual"===e.cardLevel?function(e){const t=ae(e.categories);return{actionId:l.CARD_ORDER,actionData:{idempotencyKey:te(),body:{card:{payment_monthly_limit:e.monthlyLimit,payment_daily_limit:e.dailyLimit,payment_daily_limit_option:e.hasDailyLimit,payment_transaction_limit:e.transactionLimit,payment_transaction_limit_option:e.hasTransactionLimit,active_days:e.activeDays||[],holder_id:e.membershipId,organization_id:e.organizationId,bank_account_id:e.bankAccountId,categories:t,card_level:e.cardLevel}}}}}(e):function(e){const t=ae(e.categories);return{actionId:l.CARD_ORDER,actionData:{idempotencyKey:te(),body:{card:{payment_monthly_limit:e.monthlyLimit,payment_daily_limit:e.dailyLimit,payment_daily_limit_option:e.hasDailyLimit,payment_transaction_limit:e.transactionLimit,payment_transaction_limit_option:e.hasTransactionLimit,active_days:e.activeDays||[],holder_id:e.membershipId,organization_id:e.organizationId,bank_account_id:e.bankAccountId,categories:t,card_level:e.cardLevel,card_design:e.cardDesign,..."plus"===e.cardLevel&&{type_of_print:e.typeOfPrint},ship_to_business_address:e.shipToBusiness,atm_option:e.hasAtmOption,nfc_option:e.hasNfcOption,foreign_option:e.hasForeignPaymentOption,online_option:e.hasOnlinePaymentOption,atm_daily_limit:e.atmDailyLimit,atm_monthly_limit:e.atmMonthlyLimit,...!e.shipToBusiness&&{address:{contact_name:e.address?.contactName,first_line:e.address?.firstLine,second_line:e.address?.secondLine,third_line:e.address?.thirdLine,zipcode:e.address?.zipCode,city:e.address?.city,country:e.address?.country}}}}}}}(e)}function ie(e){return{id:e.id,nickname:e.nickname,embossedName:e.embossed_name,status:e.status,maskPan:e.mask_pan,expMonth:parseInt(e.exp_month,10),expYear:parseInt(e.exp_year,10),lastActivityAt:new Date(e.last_activity_at),lastDigits:e.last_digits,shipToBusiness:e.ship_to_business,atmOption:e.atm_option,atmDailyLimitOption:e.atm_daily_limit_option,nfcOption:e.nfc_option,onlineOption:e.online_option,foreignOption:e.foreign_option,atmMonthlyLimit:e.atm_monthly_limit,atmMonthlySpent:e.atm_monthly_spent,atmDailyLimit:e.atm_daily_limit,atmDailySpent:e.atm_daily_spent,paymentMonthlyLimit:e.payment_monthly_limit,paymentMonthlySpent:e.payment_monthly_spent,paymentDailyLimit:e.payment_daily_limit,paymentDailySpent:e.payment_daily_spent,paymentDailyLimitOption:e.payment_daily_limit_option,paymentTransactionLimit:e.payment_transaction_limit,paymentTransactionLimitOption:e.payment_transaction_limit_option,activeDays:e.active_days,holderId:e.holder_id,bankAccountId:e.bank_account_id,organizationId:e.organization_id,updatedAt:new Date(e.updated_at),createdAt:new Date(e.created_at),shippedAt:new Date(e.shipped_at),cardType:e.card_type,cardLevel:e.card_level,paymentLifespanLimit:e.payment_lifespan_limit,paymentLifespanSpent:e.payment_lifespan_spent,preExpiresAt:new Date(e.pre_expires_at),categories:e.categories,renewed:e.renewed,renewal:e.renewal,...e.parent_card_summary&&{parentCardSummary:{id:e.parent_card_summary.id,lastDigits:e.parent_card_summary.last_digits}},hadOperation:e.had_operation,hadPinOperation:e.had_pin_operation,cardDesign:e.card_design,typeOfPrint:e.type_of_print,upsold:e.upsold,upsell:e.upsell,discardOn:new Date(e.discard_on),reordered:e.reordered}}function ae(e){const t=Object.values(C);return(e||[]).filter((e=>t.includes(e)))}const se={getCards:async function({membershipId:e,accessToken:t,stagingToken:n}){try{const i=t||s();if(e&&"string"!=typeof e)throw new r("membershipId must be a string");const a=await async function({membershipId:e,accessToken:t,stagingToken:n}){const i={method:"GET",headers:O({accessToken:t,stagingToken:n})},a=b.getEnvironmentUrls().THIRD_PARTY_API_URL,s=e?`${a}/v2/cards?holder_ids[]=${e}`:`${a}/v2/cards`,r=await fetch(s,i),o=await r.json();if(o.errors)throw new P(o.errors.map((e=>`${e.code}: ${e.detail}`)));return o.cards}({membershipId:e,accessToken:i,stagingToken:n});return a.map((e=>ie(e)))}catch(e){return Promise.reject(e)}},getCard:async function({cardId:e,accessToken:t,stagingToken:n}){try{const i=t||s();if(e&&"string"!=typeof e)throw new r("cardId must be a string");const a=await async function({cardId:e,accessToken:t,stagingToken:n}){const i={method:"GET",headers:O({accessToken:t,stagingToken:n})},a=`${b.getEnvironmentUrls().THIRD_PARTY_API_URL}/v2/cards?ids[]=${e}`,s=await fetch(a,i),r=await s.json();if(r.errors)throw new P(r.errors.map((e=>`${e.code}: ${e.detail}`)));return r.cards[0]}({cardId:e,accessToken:i,stagingToken:n});return ie(a)}catch(e){return Promise.reject(e)}},orderCard:async function(e){try{const t=s(),{uiParentElementId:i,debugMode:a}=d(e.operationSettings);x(e.cardSettings);const r=X({accessToken:t,stagingToken:n.getStagingToken()||void 0,debugMode:a}),o=await Q({iframeUrl:r,parentElementId:i}),c=ne(e.cardSettings),m=await o.postMessage(c);return o.destroy(),ie(m)}catch(e){return Promise.reject(e)}},unlockCard:async function(e){try{const t=s(),{uiParentElementId:i,debugMode:a}=d(e.operationSettings);!function(e){if(!e)throw new r("cardSettings parameter is required for the called function");if(!e.cardId)throw new r("cardId is required for the called function");const t=F({cardId:e.cardId});if(t.length>0)throw new r(t)}(e.cardSettings);const o=X({accessToken:t,stagingToken:n.getStagingToken()||void 0,debugMode:a}),c=await Q({iframeUrl:o,parentElementId:i}),m=function(e){return{actionId:l.CARD_UNLOCK,actionData:{cardId:e.cardSettings.cardId}}}(e),u=await c.postMessage(m);return c.destroy(),ie(u)}catch(e){return Promise.reject(e)}},displayCard:async function(e){try{const t=s(),{uiParentElementId:n}=d(e.operationSettings);!function(e){if(!e)throw new r("cardSettings parameter is required for the called function");if(!e.cardId)throw new r("cardId is required for the called function");const t=F({cardId:e.cardId});if(t.length>0)throw new r(t);let n={};void 0!==e.allowPinReveal&&(n={allowPinReveal:e.allowPinReveal}),void 0!==e.allowBlocking&&(n={...n,allowBlocking:e.allowBlocking});const i=j(n);if(i.length>0)throw new r(i)}(e.cardSettings);const i=await N(e.cardSettings,t),a=await Q({iframeUrl:i,parentElementId:n});return{destroyEmbedUI:()=>{a.destroy()}}}catch(e){return Promise.reject(e)}}},re=se;function oe({endpointUrl:e,paginationSettings:t}){const n=new URL(e);return t?.page&&n.searchParams.set("page",t.page.toString()),t?.itemsPerPage&&n.searchParams.set("per_page",t.itemsPerPage.toString()),n}function ce(e){if(e)return{totalItems:e?.total_count,totalPages:e?.total_pages,currentPage:e?.current_page,itemsPerPage:e?.per_page,previousPage:e?.prev_page||null,nextPage:e?.next_page||null}}function de(e){return{id:e.id,name:e.name,email:e.email,activityTag:e.activity_tag,iban:e.iban,bic:e.bic,currency:e.currency,status:e.status,trusted:e.trusted,createdAt:new Date(e.created_at),updatedAt:new Date(e.updated_at)}}function me(e){return{name:e.name,...e.email&&{email:e.email},...e.activityTag&&{activity_tag:e.activityTag},iban:e.iban,...e.bic&&{bic:e.bic}}}const le="/v2/sepa/beneficiaries";const ue=[{name:"name"},{name:"iban"}];const pe={getBeneficiaries:async function(e){const t=e?.accessToken||s(),n=await async function({paginationSettings:e,accessToken:t,stagingToken:n}){const i={method:"GET",headers:O({accessToken:t,stagingToken:n})},a=oe({endpointUrl:new URL(b.getEnvironmentUrls().THIRD_PARTY_API_URL+le),paginationSettings:e}),s=await fetch(a,i),r=await s.json();if(r.errors)throw new P(r.errors.map((e=>`${e.code}: ${e.detail}`)));return{beneficiaries:r.beneficiaries,meta:r.meta}}({accessToken:t,stagingToken:e?.stagingToken,paginationSettings:e?.paginationSettings}),i=n.beneficiaries.map((e=>de(e))),a=ce(n.meta);return{beneficiaries:i,...a?{meta:a}:{}}},getBeneficiary:async function({beneficiaryId:e,accessToken:t,stagingToken:n}){const i=t||s();!function(e){if(!e)throw new r("beneficiaryId parameter is required for the called function");if(e&&"string"!=typeof e)throw new r("beneficiaryId must be a string")}(e);return de(await async function({accessToken:e,stagingToken:t,beneficiaryId:n}){const i={method:"GET",headers:O({accessToken:e,stagingToken:t})},a=`${b.getEnvironmentUrls().THIRD_PARTY_API_URL}${le}/${n}`,s=await fetch(a,i),r=await s.json();if(r.errors)throw new P(r.errors.map((e=>`${e.code}: ${e.detail}`)));return r.beneficiary}({beneficiaryId:e,accessToken:i,stagingToken:n}))},addBeneficiary:async function({beneficiary:e,accessToken:t,stagingToken:n}){const i=t||s();!function(e){if(!e)throw new r("beneficiary parameter is required for the called function");if("object"!=typeof e)throw new r("beneficiary must be an object");B(e,ue);const t=F({name:e.name,iban:e.iban,email:e.email,activityTag:e.activityTag,bic:e.bic});if(t.length>0)throw new r(t)}(e);return de(await async function({beneficiary:e,accessToken:t,stagingToken:n}){const i={method:"POST",headers:O({accessToken:t,stagingToken:n,idempotencyKey:te()}),body:JSON.stringify({beneficiary:me(e)})},a=`${b.getEnvironmentUrls().THIRD_PARTY_API_URL}${le}`,s=await fetch(a,i),r=await s.json();if(r.errors)throw new P(r.errors.map((e=>`${e.code}: ${e.detail}`)));return r.beneficiary}({beneficiary:e,accessToken:i,stagingToken:n}))}},ge="/v2/sepa/transfers";function he(e){return{id:e.id,initiatorId:e.initiator_id,bankAccountId:e.bank_account_id,amount:Number(e.amount),amountCents:Number(e.amount_cents),amountCurrency:e.amount_currency,status:e.status,beneficiaryId:e.beneficiary_id,reference:e.reference,note:e.note,declinedReason:e.declined_reason,scheduledDate:new Date(e.scheduled_date),createdAt:new Date(e.created_at),updatedAt:new Date(e.updated_at),processedAt:new Date(e.processed_at),completedAt:new Date(e.completed_at),transactionId:e.transaction_id}}const fe={getSepaTransfers:async function(e={}){const t=e?.accessToken||s(),n=await async function({accessToken:e,stagingToken:t,paginationSettings:n}){const i={method:"GET",headers:O({accessToken:e,stagingToken:t})},a=oe({endpointUrl:new URL(b.getEnvironmentUrls().THIRD_PARTY_API_URL+ge),paginationSettings:n}),s=await fetch(a,i);if(!s.ok)throw new P("Failed to fetch SEPA transfers");const r=await s.json();if(r.errors)throw new P(r.errors.map((e=>`${e.code}: ${e.detail}`)));return{transfers:r.transfers,meta:r.meta}}({accessToken:t,stagingToken:e?.stagingToken,paginationSettings:e?.paginationSettings}),i=n.transfers.map((e=>he(e))),a=ce(n.meta);return{transfers:i,...a?{meta:a}:{}}},getSepaTransfer:async function({sepaTransferId:e,accessToken:t,stagingToken:n}){const i=t||s();!function(e){if(!e)throw new r("sepaTransferId parameter is required for the called function");if(e&&"string"!=typeof e)throw new r("sepaTransferId must be a string")}(e);return he(await async function({accessToken:e,stagingToken:t,sepaTransferId:n}){const i={method:"GET",headers:O({accessToken:e,stagingToken:t})},a=`${b.getEnvironmentUrls().THIRD_PARTY_API_URL}${ge}/${n}`,s=await fetch(a,i),r=await s.json();if(r.errors)throw new P(r.errors.map((e=>`${e.code}: ${e.detail}`)));return r.external_transfer}({sepaTransferId:e,accessToken:i,stagingToken:n}))}};e.beneficiaries=pe,e.cards=re,e.constants=k,e.initialize=S,e.logout=v,e.sepaTransfers=fe}));
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).QontoEmbed={})}(this,(function(e){"use strict";class t{constructor(){this.accessToken=null,this.stagingToken=null}static getInstance(){return t.instance||(t.instance=new t),t.instance}setAccessToken(e){this.accessToken=e}getAccessToken(){return this.accessToken}hasAccessToken(){return null!==this.accessToken&&""!==this.accessToken}clearAccessToken(){this.accessToken=null}setStagingToken(e){this.stagingToken=e}getStagingToken(){return this.stagingToken}hasStagingToken(){return null!==this.stagingToken&&""!==this.stagingToken}clearStagingToken(){this.stagingToken=null}}const n=t.getInstance();class a extends Error{constructor(){super(),this.stack=""}toString(){return`${this.name}: ${this.message}`}}class i extends a{constructor(){super(),this.name="AuthenticationError",this.message="Authentication failed due to missing or invalid access token.\nEnsure you have called the initialize function with a valid access token."}}function r(){if(!n.hasAccessToken())throw new i;return n.getAccessToken()}class s extends a{constructor(e){super(),this.name="InvalidParametersError",this.invalidParameters=Array.isArray(e)?e:[e],this.message=`Invalid parameters were passed to the function:\n${this.invalidParameters.map((e=>e)).join("\n")}`}}class o{constructor(){this.uiParentElementId=null,this.mfaPreference=null,this.debugMode=!1}static getInstance(){return o.instance||(o.instance=new o),o.instance}setSettings(e){e.uiParentElementId&&(this.uiParentElementId=e.uiParentElementId),e.mfaPreference&&(this.mfaPreference=e.mfaPreference),e.debugMode&&(this.debugMode=e.debugMode)}getUIParentElementId(){return this.uiParentElementId}getMFAPreference(){return this.mfaPreference}getDebugMode(){return this.debugMode}clearSettings(){this.uiParentElementId=null,this.mfaPreference=null}}const c=o.getInstance();function d(e){const t=e?.uiParentElementId||c.getUIParentElementId();if(!t)throw new s("operationSettings parameter must have a uiParentElementId for the called function.\nYou can pass it either to the initialize function or in a per function basis.");const n=e?.mfaPreference||c.getMFAPreference();if(n&&!["passkey","paired-device","sms-otp"].includes(n))throw new s("operationSettings.mfaPreference must be one of passkey, paired-device or sms-otp.");const a=e?.debugMode||c.getDebugMode();if(void 0!==a&&"boolean"!=typeof a)throw new s("operationSettings.debugMode must be a boolean.");return{uiParentElementId:t,mfaPreference:n,debugMode:a}}const m={READY:"qonto.ready"},l={CARD_SEE:"card.see",CARD_SEE_DETAILS:"card.see-details",CARD_ORDER:"card.order",CARD_UNLOCK:"card.unlock",CARD_SHOW_PIN:"card.show.pin",CARD_SET_PIN:"card.set.pin",TRANSFERS_CREATE:"transfers.create"},u={PRODUCTION:"production",STAGING:"staging",LOCAL:"local"},p={MASTER:"master",SANDBOX:"sandbox",QA:"qa"},g={EN:"en",FR:"fr",DE:"de",ES:"es",IT:"it",PT:"pt"};var f=Object.freeze({__proto__:null,ACTIONS:l,ACTIVITY_TAGS:{ATM:"atm",FALLBACK:"fallback",FEES:"fees",FINANCE:"finance",FOOD_AND_GROCERY:"food_and_grocery",GAS_STATION:"gas_station",HARDWARE_AND_EQUIPMENT:"hardware_and_equipment",HOTEL_AND_LODGING:"hotel_and_lodging",INSURANCE:"insurance",IT_AND_ELECTRONICS:"it_and_electronics",LEGAL_AND_ACCOUNTING:"legal_and_accounting",LOGISTICS:"logistics",MANUFACTURING:"manufacturing",MARKETING:"marketing",OFFICE_RENTAL:"office_rental",OFFICE_SUPPLY:"office_supply",ONLINE_SERVICE:"online_service",OTHER_EXPENSE:"other_expense",OTHER_INCOME:"other_income",OTHER_SERVICE:"other_service",PENDING:"pending",REFUND:"refund",RESTAURANT_AND_BAR:"restaurant_and_bar",SALES:"sales",SALARY:"salary",SUBSCRIPTION:"subscription",TAX:"tax",TRANSPORT:"transport",TREASURY_AND_INTERCO:"treasury_and_interco",UTILITY:"utility",VOUCHER:"voucher"},BENEFICIARY_STATUSES:{PENDING:"pending",VALIDATED:"validated",DECLINED:"declined"},BRANCHES:p,ENVIRONMENTS:u,IFRAME_EVENTS:m,LOCALES:g,SEPA_TRANSFER_DECLINE_REASONS:{BENEFICIARY_BIC_INVALID:"beneficiary_bic_invalid",BENEFICIARY_IBAN_INVALID:"beneficiary_iban_invalid",BENEFICIARY_STATUS:"beneficiary_status",BENEFICIARY_NETWORK_RULES_ERROR:"beneficiary_network_rules_error",ORGANISATION_COMPLIANCE_REASONS:"organisation_compliance_reasons",DEBIT_ACCOUNT_INSUFFICIENT_FUNDS:"debit_account_insufficient_funds",QONTO_PROCESSING_FAILED:"qonto_processing_failed"},SEPA_TRANSFER_STATUSES:{PENDING:"pending",PROCESSING:"processing",CANCELED:"canceled",DECLINED:"declined",SETTLED:"settled"}});const h=Object.values(g);function _(e){if(!function(e){return h.includes(e)}(e))throw new s(`Unsupported locale: ${e}. The locale must be one of: ${h.join(", ")}.`);return e}function y(e){if(!e?.accessToken)throw new s("Access token is required when calling initialize()");return e?.operationSettings&&d(e.operationSettings),function(e){if(e.environment){if(!["production","staging","local"].includes(e.environment))throw new s('If provided, environment must be either "production" or "staging"\nYou can "import constants from @qonto/embed-sdk/common" and then use "constants.environment.PRODUCTION" or "constants.environment.STAGING"');if(e.branch&&!["master","sandbox","qa"].includes(e.branch))throw new s('If provided, branch must be either "master", "sandbox" or "qa"\nYou can "import constants from @qonto/embed-sdk/common" and then use "constants.branch.MASTER" or "constants.environment.SANDBOX" and so on')}}(e),e.locale&&_(e.locale),e}const T="https://embed.qonto.com",I="https://embed-js{branch}.staging.qonto.co",E="https://embed.dev.qonto.co",A={[u.PRODUCTION]:{IFRAME_BASE_URL:T,IFRAME_URL:`${T}/connect`,THIRD_PARTY_API_URL:"https://thirdparty.qonto.com"},[u.STAGING]:{IFRAME_BASE_URL:I,IFRAME_URL:`${I}/connect`,THIRD_PARTY_API_URL:"https://thirdparty{branch}.staging.qonto.co"},[u.LOCAL]:{IFRAME_BASE_URL:E,IFRAME_URL:`${E}/connect`,THIRD_PARTY_API_URL:"https://thirdparty{branch}.staging.qonto.co"}};class w{constructor(){this.environment=u.PRODUCTION,this.branch=p.SANDBOX;const e=process.env.QONTO_EMBED_ENVIRONMENT,t=process.env.QONTO_EMBED_BRANCH;this.environment=Object.values(u).includes(e)?e:u.PRODUCTION,this.branch=Object.values(p).includes(t)?t:p.SANDBOX}static getInstance(){return w.instance||(w.instance=new w),w.instance}setEnvironment(e){this.environment=e}getEnvironment(){return this.environment}setBranch(e){this.branch=e}getBranch(){return this.branch}clear(){this.environment=u.PRODUCTION,this.branch=p.MASTER}getEnvironmentUrls(){if(this.environment===u.PRODUCTION)return A.production;{const e=A[this.environment];return Object.entries(e).reduce(((e,[t,n])=>({...e,[t]:n.replace("{branch}",`-${this.branch}`)})),{})}}}const b=w.getInstance();class L{constructor(){this.currentLocale="en"}static getInstance(){return L.instance||(L.instance=new L),L.instance}setLocale(e){this.currentLocale=e}getLocale(){return this.currentLocale}setDefaultLocale(){this.currentLocale="en"}}const R=L.getInstance();const k={initialize:function(e){const{accessToken:t,stagingToken:a,operationSettings:i,environment:r,branch:s,locale:o}=y(e);n.setAccessToken(t),a&&n.setStagingToken(a),o&&R.setLocale(o),i&&c.setSettings(i),r&&(b.setEnvironment(r),s&&b.setBranch(s))},logout:function(){n.clearAccessToken(),n.clearStagingToken(),R.setDefaultLocale()},constants:f},{initialize:D,logout:S,constants:v}=k;class P extends a{constructor(e){super();const t=Array.isArray(e)?e.join("\n"):e;this.name="EmbedApiError",this.message=`The call to the Embed API failed with the following errors:\n${t}`}}function O({accessToken:e,stagingToken:t,idempotencyKey:a}){const i=new Headers;i.append("Authorization",`Bearer ${e}`);const r=t||n.getStagingToken();return r&&i.append("X-Qonto-Staging-Token",r),a&&i.append("X-Qonto-Idempotency-Key",a),i.append("Content-Type","application/json"),i.append("Accept-Language",R.getLocale()),i}async function N(e,t,n){const a={method:"GET",headers:O({accessToken:t,stagingToken:n})},i=b.getEnvironmentUrls().THIRD_PARTY_API_URL,r=await fetch(`${i}/v2/cards/${e.cardId}/data_view`,a),s=await r.json();if(s.errors)throw new P(s.errors.map((e=>`${e.code}: ${e.detail}`)));return function(e,t){const n=new URL(e);return"boolean"==typeof t.allowPinReveal&&n.searchParams.set("canSeePin",t.allowPinReveal?"true":"false"),"boolean"==typeof t.allowBlocking&&n.searchParams.set("canBlock",t.allowBlocking?"true":"false"),n.toString()}(s.iframe_url,e)}var U;!function(e){e.PENDING="pending",e.ONHOLD="onhold",e.ORDER_CANCELED="order_canceled",e.LIVE="live",e.PAUSED="paused",e.STOLEN="stolen",e.LOST="lost",e.PIN_BLOCKED="pin_blocked",e.DELETED="deleted",e.PRE_EXPIRED="pre_expired",e.EXPIRED="expired",e.DISCARDED="discarded",e.SHIPPED_LOST="shipped_lost",e.ABUSIVE="abusive"}(U||(U={}));const C={TRANSPORT:"transport",RESTAURANT_AND_BAR:"restaurant_and_bar",FOOD_AND_GROCERY:"food_and_grocery",IT_AND_ELECTRONICS:"it_and_electronics",UTILITY:"utility",TAX:"tax",LEGAL_AND_ACCOUNTING:"legal_and_accounting",ATM:"atm",OFFICE_SUPPLY:"office_supply",HARDWARE_AND_EQUIPMENT:"hardware_and_equipment",FINANCE:"finance"};var $,M;function B(e,t){const n=t.filter((t=>t.requiredIfPresent?!e[t.name]&&e[t.requiredIfPresent]:void 0===e[t.name])).map((e=>e.name));if(n.length>0)throw new s(n.map((e=>`Missing required parameter: ${e}`)))}function F(e){return Object.entries(e).filter((([,e])=>void 0!==e)).filter((([,e])=>"string"!=typeof e)).map((([e])=>`${e} must be a string`))}function j(e){return Object.entries(e).filter((([,e])=>void 0!==e&&!1!==e&&!0!==e)).map((([e])=>`${e} must be a boolean`))}function G(e){return Object.entries(e).filter((([,e])=>void 0!==e)).filter((([,e])=>"number"!=typeof e)).map((([e])=>`${e} must be a number`))}!function(e){e.VIRTUAL="virtual"}($||($={})),function(e){e.METAL="metal",e.PLUS="plus",e.STANDARD="standard"}(M||(M={}));const Y=[{name:"organizationId"},{name:"membershipId"},{name:"bankAccountId"},{name:"monthlyLimit"},{name:"cardLevel"}],q=[...Y,{name:"atmDailyLimit",requiredIfPresent:"hasAtmDailyLimit"},{name:"hasAtmDailyLimit",requiredIfPresent:"hasAtmOption"},{name:"atmMonthlyLimit",requiredIfPresent:"hasAtmOption"},{name:"shipToBusiness"},{name:"cardLevel"}];function x(e){if(!e)throw new s("cardSettings parameter is required for the called function");return"virtual"===e.cardLevel?function(e){return B(e,Y),function(e){const{membershipId:t,organizationId:n,bankAccountId:a,hasDailyLimit:i,hasTransactionLimit:r,monthlyLimit:o,dailyLimit:c,transactionLimit:d,activeDays:m,categories:l,cardLevel:u}=e,p=function(e){return"virtual"!==e?['cardLevel must be "virtual"']:[]}(u),g=F({membershipId:t,organizationId:n,bankAccountId:a}),f=j({hasDailyLimit:i,hasTransactionLimit:r}),h=G({monthlyLimit:o,dailyLimit:c,transactionLimit:d}),_=z(m),y=H(l),T=[...p,...g,...f,...h,..._,...y];if(T.length>0)throw new s(T)}(e),e}(e):function(e){B(e,q),function(e){const{membershipId:t,organizationId:n,bankAccountId:a,hasDailyLimit:i,hasTransactionLimit:r,monthlyLimit:o,dailyLimit:c,transactionLimit:d,activeDays:m,categories:l,cardLevel:u,hasNfcOption:p,hasForeignPaymentOption:g,hasOnlinePaymentOption:f,shipToBusiness:h,hasAtmOption:_,hasAtmDailyLimit:y,atmDailyLimit:T,atmMonthlyLimit:I,address:E,cardDesign:A,typeOfPrint:w}=e,b=function(e){return Object.values(M).includes(e)?[]:['cardLevel must be one of "standard", "plus", "metal"']}(u),L=function(e){const t=null!=e&&"string"!=typeof e,n=!["print","embossed",void 0,null].includes(e);return t||n?['typeOfPrint must be one of "print", "embossed" or null']:[]}(w),R=F({membershipId:t,organizationId:n,bankAccountId:a}),k=j({hasDailyLimit:i,hasTransactionLimit:r,hasAtmOption:_,hasNfcOption:p,hasForeignPaymentOption:g,hasOnlinePaymentOption:f,hasAtmDailyLimit:y,shipToBusiness:h}),D=G({monthlyLimit:o,dailyLimit:c,transactionLimit:d,atmDailyLimit:T,atmMonthlyLimit:I}),S=z(m),v=H(l),P=function(e){return["undefined","string"].includes(typeof e)?[]:["cardDesign must be a string"]}(A),O=function(e,t){if(t)return[];return!e||e.contactName&&e.firstLine&&e.zipCode&&e.city&&e.country?[]:["address must contain at least contactName, firstLine, zipCode, city and country properties"]}(E,h),N=[...b,...R,...k,...D,...S,...v,...L,...P,...O];if(N.length>0)throw new s(N)}(e)}(e)}function z(e){const t=!Array.isArray(e)||!e.every((e=>Number.isInteger(e)&&e>0&&e<8));return void 0!==e&&t?["activeDays must be an array of integers between 1 and 7"]:[]}function H(e){const t=!Array.isArray(e)||e.some((e=>"string"!=typeof e));return void 0!==e&&t?["categories must be an array of strings"]:[]}class V extends a{constructor(e){super(),this.name="EmbedOperationError",this.message=e}}class K{constructor(e){this.options=e,this.iframe=null,this.parentElement=null,this.messageListeners=new Map,this.defaultTimeout=3e4;const t=new URL(e.iframeUrl);this.targetOrigin=`${t.protocol}//${t.host}`}async initialize(){if(this.iframe)return this;if(this.parentElement=document.getElementById(this.options.parentElementId),!this.parentElement)throw new V(`Could not install the authentication UI because the parent element with id ${this.options.parentElementId} was not found.\nPlease make sure to pass a valid parentElementId when calling the method.`);return new Promise(((e,t)=>{this.iframe=document.createElement("iframe"),this.iframe.src=this.options.iframeUrl,this.iframe.style.width="100%",this.iframe.style.height="100%",this.iframe.style.border="none";const n=this.options.timeout||this.defaultTimeout,a=setTimeout((()=>{window.removeEventListener("message",i),t(new V(`Could not install the authentication UI because the timeout of ${n}ms was reached.\nPlease make sure the application can reach the Internet.`))}),n),i=t=>{t.data.eventId===m.READY&&(clearTimeout(a),window.removeEventListener("message",i),e(this))};window.addEventListener("message",i),this.parentElement?.appendChild(this.iframe)}))}postMessage(e){return this.iframe&&this.iframe.contentWindow?new Promise(((t,n)=>{const a=i=>{if(i.data?.actionId===e.actionId){if("error"===i.data.status)return this.removeMessageListener(e.actionId,a),n(new V(`An error occurred when performing the action ${e.actionId}.\n${JSON.stringify(i.data.payload)}`));this.removeMessageListener(e.actionId,a),t(i.data.payload)}};this.addMessageListener(e.actionId,a),this.iframe?.contentWindow?.postMessage(e,this.targetOrigin)})):Promise.reject(new V("Attempted to perform an Embed operation without having the authentication UI initialized."))}addMessageListener(e,t){this.messageListeners.has(e)||this.messageListeners.set(e,[]);this.messageListeners.get(e).push(t),window.addEventListener("message",t)}removeMessageListener(e,t){const n=this.messageListeners.get(e);if(n){const e=n.indexOf(t);-1!==e&&(n.splice(e,1),window.removeEventListener("message",t))}}destroy(){this.messageListeners.forEach((e=>{e.forEach((e=>{window.removeEventListener("message",e)}))})),this.messageListeners.clear(),this.iframe&&this.parentElement&&(this.parentElement.removeChild(this.iframe),this.iframe=null)}}function X({accessToken:e,stagingToken:t,locale:n,debugMode:a}){const i=a||!1,r=n||R.getLocale(),s=b.getEnvironmentUrls().IFRAME_URL,o=t?`&staging_token=${encodeURIComponent(t)}`:"";return`${s}?debug=${i}&lang=${encodeURIComponent(r)}#access_token=${encodeURIComponent(e)}${o}`}function Q({parentElementId:e,iframeUrl:t}){return new K({parentElementId:e,iframeUrl:t}).initialize()}const W=[];for(let e=0;e<256;++e)W.push((e+256).toString(16).slice(1));let J;const Z=new Uint8Array(16);var ee={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function te(e,t,n){if(ee.randomUUID&&!e)return ee.randomUUID();const a=(e=e||{}).random??e.rng?.()??function(){if(!J){if("undefined"==typeof crypto||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");J=crypto.getRandomValues.bind(crypto)}return J(Z)}();if(a.length<16)throw new Error("Random bytes length must be >= 16");return a[6]=15&a[6]|64,a[8]=63&a[8]|128,function(e,t=0){return(W[e[t+0]]+W[e[t+1]]+W[e[t+2]]+W[e[t+3]]+"-"+W[e[t+4]]+W[e[t+5]]+"-"+W[e[t+6]]+W[e[t+7]]+"-"+W[e[t+8]]+W[e[t+9]]+"-"+W[e[t+10]]+W[e[t+11]]+W[e[t+12]]+W[e[t+13]]+W[e[t+14]]+W[e[t+15]]).toLowerCase()}(a)}function ne(e){return"virtual"===e.cardLevel?function(e){const t=ie(e.categories);return{actionId:l.CARD_ORDER,actionData:{idempotencyKey:te(),body:{card:{payment_monthly_limit:e.monthlyLimit,payment_daily_limit:e.dailyLimit,payment_daily_limit_option:e.hasDailyLimit,payment_transaction_limit:e.transactionLimit,payment_transaction_limit_option:e.hasTransactionLimit,active_days:e.activeDays||[],holder_id:e.membershipId,organization_id:e.organizationId,bank_account_id:e.bankAccountId,categories:t,card_level:e.cardLevel}}}}}(e):function(e){const t=ie(e.categories);return{actionId:l.CARD_ORDER,actionData:{idempotencyKey:te(),body:{card:{payment_monthly_limit:e.monthlyLimit,payment_daily_limit:e.dailyLimit,payment_daily_limit_option:e.hasDailyLimit,payment_transaction_limit:e.transactionLimit,payment_transaction_limit_option:e.hasTransactionLimit,active_days:e.activeDays||[],holder_id:e.membershipId,organization_id:e.organizationId,bank_account_id:e.bankAccountId,categories:t,card_level:e.cardLevel,card_design:e.cardDesign,..."plus"===e.cardLevel&&{type_of_print:e.typeOfPrint},ship_to_business_address:e.shipToBusiness,atm_option:e.hasAtmOption,nfc_option:e.hasNfcOption,foreign_option:e.hasForeignPaymentOption,online_option:e.hasOnlinePaymentOption,atm_daily_limit:e.atmDailyLimit,atm_monthly_limit:e.atmMonthlyLimit,...!e.shipToBusiness&&{address:{contact_name:e.address?.contactName,first_line:e.address?.firstLine,second_line:e.address?.secondLine,third_line:e.address?.thirdLine,zipcode:e.address?.zipCode,city:e.address?.city,country:e.address?.country}}}}}}}(e)}function ae(e){return{id:e.id,nickname:e.nickname,embossedName:e.embossed_name,status:e.status,maskPan:e.mask_pan,expMonth:parseInt(e.exp_month,10),expYear:parseInt(e.exp_year,10),lastActivityAt:new Date(e.last_activity_at),lastDigits:e.last_digits,shipToBusiness:e.ship_to_business,atmOption:e.atm_option,atmDailyLimitOption:e.atm_daily_limit_option,nfcOption:e.nfc_option,onlineOption:e.online_option,foreignOption:e.foreign_option,atmMonthlyLimit:e.atm_monthly_limit,atmMonthlySpent:e.atm_monthly_spent,atmDailyLimit:e.atm_daily_limit,atmDailySpent:e.atm_daily_spent,paymentMonthlyLimit:e.payment_monthly_limit,paymentMonthlySpent:e.payment_monthly_spent,paymentDailyLimit:e.payment_daily_limit,paymentDailySpent:e.payment_daily_spent,paymentDailyLimitOption:e.payment_daily_limit_option,paymentTransactionLimit:e.payment_transaction_limit,paymentTransactionLimitOption:e.payment_transaction_limit_option,activeDays:e.active_days,holderId:e.holder_id,bankAccountId:e.bank_account_id,organizationId:e.organization_id,updatedAt:new Date(e.updated_at),createdAt:new Date(e.created_at),shippedAt:new Date(e.shipped_at),cardType:e.card_type,cardLevel:e.card_level,paymentLifespanLimit:e.payment_lifespan_limit,paymentLifespanSpent:e.payment_lifespan_spent,preExpiresAt:new Date(e.pre_expires_at),categories:e.categories,renewed:e.renewed,renewal:e.renewal,...e.parent_card_summary&&{parentCardSummary:{id:e.parent_card_summary.id,lastDigits:e.parent_card_summary.last_digits}},hadOperation:e.had_operation,hadPinOperation:e.had_pin_operation,cardDesign:e.card_design,typeOfPrint:e.type_of_print,upsold:e.upsold,upsell:e.upsell,discardOn:new Date(e.discard_on),reordered:e.reordered}}function ie(e){const t=Object.values(C);return(e||[]).filter((e=>t.includes(e)))}const re={getCards:async function({membershipId:e,accessToken:t,stagingToken:n}){try{const a=t||r();if(e&&"string"!=typeof e)throw new s("membershipId must be a string");const i=await async function({membershipId:e,accessToken:t,stagingToken:n}){const a={method:"GET",headers:O({accessToken:t,stagingToken:n})},i=b.getEnvironmentUrls().THIRD_PARTY_API_URL,r=e?`${i}/v2/cards?holder_ids[]=${e}`:`${i}/v2/cards`,s=await fetch(r,a),o=await s.json();if(o.errors)throw new P(o.errors.map((e=>`${e.code}: ${e.detail}`)));return o.cards}({membershipId:e,accessToken:a,stagingToken:n});return i.map((e=>ae(e)))}catch(e){return Promise.reject(e)}},getCard:async function({cardId:e,accessToken:t,stagingToken:n}){try{const a=t||r();if(e&&"string"!=typeof e)throw new s("cardId must be a string");const i=await async function({cardId:e,accessToken:t,stagingToken:n}){const a={method:"GET",headers:O({accessToken:t,stagingToken:n})},i=`${b.getEnvironmentUrls().THIRD_PARTY_API_URL}/v2/cards?ids[]=${e}`,r=await fetch(i,a),s=await r.json();if(s.errors)throw new P(s.errors.map((e=>`${e.code}: ${e.detail}`)));return s.cards[0]}({cardId:e,accessToken:a,stagingToken:n});return ae(i)}catch(e){return Promise.reject(e)}},orderCard:async function(e){try{const t=r(),{uiParentElementId:a,debugMode:i}=d(e.operationSettings);x(e.cardSettings);const s=X({accessToken:t,stagingToken:n.getStagingToken()||void 0,debugMode:i}),o=await Q({iframeUrl:s,parentElementId:a}),c=ne(e.cardSettings),m=await o.postMessage(c);return o.destroy(),ae(m)}catch(e){return Promise.reject(e)}},unlockCard:async function(e){try{const t=r(),{uiParentElementId:a,debugMode:i}=d(e.operationSettings);!function(e){if(!e)throw new s("cardSettings parameter is required for the called function");if(!e.cardId)throw new s("cardId is required for the called function");const t=F({cardId:e.cardId});if(t.length>0)throw new s(t)}(e.cardSettings);const o=X({accessToken:t,stagingToken:n.getStagingToken()||void 0,debugMode:i}),c=await Q({iframeUrl:o,parentElementId:a}),m=function(e){return{actionId:l.CARD_UNLOCK,actionData:{cardId:e.cardSettings.cardId}}}(e),u=await c.postMessage(m);return c.destroy(),ae(u)}catch(e){return Promise.reject(e)}},displayCard:async function(e){try{const t=r(),{uiParentElementId:n}=d(e.operationSettings);!function(e){if(!e)throw new s("cardSettings parameter is required for the called function");if(!e.cardId)throw new s("cardId is required for the called function");const t=F({cardId:e.cardId});if(t.length>0)throw new s(t);let n={};void 0!==e.allowPinReveal&&(n={allowPinReveal:e.allowPinReveal}),void 0!==e.allowBlocking&&(n={...n,allowBlocking:e.allowBlocking});const a=j(n);if(a.length>0)throw new s(a)}(e.cardSettings);const a=await N(e.cardSettings,t),i=await Q({iframeUrl:a,parentElementId:n});return{destroyEmbedUI:()=>{i.destroy()}}}catch(e){return Promise.reject(e)}}},se=re;function oe({endpointUrl:e,paginationSettings:t}){const n=new URL(e);return t?.page&&n.searchParams.set("page",t.page.toString()),t?.itemsPerPage&&n.searchParams.set("per_page",t.itemsPerPage.toString()),n}function ce(e){if(e)return{totalItems:e?.total_count,totalPages:e?.total_pages,currentPage:e?.current_page,itemsPerPage:e?.per_page,previousPage:e?.prev_page||null,nextPage:e?.next_page||null}}function de(e){return{id:e.id,name:e.name,email:e.email,activityTag:e.activity_tag,iban:e.iban,bic:e.bic,currency:e.currency,status:e.status,trusted:e.trusted,createdAt:new Date(e.created_at),updatedAt:new Date(e.updated_at)}}function me(e){return{name:e.name,...e.email&&{email:e.email},...e.activityTag&&{activity_tag:e.activityTag},iban:e.iban,...e.bic&&{bic:e.bic}}}const le="/v2/sepa/beneficiaries";const ue=[{name:"name"},{name:"iban"}];const pe={getBeneficiaries:async function(e){const t=e?.accessToken||r(),n=await async function({paginationSettings:e,accessToken:t,stagingToken:n}){const a={method:"GET",headers:O({accessToken:t,stagingToken:n})},i=oe({endpointUrl:new URL(b.getEnvironmentUrls().THIRD_PARTY_API_URL+le),paginationSettings:e}),r=await fetch(i,a),s=await r.json();if(s.errors)throw new P(s.errors.map((e=>`${e.code}: ${e.detail}`)));return{beneficiaries:s.beneficiaries,meta:s.meta}}({accessToken:t,stagingToken:e?.stagingToken,paginationSettings:e?.paginationSettings}),a=n.beneficiaries.map((e=>de(e))),i=ce(n.meta);return{beneficiaries:a,...i?{meta:i}:{}}},getBeneficiary:async function({beneficiaryId:e,accessToken:t,stagingToken:n}){const a=t||r();!function(e){if(!e)throw new s("beneficiaryId parameter is required for the called function");if(e&&"string"!=typeof e)throw new s("beneficiaryId must be a string")}(e);return de(await async function({accessToken:e,stagingToken:t,beneficiaryId:n}){const a={method:"GET",headers:O({accessToken:e,stagingToken:t})},i=`${b.getEnvironmentUrls().THIRD_PARTY_API_URL}${le}/${n}`,r=await fetch(i,a),s=await r.json();if(s.errors)throw new P(s.errors.map((e=>`${e.code}: ${e.detail}`)));return s.beneficiary}({beneficiaryId:e,accessToken:a,stagingToken:n}))},addBeneficiary:async function({beneficiary:e,accessToken:t,stagingToken:n}){const a=t||r();!function(e){if(!e)throw new s("beneficiary parameter is required for the called function");if("object"!=typeof e)throw new s("beneficiary must be an object");B(e,ue);const t=F({name:e.name,iban:e.iban,email:e.email,activityTag:e.activityTag,bic:e.bic});if(t.length>0)throw new s(t)}(e);return de(await async function({beneficiary:e,accessToken:t,stagingToken:n}){const a={method:"POST",headers:O({accessToken:t,stagingToken:n,idempotencyKey:te()}),body:JSON.stringify({beneficiary:me(e)})},i=`${b.getEnvironmentUrls().THIRD_PARTY_API_URL}${le}`,r=await fetch(i,a),s=await r.json();if(s.errors)throw new P(s.errors.map((e=>`${e.code}: ${e.detail}`)));return s.beneficiary}({beneficiary:e,accessToken:a,stagingToken:n}))}};function ge(e){return{id:e.id,initiatorId:e.initiator_id,bankAccountId:e.bank_account_id,amount:Number(e.amount),amountCents:Number(e.amount_cents),amountCurrency:e.amount_currency,status:e.status,beneficiaryId:e.beneficiary_id,reference:e.reference,note:e.note,declinedReason:e.declined_reason,scheduledDate:new Date(e.scheduled_date),createdAt:new Date(e.created_at),updatedAt:new Date(e.updated_at),processedAt:new Date(e.processed_at),completedAt:new Date(e.completed_at),transactionId:e.transaction_id}}const fe="/v2/sepa/transfers";const he=[{name:"bankAccountId"},{name:"beneficiaryId"},{name:"reference"},{name:"amount"}];const _e={getSepaTransfers:async function(e={}){const t=e?.accessToken||r(),n=await async function({accessToken:e,stagingToken:t,paginationSettings:n}){const a={method:"GET",headers:O({accessToken:e,stagingToken:t})},i=oe({endpointUrl:new URL(b.getEnvironmentUrls().THIRD_PARTY_API_URL+fe),paginationSettings:n}),r=await fetch(i,a);if(!r.ok)throw new P("Failed to fetch SEPA transfers");const s=await r.json();if(s.errors)throw new P(s.errors.map((e=>`${e.code}: ${e.detail}`)));return{transfers:s.transfers,meta:s.meta}}({accessToken:t,stagingToken:e?.stagingToken,paginationSettings:e?.paginationSettings}),a=n.transfers.map((e=>ge(e))),i=ce(n.meta);return{transfers:a,...i?{meta:i}:{}}},getSepaTransfer:async function({sepaTransferId:e,accessToken:t,stagingToken:n}){const a=t||r();!function(e){if(!e)throw new s("sepaTransferId parameter is required for the called function");if(e&&"string"!=typeof e)throw new s("sepaTransferId must be a string")}(e);return ge(await async function({accessToken:e,stagingToken:t,sepaTransferId:n}){const a={method:"GET",headers:O({accessToken:e,stagingToken:t})},i=`${b.getEnvironmentUrls().THIRD_PARTY_API_URL}${fe}/${n}`,r=await fetch(i,a),s=await r.json();if(s.errors)throw new P(s.errors.map((e=>`${e.code}: ${e.detail}`)));return s.external_transfer}({sepaTransferId:e,accessToken:a,stagingToken:n}))},createSepaTransfer:async function({transfer:e,accessToken:t,stagingToken:n,idempotencyKey:a}){const i=t||r(),o=a||te();!function(e){if(!e)throw new s("transfer parameter is required for the called function");if("object"!=typeof e)throw new s("transfer must be an object");B(e,he);const t=[...F({beneficiaryId:e.beneficiaryId,bankAccountId:e.bankAccountId,note:e.note,reference:e.reference}),...G({amount:e.amount})].flat();if(t.length>0)throw new s(t)}(e);return ge(await async function({transfer:e,accessToken:t,stagingToken:n,idempotencyKey:a}){const i=function(e){return{bank_account_id:e.bankAccountId,beneficiary_id:e.beneficiaryId,amount:e.amount.toString(),reference:e.reference,...e.note?{note:e.note}:{},...e.scheduledDate?{scheduled_date:e.scheduledDate.toISOString().split("T")[0]}:{}}}(e),r={method:"POST",headers:O({accessToken:t,stagingToken:n,idempotencyKey:a}),body:JSON.stringify({transfer:i})},s=`${b.getEnvironmentUrls().THIRD_PARTY_API_URL}${fe}`,o=await fetch(s,r),c=await o.json();if(c.errors)throw new P(c.errors.map((e=>`${e.code}: ${e.detail}`)));return c.transfer}({transfer:e,accessToken:i,stagingToken:n,idempotencyKey:o}))}};e.beneficiaries=pe,e.cards=se,e.constants=v,e.initialize=D,e.logout=S,e.sepaTransfers=_e}));
@@ -1 +1 @@
1
- {"version":3,"file":"handlers.d.ts","sourceRoot":"","sources":["../../src/mocks/handlers.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAChF,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC;AAGnF,eAAO,MAAM,oBAAoB,yBAAyB,CAAC;AAK3D,eAAO,MAAM,iBAAiB,EAAE,qBAY/B,CAAC;AAEF,eAAO,MAAM,sBAAsB;;;;;;;CAOlC,CAAC;AAEF,eAAO,MAAM,uBAAuB,EAAE,qBAAqB,EAe1D,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,sBAkB1B,CAAC;AAEF,eAAO,MAAM,WAAW,6BAkMvB,CAAC"}
1
+ {"version":3,"file":"handlers.d.ts","sourceRoot":"","sources":["../../src/mocks/handlers.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAChF,OAAO,KAAK,EAEV,sBAAsB,EACvB,MAAM,sCAAsC,CAAC;AAG9C,eAAO,MAAM,oBAAoB,yBAAyB,CAAC;AAK3D,eAAO,MAAM,iBAAiB,EAAE,qBAY/B,CAAC;AAEF,eAAO,MAAM,sBAAsB;;;;;;;CAOlC,CAAC;AAEF,eAAO,MAAM,uBAAuB,EAAE,qBAAqB,EAe1D,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,sBAkB1B,CAAC;AAEF,eAAO,MAAM,WAAW,6BA0NvB,CAAC"}
@@ -14,5 +14,6 @@
14
14
  export declare const sepaTransfers: {
15
15
  getSepaTransfers: typeof import("./sepa-transfers").getSepaTransfers;
16
16
  getSepaTransfer: typeof import("./sepa-transfers").getSepaTransfer;
17
+ createSepaTransfer: typeof import("./sepa-transfers").createSepaTransfer;
17
18
  };
18
19
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sepa-transfers/index.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,aAAa;;;CAAuC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sepa-transfers/index.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,aAAa;;;;CAAuC,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import type { PaginationResponseDataObject, PaginationSettings } from '@common/api-pagination/api-pagination.types';
2
- import type { SepaTransferDataObject } from './sepa-transfers.types';
2
+ import type { NewSepaTransfer, SepaTransferDataObject } from './sepa-transfers.types';
3
3
  interface GetSepaTransfersParams {
4
4
  accessToken: string;
5
5
  stagingToken?: string;
@@ -14,8 +14,15 @@ interface GetSepaTransfersApiResponse {
14
14
  transfers: SepaTransferDataObject[];
15
15
  meta: PaginationResponseDataObject;
16
16
  }
17
+ export interface CreateSepaTransferParams {
18
+ transfer: NewSepaTransfer;
19
+ accessToken: string;
20
+ stagingToken?: string;
21
+ idempotencyKey: string;
22
+ }
17
23
  export declare const SEPA_TRANSFERS_ENDPOINT = "/v2/sepa/transfers";
18
24
  export declare function getSepaTransfers({ accessToken, stagingToken, paginationSettings, }: GetSepaTransfersParams): Promise<GetSepaTransfersApiResponse>;
19
25
  export declare function getSepaTransfer({ accessToken, stagingToken, sepaTransferId, }: GetSepaTransferParams): Promise<SepaTransferDataObject>;
26
+ export declare function createSepaTransfer({ transfer, accessToken, stagingToken, idempotencyKey, }: CreateSepaTransferParams): Promise<SepaTransferDataObject>;
20
27
  export {};
21
28
  //# sourceMappingURL=sepa-transfers.api.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sepa-transfers.api.d.ts","sourceRoot":"","sources":["../../src/sepa-transfers/sepa-transfers.api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,4BAA4B,EAC5B,kBAAkB,EACnB,MAAM,6CAA6C,CAAC;AAErD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAMrE,UAAU,sBAAsB;IAC9B,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;CACzC;AAED,UAAU,qBAAqB;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,UAAU,2BAA2B;IACnC,SAAS,EAAE,sBAAsB,EAAE,CAAC;IACpC,IAAI,EAAE,4BAA4B,CAAC;CACpC;AAED,eAAO,MAAM,uBAAuB,uBAAuB,CAAC;AAE5D,wBAAsB,gBAAgB,CAAC,EACrC,WAAW,EACX,YAAY,EACZ,kBAAkB,GACnB,EAAE,sBAAsB,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAkC/D;AAED,wBAAsB,eAAe,CAAC,EACpC,WAAW,EACX,YAAY,EACZ,cAAc,GACf,EAAE,qBAAqB,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAqBzD"}
1
+ {"version":3,"file":"sepa-transfers.api.d.ts","sourceRoot":"","sources":["../../src/sepa-transfers/sepa-transfers.api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,4BAA4B,EAC5B,kBAAkB,EACnB,MAAM,6CAA6C,CAAC;AAErD,OAAO,KAAK,EAEV,eAAe,EACf,sBAAsB,EACvB,MAAM,wBAAwB,CAAC;AAOhC,UAAU,sBAAsB;IAC9B,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;CACzC;AAED,UAAU,qBAAqB;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,UAAU,2BAA2B;IACnC,SAAS,EAAE,sBAAsB,EAAE,CAAC;IACpC,IAAI,EAAE,4BAA4B,CAAC;CACpC;AAED,MAAM,WAAW,wBAAwB;IACvC,QAAQ,EAAE,eAAe,CAAC;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,eAAO,MAAM,uBAAuB,uBAAuB,CAAC;AAE5D,wBAAsB,gBAAgB,CAAC,EACrC,WAAW,EACX,YAAY,EACZ,kBAAkB,GACnB,EAAE,sBAAsB,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAkC/D;AAED,wBAAsB,eAAe,CAAC,EACpC,WAAW,EACX,YAAY,EACZ,cAAc,GACf,EAAE,qBAAqB,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAqBzD;AAED,wBAAsB,kBAAkB,CAAC,EACvC,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,cAAc,GACf,EAAE,wBAAwB,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAyB5D"}
@@ -1,5 +1,5 @@
1
1
  import type { PaginationSettings } from '@common/api-pagination/api-pagination.types';
2
- import type { GetSepaTransfersResponse, SepaTransfer } from './sepa-transfers.types';
2
+ import type { GetSepaTransfersResponse, NewSepaTransfer, SepaTransfer } from './sepa-transfers.types';
3
3
  interface GetSepaTransfersParams {
4
4
  accessToken?: string;
5
5
  stagingToken?: string;
@@ -37,5 +37,26 @@ export declare function getSepaTransfer({ sepaTransferId, accessToken, stagingTo
37
37
  accessToken?: string;
38
38
  stagingToken?: string;
39
39
  }): Promise<SepaTransfer>;
40
+ /**
41
+ * Creates a new SEPA transfer from the current user to a given beneficiary.
42
+ * @param createTransferParams - An object with the transfer and optional
43
+ * accessToken, stagingToken, and idempotencyKey properties. The transfer
44
+ * property is required and should be an object containing the details of the
45
+ * transfer to be created.
46
+ * @returns A promise that resolves to the created SEPA transfer.
47
+ * @throws \{AuthenticationError\} If the access token is invalid or missing.
48
+ * Ensure initialize has been called before using this function if you are not
49
+ * passing the access token.
50
+ * @throws \{InvalidParametersError\} If the `transfer` parameter is not an object
51
+ * or is missing, or if the required properties of the transfer object are
52
+ * missing or invalid.
53
+ * @throws \{EmbedApiError\} If the API request fails or returns an error.
54
+ */
55
+ export declare function createSepaTransfer({ transfer, accessToken, stagingToken, idempotencyKey, }: {
56
+ transfer: NewSepaTransfer;
57
+ accessToken?: string;
58
+ stagingToken?: string;
59
+ idempotencyKey?: string;
60
+ }): Promise<SepaTransfer>;
40
61
  export {};
41
62
  //# sourceMappingURL=sepa-transfers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sepa-transfers.d.ts","sourceRoot":"","sources":["../../src/sepa-transfers/sepa-transfers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6CAA6C,CAAC;AAOtF,OAAO,KAAK,EACV,wBAAwB,EACxB,YAAY,EACb,MAAM,wBAAwB,CAAC;AAIhC,UAAU,sBAAsB;IAC9B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;CACzC;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,gBAAgB,CACpC,sBAAsB,GAAE,sBAA2B,GAClD,OAAO,CAAC,wBAAwB,CAAC,CAqBnC;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,eAAe,CAAC,EACpC,cAAc,EACd,WAAW,EACX,YAAY,GACb,EAAE;IACD,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,GAAG,OAAO,CAAC,YAAY,CAAC,CASxB"}
1
+ {"version":3,"file":"sepa-transfers.d.ts","sourceRoot":"","sources":["../../src/sepa-transfers/sepa-transfers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6CAA6C,CAAC;AAQtF,OAAO,KAAK,EACV,wBAAwB,EACxB,eAAe,EACf,YAAY,EACb,MAAM,wBAAwB,CAAC;AAOhC,UAAU,sBAAsB;IAC9B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;CACzC;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,gBAAgB,CACpC,sBAAsB,GAAE,sBAA2B,GAClD,OAAO,CAAC,wBAAwB,CAAC,CAqBnC;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,eAAe,CAAC,EACpC,cAAc,EACd,WAAW,EACX,YAAY,GACb,EAAE;IACD,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,GAAG,OAAO,CAAC,YAAY,CAAC,CASxB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,kBAAkB,CAAC,EACvC,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,cAAc,GACf,EAAE;IACD,QAAQ,EAAE,eAAe,CAAC;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,GAAG,OAAO,CAAC,YAAY,CAAC,CAWxB"}
@@ -1,7 +1,8 @@
1
- import { getSepaTransfers, getSepaTransfer } from './sepa-transfers';
1
+ import { getSepaTransfers, getSepaTransfer, createSepaTransfer } from './sepa-transfers';
2
2
  declare const sepaTransfers: {
3
3
  getSepaTransfers: typeof getSepaTransfers;
4
4
  getSepaTransfer: typeof getSepaTransfer;
5
+ createSepaTransfer: typeof createSepaTransfer;
5
6
  };
6
7
  export { sepaTransfers };
7
8
  //# sourceMappingURL=sepa-transfers.public-api.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sepa-transfers.public-api.d.ts","sourceRoot":"","sources":["../../src/sepa-transfers/sepa-transfers.public-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAErE,QAAA,MAAM,aAAa;;;CAGlB,CAAC;AAEF,OAAO,EAAE,aAAa,EAAE,CAAC"}
1
+ {"version":3,"file":"sepa-transfers.public-api.d.ts","sourceRoot":"","sources":["../../src/sepa-transfers/sepa-transfers.public-api.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,kBAAkB,EACnB,MAAM,kBAAkB,CAAC;AAE1B,QAAA,MAAM,aAAa;;;;CAIlB,CAAC;AAEF,OAAO,EAAE,aAAa,EAAE,CAAC"}
@@ -1,3 +1,4 @@
1
- import type { SepaTransfer, SepaTransferDataObject } from './sepa-transfers.types';
1
+ import type { SepaTransfer, SepaTransferDataObject, NewSepaTransfer, NewSepaTransferDataObject } from './sepa-transfers.types';
2
2
  export declare function serializeSepaTransfer(data: SepaTransferDataObject): SepaTransfer;
3
+ export declare function serializeToNewSepaTransferDataObject(transfer: NewSepaTransfer): NewSepaTransferDataObject;
3
4
  //# sourceMappingURL=sepa-transfers.serializer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sepa-transfers.serializer.d.ts","sourceRoot":"","sources":["../../src/sepa-transfers/sepa-transfers.serializer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,sBAAsB,EACvB,MAAM,wBAAwB,CAAC;AAEhC,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,sBAAsB,GAC3B,YAAY,CAoBd"}
1
+ {"version":3,"file":"sepa-transfers.serializer.d.ts","sourceRoot":"","sources":["../../src/sepa-transfers/sepa-transfers.serializer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,sBAAsB,EACtB,eAAe,EACf,yBAAyB,EAC1B,MAAM,wBAAwB,CAAC;AAEhC,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,sBAAsB,GAC3B,YAAY,CAoBd;AAED,wBAAgB,oCAAoC,CAClD,QAAQ,EAAE,eAAe,GACxB,yBAAyB,CAW3B"}
@@ -16,20 +16,68 @@ type SepaTransferStatus = (typeof SEPA_TRANSFER_STATUSES)[keyof typeof SEPA_TRAN
16
16
  export interface SepaTransfer {
17
17
  id: string;
18
18
  initiatorId: string;
19
+ /**
20
+ * The ID of the bank account from which the transfer is made.
21
+ */
19
22
  bankAccountId: string;
23
+ /**
24
+ * The amount of money being transferred, represented as a number.
25
+ */
20
26
  amount: number;
27
+ /**
28
+ * The amount of money being transferred, represented in cents as a number.
29
+ */
21
30
  amountCents: number;
31
+ /**
32
+ * The currency of the amount being transferred, represented as a string.
33
+ * @example 'EUR'
34
+ */
22
35
  amountCurrency: string;
36
+ /**
37
+ * The current status of the SEPA transfer, represented as a string.
38
+ */
23
39
  status: SepaTransferStatus;
40
+ /**
41
+ * The ID of the beneficiary to whom the transfer is made.
42
+ */
24
43
  beneficiaryId: string;
44
+ /**
45
+ * A reference string for the transfer, which can be used for tracking or
46
+ * identification purposes.
47
+ */
25
48
  reference: string;
49
+ /**
50
+ * An optional note that can be included with the transfer for additional
51
+ * information or context.
52
+ */
26
53
  note: string;
54
+ /**
55
+ * The reason for the transfer being declined, if applicable.
56
+ */
27
57
  declinedReason: SepaTransferDeclinedReason;
58
+ /**
59
+ * The date when the transfer is scheduled to be processed.
60
+ */
28
61
  scheduledDate: Date;
62
+ /**
63
+ * The date and time when the transfer was created.
64
+ */
29
65
  createdAt: Date;
66
+ /**
67
+ * The date and time when the transfer was last updated.
68
+ */
30
69
  updatedAt: Date;
70
+ /**
71
+ * The date and time when the transfer was processed.
72
+ */
31
73
  processedAt: Date;
74
+ /**
75
+ * The date and time when the transfer was completed.
76
+ */
32
77
  completedAt: Date;
78
+ /**
79
+ * The ID of the transaction associated with this SEPA transfer.
80
+ */
33
81
  transactionId: string;
34
82
  }
35
83
  export interface SepaTransferDataObject {
@@ -66,5 +114,47 @@ export interface GetSepaTransfersResponse {
66
114
  */
67
115
  meta?: PaginationState;
68
116
  }
117
+ /**
118
+ * Represents the parameters required to create a new SEPA transfer.
119
+ * This interface is used to define the structure of the data needed to
120
+ * initiate a SEPA transfer
121
+ */
122
+ export interface NewSepaTransfer {
123
+ /**
124
+ * The ID of the bank account from which the transfer will be made.
125
+ */
126
+ bankAccountId: string;
127
+ /**
128
+ * The ID of the beneficiary to whom the transfer will be made.
129
+ */
130
+ beneficiaryId: string;
131
+ /**
132
+ * The amount to be transferred, represented as a number.
133
+ */
134
+ amount: number;
135
+ /**
136
+ * A reference string for the transfer, which can be used for tracking or
137
+ * identification purposes.
138
+ */
139
+ reference: string;
140
+ /**
141
+ * An optional note that can be included with the transfer for additional
142
+ * information or context.
143
+ */
144
+ note?: string;
145
+ /**
146
+ * An optional date when the transfer is scheduled to be processed.
147
+ * If not provided, the transfer will be processed immediately.
148
+ */
149
+ scheduledDate?: Date;
150
+ }
151
+ export interface NewSepaTransferDataObject {
152
+ bank_account_id: string;
153
+ beneficiary_id: string;
154
+ amount: string;
155
+ reference: string;
156
+ note?: string;
157
+ scheduled_date?: string;
158
+ }
69
159
  export {};
70
160
  //# sourceMappingURL=sepa-transfers.types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sepa-transfers.types.d.ts","sourceRoot":"","sources":["../../src/sepa-transfers/sepa-transfers.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6CAA6C,CAAC;AACnF,OAAO,EACL,6BAA6B,EAC7B,sBAAsB,EACvB,MAAM,mBAAmB,CAAC;AAE3B;;GAEG;AACH,KAAK,0BAA0B,GAC7B,CAAC,OAAO,6BAA6B,CAAC,CAAC,MAAM,OAAO,6BAA6B,CAAC,CAAC;AAErF;;GAEG;AACH,KAAK,kBAAkB,GACrB,CAAC,OAAO,sBAAsB,CAAC,CAAC,MAAM,OAAO,sBAAsB,CAAC,CAAC;AAEvE;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,kBAAkB,CAAC;IAC3B,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,EAAE,0BAA0B,CAAC;IAC3C,aAAa,EAAE,IAAI,CAAC;IACpB,SAAS,EAAE,IAAI,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;IAChB,WAAW,EAAE,IAAI,CAAC;IAClB,WAAW,EAAE,IAAI,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,sBAAsB;IACrC,EAAE,EAAE,MAAM,CAAC;IACX,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,eAAe,EAAE,MAAM,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC;;;OAGG;IACH,SAAS,EAAE,YAAY,EAAE,CAAC;IAC1B;;;OAGG;IACH,IAAI,CAAC,EAAE,eAAe,CAAC;CACxB"}
1
+ {"version":3,"file":"sepa-transfers.types.d.ts","sourceRoot":"","sources":["../../src/sepa-transfers/sepa-transfers.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6CAA6C,CAAC;AACnF,OAAO,EACL,6BAA6B,EAC7B,sBAAsB,EACvB,MAAM,mBAAmB,CAAC;AAE3B;;GAEG;AACH,KAAK,0BAA0B,GAC7B,CAAC,OAAO,6BAA6B,CAAC,CAAC,MAAM,OAAO,6BAA6B,CAAC,CAAC;AAErF;;GAEG;AACH,KAAK,kBAAkB,GACrB,CAAC,OAAO,sBAAsB,CAAC,CAAC,MAAM,OAAO,sBAAsB,CAAC,CAAC;AAEvE;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,MAAM,EAAE,kBAAkB,CAAC;IAC3B;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,cAAc,EAAE,0BAA0B,CAAC;IAC3C;;OAEG;IACH,aAAa,EAAE,IAAI,CAAC;IACpB;;OAEG;IACH,SAAS,EAAE,IAAI,CAAC;IAChB;;OAEG;IACH,SAAS,EAAE,IAAI,CAAC;IAChB;;OAEG;IACH,WAAW,EAAE,IAAI,CAAC;IAClB;;OAEG;IACH,WAAW,EAAE,IAAI,CAAC;IAClB;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,sBAAsB;IACrC,EAAE,EAAE,MAAM,CAAC;IACX,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,eAAe,EAAE,MAAM,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC;;;OAGG;IACH,SAAS,EAAE,YAAY,EAAE,CAAC;IAC1B;;;OAGG;IACH,IAAI,CAAC,EAAE,eAAe,CAAC;CACxB;AAED;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,aAAa,CAAC,EAAE,IAAI,CAAC;CACtB;AAED,MAAM,WAAW,yBAAyB;IACxC,eAAe,EAAE,MAAM,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB"}
@@ -1,2 +1,4 @@
1
+ import type { NewSepaTransfer } from '@sepa-transfers/sepa-transfers.types';
1
2
  export declare function validateGetSepaTransferParams(sepaTransferId: string): string;
3
+ export declare function validateCreateSepaTransferParams(transfer: NewSepaTransfer): NewSepaTransfer;
2
4
  //# sourceMappingURL=sepa-transfers.validate.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sepa-transfers.validate.d.ts","sourceRoot":"","sources":["../../src/sepa-transfers/sepa-transfers.validate.ts"],"names":[],"mappings":"AAEA,wBAAgB,6BAA6B,CAAC,cAAc,EAAE,MAAM,GAAG,MAAM,CAU5E"}
1
+ {"version":3,"file":"sepa-transfers.validate.d.ts","sourceRoot":"","sources":["../../src/sepa-transfers/sepa-transfers.validate.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AAS5E,wBAAgB,6BAA6B,CAAC,cAAc,EAAE,MAAM,GAAG,MAAM,CAU5E;AAED,wBAAgB,gCAAgC,CAAC,QAAQ,EAAE,eAAe,mBAgCzE"}
@@ -1 +1 @@
1
- import{buildRequestHeaders as n}from"../common/network/network.js";import{environmentManager as e}from"../common/environment/environment-manager.js";import{addPaginationParamsToUrl as r}from"../common/api-pagination/api-pagination.js";import{EmbedApiError as o}from"../errors/EmbedApiError.js";const t="/v2/sepa/transfers";async function a({accessToken:a,stagingToken:s,paginationSettings:i}){const m={method:"GET",headers:n({accessToken:a,stagingToken:s})},c=new URL(e.getEnvironmentUrls().THIRD_PARTY_API_URL+t),f=r({endpointUrl:c,paginationSettings:i}),g=await fetch(f,m);if(!g.ok)throw new o("Failed to fetch SEPA transfers");const p=await g.json();if(p.errors)throw new o(p.errors.map((n=>`${n.code}: ${n.detail}`)));return{transfers:p.transfers,meta:p.meta}}async function s({accessToken:r,stagingToken:a,sepaTransferId:s}){const i={method:"GET",headers:n({accessToken:r,stagingToken:a})},m=`${e.getEnvironmentUrls().THIRD_PARTY_API_URL}${t}/${s}`,c=await fetch(m,i),f=await c.json();if(f.errors)throw new o(f.errors.map((n=>`${n.code}: ${n.detail}`)));return f.external_transfer}export{t as SEPA_TRANSFERS_ENDPOINT,s as getSepaTransfer,a as getSepaTransfers};
1
+ import{buildRequestHeaders as e}from"../common/network/network.js";import{environmentManager as n}from"../common/environment/environment-manager.js";import{addPaginationParamsToUrl as r}from"../common/api-pagination/api-pagination.js";import{EmbedApiError as t}from"../errors/EmbedApiError.js";import{serializeToNewSepaTransferDataObject as o}from"./sepa-transfers.serializer.js";const s="/v2/sepa/transfers";async function a({accessToken:o,stagingToken:a,paginationSettings:i}){const c={method:"GET",headers:e({accessToken:o,stagingToken:a})},m=new URL(n.getEnvironmentUrls().THIRD_PARTY_API_URL+s),f=r({endpointUrl:m,paginationSettings:i}),g=await fetch(f,c);if(!g.ok)throw new t("Failed to fetch SEPA transfers");const p=await g.json();if(p.errors)throw new t(p.errors.map((e=>`${e.code}: ${e.detail}`)));return{transfers:p.transfers,meta:p.meta}}async function i({accessToken:r,stagingToken:o,sepaTransferId:a}){const i={method:"GET",headers:e({accessToken:r,stagingToken:o})},c=`${n.getEnvironmentUrls().THIRD_PARTY_API_URL}${s}/${a}`,m=await fetch(c,i),f=await m.json();if(f.errors)throw new t(f.errors.map((e=>`${e.code}: ${e.detail}`)));return f.external_transfer}async function c({transfer:r,accessToken:a,stagingToken:i,idempotencyKey:c}){const m=o(r),f={method:"POST",headers:e({accessToken:a,stagingToken:i,idempotencyKey:c}),body:JSON.stringify({transfer:m})},g=`${n.getEnvironmentUrls().THIRD_PARTY_API_URL}${s}`,p=await fetch(g,f),T=await p.json();if(T.errors)throw new t(T.errors.map((e=>`${e.code}: ${e.detail}`)));return T.transfer}export{s as SEPA_TRANSFERS_ENDPOINT,c as createSepaTransfer,i as getSepaTransfer,a as getSepaTransfers};
@@ -1 +1 @@
1
- import"../common/auth/auth.js";import{validatePresenceOfAuthToken as a}from"../common/auth/auth.validate.js";import{serializePaginationResponse as s}from"../common/api-pagination/api-pagination.js";import{getSepaTransfer as n,getSepaTransfers as t}from"./sepa-transfers.api.js";import{serializeSepaTransfer as e}from"./sepa-transfers.serializer.js";import{validateGetSepaTransferParams as r}from"./sepa-transfers.validate.js";async function o(n={}){const r=n?.accessToken||a(),o=await t({accessToken:r,stagingToken:n?.stagingToken,paginationSettings:n?.paginationSettings}),i=o.transfers.map((a=>e(a))),p=s(o.meta);return{transfers:i,...p?{meta:p}:{}}}async function i({sepaTransferId:s,accessToken:t,stagingToken:o}){const i=t||a();r(s);const p=await n({sepaTransferId:s,accessToken:i,stagingToken:o});return e(p)}export{i as getSepaTransfer,o as getSepaTransfers};
1
+ import"../common/auth/auth.js";import{validatePresenceOfAuthToken as a}from"../common/auth/auth.validate.js";import{serializePaginationResponse as s}from"../common/api-pagination/api-pagination.js";import{createSepaTransfer as e,getSepaTransfer as n,getSepaTransfers as t}from"./sepa-transfers.api.js";import{serializeSepaTransfer as o}from"./sepa-transfers.serializer.js";import{validateCreateSepaTransferParams as r,validateGetSepaTransferParams as i}from"./sepa-transfers.validate.js";import c from"../../node_modules/.pnpm/uuid@11.1.0/node_modules/uuid/dist/esm-browser/v4.js";async function m(e={}){const n=e?.accessToken||a(),r=await t({accessToken:n,stagingToken:e?.stagingToken,paginationSettings:e?.paginationSettings}),i=r.transfers.map((a=>o(a))),c=s(r.meta);return{transfers:i,...c?{meta:c}:{}}}async function p({sepaTransferId:s,accessToken:e,stagingToken:t}){const r=e||a();i(s);const c=await n({sepaTransferId:s,accessToken:r,stagingToken:t});return o(c)}async function f({transfer:s,accessToken:n,stagingToken:t,idempotencyKey:i}){const m=n||a(),p=i||c();r(s);const f=await e({transfer:s,accessToken:m,stagingToken:t,idempotencyKey:p});return o(f)}export{f as createSepaTransfer,p as getSepaTransfer,m as getSepaTransfers};
@@ -1 +1 @@
1
- import{getSepaTransfer as e,getSepaTransfers as r}from"./sepa-transfers.js";const s={getSepaTransfers:r,getSepaTransfer:e};export{s as sepaTransfers};
1
+ import{createSepaTransfer as e,getSepaTransfer as r,getSepaTransfers as a}from"./sepa-transfers.js";const s={getSepaTransfers:a,getSepaTransfer:r,createSepaTransfer:e};export{s as sepaTransfers};
@@ -1 +1 @@
1
- function e(e){return{id:e.id,initiatorId:e.initiator_id,bankAccountId:e.bank_account_id,amount:Number(e.amount),amountCents:Number(e.amount_cents),amountCurrency:e.amount_currency,status:e.status,beneficiaryId:e.beneficiary_id,reference:e.reference,note:e.note,declinedReason:e.declined_reason,scheduledDate:new Date(e.scheduled_date),createdAt:new Date(e.created_at),updatedAt:new Date(e.updated_at),processedAt:new Date(e.processed_at),completedAt:new Date(e.completed_at),transactionId:e.transaction_id}}export{e as serializeSepaTransfer};
1
+ function e(e){return{id:e.id,initiatorId:e.initiator_id,bankAccountId:e.bank_account_id,amount:Number(e.amount),amountCents:Number(e.amount_cents),amountCurrency:e.amount_currency,status:e.status,beneficiaryId:e.beneficiary_id,reference:e.reference,note:e.note,declinedReason:e.declined_reason,scheduledDate:new Date(e.scheduled_date),createdAt:new Date(e.created_at),updatedAt:new Date(e.updated_at),processedAt:new Date(e.processed_at),completedAt:new Date(e.completed_at),transactionId:e.transaction_id}}function t(e){return{bank_account_id:e.bankAccountId,beneficiary_id:e.beneficiaryId,amount:e.amount.toString(),reference:e.reference,...e.note?{note:e.note}:{},...e.scheduledDate?{scheduled_date:e.scheduledDate.toISOString().split("T")[0]}:{}}}export{e as serializeSepaTransfer,t as serializeToNewSepaTransferDataObject};
@@ -1 +1 @@
1
- import{InvalidParametersError as r}from"../errors/InvalidParametersError.js";function e(e){if(!e)throw new r("sepaTransferId parameter is required for the called function");if(e&&"string"!=typeof e)throw new r("sepaTransferId must be a string");return e}export{e as validateGetSepaTransferParams};
1
+ import{InvalidParametersError as e}from"../errors/InvalidParametersError.js";import{validatePresenceOfRequiredParams as r,validateExpectedStringValues as n,validateExpectedNumericValues as t}from"../validation/input-param-validation.js";const a=[{name:"bankAccountId"},{name:"beneficiaryId"},{name:"reference"},{name:"amount"}];function o(r){if(!r)throw new e("sepaTransferId parameter is required for the called function");if(r&&"string"!=typeof r)throw new e("sepaTransferId must be a string");return r}function i(o){if(!o)throw new e("transfer parameter is required for the called function");if("object"!=typeof o)throw new e("transfer must be an object");r(o,a);const i=[...n({beneficiaryId:o.beneficiaryId,bankAccountId:o.bankAccountId,note:o.note,reference:o.reference}),...t({amount:o.amount})].flat();if(i.length>0)throw new e(i);return o}export{i as validateCreateSepaTransferParams,o as validateGetSepaTransferParams};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qonto/embed-sdk",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "description": "Library to embed Qonto features in your application",
5
5
  "type": "module",
6
6
  "exports": {