@veritree/services 1.0.0-5 → 1.0.0-6
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/index.js +17 -17
- package/package.json +1 -1
- package/src/{services → endpoints}/countries.js +0 -0
- package/src/{services → endpoints}/field-udpate-verifications.js +0 -0
- package/src/{services → endpoints}/field-updates.js +0 -0
- package/src/{services → endpoints}/forest-type-species.js +0 -0
- package/src/{services → endpoints}/forest-types-profiles.js +0 -0
- package/src/{services → endpoints}/forest-types.js +0 -0
- package/src/{services → endpoints}/form-submissions.js +0 -0
- package/src/{services → endpoints}/images.js +0 -0
- package/src/{services → endpoints}/orgs.js +0 -0
- package/src/{services → endpoints}/regions.js +0 -0
- package/src/{services → endpoints}/sponsors.js +0 -0
- package/src/{services → endpoints}/stats.js +0 -0
- package/src/{services → endpoints}/subdomains.js +0 -0
- package/src/{services → endpoints}/subsite-types.js +0 -0
- package/src/{services → endpoints}/subsites.js +0 -0
- package/src/{services → endpoints}/trees-orders.js +1 -0
- package/src/{services → endpoints}/user.js +0 -0
- package/src/helpers/api.js +29 -23
- package/src/helpers/session.js +0 -4
package/index.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { Countries } from './src/
|
|
2
|
-
import { FieldUpdates } from './src/
|
|
3
|
-
import { FieldUpdateVerifications } from './src/
|
|
4
|
-
import { FormSubmissions } from './src/
|
|
5
|
-
import { ForestTypeSpecies } from './src/
|
|
6
|
-
import { ForestTypes } from './src/
|
|
7
|
-
import { ForestTypeProfiles } from './src/
|
|
8
|
-
import { Images } from './src/
|
|
9
|
-
import { User } from './src/
|
|
10
|
-
import { Orgs } from './src/
|
|
11
|
-
import { Regions } from './src/
|
|
12
|
-
import { Sponsors } from './src/
|
|
13
|
-
import { Stats } from './src/
|
|
14
|
-
import { Subdomains } from './src/
|
|
15
|
-
import { Subsites } from './src/
|
|
16
|
-
import { SubsiteTypes } from './src/
|
|
17
|
-
import { TreeOrders } from './src/
|
|
1
|
+
import { Countries } from './src/endpoints/countries';
|
|
2
|
+
import { FieldUpdates } from './src/endpoints/field-updates';
|
|
3
|
+
import { FieldUpdateVerifications } from './src/endpoints/field-udpate-verifications';
|
|
4
|
+
import { FormSubmissions } from './src/endpoints/form-submissions';
|
|
5
|
+
import { ForestTypeSpecies } from './src/endpoints/forest-type-species';
|
|
6
|
+
import { ForestTypes } from './src/endpoints/forest-types';
|
|
7
|
+
import { ForestTypeProfiles } from './src/endpoints/forest-types-profiles';
|
|
8
|
+
import { Images } from './src/endpoints/images';
|
|
9
|
+
import { User } from './src/endpoints/user';
|
|
10
|
+
import { Orgs } from './src/endpoints/orgs';
|
|
11
|
+
import { Regions } from './src/endpoints/regions';
|
|
12
|
+
import { Sponsors } from './src/endpoints/sponsors';
|
|
13
|
+
import { Stats } from './src/endpoints/stats';
|
|
14
|
+
import { Subdomains } from './src/endpoints/subdomains';
|
|
15
|
+
import { Subsites } from './src/endpoints/subsites';
|
|
16
|
+
import { SubsiteTypes } from './src/endpoints/subsite-types';
|
|
17
|
+
import { TreeOrders } from './src/endpoints/trees-orders';
|
|
18
18
|
|
|
19
19
|
export {
|
|
20
20
|
Countries,
|
package/package.json
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/src/helpers/api.js
CHANGED
|
@@ -2,6 +2,21 @@ import { getCookie } from "./cookies";
|
|
|
2
2
|
import { createParamsStringFromArgs } from "../utils/args";
|
|
3
3
|
import { getSession } from "./session";
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Adds the envelope argument to the url
|
|
7
|
+
*
|
|
8
|
+
* @param {string} url
|
|
9
|
+
* @returns {string} url
|
|
10
|
+
*/
|
|
11
|
+
function handleEnvelopParam(url) {
|
|
12
|
+
if (!url || url.includes("_result=1")) return url;
|
|
13
|
+
|
|
14
|
+
const urlHasArgs = url.includes("?");
|
|
15
|
+
const urlEvenlopeArg = urlHasArgs ? "&_result=1" : "?_result=1";
|
|
16
|
+
|
|
17
|
+
return `${url}${urlEvenlopeArg}`;
|
|
18
|
+
}
|
|
19
|
+
|
|
5
20
|
export default class Api {
|
|
6
21
|
constructor(resource) {
|
|
7
22
|
this.baseUrl = `${process.env.API_VERITREE_URL}/api`;
|
|
@@ -78,9 +93,19 @@ export default class Api {
|
|
|
78
93
|
|
|
79
94
|
getUrlParams(args) {
|
|
80
95
|
this.setOrg();
|
|
96
|
+
let isOrgLess = false;
|
|
97
|
+
let orgIdParam = "";
|
|
98
|
+
let orgTypeParam = "";
|
|
99
|
+
|
|
100
|
+
// while most of endpoints require an org id and type, some endpoints do not
|
|
101
|
+
if (args && args.length) {
|
|
102
|
+
isOrgLess = Object.hasOwnProperty.call(...args, "orgless");
|
|
103
|
+
}
|
|
81
104
|
|
|
82
|
-
|
|
83
|
-
|
|
105
|
+
if (!isOrgLess) {
|
|
106
|
+
if (this.orgId) orgIdParam = `&org_id=${this.orgId}`;
|
|
107
|
+
if (this.orgType) orgTypeParam = `&org_type=${this.orgType}`;
|
|
108
|
+
}
|
|
84
109
|
|
|
85
110
|
return `?${orgIdParam}&${orgTypeParam}${createParamsStringFromArgs(args)}`;
|
|
86
111
|
}
|
|
@@ -94,7 +119,7 @@ export default class Api {
|
|
|
94
119
|
* @returns {object} envelope
|
|
95
120
|
*/
|
|
96
121
|
async unWrap(url, method = "get", data, as) {
|
|
97
|
-
url =
|
|
122
|
+
url = handleEnvelopParam(url, data); // TODO: remove when API is fully migrated to envelopes
|
|
98
123
|
const config = this.getConfig(method, data, as);
|
|
99
124
|
|
|
100
125
|
try {
|
|
@@ -117,7 +142,7 @@ export default class Api {
|
|
|
117
142
|
getConfig(method, data, as) {
|
|
118
143
|
const isGet = method === "get";
|
|
119
144
|
const isPut = as === "put";
|
|
120
|
-
const isFormData =
|
|
145
|
+
const isFormData = data instanceof FormData;
|
|
121
146
|
const accessToken = `Bearer ${getCookie("access_token")}`;
|
|
122
147
|
|
|
123
148
|
const config = {
|
|
@@ -152,23 +177,4 @@ export default class Api {
|
|
|
152
177
|
this.orgId = orgId;
|
|
153
178
|
this.orgType = orgType;
|
|
154
179
|
}
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Adds the envelope argument to the url
|
|
158
|
-
*
|
|
159
|
-
* @param {string} url
|
|
160
|
-
* @returns {string} url
|
|
161
|
-
*/
|
|
162
|
-
handleEnvelopParam(url) {
|
|
163
|
-
if (!url || url.includes("_result=1")) return url;
|
|
164
|
-
|
|
165
|
-
const urlHasArgs = url.includes("?");
|
|
166
|
-
const urlEvenlopeArg = urlHasArgs ? "&_result=1" : "?_result=1";
|
|
167
|
-
|
|
168
|
-
return `${url}${urlEvenlopeArg}`;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
isFormData(data) {
|
|
172
|
-
data instanceof FormData;
|
|
173
|
-
}
|
|
174
180
|
}
|