Socket
Socket
Sign inDemoInstall

@temporalio/client

Package Overview
Dependencies
Maintainers
4
Versions
79
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@temporalio/client - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

57

lib/index.d.ts

@@ -11,3 +11,4 @@ /**

*/
import * as grpc from 'grpc';
/// <reference types="node" />
import * as grpc from '@grpc/grpc-js';
import * as iface from '@temporalio/proto';

@@ -23,2 +24,23 @@ import { Workflow, WorkflowSignalType, WorkflowQueryType } from '@temporalio/workflow/lib/interfaces';

declare type AsyncOnly<F extends (...args: any[]) => any> = (...args: Parameters<F>) => EnsurePromise<ReturnType<F>>;
/** TLS configuration options. */
export interface TLSConfig {
/**
* Overrides the target name used for SSL host name checking.
* If this attribute is not specified, the name used for SSL host name checking will be the host from {@link ServerOptions.url}.
* This _should_ be used for testing only.
*/
serverNameOverride?: string;
/**
* Root CA certificate used by the server. If not set, and the server's
* cert is issued by someone the operating system trusts, verification will still work (ex: Cloud offering).
*/
serverRootCACertificate?: Buffer;
/** Sets the client certificate and key for connecting with mTLS */
clientCertPair?: {
/** The certificate for this client */
crt: Buffer;
/** The private key for this client */
key: Buffer;
};
}
/**

@@ -126,15 +148,22 @@ * Transforms a workflow interface `T` into a client interface

/**
* Server address and port
* Server hostname and optional port.
* Port defaults to 7233 if address contains only host.
*
* @default localhost:7233
*/
address?: string;
/**
* Channel credentials, create using the factory methods defined {@link https://grpc.github.io/grpc/node/grpc.credentials.html | here}
* TLS configuration.
* Pass a falsy value to use a non-encrypted connection or `true` or `{}` to
* connect with TLS without any customization.
*
* Either {@link credentials} or this may be specified for configuring TLS
*/
credentials?: grpc.ChannelCredentials;
tls?: TLSConfig | boolean | null;
/**
* Namespace to use in {@link Connection} methods
* Channel credentials, create using the factory methods defined {@link https://grpc.github.io/grpc/node/grpc.credentials.html | here}
*
* @default default
* Either {@link tls} or this may be specified for configuring TLS
*/
namespace?: string;
credentials?: grpc.ChannelCredentials;
/**

@@ -157,6 +186,12 @@ * Identity to report to the server

}
export declare type ConnectionOptionsWithDefaults = Required<ConnectionOptions>;
export declare type ConnectionOptionsWithDefaults = Required<Omit<ConnectionOptions, 'tls'>>;
export declare function defaultConnectionOpts(): ConnectionOptionsWithDefaults;
export interface BaseWorkflowOptions {
/**
* Workflow namespace
*
* @default default
*/
namespace?: string;
/**
* Workflow id to use when starting. If not specified a UUID is generated. Note that it is

@@ -230,3 +265,3 @@ * dangerous as in case of client side retries no deduplication will happen based on the

export declare type WorkflowOptions = BaseWorkflowOptions & WorkflowDurationOptions;
export declare type RequiredWorkflowOptions = Required<Pick<BaseWorkflowOptions, 'workflowId' | 'workflowIdReusePolicy' | 'taskQueue'>>;
export declare type RequiredWorkflowOptions = Required<Pick<BaseWorkflowOptions, 'workflowId' | 'workflowIdReusePolicy' | 'taskQueue' | 'namespace'>>;
export declare type WorkflowOptionsWithDefaults = WorkflowOptions & RequiredWorkflowOptions;

@@ -247,3 +282,3 @@ export declare type CompiledWorkflowOptionsWithDefaults = BaseWorkflowOptions & RequiredWorkflowOptions & {

export declare class Connection {
static readonly Client: typeof grpc.Client;
static readonly Client: import("@grpc/grpc-js/build/src/make-client").ServiceClientConstructor;
readonly options: ConnectionOptionsWithDefaults;

@@ -262,3 +297,3 @@ readonly client: grpc.Client;

startWorkflowExecution(opts: CompiledWorkflowOptionsWithDefaults, name: string, ...args: any[]): Promise<string>;
untilComplete(workflowId: string, runId: string): Promise<unknown>;
untilComplete(workflowId: string, runId: string, namespace?: string): Promise<unknown>;
workflow<T extends Workflow>(name: string, options: WorkflowOptions): WorkflowClient<T>;

@@ -265,0 +300,0 @@ }

69

lib/index.js

@@ -37,3 +37,3 @@ "use strict";

const os_1 = __importDefault(require("os"));
const grpc = __importStar(require("grpc"));
const grpc = __importStar(require("@grpc/grpc-js"));
const uuid_1 = require("uuid");

@@ -52,3 +52,2 @@ const ms_1 = __importDefault(require("ms"));

credentials: grpc.credentials.createInsecure(),
namespace: 'default',
dataConverter: data_converter_1.defaultDataConverter,

@@ -67,2 +66,3 @@ // ManagementFactory.getRuntimeMXBean().getName()

workflowId: uuid_1.v4(),
namespace: 'default',
workflowIdReusePolicy: iface.temporal.api.enums.v1.WorkflowIdReusePolicy.WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE_FAILED_ONLY,

@@ -83,2 +83,40 @@ ...opts,

/**
* Normalize {@link ConnectionOptions.tls} by turning false and null to undefined and true to and empty object
* NOTE: this function is duplicated in `packages/worker/src/worker.ts` for lack of a shared library
*/
function normalizeTlsConfig(tls) {
return typeof tls === 'object' ? (tls === null ? undefined : tls) : tls ? {} : undefined;
}
/**
* - Convert {@link ConnectionOptions.tls} to {@link grpc.ChannelCredentials}
* - Add the grpc.ssl_target_name_override GRPC {@link ConnectionOptions.channelArgs | channel arg}
* - Add default port to address if port not specified
*/
function normalizeGRPCConfig(options) {
const { tls: tlsFromConfig, credentials, ...rest } = options || {};
if (rest.address) {
// eslint-disable-next-line prefer-const
let [host, port] = rest.address.split(':', 2);
port = port || '7233';
rest.address = `${host}:${port}`;
}
const tls = normalizeTlsConfig(tlsFromConfig);
if (tls) {
if (credentials) {
throw new TypeError('Both `tls` and `credentials` ConnectionOptions were provided');
}
return {
...rest,
credentials: grpc.credentials.createSsl(tls.serverRootCACertificate, tls.clientCertPair?.key, tls.clientCertPair?.crt),
channelArgs: {
...rest.channelArgs,
...(tls.serverNameOverride ? { 'grpc.ssl_target_name_override': tls.serverNameOverride } : undefined),
},
};
}
else {
return rest;
}
}
/**
* Client connection to the Temporal Service

@@ -88,3 +126,6 @@ */

