@canton-network/core-wallet-store-sql 2.3.0 → 2.4.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 (56) hide show
  1. package/dist/bootstrap.d.ts +7 -2
  2. package/dist/bootstrap.d.ts.map +1 -1
  3. package/dist/cli.d.ts +5 -1
  4. package/dist/cli.d.ts.map +1 -1
  5. package/dist/index.js +45 -21
  6. package/dist/index.js.map +1 -1
  7. package/dist/migrations/001-init.js +16 -67
  8. package/dist/migrations/001-init.js.map +1 -0
  9. package/dist/migrations/002-add-transaction-timestamps.js +11 -18
  10. package/dist/migrations/002-add-transaction-timestamps.js.map +1 -0
  11. package/dist/migrations/003-add-transaction-origin.js +9 -10
  12. package/dist/migrations/003-add-transaction-origin.js.map +1 -0
  13. package/dist/migrations/004-add-session-id.js +9 -7
  14. package/dist/migrations/004-add-session-id.js.map +1 -0
  15. package/dist/migrations/005-add-wallet-disabled-reason.js +10 -11
  16. package/dist/migrations/005-add-wallet-disabled-reason.js.map +1 -0
  17. package/dist/migrations/006-change-wallet-primary-key-to-composite.js +51 -116
  18. package/dist/migrations/006-change-wallet-primary-key-to-composite.js.map +1 -0
  19. package/dist/migrations/007-add-unique-primary-per-network.js +14 -26
  20. package/dist/migrations/007-add-unique-primary-per-network.js.map +1 -0
  21. package/dist/migrations/008-add-transaction-external-tx-id.js +10 -14
  22. package/dist/migrations/008-add-transaction-external-tx-id.js.map +1 -0
  23. package/dist/migrations/009-add-wallet-rights-columns.js +29 -36
  24. package/dist/migrations/009-add-wallet-rights-columns.js.map +1 -0
  25. package/dist/migrations/010-add-transaction-network-id.js +33 -71
  26. package/dist/migrations/010-add-transaction-network-id.js.map +1 -0
  27. package/dist/migrations/011-add-transaction-id-primary-key.js +41 -79
  28. package/dist/migrations/011-add-transaction-id-primary-key.js.map +1 -0
  29. package/dist/migrations/012-add-messages-to-sign.js +10 -25
  30. package/dist/migrations/012-add-messages-to-sign.js.map +1 -0
  31. package/dist/migrations/013-add-api-key.js +8 -16
  32. package/dist/migrations/013-add-api-key.js.map +1 -0
  33. package/dist/migrations/014-add-service-account-column.js +9 -13
  34. package/dist/migrations/014-add-service-account-column.js.map +1 -0
  35. package/dist/migrations/015-add-origin-field-session.js +22 -33
  36. package/dist/migrations/015-add-origin-field-session.js.map +1 -0
  37. package/dist/migrations/016-add-failure-reason-and-awaiting-signature.js +13 -17
  38. package/dist/migrations/016-add-failure-reason-and-awaiting-signature.js.map +1 -0
  39. package/dist/migrations/017-make-idp-issuer-nullable.js +38 -80
  40. package/dist/migrations/017-make-idp-issuer-nullable.js.map +1 -0
  41. package/dist/migrations/018-add-wallet-is-auth-party.js +8 -9
  42. package/dist/migrations/018-add-wallet-is-auth-party.js.map +1 -0
  43. package/dist/migrations/019-make-session-access-token-nullable.js +39 -64
  44. package/dist/migrations/019-make-session-access-token-nullable.js.map +1 -0
  45. package/dist/migrations/020-add-message-external-tx-id-and-failure-reason.js +10 -20
  46. package/dist/migrations/020-add-message-external-tx-id-and-failure-reason.js.map +1 -0
  47. package/dist/migrations/021-add-message-kind.js +8 -9
  48. package/dist/migrations/021-add-message-kind.js.map +1 -0
  49. package/dist/schema.d.ts +3 -3
  50. package/dist/schema.d.ts.map +1 -1
  51. package/dist/store-sql.d.ts.map +1 -1
  52. package/dist/utils-BAU4kQB4.js +13 -0
  53. package/dist/utils-BAU4kQB4.js.map +1 -0
  54. package/package.json +8 -8
  55. package/dist/schema.js +0 -299
  56. package/dist/utils.js +0 -13
