Skip to content

Create experiment modularized FM SDK #3822

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Dec 21, 2020
Merged
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
},
"typescript.tsdk": "node_modules/typescript/lib",
"files.associations": { "*.json": "jsonc" }
}
}
32 changes: 32 additions & 0 deletions common/api-review/messaging-exp.api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
## API Report File for "@firebase/messaging-exp"

> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).

```ts

import { FirebaseApp } from '@firebase/app-types-exp';
import { FirebaseMessaging } from '@firebase/messaging-types-exp';
import { MessagePayload } from '@firebase/messaging-types-exp';
import { NextFn } from '@firebase/util';
import { Observer } from '@firebase/util';
import { Unsubscribe } from '@firebase/util';

// @public (undocumented)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you are planning to do this in another PR but to get documentation, the JSdoc comments need to be added in src/api.ts

export function deleteToken(messaging: FirebaseMessaging): Promise<boolean>;

// @public (undocumented)
export function getMessaging(app: FirebaseApp): FirebaseMessaging;

// @public (undocumented)
export function getToken(messaging: FirebaseMessaging, options?: {
vapidKey?: string;
swReg?: ServiceWorkerRegistration;
}): Promise<string>;

// @public (undocumented)
export function onMessage(messaging: FirebaseMessaging, nextOrObserver: NextFn<MessagePayload> | Observer<MessagePayload>): Unsubscribe;


// (No @packageDocumentation comment for this package)

```
26 changes: 26 additions & 0 deletions packages-exp/messaging-exp/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* @license
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

module.exports = {
extends: '../../config/.eslintrc.js',
parserOptions: {
project: 'tsconfig.json',
// to make vscode-eslint work with monorepo
// https://github.com/typescript-eslint/typescript-eslint/issues/251#issuecomment-463943250
tsconfigRootDir: __dirname
}
};
5 changes: 5 additions & 0 deletions packages-exp/messaging-exp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# @firebase/messaging

This is the Firebase Cloud Messaging component of the Firebase JS SDK.

**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.**
8 changes: 8 additions & 0 deletions packages-exp/messaging-exp/api-extractor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../config/api-extractor.json",
// Point it to your entry point d.ts file.
"mainEntryPointFilePath": "<projectFolder>/dist/index.d.ts",
"dtsRollup": {
"enabled": true
}
}
32 changes: 32 additions & 0 deletions packages-exp/messaging-exp/karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* @license
* Copyright 2017 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

const karmaBase = require('../../config/karma.base');

const files = [`src/**/*.test.ts`];

module.exports = function (config) {
const karmaConfig = {
...karmaBase,
files,
frameworks: ['mocha']
};

config.set(karmaConfig);
};

module.exports.files = files;
57 changes: 57 additions & 0 deletions packages-exp/messaging-exp/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"name": "@firebase/messaging-exp",
"private": true,
"version": "0.0.900",
"description": "",
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
"esm2017": "dist/index.esm2017.js",
"sw": "dist/index.sw.esm5.js",
"files": [
"dist"
],
"scripts": {
"lint": "eslint -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
"lint:fix": "eslint --fix -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
"build": "rollup -c && yarn api-report",
"build:deps": "lerna run --scope @firebase/'{app-exp,messaging-exp}' --include-dependencies build",
"dev": "rollup -c -w",
"test": "run-p test:karma type-check lint ",
"test:integration": "run-p test:karma type-check lint && cd ../../integration/messaging && npm run-script test",
"test:ci": "node ../../scripts/run_tests_in_ci.js",
"test:karma": "karma start --single-run",
"test:debug": "karma start --browsers=Chrome --auto-watch",
"prepare": "yarn build",
"api-report": "api-extractor run --local --verbose",
"type-check": "tsc --noEmit"
},
"license": "Apache-2.0",
"peerDependencies": {
"@firebase/app-exp": "0.x",
"@firebase/app-types-exp": "0.x"
},
"dependencies": {
"@firebase/component": "0.1.19",
"@firebase/installations-exp": "0.x",
"@firebase/messaging-types-exp": "0.0.900",
"@firebase/util": "0.3.2",
"idb": "3.0.2",
"tslib": "^1.11.1"
},
"devDependencies": {
"rollup-plugin-json": "^4.0.0",
"rollup-plugin-typescript2": "0.27.0",
"ts-essentials": "^6.0.7",
"typescript": "3.8.3"
},
"repository": {
"directory": "packages/messaging",
"type": "git",
"url": "https://github.com/firebase/firebase-js-sdk.git"
},
"bugs": {
"url": "https://github.com/firebase/firebase-js-sdk/issues"
},
"typings": "dist/index.d.ts"
}
85 changes: 85 additions & 0 deletions packages-exp/messaging-exp/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/**
* @license
* Copyright 2018 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import json from 'rollup-plugin-json';
import pkg from './package.json';
import typescript from 'typescript';
import typescriptPlugin from 'rollup-plugin-typescript2';

const deps = Object.keys(
Object.assign({}, pkg.peerDependencies, pkg.dependencies)
);

/**
* ES5 Builds
*/
const es5BuildPlugins = [
typescriptPlugin({
typescript
}),
json()
];

