|
| 1 | +/** |
| 2 | + * Copyright 2021 Google LLC |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +const crashlyticsIssueDefault = { |
| 18 | + appVersion: '1 (1.0.0)', |
| 19 | + id: '1', |
| 20 | + title: 'TestApp.main', |
| 21 | + subtitle: 'Runtime Error', |
| 22 | +}; |
| 23 | + |
| 24 | +const crashlyticsFatalIssueDefault: { [key: string]: any } = { |
| 25 | + '@type': |
| 26 | + 'type.googleapis.com/google.events.firebase.firebasealerts.v1.CrashlyticsNewFatalIssuePayload', |
| 27 | + issue: crashlyticsIssueDefault, |
| 28 | +}; |
| 29 | + |
| 30 | +const crashlyticsNonFatalIssueDefault: { [key: string]: any } = { |
| 31 | + '@type': |
| 32 | + 'type.googleapis.com/google.events.firebase.firebasealerts.v1.CrashlyticsNewNonfatalIssuePayload', |
| 33 | + issue: crashlyticsIssueDefault, |
| 34 | +}; |
| 35 | + |
| 36 | +const crashlyticsRegressionDefault: { [key: string]: any } = { |
| 37 | + '@type': |
| 38 | + 'type.googleapis.com/google.events.firebase.firebasealerts.v1.CrashlyticsRegressionAlertPayload', |
| 39 | + type: 'fatal', |
| 40 | + issue: crashlyticsIssueDefault, |
| 41 | + resolveTime: new Date().toISOString(), |
| 42 | +}; |
| 43 | + |
| 44 | +const trendingIssueDetailsDefault = { |
| 45 | + type: 'fatal', |
| 46 | + issue: crashlyticsIssueDefault, |
| 47 | + eventCount: 100, |
| 48 | + userCount: 100, |
| 49 | +}; |
| 50 | + |
| 51 | +const crashlyticsVelocityDefault: { [key: string]: any } = { |
| 52 | + '@type': |
| 53 | + 'type.googleapis.com/google.events.firebase.firebasealerts.v1.CrashlyticsVelocityAlertPayload', |
| 54 | + issue: crashlyticsIssueDefault, |
| 55 | + createTime: new Date().toISOString(), |
| 56 | + crashCount: 100, |
| 57 | + crashPercentage: 80, |
| 58 | + firstVersion: '1 (1.0.0)', |
| 59 | +}; |
| 60 | + |
| 61 | +const crashlyticsStabilityDigestDefault: { [key: string]: any } = { |
| 62 | + '@type': |
| 63 | + 'type.googleapis.com/google.events.firebase.firebasealerts.v1.CrashlyticsStabilityDigestPayload', |
| 64 | + digestDate: new Date().toISOString(), |
| 65 | + trendingIssues: [trendingIssueDetailsDefault], |
| 66 | +}; |
| 67 | + |
| 68 | +const crashlyticsNewAnrIssueDefault: { [key: string]: any } = { |
| 69 | + '@type': |
| 70 | + 'type.googleapis.com/google.events.firebase.firebasealerts.v1.CrashlyticsNewAnrIssuePayload', |
| 71 | + issue: crashlyticsIssueDefault, |
| 72 | +}; |
| 73 | + |
| 74 | +const billingPlanUpdateDefault: { [key: string]: any } = { |
| 75 | + '@type': |
| 76 | + 'type.googleapis.com/google.events.firebase.firebasealerts.v1.BillingPlanUpdatePayload', |
| 77 | + billingPlan: 'defaultBillingPlan', |
| 78 | + principalEmail: '[email protected]', |
| 79 | + notificationType: 'downgrade', |
| 80 | +}; |
| 81 | + |
| 82 | +const billingPlanAutomatedUpdateDefault: { [key: string]: any } = { |
| 83 | + '@type': |
| 84 | + 'type.googleapis.com/google.events.firebase.firebasealerts.v1.BillingPlanAutomatedUpdatePayload', |
| 85 | + billingPlan: 'defaultBillingPlan', |
| 86 | + notificationType: 'downgrade', |
| 87 | +}; |
| 88 | + |
| 89 | +const appDistributionNewTesterIosDeviceDefault: { [key: string]: any } = { |
| 90 | + '@type': |
| 91 | + 'type.googleapis.com/google.events.firebase.firebasealerts.v1.AppDistroNewTesterIosDevicePayload', |
| 92 | + testerName: 'Test User', |
| 93 | + |
| 94 | + testerDeviceModelName: 'Google Pixel 10', |
| 95 | + testerDeviceIdentifier: '12345', |
| 96 | +}; |
| 97 | +const appDistributionInAppFeedbackDefault: { [key: string]: any } = { |
| 98 | + '@type': |
| 99 | + 'type.googleapis.com/google.events.firebase.firebasealerts.v1.AppDistroInAppFeedbackPayload', |
| 100 | + feedbackReport: '', |
| 101 | + feedbackConsoleUri: '', |
| 102 | + testerName: 'Test User', |
| 103 | + |
| 104 | + appVersion: '1 (1.0.0)', |
| 105 | + text: '', |
| 106 | + screenshotUri: '', |
| 107 | +}; |
| 108 | + |
| 109 | +const performanceThresholdDefault: { [key: string]: any } = { |
| 110 | + metricType: 'duration', |
| 111 | + appVersion: '1 (1.0.0)', |
| 112 | + violationValue: 0.205629, |
| 113 | + thresholdUnit: 'seconds', |
| 114 | + violationUnit: 'seconds', |
| 115 | + '@type': |
| 116 | + 'type.googleapis.com/google.events.firebase.firebasealerts.v1.FireperfThresholdAlertPayload', |
| 117 | + numSamples: '200', |
| 118 | + eventName: 'custom-trace', |
| 119 | + thresholdValue: 0.15, |
| 120 | + eventType: 'duration_trace', |
| 121 | + conditionPercentile: 90, |
| 122 | + investigateUri: '', |
| 123 | +}; |
| 124 | + |
| 125 | +export const generateCloudEventWithData = (alerttype: string, data: any) => { |
| 126 | + const projectId = '1234567890'; |
| 127 | + return { |
| 128 | + alerttype: alerttype, |
| 129 | + id: Math.random().toString().slice(2), |
| 130 | + source: `//firebasealerts.googleapis.com/projects/${projectId}`, |
| 131 | + specVersion: '1.0', |
| 132 | + appid: `1:${projectId}:web:${crypto |
| 133 | + .getRandomValues(new Uint8Array(16)) |
| 134 | + .reduce((acc, byte) => acc + `${byte.toString(16)}`, '')}`, |
| 135 | + time: new Date().toISOString(), |
| 136 | + type: 'google.firebase.firebasealerts.alerts.v1.published', |
| 137 | + project: projectId, |
| 138 | + data: { |
| 139 | + '@type': |
| 140 | + 'type.googleapis.com/google.events.firebase.firebasealerts.v1.AlertData', |
| 141 | + createTime: new Date().toISOString(), |
| 142 | + endTime: new Date().toISOString(), |
| 143 | + payload: data, |
| 144 | + }, |
| 145 | + }; |
| 146 | +}; |
| 147 | + |
| 148 | +export type FirealertsType = |
| 149 | + | 'crashlytics.newFatalIssue' |
| 150 | + | 'crashlytics.newNonfatalIssue' |
| 151 | + | 'crashlytics.regression' |
| 152 | + | 'crashlytics.stabilityDigest' |
| 153 | + | 'crashlytics.velocity' |
| 154 | + | 'crashlytics.newAnrIssue' |
| 155 | + | 'billing.planUpdate' |
| 156 | + | 'billing.planAutomatedUpdate' |
| 157 | + | 'appDistribution.newTesterIosDevice' |
| 158 | + | 'appDistribution.inAppFeedback' |
| 159 | + | 'performance.threshold'; |
| 160 | + |
| 161 | +export type AlertConfig = { |
| 162 | + [key in FirealertsType]: { |
| 163 | + name: string; |
| 164 | + default: { [key: string]: any }; |
| 165 | + link: string; |
| 166 | + }; |
| 167 | +}; |
| 168 | +export const alertConfiguration: AlertConfig = { |
| 169 | + 'crashlytics.newFatalIssue': { |
| 170 | + name: 'Crashlytics: New Fatal Issue', |
| 171 | + default: crashlyticsFatalIssueDefault, |
| 172 | + link: 'https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.alerts.crashlytics.newfatalissuepayload', |
| 173 | + }, |
| 174 | + 'crashlytics.newNonfatalIssue': { |
| 175 | + name: 'Crashlytics: New Non-Fatal Issue', |
| 176 | + default: crashlyticsNonFatalIssueDefault, |
| 177 | + link: 'https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.alerts.crashlytics.newnonfatalissuepayload', |
| 178 | + }, |
| 179 | + 'crashlytics.regression': { |
| 180 | + name: 'Crashlytics: Regression', |
| 181 | + default: crashlyticsRegressionDefault, |
| 182 | + link: 'https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.alerts.crashlytics.regressionalertpayload', |
| 183 | + }, |
| 184 | + 'crashlytics.stabilityDigest': { |
| 185 | + name: 'Crashlytics: Stablity Digest', |
| 186 | + default: crashlyticsStabilityDigestDefault, |
| 187 | + link: 'https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.alerts.crashlytics.stabilitydigestpayload', |
| 188 | + }, |
| 189 | + 'crashlytics.velocity': { |
| 190 | + name: 'Crashlytics: Velocity', |
| 191 | + default: crashlyticsVelocityDefault, |
| 192 | + link: 'https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.alerts.crashlytics.velocityalertpayload', |
| 193 | + }, |
| 194 | + 'crashlytics.newAnrIssue': { |
| 195 | + name: 'Crahslytics: New ANR Issue', |
| 196 | + default: crashlyticsNewAnrIssueDefault, |
| 197 | + link: 'https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.alerts.crashlytics.newanrissuepayload', |
| 198 | + }, |
| 199 | + 'billing.planUpdate': { |
| 200 | + name: 'Billing: Plan Update', |
| 201 | + default: billingPlanUpdateDefault, |
| 202 | + link: 'https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.alerts.billing.planupdatepayload', |
| 203 | + }, |
| 204 | + 'billing.planAutomatedUpdate': { |
| 205 | + name: 'Billing: Plan Automated Update', |
| 206 | + default: billingPlanAutomatedUpdateDefault, |
| 207 | + link: 'https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.alerts.billing.planautomatedupdatepayload', |
| 208 | + }, |
| 209 | + 'appDistribution.newTesterIosDevice': { |
| 210 | + name: 'App Distribution: New Tester IOS Device', |
| 211 | + default: appDistributionNewTesterIosDeviceDefault, |
| 212 | + link: 'https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.alerts.appdistribution.newtesterdevicepayload', |
| 213 | + }, |
| 214 | + 'appDistribution.inAppFeedback': { |
| 215 | + name: 'App Distribution: In App Feedback', |
| 216 | + default: appDistributionInAppFeedbackDefault, |
| 217 | + link: 'https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.alerts.appdistribution.inappfeedbackpayload', |
| 218 | + }, |
| 219 | + 'performance.threshold': { |
| 220 | + name: 'Performance Threshold', |
| 221 | + default: performanceThresholdDefault, |
| 222 | + link: 'https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.alerts.performance.thresholdalertpayload', |
| 223 | + }, |
| 224 | +}; |
0 commit comments