@aws-amplify/api-graphql 0.0.0-unstable-1ca644b-20260128091132

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 (257) hide show
  1. package/README.md +3 -0
  2. package/dist/cjs/GraphQLAPI.js +66 -0
  3. package/dist/cjs/GraphQLAPI.js.map +1 -0
  4. package/dist/cjs/Providers/AWSAppSyncEventsProvider/index.js +117 -0
  5. package/dist/cjs/Providers/AWSAppSyncEventsProvider/index.js.map +1 -0
  6. package/dist/cjs/Providers/AWSAppSyncRealTimeProvider/index.js +96 -0
  7. package/dist/cjs/Providers/AWSAppSyncRealTimeProvider/index.js.map +1 -0
  8. package/dist/cjs/Providers/AWSWebSocketProvider/appsyncUrl.js +113 -0
  9. package/dist/cjs/Providers/AWSWebSocketProvider/appsyncUrl.js.map +1 -0
  10. package/dist/cjs/Providers/AWSWebSocketProvider/authHeaders.js +99 -0
  11. package/dist/cjs/Providers/AWSWebSocketProvider/authHeaders.js.map +1 -0
  12. package/dist/cjs/Providers/AWSWebSocketProvider/index.js +693 -0
  13. package/dist/cjs/Providers/AWSWebSocketProvider/index.js.map +1 -0
  14. package/dist/cjs/Providers/constants.js +149 -0
  15. package/dist/cjs/Providers/constants.js.map +1 -0
  16. package/dist/cjs/index.js +18 -0
  17. package/dist/cjs/index.js.map +1 -0
  18. package/dist/cjs/internals/InternalGraphQLAPI.js +269 -0
  19. package/dist/cjs/internals/InternalGraphQLAPI.js.map +1 -0
  20. package/dist/cjs/internals/events/appsyncRequest.js +96 -0
  21. package/dist/cjs/internals/events/appsyncRequest.js.map +1 -0
  22. package/dist/cjs/internals/events/index.js +142 -0
  23. package/dist/cjs/internals/events/index.js.map +1 -0
  24. package/dist/cjs/internals/events/types.js +6 -0
  25. package/dist/cjs/internals/events/types.js.map +1 -0
  26. package/dist/cjs/internals/events/utils.js +57 -0
  27. package/dist/cjs/internals/events/utils.js.map +1 -0
  28. package/dist/cjs/internals/generateClient.js +86 -0
  29. package/dist/cjs/internals/generateClient.js.map +1 -0
  30. package/dist/cjs/internals/graphqlAuth.js +63 -0
  31. package/dist/cjs/internals/graphqlAuth.js.map +1 -0
  32. package/dist/cjs/internals/graphqlRequest.js +19 -0
  33. package/dist/cjs/internals/graphqlRequest.js.map +1 -0
  34. package/dist/cjs/internals/index.js +16 -0
  35. package/dist/cjs/internals/index.js.map +1 -0
  36. package/dist/cjs/internals/server/generateClientWithAmplifyInstance.js +48 -0
  37. package/dist/cjs/internals/server/generateClientWithAmplifyInstance.js.map +1 -0
  38. package/dist/cjs/internals/server/index.js +9 -0
  39. package/dist/cjs/internals/server/index.js.map +1 -0
  40. package/dist/cjs/internals/types.js +4 -0
  41. package/dist/cjs/internals/types.js.map +1 -0
  42. package/dist/cjs/internals/utils/runtimeTypeGuards/isApiGraphQLProviderConfig.js +10 -0
  43. package/dist/cjs/internals/utils/runtimeTypeGuards/isApiGraphQLProviderConfig.js.map +1 -0
  44. package/dist/cjs/internals/utils/runtimeTypeGuards/isConfigureEventWithResourceConfig.js +10 -0
  45. package/dist/cjs/internals/utils/runtimeTypeGuards/isConfigureEventWithResourceConfig.js.map +1 -0
  46. package/dist/cjs/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.js +14 -0
  47. package/dist/cjs/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.js.map +1 -0
  48. package/dist/cjs/internals/v6.js +155 -0
  49. package/dist/cjs/internals/v6.js.map +1 -0
  50. package/dist/cjs/server/generateClient.js +42 -0
  51. package/dist/cjs/server/generateClient.js.map +1 -0
  52. package/dist/cjs/server/index.js +9 -0
  53. package/dist/cjs/server/index.js.map +1 -0
  54. package/dist/cjs/types/PubSub.js +49 -0
  55. package/dist/cjs/types/PubSub.js.map +1 -0
  56. package/dist/cjs/types/index.js +34 -0
  57. package/dist/cjs/types/index.js.map +1 -0
  58. package/dist/cjs/utils/ConnectionStateMonitor.js +134 -0
  59. package/dist/cjs/utils/ConnectionStateMonitor.js.map +1 -0
  60. package/dist/cjs/utils/ReachabilityMonitor/index.js +10 -0
  61. package/dist/cjs/utils/ReachabilityMonitor/index.js.map +1 -0
  62. package/dist/cjs/utils/ReachabilityMonitor/index.native.js +12 -0
  63. package/dist/cjs/utils/ReachabilityMonitor/index.native.js.map +1 -0
  64. package/dist/cjs/utils/ReconnectionMonitor.js +71 -0
  65. package/dist/cjs/utils/ReconnectionMonitor.js.map +1 -0
  66. package/dist/cjs/utils/errors/GraphQLApiError.js +21 -0
  67. package/dist/cjs/utils/errors/GraphQLApiError.js.map +1 -0
  68. package/dist/cjs/utils/errors/assertValidationError.js +18 -0
  69. package/dist/cjs/utils/errors/assertValidationError.js.map +1 -0
  70. package/dist/cjs/utils/errors/constants.js +47 -0
  71. package/dist/cjs/utils/errors/constants.js.map +1 -0
  72. package/dist/cjs/utils/errors/createGraphQLResultWithError.js +15 -0
  73. package/dist/cjs/utils/errors/createGraphQLResultWithError.js.map +1 -0
  74. package/dist/cjs/utils/errors/index.js +16 -0
  75. package/dist/cjs/utils/errors/index.js.map +1 -0
  76. package/dist/cjs/utils/errors/repackageAuthError.js +38 -0
  77. package/dist/cjs/utils/errors/repackageAuthError.js.map +1 -0
  78. package/dist/cjs/utils/errors/validation.js +28 -0
  79. package/dist/cjs/utils/errors/validation.js.map +1 -0
  80. package/dist/cjs/utils/index.js +11 -0
  81. package/dist/cjs/utils/index.js.map +1 -0
  82. package/dist/cjs/utils/resolveConfig.js +32 -0
  83. package/dist/cjs/utils/resolveConfig.js.map +1 -0
  84. package/dist/cjs/utils/resolveLibraryOptions.js +16 -0
  85. package/dist/cjs/utils/resolveLibraryOptions.js.map +1 -0
  86. package/dist/esm/GraphQLAPI.d.ts +37 -0
  87. package/dist/esm/GraphQLAPI.mjs +63 -0
  88. package/dist/esm/GraphQLAPI.mjs.map +1 -0
  89. package/dist/esm/Providers/AWSAppSyncEventsProvider/index.d.ts +49 -0
  90. package/dist/esm/Providers/AWSAppSyncEventsProvider/index.mjs +115 -0
  91. package/dist/esm/Providers/AWSAppSyncEventsProvider/index.mjs.map +1 -0
  92. package/dist/esm/Providers/AWSAppSyncRealTimeProvider/index.d.ts +47 -0
  93. package/dist/esm/Providers/AWSAppSyncRealTimeProvider/index.mjs +94 -0
  94. package/dist/esm/Providers/AWSAppSyncRealTimeProvider/index.mjs.map +1 -0
  95. package/dist/esm/Providers/AWSWebSocketProvider/appsyncUrl.d.ts +21 -0
  96. package/dist/esm/Providers/AWSWebSocketProvider/appsyncUrl.mjs +107 -0
  97. package/dist/esm/Providers/AWSWebSocketProvider/appsyncUrl.mjs.map +1 -0
  98. package/dist/esm/Providers/AWSWebSocketProvider/authHeaders.d.ts +8 -0
  99. package/dist/esm/Providers/AWSWebSocketProvider/authHeaders.mjs +97 -0
  100. package/dist/esm/Providers/AWSWebSocketProvider/authHeaders.mjs.map +1 -0
  101. package/dist/esm/Providers/AWSWebSocketProvider/index.d.ts +99 -0
  102. package/dist/esm/Providers/AWSWebSocketProvider/index.mjs +691 -0
  103. package/dist/esm/Providers/AWSWebSocketProvider/index.mjs.map +1 -0
  104. package/dist/esm/Providers/constants.d.ts +135 -0
  105. package/dist/esm/Providers/constants.mjs +147 -0
  106. package/dist/esm/Providers/constants.mjs.map +1 -0
  107. package/dist/esm/index.d.ts +6 -0
  108. package/dist/esm/index.mjs +7 -0
  109. package/dist/esm/index.mjs.map +1 -0
  110. package/dist/esm/internals/InternalGraphQLAPI.d.ts +45 -0
  111. package/dist/esm/internals/InternalGraphQLAPI.mjs +270 -0
  112. package/dist/esm/internals/InternalGraphQLAPI.mjs.map +1 -0
  113. package/dist/esm/internals/events/appsyncRequest.d.ts +14 -0
  114. package/dist/esm/internals/events/appsyncRequest.mjs +96 -0
  115. package/dist/esm/internals/events/appsyncRequest.mjs.map +1 -0
  116. package/dist/esm/internals/events/index.d.ts +58 -0
  117. package/dist/esm/internals/events/index.mjs +139 -0
  118. package/dist/esm/internals/events/index.mjs.map +1 -0
  119. package/dist/esm/internals/events/types.d.ts +93 -0
  120. package/dist/esm/internals/events/types.mjs +2 -0
  121. package/dist/esm/internals/events/types.mjs.map +1 -0
  122. package/dist/esm/internals/events/utils.d.ts +16 -0
  123. package/dist/esm/internals/events/utils.mjs +53 -0
  124. package/dist/esm/internals/events/utils.mjs.map +1 -0
  125. package/dist/esm/internals/generateClient.d.ts +12 -0
  126. package/dist/esm/internals/generateClient.mjs +85 -0
  127. package/dist/esm/internals/generateClient.mjs.map +1 -0
  128. package/dist/esm/internals/graphqlAuth.d.ts +3 -0
  129. package/dist/esm/internals/graphqlAuth.mjs +64 -0
  130. package/dist/esm/internals/graphqlAuth.mjs.map +1 -0
  131. package/dist/esm/internals/graphqlRequest.d.ts +3 -0
  132. package/dist/esm/internals/graphqlRequest.mjs +18 -0
  133. package/dist/esm/internals/graphqlRequest.mjs.map +1 -0
  134. package/dist/esm/internals/index.d.ts +4 -0
  135. package/dist/esm/internals/index.mjs +4 -0
  136. package/dist/esm/internals/index.mjs.map +1 -0
  137. package/dist/esm/internals/server/generateClientWithAmplifyInstance.d.ts +13 -0
  138. package/dist/esm/internals/server/generateClientWithAmplifyInstance.mjs +61 -0
  139. package/dist/esm/internals/server/generateClientWithAmplifyInstance.mjs.map +1 -0
  140. package/dist/esm/internals/server/index.d.ts +1 -0
  141. package/dist/esm/internals/server/index.mjs +2 -0
  142. package/dist/esm/internals/server/index.mjs.map +1 -0
  143. package/dist/esm/internals/types.d.ts +34 -0
  144. package/dist/esm/internals/types.mjs +2 -0
  145. package/dist/esm/internals/types.mjs.map +1 -0
  146. package/dist/esm/internals/utils/runtimeTypeGuards/isApiGraphQLProviderConfig.d.ts +2 -0
  147. package/dist/esm/internals/utils/runtimeTypeGuards/isApiGraphQLProviderConfig.mjs +8 -0
  148. package/dist/esm/internals/utils/runtimeTypeGuards/isApiGraphQLProviderConfig.mjs.map +1 -0
  149. package/dist/esm/internals/utils/runtimeTypeGuards/isConfigureEventWithResourceConfig.d.ts +8 -0
  150. package/dist/esm/internals/utils/runtimeTypeGuards/isConfigureEventWithResourceConfig.mjs +8 -0
  151. package/dist/esm/internals/utils/runtimeTypeGuards/isConfigureEventWithResourceConfig.mjs.map +1 -0
  152. package/dist/esm/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.d.ts +2 -0
  153. package/dist/esm/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.mjs +12 -0
  154. package/dist/esm/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.mjs.map +1 -0
  155. package/dist/esm/internals/v6.d.ts +100 -0
  156. package/dist/esm/internals/v6.mjs +152 -0
  157. package/dist/esm/internals/v6.mjs.map +1 -0
  158. package/dist/esm/server/generateClient.d.ts +21 -0
  159. package/dist/esm/server/generateClient.mjs +41 -0
  160. package/dist/esm/server/generateClient.mjs.map +1 -0
  161. package/dist/esm/server/index.d.ts +1 -0
  162. package/dist/esm/server/index.mjs +2 -0
  163. package/dist/esm/server/index.mjs.map +1 -0
  164. package/dist/esm/types/PubSub.d.ts +27 -0
  165. package/dist/esm/types/PubSub.mjs +47 -0
  166. package/dist/esm/types/PubSub.mjs.map +1 -0
  167. package/dist/esm/types/index.d.ts +369 -0
  168. package/dist/esm/types/index.mjs +30 -0
  169. package/dist/esm/types/index.mjs.map +1 -0
  170. package/dist/esm/utils/ConnectionStateMonitor.d.ts +69 -0
  171. package/dist/esm/utils/ConnectionStateMonitor.mjs +132 -0
  172. package/dist/esm/utils/ConnectionStateMonitor.mjs.map +1 -0
  173. package/dist/esm/utils/ReachabilityMonitor/index.d.ts +1 -0
  174. package/dist/esm/utils/ReachabilityMonitor/index.mjs +8 -0
  175. package/dist/esm/utils/ReachabilityMonitor/index.mjs.map +1 -0
  176. package/dist/esm/utils/ReachabilityMonitor/index.native.d.ts +1 -0
  177. package/dist/esm/utils/ReachabilityMonitor/index.native.mjs +9 -0
  178. package/dist/esm/utils/ReachabilityMonitor/index.native.mjs.map +1 -0
  179. package/dist/esm/utils/ReconnectionMonitor.d.ts +29 -0
  180. package/dist/esm/utils/ReconnectionMonitor.mjs +69 -0
  181. package/dist/esm/utils/ReconnectionMonitor.mjs.map +1 -0
  182. package/dist/esm/utils/errors/GraphQLApiError.d.ts +7 -0
  183. package/dist/esm/utils/errors/GraphQLApiError.mjs +19 -0
  184. package/dist/esm/utils/errors/GraphQLApiError.mjs.map +1 -0
  185. package/dist/esm/utils/errors/assertValidationError.d.ts +5 -0
  186. package/dist/esm/utils/errors/assertValidationError.mjs +17 -0
  187. package/dist/esm/utils/errors/assertValidationError.mjs.map +1 -0
  188. package/dist/esm/utils/errors/constants.d.ts +7 -0
  189. package/dist/esm/utils/errors/constants.mjs +46 -0
  190. package/dist/esm/utils/errors/constants.mjs.map +1 -0
  191. package/dist/esm/utils/errors/createGraphQLResultWithError.d.ts +2 -0
  192. package/dist/esm/utils/errors/createGraphQLResultWithError.mjs +13 -0
  193. package/dist/esm/utils/errors/createGraphQLResultWithError.mjs.map +1 -0
  194. package/dist/esm/utils/errors/index.d.ts +4 -0
  195. package/dist/esm/utils/errors/index.mjs +5 -0
  196. package/dist/esm/utils/errors/index.mjs.map +1 -0
  197. package/dist/esm/utils/errors/repackageAuthError.d.ts +7 -0
  198. package/dist/esm/utils/errors/repackageAuthError.mjs +36 -0
  199. package/dist/esm/utils/errors/repackageAuthError.mjs.map +1 -0
  200. package/dist/esm/utils/errors/validation.d.ts +7 -0
  201. package/dist/esm/utils/errors/validation.mjs +26 -0
  202. package/dist/esm/utils/errors/validation.mjs.map +1 -0
  203. package/dist/esm/utils/index.d.ts +2 -0
  204. package/dist/esm/utils/index.mjs +3 -0
  205. package/dist/esm/utils/index.mjs.map +1 -0
  206. package/dist/esm/utils/resolveConfig.d.ts +12 -0
  207. package/dist/esm/utils/resolveConfig.mjs +33 -0
  208. package/dist/esm/utils/resolveConfig.mjs.map +1 -0
  209. package/dist/esm/utils/resolveLibraryOptions.d.ts +11 -0
  210. package/dist/esm/utils/resolveLibraryOptions.mjs +13 -0
  211. package/dist/esm/utils/resolveLibraryOptions.mjs.map +1 -0
  212. package/internals/package.json +8 -0
  213. package/internals/server/package.json +8 -0
  214. package/package.json +99 -0
  215. package/server/package.json +7 -0
  216. package/src/GraphQLAPI.ts +97 -0
  217. package/src/Providers/AWSAppSyncEventsProvider/index.ts +218 -0
  218. package/src/Providers/AWSAppSyncRealTimeProvider/index.ts +185 -0
  219. package/src/Providers/AWSWebSocketProvider/appsyncUrl.ts +152 -0
  220. package/src/Providers/AWSWebSocketProvider/authHeaders.ts +146 -0
  221. package/src/Providers/AWSWebSocketProvider/index.ts +1028 -0
  222. package/src/Providers/constants.ts +154 -0
  223. package/src/index.ts +12 -0
  224. package/src/internals/InternalGraphQLAPI.ts +424 -0
  225. package/src/internals/events/appsyncRequest.ts +169 -0
  226. package/src/internals/events/index.ts +199 -0
  227. package/src/internals/events/types.ts +109 -0
  228. package/src/internals/events/utils.ts +77 -0
  229. package/src/internals/generateClient.ts +120 -0
  230. package/src/internals/graphqlAuth.ts +87 -0
  231. package/src/internals/graphqlRequest.ts +30 -0
  232. package/src/internals/index.ts +10 -0
  233. package/src/internals/server/generateClientWithAmplifyInstance.ts +73 -0
  234. package/src/internals/server/index.ts +4 -0
  235. package/src/internals/types.ts +42 -0
  236. package/src/internals/utils/runtimeTypeGuards/isApiGraphQLProviderConfig.ts +10 -0
  237. package/src/internals/utils/runtimeTypeGuards/isConfigureEventWithResourceConfig.ts +13 -0
  238. package/src/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.ts +15 -0
  239. package/src/internals/v6.ts +189 -0
  240. package/src/server/generateClient.ts +68 -0
  241. package/src/server/index.ts +4 -0
  242. package/src/types/PubSub.ts +57 -0
  243. package/src/types/index.ts +524 -0
  244. package/src/utils/ConnectionStateMonitor.ts +195 -0
  245. package/src/utils/ReachabilityMonitor/index.native.ts +7 -0
  246. package/src/utils/ReachabilityMonitor/index.ts +5 -0
  247. package/src/utils/ReconnectionMonitor.ts +77 -0
  248. package/src/utils/errors/GraphQLApiError.ts +21 -0
  249. package/src/utils/errors/assertValidationError.ts +19 -0
  250. package/src/utils/errors/constants.ts +56 -0
  251. package/src/utils/errors/createGraphQLResultWithError.ts +15 -0
  252. package/src/utils/errors/index.ts +7 -0
  253. package/src/utils/errors/repackageAuthError.ts +43 -0
  254. package/src/utils/errors/validation.ts +26 -0
  255. package/src/utils/index.ts +5 -0
  256. package/src/utils/resolveConfig.ts +46 -0
  257. package/src/utils/resolveLibraryOptions.ts +14 -0
