Skip to content

Commit 161011e

Browse files
authored
Merge de78923 into 01bb65b
2 parents 01bb65b + de78923 commit 161011e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+5466
-0
lines changed
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
module.exports = {
19+
extends: '../../config/.eslintrc.js',
20+
parserOptions: {
21+
project: 'tsconfig.json',
22+
// to make vscode-eslint work with monorepo
23+
// https://github.com/typescript-eslint/typescript-eslint/issues/251#issuecomment-463943250
24+
tsconfigRootDir: __dirname
25+
}
26+
};

packages-exp/messaging-exp/.npmignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Directories not needed by end users
2+
/src
3+
test
4+
5+
# Files not needed by end users
6+
gulpfile.js
7+
index.ts
8+
karma.conf.js
9+
tsconfig.json

packages-exp/messaging-exp/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# @firebase/messaging
2+
3+
This is the Firebase Cloud Messaging component of the Firebase JS SDK.
4+
5+
**This package is not intended for direct usage, and should only be used via the officially supported [firebase](https://www.npmjs.com/package/firebase) package.**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "../../config/api-extractor.json",
3+
// Point it to your entry point d.ts file.
4+
"mainEntryPointFilePath": "<projectFolder>/dist/index.d.ts",
5+
"dtsRollup": {
6+
"enabled": true
7+
}
8+
}
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* @license
3+
* Copyright 2017 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
const karmaBase = require('../../config/karma.base');
19+
20+
const files = [`src/**/*.test.ts`];
21+
22+
module.exports = function (config) {
23+
const karmaConfig = {
24+
...karmaBase,
25+
files,
26+
frameworks: ['mocha']
27+
};
28+
29+
config.set(karmaConfig);
30+
};
31+
32+
module.exports.files = files;
+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"name": "@firebase/messaging-exp",
3+
"private": true,
4+
"version": "0.0.800",
5+
"description": "",
6+
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
7+
"main": "dist/index.cjs.js",
8+
"module": "dist/index.esm.js",
9+
"esm2017": "dist/index.esm2017.js",
10+
"files": [
11+
"dist"
12+
],
13+
"scripts": {
14+
"lint": "eslint -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
15+
"lint:fix": "eslint --fix -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
16+
"build": "rollup -c && yarn api-report",
17+
"build:deps": "lerna run --scope @firebase/'{app-exp,messaging-exp}' --include-dependencies build",
18+
"dev": "rollup -c -w",
19+
"test": "run-p test:karma type-check lint ",
20+
"test:integration": "run-p test:karma type-check lint && cd ../../integration/messaging && npm run-script test",
21+
"test:ci": "node ../../scripts/run_tests_in_ci.js",
22+
"test:karma": "karma start --single-run",
23+
"test:debug": "karma start --browsers=Chrome --auto-watch",
24+
"prepare": "yarn build",
25+
"api-report": "api-extractor run --local --verbose",
26+
"type-check": "tsc --noEmit"
27+
},
28+
"license": "Apache-2.0",
29+
"peerDependencies": {
30+
"@firebase/app-exp": "0.x",
31+
"@firebase/app-types-exp": "0.x"
32+
},
33+
"dependencies": {
34+
"@firebase/component": "0.1.19",
35+
"@firebase/installations": "0.4.17",
36+
"@firebase/messaging-types-exp": "0.0.800",
37+
"@firebase/util": "0.3.2",
38+
"eslint": "^7.3.1",
39+
"idb": "3.0.2",
40+
"npm-run-all": "^4.1.5",
41+
"tslib": "^1.11.1"
42+
},
43+
"devDependencies": {
44+
"rollup": "2.7.6",
45+
"rollup-plugin-typescript2": "0.27.0",
46+
"ts-essentials": "^6.0.7",
47+
"typescript": "3.8.3"
48+
},
49+
"repository": {
50+
"directory": "packages/messaging",
51+
"type": "git",
52+
"url": "https://github.com/firebase/firebase-js-sdk.git"
53+
},
54+
"bugs": {
55+
"url": "https://github.com/firebase/firebase-js-sdk/issues"
56+
},
57+
"typings": "dist/index.d.ts"
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/**
2+
* @license
3+
* Copyright 2018 Google Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import json from 'rollup-plugin-json';
19+
import typescriptPlugin from 'rollup-plugin-typescript2';
20+
import typescript from 'typescript';
21+
import pkg from './package.json';
22+
23+
const deps = Object.keys(
24+
Object.assign({}, pkg.peerDependencies, pkg.dependencies)
25+
);
26+
27+
/**
28+
* ES5 Builds
29+
*/
30+
const es5BuildPlugins = [
31+
typescriptPlugin({
32+
typescript
33+
}),
34+
json()
35+
];
36+
37+
const es5Builds = [
38+
{
39+
input: 'src/index.ts',
40+
output: [
41+
{ file: pkg.main, format: 'cjs', sourcemap: true },
42+
{ file: pkg.module, format: 'es', sourcemap: true }
43+
],
44+
plugins: es5BuildPlugins,
45+
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
46+
}
47+
];
48+
49+
/**
50+
* ES2017 Builds
51+
*/
52+
const es2017BuildPlugins = [
53+
typescriptPlugin({
54+
typescript,
55+
tsconfigOverride: {
56+
compilerOptions: {
57+
target: 'es2017'
58+
}
59+
}
60+
}),
61+
json({ preferConst: true })
62+
];
63+
64+
const es2017Builds = [
65+
{
66+
input: 'src/index.ts',
67+
output: {
68+
file: pkg.esm2017,
69+
format: 'es',
70+
sourcemap: true
71+
},
72+
plugins: es2017BuildPlugins,
73+
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
74+
}
75+
];
76+
export default [...es5Builds, ...es2017Builds];

