UNPKG

5.66 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.getApplication = getApplication;
7exports.getApplicationSource = getApplicationSource;
8exports.getApplicationProtections = getApplicationProtections;
9exports.getApplicationProtectionsCount = getApplicationProtectionsCount;
10exports.getTemplates = getTemplates;
11exports.getApplications = getApplications;
12exports.getProtection = getProtection;
13var getApplicationDefaultFragments = '\n _id,\n name,\n createdAt,\n sources {\n _id,\n filename,\n extension\n }\n';
14/**
15 * Return one application by id.
16 * The options params argument can be used to filter protections by version and limit the number of protections returned.
17 * @param {String} id the application id
18 * @param {fragment} fragments GraphQL fragment
19 * @param {Array} params {{String}protectionsVersion, {Integer} protectionsNumber}
20 */
21function getApplication(applicationId) {
22 var fragments = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : getApplicationDefaultFragments;
23 var params = arguments[2];
24
25 return {
26 query: '\n query getApplication ($applicationId: String!, $protectionsVersion: String, $protectionsLimit: Int) {\n application(_id: $applicationId, protectionsVersion: $protectionsVersion, protectionsLimit: $protectionsLimit) {\n ' + fragments + '\n }\n }\n ',
27 params: JSON.stringify(Object.assign({
28 applicationId: applicationId
29 }, params))
30 };
31}
32
33var getApplicationSourceDefaultFragments = '\n _id,\n filename,\n extension\n';
34
35function getApplicationSource(sourceId) {
36 var fragments = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : getApplicationSourceDefaultFragments;
37 var limits = arguments[2];
38
39 return {
40 query: '\n query getApplicationSource ($sourceId: String!, $contentLimit: Int, $transformedLimit: Int) {\n applicationSource(_id: $sourceId, contentLimit: $contentLimit, transformedLimit: $transformedLimit) {\n ' + fragments + '\n }\n }\n ',
41 params: JSON.stringify(Object.assign({
42 sourceId: sourceId
43 }, limits))
44 };
45}
46
47var getApplicationProtectionsDefaultFragments = '\n _id,\n sources,\n parameters,\n finishedAt,\n randomizationSeed\n';
48
49function getApplicationProtections(applicationId, params) {
50 var fragments = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : getApplicationProtectionsDefaultFragments;
51
52 return {
53 query: '\n query getApplicationProtections ($applicationId: String!, $sort: String, $order: String, $limit: Int, $page: Int) {\n applicationProtections(_id: $applicationId, sort: $sort, order: $order, limit: $limit, page: $page) {\n ' + fragments + '\n }\n }\n ',
54 params: JSON.stringify(Object.assign({
55 applicationId: applicationId
56 }, params))
57 };
58}
59
60var getApplicationProtectionsCountDefaultFragments = '\n count\n';
61
62function getApplicationProtectionsCount(applicationId) {
63 var fragments = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : getApplicationProtectionsCountDefaultFragments;
64
65 return {
66 query: '\n query getApplicationProtectionsCount ($applicationId: String!) {\n applicationProtectionsCount(_id: $applicationId) {\n ' + fragments + '\n }\n }\n ',
67 params: JSON.stringify({
68 applicationId: applicationId
69 })
70 };
71}
72
73var getTemplatesDefaultFragments = '\n _id,\n parameters\n';
74
75function getTemplates() {
76 var fragments = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getTemplatesDefaultFragments;
77
78 return {
79 query: '\n query getTemplates {\n templates {\n ' + fragments + '\n }\n }\n ',
80 params: '{}'
81 };
82}
83
84var getApplicationsDefaultFragments = '\n _id,\n name,\n protections,\n parameters\n';
85/**
86 * Return all applications.
87 * The options params argument can be used to filter protections by version and limit the number of protections returned.
88 * @param {fragment} fragments GraphQL fragment
89 * @param {Array} params {{String}protectionsVersion, {Integer} protectionsNumber}
90 */
91function getApplications() {
92 var fragments = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getApplicationsDefaultFragments;
93 var params = arguments[1];
94
95 return {
96 query: '\n query getApplications($protectionsVersion:String, $protectionsLimit: Int) {\n applications(protectionsVersion: $protectionsVersion, protectionsLimit: $protectionsLimit) {\n ' + fragments + '\n }\n }\n ',
97 params: JSON.stringify(Object.assign({}, params))
98 };
99}
100
101var getProtectionDefaultFragments = {
102 application: '\n name\n ',
103 applicationProtection: '\n _id,\n state,\n bail,\n deprecations {\n type,\n entity\n },\n errorMessage,\n sources {\n filename,\n errorMessages {\n message,\n line,\n column,\n fatal\n }\n }\n '
104};
105
106function getProtection(applicationId, protectionId) {
107 var fragments = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : getProtectionDefaultFragments;
108
109 return {
110 query: '\n query getProtection ($applicationId: String!, $protectionId: String!) {\n application (_id: $applicationId) {\n ' + fragments.application + '\n }\n applicationProtection (_id: $protectionId) {\n ' + fragments.applicationProtection + '\n }\n }\n ',
111 params: JSON.stringify({
112 applicationId: applicationId,
113 protectionId: protectionId
114 })
115 };
116}
\No newline at end of file