forked from cloudflare/node-cloudflare
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This change adds support for the Cloudflare Workers API endpoints, allowing users to upload and manage their worker scripts and routes. Two set of endpoints are provided, one for non-Enterprise zones, and another for Enterprise zones. Internally, endpoints can now specify an alternative Content-Type for the request body and disable automatic JSON parsing of the response. [terinjokes@gmail.com: dropped non-source changes and added commit msg] Signed-off-by: Terin Stock <terinjokes@gmail.com>
- Loading branch information
1 parent
7d3d1b8
commit 92af8b0
Showing
9 changed files
with
474 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Copyright (C) 2014-present Cloudflare, Inc. | ||
* This software may be modified and distributed under the terms | ||
* of the MIT license. See the LICENSE file for details. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const prototypal = require('es-class'); | ||
const auto = require('autocreate'); | ||
|
||
const Resource = require('../Resource'); | ||
|
||
/** | ||
* EnterpriseZoneWorkersRoutes represents the zones/:zoneId/workers/routes API endpoint. | ||
* | ||
* @class EnterpriseZoneWorkersRoutes | ||
* @hideconstructor | ||
* @extends Resource | ||
*/ | ||
module.exports = auto( | ||
prototypal({ | ||
extends: Resource, | ||
path: 'zones/:zoneId/workers/routes', | ||
|
||
includeBasic: ['browse', 'read', 'edit', 'add', 'del'], | ||
|
||
/** | ||
* browse allows for listing all of a zone's workers routes | ||
* | ||
* @function browse | ||
* @memberof EnterpriseZoneWorkersRoutes | ||
* @instance | ||
* @async | ||
* @param {string} zone_id - The zone ID | ||
* @returns {Promise<Object>} The route browse response object. | ||
*/ | ||
/** | ||
* read allows for retrieving a specific zone's workers route | ||
* | ||
* @function read | ||
* @memberof EnterpriseZoneWorkersRoutes | ||
* @instance | ||
* @async | ||
* @param {string} zone_id - The zone ID | ||
* @param {string} id - The route ID | ||
* @returns {Promise<Object>} The route response object. | ||
*/ | ||
/** | ||
* edit allows for modifying a specific zone's workers | ||
* | ||
* @function edit | ||
* @memberof EnterpriseZoneWorkersRoutes | ||
* @instance | ||
* @async | ||
* @param {string} zone_id - The zone ID | ||
* @param {string} id - The route ID | ||
* @param {Object} config - The modified route object | ||
* @returns {Promise<Object>} The custom hostname response object. | ||
*/ | ||
/** | ||
* add allows for creating a workers route | ||
* | ||
* @function add | ||
* @memberof EnterpriseZoneWorkersRoutes | ||
* @instance | ||
* @async | ||
* @param {string} zone_id - The zone ID | ||
* @param {Object} config - The new route object | ||
* @returns {Promise<Object>} The custom route response object. | ||
*/ | ||
/** | ||
* del allows for removing a workers routes | ||
* | ||
* @function del | ||
* @memberof EnterpriseZoneWorkersRoutes | ||
* @instance | ||
* @async | ||
* @param {string} zone_id - The zone ID | ||
* @param {string} id - The route ID to delete | ||
* @returns {Promise<Object>} The custom route response object. | ||
*/ | ||
}) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright (C) 2014-present Cloudflare, Inc. | ||
* This software may be modified and distributed under the terms | ||
* of the MIT license. See the LICENSE file for details. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const prototypal = require('es-class'); | ||
const auto = require('autocreate'); | ||
|
||
const Resource = require('../Resource'); | ||
const method = require('../method'); | ||
|
||
/** | ||
* EnterpriseZoneWorkersScripts represents the accounts/:accountId/workers/scripts API endpoint. | ||
* | ||
* @class EnterpriseZoneWorkersScripts | ||
* @hideconstructor | ||
* @extends Resource | ||
*/ | ||
module.exports = auto( | ||
prototypal({ | ||
extends: Resource, | ||
path: 'accounts/:accountId/workers/scripts', | ||
|
||
includeBasic: ['browse', 'del'], | ||
|
||
/** | ||
* read retrieves a single workers script | ||
* | ||
* @function read | ||
* @memberof EnterpriseZoneWorkersScripts | ||
* @instance | ||
* @async | ||
* @param {string} account_id - The enterprise account ID | ||
* @param {string} name - The script name | ||
* @returns {Promise<Object>} The workers script response object. | ||
*/ | ||
read: method({ | ||
method: 'GET', | ||
path: ':name', | ||
json: false, | ||
}), | ||
|
||
/** | ||
* edit uploads a new version of a workers script | ||
* | ||
* @function edit | ||
* @memberof EnterpriseZoneWorkersScripts | ||
* @instance | ||
* @async | ||
* @param {string} account_id - The enterprise account ID | ||
* @param {string} name - The script name | ||
* @param {string} script - The script | ||
* @returns {Promise<Object>} The response object | ||
*/ | ||
edit: method({ | ||
method: 'PUT', | ||
path: ':name', | ||
contentType: 'application/javascript', | ||
}), | ||
|
||
/** | ||
* browse allows for listing all the workers scripts | ||
* | ||
* @function browse | ||
* @memberof EnterpriseZoneWorkersScripts | ||
* @instance | ||
* @async | ||
* @param {string} account_id - The enterprise account ID | ||
* @param {string} name - The script name | ||
* @returns {Promise<Object>} The zone workers script response object. | ||
*/ | ||
/** | ||
* del allows for deleting the specified workers script | ||
* | ||
* @function del | ||
* @memberof EnterpriseZoneWorkersScripts | ||
* @instance | ||
* @async | ||
* @param {string} account_id - The enterprise account ID | ||
* @param {string} name - The script name | ||
* @returns {Promise<Object>} The deleted zone workers script response object. | ||
*/ | ||
}) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright (C) 2014-present Cloudflare, Inc. | ||
* This software may be modified and distributed under the terms | ||
* of the MIT license. See the LICENSE file for details. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const prototypal = require('es-class'); | ||
const auto = require('autocreate'); | ||
|
||
const Resource = require('../Resource'); | ||
const method = require('../method'); | ||
|
||
/** | ||
* ZoneWorkers represents the /zones/:zoneId/workers API endpoint. | ||
* | ||
* @class ZoneWorkers | ||
* @hideconstructor | ||
* @extends Resource | ||
*/ | ||
module.exports = auto( | ||
prototypal({ | ||
extends: Resource, | ||
path: 'zones/:zoneId/workers', | ||
|
||
/** | ||
* validate allows for validating a workers script | ||
* | ||
* @function validate | ||
* @memberof ZoneWorkers | ||
* @instance | ||
* @async | ||
* @param {string} zoneId - The zone ID | ||
* @param {string} script - The worker script | ||
* @returns {Promise<Object>} The validate response object. | ||
*/ | ||
validate: method({ | ||
method: 'PUT', | ||
path: 'validate', | ||
contentType: 'application/javascript', | ||
}), | ||
}) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Copyright (C) 2014-present Cloudflare, Inc. | ||
* This software may be modified and distributed under the terms | ||
* of the MIT license. See the LICENSE file for details. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const prototypal = require('es-class'); | ||
const auto = require('autocreate'); | ||
|
||
const Resource = require('../Resource'); | ||
const method = require('../method'); | ||
|
||
/** | ||
* ZoneWorkersRoutes represents the zones/:zoneId/workers/filters API endpoint. | ||
* | ||
* @class ZoneWorkersRoutes | ||
* @hideconstructor | ||
* @extends Resource | ||
*/ | ||
module.exports = auto( | ||
prototypal({ | ||
extends: Resource, | ||
path: 'zones/:zoneId/workers/filters', | ||
|
||
includeBasic: ['browse', 'read', 'add', 'del'], | ||
|
||
/** | ||
* edit allows for modifying a specific zone's workers route | ||
* | ||
* @function edit | ||
* @memberof ZoneWorkersRoutes | ||
* @instance | ||
* @async | ||
* @param {string} zone_id - The zone ID | ||
* @param {string} id - The route ID | ||
* @param {Object} config - The modified route object | ||
* @returns {Promise<Object>} The custom hostname response object. | ||
*/ | ||
edit: method({ | ||
method: 'PUT', | ||
path: ':id', | ||
}), | ||
|
||
/** | ||
* browse allows for listing all of a zone's workers routes | ||
* | ||
* @function browse | ||
* @memberof ZoneWorkersRoutes | ||
* @instance | ||
* @async | ||
* @param {string} zone_id - The zone ID | ||
* @returns {Promise<Object>} The route browse response object. | ||
*/ | ||
/** | ||
* read allows for retrieving a specific zone's workers route | ||
* | ||
* @function read | ||
* @memberof ZoneWorkersRoutes | ||
* @instance | ||
* @async | ||
* @param {string} zone_id - The zone ID | ||
* @param {string} id - The route ID | ||
* @returns {Promise<Object>} The route response object. | ||
*/ | ||
/** | ||
* add allows for creating a workers route | ||
* | ||
* @function add | ||
* @memberof ZoneWorkersRoutes | ||
* @instance | ||
* @async | ||
* @param {string} zone_id - The zone ID | ||
* @param {Object} config - The new route object | ||
* @returns {Promise<Object>} The custom route response object. | ||
*/ | ||
/** | ||
* del allows for removing a workers route | ||
* | ||
* @function del | ||
* @memberof ZoneWorkersRoutes | ||
* @instance | ||
* @async | ||
* @param {string} zone_id - The zone ID | ||
* @param {string} id - The route ID to delete | ||
* @returns {Promise<Object>} The custom route response object. | ||
*/ | ||
}) | ||
); |
Oops, something went wrong.