@ikas/api-client 0.0.1-canary.7 → 1.0.1

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 (51) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1 -1
  3. package/dist/api/admin/admin-client.d.ts +2 -0
  4. package/dist/api/admin/admin-client.js +2 -0
  5. package/dist/api/admin/admin-client.js.map +1 -1
  6. package/dist/api/admin/generated/index.d.ts +631 -7
  7. package/dist/api/admin/generated/index.js.map +1 -1
  8. package/dist/api/admin/rest.d.ts +33 -0
  9. package/dist/api/admin/rest.js +75 -0
  10. package/dist/api/admin/rest.js.map +1 -0
  11. package/dist/api/oauth/index.d.ts +2 -1
  12. package/dist/api/oauth/index.js +11 -0
  13. package/dist/api/oauth/index.js.map +1 -1
  14. package/dist/api/oauth/models.d.ts +5 -0
  15. package/dist/globals/constants.d.ts +9 -0
  16. package/dist/globals/constants.js +11 -1
  17. package/dist/globals/constants.js.map +1 -1
  18. package/dist/helpers/index.d.ts +1 -1
  19. package/dist/helpers/index.js +1 -1
  20. package/dist/helpers/index.js.map +1 -1
  21. package/dist/helpers/webhook-helpers.d.ts +4 -0
  22. package/dist/helpers/{webhook-validate.js → webhook-helpers.js} +23 -10
  23. package/dist/helpers/webhook-helpers.js.map +1 -0
  24. package/dist/models/webhook/models.d.ts +1 -0
  25. package/package.json +6 -5
  26. package/Jenkinsfile +0 -92
  27. package/codegen/admin.yml +0 -9
  28. package/dist/helpers/webhook-validate.d.ts +0 -1
  29. package/dist/helpers/webhook-validate.js.map +0 -1
  30. package/src/api/admin/admin-client.ts +0 -15
  31. package/src/api/admin/common-gql.ts +0 -425
  32. package/src/api/admin/generated/index.ts +0 -2708
  33. package/src/api/admin/index.ts +0 -4
  34. package/src/api/admin/mutation-gql.ts +0 -255
  35. package/src/api/admin/mutation.ts +0 -195
  36. package/src/api/admin/query-gql.ts +0 -521
  37. package/src/api/admin/query.ts +0 -144
  38. package/src/api/base.ts +0 -134
  39. package/src/api/index.ts +0 -2
  40. package/src/api/oauth/index.ts +0 -47
  41. package/src/api/oauth/models.ts +0 -37
  42. package/src/globals/constants.ts +0 -19
  43. package/src/globals/index.ts +0 -1
  44. package/src/helpers/index.ts +0 -1
  45. package/src/helpers/webhook-validate.ts +0 -17
  46. package/src/index.ts +0 -34
  47. package/src/models/base.ts +0 -7
  48. package/src/models/index.ts +0 -1
  49. package/src/models/webhook/index.ts +0 -1
  50. package/src/models/webhook/models.ts +0 -90
  51. package/tsconfig.json +0 -25
package/src/api/base.ts DELETED
@@ -1,134 +0,0 @@
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<{ accessToken: string | undefined; tokenData?: TokenData }>
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, tokenData } = await this.onCheckToken(this.tokenData);
110
- if (accessToken) {
111
- this.accessToken = accessToken;
112
- this.tokenData = tokenData;
113
- this._client = this.createGraphQLClient();
114
- }
115
- }
116
- }
117
- }
118
-
119
- export class APIResult<T> {
120
- data?: T;
121
- error?: string;
122
- errors?: GraphQLError[];
123
- partial?: boolean;
124
-
125
- constructor(result: { data?: T; error?: string; errors?: GraphQLError[] }) {
126
- this.data = result.data;
127
- this.error = result.error;
128
- this.errors = result.errors;
129
- }
130
-
131
- get isSuccess() {
132
- return !this.errors?.length && !this.error;
133
- }
134
- }
package/src/api/index.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from './admin';
2
- export * from './oauth';
@@ -1,47 +0,0 @@
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
- }
@@ -1,37 +0,0 @@
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
- };
@@ -1,19 +0,0 @@
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
- }
@@ -1 +0,0 @@
1
- export * from './constants';
@@ -1 +0,0 @@
1
- export * from './webhook-validate';
@@ -1,17 +0,0 @@
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 DELETED
@@ -1,34 +0,0 @@
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
- }
@@ -1,7 +0,0 @@
1
- export interface IBaseModelWithIdAndDates {
2
- id: string;
3
- createdAt?: Date | null;
4
- updatedAt?: Date | null;
5
- merchantId?: string | null;
6
- deleted?: boolean | null;
7
- }
@@ -1 +0,0 @@
1
- export * from './webhook';
@@ -1 +0,0 @@
1
- export * from './models';
@@ -1,90 +0,0 @@
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 DELETED
@@ -1,25 +0,0 @@
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
- }