@aulynk/miniapp-sdk 0.0.0-stage → 0.1.1-ci.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 CHANGED
@@ -1,3 +1,21 @@
1
- # Temporary Holding Version
1
+ # @aulynk/miniapp-sdk
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Browser SDK for [Aulynk](https://aulynk.ru) Mini Apps. Use it inside a Mini App iframe to read user and chat information, send data to a bot, or close the app.
4
+
5
+ ```sh
6
+ npm install @aulynk/miniapp-sdk
7
+ ```
8
+
9
+ ```ts
10
+ import { AulynkMiniApp } from '@aulynk/miniapp-sdk';
11
+
12
+ const app = AulynkMiniApp.init();
13
+ const user = await app.getUser();
14
+ console.log(user.name);
15
+ ```
16
+
17
+ ## Releases
18
+
19
+ Run `npm version patch` (or use `minor` or `major`), then push the commit and version tag with `git push --follow-tags`. The tag must match the version in `package.json`. GitHub Actions publishes stable versions to npm and prereleases under the `next` dist-tag.
20
+
21
+ For the initial setup, publish the first version from an npm account with write access to the `@aulynk` scope. Then configure a GitHub Actions Trusted Publisher in the npm package settings. Use the `Aulynk` organization, this repository, and the `publish.yml` workflow. Enable direct publishing.
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Aulynk Mini App SDK
3
+ *
4
+ * Use this SDK inside an iframe-based mini app to communicate
5
+ * with the Aulynk client.
6
+ *
7
+ * @example
8
+ * ```html
9
+ * <script type="module">
10
+ * import { AulynkMiniApp } from '@aulynk/miniapp-sdk';
11
+ *
12
+ * const app = AulynkMiniApp.init();
13
+ *
14
+ * const user = await app.getUser();
15
+ * console.log('Hello', user.name);
16
+ *
17
+ * document.getElementById('close').onclick = () => app.close();
18
+ * </script>
19
+ * ```
20
+ */
21
+ export interface MiniAppUser {
22
+ id: number;
23
+ name: string;
24
+ username?: string;
25
+ avatarUrl?: string;
26
+ }
27
+ export interface MiniAppChat {
28
+ id: string;
29
+ }
30
+ export interface InitData {
31
+ userId: number;
32
+ userName: string;
33
+ appId: number;
34
+ appName: string;
35
+ chatId?: string;
36
+ ts: number;
37
+ sig: string;
38
+ raw: string;
39
+ }
40
+ export declare class AulynkMiniApp {
41
+ private initData;
42
+ private requestId;
43
+ private pending;
44
+ private constructor();
45
+ /**
46
+ * Initialize the Mini App SDK.
47
+ * Parses init_data from the URL and signals readiness to the Aulynk client.
48
+ */
49
+ static init(): AulynkMiniApp;
50
+ /** Get the raw init_data string (for server-side validation) */
51
+ getInitData(): string;
52
+ /** Get parsed init data */
53
+ getParsedInitData(): InitData;
54
+ /** Get current user info */
55
+ getUser(): Promise<MiniAppUser>;
56
+ /** Get current chat info */
57
+ getChat(): Promise<MiniAppChat | null>;
58
+ /**
59
+ * Send data back to the bot.
60
+ * The bot will receive this as a callback event.
61
+ */
62
+ sendData(data: any, opts?: {
63
+ botId?: number;
64
+ messageId?: number;
65
+ }): Promise<void>;
66
+ /** Close the mini app */
67
+ close(): void;
68
+ private request;
69
+ }
70
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,MAAM,WAAW,WAAW;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,WAAW;IACxB,EAAE,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,QAAQ;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;CACf;AAOD,qBAAa,aAAa;IACtB,OAAO,CAAC,QAAQ,CAAW;IAC3B,OAAO,CAAC,SAAS,CAAK;IACtB,OAAO,CAAC,OAAO,CAAqC;IAEpD,OAAO;IAqBP;;;OAGG;IACH,MAAM,CAAC,IAAI,IAAI,aAAa;IAwB5B,gEAAgE;IAChE,WAAW,IAAI,MAAM;IAIrB,2BAA2B;IAC3B,iBAAiB,IAAI,QAAQ;IAI7B,4BAA4B;IACtB,OAAO,IAAI,OAAO,CAAC,WAAW,CAAC;IAIrC,4BAA4B;IACtB,OAAO,IAAI,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAI5C;;;OAGG;IACG,QAAQ,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IASvF,yBAAyB;IACzB,KAAK,IAAI,IAAI;IAIb,OAAO,CAAC,OAAO;CAgBlB"}
package/dist/index.js ADDED
@@ -0,0 +1,115 @@
1
+ /**
2
+ * Aulynk Mini App SDK
3
+ *
4
+ * Use this SDK inside an iframe-based mini app to communicate
5
+ * with the Aulynk client.
6
+ *
7
+ * @example
8
+ * ```html
9
+ * <script type="module">
10
+ * import { AulynkMiniApp } from '@aulynk/miniapp-sdk';
11
+ *
12
+ * const app = AulynkMiniApp.init();
13
+ *
14
+ * const user = await app.getUser();
15
+ * console.log('Hello', user.name);
16
+ *
17
+ * document.getElementById('close').onclick = () => app.close();
18
+ * </script>
19
+ * ```
20
+ */
21
+ export class AulynkMiniApp {
22
+ constructor(initData) {
23
+ this.requestId = 0;
24
+ this.pending = new Map();
25
+ this.initData = initData;
26
+ // Listen for responses from parent
27
+ window.addEventListener('message', (e) => {
28
+ const msg = e.data;
29
+ if (!msg || typeof msg !== 'object')
30
+ return;
31
+ if (msg.type === 'aulynk:response' && typeof msg.id === 'number') {
32
+ const req = this.pending.get(msg.id);
33
+ if (req) {
34
+ this.pending.delete(msg.id);
35
+ if (msg.error) {
36
+ req.reject(new Error(msg.error));
37
+ }
38
+ else {
39
+ req.resolve(msg.data);
40
+ }
41
+ }
42
+ }
43
+ });
44
+ }
45
+ /**
46
+ * Initialize the Mini App SDK.
47
+ * Parses init_data from the URL and signals readiness to the Aulynk client.
48
+ */
49
+ static init() {
50
+ const params = new URLSearchParams(window.location.search);
51
+ const raw = params.get('init_data') || '';
52
+ const initParams = new URLSearchParams(raw.split('&sig=')[0]);
53
+ const initData = {
54
+ userId: Number(initParams.get('user_id') || 0),
55
+ userName: initParams.get('user_name') || '',
56
+ appId: Number(initParams.get('app_id') || 0),
57
+ appName: initParams.get('app_name') || '',
58
+ chatId: initParams.get('chat_id') || undefined,
59
+ ts: Number(initParams.get('ts') || 0),
60
+ sig: raw.split('&sig=')[1] || '',
61
+ raw,
62
+ };
63
+ const app = new AulynkMiniApp(initData);
64
+ // Signal ready to parent
65
+ window.parent.postMessage({ type: 'aulynk:ready' }, '*');
66
+ return app;
67
+ }
68
+ /** Get the raw init_data string (for server-side validation) */
69
+ getInitData() {
70
+ return this.initData.raw;
71
+ }
72
+ /** Get parsed init data */
73
+ getParsedInitData() {
74
+ return { ...this.initData };
75
+ }
76
+ /** Get current user info */
77
+ async getUser() {
78
+ return this.request('aulynk:getUser');
79
+ }
80
+ /** Get current chat info */
81
+ async getChat() {
82
+ return this.request('aulynk:getChat');
83
+ }
84
+ /**
85
+ * Send data back to the bot.
86
+ * The bot will receive this as a callback event.
87
+ */
88
+ async sendData(data, opts) {
89
+ window.parent.postMessage({
90
+ type: 'aulynk:sendData',
91
+ data,
92
+ botId: opts?.botId,
93
+ messageId: opts?.messageId,
94
+ }, '*');
95
+ }
96
+ /** Close the mini app */
97
+ close() {
98
+ window.parent.postMessage({ type: 'aulynk:close' }, '*');
99
+ }
100
+ request(type, data) {
101
+ return new Promise((resolve, reject) => {
102
+ const id = ++this.requestId;
103
+ this.pending.set(id, { resolve, reject });
104
+ window.parent.postMessage({ type, id, ...data }, '*');
105
+ // Timeout after 10s
106
+ setTimeout(() => {
107
+ if (this.pending.has(id)) {
108
+ this.pending.delete(id);
109
+ reject(new Error(`Mini App request timeout: ${type}`));
110
+ }
111
+ }, 10000);
112
+ });
113
+ }
114
+ }
115
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AA6BH,MAAM,OAAO,aAAa;IAKtB,YAAoB,QAAkB;QAH9B,cAAS,GAAG,CAAC,CAAC;QACd,YAAO,GAAG,IAAI,GAAG,EAA0B,CAAC;QAGhD,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAEzB,mCAAmC;QACnC,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,CAAC,CAAC,EAAE,EAAE;YACrC,MAAM,GAAG,GAAG,CAAC,CAAC,IAAI,CAAC;YACnB,IAAI,CAAC,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ;gBAAE,OAAO;YAC5C,IAAI,GAAG,CAAC,IAAI,KAAK,iBAAiB,IAAI,OAAO,GAAG,CAAC,EAAE,KAAK,QAAQ,EAAE,CAAC;gBAC/D,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;gBACrC,IAAI,GAAG,EAAE,CAAC;oBACN,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;oBAC5B,IAAI,GAAG,CAAC,KAAK,EAAE,CAAC;wBACZ,GAAG,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;oBACrC,CAAC;yBAAM,CAAC;wBACJ,GAAG,CAAC,OAAO,CAAC,GA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E,CAAC,EAAE,CAAC;oBACvB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;oBACxB,MAAM,CAAC,IAAI,KAAK,CAAC,6BAA6B,IAAI,EAAE,CAAC,CAAC,CAAC;gBAC3D,CAAC;YACL,CAAC,EAAE,KAAK,CAAC,CAAC;QACd,CAAC,CAAC,CAAC;IACP,CAAC;CACJ"}
package/package.json CHANGED
@@ -1,6 +1,30 @@
1
1
  {
2
2
  "name": "@aulynk/miniapp-sdk",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1-ci.0",
4
+ "description": "SDK for building Aulynk Mini Apps (iframe-based)",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist",
9
+ "README.md"
10
+ ],
11
+ "scripts": {
12
+ "build": "tsc",
13
+ "prepublishOnly": "npm run build"
14
+ },
15
+ "devDependencies": {
16
+ "typescript": "^5.4.0"
17
+ },
18
+ "publishConfig": {
19
+ "registry": "https://registry.npmjs.org/",
20
+ "access": "public"
21
+ },
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/Aulynk/aulynk-miniapp-sdk.git"
25
+ },
26
+ "bugs": {
27
+ "url": "https://github.com/Aulynk/aulynk-miniapp-sdk/issues"
28
+ },
29
+ "type": "module"
30
+ }