@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,47 @@
1
+ import axios from 'axios';
2
+ import qs from 'qs';
3
+ import { GetTokenWithAuthorizationCodeRequest, GrantTypeEnum, OAuthTokenResponse, RefreshTokenRequest } from './models';
4
+ import { STORE_DOMAIN } from '../../globals';
5
+
6
+ export * from './models';
7
+
8
+ type CommonOptions = {
9
+ storeName: string;
10
+ [p: string]: string;
11
+ };
12
+
13
+ export class OAuthAPI {
14
+ static getOAuthUrl(options: CommonOptions) {
15
+ return `https://${options.storeName}${options.storeDomain || STORE_DOMAIN}/api/admin/oauth`;
16
+ }
17
+
18
+ static async getTokenWithAuthorizationCode(request: GetTokenWithAuthorizationCodeRequest, options: CommonOptions) {
19
+ return axios.post<OAuthTokenResponse | null>(
20
+ `${OAuthAPI.getOAuthUrl(options)}/token`,
21
+ qs.stringify({
22
+ ...request,
23
+ grant_type: GrantTypeEnum.AUTHORIZATION_CODE,
24
+ }),
25
+ {
26
+ headers: {
27
+ 'Content-Type': 'application/x-www-form-urlencoded',
28
+ },
29
+ },
30
+ );
31
+ }
32
+
33
+ static async refreshToken(request: RefreshTokenRequest, options: CommonOptions) {
34
+ return axios.post<OAuthTokenResponse | null>(
35
+ `${OAuthAPI.getOAuthUrl(options)}/token`,
36
+ qs.stringify({
37
+ ...request,
38
+ grant_type: GrantTypeEnum.REFRESH_TOKEN,
39
+ }),
40
+ {
41
+ headers: {
42
+ 'Content-Type': 'application/x-www-form-urlencoded',
43
+ },
44
+ },
45
+ );
46
+ }
47
+ }
@@ -0,0 +1,37 @@
1
+ export enum GrantTypeEnum {
2
+ AUTHORIZATION_CODE = 'authorization_code',
3
+ CLIENT_CREDENTIALS = 'client_credentials',
4
+ REFRESH_TOKEN = 'refresh_token',
5
+ }
6
+
7
+ export enum APP_SCOPES {
8
+ READ_PRODUCTS = 'read_products',
9
+ WRITE_PRODUCTS = 'write_products',
10
+ READ_ORDERS = 'read_orders',
11
+ WRITE_ORDERS = 'write_orders',
12
+ READ_CUSTOMERS = 'read_customers',
13
+ WRITE_CUSTOMERS = 'write_customers',
14
+ READ_CAMPAIGNS = 'read_campaigns',
15
+ WRITE_CAMPAIGNS = 'write_campaigns',
16
+ READ_INVENTORIES = 'read_inventories',
17
+ WRITE_INVENTORIES = 'write_inventories',
18
+ }
19
+
20
+ export type GetTokenWithAuthorizationCodeRequest = {
21
+ client_id: string;
22
+ client_secret: string;
23
+ code: string;
24
+ redirect_uri: string;
25
+ };
26
+ export type RefreshTokenRequest = {
27
+ client_id: string;
28
+ client_secret: string;
29
+ refresh_token: string;
30
+ };
31
+ export type OAuthTokenResponse = {
32
+ token_type: string;
33
+ expires_in: number;
34
+ access_token: string;
35
+ scope: string;
36
+ refresh_token: string;
37
+ };
@@ -0,0 +1,19 @@
1
+ type IkasConfigOptions = {
2
+ apiVersion?: string;
3
+ [p: string]: any | undefined; // experimental
4
+ };
5
+
6
+ export const STORE_DOMAIN = '.myikas.com';
7
+ export const DEFAULT_API_VERSION = 'v1';
8
+
9
+ export class IkasConfig {
10
+ storeDomain: string;
11
+ apiVersion: string;
12
+ adminApiUrl: string;
13
+
14
+ constructor(options: IkasConfigOptions) {
15
+ this.storeDomain = options.storeDomain || STORE_DOMAIN;
16
+ this.apiVersion = options.apiVersion || DEFAULT_API_VERSION;
17
+ this.adminApiUrl = `https://api${this.storeDomain}/api/${this.apiVersion}/admin/graphql`;
18
+ }
19
+ }
@@ -0,0 +1 @@
1
+ export * from './constants';
@@ -0,0 +1 @@
1
+ export * from './webhook-validate';
@@ -0,0 +1,17 @@
1
+ import { IkasWebhook } from '../models';
2
+ import crypto from 'crypto';
3
+
4
+ export const webhookValidate = (clientSecret: string) => async (req: any, res: any, next: () => any) => {
5
+ const data: IkasWebhook = req.body;
6
+
7
+ const generatedHash = crypto
8
+ .createHmac('sha256', clientSecret || '')
9
+ .update(data.data, 'utf8')
10
+ .digest('hex');
11
+
12
+ if (generatedHash === data.signature) {
13
+ await next();
14
+ } else {
15
+ res.status(401).send({ message: 'invalid signature', statusCode: 401 });
16
+ }
17
+ };
package/src/index.ts ADDED
@@ -0,0 +1,34 @@
1
+ import { ikasAdminGraphQLAPIClient } from './api';
2
+ import { IkasConfig } from './globals';
3
+ import { OnCheckTokenCallback } from './api/base';
4
+
5
+ export * from './api';
6
+ export * from './globals';
7
+ export * from './helpers';
8
+ export * from './models';
9
+
10
+ type AppProps<TokenData> = {
11
+ clientId: string;
12
+ clientSecret: string;
13
+ accessToken: string;
14
+ apiVersion?: 'v1';
15
+ tokenData?: TokenData;
16
+ onCheckToken?: OnCheckTokenCallback<TokenData>;
17
+ [p: string]: any; // experimental
18
+ };
19
+
20
+ export class ikas<TokenData> {
21
+ adminApi: ikasAdminGraphQLAPIClient<TokenData>;
22
+ config: IkasConfig;
23
+
24
+ constructor(props: AppProps<TokenData>) {
25
+ this.config = new IkasConfig(props);
26
+
27
+ this.adminApi = new ikasAdminGraphQLAPIClient({
28
+ accessToken: props.accessToken,
29
+ graphApiUrl: this.config.adminApiUrl,
30
+ tokenData: props.tokenData,
31
+ onCheckToken: props.onCheckToken,
32
+ });
33
+ }
34
+ }
@@ -0,0 +1,7 @@
1
+ export interface IBaseModelWithIdAndDates {
2
+ id: string;
3
+ createdAt?: Date | null;
4
+ updatedAt?: Date | null;
5
+ merchantId?: string | null;
6
+ deleted?: boolean | null;
7
+ }
@@ -0,0 +1 @@
1
+ export * from './webhook';
@@ -0,0 +1 @@
1
+ export * from './models';
@@ -0,0 +1,90 @@
1
+ import {
2
+ Category,
3
+ Customer,
4
+ MerchantAppPaymentStatusEnum,
5
+ MerchantAppPaymentTypeEnum,
6
+ MerchantAppSubscription,
7
+ MerchantLicenceStatusEnum,
8
+ Order,
9
+ Product,
10
+ ProductAttribute,
11
+ ProductAttributeOption,
12
+ ProductAttributeValue,
13
+ ProductBrand,
14
+ ProductStockLocation,
15
+ ProductTag,
16
+ ProductVariantType,
17
+ Variant,
18
+ VariantType,
19
+ } from '../../api';
20
+
21
+ export enum WebhookScope {
22
+ ORDER_CREATED = 'store/order/created',
23
+ ORDER_UPDATED = 'store/order/updated',
24
+ PRODUCT_CREATED = 'store/product/created',
25
+ PRODUCT_UPDATED = 'store/product/updated',
26
+ CUSTOMER_CREATED = 'store/customer/created',
27
+ CUSTOMER_UPDATED = 'store/customer/updated',
28
+ CUSTOMER_FAVORITE_PRODUCTS_CREATED = 'store/customerFavoriteProducts/created',
29
+ CUSTOMER_FAVORITE_PRODUCTS_UPDATED = 'store/customerFavoriteProducts/updated',
30
+ STOCK_CREATED = 'store/stock/created',
31
+ STOCK_UPDATED = 'store/stock/updated',
32
+ APP_DELETED = 'store/app/deleted',
33
+ APP_PAYMENT = 'store/app/payment',
34
+ }
35
+
36
+ export interface IkasWebhook {
37
+ id: string;
38
+ createdAt: string; // ISO String
39
+ scope: string;
40
+ merchantId: string;
41
+ data: string;
42
+ signature: string;
43
+ authorizedAppId: string;
44
+ }
45
+
46
+ interface IWebhookProductAttributeValue extends ProductAttributeValue {
47
+ productAttribute?: ProductAttribute | null;
48
+ productAttributeOption?: ProductAttributeOption | null;
49
+ }
50
+
51
+ interface IWebhookProductVariantType extends ProductVariantType {
52
+ variantType: VariantType;
53
+ }
54
+
55
+ interface IWebhookVariant extends Variant {
56
+ attributes?: IWebhookProductAttributeValue[] | null;
57
+ }
58
+
59
+ export interface IWebhookProduct extends Product {
60
+ productVariantTypes?: IWebhookProductVariantType[] | null;
61
+ variants: IWebhookVariant[];
62
+ attributes?: IWebhookProductAttributeValue[] | null;
63
+ tags?: ProductTag[] | null;
64
+ brand?: ProductBrand | null;
65
+ categories?: Category[] | null;
66
+ }
67
+
68
+ export interface IWebhookOrder extends Order {}
69
+ export interface IWebhookCustomer extends Customer {}
70
+ export interface IWebhookStock extends ProductStockLocation {}
71
+
72
+ export type IWebhookStoreAppPaymentData = {
73
+ merchantAppPayment: {
74
+ _id: string;
75
+ appPaymentKey: string;
76
+ name: string;
77
+ type: MerchantAppPaymentTypeEnum;
78
+ status: MerchantAppPaymentStatusEnum;
79
+ paymentDate?: Date | null;
80
+ error?: string | null;
81
+ };
82
+ merchantLicence: {
83
+ licenceActivationDate?: Date | null;
84
+ fromDate?: Date | null;
85
+ toDate?: Date | null;
86
+ status: MerchantLicenceStatusEnum;
87
+ statusUpdatedAt: Date | null;
88
+ appSubscription?: MerchantAppSubscription[] | null;
89
+ };
90
+ };
package/tsconfig.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "compilerOptions": {
3
+ "baseUrl": "./src",
4
+ "outDir": "./dist",
5
+ "module": "commonjs",
6
+ "target": "es5",
7
+ "sourceMap": true,
8
+ "declaration": true,
9
+ "forceConsistentCasingInFileNames": true,
10
+ "noImplicitReturns": true,
11
+ "noImplicitThis": true,
12
+ "strictNullChecks": true,
13
+ "suppressImplicitAnyIndexErrors": true,
14
+ "noUnusedLocals": true,
15
+ "esModuleInterop": true,
16
+ "skipLibCheck": true,
17
+ "experimentalDecorators": true,
18
+ "emitDecoratorMetadata": true,
19
+ "resolveJsonModule": true
20
+ },
21
+ "exclude": [
22
+ "node_modules",
23
+ "dist"
24
+ ]
25
+ }