@pax2pay/client 0.3.51 → 0.3.53

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.
Files changed (100) hide show
  1. package/Client/Accounts/index.ts +40 -32
  2. package/Client/Beneficiaries/index.ts +15 -17
  3. package/Client/Cards/index.ts +62 -88
  4. package/Client/Categories/index.ts +9 -9
  5. package/Client/Configuration/index.ts +5 -9
  6. package/Client/Connection.ts +9 -1
  7. package/Client/Email/index.ts +1 -2
  8. package/Client/List.ts +4 -32
  9. package/Client/Omnisetup/index.ts +3 -1
  10. package/Client/Organisations/index.ts +7 -15
  11. package/Client/Reports/index.spec.ignore.ts +0 -7
  12. package/Client/Reports/index.ts +22 -33
  13. package/Client/Transfers/factory.ts +4 -2
  14. package/Client/Transfers/index.ts +4 -19
  15. package/Client/Users/index.ts +29 -33
  16. package/Client/index.ts +1 -20
  17. package/dist/Client/Accounts/index.d.ts +3 -6
  18. package/dist/Client/Accounts/index.js +25 -19
  19. package/dist/Client/Accounts/index.js.map +1 -1
  20. package/dist/Client/Beneficiaries/index.d.ts +3 -7
  21. package/dist/Client/Beneficiaries/index.js +11 -15
  22. package/dist/Client/Beneficiaries/index.js.map +1 -1
  23. package/dist/Client/Cards/index.d.ts +14 -19
  24. package/dist/Client/Cards/index.js +28 -61
  25. package/dist/Client/Cards/index.js.map +1 -1
  26. package/dist/Client/Categories/index.d.ts +4 -6
  27. package/dist/Client/Categories/index.js +7 -10
  28. package/dist/Client/Categories/index.js.map +1 -1
  29. package/dist/Client/Configuration/index.js +5 -9
  30. package/dist/Client/Configuration/index.js.map +1 -1
  31. package/dist/Client/Connection.js +7 -1
  32. package/dist/Client/Connection.js.map +1 -1
  33. package/dist/Client/Email/index.js +1 -2
  34. package/dist/Client/Email/index.js.map +1 -1
  35. package/dist/Client/List.d.ts +3 -24
  36. package/dist/Client/List.js +1 -17
  37. package/dist/Client/List.js.map +1 -1
  38. package/dist/Client/Omnisetup/index.js +3 -1
  39. package/dist/Client/Omnisetup/index.js.map +1 -1
  40. package/dist/Client/Organisations/index.d.ts +5 -6
  41. package/dist/Client/Organisations/index.js +7 -8
  42. package/dist/Client/Organisations/index.js.map +1 -1
  43. package/dist/Client/Reports/index.d.ts +1 -1
  44. package/dist/Client/Reports/index.js +15 -29
  45. package/dist/Client/Reports/index.js.map +1 -1
  46. package/dist/Client/Transfers/index.d.ts +3 -7
  47. package/dist/Client/Transfers/index.js +3 -15
  48. package/dist/Client/Transfers/index.js.map +1 -1
  49. package/dist/Client/Users/index.d.ts +5 -6
  50. package/dist/Client/Users/index.js +20 -27
  51. package/dist/Client/Users/index.js.map +1 -1
  52. package/dist/Client/index.d.ts +1 -21
  53. package/dist/Client/index.js.map +1 -1
  54. package/dist/index.d.ts +2 -2
  55. package/dist/index.js.map +1 -1
  56. package/dist/model/index.d.ts +1 -2
  57. package/dist/model/index.js.map +1 -1
  58. package/index.ts +0 -2
  59. package/model/index.ts +0 -2
  60. package/package.json +1 -1
  61. package/Client/Account/index.ts +0 -9
  62. package/Client/Beneficiary/index.ts +0 -9
  63. package/Client/Card/index.ts +0 -57
  64. package/Client/Collection.ts +0 -24
  65. package/Client/Organisation/index.ts +0 -9
  66. package/Client/Resource.ts +0 -25
  67. package/Client/Transfer/index.ts +0 -9
  68. package/Client/User/index.ts +0 -9
  69. package/Client/generatePagination.ts +0 -14
  70. package/dist/Client/Account/index.d.ts +0 -6
  71. package/dist/Client/Account/index.js +0 -7
  72. package/dist/Client/Account/index.js.map +0 -1
  73. package/dist/Client/Beneficiary/index.d.ts +0 -6
  74. package/dist/Client/Beneficiary/index.js +0 -7
  75. package/dist/Client/Beneficiary/index.js.map +0 -1
  76. package/dist/Client/Card/index.d.ts +0 -24
  77. package/dist/Client/Card/index.js +0 -25
  78. package/dist/Client/Card/index.js.map +0 -1
  79. package/dist/Client/Collection.d.ts +0 -31
  80. package/dist/Client/Collection.js +0 -19
  81. package/dist/Client/Collection.js.map +0 -1
  82. package/dist/Client/Organisation/index.d.ts +0 -6
  83. package/dist/Client/Organisation/index.js +0 -7
  84. package/dist/Client/Organisation/index.js.map +0 -1
  85. package/dist/Client/Resource.d.ts +0 -17
  86. package/dist/Client/Resource.js +0 -38
  87. package/dist/Client/Resource.js.map +0 -1
  88. package/dist/Client/Transfer/index.d.ts +0 -6
  89. package/dist/Client/Transfer/index.js +0 -7
  90. package/dist/Client/Transfer/index.js.map +0 -1
  91. package/dist/Client/User/index.d.ts +0 -6
  92. package/dist/Client/User/index.js +0 -7
  93. package/dist/Client/User/index.js.map +0 -1
  94. package/dist/Client/generatePagination.d.ts +0 -6
  95. package/dist/Client/generatePagination.js +0 -9
  96. package/dist/Client/generatePagination.js.map +0 -1
  97. package/dist/model/Sorting.d.ts +0 -8
  98. package/dist/model/Sorting.js +0 -2
  99. package/dist/model/Sorting.js.map +0 -1
  100. package/model/Sorting.ts +0 -6
