@ampless/runtime 1.0.0-alpha.41 → 1.0.0-alpha.42

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 (2) hide show
  1. package/dist/index.js +34 -22
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -24,8 +24,8 @@ function createStorage(outputs) {
24
24
  }
25
25
 
26
26
  // src/posts.ts
27
- import { cookies } from "next/headers";
28
- import { generateServerClientUsingCookies } from "@aws-amplify/adapter-nextjs/api";
27
+ import { generateServerClientUsingReqRes } from "@aws-amplify/adapter-nextjs/api";
28
+ import { createServerRunner } from "@aws-amplify/adapter-nextjs";
29
29
  import { decodeAwsJson } from "ampless";
30
30
  function decodeMetadata(value) {
31
31
  if (value === null || value === void 0) return void 0;
@@ -48,37 +48,44 @@ function toCorePost(p) {
48
48
  };
49
49
  }
50
50
  function createPostsApi(outputs) {
51
- const client = generateServerClientUsingCookies({
52
- // generateServerClientUsingCookies expects the resourcesConfig shape
53
- // — the full amplify_outputs.json satisfies it at runtime.
51
+ const { runWithAmplifyServerContext } = createServerRunner({
52
+ config: outputs
53
+ });
54
+ const client = generateServerClientUsingReqRes({
54
55
  config: outputs,
55
- cookies,
56
56
  authMode: "apiKey"
57
57
  });
58
58
  return {
59
59
  async listPublishedPosts(opts = {}) {
60
- const { data, errors } = await client.queries.listPublishedPosts({
61
- from: opts.from,
62
- to: opts.to,
63
- limit: opts.limit ?? 20,
64
- nextToken: opts.nextToken
60
+ const { data, errors } = await runWithAmplifyServerContext({
61
+ nextServerContext: null,
62
+ operation: (contextSpec) => client.queries.listPublishedPosts(contextSpec, {
63
+ from: opts.from,
64
+ to: opts.to,
65
+ limit: opts.limit ?? 20,
66
+ nextToken: opts.nextToken
67
+ })
65
68
  });
66
69
  if (errors) throw new Error(errors[0]?.message ?? "Failed to list posts");
67
70
  const items = (data?.items ?? []).filter((p) => p !== null).map(toCorePost);
68
71
  return { items, nextToken: data?.nextToken ?? null };
69
72
  },
70
73
  async getPublishedPost(slug) {
71
- const { data, errors } = await client.queries.getPublishedPost({
72
- slug
74
+ const { data, errors } = await runWithAmplifyServerContext({
75
+ nextServerContext: null,
76
+ operation: (contextSpec) => client.queries.getPublishedPost(contextSpec, { slug })
73
77
  });
74
78
  if (errors) throw new Error(errors[0]?.message ?? "Failed to get post");
75
79
  return data ? toCorePost(data) : null;
76
80
  },
77
81
  async listPostsByTag(tag, opts = {}) {
78
- const { data, errors } = await client.queries.listPostsByTag({
79
- tag,
80
- limit: opts.limit ?? 20,
81
- nextToken: opts.nextToken
82
+ const { data, errors } = await runWithAmplifyServerContext({
83
+ nextServerContext: null,
84
+ operation: (contextSpec) => client.queries.listPostsByTag(contextSpec, {
85
+ tag,
86
+ limit: opts.limit ?? 20,
87
+ nextToken: opts.nextToken
88
+ })
82
89
  });
83
90
  if (errors) throw new Error(errors[0]?.message ?? "Failed to list posts by tag");
84
91
  const items = (data?.items ?? []).filter((p) => p !== null).map(toCorePost);
@@ -88,8 +95,8 @@ function createPostsApi(outputs) {
88
95
  }
89
96
 
90
97
  // src/media.ts
91
- import { cookies as cookies2 } from "next/headers";
92
- import { generateServerClientUsingCookies as generateServerClientUsingCookies2 } from "@aws-amplify/adapter-nextjs/api";
98
+ import { generateServerClientUsingReqRes as generateServerClientUsingReqRes2 } from "@aws-amplify/adapter-nextjs/api";
99
+ import { createServerRunner as createServerRunner2 } from "@aws-amplify/adapter-nextjs";
93
100
  import { decodeAwsJson as decodeAwsJson2 } from "ampless";
94
101
  function decodeMediaMetadata(value) {
95
102
  if (value === null || value === void 0) return null;
@@ -100,15 +107,20 @@ function decodeMediaMetadata(value) {
100
107
  return null;
101
108
  }
102
109
  function createMediaApi(outputs) {
103
- const client = generateServerClientUsingCookies2({
110
+ const { runWithAmplifyServerContext } = createServerRunner2({
111
+ config: outputs
112
+ });
113
+ const client = generateServerClientUsingReqRes2({
104
114
  config: outputs,
105
- cookies: cookies2,
106
115
  authMode: "apiKey"
107
116
  });
108
117
  return {
109
118
  async getMediaBySrc(src) {
110
119
  try {
111
- const { data, errors } = await client.queries.getMediaBySrc({ src });
120
+ const { data, errors } = await runWithAmplifyServerContext({
121
+ nextServerContext: null,
122
+ operation: (contextSpec) => client.queries.getMediaBySrc(contextSpec, { src })
123
+ });
112
124
  if (errors && errors.length > 0) {
113
125
  console.error(
114
126
  `[media-api] getMediaBySrc errors for ${src}`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ampless/runtime",
3
- "version": "1.0.0-alpha.41",
3
+ "version": "1.0.0-alpha.42",
4
4
  "description": "Public-side runtime for ampless: post fetching, theme dispatch, middleware, public route handlers",
5
5
  "license": "MIT",
6
6
  "type": "module",