firebase-admin
Advanced tools
Comparing version 4.0.6 to 4.1.0
@@ -1,2 +0,2 @@ | ||
/*! firebase-admin v4.0.6 | ||
/*! firebase-admin v4.1.0 | ||
https://firebase.google.com/terms/ */ | ||
@@ -228,6 +228,6 @@ "use strict"; | ||
* @param {Object} response The response to check for errors. | ||
* @return {string} The error code if present, an empty string otherwise. | ||
* @return {string|null} The error code if present; null otherwise. | ||
*/ | ||
FirebaseAuthRequestHandler.getErrorCode = function (response) { | ||
return (response.error && response.error.message) || null; | ||
return (validator.isNonNullObject(response) && response.error && response.error.message) || null; | ||
}; | ||
@@ -402,7 +402,16 @@ /** | ||
}) | ||
.catch(function (error) { | ||
.catch(function (response) { | ||
var error; | ||
if (typeof response === 'object' && 'statusCode' in response) { | ||
// response came directly from a non-200 response. | ||
error = response.error; | ||
} | ||
else { | ||
// response came from a thrown error on a 200 response. | ||
error = response; | ||
} | ||
if (error instanceof error_1.FirebaseError) { | ||
throw error; | ||
} | ||
var errorCode = FirebaseAuthRequestHandler.getErrorCode(error) || 'INTERNAL_ERROR'; | ||
var errorCode = FirebaseAuthRequestHandler.getErrorCode(error); | ||
throw error_2.FirebaseAuthError.fromServerError(errorCode, /* message */ undefined, error); | ||
@@ -409,0 +418,0 @@ }); |
@@ -1,2 +0,2 @@ | ||
/*! firebase-admin v4.0.6 | ||
/*! firebase-admin v4.1.0 | ||
https://firebase.google.com/terms/ */ | ||
@@ -3,0 +3,0 @@ "use strict"; |
@@ -1,2 +0,2 @@ | ||
/*! firebase-admin v4.0.6 | ||
/*! firebase-admin v4.1.0 | ||
https://firebase.google.com/terms/ */ | ||
@@ -187,2 +187,3 @@ "use strict"; | ||
'https://www.googleapis.com/auth/firebase.database', | ||
'https://www.googleapis.com/auth/firebase.messaging', | ||
'https://www.googleapis.com/auth/identitytoolkit', | ||
@@ -189,0 +190,0 @@ 'https://www.googleapis.com/auth/userinfo.email', |
@@ -1,2 +0,2 @@ | ||
/*! firebase-admin v4.0.6 | ||
/*! firebase-admin v4.1.0 | ||
https://firebase.google.com/terms/ */ | ||
@@ -3,0 +3,0 @@ "use strict"; |
@@ -1,2 +0,2 @@ | ||
/*! firebase-admin v4.0.6 | ||
/*! firebase-admin v4.1.0 | ||
https://firebase.google.com/terms/ */ | ||
@@ -3,0 +3,0 @@ "use strict"; |
@@ -1,2 +0,2 @@ | ||
/*! firebase-admin v4.0.6 | ||
/*! firebase-admin v4.1.0 | ||
https://firebase.google.com/terms/ */ | ||
@@ -3,0 +3,0 @@ "use strict"; |
@@ -1,2 +0,2 @@ | ||
/*! firebase-admin v4.0.6 | ||
/*! firebase-admin v4.1.0 | ||
https://firebase.google.com/terms/ */ | ||
@@ -3,0 +3,0 @@ "use strict"; |
@@ -1,2 +0,2 @@ | ||
/*! firebase-admin v4.0.6 | ||
/*! firebase-admin v4.1.0 | ||
https://firebase.google.com/terms/ */ | ||
@@ -71,3 +71,3 @@ "use strict"; | ||
'which has been revoked. Make sure the key ID for your key file is still present at ' + | ||
'https://console.firebase.google.com/iam-admin/serviceaccounts/project. If not, generate' + | ||
'https://console.firebase.google.com/iam-admin/serviceaccounts/project. If not, generate ' + | ||
'a new key file at https://console.firebase.google.com/project/_/settings/serviceaccounts/adminsdk.'; | ||
@@ -185,2 +185,6 @@ } | ||
}; | ||
/* istanbul ignore next */ | ||
FirebaseApp.prototype.messaging = function () { | ||
throw new Error('INTERNAL ASSERT FAILED: Firebase messaging() service has not been registered.'); | ||
}; | ||
Object.defineProperty(FirebaseApp.prototype, "name", { | ||
@@ -187,0 +191,0 @@ /** |
@@ -1,2 +0,2 @@ | ||
/*! firebase-admin v4.0.6 | ||
/*! firebase-admin v4.1.0 | ||
https://firebase.google.com/terms/ */ | ||
@@ -198,3 +198,3 @@ "use strict"; | ||
this.credential = firebaseCredential; | ||
this.SDK_VERSION = '4.0.6'; | ||
this.SDK_VERSION = '4.1.0'; | ||
/* tslint:disable */ | ||
@@ -219,2 +219,6 @@ // TODO(jwenger): Database is the only consumer of firebase.Promise. We should update it to use | ||
}; | ||
/* istanbul ignore next */ | ||
FirebaseNamespace.prototype.messaging = function () { | ||
throw new Error('INTERNAL ASSERT FAILED: Firebase messaging() service has not been registered.'); | ||
}; | ||
/** | ||
@@ -221,0 +225,0 @@ * Initializes the FirebaseApp instance. |
@@ -1,3 +0,3 @@ | ||
/*! firebase-admin v4.0.6 | ||
/*! firebase-admin v4.1.0 | ||
https://firebase.google.com/terms/ */ | ||
"use strict"; |
@@ -1,4 +0,10 @@ | ||
/*! firebase-admin v4.0.6 | ||
/*! firebase-admin v4.1.0 | ||
https://firebase.google.com/terms/ */ | ||
declare namespace admin { | ||
interface FirebaseError { | ||
code: string; | ||
message: string; | ||
stack: string; | ||
} | ||
class Promise<T> extends Promise_Instance<T> { | ||
@@ -45,2 +51,3 @@ static all(values: admin.Promise<any>[]): admin.Promise<any[]>; | ||
function database(app?: admin.app.App): admin.database.Database; | ||
function messaging(app?: admin.app.App): admin.messaging.Messaging; | ||
function initializeApp(options: admin.AppOptions, name?: string): admin.app.App; | ||
@@ -56,2 +63,3 @@ } | ||
database(): admin.database.Database; | ||
messaging(): admin.messaging.Messaging; | ||
delete(): admin.Promise<undefined>; | ||
@@ -65,10 +73,14 @@ } | ||
createdAt: Date; | ||
toJSON(): Object; | ||
} | ||
interface UserInfo { | ||
uid: string; | ||
displayName: string; | ||
email: string; | ||
photoURL: string; | ||
providerId: string; | ||
uid: string; | ||
displayName: string; | ||
email: string; | ||
photoURL: string; | ||
providerId: string; | ||
toJSON(): Object; | ||
} | ||
@@ -85,2 +97,4 @@ | ||
providerData: admin.auth.UserInfo[]; | ||
toJSON(): Object; | ||
} | ||
@@ -225,4 +239,99 @@ | ||
declare namespace admin.messaging { | ||
type DataMessagePayload = { | ||
[key: string]: string; | ||
}; | ||
type NotificationMessagePayload = { | ||
tag?: string; | ||
body?: string; | ||
icon?: string; | ||
badge?: string; | ||
color?: string; | ||
sound?: string; | ||
title?: string; | ||
bodyLocKey?: string; | ||
bodyLocArgs?: string; | ||
clickAction?: string; | ||
titleLocKey?: string; | ||
titleLocArgs?: string; | ||
[other: string]: string; | ||
}; | ||
type MessagingPayload = { | ||
data?: admin.messaging.DataMessagePayload; | ||
notification?: admin.messaging.NotificationMessagePayload; | ||
}; | ||
type MessagingOptions = { | ||
dryRun?: boolean; | ||
priority?: string; | ||
timeToLive?: number; | ||
collapseKey?: string; | ||
contentAvailable?: boolean; | ||
restrictedPackageName?: string; | ||
[other: string]: any; | ||
}; | ||
type MessagingDeviceResult = { | ||
error?: admin.FirebaseError; | ||
messageId?: string; | ||
canonicalRegistrationToken?: string; | ||
}; | ||
type MessagingDevicesResponse = { | ||
canonicalRegistrationTokenCount: number; | ||
failureCount: number; | ||
multicastId: number; | ||
results: admin.messaging.MessagingDeviceResult[]; | ||
successCount: number; | ||
}; | ||
type MessagingDeviceGroupResponse = { | ||
successCount: number; | ||
failureCount: number; | ||
failedRegistrationTokens: string[]; | ||
}; | ||
type MessagingTopicResponse = { | ||
messageId: number; | ||
}; | ||
type MessagingConditionResponse = { | ||
messageId: number; | ||
}; | ||
interface Messaging { | ||
app: admin.app.App; | ||
sendToDevice( | ||
registrationToken: string, | ||
payload: admin.messaging.MessagingPayload, | ||
options?: admin.messaging.MessagingOptions | ||
): admin.Promise<admin.messaging.MessagingDevicesResponse>; | ||
sendToDevice( | ||
registrationTokens: string[], | ||
payload: admin.messaging.MessagingPayload, | ||
options?: admin.messaging.MessagingOptions | ||
): admin.Promise<admin.messaging.MessagingDevicesResponse>; | ||
sendToDeviceGroup( | ||
notificationKey: string, | ||
payload: admin.messaging.MessagingPayload, | ||
options?: admin.messaging.MessagingOptions | ||
): admin.Promise<admin.messaging.MessagingDeviceGroupResponse>; | ||
sendToTopic( | ||
topic: string, | ||
payload: admin.messaging.MessagingPayload, | ||
options?: admin.messaging.MessagingOptions | ||
): admin.Promise<admin.messaging.MessagingTopicResponse>; | ||
sendToCondition( | ||
condition: string, | ||
payload: admin.messaging.MessagingPayload, | ||
options?: admin.messaging.MessagingOptions | ||
): admin.Promise<admin.messaging.MessagingConditionResponse>; | ||
} | ||
} | ||
declare module 'firebase-admin' { | ||
export = admin; | ||
} |
@@ -1,2 +0,2 @@ | ||
/*! firebase-admin v4.0.6 | ||
/*! firebase-admin v4.1.0 | ||
https://firebase.google.com/terms/ */ | ||
@@ -6,2 +6,3 @@ "use strict"; | ||
var register_auth_1 = require("./auth/register-auth"); | ||
var register_messaging_1 = require("./messaging/register-messaging"); | ||
// Register the Database service | ||
@@ -15,2 +16,4 @@ // For historical reasons, the database code is included as minified code and registers itself | ||
register_auth_1.default(); | ||
// Register the Messaging service | ||
register_messaging_1.default(); | ||
module.exports = firebase; |
@@ -1,2 +0,2 @@ | ||
/*! firebase-admin v4.0.6 | ||
/*! firebase-admin v4.1.0 | ||
https://firebase.google.com/terms/ */ | ||
@@ -57,3 +57,3 @@ "use strict"; | ||
var contentType = responseHeaders['content-type'] || 'application/json'; | ||
if (contentType.indexOf('text/html') !== -1) { | ||
if (contentType.indexOf('text/html') !== -1 || contentType.indexOf('text/plain') !== -1) { | ||
// Text response | ||
@@ -64,3 +64,6 @@ if (statusCode >= 200 && statusCode < 300) { | ||
else { | ||
reject(response); | ||
reject({ | ||
statusCode: statusCode, | ||
error: response, | ||
}); | ||
} | ||
@@ -76,3 +79,6 @@ } | ||
else { | ||
reject(json); | ||
reject({ | ||
statusCode: statusCode, | ||
error: json, | ||
}); | ||
} | ||
@@ -86,3 +92,6 @@ } | ||
}); | ||
reject(parsingError); | ||
reject({ | ||
statusCode: statusCode, | ||
error: parsingError, | ||
}); | ||
} | ||
@@ -102,3 +111,6 @@ } | ||
}); | ||
reject(networkTimeoutError); | ||
reject({ | ||
statusCode: 408, | ||
error: networkTimeoutError, | ||
}); | ||
}); | ||
@@ -112,3 +124,6 @@ }); | ||
}); | ||
reject(networkRequestError); | ||
reject({ | ||
statusCode: 502, | ||
error: networkRequestError, | ||
}); | ||
}); | ||
@@ -115,0 +130,0 @@ if (requestData) { |
@@ -1,2 +0,2 @@ | ||
/*! firebase-admin v4.0.6 | ||
/*! firebase-admin v4.1.0 | ||
https://firebase.google.com/terms/ */ | ||
@@ -3,0 +3,0 @@ "use strict"; |
@@ -1,2 +0,2 @@ | ||
/*! firebase-admin v4.0.6 | ||
/*! firebase-admin v4.1.0 | ||
https://firebase.google.com/terms/ */ | ||
@@ -95,2 +95,41 @@ "use strict"; | ||
/** | ||
* Firebase Messaging error code structure. This extends FirebaseError. | ||
* | ||
* @param {ErrorInfo} info The error code info. | ||
* @param {string} [message] The error message. This will override the default message if provided. | ||
* @constructor | ||
*/ | ||
var FirebaseMessagingError = (function (_super) { | ||
__extends(FirebaseMessagingError, _super); | ||
function FirebaseMessagingError(info, message) { | ||
// Override default message if custom message provided. | ||
return _super.call(this, { code: 'messaging/' + info.code, message: message || info.message }) || this; | ||
} | ||
/** | ||
* Creates the developer-facing error corresponding to the backend error code. | ||
* | ||
* @param {string} serverErrorCode The server error code. | ||
* @param {string} [message] The error message. The default message is used | ||
* if not provided. | ||
* @param {Object} [rawServerResponse] The error's raw server response. | ||
* @return {FirebaseMessagingError} The corresponding developer-facing error. | ||
*/ | ||
FirebaseMessagingError.fromServerError = function (serverErrorCode, message, rawServerResponse) { | ||
// If not found, default to unknown error. | ||
var clientCodeKey = MESSAGING_SERVER_TO_CLIENT_CODE[serverErrorCode] || 'UNKNOWN_ERROR'; | ||
var error = deep_copy_1.deepCopy(MessagingClientErrorCode[clientCodeKey]); | ||
error.message = message || error.message; | ||
if (clientCodeKey === 'UNKNOWN_ERROR' && typeof rawServerResponse !== 'undefined') { | ||
try { | ||
error.message += " Raw server response: \"" + JSON.stringify(rawServerResponse) + "\""; | ||
} | ||
catch (e) { | ||
} | ||
} | ||
return new FirebaseMessagingError(error); | ||
}; | ||
return FirebaseMessagingError; | ||
}(FirebaseError)); | ||
exports.FirebaseMessagingError = FirebaseMessagingError; | ||
/** | ||
* Auth client error codes and their default messages. | ||
@@ -178,2 +217,95 @@ */ | ||
; | ||
/** | ||
* Messaging client error codes and their default messages. | ||
*/ | ||
var MessagingClientErrorCode = (function () { | ||
function MessagingClientErrorCode() { | ||
} | ||
return MessagingClientErrorCode; | ||
}()); | ||
MessagingClientErrorCode.INVALID_ARGUMENT = { | ||
code: 'invalid-argument', | ||
message: 'Invalid argument provided.', | ||
}; | ||
MessagingClientErrorCode.INVALID_RECIPIENT = { | ||
code: 'invalid-recipient', | ||
message: 'Invalid message recipient provided.', | ||
}; | ||
MessagingClientErrorCode.INVALID_PAYLOAD = { | ||
code: 'invalid-payload', | ||
message: 'Invalid message payload provided.', | ||
}; | ||
MessagingClientErrorCode.INVALID_DATA_PAYLOAD_KEY = { | ||
code: 'invalid-data-payload-key', | ||
message: 'The data message payload contains an invalid key. See the reference documentation ' + | ||
'for the DataMessagePayload type for restricted keys.', | ||
}; | ||
MessagingClientErrorCode.PAYLOAD_SIZE_LIMIT_EXCEEDED = { | ||
code: 'payload-size-limit-exceeded', | ||
message: 'The provided message payload exceeds the FCM size limits. See the error documentation ' + | ||
'for more details.', | ||
}; | ||
MessagingClientErrorCode.INVALID_OPTIONS = { | ||
code: 'invalid-options', | ||
message: 'Invalid message options provided.', | ||
}; | ||
MessagingClientErrorCode.INVALID_REGISTRATION_TOKEN = { | ||
code: 'invalid-registration-token', | ||
message: 'Invalid registration token provided. Make sure it matches the registration token ' + | ||
'the client app receives from registering with FCM.', | ||
}; | ||
MessagingClientErrorCode.REGISTRATION_TOKEN_NOT_REGISTERED = { | ||
code: 'registration-token-not-registered', | ||
message: 'The provided registration token is not registered. A previously valid registration ' + | ||
'token can be unregistered for a variety of reasons. See the error documentation for more ' + | ||
'details. Remove this registration token and stop using it to send messages.', | ||
}; | ||
MessagingClientErrorCode.MISMATCHED_CREDENTIAL = { | ||
code: 'mismatched-credential', | ||
message: 'The credential used to authenticate this SDK does not have permission to send ' + | ||
'messages to the device corresponding to the provided registration token. Make sure the ' + | ||
'credential and registration token both belong to the same Firebase project.', | ||
}; | ||
MessagingClientErrorCode.INVALID_PACKAGE_NAME = { | ||
code: 'invalid-package-name', | ||
message: 'The message was addressed to a registration token whose package name does not match ' + | ||
'the provided "restrictedPackageName" option.', | ||
}; | ||
MessagingClientErrorCode.DEVICE_MESSAGE_RATE_EXCEEDED = { | ||
code: 'device-message-rate-exceeded', | ||
message: 'The rate of messages to a particular device is too high. Reduce the number of ' + | ||
'messages sent to this device and do not immediately retry sending to this device.', | ||
}; | ||
MessagingClientErrorCode.TOPICS_MESSAGE_RATE_EXCEEDED = { | ||
code: 'topics-message-rate-exceeded', | ||
message: 'The rate of messages to subscribers to a particular topic is too high. Reduce the ' + | ||
'number of messages sent for this topic, and do not immediately retry sending to this topic.', | ||
}; | ||
MessagingClientErrorCode.INVALID_APNS_CREDENTIALS = { | ||
code: 'invalid-apns-credentials', | ||
message: 'A message targeted to an iOS device could not be sent because the required APNs ' + | ||
'SSL certificate was not uploaded or has expired. Check the validity of your development ' + | ||
'and production certificates.', | ||
}; | ||
MessagingClientErrorCode.AUTHENTICATION_ERROR = { | ||
code: 'authentication-error', | ||
message: 'An error occurred when trying to authenticate to the FCM servers. Make sure the ' + | ||
'credential used to authenticate this SDK has the proper permissions. See ' + | ||
'https://firebase.google.com/docs/admin/setup for setup instructions.', | ||
}; | ||
MessagingClientErrorCode.SERVER_UNAVAILABLE = { | ||
code: 'server-unavailable', | ||
message: 'The FCM server could not process the request in time. See the error documentation ' + | ||
'for more details.', | ||
}; | ||
MessagingClientErrorCode.INTERNAL_ERROR = { | ||
code: 'internal-error', | ||
message: 'An internal error has occurred.', | ||
}; | ||
MessagingClientErrorCode.UNKNOWN_ERROR = { | ||
code: 'unknown-error', | ||
message: 'An unknown server error was returned.', | ||
}; | ||
exports.MessagingClientErrorCode = MessagingClientErrorCode; | ||
; | ||
/** @const {ServerToClientCode} Auth server to client enum error codes. */ | ||
@@ -208,1 +340,30 @@ var AUTH_SERVER_TO_CLIENT_CODE = { | ||
}; | ||
/** @const {ServerToClientCode} Messaging server to client enum error codes. */ | ||
var MESSAGING_SERVER_TO_CLIENT_CODE = { | ||
// Generic invalid message parameter provided. | ||
InvalidParameters: 'INVALID_ARGUMENT', | ||
// Invalid registration token format. | ||
InvalidRegistration: 'INVALID_REGISTRATION_TOKEN', | ||
// Registration token is not registered. | ||
NotRegistered: 'REGISTRATION_TOKEN_NOT_REGISTERED', | ||
// Mismatched sender ID. | ||
MismatchSenderId: 'MISMATCHED_CREDENTIAL', | ||
// Registration token does not match restricted package name. | ||
InvalidPackageName: 'INVALID_PACKAGE_NAME', | ||
// Message payload size limit exceeded. | ||
MessageTooBig: 'PAYLOAD_SIZE_LIMIT_EXCEEDED', | ||
// Invalid key in the data message payload. | ||
InvalidDataKey: 'INVALID_DATA_PAYLOAD_KEY', | ||
// Invalid time to live option. | ||
InvalidTtl: 'INVALID_OPTIONS', | ||
// Device message rate exceeded. | ||
DeviceMessageRateExceeded: 'DEVICE_MESSAGE_RATE_EXCEEDED', | ||
// Topics message rate exceeded. | ||
TopicsMessageRateExceeded: 'TOPICS_MESSAGE_RATE_EXCEEDED', | ||
// Invalid APNs credentials. | ||
InvalidApnsCredential: 'INVALID_APNS_CREDENTIALS', | ||
// FCM server unavailable. | ||
Unavailable: 'SERVER_UNAVAILABLE', | ||
// FCM server internal error. | ||
InternalServerError: 'INTERNAL_ERROR', | ||
}; |
@@ -1,2 +0,2 @@ | ||
/*! firebase-admin v4.0.6 | ||
/*! firebase-admin v4.1.0 | ||
https://firebase.google.com/terms/ */ | ||
@@ -6,2 +6,52 @@ "use strict"; | ||
/** | ||
* Validates that a value is a boolean. | ||
* | ||
* @param {any} value The value to validate. | ||
* @return {boolean} Whether the value is a boolean or not. | ||
*/ | ||
function isBoolean(value) { | ||
return typeof value === 'boolean'; | ||
} | ||
exports.isBoolean = isBoolean; | ||
/** | ||
* Validates that a value is a number. | ||
* | ||
* @param {any} value The value to validate. | ||
* @return {boolean} Whether the value is a number or not. | ||
*/ | ||
function isNumber(value) { | ||
return typeof value === 'number' && !isNaN(value); | ||
} | ||
exports.isNumber = isNumber; | ||
/** | ||
* Validates that a value is a string. | ||
* | ||
* @param {any} value The value to validate. | ||
* @return {boolean} Whether the value is a string or not. | ||
*/ | ||
function isString(value) { | ||
return typeof value === 'string'; | ||
} | ||
exports.isString = isString; | ||
/** | ||
* Validates that a value is a non-empty string. | ||
* | ||
* @param {any} value The value to validate. | ||
* @return {boolean} Whether the value is a non-empty string or not. | ||
*/ | ||
function isNonEmptyString(value) { | ||
return typeof value === 'string' && value !== ''; | ||
} | ||
exports.isNonEmptyString = isNonEmptyString; | ||
/** | ||
* Validates that a value is a non-null object. | ||
* | ||
* @param {any} value The value to validate. | ||
* @return {boolean} Whether the value is a non-null object or not. | ||
*/ | ||
function isNonNullObject(value) { | ||
return typeof value === 'object' && value !== null && !(value instanceof Array); | ||
} | ||
exports.isNonNullObject = isNonNullObject; | ||
/** | ||
* Validates that a string is a valid Firebase Auth uid. | ||
@@ -87,1 +137,15 @@ * | ||
exports.isURL = isURL; | ||
/** | ||
* Validates that the provided topic is a valid FCM topic name. | ||
* | ||
* @param {any} topic The topic to validate. | ||
* @return {boolean} Whether the provided topic is a valid FCM topic name. | ||
*/ | ||
function isTopic(topic) { | ||
if (typeof topic !== 'string') { | ||
return false; | ||
} | ||
var VALID_TOPIC_REGEX = /^(\/topics\/)?(private\/)?[a-zA-Z0-9-_.~%]+$/; | ||
return VALID_TOPIC_REGEX.test(topic); | ||
} | ||
exports.isTopic = isTopic; |
{ | ||
"name": "firebase-admin", | ||
"version": "4.0.6", | ||
"version": "4.1.0", | ||
"dependencies": { | ||
@@ -5,0 +5,0 @@ "@types/jsonwebtoken": { |
{ | ||
"name": "firebase-admin", | ||
"version": "4.0.6", | ||
"version": "4.1.0", | ||
"description": "Firebase admin SDK for Node.js", | ||
@@ -5,0 +5,0 @@ "author": "Firebase (https://firebase.google.com/)", |
Sorry, the diff of this file is too big to display
284808
24
4320