@voucherify/sdk 2.7.2 → 2.7.3
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 +6 -0
- package/dist/types/Categories.d.ts +1 -0
- package/dist/types/Redemptions.d.ts +3 -1
- package/dist/types/Stackable.d.ts +33 -0
- package/dist/types/Validations.d.ts +15 -1
- package/dist/voucherifysdk.esm.js +2 -2
- package/dist/voucherifysdk.umd.development.js +2 -2
- package/dist/voucherifysdk.umd.production.min.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @voucherify/sdk
|
|
2
2
|
|
|
3
|
+
## 2.7.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`d532cc4`](https://github.com/voucherifyio/voucherify-js-sdk/commit/d532cc4dd6ccc1ea6cab120b8a3cec7d86598ffd) [#270](https://github.com/voucherifyio/voucherify-js-sdk/pull/270) Thanks [@p-zielinski](https://github.com/p-zielinski)! - Type support for partial redemptions. General update to responses of /validations and /redemptions endpoints.
|
|
8
|
+
|
|
3
9
|
## 2.7.2
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
|
@@ -4,7 +4,7 @@ import { CustomersCreateBody, SimpleCustomer } from './Customers';
|
|
|
4
4
|
import { VouchersResponse } from './Vouchers';
|
|
5
5
|
import { GiftRedemptionParams } from './Gift';
|
|
6
6
|
import { ValidationSessionParams, ValidationSessionReleaseParams } from './ValidateSession';
|
|
7
|
-
import { StackableOptions, StackableRedeemableParams } from './Stackable';
|
|
7
|
+
import { StackableOptions, StackableRedeemableInapplicableResponse, StackableRedeemableParams, StackableRedeemableSkippedResponse } from './Stackable';
|
|
8
8
|
import { PromotionTierRedeemDetailsSimple, PromotionTierRedeemDetails } from './PromotionTiers';
|
|
9
9
|
export interface RedemptionsRedeemBody {
|
|
10
10
|
tracking_id?: string;
|
|
@@ -185,6 +185,8 @@ export interface RedemptionsRedeemStackableResponse {
|
|
|
185
185
|
related_object_id: string;
|
|
186
186
|
};
|
|
187
187
|
order?: RedemptionsRedeemStackableOrderResponse;
|
|
188
|
+
skipped_redeemables?: StackableRedeemableSkippedResponse;
|
|
189
|
+
inapplicable_redeemables?: StackableRedeemableInapplicableResponse;
|
|
188
190
|
}
|
|
189
191
|
export interface RedemptionsRollbackStackableResponse {
|
|
190
192
|
rollbacks: RedemptionsRedeemStackableRedemptionResult[];
|
|
@@ -6,6 +6,7 @@ import { DiscountVouchersTypes, DiscountVouchersEffectTypes, DiscountUnitVoucher
|
|
|
6
6
|
import { SimpleProduct, SimpleSku } from './Products';
|
|
7
7
|
import { LoyaltyPointsTransfer } from './Loyalties';
|
|
8
8
|
import { ValidationError } from './ValidationError';
|
|
9
|
+
import { Category } from './Categories';
|
|
9
10
|
declare type ExpandOption = 'order' | 'redeemable' | 'redemption';
|
|
10
11
|
export interface StackableOptions {
|
|
11
12
|
expand: ExpandOption[];
|
|
@@ -54,6 +55,10 @@ export interface StackableRedeemableResultResponse {
|
|
|
54
55
|
gift?: StackableRedeemableResultGift;
|
|
55
56
|
loyalty_card?: StackableRedeemableResultLoyaltyCard;
|
|
56
57
|
error?: ValidationError;
|
|
58
|
+
details?: {
|
|
59
|
+
key?: string;
|
|
60
|
+
message?: string;
|
|
61
|
+
};
|
|
57
62
|
}
|
|
58
63
|
export interface StackableRedeemableResponse {
|
|
59
64
|
status: StackableRedeemableResponseStatus;
|
|
@@ -64,5 +69,33 @@ export interface StackableRedeemableResponse {
|
|
|
64
69
|
inapplicable_to?: ApplicableToResultList;
|
|
65
70
|
result?: StackableRedeemableResultResponse;
|
|
66
71
|
metadata?: Record<string, any>;
|
|
72
|
+
categories?: Category[];
|
|
67
73
|
}
|
|
74
|
+
export declare type StackableRedeemableInapplicableResponse = {
|
|
75
|
+
status: 'INAPPLICABLE';
|
|
76
|
+
id: string;
|
|
77
|
+
object: 'voucher' | 'promotion_tier';
|
|
78
|
+
result: {
|
|
79
|
+
error?: ValidationError;
|
|
80
|
+
details?: {
|
|
81
|
+
key?: string;
|
|
82
|
+
message?: string;
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
metadata?: Record<string, unknown>;
|
|
86
|
+
categories?: Category[];
|
|
87
|
+
};
|
|
88
|
+
export declare type StackableRedeemableSkippedResponse = {
|
|
89
|
+
status: 'SKIPPED';
|
|
90
|
+
id: string;
|
|
91
|
+
object: 'voucher' | 'promotion_tier';
|
|
92
|
+
result: {
|
|
93
|
+
details?: {
|
|
94
|
+
key?: string;
|
|
95
|
+
message?: string;
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
metadata?: Record<string, unknown>;
|
|
99
|
+
categories?: Category[];
|
|
100
|
+
};
|
|
68
101
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DiscountAmount, DiscountPercent, DiscountUnit, DiscountFixed } from './DiscountVoucher';
|
|
2
2
|
import { CustomersCreateBody } from './Customers';
|
|
3
|
-
import { StackableOptions, StackableRedeemableParams, StackableRedeemableResponse } from './Stackable';
|
|
3
|
+
import { StackableOptions, StackableRedeemableInapplicableResponse, StackableRedeemableParams, StackableRedeemableResponse, StackableRedeemableSkippedResponse } from './Stackable';
|
|
4
4
|
import { ValidationSessionParams, ValidationSessionResponse } from './ValidateSession';
|
|
5
5
|
import { ApplicableToResultList } from './ApplicableTo';
|
|
6
6
|
import { ValidationError } from './ValidationError';
|
|
@@ -79,6 +79,20 @@ export interface ValidationValidateStackableResponse {
|
|
|
79
79
|
session?: ValidationSessionResponse;
|
|
80
80
|
order?: OrdersCreateResponse;
|
|
81
81
|
redeemables?: StackableRedeemableResponse[];
|
|
82
|
+
skipped_redeemables?: StackableRedeemableSkippedResponse;
|
|
83
|
+
inapplicable_redeemables?: StackableRedeemableInapplicableResponse;
|
|
84
|
+
stacking_rules: ValidationsStackingRules;
|
|
82
85
|
}
|
|
86
|
+
export declare type ValidationsStackingRules = {
|
|
87
|
+
redeemables_limit: number;
|
|
88
|
+
applicable_redeemables_limit: number;
|
|
89
|
+
applicable_redeemables_per_category_limit?: number;
|
|
90
|
+
applicable_exclusive_redeemables_limit: number;
|
|
91
|
+
applicable_exclusive_redeemables_per_category_limit?: number;
|
|
92
|
+
exclusive_categories: string[];
|
|
93
|
+
joint_categories: string[];
|
|
94
|
+
redeemables_application_mode: 'ALL' | 'PARTIAL';
|
|
95
|
+
redeemables_sorting_rule: 'CATEGORY_HIERARCHY' | 'REQUESTED_ORDER';
|
|
96
|
+
};
|
|
83
97
|
export declare type ValidationsValidateCode = PromotionsValidateParams;
|
|
84
98
|
export declare type ValidationsValidateContext = ValidationsValidateVoucherParams;
|
|
@@ -1952,7 +1952,7 @@ function VoucherifyServerSide(options) {
|
|
|
1952
1952
|
let headers = {
|
|
1953
1953
|
'X-App-Id': options.applicationId,
|
|
1954
1954
|
'X-App-Token': options.secretKey,
|
|
1955
|
-
'X-Voucherify-Channel': options.channel || `${environment()}-SDK-v${"2.7.
|
|
1955
|
+
'X-Voucherify-Channel': options.channel || `${environment()}-SDK-v${"2.7.3"}`,
|
|
1956
1956
|
'Content-Type': 'application/json'
|
|
1957
1957
|
};
|
|
1958
1958
|
|
|
@@ -2218,7 +2218,7 @@ function VoucherifyClientSide(options) {
|
|
|
2218
2218
|
let headers = {
|
|
2219
2219
|
'X-Client-Application-Id': options.clientApplicationId,
|
|
2220
2220
|
'X-Client-Token': options.clientSecretKey,
|
|
2221
|
-
'X-Voucherify-Channel': `${environment()}-ClientSide-SDK-v${"2.7.
|
|
2221
|
+
'X-Voucherify-Channel': `${environment()}-ClientSide-SDK-v${"2.7.3"}`
|
|
2222
2222
|
};
|
|
2223
2223
|
|
|
2224
2224
|
if (environment().startsWith('Node')) {
|
|
@@ -1956,7 +1956,7 @@
|
|
|
1956
1956
|
let headers = {
|
|
1957
1957
|
'X-App-Id': options.applicationId,
|
|
1958
1958
|
'X-App-Token': options.secretKey,
|
|
1959
|
-
'X-Voucherify-Channel': options.channel || `${environment()}-SDK-v${"2.7.
|
|
1959
|
+
'X-Voucherify-Channel': options.channel || `${environment()}-SDK-v${"2.7.3"}`,
|
|
1960
1960
|
'Content-Type': 'application/json'
|
|
1961
1961
|
};
|
|
1962
1962
|
|
|
@@ -2222,7 +2222,7 @@
|
|
|
2222
2222
|
let headers = {
|
|
2223
2223
|
'X-Client-Application-Id': options.clientApplicationId,
|
|
2224
2224
|
'X-Client-Token': options.clientSecretKey,
|
|
2225
|
-
'X-Voucherify-Channel': `${environment()}-ClientSide-SDK-v${"2.7.
|
|
2225
|
+
'X-Voucherify-Channel': `${environment()}-ClientSide-SDK-v${"2.7.3"}`
|
|
2226
2226
|
};
|
|
2227
2227
|
|
|
2228
2228
|
if (environment().startsWith('Node')) {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("axios"),require("qs"),require("form-data")):"function"==typeof define&&define.amd?define(["exports","axios","qs","form-data"],e):e((t=t||self).VoucherifySDK={},t.axios,t.Qs,t.FormData)}(this,(function(t,e,s,i){"use strict";var r;e=e&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e,s=s&&Object.prototype.hasOwnProperty.call(s,"default")?s.default:s,i=i&&Object.prototype.hasOwnProperty.call(i,"default")?i.default:i,(r=t.DiscountVouchersTypesEnum||(t.DiscountVouchersTypesEnum={})).AMOUNT="AMOUNT",r.PERCENT="PERCENT",r.UNIT="UNIT",r.FIXED="FIXED";class n extends Error{constructor(t,e,s){var i,r;super((null==(r=e=null!=(i=e)?i:{})?void 0:r.message)||function(t,e){return`Unexpected status code: ${e} - Details: ${t="string"==typeof t?t:JSON.stringify(t,null,2)}`}(e,t)),this.code=void 0,this.key=void 0,this.details=void 0,this.request_id=void 0,this.resource_id=void 0,this.resource_type=void 0,this.related_object_ids=void 0,this.related_object_type=void 0,this.related_object_total=void 0,this.error=void 0,this.cause=void 0,this.code=e.code,this.key=e.key,this.details=e.details,this.request_id=e.request_id,this.resource_id=e.resource_id,this.resource_type=e.resource_type,this.related_object_ids=e.related_object_ids,this.related_object_type=e.related_object_type,this.related_object_total=e.related_object_total,this.error=e.error,this.cause=s}}class o{constructor({basePath:t,baseURL:s,headers:i,exposeErrorCause:r,timeoutMs:o}){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.exposeErrorCause=void 0,this.timeoutMs=void 0,this.basePath=t,this.baseURL=s,this.headers=i,this.exposeErrorCause=r,this.lastResponseHeaders={},this.isLastResponseHeadersSet=!1,this.timeoutMs=o,this.request=e.create({baseURL:`${this.baseURL}/${this.basePath}/`,headers:this.headers,responseType:"json"}),this.request.interceptors.response.use(void 0,t=>{var e;return null!=t&&null!=(e=t.response)&&e.status?Promise.reject(new n(t.response.status,t.response.data,!0===this.exposeErrorCause?t:void 0)):Promise.reject(t)})}isLastReponseHeadersSet(){return this.isLastResponseHeadersSet}getLastResponseHeaders(){return this.lastResponseHeaders}setLastResponseHeaders(t){const e={};for(const s in t)e[s]=String(t[s]);this.lastResponseHeaders=e,this.isLastResponseHeadersSet=!0}setBaseUrl(t){this.baseURL=t,this.request.defaults.baseURL=`${t}/${this.basePath}/`}async get(t,e){const i=await this.request.get(t,{params:e,paramsSerializer:function(t){return s.stringify(t)},timeout:this.timeoutMs});return this.setLastResponseHeaders(i.headers),i.data}async post(t,e,i,r){const n=await this.request.post(t,e,{params:i,paramsSerializer:function(t){return s.stringify(t)},headers:r,timeout:this.timeoutMs});return this.setLastResponseHeaders(n.headers),n.data}async put(t,e,s){const i=await this.request.put(t,e,{params:s,timeout:this.timeoutMs});return this.setLastResponseHeaders(i.headers),i.data}async delete(t,e){const s=await this.request.delete(t,{params:e,timeout:this.timeoutMs});return this.setLastResponseHeaders(s.headers),s.data}}function a(t=""){return encodeURIComponent(t)}function c(t){return"string"==typeof t}function l(t){return null==t||c(t)}function u(t){return"object"==typeof t&&!Array.isArray(t)&&null!==t}function d(t){return null==t||u(t)}function h(){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 p(t,e){if(!t)throw new Error(e)}function m(t,e){return Object.fromEntries(Object.entries(t).filter(([t])=>!e.includes(t)))}class g{constructor(t){this.client=void 0,this.client=t}get(t){return this.client.get("/async-actions/"+a(t))}list(t){return this.client.get("/async-actions",t)}}class v{constructor(t){this.client=void 0,this.client=t}examine(t={},e){return this.client.post("/campaigns/qualification",t,e)}}class y{constructor(t){this.client=void 0,this.qualifications=void 0,this.client=t,this.qualifications=new v(this.client)}create(t){return this.client.post("/campaigns",t)}update(t,e){return this.client.put("/campaigns/"+a(t),e)}get(t){return this.client.get("/campaigns/"+a(t))}delete(t,e={}){return this.client.delete("/campaigns/"+a(t),e)}addVoucher(t,e={},s={}){return this.client.post(`/campaigns/${a(t)}/vouchers`,e,s)}addCertainVoucher(t,e,s={}){return this.client.post(`/campaigns/${a(t)}/vouchers/${a(e)}`,s)}importVouchers(t,e){return this.client.post(`/campaigns/${a(t)}/import`,e)}list(t={}){return this.client.get("/campaigns",t)}async importVouchersCSV(t,e){p(h().startsWith("Node"),'Method "client.campaigns.importVouchersCSV(campaignId, filePath)" is only for Node environment');const s=(await import("fs")).default.createReadStream(e),r=new i;return r.append("file",s),this.client.post(`/campaigns/${t}/importCSV`,r,void 0,{"Content-Type":"multipart/form-data"})}enable(t){return this.client.post(`/campaigns/${a(t)}/enable`,{})}disable(t){return this.client.post(`/campaigns/${a(t)}/disable`,{})}}class b{constructor(t){this.client=void 0,this.client=t}list(t={}){return this.client.get("/publications",t)}create(t){return this.client.post("/publications",t)}}class f{constructor(t,e){this.client=void 0,this.exports=void 0,this.publications=void 0,this.client=t,this.exports=e,this.publications=new b(this.client)}}class ${constructor(t){this.client=void 0,this.client=t}create(t){return this.client.post("/exports",t)}list(t={}){return this.client.get("/exports",t)}get(t){return this.client.get("/exports/"+a(t))}delete(t){return this.client.delete("/exports/"+a(t))}}class w{constructor(t){this.client=void 0,this.client=t}create(t,e){return e={...e,event:t},this.client.post("/events",e)}}class k{constructor(t){this.client=void 0,this.client=t}create(t,e){return this.client.post(`/vouchers/${a(t)}/balance`,e)}}class _{constructor(t){this.client=void 0,this.client=t}examine(t,e={}){return this.client.post("/vouchers/qualification",t,e)}}class S{constructor(t,e){this.client=void 0,this.balance=void 0,this.qualifications=void 0,this.client=t,this.balance=e,this.qualifications=new _(this.client)}create(t){return this.client.post("/vouchers/"+a(t.code),t)}get(t){return this.client.get("/vouchers/"+a(t))}update(t){return this.client.put("/vouchers/"+a(t.code),t)}delete(t,e={}){return this.client.delete("/vouchers/"+a(t),e)}list(t={}){return this.client.get("/vouchers",t)}enable(t){return this.client.post(`/vouchers/${a(t)}/enable`,{})}disable(t){return this.client.post(`/vouchers/${a(t)}/disable`,{})}import(t){return this.client.post("/vouchers/import",t)}bulkUpdateMetadata(t){return this.client.post("/vouchers/metadata/async",t)}bulkUpdate(t){return this.client.post("/vouchers/bulk/async",t)}releaseValidationSession(t,e){return this.client.delete(`/vouchers/${a(t)}/sessions/${a(e)}`)}async importCSV(t){p(h().startsWith("Node"),'Method "client.vouchers.importCSV(filePath)" is only for Node environment');const e=(await import("fs")).default.createReadStream(t),s=new i;return s.append("file",e),this.client.post("/vouchers/importCSV",s,void 0,{"Content-Type":"multipart/form-data"})}listTransactions(t,e){return this.client.get(`/vouchers/${a(t)}/transactions`,e)}exportTransactions(t,e){return this.client.post(`/vouchers/${a(t)}/transactions/export`,e)}}class C{constructor(t,e){this.client=void 0,this.promotions=void 0,this.client=t,this.promotions=e}validateVoucher(t,e={}){return this.client.post(`/vouchers/${a(t)}/validate`,e)}validate(t,e={}){return u(t)?this.promotions.validate(t):this.validateVoucher(t,e)}validateStackable(t){return this.client.post("/validations",t)}}class R{constructor(t){this.client=void 0,this.client=t}redeem(t,e={}){return this.client.post(`/vouchers/${a(t)}/redemption`,e)}redeemStackable(t){return this.client.post("/redemptions",t)}get(t){return this.client.get("/redemptions/"+a(t))}list(t={}){return this.client.get("/redemptions",t)}getForVoucher(t){return this.client.get(`/vouchers/${a(t)}/redemption`)}rollback(t,e){let s={},i={};if(c(e))s.reason=e;else if(u(e)){const{reason:t,tracking_id:r,customer:n}=e;s={reason:t||void 0,tracking_id:r||void 0},i={customer:n}}return this.client.post(`/redemptions/${a(t)}/rollback`,i,s)}rollbackStackable(t,e,s){return this.client.post(`/redemptions/${a(t)}/rollbacks`,e,s)}}class V{constructor(t){this.client=void 0,this.client=t}listAll(t={}){return this.client.get("/promotions/tiers",t)}list(t){return this.client.get(`/promotions/${a(t)}/tiers`)}get(t){return this.client.get("/promotions/tiers/"+a(t))}create(t,e){return this.client.post(`/promotions/${a(t)}/tiers`,e)}redeem(t,e){return this.client.post(`/promotions/tiers/${a(t)}/redemption`,e)}update(t){return this.client.put("/promotions/tiers/"+a(t.id),t)}delete(t){return this.client.delete("/promotions/tiers/"+a(t))}}class x{constructor(t,e,s){this.client=void 0,this.tiers=void 0,this.stack=void 0,this.client=t,this.tiers=e,this.stack=s}create(t){return this.client.post("/campaigns",t)}validate(t,e){return this.client.post("/promotions/validation",t,e)}}class j{constructor(t){this.client=void 0,this.client=t}create(t){return this.client.post("/customers",t)}get(t){return this.client.get("/customers/"+a(t))}list(t){return this.client.get("/customers",t)}async*scroll(t){var e;let s=null!=(e=t.starting_after)?e:"created_at"===t.order?"1970-01-01T00:00:00Z":"2200-01-01T00:00:00Z",i=await this.client.get("/customers",Object.assign({},t,{starting_after:s}));for(;0!==i.customers.length;){for(const e of i.customers)s="created_at"===t.order?s>e.created_at?s:e.created_at:s<e.created_at?s:e.created_at,yield e;if(!i.has_more)break;i=await this.client.get("/customers",Object.assign({},t,{starting_after:s}))}}update(t){const e="id"in t?t.id:t.source_id,s=m(t,["id"]);return this.client.put("/customers/"+a(e),s)}updateInBulk(t){return this.client.post("/customers/bulk/async",t)}updateMetadataInBulk(t){return this.client.post("/customers/metadata/async",t)}delete(t){return this.client.delete("/customers/"+a(t))}deletePermanently(t){return this.client.post(`/customers/${a(t)}/permanent-deletion`,{})}updateConsents(t,e){return this.client.put(`/customers/${a(t)}/consents`,e)}listActivities(t,e){return this.client.get(`/customers/${a(t)}/activities`,e)}async importCSV(t){p(h().startsWith("Node"),'Method "client.customers.importCSV(filePath)" is only for Node environment');const e=(await import("fs")).default.createReadStream(t),s=new i;return s.append("file",e),this.client.post("/customers/importCSV",s,void 0,{"Content-Type":"multipart/form-data"})}listRedeemables(t,e){return this.client.get(`/customers/${a(t)}/redeemables`,e)}}class q{constructor(t){this.client=void 0,this.client=t}list(){return this.client.get("/consents")}}class I{constructor(t){this.client=void 0,this.client=t}create(t){return this.client.post("/orders",t)}get(t){return this.client.get("/orders/"+a(t))}update(t){return this.client.put("/orders/"+a(t.id||t.source_id),m(t,["id"]))}list(t={}){return this.client.get("/orders",t)}import(t){return this.client.post("/orders/import",t)}}class L{constructor(t){this.client=void 0,this.client=t}create(t){return this.client.post("/products",t)}get(t){return this.client.get("/products/"+a(t))}update(t){return this.client.put("/products/"+a(t.id||t.source_id),m(t,["id"]))}bulkUpdateMetadata(t){return this.client.post("/products/metadata/async",t)}bulkUpdate(t){return this.client.post("/products/bulk/async",t)}delete(t,e){return this.client.delete("/products/"+a(t),e)}list(t){return this.client.get("/products",t)}createSku(t,e){return this.client.post(`/products/${a(t)}/skus`,e)}getSku(t){return this.client.get("/skus/"+a(t))}updateSku(t,e){return this.client.put(`/products/${a(t)}/skus/${a(e.id||e.source_id)}`,m(e,["id"]))}deleteSku(t,e,s){return this.client.delete(`/products/${a(t)}/skus/${a(e)}`,s)}listSkus(t){return this.client.get(`/products/${a(t)}/skus`)}async importSkusCSV(t){p(h().startsWith("Node"),'Method "client.products.importSkusCSV(filePath)" is only for Node environment');const e=(await import("fs")).default.createReadStream(t),s=new i;return s.append("file",e),this.client.post("/skus/importCSV",s,void 0,{"Content-Type":"multipart/form-data"})}async importCSV(t){p(h().startsWith("Node"),'Method "client.products.importCSV(filePath)" is only for Node environment');const e=(await import("fs")).default.createReadStream(t),s=new i;return s.append("file",e),this.client.post("/products/importCSV",s,void 0,{"Content-Type":"multipart/form-data"})}}class A{constructor(t){this.client=void 0,this.client=t}list(t={}){return this.client.get("/rewards",t)}create(t){return this.client.post("/rewards",t)}get(t){return this.client.get("/rewards/"+a(t))}update(t){return this.client.put("/rewards/"+a(t.id),m(t,["id"]))}delete(t){return this.client.delete("/rewards/"+a(t))}getAssignment(t,e){return this.client.get(`/rewards/${a(t)}/assignments/${a(e)}`)}listAssignments(t,e={}){return this.client.get(`/rewards/${a(t)}/assignments`,e)}createAssignment(t,e){return this.client.post(`/rewards/${a(t)}/assignments`,e)}updateAssignment(t,e){return this.client.put(`/rewards/${a(t)}/assignments/${a(e.id)}`,m(e,["id"]))}deleteAssignment(t,e){return this.client.delete(`/rewards/${a(t)}/assignments/${a(e)}`)}}class T{constructor(t){this.client=void 0,this.client=t}list(t={}){return this.client.get("/loyalties",t)}create(t){return this.client.post("/loyalties",t)}get(t){return this.client.get("/loyalties/"+a(t))}update(t){return this.client.put("/loyalties/"+a(t.id),m(t,["id"]))}delete(t,e){return this.client.delete("/loyalties/"+a(t),e)}listRewardAssignments(t,e={}){return this.client.get(`/loyalties/${a(t)}/rewards`,e)}createRewardAssignments(t,e){return this.client.post(`/loyalties/${a(t)}/rewards`,e)}updateRewardAssignment(t,e){return this.client.put(`/loyalties/${a(t)}/rewards/${e.id}`,m(e,["id"]))}deleteRewardAssignment(t,e){return this.client.delete(`/loyalties/${a(t)}/rewards/${e}`)}getRewardAssignment(t,e){return this.client.get(`/loyalties/${a(t)}/rewards/${a(e)}`)}listEarningRules(t,e={}){return this.client.get(`/loyalties/${a(t)}/earning-rules`,e)}createEarningRule(t,e){return this.client.post(`/loyalties/${a(t)}/earning-rules`,e)}updateEarningRule(t,e){return this.client.put(`/loyalties/${a(t)}/earning-rules/${e.id}`,m(e,["id"]))}deleteEarningRule(t,e){return this.client.delete(`/loyalties/${a(t)}/earning-rules/${e}`)}getEarningRule(t,e){return this.client.get(`/loyalties/${a(t)}/earning-rules/${a(e)}`)}enableEarningRule(t,e){return this.client.post(`/loyalties/${a(t)}/earning-rules/${e}/enable`,{})}disableEarningRule(t,e){return this.client.post(`/loyalties/${a(t)}/earning-rules/${e}/disable`,{})}listMembers(t,e){return this.client.get(`/loyalties/${a(t)}/members`,e)}createMember(t,e){return this.client.post(`/loyalties/${a(t)}/members`,e)}getMember(t,e){return this.client.get(t?`/loyalties/${a(t)}/members/${e}`:"/loyalties/members/"+e)}getMemberActivities(t,e){return this.client.get(t?`/loyalties/${a(t)}/members/${e}/activities`:`/loyalties/members/${e}/activities`)}listMemberRewards(t,e){return this.client.get(`/loyalties/members/${a(t)}/rewards`,e)}addOrRemoveCardBalance(t,e,s){return this.client.post(s?`/loyalties/${a(s)}/members/${t}/balance`:`/loyalties/members/${t}/balance`,e)}addPoints(t,e,s){return this.client.post(`/loyalties/${a(t)}/members/${e}/balance`,s)}transferPoints(t,e,s){return this.client.post(`/loyalties/${a(t)}/members/${a(e)}/transfers`,s)}getPointsExpiration(t,e,s){return this.client.get(`/loyalties/${a(t)}/members/${e}/points-expiration`,s)}redeemReward(t,e,s){return this.client.post(`/loyalties/${a(t)}/members/${a(e)}/redemption`,s)}listLoyaltyTierRewards(t,e){return this.client.get(`/loyalties/${a(t)}/tiers/${a(e)}/rewards`)}listCardTransactions(t,e,s){return this.client.get(e?`/loyalties/${a(e)}/members/${a(t)}/transactions`:`/loyalties/members/${a(t)}/transactions`,s)}exportCardTransactions(t,e,s={}){return this.client.post(e?`/loyalties/${a(e)}/members/${a(t)}/transactions/export`:`/loyalties/members/${a(t)}/transactions/export`,s)}getRewardDetails(t,e){return this.client.get(`/loyalties/${a(t)}/reward-assignments/${a(e)}/reward`)}listTiers(t,e){return this.client.get(`/loyalties/${a(t)}/tiers`,e)}getTier(t,e){return this.client.get(`/loyalties/${a(t)}/tiers/${a(e)}`)}createTiers(t,e){return this.client.post(`/loyalties/${a(t)}/tiers`,e)}listLoyaltyTierEarningRules(t,e,s){return this.client.get(`/loyalties/${a(t)}/tiers/${a(e)}/earning-rules`,s)}listMemberLoyaltyTiers(t){return this.client.get(`/loyalties/members/${a(t)}/tiers`)}}class E{constructor(t){this.client=void 0,this.client=t}create(t){return this.client.post("/validation-rules",t)}get(t){return this.client.get("/validation-rules/"+a(t))}update(t){return this.client.put("/validation-rules/"+a(t.id),m(t,["id"]))}delete(t){return this.client.delete("/validation-rules/"+a(t))}createAssignment(t,e){return this.client.post(`/validation-rules/${a(t)}/assignments`,e)}deleteAssignment(t,e){return this.client.delete(`/validation-rules/${a(t)}/assignments/${a(e)}`)}validate(t,e={}){return this.client.post(`/validation-rules/${a(t)}/validation`,e)}list(t={}){return this.client.get("/validation-rules",t)}listRulesAssignments(t={}){return this.client.get("/validation-rules-assignments",t)}listAssignments(t,e={}){return this.client.get(`/validation-rules/${a(t)}/assignments`,e)}}class M{constructor(t){this.client=void 0,this.client=t}create(t){return this.client.post("/segments",t)}get(t){return this.client.get("/segments/"+a(t))}delete(t){return this.client.delete("/segments/"+a(t))}list(t){return this.client.get(`/customers/${a(t)}/segments`)}}class H{constructor(t){this.requestController=void 0,this.requestController=t}getLastResponseHeadersFromController(){return this.requestController.getLastResponseHeaders()}areLimitsAvailable(){return this.requestController.isLastReponseHeadersSet()}getRateLimit(){var t;const e=null!=(t=this.getLastResponseHeadersFromController()["x-rate-limit-limit"])?t:0;return parseInt(e,10)}getRateLimitRemaining(){var t;const e=null!=(t=this.getLastResponseHeadersFromController()["x-rate-limit-remaining"])?t:0;return parseInt(e,10)}getRetryAfter(){var t;const e=null!=(t=this.getLastResponseHeadersFromController()["retry-after"])?t:0;return parseInt(e,10)}}class P{constructor(t){this.client=void 0,this.client=t}list(){return this.client.get("/metadata-schemas")}get(t){return this.client.get("/metadata-schemas/"+a(t))}}class U{constructor(t){this.client=void 0,this.client=t}list(t={}){return this.client.get("/categories",t)}create(t){return this.client.post("/categories",t)}get(t){return this.client.get("/categories/"+a(t))}delete(t){return this.client.delete("/categories/"+a(t))}update(t,e){return this.client.put("/categories/"+a(t),e)}}class N{constructor(t){this.client=void 0,this.client=t}listInCampaign(t){return this.client.get(`/promotions/${t}/stacks`)}createInCampaign(t,e){return this.client.post(`/promotions/${t}/stacks`,e)}delete(t,e){return this.client.delete(`/promotions/${t}/stacks/${e}`)}get(t,e){return this.client.get(`/promotions/${t}/stacks/${e}`)}update(t,e,s){return this.client.put(`/promotions/${t}/stacks/${e}`,s)}list(t){return this.client.get("/promotions/stacks",t)}}class O{constructor(t){this.client=void 0,this.client=t}create(t){return this.client.post("/product-collections",t)}list(t){return this.client.get("/product-collections",t)}delete(t){return this.client.delete("/product-collections/"+a(t))}get(t){return this.client.get("/product-collections/"+a(t))}listProducts(t,e){return this.client.get(`/product-collections/${a(t)}/products`,e)}}class D{constructor(t){this.client=void 0,this.client=t}checkEligibility(t){return this.client.post("/qualifications",t)}}class K{constructor(t,e){this.client=void 0,this.trackingId=void 0,this.client=t,this.trackingId=e}setIdentity(t){this.trackingId=t}validate(t){var e,s;p(u(t)||c(t),'client.validate: expected "params" argument to be an object or a string');const i={};return c(t)?i.code=t:(i.code=t.code,i.item=t.items,i.amount=t.amount,i.metadata=t.metadata,i.order={metadata:t.orderMetadata},i.customer=t.customer,i.tracking_id=t.tracking_id||this.trackingId,i.session_type=t.session_type,i.session_key=t.session_key,i.session_ttl=t.session_ttl,i.session_ttl_unit=t.session_ttl_unit),i.code&&(i.code=i.code.replace(/[\r\n\t\f\v]/g,"").trim()),p(d(null==i?void 0:i.customer),'client.validate: expected "params.customer" to be an object'),p(l(null==i||null==(e=i.customer)?void 0:e.source_id),'client.validate: expected "params.customer.source_id" to be a string'),p(d(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(t,e={}){var s,i;return p(c(t),"client.redeem - please provide a valid Voucher code"),t=t.replace(/[\r\n\t\f\v]/g,"").trim(),e.customer=null!=(s=e.customer)?s:{},e.customer.source_id=null!=(i=e.customer.source_id)?i:this.trackingId,this.client.post("/redeem",e,{code:t})}publish(t,e={},s={}){var i,r,n,o,a;p(u(e),"client.publish - expected payload to be an object");const l={};return l.customer=null!=(i=e.customer)?i:{},l.customer.source_id=null!=(r=null==(n=e.customer)?void 0:n.source_id)?r:this.trackingId,l.channel=null!=(o=e.channel)?o:"Voucherify.js",p(c(null==(a=l.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=t.replace(/[\r\n\t\f\v]/g,"").trim(),this.client.post("/publish",l,s)}track(t,e,s,i,r){var n,o;p(c(t),"client.track - expected event name to be an string"),p(u(e),"client.track - expected customer to be an object");const a={event:t,metadata:null!=s?s:{},customer:e,referral:null!=i?i:void 0,loyalty:null!=r?r:void 0};return a.customer.source_id=null!=(n=e.source_id)?n:this.trackingId,p(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(t={}){const e={};return e.campaign=t.campaign,e.category=t.category,e.page=t.page,e.limit=t.limit,e.customer=t.customer,e.created_at=t.created_at,e.updated_at=t.updated_at,this.client.get("/vouchers",e)}createCustomer(t,e){return this.client.post("/customers",t,{},e?{"X-Voucherify-Double-Opt-In":!0}:{})}listConsents(){return this.client.get("/consents")}updateConsents(t,e){return this.client.put(`/customers/${a(t)}/consents`,e)}validateStackable(t){return this.client.post("/validations",t)}redeemStackable(t){return this.client.post("/redemptions",t)}qualifications(t){return this.client.post("/qualifications",t)}}t.VoucherifyClientSide=function(t){var e,s,i;p(u(t),'VoucherifyCustomer: expected "options" argument to be an object'),p(c(t.clientApplicationId),'VoucherifyCustomer: "options.clientApplicationId" is required'),p(c(t.clientSecretKey),'VoucherifyCustomer: "options.clientSecretKey" is required'),p(l(t.apiUrl),'VoucherifyCustomer: expected "options.baseUrl" to be a string'),p(l(t.trackingId),'VoucherifyCustomer: expected "options.trackingId" to be a string');let r={"X-Client-Application-Id":t.clientApplicationId,"X-Client-Token":t.clientSecretKey,"X-Voucherify-Channel":h()+"-ClientSide-SDK-v2.7.2"};h().startsWith("Node")&&(p(c(t.origin),'VoucherifyCustomer: "options.origin" is required in Node.js'),r.origin=t.origin),u(t.customHeaders)&&(r=Object.assign({},r,t.customHeaders));const n=new o({basePath:"client/v1",baseURL:null!=(e=t.apiUrl)?e:"https://api.voucherify.io",headers:r,exposeErrorCause:null!=(s=t.exposeErrorCause)&&s,timeoutMs:null!=(i=t.timeoutMs)?i:0});return new K(n,t.trackingId)},t.VoucherifyServerSide=function(t){var e,s,i;p(u(t),'VoucherifyServerSide: the "options" argument must be an object'),p(c(t.applicationId),'VoucherifyServerSide: "options.applicationId" is required'),p(c(t.secretKey),'VoucherifyServerSide: "options.secretKey" is required'),p(l(t.apiVersion),'VoucherifyServerSide: expected "options.apiVersion" to be a string'),p(l(t.channel),'VoucherifyServerSide: expected "options.channel" to be a string');let r={"X-App-Id":t.applicationId,"X-App-Token":t.secretKey,"X-Voucherify-Channel":t.channel||h()+"-SDK-v2.7.2","Content-Type":"application/json"};t.apiVersion&&(r["X-Voucherify-API-Version"]=t.apiVersion),u(t.customHeaders)&&(r=Object.assign({},r,t.customHeaders)),h().startsWith("Node")||p(!0===t.dangerouslySetSecretKeyInBrowser,`VoucherifyServerSide: you're exposing your secretKey to a ${h().toLowerCase()} environment. This is generally considered a bad practice. Did you mean to use 'VoucherifyClientSide'?`);const n=new o({basePath:"v1",baseURL:null!=(e=t.apiUrl)?e:"https://api.voucherify.io",headers:r,exposeErrorCause:null!=(s=t.exposeErrorCause)&&s,timeoutMs:null!=(i=t.timeoutMs)?i:0}),a=new g(n),d=new k(n),m=new S(n,d),v=new y(n),b=new U(n),_=new $(n),K=new w(n),W=new f(n,_),X=new V(n),F=new N(n),B=new x(n,X,F),z=new C(n,B),J=new R(n),Z=new D(n);return{vouchers:m,campaigns:v,categories:b,distributions:W,validations:z,redemptions:J,promotions:B,customers:new j(n),consents:new q(n),orders:new I(n),products:new L(n),productCollections:new O(n),qualifications:Z,rewards:new A(n),loyalties:new T(n),segments:new M(n),validationRules:new E(n),events:K,asyncActions:a,apiLimitsHandler:new H(n),metadataSchemas:new P(n)}},Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("axios"),require("qs"),require("form-data")):"function"==typeof define&&define.amd?define(["exports","axios","qs","form-data"],e):e((t=t||self).VoucherifySDK={},t.axios,t.Qs,t.FormData)}(this,(function(t,e,s,i){"use strict";var r;e=e&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e,s=s&&Object.prototype.hasOwnProperty.call(s,"default")?s.default:s,i=i&&Object.prototype.hasOwnProperty.call(i,"default")?i.default:i,(r=t.DiscountVouchersTypesEnum||(t.DiscountVouchersTypesEnum={})).AMOUNT="AMOUNT",r.PERCENT="PERCENT",r.UNIT="UNIT",r.FIXED="FIXED";class n extends Error{constructor(t,e,s){var i,r;super((null==(r=e=null!=(i=e)?i:{})?void 0:r.message)||function(t,e){return`Unexpected status code: ${e} - Details: ${t="string"==typeof t?t:JSON.stringify(t,null,2)}`}(e,t)),this.code=void 0,this.key=void 0,this.details=void 0,this.request_id=void 0,this.resource_id=void 0,this.resource_type=void 0,this.related_object_ids=void 0,this.related_object_type=void 0,this.related_object_total=void 0,this.error=void 0,this.cause=void 0,this.code=e.code,this.key=e.key,this.details=e.details,this.request_id=e.request_id,this.resource_id=e.resource_id,this.resource_type=e.resource_type,this.related_object_ids=e.related_object_ids,this.related_object_type=e.related_object_type,this.related_object_total=e.related_object_total,this.error=e.error,this.cause=s}}class o{constructor({basePath:t,baseURL:s,headers:i,exposeErrorCause:r,timeoutMs:o}){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.exposeErrorCause=void 0,this.timeoutMs=void 0,this.basePath=t,this.baseURL=s,this.headers=i,this.exposeErrorCause=r,this.lastResponseHeaders={},this.isLastResponseHeadersSet=!1,this.timeoutMs=o,this.request=e.create({baseURL:`${this.baseURL}/${this.basePath}/`,headers:this.headers,responseType:"json"}),this.request.interceptors.response.use(void 0,t=>{var e;return null!=t&&null!=(e=t.response)&&e.status?Promise.reject(new n(t.response.status,t.response.data,!0===this.exposeErrorCause?t:void 0)):Promise.reject(t)})}isLastReponseHeadersSet(){return this.isLastResponseHeadersSet}getLastResponseHeaders(){return this.lastResponseHeaders}setLastResponseHeaders(t){const e={};for(const s in t)e[s]=String(t[s]);this.lastResponseHeaders=e,this.isLastResponseHeadersSet=!0}setBaseUrl(t){this.baseURL=t,this.request.defaults.baseURL=`${t}/${this.basePath}/`}async get(t,e){const i=await this.request.get(t,{params:e,paramsSerializer:function(t){return s.stringify(t)},timeout:this.timeoutMs});return this.setLastResponseHeaders(i.headers),i.data}async post(t,e,i,r){const n=await this.request.post(t,e,{params:i,paramsSerializer:function(t){return s.stringify(t)},headers:r,timeout:this.timeoutMs});return this.setLastResponseHeaders(n.headers),n.data}async put(t,e,s){const i=await this.request.put(t,e,{params:s,timeout:this.timeoutMs});return this.setLastResponseHeaders(i.headers),i.data}async delete(t,e){const s=await this.request.delete(t,{params:e,timeout:this.timeoutMs});return this.setLastResponseHeaders(s.headers),s.data}}function a(t=""){return encodeURIComponent(t)}function c(t){return"string"==typeof t}function l(t){return null==t||c(t)}function u(t){return"object"==typeof t&&!Array.isArray(t)&&null!==t}function d(t){return null==t||u(t)}function h(){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 p(t,e){if(!t)throw new Error(e)}function m(t,e){return Object.fromEntries(Object.entries(t).filter(([t])=>!e.includes(t)))}class g{constructor(t){this.client=void 0,this.client=t}get(t){return this.client.get("/async-actions/"+a(t))}list(t){return this.client.get("/async-actions",t)}}class v{constructor(t){this.client=void 0,this.client=t}examine(t={},e){return this.client.post("/campaigns/qualification",t,e)}}class y{constructor(t){this.client=void 0,this.qualifications=void 0,this.client=t,this.qualifications=new v(this.client)}create(t){return this.client.post("/campaigns",t)}update(t,e){return this.client.put("/campaigns/"+a(t),e)}get(t){return this.client.get("/campaigns/"+a(t))}delete(t,e={}){return this.client.delete("/campaigns/"+a(t),e)}addVoucher(t,e={},s={}){return this.client.post(`/campaigns/${a(t)}/vouchers`,e,s)}addCertainVoucher(t,e,s={}){return this.client.post(`/campaigns/${a(t)}/vouchers/${a(e)}`,s)}importVouchers(t,e){return this.client.post(`/campaigns/${a(t)}/import`,e)}list(t={}){return this.client.get("/campaigns",t)}async importVouchersCSV(t,e){p(h().startsWith("Node"),'Method "client.campaigns.importVouchersCSV(campaignId, filePath)" is only for Node environment');const s=(await import("fs")).default.createReadStream(e),r=new i;return r.append("file",s),this.client.post(`/campaigns/${t}/importCSV`,r,void 0,{"Content-Type":"multipart/form-data"})}enable(t){return this.client.post(`/campaigns/${a(t)}/enable`,{})}disable(t){return this.client.post(`/campaigns/${a(t)}/disable`,{})}}class b{constructor(t){this.client=void 0,this.client=t}list(t={}){return this.client.get("/publications",t)}create(t){return this.client.post("/publications",t)}}class f{constructor(t,e){this.client=void 0,this.exports=void 0,this.publications=void 0,this.client=t,this.exports=e,this.publications=new b(this.client)}}class ${constructor(t){this.client=void 0,this.client=t}create(t){return this.client.post("/exports",t)}list(t={}){return this.client.get("/exports",t)}get(t){return this.client.get("/exports/"+a(t))}delete(t){return this.client.delete("/exports/"+a(t))}}class w{constructor(t){this.client=void 0,this.client=t}create(t,e){return e={...e,event:t},this.client.post("/events",e)}}class k{constructor(t){this.client=void 0,this.client=t}create(t,e){return this.client.post(`/vouchers/${a(t)}/balance`,e)}}class _{constructor(t){this.client=void 0,this.client=t}examine(t,e={}){return this.client.post("/vouchers/qualification",t,e)}}class S{constructor(t,e){this.client=void 0,this.balance=void 0,this.qualifications=void 0,this.client=t,this.balance=e,this.qualifications=new _(this.client)}create(t){return this.client.post("/vouchers/"+a(t.code),t)}get(t){return this.client.get("/vouchers/"+a(t))}update(t){return this.client.put("/vouchers/"+a(t.code),t)}delete(t,e={}){return this.client.delete("/vouchers/"+a(t),e)}list(t={}){return this.client.get("/vouchers",t)}enable(t){return this.client.post(`/vouchers/${a(t)}/enable`,{})}disable(t){return this.client.post(`/vouchers/${a(t)}/disable`,{})}import(t){return this.client.post("/vouchers/import",t)}bulkUpdateMetadata(t){return this.client.post("/vouchers/metadata/async",t)}bulkUpdate(t){return this.client.post("/vouchers/bulk/async",t)}releaseValidationSession(t,e){return this.client.delete(`/vouchers/${a(t)}/sessions/${a(e)}`)}async importCSV(t){p(h().startsWith("Node"),'Method "client.vouchers.importCSV(filePath)" is only for Node environment');const e=(await import("fs")).default.createReadStream(t),s=new i;return s.append("file",e),this.client.post("/vouchers/importCSV",s,void 0,{"Content-Type":"multipart/form-data"})}listTransactions(t,e){return this.client.get(`/vouchers/${a(t)}/transactions`,e)}exportTransactions(t,e){return this.client.post(`/vouchers/${a(t)}/transactions/export`,e)}}class C{constructor(t,e){this.client=void 0,this.promotions=void 0,this.client=t,this.promotions=e}validateVoucher(t,e={}){return this.client.post(`/vouchers/${a(t)}/validate`,e)}validate(t,e={}){return u(t)?this.promotions.validate(t):this.validateVoucher(t,e)}validateStackable(t){return this.client.post("/validations",t)}}class R{constructor(t){this.client=void 0,this.client=t}redeem(t,e={}){return this.client.post(`/vouchers/${a(t)}/redemption`,e)}redeemStackable(t){return this.client.post("/redemptions",t)}get(t){return this.client.get("/redemptions/"+a(t))}list(t={}){return this.client.get("/redemptions",t)}getForVoucher(t){return this.client.get(`/vouchers/${a(t)}/redemption`)}rollback(t,e){let s={},i={};if(c(e))s.reason=e;else if(u(e)){const{reason:t,tracking_id:r,customer:n}=e;s={reason:t||void 0,tracking_id:r||void 0},i={customer:n}}return this.client.post(`/redemptions/${a(t)}/rollback`,i,s)}rollbackStackable(t,e,s){return this.client.post(`/redemptions/${a(t)}/rollbacks`,e,s)}}class V{constructor(t){this.client=void 0,this.client=t}listAll(t={}){return this.client.get("/promotions/tiers",t)}list(t){return this.client.get(`/promotions/${a(t)}/tiers`)}get(t){return this.client.get("/promotions/tiers/"+a(t))}create(t,e){return this.client.post(`/promotions/${a(t)}/tiers`,e)}redeem(t,e){return this.client.post(`/promotions/tiers/${a(t)}/redemption`,e)}update(t){return this.client.put("/promotions/tiers/"+a(t.id),t)}delete(t){return this.client.delete("/promotions/tiers/"+a(t))}}class x{constructor(t,e,s){this.client=void 0,this.tiers=void 0,this.stack=void 0,this.client=t,this.tiers=e,this.stack=s}create(t){return this.client.post("/campaigns",t)}validate(t,e){return this.client.post("/promotions/validation",t,e)}}class j{constructor(t){this.client=void 0,this.client=t}create(t){return this.client.post("/customers",t)}get(t){return this.client.get("/customers/"+a(t))}list(t){return this.client.get("/customers",t)}async*scroll(t){var e;let s=null!=(e=t.starting_after)?e:"created_at"===t.order?"1970-01-01T00:00:00Z":"2200-01-01T00:00:00Z",i=await this.client.get("/customers",Object.assign({},t,{starting_after:s}));for(;0!==i.customers.length;){for(const e of i.customers)s="created_at"===t.order?s>e.created_at?s:e.created_at:s<e.created_at?s:e.created_at,yield e;if(!i.has_more)break;i=await this.client.get("/customers",Object.assign({},t,{starting_after:s}))}}update(t){const e="id"in t?t.id:t.source_id,s=m(t,["id"]);return this.client.put("/customers/"+a(e),s)}updateInBulk(t){return this.client.post("/customers/bulk/async",t)}updateMetadataInBulk(t){return this.client.post("/customers/metadata/async",t)}delete(t){return this.client.delete("/customers/"+a(t))}deletePermanently(t){return this.client.post(`/customers/${a(t)}/permanent-deletion`,{})}updateConsents(t,e){return this.client.put(`/customers/${a(t)}/consents`,e)}listActivities(t,e){return this.client.get(`/customers/${a(t)}/activities`,e)}async importCSV(t){p(h().startsWith("Node"),'Method "client.customers.importCSV(filePath)" is only for Node environment');const e=(await import("fs")).default.createReadStream(t),s=new i;return s.append("file",e),this.client.post("/customers/importCSV",s,void 0,{"Content-Type":"multipart/form-data"})}listRedeemables(t,e){return this.client.get(`/customers/${a(t)}/redeemables`,e)}}class q{constructor(t){this.client=void 0,this.client=t}list(){return this.client.get("/consents")}}class I{constructor(t){this.client=void 0,this.client=t}create(t){return this.client.post("/orders",t)}get(t){return this.client.get("/orders/"+a(t))}update(t){return this.client.put("/orders/"+a(t.id||t.source_id),m(t,["id"]))}list(t={}){return this.client.get("/orders",t)}import(t){return this.client.post("/orders/import",t)}}class L{constructor(t){this.client=void 0,this.client=t}create(t){return this.client.post("/products",t)}get(t){return this.client.get("/products/"+a(t))}update(t){return this.client.put("/products/"+a(t.id||t.source_id),m(t,["id"]))}bulkUpdateMetadata(t){return this.client.post("/products/metadata/async",t)}bulkUpdate(t){return this.client.post("/products/bulk/async",t)}delete(t,e){return this.client.delete("/products/"+a(t),e)}list(t){return this.client.get("/products",t)}createSku(t,e){return this.client.post(`/products/${a(t)}/skus`,e)}getSku(t){return this.client.get("/skus/"+a(t))}updateSku(t,e){return this.client.put(`/products/${a(t)}/skus/${a(e.id||e.source_id)}`,m(e,["id"]))}deleteSku(t,e,s){return this.client.delete(`/products/${a(t)}/skus/${a(e)}`,s)}listSkus(t){return this.client.get(`/products/${a(t)}/skus`)}async importSkusCSV(t){p(h().startsWith("Node"),'Method "client.products.importSkusCSV(filePath)" is only for Node environment');const e=(await import("fs")).default.createReadStream(t),s=new i;return s.append("file",e),this.client.post("/skus/importCSV",s,void 0,{"Content-Type":"multipart/form-data"})}async importCSV(t){p(h().startsWith("Node"),'Method "client.products.importCSV(filePath)" is only for Node environment');const e=(await import("fs")).default.createReadStream(t),s=new i;return s.append("file",e),this.client.post("/products/importCSV",s,void 0,{"Content-Type":"multipart/form-data"})}}class A{constructor(t){this.client=void 0,this.client=t}list(t={}){return this.client.get("/rewards",t)}create(t){return this.client.post("/rewards",t)}get(t){return this.client.get("/rewards/"+a(t))}update(t){return this.client.put("/rewards/"+a(t.id),m(t,["id"]))}delete(t){return this.client.delete("/rewards/"+a(t))}getAssignment(t,e){return this.client.get(`/rewards/${a(t)}/assignments/${a(e)}`)}listAssignments(t,e={}){return this.client.get(`/rewards/${a(t)}/assignments`,e)}createAssignment(t,e){return this.client.post(`/rewards/${a(t)}/assignments`,e)}updateAssignment(t,e){return this.client.put(`/rewards/${a(t)}/assignments/${a(e.id)}`,m(e,["id"]))}deleteAssignment(t,e){return this.client.delete(`/rewards/${a(t)}/assignments/${a(e)}`)}}class T{constructor(t){this.client=void 0,this.client=t}list(t={}){return this.client.get("/loyalties",t)}create(t){return this.client.post("/loyalties",t)}get(t){return this.client.get("/loyalties/"+a(t))}update(t){return this.client.put("/loyalties/"+a(t.id),m(t,["id"]))}delete(t,e){return this.client.delete("/loyalties/"+a(t),e)}listRewardAssignments(t,e={}){return this.client.get(`/loyalties/${a(t)}/rewards`,e)}createRewardAssignments(t,e){return this.client.post(`/loyalties/${a(t)}/rewards`,e)}updateRewardAssignment(t,e){return this.client.put(`/loyalties/${a(t)}/rewards/${e.id}`,m(e,["id"]))}deleteRewardAssignment(t,e){return this.client.delete(`/loyalties/${a(t)}/rewards/${e}`)}getRewardAssignment(t,e){return this.client.get(`/loyalties/${a(t)}/rewards/${a(e)}`)}listEarningRules(t,e={}){return this.client.get(`/loyalties/${a(t)}/earning-rules`,e)}createEarningRule(t,e){return this.client.post(`/loyalties/${a(t)}/earning-rules`,e)}updateEarningRule(t,e){return this.client.put(`/loyalties/${a(t)}/earning-rules/${e.id}`,m(e,["id"]))}deleteEarningRule(t,e){return this.client.delete(`/loyalties/${a(t)}/earning-rules/${e}`)}getEarningRule(t,e){return this.client.get(`/loyalties/${a(t)}/earning-rules/${a(e)}`)}enableEarningRule(t,e){return this.client.post(`/loyalties/${a(t)}/earning-rules/${e}/enable`,{})}disableEarningRule(t,e){return this.client.post(`/loyalties/${a(t)}/earning-rules/${e}/disable`,{})}listMembers(t,e){return this.client.get(`/loyalties/${a(t)}/members`,e)}createMember(t,e){return this.client.post(`/loyalties/${a(t)}/members`,e)}getMember(t,e){return this.client.get(t?`/loyalties/${a(t)}/members/${e}`:"/loyalties/members/"+e)}getMemberActivities(t,e){return this.client.get(t?`/loyalties/${a(t)}/members/${e}/activities`:`/loyalties/members/${e}/activities`)}listMemberRewards(t,e){return this.client.get(`/loyalties/members/${a(t)}/rewards`,e)}addOrRemoveCardBalance(t,e,s){return this.client.post(s?`/loyalties/${a(s)}/members/${t}/balance`:`/loyalties/members/${t}/balance`,e)}addPoints(t,e,s){return this.client.post(`/loyalties/${a(t)}/members/${e}/balance`,s)}transferPoints(t,e,s){return this.client.post(`/loyalties/${a(t)}/members/${a(e)}/transfers`,s)}getPointsExpiration(t,e,s){return this.client.get(`/loyalties/${a(t)}/members/${e}/points-expiration`,s)}redeemReward(t,e,s){return this.client.post(`/loyalties/${a(t)}/members/${a(e)}/redemption`,s)}listLoyaltyTierRewards(t,e){return this.client.get(`/loyalties/${a(t)}/tiers/${a(e)}/rewards`)}listCardTransactions(t,e,s){return this.client.get(e?`/loyalties/${a(e)}/members/${a(t)}/transactions`:`/loyalties/members/${a(t)}/transactions`,s)}exportCardTransactions(t,e,s={}){return this.client.post(e?`/loyalties/${a(e)}/members/${a(t)}/transactions/export`:`/loyalties/members/${a(t)}/transactions/export`,s)}getRewardDetails(t,e){return this.client.get(`/loyalties/${a(t)}/reward-assignments/${a(e)}/reward`)}listTiers(t,e){return this.client.get(`/loyalties/${a(t)}/tiers`,e)}getTier(t,e){return this.client.get(`/loyalties/${a(t)}/tiers/${a(e)}`)}createTiers(t,e){return this.client.post(`/loyalties/${a(t)}/tiers`,e)}listLoyaltyTierEarningRules(t,e,s){return this.client.get(`/loyalties/${a(t)}/tiers/${a(e)}/earning-rules`,s)}listMemberLoyaltyTiers(t){return this.client.get(`/loyalties/members/${a(t)}/tiers`)}}class E{constructor(t){this.client=void 0,this.client=t}create(t){return this.client.post("/validation-rules",t)}get(t){return this.client.get("/validation-rules/"+a(t))}update(t){return this.client.put("/validation-rules/"+a(t.id),m(t,["id"]))}delete(t){return this.client.delete("/validation-rules/"+a(t))}createAssignment(t,e){return this.client.post(`/validation-rules/${a(t)}/assignments`,e)}deleteAssignment(t,e){return this.client.delete(`/validation-rules/${a(t)}/assignments/${a(e)}`)}validate(t,e={}){return this.client.post(`/validation-rules/${a(t)}/validation`,e)}list(t={}){return this.client.get("/validation-rules",t)}listRulesAssignments(t={}){return this.client.get("/validation-rules-assignments",t)}listAssignments(t,e={}){return this.client.get(`/validation-rules/${a(t)}/assignments`,e)}}class M{constructor(t){this.client=void 0,this.client=t}create(t){return this.client.post("/segments",t)}get(t){return this.client.get("/segments/"+a(t))}delete(t){return this.client.delete("/segments/"+a(t))}list(t){return this.client.get(`/customers/${a(t)}/segments`)}}class H{constructor(t){this.requestController=void 0,this.requestController=t}getLastResponseHeadersFromController(){return this.requestController.getLastResponseHeaders()}areLimitsAvailable(){return this.requestController.isLastReponseHeadersSet()}getRateLimit(){var t;const e=null!=(t=this.getLastResponseHeadersFromController()["x-rate-limit-limit"])?t:0;return parseInt(e,10)}getRateLimitRemaining(){var t;const e=null!=(t=this.getLastResponseHeadersFromController()["x-rate-limit-remaining"])?t:0;return parseInt(e,10)}getRetryAfter(){var t;const e=null!=(t=this.getLastResponseHeadersFromController()["retry-after"])?t:0;return parseInt(e,10)}}class P{constructor(t){this.client=void 0,this.client=t}list(){return this.client.get("/metadata-schemas")}get(t){return this.client.get("/metadata-schemas/"+a(t))}}class U{constructor(t){this.client=void 0,this.client=t}list(t={}){return this.client.get("/categories",t)}create(t){return this.client.post("/categories",t)}get(t){return this.client.get("/categories/"+a(t))}delete(t){return this.client.delete("/categories/"+a(t))}update(t,e){return this.client.put("/categories/"+a(t),e)}}class N{constructor(t){this.client=void 0,this.client=t}listInCampaign(t){return this.client.get(`/promotions/${t}/stacks`)}createInCampaign(t,e){return this.client.post(`/promotions/${t}/stacks`,e)}delete(t,e){return this.client.delete(`/promotions/${t}/stacks/${e}`)}get(t,e){return this.client.get(`/promotions/${t}/stacks/${e}`)}update(t,e,s){return this.client.put(`/promotions/${t}/stacks/${e}`,s)}list(t){return this.client.get("/promotions/stacks",t)}}class O{constructor(t){this.client=void 0,this.client=t}create(t){return this.client.post("/product-collections",t)}list(t){return this.client.get("/product-collections",t)}delete(t){return this.client.delete("/product-collections/"+a(t))}get(t){return this.client.get("/product-collections/"+a(t))}listProducts(t,e){return this.client.get(`/product-collections/${a(t)}/products`,e)}}class D{constructor(t){this.client=void 0,this.client=t}checkEligibility(t){return this.client.post("/qualifications",t)}}class K{constructor(t,e){this.client=void 0,this.trackingId=void 0,this.client=t,this.trackingId=e}setIdentity(t){this.trackingId=t}validate(t){var e,s;p(u(t)||c(t),'client.validate: expected "params" argument to be an object or a string');const i={};return c(t)?i.code=t:(i.code=t.code,i.item=t.items,i.amount=t.amount,i.metadata=t.metadata,i.order={metadata:t.orderMetadata},i.customer=t.customer,i.tracking_id=t.tracking_id||this.trackingId,i.session_type=t.session_type,i.session_key=t.session_key,i.session_ttl=t.session_ttl,i.session_ttl_unit=t.session_ttl_unit),i.code&&(i.code=i.code.replace(/[\r\n\t\f\v]/g,"").trim()),p(d(null==i?void 0:i.customer),'client.validate: expected "params.customer" to be an object'),p(l(null==i||null==(e=i.customer)?void 0:e.source_id),'client.validate: expected "params.customer.source_id" to be a string'),p(d(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(t,e={}){var s,i;return p(c(t),"client.redeem - please provide a valid Voucher code"),t=t.replace(/[\r\n\t\f\v]/g,"").trim(),e.customer=null!=(s=e.customer)?s:{},e.customer.source_id=null!=(i=e.customer.source_id)?i:this.trackingId,this.client.post("/redeem",e,{code:t})}publish(t,e={},s={}){var i,r,n,o,a;p(u(e),"client.publish - expected payload to be an object");const l={};return l.customer=null!=(i=e.customer)?i:{},l.customer.source_id=null!=(r=null==(n=e.customer)?void 0:n.source_id)?r:this.trackingId,l.channel=null!=(o=e.channel)?o:"Voucherify.js",p(c(null==(a=l.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=t.replace(/[\r\n\t\f\v]/g,"").trim(),this.client.post("/publish",l,s)}track(t,e,s,i,r){var n,o;p(c(t),"client.track - expected event name to be an string"),p(u(e),"client.track - expected customer to be an object");const a={event:t,metadata:null!=s?s:{},customer:e,referral:null!=i?i:void 0,loyalty:null!=r?r:void 0};return a.customer.source_id=null!=(n=e.source_id)?n:this.trackingId,p(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(t={}){const e={};return e.campaign=t.campaign,e.category=t.category,e.page=t.page,e.limit=t.limit,e.customer=t.customer,e.created_at=t.created_at,e.updated_at=t.updated_at,this.client.get("/vouchers",e)}createCustomer(t,e){return this.client.post("/customers",t,{},e?{"X-Voucherify-Double-Opt-In":!0}:{})}listConsents(){return this.client.get("/consents")}updateConsents(t,e){return this.client.put(`/customers/${a(t)}/consents`,e)}validateStackable(t){return this.client.post("/validations",t)}redeemStackable(t){return this.client.post("/redemptions",t)}qualifications(t){return this.client.post("/qualifications",t)}}t.VoucherifyClientSide=function(t){var e,s,i;p(u(t),'VoucherifyCustomer: expected "options" argument to be an object'),p(c(t.clientApplicationId),'VoucherifyCustomer: "options.clientApplicationId" is required'),p(c(t.clientSecretKey),'VoucherifyCustomer: "options.clientSecretKey" is required'),p(l(t.apiUrl),'VoucherifyCustomer: expected "options.baseUrl" to be a string'),p(l(t.trackingId),'VoucherifyCustomer: expected "options.trackingId" to be a string');let r={"X-Client-Application-Id":t.clientApplicationId,"X-Client-Token":t.clientSecretKey,"X-Voucherify-Channel":h()+"-ClientSide-SDK-v2.7.3"};h().startsWith("Node")&&(p(c(t.origin),'VoucherifyCustomer: "options.origin" is required in Node.js'),r.origin=t.origin),u(t.customHeaders)&&(r=Object.assign({},r,t.customHeaders));const n=new o({basePath:"client/v1",baseURL:null!=(e=t.apiUrl)?e:"https://api.voucherify.io",headers:r,exposeErrorCause:null!=(s=t.exposeErrorCause)&&s,timeoutMs:null!=(i=t.timeoutMs)?i:0});return new K(n,t.trackingId)},t.VoucherifyServerSide=function(t){var e,s,i;p(u(t),'VoucherifyServerSide: the "options" argument must be an object'),p(c(t.applicationId),'VoucherifyServerSide: "options.applicationId" is required'),p(c(t.secretKey),'VoucherifyServerSide: "options.secretKey" is required'),p(l(t.apiVersion),'VoucherifyServerSide: expected "options.apiVersion" to be a string'),p(l(t.channel),'VoucherifyServerSide: expected "options.channel" to be a string');let r={"X-App-Id":t.applicationId,"X-App-Token":t.secretKey,"X-Voucherify-Channel":t.channel||h()+"-SDK-v2.7.3","Content-Type":"application/json"};t.apiVersion&&(r["X-Voucherify-API-Version"]=t.apiVersion),u(t.customHeaders)&&(r=Object.assign({},r,t.customHeaders)),h().startsWith("Node")||p(!0===t.dangerouslySetSecretKeyInBrowser,`VoucherifyServerSide: you're exposing your secretKey to a ${h().toLowerCase()} environment. This is generally considered a bad practice. Did you mean to use 'VoucherifyClientSide'?`);const n=new o({basePath:"v1",baseURL:null!=(e=t.apiUrl)?e:"https://api.voucherify.io",headers:r,exposeErrorCause:null!=(s=t.exposeErrorCause)&&s,timeoutMs:null!=(i=t.timeoutMs)?i:0}),a=new g(n),d=new k(n),m=new S(n,d),v=new y(n),b=new U(n),_=new $(n),K=new w(n),W=new f(n,_),X=new V(n),F=new N(n),B=new x(n,X,F),z=new C(n,B),J=new R(n),Z=new D(n);return{vouchers:m,campaigns:v,categories:b,distributions:W,validations:z,redemptions:J,promotions:B,customers:new j(n),consents:new q(n),orders:new I(n),products:new L(n),productCollections:new O(n),qualifications:Z,rewards:new A(n),loyalties:new T(n),segments:new M(n),validationRules:new E(n),events:K,asyncActions:a,apiLimitsHandler:new H(n),metadataSchemas:new P(n)}},Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
2
2
|
//# sourceMappingURL=voucherifysdk.umd.production.min.js.map
|