@at-pocket/js-sdk 0.0.1

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 ADDED
File without changes
package/package.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "@at-pocket/js-sdk",
3
+ "version": "0.0.1",
4
+ "description": "TypeScript definitions for the atPocket JS SDK",
5
+ "keywords": ["typescript", "types", "atPocket", "js-sdk"],
6
+ "author": "iii@oec",
7
+ "license": "MIT",
8
+ "types": "src/index.d.ts",
9
+ "files": ["src"],
10
+ "publishConfig": {
11
+ "access": "public"
12
+ }
13
+ }
@@ -0,0 +1,4 @@
1
+ export interface Config {
2
+ apiKey: string;
3
+ baseUrl?: string;
4
+ }
@@ -0,0 +1,12 @@
1
+ import { atPocket } from "./interfaces";
2
+
3
+ declare global {
4
+ interface Window {
5
+ atPocket: atPocket;
6
+ }
7
+
8
+ // グローバル変数として `atPocket` を宣言
9
+ var atPocket: atPocket;
10
+ }
11
+
12
+ export {};
package/src/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ /// <reference path="./globals.d.ts" />
2
+
3
+ export * from "./interfaces";
4
+ export * from "./config";
@@ -0,0 +1,16 @@
1
+ import { AppInterface } from './lib/app';
2
+ import { ApiInterface } from "./lib/api";
3
+ import { EventsInterface } from "./lib/events";
4
+ import { PortalInterface } from "./lib/portal";
5
+ import { ProxyInterface } from './lib/proxy';
6
+
7
+ // atPocket インターフェースに `app` を追加
8
+ export interface atPocket {
9
+ getData(endpoint: string): Promise<any>;
10
+ postData(endpoint: string, data: object): Promise<any>;
11
+ api: ApiInterface;
12
+ events: EventsInterface;
13
+ app: AppInterface;
14
+ portal: PortalInterface;
15
+ proxy: ProxyInterface;
16
+ }
@@ -0,0 +1,8 @@
1
+ import { IFailureCallback, IMethod, ISuccessCallback } from "../types";
2
+
3
+ export interface ApiInterface {
4
+ (pathOrUrl: string, method: IMethod, params?: any, successCallback?: ISuccessCallback, failureCallback?: IFailureCallback): Promise<any>;
5
+
6
+ url(pathOrUrl: string): string;
7
+ urlWithQuery(pathOrUrl: string, params?: any): string;
8
+ }
@@ -0,0 +1,58 @@
1
+ import { FieldsInterface } from "./fields";
2
+ import { RecordInterface } from "./record";
3
+
4
+ export interface AppInterface {
5
+
6
+ /**
7
+ * 現在表示しているアプリのAppBarのカスタム領域を取得
8
+ * @see {@link [@pocket JS-SDK](https://app000.at-pocket.com/developers/js-api/app/func.get-app-bar-space-element)}
9
+ *
10
+ * @returns {HTMLElement | null} AppBarのカスタム領域HTML要素
11
+ */
12
+ getAppBarSpaceElement(): HTMLElement | null;
13
+
14
+ /**
15
+ * レコード一覧のフィールド要素を取得
16
+ * @see {@link [@pocket JS-SDK](https://app000.at-pocket.com/developers/js-api/app/func.get-field-elements)}
17
+ *
18
+ * @param fieldUniqueId - フィールドのユニークID
19
+ * @returns NodeListOf<HTMLElement>
20
+ */
21
+ getFieldElements(fieldUniqueId: string): NodeListOf<HTMLElement>;
22
+
23
+ /**
24
+ * レコード一覧のフィールド要素を取得(行INDEX指定)
25
+ * @see {@link [@pocket JS-SDK](https://app000.at-pocket.com/developers/js-api/app/func.get-field-element)}
26
+ *
27
+ * @param fieldUniqueId - フィールドのユニークID
28
+ * @param index - 指定する行のINDEX
29
+ * @returns {HTMLElement | null} 指定フィールドのHTML要素
30
+ */
31
+ getFieldElement(fieldUniqueId: string, index: number): HTMLElement | null;
32
+
33
+ /**
34
+ * アプリのIDを取得
35
+ * @see {@link [@pocket JS-SDK](https://app000.at-pocket.com/developers/js-api/app/func.get-id)}
36
+ *
37
+ * @returns {string | null} 現在表示中のアプリID
38
+ */
39
+ getId(): string | null;
40
+
41
+ /**
42
+ * 現在表示中のレコード一覧のクエリ文字列を取得
43
+ * @see {@link [@pocket JS-SDK](https://app000.at-pocket.com/developers/js-api/app/func.get-query-condition)}
44
+ *
45
+ * @returns {Record<string, any>} クエリ文字列の key: value オブジェクト
46
+ */
47
+ getQueryCondition(): Record<string, any>;
48
+
49
+ /**
50
+ * レコード
51
+ */
52
+ record: RecordInterface;
53
+
54
+ /**
55
+ * フィールド
56
+ */
57
+ fields: FieldsInterface;
58
+ }
@@ -0,0 +1,39 @@
1
+ // イベントハンドラーの型
2
+ export type EventHandler = (event: CustomEvent) => any;
3
+
4
+ // トリガーイベントのオプションの型
5
+ export type IOptions = Record<string, any>;
6
+
7
+ // コールバック関数の型
8
+ export type ICallback = (event: CustomEvent) => void;
9
+
10
+ // Events インターフェースの定義
11
+ export interface EventsInterface {
12
+ /**
13
+ * イベントハンドラーを登録
14
+ * @param types - イベントの種類(文字列 or 文字列配列)
15
+ * @param handler - イベント発火時に実行する関数
16
+ */
17
+ on(types: string | string[], handler: EventHandler): void;
18
+
19
+ /**
20
+ * イベントハンドラーを削除
21
+ * @param types - 削除するイベントの種類(省略可)
22
+ */
23
+ off(types?: string | string[]): void;
24
+
25
+ /**
26
+ * イベントを発火
27
+ * @param type - イベントの種類
28
+ * @param options - イベントのオプション(デフォルト `{}`)
29
+ * @param callback - イベント完了後に実行する関数(オプション)
30
+ */
31
+ trigger(type: string, options?: IOptions, callback?: ICallback): CustomEvent | void;
32
+
33
+ /**
34
+ * すべてのイベントを削除
35
+ */
36
+ remove(): void;
37
+ }
38
+
39
+ export {};
@@ -0,0 +1,29 @@
1
+ export interface FieldsInterface {
2
+ /**
3
+ * フィールドの情報を取得
4
+ * @see {@link [@pocket JS-SDK](https://app000.at-pocket.com/developers/js-api/app/fields/func.get)}
5
+ *
6
+ * @param fieldUniqueId - フィールドのユニークID
7
+ * @returns {string}
8
+ */
9
+ get(fieldUniqueId: string): string;
10
+
11
+ /**
12
+ * 指定したコンテナ内にフィールド選択のセレクトボックスを作成
13
+ * @see {@link [@pocket JS-SDK](https://app000.at-pocket.com/developers/js-api/app/fields/func.get-field-select)}
14
+ *
15
+ * @param containerId - セレクトボックスを配置するコンテナのID
16
+ * @param allowedFieldTypes - 許可するフィールドタイプの配列(オプション)
17
+ * @returns {Promise<void>}
18
+ */
19
+ getFieldSelect(containerId: string, allowedFieldTypes?: string[]): Promise<void>;
20
+
21
+ /**
22
+ * URL から appId と pluginId を抽出
23
+ * @see {@link [@pocket JS-SDK](https://app000.at-pocket.com/developers/js-api/app/fields/func.extractIds)}
24
+ *
25
+ * @param url - 対象URL
26
+ * @returns { appId: number | null, pluginId: number | null }
27
+ */
28
+ extractIds(url: string): { appId: number | null; pluginId: number | null };
29
+ }
@@ -0,0 +1,3 @@
1
+ export interface PluginInterface {
2
+
3
+ }
@@ -0,0 +1,73 @@
1
+ export interface PortalInterface {
2
+ /**
3
+ * 現在表示しているポータルのコンテンツ領域取得
4
+ * @see {@link [@pocket JS-SDK](https://app000.at-pocket.com/developers/js-api/portal/func.get-content-space-element)}
5
+ *
6
+ * @returns {HTMLElement | null} コンテンツ領域のHTML要素
7
+ */
8
+ getContentSpaceElement(): HTMLElement | null;
9
+
10
+ /**
11
+ * 現在表示しているポータルのコンテンツ上部領域取得
12
+ * @see {@link [@pocket JS-SDK](https://app000.at-pocket.com/developers/js-api/portal/func.get-content-top-space-element)}
13
+ *
14
+ * @returns {HTMLElement | null} コンテンツ上部領域のHTML要素
15
+ */
16
+ getContentTopSpaceElement(): HTMLElement | null;
17
+
18
+ /**
19
+ * 現在表示しているポータルのコンテンツ下部領域取得
20
+ * @see {@link [@pocket JS-SDK](https://app000.at-pocket.com/developers/js-api/portal/func.get-content-bottom-space-element)}
21
+ *
22
+ * @returns {HTMLElement | null} コンテンツ下部領域のHTML要素
23
+ */
24
+ getContentBottomSpaceElement(): HTMLElement | null;
25
+
26
+ /**
27
+ * 現在表示しているポータルIDを取得
28
+ * @see {@link [@pocket JS-SDK](https://app000.at-pocket.com/developers/js-api/portal/func.get-id)}
29
+ *
30
+ * @returns {string | null} 現在表示中のポータルID
31
+ */
32
+ getId(): string | null;
33
+
34
+ /**
35
+ * 現在表示しているポータルページIDを取得
36
+ * @see {@link [@pocket JS-SDK](https://app000.at-pocket.com/developers/js-api/portal/func.get-page-id)}
37
+ *
38
+ * @returns {string | null} 現在表示中のポータルページID
39
+ */
40
+ getPageId(): string | null;
41
+
42
+ /**
43
+ * コンテンツ領域をクリア
44
+ * @see {@link [@pocket JS-SDK](https://app000.at-pocket.com/developers/js-api/portal/func.clear-content)}
45
+ *
46
+ * @returns {void}
47
+ */
48
+ clearContent(): void;
49
+
50
+ /**
51
+ * コンテンツ上部領域をクリア
52
+ * @see {@link [@pocket JS-SDK](https://app000.at-pocket.com/developers/js-api/portal/func.clear-content-top)}
53
+ *
54
+ * @returns {void}
55
+ */
56
+ clearContentTop(): void;
57
+
58
+ /**
59
+ * コンテンツ下部領域をクリア
60
+ * @see {@link [@pocket JS-SDK](https://app000.at-pocket.com/developers/js-api/portal/func.clear-content-bottom)}
61
+ *
62
+ * @returns {void}
63
+ */
64
+ clearContentBottom(): void;
65
+
66
+ /**
67
+ * 全てのコンテンツ領域をクリア
68
+ * @see {@link [@pocket JS-SDK](https://app000.at-pocket.com/developers/js-api/portal/func.clear-content-bottom)}
69
+ *
70
+ * @returns {void}
71
+ */
72
+ clearContentAll(): void;
73
+ }
@@ -0,0 +1,6 @@
1
+ import { IData, IFailureCallback, IHeaders, IMethod, ISuccessCallback } from "../types"
2
+
3
+ export interface ProxyInterface {
4
+ (url: string, method: IMethod, headers: IHeaders, data: IData, successCallback?: ISuccessCallback, failureCallback?: IFailureCallback): Promise<any>;
5
+ upload(url: string, method: 'POST' | 'PUT', headers: IHeaders, data: IData, successCallback?: ISuccessCallback, failureCallback?: IFailureCallback): Promise<any>;
6
+ }
@@ -0,0 +1,87 @@
1
+ export interface RecordInterface {
2
+
3
+ /**
4
+ * AppBarのカスタマイズ領域を取得
5
+ * @returns {HTMLElement | null}
6
+ */
7
+ getAppBarSpaceElement(): HTMLElement | null;
8
+ }
9
+
10
+
11
+ /**
12
+ * AppBarのカスタマイズ領域を取得
13
+ * @returns {HTMLElement | null}
14
+ */
15
+ export function getAppBarSpaceElement(): HTMLElement | null;
16
+
17
+ /**
18
+ * レコードIDを取得
19
+ * @returns {number | null} レコードID
20
+ */
21
+ export function getId(): number | null;
22
+
23
+ /**
24
+ * レコードのデータを取得
25
+ * @returns {Record<string, any>}
26
+ */
27
+ export function get(): Record<string, any>;
28
+
29
+ /**
30
+ * レコードに値をセット
31
+ * @param {object} record セットするレコードデータ
32
+ */
33
+ export function set(record: { record: any }): void;
34
+
35
+ /**
36
+ * フィールド要素を取得
37
+ * @param fieldId - フィールドのID
38
+ * @returns HTMLElement | null
39
+ */
40
+ export function getFieldElement(fieldId: string): HTMLElement | null;
41
+
42
+ /**
43
+ * フィールドのラベル要素を取得
44
+ * @param fieldId - フィールドのID
45
+ * @returns HTMLElement | null
46
+ */
47
+ export function getFieldLabelElement(fieldId: string): HTMLElement | null;
48
+
49
+ /**
50
+ * フィールドのデータ要素を取得
51
+ * @param fieldId - フィールドのID
52
+ * @returns HTMLElement | null
53
+ */
54
+ export function getFieldDataElement(fieldId: string): HTMLElement | null;
55
+
56
+ /**
57
+ * スペースフィールドの要素を取得
58
+ * @param fieldId - フィールドのID
59
+ * @returns HTMLElement | null
60
+ */
61
+ export function getSpaceElement(fieldId: string): HTMLElement | null;
62
+
63
+ /**
64
+ * フィールドの表示/非表示を切り替える
65
+ * @param fieldId - フィールドのID
66
+ * @param isShown - 表示するかどうか
67
+ */
68
+ export function setFieldShown(fieldId: string, isShown: boolean): void;
69
+
70
+ /**
71
+ * フィールドの編集可/不可を切り替える
72
+ * @param fieldId - フィールドのID
73
+ * @param isDisabled - 編集不可にするかどうか
74
+ */
75
+ export function setFieldDisabled(fieldId: string, isDisabled: boolean): void;
76
+
77
+ /**
78
+ * レコードのヘッダーの要素を取得
79
+ * @returns HTMLElement | null
80
+ */
81
+ export function getRecordHeaderSpaceElement(): HTMLElement | null;
82
+
83
+ /**
84
+ * レコードのフッターの要素を取得
85
+ * @returns HTMLElement | null
86
+ */
87
+ export function getRecordFooterSpaceElement(): HTMLElement | null;
package/src/types.ts ADDED
@@ -0,0 +1,5 @@
1
+ export type IMethod = 'GET' | 'POST' | 'PUT' | 'DELETE';
2
+ export type IHeaders = Record<string, string>;
3
+ export type IData = Record<string, any>;
4
+ export type ISuccessCallback = (data: any, headers: any, status: any) => void;
5
+ export type IFailureCallback = (error: any) => void;