@temporalio/client
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -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 @@ } |
@@ -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" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
32556
667
+ Added@grpc/grpc-js@^1.3.1
+ Added@grpc/grpc-js@1.11.2(transitive)
+ Added@grpc/proto-loader@0.7.13(transitive)
+ Added@js-sdsl/ordered-map@4.4.2(transitive)
+ Addedansi-styles@4.3.0(transitive)
+ Addedcliui@8.0.1(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addedescalade@3.2.0(transitive)
+ Addedget-caller-file@2.0.5(transitive)
+ Addedlong@5.2.3(transitive)
+ Addedprotobufjs@7.4.0(transitive)
+ Addedrequire-directory@2.1.1(transitive)
+ Addedwrap-ansi@7.0.0(transitive)
+ Addedy18n@5.0.8(transitive)
+ Addedyargs@17.7.2(transitive)
+ Addedyargs-parser@21.1.1(transitive)
- Removedgrpc@^1.24.9
- Removed@mapbox/node-pre-gyp@1.0.11(transitive)
- Removed@types/bytebuffer@5.0.49(transitive)
- Removed@types/long@3.0.32(transitive)
- Removedabbrev@1.1.1(transitive)
- Removedagent-base@6.0.2(transitive)
- Removedansi-regex@2.1.1(transitive)
- Removedaproba@2.0.0(transitive)
- Removedare-we-there-yet@2.0.0(transitive)
- Removedascli@1.0.1(transitive)
- Removedbytebuffer@5.0.1(transitive)
- Removedcamelcase@2.1.1(transitive)
- Removedchownr@2.0.0(transitive)
- Removedcliui@3.2.0(transitive)
- Removedcode-point-at@1.1.0(transitive)
- Removedcolor-support@1.1.3(transitive)
- Removedcolour@0.7.1(transitive)
- Removedconsole-control-strings@1.1.0(transitive)
- Removeddebug@4.3.7(transitive)
- Removeddecamelize@1.2.0(transitive)
- Removeddelegates@1.0.0(transitive)
- Removeddetect-libc@2.0.3(transitive)
- Removedfs-minipass@2.1.0(transitive)
- Removedgauge@3.0.2(transitive)
- Removedgrpc@1.24.11(transitive)
- Removedhas-unicode@2.0.1(transitive)
- Removedhttps-proxy-agent@5.0.1(transitive)
- Removedinvert-kv@1.0.0(transitive)
- Removedis-fullwidth-code-point@1.0.0(transitive)
- Removedlcid@1.0.0(transitive)
- Removedlodash.clone@4.5.0(transitive)
- Removedlong@3.2.0(transitive)
- Removedmake-dir@3.1.0(transitive)
- Removedminipass@3.3.65.0.0(transitive)
- Removedminizlib@2.1.2(transitive)
- Removedmkdirp@1.0.4(transitive)
- Removednan@2.20.0(transitive)
- Removednode-fetch@2.7.0(transitive)
- Removednopt@5.0.0(transitive)
- Removednpmlog@5.0.1(transitive)
- Removednumber-is-nan@1.0.1(transitive)
- Removedobject-assign@4.1.1(transitive)
- Removedoptjs@3.2.2(transitive)
- Removedos-locale@1.4.0(transitive)
- Removedprotobufjs@5.0.3(transitive)
- Removedreadable-stream@3.6.2(transitive)
- Removedrimraf@3.0.2(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedsemver@6.3.17.6.3(transitive)
- Removedset-blocking@2.0.0(transitive)
- Removedsignal-exit@3.0.7(transitive)
- Removedstring-width@1.0.2(transitive)
- Removedstring_decoder@1.3.0(transitive)
- Removedstrip-ansi@3.0.1(transitive)
- Removedtar@6.2.1(transitive)
- Removedtr46@0.0.3(transitive)
- Removedutil-deprecate@1.0.2(transitive)
- Removedwebidl-conversions@3.0.1(transitive)
- Removedwhatwg-url@5.0.0(transitive)
- Removedwide-align@1.1.5(transitive)
- Removedwindow-size@0.1.4(transitive)
- Removedwrap-ansi@2.1.0(transitive)
- Removedy18n@3.2.2(transitive)
- Removedyallist@4.0.0(transitive)
- Removedyargs@3.32.0(transitive)
Updated@temporalio/proto@^0.2.1
Updated@temporalio/workflow@^0.2.1