Skip to content

Commit

Permalink
Segments types & missing Segment List method (#29)
Browse files Browse the repository at this point in the history
* Added Segments types & missing Segment List POST method

* Updated segment types
  • Loading branch information
pkgacek authored Jan 21, 2021
1 parent 20752b9 commit 3276101
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/olive-ants-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@voucherify/sdk': patch
---

Added Segments types & missing Segment List method
15 changes: 12 additions & 3 deletions packages/sdk/src/Segments.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as T from './types/Segments'

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

Expand All @@ -7,19 +9,26 @@ export class Segments {
/**
* @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#create-segment
*/
public create(segment: $FixMe) {
return this.client.post('/segments', segment)
public create(segment: T.SegmentsCreate) {
return this.client.post<T.SegmentsCreateResponse>('/segments', segment)
}
/**
* @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#get-segment
*/
public get(segmentId: string) {
return this.client.get(`/segments/${encode(segmentId)}`)
return this.client.get<T.SegmentsGetResponse>(`/segments/${encode(segmentId)}`)
}
/**
* @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#delete-segment
*/
public delete(segmentId: string) {
return this.client.delete(`/segments/${encode(segmentId)}`)
}

/**
* @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#list-segments
*/
public list(customerId: string) {
return this.client.get<T.SegmentsListResponse>(`/customers/${encode(customerId)}/segments`)
}
}
35 changes: 35 additions & 0 deletions packages/sdk/src/types/Segments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
export interface SegmentsCreate {
name: string
type: 'static' | 'auto-update'
filter?: {
junction?: 'AND' | 'OR'
[filter_conditions: string]: $FixMe
}
customers?: string[]
}

export interface SegmentsCreateResponse {
id: string
name: string
created_at: string
metadata?: $FixMe
filter?: {
junction?: 'AND' | 'OR'
[filter_conditions: string]: $FixMe
}
type?: string
object: 'segment'
}

export type SegmentsGetResponse = SegmentsCreateResponse

export interface SegmentsListResponse {
object: 'list'
total: number
data_ref: 'data'
data: {
id: string
name: string
object: 'segment'
}[]
}
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 './Segments'
export * from './Exports'
export * from './Orders'
export * from './Consents'
Expand Down

0 comments on commit 3276101

Please sign in to comment.