@skyiro/sky-client 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/README.md +62 -0
- package/dist/enums.js +33 -0
- package/dist/index.js +23 -0
- package/dist/notifier-client.js +96 -0
- package/dist/shortener-client.js +59 -0
- package/dist/types.js +2 -0
- package/package.json +25 -0
- package/proto/notifier.proto +44 -0
- package/proto/shortener.proto +37 -0
package/README.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# @skyiro/sky-client
|
|
2
|
+
|
|
3
|
+
Single dependency for Skyiro **internal gRPC** clients:
|
|
4
|
+
|
|
5
|
+
- **Notifier** — `NotifierClient` (`notifier.v1.NotifierService`)
|
|
6
|
+
- **Short** — `ShortenerClient` (`shortener.Shortener`)
|
|
7
|
+
|
|
8
|
+
Typed **`ProductKey`**, **`EventKey`**, and **`NotificationChannel`** mirror notifier Prisma enums and seeded events so callers cannot accidentally pass unknown keys (until you extend the enums when the server adds events).
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
pnpm add @skyiro/sky-client
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Notifier
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import {
|
|
20
|
+
NotifierClient,
|
|
21
|
+
ProductKey,
|
|
22
|
+
EventKey,
|
|
23
|
+
NotificationChannel,
|
|
24
|
+
} from "@skyiro/sky-client";
|
|
25
|
+
|
|
26
|
+
const notifier = new NotifierClient(
|
|
27
|
+
process.env.NOTIFIER_GRPC_ADDRESS ?? "127.0.0.1:50510",
|
|
28
|
+
ProductKey.SkyOnelogin,
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
await notifier.publishEvent({
|
|
32
|
+
tenantId: "tenant-id",
|
|
33
|
+
eventKey: EventKey.LOGIN,
|
|
34
|
+
destinationAddress: ["user@example.com"],
|
|
35
|
+
channel: NotificationChannel.EMAIL,
|
|
36
|
+
payload: { otp: "123456" },
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
notifier.close();
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Override product per call with `productKey` on `publishEvent` / `publishEmailEvent`.
|
|
43
|
+
|
|
44
|
+
## Shortener
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import { ShortenerClient } from "@skyiro/sky-client";
|
|
48
|
+
|
|
49
|
+
const short = new ShortenerClient(
|
|
50
|
+
process.env.SHORTENER_GRPC_ADDRESS ?? "127.0.0.1:50052",
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const { shortUrl } = await short.createShortUrl({
|
|
54
|
+
url: "https://example.com/a/long/url",
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
short.close();
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Proto files
|
|
61
|
+
|
|
62
|
+
Bundled under `proto/` next to `dist/` for runtime loading from `__dirname`.
|
package/dist/enums.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NotificationChannel = exports.EventKey = exports.ProductKey = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Mirrors Prisma `ProductKey` on the notifier service.
|
|
6
|
+
* Use these values when publishing events so callers stay aligned with server configuration.
|
|
7
|
+
*/
|
|
8
|
+
exports.ProductKey = {
|
|
9
|
+
SkyPeople: "SkyPeople",
|
|
10
|
+
SkyOnelogin: "SkyOnelogin",
|
|
11
|
+
SkyPaper: "SkyPaper",
|
|
12
|
+
SkyBill: "SkyBill",
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Known notifier `Event.key` values from seed data (`prisma/data/events.yml`).
|
|
16
|
+
* Add entries here when new events are introduced on the server.
|
|
17
|
+
*/
|
|
18
|
+
exports.EventKey = {
|
|
19
|
+
LOGIN: "LOGIN",
|
|
20
|
+
PASSWORD_RESET: "PASSWORD_RESET",
|
|
21
|
+
DOC_SIGN_REQUEST: "DOC_SIGN_REQUEST",
|
|
22
|
+
DOC_SIGN_OTP: "DOC_SIGN_OTP",
|
|
23
|
+
DOC_SIGN_COMPLETED: "DOC_SIGN_COMPLETED",
|
|
24
|
+
DOC_SIGN_REJECTED: "DOC_SIGN_REJECTED",
|
|
25
|
+
DOC_OVERDUE_NOTIFICATION: "DOC_OVERDUE_NOTIFICATION",
|
|
26
|
+
};
|
|
27
|
+
/** Channels accepted by notifier `PublishEvent` (matches Prisma `NotificationChannel`). */
|
|
28
|
+
exports.NotificationChannel = {
|
|
29
|
+
SMS: "SMS",
|
|
30
|
+
EMAIL: "EMAIL",
|
|
31
|
+
PUSH: "PUSH",
|
|
32
|
+
WHATSAPP: "WHATSAPP",
|
|
33
|
+
};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.ShortenerClient = exports.NotifierClient = void 0;
|
|
18
|
+
__exportStar(require("./enums"), exports);
|
|
19
|
+
__exportStar(require("./types"), exports);
|
|
20
|
+
var notifier_client_1 = require("./notifier-client");
|
|
21
|
+
Object.defineProperty(exports, "NotifierClient", { enumerable: true, get: function () { return notifier_client_1.NotifierClient; } });
|
|
22
|
+
var shortener_client_1 = require("./shortener-client");
|
|
23
|
+
Object.defineProperty(exports, "ShortenerClient", { enumerable: true, get: function () { return shortener_client_1.ShortenerClient; } });
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NotifierClient = void 0;
|
|
4
|
+
var grpc_js_1 = require("@grpc/grpc-js");
|
|
5
|
+
var proto_loader_1 = require("@grpc/proto-loader");
|
|
6
|
+
var node_path_1 = require("node:path");
|
|
7
|
+
function loadNotifierGrpc(address) {
|
|
8
|
+
var protoPath = (0, node_path_1.resolve)(__dirname, "../proto/notifier.proto");
|
|
9
|
+
var packageDefinition = (0, proto_loader_1.loadSync)(protoPath, {
|
|
10
|
+
keepCase: false,
|
|
11
|
+
longs: String,
|
|
12
|
+
enums: String,
|
|
13
|
+
defaults: true,
|
|
14
|
+
oneofs: true,
|
|
15
|
+
});
|
|
16
|
+
var loaded = (0, grpc_js_1.loadPackageDefinition)(packageDefinition);
|
|
17
|
+
return new loaded.notifier.v1.NotifierService(address, grpc_js_1.ChannelCredentials.createInsecure());
|
|
18
|
+
}
|
|
19
|
+
var NotifierClient = /** @class */ (function () {
|
|
20
|
+
function NotifierClient(address, defaultProductKey) {
|
|
21
|
+
this.client = loadNotifierGrpc(address);
|
|
22
|
+
this.defaultProductKey = defaultProductKey;
|
|
23
|
+
}
|
|
24
|
+
NotifierClient.prototype.publishEvent = function (data) {
|
|
25
|
+
var _this = this;
|
|
26
|
+
var _a, _b, _c, _d;
|
|
27
|
+
var productKey = (_a = data.productKey) !== null && _a !== void 0 ? _a : this.defaultProductKey;
|
|
28
|
+
var grpcReq = {
|
|
29
|
+
tenantId: data.tenantId,
|
|
30
|
+
productKey: productKey,
|
|
31
|
+
eventKey: data.eventKey,
|
|
32
|
+
destinationAddress: data.destinationAddress,
|
|
33
|
+
channel: (_b = data.channel) !== null && _b !== void 0 ? _b : "",
|
|
34
|
+
payload: (_c = data.payload) !== null && _c !== void 0 ? _c : {},
|
|
35
|
+
idempotencyKey: (_d = data.idempotencyKey) !== null && _d !== void 0 ? _d : "",
|
|
36
|
+
};
|
|
37
|
+
return new Promise(function (resolvePromise, rejectPromise) {
|
|
38
|
+
_this.client.PublishEvent(grpcReq, function (error, response) {
|
|
39
|
+
if (error) {
|
|
40
|
+
rejectPromise(error);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
resolvePromise(response);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
NotifierClient.prototype.publishEmailEvent = function (data) {
|
|
48
|
+
var _this = this;
|
|
49
|
+
var _a, _b, _c;
|
|
50
|
+
var productKey = (_a = data.productKey) !== null && _a !== void 0 ? _a : this.defaultProductKey;
|
|
51
|
+
var grpcReq = {
|
|
52
|
+
tenantId: data.tenantId,
|
|
53
|
+
recipient: data.recipient,
|
|
54
|
+
templateKey: data.templateKey,
|
|
55
|
+
payload: (_b = data.payload) !== null && _b !== void 0 ? _b : {},
|
|
56
|
+
idempotencyKey: (_c = data.idempotencyKey) !== null && _c !== void 0 ? _c : "",
|
|
57
|
+
productKey: productKey,
|
|
58
|
+
};
|
|
59
|
+
return new Promise(function (resolvePromise, rejectPromise) {
|
|
60
|
+
_this.client.PublishEmailEvent(grpcReq, function (error, response) {
|
|
61
|
+
if (error) {
|
|
62
|
+
rejectPromise(error);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
resolvePromise(response);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
NotifierClient.prototype.publishNotificationEvent = function (data) {
|
|
70
|
+
var _this = this;
|
|
71
|
+
var _a, _b;
|
|
72
|
+
var grpcReq = {
|
|
73
|
+
tenantId: data.tenantId,
|
|
74
|
+
userId: data.userId,
|
|
75
|
+
channel: data.channel,
|
|
76
|
+
title: data.title,
|
|
77
|
+
body: data.body,
|
|
78
|
+
payload: (_a = data.payload) !== null && _a !== void 0 ? _a : {},
|
|
79
|
+
idempotencyKey: (_b = data.idempotencyKey) !== null && _b !== void 0 ? _b : "",
|
|
80
|
+
};
|
|
81
|
+
return new Promise(function (resolvePromise, rejectPromise) {
|
|
82
|
+
_this.client.PublishNotificationEvent(grpcReq, function (error, response) {
|
|
83
|
+
if (error) {
|
|
84
|
+
rejectPromise(error);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
resolvePromise(response);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
NotifierClient.prototype.close = function () {
|
|
92
|
+
this.client.close();
|
|
93
|
+
};
|
|
94
|
+
return NotifierClient;
|
|
95
|
+
}());
|
|
96
|
+
exports.NotifierClient = NotifierClient;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ShortenerClient = void 0;
|
|
4
|
+
var grpc_js_1 = require("@grpc/grpc-js");
|
|
5
|
+
var proto_loader_1 = require("@grpc/proto-loader");
|
|
6
|
+
var node_path_1 = require("node:path");
|
|
7
|
+
function loadShortenerGrpc(address) {
|
|
8
|
+
var protoPath = (0, node_path_1.resolve)(__dirname, "../proto/shortener.proto");
|
|
9
|
+
var packageDefinition = (0, proto_loader_1.loadSync)(protoPath, {
|
|
10
|
+
keepCase: false,
|
|
11
|
+
longs: String,
|
|
12
|
+
enums: String,
|
|
13
|
+
defaults: true,
|
|
14
|
+
oneofs: true,
|
|
15
|
+
});
|
|
16
|
+
var loaded = (0, grpc_js_1.loadPackageDefinition)(packageDefinition);
|
|
17
|
+
return new loaded.shortener.Shortener(address, grpc_js_1.ChannelCredentials.createInsecure());
|
|
18
|
+
}
|
|
19
|
+
var ShortenerClient = /** @class */ (function () {
|
|
20
|
+
function ShortenerClient(address) {
|
|
21
|
+
this.client = loadShortenerGrpc(address);
|
|
22
|
+
}
|
|
23
|
+
ShortenerClient.prototype.createShortUrl = function (data) {
|
|
24
|
+
var _this = this;
|
|
25
|
+
return new Promise(function (resolvePromise, rejectPromise) {
|
|
26
|
+
var _a, _b, _c;
|
|
27
|
+
_this.client.CreateShortUrl({
|
|
28
|
+
url: data.url,
|
|
29
|
+
customCode: (_a = data.customCode) !== null && _a !== void 0 ? _a : "",
|
|
30
|
+
ttlSeconds: data.ttlSeconds,
|
|
31
|
+
expiresIn: (_b = data.expiresIn) !== null && _b !== void 0 ? _b : "",
|
|
32
|
+
expiresAt: (_c = data.expiresAt) !== null && _c !== void 0 ? _c : "",
|
|
33
|
+
}, function (error, response) {
|
|
34
|
+
if (error) {
|
|
35
|
+
rejectPromise(error);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
resolvePromise(response);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
ShortenerClient.prototype.retrieveShortUrl = function (data) {
|
|
43
|
+
var _this = this;
|
|
44
|
+
return new Promise(function (resolvePromise, rejectPromise) {
|
|
45
|
+
_this.client.RetrieveShortUrl(data, function (error, response) {
|
|
46
|
+
if (error) {
|
|
47
|
+
rejectPromise(error);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
resolvePromise(response);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
ShortenerClient.prototype.close = function () {
|
|
55
|
+
this.client.close();
|
|
56
|
+
};
|
|
57
|
+
return ShortenerClient;
|
|
58
|
+
}());
|
|
59
|
+
exports.ShortenerClient = ShortenerClient;
|
package/dist/types.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@skyiro/sky-client",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Skyiro internal gRPC clients: Notifier + URL shortener, with typed product and event keys",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": ["dist", "proto"],
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsc -p tsconfig.json",
|
|
10
|
+
"example:publish-event": "tsx examples/send-login-otp-email.ts"
|
|
11
|
+
},
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"url": "https://registry.npmjs.org/",
|
|
14
|
+
"access": "public"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@grpc/grpc-js": "^1.12.6",
|
|
18
|
+
"@grpc/proto-loader": "^0.7.13"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@types/node": "^22.13.10",
|
|
22
|
+
"tsx": "^4.21.0",
|
|
23
|
+
"typescript": "^5.8.2"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
syntax = "proto3";
|
|
2
|
+
|
|
3
|
+
package notifier.v1;
|
|
4
|
+
|
|
5
|
+
service NotifierService {
|
|
6
|
+
rpc PublishEvent (PublishEventRequest) returns (PublishEventResponse);
|
|
7
|
+
rpc PublishEmailEvent (PublishEmailEventRequest) returns (PublishEventResponse);
|
|
8
|
+
rpc PublishNotificationEvent (PublishNotificationEventRequest) returns (PublishEventResponse);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
message PublishEventRequest {
|
|
12
|
+
string tenantId = 1;
|
|
13
|
+
string productKey = 2;
|
|
14
|
+
string eventKey = 3;
|
|
15
|
+
repeated string destinationAddress = 4;
|
|
16
|
+
string channel = 5;
|
|
17
|
+
map<string, string> payload = 6;
|
|
18
|
+
string idempotencyKey = 7;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
message PublishEmailEventRequest {
|
|
22
|
+
string tenantId = 1;
|
|
23
|
+
string recipient = 2;
|
|
24
|
+
string templateKey = 3;
|
|
25
|
+
map<string, string> payload = 4;
|
|
26
|
+
string idempotencyKey = 5;
|
|
27
|
+
string productKey = 6;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
message PublishNotificationEventRequest {
|
|
31
|
+
string tenantId = 1;
|
|
32
|
+
string userId = 2;
|
|
33
|
+
string channel = 3;
|
|
34
|
+
string title = 4;
|
|
35
|
+
string body = 5;
|
|
36
|
+
map<string, string> payload = 6;
|
|
37
|
+
string idempotencyKey = 7;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
message PublishEventResponse {
|
|
41
|
+
string eventId = 1;
|
|
42
|
+
string queueJobId = 2;
|
|
43
|
+
string status = 3;
|
|
44
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
syntax = "proto3";
|
|
2
|
+
|
|
3
|
+
package shortener.v1;
|
|
4
|
+
|
|
5
|
+
service Shortener {
|
|
6
|
+
rpc CreateShortUrl (CreateShortUrlRequest) returns (CreateShortUrlResponse);
|
|
7
|
+
rpc RetrieveShortUrl (RetrieveShortUrlRequest) returns (RetrieveShortUrlResponse);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
message CreateShortUrlRequest {
|
|
11
|
+
string url = 1;
|
|
12
|
+
string custom_code = 2;
|
|
13
|
+
optional int32 ttl_seconds = 3;
|
|
14
|
+
string expires_in = 4;
|
|
15
|
+
string expires_at = 5;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
message CreateShortUrlResponse {
|
|
19
|
+
string code = 1;
|
|
20
|
+
string short_url = 2;
|
|
21
|
+
string target_url = 3;
|
|
22
|
+
string expires_at = 4;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
message RetrieveShortUrlRequest {
|
|
26
|
+
string code = 1;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
message RetrieveShortUrlResponse {
|
|
30
|
+
bool found = 1;
|
|
31
|
+
string code = 2;
|
|
32
|
+
string target_url = 3;
|
|
33
|
+
string short_url = 4;
|
|
34
|
+
string created_at = 5;
|
|
35
|
+
string expires_at = 6;
|
|
36
|
+
int32 ttl_seconds = 7;
|
|
37
|
+
}
|