@snowplow/snowtype 0.4.1 → 0.4.2
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/dist/index.js +1 -1
- 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>>":""} = ${bt.default.inspect(i,!1,null)}
|
|
95
95
|
|
|
96
96
|
export const schemasObject${o==="ts"?": Record<string, AnySchema>":""} = ${bt.default.inspect(n,!1,null)}`,"utf-8")}function Ne(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 On(t,e){return e.debug("Checking for existing configuration.."),await I(!0),e.success("Valid configuration found"),{...G,...t}}async function V(t,e,n,i){let o=await On(i,e);n.setSpinnerTitle("Generating..."),n.isSpinning()===!1&&n.start();let r=await gt();j(r.dataStructures)&&j(r.igluCentralSchemas)&&j(r.eventSpecificationIds)&&j(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 T;let p=[...await qt(s,r.dataProductIds),...r.eventSpecificationIds].sort(),{eventSpecifications:g,cardinalityRules:f}=await Xt(s,p,e,o.instructions),A=await Qt(s,g);Ut(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 ht=await Yt(r.igluCentralSchemas),x=await Zt(s,r.dataStructures),z=!!(r.tracker==="@snowplow/browser-tracker"&&r.language.match(/javascript|typescript/)),M={language:r.language,tracker:r.tracker,schemas:[...ht,...x],eventSpecifications:A,validations:z&&o.validations},w=await(0,je.generate)(M);if(n.stop(!0),!w)throw new H;e.success("Code generated, writing...");let O=w.lines.join(`
|
|
97
|
-
`),v=(0,dt.resolve)((0,Fe.cwd)(),r.outpath);Ge.default.removeSync((0,dt.resolve)(v)),Ue.mkdirp.sync(v);let N=zt+Se(r.language);(0,_e.writeFileSync)((0,dt.resolve)(v,N),O),ye(g,r.outpath),z&&o.validations&&w.validationsSchemaObject&&(De(v,r.language,w.validationsSchemaObject,f),Ne(w.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&&Jt(g,w.lines,v,N)}var Tt=P(V);var bn={yes:!1,...G};async function Tn(t,e){let n={...bn,...t};return e.debug("Checking for existing configuration.."),await I(!0),e.success("Valid configuration found"),n}async function Ln(t,e,n,i){let o=await Tn(i,e);e.debug("Starting update process with options: ".concat(JSON.stringify(o)));let r=await gt(),s=(0,ze.resolve)((0,Ve.cwd)(),r.outpath,nt),c=new y({apiKey:t,organizationId:r.organizationId});n.setSpinnerTitle("Checking for updates..."),n.isSpinning()===!1&&n.start();let a={};if(!Et(s)&&r.eventSpecificationIds.length)throw new q;if(Et(s)&&r.eventSpecificationIds.length){let f=ve(s);a=await Le(c,r.eventSpecificationIds,f)}let p=await Te(c,r.dataStructures);if((Object.entries(a).length>0||p.length>0)===!0){if(e.success("Available updates found!"),Ie(a,p,e),o.yes===!0)return p.length>0&&(p.forEach(f=>{let A=r.dataStructures.indexOf(f.previous);r.dataStructures[A]=f.next}),ut(r)),e.debug("Applying the updates.."),V(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 Lt=P(Ln);var $n={eventSpecificationIds:[],dataStructures:[],igluCentralSchemas:[],dataProductIds:[],yes:!1,...G};async function Rn(t,e){let n={...$n,...t};if(Object.values(n).every(i=>typeof i=="boolean"||i.length===0))throw new B;return e.debug("Checking for existing configuration.."),await I(!0),e.success("Valid configuration found"),n}async function Dn(t,e,n,i){let{isJSON:o}=pt(process.cwd());if(o===!1)throw new X;let r=await Rn(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=>{be(c,p)})}),e.success("Configuration patched"),r.yes===!0?V(t,e,n,r):(e.log("Code is not generated yet for the patched configuration"),Promise.resolve(void 0))}var $t=P(Dn);var Me="0.4.
|
|
97
|
+
`),v=(0,dt.resolve)((0,Fe.cwd)(),r.outpath);Ge.default.removeSync((0,dt.resolve)(v)),Ue.mkdirp.sync(v);let N=zt+Se(r.language);(0,_e.writeFileSync)((0,dt.resolve)(v,N),O),ye(g,r.outpath),z&&o.validations&&w.validationsSchemaObject&&(De(v,r.language,w.validationsSchemaObject,f),Ne(w.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&&Jt(g,w.lines,v,N)}var Tt=P(V);var bn={yes:!1,...G};async function Tn(t,e){let n={...bn,...t};return e.debug("Checking for existing configuration.."),await I(!0),e.success("Valid configuration found"),n}async function Ln(t,e,n,i){let o=await Tn(i,e);e.debug("Starting update process with options: ".concat(JSON.stringify(o)));let r=await gt(),s=(0,ze.resolve)((0,Ve.cwd)(),r.outpath,nt),c=new y({apiKey:t,organizationId:r.organizationId});n.setSpinnerTitle("Checking for updates..."),n.isSpinning()===!1&&n.start();let a={};if(!Et(s)&&r.eventSpecificationIds.length)throw new q;if(Et(s)&&r.eventSpecificationIds.length){let f=ve(s);a=await Le(c,r.eventSpecificationIds,f)}let p=await Te(c,r.dataStructures);if((Object.entries(a).length>0||p.length>0)===!0){if(e.success("Available updates found!"),Ie(a,p,e),o.yes===!0)return p.length>0&&(p.forEach(f=>{let A=r.dataStructures.indexOf(f.previous);r.dataStructures[A]=f.next}),ut(r)),e.debug("Applying the updates.."),V(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 Lt=P(Ln);var $n={eventSpecificationIds:[],dataStructures:[],igluCentralSchemas:[],dataProductIds:[],yes:!1,...G};async function Rn(t,e){let n={...$n,...t};if(Object.values(n).every(i=>typeof i=="boolean"||i.length===0))throw new B;return e.debug("Checking for existing configuration.."),await I(!0),e.success("Valid configuration found"),n}async function Dn(t,e,n,i){let{isJSON:o}=pt(process.cwd());if(o===!1)throw new X;let r=await Rn(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=>{be(c,p)})}),e.success("Configuration patched"),r.yes===!0?V(t,e,n,r):(e.log("Code is not generated yet for the patched configuration"),Promise.resolve(void 0))}var $t=P(Dn);var Me="0.4.2";async function We(){await import("dotenv/config");let t=new mt.Command;t.exitOverride(),t.version(Me,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(At),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(Lt),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(Tt),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($t),t.addHelpText("before",oe()).addHelpText("after",`
|
|
98
98
|
`),await t.parseAsync(He.argv).catch(e=>{Nn(e)})}function Nn(t){if(!(t instanceof mt.CommanderError&&["commander.help","commander.version","commander.helpDisplayed"].indexOf(t.code)>-1))throw t}We().then(()=>{}).catch(()=>{process.exitCode=1});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@snowplow/snowtype",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
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.4.
|
|
16
|
+
"@snowplow/snowtype-core": "^0.4.2",
|
|
17
17
|
"chalk": "^4.1.2",
|
|
18
18
|
"cli-spinner": "^0.2.10",
|
|
19
19
|
"dotenv": "^16.3.1",
|