@codybrom/denim 1.3.6 → 2.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.
Files changed (46) hide show
  1. package/.github/workflows/publish.yml +17 -7
  2. package/.vscode/settings.json +34 -9
  3. package/CHANGELOG.md +137 -0
  4. package/deno.json +22 -8
  5. package/deno.lock +17 -59
  6. package/examples/edge-function.ts +171 -177
  7. package/mod.ts +138 -635
  8. package/mod_test.ts +1287 -431
  9. package/package.json +22 -22
  10. package/readme.md +155 -191
  11. package/src/api/createCarouselItem.ts +86 -0
  12. package/src/api/createThreadsContainer.ts +122 -0
  13. package/src/api/debugToken.ts +35 -0
  14. package/src/api/deleteThread.ts +36 -0
  15. package/src/api/exchangeCodeForToken.ts +50 -0
  16. package/src/api/exchangeToken.ts +36 -0
  17. package/src/api/getAppAccessToken.ts +35 -0
  18. package/src/api/getConversation.ts +51 -0
  19. package/src/api/getGhostPosts.ts +50 -0
  20. package/src/api/getLocation.ts +38 -0
  21. package/src/api/getMediaInsights.ts +39 -0
  22. package/src/api/getMentions.ts +57 -0
  23. package/src/api/getOEmbed.ts +41 -0
  24. package/src/api/getProfile.ts +46 -0
  25. package/src/api/getProfilePosts.ts +53 -0
  26. package/src/api/getPublishingLimit.ts +59 -0
  27. package/src/api/getReplies.ts +51 -0
  28. package/src/api/getSingleThread.ts +37 -0
  29. package/src/api/getThreadsList.ts +49 -0
  30. package/src/api/getUserInsights.ts +54 -0
  31. package/src/api/getUserReplies.ts +54 -0
  32. package/src/api/lookupProfile.ts +53 -0
  33. package/src/api/manageReply.ts +41 -0
  34. package/src/api/publishThreadsContainer.ts +107 -0
  35. package/src/api/refreshToken.ts +33 -0
  36. package/src/api/repost.ts +38 -0
  37. package/src/api/searchKeyword.ts +86 -0
  38. package/src/api/searchLocations.ts +46 -0
  39. package/src/constants.ts +80 -0
  40. package/src/types.ts +925 -0
  41. package/src/utils/checkContainerStatus.ts +39 -0
  42. package/src/utils/getAPI.ts +13 -0
  43. package/src/utils/mock_threads_api.ts +582 -0
  44. package/src/utils/validateRequest.ts +166 -0
  45. package/mock_threads_api.ts +0 -174
  46. package/types.ts +0 -235
@@ -1,9 +1,16 @@
1
1
  name: Publish
2
2
 
3
3
  on:
4
+ workflow_dispatch:
4
5
  push:
5
6
  branches:
6
7
  - main
8
+ paths:
9
+ - "src/**"
10
+ - "mod.ts"
11
+ - "deno.json"
12
+ - "deno.lock"
13
+ - "package.json"
7
14
 
8
15
  jobs:
9
16
  publish:
@@ -14,18 +21,21 @@ jobs:
14
21
  id-token: write
15
22
 
16
23
  steps:
17
- - uses: actions/checkout@v4
24
+ - uses: actions/checkout@v6
25
+
26
+ - uses: denoland/setup-deno@v2
27
+
28
+ - name: Run checks
29
+ run: deno task check && deno task lint && deno task test
18
30
 
19
31
  - name: Publish package to JSR
20
- run: npx jsr publish
21
-
32
+ run: deno publish
33
+
22
34
  - name: Set up Node.js
23
35
  uses: actions/setup-node@v4
24
36
  with:
25
- node-version: '20.x'
26
- registry-url: 'https://registry.npmjs.org'
37
+ node-version: "24.x"
38
+ registry-url: "https://registry.npmjs.org"
27
39
 
28
40
  - name: Publish package to NPM
29
41
  run: npm publish --provenance --access public
