@anchan828/nest-cloud-run-queue-tasks-publisher 3.1.7 → 3.1.9

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.
@@ -0,0 +1,3 @@
1
+ export declare const TASKS_PUBLISHER_MODULE_OPTIONS = "TASKS_PUBLISHER_MODULE_OPTIONS";
2
+ export declare const TASKS_CLIENT = "TASKS_CLIENT";
3
+ export declare const ERROR_QUEUE_NOT_FOUND = "Queue not found. Please set queue name.";
@@ -0,0 +1,3 @@
1
+ export const TASKS_PUBLISHER_MODULE_OPTIONS = "TASKS_PUBLISHER_MODULE_OPTIONS";
2
+ export const TASKS_CLIENT = "TASKS_CLIENT";
3
+ export const ERROR_QUEUE_NOT_FOUND = "Queue not found. Please set queue name.";
@@ -0,0 +1,4 @@
1
+ export { TasksPublisherModuleAsyncOptions, TasksPublisherModuleOptions, TasksPublisherModuleOptionsFactory, PublishConfig, PublishData, PublishOptions, } from "./interfaces";
2
+ export { TASKS_CLIENT } from "./constants";
3
+ export { TasksPublisherModule } from "./publish.module";
4
+ export { TasksPublisherService } from "./publish.service";
@@ -0,0 +1,3 @@
1
+ export { TASKS_CLIENT } from "./constants";
2
+ export { TasksPublisherModule } from "./publish.module";
3
+ export { TasksPublisherService } from "./publish.service";
@@ -0,0 +1,16 @@
1
+ import { Message, ModuleAsyncOptions, ModuleOptions, ModuleOptionsFactory, PublishExtraConfig } from "@anchan828/nest-cloud-run-queue-common";
2
+ import type { CloudTasksClient } from "@google-cloud/tasks";
3
+ import type { google } from "@google-cloud/tasks/build/protos/protos";
4
+ export interface TasksPublisherModuleOptions extends ModuleOptions {
5
+ queue?: string;
6
+ clientConfig?: ConstructorParameters<typeof CloudTasksClient>[0];
7
+ publishConfig?: PublishConfig;
8
+ extraConfig?: PublishExtraConfig;
9
+ }
10
+ export type TasksPublisherModuleAsyncOptions = ModuleAsyncOptions<TasksPublisherModuleOptions>;
11
+ export type TasksPublisherModuleOptionsFactory = ModuleOptionsFactory<TasksPublisherModuleOptions>;
12
+ export type PublishConfig = Omit<google.cloud.tasks.v2.ITask, "name">;
13
+ export type PublishOptions = {
14
+ queue?: string;
15
+ } & PublishConfig;
16
+ export type PublishData<T> = Message<T>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import { CloudTasksClient } from "@google-cloud/tasks";
2
+ import { TasksPublisherModuleOptions } from "./interfaces";
3
+ export declare function createClient(options: TasksPublisherModuleOptions): CloudTasksClient;
@@ -0,0 +1,4 @@
1
+ import { CloudTasksClient } from "@google-cloud/tasks";
2
+ export function createClient(options) {
3
+ return new CloudTasksClient(options.clientConfig);
4
+ }
@@ -0,0 +1,6 @@
1
+ import { DynamicModule } from "@nestjs/common";
2
+ import { TasksPublisherModuleAsyncOptions, TasksPublisherModuleOptions } from "./interfaces";
3
+ export declare class TasksPublisherModule {
4
+ static register(options?: TasksPublisherModuleOptions): DynamicModule;
5
+ static registerAsync(options: TasksPublisherModuleAsyncOptions): DynamicModule;
6
+ }
@@ -0,0 +1,50 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var TasksPublisherModule_1;
8
+ import { createAsyncProviders, createOptionProvider } from "@anchan828/nest-cloud-run-queue-common";
9
+ import { Module } from "@nestjs/common";
10
+ import { TASKS_CLIENT, TASKS_PUBLISHER_MODULE_OPTIONS } from "./constants";
11
+ import { createClient } from "./providers";
12
+ import { TasksPublisherService } from "./publish.service";
13
+ let TasksPublisherModule = TasksPublisherModule_1 = class TasksPublisherModule {
14
+ static register(options = {}) {
15
+ const providers = [
16
+ createOptionProvider(TASKS_PUBLISHER_MODULE_OPTIONS, options),
17
+ TasksPublisherService,
18
+ { provide: TASKS_CLIENT, useFactory: () => createClient(options) },
19
+ ];
20
+ return {
21
+ exports: providers,
22
+ global: true,
23
+ module: TasksPublisherModule_1,
24
+ providers,
25
+ };
26
+ }
27
+ static registerAsync(options) {
28
+ const asyncProviders = [
29
+ ...createAsyncProviders(TASKS_PUBLISHER_MODULE_OPTIONS, options),
30
+ TasksPublisherService,
31
+ {
32
+ inject: [TASKS_PUBLISHER_MODULE_OPTIONS],
33
+ provide: TASKS_CLIENT,
34
+ useFactory: (options) => createClient(options),
35
+ },
36
+ ];
37
+ const providers = [...asyncProviders];
38
+ return {
39
+ exports: providers,
40
+ global: true,
41
+ imports: [...(options.imports || [])],
42
+ module: TasksPublisherModule_1,
43
+ providers,
44
+ };
45
+ }
46
+ };
47
+ TasksPublisherModule = TasksPublisherModule_1 = __decorate([
48
+ Module({})
49
+ ], TasksPublisherModule);
50
+ export { TasksPublisherModule };
@@ -0,0 +1,8 @@
1
+ import { CloudTasksClient } from "@google-cloud/tasks";
2
+ import { PublishData, PublishOptions, TasksPublisherModuleOptions } from "./interfaces";
3
+ export declare class TasksPublisherService {
4
+ private readonly options;
5
+ private readonly client;
6
+ constructor(options: TasksPublisherModuleOptions, client: CloudTasksClient);
7
+ publish<T>(message: PublishData<T>, options?: PublishOptions): Promise<string>;
8
+ }
@@ -0,0 +1,57 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
11
+ return function (target, key) { decorator(target, key, paramIndex); }
12
+ };
13
+ import { CloudTasksClient } from "@google-cloud/tasks";
14
+ import { Inject, Injectable } from "@nestjs/common";
15
+ import { TASKS_CLIENT, TASKS_PUBLISHER_MODULE_OPTIONS } from "./constants";
16
+ let TasksPublisherService = class TasksPublisherService {
17
+ constructor(options, client) {
18
+ this.options = options;
19
+ this.client = client;
20
+ }
21
+ async publish(message, options) {
22
+ const taskMessage = this.options.extraConfig?.prePublish
23
+ ? await this.options.extraConfig?.prePublish(message)
24
+ : message;
25
+ const [task] = await this.client.createTask({
26
+ parent: options?.queue || this.options.queue,
27
+ task: {
28
+ ...this.options.publishConfig,
29
+ ...options,
30
+ httpRequest: {
31
+ body: Buffer.from(JSON.stringify({ message: taskMessage || {} }, this.options.extraConfig?.stringifyReplacer)).toString("base64"),
32
+ headers: {
33
+ "content-type": "application/json",
34
+ ...options?.httpRequest?.headers,
35
+ ...this.options.publishConfig?.httpRequest?.headers,
36
+ },
37
+ httpMethod: options?.httpRequest?.httpMethod || this.options.publishConfig?.httpRequest?.httpMethod || "POST",
38
+ oauthToken: options?.httpRequest?.oauthToken || this.options.publishConfig?.httpRequest?.oauthToken,
39
+ oidcToken: options?.httpRequest?.oidcToken || this.options.publishConfig?.httpRequest?.oidcToken,
40
+ url: options?.httpRequest?.url || this.options.publishConfig?.httpRequest?.url,
41
+ },
42
+ },
43
+ });
44
+ const taskName = task?.name || "";
45
+ if (this.options.extraConfig?.postPublish) {
46
+ await this.options.extraConfig?.postPublish(taskMessage, taskName);
47
+ }
48
+ return taskName;
49
+ }
50
+ };
51
+ TasksPublisherService = __decorate([
52
+ Injectable(),
53
+ __param(0, Inject(TASKS_PUBLISHER_MODULE_OPTIONS)),
54
+ __param(1, Inject(TASKS_CLIENT)),
55
+ __metadata("design:paramtypes", [Object, CloudTasksClient])
56
+ ], TasksPublisherService);
57
+ export { TasksPublisherService };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anchan828/nest-cloud-run-queue-tasks-publisher",
3
- "version": "3.1.7",
3
+ "version": "3.1.9",
4
4
  "description": "> TODO: description",
