emissions-api-sdk 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/CODE_OF_CONDUCT.md +76 -0
- package/CONTRIBUTING.md +68 -0
- package/LICENSE +201 -0
- package/MAINTAINERS.md +10 -0
- package/README.md +89 -0
- package/dist/Client.js +227 -0
- package/dist/Constants.js +19 -0
- package/dist/api/Calculation.js +41 -0
- package/dist/api/Factor.js +79 -0
- package/dist/api/FactorSets.js +24 -0
- package/dist/api/Factors.js +98 -0
- package/dist/api/Fugitive.js +40 -0
- package/dist/api/FugitiveEmission.js +40 -0
- package/dist/api/GenericCalculation.js +41 -0
- package/dist/api/Location.js +41 -0
- package/dist/api/LocationEmission.js +41 -0
- package/dist/api/Mobile.js +41 -0
- package/dist/api/MobileEmission.js +41 -0
- package/dist/api/Stationary.js +41 -0
- package/dist/api/StationaryEmission.js +41 -0
- package/dist/api/TransportationAndDistribution.js +40 -0
- package/dist/api/TransportationDistributionEmission.js +40 -0
- package/dist/coverage/clover.xml +225 -0
- package/dist/coverage/coverage-final.json +19 -0
- package/dist/coverage/lcov-report/base.css +224 -0
- package/dist/coverage/lcov-report/block-navigation.js +87 -0
- package/dist/coverage/lcov-report/favicon.png +0 -0
- package/dist/coverage/lcov-report/index.html +161 -0
- package/dist/coverage/lcov-report/prettify.css +1 -0
- package/dist/coverage/lcov-report/prettify.js +2 -0
- package/dist/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/dist/coverage/lcov-report/sorter.js +210 -0
- package/dist/coverage/lcov-report/src/Client.ts.html +838 -0
- package/dist/coverage/lcov-report/src/Constants.ts.html +130 -0
- package/dist/coverage/lcov-report/src/api/Calculation.ts.html +217 -0
- package/dist/coverage/lcov-report/src/api/Factor.ts.html +343 -0
- package/dist/coverage/lcov-report/src/api/FactorSets.ts.html +154 -0
- package/dist/coverage/lcov-report/src/api/Factors.ts.html +403 -0
- package/dist/coverage/lcov-report/src/api/Fugitive.ts.html +214 -0
- package/dist/coverage/lcov-report/src/api/FugitiveEmission.ts.html +214 -0
- package/dist/coverage/lcov-report/src/api/GenericCalculation.ts.html +217 -0
- package/dist/coverage/lcov-report/src/api/Location.ts.html +214 -0
- package/dist/coverage/lcov-report/src/api/LocationEmission.ts.html +214 -0
- package/dist/coverage/lcov-report/src/api/Mobile.ts.html +220 -0
- package/dist/coverage/lcov-report/src/api/MobileEmission.ts.html +220 -0
- package/dist/coverage/lcov-report/src/api/Stationary.ts.html +220 -0
- package/dist/coverage/lcov-report/src/api/StationaryEmission.ts.html +220 -0
- package/dist/coverage/lcov-report/src/api/TransportationAndDistribution.ts.html +211 -0
- package/dist/coverage/lcov-report/src/api/TransportationDistributionEmission.ts.html +211 -0
- package/dist/coverage/lcov-report/src/api/index.html +221 -0
- package/dist/coverage/lcov-report/src/index.html +161 -0
- package/dist/coverage/lcov-report/src/request.ts.html +235 -0
- package/dist/coverage/lcov-report/src/utils.ts.html +139 -0
- package/dist/coverage/lcov-report/test/index.html +116 -0
- package/dist/coverage/lcov-report/test/mocks/CommonRequest.ts.html +142 -0
- package/dist/coverage/lcov-report/test/mocks/FactorRequest.ts.html +133 -0
- package/dist/coverage/lcov-report/test/mocks/GenericCalculationRequest.ts.html +142 -0
- package/dist/coverage/lcov-report/test/mocks/LocationRequest.ts.html +139 -0
- package/dist/coverage/lcov-report/test/mocks/SearchRequest.ts.html +142 -0
- package/dist/coverage/lcov-report/test/mocks/index.html +176 -0
- package/dist/coverage/lcov-report/test/testUtils.ts.html +97 -0
- package/dist/coverage/lcov.info +404 -0
- package/dist/index.js +46 -0
- package/dist/interfaces/Api.js +2 -0
- package/dist/interfaces/Config.js +2 -0
- package/dist/interfaces/common.js +2 -0
- package/dist/request.js +51 -0
- package/dist/types/Client.d.ts +146 -0
- package/dist/types/Constants.d.ts +16 -0
- package/dist/types/api/Calculation.d.ts +28 -0
- package/dist/types/api/Factor.d.ts +57 -0
- package/dist/types/api/FactorSets.d.ts +11 -0
- package/dist/types/api/Factors.d.ts +68 -0
- package/dist/types/api/Fugitive.d.ts +27 -0
- package/dist/types/api/FugitiveEmission.d.ts +27 -0
- package/dist/types/api/GenericCalculation.d.ts +28 -0
- package/dist/types/api/Location.d.ts +28 -0
- package/dist/types/api/LocationEmission.d.ts +28 -0
- package/dist/types/api/Mobile.d.ts +28 -0
- package/dist/types/api/MobileEmission.d.ts +28 -0
- package/dist/types/api/Stationary.d.ts +28 -0
- package/dist/types/api/StationaryEmission.d.ts +28 -0
- package/dist/types/api/TransportationAndDistribution.d.ts +27 -0
- package/dist/types/api/TransportationDistributionEmission.d.ts +27 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/interfaces/Api.d.ts +286 -0
- package/dist/types/interfaces/Config.d.ts +66 -0
- package/dist/types/interfaces/common.d.ts +152 -0
- package/dist/types/request.d.ts +25 -0
- package/dist/types/utils.d.ts +14 -0
- package/dist/utils.js +23 -0
- package/jest.config.js +9 -0
- package/package.json +50 -0
- package/src/Client.ts +252 -0
- package/src/Constants.ts +16 -0
- package/src/api/Calculation.ts +44 -0
- package/src/api/Factor.ts +86 -0
- package/src/api/FactorSets.ts +24 -0
- package/src/api/Fugitive.ts +43 -0
- package/src/api/Location.ts +43 -0
- package/src/api/Mobile.ts +45 -0
- package/src/api/Stationary.ts +45 -0
- package/src/api/TransportationAndDistribution.ts +42 -0
- package/src/index.ts +10 -0
- package/src/interfaces/Api.ts +300 -0
- package/src/interfaces/Config.ts +78 -0
- package/src/interfaces/common.ts +174 -0
- package/src/request.ts +50 -0
- package/src/utils.ts +19 -0
- package/test/apiTest.test.ts +168 -0
- package/test/client.test.ts +82 -0
- package/test/mocks/CommonRequest.ts +19 -0
- package/test/mocks/FactorRequest.ts +16 -0
- package/test/mocks/GenericCalculationRequest.ts +19 -0
- package/test/mocks/LocationRequest.ts +19 -0
- package/test/mocks/SearchRequest.ts +19 -0
- package/test/request.test.ts +111 -0
- package/test/testUtils.ts +5 -0
- package/test/tokenRefresh.test.ts +52 -0
- package/tsconfig.json +15 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
+
size, disability, ethnicity, sex characteristics, gender identity and expression,
|
|
9
|
+
level of experience, education, socio-economic status, nationality, personal
|
|
10
|
+
appearance, race, religion, or sexual identity and orientation.
|
|
11
|
+
|
|
12
|
+
## Our Standards
|
|
13
|
+
|
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
|
15
|
+
include:
|
|
16
|
+
|
|
17
|
+
* Using welcoming and inclusive language
|
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
|
19
|
+
* Gracefully accepting constructive criticism
|
|
20
|
+
* Focusing on what is best for the community
|
|
21
|
+
* Showing empathy towards other community members
|
|
22
|
+
|
|
23
|
+
Examples of unacceptable behavior by participants include:
|
|
24
|
+
|
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
+
advances
|
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
28
|
+
* Public or private harassment
|
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
|
30
|
+
address, without explicit permission
|
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
+
professional setting
|
|
33
|
+
|
|
34
|
+
## Our Responsibilities
|
|
35
|
+
|
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
+
response to any instances of unacceptable behavior.
|
|
39
|
+
|
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
+
threatening, offensive, or harmful.
|
|
45
|
+
|
|
46
|
+
## Scope
|
|
47
|
+
|
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
+
when an individual is representing the project or its community. Examples of
|
|
50
|
+
representing a project or community include using an official project e-mail
|
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
|
53
|
+
further defined and clarified by project maintainers.
|
|
54
|
+
|
|
55
|
+
## Enforcement
|
|
56
|
+
|
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
+
reported by contacting the [project team](./MAINTAINERS.md). All
|
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
|
63
|
+
|
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
+
members of the project's leadership.
|
|
67
|
+
|
|
68
|
+
## Attribution
|
|
69
|
+
|
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
+
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
|
|
72
|
+
|
|
73
|
+
[homepage]: https://www.contributor-covenant.org
|
|
74
|
+
|
|
75
|
+
For answers to common questions about this code of conduct, see
|
|
76
|
+
https://www.contributor-covenant.org/faq
|
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
## Contributing In General
|
|
2
|
+
Our project welcomes external contributions. If you have an itch, please feel
|
|
3
|
+
free to scratch it.
|
|
4
|
+
|
|
5
|
+
To contribute notebooks or documentation, please submit a [pull request](https://github.com/IBM/ibm-envizi-emissions-api-nodejs-sdk/pulls).
|
|
6
|
+
|
|
7
|
+
A good way to familiarize yourself with the notebooks and contribution process is
|
|
8
|
+
to look for an issue in the [issue tracker](https://github.com/IBM/ibm-envizi-emissions-api-nodejs-sdk/issues).
|
|
9
|
+
|
|
10
|
+
Before embarking on a more ambitious contribution, please [raise an issue](https://github.com/IBM/ibm-envizi-emissions-api-nodejs-sdk/issues).
|
|
11
|
+
|
|
12
|
+
**Note: We appreciate your effort, and want to avoid a situation where a contribution
|
|
13
|
+
requires extensive rework (by you or by us), sits in backlog for a long time, or
|
|
14
|
+
cannot be accepted at all!**
|
|
15
|
+
|
|
16
|
+
### Proposing new features
|
|
17
|
+
|
|
18
|
+
If you would like to add a new notebook, please [raise an issue](https://github.com/IBM/ibm-envizi-emissions-api-nodejs-sdk/issues)
|
|
19
|
+
before sending a pull request so the contribution can be discussed.
|
|
20
|
+
|
|
21
|
+
### Fixing bugs
|
|
22
|
+
|
|
23
|
+
If you would like to fix a bug, please [raise an issue](https://github.com/IBM/ibm-envizi-emissions-api-nodejs-sdk/issues) before sending a
|
|
24
|
+
pull request so it can be tracked.
|
|
25
|
+
|
|
26
|
+
### Merge approval
|
|
27
|
+
|
|
28
|
+
The project maintainers use LGTM (Looks Good To Me) in comments on the code
|
|
29
|
+
review to indicate acceptance. A change requires a LGTM from a repository maintainer
|
|
30
|
+
or from a notebook maintainer (in the area of the contribution).
|
|
31
|
+
|
|
32
|
+
For a list of the maintainers, see the [MAINTAINERS.md](MAINTAINERS.md) page.
|
|
33
|
+
|
|
34
|
+
## Legal
|
|
35
|
+
|
|
36
|
+
Each source file must include a license header for the Apache
|
|
37
|
+
Software License 2.0. Using the SPDX format is the simplest approach.
|
|
38
|
+
e.g.
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
/*
|
|
42
|
+
Copyright <holder> All Rights Reserved.
|
|
43
|
+
|
|
44
|
+
SPDX-License-Identifier: Apache-2.0
|
|
45
|
+
*/
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
We have tried to make it as easy as possible to make contributions. This
|
|
49
|
+
applies to how we handle the legal aspects of contribution. We use the
|
|
50
|
+
same approach - the [Developer's Certificate of Origin 1.1 (DCO)](https://github.com/hyperledger/fabric/blob/master/docs/source/DCO1.1.txt) - that the Linux® Kernel [community](https://elinux.org/Developer_Certificate_Of_Origin)
|
|
51
|
+
uses to manage code contributions.
|
|
52
|
+
|
|
53
|
+
We simply ask that when submitting a patch for review, the developer
|
|
54
|
+
must include a sign-off statement in the commit message.
|
|
55
|
+
|
|
56
|
+
Here is an example Signed-off-by line, which indicates that the
|
|
57
|
+
submitter accepts the DCO:
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
Signed-off-by: John Doe <john.doe@example.com>
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
You can include this automatically when you commit a change to your
|
|
64
|
+
local git repository using the following command:
|
|
65
|
+
|
|
66
|
+
```
|
|
67
|
+
git commit -s
|
|
68
|
+
```
|
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/MAINTAINERS.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# MAINTAINERS
|
|
2
|
+
|
|
3
|
+
This project relates to [IBM Envizi - Emissions API](https://www.ibm.com/products/envizi)- maintained by IBM Software.
|
|
4
|
+
|
|
5
|
+
Repository Maintainers:
|
|
6
|
+
- Steffan J. Taylor (taylorsteffanj)
|
|
7
|
+
- Santhosh Ramalingam T (santhosh0703)
|
|
8
|
+
- Prakhar Sahu (prakhar-sahu)
|
|
9
|
+
|
|
10
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# IBM Envizi - Emissions API Node.js SDK
|
|
2
|
+
|
|
3
|
+
IBM Envizi - Emissions API (Emissions API) is a managed factor database and calculation engine for embedding greenhouse gas (GHG) emissions calculations into operational decision making.
|
|
4
|
+
|
|
5
|
+
The `emissions-api-sdk` is a Node.js SDK for using Emissions API in your projects.
|
|
6
|
+
|
|
7
|
+
## Sign up for the Preview
|
|
8
|
+
|
|
9
|
+
To get started with the Emissions API follow these steps:
|
|
10
|
+
|
|
11
|
+
- Sign up for the preview waitlist [IBMid sign up](https://www.ibm.com/account/reg/us-en/signup?formid=urx-53659) page.
|
|
12
|
+
- You will be sent an invite email to join to create an account.
|
|
13
|
+
- Read the [Introduction](https://developer.ibm.com/apis/catalog/ghgemissions--ibm-envizi-emissions-api/Introduction) page to get an overview of the Emissions API.
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install emissions-api-sdk
|
|
19
|
+
# or
|
|
20
|
+
yarn install emissions-api-sdk
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Quick Start
|
|
24
|
+
|
|
25
|
+
```javascript
|
|
26
|
+
import { Client, Location } from 'emissions-api-sdk';
|
|
27
|
+
|
|
28
|
+
// Initialize client
|
|
29
|
+
await Client.getClient({
|
|
30
|
+
apiKey: process.env.ENVIZI_API_KEY,
|
|
31
|
+
clientId: process.env.ENVIZI_CLIENT_ID,
|
|
32
|
+
orgId: process.env.ENVIZI_ORG_ID
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// Calculate emissions
|
|
36
|
+
const result = await Location.calculate({
|
|
37
|
+
"location": {
|
|
38
|
+
"country": "USA",
|
|
39
|
+
"stateProvince": "california"
|
|
40
|
+
},
|
|
41
|
+
"activity": {
|
|
42
|
+
"type": "electricity",
|
|
43
|
+
"value": 1,
|
|
44
|
+
"unit": "kWh"
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Authentication
|
|
50
|
+
|
|
51
|
+
The SDK supports two authentication methods:
|
|
52
|
+
|
|
53
|
+
### API Key (Recommended)
|
|
54
|
+
|
|
55
|
+
```javascript
|
|
56
|
+
await Client.getClient({
|
|
57
|
+
apiKey: process.env.ENVIZI_API_KEY,
|
|
58
|
+
clientId: process.env.ENVIZI_CLIENT_ID,
|
|
59
|
+
orgId: process.env.ENVIZI_ORG_ID
|
|
60
|
+
});
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Pre-generated Token
|
|
64
|
+
|
|
65
|
+
```javascript
|
|
66
|
+
await Client.getClient({
|
|
67
|
+
token: process.env.JWT_TOKEN,
|
|
68
|
+
clientId: process.env.ENVIZI_CLIENT_ID
|
|
69
|
+
});
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Documentation
|
|
73
|
+
|
|
74
|
+
For detailed [documentation](https://ibm.github.io/ibm-envizi-emissions-api-nodejs-sdk/), see:
|
|
75
|
+
|
|
76
|
+
- [Getting Started](https://ibm.github.io/ibm-envizi-emissions-api-nodejs-sdk/getting_started.html)
|
|
77
|
+
- [Authentication](https://ibm.github.io/ibm-envizi-emissions-api-nodejs-sdk/authentication.html)
|
|
78
|
+
- [Client Configuration](https://ibm.github.io/ibm-envizi-emissions-api-nodejs-sdk/client.html)
|
|
79
|
+
- [API Reference](https://ibm.github.io/ibm-envizi-emissions-api-nodejs-sdk/reference.html)
|
|
80
|
+
|
|
81
|
+
Other resources:
|
|
82
|
+
|
|
83
|
+
- [APIHub](https://developer.ibm.com/apis/catalog/ghgemissions--ibm-envizi-emissions-api/api/API--ghgemissions--authentication) - API documentation (OpenAPI)
|
|
84
|
+
- [Tutorials & Sample Applications](https://ibm.github.io/ibm-envizi-emissions-api/)
|
|
85
|
+
- [IBM Envizi for Excel](https://ibm.github.io/ibm-envizi-emissions-api-excel-addin) - Emissions API Excel Add-in.
|
|
86
|
+
|
|
87
|
+
## License
|
|
88
|
+
|
|
89
|
+
This project is licensed under the terms of the [LICENSE](LICENSE) file.
|
package/dist/Client.js
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Client = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const utils_1 = require("./utils");
|
|
9
|
+
const Constants_1 = require("./Constants");
|
|
10
|
+
class Client {
|
|
11
|
+
constructor(token, config, isUserProvidedToken = false) {
|
|
12
|
+
const { apiKey = "", clientId, orgId = "", host, authUrl, isExcelAddIn = false } = config;
|
|
13
|
+
this.token = token;
|
|
14
|
+
this.clientId = clientId;
|
|
15
|
+
if (isUserProvidedToken) {
|
|
16
|
+
this.apiKey = "";
|
|
17
|
+
this.orgId = "";
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
this.apiKey = apiKey;
|
|
21
|
+
this.orgId = orgId;
|
|
22
|
+
}
|
|
23
|
+
const exp = (0, utils_1.findExpiryTime)(token);
|
|
24
|
+
this.expiresAt = exp;
|
|
25
|
+
this.domain = host !== null && host !== void 0 ? host : Constants_1.API_DOMAIN;
|
|
26
|
+
this.tokenDomain = authUrl !== null && authUrl !== void 0 ? authUrl : Constants_1.TOKEN_GENERATION_API;
|
|
27
|
+
this.isUserProvidedToken = isUserProvidedToken;
|
|
28
|
+
this.clientSource = isExcelAddIn === true ? Constants_1.CLIENT_SOURCE_EXCEL : Constants_1.CLIENT_SOURCE_SDK;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Initializes and returns a Client instance with the provided configuration.
|
|
32
|
+
*
|
|
33
|
+
* @static
|
|
34
|
+
* @param {ClientConfig} config - The client configuration object
|
|
35
|
+
* @return {Promise<void>} A promise that resolves when the client is initialized
|
|
36
|
+
* @throws {Error} Throws an error if:
|
|
37
|
+
* - custom "host" is provided without "authUrl"
|
|
38
|
+
* - token is provided without "clientId"
|
|
39
|
+
* - apiKey is provided without "clientId" or "orgId"
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* // Initialize with authentication URL
|
|
43
|
+
* await Client.getClient({
|
|
44
|
+
* host: 'https://api.example.com',
|
|
45
|
+
* authUrl: 'https://auth.example.com',
|
|
46
|
+
* clientId: 'client123',
|
|
47
|
+
* orgId: 'org456'
|
|
48
|
+
* });
|
|
49
|
+
*
|
|
50
|
+
* // Initialize with existing token
|
|
51
|
+
* await Client.getClient({
|
|
52
|
+
* token: 'existing-jwt-token',
|
|
53
|
+
* clientId: 'client123'
|
|
54
|
+
* });
|
|
55
|
+
*
|
|
56
|
+
* // Initialize with API key
|
|
57
|
+
* await Client.getClient({
|
|
58
|
+
* apiKey: 'your-api-key',
|
|
59
|
+
* clientId: 'client123',
|
|
60
|
+
* orgId: 'org456'
|
|
61
|
+
* });
|
|
62
|
+
*/
|
|
63
|
+
static async getClient(config) {
|
|
64
|
+
if (config.host && !config.authUrl) {
|
|
65
|
+
throw new Error('If custom "host" is provided, "authUrl" must also be provided.');
|
|
66
|
+
}
|
|
67
|
+
if (config.token && !config.clientId) {
|
|
68
|
+
throw new Error('If token is provided directly, "clientId" must also be provided.');
|
|
69
|
+
}
|
|
70
|
+
if (config.apiKey && (!config.orgId || !config.clientId)) {
|
|
71
|
+
throw new Error('If apiKey is provided , "clientId" and "OrgId" must also be provided.');
|
|
72
|
+
}
|
|
73
|
+
let token;
|
|
74
|
+
let isUserProvidedToken = false;
|
|
75
|
+
if (config.token && config.clientId) {
|
|
76
|
+
token = config.token;
|
|
77
|
+
isUserProvidedToken = true;
|
|
78
|
+
}
|
|
79
|
+
else
|
|
80
|
+
token = await Client.requestToken(config);
|
|
81
|
+
Client.instance = new Client(token, config, isUserProvidedToken);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Returns the domain URL configured for the client.
|
|
85
|
+
*
|
|
86
|
+
* @return {string} The domain URL string
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* const client = Client.getInstance();
|
|
90
|
+
* const apiDomain = client.getDomain();
|
|
91
|
+
* console.log(apiDomain); // e.g., 'https://api.example.com'
|
|
92
|
+
*/
|
|
93
|
+
getDomain() {
|
|
94
|
+
return this.domain;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Returns the singleton instance of the Client.
|
|
98
|
+
*
|
|
99
|
+
* @static
|
|
100
|
+
* @return {Client} The singleton Client instance
|
|
101
|
+
* @throws {Error} Throws an error if the Client has not been initialized with getClient()
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* // First initialize the client
|
|
105
|
+
* await Client.getClient({
|
|
106
|
+
* clientId: 'client123',
|
|
107
|
+
* orgId: 'org456'
|
|
108
|
+
* });
|
|
109
|
+
*
|
|
110
|
+
* // Then get the instance
|
|
111
|
+
* const client = Client.getInstance();
|
|
112
|
+
* // Use the client...
|
|
113
|
+
*/
|
|
114
|
+
static getInstance() {
|
|
115
|
+
if (!Client.instance) {
|
|
116
|
+
throw new Error("Client is not initialized. Call Client.getClient() first.");
|
|
117
|
+
}
|
|
118
|
+
return Client.instance;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Refreshes the authentication token if it's about to expire.
|
|
122
|
+
* Only refreshes if the token was not provided by the user and is expiring within 60 seconds.
|
|
123
|
+
*
|
|
124
|
+
* @return {Promise<void>} A promise that resolves when the token refresh is complete
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* const client = Client.getInstance();
|
|
128
|
+
* // Ensure token is fresh before making API requests
|
|
129
|
+
* await client.refreshToken();
|
|
130
|
+
* // Proceed with API requests...
|
|
131
|
+
*/
|
|
132
|
+
async refreshToken() {
|
|
133
|
+
if (!this.isUserProvidedToken) {
|
|
134
|
+
const now = Math.floor(Date.now() / 1000);
|
|
135
|
+
if (this.expiresAt - now < 60) {
|
|
136
|
+
console.log("[SDK] Refreshing token...");
|
|
137
|
+
const token = await Client.requestToken({
|
|
138
|
+
apiKey: this.apiKey,
|
|
139
|
+
clientId: this.clientId,
|
|
140
|
+
orgId: this.orgId,
|
|
141
|
+
authUrl: this.tokenDomain,
|
|
142
|
+
});
|
|
143
|
+
this.token = token;
|
|
144
|
+
this.expiresAt = (0, utils_1.findExpiryTime)(token);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Returns the authorization header object with the Bearer token.
|
|
150
|
+
*
|
|
151
|
+
* @return {Record<string, string>} An object containing the Authorization header with the Bearer token
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* const client = Client.getInstance();
|
|
155
|
+
* const headers = {
|
|
156
|
+
* 'Content-Type': 'application/json',
|
|
157
|
+
* ...client.getAuthHeader()
|
|
158
|
+
* };
|
|
159
|
+
* // headers = { 'Content-Type': 'application/json', 'Authorization': 'Bearer token...' }
|
|
160
|
+
*/
|
|
161
|
+
getAuthHeader() {
|
|
162
|
+
return { Authorization: `Bearer ${this.token}` };
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Returns the client ID configured for this client instance.
|
|
166
|
+
*
|
|
167
|
+
* @return {string} The client ID string
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* const client = Client.getInstance();
|
|
171
|
+
* const clientId = client.getClientId();
|
|
172
|
+
* console.log(clientId); // e.g., 'client123'
|
|
173
|
+
*/
|
|
174
|
+
getClientId() {
|
|
175
|
+
return this.clientId;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Returns the client source identifier for this client instance.
|
|
179
|
+
*
|
|
180
|
+
* @return {string} The client source string
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* const client = Client.getInstance();
|
|
184
|
+
* const source = client.getClientSource();
|
|
185
|
+
* console.log(source); // e.g., 'web', 'mobile', 'sdk'
|
|
186
|
+
*/
|
|
187
|
+
getClientSource() {
|
|
188
|
+
return this.clientSource;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Requests an authentication token from the token generation API.
|
|
192
|
+
*
|
|
193
|
+
* @private
|
|
194
|
+
* @static
|
|
195
|
+
* @param {ClientConfig} config - The client configuration containing authentication details
|
|
196
|
+
* @return {Promise<string>} A promise that resolves to the authentication token string
|
|
197
|
+
* @throws {Error} Throws an error if the token response is empty
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* // Internal usage within the Client class
|
|
201
|
+
* const token = await Client.requestToken({
|
|
202
|
+
* apiKey: 'your-api-key',
|
|
203
|
+
* clientId: 'client123',
|
|
204
|
+
* orgId: 'org456',
|
|
205
|
+
* authUrl: 'https://custom-auth.example.com/token'
|
|
206
|
+
* });
|
|
207
|
+
*/
|
|
208
|
+
static async requestToken(config) {
|
|
209
|
+
var _a;
|
|
210
|
+
const tokenUrl = (_a = config.authUrl) !== null && _a !== void 0 ? _a : Constants_1.TOKEN_GENERATION_API;
|
|
211
|
+
const res = await axios_1.default.get(tokenUrl, {
|
|
212
|
+
headers: {
|
|
213
|
+
"X-Api-Key": config.apiKey,
|
|
214
|
+
"X-IBM-Client-Id": `saascore-${config.clientId}`,
|
|
215
|
+
accept: "application/json",
|
|
216
|
+
},
|
|
217
|
+
params: {
|
|
218
|
+
orgId: config.orgId
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
if (!res.data)
|
|
222
|
+
throw new Error("Token response is empty");
|
|
223
|
+
return String(res.data).trim();
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
exports.Client = Client;
|
|
227
|
+
Client.instance = null;
|