@ampless/backend 1.0.0-alpha.53 → 1.0.0-alpha.55

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.
@@ -128,9 +128,9 @@ function createProcessorTrustedHandler(opts) {
128
128
  new QueryCommand({
129
129
  TableName: POST_TABLE,
130
130
  IndexName: POST_BY_STATUS_INDEX,
131
- KeyConditionExpression: "#status = :status",
132
- ExpressionAttributeNames: { "#status": "status" },
133
- ExpressionAttributeValues: { ":status": "published" },
131
+ KeyConditionExpression: "#status = :status AND #publishedAt <= :now",
132
+ ExpressionAttributeNames: { "#status": "status", "#publishedAt": "publishedAt" },
133
+ ExpressionAttributeValues: { ":status": "published", ":now": (/* @__PURE__ */ new Date()).toISOString() },
134
134
  ScanIndexForward: false,
135
135
  ExclusiveStartKey: exclusiveStartKey
136
136
  })
@@ -159,6 +159,13 @@ async function getPost(client, args) {
159
159
  const item = data.listPosts.items[0];
160
160
  return item ? toCorePost(item) : null;
161
161
  }
162
+ function normalizePublishedAt(value) {
163
+ const d = new Date(value);
164
+ if (Number.isNaN(d.getTime())) {
165
+ throw new Error(`Invalid publishedAt: "${value}" could not be parsed as a date`);
166
+ }
167
+ return d.toISOString();
168
+ }
162
169
  var MUTATION = (
163
170
  /* GraphQL */
164
171
  `
@@ -211,7 +218,7 @@ var createPostSchema = {
211
218
  async function createPost(client, args) {
212
219
  const postId = args.postId ?? `post-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
213
220
  const status = args.status ?? "draft";
214
- const publishedAt = args.publishedAt ?? (status === "published" ? (/* @__PURE__ */ new Date()).toISOString() : void 0);
221
+ const publishedAt = args.publishedAt !== void 0 ? normalizePublishedAt(args.publishedAt) : status === "published" ? (/* @__PURE__ */ new Date()).toISOString() : void 0;
215
222
  const data = await client.query(MUTATION, {
216
223
  input: {
217
224
  postId,
@@ -283,9 +290,17 @@ async function updatePost(client, args) {
283
290
  if (args.format !== void 0) input.format = args.format;
284
291
  if (args.body !== void 0) input.body = encodeAwsJson2(args.body);
285
292
  if (args.status !== void 0) input.status = args.status;
286
- if (args.publishedAt !== void 0) input.publishedAt = args.publishedAt;
293
+ if (args.publishedAt !== void 0) {
294
+ input.publishedAt = normalizePublishedAt(args.publishedAt);
295
+ }
287
296
  if (args.tags !== void 0) input.tags = args.tags;
288
297
  if (args.metadata !== void 0) input.metadata = encodeAwsJson2(args.metadata);
298
+ if (args.status === "published" && args.publishedAt === void 0) {
299
+ const existing = await getPost(client, { postId: args.postId });
300
+ if (existing && !existing.publishedAt) {
301
+ input.publishedAt = (/* @__PURE__ */ new Date()).toISOString();
302
+ }
303
+ }
289
304
  const data = await client.query(MUTATION2, { input });
290
305
  return toCorePost(data.updatePost);
291
306
  }
@@ -1256,11 +1271,17 @@ async function upsertStaticPost(graphql, slug, body, fields) {
1256
1271
  if (fields.title !== void 0) input2.title = fields.title;
1257
1272
  if (fields.excerpt !== void 0) input2.excerpt = fields.excerpt;
1258
1273
  if (fields.status !== void 0) input2.status = fields.status;
1259
- if (fields.publishedAt !== void 0) input2.publishedAt = fields.publishedAt;
1274
+ if (fields.publishedAt !== void 0) {
1275
+ input2.publishedAt = normalizePublishedAt(fields.publishedAt);
1276
+ }
1260
1277
  if (fields.tags !== void 0) input2.tags = fields.tags;
1261
1278
  if (fields.metadata !== void 0) {
1262
1279
  input2.metadata = encodeAwsJson4(fields.metadata);
1263
1280
  }
1281
+ const effectiveStatus = fields.status ?? existing.status;
1282
+ if (effectiveStatus === "published" && fields.publishedAt === void 0 && !existing.publishedAt) {
1283
+ input2.publishedAt = (/* @__PURE__ */ new Date()).toISOString();
1284
+ }
1264
1285
  const data2 = await graphql.query(UPDATE_MUTATION, { input: input2 });
1265
1286
  const updated = toCorePost(data2.updatePost);
1266
1287
  return { post: updated, created: false };
@@ -1271,7 +1292,7 @@ async function upsertStaticPost(graphql, slug, body, fields) {
1271
1292
  );
1272
1293
  }
1273
1294
  const status = fields.status ?? "draft";
1274
- const publishedAt = fields.publishedAt ?? (status === "published" ? (/* @__PURE__ */ new Date()).toISOString() : void 0);
1295
+ const publishedAt = fields.publishedAt !== void 0 ? normalizePublishedAt(fields.publishedAt) : status === "published" ? (/* @__PURE__ */ new Date()).toISOString() : void 0;
1275
1296
  const postId = fields.postId ?? `post-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
1276
1297
  const input = {
1277
1298
  postId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ampless/backend",
3
- "version": "1.0.0-alpha.53",
3
+ "version": "1.0.0-alpha.55",
4
4
  "description": "Amplify Gen 2 backend factories for ampless: auth, data, storage, event processors, API key renewer",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -69,8 +69,8 @@
69
69
  "@smithy/protocol-http": "^5.4.4",
70
70
  "@smithy/signature-v4": "^5.4.4",
71
71
  "fflate": "^0.8.3",
72
- "@ampless/mcp-server": "1.0.0-alpha.38",
73
- "ampless": "1.0.0-alpha.32"
72
+ "@ampless/mcp-server": "1.0.0-alpha.40",
73
+ "ampless": "1.0.0-alpha.34"
74
74
  },
75
75
  "peerDependencies": {
76
76
  "@aws-amplify/backend": "^1",