@haatlabs-core/db-core 0.19.0 → 0.21.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/cjs/columns.d.ts +1 -1
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.js +17 -0
- package/dist/cjs/notification-columns.d.ts +106 -0
- package/dist/cjs/notification-columns.js +118 -0
- package/dist/columns.d.ts +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/notification-columns.d.ts +106 -0
- package/dist/notification-columns.js +90 -0
- package/dist/notification-columns.js.map +1 -0
- package/package.json +6 -6
package/dist/cjs/columns.d.ts
CHANGED
|
@@ -383,7 +383,7 @@ export declare const outboxPriorityColumn: () => import("drizzle-orm").HasDefaul
|
|
|
383
383
|
* the tables it reads come later in the same migration.
|
|
384
384
|
*/
|
|
385
385
|
export declare const ORGANIZATION_GOES_FIRST_SQL = "CREATE OR REPLACE FUNCTION organization_goes_first() RETURNS boolean\nLANGUAGE sql STABLE\nAS $$\n WITH org AS (\n SELECT NULLIF(current_setting('app.organization_id', true), '')::uuid AS id\n ),\n held AS (\n SELECT s.plan_id\n FROM subscriptions s\n JOIN org ON s.organization_id = org.id\n WHERE s.status = 'ACTIVE'\n AND s.product = 'app'\n AND s.period_start <= now()\n AND (now() < s.period_end OR (s.provider = 'shopify' AND s.provider_ended_at IS NULL))\n LIMIT 1\n ),\n plan AS (\n SELECT COALESCE(\n (SELECT plan_id FROM held),\n (SELECT id FROM plans WHERE is_default AND product = 'app' LIMIT 1)\n ) AS id\n )\n SELECT CASE\n WHEN (SELECT id FROM org) IS NULL THEN false\n ELSE COALESCE(\n (\n SELECT f.limit_value = 1\n FROM plan_features f\n JOIN plan ON f.plan_id = plan.id\n WHERE f.feature_key = 'PRIORITY'\n ),\n false\n )\n END\n$$;";
|
|
386
|
-
type TableOf<N extends string, C extends Record<string, PgColumnBuilderBase>> = PgTableWithColumns<{
|
|
386
|
+
export type TableOf<N extends string, C extends Record<string, PgColumnBuilderBase>> = PgTableWithColumns<{
|
|
387
387
|
name: N;
|
|
388
388
|
schema: undefined;
|
|
389
389
|
columns: BuildColumns<N, C, 'pg'>;
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ export { createDatabase } from './client.js';
|
|
|
2
2
|
export type { Database, DatabaseHandle, DatabaseLogger, Tx } from './client.js';
|
|
3
3
|
export { ORGANIZATION_GOES_FIRST_SQL, apiKeyColumns, auditLogColumns, auditLogIndexes, membershipColumns, membershipIndexes, organizationColumns, organizationFeatureColumns, organizationFeatureIndexes, allowanceGrantColumns, allowanceGrantIndexes, organizationOriginEnum, outboxMessageColumns, outboxMessageIndexes, outboxPriorityColumn, paymentEventColumns, paymentEventIndexes, planColumns, planFeatureColumns, planFeatureIndexes, planIndexes, planPriceColumns, planPriceIndexes, platformAdminColumns, roleEnum, shopifyInstallationColumns, subscriptionColumns, subscriptionIndexes, subscriptionStatusEnum, timestamps, usageRecordColumns, usageRecordIndexes, userColumns, webhookEventColumns, extensionKeyColumns, userIdentityColumns, disposableEmailDomainColumns, userIdentityIndexes, extensionKeyIndexes, } from './columns.js';
|
|
4
4
|
export type { ApiKeysTable, ExtensionKeysTable, UserIdentitiesTable, DisposableEmailDomainsTable, AuditLogsTable, MembershipsTable, OrganizationsTable, OrganizationFeaturesTable, AllowanceGrantsTable, OutboxMessagesTable, PaymentEventsTable, PlanFeaturesTable, PlanPricesTable, PlansTable, PlatformAdminsTable, ShopifyInstallationsTable, SubscriptionsTable, UsageRecordsTable, UsersTable, WebhookEventsTable, } from './columns.js';
|
|
5
|
+
export { notificationColumns, notificationDefaultColumns, notificationDefaultIndexes, notificationIndexes, notificationPreferenceColumns, notificationPreferenceIndexes, pushSubscriptionColumns, pushSubscriptionIndexes, } from './notification-columns.js';
|
|
6
|
+
export type { NotificationDefaultsTable, NotificationPreferencesTable, NotificationsTable, PushSubscriptionsTable, } from './notification-columns.js';
|
|
5
7
|
export { isUniqueViolation } from './errors.js';
|
|
6
8
|
export { runMigrations, runMigrationsCli } from './migrate.js';
|
|
7
9
|
export { ApiKeyRepository } from './repositories/api-key.repository.js';
|
package/dist/cjs/index.js
CHANGED
|
@@ -42,6 +42,12 @@ __export(index_exports, {
|
|
|
42
42
|
isUniqueViolation: () => import_errors.isUniqueViolation,
|
|
43
43
|
membershipColumns: () => import_columns.membershipColumns,
|
|
44
44
|
membershipIndexes: () => import_columns.membershipIndexes,
|
|
45
|
+
notificationColumns: () => import_notification_columns.notificationColumns,
|
|
46
|
+
notificationDefaultColumns: () => import_notification_columns.notificationDefaultColumns,
|
|
47
|
+
notificationDefaultIndexes: () => import_notification_columns.notificationDefaultIndexes,
|
|
48
|
+
notificationIndexes: () => import_notification_columns.notificationIndexes,
|
|
49
|
+
notificationPreferenceColumns: () => import_notification_columns.notificationPreferenceColumns,
|
|
50
|
+
notificationPreferenceIndexes: () => import_notification_columns.notificationPreferenceIndexes,
|
|
45
51
|
organizationColumns: () => import_columns.organizationColumns,
|
|
46
52
|
organizationFeatureColumns: () => import_columns.organizationFeatureColumns,
|
|
47
53
|
organizationFeatureIndexes: () => import_columns.organizationFeatureIndexes,
|
|
@@ -58,6 +64,8 @@ __export(index_exports, {
|
|
|
58
64
|
planPriceColumns: () => import_columns.planPriceColumns,
|
|
59
65
|
planPriceIndexes: () => import_columns.planPriceIndexes,
|
|
60
66
|
platformAdminColumns: () => import_columns.platformAdminColumns,
|
|
67
|
+
pushSubscriptionColumns: () => import_notification_columns.pushSubscriptionColumns,
|
|
68
|
+
pushSubscriptionIndexes: () => import_notification_columns.pushSubscriptionIndexes,
|
|
61
69
|
roleEnum: () => import_columns.roleEnum,
|
|
62
70
|
runMigrations: () => import_migrate.runMigrations,
|
|
63
71
|
runMigrationsCli: () => import_migrate.runMigrationsCli,
|
|
@@ -77,6 +85,7 @@ __export(index_exports, {
|
|
|
77
85
|
module.exports = __toCommonJS(index_exports);
|
|
78
86
|
var import_client = require("./client.js");
|
|
79
87
|
var import_columns = require("./columns.js");
|
|
88
|
+
var import_notification_columns = require("./notification-columns.js");
|
|
80
89
|
var import_errors = require("./errors.js");
|
|
81
90
|
var import_migrate = require("./migrate.js");
|
|
82
91
|
var import_api_key_repository = require("./repositories/api-key.repository.js");
|
|
@@ -116,6 +125,12 @@ var import_writers = require("./writers.js");
|
|
|
116
125
|
isUniqueViolation,
|
|
117
126
|
membershipColumns,
|
|
118
127
|
membershipIndexes,
|
|
128
|
+
notificationColumns,
|
|
129
|
+
notificationDefaultColumns,
|
|
130
|
+
notificationDefaultIndexes,
|
|
131
|
+
notificationIndexes,
|
|
132
|
+
notificationPreferenceColumns,
|
|
133
|
+
notificationPreferenceIndexes,
|
|
119
134
|
organizationColumns,
|
|
120
135
|
organizationFeatureColumns,
|
|
121
136
|
organizationFeatureIndexes,
|
|
@@ -132,6 +147,8 @@ var import_writers = require("./writers.js");
|
|
|
132
147
|
planPriceColumns,
|
|
133
148
|
planPriceIndexes,
|
|
134
149
|
platformAdminColumns,
|
|
150
|
+
pushSubscriptionColumns,
|
|
151
|
+
pushSubscriptionIndexes,
|
|
135
152
|
roleEnum,
|
|
136
153
|
runMigrations,
|
|
137
154
|
runMigrationsCli,
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type { AnyPgColumn } from 'drizzle-orm/pg-core';
|
|
2
|
+
import type { TableOf } from './columns.js';
|
|
3
|
+
/**
|
|
4
|
+
* The columns of the notification tables (@haatlabs-core/notifications). Built like the other
|
|
5
|
+
* shared columns: the app builds each table from these, with its own migrations.
|
|
6
|
+
*/
|
|
7
|
+
type Ref = {
|
|
8
|
+
id: AnyPgColumn;
|
|
9
|
+
};
|
|
10
|
+
/** One inbox item for one recipient. The sent-at columns make each delivery idempotent. */
|
|
11
|
+
export declare const notificationColumns: (refs: {
|
|
12
|
+
organizations: Ref;
|
|
13
|
+
}) => {
|
|
14
|
+
id: import("drizzle-orm").HasDefault<import("drizzle-orm").IsPrimaryKey<import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgUUIDBuilderInitial<"id">>>>;
|
|
15
|
+
organizationId: import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgUUIDBuilderInitial<"organization_id">>;
|
|
16
|
+
recipientType: import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTextBuilderInitial<"recipient_type", [string, ...string[]]>>;
|
|
17
|
+
recipientId: import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTextBuilderInitial<"recipient_id", [string, ...string[]]>>;
|
|
18
|
+
event: import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTextBuilderInitial<"event", [string, ...string[]]>>;
|
|
19
|
+
title: import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTextBuilderInitial<"title", [string, ...string[]]>>;
|
|
20
|
+
body: import("drizzle-orm").HasDefault<import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTextBuilderInitial<"body", [string, ...string[]]>>>;
|
|
21
|
+
/** An app-relative path. */
|
|
22
|
+
link: import("drizzle-orm/pg-core").PgTextBuilderInitial<"link", [string, ...string[]]>;
|
|
23
|
+
data: import("drizzle-orm").HasDefault<import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgJsonbBuilderInitial<"data">>>;
|
|
24
|
+
/** Names the thing notified, so notifying it again adds no second row. */
|
|
25
|
+
dedupeKey: import("drizzle-orm/pg-core").PgTextBuilderInitial<"dedupe_key", [string, ...string[]]>;
|
|
26
|
+
readAt: import("drizzle-orm/pg-core").PgTimestampBuilderInitial<string>;
|
|
27
|
+
liveSentAt: import("drizzle-orm/pg-core").PgTimestampBuilderInitial<string>;
|
|
28
|
+
pushSentAt: import("drizzle-orm/pg-core").PgTimestampBuilderInitial<string>;
|
|
29
|
+
emailSentAt: import("drizzle-orm/pg-core").PgTimestampBuilderInitial<string>;
|
|
30
|
+
createdAt: import("drizzle-orm").HasDefault<import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTimestampBuilderInitial<string>>>;
|
|
31
|
+
};
|
|
32
|
+
/** The notifications' indexes, for the table's third argument. */
|
|
33
|
+
export declare const notificationIndexes: (t: {
|
|
34
|
+
organizationId: AnyPgColumn;
|
|
35
|
+
recipientType: AnyPgColumn;
|
|
36
|
+
recipientId: AnyPgColumn;
|
|
37
|
+
event: AnyPgColumn;
|
|
38
|
+
dedupeKey: AnyPgColumn;
|
|
39
|
+
createdAt: AnyPgColumn;
|
|
40
|
+
readAt: AnyPgColumn;
|
|
41
|
+
}) => import("drizzle-orm/pg-core").IndexBuilder[];
|
|
42
|
+
/** A person's own choice to get an event by a channel ('email' or 'push'). */
|
|
43
|
+
export declare const notificationPreferenceColumns: (refs: {
|
|
44
|
+
organizations: Ref;
|
|
45
|
+
}) => {
|
|
46
|
+
organizationId: import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgUUIDBuilderInitial<"organization_id">>;
|
|
47
|
+
recipientType: import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTextBuilderInitial<"recipient_type", [string, ...string[]]>>;
|
|
48
|
+
recipientId: import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTextBuilderInitial<"recipient_id", [string, ...string[]]>>;
|
|
49
|
+
event: import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTextBuilderInitial<"event", [string, ...string[]]>>;
|
|
50
|
+
channel: import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTextBuilderInitial<"channel", [string, ...string[]]>>;
|
|
51
|
+
enabled: import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgBooleanBuilderInitial<"enabled">>;
|
|
52
|
+
updatedAt: import("drizzle-orm").HasDefault<import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTimestampBuilderInitial<string>>>;
|
|
53
|
+
};
|
|
54
|
+
export declare const notificationPreferenceIndexes: (t: {
|
|
55
|
+
organizationId: AnyPgColumn;
|
|
56
|
+
recipientType: AnyPgColumn;
|
|
57
|
+
recipientId: AnyPgColumn;
|
|
58
|
+
event: AnyPgColumn;
|
|
59
|
+
channel: AnyPgColumn;
|
|
60
|
+
}) => import("drizzle-orm/pg-core").PrimaryKeyBuilder[];
|
|
61
|
+
/** An organization's default for an audience, used when a person has made no choice. */
|
|
62
|
+
export declare const notificationDefaultColumns: (refs: {
|
|
63
|
+
organizations: Ref;
|
|
64
|
+
}) => {
|
|
65
|
+
organizationId: import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgUUIDBuilderInitial<"organization_id">>;
|
|
66
|
+
audience: import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTextBuilderInitial<"audience", [string, ...string[]]>>;
|
|
67
|
+
event: import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTextBuilderInitial<"event", [string, ...string[]]>>;
|
|
68
|
+
channel: import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTextBuilderInitial<"channel", [string, ...string[]]>>;
|
|
69
|
+
enabled: import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgBooleanBuilderInitial<"enabled">>;
|
|
70
|
+
updatedAt: import("drizzle-orm").HasDefault<import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTimestampBuilderInitial<string>>>;
|
|
71
|
+
};
|
|
72
|
+
export declare const notificationDefaultIndexes: (t: {
|
|
73
|
+
organizationId: AnyPgColumn;
|
|
74
|
+
audience: AnyPgColumn;
|
|
75
|
+
event: AnyPgColumn;
|
|
76
|
+
channel: AnyPgColumn;
|
|
77
|
+
}) => import("drizzle-orm/pg-core").PrimaryKeyBuilder[];
|
|
78
|
+
/** A device that gets push: a Web Push subscription, or an FCM token. */
|
|
79
|
+
export declare const pushSubscriptionColumns: (refs: {
|
|
80
|
+
organizations: Ref;
|
|
81
|
+
}) => {
|
|
82
|
+
id: import("drizzle-orm").HasDefault<import("drizzle-orm").IsPrimaryKey<import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgUUIDBuilderInitial<"id">>>>;
|
|
83
|
+
organizationId: import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgUUIDBuilderInitial<"organization_id">>;
|
|
84
|
+
recipientType: import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTextBuilderInitial<"recipient_type", [string, ...string[]]>>;
|
|
85
|
+
recipientId: import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTextBuilderInitial<"recipient_id", [string, ...string[]]>>;
|
|
86
|
+
/** 'webpush' or 'fcm'. */
|
|
87
|
+
kind: import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTextBuilderInitial<"kind", [string, ...string[]]>>;
|
|
88
|
+
/** The Web Push endpoint, or the FCM token. */
|
|
89
|
+
endpoint: import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTextBuilderInitial<"endpoint", [string, ...string[]]>>;
|
|
90
|
+
p256dh: import("drizzle-orm/pg-core").PgTextBuilderInitial<"p256dh", [string, ...string[]]>;
|
|
91
|
+
auth: import("drizzle-orm/pg-core").PgTextBuilderInitial<"auth", [string, ...string[]]>;
|
|
92
|
+
userAgent: import("drizzle-orm/pg-core").PgTextBuilderInitial<"user_agent", [string, ...string[]]>;
|
|
93
|
+
createdAt: import("drizzle-orm").HasDefault<import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTimestampBuilderInitial<string>>>;
|
|
94
|
+
lastUsedAt: import("drizzle-orm/pg-core").PgTimestampBuilderInitial<string>;
|
|
95
|
+
};
|
|
96
|
+
export declare const pushSubscriptionIndexes: (t: {
|
|
97
|
+
organizationId: AnyPgColumn;
|
|
98
|
+
recipientType: AnyPgColumn;
|
|
99
|
+
recipientId: AnyPgColumn;
|
|
100
|
+
endpoint: AnyPgColumn;
|
|
101
|
+
}) => (import("drizzle-orm/pg-core").UniqueConstraintBuilder | import("drizzle-orm/pg-core").IndexBuilder)[];
|
|
102
|
+
export type NotificationsTable = TableOf<'notifications', ReturnType<typeof notificationColumns>>;
|
|
103
|
+
export type NotificationPreferencesTable = TableOf<'notification_preferences', ReturnType<typeof notificationPreferenceColumns>>;
|
|
104
|
+
export type NotificationDefaultsTable = TableOf<'notification_defaults', ReturnType<typeof notificationDefaultColumns>>;
|
|
105
|
+
export type PushSubscriptionsTable = TableOf<'push_subscriptions', ReturnType<typeof pushSubscriptionColumns>>;
|
|
106
|
+
export {};
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var notification_columns_exports = {};
|
|
19
|
+
__export(notification_columns_exports, {
|
|
20
|
+
notificationColumns: () => notificationColumns,
|
|
21
|
+
notificationDefaultColumns: () => notificationDefaultColumns,
|
|
22
|
+
notificationDefaultIndexes: () => notificationDefaultIndexes,
|
|
23
|
+
notificationIndexes: () => notificationIndexes,
|
|
24
|
+
notificationPreferenceColumns: () => notificationPreferenceColumns,
|
|
25
|
+
notificationPreferenceIndexes: () => notificationPreferenceIndexes,
|
|
26
|
+
pushSubscriptionColumns: () => pushSubscriptionColumns,
|
|
27
|
+
pushSubscriptionIndexes: () => pushSubscriptionIndexes
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(notification_columns_exports);
|
|
30
|
+
var import_drizzle_orm = require("drizzle-orm");
|
|
31
|
+
var import_pg_core = require("drizzle-orm/pg-core");
|
|
32
|
+
const organizationId = (refs) => (0, import_pg_core.uuid)("organization_id").notNull().references(() => refs.organizations.id, { onDelete: "cascade" });
|
|
33
|
+
const timestamptz = (name) => (0, import_pg_core.timestamp)(name, { withTimezone: true });
|
|
34
|
+
const notificationColumns = (refs) => ({
|
|
35
|
+
id: (0, import_pg_core.uuid)("id").primaryKey().defaultRandom(),
|
|
36
|
+
organizationId: organizationId(refs),
|
|
37
|
+
recipientType: (0, import_pg_core.text)("recipient_type").notNull(),
|
|
38
|
+
recipientId: (0, import_pg_core.text)("recipient_id").notNull(),
|
|
39
|
+
event: (0, import_pg_core.text)("event").notNull(),
|
|
40
|
+
title: (0, import_pg_core.text)("title").notNull(),
|
|
41
|
+
body: (0, import_pg_core.text)("body").notNull().default(""),
|
|
42
|
+
/** An app-relative path. */
|
|
43
|
+
link: (0, import_pg_core.text)("link"),
|
|
44
|
+
data: (0, import_pg_core.jsonb)("data").notNull().default({}),
|
|
45
|
+
/** Names the thing notified, so notifying it again adds no second row. */
|
|
46
|
+
dedupeKey: (0, import_pg_core.text)("dedupe_key"),
|
|
47
|
+
readAt: timestamptz("read_at"),
|
|
48
|
+
liveSentAt: timestamptz("live_sent_at"),
|
|
49
|
+
pushSentAt: timestamptz("push_sent_at"),
|
|
50
|
+
emailSentAt: timestamptz("email_sent_at"),
|
|
51
|
+
createdAt: timestamptz("created_at").notNull().defaultNow()
|
|
52
|
+
});
|
|
53
|
+
const notificationIndexes = (t) => [
|
|
54
|
+
(0, import_pg_core.index)("notifications_recipient_created_idx").on(t.organizationId, t.recipientType, t.recipientId, t.createdAt),
|
|
55
|
+
(0, import_pg_core.index)("notifications_unread_idx").on(t.organizationId, t.recipientType, t.recipientId).where(import_drizzle_orm.sql`${t.readAt} is null`),
|
|
56
|
+
(0, import_pg_core.uniqueIndex)("notifications_dedupe_uq").on(t.organizationId, t.recipientType, t.recipientId, t.event, t.dedupeKey).where(import_drizzle_orm.sql`${t.dedupeKey} is not null`)
|
|
57
|
+
];
|
|
58
|
+
const notificationPreferenceColumns = (refs) => ({
|
|
59
|
+
organizationId: organizationId(refs),
|
|
60
|
+
recipientType: (0, import_pg_core.text)("recipient_type").notNull(),
|
|
61
|
+
recipientId: (0, import_pg_core.text)("recipient_id").notNull(),
|
|
62
|
+
event: (0, import_pg_core.text)("event").notNull(),
|
|
63
|
+
channel: (0, import_pg_core.text)("channel").notNull(),
|
|
64
|
+
enabled: (0, import_pg_core.boolean)("enabled").notNull(),
|
|
65
|
+
updatedAt: timestamptz("updated_at").notNull().defaultNow()
|
|
66
|
+
});
|
|
67
|
+
const notificationPreferenceIndexes = (t) => [
|
|
68
|
+
// Named: drizzle's own name is 85 characters, and Postgres cuts names at 63.
|
|
69
|
+
(0, import_pg_core.primaryKey)({
|
|
70
|
+
name: "notification_preferences_pkey",
|
|
71
|
+
columns: [t.organizationId, t.recipientType, t.recipientId, t.event, t.channel]
|
|
72
|
+
})
|
|
73
|
+
];
|
|
74
|
+
const notificationDefaultColumns = (refs) => ({
|
|
75
|
+
organizationId: organizationId(refs),
|
|
76
|
+
audience: (0, import_pg_core.text)("audience").notNull(),
|
|
77
|
+
event: (0, import_pg_core.text)("event").notNull(),
|
|
78
|
+
channel: (0, import_pg_core.text)("channel").notNull(),
|
|
79
|
+
enabled: (0, import_pg_core.boolean)("enabled").notNull(),
|
|
80
|
+
updatedAt: timestamptz("updated_at").notNull().defaultNow()
|
|
81
|
+
});
|
|
82
|
+
const notificationDefaultIndexes = (t) => [
|
|
83
|
+
(0, import_pg_core.primaryKey)({
|
|
84
|
+
name: "notification_defaults_pkey",
|
|
85
|
+
columns: [t.organizationId, t.audience, t.event, t.channel]
|
|
86
|
+
})
|
|
87
|
+
];
|
|
88
|
+
const pushSubscriptionColumns = (refs) => ({
|
|
89
|
+
id: (0, import_pg_core.uuid)("id").primaryKey().defaultRandom(),
|
|
90
|
+
organizationId: organizationId(refs),
|
|
91
|
+
recipientType: (0, import_pg_core.text)("recipient_type").notNull(),
|
|
92
|
+
recipientId: (0, import_pg_core.text)("recipient_id").notNull(),
|
|
93
|
+
/** 'webpush' or 'fcm'. */
|
|
94
|
+
kind: (0, import_pg_core.text)("kind").notNull(),
|
|
95
|
+
/** The Web Push endpoint, or the FCM token. */
|
|
96
|
+
endpoint: (0, import_pg_core.text)("endpoint").notNull(),
|
|
97
|
+
p256dh: (0, import_pg_core.text)("p256dh"),
|
|
98
|
+
auth: (0, import_pg_core.text)("auth"),
|
|
99
|
+
userAgent: (0, import_pg_core.text)("user_agent"),
|
|
100
|
+
createdAt: timestamptz("created_at").notNull().defaultNow(),
|
|
101
|
+
lastUsedAt: timestamptz("last_used_at")
|
|
102
|
+
});
|
|
103
|
+
const pushSubscriptionIndexes = (t) => [
|
|
104
|
+
(0, import_pg_core.unique)("push_subscriptions_org_endpoint_unique").on(t.organizationId, t.endpoint),
|
|
105
|
+
// Delivery reads a recipient's devices.
|
|
106
|
+
(0, import_pg_core.index)("push_subscriptions_recipient_idx").on(t.organizationId, t.recipientType, t.recipientId)
|
|
107
|
+
];
|
|
108
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
109
|
+
0 && (module.exports = {
|
|
110
|
+
notificationColumns,
|
|
111
|
+
notificationDefaultColumns,
|
|
112
|
+
notificationDefaultIndexes,
|
|
113
|
+
notificationIndexes,
|
|
114
|
+
notificationPreferenceColumns,
|
|
115
|
+
notificationPreferenceIndexes,
|
|
116
|
+
pushSubscriptionColumns,
|
|
117
|
+
pushSubscriptionIndexes
|
|
118
|
+
});
|
package/dist/columns.d.ts
CHANGED
|
@@ -383,7 +383,7 @@ export declare const outboxPriorityColumn: () => import("drizzle-orm").HasDefaul
|
|
|
383
383
|
* the tables it reads come later in the same migration.
|
|
384
384
|
*/
|
|
385
385
|
export declare const ORGANIZATION_GOES_FIRST_SQL = "CREATE OR REPLACE FUNCTION organization_goes_first() RETURNS boolean\nLANGUAGE sql STABLE\nAS $$\n WITH org AS (\n SELECT NULLIF(current_setting('app.organization_id', true), '')::uuid AS id\n ),\n held AS (\n SELECT s.plan_id\n FROM subscriptions s\n JOIN org ON s.organization_id = org.id\n WHERE s.status = 'ACTIVE'\n AND s.product = 'app'\n AND s.period_start <= now()\n AND (now() < s.period_end OR (s.provider = 'shopify' AND s.provider_ended_at IS NULL))\n LIMIT 1\n ),\n plan AS (\n SELECT COALESCE(\n (SELECT plan_id FROM held),\n (SELECT id FROM plans WHERE is_default AND product = 'app' LIMIT 1)\n ) AS id\n )\n SELECT CASE\n WHEN (SELECT id FROM org) IS NULL THEN false\n ELSE COALESCE(\n (\n SELECT f.limit_value = 1\n FROM plan_features f\n JOIN plan ON f.plan_id = plan.id\n WHERE f.feature_key = 'PRIORITY'\n ),\n false\n )\n END\n$$;";
|
|
386
|
-
type TableOf<N extends string, C extends Record<string, PgColumnBuilderBase>> = PgTableWithColumns<{
|
|
386
|
+
export type TableOf<N extends string, C extends Record<string, PgColumnBuilderBase>> = PgTableWithColumns<{
|
|
387
387
|
name: N;
|
|
388
388
|
schema: undefined;
|
|
389
389
|
columns: BuildColumns<N, C, 'pg'>;
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ export { createDatabase } from './client.js';
|
|
|
2
2
|
export type { Database, DatabaseHandle, DatabaseLogger, Tx } from './client.js';
|
|
3
3
|
export { ORGANIZATION_GOES_FIRST_SQL, apiKeyColumns, auditLogColumns, auditLogIndexes, membershipColumns, membershipIndexes, organizationColumns, organizationFeatureColumns, organizationFeatureIndexes, allowanceGrantColumns, allowanceGrantIndexes, organizationOriginEnum, outboxMessageColumns, outboxMessageIndexes, outboxPriorityColumn, paymentEventColumns, paymentEventIndexes, planColumns, planFeatureColumns, planFeatureIndexes, planIndexes, planPriceColumns, planPriceIndexes, platformAdminColumns, roleEnum, shopifyInstallationColumns, subscriptionColumns, subscriptionIndexes, subscriptionStatusEnum, timestamps, usageRecordColumns, usageRecordIndexes, userColumns, webhookEventColumns, extensionKeyColumns, userIdentityColumns, disposableEmailDomainColumns, userIdentityIndexes, extensionKeyIndexes, } from './columns.js';
|
|
4
4
|
export type { ApiKeysTable, ExtensionKeysTable, UserIdentitiesTable, DisposableEmailDomainsTable, AuditLogsTable, MembershipsTable, OrganizationsTable, OrganizationFeaturesTable, AllowanceGrantsTable, OutboxMessagesTable, PaymentEventsTable, PlanFeaturesTable, PlanPricesTable, PlansTable, PlatformAdminsTable, ShopifyInstallationsTable, SubscriptionsTable, UsageRecordsTable, UsersTable, WebhookEventsTable, } from './columns.js';
|
|
5
|
+
export { notificationColumns, notificationDefaultColumns, notificationDefaultIndexes, notificationIndexes, notificationPreferenceColumns, notificationPreferenceIndexes, pushSubscriptionColumns, pushSubscriptionIndexes, } from './notification-columns.js';
|
|
6
|
+
export type { NotificationDefaultsTable, NotificationPreferencesTable, NotificationsTable, PushSubscriptionsTable, } from './notification-columns.js';
|
|
5
7
|
export { isUniqueViolation } from './errors.js';
|
|
6
8
|
export { runMigrations, runMigrationsCli } from './migrate.js';
|
|
7
9
|
export { ApiKeyRepository } from './repositories/api-key.repository.js';
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { createDatabase } from './client.js';
|
|
2
2
|
export { ORGANIZATION_GOES_FIRST_SQL, apiKeyColumns, auditLogColumns, auditLogIndexes, membershipColumns, membershipIndexes, organizationColumns, organizationFeatureColumns, organizationFeatureIndexes, allowanceGrantColumns, allowanceGrantIndexes, organizationOriginEnum, outboxMessageColumns, outboxMessageIndexes, outboxPriorityColumn, paymentEventColumns, paymentEventIndexes, planColumns, planFeatureColumns, planFeatureIndexes, planIndexes, planPriceColumns, planPriceIndexes, platformAdminColumns, roleEnum, shopifyInstallationColumns, subscriptionColumns, subscriptionIndexes, subscriptionStatusEnum, timestamps, usageRecordColumns, usageRecordIndexes, userColumns, webhookEventColumns, extensionKeyColumns, userIdentityColumns, disposableEmailDomainColumns, userIdentityIndexes, extensionKeyIndexes, } from './columns.js';
|
|
3
|
+
export { notificationColumns, notificationDefaultColumns, notificationDefaultIndexes, notificationIndexes, notificationPreferenceColumns, notificationPreferenceIndexes, pushSubscriptionColumns, pushSubscriptionIndexes, } from './notification-columns.js';
|
|
3
4
|
export { isUniqueViolation } from './errors.js';
|
|
4
5
|
export { runMigrations, runMigrationsCli } from './migrate.js';
|
|
5
6
|
export { ApiKeyRepository } from './repositories/api-key.repository.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,OAAO,EACL,2BAA2B,EAC3B,aAAa,EACb,eAAe,EACf,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,EACnB,0BAA0B,EAC1B,0BAA0B,EAC1B,qBAAqB,EACrB,qBAAqB,EACrB,sBAAsB,EACtB,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,EACnB,WAAW,EACX,kBAAkB,EAClB,kBAAkB,EAClB,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EAChB,oBAAoB,EACpB,QAAQ,EACR,0BAA0B,EAC1B,mBAAmB,EACnB,mBAAmB,EACnB,sBAAsB,EACtB,UAAU,EACV,kBAAkB,EAClB,kBAAkB,EAClB,WAAW,EACX,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,4BAA4B,EAC5B,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,cAAc,CAAC;AAuBtB,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AAExE,O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B,EACnB,0BAA0B,EAC1B,0BAA0B,EAC1B,mBAAmB,EACnB,6BAA6B,EAC7B,6BAA6B,EAC7B,uBAAuB,EACvB,uBAAuB,GACxB,MAAM,2BAA2B,CAAC;AAOnC,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AAExE,OAAO,EAAE,sBAAsB,EAAE,MAAM,4CAA4C,CAAC;AAEpF,OAAO,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAC3E,OAAO,EAAE,sBAAsB,EAAE,MAAM,4CAA4C,CAAC;AACpF,OAAO,EAAE,yBAAyB,EAAE,MAAM,+CAA+C,CAAC;AAE1F,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AAEvE,OAAO,EAAE,uBAAuB,EAAE,MAAM,6CAA6C,CAAC;AAEtF,OAAO,EAAE,sBAAsB,EAAE,MAAM,4CAA4C,CAAC;AACpF,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzD,OAAO,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type { AnyPgColumn } from 'drizzle-orm/pg-core';
|
|
2
|
+
import type { TableOf } from './columns.js';
|
|
3
|
+
/**
|
|
4
|
+
* The columns of the notification tables (@haatlabs-core/notifications). Built like the other
|
|
5
|
+
* shared columns: the app builds each table from these, with its own migrations.
|
|
6
|
+
*/
|
|
7
|
+
type Ref = {
|
|
8
|
+
id: AnyPgColumn;
|
|
9
|
+
};
|
|
10
|
+
/** One inbox item for one recipient. The sent-at columns make each delivery idempotent. */
|
|
11
|
+
export declare const notificationColumns: (refs: {
|
|
12
|
+
organizations: Ref;
|
|
13
|
+
}) => {
|
|
14
|
+
id: import("drizzle-orm").HasDefault<import("drizzle-orm").IsPrimaryKey<import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgUUIDBuilderInitial<"id">>>>;
|
|
15
|
+
organizationId: import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgUUIDBuilderInitial<"organization_id">>;
|
|
16
|
+
recipientType: import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTextBuilderInitial<"recipient_type", [string, ...string[]]>>;
|
|
17
|
+
recipientId: import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTextBuilderInitial<"recipient_id", [string, ...string[]]>>;
|
|
18
|
+
event: import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTextBuilderInitial<"event", [string, ...string[]]>>;
|
|
19
|
+
title: import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTextBuilderInitial<"title", [string, ...string[]]>>;
|
|
20
|
+
body: import("drizzle-orm").HasDefault<import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTextBuilderInitial<"body", [string, ...string[]]>>>;
|
|
21
|
+
/** An app-relative path. */
|
|
22
|
+
link: import("drizzle-orm/pg-core").PgTextBuilderInitial<"link", [string, ...string[]]>;
|
|
23
|
+
data: import("drizzle-orm").HasDefault<import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgJsonbBuilderInitial<"data">>>;
|
|
24
|
+
/** Names the thing notified, so notifying it again adds no second row. */
|
|
25
|
+
dedupeKey: import("drizzle-orm/pg-core").PgTextBuilderInitial<"dedupe_key", [string, ...string[]]>;
|
|
26
|
+
readAt: import("drizzle-orm/pg-core").PgTimestampBuilderInitial<string>;
|
|
27
|
+
liveSentAt: import("drizzle-orm/pg-core").PgTimestampBuilderInitial<string>;
|
|
28
|
+
pushSentAt: import("drizzle-orm/pg-core").PgTimestampBuilderInitial<string>;
|
|
29
|
+
emailSentAt: import("drizzle-orm/pg-core").PgTimestampBuilderInitial<string>;
|
|
30
|
+
createdAt: import("drizzle-orm").HasDefault<import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTimestampBuilderInitial<string>>>;
|
|
31
|
+
};
|
|
32
|
+
/** The notifications' indexes, for the table's third argument. */
|
|
33
|
+
export declare const notificationIndexes: (t: {
|
|
34
|
+
organizationId: AnyPgColumn;
|
|
35
|
+
recipientType: AnyPgColumn;
|
|
36
|
+
recipientId: AnyPgColumn;
|
|
37
|
+
event: AnyPgColumn;
|
|
38
|
+
dedupeKey: AnyPgColumn;
|
|
39
|
+
createdAt: AnyPgColumn;
|
|
40
|
+
readAt: AnyPgColumn;
|
|
41
|
+
}) => import("drizzle-orm/pg-core").IndexBuilder[];
|
|
42
|
+
/** A person's own choice to get an event by a channel ('email' or 'push'). */
|
|
43
|
+
export declare const notificationPreferenceColumns: (refs: {
|
|
44
|
+
organizations: Ref;
|
|
45
|
+
}) => {
|
|
46
|
+
organizationId: import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgUUIDBuilderInitial<"organization_id">>;
|
|
47
|
+
recipientType: import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTextBuilderInitial<"recipient_type", [string, ...string[]]>>;
|
|
48
|
+
recipientId: import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTextBuilderInitial<"recipient_id", [string, ...string[]]>>;
|
|
49
|
+
event: import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTextBuilderInitial<"event", [string, ...string[]]>>;
|
|
50
|
+
channel: import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTextBuilderInitial<"channel", [string, ...string[]]>>;
|
|
51
|
+
enabled: import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgBooleanBuilderInitial<"enabled">>;
|
|
52
|
+
updatedAt: import("drizzle-orm").HasDefault<import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTimestampBuilderInitial<string>>>;
|
|
53
|
+
};
|
|
54
|
+
export declare const notificationPreferenceIndexes: (t: {
|
|
55
|
+
organizationId: AnyPgColumn;
|
|
56
|
+
recipientType: AnyPgColumn;
|
|
57
|
+
recipientId: AnyPgColumn;
|
|
58
|
+
event: AnyPgColumn;
|
|
59
|
+
channel: AnyPgColumn;
|
|
60
|
+
}) => import("drizzle-orm/pg-core").PrimaryKeyBuilder[];
|
|
61
|
+
/** An organization's default for an audience, used when a person has made no choice. */
|
|
62
|
+
export declare const notificationDefaultColumns: (refs: {
|
|
63
|
+
organizations: Ref;
|
|
64
|
+
}) => {
|
|
65
|
+
organizationId: import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgUUIDBuilderInitial<"organization_id">>;
|
|
66
|
+
audience: import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTextBuilderInitial<"audience", [string, ...string[]]>>;
|
|
67
|
+
event: import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTextBuilderInitial<"event", [string, ...string[]]>>;
|
|
68
|
+
channel: import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTextBuilderInitial<"channel", [string, ...string[]]>>;
|
|
69
|
+
enabled: import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgBooleanBuilderInitial<"enabled">>;
|
|
70
|
+
updatedAt: import("drizzle-orm").HasDefault<import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTimestampBuilderInitial<string>>>;
|
|
71
|
+
};
|
|
72
|
+
export declare const notificationDefaultIndexes: (t: {
|
|
73
|
+
organizationId: AnyPgColumn;
|
|
74
|
+
audience: AnyPgColumn;
|
|
75
|
+
event: AnyPgColumn;
|
|
76
|
+
channel: AnyPgColumn;
|
|
77
|
+
}) => import("drizzle-orm/pg-core").PrimaryKeyBuilder[];
|
|
78
|
+
/** A device that gets push: a Web Push subscription, or an FCM token. */
|
|
79
|
+
export declare const pushSubscriptionColumns: (refs: {
|
|
80
|
+
organizations: Ref;
|
|
81
|
+
}) => {
|
|
82
|
+
id: import("drizzle-orm").HasDefault<import("drizzle-orm").IsPrimaryKey<import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgUUIDBuilderInitial<"id">>>>;
|
|
83
|
+
organizationId: import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgUUIDBuilderInitial<"organization_id">>;
|
|
84
|
+
recipientType: import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTextBuilderInitial<"recipient_type", [string, ...string[]]>>;
|
|
85
|
+
recipientId: import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTextBuilderInitial<"recipient_id", [string, ...string[]]>>;
|
|
86
|
+
/** 'webpush' or 'fcm'. */
|
|
87
|
+
kind: import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTextBuilderInitial<"kind", [string, ...string[]]>>;
|
|
88
|
+
/** The Web Push endpoint, or the FCM token. */
|
|
89
|
+
endpoint: import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTextBuilderInitial<"endpoint", [string, ...string[]]>>;
|
|
90
|
+
p256dh: import("drizzle-orm/pg-core").PgTextBuilderInitial<"p256dh", [string, ...string[]]>;
|
|
91
|
+
auth: import("drizzle-orm/pg-core").PgTextBuilderInitial<"auth", [string, ...string[]]>;
|
|
92
|
+
userAgent: import("drizzle-orm/pg-core").PgTextBuilderInitial<"user_agent", [string, ...string[]]>;
|
|
93
|
+
createdAt: import("drizzle-orm").HasDefault<import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTimestampBuilderInitial<string>>>;
|
|
94
|
+
lastUsedAt: import("drizzle-orm/pg-core").PgTimestampBuilderInitial<string>;
|
|
95
|
+
};
|
|
96
|
+
export declare const pushSubscriptionIndexes: (t: {
|
|
97
|
+
organizationId: AnyPgColumn;
|
|
98
|
+
recipientType: AnyPgColumn;
|
|
99
|
+
recipientId: AnyPgColumn;
|
|
100
|
+
endpoint: AnyPgColumn;
|
|
101
|
+
}) => (import("drizzle-orm/pg-core").UniqueConstraintBuilder | import("drizzle-orm/pg-core").IndexBuilder)[];
|
|
102
|
+
export type NotificationsTable = TableOf<'notifications', ReturnType<typeof notificationColumns>>;
|
|
103
|
+
export type NotificationPreferencesTable = TableOf<'notification_preferences', ReturnType<typeof notificationPreferenceColumns>>;
|
|
104
|
+
export type NotificationDefaultsTable = TableOf<'notification_defaults', ReturnType<typeof notificationDefaultColumns>>;
|
|
105
|
+
export type PushSubscriptionsTable = TableOf<'push_subscriptions', ReturnType<typeof pushSubscriptionColumns>>;
|
|
106
|
+
export {};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { sql } from 'drizzle-orm';
|
|
2
|
+
import { boolean, index, jsonb, primaryKey, text, timestamp, unique, uniqueIndex, uuid, } from 'drizzle-orm/pg-core';
|
|
3
|
+
const organizationId = (refs) => uuid('organization_id')
|
|
4
|
+
.notNull()
|
|
5
|
+
.references(() => refs.organizations.id, { onDelete: 'cascade' });
|
|
6
|
+
const timestamptz = (name) => timestamp(name, { withTimezone: true });
|
|
7
|
+
/** One inbox item for one recipient. The sent-at columns make each delivery idempotent. */
|
|
8
|
+
export const notificationColumns = (refs) => ({
|
|
9
|
+
id: uuid('id').primaryKey().defaultRandom(),
|
|
10
|
+
organizationId: organizationId(refs),
|
|
11
|
+
recipientType: text('recipient_type').notNull(),
|
|
12
|
+
recipientId: text('recipient_id').notNull(),
|
|
13
|
+
event: text('event').notNull(),
|
|
14
|
+
title: text('title').notNull(),
|
|
15
|
+
body: text('body').notNull().default(''),
|
|
16
|
+
/** An app-relative path. */
|
|
17
|
+
link: text('link'),
|
|
18
|
+
data: jsonb('data').notNull().default({}),
|
|
19
|
+
/** Names the thing notified, so notifying it again adds no second row. */
|
|
20
|
+
dedupeKey: text('dedupe_key'),
|
|
21
|
+
readAt: timestamptz('read_at'),
|
|
22
|
+
liveSentAt: timestamptz('live_sent_at'),
|
|
23
|
+
pushSentAt: timestamptz('push_sent_at'),
|
|
24
|
+
emailSentAt: timestamptz('email_sent_at'),
|
|
25
|
+
createdAt: timestamptz('created_at').notNull().defaultNow(),
|
|
26
|
+
});
|
|
27
|
+
/** The notifications' indexes, for the table's third argument. */
|
|
28
|
+
export const notificationIndexes = (t) => [
|
|
29
|
+
index('notifications_recipient_created_idx').on(t.organizationId, t.recipientType, t.recipientId, t.createdAt),
|
|
30
|
+
index('notifications_unread_idx')
|
|
31
|
+
.on(t.organizationId, t.recipientType, t.recipientId)
|
|
32
|
+
.where(sql `${t.readAt} is null`),
|
|
33
|
+
uniqueIndex('notifications_dedupe_uq')
|
|
34
|
+
.on(t.organizationId, t.recipientType, t.recipientId, t.event, t.dedupeKey)
|
|
35
|
+
.where(sql `${t.dedupeKey} is not null`),
|
|
36
|
+
];
|
|
37
|
+
/** A person's own choice to get an event by a channel ('email' or 'push'). */
|
|
38
|
+
export const notificationPreferenceColumns = (refs) => ({
|
|
39
|
+
organizationId: organizationId(refs),
|
|
40
|
+
recipientType: text('recipient_type').notNull(),
|
|
41
|
+
recipientId: text('recipient_id').notNull(),
|
|
42
|
+
event: text('event').notNull(),
|
|
43
|
+
channel: text('channel').notNull(),
|
|
44
|
+
enabled: boolean('enabled').notNull(),
|
|
45
|
+
updatedAt: timestamptz('updated_at').notNull().defaultNow(),
|
|
46
|
+
});
|
|
47
|
+
export const notificationPreferenceIndexes = (t) => [
|
|
48
|
+
// Named: drizzle's own name is 85 characters, and Postgres cuts names at 63.
|
|
49
|
+
primaryKey({
|
|
50
|
+
name: 'notification_preferences_pkey',
|
|
51
|
+
columns: [t.organizationId, t.recipientType, t.recipientId, t.event, t.channel],
|
|
52
|
+
}),
|
|
53
|
+
];
|
|
54
|
+
/** An organization's default for an audience, used when a person has made no choice. */
|
|
55
|
+
export const notificationDefaultColumns = (refs) => ({
|
|
56
|
+
organizationId: organizationId(refs),
|
|
57
|
+
audience: text('audience').notNull(),
|
|
58
|
+
event: text('event').notNull(),
|
|
59
|
+
channel: text('channel').notNull(),
|
|
60
|
+
enabled: boolean('enabled').notNull(),
|
|
61
|
+
updatedAt: timestamptz('updated_at').notNull().defaultNow(),
|
|
62
|
+
});
|
|
63
|
+
export const notificationDefaultIndexes = (t) => [
|
|
64
|
+
primaryKey({
|
|
65
|
+
name: 'notification_defaults_pkey',
|
|
66
|
+
columns: [t.organizationId, t.audience, t.event, t.channel],
|
|
67
|
+
}),
|
|
68
|
+
];
|
|
69
|
+
/** A device that gets push: a Web Push subscription, or an FCM token. */
|
|
70
|
+
export const pushSubscriptionColumns = (refs) => ({
|
|
71
|
+
id: uuid('id').primaryKey().defaultRandom(),
|
|
72
|
+
organizationId: organizationId(refs),
|
|
73
|
+
recipientType: text('recipient_type').notNull(),
|
|
74
|
+
recipientId: text('recipient_id').notNull(),
|
|
75
|
+
/** 'webpush' or 'fcm'. */
|
|
76
|
+
kind: text('kind').notNull(),
|
|
77
|
+
/** The Web Push endpoint, or the FCM token. */
|
|
78
|
+
endpoint: text('endpoint').notNull(),
|
|
79
|
+
p256dh: text('p256dh'),
|
|
80
|
+
auth: text('auth'),
|
|
81
|
+
userAgent: text('user_agent'),
|
|
82
|
+
createdAt: timestamptz('created_at').notNull().defaultNow(),
|
|
83
|
+
lastUsedAt: timestamptz('last_used_at'),
|
|
84
|
+
});
|
|
85
|
+
export const pushSubscriptionIndexes = (t) => [
|
|
86
|
+
unique('push_subscriptions_org_endpoint_unique').on(t.organizationId, t.endpoint),
|
|
87
|
+
// Delivery reads a recipient's devices.
|
|
88
|
+
index('push_subscriptions_recipient_idx').on(t.organizationId, t.recipientType, t.recipientId),
|
|
89
|
+
];
|
|
90
|
+
//# sourceMappingURL=notification-columns.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notification-columns.js","sourceRoot":"","sources":["../src/notification-columns.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,EACL,OAAO,EACP,KAAK,EACL,KAAK,EACL,UAAU,EACV,IAAI,EACJ,SAAS,EACT,MAAM,EACN,WAAW,EACX,IAAI,GACL,MAAM,qBAAqB,CAAC;AAU7B,MAAM,cAAc,GAAG,CAAC,IAA4B,EAAE,EAAE,CACtD,I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AC,aAAa,EAAE;IAC3C,cAAc,EAAE,cAAc,CAAC,IAAI,CAAC;IACpC,aAAa,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC,OAAO,EAAE;IAC/C,WAAW,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC,OAAO,EAAE;IAC3C,0BAA0B;IAC1B,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE;IAC5B,+CAA+C;IAC/C,QAAQ,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,OAAO,EAAE;IACpC,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC;IACtB,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC;IAClB,SAAS,EAAE,IAAI,CAAC,YAAY,CAAC;IAC7B,SAAS,EAAE,WAAW,CAAC,YAAY,CAAC,CAAC,OAAO,EAAE,CAAC,UAAU,EAAE;IAC3D,UAAU,EAAE,WAAW,CAAC,cAAc,CAAC;CACxC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,CAKvC,EAAE,EAAE,CAAC;IACJ,MAAM,CAAC,wCAAwC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,cAAc,EAAE,CAAC,CAAC,QAAQ,CAAC;IACjF,wCAAwC;IACxC,KAAK,CAAC,kCAAkC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,cAAc,EAAE,CAAC,CAAC,aAAa,EAAE,CAAC,CAAC,WAAW,CAAC;CAC/F,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@haatlabs-core/db-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.0",
|
|
4
4
|
"description": "PostgreSQL and drizzle building blocks: shared columns, organizations, row-level security, audit logs.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"haatlabs",
|
|
@@ -55,13 +55,13 @@
|
|
|
55
55
|
"drizzle-orm": "^0.45.3",
|
|
56
56
|
"pg": "^8.23.1",
|
|
57
57
|
"testcontainers": "^12.2.0",
|
|
58
|
-
"@haatlabs-core/tsconfig": "0.
|
|
59
|
-
"@haatlabs-core/vitest-config": "0.
|
|
58
|
+
"@haatlabs-core/tsconfig": "0.21.0",
|
|
59
|
+
"@haatlabs-core/vitest-config": "0.21.0"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@haatlabs-core/errors": "0.
|
|
63
|
-
"@haatlabs-core/
|
|
64
|
-
"@haatlabs-core/
|
|
62
|
+
"@haatlabs-core/errors": "0.21.0",
|
|
63
|
+
"@haatlabs-core/queue": "0.21.0",
|
|
64
|
+
"@haatlabs-core/observability": "0.21.0"
|
|
65
65
|
},
|
|
66
66
|
"peerDependencies": {
|
|
67
67
|
"drizzle-orm": "^0.45.3",
|