@ldsg/ali-oss 0.3.30

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,8 @@
1
+ import { HandlerSpecificResourceSettings } from "@ldsg/handler";
2
+ import { ResourceDefinitionSpecificResourceSettings } from "@ldsg/resource-definition";
3
+ import { GeneralResourceSettings } from "@ldsg/types";
4
+ export declare const INSTANTIATE_RESOURCE_HANDLER_GENERAL_RESOURCE_SETTINGS: GeneralResourceSettings;
5
+ export declare const INSTANTIATE_RESOURCE_HANDLER_SPECIFIC_RESOURCE_SETTINGS: HandlerSpecificResourceSettings;
6
+ export declare const RESOURCE_DEFINITION_GENERAL_RESOURCE_SETTINGS: GeneralResourceSettings;
7
+ export declare const RESOURCE_DEFINITION_SPECIFIC_RESOURCE_SETTINGS: ResourceDefinitionSpecificResourceSettings;
8
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,0CAA0C,EAAE,MAAM,2BAA2B,CAAC;AACvF,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAEtD,eAAO,MAAM,sDAAsD,EAAE,uBAGpE,CAAC;AAEF,eAAO,MAAM,uDAAuD,EAAE,+BAQnE,CAAC;AAEJ,eAAO,MAAM,6CAA6C,EAAE,uBAG3D,CAAC;AAEF,eAAO,MAAM,8CAA8C,EAAE,0CAG1D,CAAC"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RESOURCE_DEFINITION_SPECIFIC_RESOURCE_SETTINGS = exports.RESOURCE_DEFINITION_GENERAL_RESOURCE_SETTINGS = exports.INSTANTIATE_RESOURCE_HANDLER_SPECIFIC_RESOURCE_SETTINGS = exports.INSTANTIATE_RESOURCE_HANDLER_GENERAL_RESOURCE_SETTINGS = void 0;
4
+ exports.INSTANTIATE_RESOURCE_HANDLER_GENERAL_RESOURCE_SETTINGS = {
5
+ title: "阿里云 OSS 实例化资源处理程序",
6
+ description: "",
7
+ };
8
+ exports.INSTANTIATE_RESOURCE_HANDLER_SPECIFIC_RESOURCE_SETTINGS = {
9
+ code: `export * from "@ldsg/ali-oss";`,
10
+ dependencies: [
11
+ {
12
+ name: "@ldsg/ali-oss",
13
+ },
14
+ ],
15
+ };
16
+ exports.RESOURCE_DEFINITION_GENERAL_RESOURCE_SETTINGS = {
17
+ title: "阿里云 OSS 资源定义",
18
+ description: "",
19
+ };
20
+ exports.RESOURCE_DEFINITION_SPECIFIC_RESOURCE_SETTINGS = {
21
+ kind: "ali_oss",
22
+ };
@@ -0,0 +1,6 @@
1
+ import { Handler } from "@ldsg/handler";
2
+ import { InstantiateResourceParams, InstantiateResourceRes } from "@ldsg/resource";
3
+ import { AliOssResource } from "./resource";
4
+ import { AliOssSpecificResourceSettings } from "./types";
5
+ export declare const handler: Handler<InstantiateResourceParams<AliOssSpecificResourceSettings>, InstantiateResourceRes<AliOssResource>>;
6
+ //# sourceMappingURL=handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../src/handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,yBAAyB,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAEnF,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,8BAA8B,EAAE,MAAM,SAAS,CAAC;AAEzD,eAAO,MAAM,OAAO,EAAE,OAAO,CAC3B,yBAAyB,CAAC,8BAA8B,CAAC,EACzD,sBAAsB,CAAC,cAAc,CAAC,CACjB,CAAC"}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handler = void 0;
4
+ const instantiate_resource_1 = require("./instantiate-resource");
5
+ exports.handler = instantiate_resource_1.instantiateResource;
@@ -0,0 +1,6 @@
1
+ export * from "./constants";
2
+ export * from "./handler";
3
+ export * from "./instantiate-resource";
4
+ export * from "./resource";
5
+ export * from "./types";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,wBAAwB,CAAC;AACvC,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./constants"), exports);
18
+ __exportStar(require("./handler"), exports);
19
+ __exportStar(require("./instantiate-resource"), exports);
20
+ __exportStar(require("./resource"), exports);
21
+ __exportStar(require("./types"), exports);
@@ -0,0 +1,5 @@
1
+ import { InstantiateResource } from "@ldsg/resource";
2
+ import { AliOssResource } from "./resource";
3
+ import { AliOssSpecificResourceSettings } from "./types";
4
+ export declare const instantiateResource: InstantiateResource<AliOssSpecificResourceSettings, AliOssResource>;
5
+ //# sourceMappingURL=instantiate-resource.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instantiate-resource.d.ts","sourceRoot":"","sources":["../src/instantiate-resource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,8BAA8B,EAAE,MAAM,SAAS,CAAC;AAEzD,eAAO,MAAM,mBAAmB,EAAE,mBAAmB,CACnD,8BAA8B,EAC9B,cAAc,CAWf,CAAC"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.instantiateResource = void 0;
4
+ const resource_1 = require("./resource");
5
+ const instantiateResource = (params) => {
6
+ const { resourceConstructorParams } = params;
7
+ const resource = new resource_1.AliOssResource(resourceConstructorParams);
8
+ const res = {
9
+ resource,
10
+ };
11
+ return res;
12
+ };
13
+ exports.instantiateResource = instantiateResource;
@@ -0,0 +1,29 @@
1
+ import { ModifyGraphQLSchema } from "@ldsg/graphql";
2
+ import { Resource, ResourceConstructorParams } from "@ldsg/resource";
3
+ import OSS from "ali-oss";
4
+ import { AliOssSpecificResourceSettings } from "./types";
5
+ interface GetClientParams {
6
+ options?: OSS.Options;
7
+ }
8
+ export type GetClient = (params?: GetClientParams) => OSS;
9
+ export interface SignatureUrlV4Params {
10
+ method: OSS.HTTPMethods;
11
+ expires: number;
12
+ request?: {
13
+ headers?: object | undefined;
14
+ queries?: object | undefined;
15
+ };
16
+ objectName: string;
17
+ additionalHeaders?: string[];
18
+ clientOptions?: OSS.Options;
19
+ }
20
+ export type SignatureUrlV4 = (params: SignatureUrlV4Params) => Promise<string>;
21
+ export declare class AliOssResource extends Resource<AliOssSpecificResourceSettings> {
22
+ clientOptions: OSS.Options;
23
+ constructor(params: ResourceConstructorParams<AliOssSpecificResourceSettings>);
24
+ modifyGraphQLSchema: ModifyGraphQLSchema;
25
+ getClient: GetClient;
26
+ signatureUrlV4: SignatureUrlV4;
27
+ }
28
+ export {};
29
+ //# sourceMappingURL=resource.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../src/resource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AACrE,OAAO,GAAG,MAAM,SAAS,CAAC;AAE1B,OAAO,EAAE,8BAA8B,EAAE,MAAM,SAAS,CAAC;AAEzD,UAAU,eAAe;IACvB,OAAO,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC;CACvB;AAED,MAAM,MAAM,SAAS,GAAG,CAAC,MAAM,CAAC,EAAE,eAAe,KAAK,GAAG,CAAC;AAE1D,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,GAAG,CAAC,WAAW,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE;QACR,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;QAC7B,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;KAC9B,CAAC;IACF,UAAU,EAAE,MAAM,CAAC;IACnB,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC7B,aAAa,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC;CAC7B;AAED,MAAM,MAAM,cAAc,GAAG,CAAC,MAAM,EAAE,oBAAoB,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;AAc/E,qBAAa,cAAe,SAAQ,QAAQ,CAAC,8BAA8B,CAAC;IAC1E,aAAa,EAAE,GAAG,CAAC,OAAO,CAAC;gBAEf,MAAM,EAAE,yBAAyB,CAAC,8BAA8B,CAAC;IAW7E,mBAAmB,EAAE,mBAAmB,CAsDtC;IAEF,SAAS,EAAE,SAAS,CAWlB;IAEF,cAAc,EAAE,cAAc,CAc5B;CACH"}
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ var _a, _b;
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.AliOssResource = void 0;
8
+ const resource_1 = require("@ldsg/resource");
9
+ const ali_oss_1 = __importDefault(require("ali-oss"));
10
+ const uuid_1 = require("uuid");
11
+ const defaultClientOptions = {
12
+ accessKeyId: (_a = process.env.ALI_OSS_ACCESS_KEY_ID) !== null && _a !== void 0 ? _a : "",
13
+ accessKeySecret: (_b = process.env.ALI_OSS_ACCESS_KEY_SECRET) !== null && _b !== void 0 ? _b : "",
14
+ bucket: process.env.ALI_OSS_BUCKET,
15
+ cname: Boolean(process.env.ALI_OSS_CNAME),
16
+ endpoint: process.env.ALI_OSS_ENDPOINT,
17
+ internal: Boolean(process.env.ALI_OSS_INTERNAL),
18
+ region: process.env.ALI_OSS_REGION,
19
+ secure: Boolean(process.env.ALI_OSS_SECURE),
20
+ authorizationV4: true,
21
+ };
22
+ class AliOssResource extends resource_1.Resource {
23
+ constructor(params) {
24
+ super(params);
25
+ this.modifyGraphQLSchema = (params) => {
26
+ const { schemaComposer } = params;
27
+ if (!schemaComposer.has("Query")) {
28
+ schemaComposer.Query.addFields({});
29
+ }
30
+ const signatureUrlV4 = this.signatureUrlV4.bind(this);
31
+ schemaComposer.Query.addFields({
32
+ aliOssDownloadUrl: {
33
+ type: "String",
34
+ args: {
35
+ key: "String!",
36
+ expires: {
37
+ type: "Int",
38
+ defaultValue: 3600,
39
+ },
40
+ },
41
+ resolve: async (source, args) => {
42
+ const url = signatureUrlV4({
43
+ method: "GET",
44
+ expires: args.expires,
45
+ objectName: args.key,
46
+ });
47
+ return url;
48
+ },
49
+ },
50
+ aliOssUploadUrl: {
51
+ type: "String",
52
+ args: {
53
+ expires: {
54
+ type: "Int",
55
+ defaultValue: 3600,
56
+ },
57
+ headers: "JSON",
58
+ },
59
+ resolve: async (source, args) => {
60
+ var _a;
61
+ const objectName = (0, uuid_1.v4)();
62
+ const url = signatureUrlV4({
63
+ method: "PUT",
64
+ expires: args.expires,
65
+ objectName,
66
+ request: {
67
+ headers: (_a = args.headers) !== null && _a !== void 0 ? _a : {},
68
+ },
69
+ });
70
+ return url;
71
+ },
72
+ },
73
+ });
74
+ };
75
+ this.getClient = (params) => {
76
+ const { options: paramsOptions = {} } = params !== null && params !== void 0 ? params : {};
77
+ const { clientOptions } = this;
78
+ const client = new ali_oss_1.default({
79
+ ...clientOptions,
80
+ ...paramsOptions,
81
+ });
82
+ return client;
83
+ };
84
+ this.signatureUrlV4 = async (params) => {
85
+ const { method, expires, request, objectName, additionalHeaders, clientOptions } = params;
86
+ const client = this.getClient({ options: clientOptions });
87
+ const url = await client.signatureUrlV4(method, expires, request, objectName, additionalHeaders);
88
+ return url;
89
+ };
90
+ const { settings } = params;
91
+ this.clientOptions = {
92
+ ...defaultClientOptions,
93
+ ...settings,
94
+ };
95
+ }
96
+ }
97
+ exports.AliOssResource = AliOssResource;
@@ -0,0 +1,2 @@
1
+ export * from "./specific-resource-settings";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./specific-resource-settings"), exports);
@@ -0,0 +1,23 @@
1
+ import { z } from "zod";
2
+ export declare const AliOssSpecificResourceSettingsSchema: z.ZodObject<{
3
+ accessKeyId: z.ZodOptional<z.ZodString>;
4
+ accessKeySecret: z.ZodOptional<z.ZodString>;
5
+ bucket: z.ZodOptional<z.ZodString>;
6
+ cname: z.ZodOptional<z.ZodBoolean>;
7
+ endpoint: z.ZodOptional<z.ZodString>;
8
+ internal: z.ZodOptional<z.ZodBoolean>;
9
+ region: z.ZodOptional<z.ZodString>;
10
+ secure: z.ZodOptional<z.ZodBoolean>;
11
+ }, z.core.$catchall<z.ZodAny>>;
12
+ export declare const SpecificResourceSettingsSchema: z.ZodObject<{
13
+ accessKeyId: z.ZodOptional<z.ZodString>;
14
+ accessKeySecret: z.ZodOptional<z.ZodString>;
15
+ bucket: z.ZodOptional<z.ZodString>;
16
+ cname: z.ZodOptional<z.ZodBoolean>;
17
+ endpoint: z.ZodOptional<z.ZodString>;
18
+ internal: z.ZodOptional<z.ZodBoolean>;
19
+ region: z.ZodOptional<z.ZodString>;
20
+ secure: z.ZodOptional<z.ZodBoolean>;
21
+ }, z.core.$catchall<z.ZodAny>>;
22
+ export type AliOssSpecificResourceSettings = z.infer<typeof AliOssSpecificResourceSettingsSchema>;
23
+ //# sourceMappingURL=specific-resource-settings.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"specific-resource-settings.d.ts","sourceRoot":"","sources":["../../src/types/specific-resource-settings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,oCAAoC;;;;;;;;;8BAW7B,CAAC;AAErB,eAAO,MAAM,8BAA8B;;;;;;;;;8BAAuC,CAAC;AACnF,MAAM,MAAM,8BAA8B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oCAAoC,CAAC,CAAC"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SpecificResourceSettingsSchema = exports.AliOssSpecificResourceSettingsSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ exports.AliOssSpecificResourceSettingsSchema = zod_1.z
6
+ .object({
7
+ accessKeyId: zod_1.z.string().optional(),
8
+ accessKeySecret: zod_1.z.string().optional(),
9
+ bucket: zod_1.z.string().optional(),
10
+ cname: zod_1.z.boolean().optional(),
11
+ endpoint: zod_1.z.string().optional(),
12
+ internal: zod_1.z.boolean().optional(),
13
+ region: zod_1.z.string().optional(),
14
+ secure: zod_1.z.boolean().optional(),
15
+ })
16
+ .catchall(zod_1.z.any());
17
+ exports.SpecificResourceSettingsSchema = exports.AliOssSpecificResourceSettingsSchema;
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@ldsg/ali-oss",
3
+ "version": "0.3.30",
4
+ "description": "Aliyun OSS resource module for LDSG",
5
+ "keywords": [],
6
+ "license": "MIT",
7
+ "author": "wanxger",
8
+ "files": [
9
+ "dist/"
10
+ ],
11
+ "main": "dist/index.js",
12
+ "types": "dist",
13
+ "publishConfig": {
14
+ "access": "public"
15
+ },
16
+ "dependencies": {
17
+ "ali-oss": "^6.19.0",
18
+ "uuid": "~14.0.1",
19
+ "zod": "^4.1.11",
20
+ "@ldsg/handler": "0.3.33",
21
+ "@ldsg/types": "0.3.33",
22
+ "@ldsg/resource-definition": "0.3.33",
23
+ "@ldsg/resource": "0.3.33",
24
+ "@ldsg/graphql": "0.3.33"
25
+ },
26
+ "devDependencies": {
27
+ "@types/ali-oss": "^6.16.11",
28
+ "@types/jest": "^29.5.2",
29
+ "@types/node": "^20.13.0",
30
+ "@types/supertest": "^6.0.0",
31
+ "jest": "^29.5.0",
32
+ "supertest": "^6.3.4",
33
+ "ts-jest": "^29.1.5",
34
+ "ts-node": "^10.9.2",
35
+ "typescript": "^5.8.3",
36
+ "@ldsg/application": "0.3.33",
37
+ "@ldsg/graphql-resolver": "0.3.33"
38
+ },
39
+ "scripts": {
40
+ "build": "tsc --project tsconfig.build.json",
41
+ "clean": "rm -rf dist"
42
+ }
43
+ }