@block52/poker-vm-sdk 1.0.7 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +154 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +241 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +255 -0
- package/dist/index.js.map +1 -1
- package/dist/sdkTypes.d.ts +1 -3
- package/dist/sdkTypes.d.ts.map +1 -1
- package/dist/types/game.d.ts +12 -3
- package/dist/types/game.d.ts.map +1 -1
- package/dist/types.d.ts +0 -6
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/actionUtils.d.ts +18 -0
- package/dist/utils/actionUtils.d.ts.map +1 -0
- package/dist/utils/addressUtils.d.ts +22 -0
- package/dist/utils/addressUtils.d.ts.map +1 -0
- package/dist/utils/gameFormatUtils.d.ts +102 -0
- package/dist/utils/gameFormatUtils.d.ts.map +1 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -55820,6 +55820,246 @@ async function getAddressFromMnemonic(mnemonic, prefix = "b52") {
|
|
|
55820
55820
|
return account.address;
|
|
55821
55821
|
}
|
|
55822
55822
|
|
|
55823
|
+
/**
|
|
55824
|
+
* Game Format Utilities
|
|
55825
|
+
*
|
|
55826
|
+
* Helper functions for working with GameFormat and GameVariant enum values.
|
|
55827
|
+
* GameFormat uses kebab-case values: "cash", "sit-and-go", "tournament"
|
|
55828
|
+
* GameVariant uses kebab-case values: "texas-holdem", "omaha"
|
|
55829
|
+
*/
|
|
55830
|
+
/**
|
|
55831
|
+
* Check if a game format is a tournament-style game (SNG or Tournament).
|
|
55832
|
+
* Tournament-style games have fixed buy-ins and elimination mechanics.
|
|
55833
|
+
*
|
|
55834
|
+
* @param format - GameFormat enum value or string
|
|
55835
|
+
* @returns true if the format is SIT_AND_GO or TOURNAMENT
|
|
55836
|
+
*/
|
|
55837
|
+
const isTournamentFormat = (format) => {
|
|
55838
|
+
if (!format)
|
|
55839
|
+
return false;
|
|
55840
|
+
return format === exports.GameFormat.SIT_AND_GO ||
|
|
55841
|
+
format === exports.GameFormat.TOURNAMENT ||
|
|
55842
|
+
format === "sit-and-go" ||
|
|
55843
|
+
format === "tournament";
|
|
55844
|
+
};
|
|
55845
|
+
/**
|
|
55846
|
+
* Check if a game format is a cash game.
|
|
55847
|
+
* Cash games allow flexible buy-ins and players can leave anytime.
|
|
55848
|
+
*
|
|
55849
|
+
* @param format - GameFormat enum value or string
|
|
55850
|
+
* @returns true if the format is CASH
|
|
55851
|
+
*/
|
|
55852
|
+
const isCashFormat = (format) => {
|
|
55853
|
+
if (!format)
|
|
55854
|
+
return false;
|
|
55855
|
+
return format === exports.GameFormat.CASH || format === "cash";
|
|
55856
|
+
};
|
|
55857
|
+
/**
|
|
55858
|
+
* Check if a game format is a Sit & Go.
|
|
55859
|
+
* Sit & Go games start when all seats are filled.
|
|
55860
|
+
*
|
|
55861
|
+
* @param format - GameFormat enum value or string
|
|
55862
|
+
* @returns true if the format is SIT_AND_GO
|
|
55863
|
+
*/
|
|
55864
|
+
const isSitAndGoFormat = (format) => {
|
|
55865
|
+
if (!format)
|
|
55866
|
+
return false;
|
|
55867
|
+
return format === exports.GameFormat.SIT_AND_GO || format === "sit-and-go";
|
|
55868
|
+
};
|
|
55869
|
+
/**
|
|
55870
|
+
* Format a game format value for display.
|
|
55871
|
+
* Capitalizes words and replaces hyphens with spaces.
|
|
55872
|
+
*
|
|
55873
|
+
* @param format - GameFormat enum value or string
|
|
55874
|
+
* @returns Formatted string for display (e.g., "Sit And Go", "Cash", "Tournament")
|
|
55875
|
+
*/
|
|
55876
|
+
const formatGameFormatDisplay = (format) => {
|
|
55877
|
+
if (!format)
|
|
55878
|
+
return "Unknown";
|
|
55879
|
+
// Replace hyphens with spaces and capitalize each word
|
|
55880
|
+
return format
|
|
55881
|
+
.split("-")
|
|
55882
|
+
.map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
|
|
55883
|
+
.join(" ");
|
|
55884
|
+
};
|
|
55885
|
+
/**
|
|
55886
|
+
* Get the string value to send to Cosmos blockchain.
|
|
55887
|
+
* Cosmos accepts kebab-case format values directly.
|
|
55888
|
+
*
|
|
55889
|
+
* @deprecated GameFormat enum values are already in kebab-case.
|
|
55890
|
+
* Use gameOptions.format directly instead of this function.
|
|
55891
|
+
* @param format - GameFormat enum value
|
|
55892
|
+
* @returns The kebab-case string value (e.g., "sit-and-go", "cash", "tournament")
|
|
55893
|
+
*/
|
|
55894
|
+
const getGameFormatForCosmos = (format) => {
|
|
55895
|
+
// GameFormat enum values are already in kebab-case, which Cosmos accepts
|
|
55896
|
+
return format;
|
|
55897
|
+
};
|
|
55898
|
+
/**
|
|
55899
|
+
* Get game format, returning "unknown" if it cannot be determined.
|
|
55900
|
+
* Does NOT default to any value - explicitly returns "unknown" for visibility.
|
|
55901
|
+
*
|
|
55902
|
+
* @param format - GameFormat enum value, string, or undefined
|
|
55903
|
+
* @returns GameFormat enum value, or "unknown" if cannot be determined
|
|
55904
|
+
*/
|
|
55905
|
+
const getGameFormat = (format) => {
|
|
55906
|
+
if (!format)
|
|
55907
|
+
return "unknown";
|
|
55908
|
+
// If it's already a valid GameFormat enum value, return it
|
|
55909
|
+
if (Object.values(exports.GameFormat).includes(format)) {
|
|
55910
|
+
return format;
|
|
55911
|
+
}
|
|
55912
|
+
// Otherwise parse it
|
|
55913
|
+
return parseGameFormat(format);
|
|
55914
|
+
};
|
|
55915
|
+
/**
|
|
55916
|
+
* Extract game format from a game object with various property name conventions.
|
|
55917
|
+
* Handles different API response formats (camelCase, snake_case, etc.)
|
|
55918
|
+
*
|
|
55919
|
+
* @param game - Game object that may have gameFormat or format properties
|
|
55920
|
+
* @returns GameFormat enum value, or "unknown" if not found
|
|
55921
|
+
*/
|
|
55922
|
+
const getGameFormatFromObject = (game) => {
|
|
55923
|
+
if (!game)
|
|
55924
|
+
return "unknown";
|
|
55925
|
+
const format = game.gameFormat || game.format;
|
|
55926
|
+
return getGameFormat(format);
|
|
55927
|
+
};
|
|
55928
|
+
/**
|
|
55929
|
+
* Parse a string value to GameFormat enum.
|
|
55930
|
+
* Handles various input formats (kebab-case, snake_case, etc.)
|
|
55931
|
+
*
|
|
55932
|
+
* @param value - String value to parse
|
|
55933
|
+
* @returns GameFormat enum value, or "unknown" if invalid
|
|
55934
|
+
*/
|
|
55935
|
+
const parseGameFormat = (value) => {
|
|
55936
|
+
if (!value)
|
|
55937
|
+
return "unknown";
|
|
55938
|
+
const normalized = value.toLowerCase().replace(/_/g, "-");
|
|
55939
|
+
switch (normalized) {
|
|
55940
|
+
case "sit-and-go":
|
|
55941
|
+
case "sitandgo":
|
|
55942
|
+
case "sng":
|
|
55943
|
+
return exports.GameFormat.SIT_AND_GO;
|
|
55944
|
+
case "tournament":
|
|
55945
|
+
case "tourney":
|
|
55946
|
+
return exports.GameFormat.TOURNAMENT;
|
|
55947
|
+
case "cash":
|
|
55948
|
+
case "ring":
|
|
55949
|
+
return exports.GameFormat.CASH;
|
|
55950
|
+
default:
|
|
55951
|
+
return "unknown";
|
|
55952
|
+
}
|
|
55953
|
+
};
|
|
55954
|
+
/**
|
|
55955
|
+
* Format a game variant value for display.
|
|
55956
|
+
* Capitalizes words and replaces hyphens with spaces.
|
|
55957
|
+
*
|
|
55958
|
+
* @param variant - GameVariant enum value or string
|
|
55959
|
+
* @returns Formatted string for display (e.g., "Texas Holdem", "Omaha", "Unknown")
|
|
55960
|
+
*/
|
|
55961
|
+
const formatGameVariantDisplay = (variant) => {
|
|
55962
|
+
if (!variant)
|
|
55963
|
+
return "Unknown";
|
|
55964
|
+
// Replace hyphens with spaces and capitalize each word
|
|
55965
|
+
return variant
|
|
55966
|
+
.split("-")
|
|
55967
|
+
.map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
|
|
55968
|
+
.join(" ");
|
|
55969
|
+
};
|
|
55970
|
+
/**
|
|
55971
|
+
* Get game variant, returning "unknown" if it cannot be determined.
|
|
55972
|
+
* Does NOT default to any value - explicitly returns "unknown" for visibility.
|
|
55973
|
+
*
|
|
55974
|
+
* @param variant - GameVariant enum value, string, or undefined
|
|
55975
|
+
* @returns GameVariant enum value, or "unknown" if cannot be determined
|
|
55976
|
+
*/
|
|
55977
|
+
const getGameVariant = (variant) => {
|
|
55978
|
+
if (!variant)
|
|
55979
|
+
return "unknown";
|
|
55980
|
+
// If it's already a valid GameVariant enum value, return it
|
|
55981
|
+
if (Object.values(exports.GameVariant).includes(variant)) {
|
|
55982
|
+
return variant;
|
|
55983
|
+
}
|
|
55984
|
+
// Otherwise parse it
|
|
55985
|
+
return parseGameVariant(variant);
|
|
55986
|
+
};
|
|
55987
|
+
/**
|
|
55988
|
+
* Parse a string value to GameVariant enum.
|
|
55989
|
+
* Handles various input formats (kebab-case, snake_case, etc.)
|
|
55990
|
+
*
|
|
55991
|
+
* @param value - String value to parse
|
|
55992
|
+
* @returns GameVariant enum value, or "unknown" if invalid
|
|
55993
|
+
*/
|
|
55994
|
+
const parseGameVariant = (value) => {
|
|
55995
|
+
if (!value)
|
|
55996
|
+
return "unknown";
|
|
55997
|
+
const normalized = value.toLowerCase().replace(/_/g, "-");
|
|
55998
|
+
switch (normalized) {
|
|
55999
|
+
case "texas-holdem":
|
|
56000
|
+
case "texasholdem":
|
|
56001
|
+
case "holdem":
|
|
56002
|
+
case "nlh":
|
|
56003
|
+
return exports.GameVariant.TEXAS_HOLDEM;
|
|
56004
|
+
case "omaha":
|
|
56005
|
+
case "plo":
|
|
56006
|
+
return exports.GameVariant.OMAHA;
|
|
56007
|
+
default:
|
|
56008
|
+
return "unknown";
|
|
56009
|
+
}
|
|
56010
|
+
};
|
|
56011
|
+
|
|
56012
|
+
/**
|
|
56013
|
+
* Check if a specific action is available in the legal actions list.
|
|
56014
|
+
*
|
|
56015
|
+
* @param legalActions - Array of legal actions available to the player
|
|
56016
|
+
* @param action - The action type to check for
|
|
56017
|
+
* @returns true if the action is available
|
|
56018
|
+
*/
|
|
56019
|
+
const hasAction = (legalActions, action) => {
|
|
56020
|
+
return legalActions.some(legalAction => legalAction.action === action);
|
|
56021
|
+
};
|
|
56022
|
+
/**
|
|
56023
|
+
* Find a specific action by type from the legal actions list.
|
|
56024
|
+
*
|
|
56025
|
+
* @param legalActions - Array of legal actions available to the player
|
|
56026
|
+
* @param actionType - The action type to find
|
|
56027
|
+
* @returns The matching LegalActionDTO or undefined if not found
|
|
56028
|
+
*/
|
|
56029
|
+
const getActionByType = (legalActions, actionType) => {
|
|
56030
|
+
return legalActions.find(action => action.action === actionType || action.action?.toString() === actionType?.toString());
|
|
56031
|
+
};
|
|
56032
|
+
|
|
56033
|
+
/**
|
|
56034
|
+
* Address Utilities
|
|
56035
|
+
*
|
|
56036
|
+
* Helper functions for validating and checking Cosmos blockchain addresses.
|
|
56037
|
+
*/
|
|
56038
|
+
/**
|
|
56039
|
+
* Check if an address represents an empty/vacant player slot.
|
|
56040
|
+
* For Cosmos addresses (b52...), we only check for null/undefined/empty.
|
|
56041
|
+
*
|
|
56042
|
+
* @param address - The player address to check
|
|
56043
|
+
* @returns true if the address is empty/vacant, false if it's a real player
|
|
56044
|
+
*/
|
|
56045
|
+
const isEmptyAddress = (address) => {
|
|
56046
|
+
if (!address)
|
|
56047
|
+
return true;
|
|
56048
|
+
if (address === "")
|
|
56049
|
+
return true;
|
|
56050
|
+
return false;
|
|
56051
|
+
};
|
|
56052
|
+
/**
|
|
56053
|
+
* Check if an address represents a valid (non-empty) player.
|
|
56054
|
+
* Opposite of isEmptyAddress.
|
|
56055
|
+
*
|
|
56056
|
+
* @param address - The player address to check
|
|
56057
|
+
* @returns true if the address is a valid player address, false if empty
|
|
56058
|
+
*/
|
|
56059
|
+
const isValidPlayerAddress = (address) => {
|
|
56060
|
+
return !isEmptyAddress(address);
|
|
56061
|
+
};
|
|
56062
|
+
|
|
55823
56063
|
/**
|
|
55824
56064
|
* Poker hand types in order of strength (weakest to strongest)
|
|
55825
56065
|
*/
|
|
@@ -57837,9 +58077,24 @@ exports.SigningCosmosClient = SigningCosmosClient;
|
|
|
57837
58077
|
exports.WithdrawalRequest = WithdrawalRequest;
|
|
57838
58078
|
exports.createSigningClientFromMnemonic = createSigningClientFromMnemonic;
|
|
57839
58079
|
exports.createWalletFromMnemonic = createWalletFromMnemonic;
|
|
58080
|
+
exports.formatGameFormatDisplay = formatGameFormatDisplay;
|
|
58081
|
+
exports.formatGameVariantDisplay = formatGameVariantDisplay;
|
|
57840
58082
|
exports.generateWallet = generateWallet;
|
|
58083
|
+
exports.getActionByType = getActionByType;
|
|
57841
58084
|
exports.getAddressFromMnemonic = getAddressFromMnemonic;
|
|
57842
58085
|
exports.getDefaultCosmosConfig = getDefaultCosmosConfig;
|
|
58086
|
+
exports.getGameFormat = getGameFormat;
|
|
58087
|
+
exports.getGameFormatForCosmos = getGameFormatForCosmos;
|
|
58088
|
+
exports.getGameFormatFromObject = getGameFormatFromObject;
|
|
58089
|
+
exports.getGameVariant = getGameVariant;
|
|
58090
|
+
exports.hasAction = hasAction;
|
|
58091
|
+
exports.isCashFormat = isCashFormat;
|
|
58092
|
+
exports.isEmptyAddress = isEmptyAddress;
|
|
58093
|
+
exports.isSitAndGoFormat = isSitAndGoFormat;
|
|
58094
|
+
exports.isTournamentFormat = isTournamentFormat;
|
|
57843
58095
|
exports.isValidMnemonic = isValidMnemonic;
|
|
58096
|
+
exports.isValidPlayerAddress = isValidPlayerAddress;
|
|
58097
|
+
exports.parseGameFormat = parseGameFormat;
|
|
58098
|
+
exports.parseGameVariant = parseGameVariant;
|
|
57844
58099
|
exports.registry = registry;
|
|
57845
58100
|
//# sourceMappingURL=index.js.map
|