authscape 1.0.714 → 1.0.718

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.
@@ -0,0 +1,10 @@
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "Bash(dir:*)",
5
+ "Bash(npm run build:*)"
6
+ ],
7
+ "deny": [],
8
+ "ask": []
9
+ }
10
+ }
@@ -0,0 +1,215 @@
1
+ # AuthScape Sitemap Integration
2
+
3
+ Automatically generate and serve a sitemap.xml for your Next.js application using the AuthScape API.
4
+
5
+ ## Features
6
+
7
+ - Automatic sitemap.xml generation from your AuthScape API
8
+ - Server-side rendering for SEO optimization
9
+ - Automatic caching with stale-while-revalidate strategy
10
+ - Domain-aware (works with multi-tenant setups)
11
+ - Zero configuration required (uses existing AuthScape settings)
12
+
13
+ ## Quick Setup (2 minutes)
14
+
15
+ ### Step 1: Copy the Template File
16
+
17
+ Copy the sitemap template to your Next.js pages directory:
18
+
19
+ ```bash
20
+ # From your project root
21
+ cp node_modules/authscape/src/templates/sitemap.xml.js pages/sitemap.xml.js
22
+ ```
23
+
24
+ Or manually create `pages/sitemap.xml.js` with this content:
25
+
26
+ ```javascript
27
+ import { createSitemapHandler } from 'authscape/src/services/sitemapService';
28
+
29
+ export default function Sitemap() {
30
+ return null;
31
+ }
32
+
33
+ export const getServerSideProps = createSitemapHandler();
34
+ ```
35
+
36
+ ### Step 2: Ensure Environment Variable is Set
37
+
38
+ Make sure your `.env.local` file has the `apiUri` configured:
39
+
40
+ ```env
41
+ apiUri=https://your-authscape-api.com
42
+ ```
43
+
44
+ ### Step 3: Test It
45
+
46
+ Visit your sitemap in your browser:
47
+
48
+ ```
49
+ http://localhost:3000/sitemap.xml
50
+ ```
51
+
52
+ Or in production:
53
+
54
+ ```
55
+ https://yourdomain.com/sitemap.xml
56
+ ```
57
+
58
+ That's it! Your sitemap is now live and automatically updating.
59
+
60
+ ## How It Works
61
+
62
+ 1. When a user requests `/sitemap.xml`, Next.js calls the `getServerSideProps` function
63
+ 2. The sitemap service extracts the current domain from the request headers
64
+ 3. It calls your AuthScape API at `/api/Sitemap?domain={yourdomain}`
65
+ 4. The API returns the sitemap XML based on your content
66
+ 5. The response is cached for 24 hours with stale-while-revalidate
67
+
68
+ ## Advanced Usage
69
+
70
+ ### Custom API URI
71
+
72
+ If you need to override the API URI for a specific environment:
73
+
74
+ ```javascript
75
+ import { createSitemapHandler } from 'authscape/src/services/sitemapService';
76
+
77
+ export default function Sitemap() {
78
+ return null;
79
+ }
80
+
81
+ // Override the API URI
82
+ export const getServerSideProps = createSitemapHandler('https://custom-api.com');
83
+ ```
84
+
85
+ ### Manual Control
86
+
87
+ If you need more control over the sitemap generation:
88
+
89
+ ```javascript
90
+ import { generateSitemap } from 'authscape/src/services/sitemapService';
91
+
92
+ export default function Sitemap() {
93
+ return null;
94
+ }
95
+
96
+ export async function getServerSideProps({ req, res }) {
97
+ const apiUri = process.env.apiUri;
98
+
99
+ // Add custom logic here
100
+ console.log('Generating sitemap for:', req.headers.host);
101
+
102
+ // Call the sitemap generator
103
+ return await generateSitemap(req, res, apiUri);
104
+ }
105
+ ```
106
+
107
+ ### Custom Cache Headers
108
+
109
+ To change the cache duration, modify the response headers:
110
+
111
+ ```javascript
112
+ import { generateSitemap } from 'authscape/src/services/sitemapService';
113
+
114
+ export default function Sitemap() {
115
+ return null;
116
+ }
117
+
118
+ export async function getServerSideProps({ req, res }) {
119
+ const result = await generateSitemap(req, res, process.env.apiUri);
120
+
121
+ // Override cache to 1 hour instead of 24 hours
122
+ res.setHeader('Cache-Control', 'public, s-maxage=3600, stale-while-revalidate');
123
+
124
+ return result;
125
+ }
126
+ ```
127
+
128
+ ## Multi-Tenant Support
129
+
130
+ The sitemap service automatically detects the current domain from the request headers, making it work seamlessly with AuthScape's multi-tenant features. Each domain will receive its own sitemap based on the content configured in the AuthScape API.
131
+
132
+ ## Troubleshooting
133
+
134
+ ### Sitemap returns 500 error
135
+
136
+ - Check that `process.env.apiUri` is properly configured
137
+ - Verify your AuthScape API is accessible
138
+ - Check the server logs for the error message
139
+
140
+ ### Sitemap is empty
141
+
142
+ - Verify your AuthScape API returns valid sitemap data at `/api/Sitemap?domain={yourdomain}`
143
+ - Test the API endpoint directly in your browser or Postman
144
+
145
+ ### Sitemap not updating
146
+
147
+ - The sitemap is cached for 24 hours by default
148
+ - Clear your browser cache or use incognito mode
149
+ - Modify the cache headers to a shorter duration during development
150
+
151
+ ## API Reference
152
+
153
+ ### `createSitemapHandler(apiUri?)`
154
+
155
+ Creates a `getServerSideProps` function configured for sitemap generation.
156
+
157
+ **Parameters:**
158
+ - `apiUri` (string, optional): Override the API URI. Defaults to `process.env.apiUri`
159
+
160
+ **Returns:**
161
+ - Function: A `getServerSideProps` function
162
+
163
+ **Example:**
164
+ ```javascript
165
+ export const getServerSideProps = createSitemapHandler();
166
+ ```
167
+
168
+ ### `generateSitemap(req, res, apiUri)`
169
+
170
+ Lower-level function for generating sitemaps with custom logic.
171
+
172
+ **Parameters:**
173
+ - `req` (NextApiRequest): Next.js request object
174
+ - `res` (NextApiResponse): Next.js response object
175
+ - `apiUri` (string): The AuthScape API base URI
176
+
177
+ **Returns:**
178
+ - Promise<{ props: {} }>: Next.js getServerSideProps return value
179
+
180
+ **Example:**
181
+ ```javascript
182
+ export async function getServerSideProps({ req, res }) {
183
+ return await generateSitemap(req, res, process.env.apiUri);
184
+ }
185
+ ```
186
+
187
+ ## SEO Benefits
188
+
189
+ Having a sitemap.xml provides several SEO benefits:
190
+
191
+ 1. **Faster Indexing**: Search engines discover your content faster
192
+ 2. **Complete Coverage**: Ensures all pages are found, even if not linked
193
+ 3. **Priority Signals**: Can indicate which pages are most important
194
+ 4. **Change Frequency**: Signals how often content is updated
195
+ 5. **Multi-lingual Support**: Can include alternate language versions
196
+
197
+ ## Integration with robots.txt
198
+
199
+ Don't forget to reference your sitemap in your `robots.txt` file:
200
+
201
+ Create `public/robots.txt`:
202
+
203
+ ```txt
204
+ User-agent: *
205
+ Allow: /
206
+
207
+ Sitemap: https://yourdomain.com/sitemap.xml
208
+ ```
209
+
210
+ ## Support
211
+
212
+ For issues or questions:
213
+ - Check the [AuthScape Documentation](https://authscape.com/docs)
214
+ - Contact AuthScape Support
215
+ - Review the source code in `node_modules/authscape/src/services/sitemapService.js`
package/index.js CHANGED
@@ -9284,6 +9284,138 @@ var signInValidator = exports.signInValidator = /*#__PURE__*/function () {
9284
9284
  }();
9285
9285
  "use strict";
9286
9286
 
9287
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
9288
+ Object.defineProperty(exports, "__esModule", {
9289
+ value: true
9290
+ });
9291
+ exports.createSitemapHandler = createSitemapHandler;
9292
+ exports["default"] = void 0;
9293
+ exports.generateSitemap = generateSitemap;
9294
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
9295
+ function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
9296
+ function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
9297
+ /**
9298
+ * AuthScape Sitemap Service
9299
+ * Provides automatic sitemap.xml generation by fetching from AuthScape API
9300
+ */
9301
+ /**
9302
+ * Generates a sitemap XML response by fetching from the AuthScape API
9303
+ * @param {Object} req - Next.js request object
9304
+ * @param {Object} res - Next.js response object
9305
+ * @param {string} apiUri - The AuthScape API base URI (from process.env.apiUri)
9306
+ * @returns {Promise<void>}
9307
+ */
9308
+ function generateSitemap(_x, _x2, _x3) {
9309
+ return _generateSitemap.apply(this, arguments);
9310
+ }
9311
+ /**
9312
+ * Higher-order function that returns a getServerSideProps function
9313
+ * configured with the API URI from environment variables
9314
+ *
9315
+ * @param {string} apiUri - Optional API URI override (defaults to process.env.apiUri)
9316
+ * @returns {Function} getServerSideProps function
9317
+ */
9318
+ function _generateSitemap() {
9319
+ _generateSitemap = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(req, res, apiUri) {
9320
+ var protocol, host, domain, encodedDomain, response, sitemap;
9321
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
9322
+ while (1) switch (_context2.prev = _context2.next) {
9323
+ case 0:
9324
+ _context2.prev = 0;
9325
+ // Get the domain from the request
9326
+ protocol = req.headers['x-forwarded-proto'] || 'http';
9327
+ host = req.headers.host;
9328
+ domain = "".concat(protocol, "://").concat(host); // URL encode the domain for the API request
9329
+ encodedDomain = encodeURIComponent(domain); // Make a basic HTTP GET request to AuthScape API
9330
+ _context2.next = 7;
9331
+ return fetch("".concat(apiUri, "/api/Sitemap?domain=").concat(encodedDomain));
9332
+ case 7:
9333
+ response = _context2.sent;
9334
+ if (response.ok) {
9335
+ _context2.next = 10;
9336
+ break;
9337
+ }
9338
+ throw new Error("API request failed with status ".concat(response.status));
9339
+ case 10:
9340
+ _context2.next = 12;
9341
+ return response.text();
9342
+ case 12:
9343
+ sitemap = _context2.sent;
9344
+ // Set the appropriate headers for XML
9345
+ res.setHeader('Content-Type', 'text/xml; charset=utf-8');
9346
+ res.setHeader('Cache-Control', 'public, s-maxage=86400, stale-while-revalidate');
9347
+
9348
+ // Send the XML response
9349
+ res.write(sitemap);
9350
+ res.end();
9351
+ return _context2.abrupt("return", {
9352
+ props: {}
9353
+ });
9354
+ case 20:
9355
+ _context2.prev = 20;
9356
+ _context2.t0 = _context2["catch"](0);
9357
+ console.error('AuthScape Sitemap Error:', _context2.t0);
9358
+
9359
+ // Return 500 error
9360
+ res.statusCode = 500;
9361
+ res.setHeader('Content-Type', 'text/plain');
9362
+ res.write('Error generating sitemap');
9363
+ res.end();
9364
+ return _context2.abrupt("return", {
9365
+ props: {}
9366
+ });
9367
+ case 28:
9368
+ case "end":
9369
+ return _context2.stop();
9370
+ }
9371
+ }, _callee2, null, [[0, 20]]);
9372
+ }));
9373
+ return _generateSitemap.apply(this, arguments);
9374
+ }
9375
+ function createSitemapHandler(apiUri) {
9376
+ return /*#__PURE__*/function () {
9377
+ var _getServerSideProps = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
9378
+ var req, res, apiBaseUri;
9379
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
9380
+ while (1) switch (_context.prev = _context.next) {
9381
+ case 0:
9382
+ req = _ref.req, res = _ref.res;
9383
+ apiBaseUri = apiUri || process.env.apiUri;
9384
+ if (apiBaseUri) {
9385
+ _context.next = 9;
9386
+ break;
9387
+ }
9388
+ console.error('AuthScape Sitemap Error: apiUri is not configured');
9389
+ res.statusCode = 500;
9390
+ res.setHeader('Content-Type', 'text/plain');
9391
+ res.write('Sitemap configuration error: API URI not set');
9392
+ res.end();
9393
+ return _context.abrupt("return", {
9394
+ props: {}
9395
+ });
9396
+ case 9:
9397
+ _context.next = 11;
9398
+ return generateSitemap(req, res, apiBaseUri);
9399
+ case 11:
9400
+ return _context.abrupt("return", _context.sent);
9401
+ case 12:
9402
+ case "end":
9403
+ return _context.stop();
9404
+ }
9405
+ }, _callee);
9406
+ }));
9407
+ function getServerSideProps(_x4) {
9408
+ return _getServerSideProps.apply(this, arguments);
9409
+ }
9410
+ return getServerSideProps;
9411
+ }();
9412
+ }
9413
+ var _default = exports["default"] = {
9414
+ generateSitemap: generateSitemap,
9415
+ createSitemapHandler: createSitemapHandler
9416
+ };
9417
+ "use strict";
9418
+
9287
9419
  Object.defineProperty(exports, "__esModule", {
9288
9420
  value: true
9289
9421
  });
@@ -9360,3 +9492,33 @@ var setCookie = exports.setCookie = function setCookie(name, value) {
9360
9492
  resolve();
9361
9493
  });
9362
9494
  };
9495
+ "use strict";
9496
+
9497
+ Object.defineProperty(exports, "__esModule", {
9498
+ value: true
9499
+ });
9500
+ exports["default"] = Sitemap;
9501
+ exports.getServerSideProps = void 0;
9502
+ var _sitemapService = require("authscape/src/services/sitemapService");
9503
+ /**
9504
+ * AuthScape Sitemap.xml Template
9505
+ *
9506
+ * USAGE:
9507
+ * Copy this file to your Next.js pages directory as: pages/sitemap.xml.js
9508
+ *
9509
+ * The sitemap will automatically be generated and available at:
9510
+ * https://yourdomain.com/sitemap.xml
9511
+ *
9512
+ * CONFIGURATION:
9513
+ * Ensure process.env.apiUri is set in your .env.local file:
9514
+ * apiUri=https://your-authscape-api.com
9515
+ */
9516
+
9517
+ function Sitemap() {
9518
+ // This component will never render - sitemap is generated server-side
9519
+ return null;
9520
+ }
9521
+
9522
+ // Export the pre-configured sitemap handler
9523
+ // It will automatically use process.env.apiUri from your environment
9524
+ var getServerSideProps = exports.getServerSideProps = (0, _sitemapService.createSitemapHandler)();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "authscape",
3
- "version": "1.0.714",
3
+ "version": "1.0.718",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,86 @@
1
+ /**
2
+ * AuthScape Sitemap Service
3
+ * Provides automatic sitemap.xml generation by fetching from AuthScape API
4
+ */
5
+
6
+ /**
7
+ * Generates a sitemap XML response by fetching from the AuthScape API
8
+ * @param {Object} req - Next.js request object
9
+ * @param {Object} res - Next.js response object
10
+ * @param {string} apiUri - The AuthScape API base URI (from process.env.apiUri)
11
+ * @returns {Promise<void>}
12
+ */
13
+ export async function generateSitemap(req, res, apiUri) {
14
+ try {
15
+ // Get the domain from the request
16
+ const protocol = req.headers['x-forwarded-proto'] || 'http';
17
+ const host = req.headers.host;
18
+ const domain = `${protocol}://${host}`;
19
+
20
+ // URL encode the domain for the API request
21
+ const encodedDomain = encodeURIComponent(domain);
22
+
23
+ // Make a basic HTTP GET request to AuthScape API
24
+ const response = await fetch(`${apiUri}/api/Sitemap?domain=${encodedDomain}`);
25
+
26
+ if (!response.ok) {
27
+ throw new Error(`API request failed with status ${response.status}`);
28
+ }
29
+
30
+ // Get the sitemap XML from the API
31
+ const sitemap = await response.text();
32
+
33
+ // Set the appropriate headers for XML
34
+ res.setHeader('Content-Type', 'text/xml; charset=utf-8');
35
+ res.setHeader('Cache-Control', 'public, s-maxage=86400, stale-while-revalidate');
36
+
37
+ // Send the XML response
38
+ res.write(sitemap);
39
+ res.end();
40
+
41
+ return {
42
+ props: {},
43
+ };
44
+ } catch (error) {
45
+ console.error('AuthScape Sitemap Error:', error);
46
+
47
+ // Return 500 error
48
+ res.statusCode = 500;
49
+ res.setHeader('Content-Type', 'text/plain');
50
+ res.write('Error generating sitemap');
51
+ res.end();
52
+
53
+ return {
54
+ props: {},
55
+ };
56
+ }
57
+ }
58
+
59
+ /**
60
+ * Higher-order function that returns a getServerSideProps function
61
+ * configured with the API URI from environment variables
62
+ *
63
+ * @param {string} apiUri - Optional API URI override (defaults to process.env.apiUri)
64
+ * @returns {Function} getServerSideProps function
65
+ */
66
+ export function createSitemapHandler(apiUri) {
67
+ return async function getServerSideProps({ req, res }) {
68
+ const apiBaseUri = apiUri || process.env.apiUri;
69
+
70
+ if (!apiBaseUri) {
71
+ console.error('AuthScape Sitemap Error: apiUri is not configured');
72
+ res.statusCode = 500;
73
+ res.setHeader('Content-Type', 'text/plain');
74
+ res.write('Sitemap configuration error: API URI not set');
75
+ res.end();
76
+ return { props: {} };
77
+ }
78
+
79
+ return await generateSitemap(req, res, apiBaseUri);
80
+ };
81
+ }
82
+
83
+ export default {
84
+ generateSitemap,
85
+ createSitemapHandler
86
+ };
@@ -0,0 +1,24 @@
1
+ /**
2
+ * AuthScape Sitemap.xml Template
3
+ *
4
+ * USAGE:
5
+ * Copy this file to your Next.js pages directory as: pages/sitemap.xml.js
6
+ *
7
+ * The sitemap will automatically be generated and available at:
8
+ * https://yourdomain.com/sitemap.xml
9
+ *
10
+ * CONFIGURATION:
11
+ * Ensure process.env.apiUri is set in your .env.local file:
12
+ * apiUri=https://your-authscape-api.com
13
+ */
14
+
15
+ import { createSitemapHandler } from 'authscape/src/services/sitemapService';
16
+
17
+ export default function Sitemap() {
18
+ // This component will never render - sitemap is generated server-side
19
+ return null;
20
+ }
21
+
22
+ // Export the pre-configured sitemap handler
23
+ // It will automatically use process.env.apiUri from your environment
24
+ export const getServerSideProps = createSitemapHandler();