Google Cloud Platform logo

Cloud Data Loss Prevention: Node.js Client

release level npm version codecov

The Data Loss Prevention API provides programmatic access to a powerful detection engine for personally identifiable information and other privacy-sensitive data in unstructured data streams.

Read more about the client libraries for Cloud APIs, including the older Google APIs Client Libraries, in Client Libraries Explained.

Table of contents:

Quickstart

Before you begin

  1. Select or create a Cloud Platform project.
  2. Enable billing for your project.
  3. Enable the Cloud Data Loss Prevention API.
  4. Set up authentication with a service account so you can access the API from your local workstation.

Installing the client library

npm install @google-cloud/dlp

Using the client library


  // Instantiates a client
  const dlp = new DLP.DlpServiceClient();

  // The string to inspect
  const string = 'Robert Frost';

  // The project ID to run the API call under
  const projectId = process.env.GCLOUD_PROJECT;

  // The minimum likelihood required before returning a match
  const minLikelihood = 'LIKELIHOOD_UNSPECIFIED';

  // The maximum number of findings to report (0 = server maximum)
  const maxFindings = 0;

  // The infoTypes of information to match
  const infoTypes = [{name: 'PERSON_NAME'}, {name: 'US_STATE'}];

  // Whether to include the matching string
  const includeQuote = true;

  // Construct item to inspect
  const item = {value: string};

  // Construct request
  const request = {
    parent: dlp.projectPath(projectId),
    inspectConfig: {
      infoTypes: infoTypes,
      minLikelihood: minLikelihood,
      limits: {
        maxFindingsPerRequest: maxFindings,
      },
      includeQuote: includeQuote,
    },
    item: item,
  };

  // Run request
  const [response] = await dlp.inspectContent(request);
  const findings = response.result.findings;
  if (findings.length > 0) {
    console.log(`Findings:`);
    findings.forEach(finding => {
      if (includeQuote) {
        console.log(`\tQuote: ${finding.quote}`);
      }
      console.log(`\tInfo type: ${finding.infoType.name}`);
      console.log(`\tLikelihood: ${finding.likelihood}`);
    });
  } else {
    console.log(`No findings.`);
  }

Samples

Samples are in the samples/ directory. The samples' README.md has instructions for running the samples.

Sample Source Code Try it
Deid source code Open in Cloud Shell
Inspect source code Open in Cloud Shell
Job Management source code Open in Cloud Shell
Metadata source code Open in Cloud Shell
Quickstart source code Open in Cloud Shell
Redact source code Open in Cloud Shell
Risk Analysis source code Open in Cloud Shell
Inspect Templates source code Open in Cloud Shell
Job Triggers source code Open in Cloud Shell

The Cloud Data Loss Prevention Node.js Client API Reference documentation also contains samples.

Versioning

This library follows Semantic Versioning.

This library is considered to be in beta. This means it is expected to be mostly stable while we work toward a general availability release; however, complete stability is not guaranteed. We will address issues and requests against beta libraries with a high priority.

More Information: Google Cloud Platform Launch Stages

Contributing

Contributions welcome! See the Contributing Guide.

License

Apache Version 2.0

See LICENSE

google

google.privacy

google.privacy.dlp

google.privacy.dlp.v2

