@ikas/api-client 0.0.1-canary.3

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 (92) hide show
  1. package/Jenkinsfile +92 -0
  2. package/README.md +2 -0
  3. package/codegen/admin.yml +9 -0
  4. package/dist/api/admin/admin-client.d.ts +8 -0
  5. package/dist/api/admin/admin-client.js +33 -0
  6. package/dist/api/admin/admin-client.js.map +1 -0
  7. package/dist/api/admin/common-gql.d.ts +4 -0
  8. package/dist/api/admin/common-gql.js +14 -0
  9. package/dist/api/admin/common-gql.js.map +1 -0
  10. package/dist/api/admin/generated/index.d.ts +2105 -0
  11. package/dist/api/admin/generated/index.js +340 -0
  12. package/dist/api/admin/generated/index.js.map +1 -0
  13. package/dist/api/admin/index.d.ts +4 -0
  14. package/dist/api/admin/index.js +17 -0
  15. package/dist/api/admin/index.js.map +1 -0
  16. package/dist/api/admin/mutation-gql.d.ts +6 -0
  17. package/dist/api/admin/mutation-gql.js +40 -0
  18. package/dist/api/admin/mutation-gql.js.map +1 -0
  19. package/dist/api/admin/mutation.d.ts +41 -0
  20. package/dist/api/admin/mutation.js +268 -0
  21. package/dist/api/admin/mutation.js.map +1 -0
  22. package/dist/api/admin/query-gql.d.ts +6 -0
  23. package/dist/api/admin/query-gql.js +34 -0
  24. package/dist/api/admin/query-gql.js.map +1 -0
  25. package/dist/api/admin/query.d.ts +33 -0
  26. package/dist/api/admin/query.js +205 -0
  27. package/dist/api/admin/query.js.map +1 -0
  28. package/dist/api/base.d.ts +44 -0
  29. package/dist/api/base.js +181 -0
  30. package/dist/api/base.js.map +1 -0
  31. package/dist/api/index.d.ts +2 -0
  32. package/dist/api/index.js +15 -0
  33. package/dist/api/index.js.map +1 -0
  34. package/dist/api/oauth/index.d.ts +11 -0
  35. package/dist/api/oauth/index.js +100 -0
  36. package/dist/api/oauth/index.js.map +1 -0
  37. package/dist/api/oauth/models.d.ts +35 -0
  38. package/dist/api/oauth/models.js +23 -0
  39. package/dist/api/oauth/models.js.map +1 -0
  40. package/dist/globals/constants.d.ts +13 -0
  41. package/dist/globals/constants.js +15 -0
  42. package/dist/globals/constants.js.map +1 -0
  43. package/dist/globals/index.d.ts +1 -0
  44. package/dist/globals/index.js +14 -0
  45. package/dist/globals/index.js.map +1 -0
  46. package/dist/helpers/index.d.ts +1 -0
  47. package/dist/helpers/index.js +14 -0
  48. package/dist/helpers/index.js.map +1 -0
  49. package/dist/helpers/webhook-validate.d.ts +1 -0
  50. package/dist/helpers/webhook-validate.js +67 -0
  51. package/dist/helpers/webhook-validate.js.map +1 -0
  52. package/dist/index.d.ts +21 -0
  53. package/dist/index.js +33 -0
  54. package/dist/index.js.map +1 -0
  55. package/dist/models/base.d.ts +7 -0
  56. package/dist/models/base.js +3 -0
  57. package/dist/models/base.js.map +1 -0
  58. package/dist/models/index.d.ts +1 -0
  59. package/dist/models/index.js +14 -0
  60. package/dist/models/index.js.map +1 -0
  61. package/dist/models/webhook/index.d.ts +1 -0
  62. package/dist/models/webhook/index.js +14 -0
  63. package/dist/models/webhook/index.js.map +1 -0
  64. package/dist/models/webhook/models.d.ts +68 -0
  65. package/dist/models/webhook/models.js +19 -0
  66. package/dist/models/webhook/models.js.map +1 -0
  67. package/dist/models/webhook/product.d.ts +19 -0
  68. package/dist/models/webhook/product.js +3 -0
  69. package/dist/models/webhook/product.js.map +1 -0
  70. package/package.json +51 -0
  71. package/src/api/admin/admin-client.ts +15 -0
  72. package/src/api/admin/common-gql.ts +425 -0
  73. package/src/api/admin/generated/index.ts +2373 -0
  74. package/src/api/admin/index.ts +4 -0
  75. package/src/api/admin/mutation-gql.ts +255 -0
  76. package/src/api/admin/mutation.ts +195 -0
  77. package/src/api/admin/query-gql.ts +434 -0
  78. package/src/api/admin/query.ts +119 -0
  79. package/src/api/base.ts +133 -0
  80. package/src/api/index.ts +2 -0
  81. package/src/api/oauth/index.ts +47 -0
  82. package/src/api/oauth/models.ts +37 -0
  83. package/src/globals/constants.ts +19 -0
  84. package/src/globals/index.ts +1 -0
  85. package/src/helpers/index.ts +1 -0
  86. package/src/helpers/webhook-validate.ts +17 -0
  87. package/src/index.ts +34 -0
  88. package/src/models/base.ts +7 -0
  89. package/src/models/index.ts +1 -0
  90. package/src/models/webhook/index.ts +1 -0
  91. package/src/models/webhook/models.ts +90 -0
  92. package/tsconfig.json +25 -0
