diff --git a/migrations/20180202184625-download-caas-appstore-configs.js b/migrations/20180202184625-download-caas-appstore-configs.js index 5f5528dc9..35b9ad8d1 100644 --- a/migrations/20180202184625-download-caas-appstore-configs.js +++ b/migrations/20180202184625-download-caas-appstore-configs.js @@ -1,7 +1,7 @@ 'use strict'; const fs = require('fs'), - superagent = require('../src/superagent.js'); + superagent = require('@cloudron/superagent'); exports.up = async function(db) { if (!fs.existsSync('/home/yellowtent/configs/cloudron.conf')) { diff --git a/migrations/20190503170326-settings-get-license.js b/migrations/20190503170326-settings-get-license.js index d1a67ef9e..4b92dcb4a 100644 --- a/migrations/20190503170326-settings-get-license.js +++ b/migrations/20190503170326-settings-get-license.js @@ -1,7 +1,7 @@ 'use strict'; const fs = require('fs'), - superagent = require('../src/superagent.js'); + superagent = require('@cloudron/superagent'); exports.up = async function(db) { if (!fs.existsSync('/etc/cloudron/cloudron.conf')) { diff --git a/migrations/20220401045439-settings-get-appstore-web-token.js b/migrations/20220401045439-settings-get-appstore-web-token.js index 4af388e1d..2a1804fc5 100644 --- a/migrations/20220401045439-settings-get-appstore-web-token.js +++ b/migrations/20220401045439-settings-get-appstore-web-token.js @@ -1,6 +1,6 @@ 'use strict'; -const superagent = require('../src/superagent.js'); +const superagent = require('@cloudron/superagent'); exports.up = async function(db) { const results1 = await db.runSql('SELECT value FROM settings WHERE name="api_server_origin"'); diff --git a/package-lock.json b/package-lock.json index b7a6e06f8..0a73af2a6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,7 @@ "@aws-sdk/client-route-53": "^3.825.0", "@aws-sdk/client-s3": "^3.825.0", "@aws-sdk/lib-storage": "^3.825.0", + "@cloudron/superagent": "^1.0.0", "@google-cloud/dns": "^5.2.0", "@google-cloud/storage": "^7.16.0", "@smithy/node-http-handler": "^4.0.6", @@ -1082,6 +1083,16 @@ "version": "1.0.2", "license": "Apache-2.0" }, + "node_modules/@cloudron/superagent": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@cloudron/superagent/-/superagent-1.0.0.tgz", + "integrity": "sha512-hMJk7175viHCJ61fXKQJGrQotbABqSxfGDHDc4X49qfBnEKd0jPiRcm8bJ28IQxP+YLRBJgzbWrEyJGntP/d/w==", + "license": "ISC", + "dependencies": { + "debug": "^4.4.1", + "safetydance": "^2.5.1" + } + }, "node_modules/@csstools/color-helpers": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/@csstools/color-helpers/-/color-helpers-5.0.1.tgz", diff --git a/package.json b/package.json index 499081a27..8bcb0bd1f 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "@aws-sdk/client-route-53": "^3.825.0", "@aws-sdk/client-s3": "^3.825.0", "@aws-sdk/lib-storage": "^3.825.0", + "@cloudron/superagent": "^1.0.0", "@google-cloud/dns": "^5.2.0", "@google-cloud/storage": "^7.16.0", "@smithy/node-http-handler": "^4.0.6", diff --git a/scripts/release b/scripts/release index d039bd3e5..b30d152d8 100755 --- a/scripts/release +++ b/scripts/release @@ -11,7 +11,7 @@ const assert = require('assert'), { program } = require('commander'), safe = require('safetydance'), semver = require('semver'), - superagent = require('../src/superagent.js'), + superagent = require('@cloudron/superagent'), Table = require('easy-table'), url = require('url'), util = require('util'), diff --git a/src/acme2.js b/src/acme2.js index 98a1d4d1e..7baf9f9f8 100644 --- a/src/acme2.js +++ b/src/acme2.js @@ -21,7 +21,7 @@ const assert = require('assert'), promiseRetry = require('./promise-retry.js'), safe = require('safetydance'), shell = require('./shell.js')('acme2'), - superagent = require('./superagent.js'), + superagent = require('@cloudron/superagent'), users = require('./users.js'); const CA_PROD_DIRECTORY_URL = 'https://acme-v02.api.letsencrypt.org/directory', diff --git a/src/apphealthmonitor.js b/src/apphealthmonitor.js index a8ca1d84c..d12f4b718 100644 --- a/src/apphealthmonitor.js +++ b/src/apphealthmonitor.js @@ -9,7 +9,7 @@ const apps = require('./apps.js'), docker = require('./docker.js'), eventlog = require('./eventlog.js'), safe = require('safetydance'), - superagent = require('./superagent.js'); + superagent = require('@cloudron/superagent'); exports = module.exports = { run diff --git a/src/applinks.js b/src/applinks.js index e3a5e1864..7a2f84e41 100644 --- a/src/applinks.js +++ b/src/applinks.js @@ -16,7 +16,7 @@ const assert = require('assert'), debug = require('debug')('box:applinks'), jsdom = require('jsdom'), safe = require('safetydance'), - superagent = require('./superagent.js'), + superagent = require('@cloudron/superagent'), uuid = require('uuid'); const APPLINKS_FIELDS= [ 'id', 'accessRestrictionJson', 'creationTime', 'updateTime', 'ts', 'label', 'tagsJson', 'icon', 'upstreamUri' ].join(','); diff --git a/src/appstore.js b/src/appstore.js index 36a4d1898..af4999b9e 100644 --- a/src/appstore.js +++ b/src/appstore.js @@ -37,7 +37,7 @@ const assert = require('assert'), safe = require('safetydance'), semver = require('semver'), settings = require('./settings.js'), - superagent = require('./superagent.js'); + superagent = require('@cloudron/superagent'); // These are the default options and will be adjusted once a subscription state is obtained // Keep in sync with appstore/routes/cloudrons.js diff --git a/src/dns/bunny.js b/src/dns/bunny.js index 750238a0a..13af2b7dc 100644 --- a/src/dns/bunny.js +++ b/src/dns/bunny.js @@ -17,7 +17,7 @@ const assert = require('assert'), dig = require('../dig.js'), dns = require('../dns.js'), safe = require('safetydance'), - superagent = require('../superagent.js'), + superagent = require('@cloudron/superagent'), waitForDns = require('./waitfordns.js'); const BUNNY_API = 'https://api.bunny.net'; diff --git a/src/dns/cloudflare.js b/src/dns/cloudflare.js index 269384636..2bbec924b 100644 --- a/src/dns/cloudflare.js +++ b/src/dns/cloudflare.js @@ -17,7 +17,7 @@ const assert = require('assert'), dig = require('../dig.js'), dns = require('../dns.js'), safe = require('safetydance'), - superagent = require('../superagent.js'), + superagent = require('@cloudron/superagent'), waitForDns = require('./waitfordns.js'), _ = require('../underscore.js'); diff --git a/src/dns/desec.js b/src/dns/desec.js index e2b46d06a..602075a18 100644 --- a/src/dns/desec.js +++ b/src/dns/desec.js @@ -18,7 +18,7 @@ const assert = require('assert'), dns = require('../dns.js'), safe = require('safetydance'), timers = require('timers/promises'), - superagent = require('../superagent.js'), + superagent = require('@cloudron/superagent'), waitForDns = require('./waitfordns.js'); const DESEC_ENDPOINT = 'https://desec.io/api/v1'; diff --git a/src/dns/digitalocean.js b/src/dns/digitalocean.js index 6d9ec09d3..20ff2c613 100644 --- a/src/dns/digitalocean.js +++ b/src/dns/digitalocean.js @@ -17,7 +17,7 @@ const assert = require('assert'), dig = require('../dig.js'), dns = require('../dns.js'), safe = require('safetydance'), - superagent = require('../superagent.js'), + superagent = require('@cloudron/superagent'), waitForDns = require('./waitfordns.js'); const DIGITALOCEAN_ENDPOINT = 'https://api.digitalocean.com'; diff --git a/src/dns/dnsimple.js b/src/dns/dnsimple.js index b46bb663a..faa809c73 100644 --- a/src/dns/dnsimple.js +++ b/src/dns/dnsimple.js @@ -17,7 +17,7 @@ const assert = require('assert'), dig = require('../dig.js'), dns = require('../dns.js'), safe = require('safetydance'), - superagent = require('../superagent.js'), + superagent = require('@cloudron/superagent'), waitForDns = require('./waitfordns.js'); const DNSIMPLE_API = 'https://api.dnsimple.com/v2'; diff --git a/src/dns/gandi.js b/src/dns/gandi.js index 0d07b7e8e..ca37e891b 100644 --- a/src/dns/gandi.js +++ b/src/dns/gandi.js @@ -17,7 +17,7 @@ const assert = require('assert'), dig = require('../dig.js'), dns = require('../dns.js'), safe = require('safetydance'), - superagent = require('../superagent.js'), + superagent = require('@cloudron/superagent'), waitForDns = require('./waitfordns.js'); const GANDI_API = 'https://dns.api.gandi.net/api/v5'; diff --git a/src/dns/godaddy.js b/src/dns/godaddy.js index 459b23da0..8e3004a06 100644 --- a/src/dns/godaddy.js +++ b/src/dns/godaddy.js @@ -17,7 +17,7 @@ const assert = require('assert'), dig = require('../dig.js'), dns = require('../dns.js'), safe = require('safetydance'), - superagent = require('../superagent.js'), + superagent = require('@cloudron/superagent'), waitForDns = require('./waitfordns.js'); // const GODADDY_API_OTE = 'https://api.ote-godaddy.com/v1/domains'; diff --git a/src/dns/hetzner.js b/src/dns/hetzner.js index 1a9cfabdf..d08bdb64c 100644 --- a/src/dns/hetzner.js +++ b/src/dns/hetzner.js @@ -17,7 +17,7 @@ const assert = require('assert'), dig = require('../dig.js'), dns = require('../dns.js'), safe = require('safetydance'), - superagent = require('../superagent.js'), + superagent = require('@cloudron/superagent'), waitForDns = require('./waitfordns.js'); const ENDPOINT = 'https://dns.hetzner.com/api/v1'; diff --git a/src/dns/linode.js b/src/dns/linode.js index 869a0fd7c..263879288 100644 --- a/src/dns/linode.js +++ b/src/dns/linode.js @@ -17,7 +17,7 @@ const assert = require('assert'), dig = require('../dig.js'), dns = require('../dns.js'), safe = require('safetydance'), - superagent = require('../superagent.js'), + superagent = require('@cloudron/superagent'), waitForDns = require('./waitfordns.js'); const LINODE_ENDPOINT = 'https://api.linode.com/v4'; diff --git a/src/dns/namecheap.js b/src/dns/namecheap.js index af7af19f3..10bed1fc2 100644 --- a/src/dns/namecheap.js +++ b/src/dns/namecheap.js @@ -18,7 +18,7 @@ const assert = require('assert'), dns = require('../dns.js'), network = require('../network.js'), safe = require('safetydance'), - superagent = require('../superagent.js'), + superagent = require('@cloudron/superagent'), timers = require('timers/promises'), util = require('util'), waitForDns = require('./waitfordns.js'), diff --git a/src/dns/namecom.js b/src/dns/namecom.js index 4d38b6ee1..a220e4140 100644 --- a/src/dns/namecom.js +++ b/src/dns/namecom.js @@ -17,7 +17,7 @@ const assert = require('assert'), dig = require('../dig.js'), dns = require('../dns.js'), safe = require('safetydance'), - superagent = require('../superagent.js'), + superagent = require('@cloudron/superagent'), waitForDns = require('./waitfordns.js'); const NAMECOM_API = 'https://api.name.com/v4'; diff --git a/src/dns/netcup.js b/src/dns/netcup.js index d1f5ce6e9..1ecf502c2 100644 --- a/src/dns/netcup.js +++ b/src/dns/netcup.js @@ -17,7 +17,7 @@ const assert = require('assert'), dig = require('../dig.js'), dns = require('../dns.js'), safe = require('safetydance'), - superagent = require('../superagent.js'), + superagent = require('@cloudron/superagent'), waitForDns = require('./waitfordns.js'); const API_ENDPOINT = 'https://ccp.netcup.net/run/webservice/servers/endpoint.php?JSON'; diff --git a/src/dns/porkbun.js b/src/dns/porkbun.js index 297039c8d..48430070f 100644 --- a/src/dns/porkbun.js +++ b/src/dns/porkbun.js @@ -17,7 +17,7 @@ const assert = require('assert'), dig = require('../dig.js'), dns = require('../dns.js'), safe = require('safetydance'), - superagent = require('../superagent.js'), + superagent = require('@cloudron/superagent'), timers = require('timers/promises'), waitForDns = require('./waitfordns.js'); diff --git a/src/dns/vultr.js b/src/dns/vultr.js index 19b49ca18..f04138f21 100644 --- a/src/dns/vultr.js +++ b/src/dns/vultr.js @@ -17,7 +17,7 @@ const assert = require('assert'), dig = require('../dig.js'), dns = require('../dns.js'), safe = require('safetydance'), - superagent = require('../superagent.js'), + superagent = require('@cloudron/superagent'), waitForDns = require('./waitfordns.js'); const VULTR_ENDPOINT = 'https://api.vultr.com/v2'; diff --git a/src/mail.js b/src/mail.js index f5b2cc153..0beab0517 100644 --- a/src/mail.js +++ b/src/mail.js @@ -79,7 +79,7 @@ const assert = require('assert'), safe = require('safetydance'), services = require('./services.js'), shell = require('./shell.js')('mail'), - superagent = require('./superagent.js'), + superagent = require('@cloudron/superagent'), validator = require('./validator.js'), _ = require('./underscore.js'); diff --git a/src/metrics.js b/src/metrics.js index 00725db49..5401aa826 100644 --- a/src/metrics.js +++ b/src/metrics.js @@ -18,7 +18,7 @@ const apps = require('./apps.js'), path = require('path'), { Readable } = require('stream'), safe = require('safetydance'), - superagent = require('./superagent.js'), + superagent = require('@cloudron/superagent'), _ = require('./underscore.js'); function translateContainerStatsSync(stats) { diff --git a/src/network/generic.js b/src/network/generic.js index ecbc66bfe..68a5a4401 100644 --- a/src/network/generic.js +++ b/src/network/generic.js @@ -12,7 +12,7 @@ const assert = require('assert'), constants = require('../constants.js'), debug = require('debug')('box:network/generic'), safe = require('safetydance'), - superagent = require('../superagent.js'); + superagent = require('@cloudron/superagent'); const gCache = { ipv4: {}, ipv6: {} }; // each has { timestamp, value, request } diff --git a/src/routes/provision.js b/src/routes/provision.js index 817d9a351..1a83791b9 100644 --- a/src/routes/provision.js +++ b/src/routes/provision.js @@ -19,7 +19,7 @@ const assert = require('assert'), network = require('../network.js'), provision = require('../provision.js'), safe = require('safetydance'), - superagent = require('../superagent.js'), + superagent = require('@cloudron/superagent'), system = require('../system.js'), users = require('../users.js'); diff --git a/src/routes/test/api-test.js b/src/routes/test/api-test.js index d37bded64..64f6d3407 100644 --- a/src/routes/test/api-test.js +++ b/src/routes/test/api-test.js @@ -8,7 +8,7 @@ const common = require('./common.js'), expect = require('expect.js'), - superagent = require('../../superagent.js'), + superagent = require('@cloudron/superagent'), timers = require('timers/promises'), tokens = require('../../tokens.js'); diff --git a/src/routes/test/applinks-test.js b/src/routes/test/applinks-test.js index d144b91e2..385210d19 100644 --- a/src/routes/test/applinks-test.js +++ b/src/routes/test/applinks-test.js @@ -8,7 +8,7 @@ const applinks = require('../../applinks.js'), common = require('./common.js'), expect = require('expect.js'), - superagent = require('../../superagent.js'); + superagent = require('@cloudron/superagent'); describe('AppLinks API', function () { const { setup, cleanup, serverUrl, owner } = common; diff --git a/src/routes/test/apppasswords-test.js b/src/routes/test/apppasswords-test.js index d3ea8a1b6..74f70eed2 100644 --- a/src/routes/test/apppasswords-test.js +++ b/src/routes/test/apppasswords-test.js @@ -8,7 +8,7 @@ const common = require('./common.js'), expect = require('expect.js'), - superagent = require('../../superagent.js'); + superagent = require('@cloudron/superagent'); describe('App Passwords', function () { const { setup, cleanup, serverUrl, user } = common; diff --git a/src/routes/test/apps-test.js b/src/routes/test/apps-test.js index 930320053..39d9755f5 100644 --- a/src/routes/test/apps-test.js +++ b/src/routes/test/apps-test.js @@ -24,7 +24,7 @@ const apps = require('../../apps.js'), safe = require('safetydance'), server = require('../../server.js'), settings = require('../../settings.js'), - superagent = require('../../superagent.js'), + superagent = require('@cloudron/superagent'), tokens = require('../../tokens.js'), url = require('url'); diff --git a/src/routes/test/appstore-test.js b/src/routes/test/appstore-test.js index 6d9b733de..463443ed6 100644 --- a/src/routes/test/appstore-test.js +++ b/src/routes/test/appstore-test.js @@ -11,7 +11,7 @@ const appstore = require('../../appstore.js'), expect = require('expect.js'), nock = require('nock'), settings = require('../../settings.js'), - superagent = require('../../superagent.js'); + superagent = require('@cloudron/superagent'); const { setup, cleanup, serverUrl, owner, appstoreToken } = common; diff --git a/src/routes/test/archives-test.js b/src/routes/test/archives-test.js index 7f5b7a709..1c919f06c 100644 --- a/src/routes/test/archives-test.js +++ b/src/routes/test/archives-test.js @@ -9,7 +9,7 @@ const archives = require('../../archives.js'), backups = require('../../backups.js'), common = require('./common.js'), expect = require('expect.js'), - superagent = require('../../superagent.js'); + superagent = require('@cloudron/superagent'); describe('Archives API', function () { const { setup, cleanup, serverUrl, owner, auditSource } = common; diff --git a/src/routes/test/backups-test.js b/src/routes/test/backups-test.js index 6cf9a9445..9645d1195 100644 --- a/src/routes/test/backups-test.js +++ b/src/routes/test/backups-test.js @@ -8,7 +8,7 @@ const backups = require('../../backups.js'), common = require('./common.js'), expect = require('expect.js'), - superagent = require('../../superagent.js'); + superagent = require('@cloudron/superagent'); const BACKUP_FOLDER = '/tmp/backup_test'; diff --git a/src/routes/test/branding-test.js b/src/routes/test/branding-test.js index 7ad3a80ea..ed25bb4b7 100644 --- a/src/routes/test/branding-test.js +++ b/src/routes/test/branding-test.js @@ -10,7 +10,7 @@ const common = require('./common.js'), expect = require('expect.js'), fs = require('fs'), paths = require('../../paths.js'), - superagent = require('../../superagent.js'); + superagent = require('@cloudron/superagent'); describe('Branding API', function () { const { setup, cleanup, serverUrl, owner } = common; diff --git a/src/routes/test/cloudron-test.js b/src/routes/test/cloudron-test.js index 7d40578e1..4e980653f 100644 --- a/src/routes/test/cloudron-test.js +++ b/src/routes/test/cloudron-test.js @@ -8,7 +8,7 @@ const constants = require('../../constants.js'), common = require('./common.js'), expect = require('expect.js'), - superagent = require('../../superagent.js'); + superagent = require('@cloudron/superagent'); describe('Cloudron', function () { const { setup, cleanup, serverUrl, owner, user, dashboardFqdn } = common; diff --git a/src/routes/test/common.js b/src/routes/test/common.js index c507fbe0f..bd12ab3df 100644 --- a/src/routes/test/common.js +++ b/src/routes/test/common.js @@ -15,7 +15,7 @@ const apps = require('../../apps.js'), server = require('../../server.js'), settings = require('../../settings.js'), support = require('../../support.js'), - superagent = require('../../superagent.js'), + superagent = require('@cloudron/superagent'), tasks = require('../../tasks.js'), timers = require('timers/promises'), tokens = require('../../tokens.js'); diff --git a/src/routes/test/directoryserver-test.js b/src/routes/test/directoryserver-test.js index a277a6f19..371d13106 100644 --- a/src/routes/test/directoryserver-test.js +++ b/src/routes/test/directoryserver-test.js @@ -7,7 +7,7 @@ const common = require('./common.js'), expect = require('expect.js'), - superagent = require('../../superagent.js'); + superagent = require('@cloudron/superagent'); describe('Directory Server API', function () { const { setup, cleanup, serverUrl, owner } = common; diff --git a/src/routes/test/dockerregistries-test.js b/src/routes/test/dockerregistries-test.js index 6f5122962..2d49a9cb3 100644 --- a/src/routes/test/dockerregistries-test.js +++ b/src/routes/test/dockerregistries-test.js @@ -9,7 +9,7 @@ const common = require('./common.js'), constants = require('../../constants.js'), expect = require('expect.js'), - superagent = require('../../superagent.js'); + superagent = require('@cloudron/superagent'); describe('Docker Registries', function () { const { setup, cleanup, serverUrl, owner } = common; diff --git a/src/routes/test/domains-test.js b/src/routes/test/domains-test.js index 937688a60..88e23bbac 100644 --- a/src/routes/test/domains-test.js +++ b/src/routes/test/domains-test.js @@ -11,7 +11,7 @@ const child_process = require('child_process'), fs = require('fs'), path = require('path'), paths = require('../../paths.js'), - superagent = require('../../superagent.js'); + superagent = require('@cloudron/superagent'); const DOMAIN_0 = { domain: 'domain0.com', diff --git a/src/routes/test/eventlog-test.js b/src/routes/test/eventlog-test.js index b2cca649b..be5c994b1 100644 --- a/src/routes/test/eventlog-test.js +++ b/src/routes/test/eventlog-test.js @@ -10,7 +10,7 @@ const async = require('async'), common = require('./common.js'), eventlog = require('../../eventlog.js'), expect = require('expect.js'), - superagent = require('../../superagent.js'); + superagent = require('@cloudron/superagent'); describe('Eventlog API', function () { const { setup, cleanup, serverUrl, owner, user } = common; diff --git a/src/routes/test/externalldap-test.js b/src/routes/test/externalldap-test.js index dca91824e..c7d422744 100644 --- a/src/routes/test/externalldap-test.js +++ b/src/routes/test/externalldap-test.js @@ -7,7 +7,7 @@ const common = require('./common.js'), expect = require('expect.js'), - superagent = require('../../superagent.js'); + superagent = require('@cloudron/superagent'); describe('External LDAP API', function () { const { setup, cleanup, serverUrl, owner } = common; diff --git a/src/routes/test/groups-test.js b/src/routes/test/groups-test.js index 873095aa8..c0bcdf1fb 100644 --- a/src/routes/test/groups-test.js +++ b/src/routes/test/groups-test.js @@ -8,7 +8,7 @@ const common = require('./common.js'), expect = require('expect.js'), - superagent = require('../../superagent.js'); + superagent = require('@cloudron/superagent'); const GROUP_NAME = 'externals'; let group0Object, group1Object; diff --git a/src/routes/test/mail-test.js b/src/routes/test/mail-test.js index 53998df0c..4f7adf0c7 100644 --- a/src/routes/test/mail-test.js +++ b/src/routes/test/mail-test.js @@ -8,7 +8,7 @@ const common = require('./common.js'), expect = require('expect.js'), mail = require('../../mail.js'), - superagent = require('../../superagent.js'), + superagent = require('@cloudron/superagent'), _ = require('../../underscore.js'); describe('Mail API', function () { diff --git a/src/routes/test/network-test.js b/src/routes/test/network-test.js index a40229a48..15c8547c0 100644 --- a/src/routes/test/network-test.js +++ b/src/routes/test/network-test.js @@ -7,7 +7,7 @@ const common = require('./common.js'), expect = require('expect.js'), - superagent = require('../../superagent.js'); + superagent = require('@cloudron/superagent'); describe('Network API', function () { const { setup, cleanup, serverUrl, owner } = common; diff --git a/src/routes/test/notifications-test.js b/src/routes/test/notifications-test.js index c1a77d17e..73f1255cf 100644 --- a/src/routes/test/notifications-test.js +++ b/src/routes/test/notifications-test.js @@ -8,7 +8,7 @@ const common = require('./common.js'), expect = require('expect.js'), notifications = require('../../notifications.js'), - superagent = require('../../superagent.js'); + superagent = require('@cloudron/superagent'); describe('Notifications API', function () { const { setup, cleanup, serverUrl, owner } = common; diff --git a/src/routes/test/oidcclients-test.js b/src/routes/test/oidcclients-test.js index d6e0fb4b6..31b8b05be 100644 --- a/src/routes/test/oidcclients-test.js +++ b/src/routes/test/oidcclients-test.js @@ -8,7 +8,7 @@ const common = require('./common.js'), expect = require('expect.js'), - superagent = require('../../superagent.js'); + superagent = require('@cloudron/superagent'); const CLIENT_0 = { id: 'client0', diff --git a/src/routes/test/profile-test.js b/src/routes/test/profile-test.js index 717a953a4..1b86aa920 100644 --- a/src/routes/test/profile-test.js +++ b/src/routes/test/profile-test.js @@ -9,7 +9,7 @@ const common = require('./common.js'), expect = require('expect.js'), speakeasy = require('speakeasy'), - superagent = require('../../superagent.js'), + superagent = require('@cloudron/superagent'), tokens = require('../../tokens.js'); describe('Profile API', function () { diff --git a/src/routes/test/provision-test.js b/src/routes/test/provision-test.js index 0ccf5d1ec..2c2e9fa15 100644 --- a/src/routes/test/provision-test.js +++ b/src/routes/test/provision-test.js @@ -10,7 +10,7 @@ const common = require('./common.js'); const appstore = require('../../appstore.js'), expect = require('expect.js'), nock = require('nock'), - superagent = require('../../superagent.js'), + superagent = require('@cloudron/superagent'), timers = require('timers/promises'); const DOMAIN = 'example-server-test.com'; diff --git a/src/routes/test/support-test.js b/src/routes/test/support-test.js index f914033a2..ed2bbbbcd 100644 --- a/src/routes/test/support-test.js +++ b/src/routes/test/support-test.js @@ -10,7 +10,7 @@ const common = require('./common.js'), fs = require('fs'), nock = require('nock'), support = require('../../support.js'), - superagent = require('../../superagent.js'); + superagent = require('@cloudron/superagent'); describe('Support API', function () { const { setup, cleanup, serverUrl, owner, mockApiServerOrigin, appstoreToken, user, admin } = common; diff --git a/src/routes/test/system-test.js b/src/routes/test/system-test.js index d38766f78..f0f5393b8 100644 --- a/src/routes/test/system-test.js +++ b/src/routes/test/system-test.js @@ -13,7 +13,7 @@ const constants = require('../../constants.js'), os = require('os'), paths = require('../../paths.js'), safe = require('safetydance'), - superagent = require('../../superagent.js'); + superagent = require('@cloudron/superagent'); describe('System', function () { const { setup, cleanup, serverUrl, owner, user, waitForTask } = common; diff --git a/src/routes/test/tasks-test.js b/src/routes/test/tasks-test.js index 50d1ae98e..90c17c27d 100644 --- a/src/routes/test/tasks-test.js +++ b/src/routes/test/tasks-test.js @@ -8,7 +8,7 @@ const common = require('./common.js'), expect = require('expect.js'), safe = require('safetydance'), - superagent = require('../../superagent.js'), + superagent = require('@cloudron/superagent'), tasks = require('../../tasks.js'); describe('Tasks API', function () { diff --git a/src/routes/test/tokens-test.js b/src/routes/test/tokens-test.js index a92340828..291230e5d 100644 --- a/src/routes/test/tokens-test.js +++ b/src/routes/test/tokens-test.js @@ -7,7 +7,7 @@ const common = require('./common.js'), expect = require('expect.js'), - superagent = require('../../superagent.js'); + superagent = require('@cloudron/superagent'); describe('Tokens API', function () { const { setup, cleanup, serverUrl, owner } = common; diff --git a/src/routes/test/updater-test.js b/src/routes/test/updater-test.js index a0613975f..7b5ca547c 100644 --- a/src/routes/test/updater-test.js +++ b/src/routes/test/updater-test.js @@ -8,7 +8,7 @@ const common = require('./common.js'), constants = require('../../constants.js'), expect = require('expect.js'), - superagent = require('../../superagent.js'); + superagent = require('@cloudron/superagent'); describe('Updater API', function () { const { setup, cleanup, serverUrl, owner } = common; diff --git a/src/routes/test/user-directory-test.js b/src/routes/test/user-directory-test.js index 580f96592..96c9e2591 100644 --- a/src/routes/test/user-directory-test.js +++ b/src/routes/test/user-directory-test.js @@ -8,7 +8,7 @@ const common = require('./common.js'), expect = require('expect.js'), - superagent = require('../../superagent.js'); + superagent = require('@cloudron/superagent'); describe('User Directory API', function () { const { setup, cleanup, serverUrl, owner, user } = common; diff --git a/src/routes/test/users-test.js b/src/routes/test/users-test.js index e0184df3d..f39d14500 100644 --- a/src/routes/test/users-test.js +++ b/src/routes/test/users-test.js @@ -7,7 +7,7 @@ const common = require('./common.js'), expect = require('expect.js'), - superagent = require('../../superagent.js'), + superagent = require('@cloudron/superagent'), users = require('../../users.js'); describe('Users API', function () { diff --git a/src/routes/test/volumes-test.js b/src/routes/test/volumes-test.js index bb41d0297..c8361c3cb 100644 --- a/src/routes/test/volumes-test.js +++ b/src/routes/test/volumes-test.js @@ -8,7 +8,7 @@ const common = require('./common.js'), expect = require('expect.js'), safe = require('safetydance'), - superagent = require('../../superagent.js'); + superagent = require('@cloudron/superagent'); describe('Volumes API', function () { const { setup, cleanup, serverUrl, owner } = common; diff --git a/src/services.js b/src/services.js index fd93a26f7..2ef9498bf 100644 --- a/src/services.js +++ b/src/services.js @@ -70,7 +70,7 @@ const addonConfigs = require('./addonconfigs.js'), settings = require('./settings.js'), sftp = require('./sftp.js'), shell = require('./shell.js')('services'), - superagent = require('./superagent.js'); + superagent = require('@cloudron/superagent'); const NOOP = async function (/*app, options*/) {}; const RMADDONDIR_CMD = path.join(__dirname, 'scripts/rmaddondir.sh'); diff --git a/src/superagent.js b/src/superagent.js deleted file mode 100644 index 7be882a93..000000000 --- a/src/superagent.js +++ /dev/null @@ -1,225 +0,0 @@ -'use strict'; - -exports = module.exports = { - head, - get, - put, - post, - patch, - del, - options, - request -}; - -// IMPORTANT: do not require box code here . This is used by migration scripts -const assert = require('assert'), - consumers = require('node:stream/consumers'), - debug = require('debug')('box:superagent'), - fs = require('fs'), - http = require('http'), - https = require('https'), - path = require('path'), - safe = require('safetydance'); - -class Request { - #boundary; - #redirectCount; - #retryCount; - #timer; - #body; - #okFunc; - #options; - #url; - - constructor(method, url) { - assert.strictEqual(typeof url, 'string'); - - this.#url = new URL(url); - this.#options = { - method, - headers: {}, - signal: null // set for timeouts - }; - this.#okFunc = ({ status }) => status >=200 && status <= 299; - this.#timer = { timeout: 0, id: null, controller: null }; - this.#retryCount = 0; - this.#body = Buffer.alloc(0); - this.#redirectCount = 5; - this.#boundary = null; // multipart only - } - - async _handleResponse(url, response) { - // const contentLength = response.headers['content-length']; - // if (!contentLength || contentLength > 5*1024*1024*1024) throw new Error(`Response size unknown or too large: ${contentLength}`); - const [consumeError, data] = await safe(consumers.buffer(response)); // have to drain response - if (consumeError) throw new Error(`Error consuming body stream: ${consumeError.message}`); - if (!response.complete) throw new Error('Incomplete response'); - const contentType = response.headers['content-type']; - - const result = { - url: new URL(response.headers['location'] || '', url), - status: response.statusCode, - headers: response.headers, - body: null, - text: null - }; - - if (contentType?.includes('application/json')) { - result.text = data.toString('utf8'); - if (data.byteLength !== 0) result.body = safe.JSON.parse(result.text) || {}; - } else if (contentType?.includes('application/x-www-form-urlencoded')) { - result.text = data.toString('utf8'); - const searchParams = new URLSearchParams(data); - result.body = Object.fromEntries(searchParams.entries()); - } else if (!contentType || contentType.startsWith('text/')) { - result.body = data; - result.text = result.body.toString('utf8'); - } else { - result.body = data; - result.text = ``; - } - - return result; - } - - async _makeRequest(url) { - return new Promise((resolve, reject) => { - const proto = url.protocol === 'https:' ? https : http; - const request = proto.request(url, this.#options); // ClientRequest - - request.on('error', reject); // network error, dns error - request.on('response', async (response) => { - const [error, result] = await safe(this._handleResponse(url, response)); - if (error) reject(error); else resolve(result); - }); - - request.write(this.#body); - - request.end(); - }); - } - - async _start() { - let error; - - for (let i = 0; i < this.#retryCount+1; i++) { - if (this.#timer.timeout) this.#timer.id = setTimeout(() => this.#timer.controller.abort(), this.#timer.timeout); - // debug(`${this.#options.method} ${this.#url.toString()}` + (i ? ` try ${i+1}` : '')); - - let response, url = this.#url; - for (let redirects = 0; redirects < this.#redirectCount+1; redirects++) { - [error, response] = await safe(this._makeRequest(url)); - if (error || (response.status < 300 || response.status > 399) || (this.#options.method !== 'GET')) break; - url = response.url; // follow - } - - if (!error && !this.#okFunc({ status: response.status })) { - error = new Error(`${response.status} ${http.STATUS_CODES[response.status]}`); - Object.assign(error, response); - } - - if (error) debug(`${this.#options.method} ${this.#url.toString()} ${error.message}`); - if (this.#timer.timeout) clearTimeout(this.#timer.id); - if (!error) return response; - } - - throw error; - } - - set(name, value) { - this.#options.headers[name.toLowerCase()] = value; - return this; - } - - query(data) { - Object.entries(data).forEach(([key, value]) => this.#url.searchParams.append(key, value)); - return this; - } - - redirects(count) { - this.#redirectCount = count; - return this; - } - - send(data) { - const contentType = this.#options.headers['content-type']; - if (!contentType || contentType === 'application/json') { - this.#options.headers['content-type'] = 'application/json'; - this.#body = Buffer.from(JSON.stringify(data), 'utf8'); - this.#options.headers['content-length'] = this.#body.byteLength; - } else if (contentType === 'application/x-www-form-urlencoded') { - this.#body = Buffer.from((new URLSearchParams(data)).toString(), 'utf8'); - this.#options.headers['content-length'] = this.#body.byteLength; - } - return this; - } - - timeout(msecs) { - this.#timer.controller = new AbortController(); - this.#timer.timeout = msecs; - this.#options.signal = this.#timer.controller.signal; - return this; - } - - retry(count) { - this.#retryCount = Math.max(0, count); - return this; - } - - ok(func) { - this.#okFunc = func; - return this; - } - - disableTLSCerts() { - this.#options.rejectUnauthorized = false; - return this; - } - - auth(username, password) { - this.set('Authorization', 'Basic ' + btoa(`${username}:${password}`)); - return this; - } - - field(name, value) { - if (!this.#boundary) this.#boundary = '----WebKitFormBoundary' + Math.random().toString(36).substring(2); - - const partHeader = Buffer.from(`--${this.#boundary}\r\nContent-Disposition: form-data; name="${name}"\r\n\r\n`, 'utf8'); - const partData = Buffer.from(value, 'utf8'); - this.#body = Buffer.concat([this.#body, partHeader, partData, Buffer.from('\r\n', 'utf8')]); - - return this; - } - - attach(name, filepathOrBuffer) { // this is only used in tests and thus simplistic - if (!this.#boundary) this.#boundary = '----WebKitFormBoundary' + Math.random().toString(36).substring(2); - - const filename = Buffer.isBuffer(filepathOrBuffer) ? name : path.basename(filepathOrBuffer); - const partHeader = Buffer.from(`--${this.#boundary}\r\nContent-Disposition: form-data; name="${name}" filename="${filename}"\r\n\r\n`, 'utf8'); - const partData = Buffer.isBuffer(filepathOrBuffer) ? filepathOrBuffer : fs.readFileSync(filepathOrBuffer); - this.#body = Buffer.concat([this.#body, partHeader, partData, Buffer.from('\r\n', 'utf8')]); - - return this; - } - - then(onFulfilled, onRejected) { - if (this.#boundary) { - const partTrailer = Buffer.from(`--${this.#boundary}--\r\n`, 'utf8'); - this.#body = Buffer.concat([this.#body, partTrailer]); - - this.#options.headers['content-type'] = `multipart/form-data; boundary=${this.#boundary}`; - this.#options.headers['content-length'] = this.#body.byteLength; - } - - this._start().then(onFulfilled, onRejected); - } -} - -function head(url) { return new Request('GET', url); } -function get(url) { return new Request('GET', url); } -function put(url) { return new Request('PUT', url); } -function post(url) { return new Request('POST', url); } -function patch(url) { return new Request('PATCH', url); } -function del(url) { return new Request('DELETE', url); } -function options(url) { return new Request('OPTIONS', url); } -function request(method, url) { return new Request(method, url); } diff --git a/src/test/server-test.js b/src/test/server-test.js index eda954b74..d57ed60f4 100644 --- a/src/test/server-test.js +++ b/src/test/server-test.js @@ -10,7 +10,7 @@ const constants = require('../constants.js'), expect = require('expect.js'), safe = require('safetydance'), server = require('../server.js'), - superagent = require('../superagent.js'); + superagent = require('@cloudron/superagent'); const SERVER_URL = 'http://localhost:' + constants.PORT; diff --git a/src/test/superagent-test.js b/src/test/superagent-test.js index 991603c48..8601e070d 100644 --- a/src/test/superagent-test.js +++ b/src/test/superagent-test.js @@ -5,7 +5,7 @@ const expect = require('expect.js'), safe = require('safetydance'), - superagent = require('../superagent.js'); + superagent = require('@cloudron/superagent'); describe('Superagent', function () { it('can get URL', async function () { diff --git a/src/users.js b/src/users.js index aca657fbb..7d4d65be1 100644 --- a/src/users.js +++ b/src/users.js @@ -101,7 +101,7 @@ const appPasswords = require('./apppasswords.js'), uaParser = require('ua-parser-js'), userDirectory = require('./user-directory.js'), uuid = require('uuid'), - superagent = require('./superagent.js'), + superagent = require('@cloudron/superagent'), util = require('util'), validator = require('./validator.js'), _ = require('./underscore.js'); diff --git a/src/wellknown.js b/src/wellknown.js index 4073b6197..274896787 100644 --- a/src/wellknown.js +++ b/src/wellknown.js @@ -13,7 +13,7 @@ const assert = require('assert'), mail = require('./mail.js'), mailServer = require('./mailserver.js'), safe = require('safetydance'), - superagent = require('./superagent.js'); + superagent = require('@cloudron/superagent'); const MAIL_AUTOCONFIG_EJS = fs.readFileSync(__dirname + '/autoconfig.xml.ejs', { encoding: 'utf8' });