@stacksjs/ts-cloud 0.9.3 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/aws/index.js +1 -269
- package/dist/bin/chunk-08c0pzkb.js +1 -0
- package/dist/bin/chunk-12210qvj.js +1 -0
- package/dist/bin/chunk-1v6bt68w.js +6 -0
- package/dist/bin/chunk-35ttwn26.js +70 -0
- package/dist/bin/chunk-3r3be05z.js +1 -0
- package/dist/bin/chunk-41yqpdv7.js +2 -0
- package/dist/bin/chunk-5rv31chh.js +1 -0
- package/dist/bin/chunk-6eat8ezk.js +2 -0
- package/dist/bin/chunk-6gktf2m2.js +1 -0
- package/dist/bin/chunk-6zjy949y.js +141 -0
- package/dist/bin/chunk-7wzdaqh6.js +2 -0
- package/dist/bin/chunk-80ar3aty.js +1 -0
- package/dist/bin/chunk-8rwhsp5b.js +2 -0
- package/dist/bin/chunk-936vp7dx.js +44 -0
- package/dist/bin/chunk-9px3rg4a.js +4 -0
- package/dist/bin/chunk-anm3ae6z.js +7364 -0
- package/dist/bin/{chunk-ynjvbphf.js → chunk-axvr7dwa.js} +6 -6
- package/dist/bin/chunk-b0hj9m5e.js +2 -0
- package/dist/bin/{chunk-mh0kdzqp.js → chunk-b2ymh8k0.js} +1 -1
- package/dist/bin/chunk-b35989e3.js +50 -0
- package/dist/bin/chunk-c2b6nk0q.js +37 -0
- package/dist/bin/chunk-ckxpgwxw.js +3 -0
- package/dist/bin/chunk-d6zzgvtn.js +92 -0
- package/dist/bin/chunk-da8zpf82.js +1 -0
- package/dist/bin/chunk-ddmjjstg.js +1 -0
- package/dist/bin/chunk-dhhz4zyj.js +1 -0
- package/dist/bin/chunk-dj9a67c3.js +9 -0
- package/dist/bin/chunk-ds1z880f.js +1 -0
- package/dist/bin/chunk-dvkj4k6h.js +111 -0
- package/dist/bin/chunk-eh40fpvj.js +1 -0
- package/dist/bin/chunk-ey9fagrr.js +6 -0
- package/dist/bin/chunk-ezftw2q4.js +1 -0
- package/dist/bin/chunk-g6a4n3rh.js +1 -0
- package/dist/bin/chunk-g90nqfgv.js +585 -0
- package/dist/bin/chunk-gs40j75w.js +1 -0
- package/dist/bin/chunk-jjjts1vt.js +1 -0
- package/dist/bin/{chunk-ry030a6b.js → chunk-jnsbzqzz.js} +30 -30
- package/dist/bin/chunk-jnx4jgw8.js +1 -0
- package/dist/bin/chunk-jt1tndm2.js +3 -0
- package/dist/bin/chunk-kybdb0ws.js +2 -0
- package/dist/bin/chunk-m3nqw76h.js +3 -0
- package/dist/bin/chunk-mn6j22zn.js +6 -0
- package/dist/bin/chunk-nb0yjkv5.js +2 -0
- package/dist/bin/chunk-pjpa4x52.js +2 -0
- package/dist/bin/chunk-pkgkfe6s.js +2 -0
- package/dist/bin/chunk-pnz5hk8n.js +60 -0
- package/dist/bin/chunk-q46zr2tv.js +1 -0
- package/dist/bin/chunk-qtdngvs8.js +1 -0
- package/dist/bin/chunk-sbejksrh.js +2 -0
- package/dist/bin/chunk-svyd4v6c.js +34 -0
- package/dist/bin/chunk-tna7ay8d.js +1 -0
- package/dist/bin/chunk-tp4c2mv1.js +1 -0
- package/dist/bin/chunk-w5d6tr2x.js +1 -0
- package/dist/bin/chunk-wewcjam5.js +1 -0
- package/dist/bin/chunk-xv4bscrm.js +1 -0
- package/dist/bin/chunk-y9eyc5pw.js +1 -0
- package/dist/bin/chunk-y9f8649w.js +512 -0
- package/dist/bin/cli.js +428 -418
- package/dist/bin/dashboard-server.js +1 -1
- package/dist/chunk-06jk7ba9.js +7355 -0
- package/dist/chunk-0e16qt6k.js +5 -0
- package/dist/chunk-13hxhzaz.js +34 -0
- package/dist/chunk-2p89vt3b.js +2 -0
- package/dist/chunk-77t2ctwn.js +2 -0
- package/dist/chunk-88z37ey4.js +114 -0
- package/dist/chunk-8c4715hz.js +2 -0
- package/dist/chunk-9a22225r.js +60 -0
- package/dist/chunk-as6by62d.js +1 -0
- package/dist/chunk-cd0zpxhf.js +44 -0
- package/dist/chunk-cp54a0qn.js +6 -0
- package/dist/chunk-d67xbk4v.js +141 -0
- package/dist/chunk-dckz9xve.js +2 -0
- package/dist/chunk-e1666vjv.js +2 -0
- package/dist/chunk-hhdx5k96.js +442 -0
- package/dist/chunk-kv2ztkp4.js +1617 -0
- package/dist/chunk-nrz6zypg.js +1 -0
- package/dist/chunk-q816js1y.js +1 -0
- package/dist/chunk-qh9ep11z.js +704 -0
- package/dist/chunk-rg720cqg.js +1 -0
- package/dist/chunk-snak8s7m.js +92 -0
- package/dist/chunk-vq737g82.js +1 -0
- package/dist/chunk-xd6w0c11.js +50 -0
- package/dist/chunk-xtwjt370.js +37 -0
- package/dist/chunk-y26yh5zp.js +1 -0
- package/dist/chunk-zmxffmmq.js +4 -0
- package/dist/deploy/attach-credentials.d.ts +4 -8
- package/dist/deploy/index.js +1 -168
- package/dist/dns/cloudflare.d.ts +27 -0
- package/dist/dns/godaddy.d.ts +18 -1
- package/dist/dns/index.d.ts +2 -0
- package/dist/dns/index.js +1 -41
- package/dist/dns/zone-migration.d.ts +92 -0
- package/dist/dns/zone-migration.test.d.ts +1 -0
- package/dist/drivers/hetzner/driver.d.ts +8 -1
- package/dist/drivers/index.js +1 -154
- package/dist/drivers/shared/compute-provision.d.ts +14 -2
- package/dist/drivers/shared/db-provision.d.ts +3 -2
- package/dist/drivers/shared/mail-provision.d.ts +116 -0
- package/dist/drivers/shared/mail-provision.test.d.ts +1 -0
- package/dist/drivers/shared/managed-services-probe.d.ts +47 -0
- package/dist/drivers/shared/managed-services-probe.test.d.ts +1 -0
- package/dist/drivers/shared/package-manager.d.ts +1 -0
- package/dist/drivers/shared/remote-failure.d.ts +21 -0
- package/dist/drivers/shared/remote-failure.test.d.ts +1 -0
- package/dist/drivers/shared/sqlite-shared-path.d.ts +50 -0
- package/dist/drivers/shared/sqlite-shared-path.test.d.ts +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +100 -6129
- package/dist/operations/plan.d.ts +136 -0
- package/dist/operations/plan.test.d.ts +1 -0
- package/dist/operations/server-rename.d.ts +84 -0
- package/dist/operations/server-rename.test.d.ts +1 -0
- package/dist/operations/site-move.d.ts +263 -0
- package/dist/operations/site-move.test.d.ts +1 -0
- package/dist/protection/index.js +1 -89
- package/dist/push/index.js +1 -509
- package/dist/spend/index.js +1 -173
- package/dist/ui/404.html +1 -1
- package/dist/ui/accept-invitation.html +1 -1
- package/dist/ui/access-denied.html +1 -1
- package/dist/ui/account/automation.html +5 -5
- package/dist/ui/account/security.html +2 -2
- package/dist/ui/applications/compose.html +6 -6
- package/dist/ui/applications/new.html +2 -2
- package/dist/ui/data/backups.html +80 -80
- package/dist/ui/data/services.html +78 -78
- package/dist/ui/data/volumes.html +50 -50
- package/dist/ui/index.html +50 -50
- package/dist/ui/infrastructure/topology.html +118 -118
- package/dist/ui/integrations.html +1 -1
- package/dist/ui/operations/alerts.html +47 -47
- package/dist/ui/operations/configuration.html +5 -5
- package/dist/ui/operations/jobs.html +76 -76
- package/dist/ui/operations/maintenance.html +6 -6
- package/dist/ui/operations/observability.html +82 -82
- package/dist/ui/operations/previews.html +5 -5
- package/dist/ui/operations/queue.html +6 -6
- package/dist/ui/operations/regions.html +6 -6
- package/dist/ui/operations/releases.html +6 -6
- package/dist/ui/operations/spend.html +54 -54
- package/dist/ui/operations/workloads.html +104 -104
- package/dist/ui/security.html +2 -2
- package/dist/ui/server/actions.html +56 -56
- package/dist/ui/server/activity.html +1 -1
- package/dist/ui/server/capacity.html +6 -6
- package/dist/ui/server/database.html +106 -106
- package/dist/ui/server/deployments.html +50 -50
- package/dist/ui/server/diagnostics.html +2 -2
- package/dist/ui/server/firewall.html +76 -76
- package/dist/ui/server/fleet.html +34 -34
- package/dist/ui/server/logs.html +24 -24
- package/dist/ui/server/metrics.html +112 -112
- package/dist/ui/server/security.html +1 -1
- package/dist/ui/server/services.html +27 -27
- package/dist/ui/server/sites.html +120 -120
- package/dist/ui/server/ssh-keys.html +51 -51
- package/dist/ui/server/team.html +144 -144
- package/dist/ui/server/terminal.html +15 -15
- package/dist/ui/serverless/alarms.html +52 -52
- package/dist/ui/serverless/assets.html +27 -27
- package/dist/ui/serverless/cost.html +2 -2
- package/dist/ui/serverless/data.html +36 -36
- package/dist/ui/serverless/deployments.html +27 -27
- package/dist/ui/serverless/firewall.html +1 -1
- package/dist/ui/serverless/functions.html +40 -40
- package/dist/ui/serverless/logs.html +24 -24
- package/dist/ui/serverless/metrics.html +2 -2
- package/dist/ui/serverless/queues.html +47 -47
- package/dist/ui/serverless/secrets.html +52 -52
- package/dist/ui/serverless/traces.html +6 -6
- package/dist/ui/serverless.html +54 -54
- package/dist/ui-src/src/charts.ts +17499 -12662
- package/dist/ui-src/src/topology.ts +2 -2
- package/package.json +3 -3
- package/dist/bin/chunk-09nwf2gy.js +0 -34
- package/dist/bin/chunk-14cwr6eh.js +0 -70
- package/dist/bin/chunk-271gk1n2.js +0 -6
- package/dist/bin/chunk-38pq971s.js +0 -2
- package/dist/bin/chunk-3gykfyq4.js +0 -37
- package/dist/bin/chunk-3r4fb59r.js +0 -3
- package/dist/bin/chunk-41x17hw1.js +0 -1
- package/dist/bin/chunk-4vrqm9h0.js +0 -2
- package/dist/bin/chunk-57y1zxbf.js +0 -3
- package/dist/bin/chunk-598yf4bs.js +0 -1
- package/dist/bin/chunk-8v7ddyvf.js +0 -1
- package/dist/bin/chunk-92mea34a.js +0 -1
- package/dist/bin/chunk-9pvsff8g.js +0 -1
- package/dist/bin/chunk-9v39615t.js +0 -1
- package/dist/bin/chunk-avm7tnwe.js +0 -1
- package/dist/bin/chunk-ax9mr6wm.js +0 -44
- package/dist/bin/chunk-axhnkn5g.js +0 -2
- package/dist/bin/chunk-b5gd39s8.js +0 -512
- package/dist/bin/chunk-b9qbp8j1.js +0 -1
- package/dist/bin/chunk-bz828v8q.js +0 -3
- package/dist/bin/chunk-c1vcdgvr.js +0 -1
- package/dist/bin/chunk-ctd2vg9w.js +0 -2
- package/dist/bin/chunk-dbgffky8.js +0 -1
- package/dist/bin/chunk-dwr30vbv.js +0 -1
- package/dist/bin/chunk-e3xrwh9z.js +0 -1
- package/dist/bin/chunk-fhc6ntvd.js +0 -2
- package/dist/bin/chunk-fpm59y25.js +0 -6
- package/dist/bin/chunk-fvbxvq6b.js +0 -1
- package/dist/bin/chunk-fy8j3y8p.js +0 -92
- package/dist/bin/chunk-fz21b57w.js +0 -1
- package/dist/bin/chunk-gavvf0pg.js +0 -141
- package/dist/bin/chunk-ggn7ax8p.js +0 -4
- package/dist/bin/chunk-gpe2prkm.js +0 -1
- package/dist/bin/chunk-gqf6jsmy.js +0 -1
- package/dist/bin/chunk-h5pa5men.js +0 -2
- package/dist/bin/chunk-hm08xdxf.js +0 -2
- package/dist/bin/chunk-hzgz13nf.js +0 -1
- package/dist/bin/chunk-hzqw8xm5.js +0 -111
- package/dist/bin/chunk-j703btc5.js +0 -50
- package/dist/bin/chunk-jpjamjey.js +0 -6935
- package/dist/bin/chunk-m2zwtapr.js +0 -1
- package/dist/bin/chunk-m669wtgr.js +0 -1
- package/dist/bin/chunk-mr0atd2s.js +0 -2
- package/dist/bin/chunk-ngcyftm2.js +0 -1
- package/dist/bin/chunk-p66ptpmr.js +0 -2
- package/dist/bin/chunk-p8q9bq9g.js +0 -1
- package/dist/bin/chunk-r3kv0vm9.js +0 -6
- package/dist/bin/chunk-r9hjwcj9.js +0 -6
- package/dist/bin/chunk-rtczra13.js +0 -1
- package/dist/bin/chunk-rytk89az.js +0 -60
- package/dist/bin/chunk-sgyffpgm.js +0 -581
- package/dist/bin/chunk-vek8a0w6.js +0 -1
- package/dist/bin/chunk-waayf9ay.js +0 -2
- package/dist/bin/chunk-yv9sth30.js +0 -1
- package/dist/chunk-01d86gt1.js +0 -1324
- package/dist/chunk-050r7ycy.js +0 -46516
- package/dist/chunk-1c8dbv57.js +0 -7278
- package/dist/chunk-29rse4p1.js +0 -12203
- package/dist/chunk-32e7ya18.js +0 -642
- package/dist/chunk-4cjrg98a.js +0 -597
- package/dist/chunk-50jpda9q.js +0 -371
- package/dist/chunk-6a1t7fnq.js +0 -12121
- package/dist/chunk-728jvrr0.js +0 -1701
- package/dist/chunk-7m60qnc8.js +0 -1762
- package/dist/chunk-aa2dkn7b.js +0 -205
- package/dist/chunk-d48vtdj4.js +0 -433
- package/dist/chunk-f55nkpvb.js +0 -8
- package/dist/chunk-fgk8cqew.js +0 -152
- package/dist/chunk-he9a874b.js +0 -769
- package/dist/chunk-k2yyatfw.js +0 -10
- package/dist/chunk-k4px0bnv.js +0 -23
- package/dist/chunk-nsgqsmrh.js +0 -1779
- package/dist/chunk-q0st3se8.js +0 -42033
- package/dist/chunk-qr803fye.js +0 -2122
- package/dist/chunk-rds0sy87.js +0 -1771
- package/dist/chunk-ttz2ra5j.js +0 -12
- package/dist/chunk-v0bahtg2.js +0 -4
- package/dist/chunk-va2yd85b.js +0 -200
- package/dist/chunk-x9s0cqfx.js +0 -13
- package/dist/chunk-zqtpg06c.js +0 -1752
package/dist/push/index.js
CHANGED
|
@@ -1,509 +1 @@
|
|
|
1
|
-
import"../chunk-
|
|
2
|
-
|
|
3
|
-
// src/push/apns.ts
|
|
4
|
-
import * as http2 from "node:http2";
|
|
5
|
-
import { createSign } from "node:crypto";
|
|
6
|
-
var APNS_PRODUCTION_HOST = "api.push.apple.com";
|
|
7
|
-
var APNS_SANDBOX_HOST = "api.sandbox.push.apple.com";
|
|
8
|
-
var TOKEN_EXPIRY_MS = 45 * 60 * 1000;
|
|
9
|
-
|
|
10
|
-
class APNsClient {
|
|
11
|
-
config;
|
|
12
|
-
token = null;
|
|
13
|
-
tokenGeneratedAt = 0;
|
|
14
|
-
client = null;
|
|
15
|
-
host;
|
|
16
|
-
constructor(config) {
|
|
17
|
-
this.config = config;
|
|
18
|
-
this.host = config.production ? APNS_PRODUCTION_HOST : APNS_SANDBOX_HOST;
|
|
19
|
-
}
|
|
20
|
-
generateToken() {
|
|
21
|
-
const now = Math.floor(Date.now() / 1000);
|
|
22
|
-
if (this.token && Date.now() - this.tokenGeneratedAt < TOKEN_EXPIRY_MS) {
|
|
23
|
-
return this.token;
|
|
24
|
-
}
|
|
25
|
-
const header = {
|
|
26
|
-
alg: "ES256",
|
|
27
|
-
kid: this.config.keyId
|
|
28
|
-
};
|
|
29
|
-
const payload = {
|
|
30
|
-
iss: this.config.teamId,
|
|
31
|
-
iat: now
|
|
32
|
-
};
|
|
33
|
-
const encodedHeader = Buffer.from(JSON.stringify(header)).toString("base64url");
|
|
34
|
-
const encodedPayload = Buffer.from(JSON.stringify(payload)).toString("base64url");
|
|
35
|
-
const signatureInput = `${encodedHeader}.${encodedPayload}`;
|
|
36
|
-
const sign = createSign("SHA256");
|
|
37
|
-
sign.update(signatureInput);
|
|
38
|
-
const signature = sign.sign(this.config.privateKey);
|
|
39
|
-
const rawSignature = this.derToRaw(signature);
|
|
40
|
-
const encodedSignature = rawSignature.toString("base64url");
|
|
41
|
-
this.token = `${signatureInput}.${encodedSignature}`;
|
|
42
|
-
this.tokenGeneratedAt = Date.now();
|
|
43
|
-
return this.token;
|
|
44
|
-
}
|
|
45
|
-
derToRaw(derSignature) {
|
|
46
|
-
let offset = 2;
|
|
47
|
-
if (derSignature[offset] !== 2) {
|
|
48
|
-
throw new Error("Invalid DER signature: expected 0x02 for R");
|
|
49
|
-
}
|
|
50
|
-
offset++;
|
|
51
|
-
const rLength = derSignature[offset];
|
|
52
|
-
offset++;
|
|
53
|
-
let r = derSignature.subarray(offset, offset + rLength);
|
|
54
|
-
offset += rLength;
|
|
55
|
-
if (derSignature[offset] !== 2) {
|
|
56
|
-
throw new Error("Invalid DER signature: expected 0x02 for S");
|
|
57
|
-
}
|
|
58
|
-
offset++;
|
|
59
|
-
const sLength = derSignature[offset];
|
|
60
|
-
offset++;
|
|
61
|
-
let s = derSignature.subarray(offset, offset + sLength);
|
|
62
|
-
if (r[0] === 0 && r.length === 33) {
|
|
63
|
-
r = r.subarray(1);
|
|
64
|
-
}
|
|
65
|
-
if (s[0] === 0 && s.length === 33) {
|
|
66
|
-
s = s.subarray(1);
|
|
67
|
-
}
|
|
68
|
-
const result = Buffer.alloc(64);
|
|
69
|
-
r.copy(result, 32 - r.length);
|
|
70
|
-
s.copy(result, 64 - s.length);
|
|
71
|
-
return result;
|
|
72
|
-
}
|
|
73
|
-
async getClient() {
|
|
74
|
-
if (this.client && !this.client.destroyed) {
|
|
75
|
-
return this.client;
|
|
76
|
-
}
|
|
77
|
-
return new Promise((resolve, reject) => {
|
|
78
|
-
this.client = http2.connect(`https://${this.host}`);
|
|
79
|
-
this.client.on("error", (err) => {
|
|
80
|
-
reject(err);
|
|
81
|
-
});
|
|
82
|
-
this.client.on("connect", () => {
|
|
83
|
-
resolve(this.client);
|
|
84
|
-
});
|
|
85
|
-
this.client.on("close", () => {
|
|
86
|
-
this.client = null;
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
buildPayload(notification) {
|
|
91
|
-
const aps = {};
|
|
92
|
-
if (notification.title || notification.body || notification.subtitle) {
|
|
93
|
-
aps.alert = {};
|
|
94
|
-
if (notification.title)
|
|
95
|
-
aps.alert.title = notification.title;
|
|
96
|
-
if (notification.subtitle)
|
|
97
|
-
aps.alert.subtitle = notification.subtitle;
|
|
98
|
-
if (notification.body)
|
|
99
|
-
aps.alert.body = notification.body;
|
|
100
|
-
}
|
|
101
|
-
if (notification.badge !== undefined) {
|
|
102
|
-
aps.badge = notification.badge;
|
|
103
|
-
}
|
|
104
|
-
if (notification.sound !== undefined) {
|
|
105
|
-
aps.sound = notification.sound;
|
|
106
|
-
}
|
|
107
|
-
if (notification.category) {
|
|
108
|
-
aps.category = notification.category;
|
|
109
|
-
}
|
|
110
|
-
if (notification.threadId) {
|
|
111
|
-
aps["thread-id"] = notification.threadId;
|
|
112
|
-
}
|
|
113
|
-
if (notification.contentAvailable) {
|
|
114
|
-
aps["content-available"] = 1;
|
|
115
|
-
}
|
|
116
|
-
if (notification.mutableContent) {
|
|
117
|
-
aps["mutable-content"] = 1;
|
|
118
|
-
}
|
|
119
|
-
if (notification.targetContentId) {
|
|
120
|
-
aps["target-content-id"] = notification.targetContentId;
|
|
121
|
-
}
|
|
122
|
-
const payload = { aps };
|
|
123
|
-
if (notification.data) {
|
|
124
|
-
Object.assign(payload, notification.data);
|
|
125
|
-
}
|
|
126
|
-
return payload;
|
|
127
|
-
}
|
|
128
|
-
async send(notification) {
|
|
129
|
-
try {
|
|
130
|
-
const client = await this.getClient();
|
|
131
|
-
const token = this.generateToken();
|
|
132
|
-
const payload = JSON.stringify(this.buildPayload(notification));
|
|
133
|
-
const headers = {
|
|
134
|
-
":method": "POST",
|
|
135
|
-
":path": `/3/device/${notification.deviceToken}`,
|
|
136
|
-
authorization: `bearer ${token}`,
|
|
137
|
-
"apns-topic": this.config.bundleId,
|
|
138
|
-
"apns-push-type": notification.pushType || "alert",
|
|
139
|
-
"apns-priority": String(notification.priority || 10)
|
|
140
|
-
};
|
|
141
|
-
if (notification.expiration !== undefined) {
|
|
142
|
-
headers["apns-expiration"] = String(notification.expiration);
|
|
143
|
-
}
|
|
144
|
-
if (notification.collapseId) {
|
|
145
|
-
headers["apns-collapse-id"] = notification.collapseId;
|
|
146
|
-
}
|
|
147
|
-
return new Promise((resolve) => {
|
|
148
|
-
const req = client.request(headers);
|
|
149
|
-
let responseData = "";
|
|
150
|
-
let statusCode = 0;
|
|
151
|
-
let apnsId;
|
|
152
|
-
req.on("response", (headers2) => {
|
|
153
|
-
statusCode = headers2[":status"];
|
|
154
|
-
apnsId = headers2["apns-id"];
|
|
155
|
-
});
|
|
156
|
-
req.on("data", (chunk) => {
|
|
157
|
-
responseData += chunk.toString();
|
|
158
|
-
});
|
|
159
|
-
req.on("end", () => {
|
|
160
|
-
if (statusCode === 200) {
|
|
161
|
-
resolve({
|
|
162
|
-
success: true,
|
|
163
|
-
deviceToken: notification.deviceToken,
|
|
164
|
-
apnsId,
|
|
165
|
-
statusCode
|
|
166
|
-
});
|
|
167
|
-
} else {
|
|
168
|
-
let error = "Unknown error";
|
|
169
|
-
let reason;
|
|
170
|
-
let timestamp;
|
|
171
|
-
if (responseData) {
|
|
172
|
-
try {
|
|
173
|
-
const parsed = JSON.parse(responseData);
|
|
174
|
-
reason = parsed.reason;
|
|
175
|
-
timestamp = parsed.timestamp;
|
|
176
|
-
error = reason || error;
|
|
177
|
-
} catch {
|
|
178
|
-
error = responseData;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
resolve({
|
|
182
|
-
success: false,
|
|
183
|
-
deviceToken: notification.deviceToken,
|
|
184
|
-
apnsId,
|
|
185
|
-
statusCode,
|
|
186
|
-
error,
|
|
187
|
-
reason,
|
|
188
|
-
timestamp
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
});
|
|
192
|
-
req.on("error", (err) => {
|
|
193
|
-
resolve({
|
|
194
|
-
success: false,
|
|
195
|
-
deviceToken: notification.deviceToken,
|
|
196
|
-
error: err.message
|
|
197
|
-
});
|
|
198
|
-
});
|
|
199
|
-
req.write(payload);
|
|
200
|
-
req.end();
|
|
201
|
-
});
|
|
202
|
-
} catch (error) {
|
|
203
|
-
return {
|
|
204
|
-
success: false,
|
|
205
|
-
deviceToken: notification.deviceToken,
|
|
206
|
-
error: error.message
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
async sendBatch(notifications, options) {
|
|
211
|
-
const concurrency = options?.concurrency || 10;
|
|
212
|
-
const results = [];
|
|
213
|
-
for (let i = 0;i < notifications.length; i += concurrency) {
|
|
214
|
-
const batch = notifications.slice(i, i + concurrency);
|
|
215
|
-
const batchResults = await Promise.all(batch.map((n) => this.send(n)));
|
|
216
|
-
results.push(...batchResults);
|
|
217
|
-
}
|
|
218
|
-
return {
|
|
219
|
-
sent: results.filter((r) => r.success).length,
|
|
220
|
-
failed: results.filter((r) => !r.success).length,
|
|
221
|
-
results
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
async sendSimple(deviceToken, title, body, data) {
|
|
225
|
-
return this.send({
|
|
226
|
-
deviceToken,
|
|
227
|
-
title,
|
|
228
|
-
body,
|
|
229
|
-
data
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
async sendSilent(deviceToken, data) {
|
|
233
|
-
return this.send({
|
|
234
|
-
deviceToken,
|
|
235
|
-
contentAvailable: true,
|
|
236
|
-
pushType: "background",
|
|
237
|
-
priority: 5,
|
|
238
|
-
data
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
close() {
|
|
242
|
-
if (this.client) {
|
|
243
|
-
this.client.close();
|
|
244
|
-
this.client = null;
|
|
245
|
-
}
|
|
246
|
-
this.token = null;
|
|
247
|
-
this.tokenGeneratedAt = 0;
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
// src/push/fcm.ts
|
|
251
|
-
import { createSign as createSign2 } from "node:crypto";
|
|
252
|
-
var FCM_API_URL = "https://fcm.googleapis.com/v1/projects";
|
|
253
|
-
var GOOGLE_TOKEN_URL = "https://oauth2.googleapis.com/token";
|
|
254
|
-
var TOKEN_EXPIRY_MS2 = 55 * 60 * 1000;
|
|
255
|
-
|
|
256
|
-
class FCMClient {
|
|
257
|
-
config;
|
|
258
|
-
accessToken = null;
|
|
259
|
-
tokenExpiresAt = 0;
|
|
260
|
-
constructor(config) {
|
|
261
|
-
this.config = config;
|
|
262
|
-
}
|
|
263
|
-
static fromServiceAccount(serviceAccount) {
|
|
264
|
-
return new FCMClient({
|
|
265
|
-
projectId: serviceAccount.project_id,
|
|
266
|
-
clientEmail: serviceAccount.client_email,
|
|
267
|
-
privateKey: serviceAccount.private_key
|
|
268
|
-
});
|
|
269
|
-
}
|
|
270
|
-
generateJWT() {
|
|
271
|
-
const now = Math.floor(Date.now() / 1000);
|
|
272
|
-
const exp = now + 3600;
|
|
273
|
-
const header = {
|
|
274
|
-
alg: "RS256",
|
|
275
|
-
typ: "JWT"
|
|
276
|
-
};
|
|
277
|
-
const payload = {
|
|
278
|
-
iss: this.config.clientEmail,
|
|
279
|
-
sub: this.config.clientEmail,
|
|
280
|
-
aud: GOOGLE_TOKEN_URL,
|
|
281
|
-
iat: now,
|
|
282
|
-
exp,
|
|
283
|
-
scope: "https://www.googleapis.com/auth/firebase.messaging"
|
|
284
|
-
};
|
|
285
|
-
const encodedHeader = Buffer.from(JSON.stringify(header)).toString("base64url");
|
|
286
|
-
const encodedPayload = Buffer.from(JSON.stringify(payload)).toString("base64url");
|
|
287
|
-
const signatureInput = `${encodedHeader}.${encodedPayload}`;
|
|
288
|
-
const sign = createSign2("SHA256");
|
|
289
|
-
sign.update(signatureInput);
|
|
290
|
-
const signature = sign.sign(this.config.privateKey, "base64url");
|
|
291
|
-
return `${signatureInput}.${signature}`;
|
|
292
|
-
}
|
|
293
|
-
async getAccessToken() {
|
|
294
|
-
if (this.accessToken && Date.now() < this.tokenExpiresAt) {
|
|
295
|
-
return this.accessToken;
|
|
296
|
-
}
|
|
297
|
-
const jwt = this.generateJWT();
|
|
298
|
-
const response = await fetch(GOOGLE_TOKEN_URL, {
|
|
299
|
-
method: "POST",
|
|
300
|
-
headers: {
|
|
301
|
-
"Content-Type": "application/x-www-form-urlencoded"
|
|
302
|
-
},
|
|
303
|
-
body: new URLSearchParams({
|
|
304
|
-
grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer",
|
|
305
|
-
assertion: jwt
|
|
306
|
-
}).toString()
|
|
307
|
-
});
|
|
308
|
-
if (!response.ok) {
|
|
309
|
-
const errorText = await response.text();
|
|
310
|
-
throw new Error(`Failed to get access token: ${errorText}`);
|
|
311
|
-
}
|
|
312
|
-
const data = await response.json();
|
|
313
|
-
this.accessToken = data.access_token;
|
|
314
|
-
this.tokenExpiresAt = Date.now() + TOKEN_EXPIRY_MS2;
|
|
315
|
-
return this.accessToken;
|
|
316
|
-
}
|
|
317
|
-
buildMessage(notification) {
|
|
318
|
-
const message = {};
|
|
319
|
-
if (notification.token) {
|
|
320
|
-
message.token = notification.token;
|
|
321
|
-
} else if (notification.topic) {
|
|
322
|
-
message.topic = notification.topic;
|
|
323
|
-
} else if (notification.condition) {
|
|
324
|
-
message.condition = notification.condition;
|
|
325
|
-
}
|
|
326
|
-
if (notification.title || notification.body || notification.imageUrl) {
|
|
327
|
-
message.notification = {};
|
|
328
|
-
if (notification.title)
|
|
329
|
-
message.notification.title = notification.title;
|
|
330
|
-
if (notification.body)
|
|
331
|
-
message.notification.body = notification.body;
|
|
332
|
-
if (notification.imageUrl)
|
|
333
|
-
message.notification.image = notification.imageUrl;
|
|
334
|
-
}
|
|
335
|
-
if (notification.data && Object.keys(notification.data).length > 0) {
|
|
336
|
-
message.data = notification.data;
|
|
337
|
-
}
|
|
338
|
-
if (notification.android) {
|
|
339
|
-
message.android = {
|
|
340
|
-
priority: notification.android.priority || "high"
|
|
341
|
-
};
|
|
342
|
-
if (notification.android.ttl) {
|
|
343
|
-
message.android.ttl = `${notification.android.ttl}s`;
|
|
344
|
-
}
|
|
345
|
-
if (notification.android.collapseKey) {
|
|
346
|
-
message.android.collapse_key = notification.android.collapseKey;
|
|
347
|
-
}
|
|
348
|
-
if (notification.android.directBootOk) {
|
|
349
|
-
message.android.direct_boot_ok = notification.android.directBootOk;
|
|
350
|
-
}
|
|
351
|
-
const androidNotification = {};
|
|
352
|
-
if (notification.android.channelId)
|
|
353
|
-
androidNotification.channel_id = notification.android.channelId;
|
|
354
|
-
if (notification.android.icon)
|
|
355
|
-
androidNotification.icon = notification.android.icon;
|
|
356
|
-
if (notification.android.color)
|
|
357
|
-
androidNotification.color = notification.android.color;
|
|
358
|
-
if (notification.android.sound)
|
|
359
|
-
androidNotification.sound = notification.android.sound;
|
|
360
|
-
if (notification.android.clickAction)
|
|
361
|
-
androidNotification.click_action = notification.android.clickAction;
|
|
362
|
-
if (notification.android.tag)
|
|
363
|
-
androidNotification.tag = notification.android.tag;
|
|
364
|
-
if (notification.android.visibility)
|
|
365
|
-
androidNotification.visibility = notification.android.visibility;
|
|
366
|
-
if (notification.android.notificationCount !== undefined) {
|
|
367
|
-
androidNotification.notification_count = notification.android.notificationCount;
|
|
368
|
-
}
|
|
369
|
-
if (Object.keys(androidNotification).length > 0) {
|
|
370
|
-
message.android.notification = androidNotification;
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
if (notification.webpush) {
|
|
374
|
-
message.webpush = notification.webpush;
|
|
375
|
-
}
|
|
376
|
-
if (notification.apns) {
|
|
377
|
-
message.apns = notification.apns;
|
|
378
|
-
}
|
|
379
|
-
if (notification.fcmOptions) {
|
|
380
|
-
message.fcm_options = notification.fcmOptions;
|
|
381
|
-
}
|
|
382
|
-
return { message };
|
|
383
|
-
}
|
|
384
|
-
async send(notification) {
|
|
385
|
-
try {
|
|
386
|
-
const accessToken = await this.getAccessToken();
|
|
387
|
-
const payload = this.buildMessage(notification);
|
|
388
|
-
const response = await fetch(`${FCM_API_URL}/${this.config.projectId}/messages:send`, {
|
|
389
|
-
method: "POST",
|
|
390
|
-
headers: {
|
|
391
|
-
Authorization: `Bearer ${accessToken}`,
|
|
392
|
-
"Content-Type": "application/json"
|
|
393
|
-
},
|
|
394
|
-
body: JSON.stringify(payload)
|
|
395
|
-
});
|
|
396
|
-
const data = await response.json();
|
|
397
|
-
if (response.ok) {
|
|
398
|
-
return {
|
|
399
|
-
success: true,
|
|
400
|
-
messageId: data.name
|
|
401
|
-
};
|
|
402
|
-
} else {
|
|
403
|
-
return {
|
|
404
|
-
success: false,
|
|
405
|
-
error: data.error?.message || "Unknown error",
|
|
406
|
-
errorCode: data.error?.status
|
|
407
|
-
};
|
|
408
|
-
}
|
|
409
|
-
} catch (error) {
|
|
410
|
-
return {
|
|
411
|
-
success: false,
|
|
412
|
-
error: error.message
|
|
413
|
-
};
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
async sendBatch(tokens, notification, options) {
|
|
417
|
-
const concurrency = options?.concurrency || 10;
|
|
418
|
-
const results = [];
|
|
419
|
-
for (let i = 0;i < tokens.length; i += concurrency) {
|
|
420
|
-
const batch = tokens.slice(i, i + concurrency);
|
|
421
|
-
const batchPromises = batch.map(async (token) => {
|
|
422
|
-
const result = await this.send({ ...notification, token });
|
|
423
|
-
return { ...result, token };
|
|
424
|
-
});
|
|
425
|
-
const batchResults = await Promise.all(batchPromises);
|
|
426
|
-
results.push(...batchResults);
|
|
427
|
-
}
|
|
428
|
-
return {
|
|
429
|
-
sent: results.filter((r) => r.success).length,
|
|
430
|
-
failed: results.filter((r) => !r.success).length,
|
|
431
|
-
results
|
|
432
|
-
};
|
|
433
|
-
}
|
|
434
|
-
async sendToTopic(topic, notification) {
|
|
435
|
-
return this.send({ ...notification, topic });
|
|
436
|
-
}
|
|
437
|
-
async sendToCondition(condition, notification) {
|
|
438
|
-
return this.send({ ...notification, condition });
|
|
439
|
-
}
|
|
440
|
-
async sendSimple(token, title, body, data) {
|
|
441
|
-
return this.send({
|
|
442
|
-
token,
|
|
443
|
-
title,
|
|
444
|
-
body,
|
|
445
|
-
data
|
|
446
|
-
});
|
|
447
|
-
}
|
|
448
|
-
async sendSilent(token, data) {
|
|
449
|
-
return this.send({
|
|
450
|
-
token,
|
|
451
|
-
data,
|
|
452
|
-
android: {
|
|
453
|
-
priority: "high"
|
|
454
|
-
}
|
|
455
|
-
});
|
|
456
|
-
}
|
|
457
|
-
async subscribeToTopic(tokens, topic) {
|
|
458
|
-
try {
|
|
459
|
-
const accessToken = await this.getAccessToken();
|
|
460
|
-
const response = await fetch(`https://iid.googleapis.com/iid/v1:batchAdd`, {
|
|
461
|
-
method: "POST",
|
|
462
|
-
headers: {
|
|
463
|
-
Authorization: `Bearer ${accessToken}`,
|
|
464
|
-
"Content-Type": "application/json"
|
|
465
|
-
},
|
|
466
|
-
body: JSON.stringify({
|
|
467
|
-
to: `/topics/${topic}`,
|
|
468
|
-
registration_tokens: tokens
|
|
469
|
-
})
|
|
470
|
-
});
|
|
471
|
-
if (response.ok) {
|
|
472
|
-
return { success: true };
|
|
473
|
-
} else {
|
|
474
|
-
const data = await response.json();
|
|
475
|
-
return { success: false, error: data.error?.message || "Failed to subscribe" };
|
|
476
|
-
}
|
|
477
|
-
} catch (error) {
|
|
478
|
-
return { success: false, error: error.message };
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
async unsubscribeFromTopic(tokens, topic) {
|
|
482
|
-
try {
|
|
483
|
-
const accessToken = await this.getAccessToken();
|
|
484
|
-
const response = await fetch(`https://iid.googleapis.com/iid/v1:batchRemove`, {
|
|
485
|
-
method: "POST",
|
|
486
|
-
headers: {
|
|
487
|
-
Authorization: `Bearer ${accessToken}`,
|
|
488
|
-
"Content-Type": "application/json"
|
|
489
|
-
},
|
|
490
|
-
body: JSON.stringify({
|
|
491
|
-
to: `/topics/${topic}`,
|
|
492
|
-
registration_tokens: tokens
|
|
493
|
-
})
|
|
494
|
-
});
|
|
495
|
-
if (response.ok) {
|
|
496
|
-
return { success: true };
|
|
497
|
-
} else {
|
|
498
|
-
const data = await response.json();
|
|
499
|
-
return { success: false, error: data.error?.message || "Failed to unsubscribe" };
|
|
500
|
-
}
|
|
501
|
-
} catch (error) {
|
|
502
|
-
return { success: false, error: error.message };
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
export {
|
|
507
|
-
FCMClient,
|
|
508
|
-
APNsClient
|
|
509
|
-
};
|
|
1
|
+
import"../chunk-77t2ctwn.js";import*as h from"node:http2";import{createSign as b}from"node:crypto";var f="api.push.apple.com",k="api.sandbox.push.apple.com",S=2700000;class R{config;token=null;tokenGeneratedAt=0;client=null;host;constructor(e){this.config=e,this.host=e.production?f:k}generateToken(){let e=Math.floor(Date.now()/1000);if(this.token&&Date.now()-this.tokenGeneratedAt<S)return this.token;let t={alg:"ES256",kid:this.config.keyId},s={iss:this.config.teamId,iat:e},r=Buffer.from(JSON.stringify(t)).toString("base64url"),n=Buffer.from(JSON.stringify(s)).toString("base64url"),i=`${r}.${n}`,o=b("SHA256");o.update(i);let a=o.sign(this.config.privateKey),l=this.derToRaw(a).toString("base64url");return this.token=`${i}.${l}`,this.tokenGeneratedAt=Date.now(),this.token}derToRaw(e){let t=2;if(e[t]!==2)throw Error("Invalid DER signature: expected 0x02 for R");t++;let s=e[t];t++;let r=e.subarray(t,t+s);if(t+=s,e[t]!==2)throw Error("Invalid DER signature: expected 0x02 for S");t++;let n=e[t];t++;let i=e.subarray(t,t+n);if(r[0]===0&&r.length===33)r=r.subarray(1);if(i[0]===0&&i.length===33)i=i.subarray(1);let o=Buffer.alloc(64);return r.copy(o,32-r.length),i.copy(o,64-i.length),o}async getClient(){if(this.client&&!this.client.destroyed)return this.client;return new Promise((e,t)=>{this.client=h.connect(`https://${this.host}`),this.client.on("error",(s)=>{t(s)}),this.client.on("connect",()=>{e(this.client)}),this.client.on("close",()=>{this.client=null})})}buildPayload(e){let t={};if(e.title||e.body||e.subtitle){if(t.alert={},e.title)t.alert.title=e.title;if(e.subtitle)t.alert.subtitle=e.subtitle;if(e.body)t.alert.body=e.body}if(e.badge!==void 0)t.badge=e.badge;if(e.sound!==void 0)t.sound=e.sound;if(e.category)t.category=e.category;if(e.threadId)t["thread-id"]=e.threadId;if(e.contentAvailable)t["content-available"]=1;if(e.mutableContent)t["mutable-content"]=1;if(e.targetContentId)t["target-content-id"]=e.targetContentId;let s={aps:t};if(e.data)Object.assign(s,e.data);return s}async send(e){try{let t=await this.getClient(),s=this.generateToken(),r=JSON.stringify(this.buildPayload(e)),n={":method":"POST",":path":`/3/device/${e.deviceToken}`,authorization:`bearer ${s}`,"apns-topic":this.config.bundleId,"apns-push-type":e.pushType||"alert","apns-priority":String(e.priority||10)};if(e.expiration!==void 0)n["apns-expiration"]=String(e.expiration);if(e.collapseId)n["apns-collapse-id"]=e.collapseId;return new Promise((i)=>{let o=t.request(n),a="",d=0,l;o.on("response",(c)=>{d=c[":status"],l=c["apns-id"]}),o.on("data",(c)=>{a+=c.toString()}),o.on("end",()=>{if(d===200)i({success:!0,deviceToken:e.deviceToken,apnsId:l,statusCode:d});else{let c="Unknown error",g,u;if(a)try{let p=JSON.parse(a);g=p.reason,u=p.timestamp,c=g||c}catch{c=a}i({success:!1,deviceToken:e.deviceToken,apnsId:l,statusCode:d,error:c,reason:g,timestamp:u})}}),o.on("error",(c)=>{i({success:!1,deviceToken:e.deviceToken,error:c.message})}),o.write(r),o.end()})}catch(t){return{success:!1,deviceToken:e.deviceToken,error:t.message}}}async sendBatch(e,t){let s=t?.concurrency||10,r=[];for(let n=0;n<e.length;n+=s){let i=e.slice(n,n+s),o=await Promise.all(i.map((a)=>this.send(a)));r.push(...o)}return{sent:r.filter((n)=>n.success).length,failed:r.filter((n)=>!n.success).length,results:r}}async sendSimple(e,t,s,r){return this.send({deviceToken:e,title:t,body:s,data:r})}async sendSilent(e,t){return this.send({deviceToken:e,contentAvailable:!0,pushType:"background",priority:5,data:t})}close(){if(this.client)this.client.close(),this.client=null;this.token=null,this.tokenGeneratedAt=0}}import{createSign as T}from"node:crypto";var C="https://fcm.googleapis.com/v1/projects",y="https://oauth2.googleapis.com/token",P=3300000;class m{config;accessToken=null;tokenExpiresAt=0;constructor(e){this.config=e}static fromServiceAccount(e){return new m({projectId:e.project_id,clientEmail:e.client_email,privateKey:e.private_key})}generateJWT(){let e=Math.floor(Date.now()/1000),t=e+3600,s={alg:"RS256",typ:"JWT"},r={iss:this.config.clientEmail,sub:this.config.clientEmail,aud:y,iat:e,exp:t,scope:"https://www.googleapis.com/auth/firebase.messaging"},n=Buffer.from(JSON.stringify(s)).toString("base64url"),i=Buffer.from(JSON.stringify(r)).toString("base64url"),o=`${n}.${i}`,a=T("SHA256");a.update(o);let d=a.sign(this.config.privateKey,"base64url");return`${o}.${d}`}async getAccessToken(){if(this.accessToken&&Date.now()<this.tokenExpiresAt)return this.accessToken;let e=this.generateJWT(),t=await fetch(y,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({grant_type:"urn:ietf:params:oauth:grant-type:jwt-bearer",assertion:e}).toString()});if(!t.ok){let r=await t.text();throw Error(`Failed to get access token: ${r}`)}let s=await t.json();return this.accessToken=s.access_token,this.tokenExpiresAt=Date.now()+P,this.accessToken}buildMessage(e){let t={};if(e.token)t.token=e.token;else if(e.topic)t.topic=e.topic;else if(e.condition)t.condition=e.condition;if(e.title||e.body||e.imageUrl){if(t.notification={},e.title)t.notification.title=e.title;if(e.body)t.notification.body=e.body;if(e.imageUrl)t.notification.image=e.imageUrl}if(e.data&&Object.keys(e.data).length>0)t.data=e.data;if(e.android){if(t.android={priority:e.android.priority||"high"},e.android.ttl)t.android.ttl=`${e.android.ttl}s`;if(e.android.collapseKey)t.android.collapse_key=e.android.collapseKey;if(e.android.directBootOk)t.android.direct_boot_ok=e.android.directBootOk;let s={};if(e.android.channelId)s.channel_id=e.android.channelId;if(e.android.icon)s.icon=e.android.icon;if(e.android.color)s.color=e.android.color;if(e.android.sound)s.sound=e.android.sound;if(e.android.clickAction)s.click_action=e.android.clickAction;if(e.android.tag)s.tag=e.android.tag;if(e.android.visibility)s.visibility=e.android.visibility;if(e.android.notificationCount!==void 0)s.notification_count=e.android.notificationCount;if(Object.keys(s).length>0)t.android.notification=s}if(e.webpush)t.webpush=e.webpush;if(e.apns)t.apns=e.apns;if(e.fcmOptions)t.fcm_options=e.fcmOptions;return{message:t}}async send(e){try{let t=await this.getAccessToken(),s=this.buildMessage(e),r=await fetch(`${C}/${this.config.projectId}/messages:send`,{method:"POST",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify(s)}),n=await r.json();if(r.ok)return{success:!0,messageId:n.name};else return{success:!1,error:n.error?.message||"Unknown error",errorCode:n.error?.status}}catch(t){return{success:!1,error:t.message}}}async sendBatch(e,t,s){let r=s?.concurrency||10,n=[];for(let i=0;i<e.length;i+=r){let a=e.slice(i,i+r).map(async(l)=>({...await this.send({...t,token:l}),token:l})),d=await Promise.all(a);n.push(...d)}return{sent:n.filter((i)=>i.success).length,failed:n.filter((i)=>!i.success).length,results:n}}async sendToTopic(e,t){return this.send({...t,topic:e})}async sendToCondition(e,t){return this.send({...t,condition:e})}async sendSimple(e,t,s,r){return this.send({token:e,title:t,body:s,data:r})}async sendSilent(e,t){return this.send({token:e,data:t,android:{priority:"high"}})}async subscribeToTopic(e,t){try{let s=await this.getAccessToken(),r=await fetch("https://iid.googleapis.com/iid/v1:batchAdd",{method:"POST",headers:{Authorization:`Bearer ${s}`,"Content-Type":"application/json"},body:JSON.stringify({to:`/topics/${t}`,registration_tokens:e})});if(r.ok)return{success:!0};else return{success:!1,error:(await r.json()).error?.message||"Failed to subscribe"}}catch(s){return{success:!1,error:s.message}}}async unsubscribeFromTopic(e,t){try{let s=await this.getAccessToken(),r=await fetch("https://iid.googleapis.com/iid/v1:batchRemove",{method:"POST",headers:{Authorization:`Bearer ${s}`,"Content-Type":"application/json"},body:JSON.stringify({to:`/topics/${t}`,registration_tokens:e})});if(r.ok)return{success:!0};else return{success:!1,error:(await r.json()).error?.message||"Failed to unsubscribe"}}catch(s){return{success:!1,error:s.message}}}}export{R as APNsClient,m as FCMClient};
|
package/dist/spend/index.js
CHANGED
|
@@ -1,173 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AnomalyConfigStore,
|
|
3
|
-
AwsSpendTransport,
|
|
4
|
-
ComputeSpendTransport,
|
|
5
|
-
CounterTracker,
|
|
6
|
-
DEFAULT_METER_MAPPINGS,
|
|
7
|
-
DEFAULT_PRICE_BOOK,
|
|
8
|
-
DEFAULT_THRESHOLDS,
|
|
9
|
-
DETECTABLE_SIGNALS,
|
|
10
|
-
ENFORCEMENT_ACTIONS,
|
|
11
|
-
ENFORCEMENT_DESCRIPTIONS,
|
|
12
|
-
ENFORCEMENT_SEVERITY,
|
|
13
|
-
FOCUS_VERSION,
|
|
14
|
-
METERS,
|
|
15
|
-
METER_KEYS,
|
|
16
|
-
MICRO_CENTS,
|
|
17
|
-
MIN_PROJECTION_CONFIDENCE,
|
|
18
|
-
RecordingSpendTransport,
|
|
19
|
-
SENSITIVITY_THRESHOLDS,
|
|
20
|
-
SPEND_CYCLE_SECONDS,
|
|
21
|
-
SPEND_GATE_SETTING,
|
|
22
|
-
SPEND_LEASE_SETTING,
|
|
23
|
-
SignalSource,
|
|
24
|
-
SpendCapError,
|
|
25
|
-
SpendGate,
|
|
26
|
-
SpendLoopLease,
|
|
27
|
-
SpendNotificationRouter,
|
|
28
|
-
SpendRunner,
|
|
29
|
-
SpendService,
|
|
30
|
-
SpendStore,
|
|
31
|
-
URGENT_SPEND_EVENTS,
|
|
32
|
-
USER_VISIBLE_ACTIONS,
|
|
33
|
-
aggregateDeltas,
|
|
34
|
-
anomalyOptionsForSignal,
|
|
35
|
-
assertSpendAllows,
|
|
36
|
-
budgetWindow,
|
|
37
|
-
compositeSpendTransport,
|
|
38
|
-
createEnforcementHandlers,
|
|
39
|
-
detectAnomalies,
|
|
40
|
-
detectLatestAnomaly,
|
|
41
|
-
evaluateBudget,
|
|
42
|
-
ewma,
|
|
43
|
-
findMapping,
|
|
44
|
-
findPriceEntry,
|
|
45
|
-
formatCents,
|
|
46
|
-
formatTimeToExhaustion,
|
|
47
|
-
governingLimitCents,
|
|
48
|
-
handleSpendRequest,
|
|
49
|
-
hourBucket,
|
|
50
|
-
hourBucketsBetween,
|
|
51
|
-
isOperationAllowed,
|
|
52
|
-
isValidTimeZone,
|
|
53
|
-
lookbackHoursForSignal,
|
|
54
|
-
median,
|
|
55
|
-
medianAbsoluteDeviation,
|
|
56
|
-
mergeDecisions,
|
|
57
|
-
mergePriceBooks,
|
|
58
|
-
meterTelemetry,
|
|
59
|
-
optionsForSignal,
|
|
60
|
-
percentOfLimit,
|
|
61
|
-
planEnforcement,
|
|
62
|
-
previousBudgetWindow,
|
|
63
|
-
priceUsage,
|
|
64
|
-
priceUsageLines,
|
|
65
|
-
projectSpend,
|
|
66
|
-
robustZScore,
|
|
67
|
-
roundCents,
|
|
68
|
-
routeMatches,
|
|
69
|
-
runEnforcement,
|
|
70
|
-
scopeKey,
|
|
71
|
-
signalDefinition,
|
|
72
|
-
spendNotificationText,
|
|
73
|
-
spendOpenApiPaths,
|
|
74
|
-
startSpendLoop,
|
|
75
|
-
streamFocusJsonl,
|
|
76
|
-
strongestActiveAction,
|
|
77
|
-
tieredMicroCents,
|
|
78
|
-
toFocusJsonl,
|
|
79
|
-
toFocusRecords,
|
|
80
|
-
usageDeltaKey,
|
|
81
|
-
utcInstantOfLocal,
|
|
82
|
-
zeroFill,
|
|
83
|
-
zoneOffsetMs,
|
|
84
|
-
zonedParts
|
|
85
|
-
} from "../chunk-29rse4p1.js";
|
|
86
|
-
import"../chunk-aa2dkn7b.js";
|
|
87
|
-
import"../chunk-050r7ycy.js";
|
|
88
|
-
import"../chunk-v0bahtg2.js";
|
|
89
|
-
export {
|
|
90
|
-
zonedParts,
|
|
91
|
-
zoneOffsetMs,
|
|
92
|
-
zeroFill,
|
|
93
|
-
utcInstantOfLocal,
|
|
94
|
-
usageDeltaKey,
|
|
95
|
-
toFocusRecords,
|
|
96
|
-
toFocusJsonl,
|
|
97
|
-
tieredMicroCents,
|
|
98
|
-
strongestActiveAction,
|
|
99
|
-
streamFocusJsonl,
|
|
100
|
-
startSpendLoop,
|
|
101
|
-
spendOpenApiPaths,
|
|
102
|
-
spendNotificationText,
|
|
103
|
-
signalDefinition,
|
|
104
|
-
scopeKey,
|
|
105
|
-
runEnforcement,
|
|
106
|
-
routeMatches,
|
|
107
|
-
roundCents,
|
|
108
|
-
robustZScore,
|
|
109
|
-
projectSpend,
|
|
110
|
-
priceUsageLines,
|
|
111
|
-
priceUsage,
|
|
112
|
-
previousBudgetWindow,
|
|
113
|
-
planEnforcement,
|
|
114
|
-
percentOfLimit,
|
|
115
|
-
optionsForSignal,
|
|
116
|
-
meterTelemetry,
|
|
117
|
-
mergePriceBooks,
|
|
118
|
-
mergeDecisions,
|
|
119
|
-
medianAbsoluteDeviation,
|
|
120
|
-
median,
|
|
121
|
-
lookbackHoursForSignal,
|
|
122
|
-
isValidTimeZone,
|
|
123
|
-
isOperationAllowed,
|
|
124
|
-
hourBucketsBetween,
|
|
125
|
-
hourBucket,
|
|
126
|
-
handleSpendRequest,
|
|
127
|
-
governingLimitCents,
|
|
128
|
-
formatTimeToExhaustion,
|
|
129
|
-
formatCents,
|
|
130
|
-
findPriceEntry,
|
|
131
|
-
findMapping,
|
|
132
|
-
ewma,
|
|
133
|
-
evaluateBudget,
|
|
134
|
-
detectLatestAnomaly,
|
|
135
|
-
detectAnomalies,
|
|
136
|
-
createEnforcementHandlers,
|
|
137
|
-
compositeSpendTransport,
|
|
138
|
-
budgetWindow,
|
|
139
|
-
assertSpendAllows,
|
|
140
|
-
anomalyOptionsForSignal,
|
|
141
|
-
aggregateDeltas,
|
|
142
|
-
USER_VISIBLE_ACTIONS,
|
|
143
|
-
URGENT_SPEND_EVENTS,
|
|
144
|
-
SpendStore,
|
|
145
|
-
SpendService,
|
|
146
|
-
SpendRunner,
|
|
147
|
-
SpendNotificationRouter,
|
|
148
|
-
SpendLoopLease,
|
|
149
|
-
SpendGate,
|
|
150
|
-
SpendCapError,
|
|
151
|
-
SignalSource,
|
|
152
|
-
SPEND_LEASE_SETTING,
|
|
153
|
-
SPEND_GATE_SETTING,
|
|
154
|
-
SPEND_CYCLE_SECONDS,
|
|
155
|
-
SENSITIVITY_THRESHOLDS,
|
|
156
|
-
RecordingSpendTransport,
|
|
157
|
-
MIN_PROJECTION_CONFIDENCE,
|
|
158
|
-
MICRO_CENTS,
|
|
159
|
-
METER_KEYS,
|
|
160
|
-
METERS,
|
|
161
|
-
FOCUS_VERSION,
|
|
162
|
-
ENFORCEMENT_SEVERITY,
|
|
163
|
-
ENFORCEMENT_DESCRIPTIONS,
|
|
164
|
-
ENFORCEMENT_ACTIONS,
|
|
165
|
-
DETECTABLE_SIGNALS,
|
|
166
|
-
DEFAULT_THRESHOLDS,
|
|
167
|
-
DEFAULT_PRICE_BOOK,
|
|
168
|
-
DEFAULT_METER_MAPPINGS,
|
|
169
|
-
CounterTracker,
|
|
170
|
-
ComputeSpendTransport,
|
|
171
|
-
AwsSpendTransport,
|
|
172
|
-
AnomalyConfigStore
|
|
173
|
-
};
|
|
1
|
+
import{$i as c,$j as da,Aj as D,Bj as E,Cj as F,Dj as G,Ej as H,Fj as I,Fk as qa,Gj as J,Gk as ra,Hj as K,Hk as sa,Ij as L,Ik as ta,Jj as M,Jk as ua,Kj as N,Kk as va,Lj as O,Lk as wa,Mj as P,Mk as xa,Nj as Q,Nk as ya,Oj as R,Ok as za,Pj as S,Pk as Aa,Qj as T,Qk as Ba,Rj as U,Sj as V,Tj as W,Uj as X,Uk as Ca,Vj as Y,Vk as Da,Wj as Z,Xj as _,Yj as aa,Zi as a,Zj as ba,_i as b,_j as ca,aj as d,ak as ea,bj as e,bk as fa,cj as f,ck as ga,dj as g,dk as ha,ej as h,ek as ia,fj as i,fk as ja,gj as j,gk as ka,hj as k,hk as la,ij as l,ik as ma,jj as m,jk as na,kj as n,kk as oa,lj as o,lk as pa,mj as p,nj as q,oj as r,pj as s,qj as t,rj as u,sj as v,tj as w,uj as x,vj as y,wj as z,xj as A,yj as B,zj as C}from"../chunk-kv2ztkp4.js";import"../chunk-cd0zpxhf.js";import"../chunk-06jk7ba9.js";import"../chunk-77t2ctwn.js";export{Z as AnomalyConfigStore,za as AwsSpendTransport,Aa as ComputeSpendTransport,x as CounterTracker,u as DEFAULT_METER_MAPPINGS,l as DEFAULT_PRICE_BOOK,B as DEFAULT_THRESHOLDS,_ as DETECTABLE_SIGNALS,c as ENFORCEMENT_ACTIONS,K as ENFORCEMENT_DESCRIPTIONS,d as ENFORCEMENT_SEVERITY,ea as FOCUS_VERSION,b as METERS,a as METER_KEYS,e as MICRO_CENTS,G as MIN_PROJECTION_CONFIDENCE,pa as RecordingSpendTransport,X as SENSITIVITY_THRESHOLDS,xa as SPEND_CYCLE_SECONDS,ka as SPEND_GATE_SETTING,ua as SPEND_LEASE_SETTING,ba as SignalSource,ma as SpendCapError,la as SpendGate,va as SpendLoopLease,ta as SpendNotificationRouter,wa as SpendRunner,ia as SpendService,C as SpendStore,qa as URGENT_SPEND_EVENTS,L as USER_VISIBLE_ACTIONS,z as aggregateDeltas,W as anomalyOptionsForSignal,na as assertSpendAllows,q as budgetWindow,Ba as compositeSpendTransport,oa as createEnforcementHandlers,U as detectAnomalies,V as detectLatestAnomaly,I as evaluateBudget,T as ewma,v as findMapping,g as findPriceEntry,ra as formatCents,F as formatTimeToExhaustion,H as governingLimitCents,Ca as handleSpendRequest,s as hourBucket,t as hourBucketsBetween,P as isOperationAllowed,m as isValidTimeZone,da as lookbackHoursForSignal,Q as median,R as medianAbsoluteDeviation,J as mergeDecisions,k as mergePriceBooks,y as meterTelemetry,ca as optionsForSignal,E as percentOfLimit,M as planEnforcement,r as previousBudgetWindow,h as priceUsage,i as priceUsageLines,D as projectSpend,S as robustZScore,j as roundCents,Y as routeMatches,N as runEnforcement,A as scopeKey,aa as signalDefinition,sa as spendNotificationText,Da as spendOpenApiPaths,ya as startSpendLoop,ha as streamFocusJsonl,O as strongestActiveAction,f as tieredMicroCents,ga as toFocusJsonl,fa as toFocusRecords,w as usageDeltaKey,p as utcInstantOfLocal,ja as zeroFill,o as zoneOffsetMs,n as zonedParts};
|
package/dist/ui/404.html
CHANGED