-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sdk): enhanced event tracking and version management
- Loading branch information
Showing
11 changed files
with
472 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,38 @@ | ||
import typescript from '@rollup/plugin-typescript'; | ||
import typescript from "@rollup/plugin-typescript"; | ||
import packageJson from "./package.json" with { type: "json" }; | ||
import replace from "@rollup/plugin-replace"; | ||
|
||
const version = packageJson.version; | ||
|
||
export default [ | ||
{ | ||
input: 'src/index.ts', | ||
output: { | ||
format: 'esm', | ||
file: './lib/esm/index.mjs', | ||
sourcemap: true | ||
}, | ||
plugins: [typescript()], | ||
external: ['@tonconnect/protocol', '@tonconnect/isomorphic-fetch', '@tonconnect/isomorphic-eventsource'] | ||
{ | ||
input: "src/index.ts", | ||
output: { | ||
format: "esm", | ||
file: "./lib/esm/index.mjs", | ||
sourcemap: true | ||
}, | ||
plugins: [ | ||
replace({ | ||
TON_CONNECT_SDK_VERSION: JSON.stringify(version) | ||
}), | ||
typescript() | ||
], | ||
external: ["@tonconnect/protocol", "@tonconnect/isomorphic-fetch", "@tonconnect/isomorphic-eventsource"] | ||
}, | ||
{ | ||
input: "src/index.ts", | ||
output: { | ||
format: "cjs", | ||
file: "./lib/cjs/index.cjs", | ||
sourcemap: true | ||
}, | ||
{ | ||
input: 'src/index.ts', | ||
output: { | ||
format: 'cjs', | ||
file: './lib/cjs/index.cjs', | ||
sourcemap: true | ||
}, | ||
plugins: [typescript()], | ||
external: ['@tonconnect/protocol', '@tonconnect/isomorphic-fetch', '@tonconnect/isomorphic-eventsource'] | ||
} | ||
plugins: [ | ||
replace({ | ||
TON_CONNECT_SDK_VERSION: JSON.stringify(version) | ||
}), | ||
typescript() | ||
], | ||
external: ["@tonconnect/protocol", "@tonconnect/isomorphic-fetch", "@tonconnect/isomorphic-eventsource"] | ||
} | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
declare const TON_CONNECT_SDK_VERSION: string; | ||
|
||
export const tonConnectSdkVersion = TON_CONNECT_SDK_VERSION; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,38 @@ | ||
/** | ||
* Removes the `ton-connect-` and `ton-connect-ui-` prefixes from the given string. | ||
*/ | ||
export type RemoveTonConnectPrefix<T> = T extends `ton-connect-ui-${infer Rest}` | ||
? Rest | ||
: T extends `ton-connect-${infer Rest}` | ||
? Rest | ||
: T; | ||
|
||
export type AddTonConnectPrefix<T extends string> = `ton-connect-${T}` | `ton-connect-ui-${T}`; | ||
|
||
/** | ||
* Interface for an event dispatcher that sends events. | ||
*/ | ||
export interface EventDispatcher<T> { | ||
export interface EventDispatcher<T extends { type: string }> { | ||
/** | ||
* Dispatches an event with the given name and details. | ||
* @param eventName - The name of the event to dispatch. | ||
* @param eventDetails - The details of the event to dispatch. | ||
*/ | ||
dispatchEvent(eventName: string, eventDetails: T): Promise<void>; | ||
dispatchEvent<P extends AddTonConnectPrefix<T['type']>>( | ||
eventName: P, | ||
eventDetails: T & { type: RemoveTonConnectPrefix<P> } | ||
): Promise<void>; | ||
|
||
/** | ||
* Adds an event listener. | ||
* @param eventName - The name of the event to listen for. | ||
* @param listener - The listener to add. | ||
* @param options - The options for the listener. | ||
* @returns A function that removes the listener. | ||
*/ | ||
addEventListener<P extends AddTonConnectPrefix<T['type']>>( | ||
eventName: P, | ||
listener: (event: CustomEvent<T & { type: RemoveTonConnectPrefix<P> }>) => void, | ||
options?: AddEventListenerOptions | ||
): Promise<() => void>; | ||
} |
Oops, something went wrong.