@voucherify/sdk 2.8.0 → 2.8.1
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/Loyalties.d.ts +6 -6
- package/dist/types/ProductCollections.d.ts +4 -3
- package/dist/types/Vouchers.d.ts +6 -0
- 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.8.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`a9ba013`](https://github.com/voucherifyio/voucherify-js-sdk/commit/a9ba013062c560a3a663b1f219f2dcb7ae9a8a7e) [#280](https://github.com/voucherifyio/voucherify-js-sdk/pull/280) Thanks [@p-zielinski](https://github.com/p-zielinski)! - TS fixes (VouchersListTransactionsRequestQuery, LoyaltiesListCardTransactionsRequestQuery, ProductCollectionsCreateRequestBody) - backwards compatible
|
|
8
|
+
|
|
3
9
|
## 2.8.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
|
@@ -551,6 +551,11 @@ export interface LoyaltiesGetPointsExpirationResponseBody {
|
|
|
551
551
|
}
|
|
552
552
|
export interface LoyaltiesListCardTransactionsRequestQuery {
|
|
553
553
|
limit?: number;
|
|
554
|
+
starting_after_id?: string;
|
|
555
|
+
order?: 'id' | '-id';
|
|
556
|
+
/**
|
|
557
|
+
* @deprecated Use starting_after_id
|
|
558
|
+
*/
|
|
554
559
|
page?: number;
|
|
555
560
|
}
|
|
556
561
|
export interface LoyaltiesListCardTransactionsResponseBody {
|
|
@@ -558,6 +563,7 @@ export interface LoyaltiesListCardTransactionsResponseBody {
|
|
|
558
563
|
data_ref: 'data';
|
|
559
564
|
data: LoyaltyCardTransaction[];
|
|
560
565
|
has_more: boolean;
|
|
566
|
+
more_starting_after?: string;
|
|
561
567
|
}
|
|
562
568
|
export declare type LoyaltiesExportCardTransactionsRequestBody = VouchersExportTransactionsRequestBody;
|
|
563
569
|
export interface LoyaltiesAddOrRemoveCardBalanceRequestBody {
|
|
@@ -648,12 +654,6 @@ export interface LoyaltiesListCardTransactionsRequestQuery {
|
|
|
648
654
|
limit?: number;
|
|
649
655
|
page?: number;
|
|
650
656
|
}
|
|
651
|
-
export interface LoyaltiesListCardTransactionsResponseBody {
|
|
652
|
-
object: 'list';
|
|
653
|
-
data_ref: 'data';
|
|
654
|
-
data: LoyaltyCardTransaction[];
|
|
655
|
-
has_more: boolean;
|
|
656
|
-
}
|
|
657
657
|
export declare type LoyaltiesExportCardTransactionsResponseBody = VouchersExportTransactionsResponseBody;
|
|
658
658
|
export interface LoyaltiesAddOrRemoveCardBalanceRequestBody {
|
|
659
659
|
points: number;
|
|
@@ -57,12 +57,13 @@ export interface DynamicProductCollectionBase {
|
|
|
57
57
|
filter?: Filter;
|
|
58
58
|
}
|
|
59
59
|
export declare type ProductCollection = ProductCollectionBase & ProductCollectionIdentity & ProductCollectionSaved;
|
|
60
|
-
export declare type Filter = {
|
|
61
|
-
junction: Junction;
|
|
62
|
-
} & Partial<Record<AllowedFiltersKeys, {
|
|
60
|
+
export declare type Filter = Partial<Record<string, Junction | {
|
|
63
61
|
conditions: Partial<Record<FiltersCondition, unknown>>;
|
|
64
62
|
}>>;
|
|
65
63
|
export declare type Junction = 'and' | 'AND' | 'or' | 'OR';
|
|
64
|
+
/**
|
|
65
|
+
* @deprecated
|
|
66
|
+
*/
|
|
66
67
|
export declare type AllowedFiltersKeys = 'id' | 'name' | 'attributes' | 'source_id' | 'price' | 'image_url' | 'product_id' | 'skus' | 'created_at' | 'updated_at' | 'object' | `metadata.${string}`;
|
|
67
68
|
export declare type FiltersCondition = '$in' | '$not_in' | '$is' | '$is_days_ago' | '$is_days_in_future' | '$is_not' | '$has_value' | '$is_unknown' | '$contains' | '$not_contain' | '$starts_with' | '$ends_with' | '$more_than' | '$less_than' | '$more_than_ago' | '$less_than_ago' | '$more_than_future' | '$less_than_future' | '$more_than_equal' | '$less_than_equal' | '$after' | '$before' | '$count' | '$count_less' | '$count_more';
|
|
68
69
|
export declare type ProductCollectionsCreateRequestBody = WithRequiredProperty<StaticProductCollectionBase, 'name' | 'type'> | Required<DynamicProductCollectionBase>;
|
package/dist/types/Vouchers.d.ts
CHANGED
|
@@ -318,6 +318,11 @@ export declare type VoucherTransaction = GiftCardTransaction | LoyaltyCardTransa
|
|
|
318
318
|
export declare type VoucherTransactionsExportFields = 'id' | 'campaign_id' | 'voucher_id' | 'type' | 'source_id' | 'reason' | 'source' | 'balance' | 'amount' | 'related_transaction_id' | 'created_at' | 'details';
|
|
319
319
|
export interface VouchersListTransactionsRequestQuery {
|
|
320
320
|
limit?: number;
|
|
321
|
+
starting_after_id?: string;
|
|
322
|
+
order?: 'id' | '-id';
|
|
323
|
+
/**
|
|
324
|
+
* @deprecated Use starting_after_id
|
|
325
|
+
*/
|
|
321
326
|
page?: number;
|
|
322
327
|
}
|
|
323
328
|
export interface VouchersListTransactionsResponseBody {
|
|
@@ -325,6 +330,7 @@ export interface VouchersListTransactionsResponseBody {
|
|
|
325
330
|
data_ref: 'data';
|
|
326
331
|
data: VoucherTransaction[];
|
|
327
332
|
has_more: boolean;
|
|
333
|
+
more_starting_after?: string;
|
|
328
334
|
}
|
|
329
335
|
export interface VouchersExportTransactionsRequestBody {
|
|
330
336
|
parameters?: {
|
|
@@ -1960,7 +1960,7 @@ function VoucherifyServerSide(options) {
|
|
|
1960
1960
|
let headers = {
|
|
1961
1961
|
'X-App-Id': options.applicationId,
|
|
1962
1962
|
'X-App-Token': options.secretKey,
|
|
1963
|
-
'X-Voucherify-Channel': options.channel || `${environment()}-SDK-v${"2.8.
|
|
1963
|
+
'X-Voucherify-Channel': options.channel || `${environment()}-SDK-v${"2.8.1"}`,
|
|
1964
1964
|
'Content-Type': 'application/json'
|
|
1965
1965
|
};
|
|
1966
1966
|
|
|
@@ -2226,7 +2226,7 @@ function VoucherifyClientSide(options) {
|
|
|
2226
2226
|
let headers = {
|
|
2227
2227
|
'X-Client-Application-Id': options.clientApplicationId,
|
|
2228
2228
|
'X-Client-Token': options.clientSecretKey,
|
|
2229
|
-
'X-Voucherify-Channel': `${environment()}-ClientSide-SDK-v${"2.8.
|
|
2229
|
+
'X-Voucherify-Channel': `${environment()}-ClientSide-SDK-v${"2.8.1"}`
|
|
2230
2230
|
};
|
|
2231
2231
|
|
|
2232
2232
|
if (environment().startsWith('Node')) {
|
|
@@ -1964,7 +1964,7 @@
|
|
|
1964
1964
|
let headers = {
|
|
1965
1965
|
'X-App-Id': options.applicationId,
|
|
1966
1966
|
'X-App-Token': options.secretKey,
|
|
1967
|
-
'X-Voucherify-Channel': options.channel || `${environment()}-SDK-v${"2.8.
|
|
1967
|
+
'X-Voucherify-Channel': options.channel || `${environment()}-SDK-v${"2.8.1"}`,
|
|
1968
1968
|
'Content-Type': 'application/json'
|
|
1969
1969
|
};
|
|
1970
1970
|
|
|
@@ -2230,7 +2230,7 @@
|
|
|
2230
2230
|
let headers = {
|
|
2231
2231
|
'X-Client-Application-Id': options.clientApplicationId,
|
|
2232
2232
|
'X-Client-Token': options.clientSecretKey,
|
|
2233
|
-
'X-Voucherify-Channel': `${environment()}-ClientSide-SDK-v${"2.8.
|
|
2233
|
+
'X-Voucherify-Channel': `${environment()}-ClientSide-SDK-v${"2.8.1"}`
|
|
2234
2234
|
};
|
|
2235
2235
|
|
|
2236
2236
|
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`,{})}listActivity(t,e){return this.client.get(`/customers/${a(t)}/activity`,e)}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 A{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 L{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.8.0"};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.8.0","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 A(n),productCollections:new O(n),qualifications:Z,rewards:new L(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`,{})}listActivity(t,e){return this.client.get(`/customers/${a(t)}/activity`,e)}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 A{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 L{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.8.1"};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.8.1","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 A(n),productCollections:new O(n),qualifications:Z,rewards:new L(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
|