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