@duckity/js 0.1.6 → 0.1.7

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@duckity/js",
3
3
  "type": "module",
4
- "version": "0.1.6",
4
+ "version": "0.1.7",
5
5
  "module": "src/index.ts",
6
6
  "types": "dist/index.d.ts",
7
7
  "collaborators": [
package/src/index.ts CHANGED
@@ -13,9 +13,22 @@ export interface GetDuckityChallengeOptions {
13
13
  /**
14
14
  * The base URL to the API endpoint. Defaults to `https://quack.duckity.com` if not provided.
15
15
  *
16
- * Update this when self-hosting a Duckling. No trailing slash must be included in the URL.
16
+ * Only update this when self-hosting a Duckling.
17
17
  */
18
18
  api?: string;
19
+
20
+ // /**
21
+ // * When this is `false`, the client will assume it is allowed to get a challenge the first time
22
+ // * one is requested. This may not always be true (when the client has an active penalty or used
23
+ // * all of their allowed requests in another session), case in which the client may be penalized.
24
+ // *
25
+ // * When this is `true`, an extra request will be made to the Duckling API to synchronize the
26
+ // * client's state with the server's state. This extra request will not issue a challenge, rather
27
+ // * only synchronize the client's state with the server's state. If the client is penalized or has
28
+ // * to wait before being allowed to get a challenge, the client will be informed of this. It'll
29
+ // * avoid getting it unnecessarily penalized at the cost of an extra request.
30
+ // */
31
+ // sync?: boolean;
19
32
  }
20
33
 
21
34
  /**
@@ -40,8 +53,13 @@ export async function solve(
40
53
  protectionProfileId: string,
41
54
  options?: GetDuckityChallengeOptions,
42
55
  ): Promise<string> {
56
+ if (options?.api && options.api.endsWith("/")) {
57
+ // Remove the trailing slash from the API URL if provided
58
+ options.api = options.api.slice(0, -1);
59
+ }
60
+
43
61
  let response: ChallengeResponse = await post(
44
- `${options?.api || "https://quack.duckity.com"}/v1/challenge`,
62
+ `${options?.api || "https://quack.duckity.com"}/v1/challenges/${protectionProfileId}/issue`,
45
63
  {
46
64
  body: {
47
65
  id: protectionProfileId,
@@ -55,4 +73,4 @@ export async function solve(
55
73
  return solution;
56
74
  }
57
75
 
58
- export default { solve }
76
+ export default { solve };
package/src/options.ts ADDED
File without changes