@01.software/sdk 0.8.0 → 0.10.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.
Files changed (48) hide show
  1. package/README.md +23 -25
  2. package/dist/{const-dv0zuAxG.d.cts → const-Dmgge6oQ.d.ts} +2 -2
  3. package/dist/{const-CCh99Gxu.d.ts → const-k0fqIBda.d.cts} +2 -2
  4. package/dist/index.cjs +52 -167
  5. package/dist/index.cjs.map +1 -1
  6. package/dist/index.d.cts +22 -34
  7. package/dist/index.d.ts +22 -34
  8. package/dist/index.js +52 -167
  9. package/dist/index.js.map +1 -1
  10. package/dist/{payload-types-FfZ2Zxp1.d.cts → payload-types-D0zFPijW.d.cts} +306 -112
  11. package/dist/{payload-types-FfZ2Zxp1.d.ts → payload-types-D0zFPijW.d.ts} +306 -112
  12. package/dist/{realtime-DupPIYx-.d.cts → realtime-D7HtUpqt.d.cts} +2 -2
  13. package/dist/{realtime-DupPIYx-.d.ts → realtime-D7HtUpqt.d.ts} +2 -2
  14. package/dist/realtime.cjs +8 -7
  15. package/dist/realtime.cjs.map +1 -1
  16. package/dist/realtime.d.cts +6 -6
  17. package/dist/realtime.d.ts +6 -6
  18. package/dist/realtime.js +8 -7
  19. package/dist/realtime.js.map +1 -1
  20. package/dist/{server-DxhuG-_s.d.cts → server-JR9TvKZ5.d.cts} +0 -2
  21. package/dist/{server-DxhuG-_s.d.ts → server-JR9TvKZ5.d.ts} +0 -2
  22. package/dist/ui/canvas/server.cjs +1 -2
  23. package/dist/ui/canvas/server.cjs.map +1 -1
  24. package/dist/ui/canvas/server.d.cts +1 -1
  25. package/dist/ui/canvas/server.d.ts +1 -1
  26. package/dist/ui/canvas/server.js +1 -2
  27. package/dist/ui/canvas/server.js.map +1 -1
  28. package/dist/ui/canvas.cjs +1 -2
  29. package/dist/ui/canvas.cjs.map +1 -1
  30. package/dist/ui/canvas.d.cts +2 -2
  31. package/dist/ui/canvas.d.ts +2 -2
  32. package/dist/ui/canvas.js +1 -2
  33. package/dist/ui/canvas.js.map +1 -1
  34. package/dist/ui/form.d.cts +1 -1
  35. package/dist/ui/form.d.ts +1 -1
  36. package/dist/ui/video.d.cts +1 -1
  37. package/dist/ui/video.d.ts +1 -1
  38. package/dist/{webhook-t7JGFLKQ.d.cts → webhook-DXr8B9E6.d.cts} +2 -2
  39. package/dist/{webhook-B9MDrH22.d.ts → webhook-caDRhnd7.d.ts} +2 -2
  40. package/dist/webhook.d.cts +3 -3
  41. package/dist/webhook.d.ts +3 -3
  42. package/package.json +1 -11
  43. package/dist/auth.cjs +0 -109
  44. package/dist/auth.cjs.map +0 -1
  45. package/dist/auth.d.cts +0 -36
  46. package/dist/auth.d.ts +0 -36
  47. package/dist/auth.js +0 -86
  48. package/dist/auth.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { F as Form } from '../payload-types-FfZ2Zxp1.cjs';
2
+ import { F as Form } from '../payload-types-D0zFPijW.cjs';
3
3
  import { RichTextData } from './rich-text.cjs';
4
4
  import '@payloadcms/richtext-lexical';
5
5
  import '@payloadcms/richtext-lexical/lexical';
package/dist/ui/form.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { F as Form } from '../payload-types-FfZ2Zxp1.js';
2
+ import { F as Form } from '../payload-types-D0zFPijW.js';
3
3
  import { RichTextData } from './rich-text.js';
4
4
  import '@payloadcms/richtext-lexical';
5
5
  import '@payloadcms/richtext-lexical/lexical';
