
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
functional fastly api with promises. A simple, minimal node.js fastly api wrapper. Sends the requests out and gives you back promises which resolve to the parsed object.
This library seeks to be developer friendly by providing promises and mapping each endpoint to a function for you, hopefully resulting in less time reading documentation: less fat-fingering of URLs, less forgetting http verbs.
For information on request parameters and response formats, please read: https://docs.fastly.com/api/
Currently in development and does not immediately seek to cover all endpoints but open to it. Pull requests and feature requests welcome.
Tested with node4+
This denotes a promise is being returned. It is an opinionated style that I've adopted because unless you are using an IDE with really good type hinting you don't always know when a promise is being returned or not. And unlike other javascript types promises cannot and should not be silently coerced into their resolved value. Functions returning promises are always treated differently so this naming convention makes this behavior obvious.
If set, phastly will automatically use the environment variable process.env.FASTLY_API_KEY. Or set/change the key with function setApiKey()
This is a great project for populating env variables from a file: https://www.npmjs.com/package/dotenv
import * as fastly from 'phastly'
// or
// const fastly = require('phastly')
function setupP(name) {
return fastly.createServiceP(name)
.then((service) => {
// use service here
})
}
import * as fastly from 'phastly'
async function setupP(name) {
let service = await fastly.createServiceP(name)
const backendData = {
name: service.name,
address: `foobarbaz.storage.googleapis.com`,
hostname: `foobarbaz.storage.googleapis.com`,
port: 443,
}
const p1 = fastly.createBackendP(service.id, 1, backendData)
const domainData = {
name: `foobarbaz.global.ssl.fastly.net`,
comment: 'generated by my app'
}
const p2 = fastly.createDomainP(service.id, 1, domainData)
const settingsData = {
'general.default_host': `foobarbaz.storage.googleapis.com`
}
const p3 = fastly.updateSettingsP(service.id, 1, settingsData)
await Promise.all([p1, p2, p3])
return fastly.activateServiceVersionP(service.id, 1)
}
phastly module.
PromisePromisePromisePromisePromisePromisePromisePromisePromisePromisePromisePromisePromisePromisePromisePromisePromiseObjectPromisePromisePromisePromisePromisePromisePromisePromisePromisePromiseWrapper to send a fastly api request. Use this if the endpoint you need hasn't been mapped to a function.
Kind: static method of phastly
Returns: Promise - resolving to response
| Param | Type | Description |
|---|---|---|
| options | Object | |
| options.params | Object | parameters to upload with encoding: application/x-www-form-urlencoded |
| options.baseUrl | string | fastly api baseUrl (default: 'https://api.fastly.com') |
| options.endpoint | string | fastly api endpoint e.g. 'service/${serviceId}/version/${version}/backend' (default: '') |
| options.headers | Object | add to or overwrite the default headers (default: {'Fastly-Key', Accept}) |
| options.method | string | the http method (default: GET) |
| options.timeout | number | the connection timeout in ms (default: 5000) |
PromiseInstant Purge a particular service of items tagged with a Surrogate Key. Soft Purging sets an object's TTL to 0s, forcing revalidation. For best results, Soft Purging should be used in conjuction with stale_while_revalidate and stale_if_error.
Kind: static method of phastly
Returns: Promise - resolves to parsed api result object
| Param | Type | Default | Description |
|---|---|---|---|
| serviceId | string | ||
| key | string | ||
| [soft] | Boolean | false | sets an object's TTL to 0s |
PromiseInstant Purge an individual URL. Soft Purging sets an object's TTL to 0s, forcing revalidation. For best results, Soft Purging should be used in conjuction with stale_while_revalidate and stale_if_error.
Kind: static method of phastly
Returns: Promise - resolves to parsed api result object
| Param | Type | Default |
|---|---|---|
| url | string | |
| [soft] | Boolean | false |
PromiseInstant Purge everything from a service
Kind: static method of phastly
Returns: Promise - resolves to parsed api result object
| Param | Type |
|---|---|
| serviceId | string |
PromiseCreate a backend for a particular service and version
Kind: static method of phastly
Returns: Promise - resolves to parsed api result object
| Param | Type | Description |
|---|---|---|
| serviceId | string | |
| version | number | |
| data | Object | keys are backend object keys |
PromiseDelete the backend for a particular service and version
Kind: static method of phastly
Returns: Promise - resolves to parsed api result object
| Param | Type | Description |
|---|---|---|
| serviceId | string | |
| version | number | |
| name | string | name of backend |
PromiseCreate a service
Kind: static method of phastly
Returns: Promise - resolves to parsed api result object
| Param | Type |
|---|---|
| name | string |
PromiseUpdate a service
Kind: static method of phastly
Returns: Promise - resolves to parsed api result object
| Param | Type | Description |
|---|---|---|
| params | Object | key/values of paramters to update |
PromiseCreate a version for a particular service
Kind: static method of phastly
Returns: Promise - resolves to parsed api result object
| Param | Type |
|---|---|
| serviceId | string |
PromiseUpdate a particular version for a particular service.
Kind: static method of phastly
Returns: Promise - resolves to parsed api result object
| Param | Type | Description |
|---|---|---|
| serviceId | string | |
| version | number | |
| data | Object | keys are service object keys |
PromiseValidate the version for a particular service and version
Kind: static method of phastly
Returns: Promise - resolves to parsed api result object
| Param | Type |
|---|---|
| serviceId | string |
| version | number |
PromiseActivate the current version
Kind: static method of phastly
Returns: Promise - resolves to parsed api result object
| Param | Type |
|---|---|
| serviceId | string |
| version | number |
PromiseDeactivate the current version
Kind: static method of phastly
Returns: Promise - resolves to parsed api result object
| Param | Type |
|---|---|
| serviceId | string |
| version | number |
PromiseClone the current configuration into a new version
Kind: static method of phastly
Returns: Promise - resolves to parsed api result object
| Param | Type |
|---|---|
| serviceId | string |
| version | number |
PromiseLocks the specified version
Kind: static method of phastly
Returns: Promise - resolves to parsed api result object
| Param | Type |
|---|---|
| serviceId | string |
| version | number |
PromiseDelete a service
Kind: static method of phastly
Returns: Promise - resolves to parsed api result object
| Param | Type |
|---|---|
| serviceId | string |
PromiseRename a service
Kind: static method of phastly
Returns: Promise - resolves to parsed api result object
| Param | Type |
|---|---|
| serviceId | string |
| newName | string |
Objecthelper function - get active version from a fastly version list
Kind: static method of phastly
Returns: Object - version information
| Param | Type | Description |
|---|---|---|
| versions | Array.<Object> | of the service |
PromiseList services
Kind: static method of phastly
Returns: Promise - resolves to parsed api result object
PromiseGet a service by id
Kind: static method of phastly
Returns: Promise - resolves to parsed api result object
| Param | Type |
|---|---|
| serviceId | string |
PromiseGet a service by name
Kind: static method of phastly
Returns: Promise - resolves to parsed api result object
| Param | Type | Description |
|---|---|---|
| name | string | name of service |
PromiseList detailed information on a specified service
Kind: static method of phastly
Returns: Promise - resolves to parsed api result object
| Param | Type |
|---|---|
| serviceId | string |
PromiseList the domains within a service
Kind: static method of phastly
Returns: Promise - resolves to deserialized response
| Param | Type | Description |
|---|---|---|
| service | string | id |
PromiseCreate a domain for a particular service and version
Kind: static method of phastly
Returns: Promise - resolves to parsed api result object
| Param | Type | Description |
|---|---|---|
| serviceId | string | |
| version | number | |
| data | Object | fastly domain object |
PromiseCheck all domains' DNS for a particular service and version
Kind: static method of phastly
Returns: Promise - resolves to parsed api result object
| Param | Type |
|---|---|
| serviceId | string |
| version | number |
PromiseCreate a new Request Settings object
Kind: static method of phastly
| Param | Type | Description |
|---|---|---|
| serviceId | string | |
| version | number | |
| settings | Object | fastly request settings object: {hash_keys, action, ...} |
PromiseUpdate the settings for a particular service and version
Kind: static method of phastly
Returns: Promise - resolves to parsed api result object
| Param | Type | Description |
|---|---|---|
| serviceId | string | |
| version | number | |
| settings | Object | fastly settings object e.g. {general.default_host, general.default_ttl, ...} |
set or change the fastly api key
Kind: static method of phastly
| Param | Type | Description |
|---|---|---|
| key | string | your fastly api key |
To update README.md make changes in doc/README.md.hbs and/or src/index.js and run doc/generate
FAQs
(P)romises for F(hastly) - functional fastly api with promises
The npm package phastly receives a total of 0 weekly downloads. As such, phastly popularity was classified as not popular.
We found that phastly demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.