@betorigami/game-ui-shared 3.0.0 → 4.1.0

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.
Files changed (31) hide show
  1. package/README.md +21 -0
  2. package/dist/components/shared/ChipTableGameComponent.d.ts +2 -0
  3. package/dist/components/shared/GameComponent.d.ts +9 -0
  4. package/dist/components/shared/GameProviderWrapper.d.ts +2 -0
  5. package/dist/components/shared/GenericAutobet/GenericAutobet.d.ts +1 -0
  6. package/dist/components/shared/context/slices/services.context.d.ts +2 -0
  7. package/dist/controllers/history.controller.d.ts +3 -3
  8. package/dist/index.d.ts +1 -0
  9. package/dist/index.mjs +6655 -4135
  10. package/dist/shared/bet.types.d.ts +24 -43
  11. package/dist/shared/create-api-factory.d.ts +3 -6
  12. package/dist/shared/provider-api/error-codes.d.ts +1 -0
  13. package/dist/shared/provider-api/generated/client/client.gen.d.ts +2 -0
  14. package/dist/shared/provider-api/generated/client/index.d.ts +10 -0
  15. package/dist/shared/provider-api/generated/client/types.gen.d.ts +120 -0
  16. package/dist/shared/provider-api/generated/client/utils.gen.d.ts +37 -0
  17. package/dist/shared/provider-api/generated/client.gen.d.ts +12 -0
  18. package/dist/shared/provider-api/generated/core/auth.gen.d.ts +25 -0
  19. package/dist/shared/provider-api/generated/core/bodySerializer.gen.d.ts +25 -0
  20. package/dist/shared/provider-api/generated/core/params.gen.d.ts +43 -0
  21. package/dist/shared/provider-api/generated/core/pathSerializer.gen.d.ts +33 -0
  22. package/dist/shared/provider-api/generated/core/queryKeySerializer.gen.d.ts +18 -0
  23. package/dist/shared/provider-api/generated/core/serverSentEvents.gen.d.ts +71 -0
  24. package/dist/shared/provider-api/generated/core/types.gen.d.ts +83 -0
  25. package/dist/shared/provider-api/generated/core/utils.gen.d.ts +19 -0
  26. package/dist/shared/provider-api/generated/index.d.ts +2 -0
  27. package/dist/shared/provider-api/generated/sdk.gen.d.ts +42 -0
  28. package/dist/shared/provider-api/generated/types.gen.d.ts +1143 -0
  29. package/dist/shared/provider-api/generated/zod.gen.d.ts +1271 -0
  30. package/dist/shared/provider-api/provider-api-client.d.ts +8 -0
  31. package/package.json +6 -3