@@ -1,25 +1,13 @@
1
1
  import * as model from "../../model"
2
- import { Account } from "../Account"
3
2
  import { Connection } from "../Connection"
4
3
  import { List } from "../List"
5
4
  import { Paginated } from "../Paginated"
6
- import { Resource } from "../Resource"
7
5
 
8
- export class Accounts extends List<model.AccountResponse, model.AccountSearchRequest> {
6
+ export class Accounts extends List<model.AccountResponse> {
9
7
  protected folder = "funding-accounts"
10
8
  private constructor(connection: Connection) {
11
9
  super(connection)
12
10
  }
13
- protected getResourcePath(resource: model.AccountResponse): string {
14
- return [this.folder, resource.provider, resource.providerAccountId].join("/")
15
- }
16
- protected createResource(response: model.AccountResponse): Resource<model.AccountResponse, { [key: string]: any }> {
17
- return new Account(
18
- this.connection,
19
- [this.folder, response.provider, response.providerAccountId].join("/"),
20
- response
21
- )
22
- }
23
11
  static create(connection: Connection) {
24
12
  return new Accounts(connection)
25
13
  }
@@ -35,28 +23,29 @@ export class Accounts extends List<model.AccountResponse, model.AccountSearchReq
35
23
  totalCount: number
36
24
  }
37
25
  | model.ErrorResponse
38
- >(`account-summaries?refresh=false&providerCodes=${providerCodes}${accountId ? `&accountId=${accountId}` : ""}${
39
- accountStates ? `&accountStates=${accountStates}` : ""
40
- }${providerAccountId ? `&providerAccountId=${providerAccountId}` : ""}
41
- `)
42
- return this.extractResponse(response)
26
+ >(`account-summaries`, {
27
+ refresh: false,
28
+ providerCodes: providerCodes,
29
+ accountId: accountId,
30
+ accountStates: accountStates,
31
+ providerAccountId: providerAccountId,
32
+ })
33
+ return this.extractResponse<model.AccountSummary>(response)
43
34
  }
