@factorialco/api-client 1.1.0 → 1.2.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/README.md CHANGED
@@ -57,11 +57,11 @@ Explicit options always take precedence.
57
57
  | Variable | Maps to option | Sent as |
58
58
  |----------|----------------|---------|
59
59
  | `FACTORIAL_API_KEY` | `apiKey` | `x-api-key` header |
60
- | `FACTORIAL_OAUTH_TOKEN` | `token` | `Authorization: Bearer` |
60
+ | `FACTORIAL_TOKEN` | `token` | `Authorization: Bearer` |
61
61
  | `FACTORIAL_BASE_URL` | `baseUrl` | — (defaults to `https://api.factorialhr.com`) |
62
62
 
63
63
  ```ts
64
- // No options needed — reads FACTORIAL_API_KEY / FACTORIAL_OAUTH_TOKEN / FACTORIAL_BASE_URL
64
+ // No options needed — reads FACTORIAL_API_KEY / FACTORIAL_TOKEN / FACTORIAL_BASE_URL
65
65
  const client = new FactorialClient();
66
66
  ```
67
67
 
@@ -172,6 +172,56 @@ try {
172
172
  You can opt out per client (restoring the `{ data, error }` return shape) with
173
173
  `new FactorialClient({ ..., throwOnError: false })`.
174
174
 
175
+ ## Webhooks
176
+
177
+ Manage subscriptions through the client, and type your handler payloads with the
178
+ generated webhook catalog (re-exported from the package root).
179
+
180
+ ```ts
181
+ import {
182
+ FactorialClient,
183
+ WEBHOOK_CATALOG,
184
+ } from "@factorialco/api-client";
185
+ import type {
186
+ AtsApplicationCreateWebhook,
187
+ WebhookSubscriptionType,
188
+ WebhookPayloadMap,
189
+ } from "@factorialco/api-client";
190
+
191
+ const client = new FactorialClient({ apiKey: process.env.FACTORIAL_API_KEY });
192
+
193
+ // Subscribe to an event. The `challenge` is a secret you choose; Factorial echoes
194
+ // it back in the `x-factorial-wh-challenge` header on every delivery so you can
195
+ // verify the request really came from Factorial.
196
+ await client.apiPublic.webhookSubscriptions.create({
197
+ subscription_type: "ats/application/create",
198
+ target_url: "https://example.com/webhooks/factorial",
199
+ company_id: 55,
200
+ challenge: "a-random-secret-you-generate",
201
+ });
202
+
203
+ // Type a handler directly…
204
+ function onApplicationCreated(payload: AtsApplicationCreateWebhook) {
205
+ console.log(payload.id);
206
+ }
207
+
208
+ // …or dispatch on the runtime subscription_type with full type safety
209
+ function handle<T extends WebhookSubscriptionType>(type: T, payload: WebhookPayloadMap[T]) {
210
+ /* payload is narrowed to the right type for `type` */
211
+ }
212
+
213
+ // Discover every event at runtime
214
+ console.log(WEBHOOK_CATALOG.length, "webhook events available");
215
+ ```
216
+
217
+ Factorial delivers the resource object at the **top level** of the POST body (no
218
+ `{ type, data }` envelope). A full event→payload reference and an SDK usage guide
219
+ for coding agents are available as a skill:
220
+
221
+ ```bash
222
+ npx skills add https://github.com/factorialco/factorial-api-sdks --skill factorial-api-sdks
223
+ ```
224
+
175
225
  ## Custom base URL
176
226
 
177
227
  ```ts
@@ -2,4 +2,5 @@ export { FactorialClient } from "./sdk.js";
2
2
  export type { FactorialClientConfig } from "./sdk.js";
3
3
  export type { PagedMeta, PaginateOptions } from "./pagination.js";
4
4
  export * from "./generated/types.gen.js";
5
+ export * from "./webhooks.js";
5
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3C,YAAY,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AACtD,YAAY,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClE,cAAc,0BAA0B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3C,YAAY,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AACtD,YAAY,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClE,cAAc,0BAA0B,CAAC;AAGzC,cAAc,eAAe,CAAC"}
package/dist/cjs/index.js CHANGED
@@ -21,4 +21,7 @@ exports.FactorialClient = void 0;
21
21
  var sdk_js_1 = require("./sdk.js");
22
22
  Object.defineProperty(exports, "FactorialClient", { enumerable: true, get: function () { return sdk_js_1.FactorialClient; } });
23
23
  __exportStar(require("./generated/types.gen.js"), exports);
24
+ // Typed webhook catalog: per-event payload aliases, WebhookSubscriptionType,
25
+ // WebhookPayloadMap, and the runtime WEBHOOK_CATALOG.
26
+ __exportStar(require("./webhooks.js"), exports);
24
27
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,kDAAkD;AAClD,yCAAyC;AACzC,+DAA+D;AAC/D,mCAA2C;AAAlC,yGAAA,eAAe,OAAA;AAGxB,2DAAyC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,kDAAkD;AAClD,yCAAyC;AACzC,+DAA+D;AAC/D,mCAA2C;AAAlC,yGAAA,eAAe,OAAA;AAGxB,2DAAyC;AACzC,6EAA6E;AAC7E,sDAAsD;AACtD,gDAA8B"}
package/dist/cjs/sdk.d.ts CHANGED
@@ -20,7 +20,7 @@ export type FactorialClientConfig = Omit<Partial<Config<ClientOptions>>, "baseUr
20
20
  /**
21
21
  * OAuth2 bearer token — sent as `Authorization: Bearer <token>`.
22
22
  * Use this when authenticating via OAuth2 instead of an API key.
23
- * Falls back to the `FACTORIAL_OAUTH_TOKEN` env var when omitted.
23
+ * Falls back to the `FACTORIAL_TOKEN` env var when omitted.
24
24
  */
25
25
  token?: string;
26
26
  };
package/dist/cjs/sdk.js CHANGED
@@ -5523,10 +5523,10 @@ class FactorialClient {
5523
5523
  globalThis.process.env
5524
5524
  : {};
5525
5525
  const resolvedApiKey = apiKey ?? env.FACTORIAL_API_KEY;
5526
- const resolvedToken = token ?? env.FACTORIAL_OAUTH_TOKEN;
5526
+ const resolvedToken = token ?? env.FACTORIAL_TOKEN;
5527
5527
  const resolvedBaseUrl = baseUrl ?? env.FACTORIAL_BASE_URL ?? "https://api.factorialhr.com";
5528
5528
  if (!resolvedApiKey && !resolvedToken) {
5529
- throw new Error("FactorialClient: provide either apiKey or token (or set FACTORIAL_API_KEY / FACTORIAL_OAUTH_TOKEN)");
5529
+ throw new Error("FactorialClient: provide either apiKey or token (or set FACTORIAL_API_KEY / FACTORIAL_TOKEN)");
5530
5530
  }
5531
5531
  // hey-api calls the auth callback once per security scheme in spec order:
5532
5532
  // 1. { type: 'http', scheme: 'bearer' } → Authorization: Bearer <token>