Skip to content

Commit

Permalink
Promotion Tiers types (#26)
Browse files Browse the repository at this point in the history
* Added Promotion Tiers types

* Updated types

* Fixed build error

* Dropped ? from metadata

* Updated types

* Updates
  • Loading branch information
pkgacek authored Feb 17, 2021
1 parent 18bd006 commit 920b5dd
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 39 deletions.
5 changes: 5 additions & 0 deletions .changeset/tough-knives-occur.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@voucherify/sdk': patch
---

Added Promotion Tiers types
25 changes: 15 additions & 10 deletions packages/sdk/src/PromotionTiers.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,43 @@
import { encode } from './helpers'
import * as T from './types/PromotionTiers'

import type { RequestController } from './RequestController'
import { encode } from './helpers'

export class PromotionTiers {
constructor(private client: RequestController) {}

/**
* @see http://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#list-promotion-tiers
*/
public listAll(params: $FixMe) {
return this.client.get('/promotions/tiers', params)
public listAll(params: T.PromotionTiersListAllParams = {}) {
return this.client.get<T.PromotionTiersListAllResponse>('/promotions/tiers', params)
}
/**
* @see http://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#get-promotions
*/
public list(promotionId: string) {
return this.client.get(`/promotions/${encode(promotionId)}/tiers`)
return this.client.get<T.PromotionTiersListResponse>(`/promotions/${encode(promotionId)}/tiers`)
}
/**
* @see http://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#add-promotion-tier-to-campaign
*/
public create(promotionId: string, params: $FixMe) {
return this.client.post(`/promotions/${encode(promotionId)}/tiers`, params)
public create(promotionId: string, params: T.PromotionTiersCreateParams) {
return this.client.post<T.PromotionTiersCreateResponse>(`/promotions/${encode(promotionId)}/tiers`, params)
}
/**
* @see http://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#redeem-promotion
*/
public redeem(promotionsTierId: string, params: $FixMe) {
return this.client.post(`/promotions/tiers/${encode(promotionsTierId)}/redemption`, params)
public redeem(promotionsTierId: string, params: T.PromotionTiersRedeemParams) {
return this.client.post<T.PromotionTiersRedeemResponse>(
`/promotions/tiers/${encode(promotionsTierId)}/redemption`,
params,
)
}
/**
* @see http://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#update-promotion
*/
public update(params: $FixMe) {
return this.client.put(`/promotions/tiers/${encode(params.id)}`, params)
public update(params: T.PromotionTiersUpdateParams) {
return this.client.put<T.PromotionTiersUpdateResponse>(`/promotions/tiers/${encode(params.id)}`, params)
}
/**
* @see http://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#delete-promotion
Expand Down
100 changes: 100 additions & 0 deletions packages/sdk/src/types/PromotionTiers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import { DiscountAmount, DiscountPercent, DiscountUnit } from './Vouchers'
import { OrdersCreateResponse, OrdersItem } from './Orders'

import { SimpleCustomer } from './Customers'
import { ValidationRulesListAssignmentsResponse } from './ValidationRules'

export interface PromotionTier {
id: string
object: 'promotion_tier'
name: string
banner?: string
campaign: {
id: string
object: 'campaign'
start_date?: string
expiration_date?: string
active: boolean
}
validation_rule_assignments: ValidationRulesListAssignmentsResponse
action: {
discount: DiscountUnit | DiscountPercent | DiscountAmount
}
hierarchy: number
metadata?: Record<string, any>
}

export interface PromotionTiersListAllParams {
is_available?: boolean
limit?: number
page?: number
}

export interface PromotionTiersListAllResponse {
object: 'list'
data_ref: 'tiers'
tiers: PromotionTier[]
has_more: boolean
}

export type PromotionTiersListResponse = PromotionTiersListAllResponse

export interface PromotionTiersCreateParams {
name?: string
banner?: string
action?: {
discount?: DiscountUnit | DiscountPercent | DiscountAmount
}
metadata?: Record<string, any>
}

export type PromotionTiersCreateResponse = PromotionTier

export interface PromotionTiersRedeemParams {
customer?: Omit<SimpleCustomer, 'object'> & { description?: string }
order?: {
id?: string
source_id?: string
amount?: number
items?: OrdersItem[]
status?: 'CREATED' | 'PAID' | 'CANCELLED' | 'FULFILLED'
metadata?: Record<string, any>
}
metadata?: Record<string, any>
session?: {
key: string
}
}

export interface PromotionTiersRedeemResponse {
id: string
object: 'redemption'
date: string
customer_id?: string
tracking_id?: string
order: Omit<OrdersCreateResponse, 'object' | 'customer'> & {
customer: {
id: string
object: 'customer'
referrals: $FixMe[]
}
total_discount_amount?: number
total_amount?: number
}
result?: string
promotion_tier: PromotionTier & {
summary: {
redemptions: {
total_redeemed: number
}
orders: {
total_amount: number
total_discount_amount: number
}
}
}
}

export type PromotionTiersUpdateParams = PromotionTiersCreateParams & { id: string }

export type PromotionTiersUpdateResponse = PromotionTier
34 changes: 5 additions & 29 deletions packages/sdk/src/types/Promotions.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,10 @@
import { DiscountAmount, DiscountPercent, DiscountUnit } from './Vouchers'

import { OrdersItem } from './Orders'
import { PromotionTier } from './PromotionTiers'
import { SimpleCustomer } from './Customers'
import { ValidationRulesCreateAssignmentResponse } from './ValidationRules'

export interface PromotionTier {
id: string
object: 'promotion_tier'
name: string
banner?: string
campaign: {
id: string
object: 'campaign'
start_date?: string
expiration_date?: string
active: boolean
}
action: {
discount: DiscountUnit | DiscountAmount | DiscountPercent
}
metadata?: Record<string, any>
hierarchy: number
validation_rule_assignments: {
data?: ValidationRulesCreateAssignmentResponse[]
object: 'list'
total: number
data_ref: 'data'
}
}

export interface PromotionsCreateResponse {
id: string
name: string
Expand All @@ -44,8 +20,8 @@ export interface PromotionsCreateResponse {
has_more: boolean
}
category?: string
auto_join?: boolean
join_once?: boolean
auto_join: boolean
join_once: boolean
validation_rules_assignments: {
data?: ValidationRulesCreateAssignmentResponse[]
object: 'list'
Expand All @@ -62,8 +38,8 @@ export interface PromotionsCreateResponse {
created_at: string
vouchers_generation_status: 'DONE'
active: boolean
use_voucher_metadata_schema?: boolean
protected?: boolean
use_voucher_metadata_schema: boolean
protected: boolean
object: 'campaign'
}

Expand Down
1 change: 1 addition & 0 deletions packages/sdk/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './Customers'
export * from './Balance'
export * from './PromotionTiers'
export * from './Promotions'
export * from './Loyalties'
export * from './Vouchers'
Expand Down

0 comments on commit 920b5dd

Please sign in to comment.