Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pz/types 010 - loyalties members #238

Merged
merged 68 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from 65 commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
fdbfeb4
changes to validateVoucher
p-zielinski Aug 24, 2023
4ded331
simple validations tests
p-zielinski Aug 24, 2023
6b57f8b
changelog
p-zielinski Aug 25, 2023
88a7a89
Update tidy-comics-hear.md
p-zielinski Aug 25, 2023
f869c79
node 16.20
p-zielinski Aug 25, 2023
f3a409f
node 16
p-zielinski Aug 25, 2023
b4ef41b
requested changes
p-zielinski Aug 25, 2023
9d8cb56
Update tidy-comics-hear.md
p-zielinski Aug 25, 2023
267f027
Update generateRandomString.ts
p-zielinski Sep 6, 2023
c61c01e
requested changes
p-zielinski Sep 6, 2023
6f1c213
Update package.json
p-zielinski Sep 6, 2023
238b54b
Update package.json
p-zielinski Sep 6, 2023
b580b54
Update tidy-comics-hear.md
p-zielinski Sep 6, 2023
87d34be
Revert "node 16.20"
p-zielinski Sep 6, 2023
4f982f6
minor changes
p-zielinski Sep 6, 2023
0a500c7
Delete createCampaignWithOnePromotionTierAndRandomName.ts
p-zielinski Sep 6, 2023
888db98
requested changes
p-zielinski Sep 6, 2023
4d1aa28
docs
p-zielinski Sep 6, 2023
8eb0de5
Revert "docs"
p-zielinski Sep 7, 2023
9335b25
remove validations
p-zielinski Sep 7, 2023
46a40bd
changeset
p-zielinski Sep 7, 2023
98c3dcd
Update tidy-comics-hear.md
p-zielinski Sep 7, 2023
509c2b1
Update tidy-comics-hear.md
p-zielinski Sep 7, 2023
88e887c
Update README.md
p-zielinski Sep 7, 2023
1768991
Update tidy-comics-hear.md
p-zielinski Sep 7, 2023
f37df9e
Create CHANGESET-TAMPLATE.md
p-zielinski Sep 7, 2023
747d2ad
Update tidy-comics-hear.md
p-zielinski Sep 7, 2023
9152eb1
Update CHANGESET-TAMPLATE.md
p-zielinski Sep 7, 2023
5ff5672
Update CHANGESET-TAMPLATE.md
p-zielinski Sep 7, 2023
b195dd3
Update CHANGESET-TAMPLATE.md
p-zielinski Sep 7, 2023
23a3f58
Update Loyalties.ts
p-zielinski Sep 8, 2023
127fbfa
in progress
p-zielinski Sep 11, 2023
8a11525
Update CHANGESET-TAMPLATE.md
p-zielinski Sep 11, 2023
d8355b0
Update tidy-comics-hear.md
p-zielinski Sep 11, 2023
e07b6ee
in progress
p-zielinski Sep 11, 2023
99756bc
Update CHANGESET-TAMPLATE.md
p-zielinski Sep 11, 2023
075934f
Update CHANGESET-TAMPLATE.md
p-zielinski Sep 12, 2023
fa17169
Update CHANGESET-TAMPLATE.md
p-zielinski Sep 12, 2023
e7b8489
in progress
p-zielinski Sep 12, 2023
32b04e8
readme, types
p-zielinski Sep 12, 2023
c5f897a
Update tidy-comics-five.md
p-zielinski Sep 12, 2023
374f717
Update Loyalties.ts
p-zielinski Sep 12, 2023
e27016c
fixes
p-zielinski Sep 12, 2023
fc93ff6
minor fixes
p-zielinski Sep 13, 2023
90d938c
dotenv in packages/sdk package.json
p-zielinski Sep 13, 2023
ad5e25e
requested changes
p-zielinski Sep 13, 2023
ce87618
Update tidy-comics-hear.md
p-zielinski Sep 14, 2023
7264b9b
Merge branch 'pz/types-001' into pz/types-010
p-zielinski Sep 15, 2023
79f3b54
Merge branch 'main' into pz/types-010
p-zielinski Sep 15, 2023
5222dbb
Delete tidy-comics-hear.md
p-zielinski Sep 15, 2023
d29192b
tests
p-zielinski Sep 15, 2023
0b7ca13
Update loyalties.spec.ts
p-zielinski Sep 16, 2023
219f12c
not finished, few changes
p-zielinski Oct 4, 2023
57babff
methods, readme
p-zielinski Oct 4, 2023
14a8c6b
in progress
p-zielinski Oct 4, 2023
46b8f97
naming
p-zielinski Oct 4, 2023
950b871
Update tidy-comics-five.md
p-zielinski Oct 4, 2023
74692ec
Update README.md
p-zielinski Oct 4, 2023
6504c8c
Update README.md
p-zielinski Oct 5, 2023
ccd7134
new types
p-zielinski Oct 5, 2023
2e27599
export and changeset
p-zielinski Oct 5, 2023
f5ced06
Update Loyalties.ts
p-zielinski Oct 9, 2023
7e0c796
Update Loyalties.ts
p-zielinski Oct 9, 2023
23669b5
fix
p-zielinski Oct 9, 2023
ac77af4
Merge branch 'main' into pz/types-010
p-zielinski Oct 9, 2023
a78d0ef
Update Loyalties.ts
p-zielinski Oct 11, 2023
88d8c96
Update Loyalties.ts
p-zielinski Oct 11, 2023
b10f51d
fix
p-zielinski Oct 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/tidy-comics-five.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@voucherify/sdk': minor
---

