@earbug/db-models 0.0.52 → 0.0.54

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/README.md CHANGED
@@ -9,3 +9,17 @@ To update the models after altering your local DB schema:
9
9
  1. bump version in `package.json`
10
10
  1. `npm publish` - Will publish to npm.
11
11
  1. Bump the version in your dependent package: `npm i @earbug/db-models@latest`
12
+
13
+ ## Connecting with TLS
14
+
15
+ TLS is **off** by default. Set `PG_SSL=true` (or pass `initDb({ ssl: true })`)
16
+ to connect over TLS and validate the server against the Amazon RDS CA bundle
17
+ that ships with this package. Services that build their own Sequelize/pg client
18
+ can use the exported `RDS_SSL_CONFIG` for the same settings.
19
+
20
+ The bundled CA comes from AWS's public truststore. Refresh it after an AWS CA
21
+ rotation and commit the regenerated file:
22
+
23
+ ```bash
24
+ npm run update-rds-ca
25
+ ```
@@ -3,8 +3,6 @@ import { Model, Optional } from 'sequelize';
3
3
  import type { JukeboxQueueEntry, JukeboxQueueEntryId } from './JukeboxQueueEntry';
4
4
  import type { JukeboxSession, JukeboxSessionId } from './JukeboxSession';
5
5
  import type { Versus, VersusId } from './Versus';
