diff --git a/components/clearly_defined/actions/create-definition/create-definition.mjs b/components/clearly_defined/actions/create-definition/create-definition.mjs new file mode 100644 index 0000000000000..223ee50651aee --- /dev/null +++ b/components/clearly_defined/actions/create-definition/create-definition.mjs @@ -0,0 +1,60 @@ +import clearlyDefined from "../../clearly_defined.app.mjs"; + +export default { + key: "clearly_defined-create-definition", + name: "Create Definition", + description: "Request the creation of a resource. [See the documentation](https://api.clearlydefined.io/api-docs/#/definitions/post_definitions).", + version: "0.0.1", + type: "action", + props: { + clearlyDefined, + type: { + propDefinition: [ + clearlyDefined, + "type", + ], + }, + provider: { + propDefinition: [ + clearlyDefined, + "provider", + ], + }, + namespace: { + propDefinition: [ + clearlyDefined, + "namespace", + ], + }, + name: { + propDefinition: [ + clearlyDefined, + "name", + ], + }, + revision: { + propDefinition: [ + clearlyDefined, + "revision", + ], + }, + }, + async run({ $ }) { + const component = `${this.type}/${this.provider}/${this.namespace}/${this.name}${this.revision + ? "/" + this.revision + : ""}`; + + const response = await this.clearlyDefined.createDefinition({ + $, + data: [ + component, + ], + }); + + if (response && Object.keys(response).length > 0) { + $.export("$summary", "Successfully created definition"); + } + + return response; + }, +}; diff --git a/components/clearly_defined/actions/get-definitions/get-definitions.mjs b/components/clearly_defined/actions/get-definitions/get-definitions.mjs new file mode 100644 index 0000000000000..8bd812c73f9bc --- /dev/null +++ b/components/clearly_defined/actions/get-definitions/get-definitions.mjs @@ -0,0 +1,140 @@ +import clearlyDefined from "../../clearly_defined.app.mjs"; + +export default { + key: "clearly_defined-get-definitions", + name: "Get Definitions", + description: "Gets the coordinates for all definitions that match the given pattern in the specified part of the definition. [See the documentation](https://api.clearlydefined.io/api-docs/#/definitions/get_definitions).", + version: "0.0.1", + type: "action", + props: { + clearlyDefined, + pattern: { + type: "string", + label: "Pattern", + description: "The string to search for in definition coordinates to get coordinate suggestions", + optional: true, + }, + type: { + propDefinition: [ + clearlyDefined, + "type", + ], + optional: true, + }, + provider: { + propDefinition: [ + clearlyDefined, + "provider", + ], + optional: true, + }, + namespace: { + propDefinition: [ + clearlyDefined, + "namespace", + ], + optional: true, + }, + name: { + propDefinition: [ + clearlyDefined, + "name", + ], + optional: true, + }, + license: { + type: "string", + label: "License", + description: "The SPDX license identifier", + optional: true, + }, + releasedAfter: { + type: "string", + label: "Released After", + description: "The minimum release date for the component. E.g. `2025-01-01`", + optional: true, + }, + releasedBefore: { + type: "string", + label: "Released Before", + description: "The maximum release date for the component. E.g. `2025-01-01`", + optional: true, + }, + minLicensedScore: { + type: "integer", + label: "Min Licensed Score", + description: "The minimum effective licensed score for the component", + optional: true, + }, + maxLicensedScore: { + type: "integer", + label: "Max Licensed Score", + description: "The maximum effective licensed score for the component", + optional: true, + }, + minDescribedScore: { + type: "integer", + label: "Min Described Score", + description: "The minimum effective described score for the component", + optional: true, + }, + maxDescribedScore: { + type: "integer", + label: "Max Described Score", + description: "The maximum effective described score for the component", + optional: true, + }, + sort: { + propDefinition: [ + clearlyDefined, + "sort", + ], + }, + sortDirection: { + propDefinition: [ + clearlyDefined, + "sortDirection", + ], + }, + continuationToken: { + type: "string", + label: "Continuation Token", + description: "Used for pagination. Seeded from the results of the previous query", + optional: true, + }, + }, + async run({ $ }) { + const response = await this.clearlyDefined.getDefinitions({ + $, + params: { + pattern: this.pattern, + type: this.type, + provider: this.provider, + name: this.name, + namespace: this.namespace, + license: this.license, + releasedAfter: this.releasedAfter, + releasedBefore: this.releasedBefore, + minLicensedScore: this.minLicensedScore, + maxLicensedScore: this.maxLicensedScore, + minDescribedScore: this.minDescribedScore, + maxDescribedScore: this.maxDescribedScore, + sort: this.sort, + sortDesc: this.sortDirection === "descending", + continuationToken: this.continuationToken, + }, + }); + + const length = response.data + ? response.data.length + : response.length + ? response.length + : 0; + + $.export("$summary", `Successfully retrieved ${length} definition${length === 1 + ? "" + : "s"}`); + + return response; + }, +}; diff --git a/components/clearly_defined/actions/get-harvests/get-harvests.mjs b/components/clearly_defined/actions/get-harvests/get-harvests.mjs new file mode 100644 index 0000000000000..2baa75e556c34 --- /dev/null +++ b/components/clearly_defined/actions/get-harvests/get-harvests.mjs @@ -0,0 +1,67 @@ +import clearlyDefined from "../../clearly_defined.app.mjs"; + +export default { + key: "clearly_defined-get-harvests", + name: "Get Harvests", + description: "Get all the harvested data for a component revision. [See the documentation](https://api.clearlydefined.io/api-docs/#/harvest/get_harvest__type___provider___namespace___name___revision_).", + version: "0.0.1", + type: "action", + props: { + clearlyDefined, + type: { + propDefinition: [ + clearlyDefined, + "type", + ], + }, + provider: { + propDefinition: [ + clearlyDefined, + "provider", + ], + }, + namespace: { + propDefinition: [ + clearlyDefined, + "namespace", + ], + }, + name: { + propDefinition: [ + clearlyDefined, + "name", + ], + }, + revision: { + propDefinition: [ + clearlyDefined, + "revision", + ], + }, + form: { + propDefinition: [ + clearlyDefined, + "form", + ], + }, + }, + async run({ $ }) { + const response = await this.clearlyDefined.getHarvests({ + $, + type: this.type, + provider: this.provider, + name: this.name, + namespace: this.namespace, + revision: this.revision, + params: { + form: this.form, + }, + }); + + if (response && Object.keys(response).length > 0) { + $.export("$summary", "Successfully retrieved harvest details"); + } + + return response; + }, +}; diff --git a/components/clearly_defined/clearly_defined.app.mjs b/components/clearly_defined/clearly_defined.app.mjs index 2298be03d05a0..13707c76a651e 100644 --- a/components/clearly_defined/clearly_defined.app.mjs +++ b/components/clearly_defined/clearly_defined.app.mjs @@ -1,11 +1,94 @@ +import { axios } from "@pipedream/platform"; +import constants from "./common/constants.mjs"; + export default { type: "app", app: "clearly_defined", - propDefinitions: {}, + propDefinitions: { + type: { + type: "string", + label: "Type", + description: "The type of component", + options: constants.COMPONENT_TYPES, + }, + provider: { + type: "string", + label: "Provider", + description: "Where the component can be found", + options: constants.COMPONENT_PROVIDERS, + }, + namespace: { + type: "string", + label: "Namespace", + description: "Many component systems have namespaces. GitHub orgs, NPM namespace, Maven group id, Conda Subdir/Architecture. If your component does not have a namespace, use '-' (ASCII hyphen).", + }, + name: { + type: "string", + label: "Name", + description: "The name of the component you want", + }, + revision: { + type: "string", + label: "Revision", + description: "Components typically have some differentiator like a version or commit id. Use that here. If this segment is omitted, the latest revision is used (if that makes sense for the provider).", + optional: true, + }, + sort: { + type: "string", + label: "Sort", + description: "The field to sort the results by", + options: constants.SORT_FIELDS, + optional: true, + }, + sortDirection: { + type: "string", + label: "Sort Direction", + description: "The direction to sort the results by", + options: constants.SORT_DIRECTIONS, + optional: true, + }, + form: { + type: "string", + label: "Form", + description: "Form of the response", + options: constants.RESPONSE_FORMS, + optional: true, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return `https://${this.$auth.environment}.clearlydefined.io`; + }, + _makeRequest({ + $ = this, + path, + ...opts + }) { + return axios($, { + url: `${this._baseUrl()}${path}`, + ...opts, + }); + }, + getDefinitions(opts = {}) { + return this._makeRequest({ + path: "/definitions", + ...opts, + }); + }, + getHarvests({ + type, provider, namespace, name, revision, ...opts + }) { + return this._makeRequest({ + path: `/harvest/${type}/${provider}/${namespace}/${name}/${revision}`, + ...opts, + }); + }, + createDefinition(opts = {}) { + return this._makeRequest({ + method: "POST", + path: "/definitions", + ...opts, + }); }, }, -}; \ No newline at end of file +}; diff --git a/components/clearly_defined/common/constants.mjs b/components/clearly_defined/common/constants.mjs new file mode 100644 index 0000000000000..aaea9be6da0fa --- /dev/null +++ b/components/clearly_defined/common/constants.mjs @@ -0,0 +1,82 @@ +const COMPONENT_TYPES = [ + "composer", + "conda", + "condasrc", + "crate", + "deb", + "debsrc", + "gem", + "git", + "go", + "maven", + "npm", + "nuget", + "pod", + "pypi", + "sourcearchive", +]; + +const COMPONENT_PROVIDERS = [ + "anaconda-main", + "anaconda-r", + "cocoapods", + "conda-forge", + "cratesio", + "debian", + "github", + "gitlab", + "mavencentral", + "mavengoogle", + "gradleplugin", + "npmjs", + "nuget", + "packagist", + "pypi", + "rubygems", +]; + +const SORT_FIELDS = [ + "type", + "provider", + "namespace", + "name", + "revision", + "license", + "releaseDate", + "licensedScore", + "describedScore", + "effectiveScore", + "toolScore", +]; + +const SORT_DIRECTIONS = [ + "ascending", + "descending", +]; + +const RESPONSE_FORMS = [ + { + label: "summarize harvested file", + value: "summary", + }, + { + label: "raw content of the harvested file", + value: "raw", + }, + { + label: "streamed content of the harvested file", + value: "streamed", + }, + { + label: "List of matching harvested files", + value: "list", + }, +]; + +export default { + COMPONENT_TYPES, + COMPONENT_PROVIDERS, + SORT_FIELDS, + SORT_DIRECTIONS, + RESPONSE_FORMS, +}; diff --git a/components/clearly_defined/package.json b/components/clearly_defined/package.json index a08648ded33dd..bb3d3a6e8c609 100644 --- a/components/clearly_defined/package.json +++ b/components/clearly_defined/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/clearly_defined", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream Clearly Defined Components", "main": "clearly_defined.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.3" } -} \ No newline at end of file +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3f5858a965ed2..d05fb015abd4a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -292,8 +292,7 @@ importers: specifier: ^3.0.1 version: 3.0.3 - components/adobe_document_generation_api: - specifiers: {} + components/adobe_document_generation_api: {} components/adobe_pdf_services: dependencies: @@ -1893,7 +1892,11 @@ importers: specifier: ^0.10.0 version: 0.10.0 - components/clearly_defined: {} + components/clearly_defined: + dependencies: + '@pipedream/platform': + specifier: ^3.0.3 + version: 3.0.3 components/clearout: dependencies: @@ -10501,8 +10504,7 @@ importers: components/syncro: {} - components/synthflow: - specifiers: {} + components/synthflow: {} components/t2m_url_shortener: {} @@ -31754,6 +31756,8 @@ snapshots: '@putout/operator-filesystem': 5.0.0(putout@36.13.1(eslint@8.57.1)(typescript@5.6.3)) '@putout/operator-json': 2.2.0 putout: 36.13.1(eslint@8.57.1)(typescript@5.6.3) + transitivePeerDependencies: + - supports-color '@putout/operator-regexp@1.0.0(putout@36.13.1(eslint@8.57.1)(typescript@5.6.3))': dependencies: