@osaas/client-web 0.2.0 → 0.3.1

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/lib/cdn.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ import { Context } from '@osaas/client-core';
2
+ export interface CdnOpts {
3
+ originPath: string;
4
+ rootObject?: string;
5
+ }
6
+ export declare function createCloudfrontDistribution(serviceId: string, instanceName: string, ctx: Context, opts?: CdnOpts): Promise<import("@aws-sdk/client-cloudfront").Distribution | undefined>;
7
+ //# sourceMappingURL=cdn.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cdn.d.ts","sourceRoot":"","sources":["../src/cdn.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,OAAO,EAAe,MAAM,oBAAoB,CAAC;AAE1D,MAAM,WAAW,OAAO;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,wBAAsB,4BAA4B,CAChD,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,MAAM,EACpB,GAAG,EAAE,OAAO,EACZ,IAAI,CAAC,EAAE,OAAO,0EAmDf"}
package/lib/cdn.js ADDED
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createCloudfrontDistribution = void 0;
4
+ const client_cloudfront_1 = require("@aws-sdk/client-cloudfront");
5
+ const client_core_1 = require("@osaas/client-core");
6
+ async function createCloudfrontDistribution(serviceId, instanceName, ctx, opts) {
7
+ const sat = await ctx.getServiceAccessToken(serviceId);
8
+ const instance = await (0, client_core_1.getInstance)(ctx, serviceId, instanceName, sat);
9
+ if (!instance) {
10
+ throw new Error(`Instance ${instanceName} not found`);
11
+ }
12
+ const originHostname = new URL(instance.url).hostname;
13
+ const client = new client_cloudfront_1.CloudFrontClient();
14
+ const input = {
15
+ DistributionConfig: {
16
+ CallerReference: Date.now().toString(),
17
+ Comment: `CDN for ${serviceId}-${instanceName}`,
18
+ DefaultRootObject: opts?.rootObject,
19
+ Origins: {
20
+ Quantity: 1,
21
+ Items: [
22
+ {
23
+ Id: originHostname,
24
+ DomainName: originHostname,
25
+ OriginPath: opts?.originPath,
26
+ CustomOriginConfig: {
27
+ HTTPPort: 80,
28
+ HTTPSPort: 443,
29
+ OriginProtocolPolicy: 'https-only',
30
+ OriginSslProtocols: {
31
+ Quantity: 1,
32
+ Items: ['TLSv1.2']
33
+ }
34
+ }
35
+ }
36
+ ]
37
+ },
38
+ DefaultCacheBehavior: {
39
+ TargetOriginId: originHostname,
40
+ ViewerProtocolPolicy: 'redirect-to-https',
41
+ AllowedMethods: {
42
+ Quantity: 7,
43
+ Items: ['GET', 'HEAD', 'POST', 'PUT', 'PATCH', 'OPTIONS', 'DELETE']
44
+ },
45
+ Compress: true,
46
+ CachePolicyId: '658327ea-f89d-4fab-a63d-7e88639e58f6',
47
+ OriginRequestPolicyId: '59781a5b-3903-41f3-afcb-af62929ccde1'
48
+ },
49
+ Enabled: true
50
+ }
51
+ };
52
+ const command = new client_cloudfront_1.CreateDistributionCommand(input);
53
+ const response = await client.send(command);
54
+ return response.Distribution;
55
+ }
56
+ exports.createCloudfrontDistribution = createCloudfrontDistribution;
57
+ //# sourceMappingURL=cdn.js.map
package/lib/cdn.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cdn.js","sourceRoot":"","sources":["../src/cdn.ts"],"names":[],"mappings":";;;AAAA,kEAIoC;AACpC,oDAA0D;AAOnD,KAAK,UAAU,4BAA4B,CAChD,SAAiB,EACjB,YAAoB,EACpB,GAAY,EACZ,IAAc;IAEd,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,qBAAqB,CAAC,SAAS,CAAC,CAAC;IACvD,MAAM,QAAQ,GAAG,MAAM,IAAA,yBAAW,EAAC,GAAG,EAAE,SAAS,EAAE,YAAY,EAAE,GAAG,CAAC,CAAC;IACtE,IAAI,CAAC,QAAQ,EAAE;QACb,MA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AI,CAAC,OAAO,CAAC,CAAC;IAC5C,OAAO,QAAQ,CAAC,YAAY,CAAC;AAC/B,CAAC;AAvDD,oEAuDC"}
package/lib/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  /** @module @osaas/client-web */
2
2
  export { publish } from './publish';
3
+ export { createCloudfrontDistribution } from './cdn';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAEhC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAEhC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,4BAA4B,EAAE,MAAM,OAAO,CAAC"}
package/lib/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  /** @module @osaas/client-web */
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.publish = void 0;
4
+ exports.createCloudfrontDistribution = exports.publish = void 0;
5
5
  var publish_1 = require("./publish");
6
6
  Object.defineProperty(exports, "publish", { enumerable: true, get: function () { return publish_1.publish; } });
7
+ var cdn_1 = require("./cdn");
8
+ Object.defineProperty(exports, "createCloudfrontDistribution", { enumerable: true, get: function () { return cdn_1.createCloudfrontDistribution; } });
7
9
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,gCAAgC;;;AAEhC,qCAAoC;AAA3B,kGAAA,OAAO,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,gCAAgC;;;AAEhC,qCAAoC;AAA3B,kGAAA,OAAO,OAAA;AAChB,6BAAqD;AAA5C,mHAAA,4BAA4B,OAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osaas/client-web",
3
- "version": "0.2.0",
3
+ "version": "0.3.1",
4
4
  "description": "Open Source Cloud Client SDK web library",
5
5
  "author": "Eyevinn Open Source Cloud <osc@eyevinn.se>",
6
6
  "homepage": "https://www.osaas.io",
@@ -25,8 +25,9 @@
25
25
  "test": "jest --passWithNoTests"
26
26
  },
27
27
  "dependencies": {
28
+ "@aws-sdk/client-cloudfront": "^3.730.0",
28
29
  "@osaas/client-core": "^0.15.0",
29
- "@osaas/client-services": "^0.5.0",
30
+ "@osaas/client-services": "^0.6.0",
30
31
  "chalk": "4.1.2",
31
32
  "mime": "^3.0.0",
32
33
  "minio": "^8.0.2"
@@ -34,5 +35,5 @@
34
35
  "publishConfig": {
35
36
  "access": "public"
36
37
  },
37
- "gitHead": "64eb9dfb6763ccf84b34a36f7ae3adf7963a58de"
38
+ "gitHead": "f4d80dc7b9e7a0e65b3faef07422b33aaafa9b23"
38
39
  }