The ohpm client interacts with the ohpm-repo through REST APIs. Currently, there are six types of APIs:
When the ohpm client accesses ohpm-repo, two authentication modes are supported: public and private key and access token.
Returns the metadata of a specified package.
GET <router-prefix>/:group?/:package_name
Attribute | Type | Mandatory | Description |
|---|---|---|---|
group | string | No | Organization name, which starts with @, for example, @ohos. |
package_name | string | Yes | Package name (excluding the organization part). |
Request example (for example, requesting an in-app HAR package @test/package1):
curl "http://myohpmrepo.com/ohpm/@test/package1"
Successful response example (for example, requesting the in-app HAR package @test/package1):
{
"_id": "@test/package1",
"name": "@test/package1",
"description": "Please describe the basic information.",
"dist-tags": {
"latest": "2.0.0"
},
"versions": {
"1.0.0": {
"name": "@test/package1",
"version": "1.0.0",
"description": "Please describe the basic information.",
"main": "Index.ets",
"author": {
"name": "apple11",
"url": "",
"email": ""
},
"license": "Apache-2.0",
"dependencies": {
},
"artifactType": "original",
"_nodeVersion": "20.14.0",
"_ohpmVersion": "ohpm-repo-5.0.3-rc.2",
"_id": "@test/package1@1.0.0",
"dist": {
"integrity": "sha512-UAPn6H3lsqQvwmevJSbWWv52PA8Ii6rgutLeJnVAHkNrUX2isytQ2pkzjodHuroYb64XKcwg+E6I8tUcFxwF3A==",
"tarball": "https://10.70.95.74:8077/ohpm/@test/package1/-/@test/package1-1.0.0.har"
}
},
"2.0.0": {
"name": "@test/package1",
"version": "2.0.0",
"description": "Please describe the basic information.",
"main": "Index.ets",
"author": {
"name": "apple11",
"url": "",
"email": ""
},
"license": "Apache-2.0",
"dependencies": {
},
"artifactType": "original",
"_nodeVersion": "20.14.0",
"_ohpmVersion": "ohpm-repo-5.0.3-rc.2",
"_id": "@test/package1@2.0.0",
"dist": {
"integrity": "sha512-6C47XiyVfUAljbS2d08LWEJE2dZHPFi6SNYEsR0REQVKUwlNKf6hNI8wKaI0dHCmDPhQPymOdGeTF+2E3fZWgQ==",
"tarball": "https://10.70.95.74:8077/ohpm/@test/package1/-/@test/package1-2.0.0.har"
}
}
},
"_rev": "2",
"time": {
"1.0.0": "2024-06-26T14:48:17.302+08:00",
"created": "2024-06-26T14:48:17.302+08:00",
"modified": "2024-06-26T14:48:27.785+08:00",
"2.0.0": "2024-06-26T14:48:27.785+08:00"
}
} The response data contains eight first-level fields, which are described as follows:
Attribute | Type | Mandatory | Description |
|---|---|---|---|
_id | string | Yes | Package name, which is used as the primary key ID of the database. |
_rev | number | Yes | Package versions. |
name | string | Yes | Package name. |
description | string | Yes | Package description. |
dist-tags | json | Yes | All tags of the package. |
versions | json | Yes | All version data of the package. |
packageType | string | No | Package type. For details, see the description. |
time | json | Yes | Package release time. |
The versions fields in the first-level fields contain all version data of the package. There are 17 fields, which are described as follows:
Attribute | Type | Mandatory | Description |
|---|---|---|---|
_id | string | Yes | Package name@Package version, for example, @myscope/myhsplib@1.0.0. |
_nodeVersion | string | Yes | Node.js version for publishing. |
_ohpmVersion | string | Yes | Version of the ohpm client for publishing. |
name | string | Yes | Package name. |
version | string | Yes | Package version. |
description | string | Yes | Package description. |
author | json | Yes | Package author information. |
repository | string | No | Source code repository address of the package. |
license | string | No | Project open-source license of the package. For details, see the description below. |
packageType | string | No | Package type. For details, see the description. |
dependencies | json | No | Package runtime dependency. |
devDependencies | json | No | Package development dependency. |
dynamicDependencies | json | No | Package dynamic dependency (only for HSP packages). |
types | string | Yes (conditionally) | Package type declaration file. |
main | string | Yes (conditionally) | Entry file of the package. |
dist | json | Yes | SSRI value and download address of the maintenance package. For details, see the description. |
hspType | string | Yes (conditionally) | HSP Package type. For details, see the description. |
Log in to the client and obtain the token required for uploading packages, removing packages, and editing tags.
POST <router-prefix>/login
Request example:
curl --request POST
--header "command: login"
--header "version: v1"
--header "Content-Type: application/json"
--data @./path/to/login-body/file.json \
"http://myohpmrepo.com/repos/ohpm/login" Request body of request example (@./path/to/login-body/file.json):
{
"publishId": "95115BAFDE",
"timestamp": 1702088629606,
"nonce": "e3b3d53f91d0488f9838c86e306ca9f5",
"signature": "qXYUnUK8Quy95a...",
"version": "v1"
} The request body contains the following five fields:
Attribute | Type | Mandatory | Description |
|---|---|---|---|
version | string | Yes | Protocol Version. |
publishId | string | Yes | Publish code. |
timestamp | number | Yes | Publish timestamp. |
nonce | string | Yes | Random number. |
signature | string | Yes | Signature value. For details, see the description. |
1. publishId: publish code generated by ohpm-repo. The publish code is bound to a user. The publish code of each user is unique and is configured by publish_id in the .ohpmrc file on the client.
2. timestamp: timestamp, in milliseconds.
3. nonce: uuidv4 random number that is dynamically generated when the client logs in.
4. signature: when a user logs in to the client, the signature is generated by combining the protocol version, publish code, publish timestamp, and random number are in the v{version}-{publishId}-{timestamp}-{nonce} format using a private key and the RSA-SHA-256 algorithm.
Successful response example:
{
"success": true,
"token": "7100c3f38dddf3cf8234...."
}
token: authentication information generated by ohpm-repo when public and private key authentication is used. You can upload and remove packages and edit tags only after the authentication information is checked to be valid.
PUT <router-prefix>/:package_name
Attribute | Type | Mandatory | Description |
|---|---|---|---|
package_name | string | Yes | Package name. |
If the package name contains an organization name, the value of package_name is the URL-encoded package name. For example, if the package name is @myscope/mypkg, the value of package_name is @myscope%2fmypkg.
Request example (for example, uploading an in-app HSP package @myscope/myhsppkg):
curl --request PUT
--header "command: publish"
--header "version: v1"
--header "Content-Type: application/json"
--data @./path/to/metadata/file.json
--header "Authorization: <token>" \
"http://myohpmrepo.com/repos/ohpm/@myscope%2fmypkg" In the request example, the metadata file (@./path/to/metadata/file.json) is generated by the ohpm client as follows:
{
"_id": "@myscop/myhsppkg",
"name": "@myscop/myhsppkg",
"packageType": "InterfaceHar",
"description": "Please describe the basic information.",
"dist-tags": {
"latest": "1.0.4"
},
"versions": {
"1.0.4": {
"name": "@myscope/myhsppkg",
"version": "1.0.4",
"description": "Please describe the basic information.",
"author": {
"name": "fsq",
"url": "",
"email": ""
},
"license": "Apache-2.0",
"packageType": "InterfaceHar",
"dependencies": {
"pkga": "1.0.0",
"pkgb": "1.0.0"
},
"types": "Index.d.ets",
"_nodeVersion": "16.20.1",
"_ohpmVersion": "1.4.0",
"_id": "@myscope/myhsppkg@1.0.4",
"dist": {
"integrity": "sha512-0bHCBS2JtlyX7Gq5q6tbO2eRRbj0RO2cAAagC/K6/zmDZHPGrnIScDkD3Yjip8I/YWq7VbY7HYlHXtcLApILVg==",
"tarball": "https://localhost:8081/repos/ohpm/@myscope/myhsppkg/-/@myscope/myhsppkg-1.0.4.har",
"integrity_hsp": "sha512-3B7KlJFEHuQ9X+Zxl+oRVIL8CCczaPu2nEGQvXrULrViXuY80Ld2CnkQEVFfd/eZK6DNAFTS1wBhqOTLYtOqow=="
}
}
},
"_attachments": {
"@test/ohpmhsplib-1.0.4.har": {
"content_type": "application/octet-stream",
"data": "H4sIAAAAAAAACu1ZUU...",
"length": 858
},
"@test/ohpmhsplib-1.0.4.hsp": {
"content_type": "application/octet-stream",
"data": "UEsDBAoAAAgAAAAAIU5v...",
"length": 29185
}
},
"hspType": "bundle_app"
}
Successful response example:
Status code: status=200
Status description: statusText='success'
Response body:
{
"code": 200,
"message": "success",
"additionalMsg: ""
} Failed response example:
Status code: status=500
Status description: statusText='error message'
Response body:
{
"code": 500,
"message": "message",
"error": "error message",
"additionalMsg: ""
}
1. When the publish fails, the ohpm client obtains the value of the error field or statusText field in the response body based on the status code and prints the message.
2. additionalMsg: If the response body contains this field and the field is not empty, the ohpm client prints the value of this field after the package is successfully released.
The ohpm client 5.0.1 and later supports streaming upload. When the size of the uploaded third-party package exceeds the threshold (5 MB by default), ohpm preferentially calls the streaming upload interface to upload the package.
POST <router-prefix>/:package_name
Attribute | Type | Mandatory | Description |
|---|---|---|---|
package_name | string | Yes | Package name. |
If the package name contains an organization name, the value of package_name is the URL-encoded package name. For example, if the package name is @myscope/mypkg, the value of package_name is @myscope%2fmypkg.
Request example (for example, uploading an in-app HSP package @myscope/myhsppkg):
curl --request POST
--header "command: publish"
--header "version: v1"
--form "pkg_stream=@hsp.tgz;application/octet-stream"
--form "metadata=@./path/to/metadata/file.json"
--header "Authorization: <token>" \
"http://myohpmrepo.com/repos/ohpm/stream/@myscope%2fmypkg" Content-Type is multipart/form-data. hsp.tgz is the HSP package to be uploaded.
In the request example, the metadata file (@./path/to/metadata/file.json) is generated by the ohpm client as follows:
{
"_id": "@myscop/myhsppkg",
"name": "@myscop/myhsppkg",
"packageType": "InterfaceHar",
"description": "Please describe the basic information.",
"dist-tags": {
"latest": "1.0.4"
},
"versions": {
"1.0.4": {
"name": "@myscope/myhsppkg",
"version": "1.0.4",
"description": "Please describe the basic information.",
"author": {
"name": "fsq",
"url": "",
"email": ""
},
"license": "Apache-2.0",
"packageType": "InterfaceHar",
"dependencies": {
"pkga": "1.0.0",
"pkgb": "1.0.0"
},
"types": "Index.d.ets",
"_nodeVersion": "16.20.1",
"_ohpmVersion": "1.4.0",
"_id": "@myscope/myhsppkg@1.0.4",
"dist": {
"integrity": "sha512-0bHCBS2JtlyX7Gq5q6tbO2eRRbj0RO2cAAagC/K6/zmDZHPGrnIScDkD3Yjip8I/YWq7VbY7HYlHXtcLApILVg==",
"tarball": "https://localhost:8081/repos/ohpm/@myscope/myhsppkg/-/@myscope/myhsppkg-1.0.4.har",
"integrity_hsp": "sha512-3B7KlJFEHuQ9X+Zxl+oRVIL8CCczaPu2nEGQvXrULrViXuY80Ld2CnkQEVFfd/eZK6DNAFTS1wBhqOTLYtOqow=="
}
}
},
"hspType": "bundle_app"
}
Successful response example:
Status code: status=200
Status description: statusText='success'
Response body:
{
"code": 200,
"message": "success",
"additionalMsg: ""
} Failed response example:
Status code: status=500
Status description: statusText='error message'
Response body:
{
"code": 500,
"message": "message",
"error": "error message",
"additionalMsg: ""
}
1. When the publish fails, the ohpm client obtains the value of the error field or statusText field in the response body based on the status code and prints the message.
2. additionalMsg: If the response body contains this field and the field is not empty, the ohpm client prints the value of this field after the package is successfully released.
Removes a HAR/HSP package (a version or the entire package) from ohpm-repo.
DELETE <router-prefix>/:package_name
Attribute | Type | Mandatory | Description |
|---|---|---|---|
package_name | string | Yes | Package name. |
Request example:
curl --request DELETE
--header "command: unpublish"
--header "version: v1"
--header "Authorization: <token>" \
"http://myohpmrepo.com/repos/ohpm/@myscope%2fmyhsppkg@1.0.0" Check the network connectivity with ohpm-repo.
GET <router-prefix>/-/ping
Request example:
curl "http://myohpmrepo.com/repos/ohpm/-/ping"
Successful response example:
{
"code": 200,
"message": "success"
} Adds a tag to the package.
POST <router-prefix>/-/package/:package_name/dist-tags/:tag
Attribute | Type | Mandatory | Description |
|---|---|---|---|
package_name | string | Yes | Package name. |
tag | string | Yes | Tag name. |
If the package name contains an organization name, the value of package_name is the URL-encoded package name. For example, if the package name is @myscope/mypkg, the value of package_name is @myscope%2fmypkg.
Request example (adding the tag test to package @myscope/myhsppkg@1.0.0):
curl --request POST
--header "command: dist-tags"
--header "version: v1"
--header "Content-Type: application/json; charset=UTF-8"
--data "{"version": "1.0.0"}"
--header "Authorization: <token>" \
"http://myohpmrepo.com/repos/ohpm/-/package/@myscope%2fmypkg/dist-tags/test" Changes the version number corresponding to the package tag.
PUT <router-prefix>/-/package/:package_name/dist-tags/:tag
Attribute | Type | Mandatory | Description |
|---|---|---|---|
package_name | string | Yes | Package name. |
tag | string | Yes | Tag name. |
Request example (changing the tag test of package @myscope/myhsppkg to version 2.0.0):
curl --request PUT
--header "command: dist-tags"
--header "version: v1"
--header "Content-Type: application/json; charset=UTF-8"
--data "{"version": "2.0.0"}"
--header "Authorization: <token>" \
"http://myohpmrepo.com/repos/ohpm/-/package/@myscope%2fmypkg/dist-tags/test" Deletes the tag of the package.
DELETE <router-prefix>/-/package/:package_name/dist-tags/:tag
Attribute | Type | Mandatory | Description |
|---|---|---|---|
package_name | string | Yes | Package name. |
tag | string | Yes | Tag name. |
Request example (deleting the tag test of the @myscope/myhsppkg package):
curl --request DELETE
--header "command: dist-tags"
--header "version: v1"
--header "Authorization: <token>" \
"http://myohpmrepo.com/repos/ohpm/-/package/@myscope%2fmypkg/dist-tags/test" Response code | Scope | Description |
|---|---|---|
200 | All interfaces of the repository | Successful. |
400 | All interfaces of the repository | Verification failure of parameter input by client, login failure. |
401 | Authentication failure. | |
404 | Accessing the interface that does not exist in the repository | The interface does not exist. |
500 | All interfaces of the repository | Internal service error. |
598 | When the response status code returned by the repository upload interface is 598, ohpm 5.0.1 or later attempts to upload the file again. |
The streaming upload interface is supported in ohpm 5.0.1 and later versions. When ohpm calls this interface, if the returned response status code is 404, the ohpm client calls the upload interface again to upload data. To ensure compatibility with the ohpm client, ensure that the response status code 404 is returned when an interface that does not exist in the repository is accessed.