@@ -1,7 +1,7 @@
1
1
  import React, { CSSProperties } from 'react';
2
2
  import { MuxPlayerProps, MuxPlayerRefAttributes } from '@mux/mux-player-react';
3
3
  export { MuxPlayerRefAttributes as VideoPlayerRef } from '@mux/mux-player-react';
4
- import { V as Video } from '../payload-types-FfZ2Zxp1.cjs';
4
+ import { V as Video } from '../payload-types-D0zFPijW.cjs';
5
5
  export { e as VideoGifOptions, V as VideoThumbnailOptions, a as getVideoGif, c as getVideoMp4Url, d as getVideoStoryboard, b as getVideoStreamUrl, g as getVideoThumbnail } from '../video-DbLL8yuc.cjs';
6
6
 
7
7
  interface VideoPlayerCSSProperties extends CSSProperties {
@@ -1,7 +1,7 @@
1
1
  import React, { CSSProperties } from 'react';
2
2
  import { MuxPlayerProps, MuxPlayerRefAttributes } from '@mux/mux-player-react';
3
3
  export { MuxPlayerRefAttributes as VideoPlayerRef } from '@mux/mux-player-react';
4
- import { V as Video } from '../payload-types-FfZ2Zxp1.js';
4
+ import { V as Video } from '../payload-types-D0zFPijW.js';
5
5
  export { e as VideoGifOptions, V as VideoThumbnailOptions, a as getVideoGif, c as getVideoMp4Url, d as getVideoStoryboard, b as getVideoStreamUrl, g as getVideoThumbnail } from '../video-DbLL8yuc.js';
6
6
 
7
7
  interface VideoPlayerCSSProperties extends CSSProperties {
@@ -1,5 +1,5 @@
1
- import { C as Collection } from './const-dv0zuAxG.cjs';
2
- import { C as Config } from './payload-types-FfZ2Zxp1.cjs';
1
+ import { C as Collection } from './const-k0fqIBda.cjs';
2
+ import { C as Config } from './payload-types-D0zFPijW.cjs';
3
3
 
4
4
  type CollectionType<T extends string> = T extends keyof Config['collections'] ? Config['collections'][T] : never;
5
5
 
@@ -1,5 +1,5 @@
1
- import { C as Collection } from './const-CCh99Gxu.js';
2
- import { C as Config } from './payload-types-FfZ2Zxp1.js';
1
+ import { C as Collection } from './const-Dmgge6oQ.js';
2
+ import { C as Config } from './payload-types-D0zFPijW.js';
3
3
 
4
4
  type CollectionType<T extends string> = T extends keyof Config['collections'] ? Config['collections'][T] : never;
5
5
 
@@ -1,3 +1,3 @@
1
- export { a as WebhookEvent, b as WebhookHandler, W as WebhookOperation, c as WebhookOptions, d as createTypedWebhookHandler, h as handleWebhook, i as isValidWebhookEvent } from './webhook-t7JGFLKQ.cjs';
2
- import './const-dv0zuAxG.cjs';
3
- import './payload-types-FfZ2Zxp1.cjs';
1
+ export { a as WebhookEvent, b as WebhookHandler, W as WebhookOperation, c as WebhookOptions, d as createTypedWebhookHandler, h as handleWebhook, i as isValidWebhookEvent } from './webhook-DXr8B9E6.cjs';
2
+ import './const-k0fqIBda.cjs';
3
+ import './payload-types-D0zFPijW.cjs';
package/dist/webhook.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { a as WebhookEvent, b as WebhookHandler, W as WebhookOperation, c as WebhookOptions, d as createTypedWebhookHandler, h as handleWebhook, i as isValidWebhookEvent } from './webhook-B9MDrH22.js';
2
- import './const-CCh99Gxu.js';
3
- import './payload-types-FfZ2Zxp1.js';
1
+ export { a as WebhookEvent, b as WebhookHandler, W as WebhookOperation, c as WebhookOptions, d as createTypedWebhookHandler, h as handleWebhook, i as isValidWebhookEvent } from './webhook-caDRhnd7.js';
2
+ import './const-Dmgge6oQ.js';
3
+ import './payload-types-D0zFPijW.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@01.software/sdk",
3
- "version": "0.8.0",
3
+ "version": "0.10.0",
4
4
  "description": "01.software SDK",
5
5
  "author": "<office@01.works>",
6
6
  "keywords": [],
@@ -19,16 +19,6 @@
19
19
  "default": "./dist/index.cjs"
20
20
  }
21
21
  },
