protobuf-platform 1.2.657 → 1.2.659

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.
@@ -0,0 +1,180 @@
1
+ 'use strict';
2
+
3
+ // Contract checks only: financial/Redis lifecycle regressions belong to services.
4
+ const assert = require('node:assert/strict');
5
+ const fs = require('node:fs');
6
+ const path = require('node:path');
7
+ const vm = require('node:vm');
8
+ const { execFileSync } = require('node:child_process');
9
+ const root = path.resolve(__dirname, '..');
10
+ const baseline = '960a899e90da887fa0831f321dff22517dfa9dff';
11
+ const readOld = (file) => execFileSync('git', ['show', `${baseline}:${file}`], { cwd: root, encoding: 'utf8', maxBuffer: 16 * 1024 * 1024 });
12
+ const normalize = (text) => text.replace(/\/\/[^\n]*/g, '').replace(/\s+/g, ' ').trim();
13
+ function declarations(source) {
14
+ const out = new Map();
15
+ const pattern = /\b(message|enum)\s+(\w+)\s*\{/g;
16
+ for (const match of source.matchAll(pattern)) {
17
+ let depth = 1;
18
+ let end = match.index + match[0].length;
19
+ const start = end;
20
+ while (depth) {
21
+ const char = source[end++];
22
+ assert.ok(char, 'Unclosed declaration');
23
+ if (char === '{') depth += 1;
24
+ if (char === '}') depth -= 1;
25
+ }
26
+ out.set(match[2], normalize(source.slice(start, end - 1)));
27
+ }
28
+ return out;
29
+ }
30
+ const additions = {
31
+ ExecuteGameplayPrecisionCommandRequest: 'string preparation_generation = 5; string preparation_fingerprint = 6; GameplayPrecisionRgEvidence rg_admission = 7;',
32
+ GameplayPrecisionResult: 'repeated GameplayPrecisionAccountingLeg accounting_legs = 17; string preparation_generation = 18; string preparation_fingerprint = 19; string command_key = 20; string request_fingerprint = 21;',
33
+ };
34
+ let preserved = 0;
35
+ for (const domain of ['user', 'payment']) {
36
+ const file = `${domain}/${domain}.proto`;
37
+ const oldSource = readOld(file);
38
+ const newSource = fs.readFileSync(path.join(root, file), 'utf8');
39
+ const current = declarations(newSource);
40
+ for (const [name, body] of declarations(oldSource)) {
41
+ assert.equal(current.get(name), body + (additions[name] ? ` ${additions[name]}` : ''), name);
42
+ preserved += 1;
43
+ }
44
+ const rpcPattern = /rpc\s+\w+\s*\([^;]+;/g;
45
+ const newRpcs = new Set([...newSource.matchAll(rpcPattern)].map((m) => normalize(m[0])));
46
+ for (const match of oldSource.matchAll(rpcPattern)) assert.ok(newRpcs.has(normalize(match[0])), match[0]);
47
+ }
48
+ console.log(`PASS: ${preserved} existing message/enum declarations and all existing RPCs preserved`);
49
+
50
+ function oldBindings(domain) {
51
+ const sandbox = { exports: {}, require, console };
52
+ vm.runInNewContext(readOld(`${domain}/${domain}_pb.js`), sandbox, { filename: `legacy-${domain}` });
53
+ return sandbox.exports;
54
+ }
55
+ const payment = require('../payment/payment_pb');
56
+ const user = require('../user/user_pb');
57
+ const oldPayment = oldBindings('payment');
58
+ const oldUser = oldBindings('user');
59
+ const roundtrip = (value) => value.constructor.deserializeBinary(value.serializeBinary());
60
+ const large = '900719925474099312345678901234567890';
61
+ const evidence = new payment.GameplayPrecisionRgEvidence();
62
+ evidence.setCommandKey('immutable-command');
63
+ evidence.setRequestFingerprint('immutable-request');
64
+ evidence.setPreparationGeneration(large);
65
+ evidence.setPreparationFingerprint('generation-fingerprint');
66
+ evidence.setAccountingCurrency('BTC');
67
+ evidence.setAccountingScale(8);
68
+ evidence.setRequestedDebitMinor('0');
69
+ evidence.setState('RELEASED');
70
+ evidence.setReceiptId('release-receipt');
71
+ const command = new payment.ExecuteGameplayPrecisionCommandRequest();
72
+ command.setCommandId('same-command');
73
+ command.setCallbackAction('bet');
74
+ command.setPreparationGeneration(large);
75
+ command.setPreparationFingerprint('generation-fingerprint');
76
+ command.setRgAdmission(evidence);
77
+ const legacyCommand = oldPayment.ExecuteGameplayPrecisionCommandRequest.deserializeBinary(command.serializeBinary());
78
+ assert.equal(legacyCommand.getCommandId(), 'same-command');
79
+ assert.equal(legacyCommand.getCallbackAction(), 'bet');
80
+ const oldRequest = new oldPayment.ExecuteGameplayPrecisionCommandRequest();
81
+ oldRequest.setCommandId('legacy-command');
82
+ const newFromOld = payment.ExecuteGameplayPrecisionCommandRequest.deserializeBinary(oldRequest.serializeBinary());
83
+ assert.equal(newFromOld.getPreparationGeneration(), '');
84
+ assert.equal(newFromOld.hasRgAdmission(), false);
85
+ const prepared = new payment.PrepareGameplayPrecisionCommandRequest();
86
+ prepared.setCommand(command);
87
+ prepared.setMode(payment.GameplayPrecisionPrepareMode.GAMEPLAY_PRECISION_REPREPARE);
88
+ prepared.setReprepareRequestId('retry-id');
89
+ prepared.setExpectedGeneration(large);
90
+ prepared.setExpectedPreparationFingerprint('generation-fingerprint');
91
+ prepared.setPreviousRelease(evidence);
92
+ assert.deepEqual(roundtrip(prepared).toObject(), prepared.toObject());
93
+ assert.equal(roundtrip(prepared).getPreviousRelease().getRequestedDebitMinor(), '0');
94
+ assert.equal(roundtrip(prepared).getExpectedGeneration(), large);
95
+ console.log('PASS: reprepare/release evidence, large IDs, zero debit and mixed-version requests');
96
+
97
+ const leg = new payment.GameplayPrecisionAccountingLeg();
98
+ leg.setIntegerDeltaMinor(`-${large}`);
99
+ leg.setFractionalDeltaNumerator('-1');
100
+ leg.setFractionalDeltaDenominator(large);
101
+ leg.setAccountingCurrency('ETH');
102
+ leg.setAccountingScale(18);
103
+ const result = new payment.GameplayPrecisionResult();
104
+ result.setStatus('STALE_PREPARATION');
105
+ result.setPreparationGeneration(large);
106
+ result.setPreparationFingerprint('generation-fingerprint');
107
+ result.setAccountingLegsList([leg]);
108
+ assert.deepEqual(roundtrip(result).toObject(), result.toObject());
109
+ assert.equal(oldPayment.GameplayPrecisionResult.deserializeBinary(result.serializeBinary()).getStatus(), 'STALE_PREPARATION');
110
+ const preparation = new payment.GameplayPrecisionPreparation();
111
+ preparation.setGeneration(large);
112
+ preparation.setRequestedDebitMinor('0');
113
+ preparation.setRequiresRgAdmission(true);
114
+ preparation.setAccountingLegsList([leg]);
115
+ const response = new payment.PrepareGameplayPrecisionCommandResponse();
116
+ response.setStatus('PREPARED');
117
+ response.setPreparation(preparation);
118
+ assert.deepEqual(roundtrip(response).toObject(), response.toObject());
119
+ assert.equal(roundtrip(response).getPreparation().getCashLedgerEntryId(), '');
120
+ response.setStatus('COMMITTED');
121
+ response.setCommittedResult(result);
122
+ assert.deepEqual(roundtrip(response).toObject(), response.toObject());
123
+ console.log('PASS: stale/result envelopes, signed exact legs, scale 18, missing cash watermark');
124
+
125
+ const binding = new user.PrecisionRgBinding();
126
+ binding.setUserId('17');
127
+ binding.setCommandKey('immutable-command');
128
+ binding.setRequestFingerprint('immutable-request');
129
+ binding.setPrecisionSessionId('session');
130
+ binding.setPreparationGeneration(large);
131
+ binding.setPreparationFingerprint('generation-fingerprint');
132
+ binding.setAccountingCurrency('USD');
133
+ binding.setAccountingScale(2);
134
+ binding.setRequestedDebitMinor('0');
135
+ binding.setGameSessionId('game-session');
136
+ binding.setProviderTransactionId('transaction');
137
+ binding.setRoundId('round');
138
+ for (const action of Object.values(user.PrecisionRgAction)) {
139
+ const request = new user.PrecisionRgAdmissionRequest();
140
+ request.setAction(action);
141
+ request.setBinding(binding);
142
+ request.setPreviousReleaseReceiptId('previous-release');
143
+ request.setAdmissionReceiptId('admission');
144
+ assert.deepEqual(roundtrip(request).toObject(), request.toObject());
145
+ }
146
+ for (const state of Object.values(user.PrecisionRgState)) {
147
+ for (const outcome of Object.values(user.PrecisionRgOutcome)) {
148
+ const reply = new user.PrecisionRgAdmissionResponse();
149
+ reply.setState(state);
150
+ reply.setOutcome(outcome);
151
+ reply.setBinding(binding);
152
+ reply.setCurrentGeneration(large);
153
+ reply.setAdmissionReceiptId('admission');
154
+ reply.setReleaseReceiptId('release');
155
+ reply.setCommitReceiptId('commit');
156
+ const decision = new user.EvaluateResponsibleGamingDecisionResponse();
157
+ decision.setAllowed(false);
158
+ decision.setReasonKey('policy-denied');
159
+ reply.setDecision(decision);
160
+ assert.deepEqual(roundtrip(reply).toObject(), reply.toObject());
161
+ }
162
+ }
163
+ assert.equal(new user.PrecisionRgAdmissionRequest().getAction(), 0);
164
+ assert.equal(new user.PrecisionRgAdmissionResponse().getOutcome(), 0);
165
+ assert.equal(new user.PrecisionRgAdmissionResponse().getState(), 0);
166
+ const legacyDecision = new oldUser.EvaluateResponsibleGamingDecisionResponse();
167
+ legacyDecision.setAllowed(true);
168
+ assert.deepEqual(Buffer.from(user.EvaluateResponsibleGamingDecisionResponse.deserializeBinary(legacyDecision.serializeBinary()).serializeBinary()), Buffer.from(legacyDecision.serializeBinary()));
169
+ console.log('PASS: all RG actions/states/outcomes, receipts, zero debit, safe defaults and legacy decision wire');
170
+
171
+ const userService = require('../user/user_grpc_pb').UserService;
172
+ const paymentService = require('../payment/payment_grpc_pb').PaymentService;
173
+ assert.equal(userService.transitionPrecisionRgAdmission.path, '/user.User/transitionPrecisionRgAdmission');
174
+ assert.equal(paymentService.prepareGameplayPrecisionCommand.path, '/payment.Payment/prepareGameplayPrecisionCommand');
175
+ assert.equal(userService.transitionPrecisionRgAdmission.requestType, user.PrecisionRgAdmissionRequest);
176
+ assert.equal(paymentService.prepareGameplayPrecisionCommand.responseType, payment.PrepareGameplayPrecisionCommandResponse);
177
+ const exported = require('../index');
178
+ assert.equal(exported.user.messages.PrecisionRgBinding, user.PrecisionRgBinding);
179
+ assert.equal(exported.payment.messages.GameplayPrecisionPreparation, payment.GameplayPrecisionPreparation);
180
+ console.log('PASS: generated gRPC paths/types and package exports');
package/user/user.proto CHANGED
@@ -205,6 +205,8 @@ service User {
205
205
  rpc reserveResponsibleGamingLossExposure(ReserveResponsibleGamingLossExposureRequest) returns (ReserveResponsibleGamingLossExposureResponse);
206
206
  rpc finalizeResponsibleGamingLossExposure(FinalizeResponsibleGamingLossExposureRequest) returns (FinalizeResponsibleGamingLossExposureResponse);
207
207
  rpc updateResponsibleGamingTimeUsage(UpdateResponsibleGamingTimeUsageRequest) returns (UpdateResponsibleGamingTimeUsageResponse);
208
+ rpc transitionPrecisionRgAdmission(PrecisionRgAdmissionRequest)
209
+ returns (PrecisionRgAdmissionResponse);
208
210
  }
209
211
  //Technical
210
212
  message PingRequest { string ping = 1; }
@@ -2590,4 +2592,58 @@ message UpdateResponsibleGamingTimeUsageResponse {
2590
2592
  bool limit_reached = 8;
2591
2593
  optional string reason_key = 9;
2592
2594
  optional ResponsibleGamingDecisionDetails decision_details = 10;
2593
- }
2595
+ }
2596
+ enum PrecisionRgAction {
2597
+ PRECISION_RG_ACTION_UNSPECIFIED = 0;
2598
+ PRECISION_RG_RESERVE = 1;
2599
+ PRECISION_RG_RELEASE = 2;
2600
+ PRECISION_RG_COMMIT = 3;
2601
+ PRECISION_RG_READ = 4;
2602
+ }
2603
+ enum PrecisionRgState {
2604
+ PRECISION_RG_STATE_UNKNOWN = 0;
2605
+ PRECISION_RG_RESERVED = 1;
2606
+ PRECISION_RG_DENIED = 2;
2607
+ PRECISION_RG_RELEASED = 3;
2608
+ PRECISION_RG_COMMITTED = 4;
2609
+ }
2610
+ enum PrecisionRgOutcome {
2611
+ PRECISION_RG_OUTCOME_UNSPECIFIED = 0;
2612
+ PRECISION_RG_OK = 1;
2613
+ PRECISION_RG_POLICY_DENIED = 2;
2614
+ PRECISION_RG_CONFLICT = 3;
2615
+ PRECISION_RG_STALE_GENERATION = 4;
2616
+ PRECISION_RG_RELEASE_REQUIRED = 5;
2617
+ PRECISION_RG_INVALID_STATE = 6;
2618
+ PRECISION_RG_STATE_UNAVAILABLE = 7;
2619
+ }
2620
+ message PrecisionRgBinding {
2621
+ string user_id = 1;
2622
+ string command_key = 2;
2623
+ string request_fingerprint = 3;
2624
+ string precision_session_id = 4;
2625
+ string preparation_generation = 5;
2626
+ string preparation_fingerprint = 6;
2627
+ string accounting_currency = 7;
2628
+ uint32 accounting_scale = 8;
2629
+ string requested_debit_minor = 9;
2630
+ string game_session_id = 10;
2631
+ string provider_transaction_id = 11;
2632
+ string round_id = 12;
2633
+ }
2634
+ message PrecisionRgAdmissionRequest {
2635
+ PrecisionRgAction action = 1;
2636
+ PrecisionRgBinding binding = 2;
2637
+ string previous_release_receipt_id = 3;
2638
+ string admission_receipt_id = 4;
2639
+ }
2640
+ message PrecisionRgAdmissionResponse {
2641
+ PrecisionRgOutcome outcome = 1;
2642
+ PrecisionRgState state = 2;
2643
+ PrecisionRgBinding binding = 3;
2644
+ string current_generation = 4;
2645
+ string admission_receipt_id = 5;
2646
+ string release_receipt_id = 6;
2647
+ string commit_receipt_id = 7;
2648
+ EvaluateResponsibleGamingDecisionResponse decision = 8;
2649
+ }
@@ -939,6 +939,28 @@ function deserialize_user_PongResponse(buffer_arg) {
939
939
  return user_pb.PongResponse.deserializeBinary(new Uint8Array(buffer_arg));
940
940
  }
941
941
 
942
+ function serialize_user_PrecisionRgAdmissionRequest(arg) {
943
+ if (!(arg instanceof user_pb.PrecisionRgAdmissionRequest)) {
944
+ throw new Error('Expected argument of type user.PrecisionRgAdmissionRequest');
945
+ }
946
+ return Buffer.from(arg.serializeBinary());
947
+ }
948
+
949
+ function deserialize_user_PrecisionRgAdmissionRequest(buffer_arg) {
950
+ return user_pb.PrecisionRgAdmissionRequest.deserializeBinary(new Uint8Array(buffer_arg));
951
+ }
952
+
953
+ function serialize_user_PrecisionRgAdmissionResponse(arg) {
954
+ if (!(arg instanceof user_pb.PrecisionRgAdmissionResponse)) {
955
+ throw new Error('Expected argument of type user.PrecisionRgAdmissionResponse');
956
+ }
957
+ return Buffer.from(arg.serializeBinary());
958
+ }
959
+
960
+ function deserialize_user_PrecisionRgAdmissionResponse(buffer_arg) {
961
+ return user_pb.PrecisionRgAdmissionResponse.deserializeBinary(new Uint8Array(buffer_arg));
962
+ }
963
+
942
964
  function serialize_user_PrepareUserKycVerificationRequest(arg) {
943
965
  if (!(arg instanceof user_pb.PrepareUserKycVerificationRequest)) {
944
966
  throw new Error('Expected argument of type user.PrepareUserKycVerificationRequest');
@@ -4244,6 +4266,17 @@ adminResetResponsibleGamingPolicy: {
4244
4266
  responseSerialize: serialize_user_UpdateResponsibleGamingTimeUsageResponse,
4245
4267
  responseDeserialize: deserialize_user_UpdateResponsibleGamingTimeUsageResponse,
4246
4268
  },
4269
+ transitionPrecisionRgAdmission: {
4270
+ path: '/user.User/transitionPrecisionRgAdmission',
4271
+ requestStream: false,
4272
+ responseStream: false,
4273
+ requestType: user_pb.PrecisionRgAdmissionRequest,
4274
+ responseType: user_pb.PrecisionRgAdmissionResponse,
4275
+ requestSerialize: serialize_user_PrecisionRgAdmissionRequest,
4276
+ requestDeserialize: deserialize_user_PrecisionRgAdmissionRequest,
4277
+ responseSerialize: serialize_user_PrecisionRgAdmissionResponse,
4278
+ responseDeserialize: deserialize_user_PrecisionRgAdmissionResponse,
4279
+ },
4247
4280
  };
4248
4281
 
4249
4282
  exports.UserClient = grpc.makeGenericClientConstructor(UserService, 'User');