@awsless/awsless 0.0.401 → 0.0.402

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.
package/dist/bin.js CHANGED
@@ -12288,6 +12288,7 @@ var pubsubFeature = defineFeature({
12288
12288
  const authorizer = new aws13.iot.Authorizer(group, "authorizer", {
12289
12289
  name,
12290
12290
  functionArn: lambda.arn
12291
+ // enableSigning: false,
12291
12292
  });
12292
12293
  new aws13.lambda.Permission(group, "permission", {
12293
12294
  functionArn: lambda.arn,
package/dist/client.d.ts CHANGED
@@ -56,13 +56,12 @@ declare const createHttpClient: <S extends Schema>(fetcher: HttpFetcher) => {
56
56
 
57
57
  type MessageCallback = (payload: any) => void;
58
58
  type ClientProps = {
59
- app: string;
60
59
  endpoint: string;
61
60
  authorizer: string;
62
61
  token?: string;
63
62
  };
64
63
  type ClientPropsProvider = () => Promise<ClientProps> | ClientProps;
65
- declare const createPubSubClient: (props: ClientProps | ClientPropsProvider) => {
64
+ declare const createPubSubClient: (app: string, props: ClientProps | ClientPropsProvider) => {
66
65
  publish(topic: string, event: string, payload: unknown, qos: QoS): Promise<void>;
67
66
  subscribe(topic: string, event: string, callback: MessageCallback): Promise<_awsless_mqtt.Unsubscribe>;
68
67
  connected: boolean;
package/dist/client.js CHANGED
@@ -80,11 +80,9 @@ var createHttpClient = (fetcher) => {
80
80
 
81
81
  // src/lib/client/pubsub.ts
82
82
  import { createClient } from "@awsless/mqtt";
83
- var createPubSubClient = (props) => {
84
- let app;
83
+ var createPubSubClient = (app, props) => {
85
84
  const mqtt = createClient(async () => {
86
85
  const config = typeof props === "function" ? await props() : props;
87
- app = config.app;
88
86
  return {
89
87
  endpoint: `wss://${config.endpoint}/mqtt`,
90
88
  username: `?x-amz-customauthorizer-name=${config.authorizer}`,
Binary file
package/dist/server.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import { AwsCredentialIdentityProvider } from '@aws-sdk/types';
2
2
  import { Mock } from 'vitest';
3
+ import { Duration, DurationFormat } from '@awsless/duration';
3
4
  import { QoS } from '@awsless/iot';
4
5
  export { QoS } from '@awsless/iot';
5
- import { DurationFormat } from '@awsless/duration';
6
+ import { IoTCustomAuthorizerResult } from 'aws-lambda';
6
7
 
7
8
  declare const regions: readonly ["us-east-2", "us-east-1", "us-west-1", "us-west-2", "af-south-1", "ap-east-1", "ap-south-2", "ap-southeast-3", "ap-southeast-4", "ap-south-1", "ap-northeast-3", "ap-northeast-2", "ap-southeast-1", "ap-southeast-2", "ap-northeast-1", "ca-central-1", "eu-central-1", "eu-west-1", "eu-west-2", "eu-south-1", "eu-west-3", "eu-south-2", "eu-north-1", "eu-central-2", "me-south-1", "me-central-1", "sa-east-1"];
8
9
  type Region = (typeof regions)[number];
@@ -89,6 +90,23 @@ type PublishOptions = {
89
90
  declare const PubSub: {
90
91
  publish(topic: string, event: string, payload: unknown, opts?: PublishOptions): Promise<void>;
91
92
  };
93
+ type PubsubAuthorizerResponse = {
94
+ authorized: boolean;
95
+ principalId?: string;
96
+ publish?: string[];
97
+ subscribe?: string[];
98
+ disconnectAfter?: Duration;
99
+ refreshAfter?: Duration;
100
+ };
101
+ type PubsubAuthorizerEvent = {
102
+ protocolData: {
103
+ mqtt?: {
104
+ password?: string;
105
+ };
106
+ };
107
+ };
108
+ declare const pubsubAuthorizerHandle: (cb: (token: string) => PubsubAuthorizerResponse | Promise<PubsubAuthorizerResponse>) => Promise<(event: PubsubAuthorizerEvent) => Promise<IoTCustomAuthorizerResult>>;
109
+ declare const pubsubAuthorizerResponse: (props: PubsubAuthorizerResponse) => IoTCustomAuthorizerResult;
92
110
 
93
111
  declare const getQueueName: <N extends string, S extends string = "stack">(resourceName: N, stackName?: S) => `app--${S}--queue--${N}`;
94
112
  declare const getQueueUrl: (name: string, stack?: string) => string | undefined;
@@ -137,4 +155,4 @@ declare const Topic: TopicResources;
137
155
  declare const APP: "app";
138
156
  declare const STACK: "stack";
139
157
 
140
- export { APP, Auth, type AuthResources, Cache, type CacheResources, type CommandContext, type CommandHandler, CommandOptions, Config, type ConfigResources, Fn, Function, type FunctionMock, type FunctionMockResponse, type FunctionResources, PubSub, type PublishOptions, Queue, type QueueMock, type QueueMockResponse, type QueueResources, type RpcAuthorizerResponse, STACK, Search, type SearchResources, Store, type StoreResources, Table, type TableResources, Task, type TaskMock, type TaskMockResponse, type TaskResources, Topic, type TopicMock, type TopicMockResponse, type TopicResources, getAuthProps, getCacheProps, getConfigName, getConfigValue, getFunctionName, getPubSubTopic, getQueueName, getQueueUrl, getSearchName, getSearchProps, getSiteBucketName, getStoreName, getTableName, getTaskName, getTopicName, mockFunction, mockPubSub, mockQueue, mockTask, mockTopic, setConfigValue };
158
+ export { APP, Auth, type AuthResources, Cache, type CacheResources, type CommandContext, type CommandHandler, CommandOptions, Config, type ConfigResources, Fn, Function, type FunctionMock, type FunctionMockResponse, type FunctionResources, PubSub, type PublishOptions, Queue, type QueueMock, type QueueMockResponse, type QueueResources, type RpcAuthorizerResponse, STACK, Search, type SearchResources, Store, type StoreResources, Table, type TableResources, Task, type TaskMock, type TaskMockResponse, type TaskResources, Topic, type TopicMock, type TopicMockResponse, type TopicResources, getAuthProps, getCacheProps, getConfigName, getConfigValue, getFunctionName, getPubSubTopic, getQueueName, getQueueUrl, getSearchName, getSearchProps, getSiteBucketName, getStoreName, getTableName, getTaskName, getTopicName, mockFunction, mockPubSub, mockQueue, mockTask, mockTopic, pubsubAuthorizerHandle, pubsubAuthorizerResponse, setConfigValue };
package/dist/server.js CHANGED
@@ -363,6 +363,7 @@ var Config = /* @__PURE__ */ new Proxy(
363
363
  );
364
364
 
365
365
  // src/lib/server/pubsub.ts
366
+ import { hours, toSeconds } from "@awsless/duration";
366
367
  import { publish as publish2, QoS } from "@awsless/iot";
367
368
  var getPubSubTopic = (name) => {
368
369
  return `${APP}/pubsub/${name}`;
@@ -376,6 +377,65 @@ var PubSub = {
376
377
  });
377
378
  }
378
379
  };
380
+ var pubsubAuthorizerHandle = async (cb) => {
381
+ return async (event) => {
382
+ const token = Buffer.from(event.protocolData.mqtt?.password ?? "", "base64").toString();
383
+ const response = await cb(token);
384
+ return pubsubAuthorizerResponse(response);
385
+ };
386
+ };
387
+ var pubsubAuthorizerResponse = (props) => {
388
+ const region = process.env.AWS_REGION;
389
+ const accountId = process.env.AWS_ACCOUNT_ID;
390
+ const prefix = `arn:aws:iot:${region}:${accountId}`;
391
+ const statements = [];
392
+ if (props.publish) {
393
+ statements.push({
394
+ Action: "iot:Publish",
395
+ Effect: "Allow",
396
+ Resource: props.publish.map((topic) => {
397
+ return `${prefix}:topic/${topic}`;
398
+ })
399
+ });
400
+ }
401
+ if (props.subscribe) {
402
+ statements.push(
403
+ {
404
+ Action: "iot:Subscribe",
405
+ Effect: "Allow",
406
+ Resource: props.subscribe.map((topic) => {
407
+ return `${prefix}:topicfilter/${topic}`;
408
+ })
409
+ },
410
+ {
411
+ Action: "iot:Receive",
412
+ Effect: "Allow",
413
+ Resource: props.subscribe.map((topic) => {
414
+ return `${prefix}:topic/${topic}`;
415
+ })
416
+ }
417
+ );
418
+ }
419
+ return {
420
+ isAuthenticated: props.authorized,
421
+ principalId: props.principalId ?? Date.now().toString(),
422
+ disconnectAfterInSeconds: Number(toSeconds(props.disconnectAfter ?? hours(1))),
423
+ refreshAfterInSeconds: Number(toSeconds(props.disconnectAfter ?? hours(1))),
424
+ policyDocuments: [
425
+ {
426
+ Version: "2012-10-17",
427
+ Statement: [
428
+ {
429
+ Action: "iot:Connect",
430
+ Effect: "Allow",
431
+ Resource: `${prefix}:client/\${iot:ClientId}`
432
+ },
433
+ ...statements
434
+ ]
435
+ }
436
+ ]
437
+ };
438
+ };
379
439
 
380
440
  // src/lib/server/search.ts
381
441
  import { define, searchClient } from "@awsless/open-search";
@@ -483,5 +543,7 @@ export {
483
543
  mockQueue,
484
544
  mockTask,
485
545
  mockTopic,
546
+ pubsubAuthorizerHandle,
547
+ pubsubAuthorizerResponse,
486
548
  setConfigValue
487
549
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awsless/awsless",
3
- "version": "0.0.401",
3
+ "version": "0.0.402",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -28,17 +28,17 @@
28
28
  }
29
29
  },
30
30
  "peerDependencies": {
31
- "@awsless/iot": "^0.0.2",
32
31
  "@awsless/lambda": "^0.0.27",
33
- "@awsless/redis": "^0.0.13",
34
32
  "@awsless/mqtt": "^0.0.2",
35
- "@awsless/s3": "^0.0.18",
36
- "@awsless/sns": "^0.0.7",
37
- "@awsless/sqs": "^0.0.7",
38
- "@awsless/ssm": "^0.0.7",
39
33
  "@awsless/open-search": "^0.0.15",
34
+ "@awsless/iot": "^0.0.2",
35
+ "@awsless/redis": "^0.0.13",
36
+ "@awsless/ssm": "^0.0.7",
37
+ "@awsless/weak-cache": "^0.0.1",
40
38
  "@awsless/validate": "^0.0.16",
41
- "@awsless/weak-cache": "^0.0.1"
39
+ "@awsless/s3": "^0.0.18",
40
+ "@awsless/sqs": "^0.0.7",
41
+ "@awsless/sns": "^0.0.7"
42
42
  },
43
43
  "dependencies": {
44
44
  "@arcanyx/cidr-slicer": "^0.3.0",
@@ -112,12 +112,12 @@
112
112
  "zip-a-folder": "^3.1.6",
113
113
  "zod": "^3.21.4",
114
114
  "zod-to-json-schema": "^3.22.3",
115
- "@awsless/code": "^0.0.10",
116
115
  "@awsless/duration": "^0.0.1",
117
- "@awsless/formation": "^0.0.57",
118
116
  "@awsless/size": "^0.0.1",
119
- "@awsless/ts-file-cache": "^0.0.10",
117
+ "@awsless/formation": "^0.0.57",
120
118
  "@awsless/validate": "^0.0.16",
119
+ "@awsless/code": "^0.0.10",
120
+ "@awsless/ts-file-cache": "^0.0.10",
121
121
  "@awsless/graphql": "^0.0.9"
122
122
  },
123
123
  "devDependencies": {