packages-exp/messaging-exp/src/api.ts

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/**
2+
* @license
3+
* Copyright 2017 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import { ComponentContainer, Provider } from '@firebase/component';
19+
import { FirebaseApp, _FirebaseService } from '@firebase/app-types-exp';
20+
import {
21+
FirebaseMessaging,
22+
MessagePayload
23+
} from '@firebase/messaging-types-exp';
24+
import { NextFn, Observer, Unsubscribe } from '@firebase/util';
25+
26+
import { FirebaseInternalDependencies } from './interfaces/internal-dependencies';
27+
import { SwController } from './controllers/sw-controller';
28+
import { WindowController } from './controllers/window-controller';
29+
import { _getProvider } from '@firebase/app-exp';
30+
import { extractAppConfig } from './helpers/extract-app-config';
31+
32+
export function getMessaging(app: FirebaseApp): FirebaseMessaging {
33+
const messagingProvider: Provider<'messaging'> = _getProvider(
34+
app,
35+
'messaging'
36+
);
37+
38+
return messagingProvider.getImmediate();
39+
}
40+
41+
export function getToken(
42+
messaging: FirebaseMessaging,
43+
options?: { vapidKey?: string; swReg?: ServiceWorkerRegistration }
44+
): Promise<string> {
45+
return messaging.getToken(options);
46+
}
47+
48+
export function deleteToken(messaging: FirebaseMessaging): Promise<boolean> {
49+
return messaging.deleteToken();
50+
}
51+
52+
export function onMessage(
53+
messaging: FirebaseMessaging,
54+
nextOrObserver: NextFn<MessagePayload> | Observer<MessagePayload>
55+
): Unsubscribe {
56+
return messaging.onMessage(nextOrObserver);
57+
}
58+
59+
export function onBackgroundMessage(
60+
messaging: FirebaseMessaging,
61+
nextOrObserver: NextFn<MessagePayload> | Observer<MessagePayload>
62+
): Unsubscribe {
63+
return messaging.onBackgroundMessage(nextOrObserver);
64+
}
65+
66+
export class MessagingService implements _FirebaseService {
67+
app!: FirebaseApp;
68+
readonly windowController: WindowController | null = null;
69+
readonly swController: SwController | null = null;
70+
71+
constructor(container: ComponentContainer) {
72+
const app = container.getProvider('app-exp').getImmediate();
73+
const appConfig = extractAppConfig(app);
74+
const installations = container.getProvider('installations').getImmediate();
75+
const analyticsProvider = container.getProvider('analytics-internal');
76+
77+
const firebaseDependencies: FirebaseInternalDependencies = {
78+
app,
79+
appConfig,
80+
installations,
81+
analyticsProvider
82+
};
83+
84+
if (self && 'ServiceWorkerGlobalScope' in self) {
85+
this.swController = new SwController(firebaseDependencies);
86+
} else {
87+
this.windowController = new WindowController(firebaseDependencies);
88+
}
89+
}
90+
91+
_delete(): Promise<void> {
92+
throw new Error('Method not implemented.');
93+
}
94+
}

0 commit comments

Comments
 (0)