@frigear-nu/push 0.0.0-stage → 0.1.1
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/module.d.mts +151 -0
- package/dist/module.json +9 -0
- package/dist/module.mjs +159 -0
- package/dist/runtime/access.d.ts +1 -0
- package/dist/runtime/access.js +16 -0
- package/dist/runtime/app/composables/usePushDevice.d.ts +24 -0
- package/dist/runtime/app/composables/usePushDevice.js +70 -0
- package/dist/runtime/app/pages/devices.d.vue.ts +3 -0
- package/dist/runtime/app/pages/devices.vue +104 -0
- package/dist/runtime/app/pages/devices.vue.d.ts +3 -0
- package/dist/runtime/app/plugins/push.client.d.ts +2 -0
- package/dist/runtime/app/plugins/push.client.js +16 -0
- package/dist/runtime/app/tabs/Devices.d.vue.ts +8 -0
- package/dist/runtime/app/tabs/Devices.vue +138 -0
- package/dist/runtime/app/tabs/Devices.vue.d.ts +8 -0
- package/dist/runtime/app/utils/device.d.ts +58 -0
- package/dist/runtime/app/utils/device.js +114 -0
- package/dist/runtime/app/utils/native.d.ts +75 -0
- package/dist/runtime/app/utils/native.js +61 -0
- package/dist/runtime/i18n/lang/da.json +71 -0
- package/dist/runtime/i18n/lang/en.json +71 -0
- package/dist/runtime/menus.d.ts +2 -0
- package/dist/runtime/menus.js +17 -0
- package/dist/runtime/providers/apns.d.ts +45 -0
- package/dist/runtime/providers/apns.js +75 -0
- package/dist/runtime/providers/config.d.ts +44 -0
- package/dist/runtime/providers/config.js +59 -0
- package/dist/runtime/providers/deliver.d.ts +35 -0
- package/dist/runtime/providers/deliver.js +52 -0
- package/dist/runtime/providers/fcm.d.ts +73 -0
- package/dist/runtime/providers/fcm.js +100 -0
- package/dist/runtime/providers/http2.d.ts +13 -0
- package/dist/runtime/providers/http2.js +74 -0
- package/dist/runtime/providers/types.d.ts +71 -0
- package/dist/runtime/providers/types.js +16 -0
- package/dist/runtime/server/db/schema.postgresql.d.ts +211 -0
- package/dist/runtime/server/db/schema.postgresql.js +26 -0
- package/dist/runtime/server/db/schema.sqlite.d.ts +225 -0
- package/dist/runtime/server/db/schema.sqlite.js +26 -0
- package/dist/runtime/server/notify-driver.d.ts +6 -0
- package/dist/runtime/server/notify-driver.js +10 -0
- package/dist/runtime/server/plugins/config-check.d.ts +2 -0
- package/dist/runtime/server/plugins/config-check.js +7 -0
- package/dist/runtime/server/policies.d.ts +1 -0
- package/dist/runtime/server/policies.js +1 -0
- package/dist/runtime/server/routes/admin/test.post.d.ts +2 -0
- package/dist/runtime/server/routes/admin/test.post.js +17 -0
- package/dist/runtime/server/routes/admin/user-devices.get.d.ts +2 -0
- package/dist/runtime/server/routes/admin/user-devices.get.js +4 -0
- package/dist/runtime/server/routes/me/device.delete.d.ts +2 -0
- package/dist/runtime/server/routes/me/device.delete.js +10 -0
- package/dist/runtime/server/routes/me/devices.get.d.ts +2 -0
- package/dist/runtime/server/routes/me/devices.get.js +4 -0
- package/dist/runtime/server/routes/me/devices.post.d.ts +2 -0
- package/dist/runtime/server/routes/me/devices.post.js +27 -0
- package/dist/runtime/server/routes/me/unregister.post.d.ts +2 -0
- package/dist/runtime/server/routes/me/unregister.post.js +9 -0
- package/dist/runtime/server/utils/push-devices.d.ts +32 -0
- package/dist/runtime/server/utils/push-devices.js +90 -0
- package/dist/runtime/server/utils/push-send.d.ts +32 -0
- package/dist/runtime/server/utils/push-send.js +79 -0
- package/dist/runtime/utils/api.d.ts +16 -0
- package/dist/runtime/utils/api.js +18 -0
- package/dist/runtime/utils/index.d.ts +4 -0
- package/dist/runtime/utils/index.js +2 -0
- package/dist/runtime/utils/provider.d.ts +7 -0
- package/dist/runtime/utils/provider.js +4 -0
- package/dist/types.d.mts +5 -0
- package/package.json +122 -3
- package/README.md +0 -3
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
export declare const pushDevices: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
2
|
+
name: "push_devices";
|
|
3
|
+
schema: undefined;
|
|
4
|
+
columns: {
|
|
5
|
+
id: import("drizzle-orm/pg-core").PgColumn<{
|
|
6
|
+
name: "id";
|
|
7
|
+
tableName: "push_devices";
|
|
8
|
+
dataType: "string";
|
|
9
|
+
columnType: "PgText";
|
|
10
|
+
data: string;
|
|
11
|
+
driverParam: string;
|
|
12
|
+
notNull: true;
|
|
13
|
+
hasDefault: false;
|
|
14
|
+
isPrimaryKey: true;
|
|
15
|
+
isAutoincrement: false;
|
|
16
|
+
hasRuntimeDefault: false;
|
|
17
|
+
enumValues: [string, ...string[]];
|
|
18
|
+
baseColumn: never;
|
|
19
|
+
identity: undefined;
|
|
20
|
+
generated: undefined;
|
|
21
|
+
}, {}, {}>;
|
|
22
|
+
userId: import("drizzle-orm/pg-core").PgColumn<{
|
|
23
|
+
name: "userId";
|
|
24
|
+
tableName: "push_devices";
|
|
25
|
+
dataType: "number";
|
|
26
|
+
columnType: "PgInteger";
|
|
27
|
+
data: number;
|
|
28
|
+
driverParam: string | number;
|
|
29
|
+
notNull: true;
|
|
30
|
+
hasDefault: false;
|
|
31
|
+
isPrimaryKey: false;
|
|
32
|
+
isAutoincrement: false;
|
|
33
|
+
hasRuntimeDefault: false;
|
|
34
|
+
enumValues: undefined;
|
|
35
|
+
baseColumn: never;
|
|
36
|
+
identity: undefined;
|
|
37
|
+
generated: undefined;
|
|
38
|
+
}, {}, {}>;
|
|
39
|
+
platform: import("drizzle-orm/pg-core").PgColumn<{
|
|
40
|
+
name: "platform";
|
|
41
|
+
tableName: "push_devices";
|
|
42
|
+
dataType: "string";
|
|
43
|
+
columnType: "PgText";
|
|
44
|
+
data: string;
|
|
45
|
+
driverParam: string;
|
|
46
|
+
notNull: true;
|
|
47
|
+
hasDefault: false;
|
|
48
|
+
isPrimaryKey: false;
|
|
49
|
+
isAutoincrement: false;
|
|
50
|
+
hasRuntimeDefault: false;
|
|
51
|
+
enumValues: [string, ...string[]];
|
|
52
|
+
baseColumn: never;
|
|
53
|
+
identity: undefined;
|
|
54
|
+
generated: undefined;
|
|
55
|
+
}, {}, {}>;
|
|
56
|
+
token: import("drizzle-orm/pg-core").PgColumn<{
|
|
57
|
+
name: "token";
|
|
58
|
+
tableName: "push_devices";
|
|
59
|
+
dataType: "string";
|
|
60
|
+
columnType: "PgText";
|
|
61
|
+
data: string;
|
|
62
|
+
driverParam: string;
|
|
63
|
+
notNull: true;
|
|
64
|
+
hasDefault: false;
|
|
65
|
+
isPrimaryKey: false;
|
|
66
|
+
isAutoincrement: false;
|
|
67
|
+
hasRuntimeDefault: false;
|
|
68
|
+
enumValues: [string, ...string[]];
|
|
69
|
+
baseColumn: never;
|
|
70
|
+
identity: undefined;
|
|
71
|
+
generated: undefined;
|
|
72
|
+
}, {}, {}>;
|
|
73
|
+
provider: import("drizzle-orm/pg-core").PgColumn<{
|
|
74
|
+
name: "provider";
|
|
75
|
+
tableName: "push_devices";
|
|
76
|
+
dataType: "string";
|
|
77
|
+
columnType: "PgText";
|
|
78
|
+
data: string;
|
|
79
|
+
driverParam: string;
|
|
80
|
+
notNull: false;
|
|
81
|
+
hasDefault: false;
|
|
82
|
+
isPrimaryKey: false;
|
|
83
|
+
isAutoincrement: false;
|
|
84
|
+
hasRuntimeDefault: false;
|
|
85
|
+
enumValues: [string, ...string[]];
|
|
86
|
+
baseColumn: never;
|
|
87
|
+
identity: undefined;
|
|
88
|
+
generated: undefined;
|
|
89
|
+
}, {}, {}>;
|
|
90
|
+
appId: import("drizzle-orm/pg-core").PgColumn<{
|
|
91
|
+
name: "appId";
|
|
92
|
+
tableName: "push_devices";
|
|
93
|
+
dataType: "string";
|
|
94
|
+
columnType: "PgText";
|
|
95
|
+
data: string;
|
|
96
|
+
driverParam: string;
|
|
97
|
+
notNull: false;
|
|
98
|
+
hasDefault: false;
|
|
99
|
+
isPrimaryKey: false;
|
|
100
|
+
isAutoincrement: false;
|
|
101
|
+
hasRuntimeDefault: false;
|
|
102
|
+
enumValues: [string, ...string[]];
|
|
103
|
+
baseColumn: never;
|
|
104
|
+
identity: undefined;
|
|
105
|
+
generated: undefined;
|
|
106
|
+
}, {}, {}>;
|
|
107
|
+
locale: import("drizzle-orm/pg-core").PgColumn<{
|
|
108
|
+
name: "locale";
|
|
109
|
+
tableName: "push_devices";
|
|
110
|
+
dataType: "string";
|
|
111
|
+
columnType: "PgText";
|
|
112
|
+
data: string;
|
|
113
|
+
driverParam: string;
|
|
114
|
+
notNull: false;
|
|
115
|
+
hasDefault: false;
|
|
116
|
+
isPrimaryKey: false;
|
|
117
|
+
isAutoincrement: false;
|
|
118
|
+
hasRuntimeDefault: false;
|
|
119
|
+
enumValues: [string, ...string[]];
|
|
120
|
+
baseColumn: never;
|
|
121
|
+
identity: undefined;
|
|
122
|
+
generated: undefined;
|
|
123
|
+
}, {}, {}>;
|
|
124
|
+
lastSeenAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
125
|
+
name: "lastSeenAt";
|
|
126
|
+
tableName: "push_devices";
|
|
127
|
+
dataType: "date";
|
|
128
|
+
columnType: "PgTimestamp";
|
|
129
|
+
data: Date;
|
|
130
|
+
driverParam: string;
|
|
131
|
+
notNull: true;
|
|
132
|
+
hasDefault: true;
|
|
133
|
+
isPrimaryKey: false;
|
|
134
|
+
isAutoincrement: false;
|
|
135
|
+
hasRuntimeDefault: true;
|
|
136
|
+
enumValues: undefined;
|
|
137
|
+
baseColumn: never;
|
|
138
|
+
identity: undefined;
|
|
139
|
+
generated: undefined;
|
|
140
|
+
}, {}, {}>;
|
|
141
|
+
createdAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
142
|
+
name: "createdAt";
|
|
143
|
+
tableName: "push_devices";
|
|
144
|
+
dataType: "date";
|
|
145
|
+
columnType: "PgTimestamp";
|
|
146
|
+
data: Date;
|
|
147
|
+
driverParam: string;
|
|
148
|
+
notNull: true;
|
|
149
|
+
hasDefault: true;
|
|
150
|
+
isPrimaryKey: false;
|
|
151
|
+
isAutoincrement: false;
|
|
152
|
+
hasRuntimeDefault: true;
|
|
153
|
+
enumValues: undefined;
|
|
154
|
+
baseColumn: never;
|
|
155
|
+
identity: undefined;
|
|
156
|
+
generated: undefined;
|
|
157
|
+
}, {}, {}>;
|
|
158
|
+
revokedAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
159
|
+
name: "revokedAt";
|
|
160
|
+
tableName: "push_devices";
|
|
161
|
+
dataType: "date";
|
|
162
|
+
columnType: "PgTimestamp";
|
|
163
|
+
data: Date;
|
|
164
|
+
driverParam: string;
|
|
165
|
+
notNull: false;
|
|
166
|
+
hasDefault: false;
|
|
167
|
+
isPrimaryKey: false;
|
|
168
|
+
isAutoincrement: false;
|
|
169
|
+
hasRuntimeDefault: false;
|
|
170
|
+
enumValues: undefined;
|
|
171
|
+
baseColumn: never;
|
|
172
|
+
identity: undefined;
|
|
173
|
+
generated: undefined;
|
|
174
|
+
}, {}, {}>;
|
|
175
|
+
secretHash: import("drizzle-orm/pg-core").PgColumn<{
|
|
176
|
+
name: "secretHash";
|
|
177
|
+
tableName: "push_devices";
|
|
178
|
+
dataType: "string";
|
|
179
|
+
columnType: "PgText";
|
|
180
|
+
data: string;
|
|
181
|
+
driverParam: string;
|
|
182
|
+
notNull: false;
|
|
183
|
+
hasDefault: false;
|
|
184
|
+
isPrimaryKey: false;
|
|
185
|
+
isAutoincrement: false;
|
|
186
|
+
hasRuntimeDefault: false;
|
|
187
|
+
enumValues: [string, ...string[]];
|
|
188
|
+
baseColumn: never;
|
|
189
|
+
identity: undefined;
|
|
190
|
+
generated: undefined;
|
|
191
|
+
}, {}, {}>;
|
|
192
|
+
failures: import("drizzle-orm/pg-core").PgColumn<{
|
|
193
|
+
name: "failures";
|
|
194
|
+
tableName: "push_devices";
|
|
195
|
+
dataType: "number";
|
|
196
|
+
columnType: "PgInteger";
|
|
197
|
+
data: number;
|
|
198
|
+
driverParam: string | number;
|
|
199
|
+
notNull: true;
|
|
200
|
+
hasDefault: true;
|
|
201
|
+
isPrimaryKey: false;
|
|
202
|
+
isAutoincrement: false;
|
|
203
|
+
hasRuntimeDefault: false;
|
|
204
|
+
enumValues: undefined;
|
|
205
|
+
baseColumn: never;
|
|
206
|
+
identity: undefined;
|
|
207
|
+
generated: undefined;
|
|
208
|
+
}, {}, {}>;
|
|
209
|
+
};
|
|
210
|
+
dialect: "pg";
|
|
211
|
+
}>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { pgTable, text, integer, timestamp, index } from "drizzle-orm/pg-core";
|
|
2
|
+
export const pushDevices = pgTable("push_devices", {
|
|
3
|
+
/** `psd_` + random id. */
|
|
4
|
+
id: text().primaryKey(),
|
|
5
|
+
userId: integer().notNull(),
|
|
6
|
+
/** `ios | android | web`. */
|
|
7
|
+
platform: text().notNull(),
|
|
8
|
+
/** The FCM registration token (android, and ios through FCM) or the APNs device token (ios through APNs). */
|
|
9
|
+
token: text().notNull().unique(),
|
|
10
|
+
/**
|
|
11
|
+
* `fcm | apns`: who issued the token, so where its pushes go. `null` for a row registered before the column existed:
|
|
12
|
+
* android is FCM and ios follows `push.ios`.
|
|
13
|
+
*/
|
|
14
|
+
provider: text(),
|
|
15
|
+
appId: text(),
|
|
16
|
+
locale: text(),
|
|
17
|
+
lastSeenAt: timestamp({ withTimezone: true }).notNull().$defaultFn(() => /* @__PURE__ */ new Date()),
|
|
18
|
+
createdAt: timestamp({ withTimezone: true }).notNull().$defaultFn(() => /* @__PURE__ */ new Date()),
|
|
19
|
+
revokedAt: timestamp({ withTimezone: true }),
|
|
20
|
+
/** SHA-256 (hex) of the installation secret the app generated; `null` for a row registered without one. */
|
|
21
|
+
secretHash: text(),
|
|
22
|
+
/** Pushes the provider refused for this device in a row (0 after a delivered one): revoked at the limit. */
|
|
23
|
+
failures: integer().notNull().default(0)
|
|
24
|
+
}, (t) => [
|
|
25
|
+
index("push_device_user_idx").on(t.userId)
|
|
26
|
+
]);
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
export declare const pushDevices: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
|
|
2
|
+
name: "push_devices";
|
|
3
|
+
schema: undefined;
|
|
4
|
+
columns: {
|
|
5
|
+
id: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
6
|
+
name: "id";
|
|
7
|
+
tableName: "push_devices";
|
|
8
|
+
dataType: "string";
|
|
9
|
+
columnType: "SQLiteText";
|
|
10
|
+
data: string;
|
|
11
|
+
driverParam: string;
|
|
12
|
+
notNull: true;
|
|
13
|
+
hasDefault: false;
|
|
14
|
+
isPrimaryKey: true;
|
|
15
|
+
isAutoincrement: false;
|
|
16
|
+
hasRuntimeDefault: false;
|
|
17
|
+
enumValues: [string, ...string[]];
|
|
18
|
+
baseColumn: never;
|
|
19
|
+
identity: undefined;
|
|
20
|
+
generated: undefined;
|
|
21
|
+
}, {}, {
|
|
22
|
+
length: undefined;
|
|
23
|
+
}>;
|
|
24
|
+
userId: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
25
|
+
name: "userId";
|
|
26
|
+
tableName: "push_devices";
|
|
27
|
+
dataType: "number";
|
|
28
|
+
columnType: "SQLiteInteger";
|
|
29
|
+
data: number;
|
|
30
|
+
driverParam: number;
|
|
31
|
+
notNull: true;
|
|
32
|
+
hasDefault: false;
|
|
33
|
+
isPrimaryKey: false;
|
|
34
|
+
isAutoincrement: false;
|
|
35
|
+
hasRuntimeDefault: false;
|
|
36
|
+
enumValues: undefined;
|
|
37
|
+
baseColumn: never;
|
|
38
|
+
identity: undefined;
|
|
39
|
+
generated: undefined;
|
|
40
|
+
}, {}, {}>;
|
|
41
|
+
platform: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
42
|
+
name: "platform";
|
|
43
|
+
tableName: "push_devices";
|
|
44
|
+
dataType: "string";
|
|
45
|
+
columnType: "SQLiteText";
|
|
46
|
+
data: string;
|
|
47
|
+
driverParam: string;
|
|
48
|
+
notNull: true;
|
|
49
|
+
hasDefault: false;
|
|
50
|
+
isPrimaryKey: false;
|
|
51
|
+
isAutoincrement: false;
|
|
52
|
+
hasRuntimeDefault: false;
|
|
53
|
+
enumValues: [string, ...string[]];
|
|
54
|
+
baseColumn: never;
|
|
55
|
+
identity: undefined;
|
|
56
|
+
generated: undefined;
|
|
57
|
+
}, {}, {
|
|
58
|
+
length: undefined;
|
|
59
|
+
}>;
|
|
60
|
+
token: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
61
|
+
name: "token";
|
|
62
|
+
tableName: "push_devices";
|
|
63
|
+
dataType: "string";
|
|
64
|
+
columnType: "SQLiteText";
|
|
65
|
+
data: string;
|
|
66
|
+
driverParam: string;
|
|
67
|
+
notNull: true;
|
|
68
|
+
hasDefault: false;
|
|
69
|
+
isPrimaryKey: false;
|
|
70
|
+
isAutoincrement: false;
|
|
71
|
+
hasRuntimeDefault: false;
|
|
72
|
+
enumValues: [string, ...string[]];
|
|
73
|
+
baseColumn: never;
|
|
74
|
+
identity: undefined;
|
|
75
|
+
generated: undefined;
|
|
76
|
+
}, {}, {
|
|
77
|
+
length: undefined;
|
|
78
|
+
}>;
|
|
79
|
+
provider: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
80
|
+
name: "provider";
|
|
81
|
+
tableName: "push_devices";
|
|
82
|
+
dataType: "string";
|
|
83
|
+
columnType: "SQLiteText";
|
|
84
|
+
data: string;
|
|
85
|
+
driverParam: string;
|
|
86
|
+
notNull: false;
|
|
87
|
+
hasDefault: false;
|
|
88
|
+
isPrimaryKey: false;
|
|
89
|
+
isAutoincrement: false;
|
|
90
|
+
hasRuntimeDefault: false;
|
|
91
|
+
enumValues: [string, ...string[]];
|
|
92
|
+
baseColumn: never;
|
|
93
|
+
identity: undefined;
|
|
94
|
+
generated: undefined;
|
|
95
|
+
}, {}, {
|
|
96
|
+
length: undefined;
|
|
97
|
+
}>;
|
|
98
|
+
appId: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
99
|
+
name: "appId";
|
|
100
|
+
tableName: "push_devices";
|
|
101
|
+
dataType: "string";
|
|
102
|
+
columnType: "SQLiteText";
|
|
103
|
+
data: string;
|
|
104
|
+
driverParam: string;
|
|
105
|
+
notNull: false;
|
|
106
|
+
hasDefault: false;
|
|
107
|
+
isPrimaryKey: false;
|
|
108
|
+
isAutoincrement: false;
|
|
109
|
+
hasRuntimeDefault: false;
|
|
110
|
+
enumValues: [string, ...string[]];
|
|
111
|
+
baseColumn: never;
|
|
112
|
+
identity: undefined;
|
|
113
|
+
generated: undefined;
|
|
114
|
+
}, {}, {
|
|
115
|
+
length: undefined;
|
|
116
|
+
}>;
|
|
117
|
+
locale: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
118
|
+
name: "locale";
|
|
119
|
+
tableName: "push_devices";
|
|
120
|
+
dataType: "string";
|
|
121
|
+
columnType: "SQLiteText";
|
|
122
|
+
data: string;
|
|
123
|
+
driverParam: string;
|
|
124
|
+
notNull: false;
|
|
125
|
+
hasDefault: false;
|
|
126
|
+
isPrimaryKey: false;
|
|
127
|
+
isAutoincrement: false;
|
|
128
|
+
hasRuntimeDefault: false;
|
|
129
|
+
enumValues: [string, ...string[]];
|
|
130
|
+
baseColumn: never;
|
|
131
|
+
identity: undefined;
|
|
132
|
+
generated: undefined;
|
|
133
|
+
}, {}, {
|
|
134
|
+
length: undefined;
|
|
135
|
+
}>;
|
|
136
|
+
lastSeenAt: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
137
|
+
name: "lastSeenAt";
|
|
138
|
+
tableName: "push_devices";
|
|
139
|
+
dataType: "date";
|
|
140
|
+
columnType: "SQLiteTimestamp";
|
|
141
|
+
data: Date;
|
|
142
|
+
driverParam: number;
|
|
143
|
+
notNull: true;
|
|
144
|
+
hasDefault: true;
|
|
145
|
+
isPrimaryKey: false;
|
|
146
|
+
isAutoincrement: false;
|
|
147
|
+
hasRuntimeDefault: true;
|
|
148
|
+
enumValues: undefined;
|
|
149
|
+
baseColumn: never;
|
|
150
|
+
identity: undefined;
|
|
151
|
+
generated: undefined;
|
|
152
|
+
}, {}, {}>;
|
|
153
|
+
createdAt: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
154
|
+
name: "createdAt";
|
|
155
|
+
tableName: "push_devices";
|
|
156
|
+
dataType: "date";
|
|
157
|
+
columnType: "SQLiteTimestamp";
|
|
158
|
+
data: Date;
|
|
159
|
+
driverParam: number;
|
|
160
|
+
notNull: true;
|
|
161
|
+
hasDefault: true;
|
|
162
|
+
isPrimaryKey: false;
|
|
163
|
+
isAutoincrement: false;
|
|
164
|
+
hasRuntimeDefault: true;
|
|
165
|
+
enumValues: undefined;
|
|
166
|
+
baseColumn: never;
|
|
167
|
+
identity: undefined;
|
|
168
|
+
generated: undefined;
|
|
169
|
+
}, {}, {}>;
|
|
170
|
+
revokedAt: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
171
|
+
name: "revokedAt";
|
|
172
|
+
tableName: "push_devices";
|
|
173
|
+
dataType: "date";
|
|
174
|
+
columnType: "SQLiteTimestamp";
|
|
175
|
+
data: Date;
|
|
176
|
+
driverParam: number;
|
|
177
|
+
notNull: false;
|
|
178
|
+
hasDefault: false;
|
|
179
|
+
isPrimaryKey: false;
|
|
180
|
+
isAutoincrement: false;
|
|
181
|
+
hasRuntimeDefault: false;
|
|
182
|
+
enumValues: undefined;
|
|
183
|
+
baseColumn: never;
|
|
184
|
+
identity: undefined;
|
|
185
|
+
generated: undefined;
|
|
186
|
+
}, {}, {}>;
|
|
187
|
+
secretHash: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
188
|
+
name: "secretHash";
|
|
189
|
+
tableName: "push_devices";
|
|
190
|
+
dataType: "string";
|
|
191
|
+
columnType: "SQLiteText";
|
|
192
|
+
data: string;
|
|
193
|
+
driverParam: string;
|
|
194
|
+
notNull: false;
|
|
195
|
+
hasDefault: false;
|
|
196
|
+
isPrimaryKey: false;
|
|
197
|
+
isAutoincrement: false;
|
|
198
|
+
hasRuntimeDefault: false;
|
|
199
|
+
enumValues: [string, ...string[]];
|
|
200
|
+
baseColumn: never;
|
|
201
|
+
identity: undefined;
|
|
202
|
+
generated: undefined;
|
|
203
|
+
}, {}, {
|
|
204
|
+
length: undefined;
|
|
205
|
+
}>;
|
|
206
|
+
failures: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
207
|
+
name: "failures";
|
|
208
|
+
tableName: "push_devices";
|
|
209
|
+
dataType: "number";
|
|
210
|
+
columnType: "SQLiteInteger";
|
|
211
|
+
data: number;
|
|
212
|
+
driverParam: number;
|
|
213
|
+
notNull: true;
|
|
214
|
+
hasDefault: true;
|
|
215
|
+
isPrimaryKey: false;
|
|
216
|
+
isAutoincrement: false;
|
|
217
|
+
hasRuntimeDefault: false;
|
|
218
|
+
enumValues: undefined;
|
|
219
|
+
baseColumn: never;
|
|
220
|
+
identity: undefined;
|
|
221
|
+
generated: undefined;
|
|
222
|
+
}, {}, {}>;
|
|
223
|
+
};
|
|
224
|
+
dialect: "sqlite";
|
|
225
|
+
}>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { sqliteTable, text, integer, index } from "drizzle-orm/sqlite-core";
|
|
2
|
+
export const pushDevices = sqliteTable("push_devices", {
|
|
3
|
+
/** `psd_` + random id. */
|
|
4
|
+
id: text().primaryKey(),
|
|
5
|
+
userId: integer().notNull(),
|
|
6
|
+
/** `ios | android | web`. */
|
|
7
|
+
platform: text().notNull(),
|
|
8
|
+
/** The FCM registration token (android, and ios through FCM) or the APNs device token (ios through APNs). */
|
|
9
|
+
token: text().notNull().unique(),
|
|
10
|
+
/**
|
|
11
|
+
* `fcm | apns`: who issued the token, so where its pushes go. `null` for a row registered before the column existed:
|
|
12
|
+
* android is FCM and ios follows `push.ios`.
|
|
13
|
+
*/
|
|
14
|
+
provider: text(),
|
|
15
|
+
appId: text(),
|
|
16
|
+
locale: text(),
|
|
17
|
+
lastSeenAt: integer({ mode: "timestamp" }).notNull().$defaultFn(() => /* @__PURE__ */ new Date()),
|
|
18
|
+
createdAt: integer({ mode: "timestamp" }).notNull().$defaultFn(() => /* @__PURE__ */ new Date()),
|
|
19
|
+
revokedAt: integer({ mode: "timestamp" }),
|
|
20
|
+
/** SHA-256 (hex) of the installation secret the app generated; `null` for a row registered without one. */
|
|
21
|
+
secretHash: text(),
|
|
22
|
+
/** Pushes the provider refused for this device in a row (0 after a delivered one): revoked at the limit. */
|
|
23
|
+
failures: integer().notNull().default(0)
|
|
24
|
+
}, (t) => [
|
|
25
|
+
index("push_device_user_idx").on(t.userId)
|
|
26
|
+
]);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { PushDispatchResult, PushNotification } from '@frigear-nu/notify/types';
|
|
2
|
+
/**
|
|
3
|
+
* The push driver of `@frigear-nu/notify` (`notify.push.driver`), which this module sets as notify's default: a
|
|
4
|
+
* `dispatchPushNotification` goes out through `sendPush`, FCM and APNs to the users' stored devices.
|
|
5
|
+
*/
|
|
6
|
+
export default function pushNotifyDriver(notification: PushNotification): Promise<PushDispatchResult>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { sendPush } from "./utils/push-send.js";
|
|
2
|
+
export default async function pushNotifyDriver(notification) {
|
|
3
|
+
return sendPush(void 0, {
|
|
4
|
+
userIds: notification.userIds,
|
|
5
|
+
title: notification.title,
|
|
6
|
+
body: notification.body,
|
|
7
|
+
...notification.url !== void 0 ? { url: notification.url } : {},
|
|
8
|
+
...notification.data !== void 0 ? { data: notification.data } : {}
|
|
9
|
+
});
|
|
10
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { pushConfigProblems } from "../../providers/config.js";
|
|
2
|
+
export default defineNitroPlugin(() => {
|
|
3
|
+
const problems = pushConfigProblems(useRuntimeConfig().push);
|
|
4
|
+
for (const problem of problems) {
|
|
5
|
+
console.error(`[@frigear-nu/push] Invalid push setting, pushes will fail until it is fixed: ${problem}`);
|
|
6
|
+
}
|
|
7
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const ownPushDevice: any;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const ownPushDevice = definePolicy("push:devices", ({ user, record }) => record.userId === Number(user.id));
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { db, schema } from "@nuxthub/db";
|
|
2
|
+
import { eq } from "drizzle-orm";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { notFound } from "@frigear-nu/module-kit/server";
|
|
5
|
+
const bodySchema = z.object({ userId: z.number().int().positive() });
|
|
6
|
+
export default defineEventHandler(async (event) => {
|
|
7
|
+
await authorize(event, "push:send");
|
|
8
|
+
const { userId } = await readValidatedBody(event, bodySchema.parse);
|
|
9
|
+
const [target] = await db.select().from(schema.users).where(eq(schema.users.id, userId)).limit(1);
|
|
10
|
+
if (!target) throw notFound("User not found.");
|
|
11
|
+
await authorize(event, "push:send", target);
|
|
12
|
+
return sendPush(event, {
|
|
13
|
+
userIds: [userId],
|
|
14
|
+
title: { da: "Testnotifikation", en: "Test notification" },
|
|
15
|
+
body: { da: "Kan du l\xE6se dette, virker pushnotifikationer p\xE5 denne enhed.", en: "If you can read this, push notifications reach this device." }
|
|
16
|
+
});
|
|
17
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { idParams, noContent, notFound } from "@frigear-nu/module-kit/server";
|
|
2
|
+
export default defineEventHandler(async (event) => {
|
|
3
|
+
const { user } = await authorize(event, "push:devices");
|
|
4
|
+
const { id } = await getValidatedRouterParams(event, idParams().parse);
|
|
5
|
+
const device = await findOwnPushDevice(user.id, id);
|
|
6
|
+
if (!device) throw notFound("Device not found.");
|
|
7
|
+
await authorize(event, "push:devices", device);
|
|
8
|
+
await removePushDevice(user.id, id);
|
|
9
|
+
return noContent(event);
|
|
10
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { created } from "@frigear-nu/module-kit/server";
|
|
3
|
+
const bodySchema = z.object({
|
|
4
|
+
platform: z.enum(["ios", "android"]),
|
|
5
|
+
token: z.string().trim().min(1).max(4096),
|
|
6
|
+
// Who issued the token. An iOS app that registers its FCM token sends `fcm`; unset is FCM on Android and `push.ios`
|
|
7
|
+
// on iOS. Android tokens are always FCM tokens.
|
|
8
|
+
provider: z.enum(["fcm", "apns"]).optional(),
|
|
9
|
+
// The token this installation registered before (its APNs token, once it registers its FCM token): removed.
|
|
10
|
+
replaces: z.string().trim().min(1).max(4096).optional(),
|
|
11
|
+
// The installation secret the app generated once (stored as a hash): needed to take over a token registered to
|
|
12
|
+
// another user (the phone changed hands), and for `replaces`.
|
|
13
|
+
secret: z.string().min(16).max(256).optional(),
|
|
14
|
+
appId: z.string().trim().min(1).max(255).optional(),
|
|
15
|
+
locale: z.string().trim().min(1).max(35).optional()
|
|
16
|
+
}).refine((body) => !(body.platform === "android" && body.provider === "apns"), {
|
|
17
|
+
message: "An Android device has an FCM token.",
|
|
18
|
+
path: ["provider"]
|
|
19
|
+
}).refine((body) => !body.replaces || body.secret, {
|
|
20
|
+
message: "Replacing a token needs the installation secret.",
|
|
21
|
+
path: ["secret"]
|
|
22
|
+
});
|
|
23
|
+
export default defineEventHandler(async (event) => {
|
|
24
|
+
const { user } = await authorize(event, "push:devices");
|
|
25
|
+
const body = await readValidatedBody(event, bodySchema.parse);
|
|
26
|
+
return created(event, await registerPushDevice(event, user.id, body));
|
|
27
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { noContent } from "@frigear-nu/module-kit/server";
|
|
3
|
+
const bodySchema = z.object({ token: z.string().trim().min(1).max(4096), secret: z.string().min(16).max(256) });
|
|
4
|
+
export default defineEventHandler(async (event) => {
|
|
5
|
+
const { user } = await authorize(event, "push:devices");
|
|
6
|
+
const { token, secret } = await readValidatedBody(event, bodySchema.parse);
|
|
7
|
+
await removePushDeviceByToken(user.id, token, secret);
|
|
8
|
+
return noContent(event);
|
|
9
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { schema } from '@nuxthub/db';
|
|
2
|
+
import type { H3Event } from 'h3';
|
|
3
|
+
import type { PushDeviceDto, RegisterDeviceInput } from '../../../types.js';
|
|
4
|
+
type DeviceRow = typeof schema.pushDevices.$inferSelect;
|
|
5
|
+
export declare function toPushDeviceDto(row: DeviceRow): PushDeviceDto;
|
|
6
|
+
/** SHA-256 (hex) of an installation secret: the only form it is stored in. */
|
|
7
|
+
export declare const hashPushInstallationSecret: (secret: string) => Promise<string>;
|
|
8
|
+
/**
|
|
9
|
+
* Registers a device for `userId`. Registering is idempotent: the same user registering the same token again (with or
|
|
10
|
+
* without the installation secret) keeps the row and makes it active again. The row is bound to the installation by
|
|
11
|
+
* `input.secret` (stored as a hash): a token that is registered to another user moves to this one only when the request
|
|
12
|
+
* carries the same secret (the phone changed hands); otherwise it answers 409 `device_owned` and nothing changes. The
|
|
13
|
+
* provider is stored resolved (what the device said, else FCM on Android and `push.ios` on iOS), and registering again
|
|
14
|
+
* updates it and clears `revokedAt` and the failure count. `input.replaces` is the token the installation registered
|
|
15
|
+
* before (its APNs token, now that it registers its FCM token): the caller's device with it is removed when it is bound
|
|
16
|
+
* to the same secret (or to none), so the installation is not notified twice. Fires `push:device:registered`.
|
|
17
|
+
*/
|
|
18
|
+
export declare function registerPushDevice(event: H3Event, userId: number, input: RegisterDeviceInput): Promise<PushDeviceDto>;
|
|
19
|
+
/** The user's active devices, newest first. */
|
|
20
|
+
export declare function listPushDevices(userId: number): Promise<PushDeviceDto[]>;
|
|
21
|
+
/** Every device of the user, revoked ones included, newest first (the staff view). */
|
|
22
|
+
export declare function listAllPushDevices(userId: number): Promise<PushDeviceDto[]>;
|
|
23
|
+
/** One of the user's own devices, or `undefined` (also for another user's device: nothing is revealed about it). */
|
|
24
|
+
export declare function findOwnPushDevice(userId: number, id: string): Promise<DeviceRow | undefined>;
|
|
25
|
+
/** Removes the user's device by id. */
|
|
26
|
+
export declare function removePushDevice(userId: number, id: string): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Removes the user's device by token, when `secret` is the installation secret it is bound to (or it is bound to none).
|
|
29
|
+
* A token that is unknown, belongs to someone else or is bound to another secret is ignored.
|
|
30
|
+
*/
|
|
31
|
+
export declare function removePushDeviceByToken(userId: number, token: string, secret: string): Promise<void>;
|
|
32
|
+
export {};
|