@canton-network/core-wallet-store-sql 2.2.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.
- package/dist/bootstrap.d.ts +7 -2
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/cli.d.ts +5 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/index.js +53 -23
- package/dist/index.js.map +1 -1
- package/dist/migrations/001-init.js +16 -67
- package/dist/migrations/001-init.js.map +1 -0
- package/dist/migrations/002-add-transaction-timestamps.js +11 -18
- package/dist/migrations/002-add-transaction-timestamps.js.map +1 -0
- package/dist/migrations/003-add-transaction-origin.js +9 -10
- package/dist/migrations/003-add-transaction-origin.js.map +1 -0
- package/dist/migrations/004-add-session-id.js +9 -7
- package/dist/migrations/004-add-session-id.js.map +1 -0
- package/dist/migrations/005-add-wallet-disabled-reason.js +10 -11
- package/dist/migrations/005-add-wallet-disabled-reason.js.map +1 -0
- package/dist/migrations/006-change-wallet-primary-key-to-composite.js +51 -116
- package/dist/migrations/006-change-wallet-primary-key-to-composite.js.map +1 -0
- package/dist/migrations/007-add-unique-primary-per-network.js +14 -26
- package/dist/migrations/007-add-unique-primary-per-network.js.map +1 -0
- package/dist/migrations/008-add-transaction-external-tx-id.js +10 -14
- package/dist/migrations/008-add-transaction-external-tx-id.js.map +1 -0
- package/dist/migrations/009-add-wallet-rights-columns.js +29 -36
- package/dist/migrations/009-add-wallet-rights-columns.js.map +1 -0
- package/dist/migrations/010-add-transaction-network-id.js +33 -71
- package/dist/migrations/010-add-transaction-network-id.js.map +1 -0
- package/dist/migrations/011-add-transaction-id-primary-key.js +41 -79
- package/dist/migrations/011-add-transaction-id-primary-key.js.map +1 -0
- package/dist/migrations/012-add-messages-to-sign.js +10 -25
- package/dist/migrations/012-add-messages-to-sign.js.map +1 -0
- package/dist/migrations/013-add-api-key.js +8 -16
- package/dist/migrations/013-add-api-key.js.map +1 -0
- package/dist/migrations/014-add-service-account-column.js +9 -13
- package/dist/migrations/014-add-service-account-column.js.map +1 -0
- package/dist/migrations/015-add-origin-field-session.js +22 -33
- package/dist/migrations/015-add-origin-field-session.js.map +1 -0
- package/dist/migrations/016-add-failure-reason-and-awaiting-signature.js +13 -17
- package/dist/migrations/016-add-failure-reason-and-awaiting-signature.js.map +1 -0
- package/dist/migrations/017-make-idp-issuer-nullable.js +38 -80
- package/dist/migrations/017-make-idp-issuer-nullable.js.map +1 -0
- package/dist/migrations/018-add-wallet-is-auth-party.js +8 -9
- package/dist/migrations/018-add-wallet-is-auth-party.js.map +1 -0
- package/dist/migrations/019-make-session-access-token-nullable.js +39 -64
- package/dist/migrations/019-make-session-access-token-nullable.js.map +1 -0
- package/dist/migrations/020-add-message-external-tx-id-and-failure-reason.js +10 -20
- package/dist/migrations/020-add-message-external-tx-id-and-failure-reason.js.map +1 -0
- package/dist/migrations/021-add-message-kind.d.ts +5 -0
- package/dist/migrations/021-add-message-kind.d.ts.map +1 -0
- package/dist/migrations/021-add-message-kind.js +10 -0
- package/dist/migrations/021-add-message-kind.js.map +1 -0
- package/dist/schema.d.ts +4 -3
- package/dist/schema.d.ts.map +1 -1
- package/dist/store-sql.d.ts +2 -2
- package/dist/store-sql.d.ts.map +1 -1
- package/dist/utils-BAU4kQB4.js +13 -0
- package/dist/utils-BAU4kQB4.js.map +1 -0
- package/package.json +9 -9
- package/dist/schema.js +0 -297
- package/dist/utils.js +0 -13
package/dist/bootstrap.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type { Kysely } from 'kysely';
|
|
2
|
-
import type
|
|
3
|
-
import type
|
|
2
|
+
import { type BootstrapConfig } from '@canton-network/core-wallet-store';
|
|
3
|
+
import { type DB } from './schema';
|
|
4
4
|
export declare function bootstrap(db: Kysely<DB>, config: BootstrapConfig): Promise<void>;
|
|
5
|
+
/**
|
|
6
|
+
* Inserts or updates the given IDPs and networks, so the store matches the
|
|
7
|
+
* config on every start. Rows not mentioned in the config are left untouched.
|
|
8
|
+
*/
|
|
9
|
+
export declare function upsertIdpsAndNetworks(db: Kysely<DB>, config: BootstrapConfig): Promise<void>;
|
|
5
10
|
//# sourceMappingURL=bootstrap.d.ts.map
|
package/dist/bootstrap.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../src/bootstrap.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAEpC,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../src/bootstrap.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAEpC,OAAO,EAEH,KAAK,eAAe,EACvB,MAAM,mCAAmC,CAAA;AAC1C,OAAO,EAAmC,KAAK,EAAE,EAAE,MAAM,UAAU,CAAA;AAEnE,wBAAsB,SAAS,CAC3B,EAAE,EAAE,MAAM,CAAC,EAAE,CAAC,EACd,MAAM,EAAE,eAAe,GACxB,OAAO,CAAC,IAAI,CAAC,CAUf;AAED;;;GAGG;AACH,wBAAsB,qBAAqB,CACvC,EAAE,EAAE,MAAM,CAAC,EAAE,CAAC,EACd,MAAM,EAAE,eAAe,GACxB,OAAO,CAAC,IAAI,CAAC,CAiCf"}
|
package/dist/cli.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
import type { StoreConfig, BootstrapConfig } from '@canton-network/core-wallet-store';
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* @param bootstrapConfig IDPs and networks that are only inserted
|
|
5
|
+
* @param configIdpsAndNetworks IDPs and networks that are inserted or updated
|
|
6
|
+
*/
|
|
7
|
+
export declare function createCLI(config: StoreConfig, bootstrapConfig: BootstrapConfig, configIdpsAndNetworks: BootstrapConfig): Command;
|
|
4
8
|
//# sourceMappingURL=cli.d.ts.map
|
package/dist/cli.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAGnC,OAAO,KAAK,EACR,WAAW,EACX,eAAe,EAClB,MAAM,mCAAmC,CAAA;AAM1C,wBAAgB,SAAS,CACrB,MAAM,EAAE,WAAW,EACnB,eAAe,
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAGnC,OAAO,KAAK,EACR,WAAW,EACX,eAAe,EAClB,MAAM,mCAAmC,CAAA;AAM1C;;;GAGG;AACH,wBAAgB,SAAS,CACrB,MAAM,EAAE,WAAW,EACnB,eAAe,EAAE,eAAe,EAChC,qBAAqB,EAAE,eAAe,GACvC,OAAO,CAmFT"}
|
package/dist/index.js
CHANGED
|
@@ -74,11 +74,11 @@ const fromNetwork = (network, userId) => {
|
|
|
74
74
|
synchronizerId: network.synchronizerId ?? null,
|
|
75
75
|
description: network.description,
|
|
76
76
|
ledgerApiBaseUrl: network.ledgerApi.baseUrl,
|
|
77
|
-
userId,
|
|
77
|
+
userId: userId ?? null,
|
|
78
78
|
identityProviderId: network.identityProviderId,
|
|
79
79
|
auth: JSON.stringify(network.auth),
|
|
80
|
-
adminAuth: network.adminAuth ? JSON.stringify(network.adminAuth) :
|
|
81
|
-
serviceAccountAuth: network.serviceAccountAuth ? JSON.stringify(network.serviceAccountAuth) :
|
|
80
|
+
adminAuth: network.adminAuth ? JSON.stringify(network.adminAuth) : null,
|
|
81
|
+
serviceAccountAuth: network.serviceAccountAuth ? JSON.stringify(network.serviceAccountAuth) : null
|
|
82
82
|
};
|
|
83
83
|
};
|
|
84
84
|
const toSession = (table) => {
|
|
@@ -183,6 +183,7 @@ const fromMessageRaw = (message, userId, networkId) => {
|
|
|
183
183
|
if (message.userId !== userId) throw new Error(`MessageRaw userId mismatch: expected ${userId}, got ${message.userId}`);
|
|
184
184
|
return {
|
|
185
185
|
id: message.id,
|
|
186
|
+
kind: message.kind,
|
|
186
187
|
status: message.status,
|
|
187
188
|
userId: message.userId,
|
|
188
189
|
partyId: message.partyId,
|
|
@@ -200,6 +201,7 @@ const fromMessageRaw = (message, userId, networkId) => {
|
|
|
200
201
|
const toMessageRaw = (table) => {
|
|
201
202
|
const result = {
|
|
202
203
|
id: table.id,
|
|
204
|
+
kind: table.kind,
|
|
203
205
|
status: table.status,
|
|
204
206
|
userId: table.userId,
|
|
205
207
|
partyId: table.partyId,
|
|
@@ -238,7 +240,7 @@ const toApiKey = (apiKey) => {
|
|
|
238
240
|
lastUsedAt: apiKey.lastUsedAt ? apiKey.lastUsedAt.toISOString() : null
|
|
239
241
|
};
|
|
240
242
|
};
|
|
241
|
-
// \0@oxc-project+runtime@0.
|
|
243
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/typeof.js
|
|
242
244
|
function _typeof(o) {
|
|
243
245
|
"@babel/helpers - typeof";
|
|
244
246
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -247,23 +249,23 @@ function _typeof(o) {
|
|
|
247
249
|
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
248
250
|
}, _typeof(o);
|
|
249
251
|
}
|
|
250
|
-
// \0@oxc-project+runtime@0.
|
|
251
|
-
function toPrimitive(t,
|
|
252
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/toPrimitive.js
|
|
253
|
+
function toPrimitive(t, e) {
|
|
252
254
|
if ("object" != _typeof(t) || !t) return t;
|
|
253
|
-
var
|
|
254
|
-
if (void 0 !==
|
|
255
|
-
var i =
|
|
255
|
+
var r;
|
|
256
|
+
if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) {
|
|
257
|
+
var i = r.call(t, e || "default");
|
|
256
258
|
if ("object" != _typeof(i)) return i;
|
|
257
259
|
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
258
260
|
}
|
|
259
|
-
return ("string" ===
|
|
261
|
+
return ("string" === e ? String : Number)(t);
|
|
260
262
|
}
|
|
261
|
-
// \0@oxc-project+runtime@0.
|
|
263
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/toPropertyKey.js
|
|
262
264
|
function toPropertyKey(t) {
|
|
263
265
|
var i = toPrimitive(t, "string");
|
|
264
266
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
265
267
|
}
|
|
266
|
-
// \0@oxc-project+runtime@0.
|
|
268
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/defineProperty.js
|
|
267
269
|
function _defineProperty(e, r, t) {
|
|
268
270
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
269
271
|
value: t,
|
|
@@ -592,7 +594,7 @@ var StoreSql = class StoreSql {
|
|
|
592
594
|
await this.db.transaction().execute(async (trx) => {
|
|
593
595
|
const existing = (await trx.selectFrom("networks").selectAll().execute()).map(toNetwork);
|
|
594
596
|
assertUniqueSelfIssuedAudience(existing, network, network.id);
|
|
595
|
-
const networkEntry = fromNetwork(network
|
|
597
|
+
const { userId: _userId, ...networkEntry } = fromNetwork(network);
|
|
596
598
|
this.logger.info("Updating network table", { networkEntry });
|
|
597
599
|
await trx.updateTable("networks").set(networkEntry).where("id", "=", network.id).execute();
|
|
598
600
|
});
|
|
@@ -608,11 +610,9 @@ var StoreSql = class StoreSql {
|
|
|
608
610
|
});
|
|
609
611
|
}
|
|
610
612
|
async removeNetwork(networkId) {
|
|
611
|
-
|
|
613
|
+
this.assertConnected();
|
|
612
614
|
await this.db.transaction().execute(async (trx) => {
|
|
613
|
-
|
|
614
|
-
if (!network) throw new Error(`Network ${networkId} does not exists`);
|
|
615
|
-
if (network.userId !== userId) throw new Error(`Network ${networkId} is not owned by user ${userId}`);
|
|
615
|
+
if (!await trx.selectFrom("networks").selectAll().where("id", "=", networkId).executeTakeFirst()) throw new Error(`Network ${networkId} does not exists`);
|
|
616
616
|
await trx.deleteFrom("networks").where("id", "=", networkId).execute();
|
|
617
617
|
});
|
|
618
618
|
}
|
|
@@ -779,10 +779,14 @@ var StoreSql = class StoreSql {
|
|
|
779
779
|
])).executeTakeFirst();
|
|
780
780
|
return message ? toMessageRaw(message) : void 0;
|
|
781
781
|
}
|
|
782
|
-
async listMessageRaws() {
|
|
782
|
+
async listMessageRaws(kind) {
|
|
783
783
|
const userId = this.assertConnected();
|
|
784
784
|
const network = await this.getCurrentNetwork();
|
|
785
|
-
return (await this.db.selectFrom("messagesRaw").selectAll().where((eb) => eb.and([
|
|
785
|
+
return (await this.db.selectFrom("messagesRaw").selectAll().where((eb) => eb.and([
|
|
786
|
+
eb("userId", "=", userId),
|
|
787
|
+
eb("networkId", "=", network.id),
|
|
788
|
+
eb("kind", "=", kind)
|
|
789
|
+
])).orderBy("createdAt", "desc").orderBy("id", "desc").execute()).map((m) => toMessageRaw(m));
|
|
786
790
|
}
|
|
787
791
|
async removeMessageRaw(messageId) {
|
|
788
792
|
const userId = this.assertConnected();
|
|
@@ -899,13 +903,36 @@ async function bootstrap(db, config) {
|
|
|
899
903
|
await Promise.all(config.idps.map((idp) => store.addIdp(idp)));
|
|
900
904
|
await Promise.all(config.networks.map((network) => store.addNetwork(network)));
|
|
901
905
|
}
|
|
906
|
+
/**
|
|
907
|
+
* Inserts or updates the given IDPs and networks, so the store matches the
|
|
908
|
+
* config on every start. Rows not mentioned in the config are left untouched.
|
|
909
|
+
*/
|
|
910
|
+
async function upsertIdpsAndNetworks(db, config) {
|
|
911
|
+
await db.transaction().execute(async (trx) => {
|
|
912
|
+
for (const idp of config.idps) {
|
|
913
|
+
const row = fromIdp(idp);
|
|
914
|
+
await trx.insertInto("idps").values(row).onConflict((oc) => oc.column("id").doUpdateSet(row)).execute();
|
|
915
|
+
}
|
|
916
|
+
const configNetworkIds = new Set(config.networks.map((n) => n.id));
|
|
917
|
+
const otherNetworks = (await trx.selectFrom("networks").selectAll().execute()).map(toNetwork).filter((network) => !configNetworkIds.has(network.id));
|
|
918
|
+
for (const network of config.networks) assertUniqueSelfIssuedAudience(otherNetworks, network);
|
|
919
|
+
for (const network of config.networks) {
|
|
920
|
+
const row = fromNetwork(network);
|
|
921
|
+
await trx.insertInto("networks").values(row).onConflict((oc) => oc.column("id").doUpdateSet(row)).execute();
|
|
922
|
+
}
|
|
923
|
+
});
|
|
924
|
+
}
|
|
902
925
|
// src/cli.ts
|
|
903
926
|
const logger = getLogger([
|
|
904
927
|
"core",
|
|
905
928
|
"wallet-store-sql",
|
|
906
929
|
"cli"
|
|
907
930
|
]);
|
|
908
|
-
|
|
931
|
+
/**
|
|
932
|
+
* @param bootstrapConfig IDPs and networks that are only inserted
|
|
933
|
+
* @param configIdpsAndNetworks IDPs and networks that are inserted or updated
|
|
934
|
+
*/
|
|
935
|
+
function createCLI(config, bootstrapConfig, configIdpsAndNetworks) {
|
|
909
936
|
const program = new Command();
|
|
910
937
|
program.command("up").description("Run all pending migrations").action(async () => {
|
|
911
938
|
const db = connection(config);
|
|
@@ -935,13 +962,16 @@ function createCLI(config, bootstrapConfig) {
|
|
|
935
962
|
await db.destroy();
|
|
936
963
|
});
|
|
937
964
|
program.command("bootstrap").description("Bootstrap DB from config").action(async () => {
|
|
938
|
-
if (!bootstrapConfig) throw new Error("Bootstrap config (idps/networks) is required for the bootstrap command");
|
|
939
965
|
const db = connection(config);
|
|
940
|
-
await
|
|
966
|
+
const idp = await db.selectFrom("idps").select("id").executeTakeFirst();
|
|
967
|
+
const network = await db.selectFrom("networks").select("id").executeTakeFirst();
|
|
968
|
+
if (idp || network) logger.info("Skipping the bootstrap section, the database already contains identity providers or networks");
|
|
969
|
+
else await bootstrap(db, bootstrapConfig);
|
|
970
|
+
await upsertIdpsAndNetworks(db, configIdpsAndNetworks);
|
|
941
971
|
await db.destroy();
|
|
942
972
|
});
|
|
943
973
|
return program;
|
|
944
974
|
}
|
|
945
|
-
export { StoreSql, bootstrap, connection, createCLI, migrator };
|
|
975
|
+
export { StoreSql, bootstrap, connection, createCLI, migrator, upsertIdpsAndNetworks };
|
|
946
976
|
|
|
947
977
|
//# sourceMappingURL=index.js.map
|