@midwayjs/cross-domain 3.0.3 → 3.0.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/cross-domain",
3
- "version": "3.0.3",
3
+ "version": "3.0.6",
4
4
  "description": "Midway Component for Cross Domain",
5
5
  "main": "dist/index.js",
6
6
  "typings": "index.d.ts",
@@ -15,8 +15,7 @@
15
15
  "files": [
16
16
  "dist/**/*.js",
17
17
  "dist/**/*.d.ts",
18
- "index.d.ts",
19
- "dist/**/*.js.map"
18
+ "index.d.ts"
20
19
  ],
21
20
  "engines": {
22
21
  "node": ">=12"
@@ -26,14 +25,14 @@
26
25
  "vary": "^1.1.2"
27
26
  },
28
27
  "devDependencies": {
29
- "@midwayjs/core": "^3.0.2",
30
- "@midwayjs/decorator": "^3.0.2",
31
- "@midwayjs/express": "^3.0.2",
32
- "@midwayjs/faas": "^3.0.2",
33
- "@midwayjs/koa": "^3.0.3",
34
- "@midwayjs/mock": "^3.0.2",
35
- "@midwayjs/serverless-app": "^3.0.2",
36
- "@midwayjs/web": "^3.0.2"
28
+ "@midwayjs/core": "^3.0.6",
29
+ "@midwayjs/decorator": "^3.0.6",
30
+ "@midwayjs/express": "^3.0.6",
31
+ "@midwayjs/faas": "^3.0.6",
32
+ "@midwayjs/koa": "^3.0.6",
33
+ "@midwayjs/mock": "^3.0.6",
34
+ "@midwayjs/serverless-app": "^3.0.6",
35
+ "@midwayjs/web": "^3.0.6"
37
36
  },
