@roko-app/instant-admin 1.0.67-roko.1 → 1.0.67-roko.3
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/__tests__/src/alarms.test.ts +268 -0
- package/dist/commonjs/alarms.d.ts +138 -0
- package/dist/commonjs/alarms.d.ts.map +1 -0
- package/dist/commonjs/alarms.js +208 -0
- package/dist/commonjs/alarms.js.map +1 -0
- package/dist/commonjs/index.d.ts +4 -1
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +12 -1
- package/dist/commonjs/index.js.map +1 -1
- package/dist/esm/alarms.d.ts +138 -0
- package/dist/esm/alarms.d.ts.map +1 -0
- package/dist/esm/alarms.js +202 -0
- package/dist/esm/alarms.js.map +1 -0
- package/dist/esm/index.d.ts +4 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +11 -1
- package/dist/esm/index.js.map +1 -1
- package/package.json +4 -4
- package/src/alarms.ts +342 -0
- package/src/index.ts +28 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/** Where an alarm is in its life. */
|
|
2
|
+
export type AlarmStatus =
|
|
3
|
+
/** Waits for its time. */
|
|
4
|
+
'pending'
|
|
5
|
+
/** Being delivered right now. */
|
|
6
|
+
| 'processing'
|
|
7
|
+
/** A delivery failed; it will be retried. */
|
|
8
|
+
| 'error'
|
|
9
|
+
/** Delivered. */
|
|
10
|
+
| 'fired'
|
|
11
|
+
/** Gave up after the last retry, or the endpoint answered 410 Gone. */
|
|
12
|
+
| 'failed';
|
|
13
|
+
/** The last delivery attempt of an alarm. */
|
|
14
|
+
export type AlarmAttempt = {
|
|
15
|
+
/** When the attempt was made (ISO 8601). */
|
|
16
|
+
at: string | null;
|
|
17
|
+
/** True if the endpoint answered with a 2xx status. */
|
|
18
|
+
success: boolean;
|
|
19
|
+
/** HTTP status of the answer, if there was one. */
|
|
20
|
+
statusCode: number | null;
|
|
21
|
+
/** Kind of failure when there was no answer, e.g. `timeout` or `dns`. */
|
|
22
|
+
errorType: string | null;
|
|
23
|
+
errorMessage: string | null;
|
|
24
|
+
};
|
|
25
|
+
/** An alarm as the server stores it. */
|
|
26
|
+
export type AlarmInfo = {
|
|
27
|
+
/** Changes every time the key is set again; also the `Idempotency-Key` of its deliveries. */
|
|
28
|
+
id: string;
|
|
29
|
+
/** Your name for the alarm, unique per app. */
|
|
30
|
+
key: string;
|
|
31
|
+
/** When it fires (ISO 8601). */
|
|
32
|
+
fireAt: string;
|
|
33
|
+
/** The https url that is called. */
|
|
34
|
+
url: string;
|
|
35
|
+
/** Sent back to you, unchanged, when the alarm fires. */
|
|
36
|
+
payload: Record<string, unknown> | null;
|
|
37
|
+
status: AlarmStatus;
|
|
38
|
+
/** How many deliveries were attempted. */
|
|
39
|
+
attempts: number;
|
|
40
|
+
lastAttempt: AlarmAttempt | null;
|
|
41
|
+
/** When the next retry happens, while `status` is `error`. */
|
|
42
|
+
nextAttemptAfter: string | null;
|
|
43
|
+
firedAt: string | null;
|
|
44
|
+
createdAt: string;
|
|
45
|
+
updatedAt: string;
|
|
46
|
+
};
|
|
47
|
+
/** The body POSTed to the alarm's url when it fires. */
|
|
48
|
+
export type AlarmEvent = {
|
|
49
|
+
type: 'alarm';
|
|
50
|
+
id: string;
|
|
51
|
+
appId: string;
|
|
52
|
+
key: string;
|
|
53
|
+
/** The time the alarm was set for (ISO 8601). */
|
|
54
|
+
fireAt: string;
|
|
55
|
+
/** 1 for the first delivery, 2 for the first retry, and so on. */
|
|
56
|
+
attempt: number;
|
|
57
|
+
payload: Record<string, unknown> | null;
|
|
58
|
+
};
|
|
59
|
+
export type SetAlarmParams = {
|
|
60
|
+
/** Your name for the alarm. Setting the same key again replaces the alarm. */
|
|
61
|
+
key: string;
|
|
62
|
+
/** When to fire: a Date, milliseconds since the epoch, or an ISO 8601 string. A time in the past fires at once. */
|
|
63
|
+
fireAt: Date | number | string;
|
|
64
|
+
/** A public https url. It receives a POST signed with `Instant-Signature`. */
|
|
65
|
+
url: string;
|
|
66
|
+
/** A JSON object (64 KB at most) sent back to you when the alarm fires. */
|
|
67
|
+
payload?: Record<string, unknown> | null;
|
|
68
|
+
};
|
|
69
|
+
export type ListAlarmsParams = {
|
|
70
|
+
/** Keep one status only. */
|
|
71
|
+
status?: AlarmStatus;
|
|
72
|
+
/** Page size, 100 by default, 1000 at most. */
|
|
73
|
+
limit?: number;
|
|
74
|
+
/** Continue after this `fireAt` (the last alarm of the previous page). */
|
|
75
|
+
after?: Date | number | string;
|
|
76
|
+
};
|
|
77
|
+
export type AlarmValidateOpts = {
|
|
78
|
+
receivedAt?: Date | null;
|
|
79
|
+
/** Oldest signature accepted, in seconds. Default 300. */
|
|
80
|
+
tolerance?: number | null;
|
|
81
|
+
};
|
|
82
|
+
type AlarmsDeps = {
|
|
83
|
+
apiURI: string;
|
|
84
|
+
appId: string;
|
|
85
|
+
/** Builds the authorized request headers; throws without an admin token. */
|
|
86
|
+
headers: () => Record<string, string>;
|
|
87
|
+
jsonFetch: (input: string, init?: RequestInit) => Promise<unknown>;
|
|
88
|
+
/** Checks an `Instant-Signature` header and returns the verified body text. */
|
|
89
|
+
verifySignature: (signatureHeader: string, body: string | (() => Promise<string>), opts?: AlarmValidateOpts | null) => Promise<string>;
|
|
90
|
+
};
|
|
91
|
+
/** Reads a verified alarm body. Throws if it is not an alarm. */
|
|
92
|
+
export declare function parseAlarmEvent(bodyText: string): AlarmEvent;
|
|
93
|
+
/** Turns a Date / epoch milliseconds / ISO string into what the server takes. */
|
|
94
|
+
export declare function toAlarmTime(time: Date | number | string): number | string;
|
|
95
|
+
/**
|
|
96
|
+
* Alarms: ask the server to call your url at a given time.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* // When work starts, ask to be called if it is not done in one hour.
|
|
100
|
+
* await db.alarms.set({
|
|
101
|
+
* key: `effort:${taskId}`,
|
|
102
|
+
* fireAt: Date.now() + 60 * 60 * 1000,
|
|
103
|
+
* url: 'https://example.com/api/alarms',
|
|
104
|
+
* payload: { taskId },
|
|
105
|
+
* });
|
|
106
|
+
*
|
|
107
|
+
* // In the route behind that url.
|
|
108
|
+
* export async function POST(req: Request) {
|
|
109
|
+
* const alarm = await db.alarms.validateRequest(req);
|
|
110
|
+
* await pauseTask(alarm.payload);
|
|
111
|
+
* return new Response('ok');
|
|
112
|
+
* }
|
|
113
|
+
*/
|
|
114
|
+
export declare class Alarms {
|
|
115
|
+
#private;
|
|
116
|
+
constructor(deps: AlarmsDeps);
|
|
117
|
+
/**
|
|
118
|
+
* Creates the alarm for `key`, or replaces the one that exists. A replaced
|
|
119
|
+
* alarm starts over with a new id, even if it had already fired.
|
|
120
|
+
*/
|
|
121
|
+
set: (params: SetAlarmParams) => Promise<AlarmInfo>;
|
|
122
|
+
/** Returns the alarm for `key`, or null if there is none. */
|
|
123
|
+
get: (key: string) => Promise<AlarmInfo | null>;
|
|
124
|
+
/** Lists the app's alarms, soonest first. */
|
|
125
|
+
list: (params?: ListAlarmsParams) => Promise<AlarmInfo[]>;
|
|
126
|
+
/** Deletes the alarm for `key`. Returns false if there was none. */
|
|
127
|
+
delete: (key: string) => Promise<boolean>;
|
|
128
|
+
/**
|
|
129
|
+
* Verifies the `Instant-Signature` header of an alarm delivery against its
|
|
130
|
+
* raw body and returns the alarm. Throws if the signature is wrong or too
|
|
131
|
+
* old, if the body is not an alarm, or if the alarm belongs to another app.
|
|
132
|
+
*/
|
|
133
|
+
validate: (signatureHeader: string, body: string | (() => Promise<string>), opts?: AlarmValidateOpts | null) => Promise<AlarmEvent>;
|
|
134
|
+
/** Same as {@link validate}, reading the header and body from a `Request`. */
|
|
135
|
+
validateRequest: (req: Request, opts?: AlarmValidateOpts | null) => Promise<AlarmEvent>;
|
|
136
|
+
}
|
|
137
|
+
export {};
|
|
138
|
+
//# sourceMappingURL=alarms.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"alarms.d.ts","sourceRoot":"","sources":["../../src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ACvB,IAAI,EAAE,MAAM,GAAG,CAAC,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC,EACtC,IAAI,CAAC,EAAE,iBAAiB,GAAG,IAAI,KAC5B,OAAO,CAAC,MAAM,CAAC,CAAC;CACtB,CAAC;AA0EF,iEAAiE;AACjE,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,UAAU,CAgB5D;AAED,iFAAiF;AACjF,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CASzE;AAMD;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,MAAM;;gBAGL,IAAI,EAAE,UAAU;IAS5B;;;OAGG;IACH,GAAG,GAAU,QAAQ,cAAc,KAAG,OAAO,CAAC,SAAS,CAAC,CAYtD;IAEF,6DAA6D;IAC7D,GAAG,GAAU,KAAK,MAAM,KAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,CAOlD;IAEF,6CAA6C;IAC7C,IAAI,GAAU,SAAQ,gBAAqB,KAAG,OAAO,CAAC,SAAS,EAAE,CAAC,CAmBhE;IAEF,oEAAoE;IACpE,MAAM,GAAU,KAAK,MAAM,KAAG,OAAO,CAAC,OAAO,CAAC,CAM5C;IAEF;;;;OAIG;IACH,QAAQ,GACN,iBAAiB,MAAM,EACvB,MAAM,MAAM,GAAG,CAAC,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC,EACtC,OAAO,iBAAiB,GAAG,IAAI,KAC9B,OAAO,CAAC,UAAU,CAAC,CAapB;IAEF,8EAA8E;IAC9E,eAAe,GACb,KAAK,OAAO,EACZ,OAAO,iBAAiB,GAAG,IAAI,KAC9B,OAAO,CAAC,UAAU,CAAC,CAMpB;CACH"}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
// Roko DB: alarms. An alarm asks the server to POST a signed JSON body to a
|
|
2
|
+
// url at a given time. One alarm per key; setting a key again replaces it.
|
|
3
|
+
// #endregion
|
|
4
|
+
// #region Parsing
|
|
5
|
+
const ALARM_STATUSES = [
|
|
6
|
+
'pending',
|
|
7
|
+
'processing',
|
|
8
|
+
'error',
|
|
9
|
+
'fired',
|
|
10
|
+
'failed',
|
|
11
|
+
];
|
|
12
|
+
function isRecord(x) {
|
|
13
|
+
return typeof x === 'object' && x !== null && !Array.isArray(x);
|
|
14
|
+
}
|
|
15
|
+
function isAlarmStatus(x) {
|
|
16
|
+
return ALARM_STATUSES.some((status) => status === x);
|
|
17
|
+
}
|
|
18
|
+
function stringOrNull(x) {
|
|
19
|
+
return typeof x === 'string' ? x : null;
|
|
20
|
+
}
|
|
21
|
+
function numberOrNull(x) {
|
|
22
|
+
return typeof x === 'number' ? x : null;
|
|
23
|
+
}
|
|
24
|
+
function requiredString(source, field) {
|
|
25
|
+
const value = source[field];
|
|
26
|
+
if (typeof value !== 'string') {
|
|
27
|
+
throw new Error(`Invalid alarm: expected a string in \`${field}\`.`);
|
|
28
|
+
}
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
function parseAttempt(x) {
|
|
32
|
+
if (!isRecord(x)) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
at: stringOrNull(x.at),
|
|
37
|
+
success: x.success === true,
|
|
38
|
+
statusCode: numberOrNull(x.statusCode),
|
|
39
|
+
errorType: stringOrNull(x.errorType),
|
|
40
|
+
errorMessage: stringOrNull(x.errorMessage),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function parseAlarm(x) {
|
|
44
|
+
if (!isRecord(x)) {
|
|
45
|
+
throw new Error('Invalid alarm: expected an object.');
|
|
46
|
+
}
|
|
47
|
+
if (!isAlarmStatus(x.status)) {
|
|
48
|
+
throw new Error('Invalid alarm: unknown status.');
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
id: requiredString(x, 'id'),
|
|
52
|
+
key: requiredString(x, 'key'),
|
|
53
|
+
fireAt: requiredString(x, 'fireAt'),
|
|
54
|
+
url: requiredString(x, 'url'),
|
|
55
|
+
payload: isRecord(x.payload) ? x.payload : null,
|
|
56
|
+
status: x.status,
|
|
57
|
+
attempts: numberOrNull(x.attempts) ?? 0,
|
|
58
|
+
lastAttempt: parseAttempt(x.lastAttempt),
|
|
59
|
+
nextAttemptAfter: stringOrNull(x.nextAttemptAfter),
|
|
60
|
+
firedAt: stringOrNull(x.firedAt),
|
|
61
|
+
createdAt: requiredString(x, 'createdAt'),
|
|
62
|
+
updatedAt: requiredString(x, 'updatedAt'),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/** Reads a verified alarm body. Throws if it is not an alarm. */
|
|
66
|
+
export function parseAlarmEvent(bodyText) {
|
|
67
|
+
const body = JSON.parse(bodyText);
|
|
68
|
+
if (!isRecord(body) || body.type !== 'alarm') {
|
|
69
|
+
throw new Error('Invalid alarm body, expected an object with type "alarm".');
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
type: 'alarm',
|
|
73
|
+
id: requiredString(body, 'id'),
|
|
74
|
+
appId: requiredString(body, 'appId'),
|
|
75
|
+
key: requiredString(body, 'key'),
|
|
76
|
+
fireAt: requiredString(body, 'fireAt'),
|
|
77
|
+
attempt: numberOrNull(body.attempt) ?? 1,
|
|
78
|
+
payload: isRecord(body.payload) ? body.payload : null,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/** Turns a Date / epoch milliseconds / ISO string into what the server takes. */
|
|
82
|
+
export function toAlarmTime(time) {
|
|
83
|
+
if (time instanceof Date) {
|
|
84
|
+
const ms = time.getTime();
|
|
85
|
+
if (Number.isNaN(ms)) {
|
|
86
|
+
throw new Error('Invalid alarm time: the Date is not valid.');
|
|
87
|
+
}
|
|
88
|
+
return ms;
|
|
89
|
+
}
|
|
90
|
+
return time;
|
|
91
|
+
}
|
|
92
|
+
// #endregion
|
|
93
|
+
// #region Alarms
|
|
94
|
+
/**
|
|
95
|
+
* Alarms: ask the server to call your url at a given time.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* // When work starts, ask to be called if it is not done in one hour.
|
|
99
|
+
* await db.alarms.set({
|
|
100
|
+
* key: `effort:${taskId}`,
|
|
101
|
+
* fireAt: Date.now() + 60 * 60 * 1000,
|
|
102
|
+
* url: 'https://example.com/api/alarms',
|
|
103
|
+
* payload: { taskId },
|
|
104
|
+
* });
|
|
105
|
+
*
|
|
106
|
+
* // In the route behind that url.
|
|
107
|
+
* export async function POST(req: Request) {
|
|
108
|
+
* const alarm = await db.alarms.validateRequest(req);
|
|
109
|
+
* await pauseTask(alarm.payload);
|
|
110
|
+
* return new Response('ok');
|
|
111
|
+
* }
|
|
112
|
+
*/
|
|
113
|
+
export class Alarms {
|
|
114
|
+
#deps;
|
|
115
|
+
constructor(deps) {
|
|
116
|
+
this.#deps = deps;
|
|
117
|
+
}
|
|
118
|
+
#url(query) {
|
|
119
|
+
const qs = new URLSearchParams({ app_id: this.#deps.appId, ...query });
|
|
120
|
+
return `${this.#deps.apiURI}/admin/alarms?${qs.toString()}`;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Creates the alarm for `key`, or replaces the one that exists. A replaced
|
|
124
|
+
* alarm starts over with a new id, even if it had already fired.
|
|
125
|
+
*/
|
|
126
|
+
set = async (params) => {
|
|
127
|
+
const res = await this.#deps.jsonFetch(this.#url(), {
|
|
128
|
+
method: 'PUT',
|
|
129
|
+
headers: this.#deps.headers(),
|
|
130
|
+
body: JSON.stringify({
|
|
131
|
+
key: params.key,
|
|
132
|
+
fireAt: toAlarmTime(params.fireAt),
|
|
133
|
+
url: params.url,
|
|
134
|
+
payload: params.payload ?? null,
|
|
135
|
+
}),
|
|
136
|
+
});
|
|
137
|
+
return parseAlarm(isRecord(res) ? res.alarm : null);
|
|
138
|
+
};
|
|
139
|
+
/** Returns the alarm for `key`, or null if there is none. */
|
|
140
|
+
get = async (key) => {
|
|
141
|
+
const res = await this.#deps.jsonFetch(this.#url({ key }), {
|
|
142
|
+
method: 'GET',
|
|
143
|
+
headers: this.#deps.headers(),
|
|
144
|
+
});
|
|
145
|
+
const alarm = isRecord(res) ? res.alarm : null;
|
|
146
|
+
return alarm == null ? null : parseAlarm(alarm);
|
|
147
|
+
};
|
|
148
|
+
/** Lists the app's alarms, soonest first. */
|
|
149
|
+
list = async (params = {}) => {
|
|
150
|
+
const query = {};
|
|
151
|
+
if (params.status) {
|
|
152
|
+
query.status = params.status;
|
|
153
|
+
}
|
|
154
|
+
if (params.limit !== undefined) {
|
|
155
|
+
query.limit = String(params.limit);
|
|
156
|
+
}
|
|
157
|
+
if (params.after !== undefined) {
|
|
158
|
+
const after = toAlarmTime(params.after);
|
|
159
|
+
query.after =
|
|
160
|
+
typeof after === 'number' ? new Date(after).toISOString() : after;
|
|
161
|
+
}
|
|
162
|
+
const res = await this.#deps.jsonFetch(this.#url(query), {
|
|
163
|
+
method: 'GET',
|
|
164
|
+
headers: this.#deps.headers(),
|
|
165
|
+
});
|
|
166
|
+
const alarms = isRecord(res) ? res.alarms : null;
|
|
167
|
+
return Array.isArray(alarms) ? alarms.map(parseAlarm) : [];
|
|
168
|
+
};
|
|
169
|
+
/** Deletes the alarm for `key`. Returns false if there was none. */
|
|
170
|
+
delete = async (key) => {
|
|
171
|
+
const res = await this.#deps.jsonFetch(this.#url({ key }), {
|
|
172
|
+
method: 'DELETE',
|
|
173
|
+
headers: this.#deps.headers(),
|
|
174
|
+
});
|
|
175
|
+
return isRecord(res) && res.deleted === true;
|
|
176
|
+
};
|
|
177
|
+
/**
|
|
178
|
+
* Verifies the `Instant-Signature` header of an alarm delivery against its
|
|
179
|
+
* raw body and returns the alarm. Throws if the signature is wrong or too
|
|
180
|
+
* old, if the body is not an alarm, or if the alarm belongs to another app.
|
|
181
|
+
*/
|
|
182
|
+
validate = async (signatureHeader, body, opts) => {
|
|
183
|
+
const bodyText = await this.#deps.verifySignature(signatureHeader, body, opts);
|
|
184
|
+
const event = parseAlarmEvent(bodyText);
|
|
185
|
+
// The signing key is the server's, shared by every app on it: without
|
|
186
|
+
// this check another app could aim its own alarm at this endpoint.
|
|
187
|
+
if (event.appId !== this.#deps.appId) {
|
|
188
|
+
throw new Error('Alarm belongs to another app');
|
|
189
|
+
}
|
|
190
|
+
return event;
|
|
191
|
+
};
|
|
192
|
+
/** Same as {@link validate}, reading the header and body from a `Request`. */
|
|
193
|
+
validateRequest = async (req, opts) => {
|
|
194
|
+
const signatureHeader = req.headers.get('instant-signature');
|
|
195
|
+
if (!signatureHeader) {
|
|
196
|
+
throw new Error('Request is missing Instant-Signature header');
|
|
197
|
+
}
|
|
198
|
+
return this.validate(signatureHeader, () => req.text(), opts);
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
// #endregion
|
|
202
|
+
//# sourceMappingURL=alarms.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"alarms.js","sourceRoot":"","sources":["../../src/alarms.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,2EAA2E;AA0G3E,aAAa;AAEb,kBAAkB;AAElB,MAAM,cAAc,GAA2B;IAC7C,SAAS;IACT,YAAY;IACZ,OAAO;IACP,OAAO;IACP,QAAQ;CACT,CAAC;AAEF,SAAS,QAAQ,CAAC,CAAU;IAC1B,OAAO,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AAClE,CAAC;AAED,SAAS,aAAa,CAAC,CAAU;IAC/B,OAAO,cAAc,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC;AACvD,CAAC;AAED,SAAS,YAAY,CAAC,CAAU;IAC9B,OAAO,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAC1C,CAAC;AAED,SAAS,YAAY,CAAC,CAAU;IAC9B,OAAO,OAAO,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AC,QAAQ,CAAC,CAAC;QACxC,sEAAsE;QACtE,mEAAmE;QACnE,IAAI,KAAK,CAAC,KAAK,KAAK,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;YACrC,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;QAClD,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;IAEF,8EAA8E;IAC9E,eAAe,GAAG,KAAK,EACrB,GAAY,EACZ,IAA+B,EACV,EAAE;QACvB,MAAM,eAAe,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;QAC7D,IAAI,CAAC,eAAe,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;QACjE,CAAC;QACD,OAAO,IAAI,CAAC,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,IAAI,CAAC,CAAC;IAChE,CAAC,CAAC;CACH;AAED,aAAa","sourcesContent":["// Roko DB: alarms. An alarm asks the server to POST a signed JSON body to a\n// url at a given time. One alarm per key; setting a key again replaces it.\n\n// #region Types\n\n/** Where an alarm is in its life. */\nexport type AlarmStatus =\n /** Waits for its time. */\n | 'pending'\n /** Being delivered right now. */\n | 'processing'\n /** A delivery failed; it will be retried. */\n | 'error'\n /** Delivered. */\n | 'fired'\n /** Gave up after the last retry, or the endpoint answered 410 Gone. */\n | 'failed';\n\n/** The last delivery attempt of an alarm. */\nexport type AlarmAttempt = {\n /** When the attempt was made (ISO 8601). */\n at: string | null;\n /** True if the endpoint answered with a 2xx status. */\n success: boolean;\n /** HTTP status of the answer, if there was one. */\n statusCode: number | null;\n /** Kind of failure when there was no answer, e.g. `timeout` or `dns`. */\n errorType: string | null;\n errorMessage: string | null;\n};\n\n/** An alarm as the server stores it. */\nexport type AlarmInfo = {\n /** Changes every time the key is set again; also the `Idempotency-Key` of its deliveries. */\n id: string;\n /** Your name for the alarm, unique per app. */\n key: string;\n /** When it fires (ISO 8601). */\n fireAt: string;\n /** The https url that is called. */\n url: string;\n /** Sent back to you, unchanged, when the alarm fires. */\n payload: Record<string, unknown> | null;\n status: AlarmStatus;\n /** How many deliveries were attempted. */\n attempts: number;\n lastAttempt: AlarmAttempt | null;\n /** When the next retry happens, while `status` is `error`. */\n nextAttemptAfter: string | null;\n firedAt: string | null;\n createdAt: string;\n updatedAt: string;\n};\n\n/** The body POSTed to the alarm's url when it fires. */\nexport type AlarmEvent = {\n type: 'alarm';\n id: string;\n appId: string;\n key: string;\n /** The time the alarm was set for (ISO 8601). */\n fireAt: string;\n /** 1 for the first delivery, 2 for the first retry, and so on. */\n attempt: number;\n payload: Record<string, unknown> | null;\n};\n\nexport type SetAlarmParams = {\n /** Your name for the alarm. Setting the same key again replaces the alarm. */\n key: string;\n /** When to fire: a Date, milliseconds since the epoch, or an ISO 8601 string. A time in the past fires at once. */\n fireAt: Date | number | string;\n /** A public https url. It receives a POST signed with `Instant-Signature`. */\n url: string;\n /** A JSON object (64 KB at most) sent back to you when the alarm fires. */\n payload?: Record<string, unknown> | null;\n};\n\nexport type ListAlarmsParams = {\n /** Keep one status only. */\n status?: AlarmStatus;\n /** Page size, 100 by default, 1000 at most. */\n limit?: number;\n /** Continue after this `fireAt` (the last alarm of the previous page). */\n after?: Date | number | string;\n};\n\nexport type AlarmValidateOpts = {\n receivedAt?: Date | null;\n /** Oldest signature accepted, in seconds. Default 300. */\n tolerance?: number | null;\n};\n\ntype AlarmsDeps = {\n apiURI: string;\n appId: string;\n /** Builds the authorized request headers; throws without an admin token. */\n headers: () => Record<string, string>;\n jsonFetch: (input: string, init?: RequestInit) => Promise<unknown>;\n /** Checks an `Instant-Signature` header and returns the verified body text. */\n verifySignature: (\n signatureHeader: string,\n body: string | (() => Promise<string>),\n opts?: AlarmValidateOpts | null,\n ) => Promise<string>;\n};\n\n// #endregion\n\n// #region Parsing\n\nconst ALARM_STATUSES: readonly AlarmStatus[] = [\n 'pending',\n 'processing',\n 'error',\n 'fired',\n 'failed',\n];\n\nfunction isRecord(x: unknown): x is Record<string, unknown> {\n return typeof x === 'object' && x !== null && !Array.isArray(x);\n}\n\nfunction isAlarmStatus(x: unknown): x is AlarmStatus {\n return ALARM_STATUSES.some((status) => status === x);\n}\n\nfunction stringOrNull(x: unknown): string | null {\n return typeof x === 'string' ? x : null;\n}\n\nfunction numberOrNull(x: unknown): number | null {\n return typeof x === 'number' ? x : null;\n}\n\nfunction requiredString(source: Record<string, unknown>, field: string) {\n const value = source[field];\n if (typeof value !== 'string') {\n throw new Error(`Invalid alarm: expected a string in \\`${field}\\`.`);\n }\n return value;\n}\n\nfunction parseAttempt(x: unknown): AlarmAttempt | null {\n if (!isRecord(x)) {\n return null;\n }\n return {\n at: stringOrNull(x.at),\n success: x.success === true,\n statusCode: numberOrNull(x.statusCode),\n errorType: stringOrNull(x.errorType),\n errorMessage: stringOrNull(x.errorMessage),\n };\n}\n\nfunction parseAlarm(x: unknown): AlarmInfo {\n if (!isRecord(x)) {\n throw new Error('Invalid alarm: expected an object.');\n }\n if (!isAlarmStatus(x.status)) {\n throw new Error('Invalid alarm: unknown status.');\n }\n return {\n id: requiredString(x, 'id'),\n key: requiredString(x, 'key'),\n fireAt: requiredString(x, 'fireAt'),\n url: requiredString(x, 'url'),\n payload: isRecord(x.payload) ? x.payload : null,\n status: x.status,\n attempts: numberOrNull(x.attempts) ?? 0,\n lastAttempt: parseAttempt(x.lastAttempt),\n nextAttemptAfter: stringOrNull(x.nextAttemptAfter),\n firedAt: stringOrNull(x.firedAt),\n createdAt: requiredString(x, 'createdAt'),\n updatedAt: requiredString(x, 'updatedAt'),\n };\n}\n\n/** Reads a verified alarm body. Throws if it is not an alarm. */\nexport function parseAlarmEvent(bodyText: string): AlarmEvent {\n const body: unknown = JSON.parse(bodyText);\n if (!isRecord(body) || body.type !== 'alarm') {\n throw new Error(\n 'Invalid alarm body, expected an object with type \"alarm\".',\n );\n }\n return {\n type: 'alarm',\n id: requiredString(body, 'id'),\n appId: requiredString(body, 'appId'),\n key: requiredString(body, 'key'),\n fireAt: requiredString(body, 'fireAt'),\n attempt: numberOrNull(body.attempt) ?? 1,\n payload: isRecord(body.payload) ? body.payload : null,\n };\n}\n\n/** Turns a Date / epoch milliseconds / ISO string into what the server takes. */\nexport function toAlarmTime(time: Date | number | string): number | string {\n if (time instanceof Date) {\n const ms = time.getTime();\n if (Number.isNaN(ms)) {\n throw new Error('Invalid alarm time: the Date is not valid.');\n }\n return ms;\n }\n return time;\n}\n\n// #endregion\n\n// #region Alarms\n\n/**\n * Alarms: ask the server to call your url at a given time.\n *\n * @example\n * // When work starts, ask to be called if it is not done in one hour.\n * await db.alarms.set({\n * key: `effort:${taskId}`,\n * fireAt: Date.now() + 60 * 60 * 1000,\n * url: 'https://example.com/api/alarms',\n * payload: { taskId },\n * });\n *\n * // In the route behind that url.\n * export async function POST(req: Request) {\n * const alarm = await db.alarms.validateRequest(req);\n * await pauseTask(alarm.payload);\n * return new Response('ok');\n * }\n */\nexport class Alarms {\n #deps: AlarmsDeps;\n\n constructor(deps: AlarmsDeps) {\n this.#deps = deps;\n }\n\n #url(query?: Record<string, string>): string {\n const qs = new URLSearchParams({ app_id: this.#deps.appId, ...query });\n return `${this.#deps.apiURI}/admin/alarms?${qs.toString()}`;\n }\n\n /**\n * Creates the alarm for `key`, or replaces the one that exists. A replaced\n * alarm starts over with a new id, even if it had already fired.\n */\n set = async (params: SetAlarmParams): Promise<AlarmInfo> => {\n const res = await this.#deps.jsonFetch(this.#url(), {\n method: 'PUT',\n headers: this.#deps.headers(),\n body: JSON.stringify({\n key: params.key,\n fireAt: toAlarmTime(params.fireAt),\n url: params.url,\n payload: params.payload ?? null,\n }),\n });\n return parseAlarm(isRecord(res) ? res.alarm : null);\n };\n\n /** Returns the alarm for `key`, or null if there is none. */\n get = async (key: string): Promise<AlarmInfo | null> => {\n const res = await this.#deps.jsonFetch(this.#url({ key }), {\n method: 'GET',\n headers: this.#deps.headers(),\n });\n const alarm = isRecord(res) ? res.alarm : null;\n return alarm == null ? null : parseAlarm(alarm);\n };\n\n /** Lists the app's alarms, soonest first. */\n list = async (params: ListAlarmsParams = {}): Promise<AlarmInfo[]> => {\n const query: Record<string, string> = {};\n if (params.status) {\n query.status = params.status;\n }\n if (params.limit !== undefined) {\n query.limit = String(params.limit);\n }\n if (params.after !== undefined) {\n const after = toAlarmTime(params.after);\n query.after =\n typeof after === 'number' ? new Date(after).toISOString() : after;\n }\n const res = await this.#deps.jsonFetch(this.#url(query), {\n method: 'GET',\n headers: this.#deps.headers(),\n });\n const alarms = isRecord(res) ? res.alarms : null;\n return Array.isArray(alarms) ? alarms.map(parseAlarm) : [];\n };\n\n /** Deletes the alarm for `key`. Returns false if there was none. */\n delete = async (key: string): Promise<boolean> => {\n const res = await this.#deps.jsonFetch(this.#url({ key }), {\n method: 'DELETE',\n headers: this.#deps.headers(),\n });\n return isRecord(res) && res.deleted === true;\n };\n\n /**\n * Verifies the `Instant-Signature` header of an alarm delivery against its\n * raw body and returns the alarm. Throws if the signature is wrong or too\n * old, if the body is not an alarm, or if the alarm belongs to another app.\n */\n validate = async (\n signatureHeader: string,\n body: string | (() => Promise<string>),\n opts?: AlarmValidateOpts | null,\n ): Promise<AlarmEvent> => {\n const bodyText = await this.#deps.verifySignature(\n signatureHeader,\n body,\n opts,\n );\n const event = parseAlarmEvent(bodyText);\n // The signing key is the server's, shared by every app on it: without\n // this check another app could aim its own alarm at this endpoint.\n if (event.appId !== this.#deps.appId) {\n throw new Error('Alarm belongs to another app');\n }\n return event;\n };\n\n /** Same as {@link validate}, reading the header and body from a `Request`. */\n validateRequest = async (\n req: Request,\n opts?: AlarmValidateOpts | null,\n ): Promise<AlarmEvent> => {\n const signatureHeader = req.headers.get('instant-signature');\n if (!signatureHeader) {\n throw new Error('Request is missing Instant-Signature header');\n }\n return this.validate(signatureHeader, () => req.text(), opts);\n };\n}\n\n// #endregion\n"]}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Readable } from 'node:stream';
|
|
2
2
|
import { tx, lookup, i, id, InstantAPIError, setInstantWarningsEnabled, type InstantIssue, type TransactionChunk, type AuthToken, type User, type Query, InstantError, type QueryResponse, type InstaQLResponse, type InstaQLParams, type ValidQuery, type InstaQLFields, type InstantQuery, type InstantQueryResult, type InstantSchema, type InstantSchemaDatabase, type InstantObject, type InstantEntity, type BackwardsCompatibleSchema, type IInstantDatabase, type AttrsDefs, type CardinalityKind, type DataAttrDef, type EntitiesDef, type EntitiesWithLinks, type EntityDef, type InstantGraph, type LinkAttrDef, type LinkDef, type InstantUnknownSchemaDef, type LinksDef, type RoomsOf, type RoomsDef, type PresenceOf, type RoomHandle, type ResolveAttrs, type ValueTypes, type InstantSchemaDef, type InstantUnknownSchema, type InstaQLEntity, type InstaQLResult, type InstaQLEntitySubquery, type InstantRules, type UpdateParams, type CreateParams, type LinkParams, type RuleParams, type FileOpts, type UploadFileResponse, type DeleteFileResponse, createInstantRouteHandler, type InstantRouteHandlerPayloadByType, type InstantRouteHandlerType, type InstantRouteHandlerBody, InstantStream, type WritableStreamCtor, type ReadableStreamCtor, InstantWritableStream, InstantReadableStream, type Logger } from '@instantdb/core';
|
|
3
3
|
import { SubscribeQueryCallback, SubscribeQueryResponse, SubscribeQueryPayload, SubscriptionReadyState } from './subscribe.ts';
|
|
4
|
+
import { Alarms, type AlarmStatus, type AlarmAttempt, type AlarmInfo, type AlarmEvent, type SetAlarmParams, type ListAlarmsParams, type AlarmValidateOpts } from './alarms.ts';
|
|
4
5
|
import { Webhooks, WebhooksManager, type WebhookAction, type WebhookStatus, type WebhookEventStatus, type WebhookInfo, type WebhookAttempt, type WebhookEventInfo, type WebhookEventsPage, type WebhookBody, type WebhookEntity, type WebhookPayload, type WebhookPayloadRecord, type WebhookPayloadRecordFor, type WebhookHandlerFn, type WebhookHandlers, type WebhookHelpers, type CreateWebhookParams, type UpdateWebhookParams } from '@instantdb/webhooks';
|
|
5
6
|
type DebugCheckResult = {
|
|
6
7
|
/** The ID of the record. */
|
|
@@ -459,6 +460,8 @@ declare class InstantAdminDatabase<Schema extends InstantSchemaDef<any, any, any
|
|
|
459
460
|
rooms: Rooms<Schema>;
|
|
460
461
|
impersonationOpts?: ImpersonationOpts;
|
|
461
462
|
webhooks: Webhooks<Schema>;
|
|
463
|
+
/** Roko DB: ask the server to call your url at a given time. */
|
|
464
|
+
alarms: Alarms;
|
|
462
465
|
tx: import("@instantdb/core").TxChunk<NonNullable<Schema>>;
|
|
463
466
|
constructor(_config: Config);
|
|
464
467
|
/**
|
|
@@ -604,5 +607,5 @@ declare class InstantAdminDatabase<Schema extends InstantSchemaDef<any, any, any
|
|
|
604
607
|
origin?: string | null | undefined;
|
|
605
608
|
}) => Promise<DebugTransactResult>;
|
|
606
609
|
}
|
|
607
|
-
export { init, init_experimental, id, tx, lookup, i, createInstantRouteHandler, type InstantRouteHandlerPayloadByType, type InstantRouteHandlerType, type InstantRouteHandlerBody, Webhooks, WebhooksManager, type WebhookAction, type WebhookStatus, type WebhookEventStatus, type WebhookInfo, type WebhookAttempt, type WebhookEventInfo, type WebhookEventsPage, type WebhookBody, type WebhookEntity, type WebhookPayload, type WebhookPayloadRecord, type WebhookPayloadRecordFor, type WebhookHandlerFn, type WebhookHandlers, type WebhookHelpers, type CreateWebhookParams, type UpdateWebhookParams, InstantAPIError, setInstantWarningsEnabled, type Config, type ImpersonationOpts, type TransactionChunk, type DebugCheckResult, type InstantAdminDatabase, type User, type InstaQLParams, type ValidQuery, type Query, InstantError, type QueryResponse, type InstaQLResponse, type InstantQuery, type InstantUnknownSchemaDef, type InstantQueryResult, type InstantSchema, type InstantSchemaDatabase, type IInstantDatabase, type InstantObject, type InstantEntity, type BackwardsCompatibleSchema, type InstaQLFields, type SubscribeQueryCallback, type SubscribeQueryResponse, type SubscribeQueryPayload, type SubscriptionReadyState, type AttrsDefs, type CardinalityKind, type DataAttrDef, type EntitiesDef, type EntitiesWithLinks, type EntityDef, type InstantGraph, type LinkAttrDef, type LinkDef, type LinksDef, type ResolveAttrs, type RoomsOf, type PresenceOf, type RoomsDef, type RoomHandle, type ValueTypes, type InstantSchemaDef, type InstantUnknownSchema, type InstaQLEntity, type InstaQLResult, type InstaQLEntitySubquery, type InstantRules, type CreateParams, type UpdateParams, type LinkParams, type FileOpts, type UploadFileResponse, type DeleteFileResponse, type DeleteManyFileResponse, type CreateReadStreamOpts, type CreateWriteStreamOpts, type InstantWritableStream, type InstantIssue, type Logger, };
|
|
610
|
+
export { init, init_experimental, id, tx, lookup, i, createInstantRouteHandler, type InstantRouteHandlerPayloadByType, type InstantRouteHandlerType, type InstantRouteHandlerBody, Alarms, type AlarmStatus, type AlarmAttempt, type AlarmInfo, type AlarmEvent, type SetAlarmParams, type ListAlarmsParams, type AlarmValidateOpts, Webhooks, WebhooksManager, type WebhookAction, type WebhookStatus, type WebhookEventStatus, type WebhookInfo, type WebhookAttempt, type WebhookEventInfo, type WebhookEventsPage, type WebhookBody, type WebhookEntity, type WebhookPayload, type WebhookPayloadRecord, type WebhookPayloadRecordFor, type WebhookHandlerFn, type WebhookHandlers, type WebhookHelpers, type CreateWebhookParams, type UpdateWebhookParams, InstantAPIError, setInstantWarningsEnabled, type Config, type ImpersonationOpts, type TransactionChunk, type DebugCheckResult, type InstantAdminDatabase, type User, type InstaQLParams, type ValidQuery, type Query, InstantError, type QueryResponse, type InstaQLResponse, type InstantQuery, type InstantUnknownSchemaDef, type InstantQueryResult, type InstantSchema, type InstantSchemaDatabase, type IInstantDatabase, type InstantObject, type InstantEntity, type BackwardsCompatibleSchema, type InstaQLFields, type SubscribeQueryCallback, type SubscribeQueryResponse, type SubscribeQueryPayload, type SubscriptionReadyState, type AttrsDefs, type CardinalityKind, type DataAttrDef, type EntitiesDef, type EntitiesWithLinks, type EntityDef, type InstantGraph, type LinkAttrDef, type LinkDef, type LinksDef, type ResolveAttrs, type RoomsOf, type PresenceOf, type RoomsDef, type RoomHandle, type ValueTypes, type InstantSchemaDef, type InstantUnknownSchema, type InstaQLEntity, type InstaQLResult, type InstaQLEntitySubquery, type InstantRules, type CreateParams, type UpdateParams, type LinkParams, type FileOpts, type UploadFileResponse, type DeleteFileResponse, type DeleteManyFileResponse, type CreateReadStreamOpts, type CreateWriteStreamOpts, type InstantWritableStream, type InstantIssue, type Logger, };
|
|
608
611
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAG5C,OAAO,EACL,EAAE,EACF,MAAM,EAEN,CAAC,EACD,EAAE,EAGF,eAAe,EACf,yBAAyB,EACzB,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,SAAS,EAGd,KAAK,IAAI,EACT,KAAK,KAAK,EACV,YAAY,EAGZ,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAClB,KAAK,qBAAqB,EAC1B,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,yBAAyB,EAC9B,KAAK,gBAAgB,EAGrB,KAAK,SAAS,EACd,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,iBAAiB,EACtB,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,OAAO,EACZ,KAAK,uBAAuB,EAC5B,KAAK,QAAQ,EACb,KAAK,OAAO,EACZ,KAAK,QAAQ,EACb,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,KAAK,gBAAgB,EACrB,KAAK,oBAAoB,EACzB,KAAK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,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,uBAAuB,EAC5B,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAClB,KAAK,qBAAqB,EAC1B,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,yBAAyB,EAC9B,KAAK,aAAa,EAClB,KAAK,sBAAsB,EAC3B,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,EAG3B,KAAK,SAAS,EACd,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,iBAAiB,EACtB,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,OAAO,EACZ,KAAK,QAAQ,EACb,KAAK,YAAY,EACjB,KAAK,OAAO,EACZ,KAAK,UAAU,EACf,KAAK,QAAQ,EACb,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,gBAAgB,EACrB,KAAK,oBAAoB,EACzB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,qBAAqB,EAC1B,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,UAAU,EAGf,KAAK,QAAQ,EACb,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,sBAAsB,EAG3B,KAAK,oBAAoB,EACzB,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,EAG1B,KAAK,YAAY,EAGjB,KAAK,MAAM,GACZ,CAAC"}
|
package/dist/esm/index.js
CHANGED
|
@@ -5,6 +5,7 @@ import { subscribe, } from "./subscribe.js";
|
|
|
5
5
|
import { parseCookie } from 'cookie';
|
|
6
6
|
import { EventSource } from '@instantdb/eventsource';
|
|
7
7
|
import { MessageEventPolyfill } from "./polyfill.js";
|
|
8
|
+
import { Alarms, } from "./alarms.js";
|
|
8
9
|
import { Webhooks, WebhooksManager, } from '@instantdb/webhooks';
|
|
9
10
|
function configWithDefaults(config) {
|
|
10
11
|
const defaultConfig = {
|
|
@@ -657,6 +658,8 @@ class InstantAdminDatabase {
|
|
|
657
658
|
rooms;
|
|
658
659
|
impersonationOpts;
|
|
659
660
|
webhooks;
|
|
661
|
+
/** Roko DB: ask the server to call your url at a given time. */
|
|
662
|
+
alarms;
|
|
660
663
|
#sseConnection = null;
|
|
661
664
|
#sseBackoff = 0;
|
|
662
665
|
#instantStream = null;
|
|
@@ -669,6 +672,13 @@ class InstantAdminDatabase {
|
|
|
669
672
|
this.streams = new Streams(this.#ensureInstantStream.bind(this));
|
|
670
673
|
this.rooms = new Rooms(this.config);
|
|
671
674
|
this.webhooks = new Webhooks(this.config, jsonFetch);
|
|
675
|
+
this.alarms = new Alarms({
|
|
676
|
+
apiURI: this.config.apiURI,
|
|
677
|
+
appId: this.config.appId,
|
|
678
|
+
headers: () => authorizedHeaders(this.config),
|
|
679
|
+
jsonFetch,
|
|
680
|
+
verifySignature: (signatureHeader, body, opts) => this.webhooks.verifySignature(signatureHeader, body, opts),
|
|
681
|
+
});
|
|
672
682
|
this.#log = createLogger(!!this.config.verbose, this.config.logger);
|
|
673
683
|
}
|
|
674
684
|
/**
|
|
@@ -1029,7 +1039,7 @@ class InstantAdminDatabase {
|
|
|
1029
1039
|
this.#maybeShutdownConnection();
|
|
1030
1040
|
};
|
|
1031
1041
|
}
|
|
1032
|
-
export { init, init_experimental, id, tx, lookup, i, createInstantRouteHandler, Webhooks, WebhooksManager,
|
|
1042
|
+
export { init, init_experimental, id, tx, lookup, i, createInstantRouteHandler, Alarms, Webhooks, WebhooksManager,
|
|
1033
1043
|
// error
|
|
1034
1044
|
InstantAPIError,
|
|
1035
1045
|
// warnings
|