Skip to content

Commit 9450fea

Browse files
committed
Initial commit
0 parents  commit 9450fea

Some content is hidden

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

43 files changed

+6369
-0
lines changed

.eslintignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
\.eslintrc.js
2+
dist/
3+
bin/

.eslintrc.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module.exports = {
2+
env: {
3+
node: true,
4+
jest: true,
5+
},
6+
parser: "@typescript-eslint/parser",
7+
parserOptions: {
8+
project: "./tsconfig.json",
9+
},
10+
plugins: ["@typescript-eslint"],
11+
extends: [
12+
"eslint:recommended",
13+
"plugin:@typescript-eslint/recommended",
14+
"plugin:@typescript-eslint/recommended-requiring-type-checking",
15+
"prettier",
16+
],
17+
rules: {
18+
semi: ["error"],
19+
"@typescript-eslint/explicit-function-return-type": [
20+
"error",
21+
{ allowExpressions: false },
22+
],
23+
},
24+
};

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

.node-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
14.17.5

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist/

LICENSE

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

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# sesame-client
2+
3+
SESAME (OS2) client for Node.js and CLI tool

bin/sesame-cli

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env node
2+
3+
"use strict";
4+
const path = require("path");
5+
const fs = require("fs");
6+
7+
process.title = "sesame-cli";
8+
const dist = path.join(path.dirname(fs.realpathSync(__filename)), "../dist");
9+
const { cli } = require(dist + "/cli");
10+
11+
cli();

dist/Sesame.d.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Command } from "./constants";
2+
import { GetStatusResponse, History } from "./types";
3+
declare type Options = {
4+
baseUrl: string;
5+
clientName: string;
6+
secretKey?: string;
7+
};
8+
export declare class Sesame {
9+
uuid: string;
10+
private options;
11+
private client;
12+
constructor(uuid: string, apiKey: string, options?: Partial<Options>);
13+
getStatus: () => Promise<GetStatusResponse>;
14+
getHistory: (params?: {
15+
page?: number;
16+
lg?: number;
17+
}) => Promise<History[]>;
18+
executeCommand: (command: Command) => Promise<void>;
19+
}
20+
export {};

dist/Sesame.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"use strict";
2+
var __importDefault = (this && this.__importDefault) || function (mod) {
3+
return (mod && mod.__esModule) ? mod : { "default": mod };
4+
};
5+
Object.defineProperty(exports, "__esModule", { value: true });
6+
exports.Sesame = void 0;
7+
const axios_1 = __importDefault(require("axios"));
8+
const utils_1 = require("./utils");
9+
const DEFAULT_OPTIONS = {
10+
baseUrl: "https://app.candyhouse.co",
11+
clientName: "SESAME RESTful API",
12+
};
13+
class Sesame {
14+
uuid;
15+
options;
16+
client;
17+
constructor(uuid, apiKey, options) {
18+
this.uuid = uuid;
19+
this.options = { ...DEFAULT_OPTIONS, ...options };
20+
this.client = axios_1.default.create({
21+
baseURL: this.options.baseUrl,
22+
headers: { "X-API-KEY": apiKey },
23+
});
24+
}
25+
getStatus = async () => {
26+
const response = await this.client.get(`/api/sesame2/${this.uuid}`);
27+
return response.data;
28+
};
29+
getHistory = async (params = {}) => {
30+
const defaultParams = { page: 1, lg: 20 };
31+
const response = await this.client.get(`/api/sesame2/${this.uuid}/history`, { params: { ...defaultParams, ...params } });
32+
return response.data.map((history) => utils_1.parseGetHistoryResponse(history));
33+
};
34+
executeCommand = (command) => {
35+
if (!this.options.secretKey) {
36+
throw new Error("Require secret key.");
37+
}
38+
return this.client.post(`/api/sesame2/${this.uuid}/cmd`, {
39+
cmd: command,
40+
sign: utils_1.generateSign(this.options.secretKey),
41+
history: Buffer.from(this.options.clientName).toString("base64"),
42+
});
43+
};
44+
}
45+
exports.Sesame = Sesame;

0 commit comments

Comments
 (0)