@punch-in/strapi-admin 1.2.7 → 1.2.8

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.
@@ -4,6 +4,16 @@ const passport = require('koa-passport');
4
4
  const compose = require('koa-compose');
5
5
  const crypto = require('crypto');
6
6
  const axios = require('axios');
7
+ const { LambdaClient, InvokeCommand } = require('@aws-sdk/client-lambda');
8
+
9
+ // Tenant Lambdas run inside a VPC with no internet route (required for the
10
+ // EFS mount - see CLAUDE.md). Reaching the central stripe-charge Lambda
11
+ // therefore goes through the VPC Interface Endpoint for the Lambda service
12
+ // (infra/shared-networking-stack.yaml) via a direct SDK invoke, not HTTPS.
13
+ // See features/API-REDESIGN.md Phase 1. The SDK v3 client-lambda package is
14
+ // preinstalled by the Node.js 18+ Lambda managed runtime, so it does not
15
+ // need to be bundled in strapi-lambda-layer.
16
+ const lambdaClient = new LambdaClient({});
7
17
 
8
18
  const {
9
19
  validateRegistrationInput,
@@ -190,6 +200,14 @@ module.exports = {
190
200
  // against *this* tenant's admin_users - never creating one.
191
201
 
192
202
  async ssoProviders(ctx) {
203
+ // SSO_PROVIDERS_MODE=invoke is the new path (see features/API-REDESIGN.md
204
+ // Phase 1); anything else keeps the old HTTPS call so this can be rolled
205
+ // back per-tenant without a redeploy while the invoke path is verified.
206
+ if (process.env.SSO_PROVIDERS_MODE === 'invoke') {
207
+ ctx.body = await fetchSsoProvidersViaInvoke();
208
+ return;
209
+ }
210
+
193
211
  try {
194
212
  const { data } = await axios.get(`${getCentralApiBase()}/sso/auth/providers`, {
195
213
  timeout: 5000,
@@ -252,6 +270,38 @@ function getCentralApiBase() {
252
270
  return (process.env.PUNCHIN_INTEGRATIONS_API_BASE || 'https://api.punch-in.co.uk').replace(/\/$/, '');
253
271
  }
254
272
 
273
+ // SsoProvidersFunction (stripe-charge/template.yaml) is also wired behind
274
+ // API Gateway via sso.js, so its handler returns an API-Gateway-proxy-shaped
275
+ // object ({ statusCode, headers, body: JSON.stringify(...) }) rather than
276
+ // the raw provider array - that shape is unchanged whether API Gateway or a
277
+ // direct InvokeCommand calls it, so it has to be unwrapped here.
278
+ async function fetchSsoProvidersViaInvoke() {
279
+ const functionName = process.env.SSO_PROVIDERS_FUNCTION_NAME;
280
+ if (!functionName) {
281
+ strapi.log.error('SSO_PROVIDERS_FUNCTION_NAME is not configured');
282
+ return [];
283
+ }
284
+
285
+ try {
286
+ const response = await lambdaClient.send(
287
+ new InvokeCommand({
288
+ FunctionName: functionName,
289
+ InvocationType: 'RequestResponse',
290
+ })
291
+ );
292
+
293
+ if (response.FunctionError) {
294
+ throw new Error(`SsoProvidersFunction returned ${response.FunctionError}`);
295
+ }
296
+
297
+ const gatewayResponse = JSON.parse(Buffer.from(response.Payload).toString('utf8'));
298
+ return JSON.parse(gatewayResponse.body);
299
+ } catch (err) {
300
+ strapi.log.error(`Failed to invoke SsoProvidersFunction: ${err.message}`);
301
+ return [];
302
+ }
303
+ }
304
+
255
305
  function secretsMatch(provided, expected) {
256
306
  if (!provided || !expected) return false;
257
307
  const a = Buffer.from(provided);
package/package.json CHANGED
@@ -139,5 +139,5 @@
139
139
  "develop:ce": "STRAPI_DISABLE_EE=true webpack-dev-server --config webpack.config.dev.js",
140
140
  "test": "echo \"no tests yet\""
141
141
  },
142
- "version": "1.2.7"
142
+ "version": "1.2.8"
143
143
  }