@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.
- 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 +45 -21
- 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.js +8 -9
- package/dist/migrations/021-add-message-kind.js.map +1 -0
- package/dist/schema.d.ts +3 -3
- package/dist/schema.d.ts.map +1 -1
- 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 +8 -8
- package/dist/schema.js +0 -299
- 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) => {
|
|
@@ -240,7 +240,7 @@ const toApiKey = (apiKey) => {
|
|
|
240
240
|
lastUsedAt: apiKey.lastUsedAt ? apiKey.lastUsedAt.toISOString() : null
|
|
241
241
|
};
|
|
242
242
|
};
|
|
243
|
-
// \0@oxc-project+runtime@0.
|
|
243
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/typeof.js
|
|
244
244
|
function _typeof(o) {
|
|
245
245
|
"@babel/helpers - typeof";
|
|
246
246
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -249,23 +249,23 @@ function _typeof(o) {
|
|
|
249
249
|
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
250
250
|
}, _typeof(o);
|
|
251
251
|
}
|
|
252
|
-
// \0@oxc-project+runtime@0.
|
|
253
|
-
function toPrimitive(t,
|
|
252
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/toPrimitive.js
|
|
253
|
+
function toPrimitive(t, e) {
|
|
254
254
|
if ("object" != _typeof(t) || !t) return t;
|
|
255
|
-
var
|
|
256
|
-
if (void 0 !==
|
|
257
|
-
var i =
|
|
255
|
+
var r;
|
|
256
|
+
if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) {
|
|
257
|
+
var i = r.call(t, e || "default");
|
|
258
258
|
if ("object" != _typeof(i)) return i;
|
|
259
259
|
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
260
260
|
}
|
|
261
|
-
return ("string" ===
|
|
261
|
+
return ("string" === e ? String : Number)(t);
|
|
262
262
|
}
|
|
263
|
-
// \0@oxc-project+runtime@0.
|
|
263
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/toPropertyKey.js
|
|
264
264
|
function toPropertyKey(t) {
|
|
265
265
|
var i = toPrimitive(t, "string");
|
|
266
266
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
267
267
|
}
|
|
268
|
-
// \0@oxc-project+runtime@0.
|
|
268
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/defineProperty.js
|
|
269
269
|
function _defineProperty(e, r, t) {
|
|
270
270
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
271
271
|
value: t,
|
|
@@ -594,7 +594,7 @@ var StoreSql = class StoreSql {
|
|
|
594
594
|
await this.db.transaction().execute(async (trx) => {
|
|
595
595
|
const existing = (await trx.selectFrom("networks").selectAll().execute()).map(toNetwork);
|
|
596
596
|
assertUniqueSelfIssuedAudience(existing, network, network.id);
|
|
597
|
-
const networkEntry = fromNetwork(network
|
|
597
|
+
const { userId: _userId, ...networkEntry } = fromNetwork(network);
|
|
598
598
|
this.logger.info("Updating network table", { networkEntry });
|
|
599
599
|
await trx.updateTable("networks").set(networkEntry).where("id", "=", network.id).execute();
|
|
600
600
|
});
|
|
@@ -610,11 +610,9 @@ var StoreSql = class StoreSql {
|
|
|
610
610
|
});
|
|
611
611
|
}
|
|
612
612
|
async removeNetwork(networkId) {
|
|
613
|
-
|
|
613
|
+
this.assertConnected();
|
|
614
614
|
await this.db.transaction().execute(async (trx) => {
|
|
615
|
-
|
|
616
|
-
if (!network) throw new Error(`Network ${networkId} does not exists`);
|
|
617
|
-
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`);
|
|
618
616
|
await trx.deleteFrom("networks").where("id", "=", networkId).execute();
|
|
619
617
|
});
|
|
620
618
|
}
|
|
@@ -905,13 +903,36 @@ async function bootstrap(db, config) {
|
|
|
905
903
|
await Promise.all(config.idps.map((idp) => store.addIdp(idp)));
|
|
906
904
|
await Promise.all(config.networks.map((network) => store.addNetwork(network)));
|
|
907
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
|
+
}
|
|
908
925
|
// src/cli.ts
|
|
909
926
|
const logger = getLogger([
|
|
910
927
|
"core",
|
|
911
928
|
"wallet-store-sql",
|
|
912
929
|
"cli"
|
|
913
930
|
]);
|
|
914
|
-
|
|
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) {
|
|
915
936
|
const program = new Command();
|
|
916
937
|
program.command("up").description("Run all pending migrations").action(async () => {
|
|
917
938
|
const db = connection(config);
|
|
@@ -941,13 +962,16 @@ function createCLI(config, bootstrapConfig) {
|
|
|
941
962
|
await db.destroy();
|
|
942
963
|
});
|
|
943
964
|
program.command("bootstrap").description("Bootstrap DB from config").action(async () => {
|
|
944
|
-
if (!bootstrapConfig) throw new Error("Bootstrap config (idps/networks) is required for the bootstrap command");
|
|
945
965
|
const db = connection(config);
|
|
946
|
-
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);
|
|
947
971
|
await db.destroy();
|
|
948
972
|
});
|
|
949
973
|
return program;
|
|
950
974
|
}
|
|
951
|
-
export { StoreSql, bootstrap, connection, createCLI, migrator };
|
|
975
|
+
export { StoreSql, bootstrap, connection, createCLI, migrator, upsertIdpsAndNetworks };
|
|
952
976
|
|
|
953
977
|
//# sourceMappingURL=index.js.map
|