Repository: apify/apify-cli (ts)

Issue:
Use IS_APIFY_AT_HOME env var to check is actor runs locally
https://github.com/apify/apify-cli/blob/0cb0de4794ce2d78b84237d9612f88d9e4c6f2fa/src/lib/actor.js#L47

We should probably use IS_AT_HOME to check if we're running on Apify. When you run locally and you don't set the local storage env var, the above error shows. `apify run` sets this automatically, so it was a bit of a surprise, but we should still figure out a better way of managing this local/remote environment. The env vars are super confusing even for long time SDK users.

_Originally posted by @mnmkng in https://github.com/apify/apify-cli/issues/265#issuecomment-1080743802_
`actor:push-data` doesn't work in the Apify Platform
I found out the `apify actor:push-data` command works locally, but doesn't work when I `apify push` it to the platform and then I `apify run` iit. I tried my best to replicate the remote environment locally by exporting the same environment variables I logged in the Actor Run in the platform - and it fails even locally.

I also found the problem is that the CLI never picks the `ActorStorage`, but always uses the `MemoryStorage` because [this](https://github.com/apify/apify-cli/blob/8f7b1fd84c4070a11b0af26b64c6a5002f7a7218/src/lib/actor.ts#L30) condition is always true. I overrode it by setting the `forceCloud` variable to true and it works as expected

What would be the best course of action here? Would you accept a PR for something along the lines of `forceCloud = Boolean(Number(process.env.APIFY_IS_AT_HOME))`

My example is as simple as [this](https://github.com/netmilk/actor-curl/blob/main/bin/start.sh#L6): `curl http://httpbin.org/ip | apify actor:push-data` and it fails with the following error message in the Apify Platform Run:
```
2024-04-18T14:24:08.937Z Error: Dataset with id: GpWJMhs1EcaSl0bDo does not exist.
2024-04-18T14:24:08.940Z     at DatasetClient.throwOnNonExisting (/usr/local/lib/node_modules/apify-cli/node_modules/@crawlee/memory-storage/resource-clients/common/base-client.js:15:15)
2024-04-18T14:24:08.942Z     at DatasetClient.pushItems (/usr/local/lib/node_modules/apify-cli/node_modules/@crawlee/memory-storage/resource-clients/dataset.js:158:18)
2024-04-18T14:24:08.944Z     at async PushDataCommand.run (/usr/local/lib/node_modules/apify-cli/src/commands/actor/push-data.js:25:9)
2024-04-18T14:24:08.946Z     at async PushDataCommand._run (/usr/local/lib/node_modules/apify-cli/node_modules/@oclif/command/lib/command.js:43:20)
2024-04-18T14:24:08.948Z     at async Config.runCommand (/usr/local/lib/node_modules/apify-cli/node_modules/@oclif/config/lib/config.js:173:24)
2024-04-18T14:24:08.950Z     at async Main.run (/usr/local/lib/node_modules/apify-cli/node_modules/@oclif/command/lib/main.js:28:9)
2024-04-18T14:24:08.952Z     at async Main._run (/usr/local/lib/node_modules/apify-cli/node_modules/@oclif/command/lib/command.js:43:20)
2024-04-18T14:24:08.954Z     at async /usr/local/lib/node_modules/apify-cli/src/bin/run:7:9
```

--- 
for the record, I'm following up on my question on [Discord](https://discord.com/channels/801163717915574323/1230526751512203309/1231987821447745536)

Pull request description:
fix: always try to get a remote storage if IS_AT_HOME is true
But maybe we should allow users to force it to get local storages too?

Fix tested and adjusted from @netmilk's fork. it does work :pog:

Closes #270 
Closes #553 

Patch:
diff --git a/src/lib/actor.ts b/src/lib/actor.ts
index 047407f..1c37b56 100644
--- a/src/lib/actor.ts
+++ b/src/lib/actor.ts
@@ -23,7 +23,7 @@ export const APIFY_STORAGE_TYPES = {
  */
 export const getApifyStorageClient = async (
     options: MemoryStorageOptions | ApifyClientOptions = {},
-    forceCloud = false,
+    forceCloud = Reflect.has(process.env, APIFY_ENV_VARS.IS_AT_HOME),
 ): Promise<StorageClient> => {
     const storageDir = getLocalStorageDir();
 


Test patch:
diff --git a/test/lib/actor.test.ts b/test/lib/actor.test.ts
new file mode 100644
index 0000000..08fd893
--- /dev/null
+++ b/test/lib/actor.test.ts
@@ -0,0 +1,19 @@
+import { APIFY_ENV_VARS } from '@apify/consts';
+import { ApifyClient } from 'apify-client';
+
+import { getApifyStorageClient } from '../../src/lib/actor.js';
+
+beforeAll(() => {
+    vitest.stubEnv(APIFY_ENV_VARS.IS_AT_HOME, 'true');
+    vitest.stubEnv(APIFY_ENV_VARS.TOKEN, 'token for sure');
+});
+
+afterAll(() => {
+    vitest.unstubAllEnvs();
+});
+
+describe('getApifyStorageClient should return a cloud instance when APIFY_IS_AT_HOME is set', () => {
+    it('should return a cloud instance', async () => {
+        await expect(getApifyStorageClient()).resolves.toBeInstanceOf(ApifyClient);
+    });
+});