From a9d630279c87c3bf8e820c7f6feecfa4f29df246 Mon Sep 17 00:00:00 2001 From: Akash Gupta Date: Wed, 28 Feb 2024 23:38:33 +0530 Subject: [PATCH 01/10] feat: package typer init --- dataCatalogTypescript/.npmrc | 2 + dataCatalogTypescript/index.ts | 158 +++++++++++++++++++++++++++++ dataCatalogTypescript/package.json | 14 +++ dataCatalogTypescript/plan.json | 42 ++++++++ dataCatalogTypescript/rudder.ts | 106 +++++++++++++++++++ 5 files changed, 322 insertions(+) create mode 100644 dataCatalogTypescript/.npmrc create mode 100644 dataCatalogTypescript/index.ts create mode 100644 dataCatalogTypescript/package.json create mode 100644 dataCatalogTypescript/plan.json create mode 100644 dataCatalogTypescript/rudder.ts diff --git a/dataCatalogTypescript/.npmrc b/dataCatalogTypescript/.npmrc new file mode 100644 index 00000000..c08a5538 --- /dev/null +++ b/dataCatalogTypescript/.npmrc @@ -0,0 +1,2 @@ +//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN} +@rudderlabs:registry=https://npm.pkg.github.com \ No newline at end of file diff --git a/dataCatalogTypescript/index.ts b/dataCatalogTypescript/index.ts new file mode 100644 index 00000000..41b8b397 --- /dev/null +++ b/dataCatalogTypescript/index.ts @@ -0,0 +1,158 @@ +/** + * This client was automatically generated by RudderTyper. ** Do Not Edit ** + */ + +import * as Rudder from './rudder' +import { apiCallback } from 'rudder-sdk-js' + +export interface CatalogAddNewEvent { + catagory?: string + description?: string + eventName?: string + type?: string +} + +export type ViolationHandler = ( + message: Record, + violations: any[] +) => void + +let analytics: () => any | undefined = () => { + return window.analytics +} + +/** Options to customize the runtime behavior of a RudderTyper client. */ +export interface RudderTyperOptions { + /** + * Underlying analytics instance where analytics calls are forwarded on to. + * Defaults to window.analytics. + */ + analytics?: any + /** + * Handler fired when if an event does not match its spec. This handler + * does not fire in production mode, because it requires inlining the full + * JSON Schema spec for each event in your Tracking Plan. + * + * By default, it will throw errors if NODE_ENV = "test" so that tests will fail + * if a message does not match the spec. Otherwise, errors will be logged to stderr. + */ + onViolation?: ViolationHandler +} + +/** + * Updates the run-time configuration of this RudderTyper client. + * + * @param {RudderTyperOptions} options - the options to upsert + * + * @typedef {Object} RudderTyperOptions + * @property {Rudder.AnalyticsJS} [analytics] - Underlying analytics instance where analytics + * calls are forwarded on to. Defaults to window.analytics. + * @property {Function} [onViolation] - Handler fired when if an event does not match its spec. This handler does not fire in + * production mode, because it requires inlining the full JSON Schema spec for each event in your Tracking Plan. By default, + * it will throw errors if NODE_ENV="test" so that tests will fail if a message does not match the spec. Otherwise, errors + * will be logged to stderr. + */ +export function setRudderTyperOptions(options: RudderTyperOptions) { + analytics = options.analytics + ? () => options.analytics || window.analytics + : analytics +} + +/** + * Helper to attach metadata on RudderTyper to outbound requests. + * This is used for attribution and debugging by the RudderStack team. + */ +function withRudderTyperContext(message: Rudder.Options = {}): Rudder.Options { + return { + ...message, + context: { + ...(message.context || {}), + ruddertyper: { + sdk: 'analytics.js', + language: 'typescript', + rudderTyperVersion: '1.0.0-beta.5', + trackingPlanId: 'tp_2cu4qwiLI03Pvkt4TnVaXPvbrBF', + trackingPlanVersion: '1', + }, + }, + } +} + +/** + * @typedef CatalogAddNewEvent + * @property {string} [catagory] - + * @property {string} [description] - + * @property {string} [eventName] - + * @property {string} [type] - + */ + +/** + * when user adds new event + * + * @param {CatalogAddNewEvent} [props] - The analytics properties that will be sent to RudderStack. + * @param {Object} [options] - A dictionary of options. For example, enable or disable specific destinations for the call. + * @param {Function} [callback] - An optional callback called after a short timeout after the analytics + * call is fired. + */ +export function catalogAddNewEvent( + props?: CatalogAddNewEvent, + options?: Rudder.Options, + callback?: apiCallback +): void { + const a = analytics() + if (a) { + a.track( + 'catalogAddNewEvent', + props || {}, + withRudderTyperContext(options), + callback + ) + } +} + +const clientAPI = { + /** + * Updates the run-time configuration of this RudderTyper client. + * + * @param {RudderTyperOptions} options - the options to upsert + * + * @typedef {Object} RudderTyperOptions + * @property {Rudder.AnalyticsJS} [analytics] - Underlying analytics instance where analytics + * calls are forwarded on to. Defaults to window.analytics. + * @property {Function} [onViolation] - Handler fired when if an event does not match its spec. This handler does not fire in + * production mode, because it requires inlining the full JSON Schema spec for each event in your Tracking Plan. By default, + * it will throw errors if NODE_ENV="test" so that tests will fail if a message does not match the spec. Otherwise, errors + * will be logged to stderr. + */ + setRudderTyperOptions, + /** + * when user adds new event + * + * @param {CatalogAddNewEvent} [props] - The analytics properties that will be sent to RudderStack. + * @param {Object} [options] - A dictionary of options. For example, enable or disable specific destinations for the call. + * @param {Function} [callback] - An optional callback called after a short timeout after the analytics + * call is fired. + */ + catalogAddNewEvent, +} + +export const RudderTyperAnalytics = new Proxy(clientAPI, { + get(target, method) { + if (typeof method === 'string' && Object.keys(target).includes(method)) { + return target[method as keyof typeof clientAPI] + } + + return () => { + const a = analytics() + if (a) { + a.track( + 'Unknown Analytics Call Fired', + { + method, + }, + withRudderTyperContext() + ) + } + } + }, +}) diff --git a/dataCatalogTypescript/package.json b/dataCatalogTypescript/package.json new file mode 100644 index 00000000..352343d8 --- /dev/null +++ b/dataCatalogTypescript/package.json @@ -0,0 +1,14 @@ +{ + "name": "@rudderlabs/rudder-typer-webapp", + "version": "1.0.0-beta.6", + "description": "Rudder-Typer analytics libraries are based on your pre-defined tracking plan specifications.", + "main": "./dist/src/cli/index.ts", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "rudderlabs", + "license": "MIT", + "dependencies": { + "rudder-sdk-js": "^2.48.2" + } +} diff --git a/dataCatalogTypescript/plan.json b/dataCatalogTypescript/plan.json new file mode 100644 index 00000000..60804204 --- /dev/null +++ b/dataCatalogTypescript/plan.json @@ -0,0 +1,42 @@ +{ + "create_time": "2024-02-26T11:52:03.590Z", + "display_name": "Data Catalog Event Tracking", + "name": "workspaces/1Rgdwcyd93G37qqMOs03KWiTQd2/tracking-plans/tp_2cu4qwiLI03Pvkt4TnVaXPvbrBF", + "rules": { + "events": [ + { + "description": "when user adds new event", + "id": "ev_2bIn2EOX1XfwHy5poijPFR6wPRK", + "name": "catalogAddNewEvent", + "rules": { + "$schema": "http://json-schema.org/draft-07/schema#", + "properties": { + "context": {}, + "properties": { + "properties": { + "catagory": { + "type": ["string"] + }, + "description": { + "type": ["string"] + }, + "eventName": { + "type": ["string"] + }, + "type": { + "type": ["string"] + } + }, + "type": "object" + }, + "traits": {} + }, + "type": "object" + }, + "version": "2-0-0" + } + ] + }, + "update_time": "2024-02-26T11:52:03.590Z", + "version": 1 +} diff --git a/dataCatalogTypescript/rudder.ts b/dataCatalogTypescript/rudder.ts new file mode 100644 index 00000000..3e8b05fe --- /dev/null +++ b/dataCatalogTypescript/rudder.ts @@ -0,0 +1,106 @@ +/** + * This client was automatically generated by RudderTyper. ** Do Not Edit ** + */ +/** + * The analytics.js snippet should be available via window.analytics. + * You can install it by following instructions at: https://docs.rudderstack.com/stream-sources/rudderstack-sdk-integration-guides/rudderstack-javascript-sdk#2-installing-the-rudderstack-javascript-sdk + */ +declare global { + interface Window { + analytics: any + } +} + +/** The Schema object which is being used by Ajv to validate the message */ +export interface Schema { + $schema?: string + description?: string + properties?: object + title?: string + type?: string +} + +/** A dictionary of options. For example, enable or disable specific destinations for the call. */ +export interface Options { + /** + * Selectivly filter destinations. By default all destinations are enabled. + * https://docs.rudderstack.com/stream-sources/rudderstack-sdk-integration-guides/rudderstack-javascript-sdk#4-how-to-filter-selective-destinations-to-send-event-data + */ + integrations?: { + [key: string]: boolean | { [key: string]: any } + } + /** + * A dictionary of extra context to attach to the call. + */ + context?: Context +} + +/** + * Context is a dictionary of extra information that provides useful context about a datapoint. + */ +export interface Context extends Record { + active?: boolean + app?: { + name?: string + version?: string + build?: string + } + campaign?: { + name?: string + source?: string + medium?: string + term?: string + content?: string + } + device?: { + id?: string + manufacturer?: string + model?: string + name?: string + type?: string + version?: string + } + ip?: string + locale?: string + location?: { + city?: string + country?: string + latitude?: string + longitude?: string + region?: string + speed?: string + } + network?: { + bluetooth?: string + carrier?: string + cellular?: string + wifi?: string + } + os?: { + name?: string + version?: string + } + page?: { + hash?: string + path?: string + referrer?: string + search?: string + title?: string + url?: string + } + referrer?: { + type?: string + name?: string + url?: string + link?: string + } + screen?: { + density?: string + height?: string + width?: string + } + timezone?: string + groupId?: string + traits?: Record + userAgent?: string +} From cd41613d4a70c41faec77785b919a30bfad7f41a Mon Sep 17 00:00:00 2001 From: Akash Gupta Date: Thu, 29 Feb 2024 00:30:41 +0530 Subject: [PATCH 02/10] feat: add build code --- dataCatalogTypescript/.npmignore | 2 ++ dataCatalogTypescript/package.json | 10 +++++++--- dataCatalogTypescript/{ => src}/index.ts | 0 dataCatalogTypescript/{ => src}/plan.json | 0 dataCatalogTypescript/{ => src}/rudder.ts | 0 dataCatalogTypescript/tsconfig.json | 12 ++++++++++++ 6 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 dataCatalogTypescript/.npmignore rename dataCatalogTypescript/{ => src}/index.ts (100%) rename dataCatalogTypescript/{ => src}/plan.json (100%) rename dataCatalogTypescript/{ => src}/rudder.ts (100%) create mode 100644 dataCatalogTypescript/tsconfig.json diff --git a/dataCatalogTypescript/.npmignore b/dataCatalogTypescript/.npmignore new file mode 100644 index 00000000..f4bcc81a --- /dev/null +++ b/dataCatalogTypescript/.npmignore @@ -0,0 +1,2 @@ +node_modules/ +src \ No newline at end of file diff --git a/dataCatalogTypescript/package.json b/dataCatalogTypescript/package.json index 352343d8..2c705be7 100644 --- a/dataCatalogTypescript/package.json +++ b/dataCatalogTypescript/package.json @@ -1,14 +1,18 @@ { "name": "@rudderlabs/rudder-typer-webapp", - "version": "1.0.0-beta.6", + "version": "1.0.0-beta.8", "description": "Rudder-Typer analytics libraries are based on your pre-defined tracking plan specifications.", - "main": "./dist/src/cli/index.ts", + "main": "dist/index.js", + "types": "dist/index.d.ts", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "build": "tsc" }, "author": "rudderlabs", "license": "MIT", "dependencies": { "rudder-sdk-js": "^2.48.2" + }, + "devDependencies": { + "typescript": "^5.3.3" } } diff --git a/dataCatalogTypescript/index.ts b/dataCatalogTypescript/src/index.ts similarity index 100% rename from dataCatalogTypescript/index.ts rename to dataCatalogTypescript/src/index.ts diff --git a/dataCatalogTypescript/plan.json b/dataCatalogTypescript/src/plan.json similarity index 100% rename from dataCatalogTypescript/plan.json rename to dataCatalogTypescript/src/plan.json diff --git a/dataCatalogTypescript/rudder.ts b/dataCatalogTypescript/src/rudder.ts similarity index 100% rename from dataCatalogTypescript/rudder.ts rename to dataCatalogTypescript/src/rudder.ts diff --git a/dataCatalogTypescript/tsconfig.json b/dataCatalogTypescript/tsconfig.json new file mode 100644 index 00000000..32e157a3 --- /dev/null +++ b/dataCatalogTypescript/tsconfig.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + "outDir": "dist", + "module": "commonjs", + "resolveJsonModule": true, + "esModuleInterop": true, + "skipLibCheck": true, + "declaration": true + }, + "include": ["./src/**/*"], + "exclude": ["node_modules"] +} \ No newline at end of file From 85361c9d9f6ac959a72bdf84809647be3170b917 Mon Sep 17 00:00:00 2001 From: Akash Gupta Date: Thu, 29 Feb 2024 19:55:43 +0530 Subject: [PATCH 03/10] feat: update code --- dataCatalogTypescript/.nvmrc | 1 + dataCatalogTypescript/package.json | 2 +- dataCatalogTypescript/src/index.ts | 6 +++--- dataCatalogTypescript/src/rudder.ts | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) create mode 100644 dataCatalogTypescript/.nvmrc diff --git a/dataCatalogTypescript/.nvmrc b/dataCatalogTypescript/.nvmrc new file mode 100644 index 00000000..7ec56198 --- /dev/null +++ b/dataCatalogTypescript/.nvmrc @@ -0,0 +1 @@ +18.17.1 \ No newline at end of file diff --git a/dataCatalogTypescript/package.json b/dataCatalogTypescript/package.json index 2c705be7..16b66d27 100644 --- a/dataCatalogTypescript/package.json +++ b/dataCatalogTypescript/package.json @@ -1,6 +1,6 @@ { "name": "@rudderlabs/rudder-typer-webapp", - "version": "1.0.0-beta.8", + "version": "1.0.0-beta.10", "description": "Rudder-Typer analytics libraries are based on your pre-defined tracking plan specifications.", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/dataCatalogTypescript/src/index.ts b/dataCatalogTypescript/src/index.ts index 41b8b397..619fdd87 100644 --- a/dataCatalogTypescript/src/index.ts +++ b/dataCatalogTypescript/src/index.ts @@ -18,14 +18,14 @@ export type ViolationHandler = ( ) => void let analytics: () => any | undefined = () => { - return window.analytics + return window.rudderanalytics } /** Options to customize the runtime behavior of a RudderTyper client. */ export interface RudderTyperOptions { /** * Underlying analytics instance where analytics calls are forwarded on to. - * Defaults to window.analytics. + * Defaults to window.rudderanalytics. */ analytics?: any /** @@ -54,7 +54,7 @@ export interface RudderTyperOptions { */ export function setRudderTyperOptions(options: RudderTyperOptions) { analytics = options.analytics - ? () => options.analytics || window.analytics + ? () => options.analytics || window.rudderanalytics : analytics } diff --git a/dataCatalogTypescript/src/rudder.ts b/dataCatalogTypescript/src/rudder.ts index 3e8b05fe..976a806b 100644 --- a/dataCatalogTypescript/src/rudder.ts +++ b/dataCatalogTypescript/src/rudder.ts @@ -7,7 +7,7 @@ */ declare global { interface Window { - analytics: any + rudderanalytics: any } } From 9dde716b9ad39938f9d3656b5925ca6eb0de313f Mon Sep 17 00:00:00 2001 From: Akash Gupta Date: Tue, 19 Mar 2024 14:28:54 +0530 Subject: [PATCH 04/10] feat: update code --- dataCatalogTypescript/package.json | 2 +- dataCatalogTypescript/src/index.ts | 434 +++++++++++++++++++++++++++- dataCatalogTypescript/src/plan.json | 279 +++++++++++++++++- 3 files changed, 687 insertions(+), 28 deletions(-) diff --git a/dataCatalogTypescript/package.json b/dataCatalogTypescript/package.json index 16b66d27..531d6d36 100644 --- a/dataCatalogTypescript/package.json +++ b/dataCatalogTypescript/package.json @@ -1,6 +1,6 @@ { "name": "@rudderlabs/rudder-typer-webapp", - "version": "1.0.0-beta.10", + "version": "1.0.0-beta.13", "description": "Rudder-Typer analytics libraries are based on your pre-defined tracking plan specifications.", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/dataCatalogTypescript/src/index.ts b/dataCatalogTypescript/src/index.ts index 619fdd87..0215d8ad 100644 --- a/dataCatalogTypescript/src/index.ts +++ b/dataCatalogTypescript/src/index.ts @@ -6,10 +6,50 @@ import * as Rudder from './rudder' import { apiCallback } from 'rudder-sdk-js' export interface CatalogAddNewEvent { - catagory?: string - description?: string - eventName?: string - type?: string + category?: string + eventName: string + eventType: string +} +export interface TrackingPlanDropEventsTriggered { + trackingPlanId: string + trackingPlanName: string +} +export interface TrackingPlanCreated { + trackingPlanId: string + trackingPlanName: string +} +export interface TrackingPlanConnected { + sourceId: any[] | string + sourceName: any[] | string + trackingPlanId: string + trackingPlanName: string +} +export interface CatalogAddNewProperty { + propertyName: string + propertyType?: string +} +export interface TrackingPlanEventsViewed { + trackingPlanId: string +} +export interface CatalogDeleteEvent { + category?: string + eventName: string + eventType: string +} +export interface CatalogDeleteProperty { + propertyName: string + propertyType?: string +} +export interface TrackingPlanEdited { + trackingPlanId: string + trackingPlanName: string +} +export interface ClickAddTrackingPlan { + trackingPlanImportType: string +} +export interface TrackingPlanDraftCreated { + trackingPlanId: string + trackingPlanName: string } export type ViolationHandler = ( @@ -71,8 +111,8 @@ function withRudderTyperContext(message: Rudder.Options = {}): Rudder.Options { sdk: 'analytics.js', language: 'typescript', rudderTyperVersion: '1.0.0-beta.5', - trackingPlanId: 'tp_2cu4qwiLI03Pvkt4TnVaXPvbrBF', - trackingPlanVersion: '1', + trackingPlanId: 'tp_2dHb5Dq7Ikav1AT3b2rpeQVoIES', + trackingPlanVersion: '9', }, }, } @@ -80,14 +120,64 @@ function withRudderTyperContext(message: Rudder.Options = {}): Rudder.Options { /** * @typedef CatalogAddNewEvent - * @property {string} [catagory] - - * @property {string} [description] - - * @property {string} [eventName] - - * @property {string} [type] - + * @property {string} [category] - + * @property {string} eventName - + * @property {string} eventType - + */ +/** + * @typedef TrackingPlanDropEventsTriggered + * @property {string} trackingPlanId - + * @property {string} trackingPlanName - + */ +/** + * @typedef TrackingPlanCreated + * @property {string} trackingPlanId - + * @property {string} trackingPlanName - + */ +/** + * @typedef TrackingPlanConnected + * @property {any[] | string} sourceId - + * @property {any[] | string} sourceName - + * @property {string} trackingPlanId - + * @property {string} trackingPlanName - + */ +/** + * @typedef CatalogAddNewProperty + * @property {string} propertyName - + * @property {string} [propertyType] - + */ +/** + * @typedef TrackingPlanEventsViewed + * @property {string} trackingPlanId - + */ +/** + * @typedef CatalogDeleteEvent + * @property {string} [category] - + * @property {string} eventName - + * @property {string} eventType - + */ +/** + * @typedef CatalogDeleteProperty + * @property {string} propertyName - + * @property {string} [propertyType] - + */ +/** + * @typedef TrackingPlanEdited + * @property {string} trackingPlanId - + * @property {string} trackingPlanName - + */ +/** + * @typedef ClickAddTrackingPlan + * @property {string} trackingPlanImportType - + */ +/** + * @typedef TrackingPlanDraftCreated + * @property {string} trackingPlanId - + * @property {string} trackingPlanName - */ /** - * when user adds new event + * Fires a 'catalogAddNewEvent' track call. * * @param {CatalogAddNewEvent} [props] - The analytics properties that will be sent to RudderStack. * @param {Object} [options] - A dictionary of options. For example, enable or disable specific destinations for the call. @@ -109,6 +199,236 @@ export function catalogAddNewEvent( ) } } +/** + * Fires a 'trackingPlanDropEventsTriggered' track call. + * + * @param {TrackingPlanDropEventsTriggered} [props] - The analytics properties that will be sent to RudderStack. + * @param {Object} [options] - A dictionary of options. For example, enable or disable specific destinations for the call. + * @param {Function} [callback] - An optional callback called after a short timeout after the analytics + * call is fired. + */ +export function trackingPlanDropEventsTriggered( + props?: TrackingPlanDropEventsTriggered, + options?: Rudder.Options, + callback?: apiCallback +): void { + const a = analytics() + if (a) { + a.track( + 'trackingPlanDropEventsTriggered', + props || {}, + withRudderTyperContext(options), + callback + ) + } +} +/** + * Fires a 'trackingPlanCreated' track call. + * + * @param {TrackingPlanCreated} [props] - The analytics properties that will be sent to RudderStack. + * @param {Object} [options] - A dictionary of options. For example, enable or disable specific destinations for the call. + * @param {Function} [callback] - An optional callback called after a short timeout after the analytics + * call is fired. + */ +export function trackingPlanCreated( + props?: TrackingPlanCreated, + options?: Rudder.Options, + callback?: apiCallback +): void { + const a = analytics() + if (a) { + a.track( + 'trackingPlanCreated', + props || {}, + withRudderTyperContext(options), + callback + ) + } +} +/** + * Fires a 'trackingPlanConnected' track call. + * + * @param {TrackingPlanConnected} [props] - The analytics properties that will be sent to RudderStack. + * @param {Object} [options] - A dictionary of options. For example, enable or disable specific destinations for the call. + * @param {Function} [callback] - An optional callback called after a short timeout after the analytics + * call is fired. + */ +export function trackingPlanConnected( + props?: TrackingPlanConnected, + options?: Rudder.Options, + callback?: apiCallback +): void { + const a = analytics() + if (a) { + a.track( + 'trackingPlanConnected', + props || {}, + withRudderTyperContext(options), + callback + ) + } +} +/** + * Fires a 'catalogAddNewProperty' track call. + * + * @param {CatalogAddNewProperty} [props] - The analytics properties that will be sent to RudderStack. + * @param {Object} [options] - A dictionary of options. For example, enable or disable specific destinations for the call. + * @param {Function} [callback] - An optional callback called after a short timeout after the analytics + * call is fired. + */ +export function catalogAddNewProperty( + props?: CatalogAddNewProperty, + options?: Rudder.Options, + callback?: apiCallback +): void { + const a = analytics() + if (a) { + a.track( + 'catalogAddNewProperty', + props || {}, + withRudderTyperContext(options), + callback + ) + } +} +/** + * Fires a 'trackingPlanEventsViewed' track call. + * + * @param {TrackingPlanEventsViewed} [props] - The analytics properties that will be sent to RudderStack. + * @param {Object} [options] - A dictionary of options. For example, enable or disable specific destinations for the call. + * @param {Function} [callback] - An optional callback called after a short timeout after the analytics + * call is fired. + */ +export function trackingPlanEventsViewed( + props?: TrackingPlanEventsViewed, + options?: Rudder.Options, + callback?: apiCallback +): void { + const a = analytics() + if (a) { + a.track( + 'trackingPlanEventsViewed', + props || {}, + withRudderTyperContext(options), + callback + ) + } +} +/** + * Fires a 'catalogDeleteEvent' track call. + * + * @param {CatalogDeleteEvent} [props] - The analytics properties that will be sent to RudderStack. + * @param {Object} [options] - A dictionary of options. For example, enable or disable specific destinations for the call. + * @param {Function} [callback] - An optional callback called after a short timeout after the analytics + * call is fired. + */ +export function catalogDeleteEvent( + props?: CatalogDeleteEvent, + options?: Rudder.Options, + callback?: apiCallback +): void { + const a = analytics() + if (a) { + a.track( + 'catalogDeleteEvent', + props || {}, + withRudderTyperContext(options), + callback + ) + } +} +/** + * Fires a 'catalogDeleteProperty' track call. + * + * @param {CatalogDeleteProperty} [props] - The analytics properties that will be sent to RudderStack. + * @param {Object} [options] - A dictionary of options. For example, enable or disable specific destinations for the call. + * @param {Function} [callback] - An optional callback called after a short timeout after the analytics + * call is fired. + */ +export function catalogDeleteProperty( + props?: CatalogDeleteProperty, + options?: Rudder.Options, + callback?: apiCallback +): void { + const a = analytics() + if (a) { + a.track( + 'catalogDeleteProperty', + props || {}, + withRudderTyperContext(options), + callback + ) + } +} +/** + * Fires a 'trackingPlanEdited' track call. + * + * @param {TrackingPlanEdited} [props] - The analytics properties that will be sent to RudderStack. + * @param {Object} [options] - A dictionary of options. For example, enable or disable specific destinations for the call. + * @param {Function} [callback] - An optional callback called after a short timeout after the analytics + * call is fired. + */ +export function trackingPlanEdited( + props?: TrackingPlanEdited, + options?: Rudder.Options, + callback?: apiCallback +): void { + const a = analytics() + if (a) { + a.track( + 'trackingPlanEdited', + props || {}, + withRudderTyperContext(options), + callback + ) + } +} +/** + * Fires a 'clickAddTrackingPlan' track call. + * + * @param {ClickAddTrackingPlan} [props] - The analytics properties that will be sent to RudderStack. + * @param {Object} [options] - A dictionary of options. For example, enable or disable specific destinations for the call. + * @param {Function} [callback] - An optional callback called after a short timeout after the analytics + * call is fired. + */ +export function clickAddTrackingPlan( + props?: ClickAddTrackingPlan, + options?: Rudder.Options, + callback?: apiCallback +): void { + const a = analytics() + if (a) { + a.track( + 'clickAddTrackingPlan', + props || {}, + withRudderTyperContext(options), + callback + ) + } +} +/** + * Fires a 'trackingPlanDraftCreated' track call. + * + * @param {TrackingPlanDraftCreated} [props] - The analytics properties that will be sent to RudderStack. + * @param {Object} [options] - A dictionary of options. For example, enable or disable specific destinations for the call. + * @param {Function} [callback] - An optional callback called after a short timeout after the analytics + * call is fired. + */ +export function trackingPlanDraftCreated( + props?: TrackingPlanDraftCreated, + options?: Rudder.Options, + callback?: apiCallback +): void { + const a = analytics() + if (a) { + a.track( + 'trackingPlanDraftCreated', + props || {}, + withRudderTyperContext(options), + callback + ) + } +} const clientAPI = { /** @@ -126,7 +446,7 @@ const clientAPI = { */ setRudderTyperOptions, /** - * when user adds new event + * Fires a 'catalogAddNewEvent' track call. * * @param {CatalogAddNewEvent} [props] - The analytics properties that will be sent to RudderStack. * @param {Object} [options] - A dictionary of options. For example, enable or disable specific destinations for the call. @@ -134,6 +454,96 @@ const clientAPI = { * call is fired. */ catalogAddNewEvent, + /** + * Fires a 'trackingPlanDropEventsTriggered' track call. + * + * @param {TrackingPlanDropEventsTriggered} [props] - The analytics properties that will be sent to RudderStack. + * @param {Object} [options] - A dictionary of options. For example, enable or disable specific destinations for the call. + * @param {Function} [callback] - An optional callback called after a short timeout after the analytics + * call is fired. + */ + trackingPlanDropEventsTriggered, + /** + * Fires a 'trackingPlanCreated' track call. + * + * @param {TrackingPlanCreated} [props] - The analytics properties that will be sent to RudderStack. + * @param {Object} [options] - A dictionary of options. For example, enable or disable specific destinations for the call. + * @param {Function} [callback] - An optional callback called after a short timeout after the analytics + * call is fired. + */ + trackingPlanCreated, + /** + * Fires a 'trackingPlanConnected' track call. + * + * @param {TrackingPlanConnected} [props] - The analytics properties that will be sent to RudderStack. + * @param {Object} [options] - A dictionary of options. For example, enable or disable specific destinations for the call. + * @param {Function} [callback] - An optional callback called after a short timeout after the analytics + * call is fired. + */ + trackingPlanConnected, + /** + * Fires a 'catalogAddNewProperty' track call. + * + * @param {CatalogAddNewProperty} [props] - The analytics properties that will be sent to RudderStack. + * @param {Object} [options] - A dictionary of options. For example, enable or disable specific destinations for the call. + * @param {Function} [callback] - An optional callback called after a short timeout after the analytics + * call is fired. + */ + catalogAddNewProperty, + /** + * Fires a 'trackingPlanEventsViewed' track call. + * + * @param {TrackingPlanEventsViewed} [props] - The analytics properties that will be sent to RudderStack. + * @param {Object} [options] - A dictionary of options. For example, enable or disable specific destinations for the call. + * @param {Function} [callback] - An optional callback called after a short timeout after the analytics + * call is fired. + */ + trackingPlanEventsViewed, + /** + * Fires a 'catalogDeleteEvent' track call. + * + * @param {CatalogDeleteEvent} [props] - The analytics properties that will be sent to RudderStack. + * @param {Object} [options] - A dictionary of options. For example, enable or disable specific destinations for the call. + * @param {Function} [callback] - An optional callback called after a short timeout after the analytics + * call is fired. + */ + catalogDeleteEvent, + /** + * Fires a 'catalogDeleteProperty' track call. + * + * @param {CatalogDeleteProperty} [props] - The analytics properties that will be sent to RudderStack. + * @param {Object} [options] - A dictionary of options. For example, enable or disable specific destinations for the call. + * @param {Function} [callback] - An optional callback called after a short timeout after the analytics + * call is fired. + */ + catalogDeleteProperty, + /** + * Fires a 'trackingPlanEdited' track call. + * + * @param {TrackingPlanEdited} [props] - The analytics properties that will be sent to RudderStack. + * @param {Object} [options] - A dictionary of options. For example, enable or disable specific destinations for the call. + * @param {Function} [callback] - An optional callback called after a short timeout after the analytics + * call is fired. + */ + trackingPlanEdited, + /** + * Fires a 'clickAddTrackingPlan' track call. + * + * @param {ClickAddTrackingPlan} [props] - The analytics properties that will be sent to RudderStack. + * @param {Object} [options] - A dictionary of options. For example, enable or disable specific destinations for the call. + * @param {Function} [callback] - An optional callback called after a short timeout after the analytics + * call is fired. + */ + clickAddTrackingPlan, + /** + * Fires a 'trackingPlanDraftCreated' track call. + * + * @param {TrackingPlanDraftCreated} [props] - The analytics properties that will be sent to RudderStack. + * @param {Object} [options] - A dictionary of options. For example, enable or disable specific destinations for the call. + * @param {Function} [callback] - An optional callback called after a short timeout after the analytics + * call is fired. + */ + trackingPlanDraftCreated, } export const RudderTyperAnalytics = new Proxy(clientAPI, { diff --git a/dataCatalogTypescript/src/plan.json b/dataCatalogTypescript/src/plan.json index 60804204..436660f2 100644 --- a/dataCatalogTypescript/src/plan.json +++ b/dataCatalogTypescript/src/plan.json @@ -1,42 +1,291 @@ { - "create_time": "2024-02-26T11:52:03.590Z", - "display_name": "Data Catalog Event Tracking", - "name": "workspaces/1Rgdwcyd93G37qqMOs03KWiTQd2/tracking-plans/tp_2cu4qwiLI03Pvkt4TnVaXPvbrBF", + "config": { + "group": "traits", + "identify": "traits", + "page": "properties", + "screen": "properties", + "track": "properties" + }, + "createdAt": "2024-03-05T19:42:45.616Z", + "creationType": "Manual", + "description": "Analytics for Data Catalog and Tracking Plan", + "id": "tp_2dHb5Dq7Ikav1AT3b2rpeQVoIES", + "name": "Catalog Event Tracking", "rules": { "events": [ { - "description": "when user adds new event", - "id": "ev_2bIn2EOX1XfwHy5poijPFR6wPRK", + "description": "", + "id": "ev_2dHOWGQueF2dKPsvf7RJZyFW2gD", "name": "catalogAddNewEvent", "rules": { "$schema": "http://json-schema.org/draft-07/schema#", "properties": { - "context": {}, "properties": { + "additionalProperties": false, + "properties": { + "category": { + "type": ["string"] + }, + "eventName": { + "type": ["string"] + }, + "eventType": { + "type": ["string"] + } + }, + "required": ["eventType", "eventName"], + "type": "object" + } + }, + "type": "object" + } + }, + { + "description": "", + "id": "ev_2dHVbAFFOzhVWMgy4IdcGTd85DB", + "name": "trackingPlanDropEventsTriggered", + "rules": { + "$schema": "http://json-schema.org/draft-07/schema#", + "properties": { + "properties": { + "additionalProperties": false, + "properties": { + "trackingPlanId": { + "type": ["string"] + }, + "trackingPlanName": { + "type": ["string"] + } + }, + "required": ["trackingPlanId", "trackingPlanName"], + "type": "object" + } + }, + "type": "object" + } + }, + { + "description": "", + "id": "ev_2dHVcgqYWoswwFrlytJ2ZZgj7zT", + "name": "trackingPlanCreated", + "rules": { + "$schema": "http://json-schema.org/draft-07/schema#", + "properties": { + "properties": { + "additionalProperties": false, + "properties": { + "trackingPlanId": { + "type": ["string"] + }, + "trackingPlanName": { + "type": ["string"] + } + }, + "required": ["trackingPlanId", "trackingPlanName"], + "type": "object" + } + }, + "type": "object" + } + }, + { + "description": "", + "id": "ev_2dHVeY1cyFxr22r5D7HuEL02o5z", + "name": "trackingPlanConnected", + "rules": { + "$schema": "http://json-schema.org/draft-07/schema#", + "properties": { + "properties": { + "additionalProperties": false, "properties": { - "catagory": { + "sourceId": { + "type": ["array", "string"] + }, + "sourceName": { + "type": ["array", "string"] + }, + "trackingPlanId": { "type": ["string"] }, - "description": { + "trackingPlanName": { + "type": ["string"] + } + }, + "required": ["trackingPlanId", "trackingPlanName", "sourceId", "sourceName"], + "type": "object" + } + }, + "type": "object" + } + }, + { + "description": "", + "id": "ev_2dHVHl8eEgcvfqqPUVSe6mvOH8H", + "name": "catalogAddNewProperty", + "rules": { + "$schema": "http://json-schema.org/draft-07/schema#", + "properties": { + "properties": { + "additionalProperties": false, + "properties": { + "propertyName": { + "type": ["string"] + }, + "propertyType": { + "type": ["string"] + } + }, + "required": ["propertyName"], + "type": "object" + } + }, + "type": "object" + } + }, + { + "description": "", + "id": "ev_2dHVhs7coz8XONMAy5MHNR8W6MW", + "name": "trackingPlanEventsViewed", + "rules": { + "$schema": "http://json-schema.org/draft-07/schema#", + "properties": { + "properties": { + "additionalProperties": false, + "properties": { + "trackingPlanId": { + "type": ["string"] + } + }, + "required": ["trackingPlanId"], + "type": "object" + } + }, + "type": "object" + } + }, + { + "description": "", + "id": "ev_2dHVJuD1fisdhMJhWjLefkWbgHL", + "name": "catalogDeleteEvent", + "rules": { + "$schema": "http://json-schema.org/draft-07/schema#", + "properties": { + "properties": { + "additionalProperties": false, + "properties": { + "category": { "type": ["string"] }, "eventName": { "type": ["string"] }, - "type": { + "eventType": { + "type": ["string"] + } + }, + "required": ["eventName", "eventType"], + "type": "object" + } + }, + "type": "object" + } + }, + { + "description": "", + "id": "ev_2dHVLTohcxZVKqzhHP6zddZxFm4", + "name": "catalogDeleteProperty", + "rules": { + "$schema": "http://json-schema.org/draft-07/schema#", + "properties": { + "properties": { + "additionalProperties": false, + "properties": { + "propertyName": { + "type": ["string"] + }, + "propertyType": { + "type": ["string"] + } + }, + "required": ["propertyName"], + "type": "object" + } + }, + "type": "object" + } + }, + { + "description": "", + "id": "ev_2dHVm47DBviVf4uCkYt1NTyB7Qn", + "name": "trackingPlanEdited", + "rules": { + "$schema": "http://json-schema.org/draft-07/schema#", + "properties": { + "properties": { + "additionalProperties": false, + "properties": { + "trackingPlanId": { + "type": ["string"] + }, + "trackingPlanName": { + "type": ["string"] + } + }, + "required": ["trackingPlanId", "trackingPlanName"], + "type": "object" + } + }, + "type": "object" + } + }, + { + "description": "", + "id": "ev_2dHVPfy3LoaGoib3oXgFZ1do7wq", + "name": "clickAddTrackingPlan", + "rules": { + "$schema": "http://json-schema.org/draft-07/schema#", + "properties": { + "properties": { + "additionalProperties": false, + "properties": { + "trackingPlanImportType": { + "type": ["string"] + } + }, + "required": ["trackingPlanImportType"], + "type": "object" + } + }, + "type": "object" + } + }, + { + "description": "", + "id": "ev_2dHVqBFB5AfntsTsuwcLjKblHOm", + "name": "trackingPlanDraftCreated", + "rules": { + "$schema": "http://json-schema.org/draft-07/schema#", + "properties": { + "properties": { + "additionalProperties": false, + "properties": { + "trackingPlanId": { + "type": ["string"] + }, + "trackingPlanName": { "type": ["string"] } }, + "required": ["trackingPlanId", "trackingPlanName"], "type": "object" - }, - "traits": {} + } }, "type": "object" - }, - "version": "2-0-0" + } } ] }, - "update_time": "2024-02-26T11:52:03.590Z", - "version": 1 + "updatedAt": "2024-03-14T10:43:50.237Z", + "version": 9, + "workspaceId": "1Rgdwcyd93G37qqMOs03KWiTQd2" } From 13b4cbbaddf6f4c8ea562041be58740c7f2475e3 Mon Sep 17 00:00:00 2001 From: Akash Gupta Date: Tue, 26 Mar 2024 18:11:22 +0530 Subject: [PATCH 05/10] feat: add temp tp version change --- ruddertyper.yml | 13 +++++++++++++ src/cli/api/api.ts | 34 ++++++++++++++++++++-------------- src/cli/commands/build.tsx | 22 +++++++++------------- src/cli/commands/init.tsx | 6 +++--- src/cli/index.tsx | 2 +- 5 files changed, 46 insertions(+), 31 deletions(-) create mode 100644 ruddertyper.yml diff --git a/ruddertyper.yml b/ruddertyper.yml new file mode 100644 index 00000000..5caf93ea --- /dev/null +++ b/ruddertyper.yml @@ -0,0 +1,13 @@ +# RudderStack RudderTyper Configuration +# Just run `npx rudder-typer@next` to re-generate a client with the latest versions of these events. + +client: + sdk: analytics.js + language: typescript + +trackingPlans: + # Tracking Plan: workspaces/1Rgdwcyd93G37qqMOs03KWiTQd2/tracking-plans/tp_2cu4qwiLI03Pvkt4TnVaXPvbrBF + # https://api.rudderstack.com/trackingplans/tp_2cu4qwiLI03Pvkt4TnVaXPvbrBF + - id: tp_2cu4qwiLI03Pvkt4TnVaXPvbrBF + workspaceId: 1Rgdwcyd93G37qqMOs03KWiTQd2 + path: dataCatalogTypescript/src diff --git a/src/cli/api/api.ts b/src/cli/api/api.ts index df0ce38b..001ad52b 100644 --- a/src/cli/api/api.ts +++ b/src/cli/api/api.ts @@ -15,16 +15,16 @@ export namespace RudderAPI { export type TrackingPlan = { name: string; - display_name: string; version: string; + id: string; rules: { events: RuleMetadata[]; global: RuleMetadata; identify_traits: RuleMetadata; group_traits: RuleMetadata; }; - create_time: Date; - update_time: Date; + createdAt: Date; + updatedAt: Date; }; export type RuleMetadata = { @@ -38,9 +38,8 @@ export namespace RudderAPI { export type Workspace = { name: string; - display_name: string; id: string; - create_time: Date; + createdAt: Date; }; } @@ -50,15 +49,16 @@ export async function fetchTrackingPlan(options: { token: string; email: string; }): Promise { - const url = `trackingplans/${options.id}`; + const url = + 'workspaces/1Rgdwcyd93G37qqMOs03KWiTQd2/catalog/tracking-plans/tp_2dHb5Dq7Ikav1AT3b2rpeQVoIES'; const response = await apiGet( url, options.token, options.email, ); - response.create_time = new Date(response.create_time); - response.update_time = new Date(response.update_time); + response.createdAt = new Date(response.createdAt); + response.updatedAt = new Date(response.updatedAt); return sanitizeTrackingPlan(response); } @@ -77,8 +77,8 @@ export async function fetchTrackingPlans(options: { ); return response.tracking_plans.map(tp => ({ ...tp, - create_time: new Date(tp.create_time), - update_time: new Date(tp.update_time), + createdAt: new Date(tp.createdAt), + updatedAt: new Date(tp.updatedAt), })); } @@ -94,7 +94,7 @@ export async function fetchWorkspace(options: { ); return { ...resp, - create_time: new Date(resp.create_time), + createdAt: new Date(resp.createdAt), }; } @@ -138,10 +138,16 @@ export async function validateToken( async function apiGet(url: string, token: string, email: string): Promise { const resp = got(url, { baseUrl: - url === 'workspace' ? 'https://api.rudderstack.com/v1' : 'https://api.rudderstack.com/v1/dg', + url === 'workspace' + ? 'https://api.rudderstack.com/v1' + : url === 'trackingplans' + ? 'https://api.rudderstack.com/v1/dg' + : 'https://api.rudderstack.com', headers: { - 'User-Agent': `RudderTyper: ${version})`, - Authorization: `Basic ${Buffer.from(email + ':' + token).toString('base64')}`, + authorization: + url === 'workspace' || url === 'trackingplans' + ? `Basic ${Buffer.from(email + ':' + token).toString('base64')}` + : 'Bearer eyJraWQiOiJocDIwQ1wvTVNsYU9tZXdlcFMrMkZRaHNhb05jeVpMSlNYTXRmaEFwRkc5UT0iLCJhbGciOiJSUzI1NiJ9.eyJjdXN0b206d29ya3NwYWNlUm9sZXMiOiJ7XCIxUmdkd2N5ZDkzRzM3cXFNT3MwM0tXaVRRZDJcIjp7XCJvcmdhbml6YXRpb25JZFwiOlwiMWM4N2VCaEdmUGl5RnF3Nzh3c0tTRDZ3SjBwXCIsXCJyb2xlXCI6XCJtZW1iZXJcIn0sXCIxdGM2eDU1VFNRQzlDNmlLQVdjZWVnMW5HZG9cIjp7XCJvcmdhbml6YXRpb25JZFwiOlwiMXRjNng1QTlEWEtvUHVrOGNCcHhoZWFhZk5sXCIsXCJyb2xlXCI6XCJhZG1pblwifSxcIjI4aTM4eHpIenpHWmFxV2FiQktDcmNETnhjZFwiOntcIm9yZ2FuaXphdGlvbklkXCI6XCIyOGkzOHlmZWUzbkhNbTZxYnRWQnNmcnZMTmtcIixcInJvbGVcIjpcIm1lbWJlclwifSxcIjF6OFFVY1p4NDlmenM0VjN3SXFOSlJIMGVtclwiOntcIm9yZ2FuaXphdGlvbklkXCI6XCIxejhRVHlnMmtlMEFzSW1LMXk1YmlITlRkVGxcIixcInJvbGVcIjpcInJlYWQtd3JpdGVcIn19Iiwic3ViIjoiNTU5MzUwZTEtZDFlZC00NTBiLWEyOWEtNTQyYTViZmZlYzg0IiwiZW1haWxfdmVyaWZpZWQiOnRydWUsImlzcyI6Imh0dHBzOlwvXC9jb2duaXRvLWlkcC51cy1lYXN0LTEuYW1hem9uYXdzLmNvbVwvdXMtZWFzdC0xX0FCWmlUalhpYSIsImN1c3RvbTp0b2tlblZlcnNpb24iOiIxMyIsImNvZ25pdG86dXNlcm5hbWUiOiI1NTkzNTBlMS1kMWVkLTQ1MGItYTI5YS01NDJhNWJmZmVjODQiLCJjdXN0b206dXNlcklkIjoiMXRialRTYm5ObkNQY25mZlJ3MGpTRmxOamljIiwib3JpZ2luX2p0aSI6IjdmNTU4Y2VmLThiNjUtNGY5Ni1iNWI0LTI4MzI2OWQyYzExZCIsImF1ZCI6IjF1ZG1mOGlxMG02ajFtaHUwZjJ0M2tkZGcwIiwiZXZlbnRfaWQiOiI2ODM4ODQ3ZS1jY2ZjLTQwZTItYWM4MC03NzkxMjk4MTNiMmUiLCJ0b2tlbl91c2UiOiJpZCIsImF1dGhfdGltZSI6MTcwOTIxNDU5MCwibmFtZSI6IkFrYXNoIEd1cHRhIiwiZXhwIjoxNzEwNDEzNTk5LCJpYXQiOjE3MTA0MDk5OTksImp0aSI6ImQyZmZjMGRmLTAzZWUtNGQyYi1iNjZmLWZiZGMyYWY5ODgzNyIsImVtYWlsIjoiYWthc2hAcnVkZGVyc3RhY2suY29tIn0.ZictoHuoqTcsD_kVmm9rFiIibbHpvE5sPoGEm7VMlJkxhPi_1OgE5vn-1Y4d2k3zqsxmFtkF_NtQxuCt6pGWHnP9fpTXvEZZ9gSpcC8cEdWefuFUrW9pL8xzPyjsay9uRfnumanCao-pDmf771mDUgUPmCw7z6QPnWagZtilA2mPPkPzFi5w6ebosWhRQ7C5EYzaxz5GIF83KKAG1UwXQ4A7iQptdAndK8G2Xz2BgCLGAaCbxSEOclm4KerUe3XQUyzOMLwfsM7C5ogPt0X_nnrX8MuqJg0WeTC1TcDsnZRhrwb7GctzbHEu1gHHgJKxGTUR2TqpHuSm0B1ZBcUCIg', }, json: true, timeout: 10000, // ms diff --git a/src/cli/commands/build.tsx b/src/cli/commands/build.tsx index dd1ecf9c..c9471382 100644 --- a/src/cli/commands/build.tsx +++ b/src/cli/commands/build.tsx @@ -148,7 +148,7 @@ export const UpdatePlanStep: React.FC = ({ for (const trackingPlanConfig of config.trackingPlans) { // Load the local copy of this Tracking Plan, we'll either use this for generation // or use it to identify what changed with the latest copy of this Tracking Plan. - const previousTrackingPlan = await loadTrackingPlan(configPath, trackingPlanConfig); + const previousTrackingPlan = undefined; // If we don't have a copy of the Tracking Plan, then we would fatal error. Instead, // fallback to pulling down a new copy of the Tracking Plan. @@ -188,7 +188,6 @@ export const UpdatePlanStep: React.FC = ({ setFailedToFindToken(true); } } - newTrackingPlan = newTrackingPlan || previousTrackingPlan; if (!newTrackingPlan) { handleFatalError(wrapError('Unable to fetch Tracking Plan from local cache or API')); @@ -197,19 +196,16 @@ export const UpdatePlanStep: React.FC = ({ const { events } = newTrackingPlan.rules; const trackingPlan: RawTrackingPlan = { - name: newTrackingPlan.display_name, - url: toTrackingPlanURL(newTrackingPlan.name), - id: toTrackingPlanId(newTrackingPlan.name), + name: newTrackingPlan.name, + url: `https://api.rudderstack.com/trackingplans/${newTrackingPlan.id}`, + id: newTrackingPlan.id, version: newTrackingPlan.version, path: trackingPlanConfig.path, - trackCalls: events - // RudderTyper doesn't yet support event versioning. For now, we just choose the most recent version. - .filter(e => events.every(e2 => e.name !== e2.name || e.version >= e2.version)) - .map(e => ({ - ...e.rules, - title: e.name, - description: e.description, - })), + trackCalls: events.map(e => ({ + ...e.rules, + title: e.name, + description: e.description, + })), }; loadedTrackingPlans.push({ diff --git a/src/cli/commands/init.tsx b/src/cli/commands/init.tsx index 65798194..e62f1dfc 100644 --- a/src/cli/commands/init.tsx +++ b/src/cli/commands/init.tsx @@ -656,7 +656,7 @@ const TrackingPlanPrompt: React.FC = ({ // Sort the Tracking Plan alphabetically by display name. const choices = orderBy( trackingPlans.map(tp => ({ - label: tp.display_name, + label: tp.name, value: tp.name, })), 'label', @@ -739,7 +739,7 @@ const SummaryPrompt: React.FC = ({ client, trackingPlans: [ { - name: trackingPlan.display_name, + name: trackingPlan.name, id: tp.id, workspaceSlug: tp.workspaceSlug, path, @@ -772,7 +772,7 @@ const SummaryPrompt: React.FC = ({ { label: 'API Token', value: `${workspace.name} (${token.slice(0, 10)}...)` }, { label: 'Tracking Plan', - value: {trackingPlan.display_name}, + value: {trackingPlan.name}, }, ]; diff --git a/src/cli/index.tsx b/src/cli/index.tsx index 21169847..c9a7e671 100644 --- a/src/cli/index.tsx +++ b/src/cli/index.tsx @@ -244,7 +244,7 @@ async function rudderTyperLibraryProperties( if (cfg && cfg.trackingPlans.length > 0) { const tp = await loadTrackingPlan(args.config, cfg.trackingPlans[0]); if (tp) { - trackingPlanName = tp.display_name; + trackingPlanName = tp.name; } } } catch {} From 0951516111265e8dc448c9b9878edf51fb7c7eff Mon Sep 17 00:00:00 2001 From: Akash Gupta Date: Wed, 3 Apr 2024 15:31:30 +0530 Subject: [PATCH 06/10] feat: update name --- ruddertyper.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruddertyper.yml b/ruddertyper.yml index 5caf93ea..c88edfe3 100644 --- a/ruddertyper.yml +++ b/ruddertyper.yml @@ -9,5 +9,5 @@ trackingPlans: # Tracking Plan: workspaces/1Rgdwcyd93G37qqMOs03KWiTQd2/tracking-plans/tp_2cu4qwiLI03Pvkt4TnVaXPvbrBF # https://api.rudderstack.com/trackingplans/tp_2cu4qwiLI03Pvkt4TnVaXPvbrBF - id: tp_2cu4qwiLI03Pvkt4TnVaXPvbrBF - workspaceId: 1Rgdwcyd93G37qqMOs03KWiTQd2 + workspaceSlug: 1Rgdwcyd93G37qqMOs03KWiTQd2 path: dataCatalogTypescript/src From e4f16eec567a706353ea57793add624727dc1efc Mon Sep 17 00:00:00 2001 From: Akash Gupta Date: Wed, 15 May 2024 18:39:42 +0530 Subject: [PATCH 07/10] feat: add new TP api v2 integration --- src/cli/api/api.ts | 100 +++++++++++++++++++++++++---- src/cli/api/trackingplans.ts | 32 +++++++-- src/cli/commands/build.tsx | 11 ++-- src/cli/commands/init.tsx | 22 +++++-- src/cli/config/ruddertyper.yml.hbs | 2 +- src/cli/config/schema.ts | 5 ++ src/cli/index.tsx | 3 +- 7 files changed, 143 insertions(+), 32 deletions(-) diff --git a/src/cli/api/api.ts b/src/cli/api/api.ts index 001ad52b..f4d1ce40 100644 --- a/src/cli/api/api.ts +++ b/src/cli/api/api.ts @@ -9,29 +9,62 @@ import { APIError } from '../types'; export namespace RudderAPI { export type GetTrackingPlanResponse = TrackingPlan; + export type GetTrackingPlanEventsResponse = TrackingPlanEvents; + + export type GetTrackingPlanEventsRulesResponse = { + name: string; + description?: string; + rules: JSONSchema7; + }; + export type ListTrackingPlansResponse = { tracking_plans: TrackingPlan[]; }; + export type ListTrackingPlansResponseV2 = { + trackingPlans: TrackingPlan[]; + }; + export type TrackingPlan = { name: string; + display_name: string; version: string; id: string; rules: { events: RuleMetadata[]; - global: RuleMetadata; - identify_traits: RuleMetadata; - group_traits: RuleMetadata; + global?: RuleMetadata; + identify_traits?: RuleMetadata; + group_traits?: RuleMetadata; }; + create_time: Date; + update_time: Date; createdAt: Date; updatedAt: Date; + creationType: string; + workspaceId: string; + }; + + export type TrackingPlanEvents = { + data: { + id: string; + name: string; + description: string; + eventType: string; + categoryId: string; + workspaceId: string; + createdBy: string; + updatedBy: string; + createdAt: Date; + updatedAt: Date; + identitySection: string; + additionalProperties: boolean; + }[]; }; export type RuleMetadata = { name: string; description?: string; rules: JSONSchema7; - version: number; }; export type ListWorkspacesResponse = Workspace; @@ -48,9 +81,10 @@ export async function fetchTrackingPlan(options: { id: string; token: string; email: string; + APIVersion: string; }): Promise { const url = - 'workspaces/1Rgdwcyd93G37qqMOs03KWiTQd2/catalog/tracking-plans/tp_2dHb5Dq7Ikav1AT3b2rpeQVoIES'; + options.APIVersion === 'v1' ? `trackingplans/${options.id}` : `tracking-plans/${options.id}`; const response = await apiGet( url, options.token, @@ -60,6 +94,36 @@ export async function fetchTrackingPlan(options: { response.createdAt = new Date(response.createdAt); response.updatedAt = new Date(response.updatedAt); + if (!response.rules) { + const url = `tracking-plans/${options.id}/events`; + const eventsResponse = await apiGet( + url, + options.token, + options.email, + ); + let eventsRulesResponse: RudderAPI.RuleMetadata[]; + if (eventsResponse) { + const eventsRulesResponsePromise = eventsResponse.data + .filter(ev => ev.eventType === 'track') + .map(async ev => { + const url = `tracking-plans/${options.id}/events/${ev.id}`; + const eventsRulesResponse = await apiGet( + url, + options.token, + options.email, + ); + return { + name: eventsRulesResponse.name, + description: eventsRulesResponse.description, + rules: eventsRulesResponse.rules, + }; + }); + eventsRulesResponse = await Promise.all(eventsRulesResponsePromise); + response.rules = { + events: eventsRulesResponse, + }; + } + } return sanitizeTrackingPlan(response); } @@ -69,17 +133,31 @@ export async function fetchTrackingPlans(options: { token: string; email: string; }): Promise { - const url = 'trackingplans'; + let url = 'trackingplans'; const response = await apiGet( url, options.token, options.email, ); - return response.tracking_plans.map(tp => ({ + response.tracking_plans.map(tp => ({ + ...tp, + createdAt: new Date(tp.create_time), + updatedAt: new Date(tp.update_time), + })); + + url = 'tracking-plans'; + const responseV2 = await apiGet( + url, + options.token, + options.email, + ); + responseV2.trackingPlans.map(tp => ({ ...tp, createdAt: new Date(tp.createdAt), updatedAt: new Date(tp.updatedAt), })); + + return response.tracking_plans.concat(responseV2.trackingPlans); } // fetchWorkspace lists the workspace found with a given Rudder API token. @@ -140,14 +218,14 @@ async function apiGet(url: string, token: string, email: string): Prom baseUrl: url === 'workspace' ? 'https://api.rudderstack.com/v1' - : url === 'trackingplans' + : url.includes('trackingplans') ? 'https://api.rudderstack.com/v1/dg' - : 'https://api.rudderstack.com', + : 'https://api.rudderstack.com/v2/catalog', headers: { authorization: - url === 'workspace' || url === 'trackingplans' + url === 'workspace' || url.includes('trackingplans') ? `Basic ${Buffer.from(email + ':' + token).toString('base64')}` - : 'Bearer eyJraWQiOiJocDIwQ1wvTVNsYU9tZXdlcFMrMkZRaHNhb05jeVpMSlNYTXRmaEFwRkc5UT0iLCJhbGciOiJSUzI1NiJ9.eyJjdXN0b206d29ya3NwYWNlUm9sZXMiOiJ7XCIxUmdkd2N5ZDkzRzM3cXFNT3MwM0tXaVRRZDJcIjp7XCJvcmdhbml6YXRpb25JZFwiOlwiMWM4N2VCaEdmUGl5RnF3Nzh3c0tTRDZ3SjBwXCIsXCJyb2xlXCI6XCJtZW1iZXJcIn0sXCIxdGM2eDU1VFNRQzlDNmlLQVdjZWVnMW5HZG9cIjp7XCJvcmdhbml6YXRpb25JZFwiOlwiMXRjNng1QTlEWEtvUHVrOGNCcHhoZWFhZk5sXCIsXCJyb2xlXCI6XCJhZG1pblwifSxcIjI4aTM4eHpIenpHWmFxV2FiQktDcmNETnhjZFwiOntcIm9yZ2FuaXphdGlvbklkXCI6XCIyOGkzOHlmZWUzbkhNbTZxYnRWQnNmcnZMTmtcIixcInJvbGVcIjpcIm1lbWJlclwifSxcIjF6OFFVY1p4NDlmenM0VjN3SXFOSlJIMGVtclwiOntcIm9yZ2FuaXphdGlvbklkXCI6XCIxejhRVHlnMmtlMEFzSW1LMXk1YmlITlRkVGxcIixcInJvbGVcIjpcInJlYWQtd3JpdGVcIn19Iiwic3ViIjoiNTU5MzUwZTEtZDFlZC00NTBiLWEyOWEtNTQyYTViZmZlYzg0IiwiZW1haWxfdmVyaWZpZWQiOnRydWUsImlzcyI6Imh0dHBzOlwvXC9jb2duaXRvLWlkcC51cy1lYXN0LTEuYW1hem9uYXdzLmNvbVwvdXMtZWFzdC0xX0FCWmlUalhpYSIsImN1c3RvbTp0b2tlblZlcnNpb24iOiIxMyIsImNvZ25pdG86dXNlcm5hbWUiOiI1NTkzNTBlMS1kMWVkLTQ1MGItYTI5YS01NDJhNWJmZmVjODQiLCJjdXN0b206dXNlcklkIjoiMXRialRTYm5ObkNQY25mZlJ3MGpTRmxOamljIiwib3JpZ2luX2p0aSI6IjdmNTU4Y2VmLThiNjUtNGY5Ni1iNWI0LTI4MzI2OWQyYzExZCIsImF1ZCI6IjF1ZG1mOGlxMG02ajFtaHUwZjJ0M2tkZGcwIiwiZXZlbnRfaWQiOiI2ODM4ODQ3ZS1jY2ZjLTQwZTItYWM4MC03NzkxMjk4MTNiMmUiLCJ0b2tlbl91c2UiOiJpZCIsImF1dGhfdGltZSI6MTcwOTIxNDU5MCwibmFtZSI6IkFrYXNoIEd1cHRhIiwiZXhwIjoxNzEwNDEzNTk5LCJpYXQiOjE3MTA0MDk5OTksImp0aSI6ImQyZmZjMGRmLTAzZWUtNGQyYi1iNjZmLWZiZGMyYWY5ODgzNyIsImVtYWlsIjoiYWthc2hAcnVkZGVyc3RhY2suY29tIn0.ZictoHuoqTcsD_kVmm9rFiIibbHpvE5sPoGEm7VMlJkxhPi_1OgE5vn-1Y4d2k3zqsxmFtkF_NtQxuCt6pGWHnP9fpTXvEZZ9gSpcC8cEdWefuFUrW9pL8xzPyjsay9uRfnumanCao-pDmf771mDUgUPmCw7z6QPnWagZtilA2mPPkPzFi5w6ebosWhRQ7C5EYzaxz5GIF83KKAG1UwXQ4A7iQptdAndK8G2Xz2BgCLGAaCbxSEOclm4KerUe3XQUyzOMLwfsM7C5ogPt0X_nnrX8MuqJg0WeTC1TcDsnZRhrwb7GctzbHEu1gHHgJKxGTUR2TqpHuSm0B1ZBcUCIg', + : 'Bearer ' + token, }, json: true, timeout: 10000, // ms diff --git a/src/cli/api/trackingplans.ts b/src/cli/api/trackingplans.ts index 327baf9c..2d8700a4 100644 --- a/src/cli/api/trackingplans.ts +++ b/src/cli/api/trackingplans.ts @@ -107,7 +107,9 @@ export function computeDelta( return deltas; } -export function parseTrackingPlanName(name: string): { id: string; workspaceSlug: string } { +export function parseTrackingPlanName( + name: string, +): { id: string; workspaceSlug: string; APIVersion: string } { const parts = name.split('/'); // Sane fallback: @@ -121,15 +123,31 @@ export function parseTrackingPlanName(name: string): { id: string; workspaceSlug return { id, workspaceSlug, + APIVersion: 'v1', }; } -export function toTrackingPlanURL(name: string): string { - const { id } = parseTrackingPlanName(name); - return `https://api.rudderstack.com/trackingplans/${id}`; +export function toTrackingPlanURL(trackingPlan: RudderAPI.TrackingPlan): string { + if (!trackingPlan.creationType) { + const { id } = parseTrackingPlanName(trackingPlan.name); + return `https://api.rudderstack.com/trackingplans/${id}`; + } + return `https://api.rudderstack.com/tracking-plans/${trackingPlan.id}`; +} + +export function toTrackingPlanId(trackingPlan: RudderAPI.TrackingPlan): string { + if (!trackingPlan.creationType) { + const { id } = parseTrackingPlanName(trackingPlan.name); + return id; + } + return trackingPlan.id; } -export function toTrackingPlanId(name: string): string { - const { id } = parseTrackingPlanName(name); - return id; +export function getTrackingPlanName(trackingPlan: RudderAPI.TrackingPlan): string { + // throw new Error(`Unable to parse Tracking Plan name: ${JSON.stringify(trackingPlan)}`); + if (!trackingPlan.creationType) { + return trackingPlan.display_name; + } + + return trackingPlan.name; } diff --git a/src/cli/commands/build.tsx b/src/cli/commands/build.tsx index c9471382..3bb8979b 100644 --- a/src/cli/commands/build.tsx +++ b/src/cli/commands/build.tsx @@ -31,7 +31,7 @@ import { ErrorContext, wrapError, toUnexpectedError, WrappedError, isWrappedErro import figures from 'figures'; import { Init } from './init'; import { getEmail } from '../config/config'; -import { toTrackingPlanId } from '../api/trackingplans'; +import { getTrackingPlanName, toTrackingPlanId } from '../api/trackingplans'; import { APIError } from '../types'; const readFile = promisify(fs.readFile); @@ -148,7 +148,7 @@ export const UpdatePlanStep: React.FC = ({ for (const trackingPlanConfig of config.trackingPlans) { // Load the local copy of this Tracking Plan, we'll either use this for generation // or use it to identify what changed with the latest copy of this Tracking Plan. - const previousTrackingPlan = undefined; + const previousTrackingPlan = await loadTrackingPlan(configPath, trackingPlanConfig); // If we don't have a copy of the Tracking Plan, then we would fatal error. Instead, // fallback to pulling down a new copy of the Tracking Plan. @@ -170,6 +170,7 @@ export const UpdatePlanStep: React.FC = ({ workspaceSlug: trackingPlanConfig.workspaceSlug, token, email, + APIVersion: trackingPlanConfig.APIVersion, }); } catch (error) { handleError(error as WrappedError); @@ -196,9 +197,9 @@ export const UpdatePlanStep: React.FC = ({ const { events } = newTrackingPlan.rules; const trackingPlan: RawTrackingPlan = { - name: newTrackingPlan.name, - url: `https://api.rudderstack.com/trackingplans/${newTrackingPlan.id}`, - id: newTrackingPlan.id, + name: getTrackingPlanName(newTrackingPlan), + url: toTrackingPlanURL(newTrackingPlan), + id: toTrackingPlanId(newTrackingPlan), version: newTrackingPlan.version, path: trackingPlanConfig.path, trackCalls: events.map(e => ({ diff --git a/src/cli/commands/init.tsx b/src/cli/commands/init.tsx index e62f1dfc..b43d2292 100644 --- a/src/cli/commands/init.tsx +++ b/src/cli/commands/init.tsx @@ -23,6 +23,7 @@ import Fuse from 'fuse.js'; import { StandardProps, DebugContext } from '../index'; import { ErrorContext, WrappedError, wrapError } from './error'; import { APIError } from '../types'; +import { getTrackingPlanName } from '../api/trackingplans'; const readir = promisify(fs.readdir); @@ -649,20 +650,23 @@ const TrackingPlanPrompt: React.FC = ({ }, []); const onSelect = (item: Item) => { - const trackingPlan = trackingPlans.find(tp => tp.name === item.value)!; + const trackingPlan = trackingPlans.find(tp => getTrackingPlanName(tp) === item.value)!; onSubmit(trackingPlan); }; // Sort the Tracking Plan alphabetically by display name. const choices = orderBy( trackingPlans.map(tp => ({ - label: tp.name, - value: tp.name, + label: getTrackingPlanName(tp), + value: getTrackingPlanName(tp), })), 'label', + 'asc', ); - let initialIndex = choices.findIndex(c => !!trackingPlan && c.value === trackingPlan.name); + let initialIndex = choices.findIndex( + c => !!trackingPlan && c.value === getTrackingPlanName(trackingPlan), + ); initialIndex = initialIndex === -1 ? 0 : initialIndex; const tips = [ @@ -733,16 +737,19 @@ const SummaryPrompt: React.FC = ({ client.moduleTarget = 'CommonJS'; client.scriptTarget = 'ES5'; } - const tp = parseTrackingPlanName(trackingPlan.name); + const tp = !!trackingPlan.creationType + ? { id: trackingPlan.id, workspaceSlug: trackingPlan.workspaceId, APIVersion: 'v2' } + : parseTrackingPlanName(trackingPlan.name); try { const config: Config = { client, trackingPlans: [ { - name: trackingPlan.name, + name: getTrackingPlanName(trackingPlan), id: tp.id, workspaceSlug: tp.workspaceSlug, path, + APIVersion: tp.APIVersion, }, ], }; @@ -770,9 +777,10 @@ const SummaryPrompt: React.FC = ({ { label: 'Language', value: language }, { label: 'Directory', value: path }, { label: 'API Token', value: `${workspace.name} (${token.slice(0, 10)}...)` }, + { label: 'API Version', value: trackingPlan.creationType ? 'v2' : 'v1' }, { label: 'Tracking Plan', - value: {trackingPlan.name}, + value: {getTrackingPlanName(trackingPlan)}, }, ]; diff --git a/src/cli/config/ruddertyper.yml.hbs b/src/cli/config/ruddertyper.yml.hbs index 96b9a055..b8555829 100644 --- a/src/cli/config/ruddertyper.yml.hbs +++ b/src/cli/config/ruddertyper.yml.hbs @@ -18,5 +18,5 @@ trackingPlans: - id: {{id}} workspaceSlug: {{workspaceSlug}} path: {{path}} - + APIVersion: {{APIVersion}} {{/each}} diff --git a/src/cli/config/schema.ts b/src/cli/config/schema.ts index 454f4ce8..9e07f335 100644 --- a/src/cli/config/schema.ts +++ b/src/cli/config/schema.ts @@ -44,6 +44,10 @@ export type TrackingPlanConfig = { * this Tracking Plan's client should be output. */ path: string; + /** + * The API version to use for the tracking plan + */ + APIVersion: string; }; // Ignore Prettier here, since otherwise prettier adds quite a bit of spacing @@ -81,6 +85,7 @@ const ConfigSchema = Joi.object().required().keys({ id: Joi.string().required().min(1), workspaceSlug: Joi.string().required().min(1), path: Joi.string().required().min(1), + APIVersion: Joi.string().required().min(1), }) ), }) diff --git a/src/cli/index.tsx b/src/cli/index.tsx index c9a7e671..45590462 100644 --- a/src/cli/index.tsx +++ b/src/cli/index.tsx @@ -12,6 +12,7 @@ import { machineId } from 'node-machine-id'; import { version } from '../../package.json'; import { loadTrackingPlan } from './api'; import yargs from 'yargs'; +import { getTrackingPlanName } from './api/trackingplans'; export type StandardProps = AnalyticsProps & { configPath: string; @@ -244,7 +245,7 @@ async function rudderTyperLibraryProperties( if (cfg && cfg.trackingPlans.length > 0) { const tp = await loadTrackingPlan(args.config, cfg.trackingPlans[0]); if (tp) { - trackingPlanName = tp.name; + trackingPlanName = getTrackingPlanName(tp); } } } catch {} From d9cd0f2177e0f18fb26d06b50dd30a94a79d7d55 Mon Sep 17 00:00:00 2001 From: Akash Gupta Date: Wed, 15 May 2024 18:44:30 +0530 Subject: [PATCH 08/10] feat: cleanup --- dataCatalogTypescript/.npmignore | 2 - dataCatalogTypescript/.npmrc | 2 - dataCatalogTypescript/.nvmrc | 1 - dataCatalogTypescript/package.json | 18 - dataCatalogTypescript/src/index.ts | 568 ---------------------------- dataCatalogTypescript/src/plan.json | 291 -------------- dataCatalogTypescript/src/rudder.ts | 106 ------ dataCatalogTypescript/tsconfig.json | 12 - ruddertyper.yml | 13 - 9 files changed, 1013 deletions(-) delete mode 100644 dataCatalogTypescript/.npmignore delete mode 100644 dataCatalogTypescript/.npmrc delete mode 100644 dataCatalogTypescript/.nvmrc delete mode 100644 dataCatalogTypescript/package.json delete mode 100644 dataCatalogTypescript/src/index.ts delete mode 100644 dataCatalogTypescript/src/plan.json delete mode 100644 dataCatalogTypescript/src/rudder.ts delete mode 100644 dataCatalogTypescript/tsconfig.json delete mode 100644 ruddertyper.yml diff --git a/dataCatalogTypescript/.npmignore b/dataCatalogTypescript/.npmignore deleted file mode 100644 index f4bcc81a..00000000 --- a/dataCatalogTypescript/.npmignore +++ /dev/null @@ -1,2 +0,0 @@ -node_modules/ -src \ No newline at end of file diff --git a/dataCatalogTypescript/.npmrc b/dataCatalogTypescript/.npmrc deleted file mode 100644 index c08a5538..00000000 --- a/dataCatalogTypescript/.npmrc +++ /dev/null @@ -1,2 +0,0 @@ -//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN} -@rudderlabs:registry=https://npm.pkg.github.com \ No newline at end of file diff --git a/dataCatalogTypescript/.nvmrc b/dataCatalogTypescript/.nvmrc deleted file mode 100644 index 7ec56198..00000000 --- a/dataCatalogTypescript/.nvmrc +++ /dev/null @@ -1 +0,0 @@ -18.17.1 \ No newline at end of file diff --git a/dataCatalogTypescript/package.json b/dataCatalogTypescript/package.json deleted file mode 100644 index 531d6d36..00000000 --- a/dataCatalogTypescript/package.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "name": "@rudderlabs/rudder-typer-webapp", - "version": "1.0.0-beta.13", - "description": "Rudder-Typer analytics libraries are based on your pre-defined tracking plan specifications.", - "main": "dist/index.js", - "types": "dist/index.d.ts", - "scripts": { - "build": "tsc" - }, - "author": "rudderlabs", - "license": "MIT", - "dependencies": { - "rudder-sdk-js": "^2.48.2" - }, - "devDependencies": { - "typescript": "^5.3.3" - } -} diff --git a/dataCatalogTypescript/src/index.ts b/dataCatalogTypescript/src/index.ts deleted file mode 100644 index 0215d8ad..00000000 --- a/dataCatalogTypescript/src/index.ts +++ /dev/null @@ -1,568 +0,0 @@ -/** - * This client was automatically generated by RudderTyper. ** Do Not Edit ** - */ - -import * as Rudder from './rudder' -import { apiCallback } from 'rudder-sdk-js' - -export interface CatalogAddNewEvent { - category?: string - eventName: string - eventType: string -} -export interface TrackingPlanDropEventsTriggered { - trackingPlanId: string - trackingPlanName: string -} -export interface TrackingPlanCreated { - trackingPlanId: string - trackingPlanName: string -} -export interface TrackingPlanConnected { - sourceId: any[] | string - sourceName: any[] | string - trackingPlanId: string - trackingPlanName: string -} -export interface CatalogAddNewProperty { - propertyName: string - propertyType?: string -} -export interface TrackingPlanEventsViewed { - trackingPlanId: string -} -export interface CatalogDeleteEvent { - category?: string - eventName: string - eventType: string -} -export interface CatalogDeleteProperty { - propertyName: string - propertyType?: string -} -export interface TrackingPlanEdited { - trackingPlanId: string - trackingPlanName: string -} -export interface ClickAddTrackingPlan { - trackingPlanImportType: string -} -export interface TrackingPlanDraftCreated { - trackingPlanId: string - trackingPlanName: string -} - -export type ViolationHandler = ( - message: Record, - violations: any[] -) => void - -let analytics: () => any | undefined = () => { - return window.rudderanalytics -} - -/** Options to customize the runtime behavior of a RudderTyper client. */ -export interface RudderTyperOptions { - /** - * Underlying analytics instance where analytics calls are forwarded on to. - * Defaults to window.rudderanalytics. - */ - analytics?: any - /** - * Handler fired when if an event does not match its spec. This handler - * does not fire in production mode, because it requires inlining the full - * JSON Schema spec for each event in your Tracking Plan. - * - * By default, it will throw errors if NODE_ENV = "test" so that tests will fail - * if a message does not match the spec. Otherwise, errors will be logged to stderr. - */ - onViolation?: ViolationHandler -} - -/** - * Updates the run-time configuration of this RudderTyper client. - * - * @param {RudderTyperOptions} options - the options to upsert - * - * @typedef {Object} RudderTyperOptions - * @property {Rudder.AnalyticsJS} [analytics] - Underlying analytics instance where analytics - * calls are forwarded on to. Defaults to window.analytics. - * @property {Function} [onViolation] - Handler fired when if an event does not match its spec. This handler does not fire in - * production mode, because it requires inlining the full JSON Schema spec for each event in your Tracking Plan. By default, - * it will throw errors if NODE_ENV="test" so that tests will fail if a message does not match the spec. Otherwise, errors - * will be logged to stderr. - */ -export function setRudderTyperOptions(options: RudderTyperOptions) { - analytics = options.analytics - ? () => options.analytics || window.rudderanalytics - : analytics -} - -/** - * Helper to attach metadata on RudderTyper to outbound requests. - * This is used for attribution and debugging by the RudderStack team. - */ -function withRudderTyperContext(message: Rudder.Options = {}): Rudder.Options { - return { - ...message, - context: { - ...(message.context || {}), - ruddertyper: { - sdk: 'analytics.js', - language: 'typescript', - rudderTyperVersion: '1.0.0-beta.5', - trackingPlanId: 'tp_2dHb5Dq7Ikav1AT3b2rpeQVoIES', - trackingPlanVersion: '9', - }, - }, - } -} - -/** - * @typedef CatalogAddNewEvent - * @property {string} [category] - - * @property {string} eventName - - * @property {string} eventType - - */ -/** - * @typedef TrackingPlanDropEventsTriggered - * @property {string} trackingPlanId - - * @property {string} trackingPlanName - - */ -/** - * @typedef TrackingPlanCreated - * @property {string} trackingPlanId - - * @property {string} trackingPlanName - - */ -/** - * @typedef TrackingPlanConnected - * @property {any[] | string} sourceId - - * @property {any[] | string} sourceName - - * @property {string} trackingPlanId - - * @property {string} trackingPlanName - - */ -/** - * @typedef CatalogAddNewProperty - * @property {string} propertyName - - * @property {string} [propertyType] - - */ -/** - * @typedef TrackingPlanEventsViewed - * @property {string} trackingPlanId - - */ -/** - * @typedef CatalogDeleteEvent - * @property {string} [category] - - * @property {string} eventName - - * @property {string} eventType - - */ -/** - * @typedef CatalogDeleteProperty - * @property {string} propertyName - - * @property {string} [propertyType] - - */ -/** - * @typedef TrackingPlanEdited - * @property {string} trackingPlanId - - * @property {string} trackingPlanName - - */ -/** - * @typedef ClickAddTrackingPlan - * @property {string} trackingPlanImportType - - */ -/** - * @typedef TrackingPlanDraftCreated - * @property {string} trackingPlanId - - * @property {string} trackingPlanName - - */ - -/** - * Fires a 'catalogAddNewEvent' track call. - * - * @param {CatalogAddNewEvent} [props] - The analytics properties that will be sent to RudderStack. - * @param {Object} [options] - A dictionary of options. For example, enable or disable specific destinations for the call. - * @param {Function} [callback] - An optional callback called after a short timeout after the analytics - * call is fired. - */ -export function catalogAddNewEvent( - props?: CatalogAddNewEvent, - options?: Rudder.Options, - callback?: apiCallback -): void { - const a = analytics() - if (a) { - a.track( - 'catalogAddNewEvent', - props || {}, - withRudderTyperContext(options), - callback - ) - } -} -/** - * Fires a 'trackingPlanDropEventsTriggered' track call. - * - * @param {TrackingPlanDropEventsTriggered} [props] - The analytics properties that will be sent to RudderStack. - * @param {Object} [options] - A dictionary of options. For example, enable or disable specific destinations for the call. - * @param {Function} [callback] - An optional callback called after a short timeout after the analytics - * call is fired. - */ -export function trackingPlanDropEventsTriggered( - props?: TrackingPlanDropEventsTriggered, - options?: Rudder.Options, - callback?: apiCallback -): void { - const a = analytics() - if (a) { - a.track( - 'trackingPlanDropEventsTriggered', - props || {}, - withRudderTyperContext(options), - callback - ) - } -} -/** - * Fires a 'trackingPlanCreated' track call. - * - * @param {TrackingPlanCreated} [props] - The analytics properties that will be sent to RudderStack. - * @param {Object} [options] - A dictionary of options. For example, enable or disable specific destinations for the call. - * @param {Function} [callback] - An optional callback called after a short timeout after the analytics - * call is fired. - */ -export function trackingPlanCreated( - props?: TrackingPlanCreated, - options?: Rudder.Options, - callback?: apiCallback -): void { - const a = analytics() - if (a) { - a.track( - 'trackingPlanCreated', - props || {}, - withRudderTyperContext(options), - callback - ) - } -} -/** - * Fires a 'trackingPlanConnected' track call. - * - * @param {TrackingPlanConnected} [props] - The analytics properties that will be sent to RudderStack. - * @param {Object} [options] - A dictionary of options. For example, enable or disable specific destinations for the call. - * @param {Function} [callback] - An optional callback called after a short timeout after the analytics - * call is fired. - */ -export function trackingPlanConnected( - props?: TrackingPlanConnected, - options?: Rudder.Options, - callback?: apiCallback -): void { - const a = analytics() - if (a) { - a.track( - 'trackingPlanConnected', - props || {}, - withRudderTyperContext(options), - callback - ) - } -} -/** - * Fires a 'catalogAddNewProperty' track call. - * - * @param {CatalogAddNewProperty} [props] - The analytics properties that will be sent to RudderStack. - * @param {Object} [options] - A dictionary of options. For example, enable or disable specific destinations for the call. - * @param {Function} [callback] - An optional callback called after a short timeout after the analytics - * call is fired. - */ -export function catalogAddNewProperty( - props?: CatalogAddNewProperty, - options?: Rudder.Options, - callback?: apiCallback -): void { - const a = analytics() - if (a) { - a.track( - 'catalogAddNewProperty', - props || {}, - withRudderTyperContext(options), - callback - ) - } -} -/** - * Fires a 'trackingPlanEventsViewed' track call. - * - * @param {TrackingPlanEventsViewed} [props] - The analytics properties that will be sent to RudderStack. - * @param {Object} [options] - A dictionary of options. For example, enable or disable specific destinations for the call. - * @param {Function} [callback] - An optional callback called after a short timeout after the analytics - * call is fired. - */ -export function trackingPlanEventsViewed( - props?: TrackingPlanEventsViewed, - options?: Rudder.Options, - callback?: apiCallback -): void { - const a = analytics() - if (a) { - a.track( - 'trackingPlanEventsViewed', - props || {}, - withRudderTyperContext(options), - callback - ) - } -} -/** - * Fires a 'catalogDeleteEvent' track call. - * - * @param {CatalogDeleteEvent} [props] - The analytics properties that will be sent to RudderStack. - * @param {Object} [options] - A dictionary of options. For example, enable or disable specific destinations for the call. - * @param {Function} [callback] - An optional callback called after a short timeout after the analytics - * call is fired. - */ -export function catalogDeleteEvent( - props?: CatalogDeleteEvent, - options?: Rudder.Options, - callback?: apiCallback -): void { - const a = analytics() - if (a) { - a.track( - 'catalogDeleteEvent', - props || {}, - withRudderTyperContext(options), - callback - ) - } -} -/** - * Fires a 'catalogDeleteProperty' track call. - * - * @param {CatalogDeleteProperty} [props] - The analytics properties that will be sent to RudderStack. - * @param {Object} [options] - A dictionary of options. For example, enable or disable specific destinations for the call. - * @param {Function} [callback] - An optional callback called after a short timeout after the analytics - * call is fired. - */ -export function catalogDeleteProperty( - props?: CatalogDeleteProperty, - options?: Rudder.Options, - callback?: apiCallback -): void { - const a = analytics() - if (a) { - a.track( - 'catalogDeleteProperty', - props || {}, - withRudderTyperContext(options), - callback - ) - } -} -/** - * Fires a 'trackingPlanEdited' track call. - * - * @param {TrackingPlanEdited} [props] - The analytics properties that will be sent to RudderStack. - * @param {Object} [options] - A dictionary of options. For example, enable or disable specific destinations for the call. - * @param {Function} [callback] - An optional callback called after a short timeout after the analytics - * call is fired. - */ -export function trackingPlanEdited( - props?: TrackingPlanEdited, - options?: Rudder.Options, - callback?: apiCallback -): void { - const a = analytics() - if (a) { - a.track( - 'trackingPlanEdited', - props || {}, - withRudderTyperContext(options), - callback - ) - } -} -/** - * Fires a 'clickAddTrackingPlan' track call. - * - * @param {ClickAddTrackingPlan} [props] - The analytics properties that will be sent to RudderStack. - * @param {Object} [options] - A dictionary of options. For example, enable or disable specific destinations for the call. - * @param {Function} [callback] - An optional callback called after a short timeout after the analytics - * call is fired. - */ -export function clickAddTrackingPlan( - props?: ClickAddTrackingPlan, - options?: Rudder.Options, - callback?: apiCallback -): void { - const a = analytics() - if (a) { - a.track( - 'clickAddTrackingPlan', - props || {}, - withRudderTyperContext(options), - callback - ) - } -} -/** - * Fires a 'trackingPlanDraftCreated' track call. - * - * @param {TrackingPlanDraftCreated} [props] - The analytics properties that will be sent to RudderStack. - * @param {Object} [options] - A dictionary of options. For example, enable or disable specific destinations for the call. - * @param {Function} [callback] - An optional callback called after a short timeout after the analytics - * call is fired. - */ -export function trackingPlanDraftCreated( - props?: TrackingPlanDraftCreated, - options?: Rudder.Options, - callback?: apiCallback -): void { - const a = analytics() - if (a) { - a.track( - 'trackingPlanDraftCreated', - props || {}, - withRudderTyperContext(options), - callback - ) - } -} - -const clientAPI = { - /** - * Updates the run-time configuration of this RudderTyper client. - * - * @param {RudderTyperOptions} options - the options to upsert - * - * @typedef {Object} RudderTyperOptions - * @property {Rudder.AnalyticsJS} [analytics] - Underlying analytics instance where analytics - * calls are forwarded on to. Defaults to window.analytics. - * @property {Function} [onViolation] - Handler fired when if an event does not match its spec. This handler does not fire in - * production mode, because it requires inlining the full JSON Schema spec for each event in your Tracking Plan. By default, - * it will throw errors if NODE_ENV="test" so that tests will fail if a message does not match the spec. Otherwise, errors - * will be logged to stderr. - */ - setRudderTyperOptions, - /** - * Fires a 'catalogAddNewEvent' track call. - * - * @param {CatalogAddNewEvent} [props] - The analytics properties that will be sent to RudderStack. - * @param {Object} [options] - A dictionary of options. For example, enable or disable specific destinations for the call. - * @param {Function} [callback] - An optional callback called after a short timeout after the analytics - * call is fired. - */ - catalogAddNewEvent, - /** - * Fires a 'trackingPlanDropEventsTriggered' track call. - * - * @param {TrackingPlanDropEventsTriggered} [props] - The analytics properties that will be sent to RudderStack. - * @param {Object} [options] - A dictionary of options. For example, enable or disable specific destinations for the call. - * @param {Function} [callback] - An optional callback called after a short timeout after the analytics - * call is fired. - */ - trackingPlanDropEventsTriggered, - /** - * Fires a 'trackingPlanCreated' track call. - * - * @param {TrackingPlanCreated} [props] - The analytics properties that will be sent to RudderStack. - * @param {Object} [options] - A dictionary of options. For example, enable or disable specific destinations for the call. - * @param {Function} [callback] - An optional callback called after a short timeout after the analytics - * call is fired. - */ - trackingPlanCreated, - /** - * Fires a 'trackingPlanConnected' track call. - * - * @param {TrackingPlanConnected} [props] - The analytics properties that will be sent to RudderStack. - * @param {Object} [options] - A dictionary of options. For example, enable or disable specific destinations for the call. - * @param {Function} [callback] - An optional callback called after a short timeout after the analytics - * call is fired. - */ - trackingPlanConnected, - /** - * Fires a 'catalogAddNewProperty' track call. - * - * @param {CatalogAddNewProperty} [props] - The analytics properties that will be sent to RudderStack. - * @param {Object} [options] - A dictionary of options. For example, enable or disable specific destinations for the call. - * @param {Function} [callback] - An optional callback called after a short timeout after the analytics - * call is fired. - */ - catalogAddNewProperty, - /** - * Fires a 'trackingPlanEventsViewed' track call. - * - * @param {TrackingPlanEventsViewed} [props] - The analytics properties that will be sent to RudderStack. - * @param {Object} [options] - A dictionary of options. For example, enable or disable specific destinations for the call. - * @param {Function} [callback] - An optional callback called after a short timeout after the analytics - * call is fired. - */ - trackingPlanEventsViewed, - /** - * Fires a 'catalogDeleteEvent' track call. - * - * @param {CatalogDeleteEvent} [props] - The analytics properties that will be sent to RudderStack. - * @param {Object} [options] - A dictionary of options. For example, enable or disable specific destinations for the call. - * @param {Function} [callback] - An optional callback called after a short timeout after the analytics - * call is fired. - */ - catalogDeleteEvent, - /** - * Fires a 'catalogDeleteProperty' track call. - * - * @param {CatalogDeleteProperty} [props] - The analytics properties that will be sent to RudderStack. - * @param {Object} [options] - A dictionary of options. For example, enable or disable specific destinations for the call. - * @param {Function} [callback] - An optional callback called after a short timeout after the analytics - * call is fired. - */ - catalogDeleteProperty, - /** - * Fires a 'trackingPlanEdited' track call. - * - * @param {TrackingPlanEdited} [props] - The analytics properties that will be sent to RudderStack. - * @param {Object} [options] - A dictionary of options. For example, enable or disable specific destinations for the call. - * @param {Function} [callback] - An optional callback called after a short timeout after the analytics - * call is fired. - */ - trackingPlanEdited, - /** - * Fires a 'clickAddTrackingPlan' track call. - * - * @param {ClickAddTrackingPlan} [props] - The analytics properties that will be sent to RudderStack. - * @param {Object} [options] - A dictionary of options. For example, enable or disable specific destinations for the call. - * @param {Function} [callback] - An optional callback called after a short timeout after the analytics - * call is fired. - */ - clickAddTrackingPlan, - /** - * Fires a 'trackingPlanDraftCreated' track call. - * - * @param {TrackingPlanDraftCreated} [props] - The analytics properties that will be sent to RudderStack. - * @param {Object} [options] - A dictionary of options. For example, enable or disable specific destinations for the call. - * @param {Function} [callback] - An optional callback called after a short timeout after the analytics - * call is fired. - */ - trackingPlanDraftCreated, -} - -export const RudderTyperAnalytics = new Proxy(clientAPI, { - get(target, method) { - if (typeof method === 'string' && Object.keys(target).includes(method)) { - return target[method as keyof typeof clientAPI] - } - - return () => { - const a = analytics() - if (a) { - a.track( - 'Unknown Analytics Call Fired', - { - method, - }, - withRudderTyperContext() - ) - } - } - }, -}) diff --git a/dataCatalogTypescript/src/plan.json b/dataCatalogTypescript/src/plan.json deleted file mode 100644 index 436660f2..00000000 --- a/dataCatalogTypescript/src/plan.json +++ /dev/null @@ -1,291 +0,0 @@ -{ - "config": { - "group": "traits", - "identify": "traits", - "page": "properties", - "screen": "properties", - "track": "properties" - }, - "createdAt": "2024-03-05T19:42:45.616Z", - "creationType": "Manual", - "description": "Analytics for Data Catalog and Tracking Plan", - "id": "tp_2dHb5Dq7Ikav1AT3b2rpeQVoIES", - "name": "Catalog Event Tracking", - "rules": { - "events": [ - { - "description": "", - "id": "ev_2dHOWGQueF2dKPsvf7RJZyFW2gD", - "name": "catalogAddNewEvent", - "rules": { - "$schema": "http://json-schema.org/draft-07/schema#", - "properties": { - "properties": { - "additionalProperties": false, - "properties": { - "category": { - "type": ["string"] - }, - "eventName": { - "type": ["string"] - }, - "eventType": { - "type": ["string"] - } - }, - "required": ["eventType", "eventName"], - "type": "object" - } - }, - "type": "object" - } - }, - { - "description": "", - "id": "ev_2dHVbAFFOzhVWMgy4IdcGTd85DB", - "name": "trackingPlanDropEventsTriggered", - "rules": { - "$schema": "http://json-schema.org/draft-07/schema#", - "properties": { - "properties": { - "additionalProperties": false, - "properties": { - "trackingPlanId": { - "type": ["string"] - }, - "trackingPlanName": { - "type": ["string"] - } - }, - "required": ["trackingPlanId", "trackingPlanName"], - "type": "object" - } - }, - "type": "object" - } - }, - { - "description": "", - "id": "ev_2dHVcgqYWoswwFrlytJ2ZZgj7zT", - "name": "trackingPlanCreated", - "rules": { - "$schema": "http://json-schema.org/draft-07/schema#", - "properties": { - "properties": { - "additionalProperties": false, - "properties": { - "trackingPlanId": { - "type": ["string"] - }, - "trackingPlanName": { - "type": ["string"] - } - }, - "required": ["trackingPlanId", "trackingPlanName"], - "type": "object" - } - }, - "type": "object" - } - }, - { - "description": "", - "id": "ev_2dHVeY1cyFxr22r5D7HuEL02o5z", - "name": "trackingPlanConnected", - "rules": { - "$schema": "http://json-schema.org/draft-07/schema#", - "properties": { - "properties": { - "additionalProperties": false, - "properties": { - "sourceId": { - "type": ["array", "string"] - }, - "sourceName": { - "type": ["array", "string"] - }, - "trackingPlanId": { - "type": ["string"] - }, - "trackingPlanName": { - "type": ["string"] - } - }, - "required": ["trackingPlanId", "trackingPlanName", "sourceId", "sourceName"], - "type": "object" - } - }, - "type": "object" - } - }, - { - "description": "", - "id": "ev_2dHVHl8eEgcvfqqPUVSe6mvOH8H", - "name": "catalogAddNewProperty", - "rules": { - "$schema": "http://json-schema.org/draft-07/schema#", - "properties": { - "properties": { - "additionalProperties": false, - "properties": { - "propertyName": { - "type": ["string"] - }, - "propertyType": { - "type": ["string"] - } - }, - "required": ["propertyName"], - "type": "object" - } - }, - "type": "object" - } - }, - { - "description": "", - "id": "ev_2dHVhs7coz8XONMAy5MHNR8W6MW", - "name": "trackingPlanEventsViewed", - "rules": { - "$schema": "http://json-schema.org/draft-07/schema#", - "properties": { - "properties": { - "additionalProperties": false, - "properties": { - "trackingPlanId": { - "type": ["string"] - } - }, - "required": ["trackingPlanId"], - "type": "object" - } - }, - "type": "object" - } - }, - { - "description": "", - "id": "ev_2dHVJuD1fisdhMJhWjLefkWbgHL", - "name": "catalogDeleteEvent", - "rules": { - "$schema": "http://json-schema.org/draft-07/schema#", - "properties": { - "properties": { - "additionalProperties": false, - "properties": { - "category": { - "type": ["string"] - }, - "eventName": { - "type": ["string"] - }, - "eventType": { - "type": ["string"] - } - }, - "required": ["eventName", "eventType"], - "type": "object" - } - }, - "type": "object" - } - }, - { - "description": "", - "id": "ev_2dHVLTohcxZVKqzhHP6zddZxFm4", - "name": "catalogDeleteProperty", - "rules": { - "$schema": "http://json-schema.org/draft-07/schema#", - "properties": { - "properties": { - "additionalProperties": false, - "properties": { - "propertyName": { - "type": ["string"] - }, - "propertyType": { - "type": ["string"] - } - }, - "required": ["propertyName"], - "type": "object" - } - }, - "type": "object" - } - }, - { - "description": "", - "id": "ev_2dHVm47DBviVf4uCkYt1NTyB7Qn", - "name": "trackingPlanEdited", - "rules": { - "$schema": "http://json-schema.org/draft-07/schema#", - "properties": { - "properties": { - "additionalProperties": false, - "properties": { - "trackingPlanId": { - "type": ["string"] - }, - "trackingPlanName": { - "type": ["string"] - } - }, - "required": ["trackingPlanId", "trackingPlanName"], - "type": "object" - } - }, - "type": "object" - } - }, - { - "description": "", - "id": "ev_2dHVPfy3LoaGoib3oXgFZ1do7wq", - "name": "clickAddTrackingPlan", - "rules": { - "$schema": "http://json-schema.org/draft-07/schema#", - "properties": { - "properties": { - "additionalProperties": false, - "properties": { - "trackingPlanImportType": { - "type": ["string"] - } - }, - "required": ["trackingPlanImportType"], - "type": "object" - } - }, - "type": "object" - } - }, - { - "description": "", - "id": "ev_2dHVqBFB5AfntsTsuwcLjKblHOm", - "name": "trackingPlanDraftCreated", - "rules": { - "$schema": "http://json-schema.org/draft-07/schema#", - "properties": { - "properties": { - "additionalProperties": false, - "properties": { - "trackingPlanId": { - "type": ["string"] - }, - "trackingPlanName": { - "type": ["string"] - } - }, - "required": ["trackingPlanId", "trackingPlanName"], - "type": "object" - } - }, - "type": "object" - } - } - ] - }, - "updatedAt": "2024-03-14T10:43:50.237Z", - "version": 9, - "workspaceId": "1Rgdwcyd93G37qqMOs03KWiTQd2" -} diff --git a/dataCatalogTypescript/src/rudder.ts b/dataCatalogTypescript/src/rudder.ts deleted file mode 100644 index 976a806b..00000000 --- a/dataCatalogTypescript/src/rudder.ts +++ /dev/null @@ -1,106 +0,0 @@ -/** - * This client was automatically generated by RudderTyper. ** Do Not Edit ** - */ -/** - * The analytics.js snippet should be available via window.analytics. - * You can install it by following instructions at: https://docs.rudderstack.com/stream-sources/rudderstack-sdk-integration-guides/rudderstack-javascript-sdk#2-installing-the-rudderstack-javascript-sdk - */ -declare global { - interface Window { - rudderanalytics: any - } -} - -/** The Schema object which is being used by Ajv to validate the message */ -export interface Schema { - $schema?: string - description?: string - properties?: object - title?: string - type?: string -} - -/** A dictionary of options. For example, enable or disable specific destinations for the call. */ -export interface Options { - /** - * Selectivly filter destinations. By default all destinations are enabled. - * https://docs.rudderstack.com/stream-sources/rudderstack-sdk-integration-guides/rudderstack-javascript-sdk#4-how-to-filter-selective-destinations-to-send-event-data - */ - integrations?: { - [key: string]: boolean | { [key: string]: any } - } - /** - * A dictionary of extra context to attach to the call. - */ - context?: Context -} - -/** - * Context is a dictionary of extra information that provides useful context about a datapoint. - */ -export interface Context extends Record { - active?: boolean - app?: { - name?: string - version?: string - build?: string - } - campaign?: { - name?: string - source?: string - medium?: string - term?: string - content?: string - } - device?: { - id?: string - manufacturer?: string - model?: string - name?: string - type?: string - version?: string - } - ip?: string - locale?: string - location?: { - city?: string - country?: string - latitude?: string - longitude?: string - region?: string - speed?: string - } - network?: { - bluetooth?: string - carrier?: string - cellular?: string - wifi?: string - } - os?: { - name?: string - version?: string - } - page?: { - hash?: string - path?: string - referrer?: string - search?: string - title?: string - url?: string - } - referrer?: { - type?: string - name?: string - url?: string - link?: string - } - screen?: { - density?: string - height?: string - width?: string - } - timezone?: string - groupId?: string - traits?: Record - userAgent?: string -} diff --git a/dataCatalogTypescript/tsconfig.json b/dataCatalogTypescript/tsconfig.json deleted file mode 100644 index 32e157a3..00000000 --- a/dataCatalogTypescript/tsconfig.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "compilerOptions": { - "outDir": "dist", - "module": "commonjs", - "resolveJsonModule": true, - "esModuleInterop": true, - "skipLibCheck": true, - "declaration": true - }, - "include": ["./src/**/*"], - "exclude": ["node_modules"] -} \ No newline at end of file diff --git a/ruddertyper.yml b/ruddertyper.yml deleted file mode 100644 index c88edfe3..00000000 --- a/ruddertyper.yml +++ /dev/null @@ -1,13 +0,0 @@ -# RudderStack RudderTyper Configuration -# Just run `npx rudder-typer@next` to re-generate a client with the latest versions of these events. - -client: - sdk: analytics.js - language: typescript - -trackingPlans: - # Tracking Plan: workspaces/1Rgdwcyd93G37qqMOs03KWiTQd2/tracking-plans/tp_2cu4qwiLI03Pvkt4TnVaXPvbrBF - # https://api.rudderstack.com/trackingplans/tp_2cu4qwiLI03Pvkt4TnVaXPvbrBF - - id: tp_2cu4qwiLI03Pvkt4TnVaXPvbrBF - workspaceSlug: 1Rgdwcyd93G37qqMOs03KWiTQd2 - path: dataCatalogTypescript/src From 299e73eac0ea06e3325f5bab2855e8cce6443cf4 Mon Sep 17 00:00:00 2001 From: Akash Gupta Date: Wed, 15 May 2024 19:06:47 +0530 Subject: [PATCH 09/10] feat: remove null properties --- src/cli/api/api.ts | 9 +++++++-- src/cli/api/trackingplans.ts | 5 +++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/cli/api/api.ts b/src/cli/api/api.ts index f4d1ce40..7539557c 100644 --- a/src/cli/api/api.ts +++ b/src/cli/api/api.ts @@ -91,8 +91,13 @@ export async function fetchTrackingPlan(options: { options.email, ); - response.createdAt = new Date(response.createdAt); - response.updatedAt = new Date(response.updatedAt); + if (options.APIVersion === 'v1') { + response.create_time = new Date(response.create_time); + response.update_time = new Date(response.update_time); + } else { + response.createdAt = new Date(response.createdAt); + response.updatedAt = new Date(response.updatedAt); + } if (!response.rules) { const url = `tracking-plans/${options.id}/events`; diff --git a/src/cli/api/trackingplans.ts b/src/cli/api/trackingplans.ts index 2d8700a4..e5079ac9 100644 --- a/src/cli/api/trackingplans.ts +++ b/src/cli/api/trackingplans.ts @@ -3,7 +3,7 @@ import { TrackingPlanConfig, resolveRelativePath, verifyDirectoryExists } from ' import sortKeys from 'sort-keys'; import * as fs from 'fs'; import { promisify } from 'util'; -import { flow } from 'lodash'; +import { flow, pickBy } from 'lodash'; import stringify from 'json-stable-stringify'; const writeFile = promisify(fs.writeFile); @@ -55,7 +55,8 @@ export async function writeTrackingPlan( export function sanitizeTrackingPlan(plan: RudderAPI.TrackingPlan): RudderAPI.TrackingPlan { // TODO: on JSON Schema Draft-04, required fields must have at least one element. // Therefore, we strip `required: []` from your rules so this error isn't surfaced. - return sortKeys(plan, { deep: true }); + const cleanupPlan = pickBy(plan, v => v !== null); + return sortKeys(cleanupPlan, { deep: true }); } export type TrackingPlanDeltas = { From 8225907c85705059214af4a699a02df13c606fab Mon Sep 17 00:00:00 2001 From: Akash Gupta Date: Fri, 19 Jul 2024 13:39:10 +0530 Subject: [PATCH 10/10] feat(tracking-plan): refactor --- src/cli/api/api.ts | 21 ++++++++++----------- src/cli/api/trackingplans.ts | 11 ++++------- src/cli/commands/init.tsx | 2 +- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/cli/api/api.ts b/src/cli/api/api.ts index 7539557c..40238309 100644 --- a/src/cli/api/api.ts +++ b/src/cli/api/api.ts @@ -91,22 +91,21 @@ export async function fetchTrackingPlan(options: { options.email, ); - if (options.APIVersion === 'v1') { - response.create_time = new Date(response.create_time); - response.update_time = new Date(response.update_time); - } else { + if (options.APIVersion === 'v2') { response.createdAt = new Date(response.createdAt); response.updatedAt = new Date(response.updatedAt); + } else { + response.create_time = new Date(response.create_time); + response.update_time = new Date(response.update_time); } - if (!response.rules) { + if (options.APIVersion === 'v2') { const url = `tracking-plans/${options.id}/events`; const eventsResponse = await apiGet( url, options.token, options.email, ); - let eventsRulesResponse: RudderAPI.RuleMetadata[]; if (eventsResponse) { const eventsRulesResponsePromise = eventsResponse.data .filter(ev => ev.eventType === 'track') @@ -123,7 +122,9 @@ export async function fetchTrackingPlan(options: { rules: eventsRulesResponse.rules, }; }); - eventsRulesResponse = await Promise.all(eventsRulesResponsePromise); + const eventsRulesResponse: RudderAPI.RuleMetadata[] = await Promise.all( + eventsRulesResponsePromise, + ); response.rules = { events: eventsRulesResponse, }; @@ -138,9 +139,8 @@ export async function fetchTrackingPlans(options: { token: string; email: string; }): Promise { - let url = 'trackingplans'; const response = await apiGet( - url, + 'trackingplans', options.token, options.email, ); @@ -150,9 +150,8 @@ export async function fetchTrackingPlans(options: { updatedAt: new Date(tp.update_time), })); - url = 'tracking-plans'; const responseV2 = await apiGet( - url, + 'tracking-plans', options.token, options.email, ); diff --git a/src/cli/api/trackingplans.ts b/src/cli/api/trackingplans.ts index e5079ac9..0aef4458 100644 --- a/src/cli/api/trackingplans.ts +++ b/src/cli/api/trackingplans.ts @@ -144,11 +144,8 @@ export function toTrackingPlanId(trackingPlan: RudderAPI.TrackingPlan): string { return trackingPlan.id; } -export function getTrackingPlanName(trackingPlan: RudderAPI.TrackingPlan): string { - // throw new Error(`Unable to parse Tracking Plan name: ${JSON.stringify(trackingPlan)}`); - if (!trackingPlan.creationType) { - return trackingPlan.display_name; - } - - return trackingPlan.name; +export function getTrackingPlanName( + trackingPlan: Pick, +): string { + return !trackingPlan.creationType ? trackingPlan.display_name : trackingPlan.name; } diff --git a/src/cli/commands/init.tsx b/src/cli/commands/init.tsx index b43d2292..10dbef73 100644 --- a/src/cli/commands/init.tsx +++ b/src/cli/commands/init.tsx @@ -737,7 +737,7 @@ const SummaryPrompt: React.FC = ({ client.moduleTarget = 'CommonJS'; client.scriptTarget = 'ES5'; } - const tp = !!trackingPlan.creationType + const tp = trackingPlan.creationType ? { id: trackingPlan.id, workspaceSlug: trackingPlan.workspaceId, APIVersion: 'v2' } : parseTrackingPlanName(trackingPlan.name); try {