google.privacy.dlp.v2
google.privacy.dlp.v2.Action
google.privacy.dlp.v2.ActivateJobTriggerRequest
google.privacy.dlp.v2.AnalyzeDataSourceRiskDetails
google.privacy.dlp.v2.AuxiliaryTable
google.privacy.dlp.v2.BigQueryField
google.privacy.dlp.v2.BigQueryKey
google.privacy.dlp.v2.BigQueryOptions
google.privacy.dlp.v2.BigQueryTable
google.privacy.dlp.v2.BoundingBox
google.privacy.dlp.v2.Bucket
google.privacy.dlp.v2.BucketingConfig
google.privacy.dlp.v2.ByteContentItem
google.privacy.dlp.v2.BytesType
google.privacy.dlp.v2.CancelDlpJobRequest
google.privacy.dlp.v2.CategoricalStatsConfig
google.privacy.dlp.v2.CategoricalStatsHistogramBucket
google.privacy.dlp.v2.CategoricalStatsResult
google.privacy.dlp.v2.CharacterMaskConfig
google.privacy.dlp.v2.CharsToIgnore
google.privacy.dlp.v2.CloudStorageFileSet
google.privacy.dlp.v2.CloudStorageOptions
google.privacy.dlp.v2.CloudStoragePath
google.privacy.dlp.v2.CloudStorageRegexFileSet
google.privacy.dlp.v2.Color
google.privacy.dlp.v2.CommonCharsToIgnore
google.privacy.dlp.v2.Condition
google.privacy.dlp.v2.Conditions
google.privacy.dlp.v2.ContentItem
google.privacy.dlp.v2.ContentLocation
google.privacy.dlp.v2.ContentOption
google.privacy.dlp.v2.CreateDeidentifyTemplateRequest
google.privacy.dlp.v2.CreateDlpJobRequest
google.privacy.dlp.v2.CreateInspectTemplateRequest
google.privacy.dlp.v2.CreateJobTriggerRequest
google.privacy.dlp.v2.CreateStoredInfoTypeRequest
google.privacy.dlp.v2.CryptoDeterministicConfig
google.privacy.dlp.v2.CryptoHashConfig
google.privacy.dlp.v2.CryptoKey
google.privacy.dlp.v2.CryptoReplaceFfxFpeConfig
google.privacy.dlp.v2.CustomInfoType
google.privacy.dlp.v2.DatastoreKey
google.privacy.dlp.v2.DatastoreOptions
google.privacy.dlp.v2.DateShiftConfig
google.privacy.dlp.v2.DateTime
google.privacy.dlp.v2.DeidentifyConfig
google.privacy.dlp.v2.DeidentifyContentRequest
google.privacy.dlp.v2.DeidentifyContentResponse
google.privacy.dlp.v2.DeidentifyTemplate
google.privacy.dlp.v2.DeleteDeidentifyTemplateRequest
google.privacy.dlp.v2.DeleteDlpJobRequest
google.privacy.dlp.v2.DeleteInspectTemplateRequest
google.privacy.dlp.v2.DeleteJobTriggerRequest
google.privacy.dlp.v2.DeleteStoredInfoTypeRequest
google.privacy.dlp.v2.DeltaPresenceEstimationConfig
google.privacy.dlp.v2.DeltaPresenceEstimationHistogramBucket
google.privacy.dlp.v2.DeltaPresenceEstimationQuasiIdValues
google.privacy.dlp.v2.DeltaPresenceEstimationResult
google.privacy.dlp.v2.DetectionRule
google.privacy.dlp.v2.Dictionary
google.privacy.dlp.v2.DlpJob
google.privacy.dlp.v2.DlpJobType
google.privacy.dlp.v2.DocumentLocation
google.privacy.dlp.v2.EntityId
google.privacy.dlp.v2.Error
google.privacy.dlp.v2.ExcludeInfoTypes
google.privacy.dlp.v2.ExclusionRule
google.privacy.dlp.v2.ExclusionType
google.privacy.dlp.v2.Expressions
google.privacy.dlp.v2.FfxCommonNativeAlphabet
google.privacy.dlp.v2.FieldId
google.privacy.dlp.v2.FieldTransformation
google.privacy.dlp.v2.FileSet
google.privacy.dlp.v2.FileType
google.privacy.dlp.v2.Finding
google.privacy.dlp.v2.FindingLimits
google.privacy.dlp.v2.FixedSizeBucketingConfig
google.privacy.dlp.v2.GetDeidentifyTemplateRequest
google.privacy.dlp.v2.GetDlpJobRequest
google.privacy.dlp.v2.GetInspectTemplateRequest
google.privacy.dlp.v2.GetJobTriggerRequest
google.privacy.dlp.v2.GetStoredInfoTypeRequest
google.privacy.dlp.v2.HotwordRule
google.privacy.dlp.v2.ImageLocation
google.privacy.dlp.v2.ImageRedactionConfig
google.privacy.dlp.v2.InfoType
google.privacy.dlp.v2.InfoTypeDescription
google.privacy.dlp.v2.InfoTypeLimit
google.privacy.dlp.v2.InfoTypeStats
google.privacy.dlp.v2.InfoTypeSupportedBy
google.privacy.dlp.v2.InfoTypeTransformation
google.privacy.dlp.v2.InfoTypeTransformations
google.privacy.dlp.v2.InspectConfig
google.privacy.dlp.v2.InspectContentRequest
google.privacy.dlp.v2.InspectContentResponse
google.privacy.dlp.v2.InspectDataSourceDetails
google.privacy.dlp.v2.InspectionRule
google.privacy.dlp.v2.InspectionRuleSet
google.privacy.dlp.v2.InspectJobConfig
google.privacy.dlp.v2.InspectResult
google.privacy.dlp.v2.InspectTemplate
google.privacy.dlp.v2.JobNotificationEmails
google.privacy.dlp.v2.JobState
google.privacy.dlp.v2.JobTrigger
google.privacy.dlp.v2.KAnonymityConfig
google.privacy.dlp.v2.KAnonymityEquivalenceClass
google.privacy.dlp.v2.KAnonymityHistogramBucket
google.privacy.dlp.v2.KAnonymityResult
google.privacy.dlp.v2.Key
google.privacy.dlp.v2.KindExpression
google.privacy.dlp.v2.KMapEstimationConfig
google.privacy.dlp.v2.KMapEstimationHistogramBucket
google.privacy.dlp.v2.KMapEstimationQuasiIdValues
google.privacy.dlp.v2.KMapEstimationResult
google.privacy.dlp.v2.KmsWrappedCryptoKey
google.privacy.dlp.v2.LargeCustomDictionaryConfig
google.privacy.dlp.v2.LargeCustomDictionaryStats
google.privacy.dlp.v2.LDiversityConfig
google.privacy.dlp.v2.LDiversityEquivalenceClass
google.privacy.dlp.v2.LDiversityHistogramBucket
google.privacy.dlp.v2.LDiversityResult
google.privacy.dlp.v2.Likelihood
google.privacy.dlp.v2.LikelihoodAdjustment
google.privacy.dlp.v2.ListDeidentifyTemplatesRequest
google.privacy.dlp.v2.ListDeidentifyTemplatesResponse
google.privacy.dlp.v2.ListDlpJobsRequest
google.privacy.dlp.v2.ListDlpJobsResponse
google.privacy.dlp.v2.ListInfoTypesRequest
google.privacy.dlp.v2.ListInfoTypesResponse
google.privacy.dlp.v2.ListInspectTemplatesRequest
google.privacy.dlp.v2.ListInspectTemplatesResponse
google.privacy.dlp.v2.ListJobTriggersRequest
google.privacy.dlp.v2.ListJobTriggersResponse
google.privacy.dlp.v2.ListStoredInfoTypesRequest
google.privacy.dlp.v2.ListStoredInfoTypesResponse
google.privacy.dlp.v2.Location
google.privacy.dlp.v2.LogicalOperator
google.privacy.dlp.v2.MatchingType
google.privacy.dlp.v2.NumericalStatsConfig
google.privacy.dlp.v2.NumericalStatsResult
google.privacy.dlp.v2.OutputSchema
google.privacy.dlp.v2.OutputStorageConfig
google.privacy.dlp.v2.PartitionId
google.privacy.dlp.v2.PathElement
google.privacy.dlp.v2.PrimitiveTransformation
google.privacy.dlp.v2.PrivacyMetric
google.privacy.dlp.v2.Proximity
google.privacy.dlp.v2.PublishFindingsToCloudDataCatalog
google.privacy.dlp.v2.PublishSummaryToCscc
google.privacy.dlp.v2.PublishToPubSub
google.privacy.dlp.v2.QuasiId
google.privacy.dlp.v2.QuasiIdentifierField
google.privacy.dlp.v2.QuasiIdField
google.privacy.dlp.v2.QuoteInfo
google.privacy.dlp.v2.Range
google.privacy.dlp.v2.RecordCondition
google.privacy.dlp.v2.RecordKey
google.privacy.dlp.v2.RecordLocation
google.privacy.dlp.v2.RecordSuppression
google.privacy.dlp.v2.RecordTransformations
google.privacy.dlp.v2.RedactConfig
google.privacy.dlp.v2.RedactImageRequest
google.privacy.dlp.v2.RedactImageResponse
google.privacy.dlp.v2.Regex
google.privacy.dlp.v2.ReidentifyContentRequest
google.privacy.dlp.v2.ReidentifyContentResponse
google.privacy.dlp.v2.RelationalOperator
google.privacy.dlp.v2.ReplaceValueConfig
google.privacy.dlp.v2.ReplaceWithInfoTypeConfig
google.privacy.dlp.v2.RequestedOptions
google.privacy.dlp.v2.Result
google.privacy.dlp.v2.RiskAnalysisJobConfig
google.privacy.dlp.v2.Row
google.privacy.dlp.v2.SampleMethod
google.privacy.dlp.v2.SaveFindings
google.privacy.dlp.v2.Schedule
google.privacy.dlp.v2.StatisticalTable
google.privacy.dlp.v2.Status
google.privacy.dlp.v2.StorageConfig
google.privacy.dlp.v2.StoredInfoType
google.privacy.dlp.v2.StoredInfoTypeConfig
google.privacy.dlp.v2.StoredInfoTypeState
google.privacy.dlp.v2.StoredInfoTypeStats
google.privacy.dlp.v2.StoredInfoTypeVersion
google.privacy.dlp.v2.StoredType
google.privacy.dlp.v2.SummaryResult
google.privacy.dlp.v2.SurrogateType
google.privacy.dlp.v2.Table
google.privacy.dlp.v2.TableLocation
google.privacy.dlp.v2.TaggedField
google.privacy.dlp.v2.TimePart
google.privacy.dlp.v2.TimePartConfig
google.privacy.dlp.v2.TimespanConfig
google.privacy.dlp.v2.TimeZone
google.privacy.dlp.v2.TransformationOverview
google.privacy.dlp.v2.TransformationResultCode
google.privacy.dlp.v2.TransformationSummary
google.privacy.dlp.v2.TransientCryptoKey
google.privacy.dlp.v2.Trigger
google.privacy.dlp.v2.UnwrappedCryptoKey
google.privacy.dlp.v2.UpdateDeidentifyTemplateRequest
google.privacy.dlp.v2.UpdateInspectTemplateRequest
google.privacy.dlp.v2.UpdateJobTriggerRequest
google.privacy.dlp.v2.UpdateStoredInfoTypeRequest
google.privacy.dlp.v2.Value
google.privacy.dlp.v2.ValueFrequency
google.privacy.dlp.v2.WordList