package/dist/schema.js DELETED
@@ -1,299 +0,0 @@
1
- // Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
2
- // SPDX-License-Identifier: Apache-2.0
3
- import { authSchema, } from '@canton-network/core-wallet-auth';
4
- import { PartyLevelRight, UserLevelRight, } from '@canton-network/core-wallet-store';
5
- export const toIdp = (table) => {
6
- switch (table.type) {
7
- case 'oauth': {
8
- if (!table.configUrl) {
9
- throw new Error(`Missing configUrl for oauth IdP: ${table.id}`);
10
- }
11
- if (table.issuer === null) {
12
- throw new Error(`Missing issuer for oauth IdP: ${table.id}`);
13
- }
14
- return {
15
- id: table.id,
16
- type: table.type,
17
- issuer: table.issuer,
18
- configUrl: table.configUrl,
19
- };
20
- }
21
- case 'self_signed':
22
- if (table.issuer === null) {
23
- throw new Error(`Missing issuer for self_signed IdP: ${table.id}`);
24
- }
25
- return {
26
- id: table.id,
27
- type: table.type,
28
- issuer: table.issuer,
29
- };
30
- case 'self_issued':
31
- return {
32
- id: table.id,
33
- type: table.type,
34
- };
35
- }
36
- };
37
- export const fromIdp = (idp) => {
38
- switch (idp.type) {
39
- case 'oauth':
40
- return {
41
- id: idp.id,
42
- type: idp.type,
43
- issuer: idp.issuer,
44
- configUrl: idp.configUrl,
45
- };
46
- case 'self_signed':
47
- return {
48
- id: idp.id,
49
- type: idp.type,
50
- issuer: idp.issuer,
51
- configUrl: null,
52
- };
53
- case 'self_issued':
54
- return {
55
- id: idp.id,
56
- type: idp.type,
57
- issuer: null,
58
- configUrl: null,
59
- };
60
- }
61
- };
62
- export const toNetwork = (table) => {
63
- return {
64
- name: table.name,
65
- id: table.id,
66
- synchronizerId: table.synchronizerId ?? undefined,
67
- identityProviderId: table.identityProviderId,
68
- description: table.description,
69
- ledgerApi: {
70
- baseUrl: table.ledgerApiBaseUrl,
71
- },
72
- auth: authSchema.parse(typeof table.auth === 'string' ? JSON.parse(table.auth) : table.auth),
73
- adminAuth: table.adminAuth
74
- ? authSchema.parse(typeof table.adminAuth === 'string'
75
- ? JSON.parse(table.adminAuth)
76
- : table.adminAuth)
77
- : undefined,
78
- serviceAccountAuth: table.serviceAccountAuth
79
- ? authSchema.parse(typeof table.serviceAccountAuth === 'string'
80
- ? JSON.parse(table.serviceAccountAuth)
81
- : table.serviceAccountAuth)
82
- : undefined,
83
- };
84
- };
85
- export const fromNetwork = (network, userId) => {
86
- return {
87
- name: network.name,
88
- id: network.id,
89
- synchronizerId: network.synchronizerId ?? null,
90
- description: network.description,
91
- ledgerApiBaseUrl: network.ledgerApi.baseUrl,
92
- userId: userId,
93
- identityProviderId: network.identityProviderId,
94
- auth: JSON.stringify(network.auth),
95
- adminAuth: network.adminAuth
96
- ? JSON.stringify(network.adminAuth)
97
- : undefined,
98
- serviceAccountAuth: network.serviceAccountAuth
99
- ? JSON.stringify(network.serviceAccountAuth)
100
- : undefined,
101
- };
102
- };
103
- export const toSession = (table) => {
104
- return {
105
- id: table.id,
106
- network: table.network,
107
- origin: table.origin,
108
- ...(table.accessToken ? { accessToken: table.accessToken } : {}),
109
- userId: table.userId,
110
- };
111
- };
112
- export const fromWallet = (wallet, userId) => {
113
- const { externalTxId, topologyTransactions, rights, isAuthParty, ...rest } = wallet;
114
- void rights;
115
- return {
116
- ...rest,
117
- primary: wallet.primary ? 1 : 0,
118
- userId: userId,
119
- disabled: wallet.disabled !== undefined && wallet.disabled ? 1 : 0,
120
- isAuthParty: isAuthParty ? 1 : 0,
121
- reason: wallet.reason ?? null,
122
- externalTxId: externalTxId && externalTxId !== '' ? externalTxId : null,
123
- topologyTransactions: topologyTransactions && topologyTransactions !== ''
124
- ? topologyTransactions
125
- : null,
126
- };
127
- };
128
- // only update fields that are explicitly provided to prevent data loss
129
- export const toWalletUpdateProperties = (params) => {
130
- const { status, externalTxId, topologyTransactions, disabled, reason, primary, signingProviderId, publicKey, namespace, isAuthParty, } = params;
131
- return {
132
- ...(status !== undefined && { status }),
133
- ...(externalTxId !== undefined && { externalTxId }),
134
- ...(topologyTransactions !== undefined && { topologyTransactions }),
135
- ...(primary !== undefined && { primary: primary ? 1 : 0 }),
136
- ...(disabled !== undefined && { disabled: disabled ? 1 : 0 }),
137
- ...(reason !== undefined && { reason }),
138
- ...(signingProviderId !== undefined && { signingProviderId }),
139
- ...(publicKey !== undefined && { publicKey }),
140
- ...(namespace !== undefined && { namespace }),
141
- ...(isAuthParty !== undefined && { isAuthParty: isAuthParty ? 1 : 0 }),
142
- };
143
- };
144
- export const toWalletStatus = (status) => {
145
- if (status === 'allocated')
146
- return 'allocated';
147
- if (status === 'removed')
148
- return 'removed';
149
- return 'initialized';
150
- };
151
- export const toWallet = (table) => {
152
- return {
153
- primary: Boolean(table.primary),
154
- status: toWalletStatus(table.status),
155
- partyId: table.partyId,
156
- hint: table.hint,
157
- publicKey: table.publicKey,
158
- namespace: table.namespace,
159
- networkId: table.networkId,
160
- signingProviderId: table.signingProviderId,
161
- disabled: table.disabled === 1,
162
- isAuthParty: Boolean(table.isAuthParty),
163
- userId: table.userId,
164
- ...(table.externalTxId !== null && {
165
- externalTxId: table.externalTxId,
166
- }),
167
- ...(table.topologyTransactions !== null && {
168
- topologyTransactions: table.topologyTransactions,
169
- }),
170
- ...(table.reason !== null && {
171
- reason: table.reason,
172
- }),
173
- rights: [],
174
- };
175
- };
176
- export const fromPartyRight = (right) => {
177
- if (Object.values(PartyLevelRight).includes(right)) {
178
- return right;
179
- }
180
- return undefined;
181
- };
182
- export const fromUserRight = (right) => {
183
- if (Object.values(UserLevelRight).includes(right)) {
184
- return right;
185
- }
186
- return undefined;
187
- };
188
- export const fromTransaction = (transaction, userId, networkId) => {
189
- return {
190
- ...transaction,
191
- networkId,
192
- payload: transaction.payload
193
- ? JSON.stringify(transaction.payload)
194
- : undefined,
195
- origin: transaction.origin || null,
196
- userId: userId,
197
- createdAt: transaction.createdAt?.toISOString() || null,
198
- signedAt: transaction.signedAt?.toISOString() || null,
199
- externalTxId: transaction.externalTxId ?? null,
200
- failureReason: transaction.failureReason || null,
201
- };
202
- };
203
- export const toTransaction = (table) => {
204
- const result = {
205
- id: table.id,
206
- commandId: table.commandId,
207
- status: table.status,
208
- preparedTransaction: table.preparedTransaction,
209
- preparedTransactionHash: table.preparedTransactionHash,
210
- payload: table.payload ? JSON.parse(table.payload) : undefined,
211
- origin: table.origin || null,
212
- userId: table.userId,
213
- networkId: table.networkId,
214
- };
215
- if (table.createdAt) {
216
- result.createdAt = new Date(table.createdAt);
217
- }
218
- if (table.signedAt) {
219
- result.signedAt = new Date(table.signedAt);
220
- }
221
- if (table.externalTxId) {
222
- result.externalTxId = table.externalTxId;
223
- }
224
- if (table.failureReason) {
225
- result.failureReason = table.failureReason;
226
- }
227
- return result;
228
- };
229
- export const fromMessageRaw = (message, userId, networkId) => {
230
- if (message.userId !== userId) {
231
- throw new Error(`MessageRaw userId mismatch: expected ${userId}, got ${message.userId}`);
232
- }
233
- return {
234
- id: message.id,
235
- kind: message.kind,
236
- status: message.status,
237
- userId: message.userId,
238
- partyId: message.partyId,
239
- publicKey: message.publicKey,
240
- message: message.message,
241
- origin: message.origin || null,
242
- networkId,
243
- createdAt: message.createdAt.toISOString(),
244
- signedAt: message.signedAt?.toISOString() || null,
245
- signature: message.signature ?? null,
246
- externalTxId: message.externalTxId ?? null,
247
- failureReason: message.failureReason ?? null,
248
- };
249
- };
250
- export const toMessageRaw = (table) => {
251
- const result = {
252
- id: table.id,
253
- kind: table.kind,
254
- status: table.status,
255
- userId: table.userId,
256
- partyId: table.partyId,
257
- publicKey: table.publicKey,
258
- message: table.message,
259
- origin: table.origin || null,
260
- createdAt: new Date(table.createdAt),
261
- };
262
- if (table.signedAt) {
263
- result.signedAt = new Date(table.signedAt);
264
- }
265
- if (table.signature) {
266
- result.signature = table.signature;
267
- }
268
- if (table.externalTxId) {
269
- result.externalTxId = table.externalTxId;
270
- }
271
- if (table.failureReason) {
272
- result.failureReason = table.failureReason;
273
- }
274
- return result;
275
- };
276
- export const fromApiKey = (table) => {
277
- return {
278
- id: table.id,
279
- digest: table.digest,
280
- name: table.name,
281
- userId: table.userId,
282
- email: table.email,
283
- networkId: table.networkId,
284
- createdAt: new Date(table.createdAt),
285
- lastUsedAt: table.lastUsedAt ? new Date(table.lastUsedAt) : undefined,
286
- };
287
- };
288
- export const toApiKey = (apiKey) => {
289
- return {
290
- id: apiKey.id,
291
- digest: apiKey.digest,
292
- name: apiKey.name,
293
- userId: apiKey.userId,
294
- email: apiKey.email,
295
- networkId: apiKey.networkId,
296
- createdAt: apiKey.createdAt.toISOString(),
297
- lastUsedAt: apiKey.lastUsedAt ? apiKey.lastUsedAt.toISOString() : null,
298
- };
299
- };
package/dist/utils.js DELETED
@@ -1,13 +0,0 @@
1
- // Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
2
- // SPDX-License-Identifier: Apache-2.0
3
- import { sql } from 'kysely';
4
- export async function isPostgres(db) {
5
- try {
6
- // Try to query PostgreSQL system catalog
7
- await sql `SELECT 1 FROM pg_database LIMIT 1`.execute(db);
8
- return true;
9
- }
10
- catch {
11
- return false;
12
- }
13
- }