@jskit-ai/connectors-core 0.2.67 → 0.2.69

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jskit-ai/connectors-core",
3
- "version": "0.2.67",
3
+ "version": "0.2.69",
4
4
  "description": "Portable integration configuration and server-side account connection runtime.",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -15,7 +15,7 @@
15
15
  "./locales/en.json": "./locales/en.json"
16
16
  },
17
17
  "dependencies": {
18
- "@jskit-ai/resource-core": "0.1.230",
18
+ "@jskit-ai/resource-core": "0.1.232",
19
19
  "jose": "^6.1.3",
20
20
  "json-rest-schema": "^1.0.20",
21
21
  "oauth4webapi": "3.8.8",
@@ -56,10 +56,10 @@
56
56
  }
57
57
  },
58
58
  "peerDependencies": {
59
- "@jskit-ai/database-runtime": "0.1.297",
60
- "@jskit-ai/http-runtime": "0.2.40",
61
- "@jskit-ai/kernel": "0.2.39",
62
- "@jskit-ai/resource-runtime": "0.2.64"
59
+ "@jskit-ai/database-runtime": "0.1.299",
60
+ "@jskit-ai/http-runtime": "0.2.42",
61
+ "@jskit-ai/kernel": "0.2.41",
62
+ "@jskit-ai/resource-runtime": "0.2.66"
63
63
  },
