@nx-ddd/notion 18.11.0 → 18.12.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/notion/index.d.ts +1 -0
- package/notion/index.js +5 -0
- package/notion/index.js.map +1 -0
- package/notion/notion.service.d.ts +8 -0
- package/notion/notion.service.impl.d.ts +30 -0
- package/notion/notion.service.impl.js +142 -0
- package/notion/notion.service.impl.js.map +1 -0
- package/notion/notion.service.js +12 -0
- package/notion/notion.service.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './notion.service';
|
package/notion/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/@nx-ddd/notion/src/lib/notion/index.ts"],"names":[],"mappings":";;;AAAA,2DAAiC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { InjectionToken } from "@angular/core";
|
|
2
|
+
import type { NotionService } from "./notion.service.impl";
|
|
3
|
+
export interface NotionConfig {
|
|
4
|
+
token: string;
|
|
5
|
+
}
|
|
6
|
+
export declare const NOTION_SERVICE: InjectionToken<NotionService>;
|
|
7
|
+
export declare const NOTION_CONFIG: InjectionToken<NotionConfig>;
|
|
8
|
+
export declare function injectNotion(): NotionService;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { InjectionToken, Provider } from '@angular/core';
|
|
2
|
+
import { LocalStorage } from "node-localstorage";
|
|
3
|
+
export interface NotionConfig {
|
|
4
|
+
token: string;
|
|
5
|
+
}
|
|
6
|
+
export declare const NOTION_CONFIG: InjectionToken<NotionConfig>;
|
|
7
|
+
export declare function provideNotionService(useFactory: () => NotionConfig): Provider[];
|
|
8
|
+
export declare class CacheAdapter {
|
|
9
|
+
protected localStorage: LocalStorage;
|
|
10
|
+
get<T>(keyOrObj: string | object): Promise<T | null>;
|
|
11
|
+
set(keyOrObj: string | object, value: any): Promise<void>;
|
|
12
|
+
remove(keyOrObj: string | object): Promise<void>;
|
|
13
|
+
call<P extends (string | object), T>(props: P, callback: (props: P) => Promise<T>): Promise<T>;
|
|
14
|
+
protected makeKey(keyOrObj: string | object): string;
|
|
15
|
+
protected makeJson(valueOrObj: any): string;
|
|
16
|
+
protected parseJson(value: string): any;
|
|
17
|
+
}
|
|
18
|
+
export declare class NotionService {
|
|
19
|
+
private config;
|
|
20
|
+
private notionClient;
|
|
21
|
+
private cache;
|
|
22
|
+
retrievePage(pageId: string): Promise<import("@notionhq/client/build/src/api-endpoints").GetPageResponse>;
|
|
23
|
+
updatePage(pageId: string, properties: any): Promise<import("@notionhq/client/build/src/api-endpoints").UpdatePageResponse>;
|
|
24
|
+
deletePage(pageId: string): Promise<void>;
|
|
25
|
+
retrieveDatabase(databaseId: string): Promise<import("@notionhq/client/build/src/api-endpoints").GetDatabaseResponse>;
|
|
26
|
+
updateDatabase(databaseId: string, properties: any): Promise<import("@notionhq/client/build/src/api-endpoints").UpdateDatabaseResponse>;
|
|
27
|
+
retrieveBlock(blockId: string): Promise<import("@notionhq/client/build/src/api-endpoints").GetBlockResponse>;
|
|
28
|
+
search(params: Parameters<typeof this.notionClient.search>[0]): Promise<import("@notionhq/client/build/src/api-endpoints").SearchResponse>;
|
|
29
|
+
queryDatabase(databaseId: string, filter?: any): Promise<(import("@notionhq/client/build/src/api-endpoints").PageObjectResponse | import("@notionhq/client/build/src/api-endpoints").PartialPageObjectResponse | import("@notionhq/client/build/src/api-endpoints").PartialDatabaseObjectResponse | import("@notionhq/client/build/src/api-endpoints").DatabaseObjectResponse)[]>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NotionService = exports.CacheAdapter = exports.NOTION_CONFIG = void 0;
|
|
4
|
+
exports.provideNotionService = provideNotionService;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const core_1 = require("@angular/core");
|
|
7
|
+
const client_1 = require("@notionhq/client");
|
|
8
|
+
const notion_service_1 = require("./notion.service");
|
|
9
|
+
const node_localstorage_1 = require("node-localstorage");
|
|
10
|
+
const CryptoJS = tslib_1.__importStar(require("crypto-js"));
|
|
11
|
+
exports.NOTION_CONFIG = new core_1.InjectionToken('NOTION_CONFIG');
|
|
12
|
+
function provideNotionService(useFactory) {
|
|
13
|
+
return [
|
|
14
|
+
{ provide: exports.NOTION_CONFIG, useFactory },
|
|
15
|
+
{ provide: notion_service_1.NOTION_SERVICE, useClass: NotionService },
|
|
16
|
+
];
|
|
17
|
+
}
|
|
18
|
+
let CacheAdapter = class CacheAdapter {
|
|
19
|
+
constructor() {
|
|
20
|
+
this.localStorage = global.localStorage || new node_localstorage_1.LocalStorage('node_modules/.cache/@nx-ddd/notion', 5 * 1024 * 1024 * 1024);
|
|
21
|
+
}
|
|
22
|
+
get(keyOrObj) {
|
|
23
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
const key = this.makeKey(keyOrObj);
|
|
25
|
+
return this.parseJson(this.localStorage.getItem(key));
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
set(keyOrObj, value) {
|
|
29
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
const key = this.makeKey(keyOrObj);
|
|
31
|
+
this.localStorage.setItem(key, this.makeJson(value));
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
remove(keyOrObj) {
|
|
35
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
const key = this.makeKey(keyOrObj);
|
|
37
|
+
this.localStorage.removeItem(key);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
call(props, callback) {
|
|
41
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
const key = this.makeKey(props);
|
|
43
|
+
let value = yield this.get(key);
|
|
44
|
+
if (value)
|
|
45
|
+
return value;
|
|
46
|
+
value = yield callback(props);
|
|
47
|
+
yield this.set(key, value);
|
|
48
|
+
return value;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
makeKey(keyOrObj) {
|
|
52
|
+
const value = typeof keyOrObj === 'string' ? keyOrObj : JSON.stringify(keyOrObj);
|
|
53
|
+
return CryptoJS.SHA256(value).toString();
|
|
54
|
+
}
|
|
55
|
+
makeJson(valueOrObj) {
|
|
56
|
+
return JSON.stringify(valueOrObj);
|
|
57
|
+
}
|
|
58
|
+
parseJson(value) {
|
|
59
|
+
return JSON.parse(value);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
exports.CacheAdapter = CacheAdapter;
|
|
63
|
+
exports.CacheAdapter = CacheAdapter = tslib_1.__decorate([
|
|
64
|
+
(0, core_1.Injectable)({ providedIn: 'root' })
|
|
65
|
+
], CacheAdapter);
|
|
66
|
+
let NotionService = class NotionService {
|
|
67
|
+
constructor() {
|
|
68
|
+
this.config = (0, core_1.inject)(exports.NOTION_CONFIG);
|
|
69
|
+
this.notionClient = new client_1.Client({ auth: this.config.token });
|
|
70
|
+
this.cache = (0, core_1.inject)(CacheAdapter);
|
|
71
|
+
}
|
|
72
|
+
retrievePage(pageId) {
|
|
73
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
74
|
+
return this.cache.call(pageId, () => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
75
|
+
return this.notionClient.pages.retrieve({ page_id: pageId });
|
|
76
|
+
}));
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
updatePage(pageId, properties) {
|
|
80
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
81
|
+
const response = yield this.notionClient.pages.update({
|
|
82
|
+
page_id: pageId,
|
|
83
|
+
properties,
|
|
84
|
+
});
|
|
85
|
+
return response;
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
deletePage(pageId) {
|
|
89
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
90
|
+
yield this.notionClient.pages.update({
|
|
91
|
+
page_id: pageId,
|
|
92
|
+
archived: true,
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
retrieveDatabase(databaseId) {
|
|
97
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
98
|
+
// return this.cache.call(databaseId, async () => {
|
|
99
|
+
return this.notionClient.databases.retrieve({ database_id: databaseId });
|
|
100
|
+
// });
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
updateDatabase(databaseId, properties) {
|
|
104
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
105
|
+
console.debug('properties:', properties);
|
|
106
|
+
const response = yield this.notionClient.databases.update({
|
|
107
|
+
database_id: databaseId,
|
|
108
|
+
properties,
|
|
109
|
+
});
|
|
110
|
+
yield this.cache.remove(databaseId);
|
|
111
|
+
return response;
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
retrieveBlock(blockId) {
|
|
115
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
116
|
+
return this.cache.call(blockId, () => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
117
|
+
return this.notionClient.blocks.retrieve({ block_id: blockId });
|
|
118
|
+
}));
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
search(params) {
|
|
122
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
123
|
+
return this.cache.call(params, () => {
|
|
124
|
+
return this.notionClient.search(params);
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
queryDatabase(databaseId, filter) {
|
|
129
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
130
|
+
const response = yield this.notionClient.databases.query({
|
|
131
|
+
database_id: databaseId,
|
|
132
|
+
filter,
|
|
133
|
+
});
|
|
134
|
+
return response.results;
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
exports.NotionService = NotionService;
|
|
139
|
+
exports.NotionService = NotionService = tslib_1.__decorate([
|
|
140
|
+
(0, core_1.Injectable)({ providedIn: 'root' })
|
|
141
|
+
], NotionService);
|
|
142
|
+
//# sourceMappingURL=notion.service.impl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notion.service.impl.js","sourceRoot":"","sources":["../../../../../packages/@nx-ddd/notion/src/lib/notion/notion.service.impl.ts"],"names":[],"mappings":";;;AAYA,oDAKC;;AAjBD,wCAA6E;AAC7E,6CAA0C;AAC1C,qDAAkD;AAClD,yDAAiD;AACjD,4DAAsC;AAMzB,QAAA,aAAa,GAAG,IAAI,qBAAc,CAAe,eAAe,CAAC,CAAC;AAE/E,SAAgB,oBAAoB,CAAC,UAA8B;IACjE,OAAO;QACL,EAAE,OAAO,EAAE,qBAAa,EAAE,UAAU,EAAE;QACtC,EAAE,OAAO,EAAE,+BAAc,EAAE,QAAQ,EAAE,aAAa,EAAE;KACrD,CAAC;AACJ,CAAC;AAEM,IAAM,YAAY,GAAlB,MAAM,YAAY;IAAlB;QACK,iBAAY,GAAiB,MAAM,CAAC,YAAY,IAAI,IAAI,gCAAY,CAAC,oCAAoC,EAAE,CAAC,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC;IAsC/I,CAAC;IApCO,GAAG,CAAI,QAAyB;;YACpC,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;YACnC,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,CAAa,CAAC;QACpE,CAAC;KAAA;IAEK,GAAG,CAAC,QAAyB,EAAE,KAAU;;YAC7C,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;YACnC,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;QACvD,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C,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;YACpC,OAAO,QAAQ,CAAC;QAClB,CAAC;KAAA;IAEK,aAAa,CAAC,OAAe;;YACjC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,GAAS,EAAE;gBACzC,OAAO,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;YAClE,CAAC,CAAA,CAAC,CAAC;QACL,CAAC;KAAA;IAEK,MAAM,CAAC,MAAsD;;YACjE,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE;gBAClC,OAAO,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAC1C,CAAC,CAAC,CAAC;QACL,CAAC;KAAA;IAEK,aAAa,CAAC,UAAkB,EAAE,MAAY;;YAClD,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,KAAK,CAAC;gBACvD,WAAW,EAAE,UAAU;gBACvB,MAAM;aACP,CAAC,CAAC;YACH,OAAO,QAAQ,CAAC,OAAO,CAAC;QAC1B,CAAC;KAAA;CACF,CAAA;AA7DY,sCAAa;wBAAb,aAAa;IADzB,IAAA,iBAAU,EAAC,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC;GACtB,aAAa,CA6DzB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NOTION_CONFIG = exports.NOTION_SERVICE = void 0;
|
|
4
|
+
exports.injectNotion = injectNotion;
|
|
5
|
+
const core_1 = require("@angular/core");
|
|
6
|
+
exports.NOTION_SERVICE = new core_1.InjectionToken('NOTION_SERVICE');
|
|
7
|
+
exports.NOTION_CONFIG = new core_1.InjectionToken('NOTION_CONFIG');
|
|
8
|
+
function injectNotion() {
|
|
9
|
+
var _a;
|
|
10
|
+
return (_a = (0, core_1.inject)(exports.NOTION_SERVICE, { optional: true })) !== null && _a !== void 0 ? _a : null;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=notion.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notion.service.js","sourceRoot":"","sources":["../../../../../packages/@nx-ddd/notion/src/lib/notion/notion.service.ts"],"names":[],"mappings":";;;AAUA,oCAEC;AAZD,wCAAuD;AAO1C,QAAA,cAAc,GAAG,IAAI,qBAAc,CAAgB,gBAAgB,CAAC,CAAC;AACrE,QAAA,aAAa,GAAG,IAAI,qBAAc,CAAe,eAAe,CAAC,CAAC;AAE/E,SAAgB,YAAY;;IAC1B,OAAO,MAAA,IAAA,aAAM,EAAC,sBAAc,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,mCAAI,IAAI,CAAC;AAC5D,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx-ddd/notion",
|
|
3
|
-
"version": "18.
|
|
3
|
+
"version": "18.12.0",
|
|
4
4
|
"main": "./index.js",
|
|
5
5
|
"types": "./index.d.ts",
|
|
6
6
|
"homepage": "https://github.com/xx-machina/plaform/tree/main/packages/@nx-ddd/notion",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
},
|
|
11
11
|
"peerDependencies": {
|
|
12
12
|
"@notionhq/client": "^2.2.2",
|
|
13
|
-
"@nx-ddd/common": "18.
|
|
13
|
+
"@nx-ddd/common": "18.12.0",
|
|
14
14
|
"dayjs": "1.11.12",
|
|
15
15
|
"lodash-es": "^4.17.15",
|
|
16
16
|
"tslib": "^2.3.0",
|