-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get package metadata in source component with polling request strategy (
- Loading branch information
Showing
8 changed files
with
171 additions
and
58 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const WEBHOOK_ID = "webhookId"; | ||
const SECRET = "secret"; | ||
|
||
const API = { | ||
DEFAULT: { | ||
BASE_URL: "https://api.npmjs.org", | ||
VERSION_PATH: "", | ||
}, | ||
REGISTRY: { | ||
BASE_URL: "https://registry.npmjs.org", | ||
VERSION_PATH: "/-/npm/v1", | ||
}, | ||
}; | ||
|
||
export default { | ||
API, | ||
WEBHOOK_ID, | ||
SECRET, | ||
}; |
This file was deleted.
Oops, something went wrong.
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,32 @@ | ||
import { axios } from "@pipedream/platform"; | ||
import constants from "./common/constants.mjs"; | ||
|
||
export default { | ||
type: "app", | ||
app: "npm", | ||
methods: { | ||
getUrl(path, api = constants.API.DEFAULT, withVersion = false) { | ||
return `${api.BASE_URL}${withVersion && api.VERSION_PATH || ""}${path}`; | ||
}, | ||
makeRequest({ | ||
$ = this, path, api, withVersion, ...args | ||
} = {}) { | ||
return axios($, { | ||
...args, | ||
url: this.getUrl(path, api, withVersion), | ||
}); | ||
}, | ||
getPackageMetadata({ | ||
packageName, ...args | ||
} = {}) { | ||
return this.makeRequest({ | ||
api: constants.API.REGISTRY, | ||
path: `/${packageName}`, | ||
headers: { | ||
"Accept": "application/vnd.npm.install-v1+json", | ||
}, | ||
...args, | ||
}); | ||
}, | ||
}, | ||
}; |
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 was deleted.
Oops, something went wrong.
69 changes: 69 additions & 0 deletions
69
components/npm/sources/download-counts/download-counts.mjs
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,69 @@ | ||
import app from "../../npm.app.mjs"; | ||
|
||
export default { | ||
key: "npm-download-counts", | ||
name: "New Download Counts", | ||
description: "Emit new event with the latest count of downloads for an npm package. [See the documentation](https://github.com/npm/registry/blob/main/docs/download-counts.md).", | ||
version: "0.1.0", | ||
type: "source", | ||
props: { | ||
app, | ||
db: "$.service.db", | ||
timer: { | ||
type: "$.interface.timer", | ||
description: "One day interval time is recommended because NPM only update metrics once a day. [See the documentation](https://github.com/npm/registry/blob/main/docs/download-counts.md#data-source).", | ||
default: { | ||
intervalSeconds: 60 * 60 * 24, | ||
}, | ||
}, | ||
period: { | ||
type: "string", | ||
label: "Period", | ||
description: "Select last-day, last-week or last-month.", | ||
optional: false, | ||
default: "last-day", | ||
options: [ | ||
"last-day", | ||
"last-week", | ||
"last-month", | ||
], | ||
}, | ||
packageName: { | ||
type: "string", | ||
label: "Package", | ||
description: "Enter an npm package name. Leave blank for all", | ||
optional: true, | ||
}, | ||
}, | ||
methods: { | ||
getDownloadCounts({ | ||
period, packageName, ...args | ||
} = {}) { | ||
const basePath = `/downloads/point/${encodeURIComponent(period)}`; | ||
return this.app.makeRequest({ | ||
path: packageName | ||
? `${basePath}/${encodeURIComponent(packageName)}` | ||
: basePath, | ||
...args, | ||
}); | ||
}, | ||
}, | ||
async run({ timestamp: ts }) { | ||
const { | ||
getDownloadCounts, | ||
period, | ||
packageName, | ||
} = this; | ||
|
||
const response = await getDownloadCounts({ | ||
period, | ||
packageName, | ||
}); | ||
|
||
this.$emit(response, { | ||
id: ts, | ||
summary: `New Download Count ${response.downloads}`, | ||
ts, | ||
}); | ||
}, | ||
}; |
46 changes: 46 additions & 0 deletions
46
components/npm/sources/new-package-version/new-package-version.mjs
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,46 @@ | ||
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform"; | ||
import app from "../../npm.app.mjs"; | ||
|
||
export default { | ||
key: "npm-new-package-version", | ||
name: "New Package Version", | ||
description: "Emit new event when a new version of an npm package is published. [See the documentation](https://github.com/npm/registry/blob/main/docs/responses/package-metadata.md)", | ||
version: "0.0.1", | ||
type: "source", | ||
dedupe: "unique", | ||
props: { | ||
app, | ||
db: "$.service.db", | ||
timer: { | ||
type: "$.interface.timer", | ||
default: { | ||
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, | ||
}, | ||
}, | ||
packageName: { | ||
type: "string", | ||
label: "Package", | ||
description: "Enter an npm package name. Leave blank for all", | ||
default: "@pipedream/platform", | ||
}, | ||
}, | ||
async run() { | ||
const { | ||
app, | ||
packageName, | ||
} = this; | ||
|
||
const response = await app.getPackageMetadata({ | ||
debug: true, | ||
packageName, | ||
}); | ||
|
||
const { "dist-tags": { latest: latestVersion } } = response; | ||
|
||
this.$emit(response, { | ||
id: latestVersion, | ||
summary: `New Package Version ${latestVersion}`, | ||
ts: Date.parse(response.modified), | ||
}); | ||
}, | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.