44
35
  async updateFundingAccount(
45
36
  providerCode: model.ProviderCode,
46
37
  providerAccountId: string,
47
38
  request: model.UpdateAccountRequest
48
39
  ) {
49
- const response = await this.connection.put<Promise<model.ErrorResponse | model.AccountResponse>>(
50
- `funding-accounts/${providerCode}/${providerAccountId}`,
40
+ return await this.connection.put<Promise<model.ErrorResponse | model.AccountResponse>>(
41
+ `${this.folder}/${providerCode}/${providerAccountId}`,
51
42
  request
52
43
  )
53
- return response
54
44
  }
55
45
  async cancelLimitAlert(providerCode: model.ProviderCode, providerAccountId: string) {
56
- const response = await this.connection.remove<Promise<model.ErrorResponse | model.AccountResponse>>(
57
- `funding-accounts/${providerCode}/${providerAccountId}/limits`
46
+ return await this.connection.remove<Promise<model.ErrorResponse | model.AccountResponse>>(
47
+ `${this.folder}/${providerCode}/${providerAccountId}/limits`
58
48
  )
59
- return response
60
49
  }
61
50
 
62
51
  async getAllFundingAccountsV2Paginated(
@@ -71,7 +60,7 @@ export class Accounts extends List<model.AccountResponse, model.AccountSearchReq
71
60
  (page, size, sort) =>
72
61
  this.connection.get<
73
62
  { list: model.FundingAccountResponseV2Basic[]; totalCount: number } | model.FundingAccountResponseV2Basic[]
74
- >(`v2/funding-accounts`, {
63
+ >(`v2/${this.folder}`, {
75
64
  page: page,
76
65
  size: size,
77
66
  sort: sort,
@@ -95,7 +84,7 @@ export class Accounts extends List<model.AccountResponse, model.AccountSearchReq
95
84
  (page, size, sort) =>
96
85
  this.connection.get<
97
86
  { list: model.FundingAccountResponseV2Full[]; totalCount: number } | model.FundingAccountResponseV2Full[]
98
- >(`v2/funding-accounts/info`, {
87
+ >(`v2/${this.folder}/info`, {
99
88
  page: page,
100
89
  size: size,
101
90
  sort: sort,
@@ -108,15 +97,34 @@ export class Accounts extends List<model.AccountResponse, model.AccountSearchReq
108
97
  )
109
98
  }
110
99
  async getFundingAccountV2(providerCode: model.ProviderCode, providerCodeId: string) {
111
- const response = await this.connection.get<model.FundingAccountResponseV2Basic>(
112
- `v2/funding-accounts/${providerCode}/${providerCodeId}`
100
+ return await this.connection.get<model.FundingAccountResponseV2Basic>(
101
+ `v2/${this.folder}/${providerCode}/${providerCodeId}`
113
102
  )
114
- return response
115
103
  }
116
104
  async getFundingAccountV2Full(providerCode: model.ProviderCode, providerCodeId: string) {
117
- const response = await this.connection.get<model.FundingAccountResponseV2Full>(
118
- `v2/funding-accounts/${providerCode}/${providerCodeId}/info`
105
+ return await this.connection.get<model.FundingAccountResponseV2Full>(
106
+ `v2/${this.folder}/${providerCode}/${providerCodeId}/info`
107
+ )
108
+ }
109
+ async getFundingAccounts(
110
+ searchRequest: model.FundingAccountSearchRequest
111
+ ): Promise<model.ErrorResponse | model.AccountResponse[]> {
112
+ const response = await this.connection.post<{ list: model.AccountResponse[]; totalCount: number }>(
113
+ `${this.folder}/searches`,
114
+ searchRequest
119
115
  )
120
- return response
116
+ return this.extractResponse(response)
117
+ }
118
+ async getAllFundingAccounts(
119
+ providerCode: model.ProviderCode,
120
+ size = 500,
121
+ sort = "friendlyName"
122
+ ): Promise<model.ErrorResponse | model.AccountResponse[]> {
123
+ const response = await this.connection.get<{ list: model.AccountResponse[]; totalCount: number }>(this.folder, {
124
+ provider: providerCode,
125
+ size: size,
126
+ sort: sort,
127
+ })
128
+ return this.extractResponse(response)
121
129
  }
122
130
  }
@@ -1,9 +1,8 @@
1
1
  import * as model from "../../model"
2
- import { Beneficiary } from "../Beneficiary"
3
2
  import { Connection } from "../Connection"
4
3
  import { List } from "../List"
5
4
 
6
- export class Beneficiaries extends List<model.BeneficiaryResponse, model.BeneficiaryRequest> {
5
+ export class Beneficiaries extends List<model.BeneficiaryResponse> {
7
6
  protected folder = "beneficiaries"
8
7
  constructor(connection: Connection) {
9
8
  super(connection)
@@ -11,16 +10,14 @@ export class Beneficiaries extends List<model.BeneficiaryResponse, model.Benefic
11
10
  static create(connection: Connection): Beneficiaries {
12
11
  return new Beneficiaries(connection)
13
12
  }
14
- protected getResourcePath(resource: model.BeneficiaryResponse): string {
15
- return [this.folder, resource.beneficiaryId].join("/")
16
- }
17
- protected createResource(response: model.BeneficiaryResponse): Beneficiary {
18
- return new Beneficiary(this.connection, [this.folder, response.beneficiaryId].join("/"), response)
19
- }
20
-
21
13
  async getAll(sort?: string): Promise<model.ErrorResponse | model.BeneficiaryResponse[]> {
22
14
  const response = await this.connection.get<{ list: model.BeneficiaryResponse[]; totalCount: number }>(
23
- `${this.folder}?page=0&size=1500${sort ? "&sort=" + sort : ""}`
15
+ `${this.folder}`,
16
+ {
17
+ page: 0,
18
+ size: 1500,
19
+ sort: sort,
20
+ }
24
21
  )
25
22
  return this.extractResponse(response)
26
23
  }
@@ -29,17 +26,18 @@ export class Beneficiaries extends List<model.BeneficiaryResponse, model.Benefic
29
26
  }
30
27
  async searchBeneficiary(request: model.SearchBeneficiaryRequest, sort?: string) {
31
28
  const response = await this.connection.post<model.ErrorResponse | model.BeneficiaryResponse[]>(
32
- `${this.folder}/searches?page=0&size=1500${sort ? "&sort=" + sort : ""}`,
33
- request
29
+ `${this.folder}/searches`,
30
+ request,
31
+ {
32
+ page: 0,
33
+ size: 1500,
34
+ sort: sort,
35
+ }
34
36
  )
35
37
  return this.extractResponse(response)
36
38
  }
37
- protected map(response: model.BeneficiaryResponse): Beneficiary & model.BeneficiaryResponse {
38
- return Object.assign(new Beneficiary(this.connection, this.getResourcePath(response), response), response)
39
- }
40
39
  async create(request: model.BeneficiaryRequest) {
41
- const result = await this.connection.post<model.BeneficiaryResponse>(`${this.folder}`, request)
42
- return model.ErrorResponse.is(result) ? result : this.map(result)
40
+ return await this.connection.post<model.BeneficiaryResponse>(`${this.folder}`, request)
43
41
  }
44
42
  async update(beneficiaryId: string, request: model.UpdateBeneficiaryRequest) {
45
43
  return await this.connection.put<model.BeneficiaryResponse>(`${this.folder}/${beneficiaryId}`, request)
@@ -1,34 +1,15 @@
1
1
  import * as model from "../../model"
2
- import { Card } from "../Card"
3
2
  import { Connection } from "../Connection"
4
3
  import { List } from "../List"
5
4
  import { Paginated } from "../Paginated"
6
5
 
7
- export class Cards extends List<
8
- model.CardResponseV2 | model.CardResponse,
9
- model.CardSearch,
10
- model.CreateCardRequest,
11
- Card
12
- > {
13
- protected folder = "cards/virtual"
6
+ export class Cards extends List<model.CardResponseV2 | model.CardResponse> {
7
+ protected readonly folder = "cards"
14
8
  constructor(connection: Connection) {
15
9
  super(connection)
16
10
  }
17
- protected getResourcePath(resource: model.CardResponseV2 | model.CardResponse): string {
18
- return [this.folder, resource.providerCode, resource.providerCardId].join("/")
19
- }
20
- protected createResource(response: model.CardResponseV2): Card {
21
- return new Card(this.connection, [this.folder, response.providerCode, response.providerCardId].join("/"), response)
22
- }
23
- protected map(response: model.CardResponseV2): Card & model.CardResponseV2 {
24
- return Object.assign(new Card(this.connection, this.getResourcePath(response), response), response)
25
- }
26
- protected mapLegacy(response: model.CardResponse): Card & model.CardResponse {
27
- return Object.assign(new Card(this.connection, this.getResourcePath(response), response), response)
28
- }
29
11
  async create(request: model.CreateCardRequest) {
30
- const result = await this.connection.post<model.CardResponseV2>("v2/cards/virtual/tokenised", request)
31
- return model.ErrorResponse.is(result) ? result : this.map(result)
12
+ return await this.connection.post<model.CardResponseV2>(`v2/${this.folder}/virtual/tokenised`, request)
32
13
  }
33
14
  async createCardWithRemittanceAdvice(request: model.CreateCardRequest, file: File) {
34
15
  const formData = new FormData()
@@ -39,12 +20,10 @@ export class Cards extends List<
39
20
  type: "application/json",
40
21
  })
41
22
  )
42
- const result = await this.connection.post<model.CardResponseV2>("v2/cards/virtual", formData)
43
- return model.ErrorResponse.is(result) ? result : this.map(result)
23
+ return await this.connection.post<model.CardResponseV2>(`v2/${this.folder}/virtual`, formData)
44
24
  }
45
25
  async createLegacy(request: model.CreateCardRequest) {
46
- const result = await this.connection.post<model.CardResponse>("cards/virtual", request)
47
- return model.ErrorResponse.is(result) ? result : this.mapLegacy(result)
26
+ return await this.connection.post<model.CardResponse>(`${this.folder}/virtual`, request)
48
27
  }
49
28
  static create(connection: Connection): Cards {
50
29
  return new Cards(connection)
@@ -60,13 +39,16 @@ export class Cards extends List<
60
39
  return await this.getNextPaginated<model.CardResponseV2>(
61
40
  previous,
62
41
  (page, size, sort) =>
63
- this.connection.get<{ list: model.CardResponseV2[]; totalCount: number } | model.CardResponseV2[]>(`v2/cards`, {
64
- page: page,
65
- size: size,
66
- sort: sort,
67
- provider: providerCode,
68
- includeCount: includeCount,
69
- }),
42
+ this.connection.get<{ list: model.CardResponseV2[]; totalCount: number } | model.CardResponseV2[]>(
43
+ `v2/${this.folder}`,
44
+ {
45
+ page: page,
46
+ size: size,
47
+ sort: sort,
48
+ provider: providerCode,
49
+ includeCount: includeCount,
50
+ }
51
+ ),
70
52
  undefined,
71
53
  page,
72
54
  size,
@@ -74,73 +56,64 @@ export class Cards extends List<
74
56
  )
75
57
  }
76
58
  async getCard(providerCardId: string, providerCode: model.ProviderCode) {
77
- const result = await this.connection
78
- .get<model.CardResponse>(`cards/virtual/${providerCode}/${providerCardId}?includeSchedules=true
79
- `)
80
- return model.ErrorResponse.is(result) ? result : this.mapLegacy(result)
59
+ return await this.connection.get<model.CardResponse>(`${this.folder}/virtual/${providerCode}/${providerCardId}`, {
60
+ includeSchedules: true,
61
+ })
81
62
  }
82
63
  async getCardV2(providerCardId: string, providerCode: model.ProviderCode) {
83
- const result = await this.connection.get<model.CardResponseV2>(`v2/cards/virtual/${providerCode}/${providerCardId}
64
+ return await this.connection.get<model.CardResponseV2>(`v2/${this.folder}/virtual/${providerCode}/${providerCardId}
84
65
  `)
85
- return model.ErrorResponse.is(result) ? result : this.map(result)
86
66
  }
87
67
  async createCard(request: model.CreateCardRequest) {
88
- const result = await this.connection.post<model.CardResponse>(`cards/virtual`, request)
89
- return model.ErrorResponse.is(result) ? result : this.mapLegacy(result)
68
+ return await this.connection.post<model.CardResponse>(`${this.folder}/virtual`, request)
90
69
  }
91
70
  async cancelCard(providerCardId: string, providerCode: model.ProviderCode) {
92
- const result = await this.connection.remove<model.CardResponse>(
93
- `cards/virtual/${providerCode}/${providerCardId}/cancel`
71
+ return await this.connection.remove<model.CardResponse>(
72
+ `${this.folder}/virtual/${providerCode}/${providerCardId}/cancel`
94
73
  )
95
- return result
96
74
  }
97
75
  async cancelCardV2(providerCardId: string, providerCode: model.ProviderCode) {
98
- const result = await this.connection.remove<model.CardResponseV2>(
99
- `v2/cards/virtual/${providerCode}/${providerCardId}/cancel`
76
+ return await this.connection.remove<model.CardResponseV2>(
77
+ `v2/${this.folder}/virtual/${providerCode}/${providerCardId}/cancel`
100
78
  )
101
- return result
102
79
  }
103
80
  async generateCardV2(providerCardId: string, providerCode: model.ProviderCode) {
104
- const result = await this.connection.get<model.CardResponseV2>(
105
- `v2/cards/virtual/${providerCode}/${providerCardId}/generate/tokenised`
81
+ return await this.connection.get<model.CardResponseV2>(
82
+ `v2/${this.folder}/virtual/${providerCode}/${providerCardId}/generate/tokenised`
106
83
  )
107
- return result
108
84
  }
109
85
  async approveCardV2(providerCardId: string, providerCode: model.ProviderCode) {
110
- const result = await this.connection.post<model.CardResponseV2>(
111
- `v2/cards/virtual/${providerCode}/${providerCardId}/approve`,
86
+ return await this.connection.post<model.CardResponseV2>(
87
+ `v2/${this.folder}/virtual/${providerCode}/${providerCardId}/approve`,
112
88
  undefined
113
89
  )
114
- return result
115
90
  }
116
91
  async declineCardV2(providerCardId: string, providerCode: model.ProviderCode) {
117
- const result = await this.connection.post<model.CardResponseV2>(
118
- `v2/cards/virtual/${providerCode}/${providerCardId}/decline`,
92
+ return await this.connection.post<model.CardResponseV2>(
93
+ `v2/${this.folder}/virtual/${providerCode}/${providerCardId}/decline`,
119
94
  undefined
120
95
  )
121
- return result
122
96
  }
123
97
  async thawCardV2(providerCardId: string, providerCode: model.ProviderCode) {
124
- const result = await this.connection.get<model.CardResponseV2>(
125
- `v2/cards/virtual/${providerCode}/${providerCardId}/thaw`
98
+ return await this.connection.get<model.CardResponseV2>(
99
+ `v2/${this.folder}/virtual/${providerCode}/${providerCardId}/thaw`
126
100
  )
127
- return result
128
101
  }
129
102
  async freezeCardV2(providerCardId: string, providerCode: model.ProviderCode) {
130
- const result = await this.connection.get<model.CardResponseV2>(
131
- `v2/cards/virtual/${providerCode}/${providerCardId}/freeze`
103
+ return await this.connection.get<model.CardResponseV2>(
104
+ `v2/${this.folder}/virtual/${providerCode}/${providerCardId}/freeze`
132
105
  )
133
- return result
134
106
  }
107
+ //Possibly should be moved to its own class
135
108
  async getCardTypesV2(providerCode: model.ProviderCode): Promise<model.ErrorResponse | model.CardTypeResponseV2[]> {
136
109
  const response = await this.connection.get<{ list: model.CardTypeResponseV2[]; totalCount: number }>(
137
- `v2/cards/types/${providerCode}`
110
+ `v2/${this.folder}/types/${providerCode}`
138
111
  )
139
- return this.extractResponse(response)
112
+ return this.extractResponse<model.CardTypeResponseV2>(response)
140
113
  }
114
+ //Possibly should be moved to its own class
141
115
  async getCardTypes(providerCode: model.ProviderCode) {
142
- const result = await this.connection.get<model.CardTypeResponse>(`cards/types/${providerCode}`)
143
- return result
116
+ return await this.connection.get<model.CardTypeResponse>(`${this.folder}/types/${providerCode}`)
144
117
  }
145
118
 
146
119
  async searchCardsV2(
@@ -148,11 +121,11 @@ export class Cards extends List<
148
121
  parameters?: Record<string, any>
149
122
  ): Promise<model.ErrorResponse | model.CardResponseV2[]> {
150
123
  const response = await this.connection.post<{ list: model.CardResponseV2[]; totalCount: number }>(
151
- `v2/cards/searches`,
124
+ `v2/${this.folder}/searches`,
152
125
  searchRequest,
153
126
  parameters
154
127
  )
155
- return this.extractResponse(response)
128
+ return this.extractResponse<model.CardResponseV2>(response)
156
129
  }
157
130
  async searchCardsV2Paginated(
158
131
  request: model.CardSearchRequest,
@@ -166,7 +139,7 @@ export class Cards extends List<
166
139
  previous,
167
140
  (page, size, sort, request) =>
168
141
  this.connection.post<{ list: model.CardResponseV2[]; totalCount: number } | model.CardResponseV2[]>(
169
- `v2/cards/searches`,
142
+ `v2/${this.folder}/searches`,
170
143
  request,
171
144
  {
172
145
  page: page,
@@ -181,6 +154,7 @@ export class Cards extends List<
181
154
  sort
182
155
  )
183
156
  }
157
+ // "Deprecated". This was added to the Accounts class so it can be removed from this when switched over wherever it's used
184
158
  async getFundingAccounts(
185
159
  searchRequest: model.FundingAccountSearchRequest
186
160
  ): Promise<model.ErrorResponse | model.AccountResponse[]> {
@@ -188,8 +162,9 @@ export class Cards extends List<
188
162
  "funding-accounts/searches",
189
163
  searchRequest
190
164
  )
191
- return this.extractResponse(response)
165
+ return this.extractResponse<model.AccountResponse>(response)
192
166
  }
167
+ // "Deprecated". This was added to the Accounts class so it can be removed from this when switched over wherever it's used
193
168
  async getAllFundingAccounts(
194
169
  providerCode: model.ProviderCode,
195
170
  size = 500,
@@ -199,39 +174,39 @@ export class Cards extends List<
199
174
  `funding-accounts`,
200
175
  { provider: providerCode, size: size, sort: sort }
201
176
  )
202
- return this.extractResponse(response)
177
+ return this.extractResponse<model.AccountResponse>(response)
203
178
  }
179
+ //Possibly should be moved to its own class
204
180
  async getCardBookingInfo(providerCardId: string, providerCode: model.ProviderCode) {
205
- const result = await this.connection
206
- .get<model.BookingInfoResponse>(`booking-info/cards/${providerCode}/${providerCardId}
181
+ return await this.connection.get<model.BookingInfoResponse>(`booking-info/cards/${providerCode}/${providerCardId}
207
182
  `)
208
- return result
209
183
  }
184
+ //Possibly should be moved to its own class
210
185
  async editCardBookingInfo(providerCardId: string, providerCode: model.ProviderCode, request: Record<string, any>) {
211
- const result = await this.connection.put<model.BookingInfoResponse>(
186
+ return await this.connection.put<model.BookingInfoResponse>(
212
187
  `booking-info/cards/${providerCode}/${providerCardId}`,
213
188
  request
214
189
  )
215
- return result
216
190
  }
217
191
  async getCardStatements(
218
192
  providerCardId: string,
219
193
  providerCode: model.ProviderCode
220
194
  ): Promise<model.ErrorResponse | model.CardStatement[]> {
221
195
  const response = await this.connection.get<{ list: model.CardStatement[]; totalCount: number }>(
222
- `cards/virtual/${providerCode}/${providerCardId}/statements`
196
+ `${this.folder}/virtual/${providerCode}/${providerCardId}/statements`
223
197
  )
224
- return this.extractResponse(response)
198
+ return this.extractResponse<model.CardStatement>(response)
225
199
  }
226
200
  async getCardTransactions(
227
201
  providerCardId: string,
228
202
  providerCode: model.ProviderCode
229
203
  ): Promise<model.ErrorResponse | model.CardTransaction[]> {
230
204
  const response = await this.connection.get<{ list: model.CardTransaction[]; totalCount: number }>(
231
- `cards/virtual/${providerCode}/${providerCardId}/transactions`
205
+ `${this.folder}/virtual/${providerCode}/${providerCardId}/transactions`
232
206
  )
233
- return this.extractResponse(response)
207
+ return this.extractResponse<model.CardTransaction>(response)
234
208
  }
209
+ //Possibly should be moved to its own class
235
210
  async searchTransaction(accountId: number): Promise<model.ErrorResponse | model.CardTransaction[]> {
236
211
  const response = await this.connection.post<{ list: model.CardTransaction[]; totalCount: number }>(
237
212
  `transactions/searches`,
@@ -239,25 +214,24 @@ export class Cards extends List<
239
214
  accountId: accountId,
240
215
  }
241
216
  )
242
- return this.extractResponse(response)
217
+ return this.extractResponse<model.CardTransaction>(response)
243
218
  }
244
219
  async editSchedule(providerCardId: string, providerCode: model.ProviderCode, request: model.ScheduleEntry[]) {
245
- const result = await this.connection.put<model.CardResponseV2>(
246
- `v2/cards/virtual/${providerCode}/${providerCardId}/schedule`,
220
+ return await this.connection.put<model.CardResponseV2>(
221
+ `v2/${this.folder}/virtual/${providerCode}/${providerCardId}/schedule`,
247
222
  {
248
223
  schedule: request,
249
224
  }
250
225
  )
251
- return result
252
226
  }
253
227
  async amendExistingCardV2(providerCardId: string, providerCode: model.ProviderCode, request: model.AmendCardRequest) {
254
- const result = await this.connection.put<model.CardResponseV2>(
255
- `v2/cards/virtual/${providerCode}/${providerCardId}/amend`,
228
+ return await this.connection.put<model.CardResponseV2>(
229
+ `v2/${this.folder}/virtual/${providerCode}/${providerCardId}/amend`,
256
230
  request
257
231
  )
258
- return result
259
232
  }
233
+ //Possibly should be moved to its own class
260
234
  async getDisplayableCardTypesForProvider(provider: model.ProviderCode = "modulr") {
261
- return await this.connection.get<Record<string, string>>(`v2/cards/types/displayable/${provider}`)
235
+ return await this.connection.get<Record<string, string>>(`v2/${this.folder}/types/displayable/${provider}`)
262
236
  }
263
237
  }
@@ -1,29 +1,29 @@
1
1
  import * as model from "../../model"
2
2
  import { CategoryResponse } from "../../model/CategoryResponse"
3
3
  import { Connection } from "../Connection"
4
- export class Categories {
4
+ import { List } from "../List"
5
+ export class Categories extends List<model.CategoryResponse> {
5
6
  protected folder = "category"
6
- constructor(private readonly connection: Connection) {}
7
+ private constructor(connection: Connection) {
8
+ super(connection)
9
+ }
7
10
  static create(connection: Connection) {
8
11
  return new Categories(connection)
9
12
  }
10
13
  async getAllCategories() {
11
- const result = await this.connection.get<{ list: CategoryResponse[]; totalCount: number }>(`category`, {
14
+ const result = await this.connection.get<{ list: CategoryResponse[]; totalCount: number }>(this.folder, {
12
15
  size: 100,
13
16
  sort: "name",
14
17
  })
15
- if (!model.ErrorResponse.is(result) && "list" in result)
16
- return result.list
17
- else
18
- return result
18
+ return this.extractResponse(result)
19
19
  }
20
20
  async editCategoryLimits(
21
21
  category: string,
22
22
  request: model.UpdateCategoryRequest
23
23
  ): Promise<model.CategoryResponse | model.ErrorResponse> {
24
- return await this.connection.put<model.CategoryResponse>(`category/${category}`, request)
24
+ return await this.connection.put<model.CategoryResponse>(`${this.folder}/${category}`, request)
25
25
  }
26
26
  async getCategory(category: string): Promise<model.CategoryResponse | model.ErrorResponse> {
27
- return await this.connection.get<model.CategoryResponse>(`category/${category}`)
27
+ return await this.connection.get<model.CategoryResponse>(`${this.folder}/${category}`)
28
28
  }
29
29
  }
@@ -9,24 +9,20 @@ export class Configuration {
9
9
  return new Configuration(connection)
10
10
  }
11
11
  async getAvailableCurrency(providerCode: ProviderCode = "modulr"): Promise<Currency[] | model.ErrorResponse> {
12
- const result = await this.connection.get<Currency[]>(`config/currencies`, { provider: providerCode })
13
- return result
12
+ return await this.connection.get<Currency[]>(`${this.folder}/currencies`, { provider: providerCode })
14
13
  }
15
14
  async updateOrganisationConfig(
16
15
  request: model.OrganisationConfig
17
16
  ): Promise<model.OrganisationConfig | model.ErrorResponse> {
18
- const result = await this.connection.post<model.OrganisationConfig>(`config/organisation`, request)
19
- return result
17
+ return await this.connection.post<model.OrganisationConfig>(`${this.folder}/organisation`, request)
20
18
  }
21
19
  async getOrganisationConfig(): Promise<model.OrganisationConfig | model.ErrorResponse> {
22
- const result = await this.connection.get<model.OrganisationConfig>(`config/organisation`)
23
- return result
20
+ return await this.connection.get<model.OrganisationConfig>(`${this.folder}/organisation`)
24
21
  }
25
22
  async getUserConfig(): Promise<model.UserConfig | model.ErrorResponse> {
26
- const result = await this.connection.get<model.UserConfig>(`config/user`)
27
- return result
23
+ return await this.connection.get<model.UserConfig>(`${this.folder}/user`)
28
24
  }
29
25
  async getPortalFeatures(): Promise<model.PaxpayFeature[] | model.ErrorResponse> {
30
- return await this.connection.get<model.PaxpayFeature[]>(`config/portal`)
26
+ return await this.connection.get<model.PaxpayFeature[]>(`${this.folder}/portal`)
31
27
  }
32
28
  }
@@ -52,6 +52,7 @@ export class Connection {
52
52
  requestHeaders["x-assume"] = this.assumedOrg
53
53
  if (cookie)
54
54
  requestHeaders["x-otp-cookie"] = cookie
55
+ let caughtErrorResponse
55
56
  const response = await fetch(
56
57
  this.url +
57
58
  "/" +
@@ -72,7 +73,14 @@ export class Connection {
72
73
  headers: requestHeaders,
73
74
  body: !isMultipart ? request && JSON.stringify(request) : request,
74
75
  }
75
- ).catch(_ => undefined)
76
+ ).catch((error: Error) => {
77
+ caughtErrorResponse = { code: 500, errors: [{ message: error.message }] }
78
+ console.error(error)
79
+ })
80
+
81
+ if (caughtErrorResponse)
82
+ return caughtErrorResponse
83
+
76
84
  if (response && response.headers.has("x-otp-cookie"))
77
85
  window.sessionStorage.setItem("cookie", response.headers.get("x-otp-cookie") ?? "")
78
86
 
@@ -8,7 +8,6 @@ export class Email {
8
8
  return new Email(connection)
9
9
  }
10
10
  async validateEmail(email: string) {
11
- const result = await this.connection.get<model.EmailValidationResponse>(`email/validate/${email}`)
12
- return result
11
+ return await this.connection.get<model.EmailValidationResponse>(`${this.folder}/validate/${email}`)
13
12
  }
14
13
  }
package/Client/List.ts CHANGED
@@ -1,15 +1,8 @@
1
1
  import * as model from "../model"
2
2
  import { Connection } from "./Connection"
3
- import { generatePagination } from "./generatePagination"
4
3
  import { Paginated } from "./Paginated"
5
- import { Resource } from "./Resource"
6
4
 
7
- export abstract class List<
8
- Response extends { [key: string]: any },
9
- Search extends { [key: string]: any },
10
- Request extends { [key: string]: any } = { [key: string]: any },
11
- T extends Resource<Response, Request> = Resource<Response, Request>
12
- > {
5
+ export abstract class List<Response extends { [key: string]: any }> {
13
6
  private DEFAULT_PAGE_SIZE = 20
14
7
  #connection: Connection
15
8
  protected get connection() {
@@ -19,28 +12,7 @@ export abstract class List<
19
12
  constructor(connection: Connection) {
20
13
  this.#connection = connection
21
14
  }
22
- protected abstract createResource(response: Response): T
23
- protected map(response: Response): T & Response {
24
- return Object.assign(this.createResource(response), response)
25
- }
26
- protected convert<S extends model.ErrorResponse & { status: number }>(result: Response | S): (T & Response) | S
27
- protected convert<S extends model.ErrorResponse & { status: number }>(result: Response[] | S): (T & Response)[] | S
28
- protected convert<S extends model.ErrorResponse & { status: number }>(
29
- result: Response[] | Response | S
30
- ): (T & Response)[] | (T & Response) | S {
31
- return Array.isArray(result) ? result.map(r => this.map(r)) : Connection.isError(result) ? result : this.map(result)
32
- }
33
- async list(page = 0, size = 20, sort: model.Sorting<Response>[] = []) {
34
- return this.convert(await this.connection.get<Response[]>(`${this.folder}${generatePagination(page, size, sort)}`))
35
- }
36
- async search(pattern: Search | string, page = 0, size = 20, sort: model.Sorting<Response>[] = []) {
37
- return this.convert(
38
- await (typeof pattern == "string"
39
- ? this.connection.get<Response[]>(`${this.folder}/searches/${pattern}${generatePagination(page, size, sort)}`)
40
- : this.connection.post<Response[]>(`${this.folder}/searches${generatePagination(page, size, sort)}`, pattern))
41
- )
42
- }
43
- async getNextPaginated<R>(
15
+ async getNextPaginated<R = Response>(
44
16
  previous: Paginated<R> | undefined,
45
17
  callback: (
46
18
  page: number,
@@ -66,7 +38,7 @@ export abstract class List<
66
38
  size = previous.size
67
39
  } else {
68
40
  page = page ?? 0
69
- size = size ?? 20
41
+ size = size ?? this.DEFAULT_PAGE_SIZE
70
42
  }
71
43
 
72
44
  const response = await callback(page, size, sort, request)
@@ -87,7 +59,7 @@ export abstract class List<
87
59
  return result
88
60
  }
89
61
 
90
- extractResponse<R>(value: R[] | { list: R[]; totalCount: number } | model.ErrorResponse) {
62
+ extractResponse<R = Response>(value: R[] | { list: R[]; totalCount: number } | model.ErrorResponse) {
91
63
  if (!model.ErrorResponse.is(value) && "list" in value)
92
64
  return value.list
93
65
  else
@@ -19,6 +19,8 @@ export class Omnisetup {
19
19
  omnisetupRequest: OmnisetupRequest,
20
20
  commit = true
21
21
  ): Promise<OmnisetupResponse | ErrorResponse> {
22
- return this.connection.post<OmnisetupResponse | ErrorResponse>(`${this.folder}?commit=${commit}`, omnisetupRequest)
22
+ return this.connection.post<OmnisetupResponse | ErrorResponse>(`${this.folder}`, omnisetupRequest, {
23
+ commit: commit,
24
+ })
23
25
  }
24
26
  }