From 30c4eb253c5041d77260dd131b2bca6ae29b92ab Mon Sep 17 00:00:00 2001 From: Peter Murray <681306+peter-murray@users.noreply.github.com> Date: Mon, 10 Apr 2023 19:11:17 +0100 Subject: [PATCH] Updating to support possible ES modules and fix imports to work under Node.js 19 properly, #220 --- .mocharc.json | 6 + package-lock.json | 169 ++++++++---------- package.json | 6 +- src/ApiError.ts | 2 +- src/api/Api.ts | 32 ++-- src/api/Cache.ts | 2 +- src/api/Capabilities.ts | 6 +- src/api/Configuration.ts | 6 +- src/api/Groups.ts | 8 +- src/api/HueApiConfig.ts | 6 +- src/api/HueRateLimiter.ts | 4 +- src/api/Lights.ts | 16 +- src/api/Remote.ts | 6 +- src/api/ResourceLinks.ts | 6 +- src/api/Rules.ts | 8 +- src/api/Scenes.ts | 10 +- src/api/Schedules.ts | 6 +- src/api/Sensors.ts | 8 +- src/api/Users.test.ts | 8 +- src/api/Users.ts | 10 +- src/api/discovery/UPnP.test.ts | 2 +- src/api/discovery/UPnP.ts | 2 +- src/api/discovery/bridge-validation.test.ts | 5 +- src/api/discovery/bridge-validation.ts | 6 +- src/api/discovery/index.test.ts | 4 +- src/api/discovery/index.ts | 8 +- src/api/discovery/mDNS.test.ts | 2 +- src/api/discovery/mDNS.ts | 8 +- src/api/discovery/nupnp.test.ts | 2 +- src/api/discovery/nupnp.ts | 8 +- src/api/http/ApiDefinition.ts | 6 +- src/api/http/HttpClientFetch.ts | 2 +- src/api/http/LocalBootstrap.ts | 16 +- src/api/http/LocalInsecureBootstrap.ts | 12 +- src/api/http/OAuthTokens.ts | 2 +- src/api/http/RemoteApi.ts | 10 +- src/api/http/RemoteBootstrap.ts | 12 +- src/api/http/Transport.ts | 14 +- src/api/http/endpoints/ApiEndpoint.ts | 6 +- src/api/http/endpoints/capabilities.ts | 4 +- src/api/http/endpoints/configuration.ts | 10 +- src/api/http/endpoints/groups.ts | 10 +- src/api/http/endpoints/lights.ts | 12 +- src/api/http/endpoints/resourceLinks.ts | 10 +- src/api/http/endpoints/rules.ts | 10 +- src/api/http/endpoints/scenes.ts | 12 +- src/api/http/endpoints/schedules.ts | 10 +- src/api/http/endpoints/sensors.ts | 10 +- src/api/http/urlUtil.test.ts | 2 +- src/api/index.ts | 8 +- src/api/placeholders/GroupIdPlaceholder.ts | 2 +- src/api/placeholders/LightIdPlaceholder.ts | 2 +- src/api/placeholders/Placeholder.ts | 4 +- .../placeholders/ResourceLinkPlaceholder.ts | 2 +- src/api/placeholders/RuleIdPlaceholder.ts | 2 +- src/api/placeholders/SceneIdPlaceholder.ts | 2 +- src/api/placeholders/ScheduleIdPlaceholder.ts | 2 +- src/api/placeholders/SensorIdPlaceholder.ts | 2 +- src/api/placeholders/UsernamePlaceholder.ts | 2 +- src/index.ts | 8 +- src/rgb.ts | 2 +- src/util.ts | 6 +- src/v3.ts | 8 +- tsconfig.json | 10 +- 64 files changed, 295 insertions(+), 309 deletions(-) create mode 100644 .mocharc.json diff --git a/.mocharc.json b/.mocharc.json new file mode 100644 index 0000000..92571ca --- /dev/null +++ b/.mocharc.json @@ -0,0 +1,6 @@ +{ + "node-option": [ + "experimental-specifier-resolution=node", + "loader=ts-node/esm" + ] +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 3e4acc6..7d83ab6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,13 +12,12 @@ "@peter-murray/hue-bridge-model": "^2.0.1", "bottleneck": "^2.19.5", "node-dns-sd": "^1.0.1", - "node-fetch": "^2.6.1" + "node-fetch": "^3.3.1" }, "devDependencies": { "@types/chai": "^4.3.0", "@types/mocha": "^9.0.0", "@types/node": "^18.15.11", - "@types/node-fetch": "^2.5.12", "chai": "~4.3.4", "mocha": "^9.1.3", "ts-node": "^10.4.0", @@ -115,16 +114,6 @@ "integrity": "sha512-E5Kwq2n4SbMzQOn6wnmBjuK9ouqlURrcZDVfbo9ftDDTFt3nk7ZKK4GMOzoYgnpQJKcxwQw+lGaBvvlMo0qN/Q==", "dev": true }, - "node_modules/@types/node-fetch": { - "version": "2.6.3", - "resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.6.3.tgz", - "integrity": "sha512-ETTL1mOEdq/sxUtgtOhKjyB2Irra4cjxksvcMUR5Zr4n+PxVhsCD9WS46oPbHL3et9Zde7CNRr+WUNlcHvsX+w==", - "dev": true, - "dependencies": { - "@types/node": "*", - "form-data": "^3.0.0" - } - }, "node_modules/@ungap/promise-all-settled": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/@ungap/promise-all-settled/-/promise-all-settled-1.1.2.tgz", @@ -219,12 +208,6 @@ "node": "*" } }, - "node_modules/asynckit": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", - "dev": true - }, "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", @@ -396,18 +379,6 @@ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "dev": true }, - "node_modules/combined-stream": { - "version": "1.0.8", - "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", - "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", - "dev": true, - "dependencies": { - "delayed-stream": "~1.0.0" - }, - "engines": { - "node": ">= 0.8" - } - }, "node_modules/concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", @@ -420,6 +391,14 @@ "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", "dev": true }, + "node_modules/data-uri-to-buffer": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz", + "integrity": "sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==", + "engines": { + "node": ">= 12" + } + }, "node_modules/debug": { "version": "4.3.3", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.3.tgz", @@ -467,15 +446,6 @@ "node": ">=6" } }, - "node_modules/delayed-stream": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", - "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", - "dev": true, - "engines": { - "node": ">=0.4.0" - } - }, "node_modules/diff": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/diff/-/diff-5.0.0.tgz", @@ -512,6 +482,28 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/fetch-blob": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz", + "integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/jimmywarting" + }, + { + "type": "paypal", + "url": "https://paypal.me/jimmywarting" + } + ], + "dependencies": { + "node-domexception": "^1.0.0", + "web-streams-polyfill": "^3.0.3" + }, + "engines": { + "node": "^12.20 || >= 14.13" + } + }, "node_modules/fill-range": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", @@ -549,18 +541,15 @@ "flat": "cli.js" } }, - "node_modules/form-data": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.1.tgz", - "integrity": "sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==", - "dev": true, + "node_modules/formdata-polyfill": { + "version": "4.0.10", + "resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz", + "integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==", "dependencies": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.8", - "mime-types": "^2.1.12" + "fetch-blob": "^3.1.2" }, "engines": { - "node": ">= 6" + "node": ">=12.20.0" } }, "node_modules/fs.realpath": { @@ -824,27 +813,6 @@ "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==", "dev": true }, - "node_modules/mime-db": { - "version": "1.52.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", - "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", - "dev": true, - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/mime-types": { - "version": "2.1.35", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", - "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", - "dev": true, - "dependencies": { - "mime-db": "1.52.0" - }, - "engines": { - "node": ">= 0.6" - } - }, "node_modules/minimatch": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-4.2.1.tgz", @@ -923,23 +891,39 @@ "resolved": "https://registry.npmjs.org/node-dns-sd/-/node-dns-sd-1.0.1.tgz", "integrity": "sha512-GCL6FgvkHoDnvJ1Yamf8mY16lYymWmYxjne4q1MC9C8sTZn9XR3BbwsrBQGikMESMFDFLC5MovNZn6wFl1yrdQ==" }, + "node_modules/node-domexception": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", + "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/jimmywarting" + }, + { + "type": "github", + "url": "https://paypal.me/jimmywarting" + } + ], + "engines": { + "node": ">=10.5.0" + } + }, "node_modules/node-fetch": { - "version": "2.6.9", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.9.tgz", - "integrity": "sha512-DJm/CJkZkRjKKj4Zi4BsKVZh3ValV5IR5s7LVZnW+6YMh0W1BfNA8XSs6DLMGYlId5F3KnA70uu2qepcR08Qqg==", + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.1.tgz", + "integrity": "sha512-cRVc/kyto/7E5shrWca1Wsea4y6tL9iYJE5FBCius3JQfb/4P4I295PfhgbJQBLTx6lATE4z+wK0rPM4VS2uow==", "dependencies": { - "whatwg-url": "^5.0.0" + "data-uri-to-buffer": "^4.0.0", + "fetch-blob": "^3.1.4", + "formdata-polyfill": "^4.0.10" }, "engines": { - "node": "4.x || >=6.0.0" + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" }, - "peerDependencies": { - "encoding": "^0.1.0" - }, - "peerDependenciesMeta": { - "encoding": { - "optional": true - } + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/node-fetch" } }, "node_modules/normalize-path": { @@ -1153,11 +1137,6 @@ "node": ">=8.0" } }, - "node_modules/tr46": { - "version": "0.0.3", - "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", - "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" - }, "node_modules/ts-node": { "version": "10.9.1", "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.1.tgz", @@ -1238,18 +1217,12 @@ "integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==", "dev": true }, - "node_modules/webidl-conversions": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", - "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==" - }, - "node_modules/whatwg-url": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", - "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", - "dependencies": { - "tr46": "~0.0.3", - "webidl-conversions": "^3.0.0" + "node_modules/web-streams-polyfill": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.2.1.tgz", + "integrity": "sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q==", + "engines": { + "node": ">= 8" } }, "node_modules/which": { diff --git a/package.json b/package.json index 2db02bf..511ba1d 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "email": "681306+peter-murray@users.noreply.github.com" } ], + "type": "module", "main": "dist/cjs/index.js", "types": "dist/esm/index.d.ts", "module": "dist/esm/index.js", @@ -17,7 +18,7 @@ "require": "./dist/cjs/index.js" }, "scripts": { - "test": "mocha -r ts-node/register \\\"src/**/*.test.ts\\\" \\\"src/**/*.test.js\\\"", + "test": "mocha -r ts-node/esm \\\"src/**/*.test.ts\\\" \\\"src/**/*.test.js\\\"", "build": "tsc -p tsconfig.json && tsc -p tsconfig_esm.json", "prepublishOnly": "npm run build" }, @@ -32,13 +33,12 @@ "@peter-murray/hue-bridge-model": "^2.0.1", "bottleneck": "^2.19.5", "node-dns-sd": "^1.0.1", - "node-fetch": "^2.6.1" + "node-fetch": "^3.3.1" }, "devDependencies": { "@types/chai": "^4.3.0", "@types/mocha": "^9.0.0", "@types/node": "^18.15.11", - "@types/node-fetch": "^2.5.12", "chai": "~4.3.4", "mocha": "^9.1.3", "ts-node": "^10.4.0", diff --git a/src/ApiError.ts b/src/ApiError.ts index e684814..d3ef3e3 100644 --- a/src/ApiError.ts +++ b/src/ApiError.ts @@ -1,4 +1,4 @@ -import { HueError } from './HueError'; +import { HueError } from './HueError.js'; export class ApiError extends Error { diff --git a/src/api/Api.ts b/src/api/Api.ts index fc31abb..5cfd2c7 100644 --- a/src/api/Api.ts +++ b/src/api/Api.ts @@ -1,21 +1,21 @@ -import { Remote } from './Remote'; -import { Cache } from './Cache'; -import { ConfigParameters, HueApiConfig } from './HueApiConfig'; -import { RemoteApi } from './http/RemoteApi'; -import { Transport } from './http/Transport'; -import { Capabilities } from './Capabilities'; -import { Configuration } from './Configuration'; -import { Groups } from './Groups'; -import { Lights } from './Lights'; -import { ResourceLinks } from './ResourceLinks'; -import { Rules } from './Rules'; -import { Scenes } from './Scenes'; -import { Schedules } from './Schedules'; -import { Sensors } from './Sensors'; -import { Users } from './Users'; +import { Remote } from './Remote.js'; +import { Cache } from './Cache.js'; +import { ConfigParameters, HueApiConfig } from './HueApiConfig.js'; +import { RemoteApi } from './http/RemoteApi.js'; +import { Transport } from './http/Transport.js'; +import { Capabilities } from './Capabilities.js'; +import { Configuration } from './Configuration.js'; +import { Groups } from './Groups.js'; +import { Lights } from './Lights.js'; +import { ResourceLinks } from './ResourceLinks.js'; +import { Rules } from './Rules.js'; +import { Scenes } from './Scenes.js'; +import { Schedules } from './Schedules.js'; +import { Sensors } from './Sensors.js'; +import { Users } from './Users.js'; import { model } from '@peter-murray/hue-bridge-model'; -import { HueApiRateLimits } from './HueApiRateLimits'; +import { HueApiRateLimits } from './HueApiRateLimits.js'; type Light = model.Light type ApiImplementationMap = { diff --git a/src/api/Cache.ts b/src/api/Cache.ts index c29de38..fefbfb5 100644 --- a/src/api/Cache.ts +++ b/src/api/Cache.ts @@ -1,5 +1,5 @@ import { model } from '@peter-murray/hue-bridge-model'; -import { LightIdPlaceholder } from './placeholders/LightIdPlaceholder'; +import { LightIdPlaceholder } from './placeholders/LightIdPlaceholder.js'; const LIGHT_ID_PLACEHOLDER = new LightIdPlaceholder(); diff --git a/src/api/Capabilities.ts b/src/api/Capabilities.ts index 29ec6eb..dbb9ee7 100644 --- a/src/api/Capabilities.ts +++ b/src/api/Capabilities.ts @@ -1,6 +1,6 @@ -import { ApiDefinition } from './http/ApiDefinition'; -import { capabilitiesApi } from './http/endpoints/capabilities'; -import { Api } from './Api'; +import { ApiDefinition } from './http/ApiDefinition.js'; +import { capabilitiesApi } from './http/endpoints/capabilities.js'; +import { Api } from './Api.js'; export class Capabilities extends ApiDefinition { diff --git a/src/api/Configuration.ts b/src/api/Configuration.ts index 2040528..c36fddc 100644 --- a/src/api/Configuration.ts +++ b/src/api/Configuration.ts @@ -1,7 +1,7 @@ import { model } from '@peter-murray/hue-bridge-model'; -import { configurationApi } from './http/endpoints/configuration'; -import { ApiDefinition } from './http/ApiDefinition'; -import { Api } from './Api'; +import { configurationApi } from './http/endpoints/configuration.js'; +import { ApiDefinition } from './http/ApiDefinition.js'; +import { Api } from './Api.js'; export class Configuration extends ApiDefinition { diff --git a/src/api/Groups.ts b/src/api/Groups.ts index bfed842..d610d7b 100644 --- a/src/api/Groups.ts +++ b/src/api/Groups.ts @@ -1,8 +1,8 @@ import { model } from '@peter-murray/hue-bridge-model'; -import { ApiDefinition } from './http/ApiDefinition'; -import { groupsApi } from './http/endpoints/groups'; -import { Api } from './Api'; -import { HueRateLimiter } from './HueRateLimiter'; +import { ApiDefinition } from './http/ApiDefinition.js'; +import { groupsApi } from './http/endpoints/groups.js'; +import { Api } from './Api.js'; +import { HueRateLimiter } from './HueRateLimiter.js'; type GroupState = model.GroupState diff --git a/src/api/HueApiConfig.ts b/src/api/HueApiConfig.ts index 6a3621d..228ca70 100644 --- a/src/api/HueApiConfig.ts +++ b/src/api/HueApiConfig.ts @@ -1,6 +1,6 @@ -import { ApiError } from '../ApiError'; -import { RemoteApi } from './http/RemoteApi'; -import { Transport } from './http/Transport'; +import { ApiError } from '../ApiError.js'; +import { RemoteApi } from './http/RemoteApi.js'; +import { Transport } from './http/Transport.js'; export type ConfigParameters = { baseUrl: string, diff --git a/src/api/HueRateLimiter.ts b/src/api/HueRateLimiter.ts index 51eea21..6b90d5e 100644 --- a/src/api/HueRateLimiter.ts +++ b/src/api/HueRateLimiter.ts @@ -1,6 +1,6 @@ import Bottleneck from 'bottleneck'; -import { RateLimit } from './HueApiRateLimits'; -import { HueApiRateLimitLogger } from './HueApiRateLimitLogger'; +import { RateLimit } from './HueApiRateLimits.js'; +import { HueApiRateLimitLogger } from './HueApiRateLimitLogger.js'; export class HueRateLimiter { diff --git a/src/api/Lights.ts b/src/api/Lights.ts index 42eb7d9..14f0c79 100644 --- a/src/api/Lights.ts +++ b/src/api/Lights.ts @@ -1,12 +1,12 @@ import { model } from '@peter-murray/hue-bridge-model'; -import { ApiDefinition } from './http/ApiDefinition'; -import { ApiError } from '../ApiError'; -import { lightsApi } from './http/endpoints/lights'; +import { ApiDefinition } from './http/ApiDefinition.js'; +import { ApiError } from '../ApiError.js'; +import { lightsApi } from './http/endpoints/lights.js'; -import { LightIdPlaceholder } from './placeholders/LightIdPlaceholder'; -import { KeyValueType } from '../commonTypes'; -import { Api } from './Api'; -import { HueRateLimiter } from './HueRateLimiter'; +import { LightIdPlaceholder } from './placeholders/LightIdPlaceholder.js'; +import { KeyValueType } from '../commonTypes.js'; +import { Api } from './Api.js'; +import { HueRateLimiter } from './HueRateLimiter.js'; const LIGHT_ID_PARSER = new LightIdPlaceholder(); @@ -87,7 +87,7 @@ export class Lights extends ApiDefinition { const lightId: number = getLightId(id); return this.hueApi.getLightDefinition(lightId) - .then(device => { + .then((device: any) => { if (!device) { throw new ApiError(`Light with id:${lightId} was not found on this bridge`); } diff --git a/src/api/Remote.ts b/src/api/Remote.ts index d342fd6..8abc1c9 100644 --- a/src/api/Remote.ts +++ b/src/api/Remote.ts @@ -1,6 +1,6 @@ -import { Token, Tokens } from './http/OAuthTokens'; -import { Api } from './Api'; -import { ApiError } from '../ApiError'; +import { Token, Tokens } from './http/OAuthTokens.js'; +import { Api } from './Api.js'; +import { ApiError } from '../ApiError.js'; type RemoteAccessCredentials = { clientId: string diff --git a/src/api/ResourceLinks.ts b/src/api/ResourceLinks.ts index 70ef9f6..2de80a3 100644 --- a/src/api/ResourceLinks.ts +++ b/src/api/ResourceLinks.ts @@ -1,7 +1,7 @@ -import { ApiDefinition } from './http/ApiDefinition'; -import { resourceLinksApi } from './http/endpoints/resourceLinks'; +import { ApiDefinition } from './http/ApiDefinition.js'; +import { resourceLinksApi } from './http/endpoints/resourceLinks.js'; import { model } from '@peter-murray/hue-bridge-model'; -import { Api } from './Api'; +import { Api } from './Api.js'; type ResourceLinkId = string | model.ResourceLink type LooseObject = { [key: string]: any }; diff --git a/src/api/Rules.ts b/src/api/Rules.ts index e99321d..8ae98dd 100644 --- a/src/api/Rules.ts +++ b/src/api/Rules.ts @@ -1,8 +1,8 @@ -import { ApiDefinition } from './http/ApiDefinition'; -import { rulesApi } from './http/endpoints/rules'; +import { ApiDefinition } from './http/ApiDefinition.js'; +import { rulesApi } from './http/endpoints/rules.js'; import { model } from '@peter-murray/hue-bridge-model'; -import { KeyValueType } from '../commonTypes'; -import { Api } from './Api'; +import { KeyValueType } from '../commonTypes.js'; +import { Api } from './Api.js'; type Rule = model.Rule; type RuleId = number | Rule; diff --git a/src/api/Scenes.ts b/src/api/Scenes.ts index 7f433d6..e3d825a 100644 --- a/src/api/Scenes.ts +++ b/src/api/Scenes.ts @@ -1,9 +1,9 @@ -import { ApiDefinition } from './http/ApiDefinition'; -import { scenesApi } from './http/endpoints/scenes'; -import { SceneIdPlaceholder } from './placeholders/SceneIdPlaceholder'; +import { ApiDefinition } from './http/ApiDefinition.js'; +import { scenesApi } from './http/endpoints/scenes.js'; +import { SceneIdPlaceholder } from './placeholders/SceneIdPlaceholder.js'; import { model } from '@peter-murray/hue-bridge-model'; -import { KeyValueType } from '../commonTypes'; -import { Api } from './Api'; +import { KeyValueType } from '../commonTypes.js'; +import { Api } from './Api.js'; type LightScene = model.LightScene type GroupScene = model.GroupScene diff --git a/src/api/Schedules.ts b/src/api/Schedules.ts index 2c201b0..1962617 100644 --- a/src/api/Schedules.ts +++ b/src/api/Schedules.ts @@ -1,7 +1,7 @@ import { model } from '@peter-murray/hue-bridge-model'; -import { ApiDefinition } from './http/ApiDefinition'; -import { schedulesApi } from './http/endpoints/schedules'; -import { Api } from './Api'; +import { ApiDefinition } from './http/ApiDefinition.js'; +import { schedulesApi } from './http/endpoints/schedules.js'; +import { Api } from './Api.js'; type Schedule = model.Schedule type ScheduleId = number | string | Schedule diff --git a/src/api/Sensors.ts b/src/api/Sensors.ts index 3176b39..4ed89d1 100644 --- a/src/api/Sensors.ts +++ b/src/api/Sensors.ts @@ -1,9 +1,9 @@ -import { ApiDefinition } from './http/ApiDefinition'; +import { ApiDefinition } from './http/ApiDefinition.js'; import { model } from '@peter-murray/hue-bridge-model'; -import { KeyValueType } from '../commonTypes'; +import { KeyValueType } from '../commonTypes.js'; -import { SensorIdResult, sensorsApi } from './http/endpoints/sensors'; -import { Api } from './Api'; +import { SensorIdResult, sensorsApi } from './http/endpoints/sensors.js'; +import { Api } from './Api.js'; type Sensor = model.Sensor type SensorId = string | Sensor diff --git a/src/api/Users.test.ts b/src/api/Users.test.ts index 6243de9..db2775b 100644 --- a/src/api/Users.test.ts +++ b/src/api/Users.test.ts @@ -1,11 +1,11 @@ 'use strict'; import {expect } from 'chai'; -import {v3} from '../v3'; -import {discovery, ApiError} from '../index'; -import {UserRecord} from "./Users"; +import {v3} from '../v3.js'; +import {discovery, ApiError} from '../index.js'; +import {UserRecord} from "./Users.js"; -const testValues = require('../../test/support/testValues'); //TODO move these +import * as testValues from '../../test/support/testValues.js'; //TODO move these describe('Hue API #users', () => { diff --git a/src/api/Users.ts b/src/api/Users.ts index bdc8060..931af27 100644 --- a/src/api/Users.ts +++ b/src/api/Users.ts @@ -1,9 +1,9 @@ -import { ApiDefinition } from './http/ApiDefinition'; -import { configurationApi, CreatedUser } from './http/endpoints/configuration'; +import { ApiDefinition } from './http/ApiDefinition.js'; +import { configurationApi, CreatedUser } from './http/endpoints/configuration.js'; import { model } from '@peter-murray/hue-bridge-model'; -import { KeyValueType } from '../commonTypes'; -import { Cache } from './Cache'; -import { Api } from './Api'; +import { KeyValueType } from '../commonTypes.js'; +import { Cache } from './Cache.js'; +import { Api } from './Api.js'; export type UserRecord = { username: string, diff --git a/src/api/discovery/UPnP.test.ts b/src/api/discovery/UPnP.test.ts index 4490920..bab6f66 100644 --- a/src/api/discovery/UPnP.test.ts +++ b/src/api/discovery/UPnP.test.ts @@ -1,5 +1,5 @@ import { expect } from 'chai'; -import { SSDPSearch } from './UPnP'; +import { SSDPSearch } from './UPnP.js'; describe('UPnP', function () { diff --git a/src/api/discovery/UPnP.ts b/src/api/discovery/UPnP.ts index de1cb1a..7aadef8 100644 --- a/src/api/discovery/UPnP.ts +++ b/src/api/discovery/UPnP.ts @@ -1,6 +1,6 @@ import * as dgram from 'dgram'; import * as events from 'events'; -import { DiscoveryBridgeDefinition } from './discoveryTypes'; +import { DiscoveryBridgeDefinition } from './discoveryTypes.js'; export class SSDPSearch { diff --git a/src/api/discovery/bridge-validation.test.ts b/src/api/discovery/bridge-validation.test.ts index 46db5ab..7d88a39 100644 --- a/src/api/discovery/bridge-validation.test.ts +++ b/src/api/discovery/bridge-validation.test.ts @@ -1,11 +1,10 @@ import {expect} from 'chai'; -import * as bridgeValidation from './bridge-validation'; -import { mDNSSearch } from "./mDNS"; +import * as bridgeValidation from './bridge-validation.js'; +import { mDNSSearch } from "./mDNS.js"; describe('bridge-validation', () => { - describe('#parseXmlDescription()', () => { it('should extract description from XML', () => { diff --git a/src/api/discovery/bridge-validation.ts b/src/api/discovery/bridge-validation.ts index cc114ed..92cf6e5 100644 --- a/src/api/discovery/bridge-validation.ts +++ b/src/api/discovery/bridge-validation.ts @@ -1,12 +1,12 @@ -import {request} from '../http/HttpClientFetch'; +import {request} from '../http/HttpClientFetch.js'; import { DiscoveryBridgeDefinition, DiscoveryBridgeDescription, DiscoveryBridgeModel, DiscoveryBridgeIcon, SpecVersion, BridgeConfigData -} from './discoveryTypes'; -import { ApiError } from '../../ApiError'; +} from './discoveryTypes.js'; +import { ApiError } from '../../ApiError.js'; const FRIENDLY_NAME = /(.*)<\/friendlyName/sm , MODEL_NAME = /(.*)<\/modelName/sm diff --git a/src/api/discovery/index.test.ts b/src/api/discovery/index.test.ts index 3ead040..6bb8c66 100644 --- a/src/api/discovery/index.test.ts +++ b/src/api/discovery/index.test.ts @@ -1,6 +1,6 @@ import {expect} from 'chai' -import * as discovery from './index'; -import { BridgeConfigData } from './discoveryTypes'; +import * as discovery from './index.js'; +import { BridgeConfigData } from './discoveryTypes.js'; describe('discovery', () => { diff --git a/src/api/discovery/index.ts b/src/api/discovery/index.ts index 171738a..3fc0f52 100644 --- a/src/api/discovery/index.ts +++ b/src/api/discovery/index.ts @@ -1,9 +1,9 @@ -import * as bridgeValidator from './bridge-validation'; -import { nupnp } from './nupnp'; -import { mDNSSearch } from './mDNS'; +import * as bridgeValidator from './bridge-validation.js'; +import { nupnp } from './nupnp.js'; +import { mDNSSearch } from './mDNS.js'; import { BridgeConfigError, BridgeDiscoveryResponse, DiscoveryBridgeDefinition, DiscoveryBridgeDescription -} from './discoveryTypes'; +} from './discoveryTypes.js'; export function mdnsSearch(timeout?: number): Promise { diff --git a/src/api/discovery/mDNS.test.ts b/src/api/discovery/mDNS.test.ts index eb499fe..f78f11f 100644 --- a/src/api/discovery/mDNS.test.ts +++ b/src/api/discovery/mDNS.test.ts @@ -1,5 +1,5 @@ import { expect } from 'chai'; -import { mDNSSearch } from './mDNS'; +import { mDNSSearch } from './mDNS.js'; describe('mDNS', function () { diff --git a/src/api/discovery/mDNS.ts b/src/api/discovery/mDNS.ts index f573fbb..69ce5e7 100644 --- a/src/api/discovery/mDNS.ts +++ b/src/api/discovery/mDNS.ts @@ -1,5 +1,5 @@ -import { DiscoveryBridgeDefinition } from './discoveryTypes'; -const mDnsSd = require('node-dns-sd'); +import { DiscoveryBridgeDefinition } from './discoveryTypes.js'; +import * as mDnsSd from 'node-dns-sd'; export class mDNSSearch { @@ -7,11 +7,11 @@ export class mDNSSearch { } search(timeout?: number, returnOnFirstFound = false): Promise { - return mDnsSd.discover({ + return mDnsSd.default.discover({ name: '_hue._tcp.local', wait: timeout ? timeout/1000 : 3, quick: returnOnFirstFound - }).then((devices: any) => { + }).then((devices: any[] | undefined) => { let results: DiscoveryBridgeDefinition[] = []; if (devices && devices.length > 0) { diff --git a/src/api/discovery/nupnp.test.ts b/src/api/discovery/nupnp.test.ts index 90cb76b..4fe909e 100644 --- a/src/api/discovery/nupnp.test.ts +++ b/src/api/discovery/nupnp.test.ts @@ -1,5 +1,5 @@ import {expect} from 'chai' -import { nupnp } from './nupnp'; +import { nupnp } from './nupnp.js'; describe('N-UPnP', () => { diff --git a/src/api/discovery/nupnp.ts b/src/api/discovery/nupnp.ts index 146b3e0..2c909d3 100644 --- a/src/api/discovery/nupnp.ts +++ b/src/api/discovery/nupnp.ts @@ -1,7 +1,7 @@ -import {request} from '../http/HttpClientFetch'; -import { DiscoveryBridgeDefinition } from './discoveryTypes'; -import { getDiscoveryMeetHueHttpsAgent } from './ca-chain'; -import { ApiError } from '../../ApiError'; +import {request} from '../http/HttpClientFetch.js'; +import { DiscoveryBridgeDefinition } from './discoveryTypes.js'; +import { getDiscoveryMeetHueHttpsAgent } from './ca-chain.js'; +import { ApiError } from '../../ApiError.js'; export function nupnp(): Promise { return request({ diff --git a/src/api/http/ApiDefinition.ts b/src/api/http/ApiDefinition.ts index 6eaee8c..0ac24b6 100644 --- a/src/api/http/ApiDefinition.ts +++ b/src/api/http/ApiDefinition.ts @@ -1,6 +1,6 @@ -import { Api } from '../Api'; -import { Transport } from './Transport'; -import { ApiEndpoint } from './endpoints/ApiEndpoint'; +import { Api } from '../Api.js'; +import { Transport } from './Transport.js'; +import { ApiEndpoint } from './endpoints/ApiEndpoint.js'; export class ApiDefinition { diff --git a/src/api/http/HttpClientFetch.ts b/src/api/http/HttpClientFetch.ts index 0b3dd65..0f91b8d 100644 --- a/src/api/http/HttpClientFetch.ts +++ b/src/api/http/HttpClientFetch.ts @@ -3,7 +3,7 @@ import fetch, { Response } from 'node-fetch'; import {URLSearchParams} from 'url'; import { Agent as HttpsAgent } from 'https'; import { Agent as HttpAgent } from 'http'; -import HttpError from './HttpError'; +import HttpError from './HttpError.js'; export type HTTPHeaders = { [key: string]: string diff --git a/src/api/http/LocalBootstrap.ts b/src/api/http/LocalBootstrap.ts index 7b1d7a6..b185f21 100644 --- a/src/api/http/LocalBootstrap.ts +++ b/src/api/http/LocalBootstrap.ts @@ -1,15 +1,15 @@ import * as https from 'https'; -import {Api} from '../Api'; +import {Api} from '../Api.js'; -import * as httpClient from './HttpClientFetch'; -import { ApiError } from '../../ApiError'; -import { Transport } from './Transport'; -import { HueApiRateLimits } from '../HueApiRateLimits'; +import * as httpClient from './HttpClientFetch.js'; +import { ApiError } from '../../ApiError.js'; +import { Transport } from './Transport.js'; +import { HueApiRateLimits } from '../HueApiRateLimits.js'; -import { getSSLCertificate, SSLCertificate } from './sslCertificate'; -import { ConfigParameters } from '../HueApiConfig'; -import { cleanHostname, getHttpsUrl } from './urlUtil'; +import { getSSLCertificate, SSLCertificate } from './sslCertificate.js'; +import { ConfigParameters } from '../HueApiConfig.js'; +import { cleanHostname, getHttpsUrl } from './urlUtil.js'; import { time } from '@peter-murray/hue-bridge-model'; const DEBUG: boolean = /node-hue-api/.test(process.env.NODE_DEBUG || ''); diff --git a/src/api/http/LocalInsecureBootstrap.ts b/src/api/http/LocalInsecureBootstrap.ts index 12b48b1..a793ae8 100644 --- a/src/api/http/LocalInsecureBootstrap.ts +++ b/src/api/http/LocalInsecureBootstrap.ts @@ -1,9 +1,9 @@ -import { Transport } from './Transport'; -import { Api } from '../Api'; -import { request, create } from './HttpClientFetch'; -import { HueApiRateLimits } from '../HueApiRateLimits'; -import { ConfigParameters } from '../HueApiConfig'; -import { getHttpUrl } from './urlUtil'; +import { Transport } from './Transport.js'; +import { Api } from '../Api.js'; +import { request, create } from './HttpClientFetch.js'; +import { HueApiRateLimits } from '../HueApiRateLimits.js'; +import { ConfigParameters } from '../HueApiConfig.js'; +import { getHttpUrl } from './urlUtil.js'; const SUPPRESS_WARNING = process.env.NODE_HUE_API_USE_INSECURE_CONNECTION != null; diff --git a/src/api/http/OAuthTokens.ts b/src/api/http/OAuthTokens.ts index 63c44ff..0b1e19d 100644 --- a/src/api/http/OAuthTokens.ts +++ b/src/api/http/OAuthTokens.ts @@ -1,4 +1,4 @@ -import { KeyValueType } from '../../commonTypes'; +import { KeyValueType } from '../../commonTypes.js'; export type Token = { value: string, diff --git a/src/api/http/RemoteApi.ts b/src/api/http/RemoteApi.ts index 62eee63..46f971c 100644 --- a/src/api/http/RemoteApi.ts +++ b/src/api/http/RemoteApi.ts @@ -1,8 +1,8 @@ -import * as httpClient from './HttpClientFetch'; -import { ApiError } from '../../ApiError'; -import { FetchResult, HttpClientFetch, HTTPHeaders, RequestConfig } from './HttpClientFetch'; -import { OAuthTokens, Tokens } from './OAuthTokens'; -import { wasSuccessful } from '../../util'; +import * as httpClient from './HttpClientFetch.js'; +import { ApiError } from '../../ApiError.js'; +import { FetchResult, HttpClientFetch, HTTPHeaders, RequestConfig } from './HttpClientFetch.js'; +import { OAuthTokens, Tokens } from './OAuthTokens.js'; +import { wasSuccessful } from '../../util.js'; import { createHash } from 'crypto'; diff --git a/src/api/http/RemoteBootstrap.ts b/src/api/http/RemoteBootstrap.ts index 7ffea70..daad8ba 100644 --- a/src/api/http/RemoteBootstrap.ts +++ b/src/api/http/RemoteBootstrap.ts @@ -1,9 +1,9 @@ -import { create } from './HttpClientFetch'; -import { RemoteApi } from './RemoteApi'; -import { Api } from '../Api'; -import { Transport } from './Transport'; -import { HueApiRateLimits } from '../HueApiRateLimits'; -import { ConfigParameters } from '../HueApiConfig'; +import { create } from './HttpClientFetch.js'; +import { RemoteApi } from './RemoteApi.js'; +import { Api } from '../Api.js'; +import { Transport } from './Transport.js'; +import { HueApiRateLimits } from '../HueApiRateLimits.js'; +import { ConfigParameters } from '../HueApiConfig.js'; export class RemoteBootstrap { diff --git a/src/api/http/Transport.ts b/src/api/http/Transport.ts index 3c7e13a..4890873 100644 --- a/src/api/http/Transport.ts +++ b/src/api/http/Transport.ts @@ -1,10 +1,10 @@ -import { ApiError } from '../../ApiError'; -import { parseErrors } from '../../util'; -import { ApiEndpoint } from './endpoints/ApiEndpoint'; -import { HueError } from '../../HueError'; -import { FetchResult, HttpClientFetch } from './HttpClientFetch'; -import { RateLimit } from '../HueApiRateLimits'; -import { HueRateLimiter } from '../HueRateLimiter'; +import { ApiError } from '../../ApiError.js'; +import { parseErrors } from '../../util.js'; +import { ApiEndpoint } from './endpoints/ApiEndpoint.js'; +import { HueError } from '../../HueError.js'; +import { FetchResult, HttpClientFetch } from './HttpClientFetch.js'; +import { RateLimit } from '../HueApiRateLimits.js'; +import { HueRateLimiter } from '../HueRateLimiter.js'; export class Transport { diff --git a/src/api/http/endpoints/ApiEndpoint.ts b/src/api/http/endpoints/ApiEndpoint.ts index dd63ffe..8f91776 100644 --- a/src/api/http/endpoints/ApiEndpoint.ts +++ b/src/api/http/endpoints/ApiEndpoint.ts @@ -1,6 +1,6 @@ -import { HTTPHeaders, RequestConfig } from '../HttpClientFetch'; -import { Placeholder } from '../../placeholders/Placeholder'; -import { UsernamePlaceholder } from '../../placeholders/UsernamePlaceholder'; +import { HTTPHeaders, RequestConfig } from '../HttpClientFetch.js'; +import { Placeholder } from '../../placeholders/Placeholder.js'; +import { UsernamePlaceholder } from '../../placeholders/UsernamePlaceholder.js'; const DEBUG: boolean = /node-hue-api/.test(process.env['NODE_DEBUG'] || ''); diff --git a/src/api/http/endpoints/capabilities.ts b/src/api/http/endpoints/capabilities.ts index bfbdd44..975bb7b 100644 --- a/src/api/http/endpoints/capabilities.ts +++ b/src/api/http/endpoints/capabilities.ts @@ -1,6 +1,6 @@ -import { ApiEndpoint } from './ApiEndpoint'; +import { ApiEndpoint } from './ApiEndpoint.js'; import { model } from '@peter-murray/hue-bridge-model'; -import { KeyValueType } from '../../../commonTypes'; +import { KeyValueType } from '../../../commonTypes.js'; function getAllCapabilities() { return new ApiEndpoint() diff --git a/src/api/http/endpoints/configuration.ts b/src/api/http/endpoints/configuration.ts index 97a1ae0..9e9b6c3 100644 --- a/src/api/http/endpoints/configuration.ts +++ b/src/api/http/endpoints/configuration.ts @@ -1,10 +1,10 @@ -import { ApiBodyPayload, ApiEndpoint } from './ApiEndpoint'; -import { UsernamePlaceholder } from '../../placeholders/UsernamePlaceholder'; +import { ApiBodyPayload, ApiEndpoint } from './ApiEndpoint.js'; +import { UsernamePlaceholder } from '../../placeholders/UsernamePlaceholder.js'; import { model } from '@peter-murray/hue-bridge-model'; -import { ApiError } from '../../../ApiError'; +import { ApiError } from '../../../ApiError.js'; -import { wasSuccessful } from '../../../util'; -import { KeyValueType } from '../../../commonTypes'; +import { wasSuccessful } from '../../../util.js'; +import { KeyValueType } from '../../../commonTypes.js'; const instanceChecks = model.instanceChecks; diff --git a/src/api/http/endpoints/groups.ts b/src/api/http/endpoints/groups.ts index db130cf..1dcac35 100644 --- a/src/api/http/endpoints/groups.ts +++ b/src/api/http/endpoints/groups.ts @@ -1,10 +1,10 @@ import { model } from '@peter-murray/hue-bridge-model'; -import { ApiBodyPayload, ApiEndpoint } from './ApiEndpoint'; -import { GroupIdPlaceholder } from '../../placeholders/GroupIdPlaceholder'; -import { ApiError } from '../../../ApiError'; +import { ApiBodyPayload, ApiEndpoint } from './ApiEndpoint.js'; +import { GroupIdPlaceholder } from '../../placeholders/GroupIdPlaceholder.js'; +import { ApiError } from '../../../ApiError.js'; -import { parseErrors, wasSuccessful } from '../../../util'; -import { KeyValueType } from '../../../commonTypes'; +import { parseErrors, wasSuccessful } from '../../../util.js'; +import { KeyValueType } from '../../../commonTypes.js'; const GroupState = model.GroupState , instanceChecks = model.instanceChecks diff --git a/src/api/http/endpoints/lights.ts b/src/api/http/endpoints/lights.ts index 940a126..afc31c6 100644 --- a/src/api/http/endpoints/lights.ts +++ b/src/api/http/endpoints/lights.ts @@ -1,10 +1,10 @@ import { model } from '@peter-murray/hue-bridge-model'; -import { LightIdPlaceholder } from '../../placeholders/LightIdPlaceholder'; -import { ApiEndpoint } from './ApiEndpoint'; -import { rgbToXY } from '../../../rgb'; -import { ApiError } from '../../../ApiError'; -import { parseErrors, wasSuccessful } from '../../../util'; -import { KeyValueType } from '../../../commonTypes'; +import { LightIdPlaceholder } from '../../placeholders/LightIdPlaceholder.js'; +import { ApiEndpoint } from './ApiEndpoint.js'; +import { rgbToXY } from '../../../rgb.js'; +import { ApiError } from '../../../ApiError.js'; +import { parseErrors, wasSuccessful } from '../../../util.js'; +import { KeyValueType } from '../../../commonTypes.js'; const LIGHT_ID_PLACEHOLDER = new LightIdPlaceholder(); diff --git a/src/api/http/endpoints/resourceLinks.ts b/src/api/http/endpoints/resourceLinks.ts index fd6178a..43cb0f7 100644 --- a/src/api/http/endpoints/resourceLinks.ts +++ b/src/api/http/endpoints/resourceLinks.ts @@ -1,9 +1,9 @@ import { model } from '@peter-murray/hue-bridge-model'; -import { extractUpdatedAttributes, parseErrors, wasSuccessful } from '../../../util'; -import { ResourceLinkPlaceholder } from '../../placeholders/ResourceLinkPlaceholder'; -import { ApiBodyPayload, ApiEndpoint } from './ApiEndpoint'; -import { ApiError } from '../../../ApiError'; -import { KeyValueType } from '../../../commonTypes'; +import { extractUpdatedAttributes, parseErrors, wasSuccessful } from '../../../util.js'; +import { ResourceLinkPlaceholder } from '../../placeholders/ResourceLinkPlaceholder.js'; +import { ApiBodyPayload, ApiEndpoint } from './ApiEndpoint.js'; +import { ApiError } from '../../../ApiError.js'; +import { KeyValueType } from '../../../commonTypes.js'; const instanceChecks = model.instanceChecks; diff --git a/src/api/http/endpoints/rules.ts b/src/api/http/endpoints/rules.ts index 0c749dd..e3e8001 100644 --- a/src/api/http/endpoints/rules.ts +++ b/src/api/http/endpoints/rules.ts @@ -1,9 +1,9 @@ import {model} from '@peter-murray/hue-bridge-model'; -import { RuleIdPlaceholder } from '../../placeholders/RuleIdPlaceholder'; -import { ApiBodyPayload, ApiEndpoint } from './ApiEndpoint'; -import { extractUpdatedAttributes, parseErrors, wasSuccessful } from '../../../util'; -import { ApiError } from '../../../ApiError'; -import { KeyValueType } from '../../../commonTypes'; +import { RuleIdPlaceholder } from '../../placeholders/RuleIdPlaceholder.js'; +import { ApiBodyPayload, ApiEndpoint } from './ApiEndpoint.js'; +import { extractUpdatedAttributes, parseErrors, wasSuccessful } from '../../../util.js'; +import { ApiError } from '../../../ApiError.js'; +import { KeyValueType } from '../../../commonTypes.js'; const instanceChecks = model.instanceChecks diff --git a/src/api/http/endpoints/scenes.ts b/src/api/http/endpoints/scenes.ts index 4649693..faed1b5 100644 --- a/src/api/http/endpoints/scenes.ts +++ b/src/api/http/endpoints/scenes.ts @@ -1,10 +1,10 @@ import { model } from '@peter-murray/hue-bridge-model'; -import { extractUpdatedAttributes, parseErrors, wasSuccessful } from '../../../util'; -import { SceneIdPlaceholder } from '../../placeholders/SceneIdPlaceholder'; -import { LightIdPlaceholder } from '../../placeholders/LightIdPlaceholder'; -import { ApiBodyPayload, ApiEndpoint } from './ApiEndpoint'; -import { ApiError } from '../../../ApiError'; -import { KeyValueType } from '../../../commonTypes'; +import { extractUpdatedAttributes, parseErrors, wasSuccessful } from '../../../util.js'; +import { SceneIdPlaceholder } from '../../placeholders/SceneIdPlaceholder.js'; +import { LightIdPlaceholder } from '../../placeholders/LightIdPlaceholder.js'; +import { ApiBodyPayload, ApiEndpoint } from './ApiEndpoint.js'; +import { ApiError } from '../../../ApiError.js'; +import { KeyValueType } from '../../../commonTypes.js'; const SCENE_ID_PLACEHOLDER = new SceneIdPlaceholder(); diff --git a/src/api/http/endpoints/schedules.ts b/src/api/http/endpoints/schedules.ts index 8191506..8103802 100644 --- a/src/api/http/endpoints/schedules.ts +++ b/src/api/http/endpoints/schedules.ts @@ -1,9 +1,9 @@ import { model, time } from '@peter-murray/hue-bridge-model'; -import { extractUpdatedAttributes, parseErrors, wasSuccessful } from '../../../util'; -import { ApiBodyPayload, ApiEndpoint } from './ApiEndpoint'; -import { ScheduleIdPlaceholder } from '../../placeholders/ScheduleIdPlaceholder'; -import { ApiError } from '../../../ApiError'; -import { KeyValueType } from '../../../commonTypes'; +import { extractUpdatedAttributes, parseErrors, wasSuccessful } from '../../../util.js'; +import { ApiBodyPayload, ApiEndpoint } from './ApiEndpoint.js'; +import { ScheduleIdPlaceholder } from '../../placeholders/ScheduleIdPlaceholder.js'; +import { ApiError } from '../../../ApiError.js'; +import { KeyValueType } from '../../../commonTypes.js'; const SCHEDULE_ID_PLACEHOLDER = new ScheduleIdPlaceholder(); diff --git a/src/api/http/endpoints/sensors.ts b/src/api/http/endpoints/sensors.ts index 32833c3..f378f5f 100644 --- a/src/api/http/endpoints/sensors.ts +++ b/src/api/http/endpoints/sensors.ts @@ -1,9 +1,9 @@ import { model } from '@peter-murray/hue-bridge-model'; -import { SensorIdPlaceholder } from '../../placeholders/SensorIdPlaceholder'; -import { ApiBodyPayload, ApiEndpoint } from './ApiEndpoint'; -import { ApiError } from '../../../ApiError'; -import { KeyValueType } from '../../../commonTypes'; -import { extractUpdatedAttributes, parseErrors, wasSuccessful } from '../../../util'; +import { SensorIdPlaceholder } from '../../placeholders/SensorIdPlaceholder.js'; +import { ApiBodyPayload, ApiEndpoint } from './ApiEndpoint.js'; +import { ApiError } from '../../../ApiError.js'; +import { KeyValueType } from '../../../commonTypes.js'; +import { extractUpdatedAttributes, parseErrors, wasSuccessful } from '../../../util.js'; const SENSOR_ID_PLACEHOLDER = new SensorIdPlaceholder(); diff --git a/src/api/http/urlUtil.test.ts b/src/api/http/urlUtil.test.ts index eeb37d7..d591b4a 100644 --- a/src/api/http/urlUtil.test.ts +++ b/src/api/http/urlUtil.test.ts @@ -1,5 +1,5 @@ import {expect} from 'chai'; -import { getHttpsUrl, isIpv6Host } from './urlUtil'; +import { getHttpsUrl, isIpv6Host } from './urlUtil.js'; const IPV6_EXPANDED = '0000:0000:0000:0000:0000:ffff:c0a8:0a28' diff --git a/src/api/index.ts b/src/api/index.ts index a97cc8f..9dd1117 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -1,7 +1,7 @@ -import { LocalBootstrap } from './http/LocalBootstrap'; -import { LocalInsecureBootstrap } from './http/LocalInsecureBootstrap'; -import { RemoteBootstrap } from './http/RemoteBootstrap'; -import { HueApiRateLimits } from './HueApiRateLimits'; +import { LocalBootstrap } from './http/LocalBootstrap.js'; +import { LocalInsecureBootstrap } from './http/LocalInsecureBootstrap.js'; +import { RemoteBootstrap } from './http/RemoteBootstrap.js'; +import { HueApiRateLimits } from './HueApiRateLimits.js'; const DEFAULT_RATE_LIMIT_CONFIG = new HueApiRateLimits(); diff --git a/src/api/placeholders/GroupIdPlaceholder.ts b/src/api/placeholders/GroupIdPlaceholder.ts index 8b0bf2d..d47754c 100644 --- a/src/api/placeholders/GroupIdPlaceholder.ts +++ b/src/api/placeholders/GroupIdPlaceholder.ts @@ -1,4 +1,4 @@ -import { Placeholder } from './Placeholder'; +import { Placeholder } from './Placeholder.js'; import { model, types } from '@peter-murray/hue-bridge-model'; export class GroupIdPlaceholder extends Placeholder { diff --git a/src/api/placeholders/LightIdPlaceholder.ts b/src/api/placeholders/LightIdPlaceholder.ts index d980ee6..019723e 100644 --- a/src/api/placeholders/LightIdPlaceholder.ts +++ b/src/api/placeholders/LightIdPlaceholder.ts @@ -1,4 +1,4 @@ -import { Placeholder } from './Placeholder'; +import { Placeholder } from './Placeholder.js'; import { model, types } from '@peter-murray/hue-bridge-model'; export class LightIdPlaceholder extends Placeholder { diff --git a/src/api/placeholders/Placeholder.ts b/src/api/placeholders/Placeholder.ts index 50718f8..20f3429 100644 --- a/src/api/placeholders/Placeholder.ts +++ b/src/api/placeholders/Placeholder.ts @@ -1,6 +1,6 @@ import { types } from '@peter-murray/hue-bridge-model'; -import { ApiError } from '../../ApiError'; -import { KeyValueType } from '../../commonTypes'; +import { ApiError } from '../../ApiError.js'; +import { KeyValueType } from '../../commonTypes.js'; type Type = types.BaseType; diff --git a/src/api/placeholders/ResourceLinkPlaceholder.ts b/src/api/placeholders/ResourceLinkPlaceholder.ts index 999b293..5f665fc 100644 --- a/src/api/placeholders/ResourceLinkPlaceholder.ts +++ b/src/api/placeholders/ResourceLinkPlaceholder.ts @@ -1,4 +1,4 @@ -import { Placeholder } from './Placeholder'; +import { Placeholder } from './Placeholder.js'; import { model, types } from '@peter-murray/hue-bridge-model'; export class ResourceLinkPlaceholder extends Placeholder { diff --git a/src/api/placeholders/RuleIdPlaceholder.ts b/src/api/placeholders/RuleIdPlaceholder.ts index 74b56e6..3e2ebcb 100644 --- a/src/api/placeholders/RuleIdPlaceholder.ts +++ b/src/api/placeholders/RuleIdPlaceholder.ts @@ -1,4 +1,4 @@ -import { Placeholder } from './Placeholder'; +import { Placeholder } from './Placeholder.js'; import { model, types } from '@peter-murray/hue-bridge-model'; export class RuleIdPlaceholder extends Placeholder { diff --git a/src/api/placeholders/SceneIdPlaceholder.ts b/src/api/placeholders/SceneIdPlaceholder.ts index 58ef2f6..5dcdd7c 100644 --- a/src/api/placeholders/SceneIdPlaceholder.ts +++ b/src/api/placeholders/SceneIdPlaceholder.ts @@ -1,4 +1,4 @@ -import { Placeholder } from './Placeholder'; +import { Placeholder } from './Placeholder.js'; import { model, types } from '@peter-murray/hue-bridge-model'; export class SceneIdPlaceholder extends Placeholder { diff --git a/src/api/placeholders/ScheduleIdPlaceholder.ts b/src/api/placeholders/ScheduleIdPlaceholder.ts index c3f704e..aa0afef 100644 --- a/src/api/placeholders/ScheduleIdPlaceholder.ts +++ b/src/api/placeholders/ScheduleIdPlaceholder.ts @@ -1,4 +1,4 @@ -import { Placeholder } from './Placeholder'; +import { Placeholder } from './Placeholder.js'; import { model, types } from '@peter-murray/hue-bridge-model'; export class ScheduleIdPlaceholder extends Placeholder { diff --git a/src/api/placeholders/SensorIdPlaceholder.ts b/src/api/placeholders/SensorIdPlaceholder.ts index 7179bf1..3293386 100644 --- a/src/api/placeholders/SensorIdPlaceholder.ts +++ b/src/api/placeholders/SensorIdPlaceholder.ts @@ -1,4 +1,4 @@ -import { Placeholder } from './Placeholder'; +import { Placeholder } from './Placeholder.js'; import { model, types } from '@peter-murray/hue-bridge-model'; export class SensorIdPlaceholder extends Placeholder { diff --git a/src/api/placeholders/UsernamePlaceholder.ts b/src/api/placeholders/UsernamePlaceholder.ts index af53836..985fba7 100644 --- a/src/api/placeholders/UsernamePlaceholder.ts +++ b/src/api/placeholders/UsernamePlaceholder.ts @@ -1,4 +1,4 @@ -import { Placeholder } from './Placeholder'; +import { Placeholder } from './Placeholder.js'; import { model, types } from '@peter-murray/hue-bridge-model'; export class UsernamePlaceholder extends Placeholder { diff --git a/src/index.ts b/src/index.ts index b36f778..90f3f6f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,16 +1,16 @@ // // This wrapper is to provide some continuity in the modifications of the APIs over time // -import * as discovery from './api/discovery'; +import * as discovery from './api/discovery/index.js'; export { discovery }; -import { ApiError } from './ApiError'; +import { ApiError } from './ApiError.js'; export { ApiError }; -export * from './v3'; +export * from './v3.js'; // Exported API that v3 wraps -export * as api from './api'; +export * as api from './api/index.js'; // Export raw implementation of bridge model export { model, time } from '@peter-murray/hue-bridge-model'; \ No newline at end of file diff --git a/src/rgb.ts b/src/rgb.ts index d692b6d..eb42a40 100644 --- a/src/rgb.ts +++ b/src/rgb.ts @@ -1,4 +1,4 @@ -import { ApiError } from './ApiError'; +import { ApiError } from './ApiError.js'; export function rgbToXY (rgb: number[], colorGamut: Gamut) { if (!colorGamut) { diff --git a/src/util.ts b/src/util.ts index 74fcaa3..04ac40d 100644 --- a/src/util.ts +++ b/src/util.ts @@ -1,6 +1,6 @@ -import { HueError } from './HueError'; -import { KeyValueType } from './commonTypes'; -import { ApiError } from './ApiError'; +import { HueError } from './HueError.js'; +import { KeyValueType } from './commonTypes.js'; +import { ApiError } from './ApiError.js'; const suppressDeprecationWarnings = process.env.NODE_HUE_API_SUPPRESS_DEPRICATION_WARNINGS || false; diff --git a/src/v3.ts b/src/v3.ts index c7a8af2..70612b7 100644 --- a/src/v3.ts +++ b/src/v3.ts @@ -1,8 +1,8 @@ import { model } from '@peter-murray/hue-bridge-model'; -import { v3Model } from './v3Model'; -import { deprecatedFunction } from './util'; -import * as api from './api'; -import { description, nupnpSearch, mdnsSearch } from './api/discovery'; +import { v3Model } from './v3Model.js'; +import { deprecatedFunction } from './util.js'; +import * as api from './api/index.js'; +import { description, nupnpSearch, mdnsSearch } from './api/discovery/index.js'; // Definition of the v3 API for node-hue-api diff --git a/tsconfig.json b/tsconfig.json index 36521c3..2b69653 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,13 +1,21 @@ { "compilerOptions": { "target": "ES2018", - "module": "commonjs", + "module": "Node16", + "moduleResolution": "Node16", "declaration": true, "outDir": "./dist/cjs", "strict": true, "esModuleInterop": true, // "allowJs": true + "typeRoots": [ + "src/customTypings", + "node_modules/@types" + ] }, + "files": [ + "src/customTypings/node-dns-sd.d.ts" + ], "exclude": [ "test", "examples",