Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
append referral code to share links (#2019)
Will Hutchinson141b02cc477c
diff --git a/js/app/packages/block-pdf/signal/location.ts b/js/app/packages/block-pdf/signal/location.tsindex 1b8d58f41e..a9bcde650b 100644--- a/js/app/packages/block-pdf/signal/location.ts+++ b/js/app/packages/block-pdf/signal/location.ts@@ -16,6 +16,7 @@ import {setTempRedirectLocation,type TempRedirectLocation,} from '@core/signal/location';+import { useReferralCode } from '@core/context/user';import { buildSimpleEntityUrl } from '@core/util/url';import { waitForSignal } from '@core/util/waitForSignal';import { createCallback } from '@solid-primitives/rootless';@@ -280,6 +281,7 @@ export function selectLocationForFidelity(export function useCreateShareUrl() {const locationStore_ = locationStore.get;const blockId = useBlockId();+ const referralCode = useReferralCode();/*** Creates a shareable URL with location information at the specified fidelity level.@@ -301,6 +303,10 @@ export function useCreateShareUrl() {const location = selectLocationForFidelity(fidelity, locations);const url = locationToUrl(location);const params = Object.fromEntries(new URL(url).searchParams);+ const code = referralCode();+ if (code) {+ params.referral_code = code;+ }const updatedUrl = buildSimpleEntityUrl({type: 'pdf',diff --git a/js/app/packages/core/component/TopBar/ShareButton.tsx b/js/app/packages/core/component/TopBar/ShareButton.tsxindex 1c7329836f..ce830ce862 100644--- a/js/app/packages/core/component/TopBar/ShareButton.tsx+++ b/js/app/packages/core/component/TopBar/ShareButton.tsx@@ -47,7 +47,7 @@ import { Dialog } from '@kobalte/core/dialog';import { DropdownMenu } from '@kobalte/core/dropdown-menu';import { cognitionApiServiceClient } from '@service-cognition/client';import { commsServiceClient } from '@service-comms/client';-import { useUserId } from '@core/context/user';+import { useReferralCode, useUserId } from '@core/context/user';import {blockNameToItemType,type ItemType,@@ -209,13 +209,20 @@ export function ShareModal(props: ShareModalProps) {const [recipientScrollRef, setRecipientScrollRef] =createSignal<HTMLElement>();+ const referralCode = useReferralCode();+const copyPublicLink = createCallback(() => {+ const params: Record<string, string> = {};+ const code = referralCode();+ if (code) {+ params.referral_code = code;+ }const url = buildSimpleEntityUrl({type: props.blockAlias,id: props.id,},- {}+ params);navigator.clipboard.writeText(url);toast.success(@@ -755,13 +762,20 @@ export function ShareButton(props: ShareButtonProps) {});});+ const referralCode = useReferralCode();+const defaultUrl = () => {+ const params: Record<string, string> = {};+ const code = referralCode();+ if (code) {+ params.referral_code = code;+ }return buildSimpleEntityUrl({id: blockId ?? '',type: blockType,},- {}+ params);};@@ -905,8 +919,16 @@ export function ShareTrigger(props: { copyLink?: () => void }) {});});- const defaultUrl = () =>- buildSimpleEntityUrl({ id: blockId ?? '', type: blockType }, {});+ const referralCode = useReferralCode();++ const defaultUrl = () => {+ const params: Record<string, string> = {};+ const code = referralCode();+ if (code) {+ params.referral_code = code;+ }+ return buildSimpleEntityUrl({ id: blockId ?? '', type: blockType }, params);+ };const copyLink = createCallback(() => {if (props.copyLink) return props.copyLink();diff --git a/js/app/packages/core/context/user.ts b/js/app/packages/core/context/user.tsindex 4f1de4491d..22ba925f37 100644--- a/js/app/packages/core/context/user.ts+++ b/js/app/packages/core/context/user.ts@@ -32,6 +32,7 @@ type UserContextValue = {hasChromeExt: Accessor<boolean | undefined>;hasTrialed: Accessor<boolean | undefined>;aiDataConsent: Accessor<boolean>;+ referralCode: Accessor<string | undefined>;};export const [UserContextProvider, useUserContext] =@@ -62,6 +63,7 @@ export const [UserContextProvider, useUserContext] =const hasChromeExt = createMemo(() => userInfo()?.hasChromeExt);const hasTrialed = createMemo(() => userInfo()?.hasTrialed);const aiDataConsent = createMemo(() => userInfo()?.aiDataConsent ?? false);+ const referralCode = createMemo(() => userInfo()?.referralCode);return {userInfo,@@ -77,6 +79,7 @@ export const [UserContextProvider, useUserContext] =hasChromeExt,hasTrialed,aiDataConsent,+ referralCode,};});@@ -128,3 +131,7 @@ export function useUserInfo() {export function useAiDataConsent() {return useUserContext().aiDataConsent;}++export function useReferralCode() {+ return useUserContext().referralCode;+}diff --git a/js/app/packages/service-clients/service-auth/client.ts b/js/app/packages/service-clients/service-auth/client.tsindex af53b2389e..1eec547fa6 100644--- a/js/app/packages/service-clients/service-auth/client.ts+++ b/js/app/packages/service-clients/service-auth/client.ts@@ -356,6 +356,7 @@ export const authServiceClient = {userId: data.userId,hasTrialed: data.hasTrialed,aiDataConsent: data.aiDataConsent,+ referralCode: data.referralCode,}));},diff --git a/js/app/packages/service-clients/service-auth/generated/schemas/getLegacyUserPermissionsResponse.ts b/js/app/packages/service-clients/service-auth/generated/schemas/getLegacyUserPermissionsResponse.tsindex 6d99ebba2e..879f860662 100644--- a/js/app/packages/service-clients/service-auth/generated/schemas/getLegacyUserPermissionsResponse.ts+++ b/js/app/packages/service-clients/service-auth/generated/schemas/getLegacyUserPermissionsResponse.ts@@ -23,6 +23,8 @@ export interface GetLegacyUserPermissionsResponse {name?: GetLegacyUserPermissionsResponseName;/** The permissions the user has */permissions: string[];+ /** The referral code for the user */+ referralCode: string;/** Whether the user has completed the tutorial */tutorialComplete: boolean;/** The user id */diff --git a/js/app/packages/service-clients/service-auth/openapi.json b/js/app/packages/service-clients/service-auth/openapi.jsonindex e87d089449..79a922fe6f 100644--- a/js/app/packages/service-clients/service-auth/openapi.json+++ b/js/app/packages/service-clients/service-auth/openapi.json@@ -3084,7 +3084,8 @@"tutorialComplete","hasChromeExt","hasTrialed",- "aiDataConsent"+ "aiDataConsent",+ "referralCode"],"properties": {"aiDataConsent": {@@ -3129,6 +3130,10 @@},"description": "The permissions the user has"},+ "referralCode": {+ "type": "string",+ "description": "The referral code for the user"+ },"tutorialComplete": {"type": "boolean","description": "Whether the user has completed the tutorial"diff --git a/rust/cloud-storage/authentication_service/src/api/user/get_legacy_user_permissions.rs b/rust/cloud-storage/authentication_service/src/api/user/get_legacy_user_permissions.rsindex 9682594199..574fcca3de 100644--- a/rust/cloud-storage/authentication_service/src/api/user/get_legacy_user_permissions.rs+++ b/rust/cloud-storage/authentication_service/src/api/user/get_legacy_user_permissions.rs@@ -36,6 +36,8 @@ pub struct GetLegacyUserPermissionsResponse {has_trialed: bool,/// Whether the user has consented to AI data sharingai_data_consent: bool,+ /// The referral code for the user+ referral_code: String,}#[derive(serde::Serialize, Debug, utoipa::ToSchema)]@@ -134,5 +136,6 @@ pub async fn handler(has_chrome_ext: legacy_user_info.has_chrome_ext,has_trialed: legacy_user_info.has_trialed,ai_data_consent: legacy_user_info.ai_data_consent,+ referral_code: legacy_user_info.referral_code,})}diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-1435acbba365796ddcb6ddbef86f4ebf664cffc44082996f6b60a60373c28f75.json b/rust/cloud-storage/macro_db_client/.sqlx/query-1435acbba365796ddcb6ddbef86f4ebf664cffc44082996f6b60a60373c28f75.jsondeleted file mode 100644index d2b084cf10..0000000000--- a/rust/cloud-storage/macro_db_client/.sqlx/query-1435acbba365796ddcb6ddbef86f4ebf664cffc44082996f6b60a60373c28f75.json+++ /dev/null@@ -1,17 +0,0 @@-{- "db_name": "PostgreSQL",- "query": "\n INSERT INTO entity_properties (id, entity_id, entity_type, property_definition_id, values)\n SELECT \n u.id,\n u.entity_id,\n 'TASK'::property_entity_type,\n u.property_definition_id,\n u.values\n FROM UNNEST(\n $1::UUID[],\n $2::TEXT[],\n $3::UUID[],\n $4::JSONB[]\n ) AS u(id, entity_id, property_definition_id, values)\n ON CONFLICT (entity_id, entity_type, property_definition_id)\n DO UPDATE SET \n values = EXCLUDED.values,\n updated_at = NOW()\n ",- "describe": {- "columns": [],- "parameters": {- "Left": [- "UuidArray",- "TextArray",- "UuidArray",- "JsonbArray"- ]- },- "nullable": []- },- "hash": "1435acbba365796ddcb6ddbef86f4ebf664cffc44082996f6b60a60373c28f75"-}diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-63492b018803ce26db5891964a0f52f37d2f54bd8243265c6561f4423af8617c.json b/rust/cloud-storage/macro_db_client/.sqlx/query-63492b018803ce26db5891964a0f52f37d2f54bd8243265c6561f4423af8617c.jsondeleted file mode 100644index 6d97183829..0000000000--- a/rust/cloud-storage/macro_db_client/.sqlx/query-63492b018803ce26db5891964a0f52f37d2f54bd8243265c6561f4423af8617c.json+++ /dev/null@@ -1,16 +0,0 @@-{- "db_name": "PostgreSQL",- "query": "\n INSERT INTO entity_properties (id, entity_id, entity_type, property_definition_id, values)\n SELECT \n u.id,\n u.entity_id,\n 'TASK'::property_entity_type,\n u.property_definition_id,\n NULL\n FROM UNNEST(\n $1::UUID[],\n $2::TEXT[],\n $3::UUID[]\n ) AS u(id, entity_id, property_definition_id)\n ON CONFLICT (entity_id, entity_type, property_definition_id)\n DO NOTHING\n ",- "describe": {- "columns": [],- "parameters": {- "Left": [- "UuidArray",- "TextArray",- "UuidArray"- ]- },- "nullable": []- },- "hash": "63492b018803ce26db5891964a0f52f37d2f54bd8243265c6561f4423af8617c"-}diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-8a7231404c684a133961181ee74af7cb5142a2e5e80077355bc86b068d90ba2d.json b/rust/cloud-storage/macro_db_client/.sqlx/query-8d25b1711e2c00fe92b1921e1c2ee17e311301f88b1550dbff4eb41b6e12db13.jsonsimilarity index 78%rename from rust/cloud-storage/macro_db_client/.sqlx/query-8a7231404c684a133961181ee74af7cb5142a2e5e80077355bc86b068d90ba2d.jsonrename to rust/cloud-storage/macro_db_client/.sqlx/query-8d25b1711e2c00fe92b1921e1c2ee17e311301f88b1550dbff4eb41b6e12db13.jsonindex 3e10ff4284..9623da14ab 100644--- a/rust/cloud-storage/macro_db_client/.sqlx/query-8a7231404c684a133961181ee74af7cb5142a2e5e80077355bc86b068d90ba2d.json+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-8d25b1711e2c00fe92b1921e1c2ee17e311301f88b1550dbff4eb41b6e12db13.json@@ -1,6 +1,6 @@{"db_name": "PostgreSQL",- "query": "\n SELECT\n u.\"id\" as \"user_id\",\n u.\"email\" as \"email\",\n u.\"stripeCustomerId\" as \"stripe_customer_id?\",\n u.\"name\" as name,\n u.\"tutorialComplete\" as tutorial_complete,\n u.\"group\" as \"group?\",\n u.\"hasChromeExt\" as has_chrome_ext,\n u.\"aiDataConsent\" as ai_data_consent,\n mu.has_trialed as has_trialed\n FROM \"User\" u\n JOIN \"macro_user\" mu ON u.macro_user_id = mu.id\n WHERE u.\"id\" = $1\n ",+ "query": "\n SELECT\n u.\"id\" as \"user_id\",\n u.\"email\" as \"email\",\n u.\"stripeCustomerId\" as \"stripe_customer_id?\",\n u.\"name\" as name,\n u.\"tutorialComplete\" as tutorial_complete,\n u.\"group\" as \"group?\",\n u.\"hasChromeExt\" as has_chrome_ext,\n u.\"aiDataConsent\" as ai_data_consent,\n mu.has_trialed as has_trialed,\n u.macro_user_id as \"macro_user_id\"\n FROM \"User\" u\n JOIN \"macro_user\" mu ON u.macro_user_id = mu.id\n WHERE u.\"id\" = $1\n ","describe": {"columns": [{@@ -47,6 +47,11 @@"ordinal": 8,"name": "has_trialed","type_info": "Bool"+ },+ {+ "ordinal": 9,+ "name": "macro_user_id",+ "type_info": "Uuid"}],"parameters": {@@ -63,8 +68,9 @@true,false,false,+ false,false]},- "hash": "8a7231404c684a133961181ee74af7cb5142a2e5e80077355bc86b068d90ba2d"+ "hash": "8d25b1711e2c00fe92b1921e1c2ee17e311301f88b1550dbff4eb41b6e12db13"}diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-9cd40fbb1ade51e9e0d49792839d1a363cada017252a6f653c2272608189bcc4.json b/rust/cloud-storage/macro_db_client/.sqlx/query-9cd40fbb1ade51e9e0d49792839d1a363cada017252a6f653c2272608189bcc4.jsondeleted file mode 100644index 9d717fa5f9..0000000000--- a/rust/cloud-storage/macro_db_client/.sqlx/query-9cd40fbb1ade51e9e0d49792839d1a363cada017252a6f653c2272608189bcc4.json+++ /dev/null@@ -1,28 +0,0 @@-{- "db_name": "PostgreSQL",- "query": "\n SELECT property_definition_id, values\n FROM entity_properties\n WHERE entity_id = $1\n AND entity_type = 'TASK'\n ",- "describe": {- "columns": [- {- "ordinal": 0,- "name": "property_definition_id",- "type_info": "Uuid"- },- {- "ordinal": 1,- "name": "values",- "type_info": "Jsonb"- }- ],- "parameters": {- "Left": [- "Text"- ]- },- "nullable": [- false,- true- ]- },- "hash": "9cd40fbb1ade51e9e0d49792839d1a363cada017252a6f653c2272608189bcc4"-}diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-cf71680da3444f573f4cddf66b6269bfe31aeee4bbec34b7e6067a855e28f2b7.json b/rust/cloud-storage/macro_db_client/.sqlx/query-cf71680da3444f573f4cddf66b6269bfe31aeee4bbec34b7e6067a855e28f2b7.jsondeleted file mode 100644index 9dc9838dc0..0000000000--- a/rust/cloud-storage/macro_db_client/.sqlx/query-cf71680da3444f573f4cddf66b6269bfe31aeee4bbec34b7e6067a855e28f2b7.json+++ /dev/null@@ -1,15 +0,0 @@-{- "db_name": "PostgreSQL",- "query": "\n UPDATE entity_properties\n SET values = $2\n WHERE entity_id = $1;\n ",- "describe": {- "columns": [],- "parameters": {- "Left": [- "Text",- "Jsonb"- ]- },- "nullable": []- },- "hash": "cf71680da3444f573f4cddf66b6269bfe31aeee4bbec34b7e6067a855e28f2b7"-}diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-f2d5d7aea9918978cd69c14f8afe24156c2fa387e001ee8eaf57e4a70a106069.json b/rust/cloud-storage/macro_db_client/.sqlx/query-f2d5d7aea9918978cd69c14f8afe24156c2fa387e001ee8eaf57e4a70a106069.jsondeleted file mode 100644index 182e0858ba..0000000000--- a/rust/cloud-storage/macro_db_client/.sqlx/query-f2d5d7aea9918978cd69c14f8afe24156c2fa387e001ee8eaf57e4a70a106069.json+++ /dev/null@@ -1,18 +0,0 @@-{- "db_name": "PostgreSQL",- "query": "\n INSERT INTO entity_properties (id, entity_id, entity_type, property_definition_id, values)\n SELECT \n u.id,\n u.entity_id,\n u.entity_type::property_entity_type,\n u.property_definition_id,\n u.values\n FROM UNNEST(\n $1::UUID[],\n $2::TEXT[],\n $3::TEXT[],\n $4::UUID[],\n $5::JSONB[]\n ) AS u(id, entity_id, entity_type, property_definition_id, values)\n ON CONFLICT (entity_id, entity_type, property_definition_id)\n DO UPDATE SET \n values = EXCLUDED.values,\n updated_at = NOW()\n ",- "describe": {- "columns": [],- "parameters": {- "Left": [- "UuidArray",- "TextArray",- "TextArray",- "UuidArray",- "JsonbArray"- ]- },- "nullable": []- },- "hash": "f2d5d7aea9918978cd69c14f8afe24156c2fa387e001ee8eaf57e4a70a106069"-}diff --git a/rust/cloud-storage/macro_db_client/src/user/get/get_legacy_user_info.rs b/rust/cloud-storage/macro_db_client/src/user/get/get_legacy_user_info.rsindex 152b842314..7c50b9d3ac 100644--- a/rust/cloud-storage/macro_db_client/src/user/get/get_legacy_user_info.rs+++ b/rust/cloud-storage/macro_db_client/src/user/get/get_legacy_user_info.rs@@ -1,4 +1,5 @@use macro_user_id::{lowercased::Lowercase, user_id::MacroUserId};+use macro_uuid::ShortUuidConverter;#[derive(Debug, serde::Serialize)]pub struct LegacyUserInfo {@@ -11,6 +12,7 @@ pub struct LegacyUserInfo {pub has_chrome_ext: bool,pub ai_data_consent: bool,pub has_trialed: bool,+ pub referral_code: String,}/// Gets the legacy user info@@ -19,8 +21,9 @@ pub async fn get_legacy_user_info(db: &sqlx::Pool<sqlx::Postgres>,user_id: &MacroUserId<Lowercase<'_>>,) -> anyhow::Result<LegacyUserInfo> {- let result = sqlx::query_as!(- LegacyUserInfo,+ let converter = ShortUuidConverter::default();++ let result = sqlx::query!(r#"SELECTu."id" as "user_id",@@ -31,13 +34,26 @@ pub async fn get_legacy_user_info(u."group" as "group?",u."hasChromeExt" as has_chrome_ext,u."aiDataConsent" as ai_data_consent,- mu.has_trialed as has_trialed+ mu.has_trialed as has_trialed,+ u.macro_user_id as "macro_user_id"FROM "User" uJOIN "macro_user" mu ON u.macro_user_id = mu.idWHERE u."id" = $1"#,user_id.as_ref())+ .map(|row| LegacyUserInfo {+ user_id: row.user_id,+ email: row.email,+ stripe_customer_id: row.stripe_customer_id,+ name: row.name,+ tutorial_complete: row.tutorial_complete,+ group: row.group,+ has_chrome_ext: row.has_chrome_ext,+ ai_data_consent: row.ai_data_consent,+ has_trialed: row.has_trialed,+ referral_code: converter.from_uuid(&row.macro_user_id),+ }).fetch_one(db).await?;