@maioradv/cms-basic-lib 1.0.0
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.
- package/README.md +6 -0
- package/dist/apitokens/graphql.d.ts +4 -0
- package/dist/apitokens/graphql.js +45 -0
- package/dist/apitokens/index.d.ts +14 -0
- package/dist/apitokens/index.js +31 -0
- package/dist/apitokens/types.d.ts +22 -0
- package/dist/apitokens/types.js +2 -0
- package/dist/auth/index.d.ts +7 -0
- package/dist/auth/index.js +15 -0
- package/dist/auth/types.d.ts +60 -0
- package/dist/auth/types.js +38 -0
- package/dist/client.d.ts +41 -0
- package/dist/client.js +60 -0
- package/dist/collections/graphql.d.ts +16 -0
- package/dist/collections/graphql.js +97 -0
- package/dist/collections/index.d.ts +26 -0
- package/dist/collections/index.js +62 -0
- package/dist/collections/types.d.ts +57 -0
- package/dist/collections/types.js +2 -0
- package/dist/config.d.ts +13 -0
- package/dist/config.js +20 -0
- package/dist/configs/graphql.d.ts +4 -0
- package/dist/configs/graphql.js +86 -0
- package/dist/configs/index.d.ts +17 -0
- package/dist/configs/index.js +37 -0
- package/dist/configs/model.d.ts +5 -0
- package/dist/configs/model.js +2 -0
- package/dist/configs/services/ti-delizio.config.d.ts +18 -0
- package/dist/configs/services/ti-delizio.config.js +9 -0
- package/dist/configs/types.d.ts +23 -0
- package/dist/configs/types.js +2 -0
- package/dist/core/dto/clauses/index.d.ts +17 -0
- package/dist/core/dto/clauses/index.js +10 -0
- package/dist/core/dto/pagination/index.d.ts +37 -0
- package/dist/core/dto/pagination/index.js +6 -0
- package/dist/core/dto/sorting/index.d.ts +9 -0
- package/dist/core/dto/sorting/index.js +10 -0
- package/dist/core/model/remove-gql.response.d.ts +3 -0
- package/dist/core/model/remove-gql.response.js +2 -0
- package/dist/core/types/resolver.d.ts +12 -0
- package/dist/core/types/resolver.js +2 -0
- package/dist/core/utils/queryParams.d.ts +9 -0
- package/dist/core/utils/queryParams.js +14 -0
- package/dist/customers/types.d.ts +9 -0
- package/dist/customers/types.js +2 -0
- package/dist/error.d.ts +14 -0
- package/dist/error.js +39 -0
- package/dist/images/graphql.d.ts +4 -0
- package/dist/images/graphql.js +38 -0
- package/dist/images/index.d.ts +11 -0
- package/dist/images/index.js +27 -0
- package/dist/images/types.d.ts +29 -0
- package/dist/images/types.js +2 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +31 -0
- package/dist/io/index.d.ts +5 -0
- package/dist/io/index.js +13 -0
- package/dist/io/types.d.ts +4 -0
- package/dist/io/types.js +2 -0
- package/dist/languages/graphql.d.ts +4 -0
- package/dist/languages/graphql.js +51 -0
- package/dist/languages/index.d.ts +14 -0
- package/dist/languages/index.js +31 -0
- package/dist/languages/types.d.ts +29 -0
- package/dist/languages/types.js +2 -0
- package/dist/model.d.ts +25 -0
- package/dist/model.js +43 -0
- package/dist/popups/graphql.d.ts +4 -0
- package/dist/popups/graphql.js +54 -0
- package/dist/popups/index.d.ts +22 -0
- package/dist/popups/index.js +53 -0
- package/dist/popups/triggers.d.ts +6 -0
- package/dist/popups/triggers.js +12 -0
- package/dist/popups/types.d.ts +67 -0
- package/dist/popups/types.js +21 -0
- package/dist/productAttributes/graphql.d.ts +6 -0
- package/dist/productAttributes/graphql.js +103 -0
- package/dist/productAttributes/index.d.ts +16 -0
- package/dist/productAttributes/index.js +37 -0
- package/dist/productAttributes/types.d.ts +37 -0
- package/dist/productAttributes/types.js +2 -0
- package/dist/productAttributes/values.d.ts +11 -0
- package/dist/productAttributes/values.js +21 -0
- package/dist/products/graphql.d.ts +4 -0
- package/dist/products/graphql.js +56 -0
- package/dist/products/index.d.ts +26 -0
- package/dist/products/index.js +65 -0
- package/dist/products/types.d.ts +82 -0
- package/dist/products/types.js +2 -0
- package/dist/products/variants.d.ts +6 -0
- package/dist/products/variants.js +12 -0
- package/dist/roles/graphql.d.ts +4 -0
- package/dist/roles/graphql.js +50 -0
- package/dist/roles/index.d.ts +14 -0
- package/dist/roles/index.js +31 -0
- package/dist/roles/types.d.ts +25 -0
- package/dist/roles/types.js +2 -0
- package/dist/types.d.ts +30 -0
- package/dist/types.js +19 -0
- package/package.json +30 -0
package/README.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiTokensResolvers = void 0;
|
|
4
|
+
exports.ApiTokensResolvers = {
|
|
5
|
+
query: {
|
|
6
|
+
apiTokens: {
|
|
7
|
+
name: 'apiTokens',
|
|
8
|
+
query: `query ApiTokenList($limit: Int, $after: Int, $before: Int){
|
|
9
|
+
apiTokens(limit: $limit, after: $after, before: $before){
|
|
10
|
+
edges {
|
|
11
|
+
node {
|
|
12
|
+
id
|
|
13
|
+
}
|
|
14
|
+
cursor
|
|
15
|
+
}
|
|
16
|
+
nodes {
|
|
17
|
+
id
|
|
18
|
+
name
|
|
19
|
+
uuid
|
|
20
|
+
permissions
|
|
21
|
+
readOnly
|
|
22
|
+
createdAt
|
|
23
|
+
updatedAt
|
|
24
|
+
}
|
|
25
|
+
meta {
|
|
26
|
+
startCursor
|
|
27
|
+
endCursor
|
|
28
|
+
hasNextPage
|
|
29
|
+
hasPreviousPage
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}`,
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
mutation: {
|
|
36
|
+
removeApiTokens: {
|
|
37
|
+
name: 'removeApiTokens',
|
|
38
|
+
query: `mutation ApiTokenDelete($id: [Int!]!){
|
|
39
|
+
removeApiTokens(id: $id) {
|
|
40
|
+
count
|
|
41
|
+
}
|
|
42
|
+
}`,
|
|
43
|
+
},
|
|
44
|
+
}
|
|
45
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { PaginatedDto, PaginatedGQL } from "../core/dto/pagination";
|
|
2
|
+
import { RemoveGQL } from "../core/model/remove-gql.response";
|
|
3
|
+
import { RestApiModuleI, ApiModule, GraphApiModuleI } from "../model";
|
|
4
|
+
import { QueryApiTokenGQLDto } from "./graphql";
|
|
5
|
+
import { ApiToken, CreateApiTokenDto, QueryApiTokenDto, UpdateApiTokenDto } from "./types";
|
|
6
|
+
export default class ApiTokens extends ApiModule implements RestApiModuleI, GraphApiModuleI {
|
|
7
|
+
create(args: CreateApiTokenDto): Promise<ApiToken>;
|
|
8
|
+
findAll(args?: QueryApiTokenDto): Promise<PaginatedDto<ApiToken>>;
|
|
9
|
+
findOne(id: number): Promise<ApiToken>;
|
|
10
|
+
update(id: number, data: UpdateApiTokenDto): Promise<ApiToken>;
|
|
11
|
+
remove(id: number): Promise<ApiToken>;
|
|
12
|
+
list(args?: QueryApiTokenGQLDto): Promise<PaginatedGQL<ApiToken>>;
|
|
13
|
+
removeMany(id: number | number[]): Promise<RemoveGQL>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const queryParams_1 = require("../core/utils/queryParams");
|
|
4
|
+
const model_1 = require("../model");
|
|
5
|
+
const graphql_1 = require("./graphql");
|
|
6
|
+
class ApiTokens extends model_1.ApiModule {
|
|
7
|
+
create(args) {
|
|
8
|
+
return this._call('post', '/apitokens', args);
|
|
9
|
+
}
|
|
10
|
+
findAll(args = {}) {
|
|
11
|
+
return this._call('get', '/apitokens', (0, queryParams_1.queryParams)(args));
|
|
12
|
+
}
|
|
13
|
+
findOne(id) {
|
|
14
|
+
return this._call('get', `/apitokens/${id}`);
|
|
15
|
+
}
|
|
16
|
+
update(id, data) {
|
|
17
|
+
return this._call('patch', `/apitokens/${id}`, data);
|
|
18
|
+
}
|
|
19
|
+
remove(id) {
|
|
20
|
+
return this._call('delete', `/apitokens/${id}`);
|
|
21
|
+
}
|
|
22
|
+
list(args = {}) {
|
|
23
|
+
return this._graphql(graphql_1.ApiTokensResolvers.query.apiTokens, args);
|
|
24
|
+
}
|
|
25
|
+
removeMany(id) {
|
|
26
|
+
return this._graphql(graphql_1.ApiTokensResolvers.mutation.removeApiTokens, {
|
|
27
|
+
id
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.default = ApiTokens;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Permission } from "../auth/types";
|
|
2
|
+
import { StringClause, WhereClausesDto } from "../core/dto/clauses";
|
|
3
|
+
import { Sorting, SortingParamsDto } from "../core/dto/sorting";
|
|
4
|
+
import { QueryParamsDto } from "../core/utils/queryParams";
|
|
5
|
+
export type ApiToken = {
|
|
6
|
+
id: number;
|
|
7
|
+
name: string;
|
|
8
|
+
uuid: string;
|
|
9
|
+
permissions: Permission[];
|
|
10
|
+
readOnly: boolean;
|
|
11
|
+
createdAt: Date;
|
|
12
|
+
updatedAt: Date;
|
|
13
|
+
};
|
|
14
|
+
export type CreateApiTokenDto = Omit<ApiToken, 'id' | 'createdAt' | 'updatedAt' | 'uuid' | 'readOnly'>;
|
|
15
|
+
export type UpdateApiTokenDto = Partial<CreateApiTokenDto>;
|
|
16
|
+
export type SortingApiTokenDto = SortingParamsDto<{
|
|
17
|
+
name?: Sorting;
|
|
18
|
+
}>;
|
|
19
|
+
export type ClausesApiTokenDto = WhereClausesDto<{
|
|
20
|
+
name?: StringClause;
|
|
21
|
+
}>;
|
|
22
|
+
export type QueryApiTokenDto = QueryParamsDto<SortingApiTokenDto, ClausesApiTokenDto>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const model_1 = require("../model");
|
|
4
|
+
class Auth extends model_1.ApiModule {
|
|
5
|
+
jwt(accessToken) {
|
|
6
|
+
return this._call('post', `/auth/jwt/${accessToken}`);
|
|
7
|
+
}
|
|
8
|
+
token(apiToken) {
|
|
9
|
+
return this._call('post', `/auth/token/${apiToken}`);
|
|
10
|
+
}
|
|
11
|
+
me() {
|
|
12
|
+
return this._call('get', `/auth/me`);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.default = Auth;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { ApiToken } from "../apitokens/types";
|
|
2
|
+
import { Customer } from "../customers/types";
|
|
3
|
+
export type AccessTokenDto = {
|
|
4
|
+
access_token: string;
|
|
5
|
+
token_type: string;
|
|
6
|
+
expires_in: number;
|
|
7
|
+
refresh_token?: string;
|
|
8
|
+
};
|
|
9
|
+
export declare enum JwtContextType {
|
|
10
|
+
customer = "Customer",
|
|
11
|
+
apiToken = "ApiToken"
|
|
12
|
+
}
|
|
13
|
+
export type JwtPayloadContext = {
|
|
14
|
+
type: JwtContextType;
|
|
15
|
+
id: number;
|
|
16
|
+
name: string;
|
|
17
|
+
};
|
|
18
|
+
export type JwtPayload = {
|
|
19
|
+
sub: string;
|
|
20
|
+
aud: string[];
|
|
21
|
+
scope: string[];
|
|
22
|
+
iat: number;
|
|
23
|
+
exp: number;
|
|
24
|
+
iss: string;
|
|
25
|
+
context: JwtPayloadContext;
|
|
26
|
+
};
|
|
27
|
+
export type Jwt = {
|
|
28
|
+
payload: JwtPayload;
|
|
29
|
+
Customer?: Customer;
|
|
30
|
+
ApiToken?: ApiToken;
|
|
31
|
+
};
|
|
32
|
+
export declare enum Permission {
|
|
33
|
+
read_products = "read_products",
|
|
34
|
+
write_products = "write_products",
|
|
35
|
+
read_collections = "read_collections",
|
|
36
|
+
write_collections = "write_collections",
|
|
37
|
+
read_productattributes = "read_productattributes",
|
|
38
|
+
write_productattributes = "write_productattributes",
|
|
39
|
+
read_productattributevalues = "read_productattributevalues",
|
|
40
|
+
write_productattributevalues = "write_productattributevalues",
|
|
41
|
+
read_bulkoperations = "read_bulkoperations",
|
|
42
|
+
write_bulkoperations = "write_bulkoperations",
|
|
43
|
+
run_bulkoperations = "run_bulkoperations",
|
|
44
|
+
read_discounts = "read_discounts",
|
|
45
|
+
write_discounts = "write_discounts",
|
|
46
|
+
read_languages = "read_languages",
|
|
47
|
+
write_languages = "write_languages",
|
|
48
|
+
read_images = "read_images",
|
|
49
|
+
write_images = "write_images",
|
|
50
|
+
read_apitokens = "read_apitokens",
|
|
51
|
+
write_apitokens = "write_apitokens",
|
|
52
|
+
read_roles = "read_roles",
|
|
53
|
+
write_roles = "write_roles",
|
|
54
|
+
read_popups = "read_popups",
|
|
55
|
+
write_popups = "write_popups",
|
|
56
|
+
read_configs = "read_configs",
|
|
57
|
+
write_configs = "write_configs",
|
|
58
|
+
write_io_operations = "write_io_operations",
|
|
59
|
+
read_io_operations = "read_io_operations"
|
|
60
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Permission = exports.JwtContextType = void 0;
|
|
4
|
+
var JwtContextType;
|
|
5
|
+
(function (JwtContextType) {
|
|
6
|
+
JwtContextType["customer"] = "Customer";
|
|
7
|
+
JwtContextType["apiToken"] = "ApiToken";
|
|
8
|
+
})(JwtContextType || (exports.JwtContextType = JwtContextType = {}));
|
|
9
|
+
var Permission;
|
|
10
|
+
(function (Permission) {
|
|
11
|
+
Permission["read_products"] = "read_products";
|
|
12
|
+
Permission["write_products"] = "write_products";
|
|
13
|
+
Permission["read_collections"] = "read_collections";
|
|
14
|
+
Permission["write_collections"] = "write_collections";
|
|
15
|
+
Permission["read_productattributes"] = "read_productattributes";
|
|
16
|
+
Permission["write_productattributes"] = "write_productattributes";
|
|
17
|
+
Permission["read_productattributevalues"] = "read_productattributevalues";
|
|
18
|
+
Permission["write_productattributevalues"] = "write_productattributevalues";
|
|
19
|
+
Permission["read_bulkoperations"] = "read_bulkoperations";
|
|
20
|
+
Permission["write_bulkoperations"] = "write_bulkoperations";
|
|
21
|
+
Permission["run_bulkoperations"] = "run_bulkoperations";
|
|
22
|
+
Permission["read_discounts"] = "read_discounts";
|
|
23
|
+
Permission["write_discounts"] = "write_discounts";
|
|
24
|
+
Permission["read_languages"] = "read_languages";
|
|
25
|
+
Permission["write_languages"] = "write_languages";
|
|
26
|
+
Permission["read_images"] = "read_images";
|
|
27
|
+
Permission["write_images"] = "write_images";
|
|
28
|
+
Permission["read_apitokens"] = "read_apitokens";
|
|
29
|
+
Permission["write_apitokens"] = "write_apitokens";
|
|
30
|
+
Permission["read_roles"] = "read_roles";
|
|
31
|
+
Permission["write_roles"] = "write_roles";
|
|
32
|
+
Permission["read_popups"] = "read_popups";
|
|
33
|
+
Permission["write_popups"] = "write_popups";
|
|
34
|
+
Permission["read_configs"] = "read_configs";
|
|
35
|
+
Permission["write_configs"] = "write_configs";
|
|
36
|
+
Permission["write_io_operations"] = "write_io_operations";
|
|
37
|
+
Permission["read_io_operations"] = "read_io_operations";
|
|
38
|
+
})(Permission || (exports.Permission = Permission = {}));
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Axios } from "axios";
|
|
2
|
+
import { ValidatedApiConfigs, ApiConfigs } from "./config";
|
|
3
|
+
import { ClientApiI } from "./model";
|
|
4
|
+
import Auth from "./auth";
|
|
5
|
+
import { AccessTokenDto } from "./auth/types";
|
|
6
|
+
import ApiTokens from "./apitokens";
|
|
7
|
+
import Collections from "./collections";
|
|
8
|
+
import Images from "./images";
|
|
9
|
+
import Configs from "./configs";
|
|
10
|
+
import IO from "./io";
|
|
11
|
+
import Languages from "./languages";
|
|
12
|
+
import Roles from "./roles";
|
|
13
|
+
import Popups from "./popups";
|
|
14
|
+
import PopupTriggers from "./popups/triggers";
|
|
15
|
+
import ProductAttributes from "./productAttributes";
|
|
16
|
+
import ProductAttributeValues from "./productAttributes/values";
|
|
17
|
+
import Products from "./products";
|
|
18
|
+
import ProductVariants from "./products/variants";
|
|
19
|
+
export declare class MaiorCmsApiClient implements ClientApiI {
|
|
20
|
+
protected config: ApiConfigs;
|
|
21
|
+
protected client: Axios;
|
|
22
|
+
protected configApi: ValidatedApiConfigs;
|
|
23
|
+
authentication: Auth;
|
|
24
|
+
apiTokens: ApiTokens;
|
|
25
|
+
collections: Collections;
|
|
26
|
+
configs: Configs;
|
|
27
|
+
images: Images;
|
|
28
|
+
io: IO;
|
|
29
|
+
languages: Languages;
|
|
30
|
+
popups: Popups;
|
|
31
|
+
popupTriggers: PopupTriggers;
|
|
32
|
+
productAttributes: ProductAttributes;
|
|
33
|
+
productAttributeValues: ProductAttributeValues;
|
|
34
|
+
products: Products;
|
|
35
|
+
productVariants: ProductVariants;
|
|
36
|
+
roles: Roles;
|
|
37
|
+
constructor(config: ApiConfigs);
|
|
38
|
+
protected _initClient(): Axios;
|
|
39
|
+
protected _initModules(): void;
|
|
40
|
+
auth(): Promise<AccessTokenDto>;
|
|
41
|
+
}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MaiorCmsApiClient = void 0;
|
|
4
|
+
const axios_1 = require("axios");
|
|
5
|
+
const config_1 = require("./config");
|
|
6
|
+
const types_1 = require("./types");
|
|
7
|
+
const auth_1 = require("./auth");
|
|
8
|
+
const error_1 = require("./error");
|
|
9
|
+
const apitokens_1 = require("./apitokens");
|
|
10
|
+
const collections_1 = require("./collections");
|
|
11
|
+
const images_1 = require("./images");
|
|
12
|
+
const configs_1 = require("./configs");
|
|
13
|
+
const io_1 = require("./io");
|
|
14
|
+
const languages_1 = require("./languages");
|
|
15
|
+
const roles_1 = require("./roles");
|
|
16
|
+
const popups_1 = require("./popups");
|
|
17
|
+
const triggers_1 = require("./popups/triggers");
|
|
18
|
+
const productAttributes_1 = require("./productAttributes");
|
|
19
|
+
const values_1 = require("./productAttributes/values");
|
|
20
|
+
const products_1 = require("./products");
|
|
21
|
+
const variants_1 = require("./products/variants");
|
|
22
|
+
class MaiorCmsApiClient {
|
|
23
|
+
constructor(config) {
|
|
24
|
+
this.config = config;
|
|
25
|
+
this.configApi = (0, config_1.validateConfigs)(this.config);
|
|
26
|
+
this.client = this._initClient();
|
|
27
|
+
this._initModules();
|
|
28
|
+
}
|
|
29
|
+
_initClient() {
|
|
30
|
+
axios_1.default.defaults.baseURL = this.configApi.sandbox ? `http://${this.configApi.host}` : `https://${this.configApi.host}`;
|
|
31
|
+
axios_1.default.defaults.headers.common[types_1.ApiHeader.ApiVersion] = this.configApi.version;
|
|
32
|
+
axios_1.default.defaults.headers.common[types_1.ApiHeader.ApiCacheControl] = this.configApi.disableCache ? 'no-cache' : 'caching';
|
|
33
|
+
axios_1.default.defaults.headers.common['Content-Type'] = 'application/json';
|
|
34
|
+
return axios_1.default;
|
|
35
|
+
}
|
|
36
|
+
_initModules() {
|
|
37
|
+
this.authentication = new auth_1.default(this.client);
|
|
38
|
+
this.apiTokens = new apitokens_1.default(this.client);
|
|
39
|
+
this.collections = new collections_1.default(this.client);
|
|
40
|
+
this.configs = new configs_1.default(this.client);
|
|
41
|
+
this.images = new images_1.default(this.client);
|
|
42
|
+
this.io = new io_1.default(this.client);
|
|
43
|
+
this.languages = new languages_1.default(this.client);
|
|
44
|
+
this.popups = new popups_1.default(this.client);
|
|
45
|
+
this.popupTriggers = new triggers_1.default(this.client);
|
|
46
|
+
this.productAttributes = new productAttributes_1.default(this.client);
|
|
47
|
+
this.productAttributeValues = new values_1.default(this.client);
|
|
48
|
+
this.products = new products_1.default(this.client);
|
|
49
|
+
this.productVariants = new variants_1.default(this.client);
|
|
50
|
+
this.roles = new roles_1.default(this.client);
|
|
51
|
+
}
|
|
52
|
+
async auth() {
|
|
53
|
+
if (!this.configApi.credentials)
|
|
54
|
+
throw new error_1.AuthError('Missing credentials');
|
|
55
|
+
const access = this.configApi.credentials.apiToken ? await this.authentication.token(this.configApi.credentials.apiToken) : await this.authentication.jwt(this.configApi.credentials.accessToken);
|
|
56
|
+
this.client.defaults.headers.common[types_1.ApiHeader.Authorization] = `${access.token_type} ${access.access_token}`;
|
|
57
|
+
return access;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.MaiorCmsApiClient = MaiorCmsApiClient;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { PaginatedGQLQueryDto } from "../core/dto/pagination";
|
|
2
|
+
import { Resolvers } from "../core/types/resolver";
|
|
3
|
+
import { ProductCollection } from "../products/types";
|
|
4
|
+
import { OmitRequire } from "../types";
|
|
5
|
+
import { Collection } from "./types";
|
|
6
|
+
export declare const CollectionsResolvers: Resolvers<['collections'], ['updateManyCollections', 'updateCollectionProducts', 'removeCollections']>;
|
|
7
|
+
export type UpdateCollectionProductsListDto = OmitRequire<ProductCollection, 'collectionId' | 'createdAt' | 'updatedAt', 'productId'>;
|
|
8
|
+
export type UpdateManyCollectionsListDto = OmitRequire<Collection, 'slug' | 'createdAt' | 'updatedAt' | 'metafields' | 'translations', 'id'>;
|
|
9
|
+
export type ArgsUpdateProductsDto = {
|
|
10
|
+
collectionId: number;
|
|
11
|
+
updateList: UpdateCollectionProductsListDto[];
|
|
12
|
+
};
|
|
13
|
+
export type ArgsUpdateManyDto = {
|
|
14
|
+
updateList: UpdateManyCollectionsListDto[];
|
|
15
|
+
};
|
|
16
|
+
export type QueryCollectionGQLDto = PaginatedGQLQueryDto;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CollectionsResolvers = void 0;
|
|
4
|
+
exports.CollectionsResolvers = {
|
|
5
|
+
query: {
|
|
6
|
+
collections: {
|
|
7
|
+
name: 'collections',
|
|
8
|
+
query: `query CollectionList($limit: Int, $after: Int, $before: Int){
|
|
9
|
+
collections(limit: $limit, after: $after, before: $before){
|
|
10
|
+
edges {
|
|
11
|
+
node {
|
|
12
|
+
id
|
|
13
|
+
}
|
|
14
|
+
cursor
|
|
15
|
+
}
|
|
16
|
+
nodes {
|
|
17
|
+
id
|
|
18
|
+
slug
|
|
19
|
+
title
|
|
20
|
+
subtitle
|
|
21
|
+
description
|
|
22
|
+
translations {
|
|
23
|
+
key
|
|
24
|
+
locale
|
|
25
|
+
value
|
|
26
|
+
}
|
|
27
|
+
metafields {
|
|
28
|
+
key
|
|
29
|
+
value
|
|
30
|
+
}
|
|
31
|
+
published
|
|
32
|
+
position
|
|
33
|
+
allowChildren
|
|
34
|
+
parentId
|
|
35
|
+
createdAt
|
|
36
|
+
updatedAt
|
|
37
|
+
}
|
|
38
|
+
meta {
|
|
39
|
+
startCursor
|
|
40
|
+
endCursor
|
|
41
|
+
hasNextPage
|
|
42
|
+
hasPreviousPage
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}`,
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
mutation: {
|
|
49
|
+
updateCollectionProducts: {
|
|
50
|
+
name: 'updateCollectionProducts',
|
|
51
|
+
query: `mutation CollectionUpdateProducts($collectionId: Int!, $updateList:[UpdateCollectionProductsListDto!]!){
|
|
52
|
+
updateCollectionProducts(collectionId:$collectionId,updateList:$updateList){
|
|
53
|
+
collectionId
|
|
54
|
+
productId
|
|
55
|
+
position
|
|
56
|
+
createdAt
|
|
57
|
+
updatedAt
|
|
58
|
+
}
|
|
59
|
+
}`,
|
|
60
|
+
},
|
|
61
|
+
updateManyCollections: {
|
|
62
|
+
name: 'updateManyCollections',
|
|
63
|
+
query: `mutation CollectionsUpdate($updateList:[UpdateManyCollectionsListDto!]!) {
|
|
64
|
+
updateManyCollections(updateList:$updateList){
|
|
65
|
+
id
|
|
66
|
+
slug
|
|
67
|
+
title
|
|
68
|
+
subtitle
|
|
69
|
+
description
|
|
70
|
+
translations {
|
|
71
|
+
key
|
|
72
|
+
locale
|
|
73
|
+
value
|
|
74
|
+
}
|
|
75
|
+
metafields {
|
|
76
|
+
key
|
|
77
|
+
value
|
|
78
|
+
}
|
|
79
|
+
published
|
|
80
|
+
position
|
|
81
|
+
allowChildren
|
|
82
|
+
parentId
|
|
83
|
+
createdAt
|
|
84
|
+
updatedAt
|
|
85
|
+
}
|
|
86
|
+
}`
|
|
87
|
+
},
|
|
88
|
+
removeCollections: {
|
|
89
|
+
name: 'removeCollections',
|
|
90
|
+
query: `mutation CollectionDelete($id: [Int!]!){
|
|
91
|
+
removeCollections(id: $id) {
|
|
92
|
+
count
|
|
93
|
+
}
|
|
94
|
+
}`,
|
|
95
|
+
},
|
|
96
|
+
}
|
|
97
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { PaginatedDto, PaginatedGQL } from "../core/dto/pagination";
|
|
2
|
+
import { RemoveGQL } from "../core/model/remove-gql.response";
|
|
3
|
+
import { Image } from "../images/types";
|
|
4
|
+
import { RestApiModuleI, ApiModule, GraphApiModuleI } from "../model";
|
|
5
|
+
import { ProductCollection } from "../products/types";
|
|
6
|
+
import { WithRelation } from "../types";
|
|
7
|
+
import { ArgsUpdateManyDto, ArgsUpdateProductsDto, QueryCollectionGQLDto } from "./graphql";
|
|
8
|
+
import { Collection, CollectionImage, CreateCollectionDto, CreateCollectionImageDto, CreateProductOnCollectionDto, FindAllCollectionDto, FindAllCollectionProductsDto, QueryCollectionDto, QueryCollectionProductsDto, UpdateCollectionDto, UpdateCollectionImageDto } from "./types";
|
|
9
|
+
export default class Collections extends ApiModule implements RestApiModuleI, GraphApiModuleI {
|
|
10
|
+
create(args: CreateCollectionDto): Promise<Collection>;
|
|
11
|
+
findAll(args?: QueryCollectionDto): Promise<PaginatedDto<FindAllCollectionDto>>;
|
|
12
|
+
findOne(id: number): Promise<Collection>;
|
|
13
|
+
update(id: number, data: UpdateCollectionDto): Promise<Collection>;
|
|
14
|
+
remove(id: number): Promise<Collection>;
|
|
15
|
+
list(args?: QueryCollectionGQLDto): Promise<PaginatedGQL<Collection>>;
|
|
16
|
+
updateMany(args: ArgsUpdateManyDto): Promise<Collection[]>;
|
|
17
|
+
updateProducts(args: ArgsUpdateProductsDto): Promise<ProductCollection[]>;
|
|
18
|
+
removeMany(id: number | number[]): Promise<RemoveGQL>;
|
|
19
|
+
createImage(collectionId: number, args: CreateCollectionImageDto): Promise<CollectionImage>;
|
|
20
|
+
findAllImages(collectionId: number): Promise<WithRelation<CollectionImage, 'Image', Image>[]>;
|
|
21
|
+
updateImage(collectionId: number, imageId: number, data: UpdateCollectionImageDto): Promise<CollectionImage>;
|
|
22
|
+
removeImage(collectionId: number, imageId: number): Promise<CollectionImage>;
|
|
23
|
+
createProduct(collectionId: number, args: CreateProductOnCollectionDto): Promise<ProductCollection>;
|
|
24
|
+
findAllProducts(collectionId: number, args?: QueryCollectionProductsDto): Promise<PaginatedDto<FindAllCollectionProductsDto>>;
|
|
25
|
+
removeProduct(collectionId: number, productId: number): Promise<ProductCollection>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const queryParams_1 = require("../core/utils/queryParams");
|
|
4
|
+
const model_1 = require("../model");
|
|
5
|
+
const graphql_1 = require("./graphql");
|
|
6
|
+
class Collections extends model_1.ApiModule {
|
|
7
|
+
create(args) {
|
|
8
|
+
return this._call('post', '/collections', args);
|
|
9
|
+
}
|
|
10
|
+
findAll(args = {}) {
|
|
11
|
+
return this._call('get', '/collections', (0, queryParams_1.queryParams)(args));
|
|
12
|
+
}
|
|
13
|
+
findOne(id) {
|
|
14
|
+
return this._call('get', `/collections/${id}`);
|
|
15
|
+
}
|
|
16
|
+
update(id, data) {
|
|
17
|
+
return this._call('patch', `/collections/${id}`, data);
|
|
18
|
+
}
|
|
19
|
+
remove(id) {
|
|
20
|
+
return this._call('delete', `/collections/${id}`);
|
|
21
|
+
}
|
|
22
|
+
list(args = {}) {
|
|
23
|
+
return this._graphql(graphql_1.CollectionsResolvers.query.collections, args);
|
|
24
|
+
}
|
|
25
|
+
updateMany(args) {
|
|
26
|
+
return this._graphql(graphql_1.CollectionsResolvers.mutation.updateManyCollections, args);
|
|
27
|
+
}
|
|
28
|
+
updateProducts(args) {
|
|
29
|
+
return this._graphql(graphql_1.CollectionsResolvers.mutation.updateCollectionProducts, args);
|
|
30
|
+
}
|
|
31
|
+
removeMany(id) {
|
|
32
|
+
return this._graphql(graphql_1.CollectionsResolvers.mutation.removeCollections, {
|
|
33
|
+
id
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
createImage(collectionId, args) {
|
|
37
|
+
return this._call('post', `/collections/${collectionId}/images`, args, {
|
|
38
|
+
headers: {
|
|
39
|
+
'Content-Type': 'multipart/form-data'
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
findAllImages(collectionId) {
|
|
44
|
+
return this._call('get', `/collections/${collectionId}/images`);
|
|
45
|
+
}
|
|
46
|
+
updateImage(collectionId, imageId, data) {
|
|
47
|
+
return this._call('patch', `/collections/${collectionId}/images/${imageId}`, data);
|
|
48
|
+
}
|
|
49
|
+
removeImage(collectionId, imageId) {
|
|
50
|
+
return this._call('delete', `/collections/${collectionId}/images/${imageId}`);
|
|
51
|
+
}
|
|
52
|
+
createProduct(collectionId, args) {
|
|
53
|
+
return this._call('post', `/collections/${collectionId}/products`, args);
|
|
54
|
+
}
|
|
55
|
+
findAllProducts(collectionId, args = {}) {
|
|
56
|
+
return this._call('get', `/collections/${collectionId}/products`, (0, queryParams_1.queryParams)(args));
|
|
57
|
+
}
|
|
58
|
+
removeProduct(collectionId, productId) {
|
|
59
|
+
return this._call('delete', `/collections/${collectionId}/products/${productId}`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.default = Collections;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { BooleanClause, NumberClause, StringClause, WhereClausesDto } from "../core/dto/clauses";
|
|
2
|
+
import { Sorting, SortingParamsDto } from "../core/dto/sorting";
|
|
3
|
+
import { QueryParamsDto } from "../core/utils/queryParams";
|
|
4
|
+
import { CreateImageDto, Image } from "../images/types";
|
|
5
|
+
import { CreateProductCollectionDto, Product, ProductCollection, ProductImage } from "../products/types";
|
|
6
|
+
import { Metafield, OmitRequire, Translation, WithRelation } from "../types";
|
|
7
|
+
export type Collection = {
|
|
8
|
+
id: number;
|
|
9
|
+
slug: string;
|
|
10
|
+
title: string;
|
|
11
|
+
subtitle: string | null;
|
|
12
|
+
description: string | null;
|
|
13
|
+
translations: Translation[];
|
|
14
|
+
metafields: Metafield[];
|
|
15
|
+
published: boolean;
|
|
16
|
+
position: number | null;
|
|
17
|
+
allowChildren: boolean;
|
|
18
|
+
parentId: number | null;
|
|
19
|
+
createdAt: Date;
|
|
20
|
+
updatedAt: Date;
|
|
21
|
+
};
|
|
22
|
+
export type CollectionImage = {
|
|
23
|
+
collectionId: number;
|
|
24
|
+
imageId: number;
|
|
25
|
+
locale: string | null;
|
|
26
|
+
position: number | null;
|
|
27
|
+
createdAt: Date;
|
|
28
|
+
updatedAt: Date;
|
|
29
|
+
};
|
|
30
|
+
export type CreateCollectionDto = OmitRequire<Collection, 'id' | 'createdAt' | 'updatedAt' | 'slug', 'title'> & {
|
|
31
|
+
products?: number[];
|
|
32
|
+
};
|
|
33
|
+
export type UpdateCollectionDto = Partial<Omit<CreateCollectionDto, 'products'>>;
|
|
34
|
+
export type SortingCollectionDto = SortingParamsDto<{
|
|
35
|
+
title?: Sorting;
|
|
36
|
+
published?: Sorting;
|
|
37
|
+
position?: Sorting;
|
|
38
|
+
}>;
|
|
39
|
+
export type ClausesCollectionDto = WhereClausesDto<{
|
|
40
|
+
title?: StringClause;
|
|
41
|
+
subtitle?: StringClause;
|
|
42
|
+
description?: StringClause;
|
|
43
|
+
parentId?: NumberClause;
|
|
44
|
+
productId?: NumberClause;
|
|
45
|
+
published?: BooleanClause;
|
|
46
|
+
noParents?: BooleanClause;
|
|
47
|
+
allowChildren?: BooleanClause;
|
|
48
|
+
}>;
|
|
49
|
+
export type QueryCollectionDto = QueryParamsDto<SortingCollectionDto, ClausesCollectionDto>;
|
|
50
|
+
export type FindAllCollectionDto = WithRelation<Collection, 'CollectionImage', WithRelation<CollectionImage, 'Image', Image>[]>;
|
|
51
|
+
export type CreateCollectionImageDto = OmitRequire<CollectionImage, 'collectionId' | 'createdAt' | 'updatedAt' | 'imageId'> & CreateImageDto;
|
|
52
|
+
export type UpdateCollectionImageDto = Omit<CreateCollectionImageDto, 'file'>;
|
|
53
|
+
export type CreateProductOnCollectionDto = Omit<CreateProductCollectionDto, 'collectionId'>;
|
|
54
|
+
export type FindAllCollectionProductsDto = WithRelation<ProductCollection, 'Product', WithRelation<Product, 'ProductImage', WithRelation<ProductImage, 'Image', Image>[]>>;
|
|
55
|
+
export type QueryCollectionProductsDto = Omit<QueryParamsDto<SortingParamsDto<{}>, WhereClausesDto<{
|
|
56
|
+
productAttributeValueId?: NumberClause;
|
|
57
|
+
}>>, 'sorting'>;
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ApiVersion, WithRequired } from "./types";
|
|
2
|
+
export type ApiConfigs = {
|
|
3
|
+
host: string;
|
|
4
|
+
credentials?: {
|
|
5
|
+
accessToken?: string;
|
|
6
|
+
apiToken?: string;
|
|
7
|
+
};
|
|
8
|
+
version?: ApiVersion;
|
|
9
|
+
sandbox?: boolean;
|
|
10
|
+
disableCache?: boolean;
|
|
11
|
+
};
|
|
12
|
+
export type ValidatedApiConfigs = ApiConfigs & WithRequired<ApiConfigs, 'version' | 'sandbox'>;
|
|
13
|
+
export declare function validateConfigs(configs: ApiConfigs): ValidatedApiConfigs;
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateConfigs = validateConfigs;
|
|
4
|
+
const error_1 = require("./error");
|
|
5
|
+
const types_1 = require("./types");
|
|
6
|
+
function validateConfigs(configs) {
|
|
7
|
+
var _a, _b, _c;
|
|
8
|
+
if (!configs.host)
|
|
9
|
+
throw new error_1.ConfigError(`Host is required`);
|
|
10
|
+
if (configs.version && !types_1.SUPPORTED_API_VERSIONS.includes(configs.version))
|
|
11
|
+
throw new error_1.ConfigError(`Version ${configs.version} is not supported anymore`);
|
|
12
|
+
if (configs.credentials && !configs.credentials.apiToken && !configs.credentials.accessToken)
|
|
13
|
+
throw new error_1.ConfigError(`Credentials are required`);
|
|
14
|
+
return {
|
|
15
|
+
...configs,
|
|
16
|
+
version: (_a = configs.version) !== null && _a !== void 0 ? _a : types_1.LATEST_API_VERSION,
|
|
17
|
+
sandbox: (_b = configs.sandbox) !== null && _b !== void 0 ? _b : false,
|
|
18
|
+
disableCache: (_c = configs.disableCache) !== null && _c !== void 0 ? _c : false
|
|
19
|
+
};
|
|
20
|
+
}
|