v2.DlpServiceClient

v2.DlpServiceClient#getStoredInfoType(request[, options][, callback])
v2.DlpServiceClient#inspectContent(request[, options][, callback])
v2.DlpServiceClient#listDeidentifyTemplates(request[, options][, callback])
v2.DlpServiceClient#listDeidentifyTemplatesStream(request[, options])
v2.DlpServiceClient#listDlpJobs(request[, options][, callback])
v2.DlpServiceClient#listDlpJobsStream(request[, options])
v2.DlpServiceClient#listInfoTypes(request[, options][, callback])
v2.DlpServiceClient#listInspectTemplates(request[, options][, callback])
v2.DlpServiceClient#listInspectTemplatesStream(request[, options])
v2.DlpServiceClient#listJobTriggers(request[, options][, callback])
v2.DlpServiceClient#listJobTriggersStream(request[, options])
v2.DlpServiceClient#listStoredInfoTypes(request[, options][, callback])
v2.DlpServiceClient#listStoredInfoTypesStream(request[, options])
v2.DlpServiceClient#matchDeidentifyTemplateFromOrganizationDeidentifyTemplateName(organizationDeidentifyTemplateName)
v2.DlpServiceClient#matchDeidentifyTemplateFromProjectDeidentifyTemplateName(projectDeidentifyTemplateName)
v2.DlpServiceClient#matchDlpJobFromDlpJobName(dlpJobName)
v2.DlpServiceClient#matchInspectTemplateFromOrganizationInspectTemplateName(organizationInspectTemplateName)
v2.DlpServiceClient#matchInspectTemplateFromProjectInspectTemplateName(projectInspectTemplateName)
v2.DlpServiceClient#matchJobTriggerFromProjectJobTriggerName(projectJobTriggerName)
v2.DlpServiceClient#matchOrganizationFromOrganizationDeidentifyTemplateName(organizationDeidentifyTemplateName)
v2.DlpServiceClient#matchOrganizationFromOrganizationInspectTemplateName(organizationInspectTemplateName)
v2.DlpServiceClient#matchOrganizationFromOrganizationName(organizationName)
v2.DlpServiceClient#matchOrganizationFromOrganizationStoredInfoTypeName(organizationStoredInfoTypeName)
v2.DlpServiceClient#matchProjectFromDlpJobName(dlpJobName)
v2.DlpServiceClient#matchProjectFromProjectDeidentifyTemplateName(projectDeidentifyTemplateName)
v2.DlpServiceClient#matchProjectFromProjectInspectTemplateName(projectInspectTemplateName)
v2.DlpServiceClient#matchProjectFromProjectJobTriggerName(projectJobTriggerName)
v2.DlpServiceClient#matchProjectFromProjectName(projectName)
v2.DlpServiceClient#matchProjectFromProjectStoredInfoTypeName(projectStoredInfoTypeName)
v2.DlpServiceClient#matchStoredInfoTypeFromOrganizationStoredInfoTypeName(organizationStoredInfoTypeName)
v2.DlpServiceClient#matchStoredInfoTypeFromProjectStoredInfoTypeName(projectStoredInfoTypeName)
v2.DlpServiceClient#organizationDeidentifyTemplatePath(organization, deidentifyTemplate)
v2.DlpServiceClient#organizationInspectTemplatePath(organization, inspectTemplate)
v2.DlpServiceClient#organizationPath(organization)
v2.DlpServiceClient#organizationStoredInfoTypePath(organization, storedInfoType)
v2.DlpServiceClient#projectDeidentifyTemplatePath(project, deidentifyTemplate)
v2.DlpServiceClient#projectInspectTemplatePath(project, inspectTemplate)
v2.DlpServiceClient#projectJobTriggerPath(project, jobTrigger)
v2.DlpServiceClient#projectPath(project)
v2.DlpServiceClient#projectStoredInfoTypePath(project, storedInfoType)
v2.DlpServiceClient#redactImage(request[, options][, callback])
v2.DlpServiceClient#reidentifyContent(request[, options][, callback])
v2.DlpServiceClient#updateDeidentifyTemplate(request[, options][, callback])
v2.DlpServiceClient#updateInspectTemplate(request[, options][, callback])
v2.DlpServiceClient#updateJobTrigger(request[, options][, callback])
v2.DlpServiceClient#updateStoredInfoType(request[, options][, callback])