@outseta/node-sdk 0.0.0 → 0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Outseta
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # @outseta/node-sdk
2
+
3
+ Node.js SDK for the [Outseta](https://www.outseta.com) API. A thin wrapper around [`@outseta/api-client`](https://www.npmjs.com/package/@outseta/api-client) designed for server-side usage.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @outseta/node-sdk
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ts
14
+ import { createClient } from "@outseta/node-sdk";
15
+
16
+ const client = createClient({
17
+ subdomain: "your-company",
18
+ apiKey: "your-api-key",
19
+ apiSecret: "your-api-secret",
20
+ });
21
+ ```
22
+
23
+ ## License
24
+
25
+ [MIT](../../LICENSE)
package/dist/index.js CHANGED
@@ -1,5 +1,55 @@
1
1
  // src/index.ts
2
2
  import { createClient } from "@outseta/api-client";
3
+
4
+ // src/verify-webhook.ts
5
+ import { createHmac, timingSafeEqual } from "node:crypto";
6
+ function verifyWebhookSignature(signature, body, signingKey) {
7
+ const key = Buffer.from(signingKey, "hex");
8
+ const computed = createHmac("sha256", key).update(Buffer.from(body, "utf-8")).digest("hex");
9
+ const expected = `sha256=${computed}`;
10
+ if (signature.length !== expected.length)
11
+ return false;
12
+ return timingSafeEqual(Buffer.from(signature), Buffer.from(expected));
13
+ }
14
+ // src/verify-jwt.ts
15
+ import { jwtVerify, createRemoteJWKSet, decodeJwt } from "jose";
16
+ async function verifyJwt(token, options) {
17
+ const jwks = createRemoteJWKSet(new URL(`https://${options.subdomain}.outseta.com/.well-known/jwks`));
18
+ const { payload } = await jwtVerify(token, jwks);
19
+ return payload;
20
+ }
21
+ async function verifyJwtWithProfile(token, options) {
22
+ const response = await fetch(`https://${options.subdomain}.outseta.com/api/v1/profile?fields=*`, {
23
+ headers: { Authorization: `Bearer ${token}` }
24
+ });
25
+ if (!response.ok) {
26
+ const error = await response.json().catch(() => ({}));
27
+ throw new Error(`Profile verification failed: [${response.status}] ${error.ErrorMessage || error.Message || response.statusText}`);
28
+ }
29
+ const profile = await response.json();
30
+ const payload = decodeJwt(token);
31
+ return { payload, profile };
32
+ }
33
+ // src/generate-token.ts
34
+ async function generateAccessToken(credentials, email) {
35
+ const response = await fetch(`https://${credentials.subdomain}.outseta.com/api/v1/tokens`, {
36
+ method: "POST",
37
+ headers: {
38
+ Authorization: `Outseta ${credentials.apiKey}:${credentials.apiSecret}`,
39
+ "Content-Type": "application/json"
40
+ },
41
+ body: JSON.stringify({ username: email })
42
+ });
43
+ const data = await response.json();
44
+ if (!response.ok) {
45
+ throw new Error(`Failed to generate token: [${response.status}] ${data.ErrorMessage || data.Message || response.statusText}`);
46
+ }
47
+ return data;
48
+ }
3
49
  export {
50
+ verifyWebhookSignature,
51
+ verifyJwtWithProfile,
52
+ verifyJwt,
53
+ generateAccessToken,
4
54
  createClient
5
55
  };
package/package.json CHANGED
@@ -1,7 +1,13 @@
1
1
  {
2
2
  "name": "@outseta/node-sdk",
3
- "version": "0.0.0",
3
+ "version": "0.2.0",
4
4
  "description": "Node.js SDK for the Outseta API",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/outseta/outseta-js.git",
9
+ "directory": "packages/node-sdk"
10
+ },
5
11
  "type": "module",
6
12
  "main": "./dist/index.js",
7
13
  "types": "./src/index.ts",
@@ -17,13 +23,18 @@
17
23
  "lint": "eslint src"
18
24
  },
19
25
  "dependencies": {
20
- "@outseta/api-client": "*"
26
+ "@outseta/api-client": "*",
27
+ "jose": "^6.2.1"
21
28
  },
22
29
  "devDependencies": {
23
30
  "typescript": "^5.7.0"
24
31
  },
25
- "files": ["dist", "src"],
32
+ "files": [
33
+ "dist",
34
+ "src"
35
+ ],
26
36
  "publishConfig": {
27
- "access": "public"
37
+ "access": "public",
38
+ "provenance": true
28
39
  }
29
40
  }
