@aws-amplify/api-graphql 4.7.13-unstable.34b927a.0 → 4.7.13-unstable.db70f7b.0

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.
@@ -34,6 +34,8 @@ const openChannels = new Set();
34
34
  async function connect(channel, options) {
35
35
  const providerOptions = (0, utils_2.configure)();
36
36
  providerOptions.authenticationType = (0, utils_2.normalizeAuth)(options?.authMode, providerOptions.authenticationType);
37
+ providerOptions.apiKey = options?.apiKey || providerOptions.apiKey;
38
+ providerOptions.authToken = options?.authToken || providerOptions.authToken;
37
39
  await AWSAppSyncEventsProvider_1.AppSyncEventProvider.connect(providerOptions);
38
40
  const channelId = (0, utils_1.amplifyUuid)();
39
41
  openChannels.add(channelId);
@@ -44,6 +46,9 @@ async function connect(channel, options) {
44
46
  }
45
47
  const subscribeOptions = { ...providerOptions, query: channel };
46
48
  subscribeOptions.authenticationType = (0, utils_2.normalizeAuth)(subOptions?.authMode, subscribeOptions.authenticationType);
49
+ subscribeOptions.apiKey = subOptions?.apiKey || subscribeOptions.apiKey;
50
+ subscribeOptions.authToken =
51
+ subOptions?.authToken || subscribeOptions.authToken;
47
52
  _subscription = AWSAppSyncEventsProvider_1.AppSyncEventProvider
48
53
  .subscribe(subscribeOptions)
49
54
  .subscribe(observer);
@@ -59,6 +64,9 @@ async function connect(channel, options) {
59
64
  variables: event,
60
65
  };
61
66
  publishOptions.authenticationType = (0, utils_2.normalizeAuth)(pubOptions?.authMode, publishOptions.authenticationType);
67
+ publishOptions.apiKey = pubOptions?.apiKey || publishOptions.apiKey;
68
+ publishOptions.authToken =
69
+ pubOptions?.authToken || publishOptions.authToken;
62
70
  return AWSAppSyncEventsProvider_1.AppSyncEventProvider.publish(publishOptions);
63
71
  };
