├── .circleci ├── config.yml ├── deploy-nightly-version.sh └── setup-npmjs.sh ├── .eslintrc.json ├── .gitattributes ├── .github ├── ISSUE_TEMPLATE │ ├── BUG_REPORT.yml │ └── feature_request.md ├── PULL_REQUEST_TEMPLATE ├── dependabot.yml └── workflows │ └── semantic.yml ├── .gitignore ├── .npmignore ├── .nvmrc ├── .prettierignore ├── .prettierrc.json ├── .vscode ├── launch.json └── settings.json ├── CHANGELOG.md ├── LICENSE ├── Makefile ├── README.md ├── examples ├── .eslintrc.json ├── .gitignore ├── README.md ├── createBucket.mjs ├── delete.ts ├── env.mjs ├── env_browser.mjs ├── follow-redirects.mjs ├── httpErrorHandled.mjs ├── index.html ├── influxdb-1.8.ts ├── invokableScripts.mjs ├── onboarding.mjs ├── package.json ├── ping.mjs ├── query.deno.ts ├── query.ts ├── queryWithParams.mjs ├── rxjs-query.ts ├── scripts │ ├── monitor.mjs │ └── server.mjs ├── tokens.mjs ├── tsconfig.json ├── write.mjs └── writeAdvanced.mjs ├── lerna.json ├── package.json ├── packages ├── .eslintrc.json ├── apis │ ├── .eslintrc.json │ ├── .npmignore │ ├── .prettierrc.json │ ├── DEVELOPMENT.md │ ├── README.md │ ├── api-extractor.json │ ├── generator │ │ ├── format.ts │ │ ├── generateApi.ts │ │ ├── index.ts │ │ ├── logger.ts │ │ ├── operationType.ts │ │ └── typesCollector.ts │ ├── package.json │ ├── resources │ │ ├── cloud.yml │ │ ├── invocable-scripts.yml │ │ ├── operations.json │ │ └── oss.yml │ ├── scripts │ │ ├── fetchSwaggerFiles.js │ │ └── patchSwagger.js │ ├── src │ │ ├── APIBase.ts │ │ ├── custom │ │ │ ├── FluxScriptInvocationAPI.ts │ │ │ └── index.ts │ │ ├── generated │ │ │ ├── AuthorizationsAPI.ts │ │ │ ├── BackupAPI.ts │ │ │ ├── BucketsAPI.ts │ │ │ ├── ChecksAPI.ts │ │ │ ├── ConfigAPI.ts │ │ │ ├── DashboardsAPI.ts │ │ │ ├── DbrpsAPI.ts │ │ │ ├── DebugAPI.ts │ │ │ ├── DeleteAPI.ts │ │ │ ├── FlagsAPI.ts │ │ │ ├── HealthAPI.ts │ │ │ ├── LabelsAPI.ts │ │ │ ├── MeAPI.ts │ │ │ ├── MetricsAPI.ts │ │ │ ├── NotificationEndpointsAPI.ts │ │ │ ├── NotificationRulesAPI.ts │ │ │ ├── OrgsAPI.ts │ │ │ ├── PingAPI.ts │ │ │ ├── QueryAPI.ts │ │ │ ├── ReadyAPI.ts │ │ │ ├── RemotesAPI.ts │ │ │ ├── ReplicationsAPI.ts │ │ │ ├── ResourcesAPI.ts │ │ │ ├── RestoreAPI.ts │ │ │ ├── RootAPI.ts │ │ │ ├── ScrapersAPI.ts │ │ │ ├── ScriptsAPI.ts │ │ │ ├── SetupAPI.ts │ │ │ ├── SigninAPI.ts │ │ │ ├── SignoutAPI.ts │ │ │ ├── SourcesAPI.ts │ │ │ ├── StacksAPI.ts │ │ │ ├── TasksAPI.ts │ │ │ ├── TelegrafAPI.ts │ │ │ ├── TelegrafsAPI.ts │ │ │ ├── TemplatesAPI.ts │ │ │ ├── UsersAPI.ts │ │ │ ├── VariablesAPI.ts │ │ │ ├── WriteAPI.ts │ │ │ ├── index.ts │ │ │ └── types.ts │ │ └── index.ts │ ├── test │ │ └── unit │ │ │ ├── custom │ │ │ └── FluxScriptInvocationAPI.test.ts │ │ │ └── typesCollector.test.ts │ ├── tsconfig.json │ ├── tsup.config.browser.ts │ └── tsup.config.ts ├── core-browser │ ├── .npmignore │ ├── README.md │ └── package.json ├── core │ ├── .npmignore │ ├── .nycrc │ ├── README.md │ ├── api-extractor.json │ ├── package.json │ ├── src │ │ ├── InfluxDB.ts │ │ ├── Point.ts │ │ ├── QueryApi.ts │ │ ├── WriteApi.ts │ │ ├── errors.ts │ │ ├── impl │ │ │ ├── QueryApiImpl.ts │ │ │ ├── RetryBuffer.ts │ │ │ ├── WriteApiImpl.ts │ │ │ ├── browser │ │ │ │ ├── .eslintrc.json │ │ │ │ ├── FetchTransport.ts │ │ │ │ └── tsconfig.json │ │ │ ├── completeCommunicationObserver.ts │ │ │ ├── node │ │ │ │ ├── NodeHttpTransport.ts │ │ │ │ └── nodeChunkCombiner.ts │ │ │ ├── retryStrategy.ts │ │ │ └── version.ts │ │ ├── index.ts │ │ ├── observable │ │ │ ├── index.ts │ │ │ ├── symbol.ts │ │ │ └── types.ts │ │ ├── options.ts │ │ ├── query │ │ │ ├── flux.ts │ │ │ └── index.ts │ │ ├── results │ │ │ ├── AnnotatedCSVResponse.ts │ │ │ ├── AnnotatedCSVResponseImpl.ts │ │ │ ├── Cancellable.ts │ │ │ ├── CommunicationObserver.ts │ │ │ ├── FluxResultObserver.ts │ │ │ ├── FluxTableColumn.ts │ │ │ ├── FluxTableMetaData.ts │ │ │ ├── LineSplitter.ts │ │ │ ├── ObservableQuery.ts │ │ │ ├── chunkCombiner.ts │ │ │ ├── chunksToLines.ts │ │ │ ├── chunksToLinesIterable.ts │ │ │ ├── index.ts │ │ │ ├── linesToRowsIterable.ts │ │ │ ├── linesToTables.ts │ │ │ └── stringToLines.ts │ │ ├── transport.ts │ │ └── util │ │ │ ├── currentTime.ts │ │ │ ├── escape.ts │ │ │ ├── logger.ts │ │ │ └── utf8Length.ts │ ├── test │ │ ├── fixture │ │ │ ├── chunksToLinesTables.json │ │ │ ├── escapeTables.json │ │ │ ├── lineSplitterTables.json │ │ │ ├── pointTables.json │ │ │ └── query │ │ │ │ ├── response2.parsed.json │ │ │ │ ├── response2.txt │ │ │ │ ├── response3.parsed.json │ │ │ │ ├── response3.txt │ │ │ │ ├── simpleResponse.txt │ │ │ │ └── simpleResponseLines.json │ │ ├── integration │ │ │ └── rxjs │ │ │ │ └── QueryApi.test.ts │ │ ├── unit │ │ │ ├── Influxdb.test.ts │ │ │ ├── Point.test.ts │ │ │ ├── QueryApi.test.ts │ │ │ ├── WriteApi.test.ts │ │ │ ├── errors.test.ts │ │ │ ├── impl │ │ │ │ ├── ObservableQuery.test.ts │ │ │ │ ├── RetryBuffer.test.ts │ │ │ │ ├── browser │ │ │ │ │ ├── FetchTransport.test.ts │ │ │ │ │ └── emulateBrowser.ts │ │ │ │ ├── node │ │ │ │ │ └── NodeHttpTransport.test.ts │ │ │ │ └── retryStrategy.test.ts │ │ │ ├── query │ │ │ │ └── flux.test.ts │ │ │ ├── results │ │ │ │ ├── FluxTableMetaData.test.ts │ │ │ │ ├── LineSplitter.test.ts │ │ │ │ ├── chunkCombiner.test.ts │ │ │ │ ├── chunksToLines.test.ts │ │ │ │ ├── chunksToLinesIterable.test.ts │ │ │ │ ├── linesToRowsIterable.test.ts │ │ │ │ ├── linesToTables.test.ts │ │ │ │ └── stringToLines.test.ts │ │ │ └── util │ │ │ │ ├── CollectLinesObserver.ts │ │ │ │ ├── CollectTablesObserver.ts │ │ │ │ ├── currentTime.test.ts │ │ │ │ ├── escape.test.ts │ │ │ │ ├── logger.test.ts │ │ │ │ ├── utf8Length.test.ts │ │ │ │ └── waitForCondition.ts │ │ └── util.ts │ ├── tsconfig.json │ ├── tsup.config.browser.ts │ └── tsup.config.ts └── giraffe │ ├── .npmignore │ ├── .nycrc │ ├── README.md │ ├── api-extractor.json │ ├── package.json │ ├── src │ ├── csvToTable.ts │ ├── index.ts │ └── queryTable.ts │ ├── test │ └── unit │ │ ├── csvToTable.test.ts │ │ ├── newTable.ts │ │ └── queryTable.test.ts │ ├── tsconfig.json │ └── tsup.config.ts ├── scripts ├── api-extractor-base.json ├── change-version.js ├── enhance-doc-index-md.js ├── esbuild-gzip-js.ts ├── fix-extracted-api-files.js ├── gh-pages_config.yml ├── repair-doc-code-blocks.js └── require-yarn.js ├── tsconfig.base.json └── yarn.lock /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2.1 2 | 3 | commands: 4 | init-dependencies: 5 | steps: 6 | - restore_cache: 7 | name: Restore Yarn Package Cache 8 | keys: 9 | - yarn-packages-v2-{{ checksum "yarn.lock" }} 10 | - run: 11 | name: Install Dependencies 12 | command: yarn install --frozen-lockfile 13 | - save_cache: 14 | name: Save Yarn Package Cache 15 | key: yarn-packages-v2-{{ checksum "yarn.lock" }} 16 | paths: 17 | - ~/.cache/yarn 18 | 19 | jobs: 20 | tests: 21 | parameters: 22 | image: 23 | type: string 24 | default: &default-image 'cimg/node:18.20' 25 | docker: 26 | - image: << parameters.image >> 27 | steps: 28 | - checkout 29 | - init-dependencies 30 | - run: 31 | name: Run tests 32 | command: | 33 | yarn build 34 | yarn test:ci 35 | yarn apidoc:ci 36 | # Upload results 37 | - store_test_results: 38 | path: ./reports 39 | coverage: 40 | parameters: 41 | docker: 42 | - image: *default-image 43 | steps: 44 | - checkout 45 | - init-dependencies 46 | - run: 47 | name: Runs tests with coverage 48 | command: | 49 | yarn --version 50 | yarn run coverage:ci 51 | - run: 52 | name: Report test results to codecov 53 | command: | 54 | curl -Os https://uploader.codecov.io/latest/linux/codecov 55 | curl -Os https://uploader.codecov.io/latest/linux/codecov.SHA256SUM 56 | curl -Os https://uploader.codecov.io/latest/linux/codecov.SHA256SUM.sig 57 | curl https://keybase.io/codecovsecurity/pgp_keys.asc | gpg --no-default-keyring --keyring trustedkeys.gpg --import 58 | gpgv codecov.SHA256SUM.sig codecov.SHA256SUM 59 | shasum -a 256 -c codecov.SHA256SUM 60 | chmod +x ./codecov 61 | ./codecov 62 | - store_artifacts: 63 | path: ./packages/core/coverage 64 | 65 | deploy-preview: 66 | parameters: 67 | docker: 68 | - image: *default-image 69 | steps: 70 | - run: 71 | name: Early return if this build is from a forked repository 72 | command: | 73 | if [[ $CIRCLE_PROJECT_USERNAME != "influxdata" ]]; then 74 | echo "Nothing to do for forked repositories, so marking this step successful" 75 | circleci step halt 76 | fi 77 | - checkout 78 | - init-dependencies 79 | - run: 80 | name: Setup npmjs 81 | command: bash .circleci/setup-npmjs.sh 82 | - run: 83 | name: Build & Deploy nightly version 84 | command: bash .circleci/deploy-nightly-version.sh 85 | 86 | workflows: 87 | build: 88 | jobs: 89 | - tests: 90 | name: 'tests-node-18' 91 | filters: 92 | branches: 93 | ignore: gh-pages 94 | - tests: 95 | name: 'tests-node-20' 96 | image: 'cimg/node:20.16' 97 | filters: 98 | branches: 99 | ignore: gh-pages 100 | - tests: 101 | name: 'tests-node-21' 102 | image: 'cimg/node:21.4' 103 | filters: 104 | branches: 105 | ignore: gh-pages 106 | - coverage: 107 | filters: 108 | branches: 109 | ignore: gh-pages 110 | - deploy-preview: 111 | requires: 112 | - tests-node-18 113 | - coverage 114 | filters: 115 | branches: 116 | only: master 117 | -------------------------------------------------------------------------------- /.circleci/deploy-nightly-version.sh: -------------------------------------------------------------------------------- 1 | set -e 2 | 3 | SCRIPT_PATH="$( cd "$(dirname "$0")" || exit ; pwd -P )" 4 | 5 | # Update Version 6 | VERSION=$(cat packages/core/src/impl/version.ts | sed 's/[^0-9.]*//g' | awk -F. '{$2+=1; OFS="."; print $1"."$2"."$3}') 7 | sed -i -e "s/CLIENT_LIB_VERSION = '.*'/CLIENT_LIB_VERSION = '${VERSION}.nightly'/" packages/core/src/impl/version.ts 8 | yarn lerna version "$VERSION"-nightly."$CIRCLE_BUILD_NUM" --no-git-tag-version --yes 9 | git config user.name "CircleCI Builder" 10 | git config user.email "noreply@influxdata.com" 11 | git commit -am "chore(release): prepare to release influxdb-client-js-${VERSION}.nightly" 12 | 13 | # Build Core 14 | cd "${SCRIPT_PATH}"/.. 15 | yarn build 16 | 17 | # Publish 18 | yarn lerna publish --canary from-package --no-git-tag-version --force-publish --preid nightly --yes 19 | -------------------------------------------------------------------------------- /.circleci/setup-npmjs.sh: -------------------------------------------------------------------------------- 1 | echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc 2 | chmod 0600 ~/.npmrc 3 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "parser": "@typescript-eslint/parser", 3 | "parserOptions": { 4 | "sourceType": "module", 5 | "ecmaFeatures": {} 6 | }, 7 | "plugins": [ 8 | "@typescript-eslint/eslint-plugin", 9 | "prettier", 10 | "eslint-plugin-tsdoc" 11 | ], 12 | "env": { 13 | "node": true, 14 | "es6": true, 15 | "mocha": true 16 | }, 17 | "extends": [ 18 | "eslint:recommended", 19 | "plugin:@typescript-eslint/recommended", 20 | "plugin:prettier/recommended" 21 | ], 22 | "rules": { 23 | "no-console": "off", 24 | "@typescript-eslint/naming-convention": [ 25 | "error", 26 | { 27 | "selector": "variable", 28 | "format": ["camelCase", "UPPER_CASE"], 29 | "filter": { 30 | "regex": "^DEFAULT_|^Log$", 31 | "match": false 32 | }, 33 | "leadingUnderscore": "allow", 34 | "trailingUnderscore": "allow" 35 | }, 36 | { 37 | "selector": "typeLike", 38 | "format": ["PascalCase"] 39 | } 40 | ], 41 | "@typescript-eslint/no-explicit-any": "off", 42 | "@typescript-eslint/no-unused-vars": [ 43 | "error", 44 | {"varsIgnorePattern": "^_", "argsIgnorePattern": "^_"} 45 | ], 46 | "@typescript-eslint/no-empty-function": "off", 47 | "@typescript-eslint/no-empty-interface": "off", 48 | "tsdoc/syntax": "error" 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Rush's JSON config files use JavaScript-style code comments. The rule below prevents pedantic 2 | # syntax highlighters such as GitHub's from highlighting these comments as errors. Your text editor 3 | # may also require a special configuration to allow comments in JSON. 4 | # 5 | # For more information, see this issue: https://github.com/microsoft/rushstack/issues/1088 6 | # 7 | *.json linguist-language=JSON-with-Comments -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/BUG_REPORT.yml: -------------------------------------------------------------------------------- 1 | name: Bug Report 2 | description: Create a bug report to help us improve 3 | labels: ["bug"] 4 | body: 5 | - type: markdown 6 | attributes: 7 | value: | 8 | Thanks for taking time to fill out this bug report! We reserve this repository issues for bugs with reproducible problems. 9 | Please redirect any questions about the JavaScript client usage to our [Community Slack](https://app.slack.com/client/TH8RGQX5Z/C03TNRVRFB2) or [Community Page](https://community.influxdata.com/) we have a lot of talented community members there who could help answer your question more quickly. 10 | 11 | * Please add a :+1: or comment on a similar existing bug report instead of opening a new one. 12 | * Please check whether the bug can be reproduced with the latest release. 13 | - type: textarea 14 | id: specifications 15 | attributes: 16 | label: Specifications 17 | description: Describe the steps to reproduce the bug. 18 | value: | 19 | * Client Version: 20 | * InfluxDB Version: 21 | * Platform: 22 | validations: 23 | required: true 24 | - type: textarea 25 | id: reproduce 26 | attributes: 27 | label: Code sample to reproduce problem 28 | description: Provide a code sample that reproduces the problem 29 | value: | 30 | ```javascript 31 | ``` 32 | validations: 33 | required: true 34 | - type: textarea 35 | id: expected-behavior 36 | attributes: 37 | label: Expected behavior 38 | description: Describe what you expected to happen when you performed the above steps. 39 | validations: 40 | required: true 41 | - type: textarea 42 | id: actual-behavior 43 | attributes: 44 | label: Actual behavior 45 | description: Describe what actually happened when you performed the above steps. 46 | validations: 47 | required: true 48 | - type: textarea 49 | id: additional-info 50 | attributes: 51 | label: Additional info 52 | description: Include gist of relevant config, logs, etc. 53 | validations: 54 | required: false 55 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Opening a feature request kicks off a discussion 4 | --- 5 | 6 | 14 | 15 | __Proposal:__ 16 | Short summary of the feature. 17 | 18 | __Current behavior:__ 19 | Describe what currently happens. 20 | 21 | __Desired behavior:__ 22 | Describe what you want. 23 | 24 | __Alternatives considered:__ 25 | Describe other solutions or features you considered. 26 | 27 | __Use case:__ 28 | Why is this important (helps with prioritizing requests)? 29 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE: -------------------------------------------------------------------------------- 1 | Fixes # 2 | 3 | ## Proposed Changes 4 | 5 | _Briefly describe your proposed changes:_ 6 | 7 | ## Checklist 8 | 9 | 10 | 11 | - [ ] CHANGELOG.md updated 12 | - [ ] Rebased/mergeable 13 | - [ ] A test has been added if appropriate 14 | - [ ] `yarn test` completes successfully 15 | - [ ] Commit messages are [conventional](https://www.conventionalcommits.org/en/v1.0.0/) 16 | - [ ] Sign [CLA](https://www.influxdata.com/legal/cla/) (if not already signed) 17 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: 'npm' 4 | directory: '/' 5 | schedule: 6 | interval: 'monthly' 7 | day: 'sunday' 8 | open-pull-requests-limit: 10 9 | -------------------------------------------------------------------------------- /.github/workflows/semantic.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: "Semantic PR and Commit Messages" 3 | 4 | on: 5 | pull_request: 6 | types: [opened, reopened, synchronize, edited] 7 | branches: 8 | - master 9 | 10 | jobs: 11 | semantic: 12 | uses: influxdata/validate-semantic-github-messages/.github/workflows/semantic.yml@main 13 | with: 14 | CHECK_PR_TITLE_OR_ONE_COMMIT: true 15 | 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | build 3 | dist 4 | coverage 5 | doc 6 | .rpt2_cache 7 | .DS_Store 8 | .nyc_output 9 | *.lcov 10 | reports 11 | yarn-error.log 12 | .idea/ 13 | /temp 14 | /docs 15 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/influxdata/influxdb-client-js/fccedfdf9ba89fbb4aef2ea25dc1e8a8d4667449/.npmignore -------------------------------------------------------------------------------- /.nvmrc: -------------------------------------------------------------------------------- 1 | v18 2 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | **/*.d.ts -------------------------------------------------------------------------------- /.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true, 3 | "semi": false, 4 | "trailingComma": "es5", 5 | "bracketSpacing": false 6 | } 7 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Core Tests", 9 | "type": "node", 10 | "request": "launch", 11 | "cwd": "${workspaceRoot}/packages/core", 12 | "program": "${workspaceRoot}/node_modules/mocha/bin/_mocha", 13 | "args": [ 14 | "--require", 15 | "esbuild-runner/register", 16 | "--timeout", 17 | "15000", 18 | "--colors", 19 | "test/**/*.test.ts" 20 | ], 21 | "internalConsoleOptions": "openOnSessionStart" 22 | } 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | // enforce prettier on save 3 | "editor.formatOnSave": true, 4 | // comments in json files are OK 5 | "files.associations": {"*.json": "jsonc"} 6 | } 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 InfluxData 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # **Releasing a new version** 2 | # Ensure that: 3 | # - You have administrator access to this repo on GitHub 4 | # - You have permissions to publish to the [influxdata](https://www.npmjs.com/org/influxdata) organization on npm 5 | # - You are on `master` and the working tree is clean 6 | # Then run the publish target with VERSION specified: 7 | # ``` 8 | # make publish VERSION=1.8.0 9 | # ``` 10 | .DEFAULT_GOAL := help 11 | 12 | help: 13 | @echo "Please use \`make ' where is one of" 14 | @echo "" 15 | @echo " publish to publish packages to specified version by VERSION property. make publish VERSION=1.1.0" 16 | @echo "" 17 | 18 | publish: 19 | $(if $(VERSION),,$(error VERSION is not defined. Pass via "make publish VERSION=1.1.0")) 20 | git checkout master 21 | git pull 22 | yarn install --frozen-lockfile 23 | node scripts/change-version.js 24 | yarn run build 25 | yarn run test 26 | @echo "Publishing $(VERSION)..." 27 | git commit -am "chore(release): prepare to release influxdb-client-js-$(VERSION)" 28 | npx lerna publish $(VERSION) 29 | @echo "Publish successful" 30 | @echo "" 31 | @echo "Next steps:" 32 | @echo " - publish updated API documentation by: \"yarn apidoc && yarn apidoc:gh-pages\"" 33 | @echo " - add new version to CHANGELOG.md" 34 | @echo " - push changes to repository by : \"git commit -am 'chore(release): prepare to next development iteration [skip CI]' && git push\"" 35 | @echo "" 36 | -------------------------------------------------------------------------------- /examples/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "parser": "@typescript-eslint/parser", 3 | "parserOptions": { 4 | "sourceType": "module", 5 | "ecmaFeatures": {} 6 | }, 7 | "plugins": ["@typescript-eslint", "prettier"], 8 | "env": { 9 | "node": true 10 | }, 11 | "extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"], 12 | "rules": { 13 | "no-console": "off", 14 | "@typescript-eslint/no-var-requires": "off" 15 | }, 16 | "overrides": [ 17 | { 18 | "files": ["*.js", "*.mjs"], 19 | "rules": { 20 | "@typescript-eslint/explicit-function-return-type": "off", 21 | "@typescript-eslint/naming-convention": ["off"] 22 | } 23 | }, 24 | { 25 | "files": ["query.deno.ts"], 26 | "rules": { 27 | "prettier/prettier": "off" 28 | } 29 | } 30 | ] 31 | } 32 | -------------------------------------------------------------------------------- /examples/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | build 3 | dist 4 | coverage 5 | doc 6 | .rpt2_cache 7 | .DS_Store 8 | .nyc_output 9 | *.lcov 10 | reports 11 | yarn-error.log 12 | package-lock.json 13 | yarn.lock 14 | pnpm-lock.yaml 15 | -------------------------------------------------------------------------------- /examples/README.md: -------------------------------------------------------------------------------- 1 | # InfluxDB Client Examples 2 | 3 | This directory contains javascript and typescript examples for node.js, browser, and deno. 4 | 5 | - Node.js examples 6 | - Prerequisites 7 | - [node](https://nodejs.org/en/) installed, at least version 18 is recommended 8 | - Run `npm install` in this directory 9 | - Change variables in [./env.mjs](env.mjs) to configure connection to your InfluxDB instance. The file can be used as-is against a new [docker InfluxDB v2.3 OSS GA installation](https://docs.influxdata.com/influxdb/v2.3/get-started/) 10 | - Examples are executable. If it does not work for you, run `npm run esr EXAMPLE.ts`. 11 | - [write.mjs](./write.mjs) 12 | Write data points to InfluxDB. 13 | - [query.ts](./query.ts) 14 | Query InfluxDB with [Flux](https://docs.influxdata.com/influxdb/latest/get-started/). 15 | - [queryWithParams.mjs](./queryWithParams.mjs) 16 | Supply parameters to a [Flux](https://docs.influxdata.com/influxdb/latest/get-started/) query. 17 | - [ping.mjs](./ping.mjs) 18 | Check status of InfluxDB server. 19 | - [createBucket.mjs](./createBucket.mjs) 20 | Creates an example bucket. 21 | - [onboarding.mjs](./onboarding.mjs) 22 | Performs onboarding of a new influxDB database. It creates a new organization, bucket and user that is then used in all examples. 23 | - [influxdb-1.8.ts](./influxdb-1.8.ts) 24 | How to use forward compatibility APIs from InfluxDB 1.8. 25 | - [rxjs-query.ts](./rxjs-query.ts) 26 | Use [RxJS](https://rxjs.dev/) to query InfluxDB with [Flux](https://docs.influxdata.com/influxdb/latest/get-started/). 27 | - [writeAdvanced.mjs](./writeAdvanced.mjs) 28 | Shows how to control the way of how data points are written to InfluxDB. 29 | - [follow-redirects.mjs](./follow-redirects.mjs) 30 | Shows how to configure the client to follow HTTP redirects. 31 | - [delete.ts](./delete.ts) 32 | Shows how to delete data from a bucket. 33 | - [httpErrorHandled.mjs](./httpErrorHandled.mjs) 34 | Shows handling HTTP Error response. 35 | - Browser examples 36 | - Change `token, org, bucket, username, password` variables in [./env_browser.mjs](env_browser.mjs) to match your InfluxDB instance 37 | - Run `npm run browser` 38 | It starts a local HTTP server and opens [index.html](./index.html) that contains client examples. 39 | The local HTTP server serves all files from this git repository and also proxies requests 40 | to a configured influxDB database, see [scripts/server.mjs](./scripts/server.mjs) for details. 41 | - Deno examples 42 | - [query.deno.ts](./query.deno.ts) shows how to query InfluxDB with [Flux](https://docs.influxdata.com/influxdb/latest/get-started/). 43 | It is almost the same as node's [query.ts](./query.ts) example, the difference is the import statement that works in [deno](https://deno.land) and built-in typescript support. 44 | -------------------------------------------------------------------------------- /examples/createBucket.mjs: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | /* 3 | This example creates a new bucket. If a bucket of the same name already exists, 4 | it is deleted and then created again. 5 | */ 6 | 7 | import {InfluxDB, HttpError} from '@influxdata/influxdb-client' 8 | import {OrgsAPI, BucketsAPI} from '@influxdata/influxdb-client-apis' 9 | import {url, org, token} from './env.mjs' 10 | const influxDB = new InfluxDB({url, token}) 11 | 12 | async function recreateBucket(name) { 13 | console.log('*** Get organization by name ***') 14 | const orgsAPI = new OrgsAPI(influxDB) 15 | const organizations = await orgsAPI.getOrgs({org}) 16 | if (!organizations || !organizations.orgs || !organizations.orgs.length) { 17 | console.error(`No organization named "${org}" found!`) 18 | } 19 | const orgID = organizations.orgs[0].id 20 | console.log(`Using organization "${org}" identified by "${orgID}"`) 21 | 22 | console.log('*** Get buckets by name ***') 23 | const bucketsAPI = new BucketsAPI(influxDB) 24 | try { 25 | const buckets = await bucketsAPI.getBuckets({orgID, name}) 26 | if (buckets && buckets.buckets && buckets.buckets.length) { 27 | console.log(`Bucket named "${name}" already exists"`) 28 | const bucketID = buckets.buckets[0].id 29 | console.log(`*** Delete Bucket "${name}" identified by "${bucketID}" ***`) 30 | await bucketsAPI.deleteBucketsID({bucketID}) 31 | } 32 | } catch (e) { 33 | if (e instanceof HttpError && e.statusCode == 404) { 34 | // OK, bucket not found 35 | } else { 36 | throw e 37 | } 38 | } 39 | 40 | console.log(`*** Create Bucket "${name}" ***`) 41 | // creates a bucket, entity properties are specified in the "body" property 42 | const bucket = await bucketsAPI.postBuckets({body: {orgID, name}}) 43 | console.log( 44 | JSON.stringify( 45 | bucket, 46 | (key, value) => (key === 'links' ? undefined : value), 47 | 2 48 | ) 49 | ) 50 | } 51 | 52 | try { 53 | await recreateBucket('example-bucket') 54 | console.log('\nFinished SUCCESS') 55 | } catch (e) { 56 | console.error(e) 57 | console.log('\nFinished ERROR') 58 | } 59 | -------------------------------------------------------------------------------- /examples/delete.ts: -------------------------------------------------------------------------------- 1 | #!./node_modules/.bin/esr 2 | 3 | ///////////////////////////////////////////////////////////////////////// 4 | // Shows how to delete data from InfluxDB. See // 5 | // https://docs.influxdata.com/influxdb/latest/write-data/delete-data/ // 6 | ///////////////////////////////////////////////////////////////////////// 7 | 8 | import {InfluxDB} from '@influxdata/influxdb-client' 9 | import {DeleteAPI} from '@influxdata/influxdb-client-apis' 10 | import {url, token, org, bucket} from './env.mjs' 11 | const influxDB = new InfluxDB({url, token}) 12 | 13 | /* 14 | The functionality of the DeleteAPI is fully demonstrated with 15 | the following sequence of examples: 16 | - write.mjs 17 | - query.ts 18 | - delete.ts 19 | - query.ts 20 | 21 | Note: You can also delete and re-create the whole bucket, 22 | see ./createBucket.js example. 23 | */ 24 | 25 | async function deleteData(): Promise { 26 | console.log('*** DELETE DATA ***') 27 | const deleteAPI = new DeleteAPI(influxDB) 28 | // define time interval for delete operation 29 | const stop = new Date() 30 | const start = new Date(stop.getTime() - /* an hour */ 60 * 60 * 1000) 31 | 32 | await deleteAPI.postDelete({ 33 | org, 34 | bucket, 35 | // you can better specify orgID, bucketID in place or org, bucket if you already know them 36 | body: { 37 | start: start.toISOString(), 38 | stop: stop.toISOString(), 39 | // see https://docs.influxdata.com/influxdb/latest/reference/syntax/delete-predicate/ 40 | predicate: '_measurement="temperature"', 41 | }, 42 | }) 43 | } 44 | 45 | deleteData() 46 | .then(() => console.log('\nFinished SUCCESS')) 47 | .catch((error) => { 48 | console.error(error) 49 | console.log('\nFinished ERROR') 50 | }) 51 | -------------------------------------------------------------------------------- /examples/env.mjs: -------------------------------------------------------------------------------- 1 | /** InfluxDB v2 URL */ 2 | const url = process.env['INFLUX_URL'] || 'http://localhost:8086' 3 | /** InfluxDB authorization token */ 4 | const token = process.env['INFLUX_TOKEN'] || 'my-token' 5 | /** Organization within InfluxDB */ 6 | const org = process.env['INFLUX_ORG'] || 'my-org' 7 | /**InfluxDB bucket used in examples */ 8 | const bucket = 'my-bucket' 9 | // ONLY onboarding example 10 | /**InfluxDB user */ 11 | const username = 'my-user' 12 | /**InfluxDB password */ 13 | const password = 'my-password' 14 | 15 | export {url, token, org, bucket, username, password} 16 | -------------------------------------------------------------------------------- /examples/env_browser.mjs: -------------------------------------------------------------------------------- 1 | /* This file contains InfluxDB configuration for the browser example. */ 2 | 3 | /** InfluxDB v2 URL, '/influxdb' relies upon proxy to forward to the target influxDB */ 4 | export const url = '/influx' //'http://localhost:8086', 5 | /** InfluxDB authorization token */ 6 | export const token = 'my-token' 7 | /** InfluxDB organization */ 8 | export const org = 'my-org' 9 | /** InfluxDB bucket used for onboarding and write requests. */ 10 | export const bucket = 'my-bucket' 11 | 12 | /** The following properties are used ONLY in the onboarding example */ 13 | /** InfluxDB user */ 14 | export const username = 'my-user' 15 | /** InfluxDB password */ 16 | export const password = 'my-password' 17 | -------------------------------------------------------------------------------- /examples/follow-redirects.mjs: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | ///////////////////////////////////////////////////////////////////////// 3 | // Shows how to configure InfluxDB node.js client to follow redirects. // 4 | ///////////////////////////////////////////////////////////////////////// 5 | 6 | import {url as targetUrl, token, org} from './env.mjs' 7 | import {InfluxDB} from '@influxdata/influxdb-client' 8 | import {createServer} from 'node:http' 9 | import followRedirects from 'follow-redirects' 10 | 11 | // start a simple HTTP server that always redirects to a configured InfluxDB 12 | const server = createServer((req, res) => { 13 | const reqUrl = new URL(req.url, `http://${req.headers.host}`) 14 | console.info(`Redirecting ${req.method} ${reqUrl} to ${targetUrl + req.url}`) 15 | res.writeHead(307, {location: targetUrl + req.url}) 16 | res.end() 17 | }) 18 | server.listen(0, 'localhost', async () => { 19 | const addressInfo = server.address() 20 | console.info('Redirection HTTP server started:', addressInfo) 21 | 22 | const url = `http://localhost:${addressInfo.port}` 23 | console.info('Executing buckets() query against InfluxDB at', url) 24 | const queryApi = new InfluxDB({ 25 | url, 26 | token, 27 | transportOptions: { 28 | // The following transport option is required in order to follow HTTP redirects in node.js. 29 | // Browsers and deno follow redirects OOTB. 30 | 'follow-redirects': followRedirects, 31 | beforeRedirect: (options, _response, request) => { 32 | // setup Authorization header for a redirected message, 33 | // authorization and cookie headers are removed by follow-redirects 34 | if (request.headers.authorization) { 35 | options.headers.authorization = request.headers.authorization 36 | } 37 | }, 38 | }, 39 | }).getQueryApi(org) 40 | try { 41 | const data = await queryApi.collectRows('buckets()', (values, tableMeta) => 42 | tableMeta.get(values, 'name') 43 | ) 44 | console.info('Available buckets:') 45 | data.forEach((name) => console.info('', name)) 46 | console.log('\nQuery SUCCESS') 47 | } catch (e) { 48 | console.error(e) 49 | console.log('\nQuery ERROR') 50 | } finally { 51 | server.close() 52 | } 53 | }) 54 | -------------------------------------------------------------------------------- /examples/httpErrorHandled.mjs: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | /////////////////////////////////////////////////////////// 3 | // Shows how to handle InfluxDB write API - HTTP Errors. // 4 | // To be run against cloud account // 5 | /////////////////////////////////////////////////////////// 6 | 7 | import {InfluxDB} from '@influxdata/influxdb-client' 8 | import {url, token, org, bucket} from './env.mjs' 9 | 10 | console.log('*** FORCE AND HANDLE HTTP ERROR ***') 11 | 12 | const writeApi = new InfluxDB({url, token}).getWriteApi(org, bucket, 'ns') 13 | 14 | try { 15 | await writeApi.writeRecord('asdf') //invalid lineprotocol 16 | await writeApi.close() 17 | } catch (e) { 18 | if (e.statusCode !== 400) { 19 | throw new Error(`Expected HTTP 400 but received ${e.statusCode}`) 20 | } 21 | console.log() 22 | console.log('Handle HTTP Error') 23 | console.log(`Caught expected HTTP ${e.statusCode}`) 24 | console.log(` At: ${e.headers.date}`) 25 | console.log(` During request: ${e.headers['x-influxdb-request-id']}`) 26 | console.log(` On build: ${e.headers['x-influxdb-build']}`) 27 | console.log(` Traceable: ${e.headers['trace-id']}`) 28 | console.log( 29 | ` Can retry: ${e._retryAfter === 0 ? false : e._retryAfter}` 30 | ) 31 | } 32 | -------------------------------------------------------------------------------- /examples/influxdb-1.8.ts: -------------------------------------------------------------------------------- 1 | #!./node_modules/.bin/esr 2 | //////////////////////////////////////////////////////////////////// 3 | // Shows how to use forward compatibility APIs from InfluxDB 1.8. // 4 | //////////////////////////////////////////////////////////////////// 5 | // [InfluxDB 2.0 API compatibility endpoints](https://docs.influxdata.com/influxdb/v1.8/tools/api/#influxdb-2-0-api-compatibility-endpoints) 6 | // are part of the InfluxDB 1.x line since InfluxDB 1.8.0. This allows you to leverage InfluxDB 2.x client libraries for both writing and 7 | // querying data with Flux. 8 | // https://docs.influxdata.com/influxdb/v1.8/about_the_project/releasenotes-changelog/#forward-compatibility 9 | 10 | import {ClientOptions, InfluxDB, Point} from '@influxdata/influxdb-client' 11 | 12 | const username = 'username' 13 | const password = 'password' 14 | 15 | const database = 'telegraf' 16 | const retentionPolicy = 'autogen' 17 | 18 | const bucket = `${database}/${retentionPolicy}` 19 | 20 | const clientOptions: ClientOptions = { 21 | url: 'http://localhost:8086', 22 | token: `${username}:${password}`, 23 | } 24 | 25 | const influxDB = new InfluxDB(clientOptions) 26 | 27 | async function writePoints(): Promise { 28 | console.log('*** WRITE POINTS ***') 29 | const writeAPI = influxDB.getWriteApi('', bucket) 30 | const point = new Point('mem') 31 | .tag('host', 'host1') 32 | .floatField('used_percent', 23.43234543) 33 | writeAPI.writePoint(point) 34 | await writeAPI.close() 35 | } 36 | 37 | async function queryRows(): Promise { 38 | console.log('*** QUERY ROWS ***') 39 | const queryAPI = influxDB.getQueryApi('') 40 | const query = `from(bucket: "${bucket}") |> range(start: -1h)` 41 | for await (const {values, tableMeta} of queryAPI.iterateRows(query)) { 42 | const o = tableMeta.toObject(values) 43 | console.log(`${o._time} ${o._measurement} : ${o._field}=${o._value}`) 44 | } 45 | console.log('\nQuery FINISHED') 46 | } 47 | 48 | writePoints() 49 | .then(queryRows) 50 | .catch((e) => console.error(e)) 51 | -------------------------------------------------------------------------------- /examples/invokableScripts.mjs: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | /* 3 | This example shows how to use API-invokable scripts. See also 4 | https://docs.influxdata.com/influxdb/cloud/api-guide/api-invokable-scripts/ . 5 | */ 6 | 7 | import {InfluxDB, HttpError} from '@influxdata/influxdb-client' 8 | import { 9 | ScriptsAPI, 10 | FluxScriptInvocationAPI, 11 | } from '@influxdata/influxdb-client-apis' 12 | import {url, token} from './env.mjs' 13 | import {argv} from 'node:process' 14 | 15 | const influxDB = new InfluxDB({url, token}) 16 | const scriptsAPI = new ScriptsAPI(influxDB) 17 | const scriptName = 'example_generate_values' 18 | 19 | async function listScripts() { 20 | console.log('*** List scripts ***') 21 | // current scripts 22 | const scripts = await scriptsAPI.getScripts() 23 | console.log(scripts.scripts) 24 | return scripts 25 | } 26 | async function createScript() { 27 | console.log('*** Create example script ***') 28 | // current scripts 29 | const script = await scriptsAPI.postScripts({ 30 | body: { 31 | script: `import "generate" 32 | 33 | generate.from( 34 | count: int(v: params.count), 35 | fn: (n) => (n + 1) * (n + 2), 36 | start: 2021-01-01T00:00:00Z, 37 | stop: 2021-01-02T00:00:00Z, 38 | )`, 39 | description: 40 | 'This is an example script generated by a javascript client.', 41 | name: scriptName, 42 | language: 'flux', 43 | }, 44 | }) 45 | console.log(script) 46 | return script 47 | } 48 | async function deleteScript(id) { 49 | console.log('*** Delete example script ***') 50 | if (!id) { 51 | const scripts = (await scriptsAPI.getScripts()).scripts 52 | id = scripts.find((x) => x.name === scriptName)?.id 53 | } 54 | if (id) { 55 | await scriptsAPI.deleteScriptsID({scriptID: id}) 56 | console.log(`Script ${scriptName} was deleted!`) 57 | } 58 | } 59 | 60 | async function invokeScript(scriptID) { 61 | console.log('*** Invoke example script ***') 62 | 63 | // parse count as a first script argument or use 10 64 | const count = Number.parseInt(argv[2] || '10') 65 | 66 | // execute script with count parameter 67 | const params = {count: count} 68 | console.log('Script parameters: ', params) 69 | // Use FluxScriptInvocationAPI to execute a particular 70 | // script with specified parameters and process parsed results 71 | const invocationAPI = new FluxScriptInvocationAPI(influxDB) 72 | const results = invocationAPI.invoke(scriptID, params) 73 | let cnt = 0 74 | for await (const {values, tableMeta} of results.iterateRows()) { 75 | cnt++ 76 | // console.log(tableMetaData.toObject(row)) 77 | console.log(cnt, '*', cnt + 1, '=', tableMeta.get(values, '_value')) 78 | } 79 | // // You can also receive the whole response body. Use with caution, 80 | // // a possibly huge stream of results is copied to memory. 81 | // const response = await scriptsAPI.postScriptsIDInvoke({ 82 | // scriptID, 83 | // body: {params}, 84 | // }) 85 | // console.log('Response:') 86 | // console.log(response) 87 | } 88 | 89 | try { 90 | await listScripts() 91 | await deleteScript() 92 | const {id} = await createScript() 93 | await invokeScript(id) 94 | console.log('\nFinished SUCCESS') 95 | } catch (e) { 96 | if (e instanceof HttpError && e.statusCode === 404) { 97 | console.error( 98 | `API invokable scripts are not supported by InfluxDB at ${url} .` 99 | ) 100 | console.error('Modify env.mjs with InfluxDB Cloud URL and token.') 101 | } else { 102 | console.error(e) 103 | } 104 | console.log('\nFinished ERROR') 105 | } 106 | -------------------------------------------------------------------------------- /examples/onboarding.mjs: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | /* 3 | This example setups a new INFLUXDB database with user,organization 4 | and bucket that can be then used in examples. All values that used 5 | for onboarding are defined in ./env.ts . 6 | */ 7 | 8 | import {InfluxDB} from '@influxdata/influxdb-client' 9 | import {SetupAPI} from '@influxdata/influxdb-client-apis' 10 | import {url, username, password, org, bucket, token} from './env.mjs' 11 | 12 | console.log('*** ONBOARDING ***') 13 | const setupApi = new SetupAPI(new InfluxDB({url})) 14 | try { 15 | const {allowed} = await setupApi.getSetup() 16 | if (allowed) { 17 | await setupApi.postSetup({ 18 | body: { 19 | org, 20 | bucket, 21 | username, 22 | password, 23 | token, 24 | }, 25 | }) 26 | console.log(`InfluxDB '${url}' is now onboarded.`) 27 | } else { 28 | console.log(`InfluxDB '${url}' has been already onboarded.`) 29 | } 30 | console.log('\nFinished SUCCESS') 31 | } catch (e) { 32 | console.error(e) 33 | console.log('\nFinished ERROR') 34 | } 35 | -------------------------------------------------------------------------------- /examples/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "license": "MIT", 4 | "scripts": { 5 | "browser": "node scripts/server.mjs", 6 | "clean": "echo 'nothing to clean'", 7 | "build": "echo 'nothing to build'", 8 | "test": "echo 'run examples to test'", 9 | "esr": "esr" 10 | }, 11 | "dependencies": { 12 | "@influxdata/influxdb-client": "link:../packages/core", 13 | "@influxdata/influxdb-client-apis": "link:../packages/apis" 14 | }, 15 | "devDependencies": { 16 | "@types/express": "^4.17.2", 17 | "@types/express-http-proxy": "^1.5.12", 18 | "@types/node": "^16", 19 | "esbuild": "0.14.25", 20 | "esbuild-runner": "^2.2.1", 21 | "express": "^4.17.1", 22 | "express-http-proxy": "^1.6.0", 23 | "follow-redirects": "^1.14.3", 24 | "open": "^7.0.0", 25 | "response-time": "^2.3.2", 26 | "rxjs": "^6.5.5", 27 | "typescript": "^4.8.2" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /examples/ping.mjs: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | /* 3 | This example shows how to check state InfluxDB instance. 4 | InfluxDB OSS APIs are available through '@influxdata/influxdb-client-apis' package. 5 | 6 | See https://docs.influxdata.com/influxdb/latest/api/ 7 | */ 8 | import {InfluxDB} from '@influxdata/influxdb-client' 9 | import {PingAPI} from '@influxdata/influxdb-client-apis' 10 | import {url} from './env.mjs' 11 | 12 | const timeout = 10 * 1000 // timeout for ping 13 | 14 | console.log('*** PING STATUS ***') 15 | const influxDB = new InfluxDB({url, timeout}) 16 | const pingAPI = new PingAPI(influxDB) 17 | 18 | pingAPI 19 | .getPing() 20 | .then(() => { 21 | console.log('\nPing SUCCESS') 22 | }) 23 | .catch((error) => { 24 | console.error(error) 25 | console.log('\nFinished ERROR') 26 | }) 27 | -------------------------------------------------------------------------------- /examples/query.deno.ts: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env -S deno run --allow-net 2 | ////////////////////////////////////////////////////// 3 | // A modified query.ts example that works with deno // 4 | ////////////////////////////////////////////////////// 5 | 6 | import {InfluxDB} from 'https://cdn.skypack.dev/@influxdata/influxdb-client-browser?dts' 7 | 8 | const url = 'http://localhost:8086' 9 | const token = 'my-token' 10 | const org = 'my-org' 11 | 12 | const queryApi = new InfluxDB({url, token}).getQueryApi(org) 13 | const fluxQuery = 14 | 'from(bucket:"my-bucket" ) |> range(start: 0) |> filter(fn: (r) => r._measurement == "temperature")' 15 | 16 | console.log('** QUERY ROWS ***') 17 | try { 18 | for await (const {values, tableMeta} of queryApi.iterateRows(fluxQuery)) { 19 | const o = tableMeta.toObject(values) 20 | // console.log(JSON.stringify(o, null, 2)) 21 | console.log( 22 | `${o._time} ${o._measurement} in '${o.location}' (${o.example}): ${o._field}=${o._value}` 23 | ) 24 | } 25 | console.log('\nFinished SUCCESS') 26 | } catch (error) { 27 | console.error(error) 28 | console.log('\nFinished ERROR') 29 | } 30 | -------------------------------------------------------------------------------- /examples/queryWithParams.mjs: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | ////////////////////////////////////////// 3 | // Shows how to use InfluxDB query API. // 4 | ////////////////////////////////////////// 5 | 6 | import {InfluxDB, flux, fluxDuration} from '@influxdata/influxdb-client' 7 | import {url, token, org} from './env.mjs' 8 | 9 | const queryApi = new InfluxDB({url, token}).getQueryApi(org) 10 | const start = fluxDuration('-1m') 11 | const measurement = 'temperature' 12 | const fluxQuery = flux`from(bucket:"my-bucket") 13 | |> range(start: ${start}) 14 | |> filter(fn: (r) => r._measurement == ${measurement})` 15 | console.log('query:', fluxQuery.toString()) 16 | 17 | console.log('*** QUERY ROWS ***') 18 | try { 19 | for await (const {values, tableMeta} of queryApi.iterateRows(fluxQuery)) { 20 | const o = tableMeta.toObject(values) 21 | // console.log(JSON.stringify(o, null, 2)) 22 | console.log( 23 | `${o._time} ${o._measurement} in '${o.location}' (${o.example}): ${o._field}=${o._value}` 24 | ) 25 | } 26 | console.log('\nFinished SUCCESS') 27 | } catch (e) { 28 | console.log('\nFinished ERROR') 29 | } 30 | -------------------------------------------------------------------------------- /examples/rxjs-query.ts: -------------------------------------------------------------------------------- 1 | #!./node_modules/.bin/esr 2 | //////////////////////////////////////////////////// 3 | // Shows how to use InfluxDB query API with rxjs. // 4 | //////////////////////////////////////////////////// 5 | 6 | import {InfluxDB} from '@influxdata/influxdb-client' 7 | import {from} from 'rxjs' 8 | import {map} from 'rxjs/operators' 9 | import {url, token, org} from './env.mjs' 10 | 11 | const queryApi = new InfluxDB({url, token}).getQueryApi(org) 12 | 13 | const fluxQuery = 14 | 'from(bucket:"my-bucket") |> range(start: -1d) |> filter(fn: (r) => r._measurement == "temperature")' 15 | 16 | console.log('*** QUERY ROWS ***') 17 | // performs query and receive line table metadata and rows 18 | // https://docs.influxdata.com/influxdb/latest/reference/syntax/annotated-csv/ 19 | from(queryApi.rows(fluxQuery)) 20 | .pipe(map(({values, tableMeta}) => tableMeta.toObject(values))) 21 | .subscribe({ 22 | next(o) { 23 | console.log( 24 | `${o._time} ${o._measurement} in '${o.location}' (${o.example}): ${o._field}=${o._value}` 25 | ) 26 | }, 27 | error(e) { 28 | console.error(e) 29 | console.log('\nFinished ERROR') 30 | }, 31 | complete() { 32 | console.log('\nFinished SUCCESS') 33 | }, 34 | }) 35 | 36 | // performs query and receive line results in annotated csv format 37 | // https://docs.influxdata.com/influxdb/latest/reference/syntax/annotated-csv/ 38 | // from(queryApi.lines(fluxQuery)).forEach(console.log) 39 | -------------------------------------------------------------------------------- /examples/scripts/monitor.mjs: -------------------------------------------------------------------------------- 1 | import {InfluxDB, Point} from '@influxdata/influxdb-client' 2 | import {url, token, org, bucket} from '../env.mjs' 3 | import responseTime from 'response-time' 4 | import {hostname} from 'node:os' 5 | 6 | // create Influx Write API to report application monitoring data 7 | const writeAPI = new InfluxDB({url, token}).getWriteApi(org, bucket, 'ns', { 8 | defaultTags: { 9 | service: 'influxdb_client_example_app', 10 | host: hostname(), 11 | }, 12 | }) 13 | // write node resource/cpu/memory usage 14 | function writeProcessUsage() { 15 | function createPoint(measurement, usage) { 16 | const point = new Point(measurement) 17 | for (const key of Object.keys(usage)) { 18 | point.floatField(key, usage[key]) 19 | } 20 | return point 21 | } 22 | 23 | // https://nodejs.org/api/process.html#process_process_memoryusage 24 | writeAPI.writePoint(createPoint('node_memory_usage', process.memoryUsage())) 25 | // https://nodejs.org/api/process.html#process_process_cpuusage_previousvalue 26 | writeAPI.writePoint(createPoint('node_cpu_usage', process.cpuUsage())) 27 | // https://nodejs.org/api/process.html#process_process_resourceusage 28 | // available since node v12.6 29 | if (process.resourceUsage) { 30 | writeAPI.writePoint( 31 | createPoint('node_resource_usage', process.resourceUsage()) 32 | ) 33 | } 34 | } 35 | // write process usage now and then every 10 seconds 36 | writeProcessUsage() 37 | const nodeUsageTimer = setInterval(writeProcessUsage, 10_000).unref() 38 | 39 | // on shutdown 40 | // - clear reporting of node usage 41 | // - flush unwritten points and cancel retries 42 | async function onShutdown() { 43 | clearInterval(nodeUsageTimer) 44 | try { 45 | await writeAPI.close() 46 | } catch (error) { 47 | console.error('ERROR: Application monitoring', error) 48 | } 49 | // eslint-disable-next-line no-process-exit 50 | process.exit(0) 51 | } 52 | process.on('SIGINT', onShutdown) 53 | process.on('SIGTERM', onShutdown) 54 | 55 | // export a monitoring function for express.js response time monitoring 56 | export default function (app) { 57 | app.use( 58 | responseTime((req, res, time) => { 59 | // print out request basics 60 | console.info( 61 | `${req.method} ${req.path} ${res.statusCode} ${ 62 | Math.round(time * 100) / 100 63 | }ms` 64 | ) 65 | // write response time to InfluxDB 66 | const point = new Point('express_http_server') 67 | .tag('uri', req.path) 68 | .tag('method', req.method) 69 | .tag('status', String(res.statusCode)) 70 | .floatField('response_time', time) 71 | writeAPI.writePoint(point) 72 | }) 73 | ) 74 | } 75 | -------------------------------------------------------------------------------- /examples/scripts/server.mjs: -------------------------------------------------------------------------------- 1 | import express from 'express' 2 | import proxy from 'express-http-proxy' 3 | import open from 'open' 4 | import {fileURLToPath} from 'node:url' 5 | import {url} from '../env.mjs' 6 | import monitor from './monitor.mjs' 7 | 8 | const port = 3001 9 | const proxyPath = '/influx' 10 | 11 | const app = express() 12 | // monitor express response time in InfluxDB 13 | monitor(app) 14 | // serve all files of the git repository 15 | const dirName = fileURLToPath(new URL('../..', import.meta.url)) 16 | app.use(express.static(dirName, {index: false})) 17 | // create also proxy to InfluxDB 18 | app.use(proxyPath, proxy(url)) 19 | app.listen(port, () => { 20 | console.log(`listening on http://localhost:${port}`) 21 | console.log(`forwarding ${proxyPath}/* to ${url}/*`) 22 | console.log(`opening http://localhost:${port}/examples/index.html`) 23 | open(`http://localhost:${port}/examples/index.html`) 24 | }) 25 | -------------------------------------------------------------------------------- /examples/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "esnext", 4 | "moduleResolution": "node", 5 | "target": "ES2018", 6 | "allowJs": true 7 | }, 8 | "exclude": ["**/*.js", "**/*.mjs"] 9 | } 10 | -------------------------------------------------------------------------------- /examples/write.mjs: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | ////////////////////////////////////////// 3 | // Shows how to use InfluxDB write API. // 4 | ////////////////////////////////////////// 5 | 6 | import {InfluxDB, Point, HttpError} from '@influxdata/influxdb-client' 7 | import {url, token, org, bucket} from './env.mjs' 8 | import {hostname} from 'node:os' 9 | 10 | console.log('*** WRITE POINTS ***') 11 | // create a write API, expecting point timestamps in nanoseconds (can be also 's', 'ms', 'us') 12 | const writeApi = new InfluxDB({url, token}).getWriteApi(org, bucket, 'ns') 13 | // setup default tags for all writes through this API 14 | writeApi.useDefaultTags({location: hostname()}) 15 | 16 | // write point with the current (client-side) timestamp 17 | const point1 = new Point('temperature') 18 | .tag('example', 'write.ts') 19 | .floatField('value', 20 + Math.round(100 * Math.random()) / 10) 20 | writeApi.writePoint(point1) 21 | console.log(` ${point1}`) 22 | // write point with a custom timestamp 23 | const point2 = new Point('temperature') 24 | .tag('example', 'write.ts') 25 | .floatField('value', 10 + Math.round(100 * Math.random()) / 10) 26 | .timestamp(new Date()) // can be also a number, but in writeApi's precision units (s, ms, us, ns)! 27 | writeApi.writePoint(point2) 28 | console.log(` ${point2.toLineProtocol(writeApi)}`) 29 | 30 | // WriteApi always buffer data into batches to optimize data transfer to InfluxDB server. 31 | // writeApi.flush() can be called to flush the buffered data. The data is always written 32 | // asynchronously, Moreover, a failed write (caused by a temporary networking or server failure) 33 | // is retried automatically. Read `writeAdvanced.js` for better explanation and details. 34 | // 35 | // close() flushes the remaining buffered data and then cancels pending retries. 36 | try { 37 | await writeApi.close() 38 | console.log('FINISHED ... now try ./query.ts') 39 | } catch (e) { 40 | console.error(e) 41 | if (e instanceof HttpError && e.statusCode === 401) { 42 | console.log('Run ./onboarding.js to setup a new InfluxDB database.') 43 | } 44 | console.log('\nFinished ERROR') 45 | } 46 | -------------------------------------------------------------------------------- /lerna.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.35.0", 3 | "npmClient": "yarn", 4 | "packages": ["packages/*"], 5 | "command": { 6 | "version": { 7 | "message": "chore(release): publish %s [skip CI]" 8 | } 9 | }, 10 | "$schema": "node_modules/lerna/schemas/lerna-schema.json" 11 | } 12 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "description": "InfluxDB 2.x client", 4 | "workspaces": { 5 | "packages": [ 6 | "packages/core", 7 | "packages/core-browser", 8 | "packages/apis", 9 | "packages/giraffe" 10 | ] 11 | }, 12 | "scripts": { 13 | "apidoc": "yarn clean && yarn build && yarn apidoc:extract && yarn apidoc:generate", 14 | "apidoc:ci": "yarn apidoc:extract && yarn apidoc:generate", 15 | "apidoc:extract": "yarn workspaces run apidoc:extract && node scripts/fix-extracted-api-files.js", 16 | "apidoc:generate": "api-documenter markdown -i docs -o docs/dist && cp scripts/gh-pages_config.yml docs/dist/_config.yml && node scripts/enhance-doc-index-md.js", 17 | "apidoc:gh-pages": "gh-pages -d docs/dist -m 'Updates [skip CI]'", 18 | "preinstall": "node ./scripts/require-yarn.js", 19 | "clean": "rimraf temp docs && yarn workspaces run clean", 20 | "build": "yarn workspaces run build", 21 | "test": "yarn --cwd packages/core build && yarn workspaces run test && yarn lint:examples", 22 | "test:ci": "yarn workspaces run test:ci && yarn lint:examples:ci", 23 | "coverage": "cd packages/core && yarn build && yarn coverage && cd ../giraffe && yarn coverage", 24 | "coverage:ci": "cd packages/core && yarn build && yarn coverage:ci && cd ../giraffe && yarn coverage:ci", 25 | "lint:examples": "yarn eslint --ignore-pattern node_modules ./examples", 26 | "lint:examples:ci": "yarn lint:examples --format junit --output-file ./reports/examples_eslint/eslint.xml" 27 | }, 28 | "homepage": "https://github.com/influxdata/influxdb-client-js", 29 | "repository": { 30 | "type": "git", 31 | "url": "git+https://github.com/influxdata/influxdb-client-js" 32 | }, 33 | "keywords": [ 34 | "influxdb", 35 | "influxdata" 36 | ], 37 | "author": { 38 | "name": "InfluxData" 39 | }, 40 | "license": "MIT", 41 | "devDependencies": { 42 | "@microsoft/api-documenter": "^7.19.12", 43 | "@types/node": "^22", 44 | "gh-pages": "^6.0.0", 45 | "lerna": "^8.0.2", 46 | "prettier": "^3.0.3", 47 | "rimraf": "^5.0.1" 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /packages/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "node": true 4 | }, 5 | "rules": { 6 | "no-console": "warn" 7 | }, 8 | "ignorePatterns": ["dist/*.js"] 9 | } 10 | -------------------------------------------------------------------------------- /packages/apis/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "overrides": [ 3 | { 4 | "files": ["src/generated/*.ts"], 5 | "excludedFiles": "*.test.js", 6 | "rules": { 7 | "tsdoc/syntax": "warn" 8 | } 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /packages/apis/.npmignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | build 3 | coverage 4 | doc 5 | .rpt2_cache 6 | .DS_Store 7 | .nyc_output 8 | *.lcov 9 | reports 10 | yarn-error.log 11 | /tsconfig.* 12 | /tsup.* 13 | /.prettierrc.json 14 | /generator 15 | /resources 16 | /src 17 | /test 18 | 19 | -------------------------------------------------------------------------------- /packages/apis/.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true, 3 | "semi": false, 4 | "trailingComma": "es5", 5 | "bracketSpacing": false 6 | } 7 | -------------------------------------------------------------------------------- /packages/apis/DEVELOPMENT.md: -------------------------------------------------------------------------------- 1 | # influxdb-client-apis 2 | 3 | Contains generated client APIs for InfluxDB v2.x. See https://github.com/influxdata/influxdb-client-js to know more. 4 | 5 | ## Build 6 | 7 | ```bash 8 | $ yarn build 9 | ``` 10 | 11 | ## Re-generate APIs code 12 | 13 | ``` 14 | yarn regenerate 15 | ``` 16 | 17 | It performs the following steps: 18 | 19 | - fetch latest versions of openapi files 20 | - re-generate src/generated/types.ts and resources/operations.json using [oats](https://github.com/influxdata/oats) 21 | - generate src/generated APIs from resources/operations.json 22 | - validates the generated output 23 | 24 | Create a new git branch with the regenerated code and submit a new pull request to review the changes. 25 | -------------------------------------------------------------------------------- /packages/apis/README.md: -------------------------------------------------------------------------------- 1 | # @influxdata/influxdb-client-apis 2 | 3 | Contains client APIs for InfluxDB v2.x. See https://github.com/influxdata/influxdb-client-js to know more. 4 | -------------------------------------------------------------------------------- /packages/apis/api-extractor.json: -------------------------------------------------------------------------------- 1 | /** 2 | * Config file for API Extractor. For more info, please visit: https://api-extractor.com 3 | */ 4 | { 5 | "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json", 6 | "extends": "../../scripts/api-extractor-base.json", 7 | "mainEntryPointFilePath": "/dist/index.d.ts" 8 | } 9 | -------------------------------------------------------------------------------- /packages/apis/generator/format.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-console */ 2 | import {Operation} from './operationType' 3 | import logger from './logger' 4 | 5 | export function capitalize1(name: string): string { 6 | return name.charAt(0).toUpperCase() + name.slice(1) 7 | } 8 | export function decapitalize1(name: string): string { 9 | return name.charAt(0).toLowerCase() + name.slice(1) 10 | } 11 | // remember what was computed to issue at most one warning 12 | const computedIds: {[key: string]: string} = {} 13 | export function getOperationId(operation: Operation): string { 14 | if (operation.operationId) return operation.operationId as string 15 | else { 16 | let retVal = computedIds[operation.path] 17 | if (!retVal) { 18 | retVal = operation.path 19 | .split('/') 20 | .map((v: string, i: number) => (i ? v : operation.operation)) 21 | .map(capitalize1) 22 | .join('') 23 | logger.warn( 24 | `no operationId defined for: ${operation.operation} ${operation.path} , using: ${retVal})` 25 | ) 26 | computedIds[operation.path] = retVal 27 | } 28 | return retVal 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /packages/apis/generator/index.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-console */ 2 | import fs from 'fs' 3 | import path from 'path' 4 | import {Operation} from './operationType' 5 | import {generateApi} from './generateApi' 6 | import logger from './logger' 7 | 8 | const operations: Array = JSON.parse( 9 | fs.readFileSync( 10 | path.join( 11 | __dirname, 12 | '..', 13 | 'resources', 14 | process.argv[2] || 'operations.json' 15 | ), 16 | 'utf-8' 17 | ) 18 | ) as Array 19 | 20 | const targetDir = path.join( 21 | __dirname, 22 | '..', 23 | 'src', 24 | process.argv[3] || 'generated' 25 | ) 26 | 27 | // reduce operations to apis 28 | const apis = operations.reduce( 29 | (acc: {[api: string]: Array}, val: Operation) => { 30 | if ( 31 | val.path === '/ready' || 32 | val.path === '/health' || 33 | val.path === '/ping' 34 | ) { 35 | // due to a bug in the swagger parser, we don't have correct server path's 36 | val.server = '' 37 | } 38 | const apiName = val.path.split('/')[1] 39 | ;(acc[apiName] || (acc[apiName] = [])).push(val) 40 | return acc 41 | }, 42 | {} as {[api: string]: Array} 43 | ) 44 | const indexContent = ["export * from './types'"] 45 | for (const key of Object.keys(apis).sort()) { 46 | const {apiName, code} = generateApi(key, apis[key]) 47 | logger.info(apiName + '.ts') 48 | indexContent.push(`export * from './${apiName}'`) 49 | fs.writeFileSync(path.join(targetDir, apiName + '.ts'), code) 50 | } 51 | logger.info('index.ts') 52 | fs.writeFileSync( 53 | path.join(targetDir, 'index.ts'), 54 | indexContent.join('\n') + '\n' 55 | ) 56 | -------------------------------------------------------------------------------- /packages/apis/generator/logger.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-console */ 2 | const logger = { 3 | warn(message: string, ...otherParameters: any[]): void { 4 | message = `\u001b[33m${message}\u001b[0m` // wrap to yellow 5 | if (otherParameters.length) { 6 | console.warn(message, ...otherParameters) 7 | } else { 8 | console.warn(message) 9 | } 10 | }, 11 | info(message: string, ...otherParameters: any[]): void { 12 | console.info(message, ...otherParameters) 13 | }, 14 | } 15 | 16 | export default logger 17 | -------------------------------------------------------------------------------- /packages/apis/generator/operationType.ts: -------------------------------------------------------------------------------- 1 | // type of the operation os operations.json's array 2 | export interface Parameter { 3 | name: string //"Zap-Trace-Span", 4 | description?: string // "OpenTracing span context", 5 | required?: boolean // false, 6 | type: string // "string" 7 | mediaType?: string // "application/json", 8 | } 9 | export interface ResponseBody { 10 | mediaType: string // "application/json", 11 | type: string //"OnboardingResponse" 12 | } 13 | export interface Response { 14 | code: string // "201", "default" 15 | description?: string //"Created default user, bucket, org", 16 | mediaTypes: Array 17 | } 18 | export interface Operation { 19 | server: string //"/api/v2", 20 | path: string //"path": "/setup", 21 | operation: string //"operation": "post", 22 | operationId?: string // "PostSetup", 23 | basicAuth?: boolean //false, 24 | summary?: string // "Set up initial user, org and bucket", 25 | positionalParams: Array 26 | headerParams: Array 27 | queryParams: Array 28 | bodyParam: Omit | null 29 | responses: Array 30 | } 31 | -------------------------------------------------------------------------------- /packages/apis/generator/typesCollector.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Collects types that must be imported for a generated API. 3 | */ 4 | export default class TypesCollector { 5 | types: {[key: string]: boolean} = {} 6 | add(type: string): void { 7 | if (type && type.charAt(0).toUpperCase() === type.charAt(0)) { 8 | if (type.startsWith('{') || type.startsWith('Array<{')) { 9 | // anonymous type; process references to custom types in it 10 | // see typesCollector.test.ts 11 | const customTypeRegExp = / ([A-Z][A-Za-z0-9-_| ]*);\n/g 12 | let match: RegExpExecArray | null 13 | while ((match = customTypeRegExp.exec(type)) !== null) { 14 | // console.log('match[1]', match[1], customTypeRegExp.lastIndex) 15 | this.add(match[1]) 16 | } 17 | } else if (type.endsWith('[]')) { 18 | this.types[type.substring(0, type.length - 2)] = true 19 | } else if (type.includes('|')) { 20 | type 21 | .split('|') 22 | .map((x) => x.trim()) 23 | .forEach((x) => this.add(x)) 24 | } else { 25 | this.types[type] = true 26 | } 27 | } 28 | } 29 | toString(): string { 30 | return Object.keys(this.types).sort().join(', ') 31 | } 32 | hasTypes(): boolean { 33 | return !!Object.keys(this.types).length 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /packages/apis/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@influxdata/influxdb-client-apis", 3 | "version": "1.35.0", 4 | "description": "InfluxDB 2.x generated APIs", 5 | "scripts": { 6 | "apidoc:extract": "api-extractor run", 7 | "build": "yarn run clean && yarn tsup --config ./tsup.config.browser.ts && yarn tsup && node ../../scripts/repair-doc-code-blocks.js ./dist/index.d.ts", 8 | "clean": "rimraf build doc dist reports", 9 | "clean:apis": "rimraf src/generated/*API.ts", 10 | "test": "yarn run lint && yarn run typecheck && yarn run test:unit", 11 | "test:unit": "mocha --require esbuild-runner/register 'test/unit/**/*.test.ts' --exit", 12 | "test:ci": "yarn run typecheck && yarn run lint:ci && yarn run test:unit --reporter mocha-junit-reporter --reporter-options mochaFile=../../reports/apis_mocha/test-results.xml", 13 | "typecheck": "tsc --noEmit --pretty", 14 | "lint": "eslint --max-warnings 0 'src/**/*.ts'", 15 | "lint:ci": "yarn run lint --format junit --output-file ../../reports/apis_eslint/eslint.xml", 16 | "lint:fix": "eslint --fix 'src/**/*.ts'", 17 | "regenerate": "yarn fetchSwaggerFiles && yarn generate && yarn test", 18 | "fetchSwaggerFiles": "node ./scripts/fetchSwaggerFiles.js", 19 | "generate": "yarn generate:clean && yarn generate:types && yarn generate:apis", 20 | "generate:clean": "rm -rf src/generated/*.ts", 21 | "generate:types": "oats -i 'types' --storeOperations resources/operations.json --patchScript $PWD/scripts/patchSwagger.js resources/oss.yml resources/invocable-scripts.yml > src/generated/types.ts && node ../../scripts/repair-doc-code-blocks.js src/generated/types.ts", 22 | "generate:apis": "yarn esr generator && yarn prettier --write src/generated/*.ts" 23 | }, 24 | "main": "dist/index.js", 25 | "module": "dist/index.mjs", 26 | "browser": "dist/index.browser.js", 27 | "types": "dist/index.d.ts", 28 | "exports": { 29 | ".": { 30 | "types": "./dist/index.d.ts", 31 | "browser": { 32 | "import": "./dist/index.mjs", 33 | "require": "./dist/index.js", 34 | "umd": "./dist/index.browser.js", 35 | "script": "./dist/influxdbApis.js" 36 | }, 37 | "deno": "./dist/index.mjs", 38 | "import": "./dist/index.mjs", 39 | "require": "./dist/index.js" 40 | } 41 | }, 42 | "homepage": "https://github.com/influxdata/influxdb-client-js", 43 | "repository": { 44 | "type": "git", 45 | "url": "git+https://github.com/influxdata/influxdb-client-js", 46 | "directory": "packages/apis" 47 | }, 48 | "keywords": [ 49 | "influxdb", 50 | "influxdata" 51 | ], 52 | "author": { 53 | "name": "Pavel Zavora" 54 | }, 55 | "license": "MIT", 56 | "peerDependencies": { 57 | "@influxdata/influxdb-client": "*" 58 | }, 59 | "devDependencies": { 60 | "@influxdata/influxdb-client": "^1.35.0", 61 | "@influxdata/oats": "^0.7.0", 62 | "@microsoft/api-extractor": "^7.31.0", 63 | "@types/mocha": "^10.0.0", 64 | "@typescript-eslint/eslint-plugin": "^7.1.0", 65 | "@typescript-eslint/parser": "^8.0.0", 66 | "chai": "^4.2.0", 67 | "esbuild": "^0.25.0", 68 | "esbuild-runner": "^2.2.1", 69 | "eslint": "^8.18.0", 70 | "eslint-config-prettier": "^10.0.1", 71 | "eslint-plugin-prettier": "^5.0.0", 72 | "eslint-plugin-tsdoc": "^0.4.0", 73 | "mocha": "^11.0.1", 74 | "mocha-junit-reporter": "^2.0.2", 75 | "nock": "^13.2.8", 76 | "prettier": "^3.0.3", 77 | "rimraf": "^5.0.1", 78 | "tsup": "^8.0.2", 79 | "typescript": "^5.1.3" 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /packages/apis/scripts/fetchSwaggerFiles.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/no-var-requires */ 2 | /* eslint-disable no-console */ 3 | /* eslint-disable @typescript-eslint/explicit-function-return-type */ 4 | const https = require('https') 5 | const path = require('path') 6 | const {writeFile} = require('fs/promises') 7 | 8 | function downloadFile(url) { 9 | return new Promise((resolve, reject) => { 10 | https 11 | .get(url, function (res) { 12 | const data = [] 13 | res 14 | .on('data', (chunk) => { 15 | data.push(chunk) 16 | }) 17 | .on('end', () => { 18 | resolve(Buffer.concat(data)) 19 | }) 20 | }) 21 | .on('error', reject) 22 | }) 23 | } 24 | 25 | const FILES = [ 26 | { 27 | file: 'resources/oss.yml', 28 | url: 'https://raw.githubusercontent.com/influxdata/openapi/master/contracts/oss.yml', 29 | }, 30 | { 31 | file: 'resources/invocable-scripts.yml', 32 | url: 'https://raw.githubusercontent.com/influxdata/openapi/master/contracts/invocable-scripts.yml', 33 | }, 34 | { 35 | file: 'resources/cloud.yml', 36 | url: 'https://raw.githubusercontent.com/influxdata/openapi/master/contracts/cloud.yml', 37 | }, 38 | ] 39 | async function downloadFiles() { 40 | for (const {file, url} of FILES) { 41 | console.info(url) 42 | const content = await downloadFile(url) 43 | const fullPath = path.join(__dirname, '..', file) 44 | await writeFile(fullPath, content) 45 | console.log('=>', fullPath, content.length) 46 | } 47 | } 48 | 49 | downloadFiles() 50 | .then(() => console.log('\nFinished SUCCESS')) 51 | .catch((error) => { 52 | console.error(error) 53 | console.log('\nFinished ERROR') 54 | process.exitCode = 1 55 | }) 56 | -------------------------------------------------------------------------------- /packages/apis/scripts/patchSwagger.js: -------------------------------------------------------------------------------- 1 | // Patch function is used by oats tool to modify a swagger document before generating API code. 2 | exports.patch = async (doc, SwaggerParser) => { 3 | // Merges Resource enum values so that the client contains also values from cloud spec 4 | const cloudApi = await SwaggerParser.bundle('./resources/cloud.yml') 5 | const cloudTypes = 6 | cloudApi.components.schemas['Resource']['properties']['type'] 7 | const ossTypes = doc.components.schemas['Resource']['properties']['type'] 8 | ossTypes.enum = ossTypes.enum.concat( 9 | cloudTypes.enum.filter((cloudType) => !ossTypes.enum.includes(cloudType)) 10 | ) 11 | 12 | return doc 13 | } 14 | -------------------------------------------------------------------------------- /packages/apis/src/APIBase.ts: -------------------------------------------------------------------------------- 1 | // this is effectively a clone of 2 | import { 3 | InfluxDB, 4 | Transport, 5 | SendOptions, 6 | Headers, 7 | } from '@influxdata/influxdb-client' 8 | 9 | // used only in browser builds 10 | declare function btoa(plain: string): string 11 | 12 | export interface RequestOptions { 13 | /** HTTP request headers */ 14 | headers?: {[key: string]: string} 15 | /** 16 | * Informs about a start of response processing. 17 | * @param headers - response HTTP headers 18 | * @param statusCode - response status code 19 | */ 20 | responseStarted?: (headers: Headers, statusCode?: number) => void 21 | } 22 | 23 | function base64(value: string): string { 24 | return typeof btoa === 'function' // browser (window,worker) environment 25 | ? btoa(value) 26 | : Buffer.from(value, 'binary').toString('base64') 27 | } 28 | /** 29 | * Base class for all apis. 30 | */ 31 | export class APIBase { 32 | transport: Transport 33 | /** 34 | * Initializes transport to communicate with InfluxDB. 35 | * @param influxDB - the main InfluxDB client object 36 | */ 37 | constructor(influxDB: InfluxDB) { 38 | if (!influxDB) throw new Error('No influxDB supplied!') 39 | if (!influxDB.transport) throw new Error('No transport supplied!') 40 | this.transport = influxDB.transport 41 | } 42 | 43 | queryString(request: any, params: string[]): string { 44 | if (request && params) { 45 | return params.reduce((acc, key) => { 46 | const val = request[key] 47 | if (val !== undefined && val !== null) { 48 | acc += acc ? '&' : '?' 49 | acc += encodeURIComponent(key) + '=' + encodeURIComponent(String(val)) 50 | } 51 | return acc 52 | }, '') 53 | } else { 54 | return '' 55 | } 56 | } 57 | 58 | request( 59 | method: string, 60 | path: string, 61 | request: any = {}, 62 | requestOptions?: RequestOptions, 63 | mediaType?: string 64 | ): Promise { 65 | const sendOptions: SendOptions = { 66 | ...requestOptions, 67 | method, 68 | } 69 | if (mediaType) { 70 | ;(sendOptions.headers || (sendOptions.headers = {}))['content-type'] = 71 | mediaType 72 | } 73 | if (request.auth) { 74 | const value = `${request.auth.user}:${request.auth.password}` 75 | ;(sendOptions.headers || (sendOptions.headers = {}))['authorization'] = 76 | `Basic ${base64(value)}` 77 | } 78 | return this.transport.request( 79 | path, 80 | request.body ? request.body : '', 81 | sendOptions, 82 | requestOptions?.responseStarted 83 | ) 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /packages/apis/src/custom/FluxScriptInvocationAPI.ts: -------------------------------------------------------------------------------- 1 | import { 2 | InfluxDB, 3 | Transport, 4 | AnnotatedCSVResponse, 5 | } from '@influxdata/influxdb-client' 6 | 7 | /** ExecutionOptions contains execution options for a flux script. */ 8 | export interface ExecutionOptions { 9 | /** 10 | * Requests gzip encoded response. 11 | */ 12 | gzip?: boolean 13 | /** 14 | * HTTP headers that will be sent with every query request. 15 | */ 16 | headers?: {[key: string]: string} 17 | } 18 | 19 | /** 20 | * FluxScriptInvocationAPI executes flux 'API invokable script' and parses the result CSV annotated data. 21 | * See https://docs.influxdata.com/influxdb/cloud/api-guide/api-invokable-scripts/ . 22 | */ 23 | export class FluxScriptInvocationAPI { 24 | // internal 25 | private transport: Transport 26 | private processCSVResponse: InfluxDB['processCSVResponse'] 27 | private options: ExecutionOptions 28 | 29 | /** 30 | * Creates FluxScriptInvocationAPI with the supplied InfluxDB instance and a particular script identifier. 31 | * @param influxDB - an instance that knows how to communicate with InfluxDB server 32 | * @param options - script execution options 33 | */ 34 | constructor(influxDB: InfluxDB, options?: ExecutionOptions) { 35 | this.transport = influxDB.transport 36 | this.processCSVResponse = influxDB.processCSVResponse 37 | this.options = {...options} 38 | } 39 | 40 | /** 41 | * Invoke returns a parsed response data stream that executes 42 | * the supplied script when asked for data. 43 | * @param scriptID - script identifier 44 | * @param params - script parameters 45 | * @returns response with various methods to process data from the returned annotated 46 | * CSV response data stream 47 | */ 48 | invoke(scriptID: string, params?: Record): AnnotatedCSVResponse { 49 | const {gzip, headers} = this.options 50 | const path = `/api/v2/scripts/${scriptID}/invoke` 51 | const body = JSON.stringify({ 52 | params: {...params}, 53 | }) 54 | const options = { 55 | method: 'POST', 56 | headers: { 57 | 'content-type': 'application/json; encoding=utf-8', 58 | 'accept-encoding': gzip ? 'gzip' : 'identity', 59 | ...headers, 60 | }, 61 | } 62 | return this.processCSVResponse( 63 | (consumer) => this.transport.send(path, body, options, consumer), 64 | () => this.transport.iterate(path, body, options) 65 | ) 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /packages/apis/src/custom/index.ts: -------------------------------------------------------------------------------- 1 | export * from './FluxScriptInvocationAPI' 2 | -------------------------------------------------------------------------------- /packages/apis/src/generated/BackupAPI.ts: -------------------------------------------------------------------------------- 1 | import {InfluxDB} from '@influxdata/influxdb-client' 2 | import {APIBase, RequestOptions} from '../APIBase' 3 | import {MetadataBackup} from './types' 4 | 5 | export interface GetBackupKVRequest {} 6 | export interface GetBackupMetadataRequest {} 7 | export interface GetBackupShardIdRequest { 8 | /** The shard ID. */ 9 | shardID: number 10 | /** The earliest time [RFC3339 date/time format](https://docs.influxdata.com/influxdb/v2.3/reference/glossary/#rfc3339-timestamp) to include in the snapshot. */ 11 | since?: string 12 | } 13 | /** 14 | * Backup API 15 | */ 16 | export class BackupAPI { 17 | // internal 18 | private base: APIBase 19 | 20 | /** 21 | * Creates BackupAPI 22 | * @param influxDB - an instance that knows how to communicate with InfluxDB server 23 | */ 24 | constructor(influxDB: InfluxDB) { 25 | this.base = new APIBase(influxDB) 26 | } 27 | /** 28 | * Download snapshot of metadata stored in the server's embedded KV store. Don't use with InfluxDB versions greater than InfluxDB 2.1.x. 29 | * See {@link https://docs.influxdata.com/influxdb/v2.4/api/#operation/GetBackupKV } 30 | * @param request - request parameters and body (if supported) 31 | * @param requestOptions - optional transport options 32 | * @returns promise of response 33 | */ 34 | getBackupKV( 35 | request?: GetBackupKVRequest, 36 | requestOptions?: RequestOptions 37 | ): Promise { 38 | return this.base.request( 39 | 'GET', 40 | `/api/v2/backup/kv`, 41 | request, 42 | requestOptions 43 | ) 44 | } 45 | /** 46 | * Download snapshot of all metadata in the server. 47 | * See {@link https://docs.influxdata.com/influxdb/v2.4/api/#operation/GetBackupMetadata } 48 | * @param request - request parameters and body (if supported) 49 | * @param requestOptions - optional transport options 50 | * @returns promise of response 51 | */ 52 | getBackupMetadata( 53 | request?: GetBackupMetadataRequest, 54 | requestOptions?: RequestOptions 55 | ): Promise { 56 | return this.base.request( 57 | 'GET', 58 | `/api/v2/backup/metadata`, 59 | request, 60 | requestOptions 61 | ) 62 | } 63 | /** 64 | * Download snapshot of all TSM data in a shard. 65 | * See {@link https://docs.influxdata.com/influxdb/v2.4/api/#operation/GetBackupShardId } 66 | * @param request - request parameters and body (if supported) 67 | * @param requestOptions - optional transport options 68 | * @returns promise of response 69 | */ 70 | getBackupShardId( 71 | request: GetBackupShardIdRequest, 72 | requestOptions?: RequestOptions 73 | ): Promise { 74 | return this.base.request( 75 | 'GET', 76 | `/api/v2/backup/shards/${request.shardID}${this.base.queryString( 77 | request, 78 | ['since'] 79 | )}`, 80 | request, 81 | requestOptions 82 | ) 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /packages/apis/src/generated/ConfigAPI.ts: -------------------------------------------------------------------------------- 1 | import {InfluxDB} from '@influxdata/influxdb-client' 2 | import {APIBase, RequestOptions} from '../APIBase' 3 | import {Config} from './types' 4 | 5 | export interface GetConfigRequest {} 6 | /** 7 | * Config API 8 | */ 9 | export class ConfigAPI { 10 | // internal 11 | private base: APIBase 12 | 13 | /** 14 | * Creates ConfigAPI 15 | * @param influxDB - an instance that knows how to communicate with InfluxDB server 16 | */ 17 | constructor(influxDB: InfluxDB) { 18 | this.base = new APIBase(influxDB) 19 | } 20 | /** 21 | * Retrieve runtime configuration. 22 | * See {@link https://docs.influxdata.com/influxdb/v2.4/api/#operation/GetConfig } 23 | * @param request - request parameters and body (if supported) 24 | * @param requestOptions - optional transport options 25 | * @returns promise of response 26 | */ 27 | getConfig( 28 | request?: GetConfigRequest, 29 | requestOptions?: RequestOptions 30 | ): Promise { 31 | return this.base.request('GET', `/api/v2/config`, request, requestOptions) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /packages/apis/src/generated/DeleteAPI.ts: -------------------------------------------------------------------------------- 1 | import {InfluxDB} from '@influxdata/influxdb-client' 2 | import {APIBase, RequestOptions} from '../APIBase' 3 | import {DeletePredicateRequest} from './types' 4 | 5 | export interface PostDeleteRequest { 6 | /** Time range parameters and an optional **delete predicate expression**. 7 | 8 | To select points to delete within the specified time range, pass a 9 | **delete predicate expression** in the `predicate` property of the request body. 10 | If you don't pass a `predicate`, InfluxDB deletes all data with timestamps 11 | in the specified time range. 12 | 13 | #### Related guides 14 | 15 | - [Delete data](https://docs.influxdata.com/influxdb/v2.3/write-data/delete-data/). 16 | - Learn how to use [delete predicate syntax](https://docs.influxdata.com/influxdb/v2.3/reference/syntax/delete-predicate/). 17 | */ 18 | body: DeletePredicateRequest 19 | /** The organization to delete data from. 20 | If you pass both `orgID` and `org`, they must both be valid. 21 | 22 | #### InfluxDB Cloud 23 | 24 | - Doesn't require `org` or `orgID`. 25 | - Deletes data from the bucket in the organization associated with the authorization (API token). 26 | 27 | #### InfluxDB OSS 28 | 29 | - Requires either `org` or `orgID`. 30 | */ 31 | org?: string 32 | /** The name or ID of the bucket to delete data from. 33 | If you pass both `bucket` and `bucketID`, `bucketID` takes precedence. 34 | */ 35 | bucket?: string 36 | /** The ID of the organization to delete data from. 37 | If you pass both `orgID` and `org`, they must both be valid. 38 | 39 | #### InfluxDB Cloud 40 | 41 | - Doesn't require `org` or `orgID`. 42 | - Deletes data from the bucket in the organization associated with the authorization (API token). 43 | 44 | #### InfluxDB OSS 45 | 46 | - Requires either `org` or `orgID`. 47 | */ 48 | orgID?: string 49 | /** The ID of the bucket to delete data from. 50 | If you pass both `bucket` and `bucketID`, `bucketID` takes precedence. 51 | */ 52 | bucketID?: string 53 | } 54 | /** 55 | * Delete API 56 | */ 57 | export class DeleteAPI { 58 | // internal 59 | private base: APIBase 60 | 61 | /** 62 | * Creates DeleteAPI 63 | * @param influxDB - an instance that knows how to communicate with InfluxDB server 64 | */ 65 | constructor(influxDB: InfluxDB) { 66 | this.base = new APIBase(influxDB) 67 | } 68 | /** 69 | * Delete data. 70 | * See {@link https://docs.influxdata.com/influxdb/v2.4/api/#operation/PostDelete } 71 | * @param request - request parameters and body (if supported) 72 | * @param requestOptions - optional transport options 73 | * @returns promise of response 74 | */ 75 | postDelete( 76 | request: PostDeleteRequest, 77 | requestOptions?: RequestOptions 78 | ): Promise { 79 | return this.base.request( 80 | 'POST', 81 | `/api/v2/delete${this.base.queryString(request, [ 82 | 'org', 83 | 'bucket', 84 | 'orgID', 85 | 'bucketID', 86 | ])}`, 87 | request, 88 | requestOptions, 89 | 'application/json' 90 | ) 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /packages/apis/src/generated/FlagsAPI.ts: -------------------------------------------------------------------------------- 1 | import {InfluxDB} from '@influxdata/influxdb-client' 2 | import {APIBase, RequestOptions} from '../APIBase' 3 | import {Flags} from './types' 4 | 5 | export interface GetFlagsRequest {} 6 | /** 7 | * Flags API 8 | */ 9 | export class FlagsAPI { 10 | // internal 11 | private base: APIBase 12 | 13 | /** 14 | * Creates FlagsAPI 15 | * @param influxDB - an instance that knows how to communicate with InfluxDB server 16 | */ 17 | constructor(influxDB: InfluxDB) { 18 | this.base = new APIBase(influxDB) 19 | } 20 | /** 21 | * Return the feature flags for the currently authenticated user. 22 | * See {@link https://docs.influxdata.com/influxdb/v2.4/api/#operation/GetFlags } 23 | * @param request - request parameters and body (if supported) 24 | * @param requestOptions - optional transport options 25 | * @returns promise of response 26 | */ 27 | getFlags( 28 | request?: GetFlagsRequest, 29 | requestOptions?: RequestOptions 30 | ): Promise { 31 | return this.base.request('GET', `/api/v2/flags`, request, requestOptions) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /packages/apis/src/generated/HealthAPI.ts: -------------------------------------------------------------------------------- 1 | import {InfluxDB} from '@influxdata/influxdb-client' 2 | import {APIBase, RequestOptions} from '../APIBase' 3 | import {HealthCheck} from './types' 4 | 5 | export interface GetHealthRequest {} 6 | /** 7 | * Health API 8 | */ 9 | export class HealthAPI { 10 | // internal 11 | private base: APIBase 12 | 13 | /** 14 | * Creates HealthAPI 15 | * @param influxDB - an instance that knows how to communicate with InfluxDB server 16 | */ 17 | constructor(influxDB: InfluxDB) { 18 | this.base = new APIBase(influxDB) 19 | } 20 | /** 21 | * Retrieve the health of the instance. 22 | * See {@link https://docs.influxdata.com/influxdb/v2.4/api/#operation/GetHealth } 23 | * @param request - request parameters and body (if supported) 24 | * @param requestOptions - optional transport options 25 | * @returns promise of response 26 | */ 27 | getHealth( 28 | request?: GetHealthRequest, 29 | requestOptions?: RequestOptions 30 | ): Promise { 31 | return this.base.request('GET', `/health`, request, requestOptions) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /packages/apis/src/generated/MeAPI.ts: -------------------------------------------------------------------------------- 1 | import {InfluxDB} from '@influxdata/influxdb-client' 2 | import {APIBase, RequestOptions} from '../APIBase' 3 | import {PasswordResetBody, UserResponse} from './types' 4 | 5 | export interface GetMeRequest {} 6 | export interface PutMePasswordRequest { 7 | auth?: {user: string; password: string} 8 | /** The new password. */ 9 | body: PasswordResetBody 10 | } 11 | /** 12 | * Me API 13 | */ 14 | export class MeAPI { 15 | // internal 16 | private base: APIBase 17 | 18 | /** 19 | * Creates MeAPI 20 | * @param influxDB - an instance that knows how to communicate with InfluxDB server 21 | */ 22 | constructor(influxDB: InfluxDB) { 23 | this.base = new APIBase(influxDB) 24 | } 25 | /** 26 | * Retrieve the currently authenticated user. 27 | * See {@link https://docs.influxdata.com/influxdb/v2.4/api/#operation/GetMe } 28 | * @param request - request parameters and body (if supported) 29 | * @param requestOptions - optional transport options 30 | * @returns promise of response 31 | */ 32 | getMe( 33 | request?: GetMeRequest, 34 | requestOptions?: RequestOptions 35 | ): Promise { 36 | return this.base.request('GET', `/api/v2/me`, request, requestOptions) 37 | } 38 | /** 39 | * Update a password. 40 | * See {@link https://docs.influxdata.com/influxdb/v2.4/api/#operation/PutMePassword } 41 | * @param request - request parameters and body (if supported) 42 | * @param requestOptions - optional transport options 43 | * @returns promise of response 44 | */ 45 | putMePassword( 46 | request: PutMePasswordRequest, 47 | requestOptions?: RequestOptions 48 | ): Promise { 49 | return this.base.request( 50 | 'PUT', 51 | `/api/v2/me/password`, 52 | request, 53 | requestOptions, 54 | 'application/json' 55 | ) 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /packages/apis/src/generated/MetricsAPI.ts: -------------------------------------------------------------------------------- 1 | import {InfluxDB} from '@influxdata/influxdb-client' 2 | import {APIBase, RequestOptions} from '../APIBase' 3 | 4 | export interface GetMetricsRequest {} 5 | /** 6 | * Metrics API 7 | */ 8 | export class MetricsAPI { 9 | // internal 10 | private base: APIBase 11 | 12 | /** 13 | * Creates MetricsAPI 14 | * @param influxDB - an instance that knows how to communicate with InfluxDB server 15 | */ 16 | constructor(influxDB: InfluxDB) { 17 | this.base = new APIBase(influxDB) 18 | } 19 | /** 20 | * Retrieve workload performance metrics. 21 | * See {@link https://docs.influxdata.com/influxdb/v2.4/api/#operation/GetMetrics } 22 | * @param request - request parameters and body (if supported) 23 | * @param requestOptions - optional transport options 24 | * @returns promise of response 25 | */ 26 | getMetrics( 27 | request?: GetMetricsRequest, 28 | requestOptions?: RequestOptions 29 | ): Promise { 30 | return this.base.request('GET', `/api/v2/metrics`, request, requestOptions) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /packages/apis/src/generated/PingAPI.ts: -------------------------------------------------------------------------------- 1 | import {InfluxDB} from '@influxdata/influxdb-client' 2 | import {APIBase, RequestOptions} from '../APIBase' 3 | 4 | export interface GetPingRequest {} 5 | /** 6 | * Ping API 7 | */ 8 | export class PingAPI { 9 | // internal 10 | private base: APIBase 11 | 12 | /** 13 | * Creates PingAPI 14 | * @param influxDB - an instance that knows how to communicate with InfluxDB server 15 | */ 16 | constructor(influxDB: InfluxDB) { 17 | this.base = new APIBase(influxDB) 18 | } 19 | /** 20 | * Get the status and version of the instance. 21 | * See {@link https://docs.influxdata.com/influxdb/v2.4/api/#operation/GetPing } 22 | * @param request - request parameters and body (if supported) 23 | * @param requestOptions - optional transport options 24 | * @returns promise of response 25 | */ 26 | getPing( 27 | request?: GetPingRequest, 28 | requestOptions?: RequestOptions 29 | ): Promise { 30 | return this.base.request('GET', `/ping`, request, requestOptions) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /packages/apis/src/generated/ReadyAPI.ts: -------------------------------------------------------------------------------- 1 | import {InfluxDB} from '@influxdata/influxdb-client' 2 | import {APIBase, RequestOptions} from '../APIBase' 3 | import {Ready} from './types' 4 | 5 | export interface GetReadyRequest {} 6 | /** 7 | * Ready API 8 | */ 9 | export class ReadyAPI { 10 | // internal 11 | private base: APIBase 12 | 13 | /** 14 | * Creates ReadyAPI 15 | * @param influxDB - an instance that knows how to communicate with InfluxDB server 16 | */ 17 | constructor(influxDB: InfluxDB) { 18 | this.base = new APIBase(influxDB) 19 | } 20 | /** 21 | * Get the readiness of an instance at startup. 22 | * See {@link https://docs.influxdata.com/influxdb/v2.4/api/#operation/GetReady } 23 | * @param request - request parameters and body (if supported) 24 | * @param requestOptions - optional transport options 25 | * @returns promise of response 26 | */ 27 | getReady( 28 | request?: GetReadyRequest, 29 | requestOptions?: RequestOptions 30 | ): Promise { 31 | return this.base.request('GET', `/ready`, request, requestOptions) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /packages/apis/src/generated/ResourcesAPI.ts: -------------------------------------------------------------------------------- 1 | import {InfluxDB} from '@influxdata/influxdb-client' 2 | import {APIBase, RequestOptions} from '../APIBase' 3 | 4 | export interface GetResourcesRequest {} 5 | /** 6 | * Resources API 7 | */ 8 | export class ResourcesAPI { 9 | // internal 10 | private base: APIBase 11 | 12 | /** 13 | * Creates ResourcesAPI 14 | * @param influxDB - an instance that knows how to communicate with InfluxDB server 15 | */ 16 | constructor(influxDB: InfluxDB) { 17 | this.base = new APIBase(influxDB) 18 | } 19 | /** 20 | * List all known resources. 21 | * See {@link https://docs.influxdata.com/influxdb/v2.4/api/#operation/GetResources } 22 | * @param request - request parameters and body (if supported) 23 | * @param requestOptions - optional transport options 24 | * @returns promise of response 25 | */ 26 | getResources( 27 | request?: GetResourcesRequest, 28 | requestOptions?: RequestOptions 29 | ): Promise { 30 | return this.base.request( 31 | 'GET', 32 | `/api/v2/resources`, 33 | request, 34 | requestOptions 35 | ) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /packages/apis/src/generated/RootAPI.ts: -------------------------------------------------------------------------------- 1 | import {InfluxDB} from '@influxdata/influxdb-client' 2 | import {APIBase, RequestOptions} from '../APIBase' 3 | import {Routes} from './types' 4 | 5 | export interface GetRoutesRequest {} 6 | /** 7 | * Root API 8 | */ 9 | export class RootAPI { 10 | // internal 11 | private base: APIBase 12 | 13 | /** 14 | * Creates RootAPI 15 | * @param influxDB - an instance that knows how to communicate with InfluxDB server 16 | */ 17 | constructor(influxDB: InfluxDB) { 18 | this.base = new APIBase(influxDB) 19 | } 20 | /** 21 | * List all top level routes. 22 | * See {@link https://docs.influxdata.com/influxdb/v2.4/api/#operation/GetRoutes } 23 | * @param request - request parameters and body (if supported) 24 | * @param requestOptions - optional transport options 25 | * @returns promise of response 26 | */ 27 | getRoutes( 28 | request?: GetRoutesRequest, 29 | requestOptions?: RequestOptions 30 | ): Promise { 31 | return this.base.request('GET', `/api/v2/`, request, requestOptions) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /packages/apis/src/generated/SetupAPI.ts: -------------------------------------------------------------------------------- 1 | import {InfluxDB} from '@influxdata/influxdb-client' 2 | import {APIBase, RequestOptions} from '../APIBase' 3 | import {IsOnboarding, OnboardingRequest, OnboardingResponse} from './types' 4 | 5 | export interface GetSetupRequest {} 6 | export interface PostSetupRequest { 7 | /** Source to create */ 8 | body: OnboardingRequest 9 | } 10 | /** 11 | * Setup API 12 | */ 13 | export class SetupAPI { 14 | // internal 15 | private base: APIBase 16 | 17 | /** 18 | * Creates SetupAPI 19 | * @param influxDB - an instance that knows how to communicate with InfluxDB server 20 | */ 21 | constructor(influxDB: InfluxDB) { 22 | this.base = new APIBase(influxDB) 23 | } 24 | /** 25 | * Check if database has default user, org, bucket. 26 | * See {@link https://docs.influxdata.com/influxdb/v2.4/api/#operation/GetSetup } 27 | * @param request - request parameters and body (if supported) 28 | * @param requestOptions - optional transport options 29 | * @returns promise of response 30 | */ 31 | getSetup( 32 | request?: GetSetupRequest, 33 | requestOptions?: RequestOptions 34 | ): Promise { 35 | return this.base.request('GET', `/api/v2/setup`, request, requestOptions) 36 | } 37 | /** 38 | * Set up initial user, org and bucket. 39 | * See {@link https://docs.influxdata.com/influxdb/v2.4/api/#operation/PostSetup } 40 | * @param request - request parameters and body (if supported) 41 | * @param requestOptions - optional transport options 42 | * @returns promise of response 43 | */ 44 | postSetup( 45 | request: PostSetupRequest, 46 | requestOptions?: RequestOptions 47 | ): Promise { 48 | return this.base.request( 49 | 'POST', 50 | `/api/v2/setup`, 51 | request, 52 | requestOptions, 53 | 'application/json' 54 | ) 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /packages/apis/src/generated/SigninAPI.ts: -------------------------------------------------------------------------------- 1 | import {InfluxDB} from '@influxdata/influxdb-client' 2 | import {APIBase, RequestOptions} from '../APIBase' 3 | 4 | export interface PostSigninRequest { 5 | auth?: {user: string; password: string} 6 | } 7 | /** 8 | * Signin API 9 | */ 10 | export class SigninAPI { 11 | // internal 12 | private base: APIBase 13 | 14 | /** 15 | * Creates SigninAPI 16 | * @param influxDB - an instance that knows how to communicate with InfluxDB server 17 | */ 18 | constructor(influxDB: InfluxDB) { 19 | this.base = new APIBase(influxDB) 20 | } 21 | /** 22 | * Create a user session. 23 | * See {@link https://docs.influxdata.com/influxdb/v2.4/api/#operation/PostSignin } 24 | * @param request - request parameters and body (if supported) 25 | * @param requestOptions - optional transport options 26 | * @returns promise of response 27 | */ 28 | postSignin( 29 | request: PostSigninRequest, 30 | requestOptions?: RequestOptions 31 | ): Promise { 32 | return this.base.request('POST', `/api/v2/signin`, request, requestOptions) 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /packages/apis/src/generated/SignoutAPI.ts: -------------------------------------------------------------------------------- 1 | import {InfluxDB} from '@influxdata/influxdb-client' 2 | import {APIBase, RequestOptions} from '../APIBase' 3 | 4 | export interface PostSignoutRequest {} 5 | /** 6 | * Signout API 7 | */ 8 | export class SignoutAPI { 9 | // internal 10 | private base: APIBase 11 | 12 | /** 13 | * Creates SignoutAPI 14 | * @param influxDB - an instance that knows how to communicate with InfluxDB server 15 | */ 16 | constructor(influxDB: InfluxDB) { 17 | this.base = new APIBase(influxDB) 18 | } 19 | /** 20 | * Expire the current UI session. 21 | * See {@link https://docs.influxdata.com/influxdb/v2.4/api/#operation/PostSignout } 22 | * @param request - request parameters and body (if supported) 23 | * @param requestOptions - optional transport options 24 | * @returns promise of response 25 | */ 26 | postSignout( 27 | request?: PostSignoutRequest, 28 | requestOptions?: RequestOptions 29 | ): Promise { 30 | return this.base.request('POST', `/api/v2/signout`, request, requestOptions) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /packages/apis/src/generated/TelegrafAPI.ts: -------------------------------------------------------------------------------- 1 | import {InfluxDB} from '@influxdata/influxdb-client' 2 | import {APIBase, RequestOptions} from '../APIBase' 3 | import {TelegrafPlugins} from './types' 4 | 5 | export interface GetTelegrafPluginsRequest { 6 | /** The type of plugin desired. */ 7 | type?: string 8 | } 9 | /** 10 | * Telegraf API 11 | */ 12 | export class TelegrafAPI { 13 | // internal 14 | private base: APIBase 15 | 16 | /** 17 | * Creates TelegrafAPI 18 | * @param influxDB - an instance that knows how to communicate with InfluxDB server 19 | */ 20 | constructor(influxDB: InfluxDB) { 21 | this.base = new APIBase(influxDB) 22 | } 23 | /** 24 | * List all Telegraf plugins. 25 | * See {@link https://docs.influxdata.com/influxdb/v2.4/api/#operation/GetTelegrafPlugins } 26 | * @param request - request parameters and body (if supported) 27 | * @param requestOptions - optional transport options 28 | * @returns promise of response 29 | */ 30 | getTelegrafPlugins( 31 | request?: GetTelegrafPluginsRequest, 32 | requestOptions?: RequestOptions 33 | ): Promise { 34 | return this.base.request( 35 | 'GET', 36 | `/api/v2/telegraf/plugins${this.base.queryString(request, ['type'])}`, 37 | request, 38 | requestOptions 39 | ) 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /packages/apis/src/generated/TemplatesAPI.ts: -------------------------------------------------------------------------------- 1 | import {InfluxDB} from '@influxdata/influxdb-client' 2 | import {APIBase, RequestOptions} from '../APIBase' 3 | import { 4 | Template, 5 | TemplateApply, 6 | TemplateExportByID, 7 | TemplateExportByName, 8 | TemplateSummary, 9 | } from './types' 10 | 11 | export interface ApplyTemplateRequest { 12 | /** Parameters for applying templates. 13 | */ 14 | body: TemplateApply 15 | } 16 | export interface ExportTemplateRequest { 17 | /** Export resources as an InfluxDB template. */ 18 | body: TemplateExportByID | TemplateExportByName 19 | } 20 | /** 21 | * Templates API 22 | */ 23 | export class TemplatesAPI { 24 | // internal 25 | private base: APIBase 26 | 27 | /** 28 | * Creates TemplatesAPI 29 | * @param influxDB - an instance that knows how to communicate with InfluxDB server 30 | */ 31 | constructor(influxDB: InfluxDB) { 32 | this.base = new APIBase(influxDB) 33 | } 34 | /** 35 | * Apply or dry-run a template. 36 | * See {@link https://docs.influxdata.com/influxdb/v2.4/api/#operation/ApplyTemplate } 37 | * @param request - request parameters and body (if supported) 38 | * @param requestOptions - optional transport options 39 | * @returns promise of response 40 | */ 41 | applyTemplate( 42 | request: ApplyTemplateRequest, 43 | requestOptions?: RequestOptions 44 | ): Promise { 45 | return this.base.request( 46 | 'POST', 47 | `/api/v2/templates/apply`, 48 | request, 49 | requestOptions, 50 | 'application/json' 51 | ) 52 | } 53 | /** 54 | * Export a new template. 55 | * See {@link https://docs.influxdata.com/influxdb/v2.4/api/#operation/ExportTemplate } 56 | * @param request - request parameters and body (if supported) 57 | * @param requestOptions - optional transport options 58 | * @returns promise of response 59 | */ 60 | exportTemplate( 61 | request: ExportTemplateRequest, 62 | requestOptions?: RequestOptions 63 | ): Promise