All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.dist.src.internal.pubsub-client.js Maven / Gradle / Ivy

The newest version!
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PubsubClient = void 0;
const generated_types_1 = require("@gomomento/generated-types");
var grpcPubsub = generated_types_1.pubsub.cache_client.pubsub;
// older versions of node don't have the global util variables https://github.com/nodejs/node/issues/20365
const headers_interceptor_1 = require("./grpc/headers-interceptor");
const cache_service_error_mapper_1 = require("../errors/cache-service-error-mapper");
const grpc_js_1 = require("@grpc/grpc-js");
const package_json_1 = require("../../package.json");
const middlewares_interceptor_1 = require("./grpc/middlewares-interceptor");
const __1 = require("../");
const utils_1 = require("@gomomento/sdk-core/dist/src/internal/utils");
const AbstractPubsubClient_1 = require("@gomomento/sdk-core/dist/src/internal/clients/pubsub/AbstractPubsubClient");
const grpc_channel_options_1 = require("./grpc/grpc-channel-options");
const retry_interceptor_1 = require("./grpc/retry-interceptor");
class PubsubClient extends AbstractPubsubClient_1.AbstractPubsubClient {
    // private static readonly RST_STREAM_NO_ERROR_MESSAGE =
    //   'Received RST_STREAM with code 0';
    /**
     * @param {TopicClientProps} props
     */
    constructor(props) {
        super(props.configuration.getLoggerFactory(), props.configuration.getLoggerFactory().getLogger(PubsubClient.name), new cache_service_error_mapper_1.CacheServiceErrorMapper(props.configuration.getThrowOnErrors()));
        this.credentialProvider = props.credentialProvider;
        this.unaryRequestTimeoutMs = PubsubClient.DEFAULT_REQUEST_TIMEOUT_MS;
        this.getLogger().debug(`Creating topic client using endpoint: '${this.credentialProvider.getCacheEndpoint()}'`);
        const topicGrpcConfig = props.configuration
            .getTransportStrategy()
            .getGrpcConfig();
        // NOTE: This is hard-coded for now but we may want to expose it via TopicConfiguration in the
        // future, as we do with some of the other clients.
        const grpcConfig = new __1.StaticGrpcConfiguration({
            deadlineMillis: this.unaryRequestTimeoutMs,
            maxSessionMemoryMb: PubsubClient.DEFAULT_MAX_SESSION_MEMORY_MB,
            keepAlivePermitWithoutCalls: topicGrpcConfig.getKeepAlivePermitWithoutCalls(),
            keepAliveTimeMs: topicGrpcConfig.getKeepAliveTimeMS(),
            keepAliveTimeoutMs: topicGrpcConfig.getKeepAliveTimeoutMS(),
        });
        const channelOptions = (0, grpc_channel_options_1.grpcChannelOptionsFromGrpcConfig)(grpcConfig);
        this.getLogger().debug(`Creating pubsub client with channel options: ${JSON.stringify(channelOptions, null, 2)}`);
        this.client = new grpcPubsub.PubsubClient(this.credentialProvider.getCacheEndpoint(), this.credentialProvider.isCacheEndpointSecure()
            ? grpc_js_1.ChannelCredentials.createSsl()
            : grpc_js_1.ChannelCredentials.createInsecure(), channelOptions);
        const headers = [
            new headers_interceptor_1.Header('Authorization', this.credentialProvider.getAuthToken()),
            new headers_interceptor_1.Header('agent', `nodejs:topic:${package_json_1.version}`),
            new headers_interceptor_1.Header('runtime-version', `nodejs:${process.versions.node}`),
        ];
        this.unaryInterceptors = PubsubClient.initializeUnaryInterceptors(headers, props.configuration, this.unaryRequestTimeoutMs);
        this.streamingInterceptors =
            PubsubClient.initializeStreamingInterceptors(headers);
    }
    getEndpoint() {
        const endpoint = this.credentialProvider.getCacheEndpoint();
        this.getLogger().debug(`Using cache endpoint: ${endpoint}`);
        return endpoint;
    }
    async sendPublish(cacheName, topicName, value) {
        const topicValue = new grpcPubsub._TopicValue();
        if (typeof value === 'string') {
            topicValue.text = value;
        }
        else {
            topicValue.binary = value;
        }
        const request = new grpcPubsub._PublishRequest({
            cache_name: cacheName,
            topic: topicName,
            value: topicValue,
        });
        return await new Promise((resolve, reject) => {
            this.client.Publish(request, {
                interceptors: this.unaryInterceptors,
            }, (err, resp) => {
                if (resp) {
                    resolve(new __1.TopicPublish.Success());
                }
                else {
                    this.getCacheServiceErrorMapper().resolveOrRejectError({
                        err: err,
                        errorResponseFactoryFn: e => new __1.TopicPublish.Error(e),
                        resolveFn: resolve,
                        rejectFn: reject,
                    });
                }
            });
        });
    }
    /**
     * @remark This method is responsible for restarting the stream if it ends unexpectedly.
     * Since we return a single subscription object to the user, we need to update it with the
     * unsubscribe function should we restart the stream. This is why we pass the subscription
     * state and subscription object to this method.
     *
     * Handling a cache not exists requires special care as well. In the most likely case,
     * when the subscription starts and the cache does not exist, we receive an error immediately.
     * We return an error from the subscribe method and do immediately unsubscribe. In a distinct,
     * unlikely but possible case, the user deletes the cache while the stream is running. In this
     * case we already returned a subscription object to the user, so we instead cancel the stream and
     * propagate an error to the user via the error handler.
     */
    sendSubscribe(options) {
        const request = new grpcPubsub._SubscriptionRequest({
            cache_name: options.cacheName,
            topic: options.topicName,
            resume_at_topic_sequence_number: options.subscriptionState.resumeAtTopicSequenceNumber,
        });
        this.getLogger().trace('Subscribing to topic with resume_at_topic_sequence_number: %s', options.subscriptionState.resumeAtTopicSequenceNumber);
        const call = this.client.Subscribe(request, {
            interceptors: this.streamingInterceptors,
        });
        options.subscriptionState.setSubscribed();
        // Allow the caller to cancel the stream.
        // Note that because we restart the stream on error or stream end,
        // we need to ensure we keep the same subscription object. That way
        // stream restarts are transparent to the caller.
        options.subscriptionState.unsubscribeFn = () => {
            call.cancel();
        };
        return new Promise((resolve, _reject) => {
            const prepareCallbackOptions = {
                ...options,
                resolve,
            };
            call.on('data', this.prepareDataCallback(prepareCallbackOptions));
            call.on('error', this.prepareErrorCallback(prepareCallbackOptions));
            call.on('end', this.prepareEndCallback(prepareCallbackOptions));
        });
    }
    prepareDataCallback(options) {
        return (resp) => {
            if (options.firstMessage) {
                options.resolve(options.subscription);
            }
            options.firstMessage = false;
            if (resp.item) {
                const sequenceNumber = resp.item.topic_sequence_number;
                options.subscriptionState.lastTopicSequenceNumber = sequenceNumber;
                this.getLogger().trace('Received an item on subscription stream; topic: %s; sequence number: %s', (0, utils_1.truncateString)(options.topicName), sequenceNumber);
                if (resp.item.value.text) {
                    options.onItem(new __1.TopicItem(resp.item.value.text, sequenceNumber, {
                        tokenId: resp.item.publisher_id,
                    }));
                }
                else if (resp.item.value.binary) {
                    options.onItem(new __1.TopicItem(resp.item.value.binary, sequenceNumber, {
                        tokenId: resp.item.publisher_id,
                    }));
                }
                else {
                    this.getLogger().error('Received subscription item with unknown type; topic: %s', (0, utils_1.truncateString)(options.topicName));
                    options.onError(new __1.TopicSubscribe.Error(new __1.UnknownError('Unknown item value type')), options.subscription);
                }
            }
            else if (resp.heartbeat) {
                this.getLogger().trace('Received heartbeat from subscription stream; topic: %s', (0, utils_1.truncateString)(options.topicName));
                options.onHeartbeat(new __1.TopicHeartbeat());
            }
            else if (resp.discontinuity) {
                this.getLogger().trace('Received discontinuity from subscription stream; topic: %s', (0, utils_1.truncateString)(options.topicName));
                options.onDiscontinuity(new __1.TopicDiscontinuity(resp.discontinuity.last_topic_sequence, resp.discontinuity.new_topic_sequence));
            }
            else {
                this.getLogger().error('Received unknown subscription item; topic: %s', (0, utils_1.truncateString)(options.topicName));
                options.onError(new __1.TopicSubscribe.Error(new __1.UnknownError('Unknown item type')), options.subscription);
            }
        };
    }
    prepareErrorCallback(options) {
        return (err) => {
            // When the caller unsubscribes, we may get a follow on error, which we ignore.
            if (!options.subscriptionState.isSubscribed) {
                return;
            }
            const serviceError = err;
            this.getLogger().trace(`Subscription encountered an error: ${serviceError.code}: ${serviceError.message}: ${serviceError.details}`);
            const shouldReconnectSubscription = 
            // previously, we were only attempting a reconnect on this one very specific case, but our current expectation is that
            // we should err on the side of retrying. This may become a sort of "deny list" of error types to *not* retry on
            // in the future, but for now we will be aggressive about retrying.
            // // serviceError.code === Status.INTERNAL &&
            //  // serviceError.details === PubsubClient.RST_STREAM_NO_ERROR_MESSAGE;
            true;
            const momentoError = new __1.TopicSubscribe.Error(this.getCacheServiceErrorMapper().convertError(serviceError));
            this.handleSubscribeError(options, momentoError, shouldReconnectSubscription);
        };
    }
    static initializeUnaryInterceptors(headers, configuration, requestTimeoutMs) {
        return [
            (0, middlewares_interceptor_1.middlewaresInterceptor)(configuration.getLoggerFactory(), [], {}),
            headers_interceptor_1.HeaderInterceptor.createHeadersInterceptor(headers),
            retry_interceptor_1.RetryInterceptor.createRetryInterceptor({
                clientName: 'PubSubClient',
                loggerFactory: configuration.getLoggerFactory(),
                overallRequestTimeoutMs: requestTimeoutMs,
            }),
        ];
    }
    // TODO https://github.com/momentohq/client-sdk-nodejs/issues/349
    // decide on streaming interceptors and middlewares
    static initializeStreamingInterceptors(headers) {
        return [headers_interceptor_1.HeaderInterceptor.createHeadersInterceptor(headers)];
    }
}
exports.PubsubClient = PubsubClient;
PubsubClient.DEFAULT_REQUEST_TIMEOUT_MS = 5 * 1000;
PubsubClient.DEFAULT_MAX_SESSION_MEMORY_MB = 256;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHVic3ViLWNsaWVudC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9pbnRlcm5hbC9wdWJzdWItY2xpZW50LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUFBLGdFQUFrRDtBQUNsRCxJQUFPLFVBQVUsR0FBRyx3QkFBTSxDQUFDLFlBQVksQ0FBQyxNQUFNLENBQUM7QUFDL0MsMEdBQTBHO0FBQzFHLG9FQUFxRTtBQUNyRSxxRkFBNkU7QUFDN0UsMkNBQTRFO0FBQzVFLHFEQUEyQztBQUMzQyw0RUFBc0U7QUFDdEUsMkJBVWE7QUFDYix1RUFBMkU7QUFDM0Usb0hBSW1GO0FBR25GLHNFQUE2RTtBQUM3RSxnRUFBMEQ7QUFFMUQsTUFBYSxZQUFhLFNBQVEsMkNBQWtDO0lBU2xFLHdEQUF3RDtJQUN4RCx1Q0FBdUM7SUFFdkM7O09BRUc7SUFDSCxZQUFZLEtBQTBCO1FBQ3BDLEtBQUssQ0FDSCxLQUFLLENBQUMsYUFBYSxDQUFDLGdCQUFnQixFQUFFLEVBQ3RDLEtBQUssQ0FBQyxhQUFhLENBQUMsZ0JBQWdCLEVBQUUsQ0FBQyxTQUFTLENBQUMsWUFBWS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ZXN0ID0gbmV3IGdycGNQdWJzdWIuX1B1Ymxpc2hSZXF1ZXN0KHtcbiAgICAgIGNhY2hlX25hbWU6IGNhY2hlTmFtZSxcbiAgICAgIHRvcGljOiB0b3BpY05hbWUsXG4gICAgICB2YWx1ZTogdG9waWNWYWx1ZSxcbiAgICB9KTtcblxuICAgIHJldHVybiBhd2FpdCBuZXcgUHJvbWlzZSgocmVzb2x2ZSwgcmVqZWN0KSA9PiB7XG4gICAgICB0aGlzLmNsaWVudC5QdWJsaXNoKFxuICAgICAgICByZXF1ZXN0LFxuICAgICAgICB7XG4gICAgICAgICAgaW50ZXJjZXB0b3JzOiB0aGlzLnVuYXJ5SW50ZXJjZXB0b3JzLFxuICAgICAgICB9LFxuICAgICAgICAoZXJyLCByZXNwKSA9PiB7XG4gICAgICAgICAgaWYgKHJlc3ApIHtcbiAgICAgICAgICAgIHJlc29sdmUobmV3IFRvcGljUHVibGlzaC5TdWNjZXNzKCkpO1xuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICB0aGlzLmdldENhY2hlU2VydmljZUVycm9yTWFwcGVyKCkucmVzb2x2ZU9yUmVqZWN0RXJyb3Ioe1xuICAgICAgICAgICAgICBlcnI6IGVycixcbiAgICAgICAgICAgICAgZXJyb3JSZXNwb25zZUZhY3RvcnlGbjogZSA9PiBuZXcgVG9waWNQdWJsaXNoLkVycm9yKGUpLFxuICAgICAgICAgICAgICByZXNvbHZlRm46IHJlc29sdmUsXG4gICAgICAgICAgICAgIHJlamVjdEZuOiByZWplY3QsXG4gICAgICAgICAgICB9KTtcbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICk7XG4gICAgfSk7XG4gIH1cblxuICAvKipcbiAgICogQHJlbWFyayBUaGlzIG1ldGhvZCBpcyByZXNwb25zaWJsZSBmb3IgcmVzdGFydGluZyB0aGUgc3RyZWFtIGlmIGl0IGVuZHMgdW5leHBlY3RlZGx5LlxuICAgKiBTaW5jZSB3ZSByZXR1cm4gYSB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b2tlbklkOiByZXNwLml0ZW0ucHVibGlzaGVyX2lkLFxuICAgICAgICAgICAgfSlcbiAgICAgICAgICApO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIHRoaXMuZ2V0TG9nZ2VyKCkuZXJyb3IoXG4gICAgICAgICAgICAnUmVjZWl2ZWQgc3Vic2NyaXB0aW9uIGl0ZW0gd2l0aCB1bmtub3duIHR5cGU7IHRvcGljOiAlcycsXG4gICAgICAgICAgICB0cnVuY2F0ZVN0cmluZyhvcHRpb25zLnRvcGljTmFtZSlcbiAgICAgICAgICApO1xuICAgICAgICAgIG9wdGlvbnMub25FcnJvcihcbiAgICAgICAgICAgIG5ldyBUb3BpY1N1YnNjcmliZS5FcnJvcihcbiAgICAgICAgICAgICAgbmV3IFVua25vd25FcnJvcignVW5rbm93biBpdGVtIHZhbHVlIHR5cGUnKVxuICAgICAgICAgICAgKSxcbiAgICAgICAgICAgIG9wdGlvbnMuc3Vic2NyaXB0aW9uXG4gICAgICAgICAgKTtcbiAgICAgICAgfVxuICAgICAgfSBlbHNlIGlmIChyZXNwLmhlYXJ0YmVhdCkge1xuICAgICAgICB0aGlzLmdldExvZ2dlcigpLnRyYWNlKFxuICAgICAgICAgICdSZWNlaXZlZCBoZWFydGJlYXQgZnJvbSBzdWJzY3JpcHRpb24gc3RyZWFtOyB0b3BpYzogJXMnLFxuICAgICAgICAgIHRydW5jYXRlU3RyaW5nKG9wdGlvbnMudG9waWNOYW1lKVxuICAgICAgICApO1xuICAgICAgICBvcHRpb25zLm9uSGVhcnRiZWF0KG5ldyBUb3BpY0hlYXJ0YmVhdCgpKTtcbiAgICAgIH0gZWxzZSBpZiAocmVzcC5kaXNjb250aW51aXR5KSB7XG4gICAgICAgIHRoaXMuZ2V0TG9nZ2VyKCkudHJhY2UoXG4gICAgICAgICAgJ1JlY2VpdmVkIGRpc2NvbnRpbnVpdHkgZnJvbSBzdWJzY3JpcHRpb24gc3RyZWFtOyB0b3BpYzogJXMnLFxuICAgICAgICAgIHRydW5jYXRlU3RyaW5nKG9wdGlvbnMudG9waWNOYW1lKVxuICAgICAgICApO1xuICAgICAgICBvcHRpb25zLm9uRGlzY29udGludWl0eShcbiAgICAgICAgICBuZXcgVG9waWNEaXNjb250aW51aXR5KFxuICAgICAgICAgICAgcmVzcC5kaXNjb250aW51aXR5Lmxhc3RfdG9waWNfc2VxdWVuY2UsXG4gICAgICAgICAgICByZXNwLmRpc2NvbnRpbnVpdHkubmV3X3RvcGljX3NlcXVlbmNlXG4gICAgICAgICAgKVxuICAgICAgICApO1xuICAgICAgfSBlbHNlIHtcbiAgICAgICAgdGhpcy5nZXRMb2dnZXIoKS5lcnJvcihcbiAgICAgICAgICAnUmVjZWl2ZWQgdW5rbm93biBzdWJzY3JpcHRpb24gaXRlbTsgdG9waWM6ICVzJyxcbiAgICAgICAgICB0cnVuY2F0ZVN0cmluZyhvcHRpb25zLnRvcGljTmFtZSlcbiAgICAgICAgKTtcbiAgICAgICAgb3B0aW9ucy5vbkVycm9yKFxuICAgICAgICAgIG5ldyBUb3BpY1N1YnNjcmliZS5FcnJvcihuZXcgVW5rbm93bkVycm9yKCdVbmtub3duIGl0ZW0gdHlwZScpKSxcbiAgICAgICAgICBvcHRpb25zLnN1YnNjcmlwdGlvblxuICAgICAgICApO1xuICAgICAgfVxuICAgIH07XG4gIH1cblxuICBwcml2YXRlIHByZXBhcmVFcnJvckNhbGxiYWNrKFxuICAgIG9wdGlvbnM6IFByZXBhcmVTdWJzY3JpYmVDYWxsYmFja09wdGlvbnNcbiAgKTogKGVycjogRXJyb3IpID0+IHZvaWQge1xuICAgIHJldHVybiAoZXJyOiBFcnJvcikgPT4ge1xuICAgICAgLy8gV2hlbiB0aGUgY2FsbGVyIHVuc3Vic2NyaWJlcywgd2UgbWF5IGdldCBhIGZvbGxvdyBvbiBlcnJvciwgd2hpY2ggd2UgaWdub3JlLlxuICAgICAgaWYgKCFvcHRpb25zLnN1YnNjcmlwdGlvblN0YXRlLmlzU3Vic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