@voucherify/sdk 2.0.7 → 2.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @voucherify/sdk
2
2
 
3
+ ## 2.0.8
4
+
5
+ ### Patch Changes
6
+
7
+ - [`e965f61`](https://github.com/voucherifyio/voucherify-js-sdk/commit/e965f615ada65812553a0e5df4409ccf6e02dae1) [#129](https://github.com/voucherifyio/voucherify-js-sdk/pull/129) Thanks [@Irene350](https://github.com/Irene350)! - Adding missing discount amounts on order for validate voucher type response
8
+
3
9
  ## 2.0.7
4
10
 
5
11
  ### Patch Changes
@@ -50,6 +50,8 @@ export interface ValidationsValidateVoucherResponse {
50
50
  discount_amount: number;
51
51
  total_discount_amount: number;
52
52
  total_amount: number;
53
+ applied_discount_amount?: number;
54
+ total_applied_discount_amount?: number;
53
55
  items?: OrdersItem[];
54
56
  };
55
57
  start_date?: string;
@@ -1404,7 +1404,7 @@ function VoucherifyServerSide(options) {
1404
1404
  let headers = {
1405
1405
  'X-App-Id': options.applicationId,
1406
1406
  'X-App-Token': options.secretKey,
1407
- 'X-Voucherify-Channel': options.channel || `${environment()}-SDK-v${"2.0.7"}`,
1407
+ 'X-Voucherify-Channel': options.channel || `${environment()}-SDK-v${"2.0.8"}`,
1408
1408
  'Content-Type': 'application/json'
1409
1409
  };
1410
1410
 
@@ -1653,7 +1653,7 @@ function VoucherifyClientSide(options) {
1653
1653
  let headers = {
1654
1654
  'X-Client-Application-Id': options.clientApplicationId,
1655
1655
  'X-Client-Token': options.clientSecretKey,
1656
- 'X-Voucherify-Channel': `${environment()}-ClientSide-SDK-v${"2.0.7"}`
1656
+ 'X-Voucherify-Channel': `${environment()}-ClientSide-SDK-v${"2.0.8"}`
1657
1657
  };
1658
1658
 
1659
1659
  if (environment().startsWith('Node')) {
@@ -1408,7 +1408,7 @@
1408
1408
  let headers = {
1409
1409
  'X-App-Id': options.applicationId,
1410
1410
  'X-App-Token': options.secretKey,
1411
- 'X-Voucherify-Channel': options.channel || `${environment()}-SDK-v${"2.0.7"}`,
1411
+ 'X-Voucherify-Channel': options.channel || `${environment()}-SDK-v${"2.0.8"}`,
1412
1412
  'Content-Type': 'application/json'
1413
1413
  };
1414
1414
 
@@ -1657,7 +1657,7 @@
1657
1657
  let headers = {
1658
1658
  'X-Client-Application-Id': options.clientApplicationId,
1659
1659
  'X-Client-Token': options.clientSecretKey,
1660
- 'X-Voucherify-Channel': `${environment()}-ClientSide-SDK-v${"2.0.7"}`
1660
+ 'X-Voucherify-Channel': `${environment()}-ClientSide-SDK-v${"2.0.8"}`
1661
1661
  };
1662
1662
 
1663
1663
  if (environment().startsWith('Node')) {
@@ -1,2 +1,2 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("axios"),require("qs")):"function"==typeof define&&define.amd?define(["exports","axios","qs"],t):t((e=e||self).VoucherifySDK={},e.axios,e.Qs)}(this,(function(e,t,s){"use strict";var i;t=t&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t,s=s&&Object.prototype.hasOwnProperty.call(s,"default")?s.default:s,(i=e.DiscountVouchersTypesEnum||(e.DiscountVouchersTypesEnum={})).AMOUNT="AMOUNT",i.PERCENT="PERCENT",i.UNIT="UNIT",i.FIXED="FIXED";class r extends Error{constructor(e,t){var s,i;super((null==(i=t=null!=(s=t)?s:{})?void 0:i.message)||function(e,t){return`Unexpected status code: ${t} - Details: ${e="string"==typeof e?e:JSON.stringify(e,null,2)}`}(t,e)),Object.assign(this,t)}}class n{constructor({basePath:e,baseURL:s,headers:i}){this.baseURL=void 0,this.basePath=void 0,this.headers=void 0,this.request=void 0,this.lastResponseHeaders=void 0,this.isLastResponseHeadersSet=void 0,this.basePath=e,this.baseURL=s,this.headers=i,this.lastResponseHeaders={},this.isLastResponseHeadersSet=!1,this.request=t.create({baseURL:`${this.baseURL}/${this.basePath}/`,headers:this.headers,responseType:"json"}),this.request.interceptors.response.use(void 0,e=>{var t;return null!=e&&null!=(t=e.response)&&t.status?Promise.reject(new r(e.response.status,e.response.data)):Promise.reject(e)})}isLastReponseHeadersSet(){return this.isLastResponseHeadersSet}getLastResponseHeaders(){return this.lastResponseHeaders}setLastResponseHeaders(e){this.lastResponseHeaders=e,this.isLastResponseHeadersSet=!0}setBaseUrl(e){this.baseURL=e,this.request.defaults.baseURL=`${e}/${this.basePath}/`}async get(e,t){const i=await this.request.get(e,{params:t,paramsSerializer:function(e){return s.stringify(e)}});return this.setLastResponseHeaders(i.headers),i.data}async post(e,t,i,r){const n=await this.request.post(e,t,{params:i,paramsSerializer:function(e){return s.stringify(e)},headers:r});return this.setLastResponseHeaders(n.headers),n.data}async put(e,t,s){const i=await this.request.put(e,t,{params:s});return this.setLastResponseHeaders(i.headers),i.data}async delete(e,t){const s=await this.request.delete(e,{params:t});return this.setLastResponseHeaders(s.headers),s.data}}function o(e=""){return encodeURIComponent(e)}function c(e){return"string"==typeof e}function a(e){return null==e||c(e)}function l(e){return"object"==typeof e&&!Array.isArray(e)&&null!==e}function u(e){return null==e||l(e)}function d(){return"undefined"!=typeof window&&void 0!==window.document?"Browser":"object"==typeof self&&self.constructor&&"DedicatedWorkerGlobalScope"===self.constructor.name?"WebWorker":"undefined"!=typeof process&&null!=process.versions&&null!=process.versions.node?"Node.js-"+process.version:"undefined"!=typeof window&&"nodejs"===window.name||navigator.userAgent.includes("Node.js")||navigator.userAgent.includes("jsdom")?"JsDom":"Unknown"}function h(e,t){if(!e)throw new Error(t)}function p(e,t){return Object.fromEntries(Object.entries(e).filter(([e])=>!t.includes(e)))}class m{constructor(e){this.client=void 0,this.client=e}get(e){return this.client.get("/async-actions/"+o(e))}list(e){return this.client.get("/async-actions",e)}}class g{constructor(e){this.client=void 0,this.client=e}examine(e={},t){return this.client.post("/campaigns/qualification",e,t)}}class v{constructor(e){this.client=void 0,this.qualifications=void 0,this.client=e,this.qualifications=new g(this.client)}create(e){return this.client.post("/campaigns",e)}update(e,t){return this.client.put("/campaigns/"+o(e),t)}get(e){return this.client.get("/campaigns/"+o(e))}delete(e,t={}){return this.client.delete("/campaigns/"+o(e),t)}addVoucher(e,t={},s={}){return this.client.post(`/campaigns/${o(e)}/vouchers`,t,s)}addCertainVoucher(e,t,s={}){return this.client.post(`/campaigns/${o(e)}/vouchers/${o(t)}`,s)}importVouchers(e,t){return this.client.post(`/campaigns/${o(e)}/import`,t)}list(e={}){return this.client.get("/campaigns",e)}}class y{constructor(e){this.client=void 0,this.client=e}list(e={}){return this.client.get("/publications",e)}create(e){return this.client.post("/publications",e)}}class b{constructor(e,t){this.client=void 0,this.exports=void 0,this.publications=void 0,this.client=e,this.exports=t,this.publications=new y(this.client)}}class f{constructor(e){this.client=void 0,this.client=e}create(e){return this.client.post("/exports",e)}get(e){return this.client.get("/exports/"+o(e))}delete(e){return this.client.delete("/exports/"+o(e))}}class w{constructor(e){this.client=void 0,this.client=e}create(e,t){return t={...t,event:e},this.client.post("/events",t)}}class ${constructor(e){this.client=void 0,this.client=e}create(e,t){return this.client.post(`/vouchers/${o(e)}/balance`,t)}}class k{constructor(e){this.client=void 0,this.client=e}examine(e,t={}){return this.client.post("/vouchers/qualification",e,t)}}class S{constructor(e,t){this.client=void 0,this.balance=void 0,this.qualifications=void 0,this.client=e,this.balance=t,this.qualifications=new k(this.client)}create(e){return this.client.post("/vouchers/"+o(e.code),e)}get(e){return this.client.get("/vouchers/"+o(e))}update(e){return this.client.put("/vouchers/"+o(e.code),e)}delete(e,t={}){return this.client.delete("/vouchers/"+o(e),t)}list(e={}){return this.client.get("/vouchers",e)}enable(e){return this.client.post(`/vouchers/${o(e)}/enable`,{})}disable(e){return this.client.post(`/vouchers/${o(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/${o(e)}/sessions/${o(t)}`)}}class R{constructor(e,t){this.client=void 0,this.promotions=void 0,this.client=e,this.promotions=t}validateVoucher(e,t={}){return this.client.post(`/vouchers/${o(e)}/validate`,t)}validate(e,t={}){return l(e)?this.promotions.validate(e):this.validateVoucher(e,t)}validateStackable(e){return this.client.post("/validations",e)}}class _{constructor(e){this.client=void 0,this.client=e}redeem(e,t={}){return this.client.post(`/vouchers/${o(e)}/redemption`,t)}redeemStackable(e){return this.client.post("/redemptions",e)}get(e){return this.client.get("/redemptions/"+o(e))}list(e={}){return this.client.get("/redemptions",e)}getForVoucher(e){return this.client.get(`/vouchers/${o(e)}/redemption`)}rollback(e,t){let s={},i={};if(c(t))s.reason=t;else if(l(t)){const{reason:e,tracking_id:r,customer:n}=t;s={reason:e||void 0,tracking_id:r||void 0},i={customer:n}}return this.client.post(`/redemptions/${o(e)}/rollback`,i,s)}rollbackStackable(e,t,s){return this.client.post(`/redemptions/${o(e)}/rollbacks`,t,s)}}class V{constructor(e){this.client=void 0,this.client=e}listAll(e={}){return this.client.get("/promotions/tiers",e)}list(e){return this.client.get(`/promotions/${o(e)}/tiers`)}create(e,t){return this.client.post(`/promotions/${o(e)}/tiers`,t)}redeem(e,t){return this.client.post(`/promotions/tiers/${o(e)}/redemption`,t)}update(e){return this.client.put("/promotions/tiers/"+o(e.id),e)}delete(e){return this.client.delete("/promotions/tiers/"+o(e))}}class x{constructor(e,t){this.client=void 0,this.tiers=void 0,this.client=e,this.tiers=t}create(e){return this.client.post("/campaigns",e)}validate(e,t){return this.client.post("/promotions/validation",e,t)}}class j{constructor(e){this.client=void 0,this.client=e}create(e){return this.client.post("/customers",e)}get(e){return this.client.get("/customers/"+o(e))}list(e){return this.client.get("/customers",e)}async*scroll(e){var t;let s=null!=(t=e.starting_after)?t:"created_at"===e.order?"1970-01-01T00:00:00Z":"2200-01-01T00:00:00Z",i=await this.client.get("/customers",Object.assign({},e,{starting_after:s}));for(;0!==i.customers.length;){for(const t of i.customers)s="created_at"===e.order?s>t.created_at?s:t.created_at:s<t.created_at?s:t.created_at,yield t;if(!i.has_more)break;i=await this.client.get("/customers",Object.assign({},e,{starting_after:s}))}}update(e){const t="id"in e?e.id:e.source_id,s=p(e,["id"]);return this.client.put("/customers/"+o(t),s)}delete(e){return this.client.delete("/customers/"+o(e))}updateConsents(e,t){return this.client.put(`/customers/${o(e)}/consents`,t)}listActivities(e,t){return this.client.get(`/customers/${o(e)}/activities`,t)}}class C{constructor(e){this.client=void 0,this.client=e}list(){return this.client.get("/consents")}}class L{constructor(e){this.client=void 0,this.client=e}create(e){return this.client.post("/orders",e)}get(e){return this.client.get("/orders/"+o(e))}update(e){return this.client.put("/orders/"+o(e.id||e.source_id),p(e,["id"]))}list(e={}){return this.client.get("/orders",e)}}class A{constructor(e){this.client=void 0,this.client=e}create(e){return this.client.post("/products",e)}get(e){return this.client.get("/products/"+o(e))}update(e){return this.client.put("/products/"+o(e.id||e.source_id),p(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/"+o(e),t)}list(e){return this.client.get("/products",e)}createSku(e,t){return this.client.post(`/products/${o(e)}/skus`,t)}getSku(e){return this.client.get("/skus/"+o(e))}updateSku(e,t){return this.client.put(`/products/${o(e)}/skus/${o(t.id||t.source_id)}`,p(t,["id"]))}deleteSku(e,t,s){return this.client.delete(`/products/${o(e)}/skus/${o(t)}`,s)}listSkus(e){return this.client.get(`/products/${o(e)}/skus`)}}class I{constructor(e){this.client=void 0,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/"+o(e))}update(e){return this.client.put("/rewards/"+o(e.id),p(e,["id"]))}delete(e){return this.client.delete("/rewards/"+o(e))}listAssignments(e,t={}){return this.client.get(`/rewards/${o(e)}/assignments`,t)}createAssignment(e,t){return this.client.post(`/rewards/${o(e)}/assignments`,t)}updateAssignment(e,t){return this.client.put(`/rewards/${o(e)}/assignments/${o(t.id)}`,p(t,["id"]))}deleteAssignment(e,t){return this.client.delete(`/rewards/${o(e)}/assignments/${o(t)}`)}}class q{constructor(e){this.client=void 0,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/"+o(e))}update(e){return this.client.put("/loyalties/"+o(e.id),p(e,["id"]))}delete(e,t){return this.client.delete("/loyalties/"+o(e),t)}listRewardAssignments(e,t={}){return this.client.get(`/loyalties/${o(e)}/rewards`,t)}createRewardAssignments(e,t){return this.client.post(`/loyalties/${o(e)}/rewards`,t)}updateRewardAssignment(e,t){return this.client.put(`/loyalties/${o(e)}/rewards/${t.id}`,p(t,["id"]))}deleteRewardAssignment(e,t){return this.client.delete(`/loyalties/${o(e)}/rewards/${t}`)}listEarningRules(e,t={}){return this.client.get(`/loyalties/${o(e)}/earning-rules`,t)}createEarningRule(e,t){return this.client.post(`/loyalties/${o(e)}/earning-rules`,t)}updateEarningRule(e,t){return this.client.put(`/loyalties/${o(e)}/earning-rules/${t.id}`,p(t,["id"]))}deleteEarningRule(e,t){return this.client.delete(`/loyalties/${o(e)}/earning-rules/${t}`)}listMembers(e,t){return this.client.get(`/loyalties/${o(e)}/members`,t)}createMember(e,t){return this.client.post(`/loyalties/${o(e)}/members`,t)}getMember(e,t){return this.client.get(`/loyalties/${o(e)}/members/${t}`)}getMemberActivities(e,t){return this.client.get(`/loyalties/${o(e)}/members/${t}/activities`)}addPoints(e,t,s){return this.client.post(`/loyalties/${o(e)}/members/${t}/balance`,s)}redeemReward(e,t,s){return this.client.post(`/loyalties/${o(e)}/members/${o(t)}/redemption`,s)}}class H{constructor(e){this.client=void 0,this.client=e}create(e){return this.client.post("/validation-rules",e)}get(e){return this.client.get("/validation-rules/"+o(e))}update(e){return this.client.put("/validation-rules/"+o(e.id),p(e,["id"]))}delete(e){return this.client.delete("/validation-rules/"+o(e))}createAssignment(e,t){return this.client.post(`/validation-rules/${o(e)}/assignments`,t)}deleteAssignment(e,t){return this.client.delete(`/validation-rules/${o(e)}/assignments/${o(t)}`)}validate(e,t={}){return this.client.post(`/validation-rules/${o(e)}/validation`,t)}list(e={}){return this.client.get("/validation-rules",e)}listAssignments(e,t={}){return this.client.get(`/validation-rules/${o(e)}/assignments`,t)}}class U{constructor(e){this.client=void 0,this.client=e}create(e){return this.client.post("/segments",e)}get(e){return this.client.get("/segments/"+o(e))}delete(e){return this.client.delete("/segments/"+o(e))}list(e){return this.client.get(`/customers/${o(e)}/segments`)}}class O{constructor(e){this.requestController=void 0,this.requestController=e}getLastResponseHeadersFromController(){return this.requestController.getLastResponseHeaders()}areLimitsAvailable(){return this.requestController.isLastReponseHeadersSet()}getRateLimit(){var e;const t=null!=(e=this.getLastResponseHeadersFromController()["x-rate-limit-limit"])?e:0;return parseInt(t,10)}getRateLimitRemaining(){var e;const t=null!=(e=this.getLastResponseHeadersFromController()["x-rate-limit-remaining"])?e:0;return parseInt(t,10)}}class P{constructor(e){this.client=void 0,this.client=e}list(){return this.client.get("/metadata-schemas")}get(e){return this.client.get("/metadata-schemas/"+o(e))}}class E{constructor(e,t){this.client=void 0,this.trackingId=void 0,this.client=e,this.trackingId=t}setIdentity(e){this.trackingId=e}validate(e){var t,s;h(l(e)||c(e),'client.validate: expected "params" argument to be an object or a string');const i={};return c(e)?i.code=e:(i.code=e.code,i.item=e.items,i.amount=e.amount,i.metadata=e.metadata,i.order={metadata:e.orderMetadata},i.customer=e.customer,i.tracking_id=e.tracking_id||this.trackingId,i.session_type=e.session_type,i.session_key=e.session_key,i.session_ttl=e.session_ttl,i.session_ttl_unit=e.session_ttl_unit),i.code&&(i.code=i.code.replace(/[\r\n\t\f\v]/g,"").trim()),h(u(null==i?void 0:i.customer),'client.validate: expected "params.customer" to be an object'),h(a(null==i||null==(t=i.customer)?void 0:t.source_id),'client.validate: expected "params.customer.source_id" to be a string'),h(u(null==i||null==(s=i.customer)?void 0:s.metadata),'client.validate: expected "params.customer.metadata" to be an object'),this.client.get(i.code?"/validate":"/promotions/validation",i)}redeem(e,t={}){var s,i;return h(c(e),"client.redeem - please provide a valid Voucher code"),e=e.replace(/[\r\n\t\f\v]/g,"").trim(),t.customer=null!=(s=t.customer)?s:{},t.customer.source_id=null!=(i=t.customer.source_id)?i:this.trackingId,this.client.post("/redeem",t,{code:e})}publish(e,t={},s={}){var i,r,n,o,a;h(l(t),"client.publish - expected payload to be an object");const u={};return u.customer=null!=(i=t.customer)?i:{},u.customer.source_id=null!=(r=null==(n=t.customer)?void 0:n.source_id)?r:this.trackingId,u.channel=null!=(o=t.channel)?o:"Voucherify.js",h(c(null==(a=u.customer)?void 0:a.source_id),"client.publish - expected payload to contain customer source id or to have tracking id set up by Voucherify client"),s.campaign=e.replace(/[\r\n\t\f\v]/g,"").trim(),this.client.post("/publish",u,s)}track(e,t,s,i,r){var n,o;h(c(e),"client.track - expected event name to be an string"),h(l(t),"client.track - expected customer to be an object");const a={event:e,metadata:null!=s?s:{},customer:t,referral:null!=i?i:void 0,loyalty:null!=r?r:void 0};return a.customer.source_id=null!=(n=t.source_id)?n:this.trackingId,h(c(null==(o=a.customer)?void 0:o.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",a)}listVouchers(e={}){const 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/${o(e)}/consents`,t)}validateStackable(e){return this.client.post("/validations",e)}redeemStackable(e){return this.client.post("/redemptions",e)}}e.VoucherifyClientSide=function(e){var t;h(l(e),'VoucherifyCustomer: expected "options" argument to be an object'),h(c(e.clientApplicationId),'VoucherifyCustomer: "options.clientApplicationId" is required'),h(c(e.clientSecretKey),'VoucherifyCustomer: "options.clientSecretKey" is required'),h(a(e.apiUrl),'VoucherifyCustomer: expected "options.baseUrl" to be a string'),h(a(e.trackingId),'VoucherifyCustomer: expected "options.trackingId" to be a string');let s={"X-Client-Application-Id":e.clientApplicationId,"X-Client-Token":e.clientSecretKey,"X-Voucherify-Channel":d()+"-ClientSide-SDK-v2.0.7"};d().startsWith("Node")&&(h(c(e.origin),'VoucherifyCustomer: "options.origin" is required in Node.js'),s.origin=e.origin),l(e.customHeaders)&&(s=Object.assign({},s,e.customHeaders));const i=new n({basePath:"client/v1",baseURL:null!=(t=e.apiUrl)?t:"https://api.voucherify.io",headers:s});return new E(i,e.trackingId)},e.VoucherifyServerSide=function(e){var t;h(l(e),'VoucherifyServerSide: the "options" argument must be an object'),h(c(e.applicationId),'VoucherifyServerSide: "options.applicationId" is required'),h(c(e.secretKey),'VoucherifyServerSide: "options.secretKey" is required'),h(a(e.apiVersion),'VoucherifyServerSide: expected "options.apiVersion" to be a string'),h(a(e.channel),'VoucherifyServerSide: expected "options.channel" to be a string');let s={"X-App-Id":e.applicationId,"X-App-Token":e.secretKey,"X-Voucherify-Channel":e.channel||d()+"-SDK-v2.0.7","Content-Type":"application/json"};e.apiVersion&&(s["X-Voucherify-API-Version"]=e.apiVersion),l(e.customHeaders)&&(s=Object.assign({},s,e.customHeaders)),d().startsWith("Node")||h(!0===e.dangerouslySetSecretKeyInBrowser,`VoucherifyServerSide: you're exposing your secretKey to a ${d().toLowerCase()} environment. This is generally considered a bad practice. Did you mean to use 'VoucherifyClientSide'?`);const i=new n({basePath:"v1",baseURL:null!=(t=e.apiUrl)?t:"https://api.voucherify.io",headers:s}),r=new m(i),o=new $(i),u=new S(i,o),p=new v(i),g=new f(i),y=new w(i),k=new b(i,g),E=new V(i),T=new x(i,E);return{vouchers:u,campaigns:p,distributions:k,validations:new R(i,T),redemptions:new _(i),promotions:T,customers:new j(i),consents:new C(i),orders:new L(i),products:new A(i),rewards:new I(i),loyalties:new q(i),segments:new U(i),validationRules:new H(i),events:y,asyncActions:r,apiLimitsHandler:new O(i),metadataSchemas:new P(i)}},Object.defineProperty(e,"__esModule",{value:!0})}));
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("axios"),require("qs")):"function"==typeof define&&define.amd?define(["exports","axios","qs"],t):t((e=e||self).VoucherifySDK={},e.axios,e.Qs)}(this,(function(e,t,s){"use strict";var i;t=t&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t,s=s&&Object.prototype.hasOwnProperty.call(s,"default")?s.default:s,(i=e.DiscountVouchersTypesEnum||(e.DiscountVouchersTypesEnum={})).AMOUNT="AMOUNT",i.PERCENT="PERCENT",i.UNIT="UNIT",i.FIXED="FIXED";class r extends Error{constructor(e,t){var s,i;super((null==(i=t=null!=(s=t)?s:{})?void 0:i.message)||function(e,t){return`Unexpected status code: ${t} - Details: ${e="string"==typeof e?e:JSON.stringify(e,null,2)}`}(t,e)),Object.assign(this,t)}}class n{constructor({basePath:e,baseURL:s,headers:i}){this.baseURL=void 0,this.basePath=void 0,this.headers=void 0,this.request=void 0,this.lastResponseHeaders=void 0,this.isLastResponseHeadersSet=void 0,this.basePath=e,this.baseURL=s,this.headers=i,this.lastResponseHeaders={},this.isLastResponseHeadersSet=!1,this.request=t.create({baseURL:`${this.baseURL}/${this.basePath}/`,headers:this.headers,responseType:"json"}),this.request.interceptors.response.use(void 0,e=>{var t;return null!=e&&null!=(t=e.response)&&t.status?Promise.reject(new r(e.response.status,e.response.data)):Promise.reject(e)})}isLastReponseHeadersSet(){return this.isLastResponseHeadersSet}getLastResponseHeaders(){return this.lastResponseHeaders}setLastResponseHeaders(e){this.lastResponseHeaders=e,this.isLastResponseHeadersSet=!0}setBaseUrl(e){this.baseURL=e,this.request.defaults.baseURL=`${e}/${this.basePath}/`}async get(e,t){const i=await this.request.get(e,{params:t,paramsSerializer:function(e){return s.stringify(e)}});return this.setLastResponseHeaders(i.headers),i.data}async post(e,t,i,r){const n=await this.request.post(e,t,{params:i,paramsSerializer:function(e){return s.stringify(e)},headers:r});return this.setLastResponseHeaders(n.headers),n.data}async put(e,t,s){const i=await this.request.put(e,t,{params:s});return this.setLastResponseHeaders(i.headers),i.data}async delete(e,t){const s=await this.request.delete(e,{params:t});return this.setLastResponseHeaders(s.headers),s.data}}function o(e=""){return encodeURIComponent(e)}function c(e){return"string"==typeof e}function a(e){return null==e||c(e)}function l(e){return"object"==typeof e&&!Array.isArray(e)&&null!==e}function u(e){return null==e||l(e)}function d(){return"undefined"!=typeof window&&void 0!==window.document?"Browser":"object"==typeof self&&self.constructor&&"DedicatedWorkerGlobalScope"===self.constructor.name?"WebWorker":"undefined"!=typeof process&&null!=process.versions&&null!=process.versions.node?"Node.js-"+process.version:"undefined"!=typeof window&&"nodejs"===window.name||navigator.userAgent.includes("Node.js")||navigator.userAgent.includes("jsdom")?"JsDom":"Unknown"}function h(e,t){if(!e)throw new Error(t)}function p(e,t){return Object.fromEntries(Object.entries(e).filter(([e])=>!t.includes(e)))}class m{constructor(e){this.client=void 0,this.client=e}get(e){return this.client.get("/async-actions/"+o(e))}list(e){return this.client.get("/async-actions",e)}}class g{constructor(e){this.client=void 0,this.client=e}examine(e={},t){return this.client.post("/campaigns/qualification",e,t)}}class v{constructor(e){this.client=void 0,this.qualifications=void 0,this.client=e,this.qualifications=new g(this.client)}create(e){return this.client.post("/campaigns",e)}update(e,t){return this.client.put("/campaigns/"+o(e),t)}get(e){return this.client.get("/campaigns/"+o(e))}delete(e,t={}){return this.client.delete("/campaigns/"+o(e),t)}addVoucher(e,t={},s={}){return this.client.post(`/campaigns/${o(e)}/vouchers`,t,s)}addCertainVoucher(e,t,s={}){return this.client.post(`/campaigns/${o(e)}/vouchers/${o(t)}`,s)}importVouchers(e,t){return this.client.post(`/campaigns/${o(e)}/import`,t)}list(e={}){return this.client.get("/campaigns",e)}}class y{constructor(e){this.client=void 0,this.client=e}list(e={}){return this.client.get("/publications",e)}create(e){return this.client.post("/publications",e)}}class b{constructor(e,t){this.client=void 0,this.exports=void 0,this.publications=void 0,this.client=e,this.exports=t,this.publications=new y(this.client)}}class f{constructor(e){this.client=void 0,this.client=e}create(e){return this.client.post("/exports",e)}get(e){return this.client.get("/exports/"+o(e))}delete(e){return this.client.delete("/exports/"+o(e))}}class w{constructor(e){this.client=void 0,this.client=e}create(e,t){return t={...t,event:e},this.client.post("/events",t)}}class ${constructor(e){this.client=void 0,this.client=e}create(e,t){return this.client.post(`/vouchers/${o(e)}/balance`,t)}}class k{constructor(e){this.client=void 0,this.client=e}examine(e,t={}){return this.client.post("/vouchers/qualification",e,t)}}class S{constructor(e,t){this.client=void 0,this.balance=void 0,this.qualifications=void 0,this.client=e,this.balance=t,this.qualifications=new k(this.client)}create(e){return this.client.post("/vouchers/"+o(e.code),e)}get(e){return this.client.get("/vouchers/"+o(e))}update(e){return this.client.put("/vouchers/"+o(e.code),e)}delete(e,t={}){return this.client.delete("/vouchers/"+o(e),t)}list(e={}){return this.client.get("/vouchers",e)}enable(e){return this.client.post(`/vouchers/${o(e)}/enable`,{})}disable(e){return this.client.post(`/vouchers/${o(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/${o(e)}/sessions/${o(t)}`)}}class R{constructor(e,t){this.client=void 0,this.promotions=void 0,this.client=e,this.promotions=t}validateVoucher(e,t={}){return this.client.post(`/vouchers/${o(e)}/validate`,t)}validate(e,t={}){return l(e)?this.promotions.validate(e):this.validateVoucher(e,t)}validateStackable(e){return this.client.post("/validations",e)}}class _{constructor(e){this.client=void 0,this.client=e}redeem(e,t={}){return this.client.post(`/vouchers/${o(e)}/redemption`,t)}redeemStackable(e){return this.client.post("/redemptions",e)}get(e){return this.client.get("/redemptions/"+o(e))}list(e={}){return this.client.get("/redemptions",e)}getForVoucher(e){return this.client.get(`/vouchers/${o(e)}/redemption`)}rollback(e,t){let s={},i={};if(c(t))s.reason=t;else if(l(t)){const{reason:e,tracking_id:r,customer:n}=t;s={reason:e||void 0,tracking_id:r||void 0},i={customer:n}}return this.client.post(`/redemptions/${o(e)}/rollback`,i,s)}rollbackStackable(e,t,s){return this.client.post(`/redemptions/${o(e)}/rollbacks`,t,s)}}class V{constructor(e){this.client=void 0,this.client=e}listAll(e={}){return this.client.get("/promotions/tiers",e)}list(e){return this.client.get(`/promotions/${o(e)}/tiers`)}create(e,t){return this.client.post(`/promotions/${o(e)}/tiers`,t)}redeem(e,t){return this.client.post(`/promotions/tiers/${o(e)}/redemption`,t)}update(e){return this.client.put("/promotions/tiers/"+o(e.id),e)}delete(e){return this.client.delete("/promotions/tiers/"+o(e))}}class x{constructor(e,t){this.client=void 0,this.tiers=void 0,this.client=e,this.tiers=t}create(e){return this.client.post("/campaigns",e)}validate(e,t){return this.client.post("/promotions/validation",e,t)}}class j{constructor(e){this.client=void 0,this.client=e}create(e){return this.client.post("/customers",e)}get(e){return this.client.get("/customers/"+o(e))}list(e){return this.client.get("/customers",e)}async*scroll(e){var t;let s=null!=(t=e.starting_after)?t:"created_at"===e.order?"1970-01-01T00:00:00Z":"2200-01-01T00:00:00Z",i=await this.client.get("/customers",Object.assign({},e,{starting_after:s}));for(;0!==i.customers.length;){for(const t of i.customers)s="created_at"===e.order?s>t.created_at?s:t.created_at:s<t.created_at?s:t.created_at,yield t;if(!i.has_more)break;i=await this.client.get("/customers",Object.assign({},e,{starting_after:s}))}}update(e){const t="id"in e?e.id:e.source_id,s=p(e,["id"]);return this.client.put("/customers/"+o(t),s)}delete(e){return this.client.delete("/customers/"+o(e))}updateConsents(e,t){return this.client.put(`/customers/${o(e)}/consents`,t)}listActivities(e,t){return this.client.get(`/customers/${o(e)}/activities`,t)}}class C{constructor(e){this.client=void 0,this.client=e}list(){return this.client.get("/consents")}}class L{constructor(e){this.client=void 0,this.client=e}create(e){return this.client.post("/orders",e)}get(e){return this.client.get("/orders/"+o(e))}update(e){return this.client.put("/orders/"+o(e.id||e.source_id),p(e,["id"]))}list(e={}){return this.client.get("/orders",e)}}class A{constructor(e){this.client=void 0,this.client=e}create(e){return this.client.post("/products",e)}get(e){return this.client.get("/products/"+o(e))}update(e){return this.client.put("/products/"+o(e.id||e.source_id),p(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/"+o(e),t)}list(e){return this.client.get("/products",e)}createSku(e,t){return this.client.post(`/products/${o(e)}/skus`,t)}getSku(e){return this.client.get("/skus/"+o(e))}updateSku(e,t){return this.client.put(`/products/${o(e)}/skus/${o(t.id||t.source_id)}`,p(t,["id"]))}deleteSku(e,t,s){return this.client.delete(`/products/${o(e)}/skus/${o(t)}`,s)}listSkus(e){return this.client.get(`/products/${o(e)}/skus`)}}class I{constructor(e){this.client=void 0,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/"+o(e))}update(e){return this.client.put("/rewards/"+o(e.id),p(e,["id"]))}delete(e){return this.client.delete("/rewards/"+o(e))}listAssignments(e,t={}){return this.client.get(`/rewards/${o(e)}/assignments`,t)}createAssignment(e,t){return this.client.post(`/rewards/${o(e)}/assignments`,t)}updateAssignment(e,t){return this.client.put(`/rewards/${o(e)}/assignments/${o(t.id)}`,p(t,["id"]))}deleteAssignment(e,t){return this.client.delete(`/rewards/${o(e)}/assignments/${o(t)}`)}}class q{constructor(e){this.client=void 0,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/"+o(e))}update(e){return this.client.put("/loyalties/"+o(e.id),p(e,["id"]))}delete(e,t){return this.client.delete("/loyalties/"+o(e),t)}listRewardAssignments(e,t={}){return this.client.get(`/loyalties/${o(e)}/rewards`,t)}createRewardAssignments(e,t){return this.client.post(`/loyalties/${o(e)}/rewards`,t)}updateRewardAssignment(e,t){return this.client.put(`/loyalties/${o(e)}/rewards/${t.id}`,p(t,["id"]))}deleteRewardAssignment(e,t){return this.client.delete(`/loyalties/${o(e)}/rewards/${t}`)}listEarningRules(e,t={}){return this.client.get(`/loyalties/${o(e)}/earning-rules`,t)}createEarningRule(e,t){return this.client.post(`/loyalties/${o(e)}/earning-rules`,t)}updateEarningRule(e,t){return this.client.put(`/loyalties/${o(e)}/earning-rules/${t.id}`,p(t,["id"]))}deleteEarningRule(e,t){return this.client.delete(`/loyalties/${o(e)}/earning-rules/${t}`)}listMembers(e,t){return this.client.get(`/loyalties/${o(e)}/members`,t)}createMember(e,t){return this.client.post(`/loyalties/${o(e)}/members`,t)}getMember(e,t){return this.client.get(`/loyalties/${o(e)}/members/${t}`)}getMemberActivities(e,t){return this.client.get(`/loyalties/${o(e)}/members/${t}/activities`)}addPoints(e,t,s){return this.client.post(`/loyalties/${o(e)}/members/${t}/balance`,s)}redeemReward(e,t,s){return this.client.post(`/loyalties/${o(e)}/members/${o(t)}/redemption`,s)}}class H{constructor(e){this.client=void 0,this.client=e}create(e){return this.client.post("/validation-rules",e)}get(e){return this.client.get("/validation-rules/"+o(e))}update(e){return this.client.put("/validation-rules/"+o(e.id),p(e,["id"]))}delete(e){return this.client.delete("/validation-rules/"+o(e))}createAssignment(e,t){return this.client.post(`/validation-rules/${o(e)}/assignments`,t)}deleteAssignment(e,t){return this.client.delete(`/validation-rules/${o(e)}/assignments/${o(t)}`)}validate(e,t={}){return this.client.post(`/validation-rules/${o(e)}/validation`,t)}list(e={}){return this.client.get("/validation-rules",e)}listAssignments(e,t={}){return this.client.get(`/validation-rules/${o(e)}/assignments`,t)}}class U{constructor(e){this.client=void 0,this.client=e}create(e){return this.client.post("/segments",e)}get(e){return this.client.get("/segments/"+o(e))}delete(e){return this.client.delete("/segments/"+o(e))}list(e){return this.client.get(`/customers/${o(e)}/segments`)}}class O{constructor(e){this.requestController=void 0,this.requestController=e}getLastResponseHeadersFromController(){return this.requestController.getLastResponseHeaders()}areLimitsAvailable(){return this.requestController.isLastReponseHeadersSet()}getRateLimit(){var e;const t=null!=(e=this.getLastResponseHeadersFromController()["x-rate-limit-limit"])?e:0;return parseInt(t,10)}getRateLimitRemaining(){var e;const t=null!=(e=this.getLastResponseHeadersFromController()["x-rate-limit-remaining"])?e:0;return parseInt(t,10)}}class P{constructor(e){this.client=void 0,this.client=e}list(){return this.client.get("/metadata-schemas")}get(e){return this.client.get("/metadata-schemas/"+o(e))}}class E{constructor(e,t){this.client=void 0,this.trackingId=void 0,this.client=e,this.trackingId=t}setIdentity(e){this.trackingId=e}validate(e){var t,s;h(l(e)||c(e),'client.validate: expected "params" argument to be an object or a string');const i={};return c(e)?i.code=e:(i.code=e.code,i.item=e.items,i.amount=e.amount,i.metadata=e.metadata,i.order={metadata:e.orderMetadata},i.customer=e.customer,i.tracking_id=e.tracking_id||this.trackingId,i.session_type=e.session_type,i.session_key=e.session_key,i.session_ttl=e.session_ttl,i.session_ttl_unit=e.session_ttl_unit),i.code&&(i.code=i.code.replace(/[\r\n\t\f\v]/g,"").trim()),h(u(null==i?void 0:i.customer),'client.validate: expected "params.customer" to be an object'),h(a(null==i||null==(t=i.customer)?void 0:t.source_id),'client.validate: expected "params.customer.source_id" to be a string'),h(u(null==i||null==(s=i.customer)?void 0:s.metadata),'client.validate: expected "params.customer.metadata" to be an object'),this.client.get(i.code?"/validate":"/promotions/validation",i)}redeem(e,t={}){var s,i;return h(c(e),"client.redeem - please provide a valid Voucher code"),e=e.replace(/[\r\n\t\f\v]/g,"").trim(),t.customer=null!=(s=t.customer)?s:{},t.customer.source_id=null!=(i=t.customer.source_id)?i:this.trackingId,this.client.post("/redeem",t,{code:e})}publish(e,t={},s={}){var i,r,n,o,a;h(l(t),"client.publish - expected payload to be an object");const u={};return u.customer=null!=(i=t.customer)?i:{},u.customer.source_id=null!=(r=null==(n=t.customer)?void 0:n.source_id)?r:this.trackingId,u.channel=null!=(o=t.channel)?o:"Voucherify.js",h(c(null==(a=u.customer)?void 0:a.source_id),"client.publish - expected payload to contain customer source id or to have tracking id set up by Voucherify client"),s.campaign=e.replace(/[\r\n\t\f\v]/g,"").trim(),this.client.post("/publish",u,s)}track(e,t,s,i,r){var n,o;h(c(e),"client.track - expected event name to be an string"),h(l(t),"client.track - expected customer to be an object");const a={event:e,metadata:null!=s?s:{},customer:t,referral:null!=i?i:void 0,loyalty:null!=r?r:void 0};return a.customer.source_id=null!=(n=t.source_id)?n:this.trackingId,h(c(null==(o=a.customer)?void 0:o.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",a)}listVouchers(e={}){const 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/${o(e)}/consents`,t)}validateStackable(e){return this.client.post("/validations",e)}redeemStackable(e){return this.client.post("/redemptions",e)}}e.VoucherifyClientSide=function(e){var t;h(l(e),'VoucherifyCustomer: expected "options" argument to be an object'),h(c(e.clientApplicationId),'VoucherifyCustomer: "options.clientApplicationId" is required'),h(c(e.clientSecretKey),'VoucherifyCustomer: "options.clientSecretKey" is required'),h(a(e.apiUrl),'VoucherifyCustomer: expected "options.baseUrl" to be a string'),h(a(e.trackingId),'VoucherifyCustomer: expected "options.trackingId" to be a string');let s={"X-Client-Application-Id":e.clientApplicationId,"X-Client-Token":e.clientSecretKey,"X-Voucherify-Channel":d()+"-ClientSide-SDK-v2.0.8"};d().startsWith("Node")&&(h(c(e.origin),'VoucherifyCustomer: "options.origin" is required in Node.js'),s.origin=e.origin),l(e.customHeaders)&&(s=Object.assign({},s,e.customHeaders));const i=new n({basePath:"client/v1",baseURL:null!=(t=e.apiUrl)?t:"https://api.voucherify.io",headers:s});return new E(i,e.trackingId)},e.VoucherifyServerSide=function(e){var t;h(l(e),'VoucherifyServerSide: the "options" argument must be an object'),h(c(e.applicationId),'VoucherifyServerSide: "options.applicationId" is required'),h(c(e.secretKey),'VoucherifyServerSide: "options.secretKey" is required'),h(a(e.apiVersion),'VoucherifyServerSide: expected "options.apiVersion" to be a string'),h(a(e.channel),'VoucherifyServerSide: expected "options.channel" to be a string');let s={"X-App-Id":e.applicationId,"X-App-Token":e.secretKey,"X-Voucherify-Channel":e.channel||d()+"-SDK-v2.0.8","Content-Type":"application/json"};e.apiVersion&&(s["X-Voucherify-API-Version"]=e.apiVersion),l(e.customHeaders)&&(s=Object.assign({},s,e.customHeaders)),d().startsWith("Node")||h(!0===e.dangerouslySetSecretKeyInBrowser,`VoucherifyServerSide: you're exposing your secretKey to a ${d().toLowerCase()} environment. This is generally considered a bad practice. Did you mean to use 'VoucherifyClientSide'?`);const i=new n({basePath:"v1",baseURL:null!=(t=e.apiUrl)?t:"https://api.voucherify.io",headers:s}),r=new m(i),o=new $(i),u=new S(i,o),p=new v(i),g=new f(i),y=new w(i),k=new b(i,g),E=new V(i),T=new x(i,E);return{vouchers:u,campaigns:p,distributions:k,validations:new R(i,T),redemptions:new _(i),promotions:T,customers:new j(i),consents:new C(i),orders:new L(i),products:new A(i),rewards:new I(i),loyalties:new q(i),segments:new U(i),validationRules:new H(i),events:y,asyncActions:r,apiLimitsHandler:new O(i),metadataSchemas:new P(i)}},Object.defineProperty(e,"__esModule",{value:!0})}));
2
2
  //# sourceMappingURL=voucherifysdk.umd.production.min.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voucherify/sdk",
3
- "version": "2.0.7",
3
+ "version": "2.0.8",
4
4
  "description": "Official Voucherify JS SDK",
5
5
  "author": "Voucherify",
6
6
  "license": "MIT",