5
5
  "homepage": "https://github.com/anchan828/nest-cloud-run-queue/tree/master/packages/pubsub-publish#readme",
6
6
  "bugs": {
@@ -12,8 +12,8 @@
12
12
  },
13
13
  "license": "MIT",
14
14
  "author": "anchan828 <anchan828@gmail.com>",
15
- "main": "./dist/index.js",
16
- "types": "./dist/index.d.ts",
15
+ "main": "dist/cjs/index.js",
16
+ "types": "dist/cjs/index.d.ts",
17
17
  "directories": {
18
18
  "dist": "dist"
19
19
  },
@@ -21,7 +21,7 @@
21
21
  "dist"
22
22
  ],
23
23
  "scripts": {
24
- "build": "tsc -p tsconfig.build.json",
24
+ "build": "tsc -p tsconfig.cjs.json && tsc -p tsconfig.esm.json",
25
25
  "build:watch": "tsc --watch",
26
26
  "copy:license": "cp ../../LICENSE ./",
27
27
  "lint": "TIMING=1 eslint '**/*.ts'",
@@ -33,11 +33,11 @@
33
33
  "watch": "tsc -w"
34
34
  },
35
35
  "dependencies": {
36
- "@anchan828/nest-cloud-run-queue-common": "^3.1.7",
36
+ "@anchan828/nest-cloud-run-queue-common": "^3.1.9",
37
37
  "@google-cloud/tasks": "^5.0.0"
38
38
  },
39
39
  "devDependencies": {
40
- "@nestjs/common": "10.3.10",
40
+ "@nestjs/common": "10.4.1",
41
41
  "rxjs": "7.8.1"
42
42
  },
43
43
  "peerDependencies": {
@@ -47,5 +47,19 @@
47
47
  "access": "public"
48
48
  },
49
49
  "packageManager": "npm@10.8.2",
50
- "gitHead": "d63c1143192396b815ac6b72d54925971d00497a"
50
+ "exports": {
51
+ ".": {
52
+ "import": {
53
+ "types": "./dist/esm/index.d.ts",
54
+ "default": "./dist/esm/index.js"
55
+ },
56
+ "require": {
57
+ "types": "./dist/cjs/index.d.ts",
58
+ "default": "./dist/cjs/index.js"
59
+ },
60
+ "types": "./dist/cjs/index.d.ts",
61
+ "default": "./dist/cjs/index.js"
62
+ }
63
+ },
64
+ "gitHead": "9a7d8adc63d5610993cebdfcd230595ab549a914"
51
65
  }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes