@dohaidang/locket_mod.js 0.0.0-stage → 0.0.3

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/LICENSE ADDED
@@ -0,0 +1,131 @@
1
+ # PolyForm Noncommercial License 1.0.0
2
+
3
+ <https://polyformproject.org/licenses/noncommercial/1.0.0>
4
+
5
+ ## Acceptance
6
+
7
+ In order to get any license under these terms, you must agree
8
+ to them as both strict obligations and conditions to all
9
+ your licenses.
10
+
11
+ ## Copyright License
12
+
13
+ The licensor grants you a copyright license for the
14
+ software to do everything you might do with the software
15
+ that would otherwise infringe the licensor's copyright
16
+ in it for any permitted purpose. However, you may
17
+ only distribute the software according to [Distribution
18
+ License](#distribution-license) and make changes or new works
19
+ based on the software according to [Changes and New Works
20
+ License](#changes-and-new-works-license).
21
+
22
+ ## Distribution License
23
+
24
+ The licensor grants you an additional copyright license
25
+ to distribute copies of the software. Your license
26
+ to distribute covers distributing the software with
27
+ changes and new works permitted by [Changes and New Works
28
+ License](#changes-and-new-works-license).
29
+
30
+ ## Notices
31
+
32
+ You must ensure that anyone who gets a copy of any part of
33
+ the software from you also gets a copy of these terms or the
34
+ URL for them above, as well as copies of any plain-text lines
35
+ beginning with `Required Notice:` that the licensor provided
36
+ with the software. For example:
37
+
38
+ > Required Notice: Copyright Hmk8386 (https://github.com/hmk8386)
39
+
40
+ ## Changes and New Works License
41
+
42
+ The licensor grants you an additional copyright license to
43
+ make changes and new works based on the software for any
44
+ permitted purpose.
45
+
46
+ ## Patent License
47
+
48
+ The licensor grants you a patent license for the software that
49
+ covers patent claims the licensor can license, or becomes able
50
+ to license, that you would infringe by using the software.
51
+
52
+ ## Noncommercial Purposes
53
+
54
+ Any noncommercial purpose is a permitted purpose.
55
+
56
+ ## Personal Uses
57
+
58
+ Personal use for research, experiment, and testing for
59
+ the benefit of public knowledge, personal study, private
60
+ entertainment, hobby projects, amateur pursuits, or religious
61
+ observance, without any anticipated commercial application,
62
+ is use for a permitted purpose.
63
+
64
+ ## Noncommercial Organizations
65
+
66
+ Use by any charitable organization, educational institution,
67
+ public research organization, public safety or health
68
+ organization, environmental protection organization,
69
+ or government institution is use for a permitted purpose
70
+ regardless of the source of funding or obligations resulting
71
+ from the funding.
72
+
73
+ ## Fair Use
74
+
75
+ You may have "fair use" rights for the software under the
76
+ law. These terms do not limit them.
77
+
78
+ ## No Other Rights
79
+
80
+ These terms do not allow you to sublicense or transfer any of
81
+ your licenses to anyone else, or prevent the licensor from
82
+ granting licenses to anyone else. These terms do not imply
83
+ any other licenses.
84
+
85
+ ## Patent Defense
86
+
87
+ If you make any written claim that the software infringes or
88
+ contributes to infringement of any patent, your patent license
89
+ for the software granted under these terms ends immediately. If
90
+ your company makes such a claim, your patent license ends
91
+ immediately for work on behalf of your company.
92
+
93
+ ## Violations
94
+
95
+ The first time you are notified in writing that you have
96
+ violated any of these terms, or done anything with the software
97
+ not covered by your licenses, your licenses can nonetheless
98
+ continue if you come into full compliance with these terms,
99
+ and take practical steps to correct past violations, within
100
+ 32 days of receiving notice. Otherwise, all your licenses
101
+ end immediately.
102
+
103
+ ## No Liability
104
+
105
+ ***As far as the law allows, the software comes as is, without
106
+ any warranty or condition, and the licensor will not be liable
107
+ to you for any damages arising out of these terms or the use
108
+ or nature of the software, under any kind of legal claim.***
109
+
110
+ ## Definitions
111
+
112
+ The **licensor** is the individual or entity offering these
113
+ terms, and the **software** is the software the licensor makes
114
+ available under these terms.
115
+
116
+ **You** refers to the individual or entity agreeing to these
117
+ terms.
118
+
119
+ **Your company** is any legal entity, sole proprietorship,
120
+ or other kind of organization that you work for, plus all
121
+ organizations that have control over, are under the control of,
122
+ or are under common control with that organization. **Control**
123
+ means ownership of substantially all the assets of an entity,
124
+ or the power to direct its management and policies by vote,
125
+ contract, or otherwise. Control can be direct or indirect.
126
+
127
+ **Your licenses** are all the licenses granted to you for the
128
+ software under these terms.
129
+
130
+ **Use** means anything you do with the software requiring one
131
+ of your licenses.
package/README.md CHANGED
@@ -1,3 +1,288 @@
1
- # Temporary Holding Version
1
+ # locket_mod.js
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
+ **Unofficial Node.js SDK for Locket Camera.** Log in, post photo and video moments, read your feed, manage friends and chat in real time, all from plain JavaScript and without an iPhone.
4
+
5
+ [![npm](https://img.shields.io/npm/v/@dohaidang/locket_mod.js.svg?style=flat-square)](https://www.npmjs.com/package/@dohaidang/locket_mod.js)
6
+ [![node](https://img.shields.io/badge/node-%3E%3D18-brightgreen.svg?style=flat-square)](https://nodejs.org)
7
+ [![license](https://img.shields.io/badge/license-PolyForm%20Noncommercial%201.0.0-blue.svg?style=flat-square)](LICENSE)
8
+
9
+ > [!WARNING]
10
+ > This is an unofficial, reverse-engineered client. It is not affiliated with Locket Camera, Inc. The private API it talks to can change at any time, and heavy automated use may get an account limited. **Noncommercial use only.** See [License](#license).
11
+
12
+ ---
13
+
14
+ ## Contents
15
+
16
+ - [Requirements](#requirements)
17
+ - [Install](#install)
18
+ - [Quick start](#quick-start)
19
+ - [Sessions](#sessions)
20
+ - [API](#api)
21
+ - [User](#user--clientuser)
22
+ - [Moments](#moments--clientmoments)
23
+ - [Friends](#friends--clientfriends)
24
+ - [Chat](#chat--clientchat)
25
+ - [Device profile](#device-profile)
26
+ - [Errors](#errors)
27
+ - [How it works](#how-it-works)
28
+ - [Running on a server or serverless](#running-on-a-server-or-serverless)
29
+ - [Development](#development)
30
+ - [License](#license)
31
+
32
+ ## Requirements
33
+
34
+ | | |
35
+ |---|---|
36
+ | **Node.js** | 18 or newer (uses the built-in `fetch`) |
37
+ | **sharp** | installed automatically, used to convert images to WebP |
38
+ | **ws** | installed automatically, only needed for real-time chat |
39
+ | **ffmpeg** | *optional*, must be on your `PATH` to post videos (thumbnail extraction + compression) |
40
+
41
+ On Windows you can get ffmpeg with `winget install Gyan.FFmpeg`; on macOS with `brew install ffmpeg`.
42
+
43
+ ## Install
44
+
45
+ ```bash
46
+ npm install @dohaidang/locket_mod.js
47
+ ```
48
+
49
+ ## Quick start
50
+
51
+ ```js
52
+ const { LocketClient } = require("@dohaidang/locket_mod.js");
53
+
54
+ (async () => {
55
+ const client = new LocketClient({ sessionPath: "my.session.json" });
56
+
57
+ // Only logs in the first time; later runs reuse the saved session.
58
+ if (!client.isAuthenticated()) {
59
+ await client.login(process.env.LOCKET_EMAIL, process.env.LOCKET_PASSWORD);
60
+ }
61
+
62
+ const me = await client.user.getProfile();
63
+ console.log(`Hi ${me.first_name} (@${me.username})`);
64
+
65
+ await client.moments.post({
66
+ image: "photo.jpg",
67
+ caption: "Posted from Node.js ✨",
68
+ });
69
+ })().catch(console.error);
70
+ ```
71
+
72
+ ```bash
73
+ # PowerShell
74
+ $env:LOCKET_EMAIL="you@example.com"; $env:LOCKET_PASSWORD="..."; node app.js
75
+ # bash
76
+ LOCKET_EMAIL=you@example.com LOCKET_PASSWORD=... node app.js
77
+ ```
78
+
79
+ ## Sessions
80
+
81
+ After `login()`, the client writes a JSON file at `sessionPath` containing your Firebase tokens and the emulated device. On the next run it loads that file and skips logging in. The `idToken` (valid about one hour) is refreshed automatically when it has less than a minute left.
82
+
83
+ > [!CAUTION]
84
+ > The session file is effectively your logged-in account. **Never commit it.** This repo's `.gitignore` only ignores names matching `*.session.json`, so name it e.g. `my.session.json`.
85
+
86
+ The client also keeps two small helper files next to the session file: `my_moments_<uid>.json` (moments you posted) and `chat_history.json` (a local message cache).
87
+
88
+ ## API
89
+
90
+ Every method returns a Promise. A client exposes four modules: `client.user`, `client.moments`, `client.friends`, `client.chat`.
91
+
92
+ ### User — `client.user`
93
+
94
+ | Method | Description |
95
+ |---|---|
96
+ | `getProfile(uid?)` | Your profile, or another user's by UID |
97
+ | `getProfileByUsername(username)` | Resolve a `locket.cam/<username>` link to a profile |
98
+ | `updateName(first, last)` | Change display name |
99
+ | `updateBirthdate("YYYY-MM-DD")` | Change birthdate |
100
+ | `updateAvatar(fileOrBufferOrUrl)` | Upload and set a profile picture |
101
+ | `syncClientData({ pushNotifications })` | Sync app version / push setting |
102
+ | `setNotificationToken({ fcmToken })` | Register a push token |
103
+
104
+ ### Moments — `client.moments`
105
+
106
+ ```js
107
+ const { NoteType } = require("@dohaidang/locket_mod.js");
108
+
109
+ // Photo with a preset caption pill
110
+ await client.moments.post({ image: "photo.jpg", noteType: NoteType.GOOD_MORNING });
111
+
112
+ // Custom caption, emoji and gradient
113
+ await client.moments.post({
114
+ image: "https://example.com/pic.jpg", // path, Buffer or URL
115
+ caption: "Coding time",
116
+ icon: "⚡",
117
+ colors: ["#FF416C", "#8A2387"],
118
+ });
119
+
120
+ // Video (needs ffmpeg) — thumbnail is extracted, files ≥ 6 MB are compressed
121
+ await client.moments.post({
122
+ video: "clip.mp4",
123
+ progressCallback: (pct) => console.log(`encoding ${pct}%`),
124
+ });
125
+
126
+ // Only to specific friends, or only to yourself
127
+ await client.moments.post({ image: "photo.jpg", recipients: ["FRIEND_UID"] });
128
+ await client.moments.post({ image: "photo.jpg", isPrivate: true });
129
+ ```
130
+
131
+ **`post()` options**
132
+
133
+ | Option | Default | Description |
134
+ |---|---|---|
135
+ | `image` | — | File path, `Buffer`, or URL |
136
+ | `video` | — | File path, `Buffer`, or URL |
137
+ | `caption` | `""` | Caption text |
138
+ | `noteType` | `NoteType.STANDARD` | One of 150+ caption presets (see `caption_presets.json`) |
139
+ | `icon` | — | Emoji shown in the caption pill |
140
+ | `colors` | — | Gradient colors, e.g. `["#FF416C", "#8A2387"]` |
141
+ | `textColor` | `#FFFFFFE6` | Caption text color |
142
+ | `recipients` | `null` | Array of friend UIDs; `null` sends to everyone |
143
+ | `isPrivate` | `false` | `true` sends to yourself only |
144
+ | `autoCompress` | `true` | Compress videos over 6 MB instead of throwing |
145
+ | `priority` | `"balanced"` | Video bitrate split: `"balanced"`, `"video"`, or `"audio"` |
146
+ | `progressCallback` | — | `(percent, message) => void` while encoding video |
147
+
148
+ **Other methods**
149
+
150
+ | Method | Description |
151
+ |---|---|
152
+ | `getMoments({ limit, pageToken, filteredByUserId })` | Paginated history → `{ moments, nextPageToken }` |
153
+ | `getLatest()` | Latest feed from friends |
154
+ | `getSharedMomentsByUsername(username, limit?)` | A friend's recent moments |
155
+ | `getSharedMomentsByUser(uid, limit?)` | Same, by UID |
156
+ | `getAllMyMoments({ limit, startDate, endDate })` | Your posted moments with views and reactions |
157
+ | `getViews(momentUid)` | View count, viewers and reactions |
158
+ | `react(momentUid, emoji)` | React to a moment |
159
+ | `comment(momentUid, receiverUid, text)` | Reply to a moment in chat |
160
+ | `markAsViewed(momentUid)` | Mark as seen |
161
+ | `delete(momentUid)` | Delete your moment |
162
+ | `uploadImage(input)` / `uploadVideo(input)` | Upload only, returns a Storage URL |
163
+
164
+ Paging through everything:
165
+
166
+ ```js
167
+ let pageToken = null;
168
+ do {
169
+ const page = await client.moments.getMoments({ limit: 50, pageToken });
170
+ page.moments.forEach((m) => console.log(m.moment_uid, m.caption));
171
+ pageToken = page.nextPageToken;
172
+ } while (pageToken);
173
+ ```
174
+
175
+ ### Friends — `client.friends`
176
+
177
+ | Method | Description |
178
+ |---|---|
179
+ | `getAllFriends()` | All friends with full profiles |
180
+ | `getFriendRequests()` | `{ incoming, outgoing }` |
181
+ | `getGroupsAndFriends()` | Groups state |
182
+ | `sendRequestByUsername(username)` / `sendRequest(uid)` | Send a friend request |
183
+ | `acceptRequest(uid)` | Accept a request |
184
+ | `remove(uidOrUsername)` | Remove a friend |
185
+ | `block(uidOrUsername)` / `unblock(uidOrUsername)` | Block / unblock |
186
+ | `suggestFriends(contacts?)` | Friend suggestions |
187
+
188
+ ### Chat — `client.chat`
189
+
190
+ ```js
191
+ await client.chat.sendMessage({ receiverUid: "FRIEND_UID", text: "Hey ❤️" });
192
+ await client.chat.sendMoment("FRIEND_UID", "MOMENT_UID", "Look at this");
193
+
194
+ const conversations = await client.chat.getConversations();
195
+ const messages = await client.chat.getMessages({ otherUserId: "FRIEND_UID" });
196
+
197
+ await client.chat.sendReaction(conversationId, messageId, "🔥");
198
+ await client.chat.removeReaction(conversationId, messageId);
199
+ await client.chat.deleteMessage(conversationId, messageId); // your own messages only
200
+ await client.chat.markAsRead({ conversationUid: conversationId, sendReadReceipt: false }); // "ghost" read
201
+
202
+ // Live messages over WebSocket, reconnects automatically
203
+ const live = await client.chat.listenRealtime("FRIEND_UID", (msg) => console.log(msg));
204
+ // later: live.close();
205
+ ```
206
+
207
+ `ReactionEmoji.OFFICIAL_PALETTE` lists the reactions the app supports.
208
+
209
+ ### Device profile
210
+
211
+ The client pretends to be the Locket iOS app on a random recent iPhone and saves that identity in the session file. To pick one yourself:
212
+
213
+ ```js
214
+ const { LocketClient, DeviceProfile } = require("@dohaidang/locket_mod.js");
215
+
216
+ const device = new DeviceProfile({
217
+ modelName: "iPhone 15 Pro",
218
+ hardwareModel: "iPhone16,1",
219
+ iosVersion: "18.1.0",
220
+ appVersion: "2.68.0",
221
+ buildNumber: "2523",
222
+ });
223
+ const client = new LocketClient({ sessionPath: "my.session.json", device });
224
+ ```
225
+
226
+ ### Errors
227
+
228
+ All errors extend `LocketError`:
229
+
230
+ | Error | When |
231
+ |---|---|
232
+ | `AuthenticationError` | Login or token refresh failed, or not logged in |
233
+ | `LocketAPIError` | The API returned an error (`err.statusCode`, `err.responseData`) |
234
+ | `StorageUploadError` | Image/video upload or video compression failed |
235
+
236
+ ```js
237
+ const { AuthenticationError, LocketAPIError } = require("@dohaidang/locket_mod.js");
238
+
239
+ try {
240
+ await client.login(email, password);
241
+ } catch (err) {
242
+ if (err instanceof AuthenticationError) console.error("Wrong email or password");
243
+ else if (err instanceof LocketAPIError) console.error(err.statusCode, err.message);
244
+ else throw err;
245
+ }
246
+ ```
247
+
248
+ ## How it works
249
+
250
+ Locket's backend runs on Firebase. This library sends the same requests the iOS app sends:
251
+
252
+ ```
253
+ LocketClient
254
+ ├─ Firebase Auth identitytoolkit / securetoken.googleapis.com login + token refresh
255
+ ├─ Cloud Functions api.locketcamera.com/<function> actions (post, chat, friends…)
256
+ ├─ Firestore REST firestore.googleapis.com reads (friends, messages, history)
257
+ ├─ Firebase Storage firebasestorage.googleapis.com image / video uploads
258
+ └─ WebSocket wss://api.locketcamera.com/wss_v2/chat live chat
259
+ ```
260
+
261
+ Every request carries the iOS bundle id, an app-like User-Agent and analytics payload from `DeviceProfile`, plus the user's Firebase `idToken`.
262
+
263
+ ## Running on a server or serverless
264
+
265
+ On platforms where the disk is read-only or wiped between runs (Firebase Cloud Functions, Vercel, Lambda…):
266
+
267
+ - Point `sessionPath` at a writable path such as `/tmp/locket.session.json`.
268
+ - Store the session file's contents somewhere persistent (Firestore, KV, a secret) and restore it before creating the client, so you don't log in on every cold start.
269
+ - Keep the email and password in a secret manager, not in code.
270
+ - Protect any HTTP endpoint you expose; whoever can call it controls the account.
271
+ - `listenRealtime()` needs a long-running process (a VPS, Cloud Run with a minimum instance), not a short-lived function.
272
+
273
+ ## Development
274
+
275
+ ```bash
276
+ git clone https://github.com/dohaidang/locket_mod.js.git
277
+ cd locket_mod.js
278
+ npm install
279
+ npm test
280
+ ```
281
+
282
+ The login test is skipped unless `LOCKET_EMAIL` and `LOCKET_PASSWORD` are set.
283
+
284
+ ## License
285
+
286
+ [PolyForm Noncommercial License 1.0.0](LICENSE): free to use, modify and share for **noncommercial** purposes only.
287
+
288
+ Required Notice: Copyright Hmk8386 (https://github.com/hmk8386)