Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TRIGGER] npm new release #12149

Merged
merged 1 commit into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions components/npm/common/constants.mjs
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,
};
4 changes: 0 additions & 4 deletions components/npm/npm.app.js

This file was deleted.

32 changes: 32 additions & 0 deletions components/npm/npm.app.mjs
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,
});
},
},
};
6 changes: 3 additions & 3 deletions components/npm/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "@pipedream/npm",
"version": "0.3.6",
"version": "0.4.0",
"description": "Pipedream Npm Components",
"main": "npm.app.js",
"main": "npm.app.mjs",
"keywords": [
"pipedream",
"npm"
Expand All @@ -14,6 +14,6 @@
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^1.2.0"
"@pipedream/platform": "^3.0.0"
}
}
49 changes: 0 additions & 49 deletions components/npm/sources/download-counts/download-counts.js

This file was deleted.

69 changes: 69 additions & 0 deletions components/npm/sources/download-counts/download-counts.mjs
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 components/npm/sources/new-package-version/new-package-version.mjs
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),
});
},
};
4 changes: 2 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading