@snowplow/snowtype 0.5.0 → 0.5.1

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.
Files changed (2) hide show
  1. package/dist/index.js +1 -1
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -94,5 +94,5 @@ export type CardinalityRule = { minCardinality?: number; maxCardinality?: number
94
94
  export const entityRules${o==="ts"?": Record<string, Record<string, CardinalityRule>>":""} = ${$t.default.inspect(i,!1,null)}
95
95
 
96
96
  export const schemasObject${o==="ts"?": Record<string, AnySchema>":""} = ${$t.default.inspect(n,!1,null)}`,"utf-8")}function _e(t){return Object.values(t).some(e=>e.properties?Object.values(e.properties).some(n=>Object.hasOwn(n||{},"pattern")):!1)}var G={instructions:!1,validations:!1};async function An(t,e){return e.debug("Checking for existing configuration.."),await I(!0),e.success("Valid configuration found"),{...G,...t}}async function z(t,e,n,i){let o=await An(i,e);n.setSpinnerTitle("Generating..."),n.isSpinning()===!1&&n.start();let r=await ft();V(r.dataStructures)&&V(r.igluCentralSchemas)&&V(r.eventSpecificationIds)&&V(r.dataProductIds)&&e.warn("Data Structures, Schemas and Event Specifications are empty.");let s=new y({apiKey:t,organizationId:r.organizationId});if(!await s.authenticate())throw new A;let p=[...await Yt(s,r.dataProductIds),...r.eventSpecificationIds].sort(),{eventSpecifications:g,cardinalityRules:f}=await Zt(s,p,e,o.instructions),O=await ee(s,g);Vt(g)&&r.tracker==="@snowplow/browser-tracker"&&e.log("You are generating Snowplow Ecommerce events. You would need to install `@snowplow/browser-plugin-snowplow-ecommerce`."),o.validations&&e.log("For validations to work properly you would need to install `ajv@8`, `ajv-formats@2` and `ajv-draft-04@1` on your project.");let St=await Qt(r.igluCentralSchemas),x=await te(s,r.dataStructures),M=!!(r.tracker==="@snowplow/browser-tracker"&&r.language.match(/javascript|typescript/)),H={language:r.language,tracker:r.tracker,schemas:[...St,...x],eventSpecifications:O,validations:M&&o.validations},v=await(0,Ge.generate)(H);if(n.stop(!0),!v)throw new W;e.success("Code generated, writing...");let b=v.lines.join(`
97
- `),S=(0,ht.resolve)((0,je.cwd)(),r.outpath);ze.default.removeSync((0,ht.resolve)(S)),Ve.mkdirp.sync(S);let F=Ht+ve(r.language);(0,Ue.writeFileSync)((0,ht.resolve)(S,F),b),Se(g,r.outpath),M&&o.validations&&v.validationsSchemaObject&&(Ne(S,r.language,v.validationsSchemaObject,f),_e(v.validationsSchemaObject)&&e.warn("Some schemas appear to have attributes that can have inconsistent validations between the pipeline and client-side validation. Read more at https://docs.snowplow.io/docs/collecting-data/code-generation/client-side-validation/#divergence-with-pipeline-validation")),o.instructions&&Kt(g,v.lines,S,F)}var Lt=P(z);var $n={yes:!1,...G};async function Ln(t,e){let n={...$n,...t};return e.debug("Checking for existing configuration.."),await I(!0),e.success("Valid configuration found"),n}async function Rn(t,e,n,i){let o=await Ln(i,e);e.debug("Starting update process with options: ".concat(JSON.stringify(o)));let r=await ft(),s=(0,He.resolve)((0,Me.cwd)(),r.outpath,ot),c=new y({apiKey:t,organizationId:r.organizationId});n.setSpinnerTitle("Checking for updates..."),n.isSpinning()===!1&&n.start();let a={};if(!kt(s)&&r.eventSpecificationIds.length)throw new X;if(kt(s)&&r.eventSpecificationIds.length){let f=he(s);a=await Re(c,r.eventSpecificationIds,f)}let p=await Le(c,r.dataStructures);if((Object.entries(a).length>0||p.length>0)===!0){if(e.success("Available updates found!"),we(a,p,e),o.yes===!0)return p.length>0&&(p.forEach(f=>{let O=r.dataStructures.indexOf(f.previous);r.dataStructures[O]=f.next}),lt(r)),e.debug("Applying the updates.."),z(t,e,n,{});e.log("No updates applied"),e.log("To apply the available updates run update with --yes flag")}else e.success("No updates found. Everything is up-to-date!");return Promise.resolve(void 0)}var Rt=P(Rn);var Dn={eventSpecificationIds:[],dataStructures:[],igluCentralSchemas:[],dataProductIds:[],yes:!1,...G};async function Fn(t,e){let n={...Dn,...t};if(Object.values(n).every(i=>typeof i=="boolean"||i.length===0))throw new K;return e.debug("Checking for existing configuration.."),await I(!0),e.success("Valid configuration found"),n}async function Nn(t,e,n,i){let{isJSON:o}=gt(process.cwd());if(o===!1)throw new Y;let r=await Fn(i,e);return e.debug("Starting patch process with options: ".concat(JSON.stringify(r))),Object.entries(r).forEach(([c,a])=>{c!=="yes"&&Array.isArray(a)&&a.length!==0&&a.forEach(p=>{$e(c,p)})}),e.success("Configuration patched"),r.yes===!0?z(t,e,n,r):(e.log("Code is not generated yet for the patched configuration"),Promise.resolve(void 0))}var Dt=P(Nn);var We="0.5.0";async function Be(){await import("dotenv/config");let t=new vt.Command;t.exitOverride(),t.version(We,void 0,"Snowtype CLI version number").name("snowtype").description("The Snowtype CLI is a tool which aims to speed up tracking implementations, provide type safety and inline documentation for developers and ultimately reduce the number of erroneous events.").showHelpAfterError().configureHelp({showGlobalOptions:!0}).option("-k, --apiKey <string>","Snowplow Console API key").option("-v, --verbose","Enable verbose logging"),t.command("init").description("Initialize the setup of Snowtype code generation in a project. Creates the `snowtype.config.json` file.").option("-i, --organizationId <string>","organization ID").option("-t, --tracker <string>","tracker to use").option("-l, --language <string>","language to use").option("-o, --outpath <string>","output path").action(Tt),t.command("update").description("Checks for latest version updates in Data Structures and Event Specifications.").option("-y, --yes","updates all to latest without asking",!1).option("-is, --instructions","generate event specification instructions",!1).action(Rt),t.command("generate").option("-is, --instructions","generate event specification instructions",!1).option("-va, --validations","add runtime validation using Ajv",!1).description("Generates tracking code based on configuration on the `snowtype.config.json` file.").action(Lt),t.command("patch").description("Adds new Data Structures and Event Specifications in the `snowtype.config.json` file.").option("-p, --dataProductIds [value...]","data product ID").option("-e, --eventSpecificationIds [value...]","tracking eventSpecification ID").option("-d, --dataStructures [value...]","data structure URI").option("-i, --igluCentralSchemas [value...]","iglu central URI").option("-y, --yes","updates all to latest without asking",!1).option("-is, --instructions","generate event specification instructions",!1).action(Dt),t.addHelpText("before",se()).addHelpText("after",`
97
+ `),S=(0,ht.resolve)((0,je.cwd)(),r.outpath);ze.default.removeSync((0,ht.resolve)(S)),Ve.mkdirp.sync(S);let F=Ht+ve(r.language);(0,Ue.writeFileSync)((0,ht.resolve)(S,F),b),Se(g,r.outpath),M&&o.validations&&v.validationsSchemaObject&&(Ne(S,r.language,v.validationsSchemaObject,f),_e(v.validationsSchemaObject)&&e.warn("Some schemas appear to have attributes that can have inconsistent validations between the pipeline and client-side validation. Read more at https://docs.snowplow.io/docs/collecting-data/code-generation/client-side-validation/#divergence-with-pipeline-validation")),o.instructions&&Kt(g,v.lines,S,F)}var Lt=P(z);var $n={yes:!1,...G};async function Ln(t,e){let n={...$n,...t};return e.debug("Checking for existing configuration.."),await I(!0),e.success("Valid configuration found"),n}async function Rn(t,e,n,i){let o=await Ln(i,e);e.debug("Starting update process with options: ".concat(JSON.stringify(o)));let r=await ft(),s=(0,He.resolve)((0,Me.cwd)(),r.outpath,ot),c=new y({apiKey:t,organizationId:r.organizationId});n.setSpinnerTitle("Checking for updates..."),n.isSpinning()===!1&&n.start();let a={};if(!kt(s)&&r.eventSpecificationIds.length)throw new X;if(kt(s)&&r.eventSpecificationIds.length){let f=he(s);a=await Re(c,r.eventSpecificationIds,f)}let p=await Le(c,r.dataStructures);if((Object.entries(a).length>0||p.length>0)===!0){if(e.success("Available updates found!"),we(a,p,e),o.yes===!0)return p.length>0&&(p.forEach(f=>{let O=r.dataStructures.indexOf(f.previous);r.dataStructures[O]=f.next}),lt(r)),e.debug("Applying the updates.."),z(t,e,n,{});e.log("No updates applied"),e.log("To apply the available updates run update with --yes flag")}else e.success("No updates found. Everything is up-to-date!");return Promise.resolve(void 0)}var Rt=P(Rn);var Dn={eventSpecificationIds:[],dataStructures:[],igluCentralSchemas:[],dataProductIds:[],yes:!1,...G};async function Fn(t,e){let n={...Dn,...t};if(Object.values(n).every(i=>typeof i=="boolean"||i.length===0))throw new K;return e.debug("Checking for existing configuration.."),await I(!0),e.success("Valid configuration found"),n}async function Nn(t,e,n,i){let{isJSON:o}=gt(process.cwd());if(o===!1)throw new Y;let r=await Fn(i,e);return e.debug("Starting patch process with options: ".concat(JSON.stringify(r))),Object.entries(r).forEach(([c,a])=>{c!=="yes"&&Array.isArray(a)&&a.length!==0&&a.forEach(p=>{$e(c,p)})}),e.success("Configuration patched"),r.yes===!0?z(t,e,n,r):(e.log("Code is not generated yet for the patched configuration"),Promise.resolve(void 0))}var Dt=P(Nn);var We="0.5.1";async function Be(){await import("dotenv/config");let t=new vt.Command;t.exitOverride(),t.version(We,void 0,"Snowtype CLI version number").name("snowtype").description("The Snowtype CLI is a tool which aims to speed up tracking implementations, provide type safety and inline documentation for developers and ultimately reduce the number of erroneous events.").showHelpAfterError().configureHelp({showGlobalOptions:!0}).option("-k, --apiKey <string>","Snowplow Console API key").option("-v, --verbose","Enable verbose logging"),t.command("init").description("Initialize the setup of Snowtype code generation in a project. Creates the `snowtype.config.json` file.").option("-i, --organizationId <string>","organization ID").option("-t, --tracker <string>","tracker to use").option("-l, --language <string>","language to use").option("-o, --outpath <string>","output path").action(Tt),t.command("update").description("Checks for latest version updates in Data Structures and Event Specifications.").option("-y, --yes","updates all to latest without asking",!1).option("-is, --instructions","generate event specification instructions",!1).action(Rt),t.command("generate").option("-is, --instructions","generate event specification instructions",!1).option("-va, --validations","add runtime validation using Ajv",!1).description("Generates tracking code based on configuration on the `snowtype.config.json` file.").action(Lt),t.command("patch").description("Adds new Data Structures and Event Specifications in the `snowtype.config.json` file.").option("-p, --dataProductIds [value...]","data product ID").option("-e, --eventSpecificationIds [value...]","tracking eventSpecification ID").option("-d, --dataStructures [value...]","data structure URI").option("-i, --igluCentralSchemas [value...]","iglu central URI").option("-y, --yes","updates all to latest without asking",!1).option("-is, --instructions","generate event specification instructions",!1).action(Dt),t.addHelpText("before",se()).addHelpText("after",`
98
98
  `),await t.parseAsync(Je.argv).catch(e=>{_n(e)})}function _n(t){if(!(t instanceof vt.CommanderError&&["commander.help","commander.version","commander.helpDisplayed"].indexOf(t.code)>-1))throw t}Be().then(()=>{}).catch(()=>{process.exitCode=1});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snowplow/snowtype",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "A code generator CLI for faster and type-safe Snowplow tracking code",
5
5
  "author": "Peter Perlepes <peter@snowplowanalytics.com>",
6
6
  "homepage": "https://snowplow.io/",
@@ -13,7 +13,7 @@
13
13
  "dependencies": {
14
14
  "@commander-js/extra-typings": "^11.1.0",
15
15
  "@inquirer/prompts": "^3.3.0",
16
- "@snowplow/snowtype-core": "^0.5.0",
16
+ "@snowplow/snowtype-core": "^0.5.1",
17
17
  "chalk": "^4.1.2",
18
18
  "cli-spinner": "^0.2.10",
19
19
  "dotenv": "^16.3.1",