@@ -0,0 +1,434 @@
1
+ import { Query } from './generated';
2
+ import { gql } from 'graphql-request';
3
+ import { CATEGORY_GQL, CUSTOMER_GQL, ORDER_GQL, PRODUCT_GQL } from './common-gql';
4
+
5
+ type Queries = {
6
+ [p in keyof Omit<Query, '__typename' | 'getImageUploadUrl'>]: string;
7
+ };
8
+
9
+ export const DefaultQueries: Queries = {
10
+ getAuthorizedApp: gql`
11
+ query GetAuthorizedApp {
12
+ getAuthorizedApp {
13
+ id
14
+ storeAppId
15
+ scope
16
+ addedDate
17
+ partnerId
18
+ salesChannelId
19
+ }
20
+ }
21
+ `,
22
+ getMerchantLicence: gql`
23
+ query GetMerchantLicence {
24
+ getMerchantLicence {
25
+ activeSubscriptionCode
26
+ activeSubscriptionId
27
+ appSubscriptions {
28
+ addedDate
29
+ appPaymentKey
30
+ authorizedAppId
31
+ createdAt
32
+ currency
33
+ deleted
34
+ id
35
+ lastPaymentDate
36
+ lastPaymentPeriod
37
+ lastPaymentPrice
38
+ lastPaymentPriceWithTax
39
+ merchantAppPaymentId
40
+ name
41
+ status
42
+ storeAppId
43
+ updatedAt
44
+ }
45
+ createdAt
46
+ deleted
47
+ fromDate
48
+ id
49
+ licenceActivationDate
50
+ limits {
51
+ code
52
+ value
53
+ }
54
+ period
55
+ region
56
+ status
57
+ statusUpdatedAt
58
+ subscriptions {
59
+ code
60
+ createdAt
61
+ currency
62
+ deleted
63
+ id
64
+ lastPaymentDate
65
+ lastPaymentPeriod
66
+ lastPaymentPrice
67
+ lastPaymentPriceWithTax
68
+ status
69
+ subscriptionId
70
+ updatedAt
71
+ }
72
+ toDate
73
+ updatedAt
74
+ }
75
+ }
76
+ `,
77
+ getMerchant: gql`
78
+ query GetMerchant {
79
+ getMerchant {
80
+ id
81
+ storeName
82
+ merchantSequence
83
+ merchantName
84
+ firstName
85
+ lastName
86
+ email
87
+ phoneNumber
88
+ address {
89
+ addressLine1
90
+ addressLine2
91
+ country {
92
+ id
93
+ name
94
+ code
95
+ }
96
+ state {
97
+ id
98
+ name
99
+ code
100
+ }
101
+ city {
102
+ id
103
+ name
104
+ code
105
+ }
106
+ district {
107
+ id
108
+ name
109
+ code
110
+ }
111
+ postalCode
112
+ }
113
+ }
114
+ }
115
+ `,
116
+ getSalesChannel: gql`
117
+ query GetSalesChannel {
118
+ getSalesChannel {
119
+ id
120
+ createdAt
121
+ updatedAt
122
+ deleted
123
+ name
124
+ paymentGateways {
125
+ id
126
+ order
127
+ }
128
+ priceListId
129
+ stockLocations {
130
+ id
131
+ order
132
+ }
133
+ type
134
+ }
135
+ }
136
+ `,
137
+ listCategory: gql`
138
+ query ListCategories(
139
+ $categoryPath: CategoryPathFilterInput
140
+ $id: StringFilterInput
141
+ $includeDeleted: Boolean
142
+ $name: StringFilterInput
143
+ $search: String
144
+ $updatedAt: DateFilterInput
145
+ ) {
146
+ listCategory(categoryPath: $categoryPath, id: $id, includeDeleted: $includeDeleted, name: $name, search: $search, updatedAt: $updatedAt) ${CATEGORY_GQL}
147
+ }
148
+ `,
149
+ listCustomer: gql`
150
+ query ListCustomer($pagination: PaginationInput, $id: StringFilterInput, $sort: String) {
151
+ listCustomer(pagination: $pagination, id: $id, sort: $sort) {
152
+ data ${CUSTOMER_GQL}
153
+ count
154
+ hasNext
155
+ limit
156
+ page
157
+ }
158
+ }
159
+ `,
160
+ listMerchantAppPayment: gql`
161
+ query ListMerchantAppPayment($id: StringFilterInput, $pagination: PaginationInput) {
162
+ listMerchantAppPayment(id: $id, pagination: $pagination) {
163
+ count
164
+ data {
165
+ appPaymentKey
166
+ createdAt
167
+ deleted
168
+ id
169
+ merchantPaymentUrl
170
+ name
171
+ paymentDate
172
+ prices {
173
+ period
174
+ price
175
+ }
176
+ status
177
+ storeAppId
178
+ type
179
+ updatedAt
180
+ }
181
+ hasNext
182
+ limit
183
+ page
184
+ }
185
+ }
186
+ `,
187
+ listOrder: gql`
188
+ query ListOrder($pagination: PaginationInput, $id: StringFilterInput) {
189
+ listOrder(pagination: $pagination, id: $id) {
190
+ count
191
+ data ${ORDER_GQL}
192
+ hasNext
193
+ limit
194
+ page
195
+ }
196
+ }
197
+ `,
198
+ listPriceList: gql`
199
+ query ListPriceList($id: StringFilterInput) {
200
+ listPriceList(id: $id) {
201
+ id
202
+ createdAt
203
+ updatedAt
204
+ deleted
205
+ currency
206
+ name
207
+ }
208
+ }
209
+ `,
210
+ listProduct: gql`
211
+ query ListProduct($pagination: PaginationInput, $id: StringFilterInput, $sku: StringFilterInput, $barcodeList: StringFilterInput) {
212
+ listProduct(pagination: $pagination, id: $id, sku: $sku, barcodeList: $barcodeList) {
213
+ count
214
+ hasNext
215
+ limit
216
+ page
217
+ data ${PRODUCT_GQL}
218
+ }
219
+ }
220
+ `,
221
+ listProductAttribute: gql`
222
+ query ListProductAttributes($id: StringFilterInput, $includeDeleted: Boolean, $name: StringFilterInput, $updatedAt: DateFilterInput) {
223
+ listProductAttribute(updatedAt: $updatedAt, includeDeleted: $includeDeleted, id: $id, name: $name) {
224
+ id
225
+ createdAt
226
+ updatedAt
227
+ name
228
+ deleted
229
+ type
230
+ description
231
+ tableTemplate {
232
+ rows {
233
+ id
234
+ name
235
+ }
236
+ columns {
237
+ id
238
+ name
239
+ }
240
+ }
241
+ options {
242
+ createdAt
243
+ id
244
+ name
245
+ updatedAt
246
+ }
247
+ }
248
+ }
249
+ `,
250
+ listProductBrand: gql`
251
+ query ListProductBrand($id: StringFilterInput, $includeDeleted: Boolean, $name: StringFilterInput, $search: String, $updatedAt: DateFilterInput) {
252
+ listProductBrand(updatedAt: $updatedAt, includeDeleted: $includeDeleted, id: $id, name: $name, search: $search) {
253
+ id
254
+ createdAt
255
+ updatedAt
256
+ name
257
+ imageId
258
+ salesChannelIds
259
+ orderType
260
+ deleted
261
+ metaData {
262
+ id
263
+ createdAt
264
+ updatedAt
265
+ slug
266
+ pageTitle
267
+ description
268
+ targetType
269
+ targetId
270
+ redirectTo
271
+ }
272
+ }
273
+ }
274
+ `,
275
+ listProductStockLocation: gql`
276
+ query ListProductStockLocation($variantId: StringFilterInput, $productId: StringFilterInput, $pagination: PaginationInput) {
277
+ listProductStockLocation(variantId: $variantId, productId: $productId, pagination: $pagination) {
278
+ count
279
+ data {
280
+ createdAt
281
+ deleted
282
+ id
283
+ productId
284
+ stockCount
285
+ stockLocationId
286
+ updatedAt
287
+ variantId
288
+ }
289
+ hasNext
290
+ limit
291
+ page
292
+ }
293
+ }
294
+ `,
295
+ listProductTag: gql`
296
+ query ListProductTag($id: StringFilterInput, $includeDeleted: Boolean, $name: StringFilterInput, $updatedAt: DateFilterInput) {
297
+ listProductTag(updatedAt: $updatedAt, includeDeleted: $includeDeleted, id: $id, name: $name) {
298
+ id
299
+ createdAt
300
+ updatedAt
301
+ name
302
+ deleted
303
+ }
304
+ }
305
+ `,
306
+ listSalesChannel: gql`
307
+ query ListSalesChannel($id: StringFilterInput) {
308
+ listSalesChannel(id: $id) {
309
+ id
310
+ createdAt
311
+ updatedAt
312
+ deleted
313
+ name
314
+ paymentGateways {
315
+ id
316
+ order
317
+ }
318
+ priceListId
319
+ stockLocations {
320
+ id
321
+ order
322
+ }
323
+ type
324
+ }
325
+ }
326
+ `,
327
+ listStockLocation: gql`
328
+ query ListStockLocation($id: StringFilterInput) {
329
+ listStockLocation(id: $id) {
330
+ id
331
+ createdAt
332
+ updatedAt
333
+ deleted
334
+ name
335
+ type
336
+ address {
337
+ address
338
+ country {
339
+ id
340
+ name
341
+ code
342
+ }
343
+ state {
344
+ id
345
+ name
346
+ code
347
+ }
348
+ city {
349
+ id
350
+ name
351
+ code
352
+ }
353
+ district {
354
+ id
355
+ name
356
+ code
357
+ }
358
+ postalCode
359
+ phone
360
+ }
361
+ }
362
+ }
363
+ `,
364
+ listStorefront: gql`
365
+ query ListStorefront($id: StringFilterInput) {
366
+ listStorefront(id: $id) {
367
+ id
368
+ name
369
+ createdAt
370
+ updatedAt
371
+ deleted
372
+ }
373
+ }
374
+ `,
375
+ listStorefrontJSScript: gql`
376
+ query ListStorefrontJSScript($id: StringFilterInput) {
377
+ listStorefrontJSScript(id: $id) {
378
+ authorizedAppId
379
+ createdAt
380
+ deleted
381
+ id
382
+ isActive
383
+ name
384
+ scriptContent
385
+ storeAppId
386
+ storefrontId
387
+ updatedAt
388
+ }
389
+ }
390
+ `,
391
+ listVariantType: gql`
392
+ query ListVariantTypes($id: StringFilterInput, $includeDeleted: Boolean, $name: StringFilterInput, $updatedAt: DateFilterInput) {
393
+ listVariantType(updatedAt: $updatedAt, includeDeleted: $includeDeleted, id: $id, name: $name) {
394
+ id
395
+ deleted
396
+ createdAt
397
+ updatedAt
398
+ name
399
+ selectionType
400
+ values {
401
+ colorCode
402
+ createdAt
403
+ id
404
+ name
405
+ thumbnailImageId
406
+ updatedAt
407
+ }
408
+ }
409
+ }
410
+ `,
411
+ listWebhook: gql`
412
+ query ListWebhook {
413
+ listWebhook {
414
+ id
415
+ createdAt
416
+ updatedAt
417
+ deleted
418
+ scope
419
+ endpoint
420
+ }
421
+ }
422
+ `,
423
+ searchProducts: gql`
424
+ query SearchProducts($input: SearchInput!) {
425
+ searchProducts(input: $input) {
426
+ data
427
+ count
428
+ totalCount
429
+ page
430
+ limit
431
+ }
432
+ }
433
+ `,
434
+ };
@@ -0,0 +1,119 @@
1
+ import { ikasAdminGraphQLAPIClient } from './admin-client';
2
+ import {
3
+ Query,
4
+ QuerylistCategoryArgs,
5
+ QuerylistCustomerArgs,
6
+ QuerylistMerchantAppPaymentArgs,
7
+ QuerylistOrderArgs,
8
+ QuerylistPriceListArgs,
9
+ QuerylistProductArgs,
10
+ QuerylistProductAttributeArgs,
11
+ QuerylistProductBrandArgs,
12
+ QuerylistProductStockLocationArgs,
13
+ QuerylistProductTagArgs,
14
+ QuerylistSalesChannelArgs,
15
+ QuerylistStockLocationArgs,
16
+ QuerylistStorefrontArgs,
17
+ QuerylistStorefrontJSScriptArgs,
18
+ QuerylistVariantTypeArgs,
19
+ QuerysearchProductsArgs,
20
+ } from './generated';
21
+ import { APIResult, QueryOptions } from '../base';
22
+
23
+ type Result<T> = APIResult<Partial<T>>;
24
+
25
+ type Queries = {
26
+ [p in keyof Omit<Query, '__typename' | 'getImageUploadUrl'>]: (options: QueryOptions<any>) => Promise<Result<Query[p]>>;
27
+ };
28
+
29
+ export class AdminQuery implements Queries {
30
+ client: ikasAdminGraphQLAPIClient<any>;
31
+
32
+ constructor(client: ikasAdminGraphQLAPIClient<any>) {
33
+ this.client = client;
34
+ }
35
+
36
+ async getAuthorizedApp(options: QueryOptions<undefined>): Promise<Result<Query['getAuthorizedApp']>> {
37
+ return this.client.query<Partial<Query['getAuthorizedApp']>>({ ...options, operationName: 'getAuthorizedApp' });
38
+ }
39
+
40
+ async getMerchant(options: QueryOptions<undefined>): Promise<Result<Query['getMerchant']>> {
41
+ return this.client.query<Partial<Query['getMerchant']>>({ ...options, operationName: 'getMerchant' });
42
+ }
43
+
44
+ async getMerchantLicence(options: QueryOptions<undefined>): Promise<Result<Query['getMerchantLicence']>> {
45
+ return this.client.query<Partial<Query['getMerchantLicence']>>({ ...options, operationName: 'getMerchantLicence' });
46
+ }
47
+
48
+ async getSalesChannel(options: QueryOptions<undefined>): Promise<Result<Query['getSalesChannel']>> {
49
+ return this.client.query<Partial<Query['getSalesChannel']>>({ ...options, operationName: 'getSalesChannel' });
50
+ }
51
+
52
+ async listCategory(options: QueryOptions<QuerylistCategoryArgs>): Promise<Result<Query['listCategory']>> {
53
+ return this.client.query<Partial<Query['listCategory']>>({ ...options, operationName: 'listCategory' });
54
+ }
55
+
56
+ async listCustomer(options: QueryOptions<QuerylistCustomerArgs>): Promise<Result<Query['listCustomer']>> {
57
+ return this.client.query<Partial<Query['listCustomer']>>({ ...options, operationName: 'listCustomer' });
58
+ }
59
+
60
+ async listMerchantAppPayment(options: QueryOptions<QuerylistMerchantAppPaymentArgs>): Promise<Result<Query['listMerchantAppPayment']>> {
61
+ return this.client.query<Partial<Query['listMerchantAppPayment']>>({ ...options, operationName: 'listMerchantAppPayment' });
62
+ }
63
+
64
+ async listOrder(options: QueryOptions<QuerylistOrderArgs>): Promise<Result<Query['listOrder']>> {
65
+ return this.client.query<Partial<Query['listOrder']>>({ ...options, operationName: 'listOrder' });
66
+ }
67
+
68
+ async listPriceList(options: QueryOptions<QuerylistPriceListArgs>): Promise<Result<Query['listPriceList']>> {
69
+ return this.client.query<Partial<Query['listPriceList']>>({ ...options, operationName: 'listPriceList' });
70
+ }
71
+
72
+ async listProduct(options: QueryOptions<QuerylistProductArgs>): Promise<Result<Query['listProduct']>> {
73
+ return this.client.query<Partial<Query['listProduct']>>({ ...options, operationName: 'listProduct' });
74
+ }
75
+
76
+ async listProductAttribute(options: QueryOptions<QuerylistProductAttributeArgs>): Promise<Result<Query['listProductAttribute']>> {
77
+ return this.client.query<Partial<Query['listProductAttribute']>>({ ...options, operationName: 'listProductAttribute' });
78
+ }
79
+
80
+ async listProductBrand(options: QueryOptions<QuerylistProductBrandArgs>): Promise<Result<Query['listProductBrand']>> {
81
+ return this.client.query<Partial<Query['listProductBrand']>>({ ...options, operationName: 'listProductBrand' });
82
+ }
83
+
84
+ async listProductStockLocation(options: QueryOptions<QuerylistProductStockLocationArgs>): Promise<Result<Query['listProductStockLocation']>> {
85
+ return this.client.query<Partial<Query['listProductStockLocation']>>({ ...options, operationName: 'listProductStockLocation' });
86
+ }
87
+
88
+ async listProductTag(options: QueryOptions<QuerylistProductTagArgs>): Promise<Result<Query['listProductTag']>> {
89
+ return this.client.query<Partial<Query['listProductTag']>>({ ...options, operationName: 'listProductTag' });
90
+ }
91
+
92
+ async listSalesChannel(options: QueryOptions<QuerylistSalesChannelArgs>): Promise<Result<Query['listSalesChannel']>> {
93
+ return this.client.query<Partial<Query['listSalesChannel']>>({ ...options, operationName: 'listSalesChannel' });
94
+ }
95
+
96
+ async listStockLocation(options: QueryOptions<QuerylistStockLocationArgs>): Promise<Result<Query['listStockLocation']>> {
97
+ return this.client.query<Partial<Query['listStockLocation']>>({ ...options, operationName: 'listStockLocation' });
98
+ }
99
+
100
+ async listStorefront(options: QueryOptions<QuerylistStorefrontArgs>): Promise<Result<Query['listStorefront']>> {
101
+ return this.client.query<Partial<Query['listStorefront']>>({ ...options, operationName: 'listStorefront' });
102
+ }
103
+
104
+ async listStorefrontJSScript(options: QueryOptions<QuerylistStorefrontJSScriptArgs>): Promise<Result<Query['listStorefrontJSScript']>> {
105
+ return this.client.query<Partial<Query['listStorefrontJSScript']>>({ ...options, operationName: 'listStorefrontJSScript' });
106
+ }
107
+
108
+ async listVariantType(options: QueryOptions<QuerylistVariantTypeArgs>): Promise<Result<Query['listVariantType']>> {
109
+ return this.client.query<Partial<Query['listVariantType']>>({ ...options, operationName: 'listVariantType' });
110
+ }
111
+
112
+ async listWebhook(options: QueryOptions<undefined>): Promise<Result<Query['listWebhook']>> {
113
+ return this.client.query<Partial<Query['listWebhook']>>({ ...options, operationName: 'listWebhook' });
114
+ }
115
+
116
+ async searchProducts(options: QueryOptions<QuerysearchProductsArgs>): Promise<Result<Query['searchProducts']>> {
117
+ return this.client.query<Partial<Query['searchProducts']>>({ ...options, operationName: 'searchProducts' });
118
+ }
119
+ }
@@ -0,0 +1,133 @@
1
+ import { ClientError, GraphQLClient } from 'graphql-request';
2
+ import { GraphQLError } from 'graphql-request/dist/types';
3
+
4
+ export type QueryOptions<T> = {
5
+ query: string;
6
+ variables?: T;
7
+ operationName?: string;
8
+ };
9
+
10
+ export type MutationOptions<T> = {
11
+ mutation: string;
12
+ variables?: T;
13
+ operationName?: string;
14
+ };
15
+
16
+ export type OnCheckTokenCallback<TokenData> = (tokenData?: TokenData) => Promise<string | undefined>;
17
+
18
+ export type BaseGraphQLAPIClientOptions<TokenData> = {
19
+ accessToken: string;
20
+ graphApiUrl: string;
21
+ tokenData?: TokenData;
22
+ onCheckToken?: OnCheckTokenCallback<TokenData>;
23
+ };
24
+
25
+ export class BaseGraphQLAPIClient<TokenData> {
26
+ _client: GraphQLClient;
27
+ accessToken: string;
28
+ graphApiUrl: string;
29
+ tokenData?: TokenData;
30
+ onCheckToken?: OnCheckTokenCallback<TokenData>;
31
+
32
+ constructor({ accessToken, graphApiUrl, onCheckToken, tokenData }: BaseGraphQLAPIClientOptions<TokenData>) {
33
+ this.accessToken = accessToken;
34
+ this.graphApiUrl = graphApiUrl;
35
+ this._client = this.createGraphQLClient();
36
+ this.tokenData = tokenData;
37
+ this.onCheckToken = onCheckToken;
38
+ }
39
+
40
+ createGraphQLClient() {
41
+ const token = this.accessToken;
42
+
43
+ // Run GraphQL queries/mutations using a static function
44
+ // ... or create a GraphQL client instance to send requests
45
+ return new GraphQLClient(this.graphApiUrl, {
46
+ headers: {
47
+ 'User-Agent': 'ikas-app-client',
48
+ ...(token ? { authorization: token ? `Bearer ${token}` : '' } : {}),
49
+ },
50
+ credentials: 'include',
51
+ });
52
+
53
+ // const authLink = setContext((_request, { headers }) => {
54
+ // return {
55
+ // headers: {
56
+ // ...headers,
57
+ // 'User-Agent': 'ikas-app-client',
58
+ // ...(token ? { authorization: token ? `Bearer ${token}` : '' } : {}),
59
+ // },
60
+ // };
61
+ // });
62
+ //
63
+ // const httpLink = createHttpLink({
64
+ // credentials: 'include',
65
+ // uri: this.graphApiUrl,
66
+ // });
67
+ //
68
+ // return new ApolloClient({
69
+ // credentials: 'include',
70
+ // link: authLink.concat(httpLink),
71
+ // cache: new InMemoryCache(),
72
+ // defaultOptions: {
73
+ // watchQuery: {
74
+ // fetchPolicy: 'no-cache',
75
+ // errorPolicy: 'ignore',
76
+ // },
77
+ // query: {
78
+ // fetchPolicy: 'no-cache',
79
+ // errorPolicy: 'all',
80
+ // },
81
+ // },
82
+ // });
83
+ }
84
+
85
+ async query<TData = any, TVariables = any>(options: QueryOptions<TVariables>) {
86
+ return this._makeRequest<TData, TVariables>(options);
87
+ }
88
+
89
+ async mutate<TData = any, TVariables = any>(options: MutationOptions<TVariables>) {
90
+ return this._makeRequest<TData, TVariables>({
91
+ ...options,
92
+ query: options.mutation,
93
+ });
94
+ }
95
+
96
+ async _makeRequest<TData, TVariables>(options: QueryOptions<TVariables>) {
97
+ await this._checkToken();
98
+ try {
99
+ const data = await this._client.request<TData, TVariables>(options.query, options.variables);
100
+ return new APIResult<TData>({ data: options.operationName ? data[options.operationName] : data });
101
+ } catch (e) {
102
+ if (e instanceof ClientError) return new APIResult<TData>({ errors: e.response.errors });
103
+ else return new APIResult<TData>({ error: e.message });
104
+ }
105
+ }
106
+
107
+ async _checkToken() {
108
+ if (this.onCheckToken) {
109
+ const accessToken = await this.onCheckToken(this.tokenData);
110
+ if (accessToken) {
111
+ this.accessToken = accessToken;
112
+ this._client = this.createGraphQLClient();
113
+ }
114
+ }
115
+ }
116
+ }
117
+
118
+ export class APIResult<T> {
119
+ data?: T;
120
+ error?: string;
121
+ errors?: GraphQLError[];
122
+ partial?: boolean;
123
+
124
+ constructor(result: { data?: T; error?: string; errors?: GraphQLError[] }) {
125
+ this.data = result.data;
126
+ this.error = result.error;
127
+ this.errors = result.errors;
128
+ }
129
+
130
+ get isSuccess() {
131
+ return !this.errors?.length && !this.error;
132
+ }
133
+ }
@@ -0,0 +1,2 @@
1
+ export * from './admin';
2
+ export * from './oauth';