@zerodot/bitly 1.0.0 → 1.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 (3) hide show
  1. package/README.md +77 -11
  2. package/dist/index.cjs +17 -6
  3. package/package.json +2 -1
package/README.md CHANGED
@@ -1,20 +1,86 @@
1
1
  # @zerodot/bitly
2
2
 
3
- Bitly node package for zerodot.
3
+ <img src="https://raw.githubusercontent.com/zerodot-io/nodes/main/packages/bitly/bitly.svg" alt="Bitly logo" width="48" height="48">
4
4
 
5
- ## Credential
5
+ Create, get, and update Bitly short links. List the bitlinks of a group, and read the click counts of a bitlink. Connect with a Bitly access token.
6
6
 
7
- Create a **Bitly access token** credential with an access token from Bitly.
7
+ ## Install
8
8
 
9
- - Access tokens can be created in Bitly under **Settings > Developer settings > API**.
9
+ In zerodot, go to **System > Nodes** and install **Bitly**.
10
10
 
11
- ## Operations
11
+ Manual: install `@zerodot/bitly` where the web app and the worker run, and add it to `ZERODOT_NODE_PACKAGES`.
12
12
 
13
- - **Bitlink**: Create, Get, Update, Get Many (by group), Get Clicks Summary
13
+ ## Nodes
14
14
 
15
- ## Notes
15
+ ### Bitly (`bitly.api`)
16
16
 
17
- - Bitly API base URL: `https://api-ssl.bitly.com/v4`
18
- - Bitlink IDs use the format `domain/hash`, for example `bit.ly/abc123`.
19
- - List Bitlinks by Group requires a group GUID.
20
- - Clicks Summary returns rolled-up click counts for a bitlink.
17
+ - **Bitlink**: create, get, update, get many, get clicks summary
18
+
19
+ **Bitlink ID.** Get, update, and clicks summary need **Bitlink**, in `domain/hash` format, for example `bit.ly/abc123`. The node rejects a value with no `/`. A scheme such as `https://` is removed, so `https://bit.ly/abc123` is sent as `bit.ly/abc123`.
20
+
21
+ **Create.** Needs **Long URL**, the destination URL. These fields are optional:
22
+
23
+ - **Domain**: the short domain. If it is empty, the node does not send it, and Bitly uses its default, `bit.ly`. A custom domain must be attached to your Bitly account.
24
+ - **Group GUID**: the group for the new bitlink. Optional. If it is empty, the node does not send it.
25
+ - **Title**: the title of the bitlink.
26
+ - **Tags**: a list of tags. An empty tag list is not sent.
27
+
28
+ The output is the bitlink that Bitly returns.
29
+
30
+ **Update.** Needs **Bitlink**. It sends only the fields you set:
31
+
32
+ - **Long URL**: a new destination URL.
33
+ - **Title**.
34
+ - **Tags**: when this field is set, the node sends it. An empty list is sent too.
35
+ - **Archived**: true or false.
36
+
37
+ **Get many.** Needs **Group GUID**. These settings change the result:
38
+
39
+ - **Archived Filter**: **Active only** (default), **Archived only**, or **Both**. The node always sends this filter.
40
+ - **Size**: the number of bitlinks, from 1 to 100.
41
+ - **Search After**: the pagination token from a previous answer.
42
+ - **Query**: text to search for in the bitlinks. For example, `docs`.
43
+
44
+ The output is the answer of Bitly as it is. The node does not read the next page for you. Copy the pagination token into **Search After** to read the next page.
45
+
46
+ **Get clicks summary.** Needs **Bitlink**. These settings change the result:
47
+
48
+ - **Unit**: `minute`, `hour`, `day` (default), `week`, or `month`.
49
+ - **Units**: the number of units to read. The default is `-1`, which means all units.
50
+ - **Unit Reference**: an ISO 8601 timestamp, for the most recent time to read. It is optional.
51
+
52
+ The output is the answer of Bitly as it is.
53
+
54
+ When Bitly answers with no body, the node returns `{ "success": true }`. This happens, for example, on an update.
55
+
56
+ **Destructive operations.** The node has no delete operation. **Update** can archive a bitlink with **Archived**.
57
+
58
+ **Binary data.** The node does not read or write binary data.
59
+
60
+ **Limits and retries.** Each call has a timeout. The default is 30 seconds. The node does not retry a failed call. It does not follow redirects. Error messages include the Bitly message. Hints are added for these statuses:
61
+
62
+ - `401`: the access token was not accepted.
63
+ - `403`: the access token may lack access to the resource.
64
+ - `404`: check the IDs.
65
+ - `429`: the rate limit was reached. Try again later.
66
+
67
+ ## Credentials
68
+
69
+ ### Bitly access token (`bitly.accessToken`)
70
+
71
+ - **Access Token** (`accessToken`): the access token. This value is secret.
72
+
73
+ The node sends the token as a Bearer token. The node does not set scopes.
74
+
75
+ The test of the credential calls `GET /v4/user`.
76
+
77
+ Setup:
78
+
79
+ 1. In Bitly, open **Settings > Developer settings > API**.
80
+ 2. Copy an access token. Create one if you have none.
81
+ 3. In zerodot, create a **Bitly access token** credential.
82
+ 4. Paste the token into **Access Token**. Save and test the credential.
83
+
84
+ ## License
85
+
86
+ AGPL-3.0-only
package/dist/index.cjs CHANGED
@@ -166,18 +166,24 @@ const bitlyConfig = zod.z.object({
166
166
  ...on("bitlink", "create", "update"),
167
167
  title: "Long URL",
168
168
  description: "The destination URL. Required when creating a bitlink",
169
- requiredWhenShown: true
169
+ requiredWhen: {
170
+ resource: ["bitlink"],
171
+ operation: ["create"]
172
+ }
170
173
  }),
