@atproto/bsky 0.0.174 → 0.0.176

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.
Files changed (55) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/api/app/bsky/unspecced/initAgeAssurance.d.ts.map +1 -1
  3. package/dist/api/app/bsky/unspecced/initAgeAssurance.js +0 -6
  4. package/dist/api/app/bsky/unspecced/initAgeAssurance.js.map +1 -1
  5. package/dist/api/index.d.ts.map +1 -1
  6. package/dist/api/index.js +0 -2
  7. package/dist/api/index.js.map +1 -1
  8. package/dist/feature-gates.d.ts +1 -2
  9. package/dist/feature-gates.d.ts.map +1 -1
  10. package/dist/feature-gates.js +0 -1
  11. package/dist/feature-gates.js.map +1 -1
  12. package/dist/lexicon/index.d.ts +4 -4
  13. package/dist/lexicon/index.d.ts.map +1 -1
  14. package/dist/lexicon/index.js +8 -8
  15. package/dist/lexicon/index.js.map +1 -1
  16. package/dist/lexicon/lexicons.d.ts +254 -254
  17. package/dist/lexicon/lexicons.js +134 -134
  18. package/dist/lexicon/lexicons.js.map +1 -1
  19. package/dist/lexicon/types/{app/bsky/unspecced → com/atproto/temp}/checkHandleAvailability.d.ts +6 -6
  20. package/dist/lexicon/types/com/atproto/temp/checkHandleAvailability.d.ts.map +1 -0
  21. package/dist/lexicon/types/{app/bsky/unspecced → com/atproto/temp}/checkHandleAvailability.js +1 -1
  22. package/dist/lexicon/types/com/atproto/temp/checkHandleAvailability.js.map +1 -0
  23. package/dist/views/index.d.ts.map +1 -1
  24. package/dist/views/index.js +1 -0
  25. package/dist/views/index.js.map +1 -1
  26. package/package.json +9 -9
  27. package/src/api/app/bsky/unspecced/initAgeAssurance.ts +0 -8
  28. package/src/api/index.ts +0 -2
  29. package/src/feature-gates.ts +0 -1
  30. package/src/lexicon/index.ts +24 -24
  31. package/src/lexicon/lexicons.ts +143 -143
  32. package/src/lexicon/types/{app/bsky/unspecced → com/atproto/temp}/checkHandleAvailability.ts +4 -4
  33. package/src/views/index.ts +1 -0
  34. package/tests/__snapshots__/feed-generation.test.ts.snap +115 -12
  35. package/tests/feed-generation.test.ts +53 -10
  36. package/tests/views/actor-search.test.ts +3 -1
  37. package/tests/views/age-assurance.test.ts +0 -3
  38. package/tests/views/author-feed.test.ts +3 -1
  39. package/tests/views/follows.test.ts +6 -2
  40. package/tests/views/likes.test.ts +3 -1
  41. package/tests/views/list-feed.test.ts +3 -1
  42. package/tests/views/mutes.test.ts +3 -1
  43. package/tests/views/notifications.test.ts +14 -7
  44. package/tests/views/reposts.test.ts +3 -1
  45. package/tests/views/timeline.test.ts +3 -1
  46. package/tsconfig.build.tsbuildinfo +1 -1
  47. package/tsconfig.tests.tsbuildinfo +1 -1
  48. package/dist/api/app/bsky/unspecced/checkHandleAvailability.d.ts +0 -4
  49. package/dist/api/app/bsky/unspecced/checkHandleAvailability.d.ts.map +0 -1
  50. package/dist/api/app/bsky/unspecced/checkHandleAvailability.js +0 -238
  51. package/dist/api/app/bsky/unspecced/checkHandleAvailability.js.map +0 -1
  52. package/dist/lexicon/types/app/bsky/unspecced/checkHandleAvailability.d.ts.map +0 -1
  53. package/dist/lexicon/types/app/bsky/unspecced/checkHandleAvailability.js.map +0 -1
  54. package/src/api/app/bsky/unspecced/checkHandleAvailability.ts +0 -291
  55. package/tests/views/handle-availability.test.ts +0 -294
