@vllnt/convex-push 0.0.0-stage → 0.1.0-canary.4a1ca91
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/CHANGELOG.md +41 -0
- package/LICENSE +21 -0
- package/README.md +415 -2
- package/dist/client/index.d.ts +180 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +152 -0
- package/dist/client/index.js.map +1 -0
- package/dist/component/_generated/api.d.ts +80 -0
- package/dist/component/_generated/api.d.ts.map +1 -0
- package/dist/component/_generated/api.js +31 -0
- package/dist/component/_generated/api.js.map +1 -0
- package/dist/component/_generated/component.d.ts +274 -0
- package/dist/component/_generated/component.d.ts.map +1 -0
- package/dist/component/_generated/component.js +11 -0
- package/dist/component/_generated/component.js.map +1 -0
- package/dist/component/_generated/dataModel.d.ts +46 -0
- package/dist/component/_generated/dataModel.d.ts.map +1 -0
- package/dist/component/_generated/dataModel.js +11 -0
- package/dist/component/_generated/dataModel.js.map +1 -0
- package/dist/component/_generated/server.d.ts +142 -0
- package/dist/component/_generated/server.d.ts.map +1 -0
- package/dist/component/_generated/server.js +80 -0
- package/dist/component/_generated/server.js.map +1 -0
- package/dist/component/actions.d.ts +29 -0
- package/dist/component/actions.d.ts.map +1 -0
- package/dist/component/actions.js +29 -0
- package/dist/component/actions.js.map +1 -0
- package/dist/component/checks.d.ts +27 -0
- package/dist/component/checks.d.ts.map +1 -0
- package/dist/component/checks.js +107 -0
- package/dist/component/checks.js.map +1 -0
- package/dist/component/convex.config.d.ts +18 -0
- package/dist/component/convex.config.d.ts.map +1 -0
- package/dist/component/convex.config.js +30 -0
- package/dist/component/convex.config.js.map +1 -0
- package/dist/component/crons.d.ts +8 -0
- package/dist/component/crons.d.ts.map +1 -0
- package/dist/component/crons.js +15 -0
- package/dist/component/crons.js.map +1 -0
- package/dist/component/crypto/codec.d.ts +64 -0
- package/dist/component/crypto/codec.d.ts.map +1 -0
- package/dist/component/crypto/codec.js +102 -0
- package/dist/component/crypto/codec.js.map +1 -0
- package/dist/component/crypto/jwt.d.ts +46 -0
- package/dist/component/crypto/jwt.d.ts.map +1 -0
- package/dist/component/crypto/jwt.js +82 -0
- package/dist/component/crypto/jwt.js.map +1 -0
- package/dist/component/crypto/token_seal.d.ts +31 -0
- package/dist/component/crypto/token_seal.d.ts.map +1 -0
- package/dist/component/crypto/token_seal.js +44 -0
- package/dist/component/crypto/token_seal.js.map +1 -0
- package/dist/component/crypto/web_push_crypto.d.ts +42 -0
- package/dist/component/crypto/web_push_crypto.d.ts.map +1 -0
- package/dist/component/crypto/web_push_crypto.js +49 -0
- package/dist/component/crypto/web_push_crypto.js.map +1 -0
- package/dist/component/internal_mutations.d.ts +48 -0
- package/dist/component/internal_mutations.d.ts.map +1 -0
- package/dist/component/internal_mutations.js +82 -0
- package/dist/component/internal_mutations.js.map +1 -0
- package/dist/component/mutations.d.ts +223 -0
- package/dist/component/mutations.d.ts.map +1 -0
- package/dist/component/mutations.js +244 -0
- package/dist/component/mutations.js.map +1 -0
- package/dist/component/providers/apns.d.ts +46 -0
- package/dist/component/providers/apns.d.ts.map +1 -0
- package/dist/component/providers/apns.js +105 -0
- package/dist/component/providers/apns.js.map +1 -0
- package/dist/component/providers/fcm.d.ts +36 -0
- package/dist/component/providers/fcm.d.ts.map +1 -0
- package/dist/component/providers/fcm.js +116 -0
- package/dist/component/providers/fcm.js.map +1 -0
- package/dist/component/providers/http.d.ts +45 -0
- package/dist/component/providers/http.d.ts.map +1 -0
- package/dist/component/providers/http.js +74 -0
- package/dist/component/providers/http.js.map +1 -0
- package/dist/component/providers/keys.d.ts +70 -0
- package/dist/component/providers/keys.d.ts.map +1 -0
- package/dist/component/providers/keys.js +89 -0
- package/dist/component/providers/keys.js.map +1 -0
- package/dist/component/providers/payload.d.ts +83 -0
- package/dist/component/providers/payload.d.ts.map +1 -0
- package/dist/component/providers/payload.js +162 -0
- package/dist/component/providers/payload.js.map +1 -0
- package/dist/component/providers/token_cache.d.ts +56 -0
- package/dist/component/providers/token_cache.d.ts.map +1 -0
- package/dist/component/providers/token_cache.js +42 -0
- package/dist/component/providers/token_cache.js.map +1 -0
- package/dist/component/providers/web_push.d.ts +40 -0
- package/dist/component/providers/web_push.d.ts.map +1 -0
- package/dist/component/providers/web_push.js +94 -0
- package/dist/component/providers/web_push.js.map +1 -0
- package/dist/component/queries.d.ts +132 -0
- package/dist/component/queries.d.ts.map +1 -0
- package/dist/component/queries.js +156 -0
- package/dist/component/queries.js.map +1 -0
- package/dist/component/queue.d.ts +66 -0
- package/dist/component/queue.d.ts.map +1 -0
- package/dist/component/queue.js +356 -0
- package/dist/component/queue.js.map +1 -0
- package/dist/component/registry.d.ts +46 -0
- package/dist/component/registry.d.ts.map +1 -0
- package/dist/component/registry.js +128 -0
- package/dist/component/registry.js.map +1 -0
- package/dist/component/schema.d.ts +286 -0
- package/dist/component/schema.d.ts.map +1 -0
- package/dist/component/schema.js +70 -0
- package/dist/component/schema.js.map +1 -0
- package/dist/component/senders.d.ts +67 -0
- package/dist/component/senders.d.ts.map +1 -0
- package/dist/component/senders.js +123 -0
- package/dist/component/senders.js.map +1 -0
- package/dist/component/validators.d.ts +784 -0
- package/dist/component/validators.d.ts.map +1 -0
- package/dist/component/validators.js +193 -0
- package/dist/component/validators.js.map +1 -0
- package/dist/shared.d.ts +109 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +131 -0
- package/dist/shared.js.map +1 -0
- package/docs/API.md +258 -0
- package/llms.txt +33 -0
- package/package.json +125 -4
- package/src/client/index.ts +276 -0
- package/src/component/_generated/api.ts +96 -0
- package/src/component/_generated/component.ts +263 -0
- package/src/component/_generated/dataModel.ts +60 -0
- package/src/component/_generated/server.ts +178 -0
- package/src/component/actions.ts +31 -0
- package/src/component/checks.ts +117 -0
- package/src/component/convex.config.ts +32 -0
- package/src/component/crons.ts +17 -0
- package/src/component/crypto/codec.ts +113 -0
- package/src/component/crypto/jwt.ts +109 -0
- package/src/component/crypto/token_seal.ts +56 -0
- package/src/component/crypto/web_push_crypto.ts +75 -0
- package/src/component/internal_mutations.ts +88 -0
- package/src/component/mutations.ts +257 -0
- package/src/component/providers/apns.ts +116 -0
- package/src/component/providers/fcm.ts +132 -0
- package/src/component/providers/http.ts +78 -0
- package/src/component/providers/keys.ts +133 -0
- package/src/component/providers/payload.ts +200 -0
- package/src/component/providers/token_cache.ts +75 -0
- package/src/component/providers/web_push.ts +101 -0
- package/src/component/queries.ts +182 -0
- package/src/component/queue.ts +425 -0
- package/src/component/registry.ts +144 -0
- package/src/component/schema.ts +82 -0
- package/src/component/senders.ts +152 -0
- package/src/component/validators.ts +285 -0
- package/src/shared.ts +155 -0
- package/src/test.ts +25 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { type PushErrorCode } from "../shared.js";
|
|
2
|
+
import type { Doc } from "./_generated/dataModel.js";
|
|
3
|
+
import type { DeviceAddress, DeviceView } from "./validators.js";
|
|
4
|
+
/**
|
|
5
|
+
* Throw a coded error.
|
|
6
|
+
* @param code - The error code.
|
|
7
|
+
* @param message - A message without secrets or payload content.
|
|
8
|
+
* @returns Never.
|
|
9
|
+
*/
|
|
10
|
+
export declare function fail(code: PushErrorCode, message: string): never;
|
|
11
|
+
/**
|
|
12
|
+
* Check an opaque ref: non-empty and at most 256 characters.
|
|
13
|
+
* @param field - Field name for the error.
|
|
14
|
+
* @param value - The ref.
|
|
15
|
+
*/
|
|
16
|
+
export declare function checkRef(field: string, value: string): void;
|
|
17
|
+
/**
|
|
18
|
+
* Whether a URL is https on the default port, with no credentials, to a public
|
|
19
|
+
* host name. IP literals, a trailing dot and private names are refused, so a registered
|
|
20
|
+
* endpoint cannot point the send action at the deployment's own network.
|
|
21
|
+
* DNS answers are not checked (a public name may still resolve privately).
|
|
22
|
+
* @param value - The URL.
|
|
23
|
+
* @returns Whether it may be used as a Web Push endpoint.
|
|
24
|
+
*/
|
|
25
|
+
export declare function isPublicHttpsUrl(value: string): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Validate a device address. Web Push endpoints must be https URLs to a public
|
|
28
|
+
* host name (see `isPublicHttpsUrl`) and carry a 65-byte P-256 key and a
|
|
29
|
+
* 16-byte auth secret.
|
|
30
|
+
* @param address - The address to check.
|
|
31
|
+
*/
|
|
32
|
+
export declare function checkAddress(address: DeviceAddress): void;
|
|
33
|
+
/**
|
|
34
|
+
* The dedupe key of an address: SHA-256 of the platform and the address. Web
|
|
35
|
+
* Push keys are left out, so a subscription whose keys rotate stays one row.
|
|
36
|
+
* @param address - A device address.
|
|
37
|
+
* @returns 64 hex characters.
|
|
38
|
+
*/
|
|
39
|
+
export declare function addressHash(address: DeviceAddress): Promise<string>;
|
|
40
|
+
/**
|
|
41
|
+
* The public view of a device. The address is never returned.
|
|
42
|
+
* @param device - A devices row.
|
|
43
|
+
* @returns The view.
|
|
44
|
+
*/
|
|
45
|
+
export declare function toDeviceView(device: Doc<"devices">): DeviceView;
|
|
46
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/component/registry.ts"],"names":[],"mappings":"AACA,OAAO,EAKL,KAAK,aAAa,EACnB,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,2BAA2B,CAAC;AAErD,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAEjE;;;;;GAKG;AACH,wBAAgB,IAAI,CAAC,IAAI,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,GAAG,KAAK,CAEhE;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAI3D;AAWD;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAoBvD;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI,CAwBzD;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,CAanE;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,GAAG,CAAC,SAAS,CAAC,GAAG,UAAU,CAa/D"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { ConvexError } from "convex/values";
|
|
2
|
+
import { MAX_CUSTOM_ADDRESS_LENGTH, MAX_ENDPOINT_LENGTH, MAX_REF_LENGTH, MAX_TOKEN_LENGTH, } from "../shared.js";
|
|
3
|
+
import { base64Decode, sha256Hex } from "./crypto/codec.js";
|
|
4
|
+
/**
|
|
5
|
+
* Throw a coded error.
|
|
6
|
+
* @param code - The error code.
|
|
7
|
+
* @param message - A message without secrets or payload content.
|
|
8
|
+
* @returns Never.
|
|
9
|
+
*/
|
|
10
|
+
export function fail(code, message) {
|
|
11
|
+
throw new ConvexError({ code, message });
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Check an opaque ref: non-empty and at most 256 characters.
|
|
15
|
+
* @param field - Field name for the error.
|
|
16
|
+
* @param value - The ref.
|
|
17
|
+
*/
|
|
18
|
+
export function checkRef(field, value) {
|
|
19
|
+
if (value.length === 0 || value.length > MAX_REF_LENGTH) {
|
|
20
|
+
fail("INVALID_ARGUMENT", `${field} must be 1 to ${String(MAX_REF_LENGTH)} characters`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function checkPrintable(field, value, max) {
|
|
24
|
+
if (value.length === 0 || value.length > max || /\s/.test(value)) {
|
|
25
|
+
fail("INVALID_ADDRESS", `${field} must be 1 to ${String(max)} characters without whitespace`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/** Host names that only resolve inside a machine or a private network. */
|
|
29
|
+
const PRIVATE_HOST = /(^localhost$)|\.(localhost|local|localdomain|internal|intranet|lan|corp|svc|test|arpa)$/;
|
|
30
|
+
/**
|
|
31
|
+
* Whether a URL is https on the default port, with no credentials, to a public
|
|
32
|
+
* host name. IP literals, a trailing dot and private names are refused, so a registered
|
|
33
|
+
* endpoint cannot point the send action at the deployment's own network.
|
|
34
|
+
* DNS answers are not checked (a public name may still resolve privately).
|
|
35
|
+
* @param value - The URL.
|
|
36
|
+
* @returns Whether it may be used as a Web Push endpoint.
|
|
37
|
+
*/
|
|
38
|
+
export function isPublicHttpsUrl(value) {
|
|
39
|
+
let url;
|
|
40
|
+
try {
|
|
41
|
+
url = new URL(value);
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
const host = url.hostname.toLowerCase();
|
|
47
|
+
const ipLiteral = host.startsWith("[") || /^[\d.]+$/.test(host);
|
|
48
|
+
const trailingDot = host.endsWith(".");
|
|
49
|
+
return (url.protocol === "https:" &&
|
|
50
|
+
url.port === "" &&
|
|
51
|
+
url.username === "" &&
|
|
52
|
+
url.password === "" &&
|
|
53
|
+
host.includes(".") &&
|
|
54
|
+
!ipLiteral &&
|
|
55
|
+
!trailingDot &&
|
|
56
|
+
!PRIVATE_HOST.test(host));
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Validate a device address. Web Push endpoints must be https URLs to a public
|
|
60
|
+
* host name (see `isPublicHttpsUrl`) and carry a 65-byte P-256 key and a
|
|
61
|
+
* 16-byte auth secret.
|
|
62
|
+
* @param address - The address to check.
|
|
63
|
+
*/
|
|
64
|
+
export function checkAddress(address) {
|
|
65
|
+
switch (address.platform) {
|
|
66
|
+
case "apns":
|
|
67
|
+
case "fcm": {
|
|
68
|
+
checkPrintable("token", address.token, MAX_TOKEN_LENGTH);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
case "webpush": {
|
|
72
|
+
checkPrintable("endpoint", address.endpoint, MAX_ENDPOINT_LENGTH);
|
|
73
|
+
if (!isPublicHttpsUrl(address.endpoint)) {
|
|
74
|
+
fail("INVALID_ADDRESS", "endpoint must be an https URL to a public host name, on the default port");
|
|
75
|
+
}
|
|
76
|
+
if (base64Decode(address.p256dh)?.length !== 65 || base64Decode(address.auth)?.length !== 16) {
|
|
77
|
+
fail("INVALID_ADDRESS", "p256dh must be a 65-byte P-256 key and auth a 16-byte secret");
|
|
78
|
+
}
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
case "custom": {
|
|
82
|
+
checkRef("provider", address.provider);
|
|
83
|
+
if (address.address.length === 0 || address.address.length > MAX_CUSTOM_ADDRESS_LENGTH) {
|
|
84
|
+
fail("INVALID_ADDRESS", `address must be 1 to ${String(MAX_CUSTOM_ADDRESS_LENGTH)} characters`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* The dedupe key of an address: SHA-256 of the platform and the address. Web
|
|
91
|
+
* Push keys are left out, so a subscription whose keys rotate stays one row.
|
|
92
|
+
* @param address - A device address.
|
|
93
|
+
* @returns 64 hex characters.
|
|
94
|
+
*/
|
|
95
|
+
export function addressHash(address) {
|
|
96
|
+
switch (address.platform) {
|
|
97
|
+
case "apns":
|
|
98
|
+
case "fcm": {
|
|
99
|
+
return sha256Hex(`${address.platform}\n${address.token}`);
|
|
100
|
+
}
|
|
101
|
+
case "webpush": {
|
|
102
|
+
return sha256Hex(`webpush\n${address.endpoint}`);
|
|
103
|
+
}
|
|
104
|
+
case "custom": {
|
|
105
|
+
return sha256Hex(`custom\n${address.provider}\n${address.address}`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* The public view of a device. The address is never returned.
|
|
111
|
+
* @param device - A devices row.
|
|
112
|
+
* @returns The view.
|
|
113
|
+
*/
|
|
114
|
+
export function toDeviceView(device) {
|
|
115
|
+
return {
|
|
116
|
+
deviceId: device._id,
|
|
117
|
+
subjectRef: device.subjectRef,
|
|
118
|
+
appRef: device.appRef,
|
|
119
|
+
platform: device.address.platform,
|
|
120
|
+
provider: device.address.platform === "custom" ? device.address.provider : undefined,
|
|
121
|
+
status: device.status,
|
|
122
|
+
invalidCode: device.invalidCode,
|
|
123
|
+
installRef: device.installRef,
|
|
124
|
+
locale: device.locale,
|
|
125
|
+
lastSeenAt: device.lastSeenAt,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/component/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EACL,yBAAyB,EACzB,mBAAmB,EACnB,cAAc,EACd,gBAAgB,GAEjB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAG5D;;;;;GAKG;AACH,MAAM,UAAU,IAAI,CAAC,IAAmB,EAAE,OAAe;IACvD,MAAM,IAAI,WAAW,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;AAC3C,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAa,EAAE,KAAa;IACnD,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,GAAG,cAAc,EAAE,CAAC;QACxD,IAAI,CAAC,kBAAkB,EAAE,GAAG,KAAK,iBAAiB,MAAM,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC;IACzF,CAAC;AACH,CAAC;AAED,SAAS,cAAc,CAAC,KAAa,EAAE,KAAa,EAAE,GAAW;IAC/D,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,GAAG,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACjE,IAAI,CAAC,iBAAiB,EAAE,GAAG,KAAK,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C;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,MAAsB;IACjD,OAAO;QACL,QAAQ,EAAE,MAAM,CAAC,GAAG;QACpB,UAAU,EAAE,MAAM,CAAC,UAAU;QAC7B,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,QAAQ,EAAE,MAAM,CAAC,OAAO,CAAC,QAAQ;QACjC,QAAQ,EAAE,MAAM,CAAC,OAAO,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS;QACpF,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,UAAU,EAAE,MAAM,CAAC,UAAU;QAC7B,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,UAAU,EAAE,MAAM,CAAC,UAAU;KAC9B,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
/** The component's four tables. */
|
|
2
|
+
declare const _default: import("convex/server").SchemaDefinition<{
|
|
3
|
+
/** One row per app install: the device registry. */
|
|
4
|
+
devices: import("convex/server").TableDefinition<import("convex/values").VObject<{
|
|
5
|
+
address: {
|
|
6
|
+
platform: "apns";
|
|
7
|
+
token: string;
|
|
8
|
+
} | {
|
|
9
|
+
platform: "fcm";
|
|
10
|
+
token: string;
|
|
11
|
+
} | {
|
|
12
|
+
auth: string;
|
|
13
|
+
endpoint: string;
|
|
14
|
+
p256dh: string;
|
|
15
|
+
platform: "webpush";
|
|
16
|
+
} | {
|
|
17
|
+
address: string;
|
|
18
|
+
platform: "custom";
|
|
19
|
+
provider: string;
|
|
20
|
+
};
|
|
21
|
+
addressHash: string;
|
|
22
|
+
appRef: string;
|
|
23
|
+
installRef?: string | undefined;
|
|
24
|
+
invalidCode?: string | undefined;
|
|
25
|
+
lastSeenAt: number;
|
|
26
|
+
locale?: string | undefined;
|
|
27
|
+
status: "active" | "disabled" | "invalid";
|
|
28
|
+
subjectRef: string;
|
|
29
|
+
}, {
|
|
30
|
+
subjectRef: import("convex/values").VString<string, "required">;
|
|
31
|
+
appRef: import("convex/values").VString<string, "required">;
|
|
32
|
+
address: import("convex/values").VUnion<{
|
|
33
|
+
platform: "apns";
|
|
34
|
+
token: string;
|
|
35
|
+
} | {
|
|
36
|
+
platform: "fcm";
|
|
37
|
+
token: string;
|
|
38
|
+
} | {
|
|
39
|
+
auth: string;
|
|
40
|
+
endpoint: string;
|
|
41
|
+
p256dh: string;
|
|
42
|
+
platform: "webpush";
|
|
43
|
+
} | {
|
|
44
|
+
address: string;
|
|
45
|
+
platform: "custom";
|
|
46
|
+
provider: string;
|
|
47
|
+
}, [import("convex/values").VObject<{
|
|
48
|
+
platform: "apns";
|
|
49
|
+
token: string;
|
|
50
|
+
}, {
|
|
51
|
+
platform: import("convex/values").VLiteral<"apns", "required">;
|
|
52
|
+
token: import("convex/values").VString<string, "required">;
|
|
53
|
+
}, "required", "platform" | "token">, import("convex/values").VObject<{
|
|
54
|
+
platform: "fcm";
|
|
55
|
+
token: string;
|
|
56
|
+
}, {
|
|
57
|
+
platform: import("convex/values").VLiteral<"fcm", "required">;
|
|
58
|
+
token: import("convex/values").VString<string, "required">;
|
|
59
|
+
}, "required", "platform" | "token">, import("convex/values").VObject<{
|
|
60
|
+
auth: string;
|
|
61
|
+
endpoint: string;
|
|
62
|
+
p256dh: string;
|
|
63
|
+
platform: "webpush";
|
|
64
|
+
}, {
|
|
65
|
+
platform: import("convex/values").VLiteral<"webpush", "required">;
|
|
66
|
+
endpoint: import("convex/values").VString<string, "required">;
|
|
67
|
+
p256dh: import("convex/values").VString<string, "required">;
|
|
68
|
+
auth: import("convex/values").VString<string, "required">;
|
|
69
|
+
}, "required", "auth" | "endpoint" | "p256dh" | "platform">, import("convex/values").VObject<{
|
|
70
|
+
address: string;
|
|
71
|
+
platform: "custom";
|
|
72
|
+
provider: string;
|
|
73
|
+
}, {
|
|
74
|
+
platform: import("convex/values").VLiteral<"custom", "required">;
|
|
75
|
+
provider: import("convex/values").VString<string, "required">;
|
|
76
|
+
address: import("convex/values").VString<string, "required">;
|
|
77
|
+
}, "required", "address" | "platform" | "provider">], "required", "address" | "auth" | "endpoint" | "p256dh" | "platform" | "provider" | "token">;
|
|
78
|
+
addressHash: import("convex/values").VString<string, "required">;
|
|
79
|
+
installRef: import("convex/values").VString<string | undefined, "optional">;
|
|
80
|
+
locale: import("convex/values").VString<string | undefined, "optional">;
|
|
81
|
+
status: import("convex/values").VUnion<"active" | "disabled" | "invalid", [import("convex/values").VLiteral<"active", "required">, import("convex/values").VLiteral<"disabled", "required">, import("convex/values").VLiteral<"invalid", "required">], "required", never>;
|
|
82
|
+
invalidCode: import("convex/values").VString<string | undefined, "optional">;
|
|
83
|
+
lastSeenAt: import("convex/values").VFloat64<number, "required">;
|
|
84
|
+
}, "required", "address" | "address.address" | "address.auth" | "address.endpoint" | "address.p256dh" | "address.platform" | "address.provider" | "address.token" | "addressHash" | "appRef" | "installRef" | "invalidCode" | "lastSeenAt" | "locale" | "status" | "subjectRef">, {
|
|
85
|
+
by_address_hash: ["addressHash", "_creationTime"];
|
|
86
|
+
by_install: ["installRef", "appRef", "_creationTime"];
|
|
87
|
+
by_status_seen: ["status", "lastSeenAt", "_creationTime"];
|
|
88
|
+
by_subject_status: ["subjectRef", "status", "_creationTime"];
|
|
89
|
+
}, {}, {}>;
|
|
90
|
+
/** One logical notification to one subject or to named devices. */
|
|
91
|
+
messages: import("convex/server").TableDefinition<import("convex/values").VObject<{
|
|
92
|
+
body?: string | undefined;
|
|
93
|
+
data: Record<string, string | number | boolean>;
|
|
94
|
+
expiresAt: number;
|
|
95
|
+
idempotencyKey?: string | undefined;
|
|
96
|
+
maxAttempts: number;
|
|
97
|
+
onDeliveryHandle?: string | undefined;
|
|
98
|
+
options: {
|
|
99
|
+
badge?: number | undefined;
|
|
100
|
+
category?: string | undefined;
|
|
101
|
+
collapseKey?: string | undefined;
|
|
102
|
+
priority: "high" | "normal";
|
|
103
|
+
sound?: string | undefined;
|
|
104
|
+
ttlSeconds?: number | undefined;
|
|
105
|
+
};
|
|
106
|
+
overrides?: {
|
|
107
|
+
apns?: {
|
|
108
|
+
interruptionLevel?: "active" | "critical" | "passive" | "time-sensitive" | undefined;
|
|
109
|
+
mutableContent?: boolean | undefined;
|
|
110
|
+
rawJson?: string | undefined;
|
|
111
|
+
threadId?: string | undefined;
|
|
112
|
+
} | undefined;
|
|
113
|
+
fcm?: {
|
|
114
|
+
channelId?: string | undefined;
|
|
115
|
+
rawJson?: string | undefined;
|
|
116
|
+
} | undefined;
|
|
117
|
+
webpush?: {
|
|
118
|
+
icon?: string | undefined;
|
|
119
|
+
rawJson?: string | undefined;
|
|
120
|
+
url?: string | undefined;
|
|
121
|
+
} | undefined;
|
|
122
|
+
} | undefined;
|
|
123
|
+
scrub: boolean;
|
|
124
|
+
scrubbedAt?: number | undefined;
|
|
125
|
+
title?: string | undefined;
|
|
126
|
+
to: {
|
|
127
|
+
subjectRef: string;
|
|
128
|
+
} | {
|
|
129
|
+
deviceIds: import("convex/values").GenericId<"devices">[];
|
|
130
|
+
};
|
|
131
|
+
}, {
|
|
132
|
+
to: import("convex/values").VUnion<{
|
|
133
|
+
subjectRef: string;
|
|
134
|
+
} | {
|
|
135
|
+
deviceIds: import("convex/values").GenericId<"devices">[];
|
|
136
|
+
}, [import("convex/values").VObject<{
|
|
137
|
+
subjectRef: string;
|
|
138
|
+
}, {
|
|
139
|
+
subjectRef: import("convex/values").VString<string, "required">;
|
|
140
|
+
}, "required", "subjectRef">, import("convex/values").VObject<{
|
|
141
|
+
deviceIds: import("convex/values").GenericId<"devices">[];
|
|
142
|
+
}, {
|
|
143
|
+
deviceIds: import("convex/values").VArray<import("convex/values").GenericId<"devices">[], import("convex/values").VId<import("convex/values").GenericId<"devices">, "required">, "required">;
|
|
144
|
+
}, "required", "deviceIds">], "required", "deviceIds" | "subjectRef">;
|
|
145
|
+
title: import("convex/values").VString<string | undefined, "optional">;
|
|
146
|
+
body: import("convex/values").VString<string | undefined, "optional">;
|
|
147
|
+
data: import("convex/values").VRecord<Record<string, string | number | boolean>, import("convex/values").VString<string, "required">, import("convex/values").VUnion<string | number | boolean, [import("convex/values").VString<string, "required">, import("convex/values").VFloat64<number, "required">, import("convex/values").VBoolean<boolean, "required">], "required", never>, "required", string>;
|
|
148
|
+
options: import("convex/values").VObject<{
|
|
149
|
+
badge?: number | undefined;
|
|
150
|
+
category?: string | undefined;
|
|
151
|
+
collapseKey?: string | undefined;
|
|
152
|
+
priority: "high" | "normal";
|
|
153
|
+
sound?: string | undefined;
|
|
154
|
+
ttlSeconds?: number | undefined;
|
|
155
|
+
}, {
|
|
156
|
+
collapseKey: import("convex/values").VString<string | undefined, "optional">;
|
|
157
|
+
ttlSeconds: import("convex/values").VFloat64<number | undefined, "optional">;
|
|
158
|
+
priority: import("convex/values").VUnion<"high" | "normal", [import("convex/values").VLiteral<"high", "required">, import("convex/values").VLiteral<"normal", "required">], "required", never>;
|
|
159
|
+
badge: import("convex/values").VFloat64<number | undefined, "optional">;
|
|
160
|
+
sound: import("convex/values").VString<string | undefined, "optional">;
|
|
161
|
+
category: import("convex/values").VString<string | undefined, "optional">;
|
|
162
|
+
}, "required", "badge" | "category" | "collapseKey" | "priority" | "sound" | "ttlSeconds">;
|
|
163
|
+
overrides: import("convex/values").VObject<{
|
|
164
|
+
apns?: {
|
|
165
|
+
interruptionLevel?: "active" | "critical" | "passive" | "time-sensitive" | undefined;
|
|
166
|
+
mutableContent?: boolean | undefined;
|
|
167
|
+
rawJson?: string | undefined;
|
|
168
|
+
threadId?: string | undefined;
|
|
169
|
+
} | undefined;
|
|
170
|
+
fcm?: {
|
|
171
|
+
channelId?: string | undefined;
|
|
172
|
+
rawJson?: string | undefined;
|
|
173
|
+
} | undefined;
|
|
174
|
+
webpush?: {
|
|
175
|
+
icon?: string | undefined;
|
|
176
|
+
rawJson?: string | undefined;
|
|
177
|
+
url?: string | undefined;
|
|
178
|
+
} | undefined;
|
|
179
|
+
} | undefined, {
|
|
180
|
+
apns: import("convex/values").VObject<{
|
|
181
|
+
interruptionLevel?: "active" | "critical" | "passive" | "time-sensitive" | undefined;
|
|
182
|
+
mutableContent?: boolean | undefined;
|
|
183
|
+
rawJson?: string | undefined;
|
|
184
|
+
threadId?: string | undefined;
|
|
185
|
+
} | undefined, {
|
|
186
|
+
threadId: import("convex/values").VString<string | undefined, "optional">;
|
|
187
|
+
interruptionLevel: import("convex/values").VUnion<"active" | "critical" | "passive" | "time-sensitive" | undefined, [import("convex/values").VLiteral<"passive", "required">, import("convex/values").VLiteral<"active", "required">, import("convex/values").VLiteral<"time-sensitive", "required">, import("convex/values").VLiteral<"critical", "required">], "optional", never>;
|
|
188
|
+
mutableContent: import("convex/values").VBoolean<boolean | undefined, "optional">;
|
|
189
|
+
rawJson: import("convex/values").VString<string | undefined, "optional">;
|
|
190
|
+
}, "optional", "interruptionLevel" | "mutableContent" | "rawJson" | "threadId">;
|
|
191
|
+
fcm: import("convex/values").VObject<{
|
|
192
|
+
channelId?: string | undefined;
|
|
193
|
+
rawJson?: string | undefined;
|
|
194
|
+
} | undefined, {
|
|
195
|
+
channelId: import("convex/values").VString<string | undefined, "optional">;
|
|
196
|
+
rawJson: import("convex/values").VString<string | undefined, "optional">;
|
|
197
|
+
}, "optional", "channelId" | "rawJson">;
|
|
198
|
+
webpush: import("convex/values").VObject<{
|
|
199
|
+
icon?: string | undefined;
|
|
200
|
+
rawJson?: string | undefined;
|
|
201
|
+
url?: string | undefined;
|
|
202
|
+
} | undefined, {
|
|
203
|
+
icon: import("convex/values").VString<string | undefined, "optional">;
|
|
204
|
+
url: import("convex/values").VString<string | undefined, "optional">;
|
|
205
|
+
rawJson: import("convex/values").VString<string | undefined, "optional">;
|
|
206
|
+
}, "optional", "icon" | "rawJson" | "url">;
|
|
207
|
+
}, "optional", "apns" | "apns.interruptionLevel" | "apns.mutableContent" | "apns.rawJson" | "apns.threadId" | "fcm" | "fcm.channelId" | "fcm.rawJson" | "webpush" | "webpush.icon" | "webpush.rawJson" | "webpush.url">;
|
|
208
|
+
onDeliveryHandle: import("convex/values").VString<string | undefined, "optional">;
|
|
209
|
+
idempotencyKey: import("convex/values").VString<string | undefined, "optional">;
|
|
210
|
+
expiresAt: import("convex/values").VFloat64<number, "required">;
|
|
211
|
+
scrubbedAt: import("convex/values").VFloat64<number | undefined, "optional">;
|
|
212
|
+
maxAttempts: import("convex/values").VFloat64<number, "required">;
|
|
213
|
+
scrub: import("convex/values").VBoolean<boolean, "required">;
|
|
214
|
+
}, "required", "body" | "data" | "expiresAt" | "idempotencyKey" | "maxAttempts" | "onDeliveryHandle" | "options" | "options.badge" | "options.category" | "options.collapseKey" | "options.priority" | "options.sound" | "options.ttlSeconds" | "overrides" | "overrides.apns" | "overrides.apns.interruptionLevel" | "overrides.apns.mutableContent" | "overrides.apns.rawJson" | "overrides.apns.threadId" | "overrides.fcm" | "overrides.fcm.channelId" | "overrides.fcm.rawJson" | "overrides.webpush" | "overrides.webpush.icon" | "overrides.webpush.rawJson" | "overrides.webpush.url" | "scrub" | "scrubbedAt" | "title" | "to" | "to.deviceIds" | "to.subjectRef" | `data.${string}`>, {
|
|
215
|
+
by_idempotency_key: ["idempotencyKey", "_creationTime"];
|
|
216
|
+
by_subject_created: ["to.subjectRef", "_creationTime"];
|
|
217
|
+
}, {}, {}>;
|
|
218
|
+
/** One row per device per message. What the status query reads. */
|
|
219
|
+
deliveries: import("convex/server").TableDefinition<import("convex/values").VObject<{
|
|
220
|
+
apns?: {
|
|
221
|
+
environment: "production" | "sandbox";
|
|
222
|
+
topic: string;
|
|
223
|
+
} | undefined;
|
|
224
|
+
attempts: number;
|
|
225
|
+
deviceId: import("convex/values").GenericId<"devices">;
|
|
226
|
+
errorCode?: string | undefined;
|
|
227
|
+
httpStatus?: number | undefined;
|
|
228
|
+
messageId: import("convex/values").GenericId<"messages">;
|
|
229
|
+
nextAttemptAt?: number | undefined;
|
|
230
|
+
platform: "apns" | "custom" | "fcm" | "webpush";
|
|
231
|
+
provider?: string | undefined;
|
|
232
|
+
providerMessageId?: string | undefined;
|
|
233
|
+
senderHandle?: string | undefined;
|
|
234
|
+
sentAt?: number | undefined;
|
|
235
|
+
status: "failed" | "invalid" | "queued" | "sent";
|
|
236
|
+
subjectRef: string;
|
|
237
|
+
updatedAt: number;
|
|
238
|
+
}, {
|
|
239
|
+
messageId: import("convex/values").VId<import("convex/values").GenericId<"messages">, "required">;
|
|
240
|
+
deviceId: import("convex/values").VId<import("convex/values").GenericId<"devices">, "required">;
|
|
241
|
+
/** The device's subject when the message was sent; a device that moved since is not sent to. */
|
|
242
|
+
subjectRef: import("convex/values").VString<string, "required">;
|
|
243
|
+
platform: import("convex/values").VUnion<"apns" | "custom" | "fcm" | "webpush", [import("convex/values").VLiteral<"apns", "required">, import("convex/values").VLiteral<"fcm", "required">, import("convex/values").VLiteral<"webpush", "required">, import("convex/values").VLiteral<"custom", "required">], "required", never>;
|
|
244
|
+
provider: import("convex/values").VString<string | undefined, "optional">;
|
|
245
|
+
senderHandle: import("convex/values").VString<string | undefined, "optional">;
|
|
246
|
+
apns: import("convex/values").VObject<{
|
|
247
|
+
environment: "production" | "sandbox";
|
|
248
|
+
topic: string;
|
|
249
|
+
} | undefined, {
|
|
250
|
+
topic: import("convex/values").VString<string, "required">;
|
|
251
|
+
environment: import("convex/values").VUnion<"production" | "sandbox", [import("convex/values").VLiteral<"production", "required">, import("convex/values").VLiteral<"sandbox", "required">], "required", never>;
|
|
252
|
+
}, "optional", "environment" | "topic">;
|
|
253
|
+
status: import("convex/values").VUnion<"failed" | "invalid" | "queued" | "sent", [import("convex/values").VLiteral<"queued", "required">, import("convex/values").VLiteral<"sent", "required">, import("convex/values").VLiteral<"failed", "required">, import("convex/values").VLiteral<"invalid", "required">], "required", never>;
|
|
254
|
+
attempts: import("convex/values").VFloat64<number, "required">;
|
|
255
|
+
providerMessageId: import("convex/values").VString<string | undefined, "optional">;
|
|
256
|
+
errorCode: import("convex/values").VString<string | undefined, "optional">;
|
|
257
|
+
httpStatus: import("convex/values").VFloat64<number | undefined, "optional">;
|
|
258
|
+
nextAttemptAt: import("convex/values").VFloat64<number | undefined, "optional">;
|
|
259
|
+
sentAt: import("convex/values").VFloat64<number | undefined, "optional">;
|
|
260
|
+
updatedAt: import("convex/values").VFloat64<number, "required">;
|
|
261
|
+
}, "required", "apns" | "apns.environment" | "apns.topic" | "attempts" | "deviceId" | "errorCode" | "httpStatus" | "messageId" | "nextAttemptAt" | "platform" | "provider" | "providerMessageId" | "senderHandle" | "sentAt" | "status" | "subjectRef" | "updatedAt">, {
|
|
262
|
+
by_message: ["messageId", "_creationTime"];
|
|
263
|
+
}, {}, {}>;
|
|
264
|
+
/** Shared cache of short-lived provider tokens. Ciphertext only. */
|
|
265
|
+
providerTokens: import("convex/server").TableDefinition<import("convex/values").VObject<{
|
|
266
|
+
audience?: string | undefined;
|
|
267
|
+
cipher: ArrayBuffer;
|
|
268
|
+
credentialRef: string;
|
|
269
|
+
expiresAt: number;
|
|
270
|
+
iv: ArrayBuffer;
|
|
271
|
+
mintedAt: number;
|
|
272
|
+
refreshAfter: number;
|
|
273
|
+
}, {
|
|
274
|
+
credentialRef: import("convex/values").VString<string, "required">;
|
|
275
|
+
audience: import("convex/values").VString<string | undefined, "optional">;
|
|
276
|
+
cipher: import("convex/values").VBytes<ArrayBuffer, "required">;
|
|
277
|
+
iv: import("convex/values").VBytes<ArrayBuffer, "required">;
|
|
278
|
+
mintedAt: import("convex/values").VFloat64<number, "required">;
|
|
279
|
+
refreshAfter: import("convex/values").VFloat64<number, "required">;
|
|
280
|
+
expiresAt: import("convex/values").VFloat64<number, "required">;
|
|
281
|
+
}, "required", "audience" | "cipher" | "credentialRef" | "expiresAt" | "iv" | "mintedAt" | "refreshAfter">, {
|
|
282
|
+
by_credential_audience: ["credentialRef", "audience", "_creationTime"];
|
|
283
|
+
}, {}, {}>;
|
|
284
|
+
}, true>;
|
|
285
|
+
export default _default;
|
|
286
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/component/schema.ts"],"names":[],"mappings":"AAaA,mCAAmC;;IAEjC,oDAAoD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAiBpD,mEAAmE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAkBnE,mEAAmE;;;;;;;;;;;;;;;;;;;;;;;QAIjE,gGAAgG;;;;;;;;;;;;;;;;;;;;;;;IAiBlG,oEAAoE"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { defineSchema, defineTable } from "convex/server";
|
|
2
|
+
import { v } from "convex/values";
|
|
3
|
+
import { apnsTarget, data, deliveryStatus, deviceAddress, deviceStatus, messageOptions, overrides, platform, } from "./validators.js";
|
|
4
|
+
/** The component's four tables. */
|
|
5
|
+
export default defineSchema({
|
|
6
|
+
/** One row per app install: the device registry. */
|
|
7
|
+
devices: defineTable({
|
|
8
|
+
subjectRef: v.string(),
|
|
9
|
+
appRef: v.string(),
|
|
10
|
+
address: deviceAddress,
|
|
11
|
+
addressHash: v.string(),
|
|
12
|
+
installRef: v.optional(v.string()),
|
|
13
|
+
locale: v.optional(v.string()),
|
|
14
|
+
status: deviceStatus,
|
|
15
|
+
invalidCode: v.optional(v.string()),
|
|
16
|
+
lastSeenAt: v.number(),
|
|
17
|
+
})
|
|
18
|
+
.index("by_address_hash", ["addressHash"])
|
|
19
|
+
.index("by_subject_status", ["subjectRef", "status"])
|
|
20
|
+
.index("by_install", ["installRef", "appRef"])
|
|
21
|
+
.index("by_status_seen", ["status", "lastSeenAt"]),
|
|
22
|
+
/** One logical notification to one subject or to named devices. */
|
|
23
|
+
messages: defineTable({
|
|
24
|
+
to: v.union(v.object({ subjectRef: v.string() }), v.object({ deviceIds: v.array(v.id("devices")) })),
|
|
25
|
+
title: v.optional(v.string()),
|
|
26
|
+
body: v.optional(v.string()),
|
|
27
|
+
data: data,
|
|
28
|
+
options: messageOptions,
|
|
29
|
+
overrides: v.optional(overrides),
|
|
30
|
+
onDeliveryHandle: v.optional(v.string()),
|
|
31
|
+
idempotencyKey: v.optional(v.string()),
|
|
32
|
+
expiresAt: v.number(),
|
|
33
|
+
scrubbedAt: v.optional(v.number()),
|
|
34
|
+
maxAttempts: v.number(),
|
|
35
|
+
scrub: v.boolean(),
|
|
36
|
+
})
|
|
37
|
+
.index("by_idempotency_key", ["idempotencyKey"])
|
|
38
|
+
.index("by_subject_created", ["to.subjectRef"]),
|
|
39
|
+
/** One row per device per message. What the status query reads. */
|
|
40
|
+
deliveries: defineTable({
|
|
41
|
+
messageId: v.id("messages"),
|
|
42
|
+
deviceId: v.id("devices"),
|
|
43
|
+
/** The device's subject when the message was sent; a device that moved since is not sent to. */
|
|
44
|
+
subjectRef: v.string(),
|
|
45
|
+
platform: platform,
|
|
46
|
+
provider: v.optional(v.string()),
|
|
47
|
+
senderHandle: v.optional(v.string()),
|
|
48
|
+
apns: v.optional(apnsTarget),
|
|
49
|
+
status: deliveryStatus,
|
|
50
|
+
attempts: v.number(),
|
|
51
|
+
providerMessageId: v.optional(v.string()),
|
|
52
|
+
errorCode: v.optional(v.string()),
|
|
53
|
+
httpStatus: v.optional(v.number()),
|
|
54
|
+
nextAttemptAt: v.optional(v.number()),
|
|
55
|
+
sentAt: v.optional(v.number()),
|
|
56
|
+
updatedAt: v.number(),
|
|
57
|
+
})
|
|
58
|
+
.index("by_message", ["messageId"]),
|
|
59
|
+
/** Shared cache of short-lived provider tokens. Ciphertext only. */
|
|
60
|
+
providerTokens: defineTable({
|
|
61
|
+
credentialRef: v.string(),
|
|
62
|
+
audience: v.optional(v.string()),
|
|
63
|
+
cipher: v.bytes(),
|
|
64
|
+
iv: v.bytes(),
|
|
65
|
+
mintedAt: v.number(),
|
|
66
|
+
refreshAfter: v.number(),
|
|
67
|
+
expiresAt: v.number(),
|
|
68
|
+
}).index("by_credential_audience", ["credentialRef", "audience"]),
|
|
69
|
+
});
|
|
70
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/component/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAClC,OAAO,EACL,UAAU,EACV,IAAI,EACJ,cAAc,EACd,aAAa,EACb,YAAY,EACZ,cAAc,EACd,SAAS,EACT,QAAQ,GACT,MAAM,iBAAiB,CAAC;AAEzB,mCAAmC;AACnC,eAAe,YAAY,CAAC;IAC1B,oDAAoD;IACpD,OAAO,EAAE,WAAW,CAAC;QACnB,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;QACtB,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;QAClB,OAAO,EAAE,aAAa;QACtB,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE;QACvB,UAAU,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;QAClC,MAAM,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;QAC9B,MAAM,EAAE,YAAY;QACpB,WAAW,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;QACnC,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;KACvB,CAAC;SACC,KAAK,CAAC,iBAAiB,EAAE,CAAC,aAAa,CAAC,CAAC;SACzC,KAAK,CAAC,mBAAmB,EAAE,CAAC,YAA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,EAAE;QACpB,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE;QACxB,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;KACtB,CAAC,CAAC,KAAK,CAAC,wBAAwB,EAAE,CAAC,eAAe,EAAE,UAAU,CAAC,CAAC;CAClE,CAAC,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { FunctionHandle } from "convex/server";
|
|
2
|
+
import type { ActionCtx } from "./_generated/server.js";
|
|
3
|
+
import type { PushEnv } from "./providers/keys.js";
|
|
4
|
+
import type { PushContent } from "./providers/payload.js";
|
|
5
|
+
import type { TokenCache } from "./providers/token_cache.js";
|
|
6
|
+
import type { CustomSendArgs, DeviceAddress, SendResult } from "./validators.js";
|
|
7
|
+
/** What the send action loads for one queued delivery. */
|
|
8
|
+
export interface Job {
|
|
9
|
+
deliveryId: string;
|
|
10
|
+
messageId: string;
|
|
11
|
+
provider?: string;
|
|
12
|
+
senderHandle?: string;
|
|
13
|
+
apns?: {
|
|
14
|
+
topic: string;
|
|
15
|
+
environment: "production" | "sandbox";
|
|
16
|
+
};
|
|
17
|
+
attempts: number;
|
|
18
|
+
expiresAt: number;
|
|
19
|
+
title?: string;
|
|
20
|
+
body?: string;
|
|
21
|
+
data: PushContent["data"];
|
|
22
|
+
options: PushContent["options"];
|
|
23
|
+
overrides?: PushContent["overrides"];
|
|
24
|
+
/** `reassigned`: the device moved to another subject after the message was sent. */
|
|
25
|
+
device: {
|
|
26
|
+
status: "active" | "disabled" | "invalid";
|
|
27
|
+
address: DeviceAddress;
|
|
28
|
+
reassigned: boolean;
|
|
29
|
+
} | null;
|
|
30
|
+
}
|
|
31
|
+
/** Everything a sender needs besides the job. */
|
|
32
|
+
export interface SenderDeps {
|
|
33
|
+
env: PushEnv;
|
|
34
|
+
cache: TokenCache;
|
|
35
|
+
now: () => number;
|
|
36
|
+
runCustom: (handle: string, args: CustomSendArgs) => Promise<unknown>;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Narrow a stored handle string to an action handle.
|
|
40
|
+
* @param handle - The stored string.
|
|
41
|
+
* @returns Whether it has the function-handle form.
|
|
42
|
+
*/
|
|
43
|
+
export declare function isActionHandle(handle: string): handle is FunctionHandle<"action", CustomSendArgs>;
|
|
44
|
+
/**
|
|
45
|
+
* Check what a custom sender returned against the sender contract.
|
|
46
|
+
* @param value - The host action's return value.
|
|
47
|
+
* @returns The result, or `null` when it does not match.
|
|
48
|
+
*/
|
|
49
|
+
export declare function parseSendResult(value: unknown): SendResult | null;
|
|
50
|
+
/**
|
|
51
|
+
* Send one queued delivery with the right sender. Nothing is sent after the
|
|
52
|
+
* message expires, to a device that is no longer active, or to a device that
|
|
53
|
+
* moved to another subject since the message was sent.
|
|
54
|
+
* @param job - The delivery, its message content and its device.
|
|
55
|
+
* @param deps - Env, token cache, clock and the custom-sender runner.
|
|
56
|
+
* @returns The sender result.
|
|
57
|
+
*/
|
|
58
|
+
export declare function runSender(job: Job, deps: SenderDeps): Promise<SendResult>;
|
|
59
|
+
/**
|
|
60
|
+
* Wire the sender dependencies to a Convex action context.
|
|
61
|
+
* @param ctx - The action context.
|
|
62
|
+
* @param env - Component env.
|
|
63
|
+
* @param cache - Provider-token cache.
|
|
64
|
+
* @returns The dependencies.
|
|
65
|
+
*/
|
|
66
|
+
export declare function actionDeps(ctx: Pick<ActionCtx, "runAction">, env: PushEnv, cache: TokenCache): SenderDeps;
|
|
67
|
+
//# sourceMappingURL=senders.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"senders.d.ts","sourceRoot":"","sources":["../../src/component/senders.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAIxD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM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