Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
51 changes: 34 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,17 @@ pnpm add @unraid/shared-callbacks
## Usage

```typescript
import { createCallbackStore, CallbackActionsStore } from '@unraid/shared-callbacks';

// Define your callback actions store
const useCallbackActions = (): CallbackActionsStore => ({
saveCallbackData: (decryptedData) => {
// Handle the decrypted callback data
console.log(decryptedData);
},
import { createCallback } from '@unraid/shared-callbacks';

const callback = createCallback({
encryptionKey: 'your-encryption-key',
sendType: 'forUpc'
// Optional: when true (default), encrypted data is stored in the hash
// instead of the `data` query parameter.
useHash: true,
});

// Create the callback store
const callbackStore = createCallbackStore(useCallbackActions);

// Use the store to send callbacks
callbackStore.send('https://example.com/callback', [
// Send encrypted callbacks (client-only)
callback.send('https://example.com/callback', [
{
type: 'signIn',
apiKey: 'your-api-key',
Expand All @@ -44,8 +38,8 @@ callbackStore.send('https://example.com/callback', [
}
]);

// Watch for incoming callbacks
callbackStore.watcher();
// Watch for incoming callbacks (client-only)
const decrypted = callback.watcher();
```

## API
Expand Down Expand Up @@ -82,7 +76,7 @@ interface CallbackActionsStore {

By default, encrypted callback data is now placed in the URL hash (fragment) rather than a query parameter to help prevent sensitive data from being sent in referrers.

You can control this behavior via the `CallbackConfig` passed to `useCallback`:
You can control this behavior via the `CallbackConfig` passed to `createCallback`:

```ts
interface CallbackConfig {
Expand All @@ -96,3 +90,26 @@ interface CallbackConfig {
```

Parsing helpers (`parse`, `watcher`) support both formats and will read encrypted data from either the hash or the `data` query parameter.

### Server / client entrypoints

To make SSR / Workers usage explicit and safe, the package also exposes split entrypoints:

- `@unraid/shared-callbacks/client` – exports `createCallback` (send, watcher, parse, generateUrl) and all types. This is intended for browser/client-only code.
- `@unraid/shared-callbacks/client` – exports `createCallback` (send, watcher, parse, generateUrl) and all types. This is intended for browser/client-only code.
- `@unraid/shared-callbacks/server` – exports `createServerCallback`, which exposes only `parse` and `generateUrl` and never touches browser globals.

Example server usage:

```ts
import {
createServerCallback,
type CallbackConfig,
} from '@unraid/shared-callbacks/server';

const config: CallbackConfig = {
encryptionKey: 'your-encryption-key',
};

const { parse, generateUrl } = createServerCallback(config);
```
Comment on lines 94 to 114
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Fix duplicated client entry + mismatched code fences (markdown rendering).  

 - `@unraid/shared-callbacks/client` – exports `createCallback` (send, watcher, parse, generateUrl) and all types. This is intended for browser/client-only code.
-- `@unraid/shared-callbacks/client` – exports `createCallback` (send, watcher, parse, generateUrl) and all types. This is intended for browser/client-only code.
 - `@unraid/shared-callbacks/server` – exports `createServerCallback`, which exposes only `parse` and `generateUrl` and never touches browser globals.
@@
 const { parse, generateUrl } = createServerCallback(config);
-```
+```

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In README.md around lines 94 to 115, there's a duplicated client entry and a
markdown code-fence issue: remove the second duplicate "-
`@unraid/shared-callbacks/client`" and replace it with the correct server entry
(if needed ensure the list contains exactly one client and one server entry with
correct descriptions), and fix the code fence by ensuring the example block uses
matching triple backticks with "ts" after the opening fence (```ts) and a
closing ``` at the end so the snippet renders properly.

22 changes: 22 additions & 0 deletions dist/client.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { CallbackConfig, QueryPayloads, SendPayloads, WatcherOptions, SignIn, SignOut, OemSignOut, Troubleshoot, Recover, Replace, TrialExtend, TrialStart, Purchase, Redeem, Renew, Upgrade, UpdateOs, DowngradeOs, Manage, MyKeys, LinkKey, Activate, AccountActionTypes, AccountKeyActionTypes, PurchaseActionTypes, ServerActionTypes, ServerState, ServerData, UserInfo, ExternalSignIn, ExternalSignOut, ExternalKeyActions, ExternalUpdateOsAction, ServerPayload, ServerTroubleshoot, ExternalActions, UpcActions, ExternalPayload, UpcPayload } from "./types.js";
export declare const createCallback: (config: CallbackConfig) => {
send: (url: string, payload: SendPayloads, redirectType?: "newTab" | "replace" | null, sendType?: string, sender?: string) => void;
parse: (data: string, options?: {
isDataURIEncoded?: boolean;
}) => QueryPayloads;
watcher: (options?: WatcherOptions) => QueryPayloads | undefined;
generateUrl: (url: string, payload: SendPayloads, sendType?: string, sender?: string) => string;
};
/**
* Backwards-compatible alias for older consumers.
* This no longer returns a shared singleton; it is a plain factory.
*/
export declare const useCallback: (config: CallbackConfig) => {
send: (url: string, payload: SendPayloads, redirectType?: "newTab" | "replace" | null, sendType?: string, sender?: string) => void;
parse: (data: string, options?: {
isDataURIEncoded?: boolean;
}) => QueryPayloads;
watcher: (options?: WatcherOptions) => QueryPayloads | undefined;
generateUrl: (url: string, payload: SendPayloads, sendType?: string, sender?: string) => string;
};
export type { CallbackConfig, QueryPayloads, SendPayloads, WatcherOptions, SignIn, SignOut, OemSignOut, Troubleshoot, Recover, Replace, TrialExtend, TrialStart, Purchase, Redeem, Renew, Upgrade, UpdateOs, DowngradeOs, Manage, MyKeys, LinkKey, Activate, AccountActionTypes, AccountKeyActionTypes, PurchaseActionTypes, ServerActionTypes, ServerState, ServerData, UserInfo, ExternalSignIn, ExternalSignOut, ExternalKeyActions, ExternalUpdateOsAction, ServerPayload, ServerTroubleshoot, ExternalActions, UpcActions, ExternalPayload, UpcPayload, };
Loading