171
174
  domain: zod.z.string().optional().meta({
172
175
  ...on("bitlink", "create"),
173
176
  title: "Domain",
174
- description: "The short domain, defaults to \"bit.ly\""
177
+ description: "The short domain. Leave empty to let Bitly use its default, bit.ly. A custom domain must be attached to your Bitly account"
175
178
  }),
176
179
  groupGuid: zod.z.string().optional().meta({
177
180
  ...on("bitlink", "create", "getMany"),
178
181
  title: "Group GUID",
179
- description: "The Bitly group GUID. Required when listing bitlinks by group",
180
- requiredWhenShown: true
182
+ description: "The Bitly group GUID. Required when listing bitlinks by group. Optional when creating a bitlink",
183
+ requiredWhen: {
184
+ resource: ["bitlink"],
185
+ operation: ["getMany"]
186
+ }
181
187
  }),
182
188
  title: zod.z.string().optional().meta({
183
189
  ...on("bitlink", "create", "update"),
@@ -246,6 +252,11 @@ const bitlyConfig = zod.z.object({
246
252
  path: ["longUrl"],
247
253
  message: "Bitlink create needs a long URL"
248
254
  });
255
+ if (config.resource === "bitlink" && config.operation === "getMany" && !config.groupGuid?.trim()) context.addIssue({
256
+ code: "custom",
257
+ path: ["groupGuid"],
258
+ message: "Bitlink list needs a group GUID"
259
+ });
249
260
  });
250
261
  // src/request.ts
251
262
  const need = (value, name, operation) => {
@@ -255,9 +266,9 @@ const need = (value, name, operation) => {
255
266
  };
256
267
  /** An ID goes in a path. It is encoded so it cannot change the path. */
257
268
  const id = (value, name, operation) => encodeURIComponent(need(value, name, operation));
258
- /** A bitlink ID is domain/hash and the slash is part of the path. */
269
+ /** A bitlink ID is domain/hash and the slash is part of the path. A scheme such as https:// is removed. */
259
270
  const bitlinkId = (value, operation) => {
260
- const parts = need(value, "bitlink", operation).split("/").filter(Boolean);
271
+ const parts = need(value, "bitlink", operation).replace(/^[a-z][a-z0-9+.-]*:\/\//i, "").split("/").filter(Boolean);
261
272
  if (parts.length < 2) throw new Error(`Bitly ${operation} needs "bitlink" in domain/hash format`);
262
273
  return parts.map(encodeURIComponent).join("/");
263
274
  };
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@zerodot/bitly",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Create and manage Bitly short links, list bitlinks by group, and view click summaries.",
5
5
  "license": "AGPL-3.0-only",
6
+ "homepage": "https://github.com/zerodot-io/nodes/tree/main/packages/bitly",
6
7
  "repository": {
7
8
  "type": "git",
8
9
  "url": "git+https://github.com/zerodot-io/nodes.git",