@mathrunet/masamune 0.0.7 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -0
- package/LICENSE +1 -1
- package/README.md +34 -1
- package/dist/functions/send_notification.d.ts +1 -0
- package/dist/functions/send_notification.js +111 -0
- package/dist/functions/send_notification.js.map +1 -0
- package/dist/functions.d.ts +1 -1
- package/dist/functions.js +1 -1
- package/dist/functions.js.map +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +7 -2
- package/dist/index.js.map +1 -1
- package/dist/lib/functions_data.d.ts +2 -2
- package/dist/lib/functions_data.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
|
+
# [0.1.0](https://github.com/mathrunet/node_masamune/compare/v0.0.8...v0.1.0) (2023-02-08)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### chore
|
|
5
|
+
|
|
6
|
+
* Edit .gitignore. ([de837ef](https://github.com/mathrunet/node_masamune/commit/de837ef8e831c6fba55e8fa94c0e33fa6cf8b7ff))
|
|
7
|
+
|
|
8
|
+
### feat
|
|
9
|
+
|
|
10
|
+
* Allow region to be specified externally. ([782d805](https://github.com/mathrunet/node_masamune/commit/782d805ac88c3991eabb3017f78cca083dd42f33))
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [0.0.8](https://github.com/mathrunet/node_masamune/compare/v0.0.7...v0.0.8) (2023-01-17)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### docs
|
|
18
|
+
|
|
19
|
+
* ReadMe creation. ([6f91ba9](https://github.com/mathrunet/node_masamune/commit/6f91ba97d8c8e3f7d41a6299d95e51a69b90fe1c))
|
|
20
|
+
|
|
21
|
+
### fix
|
|
22
|
+
|
|
23
|
+
* Changed the function name of notification. ([c1a152c](https://github.com/mathrunet/node_masamune/commit/c1a152cd3398325a7149bf4a852fe368088e4f16))
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
1
27
|
## [0.0.7](https://github.com/mathrunet/node_masamune/compare/v0.0.6...v0.0.7) (2023-01-11)
|
|
2
28
|
|
|
3
29
|
|
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -19,4 +19,37 @@
|
|
|
19
19
|
|
|
20
20
|
[[YouTube]](https://www.youtube.com/c/mathrunetchannel) | [[Packages]](https://pub.dev/publishers/mathru.net/packages) | [[Twitter]](https://twitter.com/mathru) | [[LinkedIn]](https://www.linkedin.com/in/mathrunet/)
|
|
21
21
|
|
|
22
|
-
---
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
Just load the package in index.ts and pass the predefined data to the methods to implement the server side.
|
|
25
|
+
|
|
26
|
+
Also, [katana_functions_firebase](https://pub.dev/packages/katana_functions_firebase/score) can be used to execute server-side functions from methods defined on the client side, allowing for safe implementation.
|
|
27
|
+
|
|
28
|
+
# Installation
|
|
29
|
+
|
|
30
|
+
Install the following packages
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npm install @mathrunet/masamune
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
# Implementation
|
|
37
|
+
|
|
38
|
+
Import the package as follows and pass the value of `exports` and the list of functions you wish to define to the `deploy` function.
|
|
39
|
+
|
|
40
|
+
```dart
|
|
41
|
+
import * as m from "@mathrunet/masamune";
|
|
42
|
+
|
|
43
|
+
// Define [m.Functions.xxxx] for the functions to be added to Functions.
|
|
44
|
+
//
|
|
45
|
+
// Functionsに追加する機能を[m.Functions.xxxx]を定義してください。
|
|
46
|
+
m.deploy(
|
|
47
|
+
exports,
|
|
48
|
+
[
|
|
49
|
+
// Function for PUSH Notification.
|
|
50
|
+
m.Functions.notification,
|
|
51
|
+
],
|
|
52
|
+
);
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Functions passed to deploy are deployed to Cloud Functions for Firebase.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
const functions = __importStar(require("firebase-functions"));
|
|
36
|
+
const admin = __importStar(require("firebase-admin"));
|
|
37
|
+
/**
|
|
38
|
+
* Define the process for PUSH notification.
|
|
39
|
+
*
|
|
40
|
+
* PUSH通知を行うための処理を定義します。
|
|
41
|
+
*
|
|
42
|
+
* @param title
|
|
43
|
+
* The title of the notice should be listed.
|
|
44
|
+
*
|
|
45
|
+
* 通知タイトルを記載します。
|
|
46
|
+
*
|
|
47
|
+
* @param body
|
|
48
|
+
* The contents of the notice will be described.
|
|
49
|
+
*
|
|
50
|
+
* 通知内容を記載します。
|
|
51
|
+
*
|
|
52
|
+
* @param channel_id
|
|
53
|
+
* Describe ChannelId for Android.
|
|
54
|
+
*
|
|
55
|
+
* Android向けのChannelIdを記載します。
|
|
56
|
+
*
|
|
57
|
+
* @param data
|
|
58
|
+
* Specify the data to be placed on the notification.
|
|
59
|
+
*
|
|
60
|
+
* 通知に乗せるデータを指定します。
|
|
61
|
+
*
|
|
62
|
+
* @param token
|
|
63
|
+
* Specifies the FCM token.
|
|
64
|
+
*
|
|
65
|
+
* FCMトークンを指定します。
|
|
66
|
+
*
|
|
67
|
+
* @param topic
|
|
68
|
+
* Specifies the topic of the FCM.
|
|
69
|
+
*
|
|
70
|
+
* FCMのトピックを指定します。
|
|
71
|
+
*/
|
|
72
|
+
module.exports = (region) => functions.region(region).https.onCall((query) => __awaiter(void 0, void 0, void 0, function* () {
|
|
73
|
+
try {
|
|
74
|
+
const title = query.title;
|
|
75
|
+
const body = query.body;
|
|
76
|
+
const channelId = query.channel_id;
|
|
77
|
+
const data = query.data;
|
|
78
|
+
const token = query.token;
|
|
79
|
+
const topic = query.topic;
|
|
80
|
+
if (token === undefined || topic === undefined) {
|
|
81
|
+
throw new functions.https.HttpsError("invalid-argument", "Either [token] or [topic] must be specified.");
|
|
82
|
+
}
|
|
83
|
+
const res = yield admin.messaging().send({
|
|
84
|
+
notification: {
|
|
85
|
+
title: title,
|
|
86
|
+
body: body,
|
|
87
|
+
},
|
|
88
|
+
android: {
|
|
89
|
+
priority: "high",
|
|
90
|
+
notification: {
|
|
91
|
+
title: title,
|
|
92
|
+
body: body,
|
|
93
|
+
clickAction: "FLUTTER_NOTIFICATION_CLICK",
|
|
94
|
+
channelId: channelId,
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
data: data,
|
|
98
|
+
token: token,
|
|
99
|
+
topic: topic,
|
|
100
|
+
});
|
|
101
|
+
return {
|
|
102
|
+
success: true,
|
|
103
|
+
message_id: res,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
catch (err) {
|
|
107
|
+
console.log(err);
|
|
108
|
+
throw err;
|
|
109
|
+
}
|
|
110
|
+
}));
|
|
111
|
+
//# sourceMappingURL=send_notification.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"send_notification.js","sourceRoot":"","sources":["../../src/functions/send_notification.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8DAAgD;AAChD,sDAAwC;AAExC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,CAAC,OAAO,GAAG,CAAC,MAAc,EAAE,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,MAAM,CACtE,CAAO,KAAK,EAAE,EAAE;IACZ,IAAI;QACA,MAAM,KAAK,GAAG,KAAK,CAAC,KAAe,CAAC;QACpC,MAAM,IAAI,GAAG,KAAK,CAAC,IAAc,CAAC;QAClC,MAAM,SAAS,GAAG,KAAK,CAAC,UAAgC,CAAC;QACzD,MAAM,IAAI,GAAG,KAAK,CAAC,IAA6C,CAAC;QACjE,MAAM,KAAK,GAAG,KAAK,CAAC,KAA2B,CAAC;QAChD,MAAM,KAAK,GAAG,KAAK,CAAC,KAA2B,CAAC;QAChD,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,SAAS,EAAE;YAC5C,MAAM,IAAI,SAAS,CAAC,KAAK,CAAC,UAAU,CAAC,kBAAkB,EAAE,8CAA8C,CAAC,CAAC;SAC5G;QACD,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,SAAS,EAAE,CAAC,IAAI,CACpC;YACI,YAAY,EAAE;gBACV,KAAK,EAAE,KAAK;gBACZ,IAAI,EAAE,IAAI;aACb;YACD,OAAO,EAAE;gBACL,QAAQ,EAAE,MAAM;gBAChB,YAAY,EAAE;oBACV,KAAK,EAAE,KAAK;oBACZ,IAAI,EAAE,IAAI;oBACV,WAAW,EAAE,4BAA4B;oBACzC,SAAS,EAAE,SAAS;iBACvB;aACJ;YACD,IAAI,EAAE,IAAI;YACV,KAAK,EAAE,KAAK;YACZ,KAAK,EAAE,KAAK;SACf,CACJ,CAAC;QACF,OAAO;YACH,OAAO,EAAE,IAAI;YACb,UAAU,EAAE,GAAG;SAClB,CAAC;KACL;IAAC,OAAO,GAAG,EAAE;QACV,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACjB,MAAM,GAAG,CAAC;KACb;AACL,CAAC,CAAA,CACJ,CAAC"}
|
package/dist/functions.d.ts
CHANGED
package/dist/functions.js
CHANGED
|
@@ -36,6 +36,6 @@ exports.Functions = {
|
|
|
36
36
|
*
|
|
37
37
|
* PUSH通知を送信するためのFunction。
|
|
38
38
|
*/
|
|
39
|
-
|
|
39
|
+
sendNotification: new data.FunctionsData("send_notification", require("./functions/send_notification")),
|
|
40
40
|
};
|
|
41
41
|
//# sourceMappingURL=functions.js.map
|
package/dist/functions.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"functions.js","sourceRoot":"","sources":["../src/functions.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2DAA6C;AAE7C;;;;GAIG;AACU,QAAA,SAAS,GAAG;IACvB;;;;OAIG;IACH,
|
|
1
|
+
{"version":3,"file":"functions.js","sourceRoot":"","sources":["../src/functions.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2DAA6C;AAE7C;;;;GAIG;AACU,QAAA,SAAS,GAAG;IACvB;;;;OAIG;IACH,gBAAgB,EAAE,IAAI,IAAI,CAAC,aAAa,CAAC,mBAAmB,EAAE,OAAO,CAAC,+BAA+B,CAAC,CAAC;CAC/F,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -11,9 +11,14 @@ export * from "./lib/functions_data";
|
|
|
11
11
|
*
|
|
12
12
|
* `exports`をそのまま渡します。
|
|
13
13
|
*
|
|
14
|
+
* @param region
|
|
15
|
+
* Specify a region such as `asia-northeast1`.
|
|
16
|
+
*
|
|
17
|
+
* `asia-northeast1`などのリージョンを指定します。
|
|
18
|
+
*
|
|
14
19
|
* @param deployFunctions
|
|
15
20
|
* The elements defined in [Functions] are passed as an array. The passed method is deployed.
|
|
16
21
|
*
|
|
17
22
|
* [Functions]で定義された要素を配列として渡します。渡されたメソッドがデプロイされます。
|
|
18
23
|
*/
|
|
19
|
-
export declare function deploy(exports: any, deployFunctions: data.FunctionsData[]): void;
|
|
24
|
+
export declare function deploy(exports: any, region: string, deployFunctions: data.FunctionsData[]): void;
|
package/dist/index.js
CHANGED
|
@@ -40,16 +40,21 @@ __exportStar(require("./lib/functions_data"), exports);
|
|
|
40
40
|
*
|
|
41
41
|
* `exports`をそのまま渡します。
|
|
42
42
|
*
|
|
43
|
+
* @param region
|
|
44
|
+
* Specify a region such as `asia-northeast1`.
|
|
45
|
+
*
|
|
46
|
+
* `asia-northeast1`などのリージョンを指定します。
|
|
47
|
+
*
|
|
43
48
|
* @param deployFunctions
|
|
44
49
|
* The elements defined in [Functions] are passed as an array. The passed method is deployed.
|
|
45
50
|
*
|
|
46
51
|
* [Functions]で定義された要素を配列として渡します。渡されたメソッドがデプロイされます。
|
|
47
52
|
*/
|
|
48
|
-
function deploy(exports, deployFunctions) {
|
|
53
|
+
function deploy(exports, region, deployFunctions) {
|
|
49
54
|
admin.initializeApp();
|
|
50
55
|
for (const data of deployFunctions) {
|
|
51
56
|
if (!process.env.FUNCTION_NAME || process.env.FUNCTION_NAME === data.id) {
|
|
52
|
-
exports[data.id] = data.func;
|
|
57
|
+
exports[data.id] = data.func(region);
|
|
53
58
|
}
|
|
54
59
|
}
|
|
55
60
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,sDAAwC;AACxC,8CAA4B;AAC5B,uDAAqC;AAErC
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,sDAAwC;AACxC,8CAA4B;AAC5B,uDAAqC;AAErC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAgB,MAAM,CAAC,OAAY,EAAE,MAAc,EAAE,eAAqC;IACtF,KAAK,CAAC,aAAa,EAAE,CAAC;IACtB,KAAK,MAAM,IAAI,IAAI,eAAe,EAAE;QAChC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,IAAI,OAAO,CAAC,GAAG,CAAC,aAAa,KAAK,IAAI,CAAC,EAAE,EAAE;YACrE,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;SACxC;KACJ;AACL,CAAC;AAPD,wBAOC"}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export declare class FunctionsData {
|
|
7
7
|
readonly id: string;
|
|
8
|
-
readonly func: Function;
|
|
8
|
+
readonly func: (region: string) => Function;
|
|
9
9
|
/**
|
|
10
10
|
* Define Function data for FirebaseFunctions.
|
|
11
11
|
*
|
|
@@ -21,5 +21,5 @@ export declare class FunctionsData {
|
|
|
21
21
|
*
|
|
22
22
|
* 実際の処理の中身を指定します。
|
|
23
23
|
*/
|
|
24
|
-
constructor(id: string, func: Function);
|
|
24
|
+
constructor(id: string, func: (region: string) => Function);
|
|
25
25
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"functions_data.js","sourceRoot":"","sources":["../../src/lib/functions_data.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACH,MAAa,aAAa;IACxB;;;;;;;;;;;;;;OAcG;IACH,YAAqB,EAAU,EAAW,
|
|
1
|
+
{"version":3,"file":"functions_data.js","sourceRoot":"","sources":["../../src/lib/functions_data.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACH,MAAa,aAAa;IACxB;;;;;;;;;;;;;;OAcG;IACH,YAAqB,EAAU,EAAW,IAAkC;QAAvD,OAAE,GAAF,EAAE,CAAQ;QAAW,SAAI,GAAJ,IAAI,CAA8B;IAAG,CAAC;CACjF;AAjBD,sCAiBC"}
|