@arcane-utils/pubsub 1.2.3 → 1.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  ## CHANGE LOG
4
4
 
5
+ ### V 1.2.5
6
+ Use commonjs module
7
+
5
8
  ### V 1.2.3
6
9
  Expose publishAvroRecords
7
10
 
@@ -11,7 +14,7 @@ Fix function publish validate with a schema
11
14
  ### V 1.2.1
12
15
  Fix function publish validate with a schema
13
16
 
14
- ### V 1.2.O
17
+ ### V 1.2.0
15
18
  Add a function publish validate with a schema
16
19
 
17
20
  ### V 1.1.12
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- var A=Object.create;var m=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var U=Object.getPrototypeOf,I=Object.prototype.hasOwnProperty;var k=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports),F=(e,r)=>{for(var t in r)m(e,t,{get:r[t],enumerable:!0})},h=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of j(r))!I.call(e,o)&&o!==t&&m(e,o,{get:()=>r[o],enumerable:!(n=T(r,o))||n.enumerable});return e};var y=(e,r,t)=>(t=e!=null?A(U(e)):{},h(r||!e||!e.__esModule?m(t,"default",{value:e,enumerable:!0}):t,e)),$=e=>h(m({},"__esModule",{value:!0}),e);var S=k((l,P)=>{var b=require("buffer"),s=b.Buffer;function w(e,r){for(var t in e)r[t]=e[t]}s.from&&s.alloc&&s.allocUnsafe&&s.allocUnsafeSlow?P.exports=b:(w(b,l),l.Buffer=u);function u(e,r,t){return s(e,r,t)}u.prototype=Object.create(s.prototype);w(s,u);u.from=function(e,r,t){if(typeof e=="number")throw new TypeError("Argument must not be a number");return s(e,r,t)};u.alloc=function(e,r,t){if(typeof e!="number")throw new TypeError("Argument must be a number");var n=s(e);return r!==void 0?typeof t=="string"?n.fill(r,t):n.fill(r):n.fill(0),n};u.allocUnsafe=function(e){if(typeof e!="number")throw new TypeError("Argument must be a number");return s(e)};u.allocUnsafeSlow=function(e){if(typeof e!="number")throw new TypeError("Argument must be a number");return b.SlowBuffer(e)}});var J={};F(J,{getPubsubClient:()=>x,googlePubsub:()=>O,publishAvroRecords:()=>_,publishMessage:()=>p,publishProductFlowMonitoringMessage:()=>B,publishStorageMessage:()=>E});module.exports=$(J);var O=y(require("@google-cloud/pubsub"),1);var f=require("@google-cloud/pubsub"),M=y(require("avro-js"),1),{Buffer:v}=S(),x=(e,r)=>new f.PubSub({projectId:e,keyFilename:r}),p=async(e,r,t,n)=>{let o=v.from(JSON.stringify(r));return t.topic(e).publish(o,n)},B=async(e,r,t,n,o,i,a)=>{let c={entity_id:r,status:n,monitoring_id:t,step:e};return a&&(c.error_message=a),p(o,{parameters:c},i)},E=async(e,r,t,n,o)=>{let i={metadata:{monitoring_id:o}},c={objectId:e,bucketId:r,eventTime:new Date().toISOString()};return p(t,i,n,c)},q=async(e,r)=>(await r.schema(e).get()).definition,_=async(e,r,t)=>{let n=r.topic(e),[o]=await n.getMetadata(),i=o.schemaSettings;if(!i)return Promise.reject(new Error(`Topic ${e} doesn't seem to have a schema.`));let a=i.encoding,c=await q((i==null?void 0:i.schema)??"",r),d=M.parse(c),g;switch(a){case f.Encodings.Binary:g=d.toBuffer(t);break;case f.Encodings.Json:g=v.from(d.toString(t));break;default:return Promise.reject(new Error(`Unknown schema encoding: ${a}`))}return g?await n.publishMessage({data:g}):Promise.reject(new Error(`Invalid encoding ${a} on the topic.`))};0&&(module.exports={getPubsubClient,googlePubsub,publishAvroRecords,publishMessage,publishProductFlowMonitoringMessage,publishStorageMessage});
1
+ var A=Object.create;var m=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var U=Object.getPrototypeOf,I=Object.prototype.hasOwnProperty;var k=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),F=(e,t)=>{for(var r in t)m(e,r,{get:t[r],enumerable:!0})},h=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of j(t))!I.call(e,o)&&o!==r&&m(e,o,{get:()=>t[o],enumerable:!(n=T(t,o))||n.enumerable});return e};var y=(e,t,r)=>(r=e!=null?A(U(e)):{},h(t||!e||!e.__esModule?m(r,"default",{value:e,enumerable:!0}):r,e)),$=e=>h(m({},"__esModule",{value:!0}),e);var P=k((l,S)=>{var b=require("buffer"),s=b.Buffer;function w(e,t){for(var r in e)t[r]=e[r]}s.from&&s.alloc&&s.allocUnsafe&&s.allocUnsafeSlow?S.exports=b:(w(b,l),l.Buffer=u);function u(e,t,r){return s(e,t,r)}u.prototype=Object.create(s.prototype);w(s,u);u.from=function(e,t,r){if(typeof e=="number")throw new TypeError("Argument must not be a number");return s(e,t,r)};u.alloc=function(e,t,r){if(typeof e!="number")throw new TypeError("Argument must be a number");var n=s(e);return t!==void 0?typeof r=="string"?n.fill(t,r):n.fill(t):n.fill(0),n};u.allocUnsafe=function(e){if(typeof e!="number")throw new TypeError("Argument must be a number");return s(e)};u.allocUnsafeSlow=function(e){if(typeof e!="number")throw new TypeError("Argument must be a number");return b.SlowBuffer(e)}});var J={};F(J,{getPubsubClient:()=>x,googlePubsub:()=>O,publishAvroRecords:()=>_,publishMessage:()=>p,publishProductFlowMonitoringMessage:()=>B,publishStorageMessage:()=>E});module.exports=$(J);var O=y(require("@google-cloud/pubsub"),1);var f=require("@google-cloud/pubsub"),M=y(require("avro-js"),1),{Buffer:v}=P(),x=(e,t)=>new f.PubSub({projectId:e,keyFilename:t}),p=async(e,t,r,n)=>{let o=v.from(JSON.stringify(t));return r.topic(e).publish(o,n)},B=async(e,t,r,n,o,i,a)=>{let c={entity_id:t,status:n,monitoring_id:r,step:e};return a&&(c.error_message=a),p(o,{parameters:c},i)},E=async(e,t,r,n,o)=>{let i={metadata:{monitoring_id:o}},c={objectId:e,bucketId:t,eventTime:new Date().toISOString()};return p(r,i,n,c)},q=async(e,t)=>(await t.schema(e).get()).definition,_=async(e,t,r)=>{let n=t.topic(e),[o]=await n.getMetadata(),i=o.schemaSettings;if(!i)return Promise.reject(new Error(`Topic ${e} doesn't seem to have a schema.`));let a=i.encoding,c=await q(i?.schema??"",t),d=M.parse(c),g;switch(a){case f.Encodings.Binary:g=d.toBuffer(r);break;case f.Encodings.Json:g=v.from(d.toString(r));break;default:return Promise.reject(new Error(`Unknown schema encoding: ${a}`))}return g?await n.publishMessage({data:g}):Promise.reject(new Error(`Invalid encoding ${a} on the topic.`))};0&&(module.exports={getPubsubClient,googlePubsub,publishAvroRecords,publishMessage,publishProductFlowMonitoringMessage,publishStorageMessage});
2
2
  /*! Bundled license information:
3
3
 
4
4
  safe-buffer/index.js:
@@ -1 +1 @@
1
- {"version":3,"sources":["../node_modules/safe-buffer/index.js","../src/index.ts","../src/pubsub.ts"],"sourcesContent":["/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */\n/* eslint-disable node/no-deprecated-api */\nvar buffer = require('buffer')\nvar Buffer = buffer.Buffer\n\n// alternative to using Object.keys for old browsers\nfunction copyProps (src, dst) {\n for (var key in src) {\n dst[key] = src[key]\n }\n}\nif (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) {\n module.exports = buffer\n} else {\n // Copy properties from require('buffer')\n copyProps(buffer, exports)\n exports.Buffer = SafeBuffer\n}\n\nfunction SafeBuffer (arg, encodingOrOffset, length) {\n return Buffer(arg, encodingOrOffset, length)\n}\n\nSafeBuffer.prototype = Object.create(Buffer.prototype)\n\n// Copy static methods from Buffer\ncopyProps(Buffer, SafeBuffer)\n\nSafeBuffer.from = function (arg, encodingOrOffset, length) {\n if (typeof arg === 'number') {\n throw new TypeError('Argument must not be a number')\n }\n return Buffer(arg, encodingOrOffset, length)\n}\n\nSafeBuffer.alloc = function (size, fill, encoding) {\n if (typeof size !== 'number') {\n throw new TypeError('Argument must be a number')\n }\n var buf = Buffer(size)\n if (fill !== undefined) {\n if (typeof encoding === 'string') {\n buf.fill(fill, encoding)\n } else {\n buf.fill(fill)\n }\n } else {\n buf.fill(0)\n }\n return buf\n}\n\nSafeBuffer.allocUnsafe = function (size) {\n if (typeof size !== 'number') {\n throw new TypeError('Argument must be a number')\n }\n return Buffer(size)\n}\n\nSafeBuffer.allocUnsafeSlow = function (size) {\n if (typeof size !== 'number') {\n throw new TypeError('Argument must be a number')\n }\n return buffer.SlowBuffer(size)\n}\n","export * as googlePubsub from '@google-cloud/pubsub'\nexport {\n MonitoringMessage,\n getPubsubClient,\n publishMessage,\n publishProductFlowMonitoringMessage,\n publishStorageMessage,\n publishAvroRecords\n} from './pubsub';\n","import { PubSub, Encodings } from '@google-cloud/pubsub'\nimport { MonitoringStatus } from '@arcane-utils/types'\nimport * as avro from 'avro-js';\n\nconst {Buffer} = require('safe-buffer')\n\nexport interface MonitoringMessage {\n entity_id: number,\n status: MonitoringStatus,\n monitoring_id: string,\n step: string,\n error_message?: string\n}\n\n/**\n * Get PubSub client.\n *\n * To be used in Cloud Functions because of an issue with global declaration of clients.\n */\nexport const getPubsubClient = (gcpProject: string, serviceAccount: string): PubSub => {\n return new PubSub({\n projectId: gcpProject,\n keyFilename: serviceAccount\n })\n}\n\n/**\n * Publish a message on PubSub.\n*/\nexport const publishMessage = async (topicName: string, message: any, pubsub: PubSub, attributes?: any): Promise<string> => {\n const dataBuffer = Buffer.from(JSON.stringify(message))\n return pubsub.topic(topicName).publish(dataBuffer, attributes)\n}\n\n/**\n * Publish a message for Product Flow monitoring\n*/\nexport const publishProductFlowMonitoringMessage = async (\n step: string,\n entityId: number,\n monitoringId: string,\n status: MonitoringStatus,\n topicName: string,\n pubsub: PubSub,\n errorMessage?: string\n): Promise<string> => {\n const message: MonitoringMessage = {\n entity_id: entityId,\n status,\n monitoring_id: monitoringId,\n step\n }\n if (errorMessage) {\n message.error_message = errorMessage\n }\n return publishMessage(topicName, { parameters: message }, pubsub)\n}\n\n/**\n * Publish a message similar to a storage notification\n */\nexport const publishStorageMessage = async (\n objectId: string,\n bucketId: string,\n topicName: string,\n pubsub: PubSub,\n monitoringId?: string,\n): Promise<string> => {\n const message = {\n metadata: {\n monitoring_id: monitoringId\n }\n }\n const date = new Date()\n\n const attributes = {\n objectId,\n bucketId,\n eventTime: date.toISOString()\n }\n\n return publishMessage(topicName, message, pubsub, attributes)\n}\n\n/**\n * \n * @param schemaNameOrId : schema name or id\n * @param pubsub : pubsub client\n * @returns : schema definition Avro\n */\nexport const getSchema = async (schemaNameOrId: string, pubsub: PubSub): Promise<string | null | undefined> => {\n const schema = pubsub.schema(schemaNameOrId)\n const info = await schema.get()\n return info.definition\n}\n\n\n/**\n * Publish message with schema validation\n * \n * The schema will be retrieved from the topic metadata and validated\n */\nexport const publishAvroRecords = async (topicNameOrId : string, pubSubClient: PubSub, message: any): Promise<string> => {\n // Get the topic metadata to learn about its schema encoding.\n const topic = pubSubClient.topic(topicNameOrId)\n const [topicMetadata] = await topic.getMetadata()\n const topicSchemaMetadata = topicMetadata.schemaSettings\n\n if (!topicSchemaMetadata) {\n return Promise.reject(new Error(`Topic ${topicNameOrId} doesn't seem to have a schema.`))\n \n }\n const schemaEncoding = topicSchemaMetadata.encoding;\n\n // Make an encoder using the official avro-js library.\n const definition = await getSchema(topicSchemaMetadata?.schema ?? '', pubSubClient)\n const type = avro.parse(definition)\n\n \n let dataBuffer;\n switch (schemaEncoding) {\n case Encodings.Binary:\n dataBuffer = type.toBuffer(message)\n break\n case Encodings.Json:\n dataBuffer = Buffer.from(type.toString(message))\n break\n default:\n return Promise.reject(new Error(`Unknown schema encoding: ${schemaEncoding}`))\n }\n if (!dataBuffer) {\n return Promise.reject(new Error(`Invalid encoding ${schemaEncoding} on the topic.`))\n }\n\n const messageId = await topic.publishMessage({ data: dataBuffer })\n return messageId\n}"],"mappings":"umBAAA,IAAAA,EAAAC,EAAA,CAAAC,EAAAC,IAAA,CAEA,IAAIC,EAAS,QAAQ,QAAQ,EAC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qB,SAAU,GAAIH,CAAY,EAC5EM,EAAY,QAAMD,CAAU,EAG9BnB,EACJ,OAAQkB,EAAgB,CACtB,KAAK,YAAU,OACblB,EAAaoB,EAAK,SAASvB,CAAO,EAClC,MACF,KAAK,YAAU,KACbG,EAAaT,EAAO,KAAK6B,EAAK,SAASvB,CAAO,CAAC,EAC/C,MACF,QACE,OAAO,QAAQ,OAAO,IAAI,MAAM,4BAA4BqB,CAAc,EAAE,CAAC,CACjF,CACA,OAAKlB,EAIa,MAAMe,EAAM,eAAe,CAAE,KAAMf,CAAW,CAAC,EAHxD,QAAQ,OAAO,IAAI,MAAM,oBAAoBkB,CAAc,gBAAgB,CAAC,CAKvF","names":["require_safe_buffer","__commonJSMin","exports","module","buffer","Buffer","copyProps","src","dst","key","SafeBuffer","arg","encodingOrOffset","length","size","fill","encoding","buf","src_exports","__export","getPubsubClient","googlePubsub","publishAvroRecords","publishMessage","publishProductFlowMonitoringMessage","publishStorageMessage","__toCommonJS","import_pubsub","avro","Buffer","getPubsubClient","gcpProject","serviceAccount","publishMessage","topicName","message","pubsub","attributes","dataBuffer","publishProductFlowMonitoringMessage","step","entityId","monitoringId","status","errorMessage","publishStorageMessage","objectId","bucketId","getSchema","schemaNameOrId","publishAvroRecords","topicNameOrId","pubSubClient","topic","topicMetadata","topicSchemaMetadata","schemaEncoding","definition","type"]}
1
+ {"version":3,"sources":["../node_modules/safe-buffer/index.js","../src/index.ts","../src/pubsub.ts"],"sourcesContent":["/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */\n/* eslint-disable node/no-deprecated-api */\nvar buffer = require('buffer')\nvar Buffer = buffer.Buffer\n\n// alternative to using Object.keys for old browsers\nfunction copyProps (src, dst) {\n for (var key in src) {\n dst[key] = src[key]\n }\n}\nif (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) {\n module.exports = buffer\n} else {\n // Copy properties from require('buffer')\n copyProps(buffer, exports)\n exports.Buffer = SafeBuffer\n}\n\nfunction SafeBuffer (arg, encodingOrOffset, length) {\n return Buffer(arg, encodingOrOffset, length)\n}\n\nSafeBuffer.prototype = Object.create(Buffer.prototype)\n\n// Copy static methods from Buffer\ncopyProps(Buffer, SafeBuffer)\n\nSafeBuffer.from = function (arg, encodingOrOffset, length) {\n if (typeof arg === 'number') {\n throw new TypeError('Argument must not be a number')\n }\n return Buffer(arg, encodingOrOffset, length)\n}\n\nSafeBuffer.alloc = function (size, fill, encoding) {\n if (typeof size !== 'number') {\n throw new TypeError('Argument must be a number')\n }\n var buf = Buffer(size)\n if (fill !== undefined) {\n if (typeof encoding === 'string') {\n buf.fill(fill, encoding)\n } else {\n buf.fill(fill)\n }\n } else {\n buf.fill(0)\n }\n return buf\n}\n\nSafeBuffer.allocUnsafe = function (size) {\n if (typeof size !== 'number') {\n throw new TypeError('Argument must be a number')\n }\n return Buffer(size)\n}\n\nSafeBuffer.allocUnsafeSlow = function (size) {\n if (typeof size !== 'number') {\n throw new TypeError('Argument must be a number')\n }\n return buffer.SlowBuffer(size)\n}\n","export * as googlePubsub from '@google-cloud/pubsub'\nexport {\n MonitoringMessage,\n getPubsubClient,\n publishMessage,\n publishProductFlowMonitoringMessage,\n publishStorageMessage,\n publishAvroRecords\n} from './pubsub';\n","import { PubSub, Encodings } from '@google-cloud/pubsub'\nimport { MonitoringStatus } from '@arcane-utils/types'\nimport * as avro from 'avro-js';\n\nconst {Buffer} = require('safe-buffer')\n\nexport interface MonitoringMessage {\n entity_id: number,\n status: MonitoringStatus,\n monitoring_id: string,\n step: string,\n error_message?: string\n}\n\n/**\n * Get PubSub client.\n *\n * To be used in Cloud Functions because of an issue with global declaration of clients.\n */\nexport const getPubsubClient = (gcpProject: string, serviceAccount: string): PubSub => {\n return new PubSub({\n projectId: gcpProject,\n keyFilename: serviceAccount\n })\n}\n\n/**\n * Publish a message on PubSub.\n*/\nexport const publishMessage = async (topicName: string, message: any, pubsub: PubSub, attributes?: any): Promise<string> => {\n const dataBuffer = Buffer.from(JSON.stringify(message))\n return pubsub.topic(topicName).publish(dataBuffer, attributes)\n}\n\n/**\n * Publish a message for Product Flow monitoring\n*/\nexport const publishProductFlowMonitoringMessage = async (\n step: string,\n entityId: number,\n monitoringId: string,\n status: MonitoringStatus,\n topicName: string,\n pubsub: PubSub,\n errorMessage?: string\n): Promise<string> => {\n const message: MonitoringMessage = {\n entity_id: entityId,\n status,\n monitoring_id: monitoringId,\n step\n }\n if (errorMessage) {\n message.error_message = errorMessage\n }\n return publishMessage(topicName, { parameters: message }, pubsub)\n}\n\n/**\n * Publish a message similar to a storage notification\n */\nexport const publishStorageMessage = async (\n objectId: string,\n bucketId: string,\n topicName: string,\n pubsub: PubSub,\n monitoringId?: string,\n): Promise<string> => {\n const message = {\n metadata: {\n monitoring_id: monitoringId\n }\n }\n const date = new Date()\n\n const attributes = {\n objectId,\n bucketId,\n eventTime: date.toISOString()\n }\n\n return publishMessage(topicName, message, pubsub, attributes)\n}\n\n/**\n * \n * @param schemaNameOrId : schema name or id\n * @param pubsub : pubsub client\n * @returns : schema definition Avro\n */\nexport const getSchema = async (schemaNameOrId: string, pubsub: PubSub): Promise<string | null | undefined> => {\n const schema = pubsub.schema(schemaNameOrId)\n const info = await schema.get()\n return info.definition\n}\n\n\n/**\n * Publish message with schema validation\n * \n * The schema will be retrieved from the topic metadata and validated\n */\nexport const publishAvroRecords = async (topicNameOrId : string, pubSubClient: PubSub, message: any): Promise<string> => {\n // Get the topic metadata to learn about its schema encoding.\n const topic = pubSubClient.topic(topicNameOrId)\n const [topicMetadata] = await topic.getMetadata()\n const topicSchemaMetadata = topicMetadata.schemaSettings\n\n if (!topicSchemaMetadata) {\n return Promise.reject(new Error(`Topic ${topicNameOrId} doesn't seem to have a schema.`))\n \n }\n const schemaEncoding = topicSchemaMetadata.encoding;\n\n // Make an encoder using the official avro-js library.\n const definition = await getSchema(topicSchemaMetadata?.schema ?? '', pubSubClient)\n const type = avro.parse(definition)\n\n \n let dataBuffer;\n switch (schemaEncoding) {\n case Encodings.Binary:\n dataBuffer = type.toBuffer(message)\n break\n case Encodings.Json:\n dataBuffer = Buffer.from(type.toString(message))\n break\n default:\n return Promise.reject(new Error(`Unknown schema encoding: ${schemaEncoding}`))\n }\n if (!dataBuffer) {\n return Promise.reject(new Error(`Invalid encoding ${schemaEncoding} on the topic.`))\n }\n\n const messageId = await topic.publishMessage({ data: dataBuffer })\n return messageId\n}"],"mappings":"umBAAA,IAAAA,EAAAC,EAAA,CAAAC,EAAAC,IAAA,CAEA,IAAIC,EAAS,QAAQ,QAAQ,EACzBC,EAASD,EAAO,OAGpB,SAASE,EAAWC,EAAKC,EAAK,CAC5B,QAASC,KAAOF,EACdC,EAAIC,CAAG,EAAIF,EAAIE,CAAG,CAEtB,CACIJ,EAAO,MAAQA,EAAO,OAASA,EAAO,aAAeA,EAAO,gBAC9DF,EAAO,QAAUC,GAGjBE,EAAUF,EAAQF,CAAO,EACzBA,EAAQ,OAASQ,GAGnB,SAASA,EAAYC,EAAKC,EAAkBC,EAAQ,CAClD,OAAOR,EAAOM,EAAKC,EAAkBC,CAAM,CAC7C,CAEAH,EAAW,UAAY,OAAO,OAAOL,EAAO,SAAS,EAGrDC,EAAUD,EAAQK,CAAU,EAE5BA,EAAW,KAAO,SAAUC,EAAKC,EAAkBC,EAAQ,CACzD,GAAI,OAAOF,GAAQ,SACjB,MAAM,IAAI,UAAU,+BAA+B,EAErD,OAAON,EAAOM,EAAKC,EAAkBC,CAAM,CAC7C,EAEAH,EAAW,MAAQ,SAAUI,EAAMC,EAAMC,EAAU,CACjD,GAAI,OAAOF,GAAS,SAClB,MAAM,IAAI,UAAU,2BAA2B,EAEjD,IAAIG,EAAMZ,EAAOS,CAAI,EACrB,OAAIC,IAAS,OACP,OAAOC,GAAa,SACtBC,EAAI,KAAKF,EAAMC,CAAQ,EAEvBC,EAAI,KAAKF,CAAI,EAGfE,EAAI,KAAK,CAAC,EAELA,CACT,EAEAP,EAAW,YAAc,SAAUI,EAAM,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ADEA,EAAO,OAAOa,CAAc,EACjB,IAAI,GAClB,WASDC,EAAqB,MAAOC,EAAwBC,EAAsBjB,IAAkC,CAEvH,IAAMkB,EAAQD,EAAa,MAAMD,CAAa,EACxC,CAACG,CAAa,EAAI,MAAMD,EAAM,YAAY,EAC1CE,EAAsBD,EAAc,eAE1C,GAAI,CAACC,EACH,OAAO,QAAQ,OAAO,IAAI,MAAM,SAASJ,CAAa,iCAAiC,CAAC,EAG1F,IAAMK,EAAiBD,EAAoB,SAGrCE,EAAa,MAAMT,EAAUO,GAAqB,QAAU,GAAIH,CAAY,EAC5EM,EAAY,QAAMD,CAAU,EAG9BnB,EACJ,OAAQkB,EAAgB,CACtB,KAAK,YAAU,OACblB,EAAaoB,EAAK,SAASvB,CAAO,EAClC,MACF,KAAK,YAAU,KACbG,EAAaT,EAAO,KAAK6B,EAAK,SAASvB,CAAO,CAAC,EAC/C,MACF,QACE,OAAO,QAAQ,OAAO,IAAI,MAAM,4BAA4BqB,CAAc,EAAE,CAAC,CACjF,CACA,OAAKlB,EAIa,MAAMe,EAAM,eAAe,CAAE,KAAMf,CAAW,CAAC,EAHxD,QAAQ,OAAO,IAAI,MAAM,oBAAoBkB,CAAc,gBAAgB,CAAC,CAKvF","names":["require_safe_buffer","__commonJSMin","exports","module","buffer","Buffer","copyProps","src","dst","key","SafeBuffer","arg","encodingOrOffset","length","size","fill","encoding","buf","src_exports","__export","getPubsubClient","googlePubsub","publishAvroRecords","publishMessage","publishProductFlowMonitoringMessage","publishStorageMessage","__toCommonJS","import_pubsub","avro","Buffer","getPubsubClient","gcpProject","serviceAccount","publishMessage","topicName","message","pubsub","attributes","dataBuffer","publishProductFlowMonitoringMessage","step","entityId","monitoringId","status","errorMessage","publishStorageMessage","objectId","bucketId","getSchema","schemaNameOrId","publishAvroRecords","topicNameOrId","pubSubClient","topic","topicMetadata","topicSchemaMetadata","schemaEncoding","definition","type"]}
@@ -0,0 +1,4 @@
1
+ import * as pubsub from '@google-cloud/pubsub';
2
+ export { pubsub as googlePubsub };
3
+ export { MonitoringMessage, getPubsubClient, publishAvroRecords, publishMessage, publishProductFlowMonitoringMessage, publishStorageMessage } from './pubsub.cjs';
4
+ import '@arcane-utils/types';
package/dist/pubsub.cjs CHANGED
@@ -1,4 +1,4 @@
1
- var B=Object.create;var m=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var _=Object.getPrototypeOf,T=Object.prototype.hasOwnProperty;var j=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),A=(e,t)=>{for(var r in t)m(e,r,{get:t[r],enumerable:!0})},y=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of x(t))!T.call(e,o)&&o!==r&&m(e,o,{get:()=>t[o],enumerable:!(n=E(t,o))||n.enumerable});return e};var U=(e,t,r)=>(r=e!=null?B(_(e)):{},y(t||!e||!e.__esModule?m(r,"default",{value:e,enumerable:!0}):r,e)),I=e=>y(m({},"__esModule",{value:!0}),e);var S=j((p,h)=>{var b=require("buffer"),s=b.Buffer;function w(e,t){for(var r in e)t[r]=e[r]}s.from&&s.alloc&&s.allocUnsafe&&s.allocUnsafeSlow?h.exports=b:(w(b,p),p.Buffer=u);function u(e,t,r){return s(e,t,r)}u.prototype=Object.create(s.prototype);w(s,u);u.from=function(e,t,r){if(typeof e=="number")throw new TypeError("Argument must not be a number");return s(e,t,r)};u.alloc=function(e,t,r){if(typeof e!="number")throw new TypeError("Argument must be a number");var n=s(e);return t!==void 0?typeof r=="string"?n.fill(t,r):n.fill(t):n.fill(0),n};u.allocUnsafe=function(e){if(typeof e!="number")throw new TypeError("Argument must be a number");return s(e)};u.allocUnsafeSlow=function(e){if(typeof e!="number")throw new TypeError("Argument must be a number");return b.SlowBuffer(e)}});var J={};A(J,{getPubsubClient:()=>k,getSchema:()=>v,publishAvroRecords:()=>F,publishMessage:()=>l,publishProductFlowMonitoringMessage:()=>$,publishStorageMessage:()=>q});module.exports=I(J);var f=require("@google-cloud/pubsub"),P=U(require("avro-js"),1),{Buffer:M}=S(),k=(e,t)=>new f.PubSub({projectId:e,keyFilename:t}),l=async(e,t,r,n)=>{let o=M.from(JSON.stringify(t));return r.topic(e).publish(o,n)},$=async(e,t,r,n,o,i,a)=>{let c={entity_id:t,status:n,monitoring_id:r,step:e};return a&&(c.error_message=a),l(o,{parameters:c},i)},q=async(e,t,r,n,o)=>{let i={metadata:{monitoring_id:o}},c={objectId:e,bucketId:t,eventTime:new Date().toISOString()};return l(r,i,n,c)},v=async(e,t)=>(await t.schema(e).get()).definition,F=async(e,t,r)=>{let n=t.topic(e),[o]=await n.getMetadata(),i=o.schemaSettings;if(!i)return Promise.reject(new Error(`Topic ${e} doesn't seem to have a schema.`));let a=i.encoding,c=await v((i==null?void 0:i.schema)??"",t),d=P.parse(c),g;switch(a){case f.Encodings.Binary:g=d.toBuffer(r);break;case f.Encodings.Json:g=M.from(d.toString(r));break;default:return Promise.reject(new Error(`Unknown schema encoding: ${a}`))}return g?await n.publishMessage({data:g}):Promise.reject(new Error(`Invalid encoding ${a} on the topic.`))};0&&(module.exports={getPubsubClient,getSchema,publishAvroRecords,publishMessage,publishProductFlowMonitoringMessage,publishStorageMessage});
1
+ var B=Object.create;var g=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var _=Object.getPrototypeOf,T=Object.prototype.hasOwnProperty;var j=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),A=(e,t)=>{for(var r in t)g(e,r,{get:t[r],enumerable:!0})},y=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of x(t))!T.call(e,o)&&o!==r&&g(e,o,{get:()=>t[o],enumerable:!(n=E(t,o))||n.enumerable});return e};var U=(e,t,r)=>(r=e!=null?B(_(e)):{},y(t||!e||!e.__esModule?g(r,"default",{value:e,enumerable:!0}):r,e)),I=e=>y(g({},"__esModule",{value:!0}),e);var S=j((b,w)=>{var p=require("buffer"),s=p.Buffer;function h(e,t){for(var r in e)t[r]=e[r]}s.from&&s.alloc&&s.allocUnsafe&&s.allocUnsafeSlow?w.exports=p:(h(p,b),b.Buffer=u);function u(e,t,r){return s(e,t,r)}u.prototype=Object.create(s.prototype);h(s,u);u.from=function(e,t,r){if(typeof e=="number")throw new TypeError("Argument must not be a number");return s(e,t,r)};u.alloc=function(e,t,r){if(typeof e!="number")throw new TypeError("Argument must be a number");var n=s(e);return t!==void 0?typeof r=="string"?n.fill(t,r):n.fill(t):n.fill(0),n};u.allocUnsafe=function(e){if(typeof e!="number")throw new TypeError("Argument must be a number");return s(e)};u.allocUnsafeSlow=function(e){if(typeof e!="number")throw new TypeError("Argument must be a number");return p.SlowBuffer(e)}});var J={};A(J,{getPubsubClient:()=>k,getSchema:()=>v,publishAvroRecords:()=>F,publishMessage:()=>l,publishProductFlowMonitoringMessage:()=>$,publishStorageMessage:()=>q});module.exports=I(J);var f=require("@google-cloud/pubsub"),P=U(require("avro-js"),1),{Buffer:M}=S(),k=(e,t)=>new f.PubSub({projectId:e,keyFilename:t}),l=async(e,t,r,n)=>{let o=M.from(JSON.stringify(t));return r.topic(e).publish(o,n)},$=async(e,t,r,n,o,i,a)=>{let c={entity_id:t,status:n,monitoring_id:r,step:e};return a&&(c.error_message=a),l(o,{parameters:c},i)},q=async(e,t,r,n,o)=>{let i={metadata:{monitoring_id:o}},c={objectId:e,bucketId:t,eventTime:new Date().toISOString()};return l(r,i,n,c)},v=async(e,t)=>(await t.schema(e).get()).definition,F=async(e,t,r)=>{let n=t.topic(e),[o]=await n.getMetadata(),i=o.schemaSettings;if(!i)return Promise.reject(new Error(`Topic ${e} doesn't seem to have a schema.`));let a=i.encoding,c=await v(i?.schema??"",t),d=P.parse(c),m;switch(a){case f.Encodings.Binary:m=d.toBuffer(r);break;case f.Encodings.Json:m=M.from(d.toString(r));break;default:return Promise.reject(new Error(`Unknown schema encoding: ${a}`))}return m?await n.publishMessage({data:m}):Promise.reject(new Error(`Invalid encoding ${a} on the topic.`))};0&&(module.exports={getPubsubClient,getSchema,publishAvroRecords,publishMessage,publishProductFlowMonitoringMessage,publishStorageMessage});
2
2
  /*! Bundled license information:
3
3
 
4
4
  safe-buffer/index.js:
@@ -1 +1 @@
1
- {"version":3,"sources":["../node_modules/safe-buffer/index.js","../src/pubsub.ts"],"sourcesContent":["/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */\n/* eslint-disable node/no-deprecated-api */\nvar buffer = require('buffer')\nvar Buffer = buffer.Buffer\n\n// alternative to using Object.keys for old browsers\nfunction copyProps (src, dst) {\n for (var key in src) {\n dst[key] = src[key]\n }\n}\nif (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) {\n module.exports = buffer\n} else {\n // Copy properties from require('buffer')\n copyProps(buffer, exports)\n exports.Buffer = SafeBuffer\n}\n\nfunction SafeBuffer (arg, encodingOrOffset, length) {\n return Buffer(arg, encodingOrOffset, length)\n}\n\nSafeBuffer.prototype = Object.create(Buffer.prototype)\n\n// Copy static methods from Buffer\ncopyProps(Buffer, SafeBuffer)\n\nSafeBuffer.from = function (arg, encodingOrOffset, length) {\n if (typeof arg === 'number') {\n throw new TypeError('Argument must not be a number')\n }\n return Buffer(arg, encodingOrOffset, length)\n}\n\nSafeBuffer.alloc = function (size, fill, encoding) {\n if (typeof size !== 'number') {\n throw new TypeError('Argument must be a number')\n }\n var buf = Buffer(size)\n if (fill !== undefined) {\n if (typeof encoding === 'string') {\n buf.fill(fill, encoding)\n } else {\n buf.fill(fill)\n }\n } else {\n buf.fill(0)\n }\n return buf\n}\n\nSafeBuffer.allocUnsafe = function (size) {\n if (typeof size !== 'number') {\n throw new TypeError('Argument must be a number')\n }\n return Buffer(size)\n}\n\nSafeBuffer.allocUnsafeSlow = function (size) {\n if (typeof size !== 'number') {\n throw new TypeError('Argument must be a number')\n }\n return buffer.SlowBuffer(size)\n}\n","import { PubSub, Encodings } from '@google-cloud/pubsub'\nimport { MonitoringStatus } from '@arcane-utils/types'\nimport * as avro from 'avro-js';\n\nconst {Buffer} = require('safe-buffer')\n\nexport interface MonitoringMessage {\n entity_id: number,\n status: MonitoringStatus,\n monitoring_id: string,\n step: string,\n error_message?: string\n}\n\n/**\n * Get PubSub client.\n *\n * To be used in Cloud Functions because of an issue with global declaration of clients.\n */\nexport const getPubsubClient = (gcpProject: string, serviceAccount: string): PubSub => {\n return new PubSub({\n projectId: gcpProject,\n keyFilename: serviceAccount\n })\n}\n\n/**\n * Publish a message on PubSub.\n*/\nexport const publishMessage = async (topicName: string, message: any, pubsub: PubSub, attributes?: any): Promise<string> => {\n const dataBuffer = Buffer.from(JSON.stringify(message))\n return pubsub.topic(topicName).publish(dataBuffer, attributes)\n}\n\n/**\n * Publish a message for Product Flow monitoring\n*/\nexport const publishProductFlowMonitoringMessage = async (\n step: string,\n entityId: number,\n monitoringId: string,\n status: MonitoringStatus,\n topicName: string,\n pubsub: PubSub,\n errorMessage?: string\n): Promise<string> => {\n const message: MonitoringMessage = {\n entity_id: entityId,\n status,\n monitoring_id: monitoringId,\n step\n }\n if (errorMessage) {\n message.error_message = errorMessage\n }\n return publishMessage(topicName, { parameters: message }, pubsub)\n}\n\n/**\n * Publish a message similar to a storage notification\n */\nexport const publishStorageMessage = async (\n objectId: string,\n bucketId: string,\n topicName: string,\n pubsub: PubSub,\n monitoringId?: string,\n): Promise<string> => {\n const message = {\n metadata: {\n monitoring_id: monitoringId\n }\n }\n const date = new Date()\n\n const attributes = {\n objectId,\n bucketId,\n eventTime: date.toISOString()\n }\n\n return publishMessage(topicName, message, pubsub, attributes)\n}\n\n/**\n * \n * @param schemaNameOrId : schema name or id\n * @param pubsub : pubsub client\n * @returns : schema definition Avro\n */\nexport const getSchema = async (schemaNameOrId: string, pubsub: PubSub): Promise<string | null | undefined> => {\n const schema = pubsub.schema(schemaNameOrId)\n const info = await schema.get()\n return info.definition\n}\n\n\n/**\n * Publish message with schema validation\n * \n * The schema will be retrieved from the topic metadata and validated\n */\nexport const publishAvroRecords = async (topicNameOrId : string, pubSubClient: PubSub, message: any): Promise<string> => {\n // Get the topic metadata to learn about its schema encoding.\n const topic = pubSubClient.topic(topicNameOrId)\n const [topicMetadata] = await topic.getMetadata()\n const topicSchemaMetadata = topicMetadata.schemaSettings\n\n if (!topicSchemaMetadata) {\n return Promise.reject(new Error(`Topic ${topicNameOrId} doesn't seem to have a schema.`))\n \n }\n const schemaEncoding = topicSchemaMetadata.encoding;\n\n // Make an encoder using the official avro-js library.\n const definition = await getSchema(topicSchemaMetadata?.schema ?? '', pubSubClient)\n const type = avro.parse(definition)\n\n \n let dataBuffer;\n switch (schemaEncoding) {\n case Encodings.Binary:\n dataBuffer = type.toBuffer(message)\n break\n case Encodings.Json:\n dataBuffer = Buffer.from(type.toString(message))\n break\n default:\n return Promise.reject(new Error(`Unknown schema encoding: ${schemaEncoding}`))\n }\n if (!dataBuffer) {\n return Promise.reject(new Error(`Invalid encoding ${schemaEncoding} on the topic.`))\n }\n\n const messageId = await topic.publishMessage({ data: dataBuffer })\n return messageId\n}"],"mappings":"umBAAA,IAAAA,EAAAC,EAAA,CAAAC,EAAAC,IAAA,CAEA,IAAIC,EAAS,QAAQ,QAAQ,EACzBC,EAASD,EAAO,OAGpB,SAASE,EAAWC,EAAKC,EAAK,CAC5B,QAASC,KAAOF,EACdC,EAAIC,CAAG,EAAIF,EAAIE,CAAG,CAEtB,CACIJ,EAAO,MAAQA,EAAO,OAASA,EAAO,aAAeA,EAAO,gBAC9DF,EAAO,QAAUC,GAGjBE,EAAUF,EAAQF,CAAO,EACzBA,EAAQ,OAASQ,GAGnB,SAASA,EAAYC,EAAKC,EAAkBC,EAAQ,CAClD,OAAOR,EAAOM,EAAKC,EAAkBC,CAAM,CAC7C,CAEAH,EAAW,UAAY,OAAO,OAAOL,EAAO,SAAS,EAGrDC,EAAUD,EAAQK,CAAU,EAE5BA,EAAW,KAAO,SAAUC,EAAKC,EAAkBC,EAAQ,CACzD,GAAI,OAAOF,GAAQ,SACj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AII,IACFR,EAAQ,cAAgBQ,GAEnBlB,EAAeS,EAAW,CAAE,WAAYC,CAAQ,EAAGC,CAAM,CAClE,EAKaT,EAAwB,MACnCiB,EACAC,EACAX,EACAE,EACAK,IACoB,CACpB,IAAMN,EAAU,CACd,SAAU,CACR,cAAeM,CACjB,CACF,EAGMJ,EAAa,CACjB,SAAAO,EACA,SAAAC,EACA,UALW,IAAI,KAAK,EAKJ,YAAY,CAC9B,EAEA,OAAOpB,EAAeS,EAAWC,EAASC,EAAQC,CAAU,CAC9D,EAQad,EAAY,MAAOuB,EAAwBV,KAEzC,MADEA,EAAO,OAAOU,CAAc,EACjB,IAAI,GAClB,WASDtB,EAAqB,MAAOuB,EAAwBC,EAAsBb,IAAkC,CAEvH,IAAMc,EAAQD,EAAa,MAAMD,CAAa,EACxC,CAACG,CAAa,EAAI,MAAMD,EAAM,YAAY,EAC1CE,EAAsBD,EAAc,eAE1C,GAAI,CAACC,EACH,OAAO,QAAQ,OAAO,IAAI,MAAM,SAASJ,CAAa,iCAAiC,CAAC,EAG1F,IAAMK,EAAiBD,EAAoB,SAGrCE,EAAa,MAAM9B,GAAU4B,GAAA,YAAAA,EAAqB,SAAU,GAAIH,CAAY,EAC5EM,EAAY,QAAMD,CAAU,EAG9Bf,EACJ,OAAQc,EAAgB,CACtB,KAAK,YAAU,OACbd,EAAagB,EAAK,SAASnB,CAAO,EAClC,MACF,KAAK,YAAU,KACbG,EAAaP,EAAO,KAAKuB,EAAK,SAASnB,CAAO,CAAC,EAC/C,MACF,QACE,OAAO,QAAQ,OAAO,IAAI,MAAM,4BAA4BiB,CAAc,EAAE,CAAC,CACjF,CACA,OAAKd,EAIa,MAAMW,EAAM,eAAe,CAAE,KAAMX,CAAW,CAAC,EAHxD,QAAQ,OAAO,IAAI,MAAM,oBAAoBc,CAAc,gBAAgB,CAAC,CAKvF","names":["require_safe_buffer","__commonJSMin","exports","module","buffer","Buffer","copyProps","src","dst","key","SafeBuffer","arg","encodingOrOffset","length","size","fill","encoding","buf","pubsub_exports","__export","getPubsubClient","getSchema","publishAvroRecords","publishMessage","publishProductFlowMonitoringMessage","publishStorageMessage","__toCommonJS","import_pubsub","avro","Buffer","gcpProject","serviceAccount","topicName","message","pubsub","attributes","dataBuffer","step","entityId","monitoringId","status","errorMessage","objectId","bucketId","schemaNameOrId","topicNameOrId","pubSubClient","topic","topicMetadata","topicSchemaMetadata","schemaEncoding","definition","type"]}
1
+ {"version":3,"sources":["../node_modules/safe-buffer/index.js","../src/pubsub.ts"],"sourcesContent":["/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */\n/* eslint-disable node/no-deprecated-api */\nvar buffer = require('buffer')\nvar Buffer = buffer.Buffer\n\n// alternative to using Object.keys for old browsers\nfunction copyProps (src, dst) {\n for (var key in src) {\n dst[key] = src[key]\n }\n}\nif (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) {\n module.exports = buffer\n} else {\n // Copy properties from require('buffer')\n copyProps(buffer, exports)\n exports.Buffer = SafeBuffer\n}\n\nfunction SafeBuffer (arg, encodingOrOffset, length) {\n return Buffer(arg, encodingOrOffset, length)\n}\n\nSafeBuffer.prototype = Object.create(Buffer.prototype)\n\n// Copy static methods from Buffer\ncopyProps(Buffer, SafeBuffer)\n\nSafeBuffer.from = function (arg, encodingOrOffset, length) {\n if (typeof arg === 'number') {\n throw new TypeError('Argument must not be a number')\n }\n return Buffer(arg, encodingOrOffset, length)\n}\n\nSafeBuffer.alloc = function (size, fill, encoding) {\n if (typeof size !== 'number') {\n throw new TypeError('Argument must be a number')\n }\n var buf = Buffer(size)\n if (fill !== undefined) {\n if (typeof encoding === 'string') {\n buf.fill(fill, encoding)\n } else {\n buf.fill(fill)\n }\n } else {\n buf.fill(0)\n }\n return buf\n}\n\nSafeBuffer.allocUnsafe = function (size) {\n if (typeof size !== 'number') {\n throw new TypeError('Argument must be a number')\n }\n return Buffer(size)\n}\n\nSafeBuffer.allocUnsafeSlow = function (size) {\n if (typeof size !== 'number') {\n throw new TypeError('Argument must be a number')\n }\n return buffer.SlowBuffer(size)\n}\n","import { PubSub, Encodings } from '@google-cloud/pubsub'\nimport { MonitoringStatus } from '@arcane-utils/types'\nimport * as avro from 'avro-js';\n\nconst {Buffer} = require('safe-buffer')\n\nexport interface MonitoringMessage {\n entity_id: number,\n status: MonitoringStatus,\n monitoring_id: string,\n step: string,\n error_message?: string\n}\n\n/**\n * Get PubSub client.\n *\n * To be used in Cloud Functions because of an issue with global declaration of clients.\n */\nexport const getPubsubClient = (gcpProject: string, serviceAccount: string): PubSub => {\n return new PubSub({\n projectId: gcpProject,\n keyFilename: serviceAccount\n })\n}\n\n/**\n * Publish a message on PubSub.\n*/\nexport const publishMessage = async (topicName: string, message: any, pubsub: PubSub, attributes?: any): Promise<string> => {\n const dataBuffer = Buffer.from(JSON.stringify(message))\n return pubsub.topic(topicName).publish(dataBuffer, attributes)\n}\n\n/**\n * Publish a message for Product Flow monitoring\n*/\nexport const publishProductFlowMonitoringMessage = async (\n step: string,\n entityId: number,\n monitoringId: string,\n status: MonitoringStatus,\n topicName: string,\n pubsub: PubSub,\n errorMessage?: string\n): Promise<string> => {\n const message: MonitoringMessage = {\n entity_id: entityId,\n status,\n monitoring_id: monitoringId,\n step\n }\n if (errorMessage) {\n message.error_message = errorMessage\n }\n return publishMessage(topicName, { parameters: message }, pubsub)\n}\n\n/**\n * Publish a message similar to a storage notification\n */\nexport const publishStorageMessage = async (\n objectId: string,\n bucketId: string,\n topicName: string,\n pubsub: PubSub,\n monitoringId?: string,\n): Promise<string> => {\n const message = {\n metadata: {\n monitoring_id: monitoringId\n }\n }\n const date = new Date()\n\n const attributes = {\n objectId,\n bucketId,\n eventTime: date.toISOString()\n }\n\n return publishMessage(topicName, message, pubsub, attributes)\n}\n\n/**\n * \n * @param schemaNameOrId : schema name or id\n * @param pubsub : pubsub client\n * @returns : schema definition Avro\n */\nexport const getSchema = async (schemaNameOrId: string, pubsub: PubSub): Promise<string | null | undefined> => {\n const schema = pubsub.schema(schemaNameOrId)\n const info = await schema.get()\n return info.definition\n}\n\n\n/**\n * Publish message with schema validation\n * \n * The schema will be retrieved from the topic metadata and validated\n */\nexport const publishAvroRecords = async (topicNameOrId : string, pubSubClient: PubSub, message: any): Promise<string> => {\n // Get the topic metadata to learn about its schema encoding.\n const topic = pubSubClient.topic(topicNameOrId)\n const [topicMetadata] = await topic.getMetadata()\n const topicSchemaMetadata = topicMetadata.schemaSettings\n\n if (!topicSchemaMetadata) {\n return Promise.reject(new Error(`Topic ${topicNameOrId} doesn't seem to have a schema.`))\n \n }\n const schemaEncoding = topicSchemaMetadata.encoding;\n\n // Make an encoder using the official avro-js library.\n const definition = await getSchema(topicSchemaMetadata?.schema ?? '', pubSubClient)\n const type = avro.parse(definition)\n\n \n let dataBuffer;\n switch (schemaEncoding) {\n case Encodings.Binary:\n dataBuffer = type.toBuffer(message)\n break\n case Encodings.Json:\n dataBuffer = Buffer.from(type.toString(message))\n break\n default:\n return Promise.reject(new Error(`Unknown schema encoding: ${schemaEncoding}`))\n }\n if (!dataBuffer) {\n return Promise.reject(new Error(`Invalid encoding ${schemaEncoding} on the topic.`))\n }\n\n const messageId = await topic.publishMessage({ data: dataBuffer })\n return messageId\n}"],"mappings":"umBAAA,IAAAA,EAAAC,EAAA,CAAAC,EAAAC,IAAA,CAEA,IAAIC,EAAS,QAAQ,QAAQ,EACzBC,EAASD,EAAO,OAGpB,SAASE,EAAWC,EAAKC,EAAK,CAC5B,QAASC,KAAOF,EACdC,EAAIC,CAAG,EAAIF,EAAIE,CAAG,CAEtB,CACIJ,EAAO,MAAQA,EAAO,OAASA,EAAO,aAAeA,EAAO,gBAC9DF,EAAO,QAAUC,GAGjBE,EAAUF,EAAQF,CAAO,EACzBA,EAAQ,OAASQ,GAGnB,SAASA,EAAYC,EAAKC,EAAkBC,EAAQ,CAClD,OAAOR,EAAOM,EAAKC,EAAkBC,CAAM,CAC7C,CAEAH,EAAW,UAAY,OAA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AAoBc,CAAc,gBAAgB,CAAC,CAKvF","names":["require_safe_buffer","__commonJSMin","exports","module","buffer","Buffer","copyProps","src","dst","key","SafeBuffer","arg","encodingOrOffset","length","size","fill","encoding","buf","pubsub_exports","__export","getPubsubClient","getSchema","publishAvroRecords","publishMessage","publishProductFlowMonitoringMessage","publishStorageMessage","__toCommonJS","import_pubsub","avro","Buffer","gcpProject","serviceAccount","topicName","message","pubsub","attributes","dataBuffer","step","entityId","monitoringId","status","errorMessage","objectId","bucketId","schemaNameOrId","topicNameOrId","pubSubClient","topic","topicMetadata","topicSchemaMetadata","schemaEncoding","definition","type"]}
@@ -0,0 +1,43 @@
1
+ import { PubSub } from '@google-cloud/pubsub';
2
+ import { MonitoringStatus } from '@arcane-utils/types';
3
+
4
+ interface MonitoringMessage {
5
+ entity_id: number;
6
+ status: MonitoringStatus;
7
+ monitoring_id: string;
8
+ step: string;
9
+ error_message?: string;
10
+ }
11
+ /**
12
+ * Get PubSub client.
13
+ *
14
+ * To be used in Cloud Functions because of an issue with global declaration of clients.
15
+ */
16
+ declare const getPubsubClient: (gcpProject: string, serviceAccount: string) => PubSub;
17
+ /**
18
+ * Publish a message on PubSub.
19
+ */
20
+ declare const publishMessage: (topicName: string, message: any, pubsub: PubSub, attributes?: any) => Promise<string>;
21
+ /**
22
+ * Publish a message for Product Flow monitoring
23
+ */
24
+ declare const publishProductFlowMonitoringMessage: (step: string, entityId: number, monitoringId: string, status: MonitoringStatus, topicName: string, pubsub: PubSub, errorMessage?: string) => Promise<string>;
25
+ /**
26
+ * Publish a message similar to a storage notification
27
+ */
28
+ declare const publishStorageMessage: (objectId: string, bucketId: string, topicName: string, pubsub: PubSub, monitoringId?: string) => Promise<string>;
29
+ /**
30
+ *
31
+ * @param schemaNameOrId : schema name or id
32
+ * @param pubsub : pubsub client
33
+ * @returns : schema definition Avro
34
+ */
35
+ declare const getSchema: (schemaNameOrId: string, pubsub: PubSub) => Promise<string | null | undefined>;
36
+ /**
37
+ * Publish message with schema validation
38
+ *
39
+ * The schema will be retrieved from the topic metadata and validated
40
+ */
41
+ declare const publishAvroRecords: (topicNameOrId: string, pubSubClient: PubSub, message: any) => Promise<string>;
42
+
43
+ export { type MonitoringMessage, getPubsubClient, getSchema, publishAvroRecords, publishMessage, publishProductFlowMonitoringMessage, publishStorageMessage };
package/package.json CHANGED
@@ -1,11 +1,10 @@
1
1
  {
2
2
  "name": "@arcane-utils/pubsub",
3
- "version": "1.2.3",
3
+ "version": "1.2.5",
4
4
  "description": "PubSub helper functions.",
5
5
  "type": "module",
6
- "main": "./dist/index.js",
7
- "module": "./dist/index.mjs",
8
- "types": "./dist/index.d.ts",
6
+ "main": "./dist/index.cjs",
7
+ "types": "./dist/index.d.cts",
9
8
  "files": [
10
9
  "dist"
11
10
  ],
@@ -28,8 +27,8 @@
28
27
  },