constructor(options) {
this.options = { ...defaultConnectionOpts(), ...options };
this.options = {
...defaultConnectionOpts(),
...normalizeGRPCConfig(options),
};
this.client = new Connection.Client(this.options.address, this.options.credentials, this.options.channelArgs);

@@ -106,3 +147,3 @@ const rpcImpl = (method, requestData, callback) => {

async untilReady(waitTimeMs = 5000) {
new Promise((resolve, reject) => {
return new Promise((resolve, reject) => {
this.client.waitForReady(Date.now() + waitTimeMs, (err) => {

@@ -119,5 +160,5 @@ if (err) {

async startWorkflowExecution(opts, name, ...args) {
const { namespace, identity, dataConverter } = this.options;
const { identity, dataConverter } = this.options;
const req = {
namespace,
namespace: opts.namespace,
identity,

@@ -148,5 +189,5 @@ requestId: uuid_1.v4(),

}
async untilComplete(workflowId, runId) {
async untilComplete(workflowId, runId, namespace = 'default') {
const req = {
namespace: this.options.namespace,
namespace,
execution: { workflowId, runId },

@@ -231,3 +272,3 @@ skipArchival: true,

}
return (await this.connection.untilComplete(compiledOptions.workflowId, runId));
return (await this.connection.untilComplete(compiledOptions.workflowId, runId, compiledOptions.namespace));
},

@@ -240,3 +281,3 @@ async terminate(reason) {

return this.connection.service.terminateWorkflowExecution({
namespace: this.connection.options.namespace,
namespace: compiledOptions.namespace,
identity: this.connection.options.identity,

@@ -256,3 +297,3 @@ workflowExecution: {

return this.connection.service.requestCancelWorkflowExecution({
namespace: this.connection.options.namespace,
namespace: compiledOptions.namespace,
identity: this.connection.options.identity,

@@ -272,3 +313,3 @@ requestId: uuid_1.v4(),

return this.connection.service.describeWorkflowExecution({
namespace: this.connection.options.namespace,
namespace: compiledOptions.namespace,
execution: {

@@ -289,3 +330,3 @@ runId: this.runId,

identity: this.options.identity,
namespace: this.options.namespace,
namespace: compiledOptions.namespace,
workflowExecution: { runId: workflow.runId, workflowId: compiledOptions.workflowId },

@@ -308,3 +349,3 @@ requestId: uuid_1.v4(),

// TODO: queryRejectCondition
namespace: this.options.namespace,
namespace: compiledOptions.namespace,
execution: { runId: workflow.runId, workflowId: compiledOptions.workflowId },

@@ -311,0 +352,0 @@ query: { queryType, queryArgs: { payloads: this.options.dataConverter.toPayloads(...args) } },

{
"name": "@temporalio/client",
"version": "0.2.0",
"version": "0.3.0",
"description": "Temporal.io SDK Client sub-package",

@@ -16,5 +16,5 @@ "main": "lib/index.js",

"dependencies": {
"@temporalio/proto": "^0.2.0",
"@temporalio/workflow": "^0.2.0",
"grpc": "^1.24.9",
"@grpc/grpc-js": "^1.3.1",
"@temporalio/proto": "^0.2.1",
"@temporalio/workflow": "^0.2.1",
"ms": "^2.1.3",

@@ -34,3 +34,3 @@ "protobufjs": "^6.10.2",

},
"gitHead": "5489bd5bac5ba5c2142c0bb5a081d0eeb90fa53e"
"gitHead": "59160b0eed13c8ae2e6b68e1494424884ba5b705"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc