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
15 changes: 15 additions & 0 deletions .changeset/four-days-hammer.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
---
"@clerk/astro": patch
---

Simplify submodules and drop the `bunlded` variant.

Moved
- `@clerk/astro/client/react` to `@clerk/astro/react`
- `@clerk/astro/client/stores` to `@clerk/astro/client`
Dropped
- `@clerk/astro/bundled`
- `@clerk/astro/client/bundled`
- `@clerk/astro/internal/bundled`
- `@clerk/astro/integration`
- `@clerk/astro/integration/bundled`
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
import { useAuth } from '@clerk/astro/client/react';
import { useAuth } from '@clerk/astro/react';
import React from 'react';
import { type PropsWithChildren } from 'react';

Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
import React, { type PropsWithChildren, useSyncExternalStore } from 'react';
import { UserProfile } from '@clerk/astro/client/react';
import { $userStore } from '@clerk/astro/client/stores';
import { UserProfile } from '@clerk/astro/react';
import { $userStore } from '@clerk/astro/client';

export function PageWithUser({ children }: PropsWithChildren) {
const user = useSyncExternalStore($userStore.listen, $userStore.get, $userStore.get);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,7 @@ interface Props {

const { title } = Astro.props;

import { SignedIn, SignedOut, UserButton } from "@clerk/astro/client/react";
import { SignedIn, SignedOut, UserButton } from "@clerk/astro/react";
import { LanguagePicker } from "../../components/LanguagePicker";
---

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,7 +12,7 @@ interface Props extends SignOutOptions {
</script>

<script>
import { $clerkStore } from "@clerk/astro/client/stores";
import { $clerkStore } from "@clerk/astro/client";

const button = document.querySelector(
"[data-sign-out-button]",
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,7 +3,7 @@ import Layout from "../../layouts/react/Layout.astro";
import Card from "../../components/Card.astro";
import SignOutButton from "../../lib/astro-components/SignOutButton.astro";

import { SignedIn, SignedOut, OrganizationSwitcher } from "@clerk/astro/client/react";
import { SignedIn, SignedOut, OrganizationSwitcher } from "@clerk/astro/react";
---

<Layout title="Welcome to Astro.">
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
---
import { Protect } from "@clerk/astro/client/react";
import { Protect } from "@clerk/astro/react";
import Layout from "../../layouts/react/Layout.astro";
---

Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
---
import { Protect } from "@clerk/astro/client/react";
import { Protect } from "@clerk/astro/react";
import Layout from "../../layouts/react/Layout.astro";
---

Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
---
import { SignIn } from "@clerk/astro/client/react";
import { SignIn } from "@clerk/astro/react";
import Layout from "../../layouts/react/Layout.astro";
---

Expand Down
3 changes: 0 additions & 3 deletions packages/astro/client/react/package.json

This file was deleted.

3 changes: 0 additions & 3 deletions packages/astro/client/stores/package.json

This file was deleted.

30 changes: 3 additions & 27 deletions packages/astro/package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -50,46 +50,22 @@
"types": "./dist/index.d.ts",
"import": "./dist/index.js"
},
"./client/react": {
"types": "./dist/client/react/index.d.ts",
"import": "./dist/client/react/index.js"
},
"./client/stores": {
"types": "./dist/client/stores/index.d.ts",
"import": "./dist/client/stores/index.js"
"./react": {
"types": "./dist/react/index.d.ts",
"import": "./dist/react/index.js"
},
"./client": {
"types": "./dist/client/index.d.ts",
"import": "./dist/client/index.js"
},
"./client/bundled": {
"types": "./dist/client/bundled.d.ts",
"import": "./dist/client/bundled.js"
},
"./integration": {
"types": "./dist/integration/index.d.ts",
"import": "./dist/integration/index.js"
},
"./integration/bundled": {
"types": "./dist/integration/bundled.d.ts",
"import": "./dist/integration/bundled.js"
},
"./internal": {
"types": "./dist/internal/index.d.ts",
"import": "./dist/internal/index.js"
},
"./internal/bundled": {
"types": "./dist/internal/bundled.d.ts",
"import": "./dist/internal/bundled.js"
},
"./server": {
"types": "./dist/server/index.d.ts",
"import": "./dist/server/index.js"
},
"./bundled": {
"types": "./dist/bundled.d.ts",
"import": "./dist/bundled.js"
},
"./env": "./env.d.ts",
"./components/control": "./components/control/index.ts",
"./components/control/*": "./components/control/*",
Expand Down
3 changes: 3 additions & 0 deletions packages/astro/react/package.json
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
{
"main": "../../dist/react/index.js"
}
1 change: 0 additions & 1 deletion packages/astro/src/bundled.ts

This file was deleted.

61 changes: 2 additions & 59 deletions packages/astro/src/client/index.ts
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,2 @@
import { waitForClerkScript } from '../internal/utils/loadClerkJSScript';
import { $clerk, $csrState } from '../stores/internal';
import type { AstroClerkIntegrationParams, AstroClerkUpdateOptions } from '../types';
import { mountAllClerkAstroJSComponents } from './mount-clerk-astro-js-components';
import { runOnce } from './run-once';

let initOptions: AstroClerkIntegrationParams | undefined;

/**
* Prevents firing clerk.load multiple times
*/
export const createClerkInstance = runOnce(createClerkInstanceInternal);

export async function createClerkInstanceInternal(options?: AstroClerkIntegrationParams) {
let clerkJSInstance = window.Clerk;
if (!clerkJSInstance) {
await waitForClerkScript();

if (!window.Clerk) {
throw new Error('Failed to download latest ClerkJS. Contact support@clerk.com.');
}
clerkJSInstance = window.Clerk;
}

if (!$clerk.get()) {
// @ts-ignore
$clerk.set(clerkJSInstance);
}

initOptions = options;
// TODO: Update Clerk type from @clerk/types to include this method
return (clerkJSInstance as any)
.load(options)
.then(() => {
$csrState.setKey('isLoaded', true);

mountAllClerkAstroJSComponents();

clerkJSInstance.addListener(payload => {
$csrState.setKey('client', payload.client);
$csrState.setKey('user', payload.user);
$csrState.setKey('session', payload.session);
$csrState.setKey('organization', payload.organization);
});
})
.catch(() => {});
}

export function updateClerkOptions(options: AstroClerkUpdateOptions) {
const clerk = $clerk.get();
if (!clerk) {
throw new Error('Missing clerk instance');
}
// TODO: Update Clerk type from @clerk/types to include this method
void (clerk as any).__unstable__updateProps({
options: { ...initOptions, ...options },
appearance: { ...initOptions?.appearance, ...options.appearance },
});
}
export { updateClerkOptions } from '../internal/create-clerk-instance';
export * from '../stores/external';
1 change: 0 additions & 1 deletion packages/astro/src/client/stores/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/astro/src/globals.d.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,5 +3,4 @@ export {};
declare global {
const PACKAGE_NAME: string;
const PACKAGE_VERSION: string;
const __HOTLOAD__: string;
}
4 changes: 3 additions & 1 deletion packages/astro/src/index.ts
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
export { default } from './integration';
import { createIntegration } from './integration/create-integration';

export default createIntegration();
5 changes: 0 additions & 5 deletions packages/astro/src/integration/bundled.ts

This file was deleted.

12 changes: 3 additions & 9 deletions packages/astro/src/integration/create-integration.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,10 +14,8 @@ type HotloadAstroClerkIntegrationParams = AstroClerkIntegrationParams & {
clerkJSVersion?: string;
};

function createIntegration<P extends { mode: 'hotload' | 'bundled' }>({ mode }: P) {
return (
params?: P['mode'] extends 'hotload' ? HotloadAstroClerkIntegrationParams : AstroClerkIntegrationParams,
): AstroIntegration => {
function createIntegration<Params extends HotloadAstroClerkIntegrationParams>() {
return (params?: Params): AstroIntegration => {
const { proxyUrl, isSatellite, domain, signInUrl, signUpUrl } = params || {};

// These are not provided when the "bundled" integration is used
Expand DownExpand Up@@ -50,10 +48,7 @@ function createIntegration<P extends { mode: 'hotload' | 'bundled' }>({ mode }:
},
};

const defaultBundledImportPath = `${packageName}/internal/bundled`;

const buildImportPath =
mode === 'bundled' ? defaultBundledImportPath : defaultBundledImportPath.replace('/bundled', '');
const buildImportPath = `${packageName}/internal`;

// Set params as envs do backend code has access to them
updateConfig({
Expand All@@ -72,7 +67,6 @@ function createIntegration<P extends { mode: 'hotload' | 'bundled' }>({ mode }:
...buildEnvVarFromOption(clerkJSUrl, 'PUBLIC_CLERK_JS_URL'),
...buildEnvVarFromOption(clerkJSVariant, 'PUBLIC_CLERK_JS_VARIANT'),
...buildEnvVarFromOption(clerkJSVersion, 'PUBLIC_CLERK_JS_VERSION'),
__HOTLOAD__: mode === 'hotload',
},

ssr: {
Expand Down
5 changes: 0 additions & 5 deletions packages/astro/src/integration/index.ts

This file was deleted.

13 changes: 0 additions & 13 deletions packages/astro/src/internal/bundled.ts

This file was deleted.

Original file line numberDiff line numberDiff line change
@@ -1,30 +1,35 @@
import { Clerk } from '@clerk/clerk-js';

import { waitForClerkScript } from '../internal/utils/loadClerkJSScript';
import { $clerk, $csrState } from '../stores/internal';
import type { AstroClerkCreateInstanceParams, AstroClerkUpdateOptions } from '../types';
import type { AstroClerkIntegrationParams, AstroClerkUpdateOptions } from '../types';
import { mountAllClerkAstroJSComponents } from './mount-clerk-astro-js-components';
import { runOnce } from './run-once';
import type { CreateClerkInstanceInternalFn } from './types';

let initOptions: AstroClerkCreateInstanceParams | undefined;
let initOptions: AstroClerkIntegrationParams | undefined;

/**
* Prevents firing clerk.load multiple times
*/
export const createClerkInstance: CreateClerkInstanceInternalFn = runOnce(createClerkInstanceInternal);
const createClerkInstance = runOnce(createClerkInstanceInternal);

export function createClerkInstanceInternal(options?: AstroClerkCreateInstanceParams) {
let clerkJSInstance = window.Clerk as unknown as Clerk;
async function createClerkInstanceInternal(options?: AstroClerkIntegrationParams) {
let clerkJSInstance = window.Clerk;
if (!clerkJSInstance) {
clerkJSInstance = new Clerk(options!.publishableKey);
await waitForClerkScript();

if (!window.Clerk) {
throw new Error('Failed to download latest ClerkJS. Contact support@clerk.com.');
}
clerkJSInstance = window.Clerk;
}

if (!$clerk.get()) {
// @ts-ignore
$clerk.set(clerkJSInstance);
// @ts-ignore
window.Clerk = clerkJSInstance;
}

initOptions = options;
return clerkJSInstance
// TODO: Update Clerk type from @clerk/types to include this method
return (clerkJSInstance as any)
.load(options)
.then(() => {
$csrState.setKey('isLoaded', true);
Expand All@@ -41,14 +46,16 @@ export function createClerkInstanceInternal(options?: AstroClerkCreateInstancePa
.catch(() => {});
}

export function updateClerkOptions(options: AstroClerkUpdateOptions) {
function updateClerkOptions(options: AstroClerkUpdateOptions) {
const clerk = $clerk.get();
if (!clerk) {
throw new Error('Missing clerk instance');
}
//@ts-ignore
clerk.__unstable__updateProps({
// TODO: Update Clerk type from @clerk/types to include this method
void (clerk as any).__unstable__updateProps({
options: { ...initOptions, ...options },
appearance: { ...initOptions?.appearance, ...options.appearance },
});
}

export { createClerkInstance, updateClerkOptions };
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
import type { CreateClerkInstanceInternalFn } from '../client/types';
import { $initialState } from '../stores/internal';
import type { AstroClerkIntegrationParams } from '../types';
import { mergeEnvVarsWithParams } from './merge-env-vars-with-params';
import type { CreateClerkInstanceInternalFn } from './types';

/**
* @internal
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/internal/index.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,7 @@
* injectScript('before-hydration', `...`)
*/

import { createClerkInstance } from '../client';
import { createClerkInstance } from './create-clerk-instance';
import { createInjectionScriptRunner } from './create-injection-script-runner';

const runInjectionScript = createInjectionScriptRunner(createClerkInstance);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,7 +17,9 @@ export const SignOutButton = withClerk(

const clickHandler = () => clerk?.signOut({ redirectUrl, sessionId });
const wrappedChildClickHandler: React.MouseEventHandler = async e => {
await safeExecute((child as any).props.onClick)(e);
if (child && typeof child === 'object' && 'props' in child) {
await safeExecute(child.props.onClick)(e);
}
return clickHandler();
};

Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
import type { CheckAuthorizationWithCustomPermissions } from '@clerk/types';
import type { PropsWithChildren } from 'react';

import type { ProtectComponentDefaultProps } from '../../types';
import type { ProtectComponentDefaultProps } from '../types';
import { useAuth } from './hooks';

export function SignedOut(props: PropsWithChildren) {
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,8 +12,8 @@ import { useCallback, useSyncExternalStore } from 'react';
// @ts-ignore
import { authAsyncStorage } from '#async-local-storage';

import { $authStore } from '../../stores/external';
import { $clerk, $csrState } from '../../stores/internal';
import { $authStore } from '../stores/external';
import { $clerk, $csrState } from '../stores/internal';

type CheckAuthorizationSignedOut = undefined;
type CheckAuthorizationWithoutOrgOrUser = (params?: Parameters<CheckAuthorizationWithCustomPermissions>[0]) => false;
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
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
15 changes: 15 additions & 0 deletions .changeset/four-days-hammer.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
---
"@clerk/astro": patch
---

Simplify submodules and drop the `bunlded` variant.

Moved
- `@clerk/astro/client/react` to `@clerk/astro/react`
- `@clerk/astro/client/stores` to `@clerk/astro/client`
Dropped
- `@clerk/astro/bundled`
- `@clerk/astro/client/bundled`
- `@clerk/astro/internal/bundled`
- `@clerk/astro/integration`
- `@clerk/astro/integration/bundled`
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
import { useAuth } from '@clerk/astro/client/react';
import { useAuth } from '@clerk/astro/react';
import React from 'react';
import { type PropsWithChildren } from 'react';

Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
import React, { type PropsWithChildren, useSyncExternalStore } from 'react';
import { UserProfile } from '@clerk/astro/client/react';
import { $userStore } from '@clerk/astro/client/stores';
import { UserProfile } from '@clerk/astro/react';
import { $userStore } from '@clerk/astro/client';

export function PageWithUser({ children }: PropsWithChildren) {
const user = useSyncExternalStore($userStore.listen, $userStore.get, $userStore.get);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,7 @@ interface Props {

const { title } = Astro.props;

import { SignedIn, SignedOut, UserButton } from "@clerk/astro/client/react";
import { SignedIn, SignedOut, UserButton } from "@clerk/astro/react";
import { LanguagePicker } from "../../components/LanguagePicker";
---

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,7 +12,7 @@ interface Props extends SignOutOptions {
</script>

<script>
import { $clerkStore } from "@clerk/astro/client/stores";
import { $clerkStore } from "@clerk/astro/client";

const button = document.querySelector(
"[data-sign-out-button]",
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,7 +3,7 @@ import Layout from "../../layouts/react/Layout.astro";
import Card from "../../components/Card.astro";
import SignOutButton from "../../lib/astro-components/SignOutButton.astro";

import { SignedIn, SignedOut, OrganizationSwitcher } from "@clerk/astro/client/react";
import { SignedIn, SignedOut, OrganizationSwitcher } from "@clerk/astro/react";
---

<Layout title="Welcome to Astro.">
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
---
import { Protect } from "@clerk/astro/client/react";
import { Protect } from "@clerk/astro/react";
import Layout from "../../layouts/react/Layout.astro";
---

Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
---
import { Protect } from "@clerk/astro/client/react";
import { Protect } from "@clerk/astro/react";
import Layout from "../../layouts/react/Layout.astro";
---

Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
---
import { SignIn } from "@clerk/astro/client/react";
import { SignIn } from "@clerk/astro/react";
import Layout from "../../layouts/react/Layout.astro";
---

Expand Down
3 changes: 0 additions & 3 deletions packages/astro/client/react/package.json

This file was deleted.

3 changes: 0 additions & 3 deletions packages/astro/client/stores/package.json

This file was deleted.

30 changes: 3 additions & 27 deletions packages/astro/package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -50,46 +50,22 @@
"types": "./dist/index.d.ts",
"import": "./dist/index.js"
},
"./client/react": {
"types": "./dist/client/react/index.d.ts",
"import": "./dist/client/react/index.js"
},
"./client/stores": {
"types": "./dist/client/stores/index.d.ts",
"import": "./dist/client/stores/index.js"
"./react": {
"types": "./dist/react/index.d.ts",
"import": "./dist/react/index.js"
},
"./client": {
"types": "./dist/client/index.d.ts",
"import": "./dist/client/index.js"
},
"./client/bundled": {
"types": "./dist/client/bundled.d.ts",
"import": "./dist/client/bundled.js"
},
"./integration": {
"types": "./dist/integration/index.d.ts",
"import": "./dist/integration/index.js"
},
"./integration/bundled": {
"types": "./dist/integration/bundled.d.ts",
"import": "./dist/integration/bundled.js"
},
"./internal": {
"types": "./dist/internal/index.d.ts",
"import": "./dist/internal/index.js"
},
"./internal/bundled": {
"types": "./dist/internal/bundled.d.ts",
"import": "./dist/internal/bundled.js"
},
"./server": {
"types": "./dist/server/index.d.ts",
"import": "./dist/server/index.js"
},
"./bundled": {
"types": "./dist/bundled.d.ts",
"import": "./dist/bundled.js"
},
"./env": "./env.d.ts",
"./components/control": "./components/control/index.ts",
"./components/control/*": "./components/control/*",
Expand Down
3 changes: 3 additions & 0 deletions packages/astro/react/package.json
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
{
"main": "../../dist/react/index.js"
}
1 change: 0 additions & 1 deletion packages/astro/src/bundled.ts

This file was deleted.

61 changes: 2 additions & 59 deletions packages/astro/src/client/index.ts
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,2 @@
import { waitForClerkScript } from '../internal/utils/loadClerkJSScript';
import { $clerk, $csrState } from '../stores/internal';
import type { AstroClerkIntegrationParams, AstroClerkUpdateOptions } from '../types';
import { mountAllClerkAstroJSComponents } from './mount-clerk-astro-js-components';
import { runOnce } from './run-once';

let initOptions: AstroClerkIntegrationParams | undefined;

/**
* Prevents firing clerk.load multiple times
*/
export const createClerkInstance = runOnce(createClerkInstanceInternal);

export async function createClerkInstanceInternal(options?: AstroClerkIntegrationParams) {
let clerkJSInstance = window.Clerk;
if (!clerkJSInstance) {
await waitForClerkScript();

if (!window.Clerk) {
throw new Error('Failed to download latest ClerkJS. Contact support@clerk.com.');
}
clerkJSInstance = window.Clerk;
}

if (!$clerk.get()) {
// @ts-ignore
$clerk.set(clerkJSInstance);
}

initOptions = options;
// TODO: Update Clerk type from @clerk/types to include this method
return (clerkJSInstance as any)
.load(options)
.then(() => {
$csrState.setKey('isLoaded', true);

mountAllClerkAstroJSComponents();

clerkJSInstance.addListener(payload => {
$csrState.setKey('client', payload.client);
$csrState.setKey('user', payload.user);
$csrState.setKey('session', payload.session);
$csrState.setKey('organization', payload.organization);
});
})
.catch(() => {});
}

export function updateClerkOptions(options: AstroClerkUpdateOptions) {
const clerk = $clerk.get();
if (!clerk) {
throw new Error('Missing clerk instance');
}
// TODO: Update Clerk type from @clerk/types to include this method
void (clerk as any).__unstable__updateProps({
options: { ...initOptions, ...options },
appearance: { ...initOptions?.appearance, ...options.appearance },
});
}
export { updateClerkOptions } from '../internal/create-clerk-instance';
export * from '../stores/external';
1 change: 0 additions & 1 deletion packages/astro/src/client/stores/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/astro/src/globals.d.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,5 +3,4 @@ export {};
declare global {
const PACKAGE_NAME: string;
const PACKAGE_VERSION: string;
const __HOTLOAD__: string;
}
4 changes: 3 additions & 1 deletion packages/astro/src/index.ts
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
export { default } from './integration';
import { createIntegration } from './integration/create-integration';

export default createIntegration();
5 changes: 0 additions & 5 deletions packages/astro/src/integration/bundled.ts

This file was deleted.

12 changes: 3 additions & 9 deletions packages/astro/src/integration/create-integration.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,10 +14,8 @@ type HotloadAstroClerkIntegrationParams = AstroClerkIntegrationParams & {
clerkJSVersion?: string;
};

function createIntegration<P extends { mode: 'hotload' | 'bundled' }>({ mode }: P) {
return (
params?: P['mode'] extends 'hotload' ? HotloadAstroClerkIntegrationParams : AstroClerkIntegrationParams,
): AstroIntegration => {
function createIntegration<Params extends HotloadAstroClerkIntegrationParams>() {
return (params?: Params): AstroIntegration => {
const { proxyUrl, isSatellite, domain, signInUrl, signUpUrl } = params || {};

// These are not provided when the "bundled" integration is used
Expand DownExpand Up@@ -50,10 +48,7 @@ function createIntegration<P extends { mode: 'hotload' | 'bundled' }>({ mode }:
},
};

const defaultBundledImportPath = `${packageName}/internal/bundled`;

const buildImportPath =
mode === 'bundled' ? defaultBundledImportPath : defaultBundledImportPath.replace('/bundled', '');
const buildImportPath = `${packageName}/internal`;

// Set params as envs do backend code has access to them
updateConfig({
Expand All@@ -72,7 +67,6 @@ function createIntegration<P extends { mode: 'hotload' | 'bundled' }>({ mode }:
...buildEnvVarFromOption(clerkJSUrl, 'PUBLIC_CLERK_JS_URL'),
...buildEnvVarFromOption(clerkJSVariant, 'PUBLIC_CLERK_JS_VARIANT'),
...buildEnvVarFromOption(clerkJSVersion, 'PUBLIC_CLERK_JS_VERSION'),
__HOTLOAD__: mode === 'hotload',
},

ssr: {
Expand Down
5 changes: 0 additions & 5 deletions packages/astro/src/integration/index.ts

This file was deleted.

13 changes: 0 additions & 13 deletions packages/astro/src/internal/bundled.ts

This file was deleted.

Original file line numberDiff line numberDiff line change
@@ -1,30 +1,35 @@
import { Clerk } from '@clerk/clerk-js';

import { waitForClerkScript } from '../internal/utils/loadClerkJSScript';
import { $clerk, $csrState } from '../stores/internal';
import type { AstroClerkCreateInstanceParams, AstroClerkUpdateOptions } from '../types';
import type { AstroClerkIntegrationParams, AstroClerkUpdateOptions } from '../types';
import { mountAllClerkAstroJSComponents } from './mount-clerk-astro-js-components';
import { runOnce } from './run-once';
import type { CreateClerkInstanceInternalFn } from './types';

let initOptions: AstroClerkCreateInstanceParams | undefined;
let initOptions: AstroClerkIntegrationParams | undefined;

/**
* Prevents firing clerk.load multiple times
*/
export const createClerkInstance: CreateClerkInstanceInternalFn = runOnce(createClerkInstanceInternal);
const createClerkInstance = runOnce(createClerkInstanceInternal);

export function createClerkInstanceInternal(options?: AstroClerkCreateInstanceParams) {
let clerkJSInstance = window.Clerk as unknown as Clerk;
async function createClerkInstanceInternal(options?: AstroClerkIntegrationParams) {
let clerkJSInstance = window.Clerk;
if (!clerkJSInstance) {
clerkJSInstance = new Clerk(options!.publishableKey);
await waitForClerkScript();

if (!window.Clerk) {
throw new Error('Failed to download latest ClerkJS. Contact support@clerk.com.');
}
clerkJSInstance = window.Clerk;
}

if (!$clerk.get()) {
// @ts-ignore
$clerk.set(clerkJSInstance);
// @ts-ignore
window.Clerk = clerkJSInstance;
}

initOptions = options;
return clerkJSInstance
// TODO: Update Clerk type from @clerk/types to include this method
return (clerkJSInstance as any)
.load(options)
.then(() => {
$csrState.setKey('isLoaded', true);
Expand All@@ -41,14 +46,16 @@ export function createClerkInstanceInternal(options?: AstroClerkCreateInstancePa
.catch(() => {});
}

export function updateClerkOptions(options: AstroClerkUpdateOptions) {
function updateClerkOptions(options: AstroClerkUpdateOptions) {
const clerk = $clerk.get();
if (!clerk) {
throw new Error('Missing clerk instance');
}
//@ts-ignore
clerk.__unstable__updateProps({
// TODO: Update Clerk type from @clerk/types to include this method
void (clerk as any).__unstable__updateProps({
options: { ...initOptions, ...options },
appearance: { ...initOptions?.appearance, ...options.appearance },
});
}

export { createClerkInstance, updateClerkOptions };
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
import type { CreateClerkInstanceInternalFn } from '../client/types';
import { $initialState } from '../stores/internal';
import type { AstroClerkIntegrationParams } from '../types';
import { mergeEnvVarsWithParams } from './merge-env-vars-with-params';
import type { CreateClerkInstanceInternalFn } from './types';

/**
* @internal
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/internal/index.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,7 @@
* injectScript('before-hydration', `...`)
*/

import { createClerkInstance } from '../client';
import { createClerkInstance } from './create-clerk-instance';
import { createInjectionScriptRunner } from './create-injection-script-runner';

const runInjectionScript = createInjectionScriptRunner(createClerkInstance);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,7 +17,9 @@ export const SignOutButton = withClerk(

const clickHandler = () => clerk?.signOut({ redirectUrl, sessionId });
const wrappedChildClickHandler: React.MouseEventHandler = async e => {
await safeExecute((child as any).props.onClick)(e);
if (child && typeof child === 'object' && 'props' in child) {
await safeExecute(child.props.onClick)(e);
}
return clickHandler();
};

Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
import type { CheckAuthorizationWithCustomPermissions } from '@clerk/types';
import type { PropsWithChildren } from 'react';

import type { ProtectComponentDefaultProps } from '../../types';
import type { ProtectComponentDefaultProps } from '../types';
import { useAuth } from './hooks';

export function SignedOut(props: PropsWithChildren) {
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,8 +12,8 @@ import { useCallback, useSyncExternalStore } from 'react';
// @ts-ignore
import { authAsyncStorage } from '#async-local-storage';

import { $authStore } from '../../stores/external';
import { $clerk, $csrState } from '../../stores/internal';
import { $authStore } from '../stores/external';
import { $clerk, $csrState } from '../stores/internal';

type CheckAuthorizationSignedOut = undefined;
type CheckAuthorizationWithoutOrgOrUser = (params?: Parameters<CheckAuthorizationWithCustomPermissions>[0]) => false;
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
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
15 changes: 15 additions & 0 deletions .changeset/four-days-hammer.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
---
"@clerk/astro": patch
---

Simplify submodules and drop the `bunlded` variant.

Moved
- `@clerk/astro/client/react` to `@clerk/astro/react`
- `@clerk/astro/client/stores` to `@clerk/astro/client`
Dropped
- `@clerk/astro/bundled`
- `@clerk/astro/client/bundled`
- `@clerk/astro/internal/bundled`
- `@clerk/astro/integration`
- `@clerk/astro/integration/bundled`
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
import { useAuth } from '@clerk/astro/client/react';
import { useAuth } from '@clerk/astro/react';
import React from 'react';
import { type PropsWithChildren } from 'react';

Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
import React, { type PropsWithChildren, useSyncExternalStore } from 'react';
import { UserProfile } from '@clerk/astro/client/react';
import { $userStore } from '@clerk/astro/client/stores';
import { UserProfile } from '@clerk/astro/react';
import { $userStore } from '@clerk/astro/client';

export function PageWithUser({ children }: PropsWithChildren) {
const user = useSyncExternalStore($userStore.listen, $userStore.get, $userStore.get);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,7 @@ interface Props {

const { title } = Astro.props;

import { SignedIn, SignedOut, UserButton } from "@clerk/astro/client/react";
import { SignedIn, SignedOut, UserButton } from "@clerk/astro/react";
import { LanguagePicker } from "../../components/LanguagePicker";
---

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,7 +12,7 @@ interface Props extends SignOutOptions {
</script>

<script>
import { $clerkStore } from "@clerk/astro/client/stores";
import { $clerkStore } from "@clerk/astro/client";

const button = document.querySelector(
"[data-sign-out-button]",
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,7 +3,7 @@ import Layout from "../../layouts/react/Layout.astro";
import Card from "../../components/Card.astro";
import SignOutButton from "../../lib/astro-components/SignOutButton.astro";

import { SignedIn, SignedOut, OrganizationSwitcher } from "@clerk/astro/client/react";
import { SignedIn, SignedOut, OrganizationSwitcher } from "@clerk/astro/react";
---

<Layout title="Welcome to Astro.">
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
---
import { Protect } from "@clerk/astro/client/react";
import { Protect } from "@clerk/astro/react";
import Layout from "../../layouts/react/Layout.astro";
---

Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
---
import { Protect } from "@clerk/astro/client/react";
import { Protect } from "@clerk/astro/react";
import Layout from "../../layouts/react/Layout.astro";
---

Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
---
import { SignIn } from "@clerk/astro/client/react";
import { SignIn } from "@clerk/astro/react";
import Layout from "../../layouts/react/Layout.astro";
---

Expand Down
3 changes: 0 additions & 3 deletions packages/astro/client/react/package.json

This file was deleted.

3 changes: 0 additions & 3 deletions packages/astro/client/stores/package.json

This file was deleted.

30 changes: 3 additions & 27 deletions packages/astro/package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -50,46 +50,22 @@
"types": "./dist/index.d.ts",
"import": "./dist/index.js"
},
"./client/react": {
"types": "./dist/client/react/index.d.ts",
"import": "./dist/client/react/index.js"
},
"./client/stores": {
"types": "./dist/client/stores/index.d.ts",
"import": "./dist/client/stores/index.js"
"./react": {
"types": "./dist/react/index.d.ts",
"import": "./dist/react/index.js"
},
"./client": {
"types": "./dist/client/index.d.ts",
"import": "./dist/client/index.js"
},
"./client/bundled": {
"types": "./dist/client/bundled.d.ts",
"import": "./dist/client/bundled.js"
},
"./integration": {
"types": "./dist/integration/index.d.ts",
"import": "./dist/integration/index.js"
},
"./integration/bundled": {
"types": "./dist/integration/bundled.d.ts",
"import": "./dist/integration/bundled.js"
},
"./internal": {
"types": "./dist/internal/index.d.ts",
"import": "./dist/internal/index.js"
},
"./internal/bundled": {
"types": "./dist/internal/bundled.d.ts",
"import": "./dist/internal/bundled.js"
},
"./server": {
"types": "./dist/server/index.d.ts",
"import": "./dist/server/index.js"
},
"./bundled": {
"types": "./dist/bundled.d.ts",
"import": "./dist/bundled.js"
},
"./env": "./env.d.ts",
"./components/control": "./components/control/index.ts",
"./components/control/*": "./components/control/*",
Expand Down
3 changes: 3 additions & 0 deletions packages/astro/react/package.json
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
{
"main": "../../dist/react/index.js"
}
1 change: 0 additions & 1 deletion packages/astro/src/bundled.ts

This file was deleted.

61 changes: 2 additions & 59 deletions packages/astro/src/client/index.ts
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,2 @@
import { waitForClerkScript } from '../internal/utils/loadClerkJSScript';
import { $clerk, $csrState } from '../stores/internal';
import type { AstroClerkIntegrationParams, AstroClerkUpdateOptions } from '../types';
import { mountAllClerkAstroJSComponents } from './mount-clerk-astro-js-components';
import { runOnce } from './run-once';

let initOptions: AstroClerkIntegrationParams | undefined;

/**
* Prevents firing clerk.load multiple times
*/
export const createClerkInstance = runOnce(createClerkInstanceInternal);

export async function createClerkInstanceInternal(options?: AstroClerkIntegrationParams) {
let clerkJSInstance = window.Clerk;
if (!clerkJSInstance) {
await waitForClerkScript();

if (!window.Clerk) {
throw new Error('Failed to download latest ClerkJS. Contact support@clerk.com.');
}
clerkJSInstance = window.Clerk;
}

if (!$clerk.get()) {
// @ts-ignore
$clerk.set(clerkJSInstance);
}

initOptions = options;
// TODO: Update Clerk type from @clerk/types to include this method
return (clerkJSInstance as any)
.load(options)
.then(() => {
$csrState.setKey('isLoaded', true);

mountAllClerkAstroJSComponents();

clerkJSInstance.addListener(payload => {
$csrState.setKey('client', payload.client);
$csrState.setKey('user', payload.user);
$csrState.setKey('session', payload.session);
$csrState.setKey('organization', payload.organization);
});
})
.catch(() => {});
}

export function updateClerkOptions(options: AstroClerkUpdateOptions) {
const clerk = $clerk.get();
if (!clerk) {
throw new Error('Missing clerk instance');
}
// TODO: Update Clerk type from @clerk/types to include this method
void (clerk as any).__unstable__updateProps({
options: { ...initOptions, ...options },
appearance: { ...initOptions?.appearance, ...options.appearance },
});
}
export { updateClerkOptions } from '../internal/create-clerk-instance';
export * from '../stores/external';
1 change: 0 additions & 1 deletion packages/astro/src/client/stores/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/astro/src/globals.d.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,5 +3,4 @@ export {};
declare global {
const PACKAGE_NAME: string;
const PACKAGE_VERSION: string;
const __HOTLOAD__: string;
}
4 changes: 3 additions & 1 deletion packages/astro/src/index.ts
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
export { default } from './integration';
import { createIntegration } from './integration/create-integration';

export default createIntegration();
5 changes: 0 additions & 5 deletions packages/astro/src/integration/bundled.ts

This file was deleted.

12 changes: 3 additions & 9 deletions packages/astro/src/integration/create-integration.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,10 +14,8 @@ type HotloadAstroClerkIntegrationParams = AstroClerkIntegrationParams & {
clerkJSVersion?: string;
};

function createIntegration<P extends { mode: 'hotload' | 'bundled' }>({ mode }: P) {
return (
params?: P['mode'] extends 'hotload' ? HotloadAstroClerkIntegrationParams : AstroClerkIntegrationParams,
): AstroIntegration => {
function createIntegration<Params extends HotloadAstroClerkIntegrationParams>() {
return (params?: Params): AstroIntegration => {
const { proxyUrl, isSatellite, domain, signInUrl, signUpUrl } = params || {};

// These are not provided when the "bundled" integration is used
Expand DownExpand Up@@ -50,10 +48,7 @@ function createIntegration<P extends { mode: 'hotload' | 'bundled' }>({ mode }:
},
};

const defaultBundledImportPath = `${packageName}/internal/bundled`;

const buildImportPath =
mode === 'bundled' ? defaultBundledImportPath : defaultBundledImportPath.replace('/bundled', '');
const buildImportPath = `${packageName}/internal`;

// Set params as envs do backend code has access to them
updateConfig({
Expand All@@ -72,7 +67,6 @@ function createIntegration<P extends { mode: 'hotload' | 'bundled' }>({ mode }:
...buildEnvVarFromOption(clerkJSUrl, 'PUBLIC_CLERK_JS_URL'),
...buildEnvVarFromOption(clerkJSVariant, 'PUBLIC_CLERK_JS_VARIANT'),
...buildEnvVarFromOption(clerkJSVersion, 'PUBLIC_CLERK_JS_VERSION'),
__HOTLOAD__: mode === 'hotload',
},

ssr: {
Expand Down
5 changes: 0 additions & 5 deletions packages/astro/src/integration/index.ts

This file was deleted.

13 changes: 0 additions & 13 deletions packages/astro/src/internal/bundled.ts

This file was deleted.

Original file line numberDiff line numberDiff line change
@@ -1,30 +1,35 @@
import { Clerk } from '@clerk/clerk-js';

import { waitForClerkScript } from '../internal/utils/loadClerkJSScript';
import { $clerk, $csrState } from '../stores/internal';
import type { AstroClerkCreateInstanceParams, AstroClerkUpdateOptions } from '../types';
import type { AstroClerkIntegrationParams, AstroClerkUpdateOptions } from '../types';
import { mountAllClerkAstroJSComponents } from './mount-clerk-astro-js-components';
import { runOnce } from './run-once';
import type { CreateClerkInstanceInternalFn } from './types';

let initOptions: AstroClerkCreateInstanceParams | undefined;
let initOptions: AstroClerkIntegrationParams | undefined;

/**
* Prevents firing clerk.load multiple times
*/
export const createClerkInstance: CreateClerkInstanceInternalFn = runOnce(createClerkInstanceInternal);
const createClerkInstance = runOnce(createClerkInstanceInternal);

export function createClerkInstanceInternal(options?: AstroClerkCreateInstanceParams) {
let clerkJSInstance = window.Clerk as unknown as Clerk;
async function createClerkInstanceInternal(options?: AstroClerkIntegrationParams) {
let clerkJSInstance = window.Clerk;
if (!clerkJSInstance) {
clerkJSInstance = new Clerk(options!.publishableKey);
await waitForClerkScript();

if (!window.Clerk) {
throw new Error('Failed to download latest ClerkJS. Contact support@clerk.com.');
}
clerkJSInstance = window.Clerk;
}

if (!$clerk.get()) {
// @ts-ignore
$clerk.set(clerkJSInstance);
// @ts-ignore
window.Clerk = clerkJSInstance;
}

initOptions = options;
return clerkJSInstance
// TODO: Update Clerk type from @clerk/types to include this method
return (clerkJSInstance as any)
.load(options)
.then(() => {
$csrState.setKey('isLoaded', true);
Expand All@@ -41,14 +46,16 @@ export function createClerkInstanceInternal(options?: AstroClerkCreateInstancePa
.catch(() => {});
}

export function updateClerkOptions(options: AstroClerkUpdateOptions) {
function updateClerkOptions(options: AstroClerkUpdateOptions) {
const clerk = $clerk.get();
if (!clerk) {
throw new Error('Missing clerk instance');
}
//@ts-ignore
clerk.__unstable__updateProps({
// TODO: Update Clerk type from @clerk/types to include this method
void (clerk as any).__unstable__updateProps({
options: { ...initOptions, ...options },
appearance: { ...initOptions?.appearance, ...options.appearance },
});
}

export { createClerkInstance, updateClerkOptions };
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
import type { CreateClerkInstanceInternalFn } from '../client/types';
import { $initialState } from '../stores/internal';
import type { AstroClerkIntegrationParams } from '../types';
import { mergeEnvVarsWithParams } from './merge-env-vars-with-params';
import type { CreateClerkInstanceInternalFn } from './types';

/**
* @internal
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/internal/index.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,7 @@
* injectScript('before-hydration', `...`)
*/

import { createClerkInstance } from '../client';
import { createClerkInstance } from './create-clerk-instance';
import { createInjectionScriptRunner } from './create-injection-script-runner';

const runInjectionScript = createInjectionScriptRunner(createClerkInstance);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,7 +17,9 @@ export const SignOutButton = withClerk(

const clickHandler = () => clerk?.signOut({ redirectUrl, sessionId });
const wrappedChildClickHandler: React.MouseEventHandler = async e => {
await safeExecute((child as any).props.onClick)(e);
if (child && typeof child === 'object' && 'props' in child) {
await safeExecute(child.props.onClick)(e);
}
return clickHandler();
};

Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
import type { CheckAuthorizationWithCustomPermissions } from '@clerk/types';
import type { PropsWithChildren } from 'react';

import type { ProtectComponentDefaultProps } from '../../types';
import type { ProtectComponentDefaultProps } from '../types';
import { useAuth } from './hooks';

export function SignedOut(props: PropsWithChildren) {
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,8 +12,8 @@ import { useCallback, useSyncExternalStore } from 'react';
// @ts-ignore
import { authAsyncStorage } from '#async-local-storage';

import { $authStore } from '../../stores/external';
import { $clerk, $csrState } from '../../stores/internal';
import { $authStore } from '../stores/external';
import { $clerk, $csrState } from '../stores/internal';

type CheckAuthorizationSignedOut = undefined;
type CheckAuthorizationWithoutOrgOrUser = (params?: Parameters<CheckAuthorizationWithCustomPermissions>[0]) => false;
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
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
15 changes: 15 additions & 0 deletions .changeset/four-days-hammer.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
---
"@clerk/astro": patch
---

Simplify submodules and drop the `bunlded` variant.

Moved
- `@clerk/astro/client/react` to `@clerk/astro/react`
- `@clerk/astro/client/stores` to `@clerk/astro/client`
Dropped
- `@clerk/astro/bundled`
- `@clerk/astro/client/bundled`
- `@clerk/astro/internal/bundled`
- `@clerk/astro/integration`
- `@clerk/astro/integration/bundled`
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
import { useAuth } from '@clerk/astro/client/react';
import { useAuth } from '@clerk/astro/react';
import React from 'react';
import { type PropsWithChildren } from 'react';

Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
import React, { type PropsWithChildren, useSyncExternalStore } from 'react';
import { UserProfile } from '@clerk/astro/client/react';
import { $userStore } from '@clerk/astro/client/stores';
import { UserProfile } from '@clerk/astro/react';
import { $userStore } from '@clerk/astro/client';

export function PageWithUser({ children }: PropsWithChildren) {
const user = useSyncExternalStore($userStore.listen, $userStore.get, $userStore.get);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,7 @@ interface Props {

const { title } = Astro.props;

import { SignedIn, SignedOut, UserButton } from "@clerk/astro/client/react";
import { SignedIn, SignedOut, UserButton } from "@clerk/astro/react";
import { LanguagePicker } from "../../components/LanguagePicker";
---

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,7 +12,7 @@ interface Props extends SignOutOptions {
</script>

<script>
import { $clerkStore } from "@clerk/astro/client/stores";
import { $clerkStore } from "@clerk/astro/client";

const button = document.querySelector(
"[data-sign-out-button]",
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,7 +3,7 @@ import Layout from "../../layouts/react/Layout.astro";
import Card from "../../components/Card.astro";
import SignOutButton from "../../lib/astro-components/SignOutButton.astro";

import { SignedIn, SignedOut, OrganizationSwitcher } from "@clerk/astro/client/react";
import { SignedIn, SignedOut, OrganizationSwitcher } from "@clerk/astro/react";
---

<Layout title="Welcome to Astro.">
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
---
import { Protect } from "@clerk/astro/client/react";
import { Protect } from "@clerk/astro/react";
import Layout from "../../layouts/react/Layout.astro";
---

Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
---
import { Protect } from "@clerk/astro/client/react";
import { Protect } from "@clerk/astro/react";
import Layout from "../../layouts/react/Layout.astro";
---

Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
---
import { SignIn } from "@clerk/astro/client/react";
import { SignIn } from "@clerk/astro/react";
import Layout from "../../layouts/react/Layout.astro";
---

Expand Down
3 changes: 0 additions & 3 deletions packages/astro/client/react/package.json

This file was deleted.

3 changes: 0 additions & 3 deletions packages/astro/client/stores/package.json

This file was deleted.

30 changes: 3 additions & 27 deletions packages/astro/package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -50,46 +50,22 @@
"types": "./dist/index.d.ts",
"import": "./dist/index.js"
},
"./client/react": {
"types": "./dist/client/react/index.d.ts",
"import": "./dist/client/react/index.js"
},
"./client/stores": {
"types": "./dist/client/stores/index.d.ts",
"import": "./dist/client/stores/index.js"
"./react": {
"types": "./dist/react/index.d.ts",
"import": "./dist/react/index.js"
},
"./client": {
"types": "./dist/client/index.d.ts",
"import": "./dist/client/index.js"
},
"./client/bundled": {
"types": "./dist/client/bundled.d.ts",
"import": "./dist/client/bundled.js"
},
"./integration": {
"types": "./dist/integration/index.d.ts",
"import": "./dist/integration/index.js"
},
"./integration/bundled": {
"types": "./dist/integration/bundled.d.ts",
"import": "./dist/integration/bundled.js"
},
"./internal": {
"types": "./dist/internal/index.d.ts",
"import": "./dist/internal/index.js"
},
"./internal/bundled": {
"types": "./dist/internal/bundled.d.ts",
"import": "./dist/internal/bundled.js"
},
"./server": {
"types": "./dist/server/index.d.ts",
"import": "./dist/server/index.js"
},
"./bundled": {
"types": "./dist/bundled.d.ts",
"import": "./dist/bundled.js"
},
"./env": "./env.d.ts",
"./components/control": "./components/control/index.ts",
"./components/control/*": "./components/control/*",
Expand Down
3 changes: 3 additions & 0 deletions packages/astro/react/package.json
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
{
"main": "../../dist/react/index.js"
}
1 change: 0 additions & 1 deletion packages/astro/src/bundled.ts

This file was deleted.

61 changes: 2 additions & 59 deletions packages/astro/src/client/index.ts
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,2 @@
import { waitForClerkScript } from '../internal/utils/loadClerkJSScript';
import { $clerk, $csrState } from '../stores/internal';
import type { AstroClerkIntegrationParams, AstroClerkUpdateOptions } from '../types';
import { mountAllClerkAstroJSComponents } from './mount-clerk-astro-js-components';
import { runOnce } from './run-once';

let initOptions: AstroClerkIntegrationParams | undefined;

/**
* Prevents firing clerk.load multiple times
*/
export const createClerkInstance = runOnce(createClerkInstanceInternal);

export async function createClerkInstanceInternal(options?: AstroClerkIntegrationParams) {
let clerkJSInstance = window.Clerk;
if (!clerkJSInstance) {
await waitForClerkScript();

if (!window.Clerk) {
throw new Error('Failed to download latest ClerkJS. Contact support@clerk.com.');
}
clerkJSInstance = window.Clerk;
}

if (!$clerk.get()) {
// @ts-ignore
$clerk.set(clerkJSInstance);
}

initOptions = options;
// TODO: Update Clerk type from @clerk/types to include this method
return (clerkJSInstance as any)
.load(options)
.then(() => {
$csrState.setKey('isLoaded', true);

mountAllClerkAstroJSComponents();

clerkJSInstance.addListener(payload => {
$csrState.setKey('client', payload.client);
$csrState.setKey('user', payload.user);
$csrState.setKey('session', payload.session);
$csrState.setKey('organization', payload.organization);
});
})
.catch(() => {});
}

export function updateClerkOptions(options: AstroClerkUpdateOptions) {
const clerk = $clerk.get();
if (!clerk) {
throw new Error('Missing clerk instance');
}
// TODO: Update Clerk type from @clerk/types to include this method
void (clerk as any).__unstable__updateProps({
options: { ...initOptions, ...options },
appearance: { ...initOptions?.appearance, ...options.appearance },
});
}
export { updateClerkOptions } from '../internal/create-clerk-instance';
export * from '../stores/external';
1 change: 0 additions & 1 deletion packages/astro/src/client/stores/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/astro/src/globals.d.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,5 +3,4 @@ export {};
declare global {
const PACKAGE_NAME: string;
const PACKAGE_VERSION: string;
const __HOTLOAD__: string;
}
4 changes: 3 additions & 1 deletion packages/astro/src/index.ts
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
export { default } from './integration';
import { createIntegration } from './integration/create-integration';

export default createIntegration();
5 changes: 0 additions & 5 deletions packages/astro/src/integration/bundled.ts

This file was deleted.

12 changes: 3 additions & 9 deletions packages/astro/src/integration/create-integration.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,10 +14,8 @@ type HotloadAstroClerkIntegrationParams = AstroClerkIntegrationParams & {
clerkJSVersion?: string;
};

function createIntegration<P extends { mode: 'hotload' | 'bundled' }>({ mode }: P) {
return (
params?: P['mode'] extends 'hotload' ? HotloadAstroClerkIntegrationParams : AstroClerkIntegrationParams,
): AstroIntegration => {
function createIntegration<Params extends HotloadAstroClerkIntegrationParams>() {
return (params?: Params): AstroIntegration => {
const { proxyUrl, isSatellite, domain, signInUrl, signUpUrl } = params || {};

// These are not provided when the "bundled" integration is used
Expand DownExpand Up@@ -50,10 +48,7 @@ function createIntegration<P extends { mode: 'hotload' | 'bundled' }>({ mode }:
},
};

const defaultBundledImportPath = `${packageName}/internal/bundled`;

const buildImportPath =
mode === 'bundled' ? defaultBundledImportPath : defaultBundledImportPath.replace('/bundled', '');
const buildImportPath = `${packageName}/internal`;

// Set params as envs do backend code has access to them
updateConfig({
Expand All@@ -72,7 +67,6 @@ function createIntegration<P extends { mode: 'hotload' | 'bundled' }>({ mode }:
...buildEnvVarFromOption(clerkJSUrl, 'PUBLIC_CLERK_JS_URL'),
...buildEnvVarFromOption(clerkJSVariant, 'PUBLIC_CLERK_JS_VARIANT'),
...buildEnvVarFromOption(clerkJSVersion, 'PUBLIC_CLERK_JS_VERSION'),
__HOTLOAD__: mode === 'hotload',
},

ssr: {
Expand Down
5 changes: 0 additions & 5 deletions packages/astro/src/integration/index.ts

This file was deleted.

13 changes: 0 additions & 13 deletions packages/astro/src/internal/bundled.ts

This file was deleted.

Original file line numberDiff line numberDiff line change
@@ -1,30 +1,35 @@
import { Clerk } from '@clerk/clerk-js';

import { waitForClerkScript } from '../internal/utils/loadClerkJSScript';
import { $clerk, $csrState } from '../stores/internal';
import type { AstroClerkCreateInstanceParams, AstroClerkUpdateOptions } from '../types';
import type { AstroClerkIntegrationParams, AstroClerkUpdateOptions } from '../types';
import { mountAllClerkAstroJSComponents } from './mount-clerk-astro-js-components';
import { runOnce } from './run-once';
import type { CreateClerkInstanceInternalFn } from './types';

let initOptions: AstroClerkCreateInstanceParams | undefined;
let initOptions: AstroClerkIntegrationParams | undefined;

/**
* Prevents firing clerk.load multiple times
*/
export const createClerkInstance: CreateClerkInstanceInternalFn = runOnce(createClerkInstanceInternal);
const createClerkInstance = runOnce(createClerkInstanceInternal);

export function createClerkInstanceInternal(options?: AstroClerkCreateInstanceParams) {
let clerkJSInstance = window.Clerk as unknown as Clerk;
async function createClerkInstanceInternal(options?: AstroClerkIntegrationParams) {
let clerkJSInstance = window.Clerk;
if (!clerkJSInstance) {
clerkJSInstance = new Clerk(options!.publishableKey);
await waitForClerkScript();

if (!window.Clerk) {
throw new Error('Failed to download latest ClerkJS. Contact support@clerk.com.');
}
clerkJSInstance = window.Clerk;
}

if (!$clerk.get()) {
// @ts-ignore
$clerk.set(clerkJSInstance);
// @ts-ignore
window.Clerk = clerkJSInstance;
}

initOptions = options;
return clerkJSInstance
// TODO: Update Clerk type from @clerk/types to include this method
return (clerkJSInstance as any)
.load(options)
.then(() => {
$csrState.setKey('isLoaded', true);
Expand All@@ -41,14 +46,16 @@ export function createClerkInstanceInternal(options?: AstroClerkCreateInstancePa
.catch(() => {});
}

export function updateClerkOptions(options: AstroClerkUpdateOptions) {
function updateClerkOptions(options: AstroClerkUpdateOptions) {
const clerk = $clerk.get();
if (!clerk) {
throw new Error('Missing clerk instance');
}
//@ts-ignore
clerk.__unstable__updateProps({
// TODO: Update Clerk type from @clerk/types to include this method
void (clerk as any).__unstable__updateProps({
options: { ...initOptions, ...options },
appearance: { ...initOptions?.appearance, ...options.appearance },
});
}

export { createClerkInstance, updateClerkOptions };
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
import type { CreateClerkInstanceInternalFn } from '../client/types';
import { $initialState } from '../stores/internal';
import type { AstroClerkIntegrationParams } from '../types';
import { mergeEnvVarsWithParams } from './merge-env-vars-with-params';
import type { CreateClerkInstanceInternalFn } from './types';

/**
* @internal
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/internal/index.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,7 @@
* injectScript('before-hydration', `...`)
*/

import { createClerkInstance } from '../client';
import { createClerkInstance } from './create-clerk-instance';
import { createInjectionScriptRunner } from './create-injection-script-runner';

const runInjectionScript = createInjectionScriptRunner(createClerkInstance);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,7 +17,9 @@ export const SignOutButton = withClerk(

const clickHandler = () => clerk?.signOut({ redirectUrl, sessionId });
const wrappedChildClickHandler: React.MouseEventHandler = async e => {
await safeExecute((child as any).props.onClick)(e);
if (child && typeof child === 'object' && 'props' in child) {
await safeExecute(child.props.onClick)(e);
}
return clickHandler();
};

Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
import type { CheckAuthorizationWithCustomPermissions } from '@clerk/types';
import type { PropsWithChildren } from 'react';

import type { ProtectComponentDefaultProps } from '../../types';
import type { ProtectComponentDefaultProps } from '../types';
import { useAuth } from './hooks';

export function SignedOut(props: PropsWithChildren) {
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,8 +12,8 @@ import { useCallback, useSyncExternalStore } from 'react';
// @ts-ignore
import { authAsyncStorage } from '#async-local-storage';

import { $authStore } from '../../stores/external';
import { $clerk, $csrState } from '../../stores/internal';
import { $authStore } from '../stores/external';
import { $clerk, $csrState } from '../stores/internal';

type CheckAuthorizationSignedOut = undefined;
type CheckAuthorizationWithoutOrgOrUser = (params?: Parameters<CheckAuthorizationWithCustomPermissions>[0]) => false;
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
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
15 changes: 15 additions & 0 deletions .changeset/four-days-hammer.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
---
"@clerk/astro": patch
---

Simplify submodules and drop the `bunlded` variant.

Moved
- `@clerk/astro/client/react` to `@clerk/astro/react`
- `@clerk/astro/client/stores` to `@clerk/astro/client`
Dropped
- `@clerk/astro/bundled`
- `@clerk/astro/client/bundled`
- `@clerk/astro/internal/bundled`
- `@clerk/astro/integration`
- `@clerk/astro/integration/bundled`
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
import { useAuth } from '@clerk/astro/client/react';
import { useAuth } from '@clerk/astro/react';
import React from 'react';
import { type PropsWithChildren } from 'react';

Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
import React, { type PropsWithChildren, useSyncExternalStore } from 'react';
import { UserProfile } from '@clerk/astro/client/react';
import { $userStore } from '@clerk/astro/client/stores';
import { UserProfile } from '@clerk/astro/react';
import { $userStore } from '@clerk/astro/client';

export function PageWithUser({ children }: PropsWithChildren) {
const user = useSyncExternalStore($userStore.listen, $userStore.get, $userStore.get);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,7 @@ interface Props {

const { title } = Astro.props;

import { SignedIn, SignedOut, UserButton } from "@clerk/astro/client/react";
import { SignedIn, SignedOut, UserButton } from "@clerk/astro/react";
import { LanguagePicker } from "../../components/LanguagePicker";
---

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,7 +12,7 @@ interface Props extends SignOutOptions {
</script>

<script>
import { $clerkStore } from "@clerk/astro/client/stores";
import { $clerkStore } from "@clerk/astro/client";

const button = document.querySelector(
"[data-sign-out-button]",
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,7 +3,7 @@ import Layout from "../../layouts/react/Layout.astro";
import Card from "../../components/Card.astro";
import SignOutButton from "../../lib/astro-components/SignOutButton.astro";

import { SignedIn, SignedOut, OrganizationSwitcher } from "@clerk/astro/client/react";
import { SignedIn, SignedOut, OrganizationSwitcher } from "@clerk/astro/react";
---

<Layout title="Welcome to Astro.">
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
---
import { Protect } from "@clerk/astro/client/react";
import { Protect } from "@clerk/astro/react";
import Layout from "../../layouts/react/Layout.astro";
---

Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
---
import { Protect } from "@clerk/astro/client/react";
import { Protect } from "@clerk/astro/react";
import Layout from "../../layouts/react/Layout.astro";
---

Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
---
import { SignIn } from "@clerk/astro/client/react";
import { SignIn } from "@clerk/astro/react";
import Layout from "../../layouts/react/Layout.astro";
---

Expand Down
3 changes: 0 additions & 3 deletions packages/astro/client/react/package.json

This file was deleted.

3 changes: 0 additions & 3 deletions packages/astro/client/stores/package.json

This file was deleted.

30 changes: 3 additions & 27 deletions packages/astro/package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -50,46 +50,22 @@
"types": "./dist/index.d.ts",
"import": "./dist/index.js"
},
"./client/react": {
"types": "./dist/client/react/index.d.ts",
"import": "./dist/client/react/index.js"
},
"./client/stores": {
"types": "./dist/client/stores/index.d.ts",
"import": "./dist/client/stores/index.js"
"./react": {
"types": "./dist/react/index.d.ts",
"import": "./dist/react/index.js"
},
"./client": {
"types": "./dist/client/index.d.ts",
"import": "./dist/client/index.js"
},
"./client/bundled": {
"types": "./dist/client/bundled.d.ts",
"import": "./dist/client/bundled.js"
},
"./integration": {
"types": "./dist/integration/index.d.ts",
"import": "./dist/integration/index.js"
},
"./integration/bundled": {
"types": "./dist/integration/bundled.d.ts",
"import": "./dist/integration/bundled.js"
},
"./internal": {
"types": "./dist/internal/index.d.ts",
"import": "./dist/internal/index.js"
},
"./internal/bundled": {
"types": "./dist/internal/bundled.d.ts",
"import": "./dist/internal/bundled.js"
},
"./server": {
"types": "./dist/server/index.d.ts",
"import": "./dist/server/index.js"
},
"./bundled": {
"types": "./dist/bundled.d.ts",
"import": "./dist/bundled.js"
},
"./env": "./env.d.ts",
"./components/control": "./components/control/index.ts",
"./components/control/*": "./components/control/*",
Expand Down
3 changes: 3 additions & 0 deletions packages/astro/react/package.json
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
{
"main": "../../dist/react/index.js"
}
1 change: 0 additions & 1 deletion packages/astro/src/bundled.ts

This file was deleted.

61 changes: 2 additions & 59 deletions packages/astro/src/client/index.ts
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,2 @@
import { waitForClerkScript } from '../internal/utils/loadClerkJSScript';
import { $clerk, $csrState } from '../stores/internal';
import type { AstroClerkIntegrationParams, AstroClerkUpdateOptions } from '../types';
import { mountAllClerkAstroJSComponents } from './mount-clerk-astro-js-components';
import { runOnce } from './run-once';

let initOptions: AstroClerkIntegrationParams | undefined;

/**
* Prevents firing clerk.load multiple times
*/
export const createClerkInstance = runOnce(createClerkInstanceInternal);

export async function createClerkInstanceInternal(options?: AstroClerkIntegrationParams) {
let clerkJSInstance = window.Clerk;
if (!clerkJSInstance) {
await waitForClerkScript();

if (!window.Clerk) {
throw new Error('Failed to download latest ClerkJS. Contact support@clerk.com.');
}
clerkJSInstance = window.Clerk;
}

if (!$clerk.get()) {
// @ts-ignore
$clerk.set(clerkJSInstance);
}

initOptions = options;
// TODO: Update Clerk type from @clerk/types to include this method
return (clerkJSInstance as any)
.load(options)
.then(() => {
$csrState.setKey('isLoaded', true);

mountAllClerkAstroJSComponents();

clerkJSInstance.addListener(payload => {
$csrState.setKey('client', payload.client);
$csrState.setKey('user', payload.user);
$csrState.setKey('session', payload.session);
$csrState.setKey('organization', payload.organization);
});
})
.catch(() => {});
}

export function updateClerkOptions(options: AstroClerkUpdateOptions) {
const clerk = $clerk.get();
if (!clerk) {
throw new Error('Missing clerk instance');
}
// TODO: Update Clerk type from @clerk/types to include this method
void (clerk as any).__unstable__updateProps({
options: { ...initOptions, ...options },
appearance: { ...initOptions?.appearance, ...options.appearance },
});
}
export { updateClerkOptions } from '../internal/create-clerk-instance';
export * from '../stores/external';
1 change: 0 additions & 1 deletion packages/astro/src/client/stores/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/astro/src/globals.d.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,5 +3,4 @@ export {};
declare global {
const PACKAGE_NAME: string;
const PACKAGE_VERSION: string;
const __HOTLOAD__: string;
}
4 changes: 3 additions & 1 deletion packages/astro/src/index.ts
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
export { default } from './integration';
import { createIntegration } from './integration/create-integration';

export default createIntegration();
5 changes: 0 additions & 5 deletions packages/astro/src/integration/bundled.ts

This file was deleted.

12 changes: 3 additions & 9 deletions packages/astro/src/integration/create-integration.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,10 +14,8 @@ type HotloadAstroClerkIntegrationParams = AstroClerkIntegrationParams & {
clerkJSVersion?: string;
};

function createIntegration<P extends { mode: 'hotload' | 'bundled' }>({ mode }: P) {
return (
params?: P['mode'] extends 'hotload' ? HotloadAstroClerkIntegrationParams : AstroClerkIntegrationParams,
): AstroIntegration => {
function createIntegration<Params extends HotloadAstroClerkIntegrationParams>() {
return (params?: Params): AstroIntegration => {
const { proxyUrl, isSatellite, domain, signInUrl, signUpUrl } = params || {};

// These are not provided when the "bundled" integration is used
Expand DownExpand Up@@ -50,10 +48,7 @@ function createIntegration<P extends { mode: 'hotload' | 'bundled' }>({ mode }:
},
};

const defaultBundledImportPath = `${packageName}/internal/bundled`;

const buildImportPath =
mode === 'bundled' ? defaultBundledImportPath : defaultBundledImportPath.replace('/bundled', '');
const buildImportPath = `${packageName}/internal`;

// Set params as envs do backend code has access to them
updateConfig({
Expand All@@ -72,7 +67,6 @@ function createIntegration<P extends { mode: 'hotload' | 'bundled' }>({ mode }:
...buildEnvVarFromOption(clerkJSUrl, 'PUBLIC_CLERK_JS_URL'),
...buildEnvVarFromOption(clerkJSVariant, 'PUBLIC_CLERK_JS_VARIANT'),
...buildEnvVarFromOption(clerkJSVersion, 'PUBLIC_CLERK_JS_VERSION'),
__HOTLOAD__: mode === 'hotload',
},

ssr: {
Expand Down
5 changes: 0 additions & 5 deletions packages/astro/src/integration/index.ts

This file was deleted.

13 changes: 0 additions & 13 deletions packages/astro/src/internal/bundled.ts

This file was deleted.

Original file line numberDiff line numberDiff line change
@@ -1,30 +1,35 @@
import { Clerk } from '@clerk/clerk-js';

import { waitForClerkScript } from '../internal/utils/loadClerkJSScript';
import { $clerk, $csrState } from '../stores/internal';
import type { AstroClerkCreateInstanceParams, AstroClerkUpdateOptions } from '../types';
import type { AstroClerkIntegrationParams, AstroClerkUpdateOptions } from '../types';
import { mountAllClerkAstroJSComponents } from './mount-clerk-astro-js-components';
import { runOnce } from './run-once';
import type { CreateClerkInstanceInternalFn } from './types';

let initOptions: AstroClerkCreateInstanceParams | undefined;
let initOptions: AstroClerkIntegrationParams | undefined;

/**
* Prevents firing clerk.load multiple times
*/
export const createClerkInstance: CreateClerkInstanceInternalFn = runOnce(createClerkInstanceInternal);
const createClerkInstance = runOnce(createClerkInstanceInternal);

export function createClerkInstanceInternal(options?: AstroClerkCreateInstanceParams) {
let clerkJSInstance = window.Clerk as unknown as Clerk;
async function createClerkInstanceInternal(options?: AstroClerkIntegrationParams) {
let clerkJSInstance = window.Clerk;
if (!clerkJSInstance) {
clerkJSInstance = new Clerk(options!.publishableKey);
await waitForClerkScript();

if (!window.Clerk) {
throw new Error('Failed to download latest ClerkJS. Contact support@clerk.com.');
}
clerkJSInstance = window.Clerk;
}

if (!$clerk.get()) {
// @ts-ignore
$clerk.set(clerkJSInstance);
// @ts-ignore
window.Clerk = clerkJSInstance;
}

initOptions = options;
return clerkJSInstance
// TODO: Update Clerk type from @clerk/types to include this method
return (clerkJSInstance as any)
.load(options)
.then(() => {
$csrState.setKey('isLoaded', true);
Expand All@@ -41,14 +46,16 @@ export function createClerkInstanceInternal(options?: AstroClerkCreateInstancePa
.catch(() => {});
}

export function updateClerkOptions(options: AstroClerkUpdateOptions) {
function updateClerkOptions(options: AstroClerkUpdateOptions) {
const clerk = $clerk.get();
if (!clerk) {
throw new Error('Missing clerk instance');
}
//@ts-ignore
clerk.__unstable__updateProps({
// TODO: Update Clerk type from @clerk/types to include this method
void (clerk as any).__unstable__updateProps({
options: { ...initOptions, ...options },
appearance: { ...initOptions?.appearance, ...options.appearance },
});
}

export { createClerkInstance, updateClerkOptions };
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
import type { CreateClerkInstanceInternalFn } from '../client/types';
import { $initialState } from '../stores/internal';
import type { AstroClerkIntegrationParams } from '../types';
import { mergeEnvVarsWithParams } from './merge-env-vars-with-params';
import type { CreateClerkInstanceInternalFn } from './types';

/**
* @internal
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/internal/index.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,7 @@
* injectScript('before-hydration', `...`)
*/

import { createClerkInstance } from '../client';
import { createClerkInstance } from './create-clerk-instance';
import { createInjectionScriptRunner } from './create-injection-script-runner';

const runInjectionScript = createInjectionScriptRunner(createClerkInstance);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,7 +17,9 @@ export const SignOutButton = withClerk(

const clickHandler = () => clerk?.signOut({ redirectUrl, sessionId });
const wrappedChildClickHandler: React.MouseEventHandler = async e => {
await safeExecute((child as any).props.onClick)(e);
if (child && typeof child === 'object' && 'props' in child) {
await safeExecute(child.props.onClick)(e);
}
return clickHandler();
};

Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
import type { CheckAuthorizationWithCustomPermissions } from '@clerk/types';
import type { PropsWithChildren } from 'react';

import type { ProtectComponentDefaultProps } from '../../types';
import type { ProtectComponentDefaultProps } from '../types';
import { useAuth } from './hooks';

export function SignedOut(props: PropsWithChildren) {
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,8 +12,8 @@ import { useCallback, useSyncExternalStore } from 'react';
// @ts-ignore
import { authAsyncStorage } from '#async-local-storage';

import { $authStore } from '../../stores/external';
import { $clerk, $csrState } from '../../stores/internal';
import { $authStore } from '../stores/external';
import { $clerk, $csrState } from '../stores/internal';

type CheckAuthorizationSignedOut = undefined;
type CheckAuthorizationWithoutOrgOrUser = (params?: Parameters<CheckAuthorizationWithCustomPermissions>[0]) => false;
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
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
15 changes: 15 additions & 0 deletions .changeset/four-days-hammer.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
---
"@clerk/astro": patch
---

Simplify submodules and drop the `bunlded` variant.

Moved
- `@clerk/astro/client/react` to `@clerk/astro/react`
- `@clerk/astro/client/stores` to `@clerk/astro/client`
Dropped
- `@clerk/astro/bundled`
- `@clerk/astro/client/bundled`
- `@clerk/astro/internal/bundled`
- `@clerk/astro/integration`
- `@clerk/astro/integration/bundled`
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
import { useAuth } from '@clerk/astro/client/react';
import { useAuth } from '@clerk/astro/react';
import React from 'react';
import { type PropsWithChildren } from 'react';

Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
import React, { type PropsWithChildren, useSyncExternalStore } from 'react';
import { UserProfile } from '@clerk/astro/client/react';
import { $userStore } from '@clerk/astro/client/stores';
import { UserProfile } from '@clerk/astro/react';
import { $userStore } from '@clerk/astro/client';

export function PageWithUser({ children }: PropsWithChildren) {
const user = useSyncExternalStore($userStore.listen, $userStore.get, $userStore.get);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,7 @@ interface Props {

const { title } = Astro.props;

import { SignedIn, SignedOut, UserButton } from "@clerk/astro/client/react";
import { SignedIn, SignedOut, UserButton } from "@clerk/astro/react";
import { LanguagePicker } from "../../components/LanguagePicker";
---

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,7 +12,7 @@ interface Props extends SignOutOptions {
</script>

<script>
import { $clerkStore } from "@clerk/astro/client/stores";
import { $clerkStore } from "@clerk/astro/client";

const button = document.querySelector(
"[data-sign-out-button]",
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,7 +3,7 @@ import Layout from "../../layouts/react/Layout.astro";
import Card from "../../components/Card.astro";
import SignOutButton from "../../lib/astro-components/SignOutButton.astro";

import { SignedIn, SignedOut, OrganizationSwitcher } from "@clerk/astro/client/react";
import { SignedIn, SignedOut, OrganizationSwitcher } from "@clerk/astro/react";
---

<Layout title="Welcome to Astro.">
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
---
import { Protect } from "@clerk/astro/client/react";
import { Protect } from "@clerk/astro/react";
import Layout from "../../layouts/react/Layout.astro";
---

Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
---
import { Protect } from "@clerk/astro/client/react";
import { Protect } from "@clerk/astro/react";
import Layout from "../../layouts/react/Layout.astro";
---

Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
---
import { SignIn } from "@clerk/astro/client/react";
import { SignIn } from "@clerk/astro/react";
import Layout from "../../layouts/react/Layout.astro";
---

Expand Down
3 changes: 0 additions & 3 deletions packages/astro/client/react/package.json

This file was deleted.

3 changes: 0 additions & 3 deletions packages/astro/client/stores/package.json

This file was deleted.

30 changes: 3 additions & 27 deletions packages/astro/package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -50,46 +50,22 @@
"types": "./dist/index.d.ts",
"import": "./dist/index.js"
},
"./client/react": {
"types": "./dist/client/react/index.d.ts",
"import": "./dist/client/react/index.js"
},
"./client/stores": {
"types": "./dist/client/stores/index.d.ts",
"import": "./dist/client/stores/index.js"
"./react": {
"types": "./dist/react/index.d.ts",
"import": "./dist/react/index.js"
},
"./client": {
"types": "./dist/client/index.d.ts",
"import": "./dist/client/index.js"
},
"./client/bundled": {
"types": "./dist/client/bundled.d.ts",
"import": "./dist/client/bundled.js"
},
"./integration": {
"types": "./dist/integration/index.d.ts",
"import": "./dist/integration/index.js"
},
"./integration/bundled": {
"types": "./dist/integration/bundled.d.ts",
"import": "./dist/integration/bundled.js"
},
"./internal": {
"types": "./dist/internal/index.d.ts",
"import": "./dist/internal/index.js"
},
"./internal/bundled": {
"types": "./dist/internal/bundled.d.ts",
"import": "./dist/internal/bundled.js"
},
"./server": {
"types": "./dist/server/index.d.ts",
"import": "./dist/server/index.js"
},
"./bundled": {
"types": "./dist/bundled.d.ts",
"import": "./dist/bundled.js"
},
"./env": "./env.d.ts",
"./components/control": "./components/control/index.ts",
"./components/control/*": "./components/control/*",
Expand Down
3 changes: 3 additions & 0 deletions packages/astro/react/package.json
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
{
"main": "../../dist/react/index.js"
}
1 change: 0 additions & 1 deletion packages/astro/src/bundled.ts

This file was deleted.

61 changes: 2 additions & 59 deletions packages/astro/src/client/index.ts
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,2 @@
import { waitForClerkScript } from '../internal/utils/loadClerkJSScript';
import { $clerk, $csrState } from '../stores/internal';
import type { AstroClerkIntegrationParams, AstroClerkUpdateOptions } from '../types';
import { mountAllClerkAstroJSComponents } from './mount-clerk-astro-js-components';
import { runOnce } from './run-once';

let initOptions: AstroClerkIntegrationParams | undefined;

/**
* Prevents firing clerk.load multiple times
*/
export const createClerkInstance = runOnce(createClerkInstanceInternal);

export async function createClerkInstanceInternal(options?: AstroClerkIntegrationParams) {
let clerkJSInstance = window.Clerk;
if (!clerkJSInstance) {
await waitForClerkScript();

if (!window.Clerk) {
throw new Error('Failed to download latest ClerkJS. Contact support@clerk.com.');
}
clerkJSInstance = window.Clerk;
}

if (!$clerk.get()) {
// @ts-ignore
$clerk.set(clerkJSInstance);
}

initOptions = options;
// TODO: Update Clerk type from @clerk/types to include this method
return (clerkJSInstance as any)
.load(options)
.then(() => {
$csrState.setKey('isLoaded', true);

mountAllClerkAstroJSComponents();

clerkJSInstance.addListener(payload => {
$csrState.setKey('client', payload.client);
$csrState.setKey('user', payload.user);
$csrState.setKey('session', payload.session);
$csrState.setKey('organization', payload.organization);
});
})
.catch(() => {});
}

export function updateClerkOptions(options: AstroClerkUpdateOptions) {
const clerk = $clerk.get();
if (!clerk) {
throw new Error('Missing clerk instance');
}
// TODO: Update Clerk type from @clerk/types to include this method
void (clerk as any).__unstable__updateProps({
options: { ...initOptions, ...options },
appearance: { ...initOptions?.appearance, ...options.appearance },
});
}
export { updateClerkOptions } from '../internal/create-clerk-instance';
export * from '../stores/external';
1 change: 0 additions & 1 deletion packages/astro/src/client/stores/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/astro/src/globals.d.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,5 +3,4 @@ export {};
declare global {
const PACKAGE_NAME: string;
const PACKAGE_VERSION: string;
const __HOTLOAD__: string;
}
4 changes: 3 additions & 1 deletion packages/astro/src/index.ts
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
export { default } from './integration';
import { createIntegration } from './integration/create-integration';

export default createIntegration();
5 changes: 0 additions & 5 deletions packages/astro/src/integration/bundled.ts

This file was deleted.

12 changes: 3 additions & 9 deletions packages/astro/src/integration/create-integration.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,10 +14,8 @@ type HotloadAstroClerkIntegrationParams = AstroClerkIntegrationParams & {
clerkJSVersion?: string;
};

function createIntegration<P extends { mode: 'hotload' | 'bundled' }>({ mode }: P) {
return (
params?: P['mode'] extends 'hotload' ? HotloadAstroClerkIntegrationParams : AstroClerkIntegrationParams,
): AstroIntegration => {
function createIntegration<Params extends HotloadAstroClerkIntegrationParams>() {
return (params?: Params): AstroIntegration => {
const { proxyUrl, isSatellite, domain, signInUrl, signUpUrl } = params || {};

// These are not provided when the "bundled" integration is used
Expand DownExpand Up@@ -50,10 +48,7 @@ function createIntegration<P extends { mode: 'hotload' | 'bundled' }>({ mode }:
},
};

const defaultBundledImportPath = `${packageName}/internal/bundled`;

const buildImportPath =
mode === 'bundled' ? defaultBundledImportPath : defaultBundledImportPath.replace('/bundled', '');
const buildImportPath = `${packageName}/internal`;

// Set params as envs do backend code has access to them
updateConfig({
Expand All@@ -72,7 +67,6 @@ function createIntegration<P extends { mode: 'hotload' | 'bundled' }>({ mode }:
...buildEnvVarFromOption(clerkJSUrl, 'PUBLIC_CLERK_JS_URL'),
...buildEnvVarFromOption(clerkJSVariant, 'PUBLIC_CLERK_JS_VARIANT'),
...buildEnvVarFromOption(clerkJSVersion, 'PUBLIC_CLERK_JS_VERSION'),
__HOTLOAD__: mode === 'hotload',
},

ssr: {
Expand Down
5 changes: 0 additions & 5 deletions packages/astro/src/integration/index.ts

This file was deleted.

13 changes: 0 additions & 13 deletions packages/astro/src/internal/bundled.ts

This file was deleted.

Original file line numberDiff line numberDiff line change
@@ -1,30 +1,35 @@
import { Clerk } from '@clerk/clerk-js';

import { waitForClerkScript } from '../internal/utils/loadClerkJSScript';
import { $clerk, $csrState } from '../stores/internal';
import type { AstroClerkCreateInstanceParams, AstroClerkUpdateOptions } from '../types';
import type { AstroClerkIntegrationParams, AstroClerkUpdateOptions } from '../types';
import { mountAllClerkAstroJSComponents } from './mount-clerk-astro-js-components';
import { runOnce } from './run-once';
import type { CreateClerkInstanceInternalFn } from './types';

let initOptions: AstroClerkCreateInstanceParams | undefined;
let initOptions: AstroClerkIntegrationParams | undefined;

/**
* Prevents firing clerk.load multiple times
*/
export const createClerkInstance: CreateClerkInstanceInternalFn = runOnce(createClerkInstanceInternal);
const createClerkInstance = runOnce(createClerkInstanceInternal);

export function createClerkInstanceInternal(options?: AstroClerkCreateInstanceParams) {
let clerkJSInstance = window.Clerk as unknown as Clerk;
async function createClerkInstanceInternal(options?: AstroClerkIntegrationParams) {
let clerkJSInstance = window.Clerk;
if (!clerkJSInstance) {
clerkJSInstance = new Clerk(options!.publishableKey);
await waitForClerkScript();

if (!window.Clerk) {
throw new Error('Failed to download latest ClerkJS. Contact support@clerk.com.');
}
clerkJSInstance = window.Clerk;
}

if (!$clerk.get()) {
// @ts-ignore
$clerk.set(clerkJSInstance);
// @ts-ignore
window.Clerk = clerkJSInstance;
}

initOptions = options;
return clerkJSInstance
// TODO: Update Clerk type from @clerk/types to include this method
return (clerkJSInstance as any)
.load(options)
.then(() => {
$csrState.setKey('isLoaded', true);
Expand All@@ -41,14 +46,16 @@ export function createClerkInstanceInternal(options?: AstroClerkCreateInstancePa
.catch(() => {});
}

export function updateClerkOptions(options: AstroClerkUpdateOptions) {
function updateClerkOptions(options: AstroClerkUpdateOptions) {
const clerk = $clerk.get();
if (!clerk) {
throw new Error('Missing clerk instance');
}
//@ts-ignore
clerk.__unstable__updateProps({
// TODO: Update Clerk type from @clerk/types to include this method
void (clerk as any).__unstable__updateProps({
options: { ...initOptions, ...options },
appearance: { ...initOptions?.appearance, ...options.appearance },
});
}

export { createClerkInstance, updateClerkOptions };
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
import type { CreateClerkInstanceInternalFn } from '../client/types';
import { $initialState } from '../stores/internal';
import type { AstroClerkIntegrationParams } from '../types';
import { mergeEnvVarsWithParams } from './merge-env-vars-with-params';
import type { CreateClerkInstanceInternalFn } from './types';

/**
* @internal
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/internal/index.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,7 @@
* injectScript('before-hydration', `...`)
*/

import { createClerkInstance } from '../client';
import { createClerkInstance } from './create-clerk-instance';
import { createInjectionScriptRunner } from './create-injection-script-runner';

const runInjectionScript = createInjectionScriptRunner(createClerkInstance);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,7 +17,9 @@ export const SignOutButton = withClerk(

const clickHandler = () => clerk?.signOut({ redirectUrl, sessionId });
const wrappedChildClickHandler: React.MouseEventHandler = async e => {
await safeExecute((child as any).props.onClick)(e);
if (child && typeof child === 'object' && 'props' in child) {
await safeExecute(child.props.onClick)(e);
}
return clickHandler();
};

Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
import type { CheckAuthorizationWithCustomPermissions } from '@clerk/types';
import type { PropsWithChildren } from 'react';

import type { ProtectComponentDefaultProps } from '../../types';
import type { ProtectComponentDefaultProps } from '../types';
import { useAuth } from './hooks';

export function SignedOut(props: PropsWithChildren) {
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,8 +12,8 @@ import { useCallback, useSyncExternalStore } from 'react';
// @ts-ignore
import { authAsyncStorage } from '#async-local-storage';

import { $authStore } from '../../stores/external';
import { $clerk, $csrState } from '../../stores/internal';
import { $authStore } from '../stores/external';
import { $clerk, $csrState } from '../stores/internal';

type CheckAuthorizationSignedOut = undefined;
type CheckAuthorizationWithoutOrgOrUser = (params?: Parameters<CheckAuthorizationWithCustomPermissions>[0]) => false;
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
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
15 changes: 15 additions & 0 deletions .changeset/four-days-hammer.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
---
"@clerk/astro": patch
---

Simplify submodules and drop the `bunlded` variant.

Moved
- `@clerk/astro/client/react` to `@clerk/astro/react`
- `@clerk/astro/client/stores` to `@clerk/astro/client`
Dropped
- `@clerk/astro/bundled`
- `@clerk/astro/client/bundled`
- `@clerk/astro/internal/bundled`
- `@clerk/astro/integration`
- `@clerk/astro/integration/bundled`
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
import { useAuth } from '@clerk/astro/client/react';
import { useAuth } from '@clerk/astro/react';
import React from 'react';
import { type PropsWithChildren } from 'react';

Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
import React, { type PropsWithChildren, useSyncExternalStore } from 'react';
import { UserProfile } from '@clerk/astro/client/react';
import { $userStore } from '@clerk/astro/client/stores';
import { UserProfile } from '@clerk/astro/react';
import { $userStore } from '@clerk/astro/client';

export function PageWithUser({ children }: PropsWithChildren) {
const user = useSyncExternalStore($userStore.listen, $userStore.get, $userStore.get);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,7 @@ interface Props {

const { title } = Astro.props;

import { SignedIn, SignedOut, UserButton } from "@clerk/astro/client/react";
import { SignedIn, SignedOut, UserButton } from "@clerk/astro/react";
import { LanguagePicker } from "../../components/LanguagePicker";
---

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,7 +12,7 @@ interface Props extends SignOutOptions {
</script>

<script>
import { $clerkStore } from "@clerk/astro/client/stores";
import { $clerkStore } from "@clerk/astro/client";

const button = document.querySelector(
"[data-sign-out-button]",
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,7 +3,7 @@ import Layout from "../../layouts/react/Layout.astro";
import Card from "../../components/Card.astro";
import SignOutButton from "../../lib/astro-components/SignOutButton.astro";

import { SignedIn, SignedOut, OrganizationSwitcher } from "@clerk/astro/client/react";
import { SignedIn, SignedOut, OrganizationSwitcher } from "@clerk/astro/react";
---

<Layout title="Welcome to Astro.">
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
---
import { Protect } from "@clerk/astro/client/react";
import { Protect } from "@clerk/astro/react";
import Layout from "../../layouts/react/Layout.astro";
---

Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
---
import { Protect } from "@clerk/astro/client/react";
import { Protect } from "@clerk/astro/react";
import Layout from "../../layouts/react/Layout.astro";
---

Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
---
import { SignIn } from "@clerk/astro/client/react";
import { SignIn } from "@clerk/astro/react";
import Layout from "../../layouts/react/Layout.astro";
---

Expand Down
3 changes: 0 additions & 3 deletions packages/astro/client/react/package.json

This file was deleted.

3 changes: 0 additions & 3 deletions packages/astro/client/stores/package.json

This file was deleted.

30 changes: 3 additions & 27 deletions packages/astro/package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -50,46 +50,22 @@
"types": "./dist/index.d.ts",
"import": "./dist/index.js"
},
"./client/react": {
"types": "./dist/client/react/index.d.ts",
"import": "./dist/client/react/index.js"
},
"./client/stores": {
"types": "./dist/client/stores/index.d.ts",
"import": "./dist/client/stores/index.js"
"./react": {
"types": "./dist/react/index.d.ts",
"import": "./dist/react/index.js"
},
"./client": {
"types": "./dist/client/index.d.ts",
"import": "./dist/client/index.js"
},
"./client/bundled": {
"types": "./dist/client/bundled.d.ts",
"import": "./dist/client/bundled.js"
},
"./integration": {
"types": "./dist/integration/index.d.ts",
"import": "./dist/integration/index.js"
},
"./integration/bundled": {
"types": "./dist/integration/bundled.d.ts",
"import": "./dist/integration/bundled.js"
},
"./internal": {
"types": "./dist/internal/index.d.ts",
"import": "./dist/internal/index.js"
},
"./internal/bundled": {
"types": "./dist/internal/bundled.d.ts",
"import": "./dist/internal/bundled.js"
},
"./server": {
"types": "./dist/server/index.d.ts",
"import": "./dist/server/index.js"
},
"./bundled": {
"types": "./dist/bundled.d.ts",
"import": "./dist/bundled.js"
},
"./env": "./env.d.ts",
"./components/control": "./components/control/index.ts",
"./components/control/*": "./components/control/*",
Expand Down
3 changes: 3 additions & 0 deletions packages/astro/react/package.json
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
{
"main": "../../dist/react/index.js"
}
1 change: 0 additions & 1 deletion packages/astro/src/bundled.ts

This file was deleted.

61 changes: 2 additions & 59 deletions packages/astro/src/client/index.ts
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,2 @@
import { waitForClerkScript } from '../internal/utils/loadClerkJSScript';
import { $clerk, $csrState } from '../stores/internal';
import type { AstroClerkIntegrationParams, AstroClerkUpdateOptions } from '../types';
import { mountAllClerkAstroJSComponents } from './mount-clerk-astro-js-components';
import { runOnce } from './run-once';

let initOptions: AstroClerkIntegrationParams | undefined;

/**
* Prevents firing clerk.load multiple times
*/
export const createClerkInstance = runOnce(createClerkInstanceInternal);

export async function createClerkInstanceInternal(options?: AstroClerkIntegrationParams) {
let clerkJSInstance = window.Clerk;
if (!clerkJSInstance) {
await waitForClerkScript();

if (!window.Clerk) {
throw new Error('Failed to download latest ClerkJS. Contact support@clerk.com.');
}
clerkJSInstance = window.Clerk;
}

if (!$clerk.get()) {
// @ts-ignore
$clerk.set(clerkJSInstance);
}

initOptions = options;
// TODO: Update Clerk type from @clerk/types to include this method
return (clerkJSInstance as any)
.load(options)
.then(() => {
$csrState.setKey('isLoaded', true);

mountAllClerkAstroJSComponents();

clerkJSInstance.addListener(payload => {
$csrState.setKey('client', payload.client);
$csrState.setKey('user', payload.user);
$csrState.setKey('session', payload.session);
$csrState.setKey('organization', payload.organization);
});
})
.catch(() => {});
}

export function updateClerkOptions(options: AstroClerkUpdateOptions) {
const clerk = $clerk.get();
if (!clerk) {
throw new Error('Missing clerk instance');
}
// TODO: Update Clerk type from @clerk/types to include this method
void (clerk as any).__unstable__updateProps({
options: { ...initOptions, ...options },
appearance: { ...initOptions?.appearance, ...options.appearance },
});
}
export { updateClerkOptions } from '../internal/create-clerk-instance';
export * from '../stores/external';
1 change: 0 additions & 1 deletion packages/astro/src/client/stores/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/astro/src/globals.d.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,5 +3,4 @@ export {};
declare global {
const PACKAGE_NAME: string;
const PACKAGE_VERSION: string;
const __HOTLOAD__: string;
}
4 changes: 3 additions & 1 deletion packages/astro/src/index.ts
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
export { default } from './integration';
import { createIntegration } from './integration/create-integration';

export default createIntegration();
5 changes: 0 additions & 5 deletions packages/astro/src/integration/bundled.ts

This file was deleted.

12 changes: 3 additions & 9 deletions packages/astro/src/integration/create-integration.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,10 +14,8 @@ type HotloadAstroClerkIntegrationParams = AstroClerkIntegrationParams & {
clerkJSVersion?: string;
};

function createIntegration<P extends { mode: 'hotload' | 'bundled' }>({ mode }: P) {
return (
params?: P['mode'] extends 'hotload' ? HotloadAstroClerkIntegrationParams : AstroClerkIntegrationParams,
): AstroIntegration => {
function createIntegration<Params extends HotloadAstroClerkIntegrationParams>() {
return (params?: Params): AstroIntegration => {
const { proxyUrl, isSatellite, domain, signInUrl, signUpUrl } = params || {};

// These are not provided when the "bundled" integration is used
Expand DownExpand Up@@ -50,10 +48,7 @@ function createIntegration<P extends { mode: 'hotload' | 'bundled' }>({ mode }:
},
};

const defaultBundledImportPath = `${packageName}/internal/bundled`;

const buildImportPath =
mode === 'bundled' ? defaultBundledImportPath : defaultBundledImportPath.replace('/bundled', '');
const buildImportPath = `${packageName}/internal`;

// Set params as envs do backend code has access to them
updateConfig({
Expand All@@ -72,7 +67,6 @@ function createIntegration<P extends { mode: 'hotload' | 'bundled' }>({ mode }:
...buildEnvVarFromOption(clerkJSUrl, 'PUBLIC_CLERK_JS_URL'),
...buildEnvVarFromOption(clerkJSVariant, 'PUBLIC_CLERK_JS_VARIANT'),
...buildEnvVarFromOption(clerkJSVersion, 'PUBLIC_CLERK_JS_VERSION'),
__HOTLOAD__: mode === 'hotload',
},

ssr: {
Expand Down
5 changes: 0 additions & 5 deletions packages/astro/src/integration/index.ts

This file was deleted.

13 changes: 0 additions & 13 deletions packages/astro/src/internal/bundled.ts

This file was deleted.

Original file line numberDiff line numberDiff line change
@@ -1,30 +1,35 @@
import { Clerk } from '@clerk/clerk-js';

import { waitForClerkScript } from '../internal/utils/loadClerkJSScript';
import { $clerk, $csrState } from '../stores/internal';
import type { AstroClerkCreateInstanceParams, AstroClerkUpdateOptions } from '../types';
import type { AstroClerkIntegrationParams, AstroClerkUpdateOptions } from '../types';
import { mountAllClerkAstroJSComponents } from './mount-clerk-astro-js-components';
import { runOnce } from './run-once';
import type { CreateClerkInstanceInternalFn } from './types';

let initOptions: AstroClerkCreateInstanceParams | undefined;
let initOptions: AstroClerkIntegrationParams | undefined;

/**
* Prevents firing clerk.load multiple times
*/
export const createClerkInstance: CreateClerkInstanceInternalFn = runOnce(createClerkInstanceInternal);
const createClerkInstance = runOnce(createClerkInstanceInternal);

export function createClerkInstanceInternal(options?: AstroClerkCreateInstanceParams) {
let clerkJSInstance = window.Clerk as unknown as Clerk;
async function createClerkInstanceInternal(options?: AstroClerkIntegrationParams) {
let clerkJSInstance = window.Clerk;
if (!clerkJSInstance) {
clerkJSInstance = new Clerk(options!.publishableKey);
await waitForClerkScript();

if (!window.Clerk) {
throw new Error('Failed to download latest ClerkJS. Contact support@clerk.com.');
}
clerkJSInstance = window.Clerk;
}

if (!$clerk.get()) {
// @ts-ignore
$clerk.set(clerkJSInstance);
// @ts-ignore
window.Clerk = clerkJSInstance;
}

initOptions = options;
return clerkJSInstance
// TODO: Update Clerk type from @clerk/types to include this method
return (clerkJSInstance as any)
.load(options)
.then(() => {
$csrState.setKey('isLoaded', true);
Expand All@@ -41,14 +46,16 @@ export function createClerkInstanceInternal(options?: AstroClerkCreateInstancePa
.catch(() => {});
}

export function updateClerkOptions(options: AstroClerkUpdateOptions) {
function updateClerkOptions(options: AstroClerkUpdateOptions) {
const clerk = $clerk.get();
if (!clerk) {
throw new Error('Missing clerk instance');
}
//@ts-ignore
clerk.__unstable__updateProps({
// TODO: Update Clerk type from @clerk/types to include this method
void (clerk as any).__unstable__updateProps({
options: { ...initOptions, ...options },
appearance: { ...initOptions?.appearance, ...options.appearance },
});
}

export { createClerkInstance, updateClerkOptions };
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
import type { CreateClerkInstanceInternalFn } from '../client/types';
import { $initialState } from '../stores/internal';
import type { AstroClerkIntegrationParams } from '../types';
import { mergeEnvVarsWithParams } from './merge-env-vars-with-params';
import type { CreateClerkInstanceInternalFn } from './types';

/**
* @internal
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/internal/index.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,7 @@
* injectScript('before-hydration', `...`)
*/

import { createClerkInstance } from '../client';
import { createClerkInstance } from './create-clerk-instance';
import { createInjectionScriptRunner } from './create-injection-script-runner';

const runInjectionScript = createInjectionScriptRunner(createClerkInstance);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,7 +17,9 @@ export const SignOutButton = withClerk(

const clickHandler = () => clerk?.signOut({ redirectUrl, sessionId });
const wrappedChildClickHandler: React.MouseEventHandler = async e => {
await safeExecute((child as any).props.onClick)(e);
if (child && typeof child === 'object' && 'props' in child) {
await safeExecute(child.props.onClick)(e);
}
return clickHandler();
};

Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
import type { CheckAuthorizationWithCustomPermissions } from '@clerk/types';
import type { PropsWithChildren } from 'react';

import type { ProtectComponentDefaultProps } from '../../types';
import type { ProtectComponentDefaultProps } from '../types';
import { useAuth } from './hooks';

export function SignedOut(props: PropsWithChildren) {
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,8 +12,8 @@ import { useCallback, useSyncExternalStore } from 'react';
// @ts-ignore
import { authAsyncStorage } from '#async-local-storage';

import { $authStore } from '../../stores/external';
import { $clerk, $csrState } from '../../stores/internal';
import { $authStore } from '../stores/external';
import { $clerk, $csrState } from '../stores/internal';

type CheckAuthorizationSignedOut = undefined;
type CheckAuthorizationWithoutOrgOrUser = (params?: Parameters<CheckAuthorizationWithCustomPermissions>[0]) => false;
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
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
15 changes: 15 additions & 0 deletions .changeset/four-days-hammer.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
---
"@clerk/astro": patch
---

Simplify submodules and drop the `bunlded` variant.

Moved
- `@clerk/astro/client/react` to `@clerk/astro/react`
- `@clerk/astro/client/stores` to `@clerk/astro/client`
Dropped
- `@clerk/astro/bundled`
- `@clerk/astro/client/bundled`
- `@clerk/astro/internal/bundled`
- `@clerk/astro/integration`
- `@clerk/astro/integration/bundled`
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
import { useAuth } from '@clerk/astro/client/react';
import { useAuth } from '@clerk/astro/react';
import React from 'react';
import { type PropsWithChildren } from 'react';

Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
import React, { type PropsWithChildren, useSyncExternalStore } from 'react';
import { UserProfile } from '@clerk/astro/client/react';
import { $userStore } from '@clerk/astro/client/stores';
import { UserProfile } from '@clerk/astro/react';
import { $userStore } from '@clerk/astro/client';

export function PageWithUser({ children }: PropsWithChildren) {
const user = useSyncExternalStore($userStore.listen, $userStore.get, $userStore.get);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,7 @@ interface Props {

const { title } = Astro.props;

import { SignedIn, SignedOut, UserButton } from "@clerk/astro/client/react";
import { SignedIn, SignedOut, UserButton } from "@clerk/astro/react";
import { LanguagePicker } from "../../components/LanguagePicker";
---

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,7 +12,7 @@ interface Props extends SignOutOptions {
</script>

<script>
import { $clerkStore } from "@clerk/astro/client/stores";
import { $clerkStore } from "@clerk/astro/client";

const button = document.querySelector(
"[data-sign-out-button]",
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,7 +3,7 @@ import Layout from "../../layouts/react/Layout.astro";
import Card from "../../components/Card.astro";
import SignOutButton from "../../lib/astro-components/SignOutButton.astro";

import { SignedIn, SignedOut, OrganizationSwitcher } from "@clerk/astro/client/react";
import { SignedIn, SignedOut, OrganizationSwitcher } from "@clerk/astro/react";
---

<Layout title="Welcome to Astro.">
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
---
import { Protect } from "@clerk/astro/client/react";
import { Protect } from "@clerk/astro/react";
import Layout from "../../layouts/react/Layout.astro";
---

Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
---
import { Protect } from "@clerk/astro/client/react";
import { Protect } from "@clerk/astro/react";
import Layout from "../../layouts/react/Layout.astro";
---

Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
---
import { SignIn } from "@clerk/astro/client/react";
import { SignIn } from "@clerk/astro/react";
import Layout from "../../layouts/react/Layout.astro";
---

Expand Down
3 changes: 0 additions & 3 deletions packages/astro/client/react/package.json

This file was deleted.

3 changes: 0 additions & 3 deletions packages/astro/client/stores/package.json

This file was deleted.

30 changes: 3 additions & 27 deletions packages/astro/package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -50,46 +50,22 @@
"types": "./dist/index.d.ts",
"import": "./dist/index.js"
},
"./client/react": {
"types": "./dist/client/react/index.d.ts",
"import": "./dist/client/react/index.js"
},
"./client/stores": {
"types": "./dist/client/stores/index.d.ts",
"import": "./dist/client/stores/index.js"
"./react": {
"types": "./dist/react/index.d.ts",
"import": "./dist/react/index.js"
},
"./client": {
"types": "./dist/client/index.d.ts",
"import": "./dist/client/index.js"
},
"./client/bundled": {
"types": "./dist/client/bundled.d.ts",
"import": "./dist/client/bundled.js"
},
"./integration": {
"types": "./dist/integration/index.d.ts",
"import": "./dist/integration/index.js"
},
"./integration/bundled": {
"types": "./dist/integration/bundled.d.ts",
"import": "./dist/integration/bundled.js"
},
"./internal": {
"types": "./dist/internal/index.d.ts",
"import": "./dist/internal/index.js"
},
"./internal/bundled": {
"types": "./dist/internal/bundled.d.ts",
"import": "./dist/internal/bundled.js"
},
"./server": {
"types": "./dist/server/index.d.ts",
"import": "./dist/server/index.js"
},
"./bundled": {
"types": "./dist/bundled.d.ts",
"import": "./dist/bundled.js"
},
"./env": "./env.d.ts",
"./components/control": "./components/control/index.ts",
"./components/control/*": "./components/control/*",
Expand Down
3 changes: 3 additions & 0 deletions packages/astro/react/package.json
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
{
"main": "../../dist/react/index.js"
}
1 change: 0 additions & 1 deletion packages/astro/src/bundled.ts

This file was deleted.

61 changes: 2 additions & 59 deletions packages/astro/src/client/index.ts
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,2 @@
import { waitForClerkScript } from '../internal/utils/loadClerkJSScript';
import { $clerk, $csrState } from '../stores/internal';
import type { AstroClerkIntegrationParams, AstroClerkUpdateOptions } from '../types';
import { mountAllClerkAstroJSComponents } from './mount-clerk-astro-js-components';
import { runOnce } from './run-once';

let initOptions: AstroClerkIntegrationParams | undefined;

/**
* Prevents firing clerk.load multiple times
*/
export const createClerkInstance = runOnce(createClerkInstanceInternal);

export async function createClerkInstanceInternal(options?: AstroClerkIntegrationParams) {
let clerkJSInstance = window.Clerk;
if (!clerkJSInstance) {
await waitForClerkScript();

if (!window.Clerk) {
throw new Error('Failed to download latest ClerkJS. Contact support@clerk.com.');
}
clerkJSInstance = window.Clerk;
}

if (!$clerk.get()) {
// @ts-ignore
$clerk.set(clerkJSInstance);
}

initOptions = options;
// TODO: Update Clerk type from @clerk/types to include this method
return (clerkJSInstance as any)
.load(options)
.then(() => {
$csrState.setKey('isLoaded', true);

mountAllClerkAstroJSComponents();

clerkJSInstance.addListener(payload => {
$csrState.setKey('client', payload.client);
$csrState.setKey('user', payload.user);
$csrState.setKey('session', payload.session);
$csrState.setKey('organization', payload.organization);
});
})
.catch(() => {});
}

export function updateClerkOptions(options: AstroClerkUpdateOptions) {
const clerk = $clerk.get();
if (!clerk) {
throw new Error('Missing clerk instance');
}
// TODO: Update Clerk type from @clerk/types to include this method
void (clerk as any).__unstable__updateProps({
options: { ...initOptions, ...options },
appearance: { ...initOptions?.appearance, ...options.appearance },
});
}
export { updateClerkOptions } from '../internal/create-clerk-instance';
export * from '../stores/external';
1 change: 0 additions & 1 deletion packages/astro/src/client/stores/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/astro/src/globals.d.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,5 +3,4 @@ export {};
declare global {
const PACKAGE_NAME: string;
const PACKAGE_VERSION: string;
const __HOTLOAD__: string;
}
4 changes: 3 additions & 1 deletion packages/astro/src/index.ts
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
export { default } from './integration';
import { createIntegration } from './integration/create-integration';

export default createIntegration();
5 changes: 0 additions & 5 deletions packages/astro/src/integration/bundled.ts

This file was deleted.

12 changes: 3 additions & 9 deletions packages/astro/src/integration/create-integration.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,10 +14,8 @@ type HotloadAstroClerkIntegrationParams = AstroClerkIntegrationParams & {
clerkJSVersion?: string;
};

function createIntegration<P extends { mode: 'hotload' | 'bundled' }>({ mode }: P) {
return (
params?: P['mode'] extends 'hotload' ? HotloadAstroClerkIntegrationParams : AstroClerkIntegrationParams,
): AstroIntegration => {
function createIntegration<Params extends HotloadAstroClerkIntegrationParams>() {
return (params?: Params): AstroIntegration => {
const { proxyUrl, isSatellite, domain, signInUrl, signUpUrl } = params || {};

// These are not provided when the "bundled" integration is used
Expand DownExpand Up@@ -50,10 +48,7 @@ function createIntegration<P extends { mode: 'hotload' | 'bundled' }>({ mode }:
},
};

const defaultBundledImportPath = `${packageName}/internal/bundled`;

const buildImportPath =
mode === 'bundled' ? defaultBundledImportPath : defaultBundledImportPath.replace('/bundled', '');
const buildImportPath = `${packageName}/internal`;

// Set params as envs do backend code has access to them
updateConfig({
Expand All@@ -72,7 +67,6 @@ function createIntegration<P extends { mode: 'hotload' | 'bundled' }>({ mode }:
...buildEnvVarFromOption(clerkJSUrl, 'PUBLIC_CLERK_JS_URL'),
...buildEnvVarFromOption(clerkJSVariant, 'PUBLIC_CLERK_JS_VARIANT'),
...buildEnvVarFromOption(clerkJSVersion, 'PUBLIC_CLERK_JS_VERSION'),
__HOTLOAD__: mode === 'hotload',
},

ssr: {
Expand Down
5 changes: 0 additions & 5 deletions packages/astro/src/integration/index.ts

This file was deleted.

13 changes: 0 additions & 13 deletions packages/astro/src/internal/bundled.ts

This file was deleted.

Original file line numberDiff line numberDiff line change
@@ -1,30 +1,35 @@
import { Clerk } from '@clerk/clerk-js';

import { waitForClerkScript } from '../internal/utils/loadClerkJSScript';
import { $clerk, $csrState } from '../stores/internal';
import type { AstroClerkCreateInstanceParams, AstroClerkUpdateOptions } from '../types';
import type { AstroClerkIntegrationParams, AstroClerkUpdateOptions } from '../types';
import { mountAllClerkAstroJSComponents } from './mount-clerk-astro-js-components';
import { runOnce } from './run-once';
import type { CreateClerkInstanceInternalFn } from './types';

let initOptions: AstroClerkCreateInstanceParams | undefined;
let initOptions: AstroClerkIntegrationParams | undefined;

/**
* Prevents firing clerk.load multiple times
*/
export const createClerkInstance: CreateClerkInstanceInternalFn = runOnce(createClerkInstanceInternal);
const createClerkInstance = runOnce(createClerkInstanceInternal);

export function createClerkInstanceInternal(options?: AstroClerkCreateInstanceParams) {
let clerkJSInstance = window.Clerk as unknown as Clerk;
async function createClerkInstanceInternal(options?: AstroClerkIntegrationParams) {
let clerkJSInstance = window.Clerk;
if (!clerkJSInstance) {
clerkJSInstance = new Clerk(options!.publishableKey);
await waitForClerkScript();

if (!window.Clerk) {
throw new Error('Failed to download latest ClerkJS. Contact support@clerk.com.');
}
clerkJSInstance = window.Clerk;
}

if (!$clerk.get()) {
// @ts-ignore
$clerk.set(clerkJSInstance);
// @ts-ignore
window.Clerk = clerkJSInstance;
}

initOptions = options;
return clerkJSInstance
// TODO: Update Clerk type from @clerk/types to include this method
return (clerkJSInstance as any)
.load(options)
.then(() => {
$csrState.setKey('isLoaded', true);
Expand All@@ -41,14 +46,16 @@ export function createClerkInstanceInternal(options?: AstroClerkCreateInstancePa
.catch(() => {});
}

export function updateClerkOptions(options: AstroClerkUpdateOptions) {
function updateClerkOptions(options: AstroClerkUpdateOptions) {
const clerk = $clerk.get();
if (!clerk) {
throw new Error('Missing clerk instance');
}
//@ts-ignore
clerk.__unstable__updateProps({
// TODO: Update Clerk type from @clerk/types to include this method
void (clerk as any).__unstable__updateProps({
options: { ...initOptions, ...options },
appearance: { ...initOptions?.appearance, ...options.appearance },
});
}

export { createClerkInstance, updateClerkOptions };
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
import type { CreateClerkInstanceInternalFn } from '../client/types';
import { $initialState } from '../stores/internal';
import type { AstroClerkIntegrationParams } from '../types';
import { mergeEnvVarsWithParams } from './merge-env-vars-with-params';
import type { CreateClerkInstanceInternalFn } from './types';

/**
* @internal
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/internal/index.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,7 @@
* injectScript('before-hydration', `...`)
*/

import { createClerkInstance } from '../client';
import { createClerkInstance } from './create-clerk-instance';
import { createInjectionScriptRunner } from './create-injection-script-runner';

const runInjectionScript = createInjectionScriptRunner(createClerkInstance);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,7 +17,9 @@ export const SignOutButton = withClerk(

const clickHandler = () => clerk?.signOut({ redirectUrl, sessionId });
const wrappedChildClickHandler: React.MouseEventHandler = async e => {
await safeExecute((child as any).props.onClick)(e);
if (child && typeof child === 'object' && 'props' in child) {
await safeExecute(child.props.onClick)(e);
}
return clickHandler();
};

Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
import type { CheckAuthorizationWithCustomPermissions } from '@clerk/types';
import type { PropsWithChildren } from 'react';

import type { ProtectComponentDefaultProps } from '../../types';
import type { ProtectComponentDefaultProps } from '../types';
import { useAuth } from './hooks';

export function SignedOut(props: PropsWithChildren) {
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,8 +12,8 @@ import { useCallback, useSyncExternalStore } from 'react';
// @ts-ignore
import { authAsyncStorage } from '#async-local-storage';

import { $authStore } from '../../stores/external';
import { $clerk, $csrState } from '../../stores/internal';
import { $authStore } from '../stores/external';
import { $clerk, $csrState } from '../stores/internal';

type CheckAuthorizationSignedOut = undefined;
type CheckAuthorizationWithoutOrgOrUser = (params?: Parameters<CheckAuthorizationWithCustomPermissions>[0]) => false;
Expand Down
Loading