29
28
  "tsup": {
30
29
  "entry": ["./src/index.ts"],
31
- "format": ["cjs", "esm"],
32
- "dts": false,
30
+ "format": ["cjs"],
31
+ "dts": true,
33
32
  "splitting": false,
34
33
  "sourcemap": true,
35
34
  "clean": true,
@@ -38,7 +37,7 @@
38
37
  "keywords": [
39
38
  "arcane",
40
39
  "utils",
41
- "storage"
40
+ "pubsub"
42
41
  ],
43
42
  "dependencies": {
44
43
  "@arcane-utils/types": "1.2.17",
package/dist/avro.d.cjs DELETED
@@ -1 +0,0 @@
1
- //# sourceMappingURL=avro.d.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/dist/avro.d.js DELETED
@@ -1 +0,0 @@
1
- //# sourceMappingURL=avro.d.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/dist/index.js DELETED
@@ -1,7 +0,0 @@
1
- var S=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(r,t)=>(typeof require<"u"?require:r)[t]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var M=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports);var h=M((m,d)=>{var g=S("buffer"),o=g.Buffer;function l(e,r){for(var t in e)r[t]=e[t]}o.from&&o.alloc&&o.allocUnsafe&&o.allocUnsafeSlow?d.exports=g:(l(g,m),m.Buffer=u);function u(e,r,t){return o(e,r,t)}u.prototype=Object.create(o.prototype);l(o,u);u.from=function(e,r,t){if(typeof e=="number")throw new TypeError("Argument must not be a number");return o(e,r,t)};u.alloc=function(e,r,t){if(typeof e!="number")throw new TypeError("Argument must be a number");var n=o(e);return r!==void 0?typeof t=="string"?n.fill(r,t):n.fill(r):n.fill(0),n};u.allocUnsafe=function(e){if(typeof e!="number")throw new TypeError("Argument must be a number");return o(e)};u.allocUnsafeSlow=function(e){if(typeof e!="number")throw new TypeError("Argument must be a number");return g.SlowBuffer(e)}});import*as F from"@google-cloud/pubsub";import{PubSub as v,Encodings as y}from"@google-cloud/pubsub";import*as w from"avro-js";var{Buffer:P}=h(),x=(e,r)=>new v({projectId:e,keyFilename:r}),b=async(e,r,t,n)=>{let i=P.from(JSON.stringify(r));return t.topic(e).publish(i,n)},B=async(e,r,t,n,i,s,a)=>{let c={entity_id:r,status:n,monitoring_id:t,step:e};return a&&(c.error_message=a),b(i,{parameters:c},s)},E=async(e,r,t,n,i)=>{let s={metadata:{monitoring_id:i}},c={objectId:e,bucketId:r,eventTime:new Date().toISOString()};return b(t,s,n,c)},_=async(e,r)=>(await r.schema(e).get()).definition,A=async(e,r,t)=>{let n=r.topic(e),[i]=await n.getMetadata(),s=i.schemaSettings;if(!s)return Promise.reject(new Error(`Topic ${e} doesn't seem to have a schema.`));let a=s.encoding,c=await _((s==null?void 0:s.schema)??"",r),p=w.parse(c),f;switch(a){case y.Binary:f=p.toBuffer(t);break;case y.Json:f=P.from(p.toString(t));break;default:return Promise.reject(new Error(`Unknown schema encoding: ${a}`))}return f?await n.publishMessage({data:f}):Promise.reject(new Error(`Invalid encoding ${a} on the topic.`))};export{x as getPubsubClient,F as googlePubsub,A as publishAvroRecords,b as publishMessage,B as publishProductFlowMonitoringMessage,E as publishStorageMessage};
2
- /*! Bundled license information:
3
-
4
- safe-buffer/index.js:
5
- (*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> *)
6
- */
7
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../node_modules/safe-buffer/index.js","../src/index.ts","../src/pubsub.ts"],"sourcesContent":["/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */\n/* eslint-disable node/no-deprecated-api */\nvar buffer = require('buffer')\nvar Buffer = buffer.Buffer\n\n// alternative to using Object.keys for old browsers\nfunction copyProps (src, dst) {\n for (var key in src) {\n dst[key] = src[key]\n }\n}\nif (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) {\n module.exports = buffer\n} else {\n // Copy properties from require('buffer')\n copyProps(buffer, exports)\n exports.Buffer = SafeBuffer\n}\n\nfunction SafeBuffer (arg, encodingOrOffset, length) {\n return Buffer(arg, encodingOrOffset, length)\n}\n\nSafeBuffer.prototype = Object.create(Buffer.prototype)\n\n// Copy static methods from Buffer\ncopyProps(Buffer, SafeBuffer)\n\nSafeBuffer.from = function (arg, encodingOrOffset, length) {\n if (typeof arg === 'number') {\n throw new TypeError('Argument must not be a number')\n }\n return Buffer(arg, encodingOrOffset, length)\n}\n\nSafeBuffer.alloc = function (size, fill, encoding) {\n if (typeof size !== 'number') {\n throw new TypeError('Argument must be a number')\n }\n var buf = Buffer(size)\n if (fill !== undefined) {\n if (typeof encoding === 'string') {\n buf.fill(fill, encoding)\n } else {\n buf.fill(fill)\n }\n } else {\n buf.fill(0)\n }\n return buf\n}\n\nSafeBuffer.allocUnsafe = function (size) {\n if (typeof size !== 'number') {\n throw new TypeError('Argument must be a number')\n }\n return Buffer(size)\n}\n\nSafeBuffer.allocUnsafeSlow = function (size) {\n if (typeof size !== 'number') {\n throw new TypeError('Argument must be a number')\n }\n return buffer.SlowBuffer(size)\n}\n","export * as googlePubsub from '@google-cloud/pubsub'\nexport {\n MonitoringMessage,\n getPubsubClient,\n publishMessage,\n publishProductFlowMonitoringMessage,\n publishStorageMessage,\n publishAvroRecords\n} from './pubsub';\n","import { PubSub, Encodings } from '@google-cloud/pubsub'\nimport { MonitoringStatus } from '@arcane-utils/types'\nimport * as avro from 'avro-js';\n\nconst {Buffer} = require('safe-buffer')\n\nexport interface MonitoringMessage {\n entity_id: number,\n status: MonitoringStatus,\n monitoring_id: string,\n step: string,\n error_message?: string\n}\n\n/**\n * Get PubSub client.\n *\n * To be used in Cloud Functions because of an issue with global declaration of clients.\n */\nexport const getPubsubClient = (gcpProject: string, serviceAccount: string): PubSub => {\n return new PubSub({\n projectId: gcpProject,\n keyFilename: serviceAccount\n })\n}\n\n/**\n * Publish a message on PubSub.\n*/\nexport const publishMessage = async (topicName: string, message: any, pubsub: PubSub, attributes?: any): Promise<string> => {\n const dataBuffer = Buffer.from(JSON.stringify(message))\n return pubsub.topic(topicName).publish(dataBuffer, attributes)\n}\n\n/**\n * Publish a message for Product Flow monitoring\n*/\nexport const publishProductFlowMonitoringMessage = async (\n step: string,\n entityId: number,\n monitoringId: string,\n status: MonitoringStatus,\n topicName: string,\n pubsub: PubSub,\n errorMessage?: string\n): Promise<string> => {\n const message: MonitoringMessage = {\n entity_id: entityId,\n status,\n monitoring_id: monitoringId,\n step\n }\n if (errorMessage) {\n message.error_message = errorMessage\n }\n return publishMessage(topicName, { parameters: message }, pubsub)\n}\n\n/**\n * Publish a message similar to a storage notification\n */\nexport const publishStorageMessage = async (\n objectId: string,\n bucketId: string,\n topicName: string,\n pubsub: PubSub,\n monitoringId?: string,\n): Promise<string> => {\n const message = {\n metadata: {\n monitoring_id: monitoringId\n }\n }\n const date = new Date()\n\n const attributes = {\n objectId,\n bucketId,\n eventTime: date.toISOString()\n }\n\n return publishMessage(topicName, message, pubsub, attributes)\n}\n\n/**\n * \n * @param schemaNameOrId : schema name or id\n * @param pubsub : pubsub client\n * @returns : schema definition Avro\n */\nexport const getSchema = async (schemaNameOrId: string, pubsub: PubSub): Promise<string | null | undefined> => {\n const schema = pubsub.schema(schemaNameOrId)\n const info = await schema.get()\n return info.definition\n}\n\n\n/**\n * Publish message with schema validation\n * \n * The schema will be retrieved from the topic metadata and validated\n */\nexport const publishAvroRecords = async (topicNameOrId : string, pubSubClient: PubSub, message: any): Promise<string> => {\n // Get the topic metadata to learn about its schema encoding.\n const topic = pubSubClient.topic(topicNameOrId)\n const [topicMetadata] = await topic.getMetadata()\n const topicSchemaMetadata = topicMetadata.schemaSettings\n\n if (!topicSchemaMetadata) {\n return Promise.reject(new Error(`Topic ${topicNameOrId} doesn't seem to have a schema.`))\n \n }\n const schemaEncoding = topicSchemaMetadata.encoding;\n\n // Make an encoder using the official avro-js library.\n const definition = await getSchema(topicSchemaMetadata?.schema ?? '', pubSubClient)\n const type = avro.parse(definition)\n\n \n let dataBuffer;\n switch (schemaEncoding) {\n case Encodings.Binary:\n dataBuffer = type.toBuffer(message)\n break\n case Encodings.Json:\n dataBuffer = Buffer.from(type.toString(message))\n break\n default:\n return Promise.reject(new Error(`Unknown schema encoding: ${schemaEncoding}`))\n }\n if (!dataBuffer) {\n return Promise.reject(new Error(`Invalid encoding ${schemaEncoding} on the topic.`))\n }\n\n const messageId = await topic.publishMessage({ data: dataBuffer })\n return messageId\n}"],"mappings":"uTAAA,IAAAA,EAAAC,EAAA,CAAAC,EAAAC,IAAA,CAEA,IAAIC,EAAS,EAAQ,QAAQ,EACzBC,EAASD,EAAO,OAGpB,SAASE,EAAWC,EAAKC,EAAK,CAC5B,QAASC,KAAOF,EACdC,EAAIC,CAAG,EAAIF,EAAIE,CAAG,CAEtB,CACIJ,EAAO,MAAQA,EAAO,OAASA,EAAO,aAAeA,EAAO,gBAC9DF,EAAO,QAAUC,GAGjBE,EAAUF,EAAQF,CAAO,EACzBA,EAAQ,OAASQ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AW,CAAC,EAHxD,QAAQ,OAAO,IAAI,MAAM,oBAAoBkB,CAAc,gBAAgB,CAAC,CAKvF","names":["require_safe_buffer","__commonJSMin","exports","module","buffer","Buffer","copyProps","src","dst","key","SafeBuffer","arg","encodingOrOffset","length","size","fill","encoding","buf","googlePubsub","PubSub","Encodings","avro","Buffer","getPubsubClient","gcpProject","serviceAccount","publishMessage","topicName","message","pubsub","attributes","dataBuffer","publishProductFlowMonitoringMessage","step","entityId","monitoringId","status","errorMessage","publishStorageMessage","objectId","bucketId","getSchema","schemaNameOrId","publishAvroRecords","topicNameOrId","pubSubClient","topic","topicMetadata","topicSchemaMetadata","schemaEncoding","definition","type"]}
package/dist/pubsub.js DELETED
@@ -1,7 +0,0 @@
1
- var P=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,r)=>(typeof require<"u"?require:t)[r]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var M=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var d=M((m,l)=>{var g=P("buffer"),o=g.Buffer;function p(e,t){for(var r in e)t[r]=e[r]}o.from&&o.alloc&&o.allocUnsafe&&o.allocUnsafeSlow?l.exports=g:(p(g,m),m.Buffer=u);function u(e,t,r){return o(e,t,r)}u.prototype=Object.create(o.prototype);p(o,u);u.from=function(e,t,r){if(typeof e=="number")throw new TypeError("Argument must not be a number");return o(e,t,r)};u.alloc=function(e,t,r){if(typeof e!="number")throw new TypeError("Argument must be a number");var n=o(e);return t!==void 0?typeof r=="string"?n.fill(t,r):n.fill(t):n.fill(0),n};u.allocUnsafe=function(e){if(typeof e!="number")throw new TypeError("Argument must be a number");return o(e)};u.allocUnsafeSlow=function(e){if(typeof e!="number")throw new TypeError("Argument must be a number");return g.SlowBuffer(e)}});import{PubSub as v,Encodings as y}from"@google-cloud/pubsub";import*as w from"avro-js";var{Buffer:h}=d(),T=(e,t)=>new v({projectId:e,keyFilename:t}),S=async(e,t,r,n)=>{let i=h.from(JSON.stringify(t));return r.topic(e).publish(i,n)},j=async(e,t,r,n,i,s,a)=>{let c={entity_id:t,status:n,monitoring_id:r,step:e};return a&&(c.error_message=a),S(i,{parameters:c},s)},A=async(e,t,r,n,i)=>{let s={metadata:{monitoring_id:i}},c={objectId:e,bucketId:t,eventTime:new Date().toISOString()};return S(r,s,n,c)},B=async(e,t)=>(await t.schema(e).get()).definition,U=async(e,t,r)=>{let n=t.topic(e),[i]=await n.getMetadata(),s=i.schemaSettings;if(!s)return Promise.reject(new Error(`Topic ${e} doesn't seem to have a schema.`));let a=s.encoding,c=await B((s==null?void 0:s.schema)??"",t),b=w.parse(c),f;switch(a){case y.Binary:f=b.toBuffer(r);break;case y.Json:f=h.from(b.toString(r));break;default:return Promise.reject(new Error(`Unknown schema encoding: ${a}`))}return f?await n.publishMessage({data:f}):Promise.reject(new Error(`Invalid encoding ${a} on the topic.`))};export{T as getPubsubClient,B as getSchema,U as publishAvroRecords,S as publishMessage,j as publishProductFlowMonitoringMessage,A as publishStorageMessage};
2
- /*! Bundled license information:
3
-
4
- safe-buffer/index.js:
5
- (*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> *)
6
- */
7
- //# sourceMappingURL=pubsub.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../node_modules/safe-buffer/index.js","../src/pubsub.ts"],"sourcesContent":["/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */\n/* eslint-disable node/no-deprecated-api */\nvar buffer = require('buffer')\nvar Buffer = buffer.Buffer\n\n// alternative to using Object.keys for old browsers\nfunction copyProps (src, dst) {\n for (var key in src) {\n dst[key] = src[key]\n }\n}\nif (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) {\n module.exports = buffer\n} else {\n // Copy properties from require('buffer')\n copyProps(buffer, exports)\n exports.Buffer = SafeBuffer\n}\n\nfunction SafeBuffer (arg, encodingOrOffset, length) {\n return Buffer(arg, encodingOrOffset, length)\n}\n\nSafeBuffer.prototype = Object.create(Buffer.prototype)\n\n// Copy static methods from Buffer\ncopyProps(Buffer, SafeBuffer)\n\nSafeBuffer.from = function (arg, encodingOrOffset, length) {\n if (typeof arg === 'number') {\n throw new TypeError('Argument must not be a number')\n }\n return Buffer(arg, encodingOrOffset, length)\n}\n\nSafeBuffer.alloc = function (size, fill, encoding) {\n if (typeof size !== 'number') {\n throw new TypeError('Argument must be a number')\n }\n var buf = Buffer(size)\n if (fill !== undefined) {\n if (typeof encoding === 'string') {\n buf.fill(fill, encoding)\n } else {\n buf.fill(fill)\n }\n } else {\n buf.fill(0)\n }\n return buf\n}\n\nSafeBuffer.allocUnsafe = function (size) {\n if (typeof size !== 'number') {\n throw new TypeError('Argument must be a number')\n }\n return Buffer(size)\n}\n\nSafeBuffer.allocUnsafeSlow = function (size) {\n if (typeof size !== 'number') {\n throw new TypeError('Argument must be a number')\n }\n return buffer.SlowBuffer(size)\n}\n","import { PubSub, Encodings } from '@google-cloud/pubsub'\nimport { MonitoringStatus } from '@arcane-utils/types'\nimport * as avro from 'avro-js';\n\nconst {Buffer} = require('safe-buffer')\n\nexport interface MonitoringMessage {\n entity_id: number,\n status: MonitoringStatus,\n monitoring_id: string,\n step: string,\n error_message?: string\n}\n\n/**\n * Get PubSub client.\n *\n * To be used in Cloud Functions because of an issue with global declaration of clients.\n */\nexport const getPubsubClient = (gcpProject: string, serviceAccount: string): PubSub => {\n return new PubSub({\n projectId: gcpProject,\n keyFilename: serviceAccount\n })\n}\n\n/**\n * Publish a message on PubSub.\n*/\nexport const publishMessage = async (topicName: string, message: any, pubsub: PubSub, attributes?: any): Promise<string> => {\n const dataBuffer = Buffer.from(JSON.stringify(message))\n return pubsub.topic(topicName).publish(dataBuffer, attributes)\n}\n\n/**\n * Publish a message for Product Flow monitoring\n*/\nexport const publishProductFlowMonitoringMessage = async (\n step: string,\n entityId: number,\n monitoringId: string,\n status: MonitoringStatus,\n topicName: string,\n pubsub: PubSub,\n errorMessage?: string\n): Promise<string> => {\n const message: MonitoringMessage = {\n entity_id: entityId,\n status,\n monitoring_id: monitoringId,\n step\n }\n if (errorMessage) {\n message.error_message = errorMessage\n }\n return publishMessage(topicName, { parameters: message }, pubsub)\n}\n\n/**\n * Publish a message similar to a storage notification\n */\nexport const publishStorageMessage = async (\n objectId: string,\n bucketId: string,\n topicName: string,\n pubsub: PubSub,\n monitoringId?: string,\n): Promise<string> => {\n const message = {\n metadata: {\n monitoring_id: monitoringId\n }\n }\n const date = new Date()\n\n const attributes = {\n objectId,\n bucketId,\n eventTime: date.toISOString()\n }\n\n return publishMessage(topicName, message, pubsub, attributes)\n}\n\n/**\n * \n * @param schemaNameOrId : schema name or id\n * @param pubsub : pubsub client\n * @returns : schema definition Avro\n */\nexport const getSchema = async (schemaNameOrId: string, pubsub: PubSub): Promise<string | null | undefined> => {\n const schema = pubsub.schema(schemaNameOrId)\n const info = await schema.get()\n return info.definition\n}\n\n\n/**\n * Publish message with schema validation\n * \n * The schema will be retrieved from the topic metadata and validated\n */\nexport const publishAvroRecords = async (topicNameOrId : string, pubSubClient: PubSub, message: any): Promise<string> => {\n // Get the topic metadata to learn about its schema encoding.\n const topic = pubSubClient.topic(topicNameOrId)\n const [topicMetadata] = await topic.getMetadata()\n const topicSchemaMetadata = topicMetadata.schemaSettings\n\n if (!topicSchemaMetadata) {\n return Promise.reject(new Error(`Topic ${topicNameOrId} doesn't seem to have a schema.`))\n \n }\n const schemaEncoding = topicSchemaMetadata.encoding;\n\n // Make an encoder using the official avro-js library.\n const definition = await getSchema(topicSchemaMetadata?.schema ?? '', pubSubClient)\n const type = avro.parse(definition)\n\n \n let dataBuffer;\n switch (schemaEncoding) {\n case Encodings.Binary:\n dataBuffer = type.toBuffer(message)\n break\n case Encodings.Json:\n dataBuffer = Buffer.from(type.toString(message))\n break\n default:\n return Promise.reject(new Error(`Unknown schema encoding: ${schemaEncoding}`))\n }\n if (!dataBuffer) {\n return Promise.reject(new Error(`Invalid encoding ${schemaEncoding} on the topic.`))\n }\n\n const messageId = await topic.publishMessage({ data: dataBuffer })\n return messageId\n}"],"mappings":"uTAAA,IAAAA,EAAAC,EAAA,CAAAC,EAAAC,IAAA,CAEA,IAAIC,EAAS,EAAQ,QAAQ,EACzBC,EAASD,EAAO,OAGpB,SAASE,EAAWC,EAAKC,EAAK,CAC5B,QAASC,KAAOF,EACdC,EAAIC,CAAG,EAAIF,EAAIE,CAAG,CAEtB,CACIJ,EAAO,MAAQA,EAAO,OAASA,EAAO,aAAeA,EAAO,gBAC9DF,EAAO,QAAUC,GAGjBE,EAAUF,EAAQF,CAAO,EACzBA,EAAQ,OAASQ,GAGnB,SAASA,EAAYC,EAAKC,EAAkBC,EAAQ,CAClD,OAAOR,EAAOM,EAAKC,EAAkBC,CAAM,CAC7C,CAEAH,EAAW,UAAY,OAAO,OAAOL,EAAO,SAAS,EAGrDC,EAAUD,EAAQK,CAAU,EAE5BA,EAAW,KAAO,SAAUC,EAAKC,EAAkBC,EAAQ,CACzD,GAAI,OAAOF,GAAQ,SACjB,MAAM,IAAI,UAAU,+BAA+B,EAErD,OAAON,EAAOM,EAAKC,EAAkBC,CAAM,CAC7C,EAEAH,EAAW,MAAQ,SAAUI,EAAMC,EAAMC,EAAU,CACjD,GAAI,OAAOF,GAAS,SAClB,MAAM,IAAI,UAAU,2BAA2B,EAEjD,IAAIG,EAAMZ,EAAOS,CAAI,EACrB,OAAIC,IAAS,OACP,OAAOC,GAAa,SACtBC,EAAI,KAAKF,EAAMC,CAAQ,EAEvBC,EAAI,KAAKF,CAAI,EAGfE,EAAI,KAAK,CAAC,EAELA,CACT,EAEAP,EAAW,YAAc,SAAUI,EAAM,CACvC,GAAI,OAAOA,GAAS,SAClB,MAAM,IAAI,UAAU,2BAA2B,EAEjD,OAAOT,EAAOS,CAAI,CACpB,EAEAJ,EAAW,gBAAkB,SAAUI,EAAM,CAC3C,GAAI,OAAOA,GAAS,SAClB,MAAM,IAAI,UAAU,2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GrCE,EAAa,MAAMT,GAAUO,GAAA,YAAAA,EAAqB,SAAU,GAAIH,CAAY,EAC5EM,EAAY,QAAMD,CAAU,EAG9BnB,EACJ,OAAQkB,EAAgB,CACtB,KAAK7B,EAAU,OACbW,EAAaoB,EAAK,SAASvB,CAAO,EAClC,MACF,KAAKR,EAAU,KACbW,EAAaT,EAAO,KAAK6B,EAAK,SAASvB,CAAO,CAAC,EAC/C,MACF,QACE,OAAO,QAAQ,OAAO,IAAI,MAAM,4BAA4BqB,CAAc,EAAE,CAAC,CACjF,CACA,OAAKlB,EAIa,MAAMe,EAAM,eAAe,CAAE,KAAMf,CAAW,CAAC,EAHxD,QAAQ,OAAO,IAAI,MAAM,oBAAoBkB,CAAc,gBAAgB,CAAC,CAKvF","names":["require_safe_buffer","__commonJSMin","exports","module","buffer","Buffer","copyProps","src","dst","key","SafeBuffer","arg","encodingOrOffset","length","size","fill","encoding","buf","PubSub","Encodings","avro","Buffer","getPubsubClient","gcpProject","serviceAccount","publishMessage","topicName","message","pubsub","attributes","dataBuffer","publishProductFlowMonitoringMessage","step","entityId","monitoringId","status","errorMessage","publishStorageMessage","objectId","bucketId","getSchema","schemaNameOrId","publishAvroRecords","topicNameOrId","pubSubClient","topic","topicMetadata","topicSchemaMetadata","schemaEncoding","definition","type"]}