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

feat: support cname #19

Merged
merged 2 commits into from
Jun 25, 2024
Merged

feat: support cname #19

merged 2 commits into from
Jun 25, 2024

Conversation

fengmk2
Copy link
Member

@fengmk2 fengmk2 commented Jun 25, 2024

closes #18

https://help.aliyun.com/zh/oss/user-guide/map-custom-domain-names-5

Summary by CodeRabbit

  • New Features

    • Introduced support for custom domains with a new cname option for OSSObject.
    • Added contributors section with a dynamic image link in the README.
  • Documentation

    • Updated README to include instructions for using a custom domain and modified endpoint values.
  • Chores

    • Updated Node.js version requirement to >= 16.0.0.
    • Updated CI workflow scripts and dependencies.
    • Modified package.json to reflect updated dependencies and scripts.

@fengmk2 fengmk2 added the enhancement New feature or request label Jun 25, 2024
Copy link

coderabbitai bot commented Jun 25, 2024

Walkthrough

This set of changes includes version upgrades for GitHub Actions workflows, updates to the Node.js version requirement, alterations to the OSSObject class to support custom CNAME domains, modifications to the package.json scripts and dependencies, and corresponding updates to the tests and documentation. These changes enhance the project's flexibility, compatibility, and maintainability.

Changes

File/Directory Change Summary
.github/workflows/nodejs.yml Updated actions/checkout, actions/setup-node, and codecov/codecov-action to version v4.
README.md Added custom domain usage instructions, updated endpoint value, and revised contributors section.
package.json Specified Node.js version requirement, updated ci script, and modified dependencies.
src/OSSObject.ts Introduced cname option in the OSSObjectClientInitOptions interface and updated constructor logic.
test/OSSObject.test.ts Added test cases for cname: true scenarios and verified behavior for empty bucket handling.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant OSSObject
    participant Server

    User->>OSSObject: Initialize OSSObject with cname option
    OSSObject->>OSSObject: Check if cname is true
    alt cname is true and bucket is provided
        OSSObject->>OSSObject: Set this.#bucket and this.#bucketEndpoint
    else no bucket is provided
        OSSObject->>OSSObject: Handle error for missing bucket
    end
    User->>OSSObject: Use OSSObject for operations
    OSSObject->>Server: Request with custom domain endpoint
    Server-->>OSSObject: Response
    OSSObject-->>User: Return response
Loading

Assessment against linked issues

Objective (Issue #18) Addressed Explanation
Support for CNAME custom domain handling
Documentation update for custom domain usage
Code updates to include cname option in OSSObject
Test cases for new cname functionality

Poem

Code and bytes, oh what a thrill,
Custom domains, they fit the bill.
Dependencies fresh, version four,
Seamless workflows, just like before.
In tests we trust, oh change divine,
Project updated, simply sublime!


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

socket-security bot commented Jun 25, 2024

New dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@arethetypeswrong/cli@0.15.3 Transitive: environment, filesystem, network, shell, unsafe +46 39.9 MB andrewbranch

View full report↗︎

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Outside diff range and nitpick comments (2)
src/OSSObject.ts (2)

Line range hint 375-376: Avoid using the delete operator.

The use of the delete operator can lead to performance degradation. Consider using undefined assignment instead to clear properties.

- delete options.headers['Content-Type'];
+ options.headers['content-type'] = undefined;

Line range hint 915-917: Optimize header manipulation to avoid performance issues.

Similar to the previous comment, replacing the delete operator with undefined assignment can help maintain performance, especially in critical paths.

- delete options.headers['Content-Type'];
+ options.headers['content-type'] = undefined;
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8ac8953 and 1a6b9a1.

Files selected for processing (5)
  • .github/workflows/nodejs.yml (2 hunks)
  • README.md (3 hunks)
  • package.json (5 hunks)
  • src/OSSObject.ts (2 hunks)
  • test/OSSObject.test.ts (1 hunks)
Files skipped from review due to trivial changes (2)
  • .github/workflows/nodejs.yml
  • test/OSSObject.test.ts
Additional context used
Biome
src/OSSObject.ts

[error] 375-376: Avoid the delete operator which can impact performance. (lint/performance/noDelete)

Unsafe fix: Use an undefined assignment instead.


[error] 915-917: Avoid the delete operator which can impact performance. (lint/performance/noDelete)

Unsafe fix: Use an undefined assignment instead.

LanguageTool
README.md

[uncategorized] ~26-~26: If this is a compound adjective that modifies the following noun, use a hyphen. (EN_COMPOUND_ADJECTIVE_INTERNAL)
Context: ... OSS, Object Storage Service. Equal to well known Amazon S3....


[grammar] ~146-~146: An article may be missing. (BUNCH_OF)
Context: ... aliyun too, you can set true to save lot of money. - [timeout] {String|Number} inst...


[grammar] ~166-~166: There seems to be a noun/verb agreement error. Did you mean “accelerates” or “accelerated”? (SINGULAR_NOUN_VERB_AGREEMENT)
Context: ...ion: 'oss-cn-hangzhou', }); ``` 2. use accelerate endpoint - Global accelerate endpoint:...


[uncategorized] ~401-~401: Possible missing article found. (AI_HYDRA_LEO_MISSING_THE)
Context: ...nd an object to the bucket, it's almost same as put, but it can add content to exist...


[uncategorized] ~401-~401: Possible missing article found. (AI_HYDRA_LEO_MISSING_AN)
Context: ... same as put, but it can add content to existing object rather than override it. All pa...


[uncategorized] ~444-~444: Possible missing preposition found. (AI_HYDRA_LEO_MISSING_OF)
Context: ...e baseUrl, will use baseUrl instead the default bucket and endpoint. Suggest ...


[grammar] ~543-~543: Possible subject-verb agreement error. (IS_AND_ARE)
Context: ... example: - Head an exists object and get object meta info ```js await this.stor...