64
72
  const close = async () => {
@@ -101,13 +109,14 @@ exports.connect = connect;
101
109
  async function post(channel, event, options) {
102
110
  const providerOptions = (0, utils_2.configure)();
103
111
  providerOptions.authenticationType = (0, utils_2.normalizeAuth)(options?.authMode, providerOptions.authenticationType);
112
+ providerOptions.apiKey = options?.apiKey || providerOptions.apiKey;
113
+ providerOptions.authToken = options?.authToken || providerOptions.authToken;
104
114
  // trailing slash required in publish
105
115
  const normalizedChannelName = channel[0] === '/' ? channel : `/${channel}`;
106
116
  const publishOptions = {
107
117
  ...providerOptions,
108
118
  query: normalizedChannelName,
109
119
  variables: (0, utils_2.serializeEvents)(event),
110
- authToken: options?.authToken,
111
120
  };
112
121
  const abortController = new AbortController();
113
122
  const res = await (0, appsyncRequest_1.appsyncRequest)(core_1.Amplify, publishOptions, {}, abortController);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../../src/internals/events/index.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.closeAll = exports.post = exports.connect = void 0;\nconst core_1 = require(\"@aws-amplify/core\");\nconst utils_1 = require(\"@aws-amplify/core/internals/utils\");\nconst AWSAppSyncEventsProvider_1 = require(\"../../Providers/AWSAppSyncEventsProvider\");\nconst appsyncRequest_1 = require(\"./appsyncRequest\");\nconst utils_2 = require(\"./utils\");\n// Keeps a list of open channels in the websocket\nconst openChannels = new Set();\n/**\n * @experimental API may change in future versions\n *\n * Establish a WebSocket connection to an Events channel\n *\n * @example\n * const channel = await events.connect(\"default/channel\")\n *\n * channel.subscribe({\n * next: (data) => { console.log(data) },\n * error: (err) => { console.error(err) },\n * })\n *\n * @example // authMode override\n * const channel = await events.connect(\"default/channel\", { authMode: \"userPool\" })\n *\n * @param channel - channel path; `<namespace>/<channel>`\n * @param options - request overrides: `authMode`, `authToken`\n *\n */\nasync function connect(channel, options) {\n const providerOptions = (0, utils_2.configure)();\n providerOptions.authenticationType = (0, utils_2.normalizeAuth)(options?.authMode, providerOptions.authenticationType);\n await AWSAppSyncEventsProvider_1.AppSyncEventProvider.connect(providerOptions);\n const channelId = (0, utils_1.amplifyUuid)();\n openChannels.add(channelId);\n let _subscription;\n const sub = (observer, subOptions) => {\n if (!openChannels.has(channelId)) {\n throw new Error('Channel is closed');\n }\n const subscribeOptions = { ...providerOptions, query: channel };\n subscribeOptions.authenticationType = (0, utils_2.normalizeAuth)(subOptions?.authMode, subscribeOptions.authenticationType);\n _subscription = AWSAppSyncEventsProvider_1.AppSyncEventProvider\n .subscribe(subscribeOptions)\n .subscribe(observer);\n return _subscription;\n };\n const pub = async (event, pubOptions) => {\n if (!openChannels.has(channelId)) {\n throw new Error('Channel is closed');\n }\n const publishOptions = {\n ...providerOptions,\n query: channel,\n variables: event,\n };\n publishOptions.authenticationType = (0, utils_2.normalizeAuth)(pubOptions?.authMode, publishOptions.authenticationType);\n return AWSAppSyncEventsProvider_1.AppSyncEventProvider.publish(publishOptions);\n };\n const close = async () => {\n _subscription && _subscription.unsubscribe();\n openChannels.delete(channelId);\n setTimeout(() => {\n if (openChannels.size === 0) {\n AWSAppSyncEventsProvider_1.AppSyncEventProvider.closeIfNoActiveSubscription();\n }\n }, 1000);\n };\n return {\n subscribe: sub,\n close,\n publish: pub,\n };\n}\nexports.connect = connect;\n/**\n * @experimental API may change in future versions\n *\n * Publish events to a channel via HTTP request\n *\n * @example\n * await events.post(\"default/channel\", { some: \"event\" })\n *\n * @example // event batching\n * await events.post(\"default/channel\", [{ some: \"event\" }, { some: \"event2\" }])\n *\n * @example // authMode override\n * await events.post(\"default/channel\", { some: \"event\" }, { authMode: \"userPool\" })\n *\n * @param channel - channel path; `<namespace>/<channel>`\n * @param event - JSON-serializable value or an array of values\n * @param options - request overrides: `authMode`, `authToken`\n *\n * @returns void on success\n * @throws on error\n */\nasync function post(channel, event, options) {\n const providerOptions = (0, utils_2.configure)();\n providerOptions.authenticationType = (0, utils_2.normalizeAuth)(options?.authMode, providerOptions.authenticationType);\n // trailing slash required in publish\n const normalizedChannelName = channel[0] === '/' ? channel : `/${channel}`;\n const publishOptions = {\n ...providerOptions,\n query: normalizedChannelName,\n variables: (0, utils_2.serializeEvents)(event),\n authToken: options?.authToken,\n };\n const abortController = new AbortController();\n const res = await (0, appsyncRequest_1.appsyncRequest)(core_1.Amplify, publishOptions, {}, abortController);\n if (res.failed?.length > 0) {\n return res.failed;\n }\n}\nexports.post = post;\n/**\n * @experimental API may change in future versions\n *\n * Close WebSocket connection, disconnect listeners and reconnect observers\n *\n * @example\n * await events.closeAll()\n *\n * @returns void on success\n * @throws on error\n */\nasync function closeAll() {\n await AWSAppSyncEventsProvider_1.AppSyncEventProvider.close();\n}\nexports.closeAll = closeAll;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,QAAQ,GAAG,OAAO,CAAC,IAAI,GAAG,OAAO,CAAC,OAAO,GAAG,MAAM;AAC1D,MAAM,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC;AAC3C,MAAM,OAAO,GAAG,OAAO,CAAC,mCAAmC,CAAC;AAC5D,MAAM,0BAA0B,GAAG,OAAO,CAAC,0CAA0C,CAAC;AACtF,MAAM,gBAAgB,GAAG,OAAO,CAAC,kBAAkB,CAAC;AACpD,MAAM,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC;AAClC;AACA,MAAM,YAAY,GAAG,IAAI,GAAG,EAAE;AAC9B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE;AACzC,IAAI,MAAM,eAAe,GAAG,IAAI,OAAO,CAAC,SAAS,GAAG;AACpD,IAAI,eAAe,CAAC,kBAAkB,GAAG,IAAI,OAAO,CAAC,aAAa,EAAE,OAAO,EAAE,QAAQ,EAAE,eAAe,CAAC,kBAAkB,CAAC;AAC1H,IAAI,MAAM,0BAA0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,MAAM,GAAG,GAAG,MAAM,IAAI,gBAAgB,CAAC,cAAc,EAAE,MAAM,CAAC,OAAO,EAAE,cAAc,EAAE,EAAE,EAAE,eAAe,CAAC;AAC/G,IAAI,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,EAAE;AAChC,QAAQ,OAAO,GAAG,CAAC,MAAM;AACzB;AACA;AACA,OAAO,CAAC,IAAI,GAAG,IAAI;AACnB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,QAAQ,GAAG;AAC1B,IAAI,MAAM,0BAA0B,CAAC,oBAAoB,CAAC,KAAK,EAAE;AACjE;AACA,OAAO,CAAC,QAAQ,GAAG,QAAQ;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../../src/internals/events/index.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.closeAll = exports.post = exports.connect = void 0;\nconst core_1 = require(\"@aws-amplify/core\");\nconst utils_1 = require(\"@aws-amplify/core/internals/utils\");\nconst AWSAppSyncEventsProvider_1 = require(\"../../Providers/AWSAppSyncEventsProvider\");\nconst appsyncRequest_1 = require(\"./appsyncRequest\");\nconst utils_2 = require(\"./utils\");\n// Keeps a list of open channels in the websocket\nconst openChannels = new Set();\n/**\n * @experimental API may change in future versions\n *\n * Establish a WebSocket connection to an Events channel\n *\n * @example\n * const channel = await events.connect(\"default/channel\")\n *\n * channel.subscribe({\n * next: (data) => { console.log(data) },\n * error: (err) => { console.error(err) },\n * })\n *\n * @example // authMode override\n * const channel = await events.connect(\"default/channel\", { authMode: \"userPool\" })\n *\n * @param channel - channel path; `<namespace>/<channel>`\n * @param options - request overrides: `authMode`, `authToken`\n *\n */\nasync function connect(channel, options) {\n const providerOptions = (0, utils_2.configure)();\n providerOptions.authenticationType = (0, utils_2.normalizeAuth)(options?.authMode, providerOptions.authenticationType);\n providerOptions.apiKey = options?.apiKey || providerOptions.apiKey;\n providerOptions.authToken = options?.authToken || providerOptions.authToken;\n await AWSAppSyncEventsProvider_1.AppSyncEventProvider.connect(providerOptions);\n const channelId = (0, utils_1.amplifyUuid)();\n openChannels.add(channelId);\n let _subscription;\n const sub = (observer, subOptions) => {\n if (!openChannels.has(channelId)) {\n throw new Error('Channel is closed');\n }\n const subscribeOptions = { ...providerOptions, query: channel };\n subscribeOptions.authenticationType = (0, utils_2.normalizeAuth)(subOptions?.authMode, subscribeOptions.authenticationType);\n subscribeOptions.apiKey = subOptions?.apiKey || subscribeOptions.apiKey;\n subscribeOptions.authToken =\n subOptions?.authToken || subscribeOptions.authToken;\n _subscription = AWSAppSyncEventsProvider_1.AppSyncEventProvider\n .subscribe(subscribeOptions)\n .subscribe(observer);\n return _subscription;\n };\n const pub = async (event, pubOptions) => {\n if (!openChannels.has(channelId)) {\n throw new Error('Channel is closed');\n }\n const publishOptions = {\n ...providerOptions,\n query: channel,\n variables: event,\n };\n publishOptions.authenticationType = (0, utils_2.normalizeAuth)(pubOptions?.authMode, publishOptions.authenticationType);\n publishOptions.apiKey = pubOptions?.apiKey || publishOptions.apiKey;\n publishOptions.authToken =\n pubOptions?.authToken || publishOptions.authToken;\n return AWSAppSyncEventsProvider_1.AppSyncEventProvider.publish(publishOptions);\n };\n const close = async () => {\n _subscription && _subscription.unsubscribe();\n openChannels.delete(channelId);\n setTimeout(() => {\n if (openChannels.size === 0) {\n AWSAppSyncEventsProvider_1.AppSyncEventProvider.closeIfNoActiveSubscription();\n }\n }, 1000);\n };\n return {\n subscribe: sub,\n close,\n publish: pub,\n };\n}\nexports.connect = connect;\n/**\n * @experimental API may change in future versions\n *\n * Publish events to a channel via HTTP request\n *\n * @example\n * await events.post(\"default/channel\", { some: \"event\" })\n *\n * @example // event batching\n * await events.post(\"default/channel\", [{ some: \"event\" }, { some: \"event2\" }])\n *\n * @example // authMode override\n * await events.post(\"default/channel\", { some: \"event\" }, { authMode: \"userPool\" })\n *\n * @param channel - channel path; `<namespace>/<channel>`\n * @param event - JSON-serializable value or an array of values\n * @param options - request overrides: `authMode`, `authToken`\n *\n * @returns void on success\n * @throws on error\n */\nasync function post(channel, event, options) {\n const providerOptions = (0, utils_2.configure)();\n providerOptions.authenticationType = (0, utils_2.normalizeAuth)(options?.authMode, providerOptions.authenticationType);\n providerOptions.apiKey = options?.apiKey || providerOptions.apiKey;\n providerOptions.authToken = options?.authToken || providerOptions.authToken;\n // trailing slash required in publish\n const normalizedChannelName = channel[0] === '/' ? channel : `/${channel}`;\n const publishOptions = {\n ...providerOptions,\n query: normalizedChannelName,\n variables: (0, utils_2.serializeEvents)(event),\n };\n const abortController = new AbortController();\n const res = await (0, appsyncRequest_1.appsyncRequest)(core_1.Amplify, publishOptions, {}, abortController);\n if (res.failed?.length > 0) {\n return res.failed;\n }\n}\nexports.post = post;\n/**\n * @experimental API may change in future versions\n *\n * Close WebSocket connection, disconnect listeners and reconnect observers\n *\n * @example\n * await events.closeAll()\n *\n * @returns void on success\n * @throws on error\n */\nasync function closeAll() {\n await AWSAppSyncEventsProvider_1.AppSyncEventProvider.close();\n}\nexports.closeAll = closeAll;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,QAAQ,GAAG,OAAO,CAAC,IAAI,GAAG,OAAO,CAAC,OAAO,GAAG,MAAM;AAC1D,MAAM,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC;AAC3C,MAAM,OAAO,GAAG,OAAO,CAAC,mCAAmC,CAAC;AAC5D,MAAM,0BAA0B,GAAG,OAAO,CAAC,0CAA0C,CAAC;AACtF,MAAM,gBAAgB,GAAG,OAAO,CAAC,kBAAkB,CAAC;AACpD,MAAM,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC;AAClC;AACA,MAAM,YAAY,GAAG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AAC,IAAI,GAAG,IAAI;AACnB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,QAAQ,GAAG;AAC1B,IAAI,MAAM,0BAA0B,CAAC,oBAAoB,CAAC,KAAK,EAAE;AACjE;AACA,OAAO,CAAC,QAAQ,GAAG,QAAQ;;"}
@@ -31,6 +31,8 @@ const openChannels = new Set();
31
31
  async function connect(channel, options) {
32
32
  const providerOptions = configure();
33
33
  providerOptions.authenticationType = normalizeAuth(options?.authMode, providerOptions.authenticationType);
34
+ providerOptions.apiKey = options?.apiKey || providerOptions.apiKey;
35
+ providerOptions.authToken = options?.authToken || providerOptions.authToken;
34
36
  await AppSyncEventProvider.connect(providerOptions);
35
37
  const channelId = amplifyUuid();
36
38
  openChannels.add(channelId);
@@ -41,6 +43,9 @@ async function connect(channel, options) {
41
43
  }
42
44
  const subscribeOptions = { ...providerOptions, query: channel };
43
45
  subscribeOptions.authenticationType = normalizeAuth(subOptions?.authMode, subscribeOptions.authenticationType);
46
+ subscribeOptions.apiKey = subOptions?.apiKey || subscribeOptions.apiKey;
47
+ subscribeOptions.authToken =
48
+ subOptions?.authToken || subscribeOptions.authToken;
44
49
  _subscription = AppSyncEventProvider
45
50
  .subscribe(subscribeOptions)
46
51
  .subscribe(observer);
@@ -56,6 +61,9 @@ async function connect(channel, options) {
56
61
  variables: event,
57
62
  };
58
63
  publishOptions.authenticationType = normalizeAuth(pubOptions?.authMode, publishOptions.authenticationType);
64
+ publishOptions.apiKey = pubOptions?.apiKey || publishOptions.apiKey;
65
+ publishOptions.authToken =
66
+ pubOptions?.authToken || publishOptions.authToken;
59
67
  return AppSyncEventProvider.publish(publishOptions);
60
68
  };
61
69
  const close = async () => {
@@ -97,13 +105,14 @@ async function connect(channel, options) {
97
105
  async function post(channel, event, options) {
98
106
  const providerOptions = configure();
99
107
  providerOptions.authenticationType = normalizeAuth(options?.authMode, providerOptions.authenticationType);
108
+ providerOptions.apiKey = options?.apiKey || providerOptions.apiKey;
109
+ providerOptions.authToken = options?.authToken || providerOptions.authToken;
100
110
  // trailing slash required in publish
101
111
  const normalizedChannelName = channel[0] === '/' ? channel : `/${channel}`;
102
112
  const publishOptions = {
103
113
  ...providerOptions,
104
114
  query: normalizedChannelName,
105
115
  variables: serializeEvents(event),
106
- authToken: options?.authToken,
107
116
  };
108
117
  const abortController = new AbortController();
109
118
  const res = await appsyncRequest(Amplify, publishOptions, {}, abortController);
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../../../../src/internals/events/index.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';\nimport { amplifyUuid } from '@aws-amplify/core/internals/utils';\nimport { AppSyncEventProvider as eventProvider } from '../../Providers/AWSAppSyncEventsProvider';\nimport { appsyncRequest } from './appsyncRequest';\nimport { configure, normalizeAuth, serializeEvents } from './utils';\n// Keeps a list of open channels in the websocket\nconst openChannels = new Set();\n/**\n * @experimental API may change in future versions\n *\n * Establish a WebSocket connection to an Events channel\n *\n * @example\n * const channel = await events.connect(\"default/channel\")\n *\n * channel.subscribe({\n * next: (data) => { console.log(data) },\n * error: (err) => { console.error(err) },\n * })\n *\n * @example // authMode override\n * const channel = await events.connect(\"default/channel\", { authMode: \"userPool\" })\n *\n * @param channel - channel path; `<namespace>/<channel>`\n * @param options - request overrides: `authMode`, `authToken`\n *\n */\nasync function connect(channel, options) {\n const providerOptions = configure();\n providerOptions.authenticationType = normalizeAuth(options?.authMode, providerOptions.authenticationType);\n await eventProvider.connect(providerOptions);\n const channelId = amplifyUuid();\n openChannels.add(channelId);\n let _subscription;\n const sub = (observer, subOptions) => {\n if (!openChannels.has(channelId)) {\n throw new Error('Channel is closed');\n }\n const subscribeOptions = { ...providerOptions, query: channel };\n subscribeOptions.authenticationType = normalizeAuth(subOptions?.authMode, subscribeOptions.authenticationType);\n _subscription = eventProvider\n .subscribe(subscribeOptions)\n .subscribe(observer);\n return _subscription;\n };\n const pub = async (event, pubOptions) => {\n if (!openChannels.has(channelId)) {\n throw new Error('Channel is closed');\n }\n const publishOptions = {\n ...providerOptions,\n query: channel,\n variables: event,\n };\n publishOptions.authenticationType = normalizeAuth(pubOptions?.authMode, publishOptions.authenticationType);\n return eventProvider.publish(publishOptions);\n };\n const close = async () => {\n _subscription && _subscription.unsubscribe();\n openChannels.delete(channelId);\n setTimeout(() => {\n if (openChannels.size === 0) {\n eventProvider.closeIfNoActiveSubscription();\n }\n }, 1000);\n };\n return {\n subscribe: sub,\n close,\n publish: pub,\n };\n}\n/**\n * @experimental API may change in future versions\n *\n * Publish events to a channel via HTTP request\n *\n * @example\n * await events.post(\"default/channel\", { some: \"event\" })\n *\n * @example // event batching\n * await events.post(\"default/channel\", [{ some: \"event\" }, { some: \"event2\" }])\n *\n * @example // authMode override\n * await events.post(\"default/channel\", { some: \"event\" }, { authMode: \"userPool\" })\n *\n * @param channel - channel path; `<namespace>/<channel>`\n * @param event - JSON-serializable value or an array of values\n * @param options - request overrides: `authMode`, `authToken`\n *\n * @returns void on success\n * @throws on error\n */\nasync function post(channel, event, options) {\n const providerOptions = configure();\n providerOptions.authenticationType = normalizeAuth(options?.authMode, providerOptions.authenticationType);\n // trailing slash required in publish\n const normalizedChannelName = channel[0] === '/' ? channel : `/${channel}`;\n const publishOptions = {\n ...providerOptions,\n query: normalizedChannelName,\n variables: serializeEvents(event),\n authToken: options?.authToken,\n };\n const abortController = new AbortController();\n const res = await appsyncRequest(Amplify, publishOptions, {}, abortController);\n if (res.failed?.length > 0) {\n return res.failed;\n }\n}\n/**\n * @experimental API may change in future versions\n *\n * Close WebSocket connection, disconnect listeners and reconnect observers\n *\n * @example\n * await events.closeAll()\n *\n * @returns void on success\n * @throws on error\n */\nasync function closeAll() {\n await eventProvider.close();\n}\nexport { connect, post, closeAll };\n"],"names":["eventProvider"],"mappings":";;;;;;AAAA;AACA;AAMA;AACA,MAAM,YAAY,GAAG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,CAAC,KAAK,CAAC;AACzC,QAAQ,SAAS,EAAE,OAAO,EAAE,SAAS;AACrC,KAAK;AACL,IAAI,MAAM,eAAe,GAAG,IAAI,eAAe,EAAE;AACjD,IAAI,MAAM,GAAG,GAAG,MAAM,cAAc,CAAC,OAAO,EAAE,cAAc,EAAE,EAAE,EAAE,eAAe,CAAC;AAClF,IAAI,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,EAAE;AAChC,QAAQ,OAAO,GAAG,CAAC,MAAM;AACzB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,QAAQ,GAAG;AAC1B,IAAI,MAAMA,oBAAa,CAAC,KAAK,EAAE;AAC/B;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":["../../../../src/internals/events/index.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';\nimport { amplifyUuid } from '@aws-amplify/core/internals/utils';\nimport { AppSyncEventProvider as eventProvider } from '../../Providers/AWSAppSyncEventsProvider';\nimport { appsyncRequest } from './appsyncRequest';\nimport { configure, normalizeAuth, serializeEvents } from './utils';\n// Keeps a list of open channels in the websocket\nconst openChannels = new Set();\n/**\n * @experimental API may change in future versions\n *\n * Establish a WebSocket connection to an Events channel\n *\n * @example\n * const channel = await events.connect(\"default/channel\")\n *\n * channel.subscribe({\n * next: (data) => { console.log(data) },\n * error: (err) => { console.error(err) },\n * })\n *\n * @example // authMode override\n * const channel = await events.connect(\"default/channel\", { authMode: \"userPool\" })\n *\n * @param channel - channel path; `<namespace>/<channel>`\n * @param options - request overrides: `authMode`, `authToken`\n *\n */\nasync function connect(channel, options) {\n const providerOptions = configure();\n providerOptions.authenticationType = normalizeAuth(options?.authMode, providerOptions.authenticationType);\n providerOptions.apiKey = options?.apiKey || providerOptions.apiKey;\n providerOptions.authToken = options?.authToken || providerOptions.authToken;\n await eventProvider.connect(providerOptions);\n const channelId = amplifyUuid();\n openChannels.add(channelId);\n let _subscription;\n const sub = (observer, subOptions) => {\n if (!openChannels.has(channelId)) {\n throw new Error('Channel is closed');\n }\n const subscribeOptions = { ...providerOptions, query: channel };\n subscribeOptions.authenticationType = normalizeAuth(subOptions?.authMode, subscribeOptions.authenticationType);\n subscribeOptions.apiKey = subOptions?.apiKey || subscribeOptions.apiKey;\n subscribeOptions.authToken =\n subOptions?.authToken || subscribeOptions.authToken;\n _subscription = eventProvider\n .subscribe(subscribeOptions)\n .subscribe(observer);\n return _subscription;\n };\n const pub = async (event, pubOptions) => {\n if (!openChannels.has(channelId)) {\n throw new Error('Channel is closed');\n }\n const publishOptions = {\n ...providerOptions,\n query: channel,\n variables: event,\n };\n publishOptions.authenticationType = normalizeAuth(pubOptions?.authMode, publishOptions.authenticationType);\n publishOptions.apiKey = pubOptions?.apiKey || publishOptions.apiKey;\n publishOptions.authToken =\n pubOptions?.authToken || publishOptions.authToken;\n return eventProvider.publish(publishOptions);\n };\n const close = async () => {\n _subscription && _subscription.unsubscribe();\n openChannels.delete(channelId);\n setTimeout(() => {\n if (openChannels.size === 0) {\n eventProvider.closeIfNoActiveSubscription();\n }\n }, 1000);\n };\n return {\n subscribe: sub,\n close,\n publish: pub,\n };\n}\n/**\n * @experimental API may change in future versions\n *\n * Publish events to a channel via HTTP request\n *\n * @example\n * await events.post(\"default/channel\", { some: \"event\" })\n *\n * @example // event batching\n * await events.post(\"default/channel\", [{ some: \"event\" }, { some: \"event2\" }])\n *\n * @example // authMode override\n * await events.post(\"default/channel\", { some: \"event\" }, { authMode: \"userPool\" })\n *\n * @param channel - channel path; `<namespace>/<channel>`\n * @param event - JSON-serializable value or an array of values\n * @param options - request overrides: `authMode`, `authToken`\n *\n * @returns void on success\n * @throws on error\n */\nasync function post(channel, event, options) {\n const providerOptions = configure();\n providerOptions.authenticationType = normalizeAuth(options?.authMode, providerOptions.authenticationType);\n providerOptions.apiKey = options?.apiKey || providerOptions.apiKey;\n providerOptions.authToken = options?.authToken || providerOptions.authToken;\n // trailing slash required in publish\n const normalizedChannelName = channel[0] === '/' ? channel : `/${channel}`;\n const publishOptions = {\n ...providerOptions,\n query: normalizedChannelName,\n variables: serializeEvents(event),\n };\n const abortController = new AbortController();\n const res = await appsyncRequest(Amplify, publishOptions, {}, abortController);\n if (res.failed?.length > 0) {\n return res.failed;\n }\n}\n/**\n * @experimental API may change in future versions\n *\n * Close WebSocket connection, disconnect listeners and reconnect observers\n *\n * @example\n * await events.closeAll()\n *\n * @returns void on success\n * @throws on error\n */\nasync function closeAll() {\n await eventProvider.close();\n}\nexport { connect, post, closeAll };\n"],"names":["eventProvider"],"mappings":";;;;;;AAAA;AACA;AAMA;AACA,MAAM,YAAY,GAAG,IAAI,GAAG,EAAE;AAC9B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE;AACzC,IAAI,MAAM,eAAe,GAAG,SAAS,EAAE;AACvC,IAAI,eAAe,CAAC,kBAAkB,GAAG,aAAa,CAAC,OAAO,EAAE,QAAQ,EAAE,eAAe,CAAC,kBAAkB,CAAC;AAC7G,IAAI,eAAe,CAAC,MAAM,GAAG,OAAO,EAAE,MAAM,IAAI,eAAe,CAAC,MAAM;AACtE,IAAI,eAAe,CAAC,SAAS,GAAG,OAAO,EAAE,SAAS,IAAI,eAAe,CAAC,SAAS;AAC/E,IAAI,MAAMA,oBAAa,CAAC,OAAO,CAAC,eAAe,CAAC;AAChD,IAAI,MAAM,SAAS,GAAG,WAAW,EAAE;AACnC,IAAI,YAAY,CAAC,GAAG,CAAC,SAAS,CAAC;AAC/B,IAAI,IAAI,aAAa;AACrB,IAAI,MAAM,GAAG,GAAG,CAAC,QAAQ,EAAE,UAAU,KAAK;AAC1C,QAAQ,IAAI,CAAC,YAAY,CAAC,GAAG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AAI,MAAM,GAAG,GAAG,MAAM,cAAc,CAAC,OAAO,EAAE,cAAc,EAAE,EAAE,EAAE,eAAe,CAAC;AAClF,IAAI,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,EAAE;AAChC,QAAQ,OAAO,GAAG,CAAC,MAAM;AACzB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,QAAQ,GAAG;AAC1B,IAAI,MAAMA,oBAAa,CAAC,KAAK,EAAE;AAC/B;;;;"}
@@ -71,6 +71,7 @@ export type ResolvedGraphQLAuthModes = Exclude<GraphQLAuthMode, 'identityPool'>;
71
71
  export interface EventsOptions {
72
72
  authMode?: GraphQLAuthMode;
73
73
  authToken?: string;
74
+ apiKey?: string;
74
75
  }
75
76
  export interface PublishedEvent {
76
77
  identifier: string;
@@ -80,3 +81,13 @@ export interface PublishResponse {
80
81
  failed: PublishedEvent[];
81
82
  successful: PublishedEvent[];
82
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 {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-amplify/api-graphql",
3
- "version": "4.7.13-unstable.34b927a.0+34b927a",
3
+ "version": "4.7.13-unstable.db70f7b.0+db70f7b",
4
4
  "description": "Api-graphql category of aws-amplify",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.mjs",
@@ -84,8 +84,8 @@
84
84
  "server"
85
85
  ],
86
86
  "dependencies": {
87
- "@aws-amplify/api-rest": "4.1.2-unstable.34b927a.0+34b927a",
88
- "@aws-amplify/core": "6.11.2-unstable.34b927a.0+34b927a",
87
+ "@aws-amplify/api-rest": "4.1.2-unstable.db70f7b.0+db70f7b",
88
+ "@aws-amplify/core": "6.11.2-unstable.db70f7b.0+db70f7b",
89
89
  "@aws-amplify/data-schema": "^1.7.0",
90
90
  "@aws-sdk/types": "3.387.0",
91
91
  "graphql": "15.8.0",
@@ -101,5 +101,5 @@
101
101
  "limit": "91.7 kB"
102
102
  }
103
103
  ],
104
- "gitHead": "34b927ae760e3f525f5a8c932b871998f34bd5a0"
104
+ "gitHead": "db70f7be22711c6bf03fe68d7d3d3d93070d9a85"
105
105
  }
@@ -12,6 +12,7 @@ import { configure, normalizeAuth, serializeEvents } from './utils';
12
12
  import type {
13
13
  EventsChannel,
14
14
  EventsOptions,
15
+ ProviderOptions,
15
16
  PublishResponse,
16
17
  PublishedEvent,
17
18
  SubscriptionObserver,
@@ -44,12 +45,14 @@ async function connect(
44
45
  channel: string,
45
46
  options?: EventsOptions,
46
47
  ): Promise<EventsChannel> {
47
- const providerOptions = configure();
48
+ const providerOptions: ProviderOptions = configure();
48
49
 
49
50
  providerOptions.authenticationType = normalizeAuth(
50
51
  options?.authMode,
51
52
  providerOptions.authenticationType,
52
53
  );
54
+ providerOptions.apiKey = options?.apiKey || providerOptions.apiKey;
55
+ providerOptions.authToken = options?.authToken || providerOptions.authToken;
53
56
 
54
57
  await eventProvider.connect(providerOptions);
55
58
 
@@ -70,6 +73,9 @@ async function connect(
70
73
  subOptions?.authMode,
71
74
  subscribeOptions.authenticationType,
72
75
  );
76
+ subscribeOptions.apiKey = subOptions?.apiKey || subscribeOptions.apiKey;
77
+ subscribeOptions.authToken =
78
+ subOptions?.authToken || subscribeOptions.authToken;
73
79
 
74
80
  _subscription = eventProvider
75
81
  .subscribe(subscribeOptions)
@@ -94,6 +100,9 @@ async function connect(
94
100
  pubOptions?.authMode,
95
101
  publishOptions.authenticationType,
96
102
  );
103
+ publishOptions.apiKey = pubOptions?.apiKey || publishOptions.apiKey;
104
+ publishOptions.authToken =
105
+ pubOptions?.authToken || publishOptions.authToken;
97
106
 
98
107
  return eventProvider.publish(publishOptions);
99
108
  };
@@ -141,11 +150,13 @@ async function post(
141
150
  event: DocumentType | DocumentType[],
142
151
  options?: EventsOptions,
143
152
  ): Promise<void | PublishedEvent[]> {
144
- const providerOptions = configure();
153
+ const providerOptions: ProviderOptions = configure();
145
154
  providerOptions.authenticationType = normalizeAuth(
146
155
  options?.authMode,
147
156
  providerOptions.authenticationType,
148
157
  );
158
+ providerOptions.apiKey = options?.apiKey || providerOptions.apiKey;
159
+ providerOptions.authToken = options?.authToken || providerOptions.authToken;
149
160
 
150
161
  // trailing slash required in publish
151
162
  const normalizedChannelName = channel[0] === '/' ? channel : `/${channel}`;
@@ -154,7 +165,6 @@ async function post(
154
165
  ...providerOptions,
155
166
  query: normalizedChannelName,
156
167
  variables: serializeEvents(event),
157
- authToken: options?.authToken,
158
168
  };
159
169
 
160
170
  const abortController = new AbortController();
@@ -84,6 +84,7 @@ export type ResolvedGraphQLAuthModes = Exclude<GraphQLAuthMode, 'identityPool'>;
84
84
  export interface EventsOptions {
85
85
  authMode?: GraphQLAuthMode;
86
86
  authToken?: string;
87
+ apiKey?: string;
87
88
  }
88
89
 
89
90
  export interface PublishedEvent {
@@ -95,3 +96,14 @@ export interface PublishResponse {
95
96
  failed: PublishedEvent[];
96
97
  successful: PublishedEvent[];
97
98
  }
99
+
100
+ interface EventsConfigure {
101
+ appSyncGraphqlEndpoint: string;
102
+ region?: string;
103
+ authenticationType: ResolvedGraphQLAuthModes;
104
+ apiKey?: string;
105
+ }
106
+
107
+ export type ProviderOptions = EventsConfigure & {
108
+ authToken?: string;
109
+ };