6
- import type { VersusCoCreator, VersusCoCreatorId } from './VersusCoCreator';
7
- import type { VersusOption, VersusOptionId } from './VersusOption';
8
6
  export interface GuestUserAttributes {
9
7
  jukeboxSessionId?: string;
10
8
  firstName: string;
@@ -39,28 +37,6 @@ export declare class GuestUser extends Model<GuestUserAttributes, GuestUserCreat
39
37
  hasJukeboxQueueEntry: Sequelize.HasManyHasAssociationMixin<JukeboxQueueEntry, JukeboxQueueEntryId>;
40
38
  hasJukeboxQueueEntries: Sequelize.HasManyHasAssociationsMixin<JukeboxQueueEntry, JukeboxQueueEntryId>;
41
39
  countJukeboxQueueEntries: Sequelize.HasManyCountAssociationsMixin;
42
- versusCoCreators: VersusCoCreator[];
43
- getVersusCoCreators: Sequelize.HasManyGetAssociationsMixin<VersusCoCreator>;
44
- setVersusCoCreators: Sequelize.HasManySetAssociationsMixin<VersusCoCreator, VersusCoCreatorId>;
45
- addVersusCoCreator: Sequelize.HasManyAddAssociationMixin<VersusCoCreator, VersusCoCreatorId>;
46
- addVersusCoCreators: Sequelize.HasManyAddAssociationsMixin<VersusCoCreator, VersusCoCreatorId>;
47
- createVersusCoCreator: Sequelize.HasManyCreateAssociationMixin<VersusCoCreator>;
48
- removeVersusCoCreator: Sequelize.HasManyRemoveAssociationMixin<VersusCoCreator, VersusCoCreatorId>;
49
- removeVersusCoCreators: Sequelize.HasManyRemoveAssociationsMixin<VersusCoCreator, VersusCoCreatorId>;
50
- hasVersusCoCreator: Sequelize.HasManyHasAssociationMixin<VersusCoCreator, VersusCoCreatorId>;
51
- hasVersusCoCreators: Sequelize.HasManyHasAssociationsMixin<VersusCoCreator, VersusCoCreatorId>;
52
- countVersusCoCreators: Sequelize.HasManyCountAssociationsMixin;
53
- versusOptions: VersusOption[];
54
- getVersusOptions: Sequelize.HasManyGetAssociationsMixin<VersusOption>;
55
- setVersusOptions: Sequelize.HasManySetAssociationsMixin<VersusOption, VersusOptionId>;
56
- addVersusOption: Sequelize.HasManyAddAssociationMixin<VersusOption, VersusOptionId>;
57
- addVersusOptions: Sequelize.HasManyAddAssociationsMixin<VersusOption, VersusOptionId>;
58
- createVersusOption: Sequelize.HasManyCreateAssociationMixin<VersusOption>;
59
- removeVersusOption: Sequelize.HasManyRemoveAssociationMixin<VersusOption, VersusOptionId>;
60
- removeVersusOptions: Sequelize.HasManyRemoveAssociationsMixin<VersusOption, VersusOptionId>;
61
- hasVersusOption: Sequelize.HasManyHasAssociationMixin<VersusOption, VersusOptionId>;
62
- hasVersusOptions: Sequelize.HasManyHasAssociationsMixin<VersusOption, VersusOptionId>;
63
- countVersusOptions: Sequelize.HasManyCountAssociationsMixin;
64
40
  jukeboxSession: JukeboxSession;
65
41
  getJukeboxSession: Sequelize.BelongsToGetAssociationMixin<JukeboxSession>;
66
42
  setJukeboxSession: Sequelize.BelongsToSetAssociationMixin<JukeboxSession, JukeboxSessionId>;
@@ -1,37 +1,28 @@
1
1
  import * as Sequelize from 'sequelize';
2
2
  import { Model, Optional } from 'sequelize';
3
3
  import type { AppUser, AppUserId } from './AppUser';
4
- import type { GuestUser, GuestUserId } from './GuestUser';
5
4
  import type { Versus, VersusId } from './Versus';
6
5
  export interface VersusCoCreatorAttributes {
7
6
  versusId: string;
8
- appUserId?: string;
9
- guestUserId?: string;
10
- invitedEmail?: string;
11
7
  id: string;
12
8
  createdAt: Date;
13
9
  updatedAt: Date;
10
+ appUserId: string;
14
11
  }
15
12
  export type VersusCoCreatorPk = "id";
16
13
  export type VersusCoCreatorId = VersusCoCreator[VersusCoCreatorPk];
17
- export type VersusCoCreatorOptionalAttributes = "appUserId" | "guestUserId" | "invitedEmail" | "id" | "createdAt" | "updatedAt";
14
+ export type VersusCoCreatorOptionalAttributes = "id" | "createdAt" | "updatedAt";
18
15
  export type VersusCoCreatorCreationAttributes = Optional<VersusCoCreatorAttributes, VersusCoCreatorOptionalAttributes>;
19
16
  export declare class VersusCoCreator extends Model<VersusCoCreatorAttributes, VersusCoCreatorCreationAttributes> implements VersusCoCreatorAttributes {
20
17
  versusId: string;
21
- appUserId?: string;
22
- guestUserId?: string;
23
- invitedEmail?: string;
24
18
  id: string;
25
19
  createdAt: Date;
26
20
  updatedAt: Date;
21
+ appUserId: string;
27
22
  appUser: AppUser;
28
23
  getAppUser: Sequelize.BelongsToGetAssociationMixin<AppUser>;
29
24
  setAppUser: Sequelize.BelongsToSetAssociationMixin<AppUser, AppUserId>;
30
25
  createAppUser: Sequelize.BelongsToCreateAssociationMixin<AppUser>;
31
- guestUser: GuestUser;
32
- getGuestUser: Sequelize.BelongsToGetAssociationMixin<GuestUser>;
33
- setGuestUser: Sequelize.BelongsToSetAssociationMixin<GuestUser, GuestUserId>;
34
- createGuestUser: Sequelize.BelongsToCreateAssociationMixin<GuestUser>;
35
26
  versu: Versus;
36
27
  getVersu: Sequelize.BelongsToGetAssociationMixin<Versus>;
37
28
  setVersu: Sequelize.BelongsToSetAssociationMixin<Versus, VersusId>;
@@ -38,29 +38,6 @@ class VersusCoCreator extends sequelize_1.Model {
38
38
  },
39
39
  field: 'versus_id'
40
40
  },
41
- appUserId: {
42
- type: sequelize_1.DataTypes.UUID,
43
- allowNull: true,
44
- references: {
45
- model: 'app_user',
46
- key: 'id'
47
- },
48
- field: 'app_user_id'
49
- },
50
- guestUserId: {
51
- type: sequelize_1.DataTypes.UUID,
52
- allowNull: true,
53
- references: {
54
- model: 'guest_user',
55
- key: 'id'
56
- },
57
- field: 'guest_user_id'
58
- },
59
- invitedEmail: {
60
- type: sequelize_1.DataTypes.TEXT,
61
- allowNull: true,
62
- field: 'invited_email'
63
- },
64
41
  id: {
65
42
  type: sequelize_1.DataTypes.UUID,
66
43
  allowNull: false,
@@ -78,6 +55,15 @@ class VersusCoCreator extends sequelize_1.Model {
78
55
  allowNull: false,
79
56
  defaultValue: Sequelize.Sequelize.literal('CURRENT_TIMESTAMP'),
80
57
  field: 'updated_at'
58
+ },
59
+ appUserId: {
60
+ type: sequelize_1.DataTypes.UUID,
61
+ allowNull: false,
62
+ references: {
63
+ model: 'app_user',
64
+ key: 'id'
65
+ },
66
+ field: 'app_user_id'
81
67
  }
82
68
  }, {
83
69
  sequelize,
@@ -92,15 +78,17 @@ class VersusCoCreator extends sequelize_1.Model {
92
78
  ]
93
79
  },
94
80
  {
95
- name: "idx_versus_co_creator_guest_user",
81
+ name: "idx_versus_co_creator_versus",
96
82
  fields: [
97
- { name: "guest_user_id" },
83
+ { name: "versus_id" },
98
84
  ]
99
85
  },
100
86
  {
101
- name: "idx_versus_co_creator_versus",
87
+ name: "uk_versus_co_creator_versus_app_user",
88
+ unique: true,
102
89
  fields: [
103
90
  { name: "versus_id" },
91
+ { name: "app_user_id" },
104
92
  ]
105
93
  },
106
94
  {
@@ -4,7 +4,6 @@ import type { AppUser, AppUserId } from './AppUser';
4
4
  import type { CanonAlbum, CanonAlbumId } from './CanonAlbum';
5
5
  import type { CanonArtist, CanonArtistId } from './CanonArtist';
6
6
  import type { CanonTrack, CanonTrackId } from './CanonTrack';
7
- import type { GuestUser, GuestUserId } from './GuestUser';
8
7
  import type { PlatformAlbum, PlatformAlbumId } from './PlatformAlbum';
9
8
  import type { PlatformArtist, PlatformArtistId } from './PlatformArtist';
10
9
  import type { PlatformTrack, PlatformTrackId } from './PlatformTrack';
@@ -27,11 +26,10 @@ export interface VersusOptionAttributes {
27
26
  updatedAt: Date;
28
27
  deleted: boolean;
29
28
  appUserId?: string;
30
- guestUserId?: string;
31
29
  }
32
30
  export type VersusOptionPk = "id";
33
31
  export type VersusOptionId = VersusOption[VersusOptionPk];
34
- export type VersusOptionOptionalAttributes = "canonTrackId" | "platformTrackId" | "canonAlbumId" | "platformAlbumId" | "canonArtistId" | "platformArtistId" | "voteScore" | "resultsScore" | "id" | "createdAt" | "updatedAt" | "appUserId" | "guestUserId";
32
+ export type VersusOptionOptionalAttributes = "canonTrackId" | "platformTrackId" | "canonAlbumId" | "platformAlbumId" | "canonArtistId" | "platformArtistId" | "voteScore" | "resultsScore" | "id" | "createdAt" | "updatedAt" | "appUserId";
35
33
  export type VersusOptionCreationAttributes = Optional<VersusOptionAttributes, VersusOptionOptionalAttributes>;
36
34
  export declare class VersusOption extends Model<VersusOptionAttributes, VersusOptionCreationAttributes> implements VersusOptionAttributes {
37
35
  versusId: string;
@@ -50,7 +48,6 @@ export declare class VersusOption extends Model<VersusOptionAttributes, VersusOp
50
48
  updatedAt: Date;
51
49
  deleted: boolean;
52
50
  appUserId?: string;
53
- guestUserId?: string;
54
51
  appUser: AppUser;
55
52
  getAppUser: Sequelize.BelongsToGetAssociationMixin<AppUser>;
56
53
  setAppUser: Sequelize.BelongsToSetAssociationMixin<AppUser, AppUserId>;
@@ -67,10 +64,6 @@ export declare class VersusOption extends Model<VersusOptionAttributes, VersusOp
67
64
  getCanonTrack: Sequelize.BelongsToGetAssociationMixin<CanonTrack>;
68
65
  setCanonTrack: Sequelize.BelongsToSetAssociationMixin<CanonTrack, CanonTrackId>;
69
66
  createCanonTrack: Sequelize.BelongsToCreateAssociationMixin<CanonTrack>;
70
- guestUser: GuestUser;
71
- getGuestUser: Sequelize.BelongsToGetAssociationMixin<GuestUser>;
72
- setGuestUser: Sequelize.BelongsToSetAssociationMixin<GuestUser, GuestUserId>;
73
- createGuestUser: Sequelize.BelongsToCreateAssociationMixin<GuestUser>;
74
67
  platformAlbum: PlatformAlbum;
75
68
  getPlatformAlbum: Sequelize.BelongsToGetAssociationMixin<PlatformAlbum>;
76
69
  setPlatformAlbum: Sequelize.BelongsToSetAssociationMixin<PlatformAlbum, PlatformAlbumId>;
@@ -147,15 +147,6 @@ class VersusOption extends sequelize_1.Model {
147
147
  key: 'id'
148
148
  },
149
149
  field: 'app_user_id'
150
- },
151
- guestUserId: {
152
- type: sequelize_1.DataTypes.UUID,
153
- allowNull: true,
154
- references: {
155
- model: 'guest_user',
156
- key: 'id'
157
- },
158
- field: 'guest_user_id'
159
150
  }
160
151
  }, {
161
152
  sequelize,
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export * from "./init-models";
2
- export { initDb } from "./initDb";
2
+ export { initDb, RDS_SSL_CONFIG } from "./initDb";
3
3
  export type { InitDbOptions } from "./initDb";
package/dist/index.js CHANGED
@@ -14,7 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.initDb = void 0;
17
+ exports.RDS_SSL_CONFIG = exports.initDb = void 0;
18
18
  __exportStar(require("./init-models"), exports);
19
19
  var initDb_1 = require("./initDb");
20
20
  Object.defineProperty(exports, "initDb", { enumerable: true, get: function () { return initDb_1.initDb; } });
21
+ Object.defineProperty(exports, "RDS_SSL_CONFIG", { enumerable: true, get: function () { return initDb_1.RDS_SSL_CONFIG; } });
@@ -549,10 +549,6 @@ function initModels(sequelize) {
549
549
  FeedContentType.hasMany(UserEngagementFactor, { as: "userEngagementFactors", foreignKey: "contentTypeId" });
550
550
  JukeboxQueueEntry.belongsTo(GuestUser, { as: "trackAddedGuestUser", foreignKey: "trackAddedGuestUserId" });
551
551
  GuestUser.hasMany(JukeboxQueueEntry, { as: "jukeboxQueueEntries", foreignKey: "trackAddedGuestUserId" });
552
- VersusCoCreator.belongsTo(GuestUser, { as: "guestUser", foreignKey: "guestUserId" });
553
- GuestUser.hasMany(VersusCoCreator, { as: "versusCoCreators", foreignKey: "guestUserId" });
554
- VersusOption.belongsTo(GuestUser, { as: "guestUser", foreignKey: "guestUserId" });
555
- GuestUser.hasMany(VersusOption, { as: "versusOptions", foreignKey: "guestUserId" });
556
552
  JukeboxSession.belongsTo(JukeboxAccessType, { as: "accessType", foreignKey: "accessTypeId" });
557
553
  JukeboxAccessType.hasMany(JukeboxSession, { as: "jukeboxSessions", foreignKey: "accessTypeId" });
558
554
  JukeboxUser.belongsTo(JukeboxQueueEntry, { as: "pausedQueueEntry", foreignKey: "pausedQueueEntryId" });
package/dist/initDb.d.ts CHANGED
@@ -4,4 +4,12 @@ export interface InitDbOptions {
4
4
  retry?: Options["retry"];
5
5
  logging?: Options["logging"];
6
6
  }
7
+ /**
8
+ * TLS settings that validate an RDS endpoint against the bundled AWS RDS CA
9
+ * bundle. Exported for services that construct their own Sequelize/pg client.
10
+ */
11
+ export declare const RDS_SSL_CONFIG: Readonly<{
12
+ ca: string;
13
+ rejectUnauthorized: true;
14
+ }>;
7
15
  export declare function initDb(options?: InitDbOptions): Sequelize;
package/dist/initDb.js CHANGED
@@ -1,16 +1,26 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RDS_SSL_CONFIG = void 0;
3
4
  exports.initDb = initDb;
4
5
  const sequelize_1 = require("sequelize");
5
6
  const init_models_1 = require("./init-models");
7
+ const rdsCaBundle_1 = require("./rdsCaBundle");
6
8
  const REQUIRED_ENV_VARS = ["PG_DATABASE", "PG_USER", "PG_HOST"];
9
+ /**
10
+ * TLS settings that validate an RDS endpoint against the bundled AWS RDS CA
11
+ * bundle. Exported for services that construct their own Sequelize/pg client.
12
+ */
13
+ exports.RDS_SSL_CONFIG = Object.freeze({
14
+ ca: rdsCaBundle_1.RDS_GLOBAL_CA_BUNDLE,
15
+ rejectUnauthorized: true,
16
+ });
7
17
  function initDb(options = {}) {
8
18
  var _a, _b, _c;
9
19
  const missing = REQUIRED_ENV_VARS.filter((v) => !process.env[v]);
10
20
  if (missing.length > 0) {
11
21
  throw new Error(`Missing required environment variables: ${missing.join(", ")}`);
12
22
  }
13
- console.log(`Initializing DB connection to ${process.env.PG_HOST}:${process.env.PG_PORT || "5432"}/${process.env.PG_DATABASE}...`);
23
+ console.log(`Initializing DB connection to ${process.env.PG_HOST}:${process.env.PG_PORT || "5432"}/${process.env.PG_DATABASE}${process.env.PG_SSL === "true" ? " (TLS)" : ""}...`);
14
24
  const sequelize = new sequelize_1.Sequelize(process.env.PG_DATABASE, process.env.PG_USER, process.env.PG_PASSWORD, {
15
25
  host: process.env.PG_HOST,
16
26
  port: parseInt(process.env.PG_PORT || "5432"),
@@ -18,6 +28,7 @@ function initDb(options = {}) {
18
28
  schema: "eb",
19
29
  minifyAliases: true,
20
30
  logging: (_a = options.logging) !== null && _a !== void 0 ? _a : false,
31
+ dialectOptions: process.env.PG_SSL === "true" ? { ssl: exports.RDS_SSL_CONFIG } : undefined,
21
32
  pool: (_b = options.pool) !== null && _b !== void 0 ? _b : {
22
33
  max: 10,
23
34
  min: 1,
@@ -0,0 +1 @@
1
+ export declare const RDS_GLOBAL_CA_BUNDLE: string;