64
64
  "peerDependenciesMeta": {
65
65
  "@jskit-ai/database-runtime": {
@@ -1,8 +1,7 @@
1
1
  import assert from "node:assert/strict";
2
2
  import { randomBytes } from "node:crypto";
3
3
  import test from "node:test";
4
- import knexLib from "knex";
5
- import { requireTestDatabase } from "@jskit-ai/database-runtime/server/testDatabases";
4
+ import { createPackageTestKnex, requireTestDatabase } from "@jskit-ai/database-runtime/server/testDatabases";
6
5
  import migration from "../migrations/connectors_core_initial.cjs";
7
6
  import { createCredentialProtection, createKnexConnectionStore } from "../src/server/storage.js";
8
7
 
@@ -13,22 +12,10 @@ import { createCredentialProtection, createKnexConnectionStore } from "../src/se
13
12
  // answers, which parts of a scope count, rollback of a disconnect and of a failed seal, attempt keys, the newest
14
13
  // attempt, and pruning's count and boundary.
15
14
 
16
- // The runtime's own MySQL connection settings (database-runtime's resolveKnexConnectionFromEnvironment).
17
- const RUNTIME_MYSQL = Object.freeze({ supportBigNumbers: true, bigNumberStrings: true, dateStrings: ["DATE"], timezone: "Z" });
18
-
19
- /** A migrated database of the test's own, beside TEST_DB_NAME, dropped after the test. */
20
- async function ownDatabase(context, suffix) {
21
- const name = `${requireTestDatabase(process.env)}_${suffix}`;
22
- const server = { host: process.env.DB_HOST, port: Number(process.env.DB_PORT) || 3306, user: process.env.DB_USER, password: process.env.DB_PASSWORD };
23
- const admin = knexLib({ client: "mysql2", connection: server, pool: { min: 0, max: 1 } });
24
- await admin.raw("DROP DATABASE IF EXISTS ??", [name]);
25
- await admin.raw("CREATE DATABASE ??", [name]);
26
- const knex = knexLib({ client: "mysql2", connection: { ...server, database: name, ...RUNTIME_MYSQL }, pool: { min: 0, max: 4 } });
27
- context.after(async () => {
28
- await knex.destroy();
29
- await admin.raw("DROP DATABASE IF EXISTS ??", [name]);
30
- await admin.destroy();
31
- });
15
+
16
+ /** A lettered copy of TEST_DB_NAME the test claims (createPackageTestKnex() on MySQL), migrated, dropped after the test. */
17
+ async function ownDatabase(context) {
18
+ const knex = await createPackageTestKnex(context, { environment: { ...process.env, DB_CLIENT: "mysql2" } });
32
19
  await migration.up(knex);
33
20
  return knex;
34
21
  }
@@ -40,7 +27,7 @@ const read = (store, at) => store.withConnection(at, async ({ connection }) => c
40
27
 
41
28
  test("the store needs the application's Knex and credential protection, and answers what each call's work returns", async (context) => {
42
29
  requireTestDatabase(process.env);
43
- const knex = await ownDatabase(context, "da_conn_values");
30
+ const knex = await ownDatabase(context);
44
31
  assert.throws(() => createKnexConnectionStore({ knex: {}, protection }), { name: "TypeError", message: "createKnexConnectionStore requires the application's Knex instance." });
45
32
  assert.throws(() => createKnexConnectionStore({ knex }), { name: "TypeError", message: "Connector storage requires credential protection." });
46
33
  assert.throws(() => createKnexConnectionStore({ knex, protection: { seal: async () => "" } }), { name: "TypeError", message: "Connector storage requires credential protection." });
@@ -67,7 +54,7 @@ test("the store needs the application's Knex and credential protection, and answ
67
54
 
68
55
  test("a connection is the owner's application, subject and integration, and nothing else in the scope", async (context) => {
69
56
  requireTestDatabase(process.env);
70
- const store = createKnexConnectionStore({ knex: await ownDatabase(context, "da_conn_scope"), protection });
57
+ const store = createKnexConnectionStore({ knex: await ownDatabase(context), protection });
71
58
  await store.withConnection(scope, ({ save }) => save({ account: "calendar-a" }));
72
59
  await store.withConnection({ owner, integrationId: "mail" }, ({ save }) => save({ account: "mail-a" }));
73
60
 
@@ -82,7 +69,7 @@ test("a connection is the owner's application, subject and integration, and noth
82
69
 
83
70
  test("a failed disconnect or a failed seal keeps the connection and its attempts as they were", async (context) => {
84
71
  requireTestDatabase(process.env);
85
- const knex = await ownDatabase(context, "da_conn_rollback");
72
+ const knex = await ownDatabase(context);
86
73
  const store = createKnexConnectionStore({ knex, protection });
87
74
  const attempt = { state: "pending-state", codeVerifier: "verifier", expiresAt: Date.now() + 60_000 };
88
75
  await store.withConnection(scope, async ({ save, putAttempt }) => {
@@ -117,7 +104,7 @@ test("a failed disconnect or a failed seal keeps the connection and its attempts
117
104
 
118
105
  test("first uses of new connections at once each create their row once and run their work once", { timeout: 20_000 }, async (context) => {
119
106
  requireTestDatabase(process.env);
120
- const knex = await ownDatabase(context, "da_conn_race");
107
+ const knex = await ownDatabase(context);
121
108
  const store = createKnexConnectionStore({ knex, protection });
122
109
  const slots = ["one", "two", "three"].map((integrationId) => ({ ...scope, integrationId }));
123
110
  let runs = 0;
@@ -138,7 +125,7 @@ test("first uses of new connections at once each create their row once and run t
138
125
 
139
126
  test("an attempt is keyed by its state alone, the newest live one is answered, and consuming takes it once", async (context) => {
140
127
  requireTestDatabase(process.env);
141
- const store = createKnexConnectionStore({ knex: await ownDatabase(context, "da_conn_attempts"), protection });
128
+ const store = createKnexConnectionStore({ knex: await ownDatabase(context), protection });
142
129
  const now = Date.now();
143
130
  const older = { state: "older", expiresAt: now + 10_000, owner, integrationId: "calendar" };
144
131
  const newer = { state: "newer", expiresAt: now + 20_000, owner, integrationId: "calendar" };
@@ -170,7 +157,7 @@ test("an attempt is keyed by its state alone, the newest live one is answered, a
170
157
 
171
158
  test("pruning removes every connection's attempts that expired by `before`, inclusive, and answers how many", async (context) => {
172
159
  requireTestDatabase(process.env);
173
- const store = createKnexConnectionStore({ knex: await ownDatabase(context, "da_conn_prune"), protection });
160
+ const store = createKnexConnectionStore({ knex: await ownDatabase(context), protection });
174
161
  const before = Date.now() + 60_000;
175
162
  const otherScope = { owner: { ...owner, subjectId: "user-b" }, integrationId: "mail" };
176
163
  assert.equal(await store.pruneExpiredAttempts({ before }), 0, "nothing to prune");