Add support for few endpoints of Loyalties API.
- Added support for new endpoints: `GET /loyalties/members/{memberId}`, `GET /loyalties/members/{memberId}/activities`, `GET /loyalties/members/{memberId}/rewards`, `POST /loyalties/{campaignId}/members/{memberId}/transfers`, `GET /loyalties/{campaignId}/members/{memberId}/points-expiration`, `GET /loyalties/members/{memberId}/transactions`, `GET /loyalties/{campaignId}/members/{memberId}/transactions`, `POST /loyalties/members/{memberId}/transactions/export` and `POST /loyalties/{campaignId}/members/{memberId}/transactions/export` [(examples of usage available in readme.md)](..%2F..%2Fpackages%2Fsdk%2FREADME.md)
- New exported types/interfaces: `LoyaltiesTransferPointsResponseBody`, `LoyaltiesTransferPointsRequestBody`, `LoyaltiesListMemberRewardsRequestQuery`, `LoyaltiesListMemberRewardsResponseBody`, `LoyaltiesGetPointsExpirationRequestQuery`, `LoyaltiesGetPointsExpirationResponseBody`, `LoyaltiesListCardTransactionsRequestQuery`, `LoyaltiesListCardTransactionsResponseBody`, `LoyaltiesExportCardTransactionsRequestBody`, `LoyaltiesExportCardTransactionsResponseBody`, `LoyaltiesAddOrRemoveCardBalanceRequestBody`, `LoyaltiesAddOrRemoveCardBalanceResponseBody`, `LoyaltyCardTransaction`, `SimpleLoyaltyVoucher`, `LoyaltiesTransferPoints`, `LoyaltyCardTransactionsFields`, `LoyaltyCardTransactionsType`, `Reward`, `RewardTypeCampaign`, `RewardTypeCoin`, `RewardTypeMaterial`, `RewardType`, `RewardAssignment`
80 changes: 77 additions & 3 deletions packages/sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -990,10 +990,15 @@ Methods are provided within `client.loyalties.*` namespace.
- [List Loyalty Program Earning Rules](#list-loyalty-program-earning-rules)
- [Create Loyalty Program Member](#create-loyalty-program-member)
- [Get Loyalty Program Member](#get-loyalty-program-member)
- [List Loyalty Program Members](#list-loyalty-members)
- [List Loyalty Program Members](#list-loyalty-program-members)
- [Get Loyalty Program Member Activities](#get-loyalty-program-member-activities)
- [Add Loyalty Card Balance](#add-loyalty-card-balance)
p-zielinski marked this conversation as resolved.
Show resolved Hide resolved
- [Add Or Remove Loyalty Card Balance](#add-or-remove-loyalty-card-balance)
- [[Deprecated] Add Loyalty Card Balance](#add-loyalty-card-balance)
marcin-slezak marked this conversation as resolved.
Show resolved Hide resolved
- [Transfer Loyalty Points](#transfer-loyalty-points)
- [Get Loyalty Points Expiration](#get-loyalty-points-expiration)
- [Redeem Loyalty Card](#redeem-loyalty-card)
- [List Loyalty Card Transactions](#list-loyalty-card-transactions)
- [[Export Loyalty Card Transactions](#export-loyalty-card-transactions)

#### [Create Loyalty Program](https://docs.voucherify.io/reference/create-loyalty-program)

Expand Down Expand Up @@ -1102,6 +1107,8 @@ client.loyalties.createMember(campaignId, member)

#### [Get Loyalty Program Member](https://docs.voucherify.io/reference/get-member)

Depending on the parameters, this method sends requests to [v1/loyalties/members/{memberId}](https://docs.voucherify.io/reference/get-member) or [v1/loyalties/{campaignId}/members/{memberId}](https://docs.voucherify.io/reference/get-member-1) API endpoint

```javascript
client.loyalties.getMember(campaignId, memberId)
```
Expand All @@ -1115,20 +1122,63 @@ client.loyalties.listMembers(campaignId, params)

#### [Get Loyalty Program Member Activities](https://docs.voucherify.io/reference#get-member-activities)

Depending on the parameters, this method sends requests to [v1/loyalties/members/{memberId}/activities](https://docs.voucherify.io/reference/get-member-activities) or [v1/loyalties/{campaignId}/members/{memberId}/activities](https://docs.voucherify.io/reference/get-member-activities-1) API endpoint

```javascript
client.loyalties.getMemberActivities(campaignId, memberId)
```

`memberId` referrers to Loyalty Card code.

#### [Add Loyalty Card Balance](https://docs.voucherify.io/reference/add-loyalty-card-balance)

#### [List Member Rewards](https://docs.voucherify.io/reference/list-member-rewards)

```javascript
client.loyalties.listMemberRewards(memberId, params)
```

`memberId` referrers to Loyalty Card code.

---

#### [Add Or Remove Loyalty Card Balance](https://docs.voucherify.io/reference/add-remove-loyalty-card-balance)

Depending on the parameters, this method sends requests to [v1/loyalties/members/{memberId}/balance](https://docs.voucherify.io/reference/add-remove-loyalty-card-balance) or [v1/loyalties/{campaignId}/members/{memberId}/balance](https://docs.voucherify.io/reference/add-remove-loyalty-card-balance-1) API endpoint

```javascript
client.loyalties.addOrRemoveCardBalance(memberId, balance, campaignId)
```

`memberId` referrers to Loyalty Card code.

#### [Add Loyalty Card Balance](https://docs.voucherify.io/reference/add-loyalty-card-balance-1)

```javascript
client.loyalties.addPoints(campaignId, memberId, balance)
```

`memberId` referrers to Loyalty Card code.

#### [Transfer Loyalty Points](https://docs.voucherify.io/reference/transfer-points)

```javascript
client.loyalties.transferPoints(campaignId, memberId, transferLoyaltyPoints)
```

`memberId` referrers to Loyalty Card code.

---

#### [Get Loyalty Points Expiration](https://docs.voucherify.io/reference/get-points-expiration)

```javascript
client.loyalties.getPointsExpiration(campaignId, memberId)
```

`memberId` referrers to Loyalty Card code.

---

#### [Redeem Loyalty Card]

```javascript
Expand All @@ -1141,6 +1191,30 @@ When redeeming reward with type `COIN` you need to provide additional `order` ob

---

#### [List Loyalty Card Transactions](https://docs.voucherify.io/reference/list-loyalty-card-transactions)

Depending on the parameters, this method sends requests to [v1/loyalties/members/{memberId}/transactions](https://docs.voucherify.io/reference/list-loyalty-card-transactions) or [v1/loyalties/{campaignId}/members/{memberId}/transactions](https://docs.voucherify.io/reference/list-loyalty-card-transactions-1) API endpoint

```javascript
client.loyalties.listCardTransactions(memberId, campaignId, params)
```

`memberId` referrers to Loyalty Card code.

---

#### [Export Loyalty Card Transactions](https://docs.voucherify.io/reference/export-loyalty-card-transactions)

Depending on the parameters, this method sends requests to [v1/loyalties/members/{memberId}/transactions/export](https://docs.voucherify.io/reference/export-loyalty-card-transactions) or [v1/loyalties/{campaignId}/members/{memberId}/transactions/export](https://docs.voucherify.io/reference/export-loyalty-card-transactions-1) API endpoint

```javascript
client.loyalties.exportCardTransactions(memberId, campaignId, params)
```

`memberId` referrers to Loyalty Card code.

---

### Segments

Methods are provided within `client.segments.*` namespace.
Expand Down
99 changes: 94 additions & 5 deletions packages/sdk/src/Loyalties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,27 +142,84 @@ export class Loyalties {
}
/**
* @see https://docs.voucherify.io/reference/get-member
* @see https://docs.voucherify.io/reference/get-member-1
*/
public getMember(campaignId: string, memberId: string) {
return this.client.get<T.LoyaltiesGetMemberResponse>(`/loyalties/${encode(campaignId)}/members/${memberId}`)
public getMember(campaignId: string | null, memberId: string) {
return this.client.get<T.LoyaltiesGetMemberResponse>(
campaignId ? `/loyalties/${encode(campaignId)}/members/${memberId}` : `/loyalties/members/${memberId}`,
)
}
/**
* @see https://docs.voucherify.io/reference/get-member-activities
* @see https://docs.voucherify.io/reference/get-member-activities-1
*/
public getMemberActivities(campaignId: string, memberId: string) {
public getMemberActivities(campaignId: string | null, memberId: string) {
return this.client.get<T.LoyaltiesGetMemberActivitiesResponse>(
`/loyalties/${encode(campaignId)}/members/${memberId}/activities`,
campaignId
? `/loyalties/${encode(campaignId)}/members/${memberId}/activities`
: `/loyalties/members/${memberId}/activities`,
)
}
/**
* @see https://docs.voucherify.io/reference/list-member-rewards
*/
public listMemberRewards(memberId: string, params?: T.LoyaltiesListMemberRewardsRequestQuery) {
return this.client.get<T.LoyaltiesListMemberRewardsResponseBody>(
`/loyalties/members/${encode(memberId)}/rewards`,
params,
)
}
/**
* @see https://docs.voucherify.io/reference/add-loyalty-card-balance
* @see https://docs.voucherify.io/reference/add-remove-loyalty-card-balance
* @see https://docs.voucherify.io/reference/add-remove-loyalty-card-balance-1
*/
public addOrRemoveCardBalance(
memberId: string,
balance: T.LoyaltiesAddOrRemoveCardBalanceRequestBody,
campaignId?: string,
) {
return this.client.post<T.LoyaltiesAddOrRemoveCardBalanceResponseBody>(
campaignId
? `/loyalties/${encode(campaignId)}/members/${memberId}/balance`
: `/loyalties/members/${memberId}/balance`,
balance,
)
}
/**
* @see https://docs.voucherify.io/reference/add-remove-loyalty-card-balance-1
*/
public addPoints(campaignId: string, memberId: string, balance: T.LoyaltiesAddPoints) {
return this.client.post<T.LoyaltiesAddPointsResponse>(
`/loyalties/${encode(campaignId)}/members/${memberId}/balance`,
balance,
)
}
/**
* @see https://docs.voucherify.io/reference/transfer-points
*/
public transferPoints(
campaignId: string,
memberId: string,
loyaltiesTransferPoints: T.LoyaltiesTransferPointsRequestBody,
) {
return this.client.post<T.LoyaltiesTransferPointsResponseBody>(
`/loyalties/${encode(campaignId)}/members/${encode(memberId)}/transfers`,
loyaltiesTransferPoints,
)
}
/**
* @see https://docs.voucherify.io/reference/get-points-expiration
*/
public getPointsExpiration(
campaignId: string,
memberId: string,
params?: T.LoyaltiesGetPointsExpirationRequestQuery,
) {
return this.client.get<T.LoyaltiesGetPointsExpirationResponseBody>(
`/loyalties/${encode(campaignId)}/members/${memberId}/points-expiration`,
params,
)
}
/**
* @see https://docs.voucherify.io/reference/redeem-loyalty-card
*/
Expand All @@ -172,4 +229,36 @@ export class Loyalties {
params,
)
}
/**
* @see https://docs.voucherify.io/reference/list-loyalty-card-transactions
* @see https://docs.voucherify.io/reference/list-loyalty-card-transactions-1
*/
public listCardTransactions(
memberId: string,
campaignId: string | null,
params?: T.LoyaltiesListCardTransactionsRequestQuery,
) {
return this.client.get<T.LoyaltiesListCardTransactionsResponseBody>(
campaignId
? `/loyalties/${encode(campaignId)}/members/${encode(memberId)}/transactions`
: `/loyalties/members/${encode(memberId)}/transactions`,
params,
)
}
/**
* @see https://docs.voucherify.io/reference/export-loyalty-card-transactions
* @see https://docs.voucherify.io/reference/export-loyalty-card-transactions-1
*/
public exportCardTransactions(
memberId: string,
campaignId: string | null,
params: T.LoyaltiesExportCardTransactionsRequestBody = {},
) {
return this.client.post<T.LoyaltiesExportCardTransactionsResponseBody>(
campaignId
? `/loyalties/${encode(campaignId)}/members/${encode(memberId)}/transactions/export`
: `/loyalties/members/${encode(memberId)}/transactions/export`,
params,
)
}
}
Loading
Loading