@voucherify/sdk 2.9.3 → 2.9.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.
Files changed (72) hide show
  1. package/dist/ApiLimitsHandler.d.ts +13 -0
  2. package/dist/AsyncActions.d.ts +17 -0
  3. package/dist/Balance.d.ts +15 -0
  4. package/dist/Campaigns.d.ts +66 -0
  5. package/dist/Categories.d.ts +29 -0
  6. package/dist/ClientSide.d.ts +77 -0
  7. package/dist/Consents.d.ts +13 -0
  8. package/dist/Customers.d.ts +75 -0
  9. package/dist/Distributions.d.ts +29 -0
  10. package/dist/Events.d.ts +15 -0
  11. package/dist/Exports.d.ts +25 -0
  12. package/dist/Loyalties.d.ts +171 -0
  13. package/dist/MetadataSchemas.d.ts +17 -0
  14. package/dist/Orders.d.ts +32 -0
  15. package/dist/ProductCollections.d.ts +30 -0
  16. package/dist/Products.d.ts +66 -0
  17. package/dist/PromotionTiers.d.ts +43 -0
  18. package/dist/Promotions.d.ts +30 -0
  19. package/dist/PromotionsStacks.d.ts +34 -0
  20. package/dist/Qualifications.d.ts +24 -0
  21. package/dist/Redemptions.d.ts +53 -0
  22. package/dist/RequestController.d.ts +31 -0
  23. package/dist/Rewards.d.ts +46 -0
  24. package/dist/Segments.d.ts +25 -0
  25. package/dist/ValidationRules.d.ts +47 -0
  26. package/dist/Validations.d.ts +39 -0
  27. package/dist/VoucherifyClientSide.d.ts +112 -0
  28. package/dist/VoucherifyError.d.ts +23 -0
  29. package/dist/VoucherifyServerSide.d.ts +170 -0
  30. package/dist/Vouchers.d.ts +84 -0
  31. package/dist/helpers.d.ts +20 -0
  32. package/dist/index.d.ts +63 -0
  33. package/dist/types/ApplicableTo.d.ts +32 -0
  34. package/dist/types/AsyncActions.d.ts +23 -0
  35. package/dist/types/Balance.d.ts +18 -0
  36. package/dist/types/Campaigns.d.ts +124 -0
  37. package/dist/types/Categories.d.ts +40 -0
  38. package/dist/types/ClientSide.d.ts +145 -0
  39. package/dist/types/Consents.d.ts +34 -0
  40. package/dist/types/Customers.d.ts +363 -0
  41. package/dist/types/DiscountVoucher.d.ts +94 -0
  42. package/dist/types/Distributions.d.ts +148 -0
  43. package/dist/types/Events.d.ts +21 -0
  44. package/dist/types/Exports.d.ts +151 -0
  45. package/dist/types/Gift.d.ts +5 -0
  46. package/dist/types/Loyalties.d.ts +1061 -0
  47. package/dist/types/MetadataSchemas.d.ts +34 -0
  48. package/dist/types/Orders.d.ts +199 -0
  49. package/dist/types/ProductCollections.d.ts +99 -0
  50. package/dist/types/Products.d.ts +108 -0
  51. package/dist/types/PromotionTiers.d.ts +131 -0
  52. package/dist/types/Promotions.d.ts +113 -0
  53. package/dist/types/PromotionsStacks.d.ts +74 -0
  54. package/dist/types/Qualifications.d.ts +92 -0
  55. package/dist/types/Redemptions.d.ts +215 -0
  56. package/dist/types/Rewards.d.ts +220 -0
  57. package/dist/types/Segments.d.ts +34 -0
  58. package/dist/types/Stackable.d.ts +106 -0
  59. package/dist/types/UtilityTypes.d.ts +5 -0
  60. package/dist/types/ValidateSession.d.ts +19 -0
  61. package/dist/types/ValidationError.d.ts +9 -0
  62. package/dist/types/ValidationRules.d.ts +96 -0
  63. package/dist/types/Validations.d.ts +109 -0
  64. package/dist/types/Vouchers.d.ts +452 -0
  65. package/dist/types/index.d.ts +27 -0
  66. package/dist/voucherifysdk.cjs +2022 -1
  67. package/dist/voucherifysdk.cjs.map +1 -1
  68. package/dist/voucherifysdk.esm.js +1985 -1
  69. package/dist/voucherifysdk.esm.js.map +1 -1
  70. package/package.json +2 -2
  71. package/dist/voucherifysdk.d.mts +0 -5252
  72. package/dist/voucherifysdk.d.ts +0 -5252
