mobbin 0.1.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/mobbin-sdk.js ADDED
@@ -0,0 +1,203 @@
1
+ const DEFAULT_BASE_URL = 'https://mobbin.com';
2
+ const DEFAULT_USER_AGENT =
3
+ 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120 Safari/537.36';
4
+
5
+ export class MobbinClient {
6
+ constructor({
7
+ baseUrl = DEFAULT_BASE_URL,
8
+ cookie,
9
+ headers = {},
10
+ userAgent = DEFAULT_USER_AGENT,
11
+ timeoutMs = 20000,
12
+ } = {}) {
13
+ this.baseUrl = baseUrl.replace(/\/$/, '');
14
+ this.cookie = cookie;
15
+ this.headers = headers;
16
+ this.userAgent = userAgent;
17
+ this.timeoutMs = timeoutMs;
18
+ }
19
+
20
+ setCookie(cookie) {
21
+ this.cookie = cookie;
22
+ }
23
+
24
+ async request(path, { method = 'GET', json, headers } = {}) {
25
+ const url = path.startsWith('http') ? path : `${this.baseUrl}${path}`;
26
+ const controller = new AbortController();
27
+ const timeout = setTimeout(() => controller.abort(), this.timeoutMs);
28
+
29
+ const finalHeaders = {
30
+ Accept: 'application/json, text/plain, */*',
31
+ 'User-Agent': this.userAgent,
32
+ ...this.headers,
33
+ ...headers,
34
+ };
35
+
36
+ if (this.cookie) {
37
+ finalHeaders.Cookie = this.cookie;
38
+ }
39
+
40
+ let body;
41
+ if (json !== undefined) {
42
+ finalHeaders['Content-Type'] = 'application/json';
43
+ body = JSON.stringify(json);
44
+ }
45
+
46
+ const res = await fetch(url, {
47
+ method,
48
+ headers: finalHeaders,
49
+ body,
50
+ signal: controller.signal,
51
+ });
52
+
53
+ clearTimeout(timeout);
54
+
55
+ const text = await res.text();
56
+ let data = null;
57
+ if (text) {
58
+ try {
59
+ data = JSON.parse(text);
60
+ } catch {
61
+ data = text;
62
+ }
63
+ }
64
+
65
+ if (!res.ok) {
66
+ const error = new Error(`HTTP ${res.status} ${res.statusText}`);
67
+ error.status = res.status;
68
+ error.data = data;
69
+ throw error;
70
+ }
71
+
72
+ return data;
73
+ }
74
+
75
+ fetchTrendingApps({ platform = 'ios' } = {}) {
76
+ return this.request('/api/search-bar/fetch-trending-apps', {
77
+ method: 'POST',
78
+ json: { platform },
79
+ });
80
+ }
81
+
82
+ fetchTrendingFilterTags({ platform = 'ios', experience = 'apps' } = {}) {
83
+ return this.request('/api/search-bar/fetch-trending-filter-tags', {
84
+ method: 'POST',
85
+ json: { platform, experience },
86
+ });
87
+ }
88
+
89
+ fetchTrendingKeywords({ platform = 'ios' } = {}) {
90
+ return this.request('/api/search-bar/fetch-trending-text-in-screenshot-keywords', {
91
+ method: 'POST',
92
+ json: { platform },
93
+ });
94
+ }
95
+
96
+ fetchTrendingSites() {
97
+ return this.request('/api/search-bar/fetch-trending-sites', {
98
+ method: 'POST',
99
+ json: {},
100
+ });
101
+ }
102
+
103
+ fetchSearchableSites() {
104
+ return this.request('/api/search-bar/fetch-searchable-sites', {
105
+ method: 'POST',
106
+ json: {},
107
+ });
108
+ }
109
+
110
+ fetchSearchableApps({ platform = 'ios' } = {}) {
111
+ return this.request(`/api/searchable-apps/${platform}`);
112
+ }
113
+
114
+ fetchDictionaryDefinitions() {
115
+ return this.request('/api/filter-tags/fetch-dictionary-definitions', {
116
+ method: 'POST',
117
+ json: {},
118
+ });
119
+ }
120
+
121
+ search({ query, experience = 'apps', platform = 'ios' } = {}) {
122
+ return this.request('/api/search-bar/search', {
123
+ method: 'POST',
124
+ json: { query, experience, platform },
125
+ });
126
+ }
127
+
128
+ fetchPopularApps({ platform = 'ios', limitPerCategory = 10 } = {}) {
129
+ return this.request('/api/popular-apps/fetch-popular-apps-with-preview-screens', {
130
+ method: 'POST',
131
+ json: { platform, limitPerCategory },
132
+ });
133
+ }
134
+
135
+ fetchAppVersionsScreens({ appId } = {}) {
136
+ return this.request('/api/app/fetch-app-versions-screens', {
137
+ method: 'POST',
138
+ json: { appId },
139
+ });
140
+ }
141
+
142
+ fetchScreenInfo({ screenId } = {}) {
143
+ return this.request('/api/screen/fetch-screen-info', {
144
+ method: 'POST',
145
+ json: { screenId },
146
+ });
147
+ }
148
+
149
+ fetchRecentSearches() {
150
+ return this.request('/api/recent-searches');
151
+ }
152
+
153
+ fetchContentApps({ searchRequestId = null, filterOptions, paginationOptions } = {}) {
154
+ return this.request('/api/content/fetch-apps', {
155
+ method: 'POST',
156
+ json: { searchRequestId, filterOptions, paginationOptions },
157
+ });
158
+ }
159
+
160
+ createVisualSearchImage(payload) {
161
+ return this.request('/api/visual-search-image/create', {
162
+ method: 'POST',
163
+ json: payload,
164
+ });
165
+ }
166
+ }
167
+
168
+ export function buildContentAppsPayload({
169
+ platform = 'ios',
170
+ tab = 'latest',
171
+ pageSize = 24,
172
+ } = {}) {
173
+ const filterOptions = {
174
+ filterOperator: 'or',
175
+ platform,
176
+ appCategories: null,
177
+ };
178
+
179
+ if (tab === 'latest') {
180
+ filterOptions.shouldHideNonIdealApps = true;
181
+ }
182
+
183
+ let sortBy = 'publishedAt';
184
+ if (tab === 'popular') {
185
+ sortBy = 'popularity';
186
+ } else if (tab === 'top') {
187
+ sortBy = 'rating';
188
+ }
189
+
190
+ return {
191
+ searchRequestId: null,
192
+ filterOptions,
193
+ paginationOptions: {
194
+ pageSize,
195
+ sortBy,
196
+ },
197
+ };
198
+ }
199
+
200
+ export const DEFAULTS = {
201
+ baseUrl: DEFAULT_BASE_URL,
202
+ userAgent: DEFAULT_USER_AGENT,
203
+ };
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "mobbin",
3
+ "version": "0.1.0",
4
+ "description": "CLI + lightweight SDK for Mobbin's (mostly undocumented) web JSON endpoints and asset downloads.",
5
+ "author": "Tomas Roda <dev@tomasroda.com>",
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "bin": {
9
+ "mobbin": "mobbin-cli.js"
10
+ },
11
+ "files": [
12
+ "mobbin-cli.js",
13
+ "mobbin-sdk.js",
14
+ "README.md",
15
+ "LICENSE"
16
+ ],
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/thehumanworks/mobbin-cli.git"
20
+ },
21
+ "bugs": {
22
+ "url": "https://github.com/thehumanworks/mobbin-cli/issues"
23
+ },
24
+ "homepage": "https://github.com/thehumanworks/mobbin-cli#readme",
25
+ "engines": {
26
+ "node": ">=18",
27
+ "bun": ">=1.0.0"
28
+ }
29
+ }