30
- env:
31
- NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
@@ -1,11 +1,36 @@
1
1
  {
2
- "gpt-context-generator.detectedFileExtensions": [
3
- "js",
4
- "jsx",
5
- "ts",
6
- "tsx",
7
- "mdx",
8
- "json",
9
- "md"
10
- ]
2
+ "deno.enable": true,
3
+ "deno.lint": true,
4
+ "editor.defaultFormatter": "denoland.vscode-deno",
5
+ "editor.formatOnSave": true,
6
+ "editor.codeActionsOnSave": {
7
+ "source.organizeImports": "explicit"
8
+ },
9
+ "explorer.fileNesting.enabled": true,
10
+ "explorer.fileNesting.patterns": {
11
+ "*.ts": "${capture}.test.ts, ${capture}.d.ts",
12
+ "deno.json": "deno.lock"
13
+ },
14
+ "files.exclude": {
15
+ "**/.DS_Store": true
16
+ },
17
+ "[typescript]": {
18
+ "editor.defaultFormatter": "denoland.vscode-deno"
19
+ },
20
+ "[typescriptreact]": {
21
+ "editor.defaultFormatter": "denoland.vscode-deno"
22
+ },
23
+ "[json]": {
24
+ "editor.defaultFormatter": "denoland.vscode-deno"
25
+ },
26
+ "[jsonc]": {
27
+ "editor.defaultFormatter": "denoland.vscode-deno"
28
+ },
29
+ "[markdown]": {
30
+ "editor.defaultFormatter": "denoland.vscode-deno"
31
+ },
32
+ "markdownlint.config": {
33
+ "MD010": false,
34
+ "MD024": { "siblings_only": true }
35
+ }
11
36
  }
