|
| 1 | +// The MIT License (MIT) |
| 2 | +// |
| 3 | +// Copyright (c) 2017 Firebase |
| 4 | +// |
| 5 | +// Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | +// of this software and associated documentation files (the "Software"), to deal |
| 7 | +// in the Software without restriction, including without limitation the rights |
| 8 | +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 | +// copies of the Software, and to permit persons to whom the Software is |
| 10 | +// furnished to do so, subject to the following conditions: |
| 11 | +// |
| 12 | +// The above copyright notice and this permission notice shall be included in all |
| 13 | +// copies or substantial portions of the Software. |
| 14 | +// |
| 15 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 | +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 | +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 21 | +// SOFTWARE. |
| 22 | + |
| 23 | +import { makeCloudFunction, CloudFunction, Event } from '../cloud-functions'; |
| 24 | + |
| 25 | +/** @internal */ |
| 26 | +export const provider = 'firebase.crashlytics'; |
| 27 | + |
| 28 | +/** |
| 29 | + * Handle events related to Crashlytics issues. An issue in Crashlytics is an |
| 30 | + * aggregation of crashes which have a shared root cause. |
| 31 | + */ |
| 32 | +export function issue() { |
| 33 | + return new IssueBuilder('projects/' + process.env.GCLOUD_PROJECT); |
| 34 | +} |
| 35 | + |
| 36 | +/** Builder used to create Cloud Functions for Crashlytics issue events. */ |
| 37 | +export class IssueBuilder { |
| 38 | + /** @internal */ |
| 39 | + constructor(private resource: string) { } |
| 40 | + |
| 41 | + /** Handle Crashlytics New Issue events. */ |
| 42 | + onNewDetected(handler: (event: Event<Issue>) => PromiseLike<any> | any |
| 43 | + ): CloudFunction<Issue> { |
| 44 | + return makeCloudFunction({ |
| 45 | + provider, handler, |
| 46 | + resource: this.resource, |
| 47 | + eventType: 'issue.new', |
| 48 | + }); |
| 49 | + } |
| 50 | + |
| 51 | + /** Handle Crashlytics Regressed Issue events. */ |
| 52 | + onRegressed(handler: (event: Event<Issue>) => PromiseLike<any> | any |
| 53 | + ): CloudFunction<Issue> { |
| 54 | + return makeCloudFunction({ |
| 55 | + provider, handler, |
| 56 | + resource: this.resource, |
| 57 | + eventType: 'issue.regressed', |
| 58 | + }); |
| 59 | + } |
| 60 | + |
| 61 | + /** Handle Crashlytics Velocity Alert events. */ |
| 62 | + onVelocityAlert(handler: (event: Event<Issue>) => PromiseLike<any> | any |
| 63 | + ): CloudFunction<Issue> { |
| 64 | + return makeCloudFunction({ |
| 65 | + provider, handler, |
| 66 | + resource: this.resource, |
| 67 | + eventType: 'issue.velocityAlert', |
| 68 | + }); |
| 69 | + } |
| 70 | +} |
| 71 | + |
| 72 | +/** |
| 73 | + * Interface representing a Crashlytics issue event that was logged for a specific issue. |
| 74 | + */ |
| 75 | +export class Issue { |
| 76 | + /** Fabric Issue ID. */ |
| 77 | + issueId: string; |
| 78 | + |
| 79 | + /** Issue title. */ |
| 80 | + issueTitle: string; |
| 81 | + |
| 82 | + /** App information. */ |
| 83 | + appInfo: AppInfo; |
| 84 | + |
| 85 | + /** When the issue was created (ISO8601 time stamp). */ |
| 86 | + createTime: string; |
| 87 | + |
| 88 | + /** When the issue was resolved, if the issue has been resolved (ISO8601 time stamp). */ |
| 89 | + resolvedTime?: string; |
| 90 | + |
| 91 | + /** Contains details about the velocity alert, if this event was triggered by a velocity alert. */ |
| 92 | + velocityAlert?: VelocityAlert; |
| 93 | +} |
| 94 | + |
| 95 | +export class VelocityAlert { |
| 96 | + /** The percentage of sessions which have been impacted by this issue. Example: .04 */ |
| 97 | + crashPercentage: number; |
| 98 | + |
| 99 | + /** The number of crashes that this issue has caused. */ |
| 100 | + crashes: number; |
| 101 | +} |
| 102 | + |
| 103 | +/** |
| 104 | + * Interface representing the application where this issue occurred. |
| 105 | + */ |
| 106 | +export interface AppInfo { |
| 107 | + /** The app's name. Example: "My Awesome App". */ |
| 108 | + appName: string; |
| 109 | + |
| 110 | + /** The app's platform. Examples: "android", "ios". */ |
| 111 | + appPlatform: string; |
| 112 | + |
| 113 | + /** Unique application identifier within an app store, either the Android package name or the iOS bundle id. */ |
| 114 | + appId: string; |
| 115 | + |
| 116 | + /** |
| 117 | + * The latest app version which is affected by the issue. |
| 118 | + * Examples: "1.0", "4.3.1.1.213361", "2.3 (1824253)", "v1.8b22p6". |
| 119 | + */ |
| 120 | + latestAppVersion: string; |
| 121 | +} |
0 commit comments