38
- "gitHead": "43a5971b284aa918d22d191236c5664b011f8d87"
37
+ "gitHead": "afaa5b59a2be85e915233a9268c0e05965dd5c61"
39
38
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"config.default.js","sourceRoot":"","sources":["../../src/config/config.default.ts"],"names":[],"mappings":";;;AAEa,QAAA,IAAI,GAAyB;IACxC,YAAY,EAAE,gCAAgC;IAC9C,WAAW,EAAE,KAAK;CACnB,CAAC;AAEW,QAAA,KAAK,GAAiB;IACjC,QAAQ,EAAE,OAAO;IACjB,KAAK,EAAE,GAAG;IACV,IAAI,EAAE,KAAK;CACZ,CAAC","sourcesContent":["import { CORSOptions, JSONPOptions } from '../interface';\n\nexport const cors: Partial<CORSOptions> = {\n allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH',\n credentials: false,\n};\n\nexport const jsonp: JSONPOptions = {\n callback: 'jsonp',\n limit: 512,\n csrf: false,\n};\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"configuration.js","sourceRoot":"","sources":["../src/configuration.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mDAA4D;AAC5D,yDAAyD;AACzD,yCAA0D;AAC1D,4CAAmD;AASnD,IAAa,wBAAwB,GAArC,MAAa,wBAAwB;IAInC,KAAK,CAAC,OAAO;QACX,IAAI,CAAC,kBAAkB;aACpB,eAAe,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;aAClD,OAAO,CAAC,GAAG,CAAC,EAAE;YACb,GAAG,CAAC,aAAa,CAAC,qBAAc,CAAC,CAAC;QACpC,CAAC,CAAC,CAAC;IACP,CAAC;CACF,CAAA;AATC;IADC,IAAA,kBAAM,GAAE;8BACW,+BAAwB;oEAAC;AAFlC,wBAAwB;IARpC,IAAA,yBAAa,EAAC;QACb,SAAS,EAAE,cAAc;QACzB,aAAa,EAAE;YACb;gBACE,OAAO,EAAE,aAAa;aACvB;SACF;KACF,CAAC;GACW,wBAAwB,CAWpC;AAXY,4DAAwB","sourcesContent":["import { Configuration, Inject } from '@midwayjs/decorator';\nimport * as DefaultConfig from './config/config.default';\nimport { MidwayApplicationManager } from '@midwayjs/core';\nimport { CorsMiddleware } from './middleware/cors';\n@Configuration({\n namespace: 'cross-domain',\n importConfigs: [\n {\n default: DefaultConfig,\n },\n ],\n})\nexport class CrossDomainConfiguration {\n @Inject()\n applicationManager: MidwayApplicationManager;\n\n async onReady() {\n this.applicationManager\n .getApplications(['koa', 'faas', 'express', 'egg'])\n .forEach(app => {\n app.useMiddleware(CorsMiddleware);\n });\n }\n}\n"]}
package/dist/error.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"error.js","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":";;;AAAA,yCAA2C;AAE3C,WAAW;AACX,MAAa,cAAe,SAAQ,gBAAS,CAAC,cAAc;IAC1D;QACE,KAAK,CAAC,wCAAwC,CAAC,CAAC;IAClD,CAAC;CACF;AAJD,wCAIC","sourcesContent":["import { httpError } from '@midwayjs/core';\n\n// csrf 403\nexport class JSONPCSRFError extends httpError.ForbiddenError {\n constructor() {\n super('jsonp request security validate failed');\n }\n}\n"]}
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,iDAA4E;AAAnE,8GAAA,wBAAwB,OAAiB;AAClD,oDAAkC;AAClC,qDAAmC;AACnC,0CAAwB;AACxB,8CAA4B","sourcesContent":["export { CrossDomainConfiguration as Configuration } from './configuration';\nexport * from './middleware/cors';\nexport * from './middleware/jsonp';\nexport * from './jsonp';\nexport * from './interface';\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"interface.js","sourceRoot":"","sources":["../src/interface.ts"],"names":[],"mappings":"","sourcesContent":["export interface CORSOptions {\n allowMethods: string |string[];\n origin: string|Function;\n exposeHeaders: string |string[];\n allowHeaders: string |string[];\n credentials: boolean|Function;\n keepHeadersOnError: boolean;\n maxAge: number;\n}\nexport interface JSONPOptions {\n callback: string;\n limit: number;\n csrf: boolean;\n}"]}
package/dist/jsonp.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"jsonp.js","sourceRoot":"","sources":["../src/jsonp.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mDAA8D;AAG9D,IAAa,YAAY,GAAzB,MAAa,YA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'@midwayjs/decorator';\nimport { JSONPOptions } from './interface';\n@Provide()\nexport class JSONPService {\n @Inject()\n ctx;\n\n @Config('jsonp')\n jsonpConfig;\n\n @Inject()\n res;\n\n jsonp(body: any, config?: JSONPOptions) {\n this.ctx.type = 'js';\n // https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/X-Content-Type-Options\n if (this.ctx.set) {\n this.ctx.set('x-content-type-options', 'nosniff');\n } else if (this.res.set) {\n this.res.set('x-content-type-options', 'nosniff');\n }\n\n const { callback, limit } = Object.assign({}, this.jsonpConfig, config);\n\n // Only allow \"[\",\"]\",\"a-zA-Z0123456789_\", \"$\" and \".\" characters.\n let cb = (this.ctx.query[callback] || 'callback').replace(\n /[^[\\]\\w$.]+/g,\n ''\n );\n\n if (cb.length > limit) {\n cb = cb.substring(0, limit);\n }\n\n const str = JSON.stringify(body === undefined ? null : body);\n // protect from jsonp xss\n return `/**/ typeof ${cb} === 'function' && ${cb}(${str});`;\n }\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"cors.js","sourceRoot":"","sources":["../../src/middleware/cors.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mDAA8E;AAG9E,6BAA6B;AAE7B,IAAa,cAAc,GAA3B,MAAa,cAAc;IAIzB,OAAO,CAAC,GAAG;QACT,IAAI,GAAG,CAAC,gBAAgB,EAAE,KAAK,+BAAmB,CAAC,WAAW,EAAE;YAC9D,OAAO,KAAK,EAAE,GAAQ,EAAE,GAAQ,EAAE,IAAS,EAAE,EAAE;gBAC7C,OAAO,IAAI,CAAC,oBAAoB,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;YACnD,CAAC,CAAC;SACH;aAAM;YACL,OAAO,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;gBACzB,OAAO,IAAI,CAAC,oBAAoB,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;YAC3D,CAAC,CAAC;SACH;IACH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C,IAAI,CAAC,kBAAkB,EAAE;YACjC,OAAO,MAAM,IAAI,EAAE,CAAC;SACrB;QACD,IAAI;YACF,OAAO,MAAM,IAAI,EAAE,CAAC;SACrB;QAAC,OAAO,GAAG,EAAE;YACZ,MAAM,aAAa,GAAG,GAAG,CAAC,OAAO,IAAI,EAAE,CAAC;YACxC,MAAM,cAAc,GAAG,IAAI,CAAC,MAAM,CAChC,aAAa,CAAC,IAAI,IAAI,aAAa,CAAC,IAAI,IAAI,EAAE,EAC9C,QAAQ,CACT,CAAC;YACF,OAAO,aAAa,CAAC,IAAI,CAAC;YAE1B,GAAG,CAAC,OAAO,GAAG;gBACZ,GAAG,aAAa;gBAChB,GAAG,UAAU;gBACb,GAAG,EAAE,IAAI,EAAE,cAAc,EAAE;aAC5B,CAAC;YACF,MAAM,GAAG,CAAC;SACX;IACH,CAAC;CACF,CAAA;AA9GC;IADC,IAAA,kBAAM,EAAC,MAAM,CAAC;;4CACG;AAFP,cAAc;IAD1B,IAAA,sBAAU,GAAE;GACA,cAAc,CAgH1B;AAhHY,wCAAc","sourcesContent":["import { Config, Middleware, MidwayFrameworkType } from '@midwayjs/decorator';\nimport { IMiddleware } from '@midwayjs/core';\nimport { CORSOptions } from '../interface';\nimport * as vary from 'vary';\n@Middleware()\nexport class CorsMiddleware implements IMiddleware<any, any> {\n @Config('cors')\n cors: CORSOptions;\n\n resolve(app) {\n if (app.getFrameworkType() === MidwayFrameworkType.WEB_EXPRESS) {\n return async (req: any, res: any, next: any) => {\n return this.compatibleMiddleware(req, res, next);\n };\n } else {\n return async (ctx, next) => {\n return this.compatibleMiddleware(ctx.request, ctx, next);\n };\n }\n }\n\n async compatibleMiddleware(request, response, next) {\n const requestOrigin = request.get('origin');\n // Always set Vary header\n response.vary('Origin');\n\n if (!requestOrigin) {\n return await next();\n }\n\n let origin;\n if (typeof this.cors.origin === 'function') {\n origin = await Promise.resolve(this.cors.origin(request));\n if (!origin) {\n return await next();\n }\n } else {\n origin = this.cors.origin || requestOrigin;\n }\n\n let credentials;\n if (typeof this.cors.credentials === 'function') {\n credentials = await Promise.resolve(this.cors.credentials(request));\n } else {\n credentials = !!this.cors.credentials;\n }\n\n if (request.method.toUpperCase() === 'OPTIONS') {\n if (!request.get('Access-Control-Request-Method')) {\n return await next();\n }\n\n response.set('Access-Control-Allow-Origin', origin);\n\n if (credentials === true) {\n response.set('Access-Control-Allow-Credentials', 'true');\n }\n\n if (this.cors.maxAge) {\n response.set('Access-Control-Max-Age', this.cors.maxAge);\n }\n\n if (this.cors.allowMethods) {\n response.set('Access-Control-Allow-Methods', this.cors.allowMethods);\n }\n\n let allowHeaders = this.cors.allowHeaders;\n if (!allowHeaders) {\n allowHeaders = request.get('Access-Control-Request-Headers');\n }\n if (allowHeaders) {\n response.set('Access-Control-Allow-Headers', allowHeaders);\n }\n if (response.sendStatus) {\n response.sendStatus(204);\n } else {\n response.status = 204;\n }\n return;\n }\n const headersSet = {};\n\n function set(key, value) {\n response.set(key, value);\n headersSet[key] = value;\n }\n set('Access-Control-Allow-Origin', origin);\n\n if (credentials === true) {\n set('Access-Control-Allow-Credentials', 'true');\n }\n\n if (this.cors.exposeHeaders) {\n set('Access-Control-Expose-Headers', this.cors.exposeHeaders);\n }\n\n if (!this.cors.keepHeadersOnError) {\n return await next();\n }\n try {\n return await next();\n } catch (err) {\n const errHeadersSet = err.headers || {};\n const varyWithOrigin = vary.append(\n errHeadersSet.vary || errHeadersSet.Vary || '',\n 'Origin'\n );\n delete errHeadersSet.Vary;\n\n err.headers = {\n ...errHeadersSet,\n ...headersSet,\n ...{ vary: varyWithOrigin },\n };\n throw err;\n }\n }\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"jsonp.js","sourceRoot":"","sources":["../../src/middleware/jsonp.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mDAK6B;AAE7B,oCAAwC;AACxC,oCAA0C;AAI1C,IAAa,WAAW,GAAxB,MAAa,WAAW;IACtB,KAAK,CAAC,KAAK,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,OAAO,MAAM,IAAI,EAAE,CAAC;IACtB,CAAC;CACF,CAAA;AA7BC;IADC,IAAA,kBAAM,EAAC,OAAO,CAAC;;8CACI;AAFT,eAAe;IAD3B,IAAA,sBAAU,GAAE;GACA,eAAe,CA+B3B;AA/BY,0CAAe","sourcesContent":["import {\n Config,\n Middleware,\n MidwayFrameworkType,\n Match,\n} from '@midwayjs/decorator';\nimport { IMiddleware } from '@midwayjs/core';\nimport { JSONPService } from '../jsonp';\nimport { JSONPCSRFError } from '../error';\nimport { JSONPOptions } from '../interface';\n\n@Match()\nexport class JSONPFilter {\n async match(value, req) {\n const jsonpService = await req.requestContext.getAsync(JSONPService);\n return jsonpService.jsonp(value);\n }\n}\n\n@Middleware()\nexport class JSONPMiddleware implements IMiddleware<any, any> {\n @Config('jsonp')\n jsonp: JSONPOptions;\n\n resolve(app) {\n if (app.getFrameworkType() === MidwayFrameworkType.WEB_EXPRESS) {\n app.useFilter(JSONPFilter);\n return async (req: any, res: any, next: any) => {\n return this.compatibleMiddleware(req, next);\n };\n } else {\n return async (ctx, next) => {\n const result = await this.compatibleMiddleware(ctx, next);\n const jsonpService = await ctx.requestContext.getAsync(JSONPService);\n return jsonpService.jsonp(result);\n };\n }\n }\n\n async compatibleMiddleware(context, next) {\n const { csrf } = this.jsonp;\n // midway security\n if (csrf && context.assertCsrf) {\n try {\n context.assertCsrf();\n } catch (_) {\n throw new JSONPCSRFError();\n }\n }\n return await next();\n }\n}\n"]}