package/CHANGELOG.md ADDED
@@ -0,0 +1,137 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to
7
+ [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
8
+
9
+ ## [2.0.1] - 2026-04-17
10
+
11
+ ### Fixed
12
+
13
+ - `searchLocations()` now sends the query string as the `q` URL parameter.
14
+ Meta's `/location_search` endpoint requires `q`; the prior `query` name was
15
+ silently ignored, causing proximity-only results regardless of the search
16
+ string.
17
+
18
+ ## [2.0.0] - 2026-02-08
19
+
20
+ ### Changed
21
+
22
+ - Response types now use snake_case to match the actual API. In v1, fields like
23
+ `hasReplies` on `ThreadsPost` were camelCase but never populated because the
24
+ API returns `has_replies`. Input types still use camelCase.
25
+ - `PublishingLimit` fields are optional (the API only returns requested fields)
26
+ - `MockThreadsAPI` class renamed to `MockThreadsAPIImpl`
27
+ - `createThreadsContainer` now always returns a `string` (container ID). The
28
+ previous `string | { id, permalink }` return type is removed; use
29
+ `publishThreadsContainer` with `getPermalink: true` to get the permalink.
30
+ - Updated to Deno 2 conventions and `@std/assert` ^1.0.18
31
+
32
+ ### Added
33
+
34
+ - 22 new functions covering profiles, replies, insights, search, locations,
35
+ OAuth, token management, oEmbed, repost, and delete (see readme for the full
36
+ list)
37
+ - 11 new post options: polls, GIFs, ghost posts, spoilers, text attachments,
38
+ replies, quotes, topic tags, location tags
39
+ - Optional `fields` parameter on retrieval, search, and profile lookup functions
40
+ - `reverse` parameter on `getReplies()` and `getConversation()`
41
+ - `ResponseMediaType` for response-only media type values (`TEXT_POST`,
42
+ `CAROUSEL_ALBUM`, `REPOST_FACADE`, `AUDIO`)
43
+ - Validation for new post parameters
44
+
45
+ ### Removed
46
+
47
+ - `serveRequests()` edge function handler and `handleRequest` server
48
+ - `THREADS_API_BASE_URL` constant from public exports
49
+
50
+ ## [1.3.6] - 2024-09-23
51
+
52
+ ### Fixed
53
+
54
+ - Permalink retrieval in `publishThreadsContainer`
55
+
56
+ ## [1.3.5] - 2024-09-23
57
+
58
+ ### Added
59
+
60
+ - `getThreadsList` function for retrieving a user's threads with pagination
61
+ - `getSingleThread` function for retrieving a single thread by ID
62
+ - `getPermalink` option on `publishThreadsContainer` to return permalink with
63
+ the published post ID
64
+ - `MockThreadsAPI` interface and mock implementation for testing
65
+ - `ThreadsPost`, `ThreadsListResponse`, and `PublishingLimit` types
66
+
67
+ ### Changed
68
+
69
+ - Extracted types into dedicated `types.ts` module
70
+ - Refactored all API functions to support mock API injection via `getAPI()`
71
+ - Updated edge function example
72
+
73
+ ## [1.3.1] - 2024-09-13
74
+
75
+ ### Fixed
76
+
77
+ - Media item container creation for video posts
78
+
79
+ ## [1.3.0] - 2024-09-13
80
+
81
+ ### Added
82
+
83
+ - `checkContainerStatus` helper to poll container status after publishing
84
+ - Status polling loop in `publishThreadsContainer` — waits for `PUBLISHED` or
85
+ `FINISHED` status before returning
86
+
87
+ ### Changed
88
+
89
+ - Refactored `createThreadsContainer` to use a switch statement for
90
+ media-type-specific parameter handling
91
+ - Videos are now posted directly instead of being wrapped in a carousel
92
+
93
+ ## [1.2.0] - 2024-09-13
94
+
95
+ ### Removed
96
+
97
+ - `checkHealth` function (unused Threads API endpoint)
98
+ - `Threads API.md` reference file
99
+
100
+ ## [1.1.0] - 2024-09-13
101
+
102
+ ### Added
103
+
104
+ - `CAROUSEL` media type support
105
+ - `createCarouselItem` function for building carousel posts
106
+ - `getPublishingLimit` function for checking rate limit usage
107
+ - `checkHealth` function for Threads API health checks
108
+ - Post options: `altText`, `linkAttachment`, `allowlistedCountryCodes`,
109
+ `replyControl`, `children`
110
+ - Input validation for media type and property combinations
111
+ - `package.json` for npm publishing
112
+ - Comprehensive test suite
113
+
114
+ ## [1.0.2] - 2024-08-01
115
+
116
+ ### Changed
117
+
118
+ - Updated readme with JSR badges and `deno add` install instructions
119
+ - Switched import examples from raw GitHub URL to JSR registry
120
+
121
+ ## [1.0.1] - 2024-08-01
122
+
123
+ ### Added
124
+
125
+ - JSDoc comments on all public exports
126
+ - MIT license
127
+
128
+ ## [1.0.0] - 2024-08-01
129
+
130
+ ### Added
131
+
132
+ - `createThreadsContainer` function for creating media containers (TEXT, IMAGE,
133
+ VIDEO)
134
+ - `publishThreadsContainer` function for publishing containers
135
+ - `ThreadsPostRequest` type
136
+ - `serveRequests` edge function handler
137
+ - GitHub Actions workflow for publishing to JSR
package/deno.json CHANGED
@@ -1,9 +1,23 @@
1
1
  {
2
- "name": "@codybrom/denim",
3
- "version": "1.3.6",
4
- "description": "A Deno function for posting to Threads.",
5
- "entry": "./mod.ts",
6
- "exports": {
7
- ".": "./mod.ts"
8
- }
9
- }
2
+ "name": "@codybrom/denim",
3
+ "version": "2.0.1",
4
+ "description": "A Deno/TypeScript library for the Threads API",
5
+ "exports": {
6
+ ".": "./mod.ts"
7
+ },
8
+ "imports": {
9
+ "@codybrom/denim": "./mod.ts",
10
+ "@std/assert": "jsr:@std/assert@^1.0.18"
11
+ },
12
+ "tasks": {
13
+ "test": "deno test",
14
+ "check": "deno check mod.ts",
15
+ "lint": "deno lint",
16
+ "fmt": "deno fmt",
17
+ "fmt:check": "deno fmt --check"
18
+ },
19
+ "fmt": {
20
+ "useTabs": true,
21
+ "singleQuote": false
22
+ }
23
+ }
package/deno.lock CHANGED
@@ -1,65 +1,23 @@
1
1
  {
2
- "version": "3",
3
- "packages": {
4
- "specifiers": {
5
- "jsr:@std/assert@1": "jsr:@std/assert@1.0.1",
6
- "jsr:@std/internal@^1.0.1": "jsr:@std/internal@1.0.1"
2
+ "version": "5",
3
+ "specifiers": {
4
+ "jsr:@std/assert@^1.0.18": "1.0.18",
5
+ "jsr:@std/internal@^1.0.12": "1.0.12"
6
+ },
7
+ "jsr": {
8
+ "@std/assert@1.0.18": {
9
+ "integrity": "270245e9c2c13b446286de475131dc688ca9abcd94fc5db41d43a219b34d1c78",
10
+ "dependencies": [
11
+ "jsr:@std/internal"
12
+ ]
7
13
  },
8
- "jsr": {
9
- "@std/assert@1.0.1": {
10
- "integrity": "13590ef8e5854f59e4ad252fd987e83239a1bf1f16cb9c69c1d123ebb807a75b",
11
- "dependencies": [
12
- "jsr:@std/internal@^1.0.1"
13
- ]
14
- },
15
- "@std/internal@1.0.1": {
16
- "integrity": "6f8c7544d06a11dd256c8d6ba54b11ed870aac6c5aeafff499892662c57673e6"
17
- }
14
+ "@std/internal@1.0.12": {
15
+ "integrity": "972a634fd5bc34b242024402972cd5143eac68d8dffaca5eaa4dba30ce17b027"
18
16
  }
19
17
  },
20
- "redirects": {
21
- "https://deno.land/std/testing/asserts.ts": "https://deno.land/std@0.224.0/testing/asserts.ts"
22
- },
23
- "remote": {
24
- "https://deno.land/std@0.153.0/fmt/colors.ts": "ff7dc9c9f33a72bd48bc24b21bbc1b4545d8494a431f17894dbc5fe92a938fc4",
25
- "https://deno.land/std@0.153.0/testing/_diff.ts": "141f978a283defc367eeee3ff7b58aa8763cf7c8e0c585132eae614468e9d7b8",
26
- "https://deno.land/std@0.153.0/testing/_format.ts": "cd11136e1797791045e639e9f0f4640d5b4166148796cad37e6ef75f7d7f3832",
27
- "https://deno.land/std@0.153.0/testing/_test_suite.ts": "2d07073d5460a4e3ec50c55ae822cd9bd136926d7363091379947fef9c73c3e4",
28
- "https://deno.land/std@0.153.0/testing/asserts.ts": "d6595cfc330b4233546a047a0d7d57940771aa9d97a172ceb91e84ae6200b3af",
29
- "https://deno.land/std@0.153.0/testing/bdd.ts": "35060cefd9cc21b414f4d89453b3551a3d52ec50aeff25db432503c5485b2f72",
30
- "https://deno.land/std@0.224.0/assert/_constants.ts": "a271e8ef5a573f1df8e822a6eb9d09df064ad66a4390f21b3e31f820a38e0975",
31
- "https://deno.land/std@0.224.0/assert/assert.ts": "09d30564c09de846855b7b071e62b5974b001bb72a4b797958fe0660e7849834",
32
- "https://deno.land/std@0.224.0/assert/assert_almost_equals.ts": "9e416114322012c9a21fa68e187637ce2d7df25bcbdbfd957cd639e65d3cf293",
33
- "https://deno.land/std@0.224.0/assert/assert_array_includes.ts": "14c5094471bc8e4a7895fc6aa5a184300d8a1879606574cb1cd715ef36a4a3c7",
34
- "https://deno.land/std@0.224.0/assert/assert_equals.ts": "3bbca947d85b9d374a108687b1a8ba3785a7850436b5a8930d81f34a32cb8c74",
35
- "https://deno.land/std@0.224.0/assert/assert_exists.ts": "43420cf7f956748ae6ed1230646567b3593cb7a36c5a5327269279c870c5ddfd",
36
- "https://deno.land/std@0.224.0/assert/assert_false.ts": "3e9be8e33275db00d952e9acb0cd29481a44fa0a4af6d37239ff58d79e8edeff",
37
- "https://deno.land/std@0.224.0/assert/assert_greater.ts": "5e57b201fd51b64ced36c828e3dfd773412c1a6120c1a5a99066c9b261974e46",
38
- "https://deno.land/std@0.224.0/assert/assert_greater_or_equal.ts": "9870030f997a08361b6f63400273c2fb1856f5db86c0c3852aab2a002e425c5b",
39
- "https://deno.land/std@0.224.0/assert/assert_instance_of.ts": "e22343c1fdcacfaea8f37784ad782683ec1cf599ae9b1b618954e9c22f376f2c",
40
- "https://deno.land/std@0.224.0/assert/assert_is_error.ts": "f856b3bc978a7aa6a601f3fec6603491ab6255118afa6baa84b04426dd3cc491",
41
- "https://deno.land/std@0.224.0/assert/assert_less.ts": "60b61e13a1982865a72726a5fa86c24fad7eb27c3c08b13883fb68882b307f68",
42
- "https://deno.land/std@0.224.0/assert/assert_less_or_equal.ts": "d2c84e17faba4afe085e6c9123a63395accf4f9e00150db899c46e67420e0ec3",
43
- "https://deno.land/std@0.224.0/assert/assert_match.ts": "ace1710dd3b2811c391946954234b5da910c5665aed817943d086d4d4871a8b7",
44
- "https://deno.land/std@0.224.0/assert/assert_not_equals.ts": "78d45dd46133d76ce624b2c6c09392f6110f0df9b73f911d20208a68dee2ef29",
45
- "https://deno.land/std@0.224.0/assert/assert_not_instance_of.ts": "3434a669b4d20cdcc5359779301a0588f941ffdc2ad68803c31eabdb4890cf7a",
46
- "https://deno.land/std@0.224.0/assert/assert_not_match.ts": "df30417240aa2d35b1ea44df7e541991348a063d9ee823430e0b58079a72242a",
47
- "https://deno.land/std@0.224.0/assert/assert_not_strict_equals.ts": "37f73880bd672709373d6dc2c5f148691119bed161f3020fff3548a0496f71b8",
48
- "https://deno.land/std@0.224.0/assert/assert_object_match.ts": "411450fd194fdaabc0089ae68f916b545a49d7b7e6d0026e84a54c9e7eed2693",
49
- "https://deno.land/std@0.224.0/assert/assert_rejects.ts": "4bee1d6d565a5b623146a14668da8f9eb1f026a4f338bbf92b37e43e0aa53c31",
50
- "https://deno.land/std@0.224.0/assert/assert_strict_equals.ts": "b4f45f0fd2e54d9029171876bd0b42dd9ed0efd8f853ab92a3f50127acfa54f5",
51
- "https://deno.land/std@0.224.0/assert/assert_string_includes.ts": "496b9ecad84deab72c8718735373feb6cdaa071eb91a98206f6f3cb4285e71b8",
52
- "https://deno.land/std@0.224.0/assert/assert_throws.ts": "c6508b2879d465898dab2798009299867e67c570d7d34c90a2d235e4553906eb",
53
- "https://deno.land/std@0.224.0/assert/assertion_error.ts": "ba8752bd27ebc51f723702fac2f54d3e94447598f54264a6653d6413738a8917",
54
- "https://deno.land/std@0.224.0/assert/equal.ts": "bddf07bb5fc718e10bb72d5dc2c36c1ce5a8bdd3b647069b6319e07af181ac47",
55
- "https://deno.land/std@0.224.0/assert/fail.ts": "0eba674ffb47dff083f02ced76d5130460bff1a9a68c6514ebe0cdea4abadb68",
56
- "https://deno.land/std@0.224.0/assert/mod.ts": "48b8cb8a619ea0b7958ad7ee9376500fe902284bb36f0e32c598c3dc34cbd6f3",
57
- "https://deno.land/std@0.224.0/assert/unimplemented.ts": "8c55a5793e9147b4f1ef68cd66496b7d5ba7a9e7ca30c6da070c1a58da723d73",
58
- "https://deno.land/std@0.224.0/assert/unreachable.ts": "5ae3dbf63ef988615b93eb08d395dda771c96546565f9e521ed86f6510c29e19",
59
- "https://deno.land/std@0.224.0/fmt/colors.ts": "508563c0659dd7198ba4bbf87e97f654af3c34eb56ba790260f252ad8012e1c5",
60
- "https://deno.land/std@0.224.0/internal/diff.ts": "6234a4b493ebe65dc67a18a0eb97ef683626a1166a1906232ce186ae9f65f4e6",
61
- "https://deno.land/std@0.224.0/internal/format.ts": "0a98ee226fd3d43450245b1844b47003419d34d210fa989900861c79820d21c2",
62
- "https://deno.land/std@0.224.0/internal/mod.ts": "534125398c8e7426183e12dc255bb635d94e06d0f93c60a297723abe69d3b22e",
63
- "https://deno.land/std@0.224.0/testing/asserts.ts": "d0cdbabadc49cc4247a50732ee0df1403fdcd0f95360294ad448ae8c240f3f5c"
18
+ "workspace": {
19
+ "dependencies": [
20
+ "jsr:@std/assert@^1.0.18"
21
+ ]
64
22
  }
65
23
  }