Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/four-pots-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@clerk/astro": patch
---

Introduce option to opt-out of telemetry data collection
2 changes: 2 additions & 0 deletions packages/astro/src/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ interface InternalEnv {
readonly PUBLIC_CLERK_PROXY_URL?: string;
readonly PUBLIC_CLERK_SIGN_IN_URL?: string;
readonly PUBLIC_CLERK_SIGN_UP_URL?: string;
readonly PUBLIC_CLERK_TELEMETRY_DISABLED?: string;
readonly PUBLIC_CLERK_TELEMETRY_DEBUG?: string;
}

interface ImportMeta {
Expand Down
4 changes: 2 additions & 2 deletions packages/astro/src/integration/create-integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ function createIntegration<Params extends HotloadAstroClerkIntegrationParams>()

const buildImportPath = `${packageName}/internal`;

// Set params as envs do backend code has access to them
// Set params as envs so backend code has access to them
updateConfig({
vite: {
define: {
/**
* Convert the integration params to environment variable in order for be readable from the server
* Convert the integration params to environment variable in order for it to be readable from the server
*/
...buildEnvVarFromOption(signInUrl, 'PUBLIC_CLERK_SIGN_IN_URL'),
...buildEnvVarFromOption(signUpUrl, 'PUBLIC_CLERK_SIGN_UP_URL'),
Expand Down
7 changes: 7 additions & 0 deletions packages/astro/src/internal/merge-env-vars-with-params.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { isTruthy } from '@clerk/shared/underscore';

import type { AstroClerkIntegrationParams } from '../types';

/**
Expand All @@ -11,6 +13,7 @@ const mergeEnvVarsWithParams = (params?: AstroClerkIntegrationParams & { publish
proxyUrl: paramProxy,
domain: paramDomain,
publishableKey: paramPublishableKey,
telemetry: paramTelemetry,
...rest
} = params || {};

Expand All @@ -21,6 +24,10 @@ const mergeEnvVarsWithParams = (params?: AstroClerkIntegrationParams & { publish
proxyUrl: paramProxy || import.meta.env.PUBLIC_CLERK_PROXY_URL,
domain: paramDomain || import.meta.env.PUBLIC_CLERK_DOMAIN,
publishableKey: paramPublishableKey || import.meta.env.PUBLIC_CLERK_PUBLISHABLE_KEY || '',
telemetry: paramTelemetry || {
disabled: isTruthy(import.meta.env.PUBLIC_CLERK_TELEMETRY_DISABLED),
debug: isTruthy(import.meta.env.PUBLIC_CLERK_TELEMETRY_DEBUG),
},
Comment on lines +27 to +30

@wobsoriano wobsoriano Jul 24, 2024

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This gets passed to Clerk.load() function

...rest,
};
};
Expand Down
4 changes: 4 additions & 0 deletions packages/astro/src/server/clerk-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ const createClerkClientWithOptions: CreateClerkClientWithOptions = (context, opt
// eslint-disable-next-line turbo/no-undeclared-env-vars
environment: import.meta.env.MODE,
},
telemetry: {
disabled: getSafeEnv(context).telemetryDisabled,
debug: getSafeEnv(context).telemetryDebug,
},
...options,
});

Expand Down
5 changes: 4 additions & 1 deletion packages/astro/src/server/get-safe-env.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { isTruthy } from '@clerk/shared/underscore';
import type { APIContext } from 'astro';

type ContextOrLocals = APIContext | APIContext['locals'];

/**
* @internal
* Isomorphic handler for reading environemnt variables defined from Vite or are injected in the request context (CF Pages)
* Isomorphic handler for reading environment variables defined from Vite or are injected in the request context (CF Pages)
*/
function getContextEnvVar(envVarName: keyof InternalEnv, contextOrLocals: ContextOrLocals): string | undefined {
const locals = 'locals' in contextOrLocals ? contextOrLocals.locals : contextOrLocals;
Expand Down Expand Up @@ -33,6 +34,8 @@ function getSafeEnv(context: ContextOrLocals) {
clerkJsVersion: getContextEnvVar('PUBLIC_CLERK_JS_VERSION', context),
apiVersion: getContextEnvVar('CLERK_API_VERSION', context),
apiUrl: getContextEnvVar('CLERK_API_URL', context),
telemetryDisabled: isTruthy(getContextEnvVar('PUBLIC_CLERK_TELEMETRY_DISABLED', context)),

@wobsoriano wobsoriano Jul 24, 2024

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for the createClerkClient function

telemetryDebug: isTruthy(getContextEnvVar('PUBLIC_CLERK_TELEMETRY_DEBUG', context)),
};
}

Expand Down
1 change: 0 additions & 1 deletion packages/astro/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ type AstroClerkIntegrationParams = Without<
ClerkOptions,
| 'isSatellite'
| 'sdkMetadata'
| 'telemetry'
| 'standardBrowser'
| 'selectInitialSession'
| 'routerReplace'
Expand Down