[grammar] ~709-~709: In standard English, the word ‘exists’ is a verb. Please verify that the determiner ‘an’ is correct, or that a noun is not missing between ‘an’ and ‘exists’. (A_INFINITIVE)
Context: ...lso delete success. example: - Delete an exists object ```js await store.delete('ossde...


[grammar] ~736-~736: It seems that a pronoun is missing. (IF_VB)
Context: ... [sourceBucket] {String} source Bucket. if doesn't exist,sourceBucket is same bu...


[grammar] ~736-~736: Is an article like ‘a’ or ‘an’ missing? (BE_NN)
Context: ...Bucket. if doesn't exist,sourceBucket is same bucket. - [options] {Object} optio...


[grammar] ~798-~798: In standard English, the word ‘exists’ is a verb. Please verify that the determiner ‘an’ is correct, or that a noun is not missing between ‘an’ and ‘exists’. (A_INFINITIVE)
Context: ...## .putMeta(name, meta[, options]) Set an exists object meta. parameters: - name {Stri...


[uncategorized] ~845-~845: The preposition ‘at’ seems more likely in this position. (AI_HYDRA_LEO_REPLACE_IN_AT)
Context: ...Object>} object names, max 1000 objects in once. - key {String} object name - ...


[grammar] ~916-~916: The modal verb ‘will’ requires the verb’s base form. (MD_BASEFORM)
Context: ...meta info list Each ObjectMeta will contains blow properties: - name {String} obje...


[grammar] ~981-~981: The modal verb ‘will’ requires the verb’s base form. (MD_BASEFORM)
Context: ...meta info list Each ObjectMeta will contains blow properties: - name {String} obje...


[grammar] ~1059-~1059: The modal verb ‘will’ requires the verb’s base form. (MD_BASEFORM)
Context: ...meta info list Each ObjectMeta will contains blow properties: - name {String} obje...


[grammar] ~1115-~1115: There is an agreement error between ‘put’ and ‘object’. Insert ‘a(n)’ or change the noun to plural. (PRP_VB_NN)
Context: ...for download or upload object. When you put object with signatureUrl ,you need to pass `Co...


[uncategorized] ~1138-~1138: The abbreviation “e.g.” (= for example) requires two periods. (E_G)
Context: ...ject} set the custom value for callback,eg. {var1: value1,var2:value2} Success wil...


