@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 CHANGED
@@ -1,20 +1,20 @@
1
- import { Countries } from './src/services/countries';
2
- import { FieldUpdates } from './src/services/field-updates';
3
- import { FieldUpdateVerifications } from './src/services/field-udpate-verifications';
4
- import { FormSubmissions } from './src/services/form-submissions';
5
- import { ForestTypeSpecies } from './src/services/forest-type-species';
6
- import { ForestTypes } from './src/services/forest-types';
7
- import { ForestTypeProfiles } from './src/services/forest-types-profiles';
8
- import { Images } from './src/services/images';
9
- import { User } from './src/services/user';
10
- import { Orgs } from './src/services/orgs';
11
- import { Regions } from './src/services/regions';
12
- import { Sponsors } from './src/services/sponsors';
13
- import { Stats } from './src/services/stats';
14
- import { Subdomains } from './src/services/subdomains';
15
- import { Subsites } from './src/services/subsites';
16
- import { SubsiteTypes } from './src/services/subsite-types';
17
- import { TreeOrders } from './src/services/trees-orders';
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veritree/services",
3
- "version": "1.0.0-5",
3
+ "version": "1.0.0-6",
4
4
  "description": "A collection of javascript functions/services to talk to veritree API",
5
5
  "type": "module",
6
6
  "main": "index.js",
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
@@ -1,5 +1,6 @@
1
1
  import Api from '../helpers/api';
2
2
 
3
3
  const resource = 'tree-orders';
4
+
4
5
  export const TreeOrders = new Api(resource);
5
6
 
File without changes
@@ -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
- const orgIdParam = this.orgId ? `org_id=${this.orgId}` : "";
83
- const orgTypeParam = this.orgType ? `org_type=${this.orgType}` : "";
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 = this.handleEnvelopParam(url, data); // TODO: remove when API is fully migrated to envelopes
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 = this.isFormData(data);
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
  }
@@ -1,7 +1,3 @@
1
- export const getSessionOrgId = () => {
2
- return getSession().orgId;
3
- };
4
-
5
1
  export const getSession = () => {
6
2
  return JSON.parse(localStorage.getItem('session'));
7
3
  };