package/README.md CHANGED
@@ -34,6 +34,27 @@ declare module '@betorigami/game-ui-shared' {
34
34
 
35
35
  The package does not read environment variables. A host that wants a different provably-fair verifier calls `setVerifierBaseUrl` with that URL at startup; a host that does not leaves the built-in default in place.
36
36
 
37
+ ## Provider API client
38
+
39
+ `ProviderApi` is a client for provider-api, generated with [hey-api](https://heyapi.dev) from provider-api's OpenAPI spec. Every response is checked against the spec with zod/mini before the caller sees it.
40
+
41
+ ```ts
42
+ import { ProviderApi } from '@betorigami/game-ui-shared';
43
+
44
+ const client = ProviderApi.createProviderApiClient({ baseUrl, authToken });
45
+ const { data, error } = await ProviderApi.postGamesDicePlay({ client, body });
46
+ ```
47
+
48
+ `createProviderApiClient` adds the auth token, a fresh `X-Origami-Trace` id and a `REQUEST_TIMEOUT_MS` timeout to every request. `data` is set when the request succeeds and the response matches the spec. Otherwise `error` holds the error body, which `resolveApiErrorCode` turns into an `ErrorCode`. A response that doesn't match the spec throws. Inside this package, import from `src/shared/provider-api/provider-api-client` instead.
49
+
50
+ To regenerate it after provider-api's endpoints change:
51
+
52
+ 1. Start provider-api locally from the backend repo with `ENABLE_OPENAPI_DOCS=true`, the default in its `.env.template`. It serves the spec at `http://localhost:3000/openapi.json`.
53
+ 2. Run `pnpm run generate:provider-api` in this package.
54
+ 3. Commit the changes under `src/shared/provider-api/generated/`.
55
+
56
+ The settings, including the excluded `/internal/*` routes, are in `openapi-ts.config.ts`. Don't edit the generated files by hand.
57
+
37
58
  ## Pinning
38
59
 
39
60
  `@betorigami/game-calculations` supplies the enums of the games that have not yet been extracted. A host must pin the same version of it as this package, or two copies of the engine end up in one bundle and enum identity breaks.
@@ -1,3 +1,4 @@
1
+ import { default as Big } from 'big.js';
1
2
  import { RequiredContext } from './context/required-context';
2
3
  import { HotkeyDefinition } from '../../controllers/hotkey.controller';
3
4
  import { ChipEvent } from '../../shared/chip-state.utils';
@@ -29,6 +30,7 @@ export declare abstract class ChipTableGameComponent extends GameComponent {
29
30
  protected get maxPerClickAmount(): string;
30
31
  protected get isDoubleDisabled(): boolean;
31
32
  watchDerivedChips(_prev?: unknown, _next?: unknown): void;
33
+ protected getAutobetStake(): Big;
32
34
  protected onBetAmountChange: (oldBetAmount: string, newBetAmount: string) => void;
33
35
  protected adjustPerClickAmount(action: 'half' | 'double' | 'reset'): void;
34
36
  protected handlePerClickAmountChange: (e: CustomEvent<{
@@ -20,6 +20,7 @@ export interface GameBetResult {
20
20
  hasError: boolean;
21
21
  errorCode?: ErrorCode;
22
22
  errorMessage?: string;
23
+ afterBalance: Big | null;
23
24
  }
24
25
  export declare abstract class GameComponent extends OrigamiElement {
25
26
  protected readonly locale: RequiredContext<{
@@ -86,6 +87,14 @@ export declare abstract class GameComponent extends OrigamiElement {
86
87
  disconnectedCallback(): void;
87
88
  toggleAutobet(event: AutobetToggleEvent): Promise<void>;
88
89
  protected abstract executeAutobet(autobetSettings: AutobetSettingsWithId, currentBetAmount: string): Promise<GameBetResult>;
90
+ protected getAutobetStake(currentBetAmount: string): Big;
91
+ /**
92
+ * Stops autobet before a round the provider would reject for insufficient balance, sparing it a lock
93
+ * and a write it would only undo. The balance comes from the last response rather than the wallet,
94
+ * since a game can show a balance that trails the provider's while results are still animating. An
95
+ * unknown balance, or a demo session where no provider is involved, lets the round through.
96
+ */
97
+ private canAffordAutobet;
89
98
  protected adjustBetAmount(autobetSettings: AutobetSettingsWithId, gameOutcome: 'Win' | 'Loss' | 'Draw', originalBetAmount: string, currentBetAmount: string): string;
90
99
  protected isPnLWithinLimits(autobetSettings: AutobetSettingsWithId, totalPnL: Big): boolean;
91
100
  protected updateHistoryWithBet(betResult: NewBetItem): void;
@@ -76,6 +76,7 @@ export declare class GameProviderWrapper extends OrigamiElement {
76
76
  private scale;
77
77
  language: Language;
78
78
  private _soundEffects;
79
+ private _providerApi;
79
80
  private _historyController;
80
81
  private _haptics;
81
82
  private _resizeObserver;
@@ -90,6 +91,7 @@ export declare class GameProviderWrapper extends OrigamiElement {
90
91
  firstUpdated(_changed: PropertyValues): Promise<void>;
91
92
  disconnectedCallback(): void;
92
93
  updated(changedProperties: PropertyValues): void;
94
+ private get providerApi();
93
95
  private get isDemoMode();
94
96
  private get isDesktop();
95
97
  private createLocale;
@@ -35,6 +35,7 @@ export declare class GenericAutobet extends OrigamiElement {
35
35
  willUpdate(changedProperties: Map<string | symbol, unknown>): void;
36
36
  triggerPrimaryAction(): void;
37
37
  isPrimaryActionDisabled(): boolean;
38
+ private get isBetButtonDisabled();
38
39
  private _handleWinPercentageChange;
39
40
  private _handleLossPercentageChange;
40
41
  private _handleStopOnProfitChange;
@@ -1,10 +1,12 @@
1
1
  import { HapticsController } from '../../../../controllers/haptics.controller';
2
2
  import { HistoryController } from '../../../../controllers/history.controller';
3
3
  import { SoundEffectsController } from '../../../../controllers/sound/sound-effects.controller';
4
+ import { Client } from '../../../../shared/provider-api/generated/client';
4
5
  export type ServicesContextType = {
5
6
  soundEffects: SoundEffectsController;
6
7
  haptics: HapticsController;
7
8
  historyController: HistoryController;
9
+ providerApi: Client;
8
10
  };
9
11
  export declare const servicesContext: {
10
12
  __context__: ServicesContextType;
@@ -1,5 +1,5 @@
1
1
  import { Currency } from '../shared/constants';
2
- import { ApiSession } from '../shared/create-api-factory';
2
+ import { Client } from '../shared/provider-api/provider-api-client';
3
3
  export interface HistoryItem {
4
4
  id: string;
5
5
  fullId: string;
@@ -21,7 +21,7 @@ export declare class NonceChangedEvent extends Event {
21
21
  constructor(nonce: number | null);
22
22
  }
23
23
  export declare class HistoryController extends EventTarget {
24
- private readonly getSession;
24
+ private readonly getClient;
25
25
  private _historyData;
26
26
  private _hasData;
27
27
  private _isInitialized;
@@ -33,7 +33,7 @@ export declare class HistoryController extends EventTarget {
33
33
  private _activeBetNonce;
34
34
  private _hasLoadedClientSeed;
35
35
  private _provablyFairInfoAbortController;
36
- constructor(getSession: () => ApiSession | null);
36
+ constructor(getClient: () => Client | null);
37
37
  get historyData(): HistoryItem[];
38
38
  get hasData(): boolean | null;
39
39
  get isInitialized(): boolean;
package/dist/index.d.ts CHANGED
@@ -175,6 +175,7 @@ export * from './shared/provably-fair-verifier';
175
175
  export * from './shared/provider-api/bet-result';
176
176
  export * from './shared/provider-api/error-codes';
177
177
  export * from './shared/provider-api/request-timeout';
178
+ export * as ProviderApi from './shared/provider-api/provider-api-client';
178
179
  export * from './shared/retry-once';
179
180
  export * from './shared/sleep';
180
181
  export * from './shared/utils/format-autobet-settings';