Skip to content
Open
111 changes: 110 additions & 1 deletion docs/develop/environment-configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ refer to [Temporal Client Environment Configuration Reference](../references/cli

Environment configuration is in
[Public Preview](../evaluate/development-production-features/release-stages.mdx#public-preview) in the Temporal Go,
Python, Ruby, and .NET SDKs, as well as the Temporal CLI.
Python, Ruby, TypeScript, and .NET SDKs, as well as the Temporal CLI.

:::

Expand Down Expand Up @@ -330,6 +330,59 @@ public static class LoadFromFile
```

</SdkTabs.DotNet>

<SdkTabs.TypeScript>
To load the `default` profile along with any environment variables in TypeScript, use the `loadClientConnectConfig` helper from `@temporalio/envconfig` package.

{/* SNIPSTART typescript-env-config-load-default-profile {"highlightedLines": "17-19,28-29"} */}
[env-config/src/load-from-file.ts](https://github.com/temporalio/samples-typescript/blob/main/env-config/src/load-from-file.ts)

```ts {17-19,28-29}
import { Connection, Client } from '@temporalio/client';
import { loadClientConnectConfig } from '@temporalio/envconfig';
import { resolve } from 'path';

async function main() {
console.log('--- Loading default profile from config.toml ---');

// For this sample to be self-contained, we explicitly provide the path to
// the config.toml file included in this directory.
// By default though, the config.toml file will be loaded from
// ~/.config/temporalio/temporal.toml (or the equivalent standard config directory on your OS).
const configFile = resolve(__dirname, '../config.toml');

// loadClientConnectConfig is a helper that loads a profile and prepares
// the configuration for Connection.connect and Client. By default, it loads the
// "default" profile.
const config = loadClientConnectConfig({
configSource: { path: configFile },
});

console.log(`Loaded 'default' profile from ${configFile}.`);
console.log(` Address: ${config.connectionOptions.address}`);
console.log(` Namespace: ${config.namespace}`);
console.log(` gRPC Metadata: ${JSON.stringify(config.connectionOptions.metadata)}`);

console.log('\nAttempting to connect to client...');
try {
const connection = await Connection.connect(config.connectionOptions);
const client = new Client({ connection, namespace: config.namespace });
console.log('✅ Client connected successfully!');
await connection.close();
} catch (err) {
console.log(`❌ Failed to connect: ${err}`);
}
}

main().catch((err) => {
console.error(err);
process.exit(1);
});
```

{/* SNIPEND */}

</SdkTabs.TypeScript>
</SdkTabs>

## Load configuration from a custom path
Expand Down Expand Up @@ -570,4 +623,60 @@ public static class LoadProfile

</SdkTabs.DotNet>

<SdkTabs.TypeScript>

To load a specific profile from a custom path in TypeScript, use the `loadClientConnectConfig` helper from
`@temporalio/envconfig` package with the `profile` and `configFile` options.

{/* SNIPSTART typescript-env-config-load-default-profile {"highlightedLines": "17-19,28-29"} */}
[env-config/src/load-from-file.ts](https://github.com/temporalio/samples-typescript/blob/main/env-config/src/load-from-file.ts)

```ts {17-19,28-29}
import { Connection, Client } from '@temporalio/client';
import { loadClientConnectConfig } from '@temporalio/envconfig';
import { resolve } from 'path';

async function main() {
console.log('--- Loading default profile from config.toml ---');

// For this sample to be self-contained, we explicitly provide the path to
// the config.toml file included in this directory.
// By default though, the config.toml file will be loaded from
// ~/.config/temporalio/temporal.toml (or the equivalent standard config directory on your OS).
const configFile = resolve(__dirname, '../config.toml');

// loadClientConnectConfig is a helper that loads a profile and prepares
// the configuration for Connection.connect and Client. By default, it loads the
// "default" profile.
const config = loadClientConnectConfig({
configSource: { path: configFile },
});

console.log(`Loaded 'default' profile from ${configFile}.`);
console.log(` Address: ${config.connectionOptions.address}`);
console.log(` Namespace: ${config.namespace}`);
console.log(` gRPC Metadata: ${JSON.stringify(config.connectionOptions.metadata)}`);

console.log('\nAttempting to connect to client...');
try {
const connection = await Connection.connect(config.connectionOptions);
const client = new Client({ connection, namespace: config.namespace });
console.log('✅ Client connected successfully!');
await connection.close();
} catch (err) {
console.log(`❌ Failed to connect: ${err}`);
}
}

main().catch((err) => {
console.error(err);
process.exit(1);
});
```

{/* SNIPEND */}

</SdkTabs.TypeScript>

</SdkTabs>
```
8 changes: 7 additions & 1 deletion docs/develop/typescript/converters-and-encryption.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ const worker = await Worker.create({
[ejson/src/client.ts](https://github.com/temporalio/samples-typescript/blob/main/ejson/src/client.ts)
```ts
const client = new Client({
connection,
dataConverter: { payloadConverterPath: require.resolve('./payload-converter') },
});
```
Expand Down Expand Up @@ -398,13 +399,17 @@ const worker = await Worker.create({
<!--SNIPSTART typescript-protobuf-client -->
[protobufs/src/client.ts](https://github.com/temporalio/samples-typescript/blob/main/protobufs/src/client.ts)
```ts
import { Client } from '@temporalio/client';
import { Client, Connection } from '@temporalio/client';
import { loadClientConnectConfig } from '@temporalio/envconfig';
import { v4 as uuid } from 'uuid';
import { foo, ProtoResult } from '../protos/root';
import { example } from './workflows';

async function run() {
const config = loadClientConnectConfig();
const connection = await Connection.connect(config.connectionOptions);
const client = new Client({
connection,
dataConverter: { payloadConverterPath: require.resolve('./payload-converter') },
});

Expand Down Expand Up @@ -558,6 +563,7 @@ As before, we provide a custom Data Converter to the Client and Worker:
[encryption/src/client.ts](https://github.com/temporalio/samples-typescript/blob/main/encryption/src/client.ts)
```ts
const client = new Client({
connection,
dataConverter: await getDataConverter(),
});

Expand Down
6 changes: 3 additions & 3 deletions docs/develop/typescript/schedules.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ The Temporal Service doesn't guarantee when this removal will happen.
[schedules/src/start-schedule.ts](https://github.com/temporalio/samples-typescript/blob/main/schedules/src/start-schedule.ts)
```ts
async function run() {
const client = new Client({
connection: await Connection.connect(),
});
const config = loadClientConnectConfig();
const connection = await Connection.connect(config.connectionOptions);
const client = new Client({ connection });

// https://typescript.temporal.io/api/classes/client.ScheduleClient#create
const schedule = await client.schedule.create({
Expand Down
Loading