Skip to content

Commit 690f20f

Browse files
author
PushwooshCI
committed
"use tag operations as union types"
0 parents  commit 690f20f

File tree

106 files changed

+10471
-0
lines changed

Some content is hidden

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

106 files changed

+10471
-0
lines changed

.gitignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
syntax: glob
2+
3+
.idea
4+
lib/*
5+
dist/*
6+
output/*
7+
config/config.local.js
8+
node_modules
9+
debug.html
10+
debug.js
11+
npm-debug.log
12+
package-lock.json
13+
yarn.lock
14+
ts-build
15+
.DS_Store
16+
develop/channels
17+
18+
.nyc_output/*
19+
coverage/*
20+
*.pem
21+
*.zip
22+

LICENSE.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Copyright (c) 2016 Pushwoosh (http://www.pushwoosh.com)
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
(i) the original and/or modified Software should be used exclusively to work with Pushwoosh services,
6+
7+
(ii) the above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
Pushwoosh Web Push Notification SDK
2+
=========================
3+
4+
[![GitHub release](https://img.shields.io/github/release/Pushwoosh/web-push-notifications.svg)](https://github.com/Pushwoosh/web-push-notifications/releases)
5+
[![npm](https://img.shields.io/npm/v/web-push-notifications.svg)](https://www.npmjs.com/package/web-push-notifications)
6+
![platforms](https://img.shields.io/badge/platforms-Chrome%20%7C%20Firefox%20%7C%20Safari-green.svg)
7+
8+
9+
| [Download](https://cdn.pushwoosh.com/webpush/v3/PushwooshWebSDKFiles.zip) | [Guide](https://docs.pushwoosh.com/developer/pushwoosh-sdk/web-push-notifications/web-push-sdk-30/) | [Sample](https://github.com/Pushwoosh/web-push-notifications-sample) | [NPM Package](https://www.npmjs.com/package/web-push-notifications) |
10+
|---------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------|----------------------------------------------------------------------|---------------------------------------------------------------------|
11+
12+
13+
### Integration
14+
- Download Pushwoosh Web Push SDK and unzip it. You should have the following files: `pushwoosh-service-worker.js`
15+
16+
- Place all these files to top-level root of your website directory.
17+
18+
### Installation
19+
20+
via html
21+
```html
22+
<script type="text/javascript" src="//cdn.pushwoosh.com/webpush/v3/pushwoosh-web-notifications.js" async></script>
23+
<script type="text/javascript">
24+
var Pushwoosh = Pushwoosh || [];
25+
Pushwoosh.push(['init', {
26+
apiToken: 'XXXXXXX', // Device API Token
27+
applicationCode: 'XXXXX-XXXXX', // you application code from Pushwoosh Control Panel
28+
safariWebsitePushID: 'web.com.example.domain', // unique reverse-domain string, obtained in you Apple Developer Portal. Only needed if you send push notifications to Safari browser
29+
defaultNotificationTitle: 'Pushwoosh', // sets a default title for push notifications
30+
defaultNotificationImage: 'https://yoursite.com/img/logo-medium.png', // URL to custom custom notification image
31+
autoSubscribe: true, // or false. If true, prompts a user to subscribe for pushes upon SDK initialization
32+
subscribeWidget: {
33+
enable: true
34+
},
35+
userId: 'user_id', // optional, set custom user ID
36+
}]);
37+
</script>
38+
```
39+
40+
| [Chrome Guide](https://www.pushwoosh.com/docs/chrome-web-push) | [Firefox Guide](https://www.pushwoosh.com/docs/firefox-web-push) | [Safari Guide](https://www.pushwoosh.com/docs/safari-website-notifications) | [HTTP integration Guide](https://www.pushwoosh.com/docs/chrome-web-push-for-http-websites) | [Subscription Button Guide](https://www.pushwoosh.com/v1.0/docs/push-subscription-button) |
41+
| -------------------------------------------------------------- | ---------------------------------------------------------------- | --------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------- |
42+

config/config.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module.exports = {
2+
initParams: {
3+
logLevel: 'info',
4+
applicationCode: 'XXXXX-XXXXX',
5+
apiToken: 'abcdxyz',
6+
safariWebsitePushID: 'web.com.example.test',
7+
defaultNotificationTitle: 'Pushwoosh',
8+
defaultNotificationImage: 'https://cp.pushwoosh.com/img/logo-medium.png',
9+
autoSubscribe: false,
10+
userId: 'user_id',
11+
serviceWorkerUrl: 'pushwoosh-service-worker.js',
12+
tags: {
13+
Name: 'John Doe',
14+
},
15+
subscribeWidget: {
16+
enable: true,
17+
},
18+
},
19+
20+
ssl: {
21+
key: '', // absolute path to key
22+
cert: '', // absolute path to cert
23+
},
24+
};

config/configBuilder.js

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
const BASE_PATH = '__base__';
5+
6+
// Utils
7+
function parseEnvKey(key) {
8+
return key
9+
.slice(3)
10+
.replace(/__/g, '.')
11+
.split('.');
12+
}
13+
14+
function castEnvValueTypes(value) {
15+
switch (value) {
16+
case 'true':
17+
return true;
18+
case 'false':
19+
return false;
20+
default:
21+
return value;
22+
}
23+
}
24+
25+
function setValueByPath(path, obj, value) {
26+
let tmpConfig = obj;
27+
path.forEach((pathPart, i) => {
28+
if (!(pathPart in tmpConfig)) {
29+
tmpConfig[pathPart] = {};
30+
}
31+
32+
if (i === path.length - 1) {
33+
tmpConfig[pathPart] = value;
34+
} else {
35+
tmpConfig = tmpConfig[pathPart];
36+
}
37+
});
38+
}
39+
40+
function buildObjectsMap(object, path = BASE_PATH) {
41+
const objMap = { [path]: Object.assign({}, object) };
42+
Object.keys(object).forEach((key) => {
43+
if (object[key] !== null && !Array.isArray(object[key]) && typeof object[key] === 'object') {
44+
delete objMap[path][key];
45+
Object.assign(objMap, buildObjectsMap(object[key], `${path}.${key}`));
46+
}
47+
});
48+
return objMap;
49+
}
50+
51+
function configDeepAssign(...configs) {
52+
const [baseConfig, ...anotherConfigs] = configs;
53+
54+
// Make result config map
55+
const resConfigMap = buildObjectsMap(baseConfig);
56+
anotherConfigs.forEach((config) => {
57+
const configMap = buildObjectsMap(config);
58+
Object.keys(configMap).forEach((key) => {
59+
if (key in resConfigMap) {
60+
Object.assign(resConfigMap[key], configMap[key]);
61+
delete configMap[key];
62+
}
63+
});
64+
Object.assign(resConfigMap, configMap);
65+
});
66+
67+
// Make config from map
68+
const result = {};
69+
Object.keys(resConfigMap).forEach((key) => {
70+
if (key === BASE_PATH) {
71+
Object.assign(result, resConfigMap[key]);
72+
} else {
73+
const path = key.replace(`${BASE_PATH}.`, '').split('.');
74+
setValueByPath(path, result, resConfigMap[key]);
75+
}
76+
});
77+
78+
return result;
79+
}
80+
81+
// Config Getters
82+
function getEnvironmentConfig() {
83+
const envConfig = {};
84+
Object.keys(process.env).forEach((envKey) => {
85+
if (!envKey.startsWith('PW_')) {
86+
return;
87+
}
88+
89+
const path = parseEnvKey(envKey);
90+
const value = castEnvValueTypes(process.env[envKey]);
91+
setValueByPath(path, envConfig, value);
92+
});
93+
return envConfig;
94+
}
95+
96+
// Configs
97+
const defaultConfig = require(path.resolve(__dirname, 'config.js')); // Default
98+
99+
const configPath = process.env.GUI_CONFIG_PRESET_NAME
100+
? path.resolve(__dirname, `config.${process.env.GUI_CONFIG_PRESET_NAME}.js`)
101+
: '';
102+
const presetConfig = fs.existsSync(configPath) ? require(configPath) : {}; // Preset
103+
104+
const LOCAL_CONFIG_PATH = path.resolve(__dirname, 'config.local.js');
105+
const localConfig = fs.existsSync(LOCAL_CONFIG_PATH) && process.env.NODE_ENV !== 'production'
106+
? require(LOCAL_CONFIG_PATH)
107+
: {}; // Local
108+
109+
const fileConfig = {}; // Custom file
110+
111+
const envConfig = getEnvironmentConfig(); // Environment
112+
113+
const QA_CONFIG_PATH = path.resolve(__dirname, 'config.qa.js');
114+
const qaConfig = fs.existsSync(QA_CONFIG_PATH) ? require(QA_CONFIG_PATH) : {}; // QA
115+
116+
// Build result config
117+
const config = configDeepAssign(
118+
defaultConfig,
119+
presetConfig,
120+
localConfig,
121+
fileConfig,
122+
envConfig,
123+
qaConfig,
124+
);
125+
126+
module.exports = config;

config/helpers.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function mapValues(obj, mapFn) {
2+
return Object.fromEntries(
3+
Object.entries(obj).map(([key, value]) => {
4+
return [key, mapFn(value, key)];
5+
}),
6+
);
7+
}
8+
9+
module.exports.mapValues = mapValues;
10+
11+
function stringifyObjectValues(obj) {
12+
return mapValues(obj, (value) => {
13+
return JSON.stringify(value);
14+
});
15+
}
16+
17+
module.exports.stringifyObjectValues = stringifyObjectValues;

config/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports.configBuilder = require('./configBuilder');

develop/README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Change init params
2+
3+
#### Clone the `config/config.js` to a `config/config.local.js` and edit it
4+
5+
```js
6+
module.exports = {
7+
initParams: {
8+
applicationCode: 'XXXXX-XXXXX',
9+
safariWebsitePushID: 'web.com.example.test',
10+
serviceWorkerUrl: 'pushwoosh-service-worker.uncompress.js'
11+
},
12+
13+
ssl: {
14+
key: '', // absolute path to key
15+
cert: '' // absolute path to cert
16+
}
17+
};
18+
```
19+
20+
## Build development
21+
22+
```bash
23+
npm run build
24+
```
25+
26+
## Build production
27+
28+
```bash
29+
npm run build:prod
30+
```
31+
32+
## Run server
33+
34+
```bash
35+
npm run start
36+
```
37+
38+
## Prepare release files
39+
40+
```bash
41+
npm run release
42+
```

develop/favicon.png

20.2 KB
Loading

0 commit comments

Comments
 (0)