js-sdk icon indicating copy to clipboard operation
js-sdk copied to clipboard

Warn on usage of older versions of the SDK

Open shubham1172 opened this issue 3 years ago • 5 comments

Describe the proposal

This is a derived issue from #260. It is to add a warning during startup if the user is on an older version of the Dapr SDK than the latest one. From #260,

Also add a message to runtime startup to check the latest version and to show when a new one is available (see Prisma for an example) https://registry.npmjs.org/@dapr/dapr

We must also consider the perf cost of a network call during startup.

shubham1172 avatar Jul 05 '22 18:07 shubham1172

This issue has been automatically marked as stale because it has not had activity in the last 60 days. It will be closed in the next 7 days unless it is tagged (pinned, good first issue, help wanted or triaged/resolved) or other activity occurs. Thank you for your contributions.

dapr-bot avatar Sep 04 '22 15:09 dapr-bot

@shubham1172 for these we have to compare SDK_VERSION from version .ts and current version from npm registry . to compare version we can use https://www.npmjs.com/package/semver . if you give some more idea i can do this @shubham1172

salmankhan-prs avatar Oct 15 '22 07:10 salmankhan-prs

@salmankhan-prs yes, sounds like a plan.

shubham1172 avatar Oct 15 '22 07:10 shubham1172

@shubham1172 The function to fetch current version from npm registry where i have write in DaprClient.ts ??

salmankhan-prs avatar Oct 15 '22 07:10 salmankhan-prs

@shubham1172 The function to fetch current version from npm registry where i have write in DaprClient.ts ??

When we move to multiple packages in v3.0.0, each package should contain it separately. For now, we can add it to DaprClient, similar to the dapr-client NPM package check IMO. The actual fetching of the version can be a utility in src/utils/Version.util.ts.

@XavierGeerinck WDYT?

shubham1172 avatar Oct 15 '22 07:10 shubham1172

@shubham1172 in DaprClient.ts should i need to create a new function .since i making network call to get the current version I am using await somethings like this const latestVersion=await getLatestVersionFromNpmRegistry()

salmankhan-prs avatar Nov 06 '22 09:11 salmankhan-prs

You can keep the logic under src/utils/Version.util.ts @salmankhan-prs

shubham1172 avatar Nov 07 '22 05:11 shubham1172

Hello, @shubham1172. Please review the version.utils.ts file I created below. Also, where should I call this function from?

import fetch from "node-fetch";
import { SDK_VERSION } from "../version";
import semver from 'semver'
import { Logger } from "../logger/Logger";

export const getLatestVersionFromNpmRegistry = async () => {
  const logger = new Logger("DaprClient", "DaprClient", {});

  const result = await fetch("https://registry.npmjs.org/@dapr/dapr");
  const response = await (result.json());
 const latestVersion= response["dist-tags"]["latest"];
  if (semver.lt(String(SDK_VERSION), latestVersion)   ) {
    logger.warn(
      `The ${latestVersion} version is available run npm  update @dapr/dapr `,
    );
   
  }
 
};

salmankhan-prs avatar Nov 10 '22 04:11 salmankhan-prs

@shubham1172 where should I call the above function ?

salmankhan-prs avatar Nov 11 '22 11:11 salmankhan-prs

@salmankhan-prs see this, similar to the same check https://github.com/dapr/js-sdk/blob/f9571d5b34f5b1f41a06ba9b9b4da0c2c0f3fb36/src/implementation/Client/DaprClient.ts#L102-L106

shubham1172 avatar Nov 11 '22 11:11 shubham1172

@salmankhan-prs see this, similar to the same check

https://github.com/dapr/js-sdk/blob/f9571d5b34f5b1f41a06ba9b9b4da0c2c0f3fb36/src/implementation/Client/DaprClient.ts#L102-L106

yes @shubham1172 we are doing this inside constructor .I think we cannot call async function in the constructor

salmankhan-prs avatar Nov 11 '22 11:11 salmankhan-prs

@salmankhan-prs see this, similar to the same check https://github.com/dapr/js-sdk/blob/f9571d5b34f5b1f41a06ba9b9b4da0c2c0f3fb36/src/implementation/Client/DaprClient.ts#L102-L106

yes @shubham1172 we are doing this inside constructor .I think we cannot call async function in the constructor .please correct me if i am wrong

salmankhan-prs avatar Nov 11 '22 11:11 salmankhan-prs

After some more discussion, closing this issue as won't fix. The problem is that app environments might not always have internet access (airgap), or slow internet, and this functionality might cause more issues than good. Users should rather depend on npm to keep their dependencies up to date.

shubham1172 avatar Nov 15 '22 17:11 shubham1172