@@ -0,0 +1,93 @@
1
+ import { Subscription } from 'rxjs';
2
+ import type { DocumentType, GraphQLAuthMode } from '@aws-amplify/core/internals/utils';
3
+ export interface SubscriptionObserver<T> {
4
+ next(value: T): void;
5
+ error(errorValue: any): void;
6
+ }
7
+ export interface EventsChannel {
8
+ /**
9
+ * @experimental API may change in future versions
10
+ *
11
+ * Subscribe to Events
12
+ *
13
+ * @example
14
+ * const channel = await events.connect("default/channel")
15
+ *
16
+ * channel.subscribe({
17
+ * next: (data) => { console.log(data) },
18
+ * error: (err) => { console.error(err) },
19
+ * })
20
+ *
21
+ * @example // authMode override
22
+ * channel.subscribe({
23
+ * next: (data) => { console.log(data) },
24
+ * error: (err) => { console.error(err) },
25
+ * }, { authMode: 'userPool' })
26
+ *
27
+ * @param observer - observer callback handlers
28
+ * `{ next: () => {}, error: () => {}}`
29
+ *
30
+ * @param options - subscribe overrides: `authMode`, `authToken`
31
+ *
32
+ */
33
+ subscribe(observer: SubscriptionObserver<any>, subOptions?: EventsOptions): Subscription;
34
+ /**
35
+ * @experimental API may change in future versions
36
+ *
37
+ * Publish events to a channel via WebSocket
38
+ *
39
+ * @example
40
+ * const channel = await events.connect("default/channel")
41
+ *
42
+ * await channel.publish({ some: "data" });
43
+ *
44
+ * @example // event batching
45
+ * await channel.publish("default/channel", [{ some: "event" }, { some: "event2" }])
46
+ *
47
+ * @example // authMode override
48
+ * await channel.publish({ some: "data" }, { authMode: "userPool" });
49
+ *
50
+ * @param event - JSON-serializable value or an array of values
51
+ * @param pubOptions - request overrides: `authMode`, `authToken`
52
+ *
53
+ * @returns void on success
54
+ * @throws on error
55
+ */
56
+ publish(event: DocumentType, pubOptions?: EventsOptions): Promise<any>;
57
+ /**
58
+ * @experimental API may change in future versions
59
+ *
60
+ * Close channel and any active subscriptions
61
+ *
62
+ * @example
63
+ * const channel = await events.connect("default/channel")
64
+ *
65
+ * channel.close()
66
+ *
67
+ */
68
+ close(): void;
69
+ }
70
+ export type ResolvedGraphQLAuthModes = Exclude<GraphQLAuthMode, 'identityPool'>;
71
+ export interface EventsOptions {
72
+ authMode?: GraphQLAuthMode;
73
+ authToken?: string;
74
+ apiKey?: string;
75
+ }
76
+ export interface PublishedEvent {
77
+ identifier: string;
78
+ index: number;
79
+ }
80
+ export interface PublishResponse {
81
+ failed: PublishedEvent[];
82
+ successful: PublishedEvent[];
83
+ }
84
+ interface EventsConfigure {
85
+ appSyncGraphqlEndpoint: string;
86
+ region?: string;
87
+ authenticationType: ResolvedGraphQLAuthModes;
88
+ apiKey?: string;
89
+ }
90
+ export type ProviderOptions = EventsConfigure & {
91
+ authToken?: string;
92
+ };
93
+ export {};
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=types.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,16 @@
1
+ import { DocumentType, GraphQLAuthMode } from '@aws-amplify/core/internals/utils';
2
+ import type { ResolvedGraphQLAuthModes } from './types';
3
+ export declare const normalizeAuth: (explicitAuthMode: GraphQLAuthMode | undefined, defaultAuthMode: ResolvedGraphQLAuthModes) => ResolvedGraphQLAuthModes;
4
+ export declare const configure: () => {
5
+ appSyncGraphqlEndpoint: string;
6
+ region: string | undefined;
7
+ authenticationType: ResolvedGraphQLAuthModes;
8
+ apiKey: string | undefined;
9
+ };
10
+ /**
11
+ * Event API expects an array of JSON strings
12
+ *
13
+ * @param events - JSON-serializable value or an array of values
14
+ * @returns array of JSON strings
15
+ */
16
+ export declare const serializeEvents: (events: DocumentType | DocumentType[]) => string[];
@@ -0,0 +1,53 @@
1
+ import { Amplify } from '@aws-amplify/core';
2
+
3
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4
+ // SPDX-License-Identifier: Apache-2.0
5
+ const normalizeAuth = (explicitAuthMode, defaultAuthMode) => {
6
+ if (!explicitAuthMode) {
7
+ return defaultAuthMode;
8
+ }
9
+ if (explicitAuthMode === 'identityPool') {
10
+ return 'iam';
11
+ }
12
+ return explicitAuthMode;
13
+ };
14
+ const configure = () => {
15
+ const config = Amplify.getConfig();
16
+ const eventsConfig = config.API?.Events;
17
+ if (!eventsConfig) {
18
+ throw new Error('Amplify configuration is missing. Have you called Amplify.configure()?');
19
+ }
20
+ const configAuthMode = normalizeAuth(eventsConfig.defaultAuthMode, 'apiKey');
21
+ const options = {
22
+ appSyncGraphqlEndpoint: eventsConfig.endpoint,
23
+ region: eventsConfig.region,
24
+ authenticationType: configAuthMode,
25
+ apiKey: eventsConfig.apiKey,
26
+ };
27
+ return options;
28
+ };
29
+ /**
30
+ * Event API expects an array of JSON strings
31
+ *
32
+ * @param events - JSON-serializable value or an array of values
33
+ * @returns array of JSON strings
34
+ */
35
+ const serializeEvents = (events) => {
36
+ if (Array.isArray(events)) {
37
+ return events.map((ev, idx) => {
38
+ const eventJson = JSON.stringify(ev);
39
+ if (eventJson === undefined) {
40
+ throw new Error(`Event must be a valid JSON value. Received ${ev} at index ${idx}`);
41
+ }
42
+ return eventJson;
43
+ });
44
+ }
45
+ const eventJson = JSON.stringify(events);
46
+ if (eventJson === undefined) {
47
+ throw new Error(`Event must be a valid JSON value. Received ${events}`);
48
+ }
49
+ return [eventJson];
50
+ };
51
+
52
+ export { configure, normalizeAuth, serializeEvents };
53
+ //# sourceMappingURL=utils.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.mjs","sources":["../../../../src/internals/events/utils.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { Amplify } from '@aws-amplify/core';\nexport const normalizeAuth = (explicitAuthMode, defaultAuthMode) => {\n if (!explicitAuthMode) {\n return defaultAuthMode;\n }\n if (explicitAuthMode === 'identityPool') {\n return 'iam';\n }\n return explicitAuthMode;\n};\nexport const configure = () => {\n const config = Amplify.getConfig();\n const eventsConfig = config.API?.Events;\n if (!eventsConfig) {\n throw new Error('Amplify configuration is missing. Have you called Amplify.configure()?');\n }\n const configAuthMode = normalizeAuth(eventsConfig.defaultAuthMode, 'apiKey');\n const options = {\n appSyncGraphqlEndpoint: eventsConfig.endpoint,\n region: eventsConfig.region,\n authenticationType: configAuthMode,\n apiKey: eventsConfig.apiKey,\n };\n return options;\n};\n/**\n * Event API expects an array of JSON strings\n *\n * @param events - JSON-serializable value or an array of values\n * @returns array of JSON strings\n */\nexport const serializeEvents = (events) => {\n if (Array.isArray(events)) {\n return events.map((ev, idx) => {\n const eventJson = JSON.stringify(ev);\n if (eventJson === undefined) {\n throw new Error(`Event must be a valid JSON value. Received ${ev} at index ${idx}`);\n }\n return eventJson;\n });\n }\n const eventJson = JSON.stringify(events);\n if (eventJson === undefined) {\n throw new Error(`Event must be a valid JSON value. Received ${events}`);\n }\n return [eventJson];\n};\n"],"names":[],"mappings":";;AAAA;AACA;AAEY,MAAC,aAAa,GAAG,CAAC,gBAAgB,EAAE,eAAe,KAAK;AACpE,IAAI,IAAI,CAAC,gBAAgB,EAAE;AAC3B,QAAQ,OAAO,eAAe;AAC9B,IAAI;AACJ,IAAI,IAAI,gBAAgB,KAAK,cAAc,EAAE;AAC7C,QAAQ,OAAO,KAAK;AACpB,IAAI;AACJ,IAAI,OAAO,gBAAgB;AAC3B;AACY,MAAC,SAAS,GAAG,MAAM;AAC/B,IAAI,MAAM,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE;AACtC,IAAI,MAAM,YAAY,GAAG,MAAM,CAAC,GAAG,EAAE,MAAM;AAC3C,IAAI,IAAI,CAAC,YAAY,EAAE;AACvB,QAAQ,MAAM,IAAI,KAAK,CAAC,wEAAwE,CAAC;AACjG,IAAI;AACJ,IAAI,MAAM,cAAc,GAAG,aAAa,CAAC,YAAY,CAAC,eAAe,EAAE,QAAQ,CAAC;AAChF,IAAI,MAAM,OAAO,GAAG;AACpB,QAAQ,sBAAsB,EAAE,YAAY,CAAC,QAAQ;AACrD,QAAQ,MAAM,EAAE,YAAY,CAAC,MAAM;AACnC,QAAQ,kBAAkB,EAAE,cAAc;AAC1C,QAAQ,MAAM,EAAE,YAAY,CAAC,MAAM;AACnC,KAAK;AACL,IAAI,OAAO,OAAO;AAClB;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,eAAe,GAAG,CAAC,MAAM,KAAK;AAC3C,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;AAC/B,QAAQ,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,GAAG,KAAK;AACvC,YAAY,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;AAChD,YAAY,IAAI,SAAS,KAAK,SAAS,EAAE;AACzC,gBAAgB,MAAM,IAAI,KAAK,CAAC,CAAC,2CAA2C,EAAE,EAAE,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC,CAAC;AACnG,YAAY;AACZ,YAAY,OAAO,SAAS;AAC5B,QAAQ,CAAC,CAAC;AACV,IAAI;AACJ,IAAI,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;AAC5C,IAAI,IAAI,SAAS,KAAK,SAAS,EAAE;AACjC,QAAQ,MAAM,IAAI,KAAK,CAAC,CAAC,2CAA2C,EAAE,MAAM,CAAC,CAAC,CAAC;AAC/E,IAAI;AACJ,IAAI,OAAO,CAAC,SAAS,CAAC;AACtB;;;;"}
@@ -0,0 +1,12 @@
1
+ import { V6Client } from '../types';
2
+ import { ClientGenerationParams } from './types';
3
+ /**
4
+ * @private
5
+ *
6
+ * Creates a client that can be used to make GraphQL requests, using a provided `AmplifyClassV6`
7
+ * compatible context object for config and auth fetching.
8
+ *
9
+ * @param params
10
+ * @returns
11
+ */
12
+ export declare function generateClient<T extends Record<any, any> = never, Options extends ClientGenerationParams = ClientGenerationParams>(params: Options): V6Client<T, Options>;
@@ -0,0 +1,85 @@
1
+ import { Hub } from '@aws-amplify/core';
2
+ import { addSchemaToClient } from '@aws-amplify/data-schema/runtime';
3
+ import { __headers, __endpoint, __apiKey, __authToken, __authMode, __amplify, getInternals } from '../types/index.mjs';
4
+ import { isApiGraphQLConfig } from './utils/runtimeTypeGuards/isApiGraphQLProviderConfig.mjs';
5
+ import { isConfigureEventWithResourceConfig } from './utils/runtimeTypeGuards/isConfigureEventWithResourceConfig.mjs';
6
+ import { isCancelError, cancel, graphql } from './v6.mjs';
7
+
8
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
9
+ // SPDX-License-Identifier: Apache-2.0
10
+ /**
11
+ * @private
12
+ *
13
+ * Creates a client that can be used to make GraphQL requests, using a provided `AmplifyClassV6`
14
+ * compatible context object for config and auth fetching.
15
+ *
16
+ * @param params
17
+ * @returns
18
+ */
19
+ function generateClient(params) {
20
+ const client = {
21
+ [__amplify]: params.amplify,
22
+ [__authMode]: params.authMode,
23
+ [__authToken]: params.authToken,
24
+ [__apiKey]: 'apiKey' in params ? params.apiKey : undefined,
25
+ [__endpoint]: 'endpoint' in params ? params.endpoint : undefined,
26
+ [__headers]: params.headers,
27
+ graphql,
28
+ cancel,
29
+ isCancelError,
30
+ models: emptyProperty,
31
+ enums: emptyProperty,
32
+ queries: emptyProperty,
33
+ mutations: emptyProperty,
34
+ subscriptions: emptyProperty,
35
+ };
36
+ const apiGraphqlConfig = params.amplify.getConfig().API?.GraphQL;
37
+ if (client[__endpoint]) {
38
+ if (!client[__authMode]) {
39
+ throw new Error('generateClient() requires an explicit `authMode` when `endpoint` is provided.');
40
+ }
41
+ if (client[__authMode] === 'apiKey' && !client[__apiKey]) {
42
+ throw new Error("generateClient() requires an explicit `apiKey` when `endpoint` is provided and `authMode = 'apiKey'`.");
43
+ }
44
+ }
45
+ if (!client[__endpoint]) {
46
+ if (isApiGraphQLConfig(apiGraphqlConfig)) {
47
+ addSchemaToClient(client, apiGraphqlConfig, getInternals);
48
+ }
49
+ else {
50
+ // This happens when the `Amplify.configure()` call gets evaluated after the `generateClient()` call.
51
+ //
52
+ // Cause: when the `generateClient()` and the `Amplify.configure()` calls are located in
53
+ // different source files, script bundlers may randomly arrange their orders in the production
54
+ // bundle.
55
+ //
56
+ // With the current implementation, the `client.models` instance created by `generateClient()`
57
+ // will be rebuilt on every `Amplify.configure()` call that's provided with a valid GraphQL
58
+ // provider configuration.
59
+ //
60
+ // TODO: revisit, and reverify this approach when enabling multiple clients for multi-endpoints
61
+ // configuration.
62
+ generateModelsPropertyOnAmplifyConfigure(client);
63
+ }
64
+ }
65
+ return client;
66
+ }
67
+ const generateModelsPropertyOnAmplifyConfigure = (clientRef) => {
68
+ Hub.listen('core', coreEvent => {
69
+ if (!isConfigureEventWithResourceConfig(coreEvent.payload)) {
70
+ return;
71
+ }
72
+ const apiGraphQLConfig = coreEvent.payload.data.API?.GraphQL;
73
+ if (isApiGraphQLConfig(apiGraphQLConfig)) {
74
+ addSchemaToClient(clientRef, apiGraphQLConfig, getInternals);
75
+ }
76
+ });
77
+ };
78
+ const emptyProperty = new Proxy({}, {
79
+ get() {
80
+ throw new Error('Client could not be generated. This is likely due to `Amplify.configure()` not being called prior to `generateClient()` or because the configuration passed to `Amplify.configure()` is missing GraphQL provider configuration.');
81
+ },
82
+ });
83
+
84
+ export { generateClient };
85
+ //# sourceMappingURL=generateClient.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateClient.mjs","sources":["../../../src/internals/generateClient.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { Hub } from '@aws-amplify/core';\nimport { addSchemaToClient, } from '@aws-amplify/data-schema/runtime';\nimport { __amplify, __apiKey, __authMode, __authToken, __endpoint, __headers, getInternals, } from '../types';\nimport { isApiGraphQLConfig } from './utils/runtimeTypeGuards/isApiGraphQLProviderConfig';\nimport { isConfigureEventWithResourceConfig } from './utils/runtimeTypeGuards/isConfigureEventWithResourceConfig';\nimport { cancel, graphql, isCancelError } from './v6';\n/**\n * @private\n *\n * Creates a client that can be used to make GraphQL requests, using a provided `AmplifyClassV6`\n * compatible context object for config and auth fetching.\n *\n * @param params\n * @returns\n */\nexport function generateClient(params) {\n const client = {\n [__amplify]: params.amplify,\n [__authMode]: params.authMode,\n [__authToken]: params.authToken,\n [__apiKey]: 'apiKey' in params ? params.apiKey : undefined,\n [__endpoint]: 'endpoint' in params ? params.endpoint : undefined,\n [__headers]: params.headers,\n graphql,\n cancel,\n isCancelError,\n models: emptyProperty,\n enums: emptyProperty,\n queries: emptyProperty,\n mutations: emptyProperty,\n subscriptions: emptyProperty,\n };\n const apiGraphqlConfig = params.amplify.getConfig().API?.GraphQL;\n if (client[__endpoint]) {\n if (!client[__authMode]) {\n throw new Error('generateClient() requires an explicit `authMode` when `endpoint` is provided.');\n }\n if (client[__authMode] === 'apiKey' && !client[__apiKey]) {\n throw new Error(\"generateClient() requires an explicit `apiKey` when `endpoint` is provided and `authMode = 'apiKey'`.\");\n }\n }\n if (!client[__endpoint]) {\n if (isApiGraphQLConfig(apiGraphqlConfig)) {\n addSchemaToClient(client, apiGraphqlConfig, getInternals);\n }\n else {\n // This happens when the `Amplify.configure()` call gets evaluated after the `generateClient()` call.\n //\n // Cause: when the `generateClient()` and the `Amplify.configure()` calls are located in\n // different source files, script bundlers may randomly arrange their orders in the production\n // bundle.\n //\n // With the current implementation, the `client.models` instance created by `generateClient()`\n // will be rebuilt on every `Amplify.configure()` call that's provided with a valid GraphQL\n // provider configuration.\n //\n // TODO: revisit, and reverify this approach when enabling multiple clients for multi-endpoints\n // configuration.\n generateModelsPropertyOnAmplifyConfigure(client);\n }\n }\n return client;\n}\nconst generateModelsPropertyOnAmplifyConfigure = (clientRef) => {\n Hub.listen('core', coreEvent => {\n if (!isConfigureEventWithResourceConfig(coreEvent.payload)) {\n return;\n }\n const apiGraphQLConfig = coreEvent.payload.data.API?.GraphQL;\n if (isApiGraphQLConfig(apiGraphQLConfig)) {\n addSchemaToClient(clientRef, apiGraphQLConfig, getInternals);\n }\n });\n};\nconst emptyProperty = new Proxy({}, {\n get() {\n throw new Error('Client could not be generated. This is likely due to `Amplify.configure()` not being called prior to `generateClient()` or because the configuration passed to `Amplify.configure()` is missing GraphQL provider configuration.');\n },\n});\n"],"names":[],"mappings":";;;;;;;AAAA;AACA;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,cAAc,CAAC,MAAM,EAAE;AACvC,IAAI,MAAM,MAAM,GAAG;AACnB,QAAQ,CAAC,SAAS,GAAG,MAAM,CAAC,OAAO;AACnC,QAAQ,CAAC,UAAU,GAAG,MAAM,CAAC,QAAQ;AACrC,QAAQ,CAAC,WAAW,GAAG,MAAM,CAAC,SAAS;AACvC,QAAQ,CAAC,QAAQ,GAAG,QAAQ,IAAI,MAAM,GAAG,MAAM,CAAC,MAAM,GAAG,SAAS;AAClE,QAAQ,CAAC,UAAU,GAAG,UAAU,IAAI,MAAM,GAAG,MAAM,CAAC,QAAQ,GAAG,SAAS;AACxE,QAAQ,CAAC,SAAS,GAAG,MAAM,CAAC,OAAO;AACnC,QAAQ,OAAO;AACf,QAAQ,MAAM;AACd,QAAQ,aAAa;AACrB,QAAQ,MAAM,EAAE,aAAa;AAC7B,QAAQ,KAAK,EAAE,aAAa;AAC5B,QAAQ,OAAO,EAAE,aAAa;AAC9B,QAAQ,SAAS,EAAE,aAAa;AAChC,QAAQ,aAAa,EAAE,aAAa;AACpC,KAAK;AACL,IAAI,MAAM,gBAAgB,GAAG,MAAM,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,GAAG,EAAE,OAAO;AACpE,IAAI,IAAI,MAAM,CAAC,UAAU,CAAC,EAAE;AAC5B,QAAQ,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE;AACjC,YAAY,MAAM,IAAI,KAAK,CAAC,+EAA+E,CAAC;AAC5G,QAAQ;AACR,QAAQ,IAAI,MAAM,CAAC,UAAU,CAAC,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE;AAClE,YAAY,MAAM,IAAI,KAAK,CAAC,uGAAuG,CAAC;AACpI,QAAQ;AACR,IAAI;AACJ,IAAI,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE;AAC7B,QAAQ,IAAI,kBAAkB,CAAC,gBAAgB,CAAC,EAAE;AAClD,YAAY,iBAAiB,CAAC,MAAM,EAAE,gBAAgB,EAAE,YAAY,CAAC;AACrE,QAAQ;AACR,aAAa;AACb;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,YAAY,wCAAwC,CAAC,MAAM,CAAC;AAC5D,QAAQ;AACR,IAAI;AACJ,IAAI,OAAO,MAAM;AACjB;AACA,MAAM,wCAAwC,GAAG,CAAC,SAAS,KAAK;AAChE,IAAI,GAAG,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,IAAI;AACpC,QAAQ,IAAI,CAAC,kCAAkC,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE;AACpE,YAAY;AACZ,QAAQ;AACR,QAAQ,MAAM,gBAAgB,GAAG,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,OAAO;AACpE,QAAQ,IAAI,kBAAkB,CAAC,gBAAgB,CAAC,EAAE;AAClD,YAAY,iBAAiB,CAAC,SAAS,EAAE,gBAAgB,EAAE,YAAY,CAAC;AACxE,QAAQ;AACR,IAAI,CAAC,CAAC;AACN,CAAC;AACD,MAAM,aAAa,GAAG,IAAI,KAAK,CAAC,EAAE,EAAE;AACpC,IAAI,GAAG,GAAG;AACV,QAAQ,MAAM,IAAI,KAAK,CAAC,iOAAiO,CAAC;AAC1P,IAAI,CAAC;AACL,CAAC,CAAC;;;;"}
@@ -0,0 +1,3 @@
1
+ import { GraphQLAuthMode } from '@aws-amplify/core/internals/utils';
2
+ import { AmplifyClassV6 } from '@aws-amplify/core';
3
+ export declare function headerBasedAuth(amplify: AmplifyClassV6, authMode: GraphQLAuthMode, apiKey: string | undefined, additionalHeaders?: Record<string, string>): Promise<{}>;
@@ -0,0 +1,64 @@
1
+ import { GraphQLApiError } from '../utils/errors/GraphQLApiError.mjs';
2
+ import '../utils/errors/validation.mjs';
3
+ import 'graphql';
4
+ import { NO_AUTH_TOKEN_HEADER, NO_SIGNED_IN_USER, NO_VALID_AUTH_TOKEN, NO_VALID_CREDENTIALS, NO_API_KEY } from '../utils/errors/constants.mjs';
5
+
6
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
7
+ // SPDX-License-Identifier: Apache-2.0
8
+ async function headerBasedAuth(amplify, authMode, apiKey, additionalHeaders = {}) {
9
+ let headers = {};
10
+ switch (authMode) {
11
+ case 'apiKey':
12
+ if (!apiKey) {
13
+ throw new GraphQLApiError(NO_API_KEY);
14
+ }
15
+ headers = {
16
+ 'X-Api-Key': apiKey,
17
+ };
18
+ break;
19
+ case 'iam': {
20
+ const session = await amplify.Auth.fetchAuthSession();
21
+ if (session.credentials === undefined) {
22
+ throw new GraphQLApiError(NO_VALID_CREDENTIALS);
23
+ }
24
+ break;
25
+ }
26
+ case 'oidc':
27
+ case 'userPool': {
28
+ let token;
29
+ try {
30
+ token = (await amplify.Auth.fetchAuthSession()).tokens?.accessToken.toString();
31
+ }
32
+ catch (e) {
33
+ // fetchAuthSession failed
34
+ throw new GraphQLApiError({
35
+ ...NO_SIGNED_IN_USER,
36
+ underlyingError: e,
37
+ });
38
+ }
39
+ // `fetchAuthSession()` succeeded but didn't return `tokens`.
40
+ // This may happen when unauthenticated access is enabled and there is
41
+ // no user signed in.
42
+ if (!token) {
43
+ throw new GraphQLApiError(NO_VALID_AUTH_TOKEN);
44
+ }
45
+ headers = {
46
+ Authorization: token,
47
+ };
48
+ break;
49
+ }
50
+ case 'lambda':
51
+ if (typeof additionalHeaders === 'object' &&
52
+ !additionalHeaders.Authorization) {
53
+ throw new GraphQLApiError(NO_AUTH_TOKEN_HEADER);
54
+ }
55
+ headers = {
56
+ Authorization: additionalHeaders.Authorization,
57
+ };
58
+ break;
59
+ }
60
+ return headers;
61
+ }
62
+
63
+ export { headerBasedAuth };
64
+ //# sourceMappingURL=graphqlAuth.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graphqlAuth.mjs","sources":["../../../src/internals/graphqlAuth.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { GraphQLApiError } from '../utils/errors';\nimport { NO_API_KEY, NO_AUTH_TOKEN_HEADER, NO_SIGNED_IN_USER, NO_VALID_AUTH_TOKEN, NO_VALID_CREDENTIALS, } from '../utils/errors/constants';\nexport async function headerBasedAuth(amplify, authMode, apiKey, additionalHeaders = {}) {\n let headers = {};\n switch (authMode) {\n case 'apiKey':\n if (!apiKey) {\n throw new GraphQLApiError(NO_API_KEY);\n }\n headers = {\n 'X-Api-Key': apiKey,\n };\n break;\n case 'iam': {\n const session = await amplify.Auth.fetchAuthSession();\n if (session.credentials === undefined) {\n throw new GraphQLApiError(NO_VALID_CREDENTIALS);\n }\n break;\n }\n case 'oidc':\n case 'userPool': {\n let token;\n try {\n token = (await amplify.Auth.fetchAuthSession()).tokens?.accessToken.toString();\n }\n catch (e) {\n // fetchAuthSession failed\n throw new GraphQLApiError({\n ...NO_SIGNED_IN_USER,\n underlyingError: e,\n });\n }\n // `fetchAuthSession()` succeeded but didn't return `tokens`.\n // This may happen when unauthenticated access is enabled and there is\n // no user signed in.\n if (!token) {\n throw new GraphQLApiError(NO_VALID_AUTH_TOKEN);\n }\n headers = {\n Authorization: token,\n };\n break;\n }\n case 'lambda':\n if (typeof additionalHeaders === 'object' &&\n !additionalHeaders.Authorization) {\n throw new GraphQLApiError(NO_AUTH_TOKEN_HEADER);\n }\n headers = {\n Authorization: additionalHeaders.Authorization,\n };\n break;\n case 'none':\n break;\n default:\n break;\n }\n return headers;\n}\n"],"names":[],"mappings":";;;;;AAAA;AACA;AAGO,eAAe,eAAe,CAAC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,iBAAiB,GAAG,EAAE,EAAE;AACzF,IAAI,IAAI,OAAO,GAAG,EAAE;AACpB,IAAI,QAAQ,QAAQ;AACpB,QAAQ,KAAK,QAAQ;AACrB,YAAY,IAAI,CAAC,MAAM,EAAE;AACzB,gBAAgB,MAAM,IAAI,eAAe,CAAC,UAAU,CAAC;AACrD,YAAY;AACZ,YAAY,OAAO,GAAG;AACtB,gBAAgB,WAAW,EAAE,MAAM;AACnC,aAAa;AACb,YAAY;AACZ,QAAQ,KAAK,KAAK,EAAE;AACpB,YAAY,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,gBAAgB,EAAE;AACjE,YAAY,IAAI,OAAO,CAAC,WAAW,KAAK,SAAS,EAAE;AACnD,gBAAgB,MAAM,IAAI,eAAe,CAAC,oBAAoB,CAAC;AAC/D,YAAY;AACZ,YAAY;AACZ,QAAQ;AACR,QAAQ,KAAK,MAAM;AACnB,QAAQ,KAAK,UAAU,EAAE;AACzB,YAAY,IAAI,KAAK;AACrB,YAAY,IAAI;AAChB,gBAAgB,KAAK,GAAG,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,gBAAgB,EAAE,EAAE,MAAM,EAAE,WAAW,CAAC,QAAQ,EAAE;AAC9F,YAAY;AACZ,YAAY,OAAO,CAAC,EAAE;AACtB;AACA,gBAAgB,MAAM,IAAI,eAAe,CAAC;AAC1C,oBAAoB,GAAG,iBAAiB;AACxC,oBAAoB,eAAe,EAAE,CAAC;AACtC,iBAAiB,CAAC;AAClB,YAAY;AACZ;AACA;AACA;AACA,YAAY,IAAI,CAAC,KAAK,EAAE;AACxB,gBAAgB,MAAM,IAAI,eAAe,CAAC,mBAAmB,CAAC;AAC9D,YAAY;AACZ,YAAY,OAAO,GAAG;AACtB,gBAAgB,aAAa,EAAE,KAAK;AACpC,aAAa;AACb,YAAY;AACZ,QAAQ;AACR,QAAQ,KAAK,QAAQ;AACrB,YAAY,IAAI,OAAO,iBAAiB,KAAK,QAAQ;AACrD,gBAAgB,CAAC,iBAAiB,CAAC,aAAa,EAAE;AAClD,gBAAgB,MAAM,IAAI,eAAe,CAAC,oBAAoB,CAAC;AAC/D,YAAY;AACZ,YAAY,OAAO,GAAG;AACtB,gBAAgB,aAAa,EAAE,iBAAiB,CAAC,aAAa;AAC9D,aAAa;AACb,YAAY;AAKZ;AACA,IAAI,OAAO,OAAO;AAClB;;;;"}
@@ -0,0 +1,3 @@
1
+ import { AmplifyClassV6 } from '@aws-amplify/core';
2
+ import { post } from '@aws-amplify/api-rest/internals';
3
+ export declare function graphqlRequest(amplify: AmplifyClassV6, url: string, options: any, abortController: AbortController, _post?: typeof post): Promise<import("@aws-amplify/core/internals/utils").DocumentType>;
@@ -0,0 +1,18 @@
1
+ import { AmplifyUrl } from '@aws-amplify/core/internals/utils';
2
+ import { post } from '@aws-amplify/api-rest/internals';
3
+
4
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
5
+ // SPDX-License-Identifier: Apache-2.0
6
+ async function graphqlRequest(amplify, url, options, abortController, _post) {
7
+ const p = _post ?? post;
8
+ const { body: responseBody } = await p(amplify, {
9
+ url: new AmplifyUrl(url),
10
+ options,
11
+ abortController,
12
+ });
13
+ const response = await responseBody.json();
14
+ return response;
15
+ }
16
+
17
+ export { graphqlRequest };
18
+ //# sourceMappingURL=graphqlRequest.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graphqlRequest.mjs","sources":["../../../src/internals/graphqlRequest.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { AmplifyUrl } from '@aws-amplify/core/internals/utils';\nimport { \n// cancel as cancelREST,\npost,\n// updateRequestToBeCancellable,\n } from '@aws-amplify/api-rest/internals';\nexport async function graphqlRequest(amplify, url, options, abortController, _post) {\n const p = _post ?? post;\n const { body: responseBody } = await p(amplify, {\n url: new AmplifyUrl(url),\n options,\n abortController,\n });\n const response = await responseBody.json();\n return response;\n}\n"],"names":[],"mappings":";;;AAAA;AACA;AAOO,eAAe,cAAc,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE;AACpF,IAAI,MAAM,CAAC,GAAG,KAAK,IAAI,IAAI;AAC3B,IAAI,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,MAAM,CAAC,CAAC,OAAO,EAAE;AACpD,QAAQ,GAAG,EAAE,IAAI,UAAU,CAAC,GAAG,CAAC;AAChC,QAAQ,OAAO;AACf,QAAQ,eAAe;AACvB,KAAK,CAAC;AACN,IAAI,MAAM,QAAQ,GAAG,MAAM,YAAY,CAAC,IAAI,EAAE;AAC9C,IAAI,OAAO,QAAQ;AACnB;;;;"}
@@ -0,0 +1,4 @@
1
+ export { InternalGraphQLAPI, InternalGraphQLAPIClass, } from './InternalGraphQLAPI';
2
+ export { graphql, cancel, isCancelError } from './v6';
3
+ export { generateClient } from './generateClient';
4
+ export { CommonPublicClientOptions, DefaultCommonClientOptions } from './types';
@@ -0,0 +1,4 @@
1
+ export { InternalGraphQLAPI, InternalGraphQLAPIClass } from './InternalGraphQLAPI.mjs';
2
+ export { cancel, graphql, isCancelError } from './v6.mjs';
3
+ export { generateClient } from './generateClient.mjs';
4
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
@@ -0,0 +1,13 @@
1
+ import { CommonPublicClientOptions, ServerClientGenerationParams, V6ClientSSRCookies, V6ClientSSRRequest } from '../../types';
2
+ /**
3
+ * @private
4
+ *
5
+ * Used internally by `adapter-nextjs` package.
6
+ *
7
+ * Creates a client that can be used to make GraphQL requests, using a provided `AmplifyClassV6`
8
+ * compatible context object for config and auth fetching.
9
+ *
10
+ * @param params
11
+ * @returns
12
+ */
13
+ export declare function generateClientWithAmplifyInstance<T extends Record<any, any> = never, ClientType extends V6ClientSSRRequest<T> | V6ClientSSRCookies<T> = V6ClientSSRCookies<T>>(params: ServerClientGenerationParams & CommonPublicClientOptions): ClientType;
@@ -0,0 +1,61 @@
1
+ import { addSchemaToClientWithInstance } from '@aws-amplify/data-schema/runtime';
2
+ import { __headers, __endpoint, __apiKey, __authToken, __authMode, __amplify, getInternals } from '../../types/index.mjs';
3
+ import { isApiGraphQLConfig } from '../utils/runtimeTypeGuards/isApiGraphQLProviderConfig.mjs';
4
+ import 'graphql';
5
+ import 'rxjs';
6
+ import '@aws-amplify/core/internals/utils';
7
+ import '@aws-amplify/api-rest';
8
+ import '@aws-amplify/api-rest/internals';
9
+ import '../../Providers/constants.mjs';
10
+ import '@aws-amplify/core';
11
+ import '../../types/PubSub.mjs';
12
+ import '../../utils/ReconnectionMonitor.mjs';
13
+ import '../../Providers/AWSWebSocketProvider/authHeaders.mjs';
14
+ import '../../utils/resolveConfig.mjs';
15
+ import '../../utils/errors/constants.mjs';
16
+ import '../../utils/errors/validation.mjs';
17
+ import { isCancelError, cancel, graphql } from '../v6.mjs';
18
+ import '../generateClient.mjs';
19
+
20
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
21
+ // SPDX-License-Identifier: Apache-2.0
22
+ /**
23
+ * @private
24
+ *
25
+ * Used internally by `adapter-nextjs` package.
26
+ *
27
+ * Creates a client that can be used to make GraphQL requests, using a provided `AmplifyClassV6`
28
+ * compatible context object for config and auth fetching.
29
+ *
30
+ * @param params
31
+ * @returns
32
+ */
33
+ function generateClientWithAmplifyInstance(params) {
34
+ const client = {
35
+ [__amplify]: params.amplify,
36
+ [__authMode]: params.authMode,
37
+ [__authToken]: params.authToken,
38
+ [__apiKey]: 'apiKey' in params ? params.apiKey : undefined,
39
+ [__endpoint]: 'endpoint' in params ? params.endpoint : undefined,
40
+ [__headers]: params.headers,
41
+ graphql,
42
+ cancel,
43
+ isCancelError,
44
+ };
45
+ const apiGraphqlConfig = params.config?.API?.GraphQL;
46
+ if (client[__endpoint]) {
47
+ if (!client[__authMode]) {
48
+ throw new Error('generateClient() requires an explicit `authMode` when `endpoint` is provided.');
49
+ }
50
+ if (client[__authMode] === 'apiKey' && !client[__apiKey]) {
51
+ throw new Error("generateClient() requires an explicit `apiKey` when `endpoint` is provided and `authMode = 'apiKey'`.");
52
+ }
53
+ }
54
+ if (!client[__endpoint] && isApiGraphQLConfig(apiGraphqlConfig)) {
55
+ addSchemaToClientWithInstance(client, params, getInternals);
56
+ }
57
+ return client;
58
+ }
59
+
60
+ export { generateClientWithAmplifyInstance };
61
+ //# sourceMappingURL=generateClientWithAmplifyInstance.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateClientWithAmplifyInstance.mjs","sources":["../../../../src/internals/server/generateClientWithAmplifyInstance.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { addSchemaToClientWithInstance } from '@aws-amplify/data-schema/runtime';\nimport { __amplify, __apiKey, __authMode, __authToken, __endpoint, __headers, getInternals, } from '../../types';\nimport { isApiGraphQLConfig } from '../utils/runtimeTypeGuards/isApiGraphQLProviderConfig';\nimport { cancel, graphql, isCancelError } from '..';\n/**\n * @private\n *\n * Used internally by `adapter-nextjs` package.\n *\n * Creates a client that can be used to make GraphQL requests, using a provided `AmplifyClassV6`\n * compatible context object for config and auth fetching.\n *\n * @param params\n * @returns\n */\nexport function generateClientWithAmplifyInstance(params) {\n const client = {\n [__amplify]: params.amplify,\n [__authMode]: params.authMode,\n [__authToken]: params.authToken,\n [__apiKey]: 'apiKey' in params ? params.apiKey : undefined,\n [__endpoint]: 'endpoint' in params ? params.endpoint : undefined,\n [__headers]: params.headers,\n graphql,\n cancel,\n isCancelError,\n };\n const apiGraphqlConfig = params.config?.API?.GraphQL;\n if (client[__endpoint]) {\n if (!client[__authMode]) {\n throw new Error('generateClient() requires an explicit `authMode` when `endpoint` is provided.');\n }\n if (client[__authMode] === 'apiKey' && !client[__apiKey]) {\n throw new Error(\"generateClient() requires an explicit `apiKey` when `endpoint` is provided and `authMode = 'apiKey'`.\");\n }\n }\n if (!client[__endpoint] && isApiGraphQLConfig(apiGraphqlConfig)) {\n addSchemaToClientWithInstance(client, params, getInternals);\n }\n return client;\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AACA;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,iCAAiC,CAAC,MAAM,EAAE;AAC1D,IAAI,MAAM,MAAM,GAAG;AACnB,QAAQ,CAAC,SAAS,GAAG,MAAM,CAAC,OAAO;AACnC,QAAQ,CAAC,UAAU,GAAG,MAAM,CAAC,QAAQ;AACrC,QAAQ,CAAC,WAAW,GAAG,MAAM,CAAC,SAAS;AACvC,QAAQ,CAAC,QAAQ,GAAG,QAAQ,IAAI,MAAM,GAAG,MAAM,CAAC,MAAM,GAAG,SAAS;AAClE,QAAQ,CAAC,UAAU,GAAG,UAAU,IAAI,MAAM,GAAG,MAAM,CAAC,QAAQ,GAAG,SAAS;AACxE,QAAQ,CAAC,SAAS,GAAG,MAAM,CAAC,OAAO;AACnC,QAAQ,OAAO;AACf,QAAQ,MAAM;AACd,QAAQ,aAAa;AACrB,KAAK;AACL,IAAI,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO;AACxD,IAAI,IAAI,MAAM,CAAC,UAAU,CAAC,EAAE;AAC5B,QAAQ,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE;AACjC,YAAY,MAAM,IAAI,KAAK,CAAC,+EAA+E,CAAC;AAC5G,QAAQ;AACR,QAAQ,IAAI,MAAM,CAAC,UAAU,CAAC,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE;AAClE,YAAY,MAAM,IAAI,KAAK,CAAC,uGAAuG,CAAC;AACpI,QAAQ;AACR,IAAI;AACJ,IAAI,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,kBAAkB,CAAC,gBAAgB,CAAC,EAAE;AACrE,QAAQ,6BAA6B,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,CAAC;AACnE,IAAI;AACJ,IAAI,OAAO,MAAM;AACjB;;;;"}
@@ -0,0 +1 @@
1
+ export { generateClientWithAmplifyInstance } from './generateClientWithAmplifyInstance';
@@ -0,0 +1,2 @@
1
+ export { generateClientWithAmplifyInstance } from './generateClientWithAmplifyInstance.mjs';
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,34 @@
1
+ import { AmplifyClassV6 } from '@aws-amplify/core';
2
+ import { GraphQLAuthMode } from '@aws-amplify/core/internals/utils';
3
+ import { CustomHeaders } from '@aws-amplify/data-schema/runtime';
4
+ /**
5
+ * @private
6
+ *
7
+ * The knobs available for configuring `generateClient` internally.
8
+ */
9
+ export type ClientGenerationParams = {
10
+ amplify: AmplifyClassV6;
11
+ } & CommonPublicClientOptions;
12
+ export interface DefaultCommonClientOptions {
13
+ endpoint?: never;
14
+ authMode?: GraphQLAuthMode;
15
+ apiKey?: string;
16
+ authToken?: string;
17
+ headers?: CustomHeaders;
18
+ }
19
+ /**
20
+ * Common options that can be used on public `generateClient()` interfaces.
21
+ */
22
+ export type CommonPublicClientOptions = DefaultCommonClientOptions | {
23
+ endpoint: string;
24
+ authMode: 'apiKey';
25
+ apiKey: string;
26
+ authToken?: string;
27
+ headers?: CustomHeaders;
28
+ } | {
29
+ endpoint: string;
30
+ authMode: Exclude<GraphQLAuthMode, 'apiKey'>;
31
+ apiKey?: string;
32
+ authToken?: string;
33
+ headers?: CustomHeaders;
34
+ };
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=types.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ import { GraphQLProviderConfig } from '@aws-amplify/core/internals/utils';
2
+ export declare function isApiGraphQLConfig(apiGraphQLConfig: GraphQLProviderConfig['GraphQL'] | undefined): apiGraphQLConfig is GraphQLProviderConfig['GraphQL'];
@@ -0,0 +1,8 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ function isApiGraphQLConfig(apiGraphQLConfig) {
4
+ return apiGraphQLConfig !== undefined;
5
+ }
6
+
7
+ export { isApiGraphQLConfig };
8
+ //# sourceMappingURL=isApiGraphQLProviderConfig.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isApiGraphQLProviderConfig.mjs","sources":["../../../../../src/internals/utils/runtimeTypeGuards/isApiGraphQLProviderConfig.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nexport function isApiGraphQLConfig(apiGraphQLConfig) {\n return apiGraphQLConfig !== undefined;\n}\n"],"names":[],"mappings":"AAAA;AACA;AACO,SAAS,kBAAkB,CAAC,gBAAgB,EAAE;AACrD,IAAI,OAAO,gBAAgB,KAAK,SAAS;AACzC;;;;"}
@@ -0,0 +1,8 @@
1
+ import { HubCapsule, ResourcesConfig } from '@aws-amplify/core';
2
+ export declare function isConfigureEventWithResourceConfig(payload: HubCapsule<'core', {
3
+ event: string;
4
+ data?: unknown;
5
+ }>['payload']): payload is {
6
+ event: 'configure';
7
+ data: ResourcesConfig;
8
+ };
@@ -0,0 +1,8 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ function isConfigureEventWithResourceConfig(payload) {
4
+ return payload.event === 'configure';
5
+ }
6
+
7
+ export { isConfigureEventWithResourceConfig };
8
+ //# sourceMappingURL=isConfigureEventWithResourceConfig.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isConfigureEventWithResourceConfig.mjs","sources":["../../../../../src/internals/utils/runtimeTypeGuards/isConfigureEventWithResourceConfig.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nexport function isConfigureEventWithResourceConfig(payload) {\n return payload.event === 'configure';\n}\n"],"names":[],"mappings":"AAAA;AACA;AACO,SAAS,kCAAkC,CAAC,OAAO,EAAE;AAC5D,IAAI,OAAO,OAAO,CAAC,KAAK,KAAK,WAAW;AACxC;;;;"}
@@ -0,0 +1,2 @@
1
+ import { GraphQLResult } from '../../../types';
2
+ export declare function isGraphQLResponseWithErrors(response: unknown): response is GraphQLResult;
@@ -0,0 +1,12 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ function isGraphQLResponseWithErrors(response) {
4
+ if (!response) {
5
+ return false;
6
+ }
7
+ const r = response;
8
+ return Array.isArray(r.errors) && r.errors.length > 0;
9
+ }
10
+
11
+ export { isGraphQLResponseWithErrors };
12
+ //# sourceMappingURL=isGraphQLResponseWithErrors.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isGraphQLResponseWithErrors.mjs","sources":["../../../../../src/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nexport function isGraphQLResponseWithErrors(response) {\n if (!response) {\n return false;\n }\n const r = response;\n return Array.isArray(r.errors) && r.errors.length > 0;\n}\n"],"names":[],"mappings":"AAAA;AACA;AACO,SAAS,2BAA2B,CAAC,QAAQ,EAAE;AACtD,IAAI,IAAI,CAAC,QAAQ,EAAE;AACnB,QAAQ,OAAO,KAAK;AACpB,IAAI;AACJ,IAAI,MAAM,CAAC,GAAG,QAAQ;AACtB,IAAI,OAAO,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC;AACzD;;;;"}