22
- "./auth": {
23
- "import": {
24
- "types": "./dist/auth.d.ts",
25
- "default": "./dist/auth.js"
26
- },
27
- "require": {
28
- "types": "./dist/auth.d.cts",
29
- "default": "./dist/auth.cjs"
30
- }
31
- },
32
22
  "./webhook": {
33
23
  "import": {
34
24
  "types": "./dist/webhook.d.ts",
package/dist/auth.cjs DELETED
@@ -1,109 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/auth.ts
21
- var auth_exports = {};
22
- __export(auth_exports, {
23
- createApiKey: () => createApiKey,
24
- createServerToken: () => createServerToken,
25
- decodeServerToken: () => decodeServerToken,
26
- parseApiKey: () => parseApiKey,
27
- verifyServerToken: () => verifyServerToken
28
- });
29
- module.exports = __toCommonJS(auth_exports);
30
-
31
- // src/core/internal/utils/jwt.ts
32
- var import_jose = require("jose");
33
- async function createServerToken(clientKey, secretKey, expiresIn = "1h") {
34
- if (!clientKey || !secretKey) {
35
- throw new Error("clientKey and secretKey are required.");
36
- }
37
- const secret = new TextEncoder().encode(secretKey);
38
- return new import_jose.SignJWT({ clientKey }).setProtectedHeader({ alg: "HS256" }).setIssuedAt().setExpirationTime(expiresIn).sign(secret);
39
- }
40
- async function verifyServerToken(token, secretKey) {
41
- if (!token || !secretKey) {
42
- throw new Error("token and secretKey are required.");
43
- }
44
- const secret = new TextEncoder().encode(secretKey);
45
- const { payload } = await (0, import_jose.jwtVerify)(token, secret, {
46
- algorithms: ["HS256"]
47
- });
48
- if (!payload.clientKey || typeof payload.clientKey !== "string") {
49
- throw new Error("Invalid token payload: clientKey is missing");
50
- }
51
- return {
52
- clientKey: payload.clientKey,
53
- iat: payload.iat,
54
- exp: payload.exp
55
- };
56
- }
57
- function decodeServerToken(token) {
58
- if (!token) {
59
- throw new Error("token is required.");
60
- }
61
- const payload = (0, import_jose.decodeJwt)(token);
62
- if (!payload.clientKey || typeof payload.clientKey !== "string") {
63
- throw new Error("Invalid token payload: clientKey is missing");
64
- }
65
- return {
66
- clientKey: payload.clientKey,
67
- iat: payload.iat,
68
- exp: payload.exp
69
- };
70
- }
71
-
72
- // src/core/internal/utils/encoding.ts
73
- function createApiKey(clientKey, secretKey) {
74
- if (!clientKey || !secretKey) {
75
- throw new Error("clientKey and secretKey are required.");
76
- }
77
- if (typeof Buffer !== "undefined") {
78
- return Buffer.from(`${clientKey}:${secretKey}`).toString("base64");
79
- }
80
- return btoa(`${clientKey}:${secretKey}`);
81
- }
82
- function parseApiKey(apiKey) {
83
- if (!apiKey) {
84
- throw new Error("apiKey is required.");
85
- }
86
- try {
87
- let decoded;
88
- if (typeof Buffer !== "undefined") {
89
- decoded = Buffer.from(apiKey, "base64").toString("utf-8");
90
- } else {
91
- decoded = atob(apiKey);
92
- }
93
- const colonIndex = decoded.indexOf(":");
94
- if (colonIndex === -1) {
95
- throw new Error("Invalid format: missing colon separator");
96
- }
97
- const clientKey = decoded.substring(0, colonIndex);
98
- const secretKey = decoded.substring(colonIndex + 1);
99
- if (!clientKey || !secretKey) {
100
- throw new Error("Invalid format: empty clientKey or secretKey");
101
- }
102
- return { clientKey, secretKey };
103
- } catch {
104
- throw new Error(
105
- 'Invalid API key. Expected Base64 encoded "clientKey:secretKey"'
106
- );
107
- }
108
- }
109
- //# sourceMappingURL=auth.cjs.map
package/dist/auth.cjs.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/auth.ts","../src/core/internal/utils/jwt.ts","../src/core/internal/utils/encoding.ts"],"sourcesContent":["export type { JwtPayload } from './core/internal/utils'\nexport {\n createServerToken,\n verifyServerToken,\n decodeServerToken,\n createApiKey,\n parseApiKey,\n} from './core/internal/utils'\n","import { SignJWT, jwtVerify, decodeJwt } from 'jose'\n\nexport interface JwtPayload {\n clientKey: string\n iat?: number\n exp?: number\n}\n\n/**\n * Creates a JWT token for server-side authentication.\n * The token is valid for 1 hour by default.\n */\nexport async function createServerToken(\n clientKey: string,\n secretKey: string,\n expiresIn: string = '1h',\n): Promise<string> {\n if (!clientKey || !secretKey) {\n throw new Error('clientKey and secretKey are required.')\n }\n\n const secret = new TextEncoder().encode(secretKey)\n return new SignJWT({ clientKey })\n .setProtectedHeader({ alg: 'HS256' })\n .setIssuedAt()\n .setExpirationTime(expiresIn)\n .sign(secret)\n}\n\n/**\n * Verifies a JWT token and returns the payload.\n */\nexport async function verifyServerToken(\n token: string,\n secretKey: string,\n): Promise<JwtPayload> {\n if (!token || !secretKey) {\n throw new Error('token and secretKey are required.')\n }\n\n const secret = new TextEncoder().encode(secretKey)\n const { payload } = await jwtVerify(token, secret, {\n algorithms: ['HS256'],\n })\n\n if (!payload.clientKey || typeof payload.clientKey !== 'string') {\n throw new Error('Invalid token payload: clientKey is missing')\n }\n\n return {\n clientKey: payload.clientKey as string,\n iat: payload.iat,\n exp: payload.exp,\n }\n}\n\n/**\n * Decodes a JWT token without verification.\n * WARNING: Use this only when you need to inspect token contents.\n * Always use verifyServerToken for authentication.\n */\nexport function decodeServerToken(token: string): JwtPayload {\n if (!token) {\n throw new Error('token is required.')\n }\n\n const payload = decodeJwt(token)\n\n if (!payload.clientKey || typeof payload.clientKey !== 'string') {\n throw new Error('Invalid token payload: clientKey is missing')\n }\n\n return {\n clientKey: payload.clientKey as string,\n iat: payload.iat,\n exp: payload.exp,\n }\n}\n","/**\n * Creates a Base64-encoded API key from clientKey and secretKey.\n */\nexport function createApiKey(clientKey: string, secretKey: string): string {\n if (!clientKey || !secretKey) {\n throw new Error('clientKey and secretKey are required.')\n }\n\n if (typeof Buffer !== 'undefined') {\n return Buffer.from(`${clientKey}:${secretKey}`).toString('base64')\n }\n return btoa(`${clientKey}:${secretKey}`)\n}\n\n/**\n * Parses a Base64-encoded API key to extract clientKey and secretKey.\n */\nexport function parseApiKey(apiKey: string): {\n clientKey: string\n secretKey: string\n} {\n if (!apiKey) {\n throw new Error('apiKey is required.')\n }\n\n try {\n let decoded: string\n if (typeof Buffer !== 'undefined') {\n decoded = Buffer.from(apiKey, 'base64').toString('utf-8')\n } else {\n decoded = atob(apiKey)\n }\n\n const colonIndex = decoded.indexOf(':')\n if (colonIndex === -1) {\n throw new Error('Invalid format: missing colon separator')\n }\n\n const clientKey = decoded.substring(0, colonIndex)\n const secretKey = decoded.substring(colonIndex + 1)\n\n if (!clientKey || !secretKey) {\n throw new Error('Invalid format: empty clientKey or secretKey')\n }\n\n return { clientKey, secretKey }\n } catch {\n throw new Error(\n 'Invalid API key. Expected Base64 encoded \"clientKey:secretKey\"',\n )\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAA8C;AAY9C,eAAsB,kBACpB,WACA,WACA,YAAoB,MACH;AACjB,MAAI,CAAC,aAAa,CAAC,WAAW;AAC5B,UAAM,IAAI,MAAM,uCAAuC;AAAA,EACzD;AAEA,QAAM,SAAS,IAAI,YAAY,EAAE,OAAO,SAAS;AACjD,SAAO,IAAI,oBAAQ,EAAE,UAAU,CAAC,EAC7B,mBAAmB,EAAE,KAAK,QAAQ,CAAC,EACnC,YAAY,EACZ,kBAAkB,SAAS,EAC3B,KAAK,MAAM;AAChB;AAKA,eAAsB,kBACpB,OACA,WACqB;AACrB,MAAI,CAAC,SAAS,CAAC,WAAW;AACxB,UAAM,IAAI,MAAM,mCAAmC;AAAA,EACrD;AAEA,QAAM,SAAS,IAAI,YAAY,EAAE,OAAO,SAAS;AACjD,QAAM,EAAE,QAAQ,IAAI,UAAM,uBAAU,OAAO,QAAQ;AAAA,IACjD,YAAY,CAAC,OAAO;AAAA,EACtB,CAAC;AAED,MAAI,CAAC,QAAQ,aAAa,OAAO,QAAQ,cAAc,UAAU;AAC/D,UAAM,IAAI,MAAM,6CAA6C;AAAA,EAC/D;AAEA,SAAO;AAAA,IACL,WAAW,QAAQ;AAAA,IACnB,KAAK,QAAQ;AAAA,IACb,KAAK,QAAQ;AAAA,EACf;AACF;AAOO,SAAS,kBAAkB,OAA2B;AAC3D,MAAI,CAAC,OAAO;AACV,UAAM,IAAI,MAAM,oBAAoB;AAAA,EACtC;AAEA,QAAM,cAAU,uBAAU,KAAK;AAE/B,MAAI,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
- iat?: number;
6
- exp?: number;
7
- }
8
- /**
9
- * Creates a JWT token for server-side authentication.
10
- * The token is valid for 1 hour by default.
11
- */
12
- declare function createServerToken(clientKey: string, secretKey: string, expiresIn?: string): Promise<string>;
13
- /**
14
- * Verifies a JWT token and returns the payload.
15
- */
16
- declare function verifyServerToken(token: string, secretKey: string): Promise<JwtPayload>;
17
- /**
18
- * Decodes a JWT token without verification.
19
- * WARNING: Use this only when you need to inspect token contents.
20
- * Always use verifyServerToken for authentication.
21
- */
22
- declare function decodeServerToken(token: string): JwtPayload;
23
-
24
- /**
25
- * Creates a Base64-encoded API key from clientKey and secretKey.
26
- */
27
- declare function createApiKey(clientKey: string, secretKey: string): string;
28
- /**
29
- * Parses a Base64-encoded API key to extract clientKey and secretKey.
30
- */
31
- declare function parseApiKey(apiKey: string): {
32
- clientKey: string;
33
- secretKey: string;
34
- };
35
-
36
- export { type JwtPayload, createApiKey, createServerToken, decodeServerToken, parseApiKey, verifyServerToken };
package/dist/auth.d.ts DELETED
@@ -1,36 +0,0 @@
1
- import './payload-types-FfZ2Zxp1.js';
2
-
3
- interface JwtPayload {
4
- clientKey: string;
5
- iat?: number;
6
- exp?: number;
7
- }
8
- /**
9
- * Creates a JWT token for server-side authentication.
10
- * The token is valid for 1 hour by default.
11
- */
12
- declare function createServerToken(clientKey: string, secretKey: string, expiresIn?: string): Promise<string>;
13
- /**
14
- * Verifies a JWT token and returns the payload.
15
- */
16
- declare function verifyServerToken(token: string, secretKey: string): Promise<JwtPayload>;
17
- /**
18
- * Decodes a JWT token without verification.
19
- * WARNING: Use this only when you need to inspect token contents.
20
- * Always use verifyServerToken for authentication.
21
- */
22
- declare function decodeServerToken(token: string): JwtPayload;
23
-
24
- /**
25
- * Creates a Base64-encoded API key from clientKey and secretKey.
26
- */
27
- declare function createApiKey(clientKey: string, secretKey: string): string;
28
- /**
29
- * Parses a Base64-encoded API key to extract clientKey and secretKey.
30
- */
31
- declare function parseApiKey(apiKey: string): {
32
- clientKey: string;
33
- secretKey: string;
34
- };
35
-
36
- export { type JwtPayload, createApiKey, createServerToken, decodeServerToken, parseApiKey, verifyServerToken };
package/dist/auth.js DELETED
@@ -1,86 +0,0 @@
1
- // src/core/internal/utils/jwt.ts
2
- import { SignJWT, jwtVerify, decodeJwt } from "jose";
3
- async function createServerToken(clientKey, secretKey, expiresIn = "1h") {
4
- if (!clientKey || !secretKey) {
5
- throw new Error("clientKey and secretKey are required.");
6
- }
7
- const secret = new TextEncoder().encode(secretKey);
8
- return new SignJWT({ clientKey }).setProtectedHeader({ alg: "HS256" }).setIssuedAt().setExpirationTime(expiresIn).sign(secret);
9
- }
10
- async function verifyServerToken(token, secretKey) {
11
- if (!token || !secretKey) {
12
- throw new Error("token and secretKey are required.");
13
- }
14
- const secret = new TextEncoder().encode(secretKey);
15
- const { payload } = await jwtVerify(token, secret, {
16
- algorithms: ["HS256"]
17
- });
18
- if (!payload.clientKey || typeof payload.clientKey !== "string") {
19
- throw new Error("Invalid token payload: clientKey is missing");
20
- }
21
- return {
22
- clientKey: payload.clientKey,
23
- iat: payload.iat,
24
- exp: payload.exp
25
- };
26
- }
27
- function decodeServerToken(token) {
28
- if (!token) {
29
- throw new Error("token is required.");
30
- }
31
- const payload = decodeJwt(token);
32
- if (!payload.clientKey || typeof payload.clientKey !== "string") {
33
- throw new Error("Invalid token payload: clientKey is missing");
34
- }
35
- return {
36
- clientKey: payload.clientKey,
37
- iat: payload.iat,
38
- exp: payload.exp
39
- };
40
- }
41
-
42
- // src/core/internal/utils/encoding.ts
43
- function createApiKey(clientKey, secretKey) {
44
- if (!clientKey || !secretKey) {
45
- throw new Error("clientKey and secretKey are required.");
46
- }
47
- if (typeof Buffer !== "undefined") {
48
- return Buffer.from(`${clientKey}:${secretKey}`).toString("base64");
49
- }
50
- return btoa(`${clientKey}:${secretKey}`);
51
- }
52
- function parseApiKey(apiKey) {
53
- if (!apiKey) {
54
- throw new Error("apiKey is required.");
55
- }
56
- try {
57
- let decoded;
58
- if (typeof Buffer !== "undefined") {
59
- decoded = Buffer.from(apiKey, "base64").toString("utf-8");
60
- } else {
61
- decoded = atob(apiKey);
62
- }
63
- const colonIndex = decoded.indexOf(":");
64
- if (colonIndex === -1) {
65
- throw new Error("Invalid format: missing colon separator");
66
- }
67
- const clientKey = decoded.substring(0, colonIndex);
68
- const secretKey = decoded.substring(colonIndex + 1);
69
- if (!clientKey || !secretKey) {
70
- throw new Error("Invalid format: empty clientKey or secretKey");
71
- }
72
- return { clientKey, secretKey };
73
- } catch {
74
- throw new Error(
75
- 'Invalid API key. Expected Base64 encoded "clientKey:secretKey"'
76
- );
77
- }
78
- }
79
- export {
80
- createApiKey,
81
- createServerToken,
82
- decodeServerToken,
83
- parseApiKey,
84
- verifyServerToken
85
- };
86
- //# sourceMappingURL=auth.js.map
package/dist/auth.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/core/internal/utils/jwt.ts","../src/core/internal/utils/encoding.ts"],"sourcesContent":["import { SignJWT, jwtVerify, decodeJwt } from 'jose'\n\nexport interface JwtPayload {\n clientKey: string\n iat?: number\n exp?: number\n}\n\n/**\n * Creates a JWT token for server-side authentication.\n * The token is valid for 1 hour by default.\n */\nexport async function createServerToken(\n clientKey: string,\n secretKey: string,\n expiresIn: string = '1h',\n): Promise<string> {\n if (!clientKey || !secretKey) {\n throw new Error('clientKey and secretKey are required.')\n }\n\n const secret = new TextEncoder().encode(secretKey)\n return new SignJWT({ clientKey })\n .setProtectedHeader({ alg: 'HS256' })\n .setIssuedAt()\n .setExpirationTime(expiresIn)\n .sign(secret)\n}\n\n/**\n * Verifies a JWT token and returns the payload.\n */\nexport async function verifyServerToken(\n token: string,\n secretKey: string,\n): Promise<JwtPayload> {\n if (!token || !secretKey) {\n throw new Error('token and secretKey are required.')\n }\n\n const secret = new TextEncoder().encode(secretKey)\n const { payload } = await jwtVerify(token, secret, {\n algorithms: ['HS256'],\n })\n\n if (!payload.clientKey || typeof payload.clientKey !== 'string') {\n throw new Error('Invalid token payload: clientKey is missing')\n }\n\n return {\n clientKey: payload.clientKey as string,\n iat: payload.iat,\n exp: payload.exp,\n }\n}\n\n/**\n * Decodes a JWT token without verification.\n * WARNING: Use this only when you need to inspect token contents.\n * Always use verifyServerToken for authentication.\n */\nexport function decodeServerToken(token: string): JwtPayload {\n if (!token) {\n throw new Error('token is required.')\n }\n\n const payload = decodeJwt(token)\n\n if (!payload.clientKey || typeof payload.clientKey !== 'string') {\n throw new Error('Invalid token payload: clientKey is missing')\n }\n\n return {\n clientKey: payload.clientKey as string,\n iat: payload.iat,\n exp: payload.exp,\n }\n}\n","/**\n * Creates a Base64-encoded API key from clientKey and secretKey.\n */\nexport function createApiKey(clientKey: string, secretKey: string): string {\n if (!clientKey || !secretKey) {\n throw new Error('clientKey and secretKey are required.')\n }\n\n if (typeof Buffer !== 'undefined') {\n return Buffer.from(`${clientKey}:${secretKey}`).toString('base64')\n }\n return btoa(`${clientKey}:${secretKey}`)\n}\n\n/**\n * Parses a Base64-encoded API key to extract clientKey and secretKey.\n */\nexport function parseApiKey(apiKey: string): {\n clientKey: string\n secretKey: string\n} {\n if (!apiKey) {\n throw new Error('apiKey is required.')\n }\n\n try {\n let decoded: string\n if (typeof Buffer !== 'undefined') {\n decoded = Buffer.from(apiKey, 'base64').toString('utf-8')\n } else {\n decoded = atob(apiKey)\n }\n\n const colonIndex = decoded.indexOf(':')\n if (colonIndex === -1) {\n throw new Error('Invalid format: missing colon separator')\n }\n\n const clientKey = decoded.substring(0, colonIndex)\n const secretKey = decoded.substring(colonIndex + 1)\n\n if (!clientKey || !secretKey) {\n throw new Error('Invalid format: empty clientKey or secretKey')\n }\n\n return { clientKey, secretKey }\n } catch {\n throw new Error(\n 'Invalid API key. Expected Base64 encoded \"clientKey:secretKey\"',\n )\n }\n}\n"],"mappings":";AAAA,SAAS,SAAS,WAAW,iBAAiB;AAY9C,eAAsB,kBACpB,WACA,WACA,YAAoB,MACH;AACjB,MAAI,CAAC,aAAa,CAAC,WA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