@@ -1,294 +0,0 @@
1
- import assert from 'node:assert'
2
- import {
3
- $Typed,
4
- AppBskyUnspeccedCheckHandleAvailability,
5
- AtpAgent,
6
- } from '@atproto/api'
7
- import { InvalidEmailError } from '@atproto/api/dist/client/types/app/bsky/unspecced/checkHandleAvailability'
8
- import { SeedClient, TestNetwork, basicSeed } from '@atproto/dev-env'
9
- import {
10
- OutputSchema,
11
- ResultAvailable,
12
- ResultUnavailable,
13
- } from '../../src/lexicon/types/app/bsky/unspecced/checkHandleAvailability'
14
-
15
- describe('handle availability', () => {
16
- let network: TestNetwork
17
- let agent: AtpAgent
18
- let sc: SeedClient
19
-
20
- let did: string
21
- let handle: string
22
- let handleSubdomain: string
23
- const birthDate = '1980-09-11T18:05:42.556Z'
24
-
25
- beforeAll(async () => {
26
- network = await TestNetwork.create({
27
- dbPostgresSchema: 'bsky_handle_availability',
28
- })
29
- agent = network.bsky.getClient()
30
- sc = network.getSeedClient()
31
- await basicSeed(sc)
32
- await network.processAll()
33
- did = sc.dids.alice
34
- handle = sc.accounts[did].handle
35
- handleSubdomain = handle.split('.')[0]
36
- })
37
-
38
- afterEach(() => {
39
- jest.resetAllMocks()
40
- })
41
-
42
- afterAll(async () => {
43
- await network.close()
44
- })
45
-
46
- describe('validation', () => {
47
- it('throws if email passed is invalid', async () => {
48
- await expect(
49
- agent.app.bsky.unspecced.checkHandleAvailability({
50
- handle,
51
- email: 'not-an-email',
52
- }),
53
- ).rejects.toThrow(InvalidEmailError)
54
- })
55
-
56
- it(`returns unavailable with empty suggestions input is already a slur`, async () => {
57
- const {
58
- data: { result },
59
- } = await agent.app.bsky.unspecced.checkHandleAvailability({
60
- handle: 'shit.test',
61
- })
62
-
63
- assertUnavailable(result)
64
- expect(result.suggestions).toStrictEqual([])
65
- })
66
- })
67
-
68
- describe('available handle', () => {
69
- it('returns available when trying a non-existing handle', async () => {
70
- const handle = 'a5cc0a41-f9a3-4351-b9ec-1462f255fb0a.test'
71
- const { data } = await agent.app.bsky.unspecced.checkHandleAvailability({
72
- handle,
73
- })
74
-
75
- expect(data.handle).toBe(handle)
76
- assertAvailable(data.result)
77
- })
78
- })
79
-
80
- describe('unavailable handle', () => {
81
- it('returns unavailable when trying an existing handle', async () => {
82
- const { data } = await agent.app.bsky.unspecced.checkHandleAvailability({
83
- handle,
84
- })
85
-
86
- expect(data.handle).toBe(handle)
87
- assertUnavailable(data.result)
88
- })
89
-
90
- describe('suggestions', () => {
91
- it(`returns empty list if can't create suggestions`, async () => {
92
- // This handle has the maximum allowed length. Suggestions are additive,
93
- // so no valid suggestion can be made by adding characters.
94
- const longestAllowedHandle = 'abcdefghijklmnopqr.test'
95
- const userMaxLength = {
96
- email: 'usermaxlength@mail.com',
97
- handle: longestAllowedHandle,
98
- password: 'hunter2',
99
- }
100
- await sc.createAccount('userMaxLength', userMaxLength)
101
- await network.processAll()
102
- const { data } = await agent.app.bsky.unspecced.checkHandleAvailability(
103
- {
104
- handle: longestAllowedHandle,
105
- },
106
- )
107
-
108
- expect(data.handle).toBe(longestAllowedHandle)
109
- assertUnavailable(data.result)
110
- expect(data.result.suggestions).toHaveLength(0)
111
- })
112
-
113
- it('suggests appending YOB to tentative handle', async () => {
114
- const {
115
- data: { result },
116
- } = await agent.app.bsky.unspecced.checkHandleAvailability({
117
- handle,
118
- birthDate,
119
- })
120
-
121
- assertUnavailable(result)
122
- const suggestion = result.suggestions.find(
123
- (s) => s.method === 'handle_yob',
124
- )
125
- expect(suggestion?.handle).toBe(`${handleSubdomain}80.test`)
126
- })
127
-
128
- it('suggests appending YOB to tentative handle, with hyphen if label ends with digits', async () => {
129
- const user1 = {
130
- email: 'user1@mail.com',
131
- handle: 'user1.test',
132
- password: 'hunter2',
133
- }
134
- await sc.createAccount('user1', user1)
135
- await network.processAll()
136
-
137
- const {
138
- data: { result },
139
- } = await agent.app.bsky.unspecced.checkHandleAvailability({
140
- handle: user1.handle,
141
- birthDate,
142
- })
143
-
144
- assertUnavailable(result)
145
- const suggestion = result.suggestions.find(
146
- (s) => s.method === 'handle_yob',
147
- )
148
- expect(suggestion?.handle).toBe('user1-80.test')
149
- })
150
-
151
- it('suggests using email', async () => {
152
- const {
153
- data: { result },
154
- } = await agent.app.bsky.unspecced.checkHandleAvailability({
155
- handle,
156
- email: 'email@mail.com',
157
- })
158
-
159
- assertUnavailable(result)
160
- const suggestion = result.suggestions.find((s) => s.method === 'email')
161
- expect(suggestion?.handle).toBe('email.test')
162
- })
163
-
164
- it('suggests user email with and without YOB', async () => {
165
- const {
166
- data: { result },
167
- } = await agent.app.bsky.unspecced.checkHandleAvailability({
168
- handle,
169
- email: 'email@mail.com',
170
- birthDate,
171
- })
172
-
173
- assertUnavailable(result)
174
-
175
- const suggestion0 = result.suggestions.find((s) => s.method === 'email')
176
- expect(suggestion0?.handle).toBe('email.test')
177
-
178
- const suggestion1 = result.suggestions.find(
179
- (s) => s.method === 'email_yob',
180
- )
181
- expect(suggestion1?.handle).toBe('email80.test')
182
- })
183
-
184
- it('does not suggest email if it is unavailable as handle', async () => {
185
- const user2 = {
186
- email: 'user2@mail.com',
187
- handle: 'some-name.test', // NOTE: this handle is taken.
188
- password: 'hunter2',
189
- }
190
- await sc.createAccount('user2', user2)
191
- await network.processAll()
192
-
193
- const {
194
- data: { result },
195
- } = await agent.app.bsky.unspecced.checkHandleAvailability({
196
- handle,
197
- email: 'some.name@mail.com', // NOTE: would suggest 'some-name.test' from the email, but it is taken.
198
- birthDate,
199
- })
200
-
201
- assertUnavailable(result)
202
-
203
- const suggestion0 = result.suggestions.find((s) => s.method === 'email')
204
- expect(suggestion0).toBeUndefined()
205
-
206
- const suggestion1 = result.suggestions.find(
207
- (s) => s.method === 'email_yob',
208
- )
209
- expect(suggestion1?.handle).toBe('some-name80.test')
210
- })
211
-
212
- it('suggests random hyphens in the middle of handle', async () => {
213
- const {
214
- data: { result },
215
- } = await agent.app.bsky.unspecced.checkHandleAvailability({
216
- handle,
217
- })
218
-
219
- assertUnavailable(result)
220
- const suggestion = result.suggestions.find((s) => s.method === 'hyphen')
221
- expect(suggestion?.handle).not.toBe(handle)
222
- expect(suggestion?.handle.replace('-', '')).toBe(handle)
223
- })
224
-
225
- it('suggests random digits at the end of handle', async () => {
226
- const {
227
- data: { result },
228
- } = await agent.app.bsky.unspecced.checkHandleAvailability({
229
- handle,
230
- })
231
-
232
- assertUnavailable(result)
233
- const suggestion = result.suggestions.find(
234
- (s) => s.method === 'random_digits',
235
- )
236
- expect(suggestion?.handle).not.toBe(handle)
237
- expect(suggestion?.handle.replace(/\d+/, '')).toBe(handle)
238
- })
239
-
240
- it('dedupes suggestions', async () => {
241
- jest.spyOn(global.Math, 'random').mockReturnValue(0)
242
-
243
- const {
244
- data: { result },
245
- } = await agent.app.bsky.unspecced.checkHandleAvailability({
246
- handle,
247
- })
248
-
249
- assertUnavailable(result)
250
- expect(result.suggestions).toStrictEqual([
251
- { handle: 'a-lice.test', method: 'hyphen' },
252
- { handle: 'al-ice.test', method: 'hyphen' },
253
- { handle: 'alice0.test', method: 'random_digits' },
254
- ])
255
- })
256
-
257
- it(`avoids slurs`, async () => {
258
- jest.spyOn(global.Math, 'random').mockReturnValue(0)
259
-
260
- const bass = {
261
- email: 'bass@mail.com',
262
- handle: 'bass.test',
263
- password: 'hunter2',
264
- }
265
- await sc.createAccount('bass', bass)
266
- await network.processAll()
267
-
268
- const {
269
- data: { result },
270
- } = await agent.app.bsky.unspecced.checkHandleAvailability({
271
- handle: bass.handle,
272
- })
273
-
274
- assertUnavailable(result)
275
- const suggestion = result.suggestions.find(
276
- (s) => s.handle === 'b-ass.test',
277
- )
278
- expect(suggestion).toBeUndefined()
279
- })
280
- })
281
- })
282
- })
283
-
284
- function assertAvailable(
285
- r: OutputSchema['result'],
286
- ): asserts r is $Typed<ResultAvailable> {
287
- assert(AppBskyUnspeccedCheckHandleAvailability.isResultAvailable(r))
288
- }
289
-
290
- function assertUnavailable(
291
- r: OutputSchema['result'],
292
- ): asserts r is $Typed<ResultUnavailable> {
293
- assert(AppBskyUnspeccedCheckHandleAvailability.isResultUnavailable(r))
294
- }