const es5Builds = [
// window builds
{
input: 'src/index.ts',
output: [
{ file: pkg.main, format: 'cjs', sourcemap: true },
{ file: pkg.module, format: 'es', sourcemap: true }
],
plugins: es5BuildPlugins,
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
},

// sw builds
{
input: 'src/index.sw.ts',
output: [{ file: pkg.sw, format: 'es', sourcemap: true }],
plugins: es5BuildPlugins,
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
}
];

/**
* ES2017 Builds
*/
const es2017BuildPlugins = [
typescriptPlugin({
typescript,
tsconfigOverride: {
compilerOptions: {
target: 'es2017'
}
}
}),
json({ preferConst: true })
];

const es2017Builds = [
{
input: 'src/index.ts',
output: {
file: pkg.esm2017,
format: 'es',
sourcemap: true
},
plugins: es2017BuildPlugins,
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
}
];
export default [...es5Builds, ...es2017Builds];
65 changes: 65 additions & 0 deletions packages-exp/messaging-exp/src/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* @license
* Copyright 2017 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import {
FirebaseMessaging,
MessagePayload
} from '@firebase/messaging-types-exp';
import { NextFn, Observer, Unsubscribe } from '@firebase/util';

import { FirebaseApp } from '@firebase/app-types-exp';
import { MessagingService } from './messaging-service';
import { Provider } from '@firebase/component';
import { deleteToken as _deleteToken } from './api/deleteToken';
import { _getProvider } from '@firebase/app-exp';
import { getToken as _getToken } from './api/getToken';
import { onBackgroundMessage as _onBackgroundMessage } from './api/onBackgroundMessage';
import { onMessage as _onMessage } from './api/onMessage';

export function getMessaging(app: FirebaseApp): FirebaseMessaging {
const messagingProvider: Provider<'messaging-exp'> = _getProvider(
app,
'messaging-exp'
);

return messagingProvider.getImmediate();
}

export async function getToken(
messaging: FirebaseMessaging,
options?: { vapidKey?: string; swReg?: ServiceWorkerRegistration }
): Promise<string> {
return _getToken(messaging as MessagingService, options);
}

export function deleteToken(messaging: FirebaseMessaging): Promise<boolean> {
return _deleteToken(messaging as MessagingService);
}

export function onMessage(
messaging: FirebaseMessaging,
nextOrObserver: NextFn<MessagePayload> | Observer<MessagePayload>
): Unsubscribe {
return _onMessage(messaging as MessagingService, nextOrObserver);
}

export function onBackgroundMessage(
messaging: FirebaseMessaging,
nextOrObserver: NextFn<MessagePayload> | Observer<MessagePayload>
): Unsubscribe {
return _onBackgroundMessage(messaging as MessagingService, nextOrObserver);
}
36 changes: 36 additions & 0 deletions packages-exp/messaging-exp/src/api/deleteToken.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* @license
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { ERROR_FACTORY, ErrorCode } from '../util/errors';

import { MessagingService } from '../messaging-service';
import { deleteTokenInternal } from '../internals/token-manager';
import { registerDefaultSw } from '../helpers/registerDefaultSw';

export async function deleteToken(
messaging: MessagingService
): Promise<boolean> {
if (!navigator) {
throw ERROR_FACTORY.create(ErrorCode.AVAILABLE_IN_WINDOW);
}

if (!messaging.swRegistration) {
await registerDefaultSw(messaging);
}

return deleteTokenInternal(messaging);
}
Loading