@veritree/services 2.56.0 → 2.58.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/index.js CHANGED
@@ -41,6 +41,7 @@ import { Organizations } from './src/endpoints/organizations';
41
41
  import { Tasks } from './src/endpoints/tasks';
42
42
  import { Geometries } from './src/endpoints/geometries';
43
43
  import { Password } from './src/endpoints/password';
44
+ import { TreeCodes } from './src/endpoints/tree-codes';
44
45
 
45
46
  export {
46
47
  BulkUploads,
@@ -86,4 +87,5 @@ export {
86
87
  Tasks,
87
88
  Geometries,
88
89
  Password,
90
+ TreeCodes
89
91
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veritree/services",
3
- "version": "2.56.0",
3
+ "version": "2.58.0",
4
4
  "description": "A collection of javascript functions/services to talk to veritree API",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -0,0 +1,95 @@
1
+ import Api from "../helpers/api";
2
+
3
+ class TreeCodesApi extends Api {
4
+ constructor(resource) {
5
+ super(resource);
6
+ this.resource = "tree-codes";
7
+ }
8
+
9
+ /**
10
+ * @private
11
+ * Constructs the URL for fetching items (campaigns, recipes, etc.) associated with a specific organization, sponsor, or reseller.
12
+ *
13
+ * @param {string} orgType - The shortened identifier for the organization type (o, s, r).
14
+ * @param {string} orgPublicId - The public identifier of the organization.
15
+ * @param {string} item - The specific item (campaigns, recipes, etc.) to fetch.
16
+ * @param {Object} params - Additional parameters for the API request.
17
+ * @returns {string} The constructed URL.
18
+ */
19
+ _constructFetchUrl(orgType, orgPublicId, item, params) {
20
+ return `${this.baseUrl}/${orgType}/${orgPublicId}/${
21
+ this.resource
22
+ }/${item}${this.getUrlParams(params)}`;
23
+ }
24
+
25
+ /**
26
+ * @param {string} orgType - Shortened organization type code (o, s, or r).
27
+ * @param {string} orgPublicId - Public ID of the organization.
28
+ * @param {object} params - Optional query parameters.
29
+ * @returns {object} - An object with a method 'all' that, when called, fetches all campaign data.
30
+ */
31
+ campaigns(orgType, orgPublicId, params) {
32
+ const url = this._constructFetchUrl(
33
+ orgType,
34
+ orgPublicId,
35
+ "campaigns",
36
+ params
37
+ );
38
+
39
+ /**
40
+ * Fetches campaign data
41
+ */
42
+ const all = async () => {
43
+ return await this.get(url);
44
+ }
45
+
46
+ const create = async (data) => {
47
+ return await this.post(url, data);
48
+ }
49
+
50
+ return {
51
+ all,
52
+ create
53
+ };
54
+ }
55
+
56
+ /**
57
+ * @param {string} orgType - The shortened identifier for the organization type (o, s, r).
58
+ * @param {string} orgPublicId - The public identifier of the organization.
59
+ * @param {Object} params - Additional parameters for the API request.
60
+ * @returns {Object} An object with a method 'all' to initiate the API request and retrieve recipes based on the provided parameters.
61
+ */
62
+ recipes(orgType, orgPublicId, params) {
63
+ const url = this._constructFetchUrl(
64
+ orgType,
65
+ orgPublicId,
66
+ "recipes",
67
+ params
68
+ );
69
+
70
+ /**
71
+ * Fetches recipes data
72
+ */
73
+ const all = async () => {
74
+ return await this.get(url);
75
+ }
76
+
77
+ return {
78
+ all,
79
+ };
80
+ }
81
+
82
+ ingredients(recipePubliId, params) {
83
+ const url = `${this.getUrl()}/recipes/${recipePubliId}/ingredients${this.getUrlParams(params)}`;
84
+
85
+ const all = async () => {
86
+ return await this.get(url);
87
+ }
88
+
89
+ return {
90
+ all,
91
+ };
92
+ }
93
+ }
94
+
95
+ export const TreeCodes = new TreeCodesApi();