@@ -1,2 +1,1986 @@
1
- var fe=Object.defineProperty;var be=(i,e,t)=>e in i?fe(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var l=(i,e,t)=>be(i,typeof e!="symbol"?e+"":e,t);var Ce=(o=>(o.AMOUNT="AMOUNT",o.PERCENT="PERCENT",o.UNIT="UNIT",o.FIXED="FIXED",o))(Ce||{});import Se from"axios";import ee from"qs";var f=class extends Error{constructor(t,r,o){r=r!=null?r:{};let n=(r==null?void 0:r.message)||Pe(r,t);super(n);l(this,"code");l(this,"key");l(this,"details");l(this,"request_id");l(this,"resource_id");l(this,"resource_type");l(this,"related_object_ids");l(this,"related_object_type");l(this,"related_object_total");l(this,"error");l(this,"cause");this.code=r.code,this.key=r.key,this.details=r.details,this.request_id=r.request_id,this.resource_id=r.resource_id,this.resource_type=r.resource_type,this.related_object_ids=r.related_object_ids,this.related_object_type=r.related_object_type,this.related_object_total=r.related_object_total,this.error=r.error,this.cause=o}};function Pe(i,e){return i=typeof i=="string"?i:JSON.stringify(i,null,2),`Unexpected status code: ${e} - Details: ${i}`}var y=class{constructor({basePath:e,baseURL:t,headers:r,exposeErrorCause:o,timeoutMs:n}){l(this,"baseURL");l(this,"basePath");l(this,"headers");l(this,"request");l(this,"lastResponseHeaders");l(this,"isLastResponseHeadersSet");l(this,"exposeErrorCause");l(this,"timeoutMs");this.basePath=e,this.baseURL=t,this.headers=r,this.exposeErrorCause=o,this.lastResponseHeaders={},this.isLastResponseHeadersSet=!1,this.timeoutMs=n,this.request=Se.create({baseURL:`${this.baseURL}/${this.basePath}/`,allowAbsoluteUrls:!1,headers:this.headers,responseType:"json"}),this.request.interceptors.response.use(void 0,c=>{var g;return(g=c==null?void 0:c.response)!=null&&g.status?Promise.reject(new f(c.response.status,c.response.data,this.exposeErrorCause===!0?c:void 0)):Promise.reject(c)})}isLastReponseHeadersSet(){return this.isLastResponseHeadersSet}getLastResponseHeaders(){return this.lastResponseHeaders}setLastResponseHeaders(e){let t={};for(let r in e)t[r]=String(e[r]);this.lastResponseHeaders=t,this.isLastResponseHeadersSet=!0}setBaseUrl(e){this.baseURL=e,this.request.defaults.baseURL=`${e}/${this.basePath}/`}async get(e,t){let r=await this.request.get(e,{params:t,paramsSerializer:function(o){return ee.stringify(o)},timeout:this.timeoutMs});return this.setLastResponseHeaders(r.headers),r.data}async post(e,t,r,o){let n=await this.request.post(e,t,{params:r,paramsSerializer:function(c){return ee.stringify(c)},headers:o,timeout:this.timeoutMs});return this.setLastResponseHeaders(n.headers),n.data}async put(e,t,r){let o=await this.request.put(e,t,{params:r,timeout:this.timeoutMs});return this.setLastResponseHeaders(o.headers),o.data}async delete(e,t){let r=await this.request.delete(e,{params:t,timeout:this.timeoutMs});return this.setLastResponseHeaders(r.headers),r.data}};function s(i=""){return encodeURIComponent(i)}function u(i){return typeof i=="string"}function T(i){return i==null||u(i)}function d(i){return typeof i=="object"&&!Array.isArray(i)&&i!==null}function Y(i){return i==null||d(i)}function p(){return typeof window!="undefined"&&typeof window.document!="undefined"?"Browser":typeof self=="object"&&self.constructor&&self.constructor.name==="DedicatedWorkerGlobalScope"?"WebWorker":typeof process!="undefined"&&process.versions!=null&&process.versions.node!=null?`Node.js-${process.version}`:typeof window!="undefined"&&window.name==="nodejs"||navigator.userAgent.includes("Node.js")||navigator.userAgent.includes("jsdom")?"JsDom":"Unknown"}function a(i,e){if(!i)throw new Error(e)}function m(i,e){return Object.fromEntries(Object.entries(i).filter(([t])=>!e.includes(t)))}var b=class{constructor(e){this.client=e}get(e){return this.client.get(`/async-actions/${s(e)}`)}list(e){return this.client.get("/async-actions",e)}};import Le from"form-data";var F=class{constructor(e){this.client=e}examine(e={},t){return this.client.post("/campaigns/qualification",e,t)}},C=class{constructor(e){this.client=e;l(this,"qualifications");this.qualifications=new F(this.client)}create(e){return this.client.post("/campaigns",e)}update(e,t){return this.client.put(`/campaigns/${s(e)}`,t)}get(e){return this.client.get(`/campaigns/${s(e)}`)}delete(e,t={}){return this.client.delete(`/campaigns/${s(e)}`,t)}addVoucher(e,t={},r={}){return this.client.post(`/campaigns/${s(e)}/vouchers`,t,r)}addCertainVoucher(e,t,r={}){return this.client.post(`/campaigns/${s(e)}/vouchers/${s(t)}`,r)}importVouchers(e,t){return this.client.post(`/campaigns/${s(e)}/import`,t)}list(e={}){return this.client.get("/campaigns",e)}async importVouchersCSV(e,t){a(p().startsWith("Node"),'Method "client.campaigns.importVouchersCSV(campaignId, filePath)" is only for Node environment');let o=(await import("fs")).default.createReadStream(t),n=new Le;n.append("file",o);let c={"Content-Type":"multipart/form-data"};return this.client.post(`/campaigns/${e}/importCSV`,n,void 0,c)}enable(e){return this.client.post(`/campaigns/${s(e)}/enable`,{})}disable(e){return this.client.post(`/campaigns/${s(e)}/disable`,{})}};var X=class{constructor(e){this.client=e}list(e={}){return this.client.get("/publications",e)}create(e){return this.client.post("/publications",e)}},P=class{constructor(e,t){this.client=e;this.exports=t;l(this,"publications");this.publications=new X(this.client)}};var S=class{constructor(e){this.client=e}create(e){return this.client.post("/exports",e)}list(e={}){return this.client.get("/exports",e)}get(e){return this.client.get(`/exports/${s(e)}`)}delete(e){return this.client.delete(`/exports/${s(e)}`)}};var L=class{constructor(e){this.client=e}create(e,t){return t={...t,event:e},this.client.post("/events",t)}};var _=class{constructor(e){this.client=e}create(e,t){return this.client.post(`/vouchers/${s(e)}/balance`,t)}};import _e from"form-data";var K=class{constructor(e){this.client=e}examine(e,t={}){return this.client.post("/vouchers/qualification",e,t)}},A=class{constructor(e,t){this.client=e;this.balance=t;l(this,"qualifications");this.qualifications=new K(this.client)}create(e){return this.client.post(`/vouchers/${s(e.code)}`,e)}get(e){return this.client.get(`/vouchers/${s(e)}`)}update(e){return this.client.put(`/vouchers/${s(e.code)}`,e)}delete(e,t={}){return this.client.delete(`/vouchers/${s(e)}`,t)}list(e={}){return this.client.get("/vouchers",e)}enable(e){return this.client.post(`/vouchers/${s(e)}/enable`,{})}disable(e){return this.client.post(`/vouchers/${s(e)}/disable`,{})}import(e){return this.client.post("/vouchers/import",e)}bulkUpdateMetadata(e){return this.client.post("/vouchers/metadata/async",e)}bulkUpdate(e){return this.client.post("/vouchers/bulk/async",e)}releaseValidationSession(e,t){return this.client.delete(`/vouchers/${s(e)}/sessions/${s(t)}`)}async importCSV(e){a(p().startsWith("Node"),'Method "client.vouchers.importCSV(filePath)" is only for Node environment');let r=(await import("fs")).default.createReadStream(e),o=new _e;o.append("file",r);let n={"Content-Type":"multipart/form-data"};return this.client.post("/vouchers/importCSV",o,void 0,n)}listTransactions(e,t){return this.client.get(`/vouchers/${s(e)}/transactions`,t)}exportTransactions(e,t){return this.client.post(`/vouchers/${s(e)}/transactions/export`,t)}};var x=class{constructor(e,t){this.client=e;this.promotions=t}validateVoucher(e,t={}){return this.client.post(`/vouchers/${s(e)}/validate`,t)}validate(e,t={}){return d(e)?this.promotions.validate(e):this.validateVoucher(e,t)}validateStackable(e){return this.client.post("/validations",e)}};var $=class{constructor(e){this.client=e}redeem(e,t={}){return this.client.post(`/vouchers/${s(e)}/redemption`,t)}redeemStackable(e){return this.client.post("/redemptions",e)}get(e){return this.client.get(`/redemptions/${s(e)}`)}list(e={}){return this.client.get("/redemptions",e)}getForVoucher(e){return this.client.get(`/vouchers/${s(e)}/redemption`)}rollback(e,t){let r={},o={};if(u(t))r.reason=t;else if(d(t)){let{reason:n,tracking_id:c,customer:g}=t;r={reason:n||void 0,tracking_id:c||void 0},o={customer:g}}return this.client.post(`/redemptions/${s(e)}/rollback`,o,r)}rollbackStackable(e,t,r){return this.client.post(`/redemptions/${s(e)}/rollbacks`,t,r)}};var v=class{constructor(e){this.client=e}listAll(e={}){return this.client.get("/promotions/tiers",e)}list(e){return this.client.get(`/promotions/${s(e)}/tiers`)}get(e){return this.client.get(`/promotions/tiers/${s(e)}`)}create(e,t){return this.client.post(`/promotions/${s(e)}/tiers`,t)}redeem(e,t){return this.client.post(`/promotions/tiers/${s(e)}/redemption`,t)}update(e){return this.client.put(`/promotions/tiers/${s(e.id)}`,e)}delete(e){return this.client.delete(`/promotions/tiers/${s(e)}`)}};var V=class{constructor(e,t,r){this.client=e;this.tiers=t;this.stack=r}create(e){return this.client.post("/campaigns",e)}validate(e,t){return this.client.post("/promotions/validation",e,t)}};import Ae from"form-data";var q=class{constructor(e){this.client=e}create(e){return this.client.post("/customers",e)}get(e){return this.client.get(`/customers/${s(e)}`)}list(e){return this.client.get("/customers",e)}async*scroll(e){var o;let t=(o=e.starting_after)!=null?o:e.order==="created_at"?"1970-01-01T00:00:00Z":"2200-01-01T00:00:00Z",r=await this.client.get("/customers",Object.assign({},e,{starting_after:t}));for(;r.customers.length!==0;){for(let n of r.customers)e.order==="created_at"?t=t>n.created_at?t:n.created_at:t=t<n.created_at?t:n.created_at,yield n;if(!r.has_more)break;r=await this.client.get("/customers",Object.assign({},e,{starting_after:t}))}}update(e){let t="id"in e?e.id:e.source_id,r=m(e,["id"]);return this.client.put(`/customers/${s(t)}`,r)}updateInBulk(e){return this.client.post("/customers/bulk/async",e)}updateMetadataInBulk(e){return this.client.post("/customers/metadata/async",e)}delete(e){return this.client.delete(`/customers/${s(e)}`)}deletePermanently(e){return this.client.post(`/customers/${s(e)}/permanent-deletion`,{})}listActivity(e,t){return this.client.get(`/customers/${s(e)}/activity`,t)}updateConsents(e,t){return this.client.put(`/customers/${s(e)}/consents`,t)}listActivities(e,t){return this.client.get(`/customers/${s(e)}/activities`,t)}async importCSV(e){a(p().startsWith("Node"),'Method "client.customers.importCSV(filePath)" is only for Node environment');let r=(await import("fs")).default.createReadStream(e),o=new Ae;o.append("file",r);let n={"Content-Type":"multipart/form-data"};return this.client.post("/customers/importCSV",o,void 0,n)}listRedeemables(e,t){return this.client.get(`/customers/${s(e)}/redeemables`,t)}};var k=class{constructor(e){this.client=e}list(){return this.client.get("/consents")}};var w=class{constructor(e){this.client=e}create(e){return this.client.post("/orders",e)}get(e){return this.client.get(`/orders/${s(e)}`)}update(e){return this.client.put(`/orders/${s(e.id||e.source_id)}`,m(e,["id"]))}list(e={}){return this.client.get("/orders",e)}import(e){return this.client.post("/orders/import",e)}};import te from"form-data";var E=class{constructor(e){this.client=e}create(e){return this.client.post("/products",e)}get(e){return this.client.get(`/products/${s(e)}`)}update(e){return this.client.put(`/products/${s(e.id||e.source_id)}`,m(e,["id"]))}bulkUpdateMetadata(e){return this.client.post("/products/metadata/async",e)}bulkUpdate(e){return this.client.post("/products/bulk/async",e)}delete(e,t){return this.client.delete(`/products/${s(e)}`,t)}list(e){return this.client.get("/products",e)}createSku(e,t){return this.client.post(`/products/${s(e)}/skus`,t)}getSku(e){return this.client.get(`/skus/${s(e)}`)}updateSku(e,t){return this.client.put(`/products/${s(e)}/skus/${s(t.id||t.source_id)}`,m(t,["id"]))}deleteSku(e,t,r){return this.client.delete(`/products/${s(e)}/skus/${s(t)}`,r)}listSkus(e){return this.client.get(`/products/${s(e)}/skus`)}async importSkusCSV(e){a(p().startsWith("Node"),'Method "client.products.importSkusCSV(filePath)" is only for Node environment');let r=(await import("fs")).default.createReadStream(e),o=new te;o.append("file",r);let n={"Content-Type":"multipart/form-data"};return this.client.post("/skus/importCSV",o,void 0,n)}async importCSV(e){a(p().startsWith("Node"),'Method "client.products.importCSV(filePath)" is only for Node environment');let r=(await import("fs")).default.createReadStream(e),o=new te;o.append("file",r);let n={"Content-Type":"multipart/form-data"};return this.client.post("/products/importCSV",o,void 0,n)}};var U=class{constructor(e){this.client=e}list(e={}){return this.client.get("/rewards",e)}create(e){return this.client.post("/rewards",e)}get(e){return this.client.get(`/rewards/${s(e)}`)}update(e){return this.client.put(`/rewards/${s(e.id)}`,m(e,["id"]))}delete(e){return this.client.delete(`/rewards/${s(e)}`)}getAssignment(e,t){return this.client.get(`/rewards/${s(e)}/assignments/${s(t)}`)}listAssignments(e,t={}){return this.client.get(`/rewards/${s(e)}/assignments`,t)}createAssignment(e,t){return this.client.post(`/rewards/${s(e)}/assignments`,t)}updateAssignment(e,t){return this.client.put(`/rewards/${s(e)}/assignments/${s(t.id)}`,m(t,["id"]))}deleteAssignment(e,t){return this.client.delete(`/rewards/${s(e)}/assignments/${s(t)}`)}};var B=class{constructor(e){this.client=e}list(e={}){return this.client.get("/loyalties",e)}create(e){return this.client.post("/loyalties",e)}get(e){return this.client.get(`/loyalties/${s(e)}`)}update(e){return this.client.put(`/loyalties/${s(e.id)}`,m(e,["id"]))}delete(e,t){return this.client.delete(`/loyalties/${s(e)}`,t)}listRewardAssignments(e,t={}){return this.client.get(`/loyalties/${s(e)}/rewards`,t)}createRewardAssignments(e,t){return this.client.post(`/loyalties/${s(e)}/rewards`,t)}updateRewardAssignment(e,t){return this.client.put(`/loyalties/${s(e)}/rewards/${t.id}`,m(t,["id"]))}deleteRewardAssignment(e,t){return this.client.delete(`/loyalties/${s(e)}/rewards/${t}`)}getRewardAssignment(e,t){return this.client.get(`/loyalties/${s(e)}/rewards/${s(t)}`)}listEarningRules(e,t={}){return this.client.get(`/loyalties/${s(e)}/earning-rules`,t)}createEarningRule(e,t){return this.client.post(`/loyalties/${s(e)}/earning-rules`,t)}updateEarningRule(e,t){return this.client.put(`/loyalties/${s(e)}/earning-rules/${t.id}`,m(t,["id"]))}deleteEarningRule(e,t){return this.client.delete(`/loyalties/${s(e)}/earning-rules/${t}`)}getEarningRule(e,t){return this.client.get(`/loyalties/${s(e)}/earning-rules/${s(t)}`)}enableEarningRule(e,t){return this.client.post(`/loyalties/${s(e)}/earning-rules/${t}/enable`,{})}disableEarningRule(e,t){return this.client.post(`/loyalties/${s(e)}/earning-rules/${t}/disable`,{})}listMembers(e,t){return this.client.get(`/loyalties/${s(e)}/members`,t)}createMember(e,t){return this.client.post(`/loyalties/${s(e)}/members`,t)}getMember(e,t){return this.client.get(e?`/loyalties/${s(e)}/members/${t}`:`/loyalties/members/${t}`)}listMemberActivity(e,t,r){return this.client.get(e?`/loyalties/${s(e)}/members/${t}/activity`:`/loyalties/members/${t}/activity`,r)}getMemberActivities(e,t){return this.client.get(e?`/loyalties/${s(e)}/members/${t}/activities`:`/loyalties/members/${t}/activities`)}listMemberRewards(e,t){return this.client.get(`/loyalties/members/${s(e)}/rewards`,t)}addOrRemoveCardBalance(e,t,r){return this.client.post(r?`/loyalties/${s(r)}/members/${e}/balance`:`/loyalties/members/${e}/balance`,t)}addPoints(e,t,r){return this.client.post(`/loyalties/${s(e)}/members/${t}/balance`,r)}transferPoints(e,t,r){return this.client.post(`/loyalties/${s(e)}/members/${s(t)}/transfers`,r)}getPointsExpiration(e,t,r){return this.client.get(`/loyalties/${s(e)}/members/${t}/points-expiration`,r)}redeemReward(e,t,r){return this.client.post(`/loyalties/${s(e)}/members/${s(t)}/redemption`,r)}listLoyaltyTierRewards(e,t){return this.client.get(`/loyalties/${s(e)}/tiers/${s(t)}/rewards`)}listCardTransactions(e,t,r){return this.client.get(t?`/loyalties/${s(t)}/members/${s(e)}/transactions`:`/loyalties/members/${s(e)}/transactions`,r)}exportCardTransactions(e,t,r={}){return this.client.post(t?`/loyalties/${s(t)}/members/${s(e)}/transactions/export`:`/loyalties/members/${s(e)}/transactions/export`,r)}getRewardDetails(e,t){return this.client.get(`/loyalties/${s(e)}/reward-assignments/${s(t)}/reward`)}listTiers(e,t){return this.client.get(`/loyalties/${s(e)}/tiers`,t)}getTier(e,t){return this.client.get(`/loyalties/${s(e)}/tiers/${s(t)}`)}createTiers(e,t){return this.client.post(`/loyalties/${s(e)}/tiers`,t)}listLoyaltyTierEarningRules(e,t,r){return this.client.get(`/loyalties/${s(e)}/tiers/${s(t)}/earning-rules`,r)}listMemberLoyaltyTiers(e){return this.client.get(`/loyalties/members/${s(e)}/tiers`)}};var D=class{constructor(e){this.client=e}create(e){return this.client.post("/validation-rules",e)}get(e){return this.client.get(`/validation-rules/${s(e)}`)}update(e){return this.client.put(`/validation-rules/${s(e.id)}`,m(e,["id"]))}delete(e){return this.client.delete(`/validation-rules/${s(e)}`)}createAssignment(e,t){return this.client.post(`/validation-rules/${s(e)}/assignments`,t)}deleteAssignment(e,t){return this.client.delete(`/validation-rules/${s(e)}/assignments/${s(t)}`)}validate(e,t={}){return this.client.post(`/validation-rules/${s(e)}/validation`,t)}list(e={}){return this.client.get("/validation-rules",e)}listRulesAssignments(e={}){return this.client.get("/validation-rules-assignments",e)}listAssignments(e,t={}){return this.client.get(`/validation-rules/${s(e)}/assignments`,t)}};var I=class{constructor(e){this.client=e}create(e){return this.client.post("/segments",e)}get(e){return this.client.get(`/segments/${s(e)}`)}delete(e){return this.client.delete(`/segments/${s(e)}`)}list(e){return this.client.get(`/customers/${s(e)}/segments`)}};var O=class{constructor(e){this.requestController=e}getLastResponseHeadersFromController(){return this.requestController.getLastResponseHeaders()}areLimitsAvailable(){return this.requestController.isLastReponseHeadersSet()}getRateLimit(){var t;let e=(t=this.getLastResponseHeadersFromController()["x-rate-limit-limit"])!=null?t:0;return parseInt(e,10)}getRateLimitRemaining(){var t;let e=(t=this.getLastResponseHeadersFromController()["x-rate-limit-remaining"])!=null?t:0;return parseInt(e,10)}getRetryAfter(){var t;let e=(t=this.getLastResponseHeadersFromController()["retry-after"])!=null?t:0;return parseInt(e,10)}};var M=class{constructor(e){this.client=e}list(){return this.client.get("/metadata-schemas")}get(e){return this.client.get(`/metadata-schemas/${s(e)}`)}};var N=class{constructor(e){this.client=e}list(e={}){return this.client.get("/categories",e)}create(e){return this.client.post("/categories",e)}get(e){return this.client.get(`/categories/${s(e)}`)}delete(e){return this.client.delete(`/categories/${s(e)}`)}update(e,t){return this.client.put(`/categories/${s(e)}`,t)}};var j=class{constructor(e){this.client=e}listInCampaign(e){return this.client.get(`/promotions/${e}/stacks`)}createInCampaign(e,t){return this.client.post(`/promotions/${e}/stacks`,t)}delete(e,t){return this.client.delete(`/promotions/${e}/stacks/${t}`)}get(e,t){return this.client.get(`/promotions/${e}/stacks/${t}`)}update(e,t,r){return this.client.put(`/promotions/${e}/stacks/${t}`,r)}list(e){return this.client.get("/promotions/stacks",e)}};var Q=class{constructor(e){this.client=e}create(e){return this.client.post("/product-collections",e)}list(e){return this.client.get("/product-collections",e)}delete(e){return this.client.delete(`/product-collections/${s(e)}`)}get(e){return this.client.get(`/product-collections/${s(e)}`)}listProducts(e,t){return this.client.get(`/product-collections/${s(e)}/products`,t)}};var H=class{constructor(e){this.client=e}checkEligibility(e){return this.client.post("/qualifications",e)}};function cs(i){var z,J,Z;a(d(i),'VoucherifyServerSide: the "options" argument must be an object'),a(u(i.applicationId),'VoucherifyServerSide: "options.applicationId" is required'),a(u(i.secretKey),'VoucherifyServerSide: "options.secretKey" is required'),a(T(i.apiVersion),'VoucherifyServerSide: expected "options.apiVersion" to be a string'),a(T(i.channel),'VoucherifyServerSide: expected "options.channel" to be a string');let e={"X-App-Id":i.applicationId,"X-App-Token":i.secretKey,"X-Voucherify-Channel":i.channel||`${p()}-SDK-v2.9.3`,"Content-Type":"application/json"};i.apiVersion&&(e["X-Voucherify-API-Version"]=i.apiVersion),d(i.customHeaders)&&(e=Object.assign({},e,i.customHeaders)),p().startsWith("Node")||a(i.dangerouslySetSecretKeyInBrowser===!0,`VoucherifyServerSide: you're exposing your secretKey to a ${p().toLowerCase()} environment. This is generally considered a bad practice. Did you mean to use 'VoucherifyClientSide'?`);let t=new y({basePath:"v1",baseURL:(z=i.apiUrl)!=null?z:"https://api.voucherify.io",headers:e,exposeErrorCause:(J=i.exposeErrorCause)!=null?J:!1,timeoutMs:(Z=i.timeoutMs)!=null?Z:0}),r=new b(t),o=new _(t),n=new A(t,o),c=new C(t),g=new N(t),R=new S(t),h=new L(t),se=new P(t,R),re=new v(t),ie=new j(t),W=new V(t,re,ie),oe=new x(t,W),ne=new $(t),ae=new H(t),le=new q(t),ce=new k(t),ue=new w(t),pe=new E(t),me=new Q(t),de=new U(t),ge=new B(t),Te=new I(t),Re=new D(t),ye=new O(t),he=new M(t);return{vouchers:n,campaigns:c,categories:g,distributions:se,validations:oe,redemptions:ne,promotions:W,customers:le,consents:ce,orders:ue,products:pe,productCollections:me,qualifications:ae,rewards:de,loyalties:ge,segments:Te,validationRules:Re,events:h,asyncActions:r,apiLimitsHandler:ye,metadataSchemas:he}}var G=class{constructor(e,t){this.client=e;this.trackingId=t}setIdentity(e){this.trackingId=e}validate(e){var o,n;a(d(e)||u(e),'client.validate: expected "params" argument to be an object or a string');let t={};u(e)?t.code=e:(t.code=e.code,t.item=e.items,t.amount=e.amount,t.metadata=e.metadata,t.order={metadata:e.orderMetadata},t.customer=e.customer,t.tracking_id=e.tracking_id||this.trackingId,t.session_type=e.session_type,t.session_key=e.session_key,t.session_ttl=e.session_ttl,t.session_ttl_unit=e.session_ttl_unit),t.code&&(t.code=t.code.replace(/[\r\n\t\f\v]/g,"").trim()),a(Y(t==null?void 0:t.customer),'client.validate: expected "params.customer" to be an object'),a(T((o=t==null?void 0:t.customer)==null?void 0:o.source_id),'client.validate: expected "params.customer.source_id" to be a string'),a(Y((n=t==null?void 0:t.customer)==null?void 0:n.metadata),'client.validate: expected "params.customer.metadata" to be an object');let r=t.code?"/validate":"/promotions/validation";return this.client.get(r,t)}redeem(e,t={}){var r,o;return a(u(e),"client.redeem - please provide a valid Voucher code"),e=e.replace(/[\r\n\t\f\v]/g,"").trim(),t.customer=(r=t.customer)!=null?r:{},t.customer.source_id=(o=t.customer.source_id)!=null?o:this.trackingId,this.client.post("/redeem",t,{code:e})}publish(e,t={},r={}){var n,c,g,R,h;a(d(t),"client.publish - expected payload to be an object");let o={};return o.customer=(n=t.customer)!=null?n:{},o.customer.source_id=(g=(c=t.customer)==null?void 0:c.source_id)!=null?g:this.trackingId,o.channel=(R=t.channel)!=null?R:"Voucherify.js",a(u((h=o.customer)==null?void 0:h.source_id),"client.publish - expected payload to contain customer source id or to have tracking id set up by Voucherify client"),r.campaign=e.replace(/[\r\n\t\f\v]/g,"").trim(),this.client.post("/publish",o,r)}track(e,t,r,o,n){var g,R;a(u(e),"client.track - expected event name to be an string"),a(d(t),"client.track - expected customer to be an object");let c={event:e,metadata:r!=null?r:{},customer:t,referral:o!=null?o:void 0,loyalty:n!=null?n:void 0};return c.customer.source_id=(g=t.source_id)!=null?g:this.trackingId,a(u((R=c.customer)==null?void 0:R.source_id),"client.track - expected payload to contain customer source id or to have tracking id set up by Voucherify client"),this.client.post("/events",c)}listVouchers(e={}){let t={};return t.campaign=e.campaign,t.category=e.category,t.page=e.page,t.limit=e.limit,t.customer=e.customer,t.created_at=e.created_at,t.updated_at=e.updated_at,this.client.get("/vouchers",t)}createCustomer(e,t){return this.client.post("/customers",e,{},t?{"X-Voucherify-Double-Opt-In":!0}:{})}listConsents(){return this.client.get("/consents")}updateConsents(e,t){return this.client.put(`/customers/${s(e)}/consents`,t)}validateStackable(e){return this.client.post("/validations",e)}redeemStackable(e){return this.client.post("/redemptions",e)}qualifications(e){return this.client.post("/qualifications",e)}};function Rs(i){var r,o,n;a(d(i),'VoucherifyCustomer: expected "options" argument to be an object'),a(u(i.clientApplicationId),'VoucherifyCustomer: "options.clientApplicationId" is required'),a(u(i.clientSecretKey),'VoucherifyCustomer: "options.clientSecretKey" is required'),a(T(i.apiUrl),'VoucherifyCustomer: expected "options.baseUrl" to be a string'),a(T(i.trackingId),'VoucherifyCustomer: expected "options.trackingId" to be a string');let e={"X-Client-Application-Id":i.clientApplicationId,"X-Client-Token":i.clientSecretKey,"X-Voucherify-Channel":`${p()}-ClientSide-SDK-v2.9.3`};p().startsWith("Node")&&(a(u(i.origin),'VoucherifyCustomer: "options.origin" is required in Node.js'),e.origin=i.origin),d(i.customHeaders)&&(e=Object.assign({},e,i.customHeaders));let t=new y({basePath:"client/v1",baseURL:(r=i.apiUrl)!=null?r:"https://api.voucherify.io",headers:e,exposeErrorCause:(o=i.exposeErrorCause)!=null?o:!1,timeoutMs:(n=i.timeoutMs)!=null?n:0});return new G(t,i.trackingId)}export{Ce as DiscountVouchersTypesEnum,Rs as VoucherifyClientSide,cs as VoucherifyServerSide};
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
4
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+
6
+ // src/types/DiscountVoucher.ts
7
+ var DiscountVouchersTypesEnum = /* @__PURE__ */ ((DiscountVouchersTypesEnum2) => {
8
+ DiscountVouchersTypesEnum2["AMOUNT"] = "AMOUNT";
9
+ DiscountVouchersTypesEnum2["PERCENT"] = "PERCENT";
10
+ DiscountVouchersTypesEnum2["UNIT"] = "UNIT";
11
+ DiscountVouchersTypesEnum2["FIXED"] = "FIXED";
12
+ return DiscountVouchersTypesEnum2;
13
+ })(DiscountVouchersTypesEnum || {});
14
+
15
+ // src/RequestController.ts
16
+ import axios from "axios";
17
+ import Qs from "qs";
18
+
19
+ // src/VoucherifyError.ts
20
+ var _VoucherifyError = class _VoucherifyError extends Error {
21
+ constructor(statusCode, body, axiosError) {
22
+ body = body != null ? body : {};
23
+ const message = (body == null ? void 0 : body.message) || generateMessage(body, statusCode);
24
+ super(message);
25
+ __publicField(this, "code");
26
+ __publicField(this, "key");
27
+ __publicField(this, "details");
28
+ __publicField(this, "request_id");
29
+ __publicField(this, "resource_id");
30
+ __publicField(this, "resource_type");
31
+ __publicField(this, "related_object_ids");
32
+ __publicField(this, "related_object_type");
33
+ __publicField(this, "related_object_total");
34
+ __publicField(this, "error");
35
+ __publicField(this, "cause");
36
+ this.code = body.code;
37
+ this.key = body.key;
38
+ this.details = body.details;
39
+ this.request_id = body.request_id;
40
+ this.resource_id = body.resource_id;
41
+ this.resource_type = body.resource_type;
42
+ this.related_object_ids = body.related_object_ids;
43
+ this.related_object_type = body.related_object_type;
44
+ this.related_object_total = body.related_object_total;
45
+ this.error = body.error;
46
+ this.cause = axiosError;
47
+ }
48
+ };
49
+ __name(_VoucherifyError, "VoucherifyError");
50
+ var VoucherifyError = _VoucherifyError;
51
+ function generateMessage(body, statusCode) {
52
+ body = typeof body === "string" ? body : JSON.stringify(body, null, 2);
53
+ return `Unexpected status code: ${statusCode} - Details: ${body}`;
54
+ }
55
+ __name(generateMessage, "generateMessage");
56
+
57
+ // src/RequestController.ts
58
+ var _RequestController = class _RequestController {
59
+ constructor({ basePath, baseURL, headers, exposeErrorCause, timeoutMs }) {
60
+ __publicField(this, "baseURL");
61
+ __publicField(this, "basePath");
62
+ __publicField(this, "headers");
63
+ __publicField(this, "request");
64
+ __publicField(this, "lastResponseHeaders");
65
+ __publicField(this, "isLastResponseHeadersSet");
66
+ __publicField(this, "exposeErrorCause");
67
+ __publicField(this, "timeoutMs");
68
+ this.basePath = basePath;
69
+ this.baseURL = baseURL;
70
+ this.headers = headers;
71
+ this.exposeErrorCause = exposeErrorCause;
72
+ this.lastResponseHeaders = {};
73
+ this.isLastResponseHeadersSet = false;
74
+ this.timeoutMs = timeoutMs;
75
+ this.request = axios.create({
76
+ baseURL: `${this.baseURL}/${this.basePath}/`,
77
+ allowAbsoluteUrls: false,
78
+ headers: this.headers,
79
+ responseType: "json"
80
+ });
81
+ this.request.interceptors.response.use(void 0, (error) => {
82
+ var _a;
83
+ if ((_a = error == null ? void 0 : error.response) == null ? void 0 : _a.status) {
84
+ return Promise.reject(
85
+ new VoucherifyError(
86
+ error.response.status,
87
+ error.response.data,
88
+ this.exposeErrorCause === true ? error : void 0
89
+ )
90
+ );
91
+ }
92
+ return Promise.reject(error);
93
+ });
94
+ }
95
+ isLastReponseHeadersSet() {
96
+ return this.isLastResponseHeadersSet;
97
+ }
98
+ getLastResponseHeaders() {
99
+ return this.lastResponseHeaders;
100
+ }
101
+ setLastResponseHeaders(headers) {
102
+ const result = {};
103
+ for (const key in headers) {
104
+ result[key] = String(headers[key]);
105
+ }
106
+ this.lastResponseHeaders = result;
107
+ this.isLastResponseHeadersSet = true;
108
+ }
109
+ setBaseUrl(baseURL) {
110
+ this.baseURL = baseURL;
111
+ this.request.defaults.baseURL = `${baseURL}/${this.basePath}/`;
112
+ }
113
+ async get(path, params) {
114
+ const response = await this.request.get(path, {
115
+ params,
116
+ paramsSerializer: /* @__PURE__ */ __name(function(params2) {
117
+ return Qs.stringify(params2);
118
+ }, "paramsSerializer"),
119
+ timeout: this.timeoutMs
120
+ });
121
+ this.setLastResponseHeaders(response.headers);
122
+ return response.data;
123
+ }
124
+ async post(path, body, params, headers) {
125
+ const response = await this.request.post(path, body, {
126
+ params,
127
+ paramsSerializer: /* @__PURE__ */ __name(function(params2) {
128
+ return Qs.stringify(params2);
129
+ }, "paramsSerializer"),
130
+ headers,
131
+ timeout: this.timeoutMs
132
+ });
133
+ this.setLastResponseHeaders(response.headers);
134
+ return response.data;
135
+ }
136
+ async put(path, body, params) {
137
+ const response = await this.request.put(path, body, { params, timeout: this.timeoutMs });
138
+ this.setLastResponseHeaders(response.headers);
139
+ return response.data;
140
+ }
141
+ async delete(path, params) {
142
+ const response = await this.request.delete(path, { params, timeout: this.timeoutMs });
143
+ this.setLastResponseHeaders(response.headers);
144
+ return response.data;
145
+ }
146
+ };
147
+ __name(_RequestController, "RequestController");
148
+ var RequestController = _RequestController;
149
+
150
+ // src/helpers.ts
151
+ function encode(value = "") {
152
+ return encodeURIComponent(value);
153
+ }
154
+ __name(encode, "encode");
155
+ function isString(value) {
156
+ return typeof value === "string";
157
+ }
158
+ __name(isString, "isString");
159
+ function isOptionalString(value) {
160
+ return value == null || isString(value);
161
+ }
162
+ __name(isOptionalString, "isOptionalString");
163
+ function isObject(value) {
164
+ return typeof value === "object" && !Array.isArray(value) && value !== null;
165
+ }
166
+ __name(isObject, "isObject");
167
+ function isOptionalObject(value) {
168
+ return value == null || isObject(value);
169
+ }
170
+ __name(isOptionalObject, "isOptionalObject");
171
+ function environment() {
172
+ if (typeof window !== "undefined" && typeof window.document !== "undefined") {
173
+ return "Browser";
174
+ } else if (typeof self === "object" && self.constructor && self.constructor.name === "DedicatedWorkerGlobalScope") {
175
+ return "WebWorker";
176
+ } else if (typeof process !== "undefined" && process.versions != null && process.versions.node != null) {
177
+ return `Node.js-${process.version}`;
178
+ } else if (typeof window !== "undefined" && window.name === "nodejs" || navigator.userAgent.includes("Node.js") || navigator.userAgent.includes("jsdom")) {
179
+ return "JsDom";
180
+ }
181
+ return "Unknown";
182
+ }
183
+ __name(environment, "environment");
184
+ function assert(condition, message) {
185
+ if (condition) return;
186
+ throw new Error(message);
187
+ }
188
+ __name(assert, "assert");
189
+ function omit(obj, keys) {
190
+ return Object.fromEntries(
191
+ Object.entries(obj).filter(([propertyKey]) => {
192
+ return !keys.includes(propertyKey);
193
+ })
194
+ );
195
+ }
196
+ __name(omit, "omit");
197
+
198
+ // src/AsyncActions.ts
199
+ var _AsyncActions = class _AsyncActions {
200
+ constructor(client) {
201
+ this.client = client;
202
+ }
203
+ /**
204
+ * @see https://docs.voucherify.io/reference/get-async-actions-1
205
+ */
206
+ get(asyncActionId) {
207
+ return this.client.get(`/async-actions/${encode(asyncActionId)}`);
208
+ }
209
+ /**
210
+ * @see https://docs.voucherify.io/reference/list-async-actions
211
+ */
212
+ list(params) {
213
+ return this.client.get("/async-actions", params);
214
+ }
215
+ };
216
+ __name(_AsyncActions, "AsyncActions");
217
+ var AsyncActions = _AsyncActions;
218
+
219
+ // src/Campaigns.ts
220
+ import FormData from "form-data";
221
+ var _CampaignsQualifications = class _CampaignsQualifications {
222
+ constructor(client) {
223
+ this.client = client;
224
+ }
225
+ examine(body = {}, params) {
226
+ return this.client.post("/campaigns/qualification", body, params);
227
+ }
228
+ };
229
+ __name(_CampaignsQualifications, "CampaignsQualifications");
230
+ var CampaignsQualifications = _CampaignsQualifications;
231
+ var _Campaigns = class _Campaigns {
232
+ constructor(client) {
233
+ this.client = client;
234
+ __publicField(this, "qualifications");
235
+ this.qualifications = new CampaignsQualifications(this.client);
236
+ }
237
+ /**
238
+ * @see https://docs.voucherify.io/reference/create-campaign
239
+ */
240
+ create(campaign) {
241
+ return this.client.post("/campaigns", campaign);
242
+ }
243
+ /**
244
+ * @see https://docs.voucherify.io/reference/update-campaign
245
+ */
246
+ update(nameOrId, campaign) {
247
+ return this.client.put(`/campaigns/${encode(nameOrId)}`, campaign);
248
+ }
249
+ /**
250
+ * @see https://docs.voucherify.io/reference/get-campaign
251
+ */
252
+ get(name) {
253
+ return this.client.get(`/campaigns/${encode(name)}`);
254
+ }
255
+ /**
256
+ * @see https://docs.voucherify.io/reference/delete-campaign
257
+ */
258
+ delete(name, params = {}) {
259
+ return this.client.delete(`/campaigns/${encode(name)}`, params);
260
+ }
261
+ /**
262
+ * @see https://docs.voucherify.io/reference/add-voucher-to-campaign
263
+ */
264
+ addVoucher(name, body = {}, params = {}) {
265
+ return this.client.post(`/campaigns/${encode(name)}/vouchers`, body, params);
266
+ }
267
+ /**
268
+ * @see https://docs.voucherify.io/reference/add-voucher-with-certain-code-to-campaign
269
+ */
270
+ addCertainVoucher(name, code, body = {}) {
271
+ return this.client.post(
272
+ `/campaigns/${encode(name)}/vouchers/${encode(code)}`,
273
+ body
274
+ );
275
+ }
276
+ /**
277
+ * @see https://docs.voucherify.io/reference/import-vouchers
278
+ */
279
+ importVouchers(campaignName, vouchers) {
280
+ return this.client.post(`/campaigns/${encode(campaignName)}/import`, vouchers);
281
+ }
282
+ /**
283
+ * @see https://docs.voucherify.io/reference/list-campaigns
284
+ */
285
+ list(params = {}) {
286
+ return this.client.get("/campaigns", params);
287
+ }
288
+ /**
289
+ * @see https://api.voucherify.io/v1/campaigns/{campaignId}/importCSV
290
+ */
291
+ async importVouchersCSV(campaignId, filePath) {
292
+ assert(
293
+ environment().startsWith("Node"),
294
+ `Method "client.campaigns.importVouchersCSV(campaignId, filePath)" is only for Node environment`
295
+ );
296
+ const fs = (await import("fs")).default;
297
+ const fileStream = fs.createReadStream(filePath);
298
+ const form = new FormData();
299
+ form.append("file", fileStream);
300
+ const headers = { "Content-Type": "multipart/form-data" };
301
+ return this.client.post(
302
+ `/campaigns/${campaignId}/importCSV`,
303
+ form,
304
+ void 0,
305
+ headers
306
+ );
307
+ }
308
+ /**
309
+ * @see https://docs.voucherify.io/reference/enable-campaign
310
+ */
311
+ enable(campaignId) {
312
+ return this.client.post(`/campaigns/${encode(campaignId)}/enable`, {});
313
+ }
314
+ /**
315
+ * @see https://docs.voucherify.io/reference/disable-campaign
316
+ */
317
+ disable(campaignId) {
318
+ return this.client.post(`/campaigns/${encode(campaignId)}/disable`, {});
319
+ }
320
+ };
321
+ __name(_Campaigns, "Campaigns");
322
+ var Campaigns = _Campaigns;
323
+
324
+ // src/Distributions.ts
325
+ var _DistributionsPublications = class _DistributionsPublications {
326
+ constructor(client) {
327
+ this.client = client;
328
+ }
329
+ /**
330
+ * @see https://docs.voucherify.io/reference/list-publications
331
+ */
332
+ list(params = {}) {
333
+ return this.client.get("/publications", params);
334
+ }
335
+ /**
336
+ * @see https://docs.voucherify.io/reference/create-publication
337
+ */
338
+ create(params) {
339
+ return this.client.post("/publications", params);
340
+ }
341
+ };
342
+ __name(_DistributionsPublications, "DistributionsPublications");
343
+ var DistributionsPublications = _DistributionsPublications;
344
+ var _Distributions = class _Distributions {
345
+ constructor(client, exports) {
346
+ this.client = client;
347
+ this.exports = exports;
348
+ __publicField(this, "publications");
349
+ this.publications = new DistributionsPublications(this.client);
350
+ }
351
+ };
352
+ __name(_Distributions, "Distributions");
353
+ var Distributions = _Distributions;
354
+
355
+ // src/Exports.ts
356
+ var _Exports = class _Exports {
357
+ constructor(client) {
358
+ this.client = client;
359
+ }
360
+ /**
361
+ * @see https://docs.voucherify.io/reference/create-export
362
+ */
363
+ create(exportResource) {
364
+ return this.client.post("/exports", exportResource);
365
+ }
366
+ /**
367
+ * @see https://docs.voucherify.io/reference/list-exports
368
+ */
369
+ list(query = {}) {
370
+ return this.client.get("/exports", query);
371
+ }
372
+ /**
373
+ * @see https://docs.voucherify.io/reference/get-export
374
+ */
375
+ get(exportResourceId) {
376
+ return this.client.get(`/exports/${encode(exportResourceId)}`);
377
+ }
378
+ /**
379
+ * @see https://docs.voucherify.io/reference/delete-export
380
+ */
381
+ delete(exportResourceId) {
382
+ return this.client.delete(`/exports/${encode(exportResourceId)}`);
383
+ }
384
+ };
385
+ __name(_Exports, "Exports");
386
+ var Exports = _Exports;
387
+
388
+ // src/Events.ts
389
+ var _Events = class _Events {
390
+ constructor(client) {
391
+ this.client = client;
392
+ }
393
+ /**
394
+ * @see https://docs.voucherify.io/reference/track-custom-event-client-side
395
+ */
396
+ create(eventName, params) {
397
+ params = { ...params, event: eventName };
398
+ return this.client.post("/events", params);
399
+ }
400
+ };
401
+ __name(_Events, "Events");
402
+ var Events = _Events;
403
+
404
+ // src/Balance.ts
405
+ var _Balance = class _Balance {
406
+ constructor(client) {
407
+ this.client = client;
408
+ }
409
+ /**
410
+ * Add Gift Voucher Balance
411
+ * This method gives a possibility to add balance to an existing gift voucher.
412
+ * @see https://docs.voucherify.io/reference/add-gift-voucher-balance
413
+ */
414
+ create(code, params) {
415
+ return this.client.post(`/vouchers/${encode(code)}/balance`, params);
416
+ }
417
+ };
418
+ __name(_Balance, "Balance");
419
+ var Balance = _Balance;
420
+
421
+ // src/Vouchers.ts
422
+ import FormData2 from "form-data";
423
+ var _VouchersQualification = class _VouchersQualification {
424
+ constructor(client) {
425
+ this.client = client;
426
+ }
427
+ /**
428
+ * The method can be used for sending a request to display all vouchers qualified to the given customer and context (e.g., order, loyalty reward). A checking logic won't run among coupons from bulk unique codes campaigns. For campaigns with multiple unique codes, you should run a dedicated function for searching for qualified campaigns.
429
+ * As a sample use case, you can imagine a requirement of displaying below cart the coupons eligible to a customer. The customer can take and apply the proposed voucher.
430
+ *
431
+ * @see https://docs.voucherify.io/reference/push-qualification-request
432
+ */
433
+ examine(body, params = {}) {
434
+ return this.client.post("/vouchers/qualification", body, params);
435
+ }
436
+ };
437
+ __name(_VouchersQualification, "VouchersQualification");
438
+ var VouchersQualification = _VouchersQualification;
439
+ var _Vouchers = class _Vouchers {
440
+ constructor(client, balance) {
441
+ this.client = client;
442
+ this.balance = balance;
443
+ __publicField(this, "qualifications");
444
+ this.qualifications = new VouchersQualification(this.client);
445
+ }
446
+ /**
447
+ * @see https://docs.voucherify.io/reference/create-voucher
448
+ */
449
+ create(voucher) {
450
+ return this.client.post(`/vouchers/${encode(voucher.code)}`, voucher);
451
+ }
452
+ /**
453
+ * @see https://docs.voucherify.io/reference/vouchers-get
454
+ */
455
+ get(code) {
456
+ return this.client.get(`/vouchers/${encode(code)}`);
457
+ }
458
+ /**
459
+ * @see https://docs.voucherify.io/reference/update-voucher
460
+ */
461
+ update(voucher) {
462
+ return this.client.put(`/vouchers/${encode(voucher.code)}`, voucher);
463
+ }
464
+ /**
465
+ * @see https://docs.voucherify.io/reference/delete-voucher
466
+ */
467
+ delete(code, params = {}) {
468
+ return this.client.delete(`/vouchers/${encode(code)}`, params);
469
+ }
470
+ /**
471
+ * @see https://docs.voucherify.io/reference/list-vouchers
472
+ */
473
+ list(params = {}) {
474
+ return this.client.get("/vouchers", params);
475
+ }
476
+ /**
477
+ * @see https://docs.voucherify.io/reference/enable-voucher
478
+ */
479
+ enable(code) {
480
+ return this.client.post(`/vouchers/${encode(code)}/enable`, {});
481
+ }
482
+ /**
483
+ * @see https://docs.voucherify.io/reference/disable-voucher
484
+ */
485
+ disable(code) {
486
+ return this.client.post(`/vouchers/${encode(code)}/disable`, {});
487
+ }
488
+ /**
489
+ * @see https://docs.voucherify.io/reference/import-vouchers-1
490
+ */
491
+ import(vouchers) {
492
+ return this.client.post("/vouchers/import", vouchers);
493
+ }
494
+ /**
495
+ * @see https://docs.voucherify.io/reference/aaupdate-vouchers-metadata-in-bulk
496
+ */
497
+ bulkUpdateMetadata(params) {
498
+ return this.client.post("/vouchers/metadata/async", params);
499
+ }
500
+ /**
501
+ * @see https://docs.voucherify.io/reference/aa-update-vouchers-in-bulk
502
+ */
503
+ bulkUpdate(vouchers) {
504
+ return this.client.post("/vouchers/bulk/async", vouchers);
505
+ }
506
+ /**
507
+ * @see https://docs.voucherify.io/reference/release-validation-session
508
+ */
509
+ releaseValidationSession(code, sessionKey) {
510
+ return this.client.delete(`/vouchers/${encode(code)}/sessions/${encode(sessionKey)}`);
511
+ }
512
+ /**
513
+ * @see https://docs.voucherify.io/reference/import-vouchers-using-csv
514
+ */
515
+ async importCSV(filePath) {
516
+ assert(
517
+ environment().startsWith("Node"),
518
+ `Method "client.vouchers.importCSV(filePath)" is only for Node environment`
519
+ );
520
+ const fs = (await import("fs")).default;
521
+ const fileStream = fs.createReadStream(filePath);
522
+ const form = new FormData2();
523
+ form.append("file", fileStream);
524
+ const headers = { "Content-Type": "multipart/form-data" };
525
+ return this.client.post("/vouchers/importCSV", form, void 0, headers);
526
+ }
527
+ /**
528
+ * @see https://docs.voucherify.io/reference/list-voucher-transactions
529
+ */
530
+ listTransactions(code, params) {
531
+ return this.client.get(`/vouchers/${encode(code)}/transactions`, params);
532
+ }
533
+ /**
534
+ * @see https://docs.voucherify.io/reference/export-voucher-transactions
535
+ */
536
+ exportTransactions(code, body) {
537
+ return this.client.post(
538
+ `/vouchers/${encode(code)}/transactions/export`,
539
+ body
540
+ );
541
+ }
542
+ };
543
+ __name(_Vouchers, "Vouchers");
544
+ var Vouchers = _Vouchers;
545
+
546
+ // src/Validations.ts
547
+ var _Validations = class _Validations {
548
+ constructor(client, promotions) {
549
+ this.client = client;
550
+ this.promotions = promotions;
551
+ }
552
+ /**
553
+ * @see https://docs.voucherify.io/reference/validate-voucher
554
+ */
555
+ validateVoucher(code, params = {}) {
556
+ return this.client.post(`/vouchers/${encode(code)}/validate`, params);
557
+ }
558
+ validate(code, context = {}) {
559
+ if (isObject(code)) {
560
+ return this.promotions.validate(code);
561
+ }
562
+ return this.validateVoucher(code, context);
563
+ }
564
+ /**
565
+ * @see https://docs.voucherify.io/reference/validate-stacked-discounts-1
566
+ */
567
+ validateStackable(params) {
568
+ return this.client.post(`/validations`, params);
569
+ }
570
+ };
571
+ __name(_Validations, "Validations");
572
+ var Validations = _Validations;
573
+
574
+ // src/Redemptions.ts
575
+ var _Redemptions = class _Redemptions {
576
+ constructor(client) {
577
+ this.client = client;
578
+ }
579
+ /**
580
+ * @see https://docs.voucherify.io/reference/redeem-voucher
581
+ */
582
+ redeem(code, body = {}) {
583
+ return this.client.post(`/vouchers/${encode(code)}/redemption`, body);
584
+ }
585
+ /**
586
+ * @see https://docs.voucherify.io/reference/redeem-stacked-discounts
587
+ */
588
+ redeemStackable(params) {
589
+ return this.client.post(`/redemptions`, params);
590
+ }
591
+ /**
592
+ * @see https://docs.voucherify.io/reference/get-redemption
593
+ */
594
+ get(redemptionId) {
595
+ return this.client.get(`/redemptions/${encode(redemptionId)}`);
596
+ }
597
+ /**
598
+ * @see https://docs.voucherify.io/reference/list-redemptions
599
+ */
600
+ list(params = {}) {
601
+ return this.client.get("/redemptions", params);
602
+ }
603
+ /**
604
+ * @see https://docs.voucherify.io/reference/vouchers-redemptions
605
+ */
606
+ getForVoucher(code) {
607
+ return this.client.get(`/vouchers/${encode(code)}/redemption`);
608
+ }
609
+ /**
610
+ * @see https://docs.voucherify.io/reference/rollback-redemption
611
+ */
612
+ rollback(redemptionId, params) {
613
+ let queryParams = {};
614
+ let payload = {};
615
+ if (isString(params)) {
616
+ queryParams.reason = params;
617
+ } else if (isObject(params)) {
618
+ const { reason, tracking_id: trackingId, customer } = params;
619
+ queryParams = {
620
+ reason: reason ? reason : void 0,
621
+ tracking_id: trackingId ? trackingId : void 0
622
+ };
623
+ payload = { customer };
624
+ }
625
+ return this.client.post(
626
+ `/redemptions/${encode(redemptionId)}/rollback`,
627
+ payload,
628
+ queryParams
629
+ );
630
+ }
631
+ /**
632
+ * @see https://docs.voucherify.io/reference/rollback-stackable-redemptions
633
+ * Types of params and queryParams WILL be changed in future - please do not depend on it!
634
+ */
635
+ rollbackStackable(parentRedemptionId, params, queryParams) {
636
+ return this.client.post(
637
+ `/redemptions/${encode(parentRedemptionId)}/rollbacks`,
638
+ params,
639
+ queryParams
640
+ );
641
+ }
642
+ };
643
+ __name(_Redemptions, "Redemptions");
644
+ var Redemptions = _Redemptions;
645
+
646
+ // src/PromotionTiers.ts
647
+ var _PromotionTiers = class _PromotionTiers {
648
+ constructor(client) {
649
+ this.client = client;
650
+ }
651
+ /**
652
+ * @see https://docs.voucherify.io/reference/list-promotion-tiers
653
+ */
654
+ listAll(params = {}) {
655
+ return this.client.get("/promotions/tiers", params);
656
+ }
657
+ /**
658
+ * @see https://docs.voucherify.io/reference/get-promotions
659
+ */
660
+ list(promotionId) {
661
+ return this.client.get(`/promotions/${encode(promotionId)}/tiers`);
662
+ }
663
+ /**
664
+ * @see https://docs.voucherify.io/reference/get-promotion-tier
665
+ */
666
+ get(tierId) {
667
+ return this.client.get(`/promotions/tiers/${encode(tierId)}`);
668
+ }
669
+ /**
670
+ * @see https://docs.voucherify.io/reference/add-promotion-tier-to-campaign
671
+ */
672
+ create(promotionId, params) {
673
+ return this.client.post(`/promotions/${encode(promotionId)}/tiers`, params);
674
+ }
675
+ /**
676
+ * @see https://docs.voucherify.io/reference/redeem-promotion
677
+ */
678
+ redeem(promotionsTierId, params) {
679
+ return this.client.post(
680
+ `/promotions/tiers/${encode(promotionsTierId)}/redemption`,
681
+ params
682
+ );
683
+ }
684
+ /**
685
+ * @see https://docs.voucherify.io/reference/update-promotion
686
+ */
687
+ update(params) {
688
+ return this.client.put(`/promotions/tiers/${encode(params.id)}`, params);
689
+ }
690
+ /**
691
+ * @see https://docs.voucherify.io/reference/delete-promotion
692
+ */
693
+ delete(promotionsTierId) {
694
+ return this.client.delete(`/promotions/tiers/${encode(promotionsTierId)}`);
695
+ }
696
+ };
697
+ __name(_PromotionTiers, "PromotionTiers");
698
+ var PromotionTiers = _PromotionTiers;
699
+
700
+ // src/Promotions.ts
701
+ var _Promotions = class _Promotions {
702
+ constructor(client, tiers, stack) {
703
+ this.client = client;
704
+ this.tiers = tiers;
705
+ this.stack = stack;
706
+ }
707
+ /**
708
+ * @see https://docs.voucherify.io/reference/create-promotion-campaign
709
+ */
710
+ create(promotionCampaign) {
711
+ return this.client.post("/campaigns", promotionCampaign);
712
+ }
713
+ /**
714
+ * @see https://docs.voucherify.io/reference/validate-promotions-1
715
+ */
716
+ validate(body, params) {
717
+ return this.client.post("/promotions/validation", body, params);
718
+ }
719
+ };
720
+ __name(_Promotions, "Promotions");
721
+ var Promotions = _Promotions;
722
+
723
+ // src/Customers.ts
724
+ import FormData3 from "form-data";
725
+ var _Customers = class _Customers {
726
+ constructor(client) {
727
+ this.client = client;
728
+ }
729
+ /**
730
+ * @see https://docs.voucherify.io/reference/create-customer
731
+ */
732
+ create(customer) {
733
+ return this.client.post("/customers", customer);
734
+ }
735
+ /**
736
+ * @see https://docs.voucherify.io/reference/read-customer
737
+ */
738
+ get(customerId) {
739
+ return this.client.get(`/customers/${encode(customerId)}`);
740
+ }
741
+ /**
742
+ * @see https://docs.voucherify.io/reference/list-customers
743
+ */
744
+ list(params) {
745
+ return this.client.get("/customers", params);
746
+ }
747
+ /**
748
+ * Standard list customers API has limitation of available pages to be shown equal to 100. To cover cases when you would like to fetch more, you must use scroll capabilities.
749
+ *
750
+ * ```javascript
751
+ * async function () {
752
+ * for await (const customer of voucherify.customers.scroll(params)) {
753
+ * console.log('Customer', customer)
754
+ * }
755
+ * }
756
+ * ```
757
+ */
758
+ async *scroll(params) {
759
+ var _a;
760
+ let startingAfter = (_a = params.starting_after) != null ? _a : params.order === "created_at" ? "1970-01-01T00:00:00Z" : "2200-01-01T00:00:00Z";
761
+ let response = await this.client.get(
762
+ "/customers",
763
+ Object.assign({}, params, { starting_after: startingAfter })
764
+ );
765
+ while (true) {
766
+ if (response.customers.length === 0) break;
767
+ for (const customer of response.customers) {
768
+ if (params.order === "created_at") {
769
+ startingAfter = startingAfter > customer.created_at ? startingAfter : customer.created_at;
770
+ } else {
771
+ startingAfter = startingAfter < customer.created_at ? startingAfter : customer.created_at;
772
+ }
773
+ yield customer;
774
+ }
775
+ if (!response.has_more) break;
776
+ response = await this.client.get("/customers", Object.assign({}, params, { starting_after: startingAfter }));
777
+ }
778
+ }
779
+ /**
780
+ * @see https://docs.voucherify.io/reference/update-customer
781
+ */
782
+ update(customer) {
783
+ const id = "id" in customer ? customer.id : customer.source_id;
784
+ const customerWithoutId = omit(customer, ["id"]);
785
+ return this.client.put(`/customers/${encode(id)}`, customerWithoutId);
786
+ }
787
+ /**
788
+ * @see https://docs.voucherify.io/reference/update-customers-in-bulk
789
+ */
790
+ updateInBulk(customers) {
791
+ return this.client.post(`/customers/bulk/async`, customers);
792
+ }
793
+ /**
794
+ * @see https://docs.voucherify.io/reference/update-customers-metadata-in-bulk
795
+ */
796
+ updateMetadataInBulk(sourceIdsAndMetadata) {
797
+ return this.client.post(`/customers/metadata/async`, sourceIdsAndMetadata);
798
+ }
799
+ /**
800
+ * @see https://docs.voucherify.io/reference/delete-customer
801
+ */
802
+ delete(customerId) {
803
+ return this.client.delete(`/customers/${encode(customerId)}`);
804
+ }
805
+ /**
806
+ * @see https://docs.voucherify.io/reference/delete-customer-permanently
807
+ */
808
+ deletePermanently(customerId) {
809
+ return this.client.post(
810
+ `/customers/${encode(customerId)}/permanent-deletion`,
811
+ {}
812
+ );
813
+ }
814
+ /**
815
+ * @see https://docs.voucherify.io/reference/list-customer-activity
816
+ */
817
+ listActivity(customerIdOrSourceId, params) {
818
+ return this.client.get(
819
+ `/customers/${encode(customerIdOrSourceId)}/activity`,
820
+ params
821
+ );
822
+ }
823
+ /**
824
+ * @deprecated This method is deprecated. We’re removing this method in next major version.
825
+ */
826
+ updateConsents(idOrSourceId, consents) {
827
+ return this.client.put(`/customers/${encode(idOrSourceId)}/consents`, consents);
828
+ }
829
+ /**
830
+ * @deprecated This method is deprecated in favor of the `listActivity` method. We’re removing this method in next major version.
831
+ */
832
+ listActivities(customerId, params) {
833
+ return this.client.get(`/customers/${encode(customerId)}/activities`, params);
834
+ }
835
+ /**
836
+ * @see https://docs.voucherify.io/reference/import-customers-using-csv
837
+ */
838
+ async importCSV(filePath) {
839
+ assert(
840
+ environment().startsWith("Node"),
841
+ `Method "client.customers.importCSV(filePath)" is only for Node environment`
842
+ );
843
+ const fs = (await import("fs")).default;
844
+ const fileStream = fs.createReadStream(filePath);
845
+ const form = new FormData3();
846
+ form.append("file", fileStream);
847
+ const headers = { "Content-Type": "multipart/form-data" };
848
+ return this.client.post(`/customers/importCSV`, form, void 0, headers);
849
+ }
850
+ /**
851
+ * @see https://docs.voucherify.io/reference/list-customer-redeemables
852
+ */
853
+ listRedeemables(id, params) {
854
+ return this.client.get(`/customers/${encode(id)}/redeemables`, params);
855
+ }
856
+ };
857
+ __name(_Customers, "Customers");
858
+ var Customers = _Customers;
859
+
860
+ // src/Consents.ts
861
+ var _Consents = class _Consents {
862
+ constructor(client) {
863
+ this.client = client;
864
+ }
865
+ /**
866
+ * @deprecated This method is deprecated. We’re removing this method in next major version.
867
+ */
868
+ list() {
869
+ return this.client.get("/consents");
870
+ }
871
+ };
872
+ __name(_Consents, "Consents");
873
+ var Consents = _Consents;
874
+
875
+ // src/Orders.ts
876
+ var _Orders = class _Orders {
877
+ constructor(client) {
878
+ this.client = client;
879
+ }
880
+ /**
881
+ * @see https://docs.voucherify.io/reference/create-order
882
+ */
883
+ create(order) {
884
+ return this.client.post("/orders", order);
885
+ }
886
+ /**
887
+ * @see https://docs.voucherify.io/reference/get-order
888
+ */
889
+ get(orderId) {
890
+ return this.client.get(`/orders/${encode(orderId)}`);
891
+ }
892
+ /**
893
+ * @see https://docs.voucherify.io/reference/update-order
894
+ */
895
+ update(order) {
896
+ return this.client.put(
897
+ `/orders/${encode(order.id || order.source_id)}`,
898
+ omit(order, ["id"])
899
+ );
900
+ }
901
+ /**
902
+ * @see https://docs.voucherify.io/reference/list-orders
903
+ */
904
+ list(params = {}) {
905
+ return this.client.get("/orders", params);
906
+ }
907
+ /**
908
+ * @see https://docs.voucherify.io/reference/import-orders
909
+ */
910
+ import(orders) {
911
+ return this.client.post("/orders/import", orders);
912
+ }
913
+ };
914
+ __name(_Orders, "Orders");
915
+ var Orders = _Orders;
916
+
917
+ // src/Products.ts
918
+ import FormData4 from "form-data";
919
+ var _Products = class _Products {
920
+ constructor(client) {
921
+ this.client = client;
922
+ }
923
+ /**
924
+ * @see https://docs.voucherify.io/reference/create-product
925
+ */
926
+ create(product) {
927
+ return this.client.post("/products", product);
928
+ }
929
+ /**
930
+ * @see https://docs.voucherify.io/reference/get-product
931
+ */
932
+ get(productId) {
933
+ return this.client.get(`/products/${encode(productId)}`);
934
+ }
935
+ /**
936
+ * @see https://docs.voucherify.io/reference/update-product
937
+ */
938
+ update(product) {
939
+ return this.client.put(
940
+ `/products/${encode(product.id || product.source_id)}`,
941
+ omit(product, ["id"])
942
+ );
943
+ }
944
+ /**
945
+ * @see https://docs.voucherify.io/reference/async-update-products-metadata-in-bulk
946
+ */
947
+ bulkUpdateMetadata(products) {
948
+ return this.client.post("/products/metadata/async", products);
949
+ }
950
+ /**
951
+ * @see https://docs.voucherify.io/reference/post-products-in-bulk
952
+ */
953
+ bulkUpdate(products) {
954
+ return this.client.post("/products/bulk/async", products);
955
+ }
956
+ /**
957
+ * @see https://docs.voucherify.io/reference/delete-product
958
+ */
959
+ delete(productId, params) {
960
+ return this.client.delete(`/products/${encode(productId)}`, params);
961
+ }
962
+ /**
963
+ * @see https://docs.voucherify.io/reference/list-products
964
+ */
965
+ list(params) {
966
+ return this.client.get("/products", params);
967
+ }
968
+ /**
969
+ * @see https://docs.voucherify.io/reference/create-sku
970
+ */
971
+ createSku(productId, sku) {
972
+ return this.client.post(`/products/${encode(productId)}/skus`, sku);
973
+ }
974
+ /**
975
+ * @see https://docs.voucherify.io/reference/get-sku-v20210726
976
+ */
977
+ getSku(skuId) {
978
+ return this.client.get(`/skus/${encode(skuId)}`);
979
+ }
980
+ /**
981
+ * @see https://docs.voucherify.io/reference/update-sku
982
+ */
983
+ updateSku(productId, sku) {
984
+ return this.client.put(
985
+ `/products/${encode(productId)}/skus/${encode(sku.id || sku.source_id)}`,
986
+ omit(sku, ["id"])
987
+ );
988
+ }
989
+ /**
990
+ * @see https://docs.voucherify.io/reference/delete-sku
991
+ */
992
+ deleteSku(productId, skuId, params) {
993
+ return this.client.delete(`/products/${encode(productId)}/skus/${encode(skuId)}`, params);
994
+ }
995
+ /**
996
+ * @see https://docs.voucherify.io/reference/list-skus
997
+ */
998
+ listSkus(productId) {
999
+ return this.client.get(`/products/${encode(productId)}/skus`);
1000
+ }
1001
+ /**
1002
+ * @see https://docs.voucherify.io/reference/import-skus-using-csv
1003
+ */
1004
+ async importSkusCSV(filePath) {
1005
+ assert(
1006
+ environment().startsWith("Node"),
1007
+ `Method "client.products.importSkusCSV(filePath)" is only for Node environment`
1008
+ );
1009
+ const fs = (await import("fs")).default;
1010
+ const fileStream = fs.createReadStream(filePath);
1011
+ const form = new FormData4();
1012
+ form.append("file", fileStream);
1013
+ const headers = { "Content-Type": "multipart/form-data" };
1014
+ return this.client.post(`/skus/importCSV`, form, void 0, headers);
1015
+ }
1016
+ /**
1017
+ * @see https://docs.voucherify.io/reference/import-products-using-csv
1018
+ */
1019
+ async importCSV(filePath) {
1020
+ assert(
1021
+ environment().startsWith("Node"),
1022
+ `Method "client.products.importCSV(filePath)" is only for Node environment`
1023
+ );
1024
+ const fs = (await import("fs")).default;
1025
+ const fileStream = fs.createReadStream(filePath);
1026
+ const form = new FormData4();
1027
+ form.append("file", fileStream);
1028
+ const headers = { "Content-Type": "multipart/form-data" };
1029
+ return this.client.post(`/products/importCSV`, form, void 0, headers);
1030
+ }
1031
+ };
1032
+ __name(_Products, "Products");
1033
+ var Products = _Products;
1034
+
1035
+ // src/Rewards.ts
1036
+ var _Rewards = class _Rewards {
1037
+ constructor(client) {
1038
+ this.client = client;
1039
+ }
1040
+ /**
1041
+ * @see https://docs.voucherify.io/reference/list-rewards
1042
+ */
1043
+ list(params = {}) {
1044
+ return this.client.get("/rewards", params);
1045
+ }
1046
+ /**
1047
+ * @see https://docs.voucherify.io/reference/create-reward
1048
+ */
1049
+ create(reward) {
1050
+ return this.client.post("/rewards", reward);
1051
+ }
1052
+ /**
1053
+ * @see https://docs.voucherify.io/reference/get-reward
1054
+ */
1055
+ get(rewardId) {
1056
+ return this.client.get(`/rewards/${encode(rewardId)}`);
1057
+ }
1058
+ /**
1059
+ * @see https://docs.voucherify.io/reference/update-reward
1060
+ */
1061
+ update(reward) {
1062
+ return this.client.put(`/rewards/${encode(reward.id)}`, omit(reward, ["id"]));
1063
+ }
1064
+ /**
1065
+ * @see https://docs.voucherify.io/reference/delete-reward
1066
+ */
1067
+ delete(rewardId) {
1068
+ return this.client.delete(`/rewards/${encode(rewardId)}`);
1069
+ }
1070
+ /**
1071
+ * @see https://docs.voucherify.io/reference/get-reward-assignment
1072
+ */
1073
+ getAssignment(rewardId, assignmentId) {
1074
+ return this.client.get(
1075
+ `/rewards/${encode(rewardId)}/assignments/${encode(assignmentId)}`
1076
+ );
1077
+ }
1078
+ /**
1079
+ * @see https://docs.voucherify.io/reference/list-reward-assignments
1080
+ */
1081
+ listAssignments(rewardId, params = {}) {
1082
+ return this.client.get(`/rewards/${encode(rewardId)}/assignments`, params);
1083
+ }
1084
+ /**
1085
+ * @see https://docs.voucherify.io/reference/create-reward-assignment
1086
+ */
1087
+ createAssignment(rewardId, assignment) {
1088
+ return this.client.post(
1089
+ `/rewards/${encode(rewardId)}/assignments`,
1090
+ assignment
1091
+ );
1092
+ }
1093
+ /**
1094
+ * @see https://docs.voucherify.io/reference/update-reward-assignment
1095
+ */
1096
+ updateAssignment(rewardId, assignment) {
1097
+ return this.client.put(
1098
+ `/rewards/${encode(rewardId)}/assignments/${encode(assignment.id)}`,
1099
+ omit(assignment, ["id"])
1100
+ );
1101
+ }
1102
+ deleteAssignment(rewardId, assignmentId) {
1103
+ return this.client.delete(`/rewards/${encode(rewardId)}/assignments/${encode(assignmentId)}`);
1104
+ }
1105
+ };
1106
+ __name(_Rewards, "Rewards");
1107
+ var Rewards = _Rewards;
1108
+
1109
+ // src/Loyalties.ts
1110
+ var _Loyalties = class _Loyalties {
1111
+ constructor(client) {
1112
+ this.client = client;
1113
+ }
1114
+ /**
1115
+ * @see https://docs.voucherify.io/reference/list-loyalty-programs
1116
+ */
1117
+ list(params = {}) {
1118
+ return this.client.get("/loyalties", params);
1119
+ }
1120
+ /**
1121
+ * @see https://docs.voucherify.io/reference/create-loyalty-program
1122
+ */
1123
+ create(campaign) {
1124
+ return this.client.post("/loyalties", campaign);
1125
+ }
1126
+ /**
1127
+ * @see https://docs.voucherify.io/reference/get-loyalty-program
1128
+ */
1129
+ get(campaignId) {
1130
+ return this.client.get(`/loyalties/${encode(campaignId)}`);
1131
+ }
1132
+ /**
1133
+ * @see https://docs.voucherify.io/reference/update-loyalty-program
1134
+ */
1135
+ update(campaign) {
1136
+ return this.client.put(
1137
+ `/loyalties/${encode(campaign.id)}`,
1138
+ omit(campaign, ["id"])
1139
+ );
1140
+ }
1141
+ /**
1142
+ * @see https://docs.voucherify.io/reference/delete-loyalty-program
1143
+ */
1144
+ delete(campaignId, params) {
1145
+ return this.client.delete(`/loyalties/${encode(campaignId)}`, params);
1146
+ }
1147
+ /**
1148
+ * @see https://docs.voucherify.io/reference/list-reward-assignments-1
1149
+ */
1150
+ listRewardAssignments(campaignId, params = {}) {
1151
+ return this.client.get(`/loyalties/${encode(campaignId)}/rewards`, params);
1152
+ }
1153
+ /**
1154
+ * @see https://docs.voucherify.io/reference/create-reward-assignment-1
1155
+ */
1156
+ createRewardAssignments(campaignId, assignment) {
1157
+ return this.client.post(
1158
+ `/loyalties/${encode(campaignId)}/rewards`,
1159
+ assignment
1160
+ );
1161
+ }
1162
+ /**
1163
+ * @see https://docs.voucherify.io/reference/update-reward-assignment-1
1164
+ */
1165
+ updateRewardAssignment(campaignId, assignment) {
1166
+ return this.client.put(
1167
+ `/loyalties/${encode(campaignId)}/rewards/${assignment.id}`,
1168
+ omit(assignment, ["id"])
1169
+ );
1170
+ }
1171
+ /**
1172
+ * @see https://docs.voucherify.io/reference/delete-reward-assignment-1
1173
+ */
1174
+ deleteRewardAssignment(campaignId, assignmentId) {
1175
+ return this.client.delete(`/loyalties/${encode(campaignId)}/rewards/${assignmentId}`);
1176
+ }
1177
+ /**
1178
+ * @see https://docs.voucherify.io/reference/get-reward-assignment-2
1179
+ */
1180
+ getRewardAssignment(campaignId, assignmentId) {
1181
+ return this.client.get(
1182
+ `/loyalties/${encode(campaignId)}/rewards/${encode(assignmentId)}`
1183
+ );
1184
+ }
1185
+ /**
1186
+ * @see https://docs.voucherify.io/reference/list-earning-rules
1187
+ */
1188
+ listEarningRules(campaignId, params = {}) {
1189
+ return this.client.get(
1190
+ `/loyalties/${encode(campaignId)}/earning-rules`,
1191
+ params
1192
+ );
1193
+ }
1194
+ /**
1195
+ * @see https://docs.voucherify.io/reference/create-earning-rule
1196
+ */
1197
+ createEarningRule(campaignId, earningRules) {
1198
+ return this.client.post(
1199
+ `/loyalties/${encode(campaignId)}/earning-rules`,
1200
+ earningRules
1201
+ );
1202
+ }
1203
+ /**
1204
+ * @see https://docs.voucherify.io/reference/update-earning-rule
1205
+ */
1206
+ updateEarningRule(campaignId, earningRule) {
1207
+ return this.client.put(
1208
+ `/loyalties/${encode(campaignId)}/earning-rules/${earningRule.id}`,
1209
+ omit(earningRule, ["id"])
1210
+ );
1211
+ }
1212
+ /**
1213
+ * @see https://docs.voucherify.io/reference/delete-earning-rule
1214
+ */
1215
+ deleteEarningRule(campaignId, earningRuleId) {
1216
+ return this.client.delete(`/loyalties/${encode(campaignId)}/earning-rules/${earningRuleId}`);
1217
+ }
1218
+ /**
1219
+ * @see https://docs.voucherify.io/reference/get-earning-rule
1220
+ */
1221
+ getEarningRule(campaignId, earningRuleId) {
1222
+ return this.client.get(
1223
+ `/loyalties/${encode(campaignId)}/earning-rules/${encode(earningRuleId)}`
1224
+ );
1225
+ }
1226
+ /**
1227
+ * @see https://docs.voucherify.io/reference/enable-earning-rule
1228
+ */
1229
+ enableEarningRule(campaignId, earningRuleId) {
1230
+ return this.client.post(
1231
+ `/loyalties/${encode(campaignId)}/earning-rules/${earningRuleId}/enable`,
1232
+ {}
1233
+ );
1234
+ }
1235
+ /**
1236
+ * @see https://docs.voucherify.io/reference/disable-earning-rule
1237
+ */
1238
+ disableEarningRule(campaignId, earningRuleId) {
1239
+ return this.client.post(
1240
+ `/loyalties/${encode(campaignId)}/earning-rules/${earningRuleId}/disable`,
1241
+ {}
1242
+ );
1243
+ }
1244
+ /**
1245
+ * @see https://docs.voucherify.io/reference/list-members
1246
+ */
1247
+ listMembers(campaignId, params) {
1248
+ return this.client.get(`/loyalties/${encode(campaignId)}/members`, params);
1249
+ }
1250
+ /**
1251
+ * @see https://docs.voucherify.io/reference/create-member
1252
+ */
1253
+ createMember(campaignId, member) {
1254
+ return this.client.post(`/loyalties/${encode(campaignId)}/members`, member);
1255
+ }
1256
+ /**
1257
+ * @see https://docs.voucherify.io/reference/get-member
1258
+ * @see https://docs.voucherify.io/reference/get-member-1
1259
+ */
1260
+ getMember(campaignId, memberId) {
1261
+ return this.client.get(
1262
+ campaignId ? `/loyalties/${encode(campaignId)}/members/${memberId}` : `/loyalties/members/${memberId}`
1263
+ );
1264
+ }
1265
+ /**
1266
+ * @see https://docs.voucherify.io/reference/list-member-activity
1267
+ * @see https://docs.voucherify.io/reference/list-member-activity-1
1268
+ */
1269
+ listMemberActivity(campaignId, memberId, params) {
1270
+ return this.client.get(
1271
+ campaignId ? `/loyalties/${encode(campaignId)}/members/${memberId}/activity` : `/loyalties/members/${memberId}/activity`,
1272
+ params
1273
+ );
1274
+ }
1275
+ /**
1276
+ * @deprecated This method is deprecated in favor of the `listMemberActivity` method. We’re removing this method in next major version.
1277
+ */
1278
+ getMemberActivities(campaignId, memberId) {
1279
+ return this.client.get(
1280
+ campaignId ? `/loyalties/${encode(campaignId)}/members/${memberId}/activities` : `/loyalties/members/${memberId}/activities`
1281
+ );
1282
+ }
1283
+ /**
1284
+ * @see https://docs.voucherify.io/reference/list-member-rewards
1285
+ */
1286
+ listMemberRewards(memberId, params) {
1287
+ return this.client.get(
1288
+ `/loyalties/members/${encode(memberId)}/rewards`,
1289
+ params
1290
+ );
1291
+ }
1292
+ /**
1293
+ * @see https://docs.voucherify.io/reference/add-remove-loyalty-card-balance
1294
+ * @see https://docs.voucherify.io/reference/add-remove-loyalty-card-balance-1
1295
+ */
1296
+ addOrRemoveCardBalance(memberId, balance, campaignId) {
1297
+ return this.client.post(
1298
+ campaignId ? `/loyalties/${encode(campaignId)}/members/${memberId}/balance` : `/loyalties/members/${memberId}/balance`,
1299
+ balance
1300
+ );
1301
+ }
1302
+ /**
1303
+ * @see https://docs.voucherify.io/reference/add-remove-loyalty-card-balance-1
1304
+ */
1305
+ addPoints(campaignId, memberId, balance) {
1306
+ return this.client.post(
1307
+ `/loyalties/${encode(campaignId)}/members/${memberId}/balance`,
1308
+ balance
1309
+ );
1310
+ }
1311
+ /**
1312
+ * @see https://docs.voucherify.io/reference/transfer-points
1313
+ */
1314
+ transferPoints(campaignId, memberId, loyaltiesTransferPoints) {
1315
+ return this.client.post(
1316
+ `/loyalties/${encode(campaignId)}/members/${encode(memberId)}/transfers`,
1317
+ loyaltiesTransferPoints
1318
+ );
1319
+ }
1320
+ /**
1321
+ * @see https://docs.voucherify.io/reference/get-points-expiration
1322
+ */
1323
+ getPointsExpiration(campaignId, memberId, params) {
1324
+ return this.client.get(
1325
+ `/loyalties/${encode(campaignId)}/members/${memberId}/points-expiration`,
1326
+ params
1327
+ );
1328
+ }
1329
+ /**
1330
+ * @see https://docs.voucherify.io/reference/redeem-loyalty-card
1331
+ */
1332
+ redeemReward(campaignId, memberId, params) {
1333
+ return this.client.post(
1334
+ `/loyalties/${encode(campaignId)}/members/${encode(memberId)}/redemption`,
1335
+ params
1336
+ );
1337
+ }
1338
+ /**
1339
+ * @see https://docs.voucherify.io/reference/list-loyalty-tier-rewards
1340
+ */
1341
+ listLoyaltyTierRewards(campaignId, tierId) {
1342
+ return this.client.get(
1343
+ `/loyalties/${encode(campaignId)}/tiers/${encode(tierId)}/rewards`
1344
+ );
1345
+ }
1346
+ /**
1347
+ * @see https://docs.voucherify.io/reference/list-loyalty-card-transactions
1348
+ * @see https://docs.voucherify.io/reference/list-loyalty-card-transactions-1
1349
+ */
1350
+ listCardTransactions(memberId, campaignId, params) {
1351
+ return this.client.get(
1352
+ campaignId ? `/loyalties/${encode(campaignId)}/members/${encode(memberId)}/transactions` : `/loyalties/members/${encode(memberId)}/transactions`,
1353
+ params
1354
+ );
1355
+ }
1356
+ /**
1357
+ * @see https://docs.voucherify.io/reference/export-loyalty-card-transactions
1358
+ * @see https://docs.voucherify.io/reference/export-loyalty-card-transactions-1
1359
+ */
1360
+ exportCardTransactions(memberId, campaignId, params = {}) {
1361
+ return this.client.post(
1362
+ campaignId ? `/loyalties/${encode(campaignId)}/members/${encode(memberId)}/transactions/export` : `/loyalties/members/${encode(memberId)}/transactions/export`,
1363
+ params
1364
+ );
1365
+ }
1366
+ /**
1367
+ * @see https://docs.voucherify.io/reference/get-reward-details
1368
+ */
1369
+ getRewardDetails(campaignId, assignmentId) {
1370
+ return this.client.get(
1371
+ `/loyalties/${encode(campaignId)}/reward-assignments/${encode(assignmentId)}/reward`
1372
+ );
1373
+ }
1374
+ /**
1375
+ * @see https://docs.voucherify.io/reference/list-loyalty-tiers
1376
+ */
1377
+ listTiers(campaignId, params) {
1378
+ return this.client.get(`/loyalties/${encode(campaignId)}/tiers`, params);
1379
+ }
1380
+ /**
1381
+ * @see https://docs.voucherify.io/reference/get-loyalty-tier
1382
+ */
1383
+ getTier(campaignId, tierId) {
1384
+ return this.client.get(`/loyalties/${encode(campaignId)}/tiers/${encode(tierId)}`);
1385
+ }
1386
+ /**
1387
+ * @see https://docs.voucherify.io/reference/create-loyalty-tiers
1388
+ */
1389
+ createTiers(campaignId, tiers) {
1390
+ return this.client.post(`/loyalties/${encode(campaignId)}/tiers`, tiers);
1391
+ }
1392
+ /**
1393
+ * @see https://docs.voucherify.io/reference/list-loyalty-tier-earning-rules
1394
+ */
1395
+ listLoyaltyTierEarningRules(campaignId, tierId, params) {
1396
+ return this.client.get(
1397
+ `/loyalties/${encode(campaignId)}/tiers/${encode(tierId)}/earning-rules`,
1398
+ params
1399
+ );
1400
+ }
1401
+ /**
1402
+ * @see https://docs.voucherify.io/reference/get-member-loyalty-tier
1403
+ */
1404
+ listMemberLoyaltyTiers(memberId) {
1405
+ return this.client.get(
1406
+ `/loyalties/members/${encode(memberId)}/tiers`
1407
+ );
1408
+ }
1409
+ };
1410
+ __name(_Loyalties, "Loyalties");
1411
+ var Loyalties = _Loyalties;
1412
+
1413
+ // src/ValidationRules.ts
1414
+ var _ValidationRules = class _ValidationRules {
1415
+ constructor(client) {
1416
+ this.client = client;
1417
+ }
1418
+ /**
1419
+ * @see https://docs.voucherify.io/reference/create-validation-rules
1420
+ */
1421
+ create(validationRule) {
1422
+ return this.client.post("/validation-rules", validationRule);
1423
+ }
1424
+ /**
1425
+ * @see https://docs.voucherify.io/reference/get-validation-rules
1426
+ */
1427
+ get(validationRuleId) {
1428
+ return this.client.get(`/validation-rules/${encode(validationRuleId)}`);
1429
+ }
1430
+ /**
1431
+ * @see https://docs.voucherify.io/reference/update-validation-rules
1432
+ */
1433
+ update(validationRule) {
1434
+ return this.client.put(
1435
+ `/validation-rules/${encode(validationRule.id)}`,
1436
+ omit(validationRule, ["id"])
1437
+ );
1438
+ }
1439
+ /**
1440
+ * @see https://docs.voucherify.io/reference/delete-validation-rules
1441
+ */
1442
+ delete(validationRuleId) {
1443
+ return this.client.delete(`/validation-rules/${encode(validationRuleId)}`);
1444
+ }
1445
+ /**
1446
+ * @see https://docs.voucherify.io/reference/create-validation-rules-assignment
1447
+ */
1448
+ createAssignment(validationRuleId, assignment) {
1449
+ return this.client.post(
1450
+ `/validation-rules/${encode(validationRuleId)}/assignments`,
1451
+ assignment
1452
+ );
1453
+ }
1454
+ /**
1455
+ * @see https://docs.voucherify.io/reference/delete-validation-rules-assignment
1456
+ */
1457
+ deleteAssignment(validationRuleId, assignmentId) {
1458
+ return this.client.delete(`/validation-rules/${encode(validationRuleId)}/assignments/${encode(assignmentId)}`);
1459
+ }
1460
+ validate(validationRuleId, params = {}) {
1461
+ return this.client.post(
1462
+ `/validation-rules/${encode(validationRuleId)}/validation`,
1463
+ params
1464
+ );
1465
+ }
1466
+ /**
1467
+ * @see https://docs.voucherify.io/reference/list-validation-rules
1468
+ */
1469
+ list(params = {}) {
1470
+ return this.client.get("/validation-rules", params);
1471
+ }
1472
+ /**
1473
+ * @see https://docs.voucherify.io/reference/list-validation-rules-assignments
1474
+ */
1475
+ listRulesAssignments(params = {}) {
1476
+ return this.client.get(`/validation-rules-assignments`, params);
1477
+ }
1478
+ /**
1479
+ * @see https://docs.voucherify.io/reference/list-validation-rule-assignments
1480
+ */
1481
+ listAssignments(validationRuleId, params = {}) {
1482
+ return this.client.get(
1483
+ `/validation-rules/${encode(validationRuleId)}/assignments`,
1484
+ params
1485
+ );
1486
+ }
1487
+ };
1488
+ __name(_ValidationRules, "ValidationRules");
1489
+ var ValidationRules = _ValidationRules;
1490
+
1491
+ // src/Segments.ts
1492
+ var _Segments = class _Segments {
1493
+ constructor(client) {
1494
+ this.client = client;
1495
+ }
1496
+ /**
1497
+ * @see https://docs.voucherify.io/reference/create-segment
1498
+ */
1499
+ create(segment) {
1500
+ return this.client.post("/segments", segment);
1501
+ }
1502
+ /**
1503
+ * @see https://docs.voucherify.io/reference/get-segment
1504
+ */
1505
+ get(segmentId) {
1506
+ return this.client.get(`/segments/${encode(segmentId)}`);
1507
+ }
1508
+ /**
1509
+ * @see https://docs.voucherify.io/reference/delete-segment
1510
+ */
1511
+ delete(segmentId) {
1512
+ return this.client.delete(`/segments/${encode(segmentId)}`);
1513
+ }
1514
+ /**
1515
+ * @see https://docs.voucherify.io/reference/list-segments
1516
+ */
1517
+ list(customerId) {
1518
+ return this.client.get(`/customers/${encode(customerId)}/segments`);
1519
+ }
1520
+ };
1521
+ __name(_Segments, "Segments");
1522
+ var Segments = _Segments;
1523
+
1524
+ // src/ApiLimitsHandler.ts
1525
+ var _ApiLimitsHandler = class _ApiLimitsHandler {
1526
+ constructor(requestController) {
1527
+ this.requestController = requestController;
1528
+ }
1529
+ getLastResponseHeadersFromController() {
1530
+ return this.requestController.getLastResponseHeaders();
1531
+ }
1532
+ areLimitsAvailable() {
1533
+ return this.requestController.isLastReponseHeadersSet();
1534
+ }
1535
+ getRateLimit() {
1536
+ var _a;
1537
+ const rateLimit = (_a = this.getLastResponseHeadersFromController()["x-rate-limit-limit"]) != null ? _a : 0;
1538
+ return parseInt(rateLimit, 10);
1539
+ }
1540
+ getRateLimitRemaining() {
1541
+ var _a;
1542
+ const rateLimitRemaining = (_a = this.getLastResponseHeadersFromController()["x-rate-limit-remaining"]) != null ? _a : 0;
1543
+ return parseInt(rateLimitRemaining, 10);
1544
+ }
1545
+ getRetryAfter() {
1546
+ var _a;
1547
+ const retryAfter = (_a = this.getLastResponseHeadersFromController()["retry-after"]) != null ? _a : 0;
1548
+ return parseInt(retryAfter, 10);
1549
+ }
1550
+ };
1551
+ __name(_ApiLimitsHandler, "ApiLimitsHandler");
1552
+ var ApiLimitsHandler = _ApiLimitsHandler;
1553
+
1554
+ // src/MetadataSchemas.ts
1555
+ var _MetadataSchemas = class _MetadataSchemas {
1556
+ constructor(client) {
1557
+ this.client = client;
1558
+ }
1559
+ /**
1560
+ * @see https://docs.voucherify.io/reference/list-metadata-schemas
1561
+ */
1562
+ list() {
1563
+ return this.client.get("/metadata-schemas");
1564
+ }
1565
+ /**
1566
+ * @see https://docs.voucherify.io/reference/get-metadata-schema
1567
+ */
1568
+ get(schemaName) {
1569
+ return this.client.get(`/metadata-schemas/${encode(schemaName)}`);
1570
+ }
1571
+ };
1572
+ __name(_MetadataSchemas, "MetadataSchemas");
1573
+ var MetadataSchemas = _MetadataSchemas;
1574
+
1575
+ // src/Categories.ts
1576
+ var _Categories = class _Categories {
1577
+ constructor(client) {
1578
+ this.client = client;
1579
+ }
1580
+ /**
1581
+ * @see https://docs.voucherify.io/reference/list-categories
1582
+ */
1583
+ list(params = {}) {
1584
+ return this.client.get("/categories", params);
1585
+ }
1586
+ /**
1587
+ * @see https://docs.voucherify.io/reference/create-category
1588
+ */
1589
+ create(createCategory) {
1590
+ return this.client.post("/categories", createCategory);
1591
+ }
1592
+ /**
1593
+ * @see https://docs.voucherify.io/reference/get-category
1594
+ */
1595
+ get(categoryId) {
1596
+ return this.client.get(`/categories/${encode(categoryId)}`);
1597
+ }
1598
+ /**
1599
+ * @see https://docs.voucherify.io/reference/delete-category
1600
+ */
1601
+ delete(categoryId) {
1602
+ return this.client.delete(`/categories/${encode(categoryId)}`);
1603
+ }
1604
+ /**
1605
+ * @see https://docs.voucherify.io/reference/update-category
1606
+ */
1607
+ update(categoryId, updateCategory) {
1608
+ return this.client.put(`/categories/${encode(categoryId)}`, updateCategory);
1609
+ }
1610
+ };
1611
+ __name(_Categories, "Categories");
1612
+ var Categories = _Categories;
1613
+
1614
+ // src/PromotionsStacks.ts
1615
+ var _PromotionsStacks = class _PromotionsStacks {
1616
+ constructor(client) {
1617
+ this.client = client;
1618
+ }
1619
+ /**
1620
+ * @see https://docs.voucherify.io/reference/list-promotion-stacks-in-campaign
1621
+ */
1622
+ listInCampaign(campaignId) {
1623
+ return this.client.get(`/promotions/${campaignId}/stacks`);
1624
+ }
1625
+ /**
1626
+ * @see https://docs.voucherify.io/reference/list-promotion-stacks-in-campaign
1627
+ */
1628
+ createInCampaign(campaignId, body) {
1629
+ return this.client.post(`/promotions/${campaignId}/stacks`, body);
1630
+ }
1631
+ /**
1632
+ * @see https://docs.voucherify.io/reference/delete-promotion-stack
1633
+ */
1634
+ delete(campaignId, stackId) {
1635
+ return this.client.delete(`/promotions/${campaignId}/stacks/${stackId}`);
1636
+ }
1637
+ /**
1638
+ * @see https://docs.voucherify.io/reference/get-promotion-stack
1639
+ */
1640
+ get(campaignId, stackId) {
1641
+ return this.client.get(`/promotions/${campaignId}/stacks/${stackId}`);
1642
+ }
1643
+ /**
1644
+ * @see https://docs.voucherify.io/reference/update-promotion-stack
1645
+ */
1646
+ update(campaignId, stackId, body) {
1647
+ return this.client.put(`/promotions/${campaignId}/stacks/${stackId}`, body);
1648
+ }
1649
+ /**
1650
+ * @see https://docs.voucherify.io/reference/list-promotion-stacks-in-campaign
1651
+ */
1652
+ list(params) {
1653
+ return this.client.get(`/promotions/stacks`, params);
1654
+ }
1655
+ };
1656
+ __name(_PromotionsStacks, "PromotionsStacks");
1657
+ var PromotionsStacks = _PromotionsStacks;
1658
+
1659
+ // src/ProductCollections.ts
1660
+ var _ProductCollections = class _ProductCollections {
1661
+ constructor(client) {
1662
+ this.client = client;
1663
+ }
1664
+ /**
1665
+ * @see https://docs.voucherify.io/reference/create-product-collection
1666
+ */
1667
+ create(productCollection) {
1668
+ return this.client.post(`/product-collections`, productCollection);
1669
+ }
1670
+ /**
1671
+ * @see https://docs.voucherify.io/reference/list-product-collections
1672
+ */
1673
+ list(params) {
1674
+ return this.client.get(`/product-collections`, params);
1675
+ }
1676
+ /**
1677
+ * @see https://docs.voucherify.io/reference/delete-product-collection
1678
+ */
1679
+ delete(productCollectionId) {
1680
+ return this.client.delete(`/product-collections/${encode(productCollectionId)}`);
1681
+ }
1682
+ /**
1683
+ * @see https://docs.voucherify.io/reference/get-product-collection
1684
+ */
1685
+ get(productCollectionId) {
1686
+ return this.client.get(`/product-collections/${encode(productCollectionId)}`);
1687
+ }
1688
+ /**
1689
+ * @see https://docs.voucherify.io/reference/list-products-in-collection
1690
+ */
1691
+ listProducts(productCollectionId, params) {
1692
+ return this.client.get(
1693
+ `/product-collections/${encode(productCollectionId)}/products`,
1694
+ params
1695
+ );
1696
+ }
1697
+ };
1698
+ __name(_ProductCollections, "ProductCollections");
1699
+ var ProductCollections = _ProductCollections;
1700
+
1701
+ // src/Qualifications.ts
1702
+ var _Qualifications = class _Qualifications {
1703
+ constructor(client) {
1704
+ this.client = client;
1705
+ }
1706
+ /**
1707
+ * @see https://docs.voucherify.io/reference/check-eligibility
1708
+ */
1709
+ checkEligibility(body) {
1710
+ return this.client.post("/qualifications", body);
1711
+ }
1712
+ };
1713
+ __name(_Qualifications, "Qualifications");
1714
+ var Qualifications = _Qualifications;
1715
+
1716
+ // src/VoucherifyServerSide.ts
1717
+ function VoucherifyServerSide(options) {
1718
+ var _a, _b, _c;
1719
+ assert(isObject(options), 'VoucherifyServerSide: the "options" argument must be an object');
1720
+ assert(isString(options.applicationId), 'VoucherifyServerSide: "options.applicationId" is required');
1721
+ assert(isString(options.secretKey), 'VoucherifyServerSide: "options.secretKey" is required');
1722
+ assert(isOptionalString(options.apiVersion), 'VoucherifyServerSide: expected "options.apiVersion" to be a string');
1723
+ assert(isOptionalString(options.channel), 'VoucherifyServerSide: expected "options.channel" to be a string');
1724
+ let headers = {
1725
+ "X-App-Id": options.applicationId,
1726
+ "X-App-Token": options.secretKey,
1727
+ "X-Voucherify-Channel": options.channel || `${environment()}-SDK-v${"2.9.4"}`,
1728
+ "Content-Type": "application/json"
1729
+ };
1730
+ if (options.apiVersion) {
1731
+ headers["X-Voucherify-API-Version"] = options.apiVersion;
1732
+ }
1733
+ if (isObject(options.customHeaders)) {
1734
+ headers = Object.assign({}, headers, options.customHeaders);
1735
+ }
1736
+ if (!environment().startsWith("Node")) {
1737
+ assert(
1738
+ options.dangerouslySetSecretKeyInBrowser === true,
1739
+ `VoucherifyServerSide: you're exposing your secretKey to a ${environment().toLowerCase()} environment. This is generally considered a bad practice. Did you mean to use 'VoucherifyClientSide'?`
1740
+ );
1741
+ }
1742
+ const client = new RequestController({
1743
+ basePath: "v1",
1744
+ baseURL: (_a = options.apiUrl) != null ? _a : "https://api.voucherify.io",
1745
+ headers,
1746
+ exposeErrorCause: (_b = options.exposeErrorCause) != null ? _b : false,
1747
+ timeoutMs: (_c = options.timeoutMs) != null ? _c : 0
1748
+ });
1749
+ const asyncActions = new AsyncActions(client);
1750
+ const balance = new Balance(client);
1751
+ const vouchers = new Vouchers(client, balance);
1752
+ const campaigns = new Campaigns(client);
1753
+ const categories = new Categories(client);
1754
+ const exportsNamespace = new Exports(client);
1755
+ const events = new Events(client);
1756
+ const distributions = new Distributions(client, exportsNamespace);
1757
+ const promotionTiers = new PromotionTiers(client);
1758
+ const promotionStack = new PromotionsStacks(client);
1759
+ const promotions = new Promotions(client, promotionTiers, promotionStack);
1760
+ const validations = new Validations(client, promotions);
1761
+ const redemptions = new Redemptions(client);
1762
+ const qualifications = new Qualifications(client);
1763
+ const customers = new Customers(client);
1764
+ const consents = new Consents(client);
1765
+ const orders = new Orders(client);
1766
+ const products = new Products(client);
1767
+ const productCollections = new ProductCollections(client);
1768
+ const rewards = new Rewards(client);
1769
+ const loyalties = new Loyalties(client);
1770
+ const segments = new Segments(client);
1771
+ const validationRules = new ValidationRules(client);
1772
+ const apiLimitsHandler = new ApiLimitsHandler(client);
1773
+ const metadataSchemas = new MetadataSchemas(client);
1774
+ return {
1775
+ vouchers,
1776
+ campaigns,
1777
+ categories,
1778
+ distributions,
1779
+ validations,
1780
+ redemptions,
1781
+ promotions,
1782
+ customers,
1783
+ consents,
1784
+ orders,
1785
+ products,
1786
+ productCollections,
1787
+ qualifications,
1788
+ rewards,
1789
+ loyalties,
1790
+ segments,
1791
+ validationRules,
1792
+ events,
1793
+ asyncActions,
1794
+ apiLimitsHandler,
1795
+ metadataSchemas
1796
+ };
1797
+ }
1798
+ __name(VoucherifyServerSide, "VoucherifyServerSide");
1799
+
1800
+ // src/ClientSide.ts
1801
+ var _ClientSide = class _ClientSide {
1802
+ constructor(client, trackingId) {
1803
+ this.client = client;
1804
+ this.trackingId = trackingId;
1805
+ }
1806
+ setIdentity(identity) {
1807
+ this.trackingId = identity;
1808
+ }
1809
+ /**
1810
+ * @see https://docs.voucherify.io/reference/vouchers-validate
1811
+ */
1812
+ validate(params) {
1813
+ var _a, _b;
1814
+ assert(
1815
+ isObject(params) || isString(params),
1816
+ 'client.validate: expected "params" argument to be an object or a string'
1817
+ );
1818
+ const query = {};
1819
+ if (isString(params)) {
1820
+ query.code = params;
1821
+ } else {
1822
+ query.code = params.code;
1823
+ query.item = params.items;
1824
+ query.amount = params.amount;
1825
+ query.metadata = params.metadata;
1826
+ query.order = { metadata: params.orderMetadata };
1827
+ query.customer = params.customer;
1828
+ query.tracking_id = params.tracking_id || this.trackingId;
1829
+ query.session_type = params.session_type;
1830
+ query.session_key = params.session_key;
1831
+ query.session_ttl = params.session_ttl;
1832
+ query.session_ttl_unit = params.session_ttl_unit;
1833
+ }
1834
+ if (!!query.code) {
1835
+ query.code = query.code.replace(/[\r\n\t\f\v]/g, "").trim();
1836
+ }
1837
+ assert(isOptionalObject(query == null ? void 0 : query.customer), 'client.validate: expected "params.customer" to be an object');
1838
+ assert(isOptionalString((_a = query == null ? void 0 : query.customer) == null ? void 0 : _a.source_id), 'client.validate: expected "params.customer.source_id" to be a string');
1839
+ assert(isOptionalObject((_b = query == null ? void 0 : query.customer) == null ? void 0 : _b.metadata), 'client.validate: expected "params.customer.metadata" to be an object');
1840
+ const path = query.code ? "/validate" : "/promotions/validation";
1841
+ return this.client.get(path, query);
1842
+ }
1843
+ /**
1844
+ * @see https://docs.voucherify.io/reference/redeem-voucher-client-side
1845
+ */
1846
+ redeem(code, payload = {}) {
1847
+ var _a, _b;
1848
+ assert(isString(code), "client.redeem - please provide a valid Voucher code");
1849
+ code = code.replace(/[\r\n\t\f\v]/g, "").trim();
1850
+ payload.customer = (_a = payload.customer) != null ? _a : {};
1851
+ payload.customer.source_id = (_b = payload.customer.source_id) != null ? _b : this.trackingId;
1852
+ return this.client.post("/redeem", payload, { code });
1853
+ }
1854
+ /**
1855
+ * @see https://docs.voucherify.io/reference/create-publication
1856
+ */
1857
+ publish(campaign, payload = {}, queryParams = {}) {
1858
+ var _a, _b, _c, _d, _e;
1859
+ assert(isObject(payload), "client.publish - expected payload to be an object");
1860
+ const preparedPayload = {};
1861
+ preparedPayload.customer = (_a = payload.customer) != null ? _a : {};
1862
+ preparedPayload.customer.source_id = (_c = (_b = payload.customer) == null ? void 0 : _b.source_id) != null ? _c : this.trackingId;
1863
+ preparedPayload.channel = (_d = payload.channel) != null ? _d : "Voucherify.js";
1864
+ assert(
1865
+ isString((_e = preparedPayload.customer) == null ? void 0 : _e.source_id),
1866
+ "client.publish - expected payload to contain customer source id or to have tracking id set up by Voucherify client"
1867
+ );
1868
+ queryParams.campaign = campaign.replace(/[\r\n\t\f\v]/g, "").trim();
1869
+ return this.client.post("/publish", preparedPayload, queryParams);
1870
+ }
1871
+ /**
1872
+ * @see https://docs.voucherify.io/reference/track-custom-event-client-side
1873
+ */
1874
+ track(event_name, customer, metadata, referral, loyalty) {
1875
+ var _a, _b;
1876
+ assert(isString(event_name), "client.track - expected event name to be an string");
1877
+ assert(isObject(customer), "client.track - expected customer to be an object");
1878
+ const payload = {
1879
+ event: event_name,
1880
+ metadata: metadata != null ? metadata : {},
1881
+ customer,
1882
+ referral: referral != null ? referral : void 0,
1883
+ loyalty: loyalty != null ? loyalty : void 0
1884
+ };
1885
+ payload.customer.source_id = (_a = customer.source_id) != null ? _a : this.trackingId;
1886
+ assert(
1887
+ isString((_b = payload.customer) == null ? void 0 : _b.source_id),
1888
+ "client.track - expected payload to contain customer source id or to have tracking id set up by Voucherify client"
1889
+ );
1890
+ return this.client.post("/events", payload);
1891
+ }
1892
+ /**
1893
+ * @see https://docs.voucherify.io/reference/list-vouchers
1894
+ */
1895
+ listVouchers(params = {}) {
1896
+ const query = {};
1897
+ query.campaign = params.campaign;
1898
+ query.category = params.category;
1899
+ query.page = params.page;
1900
+ query.limit = params.limit;
1901
+ query.customer = params.customer;
1902
+ query.created_at = params.created_at;
1903
+ query.updated_at = params.updated_at;
1904
+ return this.client.get("/vouchers", query);
1905
+ }
1906
+ /**
1907
+ * @see https://docs.voucherify.io/reference/create-customer
1908
+ */
1909
+ createCustomer(customer, enableDoubleOptIn) {
1910
+ return this.client.post(
1911
+ "/customers",
1912
+ customer,
1913
+ {},
1914
+ enableDoubleOptIn ? { "X-Voucherify-Double-Opt-In": true } : {}
1915
+ );
1916
+ }
1917
+ /**
1918
+ * @see https://docs.voucherify.io/reference/get-consent-client-side
1919
+ */
1920
+ listConsents() {
1921
+ return this.client.get("/consents");
1922
+ }
1923
+ /**
1924
+ * @see https://docs.voucherify.io/reference/update-customers-consents-client
1925
+ */
1926
+ updateConsents(idOrSourceId, consents) {
1927
+ return this.client.put(`/customers/${encode(idOrSourceId)}/consents`, consents);
1928
+ }
1929
+ /**
1930
+ * @see https://docs.voucherify.io/reference/validate-stackable-discounts-client-side
1931
+ */
1932
+ validateStackable(params) {
1933
+ return this.client.post(`/validations`, params);
1934
+ }
1935
+ /**
1936
+ * @see https://docs.voucherify.io/reference/redeem-stackable-discounts-client-side
1937
+ */
1938
+ redeemStackable(params) {
1939
+ return this.client.post(`/redemptions`, params);
1940
+ }
1941
+ /**
1942
+ * @see https://docs.voucherify.io/reference/check-eligibility
1943
+ */
1944
+ qualifications(body) {
1945
+ return this.client.post("/qualifications", body);
1946
+ }
1947
+ };
1948
+ __name(_ClientSide, "ClientSide");
1949
+ var ClientSide = _ClientSide;
1950
+
1951
+ // src/VoucherifyClientSide.ts
1952
+ function VoucherifyClientSide(options) {
1953
+ var _a, _b, _c;
1954
+ assert(isObject(options), 'VoucherifyCustomer: expected "options" argument to be an object');
1955
+ assert(isString(options.clientApplicationId), 'VoucherifyCustomer: "options.clientApplicationId" is required');
1956
+ assert(isString(options.clientSecretKey), 'VoucherifyCustomer: "options.clientSecretKey" is required');
1957
+ assert(isOptionalString(options.apiUrl), 'VoucherifyCustomer: expected "options.baseUrl" to be a string');
1958
+ assert(isOptionalString(options.trackingId), 'VoucherifyCustomer: expected "options.trackingId" to be a string');
1959
+ let headers = {
1960
+ "X-Client-Application-Id": options.clientApplicationId,
1961
+ "X-Client-Token": options.clientSecretKey,
1962
+ "X-Voucherify-Channel": `${environment()}-ClientSide-SDK-v${"2.9.4"}`
1963
+ };
1964
+ if (environment().startsWith("Node")) {
1965
+ assert(isString(options.origin), 'VoucherifyCustomer: "options.origin" is required in Node.js');
1966
+ headers["origin"] = options.origin;
1967
+ }
1968
+ if (isObject(options.customHeaders)) {
1969
+ headers = Object.assign({}, headers, options.customHeaders);
1970
+ }
1971
+ const client = new RequestController({
1972
+ basePath: "client/v1",
1973
+ baseURL: (_a = options.apiUrl) != null ? _a : "https://api.voucherify.io",
1974
+ headers,
1975
+ exposeErrorCause: (_b = options.exposeErrorCause) != null ? _b : false,
1976
+ timeoutMs: (_c = options.timeoutMs) != null ? _c : 0
1977
+ });
1978
+ return new ClientSide(client, options.trackingId);
1979
+ }
1980
+ __name(VoucherifyClientSide, "VoucherifyClientSide");
1981
+ export {
1982
+ DiscountVouchersTypesEnum,
1983
+ VoucherifyClientSide,
1984
+ VoucherifyServerSide
1985
+ };
2
1986
  //# sourceMappingURL=voucherifysdk.esm.js.map