@@ -0,0 +1,39 @@
1
+ import type { OutsetaCredentials } from "@outseta/api-client";
2
+
3
+ /**
4
+ * Generates a JWT access token for a user by email.
5
+ *
6
+ * Requires server-side API Key + Secret credentials.
7
+ * Useful for logging in users programmatically, testing auth flows,
8
+ * or acting on behalf of a user from a backend service.
9
+ */
10
+ export async function generateAccessToken(
11
+ credentials: OutsetaCredentials,
12
+ email: string,
13
+ ) {
14
+ const response = await fetch(
15
+ `https://${credentials.subdomain}.outseta.com/api/v1/tokens`,
16
+ {
17
+ method: "POST",
18
+ headers: {
19
+ Authorization: `Outseta ${credentials.apiKey}:${credentials.apiSecret}`,
20
+ "Content-Type": "application/json",
21
+ },
22
+ body: JSON.stringify({ username: email }),
23
+ },
24
+ );
25
+
26
+ const data = (await response.json()) as Record<string, unknown>;
27
+
28
+ if (!response.ok) {
29
+ throw new Error(
30
+ `Failed to generate token: [${response.status}] ${
31
+ (data.ErrorMessage as string) ||
32
+ (data.Message as string) ||
33
+ response.statusText
34
+ }`,
35
+ );
36
+ }
37
+
38
+ return data as { access_token: string } & Record<string, unknown>;
39
+ }
package/src/index.ts CHANGED
@@ -1,2 +1,7 @@
1
1
  export { createClient } from "@outseta/api-client";
2
2
  export type { OutsetaCredentials } from "@outseta/api-client";
3
+
4
+ export { verifyWebhookSignature } from "./verify-webhook.js";
5
+ export { verifyJwt, verifyJwtWithProfile } from "./verify-jwt.js";
6
+ export type { JWTPayload } from "./verify-jwt.js";
7
+ export { generateAccessToken } from "./generate-token.js";
@@ -0,0 +1,61 @@
1
+ import { jwtVerify, createRemoteJWKSet, decodeJwt } from "jose";
2
+ export type { JWTPayload } from "jose";
3
+
4
+ /**
5
+ * Verifies an Outseta JWT using the public JWK Set.
6
+ *
7
+ * This is the recommended method — it cryptographically verifies
8
+ * the token signature without making an API call to Outseta.
9
+ *
10
+ * For high-throughput applications, consider caching the JWK Set
11
+ * by reusing the same function across calls (jose handles caching
12
+ * internally via `createRemoteJWKSet`).
13
+ */
14
+ export async function verifyJwt(
15
+ token: string,
16
+ options: { subdomain: string },
17
+ ) {
18
+ const jwks = createRemoteJWKSet(
19
+ new URL(
20
+ `https://${options.subdomain}.outseta.com/.well-known/jwks`,
21
+ ),
22
+ );
23
+ const { payload } = await jwtVerify(token, jwks);
24
+ return payload;
25
+ }
26
+
27
+ /**
28
+ * Verifies an Outseta JWT by calling the profile endpoint.
29
+ *
30
+ * Returns both the decoded JWT payload and the full user profile.
31
+ * Simpler than JWK Set verification but makes a network request
32
+ * to Outseta on every call.
33
+ */
34
+ export async function verifyJwtWithProfile(
35
+ token: string,
36
+ options: { subdomain: string },
37
+ ) {
38
+ const response = await fetch(
39
+ `https://${options.subdomain}.outseta.com/api/v1/profile?fields=*`,
40
+ {
41
+ headers: { Authorization: `Bearer ${token}` },
42
+ },
43
+ );
44
+
45
+ if (!response.ok) {
46
+ const error = (await response.json().catch(() => ({}))) as Record<
47
+ string,
48
+ string
49
+ >;
50
+ throw new Error(
51
+ `Profile verification failed: [${response.status}] ${
52
+ error.ErrorMessage || error.Message || response.statusText
53
+ }`,
54
+ );
55
+ }
56
+
57
+ const profile = (await response.json()) as Record<string, unknown>;
58
+ const payload = decodeJwt(token);
59
+
60
+ return { payload, profile };
61
+ }
@@ -0,0 +1,23 @@
1
+ import { createHmac, timingSafeEqual } from "node:crypto";
2
+
3
+ /**
4
+ * Verifies an Outseta webhook signature.
5
+ *
6
+ * Compare the `x-hub-signature-256` request header against
7
+ * the HMAC-SHA256 computed from the raw request body and
8
+ * your webhook signing key (found in Outseta webhook settings).
9
+ */
10
+ export function verifyWebhookSignature(
11
+ signature: string,
12
+ body: string,
13
+ signingKey: string,
14
+ ): boolean {
15
+ const key = Buffer.from(signingKey, "hex");
16
+ const computed = createHmac("sha256", key)
17
+ .update(Buffer.from(body, "utf-8"))
18
+ .digest("hex");
19
+ const expected = `sha256=${computed}`;
20
+
21
+ if (signature.length !== expected.length) return false;
22
+ return timingSafeEqual(Buffer.from(signature), Buffer.from(expected));
23
+ }