[typographical] ~1195-~1195: Consider adding a comma after ‘Basically’ for more clarity. (RB_LY_COMMA)
Context: ...## .asyncSignatureUrl(name[, options]) Basically the same as signatureUrl, if refreshSTS...


[uncategorized] ~1219-~1219: The abbreviation “e.g.” (= for example) requires two periods. (E_G)
Context: ...ject} set the custom value for callback,eg. {var1: value1,var2:value2} Success wil...


[misspelling] ~1299-~1299: Use “a” instead of ‘an’ if the following word doesn’t start with a vowel sound, e.g. ‘a sentence’, ‘a university’. (EN_A_VS_AN)
Context: ...ssdemo.txt', 'public-read'); - Set an history object's ACL js const versi...


[misspelling] ~1337-~1337: Use “a” instead of ‘an’ if the following word doesn’t start with a vowel sound, e.g. ‘a sentence’, ‘a university’. (EN_A_VS_AN)
Context: ...'); console.log(result.acl); - Get an history object's ACL js const versi...


[misspelling] ~1388-~1388: Use “a” instead of ‘an’ if the following word doesn’t start with a vowel sound, e.g. ‘a sentence’, ‘a university’. (EN_A_VS_AN)
Context: ...sole.log(result.status); - Restore an history object js const versionId =...


