@headroom-cms/admin-api 0.1.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.
package/dist/auth.cjs ADDED
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/auth.ts
31
+ var auth_exports = {};
32
+ __export(auth_exports, {
33
+ authenticate: () => authenticate,
34
+ loadSSTConfig: () => loadSSTConfig
35
+ });
36
+ module.exports = __toCommonJS(auth_exports);
37
+ var import_meta = {};
38
+ async function authenticate(config) {
39
+ const { CognitoUserPool, CognitoUser, AuthenticationDetails } = await import("amazon-cognito-identity-js");
40
+ const pool = new CognitoUserPool({
41
+ UserPoolId: config.userPoolId,
42
+ ClientId: config.clientId
43
+ });
44
+ const user = new CognitoUser({ Username: config.username, Pool: pool });
45
+ const authDetails = new AuthenticationDetails({
46
+ Username: config.username,
47
+ Password: config.password
48
+ });
49
+ return new Promise((resolve, reject) => {
50
+ user.authenticateUser(authDetails, {
51
+ onSuccess: (session) => resolve(session.getAccessToken().getJwtToken()),
52
+ onFailure: (err) => reject(err),
53
+ newPasswordRequired: () => reject(new Error("Password change required"))
54
+ });
55
+ });
56
+ }
57
+ async function loadSSTConfig(outputsPath) {
58
+ const fs = await import("fs/promises");
59
+ const path = outputsPath ?? new URL("../../../.sst/outputs.json", import_meta.url).pathname;
60
+ const raw = await fs.readFile(path, "utf-8");
61
+ const outputs = JSON.parse(raw);
62
+ return {
63
+ userPoolId: outputs.userPoolId,
64
+ clientId: outputs.userPoolClientId,
65
+ apiUrl: outputs.api,
66
+ cdn: outputs.cdn
67
+ };
68
+ }
69
+ // Annotate the CommonJS export names for ESM import in node:
70
+ 0 && (module.exports = {
71
+ authenticate,
72
+ loadSSTConfig
73
+ });
@@ -0,0 +1,23 @@
1
+ interface AuthConfig {
2
+ userPoolId: string;
3
+ clientId: string;
4
+ username: string;
5
+ password: string;
6
+ }
7
+ interface SSTConfig {
8
+ userPoolId: string;
9
+ clientId: string;
10
+ apiUrl: string;
11
+ cdn: string;
12
+ }
13
+ /**
14
+ * Authenticate with Cognito using SRP (Secure Remote Password).
15
+ * Returns a JWT access token.
16
+ */
17
+ declare function authenticate(config: AuthConfig): Promise<string>;
18
+ /**
19
+ * Load SST outputs to get Cognito and API configuration.
20
+ */
21
+ declare function loadSSTConfig(outputsPath?: string): Promise<SSTConfig>;
22
+
23
+ export { type AuthConfig, type SSTConfig, authenticate, loadSSTConfig };
package/dist/auth.d.ts ADDED
@@ -0,0 +1,23 @@
1
+ interface AuthConfig {
2
+ userPoolId: string;
3
+ clientId: string;
4
+ username: string;
5
+ password: string;
6
+ }
7
+ interface SSTConfig {
8
+ userPoolId: string;
9
+ clientId: string;
10
+ apiUrl: string;
11
+ cdn: string;
12
+ }
13
+ /**
14
+ * Authenticate with Cognito using SRP (Secure Remote Password).
15
+ * Returns a JWT access token.
16
+ */
17
+ declare function authenticate(config: AuthConfig): Promise<string>;
18
+ /**
19
+ * Load SST outputs to get Cognito and API configuration.
20
+ */
21
+ declare function loadSSTConfig(outputsPath?: string): Promise<SSTConfig>;
22
+
23
+ export { type AuthConfig, type SSTConfig, authenticate, loadSSTConfig };
package/dist/auth.js ADDED
@@ -0,0 +1,36 @@
1
+ // src/auth.ts
2
+ async function authenticate(config) {
3
+ const { CognitoUserPool, CognitoUser, AuthenticationDetails } = await import("amazon-cognito-identity-js");
4
+ const pool = new CognitoUserPool({
5
+ UserPoolId: config.userPoolId,
6
+ ClientId: config.clientId
7
+ });
8
+ const user = new CognitoUser({ Username: config.username, Pool: pool });
9
+ const authDetails = new AuthenticationDetails({
10
+ Username: config.username,
11
+ Password: config.password
12
+ });
13
+ return new Promise((resolve, reject) => {
14
+ user.authenticateUser(authDetails, {
15
+ onSuccess: (session) => resolve(session.getAccessToken().getJwtToken()),
16
+ onFailure: (err) => reject(err),
17
+ newPasswordRequired: () => reject(new Error("Password change required"))
18
+ });
19
+ });
20
+ }
21
+ async function loadSSTConfig(outputsPath) {
22
+ const fs = await import("fs/promises");
23
+ const path = outputsPath ?? new URL("../../../.sst/outputs.json", import.meta.url).pathname;
24
+ const raw = await fs.readFile(path, "utf-8");
25
+ const outputs = JSON.parse(raw);
26
+ return {
27
+ userPoolId: outputs.userPoolId,
28
+ clientId: outputs.userPoolClientId,
29
+ apiUrl: outputs.api,
30
+ cdn: outputs.cdn
31
+ };
32
+ }
33
+ export {
34
+ authenticate,
35
+ loadSSTConfig
36
+ };