[uncategorized] ~1517-~1517: The abbreviation “e.g.” (= for example) requires two periods. (E_G)
Context: ...ng} the object name - tag {Object} tag, eg. {var1: value1,var2:value2} - [options...


[uncategorized] ~1535-~1535: The abbreviation “e.g.” (= for example) requires two periods. (E_G)
Context: ...ng} the object name - tag {Object} tag, eg. {var1: value1,var2:value2} - [options...


[grammar] ~1574-~1574: The modal verb ‘will’ requires the verb’s base form. (MD_BASEFORM)
Context: ...s Each error return by OSS server will contains these properties: - name {String} erro...

Markdownlint
README.md

24-24: null (MD025, single-title, single-h1)
Multiple top-level headings in the same document


184-184: null (MD034, no-bare-urls)
Bare URL used

Additional comments not posted (9)
package.json (4)

4-6: Specify Node.js version requirement.

Adding a Node.js version requirement ensures that the package will only be used with compatible versions of Node.js, which can help avoid runtime issues due to incompatible language features or APIs.


71-76: Update module exports for CommonJS and ESM compatibility.

The updated export paths facilitate the use of this package with both CommonJS and ESM module systems, which enhances its usability and compatibility across different Node.js environments.


82-83: Set main and types entry points.

Defining explicit 'main' and 'types' fields helps ensure that the package's primary entry points are clear, improving its integration with TypeScript and JavaScript projects.


13-13: Modify CI script to include attw --pack.

This change in the CI script to include attw --pack might be intended to perform additional checks or packaging steps before publication. Ensure that attw is properly configured and that its inclusion does not introduce unexpected behaviors during CI builds.

src/OSSObject.ts (3)

67-72: Add optional cname property to OSSObjectClientInitOptions.

This addition supports the new feature for handling custom domain names (CNAMEs), aligning with the PR's objective. The documentation link provided in the comment helps developers understand the context and usage of this property.


80-96: Refactor constructor logic to support cname.

The constructor now conditionally requires a bucket based on the cname setting, which allows flexibility in configuration. The logic to handle bucket naming and endpoint configuration based on cname is clear and well-implemented.


902-905: Validate bucket names dynamically.

The method #getCopySourceName dynamically checks and constructs the bucket name, which is crucial for ensuring the validity of bucket operations. This addition helps prevent errors related to incorrect bucket names.

README.md (2)

178-178: Clarify the use of the global accelerate endpoint.

The explanation about using the global accelerate endpoint could be enhanced by specifying when and why one might want to use this endpoint over others.

+ // Use this endpoint for faster global data transfer speeds.

1637-1639: Updated contributors section with dynamic content.

The change from a static list to a dynamic image link for contributors is a modern approach that keeps the list updated automatically. Ensure that the image link is always accessible to avoid broken images on the README.

@@ -159,7 +159,7 @@ const store = new OSSObject({
accessKeyId: 'your access key',
accessKeySecret: 'your access secret',
bucket: 'your bucket name',
region: 'oss-cn-hangzhou'
region: 'oss-cn-hangzhou',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specify the type of region in the documentation.

The region parameter is used in the initialization of OSSObject, but its type isn't specified in the documentation. This could lead to confusion about what values are expected (string, object, etc.).

-  region: '<oss region>',
+  region: '<oss region>', // Type: string
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
region: 'oss-cn-hangzhou',
region: 'oss-cn-hangzhou', // Type: string

Comment on lines +184 to +194
See https://help.aliyun.com/zh/oss/user-guide/map-custom-domain-names-5

```js
const { OSSObject } = require('oss-client');

const store = new OSSObject({
accessKeyId: 'your access key',
accessKeySecret: 'your access secret',
cname: true,
endpoint: 'your custome domain',
// your custom domain endpoint
endpoint: 'https://my-static.domain.com',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure the cname property is adequately explained.

The cname property is used in the example for custom domains, but there's no explanation of what it does or how it affects the behavior of the OSSObject. This could confuse users unfamiliar with the concept of CNAME in DNS settings.

+ // Set cname to true to use a custom domain name for bucket access.
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
See https://help.aliyun.com/zh/oss/user-guide/map-custom-domain-names-5
```js
const { OSSObject } = require('oss-client');
const store = new OSSObject({
accessKeyId: 'your access key',
accessKeySecret: 'your access secret',
cname: true,
endpoint: 'your custome domain',
// your custom domain endpoint
endpoint: 'https://my-static.domain.com',
See https://help.aliyun.com/zh/oss/user-guide/map-custom-domain-names-5
```js
const { OSSObject } = require('oss-client');
const store = new OSSObject({
accessKeyId: 'your access key',
accessKeySecret: 'your access secret',
cname: true, // Set cname to true to use a custom domain name for bucket access.
// your custom domain endpoint
endpoint: 'https://my-static.domain.com',
Tools
Markdownlint

184-184: null (MD034, no-bare-urls)
Bare URL used

@@ -40,6 +39,7 @@
"xml2js": "^0.6.2"
},
"devDependencies": {
"@arethetypeswrong/cli": "^0.15.3",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip

Codebase Verification

No usage of @arethetypeswrong/cli found in npm scripts.

The dependency @arethetypeswrong/cli is listed in package.json, but it is not referenced in the npm scripts. Please ensure that this tool is integrated into the project's workflow if it is intended to be used.

  • package.json: Dependency listed but not used in scripts.
Analysis chain

Add new dependency @arethetypeswrong/cli.

The addition of @arethetypeswrong/cli to devDependencies suggests improvements in type checking or code quality tools. Confirm that this tool integrates well with existing workflows and that it is used in the scripts where necessary.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the usage of `@arethetypeswrong/cli` in npm scripts.

# Test: Search for usage in npm scripts.
grep -R '@arethetypeswrong/cli' package.json

Length of output: 84



Script:

#!/bin/bash
# Description: Verify the usage of `@arethetypeswrong/cli` in npm scripts.

# Extract and check the scripts section in package.json for any usage of @arethetypeswrong/cli.
jq '.scripts' package.json | grep '@arethetypeswrong/cli'

Length of output: 55

Copy link

codecov bot commented Jun 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.37%. Comparing base (16a4cad) to head (0ceb0d6).
Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #19      +/-   ##
==========================================
+ Coverage   94.32%   94.37%   +0.05%     
==========================================
  Files          17       17              
  Lines        1867     1885      +18     
  Branches      280      285       +5     
==========================================
+ Hits         1761     1779      +18     
  Misses        106      106              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1a6b9a1 and 0ceb0d6.

Files selected for processing (1)
  • .github/workflows/nodejs.yml (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/nodejs.yml

@fengmk2 fengmk2 merged commit 8c64904 into master Jun 25, 2024
8 checks passed
@fengmk2 fengmk2 deleted the support-cname branch June 25, 2024 14:34
fengmk2 pushed a commit that referenced this pull request Jun 25, 2024
[skip ci]

## [2.2.0](v2.1.0...v2.2.0) (2024-06-25)

### Features

* support cname ([#19](#19)) ([8c64904](8c64904))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CNAME 自定义域名似乎不支持
1 participant